@eldrajs/theme-core 0.0.0 → 0.1.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +301 -0
  2. package/LICENSE +21 -0
  3. package/README.md +68 -1
  4. package/dist/bridge-DfNINXLL.js +314 -0
  5. package/dist/bridge.d.ts +2 -0
  6. package/dist/bridge.js +2 -0
  7. package/dist/design-tokens.d.ts +68 -0
  8. package/dist/design-tokens.js +486 -0
  9. package/dist/dynamic-route.d.ts +2 -0
  10. package/dist/dynamic-route.js +3 -0
  11. package/dist/dynamicRoute-CxXY-Y_8.js +126 -0
  12. package/dist/dynamicRoute-pRTBoYT6.d.ts +55 -0
  13. package/dist/i18n.d.ts +107 -0
  14. package/dist/i18n.js +192 -0
  15. package/dist/image-framing.d.ts +2 -0
  16. package/dist/image-framing.js +109 -0
  17. package/dist/imageFraming-BUZ-yqho.d.ts +51 -0
  18. package/dist/index-DxrkKyG4.d.ts +488 -0
  19. package/dist/index.d.ts +407 -0
  20. package/dist/index.js +1136 -0
  21. package/dist/layout-CWq_v6ws.d.ts +244 -0
  22. package/dist/layout.d.ts +2 -0
  23. package/dist/layout.js +930 -0
  24. package/dist/links.d.ts +113 -0
  25. package/dist/links.js +184 -0
  26. package/dist/overlay-Bgi0tIbN.d.ts +201 -0
  27. package/dist/overlay-BvkEOiMB.js +2908 -0
  28. package/dist/overlay.d.ts +2 -0
  29. package/dist/overlay.js +6 -0
  30. package/dist/preview-router.d.ts +2 -0
  31. package/dist/preview-router.js +130 -0
  32. package/dist/reusable.d.ts +66 -0
  33. package/dist/reusable.js +92 -0
  34. package/dist/reusableExpansion-Bqm83nCJ.js +229 -0
  35. package/dist/reusableExpansion-CXvs_ckx.d.ts +42 -0
  36. package/dist/stega.d.ts +17 -0
  37. package/dist/stega.js +69 -0
  38. package/dist/template-layout.d.ts +3 -0
  39. package/dist/template-layout.js +328 -0
  40. package/dist/templateLayout-MjNs0gbF.d.ts +254 -0
  41. package/package.json +89 -2
@@ -0,0 +1,2 @@
1
+ import { a as RichTextRenderStateChange, c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, i as RichTextFieldIdentity, l as PREVIEW_ROUTER_MESSAGE_TYPES, n as OverlayRuntime, o as classifyBeforeInput, r as OverlayRuntimeOptions, s as createOverlayRuntime, t as BeforeInputClassification, u as PreviewMessageRouter } from "./overlay-Bgi0tIbN.js";
2
+ export { BeforeInputClassification, type NegotiatedEditorCapabilities, OverlayRuntime, OverlayRuntimeOptions, PREVIEW_ROUTER_MESSAGE_TYPES, type PreviewMessageRouter, type PreviewRouterMessageType, RichTextFieldIdentity, RichTextRenderStateChange, classifyBeforeInput, createOverlayRuntime, createPreviewMessageRouter };
@@ -0,0 +1,6 @@
1
+ import "./stega.js";
2
+ import "./image-framing.js";
3
+ import { n as createOverlayRuntime, t as classifyBeforeInput } from "./overlay-BvkEOiMB.js";
4
+ import "./layout.js";
5
+ import { PREVIEW_ROUTER_MESSAGE_TYPES, createPreviewMessageRouter } from "./preview-router.js";
6
+ export { PREVIEW_ROUTER_MESSAGE_TYPES, classifyBeforeInput, createOverlayRuntime, createPreviewMessageRouter };
@@ -0,0 +1,2 @@
1
+ import { c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, l as PREVIEW_ROUTER_MESSAGE_TYPES, u as PreviewMessageRouter } from "./overlay-Bgi0tIbN.js";
2
+ export { NegotiatedEditorCapabilities, PREVIEW_ROUTER_MESSAGE_TYPES, PreviewMessageRouter, PreviewRouterMessageType, createPreviewMessageRouter };
@@ -0,0 +1,130 @@
1
+ //#region src/previewRouter.ts
2
+ /**
3
+ * The `editor:*` messages whose whole effect is a call on the overlay
4
+ * runtime. They carry no framework state, so they belong here rather than in
5
+ * each framework binding: `@eldrajs/theme-vue` (and any future
6
+ * `theme-react`/`theme-svelte`) delegate to this router and keep only the
7
+ * messages that touch their own reactive context (`editor:init`,
8
+ * `editor:content-update`, `editor:design-tokens`, `editor:set-mode` — which
9
+ * mirrors the mode into the theme's own context before calling the overlay —
10
+ * `editor:navigate` and `editor:refresh`).
11
+ */
12
+ const PREVIEW_ROUTER_MESSAGE_TYPES = [
13
+ "editor:select-block",
14
+ "editor:drag-start",
15
+ "editor:drag-end",
16
+ "editor:framing-mode",
17
+ "editor:rich-text-editing",
18
+ "editor:rich-text-applied",
19
+ "editor:rich-text-locate"
20
+ ];
21
+ const CLOSED = {
22
+ slots: false,
23
+ framing: false,
24
+ richText: false,
25
+ blockHover: false
26
+ };
27
+ /**
28
+ * @param overlay resolved lazily, because adapters create the bridge (whose
29
+ * `onMessage` routes here) before the overlay runtime it posts through.
30
+ */
31
+ function createPreviewMessageRouter(overlay) {
32
+ const resolve = () => typeof overlay === "function" ? overlay() : overlay;
33
+ let capabilities = { ...CLOSED };
34
+ function apply() {
35
+ const runtime = resolve();
36
+ runtime.setFramingEnabled(capabilities.framing);
37
+ runtime.setRichTextEnabled(capabilities.richText);
38
+ runtime.setBlockHoverEnabled(capabilities.blockHover);
39
+ }
40
+ return {
41
+ get capabilities() {
42
+ return capabilities;
43
+ },
44
+ negotiate(list) {
45
+ capabilities = {
46
+ slots: list.includes("block-slots"),
47
+ framing: list.includes("image-framing"),
48
+ richText: list.includes("rich-text-inline"),
49
+ blockHover: list.includes("block-hover")
50
+ };
51
+ apply();
52
+ return capabilities;
53
+ },
54
+ reset() {
55
+ capabilities = { ...CLOSED };
56
+ apply();
57
+ },
58
+ route(type, payload) {
59
+ const runtime = resolve();
60
+ switch (type) {
61
+ case "editor:select-block": {
62
+ const selection = payload;
63
+ runtime.setSelected(selection.entryId, selection.layoutNodeId, selection.reusablePlacementId);
64
+ return true;
65
+ }
66
+ case "editor:drag-start":
67
+ runtime.setDragPayload(payload.payload);
68
+ return true;
69
+ case "editor:drag-end":
70
+ runtime.setDragPayload(null);
71
+ return true;
72
+ case "editor:framing-mode": {
73
+ if (!capabilities.framing) return true;
74
+ const target = payload;
75
+ runtime.setFramingMode(target.entryId === null ? null : {
76
+ entryId: target.entryId,
77
+ fieldPath: target.fieldPath
78
+ });
79
+ return true;
80
+ }
81
+ case "editor:rich-text-editing": {
82
+ if (!capabilities.richText) return true;
83
+ const active = payload !== null && typeof payload === "object" && payload.active === true;
84
+ runtime.setRichTextEditing(richTextTarget(payload), active);
85
+ return true;
86
+ }
87
+ case "editor:rich-text-applied": {
88
+ if (!capabilities.richText) return true;
89
+ const applied = payload !== null && typeof payload === "object" ? payload : {};
90
+ runtime.acceptRichTextApplied({
91
+ ...richTextTarget(payload),
92
+ revision: typeof applied.revision === "number" ? applied.revision : -1,
93
+ anchor: typeof applied.anchor === "number" ? applied.anchor : -1,
94
+ head: typeof applied.head === "number" ? applied.head : -1,
95
+ rerender: applied.rerender !== false
96
+ });
97
+ return true;
98
+ }
99
+ case "editor:rich-text-locate":
100
+ if (!capabilities.richText) return true;
101
+ runtime.locateRichText(richTextTarget(payload));
102
+ return true;
103
+ default: return false;
104
+ }
105
+ }
106
+ };
107
+ }
108
+ /**
109
+ * Normalizes the three identity fields every §18 v3 editor message carries.
110
+ * The payload is untrusted wire data, so a non-object (null, a string, an
111
+ * array) must normalize to an unresolvable target rather than throw on
112
+ * property access and take the message loop with it.
113
+ */
114
+ function richTextTarget(payload) {
115
+ if (payload === null || typeof payload !== "object") return {
116
+ entryId: "",
117
+ fieldPath: "",
118
+ locale: null
119
+ };
120
+ const message = payload;
121
+ return {
122
+ entryId: typeof message.entryId === "string" ? message.entryId : "",
123
+ fieldPath: typeof message.fieldPath === "string" ? message.fieldPath : "",
124
+ locale: typeof message.locale === "string" ? message.locale : null,
125
+ ...typeof message.layoutNodeId === "string" && message.layoutNodeId !== "" ? { layoutNodeId: message.layoutNodeId } : {},
126
+ ...typeof message.reusablePlacementId === "string" && message.reusablePlacementId !== "" ? { reusablePlacementId: message.reusablePlacementId } : {}
127
+ };
128
+ }
129
+ //#endregion
130
+ export { PREVIEW_ROUTER_MESSAGE_TYPES, createPreviewMessageRouter };
@@ -0,0 +1,66 @@
1
+ import { T as SlotValidationContext, c as LayoutBreakpoints, d as LayoutNode, m as LayoutRenderNode, p as LayoutRenderModel, u as LayoutDocument } from "./layout-CWq_v6ws.js";
2
+ import { a as ReusableComponentRevision, i as ReusableComponentResolver, n as ReusableComponentPlacement, o as ReusableRenderIdentity, r as ReusableComponentProjection, s as createProjectionResolver, t as ReusableComponentBinding } from "./reusableExpansion-CXvs_ckx.js";
3
+ //#region src/reusable.d.ts
4
+ export type PageLayoutNode = Extract<LayoutNode, {
5
+ type: 'block';
6
+ }> | ReusableComponentPlacement | (Omit<Extract<LayoutNode, {
7
+ type: 'flex';
8
+ }>, 'children'> & {
9
+ children: PageLayoutNode[];
10
+ }) | (Omit<Extract<LayoutNode, {
11
+ type: 'grid';
12
+ }>, 'children'> & {
13
+ children: PageLayoutNode[];
14
+ });
15
+ export type PageLayoutDocument = LayoutDocument | {
16
+ version: 2;
17
+ root: Extract<PageLayoutNode, {
18
+ type: 'flex' | 'grid';
19
+ }>;
20
+ } | {
21
+ version: 3;
22
+ root: Extract<PageLayoutNode, {
23
+ type: 'flex' | 'grid';
24
+ }>;
25
+ };
26
+ export type ReusableLayoutRenderNode = (Extract<LayoutRenderNode, {
27
+ type: 'block';
28
+ }> & ReusableRenderIdentity) | (Omit<Extract<LayoutRenderNode, {
29
+ type: 'flex' | 'grid';
30
+ }>, 'children'> & ReusableRenderIdentity & {
31
+ children: ReusableLayoutRenderNode[];
32
+ });
33
+ export type ReusableLayoutRenderModel = Omit<LayoutRenderModel, 'root'> & {
34
+ root: Extract<ReusableLayoutRenderNode, {
35
+ type: 'flex' | 'grid';
36
+ }>;
37
+ dependencyKey: string;
38
+ };
39
+ export type ReusableLayoutOptions = {
40
+ projection: ReusableComponentProjection;
41
+ allowedEntryIds?: ReadonlySet<string>;
42
+ allowedContainerIds?: ReadonlySet<string>;
43
+ slotContext?: SlotValidationContext;
44
+ breakpoints?: LayoutBreakpoints;
45
+ };
46
+ export type ReusablePerspective = 'draft' | 'published';
47
+ /**
48
+ * Perspective-fenced exact-revision cache. Invalid snapshots never mutate the
49
+ * cache, and replacing one perspective reports only its known page consumers.
50
+ */
51
+ export declare class ReusableComponentSnapshotCache {
52
+ private readonly snapshots;
53
+ private readonly current;
54
+ private readonly consumers;
55
+ put(perspective: ReusablePerspective, value: unknown): ReadonlySet<string>;
56
+ resolve(perspective: ReusablePerspective): ReusableComponentResolver;
57
+ trackPage(perspective: ReusablePerspective, pageKey: string, bindings: readonly ReusableComponentBinding[]): void;
58
+ untrackPage(perspective: ReusablePerspective, pageKey: string): void;
59
+ }
60
+ /**
61
+ * Expands a page and all exact reusable revisions before producing any render
62
+ * output. The returned model is shared by Vue preview and SSR/static output.
63
+ */
64
+ export declare function createReusableLayoutRenderModel(value: unknown, options: ReusableLayoutOptions): ReusableLayoutRenderModel;
65
+ //#endregion
66
+ export { type ReusableComponentBinding, type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableComponentResolver, type ReusableComponentRevision, type ReusableRenderIdentity, createProjectionResolver };
@@ -0,0 +1,92 @@
1
+ import { createLayoutRenderModel } from "./layout.js";
2
+ import { a as expandReusablePlacements, c as validateProjectionRevisions, i as decorateReusableIdentity, n as assertClosedKeys, o as failLayout, r as createProjectionResolver, s as hasOwn, t as asObject } from "./reusableExpansion-Bqm83nCJ.js";
3
+ //#region src/reusable.ts
4
+ /**
5
+ * Perspective-fenced exact-revision cache. Invalid snapshots never mutate the
6
+ * cache, and replacing one perspective reports only its known page consumers.
7
+ */
8
+ var ReusableComponentSnapshotCache = class {
9
+ snapshots = /* @__PURE__ */ new Map();
10
+ current = /* @__PURE__ */ new Map();
11
+ consumers = /* @__PURE__ */ new Map();
12
+ put(perspective, value) {
13
+ assertPerspective(perspective);
14
+ const revision = validateProjectionRevisions({
15
+ bindings: [],
16
+ revisions: [value]
17
+ }).values().next().value;
18
+ const currentKey = componentPerspectiveKey(perspective, revision.siteId, revision.componentId);
19
+ const previous = this.current.get(currentKey);
20
+ if (previous !== void 0 && previous !== revision.revision) this.snapshots.delete(snapshotKey(perspective, revision.componentId, revision.siteId, previous));
21
+ this.snapshots.set(snapshotKey(perspective, revision.componentId, revision.siteId, revision.revision), revision);
22
+ this.current.set(currentKey, revision.revision);
23
+ if (previous === void 0 || previous === revision.revision) return /* @__PURE__ */ new Set();
24
+ return new Set(this.consumers.get(currentKey) ?? []);
25
+ }
26
+ resolve(perspective) {
27
+ assertPerspective(perspective);
28
+ return ({ componentId, siteId, revision }) => {
29
+ if (this.current.get(componentPerspectiveKey(perspective, siteId, componentId)) !== revision) return null;
30
+ return this.snapshots.get(snapshotKey(perspective, componentId, siteId, revision)) ?? null;
31
+ };
32
+ }
33
+ trackPage(perspective, pageKey, bindings) {
34
+ assertPerspective(perspective);
35
+ this.untrackPage(perspective, pageKey);
36
+ for (const binding of bindings) {
37
+ const key = componentPerspectiveKey(perspective, binding.siteId, binding.componentId);
38
+ const pages = this.consumers.get(key) ?? /* @__PURE__ */ new Set();
39
+ pages.add(pageKey);
40
+ this.consumers.set(key, pages);
41
+ }
42
+ }
43
+ untrackPage(perspective, pageKey) {
44
+ assertPerspective(perspective);
45
+ for (const [key, pages] of this.consumers) {
46
+ if (!key.startsWith(`${perspective}\0`)) continue;
47
+ pages.delete(pageKey);
48
+ if (pages.size === 0) this.consumers.delete(key);
49
+ }
50
+ }
51
+ };
52
+ /**
53
+ * Expands a page and all exact reusable revisions before producing any render
54
+ * output. The returned model is shared by Vue preview and SSR/static output.
55
+ */
56
+ function createReusableLayoutRenderModel(value, options) {
57
+ const envelope = asObject(value, "");
58
+ assertClosedKeys(envelope, ["version", "root"], "");
59
+ if (envelope.version !== 1 && envelope.version !== 2 && envelope.version !== 3) failLayout("/version", "INVALID_VALUE");
60
+ if (!hasOwn(envelope, "root")) failLayout("/root", "REQUIRED");
61
+ const rootObject = asObject(envelope.root, "/root");
62
+ if (rootObject.type !== "flex" && rootObject.type !== "grid") failLayout("/root/type", "INVALID_VALUE");
63
+ const expansion = expandReusablePlacements({
64
+ root: envelope.root,
65
+ path: "/root",
66
+ projection: options.projection,
67
+ allowReusable: envelope.version === 2 || envelope.version === 3,
68
+ ...options.allowedEntryIds === void 0 ? {} : { allowedEntryIds: options.allowedEntryIds },
69
+ ...options.allowedContainerIds === void 0 ? {} : { allowedContainerIds: options.allowedContainerIds }
70
+ });
71
+ const expanded = {
72
+ version: envelope.version,
73
+ root: expansion.root
74
+ };
75
+ const base = createLayoutRenderModel(expanded, options.allowedEntryIds, options.allowedContainerIds, options.slotContext, options.breakpoints);
76
+ return {
77
+ ...base,
78
+ root: decorateReusableIdentity(base.root, expansion.identities),
79
+ dependencyKey: expansion.dependencyKey
80
+ };
81
+ }
82
+ function assertPerspective(value) {
83
+ if (value !== "draft" && value !== "published") throw new TypeError("invalid reusable perspective");
84
+ }
85
+ function componentPerspectiveKey(perspective, siteId, componentId) {
86
+ return `${perspective}\0${siteId}\0${componentId}`;
87
+ }
88
+ function snapshotKey(perspective, componentId, siteId, revision) {
89
+ return `${componentPerspectiveKey(perspective, siteId, componentId)}\0${revision}`;
90
+ }
91
+ //#endregion
92
+ export { ReusableComponentSnapshotCache, createProjectionResolver, createReusableLayoutRenderModel };
@@ -0,0 +1,229 @@
1
+ import { LayoutValidationError, layoutRenderNodeId, normalizeLayoutDocument } from "./layout.js";
2
+ //#region src/reusableExpansion.ts
3
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
4
+ const NODE_ID = /^[A-Za-z][A-Za-z0-9_-]{0,95}$/;
5
+ const MAX_PLACEMENTS = 100;
6
+ const MAX_DEFINITIONS = 100;
7
+ function createProjectionResolver(projection) {
8
+ const revisions = validateProjectionRevisions(validateProjection(projection));
9
+ return ({ componentId, siteId, revision }) => revisions.get(revisionKey(componentId, siteId, revision)) ?? null;
10
+ }
11
+ /**
12
+ * Replaces every reusable placement in a layout tree with the exact revision
13
+ * the projection binds it to, before anything is normalized or rendered.
14
+ * Shared verbatim by page layouts and route-template layouts: the node, its
15
+ * rules, its failure codes and the render identity it hands to the overlay are
16
+ * the same in both, so there is one implementation of all of it.
17
+ */
18
+ function expandReusablePlacements(request) {
19
+ const projection = validateProjection(request.projection);
20
+ const siteIds = /* @__PURE__ */ new Set([...projection.bindings.map((binding) => binding.siteId), ...projection.revisions.map((revision) => revision.siteId)]);
21
+ if (siteIds.size > 1) failLayout("/reusableComponentProjection", "COMPONENT_FOREIGN");
22
+ const siteId = siteIds.values().next().value;
23
+ const resolver = createProjectionResolver(projection);
24
+ const bindings = new Map(projection.bindings.map((binding) => [binding.placementId, binding]));
25
+ const identities = /* @__PURE__ */ new Map();
26
+ const rawIds = /* @__PURE__ */ new Set();
27
+ const usedPlacements = /* @__PURE__ */ new Set();
28
+ const usedRevisions = /* @__PURE__ */ new Set();
29
+ const active = /* @__PURE__ */ new WeakSet();
30
+ const expand = (nodeValue, path) => {
31
+ const node = asObject(nodeValue, path);
32
+ if (active.has(node)) failLayout(path, "INVALID_VALUE");
33
+ active.add(node);
34
+ try {
35
+ const id = node.id;
36
+ if (typeof id !== "string") failLayout(`${path}/id`, "INVALID_TYPE");
37
+ if (!NODE_ID.test(id)) failLayout(`${path}/id`, "INVALID_VALUE");
38
+ if (rawIds.has(id)) failLayout(`${path}/id`, "DUPLICATE_ID");
39
+ rawIds.add(id);
40
+ if (node.type === "reusable") {
41
+ if (!request.allowReusable) failLayout(`${path}/type`, "INVALID_VALUE");
42
+ assertClosedKeys(node, [
43
+ "id",
44
+ "type",
45
+ "componentId"
46
+ ], path);
47
+ if (typeof node.componentId !== "string") failLayout(`${path}/componentId`, "INVALID_TYPE");
48
+ assertUuid(node.componentId, `${path}/componentId`);
49
+ usedPlacements.add(id);
50
+ if (usedPlacements.size > MAX_PLACEMENTS) failLayout(path, "LIMIT_EXCEEDED");
51
+ const binding = bindings.get(id);
52
+ if (!binding) failLayout(path, "COMPONENT_NOT_FOUND");
53
+ if (binding.componentId !== node.componentId) failLayout(`${path}/componentId`, "COMPONENT_STALE");
54
+ if (siteId === void 0 || binding.siteId !== siteId) failLayout(path, "COMPONENT_FOREIGN");
55
+ const revision = resolver(binding);
56
+ if (!revision) failLayout(path, "COMPONENT_NOT_FOUND");
57
+ if (revision.componentId !== binding.componentId || revision.revision !== binding.revision) failLayout(path, "COMPONENT_STALE");
58
+ if (revision.siteId !== siteId) failLayout(path, "COMPONENT_FOREIGN");
59
+ usedRevisions.add(revisionKey(revision.componentId, revision.siteId, revision.revision));
60
+ return cloneComponentNode(normalizeLayoutDocument(revision.document, request.allowedEntryIds, request.allowedContainerIds).document.root, id, identities, true);
61
+ }
62
+ if (node.type === "flex" || node.type === "grid") {
63
+ if (!Array.isArray(node.children)) failLayout(`${path}/children`, "INVALID_TYPE");
64
+ const clone = {
65
+ ...node,
66
+ children: node.children.map((child, index) => expand(child, `${path}/children/${index}`))
67
+ };
68
+ identities.set(id, { nodeId: id });
69
+ return clone;
70
+ }
71
+ identities.set(id, { nodeId: id });
72
+ return { ...node };
73
+ } finally {
74
+ active.delete(node);
75
+ }
76
+ };
77
+ const root = expand(request.root, request.path);
78
+ for (const binding of projection.bindings) if (!usedPlacements.has(binding.placementId)) failLayout("/reusableComponentProjection/bindings", "COMPONENT_STALE");
79
+ if (usedRevisions.size !== projection.revisions.length) failLayout("/reusableComponentProjection/revisions", "COMPONENT_STALE");
80
+ return {
81
+ root,
82
+ identities,
83
+ dependencyKey: projection.bindings.map((binding) => `${binding.placementId}:${binding.componentId}:${binding.revision}`).sort().join("|")
84
+ };
85
+ }
86
+ /**
87
+ * Restores the authored node id on a rendered tree and records the render id
88
+ * (and owning placement, for expanded component content) beside it, so an
89
+ * editor can address a node inside a reusable component by the pair the
90
+ * overlay reads off the DOM.
91
+ */
92
+ function decorateReusableIdentity(node, identities) {
93
+ const identity = identities.get(node.id);
94
+ if (!identity) throw new Error("missing reusable render identity");
95
+ const common = {
96
+ ...node,
97
+ renderId: node.id,
98
+ id: identity.nodeId,
99
+ ...identity
100
+ };
101
+ const children = node.children;
102
+ if (!Array.isArray(children)) return common;
103
+ return {
104
+ ...common,
105
+ children: children.map((child) => decorateReusableIdentity(child, identities))
106
+ };
107
+ }
108
+ function cloneComponentNode(node, placementId, identities, placementRoot = false) {
109
+ const renderId = placementRoot ? placementId : layoutRenderNodeId(`${placementId}\0${node.id}`);
110
+ identities.set(renderId, {
111
+ nodeId: node.id,
112
+ placementId
113
+ });
114
+ if (node.type === "block") return {
115
+ ...node,
116
+ id: renderId
117
+ };
118
+ return {
119
+ ...node,
120
+ id: renderId,
121
+ children: node.children.map((child) => cloneComponentNode(child, placementId, identities))
122
+ };
123
+ }
124
+ function validateProjection(value) {
125
+ const projection = asObject(value, "/reusableComponentProjection");
126
+ assertClosedKeys(projection, ["bindings", "revisions"], "/reusableComponentProjection");
127
+ if (!Array.isArray(projection.bindings)) failLayout("/reusableComponentProjection/bindings", "INVALID_TYPE");
128
+ if (!Array.isArray(projection.revisions)) failLayout("/reusableComponentProjection/revisions", "INVALID_TYPE");
129
+ assertArrayKeys(projection.bindings, "/reusableComponentProjection/bindings");
130
+ assertArrayKeys(projection.revisions, "/reusableComponentProjection/revisions");
131
+ if (projection.bindings.length > MAX_PLACEMENTS) failLayout("/reusableComponentProjection/bindings", "LIMIT_EXCEEDED");
132
+ if (projection.revisions.length > MAX_DEFINITIONS) failLayout("/reusableComponentProjection/revisions", "LIMIT_EXCEEDED");
133
+ const placements = /* @__PURE__ */ new Set();
134
+ const selectedRevisions = /* @__PURE__ */ new Map();
135
+ const bindings = projection.bindings.map((item, index) => {
136
+ const path = `/reusableComponentProjection/bindings/${index}`;
137
+ const binding = asObject(item, path);
138
+ assertClosedKeys(binding, [
139
+ "placementId",
140
+ "componentId",
141
+ "siteId",
142
+ "revision"
143
+ ], path);
144
+ if (typeof binding.placementId !== "string" || !NODE_ID.test(binding.placementId)) failLayout(`${path}/placementId`, "INVALID_VALUE");
145
+ if (placements.has(binding.placementId)) failLayout(`${path}/placementId`, "DUPLICATE_ID");
146
+ placements.add(binding.placementId);
147
+ assertUuid(binding.componentId, `${path}/componentId`);
148
+ assertUuid(binding.siteId, `${path}/siteId`);
149
+ assertRevision(binding.revision, `${path}/revision`);
150
+ const selectionKey = `${binding.siteId}\0${binding.componentId}`;
151
+ const selected = selectedRevisions.get(selectionKey);
152
+ if (selected !== void 0 && selected !== binding.revision) failLayout(`${path}/revision`, "COMPONENT_STALE");
153
+ selectedRevisions.set(selectionKey, binding.revision);
154
+ return binding;
155
+ });
156
+ const revisions = projection.revisions.map((item) => item);
157
+ validateProjectionRevisions({
158
+ bindings,
159
+ revisions
160
+ });
161
+ if ((/* @__PURE__ */ new Set([...bindings.map((binding) => binding.siteId), ...revisions.map((revision) => revision.siteId)])).size > 1) failLayout("/reusableComponentProjection", "COMPONENT_FOREIGN");
162
+ return {
163
+ bindings,
164
+ revisions
165
+ };
166
+ }
167
+ function validateProjectionRevisions(projection) {
168
+ if (!Array.isArray(projection.revisions) || projection.revisions.length > MAX_DEFINITIONS) failLayout("/reusableComponentProjection/revisions", "LIMIT_EXCEEDED");
169
+ const result = /* @__PURE__ */ new Map();
170
+ projection.revisions.forEach((item, index) => {
171
+ const path = `/reusableComponentProjection/revisions/${index}`;
172
+ const revision = asObject(item, path);
173
+ assertClosedKeys(revision, [
174
+ "componentId",
175
+ "siteId",
176
+ "revision",
177
+ "document"
178
+ ], path);
179
+ assertUuid(revision.componentId, `${path}/componentId`);
180
+ assertUuid(revision.siteId, `${path}/siteId`);
181
+ assertRevision(revision.revision, `${path}/revision`);
182
+ const normalized = normalizeLayoutDocument(revision.document);
183
+ const value = {
184
+ componentId: revision.componentId,
185
+ siteId: revision.siteId,
186
+ revision: revision.revision,
187
+ document: normalized.document
188
+ };
189
+ const key = revisionKey(value.componentId, value.siteId, value.revision);
190
+ if (result.has(key)) failLayout(path, "COMPONENT_STALE");
191
+ result.set(key, value);
192
+ });
193
+ return result;
194
+ }
195
+ function revisionKey(componentId, siteId, revision) {
196
+ return `${siteId}\0${componentId}\0${revision}`;
197
+ }
198
+ function asObject(value, path) {
199
+ if (typeof value !== "object" || value === null || Array.isArray(value)) failLayout(path, "INVALID_TYPE");
200
+ return value;
201
+ }
202
+ function assertClosedKeys(value, allowed, path) {
203
+ const set = new Set(allowed);
204
+ const unknown = Object.keys(value).filter((key) => !set.has(key)).sort()[0];
205
+ if (unknown !== void 0) failLayout(`${path}/${unknown.replaceAll("~", "~0").replaceAll("/", "~1")}`, "UNKNOWN_KEY");
206
+ }
207
+ function assertArrayKeys(value, path) {
208
+ const unknown = Object.keys(value).filter((key) => !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length).sort()[0];
209
+ if (unknown !== void 0) failLayout(`${path}/${unknown.replaceAll("~", "~0").replaceAll("/", "~1")}`, "UNKNOWN_KEY");
210
+ }
211
+ function assertUuid(value, path) {
212
+ if (typeof value !== "string") failLayout(path, "INVALID_TYPE");
213
+ if (!UUID.test(value)) failLayout(path, "INVALID_VALUE");
214
+ }
215
+ function assertRevision(value, path) {
216
+ if (typeof value !== "number" || !Number.isSafeInteger(value)) failLayout(path, "INVALID_TYPE");
217
+ if (value < 1) failLayout(path, "INVALID_VALUE");
218
+ }
219
+ function hasOwn(value, key) {
220
+ return Object.prototype.hasOwnProperty.call(value, key);
221
+ }
222
+ function failLayout(path, code) {
223
+ throw new LayoutValidationError({
224
+ path,
225
+ code
226
+ });
227
+ }
228
+ //#endregion
229
+ export { expandReusablePlacements as a, validateProjectionRevisions as c, decorateReusableIdentity as i, assertClosedKeys as n, failLayout as o, createProjectionResolver as r, hasOwn as s, asObject as t };
@@ -0,0 +1,42 @@
1
+ import { u as LayoutDocument } from "./layout-CWq_v6ws.js";
2
+ //#region src/reusableExpansion.d.ts
3
+ /**
4
+ * One reusable-component placement, as it appears in a stored layout document.
5
+ * Page layouts (version 2/3) and route-template layouts (version 1) carry the
6
+ * exact same node, so both expansion paths validate it here rather than each
7
+ * declaring its own shape.
8
+ */
9
+ type ReusableComponentPlacement = {
10
+ id: string;
11
+ type: 'reusable';
12
+ componentId: string;
13
+ };
14
+ type ReusableComponentBinding = {
15
+ placementId: string;
16
+ componentId: string;
17
+ siteId: string;
18
+ revision: number;
19
+ };
20
+ type ReusableComponentRevision = {
21
+ componentId: string;
22
+ siteId: string;
23
+ revision: number;
24
+ document: LayoutDocument;
25
+ };
26
+ type ReusableComponentProjection = {
27
+ bindings: ReusableComponentBinding[];
28
+ revisions: ReusableComponentRevision[];
29
+ };
30
+ type ReusableComponentResolver = (request: Readonly<{
31
+ componentId: string;
32
+ siteId: string;
33
+ revision: number;
34
+ }>) => ReusableComponentRevision | null;
35
+ type ReusableRenderIdentity = {
36
+ renderId: string;
37
+ nodeId: string;
38
+ placementId?: string;
39
+ };
40
+ declare function createProjectionResolver(projection: ReusableComponentProjection): ReusableComponentResolver;
41
+ //#endregion
42
+ export { ReusableComponentRevision as a, ReusableComponentResolver as i, ReusableComponentPlacement as n, ReusableRenderIdentity as o, ReusableComponentProjection as r, createProjectionResolver as s, ReusableComponentBinding as t };
@@ -0,0 +1,17 @@
1
+ //#region src/stega.d.ts
2
+ export interface StegaMeta {
3
+ entryId: string;
4
+ /** Dot path within entry data, e.g. "title" or "cta.label". List indices numeric: "items.2.title". */
5
+ fieldPath: string;
6
+ locale: string | null;
7
+ }
8
+ /** value + zero-width payload suffix. Bits are emitted MSB-first per UTF-8 byte. */
9
+ export declare function encodeStega(value: string, meta: StegaMeta): string;
10
+ /** cleaned only, fast path — removes any U+FEFF…U+FEFF zero-width run (the
11
+ * closing delimiter may be missing when the run ends the string). */
12
+ export declare function stripStega(value: string): string;
13
+ export declare function decodeStega(value: string): {
14
+ cleaned: string;
15
+ meta: StegaMeta | null;
16
+ };
17
+ //#endregion
package/dist/stega.js ADDED
@@ -0,0 +1,69 @@
1
+ //#region src/stega.ts
2
+ const BIT_0 = "​";
3
+ const BIT_1 = "‌";
4
+ const DELIM = "";
5
+ /**
6
+ * A payload run: U+FEFF, the bits, U+FEFF.
7
+ *
8
+ * The closing delimiter may be missing, because U+FEFF is whitespace to
9
+ * `String.prototype.trim()` while the bit characters U+200B/U+200C are not: a
10
+ * theme that renders `value.trim()` hands on a run that ends at its last bit.
11
+ * That form is only recognised when at least one bit is present and nothing
12
+ * but whitespace (or the end of the string) follows, which is exactly the
13
+ * shape trimming leaves behind. A lone U+FEFF is therefore never a run, so a
14
+ * merchant's own text keeps any U+FEFF it happens to contain instead of
15
+ * having it read as an empty payload and deleted.
16
+ */
17
+ const STEGA_RUN = /[​‌]*|[​‌]+(?=\s|$)/g;
18
+ /** value + zero-width payload suffix. Bits are emitted MSB-first per UTF-8 byte. */
19
+ function encodeStega(value, meta) {
20
+ const bytes = new TextEncoder().encode(JSON.stringify(meta));
21
+ let bits = "";
22
+ for (const byte of bytes) for (let bit = 7; bit >= 0; bit -= 1) bits += byte >> bit & 1 ? BIT_1 : BIT_0;
23
+ return value + DELIM + bits + DELIM;
24
+ }
25
+ /** cleaned only, fast path — removes any U+FEFF…U+FEFF zero-width run (the
26
+ * closing delimiter may be missing when the run ends the string). */
27
+ function stripStega(value) {
28
+ STEGA_RUN.lastIndex = 0;
29
+ return value.replace(STEGA_RUN, "");
30
+ }
31
+ function decodeStega(value) {
32
+ STEGA_RUN.lastIndex = 0;
33
+ const match = STEGA_RUN.exec(value);
34
+ if (match === null) return {
35
+ cleaned: value,
36
+ meta: null
37
+ };
38
+ const cleaned = stripStega(value);
39
+ const run = match[0];
40
+ const bits = run.endsWith(DELIM) && run.length > 1 ? run.slice(1, -1) : run.slice(1);
41
+ if (bits.length === 0 || bits.length % 8 !== 0) return {
42
+ cleaned,
43
+ meta: null
44
+ };
45
+ const bytes = new Uint8Array(bits.length / 8);
46
+ for (let i = 0; i < bytes.length; i += 1) {
47
+ let byte = 0;
48
+ for (let j = 0; j < 8; j += 1) byte = byte << 1 | (bits.charAt(i * 8 + j) === BIT_1 ? 1 : 0);
49
+ bytes[i] = byte;
50
+ }
51
+ try {
52
+ const parsed = JSON.parse(new TextDecoder().decode(bytes));
53
+ if (isStegaMeta(parsed)) return {
54
+ cleaned,
55
+ meta: parsed
56
+ };
57
+ } catch {}
58
+ return {
59
+ cleaned,
60
+ meta: null
61
+ };
62
+ }
63
+ function isStegaMeta(v) {
64
+ if (typeof v !== "object" || v === null) return false;
65
+ const m = v;
66
+ return typeof m.entryId === "string" && typeof m.fieldPath === "string" && (m.locale === null || typeof m.locale === "string");
67
+ }
68
+ //#endregion
69
+ export { decodeStega, encodeStega, stripStega };
@@ -0,0 +1,3 @@
1
+ import { a as TemplateLayoutDocument, c as TemplateLayoutRenderNode, i as TemplateLayoutContext, l as buildTemplateBlockRenames, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel } from "./templateLayout-MjNs0gbF.js";
2
+ import { n as ReusableComponentPlacement, o as ReusableRenderIdentity, r as ReusableComponentProjection } from "./reusableExpansion-CXvs_ckx.js";
3
+ export { type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableRenderIdentity, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, buildTemplateBlockRenames, createTemplateLayoutRenderModel };