kss-modern 1.7.0-beta.4 → 1.7.0-beta.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.
@@ -1 +1 @@
1
- export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.Blhbay-v.mjs';
1
+ export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.Dxz_7Er0.mjs';
@@ -1 +1 @@
1
- export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.Blhbay-v.js';
1
+ export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.Dxz_7Er0.js';
@@ -3,8 +3,8 @@ 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, 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.tLBfjOgj.mjs';
7
- export { u as createLogger } from '../shared/kss-modern.tLBfjOgj.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.AIWT72eU.mjs';
7
+ export { u as createLogger } from '../shared/kss-modern.AIWT72eU.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';
@@ -553,7 +553,7 @@ async function evaluateSchemaJobs(jobs) {
553
553
  await Promise.all(jobs.map(async (job) => {
554
554
  if (!workerFilePathResolved) {
555
555
  const z = requireZod();
556
- results.set(job.id, z ? evaluateMixinSchema(z, job.source) : { error: "zod 4 is not installed" });
556
+ results.set(job.id, z ? evaluateMixinSchema(z, job.source, job.form) : { error: "zod 4 is not installed" });
557
557
  return;
558
558
  }
559
559
  try {
@@ -599,7 +599,7 @@ function getMixinStandaloneFileName(id) {
599
599
  return `mixins-${id}-standalone.html`;
600
600
  }
601
601
 
602
- const CACHE_FORMAT = 3;
602
+ const CACHE_FORMAT = 4;
603
603
  const DEFAULT_CACHE_DIR = "node_modules/.cache/kss-modern";
604
604
  const MIXIN_GRAPH_PREFIX = "mixin:";
605
605
  let kssModernVersion;
@@ -754,16 +754,18 @@ function createMixinPipeline(config) {
754
754
  }));
755
755
  const discovered = [...pugFiles].sort().flatMap((file) => (data.files[file]?.mixins ?? []).map((mixin) => ({ file, mixin })));
756
756
  const ids = assignIds(discovered);
757
- const schemaKeys = discovered.map(({ mixin }) => mixin.schemaSource === void 0 ? void 0 : hashContent(`${mixin.schemaSource}
757
+ const getSchemaForm = (mixin) => mixin.isDefineComponent ? "defineComponent" : "mixinSchema";
758
+ const schemaKeys = discovered.map(({ mixin }) => mixin.schemaSource === void 0 ? void 0 : hashContent(`${getSchemaForm(mixin)}
759
+ ${mixin.schemaSource}
758
760
  ${zodVersion}`));
759
761
  const usedSchemaKeys = new Set(schemaKeys.filter((key) => key !== void 0));
760
762
  const schemaMisses = /* @__PURE__ */ new Map();
761
763
  discovered.forEach(({ mixin }, index) => {
762
764
  const schemaKey = schemaKeys[index];
763
765
  if (schemaKey !== void 0 && !data.schemas[schemaKey])
764
- schemaMisses.set(schemaKey, mixin.schemaSource);
766
+ schemaMisses.set(schemaKey, { source: mixin.schemaSource, form: getSchemaForm(mixin) });
765
767
  });
766
- const evaluated = await evaluateSchemaJobs([...schemaMisses].map(([id, source]) => ({ id, source })));
768
+ const evaluated = await evaluateSchemaJobs([...schemaMisses].map(([id, job]) => ({ id, ...job })));
767
769
  for (const [schemaKey, schema] of evaluated) {
768
770
  data.schemas[schemaKey] = schema;
769
771
  isCacheDirty = true;
@@ -785,11 +787,13 @@ ${zodVersion}`));
785
787
  const schema = data.schemas[schemaKey];
786
788
  if ("error" in schema) {
787
789
  if (evaluated.has(schemaKey))
788
- logger.warn(`The mixinSchema of "${mixin.name}" (${entry.file}:${mixin.line}) cannot be used, the mixin gets no playground:
790
+ logger.warn(`The schema of "${mixin.name}" (${entry.file}:${mixin.line}) cannot be used, the mixin gets no playground:
789
791
  ${schema.error}`);
790
792
  entry.schemaError = schema.error;
791
793
  return entry;
792
794
  }
795
+ if (schema.name !== void 0)
796
+ entry.path = getMixinPath(mixin.name, schema.name);
793
797
  entry.hasSchema = true;
794
798
  entry.jsonSchema = schema.jsonSchema;
795
799
  if (typeof schema.jsonSchema.description === "string")
@@ -875,7 +879,7 @@ ${result2.error}`);
875
879
  const schemaFailures = entries.filter((entry) => entry.schemaError !== void 0).map((entry) => ` \u2022 ${entry.name} (${entry.file}:${entry.line})
876
880
  ${entry.schemaError}`);
877
881
  const problems = [
878
- ...schemaFailures.length > 0 ? [`Invalid mixinSchema in ${schemaFailures.length} mixin(s):
882
+ ...schemaFailures.length > 0 ? [`Invalid schema in ${schemaFailures.length} mixin(s):
879
883
 
880
884
  ${schemaFailures.join("\n\n")}`] : [],
881
885
  ...failures.length > 0 ? [`Pug compilation failed for ${failures.length} mixin(s):
@@ -1810,7 +1814,7 @@ async function generateFullPageFile(data) {
1810
1814
  <meta name="theme-color" media="(prefers-color-scheme: dark)" content="${data.brandColor.dark}">
1811
1815
  ` : `<meta name="theme-color" content="${data.brandColor}">`}
1812
1816
  <script type="module" src="styleguide-assets/fullpage-aWqc0gjm.js"><\/script>
1813
- ${data.playgroundConfig ? '<script type="module" src="styleguide-assets/playground-BBMnDZ8b.js"><\/script>' : ""}
1817
+ ${data.playgroundConfig ? '<script type="module" src="styleguide-assets/playground-B_pD0mat.js"><\/script>' : ""}
1814
1818
  ${computedStyleTags}
1815
1819
  ${computedThemeStyleTags}
1816
1820
  </head>
@@ -2921,7 +2925,7 @@ document.addEventListener("DOMContentLoaded", () => {
2921
2925
  //#endregion
2922
2926
  ;
2923
2927
  <\/script>
2924
- <script type="module" src="styleguide-assets/preview-BkKvdDnK.js"><\/script>
2928
+ <script type="module" src="styleguide-assets/preview-C7DV5Nmc.js"><\/script>
2925
2929
  <link rel="preload" href="styleguide-assets/fonts/geist-mono-latin-400-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
2926
2930
  <link rel="preload" href="styleguide-assets/fonts/geist-mono-latin-600-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
2927
2931
  <link rel="preload" href="styleguide-assets/fonts/geist-mono-latin-300-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
@@ -3162,7 +3166,7 @@ function getMixinExplorerHtml(manifest, config) {
3162
3166
  ></iframe>
3163
3167
  <div class="absolute inset-0 hidden overflow-auto p-6 md:p-10" data-explorer-no-schema>
3164
3168
  <div class="max-w-[65ch]">
3165
- <p class="text-styleguide-highlight">The <code class="font-mono">mixinSchema</code> of <code class="font-mono font-semibold" data-explorer-no-schema-signature></code> could not be evaluated, so it has no playground. The block may only use <code class="font-mono">z</code>.</p>
3169
+ <p class="text-styleguide-highlight">The schema of <code class="font-mono font-semibold" data-explorer-no-schema-signature></code> could not be evaluated, so it has no playground. The <code class="font-mono">defineComponent</code> or <code class="font-mono">mixinSchema</code> block may only use <code class="font-mono">z</code>.</p>
3166
3170
  <pre class="mt-3 overflow-x-auto whitespace-pre-wrap rounded-lg border p-4 font-mono text-xs text-red-700 border-styleguide-border bg-styleguide-bg dark:text-red-400" data-explorer-schema-error></pre>
3167
3171
  </div>
3168
3172
  </div>
@@ -3190,7 +3194,7 @@ function getMixinExplorerHtml(manifest, config) {
3190
3194
 
3191
3195
  <div id="mixin-explorer-panel-controls" class="min-h-0 grow overflow-y-auto" role="tabpanel" aria-labelledby="mixin-explorer-tab-controls" tabindex="0">
3192
3196
  <div aria-label="Props" data-playground-panel></div>
3193
- <p class="hidden p-6 text-sm" data-explorer-no-controls>No controls: the <code class="font-mono">mixinSchema</code> could not be evaluated.</p>
3197
+ <p class="hidden p-6 text-sm" data-explorer-no-controls>No controls: the schema could not be evaluated.</p>
3194
3198
  </div>
3195
3199
  <div id="mixin-explorer-panel-code" class="hidden min-h-0 grow overflow-auto p-4 text-sm" role="tabpanel" aria-labelledby="mixin-explorer-tab-code" tabindex="-1">
3196
3200
  <div
@@ -1,10 +1,14 @@
1
- import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.Blhbay-v.mjs';
1
+ import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.Dxz_7Er0.mjs';
2
2
 
3
3
  type MixinSchemaResult = {
4
4
  jsonSchema: Record<string, unknown>;
5
+ /** `name` passed to `defineComponent`, the mixin's place in the explorer. */
6
+ name?: string;
5
7
  } | {
6
8
  error: string;
7
9
  };
10
+ /** How a mixin declares its schema, see `./discovery.ts`. */
11
+ type MixinSchemaForm = 'defineComponent' | 'mixinSchema';
8
12
 
9
13
  type Mode = StyleguideConfiguration['mode'];
10
14
 
@@ -22,11 +26,12 @@ interface PugMixinJob {
22
26
  file: string;
23
27
  name: string;
24
28
  }
25
- /** Evaluate one `mixinSchema` block and convert it to JSON Schema (see `lib/mixins/schema.ts`). */
29
+ /** Evaluate one schema block and convert it to JSON Schema (see `lib/mixins/schema.ts`). */
26
30
  interface PugSchemaJob {
27
31
  kind: 'schema';
28
32
  id: string;
29
33
  source: string;
34
+ form: MixinSchemaForm;
30
35
  }
31
36
  type PugWorkerInput = PugSectionJob | PugMixinJob | PugSchemaJob;
32
37
  interface PugWorkerSuccess {
@@ -1,10 +1,14 @@
1
- import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.Blhbay-v.js';
1
+ import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.Dxz_7Er0.js';
2
2
 
3
3
  type MixinSchemaResult = {
4
4
  jsonSchema: Record<string, unknown>;
5
+ /** `name` passed to `defineComponent`, the mixin's place in the explorer. */
6
+ name?: string;
5
7
  } | {
6
8
  error: string;
7
9
  };
10
+ /** How a mixin declares its schema, see `./discovery.ts`. */
11
+ type MixinSchemaForm = 'defineComponent' | 'mixinSchema';
8
12
 
9
13
  type Mode = StyleguideConfiguration['mode'];
10
14
 
@@ -22,11 +26,12 @@ interface PugMixinJob {
22
26
  file: string;
23
27
  name: string;
24
28
  }
25
- /** Evaluate one `mixinSchema` block and convert it to JSON Schema (see `lib/mixins/schema.ts`). */
29
+ /** Evaluate one schema block and convert it to JSON Schema (see `lib/mixins/schema.ts`). */
26
30
  interface PugSchemaJob {
27
31
  kind: 'schema';
28
32
  id: string;
29
33
  source: string;
34
+ form: MixinSchemaForm;
30
35
  }
31
36
  type PugWorkerInput = PugSectionJob | PugMixinJob | PugSchemaJob;
32
37
  interface PugWorkerSuccess {
@@ -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.tLBfjOgj.mjs';
2
+ import { r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, a as compileMarkup, p as pugErrorFile } from '../../shared/kss-modern.AIWT72eU.mjs';
3
3
  import 'node:path';
4
4
  import 'pug';
5
5
  import 'node:fs';
@@ -20,7 +20,7 @@ parentPort.on("message", async (data) => {
20
20
  try {
21
21
  if (data.kind === "schema") {
22
22
  const z = requireZod();
23
- const schema = z ? evaluateMixinSchema(z, data.source) : { error: "zod 4 is not installed" };
23
+ const schema = z ? evaluateMixinSchema(z, data.source, data.form) : { error: "zod 4 is not installed" };
24
24
  parentPort.postMessage({ id, schema });
25
25
  return;
26
26
  }
@@ -100,23 +100,35 @@ function generateId() {
100
100
  return value;
101
101
  }
102
102
 
103
+ const DEFINE_COMPONENT_RE = /\bdefineComponent\s*\(/;
103
104
  const MIXIN_SCHEMA_RE = /\bmixinSchema\s*=/;
104
105
  const MIXIN_NAME_RE = /^\s*(?:var|let|const)\s+mixinName\s*=\s*(['"])([^'"\n]*)\1\s*(?:;\s*)?$/;
106
+ const DEFINE_NAME_RE = /\bdefineComponent\s*\(\s*\{\s*name\s*:\s*(['"])([^'"\n]*)\1/;
107
+ const DEFINE_NAME_LINE_RE = /^\s*name\s*:\s*(['"])([^'"\n]*)\1\s*(?:,\s*)?$/m;
105
108
  const MIXIN_KEYWORD_RE = /^\s*mixin\s/m;
109
+ function readDefineComponentName(source) {
110
+ return (DEFINE_NAME_RE.exec(source) ?? DEFINE_NAME_LINE_RE.exec(source))?.[2];
111
+ }
106
112
  function findMixinCode(block) {
107
- const found = {};
113
+ let defineSource;
114
+ let schemaSource;
115
+ let mixinName;
108
116
  walk(block, (node) => {
109
117
  if (node.type === "Mixin")
110
118
  return false;
111
119
  if (node.type !== "Code" || node.buffer)
112
120
  return;
113
- if (found.schemaSource === void 0 && MIXIN_SCHEMA_RE.test(node.val))
114
- found.schemaSource = node.val;
121
+ if (defineSource === void 0 && DEFINE_COMPONENT_RE.test(node.val))
122
+ defineSource = node.val;
123
+ if (schemaSource === void 0 && MIXIN_SCHEMA_RE.test(node.val))
124
+ schemaSource = node.val;
115
125
  const name = MIXIN_NAME_RE.exec(node.val)?.[2];
116
- if (found.mixinName === void 0 && name !== void 0)
117
- found.mixinName = name;
126
+ if (mixinName === void 0 && name !== void 0)
127
+ mixinName = name;
118
128
  });
119
- return found;
129
+ if (defineSource !== void 0)
130
+ return { schemaSource: defineSource, isDefineComponent: true, mixinName: readDefineComponentName(defineSource) ?? mixinName };
131
+ return { schemaSource, mixinName };
120
132
  }
121
133
  function discoverMixins(source, filename) {
122
134
  if (!MIXIN_KEYWORD_RE.test(source))
@@ -146,16 +158,30 @@ function createComment(val, node) {
146
158
  function hasStartMarker(nodes) {
147
159
  return nodes.some((node) => node.type === "Comment" && node.buffer === true && node.val?.trim().startsWith("START "));
148
160
  }
161
+ const DEFINE_COMPONENT_CALL_RE = /\bdefineComponent\s*\(/;
162
+ function passMixinName(block, name) {
163
+ let isPassed = false;
164
+ walk(block, (node) => {
165
+ if (isPassed || node.type === "Mixin")
166
+ return false;
167
+ if (node.type !== "Code" || node.buffer || typeof node.val !== "string" || !DEFINE_COMPONENT_CALL_RE.test(node.val))
168
+ return;
169
+ node.val = node.val.replace(DEFINE_COMPONENT_CALL_RE, `defineComponent.call(${JSON.stringify({ mixin: name })}, `);
170
+ isPassed = true;
171
+ });
172
+ }
149
173
  const mixinMarkerPlugin = {
150
174
  preCodeGen(ast) {
151
175
  return walk(ast, (node) => {
152
176
  if (node.type !== "Mixin" || node.call || !node.block || typeof node.name !== "string")
153
177
  return;
154
- if (hasStartMarker(node.block.nodes))
155
- return;
156
- const { schemaSource, mixinName } = findMixinCode(node.block);
178
+ const { schemaSource, isDefineComponent, mixinName } = findMixinCode(node.block);
157
179
  if (schemaSource === void 0)
158
180
  return;
181
+ if (isDefineComponent)
182
+ passMixinName(node.block, node.name);
183
+ if (hasStartMarker(node.block.nodes))
184
+ return;
159
185
  const markerName = getMixinMarkerName(node.name, mixinName);
160
186
  node.block.nodes = [
161
187
  createComment(` START ${markerName}`, node),
@@ -277,14 +303,14 @@ function isLiteral(value) {
277
303
  function checkKeys(schema, allowed) {
278
304
  return Object.keys(schema).filter((key) => !allowed.includes(key)).map((key) => `uses "${key}", which comes from a zod feature the playground does not support`);
279
305
  }
280
- function checkEntry(schema) {
306
+ function checkObjectFields(schema, position) {
281
307
  if (!isObject(schema.properties))
282
308
  return ["is an object without fields, which is not supported"];
283
309
  const errors = checkKeys(schema, ENTRY_KEYS);
284
310
  if (schema.additionalProperties !== void 0 && schema.additionalProperties !== false)
285
311
  errors.push("allows unknown keys (z.looseObject or .catchall()), which is not supported");
286
312
  for (const [key, field] of Object.entries(schema.properties)) {
287
- const fieldErrors = isObject(field) ? checkValue(field, "entry-field") : ["is not a schema"];
313
+ const fieldErrors = isObject(field) ? checkValue(field, position) : ["is not a schema"];
288
314
  errors.push(...fieldErrors.map((error) => `field "${key}" ${error}`));
289
315
  }
290
316
  return errors;
@@ -341,19 +367,21 @@ function checkValue(schema, position) {
341
367
  }
342
368
  case "object":
343
369
  if (position === "array-item")
344
- return checkEntry(schema);
370
+ return checkObjectFields(schema, "entry-field");
345
371
  if (position === "entry-field")
346
372
  return ["is an object, the fields of a list entry must be scalars"];
347
373
  if (isRecord(schema))
348
374
  return checkRecord(schema);
349
- return ["is an object, nested objects are not supported; use an array of objects for a list of entries or z.record() for a map"];
375
+ if (position === "group-field")
376
+ return ["is an object inside an object prop, only one level of nesting is supported"];
377
+ return checkObjectFields(schema, "group-field");
350
378
  default:
351
379
  return ["has a type the playground cannot edit (e.g. z.any() or z.unknown())"];
352
380
  }
353
381
  }
354
382
  function checkSchemaSupport(schema) {
355
383
  if (schema.type !== "object" || !isObject(schema.properties))
356
- return ["mixinSchema must be a z.object({ \u2026 }) of props"];
384
+ return ["the schema must be a z.object({ \u2026 }) of props"];
357
385
  const errors = checkKeys(schema, ROOT_KEYS).map((error) => `the schema ${error}`);
358
386
  if (schema.additionalProperties !== void 0 && schema.additionalProperties !== false)
359
387
  errors.push("the schema allows unknown keys (z.looseObject or .catchall()), which is not supported");
@@ -364,12 +392,35 @@ function checkSchemaSupport(schema) {
364
392
  return errors;
365
393
  }
366
394
 
367
- function evaluateMixinSchema(z, source) {
395
+ function runMixinSchemaBlock(z, source) {
396
+ return { schema: new Function("z", `${source}
397
+ return mixinSchema`)(z) };
398
+ }
399
+ function runDefineComponentBlock(z, source) {
400
+ let definition;
401
+ let isCalled = false;
402
+ const recordDefinition = (value) => {
403
+ if (!isCalled) {
404
+ definition = value;
405
+ isCalled = true;
406
+ }
407
+ return {};
408
+ };
409
+ new Function("z", "defineComponent", "props", source)(z, recordDefinition, void 0);
410
+ if (!isCalled)
411
+ throw new Error("The block does not call `defineComponent`");
412
+ if (!definition || typeof definition !== "object")
413
+ throw new Error("`defineComponent` expects an object `{ name, schema }`");
414
+ const { name, schema } = definition;
415
+ if (name !== void 0 && typeof name !== "string")
416
+ throw new Error("`name` of `defineComponent` must be a string");
417
+ return { schema, name };
418
+ }
419
+ function evaluateMixinSchema(z, source, form = "mixinSchema") {
368
420
  try {
369
- const schema = new Function("z", `${source}
370
- return mixinSchema`)(z);
421
+ const { schema, name } = form === "defineComponent" ? runDefineComponentBlock(z, source) : runMixinSchemaBlock(z, source);
371
422
  if (!schema || typeof schema !== "object" || !("_zod" in schema))
372
- return { error: "`mixinSchema` is not a zod schema" };
423
+ return { error: form === "defineComponent" ? "`schema` of `defineComponent` is not a zod schema" : "`mixinSchema` is not a zod schema" };
373
424
  const jsonSchema = z.toJSONSchema(schema, {
374
425
  io: "input",
375
426
  // a type JSON Schema cannot describe (dates, maps, …) cannot get a control either
@@ -379,7 +430,7 @@ return mixinSchema`)(z);
379
430
  if (unsupported.length > 0)
380
431
  return { error: `The schema uses zod features the playground does not support:
381
432
  ${unsupported.map((line) => `- ${line}`).join("\n")}` };
382
- return { jsonSchema };
433
+ return name === void 0 ? { jsonSchema } : { jsonSchema, name };
383
434
  } catch (error) {
384
435
  return { error: error instanceof Error ? error.message : String(error) };
385
436
  }
@@ -409,6 +460,44 @@ function requireZod() {
409
460
  return zodNamespace;
410
461
  }
411
462
 
463
+ class ComponentPropsError extends Error {
464
+ issues;
465
+ constructor(message, issues) {
466
+ super(message);
467
+ this.name = "ComponentPropsError";
468
+ this.issues = issues;
469
+ }
470
+ }
471
+ function formatIssuePath(path) {
472
+ return path.reduce((formatted, segment) => {
473
+ if (typeof segment === "number")
474
+ return `${formatted}[${segment}]`;
475
+ if (typeof segment === "symbol")
476
+ return formatted;
477
+ return formatted ? `${formatted}.${segment}` : segment;
478
+ }, "");
479
+ }
480
+ function getErrorPrefix(name, mixin) {
481
+ return [name, mixin ? `(+${mixin})` : void 0].filter(Boolean).join(" ") || "defineComponent";
482
+ }
483
+ function formatComponentPropsError(issues, name, mixin) {
484
+ const prefix = getErrorPrefix(name, mixin);
485
+ return issues.map((issue) => {
486
+ const path = formatIssuePath(issue.path);
487
+ return path ? `${prefix}: ${path}: ${issue.message}` : `${prefix}: ${issue.message}`;
488
+ }).join("\n");
489
+ }
490
+ function defineComponent(definition, props) {
491
+ const mixin = this && typeof this.mixin === "string" ? this.mixin : void 0;
492
+ const name = typeof definition?.name === "string" ? definition.name : void 0;
493
+ if (typeof definition?.schema?.safeParse !== "function")
494
+ throw new TypeError(`${getErrorPrefix(name, mixin)}: \`schema\` must be a zod schema`);
495
+ const result = definition.schema.safeParse(props);
496
+ if (result.success)
497
+ return result.data;
498
+ throw new ComponentPropsError(formatComponentPropsError(result.error.issues, name, mixin), result.error.issues);
499
+ }
500
+
412
501
  function createUseId(sectionId) {
413
502
  const namespace = `id-${sectionSanitizeId(sectionId)}`;
414
503
  let autoCounter = 0;
@@ -532,7 +621,7 @@ function compilePugFile(pugFilePath, mode, sectionId, extraLocals = {}) {
532
621
  plugins: [mixinMarkerPlugin, mixinTracePlugin]
533
622
  });
534
623
  const dependencies = [path.resolve(pugFilePath), ...pugFn.dependencies.map((dep) => path.resolve(dep))];
535
- const locals = { modifierClass: "{{modifier_class}}", ...extraLocals, useId: createUseId(sectionId) };
624
+ const locals = { modifierClass: "{{modifier_class}}", ...extraLocals, useId: createUseId(sectionId), defineComponent };
536
625
  Object.defineProperty(locals, "z", { enumerable: true, get: requireZod });
537
626
  const trace = createMixinTrace();
538
627
  locals[MIXIN_TRACE_LOCAL] = trace;
@@ -13,7 +13,7 @@ interface MixinManifestEntry {
13
13
  id: string;
14
14
  name: string;
15
15
  /**
16
- * Where the mixin sits in the explorer: the segments of its `mixinName` (`'atoms/button'` ->
16
+ * Where the mixin sits in the explorer: the segments of its `defineComponent` `name` or `mixinName` (`'atoms/button'` ->
17
17
  * `['atoms', 'button']`), or just its Pug name without one. The last segment is its label.
18
18
  */
19
19
  path: string[];
@@ -23,13 +23,13 @@ interface MixinManifestEntry {
23
23
  file: string;
24
24
  /** 1-based line of the `mixin` keyword. */
25
25
  line: number;
26
- /** The mixin declares a usable `mixinSchema`, so it gets a playground. */
26
+ /** The mixin declares a usable schema (`defineComponent` or `mixinSchema`), so it gets a playground. */
27
27
  hasSchema: boolean;
28
28
  /** `.describe()` of the schema itself, shown under the mixin's name. */
29
29
  description?: string;
30
30
  /** The schema as JSON Schema (`io: 'input'`), present when `hasSchema`. */
31
31
  jsonSchema?: Record<string, unknown>;
32
- /** Why a declared `mixinSchema` could not be used. The mixin is then treated as schema-less. */
32
+ /** Why a declared schema could not be used. The mixin is then treated as schema-less. */
33
33
  schemaError?: string;
34
34
  /** Render module, relative to the output directory. Content-hashed, so a URL never goes stale. */
35
35
  module?: string;
@@ -40,7 +40,7 @@ interface MixinManifestEntry {
40
40
  };
41
41
  }
42
42
  /**
43
- * Only mixins that declare a `mixinSchema` are public. All others are internal building blocks and
43
+ * Only mixins that declare a schema, with `defineComponent` or `mixinSchema`, are public. All others are internal building blocks and
44
44
  * stay out of the manifest and the styleguide. A schema that fails to evaluate still counts, so the
45
45
  * broken schema shows up instead of the mixin silently vanishing.
46
46
  */
@@ -13,7 +13,7 @@ interface MixinManifestEntry {
13
13
  id: string;
14
14
  name: string;
15
15
  /**
16
- * Where the mixin sits in the explorer: the segments of its `mixinName` (`'atoms/button'` ->
16
+ * Where the mixin sits in the explorer: the segments of its `defineComponent` `name` or `mixinName` (`'atoms/button'` ->
17
17
  * `['atoms', 'button']`), or just its Pug name without one. The last segment is its label.
18
18
  */
19
19
  path: string[];
@@ -23,13 +23,13 @@ interface MixinManifestEntry {
23
23
  file: string;
24
24
  /** 1-based line of the `mixin` keyword. */
25
25
  line: number;
26
- /** The mixin declares a usable `mixinSchema`, so it gets a playground. */
26
+ /** The mixin declares a usable schema (`defineComponent` or `mixinSchema`), so it gets a playground. */
27
27
  hasSchema: boolean;
28
28
  /** `.describe()` of the schema itself, shown under the mixin's name. */
29
29
  description?: string;
30
30
  /** The schema as JSON Schema (`io: 'input'`), present when `hasSchema`. */
31
31
  jsonSchema?: Record<string, unknown>;
32
- /** Why a declared `mixinSchema` could not be used. The mixin is then treated as schema-less. */
32
+ /** Why a declared schema could not be used. The mixin is then treated as schema-less. */
33
33
  schemaError?: string;
34
34
  /** Render module, relative to the output directory. Content-hashed, so a URL never goes stale. */
35
35
  module?: string;
@@ -40,7 +40,7 @@ interface MixinManifestEntry {
40
40
  };
41
41
  }
42
42
  /**
43
- * Only mixins that declare a `mixinSchema` are public. All others are internal building blocks and
43
+ * Only mixins that declare a schema, with `defineComponent` or `mixinSchema`, are public. All others are internal building blocks and
44
44
  * stay out of the manifest and the styleguide. A schema that fails to evaluate still counts, so the
45
45
  * broken schema shows up instead of the mixin silently vanishing.
46
46
  */
@@ -21,8 +21,8 @@
21
21
  "file": "code-highlight-Fm7cxf-E.js",
22
22
  "name": "code-highlight"
23
23
  },
24
- "_controller-drB07Xo_.js": {
25
- "file": "controller-drB07Xo_.js",
24
+ "_controller-CKWfjaws.js": {
25
+ "file": "controller-CKWfjaws.js",
26
26
  "name": "controller",
27
27
  "imports": [
28
28
  "_utils-DtB-AzJa.js",
@@ -147,14 +147,14 @@
147
147
  ]
148
148
  },
149
149
  "client/lib/playground/explorer.ts": {
150
- "file": "explorer-BivD2FYm.js",
150
+ "file": "explorer-Des7B6PH.js",
151
151
  "name": "explorer",
152
152
  "src": "client/lib/playground/explorer.ts",
153
153
  "isDynamicEntry": true,
154
154
  "imports": [
155
155
  "_code-highlight-Fm7cxf-E.js",
156
156
  "_utils-DtB-AzJa.js",
157
- "_controller-drB07Xo_.js",
157
+ "_controller-CKWfjaws.js",
158
158
  "_alerts-DIQ8TeZB.js"
159
159
  ]
160
160
  },
@@ -169,13 +169,13 @@
169
169
  ]
170
170
  },
171
171
  "client/playground.ts": {
172
- "file": "playground-BBMnDZ8b.js",
172
+ "file": "playground-B_pD0mat.js",
173
173
  "name": "playground",
174
174
  "src": "client/playground.ts",
175
175
  "isEntry": true,
176
176
  "imports": [
177
177
  "_shared-hGcWlnRM.js",
178
- "_controller-drB07Xo_.js"
178
+ "_controller-CKWfjaws.js"
179
179
  ]
180
180
  },
181
181
  "client/preview-inline.ts": {
@@ -185,7 +185,7 @@
185
185
  "isEntry": true
186
186
  },
187
187
  "client/preview.ts": {
188
- "file": "preview-BkKvdDnK.js",
188
+ "file": "preview-C7DV5Nmc.js",
189
189
  "name": "preview",
190
190
  "src": "client/preview.ts",
191
191
  "isEntry": true,