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