opencode-generative-ui 0.1.2 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +5 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -478,12 +478,13 @@ function escapeJS(s) {
478
478
  .replace(/\r/g, "\\r")
479
479
  .replace(/<\/script>/gi, "<\\/script>");
480
480
  }
481
- function shellHTML(isSVG = false) {
481
+ function shellHTML(code, isSVG = false) {
482
482
  const bodyClass = isSVG ? "oc-svg" : "oc-html";
483
483
  const bodyKind = isSVG ? "svg" : "html";
484
484
  const hint = isSVG
485
485
  ? "Pinch or Cmd/Ctrl + wheel to zoom. Pan with middle-drag, Space + drag, or arrow keys."
486
486
  : "Zoom with pinch or Cmd/Ctrl + wheel. Pan with middle-drag, Space + drag, or arrow keys without breaking widget controls.";
487
+ const escapedCode = escapeJS(code);
487
488
  return `<!DOCTYPE html><html><head><meta charset="utf-8">
488
489
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
489
490
  <style>
@@ -541,6 +542,8 @@ window._runScripts = function() {
541
542
  old.parentNode.replaceChild(s, old);
542
543
  });
543
544
  };
545
+ window._setContent('${escapedCode}');
546
+ window._runScripts();
544
547
  </script>
545
548
  <script>${WIDGET_SHELL_SCRIPT}</script>
546
549
  </body></html>`;
@@ -616,7 +619,7 @@ const showWidget = tool({
616
619
  });
617
620
  let win;
618
621
  try {
619
- win = open(shellHTML(isSVG), {
622
+ win = open(shellHTML(code, isSVG), {
620
623
  width,
621
624
  height,
622
625
  title,
@@ -640,9 +643,6 @@ const showWidget = tool({
640
643
  }
641
644
  resolve(`Widget \"${title}\" rendered and shown to the user (${width}x${height}). ${reason}`);
642
645
  };
643
- win.on("ready", () => {
644
- win.send(`window._setContent('${escapeJS(code)}'); window._runScripts();`);
645
- });
646
646
  win.on("message", (data) => {
647
647
  messageData = data;
648
648
  finish("User sent data from widget.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-generative-ui",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "OpenCode plugin that renders HTML and SVG widgets in native macOS windows using Glimpse.",
5
5
  "type": "module",
6
6
  "exports": "./dist/index.js",