@markless/serializer 0.6.0 → 0.8.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,6 +1,7 @@
1
- import { A as protocolRowSegment, B as ASYNC_BOUNDARY_ARM, C as PROTOCOL_PAGE_SPACE_ID_PREFIXES, D as protocolInstanceQualifies, E as protocolInstancePath, F as PROTOCOL_CONTAINER_HOST_NODE_ID, I as PROTOCOL_CONTAINER_START_COMMENT, L as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, M as PROTOCOL_PROP_GRAPH_NODE_PREFIX, N as PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, O as protocolInstanceSegment, P as PROTOCOL_CONTAINER_END_COMMENT, R as PROTOCOL_IDLE_EVENT_NAME, S as PROTOCOL_EVENT_ACTION_KIND, T as STORAGE_PROTOCOL_VERSION, _ as ProtocolViewPayload, a as ProtocolBranchIdrefSite, b as protocolEventDispatchesMarkless, c as ProtocolEventActionKind, d as ProtocolRowTemplateSlotValue, f as ProtocolStatePayload, g as ProtocolSyncPolicyCondition, h as ProtocolSyncPolicyBranch, i as ProtocolBranchContentRead, j as protocolStateVersion, k as protocolProjectionSegment, l as ProtocolEventRecord, m as ProtocolSyncPolicy, n as ProtocolArmRecordSet, o as ProtocolComposedGraphProp, p as ProtocolStreamedArmPatch, r as ProtocolAsyncBoundaryArm, s as ProtocolEventAction, t as ProtocolArmBranchRecord, u as ProtocolPayloadScripts, v as protocolElementHandleReadId, w as PROTOCOL_PROPS_GRAPH_NODE_ID, x as ASYNC_PROTOCOL_VERSION, y as protocolEventActionKind, z as PROTOCOL_VISIBLE_EVENT_NAME } from "./protocol-BNO5JLsK.js";
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-D8nfDFJd.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";
2
3
  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";
3
- 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-B4dATVQ_.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-CLv0E9Gp.js";
4
5
  //#region src/payload-scripts.d.ts
5
6
  export type RenderPayloadScriptsInput = {
6
7
  readonly state: ProtocolStatePayload;
@@ -12,7 +13,9 @@ export type RenderedPayloadScripts = {
12
13
  readonly stateScript: string;
13
14
  readonly viewScript: string;
14
15
  };
15
- export declare function renderPayloadScripts(input: RenderPayloadScriptsInput): RenderedPayloadScripts;
16
+ /** How a payload's record lists are written; a served page passes encodeProtocolPayloadLists. */
17
+ export type PayloadListEncoder = <T extends object>(type: RuntimePayloadType$1, payload: T) => T;
18
+ export declare function renderPayloadScripts(input: RenderPayloadScriptsInput, encodeLists?: PayloadListEncoder): RenderedPayloadScripts;
16
19
  export declare function escapeScriptJson(value: string): string;
17
20
  //#endregion
18
21
  //#region src/protocol-state.d.ts
@@ -71,6 +74,16 @@ export declare function createProtocolStatePayload(input: ProtocolStatePayloadIn
71
74
  export declare function serializeRuntimeStateCells(cells: ProtocolStatePayload['cells']): ProtocolStatePayload['cells'];
72
75
  export declare function serializeRuntimeAsyncSnapshots(computed: ProtocolStatePayload['computed']): ProtocolStatePayload['computed'];
73
76
  //#endregion
77
+ //#region src/protocol-record-templates-encode.d.ts
78
+ /**
79
+ * Serves a record list as templates when that is shorter: records that differ only in their
80
+ * 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.
82
+ */
83
+ export declare function encodeRecordTemplates<T extends object>(records: ReadonlyArray<T>, keys?: string): ReadonlyArray<T> | ProtocolTemplatedRecords;
84
+ /** 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;
86
+ //#endregion
74
87
  //#region src/resume-record-merge.d.ts
75
88
  type ResumeRecordSet = {
76
89
  readonly state: ProtocolStatePayload;
@@ -110,4 +123,4 @@ export declare function storageSlotEntryKeyFromGraphNodeId(graphNodeId: string):
110
123
  export declare function createStorageSeedMetadata(moduleId: string, driverKey: string, fallback: string): StorageSeedMetadata;
111
124
  export declare function createStorageSeedMetadataFromGraphNodeId(graphNodeId: string, driverKey: string, fallback: string): StorageSeedMetadata;
112
125
  //#endregion
113
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, DecodedPayloadScripts, EncodedPayloadScripts, NonFiniteNumberName, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, ProtocolEventAction, ProtocolEventActionKind, ProtocolEventRecord, ProtocolPayloadScripts, ProtocolRowTemplateSlotValue, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, ProtocolViewPayload, type ResumeRecordSet, RuntimePayloadDiagnostic, RuntimePayloadError, RuntimePayloadErrorCode, RuntimePayloadType, STORAGE_PROTOCOL_VERSION, SerializationDiagnostic, SerializationResult, SerializedGraphPayload, SerializedPrimitive, SerializedRecord, SerializedSlot, TypedArrayName, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, decodePayloadScripts, decodePayloadScriptsWithVersion, deserializeGraphValue, invalidPayloadShapeError, jsonSourceWithNonFiniteNumbers, nonFiniteName, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, serializeGraphValue };
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 };
package/dist/index.js CHANGED
@@ -1,17 +1,19 @@
1
- import { C as PROTOCOL_VISIBLE_EVENT_NAME, S as PROTOCOL_IDLE_EVENT_NAME, _ as PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, a as ASYNC_PROTOCOL_VERSION, b as PROTOCOL_CONTAINER_START_COMMENT, c as PROTOCOL_PROPS_GRAPH_NODE_ID, d as protocolInstanceQualifies, f as protocolInstanceSegment, g as PROTOCOL_PROP_GRAPH_NODE_PREFIX, h as protocolStateVersion, i as ASYNC_BOUNDARY_ARM, l as STORAGE_PROTOCOL_VERSION, m as protocolRowSegment, n as protocolEventActionKind, o as PROTOCOL_EVENT_ACTION_KIND, p as protocolProjectionSegment, r as protocolEventDispatchesMarkless, s as PROTOCOL_PAGE_SPACE_ID_PREFIXES, t as protocolElementHandleReadId, u as protocolInstancePath, v as PROTOCOL_CONTAINER_END_COMMENT, x as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, y as PROTOCOL_CONTAINER_HOST_NODE_ID } from "./protocol-9Mv28nr_.js";
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";
2
2
  import { deserializeGraphValue } from "./decode.js";
3
- 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-ycVVe95T.js";
3
+ import { i as PROTOCOL_RECORD_KEYS, n as expandRecordTemplates, r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists } from "./protocol-record-templates-B0Ay3OCd.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-DYrHI-d6.js";
4
5
  //#region src/payload-scripts.ts
5
- function renderPayloadScripts(input) {
6
+ function renderPayloadScripts(input, encodeLists) {
6
7
  return {
7
8
  state: input.state,
8
9
  view: input.view,
9
- stateScript: renderDataScript("markless/state", input.state),
10
- viewScript: renderDataScript("markless/view", input.view)
10
+ stateScript: renderDataScript("markless/state", input.state, encodeLists),
11
+ viewScript: renderDataScript("markless/view", input.view, encodeLists)
11
12
  };
12
13
  }
13
- function renderDataScript(type, payload) {
14
- return `<script type="${type}">${escapeScriptJson(JSON.stringify(payload))}<\/script>`;
14
+ function renderDataScript(type, payload, encodeLists) {
15
+ const served = encodeLists ? encodeLists(type, payload) : payload;
16
+ return `<script type="${type}">${escapeScriptJson(JSON.stringify(served))}<\/script>`;
15
17
  }
16
18
  function escapeScriptJson(value) {
17
19
  return value.replace(/<(?=[/!])/g, "\\u003C");
@@ -437,6 +439,118 @@ function protocolStateSerializationError(cell, diagnostic) {
437
439
  });
438
440
  }
439
441
  //#endregion
442
+ //#region src/protocol-record-templates-encode.ts
443
+ const HOLE = /\d+|r:[^:"\\]*:/g;
444
+ const WHOLE_NUMBER = /^(?:0|[1-9]\d{0,14})$/;
445
+ const TEMPLATED_SHARE = .75;
446
+ const keyRefsByTable = /* @__PURE__ */ new Map();
447
+ function keyRefs(keys) {
448
+ let refs = keyRefsByTable.get(keys);
449
+ if (!refs) {
450
+ const names = keys.split(" ");
451
+ const index = new Map(names.map((name, at) => [name, at]));
452
+ const pattern = new RegExp(`"(${names.map((name) => name.replace(/[$]/g, "\\$&")).join("|")})":`, "g");
453
+ refs = (text) => text.replace(pattern, (_, name) => `~${index.get(name)}:`);
454
+ keyRefsByTable.set(keys, refs);
455
+ }
456
+ return refs;
457
+ }
458
+ /**
459
+ * Serves a record list as templates when that is shorter: records that differ only in their
460
+ * 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.
462
+ */
463
+ function encodeRecordTemplates(records, keys = "") {
464
+ if (records.length < 2) return records;
465
+ const refer = keys ? keyRefs(keys) : (text) => text;
466
+ const groups = /* @__PURE__ */ new Map();
467
+ const texts = [];
468
+ for (let index = 0; index < records.length; index++) {
469
+ let text = JSON.stringify(records[index]);
470
+ if (text.includes("^")) text = text.replaceAll("^", "\\u005e");
471
+ if (text.includes("~")) text = text.replaceAll("~", "\\u007e");
472
+ texts.push(text);
473
+ const values = text.match(HOLE);
474
+ const key = values ? text.replace(HOLE, "^") : text;
475
+ let group = groups.get(key);
476
+ if (!group) groups.set(key, group = {
477
+ key,
478
+ rows: [],
479
+ members: []
480
+ });
481
+ group.rows.push(values);
482
+ group.members.push(index);
483
+ }
484
+ const templates = [];
485
+ const refs = [];
486
+ for (const group of groups.values()) {
487
+ if (group.rows.length === 1) {
488
+ const member = group.members[0];
489
+ const template = refer(texts[member]);
490
+ if (JSON.stringify(template).length < texts[member].length) {
491
+ refs[member] = templates.length;
492
+ templates.push(template);
493
+ } else refs[member] = records[member];
494
+ continue;
495
+ }
496
+ 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("^");
503
+ let text = parts[0];
504
+ for (let column = 0; column < parts.length - 1; column++) {
505
+ const slot = slots.of[column];
506
+ text += (slot < 0 ? first[column] : `^${slot}`) + parts[column + 1];
507
+ }
508
+ templates.push(refer(text));
509
+ group.rows.forEach((values, row) => {
510
+ refs[group.members[row]] = slots.columns.length ? [index, ...slots.columns.map((column) => {
511
+ const value = values[column];
512
+ return WHOLE_NUMBER.test(value) ? Number(value) : value;
513
+ })] : index;
514
+ });
515
+ }
516
+ const encoded = {
517
+ t: templates,
518
+ r: refs
519
+ };
520
+ const plain = texts.reduce((total, text) => total + text.length + 1, 1);
521
+ return JSON.stringify(encoded).length <= plain * TEMPLATED_SHARE ? encoded : records;
522
+ }
523
+ function valueSlots(rows) {
524
+ const width = rows[0].length;
525
+ const of = [];
526
+ const columns = [];
527
+ for (let column = 0; column < width; column++) {
528
+ const value = rows[0][column];
529
+ if (rows.every((row) => row[column] === value)) {
530
+ of.push(-1);
531
+ continue;
532
+ }
533
+ const same = columns.findIndex((held) => rows.every((row) => row[held] === row[column]));
534
+ of.push(same >= 0 ? same : columns.push(column) - 1);
535
+ }
536
+ return {
537
+ of,
538
+ columns
539
+ };
540
+ }
541
+ /** The payload with each templated list served in its shorter form, for JSON.stringify. */
542
+ function encodeProtocolPayloadLists(type, payload) {
543
+ const keys = PROTOCOL_RECORD_KEYS[type];
544
+ let encoded;
545
+ for (const key of PROTOCOL_TEMPLATED_LISTS[type]) {
546
+ const list = payload[key];
547
+ if (!Array.isArray(list)) continue;
548
+ const served = encodeRecordTemplates(list, keys[key]);
549
+ if (served !== list) (encoded ??= { ...payload })[key] = served;
550
+ }
551
+ return encoded ?? payload;
552
+ }
553
+ //#endregion
440
554
  //#region src/resume-record-merge.ts
441
555
  function mergeResumeRecordDelta(baseline, delta) {
442
556
  assertMatchingVersion$1(baseline.state.version, delta.state.version, "state");
@@ -641,4 +755,4 @@ function createStorageCookieReader(cookieHeader) {
641
755
  return (driverKey) => values.get(storageCookieName(driverKey));
642
756
  }
643
757
  //#endregion
644
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolStateSerializationError, RuntimePayloadError, STORAGE_PROTOCOL_VERSION, STORAGE_RENDER_CONTEXT_READER, STORAGE_SLOT_SYMBOL_KEY, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, classifyResumeRecordDelta, createProtocolStatePayload, createStorageCookieReader, createStorageSeedMetadata, createStorageSeedMetadataFromGraphNodeId, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeStorageCookieValue, deserializeGraphValue, escapeScriptJson, invalidPayloadShapeError, isValidStorageKey, jsonSourceWithNonFiniteNumbers, mergeResumeRecordDelta, nonFiniteName, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, renderPayloadScripts, serializeGraphValue, serializeRuntimeAsyncSnapshots, serializeRuntimeStateCells, storageAttributeName, storageCookieAssignment, storageCookieName, storageSlotEntryKey, storageSlotEntryKeyFromGraphNodeId };
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 };
@@ -0,0 +1,165 @@
1
+ //#region src/protocol-event-names.ts
2
+ const PROTOCOL_VISIBLE_EVENT_NAME = "visible";
3
+ const PROTOCOL_IDLE_EVENT_NAME = "idle";
4
+ //#endregion
5
+ //#region src/protocol-locator-paths.ts
6
+ /**
7
+ * The container attribute that lets resume find each located element by its
8
+ * position under its parent, so a node a third-party script adds or swaps
9
+ * elsewhere cannot shift it. Format: protocol-locator-paths-format.ts.
10
+ */
11
+ const PROTOCOL_LOCATOR_PATHS_ATTRIBUTE = "data-markless-paths";
12
+ //#endregion
13
+ //#region src/protocol-page-markers.ts
14
+ const PROTOCOL_CONTAINER_START_COMMENT = "markless:page-start";
15
+ const PROTOCOL_CONTAINER_END_COMMENT = "markless:page-end";
16
+ const PROTOCOL_CONTAINER_HOST_NODE_ID = "container";
17
+ //#endregion
18
+ //#region src/protocol-prop-prefix.ts
19
+ const PROTOCOL_PROP_GRAPH_NODE_PREFIX = "prop:";
20
+ //#endregion
21
+ //#region src/protocol-constants.ts
22
+ const ASYNC_PROTOCOL_VERSION = 1;
23
+ const STORAGE_PROTOCOL_VERSION = 2;
24
+ function protocolStateVersion(storage) {
25
+ return (storage?.length ?? 0) > 0 ? 2 : 1;
26
+ }
27
+ const PROTOCOL_EVENT_ACTION_KIND = {
28
+ event: "event",
29
+ externalDelegate: "external-delegate"
30
+ };
31
+ const PROTOCOL_INSTANCE_PATH = /^(?:[cpm]\d+:|r:[^:]*:)+/;
32
+ function protocolInstanceSegment(edgeIndex) {
33
+ return `c${edgeIndex}:`;
34
+ }
35
+ function protocolProjectionSegment(edgeIndex) {
36
+ return `p${edgeIndex}:`;
37
+ }
38
+ /** One keyed `@for` row's identity segment. The key is identity, never the index. */
39
+ function protocolRowSegment(key) {
40
+ return `r:${encodeURIComponent(String(key))}:`;
41
+ }
42
+ /** The leading instance path of a composed id, or '' when the id is page-local. */
43
+ function protocolInstancePath(id) {
44
+ return PROTOCOL_INSTANCE_PATH.exec(id)?.[0] ?? "";
45
+ }
46
+ const PROTOCOL_PROPS_GRAPH_NODE_ID = "prop:props";
47
+ const PROTOCOL_INSTANCE_QUALIFIABLE = [
48
+ "prop:",
49
+ "state:",
50
+ "computed:",
51
+ "element:"
52
+ ];
53
+ const PROTOCOL_PAGE_SPACE_ID_PREFIXES = ["shared:", "storage:"];
54
+ function protocolInstanceQualifies(graphNodeId) {
55
+ const local = graphNodeId.slice(protocolInstancePath(graphNodeId).length);
56
+ if (PROTOCOL_PAGE_SPACE_ID_PREFIXES.some((prefix) => local.startsWith(prefix))) return false;
57
+ return PROTOCOL_INSTANCE_QUALIFIABLE.some((prefix) => local.startsWith(prefix)) ? true : void 0;
58
+ }
59
+ //#endregion
60
+ //#region src/async-boundary-arm.ts
61
+ const ASYNC_BOUNDARY_ARM = {
62
+ try: 0,
63
+ pending: 1,
64
+ catch: 2
65
+ };
66
+ //#endregion
67
+ //#region src/protocol-detached-content.ts
68
+ /**
69
+ * Elements whose content the HTML parser keeps out of document order: `<template>` parses its
70
+ * content into `template.content`, and the raw-text elements parse theirs as text (`<noscript>`
71
+ * with scripting on). Nothing inside one is an element the DOM-order census can count, so the
72
+ * compiler mints no host for it and the served-tree reader skips it.
73
+ */
74
+ const PROTOCOL_TEMPLATE_CONTENT_TAG = "template";
75
+ /** A `<template>` carrying this attribute is consumed by the parser into a shadow root: the element itself is gone too. */
76
+ const PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE = "shadowrootmode";
77
+ const PROTOCOL_RAW_TEXT_TAGS = /* @__PURE__ */ new Set([
78
+ "script",
79
+ "style",
80
+ "textarea",
81
+ "title",
82
+ "xmp",
83
+ "iframe",
84
+ "noembed",
85
+ "noframes",
86
+ "noscript"
87
+ ]);
88
+ //#endregion
89
+ //#region src/protocol-event-host.ts
90
+ /**
91
+ * The attribute the server writes on each served element that hosts an event
92
+ * record. The inline boot reads it from the event target up, so it finds a
93
+ * press's handler and sync policy without parsing a payload or knowing the
94
+ * element's position. Grammar: entries joined by `;`, each
95
+ * `name[:ref][!policy]`, where `ref` is the record's index in its region's event
96
+ * list (or `-` for an event an external delegate owns) and `policy` is `p`, `s`,
97
+ * `ps` or an index into the container's sync-policy table.
98
+ */
99
+ const PROTOCOL_EVENT_HOST_ATTRIBUTE = "m:on";
100
+ /** The inert script holding each distinct conditional sync policy of a container once. */
101
+ const PROTOCOL_SYNC_POLICY_TABLE_TYPE = "markless/policy";
102
+ const PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR = ";";
103
+ const PROTOCOL_EVENT_HOST_REF_SEPARATOR = ":";
104
+ const PROTOCOL_EVENT_HOST_POLICY_SEPARATOR = "!";
105
+ const PROTOCOL_EVENT_HOST_DELEGATED_REF = "-";
106
+ function formatEventHostEntries(entries) {
107
+ return entries.map((entry) => entry.name + (entry.ref === void 0 ? "" : ":" + entry.ref) + (entry.policy === void 0 ? "" : "!" + entry.policy)).join(";");
108
+ }
109
+ function parseEventHostEntries(value) {
110
+ return value.split(";").filter(Boolean).map((text) => {
111
+ const [head = "", policy] = text.split("!");
112
+ const [name = "", ref] = head.split(":");
113
+ return {
114
+ name,
115
+ ...ref === void 0 ? {} : { ref: ref === "-" ? ref : Number(ref) },
116
+ ...policy === void 0 ? {} : { policy: policy === "p" || policy === "s" || policy === "ps" ? policy : Number(policy) }
117
+ };
118
+ });
119
+ }
120
+ /**
121
+ * The inline spelling of a policy that acts on every event, or undefined when the
122
+ * policy reads the event or the graph and so needs the table.
123
+ */
124
+ function constantSyncPolicyCode(policy) {
125
+ const branches = "branches" in policy ? policy.branches : [policy];
126
+ let prevent = false;
127
+ let stop = false;
128
+ for (const branch of branches) {
129
+ if (branch.when.type !== "constant-truthy") return void 0;
130
+ if (!branch.when.value) continue;
131
+ prevent ||= branch.actions.includes("preventDefault");
132
+ stop ||= branch.actions.includes("stopPropagation");
133
+ }
134
+ if (prevent && stop) return "ps";
135
+ if (prevent) return "p";
136
+ if (stop) return "s";
137
+ }
138
+ /** Whether a policy can never act, so its host needs no policy entry at all. */
139
+ function syncPolicyNeverActs(policy) {
140
+ return ("branches" in policy ? policy.branches : [policy]).every((branch) => branch.actions.length === 0 || branch.when.type === "constant-truthy" && !branch.when.value);
141
+ }
142
+ //#endregion
143
+ //#region src/protocol.ts
144
+ function protocolEventActionKind(record) {
145
+ return record.action?.kind ?? PROTOCOL_EVENT_ACTION_KIND.event;
146
+ }
147
+ function protocolEventDispatchesMarkless(record) {
148
+ return protocolEventActionKind(record) === PROTOCOL_EVENT_ACTION_KIND.event;
149
+ }
150
+ /**
151
+ * The graph read id an arm-update symbol asks under for a minted element() id.
152
+ *
153
+ * A minted id is `idPrefix + handle` where the prefix is the rendered widget's
154
+ * instance token, a seed-map value no flip can reach. The render that served the
155
+ * arm resolves the id and files it on the branch record under this key; the
156
+ * symbol asks for it through the read channel it already has, so the mint keeps
157
+ * exactly one spelling. Resume matches the key as a SUFFIX of the id it is
158
+ * handed, because a composed symbol's reads arrive with the instance path
159
+ * prepended — that is why the key carries the namespace and not the bare handle.
160
+ */
161
+ function protocolElementHandleReadId(handleGraphNodeId) {
162
+ return `markless:element-handle-id|${handleGraphNodeId}`;
163
+ }
164
+ //#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 };
@@ -22,15 +22,6 @@ declare const PROTOCOL_CONTAINER_START_COMMENT = "markless:page-start";
22
22
  declare const PROTOCOL_CONTAINER_END_COMMENT = "markless:page-end";
23
23
  declare const PROTOCOL_CONTAINER_HOST_NODE_ID = "container";
24
24
  //#endregion
25
- //#region src/protocol-sync-policy-host.d.ts
26
- /**
27
- * The attribute the server writes on each element whose event record carries a
28
- * sync policy (preventDefault, stopPropagation), valued with that record's
29
- * hostNodeId. The inline boot finds the policy from the event's own target up
30
- * to the nearest marked element, so it never needs the element's position.
31
- */
32
- declare const PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE = "data-markless-sync";
33
- //#endregion
34
25
  //#region src/protocol-prop-prefix.d.ts
35
26
  declare const PROTOCOL_PROP_GRAPH_NODE_PREFIX = "prop:";
36
27
  //#endregion
@@ -52,6 +43,51 @@ declare const PROTOCOL_PROPS_GRAPH_NODE_ID = "prop:props";
52
43
  declare const PROTOCOL_PAGE_SPACE_ID_PREFIXES: string[];
53
44
  declare function protocolInstanceQualifies(graphNodeId: string): boolean | undefined;
54
45
  //#endregion
46
+ //#region src/protocol-detached-content.d.ts
47
+ /**
48
+ * Elements whose content the HTML parser keeps out of document order: `<template>` parses its
49
+ * content into `template.content`, and the raw-text elements parse theirs as text (`<noscript>`
50
+ * with scripting on). Nothing inside one is an element the DOM-order census can count, so the
51
+ * compiler mints no host for it and the served-tree reader skips it.
52
+ */
53
+ declare const PROTOCOL_TEMPLATE_CONTENT_TAG = "template";
54
+ /** A `<template>` carrying this attribute is consumed by the parser into a shadow root: the element itself is gone too. */
55
+ declare const PROTOCOL_DECLARATIVE_SHADOW_ROOT_ATTRIBUTE = "shadowrootmode";
56
+ declare const PROTOCOL_RAW_TEXT_TAGS: ReadonlySet<string>;
57
+ //#endregion
58
+ //#region src/protocol-event-host.d.ts
59
+ /**
60
+ * The attribute the server writes on each served element that hosts an event
61
+ * record. The inline boot reads it from the event target up, so it finds a
62
+ * press's handler and sync policy without parsing a payload or knowing the
63
+ * element's position. Grammar: entries joined by `;`, each
64
+ * `name[:ref][!policy]`, where `ref` is the record's index in its region's event
65
+ * list (or `-` for an event an external delegate owns) and `policy` is `p`, `s`,
66
+ * `ps` or an index into the container's sync-policy table.
67
+ */
68
+ declare const PROTOCOL_EVENT_HOST_ATTRIBUTE = "m:on";
69
+ /** The inert script holding each distinct conditional sync policy of a container once. */
70
+ declare const PROTOCOL_SYNC_POLICY_TABLE_TYPE = "markless/policy";
71
+ declare const PROTOCOL_EVENT_HOST_ENTRY_SEPARATOR = ";";
72
+ declare const PROTOCOL_EVENT_HOST_REF_SEPARATOR = ":";
73
+ declare const PROTOCOL_EVENT_HOST_POLICY_SEPARATOR = "!";
74
+ declare const PROTOCOL_EVENT_HOST_DELEGATED_REF = "-";
75
+ type ProtocolConstantSyncPolicyCode = 'p' | 's' | 'ps';
76
+ type ProtocolEventHostEntry = {
77
+ readonly name: string;
78
+ readonly ref?: number | typeof PROTOCOL_EVENT_HOST_DELEGATED_REF;
79
+ readonly policy?: ProtocolConstantSyncPolicyCode | number;
80
+ };
81
+ declare function formatEventHostEntries(entries: ReadonlyArray<ProtocolEventHostEntry>): string;
82
+ declare function parseEventHostEntries(value: string): ProtocolEventHostEntry[];
83
+ /**
84
+ * The inline spelling of a policy that acts on every event, or undefined when the
85
+ * policy reads the event or the graph and so needs the table.
86
+ */
87
+ declare function constantSyncPolicyCode(policy: ProtocolSyncPolicy): ProtocolConstantSyncPolicyCode | undefined;
88
+ /** Whether a policy can never act, so its host needs no policy entry at all. */
89
+ declare function syncPolicyNeverActs(policy: ProtocolSyncPolicy): boolean;
90
+ //#endregion
55
91
  //#region src/protocol.d.ts
56
92
  type ProtocolAsyncBoundaryArm = (typeof ASYNC_BOUNDARY_ARM)[keyof typeof ASYNC_BOUNDARY_ARM];
57
93
  type ProtocolSyncPolicyCondition = {
@@ -665,4 +701,4 @@ type ProtocolPayloadScripts = {
665
701
  readonly viewScript: string;
666
702
  };
667
703
  //#endregion
668
- export { protocolRowSegment as A, ASYNC_BOUNDARY_ARM as B, PROTOCOL_PAGE_SPACE_ID_PREFIXES as C, protocolInstanceQualifies as D, protocolInstancePath as E, PROTOCOL_CONTAINER_HOST_NODE_ID as F, PROTOCOL_CONTAINER_START_COMMENT as I, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE as L, PROTOCOL_PROP_GRAPH_NODE_PREFIX as M, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE as N, protocolInstanceSegment as O, PROTOCOL_CONTAINER_END_COMMENT as P, PROTOCOL_IDLE_EVENT_NAME as R, PROTOCOL_EVENT_ACTION_KIND as S, STORAGE_PROTOCOL_VERSION as T, ProtocolViewPayload as _, ProtocolBranchIdrefSite as a, protocolEventDispatchesMarkless as b, ProtocolEventActionKind as c, ProtocolRowTemplateSlotValue as d, ProtocolStatePayload as f, ProtocolSyncPolicyCondition as g, ProtocolSyncPolicyBranch as h, ProtocolBranchContentRead as i, protocolStateVersion as j, protocolProjectionSegment as k, ProtocolEventRecord as l, ProtocolSyncPolicy as m, ProtocolArmRecordSet as n, ProtocolComposedGraphProp as o, ProtocolStreamedArmPatch as p, ProtocolAsyncBoundaryArm as r, ProtocolEventAction as s, ProtocolArmBranchRecord as t, ProtocolPayloadScripts as u, protocolElementHandleReadId as v, PROTOCOL_PROPS_GRAPH_NODE_ID as w, ASYNC_PROTOCOL_VERSION as x, protocolEventActionKind as y, PROTOCOL_VISIBLE_EVENT_NAME as z };
704
+ 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 };
@@ -0,0 +1,60 @@
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",
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 };
@@ -0,0 +1,31 @@
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,4 +1,4 @@
1
- import { _ as ProtocolViewPayload, f as ProtocolStatePayload } from "./protocol-BNO5JLsK.js";
1
+ import { _ as ProtocolViewPayload, f as ProtocolStatePayload } from "./protocol-D8nfDFJd.js";
2
2
  //#region src/protocol-validation.d.ts
3
3
  type EncodedPayloadScripts = {
4
4
  readonly stateScript: string;
@@ -1,4 +1,5 @@
1
- import { i as ASYNC_BOUNDARY_ARM, o as PROTOCOL_EVENT_ACTION_KIND } from "./protocol-9Mv28nr_.js";
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-B0Ay3OCd.js";
2
3
  //#region src/protocol-validation.ts
3
4
  var RuntimePayloadError = class extends Error {
4
5
  constructor(diagnostic) {
@@ -25,7 +26,7 @@ function parseDataScript(script, type) {
25
26
  const prefix = `<script type="${type}">`;
26
27
  if (!script.startsWith(prefix) || !script.endsWith("<\/script>")) throw payloadInvalidError(type, `Expected ${type} payload script.`, `Browser resume expects the ${type} data to arrive in a canonical ${payloadScriptSelector(type)} script wrapper before decoding the resumability protocol.`, [{ message: `Emit the ${type} payload with renderPayloadScripts or an equivalent canonical script wrapper.` }]);
27
28
  try {
28
- return JSON.parse(script.slice(prefix.length, -9));
29
+ return decodeProtocolPayloadLists(type, JSON.parse(script.slice(prefix.length, -9)));
29
30
  } catch {
30
31
  throw payloadInvalidError(type, `Invalid ${type} payload JSON.`, `The ${type} payload script must contain valid JSON before the runtime can validate the resumability protocol fields.`, [{ message: `Emit valid JSON inside the ${payloadScriptSelector(type)} script content.` }]);
31
32
  }
@@ -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-B4dATVQ_.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-CLv0E9Gp.js";
2
2
  export { DecodedPayloadScripts, EncodedPayloadScripts, RuntimePayloadDiagnostic, RuntimePayloadError, RuntimePayloadErrorCode, RuntimePayloadType, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, decodePayloadScripts, decodePayloadScriptsWithVersion, invalidPayloadShapeError, payloadInvalidError, payloadScriptSelector };
@@ -1,2 +1 @@
1
- import { a as assertProtocolStatePayload, c as invalidPayloadShapeError, i as assertProtocolStateCellPayload, l as payloadInvalidError, o as assertProtocolViewPayload, r as RuntimePayloadError, s as decodePayloadScriptsWithVersion, t as decodePayloadScripts, u as payloadScriptSelector } from "./protocol-validation-storage-ycVVe95T.js";
2
- export { RuntimePayloadError, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, decodePayloadScripts, decodePayloadScriptsWithVersion, invalidPayloadShapeError, payloadInvalidError, payloadScriptSelector };
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-DYrHI-d6.js";
@@ -1,2 +1,2 @@
1
- import { A as protocolRowSegment, B as ASYNC_BOUNDARY_ARM, C as PROTOCOL_PAGE_SPACE_ID_PREFIXES, D as protocolInstanceQualifies, E as protocolInstancePath, F as PROTOCOL_CONTAINER_HOST_NODE_ID, I as PROTOCOL_CONTAINER_START_COMMENT, L as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, M as PROTOCOL_PROP_GRAPH_NODE_PREFIX, N as PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, O as protocolInstanceSegment, P as PROTOCOL_CONTAINER_END_COMMENT, R as PROTOCOL_IDLE_EVENT_NAME, S as PROTOCOL_EVENT_ACTION_KIND, T as STORAGE_PROTOCOL_VERSION, _ as ProtocolViewPayload, a as ProtocolBranchIdrefSite, b as protocolEventDispatchesMarkless, c as ProtocolEventActionKind, d as ProtocolRowTemplateSlotValue, f as ProtocolStatePayload, g as ProtocolSyncPolicyCondition, h as ProtocolSyncPolicyBranch, i as ProtocolBranchContentRead, j as protocolStateVersion, k as protocolProjectionSegment, l as ProtocolEventRecord, m as ProtocolSyncPolicy, n as ProtocolArmRecordSet, o as ProtocolComposedGraphProp, p as ProtocolStreamedArmPatch, r as ProtocolAsyncBoundaryArm, s as ProtocolEventAction, t as ProtocolArmBranchRecord, u as ProtocolPayloadScripts, v as protocolElementHandleReadId, w as PROTOCOL_PROPS_GRAPH_NODE_ID, x as ASYNC_PROTOCOL_VERSION, y as protocolEventActionKind, z as PROTOCOL_VISIBLE_EVENT_NAME } from "./protocol-BNO5JLsK.js";
2
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, ProtocolEventAction, ProtocolEventActionKind, ProtocolEventRecord, ProtocolPayloadScripts, ProtocolRowTemplateSlotValue, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, ProtocolViewPayload, STORAGE_PROTOCOL_VERSION, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion };
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-D8nfDFJd.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 };
package/dist/protocol.js CHANGED
@@ -1,2 +1 @@
1
- import { C as PROTOCOL_VISIBLE_EVENT_NAME, S as PROTOCOL_IDLE_EVENT_NAME, _ as PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, a as ASYNC_PROTOCOL_VERSION, b as PROTOCOL_CONTAINER_START_COMMENT, c as PROTOCOL_PROPS_GRAPH_NODE_ID, d as protocolInstanceQualifies, f as protocolInstanceSegment, g as PROTOCOL_PROP_GRAPH_NODE_PREFIX, h as protocolStateVersion, i as ASYNC_BOUNDARY_ARM, l as STORAGE_PROTOCOL_VERSION, m as protocolRowSegment, n as protocolEventActionKind, o as PROTOCOL_EVENT_ACTION_KIND, p as protocolProjectionSegment, r as protocolEventDispatchesMarkless, s as PROTOCOL_PAGE_SPACE_ID_PREFIXES, t as protocolElementHandleReadId, u as protocolInstancePath, v as PROTOCOL_CONTAINER_END_COMMENT, x as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, y as PROTOCOL_CONTAINER_HOST_NODE_ID } from "./protocol-9Mv28nr_.js";
2
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_VISIBLE_EVENT_NAME, STORAGE_PROTOCOL_VERSION, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion };
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";
@@ -0,0 +1,2 @@
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 };
@@ -0,0 +1 @@
1
+ export { r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists, n as expandRecordTemplates } from "./protocol-record-templates-B0Ay3OCd.js";
@@ -0,0 +1,35 @@
1
+ //#region src/render-data-hosts.d.ts
2
+ /**
3
+ * Render data names the elements of a chunk that something addresses (a handler,
4
+ * an update, a handle, a list or arm anchor). Every other element is static text
5
+ * in the chunk's markup that only has to be counted, so the compiler folds those
6
+ * into `inertElements` and renderers walk the chunk in coordinate order with the
7
+ * counts in between, which keeps DOM-order indexes exact.
8
+ */
9
+ type Coordinate = {
10
+ readonly coordinate: {
11
+ readonly path: ReadonlyArray<number>;
12
+ };
13
+ };
14
+ export type RenderDataChunkHosts<Host extends Coordinate, Slot extends Coordinate> = {
15
+ readonly hosts: ReadonlyArray<Host>;
16
+ readonly slots: ReadonlyArray<Slot>;
17
+ /** Unaddressed elements before each host and slot in coordinate order, then after the last. */
18
+ readonly inertElements?: ReadonlyArray<number>;
19
+ };
20
+ export type RenderDataChunkEntry<Host, Slot> = {
21
+ readonly kind: 'host';
22
+ readonly host: Host;
23
+ readonly inertBefore: number;
24
+ } | {
25
+ readonly kind: 'slot';
26
+ readonly slot: Slot;
27
+ readonly inertBefore: number;
28
+ };
29
+ /** The chunk's hosts and slots in document order (a parent before what it holds), each with the unaddressed elements before it. */
30
+ export declare function chunkCoordinateOrder<Host extends Coordinate, Slot extends Coordinate>(chunk: RenderDataChunkHosts<Host, Slot>): {
31
+ readonly entries: ReadonlyArray<RenderDataChunkEntry<Host, Slot>>;
32
+ readonly inertAfter: number;
33
+ };
34
+ //#endregion
35
+ export {};
@@ -0,0 +1,37 @@
1
+ //#region src/render-data-hosts.ts
2
+ function compareRenderCoordinates(left, right) {
3
+ for (let index = 0; index < Math.min(left.length, right.length); index++) {
4
+ const difference = left[index] - right[index];
5
+ if (difference !== 0) return difference;
6
+ }
7
+ return left.length - right.length;
8
+ }
9
+ /** The chunk's hosts and slots in document order (a parent before what it holds), each with the unaddressed elements before it. */
10
+ function chunkCoordinateOrder(chunk) {
11
+ const inert = chunk.inertElements;
12
+ const entries = [...chunk.hosts.map((host) => ({
13
+ path: host.coordinate.path,
14
+ order: 0,
15
+ host,
16
+ slot: void 0
17
+ })), ...chunk.slots.map((slot, order) => ({
18
+ path: slot.coordinate.path,
19
+ order: order + 1,
20
+ host: void 0,
21
+ slot
22
+ }))].sort((left, right) => compareRenderCoordinates(left.path, right.path) || left.order - right.order).map((entry, index) => entry.host ? {
23
+ kind: "host",
24
+ host: entry.host,
25
+ inertBefore: inert?.[index] ?? 0
26
+ } : {
27
+ kind: "slot",
28
+ slot: entry.slot,
29
+ inertBefore: inert?.[index] ?? 0
30
+ });
31
+ return {
32
+ entries,
33
+ inertAfter: inert?.[entries.length] ?? 0
34
+ };
35
+ }
36
+ //#endregion
37
+ export { chunkCoordinateOrder };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markless/serializer",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Markless serialization tiers and resumability payload protocol.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -42,6 +42,14 @@
42
42
  "types": "./dist/protocol.d.ts",
43
43
  "default": "./dist/protocol.js"
44
44
  },
45
+ "./record-templates": {
46
+ "types": "./dist/record-templates.d.ts",
47
+ "default": "./dist/record-templates.js"
48
+ },
49
+ "./render-data-hosts": {
50
+ "types": "./dist/render-data-hosts.d.ts",
51
+ "default": "./dist/render-data-hosts.js"
52
+ },
45
53
  "./protocol-validation": {
46
54
  "types": "./dist/protocol-validation.d.ts",
47
55
  "default": "./dist/protocol-validation.js"
@@ -1,98 +0,0 @@
1
- //#region src/protocol-event-names.ts
2
- const PROTOCOL_VISIBLE_EVENT_NAME = "visible";
3
- const PROTOCOL_IDLE_EVENT_NAME = "idle";
4
- //#endregion
5
- //#region src/protocol-locator-paths.ts
6
- /**
7
- * The container attribute that lets resume find each located element by its
8
- * position under its parent, so a node a third-party script adds or swaps
9
- * elsewhere cannot shift it. Format: protocol-locator-paths-format.ts.
10
- */
11
- const PROTOCOL_LOCATOR_PATHS_ATTRIBUTE = "data-markless-paths";
12
- //#endregion
13
- //#region src/protocol-page-markers.ts
14
- const PROTOCOL_CONTAINER_START_COMMENT = "markless:page-start";
15
- const PROTOCOL_CONTAINER_END_COMMENT = "markless:page-end";
16
- const PROTOCOL_CONTAINER_HOST_NODE_ID = "container";
17
- //#endregion
18
- //#region src/protocol-sync-policy-host.ts
19
- /**
20
- * The attribute the server writes on each element whose event record carries a
21
- * sync policy (preventDefault, stopPropagation), valued with that record's
22
- * hostNodeId. The inline boot finds the policy from the event's own target up
23
- * to the nearest marked element, so it never needs the element's position.
24
- */
25
- const PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE = "data-markless-sync";
26
- //#endregion
27
- //#region src/protocol-prop-prefix.ts
28
- const PROTOCOL_PROP_GRAPH_NODE_PREFIX = "prop:";
29
- //#endregion
30
- //#region src/protocol-constants.ts
31
- const ASYNC_PROTOCOL_VERSION = 1;
32
- const STORAGE_PROTOCOL_VERSION = 2;
33
- function protocolStateVersion(storage) {
34
- return (storage?.length ?? 0) > 0 ? 2 : 1;
35
- }
36
- const PROTOCOL_EVENT_ACTION_KIND = {
37
- event: "event",
38
- externalDelegate: "external-delegate"
39
- };
40
- const PROTOCOL_INSTANCE_PATH = /^(?:[cpm]\d+:|r:[^:]*:)+/;
41
- function protocolInstanceSegment(edgeIndex) {
42
- return `c${edgeIndex}:`;
43
- }
44
- function protocolProjectionSegment(edgeIndex) {
45
- return `p${edgeIndex}:`;
46
- }
47
- /** One keyed `@for` row's identity segment. The key is identity, never the index. */
48
- function protocolRowSegment(key) {
49
- return `r:${encodeURIComponent(String(key))}:`;
50
- }
51
- /** The leading instance path of a composed id, or '' when the id is page-local. */
52
- function protocolInstancePath(id) {
53
- return PROTOCOL_INSTANCE_PATH.exec(id)?.[0] ?? "";
54
- }
55
- const PROTOCOL_PROPS_GRAPH_NODE_ID = "prop:props";
56
- const PROTOCOL_INSTANCE_QUALIFIABLE = [
57
- "prop:",
58
- "state:",
59
- "computed:",
60
- "element:"
61
- ];
62
- const PROTOCOL_PAGE_SPACE_ID_PREFIXES = ["shared:", "storage:"];
63
- function protocolInstanceQualifies(graphNodeId) {
64
- const local = graphNodeId.slice(protocolInstancePath(graphNodeId).length);
65
- if (PROTOCOL_PAGE_SPACE_ID_PREFIXES.some((prefix) => local.startsWith(prefix))) return false;
66
- return PROTOCOL_INSTANCE_QUALIFIABLE.some((prefix) => local.startsWith(prefix)) ? true : void 0;
67
- }
68
- //#endregion
69
- //#region src/async-boundary-arm.ts
70
- const ASYNC_BOUNDARY_ARM = {
71
- try: 0,
72
- pending: 1,
73
- catch: 2
74
- };
75
- //#endregion
76
- //#region src/protocol.ts
77
- function protocolEventActionKind(record) {
78
- return record.action?.kind ?? PROTOCOL_EVENT_ACTION_KIND.event;
79
- }
80
- function protocolEventDispatchesMarkless(record) {
81
- return protocolEventActionKind(record) === PROTOCOL_EVENT_ACTION_KIND.event;
82
- }
83
- /**
84
- * The graph read id an arm-update symbol asks under for a minted element() id.
85
- *
86
- * A minted id is `idPrefix + handle` where the prefix is the rendered widget's
87
- * instance token, a seed-map value no flip can reach. The render that served the
88
- * arm resolves the id and files it on the branch record under this key; the
89
- * symbol asks for it through the read channel it already has, so the mint keeps
90
- * exactly one spelling. Resume matches the key as a SUFFIX of the id it is
91
- * handed, because a composed symbol's reads arrive with the instance path
92
- * prepended — that is why the key carries the namespace and not the bare handle.
93
- */
94
- function protocolElementHandleReadId(handleGraphNodeId) {
95
- return `markless:element-handle-id|${handleGraphNodeId}`;
96
- }
97
- //#endregion
98
- export { PROTOCOL_VISIBLE_EVENT_NAME as C, PROTOCOL_IDLE_EVENT_NAME as S, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE as _, ASYNC_PROTOCOL_VERSION as a, PROTOCOL_CONTAINER_START_COMMENT as b, PROTOCOL_PROPS_GRAPH_NODE_ID as c, protocolInstanceQualifies as d, protocolInstanceSegment as f, PROTOCOL_PROP_GRAPH_NODE_PREFIX as g, protocolStateVersion as h, ASYNC_BOUNDARY_ARM as i, STORAGE_PROTOCOL_VERSION as l, protocolRowSegment as m, protocolEventActionKind as n, PROTOCOL_EVENT_ACTION_KIND as o, protocolProjectionSegment as p, protocolEventDispatchesMarkless as r, PROTOCOL_PAGE_SPACE_ID_PREFIXES as s, protocolElementHandleReadId as t, protocolInstancePath as u, PROTOCOL_CONTAINER_END_COMMENT as v, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE as x, PROTOCOL_CONTAINER_HOST_NODE_ID as y };