jskelet 0.2.4 → 0.2.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/AGENTS.md +132 -132
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -21
- package/bin/jskelet.mjs +103 -103
- package/docs/01-baslangic.md +285 -285
- package/docs/02-mimari.md +287 -287
- package/docs/03-routing.md +480 -480
- package/docs/04-render-ve-sablonlar.md +490 -490
- package/docs/05-islands.md +482 -482
- package/docs/06-cache.md +1209 -1209
- package/docs/08-build.md +366 -366
- package/docs/09-dev-araclari.md +335 -335
- package/docs/10-dagitim.md +329 -329
- package/docs/12-panel-ve-oturum.md +384 -384
- package/docs/README.md +105 -105
- package/docs/en/01-getting-started.md +292 -292
- package/docs/en/02-architecture.md +305 -305
- package/docs/en/03-routing.md +497 -497
- package/docs/en/04-rendering.md +504 -504
- package/docs/en/05-islands.md +492 -492
- package/docs/en/06-caching.md +1239 -1239
- package/docs/en/07-configuration.md +986 -986
- package/docs/en/08-build.md +383 -383
- package/docs/en/09-dev-tools.md +342 -342
- package/docs/en/10-deployment.md +332 -332
- package/docs/en/11-migration.md +359 -359
- package/docs/en/12-dashboards-and-sessions.md +392 -392
- package/docs/en/README.md +112 -112
- package/package.json +102 -102
- package/src/build/ensure-build.mjs +15 -15
- package/src/build/paths.mjs +143 -143
- package/src/build/resolve-peer.mjs +36 -36
- package/src/build/tasks/client.mjs +268 -268
- package/src/build/tasks/css.mjs +124 -124
- package/src/build/tasks/fonts.mjs +146 -146
- package/src/build/tasks/icons.mjs +224 -224
- package/src/build/tasks/images.mjs +244 -244
- package/src/build/tasks/precompress.mjs +78 -78
- package/src/client/cache-panel/i18n.js +670 -670
- package/src/client/cache-panel/login.html +74 -74
- package/src/client/cache-panel/panel.css +756 -756
- package/src/client/cache-panel/panel.html +308 -308
- package/src/client/cache-panel/panel.js +915 -915
- package/src/client/devtools/report.html +185 -185
- package/src/client/devtools/report.js +725 -725
- package/src/client/dom.js +95 -95
- package/src/client/form.js +192 -192
- package/src/client/index.js +35 -35
- package/src/client/registry.js +297 -297
- package/src/client/safe-image.js +91 -91
- package/src/client/store.js +36 -36
- package/src/client/swap.js +188 -188
- package/src/config/pattern.js +107 -107
- package/src/http/control-flow.js +71 -71
- package/src/http/cookies.js +257 -257
- package/src/http/request-cache.js +46 -46
- package/src/http/request-context.js +162 -162
- package/src/index.js +83 -83
- package/src/init.mjs +221 -221
- package/src/runtime/alias-hooks.mjs +119 -119
- package/src/runtime/register.mjs +4 -4
- package/src/server/assets.js +147 -147
- package/src/server/cache-deps.js +42 -42
- package/src/server/cache-panel.js +759 -759
- package/src/server/cloudflare.js +607 -595
- package/src/server/create-app.js +291 -291
- package/src/server/data-cache.js +462 -462
- package/src/server/dev/report.js +369 -369
- package/src/server/dev/socket.js +170 -170
- package/src/server/dev/version-check.mjs +139 -139
- package/src/server/html-cache.js +817 -817
- package/src/server/metadata.js +102 -102
- package/src/server/middleware/compression.js +205 -205
- package/src/server/middleware/csrf.js +134 -134
- package/src/server/middleware/dev-gate.js +62 -62
- package/src/server/middleware/headers.js +37 -37
- package/src/server/middleware/redirects.js +32 -32
- package/src/server/middleware/static-precompressed.js +100 -100
- package/src/server/middleware/upstream-proxy.js +141 -141
- package/src/server/prewarm.js +601 -601
- package/src/server/redis.js +569 -569
- package/src/server/router.js +128 -128
- package/src/server/status-page.js +164 -164
- package/src/server/upstream-limiter.js +376 -376
- package/src/server/upstream-tracking.js +166 -166
- package/src/start.mjs +7 -7
- package/src/templates/layout.ejs +44 -44
- package/src/version.mjs +31 -31
- package/src/views/components/loader.js +85 -85
- package/src/views/helpers/html.js +102 -102
- package/src/views/helpers/tags.js +245 -245
|
@@ -1,224 +1,224 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phosphor SVG sprite üretimi.
|
|
3
|
-
*
|
|
4
|
-
* `@phosphor-icons/core` içindeki tek tek SVG'lerden, **yalnızca kaynakta
|
|
5
|
-
* kullanılan** ikonlar için `<symbol>` seti üretir. Tüm seti göndermek 1500+
|
|
6
|
-
* ikon, yani birkaç megabayt; kullanım taraması sprite'ı tipik olarak 10-30
|
|
7
|
-
* sembolde tutuyor.
|
|
8
|
-
*
|
|
9
|
-
* Sembol id'si: `<kebab-name>-<weight>` (örn. `arrow-right-bold`).
|
|
10
|
-
*
|
|
11
|
-
* Tarama statik metin üzerinden yapıldığı için adı çalışma anında hesaplanan
|
|
12
|
-
* bir `icon()` çağrısı sprite'a girmez. Bu yüzden ad taşıyan yapılandırma
|
|
13
|
-
* alanları (`icon: "XLogo"`) da ayrıca aranır ve `views/helpers/tags.js`
|
|
14
|
-
* dev'de eksik sembol için uyarır.
|
|
15
|
-
*/
|
|
16
|
-
import fs from "node:fs";
|
|
17
|
-
import path from "node:path";
|
|
18
|
-
import { createRequire } from "node:module";
|
|
19
|
-
import { pruneAssets, writeAsset } from "../paths.mjs";
|
|
20
|
-
import * as log from "../../log.mjs";
|
|
21
|
-
|
|
22
|
-
const SCAN_EXTENSIONS = new Set([".ejs", ".js", ".mjs"]);
|
|
23
|
-
|
|
24
|
-
/** `icon({ … })` çağrısının tamamı; `name:` ifadesi ayrıca çözümlenir. */
|
|
25
|
-
const ICON_CALL = /icon\(\s*\{([^}]*)\}/g;
|
|
26
|
-
const ICON_NAME_EXPR = /name:\s*([^,}]+)/;
|
|
27
|
-
const ICON_WEIGHT = /weight:\s*["']([^"']+)["']/;
|
|
28
|
-
/** `data-icon="flag:fill"` ve JS nesnesindeki `"data-icon": "flag:fill"`. */
|
|
29
|
-
const ICON_ATTR = /data-icon"?\s*[:=]\s*["']([a-z0-9-]+)(?::([a-z]+))?["']/g;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* İkon adı `icon()` çağrısına değişkenle geldiğinde (ör. `name: item.icon`)
|
|
33
|
-
* ad statik olarak görünmez. Bu tür adlar yapılandırma listelerinde
|
|
34
|
-
* `icon: "XLogo"` / `iconName: "XLogo"` biçiminde durur; sprite'a girmezlerse
|
|
35
|
-
* `<use>` boş kalır ve ikon görünmez.
|
|
36
|
-
*/
|
|
37
|
-
const ICON_NAME_PROP = /\b(?:icon|iconName)\s*[:=]\s*["']([A-Z][A-Za-z0-9]*)["']/g;
|
|
38
|
-
|
|
39
|
-
/** Adın içinden çıkarılabilecek sabitler: `"X"`, `cond ? "A" : "B"`. */
|
|
40
|
-
const QUOTED_NAME = /["']([A-Z][A-Za-z0-9]*)["']/g;
|
|
41
|
-
|
|
42
|
-
const WEIGHTS = new Set(["thin", "light", "regular", "bold", "fill", "duotone"]);
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* `ArrowRightIcon` → `arrow-right`
|
|
46
|
-
* @param {string} name
|
|
47
|
-
* @returns {string}
|
|
48
|
-
*/
|
|
49
|
-
function toKebab(name) {
|
|
50
|
-
return String(name)
|
|
51
|
-
.replace(/Icon$/, "")
|
|
52
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
53
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2")
|
|
54
|
-
.toLowerCase();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Paket, framework'ün değil **uygulamanın** node_modules'ünden çözülür:
|
|
59
|
-
* ikon seti uygulamanın devDependency'si.
|
|
60
|
-
*
|
|
61
|
-
* @param {string} root
|
|
62
|
-
* @returns {string | null}
|
|
63
|
-
*/
|
|
64
|
-
function resolveIconAssets(root) {
|
|
65
|
-
const require = createRequire(path.join(root, "package.json"));
|
|
66
|
-
|
|
67
|
-
// Paketin `exports` haritası `./package.json` alt yolunu açmıyor, bu yüzden
|
|
68
|
-
// bilinen bir asset dosyası üzerinden çözülür.
|
|
69
|
-
try {
|
|
70
|
-
const probe = require.resolve(
|
|
71
|
-
"@phosphor-icons/core/assets/regular/house.svg",
|
|
72
|
-
);
|
|
73
|
-
return path.dirname(path.dirname(probe));
|
|
74
|
-
} catch {
|
|
75
|
-
// exports kapalıysa klasörü doğrudan ara.
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const direct = path.join(
|
|
79
|
-
root,
|
|
80
|
-
"node_modules",
|
|
81
|
-
"@phosphor-icons",
|
|
82
|
-
"core",
|
|
83
|
-
"assets",
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
return fs.existsSync(direct) ? direct : null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @param {string} dir
|
|
91
|
-
* @param {string[]} out
|
|
92
|
-
* @returns {string[]}
|
|
93
|
-
*/
|
|
94
|
-
function collectFiles(dir, out = []) {
|
|
95
|
-
if (!fs.existsSync(dir)) return out;
|
|
96
|
-
|
|
97
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
98
|
-
const full = path.join(dir, entry.name);
|
|
99
|
-
if (entry.isDirectory()) {
|
|
100
|
-
collectFiles(full, out);
|
|
101
|
-
} else if (SCAN_EXTENSIONS.has(path.extname(entry.name))) {
|
|
102
|
-
out.push(full);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @param {string[]} scanDirs
|
|
111
|
-
* @returns {Set<string>} `name:weight` çiftleri
|
|
112
|
-
*/
|
|
113
|
-
function scanUsedIcons(scanDirs) {
|
|
114
|
-
/** @type {Set<string>} */
|
|
115
|
-
const used = new Set();
|
|
116
|
-
|
|
117
|
-
// Adı değişkenle gelen çağrıların ağırlıkları: dolaylı bulunan adlar
|
|
118
|
-
// yalnızca bu ağırlıklarda üretilir, sprite gereksiz büyümez.
|
|
119
|
-
/** @type {Set<string>} */
|
|
120
|
-
const dynamicWeights = new Set();
|
|
121
|
-
|
|
122
|
-
/** @type {Set<string>} */
|
|
123
|
-
const indirectNames = new Set();
|
|
124
|
-
|
|
125
|
-
for (const dir of scanDirs) {
|
|
126
|
-
for (const file of collectFiles(dir)) {
|
|
127
|
-
const source = fs.readFileSync(file, "utf8");
|
|
128
|
-
|
|
129
|
-
for (const match of source.matchAll(ICON_CALL)) {
|
|
130
|
-
const raw = match[1].match(ICON_WEIGHT)?.[1] ?? "regular";
|
|
131
|
-
const weight = WEIGHTS.has(raw) ? raw : "regular";
|
|
132
|
-
const expression = match[1].match(ICON_NAME_EXPR)?.[1] ?? "";
|
|
133
|
-
const names = [...expression.matchAll(QUOTED_NAME)].map((m) => m[1]);
|
|
134
|
-
|
|
135
|
-
if (!names.length) {
|
|
136
|
-
dynamicWeights.add(weight);
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
for (const name of names) used.add(`${toKebab(name)}:${weight}`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
for (const match of source.matchAll(ICON_NAME_PROP)) {
|
|
144
|
-
indirectNames.add(toKebab(match[1]));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
for (const match of source.matchAll(ICON_ATTR)) {
|
|
148
|
-
const weight = match[2] ?? "regular";
|
|
149
|
-
used.add(`${match[1]}:${WEIGHTS.has(weight) ? weight : "regular"}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!dynamicWeights.size) dynamicWeights.add("regular");
|
|
155
|
-
|
|
156
|
-
for (const name of indirectNames) {
|
|
157
|
-
for (const weight of dynamicWeights) used.add(`${name}:${weight}`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return used;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* @param {string} coreAssets
|
|
165
|
-
* @param {string} name kebab
|
|
166
|
-
* @param {string} weight
|
|
167
|
-
* @returns {string | null}
|
|
168
|
-
*/
|
|
169
|
-
function readIconBody(coreAssets, name, weight) {
|
|
170
|
-
const fileName = weight === "regular" ? `${name}.svg` : `${name}-${weight}.svg`;
|
|
171
|
-
const filePath = path.join(coreAssets, weight, fileName);
|
|
172
|
-
|
|
173
|
-
if (!fs.existsSync(filePath)) return null;
|
|
174
|
-
|
|
175
|
-
const svg = fs.readFileSync(filePath, "utf8");
|
|
176
|
-
const inner = svg.replace(/^[\s\S]*?<svg[^>]*>/, "").replace(/<\/svg>\s*$/, "");
|
|
177
|
-
return inner.trim();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @param {import('../../config/index.js').ResolvedConfig} config
|
|
182
|
-
* @returns {Promise<Record<string, string>>}
|
|
183
|
-
*/
|
|
184
|
-
export async function buildIconSprite(config) {
|
|
185
|
-
const coreAssets = resolveIconAssets(config.root);
|
|
186
|
-
if (!coreAssets) {
|
|
187
|
-
log.detail("@phosphor-icons/core not installed, skipped");
|
|
188
|
-
return {};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const scanDirs = (
|
|
192
|
-
config.icons?.scan ?? ["views", "client", "routes", "lib"]
|
|
193
|
-
).map((dir) => path.resolve(config.root, dir));
|
|
194
|
-
|
|
195
|
-
pruneAssets(["sprite."]);
|
|
196
|
-
|
|
197
|
-
const used = [...scanUsedIcons(scanDirs)].sort();
|
|
198
|
-
const symbols = [];
|
|
199
|
-
const missing = [];
|
|
200
|
-
|
|
201
|
-
for (const entry of used) {
|
|
202
|
-
const [name, weight] = entry.split(":");
|
|
203
|
-
const body = readIconBody(coreAssets, name, weight);
|
|
204
|
-
|
|
205
|
-
if (!body) {
|
|
206
|
-
missing.push(entry);
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
symbols.push(
|
|
211
|
-
`<symbol id="${name}-${weight}" viewBox="0 0 256 256">${body}</symbol>`,
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const sprite = `<svg xmlns="http://www.w3.org/2000/svg" style="display:none">${symbols.join("")}</svg>`;
|
|
216
|
-
const url = writeAsset("sprite.svg", sprite);
|
|
217
|
-
|
|
218
|
-
log.detail(`${symbols.length} symbols`);
|
|
219
|
-
if (missing.length) {
|
|
220
|
-
log.warn(`${missing.length} icons missing → ${missing.join(", ")}`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return { "sprite.svg": url };
|
|
224
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Phosphor SVG sprite üretimi.
|
|
3
|
+
*
|
|
4
|
+
* `@phosphor-icons/core` içindeki tek tek SVG'lerden, **yalnızca kaynakta
|
|
5
|
+
* kullanılan** ikonlar için `<symbol>` seti üretir. Tüm seti göndermek 1500+
|
|
6
|
+
* ikon, yani birkaç megabayt; kullanım taraması sprite'ı tipik olarak 10-30
|
|
7
|
+
* sembolde tutuyor.
|
|
8
|
+
*
|
|
9
|
+
* Sembol id'si: `<kebab-name>-<weight>` (örn. `arrow-right-bold`).
|
|
10
|
+
*
|
|
11
|
+
* Tarama statik metin üzerinden yapıldığı için adı çalışma anında hesaplanan
|
|
12
|
+
* bir `icon()` çağrısı sprite'a girmez. Bu yüzden ad taşıyan yapılandırma
|
|
13
|
+
* alanları (`icon: "XLogo"`) da ayrıca aranır ve `views/helpers/tags.js`
|
|
14
|
+
* dev'de eksik sembol için uyarır.
|
|
15
|
+
*/
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
import { pruneAssets, writeAsset } from "../paths.mjs";
|
|
20
|
+
import * as log from "../../log.mjs";
|
|
21
|
+
|
|
22
|
+
const SCAN_EXTENSIONS = new Set([".ejs", ".js", ".mjs"]);
|
|
23
|
+
|
|
24
|
+
/** `icon({ … })` çağrısının tamamı; `name:` ifadesi ayrıca çözümlenir. */
|
|
25
|
+
const ICON_CALL = /icon\(\s*\{([^}]*)\}/g;
|
|
26
|
+
const ICON_NAME_EXPR = /name:\s*([^,}]+)/;
|
|
27
|
+
const ICON_WEIGHT = /weight:\s*["']([^"']+)["']/;
|
|
28
|
+
/** `data-icon="flag:fill"` ve JS nesnesindeki `"data-icon": "flag:fill"`. */
|
|
29
|
+
const ICON_ATTR = /data-icon"?\s*[:=]\s*["']([a-z0-9-]+)(?::([a-z]+))?["']/g;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* İkon adı `icon()` çağrısına değişkenle geldiğinde (ör. `name: item.icon`)
|
|
33
|
+
* ad statik olarak görünmez. Bu tür adlar yapılandırma listelerinde
|
|
34
|
+
* `icon: "XLogo"` / `iconName: "XLogo"` biçiminde durur; sprite'a girmezlerse
|
|
35
|
+
* `<use>` boş kalır ve ikon görünmez.
|
|
36
|
+
*/
|
|
37
|
+
const ICON_NAME_PROP = /\b(?:icon|iconName)\s*[:=]\s*["']([A-Z][A-Za-z0-9]*)["']/g;
|
|
38
|
+
|
|
39
|
+
/** Adın içinden çıkarılabilecek sabitler: `"X"`, `cond ? "A" : "B"`. */
|
|
40
|
+
const QUOTED_NAME = /["']([A-Z][A-Za-z0-9]*)["']/g;
|
|
41
|
+
|
|
42
|
+
const WEIGHTS = new Set(["thin", "light", "regular", "bold", "fill", "duotone"]);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* `ArrowRightIcon` → `arrow-right`
|
|
46
|
+
* @param {string} name
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
function toKebab(name) {
|
|
50
|
+
return String(name)
|
|
51
|
+
.replace(/Icon$/, "")
|
|
52
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
53
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2")
|
|
54
|
+
.toLowerCase();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Paket, framework'ün değil **uygulamanın** node_modules'ünden çözülür:
|
|
59
|
+
* ikon seti uygulamanın devDependency'si.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} root
|
|
62
|
+
* @returns {string | null}
|
|
63
|
+
*/
|
|
64
|
+
function resolveIconAssets(root) {
|
|
65
|
+
const require = createRequire(path.join(root, "package.json"));
|
|
66
|
+
|
|
67
|
+
// Paketin `exports` haritası `./package.json` alt yolunu açmıyor, bu yüzden
|
|
68
|
+
// bilinen bir asset dosyası üzerinden çözülür.
|
|
69
|
+
try {
|
|
70
|
+
const probe = require.resolve(
|
|
71
|
+
"@phosphor-icons/core/assets/regular/house.svg",
|
|
72
|
+
);
|
|
73
|
+
return path.dirname(path.dirname(probe));
|
|
74
|
+
} catch {
|
|
75
|
+
// exports kapalıysa klasörü doğrudan ara.
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const direct = path.join(
|
|
79
|
+
root,
|
|
80
|
+
"node_modules",
|
|
81
|
+
"@phosphor-icons",
|
|
82
|
+
"core",
|
|
83
|
+
"assets",
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return fs.existsSync(direct) ? direct : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {string} dir
|
|
91
|
+
* @param {string[]} out
|
|
92
|
+
* @returns {string[]}
|
|
93
|
+
*/
|
|
94
|
+
function collectFiles(dir, out = []) {
|
|
95
|
+
if (!fs.existsSync(dir)) return out;
|
|
96
|
+
|
|
97
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
98
|
+
const full = path.join(dir, entry.name);
|
|
99
|
+
if (entry.isDirectory()) {
|
|
100
|
+
collectFiles(full, out);
|
|
101
|
+
} else if (SCAN_EXTENSIONS.has(path.extname(entry.name))) {
|
|
102
|
+
out.push(full);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {string[]} scanDirs
|
|
111
|
+
* @returns {Set<string>} `name:weight` çiftleri
|
|
112
|
+
*/
|
|
113
|
+
function scanUsedIcons(scanDirs) {
|
|
114
|
+
/** @type {Set<string>} */
|
|
115
|
+
const used = new Set();
|
|
116
|
+
|
|
117
|
+
// Adı değişkenle gelen çağrıların ağırlıkları: dolaylı bulunan adlar
|
|
118
|
+
// yalnızca bu ağırlıklarda üretilir, sprite gereksiz büyümez.
|
|
119
|
+
/** @type {Set<string>} */
|
|
120
|
+
const dynamicWeights = new Set();
|
|
121
|
+
|
|
122
|
+
/** @type {Set<string>} */
|
|
123
|
+
const indirectNames = new Set();
|
|
124
|
+
|
|
125
|
+
for (const dir of scanDirs) {
|
|
126
|
+
for (const file of collectFiles(dir)) {
|
|
127
|
+
const source = fs.readFileSync(file, "utf8");
|
|
128
|
+
|
|
129
|
+
for (const match of source.matchAll(ICON_CALL)) {
|
|
130
|
+
const raw = match[1].match(ICON_WEIGHT)?.[1] ?? "regular";
|
|
131
|
+
const weight = WEIGHTS.has(raw) ? raw : "regular";
|
|
132
|
+
const expression = match[1].match(ICON_NAME_EXPR)?.[1] ?? "";
|
|
133
|
+
const names = [...expression.matchAll(QUOTED_NAME)].map((m) => m[1]);
|
|
134
|
+
|
|
135
|
+
if (!names.length) {
|
|
136
|
+
dynamicWeights.add(weight);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
for (const name of names) used.add(`${toKebab(name)}:${weight}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
for (const match of source.matchAll(ICON_NAME_PROP)) {
|
|
144
|
+
indirectNames.add(toKebab(match[1]));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
for (const match of source.matchAll(ICON_ATTR)) {
|
|
148
|
+
const weight = match[2] ?? "regular";
|
|
149
|
+
used.add(`${match[1]}:${WEIGHTS.has(weight) ? weight : "regular"}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!dynamicWeights.size) dynamicWeights.add("regular");
|
|
155
|
+
|
|
156
|
+
for (const name of indirectNames) {
|
|
157
|
+
for (const weight of dynamicWeights) used.add(`${name}:${weight}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return used;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {string} coreAssets
|
|
165
|
+
* @param {string} name kebab
|
|
166
|
+
* @param {string} weight
|
|
167
|
+
* @returns {string | null}
|
|
168
|
+
*/
|
|
169
|
+
function readIconBody(coreAssets, name, weight) {
|
|
170
|
+
const fileName = weight === "regular" ? `${name}.svg` : `${name}-${weight}.svg`;
|
|
171
|
+
const filePath = path.join(coreAssets, weight, fileName);
|
|
172
|
+
|
|
173
|
+
if (!fs.existsSync(filePath)) return null;
|
|
174
|
+
|
|
175
|
+
const svg = fs.readFileSync(filePath, "utf8");
|
|
176
|
+
const inner = svg.replace(/^[\s\S]*?<svg[^>]*>/, "").replace(/<\/svg>\s*$/, "");
|
|
177
|
+
return inner.trim();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @param {import('../../config/index.js').ResolvedConfig} config
|
|
182
|
+
* @returns {Promise<Record<string, string>>}
|
|
183
|
+
*/
|
|
184
|
+
export async function buildIconSprite(config) {
|
|
185
|
+
const coreAssets = resolveIconAssets(config.root);
|
|
186
|
+
if (!coreAssets) {
|
|
187
|
+
log.detail("@phosphor-icons/core not installed, skipped");
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const scanDirs = (
|
|
192
|
+
config.icons?.scan ?? ["views", "client", "routes", "lib"]
|
|
193
|
+
).map((dir) => path.resolve(config.root, dir));
|
|
194
|
+
|
|
195
|
+
pruneAssets(["sprite."]);
|
|
196
|
+
|
|
197
|
+
const used = [...scanUsedIcons(scanDirs)].sort();
|
|
198
|
+
const symbols = [];
|
|
199
|
+
const missing = [];
|
|
200
|
+
|
|
201
|
+
for (const entry of used) {
|
|
202
|
+
const [name, weight] = entry.split(":");
|
|
203
|
+
const body = readIconBody(coreAssets, name, weight);
|
|
204
|
+
|
|
205
|
+
if (!body) {
|
|
206
|
+
missing.push(entry);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
symbols.push(
|
|
211
|
+
`<symbol id="${name}-${weight}" viewBox="0 0 256 256">${body}</symbol>`,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const sprite = `<svg xmlns="http://www.w3.org/2000/svg" style="display:none">${symbols.join("")}</svg>`;
|
|
216
|
+
const url = writeAsset("sprite.svg", sprite);
|
|
217
|
+
|
|
218
|
+
log.detail(`${symbols.length} symbols`);
|
|
219
|
+
if (missing.length) {
|
|
220
|
+
log.warn(`${missing.length} icons missing → ${missing.join(", ")}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return { "sprite.svg": url };
|
|
224
|
+
}
|