@idosgames/characters 0.1.1 → 0.1.3

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.
@@ -55,15 +55,26 @@ declare class ArtCatalog {
55
55
  ids(): ArtId[];
56
56
  }
57
57
 
58
- declare const LOOK_VERSION = 1;
58
+ declare const LOOK_VERSION: 2;
59
+ /** Every version this package reads: a saved v1 look stays valid. */
60
+ type LookVersion = 1 | typeof LOOK_VERSION;
61
+ /** The body (v2): the race (core/race). Its parts and gear stay the same size: only the base changes. */
62
+ interface BodyLook {
63
+ /** A race of the rig's registry ("elf"); omitted — the rig's own body. */
64
+ race?: string;
65
+ }
59
66
  interface CharacterLook {
60
- v: typeof LOOK_VERSION;
67
+ v: LookVersion;
61
68
  /** Type → part id; null — taken off. A missing type is left as it is. */
62
69
  parts?: Partial<Record<PartTypeId, string | null>>;
63
70
  colors?: Partial<Record<ColorTargetId, Hex>>;
71
+ /** The body; a missing field is left as it is. */
72
+ body?: BodyLook;
64
73
  }
65
- /** Later looks win, type by type and colour by colour (a sword over a class's default weapon). */
74
+ /** Later looks win, type by type, colour by colour; the body of the last look that gives one. */
66
75
  declare function mergeLooks(...looks: ReadonlyArray<CharacterLook | null | undefined>): CharacterLook;
76
+ /** A body from untrusted JSON: a race id; null — nothing usable. */
77
+ declare function parseBody(value: unknown): BodyLook | null;
67
78
  /** A look from untrusted JSON (custom data, a pasted preset); null when it is not one. */
68
79
  declare function parseLook(value: unknown): CharacterLook | null;
69
80
 
@@ -372,6 +383,12 @@ declare class Animator {
372
383
  private blendFromSaved;
373
384
  }
374
385
 
386
+ type Rng = () => number;
387
+ declare function seededRandom(seed: number): Rng;
388
+ /** A seed from a string (an id). */
389
+ declare function seedOf(text: string): number;
390
+ declare function pick<T>(rng: Rng, list: readonly T[]): T | undefined;
391
+
375
392
  interface RuleView {
376
393
  /** The worn skin of a type (null — none), after the player's choice and the hidden flag. */
377
394
  worn(type: PartTypeId): string | null;
@@ -379,6 +396,10 @@ interface RuleView {
379
396
  setWorn(type: PartTypeId, skin: string | null): void;
380
397
  /** Does the data have this skin. */
381
398
  exists(skin: string): boolean;
399
+ /** The character's race (its look's `body.race` in the rig's registry), null — none. */
400
+ race(): RaceDef | null;
401
+ /** Every part type of the rig, in its order. */
402
+ types(): readonly PartTypeId[];
382
403
  }
383
404
  interface PartsRule {
384
405
  id: string;
@@ -403,6 +424,55 @@ declare function bothHands(options: {
403
424
  skins: ReadonlySet<string>;
404
425
  }): PartsRule;
405
426
 
427
+ interface RaceDef {
428
+ /** Lower-case id, saved in looks ("elf"). */
429
+ id: string;
430
+ /** The name per language ("en" is the fallback). */
431
+ names: Readonly<Record<string, string>>;
432
+ /** One line about it per language, for a spec's texts and an editor's hint. */
433
+ about?: Readonly<Record<string, string>>;
434
+ /** Its own parts on the rig's race-owned types (`auto` types: Ears, Tusks); null — none. */
435
+ parts?: Readonly<Record<PartTypeId, string | null>>;
436
+ /** The skin colours it may have; the first is the default. Empty or omitted — any. */
437
+ skin?: readonly Hex[];
438
+ /** Default colours when a look gives none (the undead's pale eyes). */
439
+ colors?: Readonly<Record<ColorTargetId, Hex>>;
440
+ /** Parts it cannot wear: a type → its banned skins, or "all" (an elf grows no beard). */
441
+ ban?: Readonly<Record<PartTypeId, readonly string[] | "all">>;
442
+ /** A worn skin → what it wears instead (null — nothing), before the bans. */
443
+ replace?: Readonly<Record<string, string | null>>;
444
+ /** Parts a new character of this race starts with (a dwarf's beard), for `raceLook`. */
445
+ defaults?: Readonly<Record<PartTypeId, string | null>>;
446
+ /** Parts a generated character of this race picks from (`raceLook` with an rng). */
447
+ options?: Readonly<Record<PartTypeId, readonly (string | null)[]>>;
448
+ }
449
+ /** The races a rig knows. Mutable on purpose: a game registers its own (a race is data). */
450
+ declare class RaceRegistry {
451
+ private readonly races;
452
+ constructor(races?: readonly RaceDef[]);
453
+ /** Adds a race; one with the same id is replaced (a game re-skins a stock race). */
454
+ register(race: RaceDef): this;
455
+ get(id: string | null | undefined): RaceDef | null;
456
+ has(id: string): boolean;
457
+ list(): RaceDef[];
458
+ ids(): string[];
459
+ }
460
+ /** A race's name in a language, English when it has none there. */
461
+ declare function raceName(race: RaceDef, language?: string): string;
462
+ /**
463
+ * The race's own parts and what it cannot wear — a rule of the rig (rigs/hero/index.ts). Runs after the
464
+ * rules that resolve covering parts. The race comes from the look (`body.race`), read through the view.
465
+ */
466
+ declare function raceParts(): PartsRule;
467
+ /** Is this skin colour allowed for the race (any, when it names none). */
468
+ declare function raceAllowsSkin(race: RaceDef, color: Hex): boolean;
469
+ /**
470
+ * A look of the race to start from or to put on a foe: its body, its default parts and colours, a skin
471
+ * from its palette. With an rng the skin and the `options` are picked (the same seed — the same look).
472
+ * Merge it under the gear: `mergeLooks(raceLook(race), gearLook)`.
473
+ */
474
+ declare function raceLook(race: RaceDef, rng?: Rng, skinTarget?: ColorTargetId): CharacterLook;
475
+
406
476
  interface ShadingDef {
407
477
  /** Towards the light, in the character's world (y up) — (-0.5, 1) is from the upper left. */
408
478
  light: readonly [number, number];
@@ -489,16 +559,14 @@ interface RigDef {
489
559
  editor?: {
490
560
  groups: readonly EditorGroup[];
491
561
  };
562
+ /** The races it knows (core/race): a look's `body.race` is looked up here; games register more. */
563
+ races?: RaceRegistry;
564
+ /** The colour target a race's skin palette paints (default "Skin"). */
565
+ skinColor?: ColorTargetId;
492
566
  }
493
567
  /** Checks a rig's references once, at load: a typo fails loudly here. */
494
568
  declare function defineRig(rig: RigDef): RigDef;
495
569
 
496
- type Rng = () => number;
497
- declare function seededRandom(seed: number): Rng;
498
- /** A seed from a string (an id). */
499
- declare function seedOf(text: string): number;
500
- declare function pick<T>(rng: Rng, list: readonly T[]): T | undefined;
501
-
502
570
  type PartsChange = {
503
571
  kind: "part";
504
572
  type: PartTypeId;
@@ -517,6 +585,9 @@ type PartsChange = {
517
585
  } | {
518
586
  kind: "speech";
519
587
  viseme: Viseme;
588
+ } | {
589
+ kind: "body";
590
+ body: BodyLook;
520
591
  };
521
592
  type Listener = (change: PartsChange) => void;
522
593
  declare class PartsManager {
@@ -532,6 +603,10 @@ declare class PartsManager {
532
603
  private face;
533
604
  private emotionFace;
534
605
  private speech;
606
+ private body;
607
+ /** Colours a race painted over (target → what was there) and what it painted: given back when it goes. */
608
+ private raceSaved;
609
+ private raceGiven;
535
610
  constructor(rig: RigDef, drawable?: (skin: string) => boolean);
536
611
  /** The art changed (a pack added, another art source): recompute what each type offers. */
537
612
  setDrawable(drawable: (skin: string) => boolean): void;
@@ -555,6 +630,10 @@ declare class PartsManager {
555
630
  slotColor(slotIndex: number): Hex | null;
556
631
  /** The colour drawn into a slot's art (its `currentColor`), null — the art's own. */
557
632
  artColor(slotIndex: number): Hex | null;
633
+ /** The body as the look gives it (its race). */
634
+ bodyLook(): BodyLook;
635
+ /** The race (in the rig's registry), null — none or one the rig does not know. */
636
+ race(): RaceDef | null;
558
637
  /** The expression on now (null — the chosen face). */
559
638
  expression(): string | null;
560
639
  /** Puts on a skin by index in `list` or by name; -1 / null — none. Unknown names are ignored. */
@@ -574,6 +653,10 @@ declare class PartsManager {
574
653
  setEmotion(emotion: Emotion): void;
575
654
  /** The mouth's shape while speaking (lip-sync); "rest" — the chosen mouth. Not part of a look. */
576
655
  setSpeech(viseme: Viseme): void;
656
+ /** Replaces the body (the race). A race brings its skin when the one painted is not its. */
657
+ setBody(body: BodyLook): void;
658
+ /** Changes the race (null — none). */
659
+ setRace(race: string | null): void;
577
660
  /** Every type a random part, one that can be taken off — none 30% of the time. */
578
661
  randomize(rng?: Rng): void;
579
662
  /** The first skin of every type, nothing hidden, the art's own colours. */
@@ -581,9 +664,16 @@ declare class PartsManager {
581
664
  toLook(): CharacterLook;
582
665
  /** Puts a look on. A skin the art cannot draw is skipped (what is worn stays). */
583
666
  applyLook(look: CharacterLook): void;
667
+ /** The colours a race gave that are still unchanged go with it: what was there before comes back. */
668
+ private dropRaceColors;
669
+ /** Notes what the race painted and what it painted over (`prior` — the colours before it came). */
670
+ private rememberRaceColors;
671
+ /** The race's colours: its default ones where none is painted (or the look gives none), and its first
672
+ * skin when the painted one is not in its palette. */
673
+ private fitRaceColors;
584
674
  private rebuildLists;
585
675
  private first;
586
676
  private init;
587
677
  }
588
678
 
589
- export { ArtCatalog as A, type BlinkOptions as B, type CharacterLook as C, defineRig as D, type EditorGroup as E, hexToNumber as F, imageSizes as G, type Hex as H, mergeLooks as I, numberToHex as J, parseLook as K, LOOK_VERSION as L, pick as M, readSkeletonData as N, seedOf as O, PartsManager as P, seededRandom as Q, type RigDef as R, Skeleton as S, skinImages as T, swapUnder as U, WHITE as W, Animator as a, type PlayOptions as b, type AnimationEvent as c, Slot as d, type Attachment as e, type ArtPack as f, type ArtDef as g, type ArtStyle as h, Animation as i, type ArtId as j, Bone as k, type BoneId as l, type Color as m, type ColorTargetDef as n, type ColorTargetId as o, type ExpressionsDef as p, type PartTypeDef as q, type PartTypeId as r, type PartsChange as s, type PartsRule as t, type Rng as u, type RuleView as v, type SkeletonData as w, type Skin as x, bothHands as y, colorOf as z };
679
+ export { seedOf as $, ArtCatalog as A, type BlinkOptions as B, type CharacterLook as C, type SkeletonData as D, type EditorGroup as E, type Skin as F, bothHands as G, type Hex as H, colorOf as I, defineRig as J, hexToNumber as K, LOOK_VERSION as L, imageSizes as M, mergeLooks as N, numberToHex as O, PartsManager as P, parseBody as Q, type RigDef as R, Skeleton as S, parseLook as T, pick as U, raceAllowsSkin as V, WHITE as W, raceLook as X, raceName as Y, raceParts as Z, readSkeletonData as _, Animator as a, seededRandom as a0, skinImages as a1, swapUnder as a2, type PlayOptions as b, type AnimationEvent as c, Slot as d, type Attachment as e, type RaceDef as f, type ArtPack as g, type ArtDef as h, type ArtStyle as i, Animation as j, type ArtId as k, type BodyLook as l, Bone as m, type BoneId as n, type Color as o, type ColorTargetDef as p, type ColorTargetId as q, type ExpressionsDef as r, type LookVersion as s, type PartTypeDef as t, type PartTypeId as u, type PartsChange as v, type PartsRule as w, RaceRegistry as x, type Rng as y, type RuleView as z };
@@ -55,15 +55,26 @@ declare class ArtCatalog {
55
55
  ids(): ArtId[];
56
56
  }
57
57
 
58
- declare const LOOK_VERSION = 1;
58
+ declare const LOOK_VERSION: 2;
59
+ /** Every version this package reads: a saved v1 look stays valid. */
60
+ type LookVersion = 1 | typeof LOOK_VERSION;
61
+ /** The body (v2): the race (core/race). Its parts and gear stay the same size: only the base changes. */
62
+ interface BodyLook {
63
+ /** A race of the rig's registry ("elf"); omitted — the rig's own body. */
64
+ race?: string;
65
+ }
59
66
  interface CharacterLook {
60
- v: typeof LOOK_VERSION;
67
+ v: LookVersion;
61
68
  /** Type → part id; null — taken off. A missing type is left as it is. */
62
69
  parts?: Partial<Record<PartTypeId, string | null>>;
63
70
  colors?: Partial<Record<ColorTargetId, Hex>>;
71
+ /** The body; a missing field is left as it is. */
72
+ body?: BodyLook;
64
73
  }
65
- /** Later looks win, type by type and colour by colour (a sword over a class's default weapon). */
74
+ /** Later looks win, type by type, colour by colour; the body of the last look that gives one. */
66
75
  declare function mergeLooks(...looks: ReadonlyArray<CharacterLook | null | undefined>): CharacterLook;
76
+ /** A body from untrusted JSON: a race id; null — nothing usable. */
77
+ declare function parseBody(value: unknown): BodyLook | null;
67
78
  /** A look from untrusted JSON (custom data, a pasted preset); null when it is not one. */
68
79
  declare function parseLook(value: unknown): CharacterLook | null;
69
80
 
@@ -372,6 +383,12 @@ declare class Animator {
372
383
  private blendFromSaved;
373
384
  }
374
385
 
386
+ type Rng = () => number;
387
+ declare function seededRandom(seed: number): Rng;
388
+ /** A seed from a string (an id). */
389
+ declare function seedOf(text: string): number;
390
+ declare function pick<T>(rng: Rng, list: readonly T[]): T | undefined;
391
+
375
392
  interface RuleView {
376
393
  /** The worn skin of a type (null — none), after the player's choice and the hidden flag. */
377
394
  worn(type: PartTypeId): string | null;
@@ -379,6 +396,10 @@ interface RuleView {
379
396
  setWorn(type: PartTypeId, skin: string | null): void;
380
397
  /** Does the data have this skin. */
381
398
  exists(skin: string): boolean;
399
+ /** The character's race (its look's `body.race` in the rig's registry), null — none. */
400
+ race(): RaceDef | null;
401
+ /** Every part type of the rig, in its order. */
402
+ types(): readonly PartTypeId[];
382
403
  }
383
404
  interface PartsRule {
384
405
  id: string;
@@ -403,6 +424,55 @@ declare function bothHands(options: {
403
424
  skins: ReadonlySet<string>;
404
425
  }): PartsRule;
405
426
 
427
+ interface RaceDef {
428
+ /** Lower-case id, saved in looks ("elf"). */
429
+ id: string;
430
+ /** The name per language ("en" is the fallback). */
431
+ names: Readonly<Record<string, string>>;
432
+ /** One line about it per language, for a spec's texts and an editor's hint. */
433
+ about?: Readonly<Record<string, string>>;
434
+ /** Its own parts on the rig's race-owned types (`auto` types: Ears, Tusks); null — none. */
435
+ parts?: Readonly<Record<PartTypeId, string | null>>;
436
+ /** The skin colours it may have; the first is the default. Empty or omitted — any. */
437
+ skin?: readonly Hex[];
438
+ /** Default colours when a look gives none (the undead's pale eyes). */
439
+ colors?: Readonly<Record<ColorTargetId, Hex>>;
440
+ /** Parts it cannot wear: a type → its banned skins, or "all" (an elf grows no beard). */
441
+ ban?: Readonly<Record<PartTypeId, readonly string[] | "all">>;
442
+ /** A worn skin → what it wears instead (null — nothing), before the bans. */
443
+ replace?: Readonly<Record<string, string | null>>;
444
+ /** Parts a new character of this race starts with (a dwarf's beard), for `raceLook`. */
445
+ defaults?: Readonly<Record<PartTypeId, string | null>>;
446
+ /** Parts a generated character of this race picks from (`raceLook` with an rng). */
447
+ options?: Readonly<Record<PartTypeId, readonly (string | null)[]>>;
448
+ }
449
+ /** The races a rig knows. Mutable on purpose: a game registers its own (a race is data). */
450
+ declare class RaceRegistry {
451
+ private readonly races;
452
+ constructor(races?: readonly RaceDef[]);
453
+ /** Adds a race; one with the same id is replaced (a game re-skins a stock race). */
454
+ register(race: RaceDef): this;
455
+ get(id: string | null | undefined): RaceDef | null;
456
+ has(id: string): boolean;
457
+ list(): RaceDef[];
458
+ ids(): string[];
459
+ }
460
+ /** A race's name in a language, English when it has none there. */
461
+ declare function raceName(race: RaceDef, language?: string): string;
462
+ /**
463
+ * The race's own parts and what it cannot wear — a rule of the rig (rigs/hero/index.ts). Runs after the
464
+ * rules that resolve covering parts. The race comes from the look (`body.race`), read through the view.
465
+ */
466
+ declare function raceParts(): PartsRule;
467
+ /** Is this skin colour allowed for the race (any, when it names none). */
468
+ declare function raceAllowsSkin(race: RaceDef, color: Hex): boolean;
469
+ /**
470
+ * A look of the race to start from or to put on a foe: its body, its default parts and colours, a skin
471
+ * from its palette. With an rng the skin and the `options` are picked (the same seed — the same look).
472
+ * Merge it under the gear: `mergeLooks(raceLook(race), gearLook)`.
473
+ */
474
+ declare function raceLook(race: RaceDef, rng?: Rng, skinTarget?: ColorTargetId): CharacterLook;
475
+
406
476
  interface ShadingDef {
407
477
  /** Towards the light, in the character's world (y up) — (-0.5, 1) is from the upper left. */
408
478
  light: readonly [number, number];
@@ -489,16 +559,14 @@ interface RigDef {
489
559
  editor?: {
490
560
  groups: readonly EditorGroup[];
491
561
  };
562
+ /** The races it knows (core/race): a look's `body.race` is looked up here; games register more. */
563
+ races?: RaceRegistry;
564
+ /** The colour target a race's skin palette paints (default "Skin"). */
565
+ skinColor?: ColorTargetId;
492
566
  }
493
567
  /** Checks a rig's references once, at load: a typo fails loudly here. */
494
568
  declare function defineRig(rig: RigDef): RigDef;
495
569
 
496
- type Rng = () => number;
497
- declare function seededRandom(seed: number): Rng;
498
- /** A seed from a string (an id). */
499
- declare function seedOf(text: string): number;
500
- declare function pick<T>(rng: Rng, list: readonly T[]): T | undefined;
501
-
502
570
  type PartsChange = {
503
571
  kind: "part";
504
572
  type: PartTypeId;
@@ -517,6 +585,9 @@ type PartsChange = {
517
585
  } | {
518
586
  kind: "speech";
519
587
  viseme: Viseme;
588
+ } | {
589
+ kind: "body";
590
+ body: BodyLook;
520
591
  };
521
592
  type Listener = (change: PartsChange) => void;
522
593
  declare class PartsManager {
@@ -532,6 +603,10 @@ declare class PartsManager {
532
603
  private face;
533
604
  private emotionFace;
534
605
  private speech;
606
+ private body;
607
+ /** Colours a race painted over (target → what was there) and what it painted: given back when it goes. */
608
+ private raceSaved;
609
+ private raceGiven;
535
610
  constructor(rig: RigDef, drawable?: (skin: string) => boolean);
536
611
  /** The art changed (a pack added, another art source): recompute what each type offers. */
537
612
  setDrawable(drawable: (skin: string) => boolean): void;
@@ -555,6 +630,10 @@ declare class PartsManager {
555
630
  slotColor(slotIndex: number): Hex | null;
556
631
  /** The colour drawn into a slot's art (its `currentColor`), null — the art's own. */
557
632
  artColor(slotIndex: number): Hex | null;
633
+ /** The body as the look gives it (its race). */
634
+ bodyLook(): BodyLook;
635
+ /** The race (in the rig's registry), null — none or one the rig does not know. */
636
+ race(): RaceDef | null;
558
637
  /** The expression on now (null — the chosen face). */
559
638
  expression(): string | null;
560
639
  /** Puts on a skin by index in `list` or by name; -1 / null — none. Unknown names are ignored. */
@@ -574,6 +653,10 @@ declare class PartsManager {
574
653
  setEmotion(emotion: Emotion): void;
575
654
  /** The mouth's shape while speaking (lip-sync); "rest" — the chosen mouth. Not part of a look. */
576
655
  setSpeech(viseme: Viseme): void;
656
+ /** Replaces the body (the race). A race brings its skin when the one painted is not its. */
657
+ setBody(body: BodyLook): void;
658
+ /** Changes the race (null — none). */
659
+ setRace(race: string | null): void;
577
660
  /** Every type a random part, one that can be taken off — none 30% of the time. */
578
661
  randomize(rng?: Rng): void;
579
662
  /** The first skin of every type, nothing hidden, the art's own colours. */
@@ -581,9 +664,16 @@ declare class PartsManager {
581
664
  toLook(): CharacterLook;
582
665
  /** Puts a look on. A skin the art cannot draw is skipped (what is worn stays). */
583
666
  applyLook(look: CharacterLook): void;
667
+ /** The colours a race gave that are still unchanged go with it: what was there before comes back. */
668
+ private dropRaceColors;
669
+ /** Notes what the race painted and what it painted over (`prior` — the colours before it came). */
670
+ private rememberRaceColors;
671
+ /** The race's colours: its default ones where none is painted (or the look gives none), and its first
672
+ * skin when the painted one is not in its palette. */
673
+ private fitRaceColors;
584
674
  private rebuildLists;
585
675
  private first;
586
676
  private init;
587
677
  }
588
678
 
589
- export { ArtCatalog as A, type BlinkOptions as B, type CharacterLook as C, defineRig as D, type EditorGroup as E, hexToNumber as F, imageSizes as G, type Hex as H, mergeLooks as I, numberToHex as J, parseLook as K, LOOK_VERSION as L, pick as M, readSkeletonData as N, seedOf as O, PartsManager as P, seededRandom as Q, type RigDef as R, Skeleton as S, skinImages as T, swapUnder as U, WHITE as W, Animator as a, type PlayOptions as b, type AnimationEvent as c, Slot as d, type Attachment as e, type ArtPack as f, type ArtDef as g, type ArtStyle as h, Animation as i, type ArtId as j, Bone as k, type BoneId as l, type Color as m, type ColorTargetDef as n, type ColorTargetId as o, type ExpressionsDef as p, type PartTypeDef as q, type PartTypeId as r, type PartsChange as s, type PartsRule as t, type Rng as u, type RuleView as v, type SkeletonData as w, type Skin as x, bothHands as y, colorOf as z };
679
+ export { seedOf as $, ArtCatalog as A, type BlinkOptions as B, type CharacterLook as C, type SkeletonData as D, type EditorGroup as E, type Skin as F, bothHands as G, type Hex as H, colorOf as I, defineRig as J, hexToNumber as K, LOOK_VERSION as L, imageSizes as M, mergeLooks as N, numberToHex as O, PartsManager as P, parseBody as Q, type RigDef as R, Skeleton as S, parseLook as T, pick as U, raceAllowsSkin as V, WHITE as W, raceLook as X, raceName as Y, raceParts as Z, readSkeletonData as _, Animator as a, seededRandom as a0, skinImages as a1, swapUnder as a2, type PlayOptions as b, type AnimationEvent as c, Slot as d, type Attachment as e, type RaceDef as f, type ArtPack as g, type ArtDef as h, type ArtStyle as i, Animation as j, type ArtId as k, type BodyLook as l, Bone as m, type BoneId as n, type Color as o, type ColorTargetDef as p, type ColorTargetId as q, type ExpressionsDef as r, type LookVersion as s, type PartTypeDef as t, type PartTypeId as u, type PartsChange as v, type PartsRule as w, RaceRegistry as x, type Rng as y, type RuleView as z };
@@ -1 +1 @@
1
- import {s,D,c,w,y}from'./chunk-OF4BH3JZ.js';function Y(o,g,h=2){let b=s(o.data),y=o.shading?D(o.data,o.shading):new Map,p=new Map;return {image(n,t){let i=g.get(n),l=i?.paint?t??null:null,f=l?`${n}${l}`:n,m=p.get(f);if(m)return m;let c$1=b.get(n);return m=i&&c$1?new Promise(r=>{let e=new Image;e.onload=()=>r(e),e.onerror=()=>r(null),e.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c(i,c$1,h,{paint:l,light:y.get(n)??null}))}`;}):Promise.resolve(null),p.set(f,m),m}}}function J(o,g){let h=new Map,b=new w(o.data),y$1=(n,t,i)=>{let[l,f,m]=i.tint;if(!i.fill&&l===1&&f===1&&m===1)return t;let c=`${n}|${i.fill??`${l.toFixed(3)},${f.toFixed(3)},${m.toFixed(3)}`}`,r=h.get(c);if(r)return r;r=document.createElement("canvas"),r.width=t.width,r.height=t.height;let e=r.getContext("2d");return e.drawImage(t,0,0),e.globalCompositeOperation=i.fill?"source-in":"multiply",e.fillStyle=i.fill??`rgb(${l*255}, ${f*255}, ${m*255})`,e.fillRect(0,0,r.width,r.height),i.fill||(e.globalCompositeOperation="destination-in",e.drawImage(t,0,0)),h.set(c,r),r},p=(n,t,i,l,f,m)=>{let c=b;c.setSkins(n.flatMap(a=>o.data.skins.get(a)?[o.data.skins.get(a)]:[])),c.setupPose(),o.data.animations.get(m.animation)?.apply(c,m.time),c.resolveAttachments(),c.updateWorldTransform();let r=t?new Set(t):null,e=[];return c.slots.forEach((a,x)=>{let d=a.attachment;if(!d||r&&!r.has(a.data.name))return;let w=i?.(x)??null,M=w?O(w):[a.color.r,a.color.g,a.color.b],s=a.color.a*d.color.a;if(s<=0)return;let I=y(c,a,d,null);e.push({path:d.path,paint:l?.(x)??null,positions:Float32Array.from(I.positions),uvs:I.uvs,triangles:I.triangles,tint:[M[0]*d.color.r,M[1]*d.color.g,M[2]*d.color.b],alpha:s,fill:f});}),e};return {async draw(n,t){let i=t.pose??{animation:o.defaultAnimation,time:0},l=t.backdrop?p(t.backdrop.skins,t.backdrop.slots,void 0,void 0,t.backdrop.color,i):[],f=p(t.skins,t.slots,t.slotColor,t.artColor,null,i),m=[...l,...f],c=await Promise.all(m.map(s=>g.image(s.path,s.paint))),r=t.frame==="content"||!l.length?f:l,e=U(r.length?r:m),a=n.getContext("2d");if(a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,n.width,n.height),!e)return;let x=(t.padding??.08)*Math.min(n.width,n.height),d=Math.min((n.width-x*2)/Math.max(1,e.w),(n.height-x*2)/Math.max(1,e.h)),w=n.width/2-(e.x+e.w/2)*d,M=n.height/2+(e.y+e.h/2)*d;m.forEach((s,I)=>{let H=c[I];if(!H)return;let E=y$1(s.paint?`${s.path}${s.paint}`:s.path,H,s);a.globalAlpha=s.alpha;let T=s.triangles,v=u=>w+s.positions[u*2]*d,A=u=>M-s.positions[u*2+1]*d,$=u=>s.uvs[u*2]*H.width,R=u=>s.uvs[u*2+1]*H.height;for(let u=0;u<T.length;u+=3){let k=T[u],C=T[u+1],P=T[u+2];B(a,E,v(k),A(k),v(C),A(C),v(P),A(P),$(k),R(k),$(C),R(C),$(P),R(P));}}),a.globalAlpha=1;}}}function U(o){let g=1/0,h=1/0,b=-1/0,y=-1/0;for(let p of o)for(let n=0;n<p.positions.length;n+=2)g=Math.min(g,p.positions[n]),b=Math.max(b,p.positions[n]),h=Math.min(h,p.positions[n+1]),y=Math.max(y,p.positions[n+1]);return g===1/0?null:{x:g,y:h,w:b-g,h:y-h}}function B(o,g,h,b,y,p,n,t,i,l,f,m,c,r){let e=f-i,a=m-l,x=c-i,d=r-l,w=e*d-x*a;if(Math.abs(w)<1e-9)return;let M=y-h,s=p-b,I=n-h,H=t-b,E=(M*d-I*a)/w,T=(s*d-H*a)/w,v=(I*e-M*x)/w,A=(H*e-s*x)/w,$=(h+y+n)/3,R=(b+p+t)/3,u=(k,C)=>{let P=Math.hypot(k-$,C-R)||1;return [k+(k-$)/P*.6,C+(C-R)/P*.6]};o.save(),o.beginPath(),o.moveTo(...u(h,b)),o.lineTo(...u(y,p)),o.lineTo(...u(n,t)),o.closePath(),o.clip(),o.transform(E,T,v,A,h-E*i-v*l,b-T*i-A*l),o.drawImage(g,0,0),o.restore();}function O(o){let g=parseInt(o.replace("#",""),16);return [(g>>16&255)/255,(g>>8&255)/255,(g&255)/255]}export{Y as a,J as b};
1
+ import {s,M,c,w,y}from'./chunk-UUX4NEC2.js';function Y(o,g,h=2){let b=s(o.data),y=o.shading?M(o.data,o.shading):new Map,p=new Map;return {image(n,t){let i=g.get(n),l=i?.paint?t??null:null,f=l?`${n}${l}`:n,m=p.get(f);if(m)return m;let c$1=b.get(n);return m=i&&c$1?new Promise(r=>{let e=new Image;e.onload=()=>r(e),e.onerror=()=>r(null),e.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c(i,c$1,h,{paint:l,light:y.get(n)??null}))}`;}):Promise.resolve(null),p.set(f,m),m}}}function J(o,g){let h=new Map,b=new w(o.data),y$1=(n,t,i)=>{let[l,f,m]=i.tint;if(!i.fill&&l===1&&f===1&&m===1)return t;let c=`${n}|${i.fill??`${l.toFixed(3)},${f.toFixed(3)},${m.toFixed(3)}`}`,r=h.get(c);if(r)return r;r=document.createElement("canvas"),r.width=t.width,r.height=t.height;let e=r.getContext("2d");return e.drawImage(t,0,0),e.globalCompositeOperation=i.fill?"source-in":"multiply",e.fillStyle=i.fill??`rgb(${l*255}, ${f*255}, ${m*255})`,e.fillRect(0,0,r.width,r.height),i.fill||(e.globalCompositeOperation="destination-in",e.drawImage(t,0,0)),h.set(c,r),r},p=(n,t,i,l,f,m)=>{let c=b;c.setSkins(n.flatMap(a=>o.data.skins.get(a)?[o.data.skins.get(a)]:[])),c.setupPose(),o.data.animations.get(m.animation)?.apply(c,m.time),c.resolveAttachments(),c.updateWorldTransform();let r=t?new Set(t):null,e=[];return c.slots.forEach((a,x)=>{let d=a.attachment;if(!d||r&&!r.has(a.data.name))return;let w=i?.(x)??null,M=w?O(w):[a.color.r,a.color.g,a.color.b],s=a.color.a*d.color.a;if(s<=0)return;let I=y(c,a,d,null);e.push({path:d.path,paint:l?.(x)??null,positions:Float32Array.from(I.positions),uvs:I.uvs,triangles:I.triangles,tint:[M[0]*d.color.r,M[1]*d.color.g,M[2]*d.color.b],alpha:s,fill:f});}),e};return {async draw(n,t){let i=t.pose??{animation:o.defaultAnimation,time:0},l=t.backdrop?p(t.backdrop.skins,t.backdrop.slots,void 0,void 0,t.backdrop.color,i):[],f=p(t.skins,t.slots,t.slotColor,t.artColor,null,i),m=[...l,...f],c=await Promise.all(m.map(s=>g.image(s.path,s.paint))),r=t.frame==="content"||!l.length?f:l,e=U(r.length?r:m),a=n.getContext("2d");if(a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,n.width,n.height),!e)return;let x=(t.padding??.08)*Math.min(n.width,n.height),d=Math.min((n.width-x*2)/Math.max(1,e.w),(n.height-x*2)/Math.max(1,e.h)),w=n.width/2-(e.x+e.w/2)*d,M=n.height/2+(e.y+e.h/2)*d;m.forEach((s,I)=>{let H=c[I];if(!H)return;let E=y$1(s.paint?`${s.path}${s.paint}`:s.path,H,s);a.globalAlpha=s.alpha;let T=s.triangles,v=u=>w+s.positions[u*2]*d,A=u=>M-s.positions[u*2+1]*d,$=u=>s.uvs[u*2]*H.width,R=u=>s.uvs[u*2+1]*H.height;for(let u=0;u<T.length;u+=3){let k=T[u],C=T[u+1],P=T[u+2];B(a,E,v(k),A(k),v(C),A(C),v(P),A(P),$(k),R(k),$(C),R(C),$(P),R(P));}}),a.globalAlpha=1;}}}function U(o){let g=1/0,h=1/0,b=-1/0,y=-1/0;for(let p of o)for(let n=0;n<p.positions.length;n+=2)g=Math.min(g,p.positions[n]),b=Math.max(b,p.positions[n]),h=Math.min(h,p.positions[n+1]),y=Math.max(y,p.positions[n+1]);return g===1/0?null:{x:g,y:h,w:b-g,h:y-h}}function B(o,g,h,b,y,p,n,t,i,l,f,m,c,r){let e=f-i,a=m-l,x=c-i,d=r-l,w=e*d-x*a;if(Math.abs(w)<1e-9)return;let M=y-h,s=p-b,I=n-h,H=t-b,E=(M*d-I*a)/w,T=(s*d-H*a)/w,v=(I*e-M*x)/w,A=(H*e-s*x)/w,$=(h+y+n)/3,R=(b+p+t)/3,u=(k,C)=>{let P=Math.hypot(k-$,C-R)||1;return [k+(k-$)/P*.6,C+(C-R)/P*.6]};o.save(),o.beginPath(),o.moveTo(...u(h,b)),o.lineTo(...u(y,p)),o.lineTo(...u(n,t)),o.closePath(),o.clip(),o.transform(E,T,v,A,h-E*i-v*l,b-T*i-A*l),o.drawImage(g,0,0),o.restore();}function O(o){let g=parseInt(o.replace("#",""),16);return [(g>>16&255)/255,(g>>8&255)/255,(g&255)/255]}export{Y as a,J as b};
@@ -0,0 +1 @@
1
+ import {w,s,M,L,x,n,y as y$1,t,c}from'./chunk-UUX4NEC2.js';import y from'phaser';var b=class{constructor(t,r){this.scene=t;let e=this.rig=r.rig;this.art=r.art,this.skeleton=new w(e.data),this.sizes=s(e.data),this.lights=e.shading?M(e.data,e.shading):new Map,this.parts=new L(e,i=>this.drawsSkin(i)),r.look&&this.parts.applyLook(r.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new x(this.skeleton,e.data,e.mix),this.animator.setBlink(e.blink??null),this.play(r.animation??e.defaultAnimation,{mix:0}),this.root=t.add.container(r.x??0,r.y??0);for(let i=0;i<this.skeleton.slots.length;i++){let s=new y.GameObjects.Mesh2D(t,0,0,"__DEFAULT",[],[],true);s.setRenderAsTriangles(true),s.setVisible(false),this.root.add(s),this.slots.push({mesh:s,positions:null,vertices:[],indices:[],path:null,key:null,paint:null,waiting:false});}if(this.setScale(r.scale??1),r.autoUpdate!==false){let i=(s,o)=>this.update(o/1e3);t.events.on(y.Scenes.Events.UPDATE,i),this.offs.push(()=>t.events.off(y.Scenes.Events.UPDATE,i));}this.root.once(y.GameObjects.Events.DESTROY,()=>{for(let i of this.offs.splice(0))i();}),this.update(0);}scene;root;skeleton;animator;parts;slots=[];sizes;lights;skinsDirty=true;overlay=null;flashUntil=0;flashColor=16777215;facing=1;size=1;offs=[];asked=null;rig;art;play(t,r){return this.asked={name:t,...r?{options:r}:{}},this.animator.play(this.stanceOf(t),r)}animation(){return this.asked?.name??null}stanceOf(t){let r=this.parts;return this.rig.stance?.(t,e=>r.isWorn(e)?r.part(e):null)??t}on(t,r){let e=this.animator.on(t,r);return this.offs.push(e),e}setLook(t){this.parts.applyLook(t);}setArt(t){this.art=t;for(let r of this.slots)r.key=r.path=null,r.waiting=false;this.parts.setDrawable(r=>this.drawsSkin(r));}setPosition(t,r){return this.root.setPosition(t,r),this}setScale(t){return this.size=t,this.root.setScale(t*this.facing,t),this}setFacing(t){return this.facing=t,this.setScale(this.size)}setDepth(t){return this.root.setDepth(t),this}setVisible(t){return this.root.setVisible(t),this}setAlpha(t){return this.root.setAlpha(t),this}setOverlay(t){return this.overlay=t,this}flash(t=16777215,r=90){this.flashColor=t,this.flashUntil=this.scene.time.now+r;}worldPoint(t){let r=this.rig.anchors[t]??t,e=this.skeleton.bone(r).applied,i=this.root.getWorldTransformMatrix();return {x:i.tx+i.a*e.worldX+i.c*-e.worldY,y:i.ty+i.b*e.worldX+i.d*-e.worldY}}get displayHeight(){return this.rig.data.height*this.size}destroy(){this.root.destroy();}update(t){let r=this.skeleton,e=this.rig.expressions;if(e&&this.parts.setExpression(e.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,r.setSkins(this.parts.wornSkins().flatMap(o=>{let l=this.rig.data.skins.get(o);return l?[l]:[]}));let s=this.asked;s&&this.stanceOf(s.name)!==this.animator.current()&&this.animator.play(this.stanceOf(s.name),{...s.options,mix:.15});}this.animator.update(t),r.slots.forEach((s,o)=>{let l=this.parts.slotColor(o);if(!l)return;let a=n(l);s.color.r=(a>>16&255)/255,s.color.g=(a>>8&255)/255,s.color.b=(a&255)/255,s.color.a=1;}),r.updateWorldTransform();let i=this.flashUntil>this.scene.time.now;r.slots.forEach((s,o)=>this.drawSlot(o,i));}drawSlot(t,r){let e=this.slots[t],i=this.skeleton.slots[t],s=i.attachment,o=e.mesh;if(!s||i.color.a<=0){o.setVisible(false);return}let l=this.parts.artColor(t);if((e.path!==s.path||e.paint!==l)&&(e.path=s.path,e.paint=l,e.key=null,e.waiting=false),!e.key&&!e.waiting){let n=this.sizes.get(s.path)??{w:s.width,h:s.height},g=s.path,w=this.art.texture(g,n,()=>{e.path===g&&(e.waiting=false);},{paint:l,light:this.lights.get(g)??null});w?(e.key=w,o.setTexture(w)):e.waiting=true;}if(!e.key){o.setVisible(false);return}let a=y$1(this.skeleton,i,s,e.positions);e.positions=a.positions;let p=a.uvs.length/2,u=e.vertices;u.length=p*4;for(let n=0;n<p;n++)u[n*4]=a.positions[n*2],u[n*4+1]=-a.positions[n*2+1],u[n*4+2]=a.uvs[n*2],u[n*4+3]=a.uvs[n*2+1];let c=a.triangles,m=e.indices;if(m.length!==c.length/3*4){m.length=0;for(let n=0;n<c.length;n+=3)m.push(c[n],c[n+1],c[n+2],0);}else for(let n=0,g=0;n<c.length;n+=3,g+=4)m[g]=c[n],m[g+1]=c[n+1],m[g+2]=c[n+2];o.vertices=u,o.indices=m;let f=i.color,d=s.color,v=Math.round(f.r*d.r*255)<<16|Math.round(f.g*d.g*255)<<8|Math.round(f.b*d.b*255);this.overlay!==null&&(v=I(v,this.overlay)),r?o.setTint(this.flashColor).setTintMode(y.TintModes.FILL):o.setTint(v).setTintMode(y.TintModes.MULTIPLY),o.setAlpha(f.a*d.a),o.setVisible(true);}drawsSkin(t$1){return t(this.rig.data,t$1).every(r=>this.art.has(r))}};function I(h,t){let r=e=>Math.round((h>>e&255)*(t>>e&255)/255)<<e;return r(16)|r(8)|r(0)}var O=new WeakMap;function R(h,t,r){return `chr:${h}@${t}${r||""}`}function E(h,t,r,e,i,s,o={}){let l=r.paint?o.paint??null:null,a=R(t,i,l);if(h.exists(a))return a;let p=O.get(h);p||O.set(h,p=new Map);let u=p.get(a);if(u)return u.push(s),null;let c$1=[s];p.set(a,c$1);let m=new Image,f=()=>{p.delete(a);for(let d of c$1)d();};return m.onload=()=>{h.exists(a)||h.addImage(a,m),f();},m.onerror=()=>{console.warn(`[character] art ${t} did not render`),f();},m.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(c(r,e,i,{paint:l,light:o.light??null})),null}function z(h,t,r=2){return {has:e=>t.has(e),texture(e,i,s,o){let l=t.get(e);return l?E(h,e,l,i,r,s,o):null}}}function tt(h,t){return new Promise(r=>{let{width:e,height:i}=t,s=Math.min(2,Math.max(1,typeof devicePixelRatio=="number"&&devicePixelRatio||1));class o extends y.Scene{create(){this.cameras.main.setOrigin(0,0).setZoom(s);let p=t.scale??1,u=z(this.textures,t.catalog,Math.max(2,Math.ceil(p*s*1.5))),c=new b(this,{rig:t.rig,art:u,...t.look?{look:t.look}:{},x:e/2,y:Math.round(i*.88),scale:p});r({view:c,game:l,vector:u,destroy:()=>l.destroy(true)});}}let l=new y.Game({type:y.WEBGL,parent:h,width:Math.ceil(e*s),height:Math.ceil(i*s),scale:{mode:y.Scale.NONE,zoom:1/s},render:{autoMobileTextures:false},transparent:!t.background,...t.background?{backgroundColor:t.background}:{},scene:o,banner:false,audio:{noAudio:true}});})}export{b as a,z as b,tt as c};
@@ -0,0 +1,2 @@
1
+ var It="#1f1a21";var ne="currentColor";function se(s,t,e=1,o={}){let n=Math.max(1,Math.ceil(t.w*e)),r=Math.max(1,Math.ceil(t.h*e)),a=o.paint??s.paint,i=o.light?Ht(t,o.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}" viewBox="0 0 ${t.w} ${t.h}"${a?` color="${a}"`:""}>${i}<g stroke-linejoin="round" stroke-linecap="round"${i?' filter="url(#cel)"':""}>${s.svg}</g></svg>`}var K={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function Ht(s,t){let e=Math.max(K.min,Math.min(K.max,Math.min(s.w,s.h)*K.depth)),o=n=>+n.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${s.w}" height="${s.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*.7)}" result="body"/><feOffset in="body" dx="${o(t.x*e)}" dy="${o(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${K.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${o(-t.x*e*.42)}" dy="${o(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${K.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}function lt(s={}){let t=s.stroke??It,e=(s.opacity!==void 0?` opacity="${s.opacity}"`:"")+(s.holes?' fill-rule="evenodd"':"");return t==="none"?` stroke="none"${e}`:` stroke="${t}" stroke-width="${s.width??3.6}"${e}`}var jt=(s,t,e)=>`<path d="${s}" fill="${t}"${lt(e)}/>`,Jt=(s,t,e,o,n,r)=>`<ellipse cx="${s}" cy="${t}" rx="${e}" ry="${o}" fill="${n}"${lt(r)}/>`,re=(s,t,e,o,n)=>Jt(s,t,e,e,o,n),ie=(s,t,e,o,n,r,a)=>`<rect x="${s}" y="${t}" width="${e}" height="${o}" rx="${n}" fill="${r}"${lt(a)}/>`,ae=(s,t=It,e=2.2)=>`<path d="${s}" fill="none" stroke="${t}" stroke-width="${e}"/>`,le=(s,t,e)=>jt(s,t,{stroke:"none",...e!==void 0?{opacity:e}:{}}),ce=(s,t,...e)=>`<clipPath id="${s}"><path d="${t}" clip-rule="evenodd"/></clipPath><g clip-path="url(#${s})">${e.join("")}</g>`,he=(s,...t)=>`<g transform="${s}">${t.join("")}</g>`;function de(s,t){let e=parseInt(s.replace("#",""),16),o=i=>Math.max(0,Math.min(255,Math.round(t<0?i*(1+t):i+(255-i)*t))),n=o(e>>16&255),r=o(e>>8&255),a=o(e&255);return `#${(n<<16|r<<8|a).toString(16).padStart(6,"0")}`}var ue="#ffffff";function fe(s){let t=/^#?([0-9a-f]{6})$/i.exec(s.trim());return t?parseInt(t[1],16):16777215}function me(s){return `#${(s&16777215).toString(16).padStart(6,"0")}`}function X(s){let t=(s??"ffffffff").replace("#","").padEnd(8,"f"),e=o=>parseInt(t.slice(o,o+2),16)/255;return {r:e(0),g:e(2),b:e(4),a:e(6)}}var O=Math.PI/180,ct=1e-5;function Pt(s,t){return s.type==="ik"?new A(s,t):new dt(s,t)}var ht=s=>s>180?s-360:s<=-180?s+360:s,A=class{constructor(t,e){this.data=t;this.bones=t.bones.map(o=>e.bones[o.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?At(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Wt(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function At(s,t,e,o,n){let r=t.bone.parent;if(!r)return;t.modifyLocal(s);let a=r.applied,i=a.a,d=a.b,l=a.c,c=a.d,p=-t.shearX-t.rotation,h=i*c-d*l,u=e-a.worldX,f=o-a.worldY,m=(u*c-f*d)/h-t.x,b=(f*i-u*l)/h-t.y;p+=Math.atan2(b,m)/O,t.scaleX<0&&(p+=180),t.rotation+=ht(p)*n;}function Wt(s,t,e,o,n,r,a){t.modifyLocal(s),e.modifyLocal(s);let i=t.x,d=t.y,l=t.scaleX,c=t.scaleY,p=e.scaleX,h,u,f;l<0?(l=-l,h=180,f=-1):(h=0,f=1),c<0&&(c=-c,f=-f),p<0?(p=-p,u=180):u=0;let m=Math.abs(l-c)<=ct,b,y;m?(b=t.a*e.x+t.b*e.y+t.worldX,y=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,b=t.a*e.x+t.worldX,y=t.c*e.x+t.worldY);let x=t.bone.parent;if(!x)return;let g=x.applied,w=g.a,M=g.b,st=g.c,rt=g.d,D=w*rt-M*st,F=b-g.worldX,N=y-g.worldY;D=Math.abs(D)<=ct?0:1/D;let xt=(F*rt-N*M)*D-i,kt=(N*w-F*st)*D-d,k=Math.sqrt(xt*xt+kt*kt),P=e.bone.data.length*p;if(k<ct){At(s,t,o,n,a),e.rotation=0;return}F=o-g.worldX,N=n-g.worldY;let H=(F*rt-N*M)*D-i,j=(N*w-F*st)*D-d,G=H*H+j*j,R=0,T=0;if(m){P*=l;let v=(G-k*k-P*P)/(2*k*P);v<-1?(v=-1,T=Math.PI*r):v>1?(v=1,T=0):T=Math.acos(v)*r;let E=k+P*v,C=P*Math.sin(T);R=Math.atan2(j*E-H*C,H*E+j*C);}else {let v=l*P,E=c*P,C=v*v,J=E*E,it=Math.atan2(j,H),S=J*k*k+C*G-C*J,V=-2*J*k,wt=J-C,St=V*V-4*wt*S,Mt=false;if(St>=0){let I=Math.sqrt(St);V<0&&(I=-I),I=-(V+I)*.5;let Y=I/wt,$=S/I,L=Math.abs(Y)<Math.abs($)?Y:$,W=G-L*L;if(W>=0){let B=Math.sqrt(W)*r;R=it-Math.atan2(B,L),T=Math.atan2(B/c,(L-k)/l),Mt=true;}}if(!Mt){let I=Math.PI,Y=k-v,$=Y*Y,L=0,W=0,B=k+v,at=B*B,Tt=0;if(S=-v*k/(C-J),S>=-1&&S<=1){S=Math.acos(S);let _=v*Math.cos(S)+k,U=E*Math.sin(S),Z=_*_+U*U;Z<$&&(I=S,$=Z,Y=_,L=U),Z>at&&(W=S,at=Z,B=_,Tt=U);}G<=($+at)*.5?(R=it-Math.atan2(L*r,Y),T=I*r):(R=it-Math.atan2(Tt*r,B),T=W*r);}}let vt=Math.atan2(e.y,e.x)*f;R=ht((R-vt)/O+h-t.rotation),T=ht(((T+vt)/O-e.shearX)*f+u-e.rotation),t.rotation+=R*a,e.rotation+=T*a;}var dt=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(o=>e.bones[o.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let o=this.source.applied,n=this.data.offsets;for(let r of this.bones){let a=r.applied;a.modifyWorld(t);for(let i of this.data.properties){let d=Kt(t,o,i.prop,n)-i.offset;for(let l of i.to){let c=e[l.prop];c!==0&&qt(t,a,l.prop,l.offset+d*l.scale,c);}}}}};function Kt(s,t,e,o){let n=s.scaleX,r=s.scaleY;switch(e){case "rotate":{let a=(t.a*t.d-t.b*t.c)*n*r>0?1:-1,i=Math.atan2(t.c/r,t.a/n)/O+a*o.rotate;return i<0&&(i+=360),i}case "x":return (o.x*t.a+o.y*t.b+t.worldX)/n;case "y":return (o.x*t.c+o.y*t.d+t.worldY)/r;case "scaleX":return Math.hypot(t.a/n,t.c/r)+o.scaleX;case "scaleY":return Math.hypot(t.b/n,t.d/r)+o.scaleY;case "shearY":return (Math.atan2(t.d/r,t.b/n)-Math.atan2(t.c/r,t.a/n))/O-90+o.shearY}}function qt(s,t,e,o,n){let r=s.scaleX,a=s.scaleY;switch(e){case "rotate":{let i=t.a/r,d=t.b/r,l=t.c/a,c=t.d/a,p=o*O-Math.atan2(l,i);p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),p*=n;let h=Math.cos(p),u=Math.sin(p);t.a=(h*i-u*l)*r,t.b=(h*d-u*c)*r,t.c=(u*i+h*l)*a,t.d=(u*d+h*c)*a;return}case "x":t.worldX+=(o-t.worldX/r)*n*r;return;case "y":t.worldY+=(o-t.worldY/a)*n*a;return;case "scaleX":{let i=Math.hypot(t.a/r,t.c/a);i!==0&&(i=1+(o-i)*n/i,t.a*=i,t.c*=i);return}case "scaleY":{let i=Math.hypot(t.b/r,t.d/a);i!==0&&(i=1+(o-i)*n/i,t.b*=i,t.d*=i);return}case "shearY":{let i=t.b/r,d=t.d/a,l=Math.atan2(d,i),c=(o+90)*O;c-=l-Math.atan2(t.c/a,t.a/r),c>Math.PI?c-=2*Math.PI:c<-Math.PI&&(c+=2*Math.PI),c=l+c*n;let p=Math.hypot(i,d);t.b=Math.cos(c)*p*r,t.d=Math.sin(c)*p*a;return}}}var z=class{constructor(t){this.channels=t;}channels;times=[];values=[];kinds=[];samples=[];get count(){return this.times.length}add(t,e){this.times.push(t);for(let o=0;o<this.channels;o++)this.values.push(e[o]??0);this.kinds.push(0);for(let o=0;o<this.channels;o++)this.samples.push(null);}setCurve(t,e){if(e==="stepped"){this.kinds[t]=1;return}if(!Array.isArray(e)||t+1>=this.count)return;this.kinds[t]=2;let o=this.times[t],n=this.times[t+1];for(let r=0;r<this.channels;r++){let a=r*4;if(e.length<a+4)continue;let i=this.values[t*this.channels+r],d=this.values[(t+1)*this.channels+r];this.samples[t*this.channels+r]=Gt(o,i,Number(e[a]),Number(e[a+1]),Number(e[a+2]),Number(e[a+3]),n,d);}}keyAt(t){let e=this.times;if(!e.length||t<e[0])return -1;let o=0,n=e.length-1;for(;o<n;){let r=o+n+1>>1;e[r]<=t?o=r:n=r-1;}return o}value(t,e=0){let o=Math.max(0,this.keyAt(t)),n=this.channels,r=this.values[o*n+e];if(o+1>=this.count)return r;let a=this.kinds[o];if(a===1)return r;let i=this.times[o],d=this.times[o+1],l=this.values[(o+1)*n+e],c=this.samples[o*n+e];if(a!==2||!c)return r+(t-i)/(d-i)*(l-r);if(c[0]>t)return r+(t-i)/(c[0]-i)*(c[1]-r);for(let u=2;u<18;u+=2)if(c[u]>=t){let f=c[u-2],m=c[u-1];return m+(t-f)/(c[u]-f)*(c[u+1]-m)}let p=c[16],h=c[17];return h+(t-p)/(d-p)*(l-h)}};function Gt(s,t,e,o,n,r,a,i){let d=new Float32Array(18);for(let l=1;l<=9;l++){let c=l/10,p=1-c,h=p*p*p,u=3*p*p*c,f=3*p*c*c,m=c*c*c;d[(l-1)*2]=h*s+u*e+f*n+m*a,d[(l-1)*2+1]=h*t+u*o+f*r+m*i;}return d}var Dt=(s,t)=>s.bone!==void 0&&t.bones.has(s.bone)||s.slot!==void 0&&t.slots.has(s.slot),pt=class{constructor(t,e,o,n){this.name=t;this.duration=e;this.timelines=o;this.events=n;}name;duration;timelines;events;apply(t,e){for(let o of this.timelines)o.apply(t,e);}applyOnly(t,e,o){for(let n of this.timelines)Dt(n,o)&&n.apply(t,e);}touches(t){return this.timelines.some(e=>Dt(e,t))}},ut=class{constructor(t,e,o){this.bone=t;this.keys=e;this.props=o;}bone;keys;props;apply(t,e){if(this.keys.keyAt(e)<0)return;let o=t.bones[this.bone],n=o.pose,r=o.data;this.props.forEach((a,i)=>{let d=this.keys.value(e,i);switch(a){case "rotate":n.rotation=r.rotation+d;break;case "x":n.x=r.x+d;break;case "y":n.y=r.y+d;break;case "scaleX":n.scaleX=r.scaleX*d;break;case "scaleY":n.scaleY=r.scaleY*d;break}});}},tt=class{constructor(t,e,o){this.slot=t;this.keys=e;this.channels=o;}slot;keys;channels;apply(t,e){if(this.keys.keyAt(e)<0)return;let o=t.slots[this.slot].color;this.channels.forEach((n,r)=>o[n]=this.keys.value(e,r));}},ft=class{constructor(t,e,o){this.slot=t;this.times=e;this.names=o;}slot;times;names;apply(t,e){if(e<this.times[0])return;let o=0;for(;o+1<this.times.length&&this.times[o+1]<=e;)o++;t.slots[this.slot].attachmentKey=this.names[o];}},mt=class{constructor(t,e,o){this.constraint=t;this.keys=e;this.bends=o;}constraint;keys;bends;apply(t,e){let o=this.keys.keyAt(e);if(o<0)return;let n=t.constraints[this.constraint];n instanceof A&&(n.mix=this.keys.value(e,0),n.bendDirection=this.bends[o]);}};function Q(s,t,e){let o=new z(t);for(let n of s)o.add(n.time??0,e(n));return s.forEach((n,r)=>o.setCurve(r,n.curve)),o}var Vt={rotate:{props:["rotate"],read:s=>[s.value??0]},translate:{props:["x","y"],read:s=>[s.x??0,s.y??0]},translatex:{props:["x"],read:s=>[s.value??0]},translatey:{props:["y"],read:s=>[s.value??0]},scale:{props:["scaleX","scaleY"],read:s=>[s.x??1,s.y??1]},scalex:{props:["scaleX"],read:s=>[s.value??1]},scaley:{props:["scaleY"],read:s=>[s.value??1]}};function Rt(s,t,e){let o=[],n=0,r=i=>{for(let d of i)n=Math.max(n,d.time??0);};for(let[i,d]of Object.entries(t.bones??{})){let l=e.bone(i).index;for(let[c,p]of Object.entries(d)){let h=Vt[c];!h||!p.length||(r(p),o.push(new ut(l,Q(p,h.props.length,h.read),h.props)));}}for(let[i,d]of Object.entries(t.slots??{})){let l=e.slot(i).index;for(let[c,p]of Object.entries(d))if(p.length)if(r(p),c==="attachment")o.push(new ft(l,p.map(h=>h.time??0),p.map(h=>h.name??null)));else if(c==="rgba"||c==="rgb"){let h=c==="rgba"?["r","g","b","a"]:["r","g","b"],u=Q(p,h.length,f=>{let m=X(f.color);return h.map(b=>m[b])});o.push(new tt(l,u,[...h]));}else c==="alpha"&&o.push(new tt(l,Q(p,1,h=>[h.value??0]),["a"]));}for(let[i,d]of Object.entries(t.ik??{})){let l=e.constraints.find(c=>c.type==="ik"&&c.name===i);!l||!d.length||(r(d),o.push(new mt(l.index,Q(d,1,c=>[c.mix??1]),d.map(c=>c.bendPositive===false?-1:1))));}let a=(t.events??[]).map(i=>({time:i.time??0,name:i.name}));for(let i of a)n=Math.max(n,i.time);return new pt(s,n,o,a)}function Ie(s){let t=[],e=new Map;for(let h of s.bones){let u=h.parent?e.get(h.parent)??null:null,f={index:t.length,name:h.name,parent:u,children:[],length:h.length??0,x:h.x??0,y:h.y??0,rotation:h.rotation??0,scaleX:h.scaleX??1,scaleY:h.scaleY??1};u?.children.push(f),t.push(f),e.set(f.name,f);}let o=h=>{let u=e.get(h);if(!u)throw new Error(`no bone ${h}`);return u},n=[],r=new Map;for(let h of s.slots){let u={index:n.length,name:h.name,bone:o(h.bone),attachment:h.attachment??null,color:X(h.color)};n.push(u),r.set(u.name,u);}let a=h=>{let u=r.get(h);if(!u)throw new Error(`no slot ${h}`);return u},i=[];for(let h of s.constraints??[])if(h.type==="ik")i.push({type:"ik",index:i.length,name:h.name,bones:h.bones.map(o),target:o(h.target),mix:h.mix??1,bendDirection:h.bendPositive===false?-1:1});else if(h.type==="transform"){let u=[],f=new Set;for(let[y,x]of Object.entries(h.properties??{})){let g=[];for(let[w,M]of Object.entries(x.to??{}))f.add(w),g.push({prop:w,offset:M.offset??0,max:M.max??1,scale:M.scale??1});g.length&&u.push({prop:y,offset:x.offset??0,to:g});}let m=h.mixX??1,b=h.mixScaleX??1;i.push({type:"transform",index:i.length,name:h.name,source:o(h.source),bones:h.bones.map(o),offsets:{rotate:h.rotation??0,x:h.x??0,y:h.y??0,scaleX:h.scaleX??0,scaleY:h.scaleY??0,shearY:h.shearY??0},mix:{rotate:f.has("rotate")?h.mixRotate??1:0,x:f.has("x")?m:0,y:f.has("y")?h.mixY??m:0,scaleX:f.has("scaleX")?b:0,scaleY:f.has("scaleY")?h.mixScaleY??b:0,shearY:f.has("shearY")?h.mixShearY??1:0},properties:u});}let d=new Map,l=[],c=[];for(let h of s.skins){let u={name:h.name,attachments:new Map};for(let[f,m]of Object.entries(h.attachments??{})){let b=a(f).index,y=new Map;u.attachments.set(b,y);for(let[x,g]of Object.entries(m)){let w=g.type??"region";w==="linkedmesh"?c.push({skin:u,slot:b,key:x,a:g}):y.set(x,_t(x,g,w));}}d.set(u.name,u),l.push(u.name);}for(let{skin:h,slot:u,key:f,a:m}of c){let y=(d.get(m.skin??"default")??h).attachments.get(u)?.get(m.source??m.parent);if(!y||y.type!=="mesh")throw new Error(`linked mesh ${h.name}/${f}: no source mesh`);h.attachments.get(u).set(f,{...y,key:f,path:m.path??m.name??f,width:m.width??y.width,height:m.height??y.height,color:X(m.color)});}let p={width:s.skeleton?.width??0,height:s.skeleton?.height??0,x:s.skeleton?.x??0,y:s.skeleton?.y??0,bones:t,slots:n,constraints:i,skins:d,skinOrder:l,animations:new Map,events:Object.keys(s.events??{}),bone:o,slot:a};for(let[h,u]of Object.entries(s.animations??{}))p.animations.set(h,Rt(h,u,p));return p}function _t(s,t,e){let o=t.path??t.name??s;if(e==="mesh"){let n=Float32Array.from(t.uvs),r=n.length/2,a=t.vertices;return {type:"mesh",key:s,path:o,uvs:n,triangles:Uint16Array.from(t.triangles),vertices:Float32Array.from(a),weighted:a.length>n.length,vertexCount:r,width:t.width??0,height:t.height??0,color:X(t.color)}}return {type:"region",key:s,path:o,x:t.x??0,y:t.y??0,rotation:t.rotation??0,scaleX:t.scaleX??1,scaleY:t.scaleY??1,width:t.width??0,height:t.height??0,color:X(t.color)}}var Ct=new WeakMap;function Pe(s){let t=Ct.get(s);if(t)return t;t=new Map;for(let e of s.skins.values())for(let o of e.attachments.values())for(let n of o.values())t.has(n.path)||t.set(n.path,{w:n.width,h:n.height});return Ct.set(s,t),t}function Ae(s,t){let e=s.skins.get(t);if(!e)return [];let o=new Set;for(let n of e.attachments.values())for(let r of n.values())o.add(r.path);return [...o]}var q=Math.PI/180,yt=1e-5,et=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*q,o=(this.rotation+90+this.shearY)*q,n=Math.cos(e)*this.scaleX,r=Math.cos(o)*this.scaleY,a=Math.sin(e)*this.scaleX,i=Math.sin(o)*this.scaleY,d=this.bone.parent;if(!d){let c=t.scaleX,p=t.scaleY;this.a=n*c,this.b=r*c,this.c=a*p,this.d=i*p,this.worldX=this.x*c+t.x,this.worldY=this.y*p+t.y;return}let l=d.applied;this.worldX=l.a*this.x+l.b*this.y+l.worldX,this.worldY=l.c*this.x+l.d*this.y+l.worldY,this.a=l.a*n+l.b*a,this.b=l.a*r+l.b*i,this.c=l.c*n+l.d*a,this.d=l.c*r+l.d*i;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let o=e.applied,n=1/(o.a*o.d-o.b*o.c),r=o.d*n,a=o.b*n,i=o.c*n,d=o.a*n,l=this.worldX-o.worldX,c=this.worldY-o.worldY;this.x=l*r-c*a,this.y=c*d-l*i,this.set5(r*this.a-a*this.c,r*this.b-a*this.d,d*this.c-i*this.a,d*this.d-i*this.b);}set5(t,e,o,n){this.shearX=0;let r=t*t+o*o,a=e*e+n*n;if(r>yt){let i=Math.atan2(o,t)/q;this.rotation=i,this.scaleX=Math.sqrt(r),this.scaleY=Math.sqrt(a),a>yt?(this.shearY=Math.atan2(n,e)/q,t*n-e*o<0?(this.scaleY=-this.scaleY,this.shearY+=90-i):this.shearY-=90+i,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(a),this.shearY=0,this.rotation=a>yt?Math.atan2(n,e)/q-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let o=e.applied;o.world===t.updateId&&(o.local===t.updateId&&o.updateLocalTransform(t),o.world=0,o.resetWorld(t));}}},ot=class{constructor(t){this.data=t;this.pose=new et(this),this.applied=new et(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},bt=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},nt=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new ot(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new bt(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>Pt(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let o=this.skins.length-1;o>=0;o--){let n=this.skins[o].attachments.get(t)?.get(e);if(n)return n}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof ot?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Yt=class{constructor(t,e,o=.2){this.skeleton=t;this.data=e;this.defaultMix=o;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let o={bones:new Set(t.bones.map(n=>this.data.bone(n).index)),slots:new Set(t.slots.map(n=>this.data.slot(n).index))};this.blink={source:e,filter:o,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let o=this.data.animations.get(t);if(!o)return false;let n=e.mix??this.defaultMix;return this.previous=this.track&&n>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?n:0,this.track={animation:o,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let o=this.listeners.get(t)??new Set;return o.add(e),this.listeners.set(t,o),()=>o.delete(e)}update(t){let e=[],o=this.track;if(o&&!o.done){let n=o.time;o.time+=Math.max(0,t)*o.speed,this.collect(o,n,o.time,e),!o.loop&&o.time>=o.animation.duration&&(o.time=o.animation.duration,o.done=true,e.push({name:"end",animation:o.animation.name}));}if(this.previous){let n=this.previous;n.time+=Math.max(0,t)*n.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let n of e){for(let r of this.listeners.get(n.name)??[])r(n);for(let r of this.listeners.get("*")??[])r(n);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let o=this.blink;o&&o.at>=0&&o.source.applyOnly(t,o.options.from+o.at,o.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,o,n){let r=t.animation.duration;if(r<=0||o<=e)return;let a=Math.floor(e/r),i=t.loop?Math.floor(o/r):0;for(let d=a;d<=i;d++)for(let l of t.animation.events){let c=d*r+l.time;c>=e&&(c<o||!t.loop&&c<=o)&&n.push({name:l.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,o)=>{let n=e.pose;this.snapshot.set([n.x,n.y,n.rotation,n.scaleX,n.scaleY],o*5);}),t.slots.forEach((e,o)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],o*4)),t.constraints.forEach((e,o)=>{e instanceof A&&(this.ikSnapshot[o]=e.mix);});}blendFromSaved(t){let e=this.skeleton,o=(n,r)=>n+(r-n)*t;e.bones.forEach((n,r)=>{let a=this.snapshot,i=n.pose,d=r*5;i.x=o(a[d],i.x),i.y=o(a[d+1],i.y);let l=i.rotation-a[d+2];l-=Math.round(l/360)*360,i.rotation=a[d+2]+l*t,i.scaleX=o(a[d+3],i.scaleX),i.scaleY=o(a[d+4],i.scaleY);}),e.slots.forEach((n,r)=>{let a=this.slotSnapshot;n.color.r=o(a[r*4],n.color.r),n.color.g=o(a[r*4+1],n.color.g),n.color.b=o(a[r*4+2],n.color.b),n.color.a=o(a[r*4+3],n.color.a);}),e.constraints.forEach((n,r)=>{n instanceof A&&(n.mix=o(this.ikSnapshot[r],n.mix));});}};var Lt=Math.PI/180,Ut=new Float32Array([0,1,0,0,1,0,1,1]),Zt=new Uint16Array([0,1,2,2,3,0]),Bt=new WeakMap;function zt(s){let t=Bt.get(s);if(t)return t;let e=-s.width/2*s.scaleX,o=-s.height/2*s.scaleY,n=s.width/2*s.scaleX,r=s.height/2*s.scaleY,a=Math.cos(s.rotation*Lt),i=Math.sin(s.rotation*Lt),d=(l,c)=>[l*a-c*i+s.x,l*i+c*a+s.y];return t=Float32Array.from([...d(e,o),...d(e,r),...d(n,r),...d(n,o)]),Bt.set(s,t),t}function Xt(s,t,e,o){if(e.type==="region"){let n=o&&o.length===8?o:new Float32Array(8),r=zt(e),a=t.bone.applied;for(let i=0;i<8;i+=2){let d=r[i],l=r[i+1];n[i]=d*a.a+l*a.b+a.worldX,n[i+1]=d*a.c+l*a.d+a.worldY;}return {positions:n,uvs:Ut,triangles:Zt}}return Qt(s,t,e,o)}function Qt(s,t,e,o){let n=e.vertexCount*2,r=o&&o.length===n?o:new Float32Array(n),a=e.vertices;if(e.weighted){let i=0;for(let d=0;d<n;d+=2){let l=a[i++],c=0,p=0;for(let h=0;h<l;h++,i+=4){let u=s.bones[a[i]].applied,f=a[i+1],m=a[i+2],b=a[i+3];c+=(f*u.a+m*u.b+u.worldX)*b,p+=(f*u.c+m*u.d+u.worldY)*b;}r[d]=c,r[d+1]=p;}}else {let i=t.bone.applied;for(let d=0;d<n;d+=2){let l=a[d],c=a[d+1];r[d]=l*i.a+c*i.b+i.worldX,r[d+1]=l*i.c+c*i.d+i.worldY;}}return {positions:r,uvs:e.uvs,triangles:e.triangles}}var Ot=2;function Xe(...s){let t={v:2,parts:{},colors:{}},e;for(let o of s)o&&(Object.assign(t.parts,o.parts),Object.assign(t.colors,o.colors),o.body&&(e={...e,...o.body}));return e&&(t.body=e),t}function te(s){if(!s||typeof s!="object")return null;let t=s,e={},o=t.race;return typeof o=="string"&&/^[a-z][a-z0-9_-]{0,31}$/.test(o)&&(e.race=o),Object.keys(e).length?e:null}function Oe(s){if(!s||typeof s!="object")return null;let t=s;if(t.v!==1&&t.v!==2)return null;let e={},o={};if(t.parts&&typeof t.parts=="object")for(let[r,a]of Object.entries(t.parts))(a===null||typeof a=="string")&&(e[r]=a);if(t.colors&&typeof t.colors=="object")for(let[r,a]of Object.entries(t.colors))typeof a=="string"&&/^#[0-9a-f]{6}$/i.test(a)&&(o[r]=a);let n=t.v===2?te(t.body):null;return {v:2,parts:e,colors:o,...n?{body:n}:{}}}function $e(s){let t=s>>>0;return ()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function Fe(s){let t=2166136261;for(let e=0;e<s.length;e++)t=Math.imul(t^s.charCodeAt(e),16777619);return t>>>0}function gt(s,t){return t.length?t[Math.floor(s()*t.length)]:void 0}var ee=/^[a-z][a-z0-9_-]{0,31}$/,Et=class{races=new Map;constructor(t=[]){for(let e of t)this.register(e);}register(t){if(!ee.test(t.id))throw new Error(`race: bad id "${t.id}"`);if(!t.names.en)throw new Error(`race ${t.id}: no English name`);for(let e of t.skin??[])if(!/^#[0-9a-f]{6}$/i.test(e))throw new Error(`race ${t.id}: bad skin colour ${e}`);return this.races.set(t.id,t),this}get(t){return t&&this.races.get(t)||null}has(t){return this.races.has(t)}list(){return [...this.races.values()]}ids(){return [...this.races.keys()]}};function je(s,t="en"){return s.names[t]??s.names.en}function Je(){return {id:"race",apply(s){let t=s.race();if(t){for(let[e,o]of Object.entries(t.parts??{}))s.setWorn(e,o&&s.exists(o)?o:null);for(let[e,o]of Object.entries(t.replace??{}))for(let n of s.types())s.worn(n)===e&&s.setWorn(n,o&&s.exists(o)?o:null);for(let[e,o]of Object.entries(t.ban??{})){let n=s.worn(e);n&&(o==="all"||o.includes(n))&&s.setWorn(e,null);}}}}}function $t(s,t){return !s.skin?.length||s.skin.some(e=>e.toLowerCase()===t.toLowerCase())}function We(s,t,e="Skin"){let o={...s.defaults??{}};if(t)for(let[a,i]of Object.entries(s.options??{})){let d=gt(t,i);d!==void 0&&(o[a]=d);}let n={...s.colors??{}},r=t?gt(t,s.skin??[]):s.skin?.[0];return r&&(n[e]=r),{v:2,body:{race:s.id},parts:o,colors:n}}var Ft=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let o=(n,r)=>t.colorTargets.find(a=>(a.into??"tint")===r&&a.slotPrefixes.some(i=>n.startsWith(i)))?.id??null;this.slotTarget=t.data.slots.map(n=>o(n.name,"tint")),this.slotArt=t.data.slots.map(n=>o(n.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";body={};raceSaved=new Map;raceGiven=new Map;setDrawable(t){let e=new Set(this.rig.partTypes.filter(o=>!this.count(o.id)).map(o=>o.id));this.drawable=t,this.rebuildLists();for(let o of this.rig.partTypes){if(o.auto)continue;let n=this.chosen.get(o.id);(n&&!this.lists.get(o.id).includes(n)||!n&&e.has(o.id))&&this.chosen.set(o.id,this.first(o));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let l of this.rig.partTypes)t.set(l.id,!l.auto&&this.isWorn(l.id)?this.part(l.id):null);let e={worn:l=>t.get(l)??null,setWorn:(l,c)=>t.set(l,c),exists:l=>this.rig.data.skins.has(l)&&this.drawable(l),race:()=>this.race(),types:()=>this.rig.partTypes.map(l=>l.id)};for(let l of this.rig.rules)l.apply(e);let o=this.rig.expressions,n=this.face??this.emotionFace,r=n?o?.faces[n]:void 0;for(let[l,c]of Object.entries(r??{}))t.get(l)&&e.exists(c)&&t.set(l,c);let a=this.speech!=="rest"?o?.speech:void 0,i=a?.visemes[this.speech];a&&i&&t.get(a.type)&&e.exists(i)&&t.set(a.type,i);let d=[];for(let l of this.rig.partTypes){let c=t.get(l.id);c&&d.push(c);}return d}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}bodyLook(){return {...this.body}}race(){return this.rig.races?.get(this.body.race)??null}expression(){return this.face}equip(t,e){let o=this.lists.get(t);if(!o)return;let n;if(e===null||e===-1)n=null;else if(typeof e=="number")n=o[Math.max(0,Math.min(o.length-1,e))]??null;else if(o.includes(e))n=e;else return;n===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,n),this.emit({kind:"part",type:t,skin:n}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o>=e-1?-1:o+1):this.equip(t,(o+1)%e);}prev(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o<=-1?e-1:o-1):this.equip(t,(o-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,o=e&&this.rig.expressions?.faces[e]?e:null;o!==this.emotionFace&&(this.emotionFace=o,this.emit({kind:"expression",name:this.face??o}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}setBody(t){let e=this.race();if(this.body={...t},this.body.race!==e?.id){this.dropRaceColors();let o=new Map(this.colors);this.fitRaceColors(false),this.rememberRaceColors(o);}this.emit({kind:"body",body:this.bodyLook()});}setRace(t){let e={...this.body};t?e.race=t:delete e.race,this.setBody(e);}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let o=this.count(e.id);o&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*o));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,r]of this.colors)r&&(e[n]=r);let o=this.bodyLook();return {v:2,parts:t,colors:e,...Object.keys(o).length?{body:o}:{}}}applyLook(t){let e=this.race(),o=!!t.body&&t.body.race!==e?.id;o&&this.dropRaceColors();let n=new Map(this.colors);for(let[r,a]of Object.entries(t.parts??{}))a===void 0||this.typeDef(r)?.auto||(this.equip(r,a),a!==null&&this.part(r)===a&&this.hidden.set(r,false));for(let[r,a]of Object.entries(t.colors??{}))a&&this.setColor(r,a);t.body&&(this.body={...this.body,...t.body},o&&(this.fitRaceColors(true,t),this.rememberRaceColors(n)),this.emit({kind:"body",body:this.bodyLook()}));}dropRaceColors(){for(let[t,e]of this.raceGiven)this.color(t)?.toLowerCase()===e.toLowerCase()&&this.setColor(t,this.raceSaved.get(t)??null);this.raceGiven.clear(),this.raceSaved.clear();}rememberRaceColors(t){let e=this.race();if(!e)return;let o=new Set(Object.keys(e.colors??{}));e.skin?.length&&o.add(this.rig.skinColor??"Skin");for(let n of o){let r=this.color(n);!r||r===(t.get(n)??null)||(this.raceSaved.set(n,t.get(n)??null),this.raceGiven.set(n,r));}}fitRaceColors(t,e){let o=this.race();if(!o)return;for(let[i,d]of Object.entries(o.colors??{}))(t?e?.colors?.[i]:this.color(i))||this.setColor(i,d);let n=this.rig.skinColor??"Skin",r=this.color(n),a=t?e?.colors?.[n]??r:r;o.skin?.length&&(!a||!$t(o,a))&&this.setColor(n,o.skin[0]);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear(),this.body={},this.raceSaved.clear(),this.raceGiven.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var Nt=new WeakMap;function Ue(s,t){let e=Nt.get(s);if(e)return e;e=new Map;let o=new nt(s);o.setupPose(),o.updateWorldTransform();let[n,r]=t.light;for(let a of s.skins.values())for(let[i,d]of a.attachments)for(let l of d.values()){if(e.has(l.path)||t.skip?.some(b=>l.path.startsWith(b)))continue;let c=Xt(o,o.slots[i],l,null),p=oe(c.positions,c.uvs,l.width,l.height);if(!p)continue;let h=p.a*p.d-p.b*p.c;if(Math.abs(h)<1e-9)continue;let u=(p.d*n-p.b*r)/h,f=(-p.c*n+p.a*r)/h,m=Math.hypot(u,f)||1;e.set(l.path,{x:u/m,y:f/m});}return Nt.set(s,e),e}function oe(s,t,e,o){let n=t.length/2;if(n<3)return null;let r=0,a=0,i=0,d=0;for(let y=0;y<n;y++)r+=t[y*2]*e,a+=t[y*2+1]*o,i+=s[y*2],d+=s[y*2+1];r/=n,a/=n,i/=n,d/=n;let l=0,c=0,p=0,h=0,u=0,f=0,m=0;for(let y=0;y<n;y++){let x=t[y*2]*e-r,g=t[y*2+1]*o-a,w=s[y*2]-i,M=s[y*2+1]-d;l+=x*x,c+=x*g,p+=g*g,h+=w*x,u+=w*g,f+=M*x,m+=M*g;}let b=l*p-c*c;return Math.abs(b)<1e-9?null:{a:(h*p-u*c)/b,b:(u*l-h*c)/b,c:(f*p-m*c)/b,d:(m*l-f*c)/b}}
2
+ export{Xe as A,te as B,Oe as C,$e as D,Fe as E,gt as F,Et as G,je as H,Je as I,$t as J,We as K,Ft as L,Ue as M,It as a,ne as b,se as c,jt as d,Jt as e,re as f,ie as g,ae as h,le as i,ce as j,he as k,de as l,ue as m,fe as n,me as o,X as p,pt as q,Ie as r,Pe as s,Ae as t,ot as u,bt as v,nt as w,Yt as x,Xt as y,Ot as z};