@markless/serializer 0.9.0 → 0.10.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.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { $ as PROTOCOL_VISIBLE_EVENT_NAME, A as formatEventHostEntries, B as STORAGE_PROTOCOL_VERSION, C as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, D as ProtocolConstantSyncPolicyCode, E as PROTOCOL_SYNC_POLICY_TABLE_TYPE, F as PROTOCOL_TEMPLATE_CONTENT_TAG, G as protocolRowSegment, H as protocolInstanceQualifies, I as ASYNC_PROTOCOL_VERSION, J as PROTOCOL_CONTAINER_END_COMMENT, K as protocolStateVersion, L as PROTOCOL_EVENT_ACTION_KIND, M as syncPolicyNeverActs, N as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, O as ProtocolEventHostEntry, P as PROTOCOL_RAW_TEXT_TAGS, Q as PROTOCOL_IDLE_EVENT_NAME, R as PROTOCOL_PAGE_SPACE_ID_PREFIXES, S as PROTOCOL_EVENT_HOST_DELEGATED_REF, T as PROTOCOL_EVENT_HOST_REF_SEPARATOR, U as protocolInstanceSegment, V as protocolInstancePath, W as protocolProjectionSegment, X as PROTOCOL_CONTAINER_START_COMMENT, Y as PROTOCOL_CONTAINER_HOST_NODE_ID, Z as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, _ as ProtocolViewPayload, a as ProtocolBranchIdrefSite, b as protocolEventDispatchesMarkless, c as ProtocolEventActionKind, d as ProtocolRowTemplateSlotValue, et as ASYNC_BOUNDARY_ARM, f as ProtocolStatePayload, g as ProtocolSyncPolicyCondition, h as ProtocolSyncPolicyBranch, i as ProtocolBranchContentRead, j as parseEventHostEntries, k as constantSyncPolicyCode, l as ProtocolEventRecord, m as ProtocolSyncPolicy, n as ProtocolArmRecordSet, o as ProtocolComposedGraphProp, p as ProtocolStreamedArmPatch, q as PROTOCOL_PROP_GRAPH_NODE_PREFIX, r as ProtocolAsyncBoundaryArm, s as ProtocolEventAction, t as ProtocolArmBranchRecord, u as ProtocolPayloadScripts, v as protocolElementHandleReadId, w as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, x as PROTOCOL_EVENT_HOST_ATTRIBUTE, y as protocolEventActionKind, z as PROTOCOL_PROPS_GRAPH_NODE_ID } from "./protocol-D9lZReby.js";
2
- import { a as PROTOCOL_TEMPLATED_LISTS, i as expandRecordTemplates, n as ProtocolTemplatedRecords, o as RuntimePayloadType$1, r as decodeProtocolPayloadLists } from "./protocol-record-templates-pAcSQYqD.js";
1
+ import { $ as protocolInstanceSegment, A as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, B as PROTOCOL_RAW_TEXT_TAGS, C as ProtocolViewPayload, D as PROTOCOL_EVENT_HOST_ATTRIBUTE, E as protocolEventDispatchesMarkless, F as constantSyncPolicyCode, G as PROTOCOL_PROPS_GRAPH_NODE_ID, H as ASYNC_PROTOCOL_VERSION, I as formatEventHostEntries, J as protocolBoundSymbolBaseEnd, K as STORAGE_PROTOCOL_VERSION, L as parseEventHostEntries, M as PROTOCOL_SYNC_POLICY_TABLE_TYPE, N as ProtocolConstantSyncPolicyCode, O as PROTOCOL_EVENT_HOST_DELEGATED_REF, P as ProtocolEventHostEntry, Q as protocolInstanceQualifies, R as syncPolicyNeverActs, S as ProtocolTemplatedRecords, T as protocolEventActionKind, U as PROTOCOL_EVENT_ACTION_KIND, V as PROTOCOL_TEMPLATE_CONTENT_TAG, W as PROTOCOL_PAGE_SPACE_ID_PREFIXES, X as protocolBoundSymbolSegment, Y as protocolBoundSymbolPrefix, Z as protocolInstancePath, _ as ProtocolStatePayload, a as ProtocolBranchIdrefSite, at as PROTOCOL_CONTAINER_HOST_NODE_ID, b as ProtocolSyncPolicyBranch, c as ProtocolEventAction, ct as PROTOCOL_IDLE_EVENT_NAME, d as ProtocolInstancePaths, et as protocolProjectionSegment, f as ProtocolPayloadScripts, g as ProtocolServedRecords, h as ProtocolRowTemplateSlotValue, i as ProtocolBranchContentRead, it as PROTOCOL_CONTAINER_END_COMMENT, j as PROTOCOL_EVENT_HOST_REF_SEPARATOR, k as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, l as ProtocolEventActionKind, lt as PROTOCOL_VISIBLE_EVENT_NAME, m as ProtocolRowTemplateBranchSlot, n as ProtocolArmRecordSet, nt as protocolStateVersion, o as ProtocolComposedGraphProp, ot as PROTOCOL_CONTAINER_START_COMMENT, p as ProtocolRowTemplateArm, q as protocolBoundSymbolBase, r as ProtocolAsyncBoundaryArm, rt as PROTOCOL_PROP_GRAPH_NODE_PREFIX, s as ProtocolElementAddress, st as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, t as ProtocolArmBranchRecord, tt as protocolRowSegment, u as ProtocolEventRecord, ut as ASYNC_BOUNDARY_ARM, v as ProtocolStreamedArmPatch, w as protocolElementHandleReadId, x as ProtocolSyncPolicyCondition, y as ProtocolSyncPolicy, z as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE } from "./protocol-J1KRChwU.js";
3
2
  import { a as SerializedPrimitive, c as TypedArrayName, d as serializeGraphValue, f as deserializeGraphValue, i as SerializedGraphPayload, l as jsonSourceWithNonFiniteNumbers, n as SerializationDiagnostic, o as SerializedRecord, r as SerializationResult, s as SerializedSlot, t as NonFiniteNumberName, u as nonFiniteName } from "./value-CRkHmkRz.js";
4
- import { a as RuntimePayloadError, c as assertProtocolStateCellPayload, d as decodePayloadScriptsWithVersion, f as invalidPayloadShapeError, i as RuntimePayloadDiagnostic, l as assertProtocolStatePayload, m as payloadScriptSelector, n as DecodedPayloadScripts, o as RuntimePayloadErrorCode, p as payloadInvalidError, r as EncodedPayloadScripts, s as RuntimePayloadType, t as decodePayloadScripts, u as assertProtocolViewPayload } from "./protocol-validation-storage-CBlNSV9-.js";
3
+ import { i as RuntimePayloadType$1, n as expandRecordTemplates, r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists } from "./protocol-record-templates-DX8X0uTO.js";
4
+ import { a as RuntimePayloadError, c as assertProtocolStateCellPayload, d as decodePayloadScriptsWithVersion, f as invalidPayloadShapeError, i as RuntimePayloadDiagnostic, l as assertProtocolStatePayload, m as payloadScriptSelector, n as DecodedPayloadScripts, o as RuntimePayloadErrorCode, p as payloadInvalidError, r as EncodedPayloadScripts, s as RuntimePayloadType, t as decodePayloadScripts, u as assertProtocolViewPayload } from "./protocol-validation-storage-Cg9OKvHQ.js";
5
5
  //#region src/payload-scripts.d.ts
6
6
  export type RenderPayloadScriptsInput = {
7
7
  readonly state: ProtocolStatePayload;
@@ -71,18 +71,56 @@ export declare class ProtocolStateSerializationError extends Error implements Pr
71
71
  constructor(diagnostic: ProtocolStateSerializationDiagnostic);
72
72
  }
73
73
  export declare function createProtocolStatePayload(input: ProtocolStatePayloadInput): ProtocolStatePayload;
74
+ /** Encodes one state value, throwing an error that names the state path and the value's type. */
75
+ export declare function serializeStateCellValue(cell: {
76
+ readonly graphNodeId: string;
77
+ readonly name?: string;
78
+ readonly value: unknown;
79
+ }): SerializedGraphPayload;
74
80
  export declare function serializeRuntimeStateCells(cells: ProtocolStatePayload['cells']): ProtocolStatePayload['cells'];
75
81
  export declare function serializeRuntimeAsyncSnapshots(computed: ProtocolStatePayload['computed']): ProtocolStatePayload['computed'];
76
82
  //#endregion
77
83
  //#region src/protocol-record-templates-encode.d.ts
84
+ /** The instance paths a payload's templated lists hold, by the index their rows name them under. */
85
+ type InstancePathTable = Map<string, number>;
78
86
  /**
79
87
  * Serves a record list as templates when that is shorter: records that differ only in their
80
88
  * values share one shape, each carries only the values that differ between them, and every field
81
- * name the list's key table spells becomes its index there.
89
+ * name the list's key table spells becomes its index there. Given a path table, a keyed row's
90
+ * instance path is one value however deep the row sits, and rows name it by its index there.
82
91
  */
83
- export declare function encodeRecordTemplates<T extends object>(records: ReadonlyArray<T>, keys?: string): ReadonlyArray<T> | ProtocolTemplatedRecords;
92
+ export declare function encodeRecordTemplates<T extends object>(records: ReadonlyArray<T>, keys?: string, paths?: InstancePathTable): ReadonlyArray<T> | ProtocolTemplatedRecords;
84
93
  /** The payload with each templated list served in its shorter form, for JSON.stringify. */
85
- export declare function encodeProtocolPayloadLists<T extends object>(type: RuntimePayloadType$1, payload: T): T;
94
+ export declare function encodeProtocolPayloadLists<T extends object>(type: RuntimePayloadType$1, served: T): T;
95
+ type ArmRecords = {
96
+ readonly events?: ReadonlyArray<{
97
+ readonly eventName: string;
98
+ readonly syncPolicy?: unknown;
99
+ }>;
100
+ };
101
+ /**
102
+ * A streamed arm's record set with its lists served in their shorter form. The stream boot reads the
103
+ * events before any decoder loads: they stay plain while one carries a sync policy, and a templated
104
+ * list travels beside the names the boot listens for.
105
+ */
106
+ export declare function encodeStreamedArmRecords<T extends ArmRecords>(records: T): T;
107
+ //#endregion
108
+ //#region src/protocol-shared-records-decode.d.ts
109
+ /**
110
+ * Gives every envelope of a freshly parsed state payload, in place, a copy of each shared subtree
111
+ * it references, under ids of its own: two references to one shared record are two objects.
112
+ */
113
+ export declare function expandSharedRecords<T>(state: T): T;
114
+ //#endregion
115
+ //#region src/protocol-shared-records.d.ts
116
+ /**
117
+ * Serves each subtree of records that two or more value envelopes hold once, in `sharedRecords`.
118
+ * A component that hands its rows their own subtrees as props holds every subtree again at each
119
+ * level above it. Only a subtree each of whose records the envelope reaches exactly once is
120
+ * shared, so `expandSharedRecords` rebuilds one fresh copy per reference and every decoded value
121
+ * keeps exactly the object identities it was served with. An envelope's root record stays its own.
122
+ */
123
+ export declare function shareStateRecords<T extends object>(state: T): T;
86
124
  //#endregion
87
125
  //#region src/resume-record-merge.d.ts
88
126
  type ResumeRecordSet = {
@@ -123,4 +161,4 @@ export declare function storageSlotEntryKeyFromGraphNodeId(graphNodeId: string):
123
161
  export declare function createStorageSeedMetadata(moduleId: string, driverKey: string, fallback: string): StorageSeedMetadata;
124
162
  export declare function createStorageSeedMetadataFromGraphNodeId(graphNodeId: string, driverKey: string, fallback: string): StorageSeedMetadata;
125
163
  //#endregion
126
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, DecodedPayloadScripts, EncodedPayloadScripts, NonFiniteNumberName, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_EVENT_HOST_ATTRIBUTE, PROTOCOL_EVENT_HOST_DELEGATED_REF, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, PROTOCOL_EVENT_HOST_REF_SEPARATOR, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_RAW_TEXT_TAGS, PROTOCOL_SYNC_POLICY_TABLE_TYPE, PROTOCOL_TEMPLATED_LISTS, PROTOCOL_TEMPLATE_CONTENT_TAG, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, type ProtocolConstantSyncPolicyCode, ProtocolEventAction, ProtocolEventActionKind, type ProtocolEventHostEntry, ProtocolEventRecord, ProtocolPayloadScripts, ProtocolRowTemplateSlotValue, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, type ProtocolTemplatedRecords, ProtocolViewPayload, type ResumeRecordSet, RuntimePayloadDiagnostic, RuntimePayloadError, RuntimePayloadErrorCode, RuntimePayloadType, STORAGE_PROTOCOL_VERSION, SerializationDiagnostic, SerializationResult, SerializedGraphPayload, SerializedPrimitive, SerializedRecord, SerializedSlot, TypedArrayName, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, constantSyncPolicyCode, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeProtocolPayloadLists, deserializeGraphValue, expandRecordTemplates, formatEventHostEntries, invalidPayloadShapeError, jsonSourceWithNonFiniteNumbers, nonFiniteName, parseEventHostEntries, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, serializeGraphValue, syncPolicyNeverActs };
164
+ export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, DecodedPayloadScripts, EncodedPayloadScripts, NonFiniteNumberName, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_EVENT_HOST_ATTRIBUTE, PROTOCOL_EVENT_HOST_DELEGATED_REF, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, PROTOCOL_EVENT_HOST_REF_SEPARATOR, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_RAW_TEXT_TAGS, PROTOCOL_SYNC_POLICY_TABLE_TYPE, PROTOCOL_TEMPLATED_LISTS, PROTOCOL_TEMPLATE_CONTENT_TAG, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, type ProtocolConstantSyncPolicyCode, ProtocolElementAddress, ProtocolEventAction, ProtocolEventActionKind, type ProtocolEventHostEntry, ProtocolEventRecord, ProtocolInstancePaths, ProtocolPayloadScripts, ProtocolRowTemplateArm, ProtocolRowTemplateBranchSlot, ProtocolRowTemplateSlotValue, ProtocolServedRecords, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, ProtocolTemplatedRecords, ProtocolViewPayload, type ResumeRecordSet, RuntimePayloadDiagnostic, RuntimePayloadError, RuntimePayloadErrorCode, RuntimePayloadType, STORAGE_PROTOCOL_VERSION, SerializationDiagnostic, SerializationResult, SerializedGraphPayload, SerializedPrimitive, SerializedRecord, SerializedSlot, TypedArrayName, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, constantSyncPolicyCode, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeProtocolPayloadLists, deserializeGraphValue, expandRecordTemplates, formatEventHostEntries, invalidPayloadShapeError, jsonSourceWithNonFiniteNumbers, nonFiniteName, parseEventHostEntries, payloadInvalidError, payloadScriptSelector, protocolBoundSymbolBase, protocolBoundSymbolBaseEnd, protocolBoundSymbolPrefix, protocolBoundSymbolSegment, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, serializeGraphValue, syncPolicyNeverActs };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { A as PROTOCOL_CONTAINER_END_COMMENT, C as protocolInstancePath, D as protocolRowSegment, E as protocolProjectionSegment, F as PROTOCOL_VISIBLE_EVENT_NAME, M as PROTOCOL_CONTAINER_START_COMMENT, N as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, O as protocolStateVersion, P as PROTOCOL_IDLE_EVENT_NAME, S as STORAGE_PROTOCOL_VERSION, T as protocolInstanceSegment, _ as ASYNC_BOUNDARY_ARM, a as PROTOCOL_EVENT_HOST_DELEGATED_REF, b as PROTOCOL_PAGE_SPACE_ID_PREFIXES, c as PROTOCOL_EVENT_HOST_REF_SEPARATOR, d as formatEventHostEntries, f as parseEventHostEntries, g as PROTOCOL_TEMPLATE_CONTENT_TAG, h as PROTOCOL_RAW_TEXT_TAGS, i as PROTOCOL_EVENT_HOST_ATTRIBUTE, j as PROTOCOL_CONTAINER_HOST_NODE_ID, k as PROTOCOL_PROP_GRAPH_NODE_PREFIX, l as PROTOCOL_SYNC_POLICY_TABLE_TYPE, m as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, n as protocolEventActionKind, o as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, p as syncPolicyNeverActs, r as protocolEventDispatchesMarkless, s as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, t as protocolElementHandleReadId, u as constantSyncPolicyCode, v as ASYNC_PROTOCOL_VERSION, w as protocolInstanceQualifies, x as PROTOCOL_PROPS_GRAPH_NODE_ID, y as PROTOCOL_EVENT_ACTION_KIND } from "./protocol-B57uFVtf.js";
1
+ import { A as protocolProjectionSegment, C as protocolBoundSymbolBase, D as protocolInstancePath, E as protocolBoundSymbolSegment, F as PROTOCOL_CONTAINER_HOST_NODE_ID, I as PROTOCOL_CONTAINER_START_COMMENT, L as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, M as protocolStateVersion, N as PROTOCOL_PROP_GRAPH_NODE_PREFIX, O as protocolInstanceQualifies, P as PROTOCOL_CONTAINER_END_COMMENT, R as PROTOCOL_IDLE_EVENT_NAME, S as STORAGE_PROTOCOL_VERSION, T as protocolBoundSymbolPrefix, _ as ASYNC_BOUNDARY_ARM, a as PROTOCOL_EVENT_HOST_DELEGATED_REF, b as PROTOCOL_PAGE_SPACE_ID_PREFIXES, c as PROTOCOL_EVENT_HOST_REF_SEPARATOR, d as formatEventHostEntries, f as parseEventHostEntries, g as PROTOCOL_TEMPLATE_CONTENT_TAG, h as PROTOCOL_RAW_TEXT_TAGS, i as PROTOCOL_EVENT_HOST_ATTRIBUTE, j as protocolRowSegment, k as protocolInstanceSegment, l as PROTOCOL_SYNC_POLICY_TABLE_TYPE, m as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, n as protocolEventActionKind, o as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, p as syncPolicyNeverActs, r as protocolEventDispatchesMarkless, s as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, t as protocolElementHandleReadId, u as constantSyncPolicyCode, v as ASYNC_PROTOCOL_VERSION, w as protocolBoundSymbolBaseEnd, x as PROTOCOL_PROPS_GRAPH_NODE_ID, y as PROTOCOL_EVENT_ACTION_KIND, z as PROTOCOL_VISIBLE_EVENT_NAME } from "./protocol-Bli_tA6H.js";
2
2
  import { deserializeGraphValue } from "./decode.js";
3
- import { i as PROTOCOL_RECORD_KEYS, n as expandRecordTemplates, r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists } from "./protocol-record-templates-xPHmxyXu.js";
4
- import { a as assertProtocolStatePayload, c as invalidPayloadShapeError, i as assertProtocolStateCellPayload, l as payloadInvalidError, n as isValidStorageKey, o as assertProtocolViewPayload, r as RuntimePayloadError, s as decodePayloadScriptsWithVersion, t as decodePayloadScripts, u as payloadScriptSelector } from "./protocol-validation-storage-D-K1WBE7.js";
3
+ import { a as PROTOCOL_RECORD_KEYS, i as PROTOCOL_TEMPLATED_LISTS, n as expandRecordTemplates, r as expandSharedRecords, t as decodeProtocolPayloadLists } from "./protocol-record-templates-Ctm9M01M.js";
4
+ import { a as assertProtocolStatePayload, c as invalidPayloadShapeError, i as assertProtocolStateCellPayload, l as payloadInvalidError, n as isValidStorageKey, o as assertProtocolViewPayload, r as RuntimePayloadError, s as decodePayloadScriptsWithVersion, t as decodePayloadScripts, u as payloadScriptSelector } from "./protocol-validation-storage-DlHC66oQ.js";
5
5
  //#region src/payload-scripts.ts
6
6
  function renderPayloadScripts(input, encodeLists) {
7
7
  return {
@@ -345,6 +345,17 @@ function createProtocolStatePayload(input) {
345
345
  ...storage.length > 0 ? { storage } : {}
346
346
  };
347
347
  }
348
+ /** Encodes one state value, throwing an error that names the state path and the value's type. */
349
+ function serializeStateCellValue(cell) {
350
+ const result = serializeGraphValue(cell.value);
351
+ if (result.ok) return result.payload;
352
+ throw protocolStateSerializationError({
353
+ graphNodeId: cell.graphNodeId,
354
+ name: cell.name ?? "",
355
+ valueKind: "unknown",
356
+ value: cell.value
357
+ }, result.diagnostics[0]);
358
+ }
348
359
  function serializeRuntimeStateCells(cells) {
349
360
  return cells.map((cell) => {
350
361
  if (cell.directValue === void 0) return cell;
@@ -439,10 +450,201 @@ function protocolStateSerializationError(cell, diagnostic) {
439
450
  });
440
451
  }
441
452
  //#endregion
453
+ //#region src/protocol-shared-records.ts
454
+ function isEnvelope(value) {
455
+ return typeof value === "object" && value !== null && "root" in value && Array.isArray(value.records);
456
+ }
457
+ const SNAPSHOT_ENVELOPES = [
458
+ "key",
459
+ "value",
460
+ "error"
461
+ ];
462
+ function envelopesOf(state) {
463
+ const found = [];
464
+ const take = (value) => {
465
+ if (isEnvelope(value) && value.records.length > 0) found.push(value);
466
+ };
467
+ for (const cell of state.cells ?? []) take(cell.value);
468
+ for (const computed of state.computed ?? []) {
469
+ take(computed.value);
470
+ for (const key of SNAPSHOT_ENVELOPES) take(computed.snapshot?.[key]);
471
+ }
472
+ return found;
473
+ }
474
+ function withEnvelopes(state, next) {
475
+ const swap = (holder, key) => {
476
+ const value = holder[key];
477
+ return next.has(value) ? {
478
+ ...holder,
479
+ [key]: next.get(value)
480
+ } : holder;
481
+ };
482
+ const { cells, computed } = state;
483
+ return {
484
+ ...state,
485
+ ...cells ? { cells: cells.map((cell) => swap(cell, "value")) } : {},
486
+ ...computed ? { computed: computed.map((entry) => {
487
+ const swapped = swap(entry, "value");
488
+ if (!entry.snapshot) return swapped;
489
+ const snapshot = SNAPSHOT_ENVELOPES.reduce(swap, entry.snapshot);
490
+ return snapshot === entry.snapshot ? swapped : {
491
+ ...swapped,
492
+ snapshot
493
+ };
494
+ }) } : {}
495
+ };
496
+ }
497
+ function mapSlot(slot, ref) {
498
+ return typeof slot === "object" && slot !== null && "$ref" in slot ? { $ref: ref(slot.$ref) } : slot;
499
+ }
500
+ function mapRecordSlots(record, ref) {
501
+ const map = (slot) => mapSlot(slot, ref);
502
+ switch (record.type) {
503
+ case "object": return {
504
+ ...record,
505
+ fields: record.fields.map(([key, slot]) => [key, map(slot)])
506
+ };
507
+ case "array": return {
508
+ ...record,
509
+ items: record.items.map(map)
510
+ };
511
+ case "map": return {
512
+ ...record,
513
+ entries: record.entries.map(([key, value]) => [map(key), map(value)])
514
+ };
515
+ case "set": return {
516
+ ...record,
517
+ values: record.values.map(map)
518
+ };
519
+ case "typed-array":
520
+ case "data-view": return {
521
+ ...record,
522
+ buffer: map(record.buffer)
523
+ };
524
+ default: return record;
525
+ }
526
+ }
527
+ function forEachRef(record, visit) {
528
+ const slot = (value) => {
529
+ if (typeof value === "object" && value !== null && "$ref" in value) visit(value.$ref);
530
+ };
531
+ if (record.type === "object") for (const [, value] of record.fields) slot(value);
532
+ else if (record.type === "array") record.items.forEach(slot);
533
+ else if (record.type === "map") for (const [key, value] of record.entries) {
534
+ slot(key);
535
+ slot(value);
536
+ }
537
+ else if (record.type === "set") record.values.forEach(slot);
538
+ else if (record.type === "typed-array" || record.type === "data-view") slot(record.buffer);
539
+ }
540
+ /**
541
+ * Serves each subtree of records that two or more value envelopes hold once, in `sharedRecords`.
542
+ * A component that hands its rows their own subtrees as props holds every subtree again at each
543
+ * level above it. Only a subtree each of whose records the envelope reaches exactly once is
544
+ * shared, so `expandSharedRecords` rebuilds one fresh copy per reference and every decoded value
545
+ * keeps exactly the object identities it was served with. An envelope's root record stays its own.
546
+ */
547
+ function shareStateRecords(state) {
548
+ const envelopes = envelopesOf(state);
549
+ if (envelopes.length < 2) return state;
550
+ const keyIndex = /* @__PURE__ */ new Map();
551
+ const holders = [];
552
+ const lastHolder = [];
553
+ const representative = [];
554
+ const keysByEnvelope = envelopes.map((envelope, holder) => {
555
+ const byId = new Map(envelope.records.map((record) => [record.id, record]));
556
+ const references = /* @__PURE__ */ new Map();
557
+ const count = (id) => references.set(id, (references.get(id) ?? 0) + 1);
558
+ const root = rootRecordId(envelope);
559
+ if (root !== void 0) count(root);
560
+ for (const record of envelope.records) forEachRef(record, count);
561
+ const keys = /* @__PURE__ */ new Map();
562
+ const keyOf = (id) => {
563
+ if (keys.has(id)) return keys.get(id);
564
+ keys.set(id, null);
565
+ const record = byId.get(id);
566
+ if (!record || references.get(id) !== 1) return null;
567
+ let reachedTwice = false;
568
+ const { id: _id, ...shape } = mapRecordSlots(record, (child) => {
569
+ const key = keyOf(child);
570
+ if (key === null) reachedTwice = true;
571
+ return key ?? -1;
572
+ });
573
+ if (reachedTwice) return null;
574
+ const text = JSON.stringify(shape);
575
+ let key = keyIndex.get(text);
576
+ if (key === void 0) {
577
+ key = keyIndex.size;
578
+ keyIndex.set(text, key);
579
+ holders.push(0);
580
+ lastHolder.push(-1);
581
+ representative.push({
582
+ record,
583
+ keys
584
+ });
585
+ }
586
+ if (lastHolder[key] !== holder) {
587
+ lastHolder[key] = holder;
588
+ holders[key]++;
589
+ }
590
+ keys.set(id, key);
591
+ return key;
592
+ };
593
+ for (const record of envelope.records) keyOf(record.id);
594
+ return keys;
595
+ });
596
+ let base = 0;
597
+ for (const envelope of envelopes) for (const record of envelope.records) base = Math.max(base, record.id + 1);
598
+ const sharedIds = /* @__PURE__ */ new Map();
599
+ const sharedRecords = [];
600
+ const sharedId = (key) => {
601
+ let id = sharedIds.get(key);
602
+ if (id !== void 0) return id;
603
+ id = base + sharedIds.size;
604
+ sharedIds.set(key, id);
605
+ const { record, keys } = representative[key];
606
+ const at = sharedRecords.push(record) - 1;
607
+ sharedRecords[at] = {
608
+ ...mapRecordSlots(record, (child) => sharedId(keys.get(child))),
609
+ id
610
+ };
611
+ return id;
612
+ };
613
+ const rewritten = /* @__PURE__ */ new Map();
614
+ envelopes.forEach((envelope, holder) => {
615
+ const keys = keysByEnvelope[holder];
616
+ const root = rootRecordId(envelope);
617
+ const shared = (id) => {
618
+ const key = keys.get(id);
619
+ return id !== root && key != null && holders[key] >= 2 ? key : void 0;
620
+ };
621
+ if (!envelope.records.some((record) => shared(record.id) !== void 0)) return;
622
+ rewritten.set(envelope, {
623
+ ...envelope,
624
+ records: envelope.records.flatMap((record) => shared(record.id) !== void 0 ? [] : [mapRecordSlots(record, (id) => {
625
+ const key = shared(id);
626
+ return key === void 0 ? id : sharedId(key);
627
+ })])
628
+ });
629
+ });
630
+ return rewritten.size > 0 ? {
631
+ ...withEnvelopes(state, rewritten),
632
+ sharedRecords
633
+ } : state;
634
+ }
635
+ function rootRecordId(envelope) {
636
+ const root = envelope.root;
637
+ return typeof root === "object" && root !== null && "$ref" in root ? root.$ref : void 0;
638
+ }
639
+ //#endregion
442
640
  //#region src/protocol-record-templates-encode.ts
443
641
  const HOLE = /\d+|r:[^:"\\]*:/g;
642
+ const PATH_HOLE = /"(?:[cpm]\d+:)*r:[^:"\\]*:(?:[cpm]\d+:|r:[^:"\\]*:)*|\d+|r:[^:"\\]*:/g;
643
+ const SEGMENT = /[cpm]\d+:|r:[^:]*:/g;
444
644
  const WHOLE_NUMBER = /^(?:0|[1-9]\d{0,14})$/;
445
645
  const TEMPLATED_SHARE = .75;
646
+ const PLAIN_OUTSIDE_ROWS = /* @__PURE__ */ new Set(["cells", "events"]);
647
+ const IN_A_ROW = /"(?:[cpm]\d+:)*r:[^:"\\]*:/;
446
648
  const keyRefsByTable = /* @__PURE__ */ new Map();
447
649
  function keyRefs(keys) {
448
650
  let refs = keyRefsByTable.get(keys);
@@ -455,13 +657,15 @@ function keyRefs(keys) {
455
657
  }
456
658
  return refs;
457
659
  }
660
+ const isPath = (hole) => hole[0] === "\"";
458
661
  /**
459
662
  * Serves a record list as templates when that is shorter: records that differ only in their
460
663
  * values share one shape, each carries only the values that differ between them, and every field
461
- * name the list's key table spells becomes its index there.
664
+ * name the list's key table spells becomes its index there. Given a path table, a keyed row's
665
+ * instance path is one value however deep the row sits, and rows name it by its index there.
462
666
  */
463
- function encodeRecordTemplates(records, keys = "") {
464
- if (records.length < 2) return records;
667
+ function encodeRecordTemplates(records, keys = "", paths) {
668
+ if (records.length < (paths ? 1 : 2)) return records;
465
669
  const refer = keys ? keyRefs(keys) : (text) => text;
466
670
  const groups = /* @__PURE__ */ new Map();
467
671
  const texts = [];
@@ -469,9 +673,16 @@ function encodeRecordTemplates(records, keys = "") {
469
673
  let text = JSON.stringify(records[index]);
470
674
  if (text.includes("^")) text = text.replaceAll("^", "\\u005e");
471
675
  if (text.includes("~")) text = text.replaceAll("~", "\\u007e");
676
+ if (text.includes("`")) text = text.replaceAll("`", "\\u0060");
472
677
  texts.push(text);
473
- const values = text.match(HOLE);
474
- const key = values ? text.replace(HOLE, "^") : text;
678
+ const values = [...text.matchAll(paths ? PATH_HOLE : HOLE)];
679
+ let key = "";
680
+ let at = 0;
681
+ for (const hole of values) {
682
+ key += text.slice(at, hole.index) + (isPath(hole[0]) ? "\"`" : "^");
683
+ at = hole.index + hole[0].length;
684
+ }
685
+ key += text.slice(at);
475
686
  let group = groups.get(key);
476
687
  if (!group) groups.set(key, group = {
477
688
  key,
@@ -481,10 +692,18 @@ function encodeRecordTemplates(records, keys = "") {
481
692
  group.rows.push(values);
482
693
  group.members.push(index);
483
694
  }
695
+ const known = paths?.size ?? 0;
696
+ const pathIndex = (path) => {
697
+ let index = paths.get(path);
698
+ if (index === void 0) paths.set(path, index = paths.size);
699
+ return index;
700
+ };
484
701
  const templates = [];
485
702
  const refs = [];
486
703
  for (const group of groups.values()) {
487
- if (group.rows.length === 1) {
704
+ const first = group.rows[0];
705
+ const alone = group.rows.length === 1;
706
+ if (alone && !first.some((hole) => isPath(hole[0]))) {
488
707
  const member = group.members[0];
489
708
  const template = refer(texts[member]);
490
709
  if (JSON.stringify(template).length < texts[member].length) {
@@ -494,21 +713,19 @@ function encodeRecordTemplates(records, keys = "") {
494
713
  continue;
495
714
  }
496
715
  const index = templates.length;
497
- const first = group.rows[0];
498
- const slots = first ? valueSlots(group.rows) : {
499
- of: [],
500
- columns: []
501
- };
502
- const parts = group.key.split("^");
716
+ const slots = valueSlots(group.rows, alone);
717
+ const parts = group.key.split(/\^|"`/);
503
718
  let text = parts[0];
504
719
  for (let column = 0; column < parts.length - 1; column++) {
505
720
  const slot = slots.of[column];
506
- text += (slot < 0 ? first[column] : `^${slot}`) + parts[column + 1];
721
+ const hole = first[column][0];
722
+ text += (slot < 0 ? hole : isPath(hole) ? `"\`${slot}` : `^${slot}`) + parts[column + 1];
507
723
  }
508
724
  templates.push(refer(text));
509
725
  group.rows.forEach((values, row) => {
510
726
  refs[group.members[row]] = slots.columns.length ? [index, ...slots.columns.map((column) => {
511
- const value = values[column];
727
+ const value = values[column][0];
728
+ if (isPath(value)) return pathIndex(value.slice(1));
512
729
  return WHOLE_NUMBER.test(value) ? Number(value) : value;
513
730
  })] : index;
514
731
  });
@@ -518,19 +735,28 @@ function encodeRecordTemplates(records, keys = "") {
518
735
  r: refs
519
736
  };
520
737
  const plain = texts.reduce((total, text) => total + text.length + 1, 1);
521
- return JSON.stringify(encoded).length <= plain * TEMPLATED_SHARE ? encoded : records;
738
+ let table = 0;
739
+ if (paths) {
740
+ for (const [path, at] of paths) if (at >= known) table += path.length + 3;
741
+ }
742
+ if (JSON.stringify(encoded).length + table <= plain * TEMPLATED_SHARE) return encoded;
743
+ if (paths) {
744
+ for (const [path, at] of paths) if (at >= known) paths.delete(path);
745
+ }
746
+ return records;
522
747
  }
523
- function valueSlots(rows) {
748
+ function valueSlots(rows, alone) {
524
749
  const width = rows[0].length;
525
750
  const of = [];
526
751
  const columns = [];
752
+ const kind = (column) => isPath(rows[0][column][0]);
527
753
  for (let column = 0; column < width; column++) {
528
- const value = rows[0][column];
529
- if (rows.every((row) => row[column] === value)) {
754
+ const value = rows[0][column][0];
755
+ if (alone ? !kind(column) : rows.every((row) => row[column][0] === value)) {
530
756
  of.push(-1);
531
757
  continue;
532
758
  }
533
- const same = columns.findIndex((held) => rows.every((row) => row[held] === row[column]));
759
+ const same = columns.findIndex((held) => kind(held) === kind(column) && rows.every((row) => row[held][0] === row[column][0]));
534
760
  of.push(same >= 0 ? same : columns.push(column) - 1);
535
761
  }
536
762
  return {
@@ -538,18 +764,66 @@ function valueSlots(rows) {
538
764
  columns
539
765
  };
540
766
  }
767
+ /**
768
+ * The served table of a payload's instance paths: a path whose parent instance the table also
769
+ * holds is that entry's index and the segments it adds, so a path costs the same at any depth.
770
+ */
771
+ function encodeInstancePaths(paths) {
772
+ return [...paths.keys()].map((path) => {
773
+ const segments = path.match(SEGMENT) ?? [];
774
+ for (let length = segments.length - 1; length > 0; length--) {
775
+ const parent = segments.slice(0, length).join("");
776
+ const at = paths.get(parent);
777
+ if (at !== void 0) return [at, path.slice(parent.length)];
778
+ }
779
+ return path;
780
+ });
781
+ }
541
782
  /** The payload with each templated list served in its shorter form, for JSON.stringify. */
542
- function encodeProtocolPayloadLists(type, payload) {
783
+ function encodeProtocolPayloadLists(type, served) {
784
+ const payload = type === "markless/state" ? shareStateRecords(served) : served;
543
785
  const keys = PROTOCOL_RECORD_KEYS[type];
786
+ const paths = /* @__PURE__ */ new Map();
544
787
  let encoded;
788
+ const inRows = {};
545
789
  for (const key of PROTOCOL_TEMPLATED_LISTS[type]) {
546
790
  const list = payload[key];
547
791
  if (!Array.isArray(list)) continue;
548
- const served = encodeRecordTemplates(list, keys[key]);
792
+ if (PLAIN_OUTSIDE_ROWS.has(key)) {
793
+ const rows = new Set(list.filter((record) => IN_A_ROW.test(JSON.stringify(record))));
794
+ const served = encodeRecordTemplates([...rows], keys[key], paths);
795
+ if (Array.isArray(served)) continue;
796
+ inRows[key] = served;
797
+ (encoded ??= { ...payload })[key] = list.map((record) => rows.has(record) ? null : record);
798
+ continue;
799
+ }
800
+ const served = encodeRecordTemplates(list, keys[key], paths);
549
801
  if (served !== list) (encoded ??= { ...payload })[key] = served;
550
802
  }
803
+ if (encoded && Object.keys(inRows).length) encoded.inRows = inRows;
804
+ if (encoded && paths.size) encoded.instancePaths = encodeInstancePaths(paths);
551
805
  return encoded ?? payload;
552
806
  }
807
+ /**
808
+ * A streamed arm's record set with its lists served in their shorter form. The stream boot reads the
809
+ * events before any decoder loads: they stay plain while one carries a sync policy, and a templated
810
+ * list travels beside the names the boot listens for.
811
+ */
812
+ function encodeStreamedArmRecords(records) {
813
+ const events = records.events ?? [];
814
+ if (events.some((event) => event.syncPolicy)) return {
815
+ ...encodeProtocolPayloadLists("markless/view", {
816
+ ...records,
817
+ events: []
818
+ }),
819
+ events
820
+ };
821
+ const served = encodeProtocolPayloadLists("markless/view", records);
822
+ return served.inRows?.events ? {
823
+ ...served,
824
+ eventNames: [...new Set(events.map((event) => event.eventName))]
825
+ } : served;
826
+ }
553
827
  //#endregion
554
828
  //#region src/resume-record-merge.ts
555
829
  function mergeResumeRecordDelta(baseline, delta) {
@@ -755,4 +1029,4 @@ function createStorageCookieReader(cookieHeader) {
755
1029
  return (driverKey) => values.get(storageCookieName(driverKey));
756
1030
  }
757
1031
  //#endregion
758
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_EVENT_HOST_ATTRIBUTE, PROTOCOL_EVENT_HOST_DELEGATED_REF, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, PROTOCOL_EVENT_HOST_REF_SEPARATOR, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_RAW_TEXT_TAGS, PROTOCOL_SYNC_POLICY_TABLE_TYPE, PROTOCOL_TEMPLATED_LISTS, PROTOCOL_TEMPLATE_CONTENT_TAG, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolStateSerializationError, RuntimePayloadError, STORAGE_PROTOCOL_VERSION, STORAGE_RENDER_CONTEXT_READER, STORAGE_SLOT_SYMBOL_KEY, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, classifyResumeRecordDelta, constantSyncPolicyCode, createProtocolStatePayload, createStorageCookieReader, createStorageSeedMetadata, createStorageSeedMetadataFromGraphNodeId, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeProtocolPayloadLists, decodeStorageCookieValue, deserializeGraphValue, encodeProtocolPayloadLists, encodeRecordTemplates, escapeScriptJson, expandRecordTemplates, formatEventHostEntries, invalidPayloadShapeError, isValidStorageKey, jsonSourceWithNonFiniteNumbers, mergeResumeRecordDelta, nonFiniteName, parseEventHostEntries, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, renderPayloadScripts, serializeGraphValue, serializeRuntimeAsyncSnapshots, serializeRuntimeStateCells, storageAttributeName, storageCookieAssignment, storageCookieName, storageSlotEntryKey, storageSlotEntryKeyFromGraphNodeId, syncPolicyNeverActs };
1032
+ export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_EVENT_HOST_ATTRIBUTE, PROTOCOL_EVENT_HOST_DELEGATED_REF, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, PROTOCOL_EVENT_HOST_REF_SEPARATOR, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_RAW_TEXT_TAGS, PROTOCOL_SYNC_POLICY_TABLE_TYPE, PROTOCOL_TEMPLATED_LISTS, PROTOCOL_TEMPLATE_CONTENT_TAG, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolStateSerializationError, RuntimePayloadError, STORAGE_PROTOCOL_VERSION, STORAGE_RENDER_CONTEXT_READER, STORAGE_SLOT_SYMBOL_KEY, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, classifyResumeRecordDelta, constantSyncPolicyCode, createProtocolStatePayload, createStorageCookieReader, createStorageSeedMetadata, createStorageSeedMetadataFromGraphNodeId, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeProtocolPayloadLists, decodeStorageCookieValue, deserializeGraphValue, encodeProtocolPayloadLists, encodeRecordTemplates, encodeStreamedArmRecords, escapeScriptJson, expandRecordTemplates, expandSharedRecords, formatEventHostEntries, invalidPayloadShapeError, isValidStorageKey, jsonSourceWithNonFiniteNumbers, mergeResumeRecordDelta, nonFiniteName, parseEventHostEntries, payloadInvalidError, payloadScriptSelector, protocolBoundSymbolBase, protocolBoundSymbolBaseEnd, protocolBoundSymbolPrefix, protocolBoundSymbolSegment, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, renderPayloadScripts, serializeGraphValue, serializeRuntimeAsyncSnapshots, serializeRuntimeStateCells, serializeStateCellValue, shareStateRecords, storageAttributeName, storageCookieAssignment, storageCookieName, storageSlotEntryKey, storageSlotEntryKeyFromGraphNodeId, syncPolicyNeverActs };
@@ -56,6 +56,32 @@ function protocolInstanceQualifies(graphNodeId) {
56
56
  if (PROTOCOL_PAGE_SPACE_ID_PREFIXES.some((prefix) => local.startsWith(prefix))) return false;
57
57
  return PROTOCOL_INSTANCE_QUALIFIABLE.some((prefix) => local.startsWith(prefix)) ? true : void 0;
58
58
  }
59
+ const PROTOCOL_BOUND_PREFIX = "bound:";
60
+ function protocolBoundSymbolSegment(value) {
61
+ return encodeURIComponent(value).replace(/\(/g, "%28").replace(/\)/g, "%29");
62
+ }
63
+ function protocolBoundSymbolPrefix(base) {
64
+ return PROTOCOL_BOUND_PREFIX + (base.startsWith(PROTOCOL_BOUND_PREFIX) ? `(${base})` : protocolBoundSymbolSegment(base));
65
+ }
66
+ /** The index of the `:` that ends a bound id's base, or -1 for any other id. */
67
+ function protocolBoundSymbolBaseEnd(id) {
68
+ if (!id.startsWith(PROTOCOL_BOUND_PREFIX)) return -1;
69
+ for (let depth = 0, at = 6; at < id.length; at++) if (id[at] === "(") depth++;
70
+ else if (id[at] === ")") depth--;
71
+ else if (id[at] === ":" && !depth) return at;
72
+ return -1;
73
+ }
74
+ /** The symbol id a bound id binds, one level down, or undefined for any other id. */
75
+ function protocolBoundSymbolBase(id) {
76
+ const end = protocolBoundSymbolBaseEnd(id);
77
+ if (end < 0) return void 0;
78
+ const base = id.slice(6, end);
79
+ try {
80
+ return base[0] === "(" ? base.slice(1, -1) : decodeURIComponent(base);
81
+ } catch {
82
+ return;
83
+ }
84
+ }
59
85
  //#endregion
60
86
  //#region src/async-boundary-arm.ts
61
87
  const ASYNC_BOUNDARY_ARM = {
@@ -162,4 +188,4 @@ function protocolElementHandleReadId(handleGraphNodeId) {
162
188
  return `markless:element-handle-id|${handleGraphNodeId}`;
163
189
  }
164
190
  //#endregion
165
- export { PROTOCOL_CONTAINER_END_COMMENT as A, protocolInstancePath as C, protocolRowSegment as D, protocolProjectionSegment as E, PROTOCOL_VISIBLE_EVENT_NAME as F, PROTOCOL_CONTAINER_START_COMMENT as M, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE as N, protocolStateVersion as O, PROTOCOL_IDLE_EVENT_NAME as P, STORAGE_PROTOCOL_VERSION as S, protocolInstanceSegment as T, ASYNC_BOUNDARY_ARM as _, PROTOCOL_EVENT_HOST_DELEGATED_REF as a, PROTOCOL_PAGE_SPACE_ID_PREFIXES as b, PROTOCOL_EVENT_HOST_REF_SEPARATOR as c, formatEventHostEntries as d, parseEventHostEntries as f, PROTOCOL_TEMPLATE_CONTENT_TAG as g, PROTOCOL_RAW_TEXT_TAGS as h, PROTOCOL_EVENT_HOST_ATTRIBUTE as i, PROTOCOL_CONTAINER_HOST_NODE_ID as j, PROTOCOL_PROP_GRAPH_NODE_PREFIX as k, PROTOCOL_SYNC_POLICY_TABLE_TYPE as l, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE as m, protocolEventActionKind as n, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR as o, syncPolicyNeverActs as p, protocolEventDispatchesMarkless as r, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR as s, protocolElementHandleReadId as t, constantSyncPolicyCode as u, ASYNC_PROTOCOL_VERSION as v, protocolInstanceQualifies as w, PROTOCOL_PROPS_GRAPH_NODE_ID as x, PROTOCOL_EVENT_ACTION_KIND as y };
191
+ export { protocolProjectionSegment as A, protocolBoundSymbolBase as C, protocolInstancePath as D, protocolBoundSymbolSegment as E, PROTOCOL_CONTAINER_HOST_NODE_ID as F, PROTOCOL_CONTAINER_START_COMMENT as I, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE as L, protocolStateVersion as M, PROTOCOL_PROP_GRAPH_NODE_PREFIX as N, protocolInstanceQualifies as O, PROTOCOL_CONTAINER_END_COMMENT as P, PROTOCOL_IDLE_EVENT_NAME as R, STORAGE_PROTOCOL_VERSION as S, protocolBoundSymbolPrefix as T, ASYNC_BOUNDARY_ARM as _, PROTOCOL_EVENT_HOST_DELEGATED_REF as a, PROTOCOL_PAGE_SPACE_ID_PREFIXES as b, PROTOCOL_EVENT_HOST_REF_SEPARATOR as c, formatEventHostEntries as d, parseEventHostEntries as f, PROTOCOL_TEMPLATE_CONTENT_TAG as g, PROTOCOL_RAW_TEXT_TAGS as h, PROTOCOL_EVENT_HOST_ATTRIBUTE as i, protocolRowSegment as j, protocolInstanceSegment as k, PROTOCOL_SYNC_POLICY_TABLE_TYPE as l, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE as m, protocolEventActionKind as n, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR as o, syncPolicyNeverActs as p, protocolEventDispatchesMarkless as r, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR as s, protocolElementHandleReadId as t, constantSyncPolicyCode as u, ASYNC_PROTOCOL_VERSION as v, protocolBoundSymbolBaseEnd as w, PROTOCOL_PROPS_GRAPH_NODE_ID as x, PROTOCOL_EVENT_ACTION_KIND as y, PROTOCOL_VISIBLE_EVENT_NAME as z };
@@ -1,3 +1,4 @@
1
+ import { o as SerializedRecord } from "./value-CRkHmkRz.js";
1
2
  //#region src/async-boundary-arm.d.ts
2
3
  declare const ASYNC_BOUNDARY_ARM: {
3
4
  readonly try: 0;
@@ -42,6 +43,12 @@ declare function protocolInstancePath(id: string): string;
42
43
  declare const PROTOCOL_PROPS_GRAPH_NODE_ID = "prop:props";
43
44
  declare const PROTOCOL_PAGE_SPACE_ID_PREFIXES: string[];
44
45
  declare function protocolInstanceQualifies(graphNodeId: string): boolean | undefined;
46
+ declare function protocolBoundSymbolSegment(value: string): string;
47
+ declare function protocolBoundSymbolPrefix(base: string): string;
48
+ /** The index of the `:` that ends a bound id's base, or -1 for any other id. */
49
+ declare function protocolBoundSymbolBaseEnd(id: string): number;
50
+ /** The symbol id a bound id binds, one level down, or undefined for any other id. */
51
+ declare function protocolBoundSymbolBase(id: string): string | undefined;
45
52
  //#endregion
46
53
  //#region src/protocol-detached-content.d.ts
47
54
  /**
@@ -90,6 +97,15 @@ declare function syncPolicyNeverActs(policy: ProtocolSyncPolicy): boolean;
90
97
  //#endregion
91
98
  //#region src/protocol.d.ts
92
99
  type ProtocolAsyncBoundaryArm = (typeof ASYNC_BOUNDARY_ARM)[keyof typeof ASYNC_BOUNDARY_ARM];
100
+ /**
101
+ * Where an element sits below the node an address starts from, one step per
102
+ * level. A step counts the parent's element children, and each @if, @switch or
103
+ * @try block as one (its start comment, content and end comment together). Text
104
+ * never counts, since adjacent text merges and an empty value renders no node,
105
+ * so the server's HTML and a client-built tree read the same. A negative step
106
+ * counts back from the end: -1 is the last.
107
+ */
108
+ type ProtocolElementAddress = ReadonlyArray<number>;
93
109
  type ProtocolSyncPolicyCondition = {
94
110
  readonly type: 'and';
95
111
  readonly conditions: ReadonlyArray<ProtocolSyncPolicyCondition>;
@@ -103,6 +119,8 @@ type ProtocolSyncPolicyCondition = {
103
119
  readonly type: 'graph-truthy';
104
120
  readonly graphNodeId: string;
105
121
  readonly path?: ReadonlyArray<string>;
122
+ /** When present, the read must equal this value rather than be truthy. */
123
+ readonly equals?: string | number | boolean | null;
106
124
  } | {
107
125
  readonly type: 'constant-truthy';
108
126
  readonly value: unknown;
@@ -210,6 +228,7 @@ type ProtocolStatePayload = {
210
228
  readonly graphNodeId: string;
211
229
  readonly key: string;
212
230
  }>;
231
+ readonly sharedRecords?: ReadonlyArray<SerializedRecord>;
213
232
  };
214
233
  type ProtocolBranchContentRead = {
215
234
  readonly graphNodeId: string;
@@ -287,6 +306,8 @@ type ProtocolArmRecordSet = {
287
306
  readonly elementHandles: ProtocolViewPayload['elementHandles'];
288
307
  readonly keyedRepeats?: ProtocolViewPayload['keyedRepeats'];
289
308
  readonly branches?: ReadonlyArray<ProtocolArmBranchRecord>;
309
+ /** Served beside `events` sent as templates: the names the stream boot listens for. */
310
+ readonly eventNames?: ReadonlyArray<string>;
290
311
  };
291
312
  type ProtocolStreamedArmPatch = readonly [arm: ProtocolAsyncBoundaryArm, records: ProtocolArmRecordSet];
292
313
  /**
@@ -315,6 +336,23 @@ type ProtocolRowTemplateSlotValue = {
315
336
  readonly path: ReadonlyArray<string>;
316
337
  }>;
317
338
  };
339
+ /** One arm of a row's branch: its markup and slots, FRAGMENT-relative to the arm's first node. */
340
+ type ProtocolRowTemplateArm = {
341
+ readonly html: string;
342
+ readonly textSlots?: ReadonlyArray<{
343
+ readonly path: ReadonlyArray<number>;
344
+ } & ProtocolRowTemplateSlotValue>;
345
+ readonly attributeSlots?: ReadonlyArray<{
346
+ readonly path: ReadonlyArray<number>;
347
+ readonly name: string;
348
+ } & ProtocolRowTemplateSlotValue>;
349
+ };
350
+ type ProtocolRowTemplateBranchSlot = {
351
+ readonly path: ReadonlyArray<number>;
352
+ readonly branchId: string;
353
+ readonly armTests?: ReadonlyArray<unknown>;
354
+ readonly arms: ReadonlyArray<ProtocolRowTemplateArm>;
355
+ } & ProtocolRowTemplateSlotValue;
318
356
  type ProtocolViewPayload = {
319
357
  readonly version: typeof ASYNC_PROTOCOL_VERSION;
320
358
  readonly asyncRunners?: Readonly<Record<string, string>>;
@@ -431,7 +469,7 @@ type ProtocolViewPayload = {
431
469
  */
432
470
  readonly enclosingRow?: {
433
471
  readonly repeatId: string;
434
- readonly parentHostPath: ReadonlyArray<number>;
472
+ readonly parentHostPath: ProtocolElementAddress;
435
473
  readonly itemPath?: ReadonlyArray<string>;
436
474
  };
437
475
  readonly collectionGraphNodeId?: string;
@@ -454,6 +492,11 @@ type ProtocolViewPayload = {
454
492
  readonly arm: number;
455
493
  };
456
494
  readonly itemName: string;
495
+ /**
496
+ * The `index` name of the `@for`, which a row handler reading it is handed
497
+ * beside the item. Pay-per-use: present only when a row handler reads it.
498
+ */
499
+ readonly indexName?: string;
457
500
  readonly rowElementCount: number;
458
501
  /**
459
502
  * Element children of the parent that stand before the rows. Rows occupy
@@ -532,6 +575,18 @@ type ProtocolViewPayload = {
532
575
  readonly path: ReadonlyArray<number>;
533
576
  readonly name: string;
534
577
  } & ProtocolRowTemplateSlotValue>;
578
+ /**
579
+ * An `@if`/`@switch` written in the row, flipped per row. The slot value is
580
+ * the test (the discriminant for a `@switch`, matched against `armTests`),
581
+ * and `path` names the marker in `html` the shown arm's anchors and nodes
582
+ * replace. A branch that IS the row (`@for { @if { <tr> } }`) has the marker
583
+ * as the whole html: its arm is the row root, so a flip rebuilds the row.
584
+ * `branchId` is the branch site as the anchor comments spell it, before
585
+ * composition's prefix, like `branchArm.branchId`.
586
+ *
587
+ * Pay-per-use: a row with no such branch omits the field.
588
+ */
589
+ readonly branchSlots?: ReadonlyArray<ProtocolRowTemplateBranchSlot>;
535
590
  };
536
591
  /**
537
592
  * The parent graph node each prop a `rowTemplate` source slot reads follows,
@@ -584,16 +639,25 @@ type ProtocolViewPayload = {
584
639
  readonly rowChunkId?: string;
585
640
  };
586
641
  readonly rowElementHandles?: ReadonlyArray<{
587
- readonly hostPath: ReadonlyArray<number>;
642
+ readonly hostPath: ProtocolElementAddress;
588
643
  readonly handleId: string;
589
644
  readonly name: string;
590
645
  readonly plural?: boolean;
591
646
  }>;
592
647
  readonly rowEvents: ReadonlyArray<{
593
- readonly hostPath: ReadonlyArray<number>;
648
+ readonly hostPath: ProtocolElementAddress;
594
649
  readonly eventName: string;
595
650
  readonly symbolIds: ReadonlyArray<string>;
596
651
  readonly syncPolicy?: ProtocolSyncPolicy;
652
+ /**
653
+ * The event's host sits in arm `arm` of `rowTemplate.branchSlots[slot]`, so it
654
+ * exists only while that arm shows, and `hostPath` is ARM-relative: element
655
+ * index among the arm's nodes, then child-node indexes from there.
656
+ */
657
+ readonly arm?: {
658
+ readonly slot: number;
659
+ readonly arm: number;
660
+ };
597
661
  }>;
598
662
  }>;
599
663
  readonly branches?: ReadonlyArray<{
@@ -610,7 +674,7 @@ type ProtocolViewPayload = {
610
674
  readonly armTests?: ReadonlyArray<unknown>;
611
675
  readonly armRecords?: ReadonlyArray<{
612
676
  readonly events: ReadonlyArray<{
613
- readonly hostPath: ReadonlyArray<number>;
677
+ readonly hostPath: ProtocolElementAddress;
614
678
  readonly eventName: string;
615
679
  readonly symbolIds: ReadonlyArray<string>;
616
680
  readonly syncPolicy?: ProtocolSyncPolicy;
@@ -693,6 +757,9 @@ type ProtocolViewPayload = {
693
757
  readonly path: ReadonlyArray<string>;
694
758
  readonly runnerSymbolId?: string;
695
759
  }>;
760
+ /** As on a branch: the part instance that authored this boundary and where its live props now live, for the arm its own module re-renders on settle. */
761
+ readonly composedInstancePath?: string;
762
+ readonly composedGraphProps?: ReadonlyArray<ProtocolComposedGraphProp>;
696
763
  }>;
697
764
  };
698
765
  type ProtocolPayloadScripts = {
@@ -701,5 +768,23 @@ type ProtocolPayloadScripts = {
701
768
  readonly stateScript: string;
702
769
  readonly viewScript: string;
703
770
  };
771
+ /**
772
+ * A record list served as templates. `t` holds each distinct record shape as JSON text whose
773
+ * per-record values are `^<slot>` holes, whose instance paths are `` `<slot> `` holes naming an
774
+ * entry of the payload's `instancePaths`, and whose field names the list's generated key table
775
+ * spells are `~<index>:` references; each `r` entry is a template index (no values), a
776
+ * `[template, ...values]` row filling the holes in order, or a record no other record shares.
777
+ */
778
+ type ProtocolTemplatedRecords = {
779
+ readonly t: ReadonlyArray<string>;
780
+ readonly r: ReadonlyArray<number | ReadonlyArray<number | string> | object>;
781
+ };
782
+ /**
783
+ * The instance paths a payload's templated lists name, as `instancePaths`: each entry is a path,
784
+ * or `[parent, segments]`, the path of entry `parent` followed by `segments`.
785
+ */
786
+ type ProtocolInstancePaths = ReadonlyArray<string | readonly [number, string]>;
787
+ /** A record list as a payload script serves it: a plain array, or templates. */
788
+ type ProtocolServedRecords = ReadonlyArray<unknown> | ProtocolTemplatedRecords;
704
789
  //#endregion
705
- export { PROTOCOL_VISIBLE_EVENT_NAME as $, formatEventHostEntries as A, STORAGE_PROTOCOL_VERSION as B, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR as C, ProtocolConstantSyncPolicyCode as D, PROTOCOL_SYNC_POLICY_TABLE_TYPE as E, PROTOCOL_TEMPLATE_CONTENT_TAG as F, protocolRowSegment as G, protocolInstanceQualifies as H, ASYNC_PROTOCOL_VERSION as I, PROTOCOL_CONTAINER_END_COMMENT as J, protocolStateVersion as K, PROTOCOL_EVENT_ACTION_KIND as L, syncPolicyNeverActs as M, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE as N, ProtocolEventHostEntry as O, PROTOCOL_RAW_TEXT_TAGS as P, PROTOCOL_IDLE_EVENT_NAME as Q, PROTOCOL_PAGE_SPACE_ID_PREFIXES as R, PROTOCOL_EVENT_HOST_DELEGATED_REF as S, PROTOCOL_EVENT_HOST_REF_SEPARATOR as T, protocolInstanceSegment as U, protocolInstancePath as V, protocolProjectionSegment as W, PROTOCOL_CONTAINER_START_COMMENT as X, PROTOCOL_CONTAINER_HOST_NODE_ID as Y, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE as Z, ProtocolViewPayload as _, ProtocolBranchIdrefSite as a, protocolEventDispatchesMarkless as b, ProtocolEventActionKind as c, ProtocolRowTemplateSlotValue as d, ASYNC_BOUNDARY_ARM as et, ProtocolStatePayload as f, ProtocolSyncPolicyCondition as g, ProtocolSyncPolicyBranch as h, ProtocolBranchContentRead as i, parseEventHostEntries as j, constantSyncPolicyCode as k, ProtocolEventRecord as l, ProtocolSyncPolicy as m, ProtocolArmRecordSet as n, ProtocolComposedGraphProp as o, ProtocolStreamedArmPatch as p, PROTOCOL_PROP_GRAPH_NODE_PREFIX as q, ProtocolAsyncBoundaryArm as r, ProtocolEventAction as s, ProtocolArmBranchRecord as t, ProtocolPayloadScripts as u, protocolElementHandleReadId as v, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR as w, PROTOCOL_EVENT_HOST_ATTRIBUTE as x, protocolEventActionKind as y, PROTOCOL_PROPS_GRAPH_NODE_ID as z };
790
+ export { protocolInstanceSegment as $, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR as A, PROTOCOL_RAW_TEXT_TAGS as B, ProtocolViewPayload as C, PROTOCOL_EVENT_HOST_ATTRIBUTE as D, protocolEventDispatchesMarkless as E, constantSyncPolicyCode as F, PROTOCOL_PROPS_GRAPH_NODE_ID as G, ASYNC_PROTOCOL_VERSION as H, formatEventHostEntries as I, protocolBoundSymbolBaseEnd as J, STORAGE_PROTOCOL_VERSION as K, parseEventHostEntries as L, PROTOCOL_SYNC_POLICY_TABLE_TYPE as M, ProtocolConstantSyncPolicyCode as N, PROTOCOL_EVENT_HOST_DELEGATED_REF as O, ProtocolEventHostEntry as P, protocolInstanceQualifies as Q, syncPolicyNeverActs as R, ProtocolTemplatedRecords as S, protocolEventActionKind as T, PROTOCOL_EVENT_ACTION_KIND as U, PROTOCOL_TEMPLATE_CONTENT_TAG as V, PROTOCOL_PAGE_SPACE_ID_PREFIXES as W, protocolBoundSymbolSegment as X, protocolBoundSymbolPrefix as Y, protocolInstancePath as Z, ProtocolStatePayload as _, ProtocolBranchIdrefSite as a, PROTOCOL_CONTAINER_HOST_NODE_ID as at, ProtocolSyncPolicyBranch as b, ProtocolEventAction as c, PROTOCOL_IDLE_EVENT_NAME as ct, ProtocolInstancePaths as d, protocolProjectionSegment as et, ProtocolPayloadScripts as f, ProtocolServedRecords as g, ProtocolRowTemplateSlotValue as h, ProtocolBranchContentRead as i, PROTOCOL_CONTAINER_END_COMMENT as it, PROTOCOL_EVENT_HOST_REF_SEPARATOR as j, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR as k, ProtocolEventActionKind as l, PROTOCOL_VISIBLE_EVENT_NAME as lt, ProtocolRowTemplateBranchSlot as m, ProtocolArmRecordSet as n, protocolStateVersion as nt, ProtocolComposedGraphProp as o, PROTOCOL_CONTAINER_START_COMMENT as ot, ProtocolRowTemplateArm as p, protocolBoundSymbolBase as q, ProtocolAsyncBoundaryArm as r, PROTOCOL_PROP_GRAPH_NODE_PREFIX as rt, ProtocolElementAddress as s, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE as st, ProtocolArmBranchRecord as t, protocolRowSegment as tt, ProtocolEventRecord as u, ASYNC_BOUNDARY_ARM as ut, ProtocolStreamedArmPatch as v, protocolElementHandleReadId as w, ProtocolSyncPolicyCondition as x, ProtocolSyncPolicy as y, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE as z };
@@ -0,0 +1,149 @@
1
+ //#region src/protocol-record-keys.ts
2
+ /** The field names each templated record list may spell, in the order its templates index them. */
3
+ const PROTOCOL_RECORD_KEYS = {
4
+ "markless/state": {
5
+ computed: "graphNodeId name async deriveSymbolId value version root $type $ref source flags records id type fields items entries values bytes arrayType buffer byteOffset length byteLength directValue dependencies path snapshot status key error hostScope",
6
+ sharedSeeds: "graphNodeId deriveSymbolId dependencies path reads",
7
+ sharedDefinitions: "id name exportedName scope version graphNodeIds projectionIds dependencies definitionId definitionName returnProperties kind graphNodeId path"
8
+ },
9
+ "markless/view": {
10
+ domUpdates: "hostNodeId source graphNodeId path target kind prefix suffix trueValue falseValue textNode name constantClass leadingClass symbolId",
11
+ behaviors: "hostNodeId source functionSource inputSources inputValues inputGraphReads inputIndex graphNodeId path symbolId usesGraph",
12
+ elementHandles: "hostNodeId handleId name plural"
13
+ }
14
+ };
15
+ //#endregion
16
+ //#region src/protocol-templated-lists.ts
17
+ /**
18
+ * The record lists a payload script may serve as record templates instead of a plain array. A
19
+ * reader that parses a payload script without decoding it may read only the other lists.
20
+ */
21
+ const PROTOCOL_TEMPLATED_LISTS = {
22
+ "markless/state": [
23
+ "cells",
24
+ "computed",
25
+ "sharedSeeds",
26
+ "sharedDefinitions",
27
+ "sharedRecords"
28
+ ],
29
+ "markless/view": [
30
+ "locators",
31
+ "events",
32
+ "domUpdates",
33
+ "behaviors",
34
+ "elementHandles",
35
+ "keyedRepeats"
36
+ ]
37
+ };
38
+ //#endregion
39
+ //#region src/protocol-shared-records-decode.ts
40
+ const ref = (slot, copy) => typeof slot === "object" && slot !== null && "$ref" in slot ? { $ref: copy(slot.$ref) } : slot;
41
+ function renamed(record, copy) {
42
+ const map = (slot) => ref(slot, copy);
43
+ if (record.type === "object") return {
44
+ ...record,
45
+ fields: record.fields.map(([key, slot]) => [key, map(slot)])
46
+ };
47
+ if (record.type === "array") return {
48
+ ...record,
49
+ items: record.items.map(map)
50
+ };
51
+ if (record.type === "map") return {
52
+ ...record,
53
+ entries: record.entries.map(([key, value]) => [map(key), map(value)])
54
+ };
55
+ if (record.type === "set") return {
56
+ ...record,
57
+ values: record.values.map(map)
58
+ };
59
+ if (record.type === "typed-array" || record.type === "data-view") return {
60
+ ...record,
61
+ buffer: map(record.buffer)
62
+ };
63
+ return record;
64
+ }
65
+ /**
66
+ * Gives every envelope of a freshly parsed state payload, in place, a copy of each shared subtree
67
+ * it references, under ids of its own: two references to one shared record are two objects.
68
+ */
69
+ function expandSharedRecords(state) {
70
+ const payload = state;
71
+ const shared = payload?.sharedRecords;
72
+ if (!shared) return state;
73
+ const byId = new Map(shared.map((record) => [record.id, record]));
74
+ const expand = (envelope) => {
75
+ const records = envelope?.records;
76
+ if (!Array.isArray(records)) return;
77
+ let next = 0;
78
+ for (const record of records) next = Math.max(next, record.id + 1);
79
+ const copies = [];
80
+ const copy = (id) => {
81
+ const record = byId.get(id);
82
+ if (!record) return id;
83
+ const at = next++;
84
+ const slot = copies.push(record) - 1;
85
+ copies[slot] = {
86
+ ...renamed(record, copy),
87
+ id: at
88
+ };
89
+ return at;
90
+ };
91
+ const own = records.map((record) => renamed(record, copy));
92
+ if (copies.length) envelope.records = [...own, ...copies];
93
+ };
94
+ for (const cell of payload.cells ?? []) expand(cell?.value);
95
+ for (const computed of payload.computed ?? []) {
96
+ expand(computed?.value);
97
+ const snapshot = computed?.snapshot;
98
+ expand(snapshot?.key);
99
+ expand(snapshot?.value);
100
+ expand(snapshot?.error);
101
+ }
102
+ delete payload.sharedRecords;
103
+ return state;
104
+ }
105
+ //#endregion
106
+ //#region src/protocol-record-templates.ts
107
+ function expandRecordTemplates(list, keys = "", instancePaths = []) {
108
+ if (Array.isArray(list)) return list;
109
+ const { t, r } = list;
110
+ const names = keys.split(" ");
111
+ const paths = [];
112
+ const path = (at) => {
113
+ const entry = instancePaths[at];
114
+ return paths[at] ??= typeof entry === "string" ? entry : path(entry[0]) + entry[1];
115
+ };
116
+ const parts = t.map((text) => text.replace(/~(\d+):/g, (_, at) => `"${names[+at]}":`).split(/([\^`])(\d+)/));
117
+ return r.map((ref) => {
118
+ if (typeof ref === "number") return JSON.parse(parts[ref][0]);
119
+ if (!Array.isArray(ref)) return ref;
120
+ const part = parts[ref[0]];
121
+ let text = part[0];
122
+ for (let at = 1; at < part.length; at += 3) {
123
+ const value = ref[+part[at + 1] + 1];
124
+ text += (part[at] === "`" ? path(value) : value) + part[at + 2];
125
+ }
126
+ return JSON.parse(text);
127
+ });
128
+ }
129
+ /** Expands, in place, every templated list of a freshly parsed payload script. */
130
+ function decodeProtocolPayloadLists(type, payload) {
131
+ const record = payload;
132
+ const keys = PROTOCOL_RECORD_KEYS[type];
133
+ if (record) {
134
+ const paths = record.instancePaths;
135
+ const inRows = record.inRows;
136
+ for (const key of PROTOCOL_TEMPLATED_LISTS[type]) {
137
+ const list = record[key];
138
+ if (list && !Array.isArray(list)) record[key] = expandRecordTemplates(list, keys[key], paths);
139
+ const rows = inRows?.[key] && expandRecordTemplates(inRows[key], keys[key], paths);
140
+ let at = 0;
141
+ if (rows) record[key] = list.map((item) => item ?? rows[at++]);
142
+ }
143
+ delete record.instancePaths;
144
+ delete record.inRows;
145
+ }
146
+ return expandSharedRecords(payload);
147
+ }
148
+ //#endregion
149
+ export { PROTOCOL_RECORD_KEYS as a, PROTOCOL_TEMPLATED_LISTS as i, expandRecordTemplates as n, expandSharedRecords as r, decodeProtocolPayloadLists as t };
@@ -0,0 +1,20 @@
1
+ import { d as ProtocolInstancePaths, g as ProtocolServedRecords } from "./protocol-J1KRChwU.js";
2
+ //#region src/protocol-client.d.ts
3
+ type RuntimePayloadType = 'markless/state' | 'markless/view';
4
+ //#endregion
5
+ //#region src/protocol-templated-lists.d.ts
6
+ /**
7
+ * The record lists a payload script may serve as record templates instead of a plain array. A
8
+ * reader that parses a payload script without decoding it may read only the other lists.
9
+ */
10
+ declare const PROTOCOL_TEMPLATED_LISTS: {
11
+ readonly 'markless/state': readonly ["cells", "computed", "sharedSeeds", "sharedDefinitions", "sharedRecords"];
12
+ readonly 'markless/view': readonly ["locators", "events", "domUpdates", "behaviors", "elementHandles", "keyedRepeats"];
13
+ };
14
+ //#endregion
15
+ //#region src/protocol-record-templates.d.ts
16
+ declare function expandRecordTemplates(list: ProtocolServedRecords, keys?: string, instancePaths?: ProtocolInstancePaths): unknown[];
17
+ /** Expands, in place, every templated list of a freshly parsed payload script. */
18
+ declare function decodeProtocolPayloadLists<T>(type: RuntimePayloadType, payload: T): T;
19
+ //#endregion
20
+ export { RuntimePayloadType as i, expandRecordTemplates as n, PROTOCOL_TEMPLATED_LISTS as r, decodeProtocolPayloadLists as t };
@@ -1,4 +1,4 @@
1
- import { _ as ProtocolViewPayload, f as ProtocolStatePayload } from "./protocol-D9lZReby.js";
1
+ import { C as ProtocolViewPayload, _ as ProtocolStatePayload } from "./protocol-J1KRChwU.js";
2
2
  //#region src/protocol-validation.d.ts
3
3
  type EncodedPayloadScripts = {
4
4
  readonly stateScript: string;
@@ -1,5 +1,5 @@
1
- import { _ as ASYNC_BOUNDARY_ARM, y as PROTOCOL_EVENT_ACTION_KIND } from "./protocol-B57uFVtf.js";
2
- import { t as decodeProtocolPayloadLists } from "./protocol-record-templates-xPHmxyXu.js";
1
+ import { _ as ASYNC_BOUNDARY_ARM, y as PROTOCOL_EVENT_ACTION_KIND } from "./protocol-Bli_tA6H.js";
2
+ import { t as decodeProtocolPayloadLists } from "./protocol-record-templates-Ctm9M01M.js";
3
3
  //#region src/protocol-validation.ts
4
4
  var RuntimePayloadError = class extends Error {
5
5
  constructor(diagnostic) {
@@ -179,6 +179,11 @@ function assertNonNegativeIntegerArrayField(record, key, context) {
179
179
  if (!Array.isArray(record[key])) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected ${key} array.`);
180
180
  for (const value of record[key]) if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected ${key} non-negative integer array.`);
181
181
  }
182
+ function assertElementAddressField(record, key, context) {
183
+ const value = record[key];
184
+ if (!Array.isArray(value)) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected ${key} array.`);
185
+ if (!value.every((step) => Number.isInteger(step))) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected ${key} integer array.`);
186
+ }
182
187
  function assertOptionalStringArrayField(record, key, context) {
183
188
  if (record[key] !== void 0) assertStringArrayField(record, key, context);
184
189
  }
@@ -213,6 +218,7 @@ function assertOptionalKeyedRepeats(record) {
213
218
  if (repeat.rowStartOffset !== void 0) assertNonNegativeIntegerField(repeat, "rowStartOffset", context);
214
219
  if (repeat.rowEndOffset !== void 0) assertNonNegativeIntegerField(repeat, "rowEndOffset", context);
215
220
  assertRowEvents(repeat.rowEvents, `${context}.rowEvents`);
221
+ assertOptionalStringField(repeat, "indexName", context);
216
222
  assertOptionalRowElementHandles(repeat, `${context}.rowElementHandles`);
217
223
  assertOptionalEmptyArm(repeat, `${context}.emptyArm`);
218
224
  assertOptionalRowTemplate(repeat, `${context}.rowTemplate`);
@@ -225,7 +231,7 @@ function assertOptionalEnclosingRow(record, context) {
225
231
  if (enclosingRow === void 0) return;
226
232
  assertRecordShape(enclosingRow, context);
227
233
  assertStringField(enclosingRow, "repeatId", context);
228
- assertNonNegativeIntegerArrayField(enclosingRow, "parentHostPath", context);
234
+ assertElementAddressField(enclosingRow, "parentHostPath", context);
229
235
  assertOptionalStringArrayField(enclosingRow, "itemPath", context);
230
236
  }
231
237
  function assertOptionalPropRoutes(record, context) {
@@ -258,7 +264,34 @@ function assertOptionalRowTemplate(record, context) {
258
264
  assertOptionalStringField(template, "componentName", context);
259
265
  assertOptionalRowTemplateSlots(template.textSlots, `${context}.textSlots`);
260
266
  assertOptionalRowTemplateSlots(template.attributeSlots, `${context}.attributeSlots`, true);
261
- if ([...template.textSlots ?? [], ...template.attributeSlots ?? []].some((slot) => slot.source !== void 0) !== (template.componentName !== void 0)) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected componentName exactly when a slot carries source.`);
267
+ assertOptionalRowTemplateBranchSlots(template.branchSlots, `${context}.branchSlots`);
268
+ const slotsOf = (owner) => [...owner.textSlots ?? [], ...owner.attributeSlots ?? []];
269
+ const branchSlots = template.branchSlots ?? [];
270
+ if ([
271
+ ...slotsOf(template),
272
+ ...branchSlots,
273
+ ...branchSlots.flatMap((branch) => branch.arms.flatMap(slotsOf))
274
+ ].some((slot) => slot.source !== void 0) !== (template.componentName !== void 0)) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected componentName exactly when a slot carries source.`);
275
+ }
276
+ function assertOptionalRowTemplateBranchSlots(slots, context) {
277
+ if (slots === void 0) return;
278
+ if (!Array.isArray(slots)) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected array.`);
279
+ for (const [index, slot] of slots.entries()) {
280
+ const slotContext = `${context}[${index}]`;
281
+ assertRecordShape(slot, slotContext);
282
+ assertNonNegativeIntegerArrayField(slot, "path", slotContext);
283
+ assertStringField(slot, "branchId", slotContext);
284
+ assertRowTemplateSlotValue(slot, slotContext);
285
+ if (slot.armTests !== void 0 && !Array.isArray(slot.armTests)) throw invalidPayloadShapeError(contextPayloadType(slotContext), `Invalid ${slotContext}: expected armTests array.`);
286
+ if (!Array.isArray(slot.arms)) throw invalidPayloadShapeError(contextPayloadType(slotContext), `Invalid ${slotContext}: expected arms array.`);
287
+ for (const [armIndex, arm] of slot.arms.entries()) {
288
+ const armContext = `${slotContext}.arms[${armIndex}]`;
289
+ assertRecordShape(arm, armContext);
290
+ assertStringField(arm, "html", armContext);
291
+ assertOptionalRowTemplateSlots(arm.textSlots, `${armContext}.textSlots`);
292
+ assertOptionalRowTemplateSlots(arm.attributeSlots, `${armContext}.attributeSlots`, true);
293
+ }
294
+ }
262
295
  }
263
296
  function assertOptionalRowTemplateSlots(slots, context, named = false) {
264
297
  if (slots === void 0) return;
@@ -306,7 +339,7 @@ function assertOptionalRowElementHandles(record, context) {
306
339
  for (const [index, handle] of handles.entries()) {
307
340
  const handleContext = `${context}[${index}]`;
308
341
  assertRecordShape(handle, handleContext);
309
- assertNonNegativeIntegerArrayField(handle, "hostPath", handleContext);
342
+ assertElementAddressField(handle, "hostPath", handleContext);
310
343
  assertStringField(handle, "handleId", handleContext);
311
344
  assertStringField(handle, "name", handleContext);
312
345
  assertOptionalBooleanField(handle, "plural", handleContext);
@@ -374,10 +407,15 @@ function assertRowEvents(value, context) {
374
407
  for (const [index, event] of value.entries()) {
375
408
  const eventContext = `${context}[${index}]`;
376
409
  assertRecordShape(event, eventContext);
377
- assertNonNegativeIntegerArrayField(event, "hostPath", eventContext);
410
+ assertElementAddressField(event, "hostPath", eventContext);
378
411
  assertStringField(event, "eventName", eventContext);
379
412
  assertStringArrayField(event, "symbolIds", eventContext);
380
413
  if (event.syncPolicy !== void 0) assertSyncPolicy(event.syncPolicy, `${eventContext}.syncPolicy`);
414
+ if (event.arm !== void 0) {
415
+ assertRecordShape(event.arm, `${eventContext}.arm`);
416
+ assertNonNegativeIntegerField(event.arm, "slot", `${eventContext}.arm`);
417
+ assertNonNegativeIntegerField(event.arm, "arm", `${eventContext}.arm`);
418
+ }
381
419
  }
382
420
  }
383
421
  function assertOptionalGraphReads(record, key, context) {
@@ -774,6 +812,11 @@ function assertSyncPolicyCondition(value, context) {
774
812
  if (value.type === "graph-truthy") {
775
813
  assertStringField(value, "graphNodeId", context);
776
814
  assertOptionalStringArrayField(value, "path", context);
815
+ if ("equals" in value && value.equals !== null && ![
816
+ "string",
817
+ "number",
818
+ "boolean"
819
+ ].includes(typeof value.equals)) throw invalidPayloadShapeError(contextPayloadType(context), `Invalid ${context}: expected equals to be a string, number, boolean or null.`);
777
820
  return;
778
821
  }
779
822
  if (value.type === "constant-truthy") {
@@ -1,2 +1,2 @@
1
- import { a as RuntimePayloadError, c as assertProtocolStateCellPayload, d as decodePayloadScriptsWithVersion, f as invalidPayloadShapeError, i as RuntimePayloadDiagnostic, l as assertProtocolStatePayload, m as payloadScriptSelector, n as DecodedPayloadScripts, o as RuntimePayloadErrorCode, p as payloadInvalidError, r as EncodedPayloadScripts, s as RuntimePayloadType, t as decodePayloadScripts, u as assertProtocolViewPayload } from "./protocol-validation-storage-CBlNSV9-.js";
1
+ import { a as RuntimePayloadError, c as assertProtocolStateCellPayload, d as decodePayloadScriptsWithVersion, f as invalidPayloadShapeError, i as RuntimePayloadDiagnostic, l as assertProtocolStatePayload, m as payloadScriptSelector, n as DecodedPayloadScripts, o as RuntimePayloadErrorCode, p as payloadInvalidError, r as EncodedPayloadScripts, s as RuntimePayloadType, t as decodePayloadScripts, u as assertProtocolViewPayload } from "./protocol-validation-storage-Cg9OKvHQ.js";
2
2
  export { DecodedPayloadScripts, EncodedPayloadScripts, RuntimePayloadDiagnostic, RuntimePayloadError, RuntimePayloadErrorCode, RuntimePayloadType, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, decodePayloadScripts, decodePayloadScriptsWithVersion, invalidPayloadShapeError, payloadInvalidError, payloadScriptSelector };
@@ -1 +1 @@
1
- export { r as RuntimePayloadError, i as assertProtocolStateCellPayload, a as assertProtocolStatePayload, o as assertProtocolViewPayload, t as decodePayloadScripts, s as decodePayloadScriptsWithVersion, c as invalidPayloadShapeError, l as payloadInvalidError, u as payloadScriptSelector } from "./protocol-validation-storage-D-K1WBE7.js";
1
+ export { r as RuntimePayloadError, i as assertProtocolStateCellPayload, a as assertProtocolStatePayload, o as assertProtocolViewPayload, t as decodePayloadScripts, s as decodePayloadScriptsWithVersion, c as invalidPayloadShapeError, l as payloadInvalidError, u as payloadScriptSelector } from "./protocol-validation-storage-DlHC66oQ.js";
@@ -1,2 +1,2 @@
1
- import { $ as PROTOCOL_VISIBLE_EVENT_NAME, A as formatEventHostEntries, B as STORAGE_PROTOCOL_VERSION, C as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, D as ProtocolConstantSyncPolicyCode, E as PROTOCOL_SYNC_POLICY_TABLE_TYPE, F as PROTOCOL_TEMPLATE_CONTENT_TAG, G as protocolRowSegment, H as protocolInstanceQualifies, I as ASYNC_PROTOCOL_VERSION, J as PROTOCOL_CONTAINER_END_COMMENT, K as protocolStateVersion, L as PROTOCOL_EVENT_ACTION_KIND, M as syncPolicyNeverActs, N as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, O as ProtocolEventHostEntry, P as PROTOCOL_RAW_TEXT_TAGS, Q as PROTOCOL_IDLE_EVENT_NAME, R as PROTOCOL_PAGE_SPACE_ID_PREFIXES, S as PROTOCOL_EVENT_HOST_DELEGATED_REF, T as PROTOCOL_EVENT_HOST_REF_SEPARATOR, U as protocolInstanceSegment, V as protocolInstancePath, W as protocolProjectionSegment, X as PROTOCOL_CONTAINER_START_COMMENT, Y as PROTOCOL_CONTAINER_HOST_NODE_ID, Z as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, _ as ProtocolViewPayload, a as ProtocolBranchIdrefSite, b as protocolEventDispatchesMarkless, c as ProtocolEventActionKind, d as ProtocolRowTemplateSlotValue, et as ASYNC_BOUNDARY_ARM, f as ProtocolStatePayload, g as ProtocolSyncPolicyCondition, h as ProtocolSyncPolicyBranch, i as ProtocolBranchContentRead, j as parseEventHostEntries, k as constantSyncPolicyCode, l as ProtocolEventRecord, m as ProtocolSyncPolicy, n as ProtocolArmRecordSet, o as ProtocolComposedGraphProp, p as ProtocolStreamedArmPatch, q as PROTOCOL_PROP_GRAPH_NODE_PREFIX, r as ProtocolAsyncBoundaryArm, s as ProtocolEventAction, t as ProtocolArmBranchRecord, u as ProtocolPayloadScripts, v as protocolElementHandleReadId, w as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, x as PROTOCOL_EVENT_HOST_ATTRIBUTE, y as protocolEventActionKind, z as PROTOCOL_PROPS_GRAPH_NODE_ID } from "./protocol-D9lZReby.js";
2
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_EVENT_HOST_ATTRIBUTE, PROTOCOL_EVENT_HOST_DELEGATED_REF, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, PROTOCOL_EVENT_HOST_REF_SEPARATOR, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_RAW_TEXT_TAGS, PROTOCOL_SYNC_POLICY_TABLE_TYPE, PROTOCOL_TEMPLATE_CONTENT_TAG, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, type ProtocolConstantSyncPolicyCode, ProtocolEventAction, ProtocolEventActionKind, type ProtocolEventHostEntry, ProtocolEventRecord, ProtocolPayloadScripts, ProtocolRowTemplateSlotValue, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, ProtocolViewPayload, STORAGE_PROTOCOL_VERSION, constantSyncPolicyCode, formatEventHostEntries, parseEventHostEntries, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, syncPolicyNeverActs };
1
+ import { $ as protocolInstanceSegment, A as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, B as PROTOCOL_RAW_TEXT_TAGS, C as ProtocolViewPayload, D as PROTOCOL_EVENT_HOST_ATTRIBUTE, E as protocolEventDispatchesMarkless, F as constantSyncPolicyCode, G as PROTOCOL_PROPS_GRAPH_NODE_ID, H as ASYNC_PROTOCOL_VERSION, I as formatEventHostEntries, J as protocolBoundSymbolBaseEnd, K as STORAGE_PROTOCOL_VERSION, L as parseEventHostEntries, M as PROTOCOL_SYNC_POLICY_TABLE_TYPE, N as ProtocolConstantSyncPolicyCode, O as PROTOCOL_EVENT_HOST_DELEGATED_REF, P as ProtocolEventHostEntry, Q as protocolInstanceQualifies, R as syncPolicyNeverActs, S as ProtocolTemplatedRecords, T as protocolEventActionKind, U as PROTOCOL_EVENT_ACTION_KIND, V as PROTOCOL_TEMPLATE_CONTENT_TAG, W as PROTOCOL_PAGE_SPACE_ID_PREFIXES, X as protocolBoundSymbolSegment, Y as protocolBoundSymbolPrefix, Z as protocolInstancePath, _ as ProtocolStatePayload, a as ProtocolBranchIdrefSite, at as PROTOCOL_CONTAINER_HOST_NODE_ID, b as ProtocolSyncPolicyBranch, c as ProtocolEventAction, ct as PROTOCOL_IDLE_EVENT_NAME, d as ProtocolInstancePaths, et as protocolProjectionSegment, f as ProtocolPayloadScripts, g as ProtocolServedRecords, h as ProtocolRowTemplateSlotValue, i as ProtocolBranchContentRead, it as PROTOCOL_CONTAINER_END_COMMENT, j as PROTOCOL_EVENT_HOST_REF_SEPARATOR, k as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, l as ProtocolEventActionKind, lt as PROTOCOL_VISIBLE_EVENT_NAME, m as ProtocolRowTemplateBranchSlot, n as ProtocolArmRecordSet, nt as protocolStateVersion, o as ProtocolComposedGraphProp, ot as PROTOCOL_CONTAINER_START_COMMENT, p as ProtocolRowTemplateArm, q as protocolBoundSymbolBase, r as ProtocolAsyncBoundaryArm, rt as PROTOCOL_PROP_GRAPH_NODE_PREFIX, s as ProtocolElementAddress, st as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, t as ProtocolArmBranchRecord, tt as protocolRowSegment, u as ProtocolEventRecord, ut as ASYNC_BOUNDARY_ARM, v as ProtocolStreamedArmPatch, w as protocolElementHandleReadId, x as ProtocolSyncPolicyCondition, y as ProtocolSyncPolicy, z as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE } from "./protocol-J1KRChwU.js";
2
+ export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_EVENT_HOST_ATTRIBUTE, PROTOCOL_EVENT_HOST_DELEGATED_REF, PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, PROTOCOL_EVENT_HOST_REF_SEPARATOR, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_RAW_TEXT_TAGS, PROTOCOL_SYNC_POLICY_TABLE_TYPE, PROTOCOL_TEMPLATE_CONTENT_TAG, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, type ProtocolConstantSyncPolicyCode, ProtocolElementAddress, ProtocolEventAction, ProtocolEventActionKind, type ProtocolEventHostEntry, ProtocolEventRecord, ProtocolInstancePaths, ProtocolPayloadScripts, ProtocolRowTemplateArm, ProtocolRowTemplateBranchSlot, ProtocolRowTemplateSlotValue, ProtocolServedRecords, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, ProtocolTemplatedRecords, ProtocolViewPayload, STORAGE_PROTOCOL_VERSION, constantSyncPolicyCode, formatEventHostEntries, parseEventHostEntries, protocolBoundSymbolBase, protocolBoundSymbolBaseEnd, protocolBoundSymbolPrefix, protocolBoundSymbolSegment, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, syncPolicyNeverActs };
package/dist/protocol.js CHANGED
@@ -1 +1 @@
1
- export { _ as ASYNC_BOUNDARY_ARM, v as ASYNC_PROTOCOL_VERSION, A as PROTOCOL_CONTAINER_END_COMMENT, j as PROTOCOL_CONTAINER_HOST_NODE_ID, M as PROTOCOL_CONTAINER_START_COMMENT, m as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, y as PROTOCOL_EVENT_ACTION_KIND, i as PROTOCOL_EVENT_HOST_ATTRIBUTE, a as PROTOCOL_EVENT_HOST_DELEGATED_REF, o as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, s as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, c as PROTOCOL_EVENT_HOST_REF_SEPARATOR, P as PROTOCOL_IDLE_EVENT_NAME, N as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, b as PROTOCOL_PAGE_SPACE_ID_PREFIXES, x as PROTOCOL_PROPS_GRAPH_NODE_ID, k as PROTOCOL_PROP_GRAPH_NODE_PREFIX, h as PROTOCOL_RAW_TEXT_TAGS, l as PROTOCOL_SYNC_POLICY_TABLE_TYPE, g as PROTOCOL_TEMPLATE_CONTENT_TAG, F as PROTOCOL_VISIBLE_EVENT_NAME, S as STORAGE_PROTOCOL_VERSION, u as constantSyncPolicyCode, d as formatEventHostEntries, f as parseEventHostEntries, t as protocolElementHandleReadId, n as protocolEventActionKind, r as protocolEventDispatchesMarkless, C as protocolInstancePath, w as protocolInstanceQualifies, T as protocolInstanceSegment, E as protocolProjectionSegment, D as protocolRowSegment, O as protocolStateVersion, p as syncPolicyNeverActs } from "./protocol-B57uFVtf.js";
1
+ export { _ as ASYNC_BOUNDARY_ARM, v as ASYNC_PROTOCOL_VERSION, P as PROTOCOL_CONTAINER_END_COMMENT, F as PROTOCOL_CONTAINER_HOST_NODE_ID, I as PROTOCOL_CONTAINER_START_COMMENT, m as PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE, y as PROTOCOL_EVENT_ACTION_KIND, i as PROTOCOL_EVENT_HOST_ATTRIBUTE, a as PROTOCOL_EVENT_HOST_DELEGATED_REF, o as PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR, s as PROTOCOL_EVENT_HOST_POLICY_SEPARATOR, c as PROTOCOL_EVENT_HOST_REF_SEPARATOR, R as PROTOCOL_IDLE_EVENT_NAME, L as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, b as PROTOCOL_PAGE_SPACE_ID_PREFIXES, x as PROTOCOL_PROPS_GRAPH_NODE_ID, N as PROTOCOL_PROP_GRAPH_NODE_PREFIX, h as PROTOCOL_RAW_TEXT_TAGS, l as PROTOCOL_SYNC_POLICY_TABLE_TYPE, g as PROTOCOL_TEMPLATE_CONTENT_TAG, z as PROTOCOL_VISIBLE_EVENT_NAME, S as STORAGE_PROTOCOL_VERSION, u as constantSyncPolicyCode, d as formatEventHostEntries, f as parseEventHostEntries, C as protocolBoundSymbolBase, w as protocolBoundSymbolBaseEnd, T as protocolBoundSymbolPrefix, E as protocolBoundSymbolSegment, t as protocolElementHandleReadId, n as protocolEventActionKind, r as protocolEventDispatchesMarkless, D as protocolInstancePath, O as protocolInstanceQualifies, k as protocolInstanceSegment, A as protocolProjectionSegment, j as protocolRowSegment, M as protocolStateVersion, p as syncPolicyNeverActs } from "./protocol-Bli_tA6H.js";
@@ -1,2 +1,3 @@
1
- import { a as PROTOCOL_TEMPLATED_LISTS, i as expandRecordTemplates, n as ProtocolTemplatedRecords, o as RuntimePayloadType, r as decodeProtocolPayloadLists, t as ProtocolServedRecords } from "./protocol-record-templates-pAcSQYqD.js";
2
- export { PROTOCOL_TEMPLATED_LISTS, ProtocolServedRecords, ProtocolTemplatedRecords, type RuntimePayloadType, decodeProtocolPayloadLists, expandRecordTemplates };
1
+ import { S as ProtocolTemplatedRecords, d as ProtocolInstancePaths, g as ProtocolServedRecords } from "./protocol-J1KRChwU.js";
2
+ import { i as RuntimePayloadType, n as expandRecordTemplates, r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists } from "./protocol-record-templates-DX8X0uTO.js";
3
+ export { PROTOCOL_TEMPLATED_LISTS, type ProtocolInstancePaths, type ProtocolServedRecords, type ProtocolTemplatedRecords, type RuntimePayloadType, decodeProtocolPayloadLists, expandRecordTemplates };
@@ -1 +1 @@
1
- export { r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists, n as expandRecordTemplates } from "./protocol-record-templates-xPHmxyXu.js";
1
+ export { i as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists, n as expandRecordTemplates } from "./protocol-record-templates-Ctm9M01M.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markless/serializer",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Markless serialization tiers and resumability payload protocol.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,31 +0,0 @@
1
- //#region src/protocol-client.d.ts
2
- type RuntimePayloadType = 'markless/state' | 'markless/view';
3
- //#endregion
4
- //#region src/protocol-templated-lists.d.ts
5
- /**
6
- * The record lists a payload script may serve as record templates instead of a plain array. The
7
- * inline resumer reads the others at page load, before any decoder has loaded, so they stay plain.
8
- */
9
- declare const PROTOCOL_TEMPLATED_LISTS: {
10
- readonly 'markless/state': readonly ["computed", "sharedSeeds", "sharedDefinitions"];
11
- readonly 'markless/view': readonly ["domUpdates", "behaviors", "elementHandles"];
12
- };
13
- //#endregion
14
- //#region src/protocol-record-templates.d.ts
15
- /**
16
- * A record list served as templates. `t` holds each distinct record shape as JSON text whose
17
- * per-record values are `^<slot>` holes and whose field names the list's generated key table
18
- * spells are `~<index>:` references; each `r` entry is a template index (no values), a
19
- * `[template, ...values]` row filling the holes in order, or a record no other record shares.
20
- */
21
- type ProtocolTemplatedRecords = {
22
- readonly t: ReadonlyArray<string>;
23
- readonly r: ReadonlyArray<number | ReadonlyArray<number | string> | object>;
24
- };
25
- /** A record list as a payload script serves it: a plain array, or templates. */
26
- type ProtocolServedRecords = ReadonlyArray<unknown> | ProtocolTemplatedRecords;
27
- declare function expandRecordTemplates(list: ProtocolServedRecords, keys?: string): unknown[];
28
- /** Expands, in place, every templated list of a freshly parsed payload script. */
29
- declare function decodeProtocolPayloadLists<T>(type: RuntimePayloadType, payload: T): T;
30
- //#endregion
31
- export { PROTOCOL_TEMPLATED_LISTS as a, expandRecordTemplates as i, ProtocolTemplatedRecords as n, RuntimePayloadType as o, decodeProtocolPayloadLists as r, ProtocolServedRecords as t };
@@ -1,60 +0,0 @@
1
- //#region src/protocol-record-keys.ts
2
- /** The field names each templated record list may spell, in the order its templates index them. */
3
- const PROTOCOL_RECORD_KEYS = {
4
- "markless/state": {
5
- computed: "graphNodeId name async deriveSymbolId value version root $type $ref source flags records id type fields items entries values bytes arrayType buffer byteOffset length byteLength directValue dependencies path snapshot status key error hostScope",
6
- sharedSeeds: "graphNodeId deriveSymbolId dependencies path reads",
7
- sharedDefinitions: "id name exportedName scope version graphNodeIds projectionIds dependencies definitionId definitionName returnProperties kind graphNodeId path"
8
- },
9
- "markless/view": {
10
- domUpdates: "hostNodeId source graphNodeId path target kind prefix suffix trueValue falseValue textNode name constantClass leadingClass symbolId",
11
- behaviors: "hostNodeId source functionSource inputSources inputValues inputGraphReads inputIndex graphNodeId path symbolId usesGraph",
12
- elementHandles: "hostNodeId handleId name plural"
13
- }
14
- };
15
- //#endregion
16
- //#region src/protocol-templated-lists.ts
17
- /**
18
- * The record lists a payload script may serve as record templates instead of a plain array. The
19
- * inline resumer reads the others at page load, before any decoder has loaded, so they stay plain.
20
- */
21
- const PROTOCOL_TEMPLATED_LISTS = {
22
- "markless/state": [
23
- "computed",
24
- "sharedSeeds",
25
- "sharedDefinitions"
26
- ],
27
- "markless/view": [
28
- "domUpdates",
29
- "behaviors",
30
- "elementHandles"
31
- ]
32
- };
33
- //#endregion
34
- //#region src/protocol-record-templates.ts
35
- function expandRecordTemplates(list, keys = "") {
36
- if (Array.isArray(list)) return list;
37
- const { t, r } = list;
38
- const names = keys.split(" ");
39
- const parts = t.map((text) => text.replace(/~(\d+):/g, (_, at) => `"${names[+at]}":`).split(/\^(\d+)/));
40
- return r.map((ref) => {
41
- if (typeof ref === "number") return JSON.parse(parts[ref][0]);
42
- if (!Array.isArray(ref)) return ref;
43
- const part = parts[ref[0]];
44
- let text = part[0];
45
- for (let at = 1; at < part.length; at += 2) text += ref[+part[at] + 1] + part[at + 1];
46
- return JSON.parse(text);
47
- });
48
- }
49
- /** Expands, in place, every templated list of a freshly parsed payload script. */
50
- function decodeProtocolPayloadLists(type, payload) {
51
- const record = payload;
52
- const keys = PROTOCOL_RECORD_KEYS[type];
53
- if (record) for (const key of PROTOCOL_TEMPLATED_LISTS[type]) {
54
- const list = record[key];
55
- if (list && !Array.isArray(list)) record[key] = expandRecordTemplates(list, keys[key]);
56
- }
57
- return payload;
58
- }
59
- //#endregion
60
- export { PROTOCOL_RECORD_KEYS as i, expandRecordTemplates as n, PROTOCOL_TEMPLATED_LISTS as r, decodeProtocolPayloadLists as t };