@braincrew-lab/langchain-canvas 0.1.0 → 0.1.1
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.js +29 -0
- package/dist/styles.css +10 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1513,6 +1513,31 @@ var TEMPLATES = {
|
|
|
1513
1513
|
</section>`
|
|
1514
1514
|
}
|
|
1515
1515
|
};
|
|
1516
|
+
function SlideView({ html, ratio, title }) {
|
|
1517
|
+
const boxRef = useRef(null);
|
|
1518
|
+
const [scale, setScale] = useState(1);
|
|
1519
|
+
const [rw, rh] = ratio.split(/[:x/]/).map(Number);
|
|
1520
|
+
const DESIGN_W = 1280;
|
|
1521
|
+
const DESIGN_H = rw && rh ? Math.round(DESIGN_W * rh / rw) : 720;
|
|
1522
|
+
useEffect(() => {
|
|
1523
|
+
const el = boxRef.current;
|
|
1524
|
+
if (!el) return;
|
|
1525
|
+
const fit = () => setScale(Math.min(1, (el.clientWidth - 32) / DESIGN_W));
|
|
1526
|
+
fit();
|
|
1527
|
+
const ro = new ResizeObserver(fit);
|
|
1528
|
+
ro.observe(el);
|
|
1529
|
+
return () => ro.disconnect();
|
|
1530
|
+
}, [DESIGN_W]);
|
|
1531
|
+
return /* @__PURE__ */ jsx("div", { ref: boxRef, className: "cv-slideview", children: /* @__PURE__ */ jsx("div", { className: "cv-slideview__frame", style: { width: DESIGN_W * scale, height: DESIGN_H * scale }, children: /* @__PURE__ */ jsx(
|
|
1532
|
+
"iframe",
|
|
1533
|
+
{
|
|
1534
|
+
title,
|
|
1535
|
+
srcDoc: html,
|
|
1536
|
+
sandbox: "allow-scripts allow-popups allow-modals",
|
|
1537
|
+
style: { width: DESIGN_W, height: DESIGN_H, border: 0, transform: `scale(${scale})`, transformOrigin: "top left" }
|
|
1538
|
+
}
|
|
1539
|
+
) }) });
|
|
1540
|
+
}
|
|
1516
1541
|
function HtmlRenderer({ artifact: artifact2 }) {
|
|
1517
1542
|
const iframeRef = useRef(null);
|
|
1518
1543
|
const imgFileRef = useRef(null);
|
|
@@ -1587,6 +1612,10 @@ function HtmlRenderer({ artifact: artifact2 }) {
|
|
|
1587
1612
|
reader.onload = () => sendIframeCommand({ artifactId: artifact2.id, type: "set_src", cid: single.cid, value: String(reader.result) });
|
|
1588
1613
|
reader.readAsDataURL(file);
|
|
1589
1614
|
};
|
|
1615
|
+
const ratio = artifact2.meta?.ratio;
|
|
1616
|
+
if (ratio) {
|
|
1617
|
+
return /* @__PURE__ */ jsx("div", { className: "cv-html-wrap", children: /* @__PURE__ */ jsx(SlideView, { html: artifact2.data.html, ratio, title: artifact2.title }) });
|
|
1618
|
+
}
|
|
1590
1619
|
return /* @__PURE__ */ jsxs("div", { className: "cv-html-wrap", children: [
|
|
1591
1620
|
/* @__PURE__ */ jsx("input", { ref: imgFileRef, type: "file", accept: "image/*", hidden: true, onChange: (e) => {
|
|
1592
1621
|
onImgFile(e.target.files?.[0]);
|
package/dist/styles.css
CHANGED
|
@@ -788,6 +788,16 @@
|
|
|
788
788
|
flex: 1; min-height: 0; overflow: auto; display: flex; justify-content: center;
|
|
789
789
|
padding: 10px; background: var(--cv-surface); border-radius: 10px;
|
|
790
790
|
}
|
|
791
|
+
/* Fixed-aspect slide preview (read-only, scaled to fit). */
|
|
792
|
+
.cv-slideview {
|
|
793
|
+
flex: 1; min-height: 0; overflow: auto; display: flex; justify-content: center; align-items: flex-start;
|
|
794
|
+
padding: 16px; background: var(--cv-surface); border-radius: 10px;
|
|
795
|
+
}
|
|
796
|
+
.cv-slideview__frame {
|
|
797
|
+
position: relative; overflow: hidden; background: #fff; border-radius: 8px;
|
|
798
|
+
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
|
|
799
|
+
}
|
|
800
|
+
.cv-slideview__frame iframe { display: block; }
|
|
791
801
|
.cv-html-code {
|
|
792
802
|
flex: 1; min-height: 0; width: 100%; resize: none;
|
|
793
803
|
padding: 14px 16px; border: 1px solid var(--cv-border); border-radius: 10px;
|
package/package.json
CHANGED