dispersa 0.2.0 → 0.3.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/index.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import { D as DispersaOptions, B as BuildConfig, a as BuildResult, M as ModifierInputs, R as ResolverDocument } from './index-CePv_bgv.cjs';
2
- export { A as AndroidRendererOptions, c as BuildError, d as BuildOutput, C as CssRendererOptions, E as ErrorCode, F as FormatOptions, I as IosRendererOptions, L as LifecycleHooks, e as MediaQueryFunction, O as OutputConfig, f as OutputTree, P as PermutationData, h as RenderContext, i as RenderMeta, j as RenderOutput, g as Renderer, S as SelectorFunction, T as TailwindRendererOptions, b as ValidationMode, V as ValidationOptions, k as defineRenderer } from './index-CePv_bgv.cjs';
3
- import { R as ResolvedTokens } from './types-C1GpiJ6q.cjs';
4
- export { B as BorderValue, C as ColorToken, d as ColorValueObject, D as DesignTokenValue, b as DimensionToken, e as DimensionValue, c as DurationToken, G as GradientValue, a as ResolvedToken, S as ShadowToken, f as ShadowValueObject, T as TokenType, h as TransitionValue, g as TypographyValue, m as isBorderToken, i as isColorToken, j as isDimensionToken, n as isDurationToken, p as isGradientToken, k as isShadowToken, o as isTransitionToken, l as isTypographyToken } from './types-C1GpiJ6q.cjs';
5
- export { T as Transform } from './types-DM5faYUn.cjs';
6
- export { F as Filter } from './types-BDY1xBmD.cjs';
7
- export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-DbufGPrb.cjs';
1
+ import { D as DispersaOptions, B as BuildConfig, a as BuildResult, M as ModifierInputs, R as ResolverDocument } from './index-BkvV7Z54.cjs';
2
+ export { A as AndroidRendererOptions, c as BuildError, d as BuildOutput, C as CssRendererOptions, E as ErrorCode, F as FormatOptions, I as IosRendererOptions, L as LifecycleHooks, e as MediaQueryFunction, O as OutputConfig, f as OutputTree, P as PermutationData, h as RenderContext, i as RenderMeta, j as RenderOutput, g as Renderer, S as SelectorFunction, T as TailwindRendererOptions, b as ValidationMode, V as ValidationOptions, k as defineRenderer } from './index-BkvV7Z54.cjs';
3
+ import { R as ResolvedTokens } from './types-Bc0kA7De.cjs';
4
+ export { B as BorderToken, r as BorderValue, k as ColorComponent, j as ColorSpace, C as ColorToken, i as ColorValue, h as ColorValueObject, o as CubicBezierValue, D as DesignTokenValue, d as DimensionToken, l as DimensionValue, e as DurationToken, m as DurationValue, F as FontFamilyValue, n as FontWeightValue, w as GradientStop, G as GradientToken, v as GradientValue, a as ResolvedToken, S as ShadowToken, p as ShadowValueObject, s as StrokeStyleValue, t as StrokeStyleValueObject, T as TokenType, b as TokenValue, c as TokenValueReference, g as TransitionToken, u as TransitionValue, f as TypographyToken, q as TypographyValue, E as isBorderToken, x as isColorToken, y as isDimensionToken, H as isDurationToken, J as isGradientToken, z as isShadowToken, I as isTransitionToken, A as isTypographyToken } from './types-Bc0kA7De.cjs';
5
+ export { T as Transform } from './types-BAv39mum.cjs';
6
+ export { F as Filter } from './types-DWKq-eJj.cjs';
7
+ export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-CussyWwe.cjs';
8
8
  export { AndroidBuilderConfig, CssBuilderConfig, IosBuilderConfig, JsBuilderConfig, JsonBuilderConfig, TailwindBuilderConfig, android, css, ios, js, json, tailwind } from './builders.cjs';
9
9
  export { isOutputTree, outputTree } from './renderers.cjs';
10
10
  export { BasePermutationError, CircularReferenceError, ColorParseError, ConfigurationError, DimensionFormatError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.cjs';
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { D as DispersaOptions, B as BuildConfig, a as BuildResult, M as ModifierInputs, R as ResolverDocument } from './index-BP52gB00.js';
2
- export { A as AndroidRendererOptions, c as BuildError, d as BuildOutput, C as CssRendererOptions, E as ErrorCode, F as FormatOptions, I as IosRendererOptions, L as LifecycleHooks, e as MediaQueryFunction, O as OutputConfig, f as OutputTree, P as PermutationData, h as RenderContext, i as RenderMeta, j as RenderOutput, g as Renderer, S as SelectorFunction, T as TailwindRendererOptions, b as ValidationMode, V as ValidationOptions, k as defineRenderer } from './index-BP52gB00.js';
3
- import { R as ResolvedTokens } from './types-C1GpiJ6q.js';
4
- export { B as BorderValue, C as ColorToken, d as ColorValueObject, D as DesignTokenValue, b as DimensionToken, e as DimensionValue, c as DurationToken, G as GradientValue, a as ResolvedToken, S as ShadowToken, f as ShadowValueObject, T as TokenType, h as TransitionValue, g as TypographyValue, m as isBorderToken, i as isColorToken, j as isDimensionToken, n as isDurationToken, p as isGradientToken, k as isShadowToken, o as isTransitionToken, l as isTypographyToken } from './types-C1GpiJ6q.js';
5
- export { T as Transform } from './types-DdPWYkgh.js';
6
- export { F as Filter } from './types-Cl-1UYGD.js';
7
- export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-DJH6_4U9.js';
1
+ import { D as DispersaOptions, B as BuildConfig, a as BuildResult, M as ModifierInputs, R as ResolverDocument } from './index-DJ_UHSQG.js';
2
+ export { A as AndroidRendererOptions, c as BuildError, d as BuildOutput, C as CssRendererOptions, E as ErrorCode, F as FormatOptions, I as IosRendererOptions, L as LifecycleHooks, e as MediaQueryFunction, O as OutputConfig, f as OutputTree, P as PermutationData, h as RenderContext, i as RenderMeta, j as RenderOutput, g as Renderer, S as SelectorFunction, T as TailwindRendererOptions, b as ValidationMode, V as ValidationOptions, k as defineRenderer } from './index-DJ_UHSQG.js';
3
+ import { R as ResolvedTokens } from './types-Bc0kA7De.js';
4
+ export { B as BorderToken, r as BorderValue, k as ColorComponent, j as ColorSpace, C as ColorToken, i as ColorValue, h as ColorValueObject, o as CubicBezierValue, D as DesignTokenValue, d as DimensionToken, l as DimensionValue, e as DurationToken, m as DurationValue, F as FontFamilyValue, n as FontWeightValue, w as GradientStop, G as GradientToken, v as GradientValue, a as ResolvedToken, S as ShadowToken, p as ShadowValueObject, s as StrokeStyleValue, t as StrokeStyleValueObject, T as TokenType, b as TokenValue, c as TokenValueReference, g as TransitionToken, u as TransitionValue, f as TypographyToken, q as TypographyValue, E as isBorderToken, x as isColorToken, y as isDimensionToken, H as isDurationToken, J as isGradientToken, z as isShadowToken, I as isTransitionToken, A as isTypographyToken } from './types-Bc0kA7De.js';
5
+ export { T as Transform } from './types-CzHa7YkW.js';
6
+ export { F as Filter } from './types-BzNcG-rI.js';
7
+ export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-CZb19kiq.js';
8
8
  export { AndroidBuilderConfig, CssBuilderConfig, IosBuilderConfig, JsBuilderConfig, JsonBuilderConfig, TailwindBuilderConfig, android, css, ios, js, json, tailwind } from './builders.js';
9
9
  export { isOutputTree, outputTree } from './renderers.js';
10
10
  export { BasePermutationError, CircularReferenceError, ColorParseError, ConfigurationError, DimensionFormatError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.js';
package/dist/index.js CHANGED
@@ -3393,32 +3393,55 @@ function filterTokensBySource(tokens, expectedSource) {
3393
3393
  }
3394
3394
  return filtered;
3395
3395
  }
3396
- function interpolatePattern(pattern, modifierInputs, modifierName, context) {
3397
- let result = pattern;
3398
- if (modifierName !== void 0) {
3399
- result = result.replace(/\{modifierName\}/g, modifierName);
3396
+ function filterTokensFromSets(tokens) {
3397
+ const filtered = {};
3398
+ for (const [name, token] of Object.entries(tokens)) {
3399
+ const hasModifierSource = typeof token._sourceModifier === "string" && token._sourceModifier !== "";
3400
+ if (!hasModifierSource) {
3401
+ filtered[name] = token;
3402
+ }
3400
3403
  }
3401
- if (context !== void 0) {
3402
- result = result.replace(/\{context\}/g, context);
3404
+ return filtered;
3405
+ }
3406
+ function resolveBaseFileName(fileName, defaults) {
3407
+ if (typeof fileName === "function") {
3408
+ return fileName({ ...defaults, _base: "true" });
3409
+ }
3410
+ if (/\{.+?\}/.test(fileName)) {
3411
+ const baseInputs = Object.fromEntries(Object.keys(defaults).map((k) => [k, "base"]));
3412
+ return collapseBaseSegments(interpolatePattern(fileName, baseInputs));
3413
+ }
3414
+ const extMatch = fileName.match(/(\.[^.]+)$/);
3415
+ const extension = extMatch ? extMatch[1] : "";
3416
+ const baseName = extension ? fileName.slice(0, -extension.length) : fileName;
3417
+ return `${baseName}-base${extension}`;
3418
+ }
3419
+ function collapseBaseSegments(value) {
3420
+ let result = value;
3421
+ let previous = "";
3422
+ while (result !== previous) {
3423
+ previous = result;
3424
+ result = result.replace(/\bbase([/-])base\b/, "base");
3403
3425
  }
3426
+ return result;
3427
+ }
3428
+ function interpolatePattern(pattern, modifierInputs) {
3429
+ let result = pattern;
3404
3430
  for (const [key, value] of Object.entries(modifierInputs)) {
3405
3431
  result = result.replaceAll(`{${key}}`, value);
3406
3432
  }
3407
3433
  return result;
3408
3434
  }
3409
- function resolveFileName(fileName, modifierInputs, modifierName, context) {
3435
+ function resolveFileName(fileName, modifierInputs) {
3410
3436
  if (typeof fileName === "function") {
3411
3437
  return fileName(modifierInputs);
3412
3438
  }
3413
3439
  if (/\{.+?\}/.test(fileName)) {
3414
- return interpolatePattern(fileName, modifierInputs, modifierName, context);
3440
+ return interpolatePattern(fileName, modifierInputs);
3415
3441
  }
3416
3442
  const extMatch = fileName.match(/(\.[^.]+)$/);
3417
3443
  const extension = extMatch ? extMatch[1] : "";
3418
3444
  const baseName = extension ? fileName.slice(0, -extension.length) : fileName;
3419
- if (modifierName !== void 0 && context !== void 0) {
3420
- return `${baseName}-${modifierName}-${context}${extension}`;
3421
- }
3422
3445
  const modifierSuffix = Object.entries(modifierInputs).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, value]) => `${key}-${value}`).join("-");
3423
3446
  if (modifierSuffix) {
3424
3447
  return `${baseName}-${modifierSuffix}${extension}`;
@@ -7333,6 +7356,33 @@ function collectRemainder(tokens, included) {
7333
7356
  }
7334
7357
  return result;
7335
7358
  }
7359
+ function buildSetLayerBlocks(tokens, resolver) {
7360
+ const blocks = [];
7361
+ const included = /* @__PURE__ */ new Set();
7362
+ const addBlock = (key, blockTokens, description) => {
7363
+ if (Object.keys(blockTokens).length === 0) {
7364
+ return;
7365
+ }
7366
+ for (const k of Object.keys(blockTokens)) {
7367
+ included.add(k);
7368
+ }
7369
+ blocks.push({ key, description, tokens: blockTokens });
7370
+ };
7371
+ for (const item of resolver.resolutionOrder) {
7372
+ const ref = item.$ref;
7373
+ if (typeof ref !== "string" || !ref.startsWith("#/sets/")) {
7374
+ continue;
7375
+ }
7376
+ const setName = ref.slice("#/sets/".length);
7377
+ addBlock(
7378
+ `Set: ${setName}`,
7379
+ collectSetTokens(tokens, setName, included),
7380
+ resolver.sets?.[setName]?.description
7381
+ );
7382
+ }
7383
+ addBlock("Unattributed", collectRemainder(tokens, included));
7384
+ return blocks;
7385
+ }
7336
7386
  function buildDefaultLayerBlocks(tokens, baseModifierInputs, resolver) {
7337
7387
  const blocks = [];
7338
7388
  const included = /* @__PURE__ */ new Set();
@@ -8053,6 +8103,10 @@ var CssRenderer = class _CssRenderer {
8053
8103
  throw new ConfigurationError("Modifier preset requires modifiers to be defined in resolver");
8054
8104
  }
8055
8105
  const files = {};
8106
+ const baseResult = await this.buildModifierBaseFile(context, options);
8107
+ if (baseResult) {
8108
+ files[baseResult.fileName] = baseResult.content;
8109
+ }
8056
8110
  for (const [modifierName, modifierDef] of Object.entries(context.resolver.modifiers)) {
8057
8111
  for (const contextValue of Object.keys(modifierDef.contexts)) {
8058
8112
  const result = await this.buildModifierContextFile(
@@ -8068,6 +8122,59 @@ var CssRenderer = class _CssRenderer {
8068
8122
  }
8069
8123
  return { kind: "outputTree", files };
8070
8124
  }
8125
+ async buildModifierBaseFile(context, options) {
8126
+ const basePermutation = context.permutations.find(
8127
+ ({ modifierInputs }) => this.isBasePermutation(modifierInputs, context.meta.defaults)
8128
+ );
8129
+ if (!basePermutation) {
8130
+ return void 0;
8131
+ }
8132
+ const setTokens = filterTokensFromSets(basePermutation.tokens);
8133
+ if (Object.keys(setTokens).length === 0) {
8134
+ return void 0;
8135
+ }
8136
+ const setBlocks = buildSetLayerBlocks(setTokens, context.resolver);
8137
+ if (setBlocks.length === 0) {
8138
+ return void 0;
8139
+ }
8140
+ const modifiers = context.resolver.modifiers;
8141
+ const firstModifierName = Object.keys(modifiers)[0] ?? "";
8142
+ const firstModifierContext = context.meta.defaults[firstModifierName] ?? "";
8143
+ const baseModifierInputs = { ...context.meta.defaults };
8144
+ const selector = resolveSelector(
8145
+ options.selector,
8146
+ firstModifierName,
8147
+ firstModifierContext,
8148
+ true,
8149
+ baseModifierInputs
8150
+ );
8151
+ const mediaQuery = resolveMediaQuery(
8152
+ options.mediaQuery,
8153
+ firstModifierName,
8154
+ firstModifierContext,
8155
+ true,
8156
+ baseModifierInputs
8157
+ );
8158
+ const referenceTokens = basePermutation.tokens;
8159
+ const cssBlocks = [];
8160
+ for (const block of setBlocks) {
8161
+ const cleanTokens = stripInternalMetadata(block.tokens);
8162
+ const css2 = await this.formatTokens(cleanTokens, {
8163
+ selector,
8164
+ mediaQuery,
8165
+ minify: options.minify ?? false,
8166
+ preserveReferences: options.preserveReferences ?? false,
8167
+ referenceTokens
8168
+ });
8169
+ const header = block.description ? `/* ${block.key} */
8170
+ /* ${block.description} */` : `/* ${block.key} */`;
8171
+ cssBlocks.push(`${header}
8172
+ ${css2}`);
8173
+ }
8174
+ const content = cssBlocks.join("\n");
8175
+ const fileName = context.output.file ? resolveBaseFileName(context.output.file, context.meta.defaults) : `${context.output.name}-base.css`;
8176
+ return { fileName, content };
8177
+ }
8071
8178
  collectTokensForModifierContext(modifierName, contextValue, permutations) {
8072
8179
  const expectedSource = `${modifierName}-${contextValue}`;
8073
8180
  let tokensFromSource = {};
@@ -8114,7 +8221,7 @@ var CssRenderer = class _CssRenderer {
8114
8221
  preserveReferences: options.preserveReferences ?? false,
8115
8222
  referenceTokens
8116
8223
  });
8117
- const fileName = context.output.file ? resolveFileName(context.output.file, modifierInputs, modifierName, contextValue) : buildInMemoryOutputKey({
8224
+ const fileName = context.output.file ? resolveFileName(context.output.file, modifierInputs) : buildInMemoryOutputKey({
8118
8225
  outputName: context.output.name,
8119
8226
  extension: "css",
8120
8227
  modifierInputs,