spine-html 1.25.0 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_play-runtime.js","sources":["../node_modules/@rig-c/core/src/core/world.ts","../node_modules/@rig-c/core/src/core/skins.ts","../node_modules/@rig-c/core/src/core/deform.ts","../node_modules/@rig-c/core/src/core/draw_order.ts","../node_modules/@rig-c/core/src/core/events.ts","../node_modules/@rig-c/core/src/core/clipping.ts","../node_modules/@rig-c/core/src/core/vertices.ts","../node_modules/@rig-c/core/src/core/constraints_path.ts","../node_modules/@rig-c/core/src/core/constraints_physics.ts","../node_modules/@rig-c/core/src/core/constraints_slider.ts","../node_modules/@rig-c/core/src/core/constraints.ts","../node_modules/@rig-c/core/src/core/animation.ts","../node_modules/@rig-c/core/src/core/index.ts","../node_modules/@rig-c/core/src/core/raw.ts","../node_modules/@rig-c/core/src/core/physics_parameters.ts","../node_modules/@rig-c/core/src/core/track.ts","../node_modules/@rig-c/core/src/core/tracks.ts","../node_modules/@rig-c/core/src/core/uvs.ts","../src/liveFrameSource.ts","../src/pixelRatio.ts","../src/DomTexture.ts","../src/MeshGlBlitter.ts","../src/DomRenderer.ts","../src/CanvasRenderer.ts","../src/loadModel.ts","../node_modules/@rig-c/core/src/runtime/curves.ts","../node_modules/@rig-c/core/src/runtime/model.ts","../node_modules/@rig-c/core/src/runtime/clipping.ts","../node_modules/@rig-c/core/src/runtime/clip_draw.ts","../node_modules/@rig-c/core/src/runtime/physics.ts","../node_modules/@rig-c/core/src/runtime/pose.ts","../src/posedFrame.ts","../src/liveFrame.ts","../src/player.ts","../src/turnDials.ts"],"sourcesContent":["/**\n * The core's own setup evaluator: every bone's world matrix and origin from\n * the compiled model's bones (issue #925). Written from what a bone's fields\n * mean and from measurement against the runtime's pose dump\n * (`tools/pose_oracle.ts dump`, spine-core 4.3.13), and held to it by the core\n * suite's equivalence controls.\n *\n * ⭐ **The compiler's setup transforms are this evaluator too** (issue #1015),\n * under the same arithmetic (issue #1021). `src/transform.ts` held a second\n * evaluator of its own until #1015, and the two differed in exactly three\n * places, none of them a different matrix: the degree factor (`Math.PI / 180`\n * there, the runtime's 3.1415927 here), the frame of a bone with scale 1 and\n * no shear (`[cos, −sin, sin, cos]` of the rotation there, the y column at\n * `rotation + 90` here), and how a radian angle is turned into degrees\n * (divided by the degree factor there, multiplied by `180 / pi` here). #1015\n * made them a parameter (`WorldArithmetic`) so that no byte moved; #1021\n * measured which binds closer — every point the compiler binds from a world\n * position, posed by spine-core from the emitted build, against that position\n * — and the runtime's three put every one at the float32 floor where the\n * compiler's left `gallery/look`'s up to 8.6e-5 off. So the compiler passes\n * none now, and `RUNTIME_ARITHMETIC`, the measured choices below, is the only\n * arithmetic anything here runs under; the parameter stays for the plants\n * that swap one choice back in to show a control fire.\n *\n * ## What each measured choice is\n *\n * - **Degrees to radians with pi written 3.1415927.** The runtime's root bone\n * at rotation 0 reads `b = -2.3205103333142417e-8` and\n * `d = 0.9999999999999998`: `cos` and `sin` of 90 degrees converted with\n * pi = 3.1415927, since `(3.1415927 - pi) / 2 = 2.3205e-8`. It is that\n * decimal in double arithmetic — not float32: pi rounded to float32 would\n * give `4.37e-8`, and the bone fields read through `Math.fround` moved the\n * dump further, not closer (measured on the nineteen recipes).\n * - **The degree factor is taken once**, `pi / 180`, and every angle is\n * multiplied by it.\n * - **The y column is `cos(rotation + 90 + shearY)` and `sin(…)` on every\n * bone**, never `-sin`/`cos` of the rotation. With the constant above but\n * the `-sin` form, `2-the-12-principles` stays 61 millionths off.\n * - **A root bone is its local matrix at its own `x`, `y`**: the skeleton is\n * at the origin, unscaled, in every dump taken.\n *\n * Both halves together read IDENTICAL, worst delta exactly 0, on the 12\n * recipes without constraints (`tools/core_gate.ts`); either half alone is\n * exact on none of them.\n *\n * ## The five inherit modes\n *\n * What each mode takes from the parent, as the format's documentation words\n * it, then how it is computed here. A child's ORIGIN is always the parent's\n * matrix applied to the local `x`, `y` plus the parent's origin — the modes\n * change only the matrix.\n *\n * - `normal` — everything: parent matrix times local matrix.\n * - `onlyTranslation` — the parent's position only: the local matrix alone.\n * - `noRotationOrReflection` — the parent's scale (and what shear leaves of\n * it), not its rotation and not a reflection. The parent's matrix is made\n * conformal on its x axis: that axis kept, the y axis turned to 90 degrees\n * from it with length `|det| / |x axis|` (so the area, the scale the parent\n * carries, is kept and its sign is not); the local matrix is built at the\n * bone's rotation MINUS the parent's x-axis angle; the product is the world.\n * ⚠️ **A parent x axis whose squared length is at most `1e-5` squared is\n * collapsed** (issue #979, `COLLAPSED_X_AXIS_SQ`): the conformal frame is\n * then the parent's y column with its x component negated, beside a zero x\n * column, and the local matrix is built at the rotation less 90 plus the y\n * column's angle, summed in that order. Measured on a child of such a\n * parent: by bisection on the x axis's length, 1e-5 reads collapsed and the\n * next double above does not, at parent rotations 0, 30 and 45 (whether the\n * runtime compares the squared length with `1e-5 · 1e-5` or the length with\n * `1e-5`, 200,000 parents searched separated no pair); 480 probes of x axes\n * from 1e-4 down to 1e-20 and 0 under y axes up to 2e17, sheared, scaled and\n * reflected, read exact, where the reading this replaced (collapsed only at\n * length 0, the y column as it is, the angle less 90) read 71 of 96 off and\n * the rotation-first sum `rotation − (90 − angle)` 10 of 480. The zero\n * matrix of a bone below an inactive one is the collapsed case at length 0,\n * and it fixes the signs of zero of every child in this mode there (`CC13`).\n * - `noScale` — the parent's rotation (and reflection), not its scale: the\n * bone's local rotation is carried through the parent's matrix as a\n * direction, normalised to unit length; the y axis is that direction turned\n * 90 degrees, turned the other way when the parent reflects (`det < 0`);\n * the bone's own shear and scale are applied on that frame.\n * - `noScaleOrReflection` — as `noScale`, never turned for a reflection.\n *\n * ## To the bit (issue #966)\n *\n * The rules above were measured on the oracle's six-decimal grid; three of\n * the modes matched it and not the runtime's last bit (issue #959). Held\n * against `pose_oracle.ts dump --raw` at tolerance 0 — a bone in the mode\n * under a parent rotated, scaled, sheared and reflecting, two children 1e9\n * units out (the core suite's `CR02`, 300 per mode) — three operation orders\n * are the runtime's and the grid could not tell them:\n *\n * - a radian angle is turned into degrees by multiplying with `180 / pi`\n * (`RUNTIME_DEG`), not by dividing by `pi / 180`: the division read 106\n * of 300 `noRotationOrReflection` bones off;\n * - `noRotationOrReflection`'s y angle is `r + shearY + 90`, the shear\n * added before the right angle (`r + 90 + shearY` read 46 of 300 off);\n * - `noScale`'s direction is normalised by multiplying with the reciprocal\n * of its length (dividing read 138 of 300 off).\n *\n * Measured: `normal` on 12 recipes, `onlyTranslation` on 1 and\n * `noRotationOrReflection` on 2 of the tree's corpus; all five, under rotated,\n * scaled, sheared and reflecting parents, on the hand-written probe the core\n * suite builds (`CO07`), because the corpus reaches `noScale` only on a rig\n * with constraints and `noScaleOrReflection` on none.\n */\nimport type { ModelBone } from '../model.ts';\n\n/** Pi as the runtime converts degrees with it — see the header. */\nexport const RUNTIME_PI = 3.1415927;\nconst RAD = RUNTIME_PI / 180;\n/** Radians to degrees as the runtime converts them (issue #966): multiplied by `180 / pi`, not divided by `pi / 180` — the two differ in the last bit. */\nexport const RUNTIME_DEG = 180 / RUNTIME_PI;\n\n/** A parent x axis whose squared length is at most this is collapsed for `noRotationOrReflection` (issue #979): `1e-5` squared, as measured — see the header. */\nexport const COLLAPSED_X_AXIS_SQ = 0.00001 * 0.00001;\n\n/**\n * The three places an evaluator's arithmetic may differ in the last bit while\n * computing the same matrix (issue #1015) — see the header. The core poses and\n * the compiler binds with `RUNTIME_ARITHMETIC` (issue #1021); another value is\n * a plant's.\n */\nexport interface WorldArithmetic {\n /** Degrees to radians: every angle is multiplied by it. */\n radiansPerDegree: number;\n /** Radians to degrees — the angle `noRotationOrReflection` takes off a parent's axis. */\n degreesOf: (radians: number) => number;\n /** A bone with scale 1 and no shear takes `[cos r, −sin r, sin r, cos r]` instead of the y column at `r + 90`; the general frame everywhere else. */\n rotationOnlyFrame: boolean;\n}\n\n/** The runtime's arithmetic, as measured (the header's three choices): what the core poses with. */\nexport const RUNTIME_ARITHMETIC: WorldArithmetic = {\n radiansPerDegree: RAD,\n degreesOf: (radians) => radians * RUNTIME_DEG,\n rotationOnlyFrame: false,\n};\n\n/** One bone's world transform: the matrix `[a b; c d]` and the origin, y up. */\nexport interface CoreWorld {\n a: number;\n b: number;\n c: number;\n d: number;\n worldX: number;\n worldY: number;\n}\n\n/** The five modes, after the first-letter fold the rig spec admits. */\nexport type CoreInheritMode = 'normal' | 'onlyTranslation' | 'noRotationOrReflection' | 'noScale' | 'noScaleOrReflection';\n\nexport type M2 = [number, number, number, number];\n\n/** What computes a child's world matrix from its mode, its parent's world, its own fields and the arithmetic in force. */\nexport type InheritComputation = (mode: CoreInheritMode, parent: CoreWorld, bone: ModelBone, arithmetic: WorldArithmetic) => M2;\n\n/** The matrix of a rotation, shears and scales, in the column form the header states. */\nfunction frame(rotation: number, shearX: number, shearY: number, scaleX: number, scaleY: number, rad: number = RAD): M2 {\n const xAngle = (rotation + shearX) * rad;\n const yAngle = (rotation + 90 + shearY) * rad;\n return [Math.cos(xAngle) * scaleX, Math.cos(yAngle) * scaleY, Math.sin(xAngle) * scaleX, Math.sin(yAngle) * scaleY];\n}\n\n/** A bone's own frame — a root's matrix, and the local factor of `normal` and `onlyTranslation` — under `arithmetic`. */\nfunction localFrame(arithmetic: WorldArithmetic, rotation: number, shearX: number, shearY: number, scaleX: number, scaleY: number): M2 {\n const rad = arithmetic.radiansPerDegree;\n if (arithmetic.rotationOnlyFrame && scaleX === 1 && scaleY === 1 && shearX === 0 && shearY === 0) {\n const cos = Math.cos(rotation * rad);\n const sin = Math.sin(rotation * rad);\n return [cos, -sin, sin, cos];\n }\n return frame(rotation, shearX, shearY, scaleX, scaleY, rad);\n}\n\nfunction times(p: M2, q: M2): M2 {\n return [p[0] * q[0] + p[1] * q[2], p[0] * q[1] + p[1] * q[3], p[2] * q[0] + p[3] * q[2], p[2] * q[1] + p[3] * q[3]];\n}\n\n/**\n * The unit direction a `noScale` / `noScaleOrReflection` bone's x axis takes:\n * its local rotation carried through the parent's matrix and normalised. Shared\n * by the forward frame and `localFromWorld`'s read-back (`./constraints.ts`),\n * which builds the frame to read the bone's columns in from the rotation it\n * has just read, through this same arithmetic (issue #966).\n */\nexport function noScaleDirection(p: M2, rotation: number, rad: number = RAD): [number, number] {\n const r = rotation * rad;\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n const ux = p[0] * cos + p[1] * sin;\n const uy = p[2] * cos + p[3] * sin;\n // Normalised by multiplying with the reciprocal of the length, not by dividing by it (issue #966): the division reads 1 ulp off on 375 bone-samples of the corpus's `noScale` row.\n const inverse = 1 / Math.sqrt(ux * ux + uy * uy);\n return [ux * inverse, uy * inverse];\n}\n\n/** The world matrix of a child under `parent` in `mode`, under `arithmetic` (the runtime's unless a caller passes its own). */\nfunction modeMatrix(mode: CoreInheritMode, parent: CoreWorld, bone: ModelBone, arithmetic: WorldArithmetic = RUNTIME_ARITHMETIC): M2 {\n const rotation = bone.rotation ?? 0;\n const shearX = bone.shearX ?? 0;\n const shearY = bone.shearY ?? 0;\n const scaleX = bone.scaleX ?? 1;\n const scaleY = bone.scaleY ?? 1;\n const rad = arithmetic.radiansPerDegree;\n const p: M2 = [parent.a, parent.b, parent.c, parent.d];\n switch (mode) {\n case 'normal':\n return times(p, localFrame(arithmetic, rotation, shearX, shearY, scaleX, scaleY));\n case 'onlyTranslation':\n return localFrame(arithmetic, rotation, shearX, shearY, scaleX, scaleY);\n case 'noRotationOrReflection': {\n const xLengthSq = p[0] * p[0] + p[2] * p[2];\n let conformal: M2;\n let r: number;\n if (xLengthSq > COLLAPSED_X_AXIS_SQ) {\n const k = Math.abs(p[0] * p[3] - p[1] * p[2]) / xLengthSq;\n conformal = [p[0], -p[2] * k, p[2], p[0] * k];\n r = rotation - arithmetic.degreesOf(Math.atan2(p[2], p[0]));\n } else {\n // A collapsed x axis (issue #979): the parent's y column with its x component negated, and the rotation less 90 plus the y column's angle — see the header.\n conformal = [0, -p[1], 0, p[3]];\n r = rotation - 90 + arithmetic.degreesOf(Math.atan2(p[3], p[1]));\n }\n // The y angle adds the shear before the right angle here, unlike `frame` (issue #966): `(r + 90 + shearY)` reads last-bit off on 81 of 205 sheared or scaled bones at a 1e9 amplifier, `(r + shearY + 90)` on none; `r = rotation − parentAngle` taken first (adding the shear before the parent's angle is taken off reads 102 of 205 off).\n const xAngle = (r + shearX) * rad;\n const yAngle = (r + shearY + 90) * rad;\n return times(conformal, [Math.cos(xAngle) * scaleX, Math.cos(yAngle) * scaleY, Math.sin(xAngle) * scaleX, Math.sin(yAngle) * scaleY]);\n }\n case 'noScale':\n case 'noScaleOrReflection': {\n const [ux, uy] = noScaleDirection(p, rotation, rad);\n const flip = mode === 'noScale' && p[0] * p[3] - p[1] * p[2] < 0 ? -1 : 1;\n const turned: M2 = [ux, -uy * flip, uy, ux * flip];\n return times(turned, frame(0, shearX, shearY, scaleX, scaleY, rad));\n }\n }\n}\n\n/** The fold the rig spec admits: the first letter lower-cased; anything else is not a mode. */\nfunction modeOf(bone: ModelBone): CoreInheritMode {\n const stated = bone.inheritMode;\n if (stated === undefined) return 'normal';\n const folded = stated.length === 0 ? stated : stated[0].toLowerCase() + stated.slice(1);\n if (folded === 'normal' || folded === 'onlyTranslation' || folded === 'noRotationOrReflection' || folded === 'noScale' || folded === 'noScaleOrReflection') return folded;\n throw new Error(`bone \"${bone.name}\": inheritMode ${JSON.stringify(stated)} is no mode (readModel refuses it first)`);\n}\n\n/**\n * Every bone's setup world transform, parents first as the model lists them.\n *\n * `active`, when given, is the set of bones the applied skins leave active; a\n * bone outside it is not posed. Measured on a hand-written skeleton: the\n * runtime's dump reads an inactive bone as all zeros — matrix and origin, its\n * world as a skeleton is created — and a bone under it, active or not, is\n * posed from those zeros like any child. `inherit` replaces the mode\n * computation — the core suite's plant passes a copy with one mode's sign\n * flipped, and nothing else does. `arithmetic` is the runtime's unless a\n * caller states its own, and only a plant does: `src/transform.ts` takes the\n * default since issue #1021, as every posing path does.\n */\nexport function worldTransforms(\n bones: readonly ModelBone[],\n active: ReadonlySet<string> | null = null,\n inherit: InheritComputation = modeMatrix,\n arithmetic: WorldArithmetic = RUNTIME_ARITHMETIC,\n): Map<string, CoreWorld> {\n const out = new Map<string, CoreWorld>();\n for (const bone of bones) {\n if (active !== null && !active.has(bone.name)) {\n out.set(bone.name, { a: 0, b: 0, c: 0, d: 0, worldX: 0, worldY: 0 });\n continue;\n }\n const x = bone.x ?? 0;\n const y = bone.y ?? 0;\n if (bone.parent === undefined) {\n const [a, b, c, d] = localFrame(arithmetic, bone.rotation ?? 0, bone.shearX ?? 0, bone.shearY ?? 0, bone.scaleX ?? 1, bone.scaleY ?? 1);\n out.set(bone.name, { a, b, c, d, worldX: x, worldY: y });\n continue;\n }\n const parent = out.get(bone.parent);\n if (parent === undefined) throw new Error(`bone \"${bone.name}\": parent \"${bone.parent}\" is not posed before it`);\n const [a, b, c, d] = inherit(modeOf(bone), parent, bone, arithmetic);\n out.set(bone.name, { a, b, c, d, worldX: parent.a * x + parent.b * y + parent.worldX, worldY: parent.c * x + parent.d * y + parent.worldY });\n }\n return out;\n}\n\n/** The mode computation `worldTransforms` uses, exported so a control can wrap it. */\nexport { modeMatrix };\n","/**\n * The skin a document is posed under (issue #932): every skin merged — the\n * oracle's `--skin all` — or one skin by name, `--skin <name>`. Each rule\n * below was measured by posing hand-written skeletons through\n * `tools/pose_oracle.ts dump --skin <name>` (spine-core 4.3.13) and reading\n * the rows it printed; the core suite's `CN` controls hold the same\n * skeletons against the core at tolerance 0.\n *\n * - **What a slot shows under a named skin**: the named skin's record for\n * the placeholder, else the default skin's, else nothing. Three skins\n * `default`, `s1`, `s2` over five slots — a placeholder the default and\n * `s1` and `s2` fill, one the default alone fills, one `s1` alone, one no\n * skin, one `s1` and the default — dumped under `default`, `s1` and `s2`\n * in two file orders (`default, s1, s2` and `s2, s1, default`): `s1`\n * showed `s1`'s record where it filled the placeholder and the default's\n * where only the default did; `s2` showed `s2`'s, then the default's, and\n * nothing for the placeholder only `s1` fills; a placeholder no skin fills\n * showed nothing under every skin; the two file orders read the same row\n * under every named skin. An attachment key switching the slot at a\n * sample resolves the same way. So a named skin has no order question:\n * nothing a placeholder shows depends on the file's skin order, which the\n * model does not hold (the slots' ⚠️ in `./index.ts`).\n * - **The bones a named skin activates**: a skin-required bone is active\n * exactly when the NAMED skin names it or a bone below it — the default\n * skin's `bones` list does not count. Measured on the same probe: a\n * skin-required bone only the default names read active under `default`\n * and inactive under `s1` and `s2`; one `s1` names, and its skin-required\n * parent, active under `s1` only; a bone that is not skin-required under\n * an inactive one stayed active under every skin.\n * - **The constraints a named skin applies**: a skin-required constraint of\n * any kind is applied exactly when the named skin's list for its kind names\n * it — the default skin's list does not count either (`./constraints.ts`'s\n * header, the nine readings per kind).\n *\n * - **A slot on an inactive bone is not animated** (the commander's private\n * finding on this issue: a 19-skin rig read DIFF on 18 of its 19 skin\n * runs). A slot whose bone the applied skin leaves inactive keeps its\n * setup colour, dark colour and attachment under every slot timeline —\n * `rgba`, `rgb`, `alpha`, `rgba2`, `rgb2` and `attachment` — whether an\n * animation plays it or a slider applies it, and a deform timeline on its\n * attachment does not apply either (a mesh weighted to an ACTIVE bone, so\n * the deform would show: moved by 5 under `all` and `s1`, unmoved under\n * `default`, which leaves the slot's bone inactive). Measured on\n * hand-written skeletons under `--skin all`, `s1` (naming the bone) and\n * `default` (not): each timeline moved the slot under the first two and\n * not under the third, and the setup row read the setup under all three\n * (a slider's key included). A slot on an ACTIVE bone that shows nothing\n * (no skin holds its placeholder) IS animated: every colour key applied,\n * and an attachment key switched it. A draw-order key moves a slot on an\n * inactive bone like any other. A sequence timeline is held by the same\n * gate; its effect on such a slot is not observable in the dump — a\n * region's corners on an inactive bone are all zeros whatever the frame.\n * So the predicate is the slot bone's activity (`slotTimelinesApply`),\n * not what the slot shows; under `all` every bone some skin names is\n * active, so a one-skin rig is unchanged.\n *\n * - **No skin set** (issue #1051): a fresh skeleton whose `setSkin` was never\n * called — `underNoSkin`, the state `render` without `--skin`, A10's walk\n * and `validate()` pose in. No skin's `bones` or constraint lists are\n * applied, the default skin's included, and a slot shows the default\n * skin's record for its placeholder, else nothing — so over a document\n * with skins and no `default` one every slot shows nothing. Measured with\n * `tools/pose_oracle.ts dump --skin none` on 93 skeletons rebuilt through\n * `ingest` and `compile` (31 with no default skin, 31 whose default names\n * skin-required members, 31 with a plain default): `Skeleton.skin` read\n * `null` on all 93; all 311 skin-required bones read inactive — the 51 a\n * default skin names among them, and the 66 a constraint writes — and the\n * 125 bones that are not skin-required under one read active and unposed;\n * all 73 skin-required constraints read inactive and moved nothing when\n * removed — the 12 a default skin lists among them — and the 81 that are\n * not read active; 199 slots whose placeholder the default skin fills\n * showed it and 359 only named skins fill showed nothing; a colour key on\n * a slot whose bone is inactive held its setup colour (50 of 50) and moved\n * it on an active one (46 of 46), and a draw-order key applied either way\n * (93 of 93). The core suite's `CO29` holds the same population against\n * the core under `--raw` at tolerance 0, and `CO30` plants each rejected\n * reading (the old one among them: no skin set read as the default skin,\n * which differs exactly where the default skin names a skin-required\n * member).\n *\n * Under `all` every skin is applied at once: `bones` and the constraint\n * lists of every skin count, and a placeholder several skins fill shows the\n * LAST of them in the Spine file's order — the case `./index.ts` leaves out\n * by name, and the one the per-skin dumps exist to judge.\n */\nimport type { ModelSlot } from '../model.ts';\nimport type { CompiledDocument, CoreSkin } from './index.ts';\n\n/** The skin option that merges every skin — the oracle's `--skin all`. */\nexport const CORE_ALL_SKINS = 'all';\n\n/** The skin a document names its default skin with — Spine's `SkeletonData.defaultSkin` is the skin of this name. */\nexport const CORE_DEFAULT_SKIN = 'default';\n\n/** The skins whose `bones` and constraint lists are applied: every skin under `all`, none with no skin set, the named skin alone otherwise (the header's measurements). */\nexport function appliedSkins(doc: CompiledDocument): CoreSkin[] {\n if (doc.skin === null) return [];\n return doc.skin === CORE_ALL_SKINS ? doc.skins : doc.skins.filter((k) => k.name === doc.skin);\n}\n\n/** Under a named skin or none, the skins a placeholder is looked up in, in precedence order: the named skin, then the default skin (the header's measurements). */\nexport function lookupSkins(doc: CompiledDocument): CoreSkin[] {\n if (doc.skin === CORE_ALL_SKINS) return doc.skins;\n const named = doc.skin === null ? undefined : doc.skins.find((k) => k.name === doc.skin);\n const fallback = doc.skin === CORE_DEFAULT_SKIN ? undefined : doc.skins.find((k) => k.name === CORE_DEFAULT_SKIN);\n return [named, fallback].filter((k): k is CoreSkin => k !== undefined);\n}\n\n/**\n * The skins that could show a slot's placeholder: under `all` every skin\n * filling it — several is the file-order question — and under a named skin\n * the one it resolves to, or none.\n */\nexport function fillingSkins(doc: CompiledDocument, slot: string, placeholder: string): string[] {\n if (doc.skin === CORE_ALL_SKINS) return doc.skins.filter((k) => k.attachments[slot]?.[placeholder] !== undefined).map((k) => k.name);\n const first = lookupSkins(doc).find((k) => k.attachments[slot]?.[placeholder] !== undefined);\n return first === undefined ? [] : [first.name];\n}\n\n/** Whether a slot's timelines — its colour and attachment timelines, and the deform and sequence timelines on what it shows — apply: `slotTimelinesApply` unless a plant passes another. */\nexport type SlotTimelineGate = (doc: CompiledDocument, slot: ModelSlot, active: ReadonlySet<string>) => boolean;\n\n/** A slot's timelines apply exactly when its bone is active under the skin posed (the header's measurement). */\nexport const slotTimelinesApply: SlotTimelineGate = (_doc, slot, active) => active.has(slot.bone);\n\n/** Whether an applied skin's list for `kind` names the constraint — what applies a skin-required one (`./constraints.ts`'s header). */\nexport function listedByAppliedSkin(doc: CompiledDocument, kind: keyof CoreSkin['constraints'], name: string): boolean {\n return appliedSkins(doc).some((k) => k.constraints[kind].includes(name));\n}\n","/**\n * Construct 4 of the core, its remainder (issue #955, step 2f of issue #380):\n * the two timelines an attachment carries — `deform`, a vertex attachment's\n * vertices keyed over time, and `sequence`, the frame a region's series shows\n * — at a sample time, and under a slider at the time and mix it was applied\n * with.\n *\n * Every rule below was measured by posing hand-written skeletons through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13, `--skin all`,\n * `--physics none`) and comparing a formula over the core's own world\n * transforms (`./world.ts`, exact on every probe) with the rows the dump\n * printed, at the oracle's six-decimal rounding. Nothing here was written\n * from the runtime's source. The core suite's `CD` controls hold the same\n * skeletons against the core at tolerance 0.\n *\n * ## Deform: what a key holds\n *\n * A key states a run — `vertices`, starting at `offset` (0 unstated) — into\n * the attachment's deform array: one `x, y` pair per vertex of an unweighted\n * attachment, one pair per BINDING of a weighted one (in vertex order, then\n * binding order). What the run does not cover is an offset of 0, and a key\n * with no `vertices` is all zeros — the setup geometry.\n *\n * - **Unweighted, the runtime holds the key as positions, each the float32 sum\n * `fround(fround(setup) + fround(offset))`.** Over 800 samples of 40\n * random meshes on rotated, scaled bones, five-decimal numbers: that\n * reading 0 misses; the double sum lerped 788, the lerped positions\n * rounded to float32 791, the offsets lerped and then added 788.\n * - **Weighted, the runtime holds the key as offsets** (`fround(offset)`) and\n * adds each to its binding's float32 coordinate when the world vertices\n * are computed: `(fround(bx) + dx)·a + (fround(by) + dy)·b + worldX`, times\n * the weight, summed. Over 1,600 samples of 80 random meshes over one to\n * three of three bones: 0 misses; the float32 sum held as a position 775\n * and 780, the lerped offset rounded to float32 711 and 716.\n *\n * ## Deform: at a sample time\n *\n * The key search is construct 4's (the last key at or before `t`, key times\n * float32). Before the first key the setup geometry; at or after the last\n * key, and on a `stepped` segment, that key; between two keys the lerp\n * `a + (b − a)·p` of the two held arrays, in double — measured above, and on\n * 7,200 samples of 180 random multi-key timelines (runs short and offset,\n * keys without vertices, stepped, linear and Bézier segments): 0 misses with\n * the Bézier rule below, 114 with the far end 1, every one on a Bézier\n * piece next to the eighth or ninth point. The form `a·(1 − p) + b·p` read\n * the same 0: the two differ below the oracle's grid, so which one the\n * runtime writes is not measurable here, and the first is taken.\n *\n * - **Linear**: `p = (t − t0) / (t1 − t0)`, the key times float32 (a float32\n * `p` missed 341 of 2,400).\n * - **Bézier**: one channel whose value axis runs from 0 to 1 — the fraction\n * of the way from one key's geometry to the next — shaped as a bone\n * channel's is (`bezierPolyline` in `./animation.ts`: the polyline through\n * the cubic's nine points at tenths of its parameter, stated numbers,\n * float32 points) with ONE measured difference: ⚠️ **the recurrence runs to\n * a far end of `0.99999999`, not 1, while the polyline's last point is the\n * next key at 1.** Read off 126 curves, each point fixed by intersecting\n * the two pieces meeting at it (a 10⁵-unit run makes `p` legible to 1e-11):\n * with the far end 1 the points missed 64 of 1,134; with `0.99999999`, 1 —\n * a first point whose piece held too few samples to fit — and every other\n * far end tried missed more (1 − 2⁻²⁷ 17, 0.999999989 10, 0.99999998 68;\n * the exact one-sixth with the far end 1, 68). On the 1,080 points of the\n * 120 random curves among them, the other readings of the recurrence\n * missed more still: float32 handles 222, float32 running sums or\n * constants 258 and more (1,024 combinations tried), the cubic evaluated\n * directly 67. The residual the far end 1 leaves is one float32 step,\n * always downward, growing with the point's index. A bone\n * channel shaped by the same handles read the far end 1 (`CD02` holds\n * both): the deform curve is its own reading. The last piece, from the\n * ninth point to the next key, read exact.\n * ⚠️ **Which form each piece takes (issue #975)**: the first piece, from\n * the key to the first point, is `y1·(t − x0) / (x1 − x0)`; the last, from\n * the ninth point to the next key, `y0 + (1 − y0)·(t − x0) / (x1 − x0)`\n * (each product before its division); the eight between are the bone\n * channel's `y0 + (t − x0) / (x1 − x0) · (y1 − y0)`. A bone channel reads\n * all ten pieces in the between form (`channelAt`, bit-exact at a 1e9\n * amplifier, `CR08`). The forms differ below the oracle's six-decimal grid,\n * so they were read off `pose_oracle --raw` at tolerance 0 on `CR09`'s\n * cells (60 five-vertex meshes, one deform segment each, 40 irrational\n * samples; five-decimal keys / float32-exact keys): every piece in the\n * between form 30 / 31 of 60 exact; the first piece's product alone 52 /\n * 53; the last piece's alone 37 / 37; both 60 / 60 (and 60 / 60 on another\n * seed at 200 samples, where the between form read 14 / 14). The far end\n * stays `0.99999999`: with both forms and the far end 1, 38 / 38.\n *\n * ## Under a slider\n *\n * A slider applies its animation's deforms after the sample's own, at its\n * time, from the CURRENT deform — the sample's, or the setup geometry where\n * the sample set none (the setup positions unweighted, zero offsets\n * weighted) — with alpha its mix: `current + (target − current)·mix`, and\n * `additive` `current + (target − setup)·mix` (the setup positions\n * unweighted, zeros weighted). ⚠️ At mix exactly 1, not additive, it IS the\n * target: `current + (target − current)·1` read 1 ulp off spine-core on 27\n * of 2,790 posed rows of issue #969's hand-written population (`DM01`, the\n * survey's doubles), the target on none. ⚠️ **Additive at mix exactly 1\n * over NO current deform** — at the setup pose, or at a sample whose own\n * animation set none on that slot — **it is the target too**, not\n * `setup + (target − setup)·1` (issue #993, read off `pose_oracle --raw` at\n * tolerance 0; weighted, the setup is zeros and the two agree to the bit).\n * On 1,000 rigs of `CD05`'s generator: that rule 1,000 exact; the stated\n * blend everywhere 985 (15 misses, every one unweighted, additive, mix 1,\n * with no current deform, 1–16 ulp on a vertex). Read at every additive\n * mix 1, current deform or not: `current + target − setup` 917,\n * `current − setup + target` and `target + (current − setup)` 951 each (with\n * no current deform both are the target to the bit — they miss over one),\n * the target itself 850. So over a current deform the stated blend stands:\n * the 107 additive mix-1 rigs whose sample animation keys a deform of its\n * own read exact at every sample with it. Before the timeline's first key it\n * writes nothing. Measured on 300 samples of 60 random rigs — weighted and not,\n * additive and not, mix 1, 0.5 and in [−1, 2], with and without a deform in\n * the sample's own animation: 0 misses; reading the non-additive blend from\n * the setup geometry missed 45, reading additive as the key's positions\n * added missed 100.\n *\n * ## Which slot a deform timeline moves\n *\n * The timeline names a skin, a slot and a placeholder: a RECORD. It moves\n * every slot whose shown record at that moment — after the attachment\n * timelines and the sliders — is that record, or a linked mesh that plays\n * that record's timelines (`timelines` true), whichever slot the timeline is\n * filed under. Measured (`CD07`): a deform keyed on mesh `m` of slot `y`\n * moved a linked mesh of `m` in slot `x` and another in slot `z`, and moved\n * `x` while `y` showed another mesh and while `y` showed nothing; a linked\n * mesh with `timelines` false did not move; a deform keyed on an attachment\n * the slot shows only between two attachment keys moved it there alone.\n *\n * ## A switch\n *\n * The sample's own attachment timelines are applied before its deform and\n * sequence timelines, so those are matched against what the slot shows after\n * the sample's switches. A slider applies its animation after the sample —\n * its attachment key, then its deform and sequence keys — and ⚠️ **a slider\n * switching the slot to ANOTHER attachment clears the deform and the frame\n * the sample set**, while one naming the attachment already shown keeps\n * them. Measured on two meshes `m`, `n` and on two series `r` (setup frame 1)\n * and `q` (setup frame 2) (`CD14`): a slider switching `m` to `n` over a\n * sample deforming `m` drew `n` undeformed, and over a sample deforming `n`\n * drew `n` undeformed too (the sample's deform of `n` found `m` shown); a\n * slider naming `m` over a sample deforming `m` kept the deform; a slider\n * switching to `n` and deforming it drew its own deform; the series alike —\n * `q` at its setup frame after the switch, `r` at the sample's frame 3 when\n * the slider named `r`. ⚠️ Under\n * `--skin all` a placeholder several skins fill shows the LAST of them in the\n * Spine file's skin order, which the model does not hold (the slots' ⚠️ in\n * `./index.ts`), so a timeline keyed on such a placeholder is not posed: the\n * block is absent, naming it. Under `--skin <name>` one record resolves —\n * the named skin's, else the default's (`./skins.ts`) — and a timeline\n * moves it exactly when it is keyed under that record's skin (`CN01`).\n *\n * ## Sequence\n *\n * A region's series shows its setup frame (`sequence.setup`, 0 unstated)\n * until a sequence timeline's first key. From a key — `mode` (`hold`\n * unstated), `index` (0 unstated), `delay` (⚠️ unstated, the key before\n * it's, 0 on the first key) — the frame is `index` plus\n * `floor((t − time) / delay + 0.00001)` steps when `delay` is above 0 (no\n * step otherwise, and none in `hold`), then per mode over `count` frames:\n * `hold` the index held at the last frame, `once` the same, `loop` modulo\n * `count`, `pingpong` modulo `2·(count − 1)` folded back, and each\n * `…Reverse` mode the forward mode's frame `f` read as `count − 1 − f`. The\n * key time and `delay` are float32. Measured on 74,041 samples of 380\n * random timelines, 300 of them with delays built to put the quotient within\n * 1e-6 to 4e-5 of a whole step (52,768 samples): the epsilon 0.00001 missed\n * 0; no epsilon 440, 0.0001 1,266, a float32 quotient 306; on the 52,768,\n * 0.000005 148 and 0.00002 248. ⚠️ **A key stating no\n * delay steps by the key before it's**, carried through keys that state\n * none: a hold with delay 0.2, then a hold at index 1, then a loop at index 0\n * stating no delay stepped every 0.2 from the third key; a delay of 0 stated\n * after one of 0.2 held; the index and the mode are not carried (a key\n * stating no index after one at 3 showed frame 0; one stating no mode\n * after a loop held). A slider applies a\n * sequence key at any mix but 0. Only a region's corners read the frame (its\n * rectangle, `sequence.atlas[frame]`); a mesh's vertices read no atlas.\n *\n * ## Purity\n *\n * As the rest of the core: nothing from the Spine runtime package, nothing\n * from `src/transform.ts`, no clock, no randomness, no I/O.\n */\nimport type { ModelSlot, ModelVertices } from '../model.ts';\nimport { bezierPolyline, keyIndexAt, type CoreAnimationTimelines, type CoreCurve } from './animation.ts';\nimport { activeBones, shownAttachment, shownRow, type CompiledDocument, type CoreShown, type CoreSkin, type ShownResolution } from './index.ts';\nimport { fillingSkins, slotTimelinesApply, type SlotTimelineGate } from './skins.ts';\nimport type { ShownGeometry } from './vertices.ts';\n\n/** The far end the deform curve's recurrence runs to — the header's measurement. */\nexport const DEFORM_CURVE_END = 0.99999999;\n\n/** A sequence timeline's modes, as the model spells them. */\nexport const SEQUENCE_MODES = ['hold', 'once', 'loop', 'pingpong', 'onceReverse', 'loopReverse', 'pingpongReverse'] as const;\nexport type SequenceMode = (typeof SEQUENCE_MODES)[number];\n\n/** The step a sequence adds to its quotient before flooring it — the header's measurement. */\nexport const SEQUENCE_EPSILON = 0.00001;\n\n/** One deform key, as read: its time float32 and as stated, its curve, and its run. */\nexport interface CoreDeformKey {\n time: number;\n stated: number;\n curve: CoreCurve;\n offset: number;\n /** The run as the document states it; the runtime stores each float32. */\n vertices: number[];\n}\n\n/** One sequence key, as read — each field the parser's value where unstated. */\nexport interface CoreSequenceKey {\n time: number;\n mode: SequenceMode;\n index: number;\n /** Float32, as the runtime stores it. */\n delay: number;\n}\n\n/** One attachment's timelines in one animation: the skin, slot and placeholder it names, and its deform and sequence keys. */\nexport interface CoreAttachmentTimeline {\n skin: string;\n slot: string;\n attachment: string;\n deform: CoreDeformKey[] | null;\n sequence: CoreSequenceKey[] | null;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nconst finite = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);\n\n/** How long the deform array of a vertex array is: a pair per vertex, or per binding when weighted. */\nexport function deformLength(vertices: ModelVertices): number {\n return vertices.weighted ? 2 * vertices.bindings.reduce((n, b) => n + b.length, 0) : vertices.xy.length;\n}\n\nfunction keyTimes(list: unknown[], at: string, problems: string[]): void {\n let last = -Infinity;\n list.forEach((k, i) => {\n if (!isRecord(k)) return;\n const t = k.time;\n if (!finite(t) || t < 0) problems.push(`${at}[${i}]: time is ${JSON.stringify(t)}, not a finite time at or after 0`);\n else if (t <= last) problems.push(`${at}[${i}]: time ${t} is not after the key before it — the writer refuses key times that do not strictly increase`);\n if (finite(t)) last = Math.max(last, t);\n });\n}\n\nfunction readDeformKeys(value: unknown, at: string, vertices: ModelVertices, problems: string[]): CoreDeformKey[] {\n if (!Array.isArray(value) || value.length === 0) {\n problems.push(`${at}: keys is not a non-empty list`);\n return [];\n }\n keyTimes(value, at, problems);\n const length = deformLength(vertices);\n const out: CoreDeformKey[] = [];\n value.forEach((k, i) => {\n const kat = `${at}[${i}]`;\n if (!isRecord(k)) {\n problems.push(`${kat} is not an object`);\n return;\n }\n for (const key of Object.keys(k)) if (!['time', 'offset', 'vertices', 'curve'].includes(key)) problems.push(`${kat}: field \"${key}\" is not one a deform key carries; it carries [time, offset, vertices, curve]`);\n const run = k.vertices;\n let vertexRun: number[] = [];\n if (run !== undefined) {\n if (!Array.isArray(run) || run.length === 0 || !run.every(finite)) problems.push(`${kat}: vertices is not a non-empty list of finite numbers (omit it for the setup geometry)`);\n else vertexRun = run as number[];\n }\n let offset = 0;\n if (k.offset !== undefined) {\n if (run === undefined) problems.push(`${kat}: offset ${JSON.stringify(k.offset)} with no vertices — a key with no run is the setup geometry, and the writer states no start for it`);\n else if (typeof k.offset !== 'number' || !Number.isInteger(k.offset) || k.offset < 0) problems.push(`${kat}: offset is ${JSON.stringify(k.offset)}, not a whole index at or after 0`);\n else offset = k.offset;\n }\n if (offset + vertexRun.length > length) problems.push(`${kat}: the run starts at ${offset} and is ${vertexRun.length} long, past the ${length} numbers of the attachment's deform array`);\n let curve: CoreCurve = 'linear';\n if (k.curve !== undefined) {\n if (i === value.length - 1) problems.push(`${kat}: the last key carries a curve, which eases to no key — the writer refuses it`);\n else if (k.curve === 'stepped') curve = 'stepped';\n else if (Array.isArray(k.curve) && k.curve.length === 4 && k.curve.every(finite)) curve = k.curve as number[];\n else problems.push(`${kat}: curve is ${JSON.stringify(k.curve)}, not \"stepped\" nor 4 finite numbers (a deform key's curve is one channel)`);\n }\n const time = finite(k.time) ? k.time : 0;\n out.push({ time: Math.fround(time), stated: time, curve, offset, vertices: vertexRun });\n });\n return out;\n}\n\nfunction readSequenceKeys(value: unknown, at: string, count: number, problems: string[]): CoreSequenceKey[] {\n if (!Array.isArray(value) || value.length === 0) {\n problems.push(`${at}: keys is not a non-empty list`);\n return [];\n }\n keyTimes(value, at, problems);\n const out: CoreSequenceKey[] = [];\n value.forEach((k, i) => {\n const kat = `${at}[${i}]`;\n if (!isRecord(k)) {\n problems.push(`${kat} is not an object`);\n return;\n }\n for (const key of Object.keys(k)) if (!['time', 'mode', 'index', 'delay'].includes(key)) problems.push(`${kat}: field \"${key}\" is not one a sequence key carries; it carries [time, mode, index, delay]`);\n let mode: SequenceMode = 'hold';\n if (k.mode !== undefined) {\n const m = SEQUENCE_MODES.find((x) => x === k.mode);\n if (m === undefined) problems.push(`${kat}: mode is ${JSON.stringify(k.mode)}, none of ${SEQUENCE_MODES.join(', ')}`);\n else mode = m;\n }\n let index = 0;\n if (k.index !== undefined) {\n if (typeof k.index !== 'number' || !Number.isInteger(k.index) || k.index < 0 || k.index >= count) problems.push(`${kat}: index is ${JSON.stringify(k.index)}, not a frame of the series' ${count} — the writer refuses an index past the last frame`);\n else index = k.index;\n }\n // Unstated, the key before it's (the header's ⚠️).\n let delay = out.length === 0 ? 0 : out[out.length - 1].delay;\n if (k.delay !== undefined) {\n // A negative delay steps backwards through a floor this cut never measured; the writer states none.\n if (!finite(k.delay) || k.delay < 0) problems.push(`${kat}: delay is ${JSON.stringify(k.delay)}, not a finite number of seconds at or above 0`);\n else delay = Math.fround(k.delay);\n }\n out.push({ time: Math.fround(finite(k.time) ? k.time : 0), mode, index, delay });\n });\n return out;\n}\n\n/**\n * An animation record's `attachments` group, read: each skin, slot and\n * placeholder one of the document's records, a `deform` only on a vertex\n * attachment (mesh, bounding box, clipping, path — the four the writer keys)\n * with every run fitting its deform array, a `sequence` only on a record with\n * a series, and every key checked field by field. Every problem is named.\n */\nexport function readAttachmentTimelines(value: unknown, label: string, skins: readonly CoreSkin[], problems: string[]): CoreAttachmentTimeline[] {\n const out: CoreAttachmentTimeline[] = [];\n const where = `${label}.attachments`;\n if (!Array.isArray(value)) {\n problems.push(`${where} is not a list`);\n return out;\n }\n value.forEach((skinEntry, i) => {\n const sat = `${where}[${i}]`;\n if (!isRecord(skinEntry) || typeof skinEntry.name !== 'string') {\n problems.push(`${sat} names no skin`);\n return;\n }\n const skin = skins.find((k) => k.name === skinEntry.name);\n if (skin === undefined) problems.push(`${sat}: \"${skinEntry.name}\" is not a skin of this document`);\n if (!Array.isArray(skinEntry.slots)) {\n problems.push(`${sat}: slots is not a list`);\n return;\n }\n skinEntry.slots.forEach((slotEntry: unknown, j: number) => {\n const lat = `${sat}.slots[${j}]`;\n if (!isRecord(slotEntry) || typeof slotEntry.name !== 'string') {\n problems.push(`${lat} names no slot`);\n return;\n }\n if (!Array.isArray(slotEntry.attachments)) {\n problems.push(`${lat}: attachments is not a list`);\n return;\n }\n const slot = slotEntry.name;\n slotEntry.attachments.forEach((attEntry: unknown, m: number) => {\n const aat = `${lat}.attachments[${m}]`;\n if (!isRecord(attEntry) || typeof attEntry.name !== 'string') {\n problems.push(`${aat} names no attachment`);\n return;\n }\n for (const key of Object.keys(attEntry)) if (!['name', 'deform', 'sequence'].includes(key)) problems.push(`${aat}: field \"${key}\" is not one this reader knows; it reads [name, deform, sequence]`);\n const record = skin?.attachments[slot]?.[attEntry.name];\n const label2 = `${aat} \"${skinEntry.name}/${slot}/${attEntry.name}\"`;\n if (skin !== undefined && record === undefined) problems.push(`${label2}: skin \"${skin.name}\" files no attachment \"${attEntry.name}\" under slot \"${slot}\"`);\n const timeline: CoreAttachmentTimeline = { skin: skinEntry.name as string, slot, attachment: attEntry.name, deform: null, sequence: null };\n if (attEntry.deform !== undefined && record !== undefined) {\n const g = record.geometry;\n if (g === undefined || (g.kind !== 'mesh' && g.kind !== 'clipping' && g.kind !== 'boundingbox' && g.kind !== 'path')) problems.push(`${label2}: a deform keys the vertices of a mesh, bounding box, clipping or path attachment, and this one is a ${record.kind}`);\n else timeline.deform = readDeformKeys(attEntry.deform, `${label2}.deform`, g.vertices, problems);\n }\n if (attEntry.sequence !== undefined && record !== undefined) {\n const count = record.sequenceCount;\n if (count === undefined) problems.push(`${label2}: a sequence timeline steps a series, and this ${record.kind} carries no sequence`);\n else timeline.sequence = readSequenceKeys(attEntry.sequence, `${label2}.sequence`, count, problems);\n }\n if (attEntry.deform === undefined && attEntry.sequence === undefined) problems.push(`${label2}: carries neither a deform nor a sequence timeline`);\n out.push(timeline);\n });\n });\n });\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// evaluation\n// ---------------------------------------------------------------------------\n\n/** The array a key holds — the header's *what a key holds*: positions unweighted, offsets weighted. */\nexport function heldArray(vertices: ModelVertices, key: CoreDeformKey): number[] {\n const out = setupArray(vertices);\n key.vertices.forEach((v, i) => {\n const at = key.offset + i;\n out[at] = vertices.weighted ? Math.fround(v) : Math.fround(out[at] + Math.fround(v));\n });\n return out;\n}\n\n/** The deform array of no deform: the setup positions (float32) unweighted, zero offsets weighted. */\nexport function setupArray(vertices: ModelVertices): number[] {\n return vertices.weighted ? new Array<number>(deformLength(vertices)).fill(0) : vertices.xy.map((v) => Math.fround(v));\n}\n\n/** The fraction of the way from key `a` to key `b` at `t` — the header's two curves. */\nexport function deformPercent(a: CoreDeformKey, b: CoreDeformKey, t: number): number {\n if (a.curve === 'stepped') return 0;\n if (a.curve === 'linear') return (t - a.time) / (b.time - a.time);\n const c = a.curve;\n const inner = bezierPolyline(a.stated, 0, c[0], c[1], c[2], c[3], b.stated, DEFORM_CURVE_END);\n const points = [a.time, 0, ...inner, b.time, 1];\n let i = 2;\n while (i < points.length - 2 && points[i] < t) i += 2;\n const [x0, y0, x1, y1] = [points[i - 2], points[i - 1], points[i], points[i + 1]];\n // The two end pieces multiply before they divide — the header's *which form each piece takes*.\n if (i === 2) return (y1 * (t - x0)) / (x1 - x0);\n if (i === points.length - 2) return y0 + ((1 - y0) * (t - x0)) / (x1 - x0);\n return y0 + ((t - x0) / (x1 - x0)) * (y1 - y0);\n}\n\n/** What evaluates a deform timeline at `t`: `deformAt` unless a plant passes another. */\nexport type DeformEvaluator = (vertices: ModelVertices, keys: readonly CoreDeformKey[], t: number) => number[] | null;\n\n/** The deform array a timeline sets at `t`, or `null` before its first key — the header's *at a sample time*. */\nexport function deformAt(vertices: ModelVertices, keys: readonly CoreDeformKey[], t: number): number[] | null {\n const i = keyIndexAt(keys, t);\n if (i < 0) return null;\n const a = keys[i];\n const held = heldArray(vertices, a);\n const b = keys[i + 1];\n if (b === undefined || a.curve === 'stepped') return held;\n const next = heldArray(vertices, b);\n const p = deformPercent(a, b, t);\n return held.map((v, k) => v + (next[k] - v) * p);\n}\n\n/** What blends a slider's deform over the current one: `blendDeform` unless a plant passes another. */\nexport type DeformBlender = (vertices: ModelVertices, current: readonly number[] | null, target: readonly number[], alpha: number, additive: boolean) => number[];\n\n/** A slider's deform over the current one — the header's *under a slider*. */\nexport function blendDeform(vertices: ModelVertices, current: readonly number[] | null, target: readonly number[], alpha: number, additive: boolean): number[] {\n const setup = setupArray(vertices);\n const from = current ?? setup;\n // #969: non-additive at mix 1 the target itself, not `c + (target − c)·1`, which is last-bit off it (measured, `./hooks.ts`' DM01).\n if (!additive && alpha === 1) return [...target];\n // #993: additive at mix 1 over no current deform the target too, not `setup + (target − setup)·1` (measured, the core suite's CR10).\n if (additive && alpha === 1 && current === null) return [...target];\n return from.map((c, k) => (additive ? c + (target[k] - setup[k]) * alpha : c + (target[k] - c) * alpha));\n}\n\n/**\n * The vertex array a deform array draws: unweighted the positions\n * themselves, weighted each binding's float32 coordinate plus its offset —\n * numbers the world-vertex computation reads as they are, not through\n * `Math.fround` again (`worldVertices`' `coords`).\n */\nexport function deformedVertices(vertices: ModelVertices, deform: readonly number[]): ModelVertices {\n if (!vertices.weighted) return { weighted: false, xy: [...deform] };\n let k = 0;\n return {\n weighted: true,\n bindings: vertices.bindings.map((influences) => influences.map((b) => {\n const x = Math.fround(b.x) + deform[k];\n const y = Math.fround(b.y) + deform[k + 1];\n k += 2;\n return { ...b, x, y };\n })),\n };\n}\n\n/** The frame a sequence timeline shows at `t`, or `null` before its first key — the header's *Sequence*. */\nexport function sequenceFrameAt(keys: readonly CoreSequenceKey[], count: number, t: number): number | null {\n const i = keyIndexAt(keys, t);\n if (i < 0) return null;\n const k = keys[i];\n let n = k.index;\n if (k.mode !== 'hold' && k.delay > 0) n += Math.floor((t - k.time) / k.delay + SEQUENCE_EPSILON);\n const reverse = k.mode.endsWith('Reverse');\n const base = reverse ? k.mode.slice(0, -'Reverse'.length) : k.mode;\n let f: number;\n if (base === 'hold' || base === 'once') f = Math.min(n, count - 1);\n else if (base === 'loop') f = n % count;\n else {\n const period = 2 * (count - 1);\n f = period === 0 ? 0 : n % period;\n if (f >= count) f = period - f;\n }\n return reverse ? count - 1 - f : f;\n}\n\n// ---------------------------------------------------------------------------\n// the slots' attachments at a pose\n// ---------------------------------------------------------------------------\n\n/** What evaluates a sequence timeline at `t`: `sequenceFrameAt` unless a plant passes another. */\nexport type SequenceEvaluator = (keys: readonly CoreSequenceKey[], count: number, t: number) => number | null;\n\n/** The applications this module reads off a slider (`SliderApplication` in `./constraints_slider.ts`). */\nexport interface AttachmentApplication {\n name: string;\n timelines: { attachments: readonly CoreAttachmentTimeline[]; slots: ReadonlyArray<{ name: string; timelines: ReadonlyArray<{ kind: string; keys?: ReadonlyArray<{ time: number; name?: string | null }> }> }> };\n at: number;\n alpha: number;\n additive: boolean;\n}\n\n/** The skin, slot and placeholder a slot's shown record plays timelines as — the header's *which slot* — or null when none can key it. */\nexport function timelineIdentity(slot: string, shown: CoreShown): string | null {\n const g = shown.record.geometry;\n if (g?.kind === 'linkedmesh') return shown.record.timelines === true ? `${g.skin}/${g.slot}/${g.source}` : null;\n return `${shown.skin}/${slot}/${shown.placeholder}`;\n}\n\nconst nameOf = (a: CoreAttachmentTimeline): string => `${a.skin}/${a.slot}/${a.attachment}`;\n\n/** The part of an attachment state that depends only on the document view and placeholder. */\ninterface AttachmentIdentity {\n readonly entry: ShownGeometry;\n readonly identity: string | null;\n readonly vertices: ModelVertices | null;\n readonly count: number | undefined;\n readonly fillers: readonly string[];\n}\n\n/** Like shownAttachment's cache, scoped to the view; a new skin view resolves its own records. */\nconst identitiesOfView = new WeakMap<CompiledDocument, Map<string, Map<string, AttachmentIdentity | null>>>();\n\nfunction readIdentity(doc: CompiledDocument, resolve: (doc: CompiledDocument, slot: ModelSlot) => ShownResolution, slot: ModelSlot, placeholder: string): AttachmentIdentity | null {\n const s = resolve(doc, { ...slot, setup: placeholder });\n if (s === null || 'conflict' in s || s.record.geometry === undefined) return null;\n const g = s.record.geometry;\n const source = g.kind === 'linkedmesh' ? doc.skins.find((k) => k.name === g.skin)?.attachments[g.slot]?.[g.source] : s.record;\n const sg = source?.geometry;\n return Object.freeze({\n entry: Object.freeze({ slot: slot.name, bone: slot.bone, name: shownRow(s).name, placeholder: s.placeholder, skin: s.skin, geometry: g }),\n identity: timelineIdentity(slot.name, s),\n vertices: sg !== undefined && sg.kind !== 'region' && sg.kind !== 'linkedmesh' ? sg.vertices : null,\n count: source?.sequenceCount,\n fillers: Object.freeze(fillingSkins(doc, slot.name, s.placeholder).map((k) => `\"${k}\"`)),\n });\n}\n\nfunction identityOf(doc: CompiledDocument, resolve: (doc: CompiledDocument, slot: ModelSlot) => ShownResolution, slot: ModelSlot, placeholder: string | null): AttachmentIdentity | null {\n if (placeholder === null) return null;\n // A planted resolver may read changing state outside the document. Only the document's own reader is immutable.\n if (resolve !== shownAttachment) return readIdentity(doc, resolve, slot, placeholder);\n let slots = identitiesOfView.get(doc);\n if (slots === undefined) identitiesOfView.set(doc, slots = new Map());\n let placeholders = slots.get(slot.name);\n if (placeholders === undefined) slots.set(slot.name, placeholders = new Map());\n if (placeholders.has(placeholder)) return placeholders.get(placeholder) as AttachmentIdentity | null;\n const identity = readIdentity(doc, resolve, slot, placeholder);\n placeholders.set(placeholder, identity);\n return identity;\n}\n\n/** Index only immutable timeline identity. Times, mixes and the values they compute are never cached. */\nconst attachmentsByIdentity = new WeakMap<readonly CoreAttachmentTimeline[], ReadonlyMap<string, readonly CoreAttachmentTimeline[]>>();\ntype AttachmentSlots = AttachmentApplication['timelines']['slots'];\ntype AttachmentSwitch = NonNullable<AttachmentSlots[number]['timelines'][number]['keys']>;\nconst switchesBySlot = new WeakMap<AttachmentSlots, ReadonlyMap<string, readonly AttachmentSwitch[]>>();\n\nfunction matchingAttachments(timelines: readonly CoreAttachmentTimeline[], identity: string): readonly CoreAttachmentTimeline[] | undefined {\n let index = attachmentsByIdentity.get(timelines);\n if (index === undefined) {\n const rows = new Map<string, CoreAttachmentTimeline[]>();\n for (const a of timelines) {\n const name = nameOf(a);\n const found = rows.get(name);\n if (found === undefined) rows.set(name, [a]);\n else found.push(a);\n }\n attachmentsByIdentity.set(timelines, index = rows);\n }\n return index.get(identity);\n}\n\nfunction slotSwitches(slots: AttachmentSlots, slot: string): readonly AttachmentSwitch[] | undefined {\n let index = switchesBySlot.get(slots);\n if (index === undefined) {\n const rows = new Map<string, AttachmentSwitch[]>();\n for (const target of slots) {\n for (const tl of target.timelines) {\n if (tl.kind !== 'attachment' || tl.keys === undefined) continue;\n const found = rows.get(target.name);\n if (found === undefined) rows.set(target.name, [tl.keys]);\n else found.push(tl.keys);\n }\n }\n switchesBySlot.set(slots, index = rows);\n }\n return index.get(slot);\n}\n\n/** Allocated only when a matching timeline or a mixed deform actually has per-pose state. */\ninterface AttachmentValues {\n deform: number[] | null;\n frame: number | null;\n seen: string[];\n}\n\nfunction applyAttachment(now: AttachmentIdentity | null, values: AttachmentValues | null, timelines: readonly CoreAttachmentTimeline[], t: number, blend: AttachmentApplication | null, evalDeform: DeformEvaluator, blendOf: DeformBlender, evalFrame: SequenceEvaluator): AttachmentValues | null {\n if (now === null || now.identity === null) return values;\n const matching = matchingAttachments(timelines, now.identity);\n if (matching === undefined) return values;\n values ??= { deform: null, frame: null, seen: [] };\n if (!values.seen.includes(now.identity)) values.seen.push(now.identity);\n for (const a of matching) {\n if (a.deform !== null && now.vertices !== null) {\n const target = evalDeform(now.vertices, a.deform, t);\n if (target !== null) values.deform = blend === null ? target : blendOf(now.vertices, values.deform, target, blend.alpha, blend.additive);\n }\n if (a.sequence !== null && now.count !== undefined) {\n const f = evalFrame(a.sequence, now.count, t);\n if (f !== null) values.frame = f;\n }\n }\n return values;\n}\n\n/**\n * Every slot's shown geometry at one pose — the setup's (`sample` null) or a\n * sample's — with the deform array and the series' frame its attachment\n * timelines set, stage by stage as the header's *A switch* states: from what\n * the slot shows after the sample's own timelines (`placeholders`; the setup\n * placeholder at setup), the sample's deform and sequence timelines at `t`;\n * then each slider in order — its attachment key (a switch to another record\n * clears the deform and the frame), then its deform and sequence timelines at\n * the time and mix it was applied with. Slots in the model's order, showing a\n * record that carries geometry; a slot whose placeholder skins fill\n * differently is left to the slots' own absence. `why` names what the core\n * does not pose: a timeline moving a record whose placeholder several skins\n * fill (the header's ⚠️).\n *\n * Identity is kept per document view, slot and placeholder, and timelines\n * indexed by their record identity. A slot with no per-pose values reuses its\n * frozen entry; deform arrays and sequence frames are evaluated afresh.\n * Sliders select identities in application order, never a cached posed value.\n */\nexport function attachmentStates(\n doc: CompiledDocument,\n resolve: (doc: CompiledDocument, slot: ModelSlot) => ShownResolution,\n placeholders: ReadonlyMap<string, string | null>,\n sample: { timelines: CoreAnimationTimelines; t: number } | null,\n sliders: readonly AttachmentApplication[],\n plant: { deform?: DeformEvaluator; deformBlend?: DeformBlender; sequence?: SequenceEvaluator; slotTimelines?: SlotTimelineGate } = {},\n /**\n * The live tracks' deforms (`./tracks.ts`, issue #1336), in place of a\n * sample's: each slot's deform array as the mixed entries left it (`null`\n * none) and the records their deform timelines keyed on it — what the\n * sample's own timelines would have set and seen. Absent on every other\n * caller.\n */\n mixed?: ReadonlyMap<string, { deform: number[] | null; seen: readonly string[] }>,\n): { shown: ShownGeometry[]; why: string[] } {\n const evalDeform = plant.deform ?? deformAt;\n const blendOf = plant.deformBlend ?? blendDeform;\n const evalFrame = plant.sequence ?? sequenceFrameAt;\n const shown: ShownGeometry[] = [];\n const why: string[] = [];\n const active = activeBones(doc);\n const gate = plant.slotTimelines ?? slotTimelinesApply;\n for (const slot of doc.slots) {\n // A slot on a bone the skin leaves inactive is not animated: no deform, no frame, no slider switch (`./skins.ts`).\n const live = gate(doc, slot, active);\n let placeholder = placeholders.get(slot.name) ?? null;\n const base = live ? mixed?.get(slot.name) : undefined;\n let values: AttachmentValues | null = base === undefined || (base.deform === null && base.seen.length === 0) ? null : { deform: base.deform, frame: null, seen: [...base.seen] };\n let now = identityOf(doc, resolve, slot, placeholder);\n if (sample !== null && live) values = applyAttachment(now, values, sample.timelines.attachments, sample.t, null, evalDeform, blendOf, evalFrame);\n if (live) for (const app of sliders) {\n // Each slider switches first, clearing only the per-pose values; then its attachment timelines apply to the new identity.\n const switches = slotSwitches(app.timelines.slots, slot.name);\n if (switches !== undefined) for (const keys of switches) {\n const i = keyIndexAt(keys, app.at);\n if (i < 0) continue;\n const next = keys[i].name ?? null;\n if (next !== placeholder) {\n if (values !== null) {\n values.deform = null;\n values.frame = null;\n }\n placeholder = next;\n now = identityOf(doc, resolve, slot, placeholder);\n }\n }\n values = applyAttachment(now, values, app.timelines.attachments, app.at, app, evalDeform, blendOf, evalFrame);\n }\n if (now === null) continue;\n // The cached entry is frozen. A pose with a deform/frame owns its wrapper and values; later poses cannot write into it.\n const entry = values === null || (values.deform === null && values.frame === null) ? now.entry : { ...now.entry };\n shown.push(entry);\n if (values !== null && values.seen.length > 0 && now.fillers.length > 1) {\n why.push(`slot \"${slot.name}\" shows placeholder \"${now.entry.placeholder}\", which skins ${now.fillers.join(', ')} fill, and ${values.seen.map((x) => `\"${x}\"`).join(', ')} key(s) it — which record --skin all shows, and so whether the timeline moves it, is the Spine file's skin order, not the model's`);\n continue;\n }\n if (values !== null) {\n if (values.deform !== null) entry.deform = values.deform;\n if (values.frame !== null) entry.frame = values.frame;\n }\n }\n return { shown, why };\n}\n","/**\n * Construct 4 of the core, its remainder (issue #955, step 2f of issue #380):\n * the draw order — at the setup pose, and a draw-order timeline's at a\n * sample time and under a slider.\n *\n * Every rule below was measured by posing hand-written skeletons through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13) and reading the slot names\n * the dump lists (`drawOrder`); nothing here was written from the runtime's\n * source. The core suite's `CD` controls hold the same skeletons against the\n * core.\n *\n * - **The setup order is the slot order** (`ModelSlot`: the model's slot\n * array is the draw order), on every probe and on 19 of 19 recipes.\n * - **A key's moves are a permutation of the SETUP order**, whatever the\n * order before it: each moved slot lands at its setup index plus its\n * offset, and the slots no key moves fill the remaining places in setup\n * order. The moves are applied as a set — the model holds them in the order\n * the spec states them, and the order they are listed in changes nothing.\n * - **Before the first key the setup order; a key with no moves restores\n * it.** Measured on 3,600 samples of 120 random timelines (three to eight\n * slots, one to four keys, one to three moves each, empty keys among them):\n * 0 misses.\n * - **Key times are float32**, as every key's (`./animation.ts`).\n * - **A slider applies its animation's draw-order key after the sample's, at\n * any mix but 0, and writes nothing before its first key**: a slider at\n * 0.5 over a key at 0.3 moving the first of three slots two places read\n * `s1, s2, s0` at setup at mix 1, 0.5, 0.01 and −1, and the setup order at\n * mix 0 and at a time before the key.\n *\n * 🚫 **Two moves landing on one place are refused by `readModel`, by name.**\n * The writer refuses a slot moved twice and a destination outside the slots\n * (`compileDrawOrder` in `src/compile.ts`), not two slots sent to one\n * destination; the runtime's fill then leaves a slot out and lists another\n * twice (the compiler's note on the parser), which is a parser's accident\n * and not an order to reproduce.\n */\nimport type { ModelSlot } from '../model.ts';\nimport { keyIndexAt } from './animation.ts';\n\n/** One draw-order key, as read: its time (float32) and its moves as slot indices, empty for the setup order. */\nexport interface CoreDrawOrderKey {\n time: number;\n moves: Array<{ slot: number; offset: number }>;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\n/**\n * An animation record's `drawOrder` keys, read: times strictly increasing,\n * every move naming a slot of the document once per key, a whole offset\n * landing inside the slots, no two moves landing on one place.\n */\nexport function readDrawOrderKeys(value: unknown, label: string, slots: readonly ModelSlot[], problems: string[]): CoreDrawOrderKey[] {\n const where = `${label}.drawOrder`;\n if (!Array.isArray(value)) {\n problems.push(`${where} is not a list`);\n return [];\n }\n const indexOf = new Map(slots.map((s, i) => [s.name, i]));\n const out: CoreDrawOrderKey[] = [];\n let last = -Infinity;\n value.forEach((k, i) => {\n const at = `${where}[${i}]`;\n if (!isRecord(k)) {\n problems.push(`${at} is not an object`);\n return;\n }\n for (const key of Object.keys(k)) if (key !== 'time' && key !== 'offsets') problems.push(`${at}: field \"${key}\" is not one a draw-order key carries; it carries [time, offsets]`);\n const t = k.time;\n if (typeof t !== 'number' || !Number.isFinite(t) || t < 0) problems.push(`${at}: time is ${JSON.stringify(t)}, not a finite time at or after 0`);\n else if (t <= last) problems.push(`${at}: time ${t} is not after the key before it — the writer refuses key times that do not strictly increase`);\n if (typeof t === 'number' && Number.isFinite(t)) last = Math.max(last, t);\n const moves: CoreDrawOrderKey['moves'] = [];\n if (k.offsets !== undefined) {\n if (!Array.isArray(k.offsets)) problems.push(`${at}: offsets is not a list`);\n else {\n const landed = new Map<number, string>();\n k.offsets.forEach((o: unknown, j: number) => {\n const oat = `${at}.offsets[${j}]`;\n if (!isRecord(o) || typeof o.slot !== 'string') {\n problems.push(`${oat} names no slot`);\n return;\n }\n const index = indexOf.get(o.slot);\n if (index === undefined) {\n problems.push(`${oat}: \"${o.slot}\" is not a slot of this document`);\n return;\n }\n if (typeof o.offset !== 'number' || !Number.isInteger(o.offset)) {\n problems.push(`${oat}: slot \"${o.slot}\" offset is ${JSON.stringify(o.offset)}, not a whole number`);\n return;\n }\n if (moves.some((m) => m.slot === index)) problems.push(`${oat}: slot \"${o.slot}\" is moved twice in one key`);\n const to = index + o.offset;\n if (to < 0 || to >= slots.length) problems.push(`${oat}: slot \"${o.slot}\" is at ${index} and offset ${o.offset} lands at ${to}, outside the ${slots.length} slots`);\n else if (landed.has(to)) problems.push(`${oat}: slot \"${o.slot}\" lands at ${to}, where slot \"${landed.get(to)}\" lands too — two moves on one place leave a slot out of the runtime's order`);\n else landed.set(to, o.slot);\n moves.push({ slot: index, offset: o.offset });\n });\n }\n }\n out.push({ time: Math.fround(typeof t === 'number' && Number.isFinite(t) ? t : 0), moves });\n });\n return out;\n}\n\n/** The slot indices in the order a key's moves put them — the header's permutation of the setup order. */\nexport function orderOf(count: number, moves: CoreDrawOrderKey['moves']): number[] {\n const order = new Array<number>(count).fill(-1);\n for (const m of moves) order[m.slot + m.offset] = m.slot;\n const moved = new Set(moves.map((m) => m.slot));\n const rest = Array.from({ length: count }, (_v, i) => i).filter((i) => !moved.has(i));\n let next = 0;\n for (let i = 0; i < count; i++) if (order[i] === -1) order[i] = rest[next++];\n return order;\n}\n\n/** What evaluates a draw-order timeline: `drawOrderAt` unless a plant passes another. */\nexport type DrawOrderEvaluator = (count: number, keys: readonly CoreDrawOrderKey[], t: number) => number[] | null;\n\n/** The order a timeline sets at `t` as slot indices, or `null` before its first key. */\nexport function drawOrderAt(count: number, keys: readonly CoreDrawOrderKey[], t: number): number[] | null {\n const i = keyIndexAt(keys, t);\n return i < 0 ? null : orderOf(count, keys[i].moves);\n}\n","/**\n * Construct 4 of the core, its remainder (issue #955, step 2f of issue #380):\n * the events an animation's event timeline fires between two samples — the\n * oracle's per-sample `events` block, `[name, time, int, float, string]`.\n *\n * Every rule below was measured by posing hand-written skeletons through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13) and reading the block back;\n * nothing here was written from the runtime's source. The core suite's `CD`\n * controls hold the same skeletons against the core.\n *\n * - **A sample lists the keys whose time is in `(previous sample's t, t]`**,\n * the first sample's interval opening at −1: an event keyed at 0.25 fired\n * at the sample at 0.25 and not at the one after; one keyed at 0 fired at\n * the first sample; on an animation of duration 0 every sample sits at 0,\n * and the keys at 0 fired at the first sample alone.\n * - **Key times are float32**: an event keyed at 0.1 (float32\n * 0.10000000149) did not fire at a sample at 0.1 but at the next.\n * - **In key order**: two events keyed at one time fired in the order the\n * keys are listed.\n * - **The row's time is the key's (float32), and each of `int`, `float`,\n * `string` is the key's where it states one, else the event\n * definition's, else the parser's `0`, `0`, `\"\"`** — an event declared with\n * no string read `\"\"`, not `null` (so `tools/pose_oracle.ts`' header, which\n * said `null`, was wrong about the runtime and says so now). `volume` and\n * `balance` are the audio's, and the block does not carry them.\n * - **`float` is the double the document states**, the definition's and the\n * key's alike: `0.1000065`, which rounds to `0.100007` as a double and to\n * `0.100006` through `Math.fround`, read `0.100007` from each.\n * - A slider fires no event into the block: the oracle lists the events of\n * the sample's own animation.\n */\nimport { gridRound } from './index.ts';\n\n/** An event definition, as the model states it (`ModelEvent`): the payload a key falls back to. */\nexport interface CoreEventDef {\n /** Audio metadata retained additively; the five-column oracle row is unchanged. */\n audio?: string;\n volume?: number;\n balance?: number;\n name: string;\n int: number;\n float: number;\n string: string;\n}\n\n/** One event key, as read: its time (float32) and the payload it fires with, each field resolved. */\nexport interface CoreEventKey {\n /** Audio delivery values, as observed from the public EventTimeline API. */\n volume?: number;\n balance?: number;\n time: number;\n name: string;\n int: number;\n float: number;\n string: string;\n}\n\n/** One row of a sample's `events` block: `[name, time, int, float, string]`, the oracle's row. */\nexport type CoreEventRow = [string, number | null, number, number | null, string | null];\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nconst EVENT_DEF_FIELDS = ['name', 'int', 'float', 'string', 'audio', 'volume', 'balance'] as const;\nconst EVENT_KEY_FIELDS = ['time', 'name', 'int', 'float', 'string', 'volume', 'balance'] as const;\n\nfunction payload(raw: Record<string, unknown>, at: string, problems: string[]): { int?: number; float?: number; string?: string; volume?: number; balance?: number } {\n const out: { int?: number; float?: number; string?: string; volume?: number; balance?: number } = {};\n if (raw.int !== undefined) {\n if (typeof raw.int !== 'number' || !Number.isInteger(raw.int)) problems.push(`${at}: int is ${JSON.stringify(raw.int)}, not a whole number`);\n else out.int = raw.int;\n }\n if (raw.float !== undefined) {\n if (typeof raw.float !== 'number' || !Number.isFinite(raw.float)) problems.push(`${at}: float is ${JSON.stringify(raw.float)}, not a finite number`);\n else out.float = raw.float;\n }\n if (raw.string !== undefined) {\n if (typeof raw.string !== 'string') problems.push(`${at}: string is ${JSON.stringify(raw.string)}, not a string`);\n else out.string = raw.string;\n }\n for (const key of ['volume', 'balance'] as const) if (raw[key] !== undefined) {\n if (typeof raw[key] !== 'number' || !Number.isFinite(raw[key])) problems.push(`${at}: ${key} is ${JSON.stringify(raw[key])}, not a finite number`);\n else out[key] = raw[key];\n }\n return out;\n}\n\n/** The document's `events` section, read: a list of named definitions, each name once, each field of its type. */\nexport function readEventDefs(value: unknown, problems: string[]): Map<string, CoreEventDef> {\n const out = new Map<string, CoreEventDef>();\n if (!Array.isArray(value)) {\n problems.push('events is not a list');\n return out;\n }\n value.forEach((raw, i) => {\n const at = `events[${i}]`;\n if (!isRecord(raw) || typeof raw.name !== 'string' || raw.name === '') {\n problems.push(`${at} names no event`);\n return;\n }\n for (const key of Object.keys(raw)) if (!(EVENT_DEF_FIELDS as readonly string[]).includes(key)) problems.push(`${at} \"${raw.name}\": field \"${key}\" is not one this reader knows; it reads [${EVENT_DEF_FIELDS.join(', ')}]`);\n if (raw.audio !== undefined && typeof raw.audio !== 'string') problems.push(`${at} \"${raw.name}\": audio is ${JSON.stringify(raw.audio)}, not a string`);\n if (out.has(raw.name)) problems.push(`${at}: event \"${raw.name}\" is declared twice`);\n const p = payload(raw, `${at} \"${raw.name}\"`, problems);\n out.set(raw.name, { audio: typeof raw.audio === 'string' ? raw.audio : '', volume: p.volume ?? 0, balance: p.balance ?? 0, name: raw.name, int: p.int ?? 0, float: p.float ?? 0, string: p.string ?? '' });\n });\n return out;\n}\n\n/** An animation record's `events` keys, read: each names a declared event, times do not go backwards (equal times are two firings), each field of its type. */\nexport function readEventKeys(value: unknown, label: string, defs: ReadonlyMap<string, CoreEventDef>, problems: string[]): CoreEventKey[] {\n const where = `${label}.events`;\n if (!Array.isArray(value)) {\n problems.push(`${where} is not a list`);\n return [];\n }\n const out: CoreEventKey[] = [];\n let last = -Infinity;\n value.forEach((raw, i) => {\n const at = `${where}[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${at} is not an object`);\n return;\n }\n for (const key of Object.keys(raw)) if (!(EVENT_KEY_FIELDS as readonly string[]).includes(key)) problems.push(`${at}: field \"${key}\" is not one an event key carries; it carries [${EVENT_KEY_FIELDS.join(', ')}]`);\n const t = raw.time;\n if (typeof t !== 'number' || !Number.isFinite(t) || t < 0) problems.push(`${at}: time is ${JSON.stringify(t)}, not a finite time at or after 0`);\n else if (t < last) problems.push(`${at}: time ${t} is before the key before it — the writer refuses event times that go backwards`);\n if (typeof t === 'number' && Number.isFinite(t)) last = Math.max(last, t);\n const def = typeof raw.name === 'string' ? defs.get(raw.name) : undefined;\n if (def === undefined) {\n problems.push(`${at}: event ${JSON.stringify(raw.name)} is not declared in the document's events`);\n return;\n }\n const p = payload(raw, at, problems);\n // Observed oracle behavior: a voiced key's omitted balance falls back to\n // the definition's volume, not its balance. A silent event keeps both at 0.\n out.push({ volume: def.audio ? p.volume ?? def.volume ?? 0 : 0, balance: def.audio ? p.balance ?? def.volume ?? 0 : 0, time: Math.fround(typeof t === 'number' && Number.isFinite(t) ? t : 0), name: def.name, int: p.int ?? def.int, float: p.float ?? def.float, string: p.string ?? def.string });\n });\n return out;\n}\n\n/** What lists the events fired over `(last, t]` — or across the wrap when `wrapped` — : `eventsFired` unless a plant passes another. */\nexport type EventsFired = (keys: readonly CoreEventKey[], last: number, t: number, round?: (v: number) => number | null, wrapped?: boolean) => CoreEventRow[];\n\n/**\n * The rows of the keys fired over `(last, t]`, in key order — the header's\n * rules, rounded as the oracle rounds. `wrapped` is a looping track's step\n * whose animation time went down (`t < last`, the wrap): the keys after\n * `last`, in key order, then the keys at or before `t`, in key order — the\n * header's *Across the wrap*. Nothing but a looping track passes it.\n */\nexport function eventsFired(keys: readonly CoreEventKey[], last: number, t: number, round: (v: number) => number | null = gridRound, wrapped = false): CoreEventRow[] {\n const row = (k: CoreEventKey): CoreEventRow => [k.name, round(k.time), k.int, round(k.float), k.string];\n if (wrapped) return [...keys.filter((k) => k.time > last), ...keys.filter((k) => k.time <= t)].map(row);\n return keys.filter((k) => k.time > last && k.time <= t).map(row);\n}\n","/**\n * The core's sixth construct: clipping applied to the draw (issue #964, §5\n * item 6 of the design on issue #380) — the oracle's `clipped` block, the\n * triangles every region and mesh drawn while a clip is active hands to the\n * runtime's clipper, as the clipper returns them.\n *\n * ## How every rule below was fixed\n *\n * By running spine-core 4.3.13's `SkeletonClipping` — `clipStart`,\n * `clipEnd(slot)`, `clipEnd()`, `isClipping` and `clipTrianglesUnpacked`, the\n * calls `src/render.ts` makes, in the order it makes them — on hand-written\n * skeletons and on random triangles and polygons, and reading what it\n * returned: the return value, `clippedVerticesTyped`, `clippedUVsTyped`,\n * `clippedTrianglesTyped`. The runtime's source was not read. Each rule is a\n * reading that reproduced every case measured, next to the readings the\n * measurements rejected. The core suite's `CL` controls hold a hand-written\n * skeleton of every case against the runtime at tolerance 0.\n *\n * ## When a clip is active — the draw walk\n *\n * The walk is `src/render.ts`'s `piecesOf`: slots in the posed draw order; at\n * a clipping attachment, end the clip if this slot is its end, then start\n * this clip if its slot's bone is active and no clip is active; at every\n * other slot, clip what it draws while a clip is active, then end the clip\n * if this slot is its end. Measured on one hand-written skeleton per case:\n *\n * | case | read |\n * | --- | --- |\n * | a clip ending at a slot | that slot is clipped, the one after it is not |\n * | ending at a slot that shows nothing | ends there all the same |\n * | ending at a slot drawn BEFORE the clip, or at its own slot | never ends: every later slot is clipped |\n * | no end slot | every later slot is clipped |\n * | a second clip while the first is active | ignored: a region inside the second and outside the first read wholly cut |\n * | a second clip after the first ended | applies |\n * | a clip ending at the slot of the next clip | the next clip starts there |\n * | a clip on an inactive bone | starts nothing |\n * | a region on an inactive bone under a clip | clipped like any other |\n *\n * ## What one triangle becomes\n *\n * The clip polygon is the clipping attachment's world polygon (the `clips`\n * row, `./vertices.ts`), unrounded. When its signed area is positive (counter\n * clockwise, y up) its vertices are reversed, so it is walked clockwise, and\n * its edges are taken from vertex 0: `(v0, v1), (v1, v2), …, (vn-1, v0)`.\n * A point is inside an edge `(p, q)` when `(q.x − p.x)(y − p.y) − (q.y −\n * p.y)(x − p.x) < 0`, strictly.\n *\n * Each triangle `(a, b, c)` of the attachment, in its own order, is clipped\n * edge by edge (Sutherland–Hodgman): walking the current polygon's sides\n * `(s, e)` from `(v0, v1)` round to `(vk, v0)`, an inside `s` with an inside\n * `e` keeps `e`; inside to outside adds the intersection; outside to inside\n * adds the intersection and then `e`; outside to outside adds nothing. The\n * intersection is `s + t·(e − s)` with `t = ((q.x − p.x)(s.y − p.y) − (q.y −\n * p.y)(s.x − p.x)) / ((q.y − p.y)(e.x − s.x) − (q.x − p.x)(e.y − s.y))`, in\n * doubles. A triangle no side of which was outside any edge is returned as it\n * came, `a, b, c` — not the rotation the walk leaves it in. A result of fewer\n * than three points adds nothing; otherwise its points are appended and fanned\n * from the first: `(0, 1, 2), (0, 2, 3), …` offset by the vertices already\n * written. The clipper stores vertices and UVs as float32: every number\n * written goes through `Math.fround`.\n *\n * A triangle no side of which was outside any edge keeps its corners' own\n * UVs (through `Math.fround`) rather than weighing them — the two agree on\n * the grid, and on three rows of `spineboy-pro`'s portal the weighed UV of a\n * corner at 0 read `2e-17` where the runtime holds 0 (issue #966, `dump\n * --raw`). Each point of a triangle that was cut has a UV barycentric over\n * the source triangle, from the unrounded\n * point: with `d = 1 / ((b.y − c.y)(a.x − c.x) + (c.x − b.x)(a.y − c.y))`,\n * `wa = ((b.y − c.y)(x − c.x) + (c.x − b.x)(y − c.y))·d`,\n * `wb = ((c.y − a.y)(x − c.x) + (a.x − c.x)(y − c.y))·d`, `wc = 1 − wa − wb`,\n * and `uv = ua·wa + ub·wb + uc·wc`, the corner UVs read through\n * `Math.fround`.\n *\n * The clipper returns `true` when any triangle had a point outside any edge,\n * else `false` — and `src/render.ts` then draws the attachment's own geometry.\n *\n * Measured on 2641 random cases, every polygon strictly convex, both\n * windings, one to three triangles of both windings each: 400 against\n * polygons of three to seven vertices, 600 whose intersections fall near the\n * origin, 1200 with corner UVs chosen so the weights' rounding shows, 300\n * cutting one edge once, and 141 random star polygons that came out convex —\n * the vertex list, the UVs, the triangle list and the return value exact on\n * 2641 of 2641. On the public corpus, `spineboy-pro`'s portal animation\n * (a three-vertex clip ending at a slot) reads IDENTICAL at tolerance 0 on\n * 4338 rows drawn under it (241 dense samples; 2653 left whole, 106 cut,\n * 1579 cut away). Rejected readings, each with what it read:\n *\n * | reading | read |\n * | --- | --- |\n * | the polygon's own winding, edges from vertex 0 | triangle lists 219 of 400; vertices 36 |\n * | the polygon made counter-clockwise, inside on the left | triangle lists 400; vertices in order 130 of 400 |\n * | a triangle wholly inside returned as the walk leaves it | 396 of 400 in order — the four wholly inside rotated |\n * | the polygon as its JSON spells it, through `Math.fround` | 79 of 400 exact: the world polygon carries the bone's matrix (`b` is `cos 90°` at the runtime's pi, −2.3e-8) |\n * | the intersection from the clip edge, `p + u·(q − p)` | 228 of 300 on a horizontal edge at y = 0, where `s + t·(e − s)` read 300 |\n * | the UV weights by a division rather than a reciprocal | 586 of 600 |\n * | the UV weights relative to `a` (`wb, wc` solved, `wa = 1 − wb − wc`) | 105 of 600 |\n *\n * ## What is not posed, and why\n *\n * The block is left out, naming the slot, when a clip that starts is one of:\n *\n * - ⚠️ **not strictly convex** — a reflex vertex, three collinear vertices or\n * a repeated one. The runtime decomposes such a polygon into convex pieces\n * and clips each triangle against each piece in turn: a covering triangle\n * read the pieces (a notched square into three triangles, an L into two\n * quads; a collinear vertex dropped; a repeated vertex clipped everything\n * away). Which pieces, in which order and from which vertex is the\n * runtime's own decomposition, and the dump alone did not fix it (issue\n * #964's report). Posing it would be guessing an algorithm.\n * - **`inverse`** — the clip keeps what is outside the polygon, through a\n * decomposition of the triangle around it (a covering triangle came back as\n * fifteen vertices in five fans). Not measured past that.\n *\n * What the core DRAWS under such a clip — a decomposition of its own, the\n * `clipped` block still left out — is the last section of this file\n * (`clipThrough`, issue #964).\n *\n * `convex: true` on a strictly convex polygon changes nothing: 400 of 400\n * cases byte-identical with and without it. On a polygon that is not, the\n * runtime clips against its convex hull (a notched square with `convex` read\n * as the square); that is the first case above and is left out.\n */\n/** One row of `clipped`: `[slot, attachment, clipped, vertices, uvs, triangles]`, the oracle's row. */\nexport type CoreClippedRow = [string, string, 0 | 1, Array<number | null>, Array<number | null>, number[]];\n\n/** What the clipper returns for one attachment: the return value and the three arrays, unrounded to the oracle's grid. */\nexport interface ClipResult {\n clipped: boolean;\n vertices: number[];\n uvs: number[];\n triangles: number[];\n /** The source triangle (an index into the attachment's triangles by threes) each returned triangle was cut from — what the render samples it at (issue #964). */\n sources: number[];\n}\n\ntype Pt = [number, number];\n\n/**\n * The readings the header's table rejected, each a switch — what the core\n * suite's `CL` plants pass to show the gate names it. `clipTriangles` with\n * none set is the rule measured; nothing but a plant sets one.\n */\nexport interface ClipReading {\n /** Walk the polygon in its own winding, not clockwise. */\n ownWinding?: boolean;\n /** Walk the polygon counter-clockwise — the runtime's winding flipped. */\n flippedWinding?: boolean;\n /** Return a triangle wholly inside as the walk leaves it. */\n insideRotated?: boolean;\n /** Take the intersection from the clip edge, `p + u·(q − p)`. */\n fromClipEdge?: boolean;\n /** Divide the UV weights by the determinant rather than multiply by its reciprocal. */\n uvByDivision?: boolean;\n}\n\n/** A world polygon's signed area, doubled: positive when counter-clockwise (y up). */\nexport function signedArea2(polygon: readonly number[]): number {\n let a = 0;\n const n = polygon.length / 2;\n for (let i = 0; i < n; i++) {\n const j = (i + 1) % n;\n a += polygon[2 * i] * polygon[2 * j + 1] - polygon[2 * j] * polygon[2 * i + 1];\n }\n return a;\n}\n\n/** Why a world polygon is not one the core clips against — not strictly convex — or null. */\nexport function convexWhy(polygon: readonly number[]): string | null {\n const n = polygon.length / 2;\n if (n < 3) return `it has ${n} vertex(es)`;\n let sign = 0;\n for (let i = 0; i < n; i++) {\n const [ax, ay] = [polygon[2 * i], polygon[2 * i + 1]];\n const j = (i + 1) % n;\n const k = (i + 2) % n;\n const cross = (polygon[2 * j] - ax) * (polygon[2 * k + 1] - polygon[2 * j + 1]) - (polygon[2 * j + 1] - ay) * (polygon[2 * k] - polygon[2 * j]);\n if (cross === 0) return `vertices ${i}, ${j} and ${k} are collinear or repeated`;\n const s = Math.sign(cross);\n if (sign === 0) sign = s;\n else if (s !== sign) return `vertex ${j} turns against the others (a reflex vertex)`;\n }\n return null;\n}\n\n/** The polygon walked clockwise, as the clipper walks it (the header). */\nfunction clockwise(polygon: readonly number[], reading: ClipReading): Pt[] {\n const pts: Pt[] = [];\n for (let i = 0; i + 1 < polygon.length; i += 2) pts.push([polygon[i], polygon[i + 1]]);\n if (reading.ownWinding === true) return pts;\n const cw = signedArea2(polygon) > 0 ? pts.reverse() : pts;\n return reading.flippedWinding === true ? cw.reverse() : cw;\n}\n\nfunction intersectFromClipEdge(s: Pt, e: Pt, p: Pt, q: Pt): Pt {\n const dx = e[0] - s[0];\n const dy = e[1] - s[1];\n const ex = q[0] - p[0];\n const ey = q[1] - p[1];\n const u = (dx * (s[1] - p[1]) - dy * (s[0] - p[0])) / (ey * dx - ex * dy);\n return [p[0] + u * ex, p[1] + u * ey];\n}\n\nfunction intersect(s: Pt, e: Pt, p: Pt, q: Pt): Pt {\n const dx = e[0] - s[0];\n const dy = e[1] - s[1];\n const ex = q[0] - p[0];\n const ey = q[1] - p[1];\n const t = (ex * (s[1] - p[1]) - ey * (s[0] - p[0])) / (ey * dx - ex * dy);\n return [s[0] + t * dx, s[1] + t * dy];\n}\n\n/** One triangle against the clockwise polygon: the points, and whether any side was outside any edge. */\nfunction clipTriangle(tri: readonly Pt[], poly: readonly Pt[], reading: ClipReading): { points: Pt[]; cut: boolean } {\n const cross = reading.fromClipEdge === true ? intersectFromClipEdge : intersect;\n let input: Pt[] = [...tri];\n let cut = false;\n for (let i = 0; i < poly.length && input.length > 0; i++) {\n const p = poly[i];\n const q = poly[(i + 1) % poly.length];\n const inside = (v: Pt): boolean => (q[0] - p[0]) * (v[1] - p[1]) - (q[1] - p[1]) * (v[0] - p[0]) < 0;\n const out: Pt[] = [];\n for (let k = 0; k < input.length; k++) {\n const s = input[k];\n const e = input[(k + 1) % input.length];\n const si = inside(s);\n const ei = inside(e);\n if (si) {\n if (ei) out.push(e);\n else {\n out.push(cross(s, e, p, q));\n cut = true;\n }\n } else {\n cut = true;\n if (ei) out.push(cross(s, e, p, q), e);\n }\n }\n input = out;\n }\n return { points: cut || reading.insideRotated === true ? input : [...tri], cut };\n}\n\n/**\n * An attachment's triangles clipped against a strictly convex world polygon —\n * the header's rule. `vertices` are the attachment's world vertices, `uvs`\n * one pair per vertex, `triangles` indices into them.\n */\nexport function clipTriangles(polygon: readonly number[], vertices: readonly number[], triangles: readonly number[], uvs: readonly number[], reading: ClipReading = {}): ClipResult {\n const poly = clockwise(polygon, reading);\n const f = Math.fround;\n const outV: number[] = [];\n const outUv: number[] = [];\n const outT: number[] = [];\n const sources: number[] = [];\n let clipped = false;\n for (let k = 0; k + 2 < triangles.length; k += 3) {\n const idx = [triangles[k], triangles[k + 1], triangles[k + 2]];\n const tri = idx.map((i): Pt => [vertices[2 * i], vertices[2 * i + 1]]);\n const tuv = idx.map((i): Pt => [f(uvs[2 * i]), f(uvs[2 * i + 1])]);\n const { points, cut } = clipTriangle(tri, poly, reading);\n for (let j = 1; j + 1 < points.length; j++) sources.push(k / 3);\n clipped ||= cut;\n if (points.length < 3) continue;\n const [a, b, c] = tri;\n const d0 = b[1] - c[1];\n const d1 = c[0] - b[0];\n const d2 = a[0] - c[0];\n const d4 = c[1] - a[1];\n const det = d0 * d2 + d1 * (a[1] - c[1]);\n const d = 1 / det;\n const weigh = (v: number): number => (reading.uvByDivision === true ? v / det : v * d);\n const base = outV.length / 2;\n // A triangle no side of which was outside any edge keeps its own corner UVs (issue #966): weighed barycentrically, a corner's UV of 0 reads 2e-17 off it, 3 rows of `spineboy-pro`'s portal.\n if (!cut && reading.insideRotated !== true) {\n tri.forEach(([x, y], k2) => {\n outV.push(f(x), f(y));\n outUv.push(tuv[k2][0], tuv[k2][1]);\n });\n for (let j = 1; j + 1 < points.length; j++) outT.push(base, base + j, base + j + 1);\n continue;\n }\n for (const [x, y] of points) {\n const wa = weigh(d0 * (x - c[0]) + d1 * (y - c[1]));\n const wb = weigh(d4 * (x - c[0]) + d2 * (y - c[1]));\n const wc = 1 - wa - wb;\n outV.push(f(x), f(y));\n outUv.push(f(tuv[0][0] * wa + tuv[1][0] * wb + tuv[2][0] * wc), f(tuv[0][1] * wa + tuv[1][1] * wb + tuv[2][1] * wc));\n }\n for (let j = 1; j + 1 < points.length; j++) outT.push(base, base + j, base + j + 1);\n }\n return { clipped, vertices: outV, uvs: outUv, triangles: outT, sources };\n}\n\n/** The clipper's reading of one attachment, replaceable by the suite's plants. */\nexport type TriangleClipper = (polygon: readonly number[], vertices: readonly number[], triangles: readonly number[], uvs: readonly number[]) => ClipResult;\n\n/** One step of the draw walk: a slot, what its bone's activity is, and what it shows as the walk reads it. */\nexport type DrawStep =\n | { slot: string; kind: 'clip'; attachment: string; active: boolean; end: string | null; polygon: number[]; inverse: boolean; convex: boolean }\n | { slot: string; kind: 'draw'; attachment: string; vertices: readonly number[]; triangles: readonly number[]; uvs: readonly number[] }\n | { slot: string; kind: 'none' };\n\n/**\n * The local UVs the oracle hands a region's four corners to the clipper with, in the corner order (bottom-left, upper-left, upper-right, bottom-right).\n * Frozen (issue #1530): every drawn region of every pose hands out this one array (`rawDrawn` in `./raw.ts`), so a write to it would reach every\n * frame a consumer holds — frozen, the write throws instead.\n */\nexport const REGION_UVS: readonly number[] = Object.freeze([0, 1, 0, 0, 1, 0, 1, 1]);\n/** A region's two triangles over its four corners — the runtime's quad triangulation (`src/render.ts`'s `QUAD_TRIANGLES`). Frozen, as `REGION_UVS` is and for its reason. */\nexport const REGION_TRIANGLES: readonly number[] = Object.freeze([0, 1, 2, 2, 3, 0]);\n\n/** `clipThrough`'s shape, replaceable by the render suite's plants (`RC08`'s dropped region). */\nexport type ShapeClipper = (shape: ClipShape, vertices: readonly number[], triangles: readonly number[], uvs: readonly number[]) => ClipResult | null;\n\n/**\n * The `clipped` block from the draw walk (the header's first table), every\n * number through `round`, or why it is absent: a clip that starts over a\n * polygon the core does not reproduce the runtime's triangle list for (not\n * strictly convex, or inverse), each named.\n *\n * Beside it, `drawn`: the same walk's rows as the core DRAWS them — the block's\n * own rows wherever the block is posed, and, where a clip that is not strictly\n * convex or is inverse starts, that clip cut through `clipThrough` (a\n * decomposition of the core's own, held to the runtime by the render's pixels,\n * issue #964). `drawnWhy` names a clip the core does not draw at all (a\n * polygon that is not simple).\n */\nexport function poseClipped(\n walk: readonly DrawStep[],\n round: (v: number) => number | null,\n clip: TriangleClipper = clipTriangles,\n through: ShapeClipper = (shape, v, t, uv) => clipThrough(shape, v, t, uv, clip),\n): { rows: CoreClippedRow[] | null; why: string | null; drawn: CoreClippedRow[] | null; drawnWhy: string | null } {\n const rows: CoreClippedRow[] = [];\n const refused: string[] = [];\n const undrawn: string[] = [];\n let active: { end: string | null; shape: ClipShape } | null = null;\n for (const step of walk) {\n if (step.kind === 'clip') {\n if (active !== null && active.end === step.slot) active = null;\n if (step.active && active === null) {\n const why = step.inverse ? 'it is inverse' : convexWhy(step.polygon);\n if (why !== null) refused.push(`slot \"${step.slot}\" starts clip \"${step.attachment}\", and ${why}`);\n const shape: ClipShape = { polygon: step.polygon, inverse: step.inverse, convex: step.convex };\n const plan = clipShapeOf(shape);\n if (plan.kind === 'refused') undrawn.push(`slot \"${step.slot}\" starts clip \"${step.attachment}\", and ${plan.why}`);\n active = { end: step.end, shape };\n }\n continue;\n }\n if (step.kind === 'draw' && active !== null) {\n const r = through(active.shape, step.vertices, step.triangles, step.uvs);\n if (r !== null) rows.push([step.slot, step.attachment, r.clipped ? 1 : 0, r.vertices.map(round), r.uvs.map(round), r.triangles]);\n }\n if (active !== null && active.end === step.slot) active = null;\n }\n const drawnWhy = undrawn.length === 0\n ? null\n : `${undrawn.join('; ')} — the runtime's coverage of a polygon that is not simple is its own triangulation's, measured not to be the polygon's area (src/core/clipping.ts)`;\n const drawn = drawnWhy === null ? rows : null;\n if (refused.length > 0) {\n return { rows: null, why: `${refused.join('; ')} — the runtime decomposes such a polygon into convex pieces of its own choosing, or clips the outside of an inverse one, and neither was reproduced from the dump (src/core/clipping.ts)`, drawn, drawnWhy };\n }\n return { rows, why: null, drawn, drawnWhy };\n}\n\n// ---------------------------------------------------------------------------\n// #964 what the core draws under a concave or inverse clip\n// ---------------------------------------------------------------------------\n//\n// The oracle's `clipped` block under such a clip is the runtime's own triangle list and stays\n// absent by name (above). What the core DRAWS there is a decomposition of its own, and the claim\n// it makes is coverage, not the list: the union of the pieces is the polygon whatever the pieces\n// are. Every reading below was fixed by running spine-core 4.3.13's `SkeletonClipping` (the calls\n// `src/render.ts` makes) and reading the area it returned; the source was not read, and the\n// runtime's decomposition was not reconstructed. The runtime's documentation of the two flags\n// (`ClippingAttachment.convex` / `.inverse` in its public type declarations) says `convex` clips\n// by the convex hull of a polygon that is not convex, and that inverse clipping is always convex.\n//\n// | polygon | the core | measured against spine-core |\n// | --- | --- | --- |\n// | strictly convex, not inverse | the measured rule above, one piece: the oracle's rows | the header's 2641 cases |\n// | simple, a reflex or a collinear vertex | collinear vertices dropped, ear clipping from vertex 0, pieces merged while strictly convex (Hertel–Mehlhorn); each triangle clipped against each piece in turn by the rule above | area and return value equal on every case of `CL05` |\n// | `convex: true`, simple | its convex hull, one piece | area equal (`CL05`); the hull is the documented reading |\n// | `inverse: true`, simple | the triangle outside the hull: for each hull edge in the walk, the part outside it and inside every edge before it | area and return value equal (`CL05`): the return value is `true` for every triangle, cut or not, as the runtime's was |\n// | an otherwise strictly convex polygon with a repeated vertex, not inverse | the rule above as it stands: its zero-length edge has no inside, so nothing is drawn | the runtime drew nothing on 141 of 141 random cases |\n// | a repeated vertex anywhere else | **refused**, naming the vertices | the runtime drew nothing on 11 of 159 random non-convex cases and the polygon's area on the other 148 — which, is its decomposition's |\n// | not simple (edges crossing or touching) | **refused**, naming the edges | a self-overlapping six-vertex fan read an area of 2.67 where its even-odd fill is 26.7, its non-zero fill 29.4 and its shoelace area 32; its `convex` and `inverse` readings used the same 2.67 |\n//\n// ⭐ The render draws through this pixel for pixel as spine-core draws (`RC08`), because the\n// rasteriser samples each drawn triangle at its SOURCE triangle's affine UV (`Mesh.source` in\n// `src/render.ts`, the source index being `ClipResult.sources`): before that, a pixel falling in\n// a sub-triangle other than the runtime's was sampled at a UV a few float32 steps off, and one\n// level of one channel moved on up to 50 pixels of a probe's frame set — as much as the runtime's\n// own render moved when the same polygon was spelled from another start vertex.\n\n/**\n * A clip as the draw reads it: its world polygon and its two flags. Which\n * reading `clipThrough` takes is `clipShapeOf`'s (the table in this section's\n * header, `clipThrough`).\n */\nexport interface ClipShape {\n polygon: readonly number[];\n inverse: boolean;\n convex: boolean;\n}\n\n/**\n * How a clip is drawn through the core: `convex` — the measured rule above,\n * one piece, the oracle's `clipped` block reproduced to the bit; `pieces` —\n * a simple polygon that is not strictly convex, cut into convex pieces of the\n * core's own choosing; `inverse` — the outside of the polygon's convex hull;\n * `empty` — an otherwise strictly convex polygon with a repeated vertex, which\n * the measured rule itself clips everything away against. `refused` names why\n * the core does not draw it.\n */\nexport type ClipPlan =\n | { kind: 'convex'; polygon: readonly number[] }\n | { kind: 'pieces'; pieces: Pt[][] }\n | { kind: 'inverse'; hull: Pt[] }\n | { kind: 'refused'; why: string };\n\nfunction pointsOf(polygon: readonly number[]): Pt[] {\n const pts: Pt[] = [];\n for (let i = 0; i + 1 < polygon.length; i += 2) pts.push([polygon[i], polygon[i + 1]]);\n return pts;\n}\n\nfunction cross3(o: Pt, a: Pt, b: Pt): number {\n return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);\n}\n\n/** Whether segments `ab` and `cd` meet, touching included (exact arithmetic on the doubles given). */\nfunction segmentsMeet(a: Pt, b: Pt, c: Pt, d: Pt): boolean {\n const d1 = cross3(c, d, a);\n const d2 = cross3(c, d, b);\n const d3 = cross3(a, b, c);\n const d4 = cross3(a, b, d);\n if (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0))) return true;\n const on = (p: Pt, q: Pt, r: Pt): boolean => Math.min(p[0], q[0]) <= r[0] && r[0] <= Math.max(p[0], q[0]) && Math.min(p[1], q[1]) <= r[1] && r[1] <= Math.max(p[1], q[1]);\n return (d1 === 0 && on(c, d, a)) || (d2 === 0 && on(c, d, b)) || (d3 === 0 && on(a, b, c)) || (d4 === 0 && on(a, b, d));\n}\n\n/** Why a polygon of distinct vertices is not simple — two edges that are not neighbours meet, or a neighbour folds back over its edge — or null. */\nfunction selfCrossingWhy(pts: readonly Pt[]): string | null {\n const n = pts.length;\n for (let i = 0; i < n; i++) {\n const a = pts[i];\n const b = pts[(i + 1) % n];\n // A neighbour folding back: the next edge runs back along this one.\n const c = pts[(i + 2) % n];\n if (cross3(a, b, c) === 0 && (c[0] - b[0]) * (a[0] - b[0]) + (c[1] - b[1]) * (a[1] - b[1]) > 0) return `edges ${i} and ${(i + 1) % n} fold back over each other at vertex ${(i + 1) % n}`;\n for (let j = i + 2; j < n; j++) {\n if (i === 0 && j === n - 1) continue;\n if (segmentsMeet(a, b, pts[j], pts[(j + 1) % n])) return `edges ${i} and ${j} cross or touch (the polygon is not simple)`;\n }\n }\n return null;\n}\n\n/** The polygon with every vertex dropped that lies on the line through its two neighbours — the area is the same. */\nfunction withoutCollinear(pts: readonly Pt[]): Pt[] {\n let out = [...pts];\n for (let changed = true; changed && out.length > 3; ) {\n changed = false;\n for (let i = 0; i < out.length; i++) {\n const prev = out[(i + out.length - 1) % out.length];\n const next = out[(i + 1) % out.length];\n if (cross3(prev, out[i], next) === 0) {\n out = [...out.slice(0, i), ...out.slice(i + 1)];\n changed = true;\n break;\n }\n }\n }\n return out;\n}\n\n/** The convex hull (Andrew's monotone chain), counter-clockwise, no collinear vertex, from the lowest-leftmost point. */\nfunction convexHull(pts: readonly Pt[]): Pt[] {\n const sorted = [...pts].sort((p, q) => p[0] - q[0] || p[1] - q[1]);\n const half = (list: readonly Pt[]): Pt[] => {\n const h: Pt[] = [];\n for (const p of list) {\n while (h.length >= 2 && cross3(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();\n h.push(p);\n }\n h.pop();\n return h;\n };\n return [...half(sorted), ...half([...sorted].reverse())];\n}\n\nfunction ccw(pts: readonly Pt[]): Pt[] {\n const flat = pts.flat();\n return signedArea2(flat) < 0 ? [...pts].reverse() : [...pts];\n}\n\n/**\n * A simple counter-clockwise polygon with no collinear vertex cut into convex\n * pieces: ear clipping into triangles (the first ear from vertex 0, walking\n * forward), then every diagonal removed whose two pieces merge into a strictly\n * convex polygon (Hertel–Mehlhorn), in the order the diagonals were cut. Each\n * piece is counter-clockwise, over the polygon's own vertices — none added,\n * every one used.\n */\nexport function convexPieces(polygon: readonly number[]): number[][] {\n return piecesOf(ccw(withoutCollinear(pointsOf(polygon)))).map((piece) => piece.flat());\n}\n\nfunction piecesOf(pts: readonly Pt[]): Pt[][] {\n const n = pts.length;\n const idx = pts.map((_, i) => i);\n const tris: number[][] = [];\n const inTri = (p: Pt, a: Pt, b: Pt, c: Pt): boolean => cross3(a, b, p) >= 0 && cross3(b, c, p) >= 0 && cross3(c, a, p) >= 0;\n while (idx.length > 3) {\n let cut = false;\n for (let k = 0; k < idx.length; k++) {\n const i0 = idx[(k + idx.length - 1) % idx.length];\n const i1 = idx[k];\n const i2 = idx[(k + 1) % idx.length];\n if (cross3(pts[i0], pts[i1], pts[i2]) <= 0) continue;\n if (idx.some((j) => j !== i0 && j !== i1 && j !== i2 && inTri(pts[j], pts[i0], pts[i1], pts[i2]))) continue;\n tris.push([i0, i1, i2]);\n idx.splice(k, 1);\n cut = true;\n break;\n }\n if (!cut) throw new Error(`convexPieces: no ear left among vertices [${idx.join(', ')}] of a polygon the caller held simple — a defect in src/core/clipping.ts`);\n }\n tris.push([...idx]);\n // Hertel–Mehlhorn: merge across a shared edge while the union stays strictly convex.\n let pieces = tris.map((t) => [...t]);\n const strictlyConvex = (ring: readonly number[]): boolean => ring.every((v, i) => cross3(pts[ring[(i + ring.length - 1) % ring.length]], pts[v], pts[ring[(i + 1) % ring.length]]) > 0);\n for (let merged = true; merged; ) {\n merged = false;\n search: for (let a = 0; a < pieces.length; a++) {\n for (let b = a + 1; b < pieces.length; b++) {\n const A = pieces[a];\n const B = pieces[b];\n for (let i = 0; i < A.length; i++) {\n const u = A[i];\n const v = A[(i + 1) % A.length];\n const j = B.indexOf(v);\n if (j < 0 || B[(j + 1) % B.length] !== u) continue;\n // A walks u→v, B walks v→u: splice B's other vertices in between.\n const rest: number[] = [];\n for (let k = (j + 2) % B.length; k !== j; k = (k + 1) % B.length) rest.push(B[k]);\n const ring = [...A.slice(0, i + 1), ...rest, ...A.slice(i + 1)];\n if (!strictlyConvex(ring)) continue;\n pieces = [...pieces.slice(0, a), ring, ...pieces.slice(a + 1, b), ...pieces.slice(b + 1)];\n merged = true;\n break search;\n }\n }\n }\n }\n if (n !== new Set(pieces.flat()).size) throw new Error('convexPieces: a vertex is in no piece — a defect in src/core/clipping.ts');\n return pieces.map((ring) => ring.map((v) => pts[v]));\n}\n\n/**\n * Which reading a clip is drawn through (this section's `ClipPlan`), from its\n * world polygon and flags. A strictly convex polygon (`convexWhy` null) is the\n * measured rule whatever its flags say but `inverse`; `convex` on any other\n * simple polygon, and `inverse` always, read its convex hull, as the\n * runtime's own documentation of the two flags states.\n */\nexport function clipShapeOf(shape: ClipShape): ClipPlan {\n const pts = pointsOf(shape.polygon);\n if (pts.length < 3) return { kind: 'refused', why: `it has ${pts.length} vertex(es)` };\n const repeated: string[] = [];\n for (let i = 0; i < pts.length; i++) for (let j = i + 1; j < pts.length; j++) if (pts[i][0] === pts[j][0] && pts[i][1] === pts[j][1]) repeated.push(`${i} and ${j}`);\n if (repeated.length > 0) {\n // Consecutive repeats of an otherwise strictly convex polygon: the measured rule, whose zero-length edge has no inside.\n const distinct = pts.filter((p, i) => { const q = pts[(i + 1) % pts.length]; return p[0] !== q[0] || p[1] !== q[1]; });\n if (!shape.inverse && distinct.length === pts.length - repeated.length && distinct.length >= 3 && convexWhy(distinct.flat()) === null) return { kind: 'convex', polygon: shape.polygon };\n return { kind: 'refused', why: `vertices ${repeated.join(', ')} are the same point` };\n }\n const crossing = selfCrossingWhy(pts);\n if (crossing !== null) return { kind: 'refused', why: crossing };\n const simple = withoutCollinear(pts);\n if (cross3(simple[0], simple[1], simple[2]) === 0 && simple.length === 3) return { kind: 'refused', why: 'every vertex lies on one line' };\n if (shape.inverse) return { kind: 'inverse', hull: convexHull(simple) };\n if (convexWhy(shape.polygon) === null) return { kind: 'convex', polygon: shape.polygon };\n if (shape.convex) return { kind: 'convex', polygon: convexHull(simple).flat() };\n const pieces = piecesOf(ccw(simple));\n return pieces.length === 1 ? { kind: 'convex', polygon: pieces[0].flat() } : { kind: 'pieces', pieces };\n}\n\n/** Clip `input` to the inside of the edge `(p, q)` — one Sutherland–Hodgman step of `clipTriangle`, the same inside test and intersection. */\nfunction clipHalf(input: readonly Pt[], p: Pt, q: Pt): { points: Pt[]; cut: boolean } {\n const inside = (v: Pt): boolean => (q[0] - p[0]) * (v[1] - p[1]) - (q[1] - p[1]) * (v[0] - p[0]) < 0;\n const out: Pt[] = [];\n let cut = false;\n for (let k = 0; k < input.length; k++) {\n const s = input[k];\n const e = input[(k + 1) % input.length];\n const si = inside(s);\n const ei = inside(e);\n if (si) {\n if (ei) out.push(e);\n else {\n out.push(intersect(s, e, p, q));\n cut = true;\n }\n } else {\n cut = true;\n if (ei) out.push(intersect(s, e, p, q), e);\n }\n }\n return { points: out, cut };\n}\n\n/**\n * An attachment's triangles clipped against any clip the core draws\n * (`clipShapeOf`): the measured convex rule for a strictly convex polygon —\n * `clipTriangles` itself, so the oracle's rows stand — and otherwise, triangle\n * by triangle in the attachment's order, each convex region of the plan in\n * turn, every region cut exactly as a convex clip cuts it (a region a triangle\n * lies wholly inside keeps its corners and their UVs; a cut one is weighed and\n * fanned from its first point). `null` where the plan is refused.\n *\n * `inverse`: the regions are the triangle's parts outside the clockwise hull,\n * one per hull edge in the walk's order — outside edge `i` and inside every\n * edge before it — so they tile the triangle minus the hull without overlap.\n */\nexport function clipThrough(\n shape: ClipShape,\n vertices: readonly number[],\n triangles: readonly number[],\n uvs: readonly number[],\n clip: TriangleClipper = clipTriangles,\n reading: { dropRegion?: number } = {},\n): ClipResult | null {\n let plan = clipShapeOf(shape);\n // CO11/CL01/CN06 and portal's convex rows need the original world doubles.\n // Two 66-point region/authored up_minus15 pieces witnesses went from 2 to 0\n // rendered pixel differences with Float32 input; SDK clipper storage was not observed.\n if (plan.kind === 'pieces') plan = clipShapeOf({ ...shape, polygon: shape.polygon.map(Math.fround) });\n if (plan.kind === 'refused') return null;\n if (plan.kind === 'convex') return clip(plan.polygon, vertices, triangles, uvs);\n const f = Math.fround;\n const outV: number[] = [];\n const outUv: number[] = [];\n const outT: number[] = [];\n const sources: number[] = [];\n let clipped = false;\n const regions = plan.kind === 'pieces' ? plan.pieces.map((piece) => clockwise(piece.flat(), {})) : null;\n const hull = plan.kind === 'inverse' ? clockwise(plan.hull.flat(), {}) : [];\n for (let k = 0; k + 2 < triangles.length; k += 3) {\n const idx = [triangles[k], triangles[k + 1], triangles[k + 2]];\n const tri = idx.map((i): Pt => [vertices[2 * i], vertices[2 * i + 1]]);\n const tuv = idx.map((i): Pt => [f(uvs[2 * i]), f(uvs[2 * i + 1])]);\n const parts: Array<{ points: Pt[]; cut: boolean }> = [];\n if (regions !== null) for (const poly of regions) parts.push(clipTriangle(tri, poly, {}));\n else {\n let remaining: Pt[] = [...tri];\n let cutSoFar = false;\n for (let i = 0; i < hull.length && remaining.length > 0; i++) {\n const p = hull[i];\n const q = hull[(i + 1) % hull.length];\n const outside = clipHalf(remaining, q, p);\n parts.push({ points: outside.cut || cutSoFar ? outside.points : [...tri], cut: outside.cut || cutSoFar });\n const inside = clipHalf(remaining, p, q);\n cutSoFar ||= inside.cut;\n remaining = inside.points;\n }\n clipped = true;\n }\n const [a, b, c] = tri;\n const d0 = b[1] - c[1];\n const d1 = c[0] - b[0];\n const d2 = a[0] - c[0];\n const d4 = c[1] - a[1];\n const d = 1 / (d0 * d2 + d1 * (a[1] - c[1]));\n for (const [r, { points, cut }] of parts.entries()) {\n clipped ||= cut;\n // `CL05`'s plant: one region of the plan dropped. Nothing but a plant sets it.\n if (r === reading.dropRegion) continue;\n if (points.length < 3) continue;\n const base = outV.length / 2;\n if (!cut) {\n tri.forEach(([x, y], k2) => {\n outV.push(f(x), f(y));\n outUv.push(tuv[k2][0], tuv[k2][1]);\n });\n } else {\n for (const [x, y] of points) {\n const wa = (d0 * (x - c[0]) + d1 * (y - c[1])) * d;\n const wb = (d4 * (x - c[0]) + d2 * (y - c[1])) * d;\n const wc = 1 - wa - wb;\n outV.push(f(x), f(y));\n outUv.push(f(tuv[0][0] * wa + tuv[1][0] * wb + tuv[2][0] * wc), f(tuv[0][1] * wa + tuv[1][1] * wb + tuv[2][1] * wc));\n }\n }\n for (let j = 1; j + 1 < points.length; j++) {\n outT.push(base, base + j, base + j + 1);\n sources.push(k / 3);\n }\n }\n }\n return { clipped, vertices: outV, uvs: outUv, triangles: outT, sources };\n}\n","/**\n * The core's third construct: every drawn attachment's world vertices at the\n * setup pose (issue #931, step 2c of issue #380) — the oracle's\n * `setup.attachments` block, a region's four corners and a mesh's vertices,\n * and its `setup.clips` block, a clipping polygon and the slot its clip ends\n * at. It is the first construct where the core's arithmetic meets geometry the\n * compiler measured, so exact equivalence here is also a check on the model.\n *\n * ## How every rule below was fixed\n *\n * By posing hand-written skeletons through `tools/pose_oracle.ts dump`\n * (spine-core 4.3.13, `--skin all`, `--physics none`) and comparing a formula\n * over the core's own world transforms (`./world.ts`) with the rows the dump\n * printed, at tolerance 0 on the oracle's six-decimal grid. The runtime's\n * source was not read. The bone rows read exact in every probe, so every\n * residual below belongs to the attachment rule. The core suite's `CO17`\n * holds a hand-written skeleton of every case against the core at tolerance 0.\n *\n * ## A region's four corners\n *\n * Let `W, H` be the record's `width, height`, `sx, sy` its `scaleX, scaleY`\n * (1 unstated), and `ox, oy, w, h, ow, oh` its atlas rectangle's `offsetX,\n * offsetY, width, height, originalWidth, originalHeight` (`ModelAtlasRect`,\n * issue #935). With `kx = W/ow·sx` and `ky = H/oh·sy`:\n *\n * x1 = −W/2·sx + ox·kx, y1 = −H/2·sy + oy·ky, x2 = x1 + w·kx, y2 = y1 + h·ky\n *\n * and the corners, in this order, are `(x1,y1) (x1,y2) (x2,y2) (x2,y1)` —\n * bottom-left, upper-left, upper-right, bottom-right, as the oracle's header\n * words them. Each is turned by the record's `rotation` (degrees, pi written\n * as `./world.ts`'s `RUNTIME_PI`), moved by its `x, y` (0 unstated), and\n * carried through the slot bone's world matrix: `a·x + b·y + worldX`,\n * `c·x + d·y + worldY`. Every record field is read as the double the document\n * spells.\n *\n * Measured on 6000 hand-written regions — 70% of them trimmed, atlas `rotate`\n * 0, 90, 180 or 270, placement in ±50, rotation in ±180 and scale in ±2 —\n * each on one of ten bones rotated, scaled, sheared and reflecting, posed\n * four times: field values float32-exact and spelled with five non-float32\n * decimals, each on a page of `scale:` 1 and 0.37 (1500 each):\n *\n * | reading | exact |\n * | --- | ---: |\n * | the rule above, fields as doubles | 6000 of 6000 |\n * | the trim ignored (`w, h` for `ow, oh`, offsets 0) | 1796 of 6000, worst 335.43 units |\n * | the fields read through `Math.fround`, on the non-float32 spellings | 13 of 3000, worst 41 millionths |\n * | the atlas `bounds` taken as transposed at 90 and 270 | 3007 of 6000, worst 1634.26 units |\n *\n * So the page's `scale:` and the atlas's `rotate` do not enter the corners;\n * the rectangle's `width` and `height` are in the drawing's orientation, as\n * `AtlasRegion` in `src/atlas.ts` states.\n *\n * - **A region with a `sequence` draws its setup frame's rectangle.** Four\n * probes of one three-frame sequence whose frames differ in their trims:\n * `setup` unstated and `setup: 0` matched frame 0's corners, `setup: 1`\n * frame 1's and `setup: 2` frame 2's, and no other frame's. The frame is\n * the model's `sequence.atlas[setup ?? 0]`.\n * - ⛔ **A region whose rectangle is `null` leaves the whole block out, by\n * name.** `null` is the model's statement that the build had no source for\n * that region (`ModelRegionAttachment.atlas`); posing it at a trim of 0\n * would be inventing the four numbers the corners read — the build pair of\n * issue #931 posed one such document 11.925 world units apart. A block\n * with one row missing would read as a roster difference, not an absence,\n * so the block is absent and every such slot is named.\n *\n * ## A mesh's vertices, and a clipping polygon's\n *\n * - Unweighted: each local `x, y` through the slot bone's world matrix plus\n * its origin.\n * - Weighted: per vertex, the sum over its bindings in order of\n * `(x·a + y·b + worldX)·weight` and `(x·c + y·d + worldY)·weight`, each\n * binding's bone looked up BY NAME (`ModelBinding`) — its world, not the\n * slot bone's.\n * - ⚠️ **Every vertex coordinate, bind coordinate and weight is read through\n * `Math.fround` first**: the runtime stores a vertex attachment's array as\n * float32, while it reads a bone's and a region's numbers as the doubles\n * the text spells (`src/model.ts`'s 🔸). Measured on 1200 meshes over the\n * ten bones (60% weighted over one to four of them): float32-exact inputs\n * 600 of 600 either way; inputs with five non-float32 decimals 600 of 600\n * through `Math.fround`, 0 of 600 as doubles (worst 11 millionths). On the\n * corpus, `gallery/flex`'s weighted meshes and `gallery/squash`'s ball read\n * 1 to 3 millionths off as doubles and exact through `Math.fround`.\n * - A linked mesh is written by the oracle as kind `mesh` under its own name,\n * and its vertices are its SOURCE mesh's (`skin`, `slot`, `source` in the\n * model) through the linked mesh's own slot bone: a linked mesh on a\n * rotated, reflected and sheared bone, sourced from a mesh in another slot\n * of another skin, read exact.\n * - The atlas does not enter a mesh's vertices, and a mesh's `sequence`\n * changes none of them.\n * - A clipping polygon follows the mesh rule, and its row's `end` is the\n * model's `end` slot or `null`: 1200 polygons drawn as the meshes above,\n * half of them ending at a slot, read exact and with the right end through\n * `Math.fround` (600 of 600 on each spelling), and 0 of 600 as doubles on\n * the non-float32 spelling (worst 11 millionths).\n *\n * ## Which slots, and in what order\n *\n * A slot is listed when what it shows at setup (`shownAttachment`, issue\n * #928) is a region, a mesh or a linked mesh (`setup.attachments`) or a\n * clipping polygon (`setup.clips`), whether or not its bone is active — an\n * inactive bone's world is all zeros, and the oracle's ill-conditioned rule\n * excludes it. Rows are in the model's slot order, which is the setup draw\n * order (`ModelSlot`): measured the same order as spine-core's on 19 of 19\n * recipes. A bounding box and a path attachment have no row: the oracle's\n * dump writes no vertices for either, so neither can be posed against it.\n *\n * ## At a sample, and under a deform or a sequence (issue #955)\n *\n * `poseGeometry` poses a sample's attachments the same way, through the\n * sample's bones and in its draw order. A slot a deform timeline moved\n * carries its deform array (`ShownGeometry.deform`): the vertices are the\n * array's (`deformedVertices` in `./deform.ts`) and their coordinates are read\n * AS THEY ARE, not through `Math.fround` again — a lerped deform is a double\n * the runtime does not round (`./deform.ts`'s header: the lerped positions\n * rounded to float32 missed 791 of 800 samples). A region a sequence\n * timeline stepped carries its frame (`ShownGeometry.frame`), and its corners\n * read that frame's rectangle (`CoreRegionGeometry.frames`).\n */\nimport type { ModelAtlasRect, ModelBinding, ModelVertices } from '../model.ts';\nimport { RUNTIME_PI, type CoreWorld } from './world.ts';\nimport { deformedVertices } from './deform.ts';\nimport { poseClipped, REGION_TRIANGLES, REGION_UVS, type CoreClippedRow, type DrawStep, type ShapeClipper, type TriangleClipper } from './clipping.ts';\n\nconst RAD = RUNTIME_PI / 180;\n\n/** What a region record carries for its corners — `atlas` already the rectangle of the frame shown at setup. */\nexport interface CoreRegionGeometry {\n x?: number;\n y?: number;\n rotation?: number;\n scaleX?: number;\n scaleY?: number;\n width: number;\n height: number;\n /** The rectangle drawn at setup, or `null` when the model states the build had none. */\n atlas: ModelAtlasRect | null;\n /** A sequence's rectangles, one per frame (`sequence.atlas`) — what a sequence timeline's frame draws (`./deform.ts`). */\n frames?: ModelAtlasRect[];\n}\n\n/** The geometry a record carries, by kind, as far as the construct reads it. */\nexport type CoreGeometry =\n | { kind: 'region'; region: CoreRegionGeometry }\n | { kind: 'mesh'; vertices: ModelVertices; uvs: number[]; triangles: number[]; hull?: number }\n | { kind: 'linkedmesh'; skin: string; slot: string; source: string }\n | { kind: 'clipping'; end: string | null; vertices: ModelVertices; inverse: boolean; convex: boolean }\n | { kind: 'boundingbox'; vertices: ModelVertices }\n | { kind: 'path'; vertices: ModelVertices; closed: boolean; constantSpeed: boolean; lengths: number[] };\n\n/** A mesh's geometry as the document view files it — what `meshArraysOf` keys on. */\nexport type CoreMeshGeometry = Extract<CoreGeometry, { kind: 'mesh' }>;\n\n/** A mesh's UVs and triangles as a pose hands them out: read-only, and the same arrays on every pose. */\nexport interface MeshArrays {\n readonly uvs: readonly number[];\n readonly triangles: readonly number[];\n}\n\n/** What hands out a mesh's `MeshArrays`: `meshArraysOf` unless a control passes another (the core suite's shared-array control). */\nexport type MeshArraysOf = (mesh: CoreMeshGeometry) => MeshArrays;\n\n/** Each mesh geometry's frozen arrays, keyed on the document view's own geometry object, which no reader writes. */\nconst meshArraysByGeometry = new WeakMap<CoreMeshGeometry, MeshArrays>();\n\n/**\n * A mesh's UVs and triangles, copied once per geometry object and frozen\n * (issue #1530). The raw entry used to spread both into new arrays on every\n * pose for every drawn mesh, so that a consumer writing into a pose's arrays\n * could not reach the document's; frozen, a write throws instead, and every\n * pose of every walk and track over the same document view hands out the\n * same two arrays — so a consumer keyed on them by identity reuses what it\n * built from them. The copy is what keeps the document's own arrays out of a\n * consumer's hands: they are the reader's, and freezing them would write to\n * a value the caller passed in.\n */\nexport function meshArraysOf(mesh: CoreMeshGeometry): MeshArrays {\n let kept = meshArraysByGeometry.get(mesh);\n if (kept === undefined) {\n kept = Object.freeze({ uvs: Object.freeze([...mesh.uvs]), triangles: Object.freeze([...mesh.triangles]) });\n meshArraysByGeometry.set(mesh, kept);\n }\n return kept;\n}\n\n/** One row of `setup.attachments`: `[slot, attachment, kind, vertices]`, the oracle's row. */\nexport type CoreAttachmentRow = [string, string, 'region' | 'mesh', Array<number | null>];\n/** One row of `setup.clips`: `[slot, attachment, end, polygon]`, the oracle's row. */\nexport type CoreClipRow = [string, string, string | null, Array<number | null>];\n\n/** What computes a region's corners in the slot bone's world: `regionCorners` unless a caller passes another. */\nexport type RegionPoser = (region: CoreRegionGeometry & { atlas: ModelAtlasRect }, bone: CoreWorld) => number[];\n/** What computes a vertex array's world positions: `worldVertices` unless a caller passes another. */\nexport type VertexPoser = (vertices: ModelVertices, bone: CoreWorld, world: ReadonlyMap<string, CoreWorld>, coords?: (v: number) => number) => number[];\n/** What computes a deformed vertex array's world positions in one pass: `deformedWorldVertices` unless a caller passes another. */\nexport type DeformedVertexPoser = (vertices: ModelVertices, deform: readonly number[], bone: CoreWorld, world: ReadonlyMap<string, CoreWorld>) => number[];\n\n/** A deformed array's coordinates are read as they are (`./deform.ts`, `deformedVertices`): they are not the stored float32s. */\nexport const EXACT_COORDS = (v: number): number => v;\n\n/** A region's four corners in world units — the header's rule. */\nexport function regionCorners(region: CoreRegionGeometry & { atlas: ModelAtlasRect }, bone: CoreWorld): number[] {\n const { width: W, height: H } = region;\n const sx = region.scaleX ?? 1;\n const sy = region.scaleY ?? 1;\n const r = region.atlas;\n const kx = (W / r.originalWidth) * sx;\n const ky = (H / r.originalHeight) * sy;\n const x1 = (-W / 2) * sx + r.offsetX * kx;\n const y1 = (-H / 2) * sy + r.offsetY * ky;\n const x2 = x1 + r.width * kx;\n const y2 = y1 + r.height * ky;\n const angle = (region.rotation ?? 0) * RAD;\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n const x = region.x ?? 0;\n const y = region.y ?? 0;\n const out: number[] = [];\n for (const [px, py] of [[x1, y1], [x1, y2], [x2, y2], [x2, y1]]) {\n // The operation order is measured to the bit (issue #966): the placement is added to the cosine term before the sine term is taken off — `px·cos − py·sin + x` reads 1 ulp off on 748 attachment-samples of six corpus rows.\n const lx = px * cos + x - py * sin;\n const ly = py * cos + y + px * sin;\n out.push(bone.a * lx + bone.b * ly + bone.worldX, bone.c * lx + bone.d * ly + bone.worldY);\n }\n return out;\n}\n\n/** A weighted vertex array as the model states it. */\nexport type WeightedVertices = Extract<ModelVertices, { weighted: true }>;\n\n/**\n * One influence of a compiled weighted vertex (issue #1580): its bone as an\n * index into `CompiledWeightedVertices.bones`, its raw coordinates (`x`, `y`)\n * for a caller passing a custom `coords`, and its `Math.fround`-rounded\n * coordinates (`fx`, `fy`) and `weight` for the default posing path.\n */\nexport interface CompiledBinding {\n readonly bone: number;\n readonly x: number;\n readonly y: number;\n readonly fx: number;\n readonly fy: number;\n readonly weight: number;\n}\n\n/**\n * A weighted vertex array's bone bindings compiled to integer indices into\n * `bones` (issue #1580): `bones` lists the distinct bone names in exact\n * first-occurrence order across `vertices.bindings`, and `bindings` keeps the\n * outer vertex order and inner influence order untouched so the summation\n * order and every posed coordinate stay bit-for-bit (`Object.is`) identical.\n */\nexport interface CompiledWeightedVertices {\n readonly bones: readonly string[];\n readonly bindings: ReadonlyArray<readonly CompiledBinding[]>;\n}\n\n/** Each weighted vertex array's compiled index table, keyed on the `WeightedVertices` object itself. */\nconst compiledWeightedByVertices = new WeakMap<WeightedVertices, CompiledWeightedVertices>();\n\n/**\n * Compile `vertices`'s bone names to integer indices in first-occurrence order\n * (issue #1580). With `mapIndex`, each binding's index is passed through it\n * instead (the core suite's wrong-index plant).\n */\nexport function compileWeightedVertices(\n vertices: WeightedVertices,\n mapIndex?: (boneIndex: number, boneCount: number) => number,\n): CompiledWeightedVertices {\n const bones: string[] = [];\n const indexByName = new Map<string, number>();\n for (const influences of vertices.bindings) {\n for (const binding of influences) {\n if (!indexByName.has(binding.bone)) {\n indexByName.set(binding.bone, bones.length);\n bones.push(binding.bone);\n }\n }\n }\n const count = bones.length;\n const bindings: CompiledBinding[][] = vertices.bindings.map((influences) =>\n influences.map((binding) => {\n const idx = indexByName.get(binding.bone) as number;\n return {\n bone: mapIndex === undefined ? idx : mapIndex(idx, count),\n x: binding.x,\n y: binding.y,\n fx: Math.fround(binding.x),\n fy: Math.fround(binding.y),\n weight: Math.fround(binding.weight),\n };\n }),\n );\n return { bones, bindings };\n}\n\n/**\n * The cached `CompiledWeightedVertices` for `vertices`, compiled once per\n * `WeightedVertices` object and never shared across two different vertex\n * objects.\n */\nexport function compiledWeightedOf(vertices: WeightedVertices): CompiledWeightedVertices {\n let kept = compiledWeightedByVertices.get(vertices);\n if (kept === undefined) {\n kept = compileWeightedVertices(vertices);\n compiledWeightedByVertices.set(vertices, kept);\n }\n return kept;\n}\n\n/**\n * Resolve each distinct bone of `bones` once per pose call into a dense array\n * indexed by `CompiledBinding.bone`. Because `bones` is in first-occurrence\n * order across `vertices.bindings`, a missing bone throws the same error on\n * the same bone name as a per-influence lookup.\n */\nfunction resolveBindingBones(bones: readonly string[], world: ReadonlyMap<string, CoreWorld>): CoreWorld[] {\n const transforms = new Array<CoreWorld>(bones.length);\n for (let i = 0; i < bones.length; i++) {\n const name = bones[i];\n const t = world.get(name);\n if (t === undefined) throw new Error(`a binding names bone \"${name}\", which has no world transform (readModel refuses it first)`);\n transforms[i] = t;\n }\n return transforms;\n}\n\n/**\n * Evaluate a compiled weighted vertex table against `world` (issue #1580),\n * looking up each distinct bone once per call and summing influences in their\n * original order.\n */\nexport function compiledWorldVertices(\n compiled: CompiledWeightedVertices,\n world: ReadonlyMap<string, CoreWorld>,\n coords: (v: number) => number = Math.fround,\n): number[] {\n const transforms = resolveBindingBones(compiled.bones, world);\n const out: number[] = [];\n const fround = coords === Math.fround;\n for (const influences of compiled.bindings) {\n let wx = 0;\n let wy = 0;\n for (const binding of influences) {\n const t = transforms[binding.bone];\n const x = fround ? binding.fx : coords(binding.x);\n const y = fround ? binding.fy : coords(binding.y);\n const weight = binding.weight;\n wx += (x * t.a + y * t.b + t.worldX) * weight;\n wy += (x * t.c + y * t.d + t.worldY) * weight;\n }\n out.push(wx, wy);\n }\n return out;\n}\n\n/**\n * Evaluate a compiled weighted vertex table with `deform` in one pass\n * (issues #1530, #1580), looking up each distinct bone once per call and\n * summing influences in their original order.\n */\nexport function compiledDeformedWorldVertices(\n compiled: CompiledWeightedVertices,\n deform: readonly number[],\n world: ReadonlyMap<string, CoreWorld>,\n): number[] {\n const transforms = resolveBindingBones(compiled.bones, world);\n const out: number[] = [];\n let k = 0;\n for (const influences of compiled.bindings) {\n let wx = 0;\n let wy = 0;\n for (const binding of influences) {\n const t = transforms[binding.bone];\n const x = binding.fx + deform[k];\n const y = binding.fy + deform[k + 1];\n k += 2;\n const weight = binding.weight;\n wx += (x * t.a + y * t.b + t.worldX) * weight;\n wy += (x * t.c + y * t.d + t.worldY) * weight;\n }\n out.push(wx, wy);\n }\n return out;\n}\n\n/**\n * A vertex array's world positions — the header's mesh rule, every stored\n * number through `Math.fround`; with `coords`, the coordinates through it\n * instead (a deformed array's are read as they are, `EXACT_COORDS`), the\n * weights through `Math.fround` still. Weighted bone bindings are compiled once\n * per vertex object to integer indices (`compiledWeightedOf`, issue #1580) so\n * each pose looks up each distinct bone once rather than per influence.\n */\nexport function worldVertices(vertices: ModelVertices, bone: CoreWorld, world: ReadonlyMap<string, CoreWorld>, coords: (v: number) => number = Math.fround): number[] {\n if (!vertices.weighted) {\n const out: number[] = [];\n for (let i = 0; i + 1 < vertices.xy.length; i += 2) {\n const x = coords(vertices.xy[i]);\n const y = coords(vertices.xy[i + 1]);\n out.push(x * bone.a + y * bone.b + bone.worldX, x * bone.c + y * bone.d + bone.worldY);\n }\n return out;\n }\n return compiledWorldVertices(compiledWeightedOf(vertices), world, coords);\n}\n\n/**\n * `worldVertices(deformedVertices(vertices, deform), bone, world, EXACT_COORDS)`\n * in one pass (issues #1530, #1580): the same operations on the same numbers in the\n * same order — an unweighted vertex's coordinates are the deform array's,\n * read as they are; a weighted binding's are its float32 coordinate plus the\n * deform's pair, its weight through `Math.fround`, its bone transform indexed\n * through `compiledWeightedOf` — without building the deformed array (and,\n * weighted, one binding record per influence) on every pose only to map it\n * again. A planted vertex poser still reads the deformed array (`poseGeometry`).\n * Posed output is held equal by the core gate's sample attachments and by\n * `tools/posed_frames.ts` across the change.\n */\nexport function deformedWorldVertices(vertices: ModelVertices, deform: readonly number[], bone: CoreWorld, world: ReadonlyMap<string, CoreWorld>): number[] {\n if (!vertices.weighted) {\n const out: number[] = [];\n for (let i = 0; i + 1 < deform.length; i += 2) {\n const x = deform[i];\n const y = deform[i + 1];\n out.push(x * bone.a + y * bone.b + bone.worldX, x * bone.c + y * bone.d + bone.worldY);\n }\n return out;\n }\n return compiledDeformedWorldVertices(compiledWeightedOf(vertices), deform, world);\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nconst finite = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);\nconst RECT_FIELDS = ['width', 'height', 'offsetX', 'offsetY', 'originalWidth', 'originalHeight'] as const;\n\nfunction readRect(value: unknown, where: string, problems: string[]): ModelAtlasRect | undefined {\n if (!isRecord(value)) {\n problems.push(`${where} is ${JSON.stringify(value)}, not an atlas rectangle`);\n return undefined;\n }\n const before = problems.length;\n for (const key of Object.keys(value)) if (!(RECT_FIELDS as readonly string[]).includes(key)) problems.push(`${where}: field \"${key}\" is not one this reader knows; it reads [${RECT_FIELDS.join(', ')}]`);\n for (const key of RECT_FIELDS) if (!finite(value[key])) problems.push(`${where}: ${key} is ${JSON.stringify(value[key]) ?? 'absent'}, not a finite number`);\n return problems.length === before ? (value as unknown as ModelAtlasRect) : undefined;\n}\n\n/** A `ModelVertices`, checked: an even run of finite numbers, or per vertex a non-empty list of bindings each naming a bone of the document. */\nfunction readVertices(value: unknown, where: string, bones: ReadonlySet<string>, problems: string[]): ModelVertices | undefined {\n if (!isRecord(value) || typeof value.weighted !== 'boolean') {\n problems.push(`${where} is not { weighted: false, xy } or { weighted: true, bindings }`);\n return undefined;\n }\n const before = problems.length;\n if (!value.weighted) {\n const xy = value.xy;\n if (!Array.isArray(xy) || xy.length % 2 !== 0 || !xy.every(finite)) problems.push(`${where}.xy is not an even-length list of finite numbers`);\n return problems.length === before ? { weighted: false, xy: xy as number[] } : undefined;\n }\n const bindings = value.bindings;\n if (!Array.isArray(bindings)) {\n problems.push(`${where}.bindings is not a list`);\n return undefined;\n }\n bindings.forEach((influences, i) => {\n if (!Array.isArray(influences) || influences.length === 0) {\n problems.push(`${where}.bindings[${i}] is not a non-empty list of bindings`);\n return;\n }\n influences.forEach((b: unknown, j) => {\n const at = `${where}.bindings[${i}][${j}]`;\n if (!isRecord(b)) {\n problems.push(`${at} is not an object`);\n return;\n }\n if (typeof b.bone !== 'string' || !bones.has(b.bone)) problems.push(`${at}: bone ${JSON.stringify(b.bone)} is not a bone of this document`);\n for (const key of ['x', 'y', 'weight'] as const) if (!finite(b[key])) problems.push(`${at}: ${key} is ${JSON.stringify(b[key]) ?? 'absent'}, not a finite number`);\n });\n });\n if (problems.length !== before) return undefined;\n const weighted: WeightedVertices = { weighted: true, bindings: bindings as ModelBinding[][] };\n compiledWeightedByVertices.set(weighted, compileWeightedVertices(weighted));\n return weighted;\n}\n\n/**\n * The geometry of one attachment record, read and checked field by field —\n * called by `readModel` for every record of every skin. Returns `undefined`\n * when something was refused (the problem is pushed, naming the path). What is\n * refused mirrors the writer (`attachmentOf` in `src/model.ts`): a region\n * carrying neither a rectangle nor a sequence, or both; a sequence whose\n * `atlas` is not one rectangle per frame, or whose setup frame is not one of\n * them; and a binding, a linked mesh's link or a clip's `end` naming nothing.\n * A linked mesh's source is resolved later, once every skin is read.\n */\nexport function readGeometry(raw: Record<string, unknown>, kind: CoreGeometry['kind'], where: string, bones: ReadonlySet<string>, slots: ReadonlySet<string>, problems: string[]): CoreGeometry | undefined {\n const before = problems.length;\n switch (kind) {\n case 'region': {\n for (const key of ['x', 'y', 'rotation', 'scaleX', 'scaleY'] as const) if (raw[key] !== undefined && !finite(raw[key])) problems.push(`${where}: ${key} is ${JSON.stringify(raw[key])}, not a finite number`);\n for (const key of ['width', 'height'] as const) if (!finite(raw[key])) problems.push(`${where}: ${key} is ${JSON.stringify(raw[key]) ?? 'absent'}, not a finite number`);\n const hasRect = raw.atlas !== undefined;\n const hasSequence = raw.sequence !== undefined;\n let atlas: ModelAtlasRect | null | undefined;\n let frames: ModelAtlasRect[] | undefined;\n if (hasRect === hasSequence) {\n problems.push(`${where}: the region carries ${hasRect ? 'both an atlas rectangle and a sequence' : 'neither an atlas rectangle nor a sequence'}; the writer states exactly one of the two, and a sequence holds a rectangle per frame (issue #935)`);\n } else if (hasRect) {\n // `readModel` has read the rectangle itself (`readAtlasRect`); here only its value is taken.\n atlas = raw.atlas === null ? null : isRecord(raw.atlas) ? (raw.atlas as unknown as ModelAtlasRect) : undefined;\n } else {\n const seq = raw.sequence;\n if (!isRecord(seq)) problems.push(`${where}.sequence is not an object`);\n else {\n const count = seq.count;\n const setup = seq.setup ?? 0;\n if (typeof count !== 'number' || !Number.isInteger(count) || count < 1) problems.push(`${where}.sequence: count is ${JSON.stringify(count)}, not a whole number of at least 1`);\n else if (typeof setup !== 'number' || !Number.isInteger(setup) || setup < 0 || setup >= count) problems.push(`${where}.sequence: setup is ${JSON.stringify(seq.setup)}, not a frame of the ${count}`);\n if (!Array.isArray(seq.atlas) || seq.atlas.length !== count) problems.push(`${where}.sequence: atlas is not a list of ${JSON.stringify(count)} rectangle(s), one per frame`);\n else {\n const rects = seq.atlas.map((r, i) => readRect(r, `${where}.sequence.atlas[${i}]`, problems));\n if (typeof setup === 'number' && Number.isInteger(setup) && setup >= 0 && setup < rects.length) atlas = rects[setup];\n if (rects.every((r) => r !== undefined)) frames = rects as ModelAtlasRect[];\n }\n }\n }\n if (problems.length !== before || atlas === undefined) return undefined;\n const pick = (key: 'x' | 'y' | 'rotation' | 'scaleX' | 'scaleY'): { [k: string]: number } => (raw[key] === undefined ? {} : { [key]: raw[key] as number });\n return {\n kind: 'region',\n region: { ...pick('x'), ...pick('y'), ...pick('rotation'), ...pick('scaleX'), ...pick('scaleY'), width: raw.width as number, height: raw.height as number, atlas, ...(frames === undefined ? {} : { frames }) },\n };\n }\n case 'linkedmesh': {\n for (const key of ['skin', 'slot', 'source'] as const) if (typeof raw[key] !== 'string' || raw[key] === '') problems.push(`${where}: ${key} is ${JSON.stringify(raw[key]) ?? 'absent'}, not a non-empty string`);\n if (typeof raw.slot === 'string' && !slots.has(raw.slot)) problems.push(`${where}: slot \"${raw.slot}\" is not a slot of this document`);\n if (problems.length !== before) return undefined;\n return { kind: 'linkedmesh', skin: raw.skin as string, slot: raw.slot as string, source: raw.source as string };\n }\n case 'mesh':\n case 'clipping':\n case 'boundingbox':\n case 'path': {\n const vertices = readVertices(raw.vertices, `${where}.vertices`, bones, problems);\n if (kind === 'clipping' && raw.end !== undefined && (typeof raw.end !== 'string' || !slots.has(raw.end))) problems.push(`${where}: end is ${JSON.stringify(raw.end)}, not a slot of this document`);\n if (kind === 'clipping') for (const key of ['inverse', 'convex'] as const) if (raw[key] !== undefined && typeof raw[key] !== 'boolean') problems.push(`${where}: ${key} is ${JSON.stringify(raw[key])}, not a boolean`);\n const mesh = kind === 'mesh' && vertices !== undefined ? readMeshTriangles(raw, vertices, where, problems) : undefined;\n if (vertices === undefined || problems.length !== before) return undefined;\n if (kind === 'mesh') return mesh === undefined ? undefined : { kind, vertices, ...mesh };\n if (kind === 'clipping') return { kind, end: typeof raw.end === 'string' ? raw.end : null, vertices, inverse: raw.inverse === true, convex: raw.convex === true };\n if (kind === 'boundingbox') return { kind, vertices };\n return readPathGeometry(raw, vertices, where, problems);\n }\n }\n}\n\n/**\n * A mesh's `uvs` and `triangles`, what the clipper reads besides its vertices\n * (issue #964, `./clipping.ts`): one finite pair per vertex, and whole\n * indices into the vertices in threes — as the writer writes them.\n */\nfunction readMeshTriangles(raw: Record<string, unknown>, vertices: ModelVertices, where: string, problems: string[]): { uvs: number[]; triangles: number[]; hull?: number } | undefined {\n const before = problems.length;\n const count = vertices.weighted ? vertices.bindings.length : vertices.xy.length / 2;\n const uvs = raw.uvs;\n const triangles = raw.triangles;\n if (!Array.isArray(uvs) || !uvs.every(finite) || uvs.length !== 2 * count) problems.push(`${where}.uvs is not ${2 * count} finite numbers, one pair per vertex`);\n if (!Array.isArray(triangles) || triangles.length % 3 !== 0 || !triangles.every((i) => Number.isInteger(i) && i >= 0 && i < count)) problems.push(`${where}.triangles is not a list of whole indices below ${count}, in threes`);\n // The hull's vertex count (issue #966, retained for the raw entry): a whole number no larger than the vertices.\n const hull = raw.hull;\n if (hull !== undefined && !(typeof hull === 'number' && Number.isInteger(hull) && hull >= 0 && hull <= count)) problems.push(`${where}.hull is ${JSON.stringify(hull)}, not a whole number of vertices from 0 to ${count}`);\n return problems.length === before ? { uvs: uvs as number[], triangles: triangles as number[], ...(hull === undefined ? {} : { hull: hull as number }) } : undefined;\n}\n\n/**\n * A path attachment's own fields past its vertices (construct 5's second cut,\n * `./constraints_path.ts`): `closed` and `constantSpeed` as the writer states\n * them — absent reads the parser's `false` and `true` (the `pathAttachments`\n * block of a dump of a record stating neither) — and `lengths`, one finite\n * entry per three points, as the writer always writes it (`buildRigPath` in\n * `src/compile.ts`). `vertexCount` must be the vertices' own count and a\n * multiple of 3: the writer refuses any other, and the curve walk reads\n * groups of three.\n */\nfunction readPathGeometry(raw: Record<string, unknown>, vertices: ModelVertices, where: string, problems: string[]): CoreGeometry | undefined {\n const before = problems.length;\n for (const key of ['closed', 'constantSpeed'] as const) if (raw[key] !== undefined && typeof raw[key] !== 'boolean') problems.push(`${where}: ${key} is ${JSON.stringify(raw[key])}, not a boolean`);\n const count = vertices.weighted ? vertices.bindings.length : vertices.xy.length / 2;\n if (raw.vertexCount !== count) problems.push(`${where}: vertexCount is ${JSON.stringify(raw.vertexCount) ?? 'absent'}, and the vertices hold ${count} point(s)`);\n else if (count % 3 !== 0 || count < (raw.closed === true ? 3 : 6)) problems.push(`${where}: vertexCount is ${count}, not a multiple of 3 of at least ${raw.closed === true ? 3 : 6} — the curve walk reads knots and handles in threes`);\n const lengths = raw.lengths;\n if (!Array.isArray(lengths) || !lengths.every(finite)) problems.push(`${where}: lengths is not a list of finite numbers`);\n else if (lengths.length !== count / 3) problems.push(`${where}: lengths has ${lengths.length} entry(ies) where the vertices make ${count / 3}`);\n if (problems.length !== before) return undefined;\n return { kind: 'path', vertices, closed: raw.closed === true, constantSpeed: raw.constantSpeed !== false, lengths: lengths as number[] };\n}\n\n/** One slot as the construct reads it: its name and bone, and what it shows — the record's name, kind and geometry — or nothing. */\nexport interface ShownGeometry {\n slot: string;\n bone: string;\n /** The name the oracle's row carries (`shownRow`). */\n name: string;\n placeholder: string;\n skin: string;\n geometry: CoreGeometry;\n /** The deform array a deform timeline set on the slot (`./deform.ts`), or none. */\n deform?: readonly number[];\n /** The frame a sequence timeline set on a region's series (`./deform.ts`), or none: the setup frame. */\n frame?: number;\n}\n\n/**\n * A row's numbers: `values` through `round`, as `values.map(round)` writes\n * them — and `values` itself, not a copy, where `round` leaves every one of\n * them the same number (`Object.is`, so a `-0` the round writes as `0` is a\n * change). Issue #1530: the raw entry's `rawNumber` is the identity on every\n * finite double but `-0`, so on every pose that drew a finite attachment the\n * map was a second array of the same numbers, per attachment per pose. The\n * array handed in is the poser's own (`regionCorners` and `worldVertices`\n * build a fresh one per call, and so does the deform path's\n * `deformedWorldVertices`), held by nothing but this call, so the row may own it; the\n * draw walk's step reads the same array and writes nothing into it\n * (`DrawStep`'s arrays are readonly). A planted poser that hands out an array\n * it keeps is the shape the core suite's retained-frame control plants.\n */\nexport function roundedRow(values: number[], round: (v: number) => number | null): Array<number | null> {\n for (let i = 0; i < values.length; i++) {\n const r = round(values[i]);\n if (Object.is(r, values[i])) continue;\n const out: Array<number | null> = values.slice(0, i);\n out.push(r);\n for (let j = i + 1; j < values.length; j++) out.push(round(values[j]));\n return out;\n }\n return values;\n}\n\n/** Resolves a linked mesh's source to its vertex array, or names why not. */\nexport type SourceOf = (skin: string, slot: string, source: string) => ModelVertices | string;\n\n/**\n * What the draw walk of `./clipping.ts` needs past the shown records: the\n * draw order (every slot, showing something or not — a clip ends at a slot\n * whatever it shows), the active bones, and a mesh's `uvs` and `triangles`\n * by where a linked mesh's source is filed.\n */\nexport interface DrawWalk {\n order: readonly string[];\n active: ReadonlySet<string>;\n meshOf: (skin: string, slot: string, source: string) => { uvs: readonly number[]; triangles: readonly number[] } | undefined;\n clip?: TriangleClipper;\n /** What the drawn rows are cut through (`clipThrough`), replaceable by the render suite's plants. */\n through?: ShapeClipper;\n}\n\n/**\n * The two blocks from the slots' shown records, in slot order, every number\n * through `round` (the oracle's, `gridRound` in `./index.ts`), or — for\n * `attachments` — the reason it is absent: a shown region whose rectangle is\n * `null` (the header's ⛔), every one named. With `draw`, also the `clipped`\n * block (issue #964, `./clipping.ts`) from the unrounded geometry, or why it\n * is absent.\n */\nexport function poseGeometry(\n shown: readonly ShownGeometry[],\n world: ReadonlyMap<string, CoreWorld>,\n sourceOf: SourceOf,\n round: (v: number) => number | null,\n plant: { region?: RegionPoser; vertices?: VertexPoser; deformedVertices?: DeformedVertexPoser } = {},\n draw?: DrawWalk,\n): { attachments: CoreAttachmentRow[] | null; attachmentsWhy: string | null; clips: CoreClipRow[]; clipped: CoreClippedRow[] | null; clippedWhy: string | null; drawnClipped: CoreClippedRow[] | null; drawnClippedWhy: string | null } {\n const region = plant.region ?? regionCorners;\n const vertices = plant.vertices ?? worldVertices;\n const deformPoser = plant.deformedVertices ?? deformedWorldVertices;\n const attachments: CoreAttachmentRow[] = [];\n const clips: CoreClipRow[] = [];\n const nulls: string[] = [];\n // Issue #1530: the draw walk cuts drawn attachments through the clips the pose shows, and with none shown it cuts nothing — `poseClipped`\n // over a walk with no clip step returns no row and no reason — so the walk's steps are built only where a clip is shown.\n const walked = draw !== undefined && shown.some((s) => s.geometry.kind === 'clipping');\n const steps = new Map<string, DrawStep>();\n for (const s of shown) {\n const bone = world.get(s.bone);\n if (bone === undefined) throw new Error(`slot \"${s.slot}\": bone \"${s.bone}\" has no world transform`);\n const g = s.geometry;\n // A deform array replaces the stored vertices, its coordinates read as they are (`./deform.ts`).\n // Unplanted, the deformed positions are read in one pass (`deformedWorldVertices`, issue #1530) rather than through a deformed copy of the array.\n const deform = s.deform;\n const drawn = (v: ModelVertices): number[] => (deform === undefined ? vertices(v, bone, world) : plant.vertices === undefined || plant.deformedVertices !== undefined ? deformPoser(v, deform, bone, world) : vertices(deformedVertices(v, deform), bone, world, EXACT_COORDS));\n if (g.kind === 'region') {\n const rect = s.frame === undefined ? g.region.atlas : (g.region.frames?.[s.frame] ?? g.region.atlas);\n if (rect === null) {\n nulls.push(`slot \"${s.slot}\" shows region \"${s.name}\" (skin \"${s.skin}\", placeholder \"${s.placeholder}\")`);\n continue;\n }\n // The record's own geometry wherever the rectangle drawn is its own (no series frame): the same fields, without a copy per pose.\n const corners = region(rect === g.region.atlas ? (g.region as CoreRegionGeometry & { atlas: ModelAtlasRect }) : { ...g.region, atlas: rect }, bone);\n attachments.push([s.slot, s.name, 'region', roundedRow(corners, round)]);\n if (walked) steps.set(s.slot, { slot: s.slot, kind: 'draw', attachment: s.name, vertices: corners, triangles: REGION_TRIANGLES, uvs: REGION_UVS });\n } else if (g.kind === 'mesh') {\n const world = drawn(g.vertices);\n attachments.push([s.slot, s.name, 'mesh', roundedRow(world, round)]);\n if (walked) steps.set(s.slot, { slot: s.slot, kind: 'draw', attachment: s.name, vertices: world, triangles: g.triangles, uvs: g.uvs });\n } else if (g.kind === 'linkedmesh') {\n const source = sourceOf(g.skin, g.slot, g.source);\n if (typeof source === 'string') throw new Error(`slot \"${s.slot}\": ${source} (readModel refuses it first)`);\n const world = drawn(source);\n attachments.push([s.slot, s.name, 'mesh', roundedRow(world, round)]);\n // A linked mesh draws its source's triangles over its source's UVs.\n const mesh = draw?.meshOf(g.skin, g.slot, g.source);\n if (draw !== undefined && mesh === undefined) throw new Error(`slot \"${s.slot}\": the linked mesh's source \"${g.source}\" carries no triangles (readModel refuses it first)`);\n if (walked && mesh !== undefined) steps.set(s.slot, { slot: s.slot, kind: 'draw', attachment: s.name, vertices: world, triangles: mesh.triangles, uvs: mesh.uvs });\n } else if (g.kind === 'clipping') {\n const polygon = drawn(g.vertices);\n clips.push([s.slot, s.name, g.end, roundedRow(polygon, round)]);\n steps.set(s.slot, { slot: s.slot, kind: 'clip', attachment: s.name, active: draw?.active.has(s.bone) ?? false, end: g.end, polygon, inverse: g.inverse, convex: g.convex });\n }\n }\n const attachmentsWhy = nulls.length === 0\n ? null\n : `${nulls.join('; ')} — the model states the build had no atlas rectangle for it (atlas: null), and its corners read the trim and original size; a trim of 0 is not assumed`;\n let clipped: CoreClippedRow[] | null = null;\n let clippedWhy: string | null = draw === undefined ? 'the draw order was not given' : attachmentsWhy;\n let drawnClipped: CoreClippedRow[] | null = null;\n let drawnClippedWhy: string | null = clippedWhy;\n if (draw !== undefined && attachmentsWhy === null && !walked) {\n clipped = [];\n clippedWhy = null;\n drawnClipped = [];\n drawnClippedWhy = null;\n } else if (draw !== undefined && attachmentsWhy === null) {\n const walk = draw.order.map((slot): DrawStep => steps.get(slot) ?? { slot, kind: 'none' });\n const posed = poseClipped(walk, round, draw.clip, draw.through);\n clipped = posed.rows;\n clippedWhy = posed.why;\n drawnClipped = posed.drawn;\n drawnClippedWhy = posed.drawnWhy;\n }\n return { attachments: attachmentsWhy === null ? attachments : null, attachmentsWhy, clips, clipped, clippedWhy, drawnClipped, drawnClippedWhy };\n}\n","/**\n * Construct 5 of the core, second cut (issue #938, step 2e-ii of issue #380):\n * the path constraint, at the setup pose and at a sample time, with its\n * timelines. `./constraints.ts` runs it in the update order the first cut\n * measured; this module reads its record, walks its curve and moves its\n * bones.\n *\n * Every rule below was measured by posing hand-written skeletons through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13, `--skin all`,\n * `--physics none`) and comparing the core's rows at tolerance 0, most with\n * amplifier bones ten thousand units out along each axis of a constrained\n * bone, so that 1e-10 in its matrix reads as a grid step. Nothing here was\n * written from the runtime's source. Where a rule is not the obvious\n * reading, the reading that missed is stated beside it with its count. The\n * populations it names: the **grid** — one bone on two and three curves,\n * open and closed, at constant speed and not, percent and fixed, 61\n * positions each (976 probes); the **population** — 2,000 random probes of\n * every mode, setting, mix and curve (the core suite's `CP03` draws 600\n * like them); the **stated population** — 1,000 probes off stated lengths\n * spelled with non-float32 decimals. The core suite's `CP` controls hold the\n * probes; `tools/core_gate.ts` holds the corpus.\n *\n * ## The curve\n *\n * The constraint walks what its slot shows (`shownAttachment` at the setup\n * pose; the slot's attachment and deform timelines are not admitted, and an\n * animation keying either on a walked path leaves the samples' bones out by\n * name). A slot showing no path makes the constraint do nothing. The path's\n * world points are `./vertices.ts`'s `worldVertices`: every vertex number\n * through `Math.fround`, an unweighted path through its slot bone, a weighted\n * one through its bound bones — the doubles missed 1,946 of the population's\n * 2,000. Its `lengths` are read as the doubles the text spells: through\n * `Math.fround` they missed 697 of the stated population's 1,000. The points\n * form the chain `src/compile.ts`'s `pathChain` states — an open path drops\n * its first and last point (the end knots' outer handles), a closed one is\n * turned by one and repeats its first knot and handle — knot, handle,\n * handle, knot, …\n *\n * ## The walk: where a length along the curve is\n *\n * Every bone is placed at a length along the path: the `position`, then\n * each space after it (below). **At constant speed** (the default) the\n * runtime measures the curve itself, every pose:\n *\n * 1. **A table of the curves' lengths**, each curve four forward-difference\n * steps (`0.1875`, `0.09375`, `0.75` and `0.16666667`, the running total\n * carried across curves) — `curveLengthTable`, which `src/compile.ts`'s\n * `pathCurveLengths` also calls (issue #1015). A ten-step table missed\n * 460 of the grid's 976. The\n * last entry is the path's length; `percent` multiplies the position by\n * it. The stated `lengths` are not read: the stated total in their place\n * missed 680 of 1,000.\n * 2. **The curve** holding the length is searched for in the table from the\n * curve the previous space ended on, forward — on an open path it is not\n * restarted, so a space that walks backwards across a curve (a negative\n * spacing) stays on the later curve with a negative fraction; restarting\n * from the first curve missed 36 of the population's 2,000. A closed\n * path takes the length modulo its total (plus the total below 0) and\n * searches from the first curve every time. The fraction of the curve is\n * `(p − previous) / (entry − previous)`.\n * 3. **A table of ten segments** of that curve, ten forward-difference steps\n * of 1/10 (`0.3`, `0.03`, `0.006`, `0.16666667`), built when the curve\n * changes. The fraction times the ten-step total is searched for from the\n * segment the previous space ended on while the curve is the same, and\n * the curve's parameter is `(segment + fraction of the segment) / 10` —\n * so the parameter is linear in length within a segment, not along the\n * whole curve: the fraction of the curve used as the parameter missed 380\n * of the grid, the parameter at the exact arc length (a 2,000-piece\n * polyline) 380, and the point on the ten-segment polyline instead of the\n * curve 392.\n * 4. **The point is the cubic at that parameter**, evaluated for any\n * parameter: a negative one extrapolates the curve backwards. Only a\n * parameter that is not a number (a curve of length 0) takes the curve's\n * first knot and the direction of its first handle. Clamping every\n * parameter below 0.00001 to the start missed 11 of the population.\n *\n * **Off constant speed** (`constantSpeed: false`) the stated `lengths` are\n * the table: its entry for the last curve is the total (`vertexCount / 3`\n * less 2 on an open path, less 1 on a closed one), the curve is found as in\n * 2, and the fraction of the curve IS the cubic's parameter — the stated\n * numbers decide where bones stand even where they disagree with the\n * geometry (issue #804): measured off the geometry instead, 711 of the\n * stated population's 1,000 missed.\n *\n * **Past the ends** of an open path a bone stands on the straight line\n * through the first knot and its handle (before the start) or through the\n * last handle and the last knot (past the end), the overshoot along it.\n *\n * ## Spaces: `spacingMode`\n *\n * A `tangent` constraint places one point per bone; `chain` and\n * `chainScale` one more, the last bone's tip. The first space is 0. Each\n * next space, for the bone before it, with `L` its `length` and `W` the\n * length of `L` times its world x column:\n *\n * - `length`: `max(0, L + spacing) · W / L` — the clamp at 0 is measured:\n * without it 16 of the population missed;\n * - `fixed`: `spacing · W / L`;\n * - a bone whose `L` is below 0.00001, in either: `spacing` as stated;\n * - `percent`: `spacing`, and every space is multiplied by the path's\n * total;\n * - `proportional`: `W` (or `spacing` for a bone below 0.00001), all of them\n * then scaled by `count · spacing / their sum` when the sum is above 0,\n * and multiplied by the total over the count of spaces — the whole total\n * missed 260 of the population.\n *\n * ## Moving the bones: `rotateMode`, `offsetRotation`, the mixes\n *\n * Nothing moves when all three mixes are 0. Each bone in turn: its world\n * origin moves toward its point by `mixX` and `mixY` (the two axes on their\n * own); with `chainScale`, a bone longer than 0.00001 has its world x column\n * scaled by `(distance to the next point / W − 1) · mixRotate + 1`. Then,\n * when `mixRotate` is above 0 (a negative one turns nothing: reading it\n * as \"not 0\" missed 58 of the population), the bone turns by\n * `mixRotate` times the change from its x axis's angle to:\n *\n * - `tangent`: the curve's direction at its point — the derivative there,\n * or below a parameter of 0.001 (negative ones included; 7 of 2,000\n * tangent probes missed with 0.001 as a floor above 0) its first handle's\n * direction;\n * - `chain`, `chainScale`: the direction to the next point — ⚠️ but when the\n * next space is exactly 0, the next point's tangent. That is exact\n * equality: a space of ±1e-7 turns to the (rounding-level) direction,\n * and an ε test missed 157 of the population.\n * - `chain` with no offset: the next bone starts at this bone's tip, the\n * bone's `length` along its turned axis (the runtime's \"tip\"); not\n * carrying the tip missed 191 of the population.\n * - Otherwise `offsetRotation` degrees (the model's `rotation`) are added,\n * in the runtime's π, NEGATED when the slot bone's world matrix does not\n * have a positive determinant — never flipping missed 241 of the\n * population. Which slot bone's world that is, is the next section.\n *\n * The change is brought once into [−π, π] with the runtime's π\n * (3.1415927), which `Math.PI` there missed 881 of 2,000 by. The bones are\n * then moved in world space and read back into local values at once, as the\n * first cut's world-space transform is (`./constraints.ts`, `localFromWorld`).\n *\n * ## Which slot bone the offset reads\n *\n * The runtime brings bones up to date in an order it builds before it\n * poses: each constraint in turn brings up to date the bones it reads and\n * the bones it moves (a bone after its parents, and once only until a\n * constraint moves a bone above it), and every bone left over follows at\n * the end. A path constraint reads its slot bone only for the offset's\n * sign, and it asks the order for its slot bone only when the slot holds an\n * UNWEIGHTED path in some skin — a weighted one asks for its bound bones\n * instead. So a weighted path's slot bone can be read before the pose has\n * set it (`slotBonePlan` emulates the order):\n *\n * - set by an earlier constraint's ordering — its world as it was brought\n * up to date then, before that constraint ran; or as that constraint left\n * it when it moved the bone itself;\n * - set by nothing yet — the previous pose's world: on a new skeleton all\n * zeros, which is not positive, so the oracle's setup pose turns the\n * offset the other way; at a sample, the sample before's.\n *\n * Measured on eight hand-written cases, each exact at the setup pose and at\n * nine samples, of which reading the slot bone fresh missed three, and on\n * random update orders of path, ik and transform constraints, 783 of 783\n * exact, fresh 774 (`CP06`, `CP07`).\n *\n * A physics constraint orders its one bone as a one-bone constraint does\n * (its parents first, what hangs below it reset, the bone done), though\n * under `Physics.none` it moves nothing. A slider sets no bone in the order —\n * neither its dial nor the bones its animation keys — and resets each bone\n * its animation keys and what hangs below it, so a later constraint that\n * orders one of them sets it again. Measured on eighteen hand-written orders\n * around a weighted path with an offset (`CP13`), each exact at the setup\n * pose and three samples, where the readings rejected each miss one or two:\n * physics ordering nothing, a slider ordering its dial, a slider ordering\n * the bones it keys, a slider resetting nothing, a slider resetting only\n * below the bones it keys; and on 400 random orders of one to five physics,\n * slider, ik and transform constraints around such a path, 400 exact\n * (physics ordering nothing 388, a slider ordering its dial and keyed bones\n * 379). The previous sample is the oracle's\n * order of animations, which the model does not hold: the core poses a\n * sample with the setup pose's reading, which is the runtime's exactly\n * when the slot bone's reflection is the setup's at every sample, and\n * leaves the samples' bones out by name when it is not.\n *\n * ## Which constraints run\n *\n * One with `skin: true` runs exactly when an applied skin's `path` list\n * names it (`./constraints.ts`'s header, issue #932); one whose slot bone is\n * inactive does not. One whose constrained bone is inactive still runs\n * (measured: its other bones move; the inactive one's matrix is collapsed\n * and the oracle's ill-conditioned rule excludes it). A weight bound to an\n * inactive bone reads its world of zeros.\n *\n * ## The record and its timelines\n *\n * The dump's `paths` block is the runtime's reading of each field, and the\n * core writes the same block (`pathRows`): `positionMode` absent reads\n * `percent`, `spacingMode` `length`, `rotateMode` `tangent`, `rotation`,\n * `position` and `spacing` 0, `mixRotate` and `mixX` 1 and `mixY` the\n * resolved `mixX`; a mode's first letter is read in either case. A path\n * attachment's `closed` absent reads false and `constantSpeed` true (the\n * `pathAttachments` block, `pathAttachmentRows`). The three timelines —\n * `position` and `spacing` one channel each, `mix` three — are evaluated by\n * construct 4's `keyIndexAt` and `channelAt`, float32 key times and values,\n * before the first key the constraint's own; a key stating no value reads\n * 0, one stating no mix 1 and no `mixY` its own `mixX` (`CP08`, 24 keyed\n * skeletons at 200 dense samples). The value a key gives reaches the pose\n * through the setup blend at alpha 1, `setup + (value − setup)·1`, as the ik\n * and transform timelines' do (`./constraints.ts`, *The timelines*; issue\n * #984, `CY01`: the value as keyed read 0 of 60 probes keying all three\n * timelines bit-exact under `--raw`, the blend 60).\n *\n * ## Purity\n *\n * As the rest of the core: nothing from the Spine runtime package, nothing\n * from `src/transform.ts`, no clock, no randomness, no I/O.\n */\nimport type { ModelBone, ModelVertices } from '../model.ts';\nimport { RUNTIME_PI, type CoreWorld } from './world.ts';\nimport { EXACT_COORDS, worldVertices } from './vertices.ts';\nimport type { CoreCurve, CoreKey } from './animation.ts';\nimport type { CoreConstraintRecord } from './constraints.ts';\n\nconst RAD = RUNTIME_PI / 180;\n\n/**\n * The constant-speed walk's table of the curves' lengths — the header's *The\n * walk*, step 1: each curve four forward-difference steps (`0.1875`,\n * `0.09375`, `0.75`, `0.16666667`), the running total carried across curves,\n * one cumulative entry per curve. `chain` is flat, `x, y` per point, knot\n * handle handle knot …; `curveCount` curves are read off it.\n *\n * Exported because it has a second caller: an omitted `lengths` on a path\n * attachment is measured by `src/compile.ts` through this function (issue\n * #1015), so the number rigc writes into a file and the number the core walks\n * are one computation. Measured as the header states it on the grid (a\n * ten-step table missed 460 of 976) and held there by the core suite's `CP`\n * controls.\n */\nexport function curveLengthTable(chain: readonly number[], curveCount: number): number[] {\n const curveEnds: number[] = [];\n let total = 0;\n let x1 = chain[0];\n let y1 = chain[1];\n for (let i = 0, w = 2; i < curveCount; i++, w += 6) {\n const cx1 = chain[w];\n const cy1 = chain[w + 1];\n const cx2 = chain[w + 2];\n const cy2 = chain[w + 3];\n const x2 = chain[w + 4];\n const y2 = chain[w + 5];\n const h2x = (x1 - cx1 * 2 + cx2) * 0.1875;\n const h2y = (y1 - cy1 * 2 + cy2) * 0.1875;\n const d3x = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;\n const d3y = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;\n let d2x = h2x * 2 + d3x;\n let d2y = h2y * 2 + d3y;\n let d1x = (cx1 - x1) * 0.75 + h2x + d3x * 0.16666667;\n let d1y = (cy1 - y1) * 0.75 + h2y + d3y * 0.16666667;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n d1x += d2x;\n d1y += d2y;\n d2x += d3x;\n d2y += d3y;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n d1x += d2x;\n d1y += d2y;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n d1x += d2x + d3x;\n d1y += d2y + d3y;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n curveEnds.push(total);\n x1 = x2;\n y1 = y2;\n }\n return curveEnds;\n}\n\nconst EPSILON = 0.00001;\n\n/** The three modes a path constraint names, each as the model spells it once its first letter is lower-cased. */\nexport const PATH_POSITION_MODES = ['fixed', 'percent'] as const;\nexport const PATH_SPACING_MODES = ['length', 'fixed', 'percent', 'proportional'] as const;\nexport const PATH_ROTATE_MODES = ['tangent', 'chain', 'chainScale'] as const;\nexport type PathPositionMode = (typeof PATH_POSITION_MODES)[number];\nexport type PathSpacingMode = (typeof PATH_SPACING_MODES)[number];\nexport type PathRotateMode = (typeof PATH_ROTATE_MODES)[number];\n\n/** The fields a path record may carry after `kind`, `name`, `declaredIn` (`buildRigConstraint` in `src/compile.ts`). */\nexport const PATH_FIELDS = ['bones', 'slot', 'positionMode', 'spacingMode', 'rotateMode', 'rotation', 'position', 'spacing', 'mixRotate', 'mixX', 'mixY', 'skin'] as const;\n\n/** The curve a path constraint walks: the path attachment its slot shows, as the record states it. */\nexport interface CorePathGeometry {\n vertices: ModelVertices;\n closed: boolean;\n constantSpeed: boolean;\n lengths: number[];\n /** Set when a deform timeline replaced the vertices at a sample (`./deform.ts`): their coordinates are read as they are, not through `Math.fround`. */\n exact?: boolean;\n}\n\n/** The values a path constraint's timelines key. */\nexport interface PathPose {\n position: number;\n spacing: number;\n mixRotate: number;\n mixX: number;\n mixY: number;\n}\n\nexport interface CorePathRecord extends PathPose {\n kind: 'path';\n name: string;\n bones: string[];\n slot: string;\n /** The slot's bone — the frame an unweighted path's vertices are in. */\n slotBone: string;\n positionMode: PathPositionMode;\n spacingMode: PathSpacingMode;\n rotateMode: PathRotateMode;\n offsetRotation: number;\n skin: boolean;\n /** An applied skin's `path` list names it — what applies a skin-required one (`./constraints.ts`'s header); set per skin view by `underSkin` in `./index.ts`. */\n listedBySkin: boolean;\n /** What the slot shows at setup: its path, `null` when it shows no path (the constraint then does nothing). Set once the skins are read. */\n path: CorePathGeometry | null;\n /** Why what the slot shows cannot be told — skins that disagree over its placeholder — or null. */\n unresolved: string | null;\n /**\n * The bones the runtime brings up to date for this constraint's slot before\n * it runs, off every path attachment a skin the view can show files under\n * the slot (every skin under `all`, the named and default skins under a\n * named one, `lookupSkins` in `./skins.ts`): a\n * weighted one's bound bones, an unweighted one's slot bone (the header's\n * *Which slot bone*). Set once the skins are read.\n */\n slotDeps: string[];\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\nfunction fold<T extends string>(raw: Record<string, unknown>, key: string, modes: readonly T[], dflt: T, where: string, problems: string[]): T {\n const v = raw[key];\n if (v === undefined) return dflt;\n const folded = typeof v === 'string' && v.length > 0 ? v[0].toLowerCase() + v.slice(1) : '';\n const mode = modes.find((m) => m === folded);\n if (mode === undefined) {\n problems.push(`${where}: ${key} is ${JSON.stringify(v)}, none of ${modes.join(', ')} (first letter in either case)`);\n return dflt;\n }\n return mode;\n}\n\nfunction num(raw: Record<string, unknown>, key: string, dflt: number, where: string, problems: string[]): number {\n const v = raw[key];\n if (v === undefined) return dflt;\n if (typeof v !== 'number' || !Number.isFinite(v)) {\n problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a finite number`);\n return dflt;\n }\n return v;\n}\n\n/**\n * A path constraint's record, read field by field, or `undefined` with the\n * problems named. `bones` and `slots` are the document's names and each\n * slot's bone.\n */\nexport function readPathRecord(raw: Record<string, unknown>, name: string, where: string, bones: ReadonlySet<string>, slots: ReadonlyMap<string, string>, problems: string[]): CorePathRecord | undefined {\n const before = problems.length;\n for (const key of Object.keys(raw)) {\n if (key === 'kind' || key === 'name' || key === 'declaredIn') continue;\n if (!(PATH_FIELDS as readonly string[]).includes(key)) problems.push(`${where}: field \"${key}\" is not one this reader knows; it reads [${PATH_FIELDS.join(', ')}]`);\n }\n const list: string[] = [];\n if (!Array.isArray(raw.bones) || raw.bones.length === 0) problems.push(`${where}: bones is ${JSON.stringify(raw.bones)}, not a non-empty list of bone names`);\n else raw.bones.forEach((b, i) => (typeof b === 'string' && bones.has(b) ? list.push(b) : problems.push(`${where}: bones[${i}] ${JSON.stringify(b)} is not a bone of this document`)));\n const slot = typeof raw.slot === 'string' ? raw.slot : '';\n const slotBone = slots.get(slot);\n if (slotBone === undefined) problems.push(`${where}: slot is ${JSON.stringify(raw.slot)}, not a slot of this document`);\n if (raw.skin !== undefined && typeof raw.skin !== 'boolean') problems.push(`${where}: skin is ${JSON.stringify(raw.skin)}, not a boolean`);\n const mixX = num(raw, 'mixX', 1, where, problems);\n const record: CorePathRecord = {\n kind: 'path', name, bones: list, slot, slotBone: slotBone ?? '',\n positionMode: fold(raw, 'positionMode', PATH_POSITION_MODES, 'percent', where, problems),\n spacingMode: fold(raw, 'spacingMode', PATH_SPACING_MODES, 'length', where, problems),\n rotateMode: fold(raw, 'rotateMode', PATH_ROTATE_MODES, 'tangent', where, problems),\n offsetRotation: num(raw, 'rotation', 0, where, problems),\n position: num(raw, 'position', 0, where, problems),\n spacing: num(raw, 'spacing', 0, where, problems),\n mixRotate: num(raw, 'mixRotate', 1, where, problems),\n mixX,\n mixY: num(raw, 'mixY', mixX, where, problems),\n skin: raw.skin === true,\n listedBySkin: false,\n path: null,\n unresolved: null,\n slotDeps: [],\n };\n return problems.length === before ? record : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// timelines\n// ---------------------------------------------------------------------------\n\n/** A path constraint's three timelines, by the name the model gives them, and the channels each keys. */\nexport const PATH_TIMELINES = { position: ['value'], spacing: ['value'], mix: ['mixRotate', 'mixX', 'mixY'] } as const;\nexport type PathTimelineName = keyof typeof PATH_TIMELINES;\n\n/** One animation's timelines of one path constraint. */\nexport interface CorePathTimelines {\n name: string;\n position?: CoreKey[];\n spacing?: CoreKey[];\n mix?: CoreKey[];\n}\n\nfunction keyCurve(raw: Record<string, unknown>, channels: number, last: boolean, at: string, problems: string[]): CoreCurve {\n const curve = raw.curve;\n if (curve === undefined) return 'linear';\n if (last) {\n problems.push(`${at}: the last key carries a curve, which eases to no key — the writer refuses it`);\n return 'linear';\n }\n if (curve === 'stepped') return 'stepped';\n if (!Array.isArray(curve) || curve.length !== channels * 4 || !curve.every((n) => typeof n === 'number' && Number.isFinite(n))) {\n problems.push(`${at}: curve is ${JSON.stringify(curve)}, not \"stepped\" nor ${channels * 4} finite numbers (four per channel)`);\n return 'linear';\n }\n return curve as number[];\n}\n\n/**\n * The path timelines of one animation record's `constraints.path`, read: each\n * names a declared path constraint, each timeline is `position`, `spacing` or\n * `mix`, keys strictly increase in time, each key carries only its channels,\n * `time` and `curve`. An absent channel reads the parser's value, measured:\n * a position or spacing 0, a mix 1, a `mixY` the key's own `mixX` (the header).\n */\nexport function readPathTimelines(value: unknown, label: string, declared: ReadonlySet<string>, problems: string[]): CorePathTimelines[] {\n const out: CorePathTimelines[] = [];\n if (!Array.isArray(value)) return out;\n value.forEach((entry, i) => {\n const at = `${label}.constraints.path[${i}]`;\n if (!isRecord(entry) || typeof entry.name !== 'string') {\n problems.push(`${at} names no constraint`);\n return;\n }\n if (!declared.has(entry.name)) problems.push(`${at}: \"${entry.name}\" is not a path constraint of this document`);\n const tls: CorePathTimelines = { name: entry.name };\n if (!Array.isArray(entry.timelines)) {\n problems.push(`${at}: timelines is not a list`);\n return;\n }\n entry.timelines.forEach((tl: unknown, j: number) => {\n const tat = `${at}.timelines[${j}]`;\n if (!isRecord(tl) || typeof tl.name !== 'string' || !(tl.name in PATH_TIMELINES)) {\n problems.push(`${tat}: ${isRecord(tl) ? JSON.stringify(tl.name) : 'it'} is not a path timeline; they are ${Object.keys(PATH_TIMELINES).join(', ')}`);\n return;\n }\n const kind = tl.name as PathTimelineName;\n if (tls[kind] !== undefined) problems.push(`${tat}: \"${kind}\" is keyed twice on path constraint \"${entry.name}\"`);\n const channels: readonly string[] = PATH_TIMELINES[kind];\n const rawKeys = tl.keys;\n if (!Array.isArray(rawKeys) || rawKeys.length === 0) {\n problems.push(`${tat}: keys is not a non-empty list`);\n return;\n }\n let last = -Infinity;\n const keys: CoreKey[] = [];\n rawKeys.forEach((k: unknown, n: number) => {\n const kat = `${tat}.keys[${n}]`;\n if (!isRecord(k)) {\n problems.push(`${kat} is not an object`);\n return;\n }\n for (const f of Object.keys(k)) if (f !== 'time' && f !== 'curve' && !channels.includes(f)) problems.push(`${kat}: field \"${f}\" is not one this reader knows; it reads [time, ${channels.join(', ')}, curve]`);\n const time = k.time;\n if (typeof time !== 'number' || !Number.isFinite(time) || time < 0) {\n problems.push(`${kat}: time is ${JSON.stringify(time)}, not a finite time at or after 0`);\n return;\n }\n if (time <= last) problems.push(`${kat}: time ${time} is not after the key before it — the writer refuses key times that do not strictly increase`);\n last = Math.max(last, time);\n const stated = channels.map((c) => {\n if (c === 'mixY' && k.mixY === undefined) return num(k, 'mixX', 1, kat, problems);\n return num(k, c, kind === 'mix' ? 1 : 0, kat, problems);\n });\n keys.push({ time: Math.fround(time), values: stated.map(Math.fround), stated: { time, values: stated }, curve: keyCurve(k, channels.length, n === rawKeys.length - 1, kat, problems) });\n });\n tls[kind] = keys;\n });\n out.push(tls);\n });\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// solving\n// ---------------------------------------------------------------------------\n\n/** What the path solver reads and writes: the bones' local values, their world transforms, which are active. */\nexport interface PathSolverState {\n bones: ModelBone[];\n index: Map<string, number>;\n world: Map<string, CoreWorld>;\n active: ReadonlySet<string>;\n}\n\n/** The slot's path vertices in world units, as the constraint reads them at the moment it runs. */\nfunction pathWorld(state: PathSolverState, c: CorePathRecord, g: CorePathGeometry): number[] {\n return worldVertices(g.vertices, state.world.get(c.slotBone) as CoreWorld, state.world, g.exact === true ? EXACT_COORDS : Math.fround);\n}\n\nfunction onLineBefore(p: number, x1: number, y1: number, x2: number, y2: number, out: number[], o: number): void {\n const r = Math.atan2(y2 - y1, x2 - x1);\n out[o] = x1 + p * Math.cos(r);\n out[o + 1] = y1 + p * Math.sin(r);\n out[o + 2] = r;\n}\n\nfunction onLinePast(p: number, x0: number, y0: number, x1: number, y1: number, out: number[], o: number): void {\n const r = Math.atan2(y1 - y0, x1 - x0);\n out[o] = x1 + p * Math.cos(r);\n out[o + 1] = y1 + p * Math.sin(r);\n out[o + 2] = r;\n}\n\nfunction onCurve(p: number, x1: number, y1: number, cx1: number, cy1: number, cx2: number, cy2: number, x2: number, y2: number, out: number[], o: number, wantsTangent: boolean): void {\n if (Number.isNaN(p)) {\n out[o] = x1;\n out[o + 1] = y1;\n out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);\n return;\n }\n const t2 = p * p;\n const t3 = t2 * p;\n const u = 1 - p;\n const u2 = u * u;\n const u3 = u2 * u;\n const ut = u * p;\n const ut3x = ut * 3;\n const w1 = u * ut3x;\n const w2 = ut3x * p;\n const x = x1 * u3 + cx1 * w1 + cx2 * w2 + x2 * t3;\n const y = y1 * u3 + cy1 * w1 + cy2 * w2 + y2 * t3;\n out[o] = x;\n out[o + 1] = y;\n if (wantsTangent) {\n if (p < 0.001) out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);\n else out[o + 2] = Math.atan2(y - (y1 * u2 + cy1 * ut * 2 + cy2 * t2), x - (x1 * u2 + cx1 * ut * 2 + cx2 * t2));\n }\n}\n\n/** The world position and angle of each space along the path. */\nfunction positionsOf(state: PathSolverState, c: CorePathRecord, g: CorePathGeometry, spaces: number[], wantsTangent: boolean): number[] {\n const spaceCount = spaces.length;\n const pts = pathWorld(state, c, g);\n const n = pts.length / 2;\n const P = (k: number): [number, number] => [pts[2 * k], pts[2 * k + 1]];\n const out: number[] = new Array(spaceCount * 3 + 2).fill(0);\n const closed = g.closed;\n let position = c.position;\n if (!g.constantSpeed) {\n const lengths = g.lengths;\n const curveCount = n / 3 - (closed ? 1 : 2);\n const total = lengths[curveCount];\n if (c.positionMode === 'percent') position *= total;\n const spaceScale = c.spacingMode === 'percent' ? total : c.spacingMode === 'proportional' ? total / spaceCount : 1;\n let curve = 0;\n for (let i = 0, o = 0; i < spaceCount; i++, o += 3) {\n const space = spaces[i] * spaceScale;\n position += space;\n let p = position;\n if (closed) {\n p %= total;\n if (p < 0) p += total;\n curve = 0;\n } else if (p < 0) {\n const [x1, y1] = P(1);\n const [x2, y2] = P(2);\n onLineBefore(p, x1, y1, x2, y2, out, o);\n continue;\n } else if (p > total) {\n const [x0, y0] = P(n - 3);\n const [x1, y1] = P(n - 2);\n onLinePast(p - total, x0, y0, x1, y1, out, o);\n continue;\n }\n for (;; curve++) {\n const length = lengths[curve];\n if (p > length) continue;\n if (curve === 0) p /= length;\n else {\n const prev = lengths[curve - 1];\n p = (p - prev) / (length - prev);\n }\n break;\n }\n const k = 3 * curve + 1;\n const q = (m: number): [number, number] => P((k + m) % n);\n const [x1, y1] = q(0);\n const [cx1, cy1] = q(1);\n const [cx2, cy2] = q(2);\n const [x2, y2] = q(3);\n onCurve(p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, wantsTangent || (i > 0 && space === 0));\n }\n return out;\n }\n // constant speed: the chain, knot handle handle knot …\n const chain: number[] = [];\n if (closed) {\n for (let k = 1; k < n; k++) chain.push(...P(k));\n chain.push(...P(0), ...P(1));\n } else for (let k = 1; k < n - 1; k++) chain.push(...P(k));\n const curveCount = closed ? n / 3 : n / 3 - 1;\n const curveEnds = curveLengthTable(chain, curveCount);\n const total = curveEnds.length > 0 ? curveEnds[curveEnds.length - 1] : 0;\n if (c.positionMode === 'percent') position *= total;\n const spaceScale = c.spacingMode === 'percent' ? total : c.spacingMode === 'proportional' ? total / spaceCount : 1;\n const segmentEnds: number[] = new Array(10).fill(0);\n let curveTotal = 0;\n let lastCurve = -1;\n let x1 = 0, y1 = 0, cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;\n for (let i = 0, o = 0, curve = 0, segment = 0; i < spaceCount; i++, o += 3) {\n const space = spaces[i] * spaceScale;\n position += space;\n let p = position;\n if (closed) {\n p %= total;\n if (p < 0) p += total;\n curve = 0;\n segment = 0;\n } else if (p < 0) {\n onLineBefore(p, chain[0], chain[1], chain[2], chain[3], out, o);\n continue;\n } else if (p > total) {\n const e = chain.length;\n onLinePast(p - total, chain[e - 4], chain[e - 3], chain[e - 2], chain[e - 1], out, o);\n continue;\n }\n for (;; curve++) {\n const length = curveEnds[curve];\n if (p > length) continue;\n if (curve === 0) p /= length;\n else {\n const prev = curveEnds[curve - 1];\n p = (p - prev) / (length - prev);\n }\n break;\n }\n if (curve !== lastCurve) {\n lastCurve = curve;\n const ii = curve * 6;\n x1 = chain[ii];\n y1 = chain[ii + 1];\n cx1 = chain[ii + 2];\n cy1 = chain[ii + 3];\n cx2 = chain[ii + 4];\n cy2 = chain[ii + 5];\n x2 = chain[ii + 6];\n y2 = chain[ii + 7];\n const h2x = (x1 - cx1 * 2 + cx2) * 0.03;\n const h2y = (y1 - cy1 * 2 + cy2) * 0.03;\n const d3x = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;\n const d3y = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;\n let d2x = h2x * 2 + d3x;\n let d2y = h2y * 2 + d3y;\n let d1x = (cx1 - x1) * 0.3 + h2x + d3x * 0.16666667;\n let d1y = (cy1 - y1) * 0.3 + h2y + d3y * 0.16666667;\n curveTotal = Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[0] = curveTotal;\n for (let s = 1; s < 8; s++) {\n d1x += d2x;\n d1y += d2y;\n d2x += d3x;\n d2y += d3y;\n curveTotal += Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[s] = curveTotal;\n }\n d1x += d2x;\n d1y += d2y;\n curveTotal += Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[8] = curveTotal;\n d1x += d2x + d3x;\n d1y += d2y + d3y;\n curveTotal += Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[9] = curveTotal;\n segment = 0;\n }\n p *= curveTotal;\n for (;; segment++) {\n const length = segmentEnds[segment];\n if (p > length) continue;\n if (segment === 0) p /= length;\n else {\n const prev = segmentEnds[segment - 1];\n p = segment + (p - prev) / (length - prev);\n }\n break;\n }\n onCurve(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, wantsTangent || (i > 0 && space === 0));\n }\n return out;\n}\n\n/** A path constraint (the header): returns the bones it moved, every one in world space. */\nexport function solvePath(state: PathSolverState, c: CorePathRecord, slotWorld: CoreWorld): { changed: string[]; inWorld: string[] } {\n const g = c.path;\n const none = { changed: [], inWorld: [] };\n if (g === null) return none;\n const { mixRotate, mixX, mixY } = c;\n if (mixRotate === 0 && mixX === 0 && mixY === 0) return none;\n const wantsTangent = c.rotateMode === 'tangent';\n const scale = c.rotateMode === 'chainScale';\n const bones = c.bones.map((n) => state.bones[state.index.get(n) as number]);\n const boneCount = bones.length;\n const spaceCount = wantsTangent ? boneCount : boneCount + 1;\n const spaces: number[] = new Array(spaceCount).fill(0);\n const lengths: number[] = scale ? new Array(boneCount).fill(0) : [];\n const spacing = c.spacing;\n const worldOf = (b: ModelBone): CoreWorld => state.world.get(b.name) as CoreWorld;\n if (c.spacingMode === 'percent') {\n if (scale) {\n for (let i = 0; i < spaceCount - 1; i++) {\n const b = bones[i];\n const boneLength = b.length ?? 0;\n const w = worldOf(b);\n const x = boneLength * w.a;\n const y = boneLength * w.c;\n lengths[i] = Math.sqrt(x * x + y * y);\n }\n }\n for (let i = 1; i < spaceCount; i++) spaces[i] = spacing;\n } else if (c.spacingMode === 'proportional') {\n let sum = 0;\n for (let i = 0, n = spaceCount - 1; i < n; ) {\n const b = bones[i];\n const boneLength = b.length ?? 0;\n if (boneLength < EPSILON) {\n if (scale) lengths[i] = 0;\n spaces[++i] = spacing;\n } else {\n const w = worldOf(b);\n const x = boneLength * w.a;\n const y = boneLength * w.c;\n const length = Math.sqrt(x * x + y * y);\n if (scale) lengths[i] = length;\n spaces[++i] = length;\n sum += length;\n }\n }\n if (sum > 0) {\n sum = (spaceCount / sum) * spacing;\n for (let i = 1; i < spaceCount; i++) spaces[i] *= sum;\n }\n } else {\n const addsLength = c.spacingMode === 'length';\n for (let i = 0, n = spaceCount - 1; i < n; ) {\n const b = bones[i];\n const boneLength = b.length ?? 0;\n if (boneLength < EPSILON) {\n if (scale) lengths[i] = 0;\n spaces[++i] = spacing;\n } else {\n const w = worldOf(b);\n const x = boneLength * w.a;\n const y = boneLength * w.c;\n const length = Math.sqrt(x * x + y * y);\n if (scale) lengths[i] = length;\n spaces[++i] = ((addsLength ? Math.max(0, boneLength + spacing) : spacing) * length) / boneLength;\n }\n }\n }\n const positions = positionsOf(state, c, g, spaces, wantsTangent);\n let atX = positions[0];\n let atY = positions[1];\n let offsetRotation = c.offsetRotation;\n let fromTip: boolean;\n if (offsetRotation === 0) fromTip = c.rotateMode === 'chain';\n else {\n fromTip = false;\n const p = slotWorld;\n offsetRotation *= p.a * p.d - p.b * p.c > 0 ? RAD : -RAD;\n }\n const changed: string[] = [];\n for (let i = 0, p = 3; i < boneCount; i++, p += 3) {\n const b = bones[i];\n const w = { ...worldOf(b) };\n w.worldX += (atX - w.worldX) * mixX;\n w.worldY += (atY - w.worldY) * mixY;\n const x = positions[p];\n const y = positions[p + 1];\n const dx = x - atX;\n const dy = y - atY;\n if (scale) {\n const length = lengths[i];\n if (length >= EPSILON) {\n const s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * mixRotate + 1;\n w.a *= s;\n w.c *= s;\n }\n }\n atX = x;\n atY = y;\n if (mixRotate > 0) {\n const { a, b: bb, c: cc, d } = w;\n let r: number;\n if (wantsTangent) r = positions[p - 1];\n else if (spaces[i + 1] === 0) r = positions[p + 2];\n else r = Math.atan2(dy, dx);\n r -= Math.atan2(cc, a);\n if (fromTip) {\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n const length = b.length ?? 0;\n atX += (length * (cos * a - sin * cc) - dx) * mixRotate;\n atY += (length * (sin * a + cos * cc) - dy) * mixRotate;\n } else r += offsetRotation;\n if (r > RUNTIME_PI) r -= RUNTIME_PI * 2;\n else if (r < -RUNTIME_PI) r += RUNTIME_PI * 2;\n r *= mixRotate;\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n w.a = cos * a - sin * cc;\n w.b = cos * bb - sin * d;\n w.c = sin * a + cos * cc;\n w.d = sin * bb + cos * d;\n }\n state.world.set(b.name, w);\n changed.push(b.name);\n }\n return { changed, inWorld: [...changed] };\n}\n\n// ---------------------------------------------------------------------------\n// the dump's two path blocks\n// ---------------------------------------------------------------------------\n\n/** A mode as the runtime's enum names it: the first letter upper-cased (`chainScale` → `ChainScale`). */\nconst enumName = (mode: string): string => mode[0].toUpperCase() + mode.slice(1);\n\n/** One `paths` row, the oracle's shape (`OraclePathRow` in `tools/pose_oracle.ts`). */\nexport interface CorePathRow {\n name: string;\n slot: string;\n bones: string[];\n positionMode: string;\n spacingMode: string;\n rotateMode: string;\n offsetRotation: number | null;\n position: number | null;\n spacing: number | null;\n mixRotate: number | null;\n mixX: number | null;\n mixY: number | null;\n}\n\n/** One `pathAttachments` row, the oracle's shape. */\nexport interface CorePathAttachmentRow {\n skin: string;\n slot: string;\n placeholder: string;\n closed: boolean;\n constantSpeed: boolean;\n lengths: Array<number | null>;\n}\n\n/** The `paths` block: every path record in the document's order, its modes as the runtime names them, its numbers through `round`. */\nexport function pathRows(records: readonly CorePathRecord[], round: (v: number) => number | null): CorePathRow[] {\n return records.map((r) => ({\n name: r.name, slot: r.slot, bones: [...r.bones],\n positionMode: enumName(r.positionMode), spacingMode: enumName(r.spacingMode), rotateMode: enumName(r.rotateMode),\n offsetRotation: round(r.offsetRotation), position: round(r.position), spacing: round(r.spacing), mixRotate: round(r.mixRotate), mixX: round(r.mixX), mixY: round(r.mixY),\n }));\n}\n\n/** The `pathAttachments` block: every path attachment of every skin, its two flags as read and its `lengths` through `round`. */\nexport function pathAttachmentRows(skins: ReadonlyArray<{ name: string; attachments: Record<string, Record<string, { geometry?: { kind: string } & Partial<CorePathGeometry> }>> }>, round: (v: number) => number | null): CorePathAttachmentRow[] {\n const out: CorePathAttachmentRow[] = [];\n for (const skin of skins) {\n for (const [slot, table] of Object.entries(skin.attachments)) {\n for (const [placeholder, record] of Object.entries(table)) {\n const g = record.geometry;\n if (g?.kind !== 'path') continue;\n out.push({ skin: skin.name, slot, placeholder, closed: g.closed === true, constantSpeed: g.constantSpeed !== false, lengths: (g.lengths ?? []).map(round) });\n }\n }\n }\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// which slot bone the offset's sign reads\n// ---------------------------------------------------------------------------\n\n/**\n * When the runtime last set a path constraint's slot bone's world before the\n * constraint runs (the header's *Which slot bone*): during the ordering of\n * constraint `at` — brought up to date from its parent just `before` that\n * constraint runs, or moved by it and so as it left the bone, `after` it.\n */\nexport interface SlotBoneEvent {\n at: number;\n when: 'before' | 'after';\n}\n\n/**\n * For each path constraint, by its index in `records`, the last event that\n * set its slot bone's world before it runs — `null` when nothing has in this\n * pass, and the bone holds the previous pass's world. The runtime orders its\n * update before it poses: each constraint in turn brings the bones it reads\n * and moves up to date (a bone, its parents first, once until something\n * below which it hangs moves), and every bone left over follows at the end.\n * `skipped` names the constraints the runtime does not apply, which it does\n * not order either.\n */\nexport function slotBonePlan(bones: readonly ModelBone[], active: ReadonlySet<string>, records: readonly CoreConstraintRecord[], skipped: ReadonlySet<number>): Map<number, SlotBoneEvent | null> {\n const parent = new Map(bones.map((b) => [b.name, b.parent]));\n const children = new Map<string, string[]>();\n for (const b of bones) if (b.parent !== undefined) children.set(b.parent, [...(children.get(b.parent) ?? []), b.name]);\n const ordered = new Map(bones.map((b) => [b.name, !active.has(b.name)]));\n const last = new Map<string, SlotBoneEvent>();\n const orderBone = (name: string, m: number): void => {\n if (ordered.get(name)) return;\n const p = parent.get(name);\n if (p !== undefined) orderBone(p, m);\n ordered.set(name, true);\n last.set(name, { at: m, when: 'before' });\n };\n const unorder = (names: readonly string[]): void => {\n for (const n of names) {\n if (!active.has(n)) continue;\n if (ordered.get(n)) unorder(children.get(n) ?? []);\n ordered.set(n, false);\n }\n };\n const plan = new Map<number, SlotBoneEvent | null>();\n records.forEach((c, m) => {\n if (skipped.has(m)) return;\n let moved: readonly string[];\n // A slider sets no bone in the order; it resets each bone its animation keys, and what hangs below it (the header's *Which slot bone*).\n if (c.kind === 'slider') {\n unorder(c.timelines.bones.map((t) => t.name));\n return;\n }\n if (c.kind === 'ik') {\n moved = c.bones;\n orderBone(c.target, m);\n orderBone(c.bones[0], m);\n if (c.bones.length > 1) orderBone(c.bones[c.bones.length - 1], m);\n unorder(children.get(c.bones[0]) ?? []);\n if (c.bones.length > 1) ordered.set(c.bones[c.bones.length - 1], true);\n } else {\n // A physics constraint orders its one bone as a one-bone constraint does (the header's *Which slot bone*).\n moved = c.kind === 'physics' ? [c.bone] : c.bones;\n if (c.kind === 'transform') orderBone(c.source, m);\n else if (c.kind === 'path') for (const d of c.slotDeps) orderBone(d, m);\n for (const b of moved) orderBone(b, m);\n if (c.kind === 'path') plan.set(m, last.get(c.slotBone) ?? null);\n for (const b of moved) unorder(children.get(b) ?? []);\n for (const b of moved) ordered.set(b, true);\n }\n for (const b of moved) last.set(b, { at: m, when: 'after' });\n });\n return plan;\n}\n","/**\n * Construct 5 of the core, third and fourth cuts (issue #938, step 2e-iii,\n * and issue #956, step 2e-iv, of issue #380): the physics constraint — under\n * `Physics.none`, the oracle's default phase, where it applies nothing, and\n * stepped, `Physics.reset` then `Physics.update` at a fixed `dt`, where it\n * integrates.\n *\n * ## What an unstepped physics constraint contributes: nothing\n *\n * Measured by posing hand-written skeletons through `tools/pose_oracle.ts\n * dump` (spine-core 4.3.13, `--skin all`, `--physics none`) twice — once as\n * written, once with every physics constraint and every physics timeline\n * taken out — and comparing the two dumps at tolerance 0:\n *\n * - 400 one-constraint skeletons: the constrained bone in all five inherit\n * modes under a reflecting, sheared, scaled parent, with amplifier bones ten\n * thousand units out along its axes; each of the five components (`x`, `y`,\n * `rotate`, `scaleX`, `shearX`) at 1, between 0 and 2 or negative; `limit`,\n * `fps`, `inertia`, `strength`, `damping`, `mass`, `wind`, `gravity` and\n * `mix` at random, each `…Global` flag at random; half of them with\n * physics timelines keying `mix`, `wind` and `reset` in an animation that\n * also swings the parent — sampled at seven `grid` or `irr` times, every\n * sample posed on the ONE skeleton the dump reuses: **400 of 400\n * identical**.\n * - 462 nine-bone rigs whose two to six constraints mix physics constraints\n * with ik and world- and local-space transform constraints in random order\n * (so a physics constraint sits between a world-space edit and a constraint\n * that re-poses it), physics timelines keying `mix` and `inertia`, five\n * `irr` samples: **462 of 462 identical**, 41,577 bone-samples.\n *\n * So under `Physics.none` the physics constraint neither moves its bone nor\n * re-poses anything below it, whatever its parameters, its `mix` or its\n * timelines, and wherever it stands in the update order: `applyConstraints`\n * is given no step context and applies nothing.\n *\n * ## The stepped phase, measured (issue #956)\n *\n * Every rule below was fixed the same way: hand-written skeletons dumped by\n * `tools/pose_oracle.ts dump --physics step --dt <s>` (spine-core 4.3.13) and\n * by the core, compared at tolerance 0, most with amplifier bones ten\n * thousand units out so a difference of 1e-10 in a matrix reads as a grid\n * step. spine-core's source was not read; each rule is the reading the dump\n * left exact, and each is stated with the population that fixed it and the\n * readings it rejected. The figures `n of 400` below are one population\n * (seed 81 of the lab): 400 rigs of six bones under one to five constraints —\n * physics with every component, setting, `…Global` flag and timeline at\n * random, ik and transform among them, skin-required constraints, two\n * animations, `dt` among 1/60, 1/30, 1/120 and a random 0.005–0.05 — exact\n * on 400 of 400 (63,982 bone-samples) under the rules as written, and the\n * count is how many stayed exact with ONE rule replaced by the reading named.\n * The core suite's `CK` controls hold the probes.\n *\n * **Defaults.** A field the record leaves out reads the parser's value, read\n * off the oracle's `physics` block for a constraint stating nothing: every\n * component 0, `limit` 5000, `fps` 60 (`step` = 1 / fps: 45 read 0.022222),\n * `inertia` 0.5, `strength` 100, `damping` 0.85, `mass` 1 (the block holds\n * `massInverse`: 3 read 0.333333), `wind`, `gravity` 0, `mix` 1, every flag\n * false, `scaleY` `None`. The core writes that block from its records\n * (`physicsRows`), under both phases.\n *\n * **The schedule** (`stepSchedule`) is the oracle's, from its header: a\n * fresh state per animation, the animation applied at 0 and the skeleton\n * reset; then from each sample's predecessor `p`, a step to `p + k·dt` while\n * that is before `t`, then to `t`. The skeleton's clock is the SUM of the\n * steps' deltas (`s − previous s`), not `s`: the constraint reads its delta\n * off that clock. The setup pose under the step is the reset pose. Each step\n * applies the animation from the time the walk last applied it at\n * (`PhysicsStepContext.last`, −1 before the first), as a player does — which\n * decides only when a `reset` key fires (*reset*, below).\n *\n * **Which constraints step.** A constraint on an inactive bone does not. A\n * constraint with `skin: true` steps exactly when an applied skin's\n * `constraints.physics` list names it — under `--skin all` every skin is\n * applied at once, under `--skin <name>` the named skin alone\n * (`listedBySkin`, set per skin view by `underSkin` in `./index.ts`;\n * `physicsActive`). Measured on the\n * commander's private-corpus finding (two rows DIFF, the core leaving such\n * constraints inert): hand-written documents dumped under `--physics step`\n * with `--skin all`, `--skin s1` and `--skin default` — named by no skin:\n * not stepped under any; named by `s1`: stepped under `all` and `s1`, not\n * under `default`; named by the default skin: stepped (under `all`, and —\n * issue #932 — under `default` but not under `s1`); a skin naming the\n * constrained bone (skin-required or not), another physics constraint or an\n * ik constraint, but not this one: not stepped; no skins at all: not\n * stepped. The reading inherited from issue #938 — `skin: true` is never\n * applied under `--skin all` — was measured under `Physics.none`, where a\n * physics constraint applies nothing either way; it is rejected (`CK13`\n * plants it and turns the listed probe red). A\n * constraint whose `mix` is 0 does nothing at all at that update — not even\n * read its clock: a constraint muted from 0 to 0.3 s and then keyed to 1\n * integrates the whole 0.3 s on its first live update after the pending one\n * (sack-pro's `fall-in`; advancing the clock at `mix` 0 kept 394 of 400). A\n * constraint never updated is pending, like a reset one: its first update\n * takes the bone where it is and integrates nothing (not pending kept 399 of\n * 400 and turned sack-pro red).\n *\n * **The components.** Each is on when it is ABOVE 0: `x`, `y`, `scaleX`, and\n * the rotation when `rotate` or `shearX` is (reading any non-zero as on kept\n * 279 of 400). A negative `rotate` or `shearX` still weighs the rotation: its\n * weight is `(rotate + shearX)·mix` (dropping the negative kept 369 of 400).\n *\n * **The step** (`stepPhysics`), in the order measured. `reset` clears every\n * offset, velocity and lag, zeroes what remains and sets the constraint's\n * clock to now; it is also what a `reset` key does, while the animation is\n * applied — before the step's delta is added. Then:\n *\n * - `delta` is the clock since the constraint last read it (never below 0),\n * added to what remains. A pending constraint takes the bone's origin as\n * the one it follows and integrates nothing; what remains is kept.\n * - `x`, `y`: the offset gains `(previous origin − origin)·inertia`, held to\n * `±limit·delta`. Then while at least one fixed `step` remains: `velocity\n * += (wind·R − offset·strength)·massInverse·step` (`y`: `−= (gravity·R +\n * offset·strength)·…`), `offset += velocity·step`, `velocity *=\n * damping^(60·step)` (`damping` itself kept 268 of 400; exact at 60 fps,\n * where the exponent is 1), and one step is taken off. What remains is\n * carried to the next update (dropping it kept 116 of 400; integrating once\n * per update at `dt` in place of `step` kept 116).\n * - The offset shown is `offset − lag·(1 − remaining/step)` (at least 0),\n * `lag` the change the integration just made: the pose between two fixed\n * steps (showing the integrated offset kept 116 of 400). The bone's origin\n * moves by it times `mix` times the component.\n * - Rotation and shear follow the bone's tip: with `ca` the bone's x-axis\n * angle and `(dx, dy)` how far its origin moved since the last update (each\n * held to `±limit·delta`), the offset gains `atan2(dy + ty, dx + tx) − ca −\n * (offset − lag·z₀)·w`, brought into (−π, π] with the runtime's π\n * (3.1415927: `Math.PI` kept 369 of 400), times `inertia` — `(tx, ty)` the\n * tip `length·(a, c)` the last update left, `w` the weight above, and `z₀`\n * the SHOWN weight of the previous update: `1 − remaining/step` before\n * this update's delta is added (after it kept 177 of 400; no lag at all\n * kept 176). The spring then runs as for `x` with `−((wind·sin + gravity·\n * cos)·length/R + offset·strength)·massInverse` — `sin`, `cos` of the\n * shown angle, re-read after every step.\n * - `scaleX` follows the tip along the bone: the offset gains `(dx·cos +\n * dy·sin)·inertia / r`, `r = length·|x column|`, and springs with `(wind·cos\n * − gravity·sin − offset·strength)·massInverse`. ⚠️ With no rotation on,\n * `r` is `length·|x column| − lag·z₀` — a dimensionless lag taken from a\n * length. It is the measured reading, not a derived one: the plain `r`\n * left scale-only probes off by a relative `(inertia step)·lag/length`\n * (`1 − 0.00020008` on a 50-unit bone moved one unit a step, `5e-5` at 100\n * units, `8e-4` at 25), and the subtraction made them exact (the plain `r`\n * kept 357 of 400; with rotation on the plain `r` is the exact one).\n * - Applied last: the rotation `o = (offset − lag·z)·mix` turns both columns\n * by `o·rotate`; with `shearX` on, the y column turns by `o·rotate` and\n * the x column by `o·(rotate + shearX)` (the first reading turned the y\n * column for the shear and read 0.049 off). The x column is scaled by `1 +\n * (offset − lag·z)·mix·scaleX`. The tip `length·(a, c)` is kept for the next\n * update.\n * - After it the bone is a world edit, as a world-space transform constraint\n * leaves one: its local values read back (`localFromWorld`) and every bone\n * below it posed again — so a constraint whose components are all 0 but\n * whose `mix` is not still re-derives its bone.\n *\n * **referenceScale.** `R` above is the skeleton's `referenceScale`. A Spine\n * header stating 50 moved 30 of 50 wind-and-gravity probes, and moved none\n * without them. The model document states it (`referenceScale`, issue\n * #958): `readModel` refuses a document without it by name and stamps it on\n * every physics record (`CorePhysicsRecord.referenceScale`), which is what\n * the step reads. Until #958 the core read the parser's 100 as a constant.\n *\n * ## The timelines\n *\n * `inertia`, `strength`, `damping`, `mass`, `wind`, `gravity` and `mix`\n * keys, one channel each, construct 4's key search and curves (key times and\n * values float32), applied in the animation's order. Before the first key\n * the setup value; after it `setup + (value − setup)` — the blend at alpha 1,\n * not the value itself: the two differ by a unit in the last place, and a\n * mass probe (a parent thrown 3e11 units) and a two-constraint wind-and-mix\n * probe both read it (the value itself kept 400 of 400 in the population and\n * turned both probes red). A `mass` key states a mass: the pose holds\n * `1 / (m₀ + (value − m₀))`, `m₀ = 1 / massInverse`. A key omitting its\n * value reads 0, a `mix` key 1 (`docs/AUTHORING.md` §4.4; a first key with\n * no value, on each of the seven, read exact — the `mass` one NaN in both\n * dumps). The timeline that\n * names no constraint (`*`) writes every active constraint whose `…Global`\n * flag for that value is on, and resets every active constraint. A\n * slider's animation keys them too, at the slider's place in the update\n * order (issue #1049, `./constraints_slider.ts` *Its physics timelines*).\n *\n * **reset.** A `reset` key resets its constraints on the step whose apply\n * crosses it — a key in `(last, t]`, `last` the time the walk last applied\n * the animation at, −1 before the first (`resetCrossed`) — so once, as a\n * player crosses it (issue #960, measured against `Animation.apply(last,\n * t)` and against `AnimationState` with one track, which agreed to the bit:\n * `tools/pose_oracle.ts` §`--physics step`). Until issue #960 the oracle\n * applied the animation from 0 at every step, and this walk mirrored it: a\n * key reset its constraints at EVERY step from it on, holding the rig still\n * (ignoring the key, or firing it once, kept 278 of 400 under that\n * oracle). That\n * reading is rejected as a schedule no player runs; the core suite's `SC`\n * controls plant it and turn the probe red on the steps after the key.\n *\n * ## The environment (issue #1416)\n *\n * A constraint's `wind` and `gravity` are not forces: they are how strongly it\n * answers two directions the SKELETON carries — spine-core 4.3.13's\n * `Skeleton.windX, windY` and `gravityX, gravityY`, initially `1, 0` and `0,\n * 1` (`DEFAULT_PHYSICS_ENVIRONMENT`). The step weighs them as the runtime\n * does: for `x` and `y`, `ax = (wind·windX + gravity·gravityX)·R` and `ay =\n * (wind·windY + gravity·gravityY)·R`, `velocity += (ax − offset·strength)·…`\n * on `x` and `−= (ay + offset·strength)·…` on `y`; for the rotation and the\n * scale the same two sums without `R`, `(ax·sin + ay·cos)·length/R` and `ax·cos\n * − ay·sin` in place of the wind and gravity terms above. The skeleton's own\n * scale, which the runtime multiplies the `x` and `y` sums by, is 1 here. So\n * the environment's y points DOWN — `[0, 1]` pulls toward the bottom of the\n * screen — and with the initial values every expression is the one this file\n * computed before the environment existed: `wind·1 + gravity·0` is `wind` for\n * every finite `gravity` (a `wind` of −0 aside, which it reads as +0, as the\n * runtime does), and the render and emit bases did not move.\n *\n * The consumer sets it (`setEnvironment` on a live track, `./track.ts`), and\n * moves the rig from outside with `translatePhysics` and `rotatePhysics` —\n * `Skeleton.physicsTranslate` and `physicsRotate`, which shift what each\n * constraint last saw (`ux, uy, cx, cy`) so its next update reads the bone as\n * having moved. A constraint with no state yet is pending, and its first\n * update overwrites both, so it is left alone, as the runtime's translation of\n * it is read by nothing. The core suite's `CO56` holds all of it to spine-core\n * given the same values at tolerance 0, and `CO57` that nothing set poses what\n * was posed before.\n *\n * ## What is not exact, and why\n *\n * Over 3,000 random rigs of three shapes (all five inherit modes; ik and\n * transform among them; skin-required constraints; the timeline naming no\n * constraint) the step read exact on 2,986. The fourteen: three are wrong\n * under `--physics none` too (a transform collapsing its bone's scale, and\n * no step involved); one is a bone under an inactive parent, whose zero\n * matrix both dumpers take to NaN by different routes; the other ten are\n * last-bit differences upstream of the step, amplified by it — seven on a\n * bone in `noScale`, `noScaleOrReflection` or `noRotationOrReflection`,\n * whose world transform `./world.ts` reproduces to the grid but not to the\n * bit (a probe amplified a billion units read one of those modes a few\n * units in the last place on 61 of 61 samples, and the four other modes on\n * none), two after `localFromWorld` re-derived a bone the step then moves\n * again, and one under a constraint whose rotation weight is negative, where\n * the inertia pushes away and any difference grows. Each is exact with the\n * bones normal, or with the weight positive. The step itself holds no\n * residual found.\n *\n * ## Purity\n *\n * As the rest of the core: nothing from the Spine runtime package, nothing\n * from `src/transform.ts`, no clock, no randomness, no I/O.\n */\nimport { channelAt, keyIndexAt, poseAnimations, sampleTime, type CoreAnimationPose, type CoreCurve, type CoreKey, type SamplePhase, type TimelinePlant } from './animation.ts';\nimport { RUNTIME_PI, type CoreWorld } from './world.ts';\n\n/** Degrees to radians as the runtime converts them (`MathUtils.degRad`, `pi / 180` with the runtime's pi). */\nconst RUNTIME_RAD = RUNTIME_PI / 180;\nimport { previousPassSlotBones, type CoreConstraintRecord } from './constraints.ts';\nimport { activeBones, type CompiledDocument } from './index.ts';\n\n/** The fields a physics constraint's record may carry after `kind`, `name`, `declaredIn` — the rig branch of `buildRigConstraint` and the motion spec's physics table (`src/compile.ts`). */\nexport const PHYSICS_FIELDS = [\n 'bone', 'scaleY', 'x', 'y', 'rotate', 'scaleX', 'shearX', 'limit', 'fps', 'inertia', 'strength', 'damping', 'mass', 'wind', 'gravity', 'mix',\n 'inertiaGlobal', 'strengthGlobal', 'dampingGlobal', 'massGlobal', 'windGlobal', 'gravityGlobal', 'mixGlobal', 'skin',\n] as const;\nconst PHYSICS_NUMBERS = ['x', 'y', 'rotate', 'scaleX', 'shearX', 'limit', 'fps', 'inertia', 'strength', 'damping', 'mass', 'wind', 'gravity', 'mix'] as const;\nconst PHYSICS_FLAGS = ['inertiaGlobal', 'strengthGlobal', 'dampingGlobal', 'massGlobal', 'windGlobal', 'gravityGlobal', 'mixGlobal', 'skin'] as const;\n/** The `scaleY` modes, first letter in either case (the ik constraint's enum, which a physics constraint shares). */\nconst SCALE_Y_MODES = ['none', 'uniform', 'volume'] as const;\n\n/** The five components a physics constraint drives, in the row's order. */\nexport const PHYSICS_COMPONENTS = ['x', 'y', 'rotate', 'scaleX', 'shearX'] as const;\n/** The seven values its pose holds and its timelines key, in the row's order (`mass` as the key states it; the pose holds its inverse). */\nexport const PHYSICS_PARAMETERS = ['inertia', 'strength', 'damping', 'mass', 'wind', 'gravity', 'mix'] as const;\nexport type PhysicsParameter = (typeof PHYSICS_PARAMETERS)[number];\n/** The timelines a physics constraint is keyed by: the seven values and `reset`. */\nexport const PHYSICS_TIMELINE_KINDS = [...PHYSICS_PARAMETERS, 'reset'] as const;\nexport type PhysicsTimelineKind = (typeof PHYSICS_TIMELINE_KINDS)[number];\n/** The model's name for the timeline that names no constraint (`EVERY_GLOBAL_PHYSICS` in `src/motion.ts`). */\nexport const EVERY_GLOBAL_PHYSICS = '*';\n\n/**\n * The parser's value for a field the record leaves out, measured off the\n * oracle's `physics` block for a constraint stating nothing (the header's\n * *Defaults*): every component 0, `limit` 5000, `fps` 60, `inertia` 0.5,\n * `strength` 100, `damping` 0.85, `mass` 1, `wind` and `gravity` 0, `mix` 1.\n */\nexport const PHYSICS_DEFAULTS = { x: 0, y: 0, rotate: 0, scaleX: 0, shearX: 0, limit: 5000, fps: 60, inertia: 0.5, strength: 100, damping: 0.85, mass: 1, wind: 0, gravity: 0, mix: 1 } as const;\n\n/** The values a physics constraint's pose holds — what its timelines set and its step reads. */\nexport interface PhysicsPose {\n inertia: number;\n strength: number;\n damping: number;\n massInverse: number;\n wind: number;\n gravity: number;\n mix: number;\n}\n\n/** A physics constraint, read field by field: its bone, the components it drives, its settings and its setup pose. */\nexport interface CorePhysicsRecord extends PhysicsPose {\n kind: 'physics';\n name: string;\n bone: string;\n skin: boolean;\n /** An applied skin's `constraints.physics` list names it — what makes a skin-required constraint step (the header's *Which constraints step*); set per skin view by `underSkin` in `./index.ts`. */\n listedBySkin: boolean;\n x: number;\n y: number;\n rotate: number;\n scaleX: number;\n shearX: number;\n limit: number;\n /** `1 / fps`, the integrator's fixed step in seconds. */\n step: number;\n /** The skeleton's reference scale — the document's `referenceScale` (issue #958), which wind and gravity act over. */\n referenceScale: number;\n /** Each `…Global` flag, by the value it opts in to being driven by the timeline that names no constraint. */\n global: Record<PhysicsParameter, boolean>;\n scaleYMode: 'None' | 'Uniform' | 'Volume';\n}\n\n/**\n * A physics constraint's record, read field by field — every field the writer\n * can write for the kind and no other, each of its type, its bone a bone of\n * the document — or `undefined` with the problems named. A field left out\n * reads the parser's value (`PHYSICS_DEFAULTS`). `referenceScale` is the\n * document's, read by `readModel` (issue #958), and stamped on the record.\n */\nexport function readPhysicsRecord(raw: Record<string, unknown>, name: string, where: string, bones: ReadonlySet<string>, referenceScale: number, problems: string[]): CorePhysicsRecord | undefined {\n const before = problems.length;\n for (const key of Object.keys(raw)) {\n if (key === 'kind' || key === 'name' || key === 'declaredIn') continue;\n if (!(PHYSICS_FIELDS as readonly string[]).includes(key)) problems.push(`${where}: field \"${key}\" is not one this reader knows; it reads [${PHYSICS_FIELDS.join(', ')}]`);\n }\n if (typeof raw.bone !== 'string' || !bones.has(raw.bone)) problems.push(`${where}: bone is ${JSON.stringify(raw.bone)}, not a bone of this document`);\n for (const key of PHYSICS_NUMBERS) {\n const v = raw[key];\n if (v !== undefined && (typeof v !== 'number' || !Number.isFinite(v))) problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a finite number`);\n }\n for (const key of PHYSICS_FLAGS) {\n const v = raw[key];\n if (v !== undefined && typeof v !== 'boolean') problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a boolean`);\n }\n let scaleYMode: CorePhysicsRecord['scaleYMode'] = 'None';\n if (raw.scaleY !== undefined) {\n const folded = typeof raw.scaleY === 'string' && raw.scaleY.length > 0 ? raw.scaleY[0].toLowerCase() + raw.scaleY.slice(1) : '';\n if (!(SCALE_Y_MODES as readonly string[]).includes(folded)) problems.push(`${where}: scaleY is ${JSON.stringify(raw.scaleY)}, none of ${SCALE_Y_MODES.join(', ')}`);\n else scaleYMode = folded === 'uniform' ? 'Uniform' : folded === 'volume' ? 'Volume' : 'None';\n }\n if (problems.length !== before) return undefined;\n const n = (key: keyof typeof PHYSICS_DEFAULTS): number => (typeof raw[key] === 'number' ? (raw[key] as number) : PHYSICS_DEFAULTS[key]);\n const global = {} as Record<PhysicsParameter, boolean>;\n for (const p of PHYSICS_PARAMETERS) global[p] = raw[`${p}Global`] === true;\n return {\n kind: 'physics', name, bone: raw.bone as string, skin: raw.skin === true, listedBySkin: false,\n x: n('x'), y: n('y'), rotate: n('rotate'), scaleX: n('scaleX'), shearX: n('shearX'), limit: n('limit'), step: 1 / n('fps'), referenceScale,\n inertia: n('inertia'), strength: n('strength'), damping: n('damping'), massInverse: 1 / n('mass'), wind: n('wind'), gravity: n('gravity'), mix: n('mix'),\n global, scaleYMode,\n };\n}\n\n/** Whether a physics record steps under the skin view posed: its bone active, and not skin-required unless an applied skin lists it — measured, the header's *Which constraints step*. */\nexport function physicsActive(r: CorePhysicsRecord, active: ReadonlySet<string>): boolean {\n return (!r.skin || r.listedBySkin) && active.has(r.bone);\n}\n\n/** One physics timeline: the constraint it names (`EVERY_GLOBAL_PHYSICS` for none), what it keys, its keys (a `reset` key's `values` empty). */\nexport interface CorePhysicsTimeline {\n name: string;\n kind: PhysicsTimelineKind;\n keys: CoreKey[];\n}\n\nconst isObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\n/**\n * How many physics timelines one animation record's `constraints.physics`\n * holds — the census's count. Their key times also set the animation's\n * duration, which `./animation.ts` reads.\n */\nexport function physicsTimelineCount(value: unknown): number {\n if (!Array.isArray(value)) return 0;\n let n = 0;\n for (const entry of value) {\n if (typeof entry === 'object' && entry !== null && Array.isArray((entry as { timelines?: unknown }).timelines)) n += (entry as { timelines: unknown[] }).timelines.length;\n }\n return n;\n}\n\n/**\n * One animation record's physics timelines, read in the record's order —\n * which is the order the runtime applies them in — each naming a declared\n * physics constraint or `EVERY_GLOBAL_PHYSICS`, each kind once per name, keys\n * strictly increasing in time with a finite `value` (absent: 1 for `mix`, 0\n * for the rest — the parser's reading) and a `reset` key a time alone.\n */\nexport function readPhysicsTimelines(value: unknown, label: string, declared: ReadonlySet<string>, problems: string[]): CorePhysicsTimeline[] {\n const out: CorePhysicsTimeline[] = [];\n if (!Array.isArray(value)) return out;\n value.forEach((entry, i) => {\n const at = `${label}.constraints.physics[${i}]`;\n if (!isObject(entry) || typeof entry.name !== 'string') {\n problems.push(`${at} names no physics constraint`);\n return;\n }\n const name = entry.name;\n if (name !== EVERY_GLOBAL_PHYSICS && !declared.has(name)) problems.push(`${at}: \"${name}\" is not a physics constraint of this document (nor \"${EVERY_GLOBAL_PHYSICS}\", the timeline naming none)`);\n if (!Array.isArray(entry.timelines)) {\n problems.push(`${at}: timelines is not a list`);\n return;\n }\n const seen = new Set<string>();\n entry.timelines.forEach((raw: unknown, j: number) => {\n const tat = `${at}.timelines[${j}]`;\n const kind = isObject(raw) ? PHYSICS_TIMELINE_KINDS.find((k) => k === raw.name) : undefined;\n if (!isObject(raw) || kind === undefined) {\n problems.push(`${tat}: ${JSON.stringify(isObject(raw) ? raw.name : raw)} is not a physics timeline; one keys ${PHYSICS_TIMELINE_KINDS.join(', ')}`);\n return;\n }\n if (seen.has(kind)) problems.push(`${tat}: \"${kind}\" is keyed twice on \"${name}\"`);\n seen.add(kind);\n const keys: CoreKey[] = [];\n const rawKeys: unknown = raw.keys;\n if (!Array.isArray(rawKeys) || rawKeys.length === 0) {\n problems.push(`${tat} \"${kind}\": keys is not a non-empty list`);\n return;\n }\n let last = -Infinity;\n rawKeys.forEach((k: unknown, q: number) => {\n const kat = `${tat} \"${kind}\".keys[${q}]`;\n if (!isObject(k)) {\n problems.push(`${kat} is not an object`);\n return;\n }\n const known = kind === 'reset' ? ['time'] : ['time', 'value', 'curve'];\n for (const f of Object.keys(k)) if (!known.includes(f)) problems.push(`${kat}: field \"${f}\" is not one this reader knows; it reads [${known.join(', ')}]`);\n const time = k.time;\n if (typeof time !== 'number' || !Number.isFinite(time) || time < 0) {\n problems.push(`${kat}: time is ${JSON.stringify(time)}, not a finite time at or after 0`);\n return;\n }\n if (time <= last) problems.push(`${kat}: time ${time} is not after the key before it — the writer refuses key times that do not strictly increase`);\n last = Math.max(last, time);\n if (kind === 'reset') {\n keys.push({ time: Math.fround(time), values: [], stated: { time, values: [] }, curve: 'stepped' });\n return;\n }\n let v = kind === 'mix' ? 1 : 0;\n if (k.value !== undefined) {\n if (typeof k.value !== 'number' || !Number.isFinite(k.value)) problems.push(`${kat}: value is ${JSON.stringify(k.value)}, not a finite number`);\n else v = k.value;\n }\n let curve: CoreCurve = 'linear';\n if (k.curve !== undefined) {\n if (q === rawKeys.length - 1) problems.push(`${kat}: the last key carries a curve, which eases to no key — the writer refuses it`);\n else if (k.curve === 'stepped') curve = 'stepped';\n else if (Array.isArray(k.curve) && k.curve.length === 4 && k.curve.every((c) => typeof c === 'number' && Number.isFinite(c))) curve = k.curve as number[];\n else problems.push(`${kat}: curve is ${JSON.stringify(k.curve)}, not \"stepped\" nor four finite numbers`);\n }\n keys.push({ time: Math.fround(time), values: [Math.fround(v)], stated: { time, values: [v] }, curve });\n });\n out.push({ name, kind, keys });\n });\n });\n return out;\n}\n\n/** What evaluates one channel of a key and finds the key — construct 4's unless a plant passes others. */\nexport interface PhysicsTimelinePlant {\n channel?: (keys: readonly CoreKey[], index: number, channel: number, t: number) => number;\n search?: (keys: readonly CoreKey[], t: number) => number;\n}\n\n/**\n * The records a physics timeline that names no constraint (`*`) writes: every\n * active one whose `…Global` flag for `kind` is on, and for `reset` every\n * active one (the header's *The timelines*), in the order given. `posedPhysics`\n * asks it, and so does the additive probe (`./additive.ts`, issue #1025).\n */\nexport function unnamedPhysicsTargets<R extends CorePhysicsRecord>(records: readonly R[], kind: PhysicsTimelineKind, active: (r: CorePhysicsRecord) => boolean): R[] {\n return records.filter((r) => active(r) && (kind === 'reset' || r.global[kind]));\n}\n\n/**\n * Every physics record posed by the animation's physics timelines at `t`, in\n * the timelines' order (the header's *The timelines*), and the names of the\n * constraints a `reset` key resets while the animation is applied from\n * `last` to `t` (`resetCrossed`). `active`\n * says whether a constraint is applied at all (its skin and its bone).\n */\nexport function posedPhysics(records: readonly CorePhysicsRecord[], timelines: readonly CorePhysicsTimeline[], t: number, last: number, active: (r: CorePhysicsRecord) => boolean, plant: PhysicsTimelinePlant = {}, wrapped = false): { records: Map<string, CorePhysicsRecord>; reset: Set<string> } {\n const search = plant.search ?? keyIndexAt;\n const channel = plant.channel ?? channelAt;\n const setupOf = new Map(records.map((r) => [r.name, r]));\n const posed = new Map(records.map((r) => [r.name, { ...r }]));\n const reset = new Set<string>();\n for (const tl of timelines) {\n const targets = tl.name === EVERY_GLOBAL_PHYSICS ? unnamedPhysicsTargets([...posed.values()], tl.kind, active) : [posed.get(tl.name) as CorePhysicsRecord].filter((r) => active(r));\n if (tl.kind === 'reset') {\n if (resetCrossed(tl.keys, last, t, wrapped)) for (const r of targets) reset.add(r.name);\n continue;\n }\n const i = search(tl.keys, t);\n for (const r of targets) {\n const setup = setupOf.get(r.name) as CorePhysicsRecord;\n if (tl.kind === 'mass') {\n // The key states a mass; the pose holds its inverse, and the setup the blend starts from is the inverse inverted.\n const from = 1 / setup.massInverse;\n r.massInverse = i < 0 ? setup.massInverse : 1 / (from + (channel(tl.keys, i, 0, t) - from));\n } else {\n r[tl.kind] = i < 0 ? setup[tl.kind] : setup[tl.kind] + (channel(tl.keys, i, 0, t) - setup[tl.kind]);\n }\n }\n }\n return { records: posed, reset };\n}\n\n/**\n * Whether a `reset` timeline resets its constraints when the animation is\n * applied from `last` to `t`, as a player applies it (the header's *reset*,\n * issue #960): exactly when a key lies in `(last, t]` — so a key is crossed\n * once, by the step that reaches it, and `last` is −1 before the walk's\n * first apply, where a key at 0 is crossed.\n *\n * `wrapped` is a looping track's step whose animation time went DOWN (issue\n * #1025, `./walk.ts`): the key crossed is then one after `last` or one at or\n * before `t` — `(last, ∞)` and `(−1, t]` — measured against spine-core's\n * `PhysicsConstraint.reset` calls on A10's walk. A step that wraps the track\n * one or more times while its animation time still rises is not `wrapped`:\n * the runtime fired only `(last, t]` there (a key at 0.25 of a 0.3 s\n * animation stepped by 0.7 s, crossed by the track twice between two applies\n * at 0.1 and 0.2, fired on neither).\n */\nexport function resetCrossed(keys: readonly CoreKey[], last: number, t: number, wrapped = false): boolean {\n return wrapped ? keys.some((k) => k.time > last || k.time <= t) : keys.some((k) => last < k.time && k.time <= t);\n}\n\n// ---------------------------------------------------------------------------\n// the step\n// ---------------------------------------------------------------------------\n\n/** One physics constraint's state between two updates (the header's *The step*). */\nexport interface PhysicsState {\n /** The next update takes the bone where it is and integrates nothing: set by a reset and on a constraint never updated. */\n pending: boolean;\n lastTime: number;\n remaining: number;\n ux: number;\n uy: number;\n cx: number;\n cy: number;\n tx: number;\n ty: number;\n xOffset: number;\n xLag: number;\n xVelocity: number;\n yOffset: number;\n yLag: number;\n yVelocity: number;\n rotateOffset: number;\n rotateLag: number;\n rotateVelocity: number;\n scaleOffset: number;\n scaleLag: number;\n scaleVelocity: number;\n}\n\n/** A constraint's state before its first update: pending, its clock at 0. */\nexport function freshPhysicsState(): PhysicsState {\n return { pending: true, lastTime: 0, remaining: 0, ux: 0, uy: 0, cx: 0, cy: 0, tx: 0, ty: 0, xOffset: 0, xLag: 0, xVelocity: 0, yOffset: 0, yLag: 0, yVelocity: 0, rotateOffset: 0, rotateLag: 0, rotateVelocity: 0, scaleOffset: 0, scaleLag: 0, scaleVelocity: 0 };\n}\n\n/** A reset: offsets, velocities and lags cleared, nothing remaining, the clock read at `time`, pending. */\nexport function resetPhysicsState(s: PhysicsState, time: number): void {\n s.remaining = 0;\n s.lastTime = time;\n s.pending = true;\n s.xOffset = s.xLag = s.xVelocity = 0;\n s.yOffset = s.yLag = s.yVelocity = 0;\n s.rotateOffset = s.rotateLag = s.rotateVelocity = 0;\n s.scaleOffset = s.scaleLag = s.scaleVelocity = 0;\n}\n\n/** The runtime's two phases the oracle steps with: `reset` resets the state first. */\nexport type PhysicsPhase = 'reset' | 'update';\n\n/** What steps one constraint — `stepPhysics` unless a plant passes another. */\nexport type PhysicsStepper = (r: CorePhysicsRecord, w: CoreWorld, length: number, ctx: PhysicsStepContext) => boolean;\n\n/** What a stepped pose carries into every physics constraint it applies. */\nexport interface PhysicsStepContext {\n phase: PhysicsPhase;\n /** Live track's final parameter layer, after authored/keyed/slider values (issue #1541). */\n parameters?: { apply(record: CorePhysicsRecord): CorePhysicsRecord };\n /** The skeleton's clock: the sum of every step's delta so far. */\n time: number;\n /** Each constraint's state, by name, carried from update to update. */\n states: Map<string, PhysicsState>;\n /** The step itself; a control passes a planted copy. */\n step?: PhysicsStepper;\n /**\n * The animation time the walk last applied the animation at, −1 before its\n * first apply — a fresh track's `TrackEntry.animationLast`, read −1 on\n * spine-core 4.3.13 (issue #960). A `reset` key fires on an apply from it\n * to the step's time (`resetCrossed`).\n */\n last: number;\n /**\n * The walk's track loops (`./walk.ts`, issue #1025): a step whose animation\n * time went down from `last` wrapped, and crosses the keys `resetCrossed`\n * names for that. Absent on every walk but the looping one.\n */\n loop?: boolean;\n /** A plant only (issue #1049, `sliderPhysicsLastsOnePass: false`): what the sliders wrote on the step before, by constraint and field. */\n carried?: Map<string, Partial<Record<'inertia' | 'strength' | 'damping' | 'massInverse' | 'wind' | 'gravity' | 'mix', number>>>;\n /** Each `constraint/field` the step's own animation keys — what the planted carried write gives way to. */\n keyedNow?: Set<string>;\n /** A plant only (issue #1049, `sliderPhysicsFromCurrent: false`): each physics record's setup values, before the step's own animation. */\n setupRecords?: Map<string, CorePhysicsRecord>;\n /**\n * The world every constraint answers (issue #1416, the header's *The\n * environment*): the skeleton's wind and gravity directions, as a caller set\n * them on the live track. Absent, spine-core's own initial values\n * (`DEFAULT_PHYSICS_ENVIRONMENT`), which is every walk but a live one a\n * caller set it on.\n */\n env?: PhysicsEnvironment;\n}\n\n/**\n * The world a physics constraint answers (issue #1416): spine-core 4.3.13's\n * four skeleton fields `windX`, `windY`, `gravityX` and `gravityY`, as\n * `wind: [windX, windY]` and `gravity: [gravityX, gravityY]` — the\n * DIRECTIONS the constraints' own `wind` and `gravity` act along, which are\n * each constraint's response to them (the header's *The environment*). In the\n * runtime's convention: x to the right, **y down** — a positive y component\n * pulls a constraint toward the bottom of the screen, as `gravity: [0, 1]`\n * does.\n */\nexport interface PhysicsEnvironment {\n readonly wind: readonly [number, number];\n readonly gravity: readonly [number, number];\n}\n\n/** spine-core 4.3.13's initial `Skeleton.windX, windY, gravityX, gravityY` — `1, 0, 0, 1` — the world of every walk nobody set one on. */\nexport const DEFAULT_PHYSICS_ENVIRONMENT: PhysicsEnvironment = Object.freeze({ wind: Object.freeze([1, 0] as const), gravity: Object.freeze([0, 1] as const) });\n\n/**\n * `Skeleton.physicsTranslate(x, y)` on the states in `ctx` (issue #1416): every\n * constraint's next update sees its bone moved by `(x, y)` in the skeleton's\n * world (y up) — the consumer moved the whole rig by that much since the last\n * pose. A constraint with no state yet has not been updated, and its first\n * update is pending, so the runtime's translation of it is read by nothing.\n */\nexport function translatePhysics(ctx: PhysicsStepContext, x: number, y: number, scope?: ReadonlySet<string>): void {\n for (const [name, s] of ctx.states) {\n if (scope !== undefined && !scope.has(name)) continue;\n s.ux -= x;\n s.uy -= y;\n s.cx -= x;\n s.cy -= y;\n }\n}\n\n/**\n * `Skeleton.physicsRotate(x, y, degrees)` on the states in `ctx` (issue\n * #1416): every constraint's next update sees its bone turned by `degrees`\n * (counter-clockwise, the runtime's pi) about `(x, y)` in the skeleton's world —\n * a translation of each constraint by how far that turn carries the origin it\n * last saw, as `PhysicsConstraint.rotate` computes it.\n */\nexport function rotatePhysics(ctx: PhysicsStepContext, x: number, y: number, degrees: number, scope?: ReadonlySet<string>): void {\n const r = degrees * RUNTIME_RAD;\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n for (const [name, s] of ctx.states) {\n if (scope !== undefined && !scope.has(name)) continue;\n const dx = s.cx - x;\n const dy = s.cy - y;\n const tx = dx * cos - dy * sin - dx;\n const ty = dx * sin + dy * cos - dy;\n s.ux -= tx;\n s.uy -= ty;\n s.cx -= tx;\n s.cy -= ty;\n }\n}\n\n/** A constraint's state in `ctx`, created fresh on its first update. */\nexport function physicsState(ctx: PhysicsStepContext, name: string): PhysicsState {\n let s = ctx.states.get(name);\n if (s === undefined) {\n s = freshPhysicsState();\n ctx.states.set(name, s);\n }\n return s;\n}\n\nconst PI2 = RUNTIME_PI * 2;\nconst INV_PI2 = 1 / PI2;\n\n/** What a physics constraint's step moves, by its five component fields. */\nexport interface PhysicsDrives {\n x: boolean;\n y: boolean;\n /** `rotate` or `shearX` above 0: the two share the angular part of the step. */\n rotateOrShearX: boolean;\n scaleX: boolean;\n}\n\n/**\n * Which parts of the step a constraint drives: a component above 0 drives its\n * part and nothing else does — the test `stepPhysics` takes before each part\n * of *The step* above, posed against the runtime with the rest of it. Exported\n * because `src/ingest.ts` asks the same question of a raw file (a\n * constraint that drives none of the four moves no bone, issue #731) and\n * answers it through this function (issue #1015).\n */\nexport function physicsDrives(r: { x: number; y: number; rotate: number; shearX: number; scaleX: number }): PhysicsDrives {\n return { x: r.x > 0, y: r.y > 0, rotateOrShearX: r.rotate > 0 || r.shearX > 0, scaleX: r.scaleX > 0 };\n}\n\n/**\n * One physics constraint updated on its bone's world transform `w`\n * (mutated), `length` the bone's length — the header's *The step*, every\n * expression in the order measured. Returns false when its `mix` is 0: the\n * constraint then does nothing at all, its clock included, and the bone is\n * not re-posed.\n */\nexport function stepPhysics(r: CorePhysicsRecord, w: CoreWorld, length: number, ctx: PhysicsStepContext): boolean {\n const mix = r.mix;\n if (mix === 0) return false;\n const s = physicsState(ctx, r.name);\n const { x, y, rotateOrShearX, scaleX } = physicsDrives(r);\n const l = length;\n if (ctx.phase === 'reset') resetPhysicsState(s, ctx.time);\n const delta = Math.max(ctx.time - s.lastTime, 0);\n // The interpolation weight of the previous update, before this one's time is added: the rotate and the scale-only inertia read the pose as it was shown.\n const shown = Math.max(0, 1 - s.remaining / r.step);\n s.remaining += delta;\n s.lastTime = ctx.time;\n const bx = w.worldX;\n const by = w.worldY;\n const env = ctx.env ?? DEFAULT_PHYSICS_ENVIRONMENT;\n let z = 0;\n if (s.pending) {\n s.pending = false;\n s.ux = bx;\n s.uy = by;\n } else {\n let a = s.remaining;\n const i = r.inertia;\n const t = r.step;\n const f = r.referenceScale;\n let d = -1;\n const qx = r.limit * delta;\n const qy = qx;\n if (x || y) {\n if (x) {\n const u = (s.ux - bx) * i;\n s.xOffset += u > qx ? qx : u < -qx ? -qx : u;\n s.ux = bx;\n }\n if (y) {\n const u = (s.uy - by) * i;\n s.yOffset += u > qy ? qy : u < -qy ? -qy : u;\n s.uy = by;\n }\n if (a >= t) {\n d = Math.pow(r.damping, 60 * t);\n const m = r.massInverse * t;\n const e = r.strength;\n const wind = r.wind * f;\n const g = r.gravity * f;\n // The environment's directions (issue #1416), as the runtime weighs them; the skeleton's scale is 1 here, so its factor is left out.\n const ax = wind * env.wind[0] + g * env.gravity[0];\n const ay = wind * env.wind[1] + g * env.gravity[1];\n const xs = s.xOffset;\n const ys = s.yOffset;\n do {\n if (x) {\n s.xVelocity += (ax - s.xOffset * e) * m;\n s.xOffset += s.xVelocity * t;\n s.xVelocity *= d;\n }\n if (y) {\n s.yVelocity -= (ay + s.yOffset * e) * m;\n s.yOffset += s.yVelocity * t;\n s.yVelocity *= d;\n }\n a -= t;\n } while (a >= t);\n s.xLag = s.xOffset - xs;\n s.yLag = s.yOffset - ys;\n }\n z = Math.max(0, 1 - a / t);\n if (x) w.worldX += (s.xOffset - s.xLag * z) * mix * r.x;\n if (y) w.worldY += (s.yOffset - s.yLag * z) * mix * r.y;\n }\n if (rotateOrShearX || scaleX) {\n const ca = Math.atan2(w.c, w.a);\n let c = 0;\n let sn = 0;\n let mr = 0;\n let dx = s.cx - w.worldX;\n let dy = s.cy - w.worldY;\n if (dx > qx) dx = qx;\n else if (dx < -qx) dx = -qx;\n if (dy > qy) dy = qy;\n else if (dy < -qy) dy = -qy;\n if (rotateOrShearX) {\n mr = (r.rotate + r.shearX) * mix;\n const lagged = s.rotateLag * shown;\n let rr = Math.atan2(dy + s.ty, dx + s.tx) - ca - (s.rotateOffset - lagged) * mr;\n s.rotateOffset += (rr - Math.ceil(rr * INV_PI2 - 0.5) * PI2) * i;\n rr = (s.rotateOffset - lagged) * mr + ca;\n c = Math.cos(rr);\n sn = Math.sin(rr);\n if (scaleX) {\n rr = l * Math.sqrt(w.a * w.a + w.c * w.c);\n if (rr > 0) s.scaleOffset += ((dx * c + dy * sn) * i) / rr;\n }\n } else {\n c = Math.cos(ca);\n sn = Math.sin(ca);\n const rr = l * Math.sqrt(w.a * w.a + w.c * w.c) - s.scaleLag * shown;\n if (rr > 0) s.scaleOffset += ((dx * c + dy * sn) * i) / rr;\n }\n a = s.remaining;\n if (a >= t) {\n if (d === -1) d = Math.pow(r.damping, 60 * t);\n const m = r.massInverse * t;\n const e = r.strength;\n const ax = r.wind * env.wind[0] + r.gravity * env.gravity[0];\n const ay = r.wind * env.wind[1] + r.gravity * env.gravity[1];\n const h = l / f;\n const rs = s.rotateOffset;\n const ss = s.scaleOffset;\n for (;;) {\n a -= t;\n if (scaleX) {\n s.scaleVelocity += (ax * c - ay * sn - s.scaleOffset * e) * m;\n s.scaleOffset += s.scaleVelocity * t;\n s.scaleVelocity *= d;\n }\n if (rotateOrShearX) {\n s.rotateVelocity -= ((ax * sn + ay * c) * h + s.rotateOffset * e) * m;\n s.rotateOffset += s.rotateVelocity * t;\n s.rotateVelocity *= d;\n if (a < t) break;\n const rr = s.rotateOffset * mr + ca;\n c = Math.cos(rr);\n sn = Math.sin(rr);\n } else if (a < t) break;\n }\n s.rotateLag = s.rotateOffset - rs;\n s.scaleLag = s.scaleOffset - ss;\n }\n z = Math.max(0, 1 - a / t);\n }\n s.remaining = a;\n }\n s.cx = w.worldX;\n s.cy = w.worldY;\n if (rotateOrShearX) {\n let o = (s.rotateOffset - s.rotateLag * z) * mix;\n let sn = 0;\n let c = 0;\n let a = 0;\n if (r.shearX > 0) {\n let rr = 0;\n if (r.rotate > 0) {\n // The rotation's share turns the y column here, and the x column with the shear below.\n rr = o * r.rotate;\n sn = Math.sin(rr);\n c = Math.cos(rr);\n a = w.b;\n w.b = c * a - sn * w.d;\n w.d = sn * a + c * w.d;\n }\n rr += o * r.shearX;\n sn = Math.sin(rr);\n c = Math.cos(rr);\n a = w.a;\n w.a = c * a - sn * w.c;\n w.c = sn * a + c * w.c;\n } else {\n o *= r.rotate;\n sn = Math.sin(o);\n c = Math.cos(o);\n a = w.a;\n w.a = c * a - sn * w.c;\n w.c = sn * a + c * w.c;\n a = w.b;\n w.b = c * a - sn * w.d;\n w.d = sn * a + c * w.d;\n }\n }\n if (scaleX) {\n const k = 1 + (s.scaleOffset - s.scaleLag * z) * mix * r.scaleX;\n w.a *= k;\n w.c *= k;\n // The transverse column follows the authored mode (issue #1453), after\n // the X column: the native Volume branch bounds reciprocal compression\n // below 0.7; it is not an area-preservation promise on that branch.\n if (r.scaleYMode === 'Uniform') {\n w.b *= k;\n w.d *= k;\n } else if (r.scaleYMode === 'Volume') {\n const magnitude = Math.abs(k);\n const transverse = magnitude >= 0.7 ? 1 / magnitude : 4 - 3.67347 * magnitude;\n w.b *= transverse;\n w.d *= transverse;\n }\n }\n s.tx = l * w.a;\n s.ty = l * w.c;\n return true;\n}\n\n/** The oracle's `physics` block written from the records, in constraint order, rounded as the oracle rounds. */\nexport function physicsRows(records: readonly CorePhysicsRecord[], round: (v: number) => number | null): Array<Record<string, unknown>> {\n return records.map((r) => ({\n name: r.name, bone: r.bone,\n x: round(r.x), y: round(r.y), rotate: round(r.rotate), scaleX: round(r.scaleX), shearX: round(r.shearX), limit: round(r.limit), step: round(r.step),\n inertia: round(r.inertia), strength: round(r.strength), damping: round(r.damping), massInverse: round(r.massInverse), wind: round(r.wind), gravity: round(r.gravity), mix: round(r.mix),\n inertiaGlobal: r.global.inertia, strengthGlobal: r.global.strength, dampingGlobal: r.global.damping, massGlobal: r.global.mass, windGlobal: r.global.wind, gravityGlobal: r.global.gravity, mixGlobal: r.global.mix,\n skinRequired: r.skin, scaleYMode: r.scaleYMode,\n }));\n}\n\n// ---------------------------------------------------------------------------\n// the walk\n// ---------------------------------------------------------------------------\n\n/**\n * One step's constraint records: every physics record posed by the\n * animation's physics timelines at `t` (`posedPhysics`), and each constraint\n * a `reset` key resets reset now — while the animation is applied, before\n * the skeleton's clock moves to this step (`before` is the clock it reads;\n * the header's *reset*). `./animation.ts` calls it for every step of the walk.\n */\nexport function stepPhysicsRecords(records: readonly CoreConstraintRecord[], keyed: readonly CorePhysicsTimeline[], t: number, active: ReadonlySet<string>, ctx: PhysicsStepContext, before: number): CoreConstraintRecord[] {\n const physics = records.filter((r): r is CorePhysicsRecord => r.kind === 'physics');\n const posed = posedPhysics(physics, keyed, t, ctx.last, (r) => physicsActive(r, active), {}, ctx.loop === true && t < ctx.last);\n ctx.last = t;\n ctx.setupRecords = new Map(physics.map((r) => [r.name, r]));\n ctx.keyedNow = new Set(keyed.flatMap((tl) => (tl.kind === 'reset' ? [] : (tl.name === EVERY_GLOBAL_PHYSICS ? unnamedPhysicsTargets(physics, tl.kind, (r) => physicsActive(r, active)).map((r) => r.name) : [tl.name]).map((n) => `${n}/${tl.kind === 'mass' ? 'massInverse' : tl.kind}`))));\n for (const name of posed.reset) resetPhysicsState(physicsState(ctx, name), before);\n return records.map((r) => (r.kind === 'physics' ? (posed.records.get(r.name) as CorePhysicsRecord) : r));\n}\n\n/** A fresh step context for one animation's walk (or the setup's reset), the plant's step in place of `stepPhysics` when a control passes one. */\nexport function freshStepContext(step?: PhysicsStepper): PhysicsStepContext {\n return { phase: 'reset', time: 0, states: new Map(), last: -1, ...(step ? { step } : {}) };\n}\n\n/**\n * Why the samples' bones are left out under the step, or null: a path\n * constraint whose offset reads its slot bone from the previous pose, which\n * is then the previous step's — a pose the walk does not carry.\n */\nexport function steppedPreviousPassWhy(doc: CompiledDocument): string | null {\n const reads = previousPassSlotBones(doc, activeBones(doc));\n return reads.length === 0 ? null : `${reads.map((r) => `path constraint \"${r.constraint}\" reads slot bone \"${r.bone}\" from the previous pose`).join('; ')} — under the step the previous pose is the previous step's, which the stepped walk does not carry`;\n}\n\n/**\n * The oracle's schedule (the header's *The schedule*): for each of the `n`\n * samples of an animation of duration `d` under `phase`, the times the walk\n * steps to after the sample before it — from the previous sample's time `p`\n * (0 before the first), `p + k·dt` for `k = 1, 2, …` while that is before\n * the sample's `t`, then `t` itself unless the walk is already there. The\n * walk starts at 0 with the reset, so a sample at 0 takes no step.\n */\nexport function stepSchedule(phase: SamplePhase, d: number, n: number, dt: number): number[][] {\n const out: number[][] = [];\n let now = 0;\n for (let i = 0; i < n; i++) {\n const t = sampleTime(phase, d, i, n);\n const from = now;\n const steps: number[] = [];\n for (let k = 1; from + k * dt < t; k++) steps.push(from + k * dt);\n if (steps.length > 0) now = steps[steps.length - 1];\n if (t > now) {\n steps.push(t);\n now = t;\n }\n out.push(steps);\n }\n return out;\n}\n\n/**\n * Every animation of the document walked as the oracle's `--physics step\n * --dt <dt>` walks it (the header's *The schedule*) — `poseAnimations` in\n * `./animation.ts` given `dt`, which poses every block of each sample off\n * the last step's pose — and the steps the schedule takes to reach each\n * sample, per animation.\n */\nexport function poseSteppedAnimations(doc: CompiledDocument, phase: SamplePhase, n: number, dt: number, plant: TimelinePlant = {}): { animations: CoreAnimationPose[]; absent: Array<[string, string]>; steps: number[][] } {\n const posed = poseAnimations(doc, phase, n, plant, dt);\n return { ...posed, steps: doc.animations.map((a) => stepSchedule(phase, a.timelines.duration, n, dt).map((x) => x.length)) };\n}\n","/**\n * Construct 5 of the core, third cut (issue #938, step 2e-iii of issue\n * #380): the slider constraint at the setup pose and at a sample time, with\n * its timelines. A slider applies an animation — the one constraint kind\n * that writes bones' LOCAL values and slots rather than a world transform.\n *\n * Every rule below was measured by posing hand-written skeletons through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13, `--skin all`,\n * `--physics none`) and reading the rows back — a bone's local values through\n * `localSource` transform constraints written onto spare bones, a slot's row\n * as the dump prints it — then held at tolerance 0 by the core suite's `CQ`\n * controls. Nothing here was written from the runtime's source.\n *\n * ## Where it stands: the update order\n *\n * A slider is one more constraint in the document's order (`./constraints.ts`,\n * *The update order*): it reads its dial bone as the constraints before it\n * left it, writes the local values of the bones its animation keys, and those\n * bones and everything below them are posed again before the next\n * constraint. **Every bone its animation keys is posed again, whether or not\n * a timeline wrote it** (issue #989): a slider before a timeline's first key\n * writes nothing (below), and the bone is still posed again from its local\n * values — which is observable only on a bone an earlier constraint moved in\n * world space, whose world transform the runtime then rebuilds from the\n * local values read back from it (`localFromWorld` in `./constraints.ts`,\n * last-bit lossy against the world it came from). Measured on the three rigs\n * of `CQ06`'s population the lcg never drew (each a world-space transform on\n * `b2`, then a slider before its first key keying `b2` or its parent): `b2`'s\n * y column read 1e-7 relative off with the world kept, exact with it posed\n * again; so did every bone below. A slider at `mix` 0 poses nothing again\n * (the same three at mix 0 read exact only without it), nor does a bone\n * the animation names with no timeline (a `\"b2\": {}` entry). `CZ01` holds\n * the three, and plants the reading before.\n *\n * The runtime's setup pose and every sample apply it: at setup\n * the sliders compose on the setup pose; at a sample on the pose the sample's\n * own animation left (applied at alpha 1 from the setup pose, construct 4),\n * so **the sample's animation first, then each slider in constraint order**.\n *\n * ## The time it applies its animation at\n *\n * - **Bone-less**: the slider's `time` (a `slider` timeline's `time` key at a\n * sample), as it is: a negative time is a time before the animation's keys.\n * - **With a `bone`**: `to + (value − from) · scale`, `value` the dial's\n * `property` read exactly as a transform constraint reads its source with\n * no offset (`sourceValue` in `./constraints.ts`): `local` the local field\n * as earlier constraints left it, unwrapped; world `rotate` the x column's\n * angle brought into [0, 360); world `x`, `y` the origin; world `scaleX`,\n * `scaleY` the column lengths; world `shearY` the angle between the columns\n * less 90. Measured on a dial under a parent turned 30° and scaled 2 in x:\n * a local 10° at `scale` 0.01 read time 0.1, a world 10° read 0.350384 (the\n * x column at 35.0384°), a world −50° read 359.21° (0.35921 at 0.001).\n * Then `max(0, time)` — a dial at −50° applied the first frame — or, with\n * `loop`, `duration + (time mod duration)`: 3 over a 2 s animation read 1,\n * −0.5 read 1.5. A stated `time` beside a `bone` is not read (the bone won).\n * - The animation is then applied at that time, wrapped `time mod duration`\n * when `loop` (a bone-less 3.25 over 1 s read 0.25, which is before the\n * first key at 0.5 and so applied nothing), `duration` being the runtime's\n * (`./animation.ts`, the last key time as float32). ⚠️ A dial looping over\n * an animation of duration 0 computes `0 + (time mod 0)`, NaN — and the\n * runtime still applied the animation's one key (a rotate keyed 45 on a\n * bone at 20 read 65, as the same slider without `loop` and the bone-less\n * form looping at 0 and at 0.5 did): every key of such an animation sits\n * at 0, so the core applies it at 0. The compiler refuses the shape (A37);\n * a foreign file can still carry it.\n *\n * ## How it composes: the current pose, the mix, `additive`\n *\n * Each timeline of the slider's animation, in the animation's order, blends\n * from the CURRENT pose — whatever the setup, the sample's animation and the\n * constraints before it left — with `alpha` the slider's `mix`:\n *\n * - **Before the timeline's first key it writes nothing** (the current pose\n * stands: a slider at 0.2 over a rotate keyed from 0.5 left 20° at setup\n * and the sample's 50° alike). Not the setup value, as a sample's own\n * animation writes (construct 4).\n * - **`mix` 0 applies nothing at all** — not even an attachment key.\n * - `rotate`, `translate`/`x`/`y`, `shear`/`x`/`y`: `current + (setup + v −\n * current) · mix`; **`additive`**: `current + v · mix`. Measured on setup\n * rotation 20 and a sample at 50, the slider's value 150: 170 at mix 1,\n * 110 at 0.5, −10 at −0.5 (no clamp); additive 200 and 125. No wrap to the\n * short way round: 50 toward 290 at 0.3 read 122.\n * - `scale`/`x`/`y`: the target is `setup · v`; `current' + (target −\n * current') · mix` where `current'` is |current| with the TARGET's sign — a\n * setup `scaleY` 0.5 toward −0.5 at mix 0.5 read −0.5, not 0 — and ⚠️ at\n * mix exactly 1 the target itself (issue #989: `current' + (target −\n * current')·1` reads 11 of `CZ02`'s 50 absolute bones at mix 1 last-bit\n * off under `--raw`, the target none); **additive**: `current + (v · setup\n * − setup) · mix` (a current 6 on setup 2, v 3 read 10; issue #989:\n * `(v − 1) · setup · mix`, the reading before, reads 65 of `CZ02`'s 250\n * additive bones last-bit off, this none). The other kinds read 1,122 of\n * 1,122 probes of issue #989's scratch population bit-exact at every mix,\n * over the setup and over a current an earlier slider moved, and were left\n * as they are.\n * - `inherit`: the key's mode, from its first key on (`CQ06` holds it).\n * - Slot colours (`rgba`, `rgb`, `alpha`, `rgba2`, `rgb2`): each channel the\n * timeline names moves from the current value toward the key's by the mix\n * and is then clamped to [0, 1] — ⚠️ at mix exactly 1 it IS the key's value:\n * `current + (v − current)·1` read 1 ulp off spine-core on 30 of 13,950\n * slot readings of issue #969's hand-written population (`DM01`), the key's\n * value on none (a mix of −1 read alpha 0, of 2 read\n * 0.87451 from 0.12549 toward 0.5); `additive` changes nothing for them.\n * - `attachment`: the key's placeholder from its first key on, whatever the\n * mix above 0 (0.01 switched it); `null` shows nothing.\n *\n * ## Its timelines\n *\n * A sample's animation may key a slider's `time` and `mix` (one channel\n * each, construct 4's key search and curves, float32 key values). Before the\n * first key the slider's own value; a key omitting `value` reads 1 (the\n * compiler's note on the parser, measured again by `CQ07`). A bone-driven\n * slider ignores a `time` key: its time is its dial's.\n *\n * The keyed value reaches the slider through the setup blend at alpha 1,\n * `own + (value − own)·1` with `own` the slider's own `time` or `mix` —\n * the rule the ik, transform and path timelines follow (`./constraints.ts`,\n * *The timelines*). The two agree on the grid and part in the last bit: a\n * mix keyed linearly from 0.462 to 0.152 read 0.3521456338160804 as keyed\n * and 0.35214563381608044 through the blend at one sample, and the\n * partial-mix blend of a shear key then carried that ulp into the pose (issue\n * #991, which found it on a looped dial; the loop, the dial and the\n * translate key it was reduced with each turned out incidental — the same\n * rig without them misses on 44 to 71 of 200 draws of its two mix values as\n * keyed and on none through the blend). Measured on the issue's scratch\n * population — 500 rigs of one or two sliders, looped and unlooped dials and\n * bone-less ones, over own mixes in [−1, 2], mix keys and time keys in\n * linear, stepped and Bézier segments, under `--raw` at tolerance 0 — the\n * value as keyed read 351 of 500 exact, the blend on `mix` alone 465, on\n * `time` alone 375, on both 500. `CZ03` holds a reduced rig and plants the\n * value as keyed.\n *\n * ## What is left out, by name\n *\n * A slider whose animation keys a constraint timeline (ik, transform, path,\n * slider — writing a later constraint's pose, issue #665's case) is not\n * posed: the document's bones are absent, naming it; so is one whose\n * animation deforms a curve a path constraint walks (unmeasured). A slider's\n * deform, sequence and draw-order keys are posed since issue #955, after the\n * sample's own (`./deform.ts`, `./draw_order.ts`; they were `sliderAttachmentsWhy`'s\n * absence before). Its physics timelines are posed since issue #1049 (below),\n * and events a slider does not fire, so neither leaves anything out.\n *\n * ## Its physics timelines (issue #1049)\n *\n * Under `Physics.none` a physics constraint applies nothing\n * (`./constraints_physics.ts`), so neither do a slider's physics keys. Under\n * the step they do, and until issue #1049 the core applied none of them: on\n * the selftest's own builds where a dial's animation keys `wind` or\n * `gravity` of a constraint declared after it, every bone the constraint\n * drives left spine-core from the third step (`tip` worldX\n * 14.87037037037037 against 12.092592592592593 at 0.025 s), and with a slot\n * on that bone `render` drew wrong frames with no refusal. Measured against\n * spine-core 4.3.13's output only — A10's looping walk, `render`'s recipe at\n * 60 and 12 fps and the oracle's stepped grid under `--raw`, on 400 compiled\n * rigs of one or two sliders and one or two physics constraints in random\n * order, every kind keyed, at tolerance 0 — the rule is:\n *\n * - **A slider writes its physics keys into the pass's physics records, at\n * its place in the update order**, at the time it applies its animation at\n * (`at`), after the step's own animation posed them; a physics constraint\n * after it steps with what it wrote, one before it has already stepped.\n * Applying the writes to every constraint of the pass whatever its place\n * read 239 of the 400 rigs off; not applying them, 205.\n * - **A write lasts one pass.** The next step's records start again from the\n * step's own animation: a write that stood where the step's animation does\n * not key read 323 of 400 off.\n * - **Before the timeline's first key it writes nothing**, as for bones.\n * - **`wind`, `gravity` under `additive`: `current + v·mix`.** Every other\n * value (`inertia`, `strength`, `damping`, `mass`, `mix`), and every value\n * of a slider that is not additive: `current + (v − current)·mix`, with\n * `current` the value as the pass holds it (the step's own animation and\n * any slider before). Adding every kind read 104 of 400 off; blending from\n * the setup value (before the step's own animation), 80; writing the key\n * itself at mix exactly 1, 20 — in the last bit.\n * - **A `mass` key blends the mass**, `1 / (m + (v − m)·mix)` with `m =\n * 1 / massInverse`; blending the inverse read 28 of 400 off.\n * - **A `reset` key fires nothing** — the slider applies its animation at one\n * time, from that time, so no key is crossed (the path-slider suite's\n * `PS159` measured the same on the pose); firing a key at or before `at` on\n * every pass read 112 of 400 off.\n * - The timeline naming no constraint (`*`) writes every active constraint\n * whose `…Global` flag for that value is on, as a step's own does.\n *\n * `CO31` holds the rule on the `core_gate` probe rows and a seeded population\n * on all three entries; `CO32` plants each rejected reading (`SolverRules`).\n *\n * ## Purity\n *\n * As the rest of the core: nothing from the Spine runtime package, nothing\n * from `src/transform.ts`, no clock, no randomness, no I/O.\n */\nimport type { ModelBone } from '../model.ts';\nimport { channelAt, keyIndexAt, type CoreAnimationTimelines, type CoreCurve, type CoreKey } from './animation.ts';\nimport { sourceValue, TRANSFORM_PROPERTIES, type CoreConstraintRecord, type SolverRules, type SolverState, type TransformProperty } from './constraints.ts';\nimport type { CompiledDocument, CoreAnimation } from './index.ts';\nimport { EVERY_GLOBAL_PHYSICS, physicsActive, physicsState, resetPhysicsState, unnamedPhysicsTargets, type CorePhysicsRecord, type CorePhysicsTimeline, type PhysicsStepContext } from './constraints_physics.ts';\n\n/** The fields a slider's record may carry after `kind`, `name`, `declaredIn` (`buildRigConstraint` in `src/compile.ts`). */\nexport const SLIDER_FIELDS = ['animation', 'additive', 'loop', 'mix', 'bone', 'property', 'from', 'to', 'scale', 'max', 'local', 'time', 'skin'] as const;\n\n/** A slider, read: its animation's timelines and every setup value of the bones they key, so it can be applied with no other part of the document. */\nexport interface CoreSliderRecord {\n kind: 'slider';\n name: string;\n animation: string;\n timelines: CoreAnimationTimelines;\n /** Its animation's physics timelines, in the animation's order (issue #1049) — set by `readModel` once the animations' constraint timelines are read, which is after the records. */\n physics: readonly CorePhysicsTimeline[];\n /** The setup bones its animation keys, by name — what a non-additive key's value is added to. */\n setup: ReadonlyMap<string, ModelBone>;\n additive: boolean;\n loop: boolean;\n mix: number;\n time: number;\n /** The dial, or `null` for the bone-less form. */\n bone: string | null;\n property: TransformProperty;\n from: number;\n to: number;\n scale: number;\n local: boolean;\n skin: boolean;\n /** An applied skin's `slider` list names it — what applies a skin-required one (`./constraints.ts`'s header); set per skin view by `underSkin` in `./index.ts`. */\n listedBySkin: boolean;\n}\n\n/** One slider's timelines in one animation: the `time` and `mix` keys, `null` where not keyed. */\nexport interface CoreSliderTimeline {\n name: string;\n time: CoreKey[] | null;\n mix: CoreKey[] | null;\n}\n\n/** A slider as it was applied: its animation, at which time, with which alpha — what the slots are posed from after the bones. */\nexport interface SliderApplication {\n name: string;\n timelines: CoreAnimationTimelines;\n at: number;\n alpha: number;\n /** The slider's `additive` — how its deform timelines blend (`./deform.ts`). */\n additive: boolean;\n /** #969: the time it stored — `sliderTime`, before the animation's loop wrap — what the runtime's `SliderPose.time` reads (`./hooks.ts`). */\n time: number;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\n/**\n * A slider's record, read field by field — every field the writer can write\n * for the kind and no other, each of its type, the animation one of the\n * document's, the dial a bone of it — or `undefined` with the problems named.\n * An absent field reads the parser's value (the header): `mix` 1, `time`,\n * `from`, `to` 0, `scale` 1, the flags false.\n */\nexport function readSliderRecord(raw: Record<string, unknown>, name: string, where: string, bones: readonly ModelBone[], animations: readonly CoreAnimation[], problems: string[]): CoreSliderRecord | undefined {\n const before = problems.length;\n for (const key of Object.keys(raw)) {\n if (key === 'kind' || key === 'name' || key === 'declaredIn') continue;\n if (!(SLIDER_FIELDS as readonly string[]).includes(key)) problems.push(`${where}: field \"${key}\" is not one this reader knows; it reads [${SLIDER_FIELDS.join(', ')}]`);\n }\n const num = (key: string, dflt: number): number => {\n const v = raw[key];\n if (v === undefined) return dflt;\n if (typeof v !== 'number' || !Number.isFinite(v)) {\n problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a finite number`);\n return dflt;\n }\n return v;\n };\n const flag = (key: string): boolean => {\n const v = raw[key];\n if (v === undefined) return false;\n if (typeof v !== 'boolean') {\n problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a boolean`);\n return false;\n }\n return v;\n };\n const anim = animations.find((a) => a.name === raw.animation);\n if (anim === undefined) problems.push(`${where}: a slider's animation is ${JSON.stringify(raw.animation)}, not an animation of this document`);\n const byName = new Map(bones.map((b) => [b.name, b]));\n let bone: string | null = null;\n if (raw.bone !== undefined) {\n if (typeof raw.bone !== 'string' || !byName.has(raw.bone)) problems.push(`${where}: bone is ${JSON.stringify(raw.bone)}, not a bone of this document`);\n else bone = raw.bone;\n }\n let property: TransformProperty = 'rotate';\n if (raw.property !== undefined) {\n const p = TRANSFORM_PROPERTIES.find((x) => x === raw.property);\n if (p === undefined) problems.push(`${where}: property is ${JSON.stringify(raw.property)}, none of ${TRANSFORM_PROPERTIES.join(', ')}`);\n else property = p;\n }\n num('max', 0);\n const loop = flag('loop');\n const setup = new Map<string, ModelBone>();\n for (const target of anim?.timelines.bones ?? []) {\n const b = byName.get(target.name);\n if (b !== undefined) setup.set(b.name, b);\n }\n const record: CoreSliderRecord = {\n kind: 'slider', name, animation: anim?.name ?? '', timelines: anim?.timelines ?? { declared: 0, duration: 0, bones: [], slots: [], later: [], attachments: [], drawOrder: [], events: [] }, physics: [], setup,\n additive: flag('additive'), loop, mix: num('mix', 1), time: num('time', 0), bone, property,\n from: num('from', 0), to: num('to', 0), scale: num('scale', 1), local: flag('local'), skin: flag('skin'), listedBySkin: false,\n };\n return problems.length === before ? record : undefined;\n}\n\n/**\n * The slider timelines of one animation record's `constraints.slider`, read:\n * each names a declared slider, each of its timelines is `time` or `mix` and\n * appears once, its keys strictly increase in time and carry `time`, `value`\n * and `curve` only.\n */\nexport function readSliderTimelines(value: unknown, label: string, declared: ReadonlyArray<{ kind: string; name: string }>, problems: string[]): CoreSliderTimeline[] {\n const out: CoreSliderTimeline[] = [];\n if (!Array.isArray(value)) return out;\n value.forEach((entry, i) => {\n const at = `${label}.constraints.slider[${i}]`;\n if (!isRecord(entry) || typeof entry.name !== 'string') {\n problems.push(`${at} names no slider`);\n return;\n }\n if (!declared.some((c) => c.kind === 'slider' && c.name === entry.name)) problems.push(`${at}: \"${entry.name}\" is not a slider of this document`);\n const tl: CoreSliderTimeline = { name: entry.name, time: null, mix: null };\n if (!Array.isArray(entry.timelines)) {\n problems.push(`${at}: timelines is not a list`);\n return;\n }\n entry.timelines.forEach((raw: unknown, j: number) => {\n const tat = `${at}.timelines[${j}]`;\n if (!isRecord(raw) || (raw.name !== 'time' && raw.name !== 'mix')) {\n problems.push(`${tat}: ${JSON.stringify(isRecord(raw) ? raw.name : raw)} is not a slider timeline; a slider keys time and mix`);\n return;\n }\n const which = raw.name;\n if (tl[which] !== null) problems.push(`${tat}: \"${which}\" is keyed twice on slider \"${entry.name}\"`);\n tl[which] = readKeys(raw.keys, `${tat} \"${which}\"`, problems);\n });\n out.push(tl);\n });\n return out;\n}\n\nfunction readKeys(value: unknown, at: string, problems: string[]): CoreKey[] {\n const keys: CoreKey[] = [];\n if (!Array.isArray(value) || value.length === 0) {\n problems.push(`${at}: keys is not a non-empty list`);\n return keys;\n }\n let last = -Infinity;\n value.forEach((k: unknown, j: number) => {\n const kat = `${at}.keys[${j}]`;\n if (!isRecord(k)) {\n problems.push(`${kat} is not an object`);\n return;\n }\n for (const key of Object.keys(k)) if (key !== 'time' && key !== 'value' && key !== 'curve') problems.push(`${kat}: field \"${key}\" is not one this reader knows; it reads [time, value, curve]`);\n const time = k.time;\n if (typeof time !== 'number' || !Number.isFinite(time) || time < 0) {\n problems.push(`${kat}: time is ${JSON.stringify(time)}, not a finite time at or after 0`);\n return;\n }\n if (time <= last) problems.push(`${kat}: time ${time} is not after the key before it — the writer refuses key times that do not strictly increase`);\n last = Math.max(last, time);\n let v = 1;\n if (k.value !== undefined) {\n if (typeof k.value !== 'number' || !Number.isFinite(k.value)) problems.push(`${kat}: value is ${JSON.stringify(k.value)}, not a finite number`);\n else v = k.value;\n }\n let curve: CoreCurve = 'linear';\n if (k.curve !== undefined) {\n if (j === value.length - 1) problems.push(`${kat}: the last key carries a curve, which eases to no key — the writer refuses it`);\n else if (k.curve === 'stepped') curve = 'stepped';\n else if (Array.isArray(k.curve) && k.curve.length === 4 && k.curve.every((n) => typeof n === 'number' && Number.isFinite(n))) curve = k.curve as number[];\n else problems.push(`${kat}: curve is ${JSON.stringify(k.curve)}, not \"stepped\" nor 4 finite numbers`);\n }\n keys.push({ time: Math.fround(time), values: [Math.fround(v)], stated: { time, values: [v] }, curve });\n });\n return keys;\n}\n\n/** What evaluates one channel of a key and finds the key — construct 4's unless a plant passes others. */\nexport interface SliderTimelinePlant {\n channel?: (keys: readonly CoreKey[], index: number, channel: number, t: number) => number;\n search?: (keys: readonly CoreKey[], t: number) => number;\n}\n\n/** A slider record with its timelines' `time` and `mix` at `t` in place of its own (the header's *Its timelines*). */\nexport function posedSlider(r: CoreSliderRecord, timelines: readonly CoreSliderTimeline[], t: number, plant: SliderTimelinePlant = {}): CoreSliderRecord {\n const tl = timelines.find((x) => x.name === r.name);\n if (tl === undefined) return r;\n const search = plant.search ?? keyIndexAt;\n const channel = plant.channel ?? channelAt;\n // Through the setup blend at alpha 1, `own + (value − own)·1` (issue #991), as the ik, transform and path timelines are: the value as keyed read 351 of 500 of the issue's scratch population bit-exact under --raw, the blend 500 (CZ03).\n const at = (keys: CoreKey[] | null, own: number): number => {\n if (keys === null) return own;\n const i = search(keys, t);\n return i < 0 ? own : own + (channel(keys, i, 0, t) - own) * 1;\n };\n return { ...r, time: at(tl.time, r.time), mix: at(tl.mix, r.mix) };\n}\n\n/** The time a slider applies its animation at (the header's rule), before the animation's own loop wrap. */\nexport function sliderTime(state: SolverState, r: CoreSliderRecord): number {\n if (r.bone === null) return r.time;\n const value = sourceValue(state, { source: r.bone, localSource: r.local, offsets: ZERO_OFFSETS }, r.property);\n const time = r.to + (value - r.from) * r.scale;\n const d = r.timelines.duration;\n // Looping over a duration of 0 is NaN in the runtime, and it applied the keys: every key of such an animation sits at 0.\n if (r.loop && d === 0) return 0;\n return r.loop ? d + (time % d) : Math.max(0, time);\n}\n\nconst ZERO_OFFSETS: Record<TransformProperty, number> = { rotate: 0, x: 0, y: 0, scaleX: 0, scaleY: 0, shearY: 0 };\n\n/** The channels of a timeline at `t`, or `null` before its first key — when a slider writes nothing. */\nfunction valuesAt(keys: readonly CoreKey[], t: number): number[] | null {\n const i = keyIndexAt(keys, t);\n if (i < 0) return null;\n return keys[i].values.map((_v, c) => channelAt(keys, i, c, t));\n}\n\n/**\n * Apply one slider to the solver's bones (the header's composition rules):\n * its local values move, and the bones written are returned for the update\n * loop to pose again with everything below them. The application is pushed\n * onto `applied` for the slots.\n */\nexport function applySlider(state: SolverState, r: CoreSliderRecord, applied?: SliderApplication[], physics?: SliderPhysicsTarget): string[] {\n if (r.mix === 0) return [];\n const time = sliderTime(state, r);\n const d = r.timelines.duration;\n const at = r.loop && d !== 0 ? time % d : time;\n applied?.push({ name: r.name, timelines: r.timelines, at, alpha: r.mix, additive: r.additive, time });\n const alpha = r.mix;\n if (physics !== undefined && state.rules.sliderWritesPhysics) applySliderPhysics(r, at, alpha, physics);\n const changed: string[] = [];\n for (const target of r.timelines.bones) {\n const index = state.index.get(target.name);\n const setup = r.setup.get(target.name);\n if (index === undefined || setup === undefined) continue;\n const b = state.bones[index];\n let wrote = false;\n for (const tl of target.timelines) {\n if (tl.kind === 'inherit') {\n const i = keyIndexAt(tl.keys, at);\n if (i < 0) continue;\n b.inheritMode = tl.keys[i].mode;\n wrote = true;\n continue;\n }\n const v = valuesAt(tl.keys, at);\n if (v === null) continue;\n wrote = true;\n const add = (field: 'x' | 'y' | 'rotation' | 'shearX' | 'shearY', i: number): void => {\n const current = b[field] ?? 0;\n b[field] = r.additive ? current + v[i] * alpha : current + ((setup[field] ?? 0) + v[i] - current) * alpha;\n };\n const times = (field: 'scaleX' | 'scaleY', i: number): void => {\n const current = b[field] ?? 1;\n const s = setup[field] ?? 1;\n if (r.additive) {\n // #989: the key's product with the setup less the setup, then the mix — `(v − 1)·setup·mix` reads last-bit off (CZ02).\n b[field] = state.rules.sliderAdditiveScaleProduct ? current + (v[i] * s - s) * alpha : current + (v[i] - 1) * s * alpha;\n return;\n }\n const target = s * v[i];\n // #989: at mix exactly 1 the target itself — `from + (target − from)·1` reads last-bit off (CZ02).\n if (alpha === 1 && state.rules.sliderScaleMixOneIsTarget) {\n b[field] = target;\n return;\n }\n const from = Math.abs(current) * Math.sign(target);\n b[field] = from + (target - from) * alpha;\n };\n switch (tl.kind) {\n case 'rotate': add('rotation', 0); break;\n case 'translate': add('x', 0); add('y', 1); break;\n case 'translatex': add('x', 0); break;\n case 'translatey': add('y', 0); break;\n case 'shear': add('shearX', 0); add('shearY', 1); break;\n case 'shearx': add('shearX', 0); break;\n case 'sheary': add('shearY', 0); break;\n case 'scale': times('scaleX', 0); times('scaleY', 1); break;\n case 'scalex': times('scaleX', 0); break;\n case 'scaley': times('scaleY', 0); break;\n }\n }\n // #989: a bone the animation keys is posed again whether or not a timeline wrote it (the header's update order).\n if (wrote || (state.rules.sliderReposesKeyedBones && target.timelines.length > 0)) changed.push(target.name);\n }\n return changed;\n}\n\n/** The physics records a stepped pass carries, by name — what a slider's physics timelines write and a later physics constraint steps with (issue #1049, the header's *Its physics timelines*). */\nexport interface SliderPhysicsTarget {\n records: Map<string, CorePhysicsRecord>;\n /** Each record's setup values, before the step's own animation — what a planted blend from the setup reads. */\n setup: ReadonlyMap<string, CorePhysicsRecord>;\n active: (r: CorePhysicsRecord) => boolean;\n rules: Readonly<SolverRules>;\n ctx: PhysicsStepContext;\n /** What the sliders wrote this pass, by constraint and field — kept only under the planted reading that a write outlasts its pass. */\n written: Map<string, Partial<Record<PhysicsField, number>>>;\n}\n\n/** The fields of a physics record a timeline writes. */\ntype PhysicsField = 'inertia' | 'strength' | 'damping' | 'massInverse' | 'wind' | 'gravity' | 'mix';\n\n/**\n * The physics records of one stepped pass, ready for the sliders to write\n * (issue #1049): every physics record as the step's own animation posed it.\n * Under the planted reading that a slider's write outlasts its pass, what\n * the sliders wrote on the step before stands wherever the step's own\n * animation does not key it (`PhysicsStepContext.keyedNow`).\n */\nexport function sliderPhysicsTarget(records: readonly CoreConstraintRecord[], active: ReadonlySet<string>, ctx: PhysicsStepContext, rules: Readonly<SolverRules>): SliderPhysicsTarget {\n const posed = new Map(records.flatMap((r): Array<[string, CorePhysicsRecord]> => (r.kind === 'physics' ? [[r.name, r]] : [])));\n const out = new Map(posed);\n const written = new Map<string, Partial<Record<PhysicsField, number>>>();\n if (!rules.sliderPhysicsLastsOnePass) {\n for (const [name, fields] of ctx.carried ?? new Map<string, Partial<Record<PhysicsField, number>>>()) {\n const r = out.get(name);\n if (r === undefined) continue;\n const next = { ...r };\n const kept: Partial<Record<PhysicsField, number>> = {};\n for (const [f, v] of Object.entries(fields) as Array<[PhysicsField, number]>) {\n if (ctx.keyedNow?.has(`${name}/${f}`)) continue;\n next[f] = v;\n kept[f] = v;\n }\n out.set(name, next);\n written.set(name, kept);\n }\n ctx.carried = written;\n }\n return { records: out, setup: ctx.setupRecords ?? posed, active: (r) => physicsActive(r, active), rules, ctx, written };\n}\n\n/** The value kinds a slider's physics timeline adds under `additive` (`./additive.ts`'s table); the rest write. */\nconst PHYSICS_ADDS: ReadonlySet<string> = new Set(['wind', 'gravity']);\n\n/** A slider's physics timelines applied at `at` with alpha `alpha` onto the pass's physics records (the header's *Its physics timelines*). */\nfunction applySliderPhysics(r: CoreSliderRecord, at: number, alpha: number, target: SliderPhysicsTarget): void {\n const rules = target.rules;\n for (const tl of r.physics) {\n const named = target.records.get(tl.name);\n const targets = tl.name === EVERY_GLOBAL_PHYSICS ? unnamedPhysicsTargets([...target.records.values()], tl.kind, target.active) : named !== undefined && target.active(named) ? [named] : [];\n if (tl.kind === 'reset') {\n // A slider applies its animation at one time, from that time: no key is crossed, so a reset key fires nothing (PS159).\n if (!rules.sliderPhysicsResetIsDead && tl.keys.some((k) => k.time <= at)) for (const p of targets) resetPhysicsState(physicsState(target.ctx, p.name), target.ctx.time);\n continue;\n }\n const i = keyIndexAt(tl.keys, at);\n if (i < 0) continue;\n const v = channelAt(tl.keys, i, 0, at);\n const adds = r.additive && (PHYSICS_ADDS.has(tl.kind) || !rules.sliderPhysicsAddsWindGravityOnly);\n for (const p of targets) {\n const from = rules.sliderPhysicsFromCurrent ? p : (target.setup.get(p.name) as CorePhysicsRecord);\n const next = { ...p };\n let field: PhysicsField;\n if (tl.kind === 'mass') {\n field = 'massInverse';\n if (rules.sliderPhysicsBlendsMass) {\n const m = 1 / from.massInverse;\n next.massInverse = 1 / (adds ? 1 / p.massInverse + v * alpha : m + (v - m) * alpha);\n } else next.massInverse = adds ? p.massInverse + (1 / v) * alpha : from.massInverse + (1 / v - from.massInverse) * alpha;\n } else {\n field = tl.kind;\n next[field] = adds ? p[field] + v * alpha : from[field] + (v - from[field]) * alpha;\n }\n target.records.set(p.name, next);\n if (!rules.sliderPhysicsLastsOnePass) target.written.set(p.name, { ...target.written.get(p.name), [field]: next[field] });\n }\n }\n}\n\n/** A slot's pose as the sliders move it: what it shows, its light colour and its dark colour (`null` when it states none). */\nexport interface SlotPoseState {\n placeholder: string | null;\n light: number[];\n dark: number[] | null;\n}\n\nconst clamp01 = (v: number): number => (v < 0 ? 0 : v > 1 ? 1 : v);\n/** Each colour timeline's channels, as indices into `light` (0–3) and `dark` (4–6). */\nconst COLOUR_CHANNELS: Record<string, readonly number[]> = { rgba: [0, 1, 2, 3], rgb: [0, 1, 2], alpha: [3], rgba2: [0, 1, 2, 3, 4, 5, 6], rgb2: [0, 1, 2, 4, 5, 6] };\n\n/** Every slider application's slot timelines on one slot, in order (the header's slot rules). */\nexport function applySliderSlots(slot: string, pose: SlotPoseState, applications: readonly SliderApplication[]): void {\n for (const app of applications) {\n for (const target of app.timelines.slots) {\n if (target.name !== slot) continue;\n for (const tl of target.timelines) {\n if (tl.kind === 'attachment') {\n const i = keyIndexAt(tl.keys, app.at);\n if (i >= 0) pose.placeholder = tl.keys[i].name ?? null;\n continue;\n }\n const v = valuesAt(tl.keys, app.at);\n if (v === null) continue;\n COLOUR_CHANNELS[tl.kind].forEach((at, i) => {\n // #969: at mix 1 the key's value itself, not `current + (v − current)·1`, which is last-bit off it (measured, below).\n if (at < 4) pose.light[at] = app.alpha === 1 ? clamp01(v[i]) : clamp01(pose.light[at] + (v[i] - pose.light[at]) * app.alpha);\n else if (pose.dark !== null) pose.dark[at - 4] = app.alpha === 1 ? clamp01(v[i]) : clamp01(pose.dark[at - 4] + (v[i] - pose.dark[at - 4]) * app.alpha);\n });\n }\n }\n }\n}\n\n/**\n * Why the document's bones cannot be posed because of a slider, or null: a\n * slider whose animation keys a constraint timeline other than physics, or\n * deforms a curve a path constraint walks (the header's *What is left out*),\n * named with the animation and the kinds or the attachments.\n */\nexport function sliderBonesWhy(doc: CompiledDocument): string | null {\n const found: string[] = [];\n for (const c of doc.constraints) {\n if (c.kind !== 'slider') continue;\n const anim = doc.animations.find((a) => a.name === c.animation);\n if (anim === undefined) continue;\n const k = anim.constraints;\n const sliderTimelines = k.slider.reduce((n, s) => n + (s.time === null ? 0 : 1) + (s.mix === null ? 0 : 1), 0);\n const paths = k.path.reduce((n, p) => n + [p.position, p.spacing, p.mix].filter((x) => x !== undefined).length, 0);\n const kinds = [k.ik.length > 0 ? 'ik' : null, k.transform.length > 0 ? 'transform' : null, paths > 0 ? 'path' : null, sliderTimelines > 0 ? 'slider' : null].filter((x): x is string => x !== null);\n if (kinds.length > 0) found.push(`slider \"${c.name}\" applies animation \"${c.animation}\", which keys ${kinds.join(', ')} constraint timelines — a slider writing a later constraint's pose is not posed by this cut`);\n // A path constraint walks its slot's curve as the constraints before it left it; a slider's deform of that curve is not measured (issue #955).\n const walked = doc.constraints.flatMap((p) => (p.record?.kind === 'path' ? [p.record.slot] : []));\n const deformsPath = anim.timelines.attachments.filter((a) => a.deform !== null && walked.includes(a.slot) && doc.skins.find((s) => s.name === a.skin)?.attachments[a.slot]?.[a.attachment]?.geometry?.kind === 'path');\n if (deformsPath.length > 0) found.push(`slider \"${c.name}\" applies animation \"${c.animation}\", which deforms walked path attachment(s) ${deformsPath.map((a) => `\"${a.skin}/${a.slot}/${a.attachment}\"`).join(', ')} — a slider's deform of a curve a path constraint walks is not posed by this cut`);\n }\n return found.length === 0 ? null : found.join('; ');\n}\n","/**\n * Construct 5 of the core, first cut (issue #938, step 2e-i of issue #380):\n * the update order, and the two constraint kinds that move bones only by\n * what the bones and their target say — `ik` and `transform` — at the setup\n * pose and at a sample time, with their timelines. The second cut (issue\n * #938, step 2e-ii) adds `path`, whose record, walk and solver are\n * `./constraints_path.ts`'s; the third cut (2e-iii) adds `physics` under\n * `Physics.none` (`./constraints_physics.ts`: it applies nothing) and\n * `slider` (`./constraints_slider.ts`); the fourth (issue #956, 2e-iv)\n * steps physics when `applyConstraints` is given a step context — the\n * constraint then moves its bone in world space and the bones below it are\n * posed again, as after a world-space transform. Each is one more step of the update\n * loop below, so every constraint kind is posed; what the core still cannot\n * pose exactly leaves the bones out by name (`constraintsAbsentWhy`).\n *\n * Every rule below was measured by posing hand-written skeletons through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13, `--skin all`,\n * `--physics none`) and comparing the core's rows at tolerance 0, most of them\n * with \"amplifier\" bones — a child a million units out along each axis of the\n * bone under test — so that a difference of 1e-12 in a matrix reads as one\n * grid step (the `CC` controls hold the populations at ten thousand units:\n * at a million a skewed chain's amplifier reached 1.7e9, where a double no\n * longer resolves the grid). Nothing here was written from the runtime's\n * source. The public\n * documentation fixes the order the constraints run in (the editor's list,\n * top first) and the shape of each solver; every numeric choice beyond that —\n * which frame, which wrap, which constant — is the measurement stated next to\n * it. The core suite's `CC` controls hold the hand-written probes, and\n * `tools/core_gate.ts` holds the corpus.\n *\n * ## The update order\n *\n * **Constraints run in the document's order** — the model lists them as the\n * rig declares them and the Spine file carries that order, which is the\n * runtime's constraint list (the oracle's `constraints` roster). After each\n * one, every bone below a bone it changed is posed again from its local\n * values under its parent's new world transform, so a later constraint reads\n * the bones as the earlier ones left them. Measured: 500 random nine-bone\n * rigs, each with two to six ik and transform constraints in random order,\n * random targets and sources, reflecting, sheared, non-normal and softened —\n * every one IDENTICAL at tolerance 0 (`CC05`). Swapping two constraints that\n * touch one chain moves the pose (`CC10`).\n *\n * - A constraint whose mix for a property is 0 does not touch that property,\n * and one that touches nothing leaves the bone and everything under it\n * exactly as they were — not re-posed from its local values. A transform\n * constraint driving `y` alone whose `mixY` is absent (the pose's initial\n * 0) re-posed its bone's children from lossy local values in the first\n * reading and was 4e-6 off; skipping it made the probe exact.\n * - **A bone a transform constraint moved in world space keeps that world\n * transform**, and its local values are re-derived from it at once\n * (`localFromWorld`, below), so that when a later constraint moves one of\n * its ancestors it follows from those. Measured: a transform setting a\n * child's world rotation, then an ik turning its parent by 90°, turned the\n * child with the parent (the child's world rotation 180°); in the other\n * order, 90°.\n * - **A slider poses again every bone its animation keys**, a timeline\n * before its first key included (issue #989, `./constraints_slider.ts`,\n * *Where it stands*): on a bone a transform moved in world space that\n * rebuilds the world from the read-back local values, which the runtime\n * does and keeping the world did not (`CZ01`).\n * - A constraint with `skin: true` is applied exactly when an APPLIED skin's\n * list for its kind names it (`listedBySkin`, set per skin view by\n * `underSkin` in `./index.ts`): under `--skin all` any skin's, under\n * `--skin <name>` that skin's alone — the default skin's list does not\n * count there. Measured for all five kinds (issue #932, which carries card\n * #961's fix): a skin-required ik, transform, path, physics and slider\n * constraint on a probe where applying it moves a bone, dumped under\n * `--skin all`, `default` and `s1` against the same constraint at mix 0 —\n * named by no list: inert under all three; named by `s1`'s list: applied\n * under `all` and `s1`, inert under `default`; named by the default skin's\n * list: applied under `all` and `default`, inert under `s1` — the same\n * nine readings for every kind, 45 in all (the core suite's `CN02`). A name filed under another kind's list\n * is refused by the runtime's loader (`Couldn't find IK constraint k for\n * skin s1.`), and by `readModel`. The rule this replaced — `skin: true`\n * never applied (2e-i) — was measured only on unlisted constraints; issue\n * #956 corrected it for physics first. An ik whose target is inactive is\n * not applied (measured on an ik with its target skin-required and named by\n * no skin: the bone did not turn), nor a transform whose source is; an ik\n * and a transform are applied to every bone they name, inactive ones\n * included (*Unposed bones and collapsed frames*, below); a path constraint is applied exactly when its\n * slot's bone is active (`./constraints_path.ts`, *Which constraints run*).\n * - A path constraint moves its bones in world space, as a world-space\n * transform does, and reads the bones as the earlier constraints left\n * them — except its slot bone's world, which the offset's sign reads as\n * the runtime last set it: its update order is built before it poses, and\n * a weighted path does not ask for its slot bone (`slotBonePlan`,\n * *Which slot bone* there). This is the one place the order the runtime\n * builds is observable: ik and transform ask for every bone they read.\n *\n * ## Unposed bones and collapsed frames (issue #979)\n *\n * A bone the posed skin leaves unposed — inactive, or below an inactive bone\n * — holds the zero matrix, so a constraint over it works in a collapsed\n * frame. The grid compare never reads such a bone (the oracle's\n * ill-conditioned rule, and a document spells `-0` as `0`), so every rule here\n * was measured through `tools/pose_oracle.ts unposed`, which compares those\n * rows by `Object.is`, and on posed \"reader\" bones that carry a bone's local\n * values through a local transform constraint. The rules, planted back one at\n * a time by the core suite's `CC13` and `CC14` (`SolverRules`):\n *\n * - **An ik frame of determinant at most 0.00001 is collapsed** — exactly\n * 0.00001 collapses, the next double above does not, on a posed parent\n * (`CC14`). A one-bone ik then reads the target at the frame's origin (the\n * offset `(0, 0)`, so `atan2` is 0): the bone turns to 0 less its `shearX`,\n * plus 180 when it reflects, and `compress` scales it by `mix` toward 0.\n * A two-bone ik reads its grandparent's inverse as zero, so the target and\n * the child's origin are both the grandparent frame's origin. Before this\n * the core divided by the determinant and wrote NaN into every field.\n * - **A one-bone ik under a `noRotationOrReflection` parent floors the\n * parent x axis's squared length at 0.00001** when it builds the conformal\n * frame (`k = |det| / max(0.00001, a² + c²)`): solving for the floor on\n * five parents whose x axes are under it read 1.0000000166e-5 on each, and\n * with 0.00001 written 432 of 432 probes over three modes, eight parent x\n * scales, three y scales, three rotations and with or without\n * `compress`/`stretch` read exact, where no floor read 33 off. `./world.ts`'s frame for the same mode has no floor.\n * - **`localFromWorld` under a collapsed parent** reads x and y as the\n * division leaves them (NaN or infinite), `scaleX` 0, `shearY` 0, `scaleY`\n * the y column's length (NaN) and `rotation` 0: a local x column that is not\n * above 0.0001 — NaN included — is collapsed, and a y column no longer than\n * 0.00001 reads `rotation` 0 when the x column is collapsed too, and\n * `shearY` 0 when it is not (measured by bisection: 1e-5 reads 0, the next\n * double above reads the column's angle).\n * - **A world-space `rotate` source negates the constraint's `rotation`\n * unless its determinant is above 0**: a source of determinant 0 negates it.\n * - **An inactive bone is not posed again** when a constraint moves a bone\n * above it — it keeps its zeros, or what a constraint wrote into them — and\n * the bones below it are posed again only when a constraint moved it\n * itself (a path on an inactive bone moves the bones below it; a transform\n * on its parent does not).\n * - **A transform constraint is applied when its source is active, to every\n * bone it names**: one inactive bone among them did not stop it moving a\n * posed one (the core skipped the whole constraint), and it wrote the\n * source's position into the inactive one.\n *\n * Under these, transform (six flag sets, five modes), path, physics (under\n * `none` and the step) and one- and two-bone ik over unposed bones, and iks\n * aimed at them, read every bone row equal to spine-core's, the sign of every\n * zero included (`CC13`).\n *\n * ⚠️ **What the runtime writes into an INACTIVE constrained bone depends on\n * the pass before.** An ik naming an inactive bone is applied by the runtime\n * reading that bone's ancestors before it brings them up to date in the pass\n * — the previous pass's worlds, or zeros on a fresh skeleton — and a\n * transform or path writing into an inactive bone starts from the world the\n * previous pass left in it (the runtime does not reset it). Measured by\n * posing one skeleton sample after sample, as the oracle's dump does, against\n * a fresh skeleton per sample: an ik on `arm, hand` with `arm` inactive, a\n * transform onto an inactive bone at mix 0.5, additive or at mix 1, and a\n * path at mix 0.5 each read differently at 4 of 5 sample times (the mix-1\n * transform at 1 of 5, by 2.4e-17 in a `worldX` of 5.8e-7). The runtime\n * disagrees with itself there, so there is no rule of the format to hold, and\n * the core poses as a function of the model, the skin and the time: it reads\n * this class as a fresh skeleton does, which is the runtime's own setup pose.\n * A transform or path writes into an inactive bone from zeros; an ik naming\n * an inactive bone reads the frame above its first bone as zeros unless the\n * pass has brought that bone up to date before the ik (`frameUpdatedBefore`,\n * the order `slotBonePlan` walks), and as posed otherwise. Held against the\n * fresh reading on every row, and against the sequential one wherever the\n * two agree (`CC13`; `pose_oracle unposed` classes the rest HISTORY by\n * measurement). An ik on `arm, hand` with its target under `arm`'s parent, or\n * after a transform on that parent, read no history at all.\n *\n * The render never reads an unposed bone (the seam's zero snapshot), so the\n * history reaches a picture only through a POSED bone that a constraint moves\n * while reading a bone the history reached — and that pose is refused by\n * name (`unposedLeakWhy`), which the render meets by falling back to\n * spine-core. The taint is by bone and by what the reader reads, its world\n * or its local values: measured on 48 writer-and-reader probes (`CC15`),\n * every one whose posed rows spine-core's two readings disagree on (14) is\n * refused, and 8 are refused where the reader reads a part of the bone the\n * history does not move — a refusal costs a named fallback, a miss a picture\n * that depends on which frame played before.\n *\n * ## Reading local values back from a world transform (`localFromWorld`)\n *\n * The runtime's re-derived values were read directly: a second transform\n * constraint with `localSource` reading the bone's `rotate`, `x`, `y`,\n * `scaleX`, `scaleY`, `shearY` onto an unrelated bone's `x` at scale 10000\n * gave each to 1e-10, and they agree with these rules on every probe:\n *\n * - `normal`: the local matrix is the parent's inverse (1 over its\n * determinant, multiplied in) times the world matrix, and the local\n * position the same inverse applied to the world origin's offset. Then\n * `scaleX` is the x column's length and `shearX` is 0; ⚠️ **a local x\n * column shorter than 0.0001 is read as `scaleX` 0**, `shearY` 0, `scaleY`\n * the y column's length and `rotation` the y column's angle less 90 —\n * measured on a column collapsed to 1.8e-6 by two `scaleX` properties, where\n * the runtime read `rotation` −248.958 (the unwrapped y angle less 90) and\n * `scaleX` 0. Otherwise `rotation` is the x column's angle, `scaleY` the y\n * column's length — NEGATIVE when the determinant is — and `shearY` the y\n * column's angle less `rotation + 90`, or less `rotation − 90` when the\n * determinant is negative, brought once into (−180, 180]. The negative\n * `scaleY` and the right angle taken off the other way are what reproduce\n * the runtime's ±2.66e-6° residual on a reflected bone: 138 of 400\n * reflected and sheared probes missed with a positive `scaleY`; turning the\n * y angle by 180 first agrees to 1e-10 and not to the bit (below).\n * - `onlyTranslation`: the world matrix is the local matrix.\n * - `noRotationOrReflection`: the local matrix is taken against the parent's\n * conformal matrix (the frame `./world.ts` builds for that mode), and the\n * parent's x-axis angle is added to the rotation.\n * - `noScale`, `noScaleOrReflection`: `rotation` is the angle of the parent's\n * inverse applied to the world x column; the frame the forward pose builds\n * from that rotation (`noScaleDirection` in `./world.ts`) is formed, both\n * world columns are read in it (flipped when the parent reflects, for\n * `noScale`), and that local matrix is decomposed with its x column's\n * angle — a residual of rounding — kept as `shearX`, and `shearY` measured\n * from 0, as the forward frame `frame(0, shearX, shearY, …)` reads them.\n *\n * Each of the five held on 300 probes at the million-unit amplifier: a world\n * edit on the bone, then a translation-only edit on its parent that makes the\n * bone re-posed from its re-derived values (`CC06`).\n *\n * ## To the bit (issue #966)\n *\n * Held against `pose_oracle.ts dump --raw` at tolerance 0 (the core suite's\n * `CR01`, the `CC` populations and seeds; the corpus through `core_gate\n * --raw`), these orders are the runtime's where the grid could not tell:\n *\n * - a one-bone ik accumulates the change from the bone's own angles first,\n * `−shearX − rotation + turn + atan2·DEG` (the target's direction first\n * read 53 of 600 random iks off);\n * - a two-bone ik takes the child's offset angle off in radians before\n * turning the change into degrees, `(a1 − offset)·DEG` (`a1·DEG −\n * offset·DEG` read 44 bone findings on `spineboy-pro` against 4);\n * - an ik timeline's keyed mix and softness reach the pose through the\n * setup blend, `setup + (value − setup)·1` (the value as keyed read a\n * Bézier-eased mix 2 ulp off on `spineboy-pro`'s jump);\n * - a world-space rotate turns the change in radians, wrapped at the\n * runtime's pi (the degree form read 113 bone findings on `spineboy-pro`\n * against 44);\n * - `localFromWorld` forms the inverse's entries before applying them, and\n * reads the shear as `yAngle − (rotation + 90)`;\n * - and, in the second cut (the band `CW` controls; each rule planted back to\n * the reading before it by a `SolverRules` flag), the three read-back forms\n * above — a reflected bone's shear as the y angle less `rotation − 90`\n * (`CW01`); `noRotationOrReflection`'s columns as `(pa·wa + pc·wc)·(1/(pa² +\n * pc²))` and `(pa·wc − pc·wa)·(1/|det|)` (`CW02`); the `noScale` modes read\n * in the frame of the rotation read first, the residual kept as `shearX`\n * (`CW03`) — which bring the read-back population from 164 to 400 of 400,\n * the update-order population from 389 to 400 and the stepped physics\n * population (`CR07`) from 140 to 150 of 150; an additive world-space\n * `shearY` as `(v + 90)·RAD − 90·RAD` (`CW04`: the transform population\n * from 865 to 900 of 900); a transform timeline's mixes through the setup\n * blend (`CW05`); and the two-bone ik over a parent whose scale is 0, below;\n * - and a path timeline's position, spacing and mixes through the setup blend\n * too (issue #984, `CY01`; *The timelines*, below), and a slider\n * timeline's `time` and `mix` (issue #991, `CZ03`).\n *\n * The local values were read to the bit rather than through the re-posed\n * world: a reader bone's `x` driven by a local transform from the bone's\n * `rotate`, `x`, `y`, `scaleX`, `scaleY` or `shearY` at scale 1 under the\n * root is the value itself in the raw dump. That separated a wrong local\n * value from a right one the forward pose reads differently — the `noScale`\n * modes' local values read bit-exact before their world did, which is how\n * the kept `shearX` was found.\n *\n * ## ik — one bone\n *\n * The bone turns so its x axis points at the target. With `v` the target in\n * the bone's parent frame:\n *\n * - `normal`, `noScale`, `noScaleOrReflection`: the parent's world matrix,\n * inverted by dividing by its determinant, applied to the target's offset\n * from the PARENT's world origin, less the bone's local `x`, `y`.\n * `onlyTranslation`: the target's offset from the bone's own world origin,\n * as it is. `noRotationOrReflection`: as `normal`, with the parent's\n * conformal matrix (x axis kept, y axis at 90° with length |det| / |x|) for\n * its matrix, and the parent's x-axis angle added to the angle. Each other\n * reading of that mode missed 14 to 200 of 300 probes; the offset from the\n * bone's own origin, for `normal`, is the same number up to rounding and\n * was exact on every random probe — ⚠️ but a target AT the bone's origin\n * has only rounding noise for a direction, and the runtime turned such a\n * bone to 56.56° where that reading read 30° (0.3345 off in `b`); the\n * parent-origin reading reproduces the noise exactly (`CC04`).\n * - The rotation it needs is `atan2(v)` less `shearX` less the current\n * rotation, plus 180 when `scaleX` is negative, brought once into\n * (−180, 180], times `mix`, added to the rotation.\n * - `compress` / `stretch`: with `len` the bone's `length` times `scaleX` and\n * `d` the length of `v` — of the world offset for the two `noScale` modes —\n * when `len` is above 0.00001 (issue #966, by bisection: 0.00001 exactly is\n * left alone and the double above is scaled; 0.0001, the reading before,\n * left every bone between the two unscaled) and the target is nearer (`compress`) or\n * farther (`stretch`), `scaleX` is multiplied by `(d / len − 1) · mix + 1`.\n * With `scaleY` `uniform` `scaleY` is multiplied by the same `s`; with\n * `volume` it is divided by `s`, except below 0.7 where it is divided by\n * `0.25 + s · 0.642857`. That constant is measured: a bone of `scaleY`\n * 100000 compressed to seven lengths read `(1/scaleY − 0.25) / s` =\n * 0.642857000 to nine places on every one, and the break is between 0.6999\n * and 0.7001.\n * - `mix` 0 leaves the bone alone.\n *\n * Measured: 1,000 random probes each over rotated, scaled, reflecting and\n * sheared parents and bones, all five inherit modes, `compress`, `stretch`,\n * the three `scaleY` modes and random `mix`, all exact (`CC02`).\n *\n * ## ik — two bones\n *\n * The public documentation: the second bone must be a child of the first;\n * the child's tip reaches the target; `bendPositive` picks the side;\n * `softness` slows the chain as it straightens; `stretch` scales it to reach.\n * Measured, in the parent's parent frame (the \"grandparent\", its world\n * matrix inverted by multiplying by 1 over its determinant):\n *\n * - **Either bone not `normal`: the constraint does nothing** (all four\n * other modes on each bone, 200 probes each).\n * - The parent keeps its shear. ⚠️ The public page says the parent's local\n * shear is set to 0; spine-core 4.3.13 keeps it (100 sheared probes: 100\n * off with the shear zeroed, 0 kept).\n * - **Uniform** when the parent's |scaleX| and |scaleY| differ by at most\n * 0.00001 — measured between 9.9e-6 (uniform) and 1.01e-5 (not), at scales\n * 0.5, 1 and 2. The public page's \"nonuniform\" was read as 0.0001 at first,\n * and a world-edited parent at 1.00005 went 2,261,052 units off at the\n * amplifier.\n * - The child's local `y` is set to 0 when the scale is not uniform or\n * `stretch` is on; otherwise it is kept, and it offsets the angles by\n * `atan2(y, x)` of the child's local position — unscaled.\n * - `l1` is the distance, in the grandparent frame, from the parent's local\n * origin to the child's world origin (that is, the parent's world matrix\n * applied to the child's local `x`, `y`); `l2` is the child's `length`\n * times |its scaleX|; the target is read in the same frame.\n * - **softness**: `s` = `softness` · |parent scaleX| · (|child scaleX| + 1) ·\n * 0.5; with `d` the target's distance and `sd = d − l1 − l2·|scaleX| + s`,\n * when `sd > 0` the target is drawn in toward the parent by\n * `(sd − s·(1 − q²)) / d` of itself, `q = min(1, sd / 2s) − 1`: the chain\n * reaches `d − sd²/4s` until `sd` is `2s`, and full length after. Measured\n * on a straight chain at eleven distances and two softnesses, then at the\n * amplifier: the fully softened chain is ill-conditioned (its bend is the\n * arc-cosine of 1 − a few ulp), and only this arithmetic, with the\n * subtraction in this order and the square root (not `hypot`) for `l1`,\n * read it exactly — 132, 102, 59 and 10 of 1,000 missed on the way.\n * - **Uniform**: the law of cosines, `cos = (d² − l1² − l2²) / (2·l1·l2)`\n * with `l2` scaled by |scaleX|; below −1 the bend is π·bend, above 1 it is\n * 0 and `stretch` multiplies the parent's `scaleX` (and `scaleY` for\n * `uniform`, divides it for `volume`) by `(d/(l1+l2) − 1)·mix + 1`. The\n * parent's angle is one `atan2` of the target turned back by the bend's\n * offset — the difference of two `atan2`s is off by 2π about 1 time in 30,\n * and 2π in the runtime's degrees is not 2π.\n * - **Not uniform**: the child's tip at `(X, Y)` in the parent's scaled frame\n * solves `(b² − a²)X² − 2b²·l1·X + b²·l1² + a²·d² − a²b² = 0`\n * (`a`, `b` = `l2` times |scaleX|, |scaleY|), solved the numerically stable\n * way and taking the root of smaller magnitude; when it has none, the\n * nearest reachable pose of the three candidates — folded, straight and the\n * ellipse's vertex — on the side of the midpoint of their squared reaches\n * the target is. The folded bend is π in the runtime's own π (3.1415927);\n * the parent's angle is here the DIFFERENCE of two `atan2`s.\n * - The parent's rotation is the angle less the offset, plus 180 when its\n * `scaleX` is negative, and the child's is `(bend + offset)·deg − shearX`,\n * times the product of the parent's scale signs, plus 180 when the child's\n * `scaleX` is negative. Each change is brought once into (−180, 180] —\n * **−180 goes to 180**: a folded chain under a reflecting parent read the\n * same child angle for both bends, measured at `mix` 0.5 — and multiplied\n * by `mix`.\n *\n * Measured: 2,000 random probes per combination — grandparents rotated,\n * scaled, reflecting and sheared; parents uniform, reflecting and not\n * uniform; children offset in `y`, scaled, reflecting and sheared; `stretch`,\n * `softness`, the `scaleY` modes, both bends, random `mix` — exact at the\n * amplifier (`CC03`). Degenerate cases (`CC04`): the child at the parent's\n * origin, the target at the parent's origin, the chain exactly straight,\n * exactly folded, the softness onset and its end, a child of length 0 — all\n * exact. The runtime throws on an ik whose (first) bone is the root, so the\n * reader refuses it. A collapsed grandparent (determinant 0) is left to the\n * oracle's ill-conditioned rule, which excludes the bone and everything below\n * it — the one case where the core's value is not the runtime's.\n *\n * **A parent whose scale is 0** (issue #966, reducing #959's third class, \"a\n * transform collapsing a bone's scale, with an ik below it\", to a two-bone ik\n * with no transform at all; `CW06`–`CW08`, compared by `Object.is` on every\n * bone, the ones compare's ill-conditioned rule leaves out included):\n *\n * - a scale of 0 counts as POSITIVE in the product of the parent's scale\n * signs that turns the child's offset and angle — `Math.sign` read it as 0\n * and read 59 of 300 iks over a parent of `scaleY` 0 exact;\n * - **a child whose origin is nearer the parent's than 0.00001** in the\n * grandparent frame (`l1`) makes the constraint a one-bone ik on the parent\n * — stretched as the constraint says, never compressed, its `scaleY` mode\n * read as none — with the child posed at rotation 0 and the local `y` the\n * solver set. A parent `scaleX` of 0 puts every child there (2 of 300\n * exact before). By bisection on the parent's x scale at three child\n * offsets and three rotations the edge is the distance, not the scale:\n * 0.00001 exactly solves and the double below folds (`CW07`). The child at\n * the parent's origin (`CC04`) is the same fold.\n *\n * ## transform\n *\n * 4.3's form: `properties` maps each source property (`rotate`, `x`, `y`,\n * `scaleX`, `scaleY`, `shearY`) with its `offset` to one or more target\n * properties, each with `offset`, `scale` and `max`. For each constrained\n * bone, each source property in the document's order, each target property:\n *\n * - **The source's value.** World (`localSource` false): `rotate` is the x\n * column's angle, plus the constraint's `rotation` — negated when the source\n * reflects — and then brought into [0, 360) by adding 360 once when below 0\n * (a scale of 0.5 read 95 for a source at −170); `x`, `y` are the source's\n * world transform applied to the constraint's `x`, `y`; `scaleX`, `scaleY`\n * the column lengths plus the constraint's offsets; `shearY` the angle\n * between the columns less 90, plus `shearY`. Local: the source's local\n * value (as constraints so far left it) plus the offset, unwrapped.\n * - Less the source property's `offset`, times the target property's `scale`\n * (absent 1), plus its `offset` (absent 0); with `clamp`, held between its\n * `offset` and its `max` whichever is larger — `max` absent reads 1 (a\n * clamped 30 read 1).\n * - **The mix** of the target property: `mixRotate`, `mixX`, `mixScaleX`,\n * `mixShearY` absent read 1 for a driven property; `mixY` absent reads the\n * resolved `mixX` when `x` is driven and 0 when it is not, `mixScaleY` the\n * same over `scaleX` (the parser's reading, `src/keyorder.ts`'s note on the\n * transform constraint, measured again here). A mix of 0 applies nothing.\n * - **World** (`localTarget` false): `rotate` turns both columns by the\n * change to the value (or by the value, `additive`) brought once into\n * (−180, 180] and times the mix; `x`, `y` move the world origin; `scaleX`,\n * `scaleY` scale a column to the value (or by it, additive: `1 + (v−1)·mix`);\n * `shearY` turns the y column to `v + 90` degrees from the x column, the\n * change brought once into (−π, π] with the RUNTIME's π (78 of 300 missed\n * with Math.PI), keeping its length — additive, it turns the y column by\n * `((v + 90)·RAD − 90·RAD)·mix`, unwrapped (issue #966, `CW04`: `v·RAD`\n * agrees on the grid and read 35 of 132 probes last-bit off). **Local**: the local field moves\n * toward the value by the mix (additive: adds `v·mix`, or scales by\n * `1 + (v−1)·mix`).\n *\n * Measured: 800 probes per property in world mode over reflecting, sheared,\n * offset, scaled and clamped sources and targets; 300 per property and mode\n * pair for local, additive and both; 1,000 with random cross-mappings (a\n * property to several, several to one); the six identity mappings in both\n * key orders — all exact, amplified (`CC07`). Every one on bones of all five\n * inherit modes.\n *\n * ## The timelines\n *\n * An `ik` timeline keys `mix` and `softness` (two curve channels) and\n * `bendPositive`, `compress`, `stretch` (stepped: the flags of the last key\n * at or before `t`); a `transform` timeline keys the six mixes (six\n * channels). The key search and the curves are construct 4's\n * (`keyIndexAt`, `channelAt` in `./animation.ts`), key times and values\n * float32, a Bézier from the stated numbers. Before the first key the\n * constraint's own values; a key omitting a field reads the parser's value\n * for it — `mix` 1, `softness` 0, `bendPositive` true, `compress` and\n * `stretch` false; a transform key's mixes 1, `mixY` the key's `mixX`\n * (`src/keyorder.ts`, `PARSER_DEFAULTS`). `CC08` holds each. The keyed values\n * reach the pose through the setup blend at alpha 1, `setup + (value −\n * setup)·1`, for both kinds (issue #966: the ik's mix on the corpus, the\n * transform's six mixes on `CW05`'s probe, where the value as keyed read 0\n * of 60 exact).\n *\n * A `path` timeline's values — `position`, `spacing` and the three mixes\n * (`./constraints_path.ts`, *The record and its timelines*) — reach the pose\n * through the same setup blend (issue #984). The reading before was the\n * value as keyed; the corpus could not tell them apart, since its one row\n * keying a path timeline keys `position` over a setup position of 0, where\n * `0 + (value − 0)·1` is the value to the bit. Measured on `CY01`'s probes —\n * 60 per timeline, keyed by Bézier segments over setup values that include 0\n * and negatives, in every position, spacing and rotate mode, one to three\n * bones, under `--raw` at 40 irrational samples, tolerance 0 — the value as\n * keyed read position 33, spacing 40 and mix 1 of 60 bit-exact (0 of 60 with\n * all three keyed), the blend 60 of 60 on each; each mix channel alone\n * planted back to the value as keyed turns the mix population red.\n *\n * A `slider` timeline's `time` and `mix` go through the same setup blend\n * (issue #991, `CZ03`; `./constraints_slider.ts`, *Its timelines*).\n *\n * ## Purity\n *\n * As the rest of the core: nothing from the Spine runtime package, nothing\n * from `src/transform.ts`, no clock, no randomness, no I/O.\n */\nimport type { ModelBone } from '../model.ts';\nimport { modeMatrix, noScaleDirection, RUNTIME_PI, worldTransforms, type CoreInheritMode, type CoreWorld } from './world.ts';\nimport { channelAt, keyIndexAt, type CoreCurve, type CoreKey } from './animation.ts';\nimport { activeBones, type CompiledDocument, type CoreConstraintKind } from './index.ts';\nimport { fillingSkins } from './skins.ts';\nimport { readPathTimelines, slotBonePlan, solvePath, type CorePathRecord, type CorePathTimelines, type SlotBoneEvent } from './constraints_path.ts';\nimport { physicsTimelineCount, readPhysicsTimelines, stepPhysics, type CorePhysicsRecord, type CorePhysicsTimeline, type PhysicsStepContext } from './constraints_physics.ts';\nimport { applySlider, posedSlider, sliderPhysicsTarget, readSliderTimelines, sliderBonesWhy, type CoreSliderRecord, type CoreSliderTimeline, type SliderApplication } from './constraints_slider.ts';\n\nconst DEG = 180 / RUNTIME_PI;\nconst RAD = RUNTIME_PI / 180;\n\n/** The kinds this cut poses. */\nexport const ADMITTED_CONSTRAINT_KINDS: readonly CoreConstraintKind[] = ['ik', 'transform', 'path', 'physics', 'slider'];\n\n/** A transform constraint's six properties, in the order its timeline's channels run. */\nexport const TRANSFORM_PROPERTIES = ['rotate', 'x', 'y', 'scaleX', 'scaleY', 'shearY'] as const;\nexport type TransformProperty = (typeof TRANSFORM_PROPERTIES)[number];\n/** The mix field of each property, in the same order. */\nexport const TRANSFORM_MIXES: Record<TransformProperty, string> = { rotate: 'mixRotate', x: 'mixX', y: 'mixY', scaleX: 'mixScaleX', scaleY: 'mixScaleY', shearY: 'mixShearY' };\n/** The constraint's offset field of each property. */\nconst TRANSFORM_OFFSETS: Record<TransformProperty, string> = { rotate: 'rotation', x: 'x', y: 'y', scaleX: 'scaleX', scaleY: 'scaleY', shearY: 'shearY' };\n/** The three `scaleY` modes an ik constraint names. */\nexport const IK_SCALE_Y_MODES = ['none', 'uniform', 'volume'] as const;\nexport type IkScaleYMode = (typeof IK_SCALE_Y_MODES)[number];\n\n/** The fields each admitted kind's record may carry after `kind`, `name`, `declaredIn` (`buildRigConstraint` in `src/compile.ts`). */\nexport const CONSTRAINT_FIELDS: Record<'ik' | 'transform', readonly string[]> = {\n ik: ['bones', 'target', 'scaleY', 'mix', 'softness', 'bendPositive', 'compress', 'stretch', 'skin'],\n transform: ['bones', 'source', 'properties', 'localSource', 'localTarget', 'additive', 'clamp', 'rotation', 'x', 'y', 'scaleX', 'scaleY', 'shearY', 'mixRotate', 'mixX', 'mixY', 'mixScaleX', 'mixScaleY', 'mixShearY', 'skin'],\n};\n\n/** The values an ik constraint's timeline keys, and a pose of them. */\nexport interface IkPose {\n mix: number;\n softness: number;\n bendPositive: boolean;\n compress: boolean;\n stretch: boolean;\n}\n\nexport interface CoreIkRecord extends IkPose {\n kind: 'ik';\n name: string;\n bones: string[];\n target: string;\n scaleY: IkScaleYMode;\n skin: boolean;\n /** An applied skin's `ik` list names it — what applies a skin-required one (the header's rule); set per skin view by `underSkin` in `./index.ts`. */\n listedBySkin: boolean;\n}\n\nexport interface CoreTransformTo {\n property: TransformProperty;\n offset: number;\n scale: number;\n max: number;\n}\n\nexport interface CoreTransformFrom {\n property: TransformProperty;\n offset: number;\n to: CoreTransformTo[];\n}\n\nexport interface CoreTransformRecord {\n kind: 'transform';\n name: string;\n bones: string[];\n source: string;\n properties: CoreTransformFrom[];\n localSource: boolean;\n localTarget: boolean;\n additive: boolean;\n clamp: boolean;\n /** The constraint's offsets: `rotation`, `x`, `y`, `scaleX`, `scaleY`, `shearY`, by the property they offset. */\n offsets: Record<TransformProperty, number>;\n /** The resolved mixes, by property — the header's reading of an absent one. */\n mixes: Record<TransformProperty, number>;\n skin: boolean;\n /** An applied skin's `transform` list names it (the header's rule); set per skin view by `underSkin` in `./index.ts`. */\n listedBySkin: boolean;\n}\n\nexport type CoreConstraintRecord = CoreIkRecord | CoreTransformRecord | CorePathRecord | CorePhysicsRecord | CoreSliderRecord;\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\nfunction unknownFields(record: Record<string, unknown>, known: readonly string[], where: string, problems: string[]): void {\n for (const key of Object.keys(record)) if (!known.includes(key)) problems.push(`${where}: field \"${key}\" is not one this reader knows; it reads [${known.join(', ')}]`);\n}\n\nfunction num(raw: Record<string, unknown>, key: string, dflt: number, where: string, problems: string[]): number {\n const v = raw[key];\n if (v === undefined) return dflt;\n if (typeof v !== 'number' || !Number.isFinite(v)) {\n problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a finite number`);\n return dflt;\n }\n return v;\n}\n\nfunction flag(raw: Record<string, unknown>, key: string, dflt: boolean, where: string, problems: string[]): boolean {\n const v = raw[key];\n if (v === undefined) return dflt;\n if (typeof v !== 'boolean') {\n problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a boolean`);\n return dflt;\n }\n return v;\n}\n\nfunction boneList(raw: Record<string, unknown>, bones: ReadonlySet<string>, where: string, problems: string[]): string[] {\n if (!Array.isArray(raw.bones) || raw.bones.length === 0) {\n problems.push(`${where}: bones is ${JSON.stringify(raw.bones)}, not a non-empty list of bone names`);\n return [];\n }\n const out: string[] = [];\n raw.bones.forEach((b, i) => {\n if (typeof b !== 'string' || !bones.has(b)) problems.push(`${where}: bones[${i}] ${JSON.stringify(b)} is not a bone of this document`);\n else out.push(b);\n });\n return out;\n}\n\nfunction boneRef(raw: Record<string, unknown>, key: string, bones: ReadonlySet<string>, where: string, problems: string[]): string {\n const v = raw[key];\n if (typeof v !== 'string' || !bones.has(v)) {\n problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a bone of this document`);\n return '';\n }\n return v;\n}\n\n/** The mix of `property` as the header reads an absent one. */\nfunction resolvedMix(raw: Record<string, unknown>, property: TransformProperty, driven: ReadonlySet<TransformProperty>, where: string, problems: string[]): number {\n const stated = raw[TRANSFORM_MIXES[property]];\n if (stated !== undefined) return num(raw, TRANSFORM_MIXES[property], 0, where, problems);\n if (property === 'y') return driven.has('x') ? resolvedMix(raw, 'x', driven, where, problems) : 0;\n if (property === 'scaleY') return driven.has('scaleX') ? resolvedMix(raw, 'scaleX', driven, where, problems) : 0;\n return driven.has(property) ? 1 : 0;\n}\n\n/**\n * An ik or transform constraint's record, read field by field — every field\n * the writer can write for its kind and no other, each of its type, every\n * bone named a bone of the document — or `undefined` with the problems named.\n * `bones` is the document's bone names; `parents` each bone's parent, for the\n * two refusals the runtime would otherwise throw on while posing.\n */\nexport function readConstraintRecord(raw: Record<string, unknown>, kind: 'ik' | 'transform', name: string, where: string, bones: ReadonlySet<string>, parents: ReadonlyMap<string, string | undefined>, problems: string[]): CoreConstraintRecord | undefined {\n const before = problems.length;\n const rest: Record<string, unknown> = { ...raw };\n delete rest.kind;\n delete rest.name;\n delete rest.declaredIn;\n unknownFields(rest, CONSTRAINT_FIELDS[kind], where, problems);\n const list = boneList(raw, bones, where, problems);\n const skin = flag(raw, 'skin', false, where, problems);\n if (kind === 'ik') {\n const target = boneRef(raw, 'target', bones, where, problems);\n if (list.length > 2) problems.push(`${where}: an ik constraint names ${list.length} bones; the format takes one or two`);\n if (list.length >= 1 && parents.get(list[0]) === undefined) problems.push(`${where}: its first bone \"${list[0]}\" is the root; spine-core throws posing an ik constraint on a bone with no parent`);\n if (list.length === 2 && parents.get(list[1]) !== list[0]) problems.push(`${where}: \"${list[1]}\" is not a child of \"${list[0]}\"; a two-bone ik needs the second bone directly under the first`);\n let scaleY: IkScaleYMode = 'none';\n if (raw.scaleY !== undefined) {\n const folded = typeof raw.scaleY === 'string' && raw.scaleY.length > 0 ? raw.scaleY[0].toLowerCase() + raw.scaleY.slice(1) : '';\n const mode = IK_SCALE_Y_MODES.find((m) => m === folded);\n if (mode === undefined) problems.push(`${where}: scaleY is ${JSON.stringify(raw.scaleY)}, none of ${IK_SCALE_Y_MODES.join(', ')}`);\n else scaleY = mode;\n }\n const record: CoreIkRecord = {\n kind, name, bones: list, target, scaleY, skin, listedBySkin: false,\n mix: num(raw, 'mix', 1, where, problems),\n softness: num(raw, 'softness', 0, where, problems),\n bendPositive: flag(raw, 'bendPositive', true, where, problems),\n compress: flag(raw, 'compress', false, where, problems),\n stretch: flag(raw, 'stretch', false, where, problems),\n };\n return problems.length === before ? record : undefined;\n }\n const source = boneRef(raw, 'source', bones, where, problems);\n const properties: CoreTransformFrom[] = [];\n const driven = new Set<TransformProperty>();\n if (raw.properties !== undefined && !isRecord(raw.properties)) problems.push(`${where}: properties is not an object`);\n else if (isRecord(raw.properties)) {\n for (const [fromName, fromRaw] of Object.entries(raw.properties)) {\n const at = `${where}.properties.${fromName}`;\n const from = TRANSFORM_PROPERTIES.find((p) => p === fromName);\n if (from === undefined) {\n problems.push(`${at}: \"${fromName}\" is none of ${TRANSFORM_PROPERTIES.join(', ')}`);\n continue;\n }\n if (!isRecord(fromRaw)) {\n problems.push(`${at} is not an object`);\n continue;\n }\n unknownFields(fromRaw, ['offset', 'to'], at, problems);\n const to: CoreTransformTo[] = [];\n if (!isRecord(fromRaw.to)) problems.push(`${at}: to is not an object`);\n else {\n for (const [toName, toRaw] of Object.entries(fromRaw.to)) {\n const at2 = `${at}.to.${toName}`;\n const property = TRANSFORM_PROPERTIES.find((p) => p === toName);\n if (property === undefined) {\n problems.push(`${at2}: \"${toName}\" is none of ${TRANSFORM_PROPERTIES.join(', ')}`);\n continue;\n }\n if (!isRecord(toRaw)) {\n problems.push(`${at2} is not an object`);\n continue;\n }\n unknownFields(toRaw, ['offset', 'scale', 'max'], at2, problems);\n to.push({ property, offset: num(toRaw, 'offset', 0, at2, problems), scale: num(toRaw, 'scale', 1, at2, problems), max: num(toRaw, 'max', 1, at2, problems) });\n driven.add(property);\n }\n }\n properties.push({ property: from, offset: num(fromRaw, 'offset', 0, at, problems), to });\n }\n }\n const offsets = {} as Record<TransformProperty, number>;\n const mixes = {} as Record<TransformProperty, number>;\n for (const p of TRANSFORM_PROPERTIES) {\n offsets[p] = num(raw, TRANSFORM_OFFSETS[p], 0, where, problems);\n mixes[p] = resolvedMix(raw, p, driven, where, problems);\n }\n const record: CoreTransformRecord = {\n kind, name, bones: list, source, properties, skin, listedBySkin: false, offsets, mixes,\n localSource: flag(raw, 'localSource', false, where, problems),\n localTarget: flag(raw, 'localTarget', false, where, problems),\n additive: flag(raw, 'additive', false, where, problems),\n clamp: flag(raw, 'clamp', false, where, problems),\n };\n return problems.length === before ? record : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// timelines\n// ---------------------------------------------------------------------------\n\n/** An ik key: `mix`, `softness` as channels, the three flags as the key states them or the parser reads them. */\nexport interface CoreIkKey extends CoreKey {\n flags: { bendPositive: boolean; compress: boolean; stretch: boolean };\n}\n\n/** One animation's ik, transform and path timelines, by constraint name, in the animation's order. */\nexport interface CoreConstraintTimelines {\n ik: Array<{ name: string; keys: CoreIkKey[] }>;\n transform: Array<{ name: string; keys: CoreKey[] }>;\n /** The path constraints' timelines (`./constraints_path.ts`). */\n path: CorePathTimelines[];\n /** How many physics timelines the animation holds — they pose nothing under `Physics.none` (`./constraints_physics.ts`). */\n physics: number;\n /** The physics timelines themselves, in the animation's order — what the stepped phase poses (`./constraints_physics.ts`). */\n physicsKeyed?: CorePhysicsTimeline[];\n /** The slider timelines (`./constraints_slider.ts`). */\n slider: CoreSliderTimeline[];\n}\n\n/** The ik key's curve channels, and the transform key's, in the order a curve indexes them. */\nexport const IK_KEY_CHANNELS = ['mix', 'softness'] as const;\nexport const TRANSFORM_KEY_CHANNELS = ['mixRotate', 'mixX', 'mixY', 'mixScaleX', 'mixScaleY', 'mixShearY'] as const;\n\nfunction keyCurve(raw: Record<string, unknown>, channels: number, last: boolean, at: string, problems: string[]): CoreCurve {\n const curve = raw.curve;\n if (curve === undefined) return 'linear';\n if (last) {\n problems.push(`${at}: the last key carries a curve, which eases to no key — the writer refuses it`);\n return 'linear';\n }\n if (curve === 'stepped') return 'stepped';\n if (!Array.isArray(curve) || curve.length !== channels * 4 || !curve.every((n) => typeof n === 'number' && Number.isFinite(n))) {\n problems.push(`${at}: curve is ${JSON.stringify(curve)}, not \"stepped\" nor ${channels * 4} finite numbers (four per channel)`);\n return 'linear';\n }\n return curve as number[];\n}\n\n/**\n * The ik, transform and path timelines of one animation record's\n * `constraints`, read: each names a declared constraint of its kind, its\n * keys strictly increase in time, each key carries only the fields the\n * parser reads for its kind (the path's, `readPathTimelines` in\n * `./constraints_path.ts`); the physics timelines are counted (they pose\n * nothing under `Physics.none`) and the slider timelines read by\n * `./constraints_slider.ts`.\n */\nexport function readConstraintTimelines(value: unknown, label: string, declared: ReadonlyArray<{ kind: CoreConstraintKind; name: string }>, problems: string[]): CoreConstraintTimelines {\n const out: CoreConstraintTimelines = { ik: [], transform: [], path: [], physics: 0, slider: [] };\n if (!isRecord(value)) return out;\n out.path = readPathTimelines(value.path, label, new Set(declared.filter((c) => c.kind === 'path').map((c) => c.name)), problems);\n out.physics = physicsTimelineCount(value.physics);\n out.physicsKeyed = readPhysicsTimelines(value.physics, label, new Set(declared.filter((c) => c.kind === 'physics').map((c) => c.name)), problems);\n out.slider = readSliderTimelines(value.slider, label, declared, problems);\n for (const kind of ['ik', 'transform'] as const) {\n const list = value[kind];\n if (!Array.isArray(list)) continue;\n list.forEach((entry, i) => {\n const at = `${label}.constraints.${kind}[${i}]`;\n if (!isRecord(entry) || typeof entry.name !== 'string') {\n problems.push(`${at} names no constraint`);\n return;\n }\n if (!declared.some((c) => c.kind === kind && c.name === entry.name)) problems.push(`${at}: \"${entry.name}\" is not a ${kind} constraint of this document`);\n const rawKeys: unknown = entry.keys;\n if (!Array.isArray(rawKeys) || rawKeys.length === 0) {\n problems.push(`${at}: keys is not a non-empty list`);\n return;\n }\n const channels: readonly string[] = kind === 'ik' ? IK_KEY_CHANNELS : TRANSFORM_KEY_CHANNELS;\n const known = kind === 'ik' ? ['time', ...IK_KEY_CHANNELS, 'bendPositive', 'compress', 'stretch', 'curve'] : ['time', ...TRANSFORM_KEY_CHANNELS, 'curve'];\n let last = -Infinity;\n const keys: CoreIkKey[] = [];\n rawKeys.forEach((k: unknown, j: number) => {\n const kat = `${at}.keys[${j}]`;\n if (!isRecord(k)) {\n problems.push(`${kat} is not an object`);\n return;\n }\n unknownFields(k, known, kat, problems);\n const time = k.time;\n if (typeof time !== 'number' || !Number.isFinite(time) || time < 0) {\n problems.push(`${kat}: time is ${JSON.stringify(time)}, not a finite time at or after 0`);\n return;\n }\n if (time <= last) problems.push(`${kat}: time ${time} is not after the key before it — the writer refuses key times that do not strictly increase`);\n last = Math.max(last, time);\n // The parser's reading of an absent field (`PARSER_DEFAULTS` in src/keyorder.ts): an ik key's mix 1, softness 0; a transform key's mixes 1 and its mixY its own mixX.\n const stated = channels.map((c) => {\n if (kind === 'transform' && c === 'mixY' && k.mixY === undefined) return num(k, 'mixX', 1, kat, problems);\n return num(k, c, c === 'softness' ? 0 : 1, kat, problems);\n });\n keys.push({\n time: Math.fround(time),\n values: stated.map(Math.fround),\n stated: { time, values: stated },\n curve: keyCurve(k, channels.length, j === rawKeys.length - 1, kat, problems),\n flags: { bendPositive: flag(k, 'bendPositive', true, kat, problems), compress: flag(k, 'compress', false, kat, problems), stretch: flag(k, 'stretch', false, kat, problems) },\n });\n });\n if (kind === 'ik') out.ik.push({ name: entry.name, keys });\n else out.transform.push({ name: entry.name, keys });\n });\n }\n return out;\n}\n\n/** What evaluates one channel of a constraint key, and finds the key — construct 4's unless a plant passes others. */\nexport interface ConstraintTimelinePlant {\n channel?: (keys: readonly CoreKey[], index: number, channel: number, t: number) => number;\n search?: (keys: readonly CoreKey[], t: number) => number;\n}\n\n/** Every admitted constraint record with its timeline's values at `t` in place of its own (the header's *The timelines*). */\nexport function posedRecords(records: readonly CoreConstraintRecord[], timelines: CoreConstraintTimelines | null, t: number, plant: ConstraintTimelinePlant = {}): CoreConstraintRecord[] {\n const search = plant.search ?? keyIndexAt;\n const channel = plant.channel ?? channelAt;\n return records.map((r): CoreConstraintRecord => {\n if (timelines === null || r.kind === 'physics') return r;\n if (r.kind === 'slider') return posedSlider(r, timelines.slider, t, plant);\n if (r.kind === 'path') {\n const tl = timelines.path.find((x) => x.name === r.name);\n if (tl === undefined) return r;\n const out = { ...r };\n for (const [kind, fields] of [['position', ['position']], ['spacing', ['spacing']], ['mix', ['mixRotate', 'mixX', 'mixY']]] as const) {\n const keys = tl[kind];\n if (keys === undefined) continue;\n const i = search(keys, t);\n if (i < 0) continue;\n // Through the setup blend at alpha 1 as well (issue #984): the value as keyed read position 33, spacing 40 and mix 1 of 60 Bézier-keyed probes bit-exact at 40 irrational samples, the blend 60 of each (CY01).\n fields.forEach((f, c) => (out[f] = r[f] + (channel(keys, i, c, t) - r[f]) * 1));\n }\n return out;\n }\n if (r.kind === 'ik') {\n const tl = timelines.ik.find((x) => x.name === r.name);\n if (tl === undefined) return r;\n const i = search(tl.keys, t);\n if (i < 0) return r;\n // The keyed values reach the pose through the setup blend at alpha 1, `setup + (value − setup)·1` (issue #966): the value as keyed agrees on the grid and reads off in the last bit — a Bézier-eased mix of 0.3899 on `spineboy-pro`'s jump moved its two-bone ik 2 ulp.\n return { ...r, mix: r.mix + (channel(tl.keys, i, 0, t) - r.mix) * 1, softness: r.softness + (channel(tl.keys, i, 1, t) - r.softness) * 1, ...tl.keys[i].flags };\n }\n const tl = timelines.transform.find((x) => x.name === r.name);\n if (tl === undefined) return r;\n const i = search(tl.keys, t);\n if (i < 0) return r;\n const mixes = {} as Record<TransformProperty, number>;\n // Through the setup blend at alpha 1 too (issue #966): on 60 probes keying all six mixes by Bézier segments over setup mixes in [−1, 2], sampled at 40 irrational times, the value as keyed read 0 bit-exact and the blend 60 (CW05).\n TRANSFORM_PROPERTIES.forEach((p, c) => (mixes[p] = r.mixes[p] + (channel(tl.keys, i, c, t) - r.mixes[p]) * 1));\n return { ...r, mixes };\n });\n}\n\n// ---------------------------------------------------------------------------\n// solving\n// ---------------------------------------------------------------------------\n\n/** A change brought once into (−180, 180] — the header's measured wrap (−180 goes to 180). */\nfunction wrap180(r: number): number {\n return r > 180 ? r - 360 : r <= -180 ? r + 360 : r;\n}\n\nconst IDENTITY: CoreWorld = { a: 1, b: 0, c: 0, d: 1, worldX: 0, worldY: 0 };\n\nfunction modeOf(bone: ModelBone): CoreInheritMode {\n const m = bone.inheritMode;\n if (m === undefined || m.length === 0) return 'normal';\n const folded = m[0].toLowerCase() + m.slice(1);\n return folded === 'onlyTranslation' || folded === 'noRotationOrReflection' || folded === 'noScale' || folded === 'noScaleOrReflection' ? folded : 'normal';\n}\n\n/**\n * The rules issue #979 measured on collapsed frames and on bones the posed\n * skin leaves unposed (the header's *Unposed bones and collapsed frames*),\n * as one object so that a control can plant each one back to the reading\n * before it (`CorePlant.solver`); nothing else passes another.\n */\nexport interface SolverRules {\n /** An ik frame whose determinant is at most this in magnitude is collapsed: a one-bone ik reads the target at the frame's origin, a two-bone ik reads its grandparent's inverse as zero. */\n ikCollapsedDet: number;\n /** A one-bone ik under a `noRotationOrReflection` parent: the floor under the parent x axis's squared length. */\n ikXAxisFloor: number;\n /** `localFromWorld`: a local x column that is not above 0.0001 — NaN included — reads as collapsed, and a y column no longer than 0.00001 reads rotation 0 (x collapsed too) or shearY 0. */\n readBackCollapsed: boolean;\n /** A world-space `rotate` source negates the constraint's `rotation` unless its determinant is above 0 — at 0 too. */\n offsetNegatedAtZeroDet: boolean;\n /** An inactive bone is never posed again, and the bones below it are posed again only when a constraint moved it. */\n inactiveHoldsItsWorld: boolean;\n /** A transform constraint is applied when its source is active, to every bone it names. */\n transformIgnoresBoneActivity: boolean;\n /** A pose in which a posed bone reads a bone whose value depends on the runtime's previous pass is refused by name (`unposedLeakWhy`). */\n refuseHistoryLeak: boolean;\n /** An ik naming an inactive bone is applied when its target is active, reading the frame above its first bone as a fresh skeleton holds it: zeros unless the pass brought that bone up to date before the ik (`frameUpdatedBefore`). */\n ikOverInactiveFresh: boolean;\n /** `localFromWorld`, a reflected local matrix: `shearY` is the y angle less `rotation − 90` (issue #966), not the y angle turned by 180 less `rotation + 90`. */\n readBackReflectedShear: boolean;\n /** `localFromWorld` in `noRotationOrReflection`: the conformal frame's inverse applied as the parent x axis over its squared length and its y axis over |det| (issue #966), not divided by the conformal determinant. */\n readBackConformalInverse: boolean;\n /** `localFromWorld` in the two `noScale` modes: the world columns read in the frame the forward pose builds from the rotation just read, the x column's residual angle kept as `shearX` (issue #966), not the x column's length with `shearX` 0. */\n readBackNoScaleFrame: boolean;\n /** An additive world-space `shearY`: `(v + 90)·RAD − 90·RAD` (issue #966), not `v·RAD`. */\n additiveShearRightAngle: boolean;\n /** A two-bone ik: a parent scale of 0 counts as positive in the product of the scale signs (issue #966), not as 0. */\n ikZeroScaleSignPositive: boolean;\n /** A one-bone ik compresses or stretches only a bone whose length times scaleX is above this (issue #966; the reading before, 0.0001, left bones between the two unscaled). */\n ikStretchMinLength: number;\n /** A two-bone ik whose child's origin is nearer the parent's than this, in the grandparent frame, is a one-bone ik on the parent with the child at rotation 0 (issue #966); negative, never. */\n ikTwoBoneNearChild: number;\n /** A slider poses again every bone its animation keys, whether or not a timeline wrote it — before its first key too (issue #989) — not only the bones a timeline wrote. */\n sliderReposesKeyedBones: boolean;\n /** A slider's additive scale key: `current + (v·setup − setup)·mix` (issue #989), not `current + (v − 1)·setup·mix`. */\n sliderAdditiveScaleProduct: boolean;\n /** A slider's scale key at mix exactly 1 writes `setup·v` itself (issue #989), not `from + (setup·v − from)·1`. */\n sliderScaleMixOneIsTarget: boolean;\n /**\n * Issue #1049, each the rule `./constraints_slider.ts` *Physics timelines* states — `false` (or the named reading)\n * plants the reading it rejected: a slider's physics keys write the pass's physics records (`false`: write nothing);\n * a non-additive one blends from the CURRENT value (`false`: from the setup value); only `wind` and `gravity` add\n * (`false`: every value kind adds); a `mass` key blends the mass (`false`: the inverse); the write lasts one pass\n * (`false`: what a slider wrote stands on the next step wherever the step's own animation does not key it); a\n * `reset` key fires nothing (`false`: a key at or before the slider's time resets its constraints on every pass).\n */\n sliderWritesPhysics: boolean;\n sliderPhysicsFromCurrent: boolean;\n sliderPhysicsAddsWindGravityOnly: boolean;\n sliderPhysicsBlendsMass: boolean;\n sliderPhysicsLastsOnePass: boolean;\n sliderPhysicsResetIsDead: boolean;\n}\n\n/** The runtime's rules, as measured. */\nexport const RUNTIME_SOLVER_RULES: Readonly<SolverRules> = {\n ikCollapsedDet: 0.00001,\n ikXAxisFloor: 0.00001,\n readBackCollapsed: true,\n offsetNegatedAtZeroDet: true,\n inactiveHoldsItsWorld: true,\n transformIgnoresBoneActivity: true,\n ikOverInactiveFresh: true,\n refuseHistoryLeak: true,\n readBackReflectedShear: true,\n readBackConformalInverse: true,\n readBackNoScaleFrame: true,\n additiveShearRightAngle: true,\n ikZeroScaleSignPositive: true,\n ikStretchMinLength: 0.00001,\n ikTwoBoneNearChild: 0.00001,\n sliderReposesKeyedBones: true,\n sliderAdditiveScaleProduct: true,\n sliderScaleMixOneIsTarget: true,\n sliderWritesPhysics: true,\n sliderPhysicsFromCurrent: true,\n sliderPhysicsAddsWindGravityOnly: true,\n sliderPhysicsBlendsMass: true,\n sliderPhysicsLastsOnePass: true,\n sliderPhysicsResetIsDead: true,\n};\n\n/** The runtime's rules with a plant's over them. */\nexport function solverRules(plant: Partial<SolverRules> | undefined): Readonly<SolverRules> {\n return plant === undefined ? RUNTIME_SOLVER_RULES : { ...RUNTIME_SOLVER_RULES, ...plant };\n}\n\n/** The runtime's `scaleY` for a bone an ik scaled by `s` along its length (the header's `volume` measurement). */\nfunction volumeScaleY(scaleY: number, s: number): number {\n return scaleY / (s < 0.7 ? 0.25 + s * 0.642857 : s);\n}\n\n/** The state the solvers work on: every bone's local values, its world transform, and which bones are active. */\nexport interface SolverState {\n bones: ModelBone[];\n index: Map<string, number>;\n world: Map<string, CoreWorld>;\n active: ReadonlySet<string>;\n /** `RUNTIME_SOLVER_RULES` unless a plant passes others. */\n rules: Readonly<SolverRules>;\n}\n\nfunction bone(state: SolverState, name: string): ModelBone {\n return state.bones[state.index.get(name) as number];\n}\n\nfunction parentWorld(state: SolverState, b: ModelBone): CoreWorld {\n return b.parent === undefined ? IDENTITY : (state.world.get(b.parent) as CoreWorld);\n}\n\n/** One bone's world transform from its local values under its parent's current world transform — `./world.ts`'s arithmetic. */\nfunction poseBone(state: SolverState, b: ModelBone): void {\n // An inactive bone is not posed again: it keeps its zeros, or what a constraint wrote into them (issue #979).\n if (!state.active.has(b.name)) {\n if (!state.rules.inactiveHoldsItsWorld) state.world.set(b.name, { a: 0, b: 0, c: 0, d: 0, worldX: 0, worldY: 0 });\n return;\n }\n if (b.parent === undefined) {\n state.world.set(b.name, worldTransforms([b]).get(b.name) as CoreWorld);\n return;\n }\n const p = state.world.get(b.parent) as CoreWorld;\n const [a, bb, c, d] = modeMatrix(modeOf(b), p, b);\n const x = b.x ?? 0;\n const y = b.y ?? 0;\n state.world.set(b.name, { a, b: bb, c, d, worldX: p.a * x + p.b * y + p.worldX, worldY: p.c * x + p.d * y + p.worldY });\n}\n\n/** The bone's local values read back from its world transform — the header's `localFromWorld`. */\nexport function localFromWorld(b: ModelBone, p: CoreWorld, w: CoreWorld, rules: Readonly<SolverRules> = RUNTIME_SOLVER_RULES): void {\n const mode = b.parent === undefined ? 'normal' : modeOf(b);\n const pid = 1 / (p.a * p.d - p.b * p.c);\n const dx = w.worldX - p.worldX;\n const dy = w.worldY - p.worldY;\n // The inverse's entries are formed first, then applied (issue #966): `dx·d·pid` reads last-bit off where `dx·(d·pid)` does not.\n b.x = dx * (p.d * pid) - dy * (p.b * pid);\n b.y = dy * (p.a * pid) - dx * (p.c * pid);\n b.shearX = 0;\n if (mode === 'noScale' || mode === 'noScaleOrReflection') {\n const det = p.a * p.d - p.b * p.c;\n const flip = mode === 'noScale' && det < 0 ? -1 : 1;\n if (!rules.readBackNoScaleFrame) {\n // The reading before issue #966's second cut, kept for the control that plants it back (CW03).\n const length = Math.sqrt(w.a * w.a + w.c * w.c);\n const [ux, uy] = [w.a / length, w.c / length];\n decompose(b, length, 0, ux * w.b + uy * w.d, (ux * w.d - uy * w.b) * flip, rules);\n b.rotation = Math.atan2((uy * p.a - ux * p.c) / det, (ux * p.d - uy * p.b) / det) * DEG;\n return;\n }\n // The rotation first: the angle of the parent's adjugate applied to the world x column, both parts negated when the parent reflects (issue #966).\n const sign = det < 0 ? -1 : 1;\n const rotation = Math.atan2((p.a * w.c - p.c * w.a) * sign, (p.d * w.a - p.b * w.c) * sign) * DEG;\n // Then the frame the forward pose builds from that rotation, and the world columns read in it — its transpose, flipped for noScale under a reflecting parent.\n const [ux, uy] = noScaleDirection([p.a, p.b, p.c, p.d], rotation);\n decompose(b, ux * w.a + uy * w.c, (ux * w.c - uy * w.a) * flip, ux * w.b + uy * w.d, (ux * w.d - uy * w.b) * flip, rules, 'shearX');\n b.rotation = rotation;\n return;\n }\n let la: number;\n let lb: number;\n let lc: number;\n let ld: number;\n if (mode === 'onlyTranslation') {\n [la, lb, lc, ld] = [w.a, w.b, w.c, w.d];\n } else if (mode === 'noRotationOrReflection') {\n if (rules.readBackConformalInverse) {\n // The conformal frame's inverse as its axes over their lengths (issue #966): the x axis over its squared length, the y axis over |det|, each reciprocal multiplied in.\n const xLengthInverse = 1 / (p.a * p.a + p.c * p.c);\n const detInverse = 1 / Math.abs(p.a * p.d - p.b * p.c);\n [la, lb, lc, ld] = [(p.a * w.a + p.c * w.c) * xLengthInverse, (p.a * w.b + p.c * w.d) * xLengthInverse, (p.a * w.c - p.c * w.a) * detInverse, (p.a * w.d - p.c * w.b) * detInverse];\n } else {\n // The reading before issue #966's second cut, kept for the control that plants it back (CW02).\n const k = Math.abs(p.a * p.d - p.b * p.c) / (p.a * p.a + p.c * p.c);\n const [ca, cb, cc, cd] = [p.a, -p.c * k, p.c, p.a * k];\n const cdet = ca * cd - cb * cc;\n [la, lb, lc, ld] = [(cd * w.a - cb * w.c) / cdet, (cd * w.b - cb * w.d) / cdet, (ca * w.c - cc * w.a) / cdet, (ca * w.d - cc * w.b) / cdet];\n }\n decompose(b, la, lc, lb, ld, rules);\n b.rotation = (b.rotation ?? 0) + Math.atan2(p.c, p.a) * DEG;\n return;\n } else {\n const [ia, ib, ic, id] = [p.d * pid, p.b * pid, p.c * pid, p.a * pid];\n [la, lb, lc, ld] = [ia * w.a - ib * w.c, ia * w.b - ib * w.d, id * w.c - ic * w.a, id * w.d - ic * w.b];\n }\n decompose(b, la, lc, lb, ld, rules);\n}\n\n/**\n * A local matrix `[la lb; lc ld]` (columns `(la, lc)` and `(lb, ld)`) as rotation, scales and shears — the header's rule.\n * `xAngleIn` says which field takes the x column's angle: `rotation` (every mode but the two `noScale` ones), or `shearX`\n * — the two `noScale` modes, whose rotation is read first (issue #966: the runtime keeps the residual angle of the x\n * column, in the frame built from that rotation, as `shearX`, and measures `shearY` from 0, as the forward frame\n * `frame(0, shearX, shearY, …)` reads them).\n */\nfunction decompose(b: ModelBone, la: number, lc: number, lb: number, ld: number, rules: Readonly<SolverRules>, xAngleIn: 'rotation' | 'shearX' = 'rotation'): void {\n const sx = Math.sqrt(la * la + lc * lc);\n const yLength = Math.sqrt(lb * lb + ld * ld);\n // Not above the bound, NaN included (issue #979: a collapsed parent's inverse is NaN, and the runtime reads scaleX 0 and shearY 0 from it); a y column no longer than 0.00001 reads rotation 0.\n if (rules.readBackCollapsed ? !(sx > 0.0001) : sx <= 0.0001) {\n b.scaleX = 0;\n b.scaleY = yLength;\n b.shearY = 0;\n b.rotation = !rules.readBackCollapsed || yLength > 0.00001 ? Math.atan2(ld, lb) * DEG - 90 : 0;\n return;\n }\n const xAngle = Math.atan2(lc, la) * DEG;\n const det = la * ld - lb * lc;\n let yAngle = Math.atan2(ld, lb) * DEG;\n if (xAngleIn === 'rotation') b.rotation = xAngle;\n else b.shearX = xAngle;\n b.scaleX = sx;\n b.scaleY = det < 0 ? -yLength : yLength;\n // The inverse of the forward frame's `rotation + 90 + shearY` (issue #966): the y angle less `rotation + 90`, or, when the determinant is negative (the\n // reflection carried by the negative scaleY), less `rotation − 90` — the reading before turned the y angle by 180 first and then took `rotation + 90` off.\n const from = xAngleIn === 'rotation' ? xAngle : 0;\n let right = 90;\n if (det < 0) {\n if (rules.readBackReflectedShear) right = -90;\n else yAngle += 180;\n }\n let shear = yAngle - (from + right);\n shear = shear > 180 ? shear - 360 : shear < -180 ? shear + 360 : shear;\n // A y column no longer than 0.00001 reads shearY 0 (issue #979), as it reads rotation 0 when the x column is collapsed too.\n b.shearY = !rules.readBackCollapsed || yLength > 0.00001 ? shear : 0;\n}\n\n/** A one-bone ik (the header's *ik — one bone*): returns the bone changed, or none. */\nfunction solveOne(state: SolverState, c: CoreIkRecord, frame: CoreWorld | null = null): string[] {\n const b = bone(state, c.bones[0]);\n const p = frame ?? parentWorld(state, b);\n const bw = state.world.get(b.name) as CoreWorld;\n const t = state.world.get(c.target) as CoreWorld;\n const mode = modeOf(b);\n let [pa, pb, pc, pd] = [p.a, p.b, p.c, p.d];\n let turn = 0;\n let lx: number;\n let ly: number;\n if (mode === 'noRotationOrReflection') {\n // The x axis's squared length is floored here (issue #979, `ikXAxisFloor`) — not in `./world.ts`'s frame for the same mode.\n const k = Math.abs(pa * pd - pb * pc) / Math.max(state.rules.ikXAxisFloor, pa * pa + pc * pc);\n pb = -pc * k;\n pd = pa * k;\n turn = Math.atan2(pc, pa) * DEG;\n const det = pa * pd - pb * pc;\n const x = t.worldX - p.worldX;\n const y = t.worldY - p.worldY;\n [lx, ly] = Math.abs(det) <= state.rules.ikCollapsedDet ? [0, 0] : [(x * pd - y * pb) / det - (b.x ?? 0), (y * pa - x * pc) / det - (b.y ?? 0)];\n } else {\n if (mode === 'onlyTranslation') {\n lx = t.worldX - bw.worldX;\n ly = t.worldY - bw.worldY;\n } else {\n const det = pa * pd - pb * pc;\n const x = t.worldX - p.worldX;\n const y = t.worldY - p.worldY;\n [lx, ly] = Math.abs(det) <= state.rules.ikCollapsedDet ? [0, 0] : [(x * pd - y * pb) / det - (b.x ?? 0), (y * pa - x * pc) / det - (b.y ?? 0)];\n }\n }\n const rotation = b.rotation ?? 0;\n const scaleX = b.scaleX ?? 1;\n // Accumulated from the bone's own angles first and the target's direction last (issue #966): `atan2·DEG − shearX − rotation + turn` agrees on the grid and reads last-bit off on 53 of 600 random one-bone iks, this order on none.\n let r = -(b.shearX ?? 0) - rotation + turn + Math.atan2(ly, lx) * DEG;\n if (scaleX < 0) r += 180;\n b.rotation = rotation + wrap180(r) * c.mix;\n const len = (b.length ?? 0) * scaleX;\n if ((c.compress || c.stretch) && len > state.rules.ikStretchMinLength) {\n const wx = t.worldX - bw.worldX;\n const wy = t.worldY - bw.worldY;\n const d = mode === 'noScale' || mode === 'noScaleOrReflection' ? Math.sqrt(wx * wx + wy * wy) : Math.sqrt(lx * lx + ly * ly);\n if ((c.compress && d < len) || (c.stretch && d > len)) {\n const s = (d / len - 1) * c.mix + 1;\n b.scaleX = scaleX * s;\n if (c.scaleY === 'uniform') b.scaleY = (b.scaleY ?? 1) * s;\n else if (c.scaleY === 'volume') b.scaleY = volumeScaleY(b.scaleY ?? 1, s);\n }\n }\n return [b.name];\n}\n\n/** A two-bone ik (the header's *ik — two bones*): returns the parent changed (the child is below it), or none. */\nfunction solveTwo(state: SolverState, c: CoreIkRecord, frame: CoreWorld | null = null): string[] {\n const parent = bone(state, c.bones[0]);\n const child = bone(state, c.bones[1]);\n if (modeOf(parent) !== 'normal' || modeOf(child) !== 'normal') return [];\n const g = frame ?? parentWorld(state, parent);\n const pw = state.world.get(parent.name) as CoreWorld;\n const t = state.world.get(c.target) as CoreWorld;\n const gdet = g.a * g.d - g.b * g.c;\n // A collapsed grandparent frame (issue #979): its inverse reads as zero, so every point in it is its origin.\n const gid = Math.abs(gdet) <= state.rules.ikCollapsedDet ? 0 : 1 / gdet;\n const inGrand = (wx: number, wy: number): [number, number] => {\n const x = wx - g.worldX;\n const y = wy - g.worldY;\n return [(x * g.d - y * g.b) * gid, (y * g.a - x * g.c) * gid];\n };\n const px = parent.x ?? 0;\n const py = parent.y ?? 0;\n const psx = parent.scaleX ?? 1;\n const psy = parent.scaleY ?? 1;\n const csx = child.scaleX ?? 1;\n let sx = psx;\n let sy = psy;\n const cx = child.x ?? 0;\n let cy = child.y ?? 0;\n const uniform = Math.abs(Math.abs(psx) - Math.abs(psy)) <= 0.00001;\n if (!uniform || c.stretch) cy = 0;\n const [ox, oy] = inGrand(pw.a * cx + pw.b * cy + pw.worldX, pw.c * cx + pw.d * cy + pw.worldY);\n const dx = ox - px;\n const dy = oy - py;\n const l1 = Math.sqrt(dx * dx + dy * dy);\n let l2 = (child.length ?? 0) * Math.abs(csx);\n // The child's origin nearer the parent's than 0.00001 in the grandparent frame (issue #966): the constraint turns the parent as a one-bone ik would,\n // stretching it but neither compressing it nor scaling its y (its `scaleY` mode read as none), and poses the child at rotation 0 with the local y the solver set. Measured on parents whose x scale is 0 (CW06), and by bisection\n // on the x scale at three child offsets and three rotations: an l1 of exactly 0.00001 solves, the double below folds.\n if (l1 < state.rules.ikTwoBoneNearChild) {\n solveOne(state, { ...c, bones: [parent.name], compress: false, scaleY: 'none' }, frame);\n child.rotation = 0;\n child.y = cy;\n return [parent.name];\n }\n let [tx, ty] = inGrand(t.worldX, t.worldY);\n tx -= px;\n ty -= py;\n let d2 = tx * tx + ty * ty;\n const bend = c.bendPositive ? 1 : -1;\n if (c.softness !== 0) {\n const soft = c.softness * (Math.abs(psx) * (Math.abs(csx) + 1) * 0.5);\n const d = Math.sqrt(d2);\n const sd = d - l1 - l2 * Math.abs(psx) + soft;\n if (sd > 0) {\n const q = Math.min(1, sd / (soft * 2)) - 1;\n const pull = (sd - soft * (1 - q * q)) / d;\n tx -= pull * tx;\n ty -= pull * ty;\n d2 = tx * tx + ty * ty;\n }\n }\n let a1: number;\n let a2: number;\n if (uniform) {\n l2 *= Math.abs(psx);\n let cos = (d2 - l1 * l1 - l2 * l2) / (2 * l1 * l2);\n if (cos < -1) {\n cos = -1;\n a2 = Math.PI * bend;\n } else if (cos > 1) {\n cos = 1;\n a2 = 0;\n if (c.stretch) {\n const f = (Math.sqrt(d2) / (l1 + l2) - 1) * c.mix + 1;\n sx *= f;\n if (c.scaleY === 'uniform') sy *= f;\n else if (c.scaleY === 'volume') sy = volumeScaleY(sy, f);\n }\n } else a2 = Math.acos(cos) * bend;\n const along = l1 + l2 * cos;\n const across = l2 * Math.sin(a2);\n a1 = Math.atan2(ty * along - tx * across, tx * along + ty * across);\n } else {\n const ea = Math.abs(psx) * l2;\n const eb = Math.abs(psy) * l2;\n const aa = ea * ea;\n const bb = eb * eb;\n const qa = bb - aa;\n const qb = -2 * bb * l1;\n const qc = bb * l1 * l1 + aa * d2 - aa * bb;\n const disc = qb * qb - 4 * qa * qc;\n let solved = false;\n a1 = 0;\n a2 = 0;\n if (disc >= 0) {\n let q = Math.sqrt(disc);\n if (qb < 0) q = -q;\n q = -(qb + q) * 0.5;\n const r0 = q / qa;\n const r1 = qc / q;\n const X = Math.abs(r0) < Math.abs(r1) ? r0 : r1;\n const y2 = d2 - X * X;\n if (y2 >= 0) {\n const Y = Math.sqrt(y2) * bend;\n a1 = Math.atan2(ty, tx) - Math.atan2(Y, X);\n a2 = Math.atan2(Y / Math.abs(psy), (X - l1) / Math.abs(psx));\n solved = true;\n }\n }\n if (!solved) {\n let near = { angle: RUNTIME_PI, x: l1 - ea, y: 0, dist: (l1 - ea) * (l1 - ea) };\n let far = { angle: 0, x: l1 + ea, y: 0, dist: (l1 + ea) * (l1 + ea) };\n const vertex = (-ea * l1) / (aa - bb);\n if (vertex >= -1 && vertex <= 1) {\n const angle = Math.acos(vertex);\n const x = ea * Math.cos(angle) + l1;\n const y = eb * Math.sin(angle);\n const dist = x * x + y * y;\n if (dist < near.dist) near = { angle, x, y, dist };\n if (dist > far.dist) far = { angle, x, y, dist };\n }\n const pick = d2 <= (near.dist + far.dist) * 0.5 ? near : far;\n a1 = Math.atan2(ty, tx) - Math.atan2(pick.y * bend, pick.x);\n a2 = pick.angle * bend;\n }\n }\n // A scale of 0 counts as positive (issue #966): `Math.sign` read 0 for it and zeroed both offsets and the child's angle — 59 of 300 two-bone iks over a parent of scaleY 0 exact, against 300 (CW06).\n const signs = state.rules.ikZeroScaleSignPositive ? (psx < 0 ? -1 : 1) * (psy < 0 ? -1 : 1) : Math.sign(psx) * Math.sign(psy);\n const offset = Math.atan2(cy, cx);\n // The child's offset angle is taken off in radians before the change is turned into degrees (issue #966): `a1·DEG − offset·DEG` agrees on the grid and reads 1–4 ulp off on `spineboy-pro`'s two-bone iks (44 bone findings of a raw compare against 4, the four the ik mix's setup blend below).\n const parentRotation = parent.rotation ?? 0;\n const parentChange = (a1 - signs * offset) * DEG + (psx < 0 ? 180 : 0) - parentRotation;\n parent.rotation = parentRotation + wrap180(parentChange) * c.mix;\n parent.scaleX = sx;\n parent.scaleY = sy;\n const childTarget = ((a2 + signs * offset) * DEG - (child.shearX ?? 0)) * signs + (csx < 0 ? 180 : 0);\n const childRotation = child.rotation ?? 0;\n child.y = cy;\n child.rotation = childRotation + wrap180(childTarget - childRotation) * c.mix;\n return [parent.name];\n}\n\n/** The source's value of `property` (the header's *transform*); a slider reads its dial through it with no offset. */\nexport function sourceValue(state: SolverState, c: Pick<CoreTransformRecord, 'source' | 'localSource' | 'offsets'>, property: TransformProperty): number {\n const s = bone(state, c.source);\n const o = c.offsets;\n if (c.localSource) {\n switch (property) {\n case 'rotate': return (s.rotation ?? 0) + o.rotate;\n case 'x': return (s.x ?? 0) + o.x;\n case 'y': return (s.y ?? 0) + o.y;\n case 'scaleX': return (s.scaleX ?? 1) + o.scaleX;\n case 'scaleY': return (s.scaleY ?? 1) + o.scaleY;\n case 'shearY': return (s.shearY ?? 0) + o.shearY;\n }\n }\n const w = state.world.get(c.source) as CoreWorld;\n switch (property) {\n case 'rotate': {\n // The offset is negated unless the determinant is above 0 — a collapsed source (determinant 0, issue #979) negates it too.\n const det = w.a * w.d - w.b * w.c;\n let r = Math.atan2(w.c, w.a) * DEG + ((state.rules.offsetNegatedAtZeroDet ? det > 0 : det >= 0) ? o.rotate : -o.rotate);\n if (r < 0) r += 360;\n return r;\n }\n case 'x': return w.a * o.x + w.b * o.y + w.worldX;\n case 'y': return w.c * o.x + w.d * o.y + w.worldY;\n case 'scaleX': return Math.sqrt(w.a * w.a + w.c * w.c) + o.scaleX;\n case 'scaleY': return Math.sqrt(w.b * w.b + w.d * w.d) + o.scaleY;\n case 'shearY': return (Math.atan2(w.d, w.b) - Math.atan2(w.c, w.a)) * DEG - 90 + o.shearY;\n }\n}\n\nfunction applyWorld(w: CoreWorld, property: TransformProperty, v: number, mix: number, additive: boolean, rules: Readonly<SolverRules>): void {\n switch (property) {\n case 'rotate': {\n // In radians, the change wrapped at the runtime's pi (issue #966): the degree form `wrap180(v − atan2·DEG)·mix·RAD` agrees on the grid and reads 1–2 ulp off on the corpus's `spineboy-pro` (202 findings of a raw compare, 113 of them bones, against 96 with this reading, the rest the two-bone ik below); this reading is exact on the row once those are fixed too.\n let r = additive ? v * RAD : v * RAD - Math.atan2(w.c, w.a);\n if (r > RUNTIME_PI) r -= 2 * RUNTIME_PI;\n else if (r < -RUNTIME_PI) r += 2 * RUNTIME_PI;\n r *= mix;\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n const [a, b] = [w.a, w.b];\n w.a = cos * a - sin * w.c;\n w.b = cos * b - sin * w.d;\n w.c = sin * a + cos * w.c;\n w.d = sin * b + cos * w.d;\n return;\n }\n case 'x':\n w.worldX = additive ? w.worldX + v * mix : w.worldX + (v - w.worldX) * mix;\n return;\n case 'y':\n w.worldY = additive ? w.worldY + v * mix : w.worldY + (v - w.worldY) * mix;\n return;\n case 'scaleX':\n case 'scaleY': {\n const [p, q] = property === 'scaleX' ? (['a', 'c'] as const) : (['b', 'd'] as const);\n const s = Math.sqrt(w[p] * w[p] + w[q] * w[q]);\n if (s === 0) return;\n const k = additive ? 1 + (v - 1) * mix : 1 + ((v - s) * mix) / s;\n w[p] *= k;\n w[q] *= k;\n return;\n }\n case 'shearY': {\n const yAngle = Math.atan2(w.d, w.b);\n const xAngle = Math.atan2(w.c, w.a);\n // Additive (issue #966): the value is turned into radians with the right angle on, and the right angle taken off after — `(v + 90)·RAD − 90·RAD`, unwrapped — as the absolute form takes the columns' angle off the same sum; `v·RAD` read 35 of 132 of the transform population's additive world-shear probes last-bit off, and 123 of 300 single-mapping probes (CW04).\n let r = additive && !rules.additiveShearRightAngle ? v * RAD : (v + 90) * RAD - (additive ? 90 * RAD : yAngle - xAngle);\n if (!additive) r = r > RUNTIME_PI ? r - 2 * RUNTIME_PI : r < -RUNTIME_PI ? r + 2 * RUNTIME_PI : r;\n const angle = yAngle + r * mix;\n const s = Math.sqrt(w.b * w.b + w.d * w.d);\n w.b = Math.cos(angle) * s;\n w.d = Math.sin(angle) * s;\n return;\n }\n }\n}\n\nconst LOCAL_FIELD: Record<TransformProperty, 'rotation' | 'x' | 'y' | 'scaleX' | 'scaleY' | 'shearY'> = { rotate: 'rotation', x: 'x', y: 'y', scaleX: 'scaleX', scaleY: 'scaleY', shearY: 'shearY' };\n\nfunction applyLocal(b: ModelBone, property: TransformProperty, v: number, mix: number, additive: boolean): void {\n const field = LOCAL_FIELD[property];\n const scale = property === 'scaleX' || property === 'scaleY';\n const current = b[field] ?? (scale ? 1 : 0);\n if (!additive) b[field] = current + (v - current) * mix;\n else b[field] = scale ? current * (1 + (v - 1) * mix) : current + v * mix;\n}\n\n/** A transform constraint (the header's *transform*): returns the bones it changed, and those it changed in world space. */\nfunction solveTransform(state: SolverState, c: CoreTransformRecord): { changed: string[]; inWorld: string[] } {\n const changed: string[] = [];\n const inWorld: string[] = [];\n for (const name of c.bones) {\n const b = bone(state, name);\n const w = { ...(state.world.get(name) as CoreWorld) };\n let applied = false;\n for (const from of c.properties) {\n const value = sourceValue(state, c, from.property) - from.offset;\n for (const to of from.to) {\n const mix = c.mixes[to.property];\n if (mix === 0) continue;\n let v = value * to.scale + to.offset;\n if (c.clamp) {\n const lo = Math.min(to.offset, to.max);\n const hi = Math.max(to.offset, to.max);\n v = v < lo ? lo : v > hi ? hi : v;\n }\n applied = true;\n if (c.localTarget) applyLocal(b, to.property, v, mix, c.additive);\n else applyWorld(w, to.property, v, mix, c.additive, state.rules);\n }\n }\n if (!applied) continue;\n changed.push(name);\n if (!c.localTarget) {\n state.world.set(name, w);\n inWorld.push(name);\n }\n }\n return { changed, inWorld };\n}\n\n/** Why a constraint is not applied under the skin view posed (the header's measured rule), or null when it is. */\nfunction inactiveWhy(state: SolverState, c: CoreConstraintRecord): string | null {\n return constraintInactiveWhy(c, state.active, state.rules);\n}\n\n/**\n * Why a constraint is not applied under a skin view whose active bones are\n * `active` (the header's measured rule), or null when it is — `inactiveWhy`'s\n * reading, exported so the additive probe (`./additive.ts`, issue #1025) asks\n * the rule the solver applies rather than a copy of it.\n */\nexport function constraintInactiveWhy(c: CoreConstraintRecord, active: ReadonlySet<string>, rules: Readonly<SolverRules> = RUNTIME_SOLVER_RULES): string | null {\n // A skin-required constraint of any kind is applied when an applied skin's list for its kind names it (issue #932, card #961; physics first by issue #956).\n if (c.skin && !c.listedBySkin) return 'skin';\n // A path constraint is active when its slot's bone is (`./constraints_path.ts`, *Which constraints run*); every other kind when every bone it names is.\n // A transform constraint is applied when its source is, to every bone it names, inactive ones included (issue #979: an inactive bone among them did not stop it moving the others, and it wrote into the inactive one). An ik naming an inactive bone is left unapplied: the runtime applies it from ancestors it has not brought up to date (the header's *Unposed bones*).\n const named = c.kind === 'path' ? [c.slotBone] : c.kind === 'ik' ? (rules.ikOverInactiveFresh ? [c.target] : [...c.bones, c.target]) : c.kind === 'transform' ? (rules.transformIgnoresBoneActivity ? [c.source] : [...c.bones, c.source]) : c.kind === 'slider' ? (c.bone === null ? [] : [c.bone]) : [c.bone];\n return named.every((n) => active.has(n)) ? null : 'inactive bone';\n}\n\n/**\n * For each ik naming an inactive bone, by its index in `records`: whether the\n * pass has brought the bone above its first bone up to date by the time the\n * ik runs (the header's *Unposed bones and collapsed frames*). The runtime\n * orders its update before it poses, each constraint bringing up to date the\n * bones it reads, parents first; an inactive bone counts as already ordered,\n * so ordering one does not reach its parent. A bone ordered once in the pass\n * holds a world from this pass; one never ordered holds what the skeleton\n * held before, which on a fresh skeleton is zeros. The same walk as\n * `slotBonePlan` in `./constraints_path.ts`.\n */\nexport function frameUpdatedBefore(bones: readonly ModelBone[], active: ReadonlySet<string>, records: readonly CoreConstraintRecord[], skipped: ReadonlySet<number>): Map<number, boolean> {\n const parent = new Map(bones.map((b) => [b.name, b.parent]));\n const children = new Map<string, string[]>();\n for (const b of bones) if (b.parent !== undefined) children.set(b.parent, [...(children.get(b.parent) ?? []), b.name]);\n const ordered = new Map(bones.map((b) => [b.name, !active.has(b.name)]));\n const ever = new Set<string>();\n const orderBone = (name: string): void => {\n if (ordered.get(name)) return;\n const p = parent.get(name);\n if (p !== undefined) orderBone(p);\n ordered.set(name, true);\n ever.add(name);\n };\n const unorder = (names: readonly string[]): void => {\n for (const n of names) {\n if (!active.has(n)) continue;\n if (ordered.get(n)) unorder(children.get(n) ?? []);\n ordered.set(n, false);\n }\n };\n const out = new Map<number, boolean>();\n records.forEach((c, m) => {\n if (skipped.has(m)) return;\n if (c.kind === 'slider') {\n unorder(c.timelines.bones.map((t) => t.name));\n return;\n }\n if (c.kind === 'ik') {\n orderBone(c.target);\n orderBone(c.bones[0]);\n if (c.bones.length > 1) orderBone(c.bones[c.bones.length - 1]);\n if (c.bones.some((b) => !active.has(b))) {\n const f = parent.get(c.bones[0]);\n out.set(m, f === undefined || ever.has(f));\n }\n unorder(children.get(c.bones[0]) ?? []);\n if (c.bones.length > 1) ordered.set(c.bones[c.bones.length - 1], true);\n return;\n }\n const moved = c.kind === 'physics' ? [c.bone] : c.bones;\n if (c.kind === 'transform') orderBone(c.source);\n else if (c.kind === 'path') for (const d of c.slotDeps) orderBone(d);\n for (const b of moved) orderBone(b);\n for (const b of moved) unorder(children.get(b) ?? []);\n for (const b of moved) ordered.set(b, true);\n });\n return out;\n}\n\n/** The frame an ik over an inactive bone reads (`frameUpdatedBefore`): zeros when the pass has not brought it up to date, null (the current one) otherwise. */\nfunction inactiveIkFrame(state: SolverState, c: CoreIkRecord, i: number, updated: ReadonlyMap<number, boolean>): CoreWorld | null {\n if (!state.rules.ikOverInactiveFresh || updated.get(i) !== false) return null;\n return { a: 0, b: 0, c: 0, d: 0, worldX: 0, worldY: 0 };\n}\n\n/** A plant a control passes in place of the solving: the records as posed, rewritten (a mix scaled, a bend flipped, two swapped). */\nexport type ConstraintPlant = (records: CoreConstraintRecord[]) => CoreConstraintRecord[];\n\n/**\n * Every admitted constraint applied, in the document's order, to the bones'\n * local values (copied, never the caller's) and their world transforms as\n * `worldTransforms` posed them — the header's update order — and the world\n * transforms returned. With `physics`, the stepped phase's context, each\n * physics constraint is stepped on its bone (`stepPhysics` in\n * `./constraints_physics.ts`); without it, it applies nothing.\n */\nexport function applyConstraints(bones: readonly ModelBone[], world: ReadonlyMap<string, CoreWorld>, active: ReadonlySet<string>, records: readonly CoreConstraintRecord[], previous: ReadonlyMap<string, CoreWorld> | null = null, applied?: SliderApplication[], physics?: PhysicsStepContext, settled?: (state: SolverState) => void, rules: Readonly<SolverRules> = RUNTIME_SOLVER_RULES): Map<string, CoreWorld> {\n // No record: nothing to solve, so the world as given, copied (issue #1134) — and what `sliderPhysicsTarget` leaves on the step's context with no record, an empty carry, under the plant that carries one.\n if (records.length === 0 && settled === undefined) {\n if (physics !== undefined && !rules.sliderPhysicsLastsOnePass) physics.carried = new Map();\n return new Map(world);\n }\n const state: SolverState = { bones: bones.map((b) => ({ ...b })), index: boneIndex(bones, active), world: new Map(world), active, rules };\n const skipped = new Set<number>();\n records.forEach((c, i) => {\n if (inactiveWhy(state, c) !== null) skipped.add(i);\n });\n // A path constraint's offset reads its slot bone's world as the runtime last brought it up to date (`./constraints_path.ts`, *Which slot bone*).\n const plan = records.some((c) => c.kind === 'path') ? keptPlan(slotBonePlans, state, records, skipped, () => slotBonePlan(bones, active, records, skipped)) : new Map<number, SlotBoneEvent | null>();\n // An ik over an inactive bone reads the frame above it as the pass left it (issue #979).\n const updated = records.some((c) => c.kind === 'ik' && c.bones.some((b) => !active.has(b))) ? keptPlan(frameUpdates, state, records, skipped, () => frameUpdatedBefore(bones, active, records, skipped)) : new Map<number, boolean>();\n const snapshots = new Map<number, CoreWorld>();\n // Issue #1049: under the step a slider's physics timelines write the pass's physics records, which a later physics constraint steps with.\n const physicsPose = physics === undefined ? undefined : sliderPhysicsTarget(records, active, physics, rules);\n const snap = (i: number, when: 'before' | 'after'): void => {\n for (const [k, e] of plan) if (e !== null && e.at === i && e.when === when && !(k === i && when === 'before')) snapshots.set(k, { ...(state.world.get((records[k] as CorePathRecord).slotBone) as CoreWorld) });\n };\n for (let i = 0; i < records.length; i++) {\n const c = records[i];\n snap(i, 'before');\n if (skipped.has(i)) continue;\n let changed: string[] = [];\n let inWorld: string[] = [];\n if (c.kind === 'physics') {\n // Under Physics.none a physics constraint applies nothing; stepped, it moves its bone in world space (`./constraints_physics.ts`).\n if (physics !== undefined) {\n const w = { ...(state.world.get(c.bone) as CoreWorld) };\n const authored = physicsPose?.records.get(c.name) ?? c;\n const posed = physics.parameters?.apply(authored) ?? authored;\n if ((physics.step ?? stepPhysics)(posed, w, bone(state, c.bone).length ?? 0, physics)) {\n state.world.set(c.bone, w);\n changed = [c.bone];\n inWorld = [c.bone];\n }\n }\n } else if (c.kind === 'slider') {\n changed = applySlider(state, c, applied, physicsPose);\n } else if (c.kind === 'ik') {\n if (c.mix !== 0) {\n const frame = inactiveIkFrame(state, c, i, updated);\n changed = c.bones.length === 1 ? solveOne(state, c, frame) : solveTwo(state, c, frame);\n }\n } else if (c.kind === 'path') {\n const e = plan.get(i) ?? null;\n const stale = previous === null ? { a: 0, b: 0, c: 0, d: 0, worldX: 0, worldY: 0 } : (previous.get(c.slotBone) as CoreWorld);\n const slotWorld = (e !== null && e.at === i) ? (state.world.get(c.slotBone) as CoreWorld) : e !== null ? (snapshots.get(i) as CoreWorld) : stale;\n ({ changed, inWorld } = solvePath(state, c, slotWorld));\n } else {\n ({ changed, inWorld } = solveTransform(state, c));\n }\n if (changed.length > 0) repose(state, changed, inWorld);\n snap(i, 'after');\n }\n // #969: the solver's last state — every bone's local values as the constraints left them — for a caller reading a dial off it (`./hooks.ts`).\n settled?.(state);\n return state.world;\n}\n\n/**\n * What `slotBonePlan` (`./constraints_path.ts`) and `frameUpdatedBefore` read\n * of a record: its kind and the names it orders — a name by value, a list by\n * identity. Every pass of a walk poses its records afresh (`posedRecords`,\n * `pathDeformed`, `stepPhysicsRecords` spread each one), and a spread carries\n * these lists over as the same arrays.\n */\nfunction planShape(c: CoreConstraintRecord): readonly unknown[] {\n switch (c.kind) {\n case 'slider':\n return [c.kind, c.timelines.bones];\n case 'ik':\n return [c.kind, c.target, c.bones];\n case 'physics':\n return [c.kind, c.bone];\n case 'transform':\n return [c.kind, c.source, c.bones];\n case 'path':\n return [c.kind, c.bones, c.slotDeps, c.slotBone];\n }\n}\n\n/** A plan kept per solver index, with the record shapes (`planShape`) and the skipped records it was built over. */\ninterface KeptPlan<T> {\n shapes: ReadonlyArray<readonly unknown[]>;\n skipped: readonly number[];\n plan: T;\n}\nconst slotBonePlans = new WeakMap<ReadonlyMap<string, number>, KeptPlan<Map<number, SlotBoneEvent | null>>>();\nconst frameUpdates = new WeakMap<ReadonlyMap<string, number>, KeptPlan<Map<number, boolean>>>();\n\n/**\n * A pass's ordering plan — `slotBonePlan` or `frameUpdatedBefore` — reused\n * from the pass before when nothing it reads has changed (issue #1179): the\n * bones' names and parents and the active set (one solver index stands for\n * those, `boneIndex`), each record's shape, and which records are skipped.\n * Otherwise built again. Both read names and nothing else, so a reused plan is\n * the plan the pass would have built; neither is written once built.\n */\nfunction keptPlan<T>(kept: WeakMap<ReadonlyMap<string, number>, KeptPlan<T>>, state: SolverState, records: readonly CoreConstraintRecord[], skipped: ReadonlySet<number>, build: () => T): T {\n const shapes = records.map(planShape);\n const skips = [...skipped];\n const last = kept.get(state.index);\n if (\n last !== undefined &&\n last.shapes.length === shapes.length &&\n shapes.every((sh, i) => sh.length === last.shapes[i].length && sh.every((v, j) => v === last.shapes[i][j])) &&\n last.skipped.length === skips.length &&\n skips.every((k, i) => k === last.skipped[i])\n ) {\n return last.plan;\n }\n const plan = build();\n kept.set(state.index, { shapes, skipped: skips, plan });\n return plan;\n}\n\n/** The last bone index each view's active set was asked for, with the names and parents it was built over (`boneIndex`). */\nconst indexOfView = new WeakMap<ReadonlySet<string>, { names: string[]; parents: Array<string | undefined>; index: Map<string, number> }>();\n\n/**\n * Each bone's position in `bones`, by name — the solver's index. Every pose of\n * a view lists the same bones in the same order (issue #1134: a walk built it\n * anew on each of its passes), so the index last built under the view's\n * active set (`activeBones`, one object per view) is reused when the names\n * and the parents agree position by position, and built again otherwise —\n * the parents because `repose` keeps each bone's subtree beside the index\n * (`subtreesOf`), and a subtree is a reading of them. Read, never written.\n */\nfunction boneIndex(bones: readonly ModelBone[], active: ReadonlySet<string>): Map<string, number> {\n const kept = indexOfView.get(active);\n if (kept !== undefined && kept.names.length === bones.length && bones.every((b, i) => b.name === kept.names[i] && b.parent === kept.parents[i])) return kept.index;\n const index = new Map(bones.map((b, i) => [b.name, i]));\n indexOfView.set(active, { names: bones.map((b) => b.name), parents: bones.map((b) => b.parent), index });\n return index;\n}\n\n/** Each bone's subtree as `subtreesOf` built it, kept per solver index (one object per view's bones, `boneIndex`). */\nconst subtreesOfIndex = new WeakMap<ReadonlyMap<string, number>, ReadonlyArray<readonly number[]>>();\n\n/**\n * For the bone at each position of `state.bones`, the positions of the bone\n * and of every bone below it, ascending (issue #1179). Bones are parents\n * first, so each position is appended to its own list and its ancestors' in\n * ascending order. Built from the bones' parents once per solver index —\n * `boneIndex` hands back one index only while the names and the parents are\n * the ones it was built over, and the other two solver states (`previousPassSlotBones`,\n * `historyTaint`) build an index of their own.\n */\nfunction subtreesOf(state: SolverState): ReadonlyArray<readonly number[]> {\n const kept = subtreesOfIndex.get(state.index);\n if (kept !== undefined) return kept;\n const lists: number[][] = state.bones.map(() => []);\n for (let k = 0; k < state.bones.length; k++) {\n let at: number | undefined = k;\n while (at !== undefined) {\n lists[at].push(k);\n const parent: string | undefined = state.bones[at].parent;\n at = parent === undefined ? undefined : state.index.get(parent);\n }\n }\n subtreesOfIndex.set(state.index, lists);\n return lists;\n}\n\n/** After a constraint: the bones it moved in world space read back into local values, and every bone below one it moved posed again (the header's update order). */\nfunction repose(state: SolverState, changed: readonly string[], inWorld: readonly string[]): void {\n for (const name of inWorld) {\n const b = bone(state, name);\n localFromWorld(b, parentWorld(state, b), state.world.get(name) as CoreWorld, state.rules);\n }\n // `changed` and `inWorld` are a constraint's few bones: read as they are rather than copied into sets on each of a walk's passes (issue #1134).\n const moved = changed;\n const below = new Set(changed);\n const keep = inWorld;\n // A bone joins `below` only through its parent, so the bones that can are the moved bones' subtrees: the walk visits those, in bone order (issue\n // #1179), where it visited every bone from the first one moved (issue #1134) — the bones it no longer visits are the ones whose parent `below`\n // could never hold, so each bone it does visit reads the same `below`, and is posed again in the same order.\n const subtrees = subtreesOf(state);\n const lists: Array<readonly number[]> = [];\n for (const name of changed) {\n const at = state.index.get(name);\n if (at !== undefined) lists.push(subtrees[at]);\n }\n const visit = lists.length === 1 ? lists[0] : [...new Set(lists.flat())].sort((x, y) => x - y);\n for (const k of visit) {\n const b = state.bones[k];\n // Not through an inactive bone the constraint did not move itself (issue #979): the bones below it keep what the constraints wrote into them.\n if (b.parent !== undefined && below.has(b.parent) && (!state.rules.inactiveHoldsItsWorld || state.active.has(b.parent) || moved.includes(b.parent))) below.add(b.name);\n if (below.has(b.name) && !keep.includes(b.name)) poseBone(state, b);\n }\n}\n\n/**\n * The slot bones a path constraint's offset reads from the PREVIOUS pass —\n * those the runtime has not brought up to date in this one by the time the\n * constraint runs (`./constraints_path.ts`, *Which slot bone*) — named with\n * their constraint. Only a constraint with an offset reads its slot bone.\n */\nexport function previousPassSlotBones(doc: CompiledDocument, active: ReadonlySet<string>): Array<{ constraint: string; bone: string }> {\n const records = doc.constraints.flatMap((c) => (c.record === undefined ? [] : [c.record]));\n if (!records.some((r) => r.kind === 'path')) return [];\n const state: SolverState = { bones: [...doc.bones], index: new Map(doc.bones.map((b, i) => [b.name, i])), world: new Map(), active, rules: RUNTIME_SOLVER_RULES };\n const skipped = new Set<number>();\n records.forEach((c, i) => {\n if (inactiveWhy(state, c) !== null) skipped.add(i);\n });\n const out: Array<{ constraint: string; bone: string }> = [];\n for (const [k, e] of slotBonePlan(doc.bones, active, records, skipped)) {\n const r = records[k] as CorePathRecord;\n if (e === null && r.offsetRotation !== 0) out.push({ constraint: r.name, bone: r.slotBone });\n }\n return out;\n}\n\n/**\n * Why an animation's bones cannot be posed by this cut though the setup's\n * can, or null: a path constraint's slot whose attachment an animation keys\n * — the curve would not be the one the setup reads, and a switch of the\n * walked curve is not measured — or a path attachment an animation deforms\n * whose placeholder several skins fill, so which record `--skin all` shows,\n * and whether the deform moves it, is the Spine file's skin order (under a\n * named skin one record resolves, `./skins.ts`). A deform\n * of a walked path is otherwise posed (`./deform.ts`, issue #955).\n */\nexport function pathAnimationsWhy(doc: CompiledDocument): string | null {\n const found: string[] = [];\n const paths = doc.constraints.flatMap((c) => (c.record?.kind === 'path' ? [c.record] : []));\n for (const a of doc.animations) {\n for (const r of paths) {\n if (a.timelines.slots.some((s) => s.name === r.slot && s.timelines.some((t) => t.kind === 'attachment'))) found.push(`animation \"${a.name}\" keys the attachment of slot \"${r.slot}\", which path constraint \"${r.name}\" walks — a switch of the walked curve is not measured`);\n }\n for (const d of a.deforms) {\n const [skin, slot, att] = d.split('/');\n const g = doc.skins.find((k) => k.name === skin)?.attachments[slot]?.[att]?.geometry;\n const fillers = fillingSkins(doc, slot, att).map((k) => `\"${k}\"`);\n if (g?.kind === 'path' && fillers.length > 1) found.push(`animation \"${a.name}\" deforms path attachment \"${att}\" (skin \"${skin}\", slot \"${slot}\"), a placeholder skins ${fillers.join(', ')} fill — which of them --skin all walks, and so whether the deform moves it, is the Spine file's skin order, not the model's`);\n }\n }\n return found.length === 0 ? null : found.join('; ');\n}\n\n/**\n * Why a document's bones cannot be posed by this cut, or null when they can:\n * a path constraint walks a slot whose setup placeholder skins fill with\n * different curves (`CorePathRecord.unresolved`), it declares a constraint\n * of a kind not admitted (`ADMITTED_CONSTRAINT_KINDS` — since the path cut,\n * none is left), named with the counts of every kind it declares, or a\n * slider whose animation keys a constraint timeline (`sliderBonesWhy`).\n */\nexport function constraintsAbsentWhy(doc: CompiledDocument, rules: Readonly<SolverRules> = RUNTIME_SOLVER_RULES): string | null {\n const unresolved = doc.constraints.flatMap((c) => (c.record?.kind === 'path' && c.record.unresolved !== null ? [c.record.unresolved] : []));\n if (unresolved.length > 0) return unresolved.join('; ');\n const later = doc.constraints.filter((c) => !ADMITTED_CONSTRAINT_KINDS.includes(c.kind));\n if (later.length === 0) return sliderBonesWhy(doc) ?? (rules.refuseHistoryLeak ? unposedLeakWhy(doc) : null);\n const kinds = [...new Set(doc.constraints.map((c) => c.kind))];\n const laterKinds = [...new Set(later.map((c) => c.kind))];\n return `the document declares ${kinds.map((k) => `${k} ×${doc.constraints.filter((c) => c.kind === k).length}`).join(', ')}, and ${laterKinds.join(', ')} constraints are not admitted (item 5; ${ADMITTED_CONSTRAINT_KINDS.join(', ')} are): the oracle applies them`;\n}\n\n/**\n * Why the core refuses a pose because a posed bone would read a value the\n * runtime makes depend on its previous pass, or null (issue #979, the\n * header's ⚠️ under *Unposed bones and collapsed frames*). A constraint that\n * writes into an inactive constrained bone — an ik reading a frame the pass\n * has not brought up to date (`frameUpdatedBefore`), a transform or a path —\n * taints that bone (and, for a world write or a two-bone ik's child, the\n * bones below it): the runtime's value there differs between a skeleton\n * posed sample after sample and a fresh one. A later constraint reading a\n * tainted bone — an ik's target, a transform's or a slider's source, a\n * path's slot bone or the bones weighting its curve — taints what it moves\n * when that is unposed too, and is refused by name when it moves a posed\n * bone: that is where the history would reach the picture. The rendered\n * value of an unposed bone is the seam's zero snapshot, so nothing else of\n * this class reaches a frame.\n */\nexport function unposedLeakWhy(doc: CompiledDocument): string | null {\n return historyTaint(doc).refusal;\n}\n\n/** A constraint writing into an inactive constrained bone — what a history-dependent value started from. */\nexport interface HistoryWriter {\n kind: CoreConstraintKind;\n name: string;\n inactive: string;\n}\n\n/**\n * The walk `unposedLeakWhy` reads: every bone a writer into an inactive bone\n * reaches, world or local, with its writer (the first, in constraint order),\n * and the refusal where a posed bone would read one — the walk stops there.\n * `tools/pose_oracle.ts unposed` classes a stepped bone-sample by it (no fresh\n * reading is taken under the step).\n */\nexport function historyTaint(doc: CompiledDocument): { refusal: string | null; tainted: Map<string, HistoryWriter> } {\n const records = doc.constraints.flatMap((c) => (c.record === undefined ? [] : [c.record]));\n const active = activeBones(doc);\n if (doc.bones.every((b) => active.has(b.name))) return { refusal: null, tainted: new Map() };\n const parent = new Map(doc.bones.map((b) => [b.name, b.parent]));\n const unposed = new Set<string>();\n for (const b of doc.bones) if (!active.has(b.name) || (b.parent !== undefined && unposed.has(b.parent))) unposed.add(b.name);\n const below = (root: string): string[] => doc.bones.filter((b) => {\n for (let at: string | undefined = b.name; at !== undefined; at = parent.get(at)) if (at === root) return true;\n return false;\n }).map((b) => b.name);\n const state: SolverState = { bones: [...doc.bones], index: new Map(doc.bones.map((b, i) => [b.name, i])), world: new Map(), active, rules: RUNTIME_SOLVER_RULES };\n const skipped = new Set<number>();\n records.forEach((c, i) => {\n if (inactiveWhy(state, c) !== null) skipped.add(i);\n });\n const updated = frameUpdatedBefore(doc.bones, active, records, skipped);\n // What of a bone the previous pass reaches: its world (read by a world-space source, an ik's target, a path's slot) or its local values (read by a local source).\n const world = new Map<string, HistoryWriter>();\n const local = new Map<string, HistoryWriter>();\n const spell = (w: HistoryWriter): string => `${w.kind} constraint \"${w.name}\" writes into inactive bone \"${w.inactive}\"`;\n const union = (): Map<string, HistoryWriter> => {\n const out = new Map(world);\n for (const [k, v] of local) if (!out.has(k)) out.set(k, v);\n return out;\n };\n const taint = (into: Map<string, HistoryWriter>, names: readonly string[], origin: HistoryWriter): void => {\n for (const n of names) if (!into.has(n)) into.set(n, origin);\n };\n const label = (c: CoreConstraintRecord): string => `${c.kind} constraint \"${c.name}\"`;\n for (let i = 0; i < records.length; i++) {\n if (skipped.has(i)) continue;\n const c = records[i];\n const moved = c.kind === 'physics' ? [c.bone] : c.kind === 'slider' ? c.timelines.bones.map((t) => t.name) : c.bones;\n const readsLocal = (c.kind === 'transform' && c.localSource) || (c.kind === 'slider' && c.local);\n const operands = c.kind === 'ik' ? [c.target] : c.kind === 'transform' ? [c.source] : c.kind === 'path' ? [c.slotBone, ...c.slotDeps] : c.kind === 'slider' ? (c.bone === null ? [] : [c.bone]) : [];\n const from = readsLocal ? local : world;\n const read = operands.find((o) => from.has(o));\n if (read !== undefined) {\n const posed = moved.find((b) => !unposed.has(b));\n const origin = from.get(read) as HistoryWriter;\n if (posed !== undefined) return { refusal: `${label(c)} moves posed bone \"${posed}\" and reads ${readsLocal ? 'the local values' : 'the world transform'} of bone \"${read}\", a bone whose value depends on the runtime's previous pass (${spell(origin)}) — the runtime's own sample-after-sample and fresh-skeleton readings disagree there, so there is no one value to pose`, tainted: union() };\n taint(world, moved.flatMap(below), origin);\n taint(local, moved, origin);\n }\n const inactive = moved.find((b) => !active.has(b));\n if (inactive === undefined || c.kind === 'physics' || c.kind === 'slider') continue;\n const origin: HistoryWriter = { kind: c.kind, name: c.name, inactive };\n if (c.kind === 'ik') {\n // Its local values move; for a two-bone ik the child's, and with them the world of the child and the bones below it.\n if (updated.get(i) !== false) continue;\n taint(local, c.bones, origin);\n if (c.bones.length > 1) taint(world, below(c.bones[1]), origin);\n } else if (c.kind === 'transform' && c.localTarget) taint(local, moved, origin);\n else {\n // A world write: the bones moved and every bone below them, in world; their own local values read back from it.\n taint(world, moved.flatMap(below), origin);\n taint(local, moved, origin);\n }\n }\n return { refusal: null, tainted: union() };\n}\n","/**\n * Construct 4 of the core (issue #936, step 2d of issue #380): an animation's\n * bone and slot timelines at a sample time — the key search, the curve as the\n * runtime evaluates it, and every bone and slot timeline kind — posed on the\n * setup pose with the animation alone at full weight, the way the oracle\n * samples one (`tools/pose_oracle.ts`, *How a pose is posed*: the setup pose,\n * then the animation applied at `t` with alpha 1 from the setup pose, then the\n * world transforms).\n *\n * Every rule below was measured by posing a hand-written skeleton through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13) and reading the rows it\n * printed; nothing here was written from the runtime's source. The core\n * suite's `CA` controls hold the same skeletons against the core at tolerance\n * 0, and `tools/core_gate.ts` holds every recipe of the tree's corpus.\n *\n * ## The key search\n *\n * A timeline's value at `t` comes from the LAST key whose time is at or\n * before `t`. Measured on a `translatex` keyed at 0.5, 1 and 1.5 on a bone at\n * setup `x` 5, sampled on a grid of quarter seconds over 2 s:\n *\n * - **Before the first key the channel is at its setup value** — `x` read 5\n * at 0 and 0.25. ⚠️ Not \"untouched\": the timeline POSES the setup value. A\n * bone keyed by `translate` (0 → 10, 2 → 20) and by a `translatex` whose\n * first key is at 1 read `x` = setup (1, not 11) before 1 when `translatex`\n * is listed after `translate`, and 11 when it is listed before — each\n * timeline, in the animation's order, writes its channels at every time.\n * - **On a key exactly, that key** — a stepped key at 0.5 (value 10) followed\n * by a key at 1 (value 30) read 30 at t = 1, not 10.\n * - **At and after the last key, the last key's value** — 45 (setup 5 + 40)\n * at 1.5, 1.75 and 2.\n * - Key times are compared as the runtime stores them, float32\n * (`Math.fround`), against the sample time as a double; key values are read\n * as float32 too. A linear segment from (0, 0) to (0.4666667, 100000)\n * sampled at `off` read 12500, 37500, 62500, 87500 exactly — the key time\n * and the duration both the float32 0.46666669845581055; the double\n * 0.4666667 would have read 4.1e-5 to 2.9e-4 higher.\n *\n * ## The three curves, per segment\n *\n * A key's `curve` shapes the segment from it to the next key.\n *\n * - **None — linear**: `v0 + (t − t0) / (t1 − t0) · (v1 − v0)`, per channel.\n * - **`stepped`**: the key's own value until the next key's time.\n * - **Bézier** — four absolute numbers per channel, `cx1, cy1, cx2, cy2`, the\n * two handles of the cubic from `(t0, v0)` to `(t1, v1)` (the format's\n * documentation: a curve's control points are in the timeline's own time and\n * value). ⭐ **The runtime does not evaluate the cubic.** Posed on one bone,\n * one `translatex` from (0, 0) to (1, 1000) with handles (0.1, 800) and\n * (0.3, 1000), 2,000 `dense` samples read BELOW the exact cubic solved for\n * `t` at every interior sample, by up to 10.34 — the residual of chords\n * under a concave curve — and the slopes between consecutive samples fall\n * into exactly ten runs whose nine intersections are the cubic's points at\n * the parameter `u = 0.1, 0.2, …, 0.9` (to the fourth decimal of `t`). So\n * the curve is the POLYLINE through the key, the cubic's nine points at\n * tenths of its parameter, and the next key, and a sample is interpolated\n * linearly on the piece whose end is the first point at or after `t`.\n *\n * **The nine points, to the last float32 step.** They are stored float32,\n * and which float32 each lands on was fixed by two measurements, both with\n * the samples of spine-core's dump as the judge at the oracle's rounding:\n *\n * 1. *The recurrence.* Over 60 random segments whose every number was\n * already a float32 (82,731 samples), the cubic's tenths evaluated\n * directly missed 866 samples: each miss a point one float32 step off,\n * where the exact double lay within a few hundredths of a step of a\n * rounding midpoint — so the runtime's points carry a relative error\n * near 1e-9 before the rounding. Forward differencing the cubic at the\n * step h = 1/10 (the textbook recurrence: each point the previous plus a\n * first difference, which grows by a second, which grows by a third)\n * reproduces that error exactly when the third difference's one-sixth\n * is the eight-digit decimal `0.16666667`: 0 misses. With 1/6 exact it\n * missed 867, with 1/6 as a float32 1,694; a recurrence whose running\n * sums are float32 missed more than any.\n * 2. *The numbers it runs on.* Over 300 of the 8,145 Bézier channel\n * segments in the 19 recipes' bone timelines, each re-posed alone\n * (18,430 samples), the recurrence above missed 4,145 samples when run\n * on the key times, values and handles as float32 — and 0 when run on\n * the numbers AS THE FILE STATES THEM (the doubles its text parses to),\n * with only the polyline's two ends, the keys themselves, float32. The\n * mixed readings missed 2,479 (handles stated, keys float32), 2,587\n * (keys stated, handles float32) and 1,054 (the ends stated too). The\n * first population could not tell these apart because its numbers were\n * float32 to begin with; the model's numbers are float32 SHORTEST NAMES\n * (`f32` in `src/compile.ts`), whose doubles are not the float32 itself.\n *\n * So a key keeps both (`CoreKey.stated` and its float32 `time`/`values`),\n * and `bezierPolyline` is the recurrence over the stated numbers. The core\n * suite's `CA02` holds the measurement and every rejected reading missing.\n *\n * ## The bone timelines — alpha 1 from the setup pose\n *\n * Measured on bones with non-trivial setup values:\n *\n * - `rotate` ADDS to the setup rotation: setup 20, keys 350 → 10 read a world\n * x axis at 10° at t = 0 and at 200° (−160°) half way — the value is\n * interpolated as a number, 350 → 10 passing 180, and never wrapped to the\n * short way round.\n * - `translate`, `translatex`, `translatey` ADD to the setup position.\n * - `scale`, `scalex`, `scaley` MULTIPLY the setup scale: setup (2, 0.5) and a\n * key (3, 1) read (6, 0.5); a negative key or setup multiplies through\n * (setup −2, keys −1 → 3 read 2 → −6 through 0).\n * - `shear`, `shearx`, `sheary` ADD to the setup shear.\n * - `inherit` sets the bone's inherit mode, stepped by the format: before its\n * first key the setup mode, from each key that key's mode (measured\n * `normal → onlyTranslation → normal` under a rotated, scaled parent).\n *\n * The posed values replace the setup values in a copy of the bone and the\n * core's own evaluator (`worldTransforms`, `./world.ts`) poses the copies.\n *\n * ## The slot timelines\n *\n * - `attachment`: stepped by nature; before its first key the setup\n * attachment, from a key its placeholder, resolved exactly as the setup\n * placeholder is (`shownAttachment`), a placeholder no skin fills and a\n * `null` name both showing nothing.\n * - `rgba`, `rgb`, `alpha`, `rgba2`, `rgb2` SET the channels they name (they do\n * not add to or scale the setup colour) and leave every other channel at\n * setup: `rgb` keeps the setup alpha, `alpha` the setup rgb; `rgba2` and\n * `rgb2` set the dark colour too. A key's hex pair reads as its byte over 255\n * and is stored float32, as every key value is.\n * - **Every colour channel is clamped to [0, 1] after the curve**: an `rgba`\n * whose green curve dips below 0 and whose red curve rises above 1 read 0\n * and 1 there.\n * - 🚫 **`rgba2` or `rgb2` on a slot with no dark colour is refused.** Posed\n * through the runtime, such a timeline throws while the animation is\n * applied (`TypeError`), so no dump exists to hold a core to; the compiler\n * refuses the same timeline before any file is written (`compileTrack`).\n *\n * ## The duration and the sample times\n *\n * The oracle's sample times are the tool's formula (`sampleTime`, which the\n * tool calls here, as it rounds with `gridRound`), over the runtime's\n * duration of the animation: the LAST key time of every timeline in it — the\n * later constructs' (constraints, deform, sequence, draw order, events)\n * included — as float32, not the model's declared `duration`. Measured: a\n * rotate ending at 1 beside an event at 2.5, the model stating 0, sampled over\n * 2.5 in spine-core's dump (`CA09`); over the 54 animations of the 19 recipes,\n * every duration agreed.\n *\n * ## What is left out, by name\n *\n * The constraints are applied after the timelines, posed by their own\n * timelines at `t` (issue #938, `./constraints.ts`), and each slider's slot\n * timelines after the sample's own (`./constraints_slider.ts`); a document\n * whose setup bones are absent has no animation bones from the core, for the\n * same reason, and neither has one whose animation keys the attachment of a\n * walked path's slot, deforms a walked path whose placeholder several skins\n * fill, or whose path offset reads a slot bone from the previous pose that\n * changes its reflection (`./constraints_path.ts`); a slider whose animation\n * keys a slot on such a document, or a placeholder skins fill differently,\n * leaves the animation slots out as they leave the setup slots out.\n *\n * ## The rest of a sample (issue #955)\n *\n * The oracle's sample carries `drawOrder`, `attachments`, `clips` and\n * `events` too, and since issue #955 the core poses each: the draw order\n * (`./draw_order.ts`), every drawn attachment's and clipping polygon's world\n * vertices through the sample's bones, in that order, with what the deform\n * and sequence timelines set on them (`./deform.ts`), and the events fired\n * since the sample before (`./events.ts`); each module's header states its\n * rules with the measurements. A path walks the curve the sample's deform\n * timelines left on its slot (`pathDeformed`). The attachments and clips are\n * absent where the bones or the slots are, and the attachments where a shown\n * region's rectangle is `null` or a timeline moves a record several skins\n * fill; the draw order where a slider keys it on a document whose bones are\n * absent.\n */\nimport type { ModelBone, ModelSlot } from '../model.ts';\nimport { readAttachmentTimelines, type CoreAttachmentTimeline } from './deform.ts';\nimport { readDrawOrderKeys, type CoreDrawOrderKey } from './draw_order.ts';\nimport { readEventKeys, type CoreEventDef, type CoreEventKey } from './events.ts';\nimport { worldTransforms } from './world.ts';\nimport { applyConstraints, constraintsAbsentWhy, pathAnimationsWhy, posedRecords, previousPassSlotBones, solverRules, type CoreConstraintRecord, type CoreConstraintTimelines } from './constraints.ts';\nimport { attachmentStates, deformAt, deformedVertices, timelineIdentity } from './deform.ts';\nimport { freshStepContext, stepPhysicsRecords, stepSchedule, steppedPreviousPassWhy, type PhysicsStepContext } from './constraints_physics.ts';\nimport { drawOrderAt } from './draw_order.ts';\nimport { eventsFired, type CoreEventRow } from './events.ts';\nimport { poseGeometry, type CoreAttachmentRow, type CoreClipRow } from './vertices.ts';\nimport type { CoreClippedRow } from './clipping.ts';\nimport type { CoreWorld } from './world.ts';\nimport { applySliderSlots, type SliderApplication } from './constraints_slider.ts';\nimport { slotTimelinesApply } from './skins.ts';\nimport {\n activeBones,\n constraintRecords,\n CoreInputError,\n drawWalkOf,\n foldInheritMode,\n gridRound,\n readBlend,\n shownAttachment,\n shownRow,\n slidersKeyingWhy,\n sourceOfDoc,\n viewColours,\n WHITE,\n type CompiledDocument,\n type CoreAnimation,\n type CoreBoneRow,\n type CorePlant,\n type CoreSkin,\n type CoreSlotRow,\n} from './index.ts';\n\n/** The bone timelines that key numbers, and the channels each key carries, in the order a curve indexes them. */\nexport const BONE_TIMELINE_CHANNELS = {\n rotate: ['value'],\n translate: ['x', 'y'],\n translatex: ['value'],\n translatey: ['value'],\n scale: ['x', 'y'],\n scalex: ['value'],\n scaley: ['value'],\n shear: ['x', 'y'],\n shearx: ['value'],\n sheary: ['value'],\n} as const satisfies Record<string, readonly string[]>;\nexport type BoneNumberKind = keyof typeof BONE_TIMELINE_CHANNELS;\n\n/** Every bone timeline this construct poses: the ten that key numbers, and `inherit`. */\nexport const BONE_TIMELINE_KINDS = [...(Object.keys(BONE_TIMELINE_CHANNELS) as BoneNumberKind[]), 'inherit'] as const;\nexport type BoneTimelineKind = (typeof BONE_TIMELINE_KINDS)[number];\n\n/**\n * The slot timelines that key a colour: the key fields the writer spells each\n * with (`COLOUR_KEYS` in `src/compile.ts`), each field's hex length, and the\n * channels they carry, in the order a curve indexes them.\n */\nexport const SLOT_COLOUR_TIMELINES = {\n rgba: { fields: [['color', 8]], channels: ['r', 'g', 'b', 'a'] },\n rgb: { fields: [['color', 6]], channels: ['r', 'g', 'b'] },\n alpha: { fields: [], channels: ['a'] },\n rgba2: { fields: [['light', 8], ['dark', 6]], channels: ['r', 'g', 'b', 'a', 'r2', 'g2', 'b2'] },\n rgb2: { fields: [['light', 6], ['dark', 6]], channels: ['r', 'g', 'b', 'r2', 'g2', 'b2'] },\n} as const satisfies Record<string, { fields: ReadonlyArray<readonly [string, number]>; channels: readonly string[] }>;\nexport type SlotColourKind = keyof typeof SLOT_COLOUR_TIMELINES;\n\n/** Every slot timeline this construct poses. */\nexport const SLOT_TIMELINE_KINDS = ['attachment', ...(Object.keys(SLOT_COLOUR_TIMELINES) as SlotColourKind[])] as const;\nexport type SlotTimelineKind = (typeof SLOT_TIMELINE_KINDS)[number];\n\n/**\n * The groups of an animation after its bones and slots, in the document's\n * order: the constraint timelines (construct 5, `./constraints.ts`) and this\n * construct's remainder — attachment timelines (`./deform.ts`), the draw\n * order (`./draw_order.ts`) and events (`./events.ts`). Every key time in\n * them sets the runtime's duration.\n */\nexport const LATER_GROUPS = ['constraints', 'attachments', 'drawOrder', 'events'] as const;\n\n/** A key's curve as read: linear, a hold, or four float32 numbers per channel. */\nexport type CoreCurve = 'linear' | 'stepped' | number[];\n\n/**\n * One key, as read: its time and channels as the runtime stores them\n * (float32), the same two as the document states them (the doubles the file's\n * text parses to — what a Bézier's polyline is computed from, the header's\n * measurement), its curve, and a name or mode where the kind keys one.\n */\nexport interface CoreKey {\n time: number;\n values: number[];\n stated: { time: number; values: number[] };\n curve: CoreCurve;\n /** An attachment key's placeholder (`null` shows nothing). */\n name?: string | null;\n /** An inherit key's mode, folded. */\n mode?: string;\n}\n\nexport interface CoreTimeline<K extends string> {\n kind: K;\n keys: CoreKey[];\n}\n\nexport interface CoreTarget<K extends string> {\n name: string;\n timelines: Array<CoreTimeline<K>>;\n}\n\n/**\n * One animation's timelines, as far as this construct reads them: the bone\n * and slot timelines in full, and of every later group only how many\n * timelines it holds and its key times (which set the runtime's duration).\n */\nexport interface CoreAnimationTimelines {\n /** The model's declared duration. */\n declared: number;\n /** The runtime's duration: the last key time of every timeline, as float32 — the header's rule. */\n duration: number;\n bones: Array<CoreTarget<BoneTimelineKind>>;\n slots: Array<CoreTarget<SlotTimelineKind>>;\n /** Timelines per later group, in `LATER_GROUPS` order; a group holding none is not listed. */\n later: Array<[(typeof LATER_GROUPS)[number], number]>;\n /** The deform and sequence timelines, each attachment's (`./deform.ts`). */\n attachments: CoreAttachmentTimeline[];\n /** The draw-order keys (`./draw_order.ts`); empty where the animation keys none. */\n drawOrder: CoreDrawOrderKey[];\n /** The event keys (`./events.ts`); empty where the animation fires none. */\n events: CoreEventKey[];\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nconst isHex = (v: unknown, digits: number): v is string => typeof v === 'string' && v.length === digits && /^[0-9a-fA-F]+$/.test(v);\n\n/** A key's time: finite, not negative, float32 as the runtime stores it — or a problem. */\nfunction keyTime(raw: Record<string, unknown>, where: string, problems: string[]): number | null {\n const time = raw.time;\n if (typeof time !== 'number' || !Number.isFinite(time) || time < 0) {\n problems.push(`${where}: time is ${JSON.stringify(time)}, not a finite time at or after 0`);\n return null;\n }\n return time;\n}\n\n/** A list of keys, each an object with a strictly later time than the one before — the writer's rule. */\nfunction keyList(value: unknown, where: string, problems: string[]): Array<{ raw: Record<string, unknown>; at: string; time: number }> {\n if (!Array.isArray(value) || value.length === 0) {\n problems.push(`${where}: keys is not a non-empty list`);\n return [];\n }\n const out: Array<{ raw: Record<string, unknown>; at: string; time: number }> = [];\n let last = -Infinity;\n value.forEach((raw, i) => {\n const at = `${where}.keys[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${at} is not an object`);\n return;\n }\n const time = keyTime(raw, at, problems);\n if (time === null) return;\n if (time <= last) problems.push(`${at}: time ${raw.time} is not after the key before it — the writer refuses key times that do not strictly increase`);\n last = Math.max(last, time);\n out.push({ raw, at, time });\n });\n return out;\n}\n\nfunction unknownKeyFields(raw: Record<string, unknown>, known: readonly string[], at: string, problems: string[]): void {\n for (const key of Object.keys(raw)) if (!known.includes(key)) problems.push(`${at}: field \"${key}\" is not one this timeline's keys carry; they carry [${known.join(', ')}]`);\n}\n\n/** A key's curve: absent (linear), `stepped`, or 4 finite numbers per channel; never on the last key. */\nfunction readCurve(raw: Record<string, unknown>, channels: number, last: boolean, at: string, problems: string[]): CoreCurve {\n const curve = raw.curve;\n if (curve === undefined) return 'linear';\n if (last) {\n problems.push(`${at}: the last key carries a curve, which eases to no key — the writer refuses it`);\n return 'linear';\n }\n if (curve === 'stepped') return 'stepped';\n if (!Array.isArray(curve) || curve.length !== channels * 4 || !curve.every((n) => typeof n === 'number' && Number.isFinite(n))) {\n problems.push(`${at}: curve is ${JSON.stringify(curve)}, not \"stepped\" nor ${channels * 4} finite numbers (four per channel)`);\n return 'linear';\n }\n return curve as number[];\n}\n\nfunction readBoneTimeline(kind: BoneTimelineKind, keysValue: unknown, where: string, problems: string[]): CoreKey[] {\n const listed = keyList(keysValue, where, problems);\n return listed.map(({ raw, at, time }, i): CoreKey => {\n if (kind === 'inherit') {\n unknownKeyFields(raw, ['time', 'inherit'], at, problems);\n const mode = typeof raw.inherit === 'string' ? foldInheritMode(raw.inherit) : null;\n if (mode === null) problems.push(`${at}: inherit is ${JSON.stringify(raw.inherit)}, which folds to no inherit mode`);\n return { time: Math.fround(time), values: [], stated: { time, values: [] }, curve: 'stepped', mode: mode ?? 'normal' };\n }\n const channels: readonly string[] = BONE_TIMELINE_CHANNELS[kind];\n unknownKeyFields(raw, ['time', ...channels, 'curve'], at, problems);\n const values = channels.map((c) => {\n const v = raw[c];\n if (typeof v !== 'number' || !Number.isFinite(v)) {\n problems.push(`${at}: ${c} is ${JSON.stringify(v)}, not a finite number — the writer states every channel on every key`);\n return 0;\n }\n return v;\n });\n return { time: Math.fround(time), values: values.map(Math.fround), stated: { time, values }, curve: readCurve(raw, channels.length, i === listed.length - 1, at, problems) };\n });\n}\n\n/** A hex spelling's channels, each byte over 255 (the stated values; the runtime stores each float32). */\nfunction hexChannels(hex: string, count: number): number[] {\n const out: number[] = [];\n for (let i = 0; i < count; i++) out.push(Number.parseInt(hex.slice(2 * i, 2 * i + 2), 16) / 255);\n return out;\n}\n\nfunction readSlotTimeline(kind: SlotTimelineKind, keysValue: unknown, where: string, problems: string[]): CoreKey[] {\n const listed = keyList(keysValue, where, problems);\n return listed.map(({ raw, at, time }, i): CoreKey => {\n if (kind === 'attachment') {\n unknownKeyFields(raw, ['time', 'name'], at, problems);\n if (raw.name !== null && (typeof raw.name !== 'string' || raw.name === '')) problems.push(`${at}: name is ${JSON.stringify(raw.name)}, not a placeholder name or null`);\n return { time: Math.fround(time), values: [], stated: { time, values: [] }, curve: 'stepped', name: typeof raw.name === 'string' ? raw.name : null };\n }\n const shape: { fields: ReadonlyArray<readonly [string, number]>; channels: readonly string[] } = SLOT_COLOUR_TIMELINES[kind];\n let values: number[] = [];\n if (kind === 'alpha') {\n unknownKeyFields(raw, ['time', 'value', 'curve'], at, problems);\n const v = raw.value;\n if (typeof v !== 'number' || !Number.isFinite(v)) problems.push(`${at}: value is ${JSON.stringify(v)}, not a finite number`);\n else values = [v];\n } else {\n unknownKeyFields(raw, ['time', ...shape.fields.map(([f]) => f), 'curve'], at, problems);\n for (const [field, digits] of shape.fields) {\n const v = raw[field];\n if (!isHex(v, digits)) problems.push(`${at}: ${field} is ${JSON.stringify(v)}, not ${digits} hex digits — the one spelling the writer gives a ${kind} key's ${field}`);\n else values.push(...hexChannels(v, field === 'dark' || digits === 6 ? 3 : 4));\n }\n }\n if (values.length !== shape.channels.length) values = shape.channels.map(() => 0);\n return { time: Math.fround(time), values: values.map(Math.fround), stated: { time, values }, curve: readCurve(raw, shape.channels.length, i === listed.length - 1, at, problems) };\n });\n}\n\n/** Every key time under an animation's `constraints` group, for the runtime's duration; a time that is not a finite number is a problem. */\nfunction constraintKeyTimes(value: unknown, where: string, problems: string[]): { timelines: number; times: number[] } {\n const times: number[] = [];\n let timelines = 0;\n const keys = (list: unknown, at: string): void => {\n timelines++;\n if (!Array.isArray(list)) {\n problems.push(`${at} is not a list of keys`);\n return;\n }\n list.forEach((k, i) => {\n if (!isRecord(k)) problems.push(`${at}[${i}] is not an object`);\n else {\n const t = keyTime(k, `${at}[${i}]`, problems);\n if (t !== null) times.push(Math.fround(t));\n }\n });\n };\n const named = (list: unknown, at: string, each: (entry: Record<string, unknown>, at: string) => void): void => {\n if (!Array.isArray(list)) {\n problems.push(`${at} is not a list`);\n return;\n }\n list.forEach((entry, i) => (isRecord(entry) ? each(entry, `${at}[${i}]`) : problems.push(`${at}[${i}] is not an object`)));\n };\n if (!isRecord(value)) problems.push(`${where} is not an object`);\n else {\n for (const kind of ['ik', 'transform'] as const) named(value[kind], `${where}.${kind}`, (e, at) => keys(e.keys, `${at}.keys`));\n for (const kind of ['path', 'physics', 'slider'] as const) named(value[kind], `${where}.${kind}`, (e, at) => named(e.timelines, `${at}.timelines`, (tl, at2) => keys(tl.keys, `${at2}.keys`)));\n }\n return { timelines, times };\n}\n\n/**\n * One animation record's timelines, read and checked: every bone and slot\n * timeline in full — a target that is not a bone or slot of the document, a\n * kind that is not one of this construct's, a kind keyed twice on one target,\n * a key missing a channel or spelling one otherwise than the writer does, a\n * curve of the wrong length or on the last key, times that do not increase,\n * and `rgba2`/`rgb2` on a slot with no dark colour are each a problem, named —\n * and of the later groups only their key times.\n */\nexport function readAnimationTimelines(\n raw: Record<string, unknown>,\n label: string,\n bones: ReadonlySet<string>,\n slots: readonly ModelSlot[],\n problems: string[],\n context: { skins: readonly CoreSkin[]; events: ReadonlyMap<string, CoreEventDef> },\n): CoreAnimationTimelines {\n const declared = typeof raw.duration === 'number' && Number.isFinite(raw.duration) ? raw.duration : 0;\n if (typeof raw.duration !== 'number' || !Number.isFinite(raw.duration)) problems.push(`${label}: duration is ${JSON.stringify(raw.duration)}, not a finite number`);\n const slotByName = new Map(slots.map((s) => [s.name, s]));\n const times: number[] = [];\n const targets = <K extends string>(group: 'bones' | 'slots', kinds: readonly K[], known: (name: string) => string | null, read: (kind: K, keys: unknown, at: string, target: string) => CoreKey[]): Array<CoreTarget<K>> => {\n const value = raw[group];\n const out: Array<CoreTarget<K>> = [];\n if (!Array.isArray(value)) {\n problems.push(`${label}: ${group} is not a list`);\n return out;\n }\n value.forEach((entry, i) => {\n const at = `${label}.${group}[${i}]`;\n if (!isRecord(entry) || typeof entry.name !== 'string') {\n problems.push(`${at} names no target`);\n return;\n }\n const where = `${at} \"${entry.name}\"`;\n const miss = known(entry.name);\n if (miss !== null) problems.push(`${where}: ${miss}`);\n if (!Array.isArray(entry.timelines)) {\n problems.push(`${where}: timelines is not a list`);\n return;\n }\n const name = entry.name;\n const target: CoreTarget<K> = { name, timelines: [] };\n entry.timelines.forEach((tl, j) => {\n const tat = `${where}.timelines[${j}]`;\n if (!isRecord(tl) || typeof tl.name !== 'string') {\n problems.push(`${tat} names no timeline`);\n return;\n }\n const kind = kinds.find((k) => k === tl.name);\n if (kind === undefined) {\n problems.push(`${tat}: \"${tl.name}\" is not a ${group === 'bones' ? 'bone' : 'slot'} timeline this core reads; it reads [${kinds.join(', ')}]`);\n return;\n }\n if (target.timelines.some((x) => x.kind === kind)) problems.push(`${tat}: \"${kind}\" is keyed twice on ${name} — the writer merges one property's tracks into one`);\n const keys = read(kind, tl.keys, `${tat} \"${kind}\"`, name);\n for (const k of keys) times.push(k.time);\n target.timelines.push({ kind, keys });\n });\n out.push(target);\n });\n return out;\n };\n const boneTargets = targets('bones', BONE_TIMELINE_KINDS, (n) => (bones.has(n) ? null : `\"${n}\" is not a bone of this document`), (kind, keys, at) => readBoneTimeline(kind, keys, at, problems));\n const slotTargets = targets('slots', SLOT_TIMELINE_KINDS, (n) => (slotByName.has(n) ? null : `\"${n}\" is not a slot of this document`), (kind, keys, at, slot) => {\n if ((kind === 'rgba2' || kind === 'rgb2') && slotByName.get(slot)?.dark === undefined) {\n problems.push(`${at}: slot \"${slot}\" states no dark colour, and a ${kind} timeline on such a slot makes the runtime throw while it is applied — the writer refuses it`);\n }\n return readSlotTimeline(kind, keys, at, problems);\n });\n const later: CoreAnimationTimelines['later'] = [];\n // The constraint timelines' key times only (construct 5 reads them, `./constraints.ts`); the other three groups are read in full here.\n const constraintTimes = constraintKeyTimes(raw.constraints, `${label}.constraints`, problems);\n times.push(...constraintTimes.times);\n if (constraintTimes.timelines > 0) later.push(['constraints', constraintTimes.timelines]);\n const attachments = readAttachmentTimelines(raw.attachments, label, context.skins, problems);\n const drawOrder = readDrawOrderKeys(raw.drawOrder, label, slots, problems);\n const events = readEventKeys(raw.events, label, context.events, problems);\n for (const a of attachments) for (const k of [...(a.deform ?? []), ...(a.sequence ?? [])]) times.push(k.time);\n for (const k of [...drawOrder, ...events]) times.push(k.time);\n const attachmentTimelines = attachments.reduce((n, a) => n + (a.deform === null ? 0 : 1) + (a.sequence === null ? 0 : 1), 0);\n if (attachmentTimelines > 0) later.push(['attachments', attachmentTimelines]);\n if (drawOrder.length > 0) later.push(['drawOrder', 1]);\n if (events.length > 0) later.push(['events', 1]);\n return { declared, duration: times.length === 0 ? 0 : Math.max(...times), bones: boneTargets, slots: slotTargets, later, attachments, drawOrder, events };\n}\n\n// ---------------------------------------------------------------------------\n// evaluation\n// ---------------------------------------------------------------------------\n\n/**\n * The one-sixth of the third forward difference, as the header measured it:\n * the eight-digit decimal, which alone of the spellings tried reproduced\n * 82,731 samples of 60 random Bézier segments and 18,430 of 300 corpus\n * segments at the oracle's rounding.\n */\nexport const BEZIER_SIXTH = 0.16666667;\n/** Pieces of the runtime's polyline per Bézier segment — the header's ten slope runs. */\nexport const BEZIER_PIECES = 10;\n\n/**\n * The nine interior points of one channel's Bézier segment, `[t1, v1, …, t9,\n * v9]`, each float32: the cubic from `(t0, v0)` through the handles to `(t3,\n * v3)` — every one of the eight the number the document states, not its\n * float32 (the header's second measurement) — at its parameter `u = 0.1 …\n * 0.9`, by forward differences at the step\n * h = 1/10. With `p` the four control numbers of one coordinate, the second\n * difference is `3h²(p0 − 2p1 + p2)` and the third `6h³(3(p1 − p2) − p0 + p3)`;\n * the first starts at `3h(p1 − p0)` plus the second plus the third times\n * `BEZIER_SIXTH`; each step adds the first to the point, the second to the\n * first and the third to the second (the header's measurement fixes the\n * order of those additions and the constant).\n */\nexport function bezierPolyline(t0: number, v0: number, cx1: number, cy1: number, cx2: number, cy2: number, t3: number, v3: number): number[] {\n const walk = (p0: number, p1: number, p2: number, p3: number): number[] => {\n const second = (p0 - 2 * p1 + p2) * 0.03;\n const third = ((p1 - p2) * 3 - p0 + p3) * 0.006;\n let first = (p1 - p0) * 0.3 + second + third * BEZIER_SIXTH;\n let d2 = second * 2 + third;\n let at = p0;\n const out: number[] = [];\n for (let i = 1; i < BEZIER_PIECES; i++) {\n at += first;\n first += d2;\n d2 += third;\n out.push(Math.fround(at));\n }\n return out;\n };\n const ts = walk(t0, cx1, cx2, t3);\n const vs = walk(v0, cy1, cy2, v3);\n const out: number[] = [];\n for (let i = 0; i < ts.length; i++) out.push(ts[i], vs[i]);\n return out;\n}\n\n/** What evaluates one channel of a segment: `channelAt` unless a plant passes another. */\nexport type ChannelEvaluator = (keys: readonly CoreKey[], index: number, channel: number, t: number) => number;\n\n/** What finds the key a time falls on: `keyIndexAt` unless a plant passes another. */\nexport type KeySearch = (keys: readonly CoreKey[], t: number) => number;\n\n/** The last key at or before `t`, or −1 before the first — the header's key search. */\nexport function keyIndexAt(keys: ReadonlyArray<{ time: number }>, t: number): number {\n let found = -1;\n for (let i = 0; i < keys.length; i++) {\n if (keys[i].time <= t) found = i;\n else break;\n }\n return found;\n}\n\n/**\n * Each Bézier segment's polylines, one per channel, kept with the key that\n * starts the segment and the key that ends it (issue #1134): a polyline is a\n * function of those two keys' stated numbers and handles only, and a walk\n * evaluated the same segment's on every step. A key read is never written; a\n * plant that changes a key passes a copy, which keeps polylines of its own.\n */\nconst segmentPolylines = new WeakMap<CoreKey, { end: CoreKey; channels: Array<number[] | undefined> }>();\n\n/** Channel `channel` of the segment starting at key `index` (not the last), at `t` — the header's three curves. */\nexport function channelAt(keys: readonly CoreKey[], index: number, channel: number, t: number): number {\n const a = keys[index];\n const b = keys[index + 1];\n if (b === undefined || a.curve === 'stepped') return a.values[channel];\n if (a.curve === 'linear') return a.values[channel] + ((t - a.time) / (b.time - a.time)) * (b.values[channel] - a.values[channel]);\n let kept = segmentPolylines.get(a);\n if (kept === undefined || kept.end !== b) {\n kept = { end: b, channels: [] };\n segmentPolylines.set(a, kept);\n }\n let points = kept.channels[channel];\n if (points === undefined) {\n const c = a.curve.slice(channel * 4, channel * 4 + 4);\n const inner = bezierPolyline(a.stated.time, a.stated.values[channel], c[0], c[1], c[2], c[3], b.stated.time, b.stated.values[channel]);\n points = [a.time, a.values[channel], ...inner, b.time, b.values[channel]];\n kept.channels[channel] = points;\n }\n let i = 2;\n while (i < points.length - 2 && points[i] < t) i += 2;\n const [x0, y0, x1, y1] = [points[i - 2], points[i - 1], points[i], points[i + 1]];\n return y0 + ((t - x0) / (x1 - x0)) * (y1 - y0);\n}\n\n/** Every plant this construct takes, beside the setup constructs' own (`CorePlant`). */\nexport interface TimelinePlant extends CorePlant {\n channel?: ChannelEvaluator;\n search?: KeySearch;\n}\n\n/** A timeline's channels at `t`, or `null` before its first key (the channels are then at setup). */\nfunction valuesAt(keys: readonly CoreKey[], t: number, plant: TimelinePlant): number[] | null {\n const index = (plant.search ?? keyIndexAt)(keys, t);\n if (index < 0) return null;\n const channel = plant.channel ?? channelAt;\n return keys[index].values.map((_v, c) => channel(keys, index, c, t));\n}\n\n/** The key a stepped-by-nature timeline (attachment, inherit) shows at `t`, or `null` before its first key. */\nfunction keyAt(keys: readonly CoreKey[], t: number, plant: TimelinePlant): CoreKey | null {\n const index = (plant.search ?? keyIndexAt)(keys, t);\n return index < 0 ? null : keys[index];\n}\n\n/** Each animation's bone timelines by bone name, kept with the timelines they index (`posedBones`). */\nconst boneTimelinesByName = new WeakMap<CoreAnimationTimelines, ReadonlyMap<string, CoreTarget<BoneTimelineKind>>>();\n\n/** The animation's bone timelines by bone name, built once per timelines object (issue #1134: a walk built it again on every step); timelines read are never written. */\nfunction boneTimelinesOf(timelines: CoreAnimationTimelines): ReadonlyMap<string, CoreTarget<BoneTimelineKind>> {\n let byName = boneTimelinesByName.get(timelines);\n if (byName === undefined) {\n byName = new Map(timelines.bones.map((b) => [b.name, b]));\n boneTimelinesByName.set(timelines, byName);\n }\n return byName;\n}\n\n/** The bones posed by the animation's bone timelines at `t`: copies of the setup bones with the posed fields — the header's rules. */\nexport function posedBones(doc: CompiledDocument, timelines: CoreAnimationTimelines, t: number, plant: TimelinePlant = {}): ModelBone[] {\n const byName = boneTimelinesOf(timelines);\n return doc.bones.map((setup) => {\n const target = byName.get(setup.name);\n if (target === undefined) return setup;\n const bone: ModelBone = { ...setup };\n for (const tl of target.timelines) {\n if (tl.kind === 'inherit') {\n const key = keyAt(tl.keys, t, plant);\n if (key === null) {\n if (setup.inheritMode === undefined) delete bone.inheritMode;\n else bone.inheritMode = setup.inheritMode;\n } else bone.inheritMode = key.mode;\n continue;\n }\n const v = valuesAt(tl.keys, t, plant);\n const add = (field: 'x' | 'y' | 'rotation' | 'shearX' | 'shearY', i: number): void => {\n bone[field] = (setup[field] ?? 0) + (v === null ? 0 : v[i]);\n };\n const times = (field: 'scaleX' | 'scaleY', i: number): void => {\n bone[field] = (setup[field] ?? 1) * (v === null ? 1 : v[i]);\n };\n switch (tl.kind) {\n case 'rotate': add('rotation', 0); break;\n case 'translate': add('x', 0); add('y', 1); break;\n case 'translatex': add('x', 0); break;\n case 'translatey': add('y', 0); break;\n case 'shear': add('shearX', 0); add('shearY', 1); break;\n case 'shearx': add('shearX', 0); break;\n case 'sheary': add('shearY', 0); break;\n case 'scale': times('scaleX', 0); times('scaleY', 1); break;\n case 'scalex': times('scaleX', 0); break;\n case 'scaley': times('scaleY', 0); break;\n }\n }\n return bone;\n });\n}\n\n/**\n * A player's bone-local adjustment (issue #1336): a function the live track\n * (`openTrack`'s `adjust`, `./track.ts`) calls once per pose, after the\n * animation's timelines have posed the bone locals at the step's time and\n * before the world transforms, the constraints and the physics step — so a\n * write is what the rest of the step reads: the bone's children, the\n * attachments drawn through it, every constraint and the physics constraint\n * stepped on top of it. It is spine-core's \"application code\" writing\n * `Bone.pose` between `AnimationState.apply` and `updateWorldTransform`\n * (`CO50` holds the two equal at tolerance 0).\n *\n * - **The view is the step's locals, posed from the setup pose.** Every pose\n * of a walk is posed from the setup pose at its time (`./raw.ts`,\n * `TrackState`), so a write lives for the pose it was written in and the\n * next step's hook reads the timelines' value again, not the write. A\n * channel no timeline keys reads its setup value on every step.\n * - **A bone the hook does not write is untouched**: the timelines' bone\n * object as it was, the setup bone itself where nothing keys it. A written\n * bone is copied before the write, so the document is never written.\n * - **A write that is not a finite number is refused by name**, the bone, the\n * channel and the value — where the core refuses a non-finite value, by\n * name, rather than posing a picture with it (`finite` in `./raw.ts`).\n */\nexport interface BoneLocals {\n rotation: number;\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n shearX: number;\n shearY: number;\n}\n\n/** The locals of a step's bones, by name (`BoneLocals`). */\nexport interface AdjustableLocals {\n /** The document's bones, in its order. */\n readonly names: readonly string[];\n /** One bone's locals, read and written in place; a name the document has no bone for is refused by name. */\n bone(name: string): BoneLocals;\n}\n\n/** The pose being adjusted (issue #1540), independent of the physics clock. */\nexport interface LocalAdjustContext {\n /** Current track-0 entry's unwrapped seconds, starting at 0; null without that entry. */\n readonly trackTime: number | null;\n /** That same entry's animation name; null without it or for an explicit empty entry. */\n readonly animation: string | null;\n /** Running sum of this walk's steps, in seconds; never the physics clock. */\n readonly globalTime: number;\n}\n\n/** Called once per evaluated pose, after track composition and before world transforms and physics. Unary callbacks remain assignable. */\nexport type LocalAdjust = (locals: AdjustableLocals, ctx: LocalAdjustContext) => void;\n\n/** The seven channels a `BoneLocals` reads and writes, each with the value an unstated one reads as (`worldTransforms`' defaults). */\nconst LOCAL_CHANNELS = { rotation: 0, x: 0, y: 0, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 } as const;\ntype LocalChannel = keyof typeof LOCAL_CHANNELS;\n\n/** One bone of a step's `bones`, read through and written through, copied on its first write (`BoneLocals`' second rule). */\nclass StepLocals implements BoneLocals {\n constructor(\n private readonly bones: ModelBone[],\n private readonly index: number,\n private readonly setup: ModelBone,\n ) {}\n\n private read(channel: LocalChannel): number {\n return this.bones[this.index][channel] ?? LOCAL_CHANNELS[channel];\n }\n\n private write(channel: LocalChannel, value: number): void {\n if (typeof value !== 'number' || !Number.isFinite(value)) throw new CoreInputError(`the adjustment wrote bone \"${this.setup.name}\" ${channel} = ${String(value)}, not a finite number`);\n if (this.bones[this.index] === this.setup) this.bones[this.index] = { ...this.setup };\n this.bones[this.index][channel] = value;\n }\n\n get rotation(): number { return this.read('rotation'); }\n set rotation(v: number) { this.write('rotation', v); }\n get x(): number { return this.read('x'); }\n set x(v: number) { this.write('x', v); }\n get y(): number { return this.read('y'); }\n set y(v: number) { this.write('y', v); }\n get scaleX(): number { return this.read('scaleX'); }\n set scaleX(v: number) { this.write('scaleX', v); }\n get scaleY(): number { return this.read('scaleY'); }\n set scaleY(v: number) { this.write('scaleY', v); }\n get shearX(): number { return this.read('shearX'); }\n set shearX(v: number) { this.write('shearX', v); }\n get shearY(): number { return this.read('shearY'); }\n set shearY(v: number) { this.write('shearY', v); }\n}\n\n/** The adjustment run over a step's `bones` (`posedBones`' array, in the document's order), which it may replace bone by bone (`BoneLocals`). */\nfunction adjustLocals(doc: CompiledDocument, bones: ModelBone[], adjust: LocalAdjust, context: LocalAdjustContext): void {\n const views = new Map<string, StepLocals>();\n const names = doc.bones.map((b) => b.name);\n adjust({\n names,\n bone(name: string): BoneLocals {\n let view = views.get(name);\n if (view === undefined) {\n const index = names.indexOf(name);\n if (index < 0) throw new CoreInputError(`the adjustment asked for bone ${JSON.stringify(name)}, which is not one of this document's bones`);\n // A copy the timelines made is this step's own; the setup bone is the document's, copied on its first write.\n view = new StepLocals(bones, index, doc.bones[index]);\n views.set(name, view);\n }\n return view;\n },\n }, context);\n}\n\nconst clamp01 = (v: number): number => (v < 0 ? 0 : v > 1 ? 1 : v);\n\n/**\n * The slot rows at `t`, in the oracle's shape and rounding, or the conflicts\n * that leave them out: a slot showing a placeholder several skins fill\n * differently (the setup slots' ⚠️, `shownAttachment`).\n */\nexport function posedSlots(\n doc: CompiledDocument,\n timelines: CoreAnimationTimelines,\n t: number,\n plant: TimelinePlant = {},\n sliders: readonly SliderApplication[] = [],\n /** Filled with each slot's placeholder once the sample's own timelines have moved it, before the sliders — what the attachments are posed from (`attachmentStates`). */\n placeholders?: Map<string, string | null>,\n): { rows: CoreSlotRow[]; conflicts: string[] } {\n // The view's stated colours, read once (`viewColours`); a planted reader of the light colour is called as it always was.\n const stated = viewColours(doc);\n const colour = plant.colour ?? stated;\n const byName = new Map(timelines.slots.map((s) => [s.name, s]));\n return slotRowsFrom(doc, plant, sliders, placeholders, (slot, live) => {\n let placeholder = slot.setup;\n const setupLight = slot.color === undefined ? WHITE : colour(slot.color);\n const light = [setupLight[0], setupLight[1], setupLight[2], setupLight[3]];\n const setupDark = slot.dark === undefined ? null : stated(slot.dark);\n const dark = setupDark === null ? null : [setupDark[0], setupDark[1], setupDark[2]];\n for (const tl of live ? (byName.get(slot.name)?.timelines ?? []) : []) {\n if (tl.kind === 'attachment') {\n const key = keyAt(tl.keys, t, plant);\n placeholder = key === null ? slot.setup : (key.name ?? null);\n continue;\n }\n const v = valuesAt(tl.keys, t, plant);\n const channels = SLOT_COLOUR_TIMELINES[tl.kind].channels;\n channels.forEach((name, i) => {\n const at = { r: 0, g: 1, b: 2, a: 3, r2: 4, g2: 5, b2: 6 }[name];\n if (at < 4) light[at] = v === null ? setupLight[at] : clamp01(v[i]);\n else if (dark !== null && setupDark !== null) dark[at - 4] = v === null ? setupDark[at - 4] : clamp01(v[i]);\n });\n }\n return { placeholder, light, dark };\n });\n}\n\n/**\n * What a slot holds once the timelines have posed it and before the sliders:\n * the placeholder it shows, its light colour and its dark one (`null` where\n * the slot states none). `posedSlots` reads it off one animation at `t`; the\n * live tracks off their mixed entries (`./tracks.ts`, issue #1336).\n */\nexport interface SlotBase {\n placeholder: string | null;\n light: number[];\n dark: number[] | null;\n}\n\n/**\n * The slot rows from each slot's `SlotBase` — `baseOf`, called once per slot\n * in the document's order with whether the slot is animated at all — then the\n * sliders, the resolution and the oracle's row: `posedSlots`' body past the\n * timelines, which the live tracks share (`./tracks.ts`).\n */\nexport function slotRowsFrom(\n doc: CompiledDocument,\n plant: TimelinePlant,\n sliders: readonly SliderApplication[],\n placeholders: Map<string, string | null> | undefined,\n baseOf: (slot: ModelSlot, live: boolean) => SlotBase,\n): { rows: CoreSlotRow[]; conflicts: string[] } {\n const resolve = plant.shown ?? shownAttachment;\n const blend = plant.blend ?? readBlend;\n const round = plant.round ?? gridRound;\n const rows: CoreSlotRow[] = [];\n const conflicts: string[] = [];\n const active = activeBones(doc);\n const gate = plant.slotTimelines ?? slotTimelinesApply;\n for (const slot of doc.slots) {\n // A slot on a bone the skin leaves inactive is not animated — not by the sample's timelines, not by a slider (`./skins.ts`).\n const live = gate(doc, slot, active);\n const base = baseOf(slot, live);\n let placeholder = base.placeholder;\n const { light, dark } = base;\n // The sliders, after the animation, in constraint order (`./constraints_slider.ts`).\n // What the slot shows after the sample's own timelines: the attachments' deform and sequence timelines are matched against it (`./deform.ts`, *A switch*).\n placeholders?.set(slot.name, placeholder);\n const pose = { placeholder, light, dark };\n if (live) applySliderSlots(slot.name, pose, sliders);\n placeholder = pose.placeholder;\n const shown = placeholder === null ? null : resolve(doc, { ...slot, setup: placeholder });\n if (shown !== null && 'conflict' in shown) {\n conflicts.push(`slot \"${slot.name}\" shows placeholder \"${placeholder}\", filled by skins ${shown.conflict.map((c) => `\"${c.skin}\" (shows ${JSON.stringify(c.shown)})`).join(', ')}`);\n continue;\n }\n const row = shown === null ? null : shownRow(shown);\n rows.push([\n slot.name,\n row === null ? null : row.name,\n round(light[0]), round(light[1]), round(light[2]), round(light[3]),\n dark === null ? null : [round(dark[0]), round(dark[1]), round(dark[2])],\n row === null ? null : row.path,\n // The slot's data, not its pose: no timeline moves it (the index header's blend rule).\n blend(slot),\n ]);\n }\n return { rows, conflicts };\n}\n\n/**\n * One step of the stepped phase, as a walk hands it to the bones: the physics\n * context and the clock before the step (`./constraints_physics.ts`), and the\n * caller's adjustment of the locals (`LocalAdjust`). The adjustment rides here\n * rather than on the plant because it is not a rule the core measured and a\n * control plants back — it is the caller's input to one walk — and because\n * the step context exists exactly where a walk is stepped: the live track's\n * every pose but a `reset: 'setup'` pose 0, which no animation is applied to.\n */\nexport interface PoseStep {\n ctx: PhysicsStepContext;\n before: number;\n /** Callback and its authoritative evaluation identity travel together; no inferred clock fallback. */\n adjustment?: { callback: LocalAdjust; context: LocalAdjustContext };\n}\n\n/**\n * The bone rows at `t`, in the oracle's shape and rounding. With `constraints`\n * — the animation's constraint timelines — the document's constraints are\n * applied after the timelines, posed at `t` (`./constraints.ts`, construct\n * 5; each slider's application recorded into `sliders` for its slot\n * timelines), with the setup pose standing for the\n * previous pose a path's offset may read (`previousPassWhy` holds that);\n * without, the hierarchy and the timelines alone.\n */\nexport function posedBoneRows(doc: CompiledDocument, timelines: CoreAnimationTimelines, t: number, plant: TimelinePlant = {}, constraints?: CoreConstraintTimelines, sliders?: SliderApplication[]): CoreBoneRow[] {\n return posedBoneWorld(doc, timelines, t, plant, constraints, sliders).rows;\n}\n\n/** `posedBoneRows`, with the world transforms the rows were read off — what the sample's attachments are posed through. */\nexport function posedBoneWorld(doc: CompiledDocument, timelines: CoreAnimationTimelines, t: number, plant: TimelinePlant = {}, constraints?: CoreConstraintTimelines, sliders?: SliderApplication[], step?: PoseStep): { rows: CoreBoneRow[]; world: Map<string, CoreWorld> } {\n const posed = posedBoneStep(doc, timelines, t, plant, constraints, sliders, step);\n const stage = plant.stage;\n if (stage !== undefined) stage.begin('readout');\n const rows = stepRows(posed);\n if (stage !== undefined) stage.end('readout');\n return { rows, world: posed.world };\n}\n\n/**\n * `posedBoneWorld`'s world transforms without its rows (issue #1179, the\n * second part): the same pose by the same operations in the same order, since\n * `stepRows` only reads the world once it is posed. A walk reads `world` and\n * no row, so every walk asks for this — the scan's (`scanWalkIn` in\n * `./raw.ts`, A10's), the raw entry's batch walks and the live track's step.\n * The rows were the only thing the other variant adds, and their rounding\n * (`rawNumber`, `keptNumber`) refuses nothing, so leaving them out moves no\n * number and no refusal of a walk.\n */\nexport function posedBoneWorldAlone(doc: CompiledDocument, timelines: CoreAnimationTimelines, t: number, plant: TimelinePlant, constraints: CoreConstraintTimelines | undefined, sliders: SliderApplication[] | undefined, step: PoseStep | undefined): Map<string, CoreWorld> {\n return posedBoneStep(doc, timelines, t, plant, constraints, sliders, step).world;\n}\n\n/**\n * One pose of the bones before its rows are read: the world transforms, and\n * what the rows are rounded from. A stepped walk reads rows only off the step\n * that lands on a sample (issue #1134: of the stepped run's poses, nine in ten\n * are steps between samples), so `stepRows` rounds them when they are read,\n * once; every bone's transform is required here, at every step.\n */\ninterface PosedStep {\n bones: ModelBone[];\n world: Map<string, CoreWorld>;\n active: ReadonlySet<string>;\n round: (v: number) => number | null;\n rows?: CoreBoneRow[];\n}\n\n/** A step's bone rows, in the oracle's shape and rounding, rounded the first time they are read. */\nfunction stepRows(posed: PosedStep): CoreBoneRow[] {\n if (posed.rows !== undefined) return posed.rows;\n const { world, active, round } = posed;\n posed.rows = posed.bones.map((b): CoreBoneRow => {\n const w = world.get(b.name) as CoreWorld;\n return [b.name, round(w.worldX), round(w.worldY), round(w.a), round(w.b), round(w.c), round(w.d), active.has(b.name) ? 1 : 0, b.parent ?? null];\n });\n return posed.rows;\n}\n\n/** `posedBoneWorld` up to its rows, refusing a bone the evaluator gave no transform (`PosedStep`). */\nfunction posedBoneStep(doc: CompiledDocument, timelines: CoreAnimationTimelines, t: number, plant: TimelinePlant, constraints: CoreConstraintTimelines | undefined, sliders: SliderApplication[] | undefined, step: PoseStep | undefined): PosedStep {\n const stage = plant.stage;\n if (stage !== undefined) stage.begin('timeline');\n const bones = posedBones(doc, timelines, t, plant);\n if (stage !== undefined) stage.end('timeline');\n // One step of the stepped phase (issue #956, `./constraints_physics.ts`): the physics records posed by their timelines and stepped under the walk's context; the deformed curve a path walks as above.\n if (constraints !== undefined && step !== undefined) {\n return steppedLocals(doc, bones, plant, () => pathDeformed(doc, posedRecords(constraintRecords(doc), constraints, t), timelines, t, plant), constraints.physicsKeyed ?? [], t, sliders, step);\n }\n const active = activeBones(doc);\n // The caller's adjustment, after the timelines and before anything reads the locals (`LocalAdjust`).\n if (step?.adjustment !== undefined) {\n if (stage !== undefined) stage.begin('timeline');\n adjustLocals(doc, bones, step.adjustment.callback, step.adjustment.context);\n if (stage !== undefined) stage.end('timeline');\n }\n if (stage !== undefined) stage.begin('world');\n const initialWorld = (plant.evaluate ?? worldTransforms)(bones, active);\n if (stage !== undefined) stage.end('world');\n let world = initialWorld;\n if (constraints !== undefined) {\n if (stage !== undefined) stage.begin('constraints');\n const setupRecords = constraintRecords(doc);\n // A path walks the curve the sample's deform timelines left on its slot (`./deform.ts`); a slider's deform of a walked path leaves the bones out (`pathAnimationsWhy`).\n const records = pathDeformed(doc, posedRecords(setupRecords, constraints, t), timelines, t, plant);\n // A path constraint may read a slot bone the runtime has not yet brought up to date in this pass, as the previous pass left it (`./constraints_path.ts`, *Which slot bone*); `poseAnimations` holds that pass to the setup pose's reading.\n const previous = setupRecords.some((r) => r.kind === 'path') ? applyConstraints(doc.bones, (plant.evaluate ?? worldTransforms)(doc.bones, active), active, plant.constraints ? plant.constraints(setupRecords) : setupRecords, null, undefined, undefined, undefined, solverRules(plant.solver)) : null;\n world = applyConstraints(bones, initialWorld, active, plant.constraints ? plant.constraints(records) : records, previous, sliders, undefined, plant.readLocals === undefined ? undefined : (state) => plant.readLocals?.(state.bones, sliders ?? []), solverRules(plant.solver));\n if (stage !== undefined) stage.end('constraints');\n }\n for (const b of bones) if (world.get(b.name) === undefined) throw new CoreInputError(`the evaluator returned no transform for bone \"${b.name}\"`);\n return { bones, world, active, round: plant.round ?? gridRound };\n}\n\n/**\n * One step of the stepped phase from locals already posed (issue #1336): the\n * caller's adjustment (`LocalAdjust`), the world transforms, the physics\n * records posed by `records` and stepped under the walk's context, then every\n * constraint. No previous pass: under the step it is the previous step's, and\n * `poseAnimations` leaves such bones out. A single animation's walk reaches it\n * through `posedBoneStep` with the locals `posedBones` posed; the live tracks\n * (`./tracks.ts`) with the locals their mixed entries posed — one pose path\n * past the timelines for both.\n */\nfunction steppedLocals(doc: CompiledDocument, bones: ModelBone[], plant: TimelinePlant, records: () => CoreConstraintRecord[], physicsKeyed: NonNullable<CoreConstraintTimelines['physicsKeyed']>, t: number, sliders: SliderApplication[] | undefined, step: PoseStep): PosedStep {\n const stage = plant.stage;\n const active = activeBones(doc);\n // The caller's adjustment, after the timelines and before anything reads the locals (`LocalAdjust`).\n if (step.adjustment !== undefined) {\n if (stage !== undefined) stage.begin('timeline');\n adjustLocals(doc, bones, step.adjustment.callback, step.adjustment.context);\n if (stage !== undefined) stage.end('timeline');\n }\n if (stage !== undefined) stage.begin('world');\n const initialWorld = (plant.evaluate ?? worldTransforms)(bones, active);\n if (stage !== undefined) {\n stage.end('world');\n stage.begin('constraints');\n }\n const stepped = stepPhysicsRecords(records(), physicsKeyed, t, active, step.ctx, step.before);\n const world = applyConstraints(bones, initialWorld, active, plant.constraints ? plant.constraints(stepped) : stepped, null, sliders, step.ctx, plant.readLocals === undefined ? undefined : (state) => plant.readLocals?.(state.bones, sliders ?? []), solverRules(plant.solver));\n if (stage !== undefined) stage.end('constraints');\n for (const b of bones) if (world.get(b.name) === undefined) throw new CoreInputError(`the evaluator returned no transform for bone \"${b.name}\"`);\n return { bones, world, active, round: plant.round ?? gridRound };\n}\n\n/**\n * `steppedLocals`' world transforms, without the oracle's rows (as\n * `posedBoneWorldAlone` poses them): the live tracks' entry to the stepped\n * phase (`./tracks.ts`). The document's constraint records as they stand —\n * the live tracks mix no constraint timeline — and no physics timeline keyed.\n */\nexport function steppedLocalsWorld(doc: CompiledDocument, bones: ModelBone[], plant: TimelinePlant, sliders: SliderApplication[], step: PoseStep): Map<string, CoreWorld> {\n return steppedLocals(doc, bones, plant, () => constraintRecords(doc), [], 0, sliders, step).world;\n}\n\n/** Each path record with the curve its slot shows deformed by the sample's own deform timelines at `t` (`./deform.ts`), or as it was. */\nfunction pathDeformed(doc: CompiledDocument, records: CoreConstraintRecord[], timelines: CoreAnimationTimelines, t: number, plant: TimelinePlant): CoreConstraintRecord[] {\n if (timelines.attachments.every((a) => a.deform === null)) return records;\n return records.map((r) => {\n if (r.kind !== 'path' || r.path === null) return r;\n const slot = doc.slots.find((x) => x.name === r.slot);\n const shown = slot === undefined ? null : (plant.shown ?? shownAttachment)(doc, slot);\n if (shown === null || 'conflict' in shown) return r;\n const identity = timelineIdentity(r.slot, shown);\n const keyed = timelines.attachments.find((a) => a.deform !== null && `${a.skin}/${a.slot}/${a.attachment}` === identity);\n if (keyed === undefined || keyed.deform === null) return r;\n const d = (plant.deform ?? deformAt)(r.path.vertices, keyed.deform, t);\n return d === null ? r : { ...r, path: { ...r.path, vertices: deformedVertices(r.path.vertices, d), exact: true } };\n });\n}\n\n// ---------------------------------------------------------------------------\n// the samples\n// ---------------------------------------------------------------------------\n\n/** The oracle's phases, as `tools/pose_oracle.ts` names them. */\nexport type SamplePhase = 'grid' | 'off' | 'irr' | 'dense';\n\n/** `1 − 1/φ`, the tool's irrational offset, to the nine places it writes. */\nexport const IRR_OFFSET = 0.381966011;\n\n/**\n * Sample `i` of `n` over duration `d` under `phase` — the tool's formula\n * (`tools/pose_oracle.ts`, *Sample times*), held here so the two dumpers\n * sample at one set of times: `grid` `d·i/(n−1)` (`0` when `n` is 1), `off`\n * `d·(i+0.5)/n`, `irr` and `dense` `d·(i+IRR_OFFSET)/n`.\n */\nexport function sampleTime(phase: SamplePhase, d: number, i: number, n: number): number {\n if (phase === 'off') return (d * (i + 0.5)) / n;\n if (phase === 'irr' || phase === 'dense') return (d * (i + IRR_OFFSET)) / n;\n return n === 1 ? 0 : (d * i) / (n - 1);\n}\n\n/** One posed sample: the time and the blocks this construct produces (`null` where it leaves one out). */\nexport interface CoreSample {\n t: number | null;\n events: CoreEventRow[] | null;\n bones: CoreBoneRow[] | null;\n slots: CoreSlotRow[] | null;\n drawOrder: string[] | null;\n attachments: CoreAttachmentRow[] | null;\n clips: CoreClipRow[] | null;\n /** The triangles drawn under a clip (issue #964, `./clipping.ts`). */\n clipped: CoreClippedRow[] | null;\n}\n\nexport interface CoreAnimationPose {\n name: string;\n duration: number | null;\n samples: CoreSample[];\n}\n\n\n/** Why the animation slots are left out because a slider poses them and the bones are absent, or null. */\nfunction slidersWhy(doc: CompiledDocument): string | null {\n const keyed = doc.constraints.flatMap((c) => {\n if (c.kind !== 'slider') return [];\n const slots = doc.animations.find((a) => a.name === c.animation)?.slots ?? [];\n return slots.length === 0 ? [] : [`slider \"${c.name}\" applies animation \"${c.animation}\", which keys slot(s) ${slots.map((x) => `\"${x}\"`).join(', ')}`];\n });\n return keyed.length === 0 ? null : `${keyed.join('; ')} — the oracle applies sliders after every animation, and a slider poses the slots its animation keys at a time read off the bones, which are absent`;\n}\n\n/**\n * Why the samples' bones are left out although each was posed, or null: a\n * path constraint whose offset reads its slot bone from the previous pass\n * (`previousPassSlotBones`) is posed with the setup pose's reading of it,\n * which is the runtime's exactly when that bone's world keeps the sign of\n * its determinant — its reflection — at the setup pose and at every sample;\n * the oracle's previous pass is the sample before, in its own order of\n * animations, which the model does not hold.\n */\nfunction previousPassWhy(doc: CompiledDocument, animations: readonly CoreAnimationPose[], plant: TimelinePlant): string | null {\n const active = activeBones(doc);\n const reads = previousPassSlotBones(doc, active);\n if (reads.length === 0) return null;\n const records = constraintRecords(doc);\n const setup = applyConstraints(doc.bones, (plant.evaluate ?? worldTransforms)(doc.bones, active), active, plant.constraints ? plant.constraints(records) : records, null, undefined, undefined, undefined, solverRules(plant.solver));\n const bad: string[] = [];\n for (const { constraint, bone } of reads) {\n const w = setup.get(bone);\n const sign = w === undefined ? 0 : Math.sign(w.a * w.d - w.b * w.c);\n const flips = animations.flatMap((a) => a.samples.filter((x) => {\n const row = x.bones?.find((r) => r[0] === bone);\n if (row === undefined || row[3] === null || row[4] === null || row[5] === null || row[6] === null) return true;\n const det = row[3] * row[6] - row[4] * row[5];\n return Math.abs(det) < 1e-6 || Math.sign(det) !== sign;\n }).map((x) => `${a.name}@${x.t}`));\n if (sign === 0 || flips.length > 0) bad.push(`path constraint \"${constraint}\" reads slot bone \"${bone}\" from the previous pose, and its reflection is not the setup's at ${flips.slice(0, 3).join(', ')}${flips.length > 3 ? ` and ${flips.length - 3} more` : ''}`);\n }\n return bad.length === 0 ? null : `${bad.join('; ')} — the runtime's previous pose is the sample before in the Spine file's order of animations, which the model does not hold`;\n}\n\n/**\n * Every animation of the document sampled as the oracle samples it: `n`\n * samples in `phase` over each animation's runtime duration, each the bone\n * rows and the slot rows at `t`, in the model's order of animations. Returns\n * the blocks left out with their reasons, `animations.bones` and\n * `animations.slots` in document order.\n */\nexport function poseAnimations(doc: CompiledDocument, phase: SamplePhase, n: number, plant: TimelinePlant = {}, dt?: number): { animations: CoreAnimationPose[]; absent: Array<[string, string]> } {\n let bonesReason = constraintsAbsentWhy(doc, solverRules(plant.solver)) ?? pathAnimationsWhy(doc) ?? (dt === undefined ? null : steppedPreviousPassWhy(doc));\n const slotConflicts: string[] = [];\n const attachmentWhy: string[] = [];\n const clippedWhy: string[] = [];\n const resolve = plant.shown ?? shownAttachment;\n const round = plant.round ?? gridRound;\n const animations = doc.animations.map((anim: CoreAnimation): CoreAnimationPose => {\n const d = anim.timelines.duration;\n const samples: CoreSample[] = [];\n let last = -1;\n // Under `--physics step` (issue #956): one walk per animation — reset at 0, then the oracle's schedule, each sample posed off its last step (`./constraints_physics.ts`).\n const walk = dt === undefined || bonesReason !== null ? null : { ctx: freshStepContext(plant.physicsStep), now: 0, schedule: stepSchedule(phase, d, n, dt), sliders: [] as SliderApplication[], posed: null as PosedStep | null };\n if (walk !== null) {\n walk.posed = posedBoneStep(doc, anim.timelines, 0, plant, anim.constraints, walk.sliders, { ctx: walk.ctx, before: 0 });\n walk.ctx.phase = 'update';\n }\n for (let i = 0; i < n; i++) {\n const t = sampleTime(phase, d, i, n);\n let sliders: SliderApplication[] = [];\n let posed: { rows: CoreBoneRow[]; world: Map<string, CoreWorld> } | null = null;\n if (walk !== null) {\n for (const s of walk.schedule[i]) {\n const before = walk.ctx.time;\n walk.ctx.time += s - walk.now;\n walk.sliders = [];\n walk.posed = posedBoneStep(doc, anim.timelines, s, plant, anim.constraints, walk.sliders, { ctx: walk.ctx, before });\n walk.now = s;\n }\n sliders = walk.sliders;\n posed = walk.posed === null ? null : { rows: stepRows(walk.posed), world: walk.posed.world };\n } else posed = bonesReason === null ? posedBoneWorld(doc, anim.timelines, t, plant, anim.constraints, sliders) : null;\n const placeholders = new Map<string, string | null>();\n const slots = posedSlots(doc, anim.timelines, t, plant, sliders, placeholders);\n for (const c of slots.conflicts) if (!slotConflicts.includes(`${c} at animation \"${anim.name}\"`)) slotConflicts.push(`${c} at animation \"${anim.name}\"`);\n // The draw order: the sample's key, or the setup order before it, then each slider's key (`./draw_order.ts`).\n const evalOrder = plant.drawOrder ?? drawOrderAt;\n let order = evalOrder(doc.slots.length, anim.timelines.drawOrder, t) ?? doc.slots.map((_s, k) => k);\n for (const app of sliders) order = evalOrder(doc.slots.length, app.timelines.drawOrder, app.at) ?? order;\n const drawOrder = order.map((k) => doc.slots[k].name);\n // The attachments and clips, in the draw order, with the deform and sequence timelines' state (`./deform.ts`).\n let attachments: CoreAttachmentRow[] | null = null;\n let clips: CoreClipRow[] | null = null;\n let clipped: CoreClippedRow[] | null = null;\n if (posed !== null) {\n const states = attachmentStates(doc, resolve, placeholders, { timelines: anim.timelines, t }, sliders, plant);\n for (const w of states.why) if (!attachmentWhy.includes(w)) attachmentWhy.push(w);\n const rank = new Map(order.map((k, r) => [doc.slots[k].name, r]));\n const shown = [...states.shown].sort((a, b) => (rank.get(a.slot) ?? 0) - (rank.get(b.slot) ?? 0));\n const geometry = poseGeometry(shown, posed.world, sourceOfDoc(doc), round, { region: plant.region, vertices: plant.vertices }, drawWalkOf(doc, drawOrder, plant));\n if (geometry.attachmentsWhy !== null && !attachmentWhy.includes(geometry.attachmentsWhy)) attachmentWhy.push(geometry.attachmentsWhy);\n attachments = geometry.attachments;\n clips = geometry.clips;\n clipped = geometry.clipped;\n if (geometry.clippedWhy !== null && geometry.attachmentsWhy === null && !clippedWhy.includes(geometry.clippedWhy)) clippedWhy.push(geometry.clippedWhy);\n }\n const events = (plant.events ?? eventsFired)(anim.timelines.events, last, t, round);\n last = t;\n samples.push({ t: round(t), events, bones: posed === null ? null : posed.rows, slots: slots.rows, drawOrder, attachments, clips, clipped });\n }\n return { name: anim.name, duration: round(d), samples };\n });\n if (bonesReason === null && dt === undefined) bonesReason = previousPassWhy(doc, animations, plant);\n if (bonesReason !== null) for (const a of animations) for (const s of a.samples) s.bones = null;\n const slotsReason = (bonesReason === null ? null : slidersWhy(doc)) ?? (slotConflicts.length === 0\n ? null\n : `${slotConflicts.slice(0, 5).join('; ')}${slotConflicts.length > 5 ? `; and ${slotConflicts.length - 5} more` : ''} — under --skin all the LAST of them in the Spine file's skin order wins, and that order is the emitter's, not the model's`);\n if (slotsReason !== null) for (const a of animations) for (const s of a.samples) s.slots = null;\n const orderReason = bonesReason === null ? null : slidersKeyingWhy(doc, 'drawOrder');\n if (orderReason !== null) for (const a of animations) for (const s of a.samples) s.drawOrder = null;\n // Every vertex goes through a bone's world matrix and follows what the slot shows, so the attachments and clips need both blocks.\n const upstream = [bonesReason === null ? null : `animations.bones is absent (${bonesReason}), and every vertex goes through a bone's world matrix`, slotsReason === null ? null : 'animations.slots is absent, so what a slot shows is not posed'].filter((x): x is string => x !== null);\n const clipsReason = upstream.length > 0 ? upstream.join('; ') : attachmentWhy.some((w) => !w.includes('(atlas: null)')) ? attachmentWhy.filter((w) => !w.includes('(atlas: null)')).join('; ') : null;\n const attachmentsReason = clipsReason ?? (attachmentWhy.length === 0 ? null : attachmentWhy.join('; '));\n if (attachmentsReason !== null) for (const a of animations) for (const s of a.samples) s.attachments = null;\n if (clipsReason !== null) for (const a of animations) for (const s of a.samples) s.clips = null;\n // The clipped triangles follow the attachments and the clips, and are left out where a clip starts over a polygon the core does not clip against (`./clipping.ts`).\n const clippedReason = attachmentsReason ?? orderReason ?? (clippedWhy.length === 0 ? null : clippedWhy.join('; '));\n if (clippedReason !== null) for (const a of animations) for (const s of a.samples) s.clipped = null;\n const absent: Array<[string, string]> = [];\n if (bonesReason !== null) absent.push(['animations.bones', bonesReason]);\n if (slotsReason !== null) absent.push(['animations.slots', slotsReason]);\n if (orderReason !== null) absent.push(['animations.drawOrder', orderReason]);\n if (attachmentsReason !== null) absent.push(['animations.attachments', attachmentsReason]);\n if (clipsReason !== null) absent.push(['animations.clips', clipsReason]);\n if (clippedReason !== null) absent.push(['animations.clipped', clippedReason]);\n return { animations, absent };\n}\n","/**\n * rigc's own core: it reads the compiled model as `build` writes it\n * (`rigc-compiled/3`, and `/2` before issue #1026 and `/1` before issue #1016;\n * `skeleton.model.json`)\n * and poses it (issue #925, step 2a\n * of issue #380). It is the second dumper `tools/pose_oracle.ts` was shaped\n * for: what it poses is written into the same `pose-oracle/2` document the\n * runtime's dump is, and `compare` holds the two to each other.\n *\n * ## What it poses, and what it does not yet\n *\n * Three constructs are here, in the runtime's own order (§5 of the design on\n * issue #380): **the setup pose of every bone** — its world origin and matrix,\n * its active flag and its parent (issue #925) — **the slots at the setup\n * pose** — what each shows, its colour and dark colour, the region path\n * the shown attachment names (issue #928, below) and its blend mode (issue\n * #933) — and **every drawn\n * attachment's world vertices at the setup pose** — a region's corners, a\n * mesh's vertices and a clipping polygon (issue #931, `./vertices.ts`, whose\n * header states each measured rule). All are rounded as the oracle rounds\n * (`gridRound`). A fourth, **every animation's bone and slot timelines at the\n * oracle's sample times** (issue #936), is its own module, `./animation.ts`,\n * which this reader calls for each animation record. Its remainder (issue\n * #955) — the draw order at setup and at a sample (`./draw_order.ts`), the\n * deform and sequence timelines, which move what the attachments and clips\n * draw at setup (under a slider) and at a sample (`./deform.ts`), and the\n * events a sample fires (`./events.ts`) — is posed too. With the physics\n * parameters (issue #956, `./constraints_physics.ts`) no block of the\n * oracle's document is left: `NOT_ADMITTED` is empty. The `clipped` block\n * (issue #964, `./clipping.ts`) — the triangles drawn under a clip, as the\n * runtime's clipper returns them — is posed at setup and at every sample,\n * and left out by name where a clip that is not strictly convex, or an\n * inverse one, starts.\n *\n * **Constraints (construct 5, issue #938, `./constraints.ts`).** The oracle\n * poses the setup pose with every constraint applied, so a bone a constraint\n * moves is not where its hierarchy alone puts it. The core applies the ik,\n * transform, path, physics and slider constraints in the document's order\n * after the hierarchy, as the runtime's update order does (`./constraints.ts`'s\n * header states it with its measurements, `./constraints_path.ts`'s the\n * path's; a physics constraint under `Physics.none` applies nothing, and\n * under the stepped phase — `poseSetup`'s `physics` context, the reset —\n * integrates, `./constraints_physics.ts`, whose `poseSteppedAnimations`\n * walks the oracle's `--physics step` schedule; a slider applies an animation,\n * `./constraints_slider.ts`); a path the core cannot pose exactly (skins\n * that disagree over the curve it walks) leaves the setup bones out naming\n * it (`constraintsAbsentWhy`). Before issue #938, measured over the nineteen\n * recipes `tools/emit_hashes.ts` generates: seven declared a constraint, and\n * on each the runtime's setup pose differed from the hierarchy's alone; all\n * seven read IDENTICAL now. The `paths` and `pathAttachments` blocks — each\n * path constraint's settings and each path attachment's flags and\n * `lengths`, as the runtime reads them — are written from the model\n * (`pathRows`, `pathAttachmentRows`).\n *\n * 🔸 **Active** is measured rather than assumed. Posed through the runtime by\n * `tools/pose_oracle.ts dump` on a hand-written skeleton (issue #925's\n * report; held by the core suite's `CO07`): a bone that is not skin-required\n * is active; a skin-required bone is active exactly when the applied skin\n * names it or names a bone below it — a skin-required parent of a named bone\n * is active, and a bone that is not skin-required stays active under an\n * inactive parent. The oracle's `--skin all` applies every skin at once, so\n * under it `active` means: not skin-required, or named — itself or a bone\n * below it — by ANY skin's `bones` list. Under `--skin <name>` (issue #932,\n * `underSkin`) it is the named skin's list alone — the default skin's does\n * not count (`./skins.ts`, measured). An inactive bone is not posed\n * (`worldTransforms` in `./world.ts`).\n *\n ## The slots at the setup pose (issue #928)\n *\n * Every rule below was measured by posing a hand-written skeleton through\n * `tools/pose_oracle.ts dump` (spine-core 4.3.13, `--skin all`) and reading\n * the slot rows it printed; the core suite's `CO11` holds the same skeleton\n * against the core at tolerance 0.\n *\n * - **Which attachment a slot shows.** A slot whose setup placeholder is\n * `null` shows nothing (`null`). Otherwise the placeholder is looked up in\n * every skin; one skin filling it — the default or a named one alone —\n * shows that record. A placeholder no skin fills shows nothing: the row\n * reads `null` for the attachment and for the path, not the placeholder's\n * name.\n * - ⚠️ **Several skins filling one placeholder: the LAST in the Spine FILE's\n * skin order wins — and the model does not hold that order.** Three skins\n * filling one placeholder with three names, in three file orders\n * (`default, s1, s2`; `s2, s1, default`; `s1, default, s2`), showed `s2`,\n * `default` and `s2`'s name: the last one listed, every time — the oracle's\n * `--skin all` merges the skins in file order, a later one replacing an\n * earlier one's entry. The file's order is not the model's: the Spine\n * emitter writes `default` first and the rest in the editor's order\n * (`editorSkinOrder` in `src/compile.ts`), so a rig built with skins\n * `default, zulu, alpha` has a model listing them so and a file listing\n * `default, alpha, zulu`; with `zulu` and `alpha` filling one placeholder,\n * spine-core showed `zulu`'s attachment, and \"last in the model's order\"\n * would have shown `alpha`'s (measured through `ingest` and `build`; the\n * core suite's `CO12` builds it). That order is a Spine spelling the model\n * rightly does not carry (census §4's class), so the core does not guess it:\n * where every skin filling a slot's setup placeholder gives the same row —\n * the same shown name and path — the order cannot matter and the row is\n * posed; where they differ, the whole `setup.slots` block is absent, naming\n * the slot, the placeholder and the skins. Posing one skin at a time\n * (`--skin <name>`, `underSkin`, issue #932) has no order to know — the\n * named skin's record, else the default skin's (`./skins.ts`) — so the\n * per-skin dumps judge what the merged view leaves out, and\n * `tools/core_gate.ts` runs one per skin on a row declaring several.\n * - **The name shown** is the record's own `name` where the model states one,\n * else the placeholder: a region filed under `p` with `path: \"other\"` shows\n * `p`; one stating `name: \"n\"` shows `n`.\n * - **The region path** is the record's `path` where stated, else the name\n * shown — for a region, a mesh and a linked mesh (a region stating\n * `name: \"n\"` and no path reads path `n`; a linked mesh stating\n * `path: \"lm\"` reads `lm`; a region or mesh with a `sequence` reads its\n * stated `path` as written, `seq` and not a numbered frame). A bounding\n * box, a clipping polygon and a path attachment read `null`, as does a\n * point, which rigc does not emit.\n * - **Colour.** No colour stated reads `1, 1, 1, 1`. A stated colour reads\n * each channel as its two hex digits over 255 (`ff800040` reads\n * `1, 0.501961, 0, 0.25098`; upper case reads the same); six digits read\n * an alpha of 1. The attachment's own colour does not enter the slot's row\n * (a region tinted `00000080` under an unstated slot colour read white).\n * Every one of the 256 byte values in every channel is held by `CO11`.\n * - **Dark colour** is `null` when the slot states none, else its first\n * three channels read the same way; eight digits read the same three, the\n * fourth unread.\n * - 🚫 **Any other spelling is refused by `readModel`, by name.** The\n * runtime's reading of one is not a colour: `ff80004` (seven digits) read\n * alpha 1, `zz800040` read a red of NaN, `f` read red 0.058824 and green\n * NaN, and an empty colour read white while an empty dark colour read none.\n * Reproducing that would be copying a parser's accidents, not posing a slot.\n * - **A slot on an inactive bone still shows its attachment** (a slot on a\n * skin-required bone no skin names read its region and path).\n * - ⚠️ **A slider poses slots at setup; the other four constraint kinds do\n * not.** A slider applies an animation, and the oracle's setup applies\n * constraints: a hand-written slider whose animation keys a slot's `rgba`\n * to `ff000080` and its attachment to `q` turned that slot's setup row from\n * `r, 1, 1, 1, 1` to `q, 1, 0, 0, 0.501961`, with its dial bone and without\n * one. Issue #928 left `setup.slots` absent wherever a slider keys a slot;\n * since issue #938 each slider's slot timelines are applied after the\n * bones, in constraint order, at the time and mix it was applied with\n * (`applySliderSlots` in `./constraints_slider.ts`, which states the blend).\n * The slots are still absent, naming the slider, where the bones its time\n * is read from are absent. An ik, transform, path or physics constraint\n * moves bones only.\n * - **The blend mode** (issue #933) is the row's last cell, as the runtime's\n * enum names it: `Normal`, `Additive`, `Multiply`, `Screen`. A slot that\n * states none reads `Normal`. The runtime reads a stated blend by\n * upper-casing its first letter and looking the result up: `additive` and\n * `Additive` both read `Additive`, while `ADDITIVE` and `mUlTiPlY` read no\n * mode at all (the dump's `null`) and an empty string threw on load. So the\n * core reads exactly the eight spellings whose first letter folds to one of\n * the four names and `readModel` refuses every other by name. The mode is\n * the slot's data, not its pose: an animation keying the slot's colour left\n * it where setup put it, so a sample's row carries the setup's mode.\n *\n * ## The evaluator\n *\n * World transforms come from the core's own evaluator, `worldTransforms` in\n * `./world.ts`, written from what a bone's fields mean and from measurement\n * against the runtime's dump; its header states each measured choice. It is\n * not reached through `src/transform.ts`'s `computeWorldTransforms`: that is\n * the compiler's adapter over this same evaluator (issues #1015 and #1021 —\n * the same arithmetic since #1021), and the core importing the compiler would\n * be a cycle. The compiler's evaluator before #1015, called as it was, read\n * IDENTICAL on 1 of the 12 recipes the core poses (DIFF on 11, worst 61\n * millionths against a tolerance of one — issue #925's report). The owner's\n * decision is recorded on issue #380. `poseSetup` takes a\n * `CorePlant` — the evaluator, the skin resolution, the colour and blend readings — so\n * the suite's plants can pass a copy of one of them; nothing else passes one.\n *\n * ## Purity\n *\n * `src/` is pure and this directory is held to it by the core suite's tree\n * rule (`selftest.ts`, band `CO`): no clock, no randomness, no network, no\n * child process, no file system — `readModel` takes the document's TEXT — and\n * nothing from the Spine runtime package, as a value or as a type.\n */\nimport type { ModelAtlasRect, ModelBone, ModelEditorOrder, ModelPage, ModelPageRegion, ModelSlot, ModelStage, ModelVertices, SkinTableEntry } from '../model.ts';\nimport { worldTransforms, type CoreWorld } from './world.ts';\nimport { readAnimationTimelines, type CoreAnimationTimelines } from './animation.ts';\nimport { readEventDefs, type CoreEventDef } from './events.ts';\nimport { poseGeometry, readGeometry, type CoreAttachmentRow, type CoreClipRow, type CoreGeometry, type DeformedVertexPoser, type DrawWalk, type MeshArraysOf, type RegionPoser, type ShownGeometry, type VertexPoser } from './vertices.ts';\nimport type { CoreClippedRow, ShapeClipper, TriangleClipper } from './clipping.ts';\nimport { applyConstraints, constraintsAbsentWhy, readConstraintRecord, readConstraintTimelines, solverRules, type ConstraintPlant, type CoreConstraintRecord, type CoreConstraintTimelines, type SolverRules } from './constraints.ts';\nimport { readPathRecord } from './constraints_path.ts';\nimport { readPhysicsRecord, type PhysicsStepContext, type PhysicsStepper } from './constraints_physics.ts';\nimport { appliedSkins, CORE_ALL_SKINS, fillingSkins, listedByAppliedSkin, lookupSkins, slotTimelinesApply, type SlotTimelineGate } from './skins.ts';\nimport { applySliderSlots, readSliderRecord, type SliderApplication, type SlotPoseState } from './constraints_slider.ts';\nimport { attachmentStates, type DeformBlender, type DeformEvaluator, type SequenceEvaluator } from './deform.ts';\nimport { drawOrderAt, type DrawOrderEvaluator } from './draw_order.ts';\nimport type { EventsFired } from './events.ts';\n\n/**\n * The document spec `build` writes today (issue #1026): the `pages` section\n * (issue #1016) with each page's `pma` and `scale`, and the `stage` and\n * `editorOrder` sections — what only the Spine files beside a `/2` document\n * state.\n */\nexport const CORE_DOCUMENT_SPEC = 'rigc-compiled/3';\n\n/**\n * The spec before issue #1026: `/3` without `stage`, `editorOrder` and the\n * pages' `pma` and `scale`. Read as before, with `stated` null — a reader that\n * needs those reads them off the Spine files beside the document, and says so\n * (`src/render.ts`'s poser line, the survey's order).\n */\nexport const CORE_DOCUMENT_SPEC_2 = 'rigc-compiled/2';\n\n/**\n * The spec before issue #1016: `/2` without `pages`. Read as before — the\n * draw then takes where each region sits from the atlas beside the document\n * (`corePoser` in `src/render_core.ts` says so by name), because a `/1`\n * document does not state it.\n */\nexport const CORE_DOCUMENT_SPEC_1 = 'rigc-compiled/1';\n\n/** Every spec this reader takes, newest first. */\nexport const CORE_DOCUMENT_SPECS: readonly string[] = [CORE_DOCUMENT_SPEC, CORE_DOCUMENT_SPEC_2, CORE_DOCUMENT_SPEC_1];\n\n/** Who posed a dump the core wrote — the oracle document's `dumper`. */\nexport const CORE_DUMPER = 'rigc-core';\n\n/** A refusal about the document read. Every problem is collected and named in one throw. */\nexport class CoreInputError extends Error {}\n\n/** The document's sections after `spec`, in its key order (`modelDocument` in `src/model.ts`). */\nexport const CORE_SECTIONS = [\n // Issue #1026: `stage` (the header's setup-pose box, or null) and `editorOrder` (the order the Spine file lists skins, slot keys and animations in). `/3` only.\n 'referenceScale', 'stage', 'bones', 'slots', 'skins', 'constraints', 'events', 'animations', 'editorOrder',\n 'images', 'pageGrids', 'droppedStates', 'absentParts', 'meshBones', 'meshes', 'physics', 'deformTransforms', 'trackDerivations', 'rig',\n // Issue #1016: where each region sits on its page, in the atlas written beside the document (`pagesOfAtlas` in `src/model.ts`). `/2` only.\n 'pages',\n // Issue #968: the digest of the `skeleton.json` written beside the document (`spineFileSha256` in `src/model.ts`).\n 'spine',\n] as const;\n\n/** The sections of a `rigc-compiled/2` document: `CORE_SECTIONS` without `stage` and `editorOrder`. */\nexport const CORE_SECTIONS_2: readonly string[] = CORE_SECTIONS.filter((key) => key !== 'stage' && key !== 'editorOrder');\n\n/** The sections of a `rigc-compiled/1` document: `CORE_SECTIONS_2` without `pages`. */\nexport const CORE_SECTIONS_1: readonly string[] = CORE_SECTIONS_2.filter((key) => key !== 'pages');\n\n/** The fields of a page and of a region in the `pages` section, as the writer lists them (`MODEL_PAGE_FIELDS`, `MODEL_PAGE_REGION_FIELDS` in `src/model.ts`, mirrored). */\nexport const CORE_PAGE_FIELDS = ['name', 'width', 'height', 'pma', 'scale', 'regions'] as const;\n/** A `rigc-compiled/2` page's fields: `CORE_PAGE_FIELDS` without `pma` and `scale` (issue #1026). */\nexport const CORE_PAGE_FIELDS_2: readonly string[] = CORE_PAGE_FIELDS.filter((key) => key !== 'pma' && key !== 'scale');\n/** The stage's fields, as the writer lists them (`MODEL_STAGE_FIELDS` in `src/model.ts`, mirrored). */\nexport const CORE_STAGE_FIELDS = ['x', 'y', 'width', 'height'] as const;\n/** The stage box's fields (issue #1168), as the writer lists them (`MODEL_STAGE_BOX_FIELDS` in `src/model.ts`, mirrored). */\nexport const CORE_STAGE_BOX_FIELDS = ['slot', 'attachment'] as const;\nexport const CORE_PAGE_REGION_FIELDS = ['name', 'x', 'y', 'width', 'height', 'offsetX', 'offsetY', 'originalWidth', 'originalHeight', 'degrees', 'index'] as const;\n\n/** The fields a bone record may carry, as the writer lists them. A field outside this list is refused. */\nexport const CORE_BONE_FIELDS = ['name', 'parent', 'length', 'x', 'y', 'rotation', 'scaleX', 'scaleY', 'shearX', 'shearY', 'inheritMode', 'skinRequired', 'editor'] as const;\nconst BONE_NUMBERS = ['length', 'x', 'y', 'rotation', 'scaleX', 'scaleY', 'shearX', 'shearY'] as const;\n/** The fields a slot record may carry. */\nexport const CORE_SLOT_FIELDS = ['name', 'bone', 'setup', 'color', 'dark', 'blend'] as const;\n/** The fields a skin record may carry. */\nexport const CORE_SKIN_FIELDS = ['name', 'bones', 'constraints', 'attachments'] as const;\n/**\n * The fields each attachment kind's record may carry, as the writer lists them\n * (`ATTACHMENT_FIELDS` in `src/model.ts`, mirrored as the bone and slot lists\n * are). A field outside its kind's list is refused.\n */\nexport const CORE_ATTACHMENT_FIELDS: Readonly<Record<SkinTableEntry['kind'], readonly string[]>> = {\n mesh: ['kind', 'name', 'path', 'color', 'uvs', 'triangles', 'vertices', 'hull', 'edges', 'width', 'height', 'sequence'],\n boundingbox: ['kind', 'name', 'vertexCount', 'vertices', 'editorColor'],\n clipping: ['kind', 'name', 'end', 'convex', 'inverse', 'vertexCount', 'vertices', 'editorColor'],\n path: ['kind', 'name', 'closed', 'constantSpeed', 'vertexCount', 'vertices', 'lengths', 'editorColor'],\n region: ['kind', 'name', 'path', 'x', 'y', 'rotation', 'scaleX', 'scaleY', 'width', 'height', 'color', 'sequence', 'atlas'],\n linkedmesh: ['kind', 'name', 'path', 'source', 'skin', 'slot', 'timelines', 'width', 'height', 'color', 'sequence'],\n};\n/** The kinds whose shown record names an atlas region — the ones the oracle's row gives a path (the header's measurement). */\nexport const CORE_REGION_KINDS: ReadonlySet<SkinTableEntry['kind']> = new Set(['region', 'mesh', 'linkedmesh']);\n/** A colour the core reads: six or eight hex digits, either case (the header's measurement; anything else is refused). */\nconst HEX_COLOUR = /^[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/;\n/** The blend modes, as the runtime's enum names them (the header's measurement). */\nexport const CORE_BLEND_MODES = ['Normal', 'Additive', 'Multiply', 'Screen'] as const;\nexport type CoreBlendMode = (typeof CORE_BLEND_MODES)[number];\n/** A stated blend's reading: its first letter upper-cased, when that is one of the four names; `null` otherwise. */\nexport function foldBlend(stated: string): CoreBlendMode | null {\n const folded = `${stated.slice(0, 1).toUpperCase()}${stated.slice(1)}`;\n return (CORE_BLEND_MODES as readonly string[]).includes(folded) ? (folded as CoreBlendMode) : null;\n}\n/** The five constraint kinds a document names. */\nexport const CORE_CONSTRAINT_KINDS = ['ik', 'transform', 'path', 'physics', 'slider'] as const;\nexport type CoreConstraintKind = (typeof CORE_CONSTRAINT_KINDS)[number];\n/** The five inherit modes, as the rig spec spells them once its first letter is lower-cased. */\nexport const CORE_INHERIT_MODES = ['normal', 'onlyTranslation', 'noRotationOrReflection', 'noScale', 'noScaleOrReflection'] as const;\n\n/**\n * The fields of a region's atlas rectangle (`ModelAtlasRect` in `src/model.ts`,\n * issue #935), every one required and a finite number.\n */\nexport const CORE_ATLAS_RECT_FIELDS = ['width', 'height', 'offsetX', 'offsetY', 'originalWidth', 'originalHeight'] as const;\n\n/**\n * One attachment record, as far as the slots read it: its kind, and its own\n * name and region path where stated — and a region's atlas rectangle where the\n * record carries one, `null` where the build had no source for it (issue #935);\n * and, for the world vertices (issue #931, `./vertices.ts`), the geometry the\n * record carries, checked field by field (`readGeometry`).\n */\nexport interface CoreAttachment {\n kind: SkinTableEntry['kind'];\n name?: string;\n path?: string;\n atlas?: ModelAtlasRect | null;\n geometry?: CoreGeometry;\n /** How many frames the record's series holds, where it states a `sequence` — what a sequence key's index is checked against (`./deform.ts`). */\n sequenceCount?: number;\n /** A linked mesh's `timelines`: whether it plays its source's deform and sequence timelines (`./deform.ts`). */\n timelines?: boolean;\n /** The record's `color`, six or eight hex digits, where stated (issue #966): what the raw entry's attachment colour reads (`./raw.ts`); white where unstated. */\n color?: string;\n /** The frame its `sequence` shows at setup (`sequence.setup`, 0 unstated), where it states one (issue #966): the raw entry's sequence index when no timeline set another. */\n sequenceSetup?: number;\n}\n\n/** One skin, as far as these constructs read it: its name, the bones and constraints it activates, and its table — slot, then placeholder. */\nexport interface CoreSkin {\n name: string;\n bones: string[];\n /** The constraints it activates, by kind — a kind the document leaves out lists none (issue #932, `./skins.ts`). */\n constraints: Record<CoreConstraintKind, string[]>;\n attachments: Record<string, Record<string, CoreAttachment>>;\n}\n\n/** One constraint, as far as these constructs read it: its kind and name, a slider's animation, and an ik or transform constraint's record (`./constraints.ts`). */\nexport interface CoreConstraint {\n kind: CoreConstraintKind;\n name: string;\n /** The animation a slider applies — the one constraint kind measured to pose a slot (the slots' ⚠️). */\n animation?: string;\n /** The constraint read field by field (construct 5, issue #938): ik and transform (`./constraints.ts`), physics (`./constraints_physics.ts`), slider (`./constraints_slider.ts`). */\n record?: CoreConstraintRecord;\n}\n\n/** One animation: its name, the slots its timelines key, its timelines as construct 4 reads them (`./animation.ts`), and its constraint timelines (`./constraints.ts`). */\nexport interface CoreAnimation {\n name: string;\n slots: string[];\n timelines: CoreAnimationTimelines;\n constraints: CoreConstraintTimelines;\n /** Every attachment a `deform` timeline keys, as `skin/slot/attachment` — what a path constraint walking a deformed path needs to know (`./constraints_path.ts`). */\n deforms: string[];\n}\n\n/**\n * A `rigc-compiled/3` (or `/2`, or `/1`) document, read. `bones` and `slots` are checked field by\n * field against the writer's own records; skins and constraints are read as\n * far as their names and memberships, and every other section is only\n * required to be present — no construct this card admits reads it.\n */\nexport interface CompiledDocument {\n spec: string;\n /**\n * The skin the document is posed under (issue #932, `./skins.ts`): `all` —\n * every skin merged, the oracle's `--skin all` and `readModel`'s reading —\n * one skin's name, `underSkin`'s, or `null` — no skin set, the runtime's\n * `Skeleton.skin` before `setSkin` is called (`underNoSkin`, issue #1051).\n */\n skin: string | null;\n /** The skeleton's reference scale (issue #958), which every physics record carries too (`CorePhysicsRecord.referenceScale`). */\n referenceScale: number;\n bones: ModelBone[];\n slots: ModelSlot[];\n skins: CoreSkin[];\n constraints: CoreConstraint[];\n animations: CoreAnimation[];\n /** The digest of the `skeleton.json` `build` wrote beside the document (issue #968) — what a render holds the file beside it to before posing it here. */\n spine: { sha256: string };\n /**\n * Every page of the atlas `build` wrote beside the document and every region\n * on it, in file order (issue #1016) — where each drawing sits, which the\n * draw's page UVs read. `null` for a `rigc-compiled/1` document, which does\n * not state it. A `rigc-compiled/3` document's pages carry `pma` and `scale`\n * too (issue #1026); a `/2` document's carry neither.\n */\n pages: ModelPage[] | null;\n /**\n * What a `rigc-compiled/3` document states that only the Spine files beside\n * a `/2` or `/1` document hold (issue #1026): the setup-pose box the header\n * declares, or `null` for none, and the order the editor lists skins, their\n * slot keys and animations in. `null` for a `/2` or `/1` document.\n */\n stated: CoreStated | null;\n}\n\n/** A `rigc-compiled/3` document's `stage` and `editorOrder`, read (`CompiledDocument.stated`). */\nexport interface CoreStated {\n stage: ModelStage | null;\n editorOrder: ModelEditorOrder;\n}\n\n/**\n * The `pages` section, checked: a list of pages, each holding exactly\n * `CORE_PAGE_FIELDS` — a non-empty name, a size of two positive finite\n * numbers, a list of at least one region (issue #1054) — and each region exactly\n * `CORE_PAGE_REGION_FIELDS`, a non-empty name and nine finite numbers. Every\n * fault is named by its path. Nothing is defaulted: a field the writer always\n * writes is required here.\n */\nfunction readPages(value: unknown, problems: string[], flags: boolean): ModelPage[] {\n if (!Array.isArray(value)) {\n problems.push(`pages is ${JSON.stringify(value) ?? 'absent'}, not a list of pages`);\n return [];\n }\n const out: ModelPage[] = [];\n value.forEach((raw, i) => {\n const where = `pages[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${where} is not an object`);\n return;\n }\n const before = problems.length;\n const label = typeof raw.name === 'string' ? `${where} \"${raw.name}\"` : where;\n unknownFields(raw, flags ? CORE_PAGE_FIELDS : CORE_PAGE_FIELDS_2, label, problems);\n if (typeof raw.name !== 'string' || raw.name === '') problems.push(`${where}: name is ${JSON.stringify(raw.name) ?? 'absent'}, not a non-empty string`);\n for (const key of ['width', 'height'] as const) {\n const v = raw[key];\n if (typeof v !== 'number' || !Number.isFinite(v) || v <= 0) problems.push(`${label}: ${key} is ${JSON.stringify(v) ?? 'absent'}, not a positive finite number — a page UV divides by it`);\n }\n // Issue #1026: a /3 page states its `pma:` as the runtime reads it and the number its own `scale:` line states, or null for none.\n if (flags) {\n if (typeof raw.pma !== 'boolean') problems.push(`${label}: pma is ${JSON.stringify(raw.pma) ?? 'absent'}, not true or false — whether the page's texels are premultiplied`);\n if (raw.scale !== null && (typeof raw.scale !== 'number' || !Number.isFinite(raw.scale))) problems.push(`${label}: scale is ${JSON.stringify(raw.scale) ?? 'absent'}, not a finite number or null — the number the page's scale: line states, null where it has none`);\n }\n const regions: ModelPageRegion[] = [];\n if (!Array.isArray(raw.regions)) problems.push(`${label}: regions is not a list`);\n // Issue #1054: a page holding no region is one no build writes — the atlas text's block for it would end before any region line, which\n // the round trip refuses (A07_ATLAS_TEXT_SHAPE: \"the last page block declares no region\") — so a document stating one is refused here by\n // the page's name rather than read, where nothing on the model side would name it.\n else if (raw.regions.length === 0) problems.push(`${label}: regions is an empty list — a page holds at least one region; the atlas text cannot state a page with none (its block would end before a region line, which A07_ATLAS_TEXT_SHAPE refuses), so no build writes one`);\n else {\n raw.regions.forEach((region, j) => {\n const at = `${label}.regions[${j}]`;\n if (!isRecord(region)) {\n problems.push(`${at} is not an object`);\n return;\n }\n const named = typeof region.name === 'string' ? `${at} \"${region.name}\"` : at;\n unknownFields(region, CORE_PAGE_REGION_FIELDS, named, problems);\n if (typeof region.name !== 'string' || region.name === '') problems.push(`${at}: name is ${JSON.stringify(region.name) ?? 'absent'}, not a non-empty string`);\n for (const key of CORE_PAGE_REGION_FIELDS) {\n if (key === 'name') continue;\n const v = region[key];\n if (typeof v !== 'number' || !Number.isFinite(v)) problems.push(`${named}: ${key} is ${JSON.stringify(v) ?? 'absent'}, not a finite number`);\n }\n regions.push(region as unknown as ModelPageRegion);\n });\n }\n if (problems.length === before) {\n out.push(\n flags\n ? { name: raw.name as string, width: raw.width as number, height: raw.height as number, pma: raw.pma as boolean, scale: raw.scale as number | null, regions }\n : { name: raw.name as string, width: raw.width as number, height: raw.height as number, regions },\n );\n }\n });\n return out;\n}\n\n/** The `spine` section's value, checked: `{ \"sha256\": <64 lowercase hex> }` and nothing else, each fault named by path (issue #968). */\nfunction readSpineDigest(value: unknown, problems: string[]): string {\n if (value === undefined) return '';\n if (!isRecord(value)) {\n problems.push(`spine is ${JSON.stringify(value)}, not { \"sha256\": \"<64 lowercase hex digits>\" }`);\n return '';\n }\n for (const key of Object.keys(value)) if (key !== 'sha256') problems.push(`spine: field \"${key}\" is not one this reader knows; it reads [sha256]`);\n const sha = value.sha256;\n if (typeof sha !== 'string' || !/^[0-9a-f]{64}$/.test(sha)) {\n problems.push(`spine.sha256 is ${JSON.stringify(sha) ?? 'absent'}, not 64 lowercase hex digits — the SHA-256 of the skeleton.json written beside the document`);\n return '';\n }\n return sha;\n}\n\n/**\n * The `stage` section, checked (issue #1026): `null` — the header declares no\n * stage — or exactly `CORE_STAGE_FIELDS`, four finite numbers, each fault\n * named by path. Nothing is defaulted: the writer always writes all four.\n */\nfunction readStage(value: unknown, problems: string[]): ModelStage | null {\n if (value === null) return null;\n if (!isRecord(value)) {\n problems.push(`stage is ${JSON.stringify(value) ?? 'absent'}, not null or { x, y, width, height } — the setup-pose box the Spine header declares`);\n return null;\n }\n const before = problems.length;\n unknownFields(value, [...CORE_STAGE_FIELDS, 'box'], 'stage', problems);\n for (const key of CORE_STAGE_FIELDS) {\n const v = value[key];\n if (typeof v !== 'number' || !Number.isFinite(v)) problems.push(`stage: ${key} is ${JSON.stringify(v) ?? 'absent'}, not a finite number`);\n }\n // The stage box (issue #1168): written only where the rig asked for one, and then exactly its two names.\n const box = value.box;\n if (box !== undefined) {\n if (!isRecord(box)) problems.push(`stage.box is ${JSON.stringify(box)}, not { slot, attachment }`);\n else {\n unknownFields(box, CORE_STAGE_BOX_FIELDS, 'stage.box', problems);\n for (const key of CORE_STAGE_BOX_FIELDS) if (typeof box[key] !== 'string' || box[key] === '') problems.push(`stage.box: ${key} is ${JSON.stringify(box[key]) ?? 'absent'}, not a non-empty string`);\n }\n }\n if (problems.length !== before) return null;\n const stage: ModelStage = { x: value.x as number, y: value.y as number, width: value.width as number, height: value.height as number };\n if (isRecord(box)) stage.box = { slot: box.slot as string, attachment: box.attachment as string };\n return stage;\n}\n\n/**\n * The `editorOrder` section, checked against the records the document holds\n * (issue #1026): `skins`, every skin exactly once as `{ name, slots }` with\n * `slots` its table's slot keys exactly once each, and `animations`, every\n * animation's name exactly once. An order naming a skin, slot key or\n * animation the document does not hold, or leaving one out, is refused by\n * path — it would be another rig's order.\n */\nfunction readEditorOrder(value: unknown, skins: readonly CoreSkin[], animations: readonly CoreAnimation[], problems: string[]): ModelEditorOrder {\n const out: ModelEditorOrder = { skins: [], animations: [] };\n if (!isRecord(value)) {\n problems.push(`editorOrder is ${JSON.stringify(value) ?? 'absent'}, not { skins, animations }`);\n return out;\n }\n unknownFields(value, ['skins', 'animations'], 'editorOrder', problems);\n const names = (list: unknown, where: string): string[] | null => {\n if (!Array.isArray(list) || list.some((n) => typeof n !== 'string')) {\n problems.push(`${where} is ${JSON.stringify(list) ?? 'absent'}, not a list of names`);\n return null;\n }\n return list as string[];\n };\n /** `stated` lists exactly the names of `held`, each once — else one problem naming the first difference. */\n const permutation = (stated: readonly string[], held: readonly string[], where: string, what: string): void => {\n const seen = new Set<string>();\n for (const name of stated) {\n if (seen.has(name)) return void problems.push(`${where} lists ${what} \"${name}\" twice`);\n seen.add(name);\n if (!held.includes(name)) return void problems.push(`${where} lists ${what} \"${name}\", which the document does not hold`);\n }\n const missing = held.find((name) => !seen.has(name));\n if (missing !== undefined) problems.push(`${where} leaves out ${what} \"${missing}\"`);\n };\n if (!Array.isArray(value.skins)) problems.push(`editorOrder.skins is ${JSON.stringify(value.skins) ?? 'absent'}, not a list`);\n else {\n value.skins.forEach((entry, i) => {\n const at = `editorOrder.skins[${i}]`;\n if (!isRecord(entry) || typeof entry.name !== 'string') return void problems.push(`${at} is not { name, slots }`);\n unknownFields(entry, ['name', 'slots'], at, problems);\n const slots = names(entry.slots, `${at}.slots`);\n const skin = skins.find((k) => k.name === entry.name);\n if (slots !== null && skin !== undefined) permutation(slots, Object.keys(skin.attachments), `${at}.slots`, 'slot key');\n out.skins.push({ name: entry.name, slots: slots ?? [] });\n });\n permutation(out.skins.map((k) => k.name), skins.map((k) => k.name), 'editorOrder.skins', 'skin');\n }\n const order = names(value.animations, 'editorOrder.animations');\n if (order !== null) {\n permutation(order, animations.map((a) => a.name), 'editorOrder.animations', 'animation');\n out.animations = order;\n }\n return out;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\n/** The mode a stated `inheritMode` folds to — the first letter lower-cased and nothing else — or null. */\nexport function foldInheritMode(value: string): (typeof CORE_INHERIT_MODES)[number] | null {\n const folded = value.length === 0 ? value : value[0].toLowerCase() + value.slice(1);\n return CORE_INHERIT_MODES.find((m) => m === folded) ?? null;\n}\n\nfunction unknownFields(record: Record<string, unknown>, known: readonly string[], where: string, problems: string[]): void {\n for (const key of Object.keys(record)) {\n if (!known.includes(key)) problems.push(`${where}: field \"${key}\" is not one this reader knows; it reads [${known.join(', ')}]`);\n }\n}\n\nfunction readBones(value: unknown, problems: string[]): ModelBone[] {\n if (!Array.isArray(value)) {\n problems.push('bones is not a list');\n return [];\n }\n const out: ModelBone[] = [];\n const seen = new Set<string>();\n value.forEach((raw, i) => {\n const where = `bones[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${where} is not an object`);\n return;\n }\n const label = typeof raw.name === 'string' ? `${where} \"${raw.name}\"` : where;\n unknownFields(raw, CORE_BONE_FIELDS, label, problems);\n if (typeof raw.name !== 'string' || raw.name === '') problems.push(`${where}: name is ${JSON.stringify(raw.name)}, not a non-empty string`);\n else if (seen.has(raw.name)) problems.push(`${label}: the name is declared twice`);\n if (raw.parent !== undefined) {\n if (typeof raw.parent !== 'string') problems.push(`${label}: parent is ${JSON.stringify(raw.parent)}, not a bone name`);\n else if (!seen.has(raw.parent)) problems.push(`${label}: parent \"${raw.parent}\" is not declared before it; bones are parents first`);\n }\n for (const key of BONE_NUMBERS) {\n const v = raw[key];\n if (v !== undefined && (typeof v !== 'number' || !Number.isFinite(v))) problems.push(`${label}: ${key} is ${JSON.stringify(v)}, not a finite number`);\n }\n if (raw.inheritMode !== undefined) {\n if (typeof raw.inheritMode !== 'string' || foldInheritMode(raw.inheritMode) === null) {\n problems.push(`${label}: inheritMode is ${JSON.stringify(raw.inheritMode)}, which folds to none of ${CORE_INHERIT_MODES.join(', ')}`);\n }\n }\n if (raw.skinRequired !== undefined && typeof raw.skinRequired !== 'boolean') problems.push(`${label}: skinRequired is ${JSON.stringify(raw.skinRequired)}, not a boolean`);\n if (raw.editor !== undefined) {\n if (!isRecord(raw.editor)) problems.push(`${label}: editor is not an object`);\n else {\n unknownFields(raw.editor, ['color', 'icon'], `${label}.editor`, problems);\n for (const key of ['color', 'icon'] as const) {\n if (raw.editor[key] !== undefined && typeof raw.editor[key] !== 'string') problems.push(`${label}.editor: ${key} is not a string`);\n }\n }\n }\n if (typeof raw.name === 'string' && raw.name !== '') seen.add(raw.name);\n out.push(raw as unknown as ModelBone);\n });\n return out;\n}\n\nfunction readSlots(value: unknown, bones: ReadonlySet<string>, problems: string[]): ModelSlot[] {\n if (!Array.isArray(value)) {\n problems.push('slots is not a list');\n return [];\n }\n const out: ModelSlot[] = [];\n value.forEach((raw, i) => {\n const where = `slots[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${where} is not an object`);\n return;\n }\n const label = typeof raw.name === 'string' ? `${where} \"${raw.name}\"` : where;\n unknownFields(raw, CORE_SLOT_FIELDS, label, problems);\n if (typeof raw.name !== 'string' || raw.name === '') problems.push(`${where}: name is ${JSON.stringify(raw.name)}, not a non-empty string`);\n if (typeof raw.bone !== 'string') problems.push(`${label}: bone is ${JSON.stringify(raw.bone)}, not a bone name`);\n else if (!bones.has(raw.bone)) problems.push(`${label}: bone \"${raw.bone}\" is not a bone of this document`);\n if (raw.setup !== null && typeof raw.setup !== 'string') problems.push(`${label}: setup is ${JSON.stringify(raw.setup)}, not a placeholder name or null`);\n for (const key of ['color', 'dark', 'blend'] as const) {\n if (raw[key] !== undefined && typeof raw[key] !== 'string') problems.push(`${label}: ${key} is ${JSON.stringify(raw[key])}, not a string`);\n }\n for (const key of ['color', 'dark'] as const) {\n const v = raw[key];\n if (typeof v === 'string' && !HEX_COLOUR.test(v)) problems.push(`${label}: ${key} is ${JSON.stringify(v)}, not six or eight hex digits (rrggbb or rrggbbaa) — the only spellings whose reading was measured to be a colour`);\n }\n if (typeof raw.blend === 'string' && foldBlend(raw.blend) === null) {\n problems.push(`${label}: blend is ${JSON.stringify(raw.blend)}, which the runtime reads as no mode — one of ${CORE_BLEND_MODES.join(', ')}, first letter in either case, is the only spelling measured to be one`);\n }\n out.push(raw as unknown as ModelSlot);\n });\n return out;\n}\n\nfunction readAttachments(value: Record<string, unknown>, bones: ReadonlySet<string>, slots: ReadonlySet<string>, label: string, problems: string[]): Record<string, Record<string, CoreAttachment>> {\n const out: Record<string, Record<string, CoreAttachment>> = {};\n for (const [slot, table] of Object.entries(value)) {\n const at = `${label}.attachments[\"${slot}\"]`;\n if (!slots.has(slot)) problems.push(`${at}: \"${slot}\" is not a slot of this document`);\n if (!isRecord(table)) {\n problems.push(`${at} is not an object`);\n continue;\n }\n const entries: Record<string, CoreAttachment> = {};\n for (const [placeholder, raw] of Object.entries(table)) {\n const where = `${at}[\"${placeholder}\"]`;\n if (!isRecord(raw)) {\n problems.push(`${where} is not an object`);\n continue;\n }\n const kinds = Object.keys(CORE_ATTACHMENT_FIELDS) as Array<SkinTableEntry['kind']>;\n const kind = kinds.find((k) => k === raw.kind);\n if (kind === undefined) {\n problems.push(`${where}: kind is ${JSON.stringify(raw.kind)}, none of ${kinds.join(', ')}`);\n continue;\n }\n unknownFields(raw, CORE_ATTACHMENT_FIELDS[kind], where, problems);\n const record: CoreAttachment = { kind };\n for (const key of ['name', 'path'] as const) {\n const v = raw[key];\n if (v === undefined) continue;\n if (typeof v !== 'string' || v === '') problems.push(`${where}: ${key} is ${JSON.stringify(v)}, not a non-empty string`);\n else record[key] = v;\n }\n if (kind === 'region' && raw.atlas !== undefined) {\n const rect = readAtlasRect(raw.atlas, `${where}.atlas`, problems);\n if (rect !== undefined) record.atlas = rect;\n }\n const geometry = readGeometry(raw, kind, where, bones, slots, problems);\n if (geometry !== undefined) record.geometry = geometry;\n // The series' length, whatever the kind: a sequence key's index is a frame of it (`./deform.ts`).\n if (isRecord(raw.sequence)) {\n const count = raw.sequence.count;\n if (typeof count === 'number' && Number.isInteger(count) && count >= 1) record.sequenceCount = count;\n else if (kind !== 'region') problems.push(`${where}.sequence: count is ${JSON.stringify(count)}, not a whole number of at least 1`);\n const setupFrame = raw.sequence.setup ?? 0;\n if (typeof setupFrame === 'number' && Number.isInteger(setupFrame) && setupFrame >= 0 && (typeof count !== 'number' || setupFrame < count)) record.sequenceSetup = setupFrame;\n else if (kind !== 'region') problems.push(`${where}.sequence: setup is ${JSON.stringify(raw.sequence.setup)}, not a frame of the ${JSON.stringify(count)}`);\n }\n // The attachment's own colour (issue #966): the raw entry forms the tint from it and the slot's.\n if (raw.color !== undefined) {\n if (typeof raw.color !== 'string' || !HEX_COLOUR.test(raw.color)) problems.push(`${where}: color is ${JSON.stringify(raw.color)}, not six or eight hex digits`);\n else record.color = raw.color;\n }\n if (kind === 'linkedmesh') {\n if (typeof raw.timelines !== 'boolean') problems.push(`${where}: timelines is ${JSON.stringify(raw.timelines) ?? 'absent'}, not a boolean — the writer states whether the link plays its source's timelines`);\n else record.timelines = raw.timelines;\n }\n entries[placeholder] = record;\n }\n out[slot] = entries;\n }\n return out;\n}\n\n/** A region's `atlas`: `null`, or an object holding exactly the six fields, each a finite number. `undefined` when refused. */\nfunction readAtlasRect(value: unknown, where: string, problems: string[]): ModelAtlasRect | null | undefined {\n if (value === null) return null;\n if (!isRecord(value)) {\n problems.push(`${where} is ${JSON.stringify(value)}, neither null nor an object`);\n return undefined;\n }\n const before = problems.length;\n unknownFields(value, CORE_ATLAS_RECT_FIELDS, where, problems);\n for (const key of CORE_ATLAS_RECT_FIELDS) {\n const v = value[key];\n if (typeof v !== 'number' || !Number.isFinite(v)) problems.push(`${where}: ${key} is ${JSON.stringify(v) ?? 'absent'}, not a finite number`);\n }\n return problems.length === before ? (value as unknown as ModelAtlasRect) : undefined;\n}\n\nfunction readSkins(value: unknown, bones: ReadonlySet<string>, slots: ReadonlySet<string>, problems: string[]): CoreSkin[] {\n if (!Array.isArray(value)) {\n problems.push('skins is not a list');\n return [];\n }\n const out: CoreSkin[] = [];\n value.forEach((raw, i) => {\n const where = `skins[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${where} is not an object`);\n return;\n }\n const label = typeof raw.name === 'string' ? `${where} \"${raw.name}\"` : where;\n unknownFields(raw, CORE_SKIN_FIELDS, label, problems);\n if (typeof raw.name !== 'string' || raw.name === '') problems.push(`${where}: name is ${JSON.stringify(raw.name)}, not a non-empty string`);\n const members: string[] = [];\n if (!Array.isArray(raw.bones)) problems.push(`${label}: bones is not a list`);\n else {\n raw.bones.forEach((b, j) => {\n if (typeof b !== 'string') problems.push(`${label}: bones[${j}] is not a bone name`);\n else if (!bones.has(b)) problems.push(`${label}: bones[${j}] \"${b}\" is not a bone of this document`);\n else members.push(b);\n });\n }\n const lists = Object.fromEntries(CORE_CONSTRAINT_KINDS.map((k) => [k, [] as string[]])) as Record<CoreConstraintKind, string[]>;\n if (!isRecord(raw.constraints)) problems.push(`${label}: constraints is not an object`);\n else {\n for (const [kind, list] of Object.entries(raw.constraints)) {\n const known = CORE_CONSTRAINT_KINDS.find((k) => k === kind);\n if (known === undefined) problems.push(`${label}.constraints: \"${kind}\" is not a constraint kind; a skin lists ${CORE_CONSTRAINT_KINDS.join(', ')}`);\n else if (!Array.isArray(list) || list.some((n) => typeof n !== 'string')) problems.push(`${label}.constraints.${kind} is not a list of constraint names`);\n else lists[known] = list as string[];\n }\n }\n let attachments: Record<string, Record<string, CoreAttachment>> = {};\n if (!isRecord(raw.attachments)) problems.push(`${label}: attachments is not an object`);\n else attachments = readAttachments(raw.attachments, bones, slots, label, problems);\n out.push({ name: typeof raw.name === 'string' ? raw.name : '', bones: members, constraints: lists, attachments });\n });\n return out;\n}\n\nfunction readAnimations(value: unknown, bones: ReadonlySet<string>, slotRecords: readonly ModelSlot[], skins: readonly CoreSkin[], events: ReadonlyMap<string, CoreEventDef>, problems: string[]): CoreAnimation[] {\n const slots = new Set(slotRecords.map((s) => s.name));\n if (!Array.isArray(value)) {\n problems.push('animations is not a list');\n return [];\n }\n const out: CoreAnimation[] = [];\n value.forEach((raw, i) => {\n const where = `animations[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${where} is not an object`);\n return;\n }\n if (typeof raw.name !== 'string' || raw.name === '') problems.push(`${where}: name is ${JSON.stringify(raw.name)}, not a non-empty string`);\n const label = typeof raw.name === 'string' ? `${where} \"${raw.name}\"` : where;\n const keyed: string[] = [];\n if (!Array.isArray(raw.slots)) problems.push(`${label}: slots is not a list`);\n else {\n raw.slots.forEach((entry, j) => {\n if (!isRecord(entry) || typeof entry.name !== 'string') problems.push(`${label}: slots[${j}] names no slot`);\n else if (!slots.has(entry.name)) problems.push(`${label}: slots[${j}] \"${entry.name}\" is not a slot of this document`);\n else keyed.push(entry.name);\n });\n }\n const deforms: string[] = [];\n // The structure is checked with the key times (`laterKeyTimes` in `./animation.ts`); here only the names are taken.\n const list = (v: unknown): Array<Record<string, unknown>> => (Array.isArray(v) ? v.filter(isRecord) : []);\n for (const skin of list(raw.attachments)) for (const slot of list(skin.slots)) for (const att of list(slot.attachments)) if (att.deform !== undefined) deforms.push(`${String(skin.name)}/${String(slot.name)}/${String(att.name)}`);\n out.push({ name: typeof raw.name === 'string' ? raw.name : '', slots: keyed, timelines: readAnimationTimelines(raw, label, bones, slotRecords, problems, { skins, events }), constraints: { ik: [], transform: [], path: [], physics: 0, slider: [] }, deforms });\n });\n return out;\n}\n\nfunction readConstraints(value: unknown, animations: readonly CoreAnimation[], bones: readonly ModelBone[], slots: readonly ModelSlot[], referenceScale: number, problems: string[]): CoreConstraint[] {\n const names = new Set(bones.map((b) => b.name));\n const slotBones = new Map(slots.map((s) => [s.name, s.bone]));\n const parents = new Map(bones.map((b) => [b.name, b.parent]));\n if (!Array.isArray(value)) {\n problems.push('constraints is not a list');\n return [];\n }\n const out: CoreConstraint[] = [];\n value.forEach((raw, i) => {\n const where = `constraints[${i}]`;\n if (!isRecord(raw)) {\n problems.push(`${where} is not an object`);\n return;\n }\n const kind = CORE_CONSTRAINT_KINDS.find((k) => k === raw.kind);\n if (kind === undefined) problems.push(`${where}: kind is ${JSON.stringify(raw.kind)}, none of ${CORE_CONSTRAINT_KINDS.join(', ')}`);\n if (typeof raw.name !== 'string' || raw.name === '') problems.push(`${where}: name is ${JSON.stringify(raw.name)}, not a non-empty string`);\n if (raw.declaredIn !== 'rig' && raw.declaredIn !== 'motion') problems.push(`${where}: declaredIn is ${JSON.stringify(raw.declaredIn)}, not \"rig\" or \"motion\"`);\n const at = `${where} \"${String(raw.name)}\"`;\n let record: CoreConstraintRecord | undefined;\n if (typeof raw.name === 'string') {\n if (kind === 'ik' || kind === 'transform') record = readConstraintRecord(raw, kind, raw.name, at, names, parents, problems);\n else if (kind === 'path') record = readPathRecord(raw, raw.name, at, names, slotBones, problems);\n else if (kind === 'physics') record = readPhysicsRecord(raw, raw.name, at, names, referenceScale, problems);\n else if (kind === 'slider') record = readSliderRecord(raw, raw.name, at, bones, animations, problems);\n }\n if (kind !== undefined && typeof raw.name === 'string') out.push({ kind, name: raw.name, ...(kind === 'slider' && typeof raw.animation === 'string' ? { animation: raw.animation } : {}), ...(record !== undefined ? { record } : {}) });\n });\n return out;\n}\n\n/**\n * Read a `rigc-compiled/3` document — or a `rigc-compiled/2` one, which has\n * no `stage`, `editorOrder` or page `pma`/`scale` and is read with `stated:\n * null`, or a `rigc-compiled/1` one, which has no `pages` either and is read\n * with `pages: null` — from its text, refusing by name a text\n * that is not JSON, a wrong `spec`, a missing section (`referenceScale`\n * among them, issue #958), a section the document does not have, a\n * `referenceScale` that is not a finite number, and — in the records these constructs read (bones, slots,\n * skins and their attachment tables) — a field the writer does not write (the\n * writer's own rule, `ordered` in `src/model.ts`, mirrored), a value of the\n * wrong type, a colour spelled other than six or eight hex digits, a parent\n * declared after its child and a name that resolves to nothing. Every problem\n * is collected and thrown once.\n */\nexport function readModel(text: string, where = 'the model document'): CompiledDocument {\n let value: unknown;\n try {\n value = JSON.parse(text);\n } catch (err) {\n throw new CoreInputError(`${where}: not JSON — ${(err as Error).message}`);\n }\n if (!isRecord(value)) throw new CoreInputError(`${where}: not a JSON object`);\n if (typeof value.spec !== 'string' || !CORE_DOCUMENT_SPECS.includes(value.spec)) {\n throw new CoreInputError(\n `${where}: spec is ${JSON.stringify(value.spec)}, not \"${CORE_DOCUMENT_SPEC}\" (or \"${CORE_DOCUMENT_SPEC_2}\", read without its stage, editor order and page flags, or \"${CORE_DOCUMENT_SPEC_1}\", read without its pages too)`,\n );\n }\n const spec = value.spec;\n const sections: readonly string[] = spec === CORE_DOCUMENT_SPEC ? CORE_SECTIONS : spec === CORE_DOCUMENT_SPEC_2 ? CORE_SECTIONS_2 : CORE_SECTIONS_1;\n const problems: string[] = [];\n for (const key of sections) if (!(key in value)) problems.push(`section \"${key}\" is missing`);\n for (const key of Object.keys(value)) {\n if (key !== 'spec' && !sections.includes(key)) problems.push(`section \"${key}\" is not one a ${spec} document has`);\n }\n const pages = spec !== CORE_DOCUMENT_SPEC_1 && 'pages' in value ? readPages(value.pages, problems, spec === CORE_DOCUMENT_SPEC) : null;\n const stage = spec === CORE_DOCUMENT_SPEC && 'stage' in value ? readStage(value.stage, problems) : null;\n // The skeleton's reference scale (issue #958): wind and gravity act over it, so a missing one is the section refusal above, and a value the runtime could not read as a number is refused here by name.\n const referenceScale = typeof value.referenceScale === 'number' && Number.isFinite(value.referenceScale) ? value.referenceScale : NaN;\n if ('referenceScale' in value && Number.isNaN(referenceScale)) problems.push(`referenceScale is ${JSON.stringify(value.referenceScale)}, not a finite number — wind and gravity act over it`);\n const spine = readSpineDigest(value.spine, problems);\n const bones = readBones(value.bones, problems);\n const names = new Set(bones.map((b) => b.name));\n const slots = readSlots(value.slots, names, problems);\n const slotNames = new Set(slots.map((x) => x.name));\n const skins = readSkins(value.skins, names, slotNames, problems);\n problems.push(...linkProblems(skins));\n const events = readEventDefs(value.events, problems);\n const animations = readAnimations(value.animations, names, slots, skins, events, problems);\n const constraints = readConstraints(value.constraints, animations, bones, slots, referenceScale, problems);\n // Each skin's constraint lists name a constraint of that kind: the runtime's loader refuses any other name (`./skins.ts`).\n for (const skin of skins) {\n for (const kind of CORE_CONSTRAINT_KINDS) {\n for (const name of skin.constraints[kind]) {\n if (!constraints.some((c) => c.kind === kind && c.name === name)) problems.push(`skin \"${skin.name}\".constraints.${kind}: \"${name}\" is not a ${kind} constraint of this document — the runtime refuses the file (\"Couldn't find … constraint ${name} for skin ${skin.name}.\")`);\n }\n }\n }\n if (Array.isArray(value.animations)) {\n value.animations.forEach((raw, i) => {\n if (isRecord(raw) && animations[i] !== undefined) animations[i].constraints = readConstraintTimelines(raw.constraints, `animations[${i}] \"${animations[i].name}\"`, constraints, problems);\n });\n }\n // A slider's physics timelines are its animation's (issue #1049), read only now.\n for (const c of constraints) {\n const r = c.record;\n if (r?.kind === 'slider') r.physics = animations.find((a) => a.name === r.animation)?.constraints.physicsKeyed ?? [];\n }\n const editorOrder = spec === CORE_DOCUMENT_SPEC && 'editorOrder' in value ? readEditorOrder(value.editorOrder, skins, animations, problems) : null;\n if (problems.length > 0) throw new CoreInputError(`${where}: ${problems.length} problem(s): ${problems.join('; ')}`);\n const stated: CoreStated | null = editorOrder === null ? null : { stage, editorOrder };\n const doc: CompiledDocument = { spec, skin: CORE_ALL_SKINS, referenceScale, bones, slots, skins, constraints, animations, spine: { sha256: spine }, pages, stated };\n resolveSkinView(doc);\n return doc;\n}\n\n/**\n * The document posed under one skin (issue #932): `name` is `all` — every\n * skin merged, `readModel`'s reading — or a skin of the document, refused by\n * name otherwise. The skins, rosters and records are the document's own; the\n * constraint records are copied, so each view carries its own reading of\n * which constraints apply and what a path walks (`resolveSkinView`).\n */\nexport function underSkin(doc: CompiledDocument, name: string): CompiledDocument {\n if (name !== CORE_ALL_SKINS && !doc.skins.some((k) => k.name === name)) {\n throw new CoreInputError(`--skin ${JSON.stringify(name)}: no such skin; this document declares [${doc.skins.map((k) => k.name).join(', ') || 'none'}] (or pass ${CORE_ALL_SKINS})`);\n }\n const view: CompiledDocument = { ...doc, skin: name, constraints: doc.constraints.map((c) => (c.record === undefined ? c : { ...c, record: { ...c.record } as CoreConstraintRecord })) };\n resolveSkinView(view);\n return view;\n}\n\n/**\n * The document posed with no skin set (issue #1051): no skin's `bones` or\n * constraint lists applied — the default skin's included — and every slot\n * resolved through the default skin alone, or through nothing where the\n * document declares none (`./skins.ts`, *No skin set*, for the measurement).\n * The view a fresh skeleton is in: `render` without `--skin`, A10's walk and\n * `validate()`'s poses (`noSkinView` in `src/render_core.ts`).\n */\nexport function underNoSkin(doc: CompiledDocument): CompiledDocument {\n const view: CompiledDocument = { ...doc, skin: null, constraints: doc.constraints.map((c) => (c.record === undefined ? c : { ...c, record: { ...c.record } as CoreConstraintRecord })) };\n resolveSkinView(view);\n return view;\n}\n\n/**\n * What a skin view decides on the constraint records: whether an applied\n * skin's list names each (`listedBySkin`, `./skins.ts`), and what each path\n * constraint walks — the curve its slot shows at setup, or why that cannot\n * be told (`unresolved`) — and which bones its slot reads (`slotDeps`).\n */\nfunction resolveSkinView(doc: CompiledDocument): void {\n for (const c of doc.constraints) if (c.record !== undefined) c.record.listedBySkin = listedByAppliedSkin(doc, c.kind, c.name);\n // A path constraint walks what its slot shows at setup (construct 5's second cut, `./constraints_path.ts`).\n for (const c of doc.constraints) {\n const r = c.record;\n if (r?.kind !== 'path') continue;\n r.path = null;\n r.unresolved = null;\n const slot = doc.slots.find((s) => s.name === r.slot) as ModelSlot;\n const shown = shownAttachment(doc, slot);\n // Under `all`, every skin filling the slot's setup placeholder: the curve walked is the LAST of them in the Spine file's skin order, which the model does not hold (the slots' ⚠️), so skins stating two curves leave it unresolved. Under a named skin one resolves (`fillingSkins`).\n const fills = slot.setup === null ? [] : fillingSkins(doc, slot.name, slot.setup).flatMap((name) => {\n const g = doc.skins.find((k) => k.name === name)?.attachments[slot.name]?.[slot.setup as string]?.geometry;\n return g === undefined ? [] : [{ skin: name, g: JSON.stringify(g) }];\n });\n if (fills.length > 1 && fills.some((f) => f.g !== fills[0].g)) r.unresolved = `path constraint \"${r.name}\" walks slot \"${r.slot}\", whose placeholder \"${slot.setup}\" skins ${fills.map((x) => `\"${x.skin}\"`).join(', ')} fill differently — which one --skin all shows is the Spine file's skin order, not the model's; the per-skin dumps (--skin <name>) judge it`;\n else if (shown !== null && 'conflict' in shown) r.unresolved = `path constraint \"${r.name}\" walks slot \"${r.slot}\", whose placeholder \"${slot.setup}\" skins ${shown.conflict.map((x) => `\"${x.skin}\"`).join(', ')} fill differently — which one --skin all shows is the Spine file's skin order, not the model's; the per-skin dumps (--skin <name>) judge it`;\n else if (shown !== null && shown.record.geometry?.kind === 'path') {\n const g = shown.record.geometry;\n r.path = { vertices: g.vertices, closed: g.closed, constantSpeed: g.constantSpeed, lengths: g.lengths };\n }\n const deps: string[] = [];\n for (const skin of lookupSkins(doc)) {\n for (const record of Object.values(skin.attachments[r.slot] ?? {})) {\n const g = record.geometry;\n if (g?.kind !== 'path') continue;\n for (const b of g.vertices.weighted ? g.vertices.bindings.flatMap((v) => v.map((x) => x.bone)) : [r.slotBone]) if (!deps.includes(b)) deps.push(b);\n }\n }\n r.slotDeps = deps;\n }\n}\n\n/** Every linked mesh whose `skin`, `slot` and `source` do not resolve to a mesh record, named — the runtime refuses such a file too. */\nfunction linkProblems(skins: readonly CoreSkin[]): string[] {\n const out: string[] = [];\n skins.forEach((skin, i) => {\n for (const [slot, table] of Object.entries(skin.attachments)) {\n for (const [placeholder, record] of Object.entries(table)) {\n const g = record.geometry;\n if (g?.kind !== 'linkedmesh') continue;\n const why = sourceProblem(skins, g.skin, g.slot, g.source);\n if (why !== null) out.push(`skins[${i}] \"${skin.name}\".attachments[\"${slot}\"][\"${placeholder}\"]: ${why}`);\n }\n }\n });\n return out;\n}\n\n/** Why a linked mesh's source does not resolve, or null when it is a mesh record. */\nfunction sourceProblem(skins: readonly CoreSkin[], skin: string, slot: string, source: string): string | null {\n const found = skins.find((k) => k.name === skin);\n if (found === undefined) return `the linked mesh's skin \"${skin}\" is not a skin of this document`;\n const record = found.attachments[slot]?.[source];\n if (record === undefined) return `the linked mesh's source \"${source}\" is not in skin \"${skin}\" slot \"${slot}\"`;\n if (record.kind !== 'mesh') return `the linked mesh's source \"${source}\" in skin \"${skin}\" slot \"${slot}\" is a ${record.kind}, not a mesh`;\n return null;\n}\n\n/**\n * The oracle's rounding, stated in its header: six decimals, half up\n * (`Math.round(v * 1e6) / 1e6`), `null` for a value that is not finite, and a\n * `-0` written as `0`. `tools/pose_oracle.ts` rounds with this function, so the\n * two dumpers cannot round two ways.\n */\nexport function gridRound(v: number): number | null {\n if (!Number.isFinite(v)) return null;\n const out = Math.round(v * 1e6) / 1e6;\n return out === 0 ? 0 : out;\n}\n\n/**\n * The raw entry's number (issue #966): the double as computed, `null` for a\n * value that is not finite, and a `-0` written as `0` — what `JSON.stringify`\n * writes for it anyway, so an in-process row and its document agree. No grid:\n * `pose_oracle.ts dump --raw` writes both dumpers' numbers through this.\n */\nexport function rawNumber(v: number): number | null {\n if (!Number.isFinite(v)) return null;\n return v === 0 ? 0 : v;\n}\n\n/** One bone of a posed setup: `[name, worldX, worldY, a, b, c, d, active, parent]`, the oracle's row. */\nexport type CoreBoneRow = [string, number | null, number | null, number | null, number | null, number | null, number | null, 0 | 1, string | null];\n\n/** What computes the world transforms: the core's own `worldTransforms` (`./world.ts`) unless a caller passes another. */\nexport type SetupEvaluator = (bones: readonly ModelBone[], active: ReadonlySet<string>) => Map<string, CoreWorld>;\n\n/** One slot of a posed setup: `[name, attachment, r, g, b, a, dark, path, blend]`, the oracle's row. */\nexport type CoreSlotRow = [string, string | null, number | null, number | null, number | null, number | null, [number | null, number | null, number | null] | null, string | null, string | null];\n\n/** The record a slot's setup placeholder resolves to, and the skin whose table holds it. */\nexport interface CoreShown {\n skin: string;\n placeholder: string;\n record: CoreAttachment;\n}\n\n/**\n * What a slot shows at setup: `null` for nothing, the record shown, or — when\n * the skins filling its placeholder disagree about the row — `conflict`,\n * naming each skin with the name it would show (the header's ⚠️).\n */\nexport type ShownResolution = CoreShown | null | { conflict: Array<{ skin: string; shown: string; path: string | null }> };\n\n/** What resolves a slot's setup attachment: `shownAttachment` unless a caller passes another. */\nexport type ShownResolver = (doc: CompiledDocument, slot: ModelSlot) => ShownResolution;\n\n/** What reads a slot's blend mode: `readBlend` unless a caller passes another. */\nexport type BlendReader = (slot: ModelSlot) => CoreBlendMode;\n\n/** What reads a stated light colour into its four channels: `readColour` unless a caller passes another. */\nexport type ColourReader = (hex: string) => [number, number, number, number];\n\n/**\n * The five pose stages a step passes through when instrumented (`StageHooks`,\n * issue #1589):\n * - `timeline`: timeline evaluation, animated bone local copy, attachment/deform/sequence timeline states\n * - `world`: bone hierarchy world-transform composition (`worldTransforms`)\n * - `constraints`: constraint record posing, physics step, and constraint solver orchestration (`applyConstraints`)\n * - `geometry`: region corners, mesh/deformed world vertices, and triangle clipping (`drawnGeometry`)\n * - `readout`: slot rows, draw-order resolution/sorting, bone rows, drawn row packaging, and events\n */\nexport type CoreStage = 'timeline' | 'world' | 'constraints' | 'geometry' | 'readout';\n\n/** Zero-cost-when-absent per-stage instrumentation callbacks on `CorePlant` (issue #1589). */\nexport interface StageHooks {\n begin(stage: CoreStage): void;\n end(stage: CoreStage): void;\n}\n\n/**\n * What the core poses with, each part replaceable. The core suite's plants\n * pass a copy of one of them — a mode's sign flipped, the wrong skin, a\n * channel misread — and nothing else passes any.\n */\nexport interface CorePlant {\n /** Optional read of the solved local channels and applied slider mappings; never modifies the pose. */\n readLocals?: (bones: readonly ModelBone[], sliders: readonly SliderApplication[]) => void;\n evaluate?: SetupEvaluator;\n shown?: ShownResolver;\n colour?: ColourReader;\n /** A slot's blend mode (`readBlend`). */\n blend?: BlendReader;\n /** A region's corners (`regionCorners` in `./vertices.ts`). */\n region?: RegionPoser;\n /** A vertex array's world positions (`worldVertices` in `./vertices.ts`). */\n vertices?: VertexPoser;\n /** A deformed vertex array's world positions (`deformedWorldVertices` in `./vertices.ts`). */\n deformedVertices?: DeformedVertexPoser;\n /** A drawn mesh's read-only UVs and triangles (`meshArraysOf` in `./vertices.ts`) — the raw entry's `drawn`; nothing but a control passes one. */\n meshArrays?: MeshArraysOf;\n /** The ik, transform and path constraints as posed, rewritten before they are applied (`./constraints.ts`). */\n constraints?: ConstraintPlant;\n /** Issue #979's solver rules, one planted back to the reading before it (`RUNTIME_SOLVER_RULES` in `./constraints.ts`). */\n solver?: Partial<SolverRules>;\n /** A deform timeline's array at a time (`deformAt` in `./deform.ts`). */\n deform?: DeformEvaluator;\n /** A slider's deform over the current one (`blendDeform` in `./deform.ts`). */\n deformBlend?: DeformBlender;\n /** A sequence timeline's frame at a time (`sequenceFrameAt` in `./deform.ts`). */\n sequence?: SequenceEvaluator;\n /** A draw-order timeline's order at a time (`drawOrderAt` in `./draw_order.ts`). */\n drawOrder?: DrawOrderEvaluator;\n /** The events fired between two samples (`eventsFired` in `./events.ts`). */\n events?: EventsFired;\n /** The stepped phase's step of one physics constraint (`stepPhysics` in `./constraints_physics.ts`). */\n physicsStep?: PhysicsStepper;\n /** One attachment's triangles against a clip polygon (`clipTriangles` in `./clipping.ts`). */\n clip?: TriangleClipper;\n /** One attachment's triangles against any clip the core draws (`clipThrough` in `./clipping.ts`) — the drawn rows the raw entry hands the render. */\n through?: ShapeClipper;\n /** Whether a slot's timelines apply (`slotTimelinesApply` in `./skins.ts`). */\n slotTimelines?: SlotTimelineGate;\n /**\n * Not a plant: what every number of a row is written as — `gridRound` (the\n * oracle's grid) unless the raw entry (`./raw.ts`, issue #966) passes\n * `rawNumber`, the unrounded double.\n */\n round?: (v: number) => number | null;\n /** Per-stage instrumentation callbacks for `tools/pose_bench.ts` (issue #1589); absent on every uninstrumented walk. */\n stage?: StageHooks;\n}\n\n/** The document's ik, transform and path constraint records, in its order — what `applyConstraints` runs. */\nexport function constraintRecords(doc: CompiledDocument): CoreConstraintRecord[] {\n return doc.constraints.flatMap((c) => (c.record === undefined ? [] : [c.record]));\n}\n\n/**\n * The blocks of the oracle's document the core does not produce, each with the\n * construct that has to be admitted first (§5 of the design on issue #380), in the\n * document's key order. Empty since issue #956 wrote the `physics` block, the\n * last one; kept so a block left to a later construct has one place to be\n * named. `setup.*` blocks are not here: each is produced, or absent for the\n * reason `poseSetup` gives.\n */\nexport const NOT_ADMITTED: ReadonlyArray<readonly [string, string]> = [];\n\n/** The setup blocks the core poses, in the document's order. */\nconst POSED_BLOCKS = ['setup.bones', 'setup.slots', 'setup.drawOrder', 'setup.attachments', 'setup.clips', 'setup.clipped'] as const;\n\n/** Each view's active bones, kept for the view (`activeBones`). */\nconst activeOfView = new WeakMap<CompiledDocument, ReadonlySet<string>>();\n\n/**\n * Bones active under the skin view posed — the rule measured in the header\n * (`all`) and in `./skins.ts` (a named skin). Derived once per view object and\n * kept with it (issue #1134): the answer reads the view's bones and skins\n * only, a view is never written once it is posed, and every pose of a walk\n * asked again. Read-only to every caller; a view built anew (`underSkin`,\n * `underNoSkin`, a plant's) derives its own.\n */\nexport function activeBones(doc: CompiledDocument): ReadonlySet<string> {\n const kept = activeOfView.get(doc);\n if (kept !== undefined) return kept;\n const made = deriveActiveBones(doc);\n activeOfView.set(doc, made);\n return made;\n}\n\nfunction deriveActiveBones(doc: CompiledDocument): ReadonlySet<string> {\n const named = new Set(appliedSkins(doc).flatMap((s) => s.bones));\n const parentOf = new Map(doc.bones.map((b) => [b.name, b.parent]));\n const reached = new Set<string>();\n for (const name of named) {\n for (let at: string | undefined = name; at !== undefined && !reached.has(at); at = parentOf.get(at)) reached.add(at);\n }\n return new Set(doc.bones.filter((b) => b.skinRequired !== true || reached.has(b.name)).map((b) => b.name));\n}\n\n/**\n * A stated light colour's four channels: each pair of hex digits over 255,\n * and an alpha of 1 when six digits are stated (the header's measurement).\n * `readModel` has already refused every other spelling.\n */\nexport function readColour(hex: string): [number, number, number, number] {\n const channel = (i: number): number => Number.parseInt(hex.slice(2 * i, 2 * i + 2), 16) / 255;\n return [channel(0), channel(1), channel(2), hex.length === 8 ? channel(3) : 1];\n}\n\n/** A stated colour's channels, read once and shared (`viewColours`): read, or copied before a write — never handed out. */\nexport type StatedColour = Readonly<[number, number, number, number]>;\n\n/** Each view's stated colours, by spelling, read once (`viewColours`). */\nconst coloursOfView = new WeakMap<CompiledDocument, Map<string, StatedColour>>();\n\n/**\n * The view's reader of a stated colour: `readColour(hex)` read the first time\n * the view meets that spelling and kept, frozen, for every pose after it. The\n * slot rows read every slot's colours on every pose, and a drawn row its\n * record's (the parse was a measured share of a step). The reading is the\n * spelling's alone, so the cache is keyed on the spelling rather than on a\n * slot or a record — a colour respelled in place reads its new spelling, and\n * a view built anew starts its own. The tuple is shared by every pose, so no\n * caller hands it out or writes it (`StatedColour` is read-only): a pose's\n * channels are copied out of it. It is not frozen because a frozen array is\n * read several times slower under JavaScriptCore, measured on Bun 1.4.4, and\n * the read is the whole of what the cache is for. The core suite's `CO63`\n * holds a pose's colours to their spelling and to the pose.\n */\nexport function viewColours(doc: CompiledDocument): (hex: string) => StatedColour {\n let kept = coloursOfView.get(doc);\n if (kept === undefined) {\n kept = new Map();\n coloursOfView.set(doc, kept);\n }\n const colours = kept;\n return (hex) => {\n let c = colours.get(hex);\n if (c === undefined) {\n c = readColour(hex);\n colours.set(hex, c);\n }\n return c;\n };\n}\n\n/** A slot or record that states no light colour: white, opaque. */\nexport const WHITE: StatedColour = [1, 1, 1, 1];\n\n/**\n * A slot's blend mode: `Normal` when it states none, else the stated\n * spelling folded (the header's measurement). `readModel` has already refused\n * every spelling that folds to no mode.\n */\nexport function readBlend(slot: ModelSlot): CoreBlendMode {\n if (slot.blend === undefined) return 'Normal';\n const mode = foldBlend(slot.blend);\n if (mode === null) throw new CoreInputError(`slot \"${slot.name}\": blend ${JSON.stringify(slot.blend)} is no mode the runtime reads`);\n return mode;\n}\n\n/** The name a record shows and the region path it names — the header's two measured rules. */\nexport function shownRow(shown: CoreShown): { name: string; path: string | null } {\n const name = shown.record.name ?? shown.placeholder;\n return { name, path: CORE_REGION_KINDS.has(shown.record.kind) ? (shown.record.path ?? name) : null };\n}\n\n/** Each view's resolutions, by slot and placeholder, kept for the view (`shownAttachment`). */\nconst shownOfView = new WeakMap<CompiledDocument, Map<string, Map<string, ShownResolution>>>();\n\n/**\n * What a slot shows at setup under every skin at once — the header's rule:\n * nothing for a `null` placeholder or one no skin fills; the one record where\n * every skin filling the placeholder gives the same row; a `conflict`, naming\n * each skin in the model's order, where they differ.\n *\n * The answer reads the view's skins and the slot's name and placeholder only,\n * so it is resolved once per view, slot and placeholder and kept (issue\n * #1134: every sample of a walk resolved every slot again). Read-only to every\n * caller; a view built anew resolves its own. An explicit placeholder reads\n * another table key without changing the slot (issue #1538).\n */\nexport function shownAttachment(doc: CompiledDocument, slot: ModelSlot, placeholder: string | null = slot.setup): ShownResolution {\n if (placeholder === null) return null;\n let bySlot = shownOfView.get(doc);\n if (bySlot === undefined) {\n bySlot = new Map();\n shownOfView.set(doc, bySlot);\n }\n let byPlaceholder = bySlot.get(slot.name);\n if (byPlaceholder === undefined) {\n byPlaceholder = new Map();\n bySlot.set(slot.name, byPlaceholder);\n }\n if (byPlaceholder.has(placeholder)) return byPlaceholder.get(placeholder) as ShownResolution;\n const resolved = resolveShown(doc, slot.name, placeholder);\n byPlaceholder.set(placeholder, resolved);\n return resolved;\n}\n\nfunction resolveShown(doc: CompiledDocument, slotName: string, placeholder: string): ShownResolution {\n // Under a named skin: that skin's record, else the default skin's, else nothing (`./skins.ts`).\n if (doc.skin !== CORE_ALL_SKINS) {\n for (const skin of lookupSkins(doc)) {\n const record = skin.attachments[slotName]?.[placeholder];\n if (record !== undefined) return { skin: skin.name, placeholder, record };\n }\n return null;\n }\n const filling: CoreShown[] = [];\n for (const skin of doc.skins) {\n const record = skin.attachments[slotName]?.[placeholder];\n if (record !== undefined) filling.push({ skin: skin.name, placeholder, record });\n }\n if (filling.length === 0) return null;\n const rows = filling.map((f) => ({ skin: f.skin, ...shownRow(f) }));\n const agree = rows.every((r) => r.name === rows[0].name && r.path === rows[0].path);\n return agree ? filling[0] : { conflict: rows.map((r) => ({ skin: r.skin, shown: r.name, path: r.path })) };\n}\n\n/** The oracle's `setup` block as the core writes it: bones, slots, attachments and clips posed or absent, the draw order absent. */\nexport interface CoreSetup {\n bones: CoreBoneRow[] | null;\n slots: CoreSlotRow[] | null;\n drawOrder: string[] | null;\n attachments: CoreAttachmentRow[] | null;\n clips: CoreClipRow[] | null;\n /** The triangles drawn under a clip, as the clipper returns them (issue #964, `./clipping.ts`). */\n clipped: CoreClippedRow[] | null;\n}\n\n/**\n * The setup pose of every bone and every slot, in the oracle's row shapes and\n * rounding, and every block the core leaves absent with its reason (`absent`,\n * in document order). Bones are absent when the document declares a\n * constraint (the header's ⚠️), with the kinds and counts named; slots are\n * absent when a slot's setup placeholder is filled by skins that disagree\n * (the slots' ⚠️), with each such slot named. The attachments' world vertices\n * and the clipping polygons (`./vertices.ts`, issue #931) are absent when\n * either of those is — they go through the bones' world matrices and follow\n * what each slot shows — and the attachments also when a shown region's atlas\n * rectangle is `null`, every such slot named.\n */\nexport function poseSetup(doc: CompiledDocument, plant: CorePlant = {}, physics?: PhysicsStepContext): { setup: CoreSetup; absent: Array<[string, string]>; world: Map<string, CoreWorld> | null; shown: ShownGeometry[] | null } {\n const evaluate = plant.evaluate ?? worldTransforms;\n const resolve = plant.shown ?? shownAttachment;\n const colour = plant.colour ?? readColour;\n const blend = plant.blend ?? readBlend;\n const round = plant.round ?? gridRound;\n const bonesWhy = constraintsAbsentWhy(doc, solverRules(plant.solver));\n let bones: CoreBoneRow[] | null = null;\n let setupWorld: Map<string, CoreWorld> | null = null;\n // Each slider as it was applied, in constraint order — what the slots are posed from (`./constraints_slider.ts`).\n const applied: SliderApplication[] = [];\n if (bonesWhy === null) {\n const active = activeBones(doc);\n const records = constraintRecords(doc);\n setupWorld = applyConstraints(doc.bones, evaluate(doc.bones, active), active, plant.constraints ? plant.constraints(records) : records, null, applied, physics, plant.readLocals === undefined ? undefined : (state) => plant.readLocals?.(state.bones, applied), solverRules(plant.solver));\n const world = setupWorld;\n bones = doc.bones.map((b): CoreBoneRow => {\n const t = world.get(b.name);\n if (t === undefined) throw new CoreInputError(`the evaluator returned no transform for bone \"${b.name}\"`);\n return [b.name, round(t.worldX), round(t.worldY), round(t.a), round(t.b), round(t.c), round(t.d), active.has(b.name) ? 1 : 0, b.parent ?? null];\n });\n }\n const conflicts: string[] = [];\n const slotRows: CoreSlotRow[] = [];\n const liveBones = activeBones(doc);\n const slotGate = plant.slotTimelines ?? slotTimelinesApply;\n for (const slot of doc.slots) {\n const pose: SlotPoseState = {\n placeholder: slot.setup,\n light: slot.color === undefined ? [1, 1, 1, 1] : [...colour(slot.color)],\n dark: slot.dark === undefined ? null : readColour(slot.dark).slice(0, 3),\n };\n // A slot on an inactive bone is not animated, by a slider either (`./skins.ts`).\n if (slotGate(doc, slot, liveBones)) applySliderSlots(slot.name, pose, applied);\n const posedRecord: ModelSlot = { ...slot, setup: pose.placeholder };\n const shown = pose.placeholder === null ? null : resolve(doc, posedRecord);\n if (shown !== null && 'conflict' in shown) {\n conflicts.push(`slot \"${slot.name}\" placeholder \"${pose.placeholder}\" is filled by skins ${shown.conflict.map((c) => `\"${c.skin}\" (shows ${JSON.stringify(c.shown)}, path ${JSON.stringify(c.path)})`).join(', ')}`);\n continue;\n }\n const row = shown === null ? null : shownRow(shown);\n const [r, g, b, a] = pose.light;\n const dark = pose.dark;\n slotRows.push([\n slot.name,\n row === null ? null : row.name,\n round(r), round(g), round(b), round(a),\n dark === null ? null : [round(dark[0]), round(dark[1]), round(dark[2])],\n row === null ? null : row.path,\n blend(slot),\n ]);\n }\n const slotsWhy = (bonesWhy === null ? null : slidersWhy(doc)) ?? (conflicts.length === 0\n ? null\n : `${conflicts.join('; ')} — under --skin all the LAST of them in the Spine file's skin order wins, and that order is the emitter's (default first, the rest in the editor's order), not the model's; the per-skin dumps (--skin <name>) judge it`);\n const slots = slotsWhy === null ? slotRows : null;\n const upstream = [bonesWhy === null ? null : `setup.bones is absent (${bonesWhy}), and every vertex goes through a bone's world matrix`, slotsWhy === null ? null : 'setup.slots is absent, so what a slot shows is not posed'].filter((x): x is string => x !== null);\n // The draw order: the slot order, then each slider's draw-order key (`./draw_order.ts`), which needs the sliders' times, read off the bones.\n const orderWhy = bonesWhy === null ? null : slidersKeyingWhy(doc, 'drawOrder');\n let drawOrder: string[] | null = null;\n if (orderWhy === null) {\n let order: number[] = doc.slots.map((_s, i) => i);\n for (const app of applied) order = (plant.drawOrder ?? drawOrderAt)(doc.slots.length, app.timelines.drawOrder, app.at) ?? order;\n drawOrder = order.map((i) => doc.slots[i].name);\n }\n let attachments: CoreAttachmentRow[] | null = null;\n let clips: CoreClipRow[] | null = null;\n let clipsWhy: string | null = upstream.length === 0 ? null : upstream.join('; ');\n let attachmentsWhy: string | null = clipsWhy;\n let clipped: CoreClippedRow[] | null = null;\n let clippedWhy: string | null = clipsWhy ?? orderWhy;\n // What the raw entry reads past the rows (issue #966, `./raw.ts`): the unrounded world transforms and the shown records in draw order.\n let shownInOrder: ShownGeometry[] | null = null;\n if (clipsWhy === null && setupWorld !== null && drawOrder !== null) {\n const world = setupWorld;\n // Each slot's shown record, with what the sliders' deform and sequence timelines set on it (`./deform.ts`), in the draw order.\n // From the setup placeholders; `attachmentStates` applies each slider's attachment key, then its deform and sequence keys, in order.\n const placeholders = new Map(doc.slots.map((sl) => [sl.name, sl.setup]));\n const states = attachmentStates(doc, resolve, placeholders, null, applied, plant);\n const rank = new Map(drawOrder.map((n, i) => [n, i]));\n const shown = [...states.shown].sort((a, b) => (rank.get(a.slot) ?? 0) - (rank.get(b.slot) ?? 0));\n shownInOrder = states.why.length === 0 ? shown : null;\n const posed = poseGeometry(shown, world, sourceOfDoc(doc), round, { region: plant.region, vertices: plant.vertices }, drawWalkOf(doc, drawOrder, plant));\n const stateWhy = states.why.length === 0 ? null : `${states.why.join('; ')}`;\n attachments = stateWhy === null ? posed.attachments : null;\n attachmentsWhy = stateWhy ?? posed.attachmentsWhy;\n clips = stateWhy === null ? posed.clips : null;\n clipsWhy = stateWhy;\n clipped = stateWhy === null ? posed.clipped : null;\n clippedWhy = stateWhy ?? posed.clippedWhy;\n }\n // `NOT_ADMITTED` is in document order; bones and slots stand before `setup.drawOrder`, attachments and clips after it.\n const why: Record<(typeof POSED_BLOCKS)[number], string | null> = { 'setup.bones': bonesWhy, 'setup.slots': slotsWhy, 'setup.drawOrder': orderWhy, 'setup.attachments': attachmentsWhy, 'setup.clips': clipsWhy, 'setup.clipped': clippedWhy };\n // `NOT_ADMITTED` (empty since issue #956) stands before the setup blocks in the document's order.\n const absent: Array<[string, string]> = NOT_ADMITTED.map(([block, reason]): [string, string] => [block, reason]);\n for (const block of POSED_BLOCKS) if (why[block] !== null) absent.push([block, why[block] as string]);\n return { setup: { bones, slots, drawOrder, attachments, clips, clipped }, absent, world: setupWorld, shown: shownInOrder };\n}\n\n/** What the clipped block's draw walk reads (`DrawWalk` in `./vertices.ts`): the draw order, the active bones, and a linked mesh's source triangles. */\nexport function drawWalkOf(doc: CompiledDocument, order: readonly string[], plant: CorePlant = {}): DrawWalk {\n const active = activeBones(doc);\n return {\n order,\n active,\n meshOf: (skin, slot, source) => {\n const g = doc.skins.find((k) => k.name === skin)?.attachments[slot]?.[source]?.geometry;\n return g?.kind === 'mesh' ? { uvs: g.uvs, triangles: g.triangles } : undefined;\n },\n ...(plant.clip === undefined ? {} : { clip: plant.clip }),\n ...(plant.through === undefined ? {} : { through: plant.through }),\n };\n}\n\n/** A linked mesh's source vertices, or why they do not resolve — what `poseGeometry` reads a linked mesh through. */\nexport function sourceOfDoc(doc: CompiledDocument): (skin: string, slot: string, source: string) => ModelVertices | string {\n return (skin, slot, source) => {\n const g = doc.skins.find((k) => k.name === skin)?.attachments[slot]?.[source]?.geometry;\n return g?.kind === 'mesh' ? g.vertices : (sourceProblem(doc.skins, skin, slot, source) ?? `the linked mesh's source \"${source}\" carries no vertices`);\n };\n}\n\n/** Why a block a slider's animation keys cannot be posed because the bones its time is read from are absent, or null: `drawOrder` for the draw order. */\nexport function slidersKeyingWhy(doc: CompiledDocument, group: 'drawOrder'): string | null {\n const keyed = doc.constraints.flatMap((c) => {\n if (c.kind !== 'slider') return [];\n const anim = doc.animations.find((a) => a.name === c.animation);\n return anim !== undefined && anim.timelines[group].length > 0 ? [`slider \"${c.name}\" applies animation \"${c.animation}\", which keys the draw order`] : [];\n });\n return keyed.length === 0 ? null : `${keyed.join('; ')} — a slider's time is read off the bones, which are absent`;\n}\n\n/** Why the setup slots cannot be posed because a slider poses them and the bones its time is read from are absent, or null when no slider's animation keys a slot. */\nfunction slidersWhy(doc: CompiledDocument): string | null {\n const keyed = doc.constraints.flatMap((c) => {\n if (c.kind !== 'slider') return [];\n const slots = doc.animations.find((a) => a.name === c.animation)?.slots ?? [];\n return slots.length === 0 ? [] : [`slider \"${c.name}\" applies animation \"${c.animation}\", which keys slot(s) ${slots.map((x) => `\"${x}\"`).join(', ')}`];\n });\n return keyed.length === 0 ? null : `${keyed.join('; ')} — the oracle's setup applies sliders, and a slider poses the slots its animation keys at a time read off the bones, which are absent`;\n}\n","import { poseDial, type DialOverride } from './hooks.ts';\n/**\n * The core's raw entry (issue #966, step 3b of issue #380): one pose, or one\n * animation walked at the caller's own steps, returned as the doubles the\n * core computed — no grid — with everything a renderer or a deform measurer\n * reads past the oracle's rows: each bone's world rotation and scale\n * readings, each drawn attachment's local UVs, triangles, hull, sequence\n * frame and colour, the clip polygons, the triangles drawn under a clip, and\n * the events fired.\n *\n * The oracle's document (`tools/pose_oracle.ts`) samples an animation on a\n * phase grid, re-applying it from the setup pose at every sample; the two\n * consumers step instead. `src/render.ts` resets a track at 0 and then takes\n * exactly one step of `1/fps` per frame; `src/deformmeasure.ts` resets and\n * takes one step of `time`. So the entry takes a list of steps rather than a\n * list of times, and this header states what one step is, as measured.\n *\n * ## One step — the walk, measured\n *\n * Measured against spine-core 4.3.13 running `src/render.ts`'s recipe\n * (`AnimationState` with one non-looping track: frame 0 `apply`,\n * `Skeleton.update(0)`, `updateWorldTransform(Physics.reset)`; every later\n * frame `AnimationState.update(dt)`, `apply`, `Skeleton.update(dt)`,\n * `updateWorldTransform(Physics.update)`), read off `TrackEntry.trackTime`,\n * `TrackEntry.getAnimationTime()` and every bone's `appliedPose` in full\n * doubles (the PR of issue #966 carries the table):\n *\n * - **The track time is the running sum of the steps**, `T += dt` in double,\n * not `i·dt`, and the animation is applied at the sum. Over every\n * animation of the nineteen tree rows `TrackEntry.trackTime` equalled the\n * running sum on 2,612 of 2,612 frames at 12 fps (12,850 of 12,850 at 60,\n * 5,173 of 5,173 at 24) and `i·dt` on only 662 (1,168; 810): at 12 fps\n * frame 6 reads `0.49999999999999994`, not `0.5`, and frame 10\n * `0.8333333333333334`, not `0.8333333333333333`. `src/render.ts` files a\n * frame under `i·dt`, which is its label and not the time posed.\n * - **A non-looping track holds at its duration**: the animation time is\n * `min(T, duration)`, where `duration` is the runtime's (the last key of\n * every timeline, as float32 — `CoreAnimationTimelines.duration`). With\n * `round(duration·fps)` frames the last one overshoots on 20 animation\n * frames of the 2,612 at 12 fps (19 at 60, 25 at 24), and\n * `getAnimationTime()` read the duration on every one of them.\n * - **The physics clock moves by the step itself**, `time += dt` (the\n * skeleton's `update`), and a physics constraint integrates the time it\n * moved (`./constraints_physics.ts`). Pose 0 is the reset, every physics\n * state reset there (where, below).\n * - **Events fire over `(previous animation time, animation time]`**, the\n * first step's interval opening at −1 — so held past the duration, a step\n * fires nothing. Measured against `AnimationState`'s event listener on\n * every frame above.\n * - **Where the reset is taken is the caller's** (`RawReset`): render's\n * frame 0 applies the animation at 0 and resets there (`animation`);\n * deformmeasure's `poseAt` resets at the setup pose and then applies the\n * animation in its one step (`setup`). On a physics rig the two differ by\n * whole units, not bits: of the 162 one-jump poses (three per animation),\n * 12 read off under `animation` — six on `7-anticipation`'s physics rig (a\n * cape bone 1.7° off at 0.617 s) and six on `gallery/look`'s — and none\n * under `setup`.\n *\n * Every step poses the animation from the setup pose at its animation time\n * (the setup blend at alpha 1), as the oracle's stepped dump does, applied\n * from the animation time of the step before (−1 before the first): a\n * physics `reset` key fires on the step that crosses it, once. Until issue\n * #960 this walk fired such a key at every step from it on (the oracle's\n * reading then), and against the recipe above a probe with a key at 0.5\n * read 32 of 61 frames bit-exact at 60 fps, the rest off by up to 53 units;\n * with the key crossed once, 61 of 61 at 60 fps and 13 of 13 at 12. None of\n * the nineteen tree rows keys a `reset`, which is why the raw gate never\n * saw it. The one difference from `--physics step` is where the steps fall,\n * which is the caller's.\n *\n * ## What a pose carries\n *\n * - `bones` — the world matrix and origin, and the four readings the\n * runtime's getters give: `rotationX = atan2(c, a)·DEG`, `rotationY =\n * atan2(d, b)·DEG`, `scaleX = √(a² + c²)`, `scaleY = √(b² + d²)`, with\n * `DEG = 180 / π` at the runtime's π (`RUNTIME_DEG` in `./world.ts`) —\n * measured bit-exact against `BonePose.getWorldRotationX/Y` and\n * `getWorldScaleX/Y` on every bone of 2,793 poses of the nineteen tree\n * rows (the setup, every 12 fps frame, three jumps per animation).\n * - `slots` — the oracle's slot row as doubles (`posedSlots`).\n * - `drawn` — every region and mesh a slot shows, in draw order: its world\n * vertices (the oracle's `attachments` row as doubles), its LOCAL UVs as the\n * runtime holds them (a region's unit corners `0 1, 0 0, 1 0, 1 1` in the\n * corner order; a mesh's `uvs` — a linked mesh's source's — as the\n * document spells them: `MeshAttachment.regionUVs` read the doubles, not\n * their float32, on every mesh of the nineteen rows — `6-arcs`'\n * `2.554152e-7` where `Math.fround` gives `2.5541518766658555e-7`), its\n * triangles (a region's `0 1 2 2\n * 3 0`), its hull (a mesh's; `null` for a region), its sequence frame (the\n * frame a sequence timeline set, else the series' setup frame, else 0 —\n * the runtime gives every region and mesh a series, one frame long when\n * the record states none, and `Sequence.resolveIndex` read 0 on every such\n * attachment of the nineteen rows) and its own colour (the record's `color`, white\n * unstated) — so the caller forms the tint, slot colour times attachment\n * colour, itself. Where a region sits on a page is not the model's\n * (`ModelAtlasRect`'s 🔸); the page UVs are issue #967's.\n * - `clips`, `clipped` — the oracle's rows as doubles; `clipped` is what the\n * core DRAWS, which is the oracle's block wherever the core poses it and,\n * under a clip that is not strictly convex or is inverse (a block the core\n * leaves out), the core's own convex decomposition (`clipThrough` in\n * `./clipping.ts`, issue #964), held to spine-core by the render's pixels.\n * - `events` — the oracle's event rows as doubles.\n *\n * 🔁 **A second walk shares this one** (issue #1025, cut 4c-5a): A10's\n * LOOPING walk, which keeps a non-finite value rather than refusing it, is\n * `./walk.ts`; both are `walkIn` below in a `WalkMode`, and every difference\n * is a branch on the mode — so this entry's walk is the one it was, and the\n * raw gate's lines did not move.\n *\n * ⛔ **Nothing is posed that the core would leave out.** Where the oracle's\n * core dump names a block absent — a constraint the core cannot pose\n * exactly, skins disagreeing over a placeholder under the merged view, a\n * region with no atlas rectangle — the raw entry refuses the whole call,\n * naming why (`CoreInputError`): a renderer handed a pose with a block\n * missing would draw a different picture in silence.\n */\nimport { activeBones, CoreInputError, drawWalkOf, poseSetup, rawNumber, shownAttachment, sourceOfDoc, underNoSkin, underSkin, viewColours, WHITE, type CompiledDocument, type CorePlant, type CoreSlotRow } from './index.ts';\nimport { posedBoneWorldAlone, posedSlots, type CoreAnimationTimelines, type LocalAdjust, type TimelinePlant } from './animation.ts';\nimport { constraintsAbsentWhy, pathAnimationsWhy } from './constraints.ts';\nimport { freshStepContext, rotatePhysics, steppedPreviousPassWhy, translatePhysics, DEFAULT_PHYSICS_ENVIRONMENT, type PhysicsEnvironment, type PhysicsStepContext } from './constraints_physics.ts';\nimport { attachmentStates } from './deform.ts';\nimport { drawOrderAt, type CoreDrawOrderKey } from './draw_order.ts';\nimport { eventsFired, type CoreEventRow } from './events.ts';\nimport { REGION_TRIANGLES, REGION_UVS, type CoreClippedRow, type ShapeClipper } from './clipping.ts';\nimport { meshArraysOf, poseGeometry, worldVertices, type CoreAttachmentRow, type CoreClipRow, type ShownGeometry } from './vertices.ts';\nimport { RUNTIME_DEG, type CoreWorld } from './world.ts';\nimport { fillingSkins } from './skins.ts';\nimport type { SliderApplication } from './constraints_slider.ts';\n\n/** One bone, posed: the world transform and the runtime getters' four readings (the header's `bones`). */\nexport interface RawBone {\n name: string;\n parent: string | null;\n active: boolean;\n a: number;\n b: number;\n c: number;\n d: number;\n worldX: number;\n worldY: number;\n rotationX: number;\n rotationY: number;\n scaleX: number;\n scaleY: number;\n}\n\n/** One region or mesh drawn, in draw order (the header's `drawn`). */\nexport interface RawDrawn {\n slot: string;\n attachment: string;\n kind: 'region' | 'mesh';\n vertices: number[];\n /** Frozen, and the same array on every pose of the document view (issue #1530): `REGION_UVS` for a region, `meshArraysOf` for a mesh. */\n uvs: readonly number[];\n /** Frozen and identity-stable, as `uvs` is. */\n triangles: readonly number[];\n hull: number | null;\n sequenceIndex: number;\n colour: [number, number, number, number];\n}\n\n/** One clip polygon: `[slot, attachment, end, polygon]` as doubles. */\nexport type RawClip = [string, string, string | null, number[]];\n/** One attachment drawn under a clip: `[slot, attachment, clipped, vertices, uvs, triangles]` as the clipper returns them. */\nexport type RawClipped = [string, string, 0 | 1, number[], number[], number[]];\n/** One event fired: `[name, time, int, float, string]`. */\nexport type RawEvent = [string, number, number, number, string | null];\n\n/**\n * Where a walk's physics is reset (the header's *One step*): `animation` —\n * the animation applied at 0 and the reset taken there (`src/render.ts`'s\n * frame 0); `setup` — the reset taken at the setup pose before the animation\n * is applied (`src/deformmeasure.ts`'s `poseAt`), pose 0 then the setup pose.\n */\nexport type RawReset = 'animation' | 'setup';\n\n/** One pose — the setup's, or one step of an animation's walk. */\nexport interface RawPose {\n /** The track time (the running sum of the steps), 0 for the setup pose. */\n trackTime: number;\n /** The time the animation was applied at: the track time held at the duration. */\n animationTime: number;\n bones: RawBone[];\n slots: CoreSlotRow[];\n drawOrder: string[];\n drawn: RawDrawn[];\n clips: RawClip[];\n clipped: RawClipped[];\n events: RawEvent[];\n // --- #968 render: begin ---\n /**\n * What each slot shows, in draw order — the records `drawn` was posed from\n * (skin, placeholder, series frame, deform). `src/render_core.ts` resolves\n * each drawn attachment's atlas region and page UVs through it, with\n * `./uvs.ts`'s `drawnRegions` (issue #967's gated rule), rather than walking\n * which record a slot shows a second time.\n */\n shown: ShownGeometry[];\n // --- #968 render: end ---\n}\n\n/**\n * One bone as the scan reads it (issue #1179, the second part): the world\n * matrix and origin `RawBone` carries, and none of the readings it forms from\n * them. `A10_NO_NAN_AFTER_STEPPING` reads these six numbers and the name off a\n * bone, and nothing else (`firstNonFinite` in `src/nonfinite.ts`).\n */\nexport interface ScanBone {\n name: string;\n a: number;\n b: number;\n c: number;\n d: number;\n worldX: number;\n worldY: number;\n}\n\n/**\n * One pose as the scan reads it (issue #1179, the second part) — the scan's\n * walk (`scanWalkIn`, `scanSetupIn`): the time the animation was applied at,\n * and the bones, slot rows and drawn attachments computed exactly as a\n * `RawPose`'s are. Internal to A10's walk (`./walk.ts`); no exported pose type\n * changed for it.\n */\nexport interface ScanPose {\n animationTime: number;\n bones: ScanBone[];\n slots: CoreSlotRow[];\n drawn: ScanDrawn[];\n}\n\n/** One region or mesh drawn, as the scan reads it: its slot, its name and its world vertices, as `RawDrawn` carries them. */\nexport interface ScanDrawn {\n slot: string;\n attachment: string;\n vertices: number[];\n}\n\n// --- #968 render: begin ---\n/** The shown records in `order`, the pose's draw order (a pose's `shown`). */\nfunction drawOrderOf(shown: readonly ShownGeometry[], order: readonly string[]): ShownGeometry[] {\n const rank = new Map(order.map((n, r) => [n, r]));\n return [...shown].sort((a, b) => (rank.get(a.slot) ?? 0) - (rank.get(b.slot) ?? 0));\n}\n// --- #968 render: end ---\n\n/** A double the entry computed: never `null`, since a non-finite pose is refused rather than passed on. */\nfunction finite(v: number | null, what: string): number {\n if (v === null) throw new CoreInputError(`the raw pose computed a non-finite ${what}`);\n return v;\n}\n\n/**\n * How a walk treats the two things the raw entry and the looping walk\n * (`./walk.ts`, issue #1025) read differently: whether the track loops, and\n * whether a value that is not finite is kept in the pose or refuses the call.\n * The raw entry is `{ loop: false, keep: false }`, and that is its contract.\n */\nexport interface WalkMode {\n loop: boolean;\n keep: boolean;\n /** A plant only (the core suite's `CO26`): the animation time a looping step applies at, from its track time, the duration and the track time before it — `loopedTime` unless given. */\n time?: (trackTime: number, duration: number, before: number) => number;\n /** What the physics clock moves by, from the step and how far the animation time moved — the step itself unless given: a plant (`CO26`), the render's offline clock passed to `poseRawAnimationEach` (issue #1380), or a live track's `clock` option (`./track.ts`, issue #1396). */\n clock?: (dt: number, moved: number) => number;\n /** A plant only (`CO26`): `false` fires no `reset` key across the wrap — the reading the walk was measured against and rejected. */\n wrapResets?: boolean;\n /**\n * The live track's looping mode (`./track.ts`, issue #1276): a looping walk\n * that fires its events across the wrap and cuts its clipped rows, as the\n * raw entry does. Absent on A10's looping walk (`./walk.ts`), which does\n * neither — its one reader reads no event and no clipped row.\n */\n live?: boolean;\n}\n\n/** The raw entry's mode: a track that holds at its duration, and a non-finite value refused. */\nconst RAW_MODE: WalkMode = { loop: false, keep: false };\n\n/** What a kept walk writes a number as: the double itself, finite or not — so a NaN and an Infinity stay what they are. */\nconst keptNumber = (v: number): number => v;\n\n/** The plant a walk in `mode` poses with: the raw entry's unrounded double, or under `keep` the number whatever it is. */\nconst roundPlant = (mode: WalkMode): CorePlant => ({ round: mode.keep ? keptNumber : rawNumber });\n\n/** A double a kept walk computed, as it is; a raw walk's, refused when it is not finite (`finite`). */\nfunction numberOf(v: number | null, what: string, mode: WalkMode): number {\n return mode.keep ? (v === null ? Number.NaN : v) : finite(v, what);\n}\n\n/**\n * What the looping walk cuts a drawn attachment through under a clip: nothing\n * (issue #1179). Its one reader, A10, reads no clipped row — `./walk.ts`\n * narrows them away with the events — so the walk does not cut them; what it\n * still does is plan every clip it starts (`poseClipped`'s `clipShapeOf`), so\n * a clip the core does not draw refuses the walk by name as before. Every\n * number a looping pose carries is computed as it was.\n */\nconst NO_CLIPPED_ROWS: ShapeClipper = () => null;\n\n/** The bones of a pose from the world transforms (the header's `bones`). */\nfunction rawBones(doc: CompiledDocument, world: ReadonlyMap<string, CoreWorld>): RawBone[] {\n const active = activeBones(doc);\n return doc.bones.map((b): RawBone => {\n const w = world.get(b.name);\n if (w === undefined) throw new CoreInputError(`bone \"${b.name}\" has no world transform`);\n return {\n name: b.name,\n parent: b.parent ?? null,\n active: active.has(b.name),\n a: w.a,\n b: w.b,\n c: w.c,\n d: w.d,\n worldX: w.worldX,\n worldY: w.worldY,\n rotationX: Math.atan2(w.c, w.a) * RUNTIME_DEG,\n rotationY: Math.atan2(w.d, w.b) * RUNTIME_DEG,\n scaleX: Math.sqrt(w.a * w.a + w.c * w.c),\n scaleY: Math.sqrt(w.b * w.b + w.d * w.d),\n };\n });\n}\n\n/**\n * The bones of a scan pose (`ScanBone`): `rawBones` less the parent, the\n * active flag and the four getter readings, which nothing the scan reads is\n * computed from — each reading is formed from the world after it is posed,\n * and the matrix and origin are copied as they are.\n */\nfunction scanBones(doc: CompiledDocument, world: ReadonlyMap<string, CoreWorld>): ScanBone[] {\n return doc.bones.map((b): ScanBone => {\n const w = world.get(b.name);\n if (w === undefined) throw new CoreInputError(`bone \"${b.name}\" has no world transform`);\n return { name: b.name, a: w.a, b: w.b, c: w.c, d: w.d, worldX: w.worldX, worldY: w.worldY };\n });\n}\n\n/**\n * What a pose draws, posed and refused where the core leaves it out: the\n * attachment rows, the clip rows and the drawn clipped rows — what `rawDrawn`\n * and `scanDrawn` both assemble from.\n */\nfunction drawnGeometry(doc: CompiledDocument, shown: readonly ShownGeometry[], world: ReadonlyMap<string, CoreWorld>, order: readonly string[], plant: CorePlant, mode: WalkMode): { rows: CoreAttachmentRow[]; clips: CoreClipRow[]; drawnClipped: CoreClippedRow[] } {\n const draw = drawWalkOf(doc, order, plant);\n const geometry = poseGeometry(shown, world, sourceOfDoc(doc), mode.keep ? keptNumber : rawNumber, { region: plant.region, vertices: plant.vertices, deformedVertices: plant.deformedVertices }, mode.loop && mode.live !== true && plant.through === undefined ? { ...draw, through: NO_CLIPPED_ROWS } : draw);\n if (geometry.attachments === null) throw new CoreInputError(`the raw pose leaves the attachments out: ${geometry.attachmentsWhy}`);\n // The drawn rows (issue #964): the oracle's `clipped` rows where it is posed, and a concave or inverse clip cut through the core's own decomposition.\n if (geometry.drawnClipped === null) throw new CoreInputError(`the raw pose leaves the clipped triangles out: ${geometry.drawnClippedWhy}`);\n return { rows: geometry.attachments, clips: geometry.clips, drawnClipped: geometry.drawnClipped };\n}\n\n/**\n * The drawn attachments of a scan pose (`ScanDrawn`): `rawDrawn`'s rows, each\n * its slot, its name and its world vertices through the same `numberOf`, and\n * none of what `rawDrawn` reads past them for a renderer — the UVs and\n * triangles it copies, the record it looks up for the colour and the sequence\n * frame, the hull, the clip rows' numbers. No vertex is computed from any of\n * those. The one refusal `rawDrawn` makes past the rows, a linked mesh whose\n * source carries no mesh, is not reachable here: `poseGeometry` resolved the\n * same source by the same lookup (`sourceOfDoc`) and throws before it returns.\n *\n * 🔁 **No copy of the vertices** (issue #1179, the second part): `rawDrawn`\n * maps each row through `numberOf` into a new array; under `keep` that map is\n * the identity on every number and turns only a `null` into NaN. The scan\n * hands the row's own array on wherever it holds no `null` (`allNumbers`) and\n * maps it as before where it does, so A10 reads the same values either way.\n * What makes the row's array safe to keep past the step — A10 collects an\n * animation's 120 frames before it scans one — is that it is the pose's own:\n * `poseGeometry` (`./vertices.ts`) hands every row the corners or the skinned\n * vertices the poser just computed, a new array per attachment per pose, or a\n * rounded copy of it (`roundedRow`, issue #1530), held by nothing but the row.\n * The core suite's `CO45` plants a scan that hands every pose the same array\n * and `CO59` a poser that does, and both read the retained frames red.\n */\nfunction scanDrawn(doc: CompiledDocument, shown: readonly ShownGeometry[], world: ReadonlyMap<string, CoreWorld>, order: readonly string[], plant: CorePlant, mode: WalkMode, scanPlant: ScanPlant = {}): ScanDrawn[] {\n const { rows } = drawnGeometry(doc, shown, world, order, plant, mode);\n const drawn: ScanDrawn[] = [];\n let k = 0;\n for (const s of shown) {\n const g = s.geometry;\n if (g.kind !== 'region' && g.kind !== 'mesh' && g.kind !== 'linkedmesh') continue;\n const row = rows[k++];\n if (row === undefined || row[0] !== s.slot) throw new CoreInputError(`slot \"${s.slot}\": the attachment rows are not in the shown records' order`);\n const vertices = row[3];\n const kept = mode.keep && allNumbers(vertices) ? vertices : vertices.map((v) => numberOf(v, `vertex of slot \"${s.slot}\"`, mode));\n drawn.push({ slot: s.slot, attachment: row[1], vertices: scanPlant.vertices === undefined ? kept : scanPlant.vertices(kept, s.slot) });\n }\n return drawn;\n}\n\n/**\n * A row's numbers as the pose hands them on (issue #1530): the row's own\n * array wherever it holds no `null` — `numberOf` is then the identity on\n * every one of them, under either mode — and mapped through `numberOf` as\n * before where it does, so a raw walk refuses the same value by the same\n * name and a kept one turns it into NaN. The row's array is the pose's own:\n * `poseGeometry` (`./vertices.ts`, `roundedRow`) hands each row the array\n * the poser just built or a fresh rounded copy of it, and `poseClipped` maps\n * every clipped row into a new array; nothing else holds one, so a frame a\n * consumer keeps is not written by the next pose. The core suite's\n * retained-frame control plants a poser that keeps one buffer per slot and\n * reads the kept frames red.\n */\nfunction numbersOf(values: Array<number | null>, what: string, mode: WalkMode): number[] {\n return allNumbers(values) ? values : values.map((v) => numberOf(v, what, mode));\n}\n\n/** Whether a row's vertices hold no `null` — what `numberOf` would map — so the row's own array can be handed on as numbers. */\nfunction allNumbers(values: Array<number | null>): values is number[] {\n for (const v of values) if (v === null) return false;\n return true;\n}\n\n/**\n * The scan's one plant (the core suite's `CO45`): what a drawn row's vertices\n * are handed on as, given the array the scan would hand on. A poser that\n * reuses one buffer per slot across steps is the plant `CO45` passes.\n * Nothing but a control passes one.\n */\nexport interface ScanPlant {\n vertices?: (vertices: number[], slot: string) => number[];\n}\n\n/** Every region and mesh the shown records draw, with what the renderer reads past the vertices (the header's `drawn`). */\nfunction rawDrawn(doc: CompiledDocument, shown: readonly ShownGeometry[], world: ReadonlyMap<string, CoreWorld>, order: readonly string[], plant: CorePlant, mode: WalkMode = RAW_MODE): { drawn: RawDrawn[]; clips: RawClip[]; clipped: RawClipped[] } {\n const stage = plant.stage;\n if (stage !== undefined) stage.begin('geometry');\n const geometry = drawnGeometry(doc, shown, world, order, plant, mode);\n if (stage !== undefined) {\n stage.end('geometry');\n stage.begin('readout');\n }\n // Under a concave or inverse clip the oracle's `clipped` block is absent (the runtime's own triangle list); what the core draws is `drawnClipped`,\n // its own decomposition, and the render samples each drawn triangle at its source triangle's affine UV, so the pixels are the decomposition's\n // coverage alone (issue #964, `Mesh.source` in src/render.ts).\n const rows = geometry.rows;\n const drawn: RawDrawn[] = [];\n // Each record's stated colour, read once per view (`viewColours`) and copied into the pose's own tuple, as the pose's arrays are its own.\n const stated = viewColours(doc);\n let k = 0;\n for (const s of shown) {\n const g = s.geometry;\n if (g.kind !== 'region' && g.kind !== 'mesh' && g.kind !== 'linkedmesh') continue;\n const row = rows[k++];\n if (row === undefined || row[0] !== s.slot) throw new CoreInputError(`slot \"${s.slot}\": the attachment rows are not in the shown records' order`);\n const record = doc.skins.find((x) => x.name === s.skin)?.attachments[s.slot]?.[s.placeholder];\n const read = record?.color === undefined ? WHITE : stated(record.color);\n const colour: [number, number, number, number] = [read[0], read[1], read[2], read[3]];\n let uvs: readonly number[];\n let triangles: readonly number[];\n let hull: number | null = null;\n if (g.kind === 'region') {\n uvs = REGION_UVS;\n triangles = REGION_TRIANGLES;\n } else {\n const source = g.kind === 'mesh' ? g : doc.skins.find((x) => x.name === g.skin)?.attachments[g.slot]?.[g.source]?.geometry;\n if (source === undefined || source.kind !== 'mesh') throw new CoreInputError(`slot \"${s.slot}\": the linked mesh's source carries no mesh`);\n ({ uvs, triangles } = (plant.meshArrays ?? meshArraysOf)(source));\n hull = source.hull ?? null;\n }\n const sequenceIndex = s.frame ?? record?.sequenceSetup ?? 0;\n drawn.push({ slot: s.slot, attachment: row[1], kind: row[2], vertices: numbersOf(row[3], `vertex of slot \"${s.slot}\"`, mode), uvs, triangles, hull, sequenceIndex, colour });\n }\n const clips = geometry.clips.map((c): RawClip => [c[0], c[1], c[2], numbersOf(c[3], `clip vertex of slot \"${c[0]}\"`, mode)]);\n const clipped = geometry.drawnClipped.map((c): RawClipped => [c[0], c[1], c[2], numbersOf(c[3], `clipped vertex of slot \"${c[0]}\"`, mode), numbersOf(c[4], `clipped uv of slot \"${c[0]}\"`, mode), c[5]]);\n if (stage !== undefined) stage.end('readout');\n return { drawn, clips, clipped };\n}\n\n/**\n * The setup pose as the renderer poses a skeleton with no animation — the\n * setup pose, every physics state reset — in full doubles. Refused by name\n * where the core leaves a block of it out.\n */\nexport function poseRawSetup(doc: CompiledDocument, plant: CorePlant = {}): RawPose {\n return setupPoseIn(doc, plant, RAW_MODE);\n}\n\n/** A value-driven reset pose, using the same dial override as the independent deform survey. */\nexport function poseRawDial(doc: CompiledDocument, override: DialOverride, slider: string, plant: CorePlant = {}): { pose: RawPose; read: number | null; applied: number } {\n const result = poseDial(doc, override, slider);\n const { world, shown } = result;\n const drawOrder = [...result.drawOrder];\n const drawn = rawDrawn(result.doc, shown, world, drawOrder, plant);\n return { read: result.read, applied: result.applied, pose: {\n trackTime: 0, animationTime: 0, bones: rawBones(result.doc, world), slots: [...result.slots], drawOrder,\n ...drawn, events: [], shown: [...shown],\n } };\n}\n\n/** A table key to read, with an optional skin-view override; omitted skin keeps the supplied view. */\nexport interface SetupMeshTarget {\n readonly slot: string;\n readonly attachment: string;\n /** A named skin (with default fallback), `all`, or `null` for no skin set. */\n readonly skin?: string | null;\n}\n\n/** A detached named mesh in setup world units, y up; hull counts vertices, not coordinates. */\nexport interface SetupMesh {\n slot: string;\n /** The requested attachment table key, even when the record states another display name. */\n attachment: string;\n /** The skin whose table supplied the requested record, including a fallback. */\n skin: string;\n vertices: number[];\n triangles: number[];\n hull: number | null;\n}\n\n/** Model definitions by value: object key order is irrelevant, array positions and signed zero are not. */\nfunction sameSetupMeshDefinition(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n if (Array.isArray(a) && Array.isArray(b) && a.length !== b.length) return false;\n const left = a as Record<string, unknown>;\n const right = b as Record<string, unknown>;\n const keys = Object.keys(left);\n return keys.length === Object.keys(right).length && keys.every((key) =>\n Object.prototype.hasOwnProperty.call(right, key) && sameSetupMeshDefinition(left[key], right[key]));\n}\n\n/**\n * Read a named mesh without changing the setup selection or playing anything\n * (issue #1538). Setup constraints and reset physics use the raw poser's own\n * path. A selected mesh includes its setup-slider deform; an unselected mesh\n * reads its stored geometry through those same matrices, with no hypothetical\n * attachment switch or deform. Linked meshes use their source topology and\n * bindings, and the queried slot's bone for unweighted vertices; `timelines`\n * affects only a selected mesh's setup-slider deform, as in `poseRawSetup`.\n *\n * Skin resolution is the supplied view's unless explicitly overridden. Under\n * `all`, differing definitions of the requested mesh are refused: the model\n * does not carry the file order that would choose one. Object property order\n * does not distinguish definitions; array positions and Object.is leaf values\n * do. Identical definitions keep the resolver's first supplying skin. All arrays are fresh.\n */\nexport function readSetupMesh(doc: CompiledDocument, target: SetupMeshTarget): SetupMesh {\n const view = target.skin === undefined ? doc : target.skin === null ? underNoSkin(doc) : underSkin(doc, target.skin);\n const where = `setup mesh slot ${JSON.stringify(target.slot)} attachment ${JSON.stringify(target.attachment)} under skin ${JSON.stringify(view.skin)}`;\n const slot = view.slots.find((s) => s.name === target.slot);\n if (slot === undefined) throw new CoreInputError(`${where}: no such slot`);\n const resolved = shownAttachment(view, slot, target.attachment);\n if (resolved === null) throw new CoreInputError(`${where}: no such attachment`);\n const fills = fillingSkins(view, slot.name, target.attachment);\n const definitions = fills.map((name) => view.skins.find((k) => k.name === name)?.attachments[slot.name]?.[target.attachment]);\n if ('conflict' in resolved || definitions.some((r) => !sameSetupMeshDefinition(r, definitions[0]))) {\n throw new CoreInputError(`${where}: skins [${fills.join(', ')}] fill this attachment differently; choose a named skin`);\n }\n const geometry = resolved.record.geometry;\n const mesh = geometry?.kind === 'linkedmesh'\n ? view.skins.find((s) => s.name === geometry.skin)?.attachments[geometry.slot]?.[geometry.source]?.geometry\n : geometry;\n if (mesh?.kind !== 'mesh') throw new CoreInputError(`${where}: ${resolved.record.kind} is not a mesh`);\n const { world, shown, drawOrder } = setupPosed(view, {}, RAW_MODE);\n const selected = shown.find((s) => s.slot === slot.name && s.placeholder === target.attachment && s.skin === resolved.skin);\n const bone = world.get(slot.bone);\n if (bone === undefined) throw new CoreInputError(`${where}: no setup transform for bone ${JSON.stringify(slot.bone)}`);\n const vertices = selected === undefined\n ? numbersOf(worldVertices(mesh.vertices, bone, world).map(rawNumber), `${where} vertex`, RAW_MODE)\n : rawDrawn(view, [selected], world, drawOrder, {}).drawn[0].vertices;\n return { slot: slot.name, attachment: target.attachment, skin: resolved.skin, vertices: [...vertices], triangles: [...mesh.triangles], hull: mesh.hull ?? null };\n}\n\n/** `poseRawSetup` in `mode` — under `keep`, a value that is not finite stays in the pose (`./walk.ts`). */\nexport function setupPoseIn(doc: CompiledDocument, plant: CorePlant, mode: WalkMode): RawPose {\n const { world, shown, slots, drawOrder } = setupPosed(doc, plant, mode);\n const drawn = rawDrawn(doc, shown, world, drawOrder, plant, mode);\n return { trackTime: 0, animationTime: 0, bones: rawBones(doc, world), slots, drawOrder, ...drawn, events: [], shown: drawOrderOf(shown, drawOrder) };\n}\n\n/** `setupPoseIn` as the scan reads it (`ScanPose`): the same setup pose, the same refusals in the same order, assembled into the scan's pose. */\nexport function scanSetupIn(doc: CompiledDocument, plant: CorePlant, mode: WalkMode, scanPlant: ScanPlant = {}): ScanPose {\n const { world, shown, slots, drawOrder } = setupPosed(doc, plant, mode);\n const drawn = scanDrawn(doc, shown, world, drawOrder, plant, mode, scanPlant);\n return { animationTime: 0, bones: scanBones(doc, world), slots, drawn };\n}\n\n/** The setup pose `setupPoseIn` and `scanSetupIn` assemble, refused by name where the core leaves a block of it out. */\nfunction setupPosed(doc: CompiledDocument, plant: CorePlant, mode: WalkMode): { world: Map<string, CoreWorld>; shown: ShownGeometry[]; slots: CoreSlotRow[]; drawOrder: string[] } {\n const posed = poseSetup(doc, { ...plant, ...roundPlant(mode) }, freshStepContext(plant.physicsStep));\n // `setup.clipped` is the oracle's block, left out under a concave or inverse clip whose triangle list is the runtime's own; what the core draws there is `rawDrawn`'s to refuse or pose (issue #964).\n const absent = posed.absent.filter(([block]) => block !== 'setup.clipped');\n if (absent.length > 0) throw new CoreInputError(`the raw setup pose leaves ${absent.map(([b, why]) => `${b} out (${why})`).join('; ')}`);\n const { setup, world, shown } = posed;\n if (world === null || shown === null || setup.slots === null || setup.drawOrder === null) throw new CoreInputError('the raw setup pose was not posed');\n return { world, shown, slots: setup.slots, drawOrder: setup.drawOrder };\n}\n\n/**\n * One animation walked at the caller's steps (the header's *One step*): the\n * reset pose at 0, then one pose per step of `steps` — `steps.length + 1`\n * poses in all. `src/render.ts`'s walk is `count` steps of `1/fps`;\n * `src/deformmeasure.ts`'s is one step of `time`. A step must be a finite\n * time at or above 0; the animation must be the document's; a construct the\n * core would leave out refuses the call by name. `reset` is where the\n * physics is reset (`RawReset`): `animation` for render's walk, `setup` for\n * deformmeasure's one jump.\n */\nexport function poseRawAnimation(doc: CompiledDocument, animation: string, steps: readonly number[], plant: TimelinePlant = {}, reset: RawReset = 'animation'): RawPose[] {\n return walkIn(doc, animation, steps, plant, reset, RAW_MODE);\n}\n\n/**\n * `poseRawAnimation`, each pose handed to `visit` as it is posed rather than\n * collected (issue #1180): the same walk, the same poses in the same order,\n * and the caller holds as many of them as it keeps. `src/render_core.ts`\n * draws each and lets it go, so a render holds one pose and not an\n * animation's series — on the production rig the core poser's render peaked\n * highest on, the largest animation's series was 153 MiB of retained heap.\n * A refusal is thrown from the pose it is met at, after `visit` has seen the\n * poses before it. `clock`, when given, is what each step moves the physics\n * clock by in place of the step itself — the render's offline schedule\n * (`physicsClockStep` below, issue #1380); the track time and\n * the animation time are the steps' running sum either way.\n */\nexport function poseRawAnimationEach(doc: CompiledDocument, animation: string, steps: readonly number[], plant: TimelinePlant, reset: RawReset, visit: (pose: RawPose, index: number) => void, clock?: (dt: number) => number, environment?: StepEnvironment): void {\n walkEach(doc, animation, steps, plant, reset, clock === undefined ? RAW_MODE : { ...RAW_MODE, clock: (dt) => clock(dt) }, RAW_SHAPE, visit, environment);\n}\n\n/**\n * The live track's looping mode (`./track.ts`, issue #1276) as a batch walk's:\n * the animation time the track time wrapped by the duration, `reset` keys\n * fired across the wrap, the clipped rows cut as the raw entry cuts them, and\n * no value that is not finite kept.\n */\nconst RAW_LOOPED_MODE: WalkMode = { loop: true, keep: false, live: true };\n\n/**\n * `poseRawAnimationEach` on a looping track (issue #1684): the same walk in the\n * live track's looping mode (`RAW_LOOPED_MODE`) — the walk `render --preroll`\n * takes, which carries the physics across every wrap as a player's looping\n * track does. Not part of the entry's promised surface: `src/render_core.ts`\n * is its one caller, and spine-core's poser takes the same walk through\n * `setAnimation(0, name, true)`.\n */\nexport function poseRawLoopEach(doc: CompiledDocument, animation: string, steps: readonly number[], plant: TimelinePlant, reset: RawReset, visit: (pose: RawPose, index: number) => void, clock?: (dt: number) => number, environment?: StepEnvironment): void {\n walkEach(doc, animation, steps, plant, reset, clock === undefined ? RAW_LOOPED_MODE : { ...RAW_LOOPED_MODE, clock: (dt) => clock(dt) }, RAW_SHAPE, visit, environment);\n}\n\n/**\n * What a batch walk sets on its physics before a pose (issue #1416, part C):\n * pose `index`'s change to the world every physics constraint answers — either\n * half, merged over the one standing as a live track's `setEnvironment` merges\n * it (`setEnvironmentOn`) — or `undefined` for none. Pose 0 is the reset pose;\n * pose `k + 1` is the one step `k` makes. `rigc render --environment` is the\n * caller (`src/render_core.ts`), and spine-core's poser sets the same values on\n * its `Skeleton` before the same update (`src/render.ts`), so the two posers\n * see one world at every step.\n */\nexport type StepEnvironment = (index: number) => Partial<PhysicsEnvironment> | undefined;\n\n/** `environment`'s change for pose `index`, set on `ctx` as a live track sets one — validated and merged by `setEnvironmentOn`. */\nfunction setStepEnvironment(ctx: PhysicsStepContext, environment: StepEnvironment | undefined, index: number): void {\n const change = environment?.(index);\n if (change !== undefined) setEnvironmentOn(ctx, change, `the walk's, at pose ${index},`);\n}\n\n/**\n * How much faster than the frames a render's physics clock runs — and, since issue\n * #1389, a mesh comparison's (`src/meshcompare.ts`, `comparisonWalk`): each frame\n * moves the skeleton's clock — the time a physics constraint integrates — by\n * `physicsClockStep(1 / fps)`, the frame's step and `2⁻³⁰` of it more, while\n * the animation is applied at the running sum of the frame steps as before\n * (issue #1380).\n *\n * ⭐ **Why a render's physics clock is not the frame clock.** A physics\n * constraint keeps the time it has not yet integrated (`remaining`), takes\n * whole steps of `1 / fps` (its own `fps`, 60 by default) while at least one\n * step remains, and shows `offset − lag·(1 − remaining / step)`, `lag` being\n * everything this update's steps moved (`src/core/constraints_physics.ts`,\n * *The step*). Whenever a frame lasts a whole number of physics steps — 12,\n * 20, 30 and 60 fps against 60 Hz, and every second frame at 24 — the time\n * left at the frame's end is zero in exact arithmetic, and in doubles it is\n * either a few ulps above zero or a few ulps short of one whole step. Which of\n * the two is decided by rounding, not by the motion: the shown weight is 1 or\n * 0, so the spring is drawn one frame late or on time, and it changes regime\n * on a single frame. Measured on the public trailer (`show`, 20 fps, 321\n * frames): every spring jumps at frames 5, 12, 45 and 188 — the four frames\n * that arithmetic alone predicts — and the loop's start (frame 80, on time)\n * and end (frame 320, a frame late, which is what exact arithmetic draws)\n * differ by 31.70 units of vertex and 10.37 of bone\n * while every keyed bone agrees to 1.3e-12. spine-core 4.3.13 stepped the\n * same way draws the same frames to the bit: this is the runtime under a\n * fixed offline step, not a defect of the core's port, which is why the fix\n * is the render's schedule and the physics is untouched.\n *\n * Running the clock `2⁻³⁰` fast puts the time left a little ABOVE every\n * whole number of steps instead of on it, by `2⁻³⁰ · t` after `t` seconds:\n * 1.5e-8 s at 16 s, against a rounding error of at most a few ulps of the\n * clock (3.6e-15 s at 16 s) — so every tie resolves the way exact arithmetic\n * resolves it, a step taken, and the shown weight sits at 1 − 9e-7 rather\n * than flipping. It stays below the smallest gap a step boundary can fall\n * into for 7.8e5 s even at 23 fps against 60 Hz (a gap of 1/1380 s), and a\n * physics `reset` key, which restarts the time left from zero, is resolved\n * the same way on every frame after it, because the lead is taken on every\n * frame rather than once (read off the clock arithmetic with a reset at frame\n * 100, 16 s at the five rates: no tie; no tree probe keys a reset under the\n * render's clock). A pose stays a function of its frame\n * index alone: the lead does not depend on how many frames are asked for.\n *\n * Rejected, measured over the same arithmetic (16 s at 12, 20, 24, 25, 30 and\n * 60 fps): the clock as `i / fps` rather than a running sum (90 frames still\n * flipped at 20 fps); a one-time lead of half a step (114 flipped at 24 fps,\n * where half a step lands on the other tie); a one-time lead of any size,\n * which a `reset` key cancels; and snapping `remaining` inside the physics,\n * which changes the runtime's physics rather than the render's schedule and\n * which spine-core's poser could not follow.\n */\nexport const PHYSICS_CLOCK_LEAD = 2 ** -30;\n\n/** What one frame of `step` seconds moves a render's physics clock by — `PHYSICS_CLOCK_LEAD`; both render posers and the mesh comparison step with it. */\nexport function physicsClockStep(step: number): number {\n return step + step * PHYSICS_CLOCK_LEAD;\n}\n\n/**\n * A live track's `clock` option (issue #1396, `./track.ts` and `./tracks.ts`):\n * the caller's function, called with each step, its answer checked before the\n * skeleton's clock moves by it — a finite time at or above 0, or the step\n * refused by name, as a step itself is. `who` names the track in the refusal.\n */\nexport function checkedClock(clock: (dt: number) => number, who: string): (dt: number) => number {\n return (dt) => {\n const moved = clock(dt);\n if (typeof moved !== 'number' || !Number.isFinite(moved) || moved < 0) throw new CoreInputError(`${who} clock moved the physics by ${String(moved)} for a step of ${dt}, not a finite time at or above 0`);\n return moved;\n };\n}\n\n/**\n * A live track's `setEnvironment` (issue #1416, `./track.ts` and `./tracks.ts`):\n * the world every physics constraint answers from the next pose on, set on the\n * track's physics context — `wind` and `gravity` each a pair of finite numbers,\n * either left out to keep the one that stands, and nothing else — or refused by\n * name, before anything moves. The pair is copied: the caller's array changed\n * later moves nothing.\n */\nexport function setEnvironmentOn(ctx: PhysicsStepContext, env: unknown, who: string): void {\n if (typeof env !== 'object' || env === null || Array.isArray(env)) throw new CoreInputError(`${who} setEnvironment was given ${env === null ? 'null' : Array.isArray(env) ? 'an array' : typeof env}, not an object { wind?: [x, y], gravity?: [x, y] }`);\n const given = env as Record<string, unknown>;\n for (const key of Object.keys(given)) {\n if (key !== 'wind' && key !== 'gravity') throw new CoreInputError(`${who} setEnvironment names \"${key}\", which is not one of [wind, gravity]`);\n }\n const pair = (key: 'wind' | 'gravity'): readonly [number, number] | undefined => {\n const v = given[key];\n if (v === undefined) return undefined;\n if (!Array.isArray(v) || v.length !== 2 || v.some((n) => typeof n !== 'number' || !Number.isFinite(n))) throw new CoreInputError(`${who} setEnvironment's ${key} is ${JSON.stringify(v)}, not a pair of finite numbers [x, y] (x to the right, y down)`);\n return Object.freeze([v[0] as number, v[1] as number] as const);\n };\n const wind = pair('wind');\n const gravity = pair('gravity');\n const standing = ctx.env ?? DEFAULT_PHYSICS_ENVIRONMENT;\n ctx.env = Object.freeze({ wind: wind ?? standing.wind, gravity: gravity ?? standing.gravity });\n}\n\n/** The environment a live track's physics answers now (`setEnvironmentOn`): spine-core's initial one where none was set. */\nexport function environmentOf(ctx: PhysicsStepContext): PhysicsEnvironment {\n return ctx.env ?? DEFAULT_PHYSICS_ENVIRONMENT;\n}\n\n/** Validate the complete explicit selection before any remembered state changes. */\nexport function checkedPhysicsScope(doc: CompiledDocument, scope: readonly string[] | undefined, who: string): ReadonlySet<string> | undefined {\n if (scope === undefined) return undefined;\n if (!Array.isArray(scope)) throw new CoreInputError(`${who} physics movement scope is ${String(scope)}, not an array of physics constraint names`);\n const selected = new Set<string>();\n for (const name of scope) {\n if (typeof name !== 'string') throw new CoreInputError(`${who} physics movement scope name ${String(name)} is not a string`);\n const constraint = doc.constraints.find((c) => c.kind === 'physics' && c.name === name)\n ?? doc.constraints.find((c) => c.name === name);\n if (constraint === undefined) throw new CoreInputError(`${who} physics movement scope: no constraint \"${name}\"; this document declares [${doc.constraints.map((c) => c.name).join(', ')}]`);\n if (constraint.kind !== 'physics') throw new CoreInputError(`${who} physics movement scope: constraint \"${name}\" is ${constraint.kind}, not physics`);\n selected.add(name);\n }\n return selected;\n}\n\n/** A live track's `physicsTranslate` (issue #1416): `x` and `y` finite, or refused by name before anything moves; then `translatePhysics`. */\nexport function translateOn(ctx: PhysicsStepContext, x: number, y: number, who: string, scope?: ReadonlySet<string>): void {\n for (const [k, v] of [['x', x], ['y', y]] as const) {\n if (typeof v !== 'number' || !Number.isFinite(v)) throw new CoreInputError(`${who} physicsTranslate's ${k} is ${String(v)}, not a finite distance in the skeleton's world`);\n }\n translatePhysics(ctx, x, y, scope);\n}\n\n/** A live track's `physicsRotate` (issue #1416): `x`, `y` and `degrees` finite, or refused by name before anything moves; then `rotatePhysics`. */\nexport function rotateOn(ctx: PhysicsStepContext, x: number, y: number, degrees: number, who: string, scope?: ReadonlySet<string>): void {\n for (const [k, v] of [['x', x], ['y', y], ['degrees', degrees]] as const) {\n if (typeof v !== 'number' || !Number.isFinite(v)) throw new CoreInputError(`${who} physicsRotate's ${k} is ${String(v)}, not a finite number`);\n }\n rotatePhysics(ctx, x, y, degrees, scope);\n}\n\n/**\n * The animation time a looping track applies its animation at (`./walk.ts`,\n * *The time*): the track time wrapped by the duration, and 0 over a duration\n * of 0.\n */\nexport function loopedTime(trackTime: number, duration: number): number {\n return duration === 0 ? 0 : trackTime % duration;\n}\n\n/**\n * `poseRawAnimation` in `mode`: the raw entry's walk, or the looping walk\n * `./walk.ts` documents — the animation time the track time wrapped by the\n * duration, every value kept whatever it is. Each difference is a branch on\n * `mode` here, so the raw entry's walk is the one it was.\n */\nexport function walkIn(doc: CompiledDocument, animation: string, steps: readonly number[], plant: TimelinePlant, reset: RawReset, mode: WalkMode): RawPose[] {\n const poses: RawPose[] = [];\n walkEach(doc, animation, steps, plant, reset, mode, RAW_SHAPE, (pose) => poses.push(pose));\n return poses;\n}\n\n/**\n * `walkIn` as the scan reads it (`ScanPose`, issue #1179, the second part):\n * the same walk — every pose posed by the same operations in the same order,\n * every refusal at the same place — each pose assembled into what A10 reads.\n * `./walk.ts`'s `scanLoopingWalk` is its one caller.\n */\nexport function scanWalkIn(doc: CompiledDocument, animation: string, steps: readonly number[], plant: TimelinePlant, reset: RawReset, mode: WalkMode, scanPlant: ScanPlant = {}): ScanPose[] {\n const poses: ScanPose[] = [];\n walkEach(doc, animation, steps, plant, reset, mode, scanPlant.vertices === undefined ? SCAN_SHAPE : scanShape(scanPlant), (pose) => poses.push(pose));\n return poses;\n}\n\n/** What one step of a walk posed, before a pose is assembled from it (`PoseShape`). */\ninterface WalkStep {\n trackTime: number;\n animationTime: number;\n world: Map<string, CoreWorld>;\n slots: CoreSlotRow[];\n drawOrder: string[];\n shown: ShownGeometry[];\n /** The events the step fired, computed when called — after the drawn rows, as the raw entry has always ordered its refusals. */\n events: () => RawEvent[];\n}\n\n/**\n * What a walk assembles each pose into (issue #1179, the second part): the raw\n * entry's whole pose (`RAW_SHAPE`), or the scan's (`SCAN_SHAPE`). The walk\n * (`walkEach`) is one body: every number a pose carries is computed there and\n * in the two assemblers below, by the same calls, whatever the shape. A shape\n * chooses only what is assembled from what was posed — the scan drops the\n * readings and copies nothing it reads is computed from — and keeps the\n * order of every call that can refuse.\n *\n * No shape forms the oracle's bone rows: no walk pose carries them, and the\n * rounding they are formed through refuses nothing, so every step poses the\n * world alone (`posedBoneWorldAlone`). The rows are the sample's\n * (`posedBoneRows`, `posedBoneWorld`), formed there as before. The core\n * suite's `CO62` reads the walk's modules for a call that forms them.\n */\ninterface PoseShape<P> {\n /** The reset pose at the setup (`reset: 'setup'`). */\n setup: (doc: CompiledDocument, world: Map<string, CoreWorld>, slots: CoreSlotRow[], drawOrder: string[], shown: ShownGeometry[], plant: CorePlant, mode: WalkMode) => P;\n /** One step's pose. */\n step: (doc: CompiledDocument, posed: WalkStep, plant: CorePlant, mode: WalkMode) => P;\n}\n\n/** The raw entry's pose, assembled as it always was: at the reset the bones, then the drawn rows; at a step the drawn rows, the events, then the bones. */\nconst RAW_SHAPE: PoseShape<RawPose> = {\n setup: (doc, world, slots, drawOrder, shown, plant, mode) => ({ trackTime: 0, animationTime: 0, bones: rawBones(doc, world), slots, drawOrder, ...rawDrawn(doc, shown, world, drawOrder, plant, mode), events: [], shown: drawOrderOf(shown, drawOrder) }),\n step: (doc, p, plant, mode) => {\n const drawn = rawDrawn(doc, p.shown, p.world, p.drawOrder, plant, mode);\n const stage = plant.stage;\n if (stage !== undefined) stage.begin('readout');\n const events = p.events();\n const pose: RawPose = { trackTime: p.trackTime, animationTime: p.animationTime, bones: rawBones(doc, p.world), slots: p.slots, drawOrder: p.drawOrder, ...drawn, events, shown: p.shown };\n if (stage !== undefined) stage.end('readout');\n return pose;\n },\n};\n\n/** The scan's pose (`ScanPose`), in the raw shape's order: the scan's walk is a looping one, which fires no event. */\nfunction scanShape(scanPlant: ScanPlant): PoseShape<ScanPose> {\n return {\n setup: (doc, world, slots, drawOrder, shown, plant, mode) => {\n const bones = scanBones(doc, world);\n return { animationTime: 0, bones, slots, drawn: scanDrawn(doc, shown, world, drawOrder, plant, mode, scanPlant) };\n },\n step: (doc, p, plant, mode) => {\n const drawn = scanDrawn(doc, p.shown, p.world, p.drawOrder, plant, mode, scanPlant);\n return { animationTime: p.animationTime, bones: scanBones(doc, p.world), slots: p.slots, drawn };\n },\n };\n}\nconst SCAN_SHAPE: PoseShape<ScanPose> = scanShape({});\n\n/**\n * A walk between two of its steps (issue #1276): everything `walkEach` carries\n * from one step to the next, held in one object, so the walk can be stepped one\n * `dt` at a time (`openTrack` in `./track.ts`) as well as over a list. That is\n * the physics context (`ctx`: the skeleton's clock, the phase, each physics\n * constraint's state, the animation time a `reset` key is crossed from, whether\n * the track loops), the running track time, the animation time of the step\n * before (−1 before the first) and what the walk was opened with. Nothing else\n * survives a step: every pose is posed from the setup pose at its time.\n */\nexport interface TrackState<P> {\n readonly doc: CompiledDocument;\n readonly anim: CompiledDocument['animations'][number];\n /** The runtime's duration (`CoreAnimationTimelines.duration`). */\n readonly duration: number;\n readonly mode: WalkMode;\n readonly plant: TimelinePlant;\n /** `plant` with the mode's rounding (`roundPlant`). */\n readonly raw: TimelinePlant;\n readonly resolve: NonNullable<TimelinePlant['shown']>;\n readonly shape: PoseShape<P>;\n readonly ctx: ReturnType<typeof freshStepContext>;\n /** The caller's adjustment of each step's locals (`LocalAdjust` in `./animation.ts`): the live track's `adjust`, absent on every batch walk. */\n readonly adjust?: LocalAdjust;\n /** The running sum of the steps taken. */\n trackTime: number;\n /** The animation time of the step before, −1 before the first. */\n last: number;\n}\n\n/** The document's animation named `animation`, or the walk refused naming the document's animations. */\nfunction animationOf(doc: CompiledDocument, animation: string): CompiledDocument['animations'][number] {\n const anim = doc.animations.find((a) => a.name === animation);\n if (anim === undefined) throw new CoreInputError(`animation \"${animation}\" is not one of this document's [${doc.animations.map((a) => a.name).join(', ')}]`);\n return anim;\n}\n\n/**\n * A walk opened (issue #1276): the refusals a walk makes before its first pose,\n * then pose 0 — the reset — and the state the walk steps on from. Under\n * `reset: 'setup'` pose 0 is the setup pose, reset; under `animation` it is the\n * animation applied at 0 and reset there, a step of 0 (`stepWalk`'s `first`).\n */\nfunction openWalk<P>(doc: CompiledDocument, anim: CompiledDocument['animations'][number], plant: TimelinePlant, reset: RawReset, mode: WalkMode, shape: PoseShape<P>, adjust?: LocalAdjust, before?: (ctx: PhysicsStepContext) => void): { track: TrackState<P>; first: P } {\n const why = constraintsAbsentWhy(doc) ?? pathAnimationsWhy(doc) ?? steppedPreviousPassWhy(doc);\n if (why !== null) throw new CoreInputError(`the raw walk leaves the bones out: ${why}`);\n const ctx = freshStepContext(plant.physicsStep);\n // What the caller sets before pose 0 (issue #1416, part C): the batch walk's environment for the reset pose.\n before?.(ctx);\n if (mode.loop && mode.wrapResets !== false) ctx.loop = true;\n const track: TrackState<P> = { doc, anim, duration: anim.timelines.duration, mode, plant, raw: { ...plant, ...roundPlant(mode) }, resolve: plant.shown ?? shownAttachment, shape, ctx, adjust, trackTime: 0, last: -1 };\n if (reset === 'setup') {\n // The reset taken at the setup pose, before the animation is applied (`src/deformmeasure.ts`'s `poseAt`): pose 0 is the setup pose.\n const setup = poseSetup(doc, { ...plant, ...roundPlant(mode) }, ctx);\n const absent = setup.absent.filter(([block]) => block !== 'setup.clipped');\n if (absent.length > 0) throw new CoreInputError(`the raw walk's reset pose leaves ${absent.map(([b, w]) => `${b} out (${w})`).join('; ')}`);\n if (setup.world === null || setup.shown === null || setup.setup.slots === null || setup.setup.drawOrder === null) throw new CoreInputError('the raw walk\\'s reset pose was not posed');\n ctx.phase = 'update';\n return { track, first: shape.setup(doc, setup.world, setup.setup.slots, setup.setup.drawOrder, setup.shown, plant, mode) };\n }\n return { track, first: stepWalk(track, 0, true) };\n}\n\n/**\n * One step of a walk (the header's *One step*): the track time moved by `dt`,\n * the animation applied at the mode's time from the setup pose, the physics\n * clock moved by the step, and the pose assembled in the track's shape.\n * `first` is the reset pose under `reset: 'animation'` — a step of 0 that\n * resets the physics there — and nothing else passes it.\n */\nfunction stepWalk<P>(track: TrackState<P>, dt: number, first = false): P {\n const { doc, anim, duration, mode, plant, raw, resolve, shape, ctx, adjust } = track;\n track.trackTime += dt;\n const trackTime = track.trackTime;\n const last = track.last;\n const t = mode.loop ? (mode.time ?? loopedTime)(trackTime, duration, trackTime - dt) : trackTime < duration ? trackTime : duration;\n const before = ctx.time;\n ctx.time += mode.clock === undefined ? dt : mode.clock(dt, t - (first ? 0 : Math.max(last, 0)));\n // A10's looping walk fires no event here — its one reader reads none — nor cuts its drawn attachments through a clip (`NO_CLIPPED_ROWS`), so its\n // `clipped` rows are empty. The live track's looping mode (`live`) fires its events across the wrap by the rule `./track.ts` states as measured.\n const fire = plant.events ?? eventsFired;\n const keys = anim.timelines.events;\n const adjustment = adjust === undefined ? undefined : { callback: adjust, context: { trackTime, animation: anim.name, globalTime: trackTime } };\n const pose = poseStepFrom(doc, plant, resolve, shape, mode, ctx, first, trackTime, t, {\n world: (sliders) => posedBoneWorldAlone(doc, anim.timelines, t, raw, anim.constraints, sliders, { ctx, before, adjustment }),\n slots: (sliders, placeholders) => posedSlots(doc, anim.timelines, t, raw, sliders, placeholders),\n drawOrder: anim.timelines.drawOrder,\n at: t,\n sample: { timelines: anim.timelines, t },\n events: () => (mode.loop && mode.live !== true ? [] : mode.loop ? fire(keys, last, t, rawNumber, t < last) : fire(keys, last, t, rawNumber)),\n });\n track.last = t;\n return pose;\n}\n\n/**\n * What decides one step's pose before it is assembled (issue #1336): the bone\n * world through the stepped phase, filling the sliders it applied; the slot\n * rows, filling the placeholders the timelines left; the draw-order keys and\n * the time they are read at; the deform and sequence timelines' sample, or the\n * mixed deforms in its place; the events, computed when called. A walk's step\n * reads every one off one animation at its time (`stepWalk`); the live tracks\n * off their mixed entries (`./tracks.ts`). Everything past these is one body,\n * `poseStepFrom`.\n */\nexport interface StepPosers {\n world: (sliders: SliderApplication[]) => Map<string, CoreWorld>;\n slots: (sliders: readonly SliderApplication[], placeholders: Map<string, string | null>) => { rows: CoreSlotRow[]; conflicts: string[] };\n drawOrder: readonly CoreDrawOrderKey[];\n at: number;\n sample: { timelines: CoreAnimationTimelines; t: number } | null;\n mixed?: ReadonlyMap<string, { deform: number[] | null; seen: readonly string[] }>;\n events: () => CoreEventRow[];\n}\n\n/**\n * One step's pose from what decided it (`StepPosers`): the bone world, the\n * physics phase moved past the reset on `first`, the slot rows, the draw\n * order (the keys' order, else the setup's, then each slider's key), the\n * attachments drawn in it, and the pose assembled in `shape` — refused by name\n * where the core leaves a block out, in that order. The one body a walk's step\n * and a live tracks' step share.\n */\nfunction poseStepFrom<P>(doc: CompiledDocument, plant: TimelinePlant, resolve: NonNullable<TimelinePlant['shown']>, shape: PoseShape<P>, mode: WalkMode, ctx: ReturnType<typeof freshStepContext>, first: boolean, trackTime: number, animationTime: number, posers: StepPosers): P {\n const stage = plant.stage;\n const sliders: SliderApplication[] = [];\n const world = posers.world(sliders);\n if (first) ctx.phase = 'update';\n if (stage !== undefined) stage.begin('readout');\n const placeholders = new Map<string, string | null>();\n const slots = posers.slots(sliders, placeholders);\n if (slots.conflicts.length > 0) throw new CoreInputError(`the raw walk leaves the slots out: ${slots.conflicts.join('; ')}`);\n const evalOrder = plant.drawOrder ?? drawOrderAt;\n const baseOrder = evalOrder(doc.slots.length, posers.drawOrder, posers.at) ?? doc.slots.map((_s, k) => k);\n let order = baseOrder;\n for (const app of sliders) order = evalOrder(doc.slots.length, app.timelines.drawOrder, app.at) ?? order;\n const drawOrder = order.map((k) => doc.slots[k].name);\n if (stage !== undefined) {\n stage.end('readout');\n stage.begin('timeline');\n }\n const states = attachmentStates(doc, resolve, placeholders, posers.sample, sliders, plant, posers.mixed);\n if (stage !== undefined) stage.end('timeline');\n if (states.why.length > 0) throw new CoreInputError(`the raw walk leaves the attachments out: ${states.why.join('; ')}`);\n if (stage !== undefined) stage.begin('readout');\n const rank = new Map(drawOrder.map((n, r) => [n, r]));\n const shown = [...states.shown].sort((a, b) => (rank.get(a.slot) ?? 0) - (rank.get(b.slot) ?? 0));\n if (stage !== undefined) stage.end('readout');\n const events = (): RawEvent[] => posers.events().map((e): RawEvent => [e[0], finite(e[1], 'event time'), e[2], finite(e[3], 'event float'), e[4]]);\n return shape.step(doc, { trackTime, animationTime, world, slots: slots.rows, drawOrder, shown, events }, plant, mode);\n}\n\n/**\n * The live tracks' side of the raw pose path (issue #1336, `./tracks.ts`):\n * the refusals a walk makes before its first pose, a fresh physics context,\n * the plant with the raw entry's rounding, and the two ways a pose is made —\n * the setup pose reset (`reset: 'setup'`'s pose 0) and one step from what the\n * mixed entries decided, assembled as the raw entry's pose (`RAW_SHAPE`,\n * `RAW_MODE`: a non-finite value refused, every clipped row cut).\n */\nexport interface RawTracksPath {\n readonly ctx: ReturnType<typeof freshStepContext>;\n /** `plant` with the raw entry's rounding. */\n readonly raw: TimelinePlant;\n setupPose(): RawPose;\n step(first: boolean, trackTime: number, animationTime: number, posers: StepPosers): RawPose;\n}\n\n/** `RawTracksPath` opened on `doc`, refused by name where a walk on it would be (`openWalk`). */\nexport function openRawTracksPath(doc: CompiledDocument, plant: TimelinePlant): RawTracksPath {\n const why = constraintsAbsentWhy(doc) ?? pathAnimationsWhy(doc) ?? steppedPreviousPassWhy(doc);\n if (why !== null) throw new CoreInputError(`the raw walk leaves the bones out: ${why}`);\n const ctx = freshStepContext(plant.physicsStep);\n const raw: TimelinePlant = { ...plant, ...roundPlant(RAW_MODE) };\n const resolve = plant.shown ?? shownAttachment;\n return {\n ctx,\n raw,\n setupPose: () => {\n const setup = poseSetup(doc, raw, ctx);\n const absent = setup.absent.filter(([block]) => block !== 'setup.clipped');\n if (absent.length > 0) throw new CoreInputError(`the raw walk's reset pose leaves ${absent.map(([b, w]) => `${b} out (${w})`).join('; ')}`);\n if (setup.world === null || setup.shown === null || setup.setup.slots === null || setup.setup.drawOrder === null) throw new CoreInputError('the raw walk\\'s reset pose was not posed');\n ctx.phase = 'update';\n return RAW_SHAPE.setup(doc, setup.world, setup.setup.slots, setup.setup.drawOrder, setup.shown, plant, RAW_MODE);\n },\n step: (first, trackTime, animationTime, posers) => poseStepFrom(doc, plant, resolve, RAW_SHAPE, RAW_MODE, ctx, first, trackTime, animationTime, posers),\n };\n}\n\n/** `walkIn`'s walk, each pose assembled in `shape` and handed to `visit` in order as it is posed (`poseRawAnimationEach`): the walk opened, then stepped over `steps`. */\nfunction walkEach<P>(doc: CompiledDocument, animation: string, steps: readonly number[], plant: TimelinePlant, reset: RawReset, mode: WalkMode, shape: PoseShape<P>, visit: (pose: P, index: number) => void, environment?: StepEnvironment): void {\n const anim = animationOf(doc, animation);\n const bad = steps.findIndex((s) => !Number.isFinite(s) || s < 0);\n if (bad >= 0) throw new CoreInputError(`step ${bad} is ${steps[bad]}, not a finite time at or above 0`);\n const { track, first } = openWalk(doc, anim, plant, reset, mode, shape, undefined, environment === undefined ? undefined : (ctx) => setStepEnvironment(ctx, environment, 0));\n let visited = 0;\n visit(first, visited++);\n for (const dt of steps) {\n setStepEnvironment(track.ctx, environment, visited);\n visit(stepWalk(track, dt), visited++);\n }\n}\n\n/**\n * The raw entry's walk opened for stepping one `dt` at a time (issue #1276,\n * `openTrack` in `./track.ts`): the same refusals in the same order as\n * `walkIn`'s past the step list, pose 0 as `walkIn` poses it, and the state\n * `stepRawTrack` steps. Every pose is assembled as the raw entry's\n * (`RAW_SHAPE`).\n */\nexport function openRawTrack(doc: CompiledDocument, animation: string, plant: TimelinePlant, reset: RawReset, mode: WalkMode, adjust?: LocalAdjust, before?: (ctx: PhysicsStepContext) => void): { track: TrackState<RawPose>; first: RawPose } {\n return openWalk(doc, animationOf(doc, animation), plant, reset, mode, RAW_SHAPE, adjust, before);\n}\n\n/** One step of an opened raw track (`openRawTrack`): `walkIn`'s step, the step itself checked by the caller. */\nexport function stepRawTrack(track: TrackState<RawPose>, dt: number): RawPose {\n return stepWalk(track, dt);\n}\n\n// --- #907 the setup-pose bounding box: begin ---\n/**\n * The setup-pose bounding box (issue #907) — `setupBounds` below: the axis-aligned box around every\n * region and mesh a skeleton draws at its setup pose, as spine-core's\n * `Skeleton.getBounds(offset, size, temp)` returns it on a fresh skeleton —\n * no skin set, `updateWorldTransform(Physics.none)` — which is what the Spine\n * format says the header's `x`, `y`, `width` and `height` are.\n *\n * Every rule below was measured by running spine-core 4.3.13 through the\n * tree's own loader, not read off its source:\n *\n * - **The view is \"no skin set\"** (`underNoSkin`, issue #1051): a skeleton\n * `build` writes is loaded and bounded before anyone calls `setSkin`, so\n * the slots resolve through the default skin alone and no skin's bones or\n * constraint lists apply.\n * - **Constraints applied.** The box is of the pose `updateWorldTransform`\n * leaves, every ik, transform, path and slider constraint applied in the\n * document's order — the pose `poseSetup` computes. The editor's own\n * header is of that pose too: on `examples/spineboy/export/spineboy-pro.json`\n * (seven ik and seven transform constraints) `getBounds` with the\n * constraints applied is within 0.0035 of the header the editor wrote, and\n * with them stripped it is 0.31 off in `y` and `height`.\n * - **Physics.none.** A physics constraint applies nothing at the setup pose\n * (the oracle's setup reading). Under `Physics.reset` spine-core's box was\n * the same, to the bit, on all nineteen tree rows (two declare a physics constraint).\n * - **What is counted.** A region's four corners and a mesh's (a linked\n * mesh's) world vertices — the rows of the oracle's `setup.attachments`\n * block, in full doubles. A clipping polygon, a bounding box, a path and a\n * point are not counted (measured: each placed 5000 units out moved\n * `getBounds` by nothing), and the box is not clipped: `getBounds` called\n * without its optional clipper.\n * - **A slot on an inactive bone is not counted** — measured: a skin-required\n * bone 1000 units out, which only a named skin activates, carrying a region\n * left `getBounds` at the other region's 20 units with no skin set, and 1020\n * with the bone not skin-required. A bone that is not skin-required under an\n * inactive parent is active and unposed, and its slot is counted at the\n * vertices that pose gives; the core poses the same vertices (the oracle's\n * `setup.attachments`, held at tolerance 0), and a probe of that shape read\n * the same box both ways.\n * - **The box.** `x`, `y` are the least `x` and `y` over every counted\n * vertex and `width`, `height` the greatest less the least — the\n * bottom-left corner in Spine's y-up world, not the top-left. In full\n * doubles; `build` writes each on the model's 1e-6 grid at float32\n * (`headerBoxNumber` in `src/compile.ts`, whose comment says why).\n * - **Nothing drawn is no box.** `getBounds` over no vertex returns an offset\n * of `+Infinity` and a size of `-Infinity`, which is not a box; this\n * returns `null` for it, and the emitter writes no box rather than a number\n * nobody measured.\n *\n * Pure, like the rest of `src/core/`: it links nothing from the runtime, and\n * `tools/core_gate.ts` holds it to `getBounds` at tolerance 0 over the corpus\n * (its `BOUNDS` rows).\n */\n\n/** The setup-pose box: its bottom-left corner and its extent, in Spine world units, in full doubles. */\nexport interface CoreBounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * The setup-pose bounding box of a model document (the header's rules), or\n * `null` where nothing is drawn. Refused by name — `CoreInputError` — where\n * the core leaves the setup attachments out, since a box over the rest would\n * be a box of a different pose.\n */\nexport function setupBounds(doc: CompiledDocument, plant: CorePlant = {}): CoreBounds | null {\n const view = underNoSkin(doc);\n const posed = poseSetup(view, { ...plant, round: rawNumber });\n const rows = posed.setup.attachments;\n if (rows === null) {\n const why = posed.absent.find(([block]) => block === 'setup.attachments')?.[1] ?? 'the setup attachments were not posed';\n throw new CoreInputError(`the setup-pose bounding box cannot be computed: ${why}`);\n }\n const active = activeBones(view);\n const boneOf = new Map(view.slots.map((s) => [s.name, s.bone]));\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const [slot, attachment, , vertices] of rows) {\n const bone = boneOf.get(slot);\n if (bone === undefined || !active.has(bone)) continue;\n for (let i = 0; i + 1 < vertices.length; i += 2) {\n const x = vertices[i];\n const y = vertices[i + 1];\n if (x === null || y === null) throw new CoreInputError(`the setup-pose bounding box cannot be computed: slot \"${slot}\" attachment \"${attachment}\" vertex ${i / 2} is not finite`);\n minX = Math.min(minX, x);\n minY = Math.min(minY, y);\n maxX = Math.max(maxX, x);\n maxY = Math.max(maxY, y);\n }\n }\n if (minX === Infinity) return null;\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n// --- #907 the setup-pose bounding box: end ---\n","/** Live, per-instance parameter patches (issue #1541). No model writes or history resets. */\nimport { CoreInputError, type CompiledDocument } from './index.ts';\nimport type { CorePhysicsRecord } from './constraints_physics.ts';\n\n/** The six scalar responses a consumer can override; no units or range conversion. */\nexport interface PhysicsParameters {\n readonly strength: number;\n readonly damping: number;\n readonly inertia: number;\n readonly wind: number;\n readonly gravity: number;\n readonly mix: number;\n}\n/** Omitted fields keep their existing override, if any. */\nexport type PhysicsParameterPatch = Partial<PhysicsParameters>;\n/** Detached snapshots. `effective` is null until this constraint has been evaluated. */\nexport interface PhysicsParameterRead {\n readonly override: PhysicsParameterPatch | null;\n readonly effective: PhysicsParameters | null;\n}\n\nconst FIELDS = ['strength', 'damping', 'inertia', 'wind', 'gravity', 'mix'] as const;\nconst values = (r: CorePhysicsRecord): PhysicsParameters => ({ strength: r.strength, damping: r.damping, inertia: r.inertia, wind: r.wind, gravity: r.gravity, mix: r.mix });\n\n/** Owned by one live track, including all entries of a composed track. */\nexport class LivePhysicsParameters {\n private readonly overrides = new Map<string, PhysicsParameterPatch>();\n private readonly evaluated = new Map<string, PhysicsParameters>();\n\n constructor(private readonly doc: CompiledDocument) {}\n\n private named(name: string): void {\n const constraint = this.doc.constraints.find((c) => c.name === name);\n if (constraint === undefined) throw new CoreInputError(`physics parameters: no constraint \"${String(name)}\"; this document declares [${this.doc.constraints.map((c) => c.name).join(', ')}]`);\n if (constraint.kind !== 'physics') throw new CoreInputError(`physics parameters: constraint \"${name}\" is ${constraint.kind}, not physics`);\n }\n\n set(name: string, patch: PhysicsParameterPatch): void {\n this.named(name);\n if (typeof patch !== 'object' || patch === null || Array.isArray(patch)) throw new CoreInputError(`physics parameters: constraint \"${name}\" patch is ${String(patch)}, not an object of finite fields [${FIELDS.join(', ')}]`);\n const checked: Partial<Record<(typeof FIELDS)[number], number>> = {};\n // Validate the complete patch before publishing it, including unknown symbol keys.\n for (const key of Reflect.ownKeys(patch)) {\n if (typeof key !== 'string' || !(FIELDS as readonly string[]).includes(key)) throw new CoreInputError(`physics parameters: constraint \"${name}\" field \"${String(key)}\" is unknown; expected [${FIELDS.join(', ')}]`);\n const field = key as (typeof FIELDS)[number];\n const value = patch[field];\n if (typeof value !== 'number' || !Number.isFinite(value)) throw new CoreInputError(`physics parameters: constraint \"${name}\" field \"${field}\" is ${String(value)}, not a finite number`);\n checked[field] = value;\n }\n if (Reflect.ownKeys(checked).length > 0) this.overrides.set(name, { ...this.overrides.get(name), ...checked });\n }\n\n read(name: string): PhysicsParameterRead {\n this.named(name);\n const patch = this.overrides.get(name);\n const effective = this.evaluated.get(name);\n return { override: patch === undefined ? null : { ...patch }, effective: effective === undefined ? null : { ...effective } };\n }\n\n clear(name: string): void {\n this.named(name);\n this.overrides.delete(name);\n }\n\n /** Called only for an active constraint, after the sliders and immediately before its step. */\n apply(record: CorePhysicsRecord): CorePhysicsRecord {\n const patch = this.overrides.get(record.name);\n const posed = patch === undefined ? record : { ...record, ...patch };\n this.evaluated.set(record.name, values(posed));\n return posed;\n }\n}\n","/**\n * The core's live track (issue #1276): one animation opened on a track and\n * stepped one `dt` at a time — a player's frame loop, whose steps are not known\n * in advance — every pose the raw entry's (`RawPose` in `./raw.ts`), the doubles\n * the core computed.\n *\n * It is not new math. Both batch walks — the raw entry's `poseRawAnimation`\n * and A10's looping walk (`./walk.ts`) — take their steps up front and pose\n * every step from the setup pose, carrying from one step to the next only the\n * physics context, the running track time and the animation time of the step\n * before. That carry is one object (`TrackState` in `./raw.ts`), and the batch\n * walk is \"open, then step over the list\"; this track opens the same walk and\n * takes its steps as they come. Measured before and after that split, over the\n * nineteen tree rows' 54 animations: 956 batch walks — the raw entry at 12, 24\n * and 60 fps from each reset, held three times past the duration, its two\n * one-step jumps under each reset, `poseRawAnimationEach`, A10's walk and its\n * scan on A10's schedule and at 60 fps over three cycles — 157,771 poses, every\n * one the same bits (the PR of issue #1276 carries the table).\n *\n * Several animations on several tracks, set, queued and mixed as spine-core's\n * `AnimationState` mixes them, are `openTracks` (`./tracks.ts`, issue #1336):\n * a second state machine over the same pose path past the timelines, which\n * this track reaches with the locals its one animation posed.\n *\n * ## The walk\n *\n * - **Held** (`loop: false`): the raw entry's walk — the track time the\n * running sum of the steps, the animation time held at the duration, the\n * physics clock moved by the step (or by `clock`, *The physics clock*\n * below), events over `(previous animation time,\n * animation time]` (`./raw.ts`, *One step*). `CO46` holds it to\n * `poseRawAnimation` pose for pose, every field, bit for bit.\n * - **Looped** (`loop: true`): A10's looping walk's time, clock and `reset`\n * keys across the wrap (`./walk.ts`, *The walk*) — and, which that walk does\n * not carry because its one reader reads neither, the events it fires across\n * the wrap and the clipped rows it cuts. `CO46` holds it to\n * `poseLoopingWalk` narrowed to what that walk carries, bit for bit.\n * - **The reset is the caller's**, as on the raw entry (`RawReset`): pose 0\n * (`first`) is posed when the track is opened, the batch walk's pose 0\n * under the same reset, and every `step` is one pose after it.\n * - **Neither keeps a value that is not finite** (`keep: false`, the raw\n * entry's argument: a renderer handed one draws a different picture in\n * silence). What the raw entry refuses is a drawn vertex, a clip or clipped\n * vertex, a clipped UV and an event's numbers; a bone's matrix and a slot's\n * colour channel it passes on (NaN, `null`), and so does this track. Of\n * 108 forged animations of the tree rows (a leaf and its parent scaled past\n * the largest double), 98 were refused at the first non-finite vertex and 4\n * walked holding a non-finite bone no drawn vertex reads; `CO49` holds both\n * halves, the second on a slotless bone chain.\n *\n * ## Across the wrap — what a looping track fires, measured\n *\n * Read off spine-core 4.3.13 — `AnimationState` with `setAnimation(0, name,\n * true)`, pose 0 applied at 0 and reset there or reset at the setup pose\n * with nothing applied, then per step `update(dt)`, `apply`,\n * `Skeleton.update(dt)`, `updateWorldTransform(Physics.update)` — by a\n * listener collecting `event` and `complete` in the order queued, on the\n * tree rows' six animations keying events and on 300 seeded probes whose keys\n * sit at 0, 1e-3 after it, in the middle, one float32 ulp and 1e-3 before the\n * duration, on it, and one ulp and 1e-3 past the bone's last key (where the\n * key sets the duration); over step lists that cross the wrap once and\n * several times, land exactly on the duration, and carry the track past it by\n * more than a cycle: 4,284 walks, 229,656 steps, 13,436 across the wrap, 8,846\n * longer than a cycle, 52,880 events and 24,587 completes, each in the\n * listener's order on every step. `CO47` holds the rule on its own population.\n *\n * - **A step whose animation time rose fires `(previous time, time]`**, as the\n * raw entry's — so a step that carries the track past the duration once or\n * more while its animation time still rises fires only that interval: the\n * keys it passed on the way are not fired.\n * - **A step whose animation time went down — the wrap — fires the keys after\n * the previous time, in key order, then the keys at or before the new time,\n * in key order** (`eventsFired`'s `wrapped`): the second interval opens at\n * −1, so a key at 0 fires on every wrap. Read in key order instead, 7,680 of\n * the steps read off; with the second interval opening at 0, 6,066; with\n * nothing fired across the wrap, 12,956.\n * - **A key at exactly the duration fires on the wrap step and on no other**,\n * before the keys from 0: 11,978 such firings, every one on a wrap step. A\n * key one float32 ulp before the duration is an ordinary key — it fired on a\n * rising step 545 times, where the animation time reached it before the wrap.\n * - **An equal time is not a wrap** (`loopedTime`: a track time of exactly the\n * duration applies at 0). A track stepped by exactly the duration applies at\n * 0 on every step, so it fires its keys at 0 on its first step and nothing\n * after; stepped by half the duration it wraps on every second step.\n * - **`complete` is not carried** — a listener is the player's. Measured, it is\n * queued once on a step whose track time's whole cycles rose past 0 —\n * `⌊T / d⌋ > 0` and `⌊T / d⌋ > ⌊T_before / d⌋`, on every step at a duration\n * of 0 — however many cycles the step crossed, after the keys after the\n * previous time and before the keys from 0. A player derives it from\n * `trackTime` and `duration`.\n *\n * ## The clipped rows\n *\n * The looping mode cuts every drawn attachment under a clip as the raw entry\n * does — the oracle's rows, and the core's own decomposition under a concave\n * or inverse clip (`clipThrough`) — where A10's walk cuts none. That is a\n * mode and not a measurement: the cut is per pose and does not read whether\n * the track loops. `CO48` holds it: on the clipping probe and the tree row\n * that clips, every looping pose, past the wrap included, equals the raw\n * entry's one step to its animation time in every field but the track time\n * and the events (4,009 of 4,009 on the tree row, 690 of them cutting 12,420\n * rows).\n *\n * ## The adjustment (issue #1336)\n *\n * `adjust` is a player's own bone-local value — a breath's scale, a look's\n * rotation — written onto the bones every pose, after the animation's\n * timelines posed the locals at the step's time and before the world\n * transforms, the constraints and the physics step (`LocalAdjust` in\n * `./animation.ts`, which states the view's rules). It runs on every pose the\n * animation is applied to — every `step`, and pose 0 under `reset:\n * 'animation'` — and not on pose 0 under `reset: 'setup'`, the setup pose\n * with nothing applied: a player applies its adjustment wherever it applies\n * the animation state, the first frame included, and spine-core's reset at\n * the setup pose applies none. Absent, every pose is the one the track posed\n * before it existed, bit for bit (`CO46`, unchanged; `CO50` holds a hook that\n * writes nothing to the same bits).\n *\n * `CO50` holds it to spine-core 4.3.13 on gallery/look, whose `head` carries\n * the deformed head mesh and every face bone, and the physics-driven\n * `ahoge_whip` two bones below it: the same `scaleY` written on `head` by the\n * core's hook and on `Bone.pose` between `AnimationState.apply` and\n * `updateWorldTransform(Physics.update)`, every bone's world transform and\n * every drawn vertex equal at tolerance 0 over looping and held walks under\n * both resets — spine-core's skeleton brought back to the setup pose\n * (`setupPoseBones`) before each `apply`, which is the core's own reading:\n * every pose is posed from the setup pose. Measured, and held red there:\n *\n * - **The write carried from frame to frame** — spine-core without that\n * reset, where no timeline writes an unkeyed channel back, so a `scaleY`\n * multiplied every frame compounds (every walk off from pose 2). The core\n * carries no local from one step to the next; a value a player wants\n * carried it keeps and writes again.\n * - **The write at draw time** — made after `updateWorldTransform`, the\n * bone's own matrix alone brought up to date: the bone moves, its\n * children, the meshes they carry and the physics do not.\n * - **Pose 0 not adjusted** under `reset: 'animation'`.\n *\n * ## The physics clock (issue #1396)\n *\n * `clock` is what each step moves the skeleton's physics clock by — the time\n * a physics constraint integrates — with `poseRawAnimationEach`'s meaning.\n * Absent, it is the step itself, and every pose is the one the track posed\n * before the option existed (`CO46`–`CO50`, unchanged). `physicsClockStep` is\n * the render's clock (issue #1380), for a player stepping at a fixed rate.\n * The track time, the animation time, the wrap, the events and `trackTime`\n * stay on the running sum of the steps: the clock moves the physics and\n * nothing else.\n *\n * - **Why the track takes it.** Stepped at a fixed rate whose frame lasts a\n * whole number of physics steps, a spring shows the render's defect. On the\n * public trailer's `show`, read with play#103's detector, the frame clock\n * adds outlier poses 5, 11–13, 44–45 and 187–189 at a fixed 1/20 and 8,\n * 15–17, 31–33 and 505–507 at 1/60, and `clock: physicsClockStep` removes\n * every one (the PR of issue #1396 carries the table). A player scaling its\n * own `dt` instead moves the animation time too: a key at 0.5 s fires on\n * the tenth step of 1/20 where the render and the runtime fire it on the\n * eleventh, and the player stops agreeing with `rigc render`.\n * - **The reset.** Pose 0 under `reset: 'animation'` is a step of 0 and moves\n * the clock by `clock(0)`, as the render's walk does — 0 for\n * `physicsClockStep`; under `setup` nothing is stepped. A physics `reset`\n * key restarts a constraint's time from the clock as it stands, so it is\n * read on the same clock as every other step.\n * - **The seek** stays the caller's — open, then step to the time — and its\n * steps go through the same clock, so a seek's physics is the physics of\n * the steps it took.\n * - **A clock that returns no time** — not finite, or below 0 — refuses the\n * step by name after the track time has moved, so the track stays refused.\n *\n * `CO53` holds the mechanism on LS05's spring probe (every constraint update\n * takes the steps exact arithmetic takes; the frame clock is red), `CO54` the\n * poses (equal to the render's walk, to `poseRawAnimationEach` on the same\n * clock, between the two live entries, and to spine-core with its\n * `AnimationState` updated by the step and its `Skeleton` by the clock), and\n * `CO55` that the times and the events are those of the walk without it.\n *\n * ## The environment, and the rig moved from outside (issue #1416)\n *\n * The rig states how each physics constraint answers the world — its `wind`\n * and `gravity` — and the consumer states the world. `setEnvironment({ wind,\n * gravity })` sets it from the next pose on and it stands until set again,\n * as spine-core's four `Skeleton` fields do: `wind` is `[windX, windY]`,\n * `gravity` is `[gravityX, gravityY]`, x to the right and **y down**, and\n * until set it is the runtime's own `{ wind: [1, 0], gravity: [0, 1] }`\n * (`./constraints_physics.ts`, *The environment*). Either half may be left\n * out to keep the one that stands. So a gust is the consumer setting `wind`\n * to `[0, 0]` at rest and `[k, 0]` while it blows, and a constraint that\n * states `wind: 0` does not feel it — the response is the rig's, the gust the\n * scene's.\n *\n * `physicsTranslate(x, y)` and `physicsRotate(x, y, degrees)` are the\n * runtime's `Skeleton` methods of those names: the consumer moved or turned\n * the whole rig since the last pose — in the skeleton's world, y up, degrees\n * counter-clockwise — and every constraint's next update sees its bone move\n * by that much, so a rig walked across the screen trails what hangs from it.\n * A player forwards what spine-core's `SkeletonPhysicsMovement` forwards: the\n * change of its display object's position since the last frame, converted into\n * the skeleton's units and axes, and the change of its rotation about the\n * skeleton's origin, `physicsRotate(0, 0, Δ)`, both before the `step` that\n * poses the frame.\n *\n * `CO56` holds the poses to spine-core 4.3.13 given the same values on its\n * `Skeleton`, and holds red the readings the mapping rejects; `CO57` holds that\n * nothing set — or the runtime's own values set on every step and a move of 0\n * — poses what the track posed before the methods existed, bit for bit.\n *\n * ## The oracle chain\n *\n * Nothing here is held to spine-core directly but the events: the live track\n * is held to the batch walk (`CO46`), the held batch walk to spine-core's\n * render and deform-measure recipes (`CR03`), the looped one to A10's recipe\n * (`CO25`), and both to `tools/pose_oracle.ts`'s stepped dump, whose schedule\n * is `stepSchedule` in `./constraints_physics.ts`. A second dump would be the\n * same numbers twice.\n *\n * ⛔ **A track refused part-way stays refused.** A step is checked before\n * anything moves; a refusal past that — a construct the core leaves out, a\n * non-finite vertex or write — comes after the track time and the physics\n * have moved, so every later `step` refuses naming the step it was refused\n * at, and the caller opens the track again. So does an error the caller's own\n * `adjust` throws: it is thrown mid-step, after the same moves. Seeking is the caller's too: a physics rig has\n * history, so a seek is \"open, then step to the time\".\n */\nimport { CoreInputError, type CompiledDocument } from './index.ts';\nimport { checkedClock, checkedPhysicsScope, environmentOf, openRawTrack, rotateOn, setEnvironmentOn, stepRawTrack, translateOn, type RawPose, type RawReset, type TrackState, type WalkMode } from './raw.ts';\nimport type { LocalAdjust, TimelinePlant } from './animation.ts';\nimport type { PhysicsEnvironment } from './constraints_physics.ts';\nimport { LivePhysicsParameters, type PhysicsParameterPatch, type PhysicsParameterRead } from './physics_parameters.ts';\nexport type { PhysicsParameters, PhysicsParameterPatch, PhysicsParameterRead } from './physics_parameters.ts';\nexport type { AdjustableLocals, BoneLocals, LocalAdjust, LocalAdjustContext } from './animation.ts';\nexport type { PhysicsEnvironment } from './constraints_physics.ts';\n\n/** How a live track is opened: whether it loops, and where its physics is reset (`RawReset`) — both the caller's, neither with a default — the caller's adjustment of every pose's bone locals (the header's *The adjustment*), and what each step moves the physics clock by (the header's *The physics clock*). */\nexport interface TrackOptions {\n loop: boolean;\n reset: RawReset;\n adjust?: LocalAdjust;\n /** What each step of `dt` moves the skeleton's physics clock by — `physicsClockStep` is the render's; absent, the step itself. The track time, the animation time and the events stay on the running sum of the steps. */\n clock?: (dt: number) => number;\n}\n\n/** A live track (`openTrack`): pose 0, then one pose per `step`. */\nexport interface LiveTrack {\n /** Pose 0, posed when the track was opened: the batch walk's first pose under the same `reset`. */\n readonly first: RawPose;\n /** The next pose: the track time moved by `dt`, a finite time at or above 0. */\n step(dt: number): RawPose;\n /** The running sum of the steps taken, 0 before the first. */\n readonly trackTime: number;\n /** The time the latest pose applied the animation at (0 for pose 0). */\n readonly animationTime: number;\n /** The runtime's duration of the animation (`CoreAnimationTimelines.duration`). */\n readonly duration: number;\n /** Sets the world every physics constraint answers from the next pose on (the header's *The environment*): `wind` and `gravity` as spine-core's `Skeleton.windX, windY` and `gravityX, gravityY` — x right, y down — either left out to keep the one that stands. Until set, `{ wind: [1, 0], gravity: [0, 1] }`, the runtime's own. */\n setEnvironment(environment: Partial<PhysicsEnvironment>): void;\n /** The environment the next pose answers. */\n readonly environment: PhysicsEnvironment;\n /** Merges a finite six-field patch for one physics constraint, applied from the next pose until clear. */\n setPhysicsParameters(name: string, patch: PhysicsParameterPatch): void;\n /** Pending patch and the last evaluated six values; null effective means not yet evaluated (e.g. inactive). */\n readPhysicsParameters(name: string): PhysicsParameterRead;\n /** Removes the patch for the next pose without resetting velocities, offsets or the clock. */\n clearPhysicsParameters(name: string): void;\n /** Scope omitted: all physics; otherwise exact physics names, validated atomically. Empty selects none, duplicates select once.\n * Movement changes remembered world origins synchronously, before the next evaluation.\n * spine-core's `Skeleton.physicsTranslate`: the consumer moved the whole rig by `(x, y)` in the skeleton's world (y up) since the last pose, and every physics constraint's next update sees it. */\n physicsTranslate(x: number, y: number, scope?: readonly string[]): void;\n /** Same scope contract as physicsTranslate. The consumer turned by `degrees` (counter-clockwise) about explicit `(x, y)` in the skeleton's world; changes remembered origins, not tip direction or angular velocity. */\n physicsRotate(x: number, y: number, degrees: number, scope?: readonly string[]): void;\n}\n\n/** The two modes: a track that holds at its duration is the raw entry's walk; a looping one fires its events across the wrap and cuts its clipped rows (`live`). Neither keeps a non-finite value. */\nconst HELD: WalkMode = { loop: false, keep: false };\nconst LOOPED: WalkMode = { loop: true, keep: false, live: true };\n\n/**\n * One animation opened on a live track (the header): refused by name where the\n * batch walk refuses the same document and animation, pose 0 posed, then\n * stepped one `dt` at a time.\n */\nexport function openTrack(doc: CompiledDocument, animation: string, options: TrackOptions, plant: TimelinePlant = {}): LiveTrack {\n if (typeof options !== 'object' || options === null || typeof options.loop !== 'boolean') throw new CoreInputError(`the live track's options.loop is ${JSON.stringify((options as Partial<TrackOptions> | null)?.loop)}, not true or false`);\n if (options.reset !== 'animation' && options.reset !== 'setup') throw new CoreInputError(`the live track's options.reset is ${JSON.stringify(options.reset)}, not \"animation\" or \"setup\"`);\n if (options.adjust !== undefined && typeof options.adjust !== 'function') throw new CoreInputError(`the live track's options.adjust is ${typeof options.adjust}, not a function`);\n if (options.clock !== undefined && typeof options.clock !== 'function') throw new CoreInputError(`the live track's options.clock is ${typeof options.clock}, not a function`);\n const mode = options.loop ? LOOPED : HELD;\n const clock = options.clock === undefined ? undefined : checkedClock(options.clock, 'the live track\\'s');\n const parameters = new LivePhysicsParameters(doc);\n const { track, first } = openRawTrack(doc, animation, plant, options.reset, clock === undefined ? mode : { ...mode, clock: (dt) => clock(dt) }, options.adjust, (ctx) => { ctx.parameters = parameters; });\n return new Track(track, first, parameters);\n}\n\nclass Track implements LiveTrack {\n readonly first: RawPose;\n private readonly track: TrackState<RawPose>;\n private steps = 0;\n private latest: number;\n private refused: string | null = null;\n\n constructor(track: TrackState<RawPose>, first: RawPose, private readonly parameters: LivePhysicsParameters) {\n this.track = track;\n this.first = first;\n this.latest = first.animationTime;\n }\n\n get trackTime(): number {\n return this.track.trackTime;\n }\n\n get animationTime(): number {\n return this.latest;\n }\n\n get duration(): number {\n return this.track.duration;\n }\n\n get environment(): PhysicsEnvironment {\n return environmentOf(this.track.ctx);\n }\n\n setEnvironment(environment: Partial<PhysicsEnvironment>): void {\n this.live('setEnvironment');\n setEnvironmentOn(this.track.ctx, environment, 'the live track\\'s');\n }\n\n setPhysicsParameters(name: string, patch: PhysicsParameterPatch): void {\n this.live('setPhysicsParameters');\n this.parameters.set(name, patch);\n }\n\n readPhysicsParameters(name: string): PhysicsParameterRead {\n return this.parameters.read(name);\n }\n\n clearPhysicsParameters(name: string): void {\n this.live('clearPhysicsParameters');\n this.parameters.clear(name);\n }\n\n physicsTranslate(x: number, y: number, scope?: readonly string[]): void {\n this.live('physicsTranslate');\n translateOn(this.track.ctx, x, y, 'the live track\\'s', checkedPhysicsScope(this.track.doc, scope, 'the live track\\'s'));\n }\n\n physicsRotate(x: number, y: number, degrees: number, scope?: readonly string[]): void {\n this.live('physicsRotate');\n rotateOn(this.track.ctx, x, y, degrees, 'the live track\\'s', checkedPhysicsScope(this.track.doc, scope, 'the live track\\'s'));\n }\n\n /** A refused track refuses every call that would move it, naming the step it was refused at. */\n private live(call: string): void {\n if (this.refused !== null) throw new CoreInputError(`the live track was refused at step ${this.refused}, after its time and physics had moved; open the track again (${call} not made)`);\n }\n\n step(dt: number): RawPose {\n const n = this.steps + 1;\n if (this.refused !== null) throw new CoreInputError(`the live track was refused at step ${this.refused}, after its time and physics had moved; open the track again`);\n if (typeof dt !== 'number' || !Number.isFinite(dt) || dt < 0) throw new CoreInputError(`the live track's step ${n} is ${String(dt)}, not a finite time at or above 0`);\n try {\n const pose = stepRawTrack(this.track, dt);\n this.steps = n;\n this.latest = pose.animationTime;\n return pose;\n } catch (err) {\n this.refused = `${n} (${err instanceof Error ? err.message : String(err)})`;\n throw err;\n }\n }\n}\n","/**\n * The core's live tracks (issue #1336, piece (a)): several animations over\n * one document, each on a track of its own, queued, replaced and mixed out the\n * way spine-core 4.3.13's `AnimationState` does it, stepped one `dt` at a\n * time — a player composing a character in real time: a looping base on\n * track 0, a pose held at its end on track 1 and replaced over a mix, a\n * one-shot on track 2 played once and mixed back out, and the player's own\n * bone-local adjustment (`LocalAdjust`, issue #1336's piece (b)) after every\n * track. Every pose is the raw entry's (`RawPose` in `./raw.ts`).\n *\n * It sits beside `openTrack` (`./track.ts`) rather than inside it because it\n * is a different object: one track holds one animation and its walk, and the\n * mixing below is a second state machine as long as that module's whole body.\n * What the two share is the pose path past the timelines — the adjustment,\n * the world, every constraint and the physics step (`steppedLocalsWorld` in\n * `./animation.ts`), the slot rows and the sliders (`slotRowsFrom`), the draw\n * order, the attachments and the pose's assembly (`openRawTracksPath` in\n * `./raw.ts`) — one body that the single track reaches with the locals one\n * animation posed and this state with the locals its mixed entries posed.\n *\n * ## What a step is\n *\n * `step(dt)` is a player's frame on spine-core: `AnimationState.update(dt)`,\n * `apply`, `Skeleton.update(dt)`, `updateWorldTransform(Physics.update)`. The\n * update moves every entry's track time, starts a queued entry whose delay\n * has passed, moves every mix and ends the entries a finished mix leaves; the\n * apply poses every track in order 0..N over the setup pose — every pose is\n * posed from the setup pose, as the single track's is, so nothing but the\n * entries' state survives a step — and then the adjustment, the constraints\n * and the physics. `start()` is pose 0, the reset, where `reset` says\n * (`RawReset`): at the setup pose with nothing applied, or with the tracks set\n * so far applied at 0 (an `apply` with no `update`) and reset there.\n *\n * ## The mixing — spine-core's, ported and measured\n *\n * The state below is `AnimationState`'s, field for field and in its order of\n * operations, over the core's own timelines — so that every number is the one\n * the runtime computes, which is the only thing a control at tolerance 0 can\n * hold. In brief:\n *\n * - **Track 0 at full weight poses from the setup pose** (`MixFrom.setup`,\n * alpha 1): exactly the single track's pose. `CO51`'s positive control holds\n * a state with only track 0 set to `openTrack` on the same animation, every\n * field, bit for bit.\n * - **Every other application reads its `timelineMode`**: a property no\n * earlier entry of the same track and no lower track keys mixes from the\n * setup pose (`SETUP`); one a lower track keys mixes from the value it left\n * (`CURRENT`: a bone channel `current + (value + setup − current)·alpha`,\n * and nothing at all before the timeline's first key); one an older entry of\n * the same track keys mixes from the current value, and before its first key\n * towards the setup value (`FIRST`). A property the entry mixing in keys too\n * is HELD on the entry mixing out — applied at the hold alpha\n * `alphaMix / (1 − mix)` rather than faded, so the two do not dip through\n * the setup pose — and a hold whose next entry stops keying it fades by that\n * entry's own mix (`timelineHoldMix`).\n * - **The mix**: `mixTime / mixDuration` clamped to 1 (a mix of 0 is 1), the\n * mixing-out entry applied at `alphaMix = a·(1 − mix)`; the entry mixing in\n * at the mix. A rotation mixed at an alpha below 1 turns the way it first\n * turned (`applyRotateTimeline`'s remembered direction); a scale mixed out\n * keeps the sign of the value it mixes from.\n * - **Attachments**: an entry mixing out never keeps an attachment it keys —\n * it shows it for its own deform timelines and the slot goes back to its\n * setup attachment at the end of the apply unless an entry applied at full\n * strength keyed it (`ATTACH_SETUP` / `ATTACH_RETAIN`).\n * - **The queue**: `addAnimation` with a delay at or below 0 starts the entry\n * when the entry before it completes less its mix — at its duration, or for\n * a looping one at the end of its current cycle (`getTrackComplete`) — plus\n * the delay; `addEmptyAnimation(track, mix, 0)` after a one-shot so mixes it\n * out over its last `mix` seconds. A `delay` above 0 is that many seconds\n * after the entry before starts.\n * - **Events** fire from each track's current entry as the single live track\n * fires them (`CO47`'s rule, across the wrap included). ⚠️ **An entry mixing\n * out fires none** — not \"until the mix passes half way\": `eventThreshold`\n * defaults to 0 and an entry's events are applied only while `mix <\n * eventThreshold`, which no mix is. `complete` is not carried (issue #1276).\n * - **Physics** steps on top of the mixed locals, as on one track — and on\n * the same clock: `TracksOptions.clock`, what each step moves the physics\n * clock by, has the single track's meaning (`./track.ts`, *The physics\n * clock*, issue #1396). The entries' track times, the mixes, the queue and\n * the events stay on the steps; `start()` under `reset: 'animation'` moves\n * the clock by `clock(0)`.\n *\n * `CO51` holds all of it to spine-core 4.3.13 at tolerance 0 — every bone's\n * world transform, every drawn attachment's world vertices, every slot's\n * colour and attachment, the draw order and the events — over scripted calls\n * and seeded steps on the tree's rows, and reads each rejected reading red\n * (`TracksPlant`). The oracle's bones are brought back to the setup pose\n * (`Skeleton.setupPoseBones`) before every `apply`, as `CO50`'s are, and\n * measured that reset is needed for one thing only: with no adjustment,\n * spine-core with no reset at all agrees on every walk — `AnimationState`\n * writes back every property it keyed, through mixes, holds, empties and the\n * queue — while the player's write on a channel no entry keys carries and\n * compounds without it. The state carries nothing from one step to the next\n * but its entries, so a write lasts one pose, as on the single track.\n *\n * ## Alpha and additive entries (issue #1344)\n *\n * An entry carries spine-core's `TrackEntry.alpha` (`MixOptions.alpha`, 1 when\n * absent, changed while it plays by `setAlpha`) and `TrackEntry.additive`\n * (`MixOptions.additive`). 4.3.13 has no `MixBlend` on an entry — `additive` is\n * a boolean fixed before the next apply — so the option carries that name and\n * that type. What the runtime does with them, ported and measured (`CO52`):\n *\n * - **Alpha is a weight, multiplied in**: the current entry applies at\n * `alpha · mix`; one mixing out at `from.alpha · fromMix · (1 − mix)`, its\n * held timelines at that over `1 − mix · to.alpha`. Track 0 below alpha 1\n * leaves the setup-pose shortcut and mixes as a higher track does.\n * - **Events ignore alpha**: the current entry fires its events at any alpha,\n * 0 included; an entry mixing out fires none (`eventThreshold` 0, above).\n * - **Attachments ignore alpha**: `alphaAttachmentThreshold` is 0, so the\n * current entry keeps its attachments at any alpha, 0 included;\n * `mixAttachmentThreshold` is 0, so an entry mixing out keeps none. The draw\n * order stays refused, so `mixDrawOrderThreshold` has nothing to act on.\n * - **Additive adds what the runtime marks additive** (`Timeline.additive`):\n * every bone timeline keying numbers and the deform. On a property a lower\n * track or an older entry keyed, the keyed value (a rotation's, a\n * translation's, a shear's) is added times alpha — `current + value · alpha`\n * — a scale's offset from the setup scale is added, and a deform's offset\n * from the setup vertices (weighted: the offsets themselves). From the setup\n * pose it is the same as replacing. A rotation is added as it stands, with\n * no shortest-angle wrap and no remembered direction (`shortestRotation` is\n * `additive || …`). Colour, attachment, inherit and event timelines do not\n * read `add`: under an additive entry they apply as under a replacing one.\n * Track 0 at alpha 1 with no mix adds nothing — the runtime passes `add`\n * false on that shortcut.\n * - **An additive entry is never held**, and does not hold what it mixes in\n * over: its additive timelines take their mode with no `HOLD` bit, and a\n * timeline of an entry it replaces is not held for it. Mixing out, an\n * additive entry adds at its faded alpha, so its offset fades to nothing.\n *\n * `CO52`'s oracle resets bones and slots (`setupPose()`) before every apply,\n * not the bones alone as `CO51`'s does: on its blend probe a two-colour key at\n * a partial alpha over track 0's `rgba` mixes the dark colour from what the\n * previous frame left, which carries in a runtime whose slots are not reset —\n * measured off with the bones-only reset, equal with the full one. The state\n * poses every frame from the setup pose, slots included, as it always has.\n *\n * Each rejected reading is planted (`TracksPlant`) and read red by `CO52`:\n * alpha inverted, alpha ignored, additive as replace, an additive rotation\n * through the remembered direction, an additive entry's attachments as a\n * plain timeline, the hold blind to the entry mixing in, the holds as if no\n * entry were additive, and an alpha threshold of one half on attachments.\n *\n * ## What is left out, by name\n *\n * An animation is refused when it is set or queued if it keys what the state\n * does not mix: a constraint timeline (ik, transform, path, physics, slider),\n * a sequence timeline, the draw order, or a deform of a path attachment (a\n * path's deformed curve reaches the constraints, which this state poses from\n * their records as they stand). `timeScale`, `holdPrevious`, `reverse`,\n * `shortestRotation` on a replacing entry, the thresholds as options, per-pair\n * mix tables and the listeners are not offered. An additive entry is refused\n * nothing more: every timeline the state accepts is defined under it (*Alpha\n * and additive entries* below).\n *\n * ⛔ **A state refused part-way stays refused**, as a live track does: a step\n * is checked before anything moves, and a refusal past that — a construct the\n * core leaves out, a non-finite vertex or write, an error the caller's own\n * `adjust` throws — comes after the entries and the physics have moved, so\n * every later call refuses naming the call it was refused at.\n */\nimport type { ModelBone, ModelSlot, ModelVertices } from '../model.ts';\nimport { activeBones, CoreInputError, rawNumber, shownAttachment, viewColours, WHITE, type CompiledDocument, type CoreShown, type StatedColour } from './index.ts';\nimport { channelAt, keyIndexAt, SLOT_COLOUR_TIMELINES, slotRowsFrom, steppedLocalsWorld, type BoneTimelineKind, type CoreKey, type LocalAdjust, type SlotBase, type SlotColourKind, type TimelinePlant } from './animation.ts';\nimport { deformAt, setupArray, type CoreAttachmentTimeline } from './deform.ts';\nimport { eventsFired, type CoreEventKey, type CoreEventRow } from './events.ts';\nimport { checkedClock, checkedPhysicsScope, environmentOf, openRawTracksPath, rotateOn, setEnvironmentOn, translateOn, type RawPose, type RawReset, type RawTracksPath } from './raw.ts';\nimport type { PhysicsEnvironment } from './constraints_physics.ts';\nimport { LivePhysicsParameters, type PhysicsParameterPatch, type PhysicsParameterRead } from './physics_parameters.ts';\nimport { slotTimelinesApply } from './skins.ts';\n\n/** How the live tracks are opened: where the physics is reset (`RawReset`, the caller's, no default), the caller's adjustment of every pose's bone locals, and what each step moves the physics clock by (the header's *The physics clock*). */\nexport interface TracksOptions {\n reset: RawReset;\n adjust?: LocalAdjust;\n /** What each step of `dt` moves the skeleton's physics clock by — `physicsClockStep` is the render's; absent, the step itself. Every entry's track time, the mixes, the queue and the events stay on the steps. */\n clock?: (dt: number) => number;\n}\n\n/**\n * How `setAnimation` starts an entry: whether it loops, over how many seconds\n * the entry it replaces mixes out (0 cuts), and — issue #1344 — how strongly\n * it applies and whether it adds (the header's *Alpha and additive entries*).\n */\nexport interface MixOptions {\n loop: boolean;\n mixDuration: number;\n /** `TrackEntry.alpha`: from 0 to 1, multiplied into every timeline's weight; 1 when absent. Changed while the entry plays with `LiveTracks.setAlpha`. */\n alpha?: number;\n /** `TrackEntry.additive`: the entry's bone and deform timelines add their keyed values to what the tracks below posed rather than replacing it; `false` when absent. Fixed when the entry is set or queued, as the runtime fixes it before the next apply. */\n additive?: boolean;\n}\n\n/** How `addAnimation` queues an entry: `MixOptions`, and its delay — at or below 0 relative to when the entry before it completes, above 0 seconds after the entry before starts. */\nexport interface QueueOptions extends MixOptions {\n delay: number;\n}\n\n/** A track's current entry as a player reads it: what it plays (`null` the empty animation), its times and the animation's duration — what a player detects a completion from. */\nexport interface TrackEntryView {\n animation: string | null;\n loop: boolean;\n trackTime: number;\n /** The animation time the entry applies at now (`getAnimationTime`): the track time wrapped or held at the duration. */\n animationTime: number;\n duration: number;\n /** The entry's alpha as it stands (`MixOptions.alpha`, `LiveTracks.setAlpha`). */\n alpha: number;\n /** Whether the entry adds (`MixOptions.additive`). */\n additive: boolean;\n}\n\n/** The live tracks (`openTracks`). */\nexport interface LiveTracks {\n /** Replaces what `track` plays; the entry it replaces mixes out over `mixDuration` seconds (0 cuts). Every queued entry on the track is dropped. */\n setAnimation(track: number, animation: string, options: MixOptions): void;\n /** Mixes `track` out to nothing over `mixDuration` seconds. */\n setEmptyAnimation(track: number, mixDuration: number): void;\n /** Queues `animation` after the last entry on `track` (`QueueOptions`); on an empty track, it is set. */\n addAnimation(track: number, animation: string, options: QueueOptions): void;\n /** Queues a mix out to nothing after the last entry on `track`; `delay` 0 ends the mix when that entry completes. */\n addEmptyAnimation(track: number, mixDuration: number, delay: number): void;\n /** Sets the alpha of `track`'s current entry (`TrackEntry.alpha`), from the next pose on; an entry it mixes from keeps its own. A track playing nothing is refused. */\n setAlpha(track: number, alpha: number): void;\n /** Pose 0, the reset (the header's *What a step is*): once, before the first `step`. */\n start(): RawPose;\n /** The next pose: every entry moved by `dt`, a finite time at or above 0. */\n step(dt: number): RawPose;\n /** `track`'s current entry, or `null` where it plays nothing. */\n current(track: number): TrackEntryView | null;\n /** The running sum of the steps taken, 0 before the first. */\n readonly trackTime: number;\n /** Sets the world every physics constraint answers from the next pose on, as `LiveTrack.setEnvironment` (`./track.ts`, *The environment*). */\n setEnvironment(environment: Partial<PhysicsEnvironment>): void;\n /** The environment the next pose answers. */\n readonly environment: PhysicsEnvironment;\n /** Per-instance final parameter layer, as LiveTrack.setPhysicsParameters. Persists across entry changes. */\n setPhysicsParameters(name: string, patch: PhysicsParameterPatch): void;\n /** Detached pending patch and last evaluated six values, or null effective before start / when never active. */\n readPhysicsParameters(name: string): PhysicsParameterRead;\n /** Removes the patch without resetting the physics history, as LiveTrack.clearPhysicsParameters. */\n clearPhysicsParameters(name: string): void;\n /** Scope omitted: all physics; otherwise exact physics names, validated atomically. Empty selects none, duplicates select once.\n * Movement changes remembered world origins synchronously, before the next evaluation.\n * spine-core's `Skeleton.physicsTranslate`, as `LiveTrack.physicsTranslate`. */\n physicsTranslate(x: number, y: number, scope?: readonly string[]): void;\n /** Same exact-name scope and explicit world pivot as `LiveTrack.physicsRotate`. */\n physicsRotate(x: number, y: number, degrees: number, scope?: readonly string[]): void;\n}\n\n/**\n * The rejected readings `CO51` plants back, each on its own: the mix reversed\n * (`1 − mix`), every track above 0 mixed from the setup pose rather than the\n * value the tracks below left, the hold ignored (an entry mixing out faded on\n * a property the entry mixing in keys too), a queued entry's delay at or\n * below 0 read as \"now\" rather than as the entry before's completion, and an\n * entry mixing out firing its events until the mix passes one half. Nothing\n * but a control passes one.\n */\nexport interface TracksPlant extends TimelinePlant {\n mixReversed?: boolean;\n higherTracksFromSetup?: boolean;\n holdFaded?: boolean;\n queueDelayNow?: boolean;\n /** An entry mixing out fires its events while the mix is below one half — the reading the issue's brief stated, which the runtime's `eventThreshold` of 0 contradicts. */\n eventsUntilHalfMix?: boolean;\n /** `CO52`'s, issue #1344: every entry's alpha read as `1 − alpha`. */\n alphaInverted?: boolean;\n /** Every entry's alpha read as 1 — the option ignored. */\n alphaIgnored?: boolean;\n /** An additive entry applied, and its modes computed, as a replacing one. */\n additiveAsReplace?: boolean;\n /** An additive entry's rotations mixed through the remembered direction (`applyRotateTimeline`) as a replacing entry's are, rather than added through the timeline itself. */\n additiveRotateRemembered?: boolean;\n /** An additive entry's attachment timelines applied as a plain timeline (`AttachmentTimeline.apply`, no attachment state) rather than under the threshold rule (`applyAttachmentTimeline`). */\n additiveAttachmentsDirect?: boolean;\n /** The hold alpha computed as if the entry mixing in were at alpha 1 (`keep = 1 − mix`, not `1 − mix·to.alpha`). */\n holdIgnoresEntryAlpha?: boolean;\n /** The holds computed as if no entry were additive: an additive entry's own timelines held, and a timeline held under an additive entry mixing in. */\n additiveHeld?: boolean;\n /** An entry applied below alpha one half keeps none of its attachments — a threshold the runtime's `alphaAttachmentThreshold` of 0 does not have. */\n attachmentsBelowHalfAlpha?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// the timelines, as the state applies them\n// ---------------------------------------------------------------------------\n\n/** `timelineMode`'s bits, as `AnimationState` spells them: where a timeline mixes from, and whether it is held. */\nconst CURRENT = 0;\nconst SETUP = 1;\nconst FIRST = 2;\nconst MODE = 3;\nconst HOLD = 4;\n\n/** One timeline of an animation in the order spine-core's `Animation.timelines` holds them: the slots' (attachment and colour), the bones', the deforms, then the events. */\ntype MixTimeline =\n | { type: 'bone'; bone: number; kind: BoneTimelineKind; keys: CoreKey[]; ids: string[]; instant: boolean }\n | { type: 'colour'; slot: number; kind: SlotColourKind; keys: CoreKey[]; ids: string[]; instant: false }\n | { type: 'attachment'; slot: number; keys: CoreKey[]; ids: string[]; instant: true }\n | { type: 'deform'; identity: string; timeline: CoreAttachmentTimeline; ids: string[]; instant: false }\n | { type: 'events'; keys: CoreEventKey[]; ids: string[]; instant: true };\n\n/** An animation as the state applies it: its runtime duration, its timelines and every property they key (`Animation.hasTimeline`). */\ninterface MixAnimation {\n name: string | null;\n duration: number;\n timelines: MixTimeline[];\n ids: ReadonlySet<string>;\n}\n\n/** The empty animation (`AnimationState.emptyAnimation`): no timeline, duration 0 — one object, so setting it on an entry never applied replaces that entry. */\nconst EMPTY: MixAnimation = { name: null, duration: 0, timelines: [], ids: new Set() };\n\n/** `Timeline.additive`: the timelines the runtime adds under an additive entry — every bone timeline that keys numbers, and the deform. Colour, attachment, inherit and event timelines do not read `add`. */\nfunction addable(tl: MixTimeline): boolean {\n return tl.type === 'deform' || (tl.type === 'bone' && tl.kind !== 'inherit');\n}\n\n/** The properties a bone timeline keys, spine-core's `propertyIds` by bone name. */\nconst BONE_PROPERTIES: Record<BoneTimelineKind, readonly string[]> = {\n rotate: ['rotate'], translate: ['x', 'y'], translatex: ['x'], translatey: ['y'], scale: ['scaleX', 'scaleY'], scalex: ['scaleX'], scaley: ['scaleY'], shear: ['shearX', 'shearY'], shearx: ['shearX'], sheary: ['shearY'], inherit: ['inherit'],\n};\n\n/** The properties a slot colour timeline keys. */\nconst COLOUR_PROPERTIES: Record<SlotColourKind, readonly string[]> = { rgba: ['rgb', 'alpha'], rgb: ['rgb'], alpha: ['alpha'], rgba2: ['rgb', 'alpha', 'rgb2'], rgb2: ['rgb', 'rgb2'] };\n\n/**\n * An animation compiled for the state, or refused by name where it keys what\n * the state does not mix (the header's *What is left out*). The property ids\n * are spine-core's by name — `x|bone`, `rgb|slot`, `deform|slot|record` — so\n * two timelines key one property exactly where the runtime's do.\n */\nfunction mixAnimationOf(doc: CompiledDocument, name: string): MixAnimation {\n const anim = doc.animations.find((a) => a.name === name);\n if (anim === undefined) throw new CoreInputError(`animation \"${name}\" is not one of this document's [${doc.animations.map((a) => a.name).join(', ')}]`);\n const t = anim.timelines;\n const c = anim.constraints;\n const left: string[] = [];\n for (const [kind, n] of [['ik', c.ik.length], ['transform', c.transform.length], ['path', c.path.length], ['physics', c.physics + (c.physicsKeyed?.length ?? 0)], ['slider', c.slider.length]] as const) if (n > 0) left.push(`${kind} constraint timelines`);\n if (t.attachments.some((a) => a.sequence !== null)) left.push('a sequence timeline');\n if (t.drawOrder.length > 0) left.push('the draw order');\n for (const a of t.attachments) {\n if (a.deform === null) continue;\n const g = doc.skins.find((k) => k.name === a.skin)?.attachments[a.slot]?.[a.attachment]?.geometry;\n if (g?.kind === 'path') left.push(`a deform of path attachment \"${a.skin}/${a.slot}/${a.attachment}\"`);\n }\n if (left.length > 0) throw new CoreInputError(`animation \"${name}\" keys ${left.join(', ')}, which the live tracks do not mix — they mix bone, slot colour, attachment and deform timelines, and fire events (issue #1336)`);\n const boneIndex = new Map(doc.bones.map((b, i) => [b.name, i]));\n const slotIndex = new Map(doc.slots.map((s, i) => [s.name, i]));\n const timelines: MixTimeline[] = [];\n for (const target of t.slots) {\n const slot = slotIndex.get(target.name) as number;\n for (const tl of target.timelines) {\n if (tl.kind === 'attachment') timelines.push({ type: 'attachment', slot, keys: tl.keys, ids: [`attachment|${target.name}`], instant: true });\n else timelines.push({ type: 'colour', slot, kind: tl.kind, keys: tl.keys, ids: COLOUR_PROPERTIES[tl.kind].map((p) => `${p}|${target.name}`), instant: false });\n }\n }\n for (const target of t.bones) {\n const bone = boneIndex.get(target.name) as number;\n for (const tl of target.timelines) timelines.push({ type: 'bone', bone, kind: tl.kind, keys: tl.keys, ids: BONE_PROPERTIES[tl.kind].map((p) => `${p}|${target.name}`), instant: tl.kind === 'inherit' });\n }\n for (const a of t.attachments) {\n if (a.deform === null) continue;\n const identity = `${a.skin}/${a.slot}/${a.attachment}`;\n timelines.push({ type: 'deform', identity, timeline: a, ids: [`deform|${a.slot}|${identity}`], instant: false });\n }\n if (t.events.length > 0) timelines.push({ type: 'events', keys: t.events, ids: ['event'], instant: true });\n return { name, duration: t.duration, timelines, ids: new Set(timelines.flatMap((x) => x.ids)) };\n}\n\n/**\n * The property ids an animation's timelines key, in the order the state\n * applies them — what `CO51` holds to spine-core's `Animation.timelines`, since\n * a timeline's mode depends on which timeline of the same track saw its\n * property first.\n */\nexport function mixPropertyOrder(doc: CompiledDocument, animation: string): string[][] {\n return mixAnimationOf(doc, animation).timelines.map((x) => x.ids);\n}\n\n// ---------------------------------------------------------------------------\n// the entries — `TrackEntry`\n// ---------------------------------------------------------------------------\n\ninterface Entry {\n anim: MixAnimation;\n loop: boolean;\n previous: Entry | null;\n next: Entry | null;\n mixingFrom: Entry | null;\n mixingTo: Entry | null;\n delay: number;\n trackTime: number;\n trackLast: number;\n nextTrackLast: number;\n trackEnd: number;\n animationLast: number;\n nextAnimationLast: number;\n mixTime: number;\n mixDuration: number;\n totalAlpha: number;\n /** `TrackEntry.alpha`. */\n alpha: number;\n /** `TrackEntry.additive`. */\n additive: boolean;\n keepHold: boolean;\n timelineMode: number[];\n timelineHoldMix: Array<Entry | null | undefined>;\n /** Each rotate timeline's remembered direction, two numbers per timeline; its length is what marks the first frame (`applyRotateTimeline`). */\n timelinesRotation: number[];\n}\n\n/** A new entry (`AnimationState.trackEntry`): every field the runtime's default; the mix duration 0, `AnimationStateData`'s default mix, alpha 1, not additive. */\nfunction newEntry(anim: MixAnimation, loop: boolean): Entry {\n return {\n anim, loop, previous: null, next: null, mixingFrom: null, mixingTo: null,\n delay: 0, trackTime: 0, trackLast: -1, nextTrackLast: -1, trackEnd: Number.MAX_VALUE,\n animationLast: -1, nextAnimationLast: -1, mixTime: 0, mixDuration: 0, totalAlpha: 0, alpha: 1, additive: false, keepHold: false,\n timelineMode: [], timelineHoldMix: [], timelinesRotation: [],\n };\n}\n\n/** `TrackEntry.getAnimationTime`: the track time wrapped by the duration (0 over a duration of 0) when looping, else held at the duration. */\nfunction animationTimeOf(e: Entry): number {\n if (!e.loop) return Math.min(e.trackTime + 0, e.anim.duration);\n const d = e.anim.duration;\n if (d === 0) return 0;\n return (e.trackTime % d) + 0;\n}\n\n/** `TrackEntry.getTrackComplete`: when a looping entry ends its current cycle, when a held one reaches its duration, or now. */\nfunction trackComplete(e: Entry): number {\n const d = e.anim.duration;\n if (d !== 0) {\n if (e.loop) return d * (1 + ((e.trackTime / d) | 0));\n if (e.trackTime < d) return d;\n }\n return e.trackTime;\n}\n\nconst signum = (v: number): number => (v > 0 ? 1 : v < 0 ? -1 : 0);\nconst clamp01 = (v: number): number => (v < 0 ? 0 : v > 1 ? 1 : v);\n\n/** A slot's setup dark colour where it states none: never read, since such a slot carries no dark channel and a two-colour timeline returns before it (`applyColour`). */\nconst NO_DARK: readonly number[] = [0, 0, 0];\n\n// ---------------------------------------------------------------------------\n// one step's skeleton — the pose the entries are applied to\n// ---------------------------------------------------------------------------\n\n/** `Slot.attachmentState` against the apply's `unkeyedState`: untouched, shown for a deform only, or kept. */\nconst ATTACH_NONE = 0;\nconst ATTACH_SETUP = 1;\nconst ATTACH_RETAIN = 2;\n\ninterface SlotState {\n placeholder: string | null;\n light: number[];\n dark: number[] | null;\n deform: number[] | null;\n seen: string[];\n attachmentState: number;\n}\n\n/** What a slot's placeholder resolves to, as the state compares attachments: the record's own key, whether it is a vertex attachment, and the record its deform timelines are keyed as (`VertexAttachment.timelineAttachment`). */\ninterface Resolved {\n key: string | null;\n vertex: boolean;\n timeline: string | null;\n vertices: ModelVertices | null;\n}\n\nclass Pose {\n readonly bones: ModelBone[];\n readonly slots: SlotState[];\n readonly events: CoreEventRow[] = [];\n private readonly active: ReadonlySet<string>;\n private readonly live: boolean[];\n private readonly resolved = new Map<string, Resolved>();\n /** The view's stated colours (`viewColours`). */\n readonly stated: (hex: string) => StatedColour;\n\n constructor(\n private readonly doc: CompiledDocument,\n private readonly plant: TracksPlant,\n ) {\n this.bones = [...doc.bones];\n this.active = activeBones(doc);\n // The view's stated colours, read once (`viewColours`) and copied into the step's own channels; a planted reader of the light colour is called as it always was.\n const stated = viewColours(doc);\n this.stated = stated;\n const colour = plant.colour ?? stated;\n const gate = plant.slotTimelines ?? slotTimelinesApply;\n this.live = doc.slots.map((s) => gate(doc, s, this.active));\n this.slots = doc.slots.map((slot): SlotState => {\n const setupDark = slot.dark === undefined ? null : stated(slot.dark);\n const setupLight = slot.color === undefined ? WHITE : colour(slot.color);\n return { placeholder: slot.setup, light: [setupLight[0], setupLight[1], setupLight[2], setupLight[3]], dark: setupDark === null ? null : [setupDark[0], setupDark[1], setupDark[2]], deform: null, seen: [], attachmentState: ATTACH_NONE };\n });\n }\n\n /** Bone `i`'s locals to write: the setup bone copied on its first write, as `posedBones` copies a keyed one. */\n bone(i: number): ModelBone | null {\n const b = this.bones[i];\n if (!this.active.has(b.name)) return null;\n if (b === this.doc.bones[i]) this.bones[i] = { ...b };\n return this.bones[i];\n }\n\n slotLive(i: number): boolean {\n return this.live[i];\n }\n\n /** What `placeholder` shows in slot `i` (`Resolved`). */\n resolve(i: number, placeholder: string | null): Resolved {\n if (placeholder === null) return { key: null, vertex: false, timeline: null, vertices: null };\n const slot = this.doc.slots[i];\n const memo = `${i}\\u0000${placeholder}`;\n const known = this.resolved.get(memo);\n if (known !== undefined) return known;\n const s = (this.plant.shown ?? shownAttachment)(this.doc, { ...slot, setup: placeholder });\n let out: Resolved;\n if (s === null) out = { key: null, vertex: false, timeline: null, vertices: null };\n else if ('conflict' in s) out = { key: `conflict\\u0000${placeholder}`, vertex: false, timeline: null, vertices: null };\n else out = resolvedOf(this.doc, slot, s);\n this.resolved.set(memo, out);\n return out;\n }\n\n /** `SlotPose.setAttachment`: a different attachment clears the deform unless both play the same record's timelines. */\n setAttachment(i: number, placeholder: string | null): void {\n const s = this.slots[i];\n const was = this.resolve(i, s.placeholder);\n const now = this.resolve(i, placeholder);\n s.placeholder = placeholder;\n if (was.key === now.key) return;\n if (!now.vertex || !was.vertex || now.timeline !== was.timeline) s.deform = null;\n }\n}\n\n/** A shown record as the state compares it (`Resolved`): a vertex attachment plays its own record's timelines, a linked mesh that plays its source's those. */\nfunction resolvedOf(doc: CompiledDocument, slot: ModelSlot, s: CoreShown): Resolved {\n const g = s.record.geometry;\n const key = `${s.skin}\\u0000${s.placeholder}`;\n if (g === undefined || g.kind === 'region') return { key, vertex: false, timeline: null, vertices: null };\n if (g.kind === 'linkedmesh') {\n const source = doc.skins.find((k) => k.name === g.skin)?.attachments[g.slot]?.[g.source]?.geometry;\n const vertices = source !== undefined && source.kind !== 'region' && source.kind !== 'linkedmesh' ? source.vertices : null;\n return { key, vertex: true, timeline: s.record.timelines === true ? `${g.skin}/${g.slot}/${g.source}` : `${s.skin}/${slot.name}/${s.placeholder}`, vertices };\n }\n return { key, vertex: true, timeline: `${s.skin}/${slot.name}/${s.placeholder}`, vertices: g.vertices };\n}\n\n// ---------------------------------------------------------------------------\n// the state — `AnimationState`\n// ---------------------------------------------------------------------------\n\nclass Mixer {\n readonly tracks: Array<Entry | null> = [];\n private animationsChanged = false;\n private readonly propertyIds = new Map<string, number>();\n private readonly anims = new Map<string, MixAnimation>();\n\n constructor(\n private readonly doc: CompiledDocument,\n private readonly plant: TracksPlant,\n ) {}\n\n animation(name: string): MixAnimation {\n let a = this.anims.get(name);\n if (a === undefined) {\n a = mixAnimationOf(this.doc, name);\n this.anims.set(name, a);\n }\n return a;\n }\n\n private changed(): void {\n this.animationsChanged = true;\n }\n\n private expandToIndex(index: number): Entry | null {\n while (this.tracks.length <= index) this.tracks.push(null);\n return this.tracks[index];\n }\n\n private clearNext(entry: Entry): void {\n entry.next = null;\n }\n\n private setTrack(index: number, current: Entry): void {\n const from = this.expandToIndex(index);\n this.tracks[index] = current;\n current.previous = null;\n if (from !== null) {\n from.next = null;\n current.mixingFrom = from;\n from.mixingTo = current;\n current.mixTime = 0;\n // Reset rotation for mixing out, in case the entry was mixed in.\n from.timelinesRotation.length = 0;\n }\n this.changed();\n }\n\n setAnimation(track: number, anim: MixAnimation, loop: boolean): Entry {\n let current = this.expandToIndex(track);\n if (current !== null) {\n if (current.nextTrackLast === -1 && current.anim === anim) {\n // Don't mix from an entry that was never applied.\n this.tracks[track] = current.mixingFrom;\n this.changed();\n this.clearNext(current);\n current = current.mixingFrom;\n } else this.clearNext(current);\n }\n const entry = newEntry(anim, loop);\n this.setTrack(track, entry);\n return entry;\n }\n\n addAnimation(track: number, anim: MixAnimation, loop: boolean, delay: number): Entry {\n let last = this.expandToIndex(track);\n if (last !== null) while (last.next !== null) last = last.next;\n const entry = newEntry(anim, loop);\n if (last === null) {\n this.setTrack(track, entry);\n if (delay < 0) delay = 0;\n } else {\n last.next = entry;\n entry.previous = last;\n if (delay <= 0) delay = Math.max(delay + this.complete(last) - entry.mixDuration, 0);\n }\n entry.delay = delay;\n return entry;\n }\n\n /** `TrackEntry.setMixDuration(mixDuration, delay)`. */\n setMixDuration(entry: Entry, mixDuration: number, delay: number): void {\n entry.mixDuration = mixDuration;\n if (delay <= 0) delay = entry.previous === null ? 0 : Math.max(delay + this.complete(entry.previous) - mixDuration, 0);\n entry.delay = delay;\n }\n\n /** `getTrackComplete`, or 0 under the plant that reads a queued delay as \"now\". */\n complete(e: Entry): number {\n return this.plant.queueDelayNow === true ? e.trackTime : trackComplete(e);\n }\n\n /** `TrackEntry.mix()`: `mixTime / mixDuration` clamped to 1, 1 over a mix of 0 — reversed under the plant. */\n mixOf(e: Entry): number {\n let m: number;\n if (e.mixDuration === 0) m = 1;\n else {\n m = e.mixTime / e.mixDuration;\n if (m >= 1) m = 1;\n }\n return this.plant.mixReversed === true ? 1 - m : m;\n }\n\n /** `TrackEntry.alpha` — inverted or ignored under the plants. */\n alphaOf(e: Entry): number {\n if (this.plant.alphaIgnored === true) return 1;\n return this.plant.alphaInverted === true ? 1 - e.alpha : e.alpha;\n }\n\n /** `TrackEntry.additive` — never under the plant that applies an additive entry as a replacing one. */\n additiveOf(e: Entry): boolean {\n return e.additive && this.plant.additiveAsReplace !== true;\n }\n\n /** Whether `computeHold` reads an entry as additive — never under the plant that holds as if none were. */\n private holdsAdditive(e: Entry | null): boolean {\n return e !== null && this.additiveOf(e) && this.plant.additiveHeld !== true;\n }\n\n update(delta: number): void {\n const tracks = this.tracks;\n for (let i = 0, n = tracks.length; i < n; i++) {\n const current = tracks[i];\n if (current === null) continue;\n current.animationLast = current.nextAnimationLast;\n current.trackLast = current.nextTrackLast;\n let currentDelta = delta;\n if (current.delay > 0) {\n current.delay -= currentDelta;\n if (current.delay > 0) continue;\n currentDelta = -current.delay;\n current.delay = 0;\n }\n let next = current.next;\n if (next !== null) {\n // When the next entry's delay is passed, change to the next entry, preserving leftover time.\n const nextTime = current.trackLast - next.delay;\n if (nextTime >= 0) {\n next.delay = 0;\n next.trackTime += nextTime + delta;\n current.trackTime += currentDelta;\n this.setTrack(i, next);\n while (next.mixingFrom !== null) {\n next.mixTime += delta;\n next = next.mixingFrom;\n }\n continue;\n }\n } else if (current.trackLast >= current.trackEnd && current.mixingFrom === null) {\n tracks[i] = null;\n this.changed();\n this.clearNext(current);\n continue;\n }\n if (current.mixingFrom !== null && this.updateMixingFrom(current, delta)) {\n // End mixing from entries once all have completed.\n const from = current.mixingFrom;\n current.mixingFrom = null;\n if (from !== null) from.mixingTo = null;\n this.changed();\n }\n current.trackTime += currentDelta;\n }\n }\n\n private updateMixingFrom(to: Entry, delta: number): boolean {\n const from = to.mixingFrom;\n if (from === null) return true;\n const finished = this.updateMixingFrom(from, delta);\n from.animationLast = from.nextAnimationLast;\n from.trackLast = from.nextTrackLast;\n // The from entry was applied at least once and the mix is complete.\n if (to.nextTrackLast !== -1 && to.mixTime >= to.mixDuration) {\n // Mixing is complete for all entries before the from entry or the mix is instantaneous.\n if (from.totalAlpha === 0 || to.mixDuration === 0) {\n to.mixingFrom = from.mixingFrom;\n if (from.mixingFrom !== null) from.mixingFrom.mixingTo = to;\n if (from.totalAlpha === 0) for (let next: Entry | null = to; next.mixingTo !== null; next = next.mixingTo) next.keepHold = true;\n this.changed();\n }\n return finished;\n }\n from.trackTime += delta;\n to.mixTime += delta;\n return false;\n }\n\n /** `AnimationState.apply` onto one step's pose, every track in order; returns track 0's current entry's animation time (0 where it applied none). */\n apply(pose: Pose): number {\n if (this.animationsChanged) this.computeModes();\n let base = 0;\n const tracks = this.tracks;\n for (let i = 0, n = tracks.length; i < n; i++) {\n const current = tracks[i];\n if (current === null || current.delay > 0) continue;\n // Apply mixing from entries first.\n let alpha = this.alphaOf(current);\n if (current.mixingFrom !== null) alpha *= this.applyMixingFrom(current, pose, i);\n else if (current.trackTime >= current.trackEnd && current.next === null) alpha = 0;\n // Apply the current entry.\n const animationLast = current.animationLast;\n const animationTime = animationTimeOf(current);\n const timelines = current.anim.timelines;\n const count = timelines.length;\n if (i === 0 && alpha === 1) {\n // Track 0 at full weight poses from the setup pose and adds nothing, additive or not — the runtime passes `add` false here.\n for (const tl of timelines) {\n if (tl.type === 'attachment') this.applyAttachment(pose, tl, animationTime, SETUP, true);\n else this.applyTimeline(pose, tl, animationLast, animationTime, true, 1, SETUP, false, false);\n }\n } else {\n const modes = current.timelineMode;\n // `alphaAttachmentThreshold` is 0: an entry keeps its attachments at any alpha, 0 included.\n const retain = this.plant.attachmentsBelowHalfAlpha === true ? alpha >= 0.5 : alpha >= 0;\n const add = this.additiveOf(current);\n // `shortestRotation = add || …`: an additive entry's rotations go through the timeline itself, never the remembered direction.\n const shortest = add && this.plant.additiveRotateRemembered !== true;\n const firstFrame = !shortest && current.timelinesRotation.length !== count << 1;\n if (firstFrame) current.timelinesRotation.length = count << 1;\n timelines.forEach((tl, ii) => {\n const from = this.fromOf(modes[ii] & MODE, i);\n if (!shortest && tl.type === 'bone' && tl.kind === 'rotate') this.applyRotate(pose, tl, animationTime, alpha, from, current.timelinesRotation, ii << 1, firstFrame);\n else if (tl.type === 'attachment') {\n if (add && this.plant.additiveAttachmentsDirect === true) this.applyAttachmentDirect(pose, tl, animationTime, from, false);\n else this.applyAttachment(pose, tl, animationTime, from, retain);\n } else this.applyTimeline(pose, tl, animationLast, animationTime, true, alpha, from, false, add);\n });\n }\n if (i === 0) base = animationTime;\n current.nextAnimationLast = animationTime;\n current.nextTrackLast = current.trackTime;\n }\n // Set slot attachments to the setup pose if they were set temporarily to apply deform timelines.\n pose.slots.forEach((s, k) => {\n if (s.attachmentState === ATTACH_SETUP) pose.setAttachment(k, this.doc.slots[k].setup);\n });\n return base;\n }\n\n /** Where a timeline mixes from — `CURRENT` read as `SETUP` above track 0 under the plant. */\n private fromOf(from: number, track: number): number {\n return this.plant.higherTracksFromSetup === true && track > 0 && from === CURRENT ? SETUP : from;\n }\n\n private applyMixingFrom(to: Entry, pose: Pose, track: number): number {\n const from = to.mixingFrom as Entry;\n const fromMix = from.mixingFrom !== null ? this.applyMixingFrom(from, pose, track) : 1;\n const mix = this.mixOf(to);\n const a = this.alphaOf(from) * fromMix;\n const keep = 1 - mix * (this.plant.holdIgnoresEntryAlpha === true ? 1 : this.alphaOf(to));\n const alphaMix = a * (1 - mix);\n const alphaHold = keep > 0 ? alphaMix / keep : a;\n const timelines = from.anim.timelines;\n const count = timelines.length;\n const modes = from.timelineMode;\n const holdMix = from.timelineHoldMix;\n const add = this.additiveOf(from);\n const shortest = add && this.plant.additiveRotateRemembered !== true;\n const firstFrame = !shortest && from.timelinesRotation.length !== count << 1;\n if (firstFrame) from.timelinesRotation.length = count << 1;\n const animationLast = from.animationLast;\n const animationTime = animationTimeOf(from);\n const fire = this.plant.eventsUntilHalfMix === true && mix < 0.5;\n from.totalAlpha = 0;\n timelines.forEach((tl, i) => {\n const mode = modes[i];\n const mixFrom = this.fromOf(mode & MODE, track);\n let alpha: number;\n if ((mode & HOLD) !== 0 && this.plant.holdFaded !== true) {\n const h = holdMix[i];\n alpha = h === null || h === undefined ? alphaHold : alphaHold * (1 - this.mixOf(h));\n } else alpha = alphaMix;\n from.totalAlpha += alpha;\n if (!shortest && tl.type === 'bone' && tl.kind === 'rotate') this.applyRotate(pose, tl, animationTime, alpha, mixFrom, from.timelinesRotation, i << 1, firstFrame);\n else if (tl.type === 'attachment') {\n // `mixAttachmentThreshold` is 0: an entry mixing out never keeps an attachment, whatever its alpha.\n if (add && this.plant.additiveAttachmentsDirect === true) this.applyAttachmentDirect(pose, tl, animationTime, mixFrom, true);\n else this.applyAttachment(pose, tl, animationTime, mixFrom, false);\n }\n // An entry mixing out fires no event: `eventThreshold` is 0 and its events are applied only while the mix is below it.\n // An additive one mixing out adds at the faded alpha — its additive timelines are never held (`computeHold`).\n else this.applyTimeline(pose, tl, animationLast, animationTime, fire, alpha, mixFrom, true, add);\n });\n from.nextAnimationLast = animationTime;\n from.nextTrackLast = from.trackTime;\n return mix;\n }\n\n /** `_animationsChanged`: every track's entries' modes, oldest first, the property owners cleared after. */\n private computeModes(): void {\n this.animationsChanged = false;\n this.tracks.forEach((top, i) => {\n if (top === null) return;\n let entry: Entry | null = top;\n while (entry.mixingFrom !== null) entry = entry.mixingFrom;\n do {\n this.computeHold(entry, i);\n entry = entry.mixingTo;\n } while (entry !== null);\n });\n this.propertyIds.clear();\n }\n\n private computeHold(entry: Entry, track: number): void {\n const timelines = entry.anim.timelines;\n const modes = entry.timelineMode;\n modes.length = timelines.length;\n const holdMix = entry.timelineHoldMix;\n holdMix.length = 0;\n const to = entry.mixingTo;\n const add = this.holdsAdditive(entry);\n const toAdds = this.holdsAdditive(to);\n timelines.forEach((tl, i) => {\n const from = this.propertyFrom(track, tl.ids);\n // An additive entry's additive timelines are never held, and the entry's keepHold does not reach them.\n if (add && addable(tl)) {\n modes[i] = from;\n return;\n }\n let mode: number;\n // Hold if the next entry will overwrite this property — an additive one adding to it does not.\n if (to === null || tl.instant || (toAdds && addable(tl)) || !hasAny(to.anim, tl.ids)) mode = from;\n else {\n mode = from | HOLD;\n // Find the next entry that doesn't overwrite this property. Its mix fades out the hold, instead of it ending abruptly.\n for (let next = to.mixingTo; next !== null; next = next.mixingTo) {\n if ((this.holdsAdditive(next) && addable(tl)) || !hasAny(next.anim, tl.ids)) {\n if (next.mixDuration > 0) holdMix[i] = next;\n break;\n }\n }\n }\n if (entry.keepHold) mode = (mode & ~HOLD) | ((modes[i] ?? 0) & HOLD);\n modes[i] = mode;\n });\n }\n\n /** `AnimationState.from`: `SETUP` for a property no one keyed yet, `FIRST` for one this track keyed first, `CURRENT` for one a lower track keyed. */\n private propertyFrom(track: number, ids: readonly string[]): number {\n const owners = this.propertyIds;\n let from = SETUP;\n for (let i = 0, n = ids.length; i < n; i++) {\n const owner = owners.get(ids[i]);\n if (owner === undefined) owners.set(ids[i], track);\n else {\n if (owner !== track) {\n while (++i < n) if (!owners.has(ids[i])) owners.set(ids[i], track);\n return CURRENT;\n }\n from = FIRST;\n }\n }\n return from;\n }\n\n // -------------------------------------------------------------------------\n // the timelines' `apply`\n // -------------------------------------------------------------------------\n\n private values(keys: readonly CoreKey[], t: number): number[] | null {\n const index = (this.plant.search ?? keyIndexAt)(keys, t);\n if (index < 0) return null;\n const channel = this.plant.channel ?? channelAt;\n return keys[index].values.map((_v, c) => channel(keys, index, c, t));\n }\n\n /** `Timeline.apply` for every timeline but an attachment's and a rotation mixed below full weight; `add` is the entry's, read only by the timelines the runtime adds (`addable`). */\n private applyTimeline(pose: Pose, tl: MixTimeline, lastTime: number, time: number, fire: boolean, alpha: number, from: number, out: boolean, add: boolean): void {\n switch (tl.type) {\n case 'bone': return this.applyBone(pose, tl, time, alpha, from, out, add);\n case 'colour': return this.applyColour(pose, tl, time, alpha, from);\n case 'deform': return this.applyDeform(pose, tl, time, alpha, from, add);\n case 'events':\n if (fire) pose.events.push(...eventsFired(tl.keys, lastTime, time, rawNumber, time < lastTime));\n return;\n case 'attachment': return;\n }\n }\n\n private applyBone(pose: Pose, tl: Extract<MixTimeline, { type: 'bone' }>, time: number, alpha: number, from: number, out: boolean, add: boolean): void {\n const bone = pose.bone(tl.bone);\n if (bone === null) return;\n const setup = this.doc.bones[tl.bone];\n if (tl.kind === 'inherit') {\n const restore = (): void => {\n if (setup.inheritMode === undefined) delete bone.inheritMode;\n else bone.inheritMode = setup.inheritMode;\n };\n if (out) {\n if (from !== CURRENT) restore();\n return;\n }\n const index = (this.plant.search ?? keyIndexAt)(tl.keys, time);\n if (index < 0) {\n if (from !== CURRENT) restore();\n } else bone.inheritMode = tl.keys[index].mode;\n return;\n }\n const v = this.values(tl.keys, time);\n const relative = (field: 'x' | 'y' | 'rotation' | 'shearX' | 'shearY', i: number): void => {\n const s = setup[field] ?? 0;\n const c = bone[field] ?? 0;\n // `getRelativeValue`: from the setup pose the same either way; else the keyed value added, or the value over the setup mixed in.\n bone[field] = v === null ? beforeFirstKey(from, alpha, c, s) : from === SETUP ? s + v[i] * alpha : c + (add ? v[i] : v[i] + s - c) * alpha;\n };\n const pair = (fx: 'x' | 'shearX', fy: 'y' | 'shearY'): void => {\n const sx = setup[fx] ?? 0;\n const sy = setup[fy] ?? 0;\n if (v === null) {\n if (from === SETUP) {\n bone[fx] = sx;\n bone[fy] = sy;\n } else if (from === FIRST) {\n bone[fx] = (bone[fx] ?? 0) + (sx - (bone[fx] ?? 0)) * alpha;\n bone[fy] = (bone[fy] ?? 0) + (sy - (bone[fy] ?? 0)) * alpha;\n }\n return;\n }\n if (from === SETUP) {\n bone[fx] = sx + v[0] * alpha;\n bone[fy] = sy + v[1] * alpha;\n } else if (add) {\n bone[fx] = (bone[fx] ?? 0) + v[0] * alpha;\n bone[fy] = (bone[fy] ?? 0) + v[1] * alpha;\n } else {\n bone[fx] = (bone[fx] ?? 0) + (sx + v[0] - (bone[fx] ?? 0)) * alpha;\n bone[fy] = (bone[fy] ?? 0) + (sy + v[1] - (bone[fy] ?? 0)) * alpha;\n }\n };\n const scale = (field: 'scaleX' | 'scaleY', i: number): void => {\n const s = setup[field] ?? 1;\n const c = bone[field] ?? 1;\n bone[field] = v === null ? beforeFirstKey(from, alpha, c, s) : scaleValue(v[i] * s, alpha, from, out, add, c, s);\n };\n switch (tl.kind) {\n case 'rotate': relative('rotation', 0); break;\n case 'translate': pair('x', 'y'); break;\n case 'translatex': relative('x', 0); break;\n case 'translatey': relative('y', 0); break;\n case 'shear': pair('shearX', 'shearY'); break;\n case 'shearx': relative('shearX', 0); break;\n case 'sheary': relative('shearY', 0); break;\n case 'scale':\n if (v === null) {\n const sx = setup.scaleX ?? 1;\n const sy = setup.scaleY ?? 1;\n if (from === SETUP) {\n bone.scaleX = sx;\n bone.scaleY = sy;\n } else if (from === FIRST) {\n bone.scaleX = (bone.scaleX ?? 1) + (sx - (bone.scaleX ?? 1)) * alpha;\n bone.scaleY = (bone.scaleY ?? 1) + (sy - (bone.scaleY ?? 1)) * alpha;\n }\n } else {\n bone.scaleX = scaleValue(v[0] * (setup.scaleX ?? 1), alpha, from, out, add, bone.scaleX ?? 1, setup.scaleX ?? 1);\n bone.scaleY = scaleValue(v[1] * (setup.scaleY ?? 1), alpha, from, out, add, bone.scaleY ?? 1, setup.scaleY ?? 1);\n }\n break;\n case 'scalex': scale('scaleX', 0); break;\n case 'scaley': scale('scaleY', 0); break;\n }\n }\n\n /** `applyRotateTimeline`: a rotation mixed below full weight turns the way it first turned. */\n private applyRotate(pose: Pose, tl: Extract<MixTimeline, { type: 'bone' }>, time: number, alpha: number, from: number, rotations: number[], i: number, firstFrame: boolean): void {\n if (firstFrame) rotations[i] = 0;\n if (alpha === 1) {\n this.applyBone(pose, tl, time, 1, from, false, false);\n return;\n }\n const bone = pose.bone(tl.bone);\n if (bone === null) return;\n const setup = this.doc.bones[tl.bone].rotation ?? 0;\n const v = this.values(tl.keys, time);\n let r1: number;\n let r2: number;\n if (v === null) {\n if (from === SETUP) {\n bone.rotation = setup;\n return;\n }\n if (from === CURRENT) return;\n r1 = bone.rotation ?? 0;\n r2 = setup;\n } else {\n r1 = from === SETUP ? setup : (bone.rotation ?? 0);\n r2 = setup + v[0];\n }\n // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.\n let total: number;\n let diff = r2 - r1;\n diff -= Math.ceil(diff / 360 - 0.5) * 360;\n if (diff === 0) total = rotations[i];\n else {\n let lastTotal: number;\n let lastDiff: number;\n if (firstFrame) {\n lastTotal = 0;\n lastDiff = diff;\n } else {\n lastTotal = rotations[i];\n // A slot the runtime's array never wrote reads `undefined`, which compares as NaN.\n lastDiff = rotations[i + 1] ?? Number.NaN;\n }\n const loops = lastTotal - (lastTotal % 360);\n total = diff + loops;\n const current = diff >= 0;\n let dir = lastTotal >= 0;\n if (Math.abs(lastDiff) <= 90 && signum(lastDiff) !== signum(diff)) {\n if (Math.abs(lastTotal - loops) > 180) {\n total += 360 * signum(lastTotal);\n dir = current;\n } else if (loops !== 0) total -= 360 * signum(lastTotal);\n else dir = current;\n }\n if (dir !== current) total += 360 * signum(lastTotal);\n rotations[i] = total;\n }\n rotations[i + 1] = diff;\n bone.rotation = r1 + total * alpha;\n }\n\n /** `applyAttachmentTimeline`: shown for good when retained, else for the deform timelines only and set back at the end of the apply. */\n private applyAttachment(pose: Pose, tl: Extract<MixTimeline, { type: 'attachment' }>, time: number, from: number, retain: boolean): void {\n if (!pose.slotLive(tl.slot)) return;\n const s = pose.slots[tl.slot];\n if (!retain && s.attachmentState === ATTACH_RETAIN) return;\n const index = (this.plant.search ?? keyIndexAt)(tl.keys, time);\n let setup = index < 0;\n let name: string | null = null;\n if (!setup) {\n name = tl.keys[index].name ?? null;\n setup = !retain && name === null;\n }\n if (setup) {\n if (from === CURRENT) return;\n name = this.doc.slots[tl.slot].setup;\n }\n pose.setAttachment(tl.slot, name);\n if (retain) s.attachmentState = ATTACH_RETAIN;\n else if (!setup) s.attachmentState = ATTACH_SETUP;\n }\n\n /** `AttachmentTimeline.apply` — the plain timeline, writing no attachment state: only `additiveAttachmentsDirect` reaches it, the reading `CO52` rejects. */\n private applyAttachmentDirect(pose: Pose, tl: Extract<MixTimeline, { type: 'attachment' }>, time: number, from: number, out: boolean): void {\n if (!pose.slotLive(tl.slot)) return;\n const index = (this.plant.search ?? keyIndexAt)(tl.keys, time);\n if (out || index < 0) {\n if (from !== CURRENT) pose.setAttachment(tl.slot, this.doc.slots[tl.slot].setup);\n } else pose.setAttachment(tl.slot, tl.keys[index].name ?? null);\n }\n\n private applyColour(pose: Pose, tl: Extract<MixTimeline, { type: 'colour' }>, time: number, alpha: number, from: number): void {\n if (!pose.slotLive(tl.slot)) return;\n const slot = this.doc.slots[tl.slot];\n const s = pose.slots[tl.slot];\n const l = s.light;\n const d = s.dark;\n // The setup colours, read only: the view's (`viewColours`), or a planted reader's light colour.\n const sl = slot.color === undefined ? WHITE : (this.plant.colour ?? pose.stated)(slot.color);\n const sd = slot.dark === undefined ? NO_DARK : pose.stated(slot.dark);\n const clampLight = (): void => {\n for (let k = 0; k < 4; k++) l[k] = clamp01(l[k]);\n };\n const v = this.values(tl.keys, time);\n const channels = SLOT_COLOUR_TIMELINES[tl.kind].channels.length;\n switch (tl.kind) {\n case 'rgba': {\n if (v === null) {\n if (from === SETUP) for (let k = 0; k < 4; k++) l[k] = sl[k];\n else if (from === FIRST) {\n for (let k = 0; k < 4; k++) l[k] += (sl[k] - l[k]) * alpha;\n clampLight();\n }\n return;\n }\n if (alpha === 1) for (let k = 0; k < 4; k++) l[k] = v[k];\n else if (from === SETUP) for (let k = 0; k < 4; k++) l[k] = sl[k] + (v[k] - sl[k]) * alpha;\n else for (let k = 0; k < 4; k++) l[k] += (v[k] - l[k]) * alpha;\n clampLight();\n return;\n }\n case 'rgb': {\n if (v === null) {\n if (from === SETUP) for (let k = 0; k < 3; k++) l[k] = sl[k];\n else if (from === FIRST) for (let k = 0; k < 3; k++) l[k] += (sl[k] - l[k]) * alpha;\n return;\n }\n const rgb = [v[0], v[1], v[2]];\n if (alpha !== 1) for (let k = 0; k < 3; k++) rgb[k] = from === SETUP ? sl[k] + (rgb[k] - sl[k]) * alpha : l[k] + (rgb[k] - l[k]) * alpha;\n for (let k = 0; k < 3; k++) l[k] = clamp01(rgb[k]);\n return;\n }\n case 'alpha': {\n if (v === null) {\n if (from === SETUP) l[3] = sl[3];\n else if (from === FIRST) l[3] += (sl[3] - l[3]) * alpha;\n return;\n }\n let a = v[0];\n if (alpha !== 1) a = from === SETUP ? sl[3] + (a - sl[3]) * alpha : l[3] + (a - l[3]) * alpha;\n l[3] = clamp01(a);\n return;\n }\n case 'rgba2':\n case 'rgb2': {\n if (d === null) return;\n const withAlpha = tl.kind === 'rgba2';\n const lightN = withAlpha ? 4 : 3;\n if (v === null) {\n if (from === SETUP) {\n for (let k = 0; k < lightN; k++) l[k] = sl[k];\n for (let k = 0; k < 3; k++) d[k] = sd[k];\n } else if (from === FIRST) {\n for (let k = 0; k < lightN; k++) l[k] += (sl[k] - l[k]) * alpha;\n if (withAlpha) clampLight();\n for (let k = 0; k < 3; k++) d[k] += (sd[k] - d[k]) * alpha;\n }\n return;\n }\n const light = v.slice(0, lightN);\n const dark = v.slice(lightN, channels);\n if (withAlpha) {\n if (alpha === 1) for (let k = 0; k < 4; k++) l[k] = light[k];\n else if (from === SETUP) {\n for (let k = 0; k < 4; k++) l[k] = sl[k] + (light[k] - sl[k]) * alpha;\n for (let k = 0; k < 3; k++) dark[k] = sd[k] + (dark[k] - sd[k]) * alpha;\n } else {\n for (let k = 0; k < 4; k++) l[k] += (light[k] - l[k]) * alpha;\n for (let k = 0; k < 3; k++) dark[k] = d[k] + (dark[k] - d[k]) * alpha;\n }\n clampLight();\n } else {\n if (alpha !== 1) {\n for (let k = 0; k < 3; k++) {\n light[k] = from === SETUP ? sl[k] + (light[k] - sl[k]) * alpha : l[k] + (light[k] - l[k]) * alpha;\n dark[k] = from === SETUP ? sd[k] + (dark[k] - sd[k]) * alpha : d[k] + (dark[k] - d[k]) * alpha;\n }\n }\n for (let k = 0; k < 3; k++) l[k] = clamp01(light[k]);\n }\n for (let k = 0; k < 3; k++) d[k] = clamp01(dark[k]);\n return;\n }\n }\n }\n\n /** `DeformTimeline.apply`: every live slot showing the record the timeline keys, its deform array mixed. */\n private applyDeform(pose: Pose, tl: Extract<MixTimeline, { type: 'deform' }>, time: number, alpha: number, from: number, add: boolean): void {\n const keys = tl.timeline.deform;\n if (keys === null) return;\n pose.slots.forEach((s, k) => {\n if (!pose.slotLive(k)) return;\n const shown = pose.resolve(k, s.placeholder);\n if (!shown.vertex || shown.timeline !== tl.identity || shown.vertices === null) return;\n const vertices = shown.vertices;\n if (!s.seen.includes(tl.identity)) s.seen.push(tl.identity);\n const target = (this.plant.deform ?? deformAt)(vertices, keys, time);\n let mixFrom = from;\n if (s.deform === null) mixFrom = SETUP;\n if (target === null) {\n // `applyBeforeFirst`.\n if (mixFrom === SETUP) s.deform = null;\n else if (mixFrom === FIRST) {\n if (alpha === 1) {\n s.deform = null;\n return;\n }\n const current = s.deform as number[];\n if (!vertices.weighted) {\n const setup = setupArray(vertices);\n s.deform = current.map((c, i) => c + (setup[i] - c) * alpha);\n } else {\n const keep = 1 - alpha;\n s.deform = current.map((c) => c * keep);\n }\n }\n return;\n }\n // `applyToSlot`: added only over a deform already there — over none it is the setup pose's branch, additive or not.\n const fromSetup = mixFrom === SETUP;\n if (alpha === 1) {\n if (add && !fromSetup) {\n const current = s.deform as number[];\n if (!vertices.weighted) {\n const setup = setupArray(vertices);\n s.deform = current.map((c, i) => c + (target[i] - setup[i]));\n } else s.deform = current.map((c, i) => c + target[i]);\n } else s.deform = [...target];\n } else if (fromSetup) {\n if (!vertices.weighted) {\n const setup = setupArray(vertices);\n s.deform = target.map((v, i) => setup[i] + (v - setup[i]) * alpha);\n } else s.deform = target.map((v) => v * alpha);\n } else if (add) {\n const current = s.deform as number[];\n if (!vertices.weighted) {\n const setup = setupArray(vertices);\n s.deform = current.map((c, i) => c + (target[i] - setup[i]) * alpha);\n } else s.deform = current.map((c, i) => c + target[i] * alpha);\n } else {\n const current = s.deform as number[];\n s.deform = current.map((c, i) => c + (target[i] - c) * alpha);\n }\n });\n }\n}\n\n/** `CurveTimeline1.beforeFirstKey`. */\nfunction beforeFirstKey(from: number, alpha: number, current: number, setup: number): number {\n if (from === SETUP) return setup;\n if (from === FIRST) return current + (setup - current) * alpha;\n return current;\n}\n\n/** `CurveTimeline1.getScaleValue` past the first key, `value` the curve times the setup scale; added, its offset from the setup scale is added to the base. */\nfunction scaleValue(value: number, alpha: number, from: number, out: boolean, add: boolean, current: number, setup: number): number {\n if (alpha === 1 && !add) return value;\n let base = from === SETUP ? setup : current;\n if (add) return base + (value - setup) * alpha;\n if (out) return base + (Math.abs(value) * Math.sign(base) - base) * alpha;\n base = Math.abs(base) * Math.sign(value);\n return base + (value - base) * alpha;\n}\n\nfunction hasAny(anim: MixAnimation, ids: readonly string[]): boolean {\n for (const id of ids) if (anim.ids.has(id)) return true;\n return false;\n}\n\n// ---------------------------------------------------------------------------\n// the live tracks\n// ---------------------------------------------------------------------------\n\n/** A track index: a whole number at or above 0, or the call refused naming it. */\nfunction trackIndex(track: number, call: string): number {\n if (typeof track !== 'number' || !Number.isInteger(track) || track < 0) throw new CoreInputError(`the live tracks' ${call} names track ${String(track)}, not a whole number at or above 0`);\n return track;\n}\n\nfunction finiteAtOrAbove0(v: number, what: string, call: string): number {\n if (typeof v !== 'number' || !Number.isFinite(v) || v < 0) throw new CoreInputError(`the live tracks' ${call} ${what} is ${String(v)}, not a finite time at or above 0`);\n return v;\n}\n\nfunction loopOf(options: MixOptions | undefined, call: string): boolean {\n if (typeof options !== 'object' || options === null || typeof options.loop !== 'boolean') throw new CoreInputError(`the live tracks' ${call} options.loop is ${JSON.stringify((options as Partial<MixOptions> | null | undefined)?.loop)}, not true or false`);\n return options.loop;\n}\n\n/** An alpha: a finite number from 0 to 1, or the call refused naming it — the runtime clamps nothing and defines no weight outside it. */\nfunction alphaValue(v: unknown, what: string, call: string): number {\n if (typeof v !== 'number' || !Number.isFinite(v) || v < 0 || v > 1) throw new CoreInputError(`the live tracks' ${call} ${what} is ${typeof v === 'number' ? String(v) : JSON.stringify(v)}, not a number from 0 to 1`);\n return v;\n}\n\n/** `options.alpha` and `options.additive`: 1 and `false` when absent, else refused by name where they are not a weight and a boolean. */\nfunction blendOf(options: MixOptions, call: string): { alpha: number; additive: boolean } {\n const alpha = options.alpha === undefined ? 1 : alphaValue(options.alpha, 'options.alpha', call);\n const additive: unknown = options.additive;\n if (additive !== undefined && typeof additive !== 'boolean') throw new CoreInputError(`the live tracks' ${call} options.additive is ${JSON.stringify(additive)}, not true or false — an entry adds or it does not`);\n return { alpha, additive: additive === true };\n}\n\nfunction delayOf(v: number, call: string): number {\n if (typeof v !== 'number' || !Number.isFinite(v)) throw new CoreInputError(`the live tracks' ${call} delay is ${String(v)}, not a finite number`);\n return v;\n}\n\n/**\n * The live tracks over `doc` (the header): refused by name where a walk on the\n * document would be, then animations set, queued and mixed out on any track,\n * pose 0 posed by `start()` and one pose per `step`.\n */\nexport function openTracks(doc: CompiledDocument, options: TracksOptions, plant: TracksPlant = {}): LiveTracks {\n if (typeof options !== 'object' || options === null || (options.reset !== 'animation' && options.reset !== 'setup')) throw new CoreInputError(`the live tracks' options.reset is ${JSON.stringify((options as Partial<TracksOptions> | null)?.reset)}, not \"animation\" or \"setup\"`);\n if (options.adjust !== undefined && typeof options.adjust !== 'function') throw new CoreInputError(`the live tracks' options.adjust is ${typeof options.adjust}, not a function`);\n if (options.clock !== undefined && typeof options.clock !== 'function') throw new CoreInputError(`the live tracks' options.clock is ${typeof options.clock}, not a function`);\n const clock = options.clock === undefined ? undefined : checkedClock(options.clock, 'the live tracks\\'');\n return new Tracks(doc, options.reset, options.adjust, clock, plant, openRawTracksPath(doc, plant));\n}\n\nclass Tracks implements LiveTracks {\n private readonly mixer: Mixer;\n private readonly parameters: LivePhysicsParameters;\n private started = false;\n private steps = 0;\n private time = 0;\n private refused: string | null = null;\n\n constructor(\n private readonly doc: CompiledDocument,\n private readonly reset: RawReset,\n private readonly adjust: LocalAdjust | undefined,\n private readonly clock: ((dt: number) => number) | undefined,\n private readonly plant: TracksPlant,\n private readonly path: RawTracksPath,\n ) {\n this.mixer = new Mixer(doc, plant);\n this.parameters = new LivePhysicsParameters(doc);\n this.path.ctx.parameters = this.parameters;\n }\n\n get trackTime(): number {\n return this.time;\n }\n\n get environment(): PhysicsEnvironment {\n return environmentOf(this.path.ctx);\n }\n\n setEnvironment(environment: Partial<PhysicsEnvironment>): void {\n this.live('setEnvironment');\n setEnvironmentOn(this.path.ctx, environment, 'the live tracks\\'');\n }\n\n setPhysicsParameters(name: string, patch: PhysicsParameterPatch): void {\n this.live('setPhysicsParameters');\n this.parameters.set(name, patch);\n }\n\n readPhysicsParameters(name: string): PhysicsParameterRead {\n return this.parameters.read(name);\n }\n\n clearPhysicsParameters(name: string): void {\n this.live('clearPhysicsParameters');\n this.parameters.clear(name);\n }\n\n physicsTranslate(x: number, y: number, scope?: readonly string[]): void {\n this.live('physicsTranslate');\n translateOn(this.path.ctx, x, y, 'the live tracks\\'', checkedPhysicsScope(this.doc, scope, 'the live tracks\\''));\n }\n\n physicsRotate(x: number, y: number, degrees: number, scope?: readonly string[]): void {\n this.live('physicsRotate');\n rotateOn(this.path.ctx, x, y, degrees, 'the live tracks\\'', checkedPhysicsScope(this.doc, scope, 'the live tracks\\''));\n }\n\n private live(call: string): void {\n if (this.refused !== null) throw new CoreInputError(`the live tracks were refused at ${this.refused}, after their entries and physics had moved; open them again (${call} not made)`);\n }\n\n setAnimation(track: number, animation: string, options: MixOptions): void {\n this.live('setAnimation');\n const i = trackIndex(track, 'setAnimation');\n const loop = loopOf(options, 'setAnimation');\n const mix = finiteAtOrAbove0(options.mixDuration, 'mixDuration', 'setAnimation');\n const blend = blendOf(options, 'setAnimation');\n const entry = this.mixer.setAnimation(i, this.mixer.animation(animation), loop);\n entry.mixDuration = mix;\n entry.alpha = blend.alpha;\n entry.additive = blend.additive;\n }\n\n setEmptyAnimation(track: number, mixDuration: number): void {\n this.live('setEmptyAnimation');\n const i = trackIndex(track, 'setEmptyAnimation');\n const mix = finiteAtOrAbove0(mixDuration, 'mixDuration', 'setEmptyAnimation');\n const entry = this.mixer.setAnimation(i, EMPTY, false);\n entry.mixDuration = mix;\n entry.trackEnd = mix;\n }\n\n addAnimation(track: number, animation: string, options: QueueOptions): void {\n this.live('addAnimation');\n const i = trackIndex(track, 'addAnimation');\n const loop = loopOf(options, 'addAnimation');\n const mix = finiteAtOrAbove0(options.mixDuration, 'mixDuration', 'addAnimation');\n const delay = delayOf(options.delay, 'addAnimation');\n const blend = blendOf(options, 'addAnimation');\n const entry = this.mixer.addAnimation(i, this.mixer.animation(animation), loop, delay);\n this.mixer.setMixDuration(entry, mix, delay);\n entry.alpha = blend.alpha;\n entry.additive = blend.additive;\n }\n\n addEmptyAnimation(track: number, mixDuration: number, delay: number): void {\n this.live('addEmptyAnimation');\n const i = trackIndex(track, 'addEmptyAnimation');\n const mix = finiteAtOrAbove0(mixDuration, 'mixDuration', 'addEmptyAnimation');\n const d = delayOf(delay, 'addEmptyAnimation');\n const entry = this.mixer.addAnimation(i, EMPTY, false, d);\n if (d <= 0) entry.delay = Math.max(entry.delay + entry.mixDuration - mix, 0);\n entry.mixDuration = mix;\n entry.trackEnd = mix;\n }\n\n setAlpha(track: number, alpha: number): void {\n this.live('setAlpha');\n const i = trackIndex(track, 'setAlpha');\n const a = alphaValue(alpha, 'alpha', 'setAlpha');\n const e = this.mixer.tracks[i] ?? null;\n if (e === null) throw new CoreInputError(`the live tracks' setAlpha names track ${i}, which plays nothing — there is no entry to weigh`);\n e.alpha = a;\n }\n\n current(track: number): TrackEntryView | null {\n const e = this.mixer.tracks[trackIndex(track, 'current')] ?? null;\n if (e === null) return null;\n return { animation: e.anim.name, loop: e.loop, trackTime: e.trackTime, animationTime: animationTimeOf(e), duration: e.anim.duration, alpha: e.alpha, additive: e.additive };\n }\n\n start(): RawPose {\n this.live('start');\n if (this.started) throw new CoreInputError('the live tracks were started already; pose 0 is posed once');\n this.started = true;\n return this.guard('start', () => {\n if (this.reset === 'setup') return this.path.setupPose();\n return this.pose(0, true);\n });\n }\n\n step(dt: number): RawPose {\n const n = this.steps + 1;\n this.live(`step ${n}`);\n if (!this.started) throw new CoreInputError(`the live tracks' step ${n} comes before start(), which poses pose 0`);\n if (typeof dt !== 'number' || !Number.isFinite(dt) || dt < 0) throw new CoreInputError(`the live tracks' step ${n} is ${String(dt)}, not a finite time at or above 0`);\n return this.guard(`step ${n}`, () => {\n this.time += dt;\n const stage = this.plant.stage;\n if (stage !== undefined) stage.begin('timeline');\n this.mixer.update(dt);\n if (stage !== undefined) stage.end('timeline');\n const pose = this.pose(dt, false);\n this.steps = n;\n return pose;\n });\n }\n\n /** `f`, the state refused for good if it throws once anything has moved. */\n private guard(call: string, f: () => RawPose): RawPose {\n try {\n return f();\n } catch (err) {\n this.refused = `${call} (${err instanceof Error ? err.message : String(err)})`;\n throw err;\n }\n }\n\n /** One pose: the entries applied over the setup pose, then the raw pose path (`openRawTracksPath`). */\n private pose(dt: number, first: boolean): RawPose {\n const { doc, path } = this;\n const ctx = path.ctx;\n const before = ctx.time;\n ctx.time += this.clock === undefined ? dt : this.clock(dt);\n const stage = this.plant.stage;\n if (stage !== undefined) stage.begin('timeline');\n const pose = new Pose(doc, this.plant);\n const animationTime = this.mixer.apply(pose);\n const entry = this.mixer.tracks[0] ?? null;\n const adjustment = this.adjust === undefined ? undefined : {\n callback: this.adjust,\n context: { trackTime: entry?.trackTime ?? null, animation: entry?.anim.name ?? null, globalTime: this.time },\n };\n const mixed = new Map(doc.slots.map((s, k) => [s.name, { deform: pose.slots[k].deform, seen: pose.slots[k].seen }]));\n if (stage !== undefined) stage.end('timeline');\n return path.step(first, this.time, animationTime, {\n world: (sliders) => steppedLocalsWorld(doc, pose.bones, path.raw, sliders, { ctx, before, adjustment }),\n slots: (sliders, placeholders) => slotRowsFrom(doc, path.raw, sliders, placeholders, (_slot, _live): SlotBase => {\n const s = pose.slots[doc.slots.indexOf(_slot)];\n return { placeholder: s.placeholder, light: s.light, dark: s.dark };\n }),\n drawOrder: [],\n at: 0,\n sample: null,\n mixed,\n events: () => pose.events,\n });\n }\n}\n","/**\n * The draw's last input the core lacked (issue #967, step 3c of issue #380):\n * each drawn attachment's atlas PAGE and its PAGE UVs — the oracle's `uvs`\n * block, what `src/render.ts`'s `pieceOf` reads off `sequence.regions[index]`\n * and `sequence.getUVs(index)` — and `MeshAttachment.computeUVs`'s job, the\n * mapping texture substitution calls, as pure functions.\n *\n * The page layout is not a model record (`ModelAtlasRect`'s 🔸 in\n * `src/model.ts`: the page, `x`, `y` and `rotate` are the packer's\n * arrangement, not the drawing). It reaches these rules as a lookup\n * (`UvLookup`), so nothing here links the runtime or opens a file: since\n * issue #1016 from the document's own `pages` section, which `build` spells\n * from the atlas it writes (`documentPageLookup` below); for a\n * `rigc-compiled/1` document, which has none, from the atlas beside it, read\n * by rigc's own reader (`parseAtlasText` and `atlasRegionLookup` in\n * `src/atlas.ts`).\n *\n * ## How every rule below was fixed\n *\n * By loading hand-written atlases and skeletons through spine-core 4.3.13\n * (`TextureAtlas`, `AtlasAttachmentLoader`, `SkeletonJson`) and reading what\n * the loaded attachments hold — `sequence.getUVs(i)`, `sequence.regions[i]`,\n * `region.page.name` — and what `MeshAttachment.computeUVs` writes, then\n * comparing a formula over the atlas's own numbers, bit for bit (not on the\n * oracle's grid). The runtime's source was not read. Regions were random:\n * pages of power-of-two and other sizes, one to three pages, `bounds` anywhere\n * on the page, 70% trimmed (`offsets` other than `0, 0, width, height`), and\n * `rotate` spelled `0`, `90`, `180`, `270`, `true`, `false` and, for the\n * branch rules, `45`, `-90`, `360` and `450`; mesh and art UVs spelled with\n * five non-float32 decimals, some outside `[0, 1]`.\n *\n * ### The region's own numbers\n *\n * With `W, H` the page's `size`, the region's `u = x/W`, `v = y/H`, and its far\n * corner `u2 = (x + width)/W`, `v2 = (y + height)/H` — with `width` and\n * `height` exchanged at `rotate: 90` (and `true`) ONLY. 1,500 of 1,500\n * regions, as doubles; exchanged at 270 as well missed 262, never exchanged\n * 484. (That 270 is not exchanged is the runtime's, and the reason\n * `pageFootprint` in `src/atlas.ts` derives the page rectangle rather than\n * reading these two numbers.)\n *\n * ### A region attachment's four UVs\n *\n * In the corner order of its world vertices (bottom-left, upper-left,\n * upper-right, bottom-right — `./vertices.ts`): at `degrees === 90`\n * `(u2, v2) (u, v2) (u, v) (u2, v)`, at every other value — 0, 180, 270 and\n * the odd spellings alike — `(u, v2) (u, v) (u2, v) (u2, v2)`; each held as\n * float32. 1,500 of 1,500 through `Math.fround`; as doubles, 575 missed. The\n * readings rejected, on the same 1,500:\n *\n * | reading | misses |\n * | --- | ---: |\n * | 270 turned as 90 over a transposed rectangle | 262 |\n * | 90's corners the other way round, `(u, v) (u2, v) (u2, v2) (u, v2)` | 487 |\n * | 180 turned, `(u2, v) (u2, v2) (u, v2) (u, v)` | 260 |\n * | the trim inset into the UVs | 724 |\n *\n * The trim does not enter a region's UVs: it enters its corners\n * (`regionCorners` in `./vertices.ts`, through `ModelAtlasRect`).\n *\n * ### A mesh's page UVs — `MeshAttachment.computeUVs`\n *\n * From the attachment's own UVs `(s, t)` — art space, over the untrimmed\n * drawing — per `degrees`, in doubles, starting from `u = x/W`, `v = y/H`:\n *\n * | degrees | `u −=` | `v −=` | span `w, h` | `(u′, v′)` |\n * | --- | --- | --- | --- | --- |\n * | 90 | `(oh − oy − height)/W` | `(ow − ox − width)/H` | `oh/W, ow/H` | `u + t·w, v + (1 − s)·h` |\n * | 180 | `(ow − ox − width)/W` | `oy/H` | `ow/W, oh/H` | `u + (1 − s)·w, v + (1 − t)·h` |\n * | 270 | `oy/W` | `ox/H` | `oh/W, ow/H` | `u + (1 − t)·w, v + s·h` |\n * | any other | `ox/W` | `(oh − oy − height)/H` | `ow/W, oh/H` | `u + s·w, v + t·h` |\n *\n * (`ox, oy, ow, oh` the region's `offsetX, offsetY, originalWidth,\n * originalHeight`; `width, height` its `bounds` size.) The subtraction is its\n * own step: called into a plain array, the rule read 6,000 of 6,000 calls bit\n * for bit in doubles, while one fraction `(x − ox)/W` missed 936 and texels\n * first, `(x − ox + s·ow)/W`, 2,227. Into a plain array the function writes\n * these doubles — 4,000 of 4,000 calls wrote a value that is not a float32 —\n * and what an attachment HOLDS is each through `Math.fround`, because its\n * array is a `Float32Array`: 1,500 of 1,500 meshes, and `computeUVs` over the\n * attachment's region and own UVs reproduced the held array on all 1,500. The\n * rule through `Math.fround` held on 4,000 direct calls into a `Float32Array`,\n * 400 per spelling, the odd spellings taking the last row.\n *\n * ⚠️ **The mesh's own UVs are read as the doubles the text spells, not as\n * float32.** Reading them through `Math.fround` first missed 311 of 1,500\n * meshes (worst 4.8e-7, one float32 step of a UV near 1); every intermediate\n * in float32 missed 844. So `computeUvs` takes the model's `uvs` as they are.\n *\n * ### Which region, on which page\n *\n * - A region or mesh draws the atlas region named by its `path`, else its\n * name — the oracle's `path` cell (`shownRow` in `./index.ts`). The first\n * region of that name in the file wins (two regions named alike, the first\n * drawn), and the name is compared as the atlas line spells it: a region\n * line `art ` is not found as `art`, while CRLF line ends are not part of a\n * name (`parseAtlasText` splits on them).\n * - A **sequence**'s frame `i` draws `path + (start + i)`, the number padded\n * with zeros to `digits` (`padStart`): `start` 1 and `digits` 0 when\n * unstated — a three-frame `x` drew `x1, x2, x3`; `start 8, digits 0` drew\n * `x8, x9, x10`; `start 99, digits 1` `x99, x100`; `start 5, digits 4`\n * `x0005, x0006`. The atlas's own `index:` field is not how a frame is\n * found: regions named `seq` with `index: 1` and `2` loaded as `Region not\n * found in atlas: seq1`. Each frame draws on its own region's page: a\n * four-frame series over two pages drew frames 0–1 on the first and 2–3 on\n * the second, a mesh's frames alike.\n * - The frame drawn is the one the pose shows (`./deform.ts`'s sequence rule,\n * measured there through a region's corners), or the sequence's `setup` (0\n * unstated) where no timeline set one.\n * - A **linked mesh** draws its OWN `path`'s region (and its own sequence's\n * frames — a link stating one drew `l1, l2, l3` from setup frame 2 whatever\n * its source stated; a link stating none drew its own path) over its\n * SOURCE's UVs: a link on page `a.png` whose source sat on `b.png` drew\n * `a.png`, and its uvs were `computeUVs` of its own region over the\n * source's `regionUVs`.\n * - The page cell is the page's name as `parseAtlasText` trims it — the\n * runtime's `page.name` for a page line ` p.png ` read `p.png`.\n *\n * ## What is posed, and what is left out\n *\n * Rows in the pose's draw order, one per slot showing a region, a mesh or a\n * linked mesh — the slots the `attachments` block lists, whatever their bone\n * or alpha. Which record a slot shows and the frame its series is at are the\n * ones `./deform.ts`'s `attachmentStates` computes for the same pose, from the\n * placeholders the sample's own timelines leave (`posedSlots`) and the\n * sliders' applications (`posedBoneWorld`); at setup, from the setup\n * placeholders and the sliders applied to the setup pose. That repeats the\n * walk `poseSetup` and `poseAnimations` make, because neither returns the\n * frame (issue #966 retains it in the raw entry); the gate holds the two\n * walks to one answer by comparing both against the runtime.\n *\n * A region the atlas does not have is refused by name (`CoreInputError`):\n * spine-core refuses to load the same pair. The block is left out, with the\n * reason, where what a slot shows is not posed — the slots or the draw order\n * absent — and where a linked mesh stating its own sequence is stepped by a\n * sequence timeline counted over its source's frames, a case never measured.\n *\n * ## Purity\n *\n * As the rest of the core: nothing from the Spine runtime package, nothing\n * from `src/transform.ts`, no clock, no randomness, no I/O.\n */\nimport { activeBones, constraintRecords, CoreInputError, shownAttachment, type CompiledDocument, type CoreAnimation } from './index.ts';\nimport { posedBoneWorld, posedSlots } from './animation.ts';\nimport { applyConstraints } from './constraints.ts';\nimport type { SliderApplication } from './constraints_slider.ts';\nimport { attachmentStates } from './deform.ts';\nimport type { ShownGeometry } from './vertices.ts';\nimport type { ModelPage, ModelPageRegion } from '../model.ts';\nimport { worldTransforms } from './world.ts';\n\n/** A region as these rules read it — `AtlasRegion` in `src/atlas.ts` is one, and so is spine-core's `TextureAtlasRegion`. */\nexport interface UvRegion {\n x: number;\n y: number;\n width: number;\n height: number;\n offsetX: number;\n offsetY: number;\n originalWidth: number;\n originalHeight: number;\n degrees: number;\n}\n\n/** A page as these rules read it: its trimmed name and its `size`. */\nexport interface UvPage {\n name: string;\n width: number;\n height: number;\n}\n\n/** The region an atlas draws under a name, and its page — the first of that name, as the header states; `null` when there is none. */\nexport type UvLookup = (name: string) => { page: UvPage; region: UvRegion } | null;\n\n/**\n * The lookup over a document's `pages` section (issue #1016): the first region\n * of a name in file order, pages in order and regions in each page's order —\n * the order `pagesOfAtlas` in `src/model.ts` copies from the atlas, so this is\n * `atlasRegionLookup` over the same text, with no atlas read. The name is\n * compared as stored, untrimmed, as the header's *Which region* states.\n */\nexport function documentPageLookup(pages: readonly ModelPage[]): (name: string) => { page: UvPage; region: ModelPageRegion } | null {\n const first = new Map<string, { page: UvPage; region: ModelPageRegion }>();\n for (const page of pages) {\n const at: UvPage = { name: page.name, width: page.width, height: page.height };\n for (const region of page.regions) if (!first.has(region.name)) first.set(region.name, { page: at, region });\n }\n return (name) => first.get(name) ?? null;\n}\n\n/**\n * The readings the header's tables rejected, each a switch — what the core\n * suite's `CU` plants pass to show the gate names it. The functions below with\n * none set are the rules measured; nothing but a plant sets one.\n */\nexport interface UvReading {\n /** A region at 90 in the other corner order, `(u, v) (u2, v) (u2, v2) (u, v2)` — the rotation flipped. */\n rotationFlipped?: boolean;\n /** A region at 270 turned as one at 90, over a transposed rectangle; a mesh at 270 mapped by 90's `(u + t·w, v + (1 − s)·h)`. */\n turned270?: boolean;\n /** A mesh's page UVs with the trim offsets dropped (`ox = oy = 0`, the original size the kept one). */\n trimDropped?: boolean;\n /** A mesh's own UVs read through `Math.fround` first. */\n artAsFloat32?: boolean;\n}\n\n/** A region attachment's four page UVs as the runtime holds them — the header's rule, in the world corners' order. */\nexport function regionPageUvs(region: UvRegion, page: UvPage, reading: UvReading = {}): number[] {\n const turned = region.degrees === 90 || (reading.turned270 === true && region.degrees === 270);\n const u = region.x / page.width;\n const v = region.y / page.height;\n const u2 = (region.x + (turned ? region.height : region.width)) / page.width;\n const v2 = (region.y + (turned ? region.width : region.height)) / page.height;\n let out: number[];\n if (turned) out = reading.rotationFlipped === true ? [u, v, u2, v, u2, v2, u, v2] : [u2, v2, u, v2, u, v, u2, v];\n else out = [u, v2, u, v, u2, v, u2, v2];\n return out.map(Math.fround);\n}\n\n/**\n * `MeshAttachment.computeUVs`: art-space UVs over the untrimmed drawing mapped\n * onto `region` of `page`, in doubles — the header's table. What texture\n * substitution writes into its plain array; an attachment holds each value\n * through `Math.fround` (`meshPageUvs`).\n */\nexport function computeUvs(region: UvRegion, page: UvPage, art: readonly number[], reading: UvReading = {}): number[] {\n const dropped = reading.trimDropped === true;\n const ox = dropped ? 0 : region.offsetX;\n const oy = dropped ? 0 : region.offsetY;\n const ow = dropped ? region.width : region.originalWidth;\n const oh = dropped ? region.height : region.originalHeight;\n const W = page.width;\n const H = page.height;\n const s = reading.artAsFloat32 === true ? art.map(Math.fround) : art;\n let u = region.x / W;\n let v = region.y / H;\n const out: number[] = [];\n switch (region.degrees) {\n case 90: {\n u -= (oh - oy - region.height) / W;\n v -= (ow - ox - region.width) / H;\n const w = oh / W;\n const h = ow / H;\n for (let i = 0; i + 1 < s.length; i += 2) out.push(u + s[i + 1] * w, v + (1 - s[i]) * h);\n return out;\n }\n case 180: {\n u -= (ow - ox - region.width) / W;\n v -= oy / H;\n const w = ow / W;\n const h = oh / H;\n for (let i = 0; i + 1 < s.length; i += 2) out.push(u + (1 - s[i]) * w, v + (1 - s[i + 1]) * h);\n return out;\n }\n case 270: {\n u -= oy / W;\n v -= ox / H;\n const w = oh / W;\n const h = ow / H;\n if (reading.turned270 === true) for (let i = 0; i + 1 < s.length; i += 2) out.push(u + s[i + 1] * w, v + (1 - s[i]) * h);\n else for (let i = 0; i + 1 < s.length; i += 2) out.push(u + (1 - s[i + 1]) * w, v + s[i] * h);\n return out;\n }\n default: {\n u -= ox / W;\n v -= (oh - oy - region.height) / H;\n const w = ow / W;\n const h = oh / H;\n for (let i = 0; i + 1 < s.length; i += 2) out.push(u + s[i] * w, v + s[i + 1] * h);\n return out;\n }\n }\n}\n\n/** A mesh's page UVs as the attachment holds them: `computeUvs`, each through `Math.fround`. */\nexport function meshPageUvs(region: UvRegion, page: UvPage, art: readonly number[], reading: UvReading = {}): number[] {\n return computeUvs(region, page, art, reading).map(Math.fround);\n}\n\n/** A record's series, as the parser reads the four fields: `start` 1, `digits` 0 and `setup` 0 when unstated. */\nexport interface UvSequence {\n count: number;\n start: number;\n digits: number;\n setup: number;\n}\n\n/** Every record's series, by `skin/slot/placeholder` — `readUvSequences`. */\nexport type UvSequences = ReadonlyMap<string, UvSequence>;\n\n/** The region a series' frame draws: `path + (start + frame)`, padded with zeros to `digits` — the header's rule. */\nexport function frameRegionName(path: string, sequence: UvSequence, frame: number): string {\n return path + String(sequence.start + frame).padStart(sequence.digits, '0');\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nconst whole = (v: unknown, min: number): v is number => typeof v === 'number' && Number.isInteger(v) && v >= min;\n\n/**\n * Every record's `sequence` in a `rigc-compiled/1` document, as the parser\n * reads it — `readModel` keeps a series' count and nothing else of it, and a\n * frame's region name needs `start` and `digits`. Refuses, naming the path, a\n * field that is not a whole number (`count` of at least 1, the others of at\n * least 0) or a `setup` that is not one of the frames.\n */\nexport function readUvSequences(document: unknown): UvSequences {\n const out = new Map<string, UvSequence>();\n const problems: string[] = [];\n const skins = isRecord(document) && Array.isArray(document.skins) ? document.skins : [];\n skins.forEach((skin: unknown, k: number) => {\n if (!isRecord(skin) || typeof skin.name !== 'string' || !isRecord(skin.attachments)) return;\n for (const [slot, table] of Object.entries(skin.attachments)) {\n if (!isRecord(table)) continue;\n for (const [placeholder, record] of Object.entries(table)) {\n if (!isRecord(record) || record.sequence === undefined) continue;\n const where = `skins[${k}] \"${skin.name}\".attachments[\"${slot}\"][\"${placeholder}\"].sequence`;\n const seq = record.sequence;\n if (!isRecord(seq)) {\n problems.push(`${where} is not an object`);\n continue;\n }\n const before = problems.length;\n if (!whole(seq.count, 1)) problems.push(`${where}: count is ${JSON.stringify(seq.count) ?? 'absent'}, not a whole number of at least 1`);\n for (const key of ['start', 'digits', 'setup'] as const) if (seq[key] !== undefined && !whole(seq[key], 0)) problems.push(`${where}: ${key} is ${JSON.stringify(seq[key])}, not a whole number of at least 0`);\n if (problems.length !== before) continue;\n const count = seq.count as number;\n const setup = (seq.setup as number | undefined) ?? 0;\n if (setup >= count) {\n problems.push(`${where}: setup is ${setup}, and a ${count}-frame series has frames 0 to ${count - 1}`);\n continue;\n }\n out.set(`${skin.name}/${slot}/${placeholder}`, { count, start: (seq.start as number | undefined) ?? 1, digits: (seq.digits as number | undefined) ?? 0, setup });\n }\n }\n });\n if (problems.length > 0) throw new CoreInputError(`the model document's sequences: ${problems.join('; ')}`);\n return out;\n}\n\n/** What `poseUvs` reads besides the pose: the atlas lookup, the document's series, and a plant's reading. */\nexport interface UvSource {\n lookup: UvLookup;\n sequences: UvSequences;\n reading?: UvReading;\n}\n\n/** One row of `uvs`: `[slot, attachment, page, uvs]`, the oracle's row. */\nexport type CoreUvRow = [string, string, string, Array<number | null>];\n\n/**\n * Each slot's shown record and its series' frame at the setup pose — what\n * `poseSetup` hands `poseGeometry`: the setup placeholders, and the sliders\n * applied to the setup bones (`applyConstraints`), each slider's attachment,\n * deform and sequence keys applied in order by `attachmentStates`.\n */\nexport function shownAtSetup(doc: CompiledDocument): { shown: ShownGeometry[]; why: string[] } {\n const active = activeBones(doc);\n const applied: SliderApplication[] = [];\n applyConstraints(doc.bones, worldTransforms(doc.bones, active), active, constraintRecords(doc), null, applied);\n const placeholders = new Map(doc.slots.map((s) => [s.name, s.setup]));\n return attachmentStates(doc, shownAttachment, placeholders, null, applied);\n}\n\n/**\n * Each slot's shown record and its series' frame at time `t` of `anim` — what\n * `poseAnimations` hands `poseGeometry` under `--physics none`: the sliders\n * `posedBoneWorld` applies at `t`, the placeholders the sample's own\n * timelines leave (`posedSlots`), then `attachmentStates`.\n */\nexport function shownAtSample(doc: CompiledDocument, anim: CoreAnimation, t: number): { shown: ShownGeometry[]; why: string[] } {\n const sliders: SliderApplication[] = [];\n // The bones are posed for what the sliders apply, and only a slider constraint applies one (`applySlider`): with none, the list stays empty and the pose would be read for nothing (issue #1134).\n if (doc.constraints.some((c) => c.kind === 'slider')) posedBoneWorld(doc, anim.timelines, t, {}, anim.constraints, sliders);\n const placeholders = new Map<string, string | null>();\n posedSlots(doc, anim.timelines, t, {}, sliders, placeholders);\n return attachmentStates(doc, shownAttachment, placeholders, { timelines: anim.timelines, t }, sliders);\n}\n\n/** One drawn attachment resolved to its atlas region: what `poseUvs` maps, and what a census reads. */\nexport interface DrawnRegion {\n slot: string;\n /** The attachment's name — the row's second cell. */\n name: string;\n kind: 'region' | 'mesh' | 'linkedmesh';\n /** The region name drawn: the path, with the frame's number for a series. */\n region: string;\n /** The series' frame drawn, or `null` for a record with no series. */\n frame: number | null;\n found: { page: UvPage; region: UvRegion };\n /** The attachment's own UVs for a mesh — a linked mesh's source's — or `null` for a region. */\n art: readonly number[] | null;\n}\n\n/**\n * Every slot of `order` showing a region, a mesh or a linked mesh, resolved to\n * the atlas region it draws — the header's *Which region, on which page* — or\n * why the pose is not posed. A region the atlas lacks is refused by name.\n */\nexport function drawnRegions(doc: CompiledDocument, shown: readonly ShownGeometry[], order: readonly string[], source: UvSource): { drawn: DrawnRegion[] | null; why: string | null } {\n const bySlot = new Map(shown.map((s) => [s.slot, s]));\n const drawn: DrawnRegion[] = [];\n const unmeasured: string[] = [];\n for (const slot of order) {\n const s = bySlot.get(slot);\n if (s === undefined) continue;\n const g = s.geometry;\n if (g.kind !== 'region' && g.kind !== 'mesh' && g.kind !== 'linkedmesh') continue;\n const record = doc.skins.find((k) => k.name === s.skin)?.attachments[s.slot]?.[s.placeholder];\n if (record === undefined) throw new CoreInputError(`slot \"${s.slot}\": skin \"${s.skin}\" files no record under placeholder \"${s.placeholder}\" (readModel refuses it first)`);\n const path = record.path ?? s.name;\n const sequence = source.sequences.get(`${s.skin}/${s.slot}/${s.placeholder}`);\n if (g.kind === 'linkedmesh' && sequence !== undefined && s.frame !== undefined) {\n const sourceCount = doc.skins.find((k) => k.name === g.skin)?.attachments[g.slot]?.[g.source]?.sequenceCount;\n if (sourceCount !== sequence.count) {\n unmeasured.push(`slot \"${s.slot}\" shows linked mesh \"${s.name}\", whose own ${sequence.count}-frame series a sequence timeline steps over its source's ${sourceCount ?? 'unstated'} frame(s)`);\n continue;\n }\n }\n const frame = sequence === undefined ? null : (s.frame ?? sequence.setup);\n const name = sequence === undefined || frame === null ? path : frameRegionName(path, sequence, frame);\n const found = source.lookup(name);\n if (found === null) {\n throw new CoreInputError(\n `slot \"${s.slot}\" shows \"${s.name}\", which draws atlas region \"${name}\"${frame === null ? '' : ` (frame ${frame} of its series over \"${path}\")`}, and the atlas has no region of that name — spine-core refuses to load the pair (\"Region not found in atlas\")`,\n );\n }\n let art: readonly number[] | null = null;\n if (g.kind === 'mesh') art = g.uvs;\n else if (g.kind === 'linkedmesh') {\n // A linked mesh draws its source's UVs over its own region (the header's *Which region*).\n const from = doc.skins.find((k) => k.name === g.skin)?.attachments[g.slot]?.[g.source]?.geometry;\n if (from?.kind !== 'mesh') throw new CoreInputError(`slot \"${s.slot}\": the linked mesh's source \"${g.source}\" carries no uvs (readModel refuses it first)`);\n art = from.uvs;\n }\n drawn.push({ slot: s.slot, name: s.name, kind: g.kind, region: name, frame, found, art });\n }\n if (unmeasured.length > 0) return { drawn: null, why: `${unmeasured.join('; ')} — which of the two counts the runtime steps it over was not measured` };\n return { drawn, why: null };\n}\n\n/**\n * The `uvs` rows of one pose: `shown` (from `shownAtSetup`/`shownAtSample`) in\n * `order`, the pose's draw order, every number through `round` (the oracle's,\n * `gridRound`) — or why the block is left out. A region the atlas lacks is\n * refused by name.\n */\nexport function poseUvs(doc: CompiledDocument, shown: readonly ShownGeometry[], order: readonly string[], source: UvSource, round: (v: number) => number | null): { rows: CoreUvRow[] | null; why: string | null } {\n const reading = source.reading ?? {};\n const { drawn, why } = drawnRegions(doc, shown, order, source);\n if (drawn === null) return { rows: null, why };\n const rows = drawn.map((d): CoreUvRow => {\n const uvs = d.art === null ? regionPageUvs(d.found.region, d.found.page, reading) : meshPageUvs(d.found.region, d.found.page, d.art, reading);\n return [d.slot, d.name, d.found.page.name, uvs.map(round)];\n });\n return { rows, why: null };\n}\n\n/** Why a document's `uvs` blocks are not posed under the stepped phase, or null: a slider keying a slot's attachment or a series — its time is read off bones the step moves, and this walk poses them unstepped. */\nexport function steppedUvsWhy(doc: CompiledDocument): string | null {\n const keyed = doc.constraints.flatMap((c) => {\n if (c.kind !== 'slider') return [];\n const anim = doc.animations.find((a) => a.name === c.animation);\n if (anim === undefined) return [];\n const switches = anim.timelines.slots.some((sl) => sl.timelines.some((tl) => tl.kind === 'attachment'));\n const frames = anim.timelines.attachments.some((a) => a.sequence !== null);\n return switches || frames ? [`slider \"${c.name}\" applies animation \"${c.animation}\", which keys ${switches ? 'a slot\\'s attachment' : 'a sequence'}`] : [];\n });\n return keyed.length === 0 ? null : `${keyed.join('; ')} — under --physics step its time is read off stepped bones, and the uvs walk poses the sliders unstepped`;\n}\n","import type { LiveFrame } from './liveFrame.js';\nimport type { PosedFrame } from './posedFrame.js';\n\n/** @internal Renderer association; contains no poser dependency. */\nexport const liveDrawings = new WeakMap<object, PosedFrame>();\n\n/** @internal Resolve a borrowed view to its preallocated renderer facade. */\nexport function renderFrameOf(frame: PosedFrame | LiveFrame): PosedFrame {\n if ('order' in frame) return frame;\n // Reading the generation makes a checked stale lease fail before drawing.\n void frame.generation;\n const drawing = liveDrawings.get(frame);\n if (!drawing) throw new Error('LIVE_FRAME_SOURCE: renderer needs a liveFrame() borrowed from a player');\n return drawing;\n}\n\n","/**\n * The one forced layout both renderers share: how many device pixels one of\n * the root's CSS pixels covers on screen, read off a throwaway box.\n *\n * A renderer rasters at `world × pixelRatio` in the root's own coordinates,\n * so a `transform: scale(z)` on an ancestor — how a pan/zoom stage is built —\n * oversamples by 1/z² in backing pixels unless the zoom is folded into the\n * ratio. Neither renderer measures this on its own: it is a layout read, and\n * there is no per-frame layout read anywhere in this library. The caller\n * invokes `syncPixelRatio()` when a zoom or a resize settles.\n */\n\n/** Edge length of the throwaway box the root is measured with. */\nconst SCALE_PROBE_PX = 100;\n/**\n * Relative change below which the ratio is left alone. Layout reads are\n * quantized (1/64 px in Blink), so a 100 px probe carries ~0.016% of\n * measurement noise — 6× under this band, which in turn is 10× under the\n * smallest zoom step a UI realistically takes (1%). Inside the band the\n * sampling error is worth ~0.2% of backing pixels; outside it, a rewrite of\n * `pixelRatio` recreates every canvas's GPU surface.\n */\nconst PIXEL_RATIO_DEADBAND = 1e-3;\n\n/**\n * Measures `root`'s effective on-screen scale once and returns the ratio now\n * in effect: `devicePixelRatio × scale` when that differs from `current` by\n * more than the deadband, else `current` unchanged. A root that is not laid\n * out (a `display: none` ancestor, a detached root) measures nothing, so\n * nothing is decided and `current` comes back. Appends a hidden box to the\n * root, reads its rect, removes it — the root's children are the same\n * elements in the same order on both sides of the call.\n */\nexport function syncedPixelRatio(root: HTMLElement, current: number): number {\n const probe = document.createElement('div');\n probe.style.position = 'absolute';\n probe.style.left = '0';\n probe.style.top = '0';\n probe.style.width = `${SCALE_PROBE_PX}px`;\n probe.style.height = `${SCALE_PROBE_PX}px`;\n probe.style.visibility = 'hidden';\n probe.style.pointerEvents = 'none';\n root.appendChild(probe);\n let width = 0;\n let height = 0;\n try {\n const rect = probe.getBoundingClientRect();\n width = rect.width;\n height = rect.height;\n } finally {\n probe.remove();\n }\n\n const scale = Math.max(width, height) / SCALE_PROBE_PX;\n if (!(scale > 0)) return current;\n\n const dpr = typeof devicePixelRatio === 'number' ? devicePixelRatio : 1;\n const next = dpr * scale;\n if (current > 0 && Math.abs(next - current) < current * PIXEL_RATIO_DEADBAND) return current;\n return next;\n}\n","/**\n * Where one region sits on its page — the fields of a model document's\n * `pages[].regions[]` entry (`ModelPageRegion` in rig-c) that a cut reads.\n * `width` and `height` are the artwork's own, unrotated: a region packed at\n * `degrees: 90` occupies a `height × width` rect on the page.\n */\nexport interface PageRegion {\n name: string;\n x: number;\n y: number;\n width: number;\n height: number;\n degrees: number;\n}\n\n/**\n * One page of the layout `unpackRegions` cuts from — a model document's\n * `pages[]` entry. `width`/`height` are the page's *declared* size (the atlas\n * `size:` line the build wrote), not necessarily the image's.\n */\nexport interface PageLayout {\n name: string;\n width: number;\n height: number;\n /** Whether the page's texels are premultiplied by their alpha (absent: false). */\n pma?: boolean;\n regions: readonly PageRegion[];\n}\n\n/** One region with its page, in the order the layout lists them. */\ninterface PlacedRegion {\n region: PageRegion;\n page: PageLayout;\n}\n\nexport interface RegionImage {\n /**\n * URL of the unpacked (rotation-restored) region pixels: a blob URL minted\n * by unpackRegions, the page image URL itself when the region covers its\n * whole page, or anything the caller put there in a hand-built map.\n */\n url: string;\n /**\n * Unpacked width in **atlas units** — the region's own `width`, not the\n * bitmap's pixel width. The two differ whenever the page image ships at a\n * resolution its atlas `size:` line does not mention (see cutRegion): a\n * half-resolution page yields a bitmap half this wide. This is the layout\n * box the rigid tier writes onto its `<img>` and the denominator of the CSS\n * matrix it builds, so it stays in the frame the skeleton is authored in\n * and the browser scales the bitmap into it — the same thing a GPU does\n * when it samples normalized UVs from a texture of any resolution.\n */\n width: number;\n /** Unpacked height in atlas units — see `width`. */\n height: number;\n}\n\n/** One region's page-backed source, without an encoded per-region URL. */\nexport interface AtlasRegion {\n readonly page: PageLayout;\n readonly region: PageRegion;\n readonly image: HTMLImageElement;\n}\n\n/** Maps atlas entries in layout order; duplicate names keep the last entry. */\nexport function createAtlasRegions(\n pages: readonly PageLayout[],\n images: ReadonlyMap<string, HTMLImageElement>,\n): Map<string, AtlasRegion> {\n const result = new Map<string, AtlasRegion>();\n for (const page of pages) {\n const image = images.get(page.name);\n if (!image) throw new Error(`Missing page image: ${page.name}`);\n for (const region of page.regions) result.set(region.name, { page, region, image });\n }\n return result;\n}\n\n/** @internal Paints native region pixels without encoding them. */\nexport function drawAtlasRegion(canvas: HTMLCanvasElement, entry: AtlasRegion, ratio?: number): void {\n const plan = planCut(entry, entry.image);\n paintRegion(canvas, entry, entry.image, plan, ratio);\n}\n\n/**\n * Blob URLs minted by unpackRegions, i.e. the ones this module owns.\n *\n * Ownership has to be tracked because a RegionImage map is not necessarily\n * ours: callers may hand the renderer a map built from their own URLs (loose\n * part PNGs need no unpacking at all). revokeRegions() therefore frees only\n * what is listed here and leaves caller-owned URLs untouched.\n */\nconst ownedUrls = new Set<string>();\n\n/** Revokes `url` if unpackRegions minted it. Idempotent, caller-safe. */\nfunction revokeOwned(url: string): void {\n if (!ownedUrls.delete(url)) return;\n URL.revokeObjectURL(url);\n}\n\n/**\n * Page pixels in the alpha convention a DOM/canvas2d consumer needs: the page\n * image itself, or the derived canvas below when the page is premultiplied.\n */\nexport type PageSource = HTMLImageElement | HTMLCanvasElement;\n\n/**\n * Straight-alpha derivations of `pma: true` page images, one per image.\n *\n * Spine's texture packer premultiplies by default, and an atlas says so with a\n * `pma: true` page line: the file's RGB is already multiplied by its alpha. The\n * DOM and canvas 2D have no such mode — an <img> and `drawImage` composite\n * straight alpha by definition, so they multiply by alpha again and every\n * semi-transparent texel comes out darker than it was authored (#37). Both\n * consumers of that convention here — the region cuts below and the canvas2d\n * mesh raster in DomRenderer — therefore read this derivation instead of\n * the page, and it is *shared*: deriving per consumer would pay for the same\n * page once per renderer and once again for the load.\n *\n * (The GL mesh backend needs no derivation. It consumes premultiplied texels by\n * construction, so it just skips `UNPACK_PREMULTIPLY_ALPHA_WEBGL` at upload —\n * lossless, and the reason the two backends differ at all on such a page.)\n *\n * Weak by the page image, exactly like the GL texture cache: this package never\n * pins the caller's image, and a page the caller drops takes its derivation\n * with it. So nothing has to be freed by hand and `dispose()` stays out of it —\n * the ownership boundary is the same one `revokeRegions` respects.\n *\n * **What it costs while alive:** one page-sized canvas per `pma` page image\n * (4 bytes/px — 1 MiB for a 1024×256 page, 16 MiB for a 2048×2048 one), held\n * for as long as the caller holds the page. It is deliberately *not* charged to\n * the cut-backing budget below: that budget bounds the canvases in flight\n * during a load, a peak that appears and drains, while this sits alongside the\n * decoded page itself for the page's whole life — the same category as the\n * decoded pages the budget already documents as resident throughout.\n */\nconst straightAlphaPages = new WeakMap<HTMLImageElement, PageSource>();\n\n/** Derivations performed since load — see straightAlphaDerivations(). */\nlet derivationCount = 0;\n\n/**\n * How many straight-alpha page derivations have been built in this document.\n *\n * Deterministic (no GC in the path) and monotonic, so a test reads it before\n * and after and asserts the *difference*. Exported for the tests only — it is\n * not re-exported from index.ts and the `exports` map denies deep imports, so\n * it is not package API. (The same arrangement as `liveTextureCount` on the GL\n * blitter, and for the same reason: a cache that works is invisible.)\n */\nexport function straightAlphaDerivations(): number {\n return derivationCount;\n}\n\n/**\n * The page as a straight-alpha source: the image itself when `pma` is false,\n * otherwise its (cached) un-premultiplied derivation.\n *\n * `rgb = round(rgb * 255 / a)`, clamped, with `a === 0` left at (0,0,0,0) —\n * there is no colour to recover from a fully transparent texel.\n *\n * **Precision.** The division is done in 8 bits and cannot be done anywhere\n * else: a 2D canvas stores premultiplied colour, so `getImageData` hands back\n * `round(round(u * a / 255) * 255 / a)` for a file value `u`, already quantized\n * by the read (measured on both engines: put→get moves a value by up to 127 at\n * a = 1). The colour a low-alpha texel composites to is therefore off by at\n * most ~min(a, 127.5/a + 0.5) of 255 — nothing at a = 255 or a = 0, ≤ 1 above\n * a = 128, worst ~12 around a = 11, and bounded by `a` below that. Writing the\n * values back is exact, not a second premultiply: the canvas quantizer is\n * idempotent, so putting a value that came out of it stores it unchanged\n * (measured: a second round trip moves nothing on either engine). The remaining\n * error is one-way rounding on near-invisible texels, against a defect that\n * darkened every semi-transparent texel by up to 59 luma.\n *\n * A page image that cannot be read — no 2D context, or a cross-origin image\n * without CORS, where `getImageData` throws — falls back to the page itself and\n * caches *that*: the colour is then as wrong as it is today, but it happens\n * once per image instead of once per frame, and no frame throws. (The cut path\n * already fails on such an image at `toBlob`, so only the mesh tier can get\n * here.) An image that has not decoded yet is left uncached, so the derivation\n * happens once it has.\n */\nexport function straightAlphaSource(page: HTMLImageElement, pma: boolean): PageSource {\n if (!pma) return page;\n const cached = straightAlphaPages.get(page);\n if (cached) return cached;\n\n const width = page.naturalWidth;\n const height = page.naturalHeight;\n // Nothing to read yet: decide later rather than caching an empty canvas.\n if (!(width > 0) || !(height > 0)) return page;\n\n const derived = unpremultiply(page, width, height);\n straightAlphaPages.set(page, derived);\n if (derived !== page) derivationCount++;\n return derived;\n}\n\n/** The pixel pass behind straightAlphaSource; `page` back on any read failure. */\nfunction unpremultiply(page: HTMLImageElement, width: number, height: number): PageSource {\n const canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n // No willReadFrequently: this reads once and is then a drawImage *source*\n // for the rest of its life, which wants the accelerated surface.\n const ctx = canvas.getContext('2d');\n if (!ctx) return page;\n ctx.drawImage(page, 0, 0);\n let pixels: ImageData;\n try {\n pixels = ctx.getImageData(0, 0, width, height);\n } catch {\n // Tainted canvas (cross-origin page image, no CORS).\n return page;\n }\n const data = pixels.data;\n for (let i = 0; i < data.length; i += 4) {\n const a = data[i + 3];\n if (a === 255) continue;\n if (a === 0) {\n // Nothing to divide by, and nothing there to see.\n data[i] = 0;\n data[i + 1] = 0;\n data[i + 2] = 0;\n continue;\n }\n const scale = 255 / a;\n // Rounded explicitly: assigning a fraction to a Uint8ClampedArray rounds\n // half-to-even, which is not the rule stated above.\n data[i] = Math.min(255, Math.round(data[i] * scale));\n data[i + 1] = Math.min(255, Math.round(data[i + 1] * scale));\n data[i + 2] = Math.min(255, Math.round(data[i + 2] * scale));\n }\n ctx.putImageData(pixels, 0, 0);\n return canvas;\n}\n\n/**\n * Backing pixels the cuts still waiting for their PNG encode may hold at once.\n *\n * A started cut keeps its canvas alive until `toBlob` calls back, so starting\n * every region at once peaks at Σ(cut area) of canvas backing — on top of the\n * decoded pages, which stay resident throughout. A cut is allocated at the\n * page image's own resolution, so what is charged here is that area, not the\n * region's atlas-unit area: a half-resolution page costs a quarter of it, an\n * @2x page four times it. Measured by counting the simultaneously-alive cut\n * canvases and their backing at `toBlob` (chromium, 1:1 pages):\n * the demo's 40-region 1024×256 atlas peaks at all 40 cuts and 194,742 px\n * (0.19 Mpx ≈ 0.74 MiB), which is nothing; a synthetic 256-region atlas on\n * four 2048×2048 pages peaks at 16.78 Mpx ≈ 64 MiB, which doubles that\n * atlas's resident cost for the length of the load.\n *\n * So the cuts are started against a budget rather than all at once. 4 Mpx is\n * one 2048×2048 page's worth (≈ 16 MiB at 4 bytes/px): small atlases still run\n * every region concurrently (spineboy: all 40, budget never engaged), and the\n * synthetic one runs 64 cuts at a time — 4 waves instead of 256 serial\n * encodes, for a quarter of the peak. A single region bigger than the budget\n * is started anyway when nothing else is in flight, so the budget can never\n * starve a cut.\n */\nconst CUT_BACKING_BUDGET_PX = 4 * 1024 * 1024;\n\n/** Where one region's pixels are on its page image, and how big its cut is. */\ninterface CutPlan {\n /** The region is its whole declared page, unrotated: hand the page through. */\n passThrough: boolean;\n /** Source rect on the page image, in the image's own pixels. */\n sx: number;\n sy: number;\n sw: number;\n sh: number;\n /** Cut canvas size: that same rect, turned artwork-side up. */\n cw: number;\n ch: number;\n}\n\n/**\n * Locates a region on its page image.\n *\n * **The rect is read in the image's own frame, not in declared atlas pixels.**\n * An atlas `size:` line and the image that ships for the page need not agree:\n * projects export textures at half resolution (or @2x) and leave the atlas\n * alone. Every official Spine runtime absorbs that for free, because\n * spine-core turns a region's bounds into *normalized* UVs against the\n * declared page size (`region.u = region.x / page.width`) and a GPU samples\n * normalized coordinates at whatever resolution the texture happens to have.\n * So the rect here is the region's bounds relative to the declared page size,\n * times the image's natural size — the continuous `uv * size` frame both mesh\n * backends already address texels in. No `size - 1`, no half-texel term: this\n * maps a rect, it does not sample.\n *\n * With a page that does ship at its declared size the scale is exactly 1 and\n * every number below is the region's own integer bounds, unchanged.\n *\n * Rotation: a region packed at 90° lies on its side, so it occupies a\n * `height × width` rect on the page — which is how spine-core reads it too\n * (`u2 = (x + height) / page.width` when `degrees === 90`). The cut canvas is\n * the rect turned back upright, so the bitmap comes out in artwork\n * orientation. *Which way* back is `cutRegion`'s, derived there from the UVs\n * spine-core assigns such a region and not from this plan.\n *\n * Rounding: each *edge* is rounded to the nearest image pixel, rather than the\n * width being rounded on its own. Neighbouring regions share an edge, so\n * rounding the edge keeps their cuts tiling the image exactly — no gap, no\n * overlap, and at most half a pixel of either region's own content given up on\n * a boundary that falls mid-pixel. Rounding outward would instead pull a whole\n * neighbouring pixel into every cut on every side, which is bleed the caller\n * can see. A rect that scales down below one pixel still gets a 1×1 bitmap,\n * since a zero-sized canvas is not one.\n *\n * The alternative was measured, not argued away (#35): sampling the\n * *fractional* rect with interpolation — what a GPU does with normalized UVs —\n * buys exact placement with a resample of the whole bitmap. Both rules drew\n * the same frozen rigid-only pose from a rescaled page, diffed against that\n * pose drawn from the 1:1 page. The result is split, so the lossless copy\n * stays: sampling lowers the raw difference and the peak channel delta, while\n * rounding lowers the count of pixels with no in-tolerance match anywhere in\n * the reference's 3×3 — rounding displaces the picture, which a shift-tolerant\n * compare forgives, and sampling blurs it, which it does not. On that\n * shift-tolerant count at 0.5×, the common case, rounding is ahead in every\n * cell measured, by 1.3× to 2.2× (chromium 638 vs 1238, webkit 1443 vs 1888) —\n * an ordering rather than a count, since the counts themselves move with the\n * raster. At an integer page scale the two rules come out bit-identical, there\n * being no fractional part to disagree about, so an @2x page never had a\n * question to answer. `tests/cut-rule.spec.ts` holds the 0.5× half of this.\n */\nfunction planCut({ region, page }: PlacedRegion, image: HTMLImageElement): CutPlan {\n const iw = image.naturalWidth;\n const ih = image.naturalHeight;\n // A page with no `size:` line (or a malformed one) declares nothing, so the\n // image is taken to be its own declared size — which is what this did for\n // every page before the frame above existed.\n const pageW = page.width > 0 ? page.width : iw;\n const pageH = page.height > 0 ? page.height : ih;\n\n const rotated = region.degrees === 90;\n const packedW = rotated ? region.height : region.width;\n const packedH = rotated ? region.width : region.height;\n\n // Whole-page pass-through: an unrotated region covering its entire page\n // would be cut into a pixel-for-pixel copy of the page image, so reuse the\n // page URL instead — no canvas, no PNG re-encode, no second decoded copy in\n // memory, and nothing to revoke afterwards. Atlases written as one part per\n // page (the loose-part-PNG workflow, where every part is declared its own\n // page) hit this for every single region.\n //\n // The test is against the declared page size, at any image resolution: a\n // whole page is a whole page whether it ships at 1×, half or double, and the\n // cut would copy the image either way. (It used to be tested against the\n // image, which was the same rule as long as the two always agreed.)\n //\n // Except on a premultiplied page, where the page URL is exactly what must not\n // be handed through: those pixels are premultiplied and an <img> composites\n // straight alpha, so passing the URL along would ship the defect to the one\n // atlas shape that never even allocates a canvas (one part per page). Such a\n // region is cut like any other — from the straight-alpha derivation — and the\n // blob it mints is owned and revoked like any other.\n if (\n !page.pma &&\n !rotated &&\n region.x === 0 &&\n region.y === 0 &&\n packedW === pageW &&\n packedH === pageH\n ) {\n return { passThrough: true, sx: 0, sy: 0, sw: iw, sh: ih, cw: iw, ch: ih };\n }\n\n const scaleX = iw / pageW;\n const scaleY = ih / pageH;\n const x0 = Math.round(region.x * scaleX);\n const y0 = Math.round(region.y * scaleY);\n const sw = Math.max(1, Math.round((region.x + packedW) * scaleX) - x0);\n const sh = Math.max(1, Math.round((region.y + packedH) * scaleY) - y0);\n\n return {\n passThrough: false,\n sx: x0,\n sy: y0,\n sw,\n sh,\n cw: rotated ? sh : sw,\n ch: rotated ? sw : sh,\n };\n}\n\n/** Backing pixels one cut allocates — the charge against the budget above. */\nfunction cutBackingPixels(\n placed: PlacedRegion,\n pageImages: ReadonlyMap<string, HTMLImageElement>,\n): number {\n const image = pageImages.get(placed.page.name);\n // No image: this region is about to fail in the cut. Charging its atlas\n // units keeps the walk moving until it does.\n if (!image) return placed.region.width * placed.region.height;\n const plan = planCut(placed, image);\n return plan.cw * plan.ch;\n}\n\n/**\n * One region's bitmap: the whole-page pass-through, or a cut canvas encoded to\n * a blob URL this module then owns.\n *\n * The cut is a **1:1 copy of the source rect** planCut located — never a\n * resample — so the bitmap has the native resolution of those pixels, while\n * the `RegionImage` sizes reported alongside it stay in atlas units. A page\n * shipped at half resolution therefore costs a quarter of the cut pixels and\n * still poses identically; upscaling the cut back to declared size would only\n * quadruple the pixels and add a resample.\n *\n * Everything before the `toBlob` await runs synchronously, so calling this is\n * what \"starts\" a cut: the canvas is painted and the encode is handed to the\n * browser before control comes back.\n */\nasync function cutRegion(\n placed: PlacedRegion,\n pageImages: ReadonlyMap<string, HTMLImageElement>,\n encoding: RegionEncoding,\n): Promise<RegionImage> {\n const { region, page } = placed;\n const image = pageImages.get(page.name);\n if (!image) throw new Error(`Missing page image: ${page.name}`);\n\n const w = region.width;\n const h = region.height;\n const plan = planCut(placed, image);\n if (plan.passThrough) return { url: image.src, width: w, height: h };\n\n const canvas = document.createElement('canvas');\n paintRegion(canvas, placed, image, plan);\n\n // A `data:` URL is the same PNG inline: nothing is minted, so nothing is\n // owned and `revokeRegions` has nothing to free. It is for a consumer whose\n // content policy or snapshotting does not carry `blob:`; it costs the\n // base64 string per region for as long as the map lives.\n if (encoding === 'data') return { url: canvas.toDataURL('image/png'), width: w, height: h };\n\n const blob = await new Promise<Blob>((resolve, reject) => {\n canvas.toBlob((b) => (b ? resolve(b) : reject(new Error('toBlob failed'))), 'image/png');\n });\n const url = URL.createObjectURL(blob);\n ownedUrls.add(url);\n return { url, width: w, height: h };\n}\n\n/** The identical native-pixel producer for encoded regions and atlas canvases. */\nfunction paintRegion(canvas: HTMLCanvasElement, placed: PlacedRegion, image: HTMLImageElement, plan: CutPlan, ratio?: number): void {\n canvas.width = ratio === undefined ? plan.cw : Math.min(plan.cw, Math.max(1, Math.ceil(placed.region.width * ratio)));\n canvas.height = ratio === undefined ? plan.ch : Math.min(plan.ch, Math.max(1, Math.ceil(placed.region.height * ratio)));\n const ctx = canvas.getContext('2d');\n if (!ctx) throw new Error('2d context unavailable');\n\n if (ratio !== undefined) {\n ctx.imageSmoothingQuality = 'high';\n ctx.scale(canvas.width / plan.cw, canvas.height / plan.ch);\n }\n if (placed.region.degrees === 90) {\n // The region is packed rotated. Turn the destination frame back so the\n // source rect, drawn at its own size, lands upright and fills the canvas —\n // and turn it *clockwise*, which is derived from spine-core's UVs rather\n // than from anything this file does.\n //\n // `TextureAtlas` takes `u`/`v` from the packed rect's top-left corner and,\n // at `degrees === 90`, `u2`/`v2` from `x + height` / `y + width` — the\n // rect's far edges. `RegionAttachment` then hands the artwork's corners out\n // in the rigid tier's own order, BL, UL, UR, BR, as\n //\n // BL (u2, v2) UL (u, v2) UR (u, v) BR (u2, v)\n //\n // so the artwork's top-left corner is the packed rect's *bottom-left* and\n // its top-right is the rect's *top-left*: the artwork's top edge runs up\n // the rect's left edge, which is a packer that turned it counter-clockwise.\n //\n // `translate(cw, 0); rotate(+π/2)` maps a pixel (x, y) of the source rect —\n // sw × sh on the page, and cw = sh, ch = sw — to canvas (cw − y, x), which\n // is that turn undone:\n //\n // packed bottom-left (0, sh) → (0, 0) the cut's top-left = UL\n // packed top-left (0, 0) → (cw, 0) the cut's top-right = UR\n // packed top-right (sw, 0) → (cw, ch) the cut's bottom-right = BR\n // packed bottom-right (sw, sh) → (0, ch) the cut's bottom-left = BL\n //\n // Until #49 this was `translate(0, ch); rotate(−π/2)`, mapping (x, y) to\n // (y, ch − x): a *second* counter-clockwise turn, landing the artwork's\n // top-left at the cut's bottom-right. The bitmap came out 180° round, and\n // since `renderRegion` pins a bitmap's top-left to the attachment's UL\n // corner either way, every rotated rigid part was drawn inverted — from the\n // first commit of this package to 0.7.0. The mesh tier never was: it\n // samples the page through the UVs above.\n ctx.translate(plan.cw, 0);\n ctx.rotate(Math.PI / 2);\n }\n // Straight alpha on a premultiplied page, since the cut is encoded to a PNG\n // and shown in an <img>. The rect was planned against the image, and the\n // derivation is that image's own size, so the coordinates carry over\n // unchanged — including on a page that ships at another resolution.\n const source = straightAlphaSource(image, placed.page.pma === true);\n ctx.drawImage(source, plan.sx, plan.sy, plan.sw, plan.sh, 0, 0, plan.sw, plan.sh);\n\n}\n\n/**\n * How a cut region's PNG is handed to the `<img>`: a `blob:` URL this module\n * owns and `revokeRegions` frees (the default), or a `data:` URL that owns\n * nothing and needs no revoke.\n */\nexport type RegionEncoding = 'blob' | 'data';\n\nexport interface UnpackRegionsOptions {\n /** `'blob'` by default. */\n encoding?: RegionEncoding;\n}\n\n/**\n * Cuts every region of a page layout — a model document's `pages` section —\n * out of its page image into its own bitmap once at load time, restoring 90°\n * packing rotation, so the per-frame path never touches a canvas. Returns\n * image URLs keyed by region name. `pageImages` is keyed by page name.\n * `loadModel` calls this; it is exported for callers whose page images do not\n * come from a URL.\n *\n * This is a loading-pipeline step, not a rendering step: after this runs,\n * rendering is pure DOM (one <img> per slot, one CSS matrix write per frame).\n *\n * A region that covers its whole page unrotated skips the cut and reuses the\n * page image URL — see the pass-through in planCut.\n *\n * **A page may ship at a resolution its atlas does not declare.** Half-size\n * texture builds and @2x variants are normal, and no option is needed for\n * them: a region's bounds are read relative to the declared page size and\n * scaled onto the image's natural size, which is exactly how spine-core\n * derives the UVs the mesh tier already samples with. Each bitmap comes out at\n * the native resolution of the pixels it was cut from, and the `RegionImage`\n * sizes beside it stay in atlas units, so nothing downstream has to know.\n *\n * *Behaviour change (0.5.1 → next).* An atlas whose `size:` line is simply\n * wrong — bounds written in image pixels under a page declared some other size\n * — used to be cut \"as the coordinates say\", because the cut read the image\n * directly. It is now read the way every other Spine runtime reads it:\n * relative to the declared size. Such an atlas rendered with a skewed mesh\n * tier and an intact rigid tier before; now both tiers agree, and the fix is\n * to correct the `size:` line.\n *\n * **The cuts run concurrently.** PNG encoding is asynchronous and the browser\n * does it off the main thread, so the encodes are started together and awaited\n * together instead of one `toBlob` per iteration: awaited in series a load\n * costs the *sum* of every encode, which a throttled document turns into one\n * full throttle period per region (measured: a single 8×8 `toBlob` took 7.5 s\n * to call back in a hidden desktop Chromium pane). How many run at once is\n * bounded by CUT_BACKING_BUDGET_PX above, not by an option.\n *\n * Concurrency changes nothing a caller can observe:\n *\n * - **Order.** The returned map is keyed in layout order — pages in order,\n * each page's regions in order, which is the atlas's own order — whatever\n * order the blobs arrive in: the map is built after the cuts settle, from\n * the region list, not from the arrivals.\n * - **Duplicate names.** The last region of a given name in atlas order wins,\n * and the shadowed URL is revoked (and dropped from the ledger) rather than\n * stranded.\n * - **Failure.** Every URL this call minted is revoked before the error\n * propagates, *including cuts that were still in flight when the first\n * failure happened* — their blobs arrive later, and a load that walked away\n * from them would mint owned URLs nobody could ever revoke. So a failure\n * stops new cuts from starting but still waits for the started ones, and the\n * error it raises is the one from the earliest region in atlas order (what\n * the serial loop used to throw). Nothing here rejects unobserved.\n *\n * The blob URLs stay alive until revokeRegions() frees them — a document-wide\n * allocation the GC cannot reclaim on its own. Callers that load and unload\n * skeletons repeatedly (cutscenes, level transitions) must pair every\n * unpackRegions() with a revokeRegions(); a caller that loads once for the\n * page lifetime can ignore it.\n */\nexport async function unpackRegions(\n pages: readonly PageLayout[],\n pageImages: ReadonlyMap<string, HTMLImageElement>,\n options: UnpackRegionsOptions = {},\n): Promise<Map<string, RegionImage>> {\n const encoding = options.encoding ?? 'blob';\n if (encoding !== 'blob' && encoding !== 'data') throw new Error(`encoding must be 'blob' or 'data', got ${String(options.encoding)}`);\n const regions: PlacedRegion[] = pages.flatMap((page) => page.regions.map((region) => ({ region, page })));\n const cuts = new Array<RegionImage | undefined>(regions.length);\n\n // The earliest-in-atlas-order failure is the one that propagates, so that a\n // broken atlas reports the same region whichever encode happens to land\n // first.\n let failedIndex = -1;\n let failure: unknown;\n\n /** One in-flight cut: `done` is set before its promise resolves. */\n interface Job {\n promise: Promise<void>;\n done: boolean;\n }\n let inFlight: Job[] = [];\n let inFlightPixels = 0;\n\n for (let index = 0; index < regions.length && failedIndex === -1; index++) {\n const region = regions[index];\n if (!region) continue;\n // A pass-through allocates no canvas, but it also resolves without waiting\n // for anything, so charging it the page's area costs at most one drain.\n const pixels = cutBackingPixels(region, pageImages);\n\n while (inFlight.length > 0 && inFlightPixels + pixels > CUT_BACKING_BUDGET_PX) {\n await Promise.race(inFlight.map((job) => job.promise));\n inFlight = inFlight.filter((job) => !job.done);\n if (failedIndex !== -1) break;\n }\n if (failedIndex !== -1) break;\n\n inFlightPixels += pixels;\n const job: Job = { done: false, promise: Promise.resolve() };\n // Jobs settle, they never reject: the failure is recorded here so that\n // nothing is left for an unhandled-rejection handler to find.\n job.promise = (async () => {\n try {\n cuts[index] = await cutRegion(region, pageImages, encoding);\n } catch (error) {\n if (failedIndex === -1 || index < failedIndex) {\n failedIndex = index;\n failure = error;\n }\n } finally {\n inFlightPixels -= pixels;\n job.done = true;\n }\n })();\n inFlight.push(job);\n }\n\n // Every cut this call started is settled after this, so the cleanup below\n // reaches the blobs that arrived after the first failure too.\n await Promise.all(inFlight.map((job) => job.promise));\n\n if (failedIndex !== -1) {\n for (const cut of cuts) if (cut) revokeOwned(cut.url);\n throw failure;\n }\n\n const result = new Map<string, RegionImage>();\n for (let index = 0; index < regions.length; index++) {\n const placed = regions[index];\n const cut = cuts[index];\n if (!placed || !cut) continue;\n // Duplicate region names would otherwise strand the shadowed URL in the\n // ledger with nothing left pointing at it. Map.set keeps the key where it\n // first appeared, so atlas order survives the overwrite.\n const shadowed = result.get(placed.region.name);\n if (shadowed) revokeOwned(shadowed.url);\n result.set(placed.region.name, cut);\n }\n return result;\n}\n\n/**\n * Frees the blob URLs unpackRegions minted for `images` — the counterpart of\n * unpackRegions, to call once the skeletons using them are gone (after\n * `renderer.dispose()`, since a live <img> would keep pointing at a dead URL).\n *\n * Only URLs this module created are revoked: entries the caller supplied\n * itself (a hand-built map of loose part PNGs) and page images reused\n * verbatim by the whole-page pass-through are left alone. Idempotent —\n * revoking twice is a no-op, so it is safe on a map that is shared or\n * partially reused.\n *\n * The map keeps its entries; drop the reference (or reload) afterwards, since\n * the URLs no longer resolve.\n */\nexport function revokeRegions(images: Map<string, RegionImage>): void {\n for (const image of images.values()) revokeOwned(image.url);\n}\n","/**\n * Shared offscreen WebGL rasterizer for the mesh (deform) tier.\n *\n * One module-level context serves every renderer instance: browsers cap live\n * WebGL contexts (16 on Chrome/Safari) and a page can hold many renderers, so\n * per-renderer contexts would evict each other. Per flush, every dirty mesh is\n * shelf-packed into a rect of the offscreen canvas, its triangles are drawn\n * textured (atlas page texture, premultiplied alpha), and each rect is blitted\n * onto the mesh's per-part 2d canvas with an unclipped drawImage rect copy.\n * The texture is premultiplied either by the upload or by the exporter — a\n * `pma: true` page arrives that way, so it is uploaded unconverted (textureFor).\n *\n * Why this exists: Safari antialiases canvas2d clip paths, so the standard\n * per-triangle clip+transform+drawImage mapping pays a per-triangle AA-mask\n * cost in the GPU process — invisible to in-callback JS timing, but it\n * rAF-limits heavy scenes. GL rasterizes shared triangle edges seamlessly\n * (no clip, no crack overdraw needed), and the remaining canvas2d work is a\n * plain rect blit.\n *\n * The offscreen buffer is scratch space: rects are scissor-cleared and\n * redrawn every flush and read back in the same task, so neither\n * preserveDrawingBuffer nor cross-frame content is relied on. The buffer\n * grows quantized and never shrinks, mirroring the per-part backing policy\n * (reallocating GPU surfaces per frame is a Safari killer).\n *\n * It only ever holds a size the browser granted in full. The WebGL spec lets\n * the browser hand back a drawing buffer smaller than the canvas's\n * width × height, and Chromium does once the area passes its cap (5760 ×\n * 5760 for an 8192 × 8192 request, measured): drawing and reading back\n * through the canvas's size then copies the wrong texels into every part —\n * rectangles of another part's texture, cloth cut along straight edges, on a\n * zoomed-in stage (rig-c/review#332). So a growth the browser does not grant\n * in full is undone and that area is not asked for again. A batch the granted\n * buffer cannot hold — or one past `maxSize` — is drawn in passes through it,\n * and a job larger than the buffer in tiles (see flush()); the canvas2d path\n * is the caller's for a lost context only, never for size.\n *\n * Page textures are the one thing here with a lifetime, and since this object\n * outlives every renderer they are reference-counted: a renderer retains each\n * page it queues a job for and releases them in dispose(), and the last\n * release deletes the GL texture (a later job re-uploads it). The cache is\n * keyed weakly by the page image, so a consumer that never disposes still\n * loses nothing but GPU memory — this object never pins the caller's image.\n *\n * The canvas render mode (`CanvasRenderer`) draws through the same context: a\n * `FrameJob` is a whole player's frame — every region and mesh as textured,\n * vertex-coloured triangles in draw order, with the blend mode as batch state —\n * into one rect (or tiles of one, past the grant), blitted onto that player's\n * one visible canvas, and rastered in that rect's own frame like a mesh job. It has its own\n * program (colour and optional dark attributes) so the mesh tier's program and\n * its output stay exactly what they were; both share the page textures and\n * their reference counts.\n */\n\nimport type { BlendMode } from './posedFrame.js';\n\n// Frozen public topology remains the identity and mutation boundary. Only the\n// raster loops read this private, weakly held copy; it never enters a frame.\nconst triangleReadSources = new WeakMap<object, ArrayLike<number>>();\n\n/** @internal Ordinary indices for raster reads, preserving mutable inputs live. */\nexport function triangleReadSource(source: ArrayLike<number>): ArrayLike<number> {\n let kept = triangleReadSources.get(source);\n if (kept === undefined) {\n kept = Object.isFrozen(source) ? Array.from(source) : source;\n triangleReadSources.set(source, kept);\n }\n return kept;\n}\n\n/** Why a renderer selected Canvas2D for its last render. */\nexport type WebGLFallbackReason = 'creation-failed' | 'context-lost' | 'over-grant' | 'not-requested';\n\ntype FlushFallback = 'context-lost' | 'over-grant';\n\nexport interface MeshBlitJob {\n /** Destination per-part canvas; the blit clears its full backing first. */\n canvas: HTMLCanvasElement;\n /** Atlas page image the mesh samples (cached as a GL texture on first use). */\n page: HTMLImageElement;\n /**\n * `page.pma` — whether the page's texels are already premultiplied, which\n * decides whether the upload premultiplies them again (see textureFor). It\n * travels with the page because it describes the page's *pixels*, and the\n * blend below wants them premultiplied exactly once.\n */\n pma: boolean;\n /** Bbox-relative vertices in CSS px, x/y interleaved (indexed via `triangles`). */\n vertices: Float64Array;\n /** Normalized page UVs aligned with `vertices`. */\n uvs: ArrayLike<number>;\n /** Triangle index list into vertex/UV pairs. */\n triangles: ArrayLike<number>;\n /** Backing-store pixels per CSS px. */\n ratio: number;\n /** Rasterized region in device px — the packed rect and the blit both use it. */\n width: number;\n height: number;\n}\n\n/**\n * One run of a frame job's triangles: a stretch of the vertex data that samples\n * one page under one blend mode — one draw call.\n */\nexport interface FrameRun {\n page: HTMLImageElement;\n /** `page.pma`, as for MeshBlitJob. */\n pma: boolean;\n blend: BlendMode;\n /** First vertex of the run (not float) in `FrameJob.data`. */\n first: number;\n /** Vertices in the run — three per triangle. */\n count: number;\n}\n\n/**\n * A whole frame of one player (the canvas render mode): unindexed triangles,\n * interleaved per vertex as\n * `x, y, u, v, r, g, b, a` (stride 8) or `x, y, u, v, r, g, b, a, dr, dg, db`\n * (stride 11, the two-colour form, only when the frame carries a dark colour).\n * Positions are device px relative to the job's rect, top-left origin; the\n * colour is premultiplied by its alpha and so is the dark colour. Drawn into\n * one rect of the offscreen buffer, then blitted onto `canvas` in one\n * `drawImage` — or, past the grant, tile by tile (see flushFrame).\n */\nexport interface FrameJob {\n canvas: HTMLCanvasElement;\n width: number;\n height: number;\n data: Float32Array;\n stride: 8 | 11;\n runs: FrameRun[];\n}\n\n/**\n * Premultiplied-source blend factors per mode — the RGB pair; alpha always\n * takes ONE against the same destination factor, so a mode drawn over\n * transparency still leaves coverage behind for the blit to composite.\n */\nconst BLEND_FACTORS: Record<BlendMode, readonly [src: number, dst: number]> = {\n Normal: [1 /* ONE */, 0x0303 /* ONE_MINUS_SRC_ALPHA */],\n Additive: [1 /* ONE */, 1 /* ONE */],\n Multiply: [0x0306 /* DST_COLOR */, 0x0303 /* ONE_MINUS_SRC_ALPHA */],\n Screen: [1 /* ONE */, 0x0301 /* ONE_MINUS_SRC_COLOR */],\n};\n\nconst FRAME_VERTEX_SHADER = `\nattribute vec2 aPos;\nattribute vec2 aUV;\nattribute vec4 aColor;\nattribute vec3 aDark;\nuniform vec2 uScale;\nuniform vec2 uOrigin;\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vDark;\nvoid main() {\n vec2 clip = (aPos - uOrigin) * uScale - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n vUV = aUV;\n vColor = aColor;\n vDark = aDark;\n}`;\n\n/*\n * Two-colour tint over a premultiplied texel t: in straight terms the texel's\n * colour c is mapped to c·light + (1 − c)·dark, with alpha t.a·light.a.\n * Premultiplying that by the output alpha gives\n * t.rgb·(light·a) + (t.a − t.rgb)·(dark·a) — which is why both vertex colours\n * arrive premultiplied. With no dark colour the dark attribute is a constant 0\n * and this is a plain premultiplied vertex-colour multiply.\n */\nconst FRAME_FRAGMENT_SHADER = `\nprecision mediump float;\nuniform sampler2D uTex;\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vDark;\nvoid main() {\n vec4 t = texture2D(uTex, vUV);\n gl_FragColor = vec4(t.rgb * vColor.rgb + (t.a - t.rgb) * vDark, t.a * vColor.a);\n}`;\n\n/** WebGL contexts this module has created; see glContextCount(). */\nlet contextsCreated = 0;\n\n/**\n * WebGL contexts this module has created — the whole of the context-cap\n * accounting: one, however many renderers and players draw through it.\n *\n * @internal Read by the test harness; not part of the package API.\n */\nexport function glContextCount(): number {\n return contextsCreated;\n}\n\nconst VERTEX_SHADER = `\nattribute vec2 aPos;\nattribute vec2 aUV;\nuniform vec2 uScale;\nuniform vec2 uOrigin;\nvarying vec2 vUV;\nvoid main() {\n // aPos is in the job's own device px, top-left origin (matching the\n // top-left-origin drawImage read of the same rect); uOrigin is the top-left\n // of the viewport window within the job, 0 unless the job passes maxSize.\n vec2 clip = (aPos - uOrigin) * uScale - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n vUV = aUV;\n}`;\n\nconst FRAGMENT_SHADER = `\nprecision mediump float;\nuniform sampler2D uTex;\nvarying vec2 vUV;\nvoid main() {\n gl_FragColor = texture2D(uTex, vUV);\n}`;\n\n/** Gap between packed rects; blits are 1:1 unfiltered, so 1px is plenty. */\nconst GUTTER = 1;\n/** Drawing-buffer growth quantum (device px). */\nconst GROW_STEP = 256;\n\n/**\n * One rect of the offscreen buffer in one pass: a whole job, or one tile of\n * it. `tx`, `ty`, `tw`, `th` are the tile in the job's own device px (the\n * whole job for an untiled one), and `bx`, `by` its top-left in the buffer.\n */\ninterface Piece {\n job: number;\n tx: number;\n ty: number;\n tw: number;\n th: number;\n bx: number;\n by: number;\n pass: number;\n}\n\n/**\n * What the last flush() or flushFrame() did: its jobs, the passes it drew,\n * the pieces it drew in them, and how many of its jobs were tiled.\n *\n * @internal Read by the test harness; not part of the package API.\n */\nexport interface FlushStats {\n jobs: number;\n passes: number;\n pieces: number;\n tiledJobs: number;\n}\n\n/**\n * The buffer phase every piece is placed at: its top-left corner sits at\n * GUTTER modulo ALIGN in both axes, and the buffer's sides are multiples of\n * it, so a job's raster lands on the same phase of the window wherever it is\n * packed and whichever tile of it is drawn. Some rasterizers are invariant\n * under a translation of the window only by whole raster tiles. Measured on\n * one mesh job at pixel ratio 1.75, the buffer's height shifted and nothing\n * else: headless WebKit on macOS (Apple GPU) drew 7–14 pixels one level off\n * at shifts of 1, 2, 3, 4, 7, 8, 15, 16, 31 and 48 px, and identically at 32,\n * 64, 96, 128, 256 and 512; SwiftShader drew identically at every shift.\n * The phase makes macOS WebKit's dom mode exact across tilings; it does not\n * do that for WebKit on Linux, which differs on it too (tests/zoom-buffer.spec.ts\n * says where identity is held). It is kept because it costs nothing else.\n */\nconst ALIGN = 32;\n\n/** The smallest position at or after `v` on the piece phase (GUTTER modulo ALIGN). */\nfunction onPhase(v: number): number {\n return v + ((((GUTTER - v) % ALIGN) + ALIGN) % ALIGN);\n}\n\n/**\n * Shelf-packs pieces, tallest first, into a `bufW`-wide buffer, starting a\n * new pass when a piece would cross `bufH`. Every piece must fit the buffer\n * with its gutter. Sets each piece's position and pass, and returns the\n * height the packing needs (the last pass's, when there are several).\n */\nfunction shelfPack(pieces: Piece[], bufW: number, bufH: number): number {\n // Array.prototype.sort is stable, so equal heights keep job and tile order.\n const order = pieces.slice().sort((a, b) => b.th - a.th);\n let pass = 0;\n let shelfX = GUTTER;\n let shelfY = GUTTER;\n let shelfH = 0;\n let height = GUTTER;\n for (const piece of order) {\n if (shelfX + piece.tw + GUTTER > bufW) {\n shelfY = onPhase(shelfY + shelfH + GUTTER);\n shelfX = GUTTER;\n shelfH = 0;\n }\n if (shelfY + piece.th + GUTTER > bufH) {\n pass++;\n shelfX = GUTTER;\n shelfY = GUTTER;\n shelfH = 0;\n height = GUTTER;\n }\n piece.bx = shelfX;\n piece.by = shelfY;\n piece.pass = pass;\n shelfX = onPhase(shelfX + piece.tw + GUTTER);\n if (piece.th > shelfH) shelfH = piece.th;\n if (shelfY + piece.th + GUTTER > height) height = shelfY + piece.th + GUTTER;\n }\n return height;\n}\n\n/** Cache entry for one atlas page: the upload, and how many renderers want it. */\ninterface PageTexture {\n /** Uploaded lazily, on the first flush that binds this page. */\n texture: WebGLTexture | null;\n /** Live retain() calls outstanding — one per renderer drawing this page. */\n users: number;\n /** The alpha convention `texture` was uploaded under; meaningless without it. */\n pma: boolean;\n}\n\nclass MeshGlBlitter {\n lost = false;\n /**\n * Page textures created minus deleted, i.e. how many uploads are live right\n * now. Deterministic (no GC in the path), which is what the lifetime tests\n * assert against — see tests/gl-textures.spec.ts.\n */\n liveTextureCount = 0;\n\n private readonly canvas = document.createElement('canvas');\n private readonly gl: WebGLRenderingContext;\n private readonly uScale: WebGLUniformLocation;\n private readonly uOrigin: WebGLUniformLocation;\n private readonly meshProgram: WebGLProgram;\n private readonly meshPos: number;\n private readonly meshUV: number;\n private readonly frameProgram: WebGLProgram;\n private readonly frameScale: WebGLUniformLocation;\n private readonly frameOrigin: WebGLUniformLocation;\n private readonly framePos: number;\n private readonly frameUV: number;\n private readonly frameColor: number;\n private readonly frameDark: number;\n /** Which program's attribute layout is bound — each flush binds its own. */\n private bound: 'mesh' | 'frame' | null = null;\n /**\n * Weak by the page image on purpose: a consumer that forgets dispose()\n * leaks its texture until context loss, but dropping the image still lets\n * the image (and then the WebGLTexture this entry holds) be collected.\n * Reassigned wholesale on context loss, never iterated.\n */\n private textures = new WeakMap<HTMLImageElement, PageTexture>();\n private readonly maxSize: number;\n /**\n * The smallest drawing-buffer area the browser has refused to grant in full\n * (see the module comment); a growth to this area or more is not attempted.\n */\n private refusedArea = Number.POSITIVE_INFINITY;\n /** Test-only caps on the grant, and the tiling plant — see limitForTesting(). */\n private testArea = Number.POSITIVE_INFINITY;\n private testWidth = Number.POSITIVE_INFINITY;\n private testHeight = Number.POSITIVE_INFINITY;\n private tiling = true;\n /**\n * What the last flush() or flushFrame() did.\n *\n * @internal Read by the test harness; not part of the package API.\n */\n stats: FlushStats = { jobs: 0, passes: 0, pieces: 0, tiledJobs: 0 };\n private vertexData = new Float32Array(8192);\n /** Per-job packed rect origins (a tiled job's first tile), filled by flush(). */\n private packX: number[] = [];\n private packY: number[] = [];\n\n constructor() {\n const gl = this.canvas.getContext('webgl', {\n alpha: true,\n premultipliedAlpha: true,\n antialias: false,\n depth: false,\n stencil: false,\n preserveDrawingBuffer: false,\n });\n if (!gl) throw new Error('WebGL unavailable');\n contextsCreated++;\n this.gl = gl;\n // No restore attempt: on loss the renderer falls back to canvas2d and the\n // backend signature re-dirties every mesh, so frames stay complete.\n this.canvas.addEventListener('webglcontextlost', () => {\n this.markLost();\n });\n\n const program = this.link(VERTEX_SHADER, FRAGMENT_SHADER);\n this.meshProgram = program;\n gl.useProgram(program);\n const uScale = gl.getUniformLocation(program, 'uScale');\n const uOrigin = gl.getUniformLocation(program, 'uOrigin');\n if (!uScale || !uOrigin) throw new Error('mesh program uniforms not found');\n this.uScale = uScale;\n this.uOrigin = uOrigin;\n gl.uniform1i(gl.getUniformLocation(program, 'uTex'), 0);\n this.meshPos = gl.getAttribLocation(program, 'aPos');\n this.meshUV = gl.getAttribLocation(program, 'aUV');\n\n const frame = this.link(FRAME_VERTEX_SHADER, FRAME_FRAGMENT_SHADER);\n this.frameProgram = frame;\n gl.useProgram(frame);\n const frameScale = gl.getUniformLocation(frame, 'uScale');\n const frameOrigin = gl.getUniformLocation(frame, 'uOrigin');\n if (!frameScale || !frameOrigin) throw new Error('frame program uniforms not found');\n this.frameScale = frameScale;\n this.frameOrigin = frameOrigin;\n gl.uniform1i(gl.getUniformLocation(frame, 'uTex'), 0);\n this.framePos = gl.getAttribLocation(frame, 'aPos');\n this.frameUV = gl.getAttribLocation(frame, 'aUV');\n this.frameColor = gl.getAttribLocation(frame, 'aColor');\n this.frameDark = gl.getAttribLocation(frame, 'aDark');\n\n // One dynamic buffer for both programs; each flush binds its own layout\n // (bindMesh / bindFrame), so neither sees the other's attribute state.\n gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n gl.enable(gl.BLEND);\n gl.enable(gl.SCISSOR_TEST);\n gl.clearColor(0, 0, 0, 0);\n gl.activeTexture(gl.TEXTURE0);\n // No larger than MAX_VIEWPORT_DIMS, so that a job's window up to maxSize\n // is one viewport (see placePiece), and on the ALIGN grid, so that a\n // window's corner keeps the piece phase.\n const viewport = gl.getParameter(gl.MAX_VIEWPORT_DIMS) as Int32Array | null;\n const side = Math.min((gl.getParameter(gl.MAX_RENDERBUFFER_SIZE) as number) || 4096, 8192, viewport?.[0] || 4096, viewport?.[1] || 4096);\n this.maxSize = Math.floor(side / ALIGN) * ALIGN;\n }\n\n /**\n * Rasterizes every job and blits it onto its per-part canvas. Returns null\n * on success, or the reason the caller needs to draw on its canvas2d path.\n *\n * A batch that fits one buffer is one pass, shelf-packed as it always was.\n * One that does not — a zoomed-in stage asks for more than the browser\n * grants, or for more than `maxSize` — is drawn in passes through the\n * largest buffer the browser grants in full: its pieces are shelf-packed\n * into that buffer, a pass is drawn and blitted, and the next pass reuses\n * the buffer. A piece is a whole job, or one tile of a job larger than the\n * buffer.\n *\n * Every piece is rastered in its own job's rect (#187): the vertex upload is\n * relative to the job and nothing else, and the viewport is the job's rect\n * wherever the piece sits. A tile is the same viewport moved so that the\n * tile lands in the buffer, scissored to the tile and blitted into the\n * matching sub-rect of the part canvas — so a pixel does not depend on how\n * its job was packed, which pass drew it, or how it was tiled.\n */\n flush(jobs: MeshBlitJob[]): FlushFallback | null {\n const gl = this.gl;\n this.stats = { jobs: jobs.length, passes: 0, pieces: 0, tiledJobs: 0 };\n if (this.lost || gl.isContextLost()) return 'context-lost';\n\n // One pass if the buffer holds the whole batch: every job whole, shelf-packed.\n let width = Math.max(512, this.canvas.width);\n for (const job of jobs) width = Math.max(width, job.width + GUTTER * 2);\n let pieces: Piece[] = jobs.map((job, i) => ({ job: i, tx: 0, ty: 0, tw: job.width, th: job.height, bx: 0, by: 0, pass: 0 }));\n const height = shelfPack(pieces, width, Number.POSITIVE_INFINITY);\n if (!this.reserve(width, height)) {\n if (!this.acquire(width, height)) return this.bufferFallback();\n const planned = this.plan(jobs, this.canvas.width, this.canvas.height);\n if (!planned) return this.bufferFallback();\n pieces = planned;\n }\n // Where each job's first piece went, for whoever reads the packing.\n const packX = (this.packX = new Array<number>(jobs.length));\n const packY = (this.packY = new Array<number>(jobs.length));\n for (let k = pieces.length - 1; k >= 0; k--) {\n packX[pieces[k].job] = pieces[k].bx;\n packY[pieces[k].job] = pieces[k].by;\n }\n this.bindMesh();\n\n // Build one interleaved vertex array for the whole batch (unindexed —\n // meshes are a few hundred triangles, expansion is cheaper than managing\n // index buffers), in each job's own device px: no pack offset is folded\n // in, so the Float32 a vertex is rounded to is the job's alone.\n let floats = 0;\n for (const job of jobs) floats += job.triangles.length * 4;\n if (this.vertexData.length < floats) {\n this.vertexData = new Float32Array(1 << Math.ceil(Math.log2(floats)));\n }\n const data = this.vertexData;\n const firsts = new Array<number>(jobs.length);\n let f = 0;\n for (let i = 0; i < jobs.length; i++) {\n const { vertices, uvs, ratio } = jobs[i];\n const triangles = triangleReadSource(jobs[i].triangles);\n firsts[i] = f / 4;\n for (let t = 0; t < triangles.length; t++) {\n const vi = triangles[t] * 2;\n data[f++] = vertices[vi] * ratio;\n data[f++] = vertices[vi + 1] * ratio;\n data[f++] = uvs[vi];\n data[f++] = uvs[vi + 1];\n }\n }\n if (floats > 0) gl.bufferData(gl.ARRAY_BUFFER, data.subarray(0, floats), gl.DYNAMIC_DRAW);\n\n const cleared = new Uint8Array(jobs.length);\n const bufH = this.canvas.height;\n let start = 0;\n while (start < pieces.length) {\n const pass = pieces[start].pass;\n let end = start;\n while (end < pieces.length && pieces[end].pass === pass) end++;\n\n let boundPage: HTMLImageElement | null = null;\n for (let k = start; k < end; k++) {\n const piece = pieces[k];\n const job = jobs[piece.job];\n if (job.page !== boundPage) {\n gl.bindTexture(gl.TEXTURE_2D, this.textureFor(job.page, job.pma));\n boundPage = job.page;\n }\n this.placePiece(piece, job.width, job.height, bufH, this.uScale, this.uOrigin);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gl.drawArrays(gl.TRIANGLES, firsts[piece.job], job.triangles.length);\n }\n\n // If the context died mid-batch the draws above were no-ops; report it\n // before blitting stale/blank rects onto the part canvases.\n if (gl.isContextLost()) {\n this.markLost();\n return 'context-lost';\n }\n\n // Blit each piece onto its per-part canvas: same-task read (no\n // preserveDrawingBuffer needed), 1:1 device px (no filtering).\n for (let k = start; k < end; k++) {\n const piece = pieces[k];\n const job = jobs[piece.job];\n const ctx = job.canvas.getContext('2d');\n if (!ctx) continue;\n if (!cleared[piece.job]) {\n cleared[piece.job] = 1;\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n // Clear the full backing: the previous raster may have been larger.\n ctx.clearRect(0, 0, job.canvas.width, job.canvas.height);\n }\n if (piece.tw > 0 && piece.th > 0) {\n ctx.drawImage(this.canvas, piece.bx, piece.by, piece.tw, piece.th, piece.tx, piece.ty, piece.tw, piece.th);\n }\n }\n this.stats.passes++;\n start = end;\n }\n this.stats.pieces = pieces.length;\n // A job that drew no piece (none on a context it could get) is still cleared.\n for (let i = 0; i < jobs.length; i++) {\n if (cleared[i]) continue;\n const ctx = jobs[i].canvas.getContext('2d');\n if (!ctx) continue;\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, jobs[i].canvas.width, jobs[i].canvas.height);\n }\n return null;\n }\n\n private bufferFallback(): FlushFallback {\n return this.gl.isContextLost() ? 'context-lost' : 'over-grant';\n }\n\n /**\n * Sets the viewport, the two uniforms and the scissor for one piece. The\n * viewport is the job's own rect — or, for a job wider or taller than\n * `maxSize`, the `maxSize` window of it that holds the piece, since a\n * viewport cannot be larger — placed so that the piece's sub-rect lands on\n * the piece's rect of the buffer; the scissor is that rect. Scissor and\n * viewport are bottom-left origin; pieces are placed top-left.\n *\n * The clip-space mapping is `(p - origin) * scale - 1` with `scale` the\n * window's 2 / size, a function of the job and the window alone. Written as\n * `(p - origin) / size * 2 - 1` instead, SwiftShader drew the canvas mode's\n * 6,901 px frame differently in two tilings (51,537 pixels); this form drew\n * them identically, and the mesh tier identically either way.\n */\n private placePiece(piece: Piece, width: number, height: number, bufH: number, scale: WebGLUniformLocation, origin: WebGLUniformLocation): void {\n const gl = this.gl;\n const wx = piece.tx - (piece.tx % this.maxSize);\n const wy = piece.ty - (piece.ty % this.maxSize);\n const ww = Math.min(this.maxSize, width - wx);\n const wh = Math.min(this.maxSize, height - wy);\n // The job's top-left corner in buffer px: off the buffer for a tile past its first.\n const left = piece.bx - piece.tx;\n const top = piece.by - piece.ty;\n gl.viewport(left + wx, bufH - (top + wy) - wh, ww, wh);\n gl.uniform2f(scale, 2 / ww, 2 / wh);\n gl.uniform2f(origin, wx, wy);\n gl.scissor(piece.bx, bufH - piece.by - piece.th, piece.tw, piece.th);\n }\n\n /**\n * Cuts each rect into pieces that fit a `bufW` × `bufH` buffer with its\n * gutter — a rect that fits is one piece, a larger one is tiled, tiles never\n * crossing a `maxSize` window — and shelf-packs them, tallest first, into\n * consecutive passes of that buffer. A tile starts on the `ALIGN` grid of\n * its job, so its job's corner keeps the buffer phase every piece has.\n * Returns the pieces in pass order, or null when a rect needs tiling and\n * tiling is off (a test-only plant) or the buffer is too small to tile.\n */\n private plan(rects: ArrayLike<{ width: number; height: number }>, bufW: number, bufH: number): Piece[] | null {\n const tileW = Math.floor((bufW - GUTTER * 2) / ALIGN) * ALIGN;\n const tileH = Math.floor((bufH - GUTTER * 2) / ALIGN) * ALIGN;\n const max = this.maxSize;\n const pieces: Piece[] = [];\n for (let i = 0; i < rects.length; i++) {\n const { width, height } = rects[i];\n if (width + GUTTER * 2 <= bufW && height + GUTTER * 2 <= bufH && width <= max && height <= max) {\n pieces.push({ job: i, tx: 0, ty: 0, tw: width, th: height, bx: 0, by: 0, pass: 0 });\n continue;\n }\n if (!this.tiling || tileW <= 0 || tileH <= 0) return null;\n this.stats.tiledJobs++;\n for (let wy = 0; wy < height; wy += max) {\n const wh = Math.min(max, height - wy);\n for (let wx = 0; wx < width; wx += max) {\n const ww = Math.min(max, width - wx);\n for (let ty = wy; ty < wy + wh; ty += tileH) {\n for (let tx = wx; tx < wx + ww; tx += tileW) {\n pieces.push({ job: i, tx, ty, tw: Math.min(tileW, wx + ww - tx), th: Math.min(tileH, wy + wh - ty), bx: 0, by: 0, pass: 0 });\n }\n }\n }\n }\n }\n shelfPack(pieces, bufW, bufH);\n // Stable: a pass keeps the packing's tallest-first order.\n return pieces.sort((a, b) => a.pass - b.pass);\n }\n\n /** The buffer sides this module will use: `maxSize`, or a test cap below it. */\n private get limitW(): number {\n return Math.floor(Math.min(this.maxSize, this.testWidth) / ALIGN) * ALIGN;\n }\n\n private get limitH(): number {\n return Math.floor(Math.min(this.maxSize, this.testHeight) / ALIGN) * ALIGN;\n }\n\n /**\n * Makes the drawing buffer hold at least `width` × `height`, growing it\n * grow-only and quantized, and returns whether it does — as granted, not as\n * asked. A growth the browser grants only in part is undone (the previous\n * size was granted in full) and its area remembered, so a zoom held past\n * the cap declines each frame without reallocating the buffer twice per\n * frame. Resizing clears the buffer, which is fine: every rect is cleared\n * and redrawn anyway.\n */\n private reserve(width: number, height: number): boolean {\n const canvas = this.canvas;\n const gl = this.gl;\n const limitW = this.limitW;\n const limitH = this.limitH;\n if (width > limitW || height > limitH) return false;\n if (width > canvas.width || height > canvas.height) {\n const w = Math.min(limitW, Math.ceil(Math.max(width, canvas.width) / GROW_STEP) * GROW_STEP);\n const h = Math.min(limitH, Math.ceil(Math.max(height, canvas.height) / GROW_STEP) * GROW_STEP);\n if (w * h >= this.refusedArea) return false;\n if (w * h > this.testArea) {\n // The test cap stands for a browser that grants less than this.\n this.refusedArea = w * h;\n return false;\n }\n const previousW = canvas.width;\n const previousH = canvas.height;\n canvas.width = w;\n canvas.height = h;\n if (gl.drawingBufferWidth < w || gl.drawingBufferHeight < h) {\n this.refusedArea = Math.min(this.refusedArea, w * h);\n canvas.width = previousW;\n canvas.height = previousH;\n return false;\n }\n }\n // Held on every flush, not only after a resize: a canvas whose buffer is\n // smaller than itself is exactly the state that draws the wrong texels.\n return gl.drawingBufferWidth === canvas.width && gl.drawingBufferHeight === canvas.height;\n }\n\n /**\n * Grows the buffer toward `width` × `height` as far as the browser grants\n * in full, for a batch that one buffer cannot hold. The request is shrunk a\n * quantum at a time, larger side first, never below the buffer already\n * held, past every area the browser has refused; each refusal lowers that\n * area, so the search ends — at worst on the buffer already held. Returns\n * false only when even that is not granted in full.\n */\n private acquire(width: number, height: number): boolean {\n const canvas = this.canvas;\n let w = Math.max(canvas.width, Math.min(this.limitW, Math.ceil(width / GROW_STEP) * GROW_STEP));\n let h = Math.max(canvas.height, Math.min(this.limitH, Math.ceil(height / GROW_STEP) * GROW_STEP));\n for (;;) {\n const held = w <= canvas.width && h <= canvas.height;\n if (held || w * h < this.refusedArea) {\n if (this.reserve(w, h)) return true;\n if (held) return false;\n }\n if (w >= h && w - GROW_STEP >= canvas.width) w -= GROW_STEP;\n else if (h - GROW_STEP >= canvas.height) h -= GROW_STEP;\n else if (w - GROW_STEP >= canvas.width) w -= GROW_STEP;\n else {\n w = canvas.width;\n h = canvas.height;\n }\n }\n }\n\n /**\n * Test-only limits: `area` caps the drawing-buffer area this module will\n * take as granted (a browser that grants less), `width` and `height` cap\n * its sides below `maxSize`, and `tiling: false` is the planted control that declines a job\n * larger than the buffer instead of tiling it. Setting limits drops the\n * buffer held so far, so they hold from the next flush; null lifts them.\n * Viewport windows stay `maxSize`: the caps stand for a smaller grant, not\n * a different GPU.\n *\n * @internal Read by the test harness; not part of the package API.\n */\n limitForTesting(limits: { area?: number; width?: number; height?: number; tiling?: boolean } | null): void {\n this.testArea = limits?.area ?? Number.POSITIVE_INFINITY;\n this.testWidth = limits?.width ?? Number.POSITIVE_INFINITY;\n this.testHeight = limits?.height ?? Number.POSITIVE_INFINITY;\n this.tiling = limits?.tiling ?? true;\n this.refusedArea = Number.POSITIVE_INFINITY;\n if (limits) {\n this.canvas.width = 1;\n this.canvas.height = 1;\n }\n }\n\n /**\n * Draws one player's frame (the canvas render mode) and blits it onto\n * `job.canvas`, whose full backing is cleared first. Returns null on success\n * or a canvas2d fallback reason. The frame is one job, drawn into one rect\n * if it fits, otherwise tiled through passes exactly as flush() tiles a mesh.\n * Every tile re-issues the frame's runs under its own scissor.\n */\n flushFrame(job: FrameJob): FlushFallback | null {\n const gl = this.gl;\n this.stats = { jobs: 1, passes: 0, pieces: 0, tiledJobs: 0 };\n if (this.lost || gl.isContextLost()) return 'context-lost';\n let pieces: Piece[];\n if (this.reserve(job.width + GUTTER * 2, job.height + GUTTER * 2)) {\n pieces = [{ job: 0, tx: 0, ty: 0, tw: job.width, th: job.height, bx: GUTTER, by: GUTTER, pass: 0 }];\n } else {\n if (!this.acquire(job.width + GUTTER * 2, job.height + GUTTER * 2)) return this.bufferFallback();\n const planned = this.plan([job], this.canvas.width, this.canvas.height);\n if (!planned) return this.bufferFallback();\n pieces = planned;\n }\n const bufH = this.canvas.height;\n this.bindFrame(job.stride);\n\n let vertices = 0;\n for (const run of job.runs) vertices = Math.max(vertices, run.first + run.count);\n if (vertices > 0) gl.bufferData(gl.ARRAY_BUFFER, job.data.subarray(0, vertices * job.stride), gl.DYNAMIC_DRAW);\n\n const ctx = job.canvas.getContext('2d');\n if (ctx) {\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.globalAlpha = 1;\n ctx.globalCompositeOperation = 'source-over';\n }\n let cleared = false;\n let boundPage: HTMLImageElement | null = null;\n let boundBlend: BlendMode | null = null;\n let start = 0;\n while (start < pieces.length) {\n const pass = pieces[start].pass;\n let end = start;\n while (end < pieces.length && pieces[end].pass === pass) end++;\n for (let k = start; k < end; k++) {\n this.placePiece(pieces[k], job.width, job.height, bufH, this.frameScale, this.frameOrigin);\n gl.clear(gl.COLOR_BUFFER_BIT);\n for (const run of job.runs) {\n if (run.page !== boundPage) {\n gl.bindTexture(gl.TEXTURE_2D, this.textureFor(run.page, run.pma));\n boundPage = run.page;\n }\n if (run.blend !== boundBlend) {\n const [src, dst] = BLEND_FACTORS[run.blend];\n gl.blendFuncSeparate(src, dst, gl.ONE, dst);\n boundBlend = run.blend;\n }\n gl.drawArrays(gl.TRIANGLES, run.first, run.count);\n }\n }\n if (gl.isContextLost()) {\n this.markLost();\n return 'context-lost';\n }\n // Same-task read, 1:1 device px.\n if (ctx) {\n if (!cleared) {\n cleared = true;\n ctx.clearRect(0, 0, job.canvas.width, job.canvas.height);\n }\n for (let k = start; k < end; k++) {\n const piece = pieces[k];\n if (piece.tw > 0 && piece.th > 0) {\n ctx.drawImage(this.canvas, piece.bx, piece.by, piece.tw, piece.th, piece.tx, piece.ty, piece.tw, piece.th);\n }\n }\n }\n this.stats.passes++;\n start = end;\n }\n this.stats.pieces = pieces.length;\n if (ctx && !cleared) ctx.clearRect(0, 0, job.canvas.width, job.canvas.height);\n return null;\n }\n\n /** The mesh tier's layout, [x, y, u, v], and its premultiplied source-over. */\n private bindMesh(): void {\n const gl = this.gl;\n if (this.bound !== 'mesh') {\n gl.useProgram(this.meshProgram);\n this.disableAttributes();\n gl.enableVertexAttribArray(this.meshPos);\n gl.enableVertexAttribArray(this.meshUV);\n gl.vertexAttribPointer(this.meshPos, 2, gl.FLOAT, false, 16, 0);\n gl.vertexAttribPointer(this.meshUV, 2, gl.FLOAT, false, 16, 8);\n this.bound = 'mesh';\n }\n // Premultiplied source-over, matching canvas2d triangle compositing. Set on\n // every mesh flush: a frame job in between leaves its last blend behind.\n gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);\n }\n\n /** The frame layout: [x, y, u, v, r, g, b, a], and [dr, dg, db] at stride 11. */\n private bindFrame(stride: 8 | 11): void {\n const gl = this.gl;\n gl.useProgram(this.frameProgram);\n this.disableAttributes();\n const bytes = stride * 4;\n gl.enableVertexAttribArray(this.framePos);\n gl.enableVertexAttribArray(this.frameUV);\n gl.enableVertexAttribArray(this.frameColor);\n gl.vertexAttribPointer(this.framePos, 2, gl.FLOAT, false, bytes, 0);\n gl.vertexAttribPointer(this.frameUV, 2, gl.FLOAT, false, bytes, 8);\n gl.vertexAttribPointer(this.frameColor, 4, gl.FLOAT, false, bytes, 16);\n if (stride === 11) {\n gl.enableVertexAttribArray(this.frameDark);\n gl.vertexAttribPointer(this.frameDark, 3, gl.FLOAT, false, bytes, 32);\n } else {\n // No slot carries a dark colour: a constant zero, which reduces the\n // two-colour form to the plain colour multiply.\n gl.vertexAttrib3f(this.frameDark, 0, 0, 0);\n }\n this.bound = 'frame';\n }\n\n private disableAttributes(): void {\n const gl = this.gl;\n for (const location of [this.meshPos, this.meshUV, this.framePos, this.frameUV, this.frameColor, this.frameDark]) {\n if (location >= 0) gl.disableVertexAttribArray(location);\n }\n }\n\n private link(vertex: string, fragment: string): WebGLProgram {\n const gl = this.gl;\n const program = gl.createProgram();\n if (!program) throw new Error('createProgram failed');\n gl.attachShader(program, this.compile(gl.VERTEX_SHADER, vertex));\n gl.attachShader(program, this.compile(gl.FRAGMENT_SHADER, fragment));\n gl.linkProgram(program);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n throw new Error(`program link failed: ${gl.getProgramInfoLog(program)}`);\n }\n return program;\n }\n\n /**\n * Declares one more user of `page`. The upload itself stays lazy (the first\n * flush that binds the page does it) — this only counts, so that the last\n * release() can free the texture instead of the module holding it forever.\n * Callers retain once per page and hand the same page back exactly once;\n * DomRenderer and CanvasRenderer each keep that ledger and settle it in dispose().\n */\n retain(page: HTMLImageElement): void {\n const entry = this.textures.get(page);\n if (entry) entry.users++;\n else this.textures.set(page, { texture: null, users: 1, pma: false });\n }\n\n /**\n * Gives back one retain(). The GL texture goes when the last user of the\n * page is gone; a later job for the same page simply uploads it again. A\n * page the cache does not know (a release after a context loss dropped\n * everything, or a double dispose) is a no-op, so this is safe to call\n * unconditionally.\n */\n release(page: HTMLImageElement): void {\n const entry = this.textures.get(page);\n if (!entry) return;\n if (--entry.users > 0) return;\n this.textures.delete(page);\n if (!entry.texture) return;\n // deleteTexture is a documented no-op on a lost context rather than a\n // throw, but a lost context has already dropped the cache and zeroed the\n // count — reaching here with `lost` set would mean decrementing twice.\n if (!this.lost && !this.gl.isContextLost()) this.gl.deleteTexture(entry.texture);\n this.liveTextureCount--;\n }\n\n /**\n * Context loss invalidates every texture handle at once. Drop the cache and\n * the count instead of carrying dead handles (deleting them is pointless —\n * the GPU side is already gone) and let the next frames re-upload if the\n * caller keeps drawing; the renderer meanwhile falls back to canvas2d.\n */\n private markLost(): void {\n this.lost = true;\n this.textures = new WeakMap();\n this.liveTextureCount = 0;\n }\n\n private compile(type: number, source: string): WebGLShader {\n const gl = this.gl;\n const shader = gl.createShader(type);\n if (!shader) throw new Error('createShader failed');\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n throw new Error(`shader compile failed: ${gl.getShaderInfoLog(shader)}`);\n }\n return shader;\n }\n\n /**\n * The page's GL texture, uploaded on demand.\n *\n * `pma` is a property of the page's *pixels*, so one image cannot honestly be\n * both: two atlases naming the same image with different `pma:` lines are not\n * a mixed page, one of them is simply wrong about the file. The cache is keyed\n * by the image, so rather than trusting that, a flag that disagrees with the\n * live upload re-uploads under the new one — the pathological case stays\n * correct (at the price of re-uploading while it lasts) instead of silently\n * drawing one of the two atlases wrong.\n */\n private textureFor(page: HTMLImageElement, pma: boolean): WebGLTexture {\n let entry = this.textures.get(page);\n if (entry?.texture) {\n if (entry.pma === pma) return entry.texture;\n this.gl.deleteTexture(entry.texture);\n entry.texture = null;\n this.liveTextureCount--;\n }\n const gl = this.gl;\n const texture = gl.createTexture();\n if (!texture) throw new Error('createTexture failed');\n gl.bindTexture(gl.TEXTURE_2D, texture);\n // Premultiply at upload so blending and the premultiplied canvas agree —\n // unless the page is already premultiplied (`pma: true`), where doing it\n // again is the second multiply that darkens every semi-transparent texel\n // (#37). The blend below is premultiplied source-over either way, so a pma\n // page is simply uploaded as it is: no conversion, nothing lost.\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pma ? 0 : 1);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, page);\n // Linear, no mips, clamped — NPOT-safe in WebGL1.\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n if (!entry) {\n // Nobody retained this page — not a path this package takes, since the\n // renderer retains as it queues each job. Cache it anyway so the batch\n // does not re-upload per flush; with no users only a context loss (or\n // the image being collected, which takes the weak entry with it) clears\n // it, which is exactly the old behavior for a caller that opts out.\n entry = { texture: null, users: 0, pma };\n this.textures.set(page, entry);\n }\n entry.pma = pma;\n entry.texture = texture;\n this.liveTextureCount++;\n return texture;\n }\n}\n\nlet shared: MeshGlBlitter | null | undefined;\n\n/**\n * The module-level blitter, created on first use. Returns null when WebGL is\n * unavailable or the shared context has been lost — callers then stay on the\n * canvas2d path.\n */\nexport function getMeshGlBlitter(): MeshGlBlitter | null {\n if (shared === undefined) {\n try {\n shared = new MeshGlBlitter();\n } catch {\n shared = null;\n }\n }\n return shared && !shared.lost ? shared : null;\n}\n\n/** The reason for a null result from getMeshGlBlitter(). */\nexport function meshGlUnavailableReason(): 'creation-failed' | 'context-lost' {\n return shared?.lost ? 'context-lost' : 'creation-failed';\n}\n","import { renderFrameOf } from './liveFrameSource.js';\nimport type { LiveFrame } from './liveFrame.js';\nimport { syncedPixelRatio } from './pixelRatio.js';\nimport { type AtlasRegion, drawAtlasRegion, type PageSource, type RegionImage, straightAlphaSource } from './DomTexture.js';\nimport { getMeshGlBlitter, meshGlUnavailableReason, triangleReadSource, type MeshBlitJob, type WebGLFallbackReason } from './MeshGlBlitter.js';\nimport type { BlendMode, PosedClip, PosedFrame, PosedMesh, PosedRegion, PosedSlot } from './posedFrame.js';\n\n/** Rasterizer used for the mesh (deform) tier. */\nexport type MeshBackend = 'canvas2d' | 'webgl';\n\n/**\n * What a canvas2d mesh triangle is drawn from: `'triangle'`, a source sub-rect\n * of the page covering the triangle's clip, or `'page'`, the whole page. Both\n * draw the same picture under the same clip; they differ in cost by engine.\n */\nexport type MeshSourceRect = 'triangle' | 'page';\n\n/**\n * The source rect an engine draws a canvas2d mesh triangle from, by default.\n * Linux WebKit garbles a whole-page `drawImage` under steep per-triangle\n * affines, so it gets the sub-rect. macOS Safari ran the sub-rect 12–15% slower\n * than the whole page, in two alternated passes, and a whole-page source rect\n * through the 9-argument call ran as fast as the whole page, so the cost is the\n * small rect (#25). Every other engine therefore gets the page, which is what\n * they all drew before #19; Chromium and Firefox were not timed either way. The test is a user-agent test: Linux, AppleWebKit, and not a Chromium.\n *\n * @internal Exported for the tests; not part of the package API.\n */\nexport function defaultMeshSourceRect(userAgent: string = typeof navigator === 'object' ? navigator.userAgent : ''): MeshSourceRect {\n const linuxWebKit = /AppleWebKit/.test(userAgent) && /Linux|X11/.test(userAgent) &&\n !/Android|Chrome|Chromium|CriOS|Edg/.test(userAgent);\n return linuxWebKit ? 'triangle' : 'page';\n}\n\nconst regionVertices = new Float32Array(8);\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n/** Unique tint-filter ids across renderer instances (ids are document-global). */\nlet tintFilterSeq = 0;\n/** How far a corner of an expanded triangle may move, in multiples of the expansion. */\nconst MITRE_LIMIT = 4;\nconst offsetCorners = new Float64Array(6);\n\n/**\n * Moves each edge of a triangle `amount` pixels outward along its own normal\n * and returns the corners where the moved edges meet, in `offsetCorners`\n * (x0, y0, x1, y1, x2, y2). Pushing the corners away from the centroid\n * instead (what this replaced) moves an edge by `amount` times the sine of the\n * angle the corner ray makes with it, which on a long, thin triangle is a\n * small fraction of a pixel, and the antialiased clip edges of neighbouring\n * triangles leave the background showing along the shared edge (#104). A\n * corner moves `amount / cos(θ/2)` for a corner angle θ, so on a needle it\n * is held to `MITRE_LIMIT × amount`, which leaves that corner's edges short\n * of the full offset near the tip.\n *\n * @internal Exported for the geometry test; not part of the package API.\n */\nexport function offsetTriangle(\n x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, amount: number,\n): Float64Array {\n const out = offsetCorners;\n out[0] = x0; out[1] = y0; out[2] = x1; out[3] = y1; out[4] = x2; out[5] = y2;\n const area = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0);\n if (amount === 0 || area === 0) return out;\n // Outward unit normals of the edges 0→1, 1→2, 2→0, whichever way the triangle winds.\n const sign = area > 0 ? 1 : -1;\n let len = Math.hypot(x1 - x0, y1 - y0);\n const n0x = ((y1 - y0) / len) * sign, n0y = (-(x1 - x0) / len) * sign;\n len = Math.hypot(x2 - x1, y2 - y1);\n const n1x = ((y2 - y1) / len) * sign, n1y = (-(x2 - x1) / len) * sign;\n len = Math.hypot(x0 - x2, y0 - y2);\n const n2x = ((y0 - y2) / len) * sign, n2y = (-(x0 - x2) / len) * sign;\n offsetCorner(out, 0, n2x, n2y, n0x, n0y, amount);\n offsetCorner(out, 2, n0x, n0y, n1x, n1y, amount);\n offsetCorner(out, 4, n1x, n1y, n2x, n2y, amount);\n return out;\n}\n\n/** Moves the corner at `out[i], out[i + 1]` to where its two edges, each moved `amount` along its normal, meet. */\nfunction offsetCorner(out: Float64Array, i: number, ax: number, ay: number, bx: number, by: number, amount: number): void {\n const k = amount / (1 + ax * bx + ay * by);\n let dx = (ax + bx) * k, dy = (ay + by) * k;\n const reach = Math.hypot(dx, dy);\n const limit = MITRE_LIMIT * amount;\n if (reach > limit) {\n dx *= limit / reach;\n dy *= limit / reach;\n }\n out[i] += dx;\n out[i + 1] += dy;\n}\n\n/**\n * Formats one clip-path coordinate, rounded to 1/1000 of the element's local\n * unit so that a pose which recomputes to a bit-different float does not\n * defeat the write cache.\n *\n * Why 1/1000: the local unit is an atlas unit for a rigid `<img>` (the matrix\n * denominator) and a CSS pixel for a mesh canvas, so the worst error this can\n * add on screen is half a quantum times the element's local-to-screen scale.\n * At a 50× upscale — far past anything a skeleton is posed at — that is\n * 0.025 px, an order of magnitude under one device pixel at dpr 3, while\n * still sitting three orders of magnitude above the f32 recomputation jitter\n * of coordinates that run 10²–10³ units. Shortest-round-trip number\n * formatting then keeps every coordinate at three decimals or fewer.\n */\nfunction clipCoord(v: number): string {\n return `${clipNum(v)}px`;\n}\n\n/**\n * The same quantized number without a unit, for `path()` data — SVG path\n * coordinates are user units and a `px` suffix there is a parse error.\n */\nfunction clipNum(v: number): number {\n return Math.round(v * 1000) / 1000;\n}\n\n/**\n * Bound past which a local coordinate is treated as degenerate rather than\n * written. Two reasons, and the second is the hard one: a near-singular\n * element matrix sends the inverse — and with it these coordinates — toward\n * infinity, and JavaScript switches to exponential notation at 1e21, which is\n * not valid CSS. The browser would then drop the whole declaration and the\n * element would render UNCLIPPED, which is the one failure mode a clip must\n * never have. A billion local units is already far outside anything a\n * skeleton poses, so nothing expressible is lost by stopping here.\n */\nconst CLIP_COORD_LIMIT = 1e9;\n\n/** Half the Float32 spacing at a world coordinate, including zero/subnormals. */\nfunction float32HalfUlp(value: number): number {\n // Invalid coordinates must never acquire an infinite comparison allowance.\n if (!Number.isFinite(value)) return 0;\n return 2 ** (Math.max(-149, Math.floor(Math.log2(Math.abs(value))) - 23) - 1);\n}\n\n/** A translated coordinate may differ only by its Float32 rounding (#130). */\nfunction sameMeshCoordinate(relative: number, cached: number, world: number, offset: number): boolean {\n if (relative === cached) return true;\n // No translation on this axis: a deformation stays an exact comparison,\n // even when the other axis moves. Both origins are integer bbox corners.\n if (offset === 0) return false;\n // The current coordinate defines the available precision: a large old\n // coordinate must not lend its coarse quantum to new, precise geometry.\n const tolerance = float32HalfUlp(world);\n const residual = Math.abs(relative - cached);\n // A nearest-integer identity is unique only strictly inside half a pixel;\n // a large Float32 quantum cannot turn integer deformation into translation.\n return residual < 0.5 && residual <= tolerance;\n}\n\ntype SlotKind = 'image' | 'canvas' | 'region-canvas';\n\ninterface SlotView {\n kind: SlotKind;\n el: HTMLImageElement | HTMLCanvasElement;\n /** Region name currently shown (image kind), to skip src rewrites. */\n regionName: string;\n /** Native (1) or the minification band last drawn for an atlas region. */\n regionRatio: number;\n visible: boolean;\n zIndex: number;\n opacity: number;\n blendMode: BlendMode;\n /** Last transform string written, to skip no-op style writes. */\n transform: string;\n /** Last clip-path string written ('' = none), to skip no-op style writes. */\n clipPath: string;\n /** Current RGB tint; (1,1,1) means untinted (no filter applied). */\n tintR: number;\n tintG: number;\n tintB: number;\n /** Lazily created SVG reference filter for non-white tints. */\n tintId: string;\n tintMatrix: SVGFEColorMatrixElement | null;\n /** Canvas kind: allocated backing-store size (grow-only, quantized). */\n canvasW: number;\n canvasH: number;\n /** Canvas kind: pixelRatio the backing/CSS sizing was computed with. */\n meshRatio: number;\n /**\n * Canvas kind: shape signature of the last raster, for dirty-skipping. The\n * UV and triangle arrays are compared by identity: the frame hands the same\n * objects for the same region and attachment (see PosedMesh), so a new array\n * is a new texture mapping and an old one is not.\n */\n meshUvs: ArrayLike<number> | null;\n meshTriangles: ArrayLike<number> | null;\n meshPage: HTMLImageElement | null;\n meshSequenceIndex: number;\n meshExpand: number;\n meshSourceRect: MeshSourceRect | '';\n meshVertexCount: number;\n /** Backend that produced the last raster — a backend switch re-dirties. */\n meshBackendDrawn: MeshBackend | '';\n /**\n * Canvas-space (bbox-relative) vertices of the last raster. Float64: the\n * compared values are f64 (f32 world vertex minus integer bbox origin);\n * storing them as f32 would round some of them and leave those meshes\n * permanently \"dirty\".\n */\n meshVertices: Float64Array;\n /** Integer bbox origin of that same last raster, never the last reused frame. */\n meshOriginX: number;\n meshOriginY: number;\n /** The render() call that last drew this view — a view not drawn by the current one is hidden. */\n drawnIn: number;\n}\n\nconst BLEND_CSS: Record<BlendMode, string> = {\n Normal: '',\n Additive: 'plus-lighter',\n Multiply: 'multiply',\n Screen: 'screen',\n};\n\n/**\n * Renders a posed frame (`PosedFrame`) as DOM, split by slot kind:\n *\n * - Region slots (rigid parts) become one absolutely-positioned <img>\n * posed with a single CSS matrix() write per frame — exact, since bone\n * transforms are affine.\n * - Mesh slots (deform parts) each get a small per-part <canvas> sized\n * to the mesh's world bounding box, redrawn per frame — either with the\n * standard per-triangle clip+transform+drawImage mapping (default), or via\n * a shared offscreen WebGL canvas that rect-blits into the same per-part\n * canvases (meshBackend = 'webgl'). Frames where the canvas-space vertices\n * are unchanged reuse the previous raster on both backends.\n *\n * Both element kinds share one stacking context, so draw order interleaves\n * freely via z-index (rear hair canvas < torso img < front hair canvas).\n * The RGB tint the frame carries (slot × attachment × the player's colour) is\n * applied per element with an SVG feColorMatrix reference filter — exact\n * channel multiply, works the same on <img> and <canvas>. Dark (two-color)\n * tint is not expressible that way and is unsupported. A clip the frame\n * carries becomes a CSS clip-path per element, in that element's own local\n * frame (see `clipping`) — which slots a clip covers is decided by the poser's\n * adapter (`frameOf`), not here.\n *\n * Coordinate mapping: the frame is world space, Y-up; CSS is Y-down — world Y\n * is negated. The poser computes everything (bones, constraints, physics,\n * deformed vertices) on the CPU; this class only draws.\n */\nexport class DomRenderer {\n /**\n * Apply the clips the frame carries (default). Each element drawn inside a\n * clip gets a CSS `clip-path` in its own local frame — an element-level\n * feature, so both mesh backends see exactly the same thing and neither\n * raster path knows clipping exists.\n *\n * Which slots a clip covers is the frame's, decided by the adapter on the\n * runtime's semantics (`clipCover` in posedFrame.ts: one clip in force at a\n * time, a second one met while one is in force ignored, a clip covering the\n * slots after its own through its end slot inclusive, an end slot that is\n * the clip's own slot — or one already passed — never ending it). A clip\n * that covers every slot of the frame is the whole-skeleton clip, and it\n * takes a fast path: one `clip-path` on the root instead of one per element.\n * The root is the caller's element, so its inline `clip-path` is borrowed —\n * saved on the first write and restored when the clip stops covering the\n * frame, when `clipping` goes false, and by `dispose()`.\n *\n * False restores the pre-0.6 behaviour: clips are counted in clipSkipCount\n * and nothing is clipped, with any clip-path this renderer wrote removed.\n */\n clipping = true;\n /** Clips applied last frame — distinct clip polygons over the drawn slots. */\n clipCount = 0;\n /** Atlas rigid canvases rasterized in the last frame; never includes meshes. */\n rigidRasterCount = 0;\n /**\n * Clips in the frame NOT applied last frame: `clipping` is false, or the\n * polygon has fewer than three points. A clip the runtime itself ignores (a\n * second one met while one is in force, one on an inactive bone) never\n * reaches the frame, so it is not counted here.\n */\n clipSkipCount = 0;\n /**\n * `clip-path` style writes performed last frame, across slot elements and\n * the root, clears included. A static polygon over static elements settles\n * at zero: every clip-path is cached per element exactly as `transform` is.\n */\n clipWriteCount = 0;\n /** Mesh canvases rasterized last frame. */\n meshCount = 0;\n /** Mesh canvases that reused their previous raster last frame. */\n meshReuseCount = 0;\n /**\n * Mesh canvas backing stores (re)allocated last frame. Should drop to zero\n * once an animation reaches its steady state; a persistent nonzero value\n * means GPU surfaces are being recreated per frame (a Safari killer).\n */\n canvasReallocCount = 0;\n /** Triangles rasterized last frame. */\n triangleCount = 0;\n /**\n * How far (canvas px) each edge of a triangle's clip polygon is moved\n * outward along its normal. Closes the antialiased-clip cracks between\n * adjacent triangles, through which the background shows (#104); set to 0\n * to see them.\n */\n triangleExpand = 0.5;\n /**\n * What the canvas2d mesh backend draws each triangle from (`MeshSourceRect`):\n * by default the sub-rect on Linux WebKit and the whole page elsewhere.\n * Re-rasters every mesh once when changed.\n */\n meshSourceRect: MeshSourceRect = defaultMeshSourceRect();\n /**\n * Mesh-canvas backing-store pixels per CSS pixel. Defaults to the device\n * pixel ratio. If the caller scales the root element, fold that scale in\n * (e.g. devicePixelRatio * rootScale) so the raster matches the on-screen\n * resolution instead of over- or under-sampling — syncPixelRatio() measures\n * that scale and folds it in for you.\n */\n pixelRatio = typeof devicePixelRatio === 'number' ? devicePixelRatio : 1;\n /**\n * Rasterizer for the mesh (deform) tier. 'canvas2d' maps each triangle\n * with clip+transform+drawImage directly on the per-part canvas. 'webgl'\n * (default) rasterizes every dirty mesh into one shared offscreen WebGL\n * canvas and rect-blits each mesh back onto its per-part canvas — the DOM\n * structure and all element-level behavior (z-index interleave, tint\n * filter, mix-blend-mode, dirty-skip) are identical, only the raster step\n * changes. Motivation: Safari antialiases canvas2d clip paths, so the\n * per-triangle clip mapping pays a per-triangle AA-mask cost in the GPU\n * process that rAF-limits heavy scenes; GL rasterizes shared edges\n * seamlessly (no clip, no crack overdraw) and the blit is an unclipped\n * rect copy. Falls back to 'canvas2d' when WebGL is unavailable or the\n * shared context is lost — see meshBackendActive. The default since 1.9\n * (#109); before it, 'canvas2d'. Set 'canvas2d' to keep the 2d raster.\n */\n meshBackend: MeshBackend = 'webgl';\n /** Backend that actually rasterized the mesh tier during the last render(). */\n meshBackendActive: MeshBackend = 'webgl';\n /** Why the last render selected canvas2d for meshes. Null before rendering or when WebGL was selected. */\n meshBackendFallbackReason: WebGLFallbackReason | null = null;\n\n private readonly views = new Map<string, SlotView>();\n /** Counts render() calls: the stamp a view drawn this frame carries (`SlotView.drawnIn`). */\n private frameNumber = 0;\n private readonly pendingJobs: MeshBlitJob[] = [];\n private readonly pendingViews: SlotView[] = [];\n /**\n * Atlas page images this renderer has retained from the shared blitter,\n * one retain each. Allocated on the first webgl mesh job, so a renderer\n * that never leaves canvas2d holds nothing and gives nothing back.\n */\n private glPages: Set<HTMLImageElement> | null = null;\n /**\n * World vertices copied out of the frame. Float32, as the rigid and mesh\n * paths have always read them: the raster, the dirty signature and the\n * clip-path quantization below are calibrated on single-precision\n * coordinates, and the frame's doubles are rounded here once rather than\n * changing what those paths see.\n */\n private scratchVertices = new Float32Array(256);\n private tintDefs: SVGSVGElement | null = null;\n /** The clip whose polygon is loaded in `clipPolygon`, if any. */\n private clipActive: PosedClip | null = null;\n /** The clips counted so far this frame, applied or skipped — one count each. */\n private readonly clipsSeen = new Set<PosedClip>();\n private clipInverse = false;\n /** True while the active clip is served by one clip-path on the root. */\n private clipOnRoot = false;\n /** The active clip polygon in CSS space (Y already negated), flat x,y. */\n private clipPolygon = new Float64Array(0);\n private clipPolygonLength = 0;\n /**\n * The root's inline `clip-path` before this renderer borrowed it; null means\n * not borrowed. The root belongs to the caller, so the fast path gives back\n * exactly the string it found.\n */\n private rootClipSaved: string | null = null;\n /** Last clip-path string written to the root, to skip no-op style writes. */\n private rootClipWritten = '';\n\n /**\n * @param root Positioned element (e.g. position:absolute) that becomes the\n * skeleton origin. The renderer only appends slot elements to it — layout\n * and scaling of the root belong to the caller.\n * @param regionImages Unpacked per-region bitmaps (for the rigid tier),\n * keyed by region name — `PosedRegion.region`.\n * @param atlasRegions Optional page-backed rigid sources, from createAtlasRegions\n * or ModelAssets.atlasRegions. A matching entry takes precedence over regionImages.\n * @param pages Page images (for the mesh tier), keyed by page name —\n * `PosedMesh.page`. Read on every mesh draw, so a caller may fill it after\n * construction.\n */\n constructor(\n private readonly root: HTMLElement,\n private readonly regionImages: ReadonlyMap<string, RegionImage>,\n private readonly pages: ReadonlyMap<string, HTMLImageElement> = new Map(),\n private readonly atlasRegions: ReadonlyMap<string, AtlasRegion> = new Map(),\n ) {}\n\n /**\n * Backing-store pixels currently allocated across the mesh canvases\n * (Σ width × height). Computed on demand from the views — nothing is\n * tracked per frame — so reading it is cheap but not free; the demo reads it\n * with the other counters, twice a second.\n *\n * This is the quantity `pixelRatio` moves quadratically, and the one that\n * makes an oversampling stage visible before the frame rate does: a root\n * scaled down by CSS without that scale folded into `pixelRatio` holds\n * 1/scale² of the backing it needs. Hidden slots are included — their\n * canvases keep their allocation.\n */\n get meshBackingPixels(): number {\n let total = 0;\n for (const view of this.views.values()) {\n if (view.kind === 'canvas') total += view.canvasW * view.canvasH;\n }\n return total;\n }\n\n /**\n * Re-derives `pixelRatio` from the root's effective on-screen scale, so the\n * mesh tier rasters at the resolution the screen actually shows.\n *\n * Mesh canvases are sized in the root's own coordinates, and a CSS transform\n * anywhere above the root — the natural way to build a pan/zoom stage is\n * `transform: scale(zoom)` on an ancestor — rescales them on screen without\n * the renderer seeing it. At zoom z the raster is then oversampled by 1/z per\n * axis, 1/z² in backing pixels: GPU memory and fill rate, not correctness.\n * This folds the measured scale in, `devicePixelRatio × scale`.\n *\n * One layout read per call. The root itself is usually 0×0 (slot elements are\n * absolutely positioned and posed by transforms), so there is no box to\n * measure: a hidden 100×100 px child is appended, measured once with\n * getBoundingClientRect(), and removed again — nothing of it is left behind.\n * It cannot disturb the slot elements either: they interleave by z-index,\n * which applyCommon() writes explicitly on every visible one, so DOM order is\n * not what orders them; and the probe is `visibility: hidden` and gone before\n * anything can paint.\n *\n * The scale is the larger axis of the measured box. An ancestor rotation\n * inflates that axis-aligned box, so the ratio errs high — the safe side:\n * oversampling costs pixels, undersampling costs picture.\n *\n * A move smaller than 0.1% (see PIXEL_RATIO_DEADBAND) changes nothing, and a\n * root that is not laid out (a `display: none` ancestor — the probe measures\n * 0) changes nothing either. Both matter because writing `pixelRatio`\n * reallocates every mesh canvas on the next frame.\n *\n * The renderer never calls this itself. It is a forced synchronous layout,\n * which has no business in a render path — and there is no per-frame layout\n * read anywhere in this class. Call it when a zoom or a layout settles: after\n * a wheel/pinch gesture ends, on a debounced resize, not during the drag.\n *\n * @returns the pixel ratio now in effect (the current one if nothing moved).\n */\n syncPixelRatio(): number {\n this.pixelRatio = syncedPixelRatio(this.root, this.pixelRatio);\n return this.pixelRatio;\n }\n\n /**\n * Draws one frame. Slots the frame does not carry — no attachment, a\n * clipping attachment, an inactive bone, a kind the DOM tier does not draw —\n * are hidden, their elements kept for when they draw again.\n */\n render(input: PosedFrame | LiveFrame): void {\n const frame = renderFrameOf(input);\n this.clipCount = 0;\n this.rigidRasterCount = 0;\n this.clipSkipCount = 0;\n this.clipWriteCount = 0;\n this.meshCount = 0;\n this.meshReuseCount = 0;\n this.canvasReallocCount = 0;\n this.triangleCount = 0;\n this.clipActive = null;\n this.clipInverse = false;\n this.clipOnRoot = false;\n this.clipsSeen.clear();\n const stamp = ++this.frameNumber;\n const blitter = this.meshBackend === 'webgl' ? getMeshGlBlitter() : null;\n this.meshBackendActive = blitter ? 'webgl' : 'canvas2d';\n this.meshBackendFallbackReason = blitter ? null\n : this.meshBackend === 'webgl' ? meshGlUnavailableReason() : 'not-requested';\n const order = frame.order;\n\n // Whole-skeleton fast path: one clip covers every slot of the frame, so\n // every element is inside it — one clip-path on the root beats one per\n // element. The frame shares one clip object across the slots it covers,\n // so \"every slot\" is an identity test. An inverse clip is excluded: its\n // CSS form needs an outer ring around the element's own box, and the root\n // is an origin element with no box to use.\n const first = order.length > 0 ? order[0].clip : undefined;\n if (first && !first.inverse && this.clipping && first.polygon.length >= 6) {\n let whole = true;\n for (let i = 1, n = order.length; i < n && whole; i++) whole = order[i].clip === first;\n if (whole) {\n this.useClip(first);\n this.clipOnRoot = true;\n this.writeRootClip(this.rootClipPath());\n }\n }\n\n for (let i = 0, n = order.length; i < n; i++) {\n const slot = order[i];\n if (!this.clipOnRoot) this.useClip(slot.clip);\n const drawn = slot.kind === 'region' ? this.renderRegion(slot) : this.renderMesh(slot);\n if (drawn) drawn.drawnIn = stamp;\n }\n for (const view of this.views.values()) if (view.drawnIn !== stamp) this.hide(view);\n // Only a clip that covered the whole frame keeps the root's style; every\n // other frame hands the caller's inline value back.\n if (!this.clipOnRoot) this.releaseRootClip();\n\n if (this.pendingJobs.length) {\n const reason = blitter ? blitter.flush(this.pendingJobs) : this.meshBackendFallbackReason;\n if (reason !== null) {\n // Rasterize this batch on the 2d path so the frame stays complete;\n // the next render() re-selects the backend.\n this.meshBackendActive = 'canvas2d';\n this.meshBackendFallbackReason = reason;\n for (let i = 0; i < this.pendingJobs.length; i++) {\n const job = this.pendingJobs[i];\n this.pendingViews[i].meshBackendDrawn = 'canvas2d';\n this.rasterizeMesh2d(\n job.canvas,\n // The 2d path wants straight alpha where the upload wanted it\n // premultiplied; the derivation is cached, so this costs a lookup.\n straightAlphaSource(job.page, job.pma),\n job.vertices,\n job.uvs,\n job.triangles,\n job.ratio,\n );\n }\n }\n this.pendingJobs.length = 0;\n this.pendingViews.length = 0;\n }\n }\n\n /**\n * Removes every element this renderer added to the root (slot elements and\n * the tint filter defs), restores the root's own inline `clip-path` if the\n * whole-skeleton clip path borrowed it, and hands the atlas pages it\n * uploaded back to the shared GL blitter — the one resource here that outlives the instance, so\n * the one that has to be given back explicitly (GPU memory, and no garbage\n * collector feels pressure from it). The pages are reference-counted there:\n * a page another live renderer still draws stays uploaded, and the texture\n * is deleted only when the last user of it is disposed.\n *\n * The region bitmaps are deliberately untouched: the map is the caller's,\n * and one map is normally shared by many renderers (disposing one instance\n * must not blind the others). Free the unpacked blob URLs with\n * revokeRegions() once no renderer needs them.\n *\n * Idempotent: the retained-page ledger is cleared here, so a second call\n * releases nothing a second time.\n */\n dispose(): void {\n // The root is the caller's element and outlives this renderer, so the\n // borrowed inline clip-path goes back before the slot elements go.\n this.releaseRootClip();\n for (const view of this.views.values()) view.el.remove();\n this.views.clear();\n this.tintDefs?.remove();\n this.tintDefs = null;\n if (this.glPages) {\n const blitter = getMeshGlBlitter();\n if (blitter) for (const page of this.glPages) blitter.release(page);\n this.glPages = null;\n }\n }\n\n // --- rigid tier -----------------------------------------------------------\n\n private renderRegion(slot: PosedRegion): SlotView | null {\n const atlas = this.atlasRegions.get(slot.region);\n const regionImage = atlas ? atlas.region : this.regionImages.get(slot.region);\n if (!regionImage) return null;\n\n const view = this.view(slot.slot, atlas ? 'region-canvas' : 'image');\n\n const corners = slot.corners;\n for (let v = 0; v < 8; v++) regionVertices[v] = corners[v];\n // Corner order is BL, UL, UR, BR — the runtime's, which the poser keeps:\n // the region's UVs run (u,v2), (u,v), (u2,v), (u2,v2) in that order.\n // (The br/bl/ul/ur comments inside spine-core's computeWorldVertices are\n // stale.) Flip Y for CSS (the frame is Y-up).\n const blx = regionVertices[0], bly = -regionVertices[1];\n const ulx = regionVertices[2], uly = -regionVertices[3];\n const urx = regionVertices[4], ury = -regionVertices[5];\n\n const w = regionImage.width;\n const h = regionImage.height;\n const a = (urx - ulx) / w;\n const b = (ury - uly) / w;\n const c = (blx - ulx) / h;\n const d = (bly - uly) / h;\n // pixelRatio is the caller's declared root scale × device ratio; no layout\n // reads here. Include the region's posed affine stretch. Round UP into\n // ×1.25 bands: at most 25% linear over-resolution, never undersampled,\n // and ordinary motion within a band reuses the same native cut raster.\n const effective = this.pixelRatio * Math.max(Math.hypot(a, b), Math.hypot(c, d));\n const band = effective > 0 && effective < 1 ? 1.25 ** Math.ceil(Math.log(effective) / Math.log(1.25)) : 1;\n if (view.regionName !== slot.region || (atlas && view.regionRatio !== band)) {\n view.regionName = slot.region;\n view.regionRatio = band;\n if (atlas) {\n drawAtlasRegion(view.el as HTMLCanvasElement, atlas, band < 1 ? band : undefined);\n view.el.style.width = `${w}px`;\n view.el.style.height = `${h}px`;\n this.rigidRasterCount++;\n } else {\n const img = view.el as HTMLImageElement;\n img.src = this.regionImages.get(slot.region)!.url;\n img.width = w;\n img.height = h;\n }\n }\n this.setTransform(view, `matrix(${a},${b},${c},${d},${ulx},${uly})`);\n // Rigid elements carry a full affine, so the clip polygon rides its\n // inverse into the local (atlas-unit) frame the <img> box spans.\n this.applyClip(view, a, b, c, d, ulx, uly, w, h);\n\n this.applyCommon(view, slot);\n return view;\n }\n\n // --- deform tier ----------------------------------------------------------\n\n private renderMesh(slot: PosedMesh): SlotView | null {\n const sequenceIndex = slot.sequence;\n const page = this.pages.get(slot.page);\n if (!page) return null;\n // Which alpha convention the page's texels are in. The two backends consume\n // opposite ones — GL wants them premultiplied, `drawImage` wants them\n // straight — so this decides what each is handed, never what it does.\n const pma = slot.pma;\n\n const source = slot.vertices;\n const count = source.length;\n if (this.scratchVertices.length < count) this.scratchVertices = new Float32Array(count);\n const vertices = this.scratchVertices;\n for (let v = 0; v < count; v++) vertices[v] = source[v];\n\n // World bounds (in CSS coords: Y negated).\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (let v = 0; v < count; v += 2) {\n const x = vertices[v];\n const y = -vertices[v + 1];\n vertices[v + 1] = y;\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n }\n const pad = 1;\n minX = Math.floor(minX) - pad;\n minY = Math.floor(minY) - pad;\n const w = Math.ceil(maxX) + pad - minX;\n const h = Math.ceil(maxY) + pad - minY;\n if (w <= 0 || h <= 0) return null;\n\n const view = this.view(slot.slot, 'canvas');\n const canvas = view.el as HTMLCanvasElement;\n const ratio = this.pixelRatio;\n const uvs = slot.uvs;\n const triangles = slot.triangles;\n let dirty =\n view.meshUvs !== uvs ||\n view.meshTriangles !== triangles ||\n view.meshPage !== page ||\n view.meshSequenceIndex !== sequenceIndex ||\n view.meshExpand !== this.triangleExpand ||\n view.meshSourceRect !== this.meshSourceRect ||\n view.meshVertexCount !== count ||\n view.meshBackendDrawn !== this.meshBackendActive;\n // The backing store only grows, in 32-device-px steps. Setting\n // canvas.width recreates the GPU surface, and a deforming mesh changes\n // its bbox every frame — reallocating every mesh canvas per frame\n // stalled real Safari to ~3 fps while the JS split showed ~4 ms (the\n // cost lives in the compositor, invisible to in-callback timing). With\n // grow-only quantized backing, steady-state animation reallocates\n // nothing. A pixelRatio change is the one exception to grow-only: it\n // reallocates every mesh canvas anyway, so the new size comes from the\n // new need alone. Keeping the old size as a floor there would make a\n // ratio *drop* pay the reallocation and keep every oversized pixel — the\n // backing would never come back down to what that ratio needs. The CSS\n // size mirrors the whole backing so the pixel mapping stays 1:1; the mesh\n // draws into the top-left w×h logical region and the rest stays\n // transparent.\n const needW = Math.max(1, Math.round(w * ratio));\n const needH = Math.max(1, Math.round(h * ratio));\n const ratioChanged = view.meshRatio !== ratio;\n if (needW > view.canvasW || needH > view.canvasH || ratioChanged) {\n // 25% slack: at low fps the animation is sampled sparsely, so new bbox\n // maxima keep being discovered for many seconds — allocate ahead of the\n // curve instead of chasing it.\n const step = 32;\n const floorW = ratioChanged ? 0 : view.canvasW;\n const floorH = ratioChanged ? 0 : view.canvasH;\n view.canvasW = Math.ceil(Math.max(needW * 1.25, floorW) / step) * step;\n view.canvasH = Math.ceil(Math.max(needH * 1.25, floorH) / step) * step;\n view.meshRatio = ratio;\n canvas.width = view.canvasW;\n canvas.height = view.canvasH;\n canvas.style.width = `${view.canvasW / ratio}px`;\n canvas.style.height = `${view.canvasH / ratio}px`;\n this.canvasReallocCount++;\n dirty = true;\n }\n\n // Compare with the actual last raster, not the last frame: otherwise a\n // sequence of tolerated changes could keep moving the comparison anchor.\n // Whole-pixel translations can leave a vertex off the integer by Float32\n // rounding at a world-coordinate exponent boundary (#130). Allow at most\n // the current coordinate's half-ULP on a translated axis, strictly below\n // half a pixel. Borrowing an old, larger quantum would erase newly precise\n // deformation when moving toward zero. The one shared bbox offset keeps\n // a different integer move of one vertex a deformation, not a translate.\n if (view.meshVertices.length < count) {\n view.meshVertices = new Float64Array(count);\n dirty = true;\n }\n const rel = view.meshVertices;\n if (!dirty) {\n const offsetX = minX - view.meshOriginX;\n const offsetY = minY - view.meshOriginY;\n for (let v = 0; v < count && !dirty; v += 2) {\n dirty = !sameMeshCoordinate(vertices[v] - minX, rel[v], vertices[v], offsetX)\n || !sameMeshCoordinate(vertices[v + 1] - minY, rel[v + 1], vertices[v + 1], offsetY);\n }\n }\n\n this.setTransform(view, `translate(${minX}px,${minY}px)`);\n // A mesh canvas is posed by a translate only, so its local frame is the\n // CSS-space polygon minus that translate. The clip never reaches the\n // raster: it is not part of the dirty signature, and a mesh whose vertices\n // held still still reuses its raster under a moving clip.\n this.applyClip(view, 1, 0, 0, 1, minX, minY, view.canvasW / ratio, view.canvasH / ratio);\n\n if (!dirty) {\n this.meshReuseCount++;\n } else {\n // Commit geometry and its world origin together only when rasterized.\n for (let v = 0; v < count; v += 2) {\n rel[v] = vertices[v] - minX;\n rel[v + 1] = vertices[v + 1] - minY;\n }\n view.meshOriginX = minX;\n view.meshOriginY = minY;\n view.meshUvs = uvs;\n view.meshTriangles = triangles;\n view.meshPage = page;\n view.meshSequenceIndex = sequenceIndex;\n view.meshExpand = this.triangleExpand;\n view.meshSourceRect = this.meshSourceRect;\n view.meshVertexCount = count;\n view.meshBackendDrawn = this.meshBackendActive;\n\n if (this.meshBackendActive === 'webgl') {\n // Queued, not drawn: render() flushes the whole batch through the\n // shared GL context once the slot loop is done. `rel` is this view's\n // own signature array — nothing mutates it before the flush.\n this.pendingJobs.push({\n canvas,\n page,\n pma,\n vertices: rel,\n uvs,\n triangles,\n ratio,\n width: Math.min(view.canvasW, Math.ceil(w * ratio)),\n height: Math.min(view.canvasH, Math.ceil(h * ratio)),\n });\n this.pendingViews.push(view);\n this.retainPage(page);\n } else {\n this.rasterizeMesh2d(canvas, straightAlphaSource(page, pma), rel, uvs, triangles, ratio);\n }\n this.meshCount++;\n this.triangleCount += triangles.length / 3;\n }\n\n this.applyCommon(view, slot);\n return view;\n }\n\n /**\n * Declares this renderer a user of `page` with the shared blitter, once per\n * page — the counterpart of the release in dispose(). The set is this\n * renderer's own ledger, so sharing one page across renderers works by\n * counting rather than by guessing. On the render path this costs one\n * Set.has per queued mesh job and allocates nothing after the first page.\n */\n private retainPage(page: HTMLImageElement): void {\n const pages = (this.glPages ??= new Set<HTMLImageElement>());\n if (pages.has(page)) return;\n // Null only if the context died between the backend pick and here; the\n // flush then fails too and the batch falls back to canvas2d.\n const blitter = getMeshGlBlitter();\n if (!blitter) return;\n pages.add(page);\n blitter.retain(page);\n }\n\n /** The canvas2d raster path: clear the backing, map each triangle. */\n private rasterizeMesh2d(\n canvas: HTMLCanvasElement,\n page: PageSource,\n vertices: Float64Array,\n uvs: ArrayLike<number>,\n triangles: ArrayLike<number>,\n ratio: number,\n ): void {\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n // Clear the full backing: the previous frame's bbox (and so its drawn\n // region) may have been larger than today's.\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n ctx.setTransform(ratio, 0, 0, ratio, 0, 0);\n\n // Texel addressing, shared with the GL blitter: a normalized UV maps to\n // `uv * size` in the continuous texture frame where the page spans\n // [0, size] and texel i covers [i, i+1). drawImage-under-a-transform and\n // texture2D() both read that frame, so both backends land on the same\n // source pixels. (No half-texel term: the affine below *maps* corners, it\n // does not sample — see drawTriangle.) `page` is the page image, or its\n // straight-alpha derivation on a premultiplied one; the derivation is the\n // image's own natural size, so the frame is the same either way.\n const uw = page.width;\n const uh = page.height;\n triangles = triangleReadSource(triangles);\n for (let t = 0; t < triangles.length; t += 3) {\n const i0 = triangles[t] * 2;\n const i1 = triangles[t + 1] * 2;\n const i2 = triangles[t + 2] * 2;\n this.drawTriangle(\n ctx, page,\n vertices[i0], vertices[i0 + 1], uvs[i0] * uw, uvs[i0 + 1] * uh,\n vertices[i1], vertices[i1 + 1], uvs[i1] * uw, uvs[i1 + 1] * uh,\n vertices[i2], vertices[i2 + 1], uvs[i2] * uw, uvs[i2 + 1] * uh,\n );\n }\n }\n\n /**\n * Standard canvas triangle texture mapping (same math as the official\n * spine-canvas renderer): derive the affine that sends the triangle's\n * texture-space corners to its screen-space corners, clip, draw the page —\n * but only the part of the page this triangle can show (see below).\n *\n * The clip polygon is expanded outward from the centroid by a fraction of\n * a pixel. Browsers that antialias clip paths (Safari) otherwise leave\n * hairline cracks between adjacent triangles; the expanded clips overlap\n * into the neighbouring triangle, and since the texture is continuous\n * across the shared edge the overlap draws the same pixels — cracks close\n * with no visible cost. The texture-mapping affine itself stays exact.\n *\n * ## Why a source sub-rect instead of the whole page\n *\n * The draw is a 9-argument `drawImage` whose source rect covers exactly what\n * the clip can reveal, placed at the same texture-space position, so the\n * mapping is identical to drawing the whole page — the same affine, the same\n * texels, only fewer of them offered to the rasterizer.\n *\n * That is not an optimization. Linux WebKit — the software rasterizer, the\n * only engine this has been observed on; Chromium and macOS WebKit never show\n * it — garbles individual triangles when the whole page is drawn under a\n * steep per-triangle affine: read off the parity dump, head/goggles/foot\n * triangles land with displaced texture while the webgl capture of the same\n * pose stays clean. Switching this one call to a source sub-rect — the only\n * variable changed — took that platform's bad-pixel counts from 1042 to 2\n * (hoverboard), 231 to 4 (portal) and 803 to 3 (walk + tint), and left every\n * Chromium capture byte-identical. [measured on the ubuntu CI runner through\n * PARITY_DUMP: first with a fixed 2-texel pad (run 35209262693), then with\n * the derived rect below — the same counts (run 35213286993).] WHY that\n * rasterizer garbles the whole-page form is not identified; steep affines\n * making whole-page coordinates large is a suspicion, not a measurement. The\n * sub-rect sidesteps it. (Moving `clip()` before `transform()` was tried as a\n * separate one-variable experiment: every number came back identical, so the\n * clip path is not the cause.)\n *\n * ## How the sub-rect is derived\n *\n * It must provably cover everything the clip can reveal, which is the\n * *expanded* polygon, not the triangle. So each clip corner's canvas-space\n * displacement is pushed back through the inverse of the 2×2 affine into\n * texture space, the bounding box is taken over the displaced corners, one\n * texel of bilinear support is added, and the result is floor/ceil'd to texel\n * boundaries (so the sub-rect itself resamples nothing) and clamped to the\n * page. A fixed pad would not do: the texture-space reach of the expansion is\n * `triangleExpand` times the local texels-per-canvas-unit (up to\n * `MITRE_LIMIT` times that at a sharp corner), which on the demo's own meshes\n * ranged from ~0.26 texels on a typical triangle to ~8.6 on a foreshortened\n * one. Under-padding lets the rim of the overdraw sample\n * nothing, which brings back the very seams the overdraw exists to close.\n *\n * No half-texel offset is applied to the incoming u/v: the `(i + 0.5) / size`\n * texel-centre convention belongs to *sampling* (landing inside the intended\n * texel instead of on a filter boundary). This solves for the affine that\n * sends three source corners to three destination corners; the rasterizer\n * then samples continuously along that map. Biasing all three corners by\n * half a texel would translate the texture against the geometry — the very\n * class of offset the `uv * size` addressing removes.\n */\n private drawTriangle(\n ctx: CanvasRenderingContext2D, img: PageSource,\n x0: number, y0: number, u0: number, v0: number,\n x1: number, y1: number, u1: number, v1: number,\n x2: number, y2: number, u2: number, v2: number,\n ): void {\n drawTexturedTriangle(ctx, img, this.triangleExpand, this.meshSourceRect, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);\n }\n\n // --- clipping tier ---------------------------------------------------------\n\n /**\n * Makes `clip` the clip in force for the slot about to be drawn, loading its\n * polygon when it is not the one already loaded. Each clip object is counted\n * once per frame — in clipCount when applied, in clipSkipCount when\n * `clipping` is off or the polygon has fewer than three points (no clip is\n * in force then, so the slot draws unclipped, as the runtime would).\n *\n * The polygon is the poser's world-space one, and the only things done to it\n * here are the single-precision read the vertex paths share and the Y\n * negation the rest of the renderer already applies. It is NOT convexified\n * or triangulated the way the CPU clipper does — CSS `polygon()` takes a\n * concave polygon directly, so the decomposition that exists to feed a\n * triangle rasterizer has no job here.\n */\n private useClip(clip: PosedClip | undefined): void {\n if (!clip) {\n this.clipActive = null;\n return;\n }\n if (clip === this.clipActive) return;\n const count = clip.polygon.length;\n const counted = this.clipsSeen.has(clip);\n if (!this.clipping || count < 6) {\n if (!counted) {\n this.clipsSeen.add(clip);\n this.clipSkipCount++;\n }\n this.clipActive = null;\n return;\n }\n if (!counted) {\n this.clipsSeen.add(clip);\n this.clipCount++;\n }\n const polygon = clip.polygon;\n if (this.scratchVertices.length < count) this.scratchVertices = new Float32Array(count);\n const world = this.scratchVertices;\n for (let v = 0; v < count; v++) world[v] = polygon[v];\n if (this.clipPolygon.length < count) this.clipPolygon = new Float64Array(count);\n const poly = this.clipPolygon;\n for (let v = 0; v < count; v += 2) {\n poly[v] = world[v];\n poly[v + 1] = -world[v + 1]; // The frame is Y-up, CSS is Y-down.\n }\n this.clipPolygonLength = count;\n this.clipActive = clip;\n this.clipInverse = clip.inverse;\n }\n\n /**\n * Writes (or clears) this element's clip-path. `a…f` is the element's own\n * CSS transform, and the world polygon is carried through its INVERSE:\n * clip-path is resolved in the element's local frame and then transformed\n * along with the element, so the polygon has to arrive there already.\n *\n * `transform-origin` is `0 0` on every slot element (see view()), so the\n * matrix maps local (0,0) to (e,f) with no origin term to undo, and\n * `left/top: 0` puts the border box — clip-path's reference box — on that\n * same local origin.\n */\n private applyClip(\n view: SlotView,\n a: number,\n b: number,\n c: number,\n d: number,\n e: number,\n f: number,\n boxW: number,\n boxH: number,\n ): void {\n if (!this.clipActive || this.clipOnRoot) {\n this.setClipPath(view, '');\n return;\n }\n const det = a * d - b * c;\n // Singular: the element is collapsed onto a line or a point and draws\n // nothing, so there is no clip to express and no style write to pay for.\n if (det === 0) return;\n const inv = 1 / det;\n const poly = this.clipPolygon;\n const n = this.clipPolygonLength;\n // An inverse clip shows what is OUTSIDE the polygon. That shape has a hole\n // in it, so it needs TWO rings — an outer one and the polygon — and\n // `polygon()` cannot carry two: it is one closed ring, and listing a box\n // and a polygon inside it just makes one self-intersecting ring whose\n // even-odd fill leaves a wedge of the seam between them (measured, on a\n // corner of spineboy's boot). `path()` takes subpaths, so an inverse clip\n // is written as two of them with the even-odd rule. The outer ring is the\n // element's own box: the element paints nothing outside it anyway, so\n // box-minus-polygon is exactly the visible part of the inverse region.\n const inverse = this.clipInverse;\n let s = inverse\n ? `path(evenodd,'M0 0H${clipNum(boxW)}V${clipNum(boxH)}H0Z`\n : 'polygon(';\n for (let v = 0; v < n; v += 2) {\n const dx = poly[v] - e;\n const dy = poly[v + 1] - f;\n const lx = (d * dx - c * dy) * inv;\n const ly = (a * dy - b * dx) * inv;\n // Near-singular matrices blow the inverse up; see CLIP_COORD_LIMIT for\n // why an unwritable coordinate must not become a written-and-ignored one.\n if (!(Math.abs(lx) <= CLIP_COORD_LIMIT) || !(Math.abs(ly) <= CLIP_COORD_LIMIT)) return;\n if (inverse) {\n s += `${v > 0 ? 'L' : 'M'}${clipNum(lx)} ${clipNum(ly)}`;\n } else {\n s += `${v > 0 ? ',' : ''}${clipCoord(lx)} ${clipCoord(ly)}`;\n }\n }\n this.setClipPath(view, inverse ? `${s}Z')` : `${s})`);\n }\n\n private setClipPath(view: SlotView, clipPath: string): void {\n if (view.clipPath === clipPath) return;\n view.clipPath = clipPath;\n view.el.style.clipPath = clipPath;\n this.clipWriteCount++;\n }\n\n /** The active polygon in the root's own frame — no element transform. */\n private rootClipPath(): string {\n const poly = this.clipPolygon;\n let s = 'polygon(';\n for (let v = 0, n = this.clipPolygonLength; v < n; v += 2) {\n if (v > 0) s += ',';\n s += `${clipCoord(poly[v])} ${clipCoord(poly[v + 1])}`;\n }\n return `${s})`;\n }\n\n private writeRootClip(clipPath: string): void {\n // Borrow the caller's inline value once, so releaseRootClip gives back\n // exactly what was there. Reading `.style` is CSSOM, not a layout read.\n if (this.rootClipSaved === null) this.rootClipSaved = this.root.style.clipPath;\n if (this.rootClipWritten === clipPath) return;\n this.rootClipWritten = clipPath;\n this.root.style.clipPath = clipPath;\n this.clipWriteCount++;\n }\n\n private releaseRootClip(): void {\n if (this.rootClipSaved === null) return;\n this.root.style.clipPath = this.rootClipSaved;\n this.rootClipSaved = null;\n this.rootClipWritten = '';\n this.clipWriteCount++;\n }\n\n // --- shared plumbing -------------------------------------------------------\n\n private setTransform(view: SlotView, transform: string): void {\n if (view.transform !== transform) {\n view.transform = transform;\n view.el.style.transform = transform;\n }\n }\n\n private applyCommon(view: SlotView, slot: PosedSlot): void {\n const zIndex = slot.z;\n const tint = slot.tint;\n if (view.zIndex !== zIndex) {\n view.zIndex = zIndex;\n view.el.style.zIndex = String(zIndex);\n }\n const alpha = tint[3];\n if (view.opacity !== alpha) {\n view.opacity = alpha;\n view.el.style.opacity = alpha === 1 ? '' : String(alpha);\n }\n // RGB tint (uniform per slot) rides an feColorMatrix reference filter:\n // scaling the channels is an exact multiply, applies to <img> and\n // <canvas> alike, and never touches the raster. Needs reference-filter\n // support (Safari 15+).\n const r = tint[0];\n const g = tint[1];\n const b = tint[2];\n if (view.tintR !== r || view.tintG !== g || view.tintB !== b) {\n view.tintR = r;\n view.tintG = g;\n view.tintB = b;\n if (r === 1 && g === 1 && b === 1) {\n view.el.style.filter = '';\n } else {\n this.tintMatrixFor(view).setAttribute(\n 'values',\n `${r} 0 0 0 0 0 ${g} 0 0 0 0 0 ${b} 0 0 0 0 0 1 0`,\n );\n view.el.style.filter = `url(#${view.tintId})`;\n }\n }\n const blendMode = slot.blend;\n if (view.blendMode !== blendMode) {\n view.blendMode = blendMode;\n view.el.style.mixBlendMode = BLEND_CSS[blendMode];\n }\n if (!view.visible) {\n view.visible = true;\n view.el.style.display = '';\n }\n }\n\n private tintMatrixFor(view: SlotView): SVGFEColorMatrixElement {\n if (view.tintMatrix) return view.tintMatrix;\n if (!this.tintDefs) {\n const svg = document.createElementNS(SVG_NS, 'svg');\n svg.setAttribute('width', '0');\n svg.setAttribute('height', '0');\n svg.style.position = 'absolute';\n this.root.appendChild(svg);\n this.tintDefs = svg;\n }\n const filter = document.createElementNS(SVG_NS, 'filter');\n view.tintId = `rig-play-tint-${tintFilterSeq++}`;\n filter.setAttribute('id', view.tintId);\n // Filter math must happen in sRGB to match Spine's color multiply\n // (SVG filters default to linearRGB).\n filter.setAttribute('color-interpolation-filters', 'sRGB');\n const matrix = document.createElementNS(SVG_NS, 'feColorMatrix');\n matrix.setAttribute('in', 'SourceGraphic');\n matrix.setAttribute('type', 'matrix');\n filter.appendChild(matrix);\n this.tintDefs.appendChild(filter);\n view.tintMatrix = matrix;\n return matrix;\n }\n\n private view(slot: string, kind: SlotKind): SlotView {\n let view = this.views.get(slot);\n if (view && view.kind !== kind) {\n view.el.remove();\n view.tintMatrix?.parentElement?.remove();\n view = undefined;\n }\n if (!view) {\n const el = kind === 'image' ? document.createElement('img') : document.createElement('canvas');\n if (el instanceof HTMLImageElement) el.draggable = false;\n el.style.position = 'absolute';\n el.style.left = '0';\n el.style.top = '0';\n el.style.transformOrigin = '0 0';\n el.style.pointerEvents = 'none';\n el.style.userSelect = 'none';\n el.style.display = 'none';\n view = {\n kind,\n el,\n regionName: '',\n regionRatio: -1,\n visible: false,\n zIndex: -1,\n opacity: 1,\n blendMode: 'Normal',\n transform: '',\n clipPath: '',\n tintR: 1,\n tintG: 1,\n tintB: 1,\n tintId: '',\n tintMatrix: null,\n canvasW: 0,\n canvasH: 0,\n meshRatio: -1,\n meshUvs: null,\n meshTriangles: null,\n meshPage: null,\n meshSequenceIndex: -1,\n meshExpand: -1,\n meshSourceRect: '',\n meshVertexCount: -1,\n meshBackendDrawn: '',\n meshVertices: new Float64Array(0),\n meshOriginX: 0,\n meshOriginY: 0,\n drawnIn: 0,\n };\n this.views.set(slot, view);\n this.root.appendChild(el);\n }\n return view;\n }\n\n private hide(view: SlotView): void {\n if (view.visible) {\n view.visible = false;\n view.el.style.display = 'none';\n }\n // A hidden element keeps no clip-path: one left behind would sit there\n // stale until the slot draws again, and \"nothing is clipped\" has to be\n // true of the DOM, not only of what gets painted. Cached like every other\n // write, so the sweep costs one write per element, once.\n this.setClipPath(view, '');\n }\n}\n\n/**\n * The body of `DomRenderer.drawTriangle` (see it for the mapping, the clip\n * overdraw and the source sub-rect), as a function so the canvas render mode's\n * 2d fallback draws its triangles through the same code.\n *\n * @internal Not part of the package API.\n */\nexport function drawTexturedTriangle(\n ctx: CanvasRenderingContext2D, img: PageSource, expand: number, sourceRect: MeshSourceRect,\n x0: number, y0: number, u0: number, v0: number,\n x1: number, y1: number, u1: number, v1: number,\n x2: number, y2: number, u2: number, v2: number,\n): void {\n const corners = offsetTriangle(x0, y0, x1, y1, x2, y2, expand);\n const px0 = corners[0], py0 = corners[1];\n const px1 = corners[2], py1 = corners[3];\n const px2 = corners[4], py2 = corners[5];\n ctx.beginPath();\n ctx.moveTo(px0, py0);\n ctx.lineTo(px1, py1);\n ctx.lineTo(px2, py2);\n ctx.closePath();\n\n // Edge vectors, in canvas space and in texture space.\n const ex1 = x1 - x0, ey1 = y1 - y0;\n const ex2 = x2 - x0, ey2 = y2 - y0;\n const eu1 = u1 - u0, ev1 = v1 - v0;\n const eu2 = u2 - u0, ev2 = v2 - v0;\n\n let det = eu1 * ev2 - eu2 * ev1;\n if (det === 0) return;\n det = 1 / det;\n\n const a = (ev2 * ex1 - ev1 * ex2) * det;\n const b = (ev2 * ey1 - ev1 * ey2) * det;\n const c = (eu1 * ex2 - eu2 * ex1) * det;\n const d = (eu1 * ey2 - eu2 * ey1) * det;\n const e = x0 - a * u0 - c * v0;\n const f = y0 - b * u0 - d * v0;\n\n if (sourceRect === 'page') {\n ctx.save();\n ctx.transform(a, b, c, d, e, f);\n ctx.clip();\n ctx.drawImage(img, 0, 0);\n ctx.restore();\n return;\n }\n\n // Texture-space bounds of the clip polygon. The triangle's own corners\n // first, then the three expansion offsets carried back through the inverse\n // of [[a, c], [b, d]] — the clip reaches exactly that far and no further.\n let minU = Math.min(u0, u1, u2);\n let maxU = Math.max(u0, u1, u2);\n let minV = Math.min(v0, v1, v2);\n let maxV = Math.max(v0, v1, v2);\n const detM = a * d - b * c;\n if (detM !== 0) {\n const im = 1 / detM;\n const ia = d * im, ic = -c * im, ib = -b * im, id = a * im;\n let gx = px0 - x0, gy = py0 - y0;\n let tu = u0 + ia * gx + ic * gy, tv = v0 + ib * gx + id * gy;\n minU = Math.min(minU, tu); maxU = Math.max(maxU, tu);\n minV = Math.min(minV, tv); maxV = Math.max(maxV, tv);\n gx = px1 - x1; gy = py1 - y1;\n tu = u1 + ia * gx + ic * gy; tv = v1 + ib * gx + id * gy;\n minU = Math.min(minU, tu); maxU = Math.max(maxU, tu);\n minV = Math.min(minV, tv); maxV = Math.max(maxV, tv);\n gx = px2 - x2; gy = py2 - y2;\n tu = u2 + ia * gx + ic * gy; tv = v2 + ib * gx + id * gy;\n minU = Math.min(minU, tu); maxU = Math.max(maxU, tu);\n minV = Math.min(minV, tv); maxV = Math.max(maxV, tv);\n }\n // One texel of bilinear support on every side, snapped outward to texel\n // boundaries, clamped to the page. Source rect and destination rect are the\n // same rect in texture space, so the affine below maps it exactly as it\n // mapped the whole page.\n const sx = Math.max(0, Math.floor(minU - 1));\n const sy = Math.max(0, Math.floor(minV - 1));\n const sw = Math.min(img.width, Math.ceil(maxU + 1)) - sx;\n const sh = Math.min(img.height, Math.ceil(maxV + 1)) - sy;\n if (!(sw > 0) || !(sh > 0)) return;\n\n ctx.save();\n ctx.transform(a, b, c, d, e, f);\n ctx.clip();\n ctx.drawImage(img, sx, sy, sw, sh, sx, sy, sw, sh);\n ctx.restore();\n}\n","import { renderFrameOf } from './liveFrameSource.js';\nimport type { LiveFrame } from './liveFrame.js';\nimport { syncedPixelRatio } from './pixelRatio.js';\nimport { clipThrough, REGION_TRIANGLES } from '@rig-c/core/core';\nimport { defaultMeshSourceRect, drawTexturedTriangle, type MeshSourceRect } from './DomRenderer.js';\nimport { type PageSource, straightAlphaSource } from './DomTexture.js';\nimport { type FrameRun, getMeshGlBlitter, meshGlUnavailableReason, triangleReadSource, type WebGLFallbackReason } from './MeshGlBlitter.js';\nimport type { BlendMode, PosedClip, PosedFrame, PosedSlot } from './posedFrame.js';\n\n/** What actually drew the last frame of a `CanvasRenderer`. */\nexport type CanvasBackend = 'webgl' | 'canvas2d';\n\n/** A rectangle of world space, Y up: `x`, `y` is its bottom-left corner. */\nexport interface CanvasViewport {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nconst BLEND_CODE: Record<BlendMode, number> = { Normal: 0, Additive: 1, Multiply: 2, Screen: 3 };\nconst COMPOSITE: Record<BlendMode, GlobalCompositeOperation> = {\n Normal: 'source-over',\n Additive: 'lighter',\n Multiply: 'multiply',\n Screen: 'screen',\n};\n/** Root units added round the drawn bounds when the automatic viewport grows. */\nconst GROW_PAD = 16;\n\ntype Point = { readonly x: number; readonly y: number };\nconst composedClips = new WeakMap<PosedSlot, { source: PosedSlot; shift: Point; origin: Point; scale: Point }>();\n\n/** @internal Keep the stock clip input for the composed Canvas2D draw. */\nexport function rememberComposedClip(slot: PosedSlot, source: PosedSlot, shift: Point, origin: Point, scale: Point): PosedSlot {\n if (source.clip) composedClips.set(slot, { source, shift, origin, scale });\n return slot;\n}\n\n/**\n * Renders a posed frame (`PosedFrame`) into **one `<canvas>`** — the canvas\n * render mode, beside the DOM tier (`DomRenderer`) and with the same\n * `render(frame)` interface.\n *\n * Every slot is drawn as textured triangles straight from its atlas page — a\n * region as two triangles over its four corners and its page UVs, a mesh as its\n * own triangles — through the **shared module-level WebGL context** of the mesh\n * blitter (`MeshGlBlitter.ts`), into one rect of its offscreen buffer, and the\n * rect is copied onto this renderer's visible canvas with one `drawImage`. No\n * context is created per renderer, so any number of players draw under the\n * browser's ~16-context cap, and the page textures are shared and\n * reference-counted with every other renderer on the page.\n *\n * - **Tint** (slot × attachment × the player's colour) is a vertex colour,\n * premultiplied by its alpha; the **dark** (two-colour) tint is a second\n * vertex colour, carried only when some slot of the frame has one.\n * - **Blend** is batch state: a run of triangles ends wherever the page or the\n * blend mode changes (`drawCalls`, and `blendFlushes` for the blend changes).\n * The blends are composed inside this canvas's own rect, which starts\n * transparent — an additive or multiply slot meets the slots under it, not\n * the page behind the canvas.\n * - **Clipping** is the core's cut: every triangle a clip covers goes through\n * `clipThrough` from `rig-c/core` (convex polygons by the runtime's measured\n * rule, concave ones into convex pieces, inverse clips as the hull's\n * outside). No stencil, no `clip-path`.\n * - **Projection**: the canvas covers a rect of the root's own coordinates\n * (world x, world −y — the DOM tier's frame), so a world point lands at\n * `((x − left) · pixelRatio, (−y − top) · pixelRatio)` device px. That rect\n * is the caller's `viewport` when set, and otherwise grows to cover what the\n * frames draw (grow-only, so steady animation reallocates nothing).\n * - **Dirty-skip**: a frame whose record equals the last one drawn — vertex\n * arrays, tints, order, clips, pages — draws nothing (`framesReused`).\n *\n * When WebGL is unavailable or the shared context is lost, the frame is drawn\n * on the same visible canvas with canvas2d: regions by `drawImage` under their\n * affine, meshes and clipped pieces by the DOM tier's per-triangle mapping.\n * That fallback multiplies **alpha only** — RGB and dark tints are not drawn\n * there (`ctx.filter` is not available on Safari) — and it is a safety net,\n * not the measured path.\n */\nexport class CanvasRenderer {\n /**\n * Backing-store pixels per root CSS pixel; defaults to the device pixel\n * ratio. A root under a CSS-scaled ancestor rasters at the wrong resolution\n * until the scale is folded in — `syncPixelRatio()` measures it, as for the\n * DOM tier. The next `render` sizes the backing store to the new ratio.\n */\n pixelRatio = typeof devicePixelRatio === 'number' ? devicePixelRatio : 1;\n /** Apply the clips the frame carries (default). False draws every slot unclipped and counts the clips in `clipSkipCount`. */\n clipping = true;\n /**\n * The world rect the canvas covers. Null (default) sizes it from the frames\n * themselves: it grows to cover everything drawn and never shrinks. Set it to\n * pin the canvas to a stage box; what falls outside is not drawn.\n */\n viewport: CanvasViewport | null = null;\n /** The backend to draw with: 'webgl' (default) through the shared context, or 'canvas2d' to force the fallback. */\n backend: CanvasBackend = 'webgl';\n /** What the canvas2d fallback draws each mesh triangle from — as `DomRenderer.meshSourceRect`, with the same default. */\n meshSourceRect: MeshSourceRect = defaultMeshSourceRect();\n /** What drew the last frame (or would have, had it not been reused). */\n backendActive: CanvasBackend = 'webgl';\n /** Why the last render selected canvas2d. Null before rendering or when WebGL was selected. */\n backendFallbackReason: WebGLFallbackReason | null = null;\n /** The visible canvas — the renderer's one element in the root. */\n readonly canvas: HTMLCanvasElement;\n\n /** Draw calls issued last frame — one per run of one page under one blend. */\n drawCalls = 0;\n /** Of those runs, how many began because the blend mode changed. */\n blendFlushes = 0;\n /** Triangles drawn last frame, clipped pieces counted as cut. */\n trianglesDrawn = 0;\n /** 1 when the last render() found the record unchanged and drew nothing, else 0. */\n framesReused = 0;\n /** Blits onto the visible canvas last frame (0 or 1). */\n blits = 0;\n /** Visible-canvas backing reallocations last frame; settles at zero. */\n canvasReallocCount = 0;\n /** Distinct clips applied last frame. */\n clipCount = 0;\n /** Clips in the frame not applied last frame: `clipping` off, fewer than three points, or a polygon the core refuses to cut. */\n clipSkipCount = 0;\n\n private readonly ctx: CanvasRenderingContext2D | null;\n /** The rect in root units the canvas covers: left, top, right, bottom (Y down). Empty until the first frame. */\n private left = 0;\n private top = 0;\n private right = 0;\n private bottom = 0;\n private hasRect = false;\n private backingW = 0;\n private backingH = 0;\n private backingRatio = -1;\n private data = new Float32Array(4096);\n private readonly runs: FrameRun[] = [];\n /** Pages retained from the shared blitter, one retain each, released by dispose(). */\n private readonly glPages = new Set<HTMLImageElement>();\n /** The dirty signature of the last frame drawn: its numbers, and the objects it compares by identity. */\n private sig = new Float64Array(256);\n private sigLength = -1;\n private sigRefs: unknown[] = [];\n private nextSig = new Float64Array(256);\n private nextRefs: unknown[] = [];\n\n /**\n * @param root Positioned element that becomes the skeleton origin, exactly as\n * for `DomRenderer`: the canvas is appended to it and placed in its own\n * coordinates; layout and scaling of the root belong to the caller.\n * @param pages Page images keyed by page name — `PosedRegion.page` and\n * `PosedMesh.page`. Read on every draw.\n */\n constructor(\n private readonly root: HTMLElement,\n private readonly pages: ReadonlyMap<string, HTMLImageElement>,\n ) {\n const canvas = document.createElement('canvas');\n canvas.style.position = 'absolute';\n canvas.style.left = '0';\n canvas.style.top = '0';\n canvas.style.transformOrigin = '0 0';\n canvas.style.pointerEvents = 'none';\n canvas.style.userSelect = 'none';\n canvas.width = 0;\n canvas.height = 0;\n this.canvas = canvas;\n this.ctx = canvas.getContext('2d');\n root.appendChild(canvas);\n }\n\n /** Grows the automatic viewport to cover `box` (world units, Y up) ahead of the frames reaching it. */\n /**\n * Measures the root's effective on-screen scale and sets `pixelRatio` to\n * `devicePixelRatio × scale`, returning the ratio now in effect — the same\n * call, the same meaning and the same deadband as `DomRenderer`'s, so code\n * written against `player.renderer` survives a `mode` change. One forced\n * layout per call (a hidden box appended to the root, read, removed), which\n * is why the renderer never calls it for you. The backing store follows on\n * the next `render`; a root that is not laid out leaves the ratio alone.\n */\n syncPixelRatio(): number {\n this.pixelRatio = syncedPixelRatio(this.root, this.pixelRatio);\n return this.pixelRatio;\n }\n\n reserve(box: CanvasViewport): void {\n this.growTo(box.x, -(box.y + box.height), box.x + box.width, -box.y);\n }\n\n /** Draws one frame. */\n render(input: PosedFrame | LiveFrame): void {\n const frame = renderFrameOf(input);\n this.drawCalls = 0;\n this.blendFlushes = 0;\n this.trianglesDrawn = 0;\n this.framesReused = 0;\n this.blits = 0;\n this.canvasReallocCount = 0;\n this.clipCount = 0;\n this.clipSkipCount = 0;\n const blitter = this.backend === 'webgl' ? getMeshGlBlitter() : null;\n this.backendActive = blitter ? 'webgl' : 'canvas2d';\n this.backendFallbackReason = blitter ? null\n : this.backend === 'webgl' ? meshGlUnavailableReason() : 'not-requested';\n const order = frame.order;\n\n // The rect: the caller's, or the grow-only cover of what this frame draws.\n const view = this.viewport;\n if (view) {\n this.setRect(Math.floor(view.x), Math.floor(-(view.y + view.height)), Math.ceil(view.x + view.width), Math.ceil(-view.y));\n } else {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (let i = 0; i < order.length; i++) {\n const slot = order[i];\n const v = slot.kind === 'region' ? slot.corners : slot.vertices;\n for (let k = 0; k + 1 < v.length; k += 2) {\n const x = v[k];\n const y = -v[k + 1];\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n }\n }\n if (minX <= maxX && minY <= maxY) this.growTo(minX, minY, maxX, maxY);\n }\n this.sizeBacking();\n\n if (!this.signatureChanged(order)) {\n this.framesReused = 1;\n this.countClips(order);\n return;\n }\n if (this.backingW === 0 || this.backingH === 0) return;\n\n if (blitter) {\n this.buildVertices(order);\n const reason = blitter.flushFrame({ canvas: this.canvas, width: this.backingW, height: this.backingH, data: this.data, stride: this.stride, runs: this.runs });\n if (reason === null) {\n this.blits = 1;\n return;\n }\n // Draw this frame on the fallback; the next render() re-selects.\n this.backendActive = 'canvas2d';\n this.backendFallbackReason = reason;\n this.sigLength = -1;\n if (order.some(slot => composedClips.has(slot))) {\n // The fallback cuts the stock geometry and counts the pieces it draws.\n this.drawCalls = this.blendFlushes = this.trianglesDrawn = 0;\n this.clipCount = this.clipSkipCount = 0;\n }\n }\n this.draw2d(order);\n }\n\n /** Removes the canvas from the root and hands the pages it uploaded back to the shared blitter. Idempotent. */\n dispose(): void {\n this.canvas.remove();\n if (this.glPages.size) {\n const blitter = getMeshGlBlitter();\n if (blitter) for (const page of this.glPages) blitter.release(page);\n this.glPages.clear();\n }\n this.sigLength = -1;\n }\n\n // --- the rect -------------------------------------------------------------\n\n private growTo(minX: number, minY: number, maxX: number, maxY: number): void {\n if (this.hasRect && minX >= this.left && minY >= this.top && maxX <= this.right && maxY <= this.bottom) return;\n if (!this.hasRect) {\n this.setRect(Math.floor(minX) - GROW_PAD, Math.floor(minY) - GROW_PAD, Math.ceil(maxX) + GROW_PAD, Math.ceil(maxY) + GROW_PAD);\n return;\n }\n // Grow with slack on the side that was outgrown, so a pose sampled sparsely\n // does not reallocate on every new extreme it finds.\n const slackX = Math.max(GROW_PAD, Math.round((this.right - this.left) / 4));\n const slackY = Math.max(GROW_PAD, Math.round((this.bottom - this.top) / 4));\n this.setRect(\n minX < this.left ? Math.floor(minX) - slackX : this.left,\n minY < this.top ? Math.floor(minY) - slackY : this.top,\n maxX > this.right ? Math.ceil(maxX) + slackX : this.right,\n maxY > this.bottom ? Math.ceil(maxY) + slackY : this.bottom,\n );\n }\n\n private setRect(left: number, top: number, right: number, bottom: number): void {\n if (this.hasRect && left === this.left && top === this.top && right === this.right && bottom === this.bottom) return;\n this.left = left;\n this.top = top;\n this.right = Math.max(left, right);\n this.bottom = Math.max(top, bottom);\n this.hasRect = true;\n this.canvas.style.transform = `translate(${left}px,${top}px)`;\n }\n\n /** The backing store at `rect × pixelRatio`; reallocated only when that changes. */\n private sizeBacking(): void {\n const ratio = this.pixelRatio;\n const w = this.hasRect ? Math.max(0, Math.ceil((this.right - this.left) * ratio)) : 0;\n const h = this.hasRect ? Math.max(0, Math.ceil((this.bottom - this.top) * ratio)) : 0;\n if (w === this.backingW && h === this.backingH && ratio === this.backingRatio) return;\n this.backingW = w;\n this.backingH = h;\n this.backingRatio = ratio;\n this.canvas.width = w;\n this.canvas.height = h;\n this.canvas.style.width = `${w / ratio}px`;\n this.canvas.style.height = `${h / ratio}px`;\n this.canvasReallocCount++;\n this.sigLength = -1;\n }\n\n // --- dirty-skip -----------------------------------------------------------\n\n /** Writes this frame's signature and compares it with the last one drawn; keeps it when it differs. */\n private signatureChanged(order: PosedSlot[]): boolean {\n let n = 0;\n const refs = this.nextRefs;\n refs.length = 0;\n let sig = this.nextSig;\n const need = (k: number): void => {\n if (n + k > sig.length) {\n const grown = new Float64Array(Math.max(sig.length * 2, n + k));\n grown.set(sig.subarray(0, n));\n sig = grown;\n this.nextSig = grown;\n }\n };\n need(9);\n sig[n++] = this.meshSourceRect === 'triangle' ? 1 : 0;\n sig[n++] = this.left;\n sig[n++] = this.top;\n sig[n++] = this.backingW;\n sig[n++] = this.backingH;\n sig[n++] = this.backingRatio;\n sig[n++] = this.backendActive === 'webgl' ? 1 : 0;\n sig[n++] = this.clipping ? 1 : 0;\n sig[n++] = order.length;\n const stockClipping = this.backendActive === 'canvas2d' && this.clipping;\n let lastClip: PosedClip | undefined;\n for (let i = 0; i < order.length; i++) {\n const slot = order[i];\n const v = slot.kind === 'region' ? slot.corners : slot.vertices;\n const clip = slot.clip;\n need(10 + v.length + (clip && clip !== lastClip ? clip.polygon.length + 3 : 1));\n sig[n++] = slot.kind === 'region' ? 0 : 1;\n sig[n++] = BLEND_CODE[slot.blend];\n const t = slot.tint;\n sig[n++] = t[0];\n sig[n++] = t[1];\n sig[n++] = t[2];\n sig[n++] = t[3];\n const d = slot.dark;\n sig[n++] = d ? d[0] : -1;\n sig[n++] = d ? d[1] : -1;\n sig[n++] = d ? d[2] : -1;\n sig[n++] = v.length;\n for (let k = 0; k < v.length; k++) sig[n++] = v[k];\n if (!clip) {\n sig[n++] = 0;\n } else if (clip === lastClip) {\n sig[n++] = 1;\n } else {\n sig[n++] = 2;\n sig[n++] = (clip.inverse ? 1 : 0) + (clip.convex ? 2 : 0);\n sig[n++] = clip.polygon.length;\n for (let k = 0; k < clip.polygon.length; k++) sig[n++] = clip.polygon[k];\n lastClip = clip;\n }\n if (stockClipping && clip && clip.polygon.length >= 6) {\n const composed = composedClips.get(slot);\n need(1);\n sig[n++] = composed ? 1 : 0;\n if (composed) {\n // Identical projected inputs can round differently when cut in stock space.\n const { source, shift, origin, scale } = composed;\n const vertices = source.kind === 'region' ? source.corners : source.vertices;\n const polygon = source.clip!.polygon;\n need(8 + vertices.length + polygon.length);\n sig[n++] = shift.x;\n sig[n++] = shift.y;\n sig[n++] = origin.x;\n sig[n++] = origin.y;\n sig[n++] = scale.x;\n sig[n++] = scale.y;\n sig[n++] = vertices.length;\n for (let k = 0; k < vertices.length; k++) sig[n++] = vertices[k];\n sig[n++] = polygon.length;\n for (let k = 0; k < polygon.length; k++) sig[n++] = polygon[k];\n }\n }\n refs.push(this.pages.get(slot.page), slot.uvs);\n if (slot.kind === 'mesh') refs.push(slot.triangles);\n }\n let same = n === this.sigLength && refs.length === this.sigRefs.length;\n for (let k = 0; same && k < n; k++) same = sig[k] === this.sig[k];\n for (let k = 0; same && k < refs.length; k++) same = refs[k] === this.sigRefs[k];\n if (same) return false;\n // Swap: the new signature becomes the kept one.\n this.nextSig = this.sig;\n this.sig = sig;\n this.sigLength = n;\n this.nextRefs = this.sigRefs;\n this.sigRefs = refs;\n return true;\n }\n\n /** The clip counters for a reused frame — what drawing it would have counted. */\n private countClips(order: PosedSlot[]): void {\n const seen = new Set<PosedClip>();\n for (const slot of order) {\n const clip = slot.clip;\n if (!clip || seen.has(clip)) continue;\n seen.add(clip);\n if (this.clipping && clip.polygon.length >= 6) this.clipCount++;\n else this.clipSkipCount++;\n }\n }\n\n // --- geometry ---------------------------------------------------------------\n\n private stride: 8 | 11 = 8;\n\n /**\n * The slot's triangles in world space with their page UVs — cut by the clip\n * over it when one applies — or null when the slot draws nothing.\n */\n private piecesOf(\n slot: PosedSlot,\n clips: Map<PosedClip, boolean>,\n ): { vertices: ArrayLike<number>; uvs: ArrayLike<number>; triangles: ArrayLike<number> } | null {\n const vertices = slot.kind === 'region' ? slot.corners : slot.vertices;\n const triangles = slot.kind === 'region' ? REGION_TRIANGLES : slot.triangles;\n const clip = slot.clip;\n if (!clip) return { vertices, uvs: slot.uvs, triangles };\n let applies = clips.get(clip);\n if (applies === undefined) {\n applies = this.clipping && clip.polygon.length >= 6;\n clips.set(clip, applies);\n if (applies) this.clipCount++;\n else this.clipSkipCount++;\n }\n if (!applies) return { vertices, uvs: slot.uvs, triangles };\n const cut = clipThrough({ polygon: clip.polygon, inverse: clip.inverse, convex: clip.convex }, vertices, triangles, slot.uvs);\n if (cut === null) {\n // A polygon the core does not draw (self-crossing, collinear): counted\n // once as skipped, and the slot drawn unclipped as for a skipped clip.\n clips.set(clip, false);\n this.clipCount--;\n this.clipSkipCount++;\n return { vertices, uvs: slot.uvs, triangles };\n }\n return cut.clipped ? cut : { vertices, uvs: slot.uvs, triangles };\n }\n\n /** Fills `data` and `runs` for the GL path. */\n private buildVertices(order: PosedSlot[]): void {\n let dark = false;\n for (let i = 0; i < order.length && !dark; i++) dark = order[i].dark !== undefined;\n const stride: 8 | 11 = dark ? 11 : 8;\n this.stride = stride;\n const runs = this.runs;\n runs.length = 0;\n const clips = new Map<PosedClip, boolean>();\n const ratio = this.backingRatio;\n const left = this.left;\n const top = this.top;\n const blitter = getMeshGlBlitter();\n let vertex = 0;\n let run: FrameRun | null = null;\n for (let i = 0; i < order.length; i++) {\n const slot = order[i];\n const page = this.pages.get(slot.page);\n if (!page) continue;\n const piece = this.piecesOf(slot, clips);\n if (!piece) continue;\n const { vertices, uvs } = piece;\n const triangles = triangleReadSource(piece.triangles);\n const count = triangles.length;\n if (count === 0) continue;\n if (!this.glPages.has(page) && blitter) {\n this.glPages.add(page);\n blitter.retain(page);\n }\n if (!run || run.page !== page || run.blend !== slot.blend) {\n if (run && run.blend !== slot.blend) this.blendFlushes++;\n run = { page, pma: slot.pma, blend: slot.blend, first: vertex, count: 0 };\n runs.push(run);\n }\n const need = (vertex + count) * stride;\n if (this.data.length < need) {\n const grown = new Float32Array(1 << Math.ceil(Math.log2(need)));\n grown.set(this.data.subarray(0, vertex * stride));\n this.data = grown;\n }\n const data = this.data;\n const [r, g, b, a] = slot.tint;\n const d = slot.dark;\n let f = vertex * stride;\n for (let t = 0; t < count; t++) {\n const vi = triangles[t] * 2;\n data[f++] = (vertices[vi] - left) * ratio;\n data[f++] = (-vertices[vi + 1] - top) * ratio;\n data[f++] = uvs[vi];\n data[f++] = uvs[vi + 1];\n data[f++] = r * a;\n data[f++] = g * a;\n data[f++] = b * a;\n data[f++] = a;\n if (stride === 11) {\n data[f++] = d ? d[0] * a : 0;\n data[f++] = d ? d[1] * a : 0;\n data[f++] = d ? d[2] * a : 0;\n }\n }\n vertex += count;\n run.count += count;\n this.trianglesDrawn += count / 3;\n }\n this.drawCalls = runs.length;\n }\n\n // --- the canvas2d fallback -----------------------------------------------\n\n private draw2d(order: PosedSlot[]): void {\n const ctx = this.ctx;\n if (!ctx) return;\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.globalAlpha = 1;\n ctx.globalCompositeOperation = 'source-over';\n ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);\n const clips = new Map<PosedClip, boolean>();\n const ratio = this.backingRatio;\n const left = this.left;\n const top = this.top;\n const X = (x: number): number => (x - left) * ratio;\n const Y = (y: number): number => (-y - top) * ratio;\n let blend: BlendMode | null = null;\n for (let i = 0; i < order.length; i++) {\n const slot = order[i];\n const image = this.pages.get(slot.page);\n if (!image) continue;\n const composed = this.clipping && slot.clip ? composedClips.get(slot) : undefined;\n const sourceSlot = composed?.source ?? slot;\n const piece = this.piecesOf(sourceSlot, clips);\n if (!piece) continue;\n const sourceVertices = sourceSlot.kind === 'region' ? sourceSlot.corners : sourceSlot.vertices;\n const cut = piece.vertices !== sourceVertices;\n const project = cut ? composed : undefined;\n const drawX = project ? (x: number) => X((x + project.shift.x - project.origin.x) * project.scale.x) : X;\n const drawY = project ? (y: number) => Y((y - project.shift.y - project.origin.y) * project.scale.y) : Y;\n const source: PageSource = straightAlphaSource(image, slot.pma);\n const uw = source.width;\n const uh = source.height;\n if (slot.blend !== blend) {\n if (blend !== null) this.blendFlushes++;\n blend = slot.blend;\n ctx.globalCompositeOperation = COMPOSITE[blend];\n }\n ctx.globalAlpha = Math.max(0, Math.min(1, slot.tint[3]));\n this.drawCalls++;\n const { uvs } = piece;\n const triangles = triangleReadSource(piece.triangles);\n if (slot.kind === 'region' && !cut) {\n // A whole quad: its page sub-rect under the affine that sends the UL,\n // UR and BL texel corners to their device corners (BL, UL, UR, BR).\n const c = slot.corners;\n const sx0 = uvs[2] * uw, sy0 = uvs[3] * uh; // UL\n const sx1 = uvs[4] * uw, sy1 = uvs[5] * uh; // UR\n const sx2 = uvs[0] * uw, sy2 = uvs[1] * uh; // BL\n const m = affine(sx0, sy0, sx1, sy1, sx2, sy2, X(c[2]), Y(c[3]), X(c[4]), Y(c[5]), X(c[0]), Y(c[1]));\n if (m) {\n const minU = Math.min(uvs[0], uvs[2], uvs[4], uvs[6]) * uw;\n const minV = Math.min(uvs[1], uvs[3], uvs[5], uvs[7]) * uh;\n const maxU = Math.max(uvs[0], uvs[2], uvs[4], uvs[6]) * uw;\n const maxV = Math.max(uvs[1], uvs[3], uvs[5], uvs[7]) * uh;\n ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);\n if (maxU > minU && maxV > minV) ctx.drawImage(source, minU, minV, maxU - minU, maxV - minV, minU, minV, maxU - minU, maxV - minV);\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n }\n this.trianglesDrawn += 2;\n continue;\n }\n const vertices = cut ? piece.vertices : slot.kind === 'region' ? slot.corners : slot.vertices;\n for (let t = 0; t + 2 < triangles.length; t += 3) {\n const i0 = triangles[t] * 2;\n const i1 = triangles[t + 1] * 2;\n const i2 = triangles[t + 2] * 2;\n drawTexturedTriangle(\n ctx, source, 0.5, this.meshSourceRect,\n drawX(vertices[i0]), drawY(vertices[i0 + 1]), uvs[i0] * uw, uvs[i0 + 1] * uh,\n drawX(vertices[i1]), drawY(vertices[i1 + 1]), uvs[i1] * uw, uvs[i1 + 1] * uh,\n drawX(vertices[i2]), drawY(vertices[i2 + 1]), uvs[i2] * uw, uvs[i2 + 1] * uh,\n );\n }\n this.trianglesDrawn += triangles.length / 3;\n }\n ctx.globalAlpha = 1;\n ctx.globalCompositeOperation = 'source-over';\n }\n}\n\n/** The affine sending three source points to three destination points, as canvas `setTransform` arguments; null when degenerate. */\nfunction affine(\n u0: number, v0: number, u1: number, v1: number, u2: number, v2: number,\n x0: number, y0: number, x1: number, y1: number, x2: number, y2: number,\n): [number, number, number, number, number, number] | null {\n const eu1 = u1 - u0, ev1 = v1 - v0, eu2 = u2 - u0, ev2 = v2 - v0;\n const det = eu1 * ev2 - eu2 * ev1;\n if (det === 0) return null;\n const inv = 1 / det;\n const ex1 = x1 - x0, ey1 = y1 - y0, ex2 = x2 - x0, ey2 = y2 - y0;\n const a = (ev2 * ex1 - ev1 * ex2) * inv;\n const b = (ev2 * ey1 - ev1 * ey2) * inv;\n const c = (eu1 * ex2 - eu2 * ex1) * inv;\n const d = (eu1 * ey2 - eu2 * ey1) * inv;\n return [a, b, c, d, x0 - a * u0 - c * v0, y0 - b * u0 - d * v0];\n}\n","import { type CompiledDocument, CORE_DOCUMENT_SPECS, CoreInputError, readModel, readSetupMesh as coreReadSetupMesh, underNoSkin } from '@rig-c/core/core';\nimport { type AtlasRegion, createAtlasRegions, type RegionImage, revokeRegions, unpackRegions } from './DomTexture.js';\n\n/**\n * Loads a rig built by `rigc build`: the compiled model document\n * (`skeleton.model.json`, spec `rigc-compiled/3`) and the page images its\n * `pages` section names. The default cuts region bitmaps once; the atlas\n * option retains page-backed descriptors without encoding region PNGs.\n *\n * The document states everything the player reads — the skeleton, the\n * animations, and where every region sits on its page — so the `.atlas` and\n * `skeleton.json` the build writes beside it are not fetched. A Spine export\n * (`.json`, `.skel`) is refused by name: this package poses the compiled model\n * through `rig-c/core` and reads nothing else.\n */\n\nexport interface LoadModelOptions {\n /** URL of the compiled model document (`skeleton.model.json`). */\n modelUrl: string;\n /**\n * Maps a page name from the document's `pages` section to the URL its image\n * lives at. Defaults to resolving the name against the model URL's\n * directory: a build writes page names as paths relative to its own\n * directory, which is where the document sits.\n */\n resolvePage?: (pageName: string, modelUrl: string) => string;\n /**\n * crossOrigin attribute for the page images. Needed when the images come\n * from another origin: the region cut reads them into a canvas, and a\n * tainted canvas cannot be exported (SecurityError from toBlob).\n */\n crossOrigin?: string;\n /** fetch implementation, for custom headers or a test double. */\n fetch?: typeof globalThis.fetch;\n /**\n * What the region cut produces — the rigid tier's per-region bitmaps, which\n * only the DOM mode draws. `'atlas'`: opt-in page-backed rigid canvases,\n * no PNG encode and an empty regionImages map. `'blob'` (default): `blob:` URLs the load\n * owns and `dispose` frees. `'data'`: `data:` URLs, for a content policy or\n * a snapshot that does not carry `blob:`; nothing to free. `'none'`: no cut\n * at all, for a load that only ever draws in the canvas mode — the pages\n * are loaded, `regionImages` is empty, and a DOM-mode player opened on the\n * assets is refused by name.\n */\n regions?: RegionLoading;\n /**\n * URL of the attachment-sets sidecar (`sets.json`, spec `spine-parts-sets/1`\n * or `rig-parts-sets/1`). When omitted, `loadModel` probes `sets.json` in\n * the model document's directory and treats a 404 as \"no sets\". Pass `null`\n * to skip the probe, or a string URL to require a `sets.json` at that path.\n */\n setsUrl?: string | null;\n}\n\n/** `LoadModelOptions.regions`: how, or whether, the regions are cut. */\nexport type RegionLoading = 'atlas' | 'blob' | 'data' | 'none';\n\n/**\n * One attachment set read from `sets.json` (`spine-parts-sets/1` or\n * `rig-parts-sets/1`): the slots it replaces (`slots`, slot name → attachment\n * name) and the slots it clears (`hides`).\n */\nexport interface RigSet {\n readonly name: string;\n /** Map from slot name to the attachment name the set puts on that slot. */\n readonly slots: Readonly<Record<string, string>>;\n /** Slots the set hides (`null` attachment while the set is active). */\n readonly hides: readonly string[];\n /**\n * The world rotations (degrees, CCW, Y up) the set's art was painted at,\n * by bone (`@rig-c/parts` gesture sets, parts #465 / #476): while the set is\n * active those bones are posed at these angles (#170). Absent when the set\n * declares none.\n */\n readonly drawn?: Readonly<Record<string, number>>;\n}\n\n/**\n * What `new RigPlayer(root, assets)` draws from. The caller owns it: one load\n * can back any number of players, and nothing a player does disposes it.\n */\nexport interface ModelAssets {\n /** The document's spec, e.g. `rigc-compiled/3`. */\n readonly spec: string;\n /** Every animation the document carries, in its order, with the runtime's duration. */\n readonly animations: ReadonlyArray<{ readonly name: string; readonly duration: number }>;\n /** Every skin the document declares, in its order. */\n readonly skins: readonly string[];\n /**\n * Every attachment set read from `sets.json` (`spine-parts-sets/1` or\n * `rig-parts-sets/1`), in declaration order; empty when the build has no\n * `sets.json`.\n */\n readonly sets: readonly RigSet[];\n /**\n * The document's `stage` section, in world units (Y up): the stage the\n * build declared — the rig's own framing, for laying out a stage — or null\n * where the document has none. Where its value comes from is rigc's rule,\n * not this package's (rigc `docs/AUTHORING.md`, *Where the rebuild's stage\n * comes from*): a source that states a stage is written as stated, and a\n * source that states none gets the setup pose's bounding box in its place.\n * So one rig's `stage` is a declared frame and another's is a box, and the\n * field does not say which. For the box of what a pose draws, read\n * `player.bounds()`.\n */\n readonly stage: { readonly x: number; readonly y: number; readonly width: number; readonly height: number } | null;\n /** How the regions were cut (`LoadModelOptions.regions`): `'none'` means `regionImages` is empty and only the canvas mode can draw. */\n readonly regions: RegionLoading;\n /** Complete ready URL map on blob/data loads; empty on atlas/none loads. */\n readonly regionImages: Map<string, RegionImage>;\n /** Page-backed rigid sources on an atlas load; empty on explicit blob/data/none loads. */\n readonly atlasRegions: Map<string, AtlasRegion>;\n /** Page images, keyed by the document's page names; shared by meshes and atlas regions. */\n readonly pageImages: Map<string, HTMLImageElement>;\n /**\n * The document as `rig-c/core` read it. Opaque to callers: the player poses\n * it, and its shape is rig-c's, not this package's.\n */\n readonly document: ModelDocument;\n /**\n * Frees the blob URLs this load created (see revokeRegions). Idempotent.\n * Call it after the players drawing from these assets are disposed — a live\n * <img> would be left pointing at a dead URL.\n */\n dispose(): void;\n}\n\n/** The read document, held for the player. Deliberately opaque. */\nexport interface ModelDocument {\n readonly spec: string;\n}\n\n/** @internal What the player reads off `ModelAssets.document`. */\nexport interface ReadDocument extends ModelDocument {\n readonly doc: CompiledDocument;\n /** The document's parsed JSON — the sequences' `start`/`digits`, which `readModel` does not keep, are read off it. */\n readonly parsed: unknown;\n}\n\n/** Exact slot name and attachment table key, independent of a player's selection. */\nexport interface SetupMeshTarget {\n readonly slot: string;\n readonly attachment: string;\n /** Omitted or null: no skin set. A name uses default fallback; `all` refuses differing definitions. */\n readonly skin?: string | null;\n}\n\n/** Detached setup geometry in world units, Y up. The arrays are fresh and mutable. */\nexport interface SetupMesh {\n slot: string;\n attachment: string;\n /** The table supplying the attachment, including default fallback. */\n skin: string;\n vertices: number[];\n triangles: number[];\n /** Number of leading hull vertices, or null when absent. */\n hull: number | null;\n}\n\n/**\n * Reads any named mesh or linked mesh through the core's setup poser, without\n * creating or advancing a player. Selected meshes include setup-slider deform;\n * unselected meshes use stored geometry through unchanged setup matrices.\n * Core skin, ambiguity, non-mesh and setup refusals propagate unchanged.\n */\nexport function readSetupMesh(assets: ModelAssets, target: SetupMeshTarget): SetupMesh {\n return coreReadSetupMesh(underNoSkin((assets.document as ReadDocument).doc), target);\n}\n\nconst SETS_SPECS = ['spine-parts-sets/1', 'rig-parts-sets/1'] as const;\n\n/**\n * Keys `@rig-c/parts` writes that place nothing: `check --set` poses a set by\n * its `slots`, `hides` and `drawn` alone, so these are read past by name and\n * given no meaning here (#170, #195). `drawnLength` and `registration` record\n * how a skeleton-placed set's painting was measured; `threshold` is the\n * yaw/pitch band a pose dial switches a face set at; `focus` is the set's\n * authored focus point `[x, y]` in setup-pose coordinates (parts #722). Any\n * other key is refused by name.\n */\nconst SET_KEYS_NOT_POSED = ['drawnLength', 'registration', 'threshold', 'focus'] as const;\nconst SET_KEYS = ['slots', 'hides', 'drawn', ...SET_KEYS_NOT_POSED] as const;\nconst SETS_DOCUMENT_KEYS = ['spec', 'sets', 'threshold'] as const;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Parses and validates a `sets.json` sidecar (`spine-parts-sets/1` or\n * `rig-parts-sets/1`) against `doc`'s slots and skin attachments.\n *\n * @internal Shared with the loader below; not part of the package API.\n */\nexport function readSetsText(text: string, where: string, doc: CompiledDocument): readonly RigSet[] {\n let raw: unknown;\n try {\n raw = JSON.parse(text);\n } catch (error) {\n throw new Error(`${where}: not JSON — ${(error as Error).message}`);\n }\n if (!isRecord(raw)) {\n throw new Error(`${where}: sets document must be a JSON object`);\n }\n if (raw.spec !== SETS_SPECS[0] && raw.spec !== SETS_SPECS[1]) {\n throw new Error(\n `${where}: spec is ${JSON.stringify(raw.spec)}, not \"${SETS_SPECS[0]}\" or \"${SETS_SPECS[1]}\"`,\n );\n }\n for (const key of Object.keys(raw)) {\n if (!(SETS_DOCUMENT_KEYS as readonly string[]).includes(key)) {\n throw new Error(`${where}: unknown key ${JSON.stringify(key)} (known: ${SETS_DOCUMENT_KEYS.join(', ')})`);\n }\n }\n if (!isRecord(raw.sets) && !Array.isArray(raw.sets)) {\n throw new Error(`${where}: \"sets\" must be an object or an array`);\n }\n const knownSlots = new Set(doc.slots.map((slot) => slot.name));\n const knownBones = new Set(doc.bones.map((bone) => bone.name));\n const attachmentsBySlot = new Map<string, Set<string>>();\n for (const skin of doc.skins) {\n for (const [slotName, table] of Object.entries(skin.attachments)) {\n let set = attachmentsBySlot.get(slotName);\n if (!set) {\n set = new Set<string>();\n attachmentsBySlot.set(slotName, set);\n }\n for (const attName of Object.keys(table)) set.add(attName);\n }\n }\n\n const entries: Array<[string, Record<string, unknown>]> = [];\n if (Array.isArray(raw.sets)) {\n for (let i = 0; i < raw.sets.length; i++) {\n const item = raw.sets[i];\n if (!isRecord(item) || typeof item.name !== 'string' || item.name.length === 0) {\n throw new Error(`${where}: sets[${i}] must be an object with a non-empty \"name\"`);\n }\n entries.push([item.name, item]);\n }\n } else {\n for (const [name, item] of Object.entries(raw.sets)) {\n if (name.length === 0 || !isRecord(item)) {\n throw new Error(`${where}: set \"${name}\" must be an object`);\n }\n entries.push([name, item]);\n }\n }\n\n const out: RigSet[] = [];\n const seenNames = new Set<string>();\n for (const [name, item] of entries) {\n if (seenNames.has(name)) {\n throw new Error(`${where}: duplicate set \"${name}\"`);\n }\n seenNames.add(name);\n for (const key of Object.keys(item)) {\n if (Array.isArray(raw.sets) && key === 'name') continue;\n if (!(SET_KEYS as readonly string[]).includes(key)) {\n throw new Error(`${where}: set \"${name}\" has unknown key ${JSON.stringify(key)} (known: ${SET_KEYS.join(', ')})`);\n }\n }\n if (!isRecord(item.slots)) {\n throw new Error(`${where}: set \"${name}\" must have a \"slots\" object`);\n }\n const slots: Record<string, string> = {};\n for (const [slotName, attName] of Object.entries(item.slots)) {\n if (!knownSlots.has(slotName)) {\n throw new Error(`${where}: set \"${name}\" names unknown slot \"${slotName}\"`);\n }\n if (typeof attName !== 'string' || attName.length === 0) {\n throw new Error(`${where}: set \"${name}\" slot \"${slotName}\" attachment must be a non-empty string`);\n }\n if (!attachmentsBySlot.get(slotName)?.has(attName)) {\n throw new Error(`${where}: set \"${name}\" maps slot \"${slotName}\" to unknown attachment \"${attName}\"`);\n }\n slots[slotName] = attName;\n }\n const hides: string[] = [];\n if (item.hides !== undefined) {\n if (!Array.isArray(item.hides)) {\n throw new Error(`${where}: set \"${name}\" \"hides\" must be an array of slot names`);\n }\n for (const hidden of item.hides) {\n if (typeof hidden !== 'string' || hidden.length === 0) {\n throw new Error(`${where}: set \"${name}\" \"hides\" entries must be non-empty strings`);\n }\n if (!knownSlots.has(hidden)) {\n throw new Error(`${where}: set \"${name}\" hides unknown slot \"${hidden}\"`);\n }\n if (Object.prototype.hasOwnProperty.call(slots, hidden)) {\n throw new Error(`${where}: set \"${name}\" both replaces and hides slot \"${hidden}\"`);\n }\n if (!hides.includes(hidden)) hides.push(hidden);\n }\n }\n let drawn: Record<string, number> | undefined;\n if (item.drawn !== undefined) {\n if (!isRecord(item.drawn)) {\n throw new Error(`${where}: set \"${name}\" \"drawn\" must be an object of bone name → degrees`);\n }\n drawn = {};\n for (const [boneName, degrees] of Object.entries(item.drawn)) {\n if (!knownBones.has(boneName)) {\n throw new Error(`${where}: set \"${name}\" draws unknown bone \"${boneName}\"`);\n }\n if (typeof degrees !== 'number' || !Number.isFinite(degrees)) {\n throw new Error(`${where}: set \"${name}\" drawn bone \"${boneName}\" must be a finite number of degrees`);\n }\n drawn[boneName] = degrees;\n }\n }\n if (item.focus !== undefined) {\n if (\n !Array.isArray(item.focus) ||\n item.focus.length !== 2 ||\n typeof item.focus[0] !== 'number' ||\n !Number.isFinite(item.focus[0]) ||\n typeof item.focus[1] !== 'number' ||\n !Number.isFinite(item.focus[1])\n ) {\n throw new Error(`${where}: set \"${name}\" \"focus\" must be [x, y] of two finite numbers`);\n }\n }\n out.push(\n Object.freeze({\n name,\n slots: Object.freeze(slots),\n hides: Object.freeze(hides),\n ...(drawn === undefined || Object.keys(drawn).length === 0 ? {} : { drawn: Object.freeze(drawn) }),\n }),\n );\n }\n return Object.freeze(out);\n}\n\nasync function loadSets(\n fetchImpl: typeof globalThis.fetch,\n modelUrl: string,\n setsUrlOption: string | null | undefined,\n doc: CompiledDocument,\n): Promise<readonly RigSet[]> {\n if (setsUrlOption === null) return Object.freeze([]);\n if (typeof setsUrlOption === 'string') {\n const text = await fetchText(fetchImpl, setsUrlOption);\n return readSetsText(text, setsUrlOption, doc);\n }\n const url = resolveAgainstModel('sets.json', modelUrl);\n let response: Response;\n try {\n response = await fetchImpl(url);\n } catch {\n return Object.freeze([]);\n }\n if (!response.ok) return Object.freeze([]);\n const contentType = response.headers.get('content-type') ?? '';\n if (contentType.includes('text/html')) return Object.freeze([]);\n const text = await response.text();\n const trimmed = text.trimStart();\n if (trimmed.length === 0 || trimmed.startsWith('<')) return Object.freeze([]);\n // When an unconfigured fetch double echoes the model document back for every URL,\n // ignore it rather than mistaking the model document for sets.json.\n try {\n const parsed = JSON.parse(trimmed) as unknown;\n if (isRecord(parsed) && typeof parsed.spec === 'string' && parsed.spec.startsWith('rigc-compiled/')) {\n return Object.freeze([]);\n }\n } catch {\n // Let readSetsText report malformed JSON in a real sets.json.\n }\n return readSetsText(text, url, doc);\n}\n\nfunction stageOf(doc: CompiledDocument): ModelAssets['stage'] {\n const stage = doc.stated?.stage;\n return stage ? { x: stage.x, y: stage.y, width: stage.width, height: stage.height } : null;\n}\n\nfunction resolveAgainstModel(pageName: string, modelUrl: string): string {\n return new URL(pageName, new URL(modelUrl, document.baseURI)).href;\n}\n\nasync function fetchText(fetchImpl: typeof globalThis.fetch, url: string): Promise<string> {\n const response = await fetchImpl(url);\n if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.status}`);\n return response.text();\n}\n\nfunction loadImage(url: string, crossOrigin?: string): Promise<HTMLImageElement> {\n return new Promise((resolve, reject) => {\n const image = new Image();\n if (crossOrigin !== undefined) image.crossOrigin = crossOrigin;\n image.onload = () => resolve(image);\n image.onerror = () => reject(new Error(`Failed to load page image: ${url}`));\n image.src = url;\n });\n}\n\n/** The URL's path without its query or fragment, lower-cased — what the export check reads. */\nfunction pathOf(url: string): string {\n return url.split(/[?#]/, 1)[0].toLowerCase();\n}\n\n/**\n * Reads a model document's text, refusing by name what this package does not\n * read: a Spine export, a document whose spec `rig-c/core` does not read, and a\n * document without a `pages` section (`rigc-compiled/1`).\n *\n * @internal Shared with the loader below; not part of the package API.\n */\nexport function readModelText(text: string, where: string): ReadDocument {\n let doc: CompiledDocument;\n try {\n doc = readModel(text, where);\n } catch (error) {\n if (error instanceof CoreInputError) {\n throw new CoreInputError(`${error.message} — build it with \\`rigc build\\``);\n }\n throw error;\n }\n if (doc.pages === null) {\n throw new CoreInputError(\n `${where}: a ${doc.spec} document does not state where each region sits on its page — build it with \\`rigc build\\``,\n );\n }\n return { spec: doc.spec, doc, parsed: JSON.parse(text) as unknown };\n}\n\n/**\n * Loads a rig built by `rigc build`.\n *\n * ```ts\n * const assets = await loadModel({ modelUrl: '/rigs/walk/skeleton.model.json' });\n * const player = new RigPlayer(root, assets);\n * player.play('walk');\n * // each frame: player.frame(dt)\n * // …later: player.dispose(); assets.dispose();\n * ```\n *\n * Page images load in parallel. If anything fails part-way, no blob URL is\n * left behind.\n */\nexport async function loadModel(options: LoadModelOptions): Promise<ModelAssets> {\n const { modelUrl, crossOrigin } = options;\n const path = pathOf(modelUrl);\n if (path.endsWith('.skel') || (path.endsWith('.json') && !path.endsWith('.model.json'))) {\n throw new CoreInputError(\n `${modelUrl} is a Spine export; this player reads a compiled model document (${CORE_DOCUMENT_SPECS[0]}, skeleton.model.json) — build it with \\`rigc build\\``,\n );\n }\n const regions = options.regions ?? 'blob';\n if (regions !== 'atlas' && regions !== 'blob' && regions !== 'data' && regions !== 'none') {\n throw new Error(`regions must be 'atlas', 'blob', 'data' or 'none', got ${String(options.regions)}`);\n }\n const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);\n const resolvePage = options.resolvePage ?? resolveAgainstModel;\n\n const read = readModelText(await fetchText(fetchImpl, modelUrl), modelUrl);\n const pages = read.doc.pages ?? [];\n const pageImages = new Map<string, HTMLImageElement>();\n await Promise.all(\n pages.map(async (page) => {\n pageImages.set(page.name, await loadImage(resolvePage(page.name, modelUrl), crossOrigin));\n }),\n );\n\n const sets = await loadSets(fetchImpl, modelUrl, options.setsUrl, read.doc);\n const regionImages = regions === 'none' || regions === 'atlas' ? new Map<string, RegionImage>() : await unpackRegions(pages, pageImages, { encoding: regions });\n\n let disposed = false;\n return {\n spec: read.spec,\n animations: read.doc.animations.map((a) => ({ name: a.name, duration: a.timelines.duration })),\n skins: read.doc.skins.map((s) => s.name),\n sets,\n stage: stageOf(read.doc),\n regions,\n regionImages,\n atlasRegions: regions === 'atlas' ? createAtlasRegions(pages, pageImages) : new Map(),\n pageImages,\n document: read,\n dispose(): void {\n if (disposed) return;\n disposed = true;\n revokeRegions(regionImages);\n },\n };\n}\n","/**\n * A keyed timeline compiled once for the runtime poser (issue #1591): its key\n * times and channel values as the oracle stores them (float32, `CoreKey.time`\n * and `.values`), each segment's curve kind, and every Bézier segment's\n * polyline evaluated at load by the oracle's own `bezierPolyline`, so that a\n * pose evaluates the segment the oracle evaluates and nothing else.\n *\n * The two reads a pose makes are the oracle's (`keyIndexAt` and `channelAt`\n * in `src/core/animation.ts`), operation for operation:\n *\n * - **The key at `t`** is the last key whose time is at or before `t`, −1\n * before the first. The oracle scans from key 0 every time; the runtime\n * walks a per-pose cursor from where the previous pose left it, backwards\n * while the key's time is after `t` and forwards while the next one's is\n * not. Over key times that never decrease (the reader refuses a key not\n * after the one before, and float32 can only make two equal), both find the\n * same key for every finite `t`. A `t` that is not finite is refused before\n * any search (`RuntimeInputError`): the scan reads −1 for NaN and the\n * cursor would read wherever it stood.\n * - **A channel's value** on the segment from key `i`: the key's own value on\n * the last key and after a hold; `v0 + ((t − t0) / (t1 − t0)) · (v1 − v0)`\n * on a linear segment; and on a Bézier segment the linear piece of the\n * polyline whose end is the first point at or after `t`.\n *\n * Nothing here allocates once compiled.\n */\nimport { bezierPolyline, BEZIER_PIECES, type CoreKey } from '../core/animation.ts';\nimport { DEFORM_CURVE_END, type CoreDeformKey } from '../core/deform.ts';\n\n/** A segment's curve, per key. */\nexport const CURVE_LINEAR = 0;\nexport const CURVE_STEPPED = 1;\nexport const CURVE_BEZIER = 2;\n\n/** Numbers in one channel's polyline: the segment's two ends and the nine interior points, each a time and a value. */\nexport const POLYLINE = 2 * (BEZIER_PIECES + 1);\n\n/** One compiled timeline. `values` and `polylines` are by key, then by channel. */\nexport interface RuntimeCurve {\n readonly keys: number;\n readonly channels: number;\n readonly times: Float64Array;\n readonly values: Float64Array;\n readonly kinds: Uint8Array;\n /** `POLYLINE` numbers per key and channel; filled only where the key starts a Bézier segment. */\n readonly polylines: Float64Array;\n}\n\n/** A timeline's keys compiled; `channels` is how many values each key carries (0 for an attachment or draw-order timeline). */\nexport function compileCurve(keys: readonly { readonly time: number }[], channels: 0): RuntimeCurve;\nexport function compileCurve(keys: readonly CoreKey[], channels: number): RuntimeCurve;\nexport function compileCurve(\n keys: readonly { readonly time: number; readonly values?: readonly number[]; readonly stated?: CoreKey['stated']; readonly curve?: CoreKey['curve'] }[],\n channels: number,\n): RuntimeCurve {\n const n = keys.length;\n const times = new Float64Array(n);\n const values = new Float64Array(n * channels);\n const kinds = new Uint8Array(n);\n const polylines = new Float64Array(n * channels * POLYLINE);\n for (let i = 0; i < n; i++) {\n const a = keys[i];\n times[i] = a.time;\n const av = a.values;\n if (av !== undefined) for (let c = 0; c < channels; c++) values[i * channels + c] = av[c];\n const curve = a.curve ?? 'stepped';\n kinds[i] = curve === 'linear' ? CURVE_LINEAR : curve === 'stepped' ? CURVE_STEPPED : CURVE_BEZIER;\n if (typeof curve === 'string' || i + 1 >= n) continue;\n const b = keys[i + 1];\n const aStated = a.stated!;\n const bStated = b.stated!;\n const bValues = b.values!;\n for (let c = 0; c < channels; c++) {\n // The oracle's polyline (`channelAt`): the segment's float32 ends around the recurrence over the numbers as the document states them.\n const inner = bezierPolyline(aStated.time, aStated.values[c], curve[c * 4], curve[c * 4 + 1], curve[c * 4 + 2], curve[c * 4 + 3], bStated.time, bStated.values[c]);\n const o = (i * channels + c) * POLYLINE;\n polylines[o] = a.time;\n polylines[o + 1] = av![c];\n for (let q = 0; q < inner.length; q++) polylines[o + 2 + q] = inner[q];\n polylines[o + POLYLINE - 2] = b.time;\n polylines[o + POLYLINE - 1] = bValues[c];\n }\n }\n return { keys: n, channels, times, values, kinds, polylines };\n}\n\n/** The last key at or before `t` (−1 before the first), found from `cursors[slot]` and left there — the header's first read. */\nexport function keyAt(curve: RuntimeCurve, cursors: Int32Array, slot: number, t: number): number {\n const times = curve.times;\n // A slider can evaluate another animation between two reads of this one.\n // Shared cursor slots are only search hints: keep the hint inside THIS curve.\n let i = Math.min(cursors[slot], curve.keys - 1);\n while (i >= 0 && times[i] > t) i--;\n while (i + 1 < curve.keys && times[i + 1] <= t) i++;\n cursors[slot] = i;\n return i;\n}\n\n/** Channel `c` of the segment starting at key `i` (at or after 0), at `t` — the header's second read. */\nexport function channelValue(curve: RuntimeCurve, i: number, c: number, t: number): number {\n const ch = curve.channels;\n const values = curve.values;\n const v0 = values[i * ch + c];\n if (i + 1 >= curve.keys) return v0;\n const kind = curve.kinds[i];\n if (kind === CURVE_STEPPED) return v0;\n if (kind === CURVE_LINEAR) {\n const t0 = curve.times[i];\n return v0 + ((t - t0) / (curve.times[i + 1] - t0)) * (values[(i + 1) * ch + c] - v0);\n }\n const p = curve.polylines;\n const o = (i * ch + c) * POLYLINE;\n let q = 2;\n while (q < POLYLINE - 2 && p[o + q] < t) q += 2;\n const x0 = p[o + q - 2];\n const y0 = p[o + q - 1];\n return y0 + ((t - x0) / (p[o + q] - x0)) * (p[o + q + 1] - y0);\n}\n\n/** Deform easing has one fraction channel, a distinct recurrence end and end-piece arithmetic (core/deform.ts). */\nexport function compileDeformCurve(keys: readonly CoreDeformKey[]): RuntimeCurve {\n const curve = compileCurve(keys.map(k => ({ time: k.time, values: [0], curve: 'linear' as const, stated: { time: k.stated, values: [0] } })), 1);\n for (let i = 0; i < keys.length; i++) {\n const a = keys[i];\n curve.kinds[i] = a.curve === 'linear' ? CURVE_LINEAR : a.curve === 'stepped' ? CURVE_STEPPED : CURVE_BEZIER;\n if (typeof a.curve === 'string' || i + 1 === keys.length) continue;\n const b = keys[i + 1];\n const c = a.curve;\n const inner = bezierPolyline(a.stated, 0, c[0], c[1], c[2], c[3], b.stated, DEFORM_CURVE_END);\n const o = i * POLYLINE;\n curve.polylines[o] = a.time;\n curve.polylines[o + 1] = 0;\n curve.polylines.set(inner, o + 2);\n curve.polylines[o + POLYLINE - 2] = b.time;\n curve.polylines[o + POLYLINE - 1] = 1;\n }\n return curve;\n}\n\n/** The oracle's deformPercent, with the polyline compiled once and product-before-division at both ends. */\nexport function deformFraction(curve: RuntimeCurve, i: number, t: number): number {\n if (curve.kinds[i] === CURVE_STEPPED) return 0;\n if (curve.kinds[i] === CURVE_LINEAR) return (t - curve.times[i]) / (curve.times[i + 1] - curve.times[i]);\n const p = curve.polylines;\n const o = i * POLYLINE;\n let q = 2;\n while (q < POLYLINE - 2 && p[o + q] < t) q += 2;\n const x0 = p[o + q - 2], y0 = p[o + q - 1], x1 = p[o + q], y1 = p[o + q + 1];\n if (q === 2) return (y1 * (t - x0)) / (x1 - x0);\n if (q === POLYLINE - 2) return y0 + ((1 - y0) * (t - x0)) / (x1 - x0);\n return y0 + ((t - x0) / (x1 - x0)) * (y1 - y0);\n}\n","/**\n * The runtime poser's load-time half (issue #1591, stage 9): a skin view of\n * the compiled model (`readModel`, then `underSkin` / `underNoSkin` — the\n * oracle's reader and its views, read and never written) compiled once into\n * index-resolved bones and slots, a constraint plan, compiled timelines and\n * the sizes of every buffer a pose needs (`./pose.ts`).\n *\n * ## Refused by name, at load\n *\n * A construct the runtime does not pose yet is never guessed at. `compileRuntime`\n * collects every one it meets, each with the object it was found on\n * (`RuntimeMissing`), and:\n *\n * - **refuses the model** (`RuntimeRefusal`, every missing feature listed)\n * when one is a property of the whole model — an ik, transform or path constraint\n * over a bone the view leaves inactive, a region with no\n * atlas rectangle shown at setup, a placeholder the skins fill\n * differently, or a block the oracle itself leaves out;\n * - **refuses an animation** (`RuntimeModel.refused`; `animation(name)`\n * throws the same `RuntimeRefusal`) when the construct is the animation's\n * — an `inherit` timeline, a sequence timeline, or an\n * attachment key showing a region with no atlas\n * rectangle. Every other animation of the model is posed.\n *\n * `RUNTIME_FEATURES` is the closed list of what can be named. Stage 9 adds buffered clipping draw output; stage 8 added\n * additive local/world transform constraints. Stage 7 admitted\n * world transform targets in both no-scale inherit modes, using the existing\n * localFromWorld read-back. Stage 6 added local-source and local-target transforms. Draw-order,\n * light/dark colour, mesh and path deforms, named/no-skin views, path constraints,\n * scoped physics and immutable event deliveries remain covered.\n * `ignore: ['events']` remains an explicit diagnostic opt-out; it is\n * never the default. A merged view with conflicting attachments still refuses\n * by name, as the oracle itself cannot resolve that view without file order.\n *\n * ## What the oracle decides, the runtime reads\n *\n * Which bones are active, which constraints apply under the view, what a slot\n * shows for a placeholder and the name and path its row carries, a slot's\n * colour and blend, a linked mesh's source — each is the oracle's own answer,\n * read here once (`activeBones`, `constraintInactiveWhy`, `shownAttachment`,\n * `shownRow`, `readColour`, `readBlend`, `sourceOfDoc`). What the runtime\n * computes is the pose, and that is what the gate holds equal\n * (`tools/core_gate.ts`, *The runtime poser*).\n *\n * Pure, as all of `src/`: nothing from the Spine runtime package, no clock,\n * no randomness, no I/O.\n */\nimport type { ModelVertices } from '../model.ts';\nimport { activeBones, constraintRecords, CORE_REGION_KINDS, foldInheritMode, readBlend, readColour, shownAttachment, shownRow, sourceOfDoc, underSkin, type CompiledDocument, type CoreAnimation, type CoreBlendMode } from '../core/index.ts';\nimport { constraintInactiveWhy, constraintsAbsentWhy, pathAnimationsWhy, TRANSFORM_PROPERTIES, type CoreIkRecord, type CoreTransformRecord } from '../core/constraints.ts';\nimport { slotBonePlan, type CorePathRecord, type SlotBoneEvent } from '../core/constraints_path.ts';\nimport { RUNTIME_PI } from '../core/world.ts';\nimport { heldArray, timelineIdentity } from '../core/deform.ts';\nimport { steppedPreviousPassWhy, type CorePhysicsRecord, type PhysicsTimelineKind } from '../core/constraints_physics.ts';\nimport type { CoreSliderRecord } from '../core/constraints_slider.ts';\nimport { compileCurve, compileDeformCurve, type RuntimeCurve } from './curves.ts';\n\n/** The stage of issue #1591 this poser implements. */\nexport const RUNTIME_STAGE = 9;\n\n/** Every construct the runtime poser can refuse, by the name its refusals carry. */\nexport const RUNTIME_FEATURES = [\n 'inactive-constrained-bone',\n 'null-atlas-region',\n 'skin-conflict',\n 'oracle-absent',\n 'inherit-timeline',\n 'sequence-timeline',\n] as const;\nexport type RuntimeFeature = (typeof RUNTIME_FEATURES)[number];\n\n/** One construct not posed: what, on which object, and the animation it was found in (`null` for the model's own). */\nexport interface RuntimeMissing {\n readonly feature: RuntimeFeature;\n readonly detail: string;\n readonly animation: string | null;\n}\n\n/** Spelled once, so a refusal and a report say the same words. */\nexport function missingText(m: RuntimeMissing): string {\n return `${m.feature}: ${m.detail}${m.animation === null ? '' : ` (animation \"${m.animation}\")`}`;\n}\n\n/** What the runtime poser does not pose, named — the model's, or one animation's. */\nexport class RuntimeRefusal extends Error {\n readonly missing: readonly RuntimeMissing[];\n constructor(missing: readonly RuntimeMissing[]) {\n super(`not posed by the runtime poser (stage ${RUNTIME_STAGE}), ${missing.length} construct(s) missing: ${missing.map(missingText).join('; ')}`);\n this.missing = missing;\n }\n}\n\n/** A call the runtime poser cannot answer: a name the model does not have, a time that is not finite. */\nexport class RuntimeInputError extends Error {}\n\n/** What a consumer states at load. */\nexport interface RuntimeOptions {\n /** Constructs that move no pose, posed as absent on request. `events` is the only one. */\n readonly ignore?: readonly 'events'[];\n}\n\n/**\n * What a control passes in place of a part of the load (the selftest's\n * `runtime-poser` suite); nothing else passes one. Each acts at load only, so\n * a pose runs the same code with or without one.\n */\nexport interface RuntimePlant {\n /** Added to one bone's setup local value: the planted perturbation. */\n readonly setupNudge?: { readonly bone: string; readonly field: number; readonly delta: number };\n /** A weighted binding's bone index rewritten: the wrong-index plant. */\n readonly bindingIndex?: (index: number, bones: number) => number;\n /** Refusals let through, the construct posed as if absent: the smuggling plant. */\n readonly admit?: readonly RuntimeFeature[];\n /** The update order's scratch sized by the bone count instead of the longest target list: the short-buffer plant. */\n readonly scratchByBones?: boolean;\n /** Wrong-skin source selected by a control, never by a consumer. */\n readonly attachmentSkin?: string;\n /** Drops a key at zero on a wrap, the event boundary plant. */\n readonly eventWrapOffByOne?: boolean;\n /** The old restore behavior, which repeats keys up to the restored time. */\n readonly restoreEventsFromStart?: boolean;\n /** Omit deform / multiply offsets by weights too early / omit path / ignore physics scope: negative controls only. */\n readonly omitPhysics?: boolean;\n readonly sliderAsTrack?: boolean;\n readonly omitDeform?: boolean;\n readonly deformAfterWeights?: boolean;\n readonly omitPath?: boolean;\n readonly ignorePhysicsScope?: boolean;\n readonly omitDrawOrder?: boolean;\n readonly omitDarkColour?: boolean;\n /** Omit local-source/target transforms at load, to prove the stage-six gate. */\n readonly omitLocalTransform?: boolean;\n /** Omit world transforms with parented no-scale targets, to prove stage seven. */\n readonly omitNoScaleWorldTransform?: boolean;\n /** Omit additive transforms at load, to prove stage eight. */\n readonly omitAdditiveTransform?: boolean;\n}\n\n// A bone's local values, seven per bone.\nexport const L_X = 0;\nexport const L_Y = 1;\nexport const L_ROTATION = 2;\nexport const L_SCALE_X = 3;\nexport const L_SCALE_Y = 4;\nexport const L_SHEAR_X = 5;\nexport const L_SHEAR_Y = 6;\nexport const LOCALS = 7;\n/** The local fields by the name a `ModelBone` gives them, in `L_*` order. */\nexport const LOCAL_FIELD_NAMES = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'shearX', 'shearY'] as const;\n\n// A bone's world transform, six per bone: the matrix `[a b; c d]` and the origin.\nexport const W_A = 0;\nexport const W_B = 1;\nexport const W_C = 2;\nexport const W_D = 3;\nexport const W_X = 4;\nexport const W_Y = 5;\nexport const WORLDS = 6;\n\n// The five inherit modes.\nexport const MODE_NORMAL = 0;\nexport const MODE_ONLY_TRANSLATION = 1;\nexport const MODE_NO_ROTATION_OR_REFLECTION = 2;\nexport const MODE_NO_SCALE = 3;\nexport const MODE_NO_SCALE_OR_REFLECTION = 4;\nconst MODE_CODES = { normal: MODE_NORMAL, onlyTranslation: MODE_ONLY_TRANSLATION, noRotationOrReflection: MODE_NO_ROTATION_OR_REFLECTION, noScale: MODE_NO_SCALE, noScaleOrReflection: MODE_NO_SCALE_OR_REFLECTION } as const;\n\n// How an attachment draws.\nexport const DRAW_NONE = 0;\nexport const DRAW_REGION = 1;\nexport const DRAW_MESH = 2;\nexport const DRAW_WEIGHTED = 3;\n\n// An ik constraint's scaleY mode.\nexport const SCALE_Y_NONE = 0;\nexport const SCALE_Y_UNIFORM = 1;\nexport const SCALE_Y_VOLUME = 2;\n\n// An ik constraint's three flags, packed.\nexport const IK_BEND_POSITIVE = 1;\nexport const IK_COMPRESS = 2;\nexport const IK_STRETCH = 4;\n\n// A path constraint's position, spacing and rotate modes.\nexport const PATH_POSITION_FIXED = 0;\nexport const PATH_POSITION_PERCENT = 1;\nexport const PATH_SPACING_LENGTH = 0;\nexport const PATH_SPACING_FIXED = 1;\nexport const PATH_SPACING_PERCENT = 2;\nexport const PATH_SPACING_PROPORTIONAL = 3;\nexport const PATH_ROTATE_TANGENT = 0;\nexport const PATH_ROTATE_CHAIN = 1;\nexport const PATH_ROTATE_CHAIN_SCALE = 2;\n\n/** Degrees to radians, with the runtime's pi (`src/core/world.ts`). */\nexport const RAD = RUNTIME_PI / 180;\n\n/**\n * One record a slot can show, resolved at load: the row's name and path (the\n * oracle's `shownRow`), how it draws, its bone, where its world vertices go in\n * a pose's buffer and the numbers they are computed from — a region's four\n * corners before the bone (`regionCorners`' local half, the same operations),\n * an unweighted mesh's coordinates through `Math.fround`, a weighted mesh's\n * bindings (bone index, float32 coordinates, float32 weight) in their order.\n */\nexport interface RuntimeAttachment {\n /** Source topology resolved at load for models containing clipping. */\n readonly clipTopology?: { readonly triangles: Int32Array; readonly uvs: Float64Array };\n /** Clip polygon metadata, resolved once with the attachment. */\n readonly clip?: { readonly end: string | null; readonly inverse: boolean; readonly convex: boolean };\n /** Source timeline identity, including linked-mesh inheritance, resolved once. */\n readonly timeline: string | null;\n readonly deformOffset: number;\n readonly deformCount: number;\n readonly slot: number;\n readonly name: string;\n /** Exact resolved source table identity; display names need not be unique. */\n readonly skin: string;\n readonly placeholder: string;\n readonly path: string | null;\n readonly draw: number;\n readonly bone: number;\n /** Offset into `RuntimePose.vertices`, and how many numbers (two per vertex). */\n readonly offset: number;\n readonly count: number;\n readonly local: Float64Array;\n readonly bindingCounts: Int32Array;\n readonly bindingBones: Int32Array;\n readonly bindingX: Float64Array;\n readonly bindingY: Float64Array;\n readonly bindingWeights: Float64Array;\n}\n\n/** One slot: its bone, whether its timelines apply, what it shows at setup (an attachment index or −1), its colours and blend. */\nexport interface RuntimeSlot {\n readonly name: string;\n readonly bone: number;\n readonly live: boolean;\n readonly setupAttachment: number;\n readonly light: Float64Array;\n readonly dark: Float64Array | null;\n readonly blend: CoreBlendMode;\n}\n\n/** An ik constraint as the plan runs it. */\nexport interface RuntimeIk {\n readonly kind: 'ik';\n readonly name: string;\n readonly index: number;\n readonly applied: boolean;\n readonly bones: Int32Array;\n readonly target: number;\n readonly scaleY: number;\n readonly mix: number;\n readonly softness: number;\n readonly flags: number;\n}\n\n/** An absolute or additive transform constraint as the plan runs it: each source property's offset and its targets'. */\nexport interface RuntimeTransform {\n readonly kind: 'transform';\n readonly name: string;\n readonly index: number;\n readonly applied: boolean;\n readonly bones: Int32Array;\n readonly source: number;\n readonly fromProperty: Int32Array;\n readonly fromOffset: Float64Array;\n readonly toStart: Int32Array;\n readonly toEnd: Int32Array;\n readonly toProperty: Int32Array;\n readonly toOffset: Float64Array;\n readonly toScale: Float64Array;\n readonly toMax: Float64Array;\n /** The constraint's offsets and its setup mixes, by `TRANSFORM_PROPERTIES` index. */\n readonly offsets: Float64Array;\n readonly mixes: Float64Array;\n readonly clamp: boolean;\n readonly localSource: boolean;\n readonly localTarget: boolean;\n readonly additive: boolean;\n}\n\nexport interface RuntimePhysics {\n readonly kind: 'physics';\n readonly name: string;\n readonly index: number;\n readonly applied: boolean;\n readonly bones: Int32Array;\n readonly setup: CorePhysicsRecord;\n}\n\nexport interface RuntimeSlider {\n readonly kind: 'slider';\n readonly name: string;\n readonly index: number;\n readonly applied: boolean;\n readonly bones: Int32Array;\n readonly bone: number;\n readonly property: number;\n readonly setup: CoreSliderRecord;\n /** Resolved after every animation is compiled. Never a track. */\n animation: RuntimeAnimation;\n}\n\nexport interface RuntimePath {\n readonly kind: 'path';\n readonly name: string;\n readonly index: number;\n readonly applied: boolean;\n readonly bones: Int32Array;\n readonly slot: number;\n readonly slotBone: number;\n /** Setup path attachment index into `model.attachments`, or −1 when the slot shows no path. */\n attachment: number;\n /** Number of vertex coordinates (`2 * vertexCount`) in the setup path attachment. */\n pathVertices: number;\n readonly closed: boolean;\n readonly constantSpeed: boolean;\n readonly lengths: Float64Array;\n readonly positionMode: number;\n readonly spacingMode: number;\n readonly rotateMode: number;\n readonly offsetRotation: number;\n readonly position: number;\n readonly spacing: number;\n readonly mixRotate: number;\n readonly mixX: number;\n readonly mixY: number;\n /** Constraint index whose `before` or `after` state sets the slot bone's determinant sign (`slotBonePlan`), or −1. */\n readonly slotEventAt: number;\n readonly slotEventAfter: boolean;\n readonly setup: CorePathRecord;\n}\n\nexport interface RuntimePhysicsTimeline {\n readonly kind: PhysicsTimelineKind;\n readonly targets: Int32Array;\n readonly curve: RuntimeCurve;\n readonly cursor: number;\n}\nexport interface RuntimeSliderTimeline {\n readonly time: RuntimeCurve | null;\n readonly mix: RuntimeCurve | null;\n readonly timeCursor: number;\n readonly mixCursor: number;\n}\nexport interface RuntimePathTimeline {\n readonly position: RuntimeCurve | null;\n readonly spacing: RuntimeCurve | null;\n readonly mix: RuntimeCurve | null;\n readonly positionCursor: number;\n readonly spacingCursor: number;\n readonly mixCursor: number;\n}\nexport type RuntimeConstraint = RuntimeIk | RuntimeTransform | RuntimePhysics | RuntimeSlider | RuntimePath;\n\n/** A bone timeline: the bone, its curve, and per channel the local field it writes and whether it multiplies the setup value (scale) or adds to it. */\nexport interface RuntimeBoneTimeline {\n readonly bone: number;\n readonly curve: RuntimeCurve;\n readonly cursor: number;\n readonly fields: Int32Array;\n readonly multiply: Uint8Array;\n}\n\n/** A slot timeline: an attachment timeline (each key's attachment index, −1 nothing) or a colour timeline (each channel's index into the light or dark colour). */\nexport interface RuntimeSlotTimeline {\n readonly slot: number;\n readonly curve: RuntimeCurve;\n readonly cursor: number;\n readonly attachments: Int32Array | null;\n readonly channels: Int32Array | null;\n}\n\n/** A constraint timeline: its constraint's index in the plan, its curve, and an ik key's flags. */\nexport interface RuntimeConstraintTimeline {\n readonly constraint: number;\n readonly curve: RuntimeCurve;\n readonly cursor: number;\n readonly flags: Uint8Array | null;\n}\n\n/** One immutable event delivery, reused by every pose of this model. */\nexport interface RuntimeEvent {\n readonly name: string;\n readonly time: number;\n readonly int: number;\n readonly float: number;\n readonly string: string;\n readonly volume: number;\n readonly balance: number;\n}\n\n/** One source record's deform, its held arrays by key, matched after attachment switches. */\nexport interface RuntimeDeformTimeline {\n readonly identity: string;\n readonly curve: RuntimeCurve;\n readonly cursor: number;\n readonly held: Float64Array;\n readonly count: number;\n}\n\n/** An animation's draw-order timeline: each key's slot-index permutation of `slots.length` (`orderOf` in `src/core/draw_order.ts`), expanded once at load. */\nexport interface RuntimeDrawOrderTimeline {\n readonly curve: RuntimeCurve;\n readonly cursor: number;\n readonly orders: Int32Array;\n}\n\n/** One covered animation, compiled. */\nexport interface RuntimeAnimation {\n readonly name: string;\n readonly duration: number;\n readonly bones: readonly RuntimeBoneTimeline[];\n /** Every authored target in order; sliders compose duplicates that tracks discard. */\n readonly sliderBones: readonly RuntimeBoneTimeline[];\n readonly deforms: readonly RuntimeDeformTimeline[];\n readonly physics: readonly RuntimePhysicsTimeline[];\n readonly sliders: ReadonlyArray<RuntimeSliderTimeline | null>;\n readonly paths: ReadonlyArray<RuntimePathTimeline | null>;\n readonly slots: readonly RuntimeSlotTimeline[];\n readonly drawOrder: RuntimeDrawOrderTimeline | null;\n /** Per constraint of the plan, its timeline in this animation or `null`. */\n readonly constraints: ReadonlyArray<RuntimeConstraintTimeline | null>;\n /** How many key cursors a pose keeps for it. */\n readonly cursors: number;\n /** Number of authored event keys (including an explicitly muted diagnostic). */\n readonly events: number;\n readonly eventKeys: readonly RuntimeEvent[];\n}\n\n/** The compiled model a pose is made of (`compileRuntime`). Read-only once built. */\nexport interface RuntimeModel {\n /** Control-only boundary defect; fixed at load. */\n readonly omitDeform: boolean;\n readonly deformAfterWeights: boolean;\n readonly omitPhysics: boolean;\n readonly sliderAsTrack: boolean;\n readonly omitPath: boolean;\n readonly ignorePhysicsScope: boolean;\n readonly omitDrawOrder: boolean;\n readonly omitDarkColour: boolean;\n readonly hasPath: boolean;\n readonly maxPathSpaces: number;\n readonly maxPathVertices: number;\n readonly deformCount: number;\n readonly eventWrapOffByOne: boolean;\n readonly restoreEventsFromStart: boolean;\n readonly doc: CompiledDocument;\n readonly boneNames: readonly string[];\n readonly parents: Int32Array;\n readonly modes: Uint8Array;\n readonly active: Uint8Array;\n readonly lengths: Float64Array;\n /** Every bone's setup local values, `LOCALS` per bone. */\n readonly setup: Float64Array;\n /** Each bone's subtree, itself first, ascending: `subtrees[subtreeStart[b] … subtreeStart[b + 1])`. */\n readonly subtreeStart: Int32Array;\n readonly subtrees: Int32Array;\n readonly slots: readonly RuntimeSlot[];\n readonly attachments: readonly RuntimeAttachment[];\n readonly vertexCount: number;\n readonly constraints: readonly RuntimeConstraint[];\n readonly animations: ReadonlyMap<string, RuntimeAnimation>;\n /** The animations refused, in the document's order, each with what it misses. */\n readonly refused: ReadonlyArray<{ readonly animation: string; readonly missing: readonly RuntimeMissing[] }>;\n /** The most key cursors any covered animation needs. */\n readonly cursors: number;\n /**\n * How many bones one constraint can change at once: the longest target list,\n * and never less than the bone count. A transform constraint may name a bone\n * more than once (`readConstraintRecord` reads the list as written, and the\n * oracle applies each entry in turn), so the list, not the skeleton, bounds it.\n */\n readonly scratch: number;\n /** A covered animation by name; a refused one throws its `RuntimeRefusal`, an unknown one a `RuntimeInputError`. */\n animation(name: string): RuntimeAnimation;\n}\n\n/** The ten bone timeline kinds that key numbers: per channel, the local field and whether it multiplies (`src/core/animation.ts`, *The bone timelines*). */\nconst BONE_KINDS: Record<string, ReadonlyArray<readonly [number, 0 | 1]>> = {\n rotate: [[L_ROTATION, 0]],\n translate: [[L_X, 0], [L_Y, 0]],\n translatex: [[L_X, 0]],\n translatey: [[L_Y, 0]],\n scale: [[L_SCALE_X, 1], [L_SCALE_Y, 1]],\n scalex: [[L_SCALE_X, 1]],\n scaley: [[L_SCALE_Y, 1]],\n shear: [[L_SHEAR_X, 0], [L_SHEAR_Y, 0]],\n shearx: [[L_SHEAR_X, 0]],\n sheary: [[L_SHEAR_Y, 0]],\n};\n\n/** The light (`0 .. 3`) and dark (`4 .. 6`) colour channels each colour timeline sets, in its curve's channel order (`COLOUR_CHANNELS` in `src/core/animation.ts` and `src/core/constraints_slider.ts`). */\nconst COLOUR_CHANNELS: Record<string, readonly number[]> = { rgba: [0, 1, 2, 3], rgb: [0, 1, 2], alpha: [3], rgba2: [0, 1, 2, 3, 4, 5, 6], rgb2: [0, 1, 2, 4, 5, 6] };\n\n/** Where refusals are gathered while a model compiles. */\nclass Refusals {\n readonly model: RuntimeMissing[] = [];\n readonly byAnimation = new Map<string, RuntimeMissing[]>();\n constructor(private readonly admitted: ReadonlySet<RuntimeFeature>) {}\n\n /** Records the construct unless a plant admits it. The caller poses the construct as absent either way. */\n note(feature: RuntimeFeature, detail: string, animation: string | null = null): void {\n if (this.admitted.has(feature)) return;\n const m: RuntimeMissing = { feature, detail, animation };\n if (animation === null) this.model.push(m);\n else {\n const list = this.byAnimation.get(animation) ?? [];\n list.push(m);\n this.byAnimation.set(animation, list);\n }\n }\n}\n\n/** The view compiled for the runtime poser, or every construct it misses refused by name — the header. */\nexport function compileRuntime(doc: CompiledDocument, options: RuntimeOptions = {}, plant: RuntimePlant = {}): RuntimeModel {\n const refusals = new Refusals(new Set(plant.admit ?? []));\n const ignoreEvents = (options.ignore ?? []).includes('events');\n\n const absentWhy = constraintsAbsentWhy(doc) ?? pathAnimationsWhy(doc) ?? steppedPreviousPassWhy(doc);\n if (absentWhy !== null) refusals.note('oracle-absent', `the oracle leaves the bones out: ${absentWhy}`);\n\n // --- bones ---\n const nb = doc.bones.length;\n const boneIndex = new Map(doc.bones.map((b, i) => [b.name, i]));\n const indexOf = (name: string): number => {\n const i = boneIndex.get(name);\n if (i === undefined) throw new RuntimeInputError(`bone \"${name}\" is not a bone of this document (readModel refuses it first)`);\n return i;\n };\n const slotIndex = new Map(doc.slots.map((s, i) => [s.name, i]));\n const slotIndexOf = (name: string): number => {\n const i = slotIndex.get(name);\n if (i === undefined) throw new RuntimeInputError(`slot \"${name}\" is not a slot of this document (readModel refuses it first)`);\n return i;\n };\n const active = activeBones(doc);\n const parents = new Int32Array(nb);\n const modes = new Uint8Array(nb);\n const activeFlags = new Uint8Array(nb);\n const lengths = new Float64Array(nb);\n const setup = new Float64Array(nb * LOCALS);\n doc.bones.forEach((b, i) => {\n parents[i] = b.parent === undefined ? -1 : indexOf(b.parent);\n if (parents[i] >= i) throw new RuntimeInputError(`bone \"${b.name}\" is listed before its parent (readModel refuses it first)`);\n const mode = b.inheritMode === undefined ? 'normal' : foldInheritMode(b.inheritMode);\n if (mode === null) throw new RuntimeInputError(`bone \"${b.name}\": inheritMode ${JSON.stringify(b.inheritMode)} is no mode (readModel refuses it first)`);\n modes[i] = MODE_CODES[mode];\n activeFlags[i] = active.has(b.name) ? 1 : 0;\n lengths[i] = b.length ?? 0;\n const o = i * LOCALS;\n setup[o + L_X] = b.x ?? 0;\n setup[o + L_Y] = b.y ?? 0;\n setup[o + L_ROTATION] = b.rotation ?? 0;\n setup[o + L_SCALE_X] = b.scaleX ?? 1;\n setup[o + L_SCALE_Y] = b.scaleY ?? 1;\n setup[o + L_SHEAR_X] = b.shearX ?? 0;\n setup[o + L_SHEAR_Y] = b.shearY ?? 0;\n });\n if (plant.setupNudge !== undefined) setup[indexOf(plant.setupNudge.bone) * LOCALS + plant.setupNudge.field] += plant.setupNudge.delta;\n // Each bone's subtree, in bone order: bones are listed parents first, so each index is appended to its own list and its ancestors' in ascending order.\n const lists: number[][] = doc.bones.map(() => []);\n for (let k = 0; k < nb; k++) for (let at = k; at >= 0; at = parents[at]) lists[at].push(k);\n const subtreeStart = new Int32Array(nb + 1);\n const flat: number[] = [];\n for (let k = 0; k < nb; k++) {\n subtreeStart[k] = flat.length;\n for (const x of lists[k]) flat.push(x);\n }\n subtreeStart[nb] = flat.length;\n\n // --- constraints, in the document's order ---\n const constraints: RuntimeConstraint[] = [];\n const records = constraintRecords(doc);\n const skipped = new Set<number>();\n records.forEach((r, i) => {\n if (constraintInactiveWhy(r, active) !== null) skipped.add(i);\n });\n const pathPlan = records.some((r) => r.kind === 'path') ? slotBonePlan(doc.bones, active, records, skipped) : new Map<number, SlotBoneEvent | null>();\n for (const r of records) {\n const applied = constraintInactiveWhy(r, active) === null;\n const bones = Int32Array.from((r.kind === 'physics' ? [r.bone] : r.kind === 'slider' ? r.timelines.bones.filter(t => t.timelines.length > 0).map(t => t.name) : r.bones).map(indexOf));\n const index = constraints.length;\n if (r.kind === 'physics') {\n constraints.push({ kind: 'physics', name: r.name, index, applied, bones, setup: r });\n continue;\n }\n if (r.kind === 'slider') {\n constraints.push({ kind: 'slider', name: r.name, index, applied, bones, setup: r, bone: r.bone === null ? -1 : indexOf(r.bone), property: TRANSFORM_PROPERTIES.indexOf(r.property), animation: null as unknown as RuntimeAnimation });\n continue;\n }\n if (applied && r.bones.some((b) => !active.has(b))) refusals.note('inactive-constrained-bone', `${r.kind} constraint \"${r.name}\" names bone(s) ${r.bones.filter((b) => !active.has(b)).map((b) => `\"${b}\"`).join(', ')}, which the view leaves inactive — what the oracle writes there depends on the pass before`);\n if (r.kind === 'ik') constraints.push(compileIk(r, index, applied, bones, indexOf));\n else if (r.kind === 'path') {\n constraints.push(compilePath(r, index, applied, bones, indexOf, slotIndexOf, pathPlan.get(index) ?? null));\n } else {\n const noScaleWorld = !r.localTarget && bones.some(b => parents[b] >= 0 && (modes[b] === MODE_NO_SCALE || modes[b] === MODE_NO_SCALE_OR_REFLECTION));\n const t = compileTransform(r, index, applied && !(plant.omitLocalTransform && (r.localSource || r.localTarget)) && !(plant.omitNoScaleWorldTransform && noScaleWorld) && !(plant.omitAdditiveTransform && r.additive), bones, indexOf);\n constraints.push(t);\n }\n }\n\n // --- slots and the records they show ---\n const hasClipping = doc.skins.some(s => Object.values(s.attachments).some(table => Object.values(table).some(at => at.geometry?.kind === 'clipping')));\n const attachments: RuntimeAttachment[] = [];\n let vertexCount = 0;\n let deformCount = 0;\n const sourceOf = sourceOfDoc(doc);\n const attachmentView = plant.attachmentSkin === undefined ? doc : underSkin(doc, plant.attachmentSkin);\n /** Per slot, each placeholder's attachment index (−1 shows nothing) and what it misses, resolved once and its refusal noted for every animation that shows it. */\n const resolvedBySlot = doc.slots.map(() => new Map<string | null, { index: number; missing: readonly [RuntimeFeature, string] | null }>());\n const resolve = (si: number, placeholder: string | null, animation: string | null): number => {\n const cache = resolvedBySlot[si];\n let kept = cache.get(placeholder);\n if (kept === undefined) {\n kept = resolveRecord(si, placeholder);\n cache.set(placeholder, kept);\n }\n if (kept.missing !== null) refusals.note(kept.missing[0], kept.missing[1], animation);\n return kept.index;\n };\n const resolveRecord = (si: number, placeholder: string | null): { index: number; missing: readonly [RuntimeFeature, string] | null } => {\n const slot = doc.slots[si];\n const shown = placeholder === null ? null : shownAttachment(attachmentView, slot, placeholder);\n if (shown === null) return { index: -1, missing: null };\n if ('conflict' in shown) return { index: -1, missing: ['skin-conflict', `slot \"${slot.name}\" placeholder \"${placeholder}\" is filled by skins that disagree`] };\n const row = shownRow(shown);\n const g = shown.record.geometry;\n const at = { timeline: timelineIdentity(slot.name, shown), deformOffset: deformCount, slot: si, name: row.name, skin: shown.skin, placeholder: shown.placeholder, path: CORE_REGION_KINDS.has(shown.record.kind) ? row.path : null, bone: indexOf(slot.bone), offset: vertexCount };\n let made: RuntimeAttachment | null = null;\n let missing: readonly [RuntimeFeature, string] | null = null;\n if (g?.kind === 'clipping') {\n made = { ...meshAttachment(at, g.vertices, indexOf, plant.bindingIndex, nb), clip: { end: g.end, inverse: g.inverse, convex: g.convex } };\n }\n else if (g?.kind === 'region') {\n const r = g.region;\n if (r.atlas === null) missing = ['null-atlas-region', `slot \"${slot.name}\" shows region \"${row.name}\", whose atlas rectangle the model states as null`];\n else {\n // `regionCorners`' local half (src/core/vertices.ts), the same operations in the same order: only `a·lx + b·ly + worldX` depends on the pose.\n const W = r.width;\n const H = r.height;\n const sx = r.scaleX ?? 1;\n const sy = r.scaleY ?? 1;\n const rect = r.atlas;\n const kx = (W / rect.originalWidth) * sx;\n const ky = (H / rect.originalHeight) * sy;\n const x1 = (-W / 2) * sx + rect.offsetX * kx;\n const y1 = (-H / 2) * sy + rect.offsetY * ky;\n const x2 = x1 + rect.width * kx;\n const y2 = y1 + rect.height * ky;\n const angle = (r.rotation ?? 0) * RAD;\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n const x = r.x ?? 0;\n const y = r.y ?? 0;\n const local = new Float64Array(8);\n const corners = [x1, y1, x1, y2, x2, y2, x2, y1];\n for (let k = 0; k < 8; k += 2) {\n const px = corners[k];\n const py = corners[k + 1];\n local[k] = px * cos + x - py * sin;\n local[k + 1] = py * cos + y + px * sin;\n }\n made = vertexAttachment(at, DRAW_REGION, local, 8);\n }\n } else if (g?.kind === 'mesh' || g?.kind === 'linkedmesh') {\n const source = g.kind === 'mesh' ? g.vertices : sourceOf(g.skin, g.slot, g.source);\n if (typeof source === 'string') throw new RuntimeInputError(`slot \"${slot.name}\": ${source} (readModel refuses it first)`);\n made = meshAttachment(at, source, indexOf, plant.bindingIndex, nb);\n } else if (g?.kind === 'path') {\n made = pathAttachment(at, g.vertices, indexOf, plant.bindingIndex, nb);\n }\n // A bounding box, a refused record admitted by a plant: the row's name and path, and nothing drawn.\n if (made === null) made = vertexAttachment(at, DRAW_NONE, new Float64Array(0), 0);\n if (hasClipping) {\n if (g?.kind === 'region') made = { ...made, clipTopology: { triangles: new Int32Array([0, 1, 2, 2, 3, 0]), uvs: new Float64Array([0, 1, 0, 0, 1, 0, 1, 1]) } };\n else if (g?.kind === 'mesh' || g?.kind === 'linkedmesh') {\n const mesh = g.kind === 'mesh' ? g : doc.skins.find(s => s.name === g.skin)?.attachments[g.slot]?.[g.source]?.geometry;\n if (mesh?.kind !== 'mesh') throw new RuntimeInputError('clipping topology: linked source is not a mesh (readModel refuses it first)');\n made = { ...made, clipTopology: { triangles: Int32Array.from(mesh.triangles), uvs: Float64Array.from(mesh.uvs) } };\n }\n }\n attachments.push(made);\n vertexCount += made.count;\n deformCount += made.deformCount;\n return { index: attachments.length - 1, missing };\n };\n const slots: RuntimeSlot[] = doc.slots.map((slot, si) => {\n const bone = indexOf(slot.bone);\n const light = slot.color === undefined ? [1, 1, 1, 1] : readColour(slot.color);\n return {\n name: slot.name,\n bone,\n // A slot on a bone the view leaves inactive is not animated (`slotTimelinesApply` in src/core/skins.ts).\n live: active.has(slot.bone),\n setupAttachment: resolve(si, slot.setup, null),\n light: Float64Array.from(light),\n dark: slot.dark === undefined ? null : Float64Array.from(readColour(slot.dark).slice(0, 3)),\n blend: readBlend(slot),\n };\n });\n let hasPath = false;\n let maxPathSpaces = 0;\n let maxPathVertices = 0;\n for (const c of constraints) {\n if (c.kind !== 'path') continue;\n hasPath = true;\n c.attachment = c.setup.path === null ? -1 : slots[c.slot].setupAttachment;\n const spaceCount = c.rotateMode === PATH_ROTATE_TANGENT ? c.bones.length : c.bones.length + 1;\n if (spaceCount > maxPathSpaces) maxPathSpaces = spaceCount;\n if (c.attachment >= 0) {\n const at = attachments[c.attachment];\n c.pathVertices = at.bindingCounts.length > 0 ? at.bindingCounts.length * 2 : at.local.length;\n if (c.pathVertices > maxPathVertices) maxPathVertices = c.pathVertices;\n }\n }\n\n // --- animations ---\n const animations = new Map<string, RuntimeAnimation>();\n const refused: Array<{ animation: string; missing: RuntimeMissing[] }> = [];\n let cursorMax = 0;\n for (const anim of doc.animations) {\n const compiled = compileAnimation(anim, refusals, ignoreEvents, boneIndex, slotIndex, slots, constraints, doc, (si, ph) => resolve(si, ph, anim.name));\n const missing = refusals.byAnimation.get(anim.name);\n if (missing !== undefined && missing.length > 0) refused.push({ animation: anim.name, missing });\n else {\n animations.set(anim.name, compiled);\n cursorMax = Math.max(cursorMax, compiled.cursors);\n }\n }\n\n for (const c of constraints) if (c.kind === 'slider') {\n const a = animations.get(c.setup.animation);\n if (a !== undefined) c.animation = a;\n else for (const m of refusals.byAnimation.get(c.setup.animation) ?? []) refusals.note(m.feature, `slider \"${c.name}\" applies refused animation \"${c.setup.animation}\": ${m.detail}`);\n }\n if (refusals.model.length > 0) throw new RuntimeRefusal(refusals.model);\n const names = doc.animations.map((a) => a.name);\n return {\n omitPhysics: plant.omitPhysics === true,\n sliderAsTrack: plant.sliderAsTrack === true,\n omitDeform: plant.omitDeform === true,\n deformAfterWeights: plant.deformAfterWeights === true,\n omitPath: plant.omitPath === true,\n ignorePhysicsScope: plant.ignorePhysicsScope === true,\n omitDrawOrder: plant.omitDrawOrder === true,\n omitDarkColour: plant.omitDarkColour === true,\n hasPath,\n maxPathSpaces,\n maxPathVertices,\n deformCount,\n eventWrapOffByOne: plant.eventWrapOffByOne === true,\n restoreEventsFromStart: plant.restoreEventsFromStart === true,\n doc,\n boneNames: doc.bones.map((b) => b.name),\n parents,\n modes,\n active: activeFlags,\n lengths,\n setup,\n subtreeStart,\n subtrees: Int32Array.from(flat),\n slots,\n attachments,\n vertexCount,\n constraints,\n animations,\n refused,\n cursors: cursorMax,\n scratch: plant.scratchByBones === true ? Math.max(1, nb) : Math.max(1, nb, ...constraints.map((c) => c.bones.length)),\n animation(name: string): RuntimeAnimation {\n const found = animations.get(name);\n if (found !== undefined) return found;\n const no = refused.find((r) => r.animation === name);\n if (no !== undefined) throw new RuntimeRefusal(no.missing);\n throw new RuntimeInputError(`animation ${JSON.stringify(name)} is not one of this document's [${names.join(', ')}]`);\n },\n };\n}\n\ntype AttachmentHead = { timeline: string | null; deformOffset: number; slot: number; name: string; skin: string; placeholder: string; path: string | null; bone: number; offset: number };\n\nconst NO_INTS = new Int32Array(0);\nconst NO_NUMBERS = new Float64Array(0);\n\nfunction vertexAttachment(at: AttachmentHead, draw: number, local: Float64Array, count: number): RuntimeAttachment {\n return { ...at, draw, local, count, deformCount: draw === DRAW_MESH ? count : 0, bindingCounts: NO_INTS, bindingBones: NO_INTS, bindingX: NO_NUMBERS, bindingY: NO_NUMBERS, bindingWeights: NO_NUMBERS };\n}\n\n/** A mesh's (or a linked mesh's source's) vertices: every stored number through `Math.fround` (src/core/vertices.ts, *A mesh's vertices*). */\nfunction meshAttachment(at: AttachmentHead, vertices: ModelVertices, indexOf: (name: string) => number, rewrite: RuntimePlant['bindingIndex'], bones: number): RuntimeAttachment {\n if (!vertices.weighted) {\n const n = vertices.xy.length - (vertices.xy.length % 2);\n const local = new Float64Array(n);\n for (let i = 0; i < n; i++) local[i] = Math.fround(vertices.xy[i]);\n return vertexAttachment(at, DRAW_MESH, local, n);\n }\n const counts: number[] = [];\n const ids: number[] = [];\n const xs: number[] = [];\n const ys: number[] = [];\n const ws: number[] = [];\n for (const influences of vertices.bindings) {\n counts.push(influences.length);\n for (const b of influences) {\n const i = indexOf(b.bone);\n ids.push(rewrite === undefined ? i : rewrite(i, bones));\n xs.push(Math.fround(b.x));\n ys.push(Math.fround(b.y));\n ws.push(Math.fround(b.weight));\n }\n }\n return { ...at, deformCount: ids.length * 2, draw: DRAW_WEIGHTED, local: NO_NUMBERS, count: counts.length * 2, bindingCounts: Int32Array.from(counts), bindingBones: Int32Array.from(ids), bindingX: Float64Array.from(xs), bindingY: Float64Array.from(ys), bindingWeights: Float64Array.from(ws) };\n}\n\n/** A path attachment's vertices and bindings: stored and deformed like a mesh, never drawn into `RuntimePose.vertices`. */\nfunction pathAttachment(at: AttachmentHead, vertices: ModelVertices, indexOf: (name: string) => number, rewrite: RuntimePlant['bindingIndex'], bones: number): RuntimeAttachment {\n const m = meshAttachment(at, vertices, indexOf, rewrite, bones);\n return { ...m, draw: DRAW_NONE, count: 0 };\n}\n\nfunction compileIk(r: CoreIkRecord, index: number, applied: boolean, bones: Int32Array, indexOf: (name: string) => number): RuntimeIk {\n return {\n kind: 'ik', name: r.name, index, applied, bones, target: indexOf(r.target),\n scaleY: r.scaleY === 'uniform' ? SCALE_Y_UNIFORM : r.scaleY === 'volume' ? SCALE_Y_VOLUME : SCALE_Y_NONE,\n mix: r.mix, softness: r.softness, flags: ikFlags(r.bendPositive, r.compress, r.stretch),\n };\n}\n\nfunction ikFlags(bendPositive: boolean, compress: boolean, stretch: boolean): number {\n return (bendPositive ? IK_BEND_POSITIVE : 0) | (compress ? IK_COMPRESS : 0) | (stretch ? IK_STRETCH : 0);\n}\n\nfunction compilePath(\n r: CorePathRecord,\n index: number,\n applied: boolean,\n bones: Int32Array,\n indexOf: (name: string) => number,\n slotIndexOf: (name: string) => number,\n ev: SlotBoneEvent | null,\n): RuntimePath {\n return {\n kind: 'path',\n name: r.name,\n index,\n applied,\n bones,\n slot: slotIndexOf(r.slot),\n slotBone: indexOf(r.slotBone),\n attachment: -1,\n pathVertices: 0,\n closed: r.path?.closed ?? false,\n constantSpeed: r.path?.constantSpeed ?? true,\n lengths: Float64Array.from(r.path?.lengths ?? []),\n positionMode: r.positionMode === 'fixed' ? PATH_POSITION_FIXED : PATH_POSITION_PERCENT,\n spacingMode: r.spacingMode === 'fixed' ? PATH_SPACING_FIXED : r.spacingMode === 'percent' ? PATH_SPACING_PERCENT : r.spacingMode === 'proportional' ? PATH_SPACING_PROPORTIONAL : PATH_SPACING_LENGTH,\n rotateMode: r.rotateMode === 'chain' ? PATH_ROTATE_CHAIN : r.rotateMode === 'chainScale' ? PATH_ROTATE_CHAIN_SCALE : PATH_ROTATE_TANGENT,\n offsetRotation: r.offsetRotation,\n position: r.position,\n spacing: r.spacing,\n mixRotate: r.mixRotate,\n mixX: r.mixX,\n mixY: r.mixY,\n slotEventAt: ev === null ? -1 : ev.at,\n slotEventAfter: ev?.when === 'after',\n setup: r,\n };\n}\n\nfunction compileTransform(r: CoreTransformRecord, index: number, applied: boolean, bones: Int32Array, indexOf: (name: string) => number): RuntimeTransform {\n const fromProperty: number[] = [];\n const fromOffset: number[] = [];\n const toStart: number[] = [];\n const toEnd: number[] = [];\n const toProperty: number[] = [];\n const toOffset: number[] = [];\n const toScale: number[] = [];\n const toMax: number[] = [];\n for (const from of r.properties) {\n fromProperty.push(TRANSFORM_PROPERTIES.indexOf(from.property));\n fromOffset.push(from.offset);\n toStart.push(toProperty.length);\n for (const to of from.to) {\n toProperty.push(TRANSFORM_PROPERTIES.indexOf(to.property));\n toOffset.push(to.offset);\n toScale.push(to.scale);\n toMax.push(to.max);\n }\n toEnd.push(toProperty.length);\n }\n return {\n kind: 'transform', name: r.name, index, applied, bones, source: indexOf(r.source),\n fromProperty: Int32Array.from(fromProperty), fromOffset: Float64Array.from(fromOffset), toStart: Int32Array.from(toStart), toEnd: Int32Array.from(toEnd),\n toProperty: Int32Array.from(toProperty), toOffset: Float64Array.from(toOffset), toScale: Float64Array.from(toScale), toMax: Float64Array.from(toMax),\n offsets: Float64Array.from(TRANSFORM_PROPERTIES.map((p) => r.offsets[p])),\n mixes: Float64Array.from(TRANSFORM_PROPERTIES.map((p) => r.mixes[p])),\n clamp: r.clamp, localSource: r.localSource, localTarget: r.localTarget, additive: r.additive,\n };\n}\n\n/**\n * One animation compiled, its constructs not yet posed noted against it. The\n * oracle's lookups are kept: a bone or slot keyed by two targets takes the\n * LAST target (`posedBones`, `posedSlots` build a map of them), a constraint\n * keyed by two timelines the FIRST (`posedRecords` finds it).\n */\nfunction compileAnimation(\n anim: CoreAnimation,\n refusals: Refusals,\n ignoreEvents: boolean,\n boneIndex: ReadonlyMap<string, number>,\n slotIndex: ReadonlyMap<string, number>,\n slots: readonly RuntimeSlot[],\n constraints: readonly RuntimeConstraint[],\n doc: CompiledDocument,\n resolve: (slot: number, placeholder: string | null) => number,\n): RuntimeAnimation {\n const tl = anim.timelines;\n const name = anim.name;\n let cursors = 0;\n const deform = tl.attachments.filter((a) => a.deform !== null);\n const sequence = tl.attachments.filter((a) => a.sequence !== null);\n\n if (sequence.length > 0) refusals.note('sequence-timeline', `${sequence.length} sequence timeline(s): ${sequence.slice(0, 3).map((a) => `${a.skin}/${a.slot}/${a.attachment}`).join(', ')}${sequence.length > 3 ? ', …' : ''}`, name);\n\n let drawOrder: RuntimeDrawOrderTimeline | null = null;\n if (tl.drawOrder.length > 0) {\n const ns = slots.length;\n const orders = new Int32Array(tl.drawOrder.length * ns).fill(-1);\n const moved = new Uint8Array(ns);\n for (let i = 0; i < tl.drawOrder.length; i++) {\n const base = i * ns;\n moved.fill(0);\n for (const m of tl.drawOrder[i].moves) {\n orders[base + m.slot + m.offset] = m.slot;\n moved[m.slot] = 1;\n }\n for (let s = 0, d = 0; s < ns; s++) {\n if (moved[s] !== 0) continue;\n while (orders[base + d] !== -1) d++;\n orders[base + d] = s;\n d++;\n }\n }\n drawOrder = { curve: compileCurve(tl.drawOrder, 0), cursor: cursors++, orders };\n }\n\n const lastBy = <T extends { name: string }>(targets: readonly T[]): Map<string, T> => new Map(targets.map((t) => [t.name, t]));\n const bones: RuntimeBoneTimeline[] = [];\n type BoneTarget = (typeof tl.bones)[number];\n const byTarget = new Map<BoneTarget, RuntimeBoneTimeline[]>();\n const compileBones = (target: BoneTarget, forSlider: boolean): RuntimeBoneTimeline[] => {\n const cached = byTarget.get(target);\n if (cached !== undefined) return cached;\n const keyed: RuntimeBoneTimeline[] = [];\n byTarget.set(target, keyed);\n const bone = boneIndex.get(target.name);\n if (bone === undefined) return keyed;\n for (const t of target.timelines) {\n if (t.kind === 'inherit') {\n if (!forSlider) refusals.note('inherit-timeline', `bone \"${target.name}\" keys its inherit mode`, name);\n else for (const c of constraints) if (c.kind === 'slider' && c.setup.animation === name) {\n refusals.note('inherit-timeline', `slider \"${c.name}\" applies animation \"${name}\" whose bone \"${target.name}\" keys its inherit mode`);\n }\n continue;\n }\n const spec = BONE_KINDS[t.kind];\n keyed.push({ bone, curve: compileCurve(t.keys, spec.length), cursor: cursors++, fields: Int32Array.from(spec.map((s) => s[0])), multiply: Uint8Array.from(spec.map((s) => s[1])) });\n }\n return keyed;\n };\n // Keep the track's last-target Map order and reuse those exact curves/cursors.\n for (const target of lastBy(tl.bones).values()) bones.push(...compileBones(target, false));\n const sliderBones = constraints.some(c => c.kind === 'slider' && c.setup.animation === name)\n ? tl.bones.flatMap(target => compileBones(target, true)) : [];\n const slotTimelines: RuntimeSlotTimeline[] = [];\n const keyedSlots = [...lastBy(tl.slots).values()].flatMap((target) => {\n const si = slotIndex.get(target.name);\n return si === undefined ? [] : [{ si, target }];\n }).sort((a, b) => a.si - b.si);\n for (const { si, target } of keyedSlots) {\n // A slot on an inactive bone is not animated: its timelines are read and posed by nothing.\n if (!slots[si].live) continue;\n for (const t of target.timelines) {\n if (t.kind === 'attachment') {\n const ids = Int32Array.from(t.keys.map((k) => resolve(si, k.name ?? null)));\n slotTimelines.push({ slot: si, curve: compileCurve(t.keys, 0), cursor: cursors++, attachments: ids, channels: null });\n } else {\n const channels = COLOUR_CHANNELS[t.kind];\n slotTimelines.push({ slot: si, curve: compileCurve(t.keys, channels.length), cursor: cursors++, attachments: null, channels: Int32Array.from(channels) });\n }\n }\n }\n const constraintTimelines: Array<RuntimeConstraintTimeline | null> = constraints.map(() => null);\n for (const c of constraints) {\n if (c.kind === 'ik') {\n const keyed = anim.constraints.ik.find((x) => x.name === c.name);\n if (keyed === undefined) continue;\n constraintTimelines[c.index] = { constraint: c.index, curve: compileCurve(keyed.keys, 2), cursor: cursors++, flags: Uint8Array.from(keyed.keys.map((k) => ikFlags(k.flags.bendPositive, k.flags.compress, k.flags.stretch))) };\n } else if (c.kind === 'transform') {\n const keyed = anim.constraints.transform.find((x) => x.name === c.name);\n if (keyed === undefined) continue;\n constraintTimelines[c.index] = { constraint: c.index, curve: compileCurve(keyed.keys, TRANSFORM_PROPERTIES.length), cursor: cursors++, flags: null };\n }\n }\n const sliders = constraints.map((c): RuntimeSliderTimeline | null => {\n if (c.kind !== 'slider') return null;\n const keyed = anim.constraints.slider.find(t => t.name === c.name);\n if (keyed === undefined) return null;\n return { time: keyed.time === null ? null : compileCurve(keyed.time, 1), mix: keyed.mix === null ? null : compileCurve(keyed.mix, 1), timeCursor: cursors++, mixCursor: cursors++ };\n });\n const paths = constraints.map((c): RuntimePathTimeline | null => {\n if (c.kind !== 'path') return null;\n const keyed = anim.constraints.path.find((t) => t.name === c.name);\n if (keyed === undefined) return null;\n return {\n position: keyed.position === undefined ? null : compileCurve(keyed.position, 1),\n spacing: keyed.spacing === undefined ? null : compileCurve(keyed.spacing, 1),\n mix: keyed.mix === undefined ? null : compileCurve(keyed.mix, 3),\n positionCursor: cursors++,\n spacingCursor: cursors++,\n mixCursor: cursors++,\n };\n });\n const physics: RuntimePhysicsTimeline[] = (anim.constraints.physicsKeyed ?? []).map(t => ({\n kind: t.kind, cursor: cursors++, curve: compileCurve(t.keys, t.kind === 'reset' ? 0 : 1),\n targets: Int32Array.from(constraints.filter((c): c is RuntimePhysics => c.kind === 'physics' && c.applied && (t.name === '*' ? t.kind === 'reset' || c.setup.global[t.kind] : c.name === t.name)).map(c => c.index)),\n }));\n const deforms: RuntimeDeformTimeline[] = deform.map(a => {\n const g = doc.skins.find(s => s.name === a.skin)?.attachments[a.slot]?.[a.attachment]?.geometry;\n if (g === undefined || g.kind === 'region' || g.kind === 'linkedmesh') throw new RuntimeInputError(`deform \"${a.skin}/${a.slot}/${a.attachment}\" has no vertex geometry (readModel refuses it first)`);\n const keys = a.deform!;\n const arrays = keys.map(k => heldArray(g.vertices, k));\n return { identity: `${a.skin}/${a.slot}/${a.attachment}`, cursor: cursors++, curve: compileDeformCurve(keys), count: arrays[0].length, held: Float64Array.from(arrays.flat()) };\n });\n return { name, duration: tl.duration, physics, sliders, paths, deforms, bones, sliderBones, slots: slotTimelines, drawOrder, constraints: constraintTimelines, cursors, events: tl.events.length, eventKeys: Object.freeze(ignoreEvents ? [] : tl.events.map(key => Object.freeze({ name: key.name, time: key.time, int: key.int, float: key.float, string: key.string, volume: key.volume ?? 0, balance: key.balance ?? 0 }))) };\n}\n","/** Buffered counterpart of clipShapeOf/clipThrough/clipTriangles in src/core/clipping.ts.\n * RuntimePose.computeClipped overwrites these buffers for the live draw order.\n * Scratch and outputs are allocated at load; a frame changes counts and array cells only.\n * Concave/inverse output follows the core's drawn geometry, not an unclaimed Spine triangulation.\n */\nexport class RuntimeClipBuffer {\n readonly vertices: Float32Array;\n readonly uvs: Float32Array;\n readonly triangles: Int32Array;\n readonly sources: Int32Array;\n vertexCount = 0;\n triangleCount = 0;\n clipped = false;\n constructor(triangles: number, polygonVertices: number) {\n const points = triangles * Math.max(3, polygonVertices * (polygonVertices + 3));\n if (!Number.isSafeInteger(points) || points < 0) throw new Error('runtime clip: output capacity is not a safe non-negative integer');\n this.vertices = new Float32Array(points * 2); this.uvs = new Float32Array(points * 2);\n this.triangles = new Int32Array(points * 3); this.sources = new Int32Array(points);\n }\n}\n\nexport class RuntimeClipper {\n /** Whether the original world polygon has the oracle native convex triangle-list contract. */\n nativeRows = false;\n private readonly points: Float64Array;\n private readonly ring: Int32Array;\n private readonly work: Int32Array;\n private readonly sorted: Int32Array;\n private readonly hull: Int32Array;\n private readonly pieces: Int32Array;\n private readonly sizes: Int32Array;\n private readonly merged: Int32Array;\n private readonly regions: Float64Array;\n private readonly regionSizes: Int32Array;\n private readonly a: Float64Array;\n private readonly b: Float64Array;\n private readonly outside: Float64Array;\n private readonly tri = new Float64Array(6);\n private readonly uv = new Float64Array(6);\n private regionsCount = 0;\n private inverse = false;\n private cut = false;\n private n = 0;\n constructor(readonly maxPolygonVertices: number) {\n const n = Math.max(3, maxPolygonVertices);\n this.points = new Float64Array(n * 2); this.ring = new Int32Array(n); this.work = new Int32Array(n);\n this.sorted = new Int32Array(n); this.hull = new Int32Array(n * 2); this.pieces = new Int32Array(n * n);\n this.sizes = new Int32Array(n); this.merged = new Int32Array(n * 2);\n this.regions = new Float64Array(n * n * 2); this.regionSizes = new Int32Array(n);\n this.a = new Float64Array((n * 2 + 16) * 2); this.b = new Float64Array(this.a.length); this.outside = new Float64Array(this.a.length);\n }\n private cross(a: number, b: number, c: number): number {\n const p = this.points; return (p[b * 2] - p[a * 2]) * (p[c * 2 + 1] - p[a * 2 + 1]) - (p[b * 2 + 1] - p[a * 2 + 1]) * (p[c * 2] - p[a * 2]);\n }\n private area(indices: Int32Array, n: number): number {\n const p = this.points; let area = 0;\n for (let i = 0; i < n; i++) { const a = indices[i] * 2, b = indices[(i + 1) % n] * 2; area += p[a] * p[b + 1] - p[b] * p[a + 1]; }\n return area;\n }\n private convex(indices: Int32Array, n: number, start = 0): boolean {\n let sign = 0;\n for (let i = 0; i < n; i++) {\n const p = this.points, a = indices[start + i] * 2, b = indices[start + (i + 1) % n] * 2, c = indices[start + (i + 2) % n] * 2;\n // convexWhy takes the second edge from b, unlike cross3 used by triangulation.\n const cross = (p[b] - p[a]) * (p[c + 1] - p[b + 1]) - (p[b + 1] - p[a + 1]) * (p[c] - p[b]);\n if (cross === 0) return false;\n const next = Math.sign(cross); if (sign === 0) sign = next; else if (sign !== next) return false;\n }\n return true;\n }\n private on(a: number, b: number, r: number): boolean {\n const p = this.points; return Math.min(p[a * 2], p[b * 2]) <= p[r * 2] && p[r * 2] <= Math.max(p[a * 2], p[b * 2]) && Math.min(p[a * 2 + 1], p[b * 2 + 1]) <= p[r * 2 + 1] && p[r * 2 + 1] <= Math.max(p[a * 2 + 1], p[b * 2 + 1]);\n }\n private meet(a: number, b: number, c: number, d: number): boolean {\n const d1 = this.cross(c, d, a), d2 = this.cross(c, d, b), d3 = this.cross(a, b, c), d4 = this.cross(a, b, d);\n if (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0))) return true;\n return d1 === 0 && this.on(c, d, a) || d2 === 0 && this.on(c, d, b) || d3 === 0 && this.on(a, b, c) || d4 === 0 && this.on(a, b, d);\n }\n private region(indices: Int32Array, n: number, r: number, start = 0): void {\n const p = this.points; let area = 0;\n for (let i = 0; i < n; i++) { const a = indices[start + i] * 2, b = indices[start + (i + 1) % n] * 2; area += p[a] * p[b + 1] - p[b] * p[a + 1]; }\n const base = r * this.maxPolygonVertices * 2;\n for (let i = 0; i < n; i++) { const j = indices[start + (area > 0 ? n - 1 - i : i)] * 2; this.regions[base + i * 2] = p[j]; this.regions[base + i * 2 + 1] = p[j + 1]; }\n this.regionSizes[r] = n;\n }\n private makeHull(count: number): number {\n const idx = this.sorted, p = this.points, h = this.hull;\n for (let i = 0; i < count; i++) {\n const v = this.ring[i]; let j = i;\n while (j > 0) { const u = idx[j - 1]; if (p[u * 2] < p[v * 2] || p[u * 2] === p[v * 2] && p[u * 2 + 1] <= p[v * 2 + 1]) break; idx[j] = u; j--; }\n idx[j] = v;\n }\n let used = 0;\n for (let i = 0; i < count; i++) { const v = idx[i]; while (used >= 2 && this.cross(h[used - 2], h[used - 1], v) <= 0) used--; h[used++] = v; }\n used--;\n const lower = used;\n for (let i = count - 1; i >= 0; i--) { const v = idx[i]; while (used >= lower + 2 && this.cross(h[used - 2], h[used - 1], v) <= 0) used--; h[used++] = v; }\n return used - 1;\n }\n private plan(inverse: boolean, convex: boolean): boolean {\n this.nativeRows = false;\n const n = this.n, p = this.points, ring = this.ring;\n let repeats = 0, distinct = 0;\n for (let i = 0; i < n; i++) {\n ring[i] = i;\n for (let j = i + 1; j < n; j++) if (p[i * 2] === p[j * 2] && p[i * 2 + 1] === p[j * 2 + 1]) repeats++;\n const j = (i + 1) % n;\n if (p[i * 2] !== p[j * 2] || p[i * 2 + 1] !== p[j * 2 + 1]) this.work[distinct++] = i;\n }\n if (repeats > 0) {\n if (!inverse && distinct === n - repeats && distinct >= 3 && this.convex(this.work, distinct)) { this.regionsCount = 1; this.inverse = false; this.region(ring, n, 0); return false; }\n throw new Error('runtime clip: polygon has repeated vertices unsupported by clipShapeOf');\n }\n for (let i = 0; i < n; i++) {\n const j = (i + 1) % n, k = (i + 2) % n;\n if (this.cross(i, j, k) === 0 && (p[k * 2] - p[j * 2]) * (p[i * 2] - p[j * 2]) + (p[k * 2 + 1] - p[j * 2 + 1]) * (p[i * 2 + 1] - p[j * 2 + 1]) > 0) throw new Error('runtime clip: neighbouring polygon edges fold back');\n for (let q = i + 2; q < n; q++) if (!(i === 0 && q === n - 1) && this.meet(i, j, q, (q + 1) % n)) throw new Error('runtime clip: polygon edges cross or touch');\n }\n const originalConvex = this.convex(ring, n);\n this.nativeRows = !inverse && originalConvex;\n let count = n;\n for (let changed = true; changed && count > 3;) {\n changed = false;\n for (let i = 0; i < count; i++) if (this.cross(ring[(i + count - 1) % count], ring[i], ring[(i + 1) % count]) === 0) { ring.copyWithin(i, i + 1, count); count--; changed = true; break; }\n }\n if (count === 3 && this.cross(ring[0], ring[1], ring[2]) === 0) throw new Error('runtime clip: every polygon vertex lies on one line');\n this.inverse = inverse;\n if (inverse || !originalConvex && convex) { this.regionsCount = 1; this.region(this.hull, this.makeHull(count), 0); return false; }\n if (originalConvex) { for (let i = 0; i < n; i++) ring[i] = i; this.regionsCount = 1; this.region(ring, n, 0); return false; }\n if (this.area(ring, count) < 0) for (let i = 0; i < count / 2; i++) { const j = count - 1 - i, v = ring[i]; ring[i] = ring[j]; ring[j] = v; }\n this.work.set(ring); let left = count, pieces = 0;\n while (left > 3) {\n let found = false;\n for (let k = 0; k < left; k++) {\n const a = this.work[(k + left - 1) % left], b = this.work[k], c = this.work[(k + 1) % left];\n if (this.cross(a, b, c) <= 0) continue;\n let inside = false;\n for (let j = 0; j < left; j++) { const v = this.work[j]; if (v !== a && v !== b && v !== c && this.cross(a, b, v) >= 0 && this.cross(b, c, v) >= 0 && this.cross(c, a, v) >= 0) { inside = true; break; } }\n if (inside) continue;\n const base = pieces * this.maxPolygonVertices; this.pieces[base] = a; this.pieces[base + 1] = b; this.pieces[base + 2] = c; this.sizes[pieces++] = 3;\n this.work.copyWithin(k, k + 1, left); left--; found = true; break;\n }\n if (!found) throw new Error('runtime clip: no ear left in a polygon held simple');\n }\n for (let i = 0; i < 3; i++) this.pieces[pieces * this.maxPolygonVertices + i] = this.work[i]; this.sizes[pieces++] = 3;\n for (let changed = true; changed;) {\n changed = false;\n search: for (let a = 0; a < pieces; a++) for (let b = a + 1; b < pieces; b++) {\n const an = this.sizes[a], bn = this.sizes[b], ab = a * this.maxPolygonVertices, bb = b * this.maxPolygonVertices;\n for (let i = 0; i < an; i++) {\n const u = this.pieces[ab + i], v = this.pieces[ab + (i + 1) % an]; let j = -1;\n for (let k = 0; k < bn; k++) if (this.pieces[bb + k] === v) { j = k; break; }\n if (j < 0 || this.pieces[bb + (j + 1) % bn] !== u) continue;\n let size = 0;\n for (let k = 0; k <= i; k++) this.merged[size++] = this.pieces[ab + k];\n for (let k = (j + 2) % bn; k !== j; k = (k + 1) % bn) this.merged[size++] = this.pieces[bb + k];\n for (let k = i + 1; k < an; k++) this.merged[size++] = this.pieces[ab + k];\n let strict = true;\n for (let k = 0; k < size; k++) if (this.cross(this.merged[(k + size - 1) % size], this.merged[k], this.merged[(k + 1) % size]) <= 0) { strict = false; break; }\n if (!strict) continue;\n for (let k = 0; k < size; k++) this.pieces[ab + k] = this.merged[k]; this.sizes[a] = size;\n this.pieces.copyWithin(bb, bb + this.maxPolygonVertices, pieces * this.maxPolygonVertices); this.sizes.copyWithin(b, b + 1, pieces); pieces--; changed = true; break search;\n }\n }\n }\n this.regionsCount = pieces;\n for (let i = 0; i < pieces; i++) this.region(this.pieces, this.sizes[i], i, i * this.maxPolygonVertices);\n return pieces > 1;\n }\n /** Plan again after float32 conversion exactly when clipThrough first finds pieces. */\n prepare(polygon: Float64Array, offset: number, count: number, inverse: boolean, convex: boolean): void {\n this.n = count / 2;\n if (!Number.isInteger(this.n) || this.n < 3 || this.n > this.maxPolygonVertices) throw new Error('runtime clip: polygon vertex count exceeds its load-time capacity');\n for (let i = 0; i < count; i++) { const value = polygon[offset + i]; if (!Number.isFinite(value)) throw new Error('runtime clip: polygon contains a non-finite coordinate'); this.points[i] = value; }\n const replan = this.plan(inverse, convex), nativeRows = this.nativeRows;\n if (replan) { for (let i = 0; i < count; i++) this.points[i] = Math.fround(polygon[offset + i]); this.plan(inverse, convex); }\n this.nativeRows = nativeRows;\n }\n private half(input: Float64Array, n: number, px: number, py: number, qx: number, qy: number, out: Float64Array): number {\n let size = 0; this.cut = false; const ex = qx - px, ey = qy - py;\n for (let i = 0; i < n; i++) {\n const j = (i + 1) % n, sx = input[i * 2], sy = input[i * 2 + 1], tx = input[j * 2], ty = input[j * 2 + 1];\n const si = ex * (sy - py) - ey * (sx - px) < 0, ei = ex * (ty - py) - ey * (tx - px) < 0;\n if (!si || !ei) this.cut = true;\n if (si !== ei) { const dx = tx - sx, dy = ty - sy, t = (ex * (sy - py) - ey * (sx - px)) / (ey * dx - ex * dy); if (size * 2 + 2 > out.length) throw new Error('runtime clip: scratch polygon exceeds its load-time capacity'); out[size * 2] = sx + t * dx; out[size * 2 + 1] = sy + t * dy; size++; }\n if (ei) { if (size * 2 + 2 > out.length) throw new Error('runtime clip: scratch polygon exceeds its load-time capacity'); out[size * 2] = tx; out[size * 2 + 1] = ty; size++; }\n }\n return size;\n }\n private emit(points: Float64Array, count: number, cut: boolean, source: number, out: RuntimeClipBuffer): void {\n if (count < 3) return;\n if ((out.vertexCount + count) * 2 > out.vertices.length || out.triangleCount + count - 2 > out.sources.length) throw new Error('runtime clip: output exceeds its load-time capacity');\n const tri = this.tri, uv = this.uv, base = out.vertexCount;\n const d0 = tri[3] - tri[5], d1 = tri[4] - tri[2], d2 = tri[0] - tri[4], d4 = tri[5] - tri[1], d = 1 / (d0 * d2 + d1 * (tri[1] - tri[5]));\n for (let i = 0; i < count; i++) {\n const x = cut ? points[i * 2] : tri[i * 2], y = cut ? points[i * 2 + 1] : tri[i * 2 + 1], at = out.vertexCount++ * 2;\n out.vertices[at] = x; out.vertices[at + 1] = y;\n if (!cut) { out.uvs[at] = uv[i * 2]; out.uvs[at + 1] = uv[i * 2 + 1]; }\n else { const a = (d0 * (x - tri[4]) + d1 * (y - tri[5])) * d, b = (d4 * (x - tri[4]) + d2 * (y - tri[5])) * d, c = 1 - a - b; out.uvs[at] = uv[0] * a + uv[2] * b + uv[4] * c; out.uvs[at + 1] = uv[1] * a + uv[3] * b + uv[5] * c; }\n }\n for (let i = base * 2; i < out.vertexCount * 2; i++) if (!Number.isFinite(out.vertices[i]) || !Number.isFinite(out.uvs[i])) throw new Error(`runtime clip: triangle ${source} produced a non-finite clipped coordinate or UV`);\n for (let i = 1; i + 1 < count; i++) { const at = out.triangleCount * 3; out.triangles[at] = base; out.triangles[at + 1] = base + i; out.triangles[at + 2] = base + i + 1; out.sources[out.triangleCount++] = source; }\n }\n clip(vertices: Float64Array, offset: number, triangles: Int32Array, uvs: Float64Array, out: RuntimeClipBuffer): void {\n out.vertexCount = 0; out.triangleCount = 0; out.clipped = this.inverse;\n for (let k = 0; k < triangles.length; k += 3) {\n for (let j = 0; j < 3; j++) { const n = triangles[k + j] * 2; this.tri[j * 2] = vertices[offset + n]; this.tri[j * 2 + 1] = vertices[offset + n + 1]; this.uv[j * 2] = Math.fround(uvs[n]); this.uv[j * 2 + 1] = Math.fround(uvs[n + 1]); }\n if (!this.inverse) for (let r = 0; r < this.regionsCount; r++) {\n let input = this.a, output = this.b, count = 3, cut = false; for (let i = 0; i < 6; i++) input[i] = this.tri[i];\n const n = this.regionSizes[r], base = r * this.maxPolygonVertices * 2;\n for (let e = 0; e < n && count > 0; e++) { const p = base + e * 2, q = base + ((e + 1) % n) * 2; count = this.half(input, count, this.regions[p], this.regions[p + 1], this.regions[q], this.regions[q + 1], output); cut ||= this.cut; const swap = input; input = output; output = swap; }\n out.clipped ||= cut; this.emit(input, count, cut, k / 3, out);\n } else {\n let input = this.a, output = this.b, count = 3, cutSoFar = false; for (let i = 0; i < 6; i++) input[i] = this.tri[i];\n const n = this.regionSizes[0];\n for (let e = 0; e < n && count > 0; e++) { const p = e * 2, q = ((e + 1) % n) * 2, px = this.regions[p], py = this.regions[p + 1], qx = this.regions[q], qy = this.regions[q + 1];\n const outside = this.half(input, count, qx, qy, px, py, this.outside), cut = this.cut || cutSoFar; this.emit(this.outside, outside, cut, k / 3, out);\n count = this.half(input, count, px, py, qx, qy, output); cutSoFar ||= this.cut; const swap = input; input = output; output = swap;\n }\n }\n }\n }\n}\n","/** Stage-nine buffered draw walk; RuntimePose owns the frame buffers. */\nimport type { RuntimeModel } from './model.ts';\nimport type { RuntimePose } from './pose.ts';\nimport { RuntimeClipper, RuntimeClipBuffer } from './clipping.ts';\n/** Load once from the same model/view as the pose; frame() overwrites arrays and counts. */\nexport class RuntimeDrawClipper {\n readonly clipSlots: Int32Array;\n readonly drawSlots: Int32Array;\n readonly outputs: readonly RuntimeClipBuffer[];\n nativeRows = true;\n clipCount = 0;\n drawCount = 0;\n private readonly triangles: readonly (Int32Array | null)[];\n private readonly uvs: readonly (Float64Array | null)[];\n private readonly clipper: RuntimeClipper;\n constructor(readonly model: RuntimeModel) {\n const triangles: Array<Int32Array | null> = [], uvs: Array<Float64Array | null> = [], maxTriangles = new Int32Array(model.slots.length);\n let maxPolygon = 3;\n for (const at of model.attachments) {\n const t = at.clipTopology?.triangles ?? null, uv = at.clipTopology?.uvs ?? null;\n if (at.clip !== undefined) maxPolygon = Math.max(maxPolygon, at.count / 2);\n triangles.push(t); uvs.push(uv); if (t !== null) maxTriangles[at.slot] = Math.max(maxTriangles[at.slot], t.length / 3);\n }\n this.triangles = triangles; this.uvs = uvs; this.clipper = new RuntimeClipper(maxPolygon);\n this.clipSlots = new Int32Array(model.slots.length); this.drawSlots = new Int32Array(model.slots.length);\n this.outputs = Array.from(maxTriangles, n => new RuntimeClipBuffer(n, maxPolygon));\n }\n /** pose.computeVertices() must precede this walk. Omission is a diagnostic plant only. */\n frame(pose: RuntimePose, omit = false): void {\n if (pose.model !== this.model) throw new Error('runtime clip draw: pose differs from the prepared model');\n this.clipCount = 0; this.drawCount = 0; this.nativeRows = true;\n let active = false, end: string | null = null;\n for (let i = 0; i < pose.drawOrder.length; i++) {\n const s = pose.drawOrder[i], slot = this.model.slots[s], shown = pose.shown[s], at = shown < 0 ? null : this.model.attachments[shown];\n if (at?.clip !== undefined) {\n this.clipSlots[this.clipCount++] = s;\n if (active && end === slot.name) active = false;\n if (!omit && !active && this.model.active[at.bone] === 1) {\n this.clipper.prepare(pose.vertices, at.offset, at.count, at.clip.inverse, at.clip.convex); this.nativeRows &&= this.clipper.nativeRows; active = true; end = at.clip.end;\n }\n continue;\n }\n if (active && at !== null) {\n const triangles = this.triangles[shown], uvs = this.uvs[shown];\n if (triangles !== null && uvs !== null) {\n this.clipper.clip(pose.vertices, at.offset, triangles, uvs, this.outputs[s]); this.drawSlots[this.drawCount++] = s;\n }\n }\n if (active && end === slot.name) active = false;\n }\n }\n}\n","/** Indexed in-place physics. Arithmetic and operation order mirror the measured oracle;\n * state is allocated once per pose, never during an update. */\nimport type { CorePhysicsRecord } from '../core/constraints_physics.ts';\nimport { RUNTIME_PI } from '../core/world.ts';\nconst PI2 = RUNTIME_PI * 2;\nconst INV_PI2 = 1 / PI2;\nexport interface PhysicsState {\n /** The next update takes the bone where it is and integrates nothing: set by a reset and on a constraint never updated. */\n pending: boolean;\n lastTime: number;\n remaining: number;\n ux: number;\n uy: number;\n cx: number;\n cy: number;\n tx: number;\n ty: number;\n xOffset: number;\n xLag: number;\n xVelocity: number;\n yOffset: number;\n yLag: number;\n yVelocity: number;\n rotateOffset: number;\n rotateLag: number;\n rotateVelocity: number;\n scaleOffset: number;\n scaleLag: number;\n scaleVelocity: number;\n}\n\n/** A constraint's state before its first update: pending, its clock at 0. */\nexport function freshPhysicsState(): PhysicsState {\n return { pending: true, lastTime: 0, remaining: 0, ux: 0, uy: 0, cx: 0, cy: 0, tx: 0, ty: 0, xOffset: 0, xLag: 0, xVelocity: 0, yOffset: 0, yLag: 0, yVelocity: 0, rotateOffset: 0, rotateLag: 0, rotateVelocity: 0, scaleOffset: 0, scaleLag: 0, scaleVelocity: 0 };\n}\n\n/** A reset: offsets, velocities and lags cleared, nothing remaining, the clock read at `time`, pending. */\nexport function resetPhysicsState(s: PhysicsState, time: number): void {\n s.remaining = 0;\n s.lastTime = time;\n s.pending = true;\n s.xOffset = s.xLag = s.xVelocity = 0;\n s.yOffset = s.yLag = s.yVelocity = 0;\n s.rotateOffset = s.rotateLag = s.rotateVelocity = 0;\n s.scaleOffset = s.scaleLag = s.scaleVelocity = 0;\n}\n\nexport function stepRuntimePhysics(r: CorePhysicsRecord, s: PhysicsState, w: Float64Array, boneOffset: number, length: number, time: number, reset: boolean, env: Float64Array): boolean {\n const mix = r.mix;\n if (mix === 0) return false;\n const x = r.x > 0, y = r.y > 0, rotateOrShearX = r.rotate > 0 || r.shearX > 0, scaleX = r.scaleX > 0;\n const l = length;\n if (reset) resetPhysicsState(s, time);\n const delta = Math.max(time - s.lastTime, 0);\n // The interpolation weight of the previous update, before this one's time is added: the rotate and the scale-only inertia read the pose as it was shown.\n const shown = Math.max(0, 1 - s.remaining / r.step);\n s.remaining += delta;\n s.lastTime = time;\n const bx = w[boneOffset + 4];\n const by = w[boneOffset + 5];\n let z = 0;\n if (s.pending) {\n s.pending = false;\n s.ux = bx;\n s.uy = by;\n } else {\n let a = s.remaining;\n const i = r.inertia;\n const t = r.step;\n const f = r.referenceScale;\n let d = -1;\n const qx = r.limit * delta;\n const qy = qx;\n if (x || y) {\n if (x) {\n const u = (s.ux - bx) * i;\n s.xOffset += u > qx ? qx : u < -qx ? -qx : u;\n s.ux = bx;\n }\n if (y) {\n const u = (s.uy - by) * i;\n s.yOffset += u > qy ? qy : u < -qy ? -qy : u;\n s.uy = by;\n }\n if (a >= t) {\n d = Math.pow(r.damping, 60 * t);\n const m = r.massInverse * t;\n const e = r.strength;\n const wind = r.wind * f;\n const g = r.gravity * f;\n // The environment's directions (issue #1416), as the runtime weighs them; the skeleton's scale is 1 here, so its factor is left out.\n const ax = wind * env[0] + g * env[2];\n const ay = wind * env[1] + g * env[3];\n const xs = s.xOffset;\n const ys = s.yOffset;\n do {\n if (x) {\n s.xVelocity += (ax - s.xOffset * e) * m;\n s.xOffset += s.xVelocity * t;\n s.xVelocity *= d;\n }\n if (y) {\n s.yVelocity -= (ay + s.yOffset * e) * m;\n s.yOffset += s.yVelocity * t;\n s.yVelocity *= d;\n }\n a -= t;\n } while (a >= t);\n s.xLag = s.xOffset - xs;\n s.yLag = s.yOffset - ys;\n }\n z = Math.max(0, 1 - a / t);\n if (x) w[boneOffset + 4] += (s.xOffset - s.xLag * z) * mix * r.x;\n if (y) w[boneOffset + 5] += (s.yOffset - s.yLag * z) * mix * r.y;\n }\n if (rotateOrShearX || scaleX) {\n const ca = Math.atan2(w[boneOffset + 2], w[boneOffset + 0]);\n let c = 0;\n let sn = 0;\n let mr = 0;\n let dx = s.cx - w[boneOffset + 4];\n let dy = s.cy - w[boneOffset + 5];\n if (dx > qx) dx = qx;\n else if (dx < -qx) dx = -qx;\n if (dy > qy) dy = qy;\n else if (dy < -qy) dy = -qy;\n if (rotateOrShearX) {\n mr = (r.rotate + r.shearX) * mix;\n const lagged = s.rotateLag * shown;\n let rr = Math.atan2(dy + s.ty, dx + s.tx) - ca - (s.rotateOffset - lagged) * mr;\n s.rotateOffset += (rr - Math.ceil(rr * INV_PI2 - 0.5) * PI2) * i;\n rr = (s.rotateOffset - lagged) * mr + ca;\n c = Math.cos(rr);\n sn = Math.sin(rr);\n if (scaleX) {\n rr = l * Math.sqrt(w[boneOffset + 0] * w[boneOffset + 0] + w[boneOffset + 2] * w[boneOffset + 2]);\n if (rr > 0) s.scaleOffset += ((dx * c + dy * sn) * i) / rr;\n }\n } else {\n c = Math.cos(ca);\n sn = Math.sin(ca);\n const rr = l * Math.sqrt(w[boneOffset + 0] * w[boneOffset + 0] + w[boneOffset + 2] * w[boneOffset + 2]) - s.scaleLag * shown;\n if (rr > 0) s.scaleOffset += ((dx * c + dy * sn) * i) / rr;\n }\n a = s.remaining;\n if (a >= t) {\n if (d === -1) d = Math.pow(r.damping, 60 * t);\n const m = r.massInverse * t;\n const e = r.strength;\n const ax = r.wind * env[0] + r.gravity * env[2];\n const ay = r.wind * env[1] + r.gravity * env[3];\n const h = l / f;\n const rs = s.rotateOffset;\n const ss = s.scaleOffset;\n for (;;) {\n a -= t;\n if (scaleX) {\n s.scaleVelocity += (ax * c - ay * sn - s.scaleOffset * e) * m;\n s.scaleOffset += s.scaleVelocity * t;\n s.scaleVelocity *= d;\n }\n if (rotateOrShearX) {\n s.rotateVelocity -= ((ax * sn + ay * c) * h + s.rotateOffset * e) * m;\n s.rotateOffset += s.rotateVelocity * t;\n s.rotateVelocity *= d;\n if (a < t) break;\n const rr = s.rotateOffset * mr + ca;\n c = Math.cos(rr);\n sn = Math.sin(rr);\n } else if (a < t) break;\n }\n s.rotateLag = s.rotateOffset - rs;\n s.scaleLag = s.scaleOffset - ss;\n }\n z = Math.max(0, 1 - a / t);\n }\n s.remaining = a;\n }\n s.cx = w[boneOffset + 4];\n s.cy = w[boneOffset + 5];\n if (rotateOrShearX) {\n let angle = (s.rotateOffset - s.rotateLag * z) * mix;\n let sn = 0;\n let c = 0;\n let a = 0;\n if (r.shearX > 0) {\n let rr = 0;\n if (r.rotate > 0) {\n // The rotation's share turns the y column here, and the x column with the shear below.\n rr = angle * r.rotate;\n sn = Math.sin(rr);\n c = Math.cos(rr);\n a = w[boneOffset + 1];\n w[boneOffset + 1] = c * a - sn * w[boneOffset + 3];\n w[boneOffset + 3] = sn * a + c * w[boneOffset + 3];\n }\n rr += angle * r.shearX;\n sn = Math.sin(rr);\n c = Math.cos(rr);\n a = w[boneOffset + 0];\n w[boneOffset + 0] = c * a - sn * w[boneOffset + 2];\n w[boneOffset + 2] = sn * a + c * w[boneOffset + 2];\n } else {\n angle *= r.rotate;\n sn = Math.sin(angle);\n c = Math.cos(angle);\n a = w[boneOffset + 0];\n w[boneOffset + 0] = c * a - sn * w[boneOffset + 2];\n w[boneOffset + 2] = sn * a + c * w[boneOffset + 2];\n a = w[boneOffset + 1];\n w[boneOffset + 1] = c * a - sn * w[boneOffset + 3];\n w[boneOffset + 3] = sn * a + c * w[boneOffset + 3];\n }\n }\n if (scaleX) {\n const k = 1 + (s.scaleOffset - s.scaleLag * z) * mix * r.scaleX;\n w[boneOffset + 0] *= k;\n w[boneOffset + 2] *= k;\n // The transverse column follows the authored mode (issue #1453), after\n // the X column: the native Volume branch bounds reciprocal compression\n // below 0.7; it is not an area-preservation promise on that branch.\n if (r.scaleYMode === 'Uniform') {\n w[boneOffset + 1] *= k;\n w[boneOffset + 3] *= k;\n } else if (r.scaleYMode === 'Volume') {\n const magnitude = Math.abs(k);\n const transverse = magnitude >= 0.7 ? 1 / magnitude : 4 - 3.67347 * magnitude;\n w[boneOffset + 1] *= transverse;\n w[boneOffset + 3] *= transverse;\n }\n }\n s.tx = l * w[boneOffset + 0];\n s.ty = l * w[boneOffset + 2];\n return true;\n}\n","/**\n * The runtime poser's per-instance half (issue #1591, stage 9): one\n * `RuntimePose` per skeleton on screen, every buffer allocated when it is\n * made and overwritten in place on every pose, so that posing a frame\n * allocates nothing.\n *\n * ## What a pose is\n *\n * The oracle's sample, as `src/core/animation.ts` poses it (`poseAnimations`):\n * every pose is posed from the setup pose — the bones' setup local values,\n * then the animation's bone timelines at `t` at full weight, then the world\n * transforms parents first, then the draw order and each slot's light and dark\n * colour, attachment and own deform timelines, then the ik, transform, path,\n * physics and slider constraints in the document's order with their timelines'\n * values at `t`, each followed by the bones below what it moved posed again,\n * then the sliders' draw-order, slot and deform timelines; then, when asked,\n * every shown attachment's world vertices. Nothing of one unstepped pose\n * survives but key cursors. A stepped pose also keeps its physics clock,\n * offsets, velocities and lags; sliders select values within this pose rather\n * than advancing an independent track.\n *\n * ## The arithmetic is the oracle's\n *\n * Every formula below is the one the named function of `src/core/` computes,\n * in its order of operations, on the same doubles: a bone's frame and its\n * five inherit modes (`world.ts`), the timelines (`animation.ts`), the one-\n * and two-bone ik, the world-space transform, the path constraint (`constraints_path.ts`),\n * the read-back of a moved bone's local values and the update order (`constraints.ts`),\n * a region's corners and a mesh's vertices (`vertices.ts`). Each of those orders was fixed\n * there by measurement against spine-core 4.3.13 to the last bit; the runtime\n * does not re-measure them, it is held to the oracle at tolerance 0\n * (`tools/core_gate.ts`, *The runtime poser*), so an order changed here is a\n * difference there.\n *\n * ⚠️ The exactness hazards, each kept as the oracle has it: the setup value\n * plus 0 before a timeline's first key (which turns a `-0` setup into `0`);\n * a keyed ik, transform or path value reaching the pose through the setup blend\n * `setup + (value − setup)·1`; `Math.PI` for a folded uniform two-bone ik and\n * the runtime's 3.1415927 everywhere else; the `(−180, 180]` wrap; a mix of\n * exactly 0 touching nothing; an inactive bone posed as zeros by the\n * hierarchy and never posed again by a constraint, nor the bones below it.\n */\nimport { RuntimeDrawClipper } from './clip_draw.ts';\nimport type { CorePhysicsRecord } from '../core/constraints_physics.ts';\nimport { freshPhysicsState, resetPhysicsState, stepRuntimePhysics, type PhysicsState } from './physics.ts';\nimport { COLLAPSED_X_AXIS_SQ, RUNTIME_DEG, RUNTIME_PI } from '../core/world.ts';\nimport { channelValue, keyAt, deformFraction, CURVE_STEPPED } from './curves.ts';\nimport {\n DRAW_MESH,\n DRAW_NONE,\n DRAW_REGION,\n IK_BEND_POSITIVE,\n IK_COMPRESS,\n IK_STRETCH,\n L_ROTATION,\n L_SCALE_X,\n L_SCALE_Y,\n L_SHEAR_X,\n L_SHEAR_Y,\n L_X,\n L_Y,\n LOCALS,\n MODE_NO_ROTATION_OR_REFLECTION,\n MODE_NO_SCALE,\n MODE_NO_SCALE_OR_REFLECTION,\n MODE_NORMAL,\n MODE_ONLY_TRANSLATION,\n PATH_POSITION_PERCENT,\n PATH_ROTATE_CHAIN,\n PATH_ROTATE_CHAIN_SCALE,\n PATH_ROTATE_TANGENT,\n PATH_SPACING_LENGTH,\n PATH_SPACING_PERCENT,\n PATH_SPACING_PROPORTIONAL,\n RAD,\n RuntimeInputError,\n SCALE_Y_UNIFORM,\n SCALE_Y_VOLUME,\n W_A,\n W_B,\n W_C,\n W_D,\n W_X,\n W_Y,\n WORLDS,\n type RuntimeAnimation,\n type RuntimeConstraint,\n type RuntimeEvent,\n type RuntimeIk,\n type RuntimeModel,\n type RuntimePath,\n type RuntimeTransform,\n type RuntimeSlider,\n type RuntimePhysicsTimeline,\n} from './model.ts';\n\nconst DEG = RUNTIME_DEG;\nconst TWO_PI = 2 * RUNTIME_PI;\nconst PATH_EPSILON = 0.00001;\n// The transform properties, by `TRANSFORM_PROPERTIES` index (src/core/constraints.ts).\nconst P_ROTATE = 0;\nconst P_X = 1;\nconst P_Y = 2;\nconst P_SCALE_X = 3;\nconst P_SCALE_Y = 4;\n// `applyLocal` in src/core/constraints.ts: the six transform properties' local fields.\nconst PROPERTY_LOCAL = new Int32Array([L_ROTATION, L_X, L_Y, L_SCALE_X, L_SCALE_Y, L_SHEAR_Y]);\n\n/** A change brought once into (−180, 180] — −180 goes to 180 (src/core/constraints.ts). */\nfunction wrap180(r: number): number {\n return r > 180 ? r - 360 : r <= -180 ? r + 360 : r;\n}\n\n/** The runtime's `scaleY` for a bone an ik scaled by `s` along its length (src/core/constraints.ts, the `volume` measurement). */\nfunction volumeScaleY(scaleY: number, s: number): number {\n return scaleY / (s < 0.7 ? 0.25 + s * 0.642857 : s);\n}\n\nconst clamp01 = (v: number): number => (v < 0 ? 0 : v > 1 ? 1 : v);\n\n/** A caller-supplied physics clock; animation/track time still uses dt itself. */\nexport interface RuntimePoseOptions { readonly clock?: (dt: number) => number }\nexport type RuntimePhysicsPhase = 'none' | 'reset' | 'update';\n\n/** One skeleton's pose, every value in place. Read `world`, `light`, `dark`, `shown`, `drawOrder` and `vertices` after a pose. */\nexport class RuntimePose {\n readonly model: RuntimeModel;\n /** Every bone's local values, `LOCALS` per bone (`L_*`). */\n readonly locals: Float64Array;\n /** Every bone's world transform, `WORLDS` per bone (`W_*`). */\n readonly world: Float64Array;\n /** Every slot's light colour, four per slot. */\n readonly light: Float64Array;\n /** Every slot's dark colour, three per slot (`r2`, `g2`, `b2`), or zeros when `model.slots[s].dark === null`. */\n readonly dark: Float64Array;\n /** What every slot shows: an index into `model.attachments`, or −1 for nothing. */\n readonly shown: Int32Array;\n /** The slot indices in the live frame's draw order (`0 .. model.slots.length - 1`), updated in place. */\n readonly drawOrder: Int32Array;\n /** Every attachment's world vertices at its `offset`, written by `computeVertices` for the attachments shown. */\n readonly vertices: Float64Array;\n /** Buffered clipping output; null when the compiled model has no clipping attachments. */\n readonly clipping: RuntimeDrawClipper | null;\n /** Held/interpolated deform values, one pair per binding when weighted. */\n readonly deform: Float64Array;\n private readonly deformed: Uint8Array;\n /** The running sum of `step`'s steps, and the animation time the last pose was posed at. */\n trackTime = 0;\n time = 0;\n\n private readonly fired: RuntimeEvent[] = [];\n /** Borrowed immutable event records, in delivery order, until the next apply/step. */\n get events(): readonly RuntimeEvent[] { return this.fired; }\n private eventTime = -1;\n\n private current: RuntimeAnimation | null = null;\n private readonly cursors: Int32Array;\n // The constraints' values as posed: an ik's mix, softness and flags, a transform's six mixes, a path's position, spacing and three mixes.\n private readonly ikMix: Float64Array;\n private readonly ikSoftness: Float64Array;\n private readonly ikFlags: Uint8Array;\n private readonly mixes: Float64Array;\n private readonly pathValues: Float64Array;\n private readonly pathSlotSign: Int8Array;\n private readonly pathSpaces: Float64Array;\n private readonly pathLengths: Float64Array;\n private readonly pathPositions: Float64Array;\n private readonly pathWorldPts: Float64Array;\n private readonly pathChain: Float64Array;\n private readonly pathCurveEnds: Float64Array;\n private readonly pathSegmentEnds = new Float64Array(10);\n // The update order's scratch: the bones a constraint changed and moved in world space, in order (repeats kept, as the oracle keeps them), and per-bone marks.\n private readonly changed: Int32Array;\n private readonly inWorld: Int32Array;\n private readonly changedMark: Uint8Array;\n private readonly inWorldMark: Uint8Array;\n private readonly below: Uint8Array;\n private readonly visit: Uint8Array;\n private readonly w = new Float64Array(WORLDS);\n\n /** Sum of caller-supplied physics deltas, independent of animation time. */\n physicsTime = 0;\n private physicsLast = -1;\n private physicsPhase: RuntimePhysicsPhase = 'none';\n private physicsReady = false;\n private readonly hasPhysics: boolean;\n private readonly physicsStates: PhysicsState[];\n private readonly physicsRecords: Array<CorePhysicsRecord | null>;\n private readonly physicsScope: Uint8Array;\n private readonly environment = new Float64Array([1, 0, 0, 1]);\n private readonly sliderTime: Float64Array;\n private readonly sliderMix: Float64Array;\n private readonly sliderAt: Float64Array;\n private readonly clock: ((dt: number) => number) | undefined;\n\n constructor(model: RuntimeModel, options: RuntimePoseOptions = {}) {\n this.model = model;\n this.clipping = model.attachments.some(at => at.clip !== undefined) ? new RuntimeDrawClipper(model) : null;\n this.clock = options.clock;\n this.hasPhysics = model.constraints.some(c => c.kind === 'physics');\n this.physicsStates = model.constraints.map(() => freshPhysicsState());\n this.physicsRecords = model.constraints.map(c => c.kind === 'physics' ? { ...c.setup } : null);\n this.sliderTime = new Float64Array(model.constraints.length);\n this.sliderMix = new Float64Array(model.constraints.length);\n this.sliderAt = new Float64Array(model.constraints.length);\n const nb = model.boneNames.length;\n const ns = model.slots.length;\n const nc = model.constraints.length;\n this.physicsScope = new Uint8Array(nc);\n this.locals = new Float64Array(nb * LOCALS);\n this.world = new Float64Array(nb * WORLDS);\n this.light = new Float64Array(ns * 4);\n this.dark = new Float64Array(ns * 3);\n this.shown = new Int32Array(ns);\n this.drawOrder = new Int32Array(ns);\n for (let s = 0; s < ns; s++) this.drawOrder[s] = s;\n this.vertices = new Float64Array(model.vertexCount);\n this.deform = new Float64Array(model.deformCount);\n this.deformed = new Uint8Array(model.attachments.length);\n this.cursors = new Int32Array(Math.max(1, model.cursors)).fill(-1);\n this.ikMix = new Float64Array(nc);\n this.ikSoftness = new Float64Array(nc);\n this.ikFlags = new Uint8Array(nc);\n this.mixes = new Float64Array(nc * 6);\n this.pathValues = new Float64Array(nc * 5);\n this.pathSlotSign = new Int8Array(nc);\n const ms = model.maxPathSpaces;\n const mv = model.maxPathVertices;\n this.pathSpaces = new Float64Array(ms);\n this.pathLengths = new Float64Array(ms);\n this.pathPositions = new Float64Array(ms > 0 ? ms * 3 + 2 : 0);\n this.pathWorldPts = new Float64Array(mv);\n this.pathChain = new Float64Array(mv > 0 ? mv + 4 : 0);\n this.pathCurveEnds = new Float64Array(mv > 0 ? Math.ceil(mv / 6) + 1 : 0);\n // Sized by the longest target list (`RuntimeModel.scratch`): a transform may name one bone several times, and every entry is applied and reposed.\n this.changed = new Int32Array(model.scratch);\n this.inWorld = new Int32Array(model.scratch);\n this.changedMark = new Uint8Array(nb);\n this.inWorldMark = new Uint8Array(nb);\n this.below = new Uint8Array(nb);\n this.visit = new Uint8Array(nb);\n }\n\n /** The animation this pose plays (a covered one: `model.animation` throws a `RuntimeRefusal` for a refused one), from track time 0. */\n setAnimation(name: string): void {\n this.current = this.model.animation(name);\n this.physicsTime = 0;\n this.physicsLast = -1;\n this.physicsReady = false;\n for (let k = 0; k < this.physicsStates.length; k++) resetPhysicsState(this.physicsStates[k], 0);\n this.cursors.fill(-1);\n this.trackTime = 0;\n this.time = 0;\n this.eventTime = -1;\n this.fired.length = 0;\n }\n\n /**\n * Restore one animation's two clocks without delivering keys already passed.\n * A skin/view replacement uses the old pose's trackTime and wrapped time.\n * Unlike setAnimation + apply, restoration never replays the initial interval.\n */\n restore(name: string, trackTime: number, animationTime: number): void {\n if (!Number.isFinite(trackTime)) throw new RuntimeInputError(`restore: track time ${trackTime} is not finite`);\n if (!Number.isFinite(animationTime)) throw new RuntimeInputError(`restore: animation time ${animationTime} is not finite`);\n this.setAnimation(name);\n this.trackTime = trackTime;\n if (!this.model.restoreEventsFromStart) this.eventTime = animationTime;\n this.apply(animationTime);\n }\n\n /** The setup pose: every constraint applied with its own values, every slot as it is set up. */\n setupPose(physics: RuntimePhysicsPhase = 'none'): void {\n this.physicsPhase = physics;\n this.current = null;\n this.time = 0;\n this.eventTime = -1;\n this.fired.length = 0;\n this.physicsValues(null, 0, false);\n this.locals.set(this.model.setup);\n this.hierarchy();\n this.slotValues(null, 0);\n this.deformValues(null, 0);\n this.constraintValues(null, 0);\n this.solveConstraints();\n this.sliderAttachments();\n }\n\n /** The animation posed at its time `t`, from the setup pose (the header). */\n apply(t: number, physics: RuntimePhysicsPhase = 'none', delta = 0): void {\n const anim = this.current;\n if (anim === null) throw new RuntimeInputError('apply: no animation is set (setAnimation first)');\n if (!Number.isFinite(t)) throw new RuntimeInputError(`apply: the time ${t} is not finite`);\n if (!Number.isFinite(delta) || delta < 0) throw new RuntimeInputError(`apply: physics delta ${delta} is not finite and at or above 0`);\n this.physicsPhase = physics;\n // Reset keys see the old clock. The skeleton moves by delta only after application.\n this.physicsValues(anim, t, physics !== 'none');\n if (physics !== 'none') {\n this.physicsTime += delta;\n this.physicsReady = true;\n }\n this.collectEvents(anim, t);\n this.time = t;\n this.boneTimelines(anim, t);\n this.hierarchy();\n this.slotValues(anim, t);\n this.deformValues(anim, t);\n this.constraintValues(anim, t);\n this.solveConstraints();\n this.sliderAttachments();\n }\n\n /** One step of a looping track: the track time moved by `dt`, the animation posed at it wrapped by the duration (`loopedTime` in src/core/raw.ts). */\n step(dt: number): void {\n const anim = this.current;\n if (anim === null) throw new RuntimeInputError('step: no animation is set (setAnimation first)');\n if (!Number.isFinite(dt) || dt < 0) throw new RuntimeInputError(`step: delta ${dt} is not finite and at or above 0`);\n if (!this.physicsReady && this.hasPhysics) {\n // Initial physics setup must not consume the event interval of this step.\n const lastEventTime = this.eventTime;\n this.apply(this.time, 'reset', 0);\n this.eventTime = lastEventTime;\n }\n const moved = this.clock === undefined ? dt : this.clock(dt);\n if (!Number.isFinite(moved) || moved < 0) throw new RuntimeInputError(`step: physics clock moved by ${moved}, not finite and at or above 0`);\n this.trackTime += dt;\n this.apply(anim.duration === 0 ? 0 : this.trackTime % anim.duration, 'update', moved);\n }\n\n /** The oracle interval (last,t], tail then head on a wrap; never copies a payload. */\n private collectEvents(anim: RuntimeAnimation, t: number): void {\n const last = this.eventTime;\n const wrapped = t < last;\n const keys = anim.eventKeys;\n let count = 0;\n if (wrapped) for (let i = 0; i < keys.length; i++) if (keys[i].time > last) this.fired[count++] = keys[i];\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (key.time <= t && (wrapped ? !this.model.eventWrapOffByOne || key.time > 0 : key.time > last)) this.fired[count++] = key;\n }\n this.fired.length = count;\n this.eventTime = t;\n }\n\n // ---------------------------------------------------------------------------\n // the bones\n // ---------------------------------------------------------------------------\n\n /** The setup locals with the bone timelines' values at `t` (`posedBones`): added, or multiplied for a scale; a channel before its timeline's first key at setup plus 0, or times 1. */\n private boneTimelines(anim: RuntimeAnimation, t: number): void {\n const L = this.locals;\n const S = this.model.setup;\n L.set(S);\n const timelines = anim.bones;\n for (let k = 0; k < timelines.length; k++) {\n const tl = timelines[k];\n const i = keyAt(tl.curve, this.cursors, tl.cursor, t);\n const o = tl.bone * LOCALS;\n const fields = tl.fields;\n for (let c = 0; c < fields.length; c++) {\n const at = o + fields[c];\n if (tl.multiply[c] === 1) L[at] = S[at] * (i < 0 ? 1 : channelValue(tl.curve, i, c, t));\n else L[at] = S[at] + (i < 0 ? 0 : channelValue(tl.curve, i, c, t));\n }\n }\n }\n\n /** Every bone's world transform from its locals, parents first (`worldTransforms`): an inactive bone as zeros. */\n private hierarchy(): void {\n const nb = this.model.boneNames.length;\n for (let i = 0; i < nb; i++) this.poseBone(i, true);\n }\n\n /**\n * One bone's world transform from its locals under its parent's current\n * world (`worldTransforms` and the update order's `poseBone`). An inactive\n * bone is zeroed by the hierarchy (`fresh`) and left as it is by a repose.\n */\n private poseBone(i: number, fresh: boolean): void {\n const m = this.model;\n const W = this.world;\n const o = i * WORLDS;\n if (m.active[i] === 0) {\n if (fresh) {\n W[o + W_A] = 0;\n W[o + W_B] = 0;\n W[o + W_C] = 0;\n W[o + W_D] = 0;\n W[o + W_X] = 0;\n W[o + W_Y] = 0;\n }\n return;\n }\n const L = this.locals;\n const l = i * LOCALS;\n const x = L[l + L_X];\n const y = L[l + L_Y];\n const rotation = L[l + L_ROTATION];\n const scaleX = L[l + L_SCALE_X];\n const scaleY = L[l + L_SCALE_Y];\n const shearX = L[l + L_SHEAR_X];\n const shearY = L[l + L_SHEAR_Y];\n const parent = m.parents[i];\n if (parent < 0) {\n // A root is its own frame at its own x, y.\n const xAngle = (rotation + shearX) * RAD;\n const yAngle = (rotation + 90 + shearY) * RAD;\n W[o + W_A] = Math.cos(xAngle) * scaleX;\n W[o + W_B] = Math.cos(yAngle) * scaleY;\n W[o + W_C] = Math.sin(xAngle) * scaleX;\n W[o + W_D] = Math.sin(yAngle) * scaleY;\n W[o + W_X] = x;\n W[o + W_Y] = y;\n return;\n }\n const q = parent * WORLDS;\n const pa = W[q + W_A];\n const pb = W[q + W_B];\n const pc = W[q + W_C];\n const pd = W[q + W_D];\n const px = W[q + W_X];\n const py = W[q + W_Y];\n switch (m.modes[i]) {\n case MODE_NORMAL: {\n const xAngle = (rotation + shearX) * RAD;\n const yAngle = (rotation + 90 + shearY) * RAD;\n const la = Math.cos(xAngle) * scaleX;\n const lb = Math.cos(yAngle) * scaleY;\n const lc = Math.sin(xAngle) * scaleX;\n const ld = Math.sin(yAngle) * scaleY;\n W[o + W_A] = pa * la + pb * lc;\n W[o + W_B] = pa * lb + pb * ld;\n W[o + W_C] = pc * la + pd * lc;\n W[o + W_D] = pc * lb + pd * ld;\n break;\n }\n case MODE_ONLY_TRANSLATION: {\n const xAngle = (rotation + shearX) * RAD;\n const yAngle = (rotation + 90 + shearY) * RAD;\n W[o + W_A] = Math.cos(xAngle) * scaleX;\n W[o + W_B] = Math.cos(yAngle) * scaleY;\n W[o + W_C] = Math.sin(xAngle) * scaleX;\n W[o + W_D] = Math.sin(yAngle) * scaleY;\n break;\n }\n case MODE_NO_ROTATION_OR_REFLECTION: {\n const xLengthSq = pa * pa + pc * pc;\n let c0: number;\n let c1: number;\n let c2: number;\n let c3: number;\n let r: number;\n if (xLengthSq > COLLAPSED_X_AXIS_SQ) {\n const k = Math.abs(pa * pd - pb * pc) / xLengthSq;\n c0 = pa;\n c1 = -pc * k;\n c2 = pc;\n c3 = pa * k;\n r = rotation - Math.atan2(pc, pa) * DEG;\n } else {\n c0 = 0;\n c1 = -pb;\n c2 = 0;\n c3 = pd;\n r = rotation - 90 + Math.atan2(pd, pb) * DEG;\n }\n const xAngle = (r + shearX) * RAD;\n const yAngle = (r + shearY + 90) * RAD;\n const la = Math.cos(xAngle) * scaleX;\n const lb = Math.cos(yAngle) * scaleY;\n const lc = Math.sin(xAngle) * scaleX;\n const ld = Math.sin(yAngle) * scaleY;\n W[o + W_A] = c0 * la + c1 * lc;\n W[o + W_B] = c0 * lb + c1 * ld;\n W[o + W_C] = c2 * la + c3 * lc;\n W[o + W_D] = c2 * lb + c3 * ld;\n break;\n }\n default: {\n // noScale and noScaleOrReflection (`noScaleDirection`, then the frame at rotation 0).\n const rr = rotation * RAD;\n const cos = Math.cos(rr);\n const sin = Math.sin(rr);\n const ux0 = pa * cos + pb * sin;\n const uy0 = pc * cos + pd * sin;\n const inverse = 1 / Math.sqrt(ux0 * ux0 + uy0 * uy0);\n const ux = ux0 * inverse;\n const uy = uy0 * inverse;\n const flip = m.modes[i] === MODE_NO_SCALE && pa * pd - pb * pc < 0 ? -1 : 1;\n const t0 = ux;\n const t1 = -uy * flip;\n const t2 = uy;\n const t3 = ux * flip;\n const xAngle = (0 + shearX) * RAD;\n const yAngle = (0 + 90 + shearY) * RAD;\n const la = Math.cos(xAngle) * scaleX;\n const lb = Math.cos(yAngle) * scaleY;\n const lc = Math.sin(xAngle) * scaleX;\n const ld = Math.sin(yAngle) * scaleY;\n W[o + W_A] = t0 * la + t1 * lc;\n W[o + W_B] = t0 * lb + t1 * ld;\n W[o + W_C] = t2 * la + t3 * lc;\n W[o + W_D] = t2 * lb + t3 * ld;\n }\n }\n W[o + W_X] = pa * x + pb * y + px;\n W[o + W_Y] = pc * x + pd * y + py;\n }\n\n // ---------------------------------------------------------------------------\n // the constraints\n // ---------------------------------------------------------------------------\n\n /** Each constraint's values at `t` (`posedRecords`): its own before its timeline's first key, else the keyed values through the setup blend and the key's flags. */\n private constraintValues(anim: RuntimeAnimation | null, t: number): void {\n const cs = this.model.constraints;\n for (let k = 0; k < cs.length; k++) {\n const c = cs[k];\n const tl = anim === null ? null : anim.constraints[k];\n const i = tl === null ? -1 : keyAt(tl.curve, this.cursors, tl.cursor, t);\n if (c.kind === 'ik') {\n if (tl === null || i < 0) {\n this.ikMix[k] = c.mix;\n this.ikSoftness[k] = c.softness;\n this.ikFlags[k] = c.flags;\n } else {\n this.ikMix[k] = c.mix + (channelValue(tl.curve, i, 0, t) - c.mix) * 1;\n this.ikSoftness[k] = c.softness + (channelValue(tl.curve, i, 1, t) - c.softness) * 1;\n this.ikFlags[k] = (tl.flags as Uint8Array)[i];\n }\n } else if (c.kind === 'transform') {\n const o = k * 6;\n for (let p = 0; p < 6; p++) this.mixes[o + p] = tl === null || i < 0 ? c.mixes[p] : c.mixes[p] + (channelValue(tl.curve, i, p, t) - c.mixes[p]) * 1;\n } else if (c.kind === 'slider') {\n const keyed = anim === null ? null : anim.sliders[k];\n let time = c.setup.time, mix = c.setup.mix;\n if (keyed !== null) {\n if (keyed.time !== null) {\n const q = keyAt(keyed.time, this.cursors, keyed.timeCursor, t);\n if (q >= 0) time += (channelValue(keyed.time, q, 0, t) - time) * 1;\n }\n if (keyed.mix !== null) {\n const q = keyAt(keyed.mix, this.cursors, keyed.mixCursor, t);\n if (q >= 0) mix += (channelValue(keyed.mix, q, 0, t) - mix) * 1;\n }\n }\n this.sliderTime[k] = time;\n this.sliderMix[k] = mix;\n } else if (c.kind === 'path') {\n const keyed = anim === null ? null : anim.paths[k];\n let position = c.position;\n let spacing = c.spacing;\n let mixRotate = c.mixRotate;\n let mixX = c.mixX;\n let mixY = c.mixY;\n if (keyed !== null) {\n if (keyed.position !== null) {\n const q = keyAt(keyed.position, this.cursors, keyed.positionCursor, t);\n if (q >= 0) position = c.position + (channelValue(keyed.position, q, 0, t) - c.position) * 1;\n }\n if (keyed.spacing !== null) {\n const q = keyAt(keyed.spacing, this.cursors, keyed.spacingCursor, t);\n if (q >= 0) spacing = c.spacing + (channelValue(keyed.spacing, q, 0, t) - c.spacing) * 1;\n }\n if (keyed.mix !== null) {\n const q = keyAt(keyed.mix, this.cursors, keyed.mixCursor, t);\n if (q >= 0) {\n mixRotate = c.mixRotate + (channelValue(keyed.mix, q, 0, t) - c.mixRotate) * 1;\n mixX = c.mixX + (channelValue(keyed.mix, q, 1, t) - c.mixX) * 1;\n mixY = c.mixY + (channelValue(keyed.mix, q, 2, t) - c.mixY) * 1;\n }\n }\n }\n const o = k * 5;\n this.pathValues[o] = position;\n this.pathValues[o + 1] = spacing;\n this.pathValues[o + 2] = mixRotate;\n this.pathValues[o + 3] = mixX;\n this.pathValues[o + 4] = mixY;\n }\n }\n }\n\n /** Every applied constraint in the document's order, each followed by the update order's repose (`applyConstraints`). */\n private solveConstraints(): void {\n const cs = this.model.constraints;\n const hasPath = this.model.hasPath;\n for (let k = 0; k < cs.length; k++) {\n if (hasPath) this.snapSlotBones(k, false);\n const c = cs[k];\n if (!c.applied) continue;\n if (c.kind === 'ik') this.solveIk(c, k);\n else if (c.kind === 'transform') this.solveTransform(c, k);\n else if (c.kind === 'slider') this.solveSlider(c, k);\n else if (c.kind === 'path') this.solvePath(c, k);\n else if (this.physicsPhase !== 'none' && !this.model.omitPhysics) {\n const b = c.bones[0];\n if (stepRuntimePhysics(this.physicsRecords[k]!, this.physicsStates[k], this.world, b * WORLDS, this.model.lengths[b], this.physicsTime, this.physicsPhase === 'reset', this.environment)) {\n this.changed[0] = this.inWorld[0] = b;\n this.repose(1, 1);\n }\n }\n if (hasPath) this.snapSlotBones(k, true);\n }\n }\n\n private snapSlotBones(at: number, after: boolean): void {\n const cs = this.model.constraints;\n const W = this.world;\n for (let k = 0; k < cs.length; k++) {\n const c = cs[k];\n if (c.kind !== 'path' || c.slotEventAt !== at || c.slotEventAfter !== after || (k === at && !after)) continue;\n const sb = c.slotBone * WORLDS;\n this.pathSlotSign[k] = W[sb + W_A] * W[sb + W_D] - W[sb + W_B] * W[sb + W_C] > 0 ? 1 : -1;\n }\n }\n\n /** Reset where the consumer starts: the setup pose or animation pose zero. */\n resetPhysics(at: 'setup' | 'animation' = 'animation'): void {\n this.physicsTime = 0;\n this.physicsLast = -1;\n for (let k = 0; k < this.physicsStates.length; k++) resetPhysicsState(this.physicsStates[k], 0);\n if (at === 'animation') this.apply(0, 'reset', 0);\n else {\n const current = this.current;\n this.setupPose('reset');\n this.current = current;\n }\n this.physicsReady = true;\n }\n\n private checkPhysicsScope(scope: readonly string[] | undefined): Uint8Array | null {\n if (scope === undefined) return null;\n if (!Array.isArray(scope)) throw new RuntimeInputError(`physics movement scope is ${String(scope)}, not an array of physics constraint names`);\n const selected = this.physicsScope;\n selected.fill(0);\n const cs = this.model.constraints;\n for (let i = 0; i < scope.length; i++) {\n const name = scope[i];\n if (typeof name !== 'string') throw new RuntimeInputError(`physics movement scope name ${String(name)} is not a string`);\n let found: RuntimeConstraint | undefined;\n for (let k = 0; k < cs.length; k++) {\n if (cs[k].kind === 'physics' && cs[k].name === name) {\n found = cs[k];\n break;\n }\n }\n if (found === undefined) {\n for (let k = 0; k < cs.length; k++) {\n if (cs[k].name === name) {\n found = cs[k];\n break;\n }\n }\n }\n if (found === undefined) throw new RuntimeInputError(`physics movement scope: no constraint \"${name}\"; this document declares [${cs.map((c) => c.name).join(', ')}]`);\n if (found.kind !== 'physics') throw new RuntimeInputError(`physics movement scope: constraint \"${name}\" is ${found.kind}, not physics`);\n selected[found.index] = 1;\n }\n return this.model.ignorePhysicsScope ? null : selected;\n }\n\n /** External motion changes the previous origin, never the authored locals. */\n physicsTranslate(x: number, y: number, scope?: readonly string[]): void {\n const selected = this.checkPhysicsScope(scope);\n if (!Number.isFinite(x) || !Number.isFinite(y)) throw new RuntimeInputError('physicsTranslate: x and y must be finite');\n for (let k = 0; k < this.physicsStates.length; k++) {\n if (selected !== null && selected[k] === 0) continue;\n const s = this.physicsStates[k];\n s.ux -= x; s.uy -= y; s.cx -= x; s.cy -= y;\n }\n }\n\n physicsRotate(x: number, y: number, degrees: number, scope?: readonly string[]): void {\n const selected = this.checkPhysicsScope(scope);\n if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(degrees)) throw new RuntimeInputError('physicsRotate: x, y and degrees must be finite');\n const r = degrees * RAD, cos = Math.cos(r), sin = Math.sin(r);\n for (let k = 0; k < this.physicsStates.length; k++) {\n if (selected !== null && selected[k] === 0) continue;\n const s = this.physicsStates[k];\n const dx = s.cx - x, dy = s.cy - y;\n const tx = dx * cos - dy * sin - dx, ty = dx * sin + dy * cos - dy;\n s.ux -= tx; s.uy -= ty; s.cx -= tx; s.cy -= ty;\n }\n }\n\n setEnvironment(env: { readonly wind: readonly [number, number]; readonly gravity: readonly [number, number] }): void {\n if (!Number.isFinite(env.wind[0]) || !Number.isFinite(env.wind[1]) || !Number.isFinite(env.gravity[0]) || !Number.isFinite(env.gravity[1])) throw new RuntimeInputError('setEnvironment: wind and gravity must be finite');\n this.environment[0] = env.wind[0]; this.environment[1] = env.wind[1];\n this.environment[2] = env.gravity[0]; this.environment[3] = env.gravity[1];\n }\n\n /** The per-pass values start at setup, before any slider writes. */\n private physicsValues(anim: RuntimeAnimation | null, t: number, resets: boolean): void {\n const cs = this.model.constraints;\n for (let k = 0; k < cs.length; k++) {\n const c = cs[k];\n if (c.kind !== 'physics') continue;\n const r = this.physicsRecords[k]!;\n r.inertia = c.setup.inertia; r.strength = c.setup.strength; r.damping = c.setup.damping;\n r.massInverse = c.setup.massInverse; r.wind = c.setup.wind; r.gravity = c.setup.gravity; r.mix = c.setup.mix;\n }\n if (anim !== null) this.physicsTimelines(anim.physics, t, 1, false, true, resets);\n if (resets) this.physicsLast = t;\n }\n\n private physicsTimelines(timelines: readonly RuntimePhysicsTimeline[], t: number, alpha: number, additive: boolean, setup: boolean, resets = false): void {\n for (let q = 0; q < timelines.length; q++) {\n const tl = timelines[q];\n if (tl.kind === 'reset') {\n if (!resets) continue; // a slider applies at one value; no key is crossed\n let crossed = false;\n const last = this.physicsLast;\n for (let i = 0; i < tl.curve.keys; i++) {\n const time = tl.curve.times[i];\n if (t < last ? time > last || time <= t : time > last && time <= t) crossed = true;\n }\n if (crossed) for (let j = 0; j < tl.targets.length; j++) resetPhysicsState(this.physicsStates[tl.targets[j]], this.physicsTime);\n continue;\n }\n const i = keyAt(tl.curve, this.cursors, tl.cursor, t);\n if (i < 0) {\n // A track's before-first key restores setup even if an earlier global\n // timeline wrote this parameter. A slider's before-first key writes nothing.\n if (setup) for (let j = 0; j < tl.targets.length; j++) {\n const k = tl.targets[j], r = this.physicsRecords[k]!;\n const original = (this.model.constraints[k] as { setup: CorePhysicsRecord }).setup;\n if (tl.kind === 'mass') r.massInverse = original.massInverse;\n else r[tl.kind] = original[tl.kind];\n }\n continue;\n }\n const v = channelValue(tl.curve, i, 0, t);\n for (let j = 0; j < tl.targets.length; j++) {\n const k = tl.targets[j], r = this.physicsRecords[k]!;\n const from = setup ? (this.model.constraints[k] as { setup: CorePhysicsRecord }).setup : r;\n if (tl.kind === 'mass') {\n const mass = 1 / from.massInverse;\n r.massInverse = 1 / (mass + (v - mass) * alpha);\n } else {\n r[tl.kind] = additive && (tl.kind === 'wind' || tl.kind === 'gravity') ? r[tl.kind] + v * alpha : from[tl.kind] + (v - from[tl.kind]) * alpha;\n }\n }\n }\n }\n\n /** Read the dial where previous constraints left it; this value is never track time. */\n private solveSlider(c: RuntimeSlider, k: number): void {\n const alpha = this.sliderMix[k];\n if (alpha === 0) return;\n let time = this.sliderTime[k];\n const r = c.setup, a = c.animation;\n if (c.bone >= 0) {\n const b = c.bone, w = b * WORLDS, l = b * LOCALS;\n let value: number;\n if (r.local) {\n const field = c.property === 0 ? L_ROTATION : c.property === 1 ? L_X : c.property === 2 ? L_Y : c.property === 3 ? L_SCALE_X : c.property === 4 ? L_SCALE_Y : L_SHEAR_Y;\n value = this.locals[l + field] + 0;\n } else {\n const W = this.world, x = W[w], y = W[w + 2], bx = W[w + 1], by = W[w + 3];\n switch (c.property) {\n case 0: value = Math.atan2(y, x) * DEG + (x * by - bx * y > 0 ? 0 : -0); if (value < 0) value += 360; break;\n case 1: value = x * 0 + bx * 0 + W[w + W_X]; break;\n case 2: value = y * 0 + by * 0 + W[w + W_Y]; break;\n case 3: value = Math.sqrt(x * x + y * y) + 0; break;\n case 4: value = Math.sqrt(bx * bx + by * by) + 0; break;\n default: value = (Math.atan2(by, bx) - Math.atan2(y, x)) * DEG - 90 + 0;\n }\n }\n time = r.to + (value - r.from) * r.scale;\n time = r.loop ? a.duration === 0 ? 0 : a.duration + time % a.duration : Math.max(0, time);\n }\n const at = this.model.sliderAsTrack ? this.time : r.loop && a.duration !== 0 ? time % a.duration : time;\n this.sliderAt[k] = at;\n if (this.physicsPhase !== 'none') this.physicsTimelines(a.physics, at, alpha, r.additive, false);\n const L = this.locals, S = this.model.setup;\n for (let q = 0; q < a.sliderBones.length; q++) {\n const tl = a.sliderBones[q], i = keyAt(tl.curve, this.cursors, tl.cursor, at);\n if (i < 0) continue;\n const o = tl.bone * LOCALS;\n for (let f = 0; f < tl.fields.length; f++) {\n const n = o + tl.fields[f], v = channelValue(tl.curve, i, f, at), current = L[n], setup = S[n];\n if (tl.multiply[f]) {\n if (r.additive) L[n] = current + (v * setup - setup) * alpha;\n else {\n const target = setup * v, from = Math.abs(current) * Math.sign(target);\n L[n] = alpha === 1 ? target : from + (target - from) * alpha;\n }\n } else L[n] = r.additive ? current + v * alpha : current + (setup + v - current) * alpha;\n }\n }\n for (let q = 0; q < c.bones.length; q++) this.changed[q] = c.bones[q];\n if (c.bones.length > 0) this.repose(c.bones.length, 0);\n }\n\n /** A path constraint (`solvePath` in `src/core/constraints_path.ts`), every buffer overwritten in place. */\n private solvePath(c: RuntimePath, k: number): void {\n if (c.attachment < 0 || this.model.omitPath) return;\n const o5 = k * 5;\n const position = this.pathValues[o5];\n const spacing = this.pathValues[o5 + 1];\n const mixRotate = this.pathValues[o5 + 2];\n const mixX = this.pathValues[o5 + 3];\n const mixY = this.pathValues[o5 + 4];\n if (mixRotate === 0 && mixX === 0 && mixY === 0) return;\n const wantsTangent = c.rotateMode === PATH_ROTATE_TANGENT;\n const scale = c.rotateMode === PATH_ROTATE_CHAIN_SCALE;\n const bones = c.bones;\n const boneCount = bones.length;\n const spaceCount = wantsTangent ? boneCount : boneCount + 1;\n const spaces = this.pathSpaces;\n const lengths = this.pathLengths;\n const W = this.world;\n const modelLengths = this.model.lengths;\n spaces[0] = 0;\n if (c.spacingMode === PATH_SPACING_PERCENT) {\n if (scale) {\n for (let i = 0; i < spaceCount - 1; i++) {\n const bi = bones[i];\n const boneLength = modelLengths[bi];\n const w = bi * WORLDS;\n const x = boneLength * W[w + W_A];\n const y = boneLength * W[w + W_C];\n lengths[i] = Math.sqrt(x * x + y * y);\n }\n }\n for (let i = 1; i < spaceCount; i++) spaces[i] = spacing;\n } else if (c.spacingMode === PATH_SPACING_PROPORTIONAL) {\n let sum = 0;\n for (let i = 0, n = spaceCount - 1; i < n; ) {\n const bi = bones[i];\n const boneLength = modelLengths[bi];\n if (boneLength < PATH_EPSILON) {\n if (scale) lengths[i] = 0;\n spaces[++i] = spacing;\n } else {\n const w = bi * WORLDS;\n const x = boneLength * W[w + W_A];\n const y = boneLength * W[w + W_C];\n const length = Math.sqrt(x * x + y * y);\n if (scale) lengths[i] = length;\n spaces[++i] = length;\n sum += length;\n }\n }\n if (sum > 0) {\n sum = (spaceCount / sum) * spacing;\n for (let i = 1; i < spaceCount; i++) spaces[i] *= sum;\n }\n } else {\n const addsLength = c.spacingMode === PATH_SPACING_LENGTH;\n for (let i = 0, n = spaceCount - 1; i < n; ) {\n const bi = bones[i];\n const boneLength = modelLengths[bi];\n if (boneLength < PATH_EPSILON) {\n if (scale) lengths[i] = 0;\n spaces[++i] = spacing;\n } else {\n const w = bi * WORLDS;\n const x = boneLength * W[w + W_A];\n const y = boneLength * W[w + W_C];\n const length = Math.sqrt(x * x + y * y);\n if (scale) lengths[i] = length;\n spaces[++i] = ((addsLength ? Math.max(0, boneLength + spacing) : spacing) * length) / boneLength;\n }\n }\n }\n this.positionsOfPath(c, position, spaceCount, wantsTangent);\n const positions = this.pathPositions;\n let atX = positions[0];\n let atY = positions[1];\n let offsetRotation = c.offsetRotation;\n let fromTip: boolean;\n if (offsetRotation === 0) fromTip = c.rotateMode === PATH_ROTATE_CHAIN;\n else {\n fromTip = false;\n let positive: boolean;\n if (c.slotEventAt === k && !c.slotEventAfter) {\n const sb = c.slotBone * WORLDS;\n positive = W[sb + W_A] * W[sb + W_D] - W[sb + W_B] * W[sb + W_C] > 0;\n } else {\n positive = c.slotEventAt >= 0 && this.pathSlotSign[k] > 0;\n }\n offsetRotation *= positive ? RAD : -RAD;\n }\n for (let i = 0, p = 3; i < boneCount; i++, p += 3) {\n const bi = bones[i];\n const o = bi * WORLDS;\n let wa = W[o + W_A];\n let wb = W[o + W_B];\n let wc = W[o + W_C];\n let wd = W[o + W_D];\n const wx = W[o + W_X] + (atX - W[o + W_X]) * mixX;\n const wy = W[o + W_Y] + (atY - W[o + W_Y]) * mixY;\n const x = positions[p];\n const y = positions[p + 1];\n const dx = x - atX;\n const dy = y - atY;\n if (scale) {\n const length = lengths[i];\n if (length >= PATH_EPSILON) {\n const s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * mixRotate + 1;\n wa *= s;\n wc *= s;\n }\n }\n atX = x;\n atY = y;\n if (mixRotate > 0) {\n const a = wa;\n const bb = wb;\n const cc = wc;\n const d = wd;\n let r: number;\n if (wantsTangent) r = positions[p - 1];\n else if (spaces[i + 1] === 0) r = positions[p + 2];\n else r = Math.atan2(dy, dx);\n r -= Math.atan2(cc, a);\n if (fromTip) {\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n const length = modelLengths[bi];\n atX += (length * (cos * a - sin * cc) - dx) * mixRotate;\n atY += (length * (sin * a + cos * cc) - dy) * mixRotate;\n } else r += offsetRotation;\n if (r > RUNTIME_PI) r -= TWO_PI;\n else if (r < -RUNTIME_PI) r += TWO_PI;\n r *= mixRotate;\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n wa = cos * a - sin * cc;\n wb = cos * bb - sin * d;\n wc = sin * a + cos * cc;\n wd = sin * bb + cos * d;\n }\n W[o + W_A] = wa;\n W[o + W_B] = wb;\n W[o + W_C] = wc;\n W[o + W_D] = wd;\n W[o + W_X] = wx;\n W[o + W_Y] = wy;\n this.changed[i] = bi;\n this.inWorld[i] = bi;\n }\n if (boneCount > 0) this.repose(boneCount, boneCount);\n }\n\n private computePathWorld(c: RuntimePath): void {\n const at = this.model.attachments[c.attachment];\n const W = this.world;\n const pts = this.pathWorldPts;\n const deformed = this.deformed[c.attachment] !== 0;\n if (at.bindingCounts.length === 0) {\n const b = c.slotBone * WORLDS;\n const a = W[b + W_A];\n const bb = W[b + W_B];\n const cc = W[b + W_C];\n const d = W[b + W_D];\n const wx = W[b + W_X];\n const wy = W[b + W_Y];\n const local = deformed ? this.deform : at.local;\n const lo = deformed ? at.deformOffset : 0;\n for (let q = 0; q < c.pathVertices; q += 2) {\n const x = local[lo + q];\n const y = local[lo + q + 1];\n pts[q] = x * a + y * bb + wx;\n pts[q + 1] = x * cc + y * d + wy;\n }\n return;\n }\n const counts = at.bindingCounts;\n const bones = at.bindingBones;\n const xs = at.bindingX;\n const ys = at.bindingY;\n const weights = at.bindingWeights;\n let n = 0;\n let o = 0;\n for (let v = 0; v < counts.length; v++) {\n let wx = 0;\n let wy = 0;\n const end = n + counts[v];\n for (; n < end; n++) {\n const b = bones[n] * WORLDS;\n const weight = weights[n];\n const x = deformed ? xs[n] + this.deform[at.deformOffset + n * 2] : xs[n];\n const y = deformed ? ys[n] + this.deform[at.deformOffset + n * 2 + 1] : ys[n];\n wx += (x * W[b + W_A] + y * W[b + W_B] + W[b + W_X]) * weight;\n wy += (x * W[b + W_C] + y * W[b + W_D] + W[b + W_Y]) * weight;\n }\n pts[o++] = wx;\n pts[o++] = wy;\n }\n }\n\n private positionsOfPath(c: RuntimePath, position: number, spaceCount: number, wantsTangent: boolean): void {\n this.computePathWorld(c);\n const pts = this.pathWorldPts;\n const vc = c.pathVertices;\n const n = vc / 2;\n const spaces = this.pathSpaces;\n const out = this.pathPositions;\n const outLen = spaceCount * 3 + 2;\n for (let i = 0; i < outLen; i++) out[i] = 0;\n const closed = c.closed;\n if (!c.constantSpeed) {\n const lengths = c.lengths;\n const curveCount = n / 3 - (closed ? 1 : 2);\n const total = lengths[curveCount];\n if (c.positionMode === PATH_POSITION_PERCENT) position *= total;\n const spaceScale = c.spacingMode === PATH_SPACING_PERCENT ? total : c.spacingMode === PATH_SPACING_PROPORTIONAL ? total / spaceCount : 1;\n let curve = 0;\n for (let i = 0, o = 0; i < spaceCount; i++, o += 3) {\n const space = spaces[i] * spaceScale;\n position += space;\n let p = position;\n if (closed) {\n p %= total;\n if (p < 0) p += total;\n curve = 0;\n } else if (p < 0) {\n onLineBefore(p, pts[2], pts[3], pts[4], pts[5], out, o);\n continue;\n } else if (p > total) {\n const m0 = 2 * (n - 3);\n const m1 = 2 * (n - 2);\n onLinePast(p - total, pts[m0], pts[m0 + 1], pts[m1], pts[m1 + 1], out, o);\n continue;\n }\n for (;; curve++) {\n const length = lengths[curve];\n if (p > length) continue;\n if (curve === 0) p /= length;\n else {\n const prev = lengths[curve - 1];\n p = (p - prev) / (length - prev);\n }\n break;\n }\n const kk = 3 * curve + 1;\n const i0 = (kk % n) * 2;\n const i1 = ((kk + 1) % n) * 2;\n const i2 = ((kk + 2) % n) * 2;\n const i3 = ((kk + 3) % n) * 2;\n onCurve(p, pts[i0], pts[i0 + 1], pts[i1], pts[i1 + 1], pts[i2], pts[i2 + 1], pts[i3], pts[i3 + 1], out, o, wantsTangent || (i > 0 && space === 0));\n }\n return;\n }\n const chain = this.pathChain;\n let chainLen = 0;\n if (closed) {\n for (let q = 2; q < vc; q++) chain[chainLen++] = pts[q];\n chain[chainLen++] = pts[0];\n chain[chainLen++] = pts[1];\n chain[chainLen++] = pts[2];\n chain[chainLen++] = pts[3];\n } else {\n for (let q = 2; q < vc - 2; q++) chain[chainLen++] = pts[q];\n }\n const curveCount = closed ? n / 3 : n / 3 - 1;\n const curveEnds = this.pathCurveEnds;\n let total = 0;\n let cx0 = chain[0];\n let cy0 = chain[1];\n for (let i = 0, w = 2; i < curveCount; i++, w += 6) {\n const cx1 = chain[w];\n const cy1 = chain[w + 1];\n const cx2 = chain[w + 2];\n const cy2 = chain[w + 3];\n const x2 = chain[w + 4];\n const y2 = chain[w + 5];\n const h2x = (cx0 - cx1 * 2 + cx2) * 0.1875;\n const h2y = (cy0 - cy1 * 2 + cy2) * 0.1875;\n const d3x = ((cx1 - cx2) * 3 - cx0 + x2) * 0.09375;\n const d3y = ((cy1 - cy2) * 3 - cy0 + y2) * 0.09375;\n let d2x = h2x * 2 + d3x;\n let d2y = h2y * 2 + d3y;\n let d1x = (cx1 - cx0) * 0.75 + h2x + d3x * 0.16666667;\n let d1y = (cy1 - cy0) * 0.75 + h2y + d3y * 0.16666667;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n d1x += d2x;\n d1y += d2y;\n d2x += d3x;\n d2y += d3y;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n d1x += d2x;\n d1y += d2y;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n d1x += d2x + d3x;\n d1y += d2y + d3y;\n total += Math.sqrt(d1x * d1x + d1y * d1y);\n curveEnds[i] = total;\n cx0 = x2;\n cy0 = y2;\n }\n const pathTotal = curveCount > 0 ? curveEnds[curveCount - 1] : 0;\n if (c.positionMode === PATH_POSITION_PERCENT) position *= pathTotal;\n const spaceScale = c.spacingMode === PATH_SPACING_PERCENT ? pathTotal : c.spacingMode === PATH_SPACING_PROPORTIONAL ? pathTotal / spaceCount : 1;\n const segmentEnds = this.pathSegmentEnds;\n for (let s = 0; s < 10; s++) segmentEnds[s] = 0;\n let curveTotal = 0;\n let lastCurve = -1;\n let x1 = 0, y1 = 0, cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;\n for (let i = 0, o = 0, curve = 0, segment = 0; i < spaceCount; i++, o += 3) {\n const space = spaces[i] * spaceScale;\n position += space;\n let p = position;\n if (closed) {\n p %= pathTotal;\n if (p < 0) p += pathTotal;\n curve = 0;\n segment = 0;\n } else if (p < 0) {\n onLineBefore(p, chain[0], chain[1], chain[2], chain[3], out, o);\n continue;\n } else if (p > pathTotal) {\n onLinePast(p - pathTotal, chain[chainLen - 4], chain[chainLen - 3], chain[chainLen - 2], chain[chainLen - 1], out, o);\n continue;\n }\n for (;; curve++) {\n const length = curveEnds[curve];\n if (p > length) continue;\n if (curve === 0) p /= length;\n else {\n const prev = curveEnds[curve - 1];\n p = (p - prev) / (length - prev);\n }\n break;\n }\n if (curve !== lastCurve) {\n lastCurve = curve;\n const ii = curve * 6;\n x1 = chain[ii];\n y1 = chain[ii + 1];\n cx1 = chain[ii + 2];\n cy1 = chain[ii + 3];\n cx2 = chain[ii + 4];\n cy2 = chain[ii + 5];\n x2 = chain[ii + 6];\n y2 = chain[ii + 7];\n const h2x = (x1 - cx1 * 2 + cx2) * 0.03;\n const h2y = (y1 - cy1 * 2 + cy2) * 0.03;\n const d3x = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;\n const d3y = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;\n let d2x = h2x * 2 + d3x;\n let d2y = h2y * 2 + d3y;\n let d1x = (cx1 - x1) * 0.3 + h2x + d3x * 0.16666667;\n let d1y = (cy1 - y1) * 0.3 + h2y + d3y * 0.16666667;\n curveTotal = Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[0] = curveTotal;\n for (let s = 1; s < 8; s++) {\n d1x += d2x;\n d1y += d2y;\n d2x += d3x;\n d2y += d3y;\n curveTotal += Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[s] = curveTotal;\n }\n d1x += d2x;\n d1y += d2y;\n curveTotal += Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[8] = curveTotal;\n d1x += d2x + d3x;\n d1y += d2y + d3y;\n curveTotal += Math.sqrt(d1x * d1x + d1y * d1y);\n segmentEnds[9] = curveTotal;\n segment = 0;\n }\n p *= curveTotal;\n for (;; segment++) {\n const length = segmentEnds[segment];\n if (p > length) continue;\n if (segment === 0) p /= length;\n else {\n const prev = segmentEnds[segment - 1];\n p = segment + (p - prev) / (length - prev);\n }\n break;\n }\n onCurve(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, wantsTangent || (i > 0 && space === 0));\n }\n }\n\n private sliderAttachments(): void {\n for (let k = 0; k < this.model.constraints.length; k++) {\n this.sliderSlots(k);\n this.sliderDeforms(k);\n }\n }\n\n private sliderSlots(index: number): void {\n const cs = this.model.constraints;\n {\n const k = index, c = cs[k];\n if (c.kind !== 'slider' || !c.applied || this.sliderMix[k] === 0) return;\n const a = c.animation, t = this.sliderAt[k], alpha = this.sliderMix[k];\n if (!this.model.omitDrawOrder && a.drawOrder !== null) {\n const di = keyAt(a.drawOrder.curve, this.cursors, a.drawOrder.cursor, t);\n if (di >= 0) {\n const ns = this.drawOrder.length, orders = a.drawOrder.orders, base = di * ns;\n for (let s = 0; s < ns; s++) this.drawOrder[s] = orders[base + s];\n }\n }\n for (let q = 0; q < a.slots.length; q++) {\n const tl = a.slots[q], i = keyAt(tl.curve, this.cursors, tl.cursor, t);\n if (i < 0) continue;\n if (tl.attachments !== null) {\n const next = tl.attachments[i];\n if (next !== this.shown[tl.slot] && next >= 0) this.deformed[next] = 0;\n this.shown[tl.slot] = next;\n }\n else {\n const channels = tl.channels!;\n const slot = this.model.slots[tl.slot];\n const o = tl.slot * 4, d = tl.slot * 3;\n for (let f = 0; f < channels.length; f++) {\n const at = channels[f], v = channelValue(tl.curve, i, f, t);\n if (at < 4) {\n const n = o + at;\n this.light[n] = clamp01(alpha === 1 ? v : this.light[n] + (v - this.light[n]) * alpha);\n } else if (slot.dark !== null && !this.model.omitDarkColour) {\n const n = d + (at - 4);\n this.dark[n] = clamp01(alpha === 1 ? v : this.dark[n] + (v - this.dark[n]) * alpha);\n }\n }\n }\n }\n }\n }\n\n private sliderDeforms(index: number): void {\n if (this.model.omitDeform) return;\n const cs = this.model.constraints;\n {\n const k = index, c = cs[k];\n if (c.kind !== 'slider' || !c.applied || this.sliderMix[k] === 0) return;\n const a = c.animation, t = this.sliderAt[k], alpha = this.sliderMix[k];\n for (let q = 0; q < a.deforms.length; q++) {\n const tl = a.deforms[q], i = keyAt(tl.curve, this.cursors, tl.cursor, t);\n if (i < 0) continue;\n const held = i + 1 === tl.curve.keys || tl.curve.kinds[i] === CURVE_STEPPED;\n const p = held ? 0 : deformFraction(tl.curve, i, t), start = i * tl.count;\n for (let slot = 0; slot < this.shown.length; slot++) {\n const index = this.shown[slot];\n if (index < 0 || !this.model.slots[slot].live) continue;\n const at = this.model.attachments[index];\n if (at.timeline !== tl.identity || at.deformCount === 0) continue;\n const current = this.deformed[index] !== 0;\n for (let f = 0; f < tl.count; f++) {\n const v = tl.held[start + f], target = held ? v : v + (tl.held[start + tl.count + f] - v) * p;\n const setup = at.draw === DRAW_MESH ? at.local[f] : 0, n = at.deformOffset + f;\n const from = current ? this.deform[n] : setup;\n this.deform[n] = alpha === 1 && (!c.setup.additive || !current) ? target : c.setup.additive ? from + (target - setup) * alpha : from + (target - from) * alpha;\n }\n this.deformed[index] = 1;\n }\n }\n }\n }\n\n private solveIk(c: RuntimeIk, k: number): void {\n const mix = this.ikMix[k];\n if (mix === 0) return;\n const flags = this.ikFlags[k];\n if (c.bones.length === 1) {\n this.solveOne(c.bones[0], c.target, mix, (flags & IK_COMPRESS) !== 0, (flags & IK_STRETCH) !== 0, c.scaleY);\n this.changed[0] = c.bones[0];\n this.repose(1, 0);\n } else if (this.solveTwo(c, mix, this.ikSoftness[k], flags)) {\n this.changed[0] = c.bones[0];\n this.repose(1, 0);\n }\n }\n\n /** A one-bone ik (`solveOne`). */\n private solveOne(bi: number, ti: number, mix: number, compress: boolean, stretch: boolean, scaleYMode: number): void {\n const m = this.model;\n const L = this.locals;\n const W = this.world;\n const parent = m.parents[bi];\n const q = parent * WORLDS;\n let pa = 1;\n let pb = 0;\n let pc = 0;\n let pd = 1;\n let pwx = 0;\n let pwy = 0;\n if (parent >= 0) {\n pa = W[q + W_A];\n pb = W[q + W_B];\n pc = W[q + W_C];\n pd = W[q + W_D];\n pwx = W[q + W_X];\n pwy = W[q + W_Y];\n }\n const bw = bi * WORLDS;\n const tw = ti * WORLDS;\n const l = bi * LOCALS;\n const mode = m.modes[bi];\n let turn = 0;\n let lx: number;\n let ly: number;\n if (mode === MODE_NO_ROTATION_OR_REFLECTION) {\n const k = Math.abs(pa * pd - pb * pc) / Math.max(0.00001, pa * pa + pc * pc);\n pb = -pc * k;\n pd = pa * k;\n turn = Math.atan2(pc, pa) * DEG;\n const det = pa * pd - pb * pc;\n const x = W[tw + W_X] - pwx;\n const y = W[tw + W_Y] - pwy;\n if (Math.abs(det) <= 0.00001) {\n lx = 0;\n ly = 0;\n } else {\n lx = (x * pd - y * pb) / det - L[l + L_X];\n ly = (y * pa - x * pc) / det - L[l + L_Y];\n }\n } else if (mode === MODE_ONLY_TRANSLATION) {\n lx = W[tw + W_X] - W[bw + W_X];\n ly = W[tw + W_Y] - W[bw + W_Y];\n } else {\n const det = pa * pd - pb * pc;\n const x = W[tw + W_X] - pwx;\n const y = W[tw + W_Y] - pwy;\n if (Math.abs(det) <= 0.00001) {\n lx = 0;\n ly = 0;\n } else {\n lx = (x * pd - y * pb) / det - L[l + L_X];\n ly = (y * pa - x * pc) / det - L[l + L_Y];\n }\n }\n const rotation = L[l + L_ROTATION];\n const scaleX = L[l + L_SCALE_X];\n let r = -L[l + L_SHEAR_X] - rotation + turn + Math.atan2(ly, lx) * DEG;\n if (scaleX < 0) r += 180;\n L[l + L_ROTATION] = rotation + wrap180(r) * mix;\n const len = m.lengths[bi] * scaleX;\n if ((compress || stretch) && len > 0.00001) {\n const wx = W[tw + W_X] - W[bw + W_X];\n const wy = W[tw + W_Y] - W[bw + W_Y];\n const d = mode === MODE_NO_SCALE || mode === MODE_NO_SCALE_OR_REFLECTION ? Math.sqrt(wx * wx + wy * wy) : Math.sqrt(lx * lx + ly * ly);\n if ((compress && d < len) || (stretch && d > len)) {\n const s = (d / len - 1) * mix + 1;\n L[l + L_SCALE_X] = scaleX * s;\n if (scaleYMode === SCALE_Y_UNIFORM) L[l + L_SCALE_Y] = L[l + L_SCALE_Y] * s;\n else if (scaleYMode === SCALE_Y_VOLUME) L[l + L_SCALE_Y] = volumeScaleY(L[l + L_SCALE_Y], s);\n }\n }\n }\n\n /** A two-bone ik (`solveTwo`): whether it changed the parent. */\n private solveTwo(c: RuntimeIk, mix: number, softness: number, flags: number): boolean {\n const m = this.model;\n const L = this.locals;\n const W = this.world;\n const pi = c.bones[0];\n const ci = c.bones[1];\n if (m.modes[pi] !== MODE_NORMAL || m.modes[ci] !== MODE_NORMAL) return false;\n const stretch = (flags & IK_STRETCH) !== 0;\n const g = m.parents[pi] * WORLDS;\n const pw = pi * WORLDS;\n const tw = c.target * WORLDS;\n const pl = pi * LOCALS;\n const cl = ci * LOCALS;\n const ga = W[g + W_A];\n const gb = W[g + W_B];\n const gc = W[g + W_C];\n const gd = W[g + W_D];\n const gx = W[g + W_X];\n const gy = W[g + W_Y];\n const gdet = ga * gd - gb * gc;\n const gid = Math.abs(gdet) <= 0.00001 ? 0 : 1 / gdet;\n const px = L[pl + L_X];\n const py = L[pl + L_Y];\n const psx = L[pl + L_SCALE_X];\n const psy = L[pl + L_SCALE_Y];\n const csx = L[cl + L_SCALE_X];\n let sx = psx;\n let sy = psy;\n const cx = L[cl + L_X];\n let cy = L[cl + L_Y];\n const uniform = Math.abs(Math.abs(psx) - Math.abs(psy)) <= 0.00001;\n if (!uniform || stretch) cy = 0;\n let x = W[pw + W_A] * cx + W[pw + W_B] * cy + W[pw + W_X] - gx;\n let y = W[pw + W_C] * cx + W[pw + W_D] * cy + W[pw + W_Y] - gy;\n const ox = (x * gd - y * gb) * gid;\n const oy = (y * ga - x * gc) * gid;\n const dx = ox - px;\n const dy = oy - py;\n const l1 = Math.sqrt(dx * dx + dy * dy);\n let l2 = m.lengths[ci] * Math.abs(csx);\n if (l1 < 0.00001) {\n this.solveOne(pi, c.target, mix, false, stretch, 0);\n L[cl + L_ROTATION] = 0;\n L[cl + L_Y] = cy;\n return true;\n }\n x = W[tw + W_X] - gx;\n y = W[tw + W_Y] - gy;\n let tx = (x * gd - y * gb) * gid;\n let ty = (y * ga - x * gc) * gid;\n tx -= px;\n ty -= py;\n let d2 = tx * tx + ty * ty;\n const bend = (flags & IK_BEND_POSITIVE) !== 0 ? 1 : -1;\n if (softness !== 0) {\n const soft = softness * (Math.abs(psx) * (Math.abs(csx) + 1) * 0.5);\n const d = Math.sqrt(d2);\n const sd = d - l1 - l2 * Math.abs(psx) + soft;\n if (sd > 0) {\n const q = Math.min(1, sd / (soft * 2)) - 1;\n const pull = (sd - soft * (1 - q * q)) / d;\n tx -= pull * tx;\n ty -= pull * ty;\n d2 = tx * tx + ty * ty;\n }\n }\n let a1: number;\n let a2: number;\n if (uniform) {\n l2 *= Math.abs(psx);\n let cos = (d2 - l1 * l1 - l2 * l2) / (2 * l1 * l2);\n if (cos < -1) {\n cos = -1;\n a2 = Math.PI * bend;\n } else if (cos > 1) {\n cos = 1;\n a2 = 0;\n if (stretch) {\n const f = (Math.sqrt(d2) / (l1 + l2) - 1) * mix + 1;\n sx *= f;\n if (c.scaleY === SCALE_Y_UNIFORM) sy *= f;\n else if (c.scaleY === SCALE_Y_VOLUME) sy = volumeScaleY(sy, f);\n }\n } else a2 = Math.acos(cos) * bend;\n const along = l1 + l2 * cos;\n const across = l2 * Math.sin(a2);\n a1 = Math.atan2(ty * along - tx * across, tx * along + ty * across);\n } else {\n const ea = Math.abs(psx) * l2;\n const eb = Math.abs(psy) * l2;\n const aa = ea * ea;\n const bb = eb * eb;\n const qa = bb - aa;\n const qb = -2 * bb * l1;\n const qc = bb * l1 * l1 + aa * d2 - aa * bb;\n const disc = qb * qb - 4 * qa * qc;\n let solved = false;\n a1 = 0;\n a2 = 0;\n if (disc >= 0) {\n let q = Math.sqrt(disc);\n if (qb < 0) q = -q;\n q = -(qb + q) * 0.5;\n const r0 = q / qa;\n const r1 = qc / q;\n const X = Math.abs(r0) < Math.abs(r1) ? r0 : r1;\n const y2 = d2 - X * X;\n if (y2 >= 0) {\n const Y = Math.sqrt(y2) * bend;\n a1 = Math.atan2(ty, tx) - Math.atan2(Y, X);\n a2 = Math.atan2(Y / Math.abs(psy), (X - l1) / Math.abs(psx));\n solved = true;\n }\n }\n if (!solved) {\n let nearAngle = RUNTIME_PI;\n let nearX = l1 - ea;\n let nearY = 0;\n let nearDist = (l1 - ea) * (l1 - ea);\n let farAngle = 0;\n let farX = l1 + ea;\n let farY = 0;\n let farDist = (l1 + ea) * (l1 + ea);\n const vertex = (-ea * l1) / (aa - bb);\n if (vertex >= -1 && vertex <= 1) {\n const angle = Math.acos(vertex);\n const vx = ea * Math.cos(angle) + l1;\n const vy = eb * Math.sin(angle);\n const dist = vx * vx + vy * vy;\n if (dist < nearDist) {\n nearAngle = angle;\n nearX = vx;\n nearY = vy;\n nearDist = dist;\n }\n if (dist > farDist) {\n farAngle = angle;\n farX = vx;\n farY = vy;\n farDist = dist;\n }\n }\n if (d2 <= (nearDist + farDist) * 0.5) {\n a1 = Math.atan2(ty, tx) - Math.atan2(nearY * bend, nearX);\n a2 = nearAngle * bend;\n } else {\n a1 = Math.atan2(ty, tx) - Math.atan2(farY * bend, farX);\n a2 = farAngle * bend;\n }\n }\n }\n const signs = (psx < 0 ? -1 : 1) * (psy < 0 ? -1 : 1);\n const offset = Math.atan2(cy, cx);\n const parentRotation = L[pl + L_ROTATION];\n const parentChange = (a1 - signs * offset) * DEG + (psx < 0 ? 180 : 0) - parentRotation;\n L[pl + L_ROTATION] = parentRotation + wrap180(parentChange) * mix;\n L[pl + L_SCALE_X] = sx;\n L[pl + L_SCALE_Y] = sy;\n const childTarget = ((a2 + signs * offset) * DEG - L[cl + L_SHEAR_X]) * signs + (csx < 0 ? 180 : 0);\n const childRotation = L[cl + L_ROTATION];\n L[cl + L_Y] = cy;\n L[cl + L_ROTATION] = childRotation + wrap180(childTarget - childRotation) * mix;\n return true;\n }\n\n /** Absolute/additive transform, matching `solveTransform` in src/core/constraints.ts:\n * read the source per target/property, edit locals or the scratch world,\n * then repose the union in bone order (`repose` in that module). No read-back for a local target.\n */\n private solveTransform(c: RuntimeTransform, k: number): void {\n const W = this.world;\n const w = this.w;\n const mixes = this.mixes;\n const o6 = k * 6;\n let n = 0;\n for (let bk = 0; bk < c.bones.length; bk++) {\n const bi = c.bones[bk];\n const o = bi * WORLDS;\n w[W_A] = W[o + W_A];\n w[W_B] = W[o + W_B];\n w[W_C] = W[o + W_C];\n w[W_D] = W[o + W_D];\n w[W_X] = W[o + W_X];\n w[W_Y] = W[o + W_Y];\n let applied = false;\n for (let f = 0; f < c.fromProperty.length; f++) {\n const value = this.sourceValue(c, c.fromProperty[f]) - c.fromOffset[f];\n for (let q = c.toStart[f]; q < c.toEnd[f]; q++) {\n const property = c.toProperty[q];\n const mix = mixes[o6 + property];\n if (mix === 0) continue;\n let v = value * c.toScale[q] + c.toOffset[q];\n if (c.clamp) {\n const lo = Math.min(c.toOffset[q], c.toMax[q]);\n const hi = Math.max(c.toOffset[q], c.toMax[q]);\n v = v < lo ? lo : v > hi ? hi : v;\n }\n applied = true;\n if (c.localTarget) {\n const at = bi * LOCALS + PROPERTY_LOCAL[property];\n const current = this.locals[at];\n this.locals[at] = c.additive\n ? property === P_SCALE_X || property === P_SCALE_Y ? current * (1 + (v - 1) * mix) : current + v * mix\n : current + (v - current) * mix;\n } else applyWorld(w, property, v, mix, c.additive);\n }\n }\n if (!applied) continue;\n if (!c.localTarget) {\n W[o + W_A] = w[W_A];\n W[o + W_B] = w[W_B];\n W[o + W_C] = w[W_C];\n W[o + W_D] = w[W_D];\n W[o + W_X] = w[W_X];\n W[o + W_Y] = w[W_Y];\n }\n this.changed[n] = bi;\n this.inWorld[n] = bi;\n n++;\n }\n if (n > 0) this.repose(n, c.localTarget ? 0 : n);\n }\n\n /** The source's current local or world value (`sourceValue` in src/core/constraints.ts). */\n private sourceValue(c: RuntimeTransform, property: number): number {\n if (c.localSource) return this.locals[c.source * LOCALS + PROPERTY_LOCAL[property]] + c.offsets[property];\n const W = this.world;\n const s = c.source * WORLDS;\n const o = c.offsets;\n const a = W[s + W_A];\n const b = W[s + W_B];\n const cc = W[s + W_C];\n const d = W[s + W_D];\n switch (property) {\n case P_ROTATE: {\n const det = a * d - b * cc;\n let r = Math.atan2(cc, a) * DEG + (det > 0 ? o[P_ROTATE] : -o[P_ROTATE]);\n if (r < 0) r += 360;\n return r;\n }\n case P_X:\n return a * o[P_X] + b * o[P_Y] + W[s + W_X];\n case P_Y:\n return cc * o[P_X] + d * o[P_Y] + W[s + W_Y];\n case P_SCALE_X:\n return Math.sqrt(a * a + cc * cc) + o[P_SCALE_X];\n case P_SCALE_Y:\n return Math.sqrt(b * b + d * d) + o[P_SCALE_Y];\n default:\n return (Math.atan2(d, b) - Math.atan2(cc, a)) * DEG - 90 + o[5];\n }\n }\n\n /**\n * After a constraint (`repose`): the `nInWorld` bones it moved in world space\n * (the first of `inWorld`) read back into local values, then every bone below\n * one of the `nChanged` it changed (`changed`) posed again, in bone order —\n * but not through an inactive bone it did not move itself, and not a bone it\n * moved in world space.\n */\n private repose(nChanged: number, nInWorld: number): void {\n const m = this.model;\n const changed = this.changed;\n const changedMark = this.changedMark;\n const inWorldMark = this.inWorldMark;\n const below = this.below;\n for (let k = 0; k < nInWorld; k++) {\n this.localFromWorld(this.inWorld[k]);\n inWorldMark[this.inWorld[k]] = 1;\n }\n for (let k = 0; k < nChanged; k++) {\n changedMark[changed[k]] = 1;\n below[changed[k]] = 1;\n }\n const starts = m.subtreeStart;\n const list = m.subtrees;\n const parents = m.parents;\n const active = m.active;\n if (nChanged === 1) {\n const e = starts[changed[0] + 1];\n for (let q = starts[changed[0]]; q < e; q++) this.reposeOne(list[q], parents, active);\n for (let q = starts[changed[0]]; q < e; q++) below[list[q]] = 0;\n } else {\n // The union of the changed bones' subtrees, in bone order.\n const visit = this.visit;\n let first = parents.length;\n for (let k = 0; k < nChanged; k++) {\n const b = changed[k];\n if (b < first) first = b;\n const e = starts[b + 1];\n for (let q = starts[b]; q < e; q++) visit[list[q]] = 1;\n }\n for (let b = first; b < parents.length; b++) if (visit[b] === 1) this.reposeOne(b, parents, active);\n for (let b = first; b < parents.length; b++) {\n visit[b] = 0;\n below[b] = 0;\n }\n }\n for (let k = 0; k < nChanged; k++) changedMark[changed[k]] = 0;\n for (let k = 0; k < nInWorld; k++) inWorldMark[this.inWorld[k]] = 0;\n }\n\n private reposeOne(b: number, parents: Int32Array, active: Uint8Array): void {\n const below = this.below;\n const p = parents[b];\n if (p >= 0 && below[p] === 1 && (active[p] === 1 || this.changedMark[p] === 1)) below[b] = 1;\n if (below[b] === 1 && this.inWorldMark[b] === 0) this.poseBone(b, false);\n }\n\n /** A bone's locals read back from its world transform (`localFromWorld` in src/core/constraints.ts).\n * All five inherit modes: the no-scale forms read rotation first, rebuild\n * `noScaleDirection`, and retain the x-angle residual as shearX in `decompose`.\n */\n private localFromWorld(bi: number): void {\n const m = this.model;\n const W = this.world;\n const L = this.locals;\n const w = bi * WORLDS;\n const l = bi * LOCALS;\n const parent = m.parents[bi];\n const mode = parent < 0 ? MODE_NORMAL : m.modes[bi];\n let pa = 1;\n let pb = 0;\n let pc = 0;\n let pd = 1;\n let px = 0;\n let py = 0;\n if (parent >= 0) {\n const q = parent * WORLDS;\n pa = W[q + W_A];\n pb = W[q + W_B];\n pc = W[q + W_C];\n pd = W[q + W_D];\n px = W[q + W_X];\n py = W[q + W_Y];\n }\n const pid = 1 / (pa * pd - pb * pc);\n const dx = W[w + W_X] - px;\n const dy = W[w + W_Y] - py;\n L[l + L_X] = dx * (pd * pid) - dy * (pb * pid);\n L[l + L_Y] = dy * (pa * pid) - dx * (pc * pid);\n L[l + L_SHEAR_X] = 0;\n const wa = W[w + W_A];\n const wb = W[w + W_B];\n const wc = W[w + W_C];\n const wd = W[w + W_D];\n if (mode === MODE_NO_SCALE || mode === MODE_NO_SCALE_OR_REFLECTION) {\n const det = pa * pd - pb * pc;\n const flip = mode === MODE_NO_SCALE && det < 0 ? -1 : 1;\n const sign = det < 0 ? -1 : 1;\n const rotation = Math.atan2((pa * wc - pc * wa) * sign, (pd * wa - pb * wc) * sign) * DEG;\n const rr = rotation * RAD;\n const cos = Math.cos(rr), sin = Math.sin(rr);\n let ux = pa * cos + pb * sin, uy = pc * cos + pd * sin;\n const length = 1 / Math.sqrt(ux * ux + uy * uy);\n ux *= length; uy *= length;\n this.decompose(l, ux * wa + uy * wc, (ux * wc - uy * wa) * flip, ux * wb + uy * wd, (ux * wd - uy * wb) * flip, true);\n L[l + L_ROTATION] = rotation;\n return;\n }\n if (mode === MODE_ONLY_TRANSLATION) {\n this.decompose(l, wa, wc, wb, wd);\n return;\n }\n if (mode === MODE_NO_ROTATION_OR_REFLECTION) {\n const xLengthInverse = 1 / (pa * pa + pc * pc);\n const detInverse = 1 / Math.abs(pa * pd - pb * pc);\n this.decompose(l, (pa * wa + pc * wc) * xLengthInverse, (pa * wc - pc * wa) * detInverse, (pa * wb + pc * wd) * xLengthInverse, (pa * wd - pc * wb) * detInverse);\n L[l + L_ROTATION] = L[l + L_ROTATION] + Math.atan2(pc, pa) * DEG;\n return;\n }\n const ia = pd * pid;\n const ib = pb * pid;\n const ic = pc * pid;\n const id = pa * pid;\n this.decompose(l, ia * wa - ib * wc, id * wc - ic * wa, ia * wb - ib * wd, id * wd - ic * wb);\n }\n\n /** A local matrix with columns `(la, lc)` and `(lb, ld)` as rotation, scales and shear (`decompose`). */\n private decompose(l: number, la: number, lc: number, lb: number, ld: number, shearX = false): void {\n const L = this.locals;\n const sx = Math.sqrt(la * la + lc * lc);\n const yLength = Math.sqrt(lb * lb + ld * ld);\n if (!(sx > 0.0001)) {\n L[l + L_SCALE_X] = 0;\n L[l + L_SCALE_Y] = yLength;\n L[l + L_SHEAR_Y] = 0;\n L[l + L_ROTATION] = yLength > 0.00001 ? Math.atan2(ld, lb) * DEG - 90 : 0;\n return;\n }\n const xAngle = Math.atan2(lc, la) * DEG;\n const det = la * ld - lb * lc;\n const yAngle = Math.atan2(ld, lb) * DEG;\n L[l + (shearX ? L_SHEAR_X : L_ROTATION)] = xAngle;\n L[l + L_SCALE_X] = sx;\n L[l + L_SCALE_Y] = det < 0 ? -yLength : yLength;\n const right = det < 0 ? -90 : 90;\n let shear = yAngle - ((shearX ? 0 : xAngle) + right);\n shear = shear > 180 ? shear - 360 : shear < -180 ? shear + 360 : shear;\n L[l + L_SHEAR_Y] = yLength > 0.00001 ? shear : 0;\n }\n\n // ---------------------------------------------------------------------------\n // the slots and the vertices\n // ---------------------------------------------------------------------------\n\n /** Every slot's colour and what it shows (`posedSlots`): the setup's, then each of its timelines at `t` in order. */\n private slotValues(anim: RuntimeAnimation | null, t: number): void {\n const slots = this.model.slots;\n const light = this.light;\n const dark = this.dark;\n for (let s = 0; s < slots.length; s++) {\n const slot = slots[s];\n this.shown[s] = slot.setupAttachment;\n this.drawOrder[s] = s;\n const o = s * 4;\n light[o] = slot.light[0];\n light[o + 1] = slot.light[1];\n light[o + 2] = slot.light[2];\n light[o + 3] = slot.light[3];\n const setupDark = slot.dark;\n if (setupDark !== null) {\n const d = s * 3;\n dark[d] = setupDark[0];\n dark[d + 1] = setupDark[1];\n dark[d + 2] = setupDark[2];\n }\n }\n if (anim === null) return;\n if (!this.model.omitDrawOrder && anim.drawOrder !== null) {\n const di = keyAt(anim.drawOrder.curve, this.cursors, anim.drawOrder.cursor, t);\n if (di >= 0) {\n const ns = slots.length, orders = anim.drawOrder.orders, base = di * ns;\n for (let s = 0; s < ns; s++) this.drawOrder[s] = orders[base + s];\n }\n }\n const timelines = anim.slots;\n for (let k = 0; k < timelines.length; k++) {\n const tl = timelines[k];\n const i = keyAt(tl.curve, this.cursors, tl.cursor, t);\n const attachments = tl.attachments;\n if (attachments !== null) {\n this.shown[tl.slot] = i < 0 ? slots[tl.slot].setupAttachment : attachments[i];\n continue;\n }\n const channels = tl.channels as Int32Array;\n const slot = slots[tl.slot];\n const setup = slot.light;\n const setupDark = slot.dark;\n const o = tl.slot * 4;\n const d = tl.slot * 3;\n for (let c = 0; c < channels.length; c++) {\n const at = channels[c];\n if (at < 4) {\n light[o + at] = i < 0 ? setup[at] : clamp01(channelValue(tl.curve, i, c, t));\n } else if (setupDark !== null && !this.model.omitDarkColour) {\n dark[d + (at - 4)] = i < 0 ? setupDark[at - 4] : clamp01(channelValue(tl.curve, i, c, t));\n }\n }\n }\n }\n\n /** Reset on every pose, then match source identity after switches; no old frame's offsets survive. */\n private deformValues(anim: RuntimeAnimation | null, t: number): void {\n this.deformed.fill(0);\n this.deform.fill(0);\n if (anim === null || this.model.omitDeform) return;\n for (let k = 0; k < anim.deforms.length; k++) {\n const tl = anim.deforms[k];\n const i = keyAt(tl.curve, this.cursors, tl.cursor, t);\n if (i < 0) continue;\n const held = i + 1 === tl.curve.keys || tl.curve.kinds[i] === CURVE_STEPPED;\n const p = held ? 0 : deformFraction(tl.curve, i, t);\n const start = i * tl.count;\n for (let s = 0; s < this.shown.length; s++) {\n const index = this.shown[s];\n if (index < 0 || !this.model.slots[s].live) continue;\n const at = this.model.attachments[index];\n if (at.timeline !== tl.identity || at.deformCount === 0) continue;\n this.deformed[index] = 1;\n for (let q = 0; q < tl.count; q++) {\n const v = tl.held[start + q];\n this.deform[at.deformOffset + q] = held ? v : v + (tl.held[start + tl.count + q] - v) * p;\n }\n }\n }\n }\n\n /** Recompute vertices and overwrite clipping output, without per-frame allocation.\n * Concave/inverse rows describe the core's drawn coverage, not Spine's native triangle list.\n */\n computeClipped(): void {\n this.computeVertices();\n this.clipping?.frame(this);\n }\n\n /** Every shown attachment's world vertices into `vertices` at its offset (`regionCorners`, `worldVertices`). */\n computeVertices(): void {\n const m = this.model;\n const W = this.world;\n const out = this.vertices;\n const shown = this.shown;\n const attachments = m.attachments;\n for (let s = 0; s < shown.length; s++) {\n const index = shown[s];\n if (index < 0) continue;\n const at = attachments[index];\n if (at.draw === DRAW_NONE) continue;\n let o = at.offset;\n if (at.draw === DRAW_REGION || at.draw === DRAW_MESH) {\n const b = at.bone * WORLDS;\n const a = W[b + W_A];\n const bb = W[b + W_B];\n const c = W[b + W_C];\n const d = W[b + W_D];\n const wx = W[b + W_X];\n const wy = W[b + W_Y];\n const local = this.deformed[index] && at.draw === DRAW_MESH ? this.deform : at.local;\n const lo = this.deformed[index] && at.draw === DRAW_MESH ? at.deformOffset : 0;\n if (at.draw === DRAW_REGION) {\n for (let q = 0; q < 8; q += 2) {\n const lx = local[q];\n const ly = local[q + 1];\n out[o++] = a * lx + bb * ly + wx;\n out[o++] = c * lx + d * ly + wy;\n }\n } else {\n for (let q = 0; q < at.count; q += 2) {\n const x = local[lo + q];\n const y = local[lo + q + 1];\n out[o++] = x * a + y * bb + wx;\n out[o++] = x * c + y * d + wy;\n }\n }\n continue;\n }\n // Weighted: per vertex, the sum over its bindings in order.\n const counts = at.bindingCounts;\n const bones = at.bindingBones;\n const xs = at.bindingX;\n const ys = at.bindingY;\n const weights = at.bindingWeights;\n let n = 0;\n for (let v = 0; v < counts.length; v++) {\n let wx = 0;\n let wy = 0;\n const end = n + counts[v];\n for (; n < end; n++) {\n const b = bones[n] * WORLDS;\n const weight = weights[n];\n // The pair belongs to this influence, before its transform and weight, never to the logical vertex.\n const deformed = this.deformed[index] !== 0;\n const x = deformed ? xs[n] + this.deform[at.deformOffset + n * 2] : xs[n];\n const y = deformed ? ys[n] + this.deform[at.deformOffset + n * 2 + 1] : ys[n];\n if (deformed && m.deformAfterWeights) {\n wx += (xs[n] * W[b + W_A] + ys[n] * W[b + W_B] + W[b + W_X]) * weight + this.deform[at.deformOffset + n * 2];\n wy += (xs[n] * W[b + W_C] + ys[n] * W[b + W_D] + W[b + W_Y]) * weight + this.deform[at.deformOffset + n * 2 + 1];\n continue;\n }\n wx += (x * W[b + W_A] + y * W[b + W_B] + W[b + W_X]) * weight;\n wy += (x * W[b + W_C] + y * W[b + W_D] + W[b + W_Y]) * weight;\n }\n out[o++] = wx;\n out[o++] = wy;\n }\n }\n }\n}\n\n/** A world-space absolute/additive property, in `applyWorld` order from src/core/constraints.ts. */\nfunction applyWorld(w: Float64Array, property: number, v: number, mix: number, additive: boolean): void {\n switch (property) {\n case P_ROTATE: {\n let r = additive ? v * RAD : v * RAD - Math.atan2(w[W_C], w[W_A]);\n if (r > RUNTIME_PI) r -= TWO_PI;\n else if (r < -RUNTIME_PI) r += TWO_PI;\n r *= mix;\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n const a = w[W_A];\n const b = w[W_B];\n w[W_A] = cos * a - sin * w[W_C];\n w[W_B] = cos * b - sin * w[W_D];\n w[W_C] = sin * a + cos * w[W_C];\n w[W_D] = sin * b + cos * w[W_D];\n return;\n }\n case P_X:\n w[W_X] = additive ? w[W_X] + v * mix : w[W_X] + (v - w[W_X]) * mix;\n return;\n case P_Y:\n w[W_Y] = additive ? w[W_Y] + v * mix : w[W_Y] + (v - w[W_Y]) * mix;\n return;\n case P_SCALE_X:\n case P_SCALE_Y: {\n const p = property === P_SCALE_X ? W_A : W_B;\n const q = property === P_SCALE_X ? W_C : W_D;\n const s = Math.sqrt(w[p] * w[p] + w[q] * w[q]);\n if (s === 0) return;\n const k = additive ? 1 + (v - 1) * mix : 1 + ((v - s) * mix) / s;\n w[p] *= k;\n w[q] *= k;\n return;\n }\n default: {\n const yAngle = Math.atan2(w[W_D], w[W_B]);\n const xAngle = Math.atan2(w[W_C], w[W_A]);\n // Keep the right-angle subtraction: simplifying it to v * RAD changes bits.\n let r = (v + 90) * RAD - (additive ? 90 * RAD : yAngle - xAngle);\n if (!additive) r = r > RUNTIME_PI ? r - TWO_PI : r < -RUNTIME_PI ? r + TWO_PI : r;\n const angle = yAngle + r * mix;\n const s = Math.sqrt(w[W_B] * w[W_B] + w[W_D] * w[W_D]);\n w[W_B] = Math.cos(angle) * s;\n w[W_D] = Math.sin(angle) * s;\n }\n }\n}\n\nfunction onLineBefore(p: number, x1: number, y1: number, x2: number, y2: number, out: Float64Array, o: number): void {\n const r = Math.atan2(y2 - y1, x2 - x1);\n out[o] = x1 + p * Math.cos(r);\n out[o + 1] = y1 + p * Math.sin(r);\n out[o + 2] = r;\n}\n\nfunction onLinePast(p: number, x0: number, y0: number, x1: number, y1: number, out: Float64Array, o: number): void {\n const r = Math.atan2(y1 - y0, x1 - x0);\n out[o] = x1 + p * Math.cos(r);\n out[o + 1] = y1 + p * Math.sin(r);\n out[o + 2] = r;\n}\n\nfunction onCurve(p: number, x1: number, y1: number, cx1: number, cy1: number, cx2: number, cy2: number, x2: number, y2: number, out: Float64Array, o: number, wantsTangent: boolean): void {\n if (Number.isNaN(p)) {\n out[o] = x1;\n out[o + 1] = y1;\n out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);\n return;\n }\n const t2 = p * p;\n const t3 = t2 * p;\n const u = 1 - p;\n const u2 = u * u;\n const u3 = u2 * u;\n const ut = u * p;\n const ut3x = ut * 3;\n const w1 = u * ut3x;\n const w2 = ut3x * p;\n const x = x1 * u3 + cx1 * w1 + cx2 * w2 + x2 * t3;\n const y = y1 * u3 + cy1 * w1 + cy2 * w2 + y2 * t3;\n out[o] = x;\n out[o + 1] = y;\n if (wantsTangent) {\n if (p < 0.001) out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);\n else out[o + 2] = Math.atan2(y - (y1 * u2 + cy1 * ut * 2 + cy2 * t2), x - (x1 * u2 + cx1 * ut * 2 + cx2 * t2));\n }\n}\n","import {\n activeBones,\n type CompiledDocument,\n CoreInputError,\n type CoreSlotRow,\n type DrawnRegion,\n documentPageLookup,\n drawnRegions,\n meshPageUvs,\n type ModelPage,\n type RawDrawn,\n type RawPose,\n readUvSequences,\n regionPageUvs,\n type UvSource,\n} from '@rig-c/core/core';\n\n/**\n * The record the DOM tier draws: one posed moment of a rig, every slot the\n * renderer shows, in draw order.\n *\n * The renderer never needed a skeleton. Per slot it needs the kind, four world\n * corners or world vertices with page UVs and triangles, the bitmap or the\n * page image with its alpha convention, a tint, a blend mode, a clip polygon\n * and a stacking position — and every one of those is a field of a pose that\n * `rig-c/core` computes from the compiled model document, plus that document's\n * `pages` section. This module is the adapter from one to the other\n * (`frameOf`), and these types are the whole of what crosses it.\n *\n * Coordinates are world space, Y up, exactly as the poser computed them; the\n * renderer does the Y flip. Nothing here is rounded or re-ordered.\n */\nexport interface PosedFrame {\n /** Every slot that draws, in draw order. */\n order: PosedSlot[];\n /**\n * Monotonic pose generation counter when read off a `RigPlayer`\n * (`player.posedFrame()`), matching `player.slotIdentity().generation`.\n */\n generation?: number;\n}\n\n/** The four blend modes, spelled as the runtime's enum names them. */\nexport type BlendMode = 'Normal' | 'Additive' | 'Multiply' | 'Screen';\n\n/**\n * A clip polygon in world space and whether it keeps what is outside it.\n *\n * One object per clip in force: every slot a clip covers carries the *same*\n * object, which is how the renderer tells a clip that covers the whole frame\n * (one `clip-path` on the root) from one that covers a range of it.\n */\nexport interface PosedClip {\n /** Flat x, y pairs, world space. */\n polygon: number[];\n inverse: boolean;\n /**\n * The clipping attachment's `convex` flag: a polygon that is not convex is\n * clipped against its hull rather than decomposed. The DOM tier's CSS\n * `clip-path` takes the polygon as authored and does not read it; the canvas\n * mode's triangle cut does (`clipThrough` in `rig-c/core`).\n */\n convex: boolean;\n}\n\ninterface PosedSlotCommon {\n /** The slot's name — the renderer keys its element on it. */\n slot: string;\n /** The slot's index in the full draw order (hidden slots included): its z-index. */\n z: number;\n blend: BlendMode;\n /** Slot colour × attachment colour × the player's own colour, r g b a in [0, 1]. */\n tint: [number, number, number, number];\n /** The slot's dark (two-colour) tint, where it carries one. The DOM tier cannot draw it. */\n dark?: [number, number, number];\n /** The clip in force over this slot, where one is. */\n clip?: PosedClip;\n}\n\n/** A rigid slot: an unpacked region bitmap posed by its four world corners. */\nexport interface PosedRegion extends PosedSlotCommon {\n kind: 'region';\n /** The region drawn — the key into the region bitmap map (a sequence frame's own name). */\n region: string;\n /** Four world corners, bottom-left, upper-left, upper-right, bottom-right: x0 y0 … x3 y3. */\n corners: number[];\n /**\n * The page the region sits on — the key into the page image map. The DOM tier\n * draws the region's own bitmap and never reads it; the canvas mode samples\n * the page through `uvs`.\n */\n page: string;\n /** Whether the page's texels are premultiplied by their alpha. */\n pma: boolean;\n /**\n * The region's page UVs at its four corners, in the corners' order (u, v\n * pairs, the page spanning [0, 1]) — the runtime's region UVs, a 90°-packed\n * region's turn included. The same array object from frame to frame for the\n * same region.\n */\n uvs: number[];\n}\n\n/** A deform slot: world vertices over page UVs, rastered from the page image. */\nexport interface PosedMesh extends PosedSlotCommon {\n kind: 'mesh';\n /** The page drawn — the key into the page image map. */\n page: string;\n /** Whether the page's texels are premultiplied by their alpha. */\n pma: boolean;\n /** World vertices, flat x, y pairs. */\n vertices: number[];\n /**\n * Page UVs, flat u, v pairs, the page spanning [0, 1]. The same array object\n * from frame to frame for the same region and attachment, so the renderer\n * can tell a mesh whose texture did not change by identity.\n */\n uvs: number[];\n /** Triangle indices into `vertices`, three per triangle. Stable by identity like `uvs`. */\n triangles: number[];\n /** The sequence frame drawn (0 for an attachment with no series). */\n sequence: number;\n}\n\nexport type PosedSlot = PosedRegion | PosedMesh;\n\n/** @internal */\nexport interface TriangleCache {\n /** Known frozen triangle arrays mapped by object identity to their kept frozen output. */\n byRef: WeakMap<readonly number[], number[]>;\n /** Frozen triangle lists kept for this slot and attachment, compared index for index on the fallback path. */\n lists: number[][];\n}\n\n/**\n * What a document's frames read besides the pose, built once per document\n * view (`frameSource`): where every region sits on its page, each record's\n * sequence, which bones are active, and the per-region arrays the frames\n * share.\n *\n * @internal Not part of the package API: it holds `rig-c/core` objects, and\n * the package's types name none of them.\n */\nexport interface FrameSource {\n doc: CompiledDocument;\n uv: UvSource;\n pages: ReadonlyMap<string, ModelPage>;\n active: ReadonlySet<string>;\n boneOf: ReadonlyMap<string, string>;\n /** Setup slot index by slot name (`doc.slots`), for direct O(1) slot-row and setup-drawOrder indexing. */\n slotIndex: ReadonlyMap<string, number>;\n /** Page UVs kept per placement and attachment UV array, so a mesh's `uvs` is one object for its lifetime. */\n uvs: WeakMap<object, Map<readonly number[], number[]>>;\n /** Region page UVs kept per placement, so a region's `uvs` is one object for its lifetime. */\n regionUvs: WeakMap<object, number[]>;\n /** Triangle caches kept per slot and attachment: frozen identity fast path plus value-checked fallback. */\n triangles: Map<string, Map<string, TriangleCache>>;\n}\n\n/**\n * Builds the frame source for one view of a document — the view the track was\n * opened on (`underSkin` / `underNoSkin`), since which bones are active is a\n * fact of the skin. `text` is the document's own text: the sequences' `start`\n * and `digits` are not kept by `readModel`, and `readUvSequences` reads them\n * off the parsed JSON.\n *\n * @internal\n */\nexport function frameSource(doc: CompiledDocument, parsed: unknown): FrameSource {\n if (doc.pages === null) {\n throw new CoreInputError(\n `a ${doc.spec} document does not state where each region sits on its page; build it with \\`rigc build\\``,\n );\n }\n const pages = new Map(doc.pages.map((page) => [page.name, page]));\n const boneOf = new Map<string, string>();\n const slotIndex = new Map<string, number>();\n for (let i = 0; i < doc.slots.length; i++) {\n const slot = doc.slots[i];\n boneOf.set(slot.name, slot.bone);\n slotIndex.set(slot.name, i);\n }\n return {\n doc,\n uv: { lookup: documentPageLookup(doc.pages), sequences: readUvSequences(parsed) },\n pages,\n active: activeBones(doc),\n boneOf,\n slotIndex,\n uvs: new WeakMap(),\n regionUvs: new WeakMap(),\n triangles: new Map(),\n };\n}\n\n/** A slot row's colour channel. The core writes `null` only for a value that is not finite. */\nfunction channel(value: number | null, slot: string): number {\n if (value === null) throw new CoreInputError(`slot \"${slot}\": the pose computed a colour channel that is not finite`);\n return value;\n}\n\n/** The page UVs a drawn mesh samples — `meshPageUvs`, kept per placement and UV array. */\nfunction meshUvs(source: FrameSource, found: DrawnRegion): number[] {\n const art = found.art as readonly number[];\n let byArt = source.uvs.get(found.found);\n if (byArt === undefined) {\n byArt = new Map();\n source.uvs.set(found.found, byArt);\n }\n let kept = byArt.get(art);\n if (kept === undefined) {\n kept = meshPageUvs(found.found.region, found.found.page, art);\n byArt.set(art, kept);\n }\n return kept;\n}\n\n/** The page UVs a drawn region samples — `regionPageUvs`, kept per placement. */\nfunction regionUvs(source: FrameSource, found: DrawnRegion): number[] {\n let kept = source.regionUvs.get(found.found);\n if (kept === undefined) {\n kept = regionPageUvs(found.found.region, found.found.page);\n source.regionUvs.set(found.found, kept);\n }\n return kept;\n}\n\n/**\n * A frozen triangle list equal, index for index, to `drawn.triangles`, kept\n * per slot and attachment for reuse by identity.\n *\n * `rig-c/core`'s `meshArraysOf` hands `RawDrawn.triangles` a frozen canonical\n * array per mesh geometry, so once verified frozen on first sight it hits\n * `cache.byRef` in O(1) by reference identity without re-scanning indices or\n * re-walking property descriptors (`Object.isFrozen`). Mutable or custom inputs\n * stay out of `byRef` and take the value-checked fallback (`cache.lists`),\n * which freezes a copy (`Object.freeze`) so retained old frames cannot be\n * mutated through shared output.\n */\nfunction trianglesOf(source: FrameSource, drawn: RawDrawn): number[] {\n let byAttachment = source.triangles.get(drawn.slot);\n if (byAttachment === undefined) {\n byAttachment = new Map();\n source.triangles.set(drawn.slot, byAttachment);\n }\n let cache = byAttachment.get(drawn.attachment);\n if (cache === undefined) {\n cache = { byRef: new WeakMap(), lists: [] };\n byAttachment.set(drawn.attachment, cache);\n }\n const wanted = drawn.triangles;\n const fast = cache.byRef.get(wanted);\n if (fast !== undefined) return fast;\n const frozen = Object.isFrozen(wanted);\n let kept = cache.lists.find((list) => list.length === wanted.length && list.every((v, i) => v === wanted[i]));\n if (kept === undefined) {\n kept = frozen ? (wanted as number[]) : (Object.freeze([...wanted]) as number[]);\n cache.lists.push(kept);\n cache.byRef.set(kept, kept);\n }\n if (frozen) cache.byRef.set(wanted, kept);\n return kept;\n}\n\nfunction regionMap(regions: readonly DrawnRegion[]): Map<string, DrawnRegion> {\n const map = new Map<string, DrawnRegion>();\n for (let i = 0; i < regions.length; i++) map.set(regions[i].slot, regions[i]);\n return map;\n}\n\nfunction slotRowMap(slots: readonly CoreSlotRow[]): Map<string, CoreSlotRow> {\n const map = new Map<string, CoreSlotRow>();\n for (let i = 0; i < slots.length; i++) map.set(slots[i][0], slots[i]);\n return map;\n}\n\nfunction drawOrderMap(drawOrder: readonly string[]): Map<string, number> {\n const map = new Map<string, number>();\n for (let i = 0; i < drawOrder.length; i++) map.set(drawOrder[i], i);\n return map;\n}\n\n/**\n * The clip over each slot of the draw order, where one covers it — the official\n * draw loops' `clipStart`/`clipEnd`, restated over a pose (rigc's\n * `clipCover` in `src/render_core.ts` is the specification this follows):\n *\n * - walking the draw order, a slot showing a clipping attachment first ends the\n * clip in force if it is that clip's end slot, then starts its own when its\n * bone is active and no clip is in force — a second clip met while one is in\n * force is ignored, not nested;\n * - every other slot is covered by the clip in force, and ends it after being\n * covered if it is the end slot (the end slot is inside its own clip);\n * - a clip whose end slot is its own slot, or one already passed, never ends.\n *\n * Each started clip is one `PosedClip` object, shared by every slot it covers.\n *\n * @internal Exported for the frame gate's synthetic cover cases.\n */\nexport function clipCover(pose: Pick<RawPose, 'clips' | 'shown' | 'drawOrder'>, active: ReadonlySet<string>, draws: (slot: string) => boolean = () => true): Map<string, PosedClip> {\n const cover = new Map<string, PosedClip>();\n if (pose.clips.length === 0) return cover;\n const polygons = new Map<string, { end: string | null; polygon: number[] }>();\n for (let i = 0; i < pose.clips.length; i++) {\n const c = pose.clips[i];\n polygons.set(c[0], { end: c[2], polygon: c[3] });\n }\n const shownOf = new Map<string, RawPose['shown'][number]>();\n for (let i = 0; i < pose.shown.length; i++) {\n const s = pose.shown[i];\n shownOf.set(s.slot, s);\n }\n let current: { end: string | null; clip: PosedClip } | null = null;\n for (const slot of pose.drawOrder) {\n const shown = shownOf.get(slot);\n const g = shown?.geometry;\n const clip = g?.kind === 'clipping' ? polygons.get(slot) : undefined;\n if (shown !== undefined && g?.kind === 'clipping' && clip !== undefined) {\n if (current !== null && current.end === slot) current = null;\n // A clip start the player does not draw does not clip: the filter is a\n // draw filter, and a clip is drawn by its effect on what it covers.\n if (active.has(shown.bone) && current === null && draws(slot)) {\n current = { end: clip.end, clip: { polygon: clip.polygon, inverse: g.inverse, convex: g.convex } };\n }\n continue;\n }\n if (current !== null) cover.set(slot, current.clip);\n if (current !== null && current.end === slot) current = null;\n }\n return cover;\n}\n\n/**\n * One pose as a frame.\n *\n * - `order` is the pose's draw order narrowed to the attachments it draws\n * (`pose.drawn`, regions and meshes) on active bones; `z` is the slot's index\n * in the full draw order.\n * - A region's `corners` are its drawn vertices, which the core writes in the\n * runtime's corner order: bottom-left, upper-left, upper-right, bottom-right.\n * - A region's `uvs` are `regionPageUvs` over the region `drawnRegions`\n * resolves for it, and its `page`/`pma` that region's page.\n * - A mesh's `uvs` are `meshPageUvs` over the region `drawnRegions` resolves\n * for it (a sequence frame's own region, a linked mesh's own region over its\n * source's UVs) and its `page`/`pma` that region's page.\n * - `tint` is the slot row's colour times the attachment's colour, channel by\n * channel, then times `color` — the player's own whole-rig colour, which is\n * not a document value.\n * - `blend` is the slot row's mode; `dark` its dark colour where it has one.\n * - `clip` is `clipCover` above.\n *\n * @internal\n */\nexport function frameOf(\n source: FrameSource,\n pose: RawPose,\n color: readonly [number, number, number, number] = [1, 1, 1, 1],\n draws: (slot: string) => boolean = () => true,\n): PosedFrame {\n const { drawn: regions, why } = drawnRegions(source.doc, pose.shown, pose.drawOrder, source.uv);\n if (regions === null) throw new CoreInputError(`the page UVs are not posed: ${why}`);\n let regionOf: Map<string, DrawnRegion> | null = null;\n let rows: Map<string, CoreSlotRow> | null = null;\n let z: Map<string, number> | null = null;\n const cover = pose.clips.length === 0 ? null : clipCover(pose, source.active, draws);\n const [sr, sg, sb, sa] = color;\n const order: PosedSlot[] = [];\n for (let i = 0; i < pose.drawn.length; i++) {\n const d = pose.drawn[i];\n if (!draws(d.slot)) continue;\n const bone = source.boneOf.get(d.slot);\n if (bone === undefined || !source.active.has(bone)) continue;\n const directRegion = regions[i];\n const found =\n directRegion !== undefined && directRegion.slot === d.slot\n ? directRegion\n : (regionOf ??= regionMap(regions)).get(d.slot);\n if (found === undefined) throw new CoreInputError(`slot \"${d.slot}\" drew \"${d.attachment}\", and no atlas region was resolved for it`);\n const slotIdx = source.slotIndex.get(d.slot);\n const directRow = slotIdx !== undefined ? pose.slots[slotIdx] : undefined;\n const row =\n directRow !== undefined && directRow[0] === d.slot\n ? directRow\n : (rows ??= slotRowMap(pose.slots)).get(d.slot);\n if (row === undefined) throw new CoreInputError(`slot \"${d.slot}\" drew and has no slot row`);\n const slotZ =\n slotIdx !== undefined && pose.drawOrder[slotIdx] === d.slot\n ? slotIdx\n : ((z ??= drawOrderMap(pose.drawOrder)).get(d.slot) as number);\n const tint: [number, number, number, number] = [\n channel(row[2], d.slot) * d.colour[0] * sr,\n channel(row[3], d.slot) * d.colour[1] * sg,\n channel(row[4], d.slot) * d.colour[2] * sb,\n channel(row[5], d.slot) * d.colour[3] * sa,\n ];\n const darkRow = row[6];\n const clip = cover === null ? undefined : cover.get(d.slot);\n const common = {\n slot: d.slot,\n z: slotZ,\n blend: (row[8] ?? 'Normal') as BlendMode,\n tint,\n ...(darkRow === null ? {} : { dark: [channel(darkRow[0], d.slot), channel(darkRow[1], d.slot), channel(darkRow[2], d.slot)] as [number, number, number] }),\n ...(clip === undefined ? {} : { clip }),\n };\n const page = source.pages.get(found.found.page.name);\n if (d.kind === 'region') {\n order.push({\n ...common,\n kind: 'region',\n region: found.region,\n corners: d.vertices,\n page: found.found.page.name,\n pma: page?.pma === true,\n uvs: regionUvs(source, found),\n });\n } else {\n order.push({\n ...common,\n kind: 'mesh',\n page: found.found.page.name,\n pma: page?.pma === true,\n vertices: d.vertices,\n uvs: meshUvs(source, found),\n triangles: trianglesOf(source, d),\n sequence: d.sequenceIndex,\n });\n }\n }\n return { order };\n}\n","import { liveDrawings as drawings } from './liveFrameSource.js';\nimport { poseRawSetup } from '@rig-c/core/core';\nimport { compileRuntime, RuntimePose, type RuntimeAttachment, type RuntimeModel } from '@rig-c/core/runtime';\nimport { frameOf, type BlendMode, type FrameSource, type PosedClip, type PosedFrame, type PosedSlot } from './posedFrame.js';\n\n/** An indexed, read-only buffer. Buffer mutation methods are deliberately absent. */\nexport interface LiveNumbers {\n readonly length: number;\n readonly [index: number]: number;\n}\n\n/** A borrowed clipping polygon, shared by the slots it covers. */\nexport interface LiveClip {\n readonly polygon: LiveNumbers;\n readonly inverse: boolean;\n readonly convex: boolean;\n}\n\n/** Attachment metadata resolved once; dark and clip borrow the current pose. */\nexport interface LiveAttachment {\n readonly slot: string;\n readonly slotIndex: number;\n readonly attachment: string | null;\n readonly skin: string | null;\n /** Exact table key on the runtime path; unavailable on an oracle snapshot. */\n readonly placeholder: string | null;\n readonly kind: 'region' | 'mesh' | 'none';\n readonly region: string | null;\n readonly page: string | null;\n readonly pma: boolean;\n readonly blend: BlendMode;\n readonly offset: number;\n readonly count: number;\n readonly uvs: LiveNumbers;\n readonly triangles: LiveNumbers;\n readonly dark: LiveNumbers | null;\n readonly clip: LiveClip | null;\n}\n\n/**\n * A borrowed frame, valid only until the player's next pose mutation.\n * `drawOrder[0..count)` contains indices into `attachments`; vertices use each\n * attachment's offset/count, and tint uses slotIndex * 4. Production reuses the\n * buffers. Development leases detect stale reads, including held nested views.\n */\nexport interface LiveFrame {\n readonly generation: number;\n readonly count: number;\n readonly drawOrder: LiveNumbers;\n readonly vertices: LiveNumbers;\n readonly tint: LiveNumbers;\n readonly attachments: readonly LiveAttachment[];\n}\n\n/** @internal A stable array facade for the existing renderer interface, without vertex copies. */\nfunction numbers(buffer: Float64Array, offset: number, count: number): number[] {\n const result = new Array<number>(count);\n for (let i = 0; i < count; i++) Object.defineProperty(result, i, {\n enumerable: true, get: () => buffer[offset + i],\n });\n return Object.freeze(result) as number[];\n}\n\n/** @internal Deep development lease. No typed-array method can expose writable backing storage. */\nexport function checkedLiveFrame(frame: LiveFrame, current: () => number): LiveFrame {\n const generation = current();\n const frameGeneration = frame.generation;\n const proxies = new WeakMap<object, object>();\n const check = (): void => {\n if (current() !== generation) throw new Error(`LIVE_FRAME_STALE: borrowed generation ${frameGeneration} was invalidated; call liveFrame() again`);\n };\n const wrap = <T extends object>(value: T): T => {\n const found = proxies.get(value);\n if (found) return found as T;\n // A separate extensible target avoids proxy invariants on frozen metadata.\n const proxy = new Proxy(Array.isArray(value) ? [] : {}, {\n get(_target, property) {\n check();\n if (property === 'buffer' || property === 'set' || property === 'fill' || property === 'copyWithin' || property === 'reverse' || property === 'sort') {\n throw new Error(`LIVE_FRAME_READONLY: ${String(property)} does not expose the live backing store`);\n }\n const item: unknown = Reflect.get(value, property, value);\n if (typeof item === 'function') {\n if (ArrayBuffer.isView(value) && property !== Symbol.iterator) throw new Error(`LIVE_FRAME_READONLY: ${String(property)} is not part of the indexed live buffer interface`);\n return (...args: unknown[]) => {\n check();\n const returned: unknown = Reflect.apply(item, Array.isArray(value) ? proxy : value, args);\n return returned !== null && typeof returned === 'object' ? wrap(returned) : returned;\n };\n }\n return item !== null && typeof item === 'object' ? wrap(item) : item;\n },\n set() { check(); throw new Error('LIVE_FRAME_READONLY: live frame values cannot be assigned'); },\n defineProperty() { check(); throw new Error('LIVE_FRAME_READONLY: live frame values cannot be redefined'); },\n deleteProperty() { check(); throw new Error('LIVE_FRAME_READONLY: live frame values cannot be deleted'); },\n preventExtensions() { check(); throw new Error('LIVE_FRAME_READONLY: live frame objects cannot be reconfigured'); },\n setPrototypeOf() { check(); throw new Error('LIVE_FRAME_READONLY: live frame prototypes cannot be changed'); },\n has(_target, property) { check(); return Reflect.has(value, property); },\n ownKeys() { check(); return Reflect.ownKeys(value); },\n getOwnPropertyDescriptor(_target, property) {\n check();\n if (property === 'length' && Array.isArray(value)) return { value: value.length, writable: true, configurable: false, enumerable: false };\n const descriptor = Reflect.getOwnPropertyDescriptor(value, property);\n return descriptor ? { configurable: true, enumerable: descriptor.enumerable, get: () => Reflect.get(proxy, property) } : undefined;\n },\n });\n proxies.set(value, proxy);\n return proxy as T;\n };\n const lease = wrap(frame);\n const drawing = drawings.get(frame);\n if (drawing) drawings.set(lease, drawing);\n return lease;\n}\n\n/** Keep the optional accessor's capture out of data-only attachment creation. */\nfunction withLiveClip(metadata: LiveAttachment, template: PosedSlot | null): LiveAttachment {\n Object.defineProperty(metadata, 'clip', { get: () => template?.clip ?? null });\n return metadata;\n}\n\n/** @internal Runtime draw state. Constructed once per document view. */\nexport class RuntimeFrames {\n readonly model: RuntimeModel;\n readonly pose: RuntimePose;\n readonly renderFrame: PosedFrame = { order: [] };\n readonly live: LiveFrame;\n private readonly order: Int32Array;\n private readonly tint: Float64Array;\n private readonly templates: Array<PosedSlot | null>;\n private readonly clips: Array<PosedClip | null>;\n private readonly colours: ReadonlyArray<readonly number[]>;\n /** Incremented when a draw refresh changes colour without a pose step. */\n revision = 0;\n private readonly previousColor = new Float64Array(4).fill(Number.NaN);\n private drawn = 0;\n private epoch = 0;\n\n constructor(source: FrameSource, model?: RuntimeModel) {\n this.model = model ?? compileRuntime(source.doc);\n this.pose = new RuntimePose(this.model);\n this.order = new Int32Array(this.model.slots.length);\n this.tint = new Float64Array(this.model.slots.length * 4);\n const colours: number[][] = [];\n const metadata: LiveAttachment[] = [];\n this.clips = this.model.attachments.map(attachment => attachment.clip === undefined ? null : {\n polygon: numbers(this.pose.vertices, attachment.offset, attachment.count),\n inverse: attachment.clip.inverse, convex: attachment.clip.convex,\n });\n this.templates = this.model.attachments.map((attachment, index) => {\n const identity = attachment as RuntimeAttachment & { readonly skin?: string; readonly placeholder?: string };\n if (identity.skin === undefined || identity.placeholder === undefined) {\n throw new Error(`RUNTIME_DRAW_IDENTITY: attachment ${index} on slot \"${this.model.slots[attachment.slot].name}\" needs resolved skin and placeholder from rig-c/runtime`);\n }\n const slot = this.model.slots[attachment.slot];\n // This is a load-time oracle read, never a per-frame lookup or poser.\n const doc = { ...source.doc, slots: source.doc.slots.map((value, si) => ({ ...value, setup: si === attachment.slot ? identity.placeholder! : null })) };\n const setup = poseRawSetup(doc);\n const raw = setup.drawn.find(value => value.slot === slot.name);\n const template = frameOf(source, setup).order.find(value => value.slot === slot.name) ?? null;\n const colour = raw?.colour ?? [1, 1, 1, 1];\n colours.push(colour);\n if (template) {\n const vertices = numbers(this.pose.vertices, attachment.offset, attachment.count);\n if (template.kind === 'region') template.corners = vertices;\n else template.vertices = vertices;\n template.tint = numbers(this.tint, attachment.slot * 4, 4) as [number, number, number, number];\n if (slot.dark !== null) template.dark = numbers(this.pose.dark, attachment.slot * 3, 3) as [number, number, number];\n }\n const item = {\n slot: slot.name, slotIndex: attachment.slot, attachment: attachment.name,\n skin: identity.skin, placeholder: identity.placeholder,\n kind: template?.kind ?? 'none' as const, region: template?.kind === 'region' ? template.region : null,\n page: template?.page ?? null, pma: template?.pma ?? false, blend: slot.blend,\n offset: attachment.offset, count: attachment.count,\n uvs: Object.freeze(template?.uvs ?? []), triangles: Object.freeze(template?.kind === 'mesh' ? template.triangles : []),\n dark: template?.dark ?? null,\n clip: null,\n };\n // Keep data-only metadata for a model with no clips. Besides being\n // unnecessary there, the accessor changes JSC's allocation behavior\n // when callers read the attachment's offset on the loose path fixture.\n metadata.push(Object.freeze(this.pose.clipping === null ? item : withLiveClip(item, template)));\n return template;\n });\n this.colours = colours;\n const owner = this;\n this.live = Object.freeze({\n get generation() { return owner.epoch; }, get count() { return owner.drawn; },\n drawOrder: this.order, vertices: this.pose.vertices, tint: this.tint, attachments: Object.freeze(metadata),\n });\n drawings.set(this.live, this.renderFrame);\n }\n\n update(generation: number, color: readonly number[], draws: (slot: string) => boolean, poseChanged = true): void {\n if (poseChanged) this.pose.computeVertices();\n let colorChanged = false;\n for (let c = 0; c < 4; c++) {\n if (!Object.is(this.previousColor[c], color[c])) colorChanged = true;\n this.previousColor[c] = color[c];\n }\n if (colorChanged) this.revision++;\n let count = 0;\n let clip: PosedClip | null = null;\n let end: string | null = null;\n for (let z = 0; z < this.pose.drawOrder.length; z++) {\n const si = this.pose.drawOrder[z];\n const ai = this.pose.shown[si];\n const slot = this.model.slots[si];\n const attachment = ai < 0 ? null : this.model.attachments[ai];\n if (attachment?.clip !== undefined) {\n if (clip !== null && end === slot.name) clip = null;\n if (clip === null && this.model.active[attachment.bone] && draws(slot.name)) {\n clip = this.clips[ai]; end = attachment.clip.end;\n }\n continue;\n }\n const template = ai < 0 ? null : this.templates[ai];\n if (template && this.model.active[slot.bone]) {\n template.z = z;\n if (clip === null) { if (template.clip !== undefined) delete template.clip; }\n else template.clip = clip;\n const offset = si * 4;\n const colour = this.colours[ai];\n for (let c = 0; c < 4; c++) this.tint[offset + c] = this.pose.light[offset + c] * colour[c] * color[c];\n if (draws(template.slot)) {\n this.order[count] = ai;\n this.renderFrame.order[count++] = template;\n }\n }\n if (clip !== null && end === slot.name) clip = null;\n }\n this.renderFrame.order.length = count;\n this.drawn = count;\n this.epoch = generation;\n }\n\n snapshot(draws?: (slot: string) => boolean): PosedFrame {\n const order: PosedSlot[] = [];\n const copies = new Map<PosedClip, PosedClip>();\n let clip: PosedClip | null = null;\n let end: string | null = null;\n for (let z = 0; z < this.pose.drawOrder.length; z++) {\n const si = this.pose.drawOrder[z];\n const ai = this.pose.shown[si];\n const attachment = ai < 0 ? null : this.model.attachments[ai];\n const name = this.model.slots[si].name;\n if (attachment?.clip !== undefined) {\n if (clip !== null && end === name) clip = null;\n if (clip === null && this.model.active[attachment.bone] && (draws === undefined || draws(name))) {\n clip = this.clips[ai]; end = attachment.clip.end;\n }\n continue;\n }\n const slot = ai < 0 ? null : this.templates[ai];\n if (slot && this.model.active[this.model.slots[si].bone] && (draws === undefined || draws(name))) {\n const common = { ...slot, z, tint: slot.tint.slice() as [number, number, number, number] };\n if (slot.dark) common.dark = slot.dark.slice() as [number, number, number];\n delete common.clip;\n if (clip !== null) {\n let copy = copies.get(clip);\n if (!copy) { copy = { ...clip, polygon: clip.polygon.slice() }; copies.set(clip, copy); }\n common.clip = copy;\n }\n order.push(slot.kind === 'region'\n ? { ...common, kind: 'region' as const, region: slot.region, corners: slot.corners.slice(), page: slot.page, pma: slot.pma, uvs: slot.uvs }\n : { ...common, kind: 'mesh' as const, vertices: slot.vertices.slice(), page: slot.page, pma: slot.pma, uvs: slot.uvs, triangles: slot.triangles, sequence: slot.sequence });\n }\n if (clip !== null && end === name) clip = null;\n }\n return { order };\n }\n}\n\n/** @internal Oracle fallback keeps the same borrowed-buffer layout, without a zero-allocation claim. */\nexport function oracleLiveFrame(frame: PosedFrame, identities: ReadonlyMap<string, { attachment: string | null; skin: string | null }>, indices: ReadonlyMap<string, number>): LiveFrame {\n let size = 0;\n for (const slot of frame.order) size += (slot.kind === 'region' ? slot.corners : slot.vertices).length;\n const vertices = new Float64Array(size);\n const tint = new Float64Array(indices.size * 4);\n const drawOrder = new Int32Array(frame.order.length);\n let offset = 0;\n const attachments = frame.order.map((slot, index): LiveAttachment => {\n const points = slot.kind === 'region' ? slot.corners : slot.vertices;\n const slotIndex = indices.get(slot.slot);\n if (slotIndex === undefined) throw new Error(`LIVE_FRAME_SLOT: drawn slot \"${slot.slot}\" has no setup index`);\n vertices.set(points, offset); tint.set(slot.tint, slotIndex * 4); drawOrder[index] = index;\n const identity = identities.get(slot.slot);\n if (!identity) throw new Error(`LIVE_FRAME_IDENTITY: drawn slot \"${slot.slot}\" has no coherent identity`);\n const metadata: LiveAttachment = { slot: slot.slot, slotIndex, attachment: identity.attachment, skin: identity.skin, placeholder: null, kind: slot.kind,\n region: slot.kind === 'region' ? slot.region : null, page: slot.page, pma: slot.pma, blend: slot.blend, offset, count: points.length,\n uvs: slot.uvs, triangles: slot.kind === 'mesh' ? slot.triangles : [], dark: slot.dark ?? null, clip: slot.clip ?? null };\n offset += points.length;\n return metadata;\n });\n const live = { generation: frame.generation ?? 0, count: attachments.length, drawOrder, vertices, tint, attachments };\n drawings.set(live, frame);\n return live;\n}\n","import { type CompiledDocument, type CoreSlotRow, eventsFired, type LiveTrack, type LiveTracks, type LocalAdjust as CoreLocalAdjust, openTrack, openTracks, physicsClockStep, poseRawSetup, type RawClip, type RawDrawn, type RawPose, type TrackEntryView, underNoSkin, underSkin } from '@rig-c/core/core';\nimport { compileRuntime, RuntimeRefusal, type RuntimeModel } from '@rig-c/core/runtime';\nimport { checkedLiveFrame, oracleLiveFrame, RuntimeFrames, type LiveFrame } from './liveFrame.js';\nimport { CanvasRenderer } from './CanvasRenderer.js';\nimport { DomRenderer, type MeshBackend } from './DomRenderer.js';\nimport type { ModelAssets, ReadDocument, RigSet } from './loadModel.js';\nimport { type FrameSource, frameOf, frameSource, type PosedFrame } from './posedFrame.js';\n\n/**\n * Plays a rig built by `rigc build` on a DOM root.\n *\n * The player owns the track and the renderer: `play` opens an animation on a\n * live track (`openTrack` from `rig-c/core`), each `frame(dt)` steps it by\n * `dt × timeScale`, turns the pose into a `PosedFrame` and hands that to its\n * renderer — a `DomRenderer` (`mode: 'dom'`, the default) or a\n * `CanvasRenderer` (`mode: 'canvas'`). Everything the pose holds is computed by\n * the core from the compiled model document; this class schedules and draws.\n */\n\n/**\n * How a player draws: `'dom'` — elements, the rigid tier as `<img>` and the\n * mesh tier on per-part canvases (`DomRenderer`); `'canvas'` — the whole frame\n * into one `<canvas>` through the shared WebGL context (`CanvasRenderer`).\n */\nexport type RenderMode = 'dom' | 'canvas';\n\nexport interface RigPlayerOptions {\n /** Auto selects covered runtime features; oracle is the comparison/control path. */\n poser?: 'auto' | 'oracle';\n /** Development stale/read-only lease checks; defaults to the development build setting. */\n liveFrameChecks?: boolean;\n /**\n * The skin to pose under. Absent is the runtime's \"no skin set\" — a fresh\n * skeleton whose `setSkin` was never called (`underNoSkin`): no skin's bones\n * or constraints applied, every slot resolved through the default skin.\n */\n skin?: string;\n /** The per-pose adjustment of bone locals (`player.adjust`), set from the first pose. */\n adjust?: BoneAdjust | null;\n /** Which slots this player draws (`player.slots`); every slot when absent. */\n slots?: SlotFilter | null;\n /** How the player draws (see `RenderMode`). Default `'dom'`. Can be changed later through `mode`. */\n mode?: RenderMode;\n /** The mesh tier's rasterizer (see `DomRenderer.meshBackend`) — the DOM mode only. */\n meshBackend?: MeshBackend;\n /**\n * The step `seek` walks the track forward with, in seconds. A seek is\n * \"reopen, then step to the time\", never a jump: a physics rig has history,\n * and the pose at a time depends on the steps taken to reach it.\n */\n seekStep?: number;\n /**\n * Stand the player on rig-c's live tracks from the first `play`, so the\n * first composing call — a mix, another track, a queue, a clear — never\n * replays. Without it a plain `play` runs on the single live track, and the\n * first composing call carries it over by replaying the time played in\n * `seekStep` increments (there is no hand-over of a live track's physics\n * state in the core), which on a stage that idled a while is one long\n * frame. Pick the single track for a rig whose animations key what the\n * tracks do not mix (constraints, sequences, the draw order, a path's\n * deform); pick the tracks for layering.\n */\n tracks?: boolean;\n}\n\n/** What `on('event', …)` hands a listener: one event key the step crossed. */\n/**\n * The world a rig's physics answers (`RigPlayer.environment`): spine-core's\n * skeleton-level wind and gravity, x to the right and y down.\n */\nexport interface RigEnvironment {\n readonly wind: readonly [number, number];\n readonly gravity: readonly [number, number];\n}\n\n/** Wind and gravity for a seek step, sampled at its starting track time in seconds. */\nexport type RigEnvironmentSchedule = (replayTime: number) => RigEnvironment;\n\n/** Select constraint owners by exact bone, inclusive subtree, or exact physics names. */\nexport type PhysicsMotionScope = { bone: string } | { subtree: string } | { constraints: readonly string[] };\n/** Additional apparent movement in skeleton world units (Y up), or XY roll in degrees CCW. */\nexport type PhysicsMotion =\n | { translation: { x: number; y: number } }\n | { rotation: { degrees: number; pivot: readonly [number, number] } };\n\n/** The runtime's start values — spine-core 4.3.13's `Skeleton` defaults. */\nconst DEFAULT_ENVIRONMENT: RigEnvironment = Object.freeze({ wind: Object.freeze([1, 0] as const), gravity: Object.freeze([0, 1] as const) });\n\nexport interface RigEvent {\n name: string;\n /** The key's time in the animation. */\n time: number;\n int: number;\n float: number;\n string: string | null;\n /**\n * The track whose current entry fired it. The core's pose lists a step's\n * events in track order without naming the track, so the player attributes\n * them by counting what each track's current entry fires over the step;\n * when that count does not match the pose (an entry replaced inside the\n * step), the step's events carry no track rather than a guessed one.\n */\n track?: number;\n}\n\n/** What `on('complete', …)` hands a listener: the entry that completed, and its track. */\nexport interface RigComplete {\n animation: string;\n track: number;\n}\n\n/** How `play` starts an entry, and `queue` queues one. */\nexport interface PlayOptions {\n /** Loop; true by default. */\n loop?: boolean;\n /** The track; 0 by default. A base on 0, a layer over it on 1, a one-shot on 2. */\n track?: number;\n /** Seconds the entry this one replaces mixes out over; 0 (the default) cuts. */\n mix?: number;\n /**\n * The entry's weight, from 0 to 1 (1 by default), multiplied into every\n * timeline it applies — the same clip at 0.6 and at 0.85. Change it while\n * the entry plays with `setAlpha`. It does not touch events (fired at any\n * alpha, 0 included) or attachments (kept at any alpha).\n */\n alpha?: number;\n /**\n * The entry adds its keyed bone and deform values to what the tracks below\n * posed, rather than replacing them — a layer keying the same bone channels\n * as the base without covering its motion (false by default). Fixed when the\n * entry is set or queued. A rotation is added as it stands, with no\n * shortest-angle wrap; mixing out, an additive entry fades with its alpha\n * and is never held.\n */\n additive?: boolean;\n}\n\nexport interface QueueOptions extends PlayOptions {\n /**\n * At or below 0 (the default 0): the entry starts when the one before it\n * completes, less this entry's `mix` — a one-shot then mixes into the next\n * over its last `mix` seconds. Above 0: that many seconds after the entry\n * before it starts.\n */\n delay?: number;\n}\n\n/** A track's current entry as the player reads it (`entry(track)`). */\nexport interface TrackEntry {\n /** What it plays; null for the empty animation a `clear` left. */\n animation: string | null;\n loop: boolean;\n /** The entry's own track time, from its start. */\n trackTime: number;\n /** The animation time it applies at now: the track time wrapped, or held at the duration. */\n animationTime: number;\n duration: number;\n /** The entry's weight as it stands (`PlayOptions.alpha`, `setAlpha`). */\n alpha: number;\n /** Whether the entry adds (`PlayOptions.additive`). */\n additive: boolean;\n}\n\ntype Listener<T> = (payload: T) => void;\n\n/**\n * One rig on one root.\n *\n * ```ts\n * const player = new RigPlayer(root, assets);\n * player.play('walk');\n * requestAnimationFrame(function tick(now) { player.frame(dt); requestAnimationFrame(tick); });\n * ```\n */\n/**\n * One bone's local values at a pose, read and written in place: the seven\n * channels the runtime's bone has, in its units (degrees, world-unit\n * translation, scale factors, shear in degrees). What `BoneAdjust` receives\n * through `AdjustableBones.bone`.\n */\nexport interface BoneLocals {\n rotation: number;\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n shearX: number;\n shearY: number;\n}\n\n/** The bones of one pose, by name, as a `BoneAdjust` sees them. */\nexport interface AdjustableBones {\n /** The document's bones, in its order. */\n readonly names: readonly string[];\n /** One bone's locals, read and written in place; a name the document has no bone for is refused by name. */\n bone(name: string): BoneLocals;\n}\n\n/** The evaluation identity supplied by the core, independent of the displayed player clock. */\nexport interface BoneAdjustContext {\n /** Current track-0 entry's unwrapped seconds; null when there is no entry. */\n readonly trackTime: number | null;\n /** Current entry's animation; null also for an explicit empty entry (whose time is numeric). */\n readonly animation: string | null;\n /** Running sum of core steps in seconds, independent of the physics clock. */\n readonly globalTime: number;\n}\n\n/**\n * A caller's adjustment of a pose's bone locals — a breath's scale, a look's\n * rotation, a mouth's `scaleY` — called once per pose after the animation's\n * timelines and before the world transforms, constraints and physics (the\n * core's `openTrack({ adjust })`, held to the Spine runtime at tolerance 0\n * by rig-c). **A write lasts one pose**: the core poses every step from the\n * setup pose, so a value the caller wants held is written again each pose,\n * and nothing compounds. A non-finite value, an unknown bone, or an error the\n * function throws refuses that step in the core's words.\n */\nexport type BoneAdjust = (bones: AdjustableBones, ctx: BoneAdjustContext) => void;\n\n/** Runtime scalar responses; the core performs no unit conversion or clamping. */\nexport interface PhysicsParameters {\n readonly strength: number;\n readonly damping: number;\n readonly inertia: number;\n readonly wind: number;\n readonly gravity: number;\n readonly mix: number;\n}\n\n/** Omitted fields retain their pending override. */\nexport type PhysicsParameterPatch = Partial<PhysicsParameters>;\n\n/** Detached pending patch and last active evaluation (null until evaluated). */\nexport interface PhysicsParameterRead {\n readonly override: PhysicsParameterPatch | null;\n readonly effective: PhysicsParameters | null;\n}\n\n/**\n * Where a bone is in the pose the player holds — world units, Y up, the\n * numbers `rig-c/core` posed (`RawBone`): the world matrix `a b c d`, the\n * world position, the world rotation of each axis in degrees and the world\n * scale of each, and whether the bone is active under the player's skin.\n */\nexport interface BoneWorld {\n name: string;\n active: boolean;\n x: number;\n y: number;\n a: number;\n b: number;\n c: number;\n d: number;\n rotationX: number;\n rotationY: number;\n scaleX: number;\n scaleY: number;\n}\n\n/**\n * Which slots a player draws: an allow list of slot names, or a predicate\n * over the name. The pose is the whole rig's whatever the filter — bones,\n * constraints, physics, `bone()` and `adjust` are untouched — and only the\n * draw is filtered. A clipping slot the filter leaves out does not clip.\n */\nexport type SlotFilter = readonly string[] | ((slot: string) => boolean);\n\n/**\n * What a set call (`setSet`, `setSets`, `addSet`, `removeSet`) does with the\n * physics hung under the bones the switch re-poses (#173). Only a switch that\n * changes a set's `drawn` re-poses bones, so only then does it apply.\n *\n * - absent: nothing — the constraints read the jump as motion, as before.\n * - `'carry'`: each affected constraint's state is moved by the rigid turn its\n * deepest re-posed ancestor makes, so the chain keeps its pose relative to\n * the bone and does not snap.\n * - `'reset'`: each affected constraint starts again at the new pose, as a\n * physics `reset` key restarts it.\n */\nexport interface SetActivationOptions {\n physics?: 'carry' | 'reset';\n /**\n * Seconds over which the switch eases the bones it re-poses (#174), instead\n * of snapping them: each covered bone whose drawn rotation this call adds,\n * removes or changes turns from the local it shows to its new one (the\n * drawn local, or the clip's value when its set goes) along the shorter\n * way, by smoothstep(elapsed / ease), and the attachments swap on the frame\n * nearest the middle. A finite number at or above 0; `0` or absent is the\n * instant switch. See `setSets`.\n */\n ease?: number;\n}\n\n/** `options.ease` of a set call, checked before anything changes: 0 when absent. */\nfunction setEaseOption(call: string, options: SetActivationOptions | undefined): number {\n const ease = options?.ease;\n if (ease === undefined) return 0;\n if (typeof ease !== 'number' || !Number.isFinite(ease) || ease < 0) {\n throw new Error(`${call}: options.ease must be a finite number of seconds at or above 0, got ${typeof ease === 'number' ? String(ease) : JSON.stringify(ease)}`);\n }\n return ease;\n}\n\n/**\n * An eased set switch in flight (#174). Each eased bone turns from `from` to\n * `to`, each a fixed local rotation or `null` for the clip's value at the\n * time; `clip` holds the clip's local of each eased bone as the last pose\n * read it, before the override.\n */\ninterface SetEase {\n readonly duration: number;\n elapsed: number;\n readonly bones: ReadonlyMap<string, { readonly from: number | null; readonly to: number | null }>;\n readonly clip: Map<string, number>;\n /** The composition drawn until the swap: the one shown when the call was made. */\n readonly fromSet: RigSet | null;\n swapped: boolean;\n readonly physics: 'carry' | 'reset' | undefined;\n}\n\n/** u = elapsed / duration, clamped to [0, 1]. */\nfunction easeProgress(ease: SetEase): number {\n return Math.min(Math.max(ease.elapsed / ease.duration, 0), 1);\n}\n\n/** smoothstep(u) = u²(3 − 2u): 0 → 1, flat at both ends, never outside [0, 1]. */\nfunction smoothstep(u: number): number {\n return u * u * (3 - 2 * u);\n}\n\n/** `options.physics` of a set call, checked before anything changes. */\nfunction setPhysicsOption(call: string, options: SetActivationOptions | undefined): 'carry' | 'reset' | undefined {\n if (options === undefined) return undefined;\n if (options === null || typeof options !== 'object') {\n throw new Error(`${call}: options must be an object like { physics: 'carry' }, got ${JSON.stringify(options)}`);\n }\n const physics = options.physics;\n if (physics === undefined || physics === 'carry' || physics === 'reset') return physics;\n throw new Error(`${call}: options.physics must be 'carry' or 'reset', got ${JSON.stringify(physics)}`);\n}\n\n/** The bones whose drawn rotation differs between `before` and `after` (added, removed or changed). */\nfunction drawnChanged(before: ReadonlyMap<string, number> | null, after: ReadonlyMap<string, number> | null): Set<string> {\n const changed = new Set<string>();\n if (before !== null) for (const [bone, rotation] of before) if (after?.get(bone) !== rotation) changed.add(bone);\n if (after !== null) for (const [bone, rotation] of after) if (before?.get(bone) !== rotation) changed.add(bone);\n return changed;\n}\n\n/** The physics context a live stepper carries from step to step. */\nfunction physicsContextOf(stepper: LiveTrack | LiveTracks): PhysicsContextInternal {\n return 'first' in stepper ? (stepper as unknown as TrackInternal).track.ctx : (stepper as unknown as TracksInternal).path.ctx;\n}\n\n/** A box in world units, Y up: `y` is the bottom edge. */\nexport interface PoseBounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * Why a slot in `SlotIdentitySnapshot.slots` is not drawn (`reason !== null`),\n * or `null` when it is drawn in `posedFrame().order`:\n * - `'set-hide'`: hidden by an active attachment set (`set.hides` or a\n * `<base>_still` companion of a slot an active set covers or hides).\n * - `'timeline-null'`: an attachment timeline (or slider attachment timeline)\n * keyed the slot to `null` at the current time.\n * - `'no-attachment'`: the slot has no drawable attachment at this pose\n * (its setup placeholder is `null` with no timeline/set override, its\n * placeholder is absent from the active and default skins, or its attachment\n * is non-visual such as a clipping polygon, bounding box, or path).\n * - `'hidden'`: excluded from rendering by the player's `slots` filter or\n * because its bone is inactive under the active skin.\n */\nexport type SlotIdentityReason = 'hidden' | 'no-attachment' | 'timeline-null' | 'set-hide';\n\n/** One slot's resolved identity at `z` in the posed draw order (`SlotIdentitySnapshot.slots`). */\nexport interface SlotIdentity {\n /** The slot's name in `skeleton.model.json`. */\n readonly slot: string;\n /** Index (`0 .. slots.length - 1`) in the posed draw order. */\n readonly z: number;\n /** Resolved attachment key (`string`) when drawn, or `null` when not drawn. */\n readonly attachment: string | null;\n /** Owning skin name (`'default'`, named skin, etc.) for `attachment`, or `null` when `attachment === null`. */\n readonly skin: string | null;\n /** `null` when drawn in `posedFrame().order`; otherwise why the slot is not drawn. */\n readonly reason: SlotIdentityReason | null;\n}\n\n/**\n * Read-only slot identity snapshot coherent with the player's current pose\n * and `posedFrame()` (#144).\n */\nexport interface SlotIdentitySnapshot {\n /** Monotonic pose generation counter matching `player.generation` and `player.posedFrame().generation`. */\n readonly generation: number;\n /** The one active attachment set (`player.set`), or `null` when none or several are active. */\n readonly set: string | null;\n /** Every active attachment set (`player.activeSets`), in `sets.json` declaration order. */\n readonly sets: readonly string[];\n /** Currently active skin (`player.skin ?? null`), or `null` when only `'default'` is active. */\n readonly skin: string | null;\n /** Every slot of the skeleton in the posed draw order (`z = 0 .. slots.length - 1`), hidden/null ones included. */\n readonly slots: readonly SlotIdentity[];\n}\n\n/** An allow list as a predicate. */\nfunction predicateOf(names: readonly string[]): (slot: string) => boolean {\n const allowed = new Set(names);\n return (slot) => allowed.has(slot);\n}\n\n/** Whether `slotName` is hidden by `set` (`set.hides` or a `<base>_still` companion of a covered/hidden base slot). */\nfunction hiddenBySet(slotName: string, set: RigSet): boolean {\n if (set.hides.includes(slotName)) return true;\n if (slotName.endsWith('_still') && !(slotName in set.slots)) {\n const base = slotName.slice(0, -'_still'.length);\n if (base in set.slots || set.hides.includes(base)) return true;\n }\n return false;\n}\n\n/**\n * The slots `set` touches on `view`: every slot it covers plus every slot it\n * hides (`hides` and `<base>_still` companions). Two active sets must touch\n * disjoint slots (#168).\n */\nfunction touchedBySet(view: CompiledDocument, set: RigSet): ReadonlySet<string> {\n const touched = new Set<string>();\n for (const slot of view.slots) {\n if (slot.name in set.slots || hiddenBySet(slot.name, set)) touched.add(slot.name);\n }\n return touched;\n}\n\n/** Degrees into (-180, 180]. */\nfunction normaliseDegrees(deg: number): number {\n let v = ((deg % 360) + 360) % 360;\n if (v > 180) v -= 360;\n return v;\n}\n\n/**\n * The local rotations that put `drawn`'s bones at their world rotations at\n * the setup pose (#170), the way `@rig-c/parts` poses a set for `check --set`\n * (`poseRigBonesForDrawn`): bones in document order, each drawn bone's local\n * rotation the drawn angle less its world rotation at local 0, under its\n * already-posed parents, with no constraint applied. A bone hanging from a\n * stopped link's drawn twin `<link>_d` reads its parent as `<link>`, as\n * parts reads it (parts #404).\n */\nfunction drawnLocals(view: CompiledDocument, drawn: Readonly<Record<string, number>>): ReadonlyMap<string, number> {\n const names = new Set(view.bones.map((b) => b.name));\n const realParent = (parent: string | undefined): string | undefined =>\n parent !== undefined && parent.endsWith('_d') && names.has(parent.slice(0, -2)) ? parent.slice(0, -2) : parent;\n const bones = view.bones.map((b) => ({ ...b, parent: realParent(b.parent) }));\n const locals = new Map<string, number>();\n for (let i = 0; i < bones.length; i++) {\n const target = drawn[bones[i].name];\n if (target === undefined) continue;\n bones[i] = { ...bones[i], rotation: 0 };\n const pose = poseRawSetup({ ...view, bones, slots: [], constraints: [] });\n const world = pose.bones.find((b) => b.name === bones[i].name);\n if (world === undefined) throw new Error(`drawn bone ${JSON.stringify(bones[i].name)} was not posed`);\n const rotation = normaliseDegrees(target - normaliseDegrees((Math.atan2(world.c, world.a) * 180) / Math.PI));\n bones[i] = { ...bones[i], rotation };\n locals.set(bones[i].name, rotation);\n }\n return locals;\n}\n\n/**\n * One set equivalent to `sets` applied together, or `null` for none. One set is\n * returned as it is; several, already checked disjoint, merge their `slots` and\n * `hides` (a slot one set touches no other set names, so the merge hides and\n * covers exactly what each set does alone and does not depend on order).\n */\nfunction composeSets(sets: readonly RigSet[]): RigSet | null {\n if (sets.length === 0) return null;\n if (sets.length === 1) return sets[0];\n const drawn = sets.filter((s) => s.drawn !== undefined);\n return {\n name: sets.map((s) => s.name).join('+'),\n slots: Object.assign({}, ...sets.map((s) => s.slots)) as Record<string, string>,\n hides: sets.flatMap((s) => s.hides),\n ...(drawn.length === 0 ? {} : { drawn: Object.assign({}, ...drawn.map((s) => s.drawn)) as Record<string, number> }),\n };\n}\n\n/**\n * Applies `set` to `raw` over `view`: every slot the set covers takes the set's\n * attachment posed against `raw.bones` (keeping the slot's animated colour and\n * dark tint from `raw.slots`); every slot the set `hides` (plus any `<base>_still`\n * slot of a covered or hidden base slot) takes `attachment: null` and is removed\n * from `shown` / `drawn` / `clips`; every uncovered slot keeps its exact `raw.slots`\n * row, `shown` entry and `drawn` geometry (including any track attachment,\n * mesh deform or sequence frame).\n */\nfunction applySetToPose(view: CompiledDocument, raw: RawPose, set: RigSet): RawPose {\n const coveredNames = new Set(Object.keys(set.slots));\n const overrideSlots = view.slots.flatMap((slot) => {\n const setup = set.slots[slot.name];\n return setup !== undefined ? [{ ...slot, setup }] : [];\n });\n const world = new Map(\n raw.bones.map((bone) => [\n bone.name,\n { a: bone.a, b: bone.b, c: bone.c, d: bone.d, worldX: bone.worldX, worldY: bone.worldY },\n ]),\n );\n const overridePose =\n overrideSlots.length > 0\n ? poseRawSetup(\n { ...view, slots: overrideSlots, constraints: [] },\n { evaluate: () => world, constraints: () => [] },\n )\n : null;\n const overRowBySlot = new Map<string, CoreSlotRow>();\n const overShownBySlot = new Map<string, RawPose['shown'][number]>();\n const overDrawnBySlot = new Map<string, RawDrawn>();\n const overClipBySlot = new Map<string, RawClip>();\n if (overridePose !== null) {\n for (const row of overridePose.slots) overRowBySlot.set(row[0], row);\n for (const s of overridePose.shown) overShownBySlot.set(s.slot, s);\n for (const d of overridePose.drawn) overDrawnBySlot.set(d.slot, d);\n for (const c of overridePose.clips) overClipBySlot.set(c[0], c);\n }\n const rawShownBySlot = new Map(raw.shown.map((s) => [s.slot, s]));\n const rawDrawnBySlot = new Map(raw.drawn.map((d) => [d.slot, d]));\n const rawClipBySlot = new Map(raw.clips.map((c) => [c[0], c]));\n const hiddenSlot = (slotName: string): boolean => hiddenBySet(slotName, set);\n const slots: CoreSlotRow[] = raw.slots.map((rawRow): CoreSlotRow => {\n const slotName = rawRow[0];\n if (hiddenSlot(slotName)) {\n return [slotName, null, rawRow[2], rawRow[3], rawRow[4], rawRow[5], rawRow[6], null, rawRow[8]];\n }\n const overRow = overRowBySlot.get(slotName);\n if (overRow !== undefined) {\n return [slotName, overRow[1], rawRow[2], rawRow[3], rawRow[4], rawRow[5], rawRow[6], overRow[7], rawRow[8]];\n }\n return rawRow;\n });\n const shown: RawPose['shown'][number][] = [];\n const drawn: RawDrawn[] = [];\n const clips: RawClip[] = [];\n for (const slotName of raw.drawOrder) {\n if (hiddenSlot(slotName)) continue;\n if (coveredNames.has(slotName)) {\n const s = overShownBySlot.get(slotName);\n if (s !== undefined) shown.push(s);\n const d = overDrawnBySlot.get(slotName);\n if (d !== undefined) drawn.push(d);\n const c = overClipBySlot.get(slotName);\n if (c !== undefined) clips.push(c);\n } else {\n const s = rawShownBySlot.get(slotName);\n if (s !== undefined) shown.push(s);\n const d = rawDrawnBySlot.get(slotName);\n if (d !== undefined) drawn.push(d);\n const c = rawClipBySlot.get(slotName);\n if (c !== undefined) clips.push(c);\n }\n }\n return {\n ...raw,\n slots,\n shown,\n drawn,\n clips,\n };\n}\n\n/** Up to 4,096 steps (~68.3 s at 60 Hz) are kept at stride 1; beyond that, every 8th step is kept. */\nconst SEEK_FINE_STEP_LIMIT = 4096;\nconst SEEK_COARSE_STRIDE = 8;\n/** Maximum number of exact target-time snapshots retained per player. */\nconst SEEK_EXACT_LIMIT = 1024;\n\ninterface PhysicsStateInternal {\n pending: boolean;\n lastTime: number;\n remaining: number;\n ux: number;\n uy: number;\n cx: number;\n cy: number;\n tx: number;\n ty: number;\n xOffset: number;\n xLag: number;\n xVelocity: number;\n yOffset: number;\n yLag: number;\n yVelocity: number;\n rotateOffset: number;\n rotateLag: number;\n rotateVelocity: number;\n scaleOffset: number;\n scaleLag: number;\n scaleVelocity: number;\n}\n\ninterface PhysicsContextInternal {\n phase: 'reset' | 'update';\n time: number;\n states: Map<string, PhysicsStateInternal>;\n last: number;\n loop?: boolean;\n env?: RigEnvironment;\n}\n\ninterface TrackInternal {\n readonly first: RawPose;\n readonly track: {\n trackTime: number;\n last: number;\n readonly ctx: PhysicsContextInternal;\n };\n steps: number;\n latest: number;\n refused: string | null;\n}\n\ninterface MixerEntryInternal {\n delay: number;\n trackTime: number;\n trackLast: number;\n nextTrackLast: number;\n trackEnd: number;\n animationLast: number;\n nextAnimationLast: number;\n mixTime: number;\n mixDuration: number;\n totalAlpha: number;\n alpha: number;\n additive: boolean;\n keepHold: boolean;\n timelineMode: number[];\n timelineHoldMix: unknown[];\n timelinesRotation: number[];\n}\n\ninterface TracksInternal {\n started: boolean;\n steps: number;\n time: number;\n refused: string | null;\n readonly path: {\n readonly ctx: PhysicsContextInternal;\n };\n readonly mixer: {\n readonly tracks: Array<MixerEntryInternal | null>;\n animationsChanged: boolean;\n readonly propertyIds: Map<string, number>;\n };\n}\n\ninterface PhysicsContextSnapshot {\n readonly phase: 'reset' | 'update';\n readonly time: number;\n readonly last: number;\n readonly loop: boolean | undefined;\n readonly env: RigEnvironment | undefined;\n readonly states: ReadonlyMap<string, PhysicsStateInternal>;\n}\n\ninterface TrackStateSnapshot {\n readonly kind: 'track';\n readonly steps: number;\n readonly latest: number;\n readonly refused: string | null;\n readonly trackTime: number;\n readonly last: number;\n readonly ctx: PhysicsContextSnapshot;\n}\n\ninterface TracksStateSnapshot {\n readonly kind: 'tracks';\n readonly started: boolean;\n readonly steps: number;\n readonly time: number;\n readonly refused: string | null;\n readonly animationsChanged: boolean;\n readonly propertyIds: ReadonlyMap<string, number>;\n readonly entry: {\n readonly delay: number;\n readonly trackTime: number;\n readonly trackLast: number;\n readonly nextTrackLast: number;\n readonly trackEnd: number;\n readonly animationLast: number;\n readonly nextAnimationLast: number;\n readonly mixTime: number;\n readonly mixDuration: number;\n readonly totalAlpha: number;\n readonly alpha: number;\n readonly additive: boolean;\n readonly keepHold: boolean;\n readonly timelineMode: readonly number[];\n readonly timelineHoldMix: readonly unknown[];\n readonly timelinesRotation: readonly number[];\n } | null;\n readonly ctx: PhysicsContextSnapshot;\n}\n\ntype StepperStateSnapshot = TrackStateSnapshot | TracksStateSnapshot;\n\ninterface SeekGridEntry {\n readonly state: StepperStateSnapshot;\n readonly rawPose: RawPose;\n readonly parameters: ReadonlyMap<string, PhysicsParameterRead>;\n}\n\ninterface SeekExactEntry extends SeekGridEntry {\n readonly pose: RawPose;\n}\n\ninterface SeekCache {\n readonly mode: 'track' | 'tracks';\n readonly frontier: LiveTrack | LiveTracks;\n frontierSteps: number;\n readonly grid: Map<number, SeekGridEntry>;\n readonly exact: Map<number, SeekExactEntry>;\n}\n\nfunction capturePhysicsContext(ctx: PhysicsContextInternal): PhysicsContextSnapshot {\n const states = new Map<string, PhysicsStateInternal>();\n for (const [name, s] of ctx.states) states.set(name, { ...s });\n return {\n phase: ctx.phase,\n time: ctx.time,\n last: ctx.last,\n loop: ctx.loop,\n env: ctx.env,\n states,\n };\n}\n\nfunction restorePhysicsContext(ctx: PhysicsContextInternal, snap: PhysicsContextSnapshot): void {\n ctx.phase = snap.phase;\n ctx.time = snap.time;\n ctx.last = snap.last;\n if (snap.loop === undefined) delete ctx.loop;\n else ctx.loop = snap.loop;\n if (snap.env === undefined) delete ctx.env;\n else ctx.env = snap.env;\n ctx.states.clear();\n for (const [name, s] of snap.states) ctx.states.set(name, { ...s });\n}\n\nfunction captureStepperState(stepper: LiveTrack | LiveTracks): StepperStateSnapshot {\n if ('first' in stepper) {\n const internal = stepper as unknown as TrackInternal;\n return {\n kind: 'track',\n steps: internal.steps,\n latest: internal.latest,\n refused: internal.refused,\n trackTime: internal.track.trackTime,\n last: internal.track.last,\n ctx: capturePhysicsContext(internal.track.ctx),\n };\n }\n const internal = stepper as unknown as TracksInternal;\n const entry = internal.mixer.tracks[0] ?? null;\n return {\n kind: 'tracks',\n started: internal.started,\n steps: internal.steps,\n time: internal.time,\n refused: internal.refused,\n animationsChanged: internal.mixer.animationsChanged,\n propertyIds: new Map(internal.mixer.propertyIds),\n entry:\n entry === null\n ? null\n : {\n delay: entry.delay,\n trackTime: entry.trackTime,\n trackLast: entry.trackLast,\n nextTrackLast: entry.nextTrackLast,\n trackEnd: entry.trackEnd,\n animationLast: entry.animationLast,\n nextAnimationLast: entry.nextAnimationLast,\n mixTime: entry.mixTime,\n mixDuration: entry.mixDuration,\n totalAlpha: entry.totalAlpha,\n alpha: entry.alpha,\n additive: entry.additive,\n keepHold: entry.keepHold,\n timelineMode: [...entry.timelineMode],\n timelineHoldMix: [...entry.timelineHoldMix],\n timelinesRotation: [...entry.timelinesRotation],\n },\n ctx: capturePhysicsContext(internal.path.ctx),\n };\n}\n\nfunction restoreStepperState(stepper: LiveTrack | LiveTracks, snap: StepperStateSnapshot): void {\n if (snap.kind === 'track') {\n const internal = stepper as unknown as TrackInternal;\n internal.steps = snap.steps;\n internal.latest = snap.latest;\n internal.refused = snap.refused;\n internal.track.trackTime = snap.trackTime;\n internal.track.last = snap.last;\n restorePhysicsContext(internal.track.ctx, snap.ctx);\n return;\n }\n const internal = stepper as unknown as TracksInternal;\n internal.started = snap.started;\n internal.steps = snap.steps;\n internal.time = snap.time;\n internal.refused = snap.refused;\n internal.mixer.animationsChanged = snap.animationsChanged;\n internal.mixer.propertyIds.clear();\n for (const [k, v] of snap.propertyIds) internal.mixer.propertyIds.set(k, v);\n const entry = internal.mixer.tracks[0] ?? null;\n if (entry !== null && snap.entry !== null) {\n entry.delay = snap.entry.delay;\n entry.trackTime = snap.entry.trackTime;\n entry.trackLast = snap.entry.trackLast;\n entry.nextTrackLast = snap.entry.nextTrackLast;\n entry.trackEnd = snap.entry.trackEnd;\n entry.animationLast = snap.entry.animationLast;\n entry.nextAnimationLast = snap.entry.nextAnimationLast;\n entry.mixTime = snap.entry.mixTime;\n entry.mixDuration = snap.entry.mixDuration;\n entry.totalAlpha = snap.entry.totalAlpha;\n entry.alpha = snap.entry.alpha;\n entry.additive = snap.entry.additive;\n entry.keepHold = snap.entry.keepHold;\n entry.timelineMode = [...snap.entry.timelineMode];\n entry.timelineHoldMix = [...snap.entry.timelineHoldMix];\n entry.timelinesRotation = [...snap.entry.timelinesRotation];\n }\n restorePhysicsContext(internal.path.ctx, snap.ctx);\n}\n\nexport class RigPlayer {\n /**\n * The renderer this player draws through — its knobs and counters are the\n * caller's to read and set. A `DomRenderer` in the DOM mode, a\n * `CanvasRenderer` in the canvas mode; a new object after `mode` changes.\n */\n get renderer(): DomRenderer | CanvasRenderer {\n return this.active;\n }\n /** Multiplies every step. 0 holds the pose (nothing is re-posed); negative is refused by the track. */\n timeScale = 1;\n /** The player's whole-rig colour, r g b a — multiplied into every slot's tint. Not a document value. */\n color: [number, number, number, number] = [1, 1, 1, 1];\n\n private active: DomRenderer | CanvasRenderer;\n private readonly root: HTMLElement;\n private readonly assets: ModelAssets;\n private readonly meshBackend: MeshBackend | undefined;\n private view: CompiledDocument;\n private source: FrameSource;\n private readonly read: ReadDocument;\n private skinName: string | undefined;\n private readonly seekStep: number;\n /** The environment the page set, or null for the runtime's start values (`environment`). */\n private env: RigEnvironment | null = null;\n /**\n * The single live track (`openTrack`): what a plain `play` on track 0 runs\n * on, as every 1.x player did — one animation, every construct the core\n * poses, `seek` and a skin change by reopening. Null once the player is\n * composed.\n */\n private track: LiveTrack | null = null;\n /**\n * The live tracks (`openTracks`): opened by the first composing call — a\n * `play` with a mix or on another track, a `queue`, a `clear` — from the\n * single track's animation stepped to its time. The mixing is the Spine\n * runtime's, which does not mix a constraint, sequence, draw-order or\n * path-deform timeline, so such an animation is refused here and plays on\n * the single track only.\n */\n private tracks: LiveTracks | null = null;\n /** Track 0's animation and loop as `play` last set them — what `seek` and a skin change reopen. */\n private animation: string | null = null;\n private loop = true;\n /** One past the highest track touched — how many `current(track)` reads a step takes. */\n private trackCount = 0;\n /** `RigPlayerOptions.tracks`: every play opens the live tracks, never the single track. */\n private readonly trackMode: boolean;\n /** Set once anything beyond a plain play on track 0 happened: a mix, another track, a queue, a clear. `seek` and `skin` then cannot replay and refuse. */\n private beyondBase = false;\n private paused = false;\n /** `hold(true)`: `advance` moves the physics clock and re-poses at the same track time (#248). */\n private holding = false;\n /** Set only while a held step is in flight: the step the physics clock moves by in place of the track's zero step. */\n private heldClockStep: number | null = null;\n /** Test-only (#248's planted controls): the held step as a plain advance, as nothing, or a release that replays the time as `seek` does. Not API. */\n private heldPlant: 'advance' | 'freeze' | 'reset' | null = null;\n /** Handed to every track the player opens as its physics clock: rig-c's render clock of the step, or of the held step while one is in flight. */\n private readonly clockHook = (dt: number): number => physicsClockStep(this.heldClockStep ?? dt);\n private pose: RawPose | null = null;\n /** The un-overridden pose from the track/tracks (or setup pose when `setSet` is called before `play`). */\n private rawPose: RawPose | null = null;\n private setup: RawPose | null = null;\n private seekCache: SeekCache | null = null;\n private poseGeneration = 0;\n private runtimeModel: RuntimeModel | null = null;\n private runtimeFrames: RuntimeFrames | null = null;\n private runtimeReadback: RawPose | null = null;\n private runtimeCompletionClock = { trackTime: 0 };\n private poserLabel = 'oracle: not selected';\n private readonly oracleOnly: boolean;\n private readonly liveChecks: boolean;\n private liveDisposed = false;\n private cachedIdentity: SlotIdentitySnapshot | null = null;\n private cachedIdentityGen = -1;\n private readonly setList: readonly RigSet[];\n private readonly setsByName: ReadonlyMap<string, RigSet>;\n /** The active sets in declaration order (#168); `activeSet` is their composition. */\n private activeList: readonly RigSet[] = [];\n private activeSet: RigSet | null = null;\n private readonly touchedSets = new Map<string, ReadonlySet<string>>();\n /** The active sets' drawn bones as local rotations, applied before `adjust` on every pose (#170); null when none draws. */\n private drawnPose: ReadonlyMap<string, number> | null = null;\n /** Test-only (#173's planted control): `carry` maps every state through the identity instead of the anchor's turn. Not API. */\n private carryPlant = false;\n /** An eased set switch in flight (#174), or null. */\n private easing: SetEase | null = null;\n /** The last positive step `advance` took: what predicts the next one when an ease starts. */\n private lastStep = 0;\n /** Test-only (#174's planted controls): swap the attachments at u = 0, or ease by w = 1.2u (1 at u = 1). Not API. */\n private easePlant: 'swap-at-0' | 'overshoot' | null = null;\n private adjustFn: BoneAdjust | null = null;\n /** Current preview patches, reapplied through the public core API on replay; no edit history. */\n private readonly physicsPatches = new Map<string, PhysicsParameterPatch>();\n /** Public read snapshots belonging to a restored seek pose, not the core's private evaluation cache. */\n private heldParameters: ReadonlyMap<string, PhysicsParameterRead> | null = null;\n private slotFilter: SlotFilter | null = null;\n /** `slotFilter` as a predicate; every slot when null. */\n private draws: (slot: string) => boolean = () => true;\n /** Reads the current `adjust` and set ease during live evaluation. */\n private readonly adjustHook: CoreLocalAdjust = (locals, ctx) => this.adjustLocals(locals, ctx, this.easing);\n\n private adjustLocals(locals: Parameters<CoreLocalAdjust>[0], ctx: Parameters<CoreLocalAdjust>[1], easing: SetEase | null): void {\n if (easing !== null) this.applyEase(easing, locals);\n else if (this.drawnPose !== null) for (const [bone, rotation] of this.drawnPose) locals.bone(bone).rotation = rotation;\n if (this.adjustFn !== null) this.adjustFn(locals, ctx);\n }\n\n private readonly listeners = {\n event: new Set<Listener<RigEvent>>(),\n complete: new Set<Listener<RigComplete>>(),\n };\n\n constructor(root: HTMLElement, assets: ModelAssets, options: RigPlayerOptions = {}) {\n const read = assets.document as ReadDocument;\n this.read = read;\n if (options.poser !== undefined && options.poser !== 'auto' && options.poser !== 'oracle') throw new Error(`poser must be auto or oracle, got ${String(options.poser)}`);\n this.oracleOnly = options.poser === 'oracle';\n this.liveChecks = options.liveFrameChecks ?? (import.meta as unknown as { env?: { DEV?: boolean } }).env?.DEV === true;\n this.skinName = options.skin;\n this.view = options.skin === undefined ? underNoSkin(read.doc) : underSkin(read.doc, options.skin);\n this.source = frameSource(this.view, read.parsed);\n this.seekStep = options.seekStep ?? 1 / 60;\n this.trackMode = options.tracks === true;\n if (!(this.seekStep > 0)) throw new Error(`seekStep must be a positive number of seconds, got ${String(options.seekStep)}`);\n this.root = root;\n this.assets = assets;\n this.setList = assets.sets ?? [];\n this.setsByName = new Map(this.setList.map((s) => [s.name, s]));\n this.meshBackend = options.meshBackend;\n this.adjustFn = options.adjust ?? null;\n if (options.slots !== undefined && options.slots !== null) this.slots = options.slots;\n this.poseGeneration = 0;\n this.cachedIdentity = null;\n this.active = this.create(options.mode ?? 'dom');\n this.selectRuntime();\n }\n\n /**\n * How the player draws. Setting it swaps the renderer without reloading\n * anything: the old one is disposed (its elements removed, its GPU pages\n * handed back), the new one is created over the same root and the same\n * assets, `pixelRatio` and `clipping` carry over, and the pose the player\n * holds is drawn again at once.\n */\n get mode(): RenderMode {\n return this.active instanceof CanvasRenderer ? 'canvas' : 'dom';\n }\n\n set mode(mode: RenderMode) {\n if (mode !== 'dom' && mode !== 'canvas') throw new Error(`mode must be 'dom' or 'canvas', got ${String(mode)}`);\n if (mode === this.mode) return;\n const old = this.active;\n const next = this.create(mode);\n next.pixelRatio = old.pixelRatio;\n next.clipping = old.clipping;\n old.dispose();\n this.active = next;\n this.draw();\n }\n\n private create(mode: RenderMode): DomRenderer | CanvasRenderer {\n if (mode === 'canvas') {\n const renderer = new CanvasRenderer(this.root, this.assets.pageImages);\n // The rig's own framing, so the canvas starts at the size the setup pose\n // needs rather than growing into it frame by frame.\n if (this.assets.stage) renderer.reserve(this.assets.stage);\n return renderer;\n }\n if (mode !== 'dom') throw new Error(`mode must be 'dom' or 'canvas', got ${String(mode)}`);\n if (this.assets.regions === 'none') {\n throw new Error(\n \"these assets were loaded with regions: 'none' (no region bitmaps, for the canvas mode only); the DOM mode needs a load with regions 'atlas', 'blob' or 'data'\",\n );\n }\n const renderer = new DomRenderer(this.root, this.assets.regionImages, this.assets.pageImages, this.assets.atlasRegions);\n if (this.meshBackend) renderer.meshBackend = this.meshBackend;\n return renderer;\n }\n\n /** What track 0 plays, or null before `play` and after a `clear` of track 0 has mixed out. */\n get current(): string | null {\n return this.tracks !== null ? (this.tracks.current(0)?.animation ?? null) : this.animation;\n }\n\n /** The player's time — the running sum of the steps since `play` (or the last `seek`). */\n get time(): number {\n return this.runtimeFrames?.pose.trackTime ?? this.tracks?.trackTime ?? this.track?.trackTime ?? 0;\n }\n\n /**\n * Plays `name` on a track — track 0 by default, which is what `play(name)`\n * has always meant: the first `play` opens the tracks at their first pose\n * with the physics reset there, and the pose is drawn on the next `frame`.\n * Later calls replace what the track plays: the entry it replaces mixes out\n * over `mix` seconds (0 cuts), and every entry queued on that track is\n * dropped. The pose the player holds is re-posed at once, so a held player\n * shows the change on its next `draw`. The mixing is the Spine runtime's,\n * which rig-c holds at tolerance 0; an animation keying what the tracks do\n * not mix — a constraint, a sequence, the draw order, a path's deform — is\n * refused here, by name, in the core's words.\n */\n play(name: string, options: PlayOptions = {}): void {\n const track = options.track ?? 0;\n const loop = options.loop ?? true;\n const mix = options.mix ?? 0;\n const alpha = options.alpha ?? 1;\n const additive = options.additive ?? false;\n this.paused = false;\n this.holding = false;\n this.clearSeekCache();\n const plain = track === 0 && mix === 0 && alpha === 1 && !additive;\n if (!plain) this.beyondBase = true;\n if (this.tracks === null && plain && !this.trackMode) {\n if (this.tryRuntimePlay(name, loop)) return;\n this.oracle('animation not supported by the runtime');\n // A plain play on track 0: the single live track, reopened at the\n // animation's first pose with the physics reset there.\n this.animation = name;\n this.loop = loop;\n this.track = openTrack(this.view, name, { loop, reset: 'animation', adjust: this.adjustHook, clock: this.clockHook });\n this.setRawPose(this.initializeSingle(this.track));\n this.applyEnvironment(this.track);\n return;\n }\n const tracks = this.compose();\n tracks.setAnimation(track, name, { loop, mixDuration: mix, alpha, additive });\n this.trackCount = Math.max(this.trackCount, track + 1);\n if (track === 0) {\n this.animation = name;\n this.loop = loop;\n }\n this.setRawPose(tracks.step(0));\n }\n\n /**\n * Queues `name` after the last entry on `track` (`QueueOptions`): with\n * `delay` at or below 0 it starts when that entry completes less its own\n * `mix`, so a one-shot hands over to it across a mix; on an empty track it\n * is set. Before any `play`, the tracks are opened for it.\n */\n queue(name: string, options: QueueOptions = {}): void {\n const track = options.track ?? 0;\n this.beyondBase = true;\n this.clearSeekCache();\n const tracks = this.compose();\n tracks.addAnimation(track, name, { loop: options.loop ?? true, mixDuration: options.mix ?? 0, delay: options.delay ?? 0, alpha: options.alpha ?? 1, additive: options.additive ?? false });\n this.trackCount = Math.max(this.trackCount, track + 1);\n this.setRawPose(tracks.step(0));\n }\n\n /**\n * Mixes `track` out to nothing over `mix` seconds — the layer or one-shot\n * gone and the tracks below showing through. Track 0 cleared shows the\n * setup pose. The pose the player holds is re-posed at once.\n */\n clear(track = 0, options: { mix?: number } = {}): void {\n this.beyondBase = true;\n this.clearSeekCache();\n const tracks = this.compose();\n tracks.setEmptyAnimation(track, options.mix ?? 0);\n this.trackCount = Math.max(this.trackCount, track + 1);\n this.setRawPose(tracks.step(0));\n }\n\n /**\n * Queues a mix out to nothing after the last entry on `track`, over `mix`\n * seconds; with `delay` 0 (the default) the mix ends as that entry\n * completes, so a one-shot queued this way plays once and fades out over\n * its last `mix` seconds.\n */\n queueClear(track = 0, options: { mix?: number; delay?: number } = {}): void {\n this.beyondBase = true;\n this.clearSeekCache();\n const tracks = this.compose();\n tracks.addEmptyAnimation(track, options.mix ?? 0, options.delay ?? 0);\n this.trackCount = Math.max(this.trackCount, track + 1);\n this.setRawPose(tracks.step(0));\n }\n\n /**\n * Sets the weight of `track`'s current entry, from 0 to 1, from the next pose\n * on — the pose the player holds is re-posed at once, so a held player shows\n * it on its next `draw`. An entry it is mixing from keeps its own weight. A\n * track playing nothing, or a weight outside 0..1, is refused in the core's\n * words. On the single track this composes: the player moves onto the tracks.\n */\n setAlpha(track: number, alpha: number): void {\n this.beyondBase = true;\n this.clearSeekCache();\n const tracks = this.compose();\n tracks.setAlpha(track, alpha);\n this.setRawPose(tracks.step(0));\n }\n\n /** `track`'s current entry, or null where it plays nothing (and before `play`). */\n entry(track = 0): TrackEntry | null {\n if (this.runtimeFrames !== null) {\n if (track !== 0 || this.animation === null) return null;\n const pose = this.runtimeFrames.pose;\n return { animation: this.animation, loop: this.loop, trackTime: pose.trackTime, animationTime: pose.time, duration: this.runtimeFrames.model.animation(this.animation).duration, alpha: 1, additive: false };\n }\n if (this.tracks !== null) {\n const view = this.tracks.current(track);\n return view === null\n ? null\n : { animation: view.animation, loop: view.loop, trackTime: view.trackTime, animationTime: view.animationTime, duration: view.duration, alpha: view.alpha, additive: view.additive };\n }\n const single = this.track;\n if (track !== 0 || single === null) return null;\n return { animation: this.animation, loop: this.loop, trackTime: single.trackTime, animationTime: single.animationTime, duration: single.duration, alpha: 1, additive: false };\n }\n\n /** Whether the player is composed: on the live tracks rather than the single track. */\n get composed(): boolean {\n return this.tracks !== null;\n }\n\n /**\n * The live tracks, opened by the first composing call (or by the first\n * `play` under `tracks: true`). A single track in play is carried over by\n * replay: track 0 set to its animation, pose 0 taken by `start()` (the\n * player's — nothing steps before it) and the tracks stepped to the single\n * track's time in `seekStep` increments, so a physics rig's history\n * restarts there and nothing is fired on the way. The core offers no\n * hand-over of a live track's state, so that replay costs one pose per\n * `seekStep` of time played — which `tracks: true` avoids entirely.\n */\n private compose(): LiveTracks {\n this.oracle('track composition');\n if (this.tracks !== null) return this.tracks;\n this.clearSeekCache();\n const tracks = openTracks(this.view, { reset: 'animation', adjust: this.adjustHook, clock: this.clockHook });\n const single = this.track;\n const time = single?.trackTime ?? 0;\n if (single !== null && this.animation !== null) {\n tracks.setAnimation(0, this.animation, { loop: this.loop, mixDuration: 0 });\n this.trackCount = 1;\n }\n this.tracks = tracks;\n this.track = null;\n this.setRawPose(tracks.start());\n this.applyPhysicsParameters(tracks);\n this.applyEnvironment(tracks);\n if (time > 0) this.stepTo(time);\n return tracks;\n }\n\n /** Stores `raw` and applies the shown set (`activeSet`, or before an ease's swap the composition it eases from). Zero work when none. */\n private setRawPose(raw: RawPose, set = this.shownSet()): void {\n const pose = set === null ? raw : applySetToPose(this.view, raw, set);\n this.rawPose = raw;\n this.heldParameters = null;\n this.pose = pose;\n this.poseGeneration++;\n this.cachedIdentity = null;\n }\n\n /**\n * Sets a named physics constraint's pending patch, after keyed/slider values\n * and before the integrator on the next evaluation. No pose or clock change.\n * Unknown names/kinds/fields and non-finite values are refused atomically by\n * the core. Requires a live track (call play/queue first).\n */\n setPhysicsParameters(name: string, patch: PhysicsParameterPatch): void {\n const live = this.requirePhysicsTrack('setPhysicsParameters', name);\n live.setPhysicsParameters(name, patch);\n const standing = live.readPhysicsParameters(name).override;\n if (standing !== null) this.physicsPatches.set(name, standing);\n this.clearSeekCache();\n }\n\n /** Pending override and the held pose's last active evaluation, detached. Does not evaluate a pose. */\n readPhysicsParameters(name: string): PhysicsParameterRead {\n const read = this.requirePhysicsTrack('readPhysicsParameters', name).readPhysicsParameters(name);\n if (this.heldParameters === null) return read;\n const effective = this.heldParameters.get(name)?.effective ?? null;\n return { override: read.override, effective: effective === null ? null : { ...effective } };\n }\n\n /** Removes only the patch; authored values resume next evaluation. Physics history is retained. */\n clearPhysicsParameters(name: string): void {\n this.requirePhysicsTrack('clearPhysicsParameters', name).clearPhysicsParameters(name);\n this.physicsPatches.delete(name);\n this.clearSeekCache();\n }\n\n private requirePhysicsTrack(operation: string, name: string): LiveTrack | LiveTracks {\n const live = this.stepper();\n if (live === null) throw new Error(`${operation}(${JSON.stringify(name)}) before play: no live track`);\n return live;\n }\n\n /** No private parameter state is copied into the core's seek snapshots. */\n private readParameters(live: LiveTrack | LiveTracks): ReadonlyMap<string, PhysicsParameterRead> {\n return new Map(this.view.constraints.filter((c) => c.kind === 'physics')\n .map((c) => [c.name, live.readPhysicsParameters(c.name)]));\n }\n\n private applyPhysicsParameters(live: LiveTrack | LiveTracks): void {\n for (const [name, patch] of this.physicsPatches) live.setPhysicsParameters(name, patch);\n }\n\n /** Like the environment, standing patches are pending after the ordinary first pose; no extra evaluation. */\n private initializeSingle(live: LiveTrack): RawPose {\n this.applyPhysicsParameters(live);\n return live.first;\n }\n\n /**\n * The world the rig's physics answers (#121): `wind` and `gravity`, as\n * spine-core's skeleton-level `windX/windY` and `gravityX/gravityY` — x to\n * the right and **y down**, the runtime's axes — to which each physics\n * constraint's authored `wind` / `gravity` is the response. The runtime's\n * start values are `{ wind: [1, 0], gravity: [0, 1] }`; a player never given\n * one poses exactly as it did without this method. A half left out keeps its\n * standing value, `null` returns both to the start values, and the call\n * applies from the next step on, at any time, with no ramp of the player's\n * own — the springs are the smoothing. It is the player's, not a track's:\n * every track and layer answers the same world, and ordinary replays use the\n * environment as it stands (no history is kept). `seek` accepts a schedule\n * for that replay alone. Returns the environment now standing.\n */\n environment(environment?: Partial<RigEnvironment> | null): RigEnvironment {\n if (environment === null) {\n this.env = null;\n this.clearSeekCache();\n this.stepper()?.setEnvironment(DEFAULT_ENVIRONMENT);\n } else if (environment !== undefined) {\n this.clearSeekCache();\n const live = this.stepper();\n if (live) {\n live.setEnvironment(environment);\n this.env = live.environment;\n } else {\n const base = this.env ?? DEFAULT_ENVIRONMENT;\n this.env = { wind: environment.wind ?? base.wind, gravity: environment.gravity ?? base.gravity };\n }\n }\n return this.stepper()?.environment ?? this.env ?? DEFAULT_ENVIRONMENT;\n }\n\n /**\n * The page moved or turned the whole rig since the last step (#121), in the\n * skeleton's world — units, y up, degrees counter-clockwise — so physics\n * sees it the way spine-core's `Skeleton.physicsTranslate` /\n * `physicsRotate(0, 0, Δ)` make it: a rig dragged across the page trails\n * its cloth. The root element's layout stays the caller's; this tells the\n * physics what the caller did to it (a page-pixel delta divided by the\n * root's scale, its y negated). Applies to the next step; before `play`\n * there is nothing to move.\n */\n moved(motion: { x?: number; y?: number; rotation?: number }): void {\n if (this.runtimeFrames !== null && Number.isFinite(motion.x ?? 0) && Number.isFinite(motion.y ?? 0) && Number.isFinite(motion.rotation ?? 0)) return;\n const live = this.stepper();\n if (!live) return;\n const x = motion.x ?? 0;\n const y = motion.y ?? 0;\n if (x !== 0 || y !== 0) live.physicsTranslate(x, y);\n if (motion.rotation) live.physicsRotate(0, 0, motion.rotation);\n }\n\n /**\n * Extra apparent motion for selected physics, synchronously before evaluation.\n * World distances are X right/Y up; rotation is XY roll around an explicit\n * world pivot, not yaw/pitch. Does not move bones or draw. A step(0), reset,\n * seek/skin replay or track promotion may consume/discard external history.\n * Writes outside the selection are untouched; solver dependencies still apply.\n */\n physicsMoved(scope: PhysicsMotionScope, motion: PhysicsMotion): void {\n const object = (value: unknown, fields: readonly string[], where: string): Record<string, unknown> => {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new Error(`physicsMoved: ${where} must be an object`);\n for (const key of Reflect.ownKeys(value)) if (typeof key !== 'string' || !fields.includes(key)) throw new Error(`physicsMoved: unknown ${where} field ${String(key)}`);\n return value as Record<string, unknown>;\n };\n const finite = (value: unknown, field: string): number => {\n if (typeof value !== 'number' || !Number.isFinite(value)) throw new Error(`physicsMoved: ${field} must be a finite number, got ${String(value)}`);\n return value;\n };\n const selection = object(scope, ['bone', 'subtree', 'constraints'], 'scope');\n const keys = Object.keys(selection);\n if (keys.length !== 1) throw new Error('physicsMoved: scope must name exactly one of bone, subtree, constraints');\n const kind = keys[0];\n let names: string[];\n if (kind === 'constraints') {\n if (!Array.isArray(selection.constraints)) throw new Error('physicsMoved: constraints must be an array of exact physics names');\n names = [];\n for (const name of selection.constraints) {\n if (typeof name !== 'string') throw new Error(`physicsMoved: constraint name ${String(name)} must be a string`);\n const c = this.view.constraints.find((c) => c.kind === 'physics' && c.name === name)\n ?? this.view.constraints.find((c) => c.name === name);\n if (c === undefined) throw new Error(`physicsMoved: no constraint ${JSON.stringify(name)}`);\n if (c.kind !== 'physics') throw new Error(`physicsMoved: constraint ${JSON.stringify(name)} is ${c.kind}, not physics`);\n if (!names.includes(name)) names.push(name);\n }\n } else {\n const name = selection[kind];\n if (typeof name !== 'string' || !this.view.bones.some((b) => b.name === name)) throw new Error(`physicsMoved: no bone ${JSON.stringify(name)}`);\n const parents = new Map(this.view.bones.map((b) => [b.name, b.parent]));\n const includes = (bone: string | undefined): boolean => {\n if (kind === 'bone') return bone === name;\n for (let at = bone; at !== undefined; at = parents.get(at)) if (at === name) return true;\n return false;\n };\n names = this.view.constraints.filter((c) => c.kind === 'physics' && includes((c.record as { bone?: string } | undefined)?.bone)).map((c) => c.name);\n }\n const input = object(motion, ['translation', 'rotation'], 'motion');\n if (Object.keys(input).length !== 1) throw new Error('physicsMoved: motion must name exactly one of translation, rotation');\n let x: number, y: number, degrees: number | undefined;\n if ('translation' in input) {\n const t = object(input.translation, ['x', 'y'], 'translation');\n x = finite(t.x, 'translation.x'); y = finite(t.y, 'translation.y');\n } else {\n const r = object(input.rotation, ['degrees', 'pivot'], 'rotation');\n degrees = finite(r.degrees, 'rotation.degrees');\n if (!Array.isArray(r.pivot) || r.pivot.length !== 2) throw new Error('physicsMoved: rotation.pivot must be two finite world coordinates');\n x = finite(r.pivot[0], 'rotation.pivot[0]'); y = finite(r.pivot[1], 'rotation.pivot[1]');\n }\n // Validate even zero/before-play calls, then preserve the exact no-op path.\n if (names.length === 0 || (degrees === undefined ? x === 0 && y === 0 : degrees === 0)) return;\n const live = this.stepper();\n if (live === null) return;\n if (degrees === undefined) live.physicsTranslate(x, y, names);\n else live.physicsRotate(x, y, degrees, names);\n this.clearSeekCache();\n }\n\n /** Stops stepping; `frame` keeps drawing the pose it holds. */\n pause(): void {\n this.paused = true;\n }\n\n /** Resumes stepping after `pause`. */\n resume(): void {\n this.paused = false;\n }\n\n /**\n * Holds the track time while the physics keeps running (#248). While held,\n * `advance(dt)` and `frame(dt)` move the physics clock by `dt × timeScale`\n * (on rig-c's render clock, as a plain step does) and re-pose at the\n * **same** track time: every animation timeline — bone keys, slot colour,\n * attachments, deform, draw order — reads what it read, and only what the\n * physics drives moves, so a rig settles and stays alive on a held frame.\n * No event or complete fires, `time` stands, and an eased set switch holds\n * where it is. `hold(false)` releases it: the next step continues from the\n * physics state the held steps left, with no reset. A rig with no physics\n * constraint ignores held steps outright — nothing is re-posed. `pause()`\n * still stops everything, held or not; `play` releases the hold, as it\n * releases a pause; `seek` keeps it, and replays the time as it always does.\n */\n hold(on = true): void {\n if (on !== true && on !== false) throw new Error(`hold expects true or false, got ${JSON.stringify(on)}`);\n const releasing = this.holding && !on;\n this.holding = on;\n // The planted control replays the time on release, the way a seek-based workaround would.\n if (releasing && this.heldPlant === 'reset' && this.animation !== null && this.runtimeFrames === null && !this.beyondBase) this.seek(this.time);\n }\n\n /** Whether `hold(true)` is in force. */\n get held(): boolean {\n return this.holding;\n }\n\n /** One held step (`hold`): the open track or tracks stepped by 0 while their physics clock moves by `step`. */\n private heldStep(step: number): void {\n if (!Number.isFinite(step)) throw new Error(`advance step must be finite, got ${String(step)}`);\n if (this.heldPlant === 'freeze') return;\n if (!this.view.constraints.some((constraint) => constraint.kind === 'physics')) return;\n const live = this.tracks ?? this.track;\n if (live === null) return;\n this.heldClockStep = step;\n let raw: RawPose;\n try {\n raw = live.step(0);\n } finally {\n this.heldClockStep = null;\n }\n this.setRawPose(raw);\n }\n\n /**\n * Moves a single animation on track 0 to `time` with the pose and physics\n * state of reopening at 0 and stepping in `seekStep` increments (the last\n * one can be shorter). Ordinary seeks reuse snapshots (#141). Events and\n * completes crossed on the way are not fired.\n * It has a meaning for one animation on one track only — the player cannot\n * replay when a mix, a second track or a queue was asked for — so after any\n * of those it refuses by name; step the player forward instead.\n * On the oracle, `environmentAt` runs an uncached replay and supplies wind\n * and gravity at the start of each positive step, including a shorter last\n * step. On success the resulting physics state continues under the standing\n * environment. A failed replay leaves the held state in place. The runtime\n * poser seeks as usual and does not call `environmentAt`.\n */\n seek(time: number, environmentAt?: RigEnvironmentSchedule): void {\n if (this.animation === null) throw new Error('seek before play: no animation is open');\n if (!(time >= 0) || !Number.isFinite(time)) throw new Error(`seek time must be a finite time at or above 0, got ${String(time)}`);\n if (this.beyondBase) throw new Error('seek is defined for a single animation on track 0; after a mix, another track, a queue or a clear the player cannot replay to a time — step it forward with frame/advance instead');\n if (this.runtimeFrames !== null) {\n // Keep the documented replay clock, including floating-point accumulation.\n // A direct jump to `time` can differ from the old seek's last pose by ulps.\n const steps = Math.floor(time / this.seekStep);\n let replayTime = 0;\n for (let i = 0; i < steps; i++) replayTime += this.seekStep;\n const rest = time - replayTime;\n if (rest > 0) replayTime += rest;\n this.runtimeFrames.pose.trackTime = replayTime;\n this.applyRuntimeTime();\n return;\n }\n if (environmentAt !== undefined) {\n this.seekWithEnvironment(time, environmentAt);\n return;\n }\n // A replay has no history to ease through: an eased switch in flight lands at once.\n this.easing = null;\n const cache = this.ensureSeekCache();\n const stepper = this.tracks ?? (this.track as LiveTrack);\n const exactHit = cache.exact.get(time);\n if (exactHit !== undefined) {\n restoreStepperState(stepper, exactHit.state);\n this.rawPose = exactHit.rawPose;\n this.pose = exactHit.pose;\n this.heldParameters = exactHit.parameters;\n this.poseGeneration++;\n this.cachedIdentity = null;\n return;\n }\n const steps = Math.floor(time / this.seekStep);\n while (cache.frontierSteps < steps) {\n const raw = cache.frontier.step(this.seekStep);\n cache.frontierSteps++;\n if (cache.frontierSteps <= SEEK_FINE_STEP_LIMIT || cache.frontierSteps % SEEK_COARSE_STRIDE === 0) {\n cache.grid.set(cache.frontierSteps, {\n state: captureStepperState(cache.frontier),\n rawPose: raw,\n parameters: this.readParameters(cache.frontier),\n });\n }\n }\n let parameters: ReadonlyMap<string, PhysicsParameterRead>;\n const gridHit = cache.grid.get(steps);\n if (gridHit !== undefined) {\n restoreStepperState(stepper, gridHit.state);\n this.rawPose = gridHit.rawPose;\n parameters = gridHit.parameters;\n } else {\n const baseStep = steps - (steps % SEEK_COARSE_STRIDE);\n const baseSnap = cache.grid.get(baseStep) as SeekGridEntry;\n restoreStepperState(stepper, baseSnap.state);\n this.rawPose = baseSnap.rawPose;\n for (let i = baseStep; i < steps; i++) this.rawPose = stepper.step(this.seekStep);\n parameters = this.readParameters(stepper);\n }\n const rest = time - stepper.trackTime;\n if (rest > 0) {\n this.rawPose = stepper.step(rest);\n parameters = this.readParameters(stepper);\n }\n if (this.rawPose !== null) this.setRawPose(this.rawPose);\n this.heldParameters = parameters;\n if (this.rawPose !== null && this.pose !== null) {\n if (cache.exact.size >= SEEK_EXACT_LIMIT) {\n const oldest = cache.exact.keys().next().value;\n if (oldest !== undefined) cache.exact.delete(oldest);\n }\n cache.exact.set(time, {\n state: captureStepperState(stepper),\n rawPose: this.rawPose,\n pose: this.pose,\n parameters,\n });\n }\n }\n\n private seekWithEnvironment(time: number, environmentAt: RigEnvironmentSchedule): void {\n // Replay with the active set's final locals. Once published, the same track\n // must also support new eases during live playback.\n let replaying = true;\n const { stepper, firstPose } = this.openReplay((locals, ctx) => this.adjustLocals(locals, ctx, replaying ? null : this.easing));\n const standing = stepper.environment;\n let rawPose = firstPose;\n this.replaySteps(stepper, time, (dt) => {\n stepper.setEnvironment(environmentAt(stepper.trackTime));\n rawPose = stepper.step(dt);\n });\n // A refused stepper cannot accept setEnvironment. Restore only after a\n // successful replay, then publish the pose and the integrated state.\n stepper.setEnvironment(standing);\n this.setRawPose(rawPose, this.activeSet);\n this.easing = null;\n replaying = false;\n if ('first' in stepper) this.track = stepper;\n else this.tracks = stepper;\n }\n\n private clearSeekCache(): void {\n this.seekCache = null;\n }\n\n private ensureSeekCache(): SeekCache {\n const mode = this.tracks !== null ? 'tracks' : 'track';\n if (this.seekCache !== null && this.seekCache.mode === mode) {\n return this.seekCache;\n }\n if (this.tracks === null && this.track === null) {\n this.reopen();\n }\n const { stepper: frontier, firstPose } = this.openReplay();\n const grid = new Map<number, SeekGridEntry>();\n grid.set(0, { state: captureStepperState(frontier), rawPose: firstPose, parameters: this.readParameters(frontier) });\n this.seekCache = {\n mode,\n frontier,\n frontierSteps: 0,\n grid,\n exact: new Map<number, SeekExactEntry>(),\n };\n return this.seekCache;\n }\n\n /** Opens a separate stepper at pose 0 for a seek, without publishing it. */\n private openReplay(adjust = this.adjustHook): { stepper: LiveTrack | LiveTracks; firstPose: RawPose } {\n if (this.tracks !== null) {\n const tracks = openTracks(this.view, { reset: 'animation', adjust, clock: this.clockHook });\n tracks.setAnimation(0, this.animation as string, { loop: this.loop, mixDuration: 0 });\n const firstPose = tracks.start();\n this.applyPhysicsParameters(tracks);\n this.applyEnvironment(tracks);\n return { stepper: tracks, firstPose };\n }\n const track = openTrack(this.view, this.animation as string, { loop: this.loop, reset: 'animation', adjust, clock: this.clockHook });\n const firstPose = this.initializeSingle(track);\n this.applyEnvironment(track);\n return { stepper: track, firstPose };\n }\n\n /** Whatever is open, opened again with track 0's animation as `play` last set it, at pose 0: the single track, or the tracks under `tracks: true`. */\n private reopen(): void {\n if (this.tracks !== null) {\n const tracks = openTracks(this.view, { reset: 'animation', adjust: this.adjustHook, clock: this.clockHook });\n tracks.setAnimation(0, this.animation as string, { loop: this.loop, mixDuration: 0 });\n this.trackCount = 1;\n this.tracks = tracks;\n this.setRawPose(tracks.start());\n this.applyPhysicsParameters(tracks);\n this.applyEnvironment(tracks);\n return;\n }\n this.track = openTrack(this.view, this.animation as string, { loop: this.loop, reset: 'animation', adjust: this.adjustHook, clock: this.clockHook });\n this.setRawPose(this.initializeSingle(this.track));\n this.applyEnvironment(this.track);\n }\n\n /** What is open: the tracks, the single track, or nothing before `play`. */\n private stepper(): LiveTrack | LiveTracks | null {\n this.oracle('oracle track operation');\n return this.tracks ?? this.track;\n }\n\n /** A newly opened track or tracks answer the environment the player stands in; one never set leaves it untouched. */\n private applyEnvironment(live: LiveTrack | LiveTracks): void {\n if (this.env !== null) live.setEnvironment(this.env);\n }\n\n /** Steps whatever is open forward to `time` in `seekStep` increments, the last one shorter. */\n private stepTo(time: number): void {\n const stepper = this.tracks ?? (this.track as LiveTrack);\n this.replaySteps(stepper, time, (dt) => { this.rawPose = stepper.step(dt); });\n if (this.rawPose !== null) this.setRawPose(this.rawPose);\n }\n\n private replaySteps(stepper: LiveTrack | LiveTracks, time: number, step: (dt: number) => void): void {\n const steps = Math.floor(time / this.seekStep);\n for (let i = 0; i < steps; i++) step(this.seekStep);\n const rest = time - stepper.trackTime;\n if (rest > 0) step(rest);\n }\n\n /** Adds a listener; returns a function that removes it. */\n on(type: 'event', listener: Listener<RigEvent>): () => void;\n on(type: 'complete', listener: Listener<RigComplete>): () => void;\n on(type: 'event' | 'complete', listener: Listener<never>): () => void {\n const set = this.listeners[type] as Set<Listener<never>>;\n set.add(listener);\n return () => set.delete(listener);\n }\n\n /**\n * Advances the track by `dt × timeScale` seconds and draws the pose —\n * `advance(dt)` then `draw()`.\n */\n frame(dt: number): void {\n this.advance(dt);\n this.draw();\n }\n\n /**\n * Steps the track by `dt × timeScale` seconds and fires the step's listeners,\n * without drawing. A paused player, or a step of zero, keeps the pose it\n * holds without re-posing it, so a held rig costs the renderer's dirty\n * checks and nothing else. The physics clock moves by `physicsClockStep`\n * of the step — the step and 2⁻³⁰ of it more, rig-c's render clock — so a\n * caller stepping at a fixed rate whose frame is a whole number of physics\n * steps (`frame(1/60)`, a capture) shows no spring jump; the animation time,\n * the events and `time` stay on the steps themselves (#103).\n */\n advance(dt: number): void {\n if (this.runtimeFrames !== null) {\n const step = dt * this.timeScale;\n if (this.paused || !(step > 0)) return;\n if (!Number.isFinite(step)) throw new Error(`advance step must be finite, got ${String(step)}`);\n // The runtime poser carries no physics constraint, so a held step has nothing to move.\n if (this.holding && this.heldPlant !== 'advance') return;\n const before = this.runtimeFrames.pose.trackTime;\n const duration = this.runtimeFrames.model.animations.get(this.animation as string)!.duration;\n this.runtimeFrames.pose.trackTime += step;\n this.lastStep = step;\n this.applyRuntimeTime();\n const completionClock = this.runtimeCompletionClock;\n if (this.listeners.event.size > 0) {\n // A listener may play/seek/advance again, overwriting the borrowed list.\n // Preserve this delivery batch exactly as the oracle's detached rows do.\n const events = this.runtimeFrames.pose.events.slice();\n for (const key of events) {\n const payload: RigEvent = { name: key.name, time: key.time, int: key.int, float: key.float, string: key.string, track: 0 };\n for (const listener of this.listeners.event) listener(payload);\n }\n }\n if (this.listeners.complete.size > 0) {\n // Retain this play entry, as dispatchSingle retains its LiveTrack.\n // seek/advance inside delivery changes its clock; play replaces it.\n const after = completionClock.trackTime;\n const complete = this.loop ? (duration === 0 || Math.floor(after / duration) > Math.floor(before / duration)) : before < duration && after >= duration;\n if (complete) {\n const payload: RigComplete = { animation: this.animation as string, track: 0 };\n for (const listener of this.listeners.complete) listener(payload);\n }\n }\n return;\n }\n if (this.pose === null) return;\n const step = dt * this.timeScale;\n if (this.paused || !(step > 0)) return;\n if (this.holding && this.heldPlant !== 'advance') {\n this.heldStep(step);\n return;\n }\n this.lastStep = step;\n if (this.easing !== null) this.advanceEase(this.easing, step);\n const tracks = this.tracks;\n if (tracks !== null) {\n const before: Array<TrackEntryView | null> = [];\n for (let t = 0; t < this.trackCount; t++) before.push(tracks.current(t));\n const raw = tracks.step(step);\n this.setRawPose(raw);\n this.dispatch(raw, before, tracks);\n return;\n }\n const track = this.track;\n if (track === null) return;\n const before = track.trackTime;\n const raw = track.step(step);\n this.setRawPose(raw);\n this.dispatchSingle(raw, before, track);\n }\n\n /** Draws the pose the player holds. */\n draw(): void {\n if (this.runtimeFrames !== null) {\n this.runtimeFrames.update(this.poseGeneration, this.color, this.draws, false);\n this.renderer.render(this.runtimeFrames.live);\n return;\n }\n if (this.pose === null) return;\n this.renderer.render(this.posedFrame());\n }\n\n /**\n * The skin the rig is posed under — `RigPlayerOptions.skin`, or undefined\n * for no skin set. Setting it re-resolves the pose under the new skin\n * (which attachment each slot shows, which bones and constraints are\n * active) and keeps the animation, its loop and its track time: the track\n * is reopened under the new skin and stepped to the same time the way\n * `seek` does, so a physics rig's history restarts there and nothing is\n * fired on the way. The pose is drawn on the next `draw`/`frame`. An\n * unknown skin is refused by name, and the player is left as it was.\n */\n get skin(): string | undefined {\n return this.skinName;\n }\n\n set skin(name: string | undefined) {\n if (name === this.skinName) return;\n if (this.beyondBase) throw new Error('skin cannot change after a mix, another track, a queue or a clear: the player cannot replay those to the current time — set it before composing, or play again');\n const view = name === undefined ? underNoSkin(this.read.doc) : underSkin(this.read.doc, name);\n this.oracle('skin change');\n this.view = view;\n this.source = frameSource(view, this.read.parsed);\n this.selectRuntime();\n this.skinName = name;\n this.setup = null;\n this.easing = null;\n this.clearSeekCache();\n if (this.animation !== null && (this.track !== null || this.tracks !== null)) {\n const time = this.time;\n const animation = this.animation;\n const animationTime = this.entry(0)!.animationTime;\n if (this.tryRuntimePlay(animation, this.loop)) {\n const frames = this.runtimeFrames!;\n frames.pose.restore(animation, time, animationTime);\n this.poseGeneration++;\n this.cachedIdentity = null;\n this.runtimeReadback = null;\n frames.update(this.poseGeneration, this.color, this.draws);\n return;\n }\n this.reopen();\n this.stepTo(time);\n } else if (this.rawPose !== null) {\n this.setRawPose(this.drawnSetup());\n } else {\n this.poseGeneration++;\n this.cachedIdentity = null;\n }\n }\n\n /**\n * The named attachment sets declared in `sets.json` (`ModelAssets.sets`),\n * with the slots each covers (`slots`) and hides (`hides`). Empty (`[]`)\n * when the build has no `sets.json`.\n */\n sets(): readonly RigSet[] {\n return this.setList;\n }\n\n /**\n * The active attachment set's name when exactly one is active; `null` when\n * the base attachments are active or when several sets are (read\n * `activeSets` for the list).\n */\n get set(): string | null {\n return this.activeList.length === 1 ? this.activeList[0].name : null;\n }\n\n /** Every active attachment set's name, in `sets.json` declaration order (`[]` when none). */\n get activeSets(): readonly string[] {\n return this.activeList.map((s) => s.name);\n }\n\n /**\n * Switches the active attachment set (#134): every slot the set covers takes\n * the set's attachment (`null` restores the base / track attachments), and\n * every slot the set `hides` (plus any `<base>_still` slot of a covered or\n * hidden base slot) is hidden. Applied immediately to the pose the player\n * holds (including the setup pose before `play`) and after track evaluation\n * on every subsequent `advance`, so a track key on a covered slot is\n * overridden while the set is active and restored when cleared (`setSet(null)`).\n * Uncovered slots keep their track attachments, mesh deforms and sequence\n * frames untouched; when no set is active (`null`), track evaluation runs\n * with zero overhead and produces byte-identical poses.\n *\n * A set with `drawn` (#170) also poses its bones at those world angles, as\n * `@rig-c/parts check --set` does, replacing a clip's rotation of them.\n *\n * `setSet(name)` means exactly this one set: any other active sets are\n * cleared (`setSets([name])`), and `setSet(null)` is `setSets([])`.\n *\n * A name not in `sets.json` throws by name; a build without `sets.json` has\n * `sets()` empty and `setSet` throws.\n */\n setSet(name: string | null, options?: SetActivationOptions): void {\n if (this.setList.length === 0) {\n throw new Error(`cannot setSet(${JSON.stringify(name)}): this model has no sets.json`);\n }\n const physics = setPhysicsOption('setSet', options);\n const ease = setEaseOption('setSet', options);\n this.activate(name === null ? [] : [this.namedSet(name)], physics, ease);\n }\n\n /**\n * Makes exactly `names` the active attachment sets (#168), together: each\n * set covers and hides its slots as it does alone, provided no two of them\n * touch the same slot (cover it, hide it, or hide it as a `<base>_still`\n * companion). Composition does not depend on the order of `names`. An\n * unknown name, a repeated name or two sets touching one slot throw by name\n * and leave the active sets as they were; `[]` restores the base.\n *\n * `options.physics` (#173) decides what a switch that re-poses `drawn` bones\n * does to the physics constraints hung under them — on a bone whose drawn\n * rotation this call adds, removes or changes, or on a descendant of one:\n * `'carry'` moves each one's remembered state (where its bone was and\n * pointed) by the rigid turn of its deepest re-posed ancestor, so the chain\n * keeps its pose relative to the bone; `'reset'` restarts each one at the\n * new pose, as a physics `reset` key does. Absent, the constraints read the\n * jump as motion and kick, as they always have. Anything else throws before\n * anything changes. Nothing to do before `play` or when no physics hangs\n * under a re-posed bone. A later `seek` replays from the start with the sets\n * then active and does not reproduce a carried switch. `setSet`, `addSet`\n * and `removeSet` take the same option.\n *\n * `options.ease` (#174, seconds, a finite number at or above 0) eases the\n * bones the call re-poses instead of snapping them. Each bone whose drawn\n * rotation the call adds, removes or changes turns from what it shows to\n * its new local rotation along the shorter way, as\n * `start + shortestΔ(start, end) · smoothstep(elapsed / ease)`: going on,\n * from the clip's value at the time to the drawn local; going off, from the\n * drawn local to the clip's value. The attachments the pose draws stay the\n * previous ones until the frame whose `elapsed / ease` is nearest ½ (the\n * next step predicted from the current one; a tie goes to the later frame),\n * then become the call's; `activeSets` and `slotIdentity().sets` name the\n * call's sets at once, while `slotIdentity().slots` follows what is drawn.\n * On the frame the elapsed time reaches `ease` the player is in exactly the\n * instant switch's state. The elapsed time is the player's step\n * (`dt × timeScale`), so a paused player or a zero step holds the ease;\n * before `play`, or when no bone's rotation changes, the switch is instant.\n * A call during an ease eases again from the angles shown (a call without\n * `ease` lands it at once), and `seek` or a skin change lands it at once.\n * With `physics: 'carry'` the chains under the eased bones are carried on\n * every eased frame, by the turn that frame's blend makes; with `'reset'`\n * they restart once, at the call. `0` or absent is the instant switch on\n * the same code path; anything else throws by name before anything changes.\n */\n setSets(names: readonly string[], options?: SetActivationOptions): void {\n if (this.setList.length === 0) {\n throw new Error(`cannot setSets(${JSON.stringify(names)}): this model has no sets.json`);\n }\n const physics = setPhysicsOption('setSets', options);\n const ease = setEaseOption('setSets', options);\n const sets = names.map((name) => this.namedSet(name));\n for (let i = 0; i < sets.length; i++) {\n for (let j = 0; j < i; j++) {\n if (sets[i] === sets[j]) throw new Error(`set ${JSON.stringify(sets[i].name)} is named twice in setSets`);\n }\n }\n this.activate(sets, physics, ease);\n }\n\n /**\n * Activates `name` beside the sets already active (#168): a set already\n * active is left as it is; one touching a slot an active set touches throws\n * by name (the slot and both sets) and changes nothing.\n */\n addSet(name: string, options?: SetActivationOptions): void {\n if (this.setList.length === 0) {\n throw new Error(`cannot addSet(${JSON.stringify(name)}): this model has no sets.json`);\n }\n const physics = setPhysicsOption('addSet', options);\n const ease = setEaseOption('addSet', options);\n const found = this.namedSet(name);\n if (this.activeList.includes(found)) return;\n this.activate([...this.activeList, found], physics, ease);\n }\n\n /**\n * Deactivates `name`, keeping every other active set (#168). An unknown name\n * throws by name; a set that is not active is left as it is.\n */\n removeSet(name: string, options?: SetActivationOptions): void {\n if (this.setList.length === 0) {\n throw new Error(`cannot removeSet(${JSON.stringify(name)}): this model has no sets.json`);\n }\n const physics = setPhysicsOption('removeSet', options);\n const ease = setEaseOption('removeSet', options);\n const found = this.namedSet(name);\n if (!this.activeList.includes(found)) return;\n this.activate(this.activeList.filter((s) => s !== found), physics, ease);\n }\n\n /** The declared set named `name`, or a throw naming it and the available sets. */\n private namedSet(name: string): RigSet {\n const found = this.setsByName.get(name);\n if (found === undefined) {\n throw new Error(\n `no set named ${JSON.stringify(name)} in sets.json (available: ${this.setList.map((s) => s.name).join(', ')})`,\n );\n }\n return found;\n }\n\n /**\n * Poses again after the drawn bones changed (#170): through the tracks at\n * the same time when the player has played, else the setup pose with the\n * drawn bones at their rotations.\n */\n private reposeDrawn(): void {\n const stepper = this.tracks ?? this.track;\n if (stepper !== null && this.pose !== null) {\n this.setRawPose(stepper.step(0));\n return;\n }\n this.setRawPose(this.drawnSetup());\n }\n\n /** The setup pose with the active sets' drawn bones at their rotations (#170); the plain setup pose when none draws. */\n private drawnSetup(): RawPose {\n const setup = this.setup ?? (this.setup = poseRawSetup(this.view));\n if (this.drawnPose === null) return setup;\n return poseRawSetup({\n ...this.view,\n bones: this.view.bones.map((b) => {\n const rotation = this.drawnPose?.get(b.name);\n return rotation === undefined ? b : { ...b, rotation };\n }),\n });\n }\n\n /** The slots `set` touches, computed once per set. */\n private touched(set: RigSet): ReadonlySet<string> {\n let touched = this.touchedSets.get(set.name);\n if (touched === undefined) {\n touched = touchedBySet(this.view, set);\n this.touchedSets.set(set.name, touched);\n }\n return touched;\n }\n\n /**\n * The physics under the bones a set switch re-poses (#173), before the\n * repose step: the `changed` bones' rotations went from what the held pose\n * shows to what the player now applies (`drawnPose`, or an ease's next\n * blend, #174), and every physics constraint whose bone is one of the\n * changed bones or a descendant of one is carried or reset. Nothing to do\n * before `play` (the setup pose carries no physics state) or when no\n * constraint hangs under a changed bone.\n */\n private handOverPhysics(changed: ReadonlySet<string>, mode: 'carry' | 'reset'): void {\n const stepper = this.tracks ?? this.track;\n if (stepper === null || this.pose === null || this.rawPose === null) return;\n if (changed.size === 0) return;\n const parentOf = new Map(this.view.bones.map((b) => [b.name, b.parent]));\n /** The deepest changed bone on the way from `bone` to the root (itself included). */\n const anchorOf = (bone: string): string | undefined => {\n for (let b: string | undefined = bone; b !== undefined; b = parentOf.get(b)) if (changed.has(b)) return b;\n return undefined;\n };\n const ctx = physicsContextOf(stepper);\n const affected: Array<{ name: string; anchor: string }> = [];\n for (const c of this.view.constraints) {\n if (c.kind !== 'physics') continue;\n const bone = (c.record as { bone?: string } | undefined)?.bone;\n const anchor = bone === undefined ? undefined : anchorOf(bone);\n if (anchor === undefined) continue;\n const state = ctx.states.get(c.name);\n // A constraint not updated yet, or pending, takes its bone as it finds it on its next update.\n if (state === undefined || state.pending) continue;\n affected.push({ name: c.name, anchor });\n }\n if (affected.length === 0) return;\n if (mode === 'reset') {\n for (const { name } of affected) {\n const s = ctx.states.get(name) as PhysicsStateInternal;\n s.remaining = 0;\n s.lastTime = ctx.time;\n s.pending = true;\n s.xOffset = s.xLag = s.xVelocity = 0;\n s.yOffset = s.yLag = s.yVelocity = 0;\n s.rotateOffset = s.rotateLag = s.rotateVelocity = 0;\n s.scaleOffset = s.scaleLag = s.scaleVelocity = 0;\n }\n return;\n }\n // carry: W_old from the held pose, W_new from a trial step(0) under the new drawn rotations, undone.\n const anchors = new Set(affected.map((a) => a.anchor));\n const worlds = (pose: RawPose): Map<string, RawPose['bones'][number]> => {\n const out = new Map<string, RawPose['bones'][number]>();\n for (const b of pose.bones) if (anchors.has(b.name)) out.set(b.name, b);\n return out;\n };\n const old = worlds(this.rawPose);\n const snapshot = captureStepperState(stepper);\n const now = worlds(stepper.step(0));\n // The restore puts copies back: the states are read again by name below.\n restoreStepperState(stepper, snapshot);\n const maps = new Map<string, readonly [number, number, number, number, number, number]>();\n for (const anchor of anchors) {\n const o = old.get(anchor);\n const n = now.get(anchor);\n if (o === undefined || n === undefined) continue;\n if (this.carryPlant) {\n maps.set(anchor, [1, 0, 0, 1, 0, 0]);\n continue;\n }\n // M = W_new ∘ W_old⁻¹, as [a, b, c, d, x, y].\n const det = o.a * o.d - o.b * o.c;\n // A zero-scale anchor has no inverse: its chains are left as they are, as without the option, rather than written NaN.\n if (!Number.isFinite(det) || det === 0) continue;\n const ia = o.d / det;\n const ib = -o.b / det;\n const ic = -o.c / det;\n const id = o.a / det;\n const a = n.a * ia + n.b * ic;\n const b = n.a * ib + n.b * id;\n const c = n.c * ia + n.d * ic;\n const d = n.c * ib + n.d * id;\n maps.set(anchor, [a, b, c, d, n.worldX - (a * o.worldX + b * o.worldY), n.worldY - (c * o.worldX + d * o.worldY)]);\n }\n const states = physicsContextOf(stepper).states;\n for (const { name, anchor } of affected) {\n const m = maps.get(anchor);\n const s = states.get(name);\n if (m === undefined || s === undefined) continue;\n const [a, b, c, d, x, y] = m;\n const ux = s.ux;\n s.ux = a * ux + b * s.uy + x;\n s.uy = c * ux + d * s.uy + y;\n const cx = s.cx;\n s.cx = a * cx + b * s.cy + x;\n s.cy = c * cx + d * s.cy + y;\n const tx = s.tx;\n s.tx = a * tx + b * s.ty;\n s.ty = c * tx + d * s.ty;\n }\n }\n\n /**\n * The composition the held pose draws: `activeSet`, except before an ease's\n * swap (#174), when it is the composition the ease started from.\n */\n private shownSet(): RigSet | null {\n const easing = this.easing;\n return easing === null || easing.swapped ? this.activeSet : easing.fromSet;\n }\n\n /** The local an eased bone shows at the ease's current progress, given the clip's local `clip`. */\n private easedLocal(easing: SetEase, from: number | null, to: number | null, clip: number): number {\n const start = from ?? clip;\n const end = to ?? clip;\n const u = easeProgress(easing);\n const w = this.easePlant === 'overshoot' ? (u < 1 ? 1.2 * u : 1) : smoothstep(u);\n return start + normaliseDegrees(end - start) * w;\n }\n\n /**\n * The ease's part of `adjustHook` (#174): every drawn bone the ease does not\n * turn takes its drawn local, as without an ease; every eased bone reads\n * the clip's local (what the timelines left) and then takes its blend.\n */\n private applyEase(easing: SetEase, locals: Parameters<CoreLocalAdjust>[0]): void {\n for (const bone of easing.bones.keys()) easing.clip.set(bone, locals.bone(bone).rotation);\n if (this.drawnPose !== null) {\n for (const [bone, rotation] of this.drawnPose) if (!easing.bones.has(bone)) locals.bone(bone).rotation = rotation;\n }\n for (const [bone, { from, to }] of easing.bones) {\n locals.bone(bone).rotation = this.easedLocal(easing, from, to, easing.clip.get(bone) as number);\n }\n }\n\n /**\n * Starts an eased switch (#174) to the sets already made active, from what\n * the held pose shows: an eased bone's start is the local it shows (fixed),\n * or the clip's value for a bone that showed the clip's; its end is the new\n * drawn local, or the clip's value for a bone whose set went. Returns false,\n * changing nothing, when there is nothing to ease — before `play` (no step\n * to ease over) or when no bone's rotation changes — and the call is then\n * an instant one.\n */\n private startEase(duration: number, shownBefore: RigSet | null, drawn: Readonly<Record<string, number>> | undefined, physics: 'carry' | 'reset' | undefined): boolean {\n const stepper = this.tracks ?? this.track;\n if (stepper === null || this.pose === null) return false;\n const before = this.drawnPose;\n const after = drawn === undefined ? null : drawnLocals(this.view, drawn);\n const previous = this.easing;\n const candidates = drawnChanged(before, after);\n if (previous !== null) for (const bone of previous.bones.keys()) candidates.add(bone);\n const bones = new Map<string, { from: number | null; to: number | null }>();\n for (const bone of candidates) {\n const to = after?.get(bone) ?? null;\n let from: number | null;\n const eased = previous?.bones.get(bone);\n if (previous !== null && eased !== undefined) {\n // Mid-ease: what it shows now. At u = 0 that is the previous start, the clip's value included.\n from = previous.elapsed > 0 ? this.easedLocal(previous, eased.from, eased.to, previous.clip.get(bone) as number) : eased.from;\n } else {\n from = before?.get(bone) ?? null;\n }\n if (from === to) continue;\n bones.set(bone, { from, to });\n }\n if (bones.size === 0) return false;\n const easing: SetEase = {\n duration,\n elapsed: 0,\n bones,\n clip: new Map(),\n fromSet: shownBefore,\n swapped: false,\n physics,\n };\n // The call's own pose is u = 0; it is the swap frame only when the next step, predicted by the last one, passes farther from ½.\n if (this.easePlant === 'swap-at-0' || this.swapsNow(0, this.lastStep / duration)) easing.swapped = true;\n this.easing = easing;\n this.drawnPose = after;\n // `reset` restarts the chains under the eased bones once, at the start; `carry` runs on every eased frame (`advanceEase`).\n if (physics === 'reset') this.handOverPhysics(new Set(bones.keys()), 'reset');\n this.reposeDrawn();\n return true;\n }\n\n /**\n * Whether the frame at progress `u` is the one nearest ½, the next frame\n * being at `next`: it is when `u` reached ½ or the next one would be\n * farther from it; a tie (within 1e-9) goes to the later frame.\n */\n private swapsNow(u: number, next: number): boolean {\n if (u >= 0.5) return true;\n return next > u && 0.5 - u < next - 0.5 - 1e-9;\n }\n\n /**\n * One step of an eased switch (#174), before the track steps: the elapsed\n * time advances by the step, the attachments swap when this is the frame\n * nearest ½ (`swapsNow`, the next step predicted by this one), and the\n * ease ends — the instant switch's state, `drawnPose` alone — on the frame\n * it reaches its duration. With `physics: 'carry'`, the chains under the\n * eased bones are carried by the turn this frame's blend makes, read by a\n * trial `step(0)` at the previous time (`handOverPhysics`).\n */\n private advanceEase(easing: SetEase, step: number): void {\n easing.elapsed += step;\n if (easing.elapsed >= easing.duration) this.easing = null;\n else if (!easing.swapped && this.swapsNow(easing.elapsed / easing.duration, (easing.elapsed + step) / easing.duration)) easing.swapped = true;\n if (easing.physics === 'carry') this.handOverPhysics(new Set(easing.bones.keys()), 'carry');\n }\n\n /**\n * Makes `sets` (distinct) the active sets: refuses any two touching one slot\n * before changing anything, then applies their composition to the held pose.\n */\n private activate(sets: readonly RigSet[], physics?: 'carry' | 'reset', ease = 0): void {\n this.oracle('attachment sets');\n for (let i = 0; i < sets.length; i++) {\n for (let j = 0; j < i; j++) {\n const other = this.touched(sets[j]);\n for (const slot of this.touched(sets[i])) {\n if (other.has(slot)) {\n throw new Error(\n `sets ${JSON.stringify(sets[j].name)} and ${JSON.stringify(sets[i].name)} both touch slot ${JSON.stringify(slot)}; ` +\n 'active sets must cover and hide disjoint slots',\n );\n }\n }\n const otherDrawn = sets[j].drawn;\n for (const bone of Object.keys(sets[i].drawn ?? {})) {\n if (otherDrawn !== undefined && bone in otherDrawn) {\n throw new Error(\n `sets ${JSON.stringify(sets[j].name)} and ${JSON.stringify(sets[i].name)} both pose bone ${JSON.stringify(bone)}; ` +\n 'active sets must draw disjoint bones',\n );\n }\n }\n }\n }\n const drawnBefore = this.activeSet?.drawn;\n const shownBefore = this.shownSet();\n this.activeList = this.setList.filter((s) => sets.includes(s));\n this.activeSet = composeSets(this.activeList);\n this.clearSeekCache();\n const drawn = this.activeSet?.drawn;\n if (ease > 0 && this.startEase(ease, shownBefore, drawn, physics)) return;\n const easing = this.easing;\n if (easing !== null) {\n // An instant call during an ease lands every eased bone at once, from what it shows.\n this.easing = null;\n const posedBefore = this.drawnPose;\n this.drawnPose = drawn === undefined ? null : drawnLocals(this.view, drawn);\n const changed = drawnChanged(posedBefore, this.drawnPose);\n for (const bone of easing.bones.keys()) changed.add(bone);\n if (physics !== undefined) this.handOverPhysics(changed, physics);\n this.reposeDrawn();\n return;\n }\n if (drawn !== drawnBefore && !(drawn === undefined && drawnBefore === undefined)) {\n const posedBefore = this.drawnPose;\n this.drawnPose = drawn === undefined ? null : drawnLocals(this.view, drawn);\n if (physics !== undefined) this.handOverPhysics(drawnChanged(posedBefore, this.drawnPose), physics);\n this.reposeDrawn();\n return;\n }\n const base = this.rawPose ?? (this.setup ?? (this.setup = poseRawSetup(this.view)));\n this.rawPose = base;\n this.pose = this.activeSet === null ? base : applySetToPose(this.view, base, this.activeSet);\n this.poseGeneration++;\n this.cachedIdentity = null;\n }\n\n /**\n * Which slots this player draws (`SlotFilter`), or null for every slot.\n * Settable on a live player: the next `draw` shows it, and `bounds()` reads\n * the drawn slots. An allow list naming a slot the document does not have\n * is refused by name. The pose is the whole rig's: `bone()`, `adjust`, the\n * events and the tracks see no filter.\n */\n get slots(): SlotFilter | null {\n return this.slotFilter;\n }\n\n set slots(filter: SlotFilter | null) {\n if (filter === null) {\n this.slotFilter = null;\n this.draws = () => true;\n this.poseGeneration++;\n this.cachedIdentity = null;\n return;\n }\n if (typeof filter === 'function') {\n this.slotFilter = filter;\n this.draws = filter;\n this.poseGeneration++;\n this.cachedIdentity = null;\n return;\n }\n if (!Array.isArray(filter)) throw new Error(`slots must be an array of slot names, a function, or null, got ${typeof filter}`);\n const known = new Set(this.read.doc.slots.map((slot) => slot.name));\n const unknown = filter.filter((name) => !known.has(name));\n if (unknown.length > 0) {\n throw new Error(`no slot named ${unknown.map((n) => JSON.stringify(n)).join(', ')} in this document (slots: ${[...known].join(', ')})`);\n }\n const allowed = new Set(filter);\n this.slotFilter = [...filter];\n this.draws = (slot) => allowed.has(slot);\n this.poseGeneration++;\n this.cachedIdentity = null;\n }\n\n /**\n * The per-pose adjustment of bone locals (`BoneAdjust`), or null for none.\n * It is applied by every track the player opens — `play`, the reopen inside\n * `seek` — and by the pose drawn again after `mode` changes, on every pose\n * the animation is applied to, the first one included. Setting it re-poses\n * the pose the player holds at once (`repose`), so a held or paused player\n * shows the change on its next `draw` without a step.\n */\n get adjust(): BoneAdjust | null {\n return this.adjustFn;\n }\n\n set adjust(fn: BoneAdjust | null) {\n if (fn !== null && typeof fn !== 'function') throw new Error(`adjust must be a function or null, got ${typeof fn}`);\n this.oracle('local adjustment');\n this.adjustFn = fn;\n this.clearSeekCache();\n this.repose();\n }\n\n /**\n * Poses the held pose again at the same track time, through the current\n * `adjust`, without stepping, firing or drawing. A paused player and a zero\n * step re-pose nothing, so a caller whose adjustment reads its own state\n * (a mouth driven while the body is held) calls this when that state\n * changed, then `draw`. Nothing before `play`.\n */\n repose(): void {\n if (this.runtimeFrames !== null) { this.applyRuntimeTime(); return; }\n this.clearSeekCache();\n const stepper = this.tracks ?? this.track;\n if (stepper === null || this.pose === null) return;\n this.setRawPose(stepper.step(0));\n }\n\n /**\n * Where `name` is in the pose the player holds — the pose of the last\n * `advance`/`frame`/`seek`, or the setup pose before `play`. Read off the\n * core's pose, so it is the same in `dom` and `canvas` mode and costs nothing\n * until called. An unknown bone is refused by name.\n */\n bone(name: string): BoneWorld {\n const pose = this.posed();\n for (const bone of pose.bones) {\n if (bone.name !== name) continue;\n return {\n name,\n active: bone.active,\n x: bone.worldX,\n y: bone.worldY,\n a: bone.a,\n b: bone.b,\n c: bone.c,\n d: bone.d,\n rotationX: bone.rotationX,\n rotationY: bone.rotationY,\n scaleX: bone.scaleX,\n scaleY: bone.scaleY,\n };\n }\n throw new Error(`no bone named ${JSON.stringify(name)} in this document (bones: ${pose.bones.map((b) => b.name).join(', ')})`);\n }\n\n /**\n * The box of what the pose the player holds draws, in world units, Y up:\n * every region's four corners and every mesh's vertices, in the same frame\n * record the renderer takes (`posedFrame`). A slot under a clip counts only\n * inside the clip polygon's own box (an inverse clip removes nothing from\n * the count); bounding boxes, paths and points are not drawn and do not\n * count. `null` when nothing draws. The same numbers in `dom` and `canvas`\n * mode; nothing is computed until called.\n */\n bounds(): PoseBounds | null {\n const frame = this.runtimeFrames !== null ? this.posedFrame() : this.pose === null ? frameOf(this.source, this.posed(), this.color, this.draws) : this.posedFrame();\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const slot of frame.order) {\n const points = slot.kind === 'region' ? slot.corners : slot.vertices;\n let lo = -Infinity, lb = -Infinity, hi = Infinity, hb = Infinity;\n if (slot.clip && !slot.clip.inverse) {\n const c = slot.clip.polygon;\n lo = Infinity; lb = Infinity; hi = -Infinity; hb = -Infinity;\n for (let i = 0; i < c.length; i += 2) {\n if (c[i] < lo) lo = c[i];\n if (c[i] > hi) hi = c[i];\n if (c[i + 1] < lb) lb = c[i + 1];\n if (c[i + 1] > hb) hb = c[i + 1];\n }\n }\n for (let i = 0; i < points.length; i += 2) {\n const x = Math.min(Math.max(points[i], lo), hi);\n const y = Math.min(Math.max(points[i + 1], lb), hb);\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n }\n }\n if (minX === Infinity) return null;\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n }\n\n /** The pose the reads above see: the track's, or the setup pose before `play` (posed once). */\n private posed(): RawPose {\n if (this.runtimeFrames !== null && this.animation !== null) {\n if (this.runtimeReadback === null) {\n const track = openTrack(this.view, this.animation, { loop: this.loop, reset: 'animation', clock: physicsClockStep });\n this.runtimeReadback = this.time > 0 ? track.step(this.time) : track.first;\n }\n return this.runtimeReadback;\n }\n if (this.pose !== null) return this.pose;\n if (this.setup === null) this.setup = poseRawSetup(this.view);\n return this.activeSet === null ? this.setup : applySetToPose(this.view, this.setup, this.activeSet);\n }\n\n /** Selected poser, including the named reason when the oracle is required. */\n get poser(): string { return this.runtimeFrames !== null ? 'runtime' : this.poserLabel === 'runtime' ? 'oracle: no runtime animation is active' : this.poserLabel; }\n\n private selectRuntime(): void {\n this.runtimeModel = null;\n if (this.oracleOnly) { this.poserLabel = 'oracle: explicitly selected'; return; }\n // RuntimePose.apply defaults to physics='none'; its looping step() alone\n // does not implement this player's clamped/replayed clock and movement API.\n const physics = this.view.constraints.find(constraint => constraint.kind === 'physics');\n if (physics) {\n this.poserLabel = `oracle: physics constraint \"${physics.name}\" requires player clock, seek and movement integration`;\n return;\n }\n try {\n this.runtimeModel = compileRuntime(this.view);\n this.poserLabel = this.trackMode ? 'oracle: track composition' : this.adjustFn !== null ? 'oracle: local adjustment' : 'runtime';\n } catch (error) {\n if (!(error instanceof RuntimeRefusal)) throw error;\n this.poserLabel = `oracle: ${error.message}`;\n }\n }\n\n private tryRuntimePlay(name: string, loop: boolean): boolean {\n if (this.runtimeModel === null) return false;\n const blocked = this.trackMode ? 'track composition' : this.adjustFn !== null ? 'local adjustment' : this.activeSet !== null ? 'attachment sets' : this.easing !== null ? 'set easing' : this.env !== null ? 'environment configuration' : null;\n if (blocked !== null) { this.poserLabel = `oracle: ${blocked}`; return false; }\n if (!this.runtimeModel.animations.has(name)) {\n const refused = this.runtimeModel.refused.find(value => value.animation === name);\n if (refused) this.poserLabel = `oracle: ${new RuntimeRefusal(refused.missing).message}`;\n return false;\n }\n const frames = this.runtimeFrames ?? new RuntimeFrames(this.source, this.runtimeModel);\n frames.pose.setAnimation(name);\n frames.pose.apply(0);\n this.runtimeFrames = frames;\n this.runtimeCompletionClock = { trackTime: 0 };\n this.animation = name;\n this.loop = loop;\n this.track = null;\n this.tracks = null;\n this.pose = null;\n this.rawPose = null;\n this.poserLabel = 'runtime';\n this.poseGeneration++;\n this.cachedIdentity = null;\n this.runtimeReadback = null;\n frames.update(this.poseGeneration, this.color, this.draws);\n return true;\n }\n\n private applyRuntimeTime(): void {\n const frames = this.runtimeFrames!;\n const duration = frames.model.animations.get(this.animation as string)!.duration;\n const time = frames.pose.trackTime;\n this.runtimeCompletionClock.trackTime = time;\n frames.pose.apply(duration === 0 ? 0 : this.loop ? time % duration : Math.min(time, duration));\n this.poseGeneration++;\n this.cachedIdentity = null;\n this.runtimeReadback = null;\n frames.update(this.poseGeneration, this.color, this.draws);\n }\n\n /** Materialize the old track only at an operation stage 0 cannot execute. */\n private oracle(reason: string): void {\n if (this.runtimeFrames === null || this.animation === null) return;\n const time = this.runtimeFrames.pose.trackTime;\n const generation = this.poseGeneration;\n this.runtimeFrames = null;\n this.runtimeReadback = null;\n if (this.poserLabel === 'runtime') this.poserLabel = `oracle: ${reason}`;\n this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: 'animation', adjust: this.adjustHook, clock: this.clockHook });\n this.setRawPose(this.track.first);\n if (time > 0) this.setRawPose(this.track.step(time));\n this.poseGeneration = generation;\n this.applyEnvironment(this.track);\n }\n\n /** Borrow buffers until the next pose mutation. Request posedFrame() to retain a snapshot. */\n liveFrame(): LiveFrame {\n if (this.liveDisposed) throw new Error('LIVE_FRAME_DISPOSED: cannot borrow a frame after dispose');\n let frame: LiveFrame;\n if (this.runtimeFrames !== null) {\n this.runtimeFrames.update(this.poseGeneration, this.color, this.draws, false);\n frame = this.runtimeFrames.live;\n } else {\n const identities = new Map(this.slotIdentity().slots.map(slot => [slot.slot, slot]));\n frame = oracleLiveFrame(this.posedFrame(), identities, this.source.slotIndex);\n }\n return this.liveChecks ? this.checkedFrame(frame) : frame;\n }\n\n /** Keep lease closures out of the production borrow's call environment. */\n private checkedFrame(frame: LiveFrame): LiveFrame {\n const generation = this.poseGeneration;\n const state = this.runtimeFrames;\n const revision = state?.revision;\n return checkedLiveFrame(frame, () => this.poseGeneration === generation && (state === null || state.revision === revision) ? generation : -1);\n }\n\n /** Monotonic pose generation counter matching `posedFrame().generation` and `slotIdentity().generation`. */\n get generation(): number {\n return this.poseGeneration;\n }\n\n /**\n * The pose the player holds, as the frame record the renderer draws — under\n * this player's `slots` filter, or under `slots` given here instead (a\n * second renderer over the same assets drawing this player's pose on\n * another root: `other.render(player.posedFrame(['hand_f']))`, the one rig\n * posed once).\n */\n posedFrame(slots?: SlotFilter | null): PosedFrame {\n const draws = slots === undefined ? this.draws : slots === null ? () => true : typeof slots === 'function' ? slots : predicateOf(slots);\n if (this.runtimeFrames !== null) this.runtimeFrames.update(this.poseGeneration, this.color, this.draws, false);\n const frame: PosedFrame = this.runtimeFrames !== null ? this.runtimeFrames.snapshot(draws) : this.pose === null ? { order: [] } : frameOf(this.source, this.pose, this.color, draws);\n Object.defineProperty(frame, 'generation', {\n value: this.poseGeneration,\n enumerable: false,\n configurable: true,\n });\n return frame;\n }\n\n /**\n * A read-only slot identity snapshot coherent with `posedFrame()` (#144):\n * for every slot in the posed draw order (`z = 0 .. slots.length - 1`, hidden\n * and null slots included), its resolved attachment key (`string | null`),\n * the skin that owns that attachment (`string | null`), and `reason` (`null`\n * when drawn in `posedFrame().order`, or `'hidden' | 'no-attachment' | 'timeline-null' | 'set-hide'`\n * when not drawn), together with the active `set`, active `skin`, and frame\n * `generation`. Read off the held pose without `seek`, `repose`, or physics\n * restart.\n */\n slotIdentity(): SlotIdentitySnapshot {\n if (this.cachedIdentity !== null && this.cachedIdentityGen === this.poseGeneration) {\n return this.cachedIdentity;\n }\n const setupPose = this.setup ?? (this.setup = poseRawSetup(this.view));\n const pose = this.posed();\n const raw = this.runtimeFrames !== null ? pose : this.rawPose ?? setupPose;\n const shownBySlot = new Map(pose.shown.map((s) => [s.slot, s]));\n const setupShownSlots = new Set(setupPose.shown.map((s) => s.slot));\n const rawRowBySlot = new Map(raw.slots.map((r) => [r[0], r]));\n const slots: SlotIdentity[] = [];\n // The attachments the pose draws: before an ease's swap (#174), the composition it eases from.\n const shownSet = this.shownSet();\n for (let z = 0; z < pose.drawOrder.length; z++) {\n const slotName = pose.drawOrder[z];\n if (shownSet !== null && hiddenBySet(slotName, shownSet)) {\n slots.push(Object.freeze({\n slot: slotName,\n z,\n attachment: null,\n skin: null,\n reason: 'set-hide' as const,\n }));\n continue;\n }\n const shown = shownBySlot.get(slotName);\n const isDrawableKind =\n shown !== undefined &&\n (shown.geometry.kind === 'region' || shown.geometry.kind === 'mesh' || shown.geometry.kind === 'linkedmesh');\n if (shown !== undefined && isDrawableKind) {\n const bone = this.source.boneOf.get(slotName);\n const boneActive = bone !== undefined && this.source.active.has(bone);\n if (this.draws(slotName) && boneActive) {\n slots.push(Object.freeze({\n slot: slotName,\n z,\n attachment: shown.name,\n skin: shown.skin,\n reason: null,\n }));\n } else {\n slots.push(Object.freeze({\n slot: slotName,\n z,\n attachment: null,\n skin: null,\n reason: 'hidden' as const,\n }));\n }\n continue;\n }\n const rawRow = rawRowBySlot.get(slotName);\n const overriddenBySet = shownSet !== null && slotName in shownSet.slots;\n const setupHadAttachment = setupShownSlots.has(slotName);\n const isTimelineNull =\n !overriddenBySet &&\n ((setupHadAttachment && rawRow?.[1] === null) ||\n this.isSlotKeyedNullByTimeline(slotName, raw.animationTime));\n slots.push(Object.freeze({\n slot: slotName,\n z,\n attachment: null,\n skin: null,\n reason: isTimelineNull ? ('timeline-null' as const) : ('no-attachment' as const),\n }));\n }\n const snapshot: SlotIdentitySnapshot = Object.freeze({\n generation: this.poseGeneration,\n set: this.set,\n sets: Object.freeze(this.activeSets),\n skin: this.skinName ?? null,\n slots: Object.freeze(slots),\n });\n this.cachedIdentity = snapshot;\n this.cachedIdentityGen = this.poseGeneration;\n return snapshot;\n }\n\n /** Whether an active animation's attachment timeline explicitly keyed `null` on `slotName` at `animationTime`. */\n private isSlotKeyedNullByTimeline(slotName: string, animationTime: number): boolean {\n const checkAnimation = (animName: string | null, time: number): boolean | undefined => {\n if (animName === null) return undefined;\n const anim = this.view.animations.find((a) => a.name === animName);\n if (anim === undefined) return undefined;\n const target = anim.timelines.slots.find((s) => s.name === slotName);\n if (target === undefined) return undefined;\n let keyed: boolean | undefined;\n for (const tl of target.timelines) {\n if (tl.kind !== 'attachment') continue;\n let activeKey: { time: number; name?: string | null } | null = null;\n for (const k of tl.keys) {\n if (k.time <= time) activeKey = k;\n else break;\n }\n if (activeKey !== null) {\n keyed = activeKey.name === null || activeKey.name === undefined;\n }\n }\n return keyed;\n };\n if (this.tracks !== null) {\n let result = false;\n for (let t = 0; t < this.trackCount; t++) {\n const cur = this.tracks.current(t);\n if (cur !== null && cur.animation !== null) {\n const k = checkAnimation(cur.animation, cur.animationTime);\n if (k !== undefined) result = k;\n }\n }\n return result;\n }\n if ((this.track !== null || this.runtimeFrames !== null) && this.animation !== null) {\n return checkAnimation(this.animation, animationTime) === true;\n }\n return false;\n }\n\n /** Removes the renderer's elements and hands its GPU pages back. The assets stay the caller's. */\n dispose(): void {\n this.runtimeFrames = null;\n this.runtimeReadback = null;\n this.liveDisposed = true;\n this.poseGeneration++;\n this.renderer.dispose();\n this.clearSeekCache();\n this.cachedIdentity = null;\n this.easing = null;\n this.tracks = null;\n this.track = null;\n this.pose = null;\n this.rawPose = null;\n }\n\n /** The single track's step: its events (track 0) and its complete, as every 1.x player fired them. */\n private dispatchSingle(pose: RawPose, before: number, track: LiveTrack): void {\n if (this.listeners.event.size > 0) {\n for (const [name, time, int, float, string] of pose.events) {\n const event: RigEvent = { name, time, int, float, string, track: 0 };\n for (const listener of this.listeners.event) listener(event);\n }\n }\n if (this.listeners.complete.size > 0) {\n const d = track.duration;\n const after = track.trackTime;\n const cycles = d > 0 ? Math.floor(after / d) : Infinity;\n const was = d > 0 ? Math.floor(before / d) : -Infinity;\n if (this.loop ? cycles > 0 && cycles > was : before < d && after >= d) {\n const payload: RigComplete = { animation: this.animation as string, track: 0 };\n for (const listener of this.listeners.complete) listener(payload);\n }\n }\n }\n\n /**\n * The step's events, then its completes, each with its track. The core\n * fires a track's keys from its current entry (`pose.events`, in track\n * order and in the runtime's order across a wrap) — an entry mixing out\n * fires none — and leaves `complete` to the player, which derives it per\n * track from that track's current entry: on a looping entry, once on a step\n * whose whole cycles rose; on a held one, on the step that reaches its\n * duration. An entry replaced inside the step — by `play`, or by a queued\n * entry starting at its completion less the mix — is no longer current and\n * completes no more than it fires, which is the runtime's rule too.\n */\n private dispatch(pose: RawPose, before: ReadonlyArray<TrackEntryView | null>, tracks: LiveTracks): void {\n const after: Array<TrackEntryView | null> = [];\n for (let t = 0; t < this.trackCount; t++) after.push(tracks.current(t));\n const same = (b: TrackEntryView | null, a: TrackEntryView | null): boolean =>\n b !== null && a !== null && b.animation === a.animation && b.loop === a.loop && a.trackTime >= b.trackTime;\n\n if (this.listeners.event.size > 0 && pose.events.length > 0) {\n // Attribute by count: what each track's current entry fired over the step.\n const counts: number[] = [];\n let total = 0;\n for (let t = 0; t < this.trackCount; t++) {\n const a = after[t];\n const b = before[t];\n let n = 0;\n if (a !== null && a.animation !== null) {\n const keys = this.view.animations.find((anim) => anim.name === a.animation)?.timelines.events ?? [];\n if (keys.length > 0) {\n const last = same(b, a) ? (b as TrackEntryView).animationTime : -1;\n n = eventsFired(keys, last, a.animationTime, undefined, a.animationTime < last).length;\n }\n }\n counts.push(n);\n total += n;\n }\n const attributed = total === pose.events.length;\n let track = 0;\n let left = counts[0] ?? 0;\n for (const [name, time, int, float, string] of pose.events) {\n if (attributed) {\n while (left === 0 && track < counts.length - 1) {\n track++;\n left = counts[track];\n }\n left--;\n }\n const event: RigEvent = attributed ? { name, time, int, float, string, track } : { name, time, int, float, string };\n for (const listener of this.listeners.event) listener(event);\n }\n }\n if (this.listeners.complete.size > 0) {\n for (let t = 0; t < this.trackCount; t++) {\n const a = after[t];\n const b = before[t];\n if (!same(b, a) || a === null || a.animation === null) continue;\n const d = a.duration;\n const cycles = d > 0 ? Math.floor(a.trackTime / d) : Infinity;\n const was = d > 0 ? Math.floor((b as TrackEntryView).trackTime / d) : -Infinity;\n const fired = a.loop ? cycles > 0 && cycles > was : (b as TrackEntryView).trackTime < d && a.trackTime >= d;\n if (!fired) continue;\n const payload: RigComplete = { animation: a.animation, track: t };\n for (const listener of this.listeners.complete) listener(payload);\n }\n }\n }\n}\n","import type { BoneLocals } from './player.js';\n\nexport type TurnAxis = 'yaw' | 'pitch' | 'body';\n\n/** A discovered slider's input range in the driven bone channel's local units. */\nexport interface TurnDial {\n axis: TurnAxis;\n bone: string;\n slider: string;\n channel: keyof BoneLocals;\n min: number;\n max: number;\n provenance: string;\n}\n\nconst canonicalBones = {\n yaw: 'yaw_dial',\n pitch: 'pitch_dial',\n body: 'body_yaw_dial',\n} as const;\n\nconst channels = new Map<string, keyof BoneLocals>([\n ['rotate', 'rotation'],\n ['x', 'x'],\n ['y', 'y'],\n ['scaleX', 'scaleX'],\n ['scaleY', 'scaleY'],\n ['shearY', 'shearY'],\n]);\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : undefined;\n}\n\nfunction unprefixed(name: string): string {\n const separator = name.indexOf(':');\n return separator > 0 ? name.slice(separator + 1) : name;\n}\n\nfunction finite(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value);\n}\n\n/**\n * Reads the turn sliders in parsed compiled model JSON, in yaw, pitch, body order.\n * Supply the matching ModelAssets.animations to use runtime animation durations.\n */\nexport function discoverTurnDials(\n model: unknown,\n durations?: readonly { name: string; duration: number }[],\n): TurnDial[] {\n const doc = record(model);\n if (!doc || !Array.isArray(doc.bones) || !Array.isArray(doc.constraints)) return [];\n\n const bones = new Set(doc.bones.map((row: unknown) => record(row)?.name));\n const sliders = doc.constraints.flatMap((row: unknown) => {\n const constraint = record(row);\n if (constraint?.kind !== 'slider') return [];\n const { name, bone, animation } = constraint;\n if (typeof name !== 'string' || typeof bone !== 'string' || !bones.has(bone)) return [];\n return [{ constraint, name, bone, animation }];\n });\n const animationRows: readonly unknown[] = durations ?? (Array.isArray(doc.animations) ? doc.animations : []);\n const animations = animationRows.map(record);\n const result: TurnDial[] = [];\n\n for (const axis of ['yaw', 'pitch', 'body'] as const) {\n const canonical = canonicalBones[axis];\n // Count bindings before checking their usability. An unusable binding still makes the axis ambiguous.\n const candidates = sliders.filter(({ bone, animation }) => unprefixed(bone) === canonical ||\n (axis === 'body' && typeof animation === 'string' && unprefixed(animation) === 'body_turn'));\n if (candidates.length !== 1) continue;\n\n const { constraint, name, bone, animation } = candidates[0];\n if (!constraint.local || constraint.loop || typeof animation !== 'string') continue;\n const property = constraint.property ?? 'rotate';\n const channel = typeof property === 'string' ? channels.get(property) : undefined;\n const duration = animations.find((row) => row?.name === animation)?.duration;\n const from = constraint.from ?? 0;\n const to = constraint.to ?? 0;\n const scale = constraint.scale ?? 1;\n if (!channel || !finite(duration) || duration <= 0 ||\n !finite(from) || !finite(to) || !finite(scale) || scale === 0) continue;\n\n // Invert the slider mapping at animation times zero and duration.\n const start = from - to / scale;\n const end = from + (duration - to) / scale;\n const min = Math.min(start, end);\n const max = Math.max(start, end);\n if (!finite(min) || !finite(max) || min === max || min > 0 || max < 0) continue;\n if (result.some((dial) => dial.bone === bone && dial.channel === channel)) continue;\n\n const binding = unprefixed(bone) === canonical ? '' : ' (compiled body_turn binding)';\n result.push({\n axis,\n bone,\n slider: name,\n channel,\n min,\n max,\n provenance: `model slider ${name} → bone ${bone}, ${property}, animation ${animation}${binding}`,\n });\n }\n return result;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value)) || 0;\n}\n\n/** Maps normalized input around zero, interpolating each side of the range independently. */\nexport function normalizedDial(value: number, range: { min: number; max: number }): number {\n const input = clamp(value, -1, 1);\n const neutral = clamp(0, range.min, range.max);\n const endpoint = input < 0 ? range.min : range.max;\n return clamp(neutral + Math.abs(input) * (endpoint - neutral), range.min, range.max);\n}\n"],"names":["RAD","bone","modeOf","a","b","c","d","isRecord","finite","record","values","blendOf","world","num","keyCurve","channels","onLineBefore","onLinePast","onCurve","curveCount","total","spaceScale","x1","y1","x2","y2","cx1","cy1","cx2","cy2","cos","sin","channel","freshPhysicsState","resetPhysicsState","PI2","INV_PI2","flag","valuesAt","times","target","clamp01","COLOUR_CHANNELS","DEG","unknownFields","tl","i","wrap180","volumeScaleY","ux","uy","frame","applyWorld","origin","out","keyAt","readSetupMesh","boneIndex","document","job","whole","coreReadSetupMesh","text","j","index","drawings","internal","renderer","steps","rest","firstPose","step","before","payload","raw","animation"],"mappings":"AA4GO,MAAM,aAAa;AAC1B,MAAMA,QAAM,aAAa;AAElB,MAAM,cAAc,MAAM;AAG1B,MAAM,sBAAsB,OAAU;AAkBtC,MAAM,qBAAsC;AAAA,EACjD,kBAAkBA;AAAAA,EAClB,WAAW,CAAC,YAAY,UAAU;AAAA,EAClC,mBAAmB;AACrB;AAqBA,SAAS,MAAM,UAAkB,QAAgB,QAAgB,QAAgB,QAAgB,MAAcA,OAAS;AACtH,QAAM,UAAU,WAAW,UAAU;AACrC,QAAM,UAAU,WAAW,KAAK,UAAU;AAC1C,SAAO,CAAC,KAAK,IAAI,MAAM,IAAI,QAAQ,KAAK,IAAI,MAAM,IAAI,QAAQ,KAAK,IAAI,MAAM,IAAI,QAAQ,KAAK,IAAI,MAAM,IAAI,MAAM;AACpH;AAGA,SAAS,WAAW,YAA6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