@tecof/theme-editor 0.0.1

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.js ADDED
@@ -0,0 +1,411 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var core = require('@puckeditor/core');
6
+
7
+ // src/components/TecofProvider.tsx
8
+
9
+ // src/api.ts
10
+ var TecofApiClient = class {
11
+ constructor(apiUrl, secretKey) {
12
+ this.apiUrl = apiUrl.replace(/\/+$/, "");
13
+ this.secretKey = secretKey;
14
+ }
15
+ get headers() {
16
+ return {
17
+ "x-secret-key": this.secretKey,
18
+ Accept: "application/json",
19
+ "Content-Type": "application/json"
20
+ };
21
+ }
22
+ /**
23
+ * Fetch a page by ID (for the editor)
24
+ */
25
+ async getPage(pageId) {
26
+ try {
27
+ const res = await fetch(`${this.apiUrl}/api/store/editor/${pageId}`, {
28
+ method: "GET",
29
+ headers: this.headers
30
+ });
31
+ return await res.json();
32
+ } catch (error) {
33
+ return {
34
+ success: false,
35
+ message: error instanceof Error ? error.message : "Failed to fetch page"
36
+ };
37
+ }
38
+ }
39
+ /**
40
+ * Save a page by ID
41
+ */
42
+ async savePage(pageId, puckData, title) {
43
+ try {
44
+ const res = await fetch(`${this.apiUrl}/api/store/editor/${pageId}`, {
45
+ method: "PUT",
46
+ headers: this.headers,
47
+ body: JSON.stringify({ puckData, ...title && { title } })
48
+ });
49
+ return await res.json();
50
+ } catch (error) {
51
+ return {
52
+ success: false,
53
+ message: error instanceof Error ? error.message : "Failed to save page"
54
+ };
55
+ }
56
+ }
57
+ };
58
+ var TecofContext = react.createContext(null);
59
+ var TecofProvider = ({ apiUrl, secretKey, children }) => {
60
+ const value = react.useMemo(
61
+ () => ({
62
+ apiClient: new TecofApiClient(apiUrl, secretKey),
63
+ secretKey,
64
+ apiUrl
65
+ }),
66
+ [apiUrl, secretKey]
67
+ );
68
+ return /* @__PURE__ */ jsxRuntime.jsx(TecofContext.Provider, { value, children });
69
+ };
70
+ function useTecof() {
71
+ const ctx = react.useContext(TecofContext);
72
+ if (!ctx) {
73
+ throw new Error("useTecof must be used within a <TecofProvider>");
74
+ }
75
+ return ctx;
76
+ }
77
+
78
+ // src/components/styles.ts
79
+ var editorStyles = {
80
+ wrapper: {
81
+ position: "relative",
82
+ width: "100%",
83
+ height: "100%"
84
+ },
85
+ loading: {
86
+ display: "flex",
87
+ alignItems: "center",
88
+ justifyContent: "center",
89
+ minHeight: "100vh",
90
+ background: "#fafafa"
91
+ },
92
+ loadingInner: {
93
+ textAlign: "center"
94
+ },
95
+ loadingText: {
96
+ fontSize: "14px",
97
+ color: "#71717a",
98
+ fontFamily: "'Inter', system-ui, sans-serif"
99
+ },
100
+ saveIndicator: {
101
+ position: "fixed",
102
+ bottom: "20px",
103
+ right: "20px",
104
+ padding: "8px 16px",
105
+ background: "#18181b",
106
+ color: "#ffffff",
107
+ fontSize: "13px",
108
+ fontWeight: 500,
109
+ borderRadius: "8px",
110
+ boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
111
+ zIndex: 9999,
112
+ fontFamily: "'Inter', system-ui, sans-serif"
113
+ },
114
+ spinner: {
115
+ width: "40px",
116
+ height: "40px",
117
+ border: "3px solid #e4e4e7",
118
+ borderTopColor: "#18181b",
119
+ borderRadius: "50%",
120
+ margin: "0 auto 12px",
121
+ animation: "tecof-spin 0.7s linear infinite"
122
+ }
123
+ };
124
+ var keyframesInjected = false;
125
+ var injectKeyframes = () => {
126
+ if (keyframesInjected || typeof document === "undefined") return;
127
+ const style = document.createElement("style");
128
+ style.textContent = `@keyframes tecof-spin { to { transform: rotate(360deg); } }`;
129
+ document.head.appendChild(style);
130
+ keyframesInjected = true;
131
+ };
132
+ var EMPTY_PAGE = { content: [], root: { props: {} }, zones: {} };
133
+ var TecofEditor = ({
134
+ pageId,
135
+ config,
136
+ onSave,
137
+ onPublish,
138
+ onChange,
139
+ overrides,
140
+ plugins: extraPlugins,
141
+ className
142
+ }) => {
143
+ const { apiClient } = useTecof();
144
+ const [initialData, setInitialData] = react.useState(null);
145
+ const [loading, setLoading] = react.useState(true);
146
+ const [saving, setSaving] = react.useState(false);
147
+ const [saveStatus, setSaveStatus] = react.useState("idle");
148
+ const puckDataRef = react.useRef(null);
149
+ const isEmbedded = typeof window !== "undefined" && window.parent !== window;
150
+ react.useEffect(() => {
151
+ injectKeyframes();
152
+ }, []);
153
+ react.useEffect(() => {
154
+ let cancelled = false;
155
+ const load = async () => {
156
+ setLoading(true);
157
+ const res = await apiClient.getPage(pageId);
158
+ if (cancelled) return;
159
+ setInitialData(res.success && res.data?.puckData ? res.data.puckData : EMPTY_PAGE);
160
+ setLoading(false);
161
+ };
162
+ load();
163
+ return () => {
164
+ cancelled = true;
165
+ };
166
+ }, [pageId, apiClient]);
167
+ const handlePublish = react.useCallback(
168
+ async (data) => {
169
+ const puckData = data;
170
+ setSaving(true);
171
+ setSaveStatus("idle");
172
+ const res = await apiClient.savePage(pageId, puckData);
173
+ if (res.success) {
174
+ setSaveStatus("success");
175
+ setTimeout(() => setSaveStatus("idle"), 3e3);
176
+ onSave?.(puckData);
177
+ onPublish?.(puckData);
178
+ if (isEmbedded) window.parent.postMessage({ type: "puck:saved" }, "*");
179
+ } else {
180
+ setSaveStatus("error");
181
+ }
182
+ setSaving(false);
183
+ },
184
+ [pageId, apiClient, isEmbedded, onSave, onPublish]
185
+ );
186
+ const handleChange = react.useCallback(
187
+ (data) => {
188
+ const puckData = data;
189
+ puckDataRef.current = puckData;
190
+ onChange?.(puckData);
191
+ if (isEmbedded) window.parent.postMessage({ type: "puck:save" }, "*");
192
+ },
193
+ [onChange, isEmbedded]
194
+ );
195
+ react.useEffect(() => {
196
+ if (!isEmbedded) return;
197
+ const onMessage = (e) => {
198
+ switch (e.data?.type) {
199
+ case "puck:publish": {
200
+ const btn = document.querySelector('[data-testid="puck-publish"]');
201
+ btn ? btn.click() : puckDataRef.current && handlePublish(puckDataRef.current);
202
+ break;
203
+ }
204
+ case "puck:undo":
205
+ document.dispatchEvent(new KeyboardEvent("keydown", { key: "z", code: "KeyZ", ctrlKey: true, bubbles: true }));
206
+ break;
207
+ case "puck:redo":
208
+ document.dispatchEvent(new KeyboardEvent("keydown", { key: "z", code: "KeyZ", ctrlKey: true, shiftKey: true, bubbles: true }));
209
+ break;
210
+ case "puck:viewport": {
211
+ const frame = document.querySelector('[data-testid="puck-frame"]');
212
+ if (frame) {
213
+ const w = e.data.width || "100%";
214
+ frame.style.maxWidth = w;
215
+ frame.style.margin = w === "100%" ? "0" : "0 auto";
216
+ frame.style.transition = "max-width 0.3s ease";
217
+ }
218
+ break;
219
+ }
220
+ }
221
+ };
222
+ window.addEventListener("message", onMessage);
223
+ return () => window.removeEventListener("message", onMessage);
224
+ }, [isEmbedded, handlePublish]);
225
+ if (loading || !initialData) {
226
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: editorStyles.loading, className, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: editorStyles.loadingInner, children: [
227
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: editorStyles.spinner }),
228
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: editorStyles.loadingText, children: "Loading editor..." })
229
+ ] }) });
230
+ }
231
+ const plugins = [
232
+ ...core.fieldsPlugin ? [core.fieldsPlugin({ desktopSideBar: "left" })] : [],
233
+ ...extraPlugins || []
234
+ ];
235
+ const mergedOverrides = { header: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}), ...overrides || {} };
236
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: editorStyles.wrapper, className, children: [
237
+ /* @__PURE__ */ jsxRuntime.jsx(
238
+ core.Puck,
239
+ {
240
+ plugins,
241
+ config,
242
+ data: initialData,
243
+ onPublish: handlePublish,
244
+ onChange: handleChange,
245
+ overrides: mergedOverrides
246
+ }
247
+ ),
248
+ saving && /* @__PURE__ */ jsxRuntime.jsx("div", { style: editorStyles.saveIndicator, children: saveStatus === "error" ? "Save failed" : "Saving..." })
249
+ ] });
250
+ };
251
+ var TecofRender = ({ data, config, className }) => {
252
+ if (!data) return null;
253
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, children: /* @__PURE__ */ jsxRuntime.jsx(core.Render, { config, data }) });
254
+ };
255
+
256
+ // src/utils/index.ts
257
+ function hexToHsl(hex) {
258
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
259
+ if (!result) return { h: 0, s: 0, l: 0 };
260
+ let r = parseInt(result[1], 16) / 255;
261
+ let g = parseInt(result[2], 16) / 255;
262
+ let b = parseInt(result[3], 16) / 255;
263
+ const max = Math.max(r, g, b);
264
+ const min = Math.min(r, g, b);
265
+ let h = 0;
266
+ let s = 0;
267
+ const l = (max + min) / 2;
268
+ if (max !== min) {
269
+ const d = max - min;
270
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
271
+ switch (max) {
272
+ case r:
273
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
274
+ break;
275
+ case g:
276
+ h = ((b - r) / d + 2) / 6;
277
+ break;
278
+ case b:
279
+ h = ((r - g) / d + 4) / 6;
280
+ break;
281
+ }
282
+ }
283
+ return {
284
+ h: Math.round(h * 360),
285
+ s: Math.round(s * 100),
286
+ l: Math.round(l * 100)
287
+ };
288
+ }
289
+ function hslToHex(h, s, l) {
290
+ const sNorm = s / 100;
291
+ const lNorm = l / 100;
292
+ const a = sNorm * Math.min(lNorm, 1 - lNorm);
293
+ const f = (n) => {
294
+ const k = (n + h / 30) % 12;
295
+ const color = lNorm - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
296
+ return Math.round(255 * color).toString(16).padStart(2, "0");
297
+ };
298
+ return `#${f(0)}${f(8)}${f(4)}`;
299
+ }
300
+ function lighten(hex, amount) {
301
+ const { h, s, l } = hexToHsl(hex);
302
+ return hslToHex(h, s, Math.min(100, l + amount));
303
+ }
304
+ function darken(hex, amount) {
305
+ const { h, s, l } = hexToHsl(hex);
306
+ return hslToHex(h, s, Math.max(0, l - amount));
307
+ }
308
+ function generateCSSVariables(theme) {
309
+ const lines = [":root {"];
310
+ for (const [key, value] of Object.entries(theme.colors)) {
311
+ const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
312
+ lines.push(` --theme-color-${cssKey}: ${value};`);
313
+ }
314
+ lines.push(` --theme-font-family: ${theme.typography.fontFamily};`);
315
+ lines.push(` --theme-heading-font-family: ${theme.typography.headingFontFamily};`);
316
+ lines.push(` --theme-font-size-base: ${theme.typography.baseFontSize}px;`);
317
+ lines.push(` --theme-line-height: ${theme.typography.lineHeight};`);
318
+ lines.push(` --theme-font-weight-normal: ${theme.typography.fontWeightNormal};`);
319
+ lines.push(` --theme-font-weight-medium: ${theme.typography.fontWeightMedium};`);
320
+ lines.push(` --theme-font-weight-bold: ${theme.typography.fontWeightBold};`);
321
+ for (const [level, scale] of Object.entries(theme.typography.headingScale)) {
322
+ lines.push(` --theme-heading-${level}: ${scale}rem;`);
323
+ }
324
+ lines.push(` --theme-container-max-width: ${theme.spacing.containerMaxWidth}px;`);
325
+ lines.push(` --theme-section-padding-y: ${theme.spacing.sectionPaddingY}px;`);
326
+ lines.push(` --theme-section-padding-x: ${theme.spacing.sectionPaddingX}px;`);
327
+ lines.push(` --theme-component-gap: ${theme.spacing.componentGap}px;`);
328
+ lines.push(` --theme-border-radius: ${theme.spacing.borderRadius}px;`);
329
+ lines.push(` --theme-border-radius-lg: ${theme.spacing.borderRadiusLg}px;`);
330
+ lines.push(` --theme-border-radius-sm: ${theme.spacing.borderRadiusSm}px;`);
331
+ if (theme.customTokens) {
332
+ for (const [key, value] of Object.entries(theme.customTokens)) {
333
+ lines.push(` --theme-${key}: ${value};`);
334
+ }
335
+ }
336
+ lines.push("}");
337
+ return lines.join("\n");
338
+ }
339
+ function getDefaultTheme() {
340
+ return {
341
+ colors: {
342
+ primary: "#18181b",
343
+ secondary: "#f4f4f5",
344
+ accent: "#3b82f6",
345
+ background: "#ffffff",
346
+ foreground: "#09090b",
347
+ muted: "#f4f4f5",
348
+ mutedForeground: "#71717a",
349
+ border: "#e4e4e7",
350
+ card: "#ffffff",
351
+ cardForeground: "#09090b",
352
+ destructive: "#ef4444"
353
+ },
354
+ typography: {
355
+ fontFamily: "'Inter', system-ui, -apple-system, sans-serif",
356
+ headingFontFamily: "'Inter', system-ui, -apple-system, sans-serif",
357
+ baseFontSize: 16,
358
+ lineHeight: 1.6,
359
+ headingScale: {
360
+ h1: 3,
361
+ h2: 2.25,
362
+ h3: 1.875,
363
+ h4: 1.5,
364
+ h5: 1.25,
365
+ h6: 1
366
+ },
367
+ fontWeightNormal: 400,
368
+ fontWeightMedium: 500,
369
+ fontWeightBold: 700
370
+ },
371
+ spacing: {
372
+ containerMaxWidth: 1280,
373
+ sectionPaddingY: 80,
374
+ sectionPaddingX: 24,
375
+ componentGap: 24,
376
+ borderRadius: 8,
377
+ borderRadiusLg: 12,
378
+ borderRadiusSm: 4
379
+ }
380
+ };
381
+ }
382
+ function mergeTheme(base, overrides) {
383
+ const result = {
384
+ colors: { ...base.colors, ...overrides.colors ?? {} },
385
+ typography: { ...base.typography, ...overrides.typography ?? {} },
386
+ spacing: { ...base.spacing, ...overrides.spacing ?? {} },
387
+ customTokens: { ...base.customTokens ?? {}, ...overrides.customTokens ?? {} }
388
+ };
389
+ if (overrides.typography?.headingScale) {
390
+ result.typography.headingScale = {
391
+ ...base.typography.headingScale,
392
+ ...overrides.typography.headingScale
393
+ };
394
+ }
395
+ return result;
396
+ }
397
+
398
+ exports.TecofApiClient = TecofApiClient;
399
+ exports.TecofEditor = TecofEditor;
400
+ exports.TecofProvider = TecofProvider;
401
+ exports.TecofRender = TecofRender;
402
+ exports.darken = darken;
403
+ exports.generateCSSVariables = generateCSSVariables;
404
+ exports.getDefaultTheme = getDefaultTheme;
405
+ exports.hexToHsl = hexToHsl;
406
+ exports.hslToHex = hslToHex;
407
+ exports.lighten = lighten;
408
+ exports.mergeTheme = mergeTheme;
409
+ exports.useTecof = useTecof;
410
+ //# sourceMappingURL=index.js.map
411
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/api.ts","../src/components/TecofProvider.tsx","../src/components/styles.ts","../src/components/TecofEditor.tsx","../src/components/TecofRender.tsx","../src/utils/index.ts"],"names":["createContext","useMemo","jsx","useContext","useState","useRef","useEffect","useCallback","jsxs","fieldsPlugin","Fragment","Puck","Render"],"mappings":";;;;;;;;;AAUO,IAAM,iBAAN,MAAqB;AAAA,EAI1B,WAAA,CAAY,QAAgB,SAAA,EAAmB;AAE7C,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA,CAAO,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACvC,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AAAA,EAEA,IAAY,OAAA,GAAkC;AAC5C,IAAA,OAAO;AAAA,MACL,gBAAgB,IAAA,CAAK,SAAA;AAAA,MACrB,MAAA,EAAQ,kBAAA;AAAA,MACR,cAAA,EAAgB;AAAA,KAClB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,MAAA,EAAmD;AAC/D,IAAA,IAAI;AACF,MAAA,MAAM,GAAA,GAAM,MAAM,KAAA,CAAM,CAAA,EAAG,KAAK,MAAM,CAAA,kBAAA,EAAqB,MAAM,CAAA,CAAA,EAAI;AAAA,QACnE,MAAA,EAAQ,KAAA;AAAA,QACR,SAAS,IAAA,CAAK;AAAA,OACf,CAAA;AACD,MAAA,OAAO,MAAM,IAAI,IAAA,EAAK;AAAA,IACxB,SAAS,KAAA,EAAO;AACd,MAAA,OAAO;AAAA,QACL,OAAA,EAAS,KAAA;AAAA,QACT,OAAA,EAAS,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU;AAAA,OACpD;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAA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AiB,EAAA;AAAA,MACjB,eAAA,EAAiB,EAAA;AAAA,MACjB,YAAA,EAAc,EAAA;AAAA,MACd,YAAA,EAAc,CAAA;AAAA,MACd,cAAA,EAAgB,EAAA;AAAA,MAChB,cAAA,EAAgB;AAAA;AAClB,GACF;AACF;AAQO,SAAS,UAAA,CAAW,MAAmB,SAAA,EAA8C;AAC1F,EAAA,MAAM,MAAA,GAAsB;AAAA,IAC1B,MAAA,EAAQ,EAAE,GAAG,IAAA,CAAK,QAAQ,GAAI,SAAA,CAAU,MAAA,IAAU,EAAC,EAAG;AAAA,IACtD,UAAA,EAAY,EAAE,GAAG,IAAA,CAAK,YAAY,GAAI,SAAA,CAAU,UAAA,IAAc,EAAC,EAAG;AAAA,IAClE,OAAA,EAAS,EAAE,GAAG,IAAA,CAAK,SAAS,GAAI,SAAA,CAAU,OAAA,IAAW,EAAC,EAAG;AAAA,IACzD,YAAA,EAAc,EAAE,GAAI,IAAA,CAAK,YAAA,IAAgB,EAAC,EAAI,GAAI,SAAA,CAAU,YAAA,IAAgB,EAAC;AAAG,GAClF;AAGA,EAAA,IAAI,SAAA,CAAU,YAAY,YAAA,EAAc;AACtC,IAAA,MAAA,CAAO,WAAW,YAAA,GAAe;AAAA,MAC/B,GAAG,KAAK,UAAA,CAAW,YAAA;AAAA,MACnB,GAAG,UAAU,UAAA,CAAW;AAAA,KAC1B;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import type { ApiResponse, PuckPageData, PageApiData } from './types';\n\n/**\n * Tecof API Client — handles communication with the Tecof backend\n * for page CRUD operations using merchant secret key.\n *\n * Endpoints:\n * - GET /api/store/editor/:id → get page by ID\n * - PUT /api/store/editor/:id → save page by ID\n */\nexport class TecofApiClient {\n private apiUrl: string;\n private secretKey: string;\n\n constructor(apiUrl: string, secretKey: string) {\n // Remove trailing slash\n this.apiUrl = apiUrl.replace(/\\/+$/, '');\n this.secretKey = secretKey;\n }\n\n private get headers(): Record<string, string> {\n return {\n 'x-secret-key': this.secretKey,\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n };\n }\n\n /**\n * Fetch a page by ID (for the editor)\n */\n async getPage(pageId: string): Promise<ApiResponse<PageApiData>> {\n try {\n const res = await fetch(`${this.apiUrl}/api/store/editor/${pageId}`, {\n method: 'GET',\n headers: this.headers,\n });\n return await res.json();\n } catch (error) {\n return {\n success: false,\n message: error instanceof Error ? error.message : 'Failed to fetch page',\n };\n }\n }\n\n /**\n * Save a page by ID\n */\n async savePage(\n pageId: string,\n puckData: PuckPageData,\n title?: string\n ): Promise<ApiResponse<PageApiData>> {\n try {\n const res = await fetch(`${this.apiUrl}/api/store/editor/${pageId}`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({ puckData, ...(title && { title }) }),\n });\n return await res.json();\n } catch (error) {\n return {\n success: false,\n message: error instanceof Error ? error.message : 'Failed to save page',\n };\n }\n }\n}\n\nexport default TecofApiClient;\n","import { createContext, useContext, useMemo } from 'react';\nimport { TecofApiClient } from '../api';\nimport type { TecofProviderProps } from '../types';\n\n/* ─── Context ─── */\n\ninterface TecofContextValue {\n apiClient: TecofApiClient;\n secretKey: string;\n apiUrl: string;\n}\n\nconst TecofContext = createContext<TecofContextValue | null>(null);\n\n/* ─── Provider ─── */\n\nexport const TecofProvider = ({ apiUrl, secretKey, children }: TecofProviderProps) => {\n const value = useMemo<TecofContextValue>(\n () => ({\n apiClient: new TecofApiClient(apiUrl, secretKey),\n secretKey,\n apiUrl,\n }),\n [apiUrl, secretKey]\n );\n\n return <TecofContext.Provider value={value}>{children}</TecofContext.Provider>;\n};\n\n/* ─── Hook ─── */\n\nexport function useTecof(): TecofContextValue {\n const ctx = useContext(TecofContext);\n if (!ctx) {\n throw new Error('useTecof must be used within a <TecofProvider>');\n }\n return ctx;\n}\n\nexport default TecofProvider;\n","/**\n * Scoped styles for TecofEditor — inlined to avoid CSS module build issues.\n * These are internal styles, not exposed to consumers.\n */\nexport const editorStyles = {\n wrapper: {\n position: 'relative' as const,\n width: '100%',\n height: '100%',\n },\n loading: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: '100vh',\n background: '#fafafa',\n },\n loadingInner: {\n textAlign: 'center' as const,\n },\n loadingText: {\n fontSize: '14px',\n color: '#71717a',\n fontFamily: \"'Inter', system-ui, sans-serif\",\n },\n error: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: '200px',\n padding: '24px',\n fontSize: '14px',\n color: '#ef4444',\n fontFamily: \"'Inter', system-ui, sans-serif\",\n },\n saveIndicator: {\n position: 'fixed' as const,\n bottom: '20px',\n right: '20px',\n padding: '8px 16px',\n background: '#18181b',\n color: '#ffffff',\n fontSize: '13px',\n fontWeight: 500,\n borderRadius: '8px',\n boxShadow: '0 4px 12px rgba(0,0,0,0.15)',\n zIndex: 9999,\n fontFamily: \"'Inter', system-ui, sans-serif\",\n },\n spinner: {\n width: '40px',\n height: '40px',\n border: '3px solid #e4e4e7',\n borderTopColor: '#18181b',\n borderRadius: '50%',\n margin: '0 auto 12px',\n animation: 'tecof-spin 0.7s linear infinite',\n },\n} as const;\n\n/** Spinner keyframes — injected once into the document */\nlet keyframesInjected = false;\nexport const injectKeyframes = () => {\n if (keyframesInjected || typeof document === 'undefined') return;\n const style = document.createElement('style');\n style.textContent = `@keyframes tecof-spin { to { transform: rotate(360deg); } }`;\n document.head.appendChild(style);\n keyframesInjected = true;\n};\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { Puck, fieldsPlugin, type Data, type Config } from '@puckeditor/core';\nimport { useTecof } from './TecofProvider';\nimport { editorStyles, injectKeyframes } from './styles';\nimport type { TecofEditorProps, PuckPageData } from '../types';\n\nconst EMPTY_PAGE: PuckPageData = { content: [], root: { props: {} }, zones: {} };\n\n/**\n * TecofEditor — Puck CMS page editor.\n *\n * - Fetches page by ID via secretKey auth\n * - Saves on publish\n * - Supports iframe postMessage (undo/redo/publish/viewport)\n *\n * Requires `<TecofProvider>` ancestor for API client.\n */\nexport const TecofEditor = ({\n pageId,\n config,\n onSave,\n onPublish,\n onChange,\n overrides,\n plugins: extraPlugins,\n className,\n}: TecofEditorProps) => {\n const { apiClient } = useTecof();\n\n const [initialData, setInitialData] = useState<PuckPageData | null>(null);\n const [loading, setLoading] = useState(true);\n const [saving, setSaving] = useState(false);\n const [saveStatus, setSaveStatus] = useState<'idle' | 'success' | 'error'>('idle');\n\n const puckDataRef = useRef<PuckPageData | null>(null);\n const isEmbedded = typeof window !== 'undefined' && window.parent !== window;\n\n // Inject spinner keyframes once\n useEffect(() => { injectKeyframes(); }, []);\n\n /* ── Fetch page ── */\n useEffect(() => {\n let cancelled = false;\n const load = async () => {\n setLoading(true);\n const res = await apiClient.getPage(pageId);\n if (cancelled) return;\n setInitialData(res.success && res.data?.puckData ? res.data.puckData : EMPTY_PAGE);\n setLoading(false);\n };\n load();\n return () => { cancelled = true; };\n }, [pageId, apiClient]);\n\n /* ── Save / Publish ── */\n const handlePublish = useCallback(\n async (data: Data) => {\n const puckData = data as unknown as PuckPageData;\n setSaving(true);\n setSaveStatus('idle');\n\n const res = await apiClient.savePage(pageId, puckData);\n\n if (res.success) {\n setSaveStatus('success');\n setTimeout(() => setSaveStatus('idle'), 3000);\n onSave?.(puckData);\n onPublish?.(puckData);\n if (isEmbedded) window.parent.postMessage({ type: 'puck:saved' }, '*');\n } else {\n setSaveStatus('error');\n }\n\n setSaving(false);\n },\n [pageId, apiClient, isEmbedded, onSave, onPublish]\n );\n\n /* ── Change ── */\n const handleChange = useCallback(\n (data: Data) => {\n const puckData = data as unknown as PuckPageData;\n puckDataRef.current = puckData;\n onChange?.(puckData);\n if (isEmbedded) window.parent.postMessage({ type: 'puck:save' }, '*');\n },\n [onChange, isEmbedded]\n );\n\n /* ── iframe postMessage ── */\n useEffect(() => {\n if (!isEmbedded) return;\n\n const onMessage = (e: MessageEvent) => {\n switch (e.data?.type) {\n case 'puck:publish': {\n const btn = document.querySelector('[data-testid=\"puck-publish\"]') as HTMLButtonElement;\n btn ? btn.click() : puckDataRef.current && handlePublish(puckDataRef.current);\n break;\n }\n case 'puck:undo':\n document.dispatchEvent(new KeyboardEvent('keydown', { key: 'z', code: 'KeyZ', ctrlKey: true, bubbles: true }));\n break;\n case 'puck:redo':\n document.dispatchEvent(new KeyboardEvent('keydown', { key: 'z', code: 'KeyZ', ctrlKey: true, shiftKey: true, bubbles: true }));\n break;\n case 'puck:viewport': {\n const frame = document.querySelector('[data-testid=\"puck-frame\"]') as HTMLElement;\n if (frame) {\n const w = e.data.width || '100%';\n frame.style.maxWidth = w;\n frame.style.margin = w === '100%' ? '0' : '0 auto';\n frame.style.transition = 'max-width 0.3s ease';\n }\n break;\n }\n }\n };\n\n window.addEventListener('message', onMessage);\n return () => window.removeEventListener('message', onMessage);\n }, [isEmbedded, handlePublish]);\n\n /* ── Loading ── */\n if (loading || !initialData) {\n return (\n <div style={editorStyles.loading} className={className}>\n <div style={editorStyles.loadingInner}>\n <div style={editorStyles.spinner} />\n <p style={editorStyles.loadingText}>Loading editor...</p>\n </div>\n </div>\n );\n }\n\n /* ── Plugins & Overrides ── */\n const plugins = [\n ...(fieldsPlugin ? [fieldsPlugin({ desktopSideBar: 'left' })] : []),\n ...(extraPlugins || []),\n ];\n\n const mergedOverrides = { header: () => <></>, ...(overrides || {}) };\n\n return (\n <div style={editorStyles.wrapper} className={className}>\n <Puck\n plugins={plugins}\n config={config as Config}\n data={initialData}\n onPublish={handlePublish}\n onChange={handleChange}\n overrides={mergedOverrides}\n />\n {saving && (\n <div style={editorStyles.saveIndicator}>\n {saveStatus === 'error' ? 'Save failed' : 'Saving...'}\n </div>\n )}\n </div>\n );\n};\n\nexport default TecofEditor;","import { Render, type Config } from '@puckeditor/core';\nimport type { TecofRenderProps } from '../types';\n\n/**\n * TecofRender — Puck page renderer.\n *\n * Pass `data` (PuckPageData) and `config` (Puck Config) directly.\n * No API fetch, no provider required.\n */\nexport const TecofRender = ({ data, config, className }: TecofRenderProps) => {\n if (!data) return null;\n\n return (\n <div className={className}>\n <Render config={config as Config} data={data} />\n </div>\n );\n};\n\nexport default TecofRender;\n","import type { ThemeConfig, HSL } from '../types';\n\n/* ─── Color Converters ─── */\n\nexport function hexToHsl(hex: string): HSL {\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n if (!result) return { h: 0, s: 0, l: 0 };\n\n let r = parseInt(result[1], 16) / 255;\n let g = parseInt(result[2], 16) / 255;\n let b = parseInt(result[3], 16) / 255;\n\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n let h = 0;\n let s = 0;\n const l = (max + min) / 2;\n\n if (max !== min) {\n const d = max - min;\n s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n switch (max) {\n case r:\n h = ((g - b) / d + (g < b ? 6 : 0)) / 6;\n break;\n case g:\n h = ((b - r) / d + 2) / 6;\n break;\n case b:\n h = ((r - g) / d + 4) / 6;\n break;\n }\n }\n\n return {\n h: Math.round(h * 360),\n s: Math.round(s * 100),\n l: Math.round(l * 100),\n };\n}\n\nexport function hslToHex(h: number, s: number, l: number): string {\n const sNorm = s / 100;\n const lNorm = l / 100;\n const a = sNorm * Math.min(lNorm, 1 - lNorm);\n\n const f = (n: number) => {\n const k = (n + h / 30) % 12;\n const color = lNorm - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n return Math.round(255 * color)\n .toString(16)\n .padStart(2, '0');\n };\n\n return `#${f(0)}${f(8)}${f(4)}`;\n}\n\n/* ─── Color Manipulation ─── */\n\nexport function lighten(hex: string, amount: number): string {\n const { h, s, l } = hexToHsl(hex);\n return hslToHex(h, s, Math.min(100, l + amount));\n}\n\nexport function darken(hex: string, amount: number): string {\n const { h, s, l } = hexToHsl(hex);\n return hslToHex(h, s, Math.max(0, l - amount));\n}\n\n/* ─── CSS Variable Generation ─── */\n\nexport function generateCSSVariables(theme: ThemeConfig): string {\n const lines: string[] = [':root {'];\n\n // Colors\n for (const [key, value] of Object.entries(theme.colors)) {\n const cssKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();\n lines.push(` --theme-color-${cssKey}: ${value};`);\n }\n\n // Typography\n lines.push(` --theme-font-family: ${theme.typography.fontFamily};`);\n lines.push(` --theme-heading-font-family: ${theme.typography.headingFontFamily};`);\n lines.push(` --theme-font-size-base: ${theme.typography.baseFontSize}px;`);\n lines.push(` --theme-line-height: ${theme.typography.lineHeight};`);\n lines.push(` --theme-font-weight-normal: ${theme.typography.fontWeightNormal};`);\n lines.push(` --theme-font-weight-medium: ${theme.typography.fontWeightMedium};`);\n lines.push(` --theme-font-weight-bold: ${theme.typography.fontWeightBold};`);\n\n for (const [level, scale] of Object.entries(theme.typography.headingScale)) {\n lines.push(` --theme-heading-${level}: ${scale}rem;`);\n }\n\n // Spacing\n lines.push(` --theme-container-max-width: ${theme.spacing.containerMaxWidth}px;`);\n lines.push(` --theme-section-padding-y: ${theme.spacing.sectionPaddingY}px;`);\n lines.push(` --theme-section-padding-x: ${theme.spacing.sectionPaddingX}px;`);\n lines.push(` --theme-component-gap: ${theme.spacing.componentGap}px;`);\n lines.push(` --theme-border-radius: ${theme.spacing.borderRadius}px;`);\n lines.push(` --theme-border-radius-lg: ${theme.spacing.borderRadiusLg}px;`);\n lines.push(` --theme-border-radius-sm: ${theme.spacing.borderRadiusSm}px;`);\n\n // Custom tokens\n if (theme.customTokens) {\n for (const [key, value] of Object.entries(theme.customTokens)) {\n lines.push(` --theme-${key}: ${value};`);\n }\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\n/* ─── Default Theme ─── */\n\nexport function getDefaultTheme(): ThemeConfig {\n return {\n colors: {\n primary: '#18181b',\n secondary: '#f4f4f5',\n accent: '#3b82f6',\n background: '#ffffff',\n foreground: '#09090b',\n muted: '#f4f4f5',\n mutedForeground: '#71717a',\n border: '#e4e4e7',\n card: '#ffffff',\n cardForeground: '#09090b',\n destructive: '#ef4444',\n },\n typography: {\n fontFamily: \"'Inter', system-ui, -apple-system, sans-serif\",\n headingFontFamily: \"'Inter', system-ui, -apple-system, sans-serif\",\n baseFontSize: 16,\n lineHeight: 1.6,\n headingScale: {\n h1: 3,\n h2: 2.25,\n h3: 1.875,\n h4: 1.5,\n h5: 1.25,\n h6: 1,\n },\n fontWeightNormal: 400,\n fontWeightMedium: 500,\n fontWeightBold: 700,\n },\n spacing: {\n containerMaxWidth: 1280,\n sectionPaddingY: 80,\n sectionPaddingX: 24,\n componentGap: 24,\n borderRadius: 8,\n borderRadiusLg: 12,\n borderRadiusSm: 4,\n },\n };\n}\n\n/* ─── Deep Merge ─── */\n\nfunction isObject(item: unknown): item is Record<string, unknown> {\n return Boolean(item && typeof item === 'object' && !Array.isArray(item));\n}\n\nexport function mergeTheme(base: ThemeConfig, overrides: Partial<ThemeConfig>): ThemeConfig {\n const result: ThemeConfig = {\n colors: { ...base.colors, ...(overrides.colors ?? {}) },\n typography: { ...base.typography, ...(overrides.typography ?? {}) },\n spacing: { ...base.spacing, ...(overrides.spacing ?? {}) },\n customTokens: { ...(base.customTokens ?? {}), ...(overrides.customTokens ?? {}) },\n };\n\n // Deep-merge headingScale if provided\n if (overrides.typography?.headingScale) {\n result.typography.headingScale = {\n ...base.typography.headingScale,\n ...overrides.typography.headingScale,\n };\n }\n\n return result;\n}\n"]}