@kubuild/renderer 0.0.1 → 0.2.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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -0
  3. package/dist/action-dispatcher.d.ts +42 -0
  4. package/dist/action-dispatcher.d.ts.map +1 -0
  5. package/dist/action-runners/api-request.d.ts +77 -0
  6. package/dist/action-runners/api-request.d.ts.map +1 -0
  7. package/dist/action-runners/index.d.ts +24 -0
  8. package/dist/action-runners/index.d.ts.map +1 -0
  9. package/dist/action-runners/modal-manager.d.ts +68 -0
  10. package/dist/action-runners/modal-manager.d.ts.map +1 -0
  11. package/dist/action-runners/navigation-utils.d.ts +49 -0
  12. package/dist/action-runners/navigation-utils.d.ts.map +1 -0
  13. package/dist/action-runners/toast-container.d.ts +20 -0
  14. package/dist/action-runners/toast-container.d.ts.map +1 -0
  15. package/dist/action-runners/toast-manager.d.ts +74 -0
  16. package/dist/action-runners/toast-manager.d.ts.map +1 -0
  17. package/dist/action-runners/ui-feedback.d.ts +33 -0
  18. package/dist/action-runners/ui-feedback.d.ts.map +1 -0
  19. package/dist/animation.d.ts +26 -0
  20. package/dist/animation.d.ts.map +1 -0
  21. package/dist/code-generator.d.ts +47 -0
  22. package/dist/code-generator.d.ts.map +1 -0
  23. package/dist/error-boundary.d.ts +2 -0
  24. package/dist/error-boundary.d.ts.map +1 -1
  25. package/dist/form-context.d.ts +114 -0
  26. package/dist/form-context.d.ts.map +1 -0
  27. package/dist/index.cjs +184 -2044
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +7 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +184 -1990
  32. package/dist/index.js.map +1 -1
  33. package/dist/nodes/editable-text.d.ts +15 -0
  34. package/dist/nodes/editable-text.d.ts.map +1 -0
  35. package/dist/nodes/form-nodes.d.ts +153 -0
  36. package/dist/nodes/form-nodes.d.ts.map +1 -0
  37. package/dist/nodes/html-embed.d.ts +15 -0
  38. package/dist/nodes/html-embed.d.ts.map +1 -0
  39. package/dist/nodes/index.d.ts +5 -0
  40. package/dist/nodes/index.d.ts.map +1 -0
  41. package/dist/nodes/media-utils.d.ts +17 -0
  42. package/dist/nodes/media-utils.d.ts.map +1 -0
  43. package/dist/preview-adapter.d.ts +1 -1
  44. package/dist/preview-adapter.d.ts.map +1 -1
  45. package/dist/renderer.d.ts +4 -24
  46. package/dist/renderer.d.ts.map +1 -1
  47. package/dist/renderers/index.d.ts +2 -0
  48. package/dist/renderers/index.d.ts.map +1 -0
  49. package/dist/renderers/render-node-content.d.ts +66 -0
  50. package/dist/renderers/render-node-content.d.ts.map +1 -0
  51. package/dist/styles.d.ts +8 -3
  52. package/dist/styles.d.ts.map +1 -1
  53. package/package.json +13 -14
package/dist/index.js CHANGED
@@ -1,267 +1,5 @@
1
- // src/renderer.tsx
2
- import { useRef, useLayoutEffect, useEffect, useMemo as useMemo2 } from "react";
3
- import { isAssetReference, isActionBinding as isActionBinding2, isVariableBinding as isVariableBinding3 } from "@kubuild/schema";
4
- import { createDefaultComponentRegistry } from "@kubuild/components";
5
-
6
- // src/render-context.tsx
7
- import { createContext, useContext, useMemo } from "react";
8
- import { resolveBinding } from "@kubuild/core";
9
- import { isVariableBinding, isActionBinding } from "@kubuild/schema";
10
- import { jsx } from "react/jsx-runtime";
11
- var DEFAULT_RENDER_CONTEXT = Object.freeze({});
12
- var RenderContextReact = createContext(DEFAULT_RENDER_CONTEXT);
13
- function createRenderContext(options) {
14
- if (!options) {
15
- return DEFAULT_RENDER_CONTEXT;
16
- }
17
- const frozenVariables = options.variables ? Object.freeze({ ...options.variables }) : void 0;
18
- return Object.freeze({
19
- variables: frozenVariables,
20
- ...options.assetProvider ? { assetProvider: options.assetProvider } : {},
21
- ...options.actionRegistry ? { actionRegistry: options.actionRegistry } : {},
22
- ...options.onDiagnostic ? { onDiagnostic: options.onDiagnostic } : {}
23
- });
24
- }
25
- function createMinimalRenderContext(options) {
26
- const assetsMap = new Map(Object.entries(options?.assets ?? {}));
27
- const actionsMap = new Map(Object.entries(options?.actions ?? {}));
28
- const assetProvider = {
29
- resolve: (assetIdOrUri) => {
30
- return assetsMap.get(assetIdOrUri) || assetIdOrUri;
31
- }
32
- };
33
- const actionRegistry = {
34
- get: (type) => actionsMap.get(type),
35
- register: (type, handler) => {
36
- actionsMap.set(type, handler);
37
- },
38
- unregister: (type) => {
39
- actionsMap.delete(type);
40
- }
41
- };
42
- return createRenderContext({
43
- variables: options?.variables,
44
- assetProvider,
45
- actionRegistry,
46
- onDiagnostic: options?.onDiagnostic
47
- });
48
- }
49
- var RenderContextProvider = ({ value, children }) => {
50
- const contextValue = useMemo(() => value || DEFAULT_RENDER_CONTEXT, [value]);
51
- return /* @__PURE__ */ jsx(RenderContextReact.Provider, { value: contextValue, children });
52
- };
53
- function useRenderContext() {
54
- return useContext(RenderContextReact);
55
- }
56
- function resolveAssetSync(assetProvider, assetIdOrUri) {
57
- if (!assetProvider || !assetIdOrUri) {
58
- return void 0;
59
- }
60
- try {
61
- const result = assetProvider.resolve(assetIdOrUri);
62
- return typeof result === "string" ? result : void 0;
63
- } catch {
64
- return void 0;
65
- }
66
- }
67
- function resolveVariable(context, value) {
68
- if (value === null || value === void 0) {
69
- return value;
70
- }
71
- if (isVariableBinding(value)) {
72
- return resolveBinding(value, context).value;
73
- }
74
- if (typeof value === "string" && value.includes("{{")) {
75
- return value.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (match, key) => {
76
- const outcome = resolveBinding({ key }, context);
77
- if (outcome.status === "resolved") {
78
- return String(outcome.value);
79
- }
80
- return match;
81
- });
82
- }
83
- return value;
84
- }
85
- function resolveActionPayloadDetailed(context, payload) {
86
- if (!payload || typeof payload !== "object") {
87
- return { value: payload, invalidPaths: [] };
88
- }
89
- const invalidPaths = [];
90
- const resolveValueRecursively = (val, path) => {
91
- if (val === null || val === void 0) {
92
- return val;
93
- }
94
- if (isVariableBinding(val)) {
95
- const outcome = resolveBinding(val, context);
96
- if (outcome.status === "empty") {
97
- invalidPaths.push(path);
98
- }
99
- return outcome.value;
100
- }
101
- if (typeof val === "string") {
102
- if (val.includes("{{")) {
103
- return val.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (match, key) => {
104
- const outcome = resolveBinding({ key }, context);
105
- if (outcome.status !== "resolved") {
106
- invalidPaths.push(path);
107
- return match;
108
- }
109
- return String(outcome.value);
110
- });
111
- }
112
- return val;
113
- }
114
- if (Array.isArray(val)) {
115
- return val.map((item, index) => resolveValueRecursively(item, `${path}[${index}]`));
116
- }
117
- if (typeof val === "object") {
118
- const copy = {};
119
- for (const [k, v] of Object.entries(val)) {
120
- copy[k] = resolveValueRecursively(v, path ? `${path}.${k}` : k);
121
- }
122
- return copy;
123
- }
124
- return val;
125
- };
126
- const resolved = {};
127
- for (const [key, value] of Object.entries(payload)) {
128
- resolved[key] = resolveValueRecursively(value, key);
129
- }
130
- return { value: resolved, invalidPaths };
131
- }
132
- function resolveActionPayload(context, payload) {
133
- return resolveActionPayloadDetailed(context, payload).value;
134
- }
135
- function isActionRegistered(actionRegistry, actionType) {
136
- if (!actionRegistry || !actionType) {
137
- return false;
138
- }
139
- return Boolean(actionRegistry.get(actionType));
140
- }
141
- function dispatchAction(options) {
142
- const { action, nodeId, document, context, onDiagnostic } = options;
143
- if (!isActionBinding(action)) {
144
- const diagnostic = {
145
- code: "INVALID_ACTION_PAYLOAD",
146
- actionType: typeof action?.type === "string" ? action.type : "unknown",
147
- nodeId,
148
- message: `Invalid action binding on node ${nodeId || "unknown"}.`
149
- };
150
- onDiagnostic?.(diagnostic);
151
- context?.onDiagnostic?.(diagnostic);
152
- return false;
153
- }
154
- const handler = context?.actionRegistry?.get(action.type);
155
- if (!handler) {
156
- const diagnostic = {
157
- code: "UNKNOWN_ACTION",
158
- actionType: action.type,
159
- nodeId,
160
- message: `No action handler registered for action type "${action.type}".`
161
- };
162
- onDiagnostic?.(diagnostic);
163
- context?.onDiagnostic?.(diagnostic);
164
- return false;
165
- }
166
- const { value: resolvedPayload, invalidPaths } = resolveActionPayloadDetailed(context, action.payload);
167
- if (invalidPaths.length > 0) {
168
- const diagnostic = {
169
- code: "INVALID_ACTION_BINDING",
170
- actionType: action.type,
171
- nodeId,
172
- message: `Action "${action.type}" payload has unresolved binding path(s) [${invalidPaths.join(
173
- ", "
174
- )}] on node ${nodeId || "unknown"}; handler was not invoked.`,
175
- invalidPaths
176
- };
177
- onDiagnostic?.(diagnostic);
178
- context?.onDiagnostic?.(diagnostic);
179
- return false;
180
- }
181
- const executionContext = {
182
- nodeId,
183
- document,
184
- variables: context?.variables
185
- };
186
- try {
187
- const result = handler(resolvedPayload, executionContext);
188
- if (result && typeof result.catch === "function") {
189
- result.catch((error) => {
190
- const diagnostic = {
191
- code: "ACTION_EXECUTION_ERROR",
192
- actionType: action.type,
193
- nodeId,
194
- message: `Action "${action.type}" handler threw an asynchronous error: ${error instanceof Error ? error.message : String(error)}`,
195
- error
196
- };
197
- onDiagnostic?.(diagnostic);
198
- context?.onDiagnostic?.(diagnostic);
199
- });
200
- }
201
- return true;
202
- } catch (error) {
203
- const diagnostic = {
204
- code: "ACTION_EXECUTION_ERROR",
205
- actionType: action.type,
206
- nodeId,
207
- message: `Action "${action.type}" handler threw a synchronous error: ${error instanceof Error ? error.message : String(error)}`,
208
- error
209
- };
210
- onDiagnostic?.(diagnostic);
211
- context?.onDiagnostic?.(diagnostic);
212
- return false;
213
- }
214
- }
215
-
216
- // src/renderer.tsx
217
- import { resolveBinding as resolveBinding3, sanitizeUrl, sanitizeHtml } from "@kubuild/core";
218
- import { icons as lucideIcons } from "lucide-react";
219
-
220
- // src/styles.ts
221
- function resolveNodeStyles(styles, viewport = "desktop") {
222
- if (!styles) return {};
223
- const base = styles.base || {};
224
- const override = styles[viewport] || {};
225
- return { ...base, ...override };
226
- }
227
- function escapeCssValue(value) {
228
- return String(value).replace(/[{};]+/g, "");
229
- }
230
- function escapeCssIdent(value) {
231
- return value.replace(/["\\\]]/g, "\\$&");
232
- }
233
- function styleDefinitionToCssDeclarations(styleDefinition) {
234
- if (!styleDefinition || typeof styleDefinition !== "object") return "";
235
- const declarations = [];
236
- for (const [key, value] of Object.entries(styleDefinition)) {
237
- if (value === null || value === void 0 || value === "") continue;
238
- const property = key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
239
- declarations.push(`${property}: ${escapeCssValue(value)};`);
240
- }
241
- return declarations.join(" ");
242
- }
243
- function collectStateStylesCss(document) {
244
- if (!document?.document) return "";
245
- const rules = [];
246
- const walk = (node) => {
247
- const states = node.styles?.states;
248
- if (states && typeof states === "object") {
249
- for (const [state, styleDefinition] of Object.entries(states)) {
250
- const declarations = styleDefinitionToCssDeclarations(
251
- styleDefinition
252
- );
253
- if (!declarations) continue;
254
- const safeState = /^::?[a-zA-Z-]+$/.test(state) ? state : null;
255
- if (!safeState) continue;
256
- rules.push(`[data-kubuild-node="${escapeCssIdent(node.id)}"]${safeState} { ${declarations} }`);
257
- }
258
- }
259
- node.children?.forEach(walk);
260
- };
261
- walk(document.document);
262
- return rules.join("\n");
263
- }
264
- var DEFAULT_CSS_RESET = `
1
+ import{isActionBinding as no}from"@kubuild/schema";import{createDefaultComponentRegistry as oo}from"@kubuild/components";import{createContext as _t,useContext as jt,useMemo as zt}from"react";import{resolveBinding as pe}from"@kubuild/core";import{isVariableBinding as _e,isActionBinding as Ut}from"@kubuild/schema";import{jsx as Kt}from"react/jsx-runtime";var ie=Object.freeze({}),je=_t(ie);function Wt(r){if(!r)return ie;let e=r.variables?Object.freeze({...r.variables}):void 0;return Object.freeze({variables:e,...r.assetProvider?{assetProvider:r.assetProvider}:{},...r.actionRegistry?{actionRegistry:r.actionRegistry}:{},...r.onDiagnostic?{onDiagnostic:r.onDiagnostic}:{}})}function vo(r){let e=new Map(Object.entries(r?.assets??{})),i=new Map(Object.entries(r?.actions??{})),o={resolve:t=>e.get(t)||t},n={get:t=>i.get(t),register:(t,l)=>{i.set(t,l)},unregister:t=>{i.delete(t)}};return Wt({variables:r?.variables,assetProvider:o,actionRegistry:n,onDiagnostic:r?.onDiagnostic})}var ze=({value:r,children:e})=>{let i=zt(()=>r||ie,[r]);return Kt(je.Provider,{value:i,children:e})};function Ue(){return jt(je)}function Re(r,e){if(!(!r||!e))try{let i=r.resolve(e);return typeof i=="string"?i:void 0}catch{return}}function We(r,e){return e==null?e:_e(e)?pe(e,r).value:typeof e=="string"&&e.includes("{{")?e.replace(/\{\{\s*([\w.-]+)\s*\}\}/g,(i,o)=>{let n=pe({key:o},r);return n.status==="resolved"?String(n.value):i}):e}function Ke(r,e){if(!e||typeof e!="object")return{value:e,invalidPaths:[]};let i=[],o=(t,l)=>{if(t==null)return t;if(_e(t)){let f=pe(t,r);return f.status==="empty"&&i.push(l),f.value}if(typeof t=="string")return t.includes("{{")?t.replace(/\{\{\s*([\w.-]+)\s*\}\}/g,(f,p)=>{let u=pe({key:p},r);return u.status!=="resolved"?(i.push(l),f):String(u.value)}):t;if(Array.isArray(t))return t.map((f,p)=>o(f,`${l}[${p}]`));if(typeof t=="object"){let f={};for(let[p,u]of Object.entries(t))f[p]=o(u,l?`${l}.${p}`:p);return f}return t},n={};for(let[t,l]of Object.entries(e))n[t]=o(l,t);return{value:n,invalidPaths:i}}function Ye(r,e){return Ke(r,e).value}function Xe(r,e){return!r||!e?!1:!!r.get(e)}function Ge(r){let{action:e,nodeId:i,document:o,context:n,onDiagnostic:t}=r;if(!Ut(e)){let d={code:"INVALID_ACTION_PAYLOAD",actionType:typeof e?.type=="string"?e.type:"unknown",nodeId:i,message:`Invalid action binding on node ${i||"unknown"}.`};return t?.(d),n?.onDiagnostic?.(d),!1}let l=n?.actionRegistry?.get(e.type);if(!l){let d={code:"UNKNOWN_ACTION",actionType:e.type,nodeId:i,message:`No action handler registered for action type "${e.type}".`};return t?.(d),n?.onDiagnostic?.(d),!1}let{value:f,invalidPaths:p}=Ke(n,e.payload);if(p.length>0){let d={code:"INVALID_ACTION_BINDING",actionType:e.type,nodeId:i,message:`Action "${e.type}" payload has unresolved binding path(s) [${p.join(", ")}] on node ${i||"unknown"}; handler was not invoked.`,invalidPaths:p};return t?.(d),n?.onDiagnostic?.(d),!1}let u={nodeId:i,document:o,variables:n?.variables};try{let d=l(f,u);return d&&typeof d.catch=="function"&&d.catch(s=>{let a={code:"ACTION_EXECUTION_ERROR",actionType:e.type,nodeId:i,message:`Action "${e.type}" handler threw an asynchronous error: ${s instanceof Error?s.message:String(s)}`,error:s};t?.(a),n?.onDiagnostic?.(a)}),!0}catch(d){let s={code:"ACTION_EXECUTION_ERROR",actionType:e.type,nodeId:i,message:`Action "${e.type}" handler threw a synchronous error: ${d instanceof Error?d.message:String(d)}`,error:d};return t?.(s),n?.onDiagnostic?.(s),!1}}import{AlertTriangle as ro}from"lucide-react";function Je(r,e="desktop"){if(!r)return{};let i=r.base||{},o=r[e]||{};return{...i,...o}}function Yt(r){return String(r).replace(/[{};]+/g,"")}function Xt(r){return r.replace(/["\\\]]/g,"\\$&")}function te(r,e){if(!r||typeof r!="object")return"";let i=[],o=e?.important?" !important":"";for(let[n,t]of Object.entries(r)){if(t==null||t==="")continue;let l=n.replace(/[A-Z]/g,f=>`-${f.toLowerCase()}`);i.push(`${l}: ${Yt(t)}${o};`)}return i.join(" ")}function Ze(r,e={important:!0}){if(!r?.document)return"";let i=[],o=n=>{let t=n.styles?.states;if(t&&typeof t=="object")for(let[l,f]of Object.entries(t)){let p=te(f,{important:e.important!==!1});if(!p)continue;let u=/^::?[a-zA-Z-]+$/.test(l)?l:null;u&&i.push(`[data-kubuild-node="${Xt(n.id)}"]${u} { ${p} }`)}n.children?.forEach(o)};return o(r.document),i.join(`
2
+ `)}var Qe=`
265
3
  *, *::before, *::after {
266
4
  box-sizing: border-box;
267
5
  }
@@ -287,1744 +25,200 @@ input, button, textarea, select {
287
25
  p, h1, h2, h3, h4, h5, h6 {
288
26
  overflow-wrap: break-word;
289
27
  }
290
- `.trim();
291
-
292
- // src/error-boundary.tsx
293
- import { Component } from "react";
294
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
295
- var ComponentErrorBoundary = class extends Component {
296
- constructor(props) {
297
- super(props);
298
- this.state = { hasError: false };
299
- }
300
- static getDerivedStateFromError(error) {
301
- return { hasError: true, error };
302
- }
303
- componentDidCatch(error, errorInfo) {
304
- if (this.props.onError) {
305
- this.props.onError(error, errorInfo);
306
- }
307
- }
308
- render() {
309
- if (this.state.hasError) {
310
- const { nodeId, componentType, mode = "runtime" } = this.props;
311
- const errorMessage = this.state.error?.message || "Unknown render error";
312
- if (mode === "editor") {
313
- return /* @__PURE__ */ jsxs(
314
- "div",
315
- {
316
- "data-kubuild-node": nodeId,
317
- "data-kubuild-error": componentType,
318
- style: {
319
- padding: "12px 16px",
320
- margin: "4px 0",
321
- backgroundColor: "#fef2f2",
322
- border: "1px solid #ef4444",
323
- borderRadius: "6px",
324
- color: "#b91c1c",
325
- fontFamily: "system-ui, -apple-system, sans-serif",
326
- fontSize: "13px",
327
- lineHeight: "1.4"
328
- },
329
- children: [
330
- /* @__PURE__ */ jsxs("div", { style: { fontWeight: 600, marginBottom: "4px" }, children: [
331
- "\u26A0\uFE0F Component Render Error: <",
332
- componentType,
333
- ">"
334
- ] }),
335
- /* @__PURE__ */ jsxs("div", { style: { fontSize: "11px", color: "#7f1d1d", wordBreak: "break-all" }, children: [
336
- "Node ID: ",
337
- /* @__PURE__ */ jsx2("code", { children: nodeId }),
338
- " \u2014 ",
339
- errorMessage
340
- ] })
341
- ]
342
- }
343
- );
344
- }
345
- return /* @__PURE__ */ jsx2(
346
- "div",
347
- {
348
- "data-kubuild-node": nodeId,
349
- "data-kubuild-error": componentType,
350
- style: { display: "none" },
351
- "aria-hidden": "true"
352
- }
353
- );
354
- }
355
- return this.props.children;
356
- }
357
- };
358
-
359
- // src/prop-resolution.ts
360
- import { isVariableBinding as isVariableBinding2 } from "@kubuild/schema";
361
- import { primitiveTypeForField } from "@kubuild/components";
362
- import { resolveBinding as resolveBinding2 } from "@kubuild/core";
363
- function emptyValueFor(primitiveType) {
364
- switch (primitiveType) {
365
- case "string":
366
- return "";
367
- case "number":
368
- return 0;
369
- case "boolean":
370
- return false;
371
- }
28
+ `.trim();var Gt=`
29
+ /* Entrance / AOS Keyframes */
30
+ @keyframes kb-anim-fade {
31
+ from { opacity: 0; }
32
+ to { opacity: 1; }
372
33
  }
373
- function resolveBindableField(node, field, definition, context, diagnostics) {
374
- const rawValue = node.props?.[field.name];
375
- const expectedType = primitiveTypeForField(field);
376
- if (expectedType === void 0 || rawValue === void 0) {
377
- return rawValue;
378
- }
379
- const fallbackValue = definition.defaultProps?.[field.name] ?? field.defaultValue ?? emptyValueFor(expectedType);
380
- if (isVariableBinding2(rawValue)) {
381
- const outcome = resolveBinding2(rawValue, context);
382
- if (typeof outcome.value === expectedType) {
383
- return outcome.value;
384
- }
385
- diagnostics.push({
386
- code: "INCOMPATIBLE_BINDING_TYPE",
387
- nodeId: node.id,
388
- propName: field.name,
389
- expectedType,
390
- actualType: typeof outcome.value,
391
- message: `Prop "${field.name}" on node "${node.id}" expected a ${expectedType} but resolved binding "${rawValue.key}" produced a ${typeof outcome.value}.`
392
- });
393
- return fallbackValue;
394
- }
395
- if (expectedType === "string" && typeof rawValue === "string" && rawValue.includes("{{")) {
396
- return resolveVariable(context, rawValue);
397
- }
398
- return rawValue;
34
+ @keyframes kb-anim-fade-up {
35
+ from { opacity: 0; transform: translateY(24px); }
36
+ to { opacity: 1; transform: translateY(0); }
399
37
  }
400
- function resolvePropsForNode(node, definition, context) {
401
- const rawProps = node.props || {};
402
- if (!definition || !definition.propFields || definition.propFields.length === 0) {
403
- return { props: rawProps, diagnostics: [] };
404
- }
405
- const diagnostics = [];
406
- const resolved = { ...rawProps };
407
- for (const field of definition.propFields) {
408
- if (primitiveTypeForField(field) === void 0) {
409
- continue;
410
- }
411
- resolved[field.name] = resolveBindableField(node, field, definition, context, diagnostics);
412
- }
413
- return { props: resolved, diagnostics };
38
+ @keyframes kb-anim-fade-down {
39
+ from { opacity: 0; transform: translateY(-24px); }
40
+ to { opacity: 1; transform: translateY(0); }
414
41
  }
415
-
416
- // src/renderer.tsx
417
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
418
- function toPascalCase(str) {
419
- if (!str) return "";
420
- return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
42
+ @keyframes kb-anim-fade-left {
43
+ from { opacity: 0; transform: translateX(24px); }
44
+ to { opacity: 1; transform: translateX(0); }
421
45
  }
422
- function getYouTubeId(url) {
423
- if (!url || typeof url !== "string") return null;
424
- const match = url.match(
425
- /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i
426
- );
427
- return match ? match[1] : null;
46
+ @keyframes kb-anim-fade-right {
47
+ from { opacity: 0; transform: translateX(-24px); }
48
+ to { opacity: 1; transform: translateX(0); }
428
49
  }
429
- function getVimeoId(url) {
430
- if (!url || typeof url !== "string") return null;
431
- const match = url.match(
432
- /(?:vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|))(\d+)/i
433
- );
434
- return match ? match[3] : null;
50
+ @keyframes kb-anim-zoom-in {
51
+ from { opacity: 0; transform: scale(0.92); }
52
+ to { opacity: 1; transform: scale(1); }
435
53
  }
436
- function aspectRatioToCss(ratio) {
437
- if (ratio === "16:9") return "16 / 9";
438
- if (ratio === "4:3") return "4 / 3";
439
- if (ratio === "1:1") return "1 / 1";
440
- if (ratio === "9:16") return "9 / 16";
441
- if (typeof ratio === "string" && ratio !== "auto") return ratio.replace(":", " / ");
442
- return void 0;
54
+ @keyframes kb-anim-zoom-out {
55
+ from { opacity: 0; transform: scale(1.08); }
56
+ to { opacity: 1; transform: scale(1); }
443
57
  }
444
- var EditableText = ({
445
- as = "p",
446
- id,
447
- className,
448
- style,
449
- value,
450
- isEditable,
451
- nodeId,
452
- onClick,
453
- onChange,
454
- ...rest
455
- }) => {
456
- const isEditingRef = useRef(false);
457
- const Tag = as;
458
- if (!isEditable) {
459
- return /* @__PURE__ */ jsx3(
460
- Tag,
461
- {
462
- id,
463
- className,
464
- style,
465
- onClick,
466
- "data-kubuild-node": nodeId,
467
- ...rest,
468
- children: value
469
- }
470
- );
471
- }
472
- return /* @__PURE__ */ jsx3(
473
- Tag,
474
- {
475
- id,
476
- className,
477
- style: {
478
- ...style,
479
- outline: "none",
480
- cursor: "text"
481
- },
482
- contentEditable: true,
483
- suppressContentEditableWarning: true,
484
- "data-kubuild-node": nodeId,
485
- onClick: (e) => {
486
- onClick?.(e);
487
- },
488
- onFocus: () => {
489
- isEditingRef.current = true;
490
- },
491
- onInput: (e) => {
492
- const text = e.currentTarget.textContent ?? "";
493
- onChange?.(text, false);
494
- },
495
- onBlur: (e) => {
496
- isEditingRef.current = false;
497
- const text = e.currentTarget.textContent ?? "";
498
- onChange?.(text, true);
499
- },
500
- onKeyDown: (e) => {
501
- if (e.key === "Escape") {
502
- e.currentTarget.blur();
503
- }
504
- },
505
- ...rest,
506
- children: value
507
- }
508
- );
509
- };
510
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
511
- function transformEmbedHtml(rawHtml) {
512
- if (!rawHtml) return "";
513
- return rawHtml.replace(/<style\b([^>]*)>([\s\S]*?)<\/style>/gi, (_match, attrs, cssContent) => {
514
- let transformedCss = cssContent;
515
- transformedCss = transformedCss.replace(/(^|[\s,{}])body(?=[\s,{])/g, "$1:host, body");
516
- transformedCss = transformedCss.replace(/(^|[\s,{}])html(?=[\s,{])/g, "$1:host, html");
517
- return `<style${attrs}>
518
- :host { display: block; }
519
- ${transformedCss}</style>`;
520
- });
58
+ @keyframes kb-anim-slide-up {
59
+ from { transform: translateY(100%); }
60
+ to { transform: translateY(0); }
521
61
  }
522
- var HtmlEmbedView = ({
523
- id,
524
- style,
525
- onClick,
526
- dataKubuildNode,
527
- html,
528
- role
529
- }) => {
530
- const hostRef = useRef(null);
531
- const shadowRootRef = useRef(null);
532
- const scopedHtml = useMemo2(() => transformEmbedHtml(html), [html]);
533
- useIsomorphicLayoutEffect(() => {
534
- const host = hostRef.current;
535
- if (!host) return;
536
- if (typeof host.attachShadow === "function") {
537
- if (!shadowRootRef.current) {
538
- if (host.shadowRoot) {
539
- shadowRootRef.current = host.shadowRoot;
540
- } else {
541
- try {
542
- shadowRootRef.current = host.attachShadow({ mode: "open" });
543
- } catch {
544
- shadowRootRef.current = host.shadowRoot;
545
- }
546
- }
547
- }
548
- if (shadowRootRef.current) {
549
- shadowRootRef.current.innerHTML = scopedHtml;
550
- return;
551
- }
552
- }
553
- host.innerHTML = scopedHtml;
554
- }, [scopedHtml]);
555
- return /* @__PURE__ */ jsx3(
556
- "div",
557
- {
558
- ref: hostRef,
559
- id,
560
- style,
561
- onClick,
562
- "data-kubuild-node": dataKubuildNode,
563
- role,
564
- children: /* @__PURE__ */ jsx3(
565
- "template",
566
- {
567
- shadowrootmode: "open",
568
- dangerouslySetInnerHTML: { __html: scopedHtml }
569
- }
570
- )
571
- }
572
- );
573
- };
574
- function NodeRenderer({
575
- node,
576
- document,
577
- registry,
578
- context: propContext,
579
- viewport = "desktop",
580
- mode = "runtime",
581
- onNodeClick,
582
- onDiagnostic,
583
- onActionDispatch,
584
- onNodePropChange,
585
- instanceSuffix = ""
586
- }) {
587
- const context = propContext || DEFAULT_RENDER_CONTEXT;
588
- const styles = resolveNodeStyles(node.styles, viewport);
589
- const props = node.props || {};
590
- const definition = registry.get(node.type);
591
- const domId = instanceSuffix ? `${node.id}${instanceSuffix}` : node.id;
592
- const { props: resolvedProps, diagnostics } = resolvePropsForNode(node, definition, context);
593
- diagnostics.forEach((diagnostic) => {
594
- onDiagnostic?.(diagnostic);
595
- context?.onDiagnostic?.(diagnostic);
596
- });
597
- const handleClick = (e) => {
598
- e.stopPropagation();
599
- if (onNodeClick) {
600
- onNodeClick(node.id, e);
601
- }
602
- if (props.action && !props.disabled) {
603
- dispatchAction({
604
- action: props.action,
605
- nodeId: node.id,
606
- document,
607
- context,
608
- onDiagnostic
609
- });
610
- if (onActionDispatch && isActionBinding2(props.action)) {
611
- onActionDispatch(props.action.type, resolveActionPayload(context, props.action.payload), node.id);
612
- }
613
- }
614
- };
615
- const childrenElements = node.children?.map((child) => /* @__PURE__ */ jsx3(
616
- NodeRenderer,
617
- {
618
- node: child,
619
- document,
620
- registry,
621
- context,
622
- viewport,
623
- mode,
624
- onNodeClick,
625
- onDiagnostic,
626
- onActionDispatch,
627
- onNodePropChange,
628
- instanceSuffix
629
- },
630
- `${child.id}${instanceSuffix}`
631
- ));
632
- const renderNodeContent = () => {
633
- if (definition?.renderer && typeof definition.renderer === "function") {
634
- const CustomRenderer = definition.renderer;
635
- try {
636
- if (typeof CustomRenderer === "function" && !CustomRenderer.prototype?.isReactComponent) {
637
- return CustomRenderer({
638
- node,
639
- document,
640
- props: resolvedProps,
641
- styles,
642
- context,
643
- children: childrenElements,
644
- onClick: handleClick
645
- });
646
- }
647
- } catch (err) {
648
- throw err;
649
- }
650
- return /* @__PURE__ */ jsx3(
651
- CustomRenderer,
652
- {
653
- node,
654
- document,
655
- props: resolvedProps,
656
- styles,
657
- context,
658
- onClick: handleClick,
659
- children: childrenElements
660
- }
661
- );
662
- }
663
- switch (node.type) {
664
- case "page":
665
- return /* @__PURE__ */ jsx3("div", { id: domId, style: styles, onClick: handleClick, "data-kubuild-node": node.id, children: childrenElements });
666
- case "section":
667
- return /* @__PURE__ */ jsx3(
668
- "section",
669
- {
670
- id: domId,
671
- style: styles,
672
- onClick: handleClick,
673
- "data-kubuild-node": node.id,
674
- "aria-label": typeof resolvedProps.ariaLabel === "string" ? resolvedProps.ariaLabel : void 0,
675
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
676
- children: childrenElements
677
- }
678
- );
679
- case "container":
680
- return /* @__PURE__ */ jsx3(
681
- "div",
682
- {
683
- id: domId,
684
- style: styles,
685
- onClick: handleClick,
686
- "data-kubuild-node": node.id,
687
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
688
- children: childrenElements
689
- }
690
- );
691
- case "columns":
692
- return /* @__PURE__ */ jsx3(
693
- "div",
694
- {
695
- id: domId,
696
- style: styles,
697
- onClick: handleClick,
698
- "data-kubuild-node": node.id,
699
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
700
- children: childrenElements
701
- }
702
- );
703
- case "heading": {
704
- const rawLevel = typeof resolvedProps.level === "number" ? resolvedProps.level : typeof props.level === "number" ? props.level : 2;
705
- const clampedLevel = Math.min(Math.max(rawLevel, 1), 6);
706
- const text = String(resolvedProps.text ?? "");
707
- const Tag = `h${clampedLevel}`;
708
- const isEditable = mode === "editor" && !isVariableBinding3(props.text);
709
- return /* @__PURE__ */ jsx3(
710
- EditableText,
711
- {
712
- as: Tag,
713
- id: domId,
714
- style: styles,
715
- value: text,
716
- isEditable,
717
- nodeId: node.id,
718
- onClick: handleClick,
719
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur),
720
- "aria-label": typeof resolvedProps.ariaLabel === "string" ? resolvedProps.ariaLabel : void 0
721
- }
722
- );
723
- }
724
- case "text": {
725
- const content2 = String(resolvedProps.content ?? "");
726
- const isEditable = mode === "editor" && !isVariableBinding3(props.content);
727
- return /* @__PURE__ */ jsx3(
728
- EditableText,
729
- {
730
- as: "p",
731
- id: domId,
732
- style: styles,
733
- value: content2,
734
- isEditable,
735
- nodeId: node.id,
736
- onClick: handleClick,
737
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "content", val, isBlur),
738
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
739
- }
740
- );
741
- }
742
- case "paragraph": {
743
- const text = String(resolvedProps.text ?? resolvedProps.content ?? props.text ?? props.content ?? "");
744
- const isEditable = mode === "editor" && !isVariableBinding3(props.text) && !isVariableBinding3(props.content);
745
- const propName = props.content !== void 0 ? "content" : "text";
746
- return /* @__PURE__ */ jsx3(
747
- EditableText,
748
- {
749
- as: "p",
750
- id: domId,
751
- style: styles,
752
- value: text,
753
- isEditable,
754
- nodeId: node.id,
755
- onClick: handleClick,
756
- onChange: (val, isBlur) => onNodePropChange?.(node.id, propName, val, isBlur),
757
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
758
- }
759
- );
760
- }
761
- case "link": {
762
- const text = String(resolvedProps.text ?? props.text ?? "");
763
- const rawHref = typeof resolvedProps.href === "string" ? resolvedProps.href : typeof props.href === "string" ? props.href : void 0;
764
- const href = rawHref ? sanitizeUrl(rawHref, "#") : "#";
765
- const rawTarget = typeof resolvedProps.target === "string" ? resolvedProps.target : void 0;
766
- const rawRel = typeof resolvedProps.rel === "string" ? resolvedProps.rel : void 0;
767
- const rel = rawTarget === "_blank" && !rawRel ? "noopener noreferrer" : rawRel;
768
- const isEditable = mode === "editor" && !isVariableBinding3(props.text);
769
- if (isEditable) {
770
- return /* @__PURE__ */ jsx3(
771
- EditableText,
772
- {
773
- as: "a",
774
- id: domId,
775
- href: void 0,
776
- target: rawTarget,
777
- rel,
778
- style: styles,
779
- value: text,
780
- isEditable,
781
- nodeId: node.id,
782
- onClick: handleClick,
783
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur),
784
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
785
- }
786
- );
787
- }
788
- return /* @__PURE__ */ jsx3(
789
- "a",
790
- {
791
- id: domId,
792
- href,
793
- target: rawTarget,
794
- rel,
795
- style: styles,
796
- onClick: handleClick,
797
- "data-kubuild-node": node.id,
798
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
799
- children: text
800
- }
801
- );
802
- }
803
- case "blockquote": {
804
- const text = resolvedProps.text !== void 0 ? String(resolvedProps.text) : props.text !== void 0 ? String(props.text) : "";
805
- const rawCite = typeof resolvedProps.cite === "string" ? resolvedProps.cite : typeof props.cite === "string" ? props.cite : void 0;
806
- const safeCite = rawCite ? sanitizeUrl(rawCite) : void 0;
807
- const hasChildren = Boolean(childrenElements && childrenElements.length > 0);
808
- const isEditable = mode === "editor" && !isVariableBinding3(props.text);
809
- if (hasChildren) {
810
- return /* @__PURE__ */ jsxs2(
811
- "blockquote",
812
- {
813
- id: domId,
814
- cite: safeCite,
815
- style: styles,
816
- onClick: handleClick,
817
- "data-kubuild-node": node.id,
818
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
819
- children: [
820
- text ? isEditable ? /* @__PURE__ */ jsx3(
821
- EditableText,
822
- {
823
- as: "p",
824
- value: text,
825
- isEditable,
826
- nodeId: node.id,
827
- onClick: handleClick,
828
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur)
829
- }
830
- ) : /* @__PURE__ */ jsx3("p", { children: text }) : null,
831
- childrenElements
832
- ]
833
- }
834
- );
835
- }
836
- return /* @__PURE__ */ jsx3(
837
- EditableText,
838
- {
839
- as: "blockquote",
840
- id: domId,
841
- cite: safeCite,
842
- style: styles,
843
- value: text,
844
- isEditable,
845
- nodeId: node.id,
846
- onClick: handleClick,
847
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur),
848
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
849
- }
850
- );
851
- }
852
- case "badge": {
853
- const text = String(resolvedProps.text ?? props.text ?? "Badge");
854
- const variant = typeof resolvedProps.variant === "string" ? resolvedProps.variant : "default";
855
- const isEditable = mode === "editor" && !isVariableBinding3(props.text);
856
- return /* @__PURE__ */ jsx3(
857
- EditableText,
858
- {
859
- as: "span",
860
- id: domId,
861
- style: styles,
862
- value: text,
863
- isEditable,
864
- nodeId: node.id,
865
- "data-variant": variant,
866
- onClick: handleClick,
867
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur),
868
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
869
- }
870
- );
871
- }
872
- case "code-block": {
873
- const code = String(resolvedProps.code ?? props.code ?? "");
874
- const language = typeof resolvedProps.language === "string" ? resolvedProps.language : typeof props.language === "string" ? props.language : void 0;
875
- const isEditable = mode === "editor" && !isVariableBinding3(props.code);
876
- return /* @__PURE__ */ jsx3(
877
- "pre",
878
- {
879
- id: domId,
880
- style: styles,
881
- onClick: handleClick,
882
- "data-kubuild-node": node.id,
883
- "data-language": language,
884
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
885
- children: /* @__PURE__ */ jsx3(
886
- EditableText,
887
- {
888
- as: "code",
889
- className: language ? `language-${language}` : void 0,
890
- style: { fontFamily: "inherit", color: "inherit", display: "block", whiteSpace: "pre" },
891
- value: code,
892
- isEditable,
893
- nodeId: node.id,
894
- onClick: handleClick,
895
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "code", val, isBlur)
896
- }
897
- )
898
- }
899
- );
900
- }
901
- case "list": {
902
- const rawTag = resolvedProps.tag;
903
- const Tag = rawTag === "ol" ? "ol" : "ul";
904
- const rawListStyle = resolvedProps.listStyleType;
905
- const listStyleType = rawListStyle === "custom-icon" ? "none" : rawListStyle;
906
- const listStyles = {
907
- ...styles,
908
- ...listStyleType ? { listStyleType } : {}
909
- };
910
- return /* @__PURE__ */ jsx3(
911
- Tag,
912
- {
913
- id: domId,
914
- style: listStyles,
915
- onClick: handleClick,
916
- "data-kubuild-node": node.id,
917
- "data-list-style": rawListStyle,
918
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
919
- children: childrenElements
920
- }
921
- );
922
- }
923
- case "list-item": {
924
- const text = resolvedProps.text !== void 0 ? String(resolvedProps.text) : "";
925
- const hasChildren = Boolean(childrenElements && childrenElements.length > 0);
926
- const isEditable = mode === "editor" && !isVariableBinding3(props.text);
927
- if (hasChildren) {
928
- return /* @__PURE__ */ jsxs2(
929
- "li",
930
- {
931
- id: domId,
932
- style: styles,
933
- onClick: handleClick,
934
- "data-kubuild-node": node.id,
935
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
936
- children: [
937
- text ? isEditable ? /* @__PURE__ */ jsx3(
938
- EditableText,
939
- {
940
- as: "span",
941
- value: text,
942
- isEditable,
943
- nodeId: node.id,
944
- onClick: handleClick,
945
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur)
946
- }
947
- ) : /* @__PURE__ */ jsx3("span", { children: text }) : null,
948
- childrenElements
949
- ]
950
- }
951
- );
952
- }
953
- return /* @__PURE__ */ jsx3(
954
- EditableText,
955
- {
956
- as: "li",
957
- id: domId,
958
- style: styles,
959
- value: text,
960
- isEditable,
961
- nodeId: node.id,
962
- onClick: handleClick,
963
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur),
964
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
965
- }
966
- );
967
- }
968
- case "table": {
969
- const isStriped = resolvedProps.striped === true;
970
- const isBordered = resolvedProps.bordered !== false;
971
- const isCompact = resolvedProps.compact === true;
972
- const tableStyles = {
973
- width: "100%",
974
- borderCollapse: "collapse",
975
- ...styles,
976
- ...isBordered ? { border: styles.border || "1px solid #e2e8f0" } : {}
977
- };
978
- return /* @__PURE__ */ jsx3(
979
- "table",
980
- {
981
- id: domId,
982
- style: tableStyles,
983
- onClick: handleClick,
984
- "data-kubuild-node": node.id,
985
- "data-striped": isStriped ? "true" : void 0,
986
- "data-bordered": isBordered ? "true" : void 0,
987
- "data-compact": isCompact ? "true" : void 0,
988
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
989
- children: /* @__PURE__ */ jsx3("tbody", { children: childrenElements })
990
- }
991
- );
992
- }
993
- case "table-row": {
994
- return /* @__PURE__ */ jsx3(
995
- "tr",
996
- {
997
- id: domId,
998
- style: styles,
999
- onClick: handleClick,
1000
- "data-kubuild-node": node.id,
1001
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
1002
- children: childrenElements
1003
- }
1004
- );
1005
- }
1006
- case "table-cell": {
1007
- const rawTag = resolvedProps.tag;
1008
- const Tag = rawTag === "th" ? "th" : "td";
1009
- const colSpan = typeof resolvedProps.colSpan === "number" && resolvedProps.colSpan > 1 ? resolvedProps.colSpan : void 0;
1010
- const rowSpan = typeof resolvedProps.rowSpan === "number" && resolvedProps.rowSpan > 1 ? resolvedProps.rowSpan : void 0;
1011
- const text = resolvedProps.text !== void 0 ? String(resolvedProps.text) : "";
1012
- const hasChildren = Boolean(childrenElements && childrenElements.length > 0);
1013
- const isEditable = mode === "editor" && !isVariableBinding3(props.text);
1014
- const cellStyles = {
1015
- padding: "8px 12px",
1016
- border: "1px solid #e2e8f0",
1017
- textAlign: "left",
1018
- ...styles,
1019
- ...Tag === "th" ? {
1020
- fontWeight: styles.fontWeight || "600",
1021
- backgroundColor: styles.backgroundColor || "#f8fafc"
1022
- } : {}
1023
- };
1024
- if (hasChildren) {
1025
- return /* @__PURE__ */ jsxs2(
1026
- Tag,
1027
- {
1028
- id: domId,
1029
- colSpan,
1030
- rowSpan,
1031
- style: cellStyles,
1032
- onClick: handleClick,
1033
- "data-kubuild-node": node.id,
1034
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
1035
- children: [
1036
- text ? isEditable ? /* @__PURE__ */ jsx3(
1037
- EditableText,
1038
- {
1039
- as: "span",
1040
- value: text,
1041
- isEditable,
1042
- nodeId: node.id,
1043
- onClick: handleClick,
1044
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur)
1045
- }
1046
- ) : /* @__PURE__ */ jsx3("span", { children: text }) : null,
1047
- childrenElements
1048
- ]
1049
- }
1050
- );
1051
- }
1052
- return /* @__PURE__ */ jsx3(
1053
- EditableText,
1054
- {
1055
- as: Tag,
1056
- id: domId,
1057
- colSpan,
1058
- rowSpan,
1059
- style: cellStyles,
1060
- value: text,
1061
- isEditable,
1062
- nodeId: node.id,
1063
- onClick: handleClick,
1064
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "text", val, isBlur),
1065
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
1066
- }
1067
- );
1068
- }
1069
- case "image": {
1070
- const rawSrc = typeof resolvedProps.src === "string" && resolvedProps.src.length > 0 ? resolvedProps.src : void 0;
1071
- const directSrc = rawSrc ?? void 0;
1072
- const asset = isAssetReference(props.asset) ? props.asset : void 0;
1073
- const resolvedSrc = !directSrc && asset && context?.assetProvider ? resolveAssetSync(context.assetProvider, asset.assetId) : void 0;
1074
- const fallbackSrc = asset?.fallbackUrl;
1075
- const rawUrl = directSrc || resolvedSrc || fallbackSrc;
1076
- const safeSrc = rawUrl ? sanitizeUrl(rawUrl, "", { allowBlobMedia: true }) : void 0;
1077
- const alt = typeof resolvedProps.alt === "string" ? resolvedProps.alt : "";
1078
- const loading = resolvedProps.loading === "eager" ? "eager" : "lazy";
1079
- return /* @__PURE__ */ jsx3(
1080
- "img",
1081
- {
1082
- id: domId,
1083
- src: safeSrc || void 0,
1084
- alt,
1085
- role: alt.length === 0 ? "presentation" : void 0,
1086
- loading,
1087
- width: resolvedProps.width,
1088
- height: resolvedProps.height,
1089
- style: styles,
1090
- onClick: handleClick,
1091
- "data-kubuild-node": node.id
1092
- }
1093
- );
1094
- }
1095
- case "video": {
1096
- const rawSrc = typeof resolvedProps.src === "string" ? resolvedProps.src : typeof props.src === "string" ? props.src : "";
1097
- const provider = typeof resolvedProps.provider === "string" ? resolvedProps.provider : typeof props.provider === "string" ? props.provider : "auto";
1098
- const rawPoster = typeof resolvedProps.poster === "string" ? resolvedProps.poster : typeof props.poster === "string" ? props.poster : void 0;
1099
- const poster = rawPoster ? sanitizeUrl(rawPoster) : void 0;
1100
- const controls = resolvedProps.controls !== false && props.controls !== false;
1101
- const autoplay = resolvedProps.autoplay === true || props.autoplay === true;
1102
- const loop = resolvedProps.loop === true || props.loop === true;
1103
- const muted = resolvedProps.muted === true || props.muted === true;
1104
- const aspectRatio = aspectRatioToCss(resolvedProps.aspectRatio ?? props.aspectRatio ?? "16:9");
1105
- const ytId = provider === "youtube" ? getYouTubeId(rawSrc) || rawSrc : provider === "auto" ? getYouTubeId(rawSrc) : null;
1106
- const vimeoId = provider === "vimeo" ? getVimeoId(rawSrc) || rawSrc : provider === "auto" ? getVimeoId(rawSrc) : null;
1107
- const videoStyles = {
1108
- width: "100%",
1109
- maxWidth: "100%",
1110
- display: "block",
1111
- ...aspectRatio ? { aspectRatio } : {},
1112
- ...styles
1113
- };
1114
- if (ytId) {
1115
- const autoplayParam = autoplay ? "1" : "0";
1116
- const loopParam = loop ? `1&playlist=${ytId}` : "0";
1117
- const muteParam = muted ? "1" : "0";
1118
- const controlsParam = controls ? "1" : "0";
1119
- const embedUrl = `https://www.youtube.com/embed/${ytId}?autoplay=${autoplayParam}&loop=${loopParam}&mute=${muteParam}&controls=${controlsParam}`;
1120
- return /* @__PURE__ */ jsx3(
1121
- "div",
1122
- {
1123
- id: domId,
1124
- style: { ...videoStyles, position: "relative", overflow: "hidden" },
1125
- onClick: handleClick,
1126
- "data-kubuild-node": node.id,
1127
- "data-video-provider": "youtube",
1128
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
1129
- children: /* @__PURE__ */ jsx3(
1130
- "iframe",
1131
- {
1132
- src: embedUrl,
1133
- title: "YouTube video",
1134
- style: { width: "100%", height: "100%", border: "none", minHeight: "240px" },
1135
- allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
1136
- allowFullScreen: true
1137
- }
1138
- )
1139
- }
1140
- );
1141
- }
1142
- if (vimeoId) {
1143
- const autoplayParam = autoplay ? "1" : "0";
1144
- const loopParam = loop ? "1" : "0";
1145
- const muteParam = muted ? "1" : "0";
1146
- const embedUrl = `https://player.vimeo.com/video/${vimeoId}?autoplay=${autoplayParam}&loop=${loopParam}&muted=${muteParam}`;
1147
- return /* @__PURE__ */ jsx3(
1148
- "div",
1149
- {
1150
- id: domId,
1151
- style: { ...videoStyles, position: "relative", overflow: "hidden" },
1152
- onClick: handleClick,
1153
- "data-kubuild-node": node.id,
1154
- "data-video-provider": "vimeo",
1155
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0,
1156
- children: /* @__PURE__ */ jsx3(
1157
- "iframe",
1158
- {
1159
- src: embedUrl,
1160
- title: "Vimeo video",
1161
- style: { width: "100%", height: "100%", border: "none", minHeight: "240px" },
1162
- allow: "autoplay; fullscreen; picture-in-picture",
1163
- allowFullScreen: true
1164
- }
1165
- )
1166
- }
1167
- );
1168
- }
1169
- const safeSrc = sanitizeUrl(rawSrc, "", { allowBlobMedia: true });
1170
- return /* @__PURE__ */ jsx3(
1171
- "video",
1172
- {
1173
- id: domId,
1174
- src: safeSrc || void 0,
1175
- poster: poster || void 0,
1176
- controls,
1177
- autoPlay: autoplay,
1178
- loop,
1179
- muted,
1180
- style: videoStyles,
1181
- onClick: handleClick,
1182
- "data-kubuild-node": node.id,
1183
- "data-video-provider": "html5",
1184
- playsInline: true,
1185
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
1186
- }
1187
- );
1188
- }
1189
- case "icon": {
1190
- const name = typeof resolvedProps.name === "string" && resolvedProps.name.trim().length > 0 ? resolvedProps.name.trim() : typeof props.name === "string" && props.name.trim().length > 0 ? props.name.trim() : "star";
1191
- const size = typeof resolvedProps.size === "number" ? resolvedProps.size : typeof props.size === "number" ? props.size : 24;
1192
- const color = typeof resolvedProps.color === "string" ? resolvedProps.color : typeof props.color === "string" ? props.color : "currentColor";
1193
- const strokeWidth = typeof resolvedProps.strokeWidth === "number" ? resolvedProps.strokeWidth : typeof props.strokeWidth === "number" ? props.strokeWidth : 2;
1194
- const pascalName = toPascalCase(name);
1195
- const IconComponent = lucideIcons[pascalName];
1196
- return /* @__PURE__ */ jsx3(
1197
- "span",
1198
- {
1199
- id: domId,
1200
- style: { display: "inline-flex", alignItems: "center", justifyContent: "center", color, ...styles },
1201
- onClick: handleClick,
1202
- "data-kubuild-node": node.id,
1203
- "data-icon-name": name,
1204
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : "img",
1205
- "aria-label": typeof resolvedProps.ariaLabel === "string" ? resolvedProps.ariaLabel : name,
1206
- children: IconComponent ? /* @__PURE__ */ jsx3(IconComponent, { size, color, strokeWidth }) : /* @__PURE__ */ jsx3("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth, strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx3("polygon", { points: "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" }) })
1207
- }
1208
- );
1209
- }
1210
- case "html-embed": {
1211
- const rawHtml = typeof resolvedProps.html === "string" ? resolvedProps.html : typeof props.html === "string" ? props.html : "";
1212
- const sanitized = sanitizeHtml(rawHtml);
1213
- if (mode === "editor" && !rawHtml.trim()) {
1214
- return /* @__PURE__ */ jsxs2(
1215
- "div",
1216
- {
1217
- id: domId,
1218
- style: {
1219
- padding: "16px",
1220
- border: "2px dashed #94a3b8",
1221
- borderRadius: "8px",
1222
- backgroundColor: "#f8fafc",
1223
- color: "#64748b",
1224
- textAlign: "center",
1225
- fontSize: "13px",
1226
- fontFamily: "sans-serif",
1227
- ...styles
1228
- },
1229
- onClick: handleClick,
1230
- "data-kubuild-node": node.id,
1231
- children: [
1232
- /* @__PURE__ */ jsx3("span", { style: { fontWeight: 600 }, children: "</> HTML Embed" }),
1233
- /* @__PURE__ */ jsx3("div", { style: { fontSize: "11px", marginTop: "4px" }, children: "Click to configure HTML code in Inspector Panel" })
1234
- ]
1235
- }
1236
- );
1237
- }
1238
- return /* @__PURE__ */ jsx3(
1239
- HtmlEmbedView,
1240
- {
1241
- id: domId,
1242
- style: styles,
1243
- onClick: handleClick,
1244
- dataKubuildNode: node.id,
1245
- html: sanitized,
1246
- role: typeof resolvedProps.role === "string" ? resolvedProps.role : void 0
1247
- }
1248
- );
1249
- }
1250
- case "button": {
1251
- const label = String(resolvedProps.label ?? "Button");
1252
- const disabled = resolvedProps.disabled === true;
1253
- const rawHref = typeof resolvedProps.href === "string" ? resolvedProps.href : void 0;
1254
- const href = rawHref ? sanitizeUrl(rawHref, "#") : void 0;
1255
- const rawTarget = typeof resolvedProps.target === "string" ? resolvedProps.target : void 0;
1256
- const rawRel = typeof resolvedProps.rel === "string" ? resolvedProps.rel : void 0;
1257
- const rel = rawTarget === "_blank" && !rawRel ? "noopener noreferrer" : rawRel;
1258
- const action = isActionBinding2(props.action) ? props.action : void 0;
1259
- const actionResolved = action ? isActionRegistered(context?.actionRegistry, action.type) : void 0;
1260
- const actionAttrs = action ? { "data-kubuild-action": action.type, "data-kubuild-action-resolved": actionResolved } : {};
1261
- const ariaLabel = typeof resolvedProps.ariaLabel === "string" ? resolvedProps.ariaLabel : void 0;
1262
- const isEditable = mode === "editor" && !isVariableBinding3(props.label);
1263
- const rawButtonType = typeof resolvedProps.buttonType === "string" ? resolvedProps.buttonType : "button";
1264
- const buttonType = rawButtonType === "submit" || rawButtonType === "reset" ? rawButtonType : "button";
1265
- if (href && !disabled) {
1266
- if (isEditable) {
1267
- return /* @__PURE__ */ jsx3(
1268
- EditableText,
1269
- {
1270
- as: "a",
1271
- id: domId,
1272
- href: mode === "editor" ? void 0 : href,
1273
- target: rawTarget,
1274
- rel,
1275
- style: styles,
1276
- value: label,
1277
- isEditable,
1278
- nodeId: node.id,
1279
- onClick: handleClick,
1280
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "label", val, isBlur),
1281
- "aria-label": ariaLabel,
1282
- tabIndex: 0,
1283
- ...actionAttrs
1284
- }
1285
- );
1286
- }
1287
- return /* @__PURE__ */ jsx3(
1288
- "a",
1289
- {
1290
- id: domId,
1291
- href,
1292
- target: rawTarget,
1293
- rel,
1294
- style: styles,
1295
- onClick: handleClick,
1296
- "data-kubuild-node": node.id,
1297
- "aria-label": ariaLabel,
1298
- tabIndex: 0,
1299
- ...actionAttrs,
1300
- children: label
1301
- }
1302
- );
1303
- }
1304
- if (isEditable) {
1305
- return /* @__PURE__ */ jsx3(
1306
- EditableText,
1307
- {
1308
- as: "button",
1309
- id: domId,
1310
- type: mode === "editor" ? "button" : buttonType,
1311
- disabled,
1312
- "aria-disabled": disabled ? true : void 0,
1313
- "aria-label": ariaLabel,
1314
- tabIndex: disabled ? -1 : 0,
1315
- style: styles,
1316
- value: label,
1317
- isEditable,
1318
- nodeId: node.id,
1319
- onClick: disabled ? void 0 : handleClick,
1320
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "label", val, isBlur),
1321
- ...actionAttrs
1322
- }
1323
- );
1324
- }
1325
- return /* @__PURE__ */ jsx3(
1326
- "button",
1327
- {
1328
- id: domId,
1329
- type: mode === "editor" ? "button" : buttonType,
1330
- disabled,
1331
- "aria-disabled": disabled ? true : void 0,
1332
- "aria-label": ariaLabel,
1333
- tabIndex: disabled ? -1 : 0,
1334
- style: styles,
1335
- onClick: disabled ? void 0 : handleClick,
1336
- "data-kubuild-node": node.id,
1337
- ...actionAttrs,
1338
- children: label
1339
- }
1340
- );
1341
- }
1342
- case "form": {
1343
- const action = typeof resolvedProps.action === "string" ? resolvedProps.action : void 0;
1344
- const method = typeof resolvedProps.method === "string" ? resolvedProps.method : "POST";
1345
- const target = typeof resolvedProps.target === "string" ? resolvedProps.target : void 0;
1346
- const autoComplete = typeof resolvedProps.autoComplete === "string" ? resolvedProps.autoComplete : void 0;
1347
- const name = typeof resolvedProps.name === "string" ? resolvedProps.name : void 0;
1348
- const handleSubmit = (e) => {
1349
- if (mode === "editor") {
1350
- e.preventDefault();
1351
- }
1352
- };
1353
- return /* @__PURE__ */ jsx3(
1354
- "form",
1355
- {
1356
- id: domId,
1357
- name,
1358
- action: action && mode !== "editor" ? sanitizeUrl(action, "") : void 0,
1359
- method,
1360
- target,
1361
- autoComplete,
1362
- style: styles,
1363
- onClick: handleClick,
1364
- onSubmit: handleSubmit,
1365
- "data-kubuild-node": node.id,
1366
- role: "form",
1367
- "aria-label": name,
1368
- children: childrenElements
1369
- }
1370
- );
1371
- }
1372
- case "input": {
1373
- const name = typeof resolvedProps.name === "string" ? resolvedProps.name : void 0;
1374
- const inputType = typeof resolvedProps.type === "string" ? resolvedProps.type : "text";
1375
- const placeholder = typeof resolvedProps.placeholder === "string" ? resolvedProps.placeholder : void 0;
1376
- const defaultValue = resolvedProps.defaultValue !== void 0 ? String(resolvedProps.defaultValue) : void 0;
1377
- const required = resolvedProps.required === true;
1378
- const disabled = resolvedProps.disabled === true;
1379
- const readOnly = resolvedProps.readOnly === true;
1380
- return /* @__PURE__ */ jsx3(
1381
- "input",
1382
- {
1383
- id: domId,
1384
- type: inputType,
1385
- name,
1386
- placeholder,
1387
- defaultValue,
1388
- required,
1389
- disabled,
1390
- readOnly,
1391
- style: styles,
1392
- onClick: handleClick,
1393
- "data-kubuild-node": node.id
1394
- }
1395
- );
1396
- }
1397
- case "textarea": {
1398
- const name = typeof resolvedProps.name === "string" ? resolvedProps.name : void 0;
1399
- const placeholder = typeof resolvedProps.placeholder === "string" ? resolvedProps.placeholder : void 0;
1400
- const defaultValue = resolvedProps.defaultValue !== void 0 ? String(resolvedProps.defaultValue) : void 0;
1401
- const rows = typeof resolvedProps.rows === "number" ? resolvedProps.rows : 4;
1402
- const required = resolvedProps.required === true;
1403
- const disabled = resolvedProps.disabled === true;
1404
- const readOnly = resolvedProps.readOnly === true;
1405
- return /* @__PURE__ */ jsx3(
1406
- "textarea",
1407
- {
1408
- id: domId,
1409
- name,
1410
- placeholder,
1411
- defaultValue,
1412
- rows,
1413
- required,
1414
- disabled,
1415
- readOnly,
1416
- style: styles,
1417
- onClick: handleClick,
1418
- "data-kubuild-node": node.id
1419
- }
1420
- );
1421
- }
1422
- case "select": {
1423
- const name = typeof resolvedProps.name === "string" ? resolvedProps.name : void 0;
1424
- const placeholder = typeof resolvedProps.placeholder === "string" ? resolvedProps.placeholder : void 0;
1425
- const defaultValue = resolvedProps.defaultValue !== void 0 ? String(resolvedProps.defaultValue) : void 0;
1426
- const required = resolvedProps.required === true;
1427
- const disabled = resolvedProps.disabled === true;
1428
- let optionsList = [];
1429
- const rawOptions = resolvedProps.options ?? props.options;
1430
- if (Array.isArray(rawOptions)) {
1431
- optionsList = rawOptions.map((opt) => {
1432
- if (typeof opt === "object" && opt !== null) {
1433
- const record = opt;
1434
- return {
1435
- label: String(record.label ?? record.value ?? ""),
1436
- value: String(record.value ?? record.label ?? "")
1437
- };
1438
- }
1439
- return { label: String(opt), value: String(opt) };
1440
- });
1441
- } else if (typeof rawOptions === "string") {
1442
- try {
1443
- const parsed = JSON.parse(rawOptions);
1444
- if (Array.isArray(parsed)) {
1445
- optionsList = parsed.map((opt) => {
1446
- if (typeof opt === "object" && opt !== null) {
1447
- const record = opt;
1448
- return {
1449
- label: String(record.label ?? record.value ?? ""),
1450
- value: String(record.value ?? record.label ?? "")
1451
- };
1452
- }
1453
- return { label: String(opt), value: String(opt) };
1454
- });
1455
- }
1456
- } catch {
1457
- }
1458
- }
1459
- return /* @__PURE__ */ jsxs2(
1460
- "select",
1461
- {
1462
- id: domId,
1463
- name,
1464
- defaultValue,
1465
- required,
1466
- disabled,
1467
- style: styles,
1468
- onClick: handleClick,
1469
- "data-kubuild-node": node.id,
1470
- children: [
1471
- placeholder && /* @__PURE__ */ jsx3("option", { value: "", disabled: required, children: placeholder }),
1472
- optionsList.map((opt, idx) => /* @__PURE__ */ jsx3("option", { value: opt.value, children: opt.label }, `${opt.value}-${idx}`))
1473
- ]
1474
- }
1475
- );
1476
- }
1477
- case "checkbox": {
1478
- const name = typeof resolvedProps.name === "string" ? resolvedProps.name : void 0;
1479
- const label = String(resolvedProps.label ?? "Checkbox");
1480
- const value = resolvedProps.value !== void 0 ? String(resolvedProps.value) : "yes";
1481
- const defaultChecked = resolvedProps.defaultChecked === true;
1482
- const required = resolvedProps.required === true;
1483
- const disabled = resolvedProps.disabled === true;
1484
- const isEditable = mode === "editor" && !isVariableBinding3(props.label);
1485
- return /* @__PURE__ */ jsxs2(
1486
- "label",
1487
- {
1488
- id: domId,
1489
- style: styles,
1490
- onClick: handleClick,
1491
- "data-kubuild-node": node.id,
1492
- children: [
1493
- /* @__PURE__ */ jsx3(
1494
- "input",
1495
- {
1496
- type: "checkbox",
1497
- name,
1498
- value,
1499
- defaultChecked,
1500
- required,
1501
- disabled,
1502
- style: { cursor: disabled ? "not-allowed" : "pointer" }
1503
- }
1504
- ),
1505
- isEditable ? /* @__PURE__ */ jsx3(
1506
- EditableText,
1507
- {
1508
- as: "span",
1509
- value: label,
1510
- isEditable,
1511
- nodeId: node.id,
1512
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "label", val, isBlur)
1513
- }
1514
- ) : /* @__PURE__ */ jsx3("span", { children: label })
1515
- ]
1516
- }
1517
- );
1518
- }
1519
- case "radio": {
1520
- const name = typeof resolvedProps.name === "string" ? resolvedProps.name : void 0;
1521
- const label = String(resolvedProps.label ?? "Radio");
1522
- const value = resolvedProps.value !== void 0 ? String(resolvedProps.value) : "option";
1523
- const defaultChecked = resolvedProps.defaultChecked === true;
1524
- const required = resolvedProps.required === true;
1525
- const disabled = resolvedProps.disabled === true;
1526
- const isEditable = mode === "editor" && !isVariableBinding3(props.label);
1527
- return /* @__PURE__ */ jsxs2(
1528
- "label",
1529
- {
1530
- id: domId,
1531
- style: styles,
1532
- onClick: handleClick,
1533
- "data-kubuild-node": node.id,
1534
- children: [
1535
- /* @__PURE__ */ jsx3(
1536
- "input",
1537
- {
1538
- type: "radio",
1539
- name,
1540
- value,
1541
- defaultChecked,
1542
- required,
1543
- disabled,
1544
- style: { cursor: disabled ? "not-allowed" : "pointer" }
1545
- }
1546
- ),
1547
- isEditable ? /* @__PURE__ */ jsx3(
1548
- EditableText,
1549
- {
1550
- as: "span",
1551
- value: label,
1552
- isEditable,
1553
- nodeId: node.id,
1554
- onChange: (val, isBlur) => onNodePropChange?.(node.id, "label", val, isBlur)
1555
- }
1556
- ) : /* @__PURE__ */ jsx3("span", { children: label })
1557
- ]
1558
- }
1559
- );
1560
- }
1561
- case "collection": {
1562
- const sourceKey = typeof props.sourceKey === "string" ? props.sourceKey : void 0;
1563
- const itemAlias = typeof props.itemAlias === "string" && props.itemAlias.length > 0 ? props.itemAlias : "item";
1564
- const indexKey = `${itemAlias}Index`;
1565
- const sourceValue = sourceKey ? resolveBinding3({ key: sourceKey }, context).value : void 0;
1566
- if (!Array.isArray(sourceValue)) {
1567
- const collectionDiagnostic = {
1568
- code: "INVALID_COLLECTION_SOURCE",
1569
- nodeId: node.id,
1570
- propName: "sourceKey",
1571
- message: `Collection node "${node.id}" expected an array at variable path "${sourceKey ?? "(missing sourceKey)"}" but found ${sourceValue === void 0 ? "nothing" : typeof sourceValue}.`
1572
- };
1573
- onDiagnostic?.(collectionDiagnostic);
1574
- context?.onDiagnostic?.(collectionDiagnostic);
1575
- if (mode === "editor") {
1576
- return /* @__PURE__ */ jsx3(
1577
- "div",
1578
- {
1579
- id: domId,
1580
- "data-kubuild-node": node.id,
1581
- "data-kubuild-collection-invalid": node.type,
1582
- style: {
1583
- ...styles,
1584
- border: "2px dashed #f59e0b",
1585
- backgroundColor: "#fffbeb",
1586
- color: "#92400e",
1587
- padding: "12px",
1588
- borderRadius: "6px",
1589
- fontFamily: "system-ui, -apple-system, sans-serif"
1590
- },
1591
- onClick: handleClick,
1592
- children: /* @__PURE__ */ jsxs2("div", { style: { fontWeight: 600, fontSize: "13px" }, children: [
1593
- "\u{1F4E6} Collection: expected an array at ",
1594
- /* @__PURE__ */ jsx3("code", { children: sourceKey ?? "(missing sourceKey)" })
1595
- ] })
1596
- }
1597
- );
1598
- }
1599
- return /* @__PURE__ */ jsx3("div", { id: domId, "data-kubuild-node": node.id, style: styles, onClick: handleClick, "aria-hidden": "true" });
1600
- }
1601
- return /* @__PURE__ */ jsx3("div", { id: domId, "data-kubuild-node": node.id, style: styles, onClick: handleClick, children: sourceValue.map((item, index) => {
1602
- const childContext = {
1603
- ...context,
1604
- variables: { ...context?.variables ?? {}, [itemAlias]: item, [indexKey]: index }
1605
- };
1606
- const itemSuffix = `${instanceSuffix}--${index}`;
1607
- return node.children?.map((child) => /* @__PURE__ */ jsx3(
1608
- NodeRenderer,
1609
- {
1610
- node: child,
1611
- document,
1612
- registry,
1613
- context: childContext,
1614
- viewport,
1615
- mode,
1616
- onNodeClick,
1617
- onDiagnostic,
1618
- onActionDispatch,
1619
- onNodePropChange,
1620
- instanceSuffix: itemSuffix
1621
- },
1622
- `${child.id}${itemSuffix}`
1623
- ));
1624
- }) });
1625
- }
1626
- default:
1627
- if (mode === "editor") {
1628
- return /* @__PURE__ */ jsxs2(
1629
- "div",
1630
- {
1631
- id: domId,
1632
- "data-kubuild-node": node.id,
1633
- "data-kubuild-unknown": node.type,
1634
- style: {
1635
- ...styles,
1636
- border: "2px dashed #f59e0b",
1637
- backgroundColor: "#fffbeb",
1638
- color: "#92400e",
1639
- padding: "12px",
1640
- borderRadius: "6px",
1641
- fontFamily: "system-ui, -apple-system, sans-serif"
1642
- },
1643
- onClick: handleClick,
1644
- children: [
1645
- /* @__PURE__ */ jsxs2("div", { style: { fontWeight: 600, fontSize: "13px", marginBottom: "4px" }, children: [
1646
- "\u{1F9E9} Unknown Component: ",
1647
- /* @__PURE__ */ jsx3("code", { children: node.type })
1648
- ] }),
1649
- /* @__PURE__ */ jsxs2("div", { style: { fontSize: "11px", color: "#b45309", marginBottom: childrenElements ? "8px" : 0 }, children: [
1650
- "Node ID: ",
1651
- /* @__PURE__ */ jsx3("code", { children: node.id })
1652
- ] }),
1653
- childrenElements
1654
- ]
1655
- }
1656
- );
1657
- }
1658
- return /* @__PURE__ */ jsx3(
1659
- "div",
1660
- {
1661
- id: domId,
1662
- "data-kubuild-node": node.id,
1663
- "data-kubuild-unknown": node.type,
1664
- style: styles,
1665
- onClick: handleClick,
1666
- children: childrenElements
1667
- }
1668
- );
1669
- }
1670
- };
1671
- let content;
1672
- try {
1673
- content = renderNodeContent();
1674
- } catch (error) {
1675
- if (mode === "editor") {
1676
- content = /* @__PURE__ */ jsxs2(
1677
- "div",
1678
- {
1679
- "data-kubuild-node": node.id,
1680
- "data-kubuild-error": node.type,
1681
- style: {
1682
- padding: "12px 16px",
1683
- margin: "4px 0",
1684
- backgroundColor: "#fef2f2",
1685
- border: "1px solid #ef4444",
1686
- borderRadius: "6px",
1687
- color: "#b91c1c",
1688
- fontFamily: "system-ui, -apple-system, sans-serif",
1689
- fontSize: "13px",
1690
- lineHeight: "1.4"
1691
- },
1692
- children: [
1693
- /* @__PURE__ */ jsxs2("div", { style: { fontWeight: 600, marginBottom: "4px" }, children: [
1694
- "\u26A0\uFE0F Component Render Error: <",
1695
- node.type,
1696
- ">"
1697
- ] }),
1698
- /* @__PURE__ */ jsxs2("div", { style: { fontSize: "11px", color: "#7f1d1d", wordBreak: "break-all" }, children: [
1699
- "Node ID: ",
1700
- /* @__PURE__ */ jsx3("code", { children: node.id }),
1701
- " \u2014 ",
1702
- error instanceof Error ? error.message : String(error)
1703
- ] })
1704
- ]
1705
- }
1706
- );
1707
- } else {
1708
- content = /* @__PURE__ */ jsx3(
1709
- "div",
1710
- {
1711
- "data-kubuild-node": node.id,
1712
- "data-kubuild-error": node.type,
1713
- style: { display: "none" },
1714
- "aria-hidden": "true"
1715
- }
1716
- );
1717
- }
1718
- }
1719
- return /* @__PURE__ */ jsx3(ComponentErrorBoundary, { nodeId: node.id, componentType: node.type, mode, children: content });
62
+ @keyframes kb-anim-slide-down {
63
+ from { transform: translateY(-100%); }
64
+ to { transform: translateY(0); }
65
+ }
66
+ @keyframes kb-anim-slide-left {
67
+ from { transform: translateX(100%); }
68
+ to { transform: translateX(0); }
69
+ }
70
+ @keyframes kb-anim-slide-right {
71
+ from { transform: translateX(-100%); }
72
+ to { transform: translateX(0); }
73
+ }
74
+ @keyframes kb-anim-flip-up {
75
+ from { opacity: 0; transform: perspective(600px) rotateX(45deg); }
76
+ to { opacity: 1; transform: perspective(600px) rotateX(0deg); }
77
+ }
78
+ @keyframes kb-anim-flip-down {
79
+ from { opacity: 0; transform: perspective(600px) rotateX(-45deg); }
80
+ to { opacity: 1; transform: perspective(600px) rotateX(0deg); }
1720
81
  }
1721
- var KubuildRenderer = ({
1722
- document,
1723
- registry = createDefaultComponentRegistry(),
1724
- context,
1725
- viewport = "desktop",
1726
- mode = "runtime",
1727
- className,
1728
- onNodeClick,
1729
- onDiagnostic,
1730
- onActionDispatch,
1731
- onNodePropChange
1732
- }) => {
1733
- if (!document || !document.document) {
1734
- return /* @__PURE__ */ jsx3("div", { className, children: "Empty Document" });
1735
- }
1736
- return /* @__PURE__ */ jsx3(RenderContextProvider, { value: context, children: /* @__PURE__ */ jsxs2("div", { className: `kubuild-canvas-root ${className || ""}`, children: [
1737
- (() => {
1738
- const css = collectStateStylesCss(document);
1739
- return css ? /* @__PURE__ */ jsx3("style", { "data-kubuild-state-styles": true, children: css }) : null;
1740
- })(),
1741
- /* @__PURE__ */ jsx3(
1742
- NodeRenderer,
1743
- {
1744
- node: document.document,
1745
- document,
1746
- registry,
1747
- context,
1748
- viewport,
1749
- mode,
1750
- onNodeClick,
1751
- onDiagnostic,
1752
- onActionDispatch,
1753
- onNodePropChange
1754
- }
1755
- )
1756
- ] }) });
1757
- };
1758
82
 
1759
- // src/preview-adapter.tsx
1760
- import { useMemo as useMemo3 } from "react";
1761
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
1762
- var DEFAULT_VIEWPORT_CONFIGS = Object.freeze({
1763
- desktop: {
1764
- width: "100%",
1765
- maxWidth: "1280px",
1766
- minHeight: "600px",
1767
- label: "Desktop (1280px)",
1768
- isFluid: true
1769
- },
1770
- tablet: {
1771
- width: "768px",
1772
- height: "1024px",
1773
- minHeight: "600px",
1774
- label: "Tablet (768 \xD7 1024)",
1775
- isFluid: false
1776
- },
1777
- mobile: {
1778
- width: "375px",
1779
- height: "667px",
1780
- minHeight: "500px",
1781
- label: "Mobile (375 \xD7 667)",
1782
- isFluid: false
1783
- }
1784
- });
1785
- var DEFAULT_BREAKPOINTS = Object.freeze({
1786
- mobile: 480,
1787
- tablet: 768,
1788
- desktop: 1024
1789
- });
1790
- function resolveViewportFromWidth(width, breakpoints) {
1791
- const resolved = { ...DEFAULT_BREAKPOINTS, ...breakpoints };
1792
- if (width <= resolved.mobile) {
1793
- return "mobile";
1794
- }
1795
- if (width <= resolved.tablet) {
1796
- return "tablet";
1797
- }
1798
- return "desktop";
83
+ /* Continuous Loop Keyframes */
84
+ @keyframes kb-loop-pulse {
85
+ 0%, 100% { transform: scale(1); opacity: 1; }
86
+ 50% { transform: scale(1.05); opacity: 0.9; }
87
+ }
88
+ @keyframes kb-loop-bounce {
89
+ 0%, 100% { transform: translateY(0); }
90
+ 50% { transform: translateY(-8px); }
91
+ }
92
+ @keyframes kb-loop-spin {
93
+ from { transform: rotate(0deg); }
94
+ to { transform: rotate(360deg); }
1799
95
  }
1800
- function resolveViewportDimensions(viewport, customConfigs) {
1801
- const baseConfig = DEFAULT_VIEWPORT_CONFIGS[viewport] || DEFAULT_VIEWPORT_CONFIGS.desktop;
1802
- const custom = customConfigs?.[viewport];
1803
- return { ...baseConfig, ...custom };
96
+ @keyframes kb-loop-float {
97
+ 0%, 100% { transform: translateY(0); }
98
+ 50% { transform: translateY(-6px); }
1804
99
  }
1805
- function resolveViewportContainerStyle(viewport, customConfigs, customScale) {
1806
- const config = resolveViewportDimensions(viewport, customConfigs);
1807
- const scale = customScale ?? config.scale ?? 1;
1808
- const toCssVal = (v) => typeof v === "number" ? `${v}px` : v;
1809
- const style = {
1810
- width: toCssVal(config.width),
1811
- maxWidth: toCssVal(config.maxWidth),
1812
- minWidth: toCssVal(config.minWidth),
1813
- height: toCssVal(config.height),
1814
- minHeight: toCssVal(config.minHeight),
1815
- maxHeight: toCssVal(config.maxHeight),
1816
- aspectRatio: config.aspectRatio,
1817
- transition: "width 0.2s ease, max-width 0.2s ease, height 0.2s ease"
1818
- };
1819
- if (scale !== 1) {
1820
- style.transform = `scale(${scale})`;
1821
- style.transformOrigin = "top center";
1822
- }
1823
- return style;
100
+ @keyframes kb-loop-shimmer {
101
+ 0%, 100% { opacity: 0.75; }
102
+ 50% { opacity: 1; }
1824
103
  }
1825
- var PreviewViewportAdapter = ({
1826
- document,
1827
- viewport = "desktop",
1828
- onViewportChange,
1829
- viewportConfigs,
1830
- breakpoints,
1831
- registry,
1832
- context,
1833
- mode = "runtime",
1834
- showChrome = false,
1835
- chromeTitle,
1836
- editorOverlay,
1837
- scale,
1838
- className,
1839
- style,
1840
- canvasClassName,
1841
- canvasStyle,
1842
- onNodeClick,
1843
- onDiagnostic,
1844
- onActionDispatch
1845
- }) => {
1846
- const currentConfig = useMemo3(
1847
- () => resolveViewportDimensions(viewport, viewportConfigs),
1848
- [viewport, viewportConfigs]
1849
- );
1850
- const containerStyle = useMemo3(
1851
- () => resolveViewportContainerStyle(viewport, viewportConfigs, scale),
1852
- [viewport, viewportConfigs, scale]
1853
- );
1854
- const mergedCanvasStyle = useMemo3(
1855
- () => ({
1856
- ...containerStyle,
1857
- ...canvasStyle,
1858
- position: "relative",
1859
- boxSizing: "border-box"
1860
- }),
1861
- [containerStyle, canvasStyle]
1862
- );
1863
- return /* @__PURE__ */ jsxs3(
1864
- "div",
1865
- {
1866
- "data-kubuild-preview-container": true,
1867
- "data-viewport": viewport,
1868
- className: `kubuild-preview-viewport-adapter ${className || ""}`,
1869
- style: {
1870
- display: "flex",
1871
- flexDirection: "column",
1872
- alignItems: "center",
1873
- justifyContent: "flex-start",
1874
- width: "100%",
1875
- height: "100%",
1876
- boxSizing: "border-box",
1877
- ...style
1878
- },
1879
- children: [
1880
- showChrome && /* @__PURE__ */ jsxs3(
1881
- "div",
1882
- {
1883
- "data-kubuild-preview-chrome": true,
1884
- style: {
1885
- display: "flex",
1886
- alignItems: "center",
1887
- justifyContent: "space-between",
1888
- width: "100%",
1889
- maxWidth: containerStyle.maxWidth || containerStyle.width,
1890
- padding: "8px 12px",
1891
- marginBottom: "8px",
1892
- backgroundColor: "#1e293b",
1893
- color: "#f8fafc",
1894
- borderRadius: "8px",
1895
- fontSize: "12px",
1896
- fontFamily: "system-ui, -apple-system, sans-serif",
1897
- boxSizing: "border-box"
1898
- },
1899
- children: [
1900
- /* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
1901
- /* @__PURE__ */ jsx4("span", { style: { fontWeight: 600 }, children: chromeTitle || document.metadata?.title || "Preview" }),
1902
- /* @__PURE__ */ jsx4(
1903
- "span",
1904
- {
1905
- "data-testid": "viewport-badge",
1906
- style: {
1907
- fontSize: "10px",
1908
- padding: "2px 6px",
1909
- borderRadius: "4px",
1910
- backgroundColor: "#334155",
1911
- color: "#94a3b8",
1912
- textTransform: "uppercase",
1913
- fontWeight: 700
1914
- },
1915
- children: viewport
1916
- }
1917
- ),
1918
- /* @__PURE__ */ jsx4("span", { style: { fontSize: "11px", color: "#64748b" }, children: currentConfig.label || `${currentConfig.width} \xD7 ${currentConfig.height || "auto"}` })
1919
- ] }),
1920
- onViewportChange && /* @__PURE__ */ jsx4(
1921
- "div",
1922
- {
1923
- "data-testid": "viewport-switcher",
1924
- style: { display: "flex", gap: "4px", backgroundColor: "#0f172a", padding: "2px", borderRadius: "6px" },
1925
- children: ["desktop", "tablet", "mobile"].map((device) => {
1926
- const isActive = viewport === device;
1927
- return /* @__PURE__ */ jsx4(
1928
- "button",
1929
- {
1930
- type: "button",
1931
- "data-testid": `viewport-btn-${device}`,
1932
- onClick: () => onViewportChange(device),
1933
- style: {
1934
- padding: "4px 10px",
1935
- fontSize: "11px",
1936
- fontWeight: 500,
1937
- borderRadius: "4px",
1938
- border: "none",
1939
- cursor: "pointer",
1940
- textTransform: "capitalize",
1941
- backgroundColor: isActive ? "#3b82f6" : "transparent",
1942
- color: isActive ? "#ffffff" : "#94a3b8",
1943
- transition: "all 0.15s ease"
1944
- },
1945
- children: device
1946
- },
1947
- device
1948
- );
1949
- })
1950
- }
1951
- )
1952
- ]
104
+ `.trim();function fe(r){return r.replace(/["\\\]]/g,"\\$&")}function Jt(r,e){let i=fe(r),o=[];switch(e){case"lift":o.push(`[data-kubuild-node="${i}"] { transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease !important; will-change: transform; }`,`[data-kubuild-node="${i}"]:hover { transform: translateY(-4px) !important; box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important; }`);break;case"scale":o.push(`[data-kubuild-node="${i}"] { transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important; will-change: transform; }`,`[data-kubuild-node="${i}"]:hover { transform: scale(1.04) !important; }`);break;case"glow":o.push(`[data-kubuild-node="${i}"] { transition: box-shadow 0.25s ease !important; }`,`[data-kubuild-node="${i}"]:hover { box-shadow: 0 0 20px 2px rgba(59, 130, 246, 0.5) !important; }`);break;case"tilt":o.push(`[data-kubuild-node="${i}"] { transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important; will-change: transform; }`,`[data-kubuild-node="${i}"]:hover { transform: rotate(2deg) scale(1.02) !important; }`);break;default:break}return o}function Zt(r,e){let i=fe(r),o=[];switch(e){case"pulse":o.push(`[data-kubuild-node="${i}"] { animation: kb-loop-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite !important; }`);break;case"bounce":o.push(`[data-kubuild-node="${i}"] { animation: kb-loop-bounce 1.5s ease-in-out infinite !important; }`);break;case"spin":o.push(`[data-kubuild-node="${i}"] { animation: kb-loop-spin 3s linear infinite !important; }`);break;case"float":o.push(`[data-kubuild-node="${i}"] { animation: kb-loop-float 3s ease-in-out infinite !important; }`);break;case"shimmer":o.push(`[data-kubuild-node="${i}"] { animation: kb-loop-shimmer 2s ease-in-out infinite !important; }`);break;default:break}return o}function Qt(r,e){if(!e.type||e.type==="none")return[];let i=fe(r),o=typeof e.duration=="number"?e.duration:600,n=typeof e.delay=="number"?e.delay:0,t=e.easing||"ease-out";return[`[data-kubuild-node="${i}"] { animation-name: kb-anim-${e.type} !important; animation-duration: ${o}ms !important; animation-delay: ${n}ms !important; animation-timing-function: ${t} !important; animation-fill-mode: both !important; }`]}function me(r){if(!r?.document)return"";let e=[],i=!1,o=n=>{let t=n.animation;t&&(t.hoverEffect&&t.hoverEffect!=="none"&&(e.push(...Jt(n.id,t.hoverEffect)),i=!0),t.loopEffect&&t.loopEffect!=="none"&&(e.push(...Zt(n.id,t.loopEffect)),i=!0),t.type&&t.type!=="none"&&(e.push(...Qt(n.id,t)),i=!0)),n.children?.forEach(o)};return o(r.document),i?`${Gt}
105
+
106
+ ${e.join(`
107
+ `)}`:""}function Co(r,e){let i=e||(typeof window<"u"?window.document:null);if(!i)return!1;let o=i.querySelector(`[data-kubuild-node="${fe(r)}"]`);if(!o)return!1;let n=o.style.animation;return o.style.animation="none",o.offsetWidth,o.style.animation=n,o.dispatchEvent(new CustomEvent("kubuild:replay-animation",{bubbles:!0,detail:{nodeId:r}})),!0}import{Component as en}from"react";import{AlertTriangle as tn}from"lucide-react";import{jsx as ke,jsxs as ge}from"react/jsx-runtime";var be=class extends en{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,i){this.props.onError&&this.props.onError(e,i),this.props.onDiagnostic&&this.props.onDiagnostic({code:"ACTION_EXECUTION_ERROR",actionType:"render",nodeId:this.props.nodeId,message:`Render error in <${this.props.componentType}> (ID: ${this.props.nodeId}): ${e.message}`,error:e})}render(){if(this.state.hasError){let{nodeId:e,componentType:i,mode:o="runtime"}=this.props,n=this.state.error?.message||"Unknown render error";return o==="editor"?ge("div",{"data-kubuild-node":e,"data-kubuild-error":i,style:{padding:"12px 16px",margin:"4px 0",backgroundColor:"#fef2f2",border:"1px solid #ef4444",borderRadius:"6px",color:"#b91c1c",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"13px",lineHeight:"1.4"},children:[ge("div",{style:{fontWeight:600,marginBottom:"4px",display:"flex",alignItems:"center",gap:"6px"},children:[ke(tn,{size:14,"aria-hidden":"true"}),ge("span",{children:["Component Render Error: <",i,">"]})]}),ge("div",{style:{fontSize:"11px",color:"#7f1d1d",wordBreak:"break-all"},children:["Node ID: ",ke("code",{children:e})," \u2014 ",n]})]}):ke("div",{"data-kubuild-node":e,"data-kubuild-error":i,style:{display:"none"},"aria-hidden":"true"})}return this.props.children}};import{isVariableBinding as nn}from"@kubuild/schema";import{primitiveTypeForField as et}from"@kubuild/components";import{resolveBinding as on}from"@kubuild/core";function rn(r){switch(r){case"string":return"";case"number":return 0;case"boolean":return!1}}function sn(r,e,i,o,n){let t=r.props?.[e.name],l=et(e);if(l===void 0||t===void 0)return t;let f=i.defaultProps?.[e.name]??e.defaultValue??rn(l);if(nn(t)){let p=on(t,o);return typeof p.value===l?p.value:(n.push({code:"INCOMPATIBLE_BINDING_TYPE",nodeId:r.id,propName:e.name,expectedType:l,actualType:typeof p.value,message:`Prop "${e.name}" on node "${r.id}" expected a ${l} but resolved binding "${t.key}" produced a ${typeof p.value}.`}),f)}return l==="string"&&typeof t=="string"&&t.includes("{{")?We(o,t):t}function tt(r,e,i){let o=r.props||{};if(!e||!e.propFields||e.propFields.length===0)return{props:o,diagnostics:[]};let n=[],t={...o};for(let l of e.propFields)et(l)!==void 0&&(t[l.name]=sn(r,l,e,i,n));return{props:t,diagnostics:n}}import Ln from"react";import{isAssetReference as qn,isVariableBinding as F}from"@kubuild/schema";import{icons as Vt,Package as _n,Puzzle as jn,AlertTriangle as zn}from"lucide-react";import{resolveBinding as Un,sanitizeUrl as Z,sanitizeHtml as Wn}from"@kubuild/core";import{createContext as Sn,useContext as bt,useState as ae,useCallback as V,useRef as mt,useMemo as le,useEffect as yt}from"react";import{applyFieldTransform as gt,validateFieldValue as Tn,validateForm as En,ActionPipelineExecutor as Pn}from"@kubuild/core";import{isSafeActionUrl as an}from"@kubuild/schema";import{ActionCancellationError as Ce,ActionTimeoutError as $e}from"@kubuild/core";var J=class extends Error{status;statusText;url;method;data;headers;response;isTimeout;isCancelled;isNetworkError;stepId;cause;constructor(e,i){super(e),this.name="ApiRequestError",this.status=i?.status,this.statusText=i?.statusText,this.url=i?.url,this.method=i?.method,this.data=i?.data,this.headers=i?.headers,this.response=i?.response,this.isTimeout=i?.isTimeout??!1,this.isCancelled=i?.isCancelled??!1,this.isNetworkError=i?.isNetworkError??!1,this.stepId=i?.stepId,this.cause=i?.cause}};function ln(r,e,i){if(!r||typeof r!="string")throw new J("API request URL is required",{url:r});let o=r.trim();if(!an(o))throw new J(`Disallowed or unsafe protocol in API request URL: "${o}"`,{url:o});let n=o;if(i&&!o.startsWith("http://")&&!o.startsWith("https://")&&!o.startsWith("//")){let t=i.endsWith("/")?i.slice(0,-1):i,l=o.startsWith("/")?o:`/${o}`;n=`${t}${l}`}if(e&&typeof e=="object"&&Object.keys(e).length>0){let[t,l]=n.split("?"),f=new URLSearchParams(l||"");for(let[u,d]of Object.entries(e))d!=null&&(Array.isArray(d)?d.forEach(s=>f.append(u,String(s))):f.set(u,String(d)));let p=f.toString();n=p?`${t}?${p}`:t}return n}function dn(r,e,i,o={}){let n=r.toUpperCase(),t={...o};if(n==="GET"||n==="HEAD")return{body:void 0,headers:t};if(e==null)return{body:void 0,headers:t};let l=Object.keys(t).find(u=>u.toLowerCase()==="content-type"),f=l?t[l]:void 0,p=(i||"").toLowerCase();if(p==="form-data"||p==="formdata"||p==="multipart"||f&&f.includes("multipart/form-data")){if(typeof FormData<"u"&&e instanceof FormData)return l&&delete t[l],{body:e,headers:t};if(typeof FormData<"u"&&typeof e=="object"&&e!==null){let u=new FormData;for(let[d,s]of Object.entries(e))s!=null&&(typeof Blob<"u"&&s instanceof Blob?u.append(d,s):Array.isArray(s)?s.forEach(a=>u.append(d,typeof a=="object"?JSON.stringify(a):String(a))):typeof s=="object"?u.append(d,JSON.stringify(s)):u.append(d,String(s)));return l&&delete t[l],{body:u,headers:t}}}if(p==="urlencoded"||p==="url-encoded"||f&&f.includes("application/x-www-form-urlencoded")){if(typeof URLSearchParams<"u"&&e instanceof URLSearchParams)return l||(t["Content-Type"]="application/x-www-form-urlencoded;charset=UTF-8"),{body:e,headers:t};if(typeof e=="object"&&e!==null){let u=new URLSearchParams;for(let[d,s]of Object.entries(e))s!=null&&(Array.isArray(s)?s.forEach(a=>u.append(d,String(a))):u.append(d,String(s)));return l||(t["Content-Type"]="application/x-www-form-urlencoded;charset=UTF-8"),{body:u,headers:t}}if(typeof e=="string")return l||(t["Content-Type"]="application/x-www-form-urlencoded;charset=UTF-8"),{body:e,headers:t}}if(p==="raw"||p==="text")return l||(t["Content-Type"]="text/plain;charset=UTF-8"),{body:typeof e=="string"?e:String(e),headers:t};if(typeof e=="object"&&e!==null)return l||(t["Content-Type"]="application/json"),{body:JSON.stringify(e),headers:t};if(typeof e=="string"){if(!l)try{JSON.parse(e),t["Content-Type"]="application/json"}catch{t["Content-Type"]="text/plain;charset=UTF-8"}return{body:e,headers:t}}return{body:String(e),headers:t}}async function cn(r){let e=r.headers.get("content-type")||"",i=await r.text();if(!i||i.trim()==="")return null;if(e.includes("application/json")||e.includes("+json"))try{return JSON.parse(i)}catch{return i}let o=i.trim();if(o.startsWith("{")&&o.endsWith("}")||o.startsWith("[")&&o.endsWith("]"))try{return JSON.parse(o)}catch{return i}return i}function we(r){let e=r?.defaultTimeout,i=r?.baseUrl,o=r?.headers;return async function(t,l,f){let p=l.fetchFn||r?.fetchFn||(typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch:typeof fetch<"u"?fetch:void 0);if(!p)throw new J("No fetch implementation available for API request runner",{stepId:t.id});let u=t.payload||{},d=String(u.method||"GET").toUpperCase(),s=u.timeout??e,a=u.baseUrl??i,c=ln(String(u.url||""),u.queryParams,a),m={...o||{},...u.headers||{}},{body:b,headers:y}=dn(d,u.body,u.bodyFormat||u.bodyType,m),h=new AbortController,v,x=()=>{h.abort(f?.reason)};if(f){if(f.aborted)throw new Ce(f.reason instanceof Error?f.reason.message:"API request cancelled",t.id);f.addEventListener("abort",x,{once:!0})}s!==void 0&&s>0&&(v=setTimeout(()=>{h.abort(new $e(`API request timed out after ${s}ms`,s,t.id))},s));try{let g=await p(c,{method:d,headers:y,body:b,signal:h.signal}),w={};g.headers&&typeof g.headers.forEach=="function"&&g.headers.forEach((S,E)=>{w[E.toLowerCase()]=S});let R=await cn(g),$={ok:g.ok,status:g.status,statusText:g.statusText,headers:w,data:R,body:R,url:g.url||c};if(!g.ok){let S=(typeof R=="object"&&R!==null&&"message"in R?String(R.message):void 0)||(typeof R=="string"&&R.length<200?R:void 0)||`HTTP ${g.status} ${g.statusText||"Error"}`;throw new J(`API request failed: ${S}`,{status:g.status,statusText:g.statusText,url:c,method:d,data:R,headers:w,response:$,stepId:t.id})}return $}catch(g){if(g instanceof J)throw g;if(h.signal.aborted){let R=h.signal.reason;if(R instanceof $e||R instanceof Error&&R.name==="ActionTimeoutError"||R instanceof Ce||R instanceof Error&&R.name==="ActionCancellationError")throw R;if(g instanceof Error&&(g.name==="AbortError"||g.name==="TimeoutError"))throw v===void 0&&f?.aborted?new Ce("API request cancelled",t.id):new $e(`API request timed out after ${s}ms`,s??0,t.id)}let w=g instanceof Error?g.message:String(g);throw new J(`Network error during API request: ${w}`,{url:c,method:d,isNetworkError:!0,stepId:t.id,cause:g})}finally{v!==void 0&&clearTimeout(v),f&&f.removeEventListener("abort",x)}}}var nt=we();import{useState as un,useEffect as pn}from"react";var fn=0,Se=class{toasts=[];listeners=new Set;timers=new Map;showToast(e){let i=typeof e=="string"?{message:e}:e,o=i.id||`toast_${Date.now()}_${++fn}`,n=i.type||i.variant||"info",t=i.duration!==void 0?Math.max(0,i.duration):4e3,l=i.position||"top-right",f=i.dismissible!==!1;this.timers.has(o)&&(clearTimeout(this.timers.get(o)),this.timers.delete(o));let p={id:o,type:n,message:i.message,title:i.title,duration:t,position:l,dismissible:f,createdAt:Date.now(),dismiss:()=>this.dismissToast(o)};if(this.toasts=this.toasts.filter(u=>u.id!==o).concat(p),t>0){let u=setTimeout(()=>{this.dismissToast(o)},t);this.timers.set(o,u)}return this.notify(),p}dismissToast(e){this.timers.has(e)&&(clearTimeout(this.timers.get(e)),this.timers.delete(e));let i=this.toasts.length;this.toasts=this.toasts.filter(o=>o.id!==e),this.toasts.length!==i&&this.notify()}clearToasts(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear(),this.toasts=[],this.notify()}getToasts(){return[...this.toasts]}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(){let e=this.getToasts();for(let i of this.listeners)try{i(e)}catch(o){console.error("Error in toast listener callback:",o)}}},Q=new Se;function ot(r=Q){let[e,i]=un(()=>r.getToasts());return pn(()=>(i(r.getToasts()),r.subscribe(o=>{i(o)})),[r]),{toasts:e,showToast:o=>r.showToast(o),dismissToast:o=>r.dismissToast(o),clearToasts:()=>r.clearToasts()}}import{useState as rt,useEffect as it,useCallback as Te}from"react";var Ee=class{modals=new Map;activeStack=[];listeners=new Set;openModal(e){if(!e||typeof e!="string")return;let i=e.trim();if(i){if(this.modals.set(i,!0),this.activeStack=this.activeStack.filter(o=>o!==i).concat(i),typeof window<"u"&&typeof window.dispatchEvent=="function")try{let o=new CustomEvent("kubuild:modal:open",{detail:{modalId:i},bubbles:!0});window.dispatchEvent(o)}catch{}this.notify()}}closeModal(e){if(e&&typeof e=="string"){let i=e.trim();if(this.modals.set(i,!1),this.activeStack=this.activeStack.filter(o=>o!==i),typeof window<"u"&&typeof window.dispatchEvent=="function")try{let o=new CustomEvent("kubuild:modal:close",{detail:{modalId:i},bubbles:!0});window.dispatchEvent(o)}catch{}}else{let i=this.activeStack.pop();if(i){if(this.modals.set(i,!1),typeof window<"u"&&typeof window.dispatchEvent=="function")try{let o=new CustomEvent("kubuild:modal:close",{detail:{modalId:i},bubbles:!0});window.dispatchEvent(o)}catch{}}else for(let o of this.modals.keys())this.modals.set(o,!1)}this.notify()}toggleModal(e){return this.isModalOpen(e)?(this.closeModal(e),!1):(this.openModal(e),!0)}isModalOpen(e){return e?!!this.modals.get(e.trim()):!1}getState(){let e={};for(let[i,o]of this.modals.entries())e[i]=o;return e}getActiveModals(){return[...this.activeStack]}reset(){this.modals.clear(),this.activeStack=[],this.notify()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(){let e=this.getState();for(let i of this.listeners)try{i(e)}catch(o){console.error("Error in modal listener callback:",o)}}},se=new Ee;function Yo(r,e=se){let[i,o]=rt(()=>e.isModalOpen(r));it(()=>(o(e.isModalOpen(r)),e.subscribe(f=>{o(!!f[r])})),[r,e]);let n=Te(()=>e.openModal(r),[r,e]),t=Te(()=>e.closeModal(r),[r,e]),l=Te(()=>e.toggleModal(r),[r,e]);return{isOpen:i,open:n,close:t,toggle:l}}function Xo(r=se){let[e,i]=rt(()=>r.getState());return it(()=>(i(r.getState()),r.subscribe(o=>{i(o)})),[r]),{modals:e,activeModals:r.getActiveModals(),isOpen:o=>!!e[o],openModal:o=>r.openModal(o),closeModal:o=>r.closeModal(o),toggleModal:o=>r.toggleModal(o)}}var st=(r,e)=>{let i=r.payload||{},o=String(i.message||"").trim();if(!o)throw new Error("Toast message cannot be empty");let n=i.type||i.variant||"info",t=i.duration!==void 0?i.duration:4e3,l=i.position||"top-right",f=i.title?String(i.title):void 0,u=(e.toastManager||Q).showToast({message:o,type:n,duration:t,position:l,title:f});return{id:u.id,message:u.message,type:u.type,title:u.title,duration:u.duration,position:u.position}},at=(r,e)=>{let i=r.payload||{},o=i.modalId||i.modalNodeId||i.targetNodeId||i.nodeId,n=o?String(o).trim():"";if(!n)throw new Error("Modal ID or Modal Node ID is required for open_modal action");if((e.modalManager||se).openModal(n),e.state&&typeof e.state=="object"){let l=e.state.modals||{};e.state.modals={...l,[n]:!0},e.state[n]=!0}return e.variables&&typeof e.variables=="object"&&(e.variables[`modal_${n}_open`]=!0),{modalId:n,open:!0}},lt=(r,e)=>{let i=r.payload||{},o=i.modalId||i.modalNodeId||i.targetNodeId||i.nodeId,n=o?String(o).trim():void 0;if((e.modalManager||se).closeModal(n),n){if(e.state&&typeof e.state=="object"){let l=e.state.modals||{};e.state.modals={...l,[n]:!1},e.state[n]=!1}e.variables&&typeof e.variables=="object"&&(e.variables[`modal_${n}_open`]=!1)}else e.state&&typeof e.state=="object"&&(e.state.modals={});return{modalId:n||"all",open:!1}};import{isSafeActionUrl as mn}from"@kubuild/schema";async function gn(r,e){if(e?.copyFn)return await e.copyFn(r),!0;if(typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function")try{return await navigator.clipboard.writeText(r),!0}catch{}if(typeof document<"u")try{let i=document.createElement("textarea");i.value=r,i.setAttribute("readonly",""),i.style.position="fixed",i.style.top="-9999px",i.style.left="-9999px",i.style.opacity="0",document.body.appendChild(i),i.focus(),i.select();let o=document.execCommand("copy");if(document.body.removeChild(i),o)return!0}catch{}return!1}var dt=(r,e)=>{let i=r.payload||{},o=String(i.url||"").trim();if(!o)throw new Error("Navigation URL cannot be empty");if(!mn(o))throw new Error(`Disallowed or unsafe protocol in navigation URL: "${o}"`);let n=i.target||"_self",t=i.replace??!1,l=i.behavior||"smooth",f=i.scroll??!0;if(o.startsWith("#")){if(typeof document<"u"){try{let u=document.querySelector(o)||document.getElementById(o.slice(1));u&&typeof u.scrollIntoView=="function"&&u.scrollIntoView({behavior:f===!1?"auto":l,block:"start"})}catch{}if(typeof window<"u"&&window.location)try{window.location.hash=o}catch{}}return{url:o,target:"_self",replace:t,scroll:f,behavior:l,navigated:!0,isAnchor:!0}}if(n==="_blank")return typeof window<"u"&&typeof window.open=="function"&&window.open(o,"_blank","noopener,noreferrer"),{url:o,target:n,replace:t,scroll:f,behavior:l,navigated:!0,isAnchor:!1};let p=typeof e.onNavigate=="function"&&e.onNavigate||typeof e.navigateFn=="function"&&e.navigateFn;return p?(p(o,{target:n,replace:t,scroll:f,behavior:l}),{url:o,target:n,replace:t,scroll:f,behavior:l,navigated:!0,isAnchor:!1}):(typeof window<"u"&&window.location&&(t?window.location.replace(o):window.location.assign(o)),{url:o,target:n,replace:t,scroll:f,behavior:l,navigated:!0,isAnchor:!1})},ct=async(r,e)=>{let i=r.payload||{},o=i.text!==void 0?i.text:i.value!==void 0?i.value:"",n=typeof o=="object"&&o!==null?JSON.stringify(o):String(o??""),t=typeof e.copyFn=="function"?e.copyFn:typeof e.clipboardFn=="function"?e.clipboardFn:void 0;return await gn(n,{copyFn:t}),i.notify!==!1&&(i.notify===!0||i.toastMessage)&&(e.toastManager||Q).showToast({message:i.toastMessage||"Copied to clipboard!",type:"success",duration:3e3}),{text:n,copied:!0}},ut=(r,e)=>{let o=(r.payload||{}).formId||(typeof e.formId=="string"?e.formId:void 0);if(typeof e.resetForm=="function"&&e.resetForm(),e.form&&typeof e.form=="object")for(let n of Object.keys(e.form))e.form[n]="";if(typeof document<"u")try{let n=o?document.getElementById(o):document.querySelector("form");n&&typeof n.reset=="function"&&n.reset()}catch{}return{formId:o,reset:!0}};import{useMemo as bn}from"react";import{CheckCircle2 as yn,AlertCircle as hn,AlertTriangle as vn,Info as xn,X as Rn}from"lucide-react";import{Fragment as $n,jsx as G,jsxs as Pe}from"react/jsx-runtime";var kn={"top-right":{top:"16px",right:"16px",alignItems:"flex-end"},"top-left":{top:"16px",left:"16px",alignItems:"flex-start"},"top-center":{top:"16px",left:"50%",transform:"translateX(-50%)",alignItems:"center"},"bottom-right":{bottom:"16px",right:"16px",alignItems:"flex-end"},"bottom-left":{bottom:"16px",left:"16px",alignItems:"flex-start"},"bottom-center":{bottom:"16px",left:"50%",transform:"translateX(-50%)",alignItems:"center"}},pt={success:{bg:"#f0fdf4",border:"#bbf7d0",text:"#166534",titleText:"#14532d",iconColor:"#16a34a",Icon:yn},error:{bg:"#fef2f2",border:"#fecaca",text:"#991b1b",titleText:"#7f1d1d",iconColor:"#dc2626",Icon:hn},warning:{bg:"#fffbeb",border:"#fde68a",text:"#92400e",titleText:"#78350f",iconColor:"#d97706",Icon:vn},info:{bg:"#eff6ff",border:"#bfdbfe",text:"#1e40af",titleText:"#1e3a8a",iconColor:"#2563eb",Icon:xn}},Cn=({toast:r})=>{let e=pt[r.type]||pt.info,i=e.Icon;return Pe("div",{role:"alert","aria-live":"polite","data-testid":`toast-${r.id}`,"data-toast-type":r.type,style:{display:"flex",alignItems:"flex-start",gap:"12px",width:"100%",maxWidth:"380px",minWidth:"280px",padding:"12px 14px",backgroundColor:e.bg,border:`1px solid ${e.border}`,borderRadius:"8px",boxShadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",color:e.text,fontSize:"14px",lineHeight:"1.4",pointerEvents:"auto",animation:"kubuildToastIn 200ms cubic-bezier(0.16, 1, 0.3, 1)",wordBreak:"break-word",boxSizing:"border-box",transition:"all 200ms ease"},children:[G("div",{style:{flexShrink:0,marginTop:"2px",color:e.iconColor},children:G(i,{size:18,color:e.iconColor})}),Pe("div",{style:{flex:1,minWidth:0},children:[r.title&&G("div",{style:{fontWeight:600,fontSize:"14px",marginBottom:"2px",color:e.titleText},children:r.title}),G("div",{style:{color:e.text},children:r.message})]}),r.dismissible&&G("button",{type:"button","aria-label":"Close notification",onClick:r.dismiss,"data-testid":`toast-dismiss-${r.id}`,style:{flexShrink:0,background:"none",border:"none",cursor:"pointer",padding:"2px",marginLeft:"4px",color:e.text,opacity:.7,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"4px"},children:G(Rn,{size:16})})]})},ft=({manager:r=Q,position:e,className:i,maxVisible:o=5})=>{let{toasts:n}=ot(r),t=bn(()=>{if(e)return{[e]:n.filter(f=>(f.position||"top-right")===e)};let l={"top-right":[],"top-left":[],"top-center":[],"bottom-right":[],"bottom-left":[],"bottom-center":[]};return n.forEach(f=>{let p=f.position||"top-right";l[p].push(f)}),l},[n,e]);return n.length===0?null:Pe($n,{children:[G("style",{children:`
108
+ @keyframes kubuildToastIn {
109
+ from {
110
+ opacity: 0;
111
+ transform: translateY(-8px) scale(0.96);
1953
112
  }
1954
- ),
1955
- /* @__PURE__ */ jsxs3(
1956
- "div",
1957
- {
1958
- "data-kubuild-preview-canvas": true,
1959
- "data-viewport": viewport,
1960
- className: `kubuild-preview-canvas ${canvasClassName || ""}`,
1961
- style: mergedCanvasStyle,
1962
- children: [
1963
- /* @__PURE__ */ jsx4(
1964
- KubuildRenderer,
1965
- {
1966
- document,
1967
- registry,
1968
- context,
1969
- viewport,
1970
- mode,
1971
- onNodeClick,
1972
- onDiagnostic,
1973
- onActionDispatch
1974
- }
1975
- ),
1976
- editorOverlay && /* @__PURE__ */ jsx4(
1977
- "div",
1978
- {
1979
- "data-kubuild-preview-overlay": true,
1980
- style: {
1981
- position: "absolute",
1982
- top: 0,
1983
- left: 0,
1984
- right: 0,
1985
- bottom: 0,
1986
- pointerEvents: "none",
1987
- zIndex: 10
1988
- },
1989
- children: editorOverlay
1990
- }
1991
- )
1992
- ]
113
+ to {
114
+ opacity: 1;
115
+ transform: translateY(0) scale(1);
1993
116
  }
1994
- )
1995
- ]
1996
- }
1997
- );
1998
- };
1999
- var KubuildPreviewViewport = PreviewViewportAdapter;
2000
- export {
2001
- ComponentErrorBoundary,
2002
- DEFAULT_BREAKPOINTS,
2003
- DEFAULT_CSS_RESET,
2004
- DEFAULT_RENDER_CONTEXT,
2005
- DEFAULT_VIEWPORT_CONFIGS,
2006
- EditableText,
2007
- HtmlEmbedView,
2008
- KubuildPreviewViewport,
2009
- KubuildRenderer,
2010
- NodeRenderer,
2011
- PreviewViewportAdapter,
2012
- RenderContextProvider,
2013
- collectStateStylesCss,
2014
- createMinimalRenderContext,
2015
- createRenderContext,
2016
- dispatchAction,
2017
- isActionRegistered,
2018
- resolveActionPayload,
2019
- resolveActionPayloadDetailed,
2020
- resolveAssetSync,
2021
- resolveNodeStyles,
2022
- resolveVariable,
2023
- resolveViewportContainerStyle,
2024
- resolveViewportDimensions,
2025
- resolveViewportFromWidth,
2026
- styleDefinitionToCssDeclarations,
2027
- transformEmbedHtml,
2028
- useRenderContext
2029
- };
2030
- //# sourceMappingURL=index.js.map
117
+ }
118
+ `}),Object.entries(t).map(([l,f])=>{if(!f||f.length===0)return null;let p=f.slice(-o);return G("div",{"data-testid":`toast-container-${l}`,className:i,style:{position:"fixed",zIndex:99999,display:"flex",flexDirection:"column",gap:"8px",maxWidth:"calc(100vw - 32px)",pointerEvents:"none",...kn[l]},children:p.map(u=>G(Cn,{toast:u},u.id))},l)})]})};function wn(r){return{api_request:r?.apiRequest?we(r.apiRequest):nt,show_toast:st,open_modal:at,close_modal:lt,navigate:dt,copy_clipboard:ct,reset_form:ut,...r?.handlers||{}}}function ye(r,e){let i=wn(e);for(let[o,n]of Object.entries(i))(!r.hasHandler(o)||e?.handlers?.[o]||e?.apiRequest)&&r.registerHandler(o,n);return r}import{jsx as In}from"react/jsx-runtime";var Ne=Sn(null);function Nn(r,e){let i=new Set([...Object.keys(r),...Object.keys(e)]);for(let o of i)if(r[o]!==e[o])return!0;return!1}var ht=({formId:r,formConfig:e,initialValues:i,onSubmit:o,onSuccess:n,onError:t,actions:l,nodeId:f,document:p,onDiagnostic:u,children:d})=>{let s=Ue(),a=le(()=>r||e?.formId||f||"kubuild-form",[r,e?.formId,f]),c=le(()=>({...e?.initialValues||{},...i||{}}),[e?.initialValues,i]),[m,b]=ae(c),[y,h]=ae(c),[v,x]=ae({}),[g,w]=ae({}),[R,$]=ae(!1),S=mt(new Map),E=mt({values:y,errors:v,touched:g,initialValues:m,isSubmitting:R,formConfig:e});yt(()=>{E.current={values:y,errors:v,touched:g,initialValues:m,isSubmitting:R,formConfig:e}});let ne=V(k=>{if(!k||!k.name)return()=>{};let N={name:k.name,rules:k.rules||[],validateOn:k.validateOn||"blur",label:k.label,defaultValue:k.defaultValue,transform:k.transform,disabled:k.disabled,required:k.required};return S.current.set(k.name,N),k.defaultValue!==void 0&&(E.current.values[k.name]===void 0&&(E.current.values[k.name]=k.defaultValue),h(P=>P[k.name]===void 0?{...P,[k.name]:k.defaultValue}:P)),()=>{S.current.delete(k.name)}},[]),H=V(k=>S.current.get(k),[]),z=V((k,N)=>{let P=S.current.get(k),L=E.current.values,Y=N!==void 0?N:L[k];P?.transform&&(Y=gt(Y,P.transform));let O=[...P?.rules||[]];return P?.required&&!O.some(I=>I.type==="required")&&O.unshift({type:"required",message:`${P.label||k} is required`}),Tn(Y,O,L)},[]),B=V(k=>{let N=k||E.current.values,P=Array.from(S.current.values());return En(N,P)},[]),K=V((k,N)=>{x(P=>{if(N)return{...P,[k]:N};if(P[k]===void 0)return P;let L={...P};return delete L[k],L})},[]),Ae=V(k=>{x({...k})},[]),De=V((k,N,P)=>{let L=S.current.get(k),Y=N;L?.transform&&(Y=gt(N,L.transform)),h(_=>({..._,[k]:Y}));let O=L?.validateOn||e?.validateOn||"blur";if(P!==void 0?P:O==="change"){let _=z(k,Y);K(k,_)}},[e?.validateOn,z,K]),Oe=V((k,N=!0,P)=>{w(I=>({...I,[k]:N}));let Y=S.current.get(k)?.validateOn||e?.validateOn||"blur";if(P!==void 0?P:Y==="blur"&&N){let I=z(k);K(k,I)}},[e?.validateOn,z,K]),Ve=V((k,N=!1)=>{h(P=>N?{...k}:{...P,...k})},[]),ue=V(k=>{$(k)},[]),oe=V(k=>{let N=k||m;k&&b(k),h({...N}),x({}),w({}),$(!1)},[m]),Me=V(async k=>{if(k&&typeof k.preventDefault=="function"&&k.preventDefault(),E.current.isSubmitting)return!1;let N=E.current.values,P={};for(let O of S.current.keys())P[O]=!0;w(P);let L=B(N);if(x(L),!(Object.keys(L).length===0)){if(t?.(L),e?.scrollToFirstError!==!1&&typeof window<"u"&&typeof p<"u"){let I=Object.keys(L)[0];if(I)try{let _=window.document.querySelector(`[name="${I}"], [data-field="${I}"]`);_&&(_.scrollIntoView({behavior:"smooth",block:"center"}),_.focus?.())}catch{}}return!1}$(!0);try{if(l&&l.length>0){let O=l.filter(I=>I.trigger==="submit"&&I.enabled!==!1);if(O.length>0){let I=new Pn;ye(I);for(let _ of O){let re=await I.execute(_,{context:{form:N,variables:s?.variables?{...s.variables}:{},nodeId:f,document:p}});if(!re.success){let Le=re.error instanceof Error?re.error.message:String(re.error||"Submit pipeline failed"),qe={code:"ACTION_EXECUTION_ERROR",actionType:_.steps[0]?.type||"submit",nodeId:f,message:`Form submit pipeline failed: ${Le}`,error:re.error};return u?.(qe),s?.onDiagnostic?.(qe),t?.({_form:Le}),$(!1),!1}}}}return o&&await o(N,{formId:a,setSubmitting:ue,resetForm:oe,setErrors:x}),n?.(N),e?.resetOnSubmit&&oe(),!0}catch(O){let I=O instanceof Error?O.message:String(O),_={code:"ACTION_EXECUTION_ERROR",actionType:"submit",nodeId:f,message:`Form submit execution error: ${I}`,error:O};return u?.(_),s?.onDiagnostic?.(_),t?.({_form:I}),!1}finally{$(!1)}},[e,l,f,p,u,s,o,n,t,a,ue,oe,B]),He=le(()=>Object.keys(v).length===0,[v]),Be=le(()=>Nn(y,m),[y,m]),qt=le(()=>({formId:a,formConfig:e,initialValues:m,values:y,errors:v,touched:g,isSubmitting:R,isValid:He,dirty:Be,setFieldValue:De,setFieldTouched:Oe,setFieldError:K,setErrors:Ae,setValues:Ve,setSubmitting:ue,resetForm:oe,validateField:z,validateForm:B,handleFormSubmit:Me,registerField:ne,getFieldBinding:H}),[a,e,m,y,v,g,R,He,Be,De,Oe,K,Ae,Ve,ue,oe,z,B,Me,ne,H]);return In(Ne.Provider,{value:qt,children:d})};function X(){return bt(Ne)}function $r(){return bt(Ne)}function wr(){let r=X();return{isSubmitting:r?.isSubmitting??!1,isValid:r?.isValid??!0,dirty:r?.dirty??!1,errors:r?.errors??{}}}function Sr(r,e){let i=X();i&&r&&i.registerField(e||{name:r}),yt(()=>{if(!i||!r)return;let a=i.registerField(e||{name:r});return()=>{a()}},[i,r,e]);let o=i?.values[r]!==void 0?i.values[r]:e?.defaultValue,n=i?.errors[r],t=!!i?.touched[r],l=!!(n&&t),f=V((a,c)=>{i?.setFieldValue(r,a,c)},[i,r]),p=V((a=!0,c)=>{i?.setFieldTouched(r,a,c)},[i,r]),u=V(a=>{i?.setFieldError(r,a)},[i,r]),d=V(a=>{if(a&&typeof a=="object"&&"target"in a&&a.target){let c=a.target;if(c.type==="checkbox")f(c.checked);else if(c.type==="number"){let m=c.value===""?"":Number(c.value);f(m)}else f(c.value)}else f(a)},[f]),s=V(()=>{p(!0)},[p]);return{value:o,error:n,touched:t,isInvalid:l,setValue:f,setTouched:p,setError:u,onChange:d,onBlur:s}}import{useRef as Fn}from"react";import{jsx as vt}from"react/jsx-runtime";var j=({as:r="p",id:e,className:i,style:o,value:n,isEditable:t,nodeId:l,onClick:f,onChange:p,...u})=>{let d=Fn(!1),s=r;return t?vt(s,{id:e,className:i,style:{...o,outline:"none",cursor:"text"},contentEditable:!0,suppressContentEditableWarning:!0,"data-kubuild-node":l,onClick:a=>{f?.(a)},onFocus:()=>{d.current=!0},onInput:a=>{let c=a.currentTarget.textContent??"";p?.(c,!1)},onBlur:a=>{d.current=!1;let c=a.currentTarget.textContent??"";p?.(c,!0)},onKeyDown:a=>{a.key==="Escape"&&a.currentTarget.blur()},...u,children:n}):vt(s,{id:e,className:i,style:o,onClick:f,"data-kubuild-node":l,...u,children:n})};import{useRef as xt,useLayoutEffect as An,useEffect as Dn,useMemo as On}from"react";import{jsx as Rt}from"react/jsx-runtime";var Vn=typeof window<"u"?An:Dn;function Mn(r){return r?r.replace(/<style\b([^>]*)>([\s\S]*?)<\/style>/gi,(e,i,o)=>{let n=o;return n=n.replace(/(^|[\s,{}])body(?=[\s,{])/g,"$1:host, body"),n=n.replace(/(^|[\s,{}])html(?=[\s,{])/g,"$1:host, html"),`<style${i}>
119
+ :host { display: block; }
120
+ ${n}</style>`}):""}var kt=({id:r,style:e,onClick:i,dataKubuildNode:o,html:n,role:t})=>{let l=xt(null),f=xt(null),p=On(()=>Mn(n),[n]);return Vn(()=>{let u=l.current;if(u){if(typeof u.attachShadow=="function"){if(!f.current)if(u.shadowRoot)f.current=u.shadowRoot;else try{f.current=u.attachShadow({mode:"open"})}catch{f.current=u.shadowRoot}if(f.current){f.current.innerHTML=p;return}}u.innerHTML=p}},[p]),Rt("div",{ref:l,id:r,style:e,onClick:i,"data-kubuild-node":o,role:t,children:Rt("template",{shadowrootmode:"open",dangerouslySetInnerHTML:{__html:p}})})};import{useEffect as de}from"react";import Ct,{useEffect as Hn}from"react";import{ActionPipelineExecutor as Bn}from"@kubuild/core";async function D(r){let{node:e,trigger:i,document:o,context:n,formContext:t,extraContext:l,onDiagnostic:f,onActionDispatch:p,executor:u}=r;if(!e.actions||!Array.isArray(e.actions)||e.actions.length===0)return{executed:!1,success:!0};let d=e.actions.filter(c=>c.trigger===i&&c.enabled!==!1);if(d.length===0)return{executed:!1,success:!0};let s=u||new Bn;ye(s);let a={form:t?{...t.values}:{},variables:n?.variables?{...n.variables}:{},nodeId:e.id,document:o,toastManager:n?.toastManager,modalManager:n?.modalManager,...l||{}};for(let c of d){let m=await s.execute(c,{context:a});if(p&&c.steps.length>0&&p(c.steps[0].type,c.steps[0].payload,e.id),!m.success){let b=m.error instanceof Error?m.error.message:String(m.error||`Action pipeline "${c.id}" failed`),y={code:"ACTION_EXECUTION_ERROR",actionType:c.steps[0]?.type||i,nodeId:e.id,message:b,error:m.error};return f?.(y),n?.onDiagnostic?.(y),{executed:!0,success:!1,error:m.error}}}return{executed:!0,success:!0}}function $t(r,e){if(!r.actions?.some(t=>t.trigger==="load"&&t.enabled!==!1))return;let o=Ct?.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE||Ct?.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;if(o?.H||o?.ReactCurrentDispatcher?.current)try{Hn(()=>{e.mode!=="editor"&&D({node:r,trigger:"load",document:e.document,context:e.context,formContext:e.formContext,onDiagnostic:e.onDiagnostic,onActionDispatch:e.onActionDispatch})},[r,e.document,e.context,e.formContext,e.onDiagnostic,e.onActionDispatch,e.mode])}catch{}}import{jsx as M,jsxs as he}from"react/jsx-runtime";var wt=({id:r,name:e,action:i,method:o="POST",target:n,autoComplete:t,style:l,onClick:f,mode:p,dataKubuildNode:u,children:d})=>{let s=X();return M("form",{id:r,name:e,action:i,method:o,target:n,autoComplete:t,style:l,onClick:f,onSubmit:m=>{if(p==="editor"){m.preventDefault();return}s&&s.handleFormSubmit(m)},onReset:()=>{s&&s.resetForm()},"data-kubuild-node":u,role:"form","aria-label":e,children:d})},St=({id:r,name:e,type:i="text",placeholder:o,defaultValue:n,required:t,disabled:l,readOnly:f,rules:p,validateOn:u,transform:d,style:s,onClick:a,actions:c,nodeId:m,document:b,renderContext:y,onDiagnostic:h,onActionDispatch:v,dataKubuildNode:x})=>{let g=X();if(g&&e&&g.registerField({name:e,defaultValue:n,required:t,disabled:l,rules:p||[],validateOn:u,transform:d}),de(()=>{if(!g||!e)return;let B=g.registerField({name:e,defaultValue:n,required:t,disabled:l,rules:p||[],validateOn:u,transform:d});return()=>{B()}},[g,e,n,t,l,p,u,d]),!g||!e)return M("input",{id:r,type:i,name:e,placeholder:o,defaultValue:n!==void 0?String(n):void 0,required:t,disabled:l,readOnly:f,style:s,onClick:a,"data-kubuild-node":x});let w=g.values[e],R=w!=null?String(w):n!=null?String(n):"",$=g.errors[e],S=!!g.touched[e],E=!!($&&S);return M("input",{id:r,type:i,name:e,placeholder:o,value:R,onChange:B=>{let K=B.target.value;i==="number"&&(K=B.target.value===""?"":Number(B.target.value)),g.setFieldValue(e,K),c&&c.length>0&&D({node:{id:m||r||e,type:"input",actions:c},trigger:"change",document:b,context:y,formContext:g,extraContext:{fieldName:e,fieldValue:K},onDiagnostic:h,onActionDispatch:v})},onBlur:()=>{g.setFieldTouched(e,!0),c&&c.length>0&&D({node:{id:m||r||e,type:"input",actions:c},trigger:"blur",document:b,context:y,formContext:g,extraContext:{fieldName:e,fieldValue:g.values[e]},onDiagnostic:h,onActionDispatch:v})},onFocus:()=>{c&&c.length>0&&D({node:{id:m||r||e,type:"input",actions:c},trigger:"focus",document:b,context:y,formContext:g,extraContext:{fieldName:e,fieldValue:g.values[e]},onDiagnostic:h,onActionDispatch:v})},required:t,disabled:l,readOnly:f,style:s,onClick:a,"data-kubuild-node":x,"data-field":e,"data-invalid":E?"true":void 0,"aria-invalid":E?!0:void 0,"aria-errormessage":$?`${r}-error`:void 0})},Tt=({id:r,name:e,placeholder:i,defaultValue:o,rows:n=4,required:t,disabled:l,readOnly:f,rules:p,validateOn:u,transform:d,style:s,onClick:a,actions:c,nodeId:m,document:b,renderContext:y,onDiagnostic:h,onActionDispatch:v,dataKubuildNode:x})=>{let g=X();if(g&&e&&g.registerField({name:e,defaultValue:o,required:t,disabled:l,rules:p||[],validateOn:u,transform:d}),de(()=>{if(!g||!e)return;let B=g.registerField({name:e,defaultValue:o,required:t,disabled:l,rules:p||[],validateOn:u,transform:d});return()=>{B()}},[g,e,o,t,l,p,u,d]),!g||!e)return M("textarea",{id:r,name:e,placeholder:i,defaultValue:o!==void 0?String(o):void 0,rows:n,required:t,disabled:l,readOnly:f,style:s,onClick:a,"data-kubuild-node":x});let w=g.values[e],R=w!=null?String(w):o!=null?String(o):"",$=g.errors[e],S=!!g.touched[e],E=!!($&&S);return M("textarea",{id:r,name:e,placeholder:i,rows:n,value:R,onChange:B=>{g.setFieldValue(e,B.target.value),c&&c.length>0&&D({node:{id:m||r||e,type:"textarea",actions:c},trigger:"change",document:b,context:y,formContext:g,extraContext:{fieldName:e,fieldValue:B.target.value},onDiagnostic:h,onActionDispatch:v})},onBlur:()=>{g.setFieldTouched(e,!0),c&&c.length>0&&D({node:{id:m||r||e,type:"textarea",actions:c},trigger:"blur",document:b,context:y,formContext:g,extraContext:{fieldName:e,fieldValue:g.values[e]},onDiagnostic:h,onActionDispatch:v})},onFocus:()=>{c&&c.length>0&&D({node:{id:m||r||e,type:"textarea",actions:c},trigger:"focus",document:b,context:y,formContext:g,extraContext:{fieldName:e,fieldValue:g.values[e]},onDiagnostic:h,onActionDispatch:v})},required:t,disabled:l,readOnly:f,style:s,onClick:a,"data-kubuild-node":x,"data-field":e,"data-invalid":E?"true":void 0,"aria-invalid":E?!0:void 0,"aria-errormessage":$?`${r}-error`:void 0})},Et=({id:r,name:e,placeholder:i,defaultValue:o,required:n,disabled:t,rules:l,validateOn:f,optionsList:p,style:u,onClick:d,actions:s,nodeId:a,document:c,renderContext:m,onDiagnostic:b,onActionDispatch:y,dataKubuildNode:h})=>{let v=X();if(v&&e&&v.registerField({name:e,defaultValue:o,required:n,disabled:t,rules:l||[],validateOn:f}),de(()=>{if(!v||!e)return;let H=v.registerField({name:e,defaultValue:o,required:n,disabled:t,rules:l||[],validateOn:f});return()=>{H()}},[v,e,o,n,t,l,f]),!v||!e)return he("select",{id:r,name:e,defaultValue:o!==void 0?String(o):"",required:n,disabled:t,style:u,onClick:d,"data-kubuild-node":h,children:[i&&M("option",{value:"",disabled:!0,children:i}),p.map((H,z)=>M("option",{value:H.value,children:H.label},z))]});let x=v.values[e],g=x!=null?String(x):o!=null?String(o):"",w=v.errors[e],R=!!v.touched[e],$=!!(w&&R);return he("select",{id:r,name:e,value:g,onChange:H=>{v.setFieldValue(e,H.target.value),s&&s.length>0&&D({node:{id:a||r||e,type:"select",actions:s},trigger:"change",document:c,context:m,formContext:v,extraContext:{fieldName:e,fieldValue:H.target.value},onDiagnostic:b,onActionDispatch:y})},onBlur:()=>{v.setFieldTouched(e,!0),s&&s.length>0&&D({node:{id:a||r||e,type:"select",actions:s},trigger:"blur",document:c,context:m,formContext:v,extraContext:{fieldName:e,fieldValue:v.values[e]},onDiagnostic:b,onActionDispatch:y})},onFocus:()=>{s&&s.length>0&&D({node:{id:a||r||e,type:"select",actions:s},trigger:"focus",document:c,context:m,formContext:v,extraContext:{fieldName:e,fieldValue:v.values[e]},onDiagnostic:b,onActionDispatch:y})},required:n,disabled:t,style:u,onClick:d,"data-kubuild-node":h,"data-field":e,"data-invalid":$?"true":void 0,"aria-invalid":$?!0:void 0,"aria-errormessage":w?`${r}-error`:void 0,children:[i&&M("option",{value:"",disabled:!0,children:i}),p.map((H,z)=>M("option",{value:H.value,children:H.label},z))]})},Pt=({id:r,name:e,label:i="",defaultChecked:o=!1,required:n,disabled:t,rules:l,validateOn:f,style:p,onClick:u,actions:d,nodeId:s,document:a,renderContext:c,onDiagnostic:m,onActionDispatch:b,dataKubuildNode:y,isEditable:h,onNodePropChange:v})=>{let x=X();x&&e&&x.registerField({name:e,defaultValue:o,required:n,disabled:t,rules:l||[],validateOn:f}),de(()=>{if(!x||!e)return;let $=x.registerField({name:e,defaultValue:o,required:n,disabled:t,rules:l||[],validateOn:f});return()=>{$()}},[x,e,o,n,t,l,f]);let g=x&&e&&x.values[e]!==void 0?!!x.values[e]:o;return he("label",{id:r,style:p,onClick:u,"data-kubuild-node":y,children:[M("input",{type:"checkbox",name:e,checked:g,onChange:$=>{x&&e&&(x.setFieldValue(e,$.target.checked),d&&d.length>0&&D({node:{id:s||r||e,type:"checkbox",actions:d},trigger:"change",document:a,context:c,formContext:x,extraContext:{fieldName:e,fieldValue:$.target.checked},onDiagnostic:m,onActionDispatch:b}))},onBlur:()=>{x&&e&&(x.setFieldTouched(e,!0),d&&d.length>0&&D({node:{id:s||r||e,type:"checkbox",actions:d},trigger:"blur",document:a,context:c,formContext:x,extraContext:{fieldName:e,fieldValue:g},onDiagnostic:m,onActionDispatch:b}))},required:n,disabled:t,style:{cursor:t?"not-allowed":"pointer"},"data-field":e}),h?M(j,{as:"span",value:i,isEditable:h,nodeId:y||"",onChange:($,S)=>v?.(y||"","label",$,S)}):M("span",{children:i})]})},Nt=({id:r,name:e,label:i="",value:o="",defaultChecked:n=!1,required:t,disabled:l,rules:f,validateOn:p,style:u,onClick:d,actions:s,nodeId:a,document:c,renderContext:m,onDiagnostic:b,onActionDispatch:y,dataKubuildNode:h,isEditable:v,onNodePropChange:x})=>{let g=X();g&&e&&g.registerField({name:e,defaultValue:n?o:void 0,required:t,disabled:l,rules:f||[],validateOn:p}),de(()=>{if(!g||!e)return;let S=g.registerField({name:e,defaultValue:n?o:void 0,required:t,disabled:l,rules:f||[],validateOn:p});return()=>{S()}},[g,e,n,o,t,l,f,p]);let w=g&&e&&g.values[e]!==void 0?g.values[e]===o:n;return he("label",{id:r,style:u,onClick:d,"data-kubuild-node":h,children:[M("input",{type:"radio",name:e,value:o,checked:w,onChange:()=>{g&&e&&(g.setFieldValue(e,o),s&&s.length>0&&D({node:{id:a||r||e,type:"radio",actions:s},trigger:"change",document:c,context:m,formContext:g,extraContext:{fieldName:e,fieldValue:o},onDiagnostic:b,onActionDispatch:y}))},onBlur:()=>{g&&e&&(g.setFieldTouched(e,!0),s&&s.length>0&&D({node:{id:a||r||e,type:"radio",actions:s},trigger:"blur",document:c,context:m,formContext:g,extraContext:{fieldName:e,fieldValue:o},onDiagnostic:b,onActionDispatch:y}))},required:t,disabled:l,style:{cursor:l?"not-allowed":"pointer"},"data-field":e}),v?M(j,{as:"span",value:i,isEditable:v,nodeId:h||"",onChange:(S,E)=>x?.(h||"","label",S,E)}):M("span",{children:i})]})},It=({id:r,buttonType:e,disabled:i,ariaLabel:o,style:n,onClick:t,actions:l,node:f,document:p,renderContext:u,onDiagnostic:d,onActionDispatch:s,dataKubuildNode:a,actionAttrs:c,children:m})=>{let b=X(),y=b?.isSubmitting===!0,h=i||e==="submit"&&y;return M("button",{id:r,type:e,disabled:h,"aria-disabled":h?!0:void 0,"aria-label":o,"aria-busy":e==="submit"&&y?!0:void 0,tabIndex:h?-1:0,style:n,onClick:h?void 0:async x=>{if(h)return;if(e==="submit"){if(b&&!await b.handleFormSubmit(x))return}else e==="reset"&&b&&b.resetForm();let g=f||{id:a||r||"button",type:"button",actions:l};g.actions&&g.actions.length>0&&await D({node:g,trigger:"click",document:p,context:u,formContext:b,onDiagnostic:d,onActionDispatch:s}),t&&t(x)},"data-kubuild-node":a,...c,children:m})};function Ft(r){return r?r.replace(/[-_](\w)/g,(e,i)=>i.toUpperCase()).replace(/^\w/,e=>e.toUpperCase()):""}function At(r){if(!r||typeof r!="string")return null;let e=r.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i);return e?e[1]:null}function Dt(r){if(!r||typeof r!="string")return null;let e=r.match(/(?:vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|))(\d+)/i);return e?e[3]:null}function Ot(r){if(r==="16:9")return"16 / 9";if(r==="4:3")return"4 / 3";if(r==="1:1")return"1 / 1";if(r==="9:16")return"9 / 16";if(typeof r=="string"&&r!=="auto")return r.replace(":"," / ")}import{jsx as C,jsxs as U}from"react/jsx-runtime";function Kn(r){let{node:e,document:i,definition:o,resolvedProps:n,styles:t,context:l,childrenElements:f,handleClick:p}=r;if(o?.renderer&&typeof o.renderer=="function"){let u=o.renderer;return typeof u=="function"&&!u.prototype?.isReactComponent?u({node:e,document:i,props:n,styles:t,context:l,children:f,onClick:p}):C(u,{node:e,document:i,props:n,styles:t,context:l,onClick:p,children:f})}return null}function Yn(r){let{node:e,domId:i,styles:o,resolvedProps:n,props:t,handleClick:l,childrenElements:f}=r;switch(e.type){case"page":return C("div",{id:i,style:o,onClick:l,"data-kubuild-node":e.id,children:f});case"section":{let p=typeof n.ariaLabel=="string"?n.ariaLabel:typeof t.ariaLabel=="string"?t.ariaLabel:void 0;return C("section",{id:i,style:o,onClick:l,"data-kubuild-node":e.id,"aria-label":p,children:f})}case"container":return C("div",{id:i,style:o,onClick:l,"data-kubuild-node":e.id,children:f});case"columns":return C("div",{id:i,style:o,onClick:l,"data-kubuild-node":e.id,children:f});default:return null}}function Xn(r){let{node:e,domId:i,styles:o,resolvedProps:n,props:t,mode:l,handleClick:f,onNodePropChange:p,childrenElements:u}=r;switch(e.type){case"heading":{let d=typeof n.level=="number"?n.level:1,s=`h${Math.min(Math.max(d,1),6)}`||"h1",a=String(n.text??n.content??t.text??t.content??""),c=l==="editor"&&!F(t.text)&&!F(t.content);return C(j,{as:s,id:i,style:o,value:a,isEditable:c,nodeId:e.id,onClick:f,onChange:(m,b)=>p?.(e.id,"text",m,b)})}case"text":{let d=String(n.text??n.content??t.text??t.content??""),s=typeof n.as=="string"?n.as:typeof t.as=="string"?t.as:typeof n.tag=="string"?n.tag:typeof t.tag=="string"?t.tag:(t.content!==void 0||n.content!==void 0)&&t.text===void 0&&n.text===void 0?"p":"span",a=l==="editor"&&!F(t.text)&&!F(t.content);return C(j,{as:s,id:i,style:o,value:d,isEditable:a,nodeId:e.id,onClick:f,onChange:(c,m)=>p?.(e.id,"text",c,m)})}case"paragraph":{let d=String(n.text??n.content??t.text??t.content??""),s=l==="editor"&&!F(t.text)&&!F(t.content);return C(j,{as:"p",id:i,style:o,value:d,isEditable:s,nodeId:e.id,onClick:f,onChange:(a,c)=>p?.(e.id,"text",a,c)})}case"link":{let d=String(n.text??n.label??n.content??t.text??t.label??t.content??""),s=typeof n.href=="string"?n.href:"#",a=typeof n.target=="string"?n.target:void 0,c=l==="editor"&&!F(t.text)&&!F(t.label)&&!F(t.content),m=typeof n.rel=="string"?n.rel:a==="_blank"?"noopener noreferrer":void 0,b=l==="editor"?void 0:Z(s,"#"),y=h=>{l==="editor"&&h.preventDefault(),f(h)};return c?C(j,{as:"a",id:i,style:o,value:d,isEditable:c,nodeId:e.id,onClick:y,onChange:(h,v)=>{let x="text"in t?"text":"label";p?.(e.id,x,h,v)},href:b,target:a,rel:m}):C("a",{id:i,style:o,href:b,target:a,rel:m,onClick:y,"data-kubuild-node":e.id,children:d})}case"blockquote":{let d=typeof n.quote=="string"?n.quote:typeof n.text=="string"?n.text:typeof t.quote=="string"?t.quote:typeof t.text=="string"?t.text:void 0,s=typeof n.cite=="string"?n.cite:typeof t.cite=="string"?t.cite:void 0,a=l==="editor"&&!F(t.quote)&&!F(t.text),c={borderLeft:"4px solid #cbd5e1",paddingLeft:"1rem",margin:"1rem 0",fontStyle:"italic",color:"#475569",...o};return U("blockquote",{id:i,style:c,onClick:f,"data-kubuild-node":e.id,cite:s,children:[d!==void 0?a?C(j,{as:"p",value:d,isEditable:a,nodeId:e.id,onChange:(m,b)=>{let y="quote"in t?"quote":"text";p?.(e.id,y,m,b)}}):C("p",{children:d}):null,u,s&&U("cite",{style:{display:"block",fontStyle:"normal",fontSize:"0.875rem",marginTop:"0.5rem",color:"#64748b"},children:["\u2014 ",s]})]})}case"badge":{let d=String(n.text??n.label??t.text??t.label??""),s=typeof n.variant=="string"?n.variant:typeof t.variant=="string"?t.variant:"default",a=l==="editor"&&!F(t.text)&&!F(t.label);return C("span",{id:i,style:o,onClick:f,"data-kubuild-node":e.id,"data-variant":s,"data-badge-variant":s,children:a?C(j,{as:"span",value:d,isEditable:a,nodeId:e.id,onChange:(c,m)=>{let b="text"in t?"text":"label";p?.(e.id,b,c,m)}}):d})}case"code-block":{let d=String(n.code??t.code??""),s=typeof n.language=="string"?n.language:typeof t.language=="string"?t.language:"plaintext";return l==="editor"?C("pre",{id:i,style:o,onClick:f,"data-kubuild-node":e.id,"data-language":s,children:C("code",{className:`language-${s}`,contentEditable:!0,suppressContentEditableWarning:!0,onBlur:a=>p?.(e.id,"code",a.currentTarget.textContent??"",!0),children:d})}):C("pre",{id:i,style:o,onClick:f,"data-kubuild-node":e.id,"data-language":s,children:C("code",{className:`language-${s}`,children:d})})}default:return null}}function Gn(r){let{node:e,domId:i,styles:o,resolvedProps:n,props:t,mode:l,handleClick:f,onNodePropChange:p,childrenElements:u}=r;switch(e.type){case"list":{let s=(n.tag||t.tag)==="ol"||n.ordered===!0||t.ordered===!0?"ol":"ul",a=typeof n.listStyleType=="string"?n.listStyleType:typeof n.listStyle=="string"?n.listStyle:typeof t.listStyleType=="string"?t.listStyleType:typeof t.listStyle=="string"?t.listStyle:void 0,c=a==="custom-icon"||a==="none"?"none":a,m={...o,...c?{listStyleType:c}:{}};return C(s,{id:i,style:m,onClick:f,"data-kubuild-node":e.id,"data-list-style":a,children:u})}case"list-item":{let d=n.text!==void 0?String(n.text):t.text!==void 0?String(t.text):void 0,s=l==="editor"&&!F(t.text)&&d!==void 0;return U("li",{id:i,style:o,onClick:f,"data-kubuild-node":e.id,children:[d!==void 0&&(s?C(j,{as:"span",value:d,isEditable:s,nodeId:e.id,onChange:(a,c)=>p?.(e.id,"text",a,c)}):d),u]})}default:return null}}function Jn(r){let{node:e,domId:i,styles:o,resolvedProps:n,props:t,mode:l,handleClick:f,onNodePropChange:p,childrenElements:u}=r;switch(e.type){case"table":{let d=typeof n.cellPadding=="number"?n.cellPadding:void 0,s=typeof n.cellSpacing=="number"?n.cellSpacing:void 0,a=typeof n.border=="number"?n.border:void 0,c=n.striped===!0||t.striped===!0,m=n.bordered===!0||t.bordered===!0,b=n.hover===!0||t.hover===!0,y=n.compact===!0||t.compact===!0;return C("table",{id:i,style:o,cellPadding:d,cellSpacing:s,border:a,onClick:f,"data-kubuild-node":e.id,"data-striped":c?"true":void 0,"data-bordered":m?"true":void 0,"data-hover":b?"true":void 0,"data-compact":y?"true":void 0,children:C("tbody",{children:u})})}case"table-row":return C("tr",{id:i,style:o,onClick:f,"data-kubuild-node":e.id,children:u});case"table-cell":{let s=n.tag==="th"||t.tag==="th"||n.isHeader===!0||t.isHeader===!0||n.cellType==="header"||t.cellType==="header"||n.type==="th"||t.type==="th"?"th":"td",a=typeof n.colSpan=="number"?n.colSpan:typeof t.colSpan=="number"?t.colSpan:void 0,c=typeof n.rowSpan=="number"?n.rowSpan:typeof t.rowSpan=="number"?t.rowSpan:void 0,m=n.text!==void 0?String(n.text):t.text!==void 0?String(t.text):void 0,b=l==="editor"&&!F(t.text)&&m!==void 0;return U(s,{id:i,colSpan:a,rowSpan:c,style:o,onClick:f,"data-kubuild-node":e.id,children:[m!==void 0&&(b?C(j,{as:"span",value:m,isEditable:b,nodeId:e.id,onChange:(y,h)=>p?.(e.id,"text",y,h)}):m),u]})}default:return null}}function Zn(r){let{node:e,domId:i,styles:o,resolvedProps:n,props:t,context:l,mode:f,handleClick:p}=r;switch(e.type){case"image":{let u=n.src!==void 0?n.src:t.src!==void 0?t.src:t.asset,d;qn(u)?d=Re(l?.assetProvider,u.assetId)||u.fallbackUrl:typeof u=="string"&&(d=Re(l?.assetProvider,u)||u);let s=typeof n.alt=="string"?n.alt:typeof t.alt=="string"?t.alt:"",a=typeof n.fit=="string"?n.fit:void 0,c=n.loading==="eager"?"eager":"lazy",m=typeof n.width=="number"?n.width:void 0,b=typeof n.height=="number"?n.height:void 0,y=d?Z(d,""):void 0,h={...o,...a?{objectFit:a}:{}};return C("img",{id:i,src:y,alt:s,role:s===""?"presentation":void 0,loading:c,width:m,height:b,style:h,onClick:p,"data-kubuild-node":e.id})}case"video":{let u=n.src??n.url??t.src??t.url,d=typeof u=="string"?u:void 0,s=typeof n.poster=="string"?n.poster:void 0,a=n.controls!==!1,c=n.autoplay===!0,m=n.loop===!0,b=n.muted===!0,y=n.playsInline!==!1,h=n.aspectRatio,v={position:"relative",width:o.width||"100%",...h?{aspectRatio:Ot(h)}:{},...o},x=d?At(d):null,g=d?Dt(d):null;if(x){let $=`https://www.youtube.com/embed/${x}?autoplay=${c?1:0}&loop=${m?1:0}&mute=${b?1:0}&controls=${a?1:0}`,S=Z($,"");return C("div",{id:i,"data-video-provider":"youtube",style:v,onClick:p,"data-kubuild-node":e.id,children:C("iframe",{src:S,title:"YouTube video player",style:{width:"100%",height:"100%",border:0},allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",allowFullScreen:!0})})}if(g){let $=`https://player.vimeo.com/video/${g}?autoplay=${c?1:0}&loop=${m?1:0}&muted=${b?1:0}`,S=Z($,"");return C("div",{id:i,"data-video-provider":"vimeo",style:v,onClick:p,"data-kubuild-node":e.id,children:C("iframe",{src:S,title:"Vimeo video player",style:{width:"100%",height:"100%",border:0},allow:"autoplay; fullscreen; picture-in-picture",allowFullScreen:!0})})}let w=d?Z(d,""):void 0,R=s?Z(s,""):void 0;return C("video",{id:i,src:w,poster:R,controls:a,autoPlay:c,loop:m,muted:b,playsInline:y,style:v,onClick:p,"data-kubuild-node":e.id})}case"icon":{let u=typeof n.name=="string"?n.name:"Square",d=typeof n.size=="number"?n.size:24,s=typeof n.color=="string"?n.color:"currentColor",a=typeof n.strokeWidth=="number"?n.strokeWidth:2,c=Ft(u),m=Vt[c]||Vt[u]||_n;return C("span",{id:i,"data-icon-name":u,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",...o},onClick:p,"data-kubuild-node":e.id,children:C(m,{size:d,color:s,strokeWidth:a})})}case"html-embed":{let u=typeof n.html=="string"?n.html:"",s=n.sanitize!==!1?Wn(u):u;return!s.trim()&&f==="editor"?C("div",{id:i,style:{...o,minHeight:"60px",border:"1px dashed #94a3b8",borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f8fafc",color:"#64748b",fontSize:"0.875rem"},onClick:p,"data-kubuild-node":e.id,children:C("span",{children:"</> HTML Embed \u2014 Click to configure HTML code in Inspector Panel"})}):C(kt,{id:i,style:o,html:s,onClick:p,dataKubuildNode:e.id})}default:return null}}function Qn(r){let{node:e,domId:i,styles:o,resolvedProps:n,props:t,context:l,mode:f,document:p,onDiagnostic:u,onActionDispatch:d,handleClick:s,onNodePropChange:a,childrenElements:c}=r;switch(e.type){case"button":{let m=String(n.label??n.text??n.content??t.label??t.text??t.content??"Button"),b=typeof n.href=="string"?n.href:typeof t.href=="string"?t.href:void 0,y=typeof n.target=="string"?n.target:typeof t.target=="string"?t.target:void 0,h=n.buttonType??n.type??t.buttonType??t.type,v=typeof h=="string"&&["submit","reset","button"].includes(h)?h:"button",x=n.disabled===!0||t.disabled===!0,g=typeof n.ariaLabel=="string"?n.ariaLabel:void 0,w=f==="editor"&&!F(t.label)&&!F(t.text),R=typeof n.rel=="string"?n.rel:typeof t.rel=="string"?t.rel:y==="_blank"?"noopener noreferrer":void 0,$={};if(t.action&&!x){let S=typeof t.action=="object"?t.action.type:t.action;if($["data-kubuild-action"]=S,l?.actionRegistry){let E=Xe(l.actionRegistry,S);$["data-kubuild-action-resolved"]=E?"true":"false"}}if(b&&!x){let S=f==="editor"?void 0:Z(b,"#");return C("a",{id:i,href:S,target:y,rel:R,tabIndex:0,style:o,onClick:s,"data-kubuild-node":e.id,"aria-label":g,...$,children:m})}return w?C(j,{as:"button",id:i,type:f==="editor"?"button":v,disabled:x,"aria-disabled":x?!0:void 0,"aria-label":g,tabIndex:x?-1:0,style:o,value:m,isEditable:w,nodeId:e.id,onClick:x?void 0:s,onChange:(S,E)=>a?.(e.id,"label",S,E),...$}):C(It,{id:i,buttonType:f==="editor"?"button":v,disabled:x,ariaLabel:g,style:o,onClick:x?void 0:s,actions:e.actions,node:e,document:p,renderContext:l,onDiagnostic:u,onActionDispatch:d,dataKubuildNode:e.id,actionAttrs:$,children:m})}case"form":{let m=typeof n.action=="string"?n.action:void 0,b=typeof n.method=="string"?n.method:"POST",y=typeof n.target=="string"?n.target:void 0,h=typeof n.autoComplete=="string"?n.autoComplete:void 0,v=typeof n.name=="string"?n.name:void 0,x=e.formConfig,g={formId:x?.formId||t.formId||v||e.id,resetOnSubmit:n.resetOnSubmit===!0||(x?.resetOnSubmit??!1),scrollToFirstError:n.scrollToFirstError!==!1&&(x?.scrollToFirstError??!0),validateOn:n.validateOn||x?.validateOn||"blur",initialValues:n.initialValues||x?.initialValues};return C(ht,{formId:g.formId,formConfig:g,initialValues:g.initialValues,actions:e.actions,nodeId:e.id,document:p,onDiagnostic:u,children:C(wt,{id:i,name:v,action:m&&f!=="editor"?Z(m,""):void 0,method:b,target:y,autoComplete:h,style:o,onClick:s,mode:f,dataKubuildNode:e.id,children:c})})}case"input":{let m=typeof n.name=="string"?n.name:void 0,b=typeof n.type=="string"?n.type:"text",y=typeof n.placeholder=="string"?n.placeholder:void 0,h=n.defaultValue!==void 0?n.defaultValue:void 0,v=n.required===!0,x=n.disabled===!0,g=n.readOnly===!0,w=e.formConfig?.rules||n.rules||t.rules||[],R=n.validateOn||t.validateOn,$=n.transform||t.transform;return C(St,{id:i,name:m,type:b,placeholder:y,defaultValue:h,required:v,disabled:x,readOnly:g,rules:w,validateOn:R,transform:$,style:o,onClick:s,actions:e.actions,nodeId:e.id,document:p,renderContext:l,onDiagnostic:u,onActionDispatch:d,dataKubuildNode:e.id})}case"textarea":{let m=typeof n.name=="string"?n.name:void 0,b=typeof n.placeholder=="string"?n.placeholder:void 0,y=n.defaultValue!==void 0?n.defaultValue:void 0,h=typeof n.rows=="number"?n.rows:4,v=n.required===!0,x=n.disabled===!0,g=n.readOnly===!0,w=e.formConfig?.rules||n.rules||t.rules||[],R=n.validateOn||t.validateOn,$=n.transform||t.transform;return C(Tt,{id:i,name:m,placeholder:b,defaultValue:y,rows:h,required:v,disabled:x,readOnly:g,rules:w,validateOn:R,transform:$,style:o,onClick:s,actions:e.actions,nodeId:e.id,document:p,renderContext:l,onDiagnostic:u,onActionDispatch:d,dataKubuildNode:e.id})}case"select":{let m=typeof n.name=="string"?n.name:void 0,b=typeof n.placeholder=="string"?n.placeholder:void 0,y=n.defaultValue!==void 0?n.defaultValue:void 0,h=n.required===!0,v=n.disabled===!0,x=e.formConfig?.rules||n.rules||t.rules||[],g=n.validateOn||t.validateOn,w=[],R=n.options??t.options;if(Array.isArray(R))w=R.map($=>{if(typeof $=="object"&&$!==null){let S=$;return{label:String(S.label??S.value??""),value:String(S.value??S.label??"")}}return{label:String($),value:String($)}});else if(typeof R=="string")try{let $=JSON.parse(R);Array.isArray($)&&(w=$.map(S=>{if(typeof S=="object"&&S!==null){let E=S;return{label:String(E.label??E.value??""),value:String(E.value??E.label??"")}}return{label:String(S),value:String(S)}}))}catch{}return C(Et,{id:i,name:m,placeholder:b,defaultValue:y,required:h,disabled:v,rules:x,validateOn:g,optionsList:w,style:o,onClick:s,actions:e.actions,nodeId:e.id,document:p,renderContext:l,onDiagnostic:u,onActionDispatch:d,dataKubuildNode:e.id})}case"checkbox":{let m=typeof n.name=="string"?n.name:void 0,b=String(n.label??"Checkbox"),y=n.value!==void 0?String(n.value):"yes",h=n.defaultChecked===!0,v=n.required===!0,x=n.disabled===!0,g=e.formConfig?.rules||n.rules||t.rules||[],w=n.validateOn||t.validateOn,R=f==="editor"&&!F(t.label);return C(Pt,{id:i,name:m,label:b,value:y,defaultChecked:h,required:v,disabled:x,rules:g,validateOn:w,style:o,onClick:s,actions:e.actions,nodeId:e.id,document:p,renderContext:l,onDiagnostic:u,onActionDispatch:d,dataKubuildNode:e.id,isEditable:R,onNodePropChange:a})}case"radio":{let m=typeof n.name=="string"?n.name:void 0,b=String(n.label??"Radio"),y=n.value!==void 0?String(n.value):"option",h=n.defaultChecked===!0,v=n.required===!0,x=n.disabled===!0,g=n.rules||t.rules||[],w=n.validateOn||t.validateOn,R=f==="editor"&&!F(t.label);return C(Nt,{id:i,name:m,label:b,value:y,defaultChecked:h,required:v,disabled:x,rules:g,validateOn:w,style:o,onClick:s,actions:e.actions,nodeId:e.id,document:p,renderContext:l,onDiagnostic:u,onActionDispatch:d,dataKubuildNode:e.id,isEditable:R,onNodePropChange:a})}default:return null}}function eo(r){let{node:e,domId:i,styles:o,props:n,context:t,mode:l,handleClick:f,onDiagnostic:p,renderChildNode:u}=r;if(e.type!=="collection")return null;let d=typeof n.sourceKey=="string"?n.sourceKey:void 0,s=typeof n.itemAlias=="string"&&n.itemAlias.length>0?n.itemAlias:"item",a=`${s}Index`,c=d?Un({key:d},t).value:void 0;if(!Array.isArray(c)){let b={code:"INVALID_COLLECTION_SOURCE",nodeId:e.id,propName:"sourceKey",message:`Collection node "${e.id}" expected an array at variable path "${d??"(missing sourceKey)"}" but found ${c===void 0?"nothing":typeof c}.`};return p?.(b),t?.onDiagnostic?.(b),l==="editor"?U("div",{id:i,"data-kubuild-node":e.id,"data-kubuild-collection-invalid":e.type,style:{...o,border:"2px dashed #f59e0b",backgroundColor:"#fffbeb",padding:"12px",color:"#b45309",fontSize:"0.875rem",borderRadius:"4px"},onClick:f,children:[U("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[C(zn,{size:16}),C("strong",{children:"Collection: expected an array"})]}),U("div",{children:["Source path ",C("code",{children:d??"(none)"})," did not resolve to an array. Found"," ",C("code",{children:c===void 0?"nothing":typeof c}),"."]})]}):C("div",{id:i,"data-kubuild-node":e.id,style:{display:"contents"},"data-kubuild-empty-collection":"invalid-source"})}let m=e.children||[];return m.length===0||c.length===0?C("div",{id:i,style:o,onClick:f,"data-kubuild-node":e.id,"data-kubuild-collection-empty":c.length===0?"true":void 0,children:c.length===0&&l==="editor"&&U("div",{style:{padding:"12px",border:"1px dashed #cbd5e1",borderRadius:"4px",color:"#94a3b8",fontSize:"0.875rem",textAlign:"center"},children:["Empty Collection (",C("code",{children:d})," has 0 items)"]})}):C("div",{id:i,style:o,onClick:f,"data-kubuild-node":e.id,children:c.map((b,y)=>{let h={...t,variables:{...t.variables,[s]:b,[a]:y}},v=`__iter_${y}`;return C(Ln.Fragment,{children:m.map(x=>u(x,v,h))},`collection-item-${y}`)})})}function to(r){let{node:e,domId:i,styles:o,handleClick:n,mode:t,childrenElements:l}=r;return t==="editor"?U("div",{id:i,style:{...o,border:"2px dashed #e2e8f0",padding:"16px",backgroundColor:"#f8fafc"},onClick:n,"data-kubuild-node":e.id,"data-kubuild-unknown":e.type,children:[U("div",{style:{display:"flex",alignItems:"center",gap:"8px",color:"#64748b"},children:[C(jn,{size:16}),U("span",{children:["Unknown Component: ",e.type]}),U("span",{style:{fontSize:"12px",color:"#94a3b8"},children:["(",e.id,")"]})]}),l]}):C("div",{id:i,style:o,onClick:n,"data-kubuild-node":e.id,"data-kubuild-unknown":e.type,children:l})}function Mt(r){let e=Kn(r);if(e)return e;let i=Yn(r);if(i)return i;let o=Xn(r);if(o)return o;let n=Gn(r);if(n)return n;let t=Jn(r);if(t)return t;let l=Zn(r);if(l)return l;let f=Qn(r);if(f)return f;let p=eo(r);return p||to(r)}import{jsx as W,jsxs as ce}from"react/jsx-runtime";function Ie({node:r,document:e,registry:i,context:o,viewport:n="desktop",mode:t="runtime",onNodeClick:l,onDiagnostic:f,onActionDispatch:p,onNodePropChange:u,instanceSuffix:d=""}){let s=o||ie,a=Je(r.styles,n),c=r.props||{},m=i.get(r.type),b=d?`${r.id}${d}`:r.id,{props:y,diagnostics:h}=tt(r,m,s);h.forEach(R=>{f?.(R),s?.onDiagnostic?.(R)}),$t(r,{document:e,context:s,onDiagnostic:f,onActionDispatch:p,mode:t});let v=async R=>{R.stopPropagation(),l&&l(r.id,R),r.actions&&r.actions.length>0&&!c.disabled&&await D({node:r,trigger:"click",document:e,context:s,onDiagnostic:f,onActionDispatch:p}),c.action&&!c.disabled&&(Ge({action:c.action,nodeId:r.id,document:e,context:s,onDiagnostic:f}),p&&no(c.action)&&p(c.action.type,Ye(s,c.action.payload),r.id))},x=r.children?.map(R=>W(Ie,{node:R,document:e,registry:i,context:s,viewport:n,mode:t,onNodeClick:l,onDiagnostic:f,onActionDispatch:p,onNodePropChange:u,instanceSuffix:d},`${R.id}${d}`)),g=(R,$="",S=s)=>W(Ie,{node:R,document:e,registry:i,context:S,viewport:n,mode:t,onNodeClick:l,onDiagnostic:f,onActionDispatch:p,onNodePropChange:u,instanceSuffix:`${d}${$}`},`${R.id}${d}${$}`),w;try{w=Mt({node:r,document:e,registry:i,context:s,viewport:n,mode:t,styles:a,props:c,resolvedProps:y,definition:m,domId:b,childrenElements:x,handleClick:v,onNodeClick:l,onDiagnostic:f,onActionDispatch:p,onNodePropChange:u,instanceSuffix:d,renderChildNode:g})}catch(R){t==="editor"?w=ce("div",{"data-kubuild-node":r.id,"data-kubuild-error":r.type,style:{padding:"12px 16px",margin:"4px 0",backgroundColor:"#fef2f2",border:"1px solid #ef4444",borderRadius:"6px",color:"#b91c1c",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"13px",lineHeight:"1.4"},children:[ce("div",{style:{fontWeight:600,marginBottom:"4px",display:"flex",alignItems:"center",gap:"6px"},children:[W(ro,{size:14,"aria-hidden":"true"}),ce("span",{children:["Component Render Error: <",r.type,">"]})]}),ce("div",{style:{fontSize:"11px",color:"#7f1d1d",wordBreak:"break-all"},children:["Node ID: ",W("code",{children:r.id})," \u2014 ",R instanceof Error?R.message:String(R)]})]}):w=W("div",{"data-kubuild-node":r.id,"data-kubuild-error":r.type,style:{display:"none"},"aria-hidden":"true"})}return W(be,{nodeId:r.id,componentType:r.type,mode:t,onDiagnostic:f,children:w})}var Ht=({document:r,registry:e=oo(),context:i,viewport:o="desktop",mode:n="runtime",className:t,showToastContainer:l=!0,onNodeClick:f,onDiagnostic:p,onActionDispatch:u,onNodePropChange:d})=>!r||!r.document?W("div",{className:t,children:"Empty Document"}):W(ze,{value:i,children:ce("div",{className:`kubuild-canvas-root ${t||""}`,children:[(()=>{let s=Ze(r);return s?W("style",{"data-kubuild-state-styles":!0,children:s}):null})(),(()=>{let s=me(r);return s?W("style",{"data-kubuild-animation-styles":!0,children:s}):null})(),W(Ie,{node:r.document,document:r,registry:e,context:i,viewport:o,mode:n,onNodeClick:f,onDiagnostic:p,onActionDispatch:u,onNodePropChange:d}),l&&W(ft,{})]})});import{useMemo as Fe}from"react";import{jsx as ee,jsxs as ve}from"react/jsx-runtime";var Bt=Object.freeze({desktop:{width:"100%",maxWidth:"1280px",minHeight:"600px",label:"Desktop (1280px)",isFluid:!0},tablet:{width:"768px",height:"1024px",minHeight:"600px",label:"Tablet (768 \xD7 1024)",isFluid:!1},mobile:{width:"375px",height:"667px",minHeight:"500px",label:"Mobile (375 \xD7 667)",isFluid:!1}}),io=Object.freeze({mobile:480,tablet:768,desktop:1024});function Ai(r,e){let i={...io,...e};return r<=i.mobile?"mobile":r<=i.tablet?"tablet":"desktop"}function Lt(r,e){let i=Bt[r]||Bt.desktop,o=e?.[r];return{...i,...o}}function so(r,e,i){let o=Lt(r,e),n=i??o.scale??1,t=f=>typeof f=="number"?`${f}px`:f,l={width:t(o.width),maxWidth:t(o.maxWidth),minWidth:t(o.minWidth),height:t(o.height),minHeight:t(o.minHeight),maxHeight:t(o.maxHeight),aspectRatio:o.aspectRatio,transition:"width 0.2s ease, max-width 0.2s ease, height 0.2s ease"};return n!==1&&(l.transform=`scale(${n})`,l.transformOrigin="top center"),l}var ao=({document:r,viewport:e="desktop",onViewportChange:i,viewportConfigs:o,breakpoints:n,registry:t,context:l,mode:f="runtime",showChrome:p=!1,chromeTitle:u,editorOverlay:d,scale:s,className:a,style:c,canvasClassName:m,canvasStyle:b,onNodeClick:y,onDiagnostic:h,onActionDispatch:v})=>{let x=Fe(()=>Lt(e,o),[e,o]),g=Fe(()=>so(e,o,s),[e,o,s]),w=Fe(()=>({...g,...b,position:"relative",boxSizing:"border-box"}),[g,b]);return ve("div",{"data-kubuild-preview-container":!0,"data-viewport":e,className:`kubuild-preview-viewport-adapter ${a||""}`,style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",width:"100%",height:"100%",boxSizing:"border-box",...c},children:[p&&ve("div",{"data-kubuild-preview-chrome":!0,style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",maxWidth:g.maxWidth||g.width,padding:"8px 12px",marginBottom:"8px",backgroundColor:"#1e293b",color:"#f8fafc",borderRadius:"8px",fontSize:"12px",fontFamily:"system-ui, -apple-system, sans-serif",boxSizing:"border-box"},children:[ve("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[ee("span",{style:{fontWeight:600},children:u||r.metadata?.title||"Preview"}),ee("span",{"data-testid":"viewport-badge",style:{fontSize:"10px",padding:"2px 6px",borderRadius:"4px",backgroundColor:"#334155",color:"#94a3b8",textTransform:"uppercase",fontWeight:700},children:e}),ee("span",{style:{fontSize:"11px",color:"#64748b"},children:x.label||`${x.width} \xD7 ${x.height||"auto"}`})]}),i&&ee("div",{"data-testid":"viewport-switcher",style:{display:"flex",gap:"4px",backgroundColor:"#0f172a",padding:"2px",borderRadius:"6px"},children:["desktop","tablet","mobile"].map(R=>{let $=e===R;return ee("button",{type:"button","data-testid":`viewport-btn-${R}`,onClick:()=>i(R),style:{padding:"4px 10px",fontSize:"11px",fontWeight:500,borderRadius:"4px",border:"none",cursor:"pointer",textTransform:"capitalize",backgroundColor:$?"#3b82f6":"transparent",color:$?"#ffffff":"#94a3b8",transition:"all 0.15s ease"},children:R},R)})})]}),ve("div",{"data-kubuild-preview-canvas":!0,"data-viewport":e,className:`kubuild-preview-canvas ${m||""}`,style:w,children:[ee(Ht,{document:r,registry:t,context:l,viewport:e,mode:f,onNodeClick:y,onDiagnostic:h,onActionDispatch:v}),d&&ee("div",{"data-kubuild-preview-overlay":!0,style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none",zIndex:10},children:d})]})]})},Di=ao;function A(r){return r==null?"":String(r).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function T(r){return A(r)}function lo(r){if(!r||typeof r!="string")return null;let e=r.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i);return e?e[1]:null}function co(r){if(!r||typeof r!="string")return null;let e=r.match(/(?:vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|))(\d+)/i);return e?e[3]:null}function q(r,e,i){let o=" ".repeat(e*(i.indentSize??2)),n=" ".repeat((e+1)*(i.indentSize??2)),t=r.props||{},l=r.children||[],p=i.includeNodeClasses!==!1?`kb-node-${r.id}`:"",u=(...s)=>s.filter(Boolean).join(" "),d=t.id?` id="${T(t.id)}"`:"";switch(r.type){case"page":{let s=i.rootTag||"main",a=u("kb-page",p),c=l.map(m=>q(m,e+1,i)).join(`
121
+ `);return c?`${o}<${s} class="${a}"${d}>
122
+ ${c}
123
+ ${o}</${s}>`:`${o}<${s} class="${a}"${d}></${s}>`}case"section":{let s=t.ariaLabel?` aria-label="${T(t.ariaLabel)}"`:"",a=u("kb-section",p),c=l.map(m=>q(m,e+1,i)).join(`
124
+ `);return c?`${o}<section class="${a}"${d}${s}>
125
+ ${c}
126
+ ${o}</section>`:`${o}<section class="${a}"${d}${s}></section>`}case"container":{let s=u("kb-container",p),a=l.map(c=>q(c,e+1,i)).join(`
127
+ `);return a?`${o}<div class="${s}"${d}>
128
+ ${a}
129
+ ${o}</div>`:`${o}<div class="${s}"${d}></div>`}case"columns":{let s=u("kb-columns",p),a=l.map(c=>q(c,e+1,i)).join(`
130
+ `);return a?`${o}<div class="${s}"${d}>
131
+ ${a}
132
+ ${o}</div>`:`${o}<div class="${s}"${d}></div>`}case"heading":{let s="h2";typeof t.level=="string"&&/^h[1-6]$/i.test(t.level)?s=t.level.toLowerCase():typeof t.level=="number"&&t.level>=1&&t.level<=6?s=`h${t.level}`:typeof t.tag=="string"&&/^h[1-6]$/i.test(t.tag)&&(s=t.tag.toLowerCase());let a=t.text??t.value??t.content??"Heading",c=u("kb-heading",p);return`${o}<${s} class="${c}"${d}>${A(a)}</${s}>`}case"paragraph":{let s=t.text??t.value??t.content??"",a=u("kb-paragraph",p);return`${o}<p class="${a}"${d}>${A(s)}</p>`}case"text":{let s=t.as||"p",a=t.text??t.value??t.content??"",c=u("kb-text",p);return`${o}<${s} class="${c}"${d}>${A(a)}</${s}>`}case"link":{let s=t.href?` href="${T(t.href)}"`:' href="#"',a=t.target?` target="${T(t.target)}"`:"",c=t.rel?` rel="${T(t.rel)}"`:a.includes("_blank")?' rel="noopener noreferrer"':"",m=t.text??t.label??t.value,b=u("kb-link",p);if(l.length>0){let y=l.map(h=>q(h,e+1,i)).join(`
133
+ `);return`${o}<a class="${b}"${d}${s}${a}${c}>
134
+ ${y}
135
+ ${o}</a>`}return`${o}<a class="${b}"${d}${s}${a}${c}>${A(m??"Link")}</a>`}case"blockquote":{let s=t.cite?` cite="${T(t.cite)}"`:"",a=t.quote??t.text??t.value,c=t.author??t.citeAuthor,m=u("kb-blockquote",p);if(a||c){let b=a?`${n}<p>${A(a)}</p>`:"",y=c?`${n}<cite>${A(c)}</cite>`:"",h=[b,y].filter(Boolean).join(`
136
+ `);return`${o}<blockquote class="${m}"${d}${s}>
137
+ ${h}
138
+ ${o}</blockquote>`}if(l.length>0){let b=l.map(y=>q(y,e+1,i)).join(`
139
+ `);return`${o}<blockquote class="${m}"${d}${s}>
140
+ ${b}
141
+ ${o}</blockquote>`}return`${o}<blockquote class="${m}"${d}${s}></blockquote>`}case"badge":{let s=t.text??t.label??t.value??"Badge",a=u("kb-badge",p);return`${o}<span class="${a}"${d}>${A(s)}</span>`}case"code-block":{let s=t.code??t.text??t.value??"",a=t.language||t.lang,c=a?` class="language-${T(a)}"`:"",m=u("kb-code-block",p);return`${o}<pre class="${m}"${d}><code${c}>${A(s)}</code></pre>`}case"divider":{let s=u("kb-divider",p),a=t.text??t.label;return a?`${o}<div class="${s}"${d} role="separator"><span>${A(a)}</span></div>`:`${o}<hr class="${s}"${d} />`}case"spacer":{let s=u("kb-spacer",p);return`${o}<div class="${s}"${d} aria-hidden="true"></div>`}case"image":{let s=t.src?` src="${T(t.src)}"`:' src=""',a=t.alt?` alt="${T(t.alt)}"`:' alt=""',c=t.loading?` loading="${T(t.loading)}"`:' loading="lazy"',m=u("kb-image",p);return`${o}<img class="${m}"${d}${s}${a}${c} />`}case"video":{let s=t.src||"",a=lo(s),c=co(s),m=u("kb-video",p);if(a)return`${o}<div class="kb-video-wrapper ${p}"${d}>
142
+ ${n}<iframe src="https://www.youtube-nocookie.com/embed/${T(a)}" title="${T(t.title||"Video player")}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
143
+ ${o}</div>`;if(c)return`${o}<div class="kb-video-wrapper ${p}"${d}>
144
+ ${n}<iframe src="https://player.vimeo.com/video/${T(c)}" title="${T(t.title||"Video player")}" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
145
+ ${o}</div>`;let b=t.poster?` poster="${T(t.poster)}"`:"",y=t.controls!==!1?" controls":"",h=t.autoplay?" autoplay":"",v=t.loop?" loop":"",x=t.muted?" muted":"",g=s?` src="${T(s)}"`:"";return`${o}<video class="${m}"${d}${g}${b}${y}${h}${v}${x}></video>`}case"icon":{let s=t.name||t.icon||"star",a=t.ariaLabel?` aria-label="${T(t.ariaLabel)}"`:' aria-hidden="true"',c=u("kb-icon",p);return`${o}<span class="${c}"${d}${a} data-icon="${T(s)}"></span>`}case"html-embed":{let s=t.html??t.content??"",a=u("kb-html-embed",p);return s?`${o}<div class="${a}"${d}>
146
+ ${n}${s}
147
+ ${o}</div>`:`${o}<div class="${a}"${d}></div>`}case"button":{let s=t.label??t.text??t.value??"Button",a=t.type?` type="${T(t.type)}"`:' type="button"',c=t.disabled?" disabled":"",m=u("kb-button",p);if(t.href){let b=` href="${T(t.href)}"`,y=t.target?` target="${T(t.target)}"`:"";return`${o}<a class="${m}"${d}${b}${y}>${A(s)}</a>`}return`${o}<button class="${m}"${d}${a}${c}>${A(s)}</button>`}case"form":{let s=t.action?` action="${T(t.action)}"`:"",a=t.method?` method="${T(t.method)}"`:' method="POST"',c=u("kb-form",p),m=l.map(b=>q(b,e+1,i)).join(`
148
+ `);return m?`${o}<form class="${c}"${d}${s}${a}>
149
+ ${m}
150
+ ${o}</form>`:`${o}<form class="${c}"${d}${s}${a}></form>`}case"input":{let s=t.type?` type="${T(t.type)}"`:' type="text"',a=t.name?` name="${T(t.name)}"`:"",c=t.placeholder?` placeholder="${T(t.placeholder)}"`:"",m=t.value!==void 0?` value="${T(t.value)}"`:"",b=t.required?" required":"",y=t.disabled?" disabled":"",h=u("kb-input",p);return`${o}<input class="${h}"${d}${s}${a}${c}${m}${b}${y} />`}case"textarea":{let s=t.name?` name="${T(t.name)}"`:"",a=t.placeholder?` placeholder="${T(t.placeholder)}"`:"",c=t.rows?` rows="${T(t.rows)}"`:' rows="4"',m=t.value??t.defaultValue??"",b=t.required?" required":"",y=t.disabled?" disabled":"",h=u("kb-textarea",p);return`${o}<textarea class="${h}"${d}${s}${a}${c}${b}${y}>${A(m)}</textarea>`}case"select":{let s=t.name?` name="${T(t.name)}"`:"",a=t.required?" required":"",c=t.disabled?" disabled":"",m=u("kb-select",p),b=Array.isArray(t.options)?t.options:[],y=" ".repeat((e+1)*(i.indentSize??2)),h=b.map(v=>{let x=typeof v=="object"?v.value:v,g=typeof v=="object"?v.label:v,w=t.value===x||t.defaultValue===x?" selected":"";return`${y}<option value="${T(x)}"${w}>${A(g)}</option>`}).join(`
151
+ `);return h?`${o}<select class="${m}"${d}${s}${a}${c}>
152
+ ${h}
153
+ ${o}</select>`:`${o}<select class="${m}"${d}${s}${a}${c}></select>`}case"checkbox":{let s=t.name?` name="${T(t.name)}"`:"",a=t.checked||t.defaultChecked?" checked":"",c=t.label??t.text??"",m=u("kb-checkbox-label",p);return`${o}<label class="${m}"${d}><input type="checkbox"${s}${a} /><span>${A(c)}</span></label>`}case"radio":{let s=t.name?` name="${T(t.name)}"`:"",a=t.value?` value="${T(t.value)}"`:"",c=t.checked||t.defaultChecked?" checked":"",m=t.label??t.text??"",b=u("kb-radio-label",p);return`${o}<label class="${b}"${d}><input type="radio"${s}${a}${c} /><span>${A(m)}</span></label>`}case"list":{let s=t.tag==="ol"||t.type==="ol"||t.ordered?"ol":"ul",a=u("kb-list",p),c=l.map(m=>q(m,e+1,i)).join(`
154
+ `);return c?`${o}<${s} class="${a}"${d}>
155
+ ${c}
156
+ ${o}</${s}>`:`${o}<${s} class="${a}"${d}></${s}>`}case"list-item":{let s=t.text??t.value,a=u("kb-list-item",p);if(l.length>0){let c=l.map(m=>q(m,e+1,i)).join(`
157
+ `);return`${o}<li class="${a}"${d}>
158
+ ${c}
159
+ ${o}</li>`}return`${o}<li class="${a}"${d}>${A(s??"List item")}</li>`}case"table":{let s=u("kb-table",p),a=l.map(c=>q(c,e+1,i)).join(`
160
+ `);return a?`${o}<table class="${s}"${d}>
161
+ ${a}
162
+ ${o}</table>`:`${o}<table class="${s}"${d}></table>`}case"table-row":{let s=u("kb-table-row",p),a=l.map(c=>q(c,e+1,i)).join(`
163
+ `);return a?`${o}<tr class="${s}"${d}>
164
+ ${a}
165
+ ${o}</tr>`:`${o}<tr class="${s}"${d}></tr>`}case"table-cell":{let a=t.isHeader||t.type==="header"||t.tag==="th"?"th":"td",c=t.colSpan&&Number(t.colSpan)>1?` colspan="${T(t.colSpan)}"`:"",m=t.rowSpan&&Number(t.rowSpan)>1?` rowspan="${T(t.rowSpan)}"`:"",b=t.text??t.value??"",y=u("kb-table-cell",p);if(l.length>0){let h=l.map(v=>q(v,e+1,i)).join(`
166
+ `);return`${o}<${a} class="${y}"${d}${c}${m}>
167
+ ${h}
168
+ ${o}</${a}>`}return`${o}<${a} class="${y}"${d}${c}${m}>${A(b)}</${a}>`}case"collection":{let s=u("kb-collection",p),a=l.map(c=>q(c,e+1,i)).join(`
169
+ `);return a?`${o}<div class="${s}"${d}>
170
+ ${a}
171
+ ${o}</div>`:`${o}<div class="${s}"${d}></div>`}default:{let s=u(`kb-${r.type}`,p),a=l.map(c=>q(c,e+1,i)).join(`
172
+ `);return a?`${o}<div class="${s}"${d}>
173
+ ${a}
174
+ ${o}</div>`:`${o}<div class="${s}"${d}></div>`}}}function uo(r,e={}){let i="document"in r?r.document:r;return i?q(i,0,e):""}function xe(r,e,i=""){if(!e.trim())return"";let o=e.split(";").map(t=>t.trim()).filter(Boolean);if(o.length===0)return"";let n=o.map(t=>`${i} ${t};`).join(`
175
+ `);return`${i}${r} {
176
+ ${n}
177
+ ${i}}`}function po(r,e={}){let i="document"in r?r.document:r;if(!i)return"";let o=e.classPrefix||"kb-node-",n=[],t=[],l=[],f=[],p=a=>{let c=`.${o}${a.id}`;if(a.styles){let m={...a.styles.base||{},...a.styles.desktop||{}},b=te(m);if(b&&n.push(xe(c,b)),a.styles.tablet){let y=te(a.styles.tablet);y&&t.push(xe(c,y," "))}if(a.styles.mobile){let y=te(a.styles.mobile);y&&l.push(xe(c,y," "))}if(a.styles.states&&typeof a.styles.states=="object")for(let[y,h]of Object.entries(a.styles.states)){if(!h)continue;let v=/^::?[a-zA-Z-]+$/.test(y)?y:null;if(!v)continue;let x=te(h);x&&f.push(xe(`${c}${v}`,x))}}a.children?.forEach(p)};p(i);let u=[];e.includeReset!==!1&&u.push(`/* ==========================================================================
178
+ Baseline Reset & Typography Standards
179
+ ========================================================================== */
180
+ ${Qe}`),n.length>0&&u.push(`/* ==========================================================================
181
+ Component Styles
182
+ ========================================================================== */
183
+ ${n.join(`
184
+
185
+ `)}`),f.length>0&&u.push(`/* ==========================================================================
186
+ Interactive & Hover States
187
+ ========================================================================== */
188
+ ${f.join(`
189
+
190
+ `)}`),t.length>0&&u.push(`/* ==========================================================================
191
+ Tablet Breakpoint (max-width: 1024px)
192
+ ========================================================================== */
193
+ @media (max-width: 1024px) {
194
+ ${t.join(`
195
+
196
+ `)}
197
+ }`),l.length>0&&u.push(`/* ==========================================================================
198
+ Mobile Breakpoint (max-width: 640px)
199
+ ========================================================================== */
200
+ @media (max-width: 640px) {
201
+ ${l.join(`
202
+
203
+ `)}
204
+ }`);let d="document"in r?r:{schema:"stora.page",version:"1.0.0",document:i},s=me(d);return s&&u.push(`/* ==========================================================================
205
+ Animations & Motion Keyframes
206
+ ========================================================================== */
207
+ ${s}`),u.join(`
208
+
209
+ `)}function Bi(r,e={}){let i=A(r.metadata?.title||"KUBUILD Page"),o=r.metadata?.description?T(r.metadata.description):"",n=r.metadata?.author?T(r.metadata.author):"",t=e.lang||"en",l=po(r,e.cssOptions),f=uo(r,e.htmlOptions),p=o?` <meta name="description" content="${o}">
210
+ `:"",u=n?` <meta name="author" content="${n}">
211
+ `:"";return`<!DOCTYPE html>
212
+ <html lang="${t}">
213
+ <head>
214
+ <meta charset="UTF-8">
215
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
216
+ <title>${i}</title>
217
+ ${p}${u} <style>
218
+ ${l}
219
+ </style>
220
+ </head>
221
+ <body>
222
+ ${f}
223
+ </body>
224
+ </html>`}export{Gt as ANIMATION_KEYFRAMES_CSS,J as ApiRequestError,be as ComponentErrorBoundary,io as DEFAULT_BREAKPOINTS,Qe as DEFAULT_CSS_RESET,ie as DEFAULT_RENDER_CONTEXT,Bt as DEFAULT_VIEWPORT_CONFIGS,j as EditableText,Pt as FormCheckboxNode,wt as FormContainerNode,St as FormInputNode,Nt as FormRadioNode,Ne as FormRuntimeContext,ht as FormRuntimeProvider,Et as FormSelectNode,It as FormSubmitButtonNode,Tt as FormTextareaNode,kt as HtmlEmbedView,Di as KubuildPreviewViewport,Ht as KubuildRenderer,Ee as ModalManager,Ie as NodeRenderer,ao as PreviewViewportAdapter,ze as RenderContextProvider,Cn as ToastCard,ft as ToastContainer,Se as ToastManager,nt as apiRequestRunner,Ot as aspectRatioToCss,ln as buildApiUrl,lt as closeModalRunner,me as collectAnimationStylesCss,Ze as collectStateStylesCss,ct as copyClipboardRunner,gn as copyToClipboard,we as createApiRequestHandler,wn as createDefaultActionRunners,vo as createMinimalRenderContext,Wt as createRenderContext,Ge as dispatchAction,D as executeNodeActions,po as generateDocumentCss,uo as generateSemanticHtml,Bi as generateStandaloneHtml,Qt as getEntranceAnimationCss,Jt as getHoverEffectCss,Zt as getLoopEffectCss,Dt as getVimeoId,At as getYouTubeId,Xe as isActionRegistered,se as modalManager,dt as navigateRunner,at as openModalRunner,dn as prepareRequestBody,ye as registerDefaultActionRunners,eo as renderCollectionNode,Kn as renderCustomComponent,to as renderFallbackNode,Qn as renderFormNode,Yn as renderLayoutNode,Gn as renderListNode,Zn as renderMediaNode,Mt as renderNodeContent,Jn as renderTableNode,Xn as renderTypographyNode,Co as replayNodeAnimation,ut as resetFormRunner,Ye as resolveActionPayload,Ke as resolveActionPayloadDetailed,Re as resolveAssetSync,Je as resolveNodeStyles,We as resolveVariable,so as resolveViewportContainerStyle,Lt as resolveViewportDimensions,Ai as resolveViewportFromWidth,st as showToastRunner,te as styleDefinitionToCssDeclarations,Ft as toPascalCase,Q as toastManager,Mn as transformEmbedHtml,$r as useFormContext,Sr as useFormField,X as useFormRuntime,wr as useFormStatus,Yo as useModal,Xo as useModals,$t as useNodeLoadActions,Ue as useRenderContext,ot as useToasts};