kss-modern 1.2.0-beta.4 → 1.2.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/dist/node/lib/index.mjs +43 -48
- package/dist/node/lib/pug/worker.d.mts +0 -12
- package/dist/node/lib/pug/worker.d.ts +0 -12
- package/dist/node/lib/pug/worker.mjs +3 -4
- package/dist/node/shared/{kss-modern.o1Fp758z.mjs → kss-modern.B6jgUPtu.mjs} +13 -44
- package/dist/styleguide-assets/.vite/manifest.json +5 -4
- package/dist/styleguide-assets/fullpage-CGBSSxKh.js +332 -0
- package/dist/styleguide-assets/kss-modern-3dYdkdaU.css +3 -0
- package/dist/styleguide-assets/preview-B-NERQ5n.js +1138 -0
- package/package.json +2 -1
- package/dist/styleguide-assets/fullpage-CzaJFxfS.js +0 -177
- package/dist/styleguide-assets/kss-modern-DW2ZdZvd.css +0 -3
- package/dist/styleguide-assets/preview-ChQyjhUb.js +0 -680
package/dist/node/lib/index.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
2
|
import process from 'node:process';
|
|
4
3
|
import { fileURLToPath } from 'node:url';
|
|
5
4
|
import fs from 'fs-extra';
|
|
6
5
|
import { glob } from 'tinyglobby';
|
|
7
|
-
import { l as logger, s as sanitizeSpecialCharacters, I as INSERT_VITE_PUG_TAG_RE, P as PUG_SRC_RE, a as PUG_ERROR_OVERLAY_TAG, c as compileMarkup, p as pugErrorFile, b as
|
|
8
|
-
export {
|
|
6
|
+
import { l as logger, s as sanitizeSpecialCharacters, I as INSERT_VITE_PUG_TAG_RE, P as PUG_SRC_RE, a as PUG_ERROR_OVERLAY_TAG, c as compileMarkup, p as pugErrorFile, b as slugify, d as sectionSanitizeId, e as stripPugErrorOverlay, f as ensureStartingSlash, g as generateId, r as replaceWrapperContent, h as htmlToSearchText } from '../shared/kss-modern.B6jgUPtu.mjs';
|
|
7
|
+
export { i as createLogger } from '../shared/kss-modern.B6jgUPtu.mjs';
|
|
9
8
|
import htmlLang from '@shikijs/langs/html';
|
|
10
9
|
import markdownLang from '@shikijs/langs/markdown';
|
|
11
10
|
import scssLang from '@shikijs/langs/scss';
|
|
@@ -1037,17 +1036,6 @@ const graph = new PugDependencyGraph();
|
|
|
1037
1036
|
function getPugDependencyGraph() {
|
|
1038
1037
|
return graph;
|
|
1039
1038
|
}
|
|
1040
|
-
let lastCompileTimings = { read: 0, parse: 0, render: 0, a11y: 0, sections: 0 };
|
|
1041
|
-
function accumulateTimings(timings) {
|
|
1042
|
-
lastCompileTimings.read += timings.read;
|
|
1043
|
-
lastCompileTimings.parse += timings.parse;
|
|
1044
|
-
lastCompileTimings.render += timings.render;
|
|
1045
|
-
lastCompileTimings.a11y += timings.a11y;
|
|
1046
|
-
lastCompileTimings.sections += 1;
|
|
1047
|
-
}
|
|
1048
|
-
function getLastCompileTimings() {
|
|
1049
|
-
return lastCompileTimings;
|
|
1050
|
-
}
|
|
1051
1039
|
const __filename$1 = fileURLToPath(import.meta.url);
|
|
1052
1040
|
const __dirname$1 = path.dirname(__filename$1);
|
|
1053
1041
|
const workerFilePath = __dirname$1.includes("dist/") ? "./pug/worker.mjs" : "./worker.ts";
|
|
@@ -1114,9 +1102,6 @@ function runPinned(id, input) {
|
|
|
1114
1102
|
});
|
|
1115
1103
|
return run;
|
|
1116
1104
|
}
|
|
1117
|
-
function getPugPoolInfo() {
|
|
1118
|
-
return { cpus: os.cpus().length, maxPoolSize: MAX_POOL_SIZE, workers: allWorkers.size };
|
|
1119
|
-
}
|
|
1120
1105
|
async function terminatePugWorkers() {
|
|
1121
1106
|
const workers = [...allWorkers];
|
|
1122
1107
|
allWorkers.clear();
|
|
@@ -1147,9 +1132,8 @@ function recordFailure(mode, repository, errors, pugError) {
|
|
|
1147
1132
|
async function compileInline(mode, contentDir, repository, id, errors) {
|
|
1148
1133
|
const markupSource = repository.get(id).markup;
|
|
1149
1134
|
try {
|
|
1150
|
-
const { html, dependencies
|
|
1135
|
+
const { html, dependencies } = await compileMarkup(contentDir, mode, markupSource, id);
|
|
1151
1136
|
repository.set(id, { markup: html });
|
|
1152
|
-
accumulateTimings(timings);
|
|
1153
1137
|
await storeResult(id, markupSource, html, dependencies);
|
|
1154
1138
|
} catch (error) {
|
|
1155
1139
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1177,7 +1161,6 @@ async function compileViaWorkerPool(mode, contentDir, repository, ids, errors) {
|
|
|
1177
1161
|
return;
|
|
1178
1162
|
}
|
|
1179
1163
|
repository.set(id, { markup: result.html });
|
|
1180
|
-
accumulateTimings(result.timings);
|
|
1181
1164
|
await storeResult(id, markupSource, result.html, result.dependencies);
|
|
1182
1165
|
});
|
|
1183
1166
|
await Promise.all(tasks);
|
|
@@ -1202,7 +1185,6 @@ async function compileIds(mode, contentDir, repository, ids) {
|
|
|
1202
1185
|
if (misses.length === 0)
|
|
1203
1186
|
return clonedRepository;
|
|
1204
1187
|
const errors = [];
|
|
1205
|
-
lastCompileTimings = { read: 0, parse: 0, render: 0, a11y: 0, sections: 0 };
|
|
1206
1188
|
const useInline = mode === "development" && misses.length <= INLINE_THRESHOLD;
|
|
1207
1189
|
if (useInline) {
|
|
1208
1190
|
await Promise.all(misses.map((id) => compileInline(mode, contentDir, clonedRepository, id, errors)));
|
|
@@ -1227,6 +1209,13 @@ async function compilePugMarkupIncremental(mode, contentDir, repository, ids) {
|
|
|
1227
1209
|
return compileIds(mode, contentDir, repository, wanted);
|
|
1228
1210
|
}
|
|
1229
1211
|
|
|
1212
|
+
const TRANSIENT_FS_ERROR_CODES = /* @__PURE__ */ new Set(["ENOENT", "EBUSY", "EPERM", "EACCES"]);
|
|
1213
|
+
function isTransientFsError(error) {
|
|
1214
|
+
if (typeof error !== "object" || error === null)
|
|
1215
|
+
return false;
|
|
1216
|
+
const { code } = error;
|
|
1217
|
+
return code !== void 0 && TRANSIENT_FS_ERROR_CODES.has(code);
|
|
1218
|
+
}
|
|
1230
1219
|
async function logicalWriteFile(filepath, content) {
|
|
1231
1220
|
const dir = path.dirname(filepath);
|
|
1232
1221
|
await fs.ensureDir(dir);
|
|
@@ -1263,7 +1252,7 @@ async function generateFullPageFile(data) {
|
|
|
1263
1252
|
<meta name="theme-color" media="(prefers-color-scheme: light)" content="${data.theme.light}">
|
|
1264
1253
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${data.theme.dark}">
|
|
1265
1254
|
` : `<meta name="theme-color" content="${data.theme}">`}
|
|
1266
|
-
<script type="module" src="/styleguide-assets/fullpage-
|
|
1255
|
+
<script type="module" src="/styleguide-assets/fullpage-CGBSSxKh.js"><\/script>
|
|
1267
1256
|
${computedStyleTags}
|
|
1268
1257
|
</head>
|
|
1269
1258
|
<body${data.page.bodyclass ? ` class="${data.page.bodyclass}"` : ""}>
|
|
@@ -1963,10 +1952,11 @@ function getNextPageControlsHtml(data) {
|
|
|
1963
1952
|
</nav>
|
|
1964
1953
|
`.trim();
|
|
1965
1954
|
}
|
|
1966
|
-
function getSearchHtml(sections) {
|
|
1955
|
+
function getSearchHtml(projectTitle, sections) {
|
|
1967
1956
|
return `
|
|
1968
1957
|
<dialog
|
|
1969
1958
|
id="search-dialog"
|
|
1959
|
+
data-project="${slugify(projectTitle)}"
|
|
1970
1960
|
class="fixed inset-0 top-8 z-30 backdrop:hidden -mb-px size-full max-sm:max-h-none open:md:flex open:md:flex-col md:h-auto overflow-y-hidden max-w-none rounded-t-2xl border bg-styleguide-bg border-styleguide-border text-styleguide md:max-w-[720px] md:top-12 md:max-h-[calc(100%-5rem)] md:bottom-auto md:left-1/2 md:-translate-x-1/2 md:rounded-2xl mx-0 lg:top-24 lg:max-h-[calc(100%-8rem)]"
|
|
1971
1961
|
>
|
|
1972
1962
|
<h2 class="sr-only">Search</h2>
|
|
@@ -2007,7 +1997,7 @@ function getSearchHtml(sections) {
|
|
|
2007
1997
|
>
|
|
2008
1998
|
${sections.map((section, categoryIdx) => `
|
|
2009
1999
|
<div class="search-category" id="search-category-${categoryIdx}" data-category-index="${categoryIdx}">
|
|
2010
|
-
<h3 class="mb-
|
|
2000
|
+
<h3 class="mb-1.5 px-1.5 text-xs font-medium tracking-wider uppercase opacity-60">${section.title}</h3>
|
|
2011
2001
|
<ul>
|
|
2012
2002
|
${section.items.map((item, itemIdx) => `
|
|
2013
2003
|
<li
|
|
@@ -2022,11 +2012,13 @@ function getSearchHtml(sections) {
|
|
|
2022
2012
|
href="${item.href}"
|
|
2023
2013
|
tabindex="-1"
|
|
2024
2014
|
>
|
|
2025
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="transition-all size-5 group-hover:translate-x-0.5 group-focus:translate-x-0.5">
|
|
2015
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="transition-all size-5 shrink-0 group-hover:translate-x-0.5 group-focus:translate-x-0.5">
|
|
2026
2016
|
<path fill-rule="evenodd" d="M3 10a.75.75 0 0 1 .75-.75h10.638L10.23 5.29a.75.75 0 1 1 1.04-1.08l5.5 5.25a.75.75 0 0 1 0 1.08l-5.5 5.25a.75.75 0 1 1-1.04-1.08l4.158-3.96H3.75A.75.75 0 0 1 3 10Z" clip-rule="evenodd" />
|
|
2027
2017
|
</svg>
|
|
2028
|
-
<span class="
|
|
2029
|
-
|
|
2018
|
+
<span class="grid min-w-0 gap-0.5">
|
|
2019
|
+
<span data-search-label class="text-styleguide-highlight">${item.label}</span>
|
|
2020
|
+
<span data-type="search-hint" class="truncate text-[13px] text-styleguide"></span>
|
|
2021
|
+
</span>
|
|
2030
2022
|
</a>
|
|
2031
2023
|
</li>
|
|
2032
2024
|
`).join("\n")}
|
|
@@ -2067,7 +2059,7 @@ async function generatePreviewFile(data) {
|
|
|
2067
2059
|
<meta name="theme-color" media="(prefers-color-scheme: light)" content="${data.theme.light}">
|
|
2068
2060
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${data.theme.dark}">
|
|
2069
2061
|
` : `<meta name="theme-color" content="${data.theme}">`}
|
|
2070
|
-
<link rel="stylesheet" type="text/css" href="/styleguide-assets/kss-modern-
|
|
2062
|
+
<link rel="stylesheet" type="text/css" href="/styleguide-assets/kss-modern-3dYdkdaU.css">
|
|
2071
2063
|
<script>
|
|
2072
2064
|
//#region client/lib/iframe-resize.ts
|
|
2073
2065
|
var e = [
|
|
@@ -2220,7 +2212,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
2220
2212
|
//#endregion
|
|
2221
2213
|
;
|
|
2222
2214
|
<\/script>
|
|
2223
|
-
<script type="module" src="/styleguide-assets/preview-
|
|
2215
|
+
<script type="module" src="/styleguide-assets/preview-B-NERQ5n.js"><\/script>
|
|
2224
2216
|
<link rel="preload" href="/styleguide-assets/fonts/geist-mono-latin-400-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
|
2225
2217
|
<link rel="preload" href="/styleguide-assets/fonts/geist-mono-latin-600-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
|
2226
2218
|
<link rel="preload" href="/styleguide-assets/fonts/geist-mono-latin-300-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
|
@@ -2296,13 +2288,25 @@ function matchArraysEqual(a, b) {
|
|
|
2296
2288
|
return a.every((value, index) => value === b[index]);
|
|
2297
2289
|
}
|
|
2298
2290
|
const kssSectionRegex = /\/\*{1,2}[\s\S]*?Styleguide[\s\S]*?\*\//g;
|
|
2291
|
+
function tryReadFileSync(filePath) {
|
|
2292
|
+
try {
|
|
2293
|
+
return readFileSync(filePath, "utf8");
|
|
2294
|
+
} catch (error) {
|
|
2295
|
+
if (isTransientFsError(error))
|
|
2296
|
+
return void 0;
|
|
2297
|
+
throw error;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2299
2300
|
function watchStyleguideForChanges(watchPath, handlers) {
|
|
2300
2301
|
if (typeof handlers.onStructuralChange !== "function" || typeof handlers.onMarkupChange !== "function") {
|
|
2301
2302
|
throw new TypeError("styleguide watch requires onStructuralChange and onMarkupChange callbacks");
|
|
2302
2303
|
}
|
|
2303
2304
|
const regexFileContents = /* @__PURE__ */ new Map();
|
|
2304
2305
|
const handleCssAdd = (filePath) => {
|
|
2305
|
-
const
|
|
2306
|
+
const contents = tryReadFileSync(filePath);
|
|
2307
|
+
if (contents === void 0)
|
|
2308
|
+
return;
|
|
2309
|
+
const currentFileMatches = contents.match(kssSectionRegex);
|
|
2306
2310
|
if (currentFileMatches === null) {
|
|
2307
2311
|
return;
|
|
2308
2312
|
}
|
|
@@ -2312,7 +2316,10 @@ function watchStyleguideForChanges(watchPath, handlers) {
|
|
|
2312
2316
|
const handleCssChange = (filePath) => {
|
|
2313
2317
|
const previousFileMatches = regexFileContents.get(filePath);
|
|
2314
2318
|
const hasFileBeenReadBefore = previousFileMatches !== void 0;
|
|
2315
|
-
const
|
|
2319
|
+
const contents = tryReadFileSync(filePath);
|
|
2320
|
+
if (contents === void 0)
|
|
2321
|
+
return;
|
|
2322
|
+
const currentFileMatches = contents.match(kssSectionRegex);
|
|
2316
2323
|
if (!hasFileBeenReadBefore) {
|
|
2317
2324
|
regexFileContents.set(filePath, currentFileMatches);
|
|
2318
2325
|
if (currentFileMatches === null) {
|
|
@@ -2390,12 +2397,14 @@ function buildNavigationMappings(parsedContent) {
|
|
|
2390
2397
|
label: secondLevelSection.header,
|
|
2391
2398
|
searchKeywords: [
|
|
2392
2399
|
{
|
|
2393
|
-
|
|
2400
|
+
// header is plain text; description is rendered-markdown HTML, so strip it to plain text
|
|
2401
|
+
// before indexing — otherwise queries would match tag names and the hint would show markup.
|
|
2402
|
+
keywords: [secondLevelSection.header, htmlToSearchText(secondLevelSection.description)].filter(Boolean)
|
|
2394
2403
|
},
|
|
2395
2404
|
...secondLevelSection.sections.flatMap((thirdLevelSection) => {
|
|
2396
2405
|
return {
|
|
2397
2406
|
id: sectionSanitizeId(`section-${thirdLevelSection.id}`),
|
|
2398
|
-
keywords: [thirdLevelSection.header, thirdLevelSection.description].filter(Boolean)
|
|
2407
|
+
keywords: [thirdLevelSection.header, htmlToSearchText(thirdLevelSection.description)].filter(Boolean)
|
|
2399
2408
|
};
|
|
2400
2409
|
})
|
|
2401
2410
|
],
|
|
@@ -2552,7 +2561,7 @@ async function buildContext(config) {
|
|
|
2552
2561
|
}
|
|
2553
2562
|
const { searchSectionMapping, menuSectionMapping } = buildNavigationMappings(parsedContent);
|
|
2554
2563
|
const headerHtml = getHeaderHtml(config);
|
|
2555
|
-
const searchHtml = getSearchHtml(searchSectionMapping);
|
|
2564
|
+
const searchHtml = getSearchHtml(config.projectTitle, searchSectionMapping);
|
|
2556
2565
|
return {
|
|
2557
2566
|
baseDirectory,
|
|
2558
2567
|
parsedContent,
|
|
@@ -2643,21 +2652,17 @@ async function rebuildSections(config, context, changedSectionIds) {
|
|
|
2643
2652
|
}
|
|
2644
2653
|
if (subset.size === 0)
|
|
2645
2654
|
return;
|
|
2646
|
-
const startedAt = performance.now();
|
|
2647
|
-
const workersBefore = getPugPoolInfo().workers;
|
|
2648
2655
|
const recompiled = await compilePugMarkupIncremental(config.mode, config.contentDir, subset, subset.keys());
|
|
2649
2656
|
for (const [id, entry] of recompiled) {
|
|
2650
2657
|
context.compiledRepository.set(id, { markup: entry.markup });
|
|
2651
2658
|
reindexInsertMarkupConsumer(context, id);
|
|
2652
2659
|
}
|
|
2653
|
-
const afterCompile = performance.now();
|
|
2654
2660
|
const resolved = resolveInsertMarkupForSections(context.compiledRepository, context.sectionsById, affected);
|
|
2655
2661
|
for (const [id, markup] of resolved) {
|
|
2656
2662
|
const node = context.nodeById.get(id);
|
|
2657
2663
|
if (node)
|
|
2658
2664
|
node.markup = markup;
|
|
2659
2665
|
}
|
|
2660
|
-
const afterResolve = performance.now();
|
|
2661
2666
|
const writeTasks = [];
|
|
2662
2667
|
const previewsToWrite = /* @__PURE__ */ new Set();
|
|
2663
2668
|
for (const id of affected) {
|
|
@@ -2675,16 +2680,6 @@ async function rebuildSections(config, context, changedSectionIds) {
|
|
|
2675
2680
|
writeTasks.push(writePreviewFile(config, context, firstLevelIndex, secondLevelIndex));
|
|
2676
2681
|
}
|
|
2677
2682
|
await Promise.all(writeTasks);
|
|
2678
|
-
const afterWrite = performance.now();
|
|
2679
|
-
if (config.mode === "development") {
|
|
2680
|
-
const ms = (value) => `${value.toFixed(1)}ms`;
|
|
2681
|
-
const pool = getPugPoolInfo();
|
|
2682
|
-
const spawned = pool.workers - workersBefore;
|
|
2683
|
-
const t = getLastCompileTimings();
|
|
2684
|
-
logger.info(
|
|
2685
|
-
`Incremental rebuild: ${affected.size} section(s), ${writeTasks.length} file(s) in ${ms(afterWrite - startedAt)} (compile ${ms(afterCompile - startedAt)}, insert-markup ${ms(afterResolve - afterCompile)}, write ${ms(afterWrite - afterResolve)}) [cpus=${pool.cpus}, pool=${pool.maxPoolSize}, workers=${pool.workers}${spawned > 0 ? `, +${spawned} cold-spawned` : ""}] compile breakdown over ${t.sections} section(s): read ${ms(t.read)}, parse ${ms(t.parse)}, render ${ms(t.render)}, a11y ${ms(t.a11y)} (summed per-section; read=disk I/O, parse=lex/parse/codegen)`
|
|
2686
|
-
);
|
|
2687
|
-
}
|
|
2688
2683
|
}
|
|
2689
2684
|
async function watchStyleguide(config, onChange, onError) {
|
|
2690
2685
|
const initialBuild = await buildAll(config);
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { StyleguideConfiguration } from '../index.mjs';
|
|
2
2
|
|
|
3
3
|
type Mode = StyleguideConfiguration['mode'];
|
|
4
|
-
/** Where a section's compile time went, summed over the entry file and any <insert-vite-pug> tags. */
|
|
5
|
-
interface CompileTimings {
|
|
6
|
-
/** Reading the entry file + all includes/extends off disk (file I/O only). */
|
|
7
|
-
read: number;
|
|
8
|
-
/** pug lex + parse + codegen (CPU; excludes the include reads). */
|
|
9
|
-
parse: number;
|
|
10
|
-
/** Executing the compiled template function (pure render). */
|
|
11
|
-
render: number;
|
|
12
|
-
/** `fixAccessibilityIssues` post-processing. */
|
|
13
|
-
a11y: number;
|
|
14
|
-
}
|
|
15
4
|
|
|
16
5
|
interface PugWorkerInput {
|
|
17
6
|
id: string;
|
|
@@ -23,7 +12,6 @@ interface PugWorkerSuccess {
|
|
|
23
12
|
id: string;
|
|
24
13
|
html: string;
|
|
25
14
|
dependencies: string[];
|
|
26
|
-
timings: CompileTimings;
|
|
27
15
|
}
|
|
28
16
|
interface PugWorkerError {
|
|
29
17
|
id: string;
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { StyleguideConfiguration } from '../index.js';
|
|
2
2
|
|
|
3
3
|
type Mode = StyleguideConfiguration['mode'];
|
|
4
|
-
/** Where a section's compile time went, summed over the entry file and any <insert-vite-pug> tags. */
|
|
5
|
-
interface CompileTimings {
|
|
6
|
-
/** Reading the entry file + all includes/extends off disk (file I/O only). */
|
|
7
|
-
read: number;
|
|
8
|
-
/** pug lex + parse + codegen (CPU; excludes the include reads). */
|
|
9
|
-
parse: number;
|
|
10
|
-
/** Executing the compiled template function (pure render). */
|
|
11
|
-
render: number;
|
|
12
|
-
/** `fixAccessibilityIssues` post-processing. */
|
|
13
|
-
a11y: number;
|
|
14
|
-
}
|
|
15
4
|
|
|
16
5
|
interface PugWorkerInput {
|
|
17
6
|
id: string;
|
|
@@ -23,7 +12,6 @@ interface PugWorkerSuccess {
|
|
|
23
12
|
id: string;
|
|
24
13
|
html: string;
|
|
25
14
|
dependencies: string[];
|
|
26
|
-
timings: CompileTimings;
|
|
27
15
|
}
|
|
28
16
|
interface PugWorkerError {
|
|
29
17
|
id: string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { parentPort } from 'node:worker_threads';
|
|
2
|
-
import { c as compileMarkup, p as pugErrorFile } from '../../shared/kss-modern.
|
|
2
|
+
import { c as compileMarkup, p as pugErrorFile } from '../../shared/kss-modern.B6jgUPtu.mjs';
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'node:fs/promises';
|
|
5
5
|
import 'node:path';
|
|
6
|
-
import 'node:perf_hooks';
|
|
7
6
|
import 'pug';
|
|
8
7
|
import 'consola';
|
|
9
8
|
import 'consola/utils';
|
|
@@ -15,8 +14,8 @@ if (!parentPort) {
|
|
|
15
14
|
parentPort.on("message", async (data) => {
|
|
16
15
|
const { id, mode, html, contentDir } = data;
|
|
17
16
|
try {
|
|
18
|
-
const { html: compiled, dependencies
|
|
19
|
-
parentPort.postMessage({ id, html: compiled, dependencies
|
|
17
|
+
const { html: compiled, dependencies } = await compileMarkup(contentDir, mode, html, id);
|
|
18
|
+
parentPort.postMessage({ id, html: compiled, dependencies });
|
|
20
19
|
} catch (error) {
|
|
21
20
|
const message = error instanceof Error ? error.message : String(error);
|
|
22
21
|
parentPort.postMessage({ id, error: message, file: pugErrorFile(error) });
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { statSync, readFileSync } from 'node:fs';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { performance } from 'node:perf_hooks';
|
|
5
4
|
import pug from 'pug';
|
|
6
5
|
import { createConsola } from 'consola';
|
|
7
6
|
import { colors } from 'consola/utils';
|
|
@@ -68,6 +67,12 @@ function fixAccessibilityIssues(html) {
|
|
|
68
67
|
function sanitizeSpecialCharacters(text) {
|
|
69
68
|
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
70
69
|
}
|
|
70
|
+
function htmlToSearchText(html) {
|
|
71
|
+
return html.replace(/<[^>]+>/g, " ").replaceAll(" ", " ").replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", '"').replaceAll("'", "'").replaceAll("'", "'").replaceAll("&", "&").replace(/\s+/g, " ").trim();
|
|
72
|
+
}
|
|
73
|
+
function slugify(text) {
|
|
74
|
+
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
75
|
+
}
|
|
71
76
|
function ensureStartingSlash(input) {
|
|
72
77
|
return input.startsWith("/") ? input : `/${input}`;
|
|
73
78
|
}
|
|
@@ -176,19 +181,8 @@ function pugErrorFile(error) {
|
|
|
176
181
|
const candidate = error;
|
|
177
182
|
return candidate?.path ?? candidate?.filename;
|
|
178
183
|
}
|
|
179
|
-
let includeReadMs = 0;
|
|
180
|
-
function timedRead(filePath) {
|
|
181
|
-
const t0 = performance.now();
|
|
182
|
-
const content = readFileSync(filePath, "utf8");
|
|
183
|
-
includeReadMs += performance.now() - t0;
|
|
184
|
-
return content;
|
|
185
|
-
}
|
|
186
184
|
function compilePugFile(pugFilePath, mode, sectionId, extraLocals = {}) {
|
|
187
|
-
const tRead0 = performance.now();
|
|
188
185
|
const source = readFileSync(pugFilePath, "utf8");
|
|
189
|
-
let readMs = performance.now() - tRead0;
|
|
190
|
-
const includeReadBefore = includeReadMs;
|
|
191
|
-
const tParse0 = performance.now();
|
|
192
186
|
const pugFn = pug.compile(source, {
|
|
193
187
|
filename: pugFilePath,
|
|
194
188
|
// define doctype to avoid self-closing tags on wrong places
|
|
@@ -198,28 +192,19 @@ function compilePugFile(pugFilePath, mode, sectionId, extraLocals = {}) {
|
|
|
198
192
|
// pug defaults this to true, which wraps the generated function in per-line try/catch +
|
|
199
193
|
// line-mapping — measurably bloating codegen and `new Function`. We surface compile errors via
|
|
200
194
|
// our own overlay, so the precise pug line in a runtime stack isn't worth the cost.
|
|
201
|
-
compileDebug: false
|
|
202
|
-
plugins: [{ read: timedRead }]
|
|
195
|
+
compileDebug: false
|
|
203
196
|
});
|
|
204
|
-
const includeReads = includeReadMs - includeReadBefore;
|
|
205
|
-
const parseMs = performance.now() - tParse0 - includeReads;
|
|
206
|
-
readMs += includeReads;
|
|
207
197
|
const dependencies = [path.resolve(pugFilePath), ...pugFn.dependencies.map((dep) => path.resolve(dep))];
|
|
208
|
-
const tRender0 = performance.now();
|
|
209
198
|
const html = pugFn({ ...extraLocals, useId: createUseId(sectionId) });
|
|
210
|
-
|
|
211
|
-
return { html, dependencies, readMs, parseMs, renderMs };
|
|
199
|
+
return { html, dependencies };
|
|
212
200
|
}
|
|
213
201
|
async function expandVitePugTags(contentDir, mode, html, sectionId) {
|
|
214
202
|
const vitePugTags = html.match(INSERT_VITE_PUG_TAG_RE);
|
|
215
203
|
if (!vitePugTags) {
|
|
216
|
-
return { html, dependencies: []
|
|
204
|
+
return { html, dependencies: [] };
|
|
217
205
|
}
|
|
218
206
|
let markupOutput = html;
|
|
219
207
|
const dependencies = [];
|
|
220
|
-
let read = 0;
|
|
221
|
-
let parse = 0;
|
|
222
|
-
let render = 0;
|
|
223
208
|
await Promise.all(vitePugTags.map(async (vitePugTag) => {
|
|
224
209
|
const pugSourcePath = vitePugTag.match(PUG_SRC_RE)?.[1];
|
|
225
210
|
if (!pugSourcePath) {
|
|
@@ -232,51 +217,35 @@ async function expandVitePugTags(contentDir, mode, html, sectionId) {
|
|
|
232
217
|
const pugModifierClass = vitePugTag.match(PUG_MODIFIER_CLASS_RE);
|
|
233
218
|
const pugLocals = pugModifierClass && pugModifierClass[1] ? { modifierClass: pugModifierClass[1] } : {};
|
|
234
219
|
const pugFilePath = path.join(contentDir, pugSourcePath);
|
|
235
|
-
const { html: pugOutput, dependencies: pugDependencies
|
|
220
|
+
const { html: pugOutput, dependencies: pugDependencies } = compilePugFile(pugFilePath, mode, sectionId, pugLocals);
|
|
236
221
|
dependencies.push(...pugDependencies);
|
|
237
|
-
read += readMs;
|
|
238
|
-
parse += parseMs;
|
|
239
|
-
render += renderMs;
|
|
240
222
|
markupOutput = markupOutput.replaceAll(vitePugTag, pugOutput);
|
|
241
223
|
}));
|
|
242
|
-
return { html: markupOutput, dependencies
|
|
224
|
+
return { html: markupOutput, dependencies };
|
|
243
225
|
}
|
|
244
226
|
async function compileMarkup(contentDir, mode, html, sectionId) {
|
|
245
227
|
let result = html;
|
|
246
228
|
const dependencies = [];
|
|
247
|
-
let read = 0;
|
|
248
|
-
let parse = 0;
|
|
249
|
-
let render = 0;
|
|
250
229
|
const trimmed = html.trim();
|
|
251
230
|
const isBarePath = !trimmed.includes("<") && !trimmed.includes("\n");
|
|
252
231
|
if (isBarePath && trimmed.endsWith(".html")) {
|
|
253
232
|
const htmlFilePath = path.join(contentDir, trimmed);
|
|
254
|
-
const t0 = performance.now();
|
|
255
233
|
result = await fs.readFile(htmlFilePath, "utf-8");
|
|
256
|
-
read += performance.now() - t0;
|
|
257
234
|
dependencies.push(path.resolve(htmlFilePath));
|
|
258
235
|
} else if (isBarePath && trimmed.endsWith(".pug")) {
|
|
259
236
|
const pugFilePath = path.join(contentDir, trimmed);
|
|
260
237
|
const compiled = compilePugFile(pugFilePath, mode, sectionId);
|
|
261
238
|
result = compiled.html;
|
|
262
239
|
dependencies.push(...compiled.dependencies);
|
|
263
|
-
read += compiled.readMs;
|
|
264
|
-
parse += compiled.parseMs;
|
|
265
|
-
render += compiled.renderMs;
|
|
266
240
|
}
|
|
267
241
|
const expanded = await expandVitePugTags(contentDir, mode, result, sectionId);
|
|
268
242
|
result = expanded.html;
|
|
269
243
|
dependencies.push(...expanded.dependencies);
|
|
270
|
-
read += expanded.timings.read;
|
|
271
|
-
parse += expanded.timings.parse;
|
|
272
|
-
render += expanded.timings.render;
|
|
273
244
|
if (mode === "production") {
|
|
274
245
|
result = await biomeFormat(result);
|
|
275
246
|
}
|
|
276
|
-
const tA11y = performance.now();
|
|
277
247
|
result = fixAccessibilityIssues(result);
|
|
278
|
-
|
|
279
|
-
return { html: result, dependencies: [...new Set(dependencies)], timings: { read, parse, render, a11y } };
|
|
248
|
+
return { html: result, dependencies: [...new Set(dependencies)] };
|
|
280
249
|
}
|
|
281
250
|
|
|
282
|
-
export { INSERT_VITE_PUG_TAG_RE as I, PUG_SRC_RE as P, PUG_ERROR_OVERLAY_TAG as a,
|
|
251
|
+
export { INSERT_VITE_PUG_TAG_RE as I, PUG_SRC_RE as P, PUG_ERROR_OVERLAY_TAG as a, slugify as b, compileMarkup as c, sectionSanitizeId as d, stripPugErrorOverlay as e, ensureStartingSlash as f, generateId as g, htmlToSearchText as h, createLogger as i, logger as l, pugErrorFile as p, replaceWrapperContent as r, sanitizeSpecialCharacters as s };
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"name": "utils"
|
|
25
25
|
},
|
|
26
26
|
"client/fullpage.ts": {
|
|
27
|
-
"file": "fullpage-
|
|
27
|
+
"file": "fullpage-CGBSSxKh.js",
|
|
28
28
|
"name": "fullpage",
|
|
29
29
|
"src": "client/fullpage.ts",
|
|
30
30
|
"isEntry": true,
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"isEntry": true
|
|
83
83
|
},
|
|
84
84
|
"client/preview.ts": {
|
|
85
|
-
"file": "preview-
|
|
85
|
+
"file": "preview-B-NERQ5n.js",
|
|
86
86
|
"name": "preview",
|
|
87
87
|
"src": "client/preview.ts",
|
|
88
88
|
"isEntry": true,
|
|
@@ -90,7 +90,8 @@
|
|
|
90
90
|
"_animate-DRGZltJ3.js",
|
|
91
91
|
"_code-highlight-BygtMiLu.js",
|
|
92
92
|
"_signal-ZVBNTRLw.js",
|
|
93
|
-
"_utils-DrMb1LbR.js"
|
|
93
|
+
"_utils-DrMb1LbR.js",
|
|
94
|
+
"_shared-hGcWlnRM.js"
|
|
94
95
|
],
|
|
95
96
|
"dynamicImports": [
|
|
96
97
|
"client/lib/html-validator.ts",
|
|
@@ -118,7 +119,7 @@
|
|
|
118
119
|
]
|
|
119
120
|
},
|
|
120
121
|
"style.css": {
|
|
121
|
-
"file": "kss-modern-
|
|
122
|
+
"file": "kss-modern-3dYdkdaU.css",
|
|
122
123
|
"src": "style.css"
|
|
123
124
|
}
|
|
124
125
|
}
|