@pixldocs/canvas-renderer 0.5.245 → 0.5.247

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.
@@ -9479,7 +9479,7 @@ function createShape(element) {
9479
9479
  function createText(element) {
9480
9480
  var _a2, _b2, _c, _d, _e;
9481
9481
  const overflowPolicy = element.overflowPolicy || "grow-and-push";
9482
- let text = element.text || "Text";
9482
+ let text = element.text != null && element.text !== "" ? element.text : " ";
9483
9483
  let fontSize = element.fontSize || 16;
9484
9484
  const minFontSize = element.minFontSize || 8;
9485
9485
  const maxLines = element.maxLines || 3;
@@ -9570,7 +9570,7 @@ function createText(element) {
9570
9570
  }
9571
9571
  }
9572
9572
  if (overflowPolicy === "max-lines-ellipsis") {
9573
- const originalText = element.text || "Text";
9573
+ const originalText = element.text || " ";
9574
9574
  const countLines = (testText) => {
9575
9575
  var _a3;
9576
9576
  const tb = new fabric__namespace.Textbox(testText, {
@@ -11120,7 +11120,9 @@ const PageCanvas = react.forwardRef(
11120
11120
  const isSyncingSelectionToFabricRef = react.useRef(false);
11121
11121
  const suppressGroupMemberBordersRef = react.useRef([]);
11122
11122
  const editingTextIdRef = react.useRef(null);
11123
- const pendingTextEditOnUpRef = react.useRef(null);
11123
+ const selectAllTextOnEditingEnterRef = react.useRef(null);
11124
+ const suppressedTextEditObjectsRef = react.useRef([]);
11125
+ const suppressTextDoubleClickUntilRef = react.useRef(0);
11124
11126
  const syncLockedRef = react.useRef(false);
11125
11127
  const editLockRef = react.useRef(false);
11126
11128
  const editLockCountRef = react.useRef(0);
@@ -11748,7 +11750,7 @@ const PageCanvas = react.forwardRef(
11748
11750
  const targetWidth = Math.max(1, Number(element.width) > 0 ? Number(element.width) : Number(obj.width ?? 200));
11749
11751
  const overflowPolicy = element.overflowPolicy || "grow-and-push";
11750
11752
  const splitByGrapheme = overflowPolicy === "auto-shrink" ? false : element.splitByGrapheme ?? element.wordWrap === "break-word";
11751
- let reflowText = element.text || "Text";
11753
+ let reflowText = element.text != null && element.text !== "" ? element.text : " ";
11752
11754
  let reflowParsedStyles = null;
11753
11755
  if (element.formattingEnabled === true) {
11754
11756
  const parsed = parseTextMarkdown(reflowText);
@@ -11829,6 +11831,44 @@ const PageCanvas = react.forwardRef(
11829
11831
  });
11830
11832
  fabricCanvas.hoverCursor = "default";
11831
11833
  fabricCanvas.moveCursor = "move";
11834
+ const suppressTextEditForClick = (textbox) => {
11835
+ if (!textbox) return;
11836
+ textbox.selected = false;
11837
+ textbox.__lastSelected = false;
11838
+ textbox.__corner = void 0;
11839
+ textbox.__pixldocsSuppressNextEdit = true;
11840
+ suppressTextDoubleClickUntilRef.current = Date.now() + 350;
11841
+ if (!suppressedTextEditObjectsRef.current.some((entry) => entry.textbox === textbox)) {
11842
+ suppressedTextEditObjectsRef.current.push({ textbox, editable: textbox.editable });
11843
+ }
11844
+ textbox.editable = false;
11845
+ };
11846
+ const restoreSuppressedTextEditObjects = () => {
11847
+ const entries = suppressedTextEditObjectsRef.current.splice(0);
11848
+ for (const { textbox, editable } of entries) {
11849
+ try {
11850
+ textbox.editable = editable;
11851
+ delete textbox.__pixldocsSuppressNextEdit;
11852
+ } catch {
11853
+ }
11854
+ }
11855
+ };
11856
+ const restoreSuppressedTextEditObjectsSoon = () => {
11857
+ requestAnimationFrame(() => {
11858
+ restoreSuppressedTextEditObjects();
11859
+ });
11860
+ };
11861
+ const selectAllActiveTextbox = (textbox) => {
11862
+ var _a2;
11863
+ try {
11864
+ textbox.selectAll();
11865
+ } catch {
11866
+ const len = ((_a2 = textbox.text) == null ? void 0 : _a2.length) ?? 0;
11867
+ textbox.selectionStart = 0;
11868
+ textbox.selectionEnd = len;
11869
+ }
11870
+ fabricCanvas.requestRenderAll();
11871
+ };
11832
11872
  if (!allowSelection) {
11833
11873
  fabricCanvas.selection = false;
11834
11874
  fabricCanvas.on("selection:created", () => {
@@ -12818,6 +12858,7 @@ const PageCanvas = react.forwardRef(
12818
12858
  fabricCanvas.__updateDrilledGroupOutline = updateDrilledGroupOutline;
12819
12859
  fabricCanvas.on("mouse:down:before", (opt) => {
12820
12860
  var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
12861
+ const activeBeforeMouseDown = fabricCanvas.getActiveObject();
12821
12862
  if (editLockRef.current) {
12822
12863
  const active = fabricCanvas.getActiveObject();
12823
12864
  if (active && (((_a2 = active._ct) == null ? void 0 : _a2.isCropGroup) || active.__cropGroup)) {
@@ -12843,6 +12884,9 @@ const PageCanvas = react.forwardRef(
12843
12884
  targetId = childId;
12844
12885
  }
12845
12886
  }
12887
+ if (target instanceof fabric__namespace.Textbox && targetId && targetId !== "__background__" && activeBeforeMouseDown === target && !target.isEditing && !target.__corner && !isMultiSelectModifier(opt.e)) {
12888
+ selectAllTextOnEditingEnterRef.current = targetId;
12889
+ }
12846
12890
  const activeEditingGroupId = fabricCanvas.__activeEditingGroupId ?? null;
12847
12891
  const pageNow = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId);
12848
12892
  const childrenNow = (pageNow == null ? void 0 : pageNow.children) ?? [];
@@ -12950,9 +12994,13 @@ const PageCanvas = react.forwardRef(
12950
12994
  opt.target = effectiveTarget;
12951
12995
  pendingGroupPromotionRef.current = null;
12952
12996
  pendingGroupDrillInRef.current = { groupId: drillGroup.id, childId: effectiveTargetId, target: effectiveTarget };
12953
- effectiveTarget.selected = false;
12954
- effectiveTarget.__lastSelected = false;
12955
- effectiveTarget.__corner = void 0;
12997
+ if (effectiveTarget instanceof fabric__namespace.Textbox) {
12998
+ suppressTextEditForClick(effectiveTarget);
12999
+ } else {
13000
+ effectiveTarget.selected = false;
13001
+ effectiveTarget.__lastSelected = false;
13002
+ effectiveTarget.__corner = void 0;
13003
+ }
12956
13004
  selectElements([effectiveTargetId], false, false);
12957
13005
  updateDrilledGroupOutline();
12958
13006
  fabricCanvas.requestRenderAll();
@@ -13095,7 +13143,6 @@ const PageCanvas = react.forwardRef(
13095
13143
  lockEdits();
13096
13144
  }
13097
13145
  const o = fabricCanvas.getActiveObject();
13098
- pendingTextEditOnUpRef.current = null;
13099
13146
  if (!o) return;
13100
13147
  o.__lockScaleDuringCrop = false;
13101
13148
  });
@@ -13122,9 +13169,13 @@ const PageCanvas = react.forwardRef(
13122
13169
  (_b2 = (_a2 = pendingDrillIn.target).set) == null ? void 0 : _b2.call(_a2, { selectable: true, evented: true, hasBorders: true, hasControls: true });
13123
13170
  fabricCanvas.setActiveObject(pendingDrillIn.target);
13124
13171
  pendingDrillIn.target.setCoords();
13125
- pendingDrillIn.target.selected = false;
13126
- pendingDrillIn.target.__lastSelected = false;
13127
- pendingDrillIn.target.__corner = void 0;
13172
+ if (pendingDrillIn.target instanceof fabric__namespace.Textbox) {
13173
+ suppressTextEditForClick(pendingDrillIn.target);
13174
+ } else {
13175
+ pendingDrillIn.target.selected = false;
13176
+ pendingDrillIn.target.__lastSelected = false;
13177
+ pendingDrillIn.target.__corner = void 0;
13178
+ }
13128
13179
  fabricCanvas.requestRenderAll();
13129
13180
  } finally {
13130
13181
  requestAnimationFrame(() => {
@@ -13197,6 +13248,7 @@ const PageCanvas = react.forwardRef(
13197
13248
  syncLockedRef.current = false;
13198
13249
  }, 0);
13199
13250
  unlockEditsSoon();
13251
+ restoreSuppressedTextEditObjectsSoon();
13200
13252
  if (allowDynamicFieldClick && onDynamicFieldClick && e.target) {
13201
13253
  const clickedId = getObjectId(e.target);
13202
13254
  if (clickedId && dynamicFieldIds.includes(clickedId)) {
@@ -14483,6 +14535,9 @@ const PageCanvas = react.forwardRef(
14483
14535
  else if (active instanceof fabric__namespace.ActiveSelection && active.getObjects().length === 1 && active.getObjects()[0] instanceof fabric__namespace.Textbox) target = active.getObjects()[0];
14484
14536
  }
14485
14537
  if (target && target instanceof fabric__namespace.Textbox) {
14538
+ if (Date.now() < suppressTextDoubleClickUntilRef.current || target.__pixldocsSuppressNextEdit) {
14539
+ return;
14540
+ }
14486
14541
  const elementId = getObjectId(target);
14487
14542
  if (target.__formattingEnabled === true || target.editable === false) {
14488
14543
  sonner.toast.info("Inline formatting is on — edit the text in the right panel.", {
@@ -14499,7 +14554,21 @@ const PageCanvas = react.forwardRef(
14499
14554
  const target = e.target;
14500
14555
  if (target && target instanceof fabric__namespace.Textbox) {
14501
14556
  const elementId = getObjectId(target);
14557
+ if (target.__pixldocsSuppressNextEdit) {
14558
+ try {
14559
+ target.exitEditing();
14560
+ } catch {
14561
+ }
14562
+ editingTextIdRef.current = null;
14563
+ setEditingText(false);
14564
+ fabricCanvas.requestRenderAll();
14565
+ return;
14566
+ }
14502
14567
  editingTextIdRef.current = elementId || null;
14568
+ if (elementId && selectAllTextOnEditingEnterRef.current === elementId) {
14569
+ selectAllTextOnEditingEnterRef.current = null;
14570
+ selectAllActiveTextbox(target);
14571
+ }
14503
14572
  setEditingText(true);
14504
14573
  }
14505
14574
  });
@@ -16180,7 +16249,7 @@ const PageCanvas = react.forwardRef(
16180
16249
  });
16181
16250
  } else if (obj instanceof fabric__namespace.Textbox) {
16182
16251
  const overflowPolicy = element.overflowPolicy || "grow-and-push";
16183
- let text = element.text || "Text";
16252
+ let text = element.text != null && element.text !== "" ? element.text : " ";
16184
16253
  let parsedStyles = null;
16185
16254
  if (element.formattingEnabled === true) {
16186
16255
  const parsed = parseTextMarkdown(text);
@@ -16218,7 +16287,7 @@ const PageCanvas = react.forwardRef(
16218
16287
  }
16219
16288
  }
16220
16289
  if (overflowPolicy === "max-lines-ellipsis") {
16221
- const testTextbox = new fabric__namespace.Textbox(element.text || "Text", {
16290
+ const testTextbox = new fabric__namespace.Textbox(element.text || " ", {
16222
16291
  width: rW,
16223
16292
  fontSize,
16224
16293
  fontFamily: element.fontFamily || "Open Sans",
@@ -16228,7 +16297,7 @@ const PageCanvas = react.forwardRef(
16228
16297
  testTextbox.initDimensions();
16229
16298
  const lines = testTextbox.textLines || [];
16230
16299
  if (lines.length > maxLines) {
16231
- const originalText = element.text || "Text";
16300
+ const originalText = element.text || " ";
16232
16301
  const countLines = (testText) => {
16233
16302
  var _a3;
16234
16303
  const tb = new fabric__namespace.Textbox(testText, {
@@ -23394,9 +23463,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
23394
23463
  }
23395
23464
  return svgString;
23396
23465
  }
23397
- const resolvedPackageVersion = "0.5.245";
23466
+ const resolvedPackageVersion = "0.5.247";
23398
23467
  const PACKAGE_VERSION = resolvedPackageVersion;
23399
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.245";
23468
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.247";
23400
23469
  const roundParityValue = (value) => {
23401
23470
  if (typeof value !== "number") return value;
23402
23471
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -24210,7 +24279,7 @@ class PixldocsRenderer {
24210
24279
  await this.waitForCanvasScene(container, cloned, i);
24211
24280
  }
24212
24281
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
24213
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-00z0fojJ.cjs"));
24282
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-7--PybIt.cjs"));
24214
24283
  const prepared = preparePagesForExport(
24215
24284
  cloned.pages,
24216
24285
  canvasWidth,
@@ -26530,7 +26599,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
26530
26599
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
26531
26600
  sanitizeSvgTreeForPdf(svgToDraw);
26532
26601
  try {
26533
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-00z0fojJ.cjs"));
26602
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-7--PybIt.cjs"));
26534
26603
  try {
26535
26604
  await logTextMeasurementDiagnostic(svgToDraw);
26536
26605
  } catch {
@@ -26927,4 +26996,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
26927
26996
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
26928
26997
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
26929
26998
  exports.warmTemplateFromForm = warmTemplateFromForm;
26930
- //# sourceMappingURL=index-o3TKXqkj.cjs.map
26999
+ //# sourceMappingURL=index-D3P-zkRH.cjs.map