@arbor-css/shadows 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 +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GlobalConfig } from '../../globals/dist/globalProps.js';
|
|
2
|
+
export declare const defaultShadowLevels: readonly ["xs", "sm", "md", "lg", "xl"];
|
|
3
|
+
export type DefaultShadowLevel = (typeof defaultShadowLevels)[number];
|
|
4
|
+
export interface ShadowConfig<TSpacingLevel extends string> {
|
|
5
|
+
levels?: Record<TSpacingLevel, CompiledShadowLevel>;
|
|
6
|
+
defaultLevel?: TSpacingLevel;
|
|
7
|
+
globals?: GlobalConfig;
|
|
8
|
+
}
|
|
9
|
+
export interface CompiledShadowLevel {
|
|
10
|
+
x: string;
|
|
11
|
+
y: string;
|
|
12
|
+
blur: string;
|
|
13
|
+
spread: string;
|
|
14
|
+
color: string;
|
|
15
|
+
}
|
|
16
|
+
export interface CompiledShadows<TShadowLevel extends string = DefaultShadowLevel> {
|
|
17
|
+
defaultLevel: TShadowLevel;
|
|
18
|
+
levels: {
|
|
19
|
+
[K in TShadowLevel]: CompiledShadowLevel;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare function compileShadows<TShadowLevel extends string = DefaultShadowLevel>(config: ShadowConfig<TShadowLevel>): CompiledShadows<TShadowLevel>;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAgB,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE/E,eAAO,MAAM,mBAAmB,yCAA0C,CAAC;AAC3E,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,MAAM,WAAW,YAAY,CAAC,aAAa,SAAS,MAAM;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;IACpD,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IACnC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe,CAC/B,YAAY,SAAS,MAAM,GAAG,kBAAkB;IAEhD,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE;SACN,CAAC,IAAI,YAAY,GAAG,mBAAmB;KACxC,CAAC;CACF;AAsBD,wBAAgB,cAAc,CAC7B,YAAY,SAAS,MAAM,GAAG,kBAAkB,EAC/C,MAAM,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CA0DnE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { $, computeEquation, printComputationResult, } from '@arbor-css/calc';
|
|
2
|
+
import { $dynamicProps } from '@arbor-css/globals';
|
|
3
|
+
import { $globalProps } from '../../globals/dist/globalProps.js';
|
|
4
|
+
export const defaultShadowLevels = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
5
|
+
const defaultShadowXEquation = (step) => $.literal(`0px`);
|
|
6
|
+
const defaultShadowYEquation = (step) => $.multiply($.literal('1px'), $.fn('pow', $.literal(2), $.literal(step - 1)));
|
|
7
|
+
const defaultShadowBlurEquation = (step) => $.multiply($.literal($globalProps.shadowBlur.varFallback('0.5')), $.literal($globalProps.baseSpacingSize.varFallback('0.5rem')), $.literal(0.25), $.fn('pow', $.literal(2), $.literal(step - 1)));
|
|
8
|
+
const defaultShadowSpreadEquation = (step) => $.multiply($.literal($globalProps.shadowSpread.varFallback('1')), $.literal('1px'));
|
|
9
|
+
const defaultShadowColorEquation = (step) => $.literal($dynamicProps.shadowColor.varFallback($globalProps.defaultShadowColor.var));
|
|
10
|
+
export function compileShadows(config) {
|
|
11
|
+
const levelNames = config.levels ?
|
|
12
|
+
Object.keys(config.levels)
|
|
13
|
+
: defaultShadowLevels;
|
|
14
|
+
const baseIndex =
|
|
15
|
+
// user supplied explicit default level
|
|
16
|
+
config.defaultLevel ? levelNames.indexOf(config.defaultLevel)
|
|
17
|
+
// user did not give us a default level, but did give us custom levels, so we'll pick the middle one as the default
|
|
18
|
+
: config.levels ? Math.floor(levelNames.length / 2)
|
|
19
|
+
// user did not give us a default level, and is using the default levels, so we'll use 'md' as the default.
|
|
20
|
+
: levelNames.indexOf('md');
|
|
21
|
+
const ctx = {
|
|
22
|
+
propertyValues: {
|
|
23
|
+
[$globalProps.defaultShadowColor.name]: config.globals?.defaultShadowColor?.toString(),
|
|
24
|
+
[$globalProps.shadowSpread.name]: config.globals?.shadowSpread?.toString(),
|
|
25
|
+
[$globalProps.baseSpacingSize.name]: config.globals?.baseSpacingSize?.toString(),
|
|
26
|
+
[$globalProps.shadowBlur.name]: config.globals?.shadowBlur?.toString(),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const levels = levelNames.reduce((acc, name, i) => {
|
|
30
|
+
const nameCast = name;
|
|
31
|
+
const levelConfig = config.levels?.[nameCast];
|
|
32
|
+
acc[nameCast] = {
|
|
33
|
+
x: printComputationResult(computeEquation(defaultShadowXEquation(i), ctx)),
|
|
34
|
+
y: printComputationResult(computeEquation(defaultShadowYEquation(i), ctx)),
|
|
35
|
+
blur: printComputationResult(computeEquation(defaultShadowBlurEquation(i), ctx)),
|
|
36
|
+
spread: printComputationResult(computeEquation(defaultShadowSpreadEquation(i), ctx)),
|
|
37
|
+
color: printComputationResult(computeEquation(defaultShadowColorEquation(i), ctx)),
|
|
38
|
+
...levelConfig,
|
|
39
|
+
};
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
42
|
+
return {
|
|
43
|
+
defaultLevel: config.defaultLevel ?? levelNames[baseIndex],
|
|
44
|
+
levels,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,CAAC,EAED,eAAe,EACf,sBAAsB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAgB,MAAM,mCAAmC,CAAC;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAC;AA0B3E,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAClE,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,EAAE,CAC/C,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,MAAM,yBAAyB,GAAG,CAAC,IAAY,EAAE,EAAE,CAClD,CAAC,CAAC,QAAQ,CACT,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EACrD,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,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ACN,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arbor-css/shadows",
|
|
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/calc": "0.0.1",
|
|
26
|
+
"@arbor-css/globals": "0.0.1",
|
|
27
|
+
"@arbor-css/tokens": "0.0.1"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"dev": "tsc -w --preserveWatchOutput"
|
|
32
|
+
}
|
|
33
|
+
}
|