@arbor-css/css-eval 0.0.110 → 0.0.112
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/computation.d.ts +24 -1
- package/dist/computation.d.ts.map +1 -1
- package/dist/computation.js +1 -1
- package/dist/computation.js.map +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/simplification.d.ts +5 -2
- package/dist/simplification.d.ts.map +1 -1
- package/dist/simplification.js +7 -37
- package/dist/simplification.js.map +1 -1
- package/dist/util.d.ts +3 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +59 -5
- package/dist/util.js.map +1 -1
- package/package.json +3 -2
package/dist/computation.d.ts
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
import { TokenPurpose } from '@arbor-css/tokens';
|
|
1
2
|
import { Css } from './interpolation.js';
|
|
2
3
|
import { CssEnvValues } from './resolveEnv.js';
|
|
3
4
|
import { CssSimplifier } from './simplification.js';
|
|
4
5
|
export interface CssResolutionContext {
|
|
6
|
+
/**
|
|
7
|
+
* Known property values to resolve and bake into the CSS. This is used to
|
|
8
|
+
* simplify output CSS where the dependencies of a value are known and
|
|
9
|
+
* hard-coded; for example, other values present in a mode.
|
|
10
|
+
*/
|
|
5
11
|
propertyValues?: Record<string, string | Css>;
|
|
12
|
+
/**
|
|
13
|
+
* Values from the runtime environment may be used to resolve and
|
|
14
|
+
* simplify runtime-known CSS value types like vw, vh, rem, etc.
|
|
15
|
+
* NOT meant for use in generating CSS for application; only really
|
|
16
|
+
* relevant for interactive tooling and introspection purposes.
|
|
17
|
+
*/
|
|
6
18
|
envValues?: CssEnvValues;
|
|
19
|
+
/**
|
|
20
|
+
* Skip applying known property values and env values
|
|
21
|
+
*/
|
|
7
22
|
skipBaking?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Optional; provide a simplifier implementation to reduce the size and complexity
|
|
25
|
+
* of the final CSS by pre-computing arithmetic and simplifying expressions.
|
|
26
|
+
*/
|
|
8
27
|
simplifier?: CssSimplifier;
|
|
28
|
+
/**
|
|
29
|
+
* Optional; helps tune simplification for particular CSS value types.
|
|
30
|
+
*/
|
|
31
|
+
purpose?: TokenPurpose;
|
|
9
32
|
}
|
|
10
|
-
export declare function resolveCss(input: Css, { propertyValues, envValues, skipBaking, simplifier, }: CssResolutionContext): string;
|
|
33
|
+
export declare function resolveCss(input: Css, { propertyValues, envValues, skipBaking, simplifier, purpose, }: CssResolutionContext): string;
|
|
11
34
|
//# sourceMappingURL=computation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computation.d.ts","sourceRoot":"","sources":["../src/computation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAc,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC;IAC9C,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"computation.d.ts","sourceRoot":"","sources":["../src/computation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAc,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,wBAAgB,UAAU,CACzB,KAAK,EAAE,GAAG,EACV,EACC,cAAmB,EACnB,SAAc,EACd,UAAkB,EAClB,UAAU,EACV,OAAO,GACP,EAAE,oBAAoB,UAevB"}
|
package/dist/computation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveEnv } from './resolveEnv.js';
|
|
2
2
|
import { resolveProperties } from './resolveProperties.js';
|
|
3
|
-
export function resolveCss(input, { propertyValues = {}, envValues = {}, skipBaking = false, simplifier, }) {
|
|
3
|
+
export function resolveCss(input, { propertyValues = {}, envValues = {}, skipBaking = false, simplifier, purpose, }) {
|
|
4
4
|
let result = skipBaking ?
|
|
5
5
|
input.text
|
|
6
6
|
: resolveEnv(resolveProperties(input, propertyValues), envValues).text;
|
package/dist/computation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computation.js","sourceRoot":"","sources":["../src/computation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computation.js","sourceRoot":"","sources":["../src/computation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAgC3D,MAAM,UAAU,UAAU,CACzB,KAAU,EACV,EACC,cAAc,GAAG,EAAE,EACnB,SAAS,GAAG,EAAE,EACd,UAAU,GAAG,KAAK,EAClB,UAAU,EACV,OAAO,GACe;IAEvB,IAAI,MAAM,GACT,UAAU,CAAC,CAAC;QACX,KAAK,CAAC,IAAI;QACX,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,EAAE,cAAc,CAAC,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC;IAExE,IAAI,UAAU,EAAE,CAAC;QAChB,MAAM,GAAG,UAAU,CAAC;YACnB,GAAG,KAAK;YACR,IAAI,EAAE,MAAM;SACZ,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const simplifier:
|
|
1
|
+
export declare const simplifier: import("./simplification.js").CssSimplifier;
|
|
2
2
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,6CAGrB,CAAC"}
|
package/dist/simplification.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TokenPurpose } from '@arbor-css/tokens';
|
|
1
2
|
import { Css } from './interpolation.js';
|
|
2
3
|
/**
|
|
3
4
|
* Applies simplifications not covered by LightningCSS.
|
|
@@ -13,7 +14,9 @@ export interface CssSimplificationOptions {
|
|
|
13
14
|
*/
|
|
14
15
|
passes: number;
|
|
15
16
|
}
|
|
16
|
-
export type CssSimplifier = (css: Css
|
|
17
|
+
export type CssSimplifier = (css: Css, options?: {
|
|
18
|
+
purpose?: TokenPurpose;
|
|
19
|
+
}) => string;
|
|
17
20
|
export type CssTransformFunction = ({ filename, code, }: {
|
|
18
21
|
filename: string;
|
|
19
22
|
code: Uint8Array;
|
|
@@ -26,5 +29,5 @@ export declare function createSimplifier(config: {
|
|
|
26
29
|
*/
|
|
27
30
|
transform: CssTransformFunction;
|
|
28
31
|
options?: CssSimplificationOptions;
|
|
29
|
-
}):
|
|
32
|
+
}): CssSimplifier;
|
|
30
33
|
//# sourceMappingURL=simplification.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simplification.d.ts","sourceRoot":"","sources":["../src/simplification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAGzC;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"simplification.d.ts","sourceRoot":"","sources":["../src/simplification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAGzC;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOzD;AAYD,MAAM,WAAW,wBAAwB;IACxC;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;CACf;AACD,MAAM,MAAM,aAAa,GAAG,CAC3B,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE;IACT,OAAO,CAAC,EAAE,YAAY,CAAC;CACvB,KACG,MAAM,CAAC;AACZ,MAAM,MAAM,oBAAoB,GAAG,CAAC,EACnC,QAAQ,EACR,IAAI,GACJ,EAAE;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;CACjB,KAAK;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAE3B,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACxC;;OAEG;IACH,SAAS,EAAE,oBAAoB,CAAC;IAChC,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACnC,GAAG,aAAa,CA0BhB"}
|
package/dist/simplification.js
CHANGED
|
@@ -1,46 +1,16 @@
|
|
|
1
|
+
import { replaceTopLevelTerms } from '@arbor-css/util';
|
|
1
2
|
import { unwrapDummyAssignment, wrapWithDummyAssignment } from './util.js';
|
|
2
3
|
/**
|
|
3
4
|
* Applies simplifications not covered by LightningCSS.
|
|
4
5
|
* Uses linear-time paren scanning instead of regex to avoid backtracking.
|
|
5
6
|
*/
|
|
6
7
|
export function simplifyPreprocessCss(css) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
while (searchIndex < css.length) {
|
|
11
|
-
const calcIndex = css.indexOf(calcKeyword, searchIndex);
|
|
12
|
-
if (calcIndex === -1) {
|
|
13
|
-
result += css.slice(searchIndex);
|
|
14
|
-
break;
|
|
8
|
+
return replaceTopLevelTerms(css, (term) => {
|
|
9
|
+
if (term.startsWith('calc(')) {
|
|
10
|
+
return 'calc(' + simplifyLikeUnitDivision(term.slice(5, -1)) + ')';
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const closeParenIndex = findMatchingParen(css, openParenIndex);
|
|
19
|
-
if (closeParenIndex === -1) {
|
|
20
|
-
result += css.slice(calcIndex);
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
const content = css.slice(openParenIndex + 1, closeParenIndex);
|
|
24
|
-
const simplified = simplifyLikeUnitDivision(content);
|
|
25
|
-
result += 'calc(' + simplified + ')';
|
|
26
|
-
searchIndex = closeParenIndex + 1;
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
function findMatchingParen(text, openParenIndex) {
|
|
31
|
-
let depth = 0;
|
|
32
|
-
for (let i = openParenIndex; i < text.length; i++) {
|
|
33
|
-
if (text[i] === '(') {
|
|
34
|
-
depth++;
|
|
35
|
-
}
|
|
36
|
-
else if (text[i] === ')') {
|
|
37
|
-
depth--;
|
|
38
|
-
if (depth === 0) {
|
|
39
|
-
return i;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return -1;
|
|
12
|
+
return term;
|
|
13
|
+
});
|
|
44
14
|
}
|
|
45
15
|
function simplifyLikeUnitDivision(content) {
|
|
46
16
|
return content.replace(/([0-9]+)([a-z]+)\s*\/\s*([0-9]+)\2/g, (_match, num1, _unit1, num2) => {
|
|
@@ -51,7 +21,7 @@ function simplifyLikeUnitDivision(content) {
|
|
|
51
21
|
export function createSimplifier(config) {
|
|
52
22
|
const enc = new TextEncoder();
|
|
53
23
|
const dec = new TextDecoder();
|
|
54
|
-
return (css) => {
|
|
24
|
+
return (css, options) => {
|
|
55
25
|
let cssToTransform = css.text;
|
|
56
26
|
for (let i = 0; i < (config.options?.passes ?? 1); i++) {
|
|
57
27
|
cssToTransform = simplifyPreprocessCss(cssToTransform);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simplification.js","sourceRoot":"","sources":["../src/simplification.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAChD,
|
|
1
|
+
{"version":3,"file":"simplification.js","sourceRoot":"","sources":["../src/simplification.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAChD,OAAO,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE;QACzC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9B,OAAO,OAAO,GAAG,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACpE,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB,CAAC,OAAe;IAChD,OAAO,OAAO,CAAC,OAAO,CACrB,qCAAqC,EACrC,CAAC,MAAM,EAAE,IA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,4 @@
|
|
|
1
|
+
import { TokenPurpose } from '@arbor-css/tokens';
|
|
1
2
|
/**
|
|
2
3
|
* LightningCSS only supports parsing full
|
|
3
4
|
* stylesheets, but we often need to resolve
|
|
@@ -5,6 +6,7 @@
|
|
|
5
6
|
* need to apply special processing to handle that case.
|
|
6
7
|
*/
|
|
7
8
|
export declare function isSingleValue(css: string): boolean;
|
|
8
|
-
export declare function
|
|
9
|
+
export declare function guessPurposeFromText(css: string): TokenPurpose;
|
|
10
|
+
export declare function wrapWithDummyAssignment(css: string, purpose?: TokenPurpose): string;
|
|
9
11
|
export declare function unwrapDummyAssignment(css: string): string;
|
|
10
12
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAUlD;
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAUlD;AA4BD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CA8B9D;AAED,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,YAAwC,GAC/C,MAAM,CAKR;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASzD"}
|
package/dist/util.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { replaceTopLevelTerms } from '@arbor-css/util';
|
|
1
2
|
/**
|
|
2
3
|
* LightningCSS only supports parsing full
|
|
3
4
|
* stylesheets, but we often need to resolve
|
|
@@ -12,16 +13,69 @@ export function isSingleValue(css) {
|
|
|
12
13
|
const withoutIf = css.replace(/if\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\)/g, '');
|
|
13
14
|
return !withoutIf.includes(':') && !withoutIf.includes(';');
|
|
14
15
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const purposeToPropertyTarget = {
|
|
17
|
+
color: 'background',
|
|
18
|
+
background: 'background',
|
|
19
|
+
'border-radius': 'border-radius',
|
|
20
|
+
shadow: 'box-shadow',
|
|
21
|
+
'border-style': 'border-style',
|
|
22
|
+
'border-width': 'border-width',
|
|
23
|
+
'font-size': 'font-size',
|
|
24
|
+
'font-weight': 'font-weight',
|
|
25
|
+
'easing-function': 'animation-timing-function',
|
|
26
|
+
'font-family': 'font-family',
|
|
27
|
+
'letter-spacing': 'letter-spacing',
|
|
28
|
+
'line-height': 'line-height',
|
|
29
|
+
duration: 'transition-duration',
|
|
30
|
+
'shadow-blur': 'width',
|
|
31
|
+
'shadow-color': 'background',
|
|
32
|
+
'shadow-spread': 'width',
|
|
33
|
+
'shadow-x': 'width',
|
|
34
|
+
'shadow-y': 'width',
|
|
35
|
+
border: 'border',
|
|
36
|
+
scalar: 'line-height',
|
|
37
|
+
size: 'width',
|
|
38
|
+
spacing: 'width',
|
|
39
|
+
other: 'background', // picked as a versatile simplifier property
|
|
40
|
+
};
|
|
41
|
+
export function guessPurposeFromText(css) {
|
|
42
|
+
// values with spaces in them could be border or shadow shorthands... or
|
|
43
|
+
// many other kinds of shorthands...
|
|
44
|
+
const withoutTermContents = replaceTopLevelTerms(css, () => '<term>');
|
|
45
|
+
const termCount = withoutTermContents.split(/\s+/).length;
|
|
46
|
+
if (termCount > 1) {
|
|
47
|
+
if (termCount === 2) {
|
|
48
|
+
return 'border-style';
|
|
49
|
+
}
|
|
50
|
+
else if (termCount === 3) {
|
|
51
|
+
return 'border';
|
|
52
|
+
}
|
|
53
|
+
else if (termCount > 3) {
|
|
54
|
+
return 'shadow';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// This is a very rough heuristic to determine the purpose of a token based on its value,
|
|
58
|
+
// which helps us choose appropriate simplification strategies.
|
|
59
|
+
if (css.includes('rgb') ||
|
|
60
|
+
css.includes('okl') ||
|
|
61
|
+
css.includes('#') ||
|
|
62
|
+
css.includes('hsl') ||
|
|
63
|
+
css.includes('lab') ||
|
|
64
|
+
css.includes('lch') ||
|
|
65
|
+
css.includes('color')) {
|
|
66
|
+
return 'color';
|
|
67
|
+
}
|
|
68
|
+
return 'other';
|
|
69
|
+
}
|
|
70
|
+
export function wrapWithDummyAssignment(css, purpose = guessPurposeFromText(css)) {
|
|
71
|
+
const propertyName = purposeToPropertyTarget[purpose] || 'background';
|
|
18
72
|
// Wrap the input in a dummy assignment to make it parseable as a stylesheet.
|
|
19
73
|
// We can remove this later since we only care about the value of the variable.
|
|
20
|
-
return
|
|
74
|
+
return `[data-arbor-result]{${propertyName}:${css};}`;
|
|
21
75
|
}
|
|
22
76
|
export function unwrapDummyAssignment(css) {
|
|
23
77
|
// Extract the original value from the dummy assignment.
|
|
24
|
-
const match = css.match(/\[data-arbor-result\]\s*{\s*
|
|
78
|
+
const match = css.match(/\[data-arbor-result\]\s*{\s*[\w-]+\s*:\s*(.+?)\s*;?\s*}/);
|
|
25
79
|
if (!match) {
|
|
26
80
|
throw new Error('Invalid dummy assignment format');
|
|
27
81
|
}
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACxC,6DAA6D;IAC7D,kDAAkD;IAClD,yEAAyE;IACzE,mCAAmC;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
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"lightningcss": "^1.32.0",
|
|
42
|
-
"@arbor-css/tokens": "0.0.
|
|
42
|
+
"@arbor-css/tokens": "0.0.112",
|
|
43
|
+
"@arbor-css/util": "0.0.112"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"build": "tsc",
|