@blockle/blocks-core 0.21.6 → 0.21.8

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.
@@ -8,21 +8,19 @@ function defineProperties({
8
8
  const result = {};
9
9
  for (const property in properties) {
10
10
  const values = properties[property];
11
- result[property] = {
11
+ const propertyResult = {
12
12
  values: {}
13
13
  };
14
- const ref = result[property];
15
- if (!ref || !ref.values) {
16
- throw new Error(`Invalid property definition for ${property}`);
17
- }
18
14
  if (Array.isArray(values)) {
19
15
  for (const value of values) {
20
16
  const defaultClass = css.style({
21
17
  [property]: value
22
18
  });
23
- ref.values[value] = {
24
- defaultClass,
25
- conditions: conditions == null ? void 0 : conditions.map((condition, i) => {
19
+ const propResult = {
20
+ defaultClass
21
+ };
22
+ if (conditions) {
23
+ propResult.conditions = conditions.map((condition, i) => {
26
24
  if (i === 0 && Object.keys(condition).length === 0) {
27
25
  return defaultClass;
28
26
  }
@@ -38,21 +36,22 @@ function defineProperties({
38
36
  throw new Error(
39
37
  `Invalid condition for ${property}: ${JSON.stringify(condition)}`
40
38
  );
41
- })
42
- };
43
- if (!conditions && "conditions" in ref.values) {
44
- delete ref.values.conditions;
39
+ });
45
40
  }
41
+ propertyResult.values[value] = propResult;
46
42
  }
43
+ result[property] = propertyResult;
47
44
  continue;
48
45
  }
49
46
  for (const value in values) {
50
47
  const defaultClass = css.style({
51
48
  [property]: values[value]
52
49
  });
53
- ref.values[value] = {
54
- defaultClass,
55
- conditions: conditions == null ? void 0 : conditions.map((condition, i) => {
50
+ const propResult = {
51
+ defaultClass
52
+ };
53
+ if (conditions) {
54
+ propResult.conditions = conditions.map((condition, i) => {
56
55
  if (i === 0 && Object.keys(condition).length === 0) {
57
56
  return defaultClass;
58
57
  }
@@ -68,12 +67,11 @@ function defineProperties({
68
67
  throw new Error(
69
68
  `Invalid condition for ${property}: ${JSON.stringify(condition)}`
70
69
  );
71
- })
72
- };
73
- if (!conditions && "conditions" in ref.values) {
74
- delete ref.values.conditions;
70
+ });
75
71
  }
72
+ propertyResult.values[value] = propResult;
76
73
  }
74
+ result[property] = propertyResult;
77
75
  }
78
76
  return result;
79
77
  }
@@ -6,21 +6,19 @@ function defineProperties({
6
6
  const result = {};
7
7
  for (const property in properties) {
8
8
  const values = properties[property];
9
- result[property] = {
9
+ const propertyResult = {
10
10
  values: {}
11
11
  };
12
- const ref = result[property];
13
- if (!ref || !ref.values) {
14
- throw new Error(`Invalid property definition for ${property}`);
15
- }
16
12
  if (Array.isArray(values)) {
17
13
  for (const value of values) {
18
14
  const defaultClass = style({
19
15
  [property]: value
20
16
  });
21
- ref.values[value] = {
22
- defaultClass,
23
- conditions: conditions == null ? void 0 : conditions.map((condition, i) => {
17
+ const propResult = {
18
+ defaultClass
19
+ };
20
+ if (conditions) {
21
+ propResult.conditions = conditions.map((condition, i) => {
24
22
  if (i === 0 && Object.keys(condition).length === 0) {
25
23
  return defaultClass;
26
24
  }
@@ -36,21 +34,22 @@ function defineProperties({
36
34
  throw new Error(
37
35
  `Invalid condition for ${property}: ${JSON.stringify(condition)}`
38
36
  );
39
- })
40
- };
41
- if (!conditions && "conditions" in ref.values) {
42
- delete ref.values.conditions;
37
+ });
43
38
  }
39
+ propertyResult.values[value] = propResult;
44
40
  }
41
+ result[property] = propertyResult;
45
42
  continue;
46
43
  }
47
44
  for (const value in values) {
48
45
  const defaultClass = style({
49
46
  [property]: values[value]
50
47
  });
51
- ref.values[value] = {
52
- defaultClass,
53
- conditions: conditions == null ? void 0 : conditions.map((condition, i) => {
48
+ const propResult = {
49
+ defaultClass
50
+ };
51
+ if (conditions) {
52
+ propResult.conditions = conditions.map((condition, i) => {
54
53
  if (i === 0 && Object.keys(condition).length === 0) {
55
54
  return defaultClass;
56
55
  }
@@ -66,12 +65,11 @@ function defineProperties({
66
65
  throw new Error(
67
66
  `Invalid condition for ${property}: ${JSON.stringify(condition)}`
68
67
  );
69
- })
70
- };
71
- if (!conditions && "conditions" in ref.values) {
72
- delete ref.values.conditions;
68
+ });
73
69
  }
70
+ propertyResult.values[value] = propResult;
74
71
  }
72
+ result[property] = propertyResult;
75
73
  }
76
74
  return result;
77
75
  }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function parseCSSTransform(styleDeclaration) {
4
+ const transform = styleDeclaration.getPropertyValue("transform");
5
+ if (!transform || transform === "none" || !transform.startsWith("matrix(")) {
6
+ return {
7
+ a: 1,
8
+ b: 0,
9
+ c: 0,
10
+ d: 1,
11
+ tx: 0,
12
+ ty: 0
13
+ };
14
+ }
15
+ const matrixValues = transform.substring(7, transform.length - 1).split(",").map((value) => cssValueToNumber(value.trim()));
16
+ if (matrixValues.length !== 6) {
17
+ throw new Error("Invalid matrix value");
18
+ }
19
+ return {
20
+ a: matrixValues[0],
21
+ b: matrixValues[1],
22
+ c: matrixValues[2],
23
+ d: matrixValues[3],
24
+ tx: matrixValues[4],
25
+ ty: matrixValues[5]
26
+ };
27
+ }
28
+ function getCSSScale(styleDeclaration) {
29
+ const scale = styleDeclaration.getPropertyValue("scale");
30
+ if (!scale || scale === "none") {
31
+ const matrix2d = parseCSSTransform(styleDeclaration);
32
+ const scaleX = Math.sqrt(matrix2d.a * matrix2d.a + matrix2d.b * matrix2d.b);
33
+ const scaleY = Math.sqrt(matrix2d.c * matrix2d.c + matrix2d.d * matrix2d.d);
34
+ return [scaleX, scaleY];
35
+ }
36
+ if (scale.includes(" ")) {
37
+ return scale.split(" ").map((value) => cssValueToNumber(value));
38
+ }
39
+ const scaleValue = cssValueToNumber(scale);
40
+ return [scaleValue, scaleValue];
41
+ }
42
+ function getOriginalElementSize(styleDeclaration, width, height) {
43
+ const [scaleX, scaleY] = getCSSScale(styleDeclaration);
44
+ return [width / scaleX, height / scaleY];
45
+ }
46
+ function cssValueToNumber(value) {
47
+ if (!value) {
48
+ return 0;
49
+ }
50
+ const parsedValue = Number.parseFloat(value);
51
+ if (Number.isNaN(parsedValue)) {
52
+ return 0;
53
+ }
54
+ return parsedValue;
55
+ }
56
+ exports.cssValueToNumber = cssValueToNumber;
57
+ exports.getCSSScale = getCSSScale;
58
+ exports.getOriginalElementSize = getOriginalElementSize;
59
+ 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,59 @@
1
+ function parseCSSTransform(styleDeclaration) {
2
+ const transform = styleDeclaration.getPropertyValue("transform");
3
+ if (!transform || transform === "none" || !transform.startsWith("matrix(")) {
4
+ return {
5
+ a: 1,
6
+ b: 0,
7
+ c: 0,
8
+ d: 1,
9
+ tx: 0,
10
+ ty: 0
11
+ };
12
+ }
13
+ const matrixValues = transform.substring(7, transform.length - 1).split(",").map((value) => cssValueToNumber(value.trim()));
14
+ if (matrixValues.length !== 6) {
15
+ throw new Error("Invalid matrix value");
16
+ }
17
+ return {
18
+ a: matrixValues[0],
19
+ b: matrixValues[1],
20
+ c: matrixValues[2],
21
+ d: matrixValues[3],
22
+ tx: matrixValues[4],
23
+ ty: matrixValues[5]
24
+ };
25
+ }
26
+ function getCSSScale(styleDeclaration) {
27
+ const scale = styleDeclaration.getPropertyValue("scale");
28
+ if (!scale || scale === "none") {
29
+ const matrix2d = parseCSSTransform(styleDeclaration);
30
+ const scaleX = Math.sqrt(matrix2d.a * matrix2d.a + matrix2d.b * matrix2d.b);
31
+ const scaleY = Math.sqrt(matrix2d.c * matrix2d.c + matrix2d.d * matrix2d.d);
32
+ return [scaleX, scaleY];
33
+ }
34
+ if (scale.includes(" ")) {
35
+ return scale.split(" ").map((value) => cssValueToNumber(value));
36
+ }
37
+ const scaleValue = cssValueToNumber(scale);
38
+ return [scaleValue, scaleValue];
39
+ }
40
+ function getOriginalElementSize(styleDeclaration, width, height) {
41
+ const [scaleX, scaleY] = getCSSScale(styleDeclaration);
42
+ return [width / scaleX, height / scaleY];
43
+ }
44
+ function cssValueToNumber(value) {
45
+ if (!value) {
46
+ return 0;
47
+ }
48
+ const parsedValue = Number.parseFloat(value);
49
+ if (Number.isNaN(parsedValue)) {
50
+ return 0;
51
+ }
52
+ return parsedValue;
53
+ }
54
+ export {
55
+ cssValueToNumber,
56
+ getCSSScale,
57
+ getOriginalElementSize,
58
+ parseCSSTransform
59
+ };
@@ -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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockle/blocks-core",
3
- "version": "0.21.6",
3
+ "version": "0.21.8",
4
4
  "description": "Core for Blocks",
5
5
  "type": "module",
6
6
  "sideEffects": false,