kordoc 1.7.0 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -254,7 +254,7 @@ function tableToMarkdown(table) {
254
254
  }
255
255
 
256
256
  // src/utils.ts
257
- var VERSION = true ? "1.7.0" : "0.0.0-dev";
257
+ var VERSION = true ? "1.7.2" : "0.0.0-dev";
258
258
  function toArrayBuffer(buf) {
259
259
  if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
260
260
  return buf.buffer;
@@ -1573,6 +1573,20 @@ function extractLines(fnArray, argsArray) {
1573
1573
  let currentPath = [];
1574
1574
  let pathStartX = 0, pathStartY = 0;
1575
1575
  let curX = 0, curY = 0;
1576
+ function pushRectangle(path, rx, ry, rw, rh) {
1577
+ if (Math.abs(rh) < ORIENTATION_TOL * 2) {
1578
+ path.push({ x1: rx, y1: ry + rh / 2, x2: rx + rw, y2: ry + rh / 2 });
1579
+ } else if (Math.abs(rw) < ORIENTATION_TOL * 2) {
1580
+ path.push({ x1: rx + rw / 2, y1: ry, x2: rx + rw / 2, y2: ry + rh });
1581
+ } else {
1582
+ path.push(
1583
+ { x1: rx, y1: ry, x2: rx + rw, y2: ry },
1584
+ { x1: rx + rw, y1: ry, x2: rx + rw, y2: ry + rh },
1585
+ { x1: rx + rw, y1: ry + rh, x2: rx, y2: ry + rh },
1586
+ { x1: rx, y1: ry + rh, x2: rx, y2: ry }
1587
+ );
1588
+ }
1589
+ }
1576
1590
  function flushPath(isStroke) {
1577
1591
  if (!isStroke) {
1578
1592
  currentPath = [];
@@ -1591,49 +1605,78 @@ function extractLines(fnArray, argsArray) {
1591
1605
  lineWidth = args[0] || 1;
1592
1606
  break;
1593
1607
  case OPS.constructPath: {
1594
- const subOps = args[0];
1595
- const coords = args[1];
1596
- let ci = 0;
1597
- for (const subOp of subOps) {
1598
- if (subOp === OPS.moveTo) {
1599
- curX = coords[ci++];
1600
- curY = coords[ci++];
1601
- pathStartX = curX;
1602
- pathStartY = curY;
1603
- } else if (subOp === OPS.lineTo) {
1604
- const x2 = coords[ci++], y2 = coords[ci++];
1605
- currentPath.push({ x1: curX, y1: curY, x2, y2 });
1606
- curX = x2;
1607
- curY = y2;
1608
- } else if (subOp === OPS.rectangle) {
1609
- const rx = coords[ci++], ry = coords[ci++];
1610
- const rw = coords[ci++], rh = coords[ci++];
1611
- if (Math.abs(rh) < ORIENTATION_TOL * 2) {
1612
- currentPath.push({ x1: rx, y1: ry + rh / 2, x2: rx + rw, y2: ry + rh / 2 });
1613
- } else if (Math.abs(rw) < ORIENTATION_TOL * 2) {
1614
- currentPath.push({ x1: rx + rw / 2, y1: ry, x2: rx + rw / 2, y2: ry + rh });
1615
- } else {
1616
- currentPath.push(
1617
- { x1: rx, y1: ry, x2: rx + rw, y2: ry },
1618
- // bottom
1619
- { x1: rx + rw, y1: ry, x2: rx + rw, y2: ry + rh },
1620
- // right
1621
- { x1: rx + rw, y1: ry + rh, x2: rx, y2: ry + rh },
1622
- // top
1623
- { x1: rx, y1: ry + rh, x2: rx, y2: ry }
1624
- // left
1625
- );
1608
+ const arg0 = args[0];
1609
+ if (Array.isArray(arg0)) {
1610
+ const subOps = arg0;
1611
+ const coords = args[1];
1612
+ let ci = 0;
1613
+ for (const subOp of subOps) {
1614
+ if (subOp === OPS.moveTo) {
1615
+ curX = coords[ci++];
1616
+ curY = coords[ci++];
1617
+ pathStartX = curX;
1618
+ pathStartY = curY;
1619
+ } else if (subOp === OPS.lineTo) {
1620
+ const x2 = coords[ci++], y2 = coords[ci++];
1621
+ currentPath.push({ x1: curX, y1: curY, x2, y2 });
1622
+ curX = x2;
1623
+ curY = y2;
1624
+ } else if (subOp === OPS.rectangle) {
1625
+ const rx = coords[ci++], ry = coords[ci++];
1626
+ const rw = coords[ci++], rh = coords[ci++];
1627
+ pushRectangle(currentPath, rx, ry, rw, rh);
1628
+ } else if (subOp === OPS.closePath) {
1629
+ if (curX !== pathStartX || curY !== pathStartY) {
1630
+ currentPath.push({ x1: curX, y1: curY, x2: pathStartX, y2: pathStartY });
1631
+ }
1632
+ curX = pathStartX;
1633
+ curY = pathStartY;
1634
+ } else if (subOp === OPS.curveTo) {
1635
+ ci += 6;
1636
+ } else if (subOp === OPS.curveTo2 || subOp === OPS.curveTo3) {
1637
+ ci += 4;
1626
1638
  }
1627
- } else if (subOp === OPS.closePath) {
1628
- if (curX !== pathStartX || curY !== pathStartY) {
1629
- currentPath.push({ x1: curX, y1: curY, x2: pathStartX, y2: pathStartY });
1639
+ }
1640
+ } else {
1641
+ const afterOp = arg0;
1642
+ const dataArr = args[1];
1643
+ const pathData = dataArr?.[0];
1644
+ if (pathData && typeof pathData === "object") {
1645
+ const len = Object.keys(pathData).length;
1646
+ let di = 0;
1647
+ while (di < len) {
1648
+ const drawOp = pathData[di++];
1649
+ if (drawOp === 0 /* moveTo */) {
1650
+ curX = pathData[di++];
1651
+ curY = pathData[di++];
1652
+ pathStartX = curX;
1653
+ pathStartY = curY;
1654
+ } else if (drawOp === 1 /* lineTo */) {
1655
+ const x2 = pathData[di++], y2 = pathData[di++];
1656
+ currentPath.push({ x1: curX, y1: curY, x2, y2 });
1657
+ curX = x2;
1658
+ curY = y2;
1659
+ } else if (drawOp === 2 /* curveTo */) {
1660
+ di += 6;
1661
+ } else if (drawOp === 3 /* quadraticCurveTo */) {
1662
+ di += 4;
1663
+ } else if (drawOp === 4 /* closePath */) {
1664
+ if (curX !== pathStartX || curY !== pathStartY) {
1665
+ currentPath.push({ x1: curX, y1: curY, x2: pathStartX, y2: pathStartY });
1666
+ }
1667
+ curX = pathStartX;
1668
+ curY = pathStartY;
1669
+ } else {
1670
+ break;
1671
+ }
1630
1672
  }
1631
- curX = pathStartX;
1632
- curY = pathStartY;
1633
- } else if (subOp === OPS.curveTo) {
1634
- ci += 6;
1635
- } else if (subOp === OPS.curveTo2 || subOp === OPS.curveTo3) {
1636
- ci += 4;
1673
+ }
1674
+ if (afterOp === OPS.stroke || afterOp === OPS.closeStroke) {
1675
+ flushPath(true);
1676
+ } else if (afterOp === OPS.fill || afterOp === OPS.eoFill || afterOp === OPS.fillStroke || afterOp === OPS.eoFillStroke || afterOp === OPS.closeFillStroke || afterOp === OPS.closeEOFillStroke) {
1677
+ flushPath(true);
1678
+ } else if (afterOp === OPS.endPath) {
1679
+ flushPath(false);
1637
1680
  }
1638
1681
  }
1639
1682
  break;