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