css-in-props 3.8.9 → 3.14.0

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.
Files changed (43) hide show
  1. package/README.md +6 -22
  2. package/dist/cjs/index.js +4 -4
  3. package/dist/cjs/props/animation.js +28 -23
  4. package/dist/cjs/props/block.js +46 -58
  5. package/dist/cjs/props/flex.js +4 -5
  6. package/dist/cjs/props/index.js +18 -19
  7. package/dist/cjs/props/misc.js +10 -3
  8. package/dist/cjs/props/theme.js +10 -7
  9. package/dist/cjs/set.js +13 -6
  10. package/dist/cjs/transform/executors.js +54 -47
  11. package/dist/cjs/transform/index.js +2 -2
  12. package/dist/cjs/transform/transformers.js +69 -20
  13. package/dist/esm/index.js +4 -4
  14. package/dist/esm/props/animation.js +28 -23
  15. package/dist/esm/props/block.js +46 -58
  16. package/dist/esm/props/flex.js +4 -5
  17. package/dist/esm/props/index.js +18 -19
  18. package/dist/esm/props/misc.js +10 -3
  19. package/dist/esm/props/theme.js +10 -7
  20. package/dist/esm/set.js +12 -5
  21. package/dist/esm/transform/executors.js +54 -47
  22. package/dist/esm/transform/index.js +2 -2
  23. package/dist/esm/transform/transformers.js +69 -20
  24. package/dist/iife/index.js +230 -167
  25. package/index.js +1 -0
  26. package/package.json +13 -15
  27. package/src/index.js +4 -4
  28. package/src/props/animation.js +28 -23
  29. package/src/props/block.js +49 -57
  30. package/src/props/flex.js +4 -5
  31. package/src/props/index.js +18 -19
  32. package/src/props/misc.js +10 -3
  33. package/src/props/theme.js +10 -7
  34. package/src/set.js +11 -4
  35. package/src/transform/executors.js +60 -52
  36. package/src/transform/index.js +2 -2
  37. package/src/transform/transformers.js +85 -23
  38. package/dist/cjs/_transform.js +0 -30
  39. package/dist/cjs/emotion.js +0 -29
  40. package/dist/esm/_transform.js +0 -10
  41. package/dist/esm/emotion.js +0 -9
  42. package/src/_transform.js +0 -10
  43. package/src/emotion.js +0 -9
@@ -1,4 +1,4 @@
1
1
  'use strict'
2
2
 
3
- export * from './executors'
4
- export * from './transformers'
3
+ export * from './executors.js'
4
+ export * from './transformers.js'
@@ -1,34 +1,58 @@
1
1
  'use strict'
2
2
 
3
- import { isFunction } from '@domql/utils'
4
- import { useCssInProps } from './executors'
3
+ import { isFunction } from '@symbo.ls/utils'
4
+ import { useCssInProps } from './executors.js'
5
5
 
6
6
  /**
7
7
  * PROP APPLICATORS
8
8
  * Functions that handle different types of property applications
9
9
  */
10
10
 
11
+ // Match `[data-theme="dark"]` / `[data-theme='light']` with either quote
12
+ // style, grabbing the scheme name (`dark` / `light` / custom) for pairing
13
+ // with `prefers-color-scheme`.
14
+ const DATA_THEME_RE = /^\[data-theme=(?:"([^"]+)"|'([^']+)')\]$/
15
+
11
16
  // Media query handler
12
17
  const applyMediaProps = (key, selectorProps, element) => {
13
18
  const { context } = element
14
19
  if (!context.designSystem?.media) return
15
20
 
16
- const mediaValue = context.designSystem.media[key.slice(1)]
21
+ const schemeKey = key.slice(1)
22
+ const mediaValue = context.designSystem.media[schemeKey]
17
23
  const generatedClass = useCssInProps(selectorProps, element)
18
24
 
19
- let mediaKey
20
25
  if (!mediaValue) {
21
- mediaKey = key
22
- } else if (mediaValue === 'print') {
23
- mediaKey = '@media print'
24
- } else if (mediaValue[0] === '(') {
25
- mediaKey = `@media screen and ${mediaValue}`
26
- } else {
27
- // CSS selector (e.g. [data-theme="dark"]) use as parent selector
28
- mediaKey = `${mediaValue} &`
26
+ return { [key]: generatedClass }
27
+ }
28
+ if (mediaValue === 'print') {
29
+ return { '@media print': generatedClass }
30
+ }
31
+ if (mediaValue[0] === '(') {
32
+ return { [`@media screen and ${mediaValue}`]: generatedClass }
29
33
  }
30
34
 
31
- return { [mediaKey]: generatedClass }
35
+ // CSS selector (e.g. `[data-theme="dark"]`). Always emit the selector
36
+ // rule so explicit `data-theme="dark"` wins. For the standard `dark` /
37
+ // `light` schemes, ALSO emit a `@media (prefers-color-scheme: X)`
38
+ // fallback so the component adopts the OS scheme when `data-theme` is
39
+ // absent (i.e. `globalTheme: 'auto'`). Guard the fallback with
40
+ // `:not([data-theme])` on the app scope root so an explicit
41
+ // `data-theme="light"` (stamped on the app root) forces light even when
42
+ // the OS prefers dark. Other schemes (`sepia`, custom) are opt-in only.
43
+ const match = mediaValue.match(DATA_THEME_RE)
44
+ const scheme = match ? (match[1] || match[2]) : schemeKey
45
+ const result = { [`${mediaValue} &`]: generatedClass }
46
+ if (scheme === 'dark' || scheme === 'light') {
47
+ const scopeSelector = context.designSystem?.scopeSelector || ':root'
48
+ const guard = scopeSelector === ':root'
49
+ ? ':root:not([data-theme])'
50
+ : `${scopeSelector}:not([data-theme])`
51
+ result[`@media (prefers-color-scheme: ${scheme})`] = {
52
+ [`${guard} &`]: generatedClass
53
+ }
54
+ }
55
+ return result
32
56
  }
33
57
 
34
58
  // Simple applicators
@@ -38,7 +62,37 @@ const applyAndProps = (key, selectorProps, element) => {
38
62
 
39
63
  const applySelectorProps = (key, selectorProps, element) => {
40
64
  const selectorKey = `&${key}`
41
- return { [selectorKey]: useCssInProps(selectorProps, element) }
65
+ const resolved = useCssInProps(selectorProps, element)
66
+
67
+ // When the selector has commas and the resolved value contains nested selectors
68
+ // (e.g. '> h1'), distribute each nested selector across all comma parts
69
+ if (key.includes(',') && resolved) {
70
+ const flat = {}
71
+ const nested = {}
72
+ for (const k in resolved) {
73
+ if (typeof resolved[k] === 'object' && resolved[k] !== null) {
74
+ nested[k] = resolved[k]
75
+ } else {
76
+ flat[k] = resolved[k]
77
+ }
78
+ }
79
+ if (Object.keys(nested).length) {
80
+ const parts = selectorKey.split(',').map(p => p.trim())
81
+ const result = {}
82
+ // Flat styles apply to the combined selector
83
+ if (Object.keys(flat).length) {
84
+ result[selectorKey] = flat
85
+ }
86
+ // Each nested selector is distributed across all comma parts
87
+ for (const nestedKey in nested) {
88
+ const distributed = parts.map(p => `${p} ${nestedKey}`).join(', ')
89
+ result[distributed] = nested[nestedKey]
90
+ }
91
+ return result
92
+ }
93
+ }
94
+
95
+ return { [selectorKey]: resolved }
42
96
  }
43
97
 
44
98
  // Resolve a case value from context.cases
@@ -54,7 +108,7 @@ const applyCaseProps = (key, selectorProps, element) => {
54
108
  const caseKey = key.slice(1)
55
109
  let isCaseTrue = resolveCase(caseKey, element)
56
110
  if (isCaseTrue === undefined) {
57
- isCaseTrue = !!element.props?.[caseKey]
111
+ isCaseTrue = !!element[caseKey]
58
112
  }
59
113
  if (!isCaseTrue) return
60
114
  return useCssInProps(selectorProps, element)
@@ -64,25 +118,33 @@ const applyVariableProps = (key, selectorVal, element) => {
64
118
  return { [key]: selectorVal }
65
119
  }
66
120
 
67
- // . prefix: Truthy conditional (props/state first, then context.cases)
121
+ // . prefix: Truthy conditional (element/state first, then context.cases)
68
122
  const applyConditionalCaseProps = (key, selectorProps, element) => {
69
123
  const caseKey = key.slice(1)
70
- let isCaseTrue = element.props[caseKey] === true || element.state[caseKey] || element[caseKey]
124
+ let isCaseTrue = element[caseKey] === true || element.state?.[caseKey]
71
125
  if (!isCaseTrue) {
72
- const caseResult = resolveCase(caseKey, element)
73
- if (caseResult !== undefined) isCaseTrue = caseResult
126
+ if (typeof element[caseKey] === 'function') {
127
+ try { isCaseTrue = element[caseKey](element, element.state, element.context) } catch (e) {}
128
+ } else {
129
+ const caseResult = resolveCase(caseKey, element)
130
+ if (caseResult !== undefined) isCaseTrue = caseResult
131
+ }
74
132
  }
75
133
  if (!isCaseTrue) return
76
134
  return useCssInProps(selectorProps, element)
77
135
  }
78
136
 
79
- // ! prefix: Falsy conditional (props/state first, then context.cases)
137
+ // ! prefix: Falsy conditional (element/state first, then context.cases)
80
138
  const applyConditionalFalsyProps = (key, selectorProps, element) => {
81
139
  const caseKey = key.slice(1)
82
- let isCaseTrue = element.props[caseKey] === true || element.state[caseKey] || element[caseKey]
140
+ let isCaseTrue = element[caseKey] === true || element.state?.[caseKey]
83
141
  if (!isCaseTrue) {
84
- const caseResult = resolveCase(caseKey, element)
85
- if (caseResult !== undefined) isCaseTrue = caseResult
142
+ if (typeof element[caseKey] === 'function') {
143
+ try { isCaseTrue = element[caseKey](element, element.state, element.context) } catch (e) {}
144
+ } else {
145
+ const caseResult = resolveCase(caseKey, element)
146
+ if (caseResult !== undefined) isCaseTrue = caseResult
147
+ }
86
148
  }
87
149
  if (isCaseTrue) return
88
150
  return useCssInProps(selectorProps, element)
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var transform_exports = {};
20
- __export(transform_exports, {
21
- transformClassname: () => transformClassname
22
- });
23
- module.exports = __toCommonJS(transform_exports);
24
- var import_utils = require("@domql/utils");
25
- var import_transform = require("./transform");
26
- const transformClassname = (element) => {
27
- const { props } = element;
28
- if (!(0, import_utils.isObject)(props)) return;
29
- return (0, import_transform.useCssInProps)(props, element);
30
- };
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var emotion_exports = {};
20
- __export(emotion_exports, {
21
- transformEmotion: () => transformEmotion
22
- });
23
- module.exports = __toCommonJS(emotion_exports);
24
- var import_utils = require("@domql/utils");
25
- var import_emotion = require("@symbo.ls/emotion");
26
- const { css } = import_emotion.emotion;
27
- const transformEmotion = (props, callback) => {
28
- return (0, import_utils.isFunction)(callback) ? callback(props) : css(props);
29
- };
@@ -1,10 +0,0 @@
1
- import { isObject } from "@domql/utils";
2
- import { useCssInProps } from "./transform";
3
- const transformClassname = (element) => {
4
- const { props } = element;
5
- if (!isObject(props)) return;
6
- return useCssInProps(props, element);
7
- };
8
- export {
9
- transformClassname
10
- };
@@ -1,9 +0,0 @@
1
- import { isFunction } from "@domql/utils";
2
- import { emotion } from "@symbo.ls/emotion";
3
- const { css } = emotion;
4
- const transformEmotion = (props, callback) => {
5
- return isFunction(callback) ? callback(props) : css(props);
6
- };
7
- export {
8
- transformEmotion
9
- };
package/src/_transform.js DELETED
@@ -1,10 +0,0 @@
1
- 'use strict'
2
-
3
- import { isObject } from '@domql/utils'
4
- import { useCssInProps } from './transform'
5
-
6
- export const transformClassname = (element) => {
7
- const { props } = element
8
- if (!isObject(props)) return
9
- return useCssInProps(props, element)
10
- }
package/src/emotion.js DELETED
@@ -1,9 +0,0 @@
1
- 'use strict'
2
-
3
- import { isFunction } from '@domql/utils'
4
- import { emotion } from '@symbo.ls/emotion'
5
- const { css } = emotion
6
-
7
- export const transformEmotion = (props, callback) => {
8
- return isFunction(callback) ? callback(props) : css(props)
9
- }