@esotericsoftware/spine-player
Version:
The official Spine Runtimes for the web.
1,607 lines (1,602 loc) • 493 kB
JavaScript
var spine = (() => {
var __defProp = Object.defineProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// spine-player/src/index.ts
var src_exports = {};
__export(src_exports, {
AlphaTimeline: () => AlphaTimeline,
Animation: () => Animation,
AnimationState: () => AnimationState,
AnimationStateAdapter: () => AnimationStateAdapter,
AnimationStateData: () => AnimationStateData,
AssetManager: () => AssetManager,
AssetManagerBase: () => AssetManagerBase,
AtlasAttachmentLoader: () => AtlasAttachmentLoader,
Attachment: () => Attachment,
AttachmentTimeline: () => AttachmentTimeline,
BinaryInput: () => BinaryInput,
BlendMode: () => BlendMode,
Bone: () => Bone,
BoneData: () => BoneData,
BoundingBoxAttachment: () => BoundingBoxAttachment,
CURRENT: () => CURRENT,
CameraController: () => CameraController,
ClippingAttachment: () => ClippingAttachment,
Color: () => Color,
Color2Attribute: () => Color2Attribute,
ColorAttribute: () => ColorAttribute,
ConstraintData: () => ConstraintData,
CurveTimeline: () => CurveTimeline,
CurveTimeline1: () => CurveTimeline1,
CurveTimeline2: () => CurveTimeline2,
DebugUtils: () => DebugUtils,
DeformTimeline: () => DeformTimeline,
Downloader: () => Downloader,
DrawOrderTimeline: () => DrawOrderTimeline,
Event: () => Event,
EventData: () => EventData,
EventQueue: () => EventQueue,
EventTimeline: () => EventTimeline,
EventType: () => EventType,
FIRST: () => FIRST,
FakeTexture: () => FakeTexture,
GLTexture: () => GLTexture,
HOLD_FIRST: () => HOLD_FIRST,
HOLD_MIX: () => HOLD_MIX,
HOLD_SUBSEQUENT: () => HOLD_SUBSEQUENT,
IkConstraint: () => IkConstraint,
IkConstraintData: () => IkConstraintData,
IkConstraintTimeline: () => IkConstraintTimeline,
Input: () => Input,
IntSet: () => IntSet,
Interpolation: () => Interpolation,
JitterEffect: () => JitterEffect,
LoadingScreen: () => LoadingScreen,
M00: () => M00,
M01: () => M01,
M02: () => M02,
M03: () => M03,
M10: () => M10,
M11: () => M11,
M12: () => M12,
M13: () => M13,
M20: () => M20,
M21: () => M21,
M22: () => M22,
M23: () => M23,
M30: () => M30,
M31: () => M31,
M32: () => M32,
M33: () => M33,
ManagedWebGLRenderingContext: () => ManagedWebGLRenderingContext,
MathUtils: () => MathUtils,
Matrix4: () => Matrix42,
Mesh: () => Mesh,
MeshAttachment: () => MeshAttachment,
MixBlend: () => MixBlend,
MixDirection: () => MixDirection,
OrthoCamera: () => OrthoCamera,
PathAttachment: () => PathAttachment,
PathConstraint: () => PathConstraint,
PathConstraintData: () => PathConstraintData,
PathConstraintMixTimeline: () => PathConstraintMixTimeline,
PathConstraintPositionTimeline: () => PathConstraintPositionTimeline,
PathConstraintSpacingTimeline: () => PathConstraintSpacingTimeline,
PointAttachment: () => PointAttachment,
PolygonBatcher: () => PolygonBatcher,
Pool: () => Pool,
Position2Attribute: () => Position2Attribute,
Position3Attribute: () => Position3Attribute,
PositionMode: () => PositionMode,
Pow: () => Pow,
PowOut: () => PowOut,
RGB2Timeline: () => RGB2Timeline,
RGBA2Timeline: () => RGBA2Timeline,
RGBATimeline: () => RGBATimeline,
RGBTimeline: () => RGBTimeline,
RegionAttachment: () => RegionAttachment,
ResizeMode: () => ResizeMode,
RotateMode: () => RotateMode,
RotateTimeline: () => RotateTimeline,
SETUP: () => SETUP,
SUBSEQUENT: () => SUBSEQUENT,
ScaleTimeline: () => ScaleTimeline,
ScaleXTimeline: () => ScaleXTimeline,
ScaleYTimeline: () => ScaleYTimeline,
SceneRenderer: () => SceneRenderer,
SequenceTimeline: () => SequenceTimeline,
Shader: () => Shader,
ShapeRenderer: () => ShapeRenderer,
ShapeType: () => ShapeType,
ShearTimeline: () => ShearTimeline,
ShearXTimeline: () => ShearXTimeline,
ShearYTimeline: () => ShearYTimeline,
Skeleton: () => Skeleton,
SkeletonBinary: () => SkeletonBinary,
SkeletonBounds: () => SkeletonBounds,
SkeletonClipping: () => SkeletonClipping,
SkeletonData: () => SkeletonData,
SkeletonDebugRenderer: () => SkeletonDebugRenderer,
SkeletonJson: () => SkeletonJson,
SkeletonRenderer: () => SkeletonRenderer,
Skin: () => Skin,
SkinEntry: () => SkinEntry,
Slot: () => Slot,
SlotData: () => SlotData,
SpacingMode: () => SpacingMode,
SpineCanvas: () => SpineCanvas,
SpinePlayer: () => SpinePlayer,
SpinePlayerEditor: () => SpinePlayerEditor,
StringSet: () => StringSet,
SwirlEffect: () => SwirlEffect,
TexCoordAttribute: () => TexCoordAttribute,
Texture: () => Texture,
TextureAtlas: () => TextureAtlas,
TextureAtlasPage: () => TextureAtlasPage,
TextureAtlasRegion: () => TextureAtlasRegion,
TextureFilter: () => TextureFilter,
TextureRegion: () => TextureRegion,
TextureWrap: () => TextureWrap,
TimeKeeper: () => TimeKeeper,
Timeline: () => Timeline,
Touch: () => Touch,
TrackEntry: () => TrackEntry,
TransformConstraint: () => TransformConstraint,
TransformConstraintData: () => TransformConstraintData,
TransformConstraintTimeline: () => TransformConstraintTimeline,
TransformMode: () => TransformMode,
TranslateTimeline: () => TranslateTimeline,
TranslateXTimeline: () => TranslateXTimeline,
TranslateYTimeline: () => TranslateYTimeline,
Triangulator: () => Triangulator,
Utils: () => Utils,
Vector2: () => Vector2,
Vector3: () => Vector3,
VertexAttachment: () => VertexAttachment,
VertexAttribute: () => VertexAttribute,
VertexAttributeType: () => VertexAttributeType,
WebGLBlendModeConverter: () => WebGLBlendModeConverter,
WindowedMean: () => WindowedMean
});
// spine-core/src/Utils.ts
var IntSet = class {
constructor() {
this.array = new Array();
}
add(value) {
let contains = this.contains(value);
this.array[value | 0] = value | 0;
return !contains;
}
contains(value) {
return this.array[value | 0] != void 0;
}
remove(value) {
this.array[value | 0] = void 0;
}
clear() {
this.array.length = 0;
}
};
var StringSet = class {
constructor() {
this.entries = {};
this.size = 0;
}
add(value) {
let contains = this.entries[value];
this.entries[value] = true;
if (!contains) {
this.size++;
return true;
}
return false;
}
addAll(values) {
let oldSize = this.size;
for (var i = 0, n = values.length; i < n; i++)
this.add(values[i]);
return oldSize != this.size;
}
contains(value) {
return this.entries[value];
}
clear() {
this.entries = {};
this.size = 0;
}
};
var _Color = class {
constructor(r = 0, g = 0, b = 0, a = 0) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
set(r, g, b, a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
return this.clamp();
}
setFromColor(c) {
this.r = c.r;
this.g = c.g;
this.b = c.b;
this.a = c.a;
return this;
}
setFromString(hex) {
hex = hex.charAt(0) == "#" ? hex.substr(1) : hex;
this.r = parseInt(hex.substr(0, 2), 16) / 255;
this.g = parseInt(hex.substr(2, 2), 16) / 255;
this.b = parseInt(hex.substr(4, 2), 16) / 255;
this.a = hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255;
return this;
}
add(r, g, b, a) {
this.r += r;
this.g += g;
this.b += b;
this.a += a;
return this.clamp();
}
clamp() {
if (this.r < 0)
this.r = 0;
else if (this.r > 1)
this.r = 1;
if (this.g < 0)
this.g = 0;
else if (this.g > 1)
this.g = 1;
if (this.b < 0)
this.b = 0;
else if (this.b > 1)
this.b = 1;
if (this.a < 0)
this.a = 0;
else if (this.a > 1)
this.a = 1;
return this;
}
static rgba8888ToColor(color, value) {
color.r = ((value & 4278190080) >>> 24) / 255;
color.g = ((value & 16711680) >>> 16) / 255;
color.b = ((value & 65280) >>> 8) / 255;
color.a = (value & 255) / 255;
}
static rgb888ToColor(color, value) {
color.r = ((value & 16711680) >>> 16) / 255;
color.g = ((value & 65280) >>> 8) / 255;
color.b = (value & 255) / 255;
}
static fromString(hex) {
return new _Color().setFromString(hex);
}
};
var Color = _Color;
Color.WHITE = new _Color(1, 1, 1, 1);
Color.RED = new _Color(1, 0, 0, 1);
Color.GREEN = new _Color(0, 1, 0, 1);
Color.BLUE = new _Color(0, 0, 1, 1);
Color.MAGENTA = new _Color(1, 0, 1, 1);
var _MathUtils = class {
static clamp(value, min, max) {
if (value < min)
return min;
if (value > max)
return max;
return value;
}
static cosDeg(degrees) {
return Math.cos(degrees * _MathUtils.degRad);
}
static sinDeg(degrees) {
return Math.sin(degrees * _MathUtils.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));
}
static isPowerOfTwo(value) {
return value && (value & value - 1) === 0;
}
};
var MathUtils = _MathUtils;
MathUtils.PI = 3.1415927;
MathUtils.PI2 = _MathUtils.PI * 2;
MathUtils.radiansToDegrees = 180 / _MathUtils.PI;
MathUtils.radDeg = _MathUtils.radiansToDegrees;
MathUtils.degreesToRadians = _MathUtils.PI / 180;
MathUtils.degRad = _MathUtils.degreesToRadians;
var Interpolation = class {
apply(start, end, a) {
return start + (end - start) * this.applyInternal(a);
}
};
var Pow = class extends Interpolation {
constructor(power) {
super();
this.power = 2;
this.power = power;
}
applyInternal(a) {
if (a <= 0.5)
return Math.pow(a * 2, this.power) / 2;
return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1;
}
};
var PowOut = class extends Pow {
constructor(power) {
super(power);
}
applyInternal(a) {
return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1;
}
};
var _Utils = class {
static arrayCopy(source, sourceStart, dest, destStart, numElements) {
for (let i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
dest[j] = source[i];
}
}
static arrayFill(array, fromIndex, toIndex, value) {
for (let i = fromIndex; i < toIndex; i++)
array[i] = value;
}
static setArraySize(array, size, value = 0) {
let oldSize = array.length;
if (oldSize == size)
return array;
array.length = size;
if (oldSize < size) {
for (let i = oldSize; i < size; i++)
array[i] = value;
}
return array;
}
static ensureArrayCapacity(array, size, value = 0) {
if (array.length >= size)
return array;
return _Utils.setArraySize(array, size, value);
}
static newArray(size, defaultValue) {
let array = new Array(size);
for (let i = 0; i < size; i++)
array[i] = defaultValue;
return array;
}
static newFloatArray(size) {
if (_Utils.SUPPORTS_TYPED_ARRAYS)
return new Float32Array(size);
else {
let array = new Array(size);
for (let i = 0; i < array.length; i++)
array[i] = 0;
return array;
}
}
static newShortArray(size) {
if (_Utils.SUPPORTS_TYPED_ARRAYS)
return new Int16Array(size);
else {
let array = new Array(size);
for (let i = 0; i < array.length; i++)
array[i] = 0;
return array;
}
}
static toFloatArray(array) {
return _Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
}
static toSinglePrecision(value) {
return _Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value;
}
static webkit602BugfixHelper(alpha, blend) {
}
static contains(array, element, identity = true) {
for (var i = 0; i < array.length; i++)
if (array[i] == element)
return true;
return false;
}
static enumValue(type, name) {
return type[name[0].toUpperCase() + name.slice(1)];
}
};
var Utils = _Utils;
Utils.SUPPORTS_TYPED_ARRAYS = typeof Float32Array !== "undefined";
var DebugUtils = class {
static logBones(skeleton) {
for (let i = 0; i < skeleton.bones.length; i++) {
let bone = skeleton.bones[i];
console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY);
}
}
};
var Pool = class {
constructor(instantiator) {
this.items = new Array();
this.instantiator = instantiator;
}
obtain() {
return this.items.length > 0 ? this.items.pop() : this.instantiator();
}
free(item) {
if (item.reset)
item.reset();
this.items.push(item);
}
freeAll(items) {
for (let i = 0; i < items.length; i++)
this.free(items[i]);
}
clear() {
this.items.length = 0;
}
};
var Vector2 = class {
constructor(x = 0, y = 0) {
this.x = x;
this.y = y;
}
set(x, y) {
this.x = x;
this.y = y;
return this;
}
length() {
let x = this.x;
let y = this.y;
return Math.sqrt(x * x + y * y);
}
normalize() {
let len = this.length();
if (len != 0) {
this.x /= len;
this.y /= len;
}
return this;
}
};
var TimeKeeper = class {
constructor() {
this.maxDelta = 0.064;
this.framesPerSecond = 0;
this.delta = 0;
this.totalTime = 0;
this.lastTime = Date.now() / 1e3;
this.frameCount = 0;
this.frameTime = 0;
}
update() {
let now = Date.now() / 1e3;
this.delta = now - this.lastTime;
this.frameTime += this.delta;
this.totalTime += this.delta;
if (this.delta > this.maxDelta)
this.delta = this.maxDelta;
this.lastTime = now;
this.frameCount++;
if (this.frameTime > 1) {
this.framesPerSecond = this.frameCount / this.frameTime;
this.frameTime = 0;
this.frameCount = 0;
}
}
};
var WindowedMean = class {
constructor(windowSize = 32) {
this.addedValues = 0;
this.lastValue = 0;
this.mean = 0;
this.dirty = true;
this.values = new Array(windowSize);
}
hasEnoughData() {
return this.addedValues >= this.values.length;
}
addValue(value) {
if (this.addedValues < this.values.length)
this.addedValues++;
this.values[this.lastValue++] = value;
if (this.lastValue > this.values.length - 1)
this.lastValue = 0;
this.dirty = true;
}
getMean() {
if (this.hasEnoughData()) {
if (this.dirty) {
let mean = 0;
for (let i = 0; i < this.values.length; i++)
mean += this.values[i];
this.mean = mean / this.values.length;
this.dirty = false;
}
return this.mean;
}
return 0;
}
};
// spine-core/src/attachments/Attachment.ts
var Attachment = class {
constructor(name) {
if (!name)
throw new Error("name cannot be null.");
this.name = name;
}
};
var _VertexAttachment = class extends Attachment {
constructor(name) {
super(name);
this.id = _VertexAttachment.nextID++;
this.bones = null;
this.vertices = null;
this.worldVerticesLength = 0;
this.timelineAttahment = this;
}
computeWorldVertices(slot, start, count, worldVertices, offset, stride) {
count = offset + (count >> 1) * stride;
let skeleton = slot.bone.skeleton;
let deformArray = slot.deform;
let vertices = this.vertices;
let bones = this.bones;
if (!bones) {
if (deformArray.length > 0)
vertices = deformArray;
let bone = slot.bone;
let x = bone.worldX;
let y = bone.worldY;
let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
for (let v2 = start, w = offset; w < count; v2 += 2, w += stride) {
let vx = vertices[v2], vy = vertices[v2 + 1];
worldVertices[w] = vx * a + vy * b + x;
worldVertices[w + 1] = vx * c + vy * d + y;
}
return;
}
let v = 0, skip = 0;
for (let i = 0; i < start; i += 2) {
let n = bones[v];
v += n + 1;
skip += n;
}
let skeletonBones = skeleton.bones;
if (deformArray.length == 0) {
for (let w = offset, b = skip * 3; w < count; w += stride) {
let wx = 0, wy = 0;
let n = bones[v++];
n += v;
for (; v < n; v++, b += 3) {
let bone = skeletonBones[bones[v]];
let vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
}
worldVertices[w] = wx;
worldVertices[w + 1] = wy;
}
} else {
let deform = deformArray;
for (let w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
let wx = 0, wy = 0;
let n = bones[v++];
n += v;
for (; v < n; v++, b += 3, f += 2) {
let bone = skeletonBones[bones[v]];
let vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
}
worldVertices[w] = wx;
worldVertices[w + 1] = wy;
}
}
}
copyTo(attachment) {
if (this.bones) {
attachment.bones = new Array(this.bones.length);
Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
} else
attachment.bones = null;
if (this.vertices) {
attachment.vertices = Utils.newFloatArray(this.vertices.length);
Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
} else
attachment.vertices = null;
attachment.worldVerticesLength = this.worldVerticesLength;
attachment.timelineAttahment = this.timelineAttahment;
}
};
var VertexAttachment = _VertexAttachment;
VertexAttachment.nextID = 0;
// spine-core/src/attachments/Sequence.ts
var _Sequence = class {
constructor(count) {
this.id = _Sequence.nextID();
this.start = 0;
this.digits = 0;
this.setupIndex = 0;
this.regions = new Array(count);
}
copy() {
let copy = new _Sequence(this.regions.length);
Utils.arrayCopy(this.regions, 0, copy.regions, 0, this.regions.length);
copy.start = this.start;
copy.digits = this.digits;
copy.setupIndex = this.setupIndex;
return copy;
}
apply(slot, attachment) {
let index = slot.sequenceIndex;
if (index == -1)
index = this.setupIndex;
if (index >= this.regions.length)
index = this.regions.length - 1;
let region = this.regions[index];
if (attachment.region != region) {
attachment.region = region;
attachment.updateRegion();
}
}
getPath(basePath, index) {
let result = basePath;
let frame = (this.start + index).toString();
for (let i = this.digits - frame.length; i > 0; i--)
result += "0";
result += frame;
return result;
}
static nextID() {
return _Sequence._nextID++;
}
};
var Sequence = _Sequence;
Sequence._nextID = 0;
var SequenceMode;
(function(SequenceMode2) {
SequenceMode2[SequenceMode2["hold"] = 0] = "hold";
SequenceMode2[SequenceMode2["once"] = 1] = "once";
SequenceMode2[SequenceMode2["loop"] = 2] = "loop";
SequenceMode2[SequenceMode2["pingpong"] = 3] = "pingpong";
SequenceMode2[SequenceMode2["onceReverse"] = 4] = "onceReverse";
SequenceMode2[SequenceMode2["loopReverse"] = 5] = "loopReverse";
SequenceMode2[SequenceMode2["pingpongReverse"] = 6] = "pingpongReverse";
})(SequenceMode || (SequenceMode = {}));
var SequenceModeValues = [
0,
1,
2,
3,
4,
5,
6
];
// spine-core/src/Animation.ts
var Animation = class {
constructor(name, timelines, duration) {
this.timelines = null;
this.timelineIds = null;
if (!name)
throw new Error("name cannot be null.");
this.name = name;
this.setTimelines(timelines);
this.duration = duration;
}
setTimelines(timelines) {
if (!timelines)
throw new Error("timelines cannot be null.");
this.timelines = timelines;
this.timelineIds = new StringSet();
for (var i = 0; i < timelines.length; i++)
this.timelineIds.addAll(timelines[i].getPropertyIds());
}
hasTimeline(ids) {
for (let i = 0; i < ids.length; i++)
if (this.timelineIds.contains(ids[i]))
return true;
return false;
}
apply(skeleton, lastTime, time, loop, events, alpha, blend, direction) {
if (!skeleton)
throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) {
time %= this.duration;
if (lastTime > 0)
lastTime %= this.duration;
}
let timelines = this.timelines;
for (let i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction);
}
};
var MixBlend;
(function(MixBlend2) {
MixBlend2[MixBlend2["setup"] = 0] = "setup";
MixBlend2[MixBlend2["first"] = 1] = "first";
MixBlend2[MixBlend2["replace"] = 2] = "replace";
MixBlend2[MixBlend2["add"] = 3] = "add";
})(MixBlend || (MixBlend = {}));
var MixDirection;
(function(MixDirection2) {
MixDirection2[MixDirection2["mixIn"] = 0] = "mixIn";
MixDirection2[MixDirection2["mixOut"] = 1] = "mixOut";
})(MixDirection || (MixDirection = {}));
var Property = {
rotate: 0,
x: 1,
y: 2,
scaleX: 3,
scaleY: 4,
shearX: 5,
shearY: 6,
rgb: 7,
alpha: 8,
rgb2: 9,
attachment: 10,
deform: 11,
event: 12,
drawOrder: 13,
ikConstraint: 14,
transformConstraint: 15,
pathConstraintPosition: 16,
pathConstraintSpacing: 17,
pathConstraintMix: 18,
sequence: 19
};
var Timeline = class {
constructor(frameCount, propertyIds) {
this.propertyIds = null;
this.frames = null;
this.propertyIds = propertyIds;
this.frames = Utils.newFloatArray(frameCount * this.getFrameEntries());
}
getPropertyIds() {
return this.propertyIds;
}
getFrameEntries() {
return 1;
}
getFrameCount() {
return this.frames.length / this.getFrameEntries();
}
getDuration() {
return this.frames[this.frames.length - this.getFrameEntries()];
}
static search1(frames, time) {
let n = frames.length;
for (let i = 1; i < n; i++)
if (frames[i] > time)
return i - 1;
return n - 1;
}
static search(frames, time, step) {
let n = frames.length;
for (let i = step; i < n; i += step)
if (frames[i] > time)
return i - step;
return n - step;
}
};
var CurveTimeline = class extends Timeline {
constructor(frameCount, bezierCount, propertyIds) {
super(frameCount, propertyIds);
this.curves = null;
this.curves = Utils.newFloatArray(frameCount + bezierCount * 18);
this.curves[frameCount - 1] = 1;
}
setLinear(frame) {
this.curves[frame] = 0;
}
setStepped(frame) {
this.curves[frame] = 1;
}
shrink(bezierCount) {
let size = this.getFrameCount() + bezierCount * 18;
if (this.curves.length > size) {
let newCurves = Utils.newFloatArray(size);
Utils.arrayCopy(this.curves, 0, newCurves, 0, size);
this.curves = newCurves;
}
}
setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2) {
let curves = this.curves;
let i = this.getFrameCount() + bezier * 18;
if (value == 0)
curves[frame] = 2 + i;
let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03;
let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 6e-3, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 6e-3;
let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667;
let x = time1 + dx, y = value1 + dy;
for (let n = i + 18; i < n; i += 2) {
curves[i] = x;
curves[i + 1] = y;
dx += ddx;
dy += ddy;
ddx += dddx;
ddy += dddy;
x += dx;
y += dy;
}
}
getBezierValue(time, frameIndex, valueOffset, i) {
let curves = this.curves;
if (curves[i] > time) {
let x2 = this.frames[frameIndex], y2 = this.frames[frameIndex + valueOffset];
return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2);
}
let n = i + 18;
for (i += 2; i < n; i += 2) {
if (curves[i] >= time) {
let x2 = curves[i - 2], y2 = curves[i - 1];
return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2);
}
}
frameIndex += this.getFrameEntries();
let x = curves[n - 2], y = curves[n - 1];
return y + (time - x) / (this.frames[frameIndex] - x) * (this.frames[frameIndex + valueOffset] - y);
}
};
var CurveTimeline1 = class extends CurveTimeline {
constructor(frameCount, bezierCount, propertyId) {
super(frameCount, bezierCount, [propertyId]);
}
getFrameEntries() {
return 2;
}
setFrame(frame, time, value) {
frame <<= 1;
this.frames[frame] = time;
this.frames[frame + 1] = value;
}
getCurveValue(time) {
let frames = this.frames;
let i = frames.length - 2;
for (let ii = 2; ii <= i; ii += 2) {
if (frames[ii] > time) {
i = ii - 2;
break;
}
}
let curveType = this.curves[i >> 1];
switch (curveType) {
case 0:
let before = frames[i], value = frames[i + 1];
return value + (time - before) / (frames[i + 2] - before) * (frames[i + 2 + 1] - value);
case 1:
return frames[i + 1];
}
return this.getBezierValue(time, i, 1, curveType - 2);
}
};
var CurveTimeline2 = class extends CurveTimeline {
constructor(frameCount, bezierCount, propertyId1, propertyId2) {
super(frameCount, bezierCount, [propertyId1, propertyId2]);
}
getFrameEntries() {
return 3;
}
setFrame(frame, time, value1, value2) {
frame *= 3;
this.frames[frame] = time;
this.frames[frame + 1] = value1;
this.frames[frame + 2] = value2;
}
};
var RotateTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.rotate + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.rotation = bone.data.rotation;
return;
case 1:
bone.rotation += (bone.data.rotation - bone.rotation) * alpha;
}
return;
}
let r = this.getCurveValue(time);
switch (blend) {
case 0:
bone.rotation = bone.data.rotation + r * alpha;
break;
case 1:
case 2:
r += bone.data.rotation - bone.rotation;
case 3:
bone.rotation += r * alpha;
}
}
};
var TranslateTimeline = class extends CurveTimeline2 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.x + "|" + boneIndex, Property.y + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case 1:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
}
return;
}
let x = 0, y = 0;
let i = Timeline.search(frames, time, 3);
let curveType = this.curves[i / 3];
switch (curveType) {
case 0:
let before = frames[i];
x = frames[i + 1];
y = frames[i + 2];
let t = (time - before) / (frames[i + 3] - before);
x += (frames[i + 3 + 1] - x) * t;
y += (frames[i + 3 + 2] - y) * t;
break;
case 1:
x = frames[i + 1];
y = frames[i + 2];
break;
default:
x = this.getBezierValue(time, i, 1, curveType - 2);
y = this.getBezierValue(time, i, 2, curveType + 18 - 2);
}
switch (blend) {
case 0:
bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha;
break;
case 1:
case 2:
bone.x += (bone.data.x + x - bone.x) * alpha;
bone.y += (bone.data.y + y - bone.y) * alpha;
break;
case 3:
bone.x += x * alpha;
bone.y += y * alpha;
}
}
};
var TranslateXTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.x + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.x = bone.data.x;
return;
case 1:
bone.x += (bone.data.x - bone.x) * alpha;
}
return;
}
let x = this.getCurveValue(time);
switch (blend) {
case 0:
bone.x = bone.data.x + x * alpha;
break;
case 1:
case 2:
bone.x += (bone.data.x + x - bone.x) * alpha;
break;
case 3:
bone.x += x * alpha;
}
}
};
var TranslateYTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.y + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.y = bone.data.y;
return;
case 1:
bone.y += (bone.data.y - bone.y) * alpha;
}
return;
}
let y = this.getCurveValue(time);
switch (blend) {
case 0:
bone.y = bone.data.y + y * alpha;
break;
case 1:
case 2:
bone.y += (bone.data.y + y - bone.y) * alpha;
break;
case 3:
bone.y += y * alpha;
}
}
};
var ScaleTimeline = class extends CurveTimeline2 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.scaleX + "|" + boneIndex, Property.scaleY + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY;
return;
case 1:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
}
return;
}
let x, y;
let i = Timeline.search(frames, time, 3);
let curveType = this.curves[i / 3];
switch (curveType) {
case 0:
let before = frames[i];
x = frames[i + 1];
y = frames[i + 2];
let t = (time - before) / (frames[i + 3] - before);
x += (frames[i + 3 + 1] - x) * t;
y += (frames[i + 3 + 2] - y) * t;
break;
case 1:
x = frames[i + 1];
y = frames[i + 2];
break;
default:
x = this.getBezierValue(time, i, 1, curveType - 2);
y = this.getBezierValue(time, i, 2, curveType + 18 - 2);
}
x *= bone.data.scaleX;
y *= bone.data.scaleY;
if (alpha == 1) {
if (blend == 3) {
bone.scaleX += x - bone.data.scaleX;
bone.scaleY += y - bone.data.scaleY;
} else {
bone.scaleX = x;
bone.scaleY = y;
}
} else {
let bx = 0, by = 0;
if (direction == 1) {
switch (blend) {
case 0:
bx = bone.data.scaleX;
by = bone.data.scaleY;
bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
break;
case 1:
case 2:
bx = bone.scaleX;
by = bone.scaleY;
bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
break;
case 3:
bone.scaleX = (x - bone.data.scaleX) * alpha;
bone.scaleY = (y - bone.data.scaleY) * alpha;
}
} else {
switch (blend) {
case 0:
bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
bone.scaleX = bx + (x - bx) * alpha;
bone.scaleY = by + (y - by) * alpha;
break;
case 1:
case 2:
bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
by = Math.abs(bone.scaleY) * MathUtils.signum(y);
bone.scaleX = bx + (x - bx) * alpha;
bone.scaleY = by + (y - by) * alpha;
break;
case 3:
bone.scaleX += (x - bone.data.scaleX) * alpha;
bone.scaleY += (y - bone.data.scaleY) * alpha;
}
}
}
}
};
var ScaleXTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.scaleX + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.scaleX = bone.data.scaleX;
return;
case 1:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
}
return;
}
let x = this.getCurveValue(time) * bone.data.scaleX;
if (alpha == 1) {
if (blend == 3)
bone.scaleX += x - bone.data.scaleX;
else
bone.scaleX = x;
} else {
let bx = 0;
if (direction == 1) {
switch (blend) {
case 0:
bx = bone.data.scaleX;
bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
break;
case 1:
case 2:
bx = bone.scaleX;
bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
break;
case 3:
bone.scaleX = (x - bone.data.scaleX) * alpha;
}
} else {
switch (blend) {
case 0:
bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
bone.scaleX = bx + (x - bx) * alpha;
break;
case 1:
case 2:
bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
bone.scaleX = bx + (x - bx) * alpha;
break;
case 3:
bone.scaleX += (x - bone.data.scaleX) * alpha;
}
}
}
}
};
var ScaleYTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.scaleY + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.scaleY = bone.data.scaleY;
return;
case 1:
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
}
return;
}
let y = this.getCurveValue(time) * bone.data.scaleY;
if (alpha == 1) {
if (blend == 3)
bone.scaleY += y - bone.data.scaleY;
else
bone.scaleY = y;
} else {
let by = 0;
if (direction == 1) {
switch (blend) {
case 0:
by = bone.data.scaleY;
bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
break;
case 1:
case 2:
by = bone.scaleY;
bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
break;
case 3:
bone.scaleY = (y - bone.data.scaleY) * alpha;
}
} else {
switch (blend) {
case 0:
by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
bone.scaleY = by + (y - by) * alpha;
break;
case 1:
case 2:
by = Math.abs(bone.scaleY) * MathUtils.signum(y);
bone.scaleY = by + (y - by) * alpha;
break;
case 3:
bone.scaleY += (y - bone.data.scaleY) * alpha;
}
}
}
}
};
var ShearTimeline = class extends CurveTimeline2 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.shearX + "|" + boneIndex, Property.shearY + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY;
return;
case 1:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
}
return;
}
let x = 0, y = 0;
let i = Timeline.search(frames, time, 3);
let curveType = this.curves[i / 3];
switch (curveType) {
case 0:
let before = frames[i];
x = frames[i + 1];
y = frames[i + 2];
let t = (time - before) / (frames[i + 3] - before);
x += (frames[i + 3 + 1] - x) * t;
y += (frames[i + 3 + 2] - y) * t;
break;
case 1:
x = frames[i + 1];
y = frames[i + 2];
break;
default:
x = this.getBezierValue(time, i, 1, curveType - 2);
y = this.getBezierValue(time, i, 2, curveType + 18 - 2);
}
switch (blend) {
case 0:
bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha;
break;
case 1:
case 2:
bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
break;
case 3:
bone.shearX += x * alpha;
bone.shearY += y * alpha;
}
}
};
var ShearXTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.shearX + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.shearX = bone.data.shearX;
return;
case 1:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
}
return;
}
let x = this.getCurveValue(time);
switch (blend) {
case 0:
bone.shearX = bone.data.shearX + x * alpha;
break;
case 1:
case 2:
bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
break;
case 3:
bone.shearX += x * alpha;
}
}
};
var ShearYTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, boneIndex) {
super(frameCount, bezierCount, Property.shearY + "|" + boneIndex);
this.boneIndex = 0;
this.boneIndex = boneIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let bone = skeleton.bones[this.boneIndex];
if (!bone.active)
return;
let frames = this.frames;
if (time < frames[0]) {
switch (blend) {
case 0:
bone.shearY = bone.data.shearY;
return;
case 1:
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
}
return;
}
let y = this.getCurveValue(time);
switch (blend) {
case 0:
bone.shearY = bone.data.shearY + y * alpha;
break;
case 1:
case 2:
bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
break;
case 3:
bone.shearY += y * alpha;
}
}
};
var RGBATimeline = class extends CurveTimeline {
constructor(frameCount, bezierCount, slotIndex) {
super(frameCount, bezierCount, [
Property.rgb + "|" + slotIndex,
Property.alpha + "|" + slotIndex
]);
this.slotIndex = 0;
this.slotIndex = slotIndex;
}
getFrameEntries() {
return 5;
}
setFrame(frame, time, r, g, b, a) {
frame *= 5;
this.frames[frame] = time;
this.frames[frame + 1] = r;
this.frames[frame + 2] = g;
this.frames[frame + 3] = b;
this.frames[frame + 4] = a;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let slot = skeleton.slots[this.slotIndex];
if (!slot.bone.active)
return;
let frames = this.frames;
let color = slot.color;
if (time < frames[0]) {
let setup = slot.data.color;
switch (blend) {
case 0:
color.setFromColor(setup);
return;
case 1:
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return;
}
let r = 0, g = 0, b = 0, a = 0;
let i = Timeline.search(frames, time, 5);
let curveType = this.curves[i / 5];
switch (curveType) {
case 0:
let before = frames[i];
r = frames[i + 1];
g = frames[i + 2];
b = frames[i + 3];
a = frames[i + 4];
let t = (time - before) / (frames[i + 5] - before);
r += (frames[i + 5 + 1] - r) * t;
g += (frames[i + 5 + 2] - g) * t;
b += (frames[i + 5 + 3] - b) * t;
a += (frames[i + 5 + 4] - a) * t;
break;
case 1:
r = frames[i + 1];
g = frames[i + 2];
b = frames[i + 3];
a = frames[i + 4];
break;
default:
r = this.getBezierValue(time, i, 1, curveType - 2);
g = this.getBezierValue(time, i, 2, curveType + 18 - 2);
b = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
a = this.getBezierValue(time, i, 4, curveType + 18 * 3 - 2);
}
if (alpha == 1)
color.set(r, g, b, a);
else {
if (blend == 0)
color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
}
}
};
var RGBTimeline = class extends CurveTimeline {
constructor(frameCount, bezierCount, slotIndex) {
super(frameCount, bezierCount, [
Property.rgb + "|" + slotIndex
]);
this.slotIndex = 0;
this.slotIndex = slotIndex;
}
getFrameEntries() {
return 4;
}
setFrame(frame, time, r, g, b) {
frame <<= 2;
this.frames[frame] = time;
this.frames[frame + 1] = r;
this.frames[frame + 2] = g;
this.frames[frame + 3] = b;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let slot = skeleton.slots[this.slotIndex];
if (!slot.bone.active)
return;
let frames = this.frames;
let color = slot.color;
if (time < frames[0]) {
let setup = slot.data.color;
switch (blend) {
case 0:
color.r = setup.r;
color.g = setup.g;
color.b = setup.b;
return;
case 1:
color.r += (setup.r - color.r) * alpha;
color.g += (setup.g - color.g) * alpha;
color.b += (setup.b - color.b) * alpha;
}
return;
}
let r = 0, g = 0, b = 0;
let i = Timeline.search(frames, time, 4);
let curveType = this.curves[i >> 2];
switch (curveType) {
case 0:
let before = frames[i];
r = frames[i + 1];
g = frames[i + 2];
b = frames[i + 3];
let t = (time - before) / (frames[i + 4] - before);
r += (frames[i + 4 + 1] - r) * t;
g += (frames[i + 4 + 2] - g) * t;
b += (frames[i + 4 + 3] - b) * t;
break;
case 1:
r = frames[i + 1];
g = frames[i + 2];
b = frames[i + 3];
break;
default:
r = this.getBezierValue(time, i, 1, curveType - 2);
g = this.getBezierValue(time, i, 2, curveType + 18 - 2);
b = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
}
if (alpha == 1) {
color.r = r;
color.g = g;
color.b = b;
} else {
if (blend == 0) {
let setup = slot.data.color;
color.r = setup.r;
color.g = setup.g;
color.b = setup.b;
}
color.r += (r - color.r) * alpha;
color.g += (g - color.g) * alpha;
color.b += (b - color.b) * alpha;
}
}
};
var AlphaTimeline = class extends CurveTimeline1 {
constructor(frameCount, bezierCount, slotIndex) {
super(frameCount, bezierCount, Property.alpha + "|" + slotIndex);
this.slotIndex = 0;
this.slotIndex = slotIndex;
}
apply(skeleton, lastTime, time, events, alpha, blend, direction) {
let slot = skeleton.slots[this.slotIndex];
if (!slot.bone.active)
return;
let color = slot.color;
if (time < this.frames[0]) {
let setup = slot.data.color;
switch (blend) {
case 0:
color.a = setup.a;
return;
case 1:
color.a += (setup.a - color.a) * alpha;
}
return;
}
let a = this.getCurveValue(time);
if (alpha == 1)
color.a = a;
else {
if (blend == 0)
color.a = sl