@arbor-css/spacing 0.0.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.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GlobalConfig } from '../../globals/dist/globalProps.js';
|
|
2
|
+
export declare const defaultSpacingLevels: readonly ["2xs", "xs", "sm", "md", "lg", "xl", "2xl", "3xl"];
|
|
3
|
+
export type DefaultSpacingLevel = (typeof defaultSpacingLevels)[number];
|
|
4
|
+
export interface SpacingConfig<TSpacingLevel extends string> {
|
|
5
|
+
levels?: Record<TSpacingLevel, string | number>;
|
|
6
|
+
defaultLevel?: TSpacingLevel;
|
|
7
|
+
globals?: GlobalConfig;
|
|
8
|
+
}
|
|
9
|
+
export interface CompiledSpacing<TSpacingLevel extends string = DefaultSpacingLevel> {
|
|
10
|
+
defaultLevel: TSpacingLevel;
|
|
11
|
+
levels: {
|
|
12
|
+
[K in TSpacingLevel]: string | number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare function compileSpacing<TSpacingLevel extends string = DefaultSpacingLevel>(config: SpacingConfig<TSpacingLevel>): CompiledSpacing<TSpacingLevel>;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE/E,eAAO,MAAM,oBAAoB,8DASvB,CAAC;AACX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAcxE,MAAM,WAAW,aAAa,CAAC,aAAa,SAAS,MAAM;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAChD,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,eAAe,CAC/B,aAAa,SAAS,MAAM,GAAG,mBAAmB;IAElD,YAAY,EAAE,aAAa,CAAC;IAC5B,MAAM,EAAE;SACN,CAAC,IAAI,aAAa,GAAG,MAAM,GAAG,MAAM;KACrC,CAAC;CACF;AAED,wBAAgB,cAAc,CAC7B,aAAa,SAAS,MAAM,GAAG,mBAAmB,EACjD,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,eAAe,CAAC,aAAa,CAAC,CAsCtE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { $, computeEquation, printComputationResult } from '@arbor-css/calc';
|
|
2
|
+
import { $globalProps } from '../../globals/dist/globalProps.js';
|
|
3
|
+
export const defaultSpacingLevels = [
|
|
4
|
+
'2xs',
|
|
5
|
+
'xs',
|
|
6
|
+
'sm',
|
|
7
|
+
'md',
|
|
8
|
+
'lg',
|
|
9
|
+
'xl',
|
|
10
|
+
'2xl',
|
|
11
|
+
'3xl',
|
|
12
|
+
];
|
|
13
|
+
const defaultSpacingEquation = (step) => $.multiply(
|
|
14
|
+
// calculate rem value of the spacing relative to the
|
|
15
|
+
// font size.
|
|
16
|
+
$.divide($.literal($globalProps.baseSpacingSize.var), $.literal($globalProps.baseFontSize.var)), $.literal('1rem'), $.fn('pow', $.literal(1.5), $.literal(step)));
|
|
17
|
+
export function compileSpacing(config) {
|
|
18
|
+
const levelNames = config.levels ?
|
|
19
|
+
Object.keys(config.levels)
|
|
20
|
+
: defaultSpacingLevels;
|
|
21
|
+
const baseIndex =
|
|
22
|
+
// user supplied explicit default level
|
|
23
|
+
config.defaultLevel ? levelNames.indexOf(config.defaultLevel)
|
|
24
|
+
// user did not give us a default level, but did give us custom levels, so we'll pick the middle one as the default
|
|
25
|
+
: config.levels ? Math.floor(levelNames.length / 2)
|
|
26
|
+
// user did not give us a default level, and is using the default levels, so we'll use 'md' as the default.
|
|
27
|
+
: levelNames.indexOf('md');
|
|
28
|
+
const levels = levelNames.reduce((acc, name, i) => {
|
|
29
|
+
const nameCast = name;
|
|
30
|
+
const levelConfig = config.levels?.[nameCast]?.toString();
|
|
31
|
+
acc[nameCast] =
|
|
32
|
+
levelConfig ??
|
|
33
|
+
printComputationResult(computeEquation(defaultSpacingEquation(i - baseIndex), {
|
|
34
|
+
propertyValues: {
|
|
35
|
+
[$globalProps.baseSpacingSize.name]: config.globals?.baseSpacingSize?.toString(),
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
return {
|
|
41
|
+
defaultLevel: config.defaultLevel ?? levelNames[baseIndex],
|
|
42
|
+
levels,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAgB,MAAM,mCAAmC,CAAC;AAE/E,MAAM,CAAC,MAAM,oBAAoB,GAAG;IACnC,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,KAAK;CACI,CAAC;AAGX,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,EAAE,CAC/C,CAAC,CAAC,QAAQ;AACT,qDAAqD;AACrD,aAAa;AACb,CAAC,CAAC,MAAM,CACP,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,CAAC,EAC3C,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,GAA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ACZ,CAAC,EACD,EAAmC,CACS,CAAC;IAE9C,OAAO;QACN,YAAY,EACX,MAAM,CAAC,YAAY,IAAK,UAAU,CAAC,SAAS,CAAmB;QAChE,MAAM;KACN,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arbor-css/spacing",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"development": "./src/index.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"node": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^6.0.3"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@arbor-css/tokens": "0.0.1",
|
|
26
|
+
"@arbor-css/globals": "0.0.1",
|
|
27
|
+
"@arbor-css/calc": "0.0.1"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"dev": "tsc -w --preserveWatchOutput"
|
|
32
|
+
}
|
|
33
|
+
}
|