veo-sdk 0.5.6 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/builder.cjs CHANGED
@@ -569,6 +569,42 @@ function applyBlockStyle(el, style, kind) {
569
569
  if (typeof s.marginBottom === "number" && Number.isFinite(s.marginBottom)) {
570
570
  el.style.marginBottom = `${clampNum(s.marginBottom, 0, 64)}px`;
571
571
  }
572
+ if (kind !== "image") {
573
+ if (typeof s.fontSize === "number" && Number.isFinite(s.fontSize)) {
574
+ el.style.fontSize = `${clampNum(s.fontSize, 8, 96)}px`;
575
+ }
576
+ if (typeof s.fontFamily === "string" && s.fontFamily && s.fontFamily !== "inherit") {
577
+ el.style.fontFamily = s.fontFamily;
578
+ }
579
+ if (typeof s.fontWeight === "string" && s.fontWeight) el.style.fontWeight = s.fontWeight;
580
+ if (typeof s.textTransform === "string" && s.textTransform && s.textTransform !== "none") {
581
+ el.style.textTransform = s.textTransform;
582
+ }
583
+ if (typeof s.lineHeight === "number" && Number.isFinite(s.lineHeight)) {
584
+ el.style.lineHeight = `${clampNum(s.lineHeight, 50, 300)}%`;
585
+ }
586
+ if (typeof s.letterSpacing === "number" && Number.isFinite(s.letterSpacing)) {
587
+ el.style.letterSpacing = `${clampNum(s.letterSpacing, -5, 20)}px`;
588
+ }
589
+ }
590
+ if (typeof s.background === "string" && s.background) el.style.background = s.background;
591
+ if (typeof s.borderWidth === "number" && s.borderWidth > 0) {
592
+ const bc = typeof s.borderColor === "string" && s.borderColor ? s.borderColor : "#bbbbbb";
593
+ el.style.border = `${clampNum(s.borderWidth, 0, 20)}px solid ${bc}`;
594
+ }
595
+ if (kind !== "image" && typeof s.radius === "number" && Number.isFinite(s.radius)) {
596
+ el.style.borderRadius = `${clampNum(s.radius, 0, 64)}px`;
597
+ }
598
+ for (const side of ["Top", "Right", "Bottom", "Left"]) {
599
+ const p = s[`padding${side}`];
600
+ if (typeof p === "number" && Number.isFinite(p)) {
601
+ el.style.setProperty(`padding-${side.toLowerCase()}`, `${clampNum(p, 0, 128)}px`);
602
+ }
603
+ const m = s[`margin${side}`];
604
+ if (typeof m === "number" && Number.isFinite(m)) {
605
+ el.style.setProperty(`margin-${side.toLowerCase()}`, `${clampNum(m, 0, 128)}px`);
606
+ }
607
+ }
572
608
  }
573
609
  function createCloseButton(doc, onClose, className = "veo-guide-close") {
574
610
  const closeBtn = doc.createElement("button");
@@ -1754,182 +1790,6 @@ var BannerRenderer = class extends BaseRenderer {
1754
1790
  function bannerClassOf(position, embedded) {
1755
1791
  return embedded ? "veo-banner veo-banner-embedded" : `veo-banner veo-banner-${position}`;
1756
1792
  }
1757
- var CompositeRenderer = class extends BaseRenderer {
1758
- async render(context) {
1759
- const idx = context.nav?.stepIndex ?? 0;
1760
- const step = context.guide.guideSteps[idx];
1761
- if (!step) return;
1762
- const anchorSelector = step.position === "relative-to-element" || step.presentation === "inline" ? step.anchorSelector?.trim() || void 0 : void 0;
1763
- let anchor = null;
1764
- if (anchorSelector) {
1765
- anchor = await waitForElement(anchorSelector);
1766
- if (!anchor) return;
1767
- }
1768
- const { host, root } = this.createHost();
1769
- const doc = root.ownerDocument ?? document;
1770
- const card = doc.createElement("div");
1771
- card.className = "veo-card";
1772
- applyCompositeDesign(card, step.design ?? {});
1773
- const dismiss = (action, meta) => {
1774
- context.onInteraction({
1775
- guideId: context.guide.guideId,
1776
- stepIndex: idx,
1777
- action,
1778
- ...meta?.id ? { metadata: { buttonId: meta.id } } : {}
1779
- });
1780
- };
1781
- const synthetic = { blocks: step.blocks ?? [] };
1782
- for (const node of buildContentNodes(synthetic, doc)) card.appendChild(node);
1783
- const buttons = (step.blocks ?? []).filter((b) => b.type === "button");
1784
- if (buttons.length) {
1785
- const row = doc.createElement("div");
1786
- row.className = "veo-guide-actions";
1787
- for (const b of buttons) row.appendChild(this.buildButton(b, doc, context, dismiss));
1788
- card.appendChild(row);
1789
- }
1790
- card.appendChild(
1791
- createCloseButton(doc, () => {
1792
- dismiss("dismissed");
1793
- this.closeOrSkip(context);
1794
- })
1795
- );
1796
- if (step.presentation === "inline" && anchor) {
1797
- host.style.display = "block";
1798
- const pos = inlinePosOf(step.inlinePosition);
1799
- root.appendChild(card);
1800
- insertHost(anchor, host, pos);
1801
- this.registerCleanup(keepHostAttached(host, anchorSelector, pos));
1802
- } else if (step.position === "relative-to-element" && anchor) {
1803
- const wrapper = doc.createElement("div");
1804
- wrapper.className = "veo-composite-anchored";
1805
- wrapper.appendChild(card);
1806
- root.appendChild(wrapper);
1807
- this.registerCleanup(await anchorPosition(anchor, wrapper));
1808
- } else {
1809
- const overlay = doc.createElement("div");
1810
- overlay.className = "veo-composite-overlay";
1811
- if (step.position === "center" && step.design?.backdrop !== false) {
1812
- overlay.classList.add("veo-composite-overlay--dim");
1813
- overlay.addEventListener("click", (e) => {
1814
- if (e.target === overlay) {
1815
- dismiss("dismissed");
1816
- this.closeOrSkip(context);
1817
- }
1818
- });
1819
- }
1820
- applyViewportPosition(card, step.position);
1821
- overlay.appendChild(card);
1822
- root.appendChild(overlay);
1823
- }
1824
- context.onInteraction({ guideId: context.guide.guideId, stepIndex: idx, action: "shown" });
1825
- }
1826
- /** Botón con enrutado de acción (navegación / cierre / url / guía). */
1827
- buildButton(block, doc, context, emit) {
1828
- const btn = doc.createElement("button");
1829
- btn.type = "button";
1830
- btn.className = "veo-guide-cta";
1831
- btn.textContent = block.text?.trim() || "OK";
1832
- btn.addEventListener("click", () => {
1833
- emit("cta_clicked", block);
1834
- const nav = context.nav?.callbacks;
1835
- switch (block.action) {
1836
- case "next":
1837
- case "submit-forms":
1838
- case "submit-forms-advance":
1839
- if (nav) nav.onNext();
1840
- else context.onClose();
1841
- break;
1842
- case "prev":
1843
- nav?.onBack();
1844
- break;
1845
- case "url":
1846
- if (typeof block.url === "string" && isSafeUrl(block.url)) {
1847
- window.open(block.url, "_blank", "noopener,noreferrer");
1848
- }
1849
- break;
1850
- case "guide":
1851
- if (block.targetGuideId) context.onOpenGuide?.(block.targetGuideId);
1852
- this.closeOrSkip(context);
1853
- break;
1854
- default:
1855
- this.closeOrSkip(context);
1856
- }
1857
- });
1858
- return btn;
1859
- }
1860
- closeOrSkip(context) {
1861
- if (context.nav?.callbacks) context.nav.callbacks.onSkip();
1862
- else context.onClose();
1863
- }
1864
- };
1865
- function inlinePosOf(p) {
1866
- return p === "before" || p === "prepend" || p === "append" ? p : "after";
1867
- }
1868
- function applyViewportPosition(card, position) {
1869
- const s = card.style;
1870
- s.position = "fixed";
1871
- const M = "16px";
1872
- const v = position.includes("top") ? "top" : position.includes("bottom") ? "bottom" : "middle";
1873
- const h = position.includes("left") ? "left" : position.includes("right") ? "right" : "middle";
1874
- if (position === "center") {
1875
- s.top = "50%";
1876
- s.left = "50%";
1877
- s.transform = "translate(-50%, -50%)";
1878
- return;
1879
- }
1880
- if (v === "top") s.top = M;
1881
- else if (v === "bottom") s.bottom = M;
1882
- else {
1883
- s.top = "50%";
1884
- s.transform = "translateY(-50%)";
1885
- }
1886
- if (h === "left") s.left = M;
1887
- else if (h === "right") s.right = M;
1888
- else {
1889
- s.left = "50%";
1890
- s.transform = `${s.transform} translateX(-50%)`.trim();
1891
- }
1892
- }
1893
- async function anchorPosition(anchor, wrapper) {
1894
- const update = async () => {
1895
- const { x, y } = await dom.computePosition(anchor, wrapper, {
1896
- placement: "bottom",
1897
- strategy: "fixed",
1898
- middleware: [dom.offset(8), dom.flip(), dom.shift({ padding: 8 })]
1899
- });
1900
- wrapper.style.left = `${x}px`;
1901
- wrapper.style.top = `${y}px`;
1902
- };
1903
- await update();
1904
- const reposition = () => void update();
1905
- window.addEventListener("scroll", reposition, true);
1906
- window.addEventListener("resize", reposition);
1907
- return () => {
1908
- window.removeEventListener("scroll", reposition, true);
1909
- window.removeEventListener("resize", reposition);
1910
- };
1911
- }
1912
- function applyCompositeDesign(card, design) {
1913
- const s = card.style;
1914
- const px = (v) => typeof v === "number" && Number.isFinite(v) ? `${v}px` : null;
1915
- const strv = (v) => typeof v === "string" && v ? v : null;
1916
- if (strv(design.background)) s.background = design.background;
1917
- if (strv(design.textColor)) s.color = design.textColor;
1918
- if (px(design.fontSize)) s.fontSize = px(design.fontSize);
1919
- if (strv(design.fontWeight)) s.fontWeight = design.fontWeight;
1920
- if (strv(design.align)) s.textAlign = design.align;
1921
- if (typeof design.lineHeight === "number") s.lineHeight = `${design.lineHeight}%`;
1922
- if (px(design.radius)) s.borderRadius = px(design.radius);
1923
- if (px(design.width)) s.width = px(design.width);
1924
- const bw = px(design.borderWidth);
1925
- if (bw) s.border = `${bw} solid ${strv(design.borderColor) ?? "#e5e5e5"}`;
1926
- for (const side of ["Top", "Right", "Bottom", "Left"]) {
1927
- const p = px(design[`padding${side}`]);
1928
- if (p) s.setProperty(`padding-${side.toLowerCase()}`, p);
1929
- const m = px(design[`margin${side}`]);
1930
- if (m) s.setProperty(`margin-${side.toLowerCase()}`, m);
1931
- }
1932
- }
1933
1793
 
1934
1794
  // src/utils/uuid.ts
1935
1795
  function uuidv7() {
@@ -2086,85 +1946,53 @@ function escapeClosing(code, tag) {
2086
1946
  return code.replace(rx, `<\\/${tag}`);
2087
1947
  }
2088
1948
 
2089
- // src/plugins/guides/renderers/custom-renderer.ts
2090
- var DEFAULT_PLACEMENT = { mode: "floating", position: "bottom-right" };
2091
- var DEFAULT_OFFSET = 16;
2092
- var DEFAULT_WIDTH = 360;
2093
- var CustomRenderer = class extends BaseRenderer {
2094
- async render(context) {
2095
- const step = context.guide.guideSteps[0];
2096
- if (!step || typeof step.html !== "string" || step.html.length === 0) return;
2097
- const placement = step.placement ?? DEFAULT_PLACEMENT;
2098
- let anchor = null;
2099
- if (placement.mode === "anchored") {
2100
- const selector = placement.selector ?? step.selector ?? context.guide.activationRules.selector;
2101
- if (typeof selector !== "string" || selector.length === 0) return;
2102
- anchor = await waitForElement(selector);
2103
- if (!anchor) return;
2104
- }
2105
- const { root } = this.createHost();
2106
- const doc = root.ownerDocument ?? document;
1949
+ // src/plugins/guides/code-block.ts
1950
+ function mountCodeBlock(block, doc, context) {
1951
+ if (block.sandboxed) {
1952
+ const step = { html: block.html ?? "", css: block.css, js: block.js };
1953
+ const { iframe, cleanup } = mountCustomFrame(doc, step, context, { width: "100%" });
2107
1954
  const wrapper = doc.createElement("div");
2108
- wrapper.className = placement.mode === "anchored" ? "veo-custom-anchored" : "veo-custom-floating";
2109
- const { iframe, cleanup } = mountCustomFrame(doc, step, context, {
2110
- width: toCssSize(placement.width ?? DEFAULT_WIDTH),
2111
- fixedHeight: placement.height ?? null
2112
- });
2113
- this.registerCleanup(cleanup);
1955
+ wrapper.className = "veo-code-sandbox";
2114
1956
  wrapper.appendChild(iframe);
2115
- root.appendChild(wrapper);
2116
- if (placement.mode === "floating") {
2117
- applyFloatingPosition(wrapper, placement);
2118
- } else if (anchor) {
2119
- this.registerCleanup(await this.setupAnchoredPosition(anchor, wrapper, placement));
1957
+ return { node: wrapper, cleanup };
1958
+ }
1959
+ const hostDoc = doc;
1960
+ const injected = [];
1961
+ if (typeof block.css === "string" && block.css.trim()) {
1962
+ const style = hostDoc.createElement("style");
1963
+ style.textContent = block.css;
1964
+ hostDoc.head.appendChild(style);
1965
+ injected.push(style);
1966
+ }
1967
+ let node = null;
1968
+ if (typeof block.html === "string" && block.html.trim()) {
1969
+ node = doc.createElement("div");
1970
+ node.className = "veo-code-html";
1971
+ node.innerHTML = block.html;
1972
+ for (const old of Array.from(node.querySelectorAll("script"))) {
1973
+ injected.push(runScript(old, hostDoc));
1974
+ old.remove();
2120
1975
  }
2121
- context.onInteraction({ guideId: context.guide.guideId, stepIndex: 0, action: "shown" });
2122
1976
  }
2123
- async setupAnchoredPosition(anchor, wrapper, placement) {
2124
- const side = placement.side ?? "bottom";
2125
- const update = async () => {
2126
- const { x, y } = await dom.computePosition(anchor, wrapper, {
2127
- placement: side,
2128
- strategy: "fixed",
2129
- middleware: [dom.offset(placement.offsetY ?? 8), dom.flip(), dom.shift({ padding: 8 })]
2130
- });
2131
- wrapper.style.left = `${x}px`;
2132
- wrapper.style.top = `${y}px`;
2133
- };
2134
- await update();
2135
- const reposition = () => {
2136
- void update();
2137
- };
2138
- window.addEventListener("scroll", reposition, true);
2139
- window.addEventListener("resize", reposition);
2140
- return () => {
2141
- window.removeEventListener("scroll", reposition, true);
2142
- window.removeEventListener("resize", reposition);
2143
- };
2144
- }
2145
- };
2146
- function applyFloatingPosition(wrapper, placement) {
2147
- const position = placement.position ?? "bottom-right";
2148
- const ox = `${placement.offsetX ?? DEFAULT_OFFSET}px`;
2149
- const oy = `${placement.offsetY ?? DEFAULT_OFFSET}px`;
2150
- const s = wrapper.style;
2151
- if (position === "center") {
2152
- s.top = "50%";
2153
- s.left = "50%";
2154
- s.transform = "translate(-50%, -50%)";
2155
- return;
2156
- }
2157
- const [vertical, horizontal] = position.split("-");
2158
- if (vertical === "top") s.top = oy;
2159
- else s.bottom = oy;
2160
- if (horizontal === "left") {
2161
- s.left = ox;
2162
- } else if (horizontal === "right") {
2163
- s.right = ox;
2164
- } else {
2165
- s.left = "50%";
2166
- s.transform = "translateX(-50%)";
1977
+ if (typeof block.js === "string" && block.js.trim()) {
1978
+ const s = hostDoc.createElement("script");
1979
+ s.textContent = block.js;
1980
+ hostDoc.body.appendChild(s);
1981
+ injected.push(s);
2167
1982
  }
1983
+ return {
1984
+ node,
1985
+ cleanup: () => {
1986
+ for (const n of injected) n.parentNode?.removeChild(n);
1987
+ }
1988
+ };
1989
+ }
1990
+ function runScript(old, hostDoc) {
1991
+ const s = hostDoc.createElement("script");
1992
+ for (const attr of Array.from(old.attributes)) s.setAttribute(attr.name, attr.value);
1993
+ if (!old.src) s.textContent = old.textContent;
1994
+ hostDoc.body.appendChild(s);
1995
+ return s;
2168
1996
  }
2169
1997
 
2170
1998
  // src/plugins/guides/form-content.ts
@@ -2432,6 +2260,430 @@ function buildScale(wrapper, doc, min, max, btnClass, symbol) {
2432
2260
  return { wrapper, read: () => selected };
2433
2261
  }
2434
2262
 
2263
+ // src/plugins/guides/renderers/composite-renderer.ts
2264
+ var CompositeRenderer = class extends BaseRenderer {
2265
+ async render(context) {
2266
+ const idx = context.nav?.stepIndex ?? 0;
2267
+ const step = context.guide.guideSteps[idx];
2268
+ if (!step) return;
2269
+ const anchorSelector = step.position === "relative-to-element" || step.presentation === "inline" ? step.anchorSelector?.trim() || void 0 : void 0;
2270
+ let anchor = null;
2271
+ if (anchorSelector) {
2272
+ anchor = await waitForElement(anchorSelector);
2273
+ if (!anchor) return;
2274
+ }
2275
+ const { host, root } = this.createHost();
2276
+ const doc = root.ownerDocument ?? document;
2277
+ const design = step.design ?? {};
2278
+ if (typeof design.zIndex === "number") host.style.zIndex = String(design.zIndex);
2279
+ const card = doc.createElement("div");
2280
+ card.className = "veo-card";
2281
+ applyCompositeDesign(card, design);
2282
+ const dismiss = (action, meta) => {
2283
+ context.onInteraction({
2284
+ guideId: context.guide.guideId,
2285
+ stepIndex: idx,
2286
+ action,
2287
+ ...{}
2288
+ });
2289
+ };
2290
+ const readers = [];
2291
+ this.buildContent(card, step.blocks ?? [], doc, context, idx, readers);
2292
+ if (design.closeButton !== false) {
2293
+ const closeBtn = createCloseButton(doc, () => {
2294
+ dismiss("dismissed");
2295
+ this.closeOrSkip(context);
2296
+ });
2297
+ const closeColor = typeof design.closeColor === "string" ? design.closeColor : null;
2298
+ const hoverColor = typeof design.closeHoverColor === "string" ? design.closeHoverColor : null;
2299
+ if (closeColor) closeBtn.style.color = closeColor;
2300
+ if (hoverColor) {
2301
+ closeBtn.addEventListener("mouseenter", () => {
2302
+ closeBtn.style.color = hoverColor;
2303
+ });
2304
+ closeBtn.addEventListener("mouseleave", () => {
2305
+ closeBtn.style.color = closeColor ?? "";
2306
+ });
2307
+ }
2308
+ card.appendChild(closeBtn);
2309
+ }
2310
+ if (step.presentation === "inline" && anchor) {
2311
+ host.style.display = "block";
2312
+ const pos = inlinePosOf(step.inlinePosition);
2313
+ root.appendChild(card);
2314
+ insertHost(anchor, host, pos);
2315
+ this.registerCleanup(keepHostAttached(host, anchorSelector, pos));
2316
+ } else if (step.position === "relative-to-element" && anchor) {
2317
+ if (design.backdrop === true) {
2318
+ const bg = doc.createElement("div");
2319
+ bg.className = "veo-composite-overlay veo-composite-overlay--dim";
2320
+ if (typeof design.backdropColor === "string") bg.style.background = design.backdropColor;
2321
+ const bz = typeof design.backdropZIndex === "number" ? design.backdropZIndex : 2e5;
2322
+ bg.style.zIndex = String(bz);
2323
+ root.appendChild(bg);
2324
+ if (design.targetAbove === true) this.registerCleanup(liftTarget(anchor, bz + 1));
2325
+ }
2326
+ const wrapper = doc.createElement("div");
2327
+ wrapper.className = "veo-composite-anchored";
2328
+ const caretEl = design.caret === false ? null : makeCaret(doc, design);
2329
+ if (caretEl) wrapper.appendChild(caretEl);
2330
+ wrapper.appendChild(card);
2331
+ root.appendChild(wrapper);
2332
+ this.registerCleanup(await anchorPosition(anchor, wrapper, caretEl));
2333
+ } else {
2334
+ const overlay = doc.createElement("div");
2335
+ overlay.className = "veo-composite-overlay";
2336
+ if (step.position === "center" && design.backdrop !== false) {
2337
+ overlay.classList.add("veo-composite-overlay--dim");
2338
+ if (typeof design.backdropColor === "string") {
2339
+ overlay.style.background = design.backdropColor;
2340
+ }
2341
+ if (typeof design.backdropZIndex === "number") {
2342
+ overlay.style.zIndex = String(design.backdropZIndex);
2343
+ }
2344
+ overlay.addEventListener("click", (e) => {
2345
+ if (e.target === overlay) {
2346
+ dismiss("dismissed");
2347
+ this.closeOrSkip(context);
2348
+ }
2349
+ });
2350
+ }
2351
+ applyViewportPosition(card, step.position, design);
2352
+ overlay.appendChild(card);
2353
+ root.appendChild(overlay);
2354
+ }
2355
+ context.onInteraction({ guideId: context.guide.guideId, stepIndex: idx, action: "shown" });
2356
+ }
2357
+ /** Recorre los bloques en orden y los pinta en la card. */
2358
+ buildContent(card, blocks, doc, context, idx, readers) {
2359
+ const emit = (block) => {
2360
+ context.onInteraction({
2361
+ guideId: context.guide.guideId,
2362
+ stepIndex: idx,
2363
+ action: "cta_clicked",
2364
+ ...block.id ? { metadata: { buttonId: block.id } } : {}
2365
+ });
2366
+ };
2367
+ let i = 0;
2368
+ while (i < blocks.length) {
2369
+ const b = blocks[i];
2370
+ if (!b) {
2371
+ i++;
2372
+ continue;
2373
+ }
2374
+ if (b.type === "button") {
2375
+ const row = doc.createElement("div");
2376
+ row.className = "veo-guide-actions";
2377
+ while (i < blocks.length && blocks[i]?.type === "button") {
2378
+ row.appendChild(
2379
+ this.buildButton(blocks[i], doc, context, idx, readers, emit)
2380
+ );
2381
+ i++;
2382
+ }
2383
+ card.appendChild(row);
2384
+ continue;
2385
+ }
2386
+ if (b.type === "code") {
2387
+ const { node: node2, cleanup } = mountCodeBlock(b, doc, context);
2388
+ if (node2) card.appendChild(node2);
2389
+ this.registerCleanup(cleanup);
2390
+ i++;
2391
+ continue;
2392
+ }
2393
+ if (b.type === "form") {
2394
+ const form = doc.createElement("div");
2395
+ form.className = "veo-form";
2396
+ for (const field of b.fields ?? []) {
2397
+ const { wrapper, read } = buildField(field, doc);
2398
+ readers.push({ field, read });
2399
+ form.appendChild(wrapper);
2400
+ }
2401
+ card.appendChild(form);
2402
+ i++;
2403
+ continue;
2404
+ }
2405
+ const node = buildContentBlock(b, doc);
2406
+ if (node) card.appendChild(node);
2407
+ i++;
2408
+ }
2409
+ }
2410
+ /** Botón con enrutado de acción (navegación / cierre / url / guía / envío de forms). */
2411
+ buildButton(block, doc, context, idx, readers, emit) {
2412
+ const btn = doc.createElement("button");
2413
+ btn.type = "button";
2414
+ btn.className = "veo-guide-cta";
2415
+ btn.textContent = block.text?.trim() || "OK";
2416
+ const nav = context.nav?.callbacks;
2417
+ btn.addEventListener("click", () => {
2418
+ switch (block.action) {
2419
+ case "next":
2420
+ emit(block);
2421
+ if (nav) nav.onNext();
2422
+ else context.onClose();
2423
+ break;
2424
+ case "prev":
2425
+ emit(block);
2426
+ nav?.onBack();
2427
+ break;
2428
+ case "url":
2429
+ emit(block);
2430
+ if (typeof block.url === "string" && isSafeUrl(block.url)) {
2431
+ window.open(block.url, "_blank", "noopener,noreferrer");
2432
+ }
2433
+ break;
2434
+ case "guide":
2435
+ emit(block);
2436
+ if (block.targetGuideId) context.onOpenGuide?.(block.targetGuideId);
2437
+ this.closeOrSkip(context);
2438
+ break;
2439
+ case "submit-forms":
2440
+ case "submit-forms-advance":
2441
+ case "submit-forms-goto":
2442
+ this.submitForms(readers, context, idx, btn, () => {
2443
+ emit(block);
2444
+ if (block.action === "submit-forms" || !nav) {
2445
+ context.onClose();
2446
+ } else if (block.action === "submit-forms-goto" && typeof block.targetStep === "number" && nav.onGoto) {
2447
+ nav.onGoto(block.targetStep);
2448
+ } else {
2449
+ nav.onNext();
2450
+ }
2451
+ });
2452
+ break;
2453
+ default:
2454
+ emit(block);
2455
+ this.closeOrSkip(context);
2456
+ }
2457
+ });
2458
+ return btn;
2459
+ }
2460
+ /** Recoge respuestas de todos los form-blocks del paso, valida y envía. */
2461
+ submitForms(readers, context, idx, btn, onDone) {
2462
+ const answers = {};
2463
+ for (const { field, read } of readers) {
2464
+ const value = read();
2465
+ const empty = value === void 0 || value === null || value === "";
2466
+ if (empty) {
2467
+ if (field.required) {
2468
+ btn.textContent = `Completa "${field.label}"`;
2469
+ return;
2470
+ }
2471
+ continue;
2472
+ }
2473
+ answers[field.key] = value;
2474
+ }
2475
+ if (readers.length > 0 && Object.keys(answers).length === 0) return;
2476
+ btn.disabled = true;
2477
+ const submitFn = context.onFormSubmit ?? (() => Promise.resolve(true));
2478
+ void submitFn(answers).then((ok) => {
2479
+ btn.disabled = false;
2480
+ if (!ok) return;
2481
+ context.onInteraction({
2482
+ guideId: context.guide.guideId,
2483
+ stepIndex: idx,
2484
+ action: "completed"
2485
+ });
2486
+ onDone();
2487
+ });
2488
+ }
2489
+ closeOrSkip(context) {
2490
+ if (context.nav?.callbacks) context.nav.callbacks.onSkip();
2491
+ else context.onClose();
2492
+ }
2493
+ };
2494
+ function inlinePosOf(p) {
2495
+ return p === "before" || p === "prepend" || p === "append" ? p : "after";
2496
+ }
2497
+ function applyViewportPosition(card, position, design) {
2498
+ const s = card.style;
2499
+ s.position = "fixed";
2500
+ const M = "16px";
2501
+ const hAlign = design.hAlign === "left" ? "left" : design.hAlign === "right" ? "right" : null;
2502
+ const v = position.includes("top") ? "top" : position.includes("bottom") ? "bottom" : "middle";
2503
+ const h = hAlign ?? (position.includes("left") ? "left" : position.includes("right") ? "right" : "middle");
2504
+ if (v === "top") s.top = M;
2505
+ else if (v === "bottom") s.bottom = M;
2506
+ else s.top = "50%";
2507
+ if (h === "left") s.left = M;
2508
+ else if (h === "right") s.right = M;
2509
+ else s.left = "50%";
2510
+ const tx = h === "middle" ? "-50%" : "0";
2511
+ const ty = v === "middle" ? "-50%" : "0";
2512
+ s.transform = tx === "0" && ty === "0" ? "" : `translate(${tx}, ${ty})`;
2513
+ }
2514
+ function makeCaret(doc, design) {
2515
+ const caret = doc.createElement("div");
2516
+ caret.className = "veo-composite-caret";
2517
+ const w = typeof design.caretWidth === "number" ? design.caretWidth : 12;
2518
+ const h = typeof design.caretHeight === "number" ? design.caretHeight : 12;
2519
+ const s = caret.style;
2520
+ s.position = "absolute";
2521
+ s.width = `${w}px`;
2522
+ s.height = `${h}px`;
2523
+ s.transform = "rotate(45deg)";
2524
+ s.background = typeof design.background === "string" ? design.background : "#ffffff";
2525
+ if (typeof design.borderWidth === "number" && design.borderWidth > 0) {
2526
+ const bc = typeof design.borderColor === "string" ? design.borderColor : "#bbbbbb";
2527
+ s.border = `${design.borderWidth}px solid ${bc}`;
2528
+ }
2529
+ return caret;
2530
+ }
2531
+ function liftTarget(anchor, zIndex) {
2532
+ const el = anchor;
2533
+ const prevPosition = el.style.position;
2534
+ const prevZ = el.style.zIndex;
2535
+ if (getComputedStyle(el).position === "static") el.style.position = "relative";
2536
+ el.style.zIndex = String(zIndex);
2537
+ return () => {
2538
+ el.style.position = prevPosition;
2539
+ el.style.zIndex = prevZ;
2540
+ };
2541
+ }
2542
+ async function anchorPosition(anchor, wrapper, caret) {
2543
+ const update = async () => {
2544
+ const { x, y, placement, middlewareData } = await dom.computePosition(anchor, wrapper, {
2545
+ placement: "bottom",
2546
+ strategy: "fixed",
2547
+ middleware: [
2548
+ dom.offset(caret ? 10 : 8),
2549
+ dom.flip(),
2550
+ dom.shift({ padding: 8 }),
2551
+ ...caret ? [dom.arrow({ element: caret })] : []
2552
+ ]
2553
+ });
2554
+ wrapper.style.left = `${x}px`;
2555
+ wrapper.style.top = `${y}px`;
2556
+ if (caret) positionArrow(caret, placement, middlewareData.arrow);
2557
+ };
2558
+ await update();
2559
+ const reposition = () => void update();
2560
+ window.addEventListener("scroll", reposition, true);
2561
+ window.addEventListener("resize", reposition);
2562
+ return () => {
2563
+ window.removeEventListener("scroll", reposition, true);
2564
+ window.removeEventListener("resize", reposition);
2565
+ };
2566
+ }
2567
+ function applyCompositeDesign(card, design) {
2568
+ const s = card.style;
2569
+ const px = (v) => typeof v === "number" && Number.isFinite(v) ? `${v}px` : null;
2570
+ const strv = (v) => typeof v === "string" && v ? v : null;
2571
+ if (strv(design.background)) s.background = design.background;
2572
+ const textColor = strv(design.color) ?? strv(design.textColor);
2573
+ if (textColor) s.color = textColor;
2574
+ if (px(design.fontSize)) s.fontSize = px(design.fontSize);
2575
+ if (strv(design.fontWeight)) s.fontWeight = design.fontWeight;
2576
+ if (strv(design.fontFamily) && design.fontFamily !== "inherit") {
2577
+ s.fontFamily = design.fontFamily;
2578
+ }
2579
+ if (strv(design.textTransform) && design.textTransform !== "none") {
2580
+ s.textTransform = design.textTransform;
2581
+ }
2582
+ if (typeof design.letterSpacing === "number") s.letterSpacing = `${design.letterSpacing}px`;
2583
+ if (strv(design.align)) s.textAlign = design.align;
2584
+ if (typeof design.lineHeight === "number") s.lineHeight = `${design.lineHeight}%`;
2585
+ if (px(design.radius)) s.borderRadius = px(design.radius);
2586
+ const bw = px(design.borderWidth);
2587
+ if (bw) s.border = `${bw} solid ${strv(design.borderColor) ?? "#e5e5e5"}`;
2588
+ if (strv(design.shadowColor) || typeof design.shadowBlur === "number") {
2589
+ const n = (k) => typeof design[k] === "number" ? design[k] : 0;
2590
+ s.boxShadow = `${n("shadowX")}px ${n("shadowY")}px ${n("shadowBlur")}px ${n("shadowSpread")}px ${strv(design.shadowColor) ?? "rgba(0,0,0,0.2)"}`;
2591
+ }
2592
+ if (design.fullWidth === true) {
2593
+ s.width = "100%";
2594
+ } else if (design.widthType === "fluid") {
2595
+ s.width = "auto";
2596
+ if (px(design.width)) s.maxWidth = px(design.width);
2597
+ } else if (px(design.width)) {
2598
+ s.width = px(design.width);
2599
+ }
2600
+ for (const side of ["Top", "Right", "Bottom", "Left"]) {
2601
+ const p = px(design[`padding${side}`]);
2602
+ if (p) s.setProperty(`padding-${side.toLowerCase()}`, p);
2603
+ const m = px(design[`margin${side}`]);
2604
+ if (m) s.setProperty(`margin-${side.toLowerCase()}`, m);
2605
+ }
2606
+ }
2607
+ var DEFAULT_PLACEMENT = { mode: "floating", position: "bottom-right" };
2608
+ var DEFAULT_OFFSET = 16;
2609
+ var DEFAULT_WIDTH = 360;
2610
+ var CustomRenderer = class extends BaseRenderer {
2611
+ async render(context) {
2612
+ const step = context.guide.guideSteps[0];
2613
+ if (!step || typeof step.html !== "string" || step.html.length === 0) return;
2614
+ const placement = step.placement ?? DEFAULT_PLACEMENT;
2615
+ let anchor = null;
2616
+ if (placement.mode === "anchored") {
2617
+ const selector = placement.selector ?? step.selector ?? context.guide.activationRules.selector;
2618
+ if (typeof selector !== "string" || selector.length === 0) return;
2619
+ anchor = await waitForElement(selector);
2620
+ if (!anchor) return;
2621
+ }
2622
+ const { root } = this.createHost();
2623
+ const doc = root.ownerDocument ?? document;
2624
+ const wrapper = doc.createElement("div");
2625
+ wrapper.className = placement.mode === "anchored" ? "veo-custom-anchored" : "veo-custom-floating";
2626
+ const { iframe, cleanup } = mountCustomFrame(doc, step, context, {
2627
+ width: toCssSize(placement.width ?? DEFAULT_WIDTH),
2628
+ fixedHeight: placement.height ?? null
2629
+ });
2630
+ this.registerCleanup(cleanup);
2631
+ wrapper.appendChild(iframe);
2632
+ root.appendChild(wrapper);
2633
+ if (placement.mode === "floating") {
2634
+ applyFloatingPosition(wrapper, placement);
2635
+ } else if (anchor) {
2636
+ this.registerCleanup(await this.setupAnchoredPosition(anchor, wrapper, placement));
2637
+ }
2638
+ context.onInteraction({ guideId: context.guide.guideId, stepIndex: 0, action: "shown" });
2639
+ }
2640
+ async setupAnchoredPosition(anchor, wrapper, placement) {
2641
+ const side = placement.side ?? "bottom";
2642
+ const update = async () => {
2643
+ const { x, y } = await dom.computePosition(anchor, wrapper, {
2644
+ placement: side,
2645
+ strategy: "fixed",
2646
+ middleware: [dom.offset(placement.offsetY ?? 8), dom.flip(), dom.shift({ padding: 8 })]
2647
+ });
2648
+ wrapper.style.left = `${x}px`;
2649
+ wrapper.style.top = `${y}px`;
2650
+ };
2651
+ await update();
2652
+ const reposition = () => {
2653
+ void update();
2654
+ };
2655
+ window.addEventListener("scroll", reposition, true);
2656
+ window.addEventListener("resize", reposition);
2657
+ return () => {
2658
+ window.removeEventListener("scroll", reposition, true);
2659
+ window.removeEventListener("resize", reposition);
2660
+ };
2661
+ }
2662
+ };
2663
+ function applyFloatingPosition(wrapper, placement) {
2664
+ const position = placement.position ?? "bottom-right";
2665
+ const ox = `${placement.offsetX ?? DEFAULT_OFFSET}px`;
2666
+ const oy = `${placement.offsetY ?? DEFAULT_OFFSET}px`;
2667
+ const s = wrapper.style;
2668
+ if (position === "center") {
2669
+ s.top = "50%";
2670
+ s.left = "50%";
2671
+ s.transform = "translate(-50%, -50%)";
2672
+ return;
2673
+ }
2674
+ const [vertical, horizontal] = position.split("-");
2675
+ if (vertical === "top") s.top = oy;
2676
+ else s.bottom = oy;
2677
+ if (horizontal === "left") {
2678
+ s.left = ox;
2679
+ } else if (horizontal === "right") {
2680
+ s.right = ox;
2681
+ } else {
2682
+ s.left = "50%";
2683
+ s.transform = "translateX(-50%)";
2684
+ }
2685
+ }
2686
+
2435
2687
  // src/plugins/guides/renderers/form-renderer.ts
2436
2688
  var FormRenderer = class extends BaseRenderer {
2437
2689
  render(context) {