@newlogic-digital/core 4.1.5 → 4.1.6

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@newlogic-digital/core",
3
3
  "type": "module",
4
- "version": "4.1.5",
4
+ "version": "4.1.6",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "newlogic-core": "./bin/newlogic-core.js"
@@ -1,21 +1,48 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises'
2
2
  import { join } from 'node:path'
3
3
 
4
+ /**
5
+ * Parsuje unicode-range na číselné intervaly [start, end] - minifikátory zápis normalizují
6
+ * (Lightning CSS ve Vite 8 stripuje nuly a používá wildcardy, např. U+0000-00FF → U+??)
7
+ *
8
+ * @param {string} rule
9
+ * @returns {[number, number][]}
10
+ */
11
+ const parseUnicodeRange = (rule) => {
12
+ const range = (rule.match(/unicode-range:([^;}]+)/i)?.[1] ?? '').toUpperCase()
13
+
14
+ return range.split(',').flatMap((token) => {
15
+ const match = token.trim().match(/^U\+([0-9A-F?]+)(?:-([0-9A-F]+))?$/)
16
+
17
+ if (!match) return []
18
+ if (match[1].includes('?')) {
19
+ return [[parseInt(match[1].replace(/\?/g, '0'), 16), parseInt(match[1].replace(/\?/g, 'F'), 16)]]
20
+ }
21
+
22
+ return [[parseInt(match[1], 16), parseInt(match[2] ?? match[1], 16)]]
23
+ })
24
+ }
25
+
4
26
  /**
5
27
  * @param {string} rule
6
28
  * @returns {string | null}
7
29
  */
8
30
  const unicodeRangeSubset = (rule) => {
9
- // toUpperCase kvůli minifikátorům, které zápis normalizují na lowercase (Lightning CSS ve Vite 8)
10
- const range = (rule.match(/unicode-range:([^;}]+)/i)?.[1] ?? '').toUpperCase()
31
+ const ranges = parseUnicodeRange(rule)
32
+
33
+ /**
34
+ * @param {number} start
35
+ * @param {number} [end]
36
+ */
37
+ const has = (start, end) => ranges.some(([rangeStart, rangeEnd]) => rangeStart === start && (end === undefined || rangeEnd === end))
11
38
 
12
- if (range.includes('U+0000-00FF')) return 'latin'
13
- if (range.includes('U+0102-')) return 'vietnamese'
14
- if (range.includes('U+0100-')) return 'latin-ext'
15
- if (range.includes('U+0400-045F')) return 'cyrillic'
16
- if (range.includes('U+0460-052F')) return 'cyrillic-ext'
17
- if (range.includes('U+1F00-1FFF')) return 'greek-ext'
18
- if (range.includes('U+0370-')) return 'greek'
39
+ if (has(0x0000, 0x00FF)) return 'latin'
40
+ if (has(0x0102)) return 'vietnamese'
41
+ if (has(0x0100)) return 'latin-ext'
42
+ if (has(0x0400, 0x045F)) return 'cyrillic'
43
+ if (has(0x0460, 0x052F)) return 'cyrillic-ext'
44
+ if (has(0x1F00, 0x1FFF)) return 'greek-ext'
45
+ if (has(0x0370)) return 'greek'
19
46
 
20
47
  return null
21
48
  }