@transferwise/components 46.155.0 → 46.156.0

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.
Files changed (235) hide show
  1. package/build/AvatarLayout/AvatarLayout.js.map +1 -1
  2. package/build/AvatarLayout/AvatarLayout.mjs.map +1 -1
  3. package/build/AvatarView/AvatarView.js.map +1 -1
  4. package/build/AvatarView/AvatarView.mjs.map +1 -1
  5. package/build/AvatarView/Dot/Dot.js.map +1 -1
  6. package/build/AvatarView/Dot/Dot.mjs.map +1 -1
  7. package/build/Body/Body.js.map +1 -1
  8. package/build/Body/Body.mjs.map +1 -1
  9. package/build/Chips/Chip/Chip.js.map +1 -1
  10. package/build/Chips/Chip/Chip.mjs.map +1 -1
  11. package/build/DefinitionList/DefinitionList.js +2 -1
  12. package/build/DefinitionList/DefinitionList.js.map +1 -1
  13. package/build/DefinitionList/DefinitionList.mjs +2 -1
  14. package/build/DefinitionList/DefinitionList.mjs.map +1 -1
  15. package/build/Display/Display.js.map +1 -1
  16. package/build/Display/Display.mjs.map +1 -1
  17. package/build/ExpressiveMoneyInput/AmountInput/AmountInput.js +2 -2
  18. package/build/ExpressiveMoneyInput/AmountInput/AmountInput.js.map +1 -1
  19. package/build/ExpressiveMoneyInput/AmountInput/AmountInput.mjs +1 -1
  20. package/build/ExpressiveMoneyInput/AmountInput/AmountInput.mjs.map +1 -1
  21. package/build/ExpressiveMoneyInput/AnimatedNumber/AnimatedNumber.js +4 -4
  22. package/build/ExpressiveMoneyInput/AnimatedNumber/AnimatedNumber.js.map +1 -1
  23. package/build/ExpressiveMoneyInput/AnimatedNumber/AnimatedNumber.mjs +1 -1
  24. package/build/ExpressiveMoneyInput/AnimatedNumber/AnimatedNumber.mjs.map +1 -1
  25. package/build/ExpressiveMoneyInput/Chevron/Chevron.js +2 -2
  26. package/build/ExpressiveMoneyInput/Chevron/Chevron.js.map +1 -1
  27. package/build/ExpressiveMoneyInput/Chevron/Chevron.mjs +1 -1
  28. package/build/ExpressiveMoneyInput/Chevron/Chevron.mjs.map +1 -1
  29. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.js.map +1 -1
  30. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.mjs.map +1 -1
  31. package/build/ExpressiveMoneyInput/ExpressiveMoneyInput.js +3 -3
  32. package/build/ExpressiveMoneyInput/ExpressiveMoneyInput.js.map +1 -1
  33. package/build/ExpressiveMoneyInput/ExpressiveMoneyInput.mjs +1 -1
  34. package/build/ExpressiveMoneyInput/ExpressiveMoneyInput.mjs.map +1 -1
  35. package/build/ExpressiveMoneyInput/hooks/useInputStyle.js.map +1 -1
  36. package/build/ExpressiveMoneyInput/hooks/useInputStyle.mjs.map +1 -1
  37. package/build/IconButton/IconButton.js.map +1 -1
  38. package/build/IconButton/IconButton.mjs.map +1 -1
  39. package/build/Link/Link.js.map +1 -1
  40. package/build/Link/Link.mjs.map +1 -1
  41. package/build/Markup/Markup.js +138 -0
  42. package/build/Markup/Markup.js.map +1 -0
  43. package/build/Markup/Markup.mjs +133 -0
  44. package/build/Markup/Markup.mjs.map +1 -0
  45. package/build/Markup/constants.js +21 -0
  46. package/build/Markup/constants.js.map +1 -0
  47. package/build/Markup/constants.mjs +15 -0
  48. package/build/Markup/constants.mjs.map +1 -0
  49. package/build/Markup/utils/parseMarkup.js +263 -0
  50. package/build/Markup/utils/parseMarkup.js.map +1 -0
  51. package/build/Markup/utils/parseMarkup.mjs +258 -0
  52. package/build/Markup/utils/parseMarkup.mjs.map +1 -0
  53. package/build/Markup/utils/sanitise.js +111 -0
  54. package/build/Markup/utils/sanitise.js.map +1 -0
  55. package/build/Markup/utils/sanitise.mjs +108 -0
  56. package/build/Markup/utils/sanitise.mjs.map +1 -0
  57. package/build/Nudge/Nudge.js +11 -2
  58. package/build/Nudge/Nudge.js.map +1 -1
  59. package/build/Nudge/Nudge.mjs +12 -3
  60. package/build/Nudge/Nudge.mjs.map +1 -1
  61. package/build/Sticky/Sticky.js +1 -0
  62. package/build/Sticky/Sticky.js.map +1 -1
  63. package/build/Sticky/Sticky.mjs +1 -0
  64. package/build/Sticky/Sticky.mjs.map +1 -1
  65. package/build/Title/Title.js +1 -0
  66. package/build/Title/Title.js.map +1 -1
  67. package/build/Title/Title.mjs +1 -0
  68. package/build/Title/Title.mjs.map +1 -1
  69. package/build/_deprecated/Select/Option/Option.js.map +1 -1
  70. package/build/_deprecated/Select/Option/Option.mjs.map +1 -1
  71. package/build/_deprecated/Select/SearchBox/SearchBox.js.map +1 -1
  72. package/build/_deprecated/Select/SearchBox/SearchBox.mjs.map +1 -1
  73. package/build/common/Circle/Circle.js.map +1 -1
  74. package/build/common/Circle/Circle.mjs.map +1 -1
  75. package/build/i18n/hu.json +1 -1
  76. package/build/i18n/hu.json.js +1 -1
  77. package/build/i18n/hu.json.mjs +1 -1
  78. package/build/index.js +2 -0
  79. package/build/index.js.map +1 -1
  80. package/build/index.mjs +1 -0
  81. package/build/index.mjs.map +1 -1
  82. package/build/main.css +71 -1
  83. package/build/styles/DefinitionList/DefinitionList.css +30 -0
  84. package/build/styles/Markup/Markup.css +28 -0
  85. package/build/styles/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  86. package/build/styles/Nudge/Nudge.css +1 -1
  87. package/build/styles/Sticky/Sticky.css +4 -0
  88. package/build/styles/main.css +71 -1
  89. package/build/types/AvatarLayout/AvatarLayout.d.ts +2 -2
  90. package/build/types/AvatarLayout/AvatarLayout.d.ts.map +1 -1
  91. package/build/types/AvatarLayout/index.d.ts +1 -1
  92. package/build/types/AvatarLayout/index.d.ts.map +1 -1
  93. package/build/types/AvatarView/AvatarView.d.ts +2 -2
  94. package/build/types/AvatarView/AvatarView.d.ts.map +1 -1
  95. package/build/types/AvatarView/Dot/Dot.d.ts +1 -1
  96. package/build/types/AvatarView/Dot/Dot.d.ts.map +1 -1
  97. package/build/types/AvatarView/index.d.ts +1 -1
  98. package/build/types/AvatarView/index.d.ts.map +1 -1
  99. package/build/types/Body/Body.d.ts +13 -2
  100. package/build/types/Body/Body.d.ts.map +1 -1
  101. package/build/types/Body/index.d.ts +1 -0
  102. package/build/types/Body/index.d.ts.map +1 -1
  103. package/build/types/Chips/Chip/Chip.d.ts +2 -2
  104. package/build/types/Chips/Chip/Chip.d.ts.map +1 -1
  105. package/build/types/Chips/index.d.ts +1 -1
  106. package/build/types/Chips/index.d.ts.map +1 -1
  107. package/build/types/DefinitionList/DefinitionList.d.ts.map +1 -1
  108. package/build/types/Display/Display.d.ts +2 -2
  109. package/build/types/Display/Display.d.ts.map +1 -1
  110. package/build/types/Display/index.d.ts +1 -0
  111. package/build/types/Display/index.d.ts.map +1 -1
  112. package/build/types/ExpressiveMoneyInput/AmountInput/AmountInput.d.ts +3 -3
  113. package/build/types/ExpressiveMoneyInput/AmountInput/AmountInput.d.ts.map +1 -1
  114. package/build/types/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.d.ts +3 -3
  115. package/build/types/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.d.ts.map +1 -1
  116. package/build/types/ExpressiveMoneyInput/ExpressiveMoneyInput.d.ts +4 -4
  117. package/build/types/ExpressiveMoneyInput/ExpressiveMoneyInput.d.ts.map +1 -1
  118. package/build/types/ExpressiveMoneyInput/hooks/useInputStyle.d.ts +1 -1
  119. package/build/types/ExpressiveMoneyInput/hooks/useInputStyle.d.ts.map +1 -1
  120. package/build/types/ExpressiveMoneyInput/index.d.ts +1 -1
  121. package/build/types/ExpressiveMoneyInput/index.d.ts.map +1 -1
  122. package/build/types/IconButton/IconButton.d.ts +2 -2
  123. package/build/types/IconButton/IconButton.d.ts.map +1 -1
  124. package/build/types/IconButton/index.d.ts +1 -1
  125. package/build/types/IconButton/index.d.ts.map +1 -1
  126. package/build/types/Link/Link.d.ts +2 -2
  127. package/build/types/Link/Link.d.ts.map +1 -1
  128. package/build/types/Link/index.d.ts +1 -1
  129. package/build/types/Link/index.d.ts.map +1 -1
  130. package/build/types/Markup/Markup.d.ts +18 -0
  131. package/build/types/Markup/Markup.d.ts.map +1 -0
  132. package/build/types/Markup/Markup.types.d.ts +77 -0
  133. package/build/types/Markup/Markup.types.d.ts.map +1 -0
  134. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts +12 -0
  135. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts.map +1 -0
  136. package/build/types/Markup/constants.d.ts +6 -0
  137. package/build/types/Markup/constants.d.ts.map +1 -0
  138. package/build/types/Markup/index.d.ts +3 -0
  139. package/build/types/Markup/index.d.ts.map +1 -0
  140. package/build/types/Markup/utils/parseMarkup.d.ts +8 -0
  141. package/build/types/Markup/utils/parseMarkup.d.ts.map +1 -0
  142. package/build/types/Markup/utils/sanitise.d.ts +4 -0
  143. package/build/types/Markup/utils/sanitise.d.ts.map +1 -0
  144. package/build/types/MoneyInput/MoneyInput.d.ts +1 -1
  145. package/build/types/MoneyInput/MoneyInput.d.ts.map +1 -1
  146. package/build/types/Nudge/Nudge.d.ts +28 -5
  147. package/build/types/Nudge/Nudge.d.ts.map +1 -1
  148. package/build/types/Nudge/index.d.ts +1 -1
  149. package/build/types/Nudge/index.d.ts.map +1 -1
  150. package/build/types/Sticky/Sticky.d.ts.map +1 -1
  151. package/build/types/Title/Title.d.ts +13 -3
  152. package/build/types/Title/Title.d.ts.map +1 -1
  153. package/build/types/Title/index.d.ts +1 -0
  154. package/build/types/Title/index.d.ts.map +1 -1
  155. package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
  156. package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
  157. package/build/types/_deprecated/Select/Option/Option.d.ts +2 -2
  158. package/build/types/_deprecated/Select/Option/Option.d.ts.map +1 -1
  159. package/build/types/common/Circle/Circle.d.ts +1 -1
  160. package/build/types/common/Circle/Circle.d.ts.map +1 -1
  161. package/build/types/common/Circle/index.d.ts +1 -1
  162. package/build/types/common/Circle/index.d.ts.map +1 -1
  163. package/build/types/index.d.ts +6 -0
  164. package/build/types/index.d.ts.map +1 -1
  165. package/package.json +3 -3
  166. package/src/AvatarLayout/AvatarLayout.tsx +3 -3
  167. package/src/AvatarLayout/index.ts +1 -1
  168. package/src/AvatarView/AvatarView.tsx +4 -4
  169. package/src/AvatarView/Dot/Dot.tsx +1 -1
  170. package/src/AvatarView/index.ts +1 -1
  171. package/src/Body/Body.tsx +2 -2
  172. package/src/Body/index.ts +1 -0
  173. package/src/Chips/Chip/Chip.tsx +2 -2
  174. package/src/Chips/index.ts +1 -1
  175. package/src/DefinitionList/DefinitionList.css +30 -0
  176. package/src/DefinitionList/DefinitionList.less +24 -0
  177. package/src/DefinitionList/DefinitionList.tsx +1 -0
  178. package/src/DefinitionList/_stories/DefinitionList.test.story.tsx +168 -0
  179. package/src/Display/Display.tsx +2 -2
  180. package/src/Display/index.ts +1 -0
  181. package/src/Drawer/Drawer.test.tsx +2 -3
  182. package/src/ExpressiveMoneyInput/AmountInput/AmountInput.tsx +4 -4
  183. package/src/ExpressiveMoneyInput/AnimatedNumber/AnimatedNumber.tsx +1 -1
  184. package/src/ExpressiveMoneyInput/Chevron/Chevron.tsx +1 -1
  185. package/src/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.tsx +3 -3
  186. package/src/ExpressiveMoneyInput/ExpressiveMoneyInput.test.tsx +1 -1
  187. package/src/ExpressiveMoneyInput/ExpressiveMoneyInput.tsx +5 -8
  188. package/src/ExpressiveMoneyInput/_stories/ExpressiveMoneyInput.story.tsx +1 -1
  189. package/src/ExpressiveMoneyInput/_stories/ExpressiveMoneyInput.test.story.tsx +1 -1
  190. package/src/ExpressiveMoneyInput/hooks/useInputStyle.ts +1 -1
  191. package/src/ExpressiveMoneyInput/index.ts +1 -1
  192. package/src/IconButton/IconButton.tsx +2 -2
  193. package/src/IconButton/_stories/IconButton.story.tsx +8 -8
  194. package/src/IconButton/index.ts +1 -1
  195. package/src/Link/Link.tsx +2 -2
  196. package/src/Link/index.ts +1 -1
  197. package/src/Markup/Markup.css +28 -0
  198. package/src/Markup/Markup.injection.test.tsx +163 -0
  199. package/src/Markup/Markup.less +29 -0
  200. package/src/Markup/Markup.test.tsx +502 -0
  201. package/src/Markup/Markup.tsx +175 -0
  202. package/src/Markup/Markup.types.ts +62 -0
  203. package/src/Markup/_stories/Markup.docs.mdx +75 -0
  204. package/src/Markup/_stories/Markup.security.docs.mdx +343 -0
  205. package/src/Markup/_stories/Markup.story.tsx +266 -0
  206. package/src/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  207. package/src/Markup/_stories/Vulnerability/Vulnerability.tsx +30 -0
  208. package/src/Markup/constants.ts +23 -0
  209. package/src/Markup/index.ts +2 -0
  210. package/src/Markup/utils/parseMarkup.test.ts +706 -0
  211. package/src/Markup/utils/parseMarkup.ts +265 -0
  212. package/src/Markup/utils/sanitise.test.ts +499 -0
  213. package/src/Markup/utils/sanitise.ts +129 -0
  214. package/src/Nudge/Nudge.css +1 -1
  215. package/src/Nudge/Nudge.less +1 -1
  216. package/src/Nudge/Nudge.test.tsx +43 -0
  217. package/src/Nudge/Nudge.tsx +43 -8
  218. package/src/Nudge/index.ts +1 -1
  219. package/src/Sticky/Sticky.css +4 -0
  220. package/src/Sticky/Sticky.less +6 -0
  221. package/src/Sticky/Sticky.test.tsx +1 -0
  222. package/src/Sticky/Sticky.tsx +1 -0
  223. package/src/Sticky/_stories/Sticky.test.story.tsx +177 -0
  224. package/src/Title/Title.tsx +25 -20
  225. package/src/Title/index.ts +1 -0
  226. package/src/_deprecated/LegacyListItem/_stories/LegacyListItem.story.tsx +2 -3
  227. package/src/_deprecated/Select/Option/Option.test.tsx +1 -1
  228. package/src/_deprecated/Select/Option/Option.tsx +2 -2
  229. package/src/_deprecated/Select/SearchBox/SearchBox.tsx +2 -2
  230. package/src/common/Circle/Circle.tsx +2 -2
  231. package/src/common/Circle/index.ts +1 -1
  232. package/src/i18n/hu.json +1 -1
  233. package/src/index.ts +6 -0
  234. package/src/main.css +71 -1
  235. package/src/main.less +2 -0
@@ -0,0 +1,265 @@
1
+ import { ALLOWED_TAGS, ALLOWED_TARGETS, MAX_NESTING_DEPTH, TAG_ALIASES } from '../constants';
2
+ import { MarkupNode } from '../Markup.types';
3
+
4
+ export { MAX_NESTING_DEPTH };
5
+ export const MAX_INPUT_LENGTH = 10_000;
6
+ export const MAX_ACCESSIBILITY_LABEL_LENGTH = 250;
7
+
8
+ const OBJECT_PROTOTYPE_KEYS = new Set(Object.getOwnPropertyNames(Object.prototype));
9
+
10
+ // eslint-disable-next-line regexp/no-control-character
11
+ const CONTROL_CHARS = /[\x00-\x1f\x7f-\x9f]/g;
12
+ const HTML_METACHAR = /[<>"']/g;
13
+
14
+ /**
15
+ * Matches opening and closing tags from the ALLOWED_TAGS allow-list.
16
+ *
17
+ * Capture groups:
18
+ * 1. `/` if this is a closing tag, undefined otherwise
19
+ * 2. Tag name
20
+ * 3. Raw attribute string between the tag name and `>` (empty for closing tags)
21
+ *
22
+ * The lookahead `(?=[\s>/])` after the tag name ensures we don't match partial
23
+ * words — e.g. `<stronger>` won't be matched as `<strong>`.
24
+ *
25
+ * Global flag (`g`) allows iterative matching via `exec()`.
26
+ */
27
+ const TAG_REGEX = new RegExp(
28
+ `<(\\/)?(${ALLOWED_TAGS.join('|')})(?=[\\s>/])((?:[^>"']*(?:"[^"]*"|'[^']*'))*[^>"']*)>`,
29
+ 'g',
30
+ );
31
+
32
+ type Token =
33
+ | { type: 'text'; content: string }
34
+ | { type: 'newline' }
35
+ | { type: 'open'; tag: string; attrs: string }
36
+ | { type: 'close'; tag: string };
37
+
38
+ /**
39
+ * Splits the input string into a flat list of tokens by scanning for known tags.
40
+ * Text between tags is emitted as text/newline tokens. Unrecognised tags are never
41
+ * tokenised — they remain part of the surrounding text content.
42
+ */
43
+ function tokenise(input: string): Token[] {
44
+ const tokens: Token[] = [];
45
+ let lastIndex = 0;
46
+
47
+ TAG_REGEX.lastIndex = 0;
48
+ let match = TAG_REGEX.exec(input);
49
+
50
+ while (match !== null) {
51
+ if (match.index > lastIndex) {
52
+ pushTextWithNewlines(tokens, input.slice(lastIndex, match.index));
53
+ }
54
+
55
+ const isClose = match[1] === '/';
56
+ const tag = match[2];
57
+ const attrs = match[3] || '';
58
+
59
+ if (isClose) {
60
+ tokens.push({ type: 'close', tag });
61
+ } else {
62
+ tokens.push({ type: 'open', tag, attrs });
63
+ }
64
+
65
+ lastIndex = TAG_REGEX.lastIndex;
66
+ match = TAG_REGEX.exec(input);
67
+ }
68
+
69
+ if (lastIndex < input.length) {
70
+ pushTextWithNewlines(tokens, input.slice(lastIndex));
71
+ }
72
+
73
+ return tokens;
74
+ }
75
+
76
+ /** Splits a text fragment on newline characters, interleaving newline tokens between parts. */
77
+ function pushTextWithNewlines(tokens: Token[], text: string): void {
78
+ const parts = text.split('\n');
79
+ for (let index = 0; index < parts.length; index += 1) {
80
+ if (index > 0) {
81
+ tokens.push({ type: 'newline' });
82
+ }
83
+ if (parts[index]) {
84
+ tokens.push({ type: 'text', content: parts[index] });
85
+ }
86
+ }
87
+ }
88
+
89
+ type ParseResult = { closed: true; nodes: MarkupNode[] } | { closed: false; nodes: MarkupNode[] };
90
+
91
+ /**
92
+ * Recursive descent parser that consumes tokens and builds a MarkupNode tree.
93
+ *
94
+ * When `untilTag` is provided, the function collects nodes until it finds a matching
95
+ * close token — returning `{ closed: true }`. If it exhausts all tokens without finding
96
+ * the close, it returns `{ closed: false }` so the caller can fall back to plain text
97
+ * (graceful degradation for malformed input).
98
+ *
99
+ * The shared `position` object acts as a cursor across recursive calls, avoiding the
100
+ * need to slice or copy the token array.
101
+ */
102
+ function parse(
103
+ tokens: Token[],
104
+ position: { index: number },
105
+ untilTag?: string,
106
+ depth = 0,
107
+ ): ParseResult {
108
+ const nodes: MarkupNode[] = [];
109
+
110
+ while (position.index < tokens.length) {
111
+ const token = tokens[position.index];
112
+
113
+ if (token.type === 'text') {
114
+ nodes.push({ type: 'text', content: token.content });
115
+ position.index += 1;
116
+ } else if (token.type === 'newline') {
117
+ nodes.push({ type: 'newline' });
118
+ position.index += 1;
119
+ } else if (token.type === 'close') {
120
+ if (token.tag === untilTag) {
121
+ position.index += 1;
122
+ return { closed: true, nodes };
123
+ }
124
+ // Mismatched close tag — render as literal text
125
+ nodes.push({ type: 'text', content: `</${token.tag}>` });
126
+ position.index += 1;
127
+ } else if (token.type === 'open') {
128
+ if (depth >= MAX_NESTING_DEPTH) {
129
+ nodes.push({ type: 'text', content: `<${token.tag}${token.attrs}>` });
130
+ position.index += 1;
131
+ } else {
132
+ position.index += 1;
133
+ const result = parse(tokens, position, token.tag, depth + 1);
134
+
135
+ if (result.closed) {
136
+ const node = buildNode(token.tag, token.attrs, result.nodes);
137
+ nodes.push(node);
138
+ } else {
139
+ nodes.push({ type: 'text', content: `<${token.tag}${token.attrs}>` });
140
+ nodes.push(...result.nodes);
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ if (untilTag) {
147
+ return { closed: false, nodes };
148
+ }
149
+
150
+ return { closed: true, nodes };
151
+ }
152
+
153
+ /**
154
+ * Maps a raw tag name to a typed MarkupNode. Resolves aliases first (p→paragraph, a→link),
155
+ * then builds the appropriate node shape. Link nodes carry full attributes; other element
156
+ * nodes extract only accessibilityLabel.
157
+ */
158
+ function buildNode(rawTag: string, attrs: string, children: MarkupNode[]): MarkupNode {
159
+ const tag = TAG_ALIASES[rawTag] || rawTag;
160
+
161
+ if (tag === 'link') {
162
+ return { type: 'link', children, ...parseAttributes(attrs) };
163
+ }
164
+
165
+ if (tag === 'paragraph') {
166
+ return { type: 'paragraph', children };
167
+ }
168
+
169
+ const { accessibilityLabel } = parseAttributes(attrs);
170
+
171
+ return {
172
+ type: tag as MarkupNode['type'],
173
+ children,
174
+ ...(accessibilityLabel && { accessibilityLabel }),
175
+ } as MarkupNode;
176
+ }
177
+
178
+ /**
179
+ * Matches allow-listed attributes from the raw attribute string captured by TAG_REGEX.
180
+ * Requires whitespace before each attribute name to prevent matching inside quoted values.
181
+ *
182
+ * Example: for input ` href="https://wise.com" target="_blank"`
183
+ * - Match 1: groups = ['href', 'https://wise.com', undefined]
184
+ * - Match 2: groups = ['target', '_blank', undefined]
185
+ *
186
+ * Capture groups:
187
+ * 1. Attribute name (href, action, target, or accessibilityLabel)
188
+ * 2. Double-quoted value (if present)
189
+ * 3. Single-quoted value (if present)
190
+ */
191
+ const ATTR_REGEX = /(?<=\s)(href|action|target|accessibilityLabel)=(?:"([^"]*)"|'([^']*)')/g;
192
+
193
+ type ParsedAttributes = {
194
+ href?: string;
195
+ action?: string;
196
+ target?: string;
197
+ accessibilityLabel?: string;
198
+ };
199
+
200
+ /**
201
+ * Extracts allowed attributes from a raw attribute string.
202
+ * Supports both double- and single-quoted values. Any attribute not in the
203
+ * allow-list (href, action, target, accessibilityLabel) is silently discarded.
204
+ * First occurrence wins — duplicates are ignored.
205
+ */
206
+ function parseAttributes(attrs: string): ParsedAttributes {
207
+ const result: ParsedAttributes = {};
208
+ ATTR_REGEX.lastIndex = 0;
209
+ let match = ATTR_REGEX.exec(attrs);
210
+
211
+ while (match !== null) {
212
+ const key = match[1] as 'href' | 'action' | 'target' | 'accessibilityLabel';
213
+ const value = match[2] ?? match[3];
214
+
215
+ if (!(key in result)) {
216
+ const sanitized = sanitizeAttributeValue(key, value);
217
+ if (sanitized !== undefined) {
218
+ result[key] = sanitized;
219
+ }
220
+ }
221
+
222
+ match = ATTR_REGEX.exec(attrs);
223
+ }
224
+
225
+ return result;
226
+ }
227
+
228
+ function sanitizeAttributeValue(
229
+ key: 'href' | 'action' | 'target' | 'accessibilityLabel',
230
+ value: string,
231
+ ): string | undefined {
232
+ switch (key) {
233
+ case 'href':
234
+ return value.replace(CONTROL_CHARS, '');
235
+ case 'action':
236
+ if (OBJECT_PROTOTYPE_KEYS.has(value)) {
237
+ return undefined;
238
+ }
239
+ return value;
240
+ case 'target':
241
+ if (!ALLOWED_TARGETS.includes(value)) {
242
+ return undefined;
243
+ }
244
+ return value;
245
+ case 'accessibilityLabel':
246
+ return value.replace(HTML_METACHAR, '').slice(0, MAX_ACCESSIBILITY_LABEL_LENGTH);
247
+ default:
248
+ return undefined;
249
+ }
250
+ }
251
+
252
+ /** Entry point: tokenises the input string, then parses the token stream into a MarkupNode tree. */
253
+ export function parseMarkup(input: string): MarkupNode[] {
254
+ if (!input) {
255
+ return [];
256
+ }
257
+
258
+ if (input.length > MAX_INPUT_LENGTH) {
259
+ return [{ type: 'text', content: input }];
260
+ }
261
+
262
+ const tokens = tokenise(input);
263
+ const position = { index: 0 };
264
+ return parse(tokens, position).nodes;
265
+ }