@pixldocs/canvas-renderer 0.5.11 → 0.5.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 +72 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2718,18 +2718,37 @@ const clearFabricCharCache = () => {
|
|
|
2718
2718
|
};
|
|
2719
2719
|
const clearFontCacheAndRerender = (canvas) => {
|
|
2720
2720
|
clearFabricCharCache();
|
|
2721
|
-
const
|
|
2721
|
+
const resetTextboxLayoutInternals = (obj) => {
|
|
2722
2722
|
var _a;
|
|
2723
|
+
(_a = obj._clearCache) == null ? void 0 : _a.call(obj);
|
|
2724
|
+
obj.__charBounds = [];
|
|
2725
|
+
obj.__lineWidths = [];
|
|
2726
|
+
obj.__lineHeights = [];
|
|
2727
|
+
obj.__graphemeLines = [];
|
|
2728
|
+
obj._textLines = [];
|
|
2729
|
+
obj.textLines = [];
|
|
2730
|
+
obj._styleMap = null;
|
|
2731
|
+
obj.styleMap = null;
|
|
2732
|
+
obj.dirty = true;
|
|
2733
|
+
};
|
|
2734
|
+
const fixTextbox = (obj) => {
|
|
2735
|
+
var _a, _b;
|
|
2723
2736
|
if (obj instanceof fabric__namespace.Textbox) {
|
|
2724
2737
|
const savedWidth = obj.width;
|
|
2725
|
-
|
|
2738
|
+
const savedScaleX = obj.scaleX;
|
|
2739
|
+
const savedScaleY = obj.scaleY;
|
|
2740
|
+
resetTextboxLayoutInternals(obj);
|
|
2726
2741
|
obj.initDimensions();
|
|
2727
|
-
if (savedWidth != null
|
|
2728
|
-
obj.width
|
|
2742
|
+
if (savedWidth != null) {
|
|
2743
|
+
obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY });
|
|
2744
|
+
resetTextboxLayoutInternals(obj);
|
|
2745
|
+
obj.initDimensions();
|
|
2746
|
+
obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY, dirty: true });
|
|
2729
2747
|
}
|
|
2748
|
+
(_a = obj._clearCache) == null ? void 0 : _a.call(obj);
|
|
2730
2749
|
obj.setCoords();
|
|
2731
2750
|
} else if (obj instanceof fabric__namespace.Group) {
|
|
2732
|
-
(
|
|
2751
|
+
(_b = obj._objects) == null ? void 0 : _b.forEach(fixTextbox);
|
|
2733
2752
|
obj.dirty = true;
|
|
2734
2753
|
obj.setCoords();
|
|
2735
2754
|
}
|
|
@@ -11842,10 +11861,12 @@ function PixldocsPreview(props) {
|
|
|
11842
11861
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
11843
11862
|
const [fontsReady, setFontsReady] = react.useState(false);
|
|
11844
11863
|
const [fontsReadyVersion, setFontsReadyVersion] = react.useState(0);
|
|
11864
|
+
const [canvasSettled, setCanvasSettled] = react.useState(false);
|
|
11845
11865
|
const isResolveMode = !("config" in props && props.config);
|
|
11846
11866
|
react.useEffect(() => {
|
|
11847
11867
|
if (!isResolveMode) {
|
|
11848
11868
|
setResolvedConfig(null);
|
|
11869
|
+
setCanvasSettled(false);
|
|
11849
11870
|
return;
|
|
11850
11871
|
}
|
|
11851
11872
|
const p = props;
|
|
@@ -11853,6 +11874,7 @@ function PixldocsPreview(props) {
|
|
|
11853
11874
|
let cancelled = false;
|
|
11854
11875
|
setIsLoading(true);
|
|
11855
11876
|
setFontsReady(false);
|
|
11877
|
+
setCanvasSettled(false);
|
|
11856
11878
|
resolveFromForm({
|
|
11857
11879
|
templateId: p.templateId,
|
|
11858
11880
|
formSchemaId: p.formSchemaId,
|
|
@@ -11897,6 +11919,7 @@ function PixldocsPreview(props) {
|
|
|
11897
11919
|
var _a, _b;
|
|
11898
11920
|
if (!config) return;
|
|
11899
11921
|
let cancelled = false;
|
|
11922
|
+
setCanvasSettled(false);
|
|
11900
11923
|
const bump = () => {
|
|
11901
11924
|
if (cancelled) return;
|
|
11902
11925
|
clearMeasurementCache();
|
|
@@ -11914,11 +11937,17 @@ function PixldocsPreview(props) {
|
|
|
11914
11937
|
if (isResolveMode) return;
|
|
11915
11938
|
if (!config) {
|
|
11916
11939
|
setFontsReady(false);
|
|
11940
|
+
setCanvasSettled(false);
|
|
11917
11941
|
return;
|
|
11918
11942
|
}
|
|
11919
11943
|
setFontsReady(false);
|
|
11944
|
+
setCanvasSettled(false);
|
|
11920
11945
|
ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
|
|
11921
11946
|
}, [isResolveMode, config]);
|
|
11947
|
+
const handleCanvasReady = react.useCallback(() => {
|
|
11948
|
+
setCanvasSettled(true);
|
|
11949
|
+
onReady == null ? void 0 : onReady();
|
|
11950
|
+
}, [onReady]);
|
|
11922
11951
|
if (isLoading) {
|
|
11923
11952
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
|
|
11924
11953
|
}
|
|
@@ -11926,18 +11955,21 @@ function PixldocsPreview(props) {
|
|
|
11926
11955
|
if (!fontsReady) {
|
|
11927
11956
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
|
|
11928
11957
|
}
|
|
11929
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
11930
|
-
|
|
11931
|
-
|
|
11932
|
-
|
|
11933
|
-
|
|
11934
|
-
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11940
|
-
|
|
11958
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: { ...style, position: "relative" }, children: [
|
|
11959
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { visibility: canvasSettled ? "visible" : "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11960
|
+
PreviewCanvas,
|
|
11961
|
+
{
|
|
11962
|
+
config,
|
|
11963
|
+
pageIndex,
|
|
11964
|
+
zoom,
|
|
11965
|
+
absoluteZoom,
|
|
11966
|
+
onDynamicFieldClick,
|
|
11967
|
+
onReady: handleCanvasReady
|
|
11968
|
+
},
|
|
11969
|
+
previewKey
|
|
11970
|
+
) }),
|
|
11971
|
+
!canvasSettled && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
|
|
11972
|
+
] });
|
|
11941
11973
|
}
|
|
11942
11974
|
class PixldocsRenderer {
|
|
11943
11975
|
constructor(config) {
|
|
@@ -12581,14 +12613,30 @@ class PixldocsRenderer {
|
|
|
12581
12613
|
scaleX: obj.scaleX,
|
|
12582
12614
|
scaleY: obj.scaleY
|
|
12583
12615
|
};
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12616
|
+
const resetTextboxLayoutInternals = () => {
|
|
12617
|
+
var _a4;
|
|
12618
|
+
(_a4 = obj._clearCache) == null ? void 0 : _a4.call(obj);
|
|
12619
|
+
obj.__charBounds = [];
|
|
12620
|
+
obj.__lineWidths = [];
|
|
12621
|
+
obj.__lineHeights = [];
|
|
12622
|
+
obj.__graphemeLines = [];
|
|
12623
|
+
obj._textLines = [];
|
|
12624
|
+
obj.textLines = [];
|
|
12625
|
+
obj._styleMap = null;
|
|
12626
|
+
obj.styleMap = null;
|
|
12627
|
+
obj.dirty = true;
|
|
12628
|
+
};
|
|
12629
|
+
resetTextboxLayoutInternals();
|
|
12591
12630
|
obj.initDimensions();
|
|
12631
|
+
if (saved.width != null) {
|
|
12632
|
+
(_a3 = obj.set) == null ? void 0 : _a3.call(obj, {
|
|
12633
|
+
width: saved.width,
|
|
12634
|
+
scaleX: saved.scaleX,
|
|
12635
|
+
scaleY: saved.scaleY
|
|
12636
|
+
});
|
|
12637
|
+
resetTextboxLayoutInternals();
|
|
12638
|
+
obj.initDimensions();
|
|
12639
|
+
}
|
|
12592
12640
|
(_b2 = obj.set) == null ? void 0 : _b2.call(obj, {
|
|
12593
12641
|
width: saved.width,
|
|
12594
12642
|
scaleX: saved.scaleX,
|