@nkardaz/typography-rules 1.0.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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +911 -0
  3. package/dist/api/blacklist.d.ts +72 -0
  4. package/dist/api/htmlNodes.d.ts +30 -0
  5. package/dist/api/index.d.ts +6 -0
  6. package/dist/api/newRule.d.ts +51 -0
  7. package/dist/api/registerRule.d.ts +27 -0
  8. package/dist/api/rulesInit.d.ts +49 -0
  9. package/dist/functions/chemNotation.d.ts +10 -0
  10. package/dist/functions/clearSpaces.d.ts +16 -0
  11. package/dist/functions/index.cjs +514 -0
  12. package/dist/functions/index.d.ts +8 -0
  13. package/dist/functions/index.mjs +491 -0
  14. package/dist/functions/rubyText.d.ts +11 -0
  15. package/dist/functions/runt.d.ts +3 -0
  16. package/dist/functions/smartNumberGrouping.d.ts +25 -0
  17. package/dist/functions/smartQuotes.d.ts +29 -0
  18. package/dist/functions/wrapWithTag.d.ts +42 -0
  19. package/dist/glyphs/index.cjs +737 -0
  20. package/dist/glyphs/index.d.ts +53 -0
  21. package/dist/glyphs/index.mjs +714 -0
  22. package/dist/glyphs/proto.d.ts +11 -0
  23. package/dist/glyphs/registry.d.ts +728 -0
  24. package/dist/glyphs/types.d.ts +151 -0
  25. package/dist/helpers/index.cjs +268 -0
  26. package/dist/helpers/index.d.ts +133 -0
  27. package/dist/helpers/index.mjs +245 -0
  28. package/dist/helpers/types.d.ts +71 -0
  29. package/dist/index.cjs +985 -0
  30. package/dist/index.d.ts +5 -0
  31. package/dist/index.mjs +977 -0
  32. package/dist/style/index.d.ts +2 -0
  33. package/dist/style/main.css +16 -0
  34. package/dist/types.d.ts +223 -0
  35. package/dist/typography/aliases.d.ts +129 -0
  36. package/dist/typography/expressions/common.d.ts +29 -0
  37. package/dist/typography/expressions/en.d.ts +25 -0
  38. package/dist/typography/expressions/ru.d.ts +29 -0
  39. package/dist/typography/markup/common.d.ts +17 -0
  40. package/dist/typography/markup/en.d.ts +3 -0
  41. package/dist/typography/markup/index.d.ts +4 -0
  42. package/dist/typography/markup/ru.d.ts +3 -0
  43. package/dist/typography/sets/ang.d.ts +3 -0
  44. package/dist/typography/sets/common.d.ts +17 -0
  45. package/dist/typography/sets/en.d.ts +14 -0
  46. package/dist/typography/sets/index.d.ts +5 -0
  47. package/dist/typography/sets/ru.d.ts +16 -0
  48. package/dist/typography/store.d.ts +63 -0
  49. package/package.json +92 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,985 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ALIAS: () => ALIAS,
24
+ clearBlacklist: () => clearBlacklist,
25
+ createAlias: () => createAlias,
26
+ defaultRuleKeys: () => defaultRuleKeys,
27
+ disableRule: () => disableRule,
28
+ enableRule: () => enableRule,
29
+ getWeightedRules: () => getWeightedRules,
30
+ htmlNode: () => htmlNode,
31
+ initMarkupRules: () => initMarkupRules,
32
+ initTypographyRules: () => initTypographyRules,
33
+ isGloballyDisabled: () => isGloballyDisabled,
34
+ isRuleDisabled: () => isRuleDisabled,
35
+ newRule: () => newRule,
36
+ nodeToMdast: () => nodeToMdast,
37
+ registerRule: () => registerRule,
38
+ renderNode: () => renderNode,
39
+ renderNodes: () => renderNodes,
40
+ resetTypographyRules: () => resetTypographyRules,
41
+ rulesBase: () => rulesBase,
42
+ rulesCount: () => rulesCount,
43
+ rulesHas: () => rulesHas,
44
+ toggleRule: () => toggleRule,
45
+ typographyRules: () => typographyRules
46
+ });
47
+ module.exports = __toCommonJS(index_exports);
48
+
49
+ // src/api/newRule.ts
50
+ function newRule(label, rule, second, weight = 0) {
51
+ if (typeof rule === "function") {
52
+ return {
53
+ label,
54
+ kind: "function",
55
+ rule,
56
+ args: Array.isArray(second) ? second : [],
57
+ weight
58
+ };
59
+ }
60
+ if (typeof second === "string") {
61
+ return {
62
+ label,
63
+ kind: "replace",
64
+ rule,
65
+ replacement: second,
66
+ weight
67
+ };
68
+ }
69
+ return {
70
+ label,
71
+ kind: "transform",
72
+ rule,
73
+ transform: second,
74
+ weight
75
+ };
76
+ }
77
+
78
+ // src/typography/aliases.ts
79
+ function createAlias(map) {
80
+ const normalized = Object.fromEntries(
81
+ Object.entries(map).map(([key, values]) => [
82
+ key.toLowerCase(),
83
+ values.map((v) => v.toLowerCase())
84
+ ])
85
+ );
86
+ const methods = {
87
+ /**
88
+ * Checks whether an alias exists in the map,
89
+ * either as a root key or as an alternative name.
90
+ *
91
+ * @param alias - The alias to look up (case-insensitive).
92
+ * @returns `true` if the alias is found, `false` otherwise.
93
+ *
94
+ * @example
95
+ * ALIAS.has('English') // true
96
+ * ALIAS.has('fr') // false
97
+ */
98
+ has(alias) {
99
+ const a = alias.toLowerCase();
100
+ if (a in normalized) return true;
101
+ return Object.values(normalized).some((vals) => vals.includes(a));
102
+ },
103
+ /**
104
+ * Resolves an alias to its root key.
105
+ *
106
+ * @param alias - The alias to resolve (case-insensitive).
107
+ * @returns The root key if found, `undefined` otherwise.
108
+ *
109
+ * @example
110
+ * ALIAS.resolve('Russian') // 'ru'
111
+ * ALIAS.resolve('ru-RU') // 'ru'
112
+ * ALIAS.resolve('fr') // undefined
113
+ */
114
+ resolve(alias) {
115
+ const a = alias.toLowerCase();
116
+ if (a in normalized) return a;
117
+ return Object.keys(normalized).find((k) => {
118
+ const values = normalized[k];
119
+ return Array.isArray(values) && values.includes(a);
120
+ });
121
+ },
122
+ /**
123
+ * Adds one or more alternative names to an existing or new root key.
124
+ * All values are automatically lowercased.
125
+ *
126
+ * @param root - The root key to add aliases to.
127
+ * @param aliases - One or more alternative names to register.
128
+ *
129
+ * @example
130
+ * ALIAS.push('ru', 'Рус', 'ру')
131
+ * ALIAS.ru // ['ru-ru', 'russian', 'русский', 'рус', 'ру']
132
+ */
133
+ push(root2, ...aliases) {
134
+ for (const alias of aliases) {
135
+ const a = alias.toLowerCase();
136
+ const r = root2.toLowerCase();
137
+ if (a in normalized) {
138
+ normalized[a]?.push(r);
139
+ } else {
140
+ normalized[a] = [r];
141
+ }
142
+ }
143
+ },
144
+ /**
145
+ * Normalizes one or more strings to lowercase.
146
+ *
147
+ * @param alias - One or more strings to normalize.
148
+ * @returns An array of lowercased strings.
149
+ *
150
+ * @example
151
+ * ALIAS.normalize('English', 'RU-RU') // ['english', 'ru-ru']
152
+ */
153
+ normalize(...alias) {
154
+ return alias.map((a) => a.toLowerCase());
155
+ }
156
+ };
157
+ return new Proxy(methods, {
158
+ get(target, prop) {
159
+ if (prop in target) return target[prop];
160
+ return normalized[prop];
161
+ },
162
+ has(_target, prop) {
163
+ return prop in normalized;
164
+ },
165
+ ownKeys() {
166
+ return [...Object.keys(normalized), ...Object.keys(methods)];
167
+ },
168
+ getOwnPropertyDescriptor(_target, prop) {
169
+ if (prop in normalized || prop in methods) {
170
+ return { enumerable: true, configurable: true };
171
+ }
172
+ return void 0;
173
+ }
174
+ });
175
+ }
176
+ var ALIAS = createAlias({
177
+ ru: ["ru-RU", "Russian", "\u0420\u0443\u0441\u0441\u043A\u0438\u0439"],
178
+ en: ["en-US", "English"],
179
+ ang: ["\xC6nglis\u010B", "\xC6nglisc", "Old English"]
180
+ });
181
+
182
+ // src/typography/store.ts
183
+ var _rules = { common: [] };
184
+ var _cache = /* @__PURE__ */ new Map();
185
+ var typographyRules = new Proxy(_rules, {
186
+ set(target, locale3, value) {
187
+ target[locale3] = value;
188
+ _cache.delete(locale3);
189
+ if (locale3 !== "common") _cache.delete("common");
190
+ return true;
191
+ }
192
+ });
193
+ function getWeightedRules(locale3) {
194
+ if (_cache.has(locale3)) return _cache.get(locale3);
195
+ const common = _rules["common"] ?? [];
196
+ const localized = _rules[locale3] ?? [];
197
+ if (common.length === 0 && localized.length === 0) return [];
198
+ const result = [...common, ...localized].sort((a, b) => {
199
+ const weightA = a.weight ?? 0;
200
+ const weightB = b.weight ?? 0;
201
+ return weightA !== weightB ? weightA - weightB : 0;
202
+ });
203
+ _cache.set(locale3, result);
204
+ return result;
205
+ }
206
+ function resetTypographyRules() {
207
+ for (const key in _rules) {
208
+ _rules[key] = [];
209
+ }
210
+ _cache.clear();
211
+ }
212
+ function rulesHas(locale3) {
213
+ return !!_rules[locale3];
214
+ }
215
+ function rulesCount(locale3) {
216
+ return _rules[locale3]?.length ?? 0;
217
+ }
218
+
219
+ // src/api/registerRule.ts
220
+ function registerRule(locale3, ...rules) {
221
+ const key = ALIAS.resolve(locale3) ?? locale3;
222
+ if (!typographyRules[key]) typographyRules[key] = [];
223
+ typographyRules[key].push(...rules);
224
+ }
225
+ function rulesBase(locale3, base, label, excludes, ...rules) {
226
+ const localeKey = ALIAS.resolve(locale3) ?? locale3;
227
+ const baseKey = ALIAS.resolve(base) ?? base;
228
+ const baseRules = (typographyRules[baseKey] ?? []).filter((rule) => !excludes?.includes(rule.label)).map((rule) => {
229
+ if (!label) return rule;
230
+ const shallow = { ...rule };
231
+ if (shallow.label) {
232
+ shallow.label = shallow.label.replace(label.expression, label.replacement);
233
+ }
234
+ return shallow;
235
+ });
236
+ registerRule(localeKey, ...baseRules, ...rules);
237
+ }
238
+
239
+ // src/api/blacklist.ts
240
+ function createNode() {
241
+ return {
242
+ children: /* @__PURE__ */ new Map(),
243
+ end: false
244
+ };
245
+ }
246
+ var root = createNode();
247
+ var globalDisabled = false;
248
+ function getParts(rule) {
249
+ return rule.split("/").filter(Boolean);
250
+ }
251
+ function disableRule(rule) {
252
+ if (rule === "*") {
253
+ globalDisabled = true;
254
+ return;
255
+ }
256
+ let node = root;
257
+ for (const part of getParts(rule)) {
258
+ if (!node.children.has(part)) {
259
+ node.children.set(part, createNode());
260
+ }
261
+ node = node.children.get(part);
262
+ }
263
+ node.end = true;
264
+ }
265
+ function enableRule(rule) {
266
+ if (rule === "*") {
267
+ globalDisabled = false;
268
+ return;
269
+ }
270
+ const stack = [];
271
+ let node = root;
272
+ for (const part of getParts(rule)) {
273
+ if (!node.children.has(part)) return;
274
+ stack.push({ node, part });
275
+ node = node.children.get(part);
276
+ }
277
+ node.end = false;
278
+ for (let i = stack.length - 1; i >= 0; i--) {
279
+ const entry = stack[i];
280
+ if (!entry) continue;
281
+ const { node: parent, part } = entry;
282
+ const child = parent.children.get(part);
283
+ if (child.end || child.children.size > 0) break;
284
+ parent.children.delete(part);
285
+ }
286
+ }
287
+ function toggleRule(rule) {
288
+ if (isRuleDisabled(rule)) {
289
+ enableRule(rule);
290
+ } else {
291
+ disableRule(rule);
292
+ }
293
+ }
294
+ function isRuleDisabled(rule) {
295
+ if (globalDisabled) return true;
296
+ let node = root;
297
+ for (const part of getParts(rule)) {
298
+ if (node.end) return true;
299
+ if (!node.children.has(part)) return false;
300
+ node = node.children.get(part);
301
+ }
302
+ return node.end;
303
+ }
304
+ function isGloballyDisabled() {
305
+ return globalDisabled;
306
+ }
307
+ function clearBlacklist() {
308
+ globalDisabled = false;
309
+ root.children.clear();
310
+ root.end = false;
311
+ }
312
+
313
+ // src/typography/sets/index.ts
314
+ var sets_exports = {};
315
+ __export(sets_exports, {
316
+ ang: () => ang_default,
317
+ common: () => common_default2,
318
+ en: () => en_default2,
319
+ ru: () => ru_default2
320
+ });
321
+
322
+ // src/typography/sets/ang.ts
323
+ var ang_default = [
324
+ newRule("/\xE6nglis\u010B/articles/\xFEe", /\s+The\s+/g, ` \xDE\u0364 `),
325
+ newRule("/\xE6nglis\u010B/articles/\xFEe", /\s+the\s+/g, ` \xFE\u0364 `),
326
+ newRule("/\xE6nglis\u010B/articles/\xFEe", /\s+Þe\s+/g, ` \xDE\u0364 `),
327
+ newRule("/\xE6nglis\u010B/articles/\xFEe", /\s+þe\s+/g, ` \xFE\u0364 `)
328
+ ];
329
+
330
+ // src/typography/sets/common.ts
331
+ var import_functions = require("./functions/index.cjs");
332
+ var import_glyphs2 = require("./glyphs/index.cjs");
333
+
334
+ // src/typography/expressions/common.ts
335
+ var import_glyphs = require("./glyphs/index.cjs");
336
+ var PARTS = {
337
+ numerals: "[" + import_glyphs.RANGES.common.DIGITS.join("") + "]+",
338
+ interNumber: "[" + import_glyphs.MATHS.minus + import_glyphs.DASHES.en + "]",
339
+ walletSymbols: import_glyphs.WALLET.SYMBOL.values().map((s) => RegExp.escape(s)).join("|"),
340
+ walletISO: import_glyphs.WALLET.ISO.join("|"),
341
+ leftBrackets: RegExp.escape(import_glyphs.BRACKETS.common.left.join("")),
342
+ rightBrackets: RegExp.escape(import_glyphs.BRACKETS.common.right.join("")),
343
+ percentLike: "[" + import_glyphs.CHARACTERS.find("percent", "permil", "perTenThousand")?.join("") + "]",
344
+ expressivePunctuation: "[" + import_glyphs.PUNCTUATION.common.rightSided.find(
345
+ "exclamation",
346
+ "doubleExclamation",
347
+ "exclamationQuestion",
348
+ "question",
349
+ "doubleQuestion",
350
+ "questionExclamation",
351
+ "reversedQuestion",
352
+ "interrobang"
353
+ )?.join("") + "]",
354
+ get number() {
355
+ const value = `([${import_glyphs.MATHS.minus}]?${PARTS.numerals})`;
356
+ Object.defineProperty(this, "number", { value, enumerable: true, configurable: false });
357
+ return value;
358
+ }
359
+ };
360
+ var EXPRESSIONS = {
361
+ plusMinus: new RegExp(`(\\+[-${import_glyphs.MATHS.minus}])`, "g"),
362
+ minusPlus: new RegExp(`([-${import_glyphs.MATHS.minus}]\\+)`, "g"),
363
+ sectionNumeral: new RegExp(`(${import_glyphs.CHARACTERS.section})\\s*((?:${PARTS.numerals}\\s*)*)`, "g"),
364
+ percentValue: new RegExp(`${PARTS.number}\\s*(${PARTS.percentLike})`, "g"),
365
+ numeralsRange: new RegExp(`(${PARTS.numerals})-(${PARTS.numerals})`, "g"),
366
+ ellipsisRange: new RegExp(`${PARTS.number + PARTS.interNumber + PARTS.number}`, "g"),
367
+ multipleEllipsis: new RegExp(`${import_glyphs.PUNCTUATION.common.rightSided.ellipsis}{2,}`, "g"),
368
+ walletSymbolBeforeValue: new RegExp(`(${PARTS.walletSymbols})\\s*(\\d[\\d.]*)`, "g"),
369
+ walletSymbolAfterValue: new RegExp(`(\\d+)\\s*(${PARTS.walletSymbols})`, "g"),
370
+ walletISOBeforeValue: new RegExp(`(${PARTS.walletISO})\\s*(\\d[\\d.]*)`, "g"),
371
+ walletISOAfterValue: new RegExp(`(\\d+)\\s*(${PARTS.walletISO})`, "g"),
372
+ expressiveAposiopesis: new RegExp(
373
+ `(${PARTS.expressivePunctuation})\\s*(?:${import_glyphs.PUNCTUATION.common.rightSided.ellipsis}|\\.{1,})[.${import_glyphs.PUNCTUATION.common.rightSided.ellipsis}]*`,
374
+ "g"
375
+ ),
376
+ backwardsExpressiveAposiopesis: new RegExp(
377
+ `(?:${import_glyphs.PUNCTUATION.common.rightSided.ellipsis}|\\.{1,})[.${import_glyphs.PUNCTUATION.common.rightSided.ellipsis}]*\\s*(${PARTS.expressivePunctuation})`,
378
+ "g"
379
+ ),
380
+ temperature: new RegExp(`(\\d+)\\s*(${import_glyphs.TEMPERATURES.join()})`, "g")
381
+ };
382
+ var common_default = EXPRESSIONS;
383
+
384
+ // src/typography/sets/common.ts
385
+ var common_default2 = [
386
+ // Whitespace cleanup
387
+ // newRule(/\s+/g, SPACES._),
388
+ newRule("/common/space/cleanup/multiple", import_functions.clearSpaces),
389
+ newRule("/common/space/cleanup/trim", /^\s|\s$/g, import_glyphs2.NONE),
390
+ // Math
391
+ // Minus sign for negative numbers
392
+ newRule("/common/number/negative", /(?<!\d)-(\d+)/g, `${import_glyphs2.MATHS.minus}$1`),
393
+ // En dash for ranges, e.g. 1–2
394
+ newRule("/common/number/range/en-dash", common_default.numeralsRange, `$1${import_glyphs2.DASHES.en}$2`),
395
+ // Ellipsis for ranges, e.g. −2…3
396
+ newRule(
397
+ "/common/number/range/ellipsis-on-negative",
398
+ common_default.ellipsisRange,
399
+ `$1${import_glyphs2.PUNCTUATION.common.rightSided.ellipsis}$2`
400
+ ),
401
+ newRule("/common/number/dimension", /(\d+)\s*(?:x|х)\s*(\d+)/g, `$1${import_glyphs2.MATHS.multiply}$2`),
402
+ newRule("/common/number/multiply", /(\d+\s*)(?:\*)(\s*\d+)/g, `$1${import_glyphs2.MATHS.multiply}$2`),
403
+ newRule("/common/number/fraction", /(\d+)\/(\d+)/g, `$1${import_glyphs2.MATHS.fractionSlash}$2`),
404
+ newRule("/common/symbol/copyright", /\((?:c|с)\)/g, import_glyphs2.CHARACTERS.copyright),
405
+ newRule("/common/symbol/trademark", /\((?:tm|тм)\)/g, import_glyphs2.CHARACTERS.trademark),
406
+ newRule("/common/symbol/registered", /\(r\)/g, import_glyphs2.CHARACTERS.registered),
407
+ newRule("/common/symbol/section", /\(s\)/g, import_glyphs2.CHARACTERS.section),
408
+ newRule("/common/symbol/math/plus-minus", common_default.plusMinus, import_glyphs2.MATHS.plusMinus),
409
+ newRule("/common/symbol/math/minus-plus", common_default.minusPlus, import_glyphs2.MATHS.minusPlus),
410
+ // Generic Typography
411
+ // Em dash replacing double hyphen
412
+ newRule("/common/punctuation/dashes/em-dash", /--/g, import_glyphs2.DASHES.em),
413
+ // Fix too large dots count
414
+ newRule("/common/punctuation/dots/overload", /\.{4,}/g, "..."),
415
+ // Ellipsis replacing three dots
416
+ newRule("/common/punctuation/dots/ellipsis", /\.\.\./g, import_glyphs2.PUNCTUATION.common.rightSided.ellipsis),
417
+ // Fix multiple ellipses
418
+ newRule(
419
+ "/common/punctuation/dots/ellipsis-overload",
420
+ common_default.multipleEllipsis,
421
+ import_glyphs2.PUNCTUATION.common.rightSided.ellipsis
422
+ ),
423
+ // Apostrophe replacing single straight quote
424
+ newRule("/common/punctuation/apostrophe", /'/g, import_glyphs2.PUNCTUATION.common.generic.apostrophe, 200),
425
+ newRule(
426
+ "/common/symbol/section/value",
427
+ common_default.sectionNumeral,
428
+ (match) => {
429
+ const numero = match[1];
430
+ const numeral = match[2].replace(/\s+/g, "");
431
+ return `${numero}${import_glyphs2.SPACES.noBreakNarrow}${numeral}`;
432
+ },
433
+ 1
434
+ ),
435
+ // Runt
436
+ newRule("/common/typography/runt", import_functions.runt, void 0, Infinity)
437
+ ];
438
+
439
+ // src/typography/sets/en.ts
440
+ var import_functions2 = require("./functions/index.cjs");
441
+ var import_glyphs4 = require("./glyphs/index.cjs");
442
+
443
+ // src/typography/expressions/en.ts
444
+ var import_glyphs3 = require("./glyphs/index.cjs");
445
+ var SI_PREFIX = "Y|Z|E|P|T|G|M|k|h|da|d|c|m|\u03BC|n|p|f|a|z|y";
446
+ var SI_BASE = [
447
+ "g|t",
448
+ "m",
449
+ "s|min|h",
450
+ "N",
451
+ "Pa",
452
+ "J",
453
+ "W",
454
+ "A|V|\u03A9|F|H|C|T|Wb",
455
+ "Hz",
456
+ "mol|cd|rad|sr"
457
+ ].join("|");
458
+ var SI_UNIT = `(?:${SI_PREFIX})?(?:${SI_BASE})`;
459
+ var SI_OPERAND = `(?:${SI_UNIT})(?:\\^[\\d]+)?`;
460
+ var PARTS2 = {
461
+ ...PARTS,
462
+ leftPunctuation: RegExp.escape(import_glyphs3.PUNCTUATION.get("en", "leftSided").join("")),
463
+ rightPunctuation: RegExp.escape(import_glyphs3.PUNCTUATION.get("en", "rightSided").join("")),
464
+ get leftChars() {
465
+ const value = PARTS2.leftPunctuation + PARTS2.leftBrackets;
466
+ Object.defineProperty(this, "leftChars", { value, enumerable: true, configurable: false });
467
+ return value;
468
+ },
469
+ get rightChars() {
470
+ const value = PARTS2.rightPunctuation + PARTS2.rightBrackets;
471
+ Object.defineProperty(this, "rightChars", { value, enumerable: true, configurable: false });
472
+ return value;
473
+ }
474
+ };
475
+ var EXPRESSIONS2 = {
476
+ ...EXPRESSIONS,
477
+ numberNumeral: new RegExp(`(${import_glyphs3.CHARACTERS.number})\\s*(${PARTS2.numerals})`, "g"),
478
+ invalidPunctuationSpacing: new RegExp(
479
+ `(?<=[${PARTS2.leftChars}])\\s+|(?<!\\s)\\s(?=[${PARTS2.rightChars}])`,
480
+ "g"
481
+ ),
482
+ siUnitMul: new RegExp(`(${SI_OPERAND})\\*(${SI_OPERAND}(?:\\/${SI_OPERAND})*)`, "g"),
483
+ siUnitDiv: new RegExp(`(${SI_OPERAND}(?:\\/${SI_OPERAND})*)\\*(${SI_OPERAND})`, "g"),
484
+ siUnitBase: new RegExp(`(\\d+)\\s*(${SI_UNIT})(?![/*])`, "g"),
485
+ siUnitPowAfterNum: new RegExp(`(\\d+)\\s*(${SI_UNIT})(\\d+)`, "g"),
486
+ siUnitPow: new RegExp(`(?<!\\d\\s*)(${SI_UNIT})(\\d+)`, "g")
487
+ };
488
+ var en_default = EXPRESSIONS2;
489
+
490
+ // src/typography/sets/en.ts
491
+ var locale = "en-US";
492
+ var en_default2 = [
493
+ newRule("/english/currency/wallet/symbol-flip", en_default.walletSymbolAfterValue, `$2$1`),
494
+ newRule("/english/currency/wallet/iso-flip", en_default.walletISOBeforeValue, `$2$1`),
495
+ newRule("/english/currency/wallet/symbol-value", en_default.walletSymbolBeforeValue, `$1$2`),
496
+ newRule(
497
+ "/english/currency/wallet/iso-value",
498
+ en_default.walletISOAfterValue,
499
+ `$1${import_glyphs4.SPACES.noBreak}$2`
500
+ ),
501
+ newRule("/english/number/groups", import_functions2.smartNumberGrouping, [{ locale }]),
502
+ newRule("/english/metric/si-unit/base", en_default.siUnitBase, `$1${import_glyphs4.SPACES.noBreakNarrow}$2`),
503
+ newRule("/english/metric/si-unit/n*n-n", en_default.siUnitMul, `$1${import_glyphs4.CHARACTERS.middleDot}$2`),
504
+ newRule("/english/metric/si-unit/n-n*n", en_default.siUnitDiv, `$1${import_glyphs4.CHARACTERS.middleDot}$2`),
505
+ newRule(
506
+ "/english/metric/si-unit/pow-after-value",
507
+ import_functions2.wrapWithTag,
508
+ [
509
+ {
510
+ expression: en_default.siUnitPowAfterNum,
511
+ tag: "sup",
512
+ placement: `$1${import_glyphs4.SPACES.noBreakNarrow}$2<TAG>$3</TAG>`
513
+ }
514
+ ],
515
+ -1
516
+ ),
517
+ newRule(
518
+ "/english/metric/si-unit/pow",
519
+ import_functions2.wrapWithTag,
520
+ [
521
+ {
522
+ expression: en_default.siUnitPow,
523
+ tag: "sup",
524
+ placement: `$1<TAG>$2</TAG>`
525
+ }
526
+ ],
527
+ -1
528
+ ),
529
+ newRule("/english/scientific/temperature/value", en_default.temperature, `$1$2`),
530
+ newRule("/english/symbol/percent-like/value", en_default.percentValue, `$1$2`),
531
+ newRule("/english/symbol/hash/value", en_default.numberNumeral, `$1$2`),
532
+ newRule("/english/number/division", /(\d+\s*)(?:\/)(\s*\d+)/g, `$1${import_glyphs4.MATHS.obelus}$2`),
533
+ newRule(
534
+ "/english/number/division-times",
535
+ /(\d+\s*)(?:\/\*)(\s*\d+)/g,
536
+ `$1${import_glyphs4.MATHS.divisionTimes}$2`
537
+ ),
538
+ newRule(
539
+ "/english/punctuation/quotes",
540
+ import_functions2.smartQuotes,
541
+ [
542
+ {
543
+ outer: [import_glyphs4.PUNCTUATION.en.leftSided.outerQuoteOpen, import_glyphs4.PUNCTUATION.en.rightSided.outerQuoteClose],
544
+ inner: [import_glyphs4.PUNCTUATION.en.leftSided.innerQuoteOpen, import_glyphs4.PUNCTUATION.en.rightSided.innerQuoteClose]
545
+ }
546
+ ],
547
+ 100
548
+ ),
549
+ newRule(
550
+ "/english/punctuation/dot-before-expression",
551
+ en_default.expressiveAposiopesis,
552
+ import_glyphs4.PUNCTUATION.common.rightSided.ellipsis + "$1"
553
+ ),
554
+ newRule(
555
+ "/english/punctuation/dot-before-expression",
556
+ en_default.backwardsExpressiveAposiopesis,
557
+ import_glyphs4.PUNCTUATION.common.rightSided.ellipsis + "$1"
558
+ ),
559
+ newRule(
560
+ "/english/punctuation/invalid-spacing",
561
+ en_default.invalidPunctuationSpacing,
562
+ import_glyphs4.NONE,
563
+ 1e3
564
+ ),
565
+ newRule("/english/ligatures/fi", /fi/g, import_glyphs4.LIGATURES.fi),
566
+ newRule("/english/ligatures/fl", /fl/g, import_glyphs4.LIGATURES.fl),
567
+ newRule("/english/ligatures/ffi", /ffi/g, import_glyphs4.LIGATURES.ffi),
568
+ newRule("/english/ligatures/ffl", /ffl/g, import_glyphs4.LIGATURES.ffl)
569
+ ];
570
+
571
+ // src/typography/sets/ru.ts
572
+ var import_functions3 = require("./functions/index.cjs");
573
+ var import_glyphs6 = require("./glyphs/index.cjs");
574
+
575
+ // src/typography/expressions/ru.ts
576
+ var import_glyphs5 = require("./glyphs/index.cjs");
577
+ var SI_PREFIX2 = "\u0419|\u0417|\u042D|\u041F|\u0422|\u0413|\u041C|\u043A|\u0433|\u041C|\u043A|\u0434|\u0441|\u043C|\u043C\u043A|\u043D|\u043F|\u0444|\u0430|\u0437|\u0439";
578
+ var SI_BASE2 = [
579
+ "\u0433|\u0442",
580
+ "\u043C",
581
+ "\u0441|\u043C\u0438\u043D|\u0447",
582
+ "\u041D",
583
+ "\u041F\u0430",
584
+ "\u0414\u0436",
585
+ "\u0412\u0442",
586
+ "\u0410|\u0412|\u041E\u043C|\u0424|\u0413\u043D|\u041A\u043B|\u0422\u043B|\u0412\u0431",
587
+ "\u0413\u0446",
588
+ "\u043C\u043E\u043B\u044C|\u043A\u0434|\u0440\u0430\u0434|\u0441\u0440"
589
+ ].join("|");
590
+ var SI_UNIT2 = `(?:${SI_PREFIX2})?(?:${SI_BASE2})`;
591
+ var SI_OPERAND2 = `(?:${SI_UNIT2})(?:\\^[\\d]+)?`;
592
+ var PARTS3 = {
593
+ ...PARTS,
594
+ leftPunctuation: RegExp.escape(import_glyphs5.PUNCTUATION.get("ru", "leftSided").join("")),
595
+ rightPunctuation: RegExp.escape(import_glyphs5.PUNCTUATION.get("ru", "rightSided").join("")),
596
+ get leftChars() {
597
+ const value = PARTS3.leftPunctuation + PARTS3.leftBrackets;
598
+ Object.defineProperty(this, "leftChars", { value, enumerable: true, configurable: false });
599
+ return value;
600
+ },
601
+ get rightChars() {
602
+ const value = PARTS3.rightPunctuation + PARTS3.rightBrackets;
603
+ Object.defineProperty(this, "rightChars", { value, enumerable: true, configurable: false });
604
+ return value;
605
+ }
606
+ };
607
+ var EXPRESSIONS3 = {
608
+ ...EXPRESSIONS,
609
+ numeroNumeral: new RegExp(`(${import_glyphs5.CHARACTERS.numero})\\s*((?:${PARTS3.numerals}\\s*)*)`, "g"),
610
+ invalidPunctuationSpacing: new RegExp(
611
+ `(?<=[${PARTS3.leftChars}])\\s+|(?<!\\s)\\s(?=[${PARTS3.rightChars}])`,
612
+ "g"
613
+ ),
614
+ dialogEmDash: new RegExp(`(^${import_glyphs5.DASHES.em})\\s*`, "gm"),
615
+ attributionEmDash: new RegExp(
616
+ `([${PARTS3.rightPunctuation}])\\s*(${import_glyphs5.DASHES.em})\\s*([\u0430-\u044F\u0410-\u042F\u0451\u0401a-zA-Z]+)`,
617
+ "gi"
618
+ ),
619
+ subjectPredicateEmDash: new RegExp(
620
+ `([\u0430-\u044F\u0410-\u042F\u0451\u0401a-zA-Z]+)\\s+(${import_glyphs5.DASHES.em})\\s+([\u0430-\u044F\u0410-\u042F\u0451\u0401a-zA-Z]+)`,
621
+ "gi"
622
+ ),
623
+ siUnitMul: new RegExp(`(${SI_OPERAND2})\\*(${SI_OPERAND2}(?:\\/${SI_OPERAND2})*)`, "g"),
624
+ siUnitDiv: new RegExp(`(${SI_OPERAND2}(?:\\/${SI_OPERAND2})*)\\*(${SI_OPERAND2})`, "g"),
625
+ siUnitBase: new RegExp(`(\\d+)\\s*(${SI_UNIT2})(?![/*])`, "g"),
626
+ siUnitPowAfterNum: new RegExp(`(\\d+)\\s*(${SI_UNIT2})(\\d+)`, "g"),
627
+ siUnitPow: new RegExp(`(?<!\\d\\s*)(${SI_UNIT2})(\\d+)`, "g"),
628
+ date: new RegExp(`(${PARTS3.numerals})\\s(\u0432\u0432|\u0432|\u0433\u0433|\u0433|\u043C\u0435\u0441|\u043D\u0435\u0434|\u0434\u043D|\u0434)(\\.|\\s)`, "gi")
629
+ };
630
+ var ru_default = EXPRESSIONS3;
631
+
632
+ // src/typography/sets/ru.ts
633
+ var locale2 = "ru-RU";
634
+ var ru_default2 = [
635
+ newRule("/russian/currency/wallet/symbol-flip", ru_default.walletSymbolBeforeValue, `$2$1`),
636
+ newRule("/russian/currency/wallet/iso-flip", ru_default.walletISOBeforeValue, `$2$1`),
637
+ newRule(
638
+ "/russian/currency/wallet/symbol-value",
639
+ ru_default.walletSymbolAfterValue,
640
+ `$1${import_glyphs6.SPACES.noBreak}$2`
641
+ ),
642
+ newRule(
643
+ "/russian/currency/wallet/iso-value",
644
+ ru_default.walletISOAfterValue,
645
+ `$1${import_glyphs6.SPACES.noBreak}$2`
646
+ ),
647
+ newRule(
648
+ "/russian/currency/rub-to-symbol",
649
+ /(\d+)\s*(?:рублей|рубля|рубль|руб\.?|р\.?)(?!\p{L})/giu,
650
+ `$1${import_glyphs6.SPACES.noBreak + import_glyphs6.WALLET.SYMBOL.ruble}`
651
+ ),
652
+ newRule(
653
+ "/russian/currency/eur-to-symbol",
654
+ /(\d+)\s*(?:евро)(?!\p{L})/giu,
655
+ `$1${import_glyphs6.SPACES.noBreak + import_glyphs6.WALLET.SYMBOL.euro}`
656
+ ),
657
+ newRule(
658
+ "/russian/currency/usd-to-symbol",
659
+ /(\d+)\s*(?:долларов|доллар|дол\.?)(?!\p{L})/giu,
660
+ `$1${import_glyphs6.SPACES.noBreak + import_glyphs6.WALLET.SYMBOL.dollar}`
661
+ ),
662
+ newRule("/russian/number/groups", import_functions3.smartNumberGrouping, [{ locale: locale2 }]),
663
+ newRule("/russian/number/normalize/dot->comma", /(\d+)\.(\d+)/g, "$1,$2"),
664
+ newRule("/russian/metric/si-unit/base", ru_default.siUnitBase, `$1${import_glyphs6.SPACES.noBreakNarrow}$2`),
665
+ newRule("/russian/metric/si-unit/n*n-n", ru_default.siUnitMul, `$1${import_glyphs6.CHARACTERS.middleDot}$2`),
666
+ newRule("/russian/metric/si-unit/n-n*n", ru_default.siUnitDiv, `$1${import_glyphs6.CHARACTERS.middleDot}$2`),
667
+ newRule(
668
+ "/russian/metric/si-unit/pow-after-value",
669
+ import_functions3.wrapWithTag,
670
+ [
671
+ {
672
+ expression: ru_default.siUnitPowAfterNum,
673
+ tag: "sup",
674
+ placement: `$1${import_glyphs6.SPACES.noBreakNarrow}$2<TAG>$3</TAG>`
675
+ }
676
+ ],
677
+ -1
678
+ ),
679
+ newRule(
680
+ "/russian/metric/si-unit/pow",
681
+ import_functions3.wrapWithTag,
682
+ [
683
+ {
684
+ expression: ru_default.siUnitPow,
685
+ tag: "sup",
686
+ placement: `$1<TAG>$2</TAG>`
687
+ }
688
+ ],
689
+ -1
690
+ ),
691
+ newRule(
692
+ "/russian/scientific/temperature/value",
693
+ ru_default.temperature,
694
+ `$1${import_glyphs6.SPACES.noBreak}$2`
695
+ ),
696
+ newRule("/russian/symbol/percent-like/value", ru_default.percentValue, `$1${import_glyphs6.SPACES.noBreak}$2`),
697
+ newRule("/russian/symbol/numero/value", ru_default.numeroNumeral, (match) => {
698
+ const numero = match[1];
699
+ const numeral = match[2].replace(/\s+/g, "");
700
+ return `${numero}${import_glyphs6.SPACES.noBreakNarrow}${numeral}`;
701
+ }),
702
+ newRule("/russian/number/division", /(\d+\s*)(?:\/)(\s*\d+)/g, `$1${import_glyphs6.MATHS.obelus}$2`),
703
+ newRule(
704
+ "/russian/number/division-times",
705
+ /(\d+\s*)(?:\/\*)(\s*\d+)/g,
706
+ `$1${import_glyphs6.MATHS.divisionTimes}$2`
707
+ ),
708
+ newRule(
709
+ "/russian/punctuation/dashes/dialog-em-dash",
710
+ ru_default.dialogEmDash,
711
+ `$1${import_glyphs6.SPACES.noBreak}`
712
+ ),
713
+ newRule(
714
+ "/russian/punctuation/dashes/attribution-em-dash",
715
+ ru_default.attributionEmDash,
716
+ `$1${import_glyphs6.SPACES.noBreak}$2${import_glyphs6.SPACES.noBreak}$3`
717
+ ),
718
+ newRule(
719
+ "/russian/punctuation/dashes/subject-predicate-em-dash",
720
+ ru_default.subjectPredicateEmDash,
721
+ `$1${import_glyphs6.SPACES.noBreak}$2${import_glyphs6.SPACES._}$3`
722
+ ),
723
+ newRule(
724
+ "/russian/punctuation/quotes",
725
+ import_functions3.smartQuotes,
726
+ [
727
+ {
728
+ outer: [import_glyphs6.PUNCTUATION.ru.leftSided.outerQuoteOpen, import_glyphs6.PUNCTUATION.ru.rightSided.outerQuoteClose],
729
+ inner: [import_glyphs6.PUNCTUATION.ru.leftSided.innerQuoteOpen, import_glyphs6.PUNCTUATION.ru.rightSided.innerQuoteClose]
730
+ }
731
+ ],
732
+ 100
733
+ ),
734
+ newRule("/russian/punctuation/dot-after-quote", /\.»/g, "\xBB.", 1e3),
735
+ newRule(
736
+ "/russian/punctuation/dot-after-expression",
737
+ ru_default.backwardsExpressiveAposiopesis,
738
+ "$1.."
739
+ ),
740
+ newRule("/russian/punctuation/dot-after-expression", ru_default.expressiveAposiopesis, "$1.."),
741
+ newRule(
742
+ "/russian/punctuation/invalid-spacing",
743
+ ru_default.invalidPunctuationSpacing,
744
+ import_glyphs6.NONE,
745
+ 1e3
746
+ ),
747
+ newRule(
748
+ "/russian/compositions/initials",
749
+ /([а-яёА-ЯЁ]\.)[\s]([а-яёА-ЯЁ]\.)[\s]([а-яёА-ЯЁ][а-яёА-ЯЁ]+)/g,
750
+ `$1${import_glyphs6.SPACES.thin}$2${import_glyphs6.SPACES.thin}$3`
751
+ ),
752
+ newRule(
753
+ "/russian/compositions/initials",
754
+ /([а-яёА-ЯЁ][а-яёА-ЯЁ]+)[\s]([а-яёА-ЯЁ}]\.)[\s]([а-яёА-ЯЁ]\.)/g,
755
+ `$1${import_glyphs6.SPACES.thin}$2${import_glyphs6.SPACES.thin}$3`
756
+ ),
757
+ newRule(
758
+ "/russian/text/conjunctions",
759
+ /\s(бы|б|же|ж|ли|ль)(?![а-яА-ЯёЁ])/gi,
760
+ `${import_glyphs6.SPACES.noBreak}$1`
761
+ ),
762
+ newRule(
763
+ "/russian/text/conjunctions",
764
+ /(?<=\s)(за|из|до|об|на|но|не|ни|то|от|по|со|или|для|над|под|при|что|если|через|после|перед)\s/gi,
765
+ `$1${import_glyphs6.SPACES.noBreak}`
766
+ ),
767
+ newRule("/russian/text/adress", /(?<=\s)(мкр-н|мкр\.)\s/gi, `$1${import_glyphs6.SPACES.noBreak}`),
768
+ newRule(
769
+ "/russian/text/adress",
770
+ /(?<=\s)(дом|д\.|под\.|п-д|эт\.|кв\.)\s*(\d+)/gi,
771
+ `$1${import_glyphs6.SPACES.noBreak}$2`
772
+ ),
773
+ newRule("/russian/text/adress", /(?<=\d+[-]?(?:й|го|му))\s*([-−]?этаж)/gi, `${import_glyphs6.SPACES.noBreak}$1`),
774
+ newRule(
775
+ "/russian/text/adress",
776
+ /(?<=\s)(обл|кр|ст|пос|с|д|ул|пер|пр|пр-т|просп|пл|бул|б-р|наб|ш|туп|оф|комн?|уч|вл|влад|стр|корп?)(\.|\s)([а-яА-ЯёЁa-zA-Z\d]+)/gi,
777
+ `$1.${import_glyphs6.SPACES.noBreak}$2`
778
+ ),
779
+ newRule(
780
+ "/russian/text/common-shorts",
781
+ /(?<=\s)(коп|см|им|рис|илл?|гл|кн|стр|ст|с|п)(\.|\s)/gi,
782
+ `$1.${import_glyphs6.SPACES.noBreak}.`
783
+ ),
784
+ newRule(
785
+ "/russian/text/organizations",
786
+ /(АО|ОАО|ЗАО|ООО|ПАО|НИИ|ПБОЮЛ)\s+/g,
787
+ `$1${import_glyphs6.SPACES.noBreak}`
788
+ ),
789
+ newRule("/russian/text/dates", ru_default.date, `$1${import_glyphs6.SPACES.noBreak}$2.`),
790
+ newRule(
791
+ "/russian/text/millions",
792
+ /(\d+)\s*(тыс|млн|млрд|трлн)(\.|\s)/gi,
793
+ `$1${import_glyphs6.SPACES.noBreak}$2.`
794
+ ),
795
+ newRule(
796
+ "/russian/text/no-break-hyphen",
797
+ /(^|[^а-яА-ЯёЁ])(кто|что|какой|который|чей|сколько|где|куда|откуда|когда|как|зачем|почему|отчего|так|этак|тогда|из)-(то|либо|нибудь|за)/gi,
798
+ `$1$2${import_glyphs6.DASHES.noBreakHyphen}$3`
799
+ ),
800
+ newRule(
801
+ "/russian/text/no-break-hyphen",
802
+ /(^|[^а-яА-ЯёЁ])(кое)-(кто|что|какой|где|куда|откуда|когда|как|зачем|почему)/gi,
803
+ `$1$2${import_glyphs6.DASHES.noBreakHyphen}$3`
804
+ ),
805
+ newRule(
806
+ "/russian/text/no-break-hyphen",
807
+ /(^|[^а-яА-ЯёЁ])(ну|скажи|пойди|дай|глянь|гляди|погоди|постой|поди|послушай|посмотри|вот|ничего|да|нет|полноте)-(ка|те|де|с|тка|тко|ста)/gi,
808
+ `$1$2${import_glyphs6.DASHES.noBreakHyphen}$3`
809
+ ),
810
+ newRule(
811
+ "/russian/text/no-break-hyphen",
812
+ /(^|[^а-яА-ЯёЁ])(все|всё|так|опять|довольно|[а-яА-ЯёЁ]+)-(таки)/gi,
813
+ `$1$2${import_glyphs6.DASHES.noBreakHyphen}$3`
814
+ ),
815
+ newRule("/russian/text/orphan-letters", /(?<![а-яА-ЯёЁ])([а-яА-ЯёЁ])\s/g, `$1${import_glyphs6.SPACES.noBreak}`)
816
+ ];
817
+
818
+ // src/typography/markup/index.ts
819
+ var markup_exports = {};
820
+ __export(markup_exports, {
821
+ common: () => common_default3,
822
+ en: () => en_default3,
823
+ ru: () => ru_default3
824
+ });
825
+
826
+ // src/typography/markup/common.ts
827
+ var import_functions4 = require("./functions/index.cjs");
828
+ var common_default3 = [
829
+ // HTML Wraps
830
+ // Chemical
831
+ newRule(
832
+ "/common/wraps/chem",
833
+ import_functions4.chemNotation,
834
+ [{ className: "@nkardaz-typography-chem" }],
835
+ Infinity
836
+ ),
837
+ // Wraps for ルビ, furigana
838
+ newRule(
839
+ "/common/wraps/ruby",
840
+ import_functions4.rubyText,
841
+ [{ marker: "?:" }, { className: "@nkardaz-typography-ruby --alternate" }],
842
+ Infinity
843
+ ),
844
+ newRule(
845
+ "/common/wraps/ruby",
846
+ import_functions4.rubyText,
847
+ [{ marker: "!:" }, { className: "@nkardaz-typography-ruby --under" }],
848
+ Infinity
849
+ ),
850
+ newRule(
851
+ "/common/wraps/ruby",
852
+ import_functions4.rubyText,
853
+ [{ marker: ":" }, { className: "@nkardaz-typography-ruby --over" }],
854
+ Infinity
855
+ ),
856
+ // Wraps for superscript and subscript
857
+ newRule(
858
+ "/common/wraps/sup",
859
+ import_functions4.wrapWithTag,
860
+ [{ marker: "^", tag: "sup" }, { className: "@nkardaz-typography-sup" }],
861
+ Infinity
862
+ ),
863
+ newRule(
864
+ "/common/wraps/sub",
865
+ import_functions4.wrapWithTag,
866
+ [{ marker: "_", tag: "sub" }, { className: "@nkardaz-typography-sub" }],
867
+ Infinity
868
+ )
869
+ ];
870
+
871
+ // src/typography/markup/en.ts
872
+ var en_default3 = [
873
+ // HTML Helpers
874
+ // newRule('/english/number/float-value', /(\d+)\\.(\d+)/g, '$1[^$2]'),
875
+ ];
876
+
877
+ // src/typography/markup/ru.ts
878
+ var ru_default3 = [
879
+ // HTML Helpers
880
+ // newRule('/russian/number/float-value', /(\d+),(\d+)/g, '$1[^$2]'),
881
+ ];
882
+
883
+ // src/api/rulesInit.ts
884
+ var defaultTypographyRules = {};
885
+ var defaultMarkupRules = {};
886
+ for (const [locale3, rules] of Object.entries(sets_exports)) {
887
+ defaultTypographyRules[locale3] = rules;
888
+ }
889
+ for (const [locale3, rules] of Object.entries(markup_exports)) {
890
+ defaultMarkupRules[locale3] = rules;
891
+ }
892
+ var defaultRuleKeys = Object.keys(
893
+ defaultTypographyRules
894
+ );
895
+ function initRules(defaults, from) {
896
+ const keys = from.length === 0 ? Object.keys(defaults) : from;
897
+ for (const key of keys) {
898
+ if (!typographyRules[key]) {
899
+ typographyRules[key] = [];
900
+ }
901
+ typographyRules[key].push(...defaults[key] ?? []);
902
+ }
903
+ }
904
+ function initTypographyRules(...from) {
905
+ initRules(defaultTypographyRules, from);
906
+ }
907
+ function initMarkupRules(...from) {
908
+ initRules(defaultMarkupRules, from);
909
+ }
910
+
911
+ // src/api/htmlNodes.ts
912
+ function htmlNode(text, { expression, nodes } = {}) {
913
+ if (!expression || !nodes) {
914
+ return [{ type: "text", value: text }];
915
+ }
916
+ const result = [];
917
+ let lastIndex = 0;
918
+ for (const match of text.matchAll(expression)) {
919
+ const matchStart = match.index;
920
+ if (matchStart > lastIndex) {
921
+ result.push({ type: "text", value: text.slice(lastIndex, matchStart) });
922
+ }
923
+ result.push(nodes(match));
924
+ lastIndex = matchStart + match[0].length;
925
+ }
926
+ if (lastIndex < text.length) {
927
+ result.push({ type: "text", value: text.slice(lastIndex) });
928
+ }
929
+ return result;
930
+ }
931
+ function renderNode(node) {
932
+ if (node.type === "text") {
933
+ return node.value;
934
+ }
935
+ const element = node;
936
+ const attrs = [];
937
+ if (element.className) {
938
+ attrs.push(`class="${element.className}"`);
939
+ }
940
+ if (element.attrs) {
941
+ for (const [name, value] of Object.entries(element.attrs)) {
942
+ attrs.push(`${name}="${value}"`);
943
+ }
944
+ }
945
+ const attrString = attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
946
+ const inner = element.children.map(renderNode).join("");
947
+ return `<${element.type}${attrString}>${inner}</${element.type}>`;
948
+ }
949
+ function renderNodes(nodes) {
950
+ return nodes.map(renderNode).join("");
951
+ }
952
+ function nodeToMdast(n) {
953
+ if (n.type === "text") {
954
+ return {
955
+ type: "text",
956
+ value: n.value
957
+ };
958
+ }
959
+ const element = n;
960
+ const attributes = [];
961
+ if (element.className) {
962
+ attributes.push({
963
+ type: "mdxJsxAttribute",
964
+ name: "className",
965
+ value: element.className
966
+ });
967
+ }
968
+ if (element.attrs) {
969
+ for (const [name, value] of Object.entries(element.attrs)) {
970
+ attributes.push({
971
+ type: "mdxJsxAttribute",
972
+ name,
973
+ value
974
+ });
975
+ }
976
+ }
977
+ return {
978
+ type: "mdxJsxTextElement",
979
+ name: element.type,
980
+ attributes,
981
+ children: element.children.map(nodeToMdast),
982
+ data: element.data
983
+ };
984
+ }
985
+ //# sourceMappingURL=index.cjs.map