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.js
CHANGED
|
@@ -5938,6 +5938,39 @@ var VectorScene = class {
|
|
|
5938
5938
|
// src/react/VectorViewport.tsx
|
|
5939
5939
|
init_shape_builders();
|
|
5940
5940
|
|
|
5941
|
+
// src/react/blob-url-lifecycle.ts
|
|
5942
|
+
var SVG_BLOB_HREF_PATTERN = /\b(?:href|xlink:href)=["'](blob:[^"']+)["']/g;
|
|
5943
|
+
function collectImageBlobHrefs(items) {
|
|
5944
|
+
const hrefs = /* @__PURE__ */ new Set();
|
|
5945
|
+
for (const item of items) {
|
|
5946
|
+
if (item.toolKind !== "image") continue;
|
|
5947
|
+
if (item.imageRasterHref?.startsWith("blob:")) {
|
|
5948
|
+
hrefs.add(item.imageRasterHref);
|
|
5949
|
+
}
|
|
5950
|
+
if (item.imageThumbnailHref?.startsWith("blob:")) {
|
|
5951
|
+
hrefs.add(item.imageThumbnailHref);
|
|
5952
|
+
}
|
|
5953
|
+
for (const match of item.childrenSvg.matchAll(SVG_BLOB_HREF_PATTERN)) {
|
|
5954
|
+
const href = match[1];
|
|
5955
|
+
if (href) {
|
|
5956
|
+
hrefs.add(href);
|
|
5957
|
+
}
|
|
5958
|
+
}
|
|
5959
|
+
}
|
|
5960
|
+
return hrefs;
|
|
5961
|
+
}
|
|
5962
|
+
function rememberImageBlobHrefs(items, rememberedHrefs) {
|
|
5963
|
+
for (const href of collectImageBlobHrefs(items)) {
|
|
5964
|
+
rememberedHrefs.add(href);
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
function releaseRememberedBlobHrefs(rememberedHrefs, releaseHref) {
|
|
5968
|
+
for (const href of rememberedHrefs) {
|
|
5969
|
+
releaseHref(href);
|
|
5970
|
+
}
|
|
5971
|
+
rememberedHrefs.clear();
|
|
5972
|
+
}
|
|
5973
|
+
|
|
5941
5974
|
// src/react/InteractionOverlay.tsx
|
|
5942
5975
|
init_rect();
|
|
5943
5976
|
|
|
@@ -7291,6 +7324,7 @@ var VectorViewport = forwardRef(
|
|
|
7291
7324
|
if (typeof indexedDB !== "undefined" && !imageStoreRef.current) {
|
|
7292
7325
|
imageStoreRef.current = new IndexedDbImageStore();
|
|
7293
7326
|
}
|
|
7327
|
+
const rememberedImageBlobHrefsRef = useRef(/* @__PURE__ */ new Set());
|
|
7294
7328
|
const strokeStyleRef = useRef({ ...DEFAULT_STROKE_STYLE });
|
|
7295
7329
|
const [strokeStyleState, setStrokeStyleState] = useState({
|
|
7296
7330
|
...DEFAULT_STROKE_STYLE
|
|
@@ -7323,11 +7357,7 @@ var VectorViewport = forwardRef(
|
|
|
7323
7357
|
const existing = list.find((i) => i.id === item.id);
|
|
7324
7358
|
if (!existing || existing.toolKind !== "image" || !existing.imageIntrinsicSize)
|
|
7325
7359
|
return;
|
|
7326
|
-
const { imageIntrinsicSize: isize
|
|
7327
|
-
const needsSwap = imageThumbnailHref?.startsWith("blob:");
|
|
7328
|
-
if (needsSwap && imageThumbnailHref) {
|
|
7329
|
-
URL.revokeObjectURL(imageThumbnailHref);
|
|
7330
|
-
}
|
|
7360
|
+
const { imageIntrinsicSize: isize } = existing;
|
|
7331
7361
|
const rebuilt = {
|
|
7332
7362
|
...existing,
|
|
7333
7363
|
imageThumbnailHref: void 0,
|
|
@@ -7623,27 +7653,18 @@ var VectorViewport = forwardRef(
|
|
|
7623
7653
|
setEditingTextId(null);
|
|
7624
7654
|
}
|
|
7625
7655
|
}, [items, editingTextId]);
|
|
7626
|
-
const itemsSnapshotForBlobRef = useRef([]);
|
|
7627
7656
|
useEffect(() => {
|
|
7628
|
-
|
|
7629
|
-
itemsSnapshotForBlobRef.current = items;
|
|
7630
|
-
const blobHrefs = (list) => {
|
|
7631
|
-
const s = /* @__PURE__ */ new Set();
|
|
7632
|
-
for (const it of list) {
|
|
7633
|
-
if (it.toolKind === "image" && it.imageRasterHref?.startsWith("blob:")) {
|
|
7634
|
-
s.add(it.imageRasterHref);
|
|
7635
|
-
}
|
|
7636
|
-
}
|
|
7637
|
-
return s;
|
|
7638
|
-
};
|
|
7639
|
-
const before = blobHrefs(prev);
|
|
7640
|
-
const after = blobHrefs(items);
|
|
7641
|
-
for (const href of before) {
|
|
7642
|
-
if (!after.has(href)) {
|
|
7643
|
-
URL.revokeObjectURL(href);
|
|
7644
|
-
}
|
|
7645
|
-
}
|
|
7657
|
+
rememberImageBlobHrefs(items, rememberedImageBlobHrefsRef.current);
|
|
7646
7658
|
}, [items]);
|
|
7659
|
+
useEffect(
|
|
7660
|
+
() => () => {
|
|
7661
|
+
releaseRememberedBlobHrefs(
|
|
7662
|
+
rememberedImageBlobHrefsRef.current,
|
|
7663
|
+
(href) => URL.revokeObjectURL(href)
|
|
7664
|
+
);
|
|
7665
|
+
},
|
|
7666
|
+
[]
|
|
7667
|
+
);
|
|
7647
7668
|
const PASTE_OFFSET_WORLD = 24;
|
|
7648
7669
|
const copyIdsToInternalClipboard = useCallback((ids) => {
|
|
7649
7670
|
if (ids.length === 0) return;
|