@sushichan044/kg-core 0.6.4 → 0.6.5

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/README.md CHANGED
@@ -65,7 +65,10 @@ the paragraph end.
65
65
  The composer classifies the core prose classes from JLReq, resolves pair spacing,
66
66
  and selects line breaks over the whole source paragraph. It prefers natural setting,
67
67
  then shrinking punctuation space, hanging a comma or full stop, stretching eligible
68
- space, and finally a forced emergency line. It owns Japanese line-start and line-end
68
+ space, and finally a forced emergency line. The half em that follows a closing
69
+ bracket, comma, or full stop is invisible once that character lands at the line end,
70
+ so it is the first space spent and it costs the paragraph nothing, which keeps a
71
+ line-start bracket at its full em. It owns Japanese line-start and line-end
69
72
  restrictions, inseparable punctuation, question/exclamation gap suppression, and
70
73
  ruby placement.
71
74
 
package/dist/index.mjs CHANGED
@@ -1485,7 +1485,7 @@ const defaultJapaneseTypesettingProfile = {
1485
1485
  kind: "glue",
1486
1486
  naturalWidthEm: .5,
1487
1487
  shrink: {
1488
- priority: 2,
1488
+ priority: 0,
1489
1489
  amountEm: .5
1490
1490
  }
1491
1491
  } : null,
@@ -1495,6 +1495,10 @@ const defaultJapaneseTypesettingProfile = {
1495
1495
  //#endregion
1496
1496
  //#region src/composer/internal/paragraph-layout.ts
1497
1497
  const EPSILON = 1e-9;
1498
+ /**
1499
+ * Spending capacity at this priority changes nothing the reader can see.
1500
+ */
1501
+ const FREE_SHRINK_PRIORITY = 0;
1498
1502
  function skipSourceGaps(atoms, start) {
1499
1503
  let cursor = start;
1500
1504
  while (atoms[cursor]?.sourceGap === true) cursor += 1;
@@ -1571,6 +1575,7 @@ function candidate(atoms, classes, start, end, lineLengthEm, profile) {
1571
1575
  const naturalSizeEm = atoms.slice(contentStart, end).reduce((total, atom) => total + atom.boxAdvanceEm, 0) + pairValues.reduce((total, value) => total + value.spacing.naturalWidthEm, 0);
1572
1576
  const terminal = skipSourceGaps(atoms, end) === atoms.length;
1573
1577
  const shrinkCapacity = capacity(pairValues, ({ shrink }) => shrink);
1578
+ const freeShrinkCapacity = capacity(pairValues, ({ shrink }) => shrink?.priority === FREE_SHRINK_PRIORITY ? shrink : void 0);
1574
1579
  const stretchCapacity = capacity(pairValues, ({ stretch }) => stretch);
1575
1580
  const overflow = naturalSizeEm - lineLengthEm;
1576
1581
  const underflow = lineLengthEm - naturalSizeEm;
@@ -1604,6 +1609,8 @@ function candidate(atoms, classes, start, end, lineLengthEm, profile) {
1604
1609
  };
1605
1610
  if (overflow > 0 && overflow <= shrinkCapacity + EPSILON) {
1606
1611
  const resolved = resolveSpacings(pairValues, "shrink", overflow);
1612
+ const chargeableCapacity = shrinkCapacity - freeShrinkCapacity;
1613
+ const chargeableShrink = Math.max(0, overflow - freeShrinkCapacity);
1607
1614
  return {
1608
1615
  start,
1609
1616
  contentStart,
@@ -1613,7 +1620,7 @@ function candidate(atoms, classes, start, end, lineLengthEm, profile) {
1613
1620
  inlineSizeEm: lineLengthEm,
1614
1621
  break: { kind: "shrunk" },
1615
1622
  hangingIndex: null,
1616
- deformationRatio: shrinkCapacity === 0 ? 0 : overflow / shrinkCapacity,
1623
+ deformationRatio: chargeableCapacity <= EPSILON ? 0 : chargeableShrink / chargeableCapacity,
1617
1624
  priorityCost: resolved.priorityCost
1618
1625
  };
1619
1626
  }
@@ -1665,7 +1672,7 @@ function scoreFor(line, previousFitness) {
1665
1672
  forced: mode === "forced" ? 1 : 0,
1666
1673
  stretched: mode === "stretched" ? 1 : 0,
1667
1674
  hanging: mode === "hanging" ? 1 : 0,
1668
- shrunk: mode === "shrunk" ? 1 : 0
1675
+ shrunk: mode === "shrunk" && line.priorityCost > EPSILON ? 1 : 0
1669
1676
  };
1670
1677
  return {
1671
1678
  score: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sushichan044/kg-core",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "Framework-independent parsing, composition, and proofreading for Japanese manuscripts",
5
5
  "keywords": [
6
6
  "japanese",