veo-sdk 0.5.25 → 0.5.27

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
@@ -2126,7 +2126,24 @@ var init_custom_frame = __esm({
2126
2126
  });
2127
2127
 
2128
2128
  // src/plugins/guides/code-block.ts
2129
- function mountCodeBlock(block, doc, context) {
2129
+ function insertRawNodes(anchor, nodes, pos) {
2130
+ const parent = anchor.parentNode;
2131
+ if (pos === "prepend") {
2132
+ const first = anchor.firstChild;
2133
+ for (const n of nodes) anchor.insertBefore(n, first);
2134
+ } else if (pos === "append") {
2135
+ for (const n of nodes) anchor.appendChild(n);
2136
+ } else if (pos === "before") {
2137
+ for (const n of nodes) parent?.insertBefore(n, anchor);
2138
+ } else {
2139
+ let ref = anchor;
2140
+ for (const n of nodes) {
2141
+ parent?.insertBefore(n, ref.nextSibling);
2142
+ ref = n;
2143
+ }
2144
+ }
2145
+ }
2146
+ function mountCodeBlock(block, doc, context, host, rawInline) {
2130
2147
  if (block.sandboxed) {
2131
2148
  const step = { html: block.html ?? "", css: block.css, js: block.js };
2132
2149
  const { iframe, cleanup } = mountCustomFrame(doc, step, context, { width: "100%" });
@@ -2145,19 +2162,28 @@ function mountCodeBlock(block, doc, context) {
2145
2162
  }
2146
2163
  let node = null;
2147
2164
  if (typeof block.html === "string" && block.html.trim()) {
2148
- node = doc.createElement("div");
2149
- node.className = "veo-code-html";
2150
- const inner = node.attachShadow({ mode: "open" });
2151
- for (const sheet of Array.from(hostDoc.querySelectorAll('link[rel="stylesheet"], style'))) {
2152
- inner.appendChild(sheet.cloneNode(true));
2153
- }
2154
2165
  const holder = doc.createElement("div");
2166
+ holder.className = "veo-code-html";
2155
2167
  holder.innerHTML = block.html;
2156
2168
  for (const old of Array.from(holder.querySelectorAll("script"))) {
2157
2169
  injected.push(runScript(old, hostDoc));
2158
2170
  old.remove();
2159
2171
  }
2160
- inner.appendChild(holder);
2172
+ if (rawInline) {
2173
+ const rawNodes = Array.from(holder.childNodes);
2174
+ insertRawNodes(rawInline.anchor, rawNodes, rawInline.pos);
2175
+ injected.push(...rawNodes);
2176
+ } else if (host) {
2177
+ const slotName = `veo-code-${++codeSlotSeq}`;
2178
+ holder.slot = slotName;
2179
+ host.appendChild(holder);
2180
+ injected.push(holder);
2181
+ const slot = doc.createElement("slot");
2182
+ slot.setAttribute("name", slotName);
2183
+ node = slot;
2184
+ } else {
2185
+ node = holder;
2186
+ }
2161
2187
  }
2162
2188
  if (typeof block.js === "string" && block.js.trim()) {
2163
2189
  const s = hostDoc.createElement("script");
@@ -2179,9 +2205,11 @@ function runScript(old, hostDoc) {
2179
2205
  hostDoc.body.appendChild(s);
2180
2206
  return s;
2181
2207
  }
2208
+ var codeSlotSeq;
2182
2209
  var init_code_block = __esm({
2183
2210
  "src/plugins/guides/code-block.ts"() {
2184
2211
  init_custom_frame();
2212
+ codeSlotSeq = 0;
2185
2213
  }
2186
2214
  });
2187
2215
 
@@ -2604,6 +2632,18 @@ var init_composite_renderer = __esm({
2604
2632
  anchor = await waitForElement(anchorSelector);
2605
2633
  if (!anchor) return;
2606
2634
  }
2635
+ const blocks = step.blocks ?? [];
2636
+ const soleCode = blocks.length === 1 && blocks[0]?.type === "code" ? blocks[0] : void 0;
2637
+ if (step.presentation === "inline" && anchor && soleCode && !soleCode.sandboxed) {
2638
+ const rawDoc = anchor.ownerDocument ?? document;
2639
+ const { cleanup } = mountCodeBlock(soleCode, rawDoc, context, void 0, {
2640
+ anchor,
2641
+ pos: inlinePosOf(step.inlinePosition)
2642
+ });
2643
+ this.registerCleanup(cleanup);
2644
+ context.onInteraction({ guideId: context.guide.guideId, stepIndex: idx, action: "shown" });
2645
+ return;
2646
+ }
2607
2647
  const { host, root } = this.createHost();
2608
2648
  const doc = root.ownerDocument ?? document;
2609
2649
  const design = step.design ?? {};
@@ -2620,7 +2660,7 @@ var init_composite_renderer = __esm({
2620
2660
  });
2621
2661
  };
2622
2662
  const readers = [];
2623
- this.buildContent(card, step.blocks ?? [], doc, context, idx, readers);
2663
+ this.buildContent(card, step.blocks ?? [], doc, context, idx, readers, host);
2624
2664
  const lastBlock = card.lastElementChild;
2625
2665
  if (lastBlock && !lastBlock.style.marginBottom) lastBlock.style.marginBottom = "0";
2626
2666
  if (design.closeButton !== false) {
@@ -2691,7 +2731,7 @@ var init_composite_renderer = __esm({
2691
2731
  context.onInteraction({ guideId: context.guide.guideId, stepIndex: idx, action: "shown" });
2692
2732
  }
2693
2733
  /** Recorre los bloques en orden y los pinta en la card. */
2694
- buildContent(card, blocks, doc, context, idx, readers) {
2734
+ buildContent(card, blocks, doc, context, idx, readers, host) {
2695
2735
  const emit = (block) => {
2696
2736
  context.onInteraction({
2697
2737
  guideId: context.guide.guideId,
@@ -2725,7 +2765,7 @@ var init_composite_renderer = __esm({
2725
2765
  continue;
2726
2766
  }
2727
2767
  if (b.type === "code") {
2728
- const { node: node2, cleanup } = mountCodeBlock(b, doc, context);
2768
+ const { node: node2, cleanup } = mountCodeBlock(b, doc, context, host);
2729
2769
  if (node2) card.appendChild(node2);
2730
2770
  this.registerCleanup(cleanup);
2731
2771
  i++;