@newlogic-digital/core 4.1.4 → 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/index.js +11 -0
- package/package.json +6 -1
- package/src/fontsManifest.js +97 -0
- package/types/index.d.ts +4 -0
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import process from 'node:process'
|
|
|
11
11
|
import heroicons from '@newlogic-digital/vite-plugin-heroicons'
|
|
12
12
|
import { fileURLToPath } from 'node:url'
|
|
13
13
|
import { processPostcssCustomProperties } from './src/postcssCustomProperties.js'
|
|
14
|
+
import { fontsManifest } from './src/fontsManifest.js'
|
|
14
15
|
import { createLogger } from 'vite'
|
|
15
16
|
import console from 'node:console'
|
|
16
17
|
|
|
@@ -76,6 +77,10 @@ const defaultOptions = {
|
|
|
76
77
|
},
|
|
77
78
|
tailwindcss: {},
|
|
78
79
|
send: {},
|
|
80
|
+
fontless: {
|
|
81
|
+
options: undefined,
|
|
82
|
+
manifest: undefined,
|
|
83
|
+
},
|
|
79
84
|
latte: {
|
|
80
85
|
globals: {
|
|
81
86
|
srcPath: resolve(process.cwd(), 'src'),
|
|
@@ -129,6 +134,12 @@ const plugin = async (options = {}) => {
|
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
|
|
137
|
+
if (options.fontless?.options) {
|
|
138
|
+
const { fontless } = await import('fontless')
|
|
139
|
+
|
|
140
|
+
optionalPlugins.push(fontless(options.fontless.options), fontsManifest(options.fontless.manifest))
|
|
141
|
+
}
|
|
142
|
+
|
|
132
143
|
if (options.cssInline.paths.length > 0) {
|
|
133
144
|
const cssInline = (await import('@vituum/vite-plugin-css-inline')).default
|
|
134
145
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newlogic-digital/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.6",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"newlogic-core": "./bin/newlogic-core.js"
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@tailwindcss/vite": "^4.2.4",
|
|
38
38
|
"@vituum/vite-plugin-twig": "^2.0.1",
|
|
39
|
+
"fontless": "^0.2.1",
|
|
39
40
|
"vite": "^8.0.10"
|
|
40
41
|
},
|
|
41
42
|
"peerDependenciesMeta": {
|
|
@@ -44,12 +45,16 @@
|
|
|
44
45
|
},
|
|
45
46
|
"@tailwindcss/vite": {
|
|
46
47
|
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"fontless": {
|
|
50
|
+
"optional": true
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
53
|
"devDependencies": {
|
|
50
54
|
"@tailwindcss/vite": "^4.3.0",
|
|
51
55
|
"@types/node": "^25.9",
|
|
52
56
|
"@vituum/vite-plugin-twig": "^2.0.1",
|
|
57
|
+
"fontless": "^0.2.1",
|
|
53
58
|
"rolldown": "^1.0.2",
|
|
54
59
|
"typescript": "^6"
|
|
55
60
|
},
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
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
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} rule
|
|
28
|
+
* @returns {string | null}
|
|
29
|
+
*/
|
|
30
|
+
const unicodeRangeSubset = (rule) => {
|
|
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))
|
|
38
|
+
|
|
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'
|
|
46
|
+
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Doplní cesty fontů do manifest.json (entry.assets + entry.fonts se subsetem),
|
|
52
|
+
* aby šly z PHP poslat jako Link hlavičky jen pro subsety daného jazyka
|
|
53
|
+
*
|
|
54
|
+
* @param {string[]} [families] - font families, které se mají includovat do manifestu (undefined = všechny)
|
|
55
|
+
* @returns {import('vite').Plugin}
|
|
56
|
+
*/
|
|
57
|
+
export const fontsManifest = families => ({
|
|
58
|
+
name: '@newlogic-digital/core:fonts-manifest',
|
|
59
|
+
apply: 'build',
|
|
60
|
+
async writeBundle(options, bundle) {
|
|
61
|
+
const manifestPath = join(options.dir ?? '', 'manifest.json')
|
|
62
|
+
const manifest = await readFile(manifestPath, 'utf8').then(JSON.parse).catch(() => null)
|
|
63
|
+
|
|
64
|
+
if (!manifest) return
|
|
65
|
+
|
|
66
|
+
let hasFonts = false
|
|
67
|
+
|
|
68
|
+
for (const entry of Object.values(manifest)) {
|
|
69
|
+
const asset = bundle[entry.file]
|
|
70
|
+
|
|
71
|
+
if (!entry.file?.endsWith('.css') || asset?.type !== 'asset') continue
|
|
72
|
+
|
|
73
|
+
const fonts = [...asset.source.toString().matchAll(/@font-face\s*\{[^}]*\}/g)]
|
|
74
|
+
.filter(([rule]) => !/font-style:\s*(italic|oblique)/.test(rule))
|
|
75
|
+
.map(([rule]) => ({
|
|
76
|
+
family: rule.match(/font-family:\s*(['"]?)([^;'"}]+)\1/)?.[2],
|
|
77
|
+
file: rule.match(/url\((['"]?)([^)'"]+)\1\)/)?.[2]?.replace(/^\//, ''),
|
|
78
|
+
subset: unicodeRangeSubset(rule),
|
|
79
|
+
}))
|
|
80
|
+
.filter(font => font.file && (!families || (font.family && families.includes(font.family))))
|
|
81
|
+
|
|
82
|
+
if (fonts.length === 0) continue
|
|
83
|
+
|
|
84
|
+
entry.assets = [...new Set([...entry.assets ?? [], ...fonts.map(font => font.file)])]
|
|
85
|
+
// rodina → subset → pole souborů; umožňuje preloadovat jen vybrané rodiny a subsety
|
|
86
|
+
entry.fonts = fonts.reduce((acc, font) => {
|
|
87
|
+
if (font.family && font.subset) ((acc[font.family] ??= {})[font.subset] ??= []).push(font.file)
|
|
88
|
+
return acc
|
|
89
|
+
}, {})
|
|
90
|
+
hasFonts = true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (hasFonts) {
|
|
94
|
+
await writeFile(manifestPath, JSON.stringify(manifest, null, 2))
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
})
|
package/types/index.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface PluginUserConfig {
|
|
|
15
15
|
cssInline?: import('@vituum/vite-plugin-css-inline').PluginUserConfig
|
|
16
16
|
send?: import('@vituum/vite-plugin-send').PluginUserConfig
|
|
17
17
|
tailwindcss?: import('@tailwindcss/vite').PluginOptions
|
|
18
|
+
fontless?: {
|
|
19
|
+
options?: import('fontless').FontlessOptions
|
|
20
|
+
manifest?: string[]
|
|
21
|
+
}
|
|
18
22
|
latte?: import('@vituum/vite-plugin-latte').PluginUserConfig
|
|
19
23
|
twig?: import('@vituum/vite-plugin-twig').PluginUserConfig
|
|
20
24
|
heroicons?: import('@newlogic-digital/vite-plugin-heroicons').HeroiconsOptions
|