@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,314 @@
1
+ //#region src/bridge/protocol.ts
2
+ const BRIDGE_PROTOCOL = "eldra-bridge";
3
+ const BRIDGE_VERSION = 1;
4
+ /**
5
+ * §18 v3: the fixed `beforeinput` inputTypes the theme forwards as commands —
6
+ * everything it cannot let the browser do natively inside one text run. The
7
+ * names are the native `InputEvent.inputType` spellings so neither side
8
+ * invents a vocabulary of its own; Studio maps each to a TipTap command.
9
+ */
10
+ const RICH_TEXT_COMMAND_NAMES = [
11
+ "insertParagraph",
12
+ "insertLineBreak",
13
+ "insertFromPaste",
14
+ "insertFromDrop",
15
+ "deleteByCut",
16
+ "deleteContentBackward",
17
+ "deleteContentForward",
18
+ "deleteWordBackward",
19
+ "deleteWordForward",
20
+ "deleteContent",
21
+ "formatBold",
22
+ "formatItalic",
23
+ "formatUnderline",
24
+ "formatStrikeThrough",
25
+ "historyUndo",
26
+ "historyRedo"
27
+ ];
28
+ const KNOWN_MESSAGE_TYPES = /* @__PURE__ */ new Set([
29
+ "editor:hello",
30
+ "editor:init",
31
+ "editor:content-update",
32
+ "editor:design-tokens",
33
+ "editor:theme-messages",
34
+ "editor:select-block",
35
+ "editor:navigate",
36
+ "editor:set-mode",
37
+ "editor:set-viewport",
38
+ "editor:refresh",
39
+ "editor:ping",
40
+ "editor:drag-start",
41
+ "editor:drag-end",
42
+ "editor:framing-mode",
43
+ "editor:rich-text-editing",
44
+ "editor:rich-text-applied",
45
+ "editor:rich-text-locate",
46
+ "theme:ready",
47
+ "theme:pong",
48
+ "theme:route-changed",
49
+ "theme:block-clicked",
50
+ "theme:field-clicked",
51
+ "theme:text-edited",
52
+ "theme:blocks-rendered",
53
+ "theme:block-hovered",
54
+ "theme:slots-rendered",
55
+ "theme:height-changed",
56
+ "theme:error",
57
+ "theme:request-failed",
58
+ "theme:drop-candidate",
59
+ "theme:node-dropped",
60
+ "theme:framing-target",
61
+ "theme:framing-changed",
62
+ "theme:rich-text-selection",
63
+ "theme:rich-text-input",
64
+ "theme:rich-text-command"
65
+ ]);
66
+ /**
67
+ * Capabilities advertised in editor:hello. Single source of truth is contracts §8b.1/§8b.13:
68
+ * the list below, matched verbatim by Studio's vendored app/types/bridge.ts.
69
+ */
70
+ const EDITOR_CAPABILITIES = [
71
+ "content-update",
72
+ "select-block",
73
+ "inline-text",
74
+ "block-slots",
75
+ "block-hover",
76
+ "image-framing",
77
+ "rich-text-inline"
78
+ ];
79
+ /** Capabilities the theme advertises in theme:ready. `block-slots` gates the
80
+ * editor-only slot markers and their theme:slots-rendered geometry reports.
81
+ * `block-hover` gates theme:block-hovered, the hovered block's identity and
82
+ * rect, the same way. `image-framing` gates the framing messages. `rich-text-inline` gates the
83
+ * §18 v3 messages that let the operator edit rich text natively in the
84
+ * theme's own rendered DOM while Studio owns the document, the editor and
85
+ * the toolbar; a side that does not advertise it never sends, and must
86
+ * ignore, those messages. */
87
+ const THEME_CAPABILITIES = [
88
+ "design-tokens",
89
+ "block-slots",
90
+ "block-hover",
91
+ "image-framing",
92
+ "rich-text-inline"
93
+ ];
94
+ //#endregion
95
+ //#region src/bridge/envelope.ts
96
+ function makeEnvelope(type, payload) {
97
+ return {
98
+ protocol: BRIDGE_PROTOCOL,
99
+ version: 1,
100
+ id: crypto.randomUUID(),
101
+ type,
102
+ payload
103
+ };
104
+ }
105
+ /** Returns null for anything that must be ignored; logs per contracts §1.4. */
106
+ function parseEnvelope(data) {
107
+ if (typeof data !== "object" || data === null) return null;
108
+ const e = data;
109
+ if (e.protocol !== "eldra-bridge") return null;
110
+ if (typeof e.version !== "number" || typeof e.id !== "string" || typeof e.type !== "string") {
111
+ console.debug("[eldra-bridge] ignoring malformed envelope");
112
+ return null;
113
+ }
114
+ if (e.version > 1) {
115
+ console.debug(`[eldra-bridge] ignoring newer-version envelope (v${e.version} > v1)`);
116
+ return null;
117
+ }
118
+ if (!KNOWN_MESSAGE_TYPES.has(e.type)) {
119
+ console.debug(`[eldra-bridge] ignoring unknown message type "${e.type}"`);
120
+ return null;
121
+ }
122
+ return e;
123
+ }
124
+ //#endregion
125
+ //#region src/bridge/editor.ts
126
+ const HELLO_INTERVAL_MS = 500;
127
+ const HELLO_MAX_ATTEMPTS = 20;
128
+ const PING_INTERVAL_MS = 5e3;
129
+ const MAX_MISSED_PONGS = 3;
130
+ function createEditorBridge(opts) {
131
+ const { iframe, targetOrigin, onMessage, onDisconnected, onConnected } = opts;
132
+ if (targetOrigin === "*") throw new Error("createEditorBridge: targetOrigin must be an exact origin, never \"*\"");
133
+ let state = "hello";
134
+ let helloTimer = null;
135
+ let pingTimer = null;
136
+ let helloAttempts = 0;
137
+ let missedPongs = 0;
138
+ let pongSinceLastPing = true;
139
+ let disconnectedNotified = false;
140
+ function send(type, payload) {
141
+ iframe.contentWindow?.postMessage(makeEnvelope(type, payload), targetOrigin);
142
+ }
143
+ function stopHello() {
144
+ if (helloTimer !== null) {
145
+ clearInterval(helloTimer);
146
+ helloTimer = null;
147
+ }
148
+ }
149
+ function stopPing() {
150
+ if (pingTimer !== null) {
151
+ clearInterval(pingTimer);
152
+ pingTimer = null;
153
+ }
154
+ }
155
+ function startHello() {
156
+ stopHello();
157
+ stopPing();
158
+ state = "hello";
159
+ helloAttempts = 1;
160
+ send("editor:hello", { capabilities: [...EDITOR_CAPABILITIES] });
161
+ helloTimer = setInterval(() => {
162
+ if (helloAttempts >= HELLO_MAX_ATTEMPTS) {
163
+ stopHello();
164
+ if (!disconnectedNotified) {
165
+ disconnectedNotified = true;
166
+ onDisconnected();
167
+ }
168
+ return;
169
+ }
170
+ helloAttempts += 1;
171
+ send("editor:hello", { capabilities: [...EDITOR_CAPABILITIES] });
172
+ }, HELLO_INTERVAL_MS);
173
+ }
174
+ function startPing() {
175
+ stopPing();
176
+ missedPongs = 0;
177
+ pongSinceLastPing = false;
178
+ pingTimer = setInterval(() => {
179
+ if (!pongSinceLastPing) {
180
+ missedPongs += 1;
181
+ if (missedPongs >= MAX_MISSED_PONGS && !disconnectedNotified) {
182
+ disconnectedNotified = true;
183
+ onDisconnected();
184
+ }
185
+ }
186
+ pongSinceLastPing = false;
187
+ send("editor:ping", {});
188
+ }, PING_INTERVAL_MS);
189
+ }
190
+ function handleMessage(event) {
191
+ if (state === "destroyed") return;
192
+ if (event.origin !== targetOrigin || event.source !== iframe.contentWindow) return;
193
+ const env = parseEnvelope(event.data);
194
+ if (env === null) return;
195
+ if (!env.type.startsWith("theme:")) return;
196
+ if (env.type === "theme:pong") {
197
+ missedPongs = 0;
198
+ pongSinceLastPing = true;
199
+ if (disconnectedNotified) {
200
+ disconnectedNotified = false;
201
+ onConnected();
202
+ }
203
+ return;
204
+ }
205
+ if (env.type === "theme:ready") {
206
+ if (state === "hello") {
207
+ stopHello();
208
+ state = "connected";
209
+ disconnectedNotified = false;
210
+ onConnected();
211
+ startPing();
212
+ }
213
+ }
214
+ onMessage(env.type, env.payload);
215
+ }
216
+ const onLoad = () => {
217
+ startHello();
218
+ };
219
+ window.addEventListener("message", handleMessage);
220
+ iframe.addEventListener("load", onLoad);
221
+ return {
222
+ post(type, payload) {
223
+ if (state === "destroyed") return;
224
+ send(type, payload);
225
+ },
226
+ destroy() {
227
+ state = "destroyed";
228
+ stopHello();
229
+ stopPing();
230
+ window.removeEventListener("message", handleMessage);
231
+ iframe.removeEventListener("load", onLoad);
232
+ }
233
+ };
234
+ }
235
+ //#endregion
236
+ //#region src/bridge/theme.ts
237
+ const PRE_LOCK_QUEUE_LIMIT = 50;
238
+ function createThemeBridge(opts) {
239
+ const { allowedOrigins, onMessage } = opts;
240
+ let lockedOrigin = null;
241
+ let initReceived = false;
242
+ let destroyed = false;
243
+ const preLockQueue = [];
244
+ function deliver(env) {
245
+ if (lockedOrigin === null) return;
246
+ window.parent.postMessage(env, lockedOrigin);
247
+ }
248
+ function forward(env) {
249
+ onMessage(env.type, env.payload);
250
+ }
251
+ function sendReady() {
252
+ deliver(makeEnvelope("theme:ready", {
253
+ manifestVersion: 1,
254
+ themeVersion: readMeta("eldra-theme-version"),
255
+ sdkVersion: readMeta("eldra-sdk-version"),
256
+ path: window.location.pathname,
257
+ capabilities: [...THEME_CAPABILITIES],
258
+ ...opts.breakpoints === void 0 ? {} : { breakpoints: opts.breakpoints }
259
+ }));
260
+ }
261
+ /** semantics 2: lock the first allowed origin as the sole reply target, then flush queued posts. */
262
+ function lockAndFlush(origin) {
263
+ lockedOrigin = origin;
264
+ for (const queued of preLockQueue.splice(0)) deliver(queued);
265
+ }
266
+ function handleMessage(event) {
267
+ if (destroyed) return;
268
+ if (lockedOrigin !== null ? event.origin !== lockedOrigin : !allowedOrigins.includes(event.origin)) return;
269
+ const env = parseEnvelope(event.data);
270
+ if (env === null) return;
271
+ if (!env.type.startsWith("editor:")) return;
272
+ if (env.type === "editor:hello") {
273
+ opts.onEditorHello?.(env.payload.capabilities);
274
+ if (lockedOrigin === null) {
275
+ lockedOrigin = event.origin;
276
+ sendReady();
277
+ for (const queued of preLockQueue.splice(0)) deliver(queued);
278
+ } else sendReady();
279
+ return;
280
+ }
281
+ if (lockedOrigin === null) lockAndFlush(event.origin);
282
+ if (env.type === "editor:ping") {
283
+ deliver(makeEnvelope("theme:pong", {}));
284
+ return;
285
+ }
286
+ if (env.type === "editor:init") initReceived = true;
287
+ forward(env);
288
+ }
289
+ window.addEventListener("message", handleMessage);
290
+ return {
291
+ post(type, payload) {
292
+ if (destroyed) return;
293
+ const env = makeEnvelope(type, payload);
294
+ if (lockedOrigin === null) {
295
+ if (preLockQueue.length < PRE_LOCK_QUEUE_LIMIT) preLockQueue.push(env);
296
+ return;
297
+ }
298
+ deliver(env);
299
+ },
300
+ get connected() {
301
+ return initReceived;
302
+ },
303
+ destroy() {
304
+ destroyed = true;
305
+ window.removeEventListener("message", handleMessage);
306
+ }
307
+ };
308
+ }
309
+ /** theme/sdk versions are stamped as <meta> tags by @eldrajs/theme-nuxt (B7); '0.0.0' outside it. */
310
+ function readMeta(name) {
311
+ return document.querySelector(`meta[name="${name}"]`)?.content ?? "0.0.0";
312
+ }
313
+ //#endregion
314
+ export { BRIDGE_PROTOCOL as a, KNOWN_MESSAGE_TYPES as c, parseEnvelope as i, RICH_TEXT_COMMAND_NAMES as l, createEditorBridge as n, BRIDGE_VERSION as o, makeEnvelope as r, EDITOR_CAPABILITIES as s, createThemeBridge as t, THEME_CAPABILITIES as u };
@@ -0,0 +1,2 @@
1
+ import { C as RichTextDoc, D as ThemeRichTextCommandMessage, E as THEME_CAPABILITIES, O as ThemeRichTextInputMessage, S as RichTextCommandName, T as StructuralDragPayload, _ as EditorRichTextLocateMessage, a as BRIDGE_PROTOCOL, b as ResolvedDesignTokensPayload, c as BridgeHandler, d as DOMRectLike, f as DraftEntryPayload, g as EditorRichTextEditingMessage, h as EditorRichTextAppliedMessage, i as parseEnvelope, k as ThemeRichTextSelectionMessage, l as BridgeMessageType, m as EditorMode, n as createEditorBridge, o as BRIDGE_VERSION, p as EDITOR_CAPABILITIES, r as makeEnvelope, s as BridgeEnvelope, t as createThemeBridge, u as BridgePayloads, v as KNOWN_MESSAGE_TYPES, w as RichTextIdentity, x as ResolvedThemeMessagesPayload, y as RICH_TEXT_COMMAND_NAMES } from "./index-DxrkKyG4.js";
2
+ export { BRIDGE_PROTOCOL, BRIDGE_VERSION, type BridgeEnvelope, type BridgeHandler, type BridgeMessageType, type BridgePayloads, type DOMRectLike, type DraftEntryPayload, EDITOR_CAPABILITIES, type EditorMode, type EditorRichTextAppliedMessage, type EditorRichTextEditingMessage, type EditorRichTextLocateMessage, KNOWN_MESSAGE_TYPES, RICH_TEXT_COMMAND_NAMES, type ResolvedDesignTokensPayload, type ResolvedThemeMessagesPayload, type RichTextCommandName, type RichTextDoc, type RichTextIdentity, type StructuralDragPayload, THEME_CAPABILITIES, type ThemeRichTextCommandMessage, type ThemeRichTextInputMessage, type ThemeRichTextSelectionMessage, createEditorBridge, createThemeBridge, makeEnvelope, parseEnvelope };
package/dist/bridge.js ADDED
@@ -0,0 +1,2 @@
1
+ import { a as BRIDGE_PROTOCOL, c as KNOWN_MESSAGE_TYPES, i as parseEnvelope, l as RICH_TEXT_COMMAND_NAMES, n as createEditorBridge, o as BRIDGE_VERSION, r as makeEnvelope, s as EDITOR_CAPABILITIES, t as createThemeBridge, u as THEME_CAPABILITIES } from "./bridge-DfNINXLL.js";
2
+ export { BRIDGE_PROTOCOL, BRIDGE_VERSION, EDITOR_CAPABILITIES, KNOWN_MESSAGE_TYPES, RICH_TEXT_COMMAND_NAMES, THEME_CAPABILITIES, createEditorBridge, createThemeBridge, makeEnvelope, parseEnvelope };
@@ -0,0 +1,68 @@
1
+ //#region src/designTokens.d.ts
2
+ export type DesignTokenId = string;
3
+ export type ColorLiteral = string;
4
+ export type ResponsiveTokenValue<T> = {
5
+ normal: T;
6
+ tablet?: T;
7
+ mobile?: T;
8
+ };
9
+ export interface ThemeColorToken {
10
+ label: string;
11
+ value: ColorLiteral;
12
+ group?: string;
13
+ allowSiteOverride?: boolean;
14
+ }
15
+ export interface ContainerPreset {
16
+ label: string;
17
+ maxWidth: CssTokenLength | 'none';
18
+ gutter: ResponsiveTokenValue<CssTokenLength>;
19
+ allowSiteOverride?: boolean;
20
+ }
21
+ export interface ThemeDesignTokens {
22
+ colors: Record<DesignTokenId, ThemeColorToken>;
23
+ containers: Record<DesignTokenId, ContainerPreset>;
24
+ allowCustomColors?: boolean;
25
+ }
26
+ export interface ContainerOverride {
27
+ maxWidth: CssTokenLength | 'none';
28
+ gutter: ResponsiveTokenValue<CssTokenLength>;
29
+ }
30
+ export interface SiteDesignTokenOverrides {
31
+ colors: Record<DesignTokenId, ColorLiteral>;
32
+ containers: Record<DesignTokenId, ContainerOverride>;
33
+ }
34
+ export interface DesignTokenCatalog {
35
+ revision: number;
36
+ theme: ThemeDesignTokens;
37
+ overrides: SiteDesignTokenOverrides;
38
+ resolved: ThemeDesignTokens;
39
+ }
40
+ export type ColorSelection = {
41
+ kind: 'token';
42
+ token: DesignTokenId;
43
+ } | {
44
+ kind: 'custom';
45
+ value: ColorLiteral;
46
+ };
47
+ export type CssTokenLength = `${number}px` | `${number}rem` | `${number}%`;
48
+ export type DesignTokenValidationCode = 'INVALID_TYPE' | 'UNKNOWN_KEY' | 'REQUIRED' | 'INVALID_VALUE' | 'LIMIT_EXCEEDED' | 'TOKEN_NOT_FOUND' | 'OVERRIDE_FORBIDDEN';
49
+ export declare class DesignTokenValidationError extends Error {
50
+ readonly path: string;
51
+ readonly code: DesignTokenValidationCode;
52
+ constructor(path: string, code: DesignTokenValidationCode);
53
+ }
54
+ export declare function normalizeThemeDesignTokens(value: unknown): ThemeDesignTokens;
55
+ export declare function normalizeSiteDesignTokenOverrides(value: unknown, theme: ThemeDesignTokens): SiteDesignTokenOverrides;
56
+ export declare function resolveDesignTokenCatalog(value: unknown): DesignTokenCatalog;
57
+ export declare function applyDesignTokenOverrides(themeValue: unknown, overridesValue: unknown): ThemeDesignTokens;
58
+ export declare function normalizeColorSelection(value: unknown, tokens: ThemeDesignTokens, opts?: {
59
+ allowCustomColors?: boolean;
60
+ }): ColorSelection;
61
+ export declare function resolveColorSelection(selection: unknown, tokens: ThemeDesignTokens): string;
62
+ export declare function generateDesignTokenCss(value: ThemeDesignTokens | DesignTokenCatalog, opts?: {
63
+ scope?: string;
64
+ }): string;
65
+ export declare function generateTailwindThemeCss(value: ThemeDesignTokens | DesignTokenCatalog): string;
66
+ export declare function designTokenRevisionHash(value: ThemeDesignTokens | DesignTokenCatalog): string;
67
+ export declare function responsiveValue<T>(value: ResponsiveTokenValue<T>, breakpoint: 'normal' | 'tablet' | 'mobile'): T;
68
+ //#endregion