@braincrew-lab/langchain-canvas 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.
- package/dist/index.js +9 -60
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -392,6 +392,14 @@ var INSPECTOR_SCRIPT = `
|
|
|
392
392
|
}, "*");
|
|
393
393
|
}, true);
|
|
394
394
|
|
|
395
|
+
// Block the browser's native drag (images and links start an HTML5 drag on
|
|
396
|
+
// mousemove by default, which hijacks our free-drag \u2014 the image "ghost" gets
|
|
397
|
+
// dragged instead of the element moving). Suppress it for any editable node.
|
|
398
|
+
document.addEventListener("dragstart", function (e) {
|
|
399
|
+
var t = e.target;
|
|
400
|
+
if (t instanceof Element && t.closest("[data-cid]") && !t.hasAttribute("data-lcx")) e.preventDefault();
|
|
401
|
+
}, true);
|
|
402
|
+
|
|
395
403
|
// --- drag: freely move an element anywhere, or marquee-select empty space ----
|
|
396
404
|
document.addEventListener("mousedown", function (e) {
|
|
397
405
|
suppressClick = false; // a fresh press: never carry a stale suppress
|
|
@@ -1768,8 +1776,7 @@ var dataExporters = {
|
|
|
1768
1776
|
{ label: "JSON", extension: "json", mime: MIME.json, build: (a) => JSON.stringify(a.data, null, 2) }
|
|
1769
1777
|
],
|
|
1770
1778
|
slides: [
|
|
1771
|
-
{ label: "PowerPoint", extension: "pptx", mime: MIME.pptx, build: (a) => slidesToPptx(a.data, a.title) }
|
|
1772
|
-
{ label: "Figma (JSON)", extension: "json", mime: MIME.json, build: (a) => slidesToFigmaJson(a.data) }
|
|
1779
|
+
{ label: "PowerPoint", extension: "pptx", mime: MIME.pptx, build: (a) => slidesToPptx(a.data, a.title) }
|
|
1773
1780
|
]
|
|
1774
1781
|
};
|
|
1775
1782
|
function toStandaloneHtml(title, renderedHtml) {
|
|
@@ -1876,52 +1883,6 @@ async function slidesToPptx(data, _title) {
|
|
|
1876
1883
|
}
|
|
1877
1884
|
return await pptx.write({ outputType: "blob" });
|
|
1878
1885
|
}
|
|
1879
|
-
function slidesToFigmaJson(data) {
|
|
1880
|
-
const W = 1280;
|
|
1881
|
-
const H = 720;
|
|
1882
|
-
const GAP = 64;
|
|
1883
|
-
const slides2 = data.slides.length ? data.slides : [{ title: "Empty deck" }];
|
|
1884
|
-
const textNode = (x, y, width, characters, fontSize, fontWeight, align, color = "#1F2328") => ({ type: "text", x, y, width, characters, fontSize, fontWeight, align, color });
|
|
1885
|
-
const frames = slides2.map((slide, i) => {
|
|
1886
|
-
const nodes = [];
|
|
1887
|
-
for (const el of resolveElements(slide)) {
|
|
1888
|
-
if (el.type !== "text") continue;
|
|
1889
|
-
nodes.push(
|
|
1890
|
-
textNode(el.x / 100 * W, el.y / 100 * H, el.w / 100 * W, el.text ?? "", el.fontSize ?? 24, el.bold ? 700 : 400, el.align === "center" ? "CENTER" : "LEFT", el.color ?? slide.textColor ?? "#1F2328")
|
|
1891
|
-
);
|
|
1892
|
-
}
|
|
1893
|
-
return { name: `Slide ${i + 1}`, x: 0, y: i * (H + GAP), width: W, height: H, fill: slide.background ?? "#FFFFFF", nodes };
|
|
1894
|
-
});
|
|
1895
|
-
return JSON.stringify({ type: "langchain-canvas/figma-deck", version: 1, frames }, null, 2);
|
|
1896
|
-
}
|
|
1897
|
-
function slidesToSvg(data) {
|
|
1898
|
-
const W = 1280;
|
|
1899
|
-
const H = 720;
|
|
1900
|
-
const GAP = 64;
|
|
1901
|
-
const slides2 = data.slides.length ? data.slides : [{ title: "Empty deck" }];
|
|
1902
|
-
const totalH = slides2.length * H + (slides2.length - 1) * GAP;
|
|
1903
|
-
const text = (x, y, value, size, anchor, weight, fill = "#1f2328") => `<text x="${x}" y="${y}" font-family="Inter, Arial, sans-serif" font-size="${size}" font-weight="${weight}" text-anchor="${anchor}" fill="${fill}">${escapeXml(value)}</text>`;
|
|
1904
|
-
const frames = slides2.map((slide, i) => {
|
|
1905
|
-
const y = i * (H + GAP);
|
|
1906
|
-
const bg = slide.background ?? "#ffffff";
|
|
1907
|
-
let body = `<rect width="${W}" height="${H}" rx="8" fill="${bg}" stroke="#e5e7eb"/>`;
|
|
1908
|
-
for (const el of resolveElements(slide)) {
|
|
1909
|
-
const ex = el.x / 100 * W;
|
|
1910
|
-
const ey = el.y / 100 * H;
|
|
1911
|
-
const ew = el.w / 100 * W;
|
|
1912
|
-
if (el.type === "text") {
|
|
1913
|
-
const anchor = el.align === "center" ? "middle" : el.align === "right" ? "end" : "start";
|
|
1914
|
-
const ax = el.align === "center" ? ex + ew / 2 : el.align === "right" ? ex + ew : ex;
|
|
1915
|
-
const fs = el.fontSize ?? 24;
|
|
1916
|
-
body += text(ax, ey + fs, el.text ?? "", fs, anchor, el.bold ? 700 : 400, el.color ?? slide.textColor ?? "#1f2328");
|
|
1917
|
-
} else if (el.src) {
|
|
1918
|
-
body += `<image href="${el.src}" x="${ex}" y="${ey}" width="${ew}" height="${el.h / 100 * H}" preserveAspectRatio="xMidYMid meet"/>`;
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
return `<g transform="translate(0 ${y})">${body}</g>`;
|
|
1922
|
-
}).join("");
|
|
1923
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${totalH}" viewBox="0 0 ${W} ${totalH}">${frames}</svg>`;
|
|
1924
|
-
}
|
|
1925
1886
|
function slidesToPrintHtml(data, title) {
|
|
1926
1887
|
const slides2 = data.slides.length ? data.slides : [{ title: "Empty deck" }];
|
|
1927
1888
|
const pages = slides2.map((slide) => {
|
|
@@ -2035,14 +1996,6 @@ function ExportMenu({ artifact: artifact2, getRenderedHtml }) {
|
|
|
2035
1996
|
}
|
|
2036
1997
|
setOpen(false);
|
|
2037
1998
|
};
|
|
2038
|
-
const copyToFigma = async () => {
|
|
2039
|
-
const svg = slidesToSvg(artifact2.data);
|
|
2040
|
-
try {
|
|
2041
|
-
await navigator.clipboard.writeText(svg);
|
|
2042
|
-
} catch {
|
|
2043
|
-
}
|
|
2044
|
-
setOpen(false);
|
|
2045
|
-
};
|
|
2046
1999
|
return /* @__PURE__ */ jsxs("div", { className: "cv-export", children: [
|
|
2047
2000
|
/* @__PURE__ */ jsx(
|
|
2048
2001
|
"button",
|
|
@@ -2065,10 +2018,6 @@ function ExportMenu({ artifact: artifact2, getRenderedHtml }) {
|
|
|
2065
2018
|
"PDF ",
|
|
2066
2019
|
/* @__PURE__ */ jsx("span", { className: "cv-export__ext", children: ".pdf" })
|
|
2067
2020
|
] }),
|
|
2068
|
-
artifact2.type === "slides" && /* @__PURE__ */ jsxs("button", { role: "menuitem", onClick: copyToFigma, children: [
|
|
2069
|
-
"Copy to Figma ",
|
|
2070
|
-
/* @__PURE__ */ jsx("span", { className: "cv-export__ext", children: "paste \u2318V" })
|
|
2071
|
-
] }),
|
|
2072
2021
|
dataOptions.map((option) => /* @__PURE__ */ jsxs("button", { role: "menuitem", onClick: () => exportData(option), children: [
|
|
2073
2022
|
option.label,
|
|
2074
2023
|
" ",
|
package/package.json
CHANGED