@yahoo/uds-create-config 5.96.5 → 5.97.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.
Files changed (33) hide show
  1. package/dist/configs/system.js +2 -0
  2. package/dist/entities/system/Source.d.ts +1 -0
  3. package/dist/entities/system/Source.js +39 -3
  4. package/dist/entities/system/component-module.d.ts +15 -1
  5. package/dist/entities/system/component-module.js +76 -5
  6. package/dist/entities/system/copy-plan.js +2 -1
  7. package/dist/entities/system/defineComponent.d.ts +7 -1
  8. package/dist/entities/system/icon-library.js +9 -0
  9. package/dist/entities/system/vendor-conditions.d.ts +67 -0
  10. package/dist/entities/system/vendor-conditions.js +253 -0
  11. package/dist/framework/Config.d.ts +24 -2
  12. package/dist/framework/Config.js +44 -6
  13. package/dist/framework/class-names.js +7 -4
  14. package/dist/framework/module-views.d.ts +9 -1
  15. package/dist/framework/projections.js +56 -10
  16. package/dist/framework/prop-surface.d.ts +7 -1
  17. package/dist/framework/prop-surface.js +140 -37
  18. package/dist/framework/ref-integrity.js +1 -0
  19. package/dist/framework/registry.d.ts +3 -1
  20. package/dist/framework/render-spec.js +6 -0
  21. package/dist/framework/schema-version.d.ts +1 -1
  22. package/dist/framework/schema-version.js +5 -5
  23. package/dist/framework/source-integrity.js +1 -0
  24. package/dist/index.d.ts +6 -5
  25. package/dist/index.js +5 -4
  26. package/dist/lint/rules.d.ts +6 -0
  27. package/dist/lint/rules.js +6 -0
  28. package/dist/migrations/20261112163439_vendor_link_type.d.ts +8 -0
  29. package/dist/migrations/20261112163439_vendor_link_type.js +10 -0
  30. package/dist/spec/glyph-jsx.js +4 -2
  31. package/dist/spec/glyph-members.js +3 -1
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +2 -2
@@ -51,6 +51,7 @@ import { computedVisibilityMigration } from "../migrations/20261110145811_comput
51
51
  import { anatomyNodeStatesMigration } from "../migrations/20261110171151_anatomy_node_states.js";
52
52
  import { nativeLintLocationsMigration } from "../migrations/20261112145536_native_lint_locations.js";
53
53
  import { variantBooleansMigration } from "../migrations/20261112154943_variant_booleans.js";
54
+ import { vendorLinkTypeMigration } from "../migrations/20261112163439_vendor_link_type.js";
54
55
  import { CanvasRole } from "../entities/system/CanvasRole.js";
55
56
  import { GlobalStyle } from "../entities/system/GlobalStyle.js";
56
57
  import { Guidance } from "../entities/system/Guidance.js";
@@ -238,5 +239,6 @@ if (!registeredSchemaMigrations().has(20261110145811)) registerSchemaMigrations(
238
239
  if (!registeredSchemaMigrations().has(20261110171151)) registerSchemaMigrations(anatomyNodeStatesMigration);
239
240
  if (!registeredSchemaMigrations().has(20261112145536)) registerSchemaMigrations(nativeLintLocationsMigration);
240
241
  if (!registeredSchemaMigrations().has(20261112154943)) registerSchemaMigrations(variantBooleansMigration);
242
+ if (!registeredSchemaMigrations().has(20261112163439)) registerSchemaMigrations(vendorLinkTypeMigration);
241
243
  //#endregion
242
244
  export { System };
@@ -112,6 +112,7 @@ declare const LinkedSystemDefinition: EntityClass<z.ZodObject<{
112
112
  type: z.ZodOptional<z.ZodEnum<{
113
113
  linked: "linked";
114
114
  hybrid: "hybrid";
115
+ vendor: "vendor";
115
116
  }>>;
116
117
  version: z.ZodOptional<z.ZodString>;
117
118
  }, z.core.$strict>, z.ZodObject<Record<never, never>, z.core.$strip>, "source", {
@@ -8,6 +8,7 @@ import { storedStyleRules } from "./Component.js";
8
8
  import { foldRetiredFields } from "../../framework/retired-fields.js";
9
9
  import { sourceUnreachable } from "../../framework/sources.js";
10
10
  import { covers, directivesOf, excludes, includeOf } from "./link-declaration.js";
11
+ import { isVendorModifierMapping, vendorModifierMappingProblems } from "./vendor-conditions.js";
11
12
  import { planCopy } from "./copy-plan.js";
12
13
  import { planBreak, planExclude, planLink, planLinkApplied, planUnlink, sourceRowStates } from "./link-plan.js";
13
14
  import { z } from "zod";
@@ -369,7 +370,8 @@ const LinkedSystemDefinition = defineEntity({
369
370
  invariants: (config) => [
370
371
  ...config.list("source").filter(({ path }) => !isLinkSlug(path)).map(({ path }) => `Link "${path}": ${LINK_SLUG_MESSAGE}`),
371
372
  ...linkRedirects(config).filter((redirect) => redirect.problem !== void 0 && redirect.problem !== "missing").map(redirectSentence),
372
- ...excludedDirectives(config)
373
+ ...excludedDirectives(config),
374
+ ...vendorDirectives(config)
373
375
  ],
374
376
  schemas: {
375
377
  create: { example: ({ config }) => {
@@ -774,8 +776,19 @@ const LinkedSystemDefinition = defineEntity({
774
776
  * The same holds for the motion presets and composites a taken component names: through a
775
777
  * `hybrid` link it plays this system's of that name, and otherwise the source's own, emitted
776
778
  * under the pin's names.
779
+ *
780
+ * `vendor` brings in only the entities its `options.include` names. Nothing they reference lands
781
+ * as a row: a taken component draws every value from its own source under the pin's names, and so
782
+ * do the components it renders. Its `options` take only `hidden`, since a product value laid over
783
+ * it would mix this system's vocabulary into the source's, and a modifier's `override` naming one
784
+ * of this system's modifiers, which says when the vendor's values apply and changes none of them
785
+ * (`vendor-conditions.ts`).
777
786
  */
778
- type: z.enum(["linked", "hybrid"]).optional().describe("How this source joins the system: `linked` (the default) brings in everything its entities reference and refuses a path another link offers differently; `hybrid` brings in only what no other link offers and uses this system's tokens, motion presets and composites wherever it has one of the same name."),
787
+ type: z.enum([
788
+ "linked",
789
+ "hybrid",
790
+ "vendor"
791
+ ]).optional().describe("How this source joins the system: `linked` (the default) brings in everything its entities reference and refuses a path another link offers differently; `hybrid` brings in only what no other link offers and uses this system's tokens, motion presets and composites wherever it has one of the same name; `vendor` brings in only what `options.include` names, drawn entirely from the source's own values, with no `override` or `extend` in `options` except a modifier's `override` naming the modifier of this system it stands for."),
779
792
  /**
780
793
  * The exact published version every ref through this link resolves against.
781
794
  *
@@ -846,7 +859,10 @@ displayName: ({ member, path }) => typeof member.name === "string" && member.nam
846
859
  accessor: accessor ?? kind,
847
860
  path
848
861
  }),
849
- sourceType: (body) => body.type === "hybrid" ? "hybrid" : "linked",
862
+ sourceType: (body) => {
863
+ const { type } = body;
864
+ return type === "hybrid" || type === "vendor" ? type : "linked";
865
+ },
850
866
  bulkExcludes: ({ body, kind, accessor, path }) => excludes({
851
867
  declared: includeOf(body),
852
868
  accessor: accessor ?? kind,
@@ -935,6 +951,26 @@ function excludedDirectives(config) {
935
951
  })).map((path) => `Link "${slug}": options.${accessor}["${path}"] adjusts a path its \`options.include\` excludes, which derives no row. Drop the entry, or the exclusion.`) : []);
936
952
  });
937
953
  }
954
+ /**
955
+ * Each `options` entry that changes what a `vendor` source brings. A vendor's entities draw every value
956
+ * from their own source, so a product value laid over one would mix the two systems' vocabularies,
957
+ * and the typing of its props from that source would no longer hold. `hidden` changes nothing it
958
+ * draws, so it stays. So does a modifier pointed at one of this system's
959
+ * ({@link isVendorModifierMapping}): it changes when the vendor's values apply, and none of them.
960
+ */
961
+ function vendorDirectives(config) {
962
+ return config.list("source").flatMap(({ path: slug }) => {
963
+ if (config.sourceTypeOf(slug) !== "vendor") return [];
964
+ return [...directivesOf(config.storedBody("source", slug)).flatMap(([accessor, entries]) => isPlainObject(entries) ? Object.entries(entries).filter(([, entry]) => isPlainObject(entry) && (entry.override !== void 0 || entry.extend !== void 0) && !isVendorModifierMapping({
965
+ config,
966
+ accessor,
967
+ entry
968
+ })).map(([path]) => `Link "${slug}": options.${accessor}["${path}"] changes what a vendor source brings, which is used as shipped. To change it, wrap it in a component of your own; a vendor entry takes only \`hidden\`, or for a modifier an \`override\` naming the modifier of this system it stands for.`) : []), ...vendorModifierMappingProblems({
969
+ config,
970
+ slug
971
+ })];
972
+ });
973
+ }
938
974
  /** The `options` entry for one path, or `undefined` where the pin says nothing about it. */
939
975
  function directiveAt(body, accessor, path) {
940
976
  return body.options?.[accessor]?.[path];
@@ -125,6 +125,20 @@ declare function linkedModuleView({
125
125
  readonly shadowed: boolean;
126
126
  readonly route?: string;
127
127
  }): Config;
128
+ /**
129
+ * A `vendor` pin's source as this config's stylesheet and runtime name its style props: the source's
130
+ * own style properties and values, under the pin's class prefix (`shop-acme`) and the variable
131
+ * namespace its tokens are declared under here. A value one of its components passes another
132
+ * (`<Box bg="paper">` in its render) paints the source's `paper`, and names no class of this config's.
133
+ * `undefined` for a pin that isn't `vendor`, or whose source isn't attached.
134
+ */
135
+ declare function vendorStyleView({
136
+ consumer,
137
+ slug
138
+ }: {
139
+ readonly consumer: Config;
140
+ readonly slug: string;
141
+ }): Config | undefined;
128
142
  /**
129
143
  * A linked component's module source, and the config its module is built from.
130
144
  *
@@ -138,4 +152,4 @@ declare function linkedComponentModule(config: Config, componentPathOrRef: strin
138
152
  readonly view: Config;
139
153
  } | undefined;
140
154
  //#endregion
141
- export { COMPONENT_ENTRY_STATIC, CREATED_COMPONENT_DIRECTORY, ComponentModuleSource, ComponentRegistryImport, ComponentRegistryImportBinding, componentModuleFilePaths, componentModuleKey, componentModuleSource, componentRegistryImports, createdComponentFilePath, createdComponentPathOf, createdModuleKey, isCreatedComponent, linkedComponentModule, linkedModuleView };
155
+ export { COMPONENT_ENTRY_STATIC, CREATED_COMPONENT_DIRECTORY, ComponentModuleSource, ComponentRegistryImport, ComponentRegistryImportBinding, componentModuleFilePaths, componentModuleKey, componentModuleSource, componentRegistryImports, createdComponentFilePath, createdComponentPathOf, createdModuleKey, isCreatedComponent, linkedComponentModule, linkedModuleView, vendorStyleView };
@@ -4,9 +4,12 @@ import { createSliceMemo } from "../../framework/memo.js";
4
4
  import { moduleViewOf, registerModuleView } from "../../framework/module-views.js";
5
5
  import { File } from "./File.js";
6
6
  import { Settings, classPrefixOf, prefixed, varPrefixOf } from "./Settings.js";
7
+ import { sourceVarPrefix } from "../../framework/projections.js";
8
+ import { hasJsMotion } from "./motion-presets.js";
7
9
  import { stylePropClassBase, stylePropOwnClasses } from "../../framework/class-names.js";
8
10
  import { Component } from "./Component.js";
9
11
  import { contentKey } from "../../framework/utils/content-key.js";
12
+ import { recordStatedModifiers, statedModifiersOf, vendorSource } from "./vendor-conditions.js";
10
13
  //#region src/entities/system/component-module.ts
11
14
  /**
12
15
  * What names a compiled component module: a content key over the module's config-visible build
@@ -126,9 +129,31 @@ function componentRuntimeKey(config) {
126
129
  settings: Settings.get(config)?.toJSON(),
127
130
  entities: componentRuntimeEntitiesKey(config),
128
131
  inputDir: Settings.get(config)?.inputDir,
129
- ...viewClassNamesKey(config)
132
+ ...viewClassNamesKey(config),
133
+ ...viewHostKey(config)
130
134
  });
131
135
  }
136
+ const viewHosts = /* @__PURE__ */ new WeakMap();
137
+ /**
138
+ * What a module view's consumer decides about the module beyond its class names: whether the
139
+ * consumer plays a JS motion preset (the module wraps itself in the motion module only then), and the
140
+ * pin the view was built for, whose type and `include` decide which of the source's components are
141
+ * the consumer's rows and which style properties the pin reaches. Empty for a config that isn't a view.
142
+ */
143
+ function viewHostKey(config) {
144
+ const link = moduleViewOf(config);
145
+ if (!link) return {};
146
+ let key = viewHosts.get(config);
147
+ if (key === void 0) {
148
+ const [declared] = sourceHops(link.slug);
149
+ key = contentKey({
150
+ jsMotion: hasJsMotion(link.consumer),
151
+ pin: declared === void 0 ? void 0 : link.consumer.resolve("source", declared)?.toJSON()
152
+ });
153
+ viewHosts.set(config, key);
154
+ }
155
+ return { host: key };
156
+ }
132
157
  const viewClassNames = /* @__PURE__ */ new WeakMap();
133
158
  /**
134
159
  * A module view's style-prop classes, which the consumer's rows name where it holds one
@@ -373,7 +398,7 @@ function linkedModuleView({ consumer, owner, slug, shadowed, route = slug }) {
373
398
  prefix: classPrefixOf(consumer),
374
399
  name: slug
375
400
  }) : classPrefixOf(consumer);
376
- const view = owner.apply({
401
+ const named = owner.apply({
377
402
  kind: "settings",
378
403
  operation: "update",
379
404
  path: "settings",
@@ -382,7 +407,8 @@ function linkedModuleView({ consumer, owner, slug, shadowed, route = slug }) {
382
407
  variables: varPrefixOf(owner)
383
408
  } }
384
409
  });
385
- if (view !== owner) registerModuleView({
410
+ const view = named === owner ? owner.fork() : named;
411
+ registerModuleView({
386
412
  view,
387
413
  link: {
388
414
  consumer,
@@ -391,6 +417,51 @@ function linkedModuleView({ consumer, owner, slug, shadowed, route = slug }) {
391
417
  });
392
418
  return view;
393
419
  }
420
+ /**
421
+ * A `vendor` pin's source as this config's stylesheet and runtime name its style props: the source's
422
+ * own style properties and values, under the pin's class prefix (`shop-acme`) and the variable
423
+ * namespace its tokens are declared under here. A value one of its components passes another
424
+ * (`<Box bg="paper">` in its render) paints the source's `paper`, and names no class of this config's.
425
+ * `undefined` for a pin that isn't `vendor`, or whose source isn't attached.
426
+ */
427
+ function vendorStyleView({ consumer, slug }) {
428
+ if (consumer.sourceTypeOf(slug) !== "vendor") return void 0;
429
+ const owner = consumer.sourceFor(slug);
430
+ if (!owner) return void 0;
431
+ let bySlug = vendorViews.get(consumer);
432
+ if (!bySlug) {
433
+ bySlug = /* @__PURE__ */ new Map();
434
+ vendorViews.set(consumer, bySlug);
435
+ }
436
+ const held = bySlug.get(slug);
437
+ if (held?.owner === owner) return held.view;
438
+ const stated = vendorSource({
439
+ consumer,
440
+ slug
441
+ }) ?? owner;
442
+ const view = stated.apply({
443
+ kind: "settings",
444
+ operation: "update",
445
+ path: "settings",
446
+ data: { "css.prefix": {
447
+ classNames: prefixed({
448
+ prefix: classPrefixOf(consumer),
449
+ name: slug
450
+ }),
451
+ variables: sourceVarPrefix(consumer, slug)
452
+ } }
453
+ });
454
+ recordStatedModifiers({
455
+ config: view,
456
+ bound: statedModifiersOf(stated)
457
+ });
458
+ bySlug.set(slug, {
459
+ owner,
460
+ view
461
+ });
462
+ return view;
463
+ }
464
+ const vendorViews = /* @__PURE__ */ new WeakMap();
394
465
  /** Views are built per consumer, owner, slug and shadowing, since every linked component of one owner
395
466
  * shares one. */
396
467
  const views = /* @__PURE__ */ new WeakMap();
@@ -441,7 +512,7 @@ function linkedComponentModule(config, componentPathOrRef) {
441
512
  const owner = config.configFor(fileRef);
442
513
  const pin = publishedPin(config, slug);
443
514
  if (!owner || !pin) return void 0;
444
- const shadowed = askedSource !== void 0;
515
+ const shadowed = askedSource !== void 0 && parsed !== void 0 && config.resolve(Component.kind, parsed.path) !== void 0;
445
516
  const view = cachedView(config, (shadowed && owner === config.sourceFor(slug) ? config.drawnSourceFor(slug) : void 0) ?? owner, slug, shadowed);
446
517
  const moduleKey = componentModuleKey(view, filePath);
447
518
  if (!moduleKey) return void 0;
@@ -492,4 +563,4 @@ function publishedPin(config, slug) {
492
563
  }
493
564
  }
494
565
  //#endregion
495
- export { COMPONENT_ENTRY_STATIC, CREATED_COMPONENT_DIRECTORY, componentModuleFilePaths, componentModuleKey, componentModuleSource, componentRegistryImports, createdComponentFilePath, createdComponentPathOf, createdModuleKey, isCreatedComponent, linkedComponentModule, linkedModuleView };
566
+ export { COMPONENT_ENTRY_STATIC, CREATED_COMPONENT_DIRECTORY, componentModuleFilePaths, componentModuleKey, componentModuleSource, componentRegistryImports, createdComponentFilePath, createdComponentPathOf, createdModuleKey, isCreatedComponent, linkedComponentModule, linkedModuleView, vendorStyleView };
@@ -2,8 +2,8 @@ import { MINTED, collectRefs, isMintedRow, kindOf, pathOf, rewriteRefs, sourceOf
2
2
  import { rejectData } from "../../framework/rejection.js";
3
3
  import { kindBorrowable } from "../../framework/registry.js";
4
4
  import { File } from "./File.js";
5
- import { componentModuleFilePaths, componentRegistryImports } from "./component-module.js";
6
5
  import { PIN_KIND, covers, declarationOf, includeWrite, narrowDeclaration } from "./link-declaration.js";
6
+ import { componentModuleFilePaths, componentRegistryImports } from "./component-module.js";
7
7
  //#region src/entities/system/copy-plan.ts
8
8
  /**
9
9
  * The source's entries one path names: every item of the kind for `'*'`, a folder's members for a
@@ -73,6 +73,7 @@ function planCopy({ config, input }) {
73
73
  const wholesale = input.data === "*";
74
74
  const source = config.sourceFor(slug);
75
75
  if (!source) rejectData(`Cannot copy through "${slug}" — nothing has resolved that link.`);
76
+ if (config.sourceTypeOf(slug) === "vendor") rejectData(`Cannot copy through "${slug}" — it is a vendor source, which is used as shipped. Copied in, its components would draw from this system's entities of the same names. To take them as your own, make the source \`linked\` first.`);
76
77
  /** The kinds named, with what to take of each. An accessor this config has no kind for is refused
77
78
  * by name, since it is a typo rather than a source that offers nothing. */
78
79
  const wanted = [];
@@ -970,6 +970,12 @@ type WidestComponentBuilder = ComponentBuilder<LayerMap, PropMap, unknown, unkno
970
970
  type LinkedHandle<Handle, Props extends PropMap = Record<never, never>, Layers extends Record<string, LayerElement> = Record<never, never>> = Handle extends {
971
971
  metadata(meta: never): infer Builder;
972
972
  } ? Builder extends ComponentBuilder<infer L extends LayerMap, infer P extends PropMap, infer E, infer D, infer F extends string, infer S extends StateMap> ? WithStatics<ComponentBuilder<Without<L, keyof Layers> & Layers extends infer Swapped extends LayerMap ? Swapped : L, CompactProps<Without<P, keyof Props> & Props>, E, D, F, S>, Builder, Omit<Handle, keyof Builder>> : Handle : Handle;
973
+ /**
974
+ * The tombstones a `vendor` pin's handle is laid over with, as {@link LinkedHandle}'s `Props`: this
975
+ * system's style props and modifiers, and the style-property props the component itself or a forwarded
976
+ * layer declares (`Own`). Its values are its source's, so its call site takes none of them.
977
+ */
978
+ type VendorWithheld<Own extends string = never> = { readonly [K in (keyof RegisteredStyleProps & string) | (keyof RegisteredModifiers & string) | Own]: null };
973
979
  /**
974
980
  * A rebuilt handle with the source handle's statics beside it, when it has any. A static whose
975
981
  * builder is the handle's own is the rebuilt handle, with that static's own statics beside it.
@@ -1004,4 +1010,4 @@ interface DefineComponent {
1004
1010
  declare function definePropsFirst<const P extends PropMap<LayerPath>>(props: P & NoInfer<{ [K in keyof P]: Exact<P[K], AuthoredProp<LayerPath>> }>): ComponentBuilder<LayerMap, CompactProps<P>>;
1005
1011
  declare const defineComponent: DefineComponent;
1006
1012
  //#endregion
1007
- export { AsInput, AuthoredComponent, AuthoredDefaultsOf, AuthoredProp, ComponentBuilder, ComponentPropsOf, GlyphComponent, GlyphValue, LayerElement, LayerMap, LinkedHandle, ModifierProps, PhantomCallProps, PhantomReadProps, PropCondition, PropDecl, PropMap, RegisteredMembers, RenderArgs, SlotCodeForm, SlotDecl, StateMap, StyleProps, StyleRefProps, StyleRefs, StyleRuleInput, UnconditionalDefaults, defineComponent };
1013
+ export { AsInput, AuthoredComponent, AuthoredDefaultsOf, AuthoredProp, ComponentBuilder, ComponentPropsOf, GlyphComponent, GlyphValue, LayerElement, LayerMap, LinkedHandle, ModifierProps, PhantomCallProps, PhantomReadProps, PropCondition, PropDecl, PropMap, RegisteredMembers, RenderArgs, SlotCodeForm, SlotDecl, StateMap, StyleProps, StyleRefProps, StyleRefs, StyleRuleInput, UnconditionalDefaults, VendorWithheld, defineComponent };
@@ -51,6 +51,15 @@ const librariesOf = createSliceMemo({
51
51
  compute: (_config) => /* @__PURE__ */ new Map()
52
52
  });
53
53
  function readIconLibrary(config, path) {
54
+ const at = path.lastIndexOf("@");
55
+ if (at > 0) {
56
+ const owner = config.sourceFor(path.slice(at + 1));
57
+ const library = owner ? iconLibrary(owner, path.slice(0, at)) : void 0;
58
+ return library ? {
59
+ ...library,
60
+ path
61
+ } : void 0;
62
+ }
54
63
  const group = Icon.groups(config).find((entry) => entry.path === path);
55
64
  if (!group) return void 0;
56
65
  const { items: _items, sizes, variants, ...meta } = group.meta;
@@ -0,0 +1,67 @@
1
+ import { Config } from "../../framework/Config.js";
2
+
3
+ //#region src/entities/system/vendor-conditions.d.ts
4
+ /**
5
+ * The pin's modifier mappings that map nothing in the attached source: a path the source doesn't
6
+ * hold, or a modifier of another category than ours. Such a modifier keeps the vendor's own
7
+ * activation, which isn't what the entry asked for, so a build reports it.
8
+ */
9
+ declare function unheldVendorModifierMappings({
10
+ config,
11
+ slug
12
+ }: {
13
+ readonly config: Config;
14
+ readonly slug: string;
15
+ }): string[];
16
+ /**
17
+ * The vendor's modifiers this config states as its own, vendor path to our path: the ones the pin
18
+ * maps, then the modes a selector switches that we hold at the same path. A modifier that asks
19
+ * about a surface (`composite`) is never bound, since the surface it asks about is the vendor's.
20
+ */
21
+ declare function vendorModifierBindings({
22
+ consumer,
23
+ slug
24
+ }: {
25
+ readonly consumer: Config;
26
+ readonly slug: string;
27
+ }): ReadonlyMap<string, string>;
28
+ /** A vendor's mode that nothing in the consuming config turns on. */
29
+ interface UnmappedVendorMode {
30
+ readonly slug: string;
31
+ /** The vendor's modifier, by path. */
32
+ readonly modifier: string;
33
+ /** The selector that turns it on. */
34
+ readonly selector: string;
35
+ /** This config's one mode of the same name, which a mapping would most likely name. */
36
+ readonly candidate?: string;
37
+ }
38
+ /**
39
+ * Each mode of a `vendor` pin's source that what the pin takes varies under, and that nothing in
40
+ * this config turns on: a selector switches it, no binding states it as one of ours
41
+ * ({@link vendorModifierBindings}), and none of our modifiers is switched by the same selector. It
42
+ * keeps the vendor's own switch, which only the app can set, so the lint reports it.
43
+ *
44
+ * A mode a query decides is left out, since the device answers it wherever the component renders.
45
+ */
46
+ declare function unmappedVendorModes(config: Config): UnmappedVendorMode[];
47
+ /**
48
+ * A `vendor` pin's source with its bound modifiers activating as this config's do
49
+ * ({@link vendorModifierBindings}). Each keeps the vendor's path, so the vendor's tokens, rules and
50
+ * style props read against it unchanged. `undefined` for a pin that isn't `vendor`, or whose source
51
+ * isn't attached.
52
+ */
53
+ declare function vendorSource({
54
+ consumer,
55
+ slug
56
+ }: {
57
+ readonly consumer: Config;
58
+ readonly slug: string;
59
+ }): Config | undefined;
60
+ /**
61
+ * The path a modifier is stated under: ours, for a vendor's modifier bound to one of ours, and its
62
+ * own otherwise. What names a mode outside the stylesheet's own selector reads this, as the
63
+ * attribute an editor forces a mode with does.
64
+ */
65
+ declare function statedModifierPath(config: Config, path: string): string;
66
+ //#endregion
67
+ export { UnmappedVendorMode, statedModifierPath, unheldVendorModifierMappings, unmappedVendorModes, vendorModifierBindings, vendorSource };
@@ -0,0 +1,253 @@
1
+ import { isRef, kindOf, pathOf, sourceOf } from "../../framework/utils/refs.js";
2
+ import { isPlainObject } from "../../framework/utils/field-path.js";
3
+ import { modifierCategory } from "./modifier-axis.js";
4
+ import { directivesOf } from "./link-declaration.js";
5
+ //#region src/entities/system/vendor-conditions.ts
6
+ /** How a modifier activates. A bound modifier takes these from ours and keeps the rest. */
7
+ const ACTIVATION_FIELDS = [
8
+ "type",
9
+ "value",
10
+ "media",
11
+ "declarations"
12
+ ];
13
+ /** The entries of a pin's `options` that map a vendor modifier, as written. */
14
+ function vendorModifierMappings({ config, slug }) {
15
+ const accessor = config.accessorOf("modifier") ?? "modifier";
16
+ return directivesOf(config.storedBody("source", slug)).flatMap(([named, entries]) => named === accessor && isPlainObject(entries) ? Object.entries(entries).flatMap(([vendor, entry]) => isPlainObject(entry) && entry.override !== void 0 ? [{
17
+ vendor,
18
+ target: entry.override
19
+ }] : []) : []);
20
+ }
21
+ /** Whether a pin's `options` entry is a modifier mapping: a ref at a modifier, and nothing else. */
22
+ function isVendorModifierMapping({ config, accessor, entry }) {
23
+ return accessor === (config.accessorOf("modifier") ?? "modifier") && isPlainObject(entry) && entry.extend === void 0 && isRef(entry.override) && kindOf(entry.override) === "modifier";
24
+ }
25
+ /**
26
+ * Why a pin's modifier mapping can't be written, one sentence per entry: what this config alone can
27
+ * say, so it holds as an invariant whether or not the source is attached.
28
+ */
29
+ function vendorModifierMappingProblems({ config, slug }) {
30
+ const problems = [];
31
+ for (const mapping of modifierMappings({
32
+ config,
33
+ slug
34
+ })) if (!mapping.ours) problems.push(`${mapping.at} maps the vendor's modifier to "${mapping.target}", which isn't a modifier of this system.`);
35
+ else if (activationOf(mapping.ours).type === "composite") problems.push(`${mapping.at} maps the vendor's modifier to "${mapping.ours.path}", which asks whether an element sits on a surface. Only a selector or a query can stand in for the vendor's.`);
36
+ return problems;
37
+ }
38
+ /**
39
+ * The pin's modifier mappings that map nothing in the attached source: a path the source doesn't
40
+ * hold, or a modifier of another category than ours. Such a modifier keeps the vendor's own
41
+ * activation, which isn't what the entry asked for, so a build reports it.
42
+ */
43
+ function unheldVendorModifierMappings({ config, slug }) {
44
+ const vendor = config.liveSourceFor(slug);
45
+ if (!vendor) return [];
46
+ const problems = [];
47
+ for (const mapping of modifierMappings({
48
+ config,
49
+ slug
50
+ })) {
51
+ if (!mapping.ours || activationOf(mapping.ours).type === "composite") continue;
52
+ const theirs = vendor.resolve("modifier", mapping.vendor);
53
+ if (!theirs) {
54
+ problems.push(`${mapping.at} names no modifier of the source. Its modifiers are spelled by path, as in "appearance/dark".`);
55
+ continue;
56
+ }
57
+ const theirCategory = modifierCategory(vendor, theirs.path) ?? "plain";
58
+ const ourCategory = modifierCategory(config, mapping.ours.path) ?? "plain";
59
+ if (theirCategory !== ourCategory) problems.push(`${mapping.at} maps a ${theirCategory} modifier to "${mapping.ours.path}", which is a ${ourCategory} one here. A modifier maps to one of the same kind.`);
60
+ }
61
+ return problems;
62
+ }
63
+ /** Each mapping a pin writes, with the modifier of this config it names when there is one. */
64
+ function modifierMappings({ config, slug }) {
65
+ const accessor = config.accessorOf("modifier") ?? "modifier";
66
+ return vendorModifierMappings({
67
+ config,
68
+ slug
69
+ }).flatMap((mapping) => {
70
+ const { target } = mapping;
71
+ if (!isRef(target) || kindOf(target) !== "modifier") return [];
72
+ return [{
73
+ vendor: mapping.vendor,
74
+ at: `Link "${slug}": options.${accessor}["${mapping.vendor}"]`,
75
+ target: pathOf(target),
76
+ ours: sourceOf(target) === void 0 ? config.resolve("modifier", pathOf(target)) : void 0
77
+ }];
78
+ });
79
+ }
80
+ /**
81
+ * The vendor's modifiers this config states as its own, vendor path to our path: the ones the pin
82
+ * maps, then the modes a selector switches that we hold at the same path. A modifier that asks
83
+ * about a surface (`composite`) is never bound, since the surface it asks about is the vendor's.
84
+ */
85
+ function vendorModifierBindings({ consumer, slug }) {
86
+ const vendor = consumer.sourceFor(slug);
87
+ if (!vendor || consumer.sourceTypeOf(slug) !== "vendor") return NO_BINDINGS;
88
+ const held = bindings.get(consumer)?.get(slug);
89
+ if (held?.vendor === vendor) return held.bound;
90
+ const bound = /* @__PURE__ */ new Map();
91
+ const bind = ({ theirs, ours }) => {
92
+ const vendorModifier = vendor.resolve("modifier", theirs);
93
+ const ourModifier = consumer.resolve("modifier", ours);
94
+ if (!vendorModifier || !ourModifier) return;
95
+ if (vendor.vendorOf("modifier", vendorModifier.path)) return;
96
+ if (activationOf(vendorModifier).type === "composite") return;
97
+ if (activationOf(ourModifier).type === "composite") return;
98
+ if (modifierCategory(vendor, vendorModifier.path) !== modifierCategory(consumer, ourModifier.path)) return;
99
+ bound.set(vendorModifier.path, ourModifier.path);
100
+ };
101
+ for (const mapping of vendorModifierMappings({
102
+ config: consumer,
103
+ slug
104
+ })) {
105
+ if (!isRef(mapping.target) || kindOf(mapping.target) !== "modifier") continue;
106
+ if (sourceOf(mapping.target) !== void 0) continue;
107
+ bind({
108
+ theirs: mapping.vendor,
109
+ ours: pathOf(mapping.target)
110
+ });
111
+ }
112
+ const switched = (config, path) => modifierCategory(config, path) === "mode" && activationOf(config.resolve("modifier", path)).type === "selector";
113
+ const own = new Set(consumer.list("modifier").map(({ path }) => path));
114
+ for (const { path } of vendor.list("modifier")) {
115
+ if (bound.has(path) || !own.has(path)) continue;
116
+ if (!switched(vendor, path) || !switched(consumer, path)) continue;
117
+ bind({
118
+ theirs: path,
119
+ ours: path
120
+ });
121
+ }
122
+ let bySlug = bindings.get(consumer);
123
+ if (!bySlug) {
124
+ bySlug = /* @__PURE__ */ new Map();
125
+ bindings.set(consumer, bySlug);
126
+ }
127
+ bySlug.set(slug, {
128
+ vendor,
129
+ bound
130
+ });
131
+ return bound;
132
+ }
133
+ /**
134
+ * Each mode of a `vendor` pin's source that what the pin takes varies under, and that nothing in
135
+ * this config turns on: a selector switches it, no binding states it as one of ours
136
+ * ({@link vendorModifierBindings}), and none of our modifiers is switched by the same selector. It
137
+ * keeps the vendor's own switch, which only the app can set, so the lint reports it.
138
+ *
139
+ * A mode a query decides is left out, since the device answers it wherever the component renders.
140
+ */
141
+ function unmappedVendorModes(config) {
142
+ const found = [];
143
+ const ours = config.list("modifier").map(({ path }) => ({
144
+ path,
145
+ mode: modifierCategory(config, path) === "mode",
146
+ ...activationOf(config.resolve("modifier", path))
147
+ }));
148
+ const switches = new Set(ours.flatMap(({ type, value }) => type === "selector" && typeof value === "string" ? [value.trim()] : []));
149
+ for (const slug of config.sourceSlugs()) {
150
+ if (config.sourceTypeOf(slug) !== "vendor") continue;
151
+ const vendor = config.sourceFor(slug);
152
+ if (!vendor) continue;
153
+ const bound = vendorModifierBindings({
154
+ consumer: config,
155
+ slug
156
+ });
157
+ for (const target of config.sourceClosure(slug, "modifier")) {
158
+ const modifier = vendor.resolve("modifier", pathOf(target));
159
+ if (!modifier || bound.has(modifier.path)) continue;
160
+ if (modifierCategory(vendor, modifier.path) !== "mode") continue;
161
+ if (vendor.vendorOf("modifier", modifier.path)) continue;
162
+ const { type, value } = activationOf(modifier);
163
+ if (type !== "selector" || typeof value !== "string") continue;
164
+ if (switches.has(value.trim())) continue;
165
+ const leaf = modifier.path.split("/").pop();
166
+ const named = ours.filter(({ path, mode, type: ourType }) => mode && ourType !== "composite" && path.split("/").pop() === leaf);
167
+ found.push({
168
+ slug,
169
+ modifier: modifier.path,
170
+ selector: value,
171
+ ...named.length === 1 && named[0] ? { candidate: named[0].path } : {}
172
+ });
173
+ }
174
+ }
175
+ return found;
176
+ }
177
+ /**
178
+ * A `vendor` pin's source with its bound modifiers activating as this config's do
179
+ * ({@link vendorModifierBindings}). Each keeps the vendor's path, so the vendor's tokens, rules and
180
+ * style props read against it unchanged. `undefined` for a pin that isn't `vendor`, or whose source
181
+ * isn't attached.
182
+ */
183
+ function vendorSource({ consumer, slug }) {
184
+ if (consumer.sourceTypeOf(slug) !== "vendor") return void 0;
185
+ const vendor = consumer.sourceFor(slug);
186
+ if (!vendor) return void 0;
187
+ const held = sources.get(consumer)?.get(slug);
188
+ if (held?.vendor === vendor) return held.stated;
189
+ const bound = vendorModifierBindings({
190
+ consumer,
191
+ slug
192
+ });
193
+ let stated = vendor.fork();
194
+ for (const [theirs, ours] of bound) {
195
+ const activation = activationOf(consumer.resolve("modifier", ours));
196
+ const current = activationOf(vendor.resolve("modifier", theirs));
197
+ if (ACTIVATION_FIELDS.every((field) => same(activation[field], current[field]))) continue;
198
+ stated = stated.apply({
199
+ kind: "modifier",
200
+ operation: "update",
201
+ path: theirs,
202
+ data: Object.fromEntries(ACTIVATION_FIELDS.flatMap((field) => {
203
+ if (activation[field] !== void 0) return [[field, activation[field]]];
204
+ return current[field] === void 0 ? [] : [[field, null]];
205
+ }))
206
+ });
207
+ }
208
+ recordStatedModifiers({
209
+ config: stated,
210
+ bound
211
+ });
212
+ let bySlug = sources.get(consumer);
213
+ if (!bySlug) {
214
+ bySlug = /* @__PURE__ */ new Map();
215
+ sources.set(consumer, bySlug);
216
+ }
217
+ bySlug.set(slug, {
218
+ vendor,
219
+ stated
220
+ });
221
+ return stated;
222
+ }
223
+ /** Records, on a config derived from a vendor's, which of its modifiers are stated as another's. */
224
+ function recordStatedModifiers({ config, bound }) {
225
+ if (bound.size > 0) statedAs.set(config, bound);
226
+ }
227
+ /** The modifiers a config states as another's, for a config derived from it to carry on. */
228
+ function statedModifiersOf(config) {
229
+ return statedAs.get(config) ?? NO_BINDINGS;
230
+ }
231
+ /**
232
+ * The path a modifier is stated under: ours, for a vendor's modifier bound to one of ours, and its
233
+ * own otherwise. What names a mode outside the stylesheet's own selector reads this, as the
234
+ * attribute an editor forces a mode with does.
235
+ */
236
+ function statedModifierPath(config, path) {
237
+ const bound = statedAs.get(config);
238
+ if (!bound) return path;
239
+ return bound.get(config.resolve("modifier", path)?.path ?? path) ?? path;
240
+ }
241
+ function activationOf(modifier) {
242
+ const body = modifier?.toJSON();
243
+ return isPlainObject(body) ? body : {};
244
+ }
245
+ function same(a, b) {
246
+ return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
247
+ }
248
+ const NO_BINDINGS = /* @__PURE__ */ new Map();
249
+ const bindings = /* @__PURE__ */ new WeakMap();
250
+ const sources = /* @__PURE__ */ new WeakMap();
251
+ const statedAs = /* @__PURE__ */ new WeakMap();
252
+ //#endregion
253
+ export { isVendorModifierMapping, recordStatedModifiers, statedModifierPath, statedModifiersOf, unheldVendorModifierMappings, unmappedVendorModes, vendorModifierBindings, vendorModifierMappingProblems, vendorSource };