@idraw/core 0.4.0-beta.23 → 0.4.0-beta.25

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.
@@ -656,23 +656,23 @@ var __privateMethod = (obj, member, method) => {
656
656
  const ctx = canvas.getContext("2d");
657
657
  if (createCustomContext2D) {
658
658
  const viewContext = createCustomContext2D(ctxOpts);
659
- const helperContext = createCustomContext2D(ctxOpts);
660
- const underContext = createCustomContext2D(ctxOpts);
659
+ const overlayContext = createCustomContext2D(ctxOpts);
660
+ const underlayContext = createCustomContext2D(ctxOpts);
661
661
  const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
662
662
  const drawView = () => {
663
663
  const { width: w2, height: h2 } = viewContext.$getSize();
664
664
  boardContext.clearRect(0, 0, w2, h2);
665
- boardContext.drawImage(underContext.canvas, 0, 0, w2, h2);
665
+ boardContext.drawImage(underlayContext.canvas, 0, 0, w2, h2);
666
666
  boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
667
- boardContext.drawImage(helperContext.canvas, 0, 0, w2, h2);
668
- underContext.clearRect(0, 0, w2, h2);
667
+ boardContext.drawImage(overlayContext.canvas, 0, 0, w2, h2);
668
+ underlayContext.clearRect(0, 0, w2, h2);
669
669
  viewContext.clearRect(0, 0, w2, h2);
670
- helperContext.clearRect(0, 0, w2, h2);
670
+ overlayContext.clearRect(0, 0, w2, h2);
671
671
  };
672
672
  const content = {
673
- underContext,
673
+ underlayContext,
674
674
  viewContext,
675
- helperContext,
675
+ overlayContext,
676
676
  boardContext,
677
677
  drawView
678
678
  };
@@ -680,45 +680,45 @@ var __privateMethod = (obj, member, method) => {
680
680
  }
681
681
  if (offscreen === true) {
682
682
  const viewContext = createOffscreenContext2D(ctxOpts);
683
- const helperContext = createOffscreenContext2D(ctxOpts);
684
- const underContext = createOffscreenContext2D(ctxOpts);
683
+ const overlayContext = createOffscreenContext2D(ctxOpts);
684
+ const underlayContext = createOffscreenContext2D(ctxOpts);
685
685
  const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
686
686
  const drawView = () => {
687
687
  const { width: w2, height: h2 } = viewContext.$getSize();
688
688
  boardContext.clearRect(0, 0, w2, h2);
689
- boardContext.drawImage(underContext.canvas, 0, 0, w2, h2);
689
+ boardContext.drawImage(underlayContext.canvas, 0, 0, w2, h2);
690
690
  boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
691
- boardContext.drawImage(helperContext.canvas, 0, 0, w2, h2);
692
- underContext.clearRect(0, 0, w2, h2);
691
+ boardContext.drawImage(overlayContext.canvas, 0, 0, w2, h2);
692
+ underlayContext.clearRect(0, 0, w2, h2);
693
693
  viewContext.clearRect(0, 0, w2, h2);
694
- helperContext.clearRect(0, 0, w2, h2);
694
+ overlayContext.clearRect(0, 0, w2, h2);
695
695
  };
696
696
  const content = {
697
- underContext,
697
+ underlayContext,
698
698
  viewContext,
699
- helperContext,
699
+ overlayContext,
700
700
  boardContext,
701
701
  drawView
702
702
  };
703
703
  return content;
704
704
  } else {
705
705
  const viewContext = createContext2D(ctxOpts);
706
- const helperContext = createContext2D(ctxOpts);
707
- const underContext = createContext2D(ctxOpts);
706
+ const overlayContext = createContext2D(ctxOpts);
707
+ const underlayContext = createContext2D(ctxOpts);
708
708
  const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
709
709
  const drawView = () => {
710
710
  boardContext.clearRect(0, 0, width, height);
711
- boardContext.drawImage(underContext.canvas, 0, 0, width, height);
711
+ boardContext.drawImage(underlayContext.canvas, 0, 0, width, height);
712
712
  boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
713
- boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
714
- underContext.clearRect(0, 0, width, height);
713
+ boardContext.drawImage(overlayContext.canvas, 0, 0, width, height);
714
+ underlayContext.clearRect(0, 0, width, height);
715
715
  viewContext.clearRect(0, 0, width, height);
716
- helperContext.clearRect(0, 0, width, height);
716
+ overlayContext.clearRect(0, 0, width, height);
717
717
  };
718
718
  const content = {
719
- underContext,
719
+ underlayContext,
720
720
  viewContext,
721
- helperContext,
721
+ overlayContext,
722
722
  boardContext,
723
723
  drawView
724
724
  };
@@ -1932,6 +1932,8 @@ var __privateMethod = (obj, member, method) => {
1932
1932
  fontSize: 16,
1933
1933
  fontFamily: "sans-serif",
1934
1934
  fontWeight: 400,
1935
+ minInlineSize: "auto",
1936
+ wordBreak: "break-all",
1935
1937
  overflow: "hidden"
1936
1938
  };
1937
1939
  return config;
@@ -2084,6 +2086,10 @@ var __privateMethod = (obj, member, method) => {
2084
2086
  resizeElementBaseDetail(elem, opts);
2085
2087
  return elem;
2086
2088
  }
2089
+ const baseFontFamilyList = ["-apple-system", '"system-ui"', ' "Segoe UI"', " Roboto", '"Helvetica Neue"', "Arial", '"Noto Sans"', " sans-serif"];
2090
+ function enhanceFontFamliy(fontFamily2) {
2091
+ return [fontFamily2, ...baseFontFamilyList].join(", ");
2092
+ }
2087
2093
  function createColorStyle(ctx, color2, opts) {
2088
2094
  if (typeof color2 === "string") {
2089
2095
  return color2;
@@ -2140,19 +2146,36 @@ var __privateMethod = (obj, member, method) => {
2140
2146
  const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
2141
2147
  const { parentOpacity } = opts;
2142
2148
  const opacity = getOpacity(originElem) * parentOpacity;
2143
- drawClipPath(ctx, viewElem, {
2144
- originElem,
2145
- calcElemSize,
2146
- viewScaleInfo,
2147
- viewSizeInfo,
2148
- renderContent: () => {
2149
- ctx.globalAlpha = opacity;
2150
- drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
2151
- renderContent === null || renderContent === void 0 ? void 0 : renderContent();
2152
- drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
2153
- ctx.globalAlpha = parentOpacity;
2149
+ const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = originElem.detail;
2150
+ const mainRender = () => {
2151
+ ctx.globalAlpha = opacity;
2152
+ drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
2153
+ renderContent === null || renderContent === void 0 ? void 0 : renderContent();
2154
+ drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
2155
+ ctx.globalAlpha = parentOpacity;
2156
+ };
2157
+ if (clipPath) {
2158
+ drawClipPath(ctx, viewElem, {
2159
+ originElem,
2160
+ calcElemSize,
2161
+ viewScaleInfo,
2162
+ viewSizeInfo,
2163
+ renderContent: () => {
2164
+ mainRender();
2165
+ }
2166
+ });
2167
+ if (typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
2168
+ drawClipPathStroke(ctx, viewElem, {
2169
+ originElem,
2170
+ calcElemSize,
2171
+ viewScaleInfo,
2172
+ viewSizeInfo,
2173
+ parentOpacity
2174
+ });
2154
2175
  }
2155
- });
2176
+ } else {
2177
+ mainRender();
2178
+ }
2156
2179
  }
2157
2180
  function drawClipPath(ctx, viewElem, opts) {
2158
2181
  const { renderContent, originElem, calcElemSize, viewSizeInfo } = opts;
@@ -2183,6 +2206,38 @@ var __privateMethod = (obj, member, method) => {
2183
2206
  renderContent === null || renderContent === void 0 ? void 0 : renderContent();
2184
2207
  }
2185
2208
  }
2209
+ function drawClipPathStroke(ctx, viewElem, opts) {
2210
+ const { renderContent, originElem, calcElemSize, viewSizeInfo, parentOpacity } = opts;
2211
+ const totalScale = viewSizeInfo.devicePixelRatio;
2212
+ const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = (originElem === null || originElem === void 0 ? void 0 : originElem.detail) || {};
2213
+ if (clipPath && calcElemSize && clipPath.commands && typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
2214
+ const { x: x2, y: y2, w: w2, h: h2 } = calcElemSize;
2215
+ const { originW, originH, originX, originY } = clipPath;
2216
+ const scaleW = w2 / originW;
2217
+ const scaleH = h2 / originH;
2218
+ const viewOriginX = originX * scaleW;
2219
+ const viewOriginY = originY * scaleH;
2220
+ const internalX = x2 - viewOriginX;
2221
+ const internalY = y2 - viewOriginY;
2222
+ ctx.save();
2223
+ ctx.globalAlpha = parentOpacity;
2224
+ ctx.translate(internalX, internalY);
2225
+ ctx.scale(totalScale * scaleW, totalScale * scaleH);
2226
+ const pathStr = generateSVGPath(clipPath.commands || []);
2227
+ const path2d = new Path2D(pathStr);
2228
+ ctx.strokeStyle = clipPathStrokeColor;
2229
+ ctx.lineWidth = clipPathStrokeWidth;
2230
+ ctx.stroke(path2d);
2231
+ ctx.translate(0 - internalX, 0 - internalY);
2232
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
2233
+ rotateElement$1(ctx, Object.assign({}, viewElem), () => {
2234
+ renderContent === null || renderContent === void 0 ? void 0 : renderContent();
2235
+ });
2236
+ ctx.restore();
2237
+ } else {
2238
+ renderContent === null || renderContent === void 0 ? void 0 : renderContent();
2239
+ }
2240
+ }
2186
2241
  function drawBoxBackground(ctx, viewElem, opts) {
2187
2242
  var _a, _b;
2188
2243
  const { pattern, viewScaleInfo, viewSizeInfo } = opts;
@@ -2488,7 +2543,7 @@ var __privateMethod = (obj, member, method) => {
2488
2543
  function drawImage(ctx, elem, opts) {
2489
2544
  const content = opts.loader.getContent(elem);
2490
2545
  const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2491
- const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
2546
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
2492
2547
  const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2493
2548
  rotateElement$1(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
2494
2549
  drawBoxShadow(ctx, viewElem, {
@@ -2511,6 +2566,10 @@ var __privateMethod = (obj, member, method) => {
2511
2566
  viewScaleInfo,
2512
2567
  viewSizeInfo
2513
2568
  });
2569
+ const { detail } = elem;
2570
+ const { scaleMode, originW = 0, originH = 0 } = detail;
2571
+ const imageW = ctx.$undoPixelRatio(originW);
2572
+ const imageH = ctx.$undoPixelRatio(originH);
2514
2573
  ctx.save();
2515
2574
  ctx.fillStyle = "transparent";
2516
2575
  ctx.beginPath();
@@ -2522,7 +2581,41 @@ var __privateMethod = (obj, member, method) => {
2522
2581
  ctx.closePath();
2523
2582
  ctx.fill();
2524
2583
  ctx.clip();
2525
- ctx.drawImage(content, x3, y3, w3, h3);
2584
+ if (scaleMode && originH && originW) {
2585
+ let sx = 0;
2586
+ let sy = 0;
2587
+ let sWidth = imageW;
2588
+ let sHeight = imageH;
2589
+ const dx = x3;
2590
+ const dy = y3;
2591
+ const dWidth = w3;
2592
+ const dHeight = h3;
2593
+ if (imageW > elem.w || imageH > elem.h) {
2594
+ if (scaleMode === "fill") {
2595
+ const sourceScale = Math.max(elem.w / imageW, elem.h / imageH);
2596
+ const newImageWidth = imageW * sourceScale;
2597
+ const newImageHeight = imageH * sourceScale;
2598
+ sx = (newImageWidth - elem.w) / 2 / sourceScale;
2599
+ sy = (newImageHeight - elem.h) / 2 / sourceScale;
2600
+ sWidth = elem.w / sourceScale;
2601
+ sHeight = elem.h / sourceScale;
2602
+ } else if (scaleMode === "tile") {
2603
+ sx = 0;
2604
+ sy = 0;
2605
+ sWidth = elem.w;
2606
+ sHeight = elem.h;
2607
+ } else if (scaleMode === "fit") {
2608
+ const sourceScale = Math.min(elem.w / imageW, elem.h / imageH);
2609
+ sx = (imageW - elem.w / sourceScale) / 2;
2610
+ sy = (imageH - elem.h / sourceScale) / 2;
2611
+ sWidth = elem.w / sourceScale;
2612
+ sHeight = elem.h / sourceScale;
2613
+ }
2614
+ }
2615
+ ctx.drawImage(content, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
2616
+ } else {
2617
+ ctx.drawImage(content, x3, y3, w3, h3);
2618
+ }
2526
2619
  ctx.globalAlpha = parentOpacity;
2527
2620
  ctx.restore();
2528
2621
  }
@@ -2563,6 +2656,14 @@ var __privateMethod = (obj, member, method) => {
2563
2656
  });
2564
2657
  }
2565
2658
  const detailConfig = getDefaultElementDetailConfig();
2659
+ function isTextWidthWithinErrorRange(w0, w1, scale) {
2660
+ if (scale < 0.5) {
2661
+ if (w0 < w1 && (w0 - w1) / w0 > -0.15) {
2662
+ return true;
2663
+ }
2664
+ }
2665
+ return w0 >= w1;
2666
+ }
2566
2667
  function drawText(ctx, elem, opts) {
2567
2668
  const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2568
2669
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
@@ -2578,6 +2679,9 @@ var __privateMethod = (obj, member, method) => {
2578
2679
  const detail = Object.assign(Object.assign({}, detailConfig), elem.detail);
2579
2680
  const originFontSize = detail.fontSize || detailConfig.fontSize;
2580
2681
  const fontSize2 = originFontSize * viewScaleInfo.scale;
2682
+ if (fontSize2 < 2) {
2683
+ return;
2684
+ }
2581
2685
  const originLineHeight = detail.lineHeight || originFontSize;
2582
2686
  const lineHeight2 = originLineHeight * viewScaleInfo.scale;
2583
2687
  ctx.fillStyle = elem.detail.color || detailConfig.color;
@@ -2585,7 +2689,7 @@ var __privateMethod = (obj, member, method) => {
2585
2689
  ctx.$setFont({
2586
2690
  fontWeight: detail.fontWeight,
2587
2691
  fontSize: fontSize2,
2588
- fontFamily: detail.fontFamily
2692
+ fontFamily: enhanceFontFamliy(detail.fontFamily)
2589
2693
  });
2590
2694
  let detailText = detail.text.replace(/\r\n/gi, "\n");
2591
2695
  if (detail.textTransform === "lowercase") {
@@ -2597,30 +2701,48 @@ var __privateMethod = (obj, member, method) => {
2597
2701
  const detailTextList = detailText.split("\n");
2598
2702
  const lines = [];
2599
2703
  let lineNum = 0;
2600
- detailTextList.forEach((tempText, idx) => {
2704
+ detailTextList.forEach((itemText, idx) => {
2601
2705
  if (detail.minInlineSize === "maxContent") {
2602
2706
  lines.push({
2603
- text: tempText,
2604
- width: ctx.$undoPixelRatio(ctx.measureText(tempText).width)
2707
+ text: itemText,
2708
+ width: ctx.$undoPixelRatio(ctx.measureText(itemText).width)
2605
2709
  });
2606
2710
  } else {
2607
2711
  let lineText = "";
2608
- if (tempText.length > 0) {
2609
- for (let i = 0; i < tempText.length; i++) {
2610
- if (ctx.measureText(lineText + (tempText[i] || "")).width <= ctx.$doPixelRatio(w2)) {
2611
- lineText += tempText[i] || "";
2712
+ let splitStr = "";
2713
+ let tempStrList = itemText.split(splitStr);
2714
+ if (detail.wordBreak === "normal") {
2715
+ const splitStr2 = " ";
2716
+ const wordList = itemText.split(splitStr2);
2717
+ tempStrList = [];
2718
+ wordList.forEach((word, idx2) => {
2719
+ tempStrList.push(word);
2720
+ if (idx2 < wordList.length - 1) {
2721
+ tempStrList.push(splitStr2);
2722
+ }
2723
+ });
2724
+ }
2725
+ if (tempStrList.length === 1 && detail.overflow === "visible") {
2726
+ lines.push({
2727
+ text: tempStrList[0],
2728
+ width: ctx.$undoPixelRatio(ctx.measureText(tempStrList[0]).width)
2729
+ });
2730
+ } else if (tempStrList.length > 0) {
2731
+ for (let i = 0; i < tempStrList.length; i++) {
2732
+ if (isTextWidthWithinErrorRange(ctx.$doPixelRatio(w2), ctx.measureText(lineText + tempStrList[i]).width, viewScaleInfo.scale)) {
2733
+ lineText += tempStrList[i] || "";
2612
2734
  } else {
2613
2735
  lines.push({
2614
2736
  text: lineText,
2615
2737
  width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
2616
2738
  });
2617
- lineText = tempText[i] || "";
2739
+ lineText = tempStrList[i] || "";
2618
2740
  lineNum++;
2619
2741
  }
2620
- if ((lineNum + 1) * fontHeight > h2) {
2742
+ if ((lineNum + 1) * fontHeight > h2 && detail.overflow === "hidden") {
2621
2743
  break;
2622
2744
  }
2623
- if (tempText.length - 1 === i) {
2745
+ if (tempStrList.length - 1 === i) {
2624
2746
  if ((lineNum + 1) * fontHeight <= h2) {
2625
2747
  lines.push({
2626
2748
  text: lineText,
@@ -2642,6 +2764,10 @@ var __privateMethod = (obj, member, method) => {
2642
2764
  }
2643
2765
  });
2644
2766
  let startY = 0;
2767
+ let eachLineStartY = 0;
2768
+ if (fontHeight > fontSize2) {
2769
+ eachLineStartY = (fontHeight - fontSize2) / 2;
2770
+ }
2645
2771
  if (lines.length * fontHeight < h2) {
2646
2772
  if (elem.detail.verticalAlign === "top") {
2647
2773
  startY = 0;
@@ -2672,7 +2798,7 @@ var __privateMethod = (obj, member, method) => {
2672
2798
  } else if (detail.textAlign === "right") {
2673
2799
  _x = x2 + (w2 - line.width);
2674
2800
  }
2675
- ctx.fillText(line.text, _x, _y + fontHeight * i);
2801
+ ctx.fillText(line.text, _x, _y + fontHeight * i + eachLineStartY);
2676
2802
  });
2677
2803
  }
2678
2804
  }
@@ -2681,7 +2807,7 @@ var __privateMethod = (obj, member, method) => {
2681
2807
  }
2682
2808
  function drawPath(ctx, elem, opts) {
2683
2809
  const { detail } = elem;
2684
- const { originX, originY, originW, originH } = detail;
2810
+ const { originX, originY, originW, originH, fillRule } = detail;
2685
2811
  const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2686
2812
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
2687
2813
  const scaleW = w2 / originW;
@@ -2711,7 +2837,7 @@ var __privateMethod = (obj, member, method) => {
2711
2837
  const path2d = new Path2D(pathStr);
2712
2838
  if (detail.fill) {
2713
2839
  ctx.fillStyle = detail.fill;
2714
- ctx.fill(path2d);
2840
+ ctx.fill(path2d, fillRule);
2715
2841
  }
2716
2842
  if (detail.stroke && detail.strokeWidth !== 0) {
2717
2843
  ctx.strokeStyle = detail.stroke;
@@ -2728,7 +2854,7 @@ var __privateMethod = (obj, member, method) => {
2728
2854
  });
2729
2855
  }
2730
2856
  function drawElement(ctx, elem, opts) {
2731
- var _a;
2857
+ var _a, _b, _c;
2732
2858
  if (((_a = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
2733
2859
  return;
2734
2860
  }
@@ -2737,6 +2863,10 @@ var __privateMethod = (obj, member, method) => {
2737
2863
  if (scale < 1 && (w2 * scale < 1 || h2 * scale < 1) || opts.parentOpacity === 0) {
2738
2864
  return;
2739
2865
  }
2866
+ const { overrideElementMap } = opts;
2867
+ if ((_c = (_b = overrideElementMap === null || overrideElementMap === void 0 ? void 0 : overrideElementMap[elem.uuid]) === null || _b === void 0 ? void 0 : _b.operations) === null || _c === void 0 ? void 0 : _c.invisible) {
2868
+ return;
2869
+ }
2740
2870
  try {
2741
2871
  switch (elem.type) {
2742
2872
  case "rect": {
@@ -2782,7 +2912,7 @@ var __privateMethod = (obj, member, method) => {
2782
2912
  }
2783
2913
  function drawGroup(ctx, elem, opts) {
2784
2914
  const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2785
- const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo, viewSizeInfo }) || elem;
2915
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo }) || elem;
2786
2916
  const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2787
2917
  rotateElement$1(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
2788
2918
  ctx.globalAlpha = getOpacity(elem) * parentOpacity;
@@ -2879,7 +3009,7 @@ var __privateMethod = (obj, member, method) => {
2879
3009
  function drawLayout(ctx, layout, opts, renderContent) {
2880
3010
  const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2881
3011
  const elem = Object.assign({ uuid: "layout", type: "group" }, layout);
2882
- const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
3012
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
2883
3013
  const angle2 = 0;
2884
3014
  const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2885
3015
  ctx.globalAlpha = 1;
@@ -2893,7 +3023,7 @@ var __privateMethod = (obj, member, method) => {
2893
3023
  if (layout.detail.overflow === "hidden") {
2894
3024
  const { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 } = opts;
2895
3025
  const elem2 = Object.assign({ uuid: "layout", type: "group" }, layout);
2896
- const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 }) || elem2;
3026
+ const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2 }) || elem2;
2897
3027
  const viewElem2 = Object.assign(Object.assign({}, elem2), viewElemSize);
2898
3028
  const { x: x3, y: y3, w: w3, h: h3, radiusList } = calcViewBoxSize(viewElem2, {
2899
3029
  viewScaleInfo: viewScaleInfo2,
@@ -2918,6 +3048,15 @@ var __privateMethod = (obj, member, method) => {
2918
3048
  drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
2919
3049
  ctx.globalAlpha = parentOpacity;
2920
3050
  }
3051
+ function drawGlobalBackground(ctx, global, opts) {
3052
+ if (typeof (global === null || global === void 0 ? void 0 : global.background) === "string") {
3053
+ const { viewSizeInfo } = opts;
3054
+ const { width, height } = viewSizeInfo;
3055
+ ctx.globalAlpha = 1;
3056
+ ctx.fillStyle = global.background;
3057
+ ctx.fillRect(0, 0, width, height);
3058
+ }
3059
+ }
2921
3060
  var __awaiter = function(thisArg, _arguments, P, generator) {
2922
3061
  function adopt(value) {
2923
3062
  return value instanceof P ? value : new P(function(resolve) {
@@ -3184,7 +3323,7 @@ var __privateMethod = (obj, member, method) => {
3184
3323
  }
3185
3324
  drawData(data, opts) {
3186
3325
  const loader = __classPrivateFieldGet$5(this, _Renderer_loader, "f");
3187
- const { calculator } = __classPrivateFieldGet$5(this, _Renderer_opts, "f");
3326
+ const { calculator, sharer } = __classPrivateFieldGet$5(this, _Renderer_opts, "f");
3188
3327
  const viewContext = __classPrivateFieldGet$5(this, _Renderer_opts, "f").viewContext;
3189
3328
  viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
3190
3329
  const parentElementSize = {
@@ -3198,8 +3337,10 @@ var __privateMethod = (obj, member, method) => {
3198
3337
  calculator,
3199
3338
  parentElementSize,
3200
3339
  elementAssets: data.assets,
3201
- parentOpacity: 1
3340
+ parentOpacity: 1,
3341
+ overrideElementMap: sharer === null || sharer === void 0 ? void 0 : sharer.getActiveOverrideElemenentMap()
3202
3342
  }, opts);
3343
+ drawGlobalBackground(viewContext, data.global, drawOpts);
3203
3344
  if (data.layout) {
3204
3345
  drawLayout(viewContext, data.layout, drawOpts, () => {
3205
3346
  drawElementList(viewContext, data, drawOpts);
@@ -3627,7 +3768,8 @@ var __privateMethod = (obj, member, method) => {
3627
3768
  offsetLeft: 0,
3628
3769
  offsetRight: 0,
3629
3770
  offsetTop: 0,
3630
- offsetBottom: 0
3771
+ offsetBottom: 0,
3772
+ overrideElementMap: null
3631
3773
  };
3632
3774
  class Sharer {
3633
3775
  constructor() {
@@ -3695,6 +3837,12 @@ var __privateMethod = (obj, member, method) => {
3695
3837
  };
3696
3838
  return sizeInfo;
3697
3839
  }
3840
+ getActiveOverrideElemenentMap() {
3841
+ return __classPrivateFieldGet$2(this, _Sharer_activeStore, "f").get("overrideElementMap");
3842
+ }
3843
+ setActiveOverrideElemenentMap(map) {
3844
+ __classPrivateFieldGet$2(this, _Sharer_activeStore, "f").set("overrideElementMap", map);
3845
+ }
3698
3846
  }
3699
3847
  _Sharer_activeStore = /* @__PURE__ */ new WeakMap(), _Sharer_sharedStore = /* @__PURE__ */ new WeakMap();
3700
3848
  var __classPrivateFieldSet$1 = function(receiver, state, value, kind, f) {
@@ -3795,15 +3943,15 @@ var __privateMethod = (obj, member, method) => {
3795
3943
  const originViewSize = sharer.getActiveViewSizeInfo();
3796
3944
  const newViewSize = Object.assign(Object.assign({}, originViewSize), viewSize);
3797
3945
  const { width, height, devicePixelRatio } = newViewSize;
3798
- const { underContext, boardContext, helperContext, viewContext } = __classPrivateFieldGet$1(this, _Viewer_opts, "f").boardContent;
3946
+ const { underlayContext, boardContext, overlayContext, viewContext } = __classPrivateFieldGet$1(this, _Viewer_opts, "f").boardContent;
3799
3947
  boardContext.canvas.width = width * devicePixelRatio;
3800
3948
  boardContext.canvas.height = height * devicePixelRatio;
3801
3949
  boardContext.canvas.style.width = `${width}px`;
3802
3950
  boardContext.canvas.style.height = `${height}px`;
3803
- underContext.canvas.width = width * devicePixelRatio;
3804
- underContext.canvas.height = height * devicePixelRatio;
3805
- helperContext.canvas.width = width * devicePixelRatio;
3806
- helperContext.canvas.height = height * devicePixelRatio;
3951
+ underlayContext.canvas.width = width * devicePixelRatio;
3952
+ underlayContext.canvas.height = height * devicePixelRatio;
3953
+ overlayContext.canvas.width = width * devicePixelRatio;
3954
+ overlayContext.canvas.height = height * devicePixelRatio;
3807
3955
  viewContext.canvas.width = width * devicePixelRatio;
3808
3956
  viewContext.canvas.height = height * devicePixelRatio;
3809
3957
  sharer.setActiveViewSizeInfo(newViewSize);
@@ -4036,18 +4184,18 @@ var __privateMethod = (obj, member, method) => {
4036
4184
  const { width, height, devicePixelRatio } = newViewSize;
4037
4185
  const { boardContent } = __classPrivateFieldGet(this, _Board_opts, "f");
4038
4186
  boardContent.viewContext.$resize({ width, height, devicePixelRatio });
4039
- boardContent.helperContext.$resize({ width, height, devicePixelRatio });
4187
+ boardContent.overlayContext.$resize({ width, height, devicePixelRatio });
4040
4188
  boardContent.boardContext.$resize({ width, height, devicePixelRatio });
4041
- boardContent.underContext.$resize({ width, height, devicePixelRatio });
4189
+ boardContent.underlayContext.$resize({ width, height, devicePixelRatio });
4042
4190
  __classPrivateFieldGet(this, _Board_viewer, "f").drawFrame();
4043
4191
  __classPrivateFieldGet(this, _Board_watcher, "f").trigger("resize", viewSize);
4044
4192
  __classPrivateFieldGet(this, _Board_sharer, "f").setActiveViewSizeInfo(newViewSize);
4045
4193
  }
4046
4194
  clear() {
4047
4195
  const { boardContent } = __classPrivateFieldGet(this, _Board_opts, "f");
4048
- const { underContext, helperContext, viewContext, boardContext } = boardContent;
4049
- underContext.clearRect(0, 0, underContext.canvas.width, underContext.canvas.height);
4050
- helperContext.clearRect(0, 0, helperContext.canvas.width, helperContext.canvas.height);
4196
+ const { underlayContext, overlayContext, viewContext, boardContext } = boardContent;
4197
+ underlayContext.clearRect(0, 0, underlayContext.canvas.width, underlayContext.canvas.height);
4198
+ overlayContext.clearRect(0, 0, overlayContext.canvas.width, overlayContext.canvas.height);
4051
4199
  viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
4052
4200
  boardContext.clearRect(0, 0, boardContext.canvas.width, boardContext.canvas.height);
4053
4201
  __classPrivateFieldGet(this, _Board_instances, "m", _Board_handleClear).call(this);
@@ -5631,7 +5779,7 @@ var __privateMethod = (obj, member, method) => {
5631
5779
  const middlewareEventTextChange = "@middleware/text-change";
5632
5780
  const defaultElementDetail = getDefaultElementDetailConfig();
5633
5781
  const MiddlewareTextEditor = (opts) => {
5634
- const { eventHub, boardContent, viewer } = opts;
5782
+ const { eventHub, boardContent, viewer, sharer } = opts;
5635
5783
  const canvas = boardContent.boardContext.canvas;
5636
5784
  const textarea = document.createElement("div");
5637
5785
  textarea.setAttribute("contenteditable", "true");
@@ -5654,8 +5802,24 @@ var __privateMethod = (obj, member, method) => {
5654
5802
  resetCanvasWrapper();
5655
5803
  resetTextArea(e);
5656
5804
  mask.style.display = "block";
5805
+ if (activeElem == null ? void 0 : activeElem.uuid) {
5806
+ sharer.setActiveOverrideElemenentMap({
5807
+ [activeElem.uuid]: {
5808
+ operations: { invisible: true }
5809
+ }
5810
+ });
5811
+ viewer.drawFrame();
5812
+ }
5657
5813
  };
5658
5814
  const hideTextArea = () => {
5815
+ if (activeElem == null ? void 0 : activeElem.uuid) {
5816
+ const map = sharer.getActiveOverrideElemenentMap();
5817
+ if (map) {
5818
+ delete map[activeElem.uuid];
5819
+ }
5820
+ sharer.setActiveOverrideElemenentMap(map);
5821
+ viewer.drawFrame();
5822
+ }
5659
5823
  mask.style.display = "none";
5660
5824
  activeElem = null;
5661
5825
  activePosition = [];
@@ -5745,11 +5909,11 @@ var __privateMethod = (obj, member, method) => {
5745
5909
  textarea.style.resize = "none";
5746
5910
  textarea.style.overflow = "hidden";
5747
5911
  textarea.style.wordBreak = "break-all";
5748
- textarea.style.background = "#FFFFFF";
5749
- textarea.style.color = "#333333";
5912
+ textarea.style.background = "transparent";
5913
+ textarea.style.color = `${detail.color || "#333333"}`;
5750
5914
  textarea.style.fontSize = `${detail.fontSize * scale}px`;
5751
- textarea.style.lineHeight = `${detail.lineHeight * scale}px`;
5752
- textarea.style.fontFamily = detail.fontFamily;
5915
+ textarea.style.lineHeight = `${(detail.lineHeight || detail.fontSize) * scale}px`;
5916
+ textarea.style.fontFamily = enhanceFontFamliy(detail.fontFamily);
5753
5917
  textarea.style.fontWeight = `${detail.fontWeight}`;
5754
5918
  textarea.style.padding = "0";
5755
5919
  textarea.style.margin = "0";
@@ -5834,7 +5998,7 @@ var __privateMethod = (obj, member, method) => {
5834
5998
  };
5835
5999
  const MiddlewareSelector = (opts) => {
5836
6000
  const { viewer, sharer, boardContent, calculator, eventHub } = opts;
5837
- const { helperContext } = boardContent;
6001
+ const { overlayContext } = boardContent;
5838
6002
  let prevPoint = null;
5839
6003
  let inBusyMode = null;
5840
6004
  sharer.setSharedStorage(keyActionType, null);
@@ -5891,7 +6055,7 @@ var __privateMethod = (obj, member, method) => {
5891
6055
  };
5892
6056
  const pointTargetBaseOptions = () => {
5893
6057
  return {
5894
- ctx: helperContext,
6058
+ ctx: overlayContext,
5895
6059
  calculator,
5896
6060
  data: sharer.getActiveStorage("data"),
5897
6061
  selectedElements: getActiveElements(),
@@ -5982,7 +6146,7 @@ var __privateMethod = (obj, member, method) => {
5982
6146
  };
5983
6147
  if ((groupQueue == null ? void 0 : groupQueue.length) > 0) {
5984
6148
  const isInActiveGroup = isPointInViewActiveGroup(e.point, {
5985
- ctx: helperContext,
6149
+ ctx: overlayContext,
5986
6150
  viewScaleInfo: sharer.getActiveViewScaleInfo(),
5987
6151
  viewSizeInfo: sharer.getActiveViewSizeInfo(),
5988
6152
  groupQueue: sharer.getSharedStorage(keyGroupQueue)
@@ -6059,7 +6223,7 @@ var __privateMethod = (obj, member, method) => {
6059
6223
  const groupQueue = sharer.getSharedStorage(keyGroupQueue);
6060
6224
  if ((groupQueue == null ? void 0 : groupQueue.length) > 0) {
6061
6225
  if (isPointInViewActiveGroup(e.point, {
6062
- ctx: helperContext,
6226
+ ctx: overlayContext,
6063
6227
  viewScaleInfo: sharer.getActiveViewScaleInfo(),
6064
6228
  viewSizeInfo: sharer.getActiveViewSizeInfo(),
6065
6229
  groupQueue
@@ -6352,7 +6516,7 @@ var __privateMethod = (obj, member, method) => {
6352
6516
  viewer.drawFrame();
6353
6517
  },
6354
6518
  doubleClick(e) {
6355
- var _a, _b, _c, _d, _e, _f;
6519
+ var _a, _b, _c, _d, _e, _f, _g, _h;
6356
6520
  if (sharer.getSharedStorage(keyEnableSelectInGroup) === false) {
6357
6521
  return;
6358
6522
  }
@@ -6369,11 +6533,11 @@ var __privateMethod = (obj, member, method) => {
6369
6533
  viewer.drawFrame();
6370
6534
  return;
6371
6535
  }
6372
- } else if (target.elements.length === 1 && ((_d = target.elements[0]) == null ? void 0 : _d.type) === "text") {
6536
+ } else if (target.elements.length === 1 && ((_d = target.elements[0]) == null ? void 0 : _d.type) === "text" && !((_f = (_e = target.elements[0]) == null ? void 0 : _e.operations) == null ? void 0 : _f.invisible)) {
6373
6537
  eventHub.trigger(middlewareEventTextEdit, {
6374
6538
  element: target.elements[0],
6375
6539
  groupQueue: sharer.getSharedStorage(keyGroupQueue) || [],
6376
- position: getElementPositionFromList((_e = target.elements[0]) == null ? void 0 : _e.uuid, ((_f = sharer.getActiveStorage("data")) == null ? void 0 : _f.elements) || []),
6540
+ position: getElementPositionFromList((_g = target.elements[0]) == null ? void 0 : _g.uuid, ((_h = sharer.getActiveStorage("data")) == null ? void 0 : _h.elements) || []),
6377
6541
  viewScaleInfo: sharer.getActiveViewScaleInfo()
6378
6542
  });
6379
6543
  }
@@ -6404,10 +6568,10 @@ var __privateMethod = (obj, member, method) => {
6404
6568
  }) : null;
6405
6569
  const isLock = !!((_a = hoverElement == null ? void 0 : hoverElement.operations) == null ? void 0 : _a.lock);
6406
6570
  if ((groupQueue == null ? void 0 : groupQueue.length) > 0) {
6407
- drawGroupQueueVertexesWrappers(helperContext, groupQueueVertexesList, drawBaseOpts);
6571
+ drawGroupQueueVertexesWrappers(overlayContext, groupQueueVertexesList, drawBaseOpts);
6408
6572
  if (hoverElement && actionType !== "drag") {
6409
6573
  if (isLock) {
6410
- drawLockVertexesWrapper(helperContext, hoverElementVertexes, {
6574
+ drawLockVertexesWrapper(overlayContext, hoverElementVertexes, {
6411
6575
  ...drawBaseOpts,
6412
6576
  controller: calcElementSizeController(hoverElement, {
6413
6577
  groupQueue,
@@ -6416,11 +6580,11 @@ var __privateMethod = (obj, member, method) => {
6416
6580
  })
6417
6581
  });
6418
6582
  } else {
6419
- drawHoverVertexesWrapper(helperContext, hoverElementVertexes, drawBaseOpts);
6583
+ drawHoverVertexesWrapper(overlayContext, hoverElementVertexes, drawBaseOpts);
6420
6584
  }
6421
6585
  }
6422
6586
  if (!isLock && elem && ["select", "drag", "resize"].includes(actionType)) {
6423
- drawSelectedElementControllersVertexes(helperContext, selectedElementController, {
6587
+ drawSelectedElementControllersVertexes(overlayContext, selectedElementController, {
6424
6588
  ...drawBaseOpts,
6425
6589
  element: elem,
6426
6590
  calculator,
@@ -6429,7 +6593,7 @@ var __privateMethod = (obj, member, method) => {
6429
6593
  if (actionType === "drag") {
6430
6594
  const xLines = sharer2.getSharedStorage(keySelectedReferenceXLines);
6431
6595
  const yLines = sharer2.getSharedStorage(keySelectedReferenceYLines);
6432
- drawReferenceLines(helperContext, {
6596
+ drawReferenceLines(overlayContext, {
6433
6597
  xLines,
6434
6598
  yLines
6435
6599
  });
@@ -6438,7 +6602,7 @@ var __privateMethod = (obj, member, method) => {
6438
6602
  } else {
6439
6603
  if (hoverElement && actionType !== "drag") {
6440
6604
  if (isLock) {
6441
- drawLockVertexesWrapper(helperContext, hoverElementVertexes, {
6605
+ drawLockVertexesWrapper(overlayContext, hoverElementVertexes, {
6442
6606
  ...drawBaseOpts,
6443
6607
  controller: calcElementSizeController(hoverElement, {
6444
6608
  groupQueue,
@@ -6447,11 +6611,11 @@ var __privateMethod = (obj, member, method) => {
6447
6611
  })
6448
6612
  });
6449
6613
  } else {
6450
- drawHoverVertexesWrapper(helperContext, hoverElementVertexes, drawBaseOpts);
6614
+ drawHoverVertexesWrapper(overlayContext, hoverElementVertexes, drawBaseOpts);
6451
6615
  }
6452
6616
  }
6453
6617
  if (!isLock && elem && ["select", "drag", "resize"].includes(actionType)) {
6454
- drawSelectedElementControllersVertexes(helperContext, selectedElementController, {
6618
+ drawSelectedElementControllersVertexes(overlayContext, selectedElementController, {
6455
6619
  ...drawBaseOpts,
6456
6620
  element: elem,
6457
6621
  calculator,
@@ -6460,13 +6624,13 @@ var __privateMethod = (obj, member, method) => {
6460
6624
  if (actionType === "drag") {
6461
6625
  const xLines = sharer2.getSharedStorage(keySelectedReferenceXLines);
6462
6626
  const yLines = sharer2.getSharedStorage(keySelectedReferenceYLines);
6463
- drawReferenceLines(helperContext, {
6627
+ drawReferenceLines(overlayContext, {
6464
6628
  xLines,
6465
6629
  yLines
6466
6630
  });
6467
6631
  }
6468
6632
  } else if (actionType === "area" && areaStart && areaEnd) {
6469
- drawArea(helperContext, { start: areaStart, end: areaEnd });
6633
+ drawArea(overlayContext, { start: areaStart, end: areaEnd });
6470
6634
  } else if (["drag-list", "drag-list-end"].includes(actionType)) {
6471
6635
  const listAreaSize = calcSelectedElementsArea(getActiveElements(), {
6472
6636
  viewScaleInfo: sharer2.getActiveViewScaleInfo(),
@@ -6474,7 +6638,7 @@ var __privateMethod = (obj, member, method) => {
6474
6638
  calculator
6475
6639
  });
6476
6640
  if (listAreaSize) {
6477
- drawListArea(helperContext, { areaSize: listAreaSize });
6641
+ drawListArea(overlayContext, { areaSize: listAreaSize });
6478
6642
  }
6479
6643
  }
6480
6644
  }
@@ -6496,8 +6660,8 @@ var __privateMethod = (obj, member, method) => {
6496
6660
  scrollBarColor: "#FFFFFF60",
6497
6661
  showScrollBar: false
6498
6662
  };
6499
- function isPointAtRect(helperContext, p, rect) {
6500
- const ctx = helperContext;
6663
+ function isPointAtRect(overlayContext, p, rect) {
6664
+ const ctx = overlayContext;
6501
6665
  const { x: x2, y: y2, w: w2, h: h2 } = rect;
6502
6666
  ctx.beginPath();
6503
6667
  ctx.rect(x2, y2, w2, h2);
@@ -6507,12 +6671,12 @@ var __privateMethod = (obj, member, method) => {
6507
6671
  }
6508
6672
  return false;
6509
6673
  }
6510
- function isPointInScrollThumb(helperContext, p, opts) {
6674
+ function isPointInScrollThumb(overlayContext, p, opts) {
6511
6675
  let thumbType = null;
6512
6676
  const { xThumbRect, yThumbRect } = opts;
6513
- if (xThumbRect && isPointAtRect(helperContext, p, xThumbRect)) {
6677
+ if (xThumbRect && isPointAtRect(overlayContext, p, xThumbRect)) {
6514
6678
  thumbType = "X";
6515
- } else if (yThumbRect && isPointAtRect(helperContext, p, yThumbRect)) {
6679
+ } else if (yThumbRect && isPointAtRect(overlayContext, p, yThumbRect)) {
6516
6680
  thumbType = "Y";
6517
6681
  }
6518
6682
  return thumbType;
@@ -6636,8 +6800,8 @@ var __privateMethod = (obj, member, method) => {
6636
6800
  }
6637
6801
  ctx.restore();
6638
6802
  }
6639
- function drawScrollerInfo(helperContext, opts) {
6640
- const ctx = helperContext;
6803
+ function drawScrollerInfo(overlayContext, opts) {
6804
+ const ctx = overlayContext;
6641
6805
  const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
6642
6806
  const { activeThumbType, prevPoint, activePoint } = scrollInfo;
6643
6807
  const wrapper = calcScrollerInfo(viewScaleInfo, viewSizeInfo);
@@ -6680,7 +6844,7 @@ var __privateMethod = (obj, member, method) => {
6680
6844
  }
6681
6845
  const MiddlewareScroller = (opts) => {
6682
6846
  const { viewer, boardContent, sharer } = opts;
6683
- const { helperContext } = boardContent;
6847
+ const { overlayContext } = boardContent;
6684
6848
  sharer.setSharedStorage(keyXThumbRect, null);
6685
6849
  sharer.setSharedStorage(keyYThumbRect, null);
6686
6850
  const clear = () => {
@@ -6714,7 +6878,7 @@ var __privateMethod = (obj, member, method) => {
6714
6878
  }
6715
6879
  };
6716
6880
  const getThumbType = (p) => {
6717
- return isPointInScrollThumb(helperContext, p, {
6881
+ return isPointInScrollThumb(overlayContext, p, {
6718
6882
  xThumbRect: sharer.getSharedStorage(keyXThumbRect),
6719
6883
  yThumbRect: sharer.getSharedStorage(keyYThumbRect)
6720
6884
  });
@@ -6761,7 +6925,7 @@ var __privateMethod = (obj, member, method) => {
6761
6925
  }
6762
6926
  },
6763
6927
  beforeDrawFrame({ snapshot }) {
6764
- const { xThumbRect, yThumbRect } = drawScroller(helperContext, { snapshot });
6928
+ const { xThumbRect, yThumbRect } = drawScroller(overlayContext, { snapshot });
6765
6929
  sharer.setSharedStorage(keyXThumbRect, xThumbRect);
6766
6930
  sharer.setSharedStorage(keyYThumbRect, yThumbRect);
6767
6931
  }
@@ -6806,12 +6970,35 @@ var __privateMethod = (obj, member, method) => {
6806
6970
  const gridKeyColor = "#AAAAAA40";
6807
6971
  const lineSize = 1;
6808
6972
  const selectedAreaColor = "#196097";
6973
+ const limitRulerUnitList = [1, 2, 5, 10, 20, 50, 100, 200, 500];
6974
+ function limitRulerUnit(unit) {
6975
+ unit = Math.max(limitRulerUnitList[0], Math.min(unit, limitRulerUnitList[limitRulerUnitList.length - 1]));
6976
+ for (let i = 0; i < limitRulerUnitList.length - 1; i++) {
6977
+ const thisUnit = limitRulerUnitList[i];
6978
+ const nextUnit = limitRulerUnitList[i + 1];
6979
+ if (unit > nextUnit) {
6980
+ continue;
6981
+ }
6982
+ if (unit === thisUnit) {
6983
+ return unit;
6984
+ }
6985
+ if (unit === nextUnit) {
6986
+ return unit;
6987
+ }
6988
+ const mid = (thisUnit + nextUnit) / 2;
6989
+ if (unit <= mid) {
6990
+ return thisUnit;
6991
+ }
6992
+ return nextUnit;
6993
+ }
6994
+ return unit;
6995
+ }
6809
6996
  function calcRulerScaleList(opts) {
6810
6997
  const { scale, viewLength, viewOffset } = opts;
6811
6998
  const list = [];
6812
6999
  let rulerUnit = 10;
6813
7000
  rulerUnit = formatNumber(rulerUnit / scale, { decimalPlaces: 0 });
6814
- rulerUnit = Math.max(10, Math.min(rulerUnit, 1e3));
7001
+ rulerUnit = limitRulerUnit(rulerUnit);
6815
7002
  const rulerKeyUnit = rulerUnit * 10;
6816
7003
  const rulerSubKeyUnit = rulerUnit * 5;
6817
7004
  let index = 0;
@@ -6834,7 +7021,7 @@ var __privateMethod = (obj, member, method) => {
6834
7021
  list.push(rulerScale);
6835
7022
  index++;
6836
7023
  }
6837
- return list;
7024
+ return { list, rulerUnit };
6838
7025
  }
6839
7026
  function calcXRulerScaleList(opts) {
6840
7027
  const { viewScaleInfo, viewSizeInfo } = opts;
@@ -6946,7 +7133,7 @@ var __privateMethod = (obj, member, method) => {
6946
7133
  ctx.strokeStyle = borderColor;
6947
7134
  ctx.stroke();
6948
7135
  }
6949
- function drawUnderGrid(ctx, opts) {
7136
+ function drawGrid(ctx, opts) {
6950
7137
  const { xList, yList, viewSizeInfo } = opts;
6951
7138
  const { width, height } = viewSizeInfo;
6952
7139
  for (let i = 0; i < xList.length; i++) {
@@ -7034,7 +7221,7 @@ var __privateMethod = (obj, member, method) => {
7034
7221
  const middlewareEventRuler = "@middleware/show-ruler";
7035
7222
  const MiddlewareRuler = (opts) => {
7036
7223
  const { boardContent, viewer, eventHub, calculator } = opts;
7037
- const { helperContext, underContext } = boardContent;
7224
+ const { overlayContext, underlayContext } = boardContent;
7038
7225
  let show = true;
7039
7226
  let showGrid = true;
7040
7227
  const rulerCallback = (e) => {
@@ -7060,14 +7247,15 @@ var __privateMethod = (obj, member, method) => {
7060
7247
  if (show === true) {
7061
7248
  const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
7062
7249
  const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
7063
- drawScrollerSelectedArea(helperContext, { snapshot, calculator });
7064
- drawRulerBackground(helperContext, { viewScaleInfo, viewSizeInfo });
7065
- const xList = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
7066
- drawXRuler(helperContext, { scaleList: xList });
7067
- const yList = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
7068
- drawYRuler(helperContext, { scaleList: yList });
7250
+ drawScrollerSelectedArea(overlayContext, { snapshot, calculator });
7251
+ drawRulerBackground(overlayContext, { viewScaleInfo, viewSizeInfo });
7252
+ const { list: xList, rulerUnit } = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
7253
+ drawXRuler(overlayContext, { scaleList: xList });
7254
+ const { list: yList } = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
7255
+ drawYRuler(overlayContext, { scaleList: yList });
7069
7256
  if (showGrid === true) {
7070
- drawUnderGrid(underContext, {
7257
+ const ctx = rulerUnit === 1 ? overlayContext : underlayContext;
7258
+ drawGrid(ctx, {
7071
7259
  xList,
7072
7260
  yList,
7073
7261
  viewScaleInfo,
@@ -7236,7 +7424,7 @@ var __privateMethod = (obj, member, method) => {
7236
7424
  const infoLineHeight = 16;
7237
7425
  const MiddlewareInfo = (opts) => {
7238
7426
  const { boardContent, calculator } = opts;
7239
- const { helperContext } = boardContent;
7427
+ const { overlayContext } = boardContent;
7240
7428
  return {
7241
7429
  name: "@middleware/info",
7242
7430
  beforeDrawFrame({ snapshot }) {
@@ -7292,7 +7480,7 @@ var __privateMethod = (obj, member, method) => {
7292
7480
  const xyText = `${formatNumber(x22, { decimalPlaces: 0 })},${formatNumber(y22, { decimalPlaces: 0 })}`;
7293
7481
  const whText = `${formatNumber(w22, { decimalPlaces: 0 })}x${formatNumber(h22, { decimalPlaces: 0 })}`;
7294
7482
  const angleText = `${formatNumber(elem.angle || 0, { decimalPlaces: 0 })}°`;
7295
- drawSizeInfoText(helperContext, {
7483
+ drawSizeInfoText(overlayContext, {
7296
7484
  point: {
7297
7485
  x: rectInfo.bottom.x,
7298
7486
  y: rectInfo.bottom.y + infoFontSize
@@ -7305,7 +7493,7 @@ var __privateMethod = (obj, member, method) => {
7305
7493
  color: infoTextColor,
7306
7494
  background: infoBackground
7307
7495
  });
7308
- drawPositionInfoText(helperContext, {
7496
+ drawPositionInfoText(overlayContext, {
7309
7497
  point: {
7310
7498
  x: rectInfo.topLeft.x,
7311
7499
  y: rectInfo.topLeft.y - infoFontSize * 2
@@ -7318,7 +7506,7 @@ var __privateMethod = (obj, member, method) => {
7318
7506
  color: infoTextColor,
7319
7507
  background: infoBackground
7320
7508
  });
7321
- drawAngleInfoText(helperContext, {
7509
+ drawAngleInfoText(overlayContext, {
7322
7510
  point: {
7323
7511
  x: rectInfo.top.x + infoFontSize,
7324
7512
  y: rectInfo.top.y - infoFontSize * 2
@@ -7433,7 +7621,7 @@ var __privateMethod = (obj, member, method) => {
7433
7621
  }
7434
7622
  const MiddlewareLayoutSelector = (opts) => {
7435
7623
  const { sharer, boardContent, calculator, viewer, eventHub } = opts;
7436
- const { helperContext } = boardContent;
7624
+ const { overlayContext } = boardContent;
7437
7625
  let prevPoint = null;
7438
7626
  const clear = () => {
7439
7627
  prevPoint = null;
@@ -7653,7 +7841,7 @@ var __privateMethod = (obj, member, method) => {
7653
7841
  const { x: x2, y: y2, w: w2, h: h2 } = activeStore.data.layout;
7654
7842
  const size = { x: x2, y: y2, w: w2, h: h2 };
7655
7843
  const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
7656
- drawLayoutController(helperContext, { controller, operations: activeStore.data.layout.operations || {} });
7844
+ drawLayoutController(overlayContext, { controller, operations: activeStore.data.layout.operations || {} });
7657
7845
  }
7658
7846
  }
7659
7847
  },