@patterkit/runtime 0.20.0 → 0.21.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.
package/dist/index.d.cts CHANGED
@@ -680,8 +680,6 @@ declare class Engine {
680
680
  * across the family 2026-09-05, after a Storylets venue clock and this project's coverage driver
681
681
  * were each refused the one property they existed to move.) */
682
682
  setProperty(ref: string, value: ScalarValue): void;
683
- /** The shared `@patter` properties, for a live state inspector: each with its ref, type, current
684
- * value, declared default (for reset), and enum options. Mirrors the Unity / Godot ports. */
685
683
  /** The run's decisions, in order, each naming the flow it happened in. Empty unless the
686
684
  * run was opened with `log: true`. A flow's own log stays flow-local; this is the only
687
685
  * place a story spanning several flows reads as one sequence. */
@@ -696,6 +694,8 @@ declare class Engine {
696
694
  /** How many times each node has been entered across every flow, by node id: the shared count. With a
697
695
  * flow's own {@link Flow.getVisitCounts}, every visit count the run keeps, read without a save. */
698
696
  getVisitCounts(): Record<string, number>;
697
+ /** The shared `@patter` properties, for a live state inspector: each with its ref, type, current
698
+ * value, declared default (for reset), and enum options. Every runtime has the same call. */
699
699
  listProperties(): PropertyRow[];
700
700
  private splitShared;
701
701
  /** The shared `@patter` values alone, as `{ patter: {...} }`.
package/dist/index.d.ts CHANGED
@@ -680,8 +680,6 @@ declare class Engine {
680
680
  * across the family 2026-09-05, after a Storylets venue clock and this project's coverage driver
681
681
  * were each refused the one property they existed to move.) */
682
682
  setProperty(ref: string, value: ScalarValue): void;
683
- /** The shared `@patter` properties, for a live state inspector: each with its ref, type, current
684
- * value, declared default (for reset), and enum options. Mirrors the Unity / Godot ports. */
685
683
  /** The run's decisions, in order, each naming the flow it happened in. Empty unless the
686
684
  * run was opened with `log: true`. A flow's own log stays flow-local; this is the only
687
685
  * place a story spanning several flows reads as one sequence. */
@@ -696,6 +694,8 @@ declare class Engine {
696
694
  /** How many times each node has been entered across every flow, by node id: the shared count. With a
697
695
  * flow's own {@link Flow.getVisitCounts}, every visit count the run keeps, read without a save. */
698
696
  getVisitCounts(): Record<string, number>;
697
+ /** The shared `@patter` properties, for a live state inspector: each with its ref, type, current
698
+ * value, declared default (for reset), and enum options. Every runtime has the same call. */
699
699
  listProperties(): PropertyRow[];
700
700
  private splitShared;
701
701
  /** The shared `@patter` values alone, as `{ patter: {...} }`.
package/dist/index.js CHANGED
@@ -43,6 +43,18 @@ function buildTagIndex(bundle) {
43
43
  // src/engine.ts
44
44
  import { SAVE_VERSION } from "@patterkit/model";
45
45
  var astCache = /* @__PURE__ */ new WeakMap();
46
+ var tagIndexCache = /* @__PURE__ */ new WeakMap();
47
+ function tagIndexFor(bundle) {
48
+ let index = tagIndexCache.get(bundle);
49
+ if (!index) {
50
+ index = buildTagIndex(bundle);
51
+ tagIndexCache.set(bundle, index);
52
+ }
53
+ return index;
54
+ }
55
+ function tagsOf(host, id) {
56
+ return host.tagIndex.get(id)?.slice();
57
+ }
46
58
  var OWNER = "Patter";
47
59
  var esc = (id) => id.replace(/%/g, "%25").replace(/\//g, "%2F");
48
60
  var OWNS_REGISTRY = /* @__PURE__ */ Symbol("ownsRegistry");
@@ -171,7 +183,7 @@ var Engine = class _Engine {
171
183
  sceneGameIdToId: this.sceneGameIdToId,
172
184
  blockGameIdToId: this.blockGameIdToId,
173
185
  // same instances the engine resolves with
174
- tagIndex: buildTagIndex(bundle),
186
+ tagIndex: tagIndexFor(bundle),
175
187
  registry,
176
188
  ownsRegistry,
177
189
  patterBag,
@@ -430,18 +442,18 @@ var Engine = class _Engine {
430
442
  * delivered step carries. Empty array for an unknown id or a beat with no tags anywhere up the chain.
431
443
  */
432
444
  tagsForBeat(beatId) {
433
- return this.host.tagIndex.get(beatId) ?? [];
445
+ return tagsOf(this.host, beatId) ?? [];
434
446
  }
435
447
  /** A scene's own tags (by internal id or gameId address). Empty when none / unknown. */
436
448
  tagsForScene(sceneRef) {
437
449
  const id = this.resolveSceneRef(sceneRef);
438
- return (id != null ? this.host.tagIndex.get(id) : void 0) ?? [];
450
+ return (id != null ? tagsOf(this.host, id) : void 0) ?? [];
439
451
  }
440
452
  /** A block's accumulated tags (scene + block), by scene + block ref (id or gameId). Empty when none / unknown. */
441
453
  tagsForBlock(sceneRef, blockRef) {
442
454
  const sceneId = this.resolveSceneRef(sceneRef);
443
455
  const id = this.resolveBlockRef(sceneId, blockRef);
444
- return (id != null ? this.host.tagIndex.get(id) : void 0) ?? [];
456
+ return (id != null ? tagsOf(this.host, id) : void 0) ?? [];
445
457
  }
446
458
  /**
447
459
  * A scene's own author gameData (by internal id or gameId address): the RAW sparse overrides, exactly
@@ -560,7 +572,7 @@ var Engine = class _Engine {
560
572
  }
561
573
  /** One beat's static data (source locale), the same shape a delivered step carries. */
562
574
  beatInfo(beat) {
563
- const tags = this.host.tagIndex.get(beat.id);
575
+ const tags = tagsOf(this.host, beat.id);
564
576
  const info = { id: beat.id, kind: beat.kind };
565
577
  if (beat.kind === "line") {
566
578
  if (beat.character !== void 0) {
@@ -580,7 +592,7 @@ var Engine = class _Engine {
580
592
  }
581
593
  /** A `{ tags }` fragment for an id, present only when the id has accumulated tags (keeps output tidy). */
582
594
  tagsField(id) {
583
- const tags = this.host.tagIndex.get(id);
595
+ const tags = tagsOf(this.host, id);
584
596
  return tags && tags.length ? { tags } : {};
585
597
  }
586
598
  /** Retrieve an open flow by id (undefined if none / closed). */
@@ -717,8 +729,6 @@ var Engine = class _Engine {
717
729
  this.host.registry.set(scope, name, value, { host: true });
718
730
  if (this.host.journal && prev !== void 0) this.host.journal.undo.push(() => this.host.registry.set(scope, name, prev, { host: true }));
719
731
  }
720
- /** The shared `@patter` properties, for a live state inspector: each with its ref, type, current
721
- * value, declared default (for reset), and enum options. Mirrors the Unity / Godot ports. */
722
732
  /** The run's decisions, in order, each naming the flow it happened in. Empty unless the
723
733
  * run was opened with `log: true`. A flow's own log stays flow-local; this is the only
724
734
  * place a story spanning several flows reads as one sequence. */
@@ -750,6 +760,8 @@ var Engine = class _Engine {
750
760
  getVisitCounts() {
751
761
  return Object.fromEntries(this.host.sharedVisits);
752
762
  }
763
+ /** The shared `@patter` properties, for a live state inspector: each with its ref, type, current
764
+ * value, declared default (for reset), and enum options. Every runtime has the same call. */
753
765
  listProperties() {
754
766
  return this.host.patterSharedDecls.map((d) => ({
755
767
  name: d.name,
@@ -1737,7 +1749,7 @@ var Flow = class {
1737
1749
  };
1738
1750
  // -- Strings / beats ------------------------------------------------------
1739
1751
  beatResult(beat) {
1740
- const tags = this.host.tagIndex.get(beat.id);
1752
+ const tags = tagsOf(this.host, beat.id);
1741
1753
  const withTags = tags && tags.length ? { tags } : {};
1742
1754
  switch (beat.kind) {
1743
1755
  case "gameEvent":
@@ -1804,7 +1816,7 @@ var Flow = class {
1804
1816
  /** A replayed prompt as a step: the beat's id, gameData, and tags, and the text and speaker fields the
1805
1817
  * choice showed. */
1806
1818
  promptResult(beat, shown) {
1807
- const tags = this.host.tagIndex.get(beat.id);
1819
+ const tags = tagsOf(this.host, beat.id);
1808
1820
  const withTags = tags && tags.length ? { tags } : {};
1809
1821
  if (shown.kind === "text") return { type: "text", id: beat.id, text: shown.text, gameData: beat.gameData, ...withTags };
1810
1822
  return {