canvu-react 0.3.12 → 0.3.13
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.cjs +94 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +94 -48
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +94 -48
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +94 -48
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +30 -5
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +30 -5
- package/dist/realtime.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1713,7 +1713,8 @@ function collectEraserTargetsAtWorldPoint(items, worldX, worldY, options) {
|
|
|
1713
1713
|
var HYDRATION_CACHE_NAME = "canvu-asset-hydration-v1";
|
|
1714
1714
|
var DEFAULT_PDF_SCALE = 1.15;
|
|
1715
1715
|
var DEFAULT_PDF_PAGE_CONCURRENCY = 2;
|
|
1716
|
-
var
|
|
1716
|
+
var hydrationSourcePromises = /* @__PURE__ */ new Map();
|
|
1717
|
+
var pdfSourceBlobPromises = /* @__PURE__ */ new Map();
|
|
1717
1718
|
function buildImageHydrationKey(assetId) {
|
|
1718
1719
|
return `image:${assetId}`;
|
|
1719
1720
|
}
|
|
@@ -1761,23 +1762,38 @@ async function fetchBlob(url) {
|
|
|
1761
1762
|
return null;
|
|
1762
1763
|
}
|
|
1763
1764
|
}
|
|
1764
|
-
async function
|
|
1765
|
+
async function getHydrationSource(key, preferCachedRasters, loader) {
|
|
1765
1766
|
const cached = preferCachedRasters ? await readCachedHydrationBlob(key) : null;
|
|
1766
|
-
if (cached)
|
|
1767
|
-
|
|
1767
|
+
if (cached) {
|
|
1768
|
+
return {
|
|
1769
|
+
blob: cached
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
const inFlight = hydrationSourcePromises.get(key);
|
|
1768
1773
|
if (inFlight) return await inFlight;
|
|
1769
1774
|
const nextPromise = (async () => {
|
|
1770
|
-
const
|
|
1771
|
-
if (blob) {
|
|
1772
|
-
await writeCachedHydrationBlob(key, blob);
|
|
1775
|
+
const source = await loader();
|
|
1776
|
+
if (source?.blob) {
|
|
1777
|
+
await writeCachedHydrationBlob(key, source.blob);
|
|
1773
1778
|
}
|
|
1774
|
-
return
|
|
1779
|
+
return source;
|
|
1775
1780
|
})();
|
|
1776
|
-
|
|
1781
|
+
hydrationSourcePromises.set(key, nextPromise);
|
|
1777
1782
|
try {
|
|
1778
1783
|
return await nextPromise;
|
|
1779
1784
|
} finally {
|
|
1780
|
-
|
|
1785
|
+
hydrationSourcePromises.delete(key);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
async function getPdfSourceBlob(url) {
|
|
1789
|
+
const inFlight = pdfSourceBlobPromises.get(url);
|
|
1790
|
+
if (inFlight) return await inFlight;
|
|
1791
|
+
const nextPromise = fetchBlob(url);
|
|
1792
|
+
pdfSourceBlobPromises.set(url, nextPromise);
|
|
1793
|
+
try {
|
|
1794
|
+
return await nextPromise;
|
|
1795
|
+
} finally {
|
|
1796
|
+
pdfSourceBlobPromises.delete(url);
|
|
1781
1797
|
}
|
|
1782
1798
|
}
|
|
1783
1799
|
function registerObjectUrl(objectUrls, blob) {
|
|
@@ -1831,18 +1847,22 @@ async function hydrateImageAssets(requests, resolvedAssetUrls, objectUrls, prefe
|
|
|
1831
1847
|
if (!resolvedAsset?.url) {
|
|
1832
1848
|
return [assetId, null];
|
|
1833
1849
|
}
|
|
1834
|
-
const
|
|
1850
|
+
const source = await getHydrationSource(
|
|
1835
1851
|
buildImageHydrationKey(assetId),
|
|
1836
1852
|
preferCachedRasters,
|
|
1837
|
-
async () =>
|
|
1853
|
+
async () => {
|
|
1854
|
+
const blob = await fetchBlob(resolvedAsset.url);
|
|
1855
|
+
if (!blob) return null;
|
|
1856
|
+
return { blob };
|
|
1857
|
+
}
|
|
1838
1858
|
);
|
|
1839
|
-
if (!blob) {
|
|
1859
|
+
if (!source?.blob) {
|
|
1840
1860
|
return [assetId, null];
|
|
1841
1861
|
}
|
|
1842
1862
|
return [
|
|
1843
1863
|
assetId,
|
|
1844
1864
|
{
|
|
1845
|
-
href: registerObjectUrl(objectUrls, blob)
|
|
1865
|
+
href: registerObjectUrl(objectUrls, source.blob)
|
|
1846
1866
|
}
|
|
1847
1867
|
];
|
|
1848
1868
|
})
|
|
@@ -1857,45 +1877,69 @@ async function hydratePdfAssets(requests, resolvedAssetUrls, objectUrls, options
|
|
|
1857
1877
|
if (!resolvedAsset?.url) {
|
|
1858
1878
|
continue;
|
|
1859
1879
|
}
|
|
1860
|
-
const
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1880
|
+
const pageKeys = group.pageNumbers.map((pageNumber) => ({
|
|
1881
|
+
pageNumber,
|
|
1882
|
+
cacheKey: buildPdfHydrationKey(group.assetId, pageNumber, group.scale)
|
|
1883
|
+
}));
|
|
1884
|
+
const pagesToRender = [];
|
|
1885
|
+
for (const { pageNumber, cacheKey } of pageKeys) {
|
|
1886
|
+
const cachedBlob = options.preferCachedRasters ? await readCachedHydrationBlob(cacheKey) : null;
|
|
1887
|
+
if (cachedBlob) {
|
|
1888
|
+
hydratedPages.set(cacheKey, {
|
|
1889
|
+
href: registerObjectUrl(objectUrls, cachedBlob)
|
|
1890
|
+
});
|
|
1866
1891
|
continue;
|
|
1867
1892
|
}
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
if (missingPages.length === 0) {
|
|
1873
|
-
continue;
|
|
1893
|
+
if (!hydrationSourcePromises.has(cacheKey)) {
|
|
1894
|
+
pagesToRender.push({ pageNumber, cacheKey });
|
|
1895
|
+
}
|
|
1874
1896
|
}
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1897
|
+
if (pagesToRender.length > 0) {
|
|
1898
|
+
const renderPromise = (async () => {
|
|
1899
|
+
const pdfBlob = await getPdfSourceBlob(resolvedAsset.url);
|
|
1900
|
+
if (!pdfBlob) {
|
|
1901
|
+
return /* @__PURE__ */ new Map();
|
|
1902
|
+
}
|
|
1903
|
+
const renderedPages = await loadPdfToStore(pdfBlob, options.imageStore, {
|
|
1904
|
+
scale: group.scale,
|
|
1905
|
+
pageNumbers: pagesToRender.map(({ pageNumber }) => pageNumber),
|
|
1906
|
+
pageConcurrency: options.pdfPageConcurrency
|
|
1907
|
+
});
|
|
1908
|
+
const renderedByPage = /* @__PURE__ */ new Map();
|
|
1909
|
+
for (const renderedPage of renderedPages) {
|
|
1910
|
+
const pageBlob = await options.imageStore.getOriginal(renderedPage.blobId);
|
|
1911
|
+
renderedByPage.set(
|
|
1912
|
+
renderedPage.pageNumber,
|
|
1913
|
+
pageBlob ? {
|
|
1914
|
+
blob: pageBlob,
|
|
1915
|
+
width: renderedPage.width,
|
|
1916
|
+
height: renderedPage.height
|
|
1917
|
+
} : null
|
|
1918
|
+
);
|
|
1919
|
+
}
|
|
1920
|
+
return renderedByPage;
|
|
1921
|
+
})();
|
|
1922
|
+
for (const { pageNumber, cacheKey } of pagesToRender) {
|
|
1923
|
+
const pagePromise = getHydrationSource(
|
|
1924
|
+
cacheKey,
|
|
1925
|
+
options.preferCachedRasters,
|
|
1926
|
+
async () => (await renderPromise).get(pageNumber) ?? null
|
|
1927
|
+
);
|
|
1928
|
+
hydrationSourcePromises.set(cacheKey, pagePromise);
|
|
1929
|
+
}
|
|
1878
1930
|
}
|
|
1879
|
-
const
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
const cacheKey = buildPdfHydrationKey(
|
|
1886
|
-
group.assetId,
|
|
1887
|
-
renderedPage.pageNumber,
|
|
1888
|
-
group.scale
|
|
1931
|
+
for (const { cacheKey } of pageKeys) {
|
|
1932
|
+
if (hydratedPages.has(cacheKey)) continue;
|
|
1933
|
+
const source = await getHydrationSource(
|
|
1934
|
+
cacheKey,
|
|
1935
|
+
options.preferCachedRasters,
|
|
1936
|
+
async () => null
|
|
1889
1937
|
);
|
|
1890
|
-
|
|
1891
|
-
if (!pageBlob) {
|
|
1892
|
-
continue;
|
|
1893
|
-
}
|
|
1894
|
-
await writeCachedHydrationBlob(cacheKey, pageBlob);
|
|
1938
|
+
if (!source?.blob) continue;
|
|
1895
1939
|
hydratedPages.set(cacheKey, {
|
|
1896
|
-
href: registerObjectUrl(objectUrls,
|
|
1897
|
-
width:
|
|
1898
|
-
height:
|
|
1940
|
+
href: registerObjectUrl(objectUrls, source.blob),
|
|
1941
|
+
width: source.width,
|
|
1942
|
+
height: source.height
|
|
1899
1943
|
});
|
|
1900
1944
|
}
|
|
1901
1945
|
}
|
|
@@ -1936,7 +1980,9 @@ async function hydrateSceneItemsWithAssets(items, assetStore, options = {}) {
|
|
|
1936
1980
|
objectUrls,
|
|
1937
1981
|
{
|
|
1938
1982
|
imageStore,
|
|
1939
|
-
pdfPageConcurrency
|
|
1983
|
+
pdfPageConcurrency,
|
|
1984
|
+
preferCachedRasters
|
|
1985
|
+
}
|
|
1940
1986
|
);
|
|
1941
1987
|
return {
|
|
1942
1988
|
items: items.map((item) => {
|