@effing/canvas 0.31.2 → 0.31.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 +46 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1498,7 +1498,7 @@ function resolveInheritedStyle(merged, color, parent) {
|
|
|
1498
1498
|
function normalizeChildren(node) {
|
|
1499
1499
|
const raw = node.children ?? node.props.children;
|
|
1500
1500
|
if (raw == null) return [];
|
|
1501
|
-
return Array.isArray(raw) ? raw : [raw];
|
|
1501
|
+
return Array.isArray(raw) ? raw.flat(Infinity) : [raw];
|
|
1502
1502
|
}
|
|
1503
1503
|
|
|
1504
1504
|
// src/jsx/draw/svg/defs.ts
|
|
@@ -1508,6 +1508,8 @@ function collectDefs(children) {
|
|
|
1508
1508
|
const masks = /* @__PURE__ */ new Map();
|
|
1509
1509
|
const filters = /* @__PURE__ */ new Map();
|
|
1510
1510
|
function insertDef(def) {
|
|
1511
|
+
if (!def || typeof def !== "object" || !("props" in def) || !def.props)
|
|
1512
|
+
return;
|
|
1511
1513
|
const id = def.props.id;
|
|
1512
1514
|
if (!id) return;
|
|
1513
1515
|
if (def.type === "clipPath") clips.set(id, normalizeChildren(def));
|
|
@@ -2394,9 +2396,9 @@ function drawSvgContainer(ctx, node, x, y, width, height) {
|
|
|
2394
2396
|
const inherited = resolveInheritedStyle(merged, color);
|
|
2395
2397
|
const children = node.props.children;
|
|
2396
2398
|
if (children != null) {
|
|
2397
|
-
const childArray = Array.isArray(children) ? children : [children];
|
|
2399
|
+
const childArray = Array.isArray(children) ? children.flat(Infinity) : [children];
|
|
2398
2400
|
const svgChildren = childArray.filter(
|
|
2399
|
-
(c) => c != null && typeof c === "object"
|
|
2401
|
+
(c) => c != null && typeof c === "object" && !Array.isArray(c)
|
|
2400
2402
|
);
|
|
2401
2403
|
const defs = collectDefs(svgChildren);
|
|
2402
2404
|
for (const child of svgChildren) {
|
|
@@ -3631,11 +3633,12 @@ async function buildNode(element, parentStyle, yogaNode, viewportWidth, viewport
|
|
|
3631
3633
|
}
|
|
3632
3634
|
applyStylesToYoga(yogaNode, style);
|
|
3633
3635
|
if (tagName === "svg") {
|
|
3636
|
+
const resolvedChildren = resolveSvgTree(props.children);
|
|
3634
3637
|
return {
|
|
3635
3638
|
type: tagName,
|
|
3636
3639
|
style,
|
|
3637
3640
|
children: [],
|
|
3638
|
-
props,
|
|
3641
|
+
props: { ...props, children: resolvedChildren },
|
|
3639
3642
|
yogaNode
|
|
3640
3643
|
};
|
|
3641
3644
|
}
|
|
@@ -3757,6 +3760,45 @@ function extractTextContent(children) {
|
|
|
3757
3760
|
}
|
|
3758
3761
|
return void 0;
|
|
3759
3762
|
}
|
|
3763
|
+
function resolveSvgTree(node) {
|
|
3764
|
+
if (node === null || node === void 0 || typeof node === "boolean")
|
|
3765
|
+
return null;
|
|
3766
|
+
if (typeof node === "string" || typeof node === "number") return node;
|
|
3767
|
+
if (Array.isArray(node)) {
|
|
3768
|
+
const out = [];
|
|
3769
|
+
let changed = false;
|
|
3770
|
+
for (const child of node) {
|
|
3771
|
+
const resolved = resolveSvgTree(child);
|
|
3772
|
+
if (resolved === null || resolved === void 0) {
|
|
3773
|
+
changed = true;
|
|
3774
|
+
continue;
|
|
3775
|
+
}
|
|
3776
|
+
if (Array.isArray(resolved)) {
|
|
3777
|
+
changed = true;
|
|
3778
|
+
for (const r of resolved) out.push(r);
|
|
3779
|
+
} else {
|
|
3780
|
+
if (resolved !== child) changed = true;
|
|
3781
|
+
out.push(resolved);
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
return changed ? out : node;
|
|
3785
|
+
}
|
|
3786
|
+
const el = node;
|
|
3787
|
+
if (typeof el.type === "function") {
|
|
3788
|
+
const rendered = el.type(
|
|
3789
|
+
el.props ?? {}
|
|
3790
|
+
);
|
|
3791
|
+
return resolveSvgTree(rendered);
|
|
3792
|
+
}
|
|
3793
|
+
const elProps = el.props ?? {};
|
|
3794
|
+
if (elProps.children !== void 0) {
|
|
3795
|
+
const resolvedChildren = resolveSvgTree(elProps.children);
|
|
3796
|
+
if (resolvedChildren !== elProps.children) {
|
|
3797
|
+
return { ...el, props: { ...elProps, children: resolvedChildren } };
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
return el;
|
|
3801
|
+
}
|
|
3760
3802
|
function hasElementChildren(children) {
|
|
3761
3803
|
if (children === void 0 || children === null || typeof children === "boolean")
|
|
3762
3804
|
return false;
|