kss-modern 1.7.0-beta.1 → 1.7.0-beta.2

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.
@@ -3,16 +3,13 @@ import process from 'node:process';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import fs from 'fs-extra';
5
5
  import { glob } from 'tinyglobby';
6
- import { l as logger, s as sanitizeSpecialCharacters, P as PUG_ERROR_OVERLAY_TAG, r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, p as pugErrorFile, a as compileMarkup, g as getZodVersion, M as MIXIN_COMPILE_OPTIONS, b as getMixinWrapperSource, d as slugify, I as INSERT_VITE_PUG_TAG_RE, f as PUG_SRC_RE, t as themeClassList, h as ensureStartingSlash, i as sectionSanitizeId, j as stripPugErrorOverlay, k as generateId, m as replaceWrapperContent, n as formatSourceCode, o as htmlToSearchText } from '../shared/kss-modern.D1AKakeJ.mjs';
7
- export { q as createLogger } from '../shared/kss-modern.D1AKakeJ.mjs';
6
+ import { l as logger, s as sanitizeSpecialCharacters, P as PUG_ERROR_OVERLAY_TAG, r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, p as pugErrorFile, a as compileMarkup, g as getZodVersion, d as discoverMixins, M as MIXIN_COMPILE_OPTIONS, b as getMixinWrapperSource, f as slugify, I as INSERT_VITE_PUG_TAG_RE, h as PUG_SRC_RE, t as themeClassList, i as ensureStartingSlash, j as sectionSanitizeId, k as stripPugErrorOverlay, m as generateId, n as replaceWrapperContent, o as formatSourceCode, q as htmlToSearchText } from '../shared/kss-modern.BOTbHnCm.mjs';
7
+ export { u as createLogger } from '../shared/kss-modern.BOTbHnCm.mjs';
8
8
  import { existsSync, readFileSync } from 'node:fs';
9
9
  import fs$1 from 'node:fs/promises';
10
10
  import { createHash } from 'node:crypto';
11
11
  import os from 'node:os';
12
12
  import { Worker } from 'node:worker_threads';
13
- import lex from 'pug-lexer';
14
- import parse$1 from 'pug-parser';
15
- import walk from 'pug-walk';
16
13
  import htmlLang from '@shikijs/langs/html';
17
14
  import markdownLang from '@shikijs/langs/markdown';
18
15
  import scssLang from '@shikijs/langs/scss';
@@ -30,6 +27,9 @@ import 'pug';
30
27
  import 'consola';
31
28
  import 'consola/utils';
32
29
  import 'node:module';
30
+ import 'pug-walk';
31
+ import 'pug-lexer';
32
+ import 'pug-parser';
33
33
  import 'pug-load';
34
34
 
35
35
  const HEX_COLOR_RE = /^#[0-9A-F]{6}$/i;
@@ -586,42 +586,6 @@ async function logicalWriteFile(filepath, content) {
586
586
  await fs.writeFile(filepath, content);
587
587
  }
588
588
 
589
- const MIXIN_SCHEMA_RE = /\bmixinSchema\s*=/;
590
- const MIXIN_NAME_RE = /^\s*(?:var|let|const)\s+mixinName\s*=\s*(['"])([^'"\n]*)\1\s*(?:;\s*)?$/;
591
- const MIXIN_KEYWORD_RE = /^\s*mixin\s/m;
592
- function findMixinCode(block) {
593
- const found = {};
594
- walk(block, (node) => {
595
- if (node.type === "Mixin")
596
- return false;
597
- if (node.type !== "Code" || node.buffer)
598
- return;
599
- if (found.schemaSource === void 0 && MIXIN_SCHEMA_RE.test(node.val))
600
- found.schemaSource = node.val;
601
- const name = MIXIN_NAME_RE.exec(node.val)?.[2];
602
- if (found.mixinName === void 0 && name !== void 0)
603
- found.mixinName = name;
604
- });
605
- return found;
606
- }
607
- function discoverMixins(source, filename) {
608
- if (!MIXIN_KEYWORD_RE.test(source))
609
- return [];
610
- const ast = parse$1(lex(source, { filename }), { filename, src: source });
611
- const mixins = [];
612
- for (const node of ast.nodes) {
613
- if (node.type !== "Mixin" || node.call)
614
- continue;
615
- mixins.push({
616
- name: node.name,
617
- args: node.args ?? null,
618
- line: node.line,
619
- ...node.block ? findMixinCode(node.block) : {}
620
- });
621
- }
622
- return mixins;
623
- }
624
-
625
589
  const MIXIN_MANIFEST_PATH = "mixins/manifest.json";
626
590
  const MIXIN_OVERVIEW_FILE = "mixins.html";
627
591
  function getMixinExplorerHref(id) {
@@ -1,5 +1,5 @@
1
1
  import { parentPort } from 'node:worker_threads';
2
- import { r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, a as compileMarkup, p as pugErrorFile } from '../../shared/kss-modern.D1AKakeJ.mjs';
2
+ import { r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, a as compileMarkup, p as pugErrorFile } from '../../shared/kss-modern.BOTbHnCm.mjs';
3
3
  import 'node:path';
4
4
  import 'pug';
5
5
  import 'node:fs';
@@ -8,6 +8,8 @@ import 'consola';
8
8
  import 'consola/utils';
9
9
  import 'node:module';
10
10
  import 'pug-walk';
11
+ import 'pug-lexer';
12
+ import 'pug-parser';
11
13
  import 'pug-load';
12
14
 
13
15
  if (!parentPort) {
@@ -6,6 +6,8 @@ import { createConsola } from 'consola';
6
6
  import { colors } from 'consola/utils';
7
7
  import { createRequire } from 'node:module';
8
8
  import walk from 'pug-walk';
9
+ import lex from 'pug-lexer';
10
+ import parse from 'pug-parser';
9
11
  import pugLoad from 'pug-load';
10
12
 
11
13
  const sectionSanitizeId = (id2) => id2.toLowerCase().replaceAll(".", "-");
@@ -98,6 +100,72 @@ function generateId() {
98
100
  return value;
99
101
  }
100
102
 
103
+ const MIXIN_SCHEMA_RE = /\bmixinSchema\s*=/;
104
+ const MIXIN_NAME_RE = /^\s*(?:var|let|const)\s+mixinName\s*=\s*(['"])([^'"\n]*)\1\s*(?:;\s*)?$/;
105
+ const MIXIN_KEYWORD_RE = /^\s*mixin\s/m;
106
+ function findMixinCode(block) {
107
+ const found = {};
108
+ walk(block, (node) => {
109
+ if (node.type === "Mixin")
110
+ return false;
111
+ if (node.type !== "Code" || node.buffer)
112
+ return;
113
+ if (found.schemaSource === void 0 && MIXIN_SCHEMA_RE.test(node.val))
114
+ found.schemaSource = node.val;
115
+ const name = MIXIN_NAME_RE.exec(node.val)?.[2];
116
+ if (found.mixinName === void 0 && name !== void 0)
117
+ found.mixinName = name;
118
+ });
119
+ return found;
120
+ }
121
+ function discoverMixins(source, filename) {
122
+ if (!MIXIN_KEYWORD_RE.test(source))
123
+ return [];
124
+ const ast = parse(lex(source, { filename }), { filename, src: source });
125
+ const mixins = [];
126
+ for (const node of ast.nodes) {
127
+ if (node.type !== "Mixin" || node.call)
128
+ continue;
129
+ mixins.push({
130
+ name: node.name,
131
+ args: node.args ?? null,
132
+ line: node.line,
133
+ ...node.block ? findMixinCode(node.block) : {}
134
+ });
135
+ }
136
+ return mixins;
137
+ }
138
+
139
+ function getMixinMarkerName(name, mixinName) {
140
+ const segment = mixinName?.split("/").map((part) => part.trim()).filter(Boolean).at(-1) ?? name;
141
+ return segment.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/[-_\s]+/g, " ").trim().toUpperCase();
142
+ }
143
+ function createComment(val, node) {
144
+ return { type: "Comment", val, buffer: true, line: node.line, column: node.column, filename: node.filename };
145
+ }
146
+ function hasStartMarker(nodes) {
147
+ return nodes.some((node) => node.type === "Comment" && node.buffer === true && node.val?.trim().startsWith("START "));
148
+ }
149
+ const mixinMarkerPlugin = {
150
+ preCodeGen(ast) {
151
+ return walk(ast, (node) => {
152
+ if (node.type !== "Mixin" || node.call || !node.block || typeof node.name !== "string")
153
+ return;
154
+ if (hasStartMarker(node.block.nodes))
155
+ return;
156
+ const { schemaSource, mixinName } = findMixinCode(node.block);
157
+ if (schemaSource === void 0)
158
+ return;
159
+ const markerName = getMixinMarkerName(node.name, mixinName);
160
+ node.block.nodes = [
161
+ createComment(` START ${markerName}`, node),
162
+ ...node.block.nodes,
163
+ createComment(` END ${markerName}`, node)
164
+ ];
165
+ });
166
+ }
167
+ };
168
+
101
169
  const parseCache = /* @__PURE__ */ new Map();
102
170
  function signatureOf(filename) {
103
171
  try {
@@ -178,7 +246,7 @@ function compileMixinModule(file, name) {
178
246
  ...MIXIN_COMPILE_OPTIONS,
179
247
  // a sibling of the mixin's file, so its relative includes resolve exactly as in the file itself
180
248
  filename: path.join(path.dirname(absoluteFile), `__kss-mixin-${name}.pug`),
181
- plugins: [mixinPugPlugin]
249
+ plugins: [mixinPugPlugin, mixinMarkerPlugin]
182
250
  });
183
251
  return {
184
252
  code: `${body}
@@ -436,8 +504,9 @@ function compilePugFile(pugFilePath, mode, sectionId, extraLocals = {}) {
436
504
  // line-mapping — measurably bloating codegen and `new Function`. We surface compile errors via
437
505
  // our own overlay, so the precise pug line in a runtime stack isn't worth the cost.
438
506
  compileDebug: false,
439
- // records which mixins the section calls, see ./mixin-trace.ts
440
- plugins: [mixinTracePlugin]
507
+ // START/END comments around public mixins, see ./mixin-markers.ts; records which mixins the
508
+ // section calls, see ./mixin-trace.ts
509
+ plugins: [mixinMarkerPlugin, mixinTracePlugin]
441
510
  });
442
511
  const dependencies = [path.resolve(pugFilePath), ...pugFn.dependencies.map((dep) => path.resolve(dep))];
443
512
  const locals = { modifierClass: "{{modifier_class}}", ...extraLocals, useId: createUseId(sectionId) };
@@ -499,4 +568,4 @@ async function compileMarkup(contentDir, mode, html, sectionId) {
499
568
  return { html: result, dependencies: [...new Set(dependencies)], mixinUsage: mergeMixinUsage(mixinUsage) };
500
569
  }
501
570
 
502
- export { INSERT_VITE_PUG_TAG_RE as I, MIXIN_COMPILE_OPTIONS as M, PUG_ERROR_OVERLAY_TAG as P, compileMarkup as a, getMixinWrapperSource as b, compileMixinModule as c, slugify as d, evaluateMixinSchema as e, PUG_SRC_RE as f, getZodVersion as g, ensureStartingSlash as h, sectionSanitizeId as i, stripPugErrorOverlay as j, generateId as k, logger as l, replaceWrapperContent as m, formatSourceCode as n, htmlToSearchText as o, pugErrorFile as p, createLogger as q, requireZod as r, sanitizeSpecialCharacters as s, themeClassList as t };
571
+ export { INSERT_VITE_PUG_TAG_RE as I, MIXIN_COMPILE_OPTIONS as M, PUG_ERROR_OVERLAY_TAG as P, compileMarkup as a, getMixinWrapperSource as b, compileMixinModule as c, discoverMixins as d, evaluateMixinSchema as e, slugify as f, getZodVersion as g, PUG_SRC_RE as h, ensureStartingSlash as i, sectionSanitizeId as j, stripPugErrorOverlay as k, logger as l, generateId as m, replaceWrapperContent as n, formatSourceCode as o, pugErrorFile as p, htmlToSearchText as q, requireZod as r, sanitizeSpecialCharacters as s, themeClassList as t, createLogger as u };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kss-modern",
3
3
  "type": "module",
4
- "version": "1.7.0-beta.1",
4
+ "version": "1.7.0-beta.2",
5
5
  "description": "Modern KSS compatible styleguide generator",
6
6
  "keywords": [
7
7
  "kss",