@blankdotpage/cake 0.1.44 → 0.1.45

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.
@@ -1 +1 @@
1
- {"version":3,"file":"word-break.d.ts","sourceRoot":"","sources":["../../../src/cake/shared/word-break.ts"],"names":[],"mappings":"AAqCA;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CA8BhC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAkBhC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA8ClE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA8DlE"}
1
+ {"version":3,"file":"word-break.d.ts","sourceRoot":"","sources":["../../../src/cake/shared/word-break.ts"],"names":[],"mappings":"AAuCA;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CA8BhC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CA0EhC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA8ClE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA8DlE"}
@@ -1,4 +1,5 @@
1
1
  import { wordSegments } from "./segmenter";
2
+ const ZERO_WIDTH_PLACEHOLDER = "\u200B";
2
3
  function getWordSegments(text) {
3
4
  return wordSegments(text).map((seg) => ({
4
5
  segment: seg.segment,
@@ -63,6 +64,51 @@ export function getWordBoundaries(text, offset) {
63
64
  return { start: 0, end: 0 };
64
65
  }
65
66
  const clampedOffset = Math.max(0, Math.min(offset, maxLength));
67
+ // Zero-width placeholders are internal formatting artifacts used for
68
+ // pending mark state and should not split a "word" for double-click.
69
+ if (text.includes(ZERO_WIDTH_PLACEHOLDER)) {
70
+ const nonPlaceholderPrefixCounts = new Array(text.length + 1).fill(0);
71
+ let compactText = "";
72
+ let compactCount = 0;
73
+ for (let i = 0; i < text.length; i += 1) {
74
+ const char = text[i] ?? "";
75
+ if (char !== ZERO_WIDTH_PLACEHOLDER) {
76
+ compactText += char;
77
+ compactCount += 1;
78
+ }
79
+ nonPlaceholderPrefixCounts[i + 1] = compactCount;
80
+ }
81
+ if (compactText.length === 0) {
82
+ return { start: 0, end: 0 };
83
+ }
84
+ const compactOffset = nonPlaceholderPrefixCounts[clampedOffset] ?? 0;
85
+ let adjustedCompactOffset = compactOffset;
86
+ if (adjustedCompactOffset >= compactText.length) {
87
+ adjustedCompactOffset = compactText.length - 1;
88
+ }
89
+ const compactChar = compactText[adjustedCompactOffset] ?? "";
90
+ if (compactChar === "\n" && adjustedCompactOffset > 0) {
91
+ adjustedCompactOffset = adjustedCompactOffset - 1;
92
+ }
93
+ const compactBounds = getWordBoundariesAt(compactText, adjustedCompactOffset);
94
+ const compactStart = compactBounds.start;
95
+ const compactEnd = compactBounds.end;
96
+ let rawStart = 0;
97
+ for (let i = 0; i < nonPlaceholderPrefixCounts.length; i += 1) {
98
+ if ((nonPlaceholderPrefixCounts[i] ?? 0) >= compactStart) {
99
+ rawStart = i;
100
+ break;
101
+ }
102
+ }
103
+ let rawEnd = text.length;
104
+ for (let i = rawStart; i < nonPlaceholderPrefixCounts.length; i += 1) {
105
+ if ((nonPlaceholderPrefixCounts[i] ?? 0) >= compactEnd) {
106
+ rawEnd = i;
107
+ break;
108
+ }
109
+ }
110
+ return { start: rawStart, end: rawEnd };
111
+ }
66
112
  let adjustedOffset = clampedOffset;
67
113
  if (adjustedOffset >= maxLength) {
68
114
  adjustedOffset = maxLength - 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blankdotpage/cake",
3
- "version": "0.1.44",
3
+ "version": "0.1.45",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",