@blockle/blocks-core 0.21.8 → 0.21.10

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 {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const css = require("@vanilla-extract/css");
4
+ const layers_css = require("../css/layers.css.cjs");
4
5
  function defineProperties({
5
6
  properties,
6
7
  conditions
@@ -14,21 +15,29 @@ function defineProperties({
14
15
  if (Array.isArray(values)) {
15
16
  for (const value of values) {
16
17
  const defaultClass = css.style({
17
- [property]: value
18
+ "@layer": {
19
+ [layers_css.blocksLayer]: {
20
+ [property]: value
21
+ }
22
+ }
18
23
  });
19
24
  const propResult = {
20
25
  defaultClass
21
26
  };
22
- if (conditions) {
27
+ if (isValidConditionList(conditions)) {
23
28
  propResult.conditions = conditions.map((condition, i) => {
24
29
  if (i === 0 && Object.keys(condition).length === 0) {
25
30
  return defaultClass;
26
31
  }
27
32
  if (typeof condition === "object" && condition["@media"]) {
28
33
  return css.style({
29
- "@media": {
30
- [condition["@media"]]: {
31
- [property]: value
34
+ "@layer": {
35
+ [layers_css.blocksLayer]: {
36
+ "@media": {
37
+ [condition["@media"]]: {
38
+ [property]: value
39
+ }
40
+ }
32
41
  }
33
42
  }
34
43
  });
@@ -45,12 +54,16 @@ function defineProperties({
45
54
  }
46
55
  for (const value in values) {
47
56
  const defaultClass = css.style({
48
- [property]: values[value]
57
+ "@layer": {
58
+ [layers_css.blocksLayer]: {
59
+ [property]: values[value]
60
+ }
61
+ }
49
62
  });
50
63
  const propResult = {
51
64
  defaultClass
52
65
  };
53
- if (conditions) {
66
+ if (isValidConditionList(conditions)) {
54
67
  propResult.conditions = conditions.map((condition, i) => {
55
68
  if (i === 0 && Object.keys(condition).length === 0) {
56
69
  return defaultClass;
@@ -75,4 +88,7 @@ function defineProperties({
75
88
  }
76
89
  return result;
77
90
  }
91
+ function isValidConditionList(condition) {
92
+ return Array.isArray(condition) && condition.length > 0;
93
+ }
78
94
  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 {};
@@ -1,4 +1,5 @@
1
1
  import { style } from "@vanilla-extract/css";
2
+ import { blocksLayer } from "../css/layers.css.js";
2
3
  function defineProperties({
3
4
  properties,
4
5
  conditions
@@ -12,21 +13,29 @@ function defineProperties({
12
13
  if (Array.isArray(values)) {
13
14
  for (const value of values) {
14
15
  const defaultClass = style({
15
- [property]: value
16
+ "@layer": {
17
+ [blocksLayer]: {
18
+ [property]: value
19
+ }
20
+ }
16
21
  });
17
22
  const propResult = {
18
23
  defaultClass
19
24
  };
20
- if (conditions) {
25
+ if (isValidConditionList(conditions)) {
21
26
  propResult.conditions = conditions.map((condition, i) => {
22
27
  if (i === 0 && Object.keys(condition).length === 0) {
23
28
  return defaultClass;
24
29
  }
25
30
  if (typeof condition === "object" && condition["@media"]) {
26
31
  return style({
27
- "@media": {
28
- [condition["@media"]]: {
29
- [property]: value
32
+ "@layer": {
33
+ [blocksLayer]: {
34
+ "@media": {
35
+ [condition["@media"]]: {
36
+ [property]: value
37
+ }
38
+ }
30
39
  }
31
40
  }
32
41
  });
@@ -43,12 +52,16 @@ function defineProperties({
43
52
  }
44
53
  for (const value in values) {
45
54
  const defaultClass = style({
46
- [property]: values[value]
55
+ "@layer": {
56
+ [blocksLayer]: {
57
+ [property]: values[value]
58
+ }
59
+ }
47
60
  });
48
61
  const propResult = {
49
62
  defaultClass
50
63
  };
51
- if (conditions) {
64
+ if (isValidConditionList(conditions)) {
52
65
  propResult.conditions = conditions.map((condition, i) => {
53
66
  if (i === 0 && Object.keys(condition).length === 0) {
54
67
  return defaultClass;
@@ -73,6 +86,9 @@ function defineProperties({
73
86
  }
74
87
  return result;
75
88
  }
89
+ function isValidConditionList(condition) {
90
+ return Array.isArray(condition) && condition.length > 0;
91
+ }
76
92
  export {
77
93
  defineProperties
78
94
  };
@@ -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.10",
4
4
  "description": "Core for Blocks",
5
5
  "type": "module",
6
6
  "sideEffects": false,