@newlogic-digital/core 4.1.3 → 4.1.5

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 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
 
@@ -43,7 +44,7 @@ const defaultOptions = {
43
44
  mode: null,
44
45
  cert: 'localhost',
45
46
  format: ['latte'],
46
- codeSplitting: {},
47
+ codeSplitting: undefined,
47
48
  input: {
48
49
  assets: [
49
50
  './src/styles/*.{css,pcss,scss,sass,less,styl,stylus}',
@@ -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
 
@@ -271,15 +282,18 @@ const plugin = async (options = {}) => {
271
282
  groups: [
272
283
  {
273
284
  name: 'swup',
274
- test: /swup/,
285
+ test: /node_modules[\\/]swup(?:[\\/]|$)/,
286
+ priority: 30,
275
287
  },
276
288
  {
277
- name: '@hotwired/stimulus',
278
- test: /@hotwired\/stimulus/,
289
+ name: 'hotwired-stimulus',
290
+ test: /node_modules[\\/]@hotwired[\\/]stimulus(?:[\\/]|$)/,
291
+ priority: 30,
279
292
  },
280
293
  {
281
294
  name: 'naja',
282
- test: /naja/,
295
+ test: /node_modules[\\/]naja(?:[\\/]|$)/,
296
+ priority: 30,
283
297
  },
284
298
  ],
285
299
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@newlogic-digital/core",
3
3
  "type": "module",
4
- "version": "4.1.3",
4
+ "version": "4.1.5",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "newlogic-core": "./bin/newlogic-core.js"
@@ -28,7 +28,7 @@
28
28
  "browserslist-to-esbuild": "^2.1.1",
29
29
  "lightningcss": "^1.32.0",
30
30
  "npm-check-updates": "^22.2.0",
31
- "oxlint": "^1.65.0",
31
+ "oxlint": "^1.66.0",
32
32
  "postcss-custom-properties": "^15.0.1",
33
33
  "stylelint-config-standard": "^40.0.0",
34
34
  "vituum": "^2.0.2"
@@ -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,13 +45,17 @@
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
- "@types/node": "^25.8",
55
+ "@types/node": "^25.9",
52
56
  "@vituum/vite-plugin-twig": "^2.0.1",
53
- "rolldown": "^1.0.1",
57
+ "fontless": "^0.2.1",
58
+ "rolldown": "^1.0.2",
54
59
  "typescript": "^6"
55
60
  },
56
61
  "files": [
package/src/+.css ADDED
@@ -0,0 +1 @@
1
+ @import "./styles/main.css";
@@ -0,0 +1,70 @@
1
+ import { readFile, writeFile } from 'node:fs/promises'
2
+ import { join } from 'node:path'
3
+
4
+ /**
5
+ * @param {string} rule
6
+ * @returns {string | null}
7
+ */
8
+ 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()
11
+
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'
19
+
20
+ return null
21
+ }
22
+
23
+ /**
24
+ * Doplní cesty fontů do manifest.json (entry.assets + entry.fonts se subsetem),
25
+ * aby šly z PHP poslat jako Link hlavičky jen pro subsety daného jazyka
26
+ *
27
+ * @param {string[]} [families] - font families, které se mají includovat do manifestu (undefined = všechny)
28
+ * @returns {import('vite').Plugin}
29
+ */
30
+ export const fontsManifest = families => ({
31
+ name: '@newlogic-digital/core:fonts-manifest',
32
+ apply: 'build',
33
+ async writeBundle(options, bundle) {
34
+ const manifestPath = join(options.dir ?? '', 'manifest.json')
35
+ const manifest = await readFile(manifestPath, 'utf8').then(JSON.parse).catch(() => null)
36
+
37
+ if (!manifest) return
38
+
39
+ let hasFonts = false
40
+
41
+ for (const entry of Object.values(manifest)) {
42
+ const asset = bundle[entry.file]
43
+
44
+ if (!entry.file?.endsWith('.css') || asset?.type !== 'asset') continue
45
+
46
+ const fonts = [...asset.source.toString().matchAll(/@font-face\s*\{[^}]*\}/g)]
47
+ .filter(([rule]) => !/font-style:\s*(italic|oblique)/.test(rule))
48
+ .map(([rule]) => ({
49
+ family: rule.match(/font-family:\s*(['"]?)([^;'"}]+)\1/)?.[2],
50
+ file: rule.match(/url\((['"]?)([^)'"]+)\1\)/)?.[2]?.replace(/^\//, ''),
51
+ subset: unicodeRangeSubset(rule),
52
+ }))
53
+ .filter(font => font.file && (!families || (font.family && families.includes(font.family))))
54
+
55
+ if (fonts.length === 0) continue
56
+
57
+ entry.assets = [...new Set([...entry.assets ?? [], ...fonts.map(font => font.file)])]
58
+ // rodina → subset → pole souborů; umožňuje preloadovat jen vybrané rodiny a subsety
59
+ entry.fonts = fonts.reduce((acc, font) => {
60
+ if (font.family && font.subset) ((acc[font.family] ??= {})[font.subset] ??= []).push(font.file)
61
+ return acc
62
+ }, {})
63
+ hasFonts = true
64
+ }
65
+
66
+ if (hasFonts) {
67
+ await writeFile(manifestPath, JSON.stringify(manifest, null, 2))
68
+ }
69
+ },
70
+ })
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