Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | 1x 4x 1x 3x 1x 3x 1x 3x 1x 3x 3x 3x 4x 4x 1x 11x | /**
* Mobile Token Filters
*
* Filter functions for categorizing tokens in mobile outputs (Android, iOS).
* These filters are used at the file level in Style Dictionary configuration
* to pre-filter tokens before they reach the format functions.
*/
import type { Config, Filter, TransformedToken } from 'style-dictionary/types';
import type { StyleDictionaryHost } from '../style-dictionary-host.js';
import {
PATH_INDEX,
CATEGORY,
NAMESPACE,
SCOPE,
isSystemColorToken,
isReferenceColorToken,
isSemanticColorToken,
isPaletteToken,
} from '../utils/mobile-helpers.js';
/**
* Filter for spacing tokens (slds.g.spacing.*)
*/
export const spacingFilterFn = ((token: TransformedToken, _options: Config) =>
token.path[PATH_INDEX.NAMESPACE] === NAMESPACE.SLDS &&
token.path[PATH_INDEX.SCOPE] === SCOPE.GLOBAL &&
token.path[PATH_INDEX.CATEGORY] === CATEGORY.SPACING) satisfies Filter['filter'];
/**
* Filter for sizing tokens (slds.g.sizing.*)
*/
export const sizingFilterFn = ((token: TransformedToken, _options: Config) =>
token.path[PATH_INDEX.NAMESPACE] === NAMESPACE.SLDS &&
token.path[PATH_INDEX.SCOPE] === SCOPE.GLOBAL &&
token.path[PATH_INDEX.CATEGORY] === CATEGORY.SIZING) satisfies Filter['filter'];
/**
* Filter for radius/shape tokens (slds.g.radius.*)
*/
export const radiusFilterFn = ((token: TransformedToken, _options: Config) =>
token.path[PATH_INDEX.NAMESPACE] === NAMESPACE.SLDS &&
token.path[PATH_INDEX.SCOPE] === SCOPE.GLOBAL &&
token.path[PATH_INDEX.CATEGORY] === CATEGORY.RADIUS) satisfies Filter['filter'];
/**
* Filter for duration/motion tokens (slds.g.duration.*)
*/
export const durationFilterFn = ((token: TransformedToken, _options: Config) =>
token.path[PATH_INDEX.NAMESPACE] === NAMESPACE.SLDS &&
token.path[PATH_INDEX.SCOPE] === SCOPE.GLOBAL &&
token.path[PATH_INDEX.CATEGORY] === CATEGORY.DURATION) satisfies Filter['filter'];
/**
* Filter for font tokens (slds.g.font.*)
*/
export const fontFilterFn = ((token: TransformedToken, _options: Config) =>
token.path[PATH_INDEX.NAMESPACE] === NAMESPACE.SLDS &&
token.path[PATH_INDEX.SCOPE] === SCOPE.GLOBAL &&
token.path[PATH_INDEX.CATEGORY] === CATEGORY.FONT) satisfies Filter['filter'];
/**
* Filter for system color tokens (slds.g.color.{family}.base.{scale})
* Reuses existing helper function
*/
export const systemColorFilterFn = ((token: TransformedToken, _options: Config) =>
isSystemColorToken(token)) satisfies Filter['filter'];
/**
* Filter for reference color tokens (slds.r.color.*)
* Reuses existing helper function
*/
export const referenceColorFilterFn = ((token: TransformedToken, _options: Config) =>
isReferenceColorToken(token)) satisfies Filter['filter'];
/**
* Filter for semantic color tokens (slds.g.color.{semantic-name})
* Reuses existing helper function
*/
export const semanticColorFilterFn = ((token: TransformedToken, _options: Config) =>
isSemanticColorToken(token)) satisfies Filter['filter'];
/**
* Filter for palette color tokens (alias.palette.*)
* Reuses existing helper function
*/
export const paletteColorFilterFn = ((token: TransformedToken, _options: Config) =>
isPaletteToken(token)) satisfies Filter['filter'];
/**
* Base mobile filter - includes all mobile-relevant tokens (global, reference, and palette aliases)
* Used for TokensAll and color files that need cross-references
*/
export const mobileFilterFn = ((token: TransformedToken, _options: Config) =>
(token.path[0] === 'slds' && (token.path[1] === 'g' || token.path[1] === 'r')) ||
(token.path[0] === 'alias' && token.path[1] === 'palette')) satisfies Filter['filter'];
/**
* Register all mobile filters with Style Dictionary
* @param {object} StyleDictionary - Style Dictionary instance
*/
export function registerMobileFilters(StyleDictionary: StyleDictionaryHost) {
StyleDictionary.registerFilter({
name: 'filter/mobile-spacing',
filter: spacingFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-sizing',
filter: sizingFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-radius',
filter: radiusFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-duration',
filter: durationFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-font',
filter: fontFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-system-colors',
filter: systemColorFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-reference-colors',
filter: referenceColorFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-semantic-colors',
filter: semanticColorFilterFn,
});
StyleDictionary.registerFilter({
name: 'filter/mobile-palette-colors',
filter: paletteColorFilterFn,
});
// Register the base mobile filter
StyleDictionary.registerFilter({
name: 'filter/mobile',
filter: mobileFilterFn,
});
}
|