canvu-react 0.3.19 → 0.3.20
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/react.cjs +45 -24
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +45 -24
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.cjs
CHANGED
|
@@ -5945,6 +5945,39 @@ var VectorScene = class {
|
|
|
5945
5945
|
// src/react/VectorViewport.tsx
|
|
5946
5946
|
init_shape_builders();
|
|
5947
5947
|
|
|
5948
|
+
// src/react/blob-url-lifecycle.ts
|
|
5949
|
+
var SVG_BLOB_HREF_PATTERN = /\b(?:href|xlink:href)=["'](blob:[^"']+)["']/g;
|
|
5950
|
+
function collectImageBlobHrefs(items) {
|
|
5951
|
+
const hrefs = /* @__PURE__ */ new Set();
|
|
5952
|
+
for (const item of items) {
|
|
5953
|
+
if (item.toolKind !== "image") continue;
|
|
5954
|
+
if (item.imageRasterHref?.startsWith("blob:")) {
|
|
5955
|
+
hrefs.add(item.imageRasterHref);
|
|
5956
|
+
}
|
|
5957
|
+
if (item.imageThumbnailHref?.startsWith("blob:")) {
|
|
5958
|
+
hrefs.add(item.imageThumbnailHref);
|
|
5959
|
+
}
|
|
5960
|
+
for (const match of item.childrenSvg.matchAll(SVG_BLOB_HREF_PATTERN)) {
|
|
5961
|
+
const href = match[1];
|
|
5962
|
+
if (href) {
|
|
5963
|
+
hrefs.add(href);
|
|
5964
|
+
}
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
return hrefs;
|
|
5968
|
+
}
|
|
5969
|
+
function rememberImageBlobHrefs(items, rememberedHrefs) {
|
|
5970
|
+
for (const href of collectImageBlobHrefs(items)) {
|
|
5971
|
+
rememberedHrefs.add(href);
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
function releaseRememberedBlobHrefs(rememberedHrefs, releaseHref) {
|
|
5975
|
+
for (const href of rememberedHrefs) {
|
|
5976
|
+
releaseHref(href);
|
|
5977
|
+
}
|
|
5978
|
+
rememberedHrefs.clear();
|
|
5979
|
+
}
|
|
5980
|
+
|
|
5948
5981
|
// src/react/InteractionOverlay.tsx
|
|
5949
5982
|
init_rect();
|
|
5950
5983
|
|
|
@@ -7298,6 +7331,7 @@ var VectorViewport = react.forwardRef(
|
|
|
7298
7331
|
if (typeof indexedDB !== "undefined" && !imageStoreRef.current) {
|
|
7299
7332
|
imageStoreRef.current = new IndexedDbImageStore();
|
|
7300
7333
|
}
|
|
7334
|
+
const rememberedImageBlobHrefsRef = react.useRef(/* @__PURE__ */ new Set());
|
|
7301
7335
|
const strokeStyleRef = react.useRef({ ...DEFAULT_STROKE_STYLE });
|
|
7302
7336
|
const [strokeStyleState, setStrokeStyleState] = react.useState({
|
|
7303
7337
|
...DEFAULT_STROKE_STYLE
|
|
@@ -7330,11 +7364,7 @@ var VectorViewport = react.forwardRef(
|
|
|
7330
7364
|
const existing = list.find((i) => i.id === item.id);
|
|
7331
7365
|
if (!existing || existing.toolKind !== "image" || !existing.imageIntrinsicSize)
|
|
7332
7366
|
return;
|
|
7333
|
-
const { imageIntrinsicSize: isize
|
|
7334
|
-
const needsSwap = imageThumbnailHref?.startsWith("blob:");
|
|
7335
|
-
if (needsSwap && imageThumbnailHref) {
|
|
7336
|
-
URL.revokeObjectURL(imageThumbnailHref);
|
|
7337
|
-
}
|
|
7367
|
+
const { imageIntrinsicSize: isize } = existing;
|
|
7338
7368
|
const rebuilt = {
|
|
7339
7369
|
...existing,
|
|
7340
7370
|
imageThumbnailHref: void 0,
|
|
@@ -7630,27 +7660,18 @@ var VectorViewport = react.forwardRef(
|
|
|
7630
7660
|
setEditingTextId(null);
|
|
7631
7661
|
}
|
|
7632
7662
|
}, [items, editingTextId]);
|
|
7633
|
-
const itemsSnapshotForBlobRef = react.useRef([]);
|
|
7634
7663
|
react.useEffect(() => {
|
|
7635
|
-
|
|
7636
|
-
itemsSnapshotForBlobRef.current = items;
|
|
7637
|
-
const blobHrefs = (list) => {
|
|
7638
|
-
const s = /* @__PURE__ */ new Set();
|
|
7639
|
-
for (const it of list) {
|
|
7640
|
-
if (it.toolKind === "image" && it.imageRasterHref?.startsWith("blob:")) {
|
|
7641
|
-
s.add(it.imageRasterHref);
|
|
7642
|
-
}
|
|
7643
|
-
}
|
|
7644
|
-
return s;
|
|
7645
|
-
};
|
|
7646
|
-
const before = blobHrefs(prev);
|
|
7647
|
-
const after = blobHrefs(items);
|
|
7648
|
-
for (const href of before) {
|
|
7649
|
-
if (!after.has(href)) {
|
|
7650
|
-
URL.revokeObjectURL(href);
|
|
7651
|
-
}
|
|
7652
|
-
}
|
|
7664
|
+
rememberImageBlobHrefs(items, rememberedImageBlobHrefsRef.current);
|
|
7653
7665
|
}, [items]);
|
|
7666
|
+
react.useEffect(
|
|
7667
|
+
() => () => {
|
|
7668
|
+
releaseRememberedBlobHrefs(
|
|
7669
|
+
rememberedImageBlobHrefsRef.current,
|
|
7670
|
+
(href) => URL.revokeObjectURL(href)
|
|
7671
|
+
);
|
|
7672
|
+
},
|
|
7673
|
+
[]
|
|
7674
|
+
);
|
|
7654
7675
|
const PASTE_OFFSET_WORLD = 24;
|
|
7655
7676
|
const copyIdsToInternalClipboard = react.useCallback((ids) => {
|
|
7656
7677
|
if (ids.length === 0) return;
|