@pixerate/editor-react 0.75.0 → 0.75.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/vector/index.cjs +30 -46
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +43 -59
- package/dist/vector/index.js.map +1 -1
- package/package.json +3 -3
package/dist/vector/index.cjs
CHANGED
|
@@ -277,48 +277,19 @@ function VectorTextElement({ node }) {
|
|
|
277
277
|
)) });
|
|
278
278
|
}
|
|
279
279
|
function VectorSceneNodes({ nodes }) {
|
|
280
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: nodes.map(
|
|
281
|
-
(node) => node.kind === "text" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorTextElement, { node }, node.id) : node.kind === "group" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
282
|
-
"g",
|
|
283
|
-
{
|
|
284
|
-
"data-vector-id": node.id,
|
|
285
|
-
"data-vector-mask": node.mask?.type,
|
|
286
|
-
transform: node.transform,
|
|
287
|
-
opacity: node.opacity < 1 ? node.opacity : void 0,
|
|
288
|
-
filter: node.filter,
|
|
289
|
-
style: blendStyle(node.blendMode),
|
|
290
|
-
children: node.mask ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorMaskedNodes, { mask: node.mask, nodes: node.children }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorSceneNodes, { nodes: node.children })
|
|
291
|
-
},
|
|
292
|
-
node.id
|
|
293
|
-
) : node.layers ? (
|
|
294
|
-
// Fill and stroke stacks: each layer in order, bottom to top.
|
|
295
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
296
|
-
"g",
|
|
297
|
-
{
|
|
298
|
-
"data-vector-id": node.id,
|
|
299
|
-
transform: node.transform,
|
|
300
|
-
opacity: node.opacity < 1 ? node.opacity : void 0,
|
|
301
|
-
filter: node.filter,
|
|
302
|
-
style: blendStyle(node.blendMode),
|
|
303
|
-
children: node.layers.map((layer) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorPaintPath, { paint: layer, d: node.d, fillRule: node.fillRule, layer: `${layer.kind}-${layer.index}` }, `${layer.kind}-${layer.index}`))
|
|
304
|
-
},
|
|
305
|
-
node.id
|
|
306
|
-
)
|
|
307
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
308
|
-
VectorPaintPath,
|
|
309
|
-
{
|
|
310
|
-
paint: node,
|
|
311
|
-
d: node.d,
|
|
312
|
-
fillRule: node.fillRule,
|
|
313
|
-
id: node.id,
|
|
314
|
-
transform: node.transform,
|
|
315
|
-
filter: node.filter,
|
|
316
|
-
blendMode: node.blendMode
|
|
317
|
-
},
|
|
318
|
-
node.id
|
|
319
|
-
)
|
|
320
|
-
) });
|
|
280
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: nodes.map((node) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorSceneNode, { node }, node.id)) });
|
|
321
281
|
}
|
|
282
|
+
var VectorSceneNode = import_react3.default.memo(function VectorSceneNode2({ node }) {
|
|
283
|
+
if (node.kind === "text") return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorTextElement, { node });
|
|
284
|
+
if (node.kind === "group")
|
|
285
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("g", { "data-vector-id": node.id, "data-vector-mask": node.mask?.type, transform: node.transform, opacity: node.opacity < 1 ? node.opacity : void 0, filter: node.filter, style: blendStyle(node.blendMode), children: node.mask ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorMaskedNodes, { mask: node.mask, nodes: node.children }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorSceneNodes, { nodes: node.children }) });
|
|
286
|
+
if (node.layers)
|
|
287
|
+
return (
|
|
288
|
+
// Fill and stroke stacks: each layer in order, bottom to top.
|
|
289
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("g", { "data-vector-id": node.id, transform: node.transform, opacity: node.opacity < 1 ? node.opacity : void 0, filter: node.filter, style: blendStyle(node.blendMode), children: node.layers.map((layer) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorPaintPath, { paint: layer, d: node.d, fillRule: node.fillRule, layer: `${layer.kind}-${layer.index}` }, `${layer.kind}-${layer.index}`)) })
|
|
290
|
+
);
|
|
291
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VectorPaintPath, { paint: node, d: node.d, fillRule: node.fillRule, id: node.id, transform: node.transform, filter: node.filter, blendMode: node.blendMode });
|
|
292
|
+
});
|
|
322
293
|
function VectorMaskedNodes({ mask, nodes }) {
|
|
323
294
|
const b = mask.bounds;
|
|
324
295
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
@@ -413,7 +384,8 @@ function VectorCanvas({
|
|
|
413
384
|
const editingText = state.textEdit?.nodeId ?? null;
|
|
414
385
|
const fitted = (0, import_react3.useRef)(!fitOnMount);
|
|
415
386
|
const uid = (0, import_react3.useId)().replace(/:/g, "");
|
|
416
|
-
const
|
|
387
|
+
const [size, setSize] = (0, import_react3.useState)(null);
|
|
388
|
+
const scene = (0, import_vector3.getVectorSceneRenderData)(state, { idPrefix: `ve${uid}-`, ...size ? { viewportSize: size } : {} });
|
|
417
389
|
const overlay = (0, import_vector3.getVectorOverlayRenderData)(state);
|
|
418
390
|
const host = (0, import_vector3.getVectorSymbolEditBackground)(state, { idPrefix: `ve${uid}-host-` });
|
|
419
391
|
(0, import_react3.useEffect)(() => {
|
|
@@ -431,6 +403,18 @@ function VectorCanvas({
|
|
|
431
403
|
observer.observe(el);
|
|
432
404
|
return () => observer.disconnect();
|
|
433
405
|
}, [controller]);
|
|
406
|
+
(0, import_react3.useEffect)(() => {
|
|
407
|
+
const el = svgRef.current;
|
|
408
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
409
|
+
const measure = () => {
|
|
410
|
+
const r = el.getBoundingClientRect();
|
|
411
|
+
if (r.width > 0 && r.height > 0) setSize((s) => s && s.width === r.width && s.height === r.height ? s : { width: r.width, height: r.height });
|
|
412
|
+
};
|
|
413
|
+
measure();
|
|
414
|
+
const observer = new ResizeObserver(measure);
|
|
415
|
+
observer.observe(el);
|
|
416
|
+
return () => observer.disconnect();
|
|
417
|
+
}, []);
|
|
434
418
|
(0, import_react3.useEffect)(() => {
|
|
435
419
|
if (!editingText) return;
|
|
436
420
|
const t = setTimeout(() => textRef.current?.focus({ preventScroll: true }), 0);
|
|
@@ -566,8 +550,8 @@ function VectorCanvas({
|
|
|
566
550
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: h.x, cy: h.y, r: import_vector3.VECTOR_OVERLAY_THEME.handleRadius + (h.hovered || h.active ? 1 : 0), fill: h.active ? accentColor : import_vector3.VECTOR_OVERLAY_THEME.handleFill, stroke: accentColor })
|
|
567
551
|
] }, h.index)),
|
|
568
552
|
overlay.envelope.anchors.map((a) => {
|
|
569
|
-
const
|
|
570
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { "data-vector-envelope-anchor": a.index, x: a.x -
|
|
553
|
+
const size2 = as + (a.hovered || a.active ? 2 : 0);
|
|
554
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { "data-vector-envelope-anchor": a.index, x: a.x - size2 / 2, y: a.y - size2 / 2, width: size2, height: size2, fill: a.active ? accentColor : import_vector3.VECTOR_OVERLAY_THEME.handleFill, stroke: accentColor }, a.index);
|
|
571
555
|
})
|
|
572
556
|
] }),
|
|
573
557
|
overlay.handles.map((h) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("g", { "data-vector-handle": h.ref.handle, children: [
|
|
@@ -575,10 +559,10 @@ function VectorCanvas({
|
|
|
575
559
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: h.x, cy: h.y, r: import_vector3.VECTOR_OVERLAY_THEME.handleRadius + (h.hovered ? 1 : 0), fill: import_vector3.VECTOR_OVERLAY_THEME.handleFill, stroke: accentColor })
|
|
576
560
|
] }, `${h.ref.nodeId}:${h.ref.subpath}:${h.ref.index}:${h.ref.handle}`)),
|
|
577
561
|
overlay.anchors.map((a) => {
|
|
578
|
-
const
|
|
562
|
+
const size2 = as + (a.hovered ? 2 : 0);
|
|
579
563
|
const fill = a.selected ? accentColor : import_vector3.VECTOR_OVERLAY_THEME.handleFill;
|
|
580
564
|
const key = `${a.ref.nodeId}:${a.ref.subpath}:${a.ref.index}`;
|
|
581
|
-
return a.type === "corner" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { "data-vector-anchor": a.ref.index, x: a.x -
|
|
565
|
+
return a.type === "corner" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { "data-vector-anchor": a.ref.index, x: a.x - size2 / 2, y: a.y - size2 / 2, width: size2, height: size2, fill, stroke: accentColor }, key) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { "data-vector-anchor": a.ref.index, cx: a.x, cy: a.y, r: size2 / 2, fill, stroke: accentColor }, key);
|
|
582
566
|
}),
|
|
583
567
|
overlay.cornerWidgets.map((w) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("g", { "data-vector-corner-widget": w.ref.index, "data-corner-kind": w.kind, children: [
|
|
584
568
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: w.x, cy: w.y, r: import_vector3.VECTOR_OVERLAY_THEME.cornerWidgetRadius + (w.hovered ? 1 : 0), fill: import_vector3.VECTOR_OVERLAY_THEME.handleFill, stroke: accentColor }),
|