Skip to content

Commit

Permalink
Smaller spine library, save 14KB package size (#17731)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Oct 23, 2024
1 parent 4b2399f commit 9073fd3
Show file tree
Hide file tree
Showing 3 changed files with 432 additions and 1,424 deletions.
269 changes: 172 additions & 97 deletions cocos/spine/lib/spine-core.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,177 @@
var spine;
(function (spine) {
var MixBlend;
(function (MixBlend) {
MixBlend[MixBlend["setup"] = 0] = "setup";
MixBlend[MixBlend["first"] = 1] = "first";
MixBlend[MixBlend["replace"] = 2] = "replace";
MixBlend[MixBlend["add"] = 3] = "add";
})(MixBlend = spine.MixBlend || (spine.MixBlend = {}));
var MixDirection;
(function (MixDirection) {
MixDirection[MixDirection["mixIn"] = 0] = "mixIn";
MixDirection[MixDirection["mixOut"] = 1] = "mixOut";
})(MixDirection = spine.MixDirection || (spine.MixDirection = {}));
var TimelineType;
(function (TimelineType) {
TimelineType[TimelineType["rotate"] = 0] = "rotate";
TimelineType[TimelineType["translate"] = 1] = "translate";
TimelineType[TimelineType["scale"] = 2] = "scale";
TimelineType[TimelineType["shear"] = 3] = "shear";
TimelineType[TimelineType["attachment"] = 4] = "attachment";
TimelineType[TimelineType["color"] = 5] = "color";
TimelineType[TimelineType["deform"] = 6] = "deform";
TimelineType[TimelineType["event"] = 7] = "event";
TimelineType[TimelineType["drawOrder"] = 8] = "drawOrder";
TimelineType[TimelineType["ikConstraint"] = 9] = "ikConstraint";
TimelineType[TimelineType["transformConstraint"] = 10] = "transformConstraint";
TimelineType[TimelineType["pathConstraintPosition"] = 11] = "pathConstraintPosition";
TimelineType[TimelineType["pathConstraintSpacing"] = 12] = "pathConstraintSpacing";
TimelineType[TimelineType["pathConstraintMix"] = 13] = "pathConstraintMix";
TimelineType[TimelineType["twoColor"] = 14] = "twoColor";
})(TimelineType = spine.TimelineType || (spine.TimelineType = {}));
var EventType;
(function (EventType) {
EventType[EventType["start"] = 0] = "start";
EventType[EventType["interrupt"] = 1] = "interrupt";
EventType[EventType["end"] = 2] = "end";
EventType[EventType["dispose"] = 3] = "dispose";
EventType[EventType["complete"] = 4] = "complete";
EventType[EventType["event"] = 5] = "event";
})(EventType = spine.EventType || (spine.EventType = {}));
var BlendMode;
(function (BlendMode) {
BlendMode[BlendMode["Normal"] = 0] = "Normal";
BlendMode[BlendMode["Additive"] = 1] = "Additive";
BlendMode[BlendMode["Multiply"] = 2] = "Multiply";
BlendMode[BlendMode["Screen"] = 3] = "Screen";
})(BlendMode = spine.BlendMode || (spine.BlendMode = {}));
var TransformMode;
(function (TransformMode) {
TransformMode[TransformMode["Normal"] = 0] = "Normal";
TransformMode[TransformMode["OnlyTranslation"] = 1] = "OnlyTranslation";
TransformMode[TransformMode["NoRotationOrReflection"] = 2] = "NoRotationOrReflection";
TransformMode[TransformMode["NoScale"] = 3] = "NoScale";
TransformMode[TransformMode["NoScaleOrReflection"] = 4] = "NoScaleOrReflection";
})(TransformMode = spine.TransformMode || (spine.TransformMode = {}));
var PositionMode;
(function (PositionMode) {
PositionMode[PositionMode["Fixed"] = 0] = "Fixed";
PositionMode[PositionMode["Percent"] = 1] = "Percent";
})(PositionMode = spine.PositionMode || (spine.PositionMode = {}));
var SpacingMode;
(function (SpacingMode) {
SpacingMode[SpacingMode["Length"] = 0] = "Length";
SpacingMode[SpacingMode["Fixed"] = 1] = "Fixed";
SpacingMode[SpacingMode["Percent"] = 2] = "Percent";
})(SpacingMode = spine.SpacingMode || (spine.SpacingMode = {}));
var RotateMode;
(function (RotateMode) {
RotateMode[RotateMode["Tangent"] = 0] = "Tangent";
RotateMode[RotateMode["Chain"] = 1] = "Chain";
RotateMode[RotateMode["ChainScale"] = 2] = "ChainScale";
})(RotateMode = spine.RotateMode || (spine.RotateMode = {}));
var TextureFilter;
(function (TextureFilter) {
TextureFilter[TextureFilter["Nearest"] = 9728] = "Nearest";
TextureFilter[TextureFilter["Linear"] = 9729] = "Linear";
TextureFilter[TextureFilter["MipMap"] = 9987] = "MipMap";
TextureFilter[TextureFilter["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
TextureFilter[TextureFilter["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
TextureFilter[TextureFilter["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
TextureFilter[TextureFilter["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
})(TextureFilter = spine.TextureFilter || (spine.TextureFilter = {}));
var TextureWrap;
(function (TextureWrap) {
TextureWrap[TextureWrap["MirroredRepeat"] = 33648] = "MirroredRepeat";
TextureWrap[TextureWrap["ClampToEdge"] = 33071] = "ClampToEdge";
TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat";
})(TextureWrap = spine.TextureWrap || (spine.TextureWrap = {}));
var AttachmentType;
(function (AttachmentType) {
AttachmentType[AttachmentType["Region"] = 0] = "Region";
AttachmentType[AttachmentType["BoundingBox"] = 1] = "BoundingBox";
AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh";
AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh";
AttachmentType[AttachmentType["Path"] = 4] = "Path";
AttachmentType[AttachmentType["Point"] = 5] = "Point";
AttachmentType[AttachmentType["Clipping"] = 6] = "Clipping";
})(AttachmentType = spine.AttachmentType || (spine.AttachmentType = {}));

function defineReverseKeyEnum(e) {
for (var key in e) {
var value = e[key];
e[value] = key;
}
}

var e = spine.MixBlend = {
setup: 0,
first: 1,
replace: 2,
add: 3
};
defineReverseKeyEnum(e);

e = spine.MixDirection = {
mixIn: 0,
mixOut: 1
};
defineReverseKeyEnum(e);

e = spine.TimelineType = {
rotate: 0,
translate: 1,
scale: 2,
shear: 3,
attachment: 4,
color: 5,
deform: 6,
event: 7,
drawOrder: 8,
ikConstraint: 9,
transformConstraint: 10,
pathConstraintPosition: 11,
pathConstraintSpacing: 12,
pathConstraintMix: 13,
twoColor: 14
};
defineReverseKeyEnum(e);

e = spine.EventType = {
start:0,
interrupt: 1,
end: 2,
dispose: 3,
complete: 4,
event: 5
};
defineReverseKeyEnum(e);

e = spine.BlendMode = {
Normal:0,
Additive: 1,
Multiply: 2,
Screen: 3
};
defineReverseKeyEnum(e);

e = spine.TransformMode = {
Normal: 0,
OnlyTranslation: 1,
NoRotationOrReflection: 2,
NoScale: 3,
NoScaleOrReflection: 4
};
defineReverseKeyEnum(e);

e = spine.PositionMode = {
Fixed: 0,
Percent: 1
};
defineReverseKeyEnum(e);

e = spine.SpacingMode = {
Length: 0,
Fixed: 1,
Percent: 2
};
defineReverseKeyEnum(e);

e = spine.RotateMode = {
Tangent: 0,
Chain: 1,
ChainScale: 2
};
defineReverseKeyEnum(e);

e = spine.TextureFilter = {
Nearest: 9728,
Linear: 9729,
MipMap: 9987,
MipMapNearestNearest: 9984,
MipMapLinearNearest: 9985,
MipMapNearestLinear: 9986,
MipMapLinearLinear: 9987
};
defineReverseKeyEnum(e);

e = spine.TextureWrap = {
MirroredRepeat: 33648,
ClampToEdge: 33071,
Repeat: 10497
};
defineReverseKeyEnum(e);

e = spine.AttachmentType = {
Region: 0,
BoundingBox: 1,
Mesh: 2,
LinkedMesh: 3,
Path: 4,
Point: 5,
Clipping: 6
};
defineReverseKeyEnum(e);

e = null;

const PI = 3.1415927;
const PI2 = PI * 2;
const radiansToDegrees = 180 / PI;
const radDeg = radiansToDegrees;
const degreesToRadians = PI / 180;
const degRad = degreesToRadians;

spine.MathUtils = class MathUtils {
static PI = PI;
static PI2 = PI2;
static radiansToDegrees = radiansToDegrees;
static radDeg = radDeg;
static degreesToRadians = degreesToRadians;
static degRad = degRad;

static clamp (value, min, max) {
if (value < min) return min;
if (value > max) return max;
return value;
}

static cosDeg (degrees) {
return Math.cos(degrees * degRad);
}

static sinDeg (degrees) {
return Math.sin(degrees * degRad);
}

static signum (value) {
return value > 0 ? 1 : value < 0 ? -1 : 0;
}

static toInt (x) {
return x > 0 ? Math.floor(x) : Math.ceil(x);
}

static cbrt (x) {
let y = Math.pow(Math.abs(x), 1/3);
return x < 0 ? -y : y;
}

static randomTriangular (min, max) {
return MathUtils.randomTriangularWith(min, max, (min + max) * 0.5);
}

static randomTriangularWith (min, max, mode) {
let u = Math.random();
let d = max - min;
if (u <= (mode - min) / d) return min + Math.sqrt(u * d * (mode - min));
return max - Math.sqrt((1 - u) * d * (max - mode));
}
}

})(spine || (spine = {}));
export default spine;
Loading

0 comments on commit 9073fd3

Please sign in to comment.