@oxyhq/core 10.1.0 → 10.1.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.
@@ -78,20 +78,23 @@ export declare function normalizeInlineText(value: string): string;
78
78
  * 2. Unify every line-break form (CRLF, lone CR, U+2028, U+2029) to `\n`.
79
79
  * 3. Collapse runs of HORIZONTAL whitespace (spaces, tabs, NBSP and friends)
80
80
  * to a single space. Line breaks are untouched.
81
- * 4. Strip the horizontal whitespace at the END of each line.
81
+ * 4. Strip the horizontal whitespace at BOTH ends of every line.
82
82
  * 5. Collapse three or more line breaks to exactly one blank line (`\n\n`).
83
- * 6. Trim both ends.
83
+ * 6. Trim both ends of the value.
84
84
  *
85
85
  * STEP 4 MUST PRECEDE STEP 5 — this is the whole point of the function. A
86
86
  * "blank" line that actually contains spaces (`"a\n \n \nb"`) breaks the
87
87
  * run of `\n` characters, so a bare `\n{3,}` collapse (step 5 alone) never sees
88
88
  * it and the extra blank lines survive into the UI. That is exactly the bug in
89
- * federated post bodies. Removing the trailing horizontal whitespace first
90
- * turns those lines into real, empty lines, which step 5 then collapses.
91
- *
92
- * A single space at the START of a line is preserved: only RUNS of horizontal
93
- * whitespace collapse, and an indent is not trailing whitespace, so a one-space
94
- * indent is treated as the author's and left alone.
89
+ * federated post bodies. Trimming each line first turns those lines into real,
90
+ * empty lines, which step 5 then collapses.
91
+ *
92
+ * Every line is trimmed on BOTH sides, so a leading indent is removed outright
93
+ * rather than reduced to one space. Step 3 has already destroyed whatever indent
94
+ * the author wrote (`" Mundo"` `" Mundo"`), so a surviving space would not
95
+ * be the author's intent — it would be an arbitrary remnant of exactly the
96
+ * source-markup indentation this function exists to erase, and `pre-wrap` renders
97
+ * it. Indentation is invisible in HTML by spec; it must be invisible here too.
95
98
  *
96
99
  * A value that is empty or whitespace-only returns `''`.
97
100
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/core",
3
- "version": "10.1.0",
3
+ "version": "10.1.2",
4
4
  "description": "OxyHQ SDK Foundation — API client, authentication, cryptographic identity, and shared utilities",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -94,8 +94,8 @@
94
94
  }
95
95
  },
96
96
  "dependencies": {
97
- "@oxyhq/contracts": "workspace:^",
98
- "@oxyhq/protocol": "workspace:^",
97
+ "@oxyhq/contracts": "^0.14.0",
98
+ "@oxyhq/protocol": "^0.1.5",
99
99
  "bip39": "^3.1.0",
100
100
  "buffer": "^6.0.3",
101
101
  "elliptic": "^6.6.1",
@@ -124,8 +124,16 @@ describe('normalizeMultilineText', () => {
124
124
  );
125
125
  });
126
126
 
127
- it('preserves a single-space indent (it is the author\'s, not markup noise)', () => {
128
- expect(normalizeMultilineText('a\n b')).toBe('a\n b');
127
+ it('strips leading horizontal whitespace from every line', () => {
128
+ expect(normalizeMultilineText('a\n b')).toBe('a\nb');
129
+ expect(normalizeMultilineText('one\n\ttwo\n three')).toBe('one\ntwo\nthree');
130
+ });
131
+
132
+ it('leaves no indent residue after a space-filled blank line', () => {
133
+ // The blank line collapses AND the six-space indent goes away entirely —
134
+ // collapsing it to a single space would leave a visible artifact under
135
+ // `white-space: pre-wrap`.
136
+ expect(normalizeMultilineText('Hola\n \n\n Mundo')).toBe('Hola\n\nMundo');
129
137
  });
130
138
 
131
139
  it('normalizes CRLF and lone CR to \\n', () => {
@@ -176,6 +184,7 @@ describe('normalizeMultilineText', () => {
176
184
  'First paragraph.\n\nSecond paragraph.',
177
185
  `a${NBSP}b`,
178
186
  'a\n b',
187
+ 'Hola\n \n\n Mundo',
179
188
  '',
180
189
  ' ',
181
190
  `Caf${DECOMPOSED_E_ACUTE}`,
@@ -61,12 +61,11 @@ const INLINE_NEEDS_NORMALIZATION = /[^\x20-\x7E]|^ | $| {2}/;
61
61
  /**
62
62
  * Same idea as {@link INLINE_NEEDS_NORMALIZATION}, for MULTILINE values: `\n`
63
63
  * joins the printable-ASCII fast-path alphabet, and the additional shapes a
64
- * normalized body can never contain are a space before a line break (trailing
65
- * horizontal whitespace) and a run of three line breaks (more than one blank
66
- * line). A single space AFTER a line break is legal — a one-space indent is
67
- * the author's, and normalization deliberately preserves it.
64
+ * normalized body can never contain are a space adjacent to a line break — on
65
+ * either side, since every line is trimmed — and a run of three line breaks
66
+ * (more than one blank line).
68
67
  */
69
- const MULTILINE_NEEDS_NORMALIZATION = /[^\x20-\x7E\n]|^[ \n]|[ \n]$| {2}| \n|\n{3}/;
68
+ const MULTILINE_NEEDS_NORMALIZATION = /[^\x20-\x7E\n]|^[ \n]|[ \n]$| {2}| \n|\n |\n{3}/;
70
69
 
71
70
  /** Any run of whitespace, including tabs, line breaks and Unicode spaces. */
72
71
  const ANY_WHITESPACE_RUN = /\s+/g;
@@ -92,9 +91,20 @@ const LINE_BREAK_FORMS = /\r\n|\r|\p{Zl}|\p{Zp}/gu;
92
91
  */
93
92
  const HORIZONTAL_WHITESPACE_RUN = /[^\S\n]+/g;
94
93
 
95
- /** Horizontal whitespace at the end of a line — the blank-line spoiler. */
94
+ /**
95
+ * Horizontal whitespace at the END of a line — the blank-line spoiler: it is
96
+ * what makes an "empty" line non-empty and hides it from {@link EXCESS_BLANK_LINES}.
97
+ */
96
98
  const TRAILING_HORIZONTAL_WHITESPACE = / +\n/g;
97
99
 
100
+ /**
101
+ * Horizontal whitespace at the START of a line: source-markup indentation. HTML
102
+ * collapses it by spec, so it is invisible where the text came from and carries
103
+ * no meaning — it only becomes visible once a client renders the value with
104
+ * `white-space: pre-wrap`.
105
+ */
106
+ const LEADING_HORIZONTAL_WHITESPACE = /\n +/g;
107
+
98
108
  /** Three or more line breaks: more than one blank line between paragraphs. */
99
109
  const EXCESS_BLANK_LINES = /\n{3,}/g;
100
110
 
@@ -140,20 +150,23 @@ export function normalizeInlineText(value: string): string {
140
150
  * 2. Unify every line-break form (CRLF, lone CR, U+2028, U+2029) to `\n`.
141
151
  * 3. Collapse runs of HORIZONTAL whitespace (spaces, tabs, NBSP and friends)
142
152
  * to a single space. Line breaks are untouched.
143
- * 4. Strip the horizontal whitespace at the END of each line.
153
+ * 4. Strip the horizontal whitespace at BOTH ends of every line.
144
154
  * 5. Collapse three or more line breaks to exactly one blank line (`\n\n`).
145
- * 6. Trim both ends.
155
+ * 6. Trim both ends of the value.
146
156
  *
147
157
  * STEP 4 MUST PRECEDE STEP 5 — this is the whole point of the function. A
148
158
  * "blank" line that actually contains spaces (`"a\n \n \nb"`) breaks the
149
159
  * run of `\n` characters, so a bare `\n{3,}` collapse (step 5 alone) never sees
150
160
  * it and the extra blank lines survive into the UI. That is exactly the bug in
151
- * federated post bodies. Removing the trailing horizontal whitespace first
152
- * turns those lines into real, empty lines, which step 5 then collapses.
161
+ * federated post bodies. Trimming each line first turns those lines into real,
162
+ * empty lines, which step 5 then collapses.
153
163
  *
154
- * A single space at the START of a line is preserved: only RUNS of horizontal
155
- * whitespace collapse, and an indent is not trailing whitespace, so a one-space
156
- * indent is treated as the author's and left alone.
164
+ * Every line is trimmed on BOTH sides, so a leading indent is removed outright
165
+ * rather than reduced to one space. Step 3 has already destroyed whatever indent
166
+ * the author wrote (`" Mundo"` `" Mundo"`), so a surviving space would not
167
+ * be the author's intent — it would be an arbitrary remnant of exactly the
168
+ * source-markup indentation this function exists to erase, and `pre-wrap` renders
169
+ * it. Indentation is invisible in HTML by spec; it must be invisible here too.
157
170
  *
158
171
  * A value that is empty or whitespace-only returns `''`.
159
172
  *
@@ -168,6 +181,7 @@ export function normalizeMultilineText(value: string): string {
168
181
  .replace(LINE_BREAK_FORMS, '\n')
169
182
  .replace(HORIZONTAL_WHITESPACE_RUN, ' ')
170
183
  .replace(TRAILING_HORIZONTAL_WHITESPACE, '\n')
184
+ .replace(LEADING_HORIZONTAL_WHITESPACE, '\n')
171
185
  .replace(EXCESS_BLANK_LINES, '\n\n')
172
186
  .trim();
173
187
  }