@pixldocs/canvas-renderer 0.5.12 → 0.5.14
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 +89 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +89 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2699,18 +2699,37 @@ const clearFabricCharCache = () => {
|
|
|
2699
2699
|
};
|
|
2700
2700
|
const clearFontCacheAndRerender = (canvas) => {
|
|
2701
2701
|
clearFabricCharCache();
|
|
2702
|
-
const
|
|
2702
|
+
const resetTextboxLayoutInternals = (obj) => {
|
|
2703
2703
|
var _a;
|
|
2704
|
+
(_a = obj._clearCache) == null ? void 0 : _a.call(obj);
|
|
2705
|
+
obj.__charBounds = [];
|
|
2706
|
+
obj.__lineWidths = [];
|
|
2707
|
+
obj.__lineHeights = [];
|
|
2708
|
+
obj.__graphemeLines = [];
|
|
2709
|
+
obj._textLines = [];
|
|
2710
|
+
obj.textLines = [];
|
|
2711
|
+
obj._styleMap = null;
|
|
2712
|
+
obj.styleMap = null;
|
|
2713
|
+
obj.dirty = true;
|
|
2714
|
+
};
|
|
2715
|
+
const fixTextbox = (obj) => {
|
|
2716
|
+
var _a, _b;
|
|
2704
2717
|
if (obj instanceof fabric.Textbox) {
|
|
2705
2718
|
const savedWidth = obj.width;
|
|
2706
|
-
|
|
2719
|
+
const savedScaleX = obj.scaleX;
|
|
2720
|
+
const savedScaleY = obj.scaleY;
|
|
2721
|
+
resetTextboxLayoutInternals(obj);
|
|
2707
2722
|
obj.initDimensions();
|
|
2708
|
-
if (savedWidth != null
|
|
2709
|
-
obj.width
|
|
2723
|
+
if (savedWidth != null) {
|
|
2724
|
+
obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY });
|
|
2725
|
+
resetTextboxLayoutInternals(obj);
|
|
2726
|
+
obj.initDimensions();
|
|
2727
|
+
obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY, dirty: true });
|
|
2710
2728
|
}
|
|
2729
|
+
(_a = obj._clearCache) == null ? void 0 : _a.call(obj);
|
|
2711
2730
|
obj.setCoords();
|
|
2712
2731
|
} else if (obj instanceof fabric.Group) {
|
|
2713
|
-
(
|
|
2732
|
+
(_b = obj._objects) == null ? void 0 : _b.forEach(fixTextbox);
|
|
2714
2733
|
obj.dirty = true;
|
|
2715
2734
|
obj.setCoords();
|
|
2716
2735
|
}
|
|
@@ -11824,6 +11843,7 @@ function PixldocsPreview(props) {
|
|
|
11824
11843
|
const [fontsReady, setFontsReady] = useState(false);
|
|
11825
11844
|
const [fontsReadyVersion, setFontsReadyVersion] = useState(0);
|
|
11826
11845
|
const [canvasSettled, setCanvasSettled] = useState(false);
|
|
11846
|
+
const [stabilizationPass, setStabilizationPass] = useState(0);
|
|
11827
11847
|
const isResolveMode = !("config" in props && props.config);
|
|
11828
11848
|
useEffect(() => {
|
|
11829
11849
|
if (!isResolveMode) {
|
|
@@ -11882,6 +11902,7 @@ function PixldocsPreview(props) {
|
|
|
11882
11902
|
if (!config) return;
|
|
11883
11903
|
let cancelled = false;
|
|
11884
11904
|
setCanvasSettled(false);
|
|
11905
|
+
setStabilizationPass(0);
|
|
11885
11906
|
const bump = () => {
|
|
11886
11907
|
if (cancelled) return;
|
|
11887
11908
|
clearMeasurementCache();
|
|
@@ -11894,22 +11915,32 @@ function PixldocsPreview(props) {
|
|
|
11894
11915
|
window.clearTimeout(timeoutId);
|
|
11895
11916
|
};
|
|
11896
11917
|
}, [config]);
|
|
11897
|
-
const previewKey = useMemo(
|
|
11918
|
+
const previewKey = useMemo(
|
|
11919
|
+
() => `${pageIndex}-${fontsReadyVersion}-${stabilizationPass}`,
|
|
11920
|
+
[pageIndex, fontsReadyVersion, stabilizationPass]
|
|
11921
|
+
);
|
|
11898
11922
|
useEffect(() => {
|
|
11899
11923
|
if (isResolveMode) return;
|
|
11900
11924
|
if (!config) {
|
|
11901
11925
|
setFontsReady(false);
|
|
11902
11926
|
setCanvasSettled(false);
|
|
11927
|
+
setStabilizationPass(0);
|
|
11903
11928
|
return;
|
|
11904
11929
|
}
|
|
11905
11930
|
setFontsReady(false);
|
|
11906
11931
|
setCanvasSettled(false);
|
|
11932
|
+
setStabilizationPass(0);
|
|
11907
11933
|
ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
|
|
11908
11934
|
}, [isResolveMode, config]);
|
|
11909
11935
|
const handleCanvasReady = useCallback(() => {
|
|
11936
|
+
if (stabilizationPass === 0) {
|
|
11937
|
+
setCanvasSettled(false);
|
|
11938
|
+
setStabilizationPass(1);
|
|
11939
|
+
return;
|
|
11940
|
+
}
|
|
11910
11941
|
setCanvasSettled(true);
|
|
11911
11942
|
onReady == null ? void 0 : onReady();
|
|
11912
|
-
}, [onReady]);
|
|
11943
|
+
}, [onReady, stabilizationPass]);
|
|
11913
11944
|
if (isLoading) {
|
|
11914
11945
|
return /* @__PURE__ */ jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
|
|
11915
11946
|
}
|
|
@@ -12323,6 +12354,7 @@ class PixldocsRenderer {
|
|
|
12323
12354
|
cleanup();
|
|
12324
12355
|
reject(new Error("Render timeout (30s)"));
|
|
12325
12356
|
}, 3e4);
|
|
12357
|
+
let stabilizationPass = 0;
|
|
12326
12358
|
const cleanup = () => {
|
|
12327
12359
|
clearTimeout(timeout);
|
|
12328
12360
|
try {
|
|
@@ -12332,6 +12364,19 @@ class PixldocsRenderer {
|
|
|
12332
12364
|
container.remove();
|
|
12333
12365
|
};
|
|
12334
12366
|
const onReady = () => {
|
|
12367
|
+
if (stabilizationPass === 0) {
|
|
12368
|
+
stabilizationPass = 1;
|
|
12369
|
+
root.render(
|
|
12370
|
+
createElement(PreviewCanvas2, {
|
|
12371
|
+
config,
|
|
12372
|
+
pageIndex,
|
|
12373
|
+
zoom: pixelRatio,
|
|
12374
|
+
absoluteZoom: true,
|
|
12375
|
+
onReady
|
|
12376
|
+
})
|
|
12377
|
+
);
|
|
12378
|
+
return;
|
|
12379
|
+
}
|
|
12335
12380
|
const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
|
|
12336
12381
|
this.waitForCanvasImages(container, expectedImageCount).then(async () => {
|
|
12337
12382
|
try {
|
|
@@ -12403,6 +12448,7 @@ class PixldocsRenderer {
|
|
|
12403
12448
|
cleanup();
|
|
12404
12449
|
reject(new Error("SVG render timeout (30s)"));
|
|
12405
12450
|
}, 3e4);
|
|
12451
|
+
let stabilizationPass = 0;
|
|
12406
12452
|
const cleanup = () => {
|
|
12407
12453
|
clearTimeout(timeout);
|
|
12408
12454
|
try {
|
|
@@ -12412,6 +12458,19 @@ class PixldocsRenderer {
|
|
|
12412
12458
|
container.remove();
|
|
12413
12459
|
};
|
|
12414
12460
|
const onReady = () => {
|
|
12461
|
+
if (stabilizationPass === 0) {
|
|
12462
|
+
stabilizationPass = 1;
|
|
12463
|
+
root.render(
|
|
12464
|
+
createElement(PreviewCanvas2, {
|
|
12465
|
+
config,
|
|
12466
|
+
pageIndex,
|
|
12467
|
+
zoom: 1,
|
|
12468
|
+
absoluteZoom: true,
|
|
12469
|
+
onReady
|
|
12470
|
+
})
|
|
12471
|
+
);
|
|
12472
|
+
return;
|
|
12473
|
+
}
|
|
12415
12474
|
const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
|
|
12416
12475
|
this.waitForCanvasImages(container, expectedImageCount).then(async () => {
|
|
12417
12476
|
var _a, _b;
|
|
@@ -12575,14 +12634,30 @@ class PixldocsRenderer {
|
|
|
12575
12634
|
scaleX: obj.scaleX,
|
|
12576
12635
|
scaleY: obj.scaleY
|
|
12577
12636
|
};
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12637
|
+
const resetTextboxLayoutInternals = () => {
|
|
12638
|
+
var _a4;
|
|
12639
|
+
(_a4 = obj._clearCache) == null ? void 0 : _a4.call(obj);
|
|
12640
|
+
obj.__charBounds = [];
|
|
12641
|
+
obj.__lineWidths = [];
|
|
12642
|
+
obj.__lineHeights = [];
|
|
12643
|
+
obj.__graphemeLines = [];
|
|
12644
|
+
obj._textLines = [];
|
|
12645
|
+
obj.textLines = [];
|
|
12646
|
+
obj._styleMap = null;
|
|
12647
|
+
obj.styleMap = null;
|
|
12648
|
+
obj.dirty = true;
|
|
12649
|
+
};
|
|
12650
|
+
resetTextboxLayoutInternals();
|
|
12585
12651
|
obj.initDimensions();
|
|
12652
|
+
if (saved.width != null) {
|
|
12653
|
+
(_a3 = obj.set) == null ? void 0 : _a3.call(obj, {
|
|
12654
|
+
width: saved.width,
|
|
12655
|
+
scaleX: saved.scaleX,
|
|
12656
|
+
scaleY: saved.scaleY
|
|
12657
|
+
});
|
|
12658
|
+
resetTextboxLayoutInternals();
|
|
12659
|
+
obj.initDimensions();
|
|
12660
|
+
}
|
|
12586
12661
|
(_b2 = obj.set) == null ? void 0 : _b2.call(obj, {
|
|
12587
12662
|
width: saved.width,
|
|
12588
12663
|
scaleX: saved.scaleX,
|