veo-sdk 0.3.8 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1044,21 +1044,6 @@ var init_styles = __esm({
1044
1044
  background: transparent;
1045
1045
  color-scheme: normal;
1046
1046
  }
1047
- /*
1048
- * X de cerrar de las gu\xEDas custom: el HTML del cliente vive en un iframe
1049
- * sandbox, as\xED que el bot\xF3n lo pone el host POR ENCIMA del iframe. Con fondo
1050
- * propio para ser visible sobre cualquier contenido.
1051
- */
1052
- .veo-custom-close {
1053
- position: absolute; top: 6px; right: 6px; z-index: 1;
1054
- width: 22px; height: 22px; padding: 0;
1055
- display: flex; align-items: center; justify-content: center;
1056
- font-size: 16px; line-height: 1; color: #6b7280;
1057
- background: rgba(255, 255, 255, 0.92);
1058
- border: 1px solid rgba(0, 0, 0, 0.08); border-radius: 50%;
1059
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); cursor: pointer;
1060
- }
1061
- .veo-custom-close:hover { color: #111827; }
1062
1047
 
1063
1048
  @keyframes veo-fade-in { from { opacity: 0; } to { opacity: 1; } }
1064
1049
  @keyframes veo-slide-up {
@@ -1231,7 +1216,8 @@ function mountCustomFrame(doc, step, context, opts) {
1231
1216
  const token = uuidv7();
1232
1217
  const wantsTailwind = step.style?.tailwind === true;
1233
1218
  iframe.srcdoc = buildSrcdoc(step.html ?? "", step.css ?? "", step.js ?? "", token, {
1234
- tokens: collectHostTokens(),
1219
+ hostCss: collectHostStyles(),
1220
+ htmlAttrs: hostHtmlAttrs(),
1235
1221
  tailwind: wantsTailwind
1236
1222
  });
1237
1223
  const close = () => context.onClose();
@@ -1282,25 +1268,39 @@ function mountCustomFrame(doc, step, context, opts) {
1282
1268
  function toCssSize(value) {
1283
1269
  return typeof value === "number" ? `${value}px` : value;
1284
1270
  }
1285
- function collectHostTokens() {
1286
- if (typeof window === "undefined" || typeof document === "undefined") return "";
1271
+ function collectHostStyles() {
1272
+ if (typeof document === "undefined") return "";
1273
+ let out = "";
1287
1274
  try {
1288
- const rootStyle = getComputedStyle(document.documentElement);
1289
- const decls = [];
1290
- const seen = /* @__PURE__ */ new Set();
1291
- for (let i = 0; i < rootStyle.length && decls.length < 400; i++) {
1292
- const name = rootStyle.item(i);
1293
- if (!name.startsWith("--") || seen.has(name)) continue;
1294
- seen.add(name);
1295
- const value = rootStyle.getPropertyValue(name).trim();
1296
- if (!value || value.length > 200 || /[<>{}]/.test(value)) continue;
1297
- decls.push(`${name}:${value}`);
1275
+ for (const sheet of Array.from(document.styleSheets)) {
1276
+ let rules = null;
1277
+ try {
1278
+ rules = sheet.cssRules;
1279
+ } catch {
1280
+ continue;
1281
+ }
1282
+ if (!rules) continue;
1283
+ for (const rule of Array.from(rules)) {
1284
+ out += `${rule.cssText}
1285
+ `;
1286
+ if (out.length > MAX_HOST_CSS) return out;
1287
+ }
1298
1288
  }
1299
- const bodyFont = getComputedStyle(document.body).fontFamily;
1300
- if (bodyFont && bodyFont.length <= 200 && !/[<>{}]/.test(bodyFont)) {
1301
- decls.push(`--veo-host-font:${bodyFont}`);
1289
+ } catch {
1290
+ return out;
1291
+ }
1292
+ return out;
1293
+ }
1294
+ function hostHtmlAttrs() {
1295
+ if (typeof document === "undefined") return "";
1296
+ try {
1297
+ const el = document.documentElement;
1298
+ const attrs = [];
1299
+ for (const name of ["class", "style", "data-theme", "data-mode", "data-color-mode"]) {
1300
+ const v = el.getAttribute(name);
1301
+ if (v && v.length <= 1e3 && !/["<>]/.test(v)) attrs.push(`${name}="${v}"`);
1302
1302
  }
1303
- return decls.length ? `:root{${decls.join(";")}}` : "";
1303
+ return attrs.join(" ");
1304
1304
  } catch {
1305
1305
  return "";
1306
1306
  }
@@ -1310,18 +1310,24 @@ function isRecord(value) {
1310
1310
  }
1311
1311
  function buildSrcdoc(html, css, js, token, opts) {
1312
1312
  const bridge = `(function(){var T=${JSON.stringify(token)};function P(m){m.__veo=T;parent.postMessage(m,'*');}window.veo={dismiss:function(){P({type:'dismiss'});},cta:function(u){P({type:'cta',url:u});},track:function(n,p){P({type:'track',name:n,props:p||{}});},navigate:function(u){P({type:'navigate',url:u});}};document.addEventListener('click',function(e){var a=e.target&&e.target.closest?e.target.closest('a[href]'):null;if(!a)return;var h=a.getAttribute('href');if(!h||h.charAt(0)==='#'||/^(javascript|mailto|tel):/i.test(h))return;e.preventDefault();if(a.target==='_blank'){P({type:'cta',url:a.href,close:false});}else{P({type:'navigate',url:h});}},true);function H(){P({type:'resize',height:Math.ceil(document.documentElement.scrollHeight)});}window.addEventListener('load',H);try{if(typeof ResizeObserver!=='undefined'){new ResizeObserver(H).observe(document.documentElement);}}catch(e){}})();`;
1313
- const tokensStyle = opts.tokens ? `<style>${escapeClosing(opts.tokens, "style")}</style>` : "";
1313
+ const hostStyle = opts.hostCss ? `<style>${escapeClosing(opts.hostCss, "style")}</style>` : "";
1314
1314
  const tailwind = opts.tailwind ? '<script src="https://cdn.tailwindcss.com"></script>' : "";
1315
- return '<!DOCTYPE html><html><head><meta charset="utf-8"><style>html,body{margin:0;padding:0;background:transparent;font-family:var(--veo-host-font,system-ui,sans-serif);}</style>' + tokensStyle + tailwind + `<style>${escapeClosing(css, "style")}</style></head><body>${html}<script>${bridge}</script>` + (js ? `<script>${escapeClosing(js, "script")}</script>` : "") + "</body></html>";
1315
+ return (
1316
+ // Orden: base → CSS del host (utilidades+clases propias+:root) → reset
1317
+ // flotante (fondo transparente, sin márgenes) → Tailwind → CSS del autor (gana).
1318
+ `<!DOCTYPE html><html ${opts.htmlAttrs}><head><meta charset="utf-8"><style>html,body{margin:0;padding:0;}body{font-family:system-ui,-apple-system,sans-serif;}</style>` + hostStyle + "<style>html,body{margin:0!important;padding:0!important;background:transparent!important;}</style>" + tailwind + `<style>${escapeClosing(css, "style")}</style></head><body>${html}<script>${bridge}</script>` + (js ? `<script>${escapeClosing(js, "script")}</script>` : "") + "</body></html>"
1319
+ );
1316
1320
  }
1317
1321
  function escapeClosing(code, tag) {
1318
1322
  const rx = tag === "script" ? /<\/script/gi : /<\/style/gi;
1319
1323
  return code.replace(rx, `<\\/${tag}`);
1320
1324
  }
1325
+ var MAX_HOST_CSS;
1321
1326
  var init_custom_frame = __esm({
1322
1327
  "src/plugins/guides/renderers/custom-frame.ts"() {
1323
1328
  init_uuid();
1324
1329
  init_block_builder();
1330
+ MAX_HOST_CSS = 800 * 1024;
1325
1331
  }
1326
1332
  });
1327
1333
  function applyFloatingPosition(wrapper, placement) {
@@ -1350,7 +1356,6 @@ function applyFloatingPosition(wrapper, placement) {
1350
1356
  var DEFAULT_PLACEMENT, DEFAULT_OFFSET, DEFAULT_WIDTH, CustomRenderer;
1351
1357
  var init_custom_renderer = __esm({
1352
1358
  "src/plugins/guides/renderers/custom-renderer.ts"() {
1353
- init_block_builder();
1354
1359
  init_wait_for_element();
1355
1360
  init_base_renderer();
1356
1361
  init_custom_frame();
@@ -1379,20 +1384,6 @@ var init_custom_renderer = __esm({
1379
1384
  });
1380
1385
  this.registerCleanup(cleanup);
1381
1386
  wrapper.appendChild(iframe);
1382
- wrapper.appendChild(
1383
- createCloseButton(
1384
- doc,
1385
- () => {
1386
- context.onInteraction({
1387
- guideId: context.guide.guideId,
1388
- stepIndex: 0,
1389
- action: "dismissed"
1390
- });
1391
- context.onClose();
1392
- },
1393
- "veo-custom-close"
1394
- )
1395
- );
1396
1387
  root.appendChild(wrapper);
1397
1388
  if (placement.mode === "floating") {
1398
1389
  applyFloatingPosition(wrapper, placement);
@@ -1773,7 +1764,6 @@ var init_inline_host = __esm({
1773
1764
  var InlineCustomRenderer;
1774
1765
  var init_inline_custom_renderer = __esm({
1775
1766
  "src/plugins/guides/renderers/inline-custom-renderer.ts"() {
1776
- init_block_builder();
1777
1767
  init_inline_host();
1778
1768
  init_wait_for_element();
1779
1769
  init_base_renderer();
@@ -1797,20 +1787,6 @@ var init_inline_custom_renderer = __esm({
1797
1787
  const { iframe, cleanup } = mountCustomFrame(doc, step, context, { width: "100%" });
1798
1788
  this.registerCleanup(cleanup);
1799
1789
  wrapper.appendChild(iframe);
1800
- wrapper.appendChild(
1801
- createCloseButton(
1802
- doc,
1803
- () => {
1804
- context.onInteraction({
1805
- guideId: context.guide.guideId,
1806
- stepIndex: 0,
1807
- action: "dismissed"
1808
- });
1809
- context.onClose();
1810
- },
1811
- "veo-custom-close"
1812
- )
1813
- );
1814
1790
  root.appendChild(wrapper);
1815
1791
  context.onInteraction({ guideId: context.guide.guideId, stepIndex: 0, action: "shown" });
1816
1792
  }