veo-sdk 0.3.0 → 0.3.3

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.
@@ -0,0 +1,5 @@
1
+ export { createBuilderSession, initBuilderMode, startElementPicker, stopElementPicker } from './chunk-PASI5SAK.mjs';
2
+ import './chunk-GHP7ZJCW.mjs';
3
+ import './chunk-PTG3BTJE.mjs';
4
+ //# sourceMappingURL=builder-VPQDAUIL.mjs.map
5
+ //# sourceMappingURL=builder-VPQDAUIL.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"builder-UEGKG2UR.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"builder-VPQDAUIL.mjs"}
package/dist/builder.cjs CHANGED
@@ -13,10 +13,12 @@ function hasDocument() {
13
13
  // src/core/builder-constants.ts
14
14
  var BUILDER_TOKEN_PARAM = "veoBuilder";
15
15
  var BUILDER_ORIGIN_PARAM = "veoBuilderOrigin";
16
+ var BUILDER_PANEL_PARAM = "veoBuilderPanel";
17
+ var BUILDER_PANEL_PATH_PARAM = "veoBuilderPanelPath";
18
+ var BUILDER_GUIDE_PARAM = "veoGuide";
16
19
 
17
20
  // src/core/builder-token.ts
18
- var TOKEN_KEY = "veo:builder_token";
19
- var ORIGIN_KEY = "veo:builder_origin";
21
+ var CTX_KEY = "veo:builder_ctx";
20
22
  function session() {
21
23
  try {
22
24
  return window.sessionStorage;
@@ -31,32 +33,27 @@ function urlParams() {
31
33
  return null;
32
34
  }
33
35
  }
34
- function resolveBuilderToken() {
36
+ function resolveBuilderContext() {
35
37
  if (!hasWindow()) return null;
36
38
  const params = urlParams();
37
39
  const fromUrl = params?.get(BUILDER_TOKEN_PARAM);
38
40
  if (fromUrl) {
39
- const store = session();
41
+ const ctx = {
42
+ token: fromUrl,
43
+ origin: params?.get(BUILDER_ORIGIN_PARAM) ?? null,
44
+ panel: params?.get(BUILDER_PANEL_PARAM) === "1",
45
+ guide: params?.get(BUILDER_GUIDE_PARAM) ?? null,
46
+ panelPath: params?.get(BUILDER_PANEL_PATH_PARAM) ?? null
47
+ };
40
48
  try {
41
- store?.setItem(TOKEN_KEY, fromUrl);
42
- const origin = params?.get(BUILDER_ORIGIN_PARAM);
43
- if (origin) store?.setItem(ORIGIN_KEY, origin);
49
+ session()?.setItem(CTX_KEY, JSON.stringify(ctx));
44
50
  } catch {
45
51
  }
46
- return fromUrl;
47
- }
48
- try {
49
- return session()?.getItem(TOKEN_KEY) ?? null;
50
- } catch {
51
- return null;
52
+ return ctx;
52
53
  }
53
- }
54
- function resolveBuilderOrigin() {
55
- if (!hasWindow()) return null;
56
- const fromUrl = urlParams()?.get(BUILDER_ORIGIN_PARAM);
57
- if (fromUrl) return fromUrl;
58
54
  try {
59
- return session()?.getItem(ORIGIN_KEY) ?? null;
55
+ const raw = session()?.getItem(CTX_KEY);
56
+ return raw ? JSON.parse(raw) : null;
60
57
  } catch {
61
58
  return null;
62
59
  }
@@ -64,9 +61,7 @@ function resolveBuilderOrigin() {
64
61
  function clearBuilderToken() {
65
62
  if (!hasWindow()) return;
66
63
  try {
67
- const store = session();
68
- store?.removeItem(TOKEN_KEY);
69
- store?.removeItem(ORIGIN_KEY);
64
+ session()?.removeItem(CTX_KEY);
70
65
  } catch {
71
66
  }
72
67
  }
@@ -1597,6 +1592,124 @@ function safeDestroy(renderer) {
1597
1592
  // src/plugins/builder/bridge-protocol.ts
1598
1593
  var VEO_BUILDER_SOURCE = "veo-builder";
1599
1594
 
1595
+ // src/plugins/builder/builder-panel.ts
1596
+ var DEFAULT_PANEL_PATH = "/guides/design";
1597
+ var PANEL_W = 400;
1598
+ var PANEL_H = 640;
1599
+ var MARGIN = 16;
1600
+ function injectBuilderPanel(opts) {
1601
+ if (!hasWindow() || !hasDocument()) {
1602
+ return { target: () => null, teardown: () => {
1603
+ } };
1604
+ }
1605
+ const host = document.createElement("div");
1606
+ host.setAttribute("data-veo-builder-panel", "");
1607
+ const shadow = host.attachShadow({ mode: "open" });
1608
+ const style = document.createElement("style");
1609
+ style.textContent = PANEL_CSS;
1610
+ const card = document.createElement("div");
1611
+ card.className = "veo-panel";
1612
+ let left = Math.max(MARGIN, window.innerWidth - PANEL_W - MARGIN);
1613
+ let top = MARGIN;
1614
+ card.style.left = `${left}px`;
1615
+ card.style.top = `${top}px`;
1616
+ const header = document.createElement("div");
1617
+ header.className = "veo-panel-header";
1618
+ const title = document.createElement("span");
1619
+ title.className = "veo-panel-title";
1620
+ title.textContent = "Veo \xB7 Editor";
1621
+ const close = document.createElement("button");
1622
+ close.className = "veo-panel-close";
1623
+ close.type = "button";
1624
+ close.setAttribute("aria-label", "Cerrar");
1625
+ close.textContent = "\u2715";
1626
+ close.addEventListener("click", () => opts.onClose());
1627
+ header.append(title, close);
1628
+ const iframe = document.createElement("iframe");
1629
+ iframe.className = "veo-panel-frame";
1630
+ iframe.title = "Editor de Veo";
1631
+ iframe.src = buildPanelUrl(opts);
1632
+ card.append(header, iframe);
1633
+ shadow.append(style, card);
1634
+ document.body.appendChild(host);
1635
+ const onHeaderDown = (e) => {
1636
+ if (e.target?.classList.contains("veo-panel-close")) return;
1637
+ e.preventDefault();
1638
+ const startX = e.clientX;
1639
+ const startY = e.clientY;
1640
+ const origLeft = left;
1641
+ const origTop = top;
1642
+ iframe.style.pointerEvents = "none";
1643
+ card.classList.add("dragging");
1644
+ const onMove = (ev) => {
1645
+ const maxLeft = window.innerWidth - card.offsetWidth;
1646
+ const maxTop = window.innerHeight - 40;
1647
+ left = clamp2(origLeft + (ev.clientX - startX), 0, Math.max(0, maxLeft));
1648
+ top = clamp2(origTop + (ev.clientY - startY), 0, Math.max(0, maxTop));
1649
+ card.style.left = `${left}px`;
1650
+ card.style.top = `${top}px`;
1651
+ };
1652
+ const onUp = () => {
1653
+ window.removeEventListener("mousemove", onMove);
1654
+ window.removeEventListener("mouseup", onUp);
1655
+ iframe.style.pointerEvents = "";
1656
+ card.classList.remove("dragging");
1657
+ };
1658
+ window.addEventListener("mousemove", onMove);
1659
+ window.addEventListener("mouseup", onUp);
1660
+ };
1661
+ header.addEventListener("mousedown", onHeaderDown);
1662
+ return {
1663
+ target: () => iframe.contentWindow,
1664
+ teardown: () => host.remove()
1665
+ };
1666
+ }
1667
+ function clamp2(v, min, max) {
1668
+ return Math.min(Math.max(v, min), max);
1669
+ }
1670
+ function buildPanelUrl(opts) {
1671
+ const path = opts.panelPath ?? DEFAULT_PANEL_PATH;
1672
+ const url = new URL(path, opts.dashboardOrigin);
1673
+ url.searchParams.set("veoToken", opts.token);
1674
+ url.searchParams.set("veoApp", opts.appOrigin);
1675
+ if (opts.guide) url.searchParams.set("veoGuide", opts.guide);
1676
+ return url.toString();
1677
+ }
1678
+ var PANEL_CSS = `
1679
+ :host { all: initial; }
1680
+ .veo-panel {
1681
+ position: fixed;
1682
+ width: ${PANEL_W}px; height: ${PANEL_H}px;
1683
+ min-width: 320px; min-height: 320px;
1684
+ max-width: 96vw; max-height: 94vh;
1685
+ display: flex; flex-direction: column;
1686
+ background: #fff;
1687
+ border-radius: 12px;
1688
+ box-shadow: 0 12px 40px rgba(0,0,0,0.28);
1689
+ overflow: hidden;
1690
+ resize: both;
1691
+ z-index: 2147483647;
1692
+ font-family: system-ui, -apple-system, sans-serif;
1693
+ }
1694
+ .veo-panel.dragging { user-select: none; }
1695
+ .veo-panel-header {
1696
+ flex: 0 0 auto;
1697
+ display: flex; align-items: center; justify-content: space-between;
1698
+ padding: 8px 12px;
1699
+ background: #0f172a; color: #fff;
1700
+ font-size: 13px; font-weight: 600;
1701
+ cursor: grab;
1702
+ }
1703
+ .veo-panel-header:active { cursor: grabbing; }
1704
+ .veo-panel-close {
1705
+ border: 0; background: transparent; color: #fff;
1706
+ font-size: 15px; cursor: pointer; line-height: 1;
1707
+ padding: 4px 6px; border-radius: 6px;
1708
+ }
1709
+ .veo-panel-close:hover { background: rgba(255,255,255,0.15); }
1710
+ .veo-panel-frame { flex: 1 1 auto; width: 100%; border: 0; background: #fff; }
1711
+ `;
1712
+
1600
1713
  // src/plugins/autocapture/constants.ts
1601
1714
  var HASHED_CLASS_PATTERNS = [
1602
1715
  /^css-[a-z0-9]{4,}$/i,
@@ -1881,18 +1994,23 @@ function stopElementPicker() {
1881
1994
  // src/plugins/builder/builder-mode.ts
1882
1995
  function initBuilderMode() {
1883
1996
  if (!hasWindow() || !hasDocument()) return null;
1884
- const token = resolveBuilderToken();
1885
- if (!token) return null;
1886
- const dashboardOrigin = resolveDashboardOrigin();
1997
+ const ctx = resolveBuilderContext();
1998
+ if (!ctx) return null;
1999
+ const token = ctx.token;
2000
+ const dashboardOrigin = resolveDashboardOrigin(ctx.origin);
1887
2001
  if (!dashboardOrigin) return null;
1888
- const target = resolveTarget();
1889
- if (!target) return null;
1890
2002
  let picker = null;
2003
+ let panel = null;
2004
+ let staticTarget = null;
2005
+ const getTarget = () => panel ? panel.target() : staticTarget;
1891
2006
  const post = (event) => {
1892
- target.postMessage({ source: VEO_BUILDER_SOURCE, token, ...event }, dashboardOrigin);
2007
+ getTarget()?.postMessage({ source: VEO_BUILDER_SOURCE, token, ...event }, dashboardOrigin);
1893
2008
  };
1894
2009
  const handleCommand = (cmd) => {
1895
2010
  switch (cmd.type) {
2011
+ case "panel-ready":
2012
+ post({ type: "ready" });
2013
+ break;
1896
2014
  case "start-picker":
1897
2015
  picker?.stop();
1898
2016
  picker = startElementPicker({
@@ -1936,13 +2054,28 @@ function initBuilderMode() {
1936
2054
  picker?.stop();
1937
2055
  picker = null;
1938
2056
  closeGuidePreview();
1939
- clearBuilderToken();
1940
2057
  post({ type: "closed" });
2058
+ panel?.teardown();
2059
+ panel = null;
2060
+ clearBuilderToken();
1941
2061
  };
2062
+ if (ctx.panel) {
2063
+ panel = injectBuilderPanel({
2064
+ dashboardOrigin,
2065
+ token,
2066
+ appOrigin: window.location.origin,
2067
+ guide: ctx.guide,
2068
+ panelPath: ctx.panelPath,
2069
+ onClose: () => teardown()
2070
+ });
2071
+ } else {
2072
+ staticTarget = resolveTarget();
2073
+ if (!staticTarget) return null;
2074
+ }
1942
2075
  const activate = () => {
1943
2076
  window.addEventListener("message", onMessage);
1944
2077
  window.addEventListener("pagehide", onPageHide);
1945
- post({ type: "ready" });
2078
+ if (!ctx.panel) post({ type: "ready" });
1946
2079
  };
1947
2080
  const cfg = window.__veoBuilder;
1948
2081
  if (cfg?.apiKey && cfg?.apiUrl) {
@@ -1975,11 +2108,10 @@ function resolveTarget() {
1975
2108
  if (window.parent && window.parent !== window) return window.parent;
1976
2109
  return null;
1977
2110
  }
1978
- function resolveDashboardOrigin() {
1979
- const stored = resolveBuilderOrigin();
1980
- if (stored) {
2111
+ function resolveDashboardOrigin(originHint) {
2112
+ if (originHint) {
1981
2113
  try {
1982
- return new URL(stored).origin;
2114
+ return new URL(originHint).origin;
1983
2115
  } catch {
1984
2116
  return null;
1985
2117
  }