@blockle/blocks-core 0.21.7 → 0.21.9
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/atoms/atoms.cjs +13 -7
- package/dist/atoms/atoms.css.d.ts +436 -176
- package/dist/atoms/atoms.js +13 -7
- package/dist/atoms/atoms.spec.d.ts +1 -0
- package/dist/atoms/defineProperties.cjs +5 -2
- package/dist/atoms/defineProperties.d.ts +5 -5
- package/dist/atoms/defineProperties.js +5 -2
- package/dist/css/cssMatrixUtils.cjs +64 -0
- package/dist/css/cssMatrixUtils.d.ts +13 -0
- package/dist/css/cssMatrixUtils.js +64 -0
- package/dist/css/cssMatrixUtils.test.d.ts +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/theme/makeComponentTheme.d.ts +1 -1
- package/package.json +1 -1
package/dist/atoms/atoms.js
CHANGED
|
@@ -4,20 +4,26 @@ function atoms(properties) {
|
|
|
4
4
|
for (const property in properties) {
|
|
5
5
|
const value = properties[property];
|
|
6
6
|
const target = atomicProperties[property];
|
|
7
|
-
if (
|
|
8
|
-
|
|
7
|
+
if (!target) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
11
|
+
if (target.values[value] !== void 0) {
|
|
9
12
|
classList.push(target.values[value].defaultClass);
|
|
10
13
|
}
|
|
11
14
|
} else if (Array.isArray(value)) {
|
|
12
15
|
value.forEach((val, i) => {
|
|
13
|
-
|
|
16
|
+
const atomicValue = target.values[val];
|
|
14
17
|
if (i === 0) {
|
|
15
|
-
if (
|
|
16
|
-
classList.push(
|
|
18
|
+
if (atomicValue) {
|
|
19
|
+
classList.push(atomicValue.defaultClass);
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!(atomicValue == null ? void 0 : atomicValue.conditions[i])) {
|
|
24
|
+
return;
|
|
20
25
|
}
|
|
26
|
+
classList.push(atomicValue == null ? void 0 : atomicValue.conditions[i]);
|
|
21
27
|
});
|
|
22
28
|
}
|
|
23
29
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -19,7 +19,7 @@ function defineProperties({
|
|
|
19
19
|
const propResult = {
|
|
20
20
|
defaultClass
|
|
21
21
|
};
|
|
22
|
-
if (conditions) {
|
|
22
|
+
if (isValidConditionList(conditions)) {
|
|
23
23
|
propResult.conditions = conditions.map((condition, i) => {
|
|
24
24
|
if (i === 0 && Object.keys(condition).length === 0) {
|
|
25
25
|
return defaultClass;
|
|
@@ -50,7 +50,7 @@ function defineProperties({
|
|
|
50
50
|
const propResult = {
|
|
51
51
|
defaultClass
|
|
52
52
|
};
|
|
53
|
-
if (conditions) {
|
|
53
|
+
if (isValidConditionList(conditions)) {
|
|
54
54
|
propResult.conditions = conditions.map((condition, i) => {
|
|
55
55
|
if (i === 0 && Object.keys(condition).length === 0) {
|
|
56
56
|
return defaultClass;
|
|
@@ -75,4 +75,7 @@ function defineProperties({
|
|
|
75
75
|
}
|
|
76
76
|
return result;
|
|
77
77
|
}
|
|
78
|
+
function isValidConditionList(condition) {
|
|
79
|
+
return Array.isArray(condition) && condition.length > 0;
|
|
80
|
+
}
|
|
78
81
|
exports.defineProperties = defineProperties;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Properties as CSSProperties } from 'csstype';
|
|
2
|
-
type MapArray<T extends
|
|
2
|
+
type MapArray<T extends unknown[], V> = {
|
|
3
3
|
[Index in keyof T]: V;
|
|
4
4
|
};
|
|
5
5
|
type AtomicPrimitiveValue = string | number;
|
|
@@ -13,20 +13,20 @@ type PropertyDefinition<TProperties, TConditions> = {
|
|
|
13
13
|
properties: TProperties;
|
|
14
14
|
conditions?: TConditions;
|
|
15
15
|
};
|
|
16
|
-
type PropertyResultValue<TConditions> = TConditions extends
|
|
16
|
+
type PropertyResultValue<TConditions> = TConditions extends unknown[] ? {
|
|
17
17
|
defaultClass: string;
|
|
18
|
-
conditions: TConditions extends
|
|
18
|
+
conditions: TConditions extends unknown[] ? MapArray<TConditions, string> : never;
|
|
19
19
|
} : {
|
|
20
20
|
defaultClass: string;
|
|
21
21
|
};
|
|
22
22
|
type PropertyResult<TProperties extends Properties, TConditions> = {
|
|
23
23
|
[K in keyof TProperties]: {
|
|
24
|
-
values: TProperties[K] extends
|
|
24
|
+
values: TProperties[K] extends AtomicPrimitiveValue[] ? {
|
|
25
25
|
[V in TProperties[K][number]]: PropertyResultValue<TConditions>;
|
|
26
26
|
} : {
|
|
27
27
|
[V in keyof TProperties[K]]: PropertyResultValue<TConditions>;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
export declare function defineProperties<const TProperties extends Properties,
|
|
31
|
+
export declare function defineProperties<const TProperties extends Properties, TConditions extends PropertyConditions | undefined>({ properties, conditions, }: PropertyDefinition<TProperties, TConditions>): PropertyResult<TProperties, TConditions>;
|
|
32
32
|
export {};
|
|
@@ -17,7 +17,7 @@ function defineProperties({
|
|
|
17
17
|
const propResult = {
|
|
18
18
|
defaultClass
|
|
19
19
|
};
|
|
20
|
-
if (conditions) {
|
|
20
|
+
if (isValidConditionList(conditions)) {
|
|
21
21
|
propResult.conditions = conditions.map((condition, i) => {
|
|
22
22
|
if (i === 0 && Object.keys(condition).length === 0) {
|
|
23
23
|
return defaultClass;
|
|
@@ -48,7 +48,7 @@ function defineProperties({
|
|
|
48
48
|
const propResult = {
|
|
49
49
|
defaultClass
|
|
50
50
|
};
|
|
51
|
-
if (conditions) {
|
|
51
|
+
if (isValidConditionList(conditions)) {
|
|
52
52
|
propResult.conditions = conditions.map((condition, i) => {
|
|
53
53
|
if (i === 0 && Object.keys(condition).length === 0) {
|
|
54
54
|
return defaultClass;
|
|
@@ -73,6 +73,9 @@ function defineProperties({
|
|
|
73
73
|
}
|
|
74
74
|
return result;
|
|
75
75
|
}
|
|
76
|
+
function isValidConditionList(condition) {
|
|
77
|
+
return Array.isArray(condition) && condition.length > 0;
|
|
78
|
+
}
|
|
76
79
|
export {
|
|
77
80
|
defineProperties
|
|
78
81
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const CSSMatrixValuePattern = /matrix\((.*?)\)/;
|
|
4
|
+
function parseCSSTransform(styleDeclaration) {
|
|
5
|
+
const transform = styleDeclaration.getPropertyValue("transform");
|
|
6
|
+
if (!transform || !CSSMatrixValuePattern.test(transform)) {
|
|
7
|
+
return {
|
|
8
|
+
a: 1,
|
|
9
|
+
b: 0,
|
|
10
|
+
c: 0,
|
|
11
|
+
d: 1,
|
|
12
|
+
tx: 0,
|
|
13
|
+
ty: 0
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const matrixMatch = transform.match(CSSMatrixValuePattern);
|
|
17
|
+
if (!matrixMatch || !matrixMatch[1]) {
|
|
18
|
+
throw new Error(`Invalid matrix value: ${transform}`);
|
|
19
|
+
}
|
|
20
|
+
const matrixValues = matrixMatch[1].split(",").map((value) => cssValueToNumber(value.trim()));
|
|
21
|
+
if (matrixValues.length !== 6) {
|
|
22
|
+
throw new Error("Invalid matrix value");
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
a: matrixValues[0],
|
|
26
|
+
b: matrixValues[1],
|
|
27
|
+
c: matrixValues[2],
|
|
28
|
+
d: matrixValues[3],
|
|
29
|
+
tx: matrixValues[4],
|
|
30
|
+
ty: matrixValues[5]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function getCSSScale(styleDeclaration) {
|
|
34
|
+
const scale = styleDeclaration.getPropertyValue("scale");
|
|
35
|
+
if (!scale || scale === "none") {
|
|
36
|
+
const matrix2d = parseCSSTransform(styleDeclaration);
|
|
37
|
+
const scaleX = Math.sqrt(matrix2d.a * matrix2d.a + matrix2d.b * matrix2d.b);
|
|
38
|
+
const scaleY = Math.sqrt(matrix2d.c * matrix2d.c + matrix2d.d * matrix2d.d);
|
|
39
|
+
return [scaleX, scaleY];
|
|
40
|
+
}
|
|
41
|
+
if (scale.includes(" ")) {
|
|
42
|
+
return scale.split(" ").map((value) => cssValueToNumber(value));
|
|
43
|
+
}
|
|
44
|
+
const scaleValue = cssValueToNumber(scale);
|
|
45
|
+
return [scaleValue, scaleValue];
|
|
46
|
+
}
|
|
47
|
+
function getOriginalElementSize(styleDeclaration, width, height) {
|
|
48
|
+
const [scaleX, scaleY] = getCSSScale(styleDeclaration);
|
|
49
|
+
return [width / scaleX, height / scaleY];
|
|
50
|
+
}
|
|
51
|
+
function cssValueToNumber(value) {
|
|
52
|
+
if (!value) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
const parsedValue = Number.parseFloat(value);
|
|
56
|
+
if (Number.isNaN(parsedValue)) {
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
return parsedValue;
|
|
60
|
+
}
|
|
61
|
+
exports.cssValueToNumber = cssValueToNumber;
|
|
62
|
+
exports.getCSSScale = getCSSScale;
|
|
63
|
+
exports.getOriginalElementSize = getOriginalElementSize;
|
|
64
|
+
exports.parseCSSTransform = parseCSSTransform;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Vector2D = [x: number, y: number];
|
|
2
|
+
export type Matrix2D = {
|
|
3
|
+
a: number;
|
|
4
|
+
b: number;
|
|
5
|
+
c: number;
|
|
6
|
+
d: number;
|
|
7
|
+
tx: number;
|
|
8
|
+
ty: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function parseCSSTransform(styleDeclaration: CSSStyleDeclaration): Matrix2D;
|
|
11
|
+
export declare function getCSSScale(styleDeclaration: CSSStyleDeclaration): Vector2D;
|
|
12
|
+
export declare function getOriginalElementSize(styleDeclaration: CSSStyleDeclaration, width: number, height: number): Vector2D;
|
|
13
|
+
export declare function cssValueToNumber(value?: string): number;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const CSSMatrixValuePattern = /matrix\((.*?)\)/;
|
|
2
|
+
function parseCSSTransform(styleDeclaration) {
|
|
3
|
+
const transform = styleDeclaration.getPropertyValue("transform");
|
|
4
|
+
if (!transform || !CSSMatrixValuePattern.test(transform)) {
|
|
5
|
+
return {
|
|
6
|
+
a: 1,
|
|
7
|
+
b: 0,
|
|
8
|
+
c: 0,
|
|
9
|
+
d: 1,
|
|
10
|
+
tx: 0,
|
|
11
|
+
ty: 0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const matrixMatch = transform.match(CSSMatrixValuePattern);
|
|
15
|
+
if (!matrixMatch || !matrixMatch[1]) {
|
|
16
|
+
throw new Error(`Invalid matrix value: ${transform}`);
|
|
17
|
+
}
|
|
18
|
+
const matrixValues = matrixMatch[1].split(",").map((value) => cssValueToNumber(value.trim()));
|
|
19
|
+
if (matrixValues.length !== 6) {
|
|
20
|
+
throw new Error("Invalid matrix value");
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
a: matrixValues[0],
|
|
24
|
+
b: matrixValues[1],
|
|
25
|
+
c: matrixValues[2],
|
|
26
|
+
d: matrixValues[3],
|
|
27
|
+
tx: matrixValues[4],
|
|
28
|
+
ty: matrixValues[5]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function getCSSScale(styleDeclaration) {
|
|
32
|
+
const scale = styleDeclaration.getPropertyValue("scale");
|
|
33
|
+
if (!scale || scale === "none") {
|
|
34
|
+
const matrix2d = parseCSSTransform(styleDeclaration);
|
|
35
|
+
const scaleX = Math.sqrt(matrix2d.a * matrix2d.a + matrix2d.b * matrix2d.b);
|
|
36
|
+
const scaleY = Math.sqrt(matrix2d.c * matrix2d.c + matrix2d.d * matrix2d.d);
|
|
37
|
+
return [scaleX, scaleY];
|
|
38
|
+
}
|
|
39
|
+
if (scale.includes(" ")) {
|
|
40
|
+
return scale.split(" ").map((value) => cssValueToNumber(value));
|
|
41
|
+
}
|
|
42
|
+
const scaleValue = cssValueToNumber(scale);
|
|
43
|
+
return [scaleValue, scaleValue];
|
|
44
|
+
}
|
|
45
|
+
function getOriginalElementSize(styleDeclaration, width, height) {
|
|
46
|
+
const [scaleX, scaleY] = getCSSScale(styleDeclaration);
|
|
47
|
+
return [width / scaleX, height / scaleY];
|
|
48
|
+
}
|
|
49
|
+
function cssValueToNumber(value) {
|
|
50
|
+
if (!value) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
const parsedValue = Number.parseFloat(value);
|
|
54
|
+
if (Number.isNaN(parsedValue)) {
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
return parsedValue;
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
cssValueToNumber,
|
|
61
|
+
getCSSScale,
|
|
62
|
+
getOriginalElementSize,
|
|
63
|
+
parseCSSTransform
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -16,6 +16,7 @@ const helpers = require("./utils/typing/helpers.cjs");
|
|
|
16
16
|
const atoms = require("./atoms/atoms.cjs");
|
|
17
17
|
const atoms_css = require("./atoms/atoms.css.cjs");
|
|
18
18
|
const getAtomsAndProps = require("./atoms/getAtomsAndProps.cjs");
|
|
19
|
+
const cssMatrixUtils = require("./css/cssMatrixUtils.cjs");
|
|
19
20
|
exports.breakpointNames = breakpoint.breakpointNames;
|
|
20
21
|
exports.minMediaQuery = breakpoint.minMediaQuery;
|
|
21
22
|
exports.blocksLayer = layers_css.blocksLayer;
|
|
@@ -35,3 +36,7 @@ exports.isObjectLike = helpers.isObjectLike;
|
|
|
35
36
|
exports.atoms = atoms.atoms;
|
|
36
37
|
exports.atomicProperties = atoms_css.atomicProperties;
|
|
37
38
|
exports.getAtomsAndProps = getAtomsAndProps.getAtomsAndProps;
|
|
39
|
+
exports.cssValueToNumber = cssMatrixUtils.cssValueToNumber;
|
|
40
|
+
exports.getCSSScale = cssMatrixUtils.getCSSScale;
|
|
41
|
+
exports.getOriginalElementSize = cssMatrixUtils.getOriginalElementSize;
|
|
42
|
+
exports.parseCSSTransform = cssMatrixUtils.parseCSSTransform;
|
package/dist/index.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export { atoms, type Atoms } from './atoms/atoms';
|
|
|
19
19
|
export { atomicProperties } from './atoms/atoms.css';
|
|
20
20
|
export type { MarginAtoms, PaddingAtoms, TextAtoms } from './atoms/atomTypes';
|
|
21
21
|
export { getAtomsAndProps } from './atoms/getAtomsAndProps';
|
|
22
|
+
export { cssValueToNumber, getCSSScale, getOriginalElementSize, parseCSSTransform, } from './css/cssMatrixUtils';
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { isObjectLike } from "./utils/typing/helpers.js";
|
|
|
14
14
|
import { atoms } from "./atoms/atoms.js";
|
|
15
15
|
import { atomicProperties } from "./atoms/atoms.css.js";
|
|
16
16
|
import { getAtomsAndProps } from "./atoms/getAtomsAndProps.js";
|
|
17
|
+
import { cssValueToNumber, getCSSScale, getOriginalElementSize, parseCSSTransform } from "./css/cssMatrixUtils.js";
|
|
17
18
|
export {
|
|
18
19
|
alignItemsMap,
|
|
19
20
|
atomicProperties,
|
|
@@ -22,8 +23,11 @@ export {
|
|
|
22
23
|
breakpointNames,
|
|
23
24
|
classnames,
|
|
24
25
|
composeRefs,
|
|
26
|
+
cssValueToNumber,
|
|
25
27
|
getAtomsAndProps,
|
|
26
28
|
getBoundValue,
|
|
29
|
+
getCSSScale,
|
|
30
|
+
getOriginalElementSize,
|
|
27
31
|
hasAnimationDuration,
|
|
28
32
|
isObjectLike,
|
|
29
33
|
justifyContentMap,
|
|
@@ -31,6 +35,7 @@ export {
|
|
|
31
35
|
makeTheme,
|
|
32
36
|
mergeProps,
|
|
33
37
|
minMediaQuery,
|
|
38
|
+
parseCSSTransform,
|
|
34
39
|
rem,
|
|
35
40
|
roundToPrecision,
|
|
36
41
|
vars
|
|
@@ -25,5 +25,5 @@ export type ComponentTheme<T extends RecordLike> = ComponentThemeToStyles<T> & {
|
|
|
25
25
|
export type ThemeComponentsStyles = {
|
|
26
26
|
[K in keyof ComponentThemes]?: ComponentTheme<ComponentThemes[K]>;
|
|
27
27
|
};
|
|
28
|
-
export declare function makeComponentTheme<T extends keyof ThemeComponentsStyles>(component: T, componentTheme: ThemeComponentsStyles[T]): ThemeComponentsStyles[T]
|
|
28
|
+
export declare function makeComponentTheme<T extends keyof ThemeComponentsStyles>(component: T, componentTheme: Exclude<ThemeComponentsStyles[T], undefined>): Exclude<ThemeComponentsStyles[T], undefined>;
|
|
29
29
|
export {};
|