@hailin-zheng/editor-core 2.0.4 → 2.0.6

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/index.js CHANGED
@@ -4,7 +4,8 @@ import * as acor from 'acorn';
4
4
  import { generate } from 'astring';
5
5
  import estraverse from 'estraverse';
6
6
  import * as bwipjs from 'bwip-js';
7
- import { init as init$1, styleModule, classModule, attributesModule, eventListenersModule } from 'snabbdom';
7
+ import JsBarcode from 'jsbarcode';
8
+ import { toVNode, init as init$1, styleModule, classModule, attributesModule, eventListenersModule } from 'snabbdom';
8
9
 
9
10
  /**
10
11
  * 元素事件
@@ -484,7 +485,23 @@ class CommonUtil {
484
485
  const { width, height } = rect;
485
486
  const x = 0;
486
487
  const y = 0;
487
- const points = [{ x, y, type: 'left-top' }, { x: x + width, y, type: 'right-top' }, { x: x + (Math.floor(width / 2)), y: y, type: 'top-middle' }, { x, y: y + Math.floor(height / 2), type: 'left-middle' }, { x, y: y + height, type: 'left-bottom' }, { x: width, y: Math.floor(height / 2), type: 'right-middle' }, { x: x + width, y: y + height, type: 'right-bottom' }, { x: x + (Math.floor(width / 2)), y: y + height, type: 'bottom-middle' }];
488
+ const points = [{ x, y, type: 'left-top' }, {
489
+ x: x + width,
490
+ y,
491
+ type: 'right-top'
492
+ }, { x: x + (Math.floor(width / 2)), y: y, type: 'top-middle' }, {
493
+ x,
494
+ y: y + Math.floor(height / 2),
495
+ type: 'left-middle'
496
+ }, { x, y: y + height, type: 'left-bottom' }, {
497
+ x: width,
498
+ y: Math.floor(height / 2),
499
+ type: 'right-middle'
500
+ }, { x: x + width, y: y + height, type: 'right-bottom' }, {
501
+ x: x + (Math.floor(width / 2)),
502
+ y: y + height,
503
+ type: 'bottom-middle'
504
+ }];
488
505
  for (let i = 0; i < points.length; i++) {
489
506
  const point = points[i];
490
507
  const { x: px, y: py } = point;
@@ -495,11 +512,11 @@ class CommonUtil {
495
512
  return null;
496
513
  }
497
514
  /**
498
- * 整形符合连线要求
499
- * @param points
500
- * @param width
501
- * @param strokeColor
502
- */
515
+ * 整形符合连线要求
516
+ * @param points
517
+ * @param width
518
+ * @param strokeColor
519
+ */
503
520
  static resharpPoints(points) {
504
521
  let prevPoint = points[0];
505
522
  const array = [];
@@ -621,6 +638,11 @@ class CommonUtil {
621
638
  return [item];
622
639
  }
623
640
  }
641
+ static removeChild(ele) {
642
+ while (ele.firstChild) {
643
+ ele.removeChild(ele.firstChild);
644
+ }
645
+ }
624
646
  }
625
647
 
626
648
  const docOpsMap = new Map();
@@ -3406,7 +3428,7 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3406
3428
  };
3407
3429
  pageCorner.children?.push(ElementUtil.getStrokeSvgPath(`M ${paddingPos.x - lineWidth} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y - lineWidth}`, "grey", drawLineWidth));
3408
3430
  paddingPos = { x: docWidth - padding.right, y: padding.top };
3409
- pageCorner.children?.push(ElementUtil.getStrokeSvgPath(`M ${paddingPos.x + lineWidth} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y + lineWidth}`, "grey", drawLineWidth));
3431
+ pageCorner.children?.push(ElementUtil.getStrokeSvgPath(`M ${paddingPos.x + lineWidth} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y - lineWidth}`, "grey", drawLineWidth));
3410
3432
  paddingPos = { x: padding.left, y: docHeight - this.padding.bottom };
3411
3433
  pageCorner.children?.push(ElementUtil.getStrokeSvgPath(`M ${paddingPos.x - lineWidth} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y + lineWidth}`, "grey", drawLineWidth));
3412
3434
  paddingPos = { x: docWidth - padding.left, y: docHeight - this.padding.bottom };
@@ -3803,7 +3825,7 @@ function drawDecorator(e, r) {
3803
3825
  function exportDecoratorHTML(event, r) {
3804
3826
  const canPaint = r.element.isMouseenter || r.element.isFocused;
3805
3827
  if (canPaint && r.element.paintRenders.indexOf(r) === 0) {
3806
- const strokeColor = r.element.isMouseenter ? '#ff0000' : '#0050b3';
3828
+ const strokeColor = '#0050b3';
3807
3829
  const verOffset = 0;
3808
3830
  const renderPosMap = getCurrentParaGroupRenders(r).map(item => ({ pos: getRenderPosToDoc(item), render: item }));
3809
3831
  if (renderPosMap.length > 1) {
@@ -9548,6 +9570,858 @@ class ValidateRenderObject extends CommContentBaseRenderObject {
9548
9570
  }
9549
9571
  }
9550
9572
 
9573
+ /*
9574
+ * QR Code generator library (TypeScript)
9575
+ *
9576
+ * Copyright (c) Project Nayuki. (MIT License)
9577
+ * https://www.nayuki.io/page/qr-code-generator-library
9578
+ *
9579
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
9580
+ * this software and associated documentation files (the "Software"), to deal in
9581
+ * the Software without restriction, including without limitation the rights to
9582
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9583
+ * the Software, and to permit persons to whom the Software is furnished to do so,
9584
+ * subject to the following conditions:
9585
+ * - The above copyright notice and this permission notice shall be included in
9586
+ * all copies or substantial portions of the Software.
9587
+ * - The Software is provided "as is", without warranty of any kind, express or
9588
+ * implied, including but not limited to the warranties of merchantability,
9589
+ * fitness for a particular purpose and noninfringement. In no event shall the
9590
+ * authors or copyright holders be liable for any claim, damages or other
9591
+ * liability, whether in an action of contract, tort or otherwise, arising from,
9592
+ * out of or in connection with the Software or the use or other dealings in the
9593
+ * Software.
9594
+ */
9595
+ var qrcodegen;
9596
+ (function (qrcodegen) {
9597
+ /*---- QR Code symbol class ----*/
9598
+ /*
9599
+ * A QR Code symbol, which is a type of two-dimension barcode.
9600
+ * Invented by Denso Wave and described in the ISO/IEC 18004 standard.
9601
+ * Instances of this class represent an immutable square grid of dark and light cells.
9602
+ * The class provides static factory functions to create a QR Code from text or binary data.
9603
+ * The class covers the QR Code Model 2 specification, supporting all versions (sizes)
9604
+ * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
9605
+ *
9606
+ * Ways to create a QR Code object:
9607
+ * - High level: Take the payload data and call QrCode.encodeText() or QrCode.encodeBinary().
9608
+ * - Mid level: Custom-make the list of segments and call QrCode.encodeSegments().
9609
+ * - Low level: Custom-make the array of data codeword bytes (including
9610
+ * segment headers and final padding, excluding error correction codewords),
9611
+ * supply the appropriate version number, and call the QrCode() constructor.
9612
+ * (Note that all ways require supplying the desired error correction level.)
9613
+ */
9614
+ class QrCode {
9615
+ version;
9616
+ errorCorrectionLevel;
9617
+ /*-- Static factory functions (high level) --*/
9618
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
9619
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
9620
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
9621
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
9622
+ // ecl argument if it can be done without increasing the version.
9623
+ static encodeText(text, ecl) {
9624
+ const segs = qrcodegen.QrSegment.makeSegments(text);
9625
+ return QrCode.encodeSegments(segs, ecl);
9626
+ }
9627
+ // Returns a QR Code representing the given binary data at the given error correction level.
9628
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
9629
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
9630
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
9631
+ static encodeBinary(data, ecl) {
9632
+ const seg = qrcodegen.QrSegment.makeBytes(data);
9633
+ return QrCode.encodeSegments([seg], ecl);
9634
+ }
9635
+ /*-- Static factory functions (mid level) --*/
9636
+ // Returns a QR Code representing the given segments with the given encoding parameters.
9637
+ // The smallest possible QR Code version within the given range is automatically
9638
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
9639
+ // may be higher than the ecl argument if it can be done without increasing the
9640
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
9641
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
9642
+ // This function allows the user to create a custom sequence of segments that switches
9643
+ // between modes (such as alphanumeric and byte) to encode text in less space.
9644
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
9645
+ static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
9646
+ if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION)
9647
+ || mask < -1 || mask > 7)
9648
+ throw new RangeError("Invalid value");
9649
+ // Find the minimal version number to use
9650
+ let version;
9651
+ let dataUsedBits;
9652
+ for (version = minVersion;; version++) {
9653
+ const dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available
9654
+ const usedBits = QrSegment.getTotalBits(segs, version);
9655
+ if (usedBits <= dataCapacityBits) {
9656
+ dataUsedBits = usedBits;
9657
+ break; // This version number is found to be suitable
9658
+ }
9659
+ if (version >= maxVersion) // All versions in the range could not fit the given data
9660
+ throw new RangeError("Data too long");
9661
+ }
9662
+ // Increase the error correction level while the data still fits in the current version number
9663
+ for (const newEcl of [QrCode.Ecc.MEDIUM, QrCode.Ecc.QUARTILE, QrCode.Ecc.HIGH]) { // From low to high
9664
+ if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8)
9665
+ ecl = newEcl;
9666
+ }
9667
+ // Concatenate all segments to create the data bit string
9668
+ let bb = [];
9669
+ for (const seg of segs) {
9670
+ appendBits(seg.mode.modeBits, 4, bb);
9671
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
9672
+ for (const b of seg.getData())
9673
+ bb.push(b);
9674
+ }
9675
+ assert(bb.length == dataUsedBits);
9676
+ // Add terminator and pad up to a byte if applicable
9677
+ const dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8;
9678
+ assert(bb.length <= dataCapacityBits);
9679
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
9680
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
9681
+ assert(bb.length % 8 == 0);
9682
+ // Pad with alternating bytes until data capacity is reached
9683
+ for (let padByte = 0xEC; bb.length < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
9684
+ appendBits(padByte, 8, bb);
9685
+ // Pack bits into bytes in big endian
9686
+ let dataCodewords = [];
9687
+ while (dataCodewords.length * 8 < bb.length)
9688
+ dataCodewords.push(0);
9689
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << (7 - (i & 7)));
9690
+ // Create the QR Code object
9691
+ return new QrCode(version, ecl, dataCodewords, mask);
9692
+ }
9693
+ /*-- Fields --*/
9694
+ // The width and height of this QR Code, measured in modules, between
9695
+ // 21 and 177 (inclusive). This is equal to version * 4 + 17.
9696
+ size;
9697
+ // The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
9698
+ // Even if a QR Code is created with automatic masking requested (mask = -1),
9699
+ // the resulting object still has a mask value between 0 and 7.
9700
+ mask;
9701
+ // The modules of this QR Code (false = light, true = dark).
9702
+ // Immutable after constructor finishes. Accessed through getModule().
9703
+ modules = [];
9704
+ // Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
9705
+ isFunction = [];
9706
+ /*-- Constructor (low level) and fields --*/
9707
+ // Creates a new QR Code with the given version number,
9708
+ // error correction level, data codeword bytes, and mask number.
9709
+ // This is a low-level API that most users should not use directly.
9710
+ // A mid-level API is the encodeSegments() function.
9711
+ constructor(
9712
+ // The version number of this QR Code, which is between 1 and 40 (inclusive).
9713
+ // This determines the size of this barcode.
9714
+ version,
9715
+ // The error correction level used in this QR Code.
9716
+ errorCorrectionLevel, dataCodewords, msk) {
9717
+ this.version = version;
9718
+ this.errorCorrectionLevel = errorCorrectionLevel;
9719
+ // Check scalar arguments
9720
+ if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION)
9721
+ throw new RangeError("Version value out of range");
9722
+ if (msk < -1 || msk > 7)
9723
+ throw new RangeError("Mask value out of range");
9724
+ this.size = version * 4 + 17;
9725
+ // Initialize both grids to be size*size arrays of Boolean false
9726
+ let row = [];
9727
+ for (let i = 0; i < this.size; i++)
9728
+ row.push(false);
9729
+ for (let i = 0; i < this.size; i++) {
9730
+ this.modules.push(row.slice()); // Initially all light
9731
+ this.isFunction.push(row.slice());
9732
+ }
9733
+ // Compute ECC, draw modules
9734
+ this.drawFunctionPatterns();
9735
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
9736
+ this.drawCodewords(allCodewords);
9737
+ // Do masking
9738
+ if (msk == -1) { // Automatically choose best mask
9739
+ let minPenalty = 1000000000;
9740
+ for (let i = 0; i < 8; i++) {
9741
+ this.applyMask(i);
9742
+ this.drawFormatBits(i);
9743
+ const penalty = this.getPenaltyScore();
9744
+ if (penalty < minPenalty) {
9745
+ msk = i;
9746
+ minPenalty = penalty;
9747
+ }
9748
+ this.applyMask(i); // Undoes the mask due to XOR
9749
+ }
9750
+ }
9751
+ assert(0 <= msk && msk <= 7);
9752
+ this.mask = msk;
9753
+ this.applyMask(msk); // Apply the final choice of mask
9754
+ this.drawFormatBits(msk); // Overwrite old format bits
9755
+ this.isFunction = [];
9756
+ }
9757
+ /*-- Accessor methods --*/
9758
+ // Returns the color of the module (pixel) at the given coordinates, which is false
9759
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
9760
+ // If the given coordinates are out of bounds, then false (light) is returned.
9761
+ getModule(x, y) {
9762
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
9763
+ }
9764
+ /*-- Private helper methods for constructor: Drawing function modules --*/
9765
+ // Reads this object's version field, and draws and marks all function modules.
9766
+ drawFunctionPatterns() {
9767
+ // Draw horizontal and vertical timing patterns
9768
+ for (let i = 0; i < this.size; i++) {
9769
+ this.setFunctionModule(6, i, i % 2 == 0);
9770
+ this.setFunctionModule(i, 6, i % 2 == 0);
9771
+ }
9772
+ // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
9773
+ this.drawFinderPattern(3, 3);
9774
+ this.drawFinderPattern(this.size - 4, 3);
9775
+ this.drawFinderPattern(3, this.size - 4);
9776
+ // Draw numerous alignment patterns
9777
+ const alignPatPos = this.getAlignmentPatternPositions();
9778
+ const numAlign = alignPatPos.length;
9779
+ for (let i = 0; i < numAlign; i++) {
9780
+ for (let j = 0; j < numAlign; j++) {
9781
+ // Don't draw on the three finder corners
9782
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
9783
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
9784
+ }
9785
+ }
9786
+ // Draw configuration data
9787
+ this.drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
9788
+ this.drawVersion();
9789
+ }
9790
+ // Draws two copies of the format bits (with its own error correction code)
9791
+ // based on the given mask and this object's error correction level field.
9792
+ drawFormatBits(mask) {
9793
+ // Calculate error correction code and pack bits
9794
+ const data = this.errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3
9795
+ let rem = data;
9796
+ for (let i = 0; i < 10; i++)
9797
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
9798
+ const bits = (data << 10 | rem) ^ 0x5412; // uint15
9799
+ assert(bits >>> 15 == 0);
9800
+ // Draw first copy
9801
+ for (let i = 0; i <= 5; i++)
9802
+ this.setFunctionModule(8, i, getBit(bits, i));
9803
+ this.setFunctionModule(8, 7, getBit(bits, 6));
9804
+ this.setFunctionModule(8, 8, getBit(bits, 7));
9805
+ this.setFunctionModule(7, 8, getBit(bits, 8));
9806
+ for (let i = 9; i < 15; i++)
9807
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
9808
+ // Draw second copy
9809
+ for (let i = 0; i < 8; i++)
9810
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
9811
+ for (let i = 8; i < 15; i++)
9812
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
9813
+ this.setFunctionModule(8, this.size - 8, true); // Always dark
9814
+ }
9815
+ // Draws two copies of the version bits (with its own error correction code),
9816
+ // based on this object's version field, iff 7 <= version <= 40.
9817
+ drawVersion() {
9818
+ if (this.version < 7)
9819
+ return;
9820
+ // Calculate error correction code and pack bits
9821
+ let rem = this.version; // version is uint6, in the range [7, 40]
9822
+ for (let i = 0; i < 12; i++)
9823
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25);
9824
+ const bits = this.version << 12 | rem; // uint18
9825
+ assert(bits >>> 18 == 0);
9826
+ // Draw two copies
9827
+ for (let i = 0; i < 18; i++) {
9828
+ const color = getBit(bits, i);
9829
+ const a = this.size - 11 + i % 3;
9830
+ const b = Math.floor(i / 3);
9831
+ this.setFunctionModule(a, b, color);
9832
+ this.setFunctionModule(b, a, color);
9833
+ }
9834
+ }
9835
+ // Draws a 9*9 finder pattern including the border separator,
9836
+ // with the center module at (x, y). Modules can be out of bounds.
9837
+ drawFinderPattern(x, y) {
9838
+ for (let dy = -4; dy <= 4; dy++) {
9839
+ for (let dx = -4; dx <= 4; dx++) {
9840
+ const dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
9841
+ const xx = x + dx;
9842
+ const yy = y + dy;
9843
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
9844
+ this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
9845
+ }
9846
+ }
9847
+ }
9848
+ // Draws a 5*5 alignment pattern, with the center module
9849
+ // at (x, y). All modules must be in bounds.
9850
+ drawAlignmentPattern(x, y) {
9851
+ for (let dy = -2; dy <= 2; dy++) {
9852
+ for (let dx = -2; dx <= 2; dx++)
9853
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
9854
+ }
9855
+ }
9856
+ // Sets the color of a module and marks it as a function module.
9857
+ // Only used by the constructor. Coordinates must be in bounds.
9858
+ setFunctionModule(x, y, isDark) {
9859
+ this.modules[y][x] = isDark;
9860
+ this.isFunction[y][x] = true;
9861
+ }
9862
+ /*-- Private helper methods for constructor: Codewords and masking --*/
9863
+ // Returns a new byte string representing the given data with the appropriate error correction
9864
+ // codewords appended to it, based on this object's version and error correction level.
9865
+ addEccAndInterleave(data) {
9866
+ const ver = this.version;
9867
+ const ecl = this.errorCorrectionLevel;
9868
+ if (data.length != QrCode.getNumDataCodewords(ver, ecl))
9869
+ throw new RangeError("Invalid argument");
9870
+ // Calculate parameter numbers
9871
+ const numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
9872
+ const blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
9873
+ const rawCodewords = Math.floor(QrCode.getNumRawDataModules(ver) / 8);
9874
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
9875
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
9876
+ // Split data into blocks and append ECC to each block
9877
+ let blocks = [];
9878
+ const rsDiv = QrCode.reedSolomonComputeDivisor(blockEccLen);
9879
+ for (let i = 0, k = 0; i < numBlocks; i++) {
9880
+ let dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
9881
+ k += dat.length;
9882
+ const ecc = QrCode.reedSolomonComputeRemainder(dat, rsDiv);
9883
+ if (i < numShortBlocks)
9884
+ dat.push(0);
9885
+ blocks.push(dat.concat(ecc));
9886
+ }
9887
+ // Interleave (not concatenate) the bytes from every block into a single sequence
9888
+ let result = [];
9889
+ for (let i = 0; i < blocks[0].length; i++) {
9890
+ blocks.forEach((block, j) => {
9891
+ // Skip the padding byte in short blocks
9892
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
9893
+ result.push(block[i]);
9894
+ });
9895
+ }
9896
+ assert(result.length == rawCodewords);
9897
+ return result;
9898
+ }
9899
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
9900
+ // data area of this QR Code. Function modules need to be marked off before this is called.
9901
+ drawCodewords(data) {
9902
+ if (data.length != Math.floor(QrCode.getNumRawDataModules(this.version) / 8))
9903
+ throw new RangeError("Invalid argument");
9904
+ let i = 0; // Bit index into the data
9905
+ // Do the funny zigzag scan
9906
+ for (let right = this.size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
9907
+ if (right == 6)
9908
+ right = 5;
9909
+ for (let vert = 0; vert < this.size; vert++) { // Vertical counter
9910
+ for (let j = 0; j < 2; j++) {
9911
+ const x = right - j; // Actual x coordinate
9912
+ const upward = ((right + 1) & 2) == 0;
9913
+ const y = upward ? this.size - 1 - vert : vert; // Actual y coordinate
9914
+ if (!this.isFunction[y][x] && i < data.length * 8) {
9915
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
9916
+ i++;
9917
+ }
9918
+ // If this QR Code has any remainder bits (0 to 7), they were assigned as
9919
+ // 0/false/light by the constructor and are left unchanged by this method
9920
+ }
9921
+ }
9922
+ }
9923
+ assert(i == data.length * 8);
9924
+ }
9925
+ // XORs the codeword modules in this QR Code with the given mask pattern.
9926
+ // The function modules must be marked and the codeword bits must be drawn
9927
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
9928
+ // the same mask value a second time will undo the mask. A final well-formed
9929
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
9930
+ applyMask(mask) {
9931
+ if (mask < 0 || mask > 7)
9932
+ throw new RangeError("Mask value out of range");
9933
+ for (let y = 0; y < this.size; y++) {
9934
+ for (let x = 0; x < this.size; x++) {
9935
+ let invert;
9936
+ switch (mask) {
9937
+ case 0:
9938
+ invert = (x + y) % 2 == 0;
9939
+ break;
9940
+ case 1:
9941
+ invert = y % 2 == 0;
9942
+ break;
9943
+ case 2:
9944
+ invert = x % 3 == 0;
9945
+ break;
9946
+ case 3:
9947
+ invert = (x + y) % 3 == 0;
9948
+ break;
9949
+ case 4:
9950
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
9951
+ break;
9952
+ case 5:
9953
+ invert = x * y % 2 + x * y % 3 == 0;
9954
+ break;
9955
+ case 6:
9956
+ invert = (x * y % 2 + x * y % 3) % 2 == 0;
9957
+ break;
9958
+ case 7:
9959
+ invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
9960
+ break;
9961
+ default: throw new Error("Unreachable");
9962
+ }
9963
+ if (!this.isFunction[y][x] && invert)
9964
+ this.modules[y][x] = !this.modules[y][x];
9965
+ }
9966
+ }
9967
+ }
9968
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
9969
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
9970
+ getPenaltyScore() {
9971
+ let result = 0;
9972
+ // Adjacent modules in row having same color, and finder-like patterns
9973
+ for (let y = 0; y < this.size; y++) {
9974
+ let runColor = false;
9975
+ let runX = 0;
9976
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
9977
+ for (let x = 0; x < this.size; x++) {
9978
+ if (this.modules[y][x] == runColor) {
9979
+ runX++;
9980
+ if (runX == 5)
9981
+ result += QrCode.PENALTY_N1;
9982
+ else if (runX > 5)
9983
+ result++;
9984
+ }
9985
+ else {
9986
+ this.finderPenaltyAddHistory(runX, runHistory);
9987
+ if (!runColor)
9988
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
9989
+ runColor = this.modules[y][x];
9990
+ runX = 1;
9991
+ }
9992
+ }
9993
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * QrCode.PENALTY_N3;
9994
+ }
9995
+ // Adjacent modules in column having same color, and finder-like patterns
9996
+ for (let x = 0; x < this.size; x++) {
9997
+ let runColor = false;
9998
+ let runY = 0;
9999
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
10000
+ for (let y = 0; y < this.size; y++) {
10001
+ if (this.modules[y][x] == runColor) {
10002
+ runY++;
10003
+ if (runY == 5)
10004
+ result += QrCode.PENALTY_N1;
10005
+ else if (runY > 5)
10006
+ result++;
10007
+ }
10008
+ else {
10009
+ this.finderPenaltyAddHistory(runY, runHistory);
10010
+ if (!runColor)
10011
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
10012
+ runColor = this.modules[y][x];
10013
+ runY = 1;
10014
+ }
10015
+ }
10016
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * QrCode.PENALTY_N3;
10017
+ }
10018
+ // 2*2 blocks of modules having same color
10019
+ for (let y = 0; y < this.size - 1; y++) {
10020
+ for (let x = 0; x < this.size - 1; x++) {
10021
+ const color = this.modules[y][x];
10022
+ if (color == this.modules[y][x + 1] &&
10023
+ color == this.modules[y + 1][x] &&
10024
+ color == this.modules[y + 1][x + 1])
10025
+ result += QrCode.PENALTY_N2;
10026
+ }
10027
+ }
10028
+ // Balance of dark and light modules
10029
+ let dark = 0;
10030
+ for (const row of this.modules)
10031
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
10032
+ const total = this.size * this.size; // Note that size is odd, so dark/total != 1/2
10033
+ // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)%
10034
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
10035
+ assert(0 <= k && k <= 9);
10036
+ result += k * QrCode.PENALTY_N4;
10037
+ assert(0 <= result && result <= 2568888); // Non-tight upper bound based on default values of PENALTY_N1, ..., N4
10038
+ return result;
10039
+ }
10040
+ /*-- Private helper functions --*/
10041
+ // Returns an ascending list of positions of alignment patterns for this version number.
10042
+ // Each position is in the range [0,177), and are used on both the x and y axes.
10043
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
10044
+ getAlignmentPatternPositions() {
10045
+ if (this.version == 1)
10046
+ return [];
10047
+ else {
10048
+ const numAlign = Math.floor(this.version / 7) + 2;
10049
+ const step = (this.version == 32) ? 26 :
10050
+ Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
10051
+ let result = [6];
10052
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
10053
+ result.splice(1, 0, pos);
10054
+ return result;
10055
+ }
10056
+ }
10057
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
10058
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
10059
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
10060
+ static getNumRawDataModules(ver) {
10061
+ if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION)
10062
+ throw new RangeError("Version number out of range");
10063
+ let result = (16 * ver + 128) * ver + 64;
10064
+ if (ver >= 2) {
10065
+ const numAlign = Math.floor(ver / 7) + 2;
10066
+ result -= (25 * numAlign - 10) * numAlign - 55;
10067
+ if (ver >= 7)
10068
+ result -= 36;
10069
+ }
10070
+ assert(208 <= result && result <= 29648);
10071
+ return result;
10072
+ }
10073
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
10074
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
10075
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
10076
+ static getNumDataCodewords(ver, ecl) {
10077
+ return Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
10078
+ QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] *
10079
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
10080
+ }
10081
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
10082
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
10083
+ static reedSolomonComputeDivisor(degree) {
10084
+ if (degree < 1 || degree > 255)
10085
+ throw new RangeError("Degree out of range");
10086
+ // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1.
10087
+ // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array [255, 8, 93].
10088
+ let result = [];
10089
+ for (let i = 0; i < degree - 1; i++)
10090
+ result.push(0);
10091
+ result.push(1); // Start off with the monomial x^0
10092
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
10093
+ // and drop the highest monomial term which is always 1x^degree.
10094
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
10095
+ let root = 1;
10096
+ for (let i = 0; i < degree; i++) {
10097
+ // Multiply the current product by (x - r^i)
10098
+ for (let j = 0; j < result.length; j++) {
10099
+ result[j] = QrCode.reedSolomonMultiply(result[j], root);
10100
+ if (j + 1 < result.length)
10101
+ result[j] ^= result[j + 1];
10102
+ }
10103
+ root = QrCode.reedSolomonMultiply(root, 0x02);
10104
+ }
10105
+ return result;
10106
+ }
10107
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
10108
+ static reedSolomonComputeRemainder(data, divisor) {
10109
+ let result = divisor.map(_ => 0);
10110
+ for (const b of data) { // Polynomial division
10111
+ const factor = b ^ result.shift();
10112
+ result.push(0);
10113
+ divisor.forEach((coef, i) => result[i] ^= QrCode.reedSolomonMultiply(coef, factor));
10114
+ }
10115
+ return result;
10116
+ }
10117
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
10118
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
10119
+ static reedSolomonMultiply(x, y) {
10120
+ if (x >>> 8 != 0 || y >>> 8 != 0)
10121
+ throw new RangeError("Byte out of range");
10122
+ // Russian peasant multiplication
10123
+ let z = 0;
10124
+ for (let i = 7; i >= 0; i--) {
10125
+ z = (z << 1) ^ ((z >>> 7) * 0x11D);
10126
+ z ^= ((y >>> i) & 1) * x;
10127
+ }
10128
+ assert(z >>> 8 == 0);
10129
+ return z;
10130
+ }
10131
+ // Can only be called immediately after a light run is added, and
10132
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
10133
+ finderPenaltyCountPatterns(runHistory) {
10134
+ const n = runHistory[1];
10135
+ assert(n <= this.size * 3);
10136
+ const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
10137
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0)
10138
+ + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
10139
+ }
10140
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
10141
+ finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
10142
+ if (currentRunColor) { // Terminate dark run
10143
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
10144
+ currentRunLength = 0;
10145
+ }
10146
+ currentRunLength += this.size; // Add light border to final run
10147
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
10148
+ return this.finderPenaltyCountPatterns(runHistory);
10149
+ }
10150
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
10151
+ finderPenaltyAddHistory(currentRunLength, runHistory) {
10152
+ if (runHistory[0] == 0)
10153
+ currentRunLength += this.size; // Add light border to initial run
10154
+ runHistory.pop();
10155
+ runHistory.unshift(currentRunLength);
10156
+ }
10157
+ /*-- Constants and tables --*/
10158
+ // The minimum version number supported in the QR Code Model 2 standard.
10159
+ static MIN_VERSION = 1;
10160
+ // The maximum version number supported in the QR Code Model 2 standard.
10161
+ static MAX_VERSION = 40;
10162
+ // For use in getPenaltyScore(), when evaluating which mask is best.
10163
+ static PENALTY_N1 = 3;
10164
+ static PENALTY_N2 = 3;
10165
+ static PENALTY_N3 = 40;
10166
+ static PENALTY_N4 = 10;
10167
+ static ECC_CODEWORDS_PER_BLOCK = [
10168
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
10169
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
10170
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
10171
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
10172
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
10173
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // High
10174
+ ];
10175
+ static NUM_ERROR_CORRECTION_BLOCKS = [
10176
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
10177
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
10178
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
10179
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
10180
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
10181
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81], // High
10182
+ ];
10183
+ }
10184
+ qrcodegen.QrCode = QrCode;
10185
+ // Appends the given number of low-order bits of the given value
10186
+ // to the given buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len.
10187
+ function appendBits(val, len, bb) {
10188
+ if (len < 0 || len > 31 || val >>> len != 0)
10189
+ throw new RangeError("Value out of range");
10190
+ for (let i = len - 1; i >= 0; i--) // Append bit by bit
10191
+ bb.push((val >>> i) & 1);
10192
+ }
10193
+ // Returns true iff the i'th bit of x is set to 1.
10194
+ function getBit(x, i) {
10195
+ return ((x >>> i) & 1) != 0;
10196
+ }
10197
+ // Throws an exception if the given condition is false.
10198
+ function assert(cond) {
10199
+ if (!cond)
10200
+ throw new Error("Assertion error");
10201
+ }
10202
+ /*---- Data segment class ----*/
10203
+ /*
10204
+ * A segment of character/binary/control data in a QR Code symbol.
10205
+ * Instances of this class are immutable.
10206
+ * The mid-level way to create a segment is to take the payload data
10207
+ * and call a static factory function such as QrSegment.makeNumeric().
10208
+ * The low-level way to create a segment is to custom-make the bit buffer
10209
+ * and call the QrSegment() constructor with appropriate values.
10210
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
10211
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
10212
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
10213
+ */
10214
+ class QrSegment {
10215
+ mode;
10216
+ numChars;
10217
+ bitData;
10218
+ /*-- Static factory functions (mid level) --*/
10219
+ // Returns a segment representing the given binary data encoded in
10220
+ // byte mode. All input byte arrays are acceptable. Any text string
10221
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
10222
+ static makeBytes(data) {
10223
+ let bb = [];
10224
+ for (const b of data)
10225
+ appendBits(b, 8, bb);
10226
+ return new QrSegment(QrSegment.Mode.BYTE, data.length, bb);
10227
+ }
10228
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
10229
+ static makeNumeric(digits) {
10230
+ if (!QrSegment.isNumeric(digits))
10231
+ throw new RangeError("String contains non-numeric characters");
10232
+ let bb = [];
10233
+ for (let i = 0; i < digits.length;) { // Consume up to 3 digits per iteration
10234
+ const n = Math.min(digits.length - i, 3);
10235
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
10236
+ i += n;
10237
+ }
10238
+ return new QrSegment(QrSegment.Mode.NUMERIC, digits.length, bb);
10239
+ }
10240
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
10241
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
10242
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
10243
+ static makeAlphanumeric(text) {
10244
+ if (!QrSegment.isAlphanumeric(text))
10245
+ throw new RangeError("String contains unencodable characters in alphanumeric mode");
10246
+ let bb = [];
10247
+ let i;
10248
+ for (i = 0; i + 2 <= text.length; i += 2) { // Process groups of 2
10249
+ let temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
10250
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
10251
+ appendBits(temp, 11, bb);
10252
+ }
10253
+ if (i < text.length) // 1 character remaining
10254
+ appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
10255
+ return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length, bb);
10256
+ }
10257
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
10258
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
10259
+ static makeSegments(text) {
10260
+ // Select the most efficient segment encoding automatically
10261
+ if (text == "")
10262
+ return [];
10263
+ else if (QrSegment.isNumeric(text))
10264
+ return [QrSegment.makeNumeric(text)];
10265
+ else if (QrSegment.isAlphanumeric(text))
10266
+ return [QrSegment.makeAlphanumeric(text)];
10267
+ else
10268
+ return [QrSegment.makeBytes(QrSegment.toUtf8ByteArray(text))];
10269
+ }
10270
+ // Returns a segment representing an Extended Channel Interpretation
10271
+ // (ECI) designator with the given assignment value.
10272
+ static makeEci(assignVal) {
10273
+ let bb = [];
10274
+ if (assignVal < 0)
10275
+ throw new RangeError("ECI assignment value out of range");
10276
+ else if (assignVal < (1 << 7))
10277
+ appendBits(assignVal, 8, bb);
10278
+ else if (assignVal < (1 << 14)) {
10279
+ appendBits(0b10, 2, bb);
10280
+ appendBits(assignVal, 14, bb);
10281
+ }
10282
+ else if (assignVal < 1000000) {
10283
+ appendBits(0b110, 3, bb);
10284
+ appendBits(assignVal, 21, bb);
10285
+ }
10286
+ else
10287
+ throw new RangeError("ECI assignment value out of range");
10288
+ return new QrSegment(QrSegment.Mode.ECI, 0, bb);
10289
+ }
10290
+ // Tests whether the given string can be encoded as a segment in numeric mode.
10291
+ // A string is encodable iff each character is in the range 0 to 9.
10292
+ static isNumeric(text) {
10293
+ return QrSegment.NUMERIC_REGEX.test(text);
10294
+ }
10295
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
10296
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
10297
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
10298
+ static isAlphanumeric(text) {
10299
+ return QrSegment.ALPHANUMERIC_REGEX.test(text);
10300
+ }
10301
+ /*-- Constructor (low level) and fields --*/
10302
+ // Creates a new QR Code segment with the given attributes and data.
10303
+ // The character count (numChars) must agree with the mode and the bit buffer length,
10304
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
10305
+ constructor(
10306
+ // The mode indicator of this segment.
10307
+ mode,
10308
+ // The length of this segment's unencoded data. Measured in characters for
10309
+ // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
10310
+ // Always zero or positive. Not the same as the data's bit length.
10311
+ numChars,
10312
+ // The data bits of this segment. Accessed through getData().
10313
+ bitData) {
10314
+ this.mode = mode;
10315
+ this.numChars = numChars;
10316
+ this.bitData = bitData;
10317
+ if (numChars < 0)
10318
+ throw new RangeError("Invalid argument");
10319
+ this.bitData = bitData.slice(); // Make defensive copy
10320
+ }
10321
+ /*-- Methods --*/
10322
+ // Returns a new copy of the data bits of this segment.
10323
+ getData() {
10324
+ return this.bitData.slice(); // Make defensive copy
10325
+ }
10326
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
10327
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
10328
+ static getTotalBits(segs, version) {
10329
+ let result = 0;
10330
+ for (const seg of segs) {
10331
+ const ccbits = seg.mode.numCharCountBits(version);
10332
+ if (seg.numChars >= (1 << ccbits))
10333
+ return Infinity; // The segment's length doesn't fit the field's bit width
10334
+ result += 4 + ccbits + seg.bitData.length;
10335
+ }
10336
+ return result;
10337
+ }
10338
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
10339
+ static toUtf8ByteArray(str) {
10340
+ str = encodeURI(str);
10341
+ let result = [];
10342
+ for (let i = 0; i < str.length; i++) {
10343
+ if (str.charAt(i) != "%")
10344
+ result.push(str.charCodeAt(i));
10345
+ else {
10346
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
10347
+ i += 2;
10348
+ }
10349
+ }
10350
+ return result;
10351
+ }
10352
+ /*-- Constants --*/
10353
+ // Describes precisely all strings that are encodable in numeric mode.
10354
+ static NUMERIC_REGEX = /^[0-9]*$/;
10355
+ // Describes precisely all strings that are encodable in alphanumeric mode.
10356
+ static ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
10357
+ // The set of all legal characters in alphanumeric mode,
10358
+ // where each character value maps to the index in the string.
10359
+ static ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
10360
+ }
10361
+ qrcodegen.QrSegment = QrSegment;
10362
+ })(qrcodegen || (qrcodegen = {}));
10363
+ /*---- Public helper enumeration ----*/
10364
+ (function (qrcodegen) {
10365
+ (function (QrCode) {
10366
+ /*
10367
+ * The error correction level in a QR Code symbol. Immutable.
10368
+ */
10369
+ class Ecc {
10370
+ ordinal;
10371
+ formatBits;
10372
+ /*-- Constants --*/
10373
+ static LOW = new Ecc(0, 1); // The QR Code can tolerate about 7% erroneous codewords
10374
+ static MEDIUM = new Ecc(1, 0); // The QR Code can tolerate about 15% erroneous codewords
10375
+ static QUARTILE = new Ecc(2, 3); // The QR Code can tolerate about 25% erroneous codewords
10376
+ static HIGH = new Ecc(3, 2); // The QR Code can tolerate about 30% erroneous codewords
10377
+ /*-- Constructor and fields --*/
10378
+ constructor(
10379
+ // In the range 0 to 3 (unsigned 2-bit integer).
10380
+ ordinal,
10381
+ // (Package-private) In the range 0 to 3 (unsigned 2-bit integer).
10382
+ formatBits) {
10383
+ this.ordinal = ordinal;
10384
+ this.formatBits = formatBits;
10385
+ }
10386
+ }
10387
+ QrCode.Ecc = Ecc;
10388
+ })(qrcodegen.QrCode || (qrcodegen.QrCode = {}));
10389
+ })(qrcodegen || (qrcodegen = {}));
10390
+ /*---- Public helper enumeration ----*/
10391
+ (function (qrcodegen) {
10392
+ (function (QrSegment) {
10393
+ /*
10394
+ * Describes how a segment's data bits are interpreted. Immutable.
10395
+ */
10396
+ class Mode {
10397
+ modeBits;
10398
+ numBitsCharCount;
10399
+ /*-- Constants --*/
10400
+ static NUMERIC = new Mode(0x1, [10, 12, 14]);
10401
+ static ALPHANUMERIC = new Mode(0x2, [9, 11, 13]);
10402
+ static BYTE = new Mode(0x4, [8, 16, 16]);
10403
+ static KANJI = new Mode(0x8, [8, 10, 12]);
10404
+ static ECI = new Mode(0x7, [0, 0, 0]);
10405
+ /*-- Constructor and fields --*/
10406
+ constructor(
10407
+ // The mode indicator bits, which is a uint4 value (range 0 to 15).
10408
+ modeBits,
10409
+ // Number of character count bits for three different version ranges.
10410
+ numBitsCharCount) {
10411
+ this.modeBits = modeBits;
10412
+ this.numBitsCharCount = numBitsCharCount;
10413
+ }
10414
+ /*-- Method --*/
10415
+ // (Package-private) Returns the bit width of the character count field for a segment in
10416
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
10417
+ numCharCountBits(ver) {
10418
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
10419
+ }
10420
+ }
10421
+ QrSegment.Mode = Mode;
10422
+ })(qrcodegen.QrSegment || (qrcodegen.QrSegment = {}));
10423
+ })(qrcodegen || (qrcodegen = {}));
10424
+
9551
10425
  class DataElementBarcode extends DataElementLeaf {
9552
10426
  resizeable = true;
9553
10427
  barCodeCanvas;
@@ -9562,6 +10436,11 @@ class DataElementBarcode extends DataElementLeaf {
9562
10436
  this.cache = false;
9563
10437
  });
9564
10438
  }
10439
+ //伸缩的模式,auto:可以任意伸缩高度和宽度,scale:只能等比例伸缩高度宽度
10440
+ //resizeMode:'auto'|'scale'='auto';
10441
+ get resizeMode() {
10442
+ return this.props.type === 'qrcode';
10443
+ }
9565
10444
  createRenderObject() {
9566
10445
  const render = new DataElementBarcodeRenderObject(this);
9567
10446
  render.rect.width = this.props.width + 2;
@@ -9643,6 +10522,62 @@ class DataElementBarcodeRenderObject extends ResizeLeafRenderObject {
9643
10522
  ctxNative.fill();
9644
10523
  ctxNative.restore();
9645
10524
  }
10525
+ exportHTML(event) {
10526
+ const t = super.exportHTML(event);
10527
+ if (this.element.props.type === 'qrcode') {
10528
+ const QRC = qrcodegen.QrCode;
10529
+ const qr0 = QRC.encodeText(this.element.props.text, QRC.Ecc.MEDIUM);
10530
+ t.children = [this.toSvgString(qr0, 2, '#000', '#000')];
10531
+ }
10532
+ else {
10533
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
10534
+ JsBarcode(svg, this.element.props.text);
10535
+ const vNode = toVNode(svg);
10536
+ t.children = [vNode];
10537
+ }
10538
+ return t;
10539
+ }
10540
+ toSvgString(qr, border, lightColor, darkColor) {
10541
+ let parts = [];
10542
+ for (let y = 0; y < qr.size; y++) {
10543
+ for (let x = 0; x < qr.size; x++) {
10544
+ if (qr.getModule(x, y))
10545
+ parts.push(`M${x + border},${y + border}h1v1h-1z`);
10546
+ }
10547
+ }
10548
+ return {
10549
+ sel: 'svg',
10550
+ data: {
10551
+ ns: 'http://www.w3.org/2000/svg',
10552
+ attrs: {
10553
+ viewBox: `0 0 ${qr.size + border * 2} ${qr.size + border * 2}`,
10554
+ width: this.element.props.width,
10555
+ height: this.element.props.height,
10556
+ stroke: 'none'
10557
+ }
10558
+ },
10559
+ children: [{
10560
+ sel: 'rect',
10561
+ data: {
10562
+ ns: 'http://www.w3.org/2000/svg',
10563
+ attrs: {
10564
+ width: '100%',
10565
+ height: '100%',
10566
+ fill: '#fff'
10567
+ }
10568
+ }
10569
+ }, {
10570
+ sel: 'path',
10571
+ data: {
10572
+ ns: 'http://www.w3.org/2000/svg',
10573
+ attrs: {
10574
+ d: parts.join(" "),
10575
+ fill: '#000'
10576
+ }
10577
+ }
10578
+ }]
10579
+ };
10580
+ }
9646
10581
  }
9647
10582
  class DataElementBarcodeFactory extends ElementFactory {
9648
10583
  match(type) {
@@ -10337,6 +11272,57 @@ class DataElementListFactory extends DataElementBaseFactory {
10337
11272
  }
10338
11273
  }
10339
11274
 
11275
+ class BreakElement extends LeafElement {
11276
+ textProps;
11277
+ constructor() {
11278
+ super('br');
11279
+ this.textProps = new TextProps();
11280
+ this.textProps.fontSize = 14;
11281
+ this.textProps.fontName = '宋体';
11282
+ this.textProps.color = '#595959';
11283
+ }
11284
+ createRenderObject() {
11285
+ const symbol = new BreakRenderObject(this);
11286
+ symbol.rect.height = 14;
11287
+ symbol.rect.width = 7;
11288
+ return symbol;
11289
+ }
11290
+ serialize() {
11291
+ return {
11292
+ type: 'br',
11293
+ props: {}
11294
+ };
11295
+ }
11296
+ clone() {
11297
+ const clone = new BreakElement();
11298
+ //clone.renderCtx = this.renderCtx;
11299
+ return clone;
11300
+ }
11301
+ }
11302
+ class BreakRenderObject extends LeafRenderObject {
11303
+ render(e) {
11304
+ const { render, position } = e;
11305
+ if (render.drawMode === 'print') {
11306
+ return;
11307
+ }
11308
+ render.contentContext.drawText('↓', this.element.textProps, position.x, position.y, 20, this.rect.height);
11309
+ }
11310
+ clone() {
11311
+ const render = new BreakRenderObject(this.element);
11312
+ render.rect = ElementUtil.cloneRect(this.rect);
11313
+ return render;
11314
+ }
11315
+ }
11316
+ class BreakFactory extends ElementFactory {
11317
+ match(type) {
11318
+ return type === 'br';
11319
+ }
11320
+ createElement(data) {
11321
+ const ele = new BreakElement();
11322
+ return ele;
11323
+ }
11324
+ }
11325
+
10340
11326
  class DataElementText extends DataElementInlineGroup {
10341
11327
  //props: DataEleBaseTextProps;
10342
11328
  constructor() {
@@ -10367,10 +11353,19 @@ class DataElementText extends DataElementInlineGroup {
10367
11353
  this.pubOnChange('self');
10368
11354
  this.clearInnerItems();
10369
11355
  if (val) {
10370
- const valueText = new TextGroupElement();
10371
- this.props.valueTextProps.clone(valueText.props);
10372
- valueText.text = val + '';
10373
- this.addChild(valueText, this.length - 1);
11356
+ const items = val.split('<br/>');
11357
+ if (items.length) {
11358
+ items.forEach((item, index) => {
11359
+ const valueText = new TextGroupElement();
11360
+ this.props.valueTextProps.clone(valueText.props);
11361
+ valueText.text = item + '';
11362
+ this.addChild(valueText, this.length - 1);
11363
+ if (index < items.length - 1) {
11364
+ const brElement = new BreakElement();
11365
+ this.addChild(brElement, this.length - 1);
11366
+ }
11367
+ });
11368
+ }
10374
11369
  }
10375
11370
  this.onChangedValidate();
10376
11371
  }
@@ -11087,57 +12082,6 @@ class RadioBoxRenderObject extends LeafRenderObject {
11087
12082
  }
11088
12083
  }
11089
12084
 
11090
- class BreakElement extends LeafElement {
11091
- textProps;
11092
- constructor() {
11093
- super('br');
11094
- this.textProps = new TextProps();
11095
- this.textProps.fontSize = 14;
11096
- this.textProps.fontName = '宋体';
11097
- this.textProps.color = '#595959';
11098
- }
11099
- createRenderObject() {
11100
- const symbol = new BreakRenderObject(this);
11101
- symbol.rect.height = 14;
11102
- symbol.rect.width = 7;
11103
- return symbol;
11104
- }
11105
- serialize() {
11106
- return {
11107
- type: 'br',
11108
- props: {}
11109
- };
11110
- }
11111
- clone() {
11112
- const clone = new BreakElement();
11113
- //clone.renderCtx = this.renderCtx;
11114
- return clone;
11115
- }
11116
- }
11117
- class BreakRenderObject extends LeafRenderObject {
11118
- render(e) {
11119
- const { render, position } = e;
11120
- if (render.drawMode === 'print') {
11121
- return;
11122
- }
11123
- render.contentContext.drawText('↓', this.element.textProps, position.x, position.y, 20, this.rect.height);
11124
- }
11125
- clone() {
11126
- const render = new BreakRenderObject(this.element);
11127
- render.rect = ElementUtil.cloneRect(this.rect);
11128
- return render;
11129
- }
11130
- }
11131
- class BreakFactory extends ElementFactory {
11132
- match(type) {
11133
- return type === 'br';
11134
- }
11135
- createElement(data) {
11136
- const ele = new BreakElement();
11137
- return ele;
11138
- }
11139
- }
11140
-
11141
12085
  class ColumnPatchUtil {
11142
12086
  static getPatchPacks(cols, splitCols) {
11143
12087
  const oldLinePointMap = this.getLinePointMap(cols);
@@ -15962,7 +16906,7 @@ class DocumentEvent {
15962
16906
  //如果单元格中包含图片等可缩放的元素,并且元素的大小超过单元格,则当前图片的某一部分就无法缩放
15963
16907
  if (!this.ismousedown && this.focusedElement && this.focusedRect && this.focusedElement['resizeable']) {
15964
16908
  const relativePos = { x: mousePos.x - this.focusedRect.x, y: mousePos.y - this.focusedRect.y };
15965
- const isInCellBorder = CommonUtil.isInPictureResizePoint(this.focusedRect, relativePos, 4);
16909
+ let isInCellBorder = CommonUtil.isInPictureResizePoint(this.focusedRect, relativePos, 4);
15966
16910
  if (isInCellBorder) {
15967
16911
  cursorType = ElementUtil.getBorderCursor(isInCellBorder.borderType);
15968
16912
  if (isInCellBorder?.borderType === 'none') {
@@ -16564,6 +17508,7 @@ class DocumentEvent {
16564
17508
  const mousedownPos = this.edgeRenderInfo.mousedownPos;
16565
17509
  let moveDistanceX = this.currentPos.x - mousedownPos.x;
16566
17510
  let moveDistanceY = this.currentPos.y - mousedownPos.y;
17511
+ const isScale = imgElement['resizeMode'] === 'scale' || e.shift;
16567
17512
  if (['left-top', 'left-middle', 'left-bottom', 'right-top', 'right-middle', 'right-bottom', 'top-middle', 'bottom-middle'].indexOf(border) >= 0) {
16568
17513
  if (['left-middle', 'right-middle'].indexOf(border) >= 0) {
16569
17514
  moveDistanceY = 0;
@@ -16572,7 +17517,7 @@ class DocumentEvent {
16572
17517
  moveDistanceX = 0;
16573
17518
  }
16574
17519
  //shift键按比例缩放
16575
- if (e.shift && ['left-top', 'right-top', 'left-bottom', 'right-bottom'].indexOf(border) >= 0) {
17520
+ if (isScale || ['left-top', 'right-top', 'left-bottom', 'right-bottom'].indexOf(border) >= 0) {
16576
17521
  let scale = 1;
16577
17522
  if (Math.abs(moveDistanceX) > Math.abs(moveDistanceY)) {
16578
17523
  scale = moveDistanceX / imgElement.props.width;
@@ -16934,55 +17879,6 @@ class DocumentInput {
16934
17879
  onTabKeyEvent = new Subject$1();
16935
17880
  constructor(docCtx) {
16936
17881
  this.docCtx = docCtx;
16937
- // const os = ElementUtil.getOSPlatform();
16938
- // this.bindInput(node);
16939
- // node.addEventListener('keydown', evt => {
16940
- // const keyEvent = new KeyboradElementEvent(this.docCtx);
16941
- // keyEvent.sourceEvent = evt;
16942
- // if (DocumentEvent.invokeEvent('ElementKeyDown', this.docCtx.selectionState.startControl as LeafElement, keyEvent, 'All')) {
16943
- // return;
16944
- // }
16945
- // if (evt.keyCode === 8) {
16946
- // this.onBackspaceEvent.next(evt);
16947
- // } else if (evt.keyCode === 13 && !evt.shiftKey) {
16948
- // this.onEnterEvent.next();
16949
- // } else if (evt.keyCode === 37) {
16950
- // this.onLeftEvent.next();
16951
- // } else if (evt.keyCode === 39) {
16952
- // this.onRightEvent.next();
16953
- // } else if (evt.keyCode === 38) {
16954
- // this.onUpEvent.next();
16955
- // } else if (evt.keyCode === 40) {
16956
- // this.onDownEvent.next();
16957
- // } else if (evt.keyCode === 9) {
16958
- // evt.preventDefault();
16959
- // this.onTabKeyEvent.next();
16960
- // } else if (evt.keyCode === 13 && evt.shiftKey) {
16961
- // evt.preventDefault();
16962
- // this.onInsertBr.next();
16963
- // } else if (evt.keyCode === 46) {
16964
- // this.onDeleteEvent.next(evt);
16965
- // } else if (evt.ctrlKey && evt.keyCode === 65 && os !== 'Mac') {
16966
- // evt.preventDefault();
16967
- // this.onSelectAllEvent.next();
16968
- // } else if (evt.metaKey && evt.keyCode === 65 && os === 'Mac') {
16969
- // evt.preventDefault();
16970
- // this.onSelectAllEvent.next();
16971
- // } else if (evt.keyCode === 36) {
16972
- // this.onHomeEvent.next();
16973
- // } else if (evt.keyCode === 35) {
16974
- // this.onEndEvent.next();
16975
- // }
16976
- // });
16977
- // node.addEventListener('copy', evt => {
16978
- // this.onCopyEvent.next(evt);
16979
- // });
16980
- // node.addEventListener('paste', evt => {
16981
- // this.onPasteEvent.next(evt);
16982
- // })
16983
- // node.addEventListener('cut', evt => {
16984
- // this.onCutEvent.next(evt);
16985
- // })
16986
17882
  }
16987
17883
  getEventListener() {
16988
17884
  const os = ElementUtil.getOSPlatform();
@@ -18651,6 +19547,9 @@ function createPrintTemplate({ width, height, orient }) {
18651
19547
  box-sizing: border-box;
18652
19548
  -moz-box-sizing: border-box;
18653
19549
  }
19550
+ body *{
19551
+ white-space: pre;
19552
+ }
18654
19553
  @page {
18655
19554
  size: ${orient};
18656
19555
  margin: 0;
@@ -18721,6 +19620,18 @@ function printNodes(printNodes, options, printEvent = null) {
18721
19620
  }
18722
19621
  printIFrame.onload = () => {
18723
19622
  setTimeout(() => {
19623
+ printIFrame.contentWindow?.window.matchMedia('print').addListener(function (query) {
19624
+ if (!query.matches) {
19625
+ console.log('用户已经打印');
19626
+ // 执行打印完成后需要执行的代码
19627
+ }
19628
+ });
19629
+ printIFrame.contentWindow?.window.matchMedia('screen').addListener(function (query) {
19630
+ if (!query.matches) {
19631
+ console.log('用户已经打印');
19632
+ // 执行打印完成后需要执行的代码
19633
+ }
19634
+ });
18724
19635
  printIFrame.contentWindow?.print();
18725
19636
  printIFrame.parentNode?.removeChild(printIFrame);
18726
19637
  }, 0);
@@ -24593,18 +25504,12 @@ class DocumentPrintOffscreenBase {
24593
25504
  const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
24594
25505
  docSvgHelper.mode = 'print';
24595
25506
  const pageSvgVNodes = docRenders.filter((item, index) => !printRanges || printRanges.indexOf(index) >= 0).map(item => docSvgHelper.getPageSvgVNode(item));
24596
- ({
24597
- sel: 'div#docContent',
24598
- data: {},
24599
- children: [...pageSvgVNodes]
24600
- });
24601
25507
  const patch = init([
24602
25508
  modules.class,
24603
25509
  modules.props,
24604
25510
  modules.attributes,
24605
25511
  modules.style
24606
25512
  ]);
24607
- new DOMParser();
24608
25513
  const domNodes = pageSvgVNodes.map(item => patch(item)); //.map(item => docParser.parseFromString(item, 'text/html').firstChild) as Array<HTMLElement>;
24609
25514
  return domNodes;
24610
25515
  }
@@ -24664,12 +25569,16 @@ class EditorCalendarVNode {
24664
25569
  selectedDate;
24665
25570
  currentDate = '';
24666
25571
  onSetValue = new Subject$1();
25572
+ currTime;
25573
+ selectedTime;
24667
25574
  constructor() {
24668
25575
  this.currYear = createSignal(new Date().getFullYear());
24669
25576
  //月份赋值是按照索引来的,所以要减1
24670
25577
  this.currMonth = createSignal(new Date().getMonth());
24671
25578
  this.currCalendarMode = createSignal('day');
24672
25579
  this.selectedDate = createSignal(null);
25580
+ this.currTime = createSignal(null);
25581
+ this.selectedTime = createSignal(null);
24673
25582
  }
24674
25583
  reset() {
24675
25584
  this.currYear.value = new Date().getFullYear();
@@ -24678,6 +25587,8 @@ class EditorCalendarVNode {
24678
25587
  this.currCalendarMode.value = 'day';
24679
25588
  this.selectedDate.value = moment().format('YYYY-MM-DD');
24680
25589
  this.currentDate = '';
25590
+ this.currTime.value = null;
25591
+ this.selectedTime.value = null;
24681
25592
  }
24682
25593
  render(position, dataValue) {
24683
25594
  if (!this.currentDate && dataValue) {
@@ -24689,6 +25600,10 @@ class EditorCalendarVNode {
24689
25600
  if (!this.currentDate) {
24690
25601
  this.currentDate = moment().format('YYYY-MM-DD');
24691
25602
  }
25603
+ if (!this.currTime.value) {
25604
+ this.currTime.value = moment().format('HH:mm:ss');
25605
+ this.selectedTime.value = this.currTime.value;
25606
+ }
24692
25607
  const container = this.renderDropContainer(position);
24693
25608
  let viewNode;
24694
25609
  if (this.currCalendarMode.value === 'day') {
@@ -24815,6 +25730,31 @@ class EditorCalendarVNode {
24815
25730
  sel: 'div.editor-calendar-footer',
24816
25731
  data: {},
24817
25732
  children: [{
25733
+ sel: 'div.editor-calendar-footer-left',
25734
+ data: {},
25735
+ children: [
25736
+ {
25737
+ sel: 'input.editor-calendar-footer-left-time',
25738
+ data: {
25739
+ attrs: {
25740
+ value: this.currTime.value
25741
+ },
25742
+ on: {
25743
+ change: (event) => {
25744
+ if (moment(event.target.value, 'HH:mm:ss').isValid()) {
25745
+ this.selectedTime = event.target.value;
25746
+ }
25747
+ else {
25748
+ event.target.value = this.currTime.value;
25749
+ this.currTime.onChange();
25750
+ }
25751
+ }
25752
+ }
25753
+ }
25754
+ }
25755
+ ]
25756
+ },
25757
+ {
24818
25758
  sel: 'div.editor-calendar-footer-right',
24819
25759
  data: {},
24820
25760
  children: [{
@@ -24826,7 +25766,7 @@ class EditorCalendarVNode {
24826
25766
  this.onSetValue.next(new Date());
24827
25767
  }
24828
25768
  else {
24829
- this.onSetValue.next(moment(this.selectedDate.value).toDate());
25769
+ this.onSetValue.next(moment(this.selectedDate.value + ' ' + this.selectedTime.value).toDate());
24830
25770
  }
24831
25771
  }
24832
25772
  }
@@ -25869,12 +26809,18 @@ class DocEditor {
25869
26809
  */
25870
26810
  getCurrentDataElement() {
25871
26811
  const selectionState = this.documentSelection.selectionState;
25872
- const { startControl } = selectionState;
26812
+ const { startControl, startOffset } = selectionState;
25873
26813
  if (startControl) {
25874
26814
  if (!ElementUtil.verifyHitable(startControl)) {
25875
26815
  return null;
25876
26816
  }
25877
- return ElementUtil.getParent(startControl, validateDataEle);
26817
+ const dataEle = ElementUtil.getParent(startControl, validateDataEle);
26818
+ if (IsInSideDataElement(startControl, startOffset)) {
26819
+ return dataEle;
26820
+ }
26821
+ else {
26822
+ return null;
26823
+ }
25878
26824
  }
25879
26825
  return null;
25880
26826
  }
@@ -26457,7 +27403,7 @@ class DocEditor {
26457
27403
  const vNodeFunc = this.renderRoot();
26458
27404
  setActiveEditorContext(null);
26459
27405
  const render = () => {
26460
- console.time('patch');
27406
+ //console.time('patch');
26461
27407
  setActiveEditorContext(this);
26462
27408
  const vNode = vNodeFunc.render();
26463
27409
  setActiveEditorContext(null);
@@ -26469,7 +27415,7 @@ class DocEditor {
26469
27415
  this.vNodeDocContent = this.nodePatch(this.svgContainer, vNode);
26470
27416
  }
26471
27417
  this.afterNodePatch.next();
26472
- console.timeEnd('patch');
27418
+ //console.timeEnd('patch');
26473
27419
  };
26474
27420
  render();
26475
27421
  this.onShouldRender.subscribe(() => {
@@ -26561,8 +27507,10 @@ class DocEditor {
26561
27507
  }
26562
27508
  getHtml() {
26563
27509
  const offPrint = new DocumentPrintOffscreen();
26564
- offPrint.beforePrint.subscribe(() => { });
26565
- offPrint.afterPrint.subscribe(() => { });
27510
+ offPrint.beforePrint.subscribe(() => {
27511
+ });
27512
+ offPrint.afterPrint.subscribe(() => {
27513
+ });
26566
27514
  const html = offPrint.getSvgNodes(this.docCtx.document.paintRenders);
26567
27515
  console.log(html);
26568
27516
  }
@@ -26618,6 +27566,9 @@ class DocEditor {
26618
27566
  const values = options.filter(item => item.checked).map(item => item.code);
26619
27567
  dataEle.setValue(values);
26620
27568
  editor.setDataElemEndFocus(dataEle);
27569
+ if (!multiSelect) {
27570
+ editor.selectionState.clear();
27571
+ }
26621
27572
  };
26622
27573
  const itemsVNode = options.map(item => {
26623
27574
  const ckbVNode = {
@@ -26814,11 +27765,18 @@ const deleteCurrentParagraph = (evt) => {
26814
27765
  selectionState.clear();
26815
27766
  const psymbol = ElementUtil.getLastLeafElement(currentElement);
26816
27767
  const nextFocusableEle = ElementUtil.getRecursionNextSiblingElement(psymbol, false, true, viewOptions);
27768
+ const parentContainer = currentElement.parent;
26817
27769
  if (nextFocusableEle) {
26818
- selectionState.resetRange(nextFocusableEle, 0);
27770
+ if (nextFocusableEle.parent === parentContainer) {
27771
+ selectionState.resetRange(nextFocusableEle, 0);
27772
+ }
27773
+ else {
27774
+ selectionState.resetRange(parentContainer, 0);
27775
+ }
26819
27776
  }
26820
27777
  else {
26821
- selectionState.clear();
27778
+ selectionState.resetRange(parentContainer, 0);
27779
+ //selectionState.clear();
26822
27780
  }
26823
27781
  currentElement.remove();
26824
27782
  currentElement.destroy();