@blockle/blocks-core 0.21.7 → 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.
@@ -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.7",
3
+ "version": "0.21.8",
4
4
  "description": "Core for Blocks",
5
5
  "type": "module",
6
6
  "sideEffects": false,