dispersa 0.3.1 → 0.4.1

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,5 +1,5 @@
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';
1
+ import { D as DispersaOptions, B as BuildConfig, a as BuildResult, M as ModifierInputs, R as ResolverDocument } from './index-dwm-xYbQ.cjs';
2
+ export { A as AndroidRendererOptions, c as BuildError, d as BuildOutput, C as CssRendererOptions, E as ErrorCode, F as FileFunction, e as FormatOptions, I as IosRendererOptions, L as LifecycleHooks, f as MediaQueryFunction, O as OutputConfig, g as OutputTree, P as PermutationData, i as RenderContext, j as RenderMeta, k as RenderOutput, h as Renderer, S as SelectorFunction, T as TailwindRendererOptions, b as ValidationMode, V as ValidationOptions, l as defineRenderer } from './index-dwm-xYbQ.cjs';
3
3
  import { R as ResolvedTokens } from './types-Bc0kA7De.cjs';
4
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
5
  export { T as Transform } from './types-BAv39mum.cjs';
@@ -7,7 +7,7 @@ export { F as Filter } from './types-DWKq-eJj.cjs';
7
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
- export { BasePermutationError, CircularReferenceError, ColorParseError, ConfigurationError, DimensionFormatError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.cjs';
10
+ export { BasePermutationError, CircularReferenceError, ConfigurationError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.cjs';
11
11
  import 'json-schema-to-ts';
12
12
 
13
13
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { D as DispersaOptions, B as BuildConfig, a as BuildResult, M as ModifierInputs, R as ResolverDocument } from './index-Bkedvob6.js';
2
+ export { A as AndroidRendererOptions, c as BuildError, d as BuildOutput, C as CssRendererOptions, E as ErrorCode, F as FileFunction, e as FormatOptions, I as IosRendererOptions, L as LifecycleHooks, f as MediaQueryFunction, O as OutputConfig, g as OutputTree, P as PermutationData, i as RenderContext, j as RenderMeta, k as RenderOutput, h as Renderer, S as SelectorFunction, T as TailwindRendererOptions, b as ValidationMode, V as ValidationOptions, l as defineRenderer } from './index-Bkedvob6.js';
3
3
  import { R as ResolvedTokens } from './types-Bc0kA7De.js';
4
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
5
  export { T as Transform } from './types-CzHa7YkW.js';
@@ -7,7 +7,7 @@ export { F as Filter } from './types-BzNcG-rI.js';
7
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
- export { BasePermutationError, CircularReferenceError, ColorParseError, ConfigurationError, DimensionFormatError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.js';
10
+ export { BasePermutationError, CircularReferenceError, ConfigurationError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.js';
11
11
  import 'json-schema-to-ts';
12
12
 
13
13
  /**
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ var init_token_utils = __esm({
59
59
  });
60
60
 
61
61
  // src/shared/errors/index.ts
62
- var DispersaError, TokenReferenceError, CircularReferenceError, ValidationError, ColorParseError, DimensionFormatError, FileOperationError, ConfigurationError, BasePermutationError, ModifierError;
62
+ var DispersaError, TokenReferenceError, CircularReferenceError, ValidationError, FileOperationError, ConfigurationError, BasePermutationError, ModifierError;
63
63
  var init_errors = __esm({
64
64
  "src/shared/errors/index.ts"() {
65
65
  DispersaError = class extends Error {
@@ -110,20 +110,6 @@ var init_errors = __esm({
110
110
  this.name = "ValidationError";
111
111
  }
112
112
  };
113
- ColorParseError = class extends DispersaError {
114
- constructor(colorValue) {
115
- super(`Color parsing failed: '${colorValue}'. Provide a valid CSS color or DTCG color object.`);
116
- this.colorValue = colorValue;
117
- this.name = "ColorParseError";
118
- }
119
- };
120
- DimensionFormatError = class extends DispersaError {
121
- constructor(dimensionValue) {
122
- super(`Dimension parsing failed: '${dimensionValue}'. Provide a valid DTCG dimension object.`);
123
- this.dimensionValue = dimensionValue;
124
- this.name = "DimensionFormatError";
125
- }
126
- };
127
113
  FileOperationError = class extends DispersaError {
128
114
  constructor(operation, filePath, originalError) {
129
115
  super(`Failed to ${operation} file: ${filePath}. ${originalError.message}`);
@@ -3880,12 +3866,6 @@ function toBuildError(error, outputName) {
3880
3866
  if (error instanceof ValidationError) {
3881
3867
  return { message, code: "VALIDATION", severity: "error" };
3882
3868
  }
3883
- if (error instanceof ColorParseError) {
3884
- return { message, code: "COLOR_PARSE", severity: "error" };
3885
- }
3886
- if (error instanceof DimensionFormatError) {
3887
- return { message, code: "DIMENSION_FORMAT", severity: "error" };
3888
- }
3889
3869
  if (error instanceof FileOperationError) {
3890
3870
  return { message, code: "FILE_OPERATION", path: error.filePath, severity: "error" };
3891
3871
  }
@@ -5880,6 +5860,32 @@ var TokenParser = class {
5880
5860
  };
5881
5861
 
5882
5862
  // src/build/pipeline/token-pipeline.ts
5863
+ var ROOT_REF_PATTERN = /\.\$root\}/g;
5864
+ function rewriteRootReferences(value) {
5865
+ if (typeof value === "string") {
5866
+ return ROOT_REF_PATTERN.test(value) ? value.replace(ROOT_REF_PATTERN, "}") : value;
5867
+ }
5868
+ if (Array.isArray(value)) {
5869
+ let changed = false;
5870
+ const mapped = value.map((item) => {
5871
+ const rewritten = rewriteRootReferences(item);
5872
+ if (rewritten !== item) changed = true;
5873
+ return rewritten;
5874
+ });
5875
+ return changed ? mapped : value;
5876
+ }
5877
+ if (typeof value === "object" && value !== null) {
5878
+ let changed = false;
5879
+ const result = {};
5880
+ for (const [k, v] of Object.entries(value)) {
5881
+ const rewritten = rewriteRootReferences(v);
5882
+ if (rewritten !== v) changed = true;
5883
+ result[k] = rewritten;
5884
+ }
5885
+ return changed ? result : value;
5886
+ }
5887
+ return value;
5888
+ }
5883
5889
  var TokenPipeline = class {
5884
5890
  options;
5885
5891
  validationHandler;
@@ -5904,8 +5910,9 @@ var TokenPipeline = class {
5904
5910
  * 5. Resolve JSON Pointer references
5905
5911
  * 6. Parse and flatten token structure
5906
5912
  * 7. Resolve alias references
5907
- * 8. Apply filters (if provided) runs first to remove tokens before transforms
5908
- * 9. Apply transforms (if provided) — runs on the already-filtered token set
5913
+ * 8. Strip $root from token names/paths (DTCG structural mechanism, transparent in output)
5914
+ * 9. Apply filters (if provided) — runs first to remove tokens before transforms
5915
+ * 10. Apply transforms (if provided) — runs on the already-filtered token set
5909
5916
  *
5910
5917
  * Each stage is explicitly typed to ensure correct order and prevent temporal coupling.
5911
5918
  *
@@ -5945,7 +5952,8 @@ var TokenPipeline = class {
5945
5952
  const refResolved = await this.resolveReferences(preprocessed);
5946
5953
  const flattened = this.flattenTokens(refResolved);
5947
5954
  const aliasResolved = this.resolveAliases(flattened);
5948
- const filtered = this.applyFilterStage(aliasResolved, filterList);
5955
+ const rootStripped = this.stripRootTokenNames(aliasResolved);
5956
+ const filtered = this.applyFilterStage(rootStripped, filterList);
5949
5957
  return this.applyTransformStage(filtered, transformList);
5950
5958
  }
5951
5959
  /**
@@ -6030,8 +6038,34 @@ var TokenPipeline = class {
6030
6038
  return { ...rest, aliasResolvedTokens };
6031
6039
  }
6032
6040
  /**
6033
- * Stage 8: Apply filters to final tokens (before transforms to skip unnecessary work)
6041
+ * Stage 8: Strip `$root` from token names and paths.
6042
+ *
6043
+ * `$root` is a DTCG structural mechanism that allows a group to carry a
6044
+ * default value alongside child tokens. References must use the full path
6045
+ * (`{color.action.brand.$root}`) for alias resolution, but `$root` should
6046
+ * be transparent in output. This stage re-keys tokens so downstream
6047
+ * consumers (filters, transforms, renderers) see clean names.
6034
6048
  */
6049
+ stripRootTokenNames(stage) {
6050
+ const tokens = stage.aliasResolvedTokens;
6051
+ const result = {};
6052
+ for (const [key, token] of Object.entries(tokens)) {
6053
+ const rewrittenOriginal = rewriteRootReferences(token.originalValue);
6054
+ if (!key.endsWith(".$root")) {
6055
+ result[key] = rewrittenOriginal !== token.originalValue ? { ...token, originalValue: rewrittenOriginal } : token;
6056
+ continue;
6057
+ }
6058
+ const strippedPath = token.path.filter((segment) => segment !== "$root");
6059
+ const strippedName = strippedPath.join(".");
6060
+ result[strippedName] = {
6061
+ ...token,
6062
+ path: strippedPath,
6063
+ name: strippedName,
6064
+ originalValue: rewrittenOriginal
6065
+ };
6066
+ }
6067
+ return { ...stage, aliasResolvedTokens: result };
6068
+ }
6035
6069
  applyFilterStage(stage, filterList) {
6036
6070
  let tokens = stage.aliasResolvedTokens;
6037
6071
  if (filterList !== void 0 && filterList.length > 0) {
@@ -9689,6 +9723,6 @@ init_errors();
9689
9723
  * LICENSE file in the root directory of this source tree.
9690
9724
  */
9691
9725
 
9692
- export { BasePermutationError, CircularReferenceError, ColorParseError, ConfigurationError, DimensionFormatError, Dispersa, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError, android, css, defineRenderer, ios, isBorderToken, isColorToken, isDimensionToken, isDurationToken, isGradientToken, isOutputTree, isShadowToken, isTransitionToken, isTypographyToken, js, json, outputTree, tailwind };
9726
+ export { BasePermutationError, CircularReferenceError, ConfigurationError, Dispersa, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError, android, css, defineRenderer, ios, isBorderToken, isColorToken, isDimensionToken, isDurationToken, isGradientToken, isOutputTree, isShadowToken, isTransitionToken, isTypographyToken, js, json, outputTree, tailwind };
9693
9727
  //# sourceMappingURL=index.js.map
9694
9728
  //# sourceMappingURL=index.js.map