@blockle/blocks-core 0.21.8 → 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.
@@ -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 (typeof value === "string") {
8
- if (target.values[value]) {
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
- var _a;
16
+ const atomicValue = target.values[val];
14
17
  if (i === 0) {
15
- if (target.values[val]) {
16
- classList.push(target.values[val].defaultClass);
18
+ if (atomicValue) {
19
+ classList.push(atomicValue.defaultClass);
17
20
  }
18
- } else {
19
- classList.push(((_a = target.values[val]) == null ? void 0 : _a.conditions[i]) ?? "");
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 any[], V> = {
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 any[] ? {
16
+ type PropertyResultValue<TConditions> = TConditions extends unknown[] ? {
17
17
  defaultClass: string;
18
- conditions: TConditions extends any[] ? MapArray<TConditions, string> : never;
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 any[] ? {
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, const TConditions extends PropertyConditions>({ properties, conditions, }: PropertyDefinition<TProperties, TConditions>): PropertyResult<TProperties, TConditions>;
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
  };
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const CSSMatrixValuePattern = /matrix\((.*?)\)/;
3
4
  function parseCSSTransform(styleDeclaration) {
4
5
  const transform = styleDeclaration.getPropertyValue("transform");
5
- if (!transform || transform === "none" || !transform.startsWith("matrix(")) {
6
+ if (!transform || !CSSMatrixValuePattern.test(transform)) {
6
7
  return {
7
8
  a: 1,
8
9
  b: 0,
@@ -12,7 +13,11 @@ function parseCSSTransform(styleDeclaration) {
12
13
  ty: 0
13
14
  };
14
15
  }
15
- const matrixValues = transform.substring(7, transform.length - 1).split(",").map((value) => cssValueToNumber(value.trim()));
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()));
16
21
  if (matrixValues.length !== 6) {
17
22
  throw new Error("Invalid matrix value");
18
23
  }
@@ -1,6 +1,7 @@
1
+ const CSSMatrixValuePattern = /matrix\((.*?)\)/;
1
2
  function parseCSSTransform(styleDeclaration) {
2
3
  const transform = styleDeclaration.getPropertyValue("transform");
3
- if (!transform || transform === "none" || !transform.startsWith("matrix(")) {
4
+ if (!transform || !CSSMatrixValuePattern.test(transform)) {
4
5
  return {
5
6
  a: 1,
6
7
  b: 0,
@@ -10,7 +11,11 @@ function parseCSSTransform(styleDeclaration) {
10
11
  ty: 0
11
12
  };
12
13
  }
13
- const matrixValues = transform.substring(7, transform.length - 1).split(",").map((value) => cssValueToNumber(value.trim()));
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()));
14
19
  if (matrixValues.length !== 6) {
15
20
  throw new Error("Invalid matrix value");
16
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockle/blocks-core",
3
- "version": "0.21.8",
3
+ "version": "0.21.9",
4
4
  "description": "Core for Blocks",
5
5
  "type": "module",
6
6
  "sideEffects": false,