@symbo.ls/scratch 3.14.1 → 3.14.3

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 (186) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/index.cjs +1 -0
  3. package/dist/cjs/src/defaultConfig/animation.cjs +1 -0
  4. package/dist/cjs/src/defaultConfig/cases.cjs +1 -0
  5. package/dist/cjs/src/defaultConfig/class.cjs +1 -0
  6. package/dist/cjs/src/defaultConfig/color.cjs +1 -0
  7. package/dist/cjs/src/defaultConfig/document.cjs +1 -0
  8. package/dist/cjs/src/defaultConfig/font-family.cjs +1 -0
  9. package/dist/cjs/src/defaultConfig/font.cjs +1 -0
  10. package/dist/cjs/src/defaultConfig/grid.cjs +1 -0
  11. package/dist/cjs/src/defaultConfig/icons.cjs +1 -0
  12. package/dist/cjs/src/defaultConfig/index.cjs +1 -0
  13. package/dist/cjs/src/defaultConfig/media.cjs +1 -0
  14. package/dist/cjs/src/defaultConfig/responsive.cjs +1 -0
  15. package/dist/cjs/src/defaultConfig/sequence.cjs +1 -0
  16. package/dist/cjs/src/defaultConfig/shadow.cjs +1 -0
  17. package/dist/cjs/src/defaultConfig/spacing.cjs +1 -0
  18. package/dist/cjs/src/defaultConfig/svg.cjs +1 -0
  19. package/dist/cjs/src/defaultConfig/templates.cjs +1 -0
  20. package/dist/cjs/src/defaultConfig/theme.cjs +1 -0
  21. package/dist/cjs/src/defaultConfig/timing.cjs +1 -0
  22. package/dist/cjs/src/defaultConfig/typography.cjs +1 -0
  23. package/dist/cjs/src/defaultConfig/unit.cjs +1 -0
  24. package/dist/cjs/src/factory.cjs +1 -0
  25. package/dist/cjs/src/index.cjs +1 -0
  26. package/dist/cjs/src/set.cjs +1 -0
  27. package/dist/cjs/src/system/color.cjs +1 -0
  28. package/dist/cjs/src/system/document.cjs +1 -0
  29. package/dist/cjs/src/system/font.cjs +1 -0
  30. package/dist/cjs/src/system/index.cjs +1 -0
  31. package/dist/cjs/src/system/reset.cjs +1 -0
  32. package/dist/cjs/src/system/shadow.cjs +1 -0
  33. package/dist/cjs/src/system/spacing.cjs +1 -0
  34. package/dist/cjs/src/system/svg.cjs +1 -0
  35. package/dist/cjs/src/system/theme.cjs +1 -0
  36. package/dist/cjs/src/system/timing.cjs +1 -0
  37. package/dist/cjs/src/system/typography.cjs +1 -0
  38. package/dist/cjs/src/tests/index.cjs +1 -0
  39. package/dist/cjs/src/transforms/index.cjs +1 -0
  40. package/dist/cjs/src/utils/color.cjs +1 -0
  41. package/dist/cjs/src/utils/font.cjs +9 -0
  42. package/dist/cjs/src/utils/index.cjs +1 -0
  43. package/dist/cjs/src/utils/sequence.cjs +1 -0
  44. package/dist/cjs/src/utils/sprite.cjs +1 -0
  45. package/dist/cjs/src/utils/theme.cjs +1 -0
  46. package/dist/cjs/src/utils/unit.cjs +1 -0
  47. package/dist/cjs/src/utils/var.cjs +1 -0
  48. package/dist/esm/index.js +1 -0
  49. package/dist/esm/src/defaultConfig/animation.js +1 -0
  50. package/dist/esm/src/defaultConfig/cases.js +1 -0
  51. package/dist/esm/src/defaultConfig/class.js +1 -0
  52. package/dist/esm/src/defaultConfig/color.js +1 -0
  53. package/dist/esm/src/defaultConfig/document.js +1 -0
  54. package/dist/esm/src/defaultConfig/font-family.js +1 -0
  55. package/dist/esm/src/defaultConfig/font.js +1 -0
  56. package/dist/esm/src/defaultConfig/grid.js +1 -0
  57. package/dist/esm/src/defaultConfig/icons.js +1 -0
  58. package/dist/esm/src/defaultConfig/index.js +1 -0
  59. package/dist/esm/src/defaultConfig/media.js +1 -0
  60. package/dist/esm/src/defaultConfig/responsive.js +1 -0
  61. package/dist/esm/src/defaultConfig/sequence.js +1 -0
  62. package/dist/esm/src/defaultConfig/shadow.js +1 -0
  63. package/dist/esm/src/defaultConfig/spacing.js +1 -0
  64. package/dist/esm/src/defaultConfig/svg.js +1 -0
  65. package/dist/esm/src/defaultConfig/templates.js +1 -0
  66. package/dist/esm/src/defaultConfig/theme.js +1 -0
  67. package/dist/esm/src/defaultConfig/timing.js +1 -0
  68. package/dist/esm/src/defaultConfig/typography.js +1 -0
  69. package/dist/esm/src/defaultConfig/unit.js +1 -0
  70. package/dist/esm/src/factory.js +1 -0
  71. package/dist/esm/src/index.js +1 -0
  72. package/dist/esm/src/set.js +1 -0
  73. package/dist/esm/src/system/color.js +1 -0
  74. package/dist/esm/src/system/document.js +1 -0
  75. package/dist/esm/src/system/font.js +1 -0
  76. package/dist/esm/src/system/index.js +1 -0
  77. package/dist/esm/src/system/reset.js +1 -0
  78. package/dist/esm/src/system/shadow.js +1 -0
  79. package/dist/esm/src/system/spacing.js +1 -0
  80. package/dist/esm/src/system/svg.js +1 -0
  81. package/dist/esm/src/system/theme.js +1 -0
  82. package/dist/esm/src/system/timing.js +1 -0
  83. package/dist/esm/src/system/typography.js +1 -0
  84. package/dist/esm/src/tests/index.js +1 -0
  85. package/dist/esm/src/transforms/index.js +1 -0
  86. package/dist/esm/src/utils/color.js +1 -0
  87. package/dist/esm/src/utils/font.js +9 -0
  88. package/dist/esm/src/utils/index.js +1 -0
  89. package/dist/esm/src/utils/sequence.js +1 -0
  90. package/dist/esm/src/utils/sprite.js +1 -0
  91. package/dist/esm/src/utils/theme.js +1 -0
  92. package/dist/esm/src/utils/unit.js +1 -0
  93. package/dist/esm/src/utils/var.js +1 -0
  94. package/package.json +17 -16
  95. package/dist/cjs/defaultConfig/animation.js +0 -26
  96. package/dist/cjs/defaultConfig/cases.js +0 -26
  97. package/dist/cjs/defaultConfig/class.js +0 -27
  98. package/dist/cjs/defaultConfig/color.js +0 -28
  99. package/dist/cjs/defaultConfig/document.js +0 -26
  100. package/dist/cjs/defaultConfig/font-family.js +0 -34
  101. package/dist/cjs/defaultConfig/font.js +0 -26
  102. package/dist/cjs/defaultConfig/grid.js +0 -27
  103. package/dist/cjs/defaultConfig/icons.js +0 -28
  104. package/dist/cjs/defaultConfig/index.js +0 -222
  105. package/dist/cjs/defaultConfig/media.js +0 -31
  106. package/dist/cjs/defaultConfig/responsive.js +0 -52
  107. package/dist/cjs/defaultConfig/sequence.js +0 -51
  108. package/dist/cjs/defaultConfig/shadow.js +0 -26
  109. package/dist/cjs/defaultConfig/spacing.js +0 -87
  110. package/dist/cjs/defaultConfig/svg.js +0 -28
  111. package/dist/cjs/defaultConfig/templates.js +0 -26
  112. package/dist/cjs/defaultConfig/theme.js +0 -26
  113. package/dist/cjs/defaultConfig/timing.js +0 -68
  114. package/dist/cjs/defaultConfig/typography.js +0 -72
  115. package/dist/cjs/defaultConfig/unit.js +0 -28
  116. package/dist/cjs/factory.js +0 -386
  117. package/dist/cjs/index.js +0 -6365
  118. package/dist/cjs/package.json +0 -4
  119. package/dist/cjs/set.js +0 -5681
  120. package/dist/cjs/system/color.js +0 -4585
  121. package/dist/cjs/system/document.js +0 -4396
  122. package/dist/cjs/system/font.js +0 -4444
  123. package/dist/cjs/system/index.js +0 -5764
  124. package/dist/cjs/system/reset.js +0 -4511
  125. package/dist/cjs/system/shadow.js +0 -4898
  126. package/dist/cjs/system/spacing.js +0 -4847
  127. package/dist/cjs/system/svg.js +0 -4496
  128. package/dist/cjs/system/theme.js +0 -4686
  129. package/dist/cjs/system/timing.js +0 -4724
  130. package/dist/cjs/system/typography.js +0 -4821
  131. package/dist/cjs/tests/index.js +0 -30
  132. package/dist/cjs/transforms/index.js +0 -5104
  133. package/dist/cjs/utils/color.js +0 -187
  134. package/dist/cjs/utils/font.js +0 -91
  135. package/dist/cjs/utils/index.js +0 -5084
  136. package/dist/cjs/utils/sequence.js +0 -4711
  137. package/dist/cjs/utils/sprite.js +0 -426
  138. package/dist/cjs/utils/theme.js +0 -31
  139. package/dist/cjs/utils/unit.js +0 -81
  140. package/dist/cjs/utils/var.js +0 -4450
  141. package/index.js +0 -1
  142. package/src/defaultConfig/animation.js +0 -3
  143. package/src/defaultConfig/cases.js +0 -3
  144. package/src/defaultConfig/class.js +0 -6
  145. package/src/defaultConfig/color.js +0 -9
  146. package/src/defaultConfig/document.js +0 -3
  147. package/src/defaultConfig/font-family.js +0 -15
  148. package/src/defaultConfig/font.js +0 -12
  149. package/src/defaultConfig/grid.js +0 -5
  150. package/src/defaultConfig/icons.js +0 -4
  151. package/src/defaultConfig/index.js +0 -24
  152. package/src/defaultConfig/media.js +0 -10
  153. package/src/defaultConfig/responsive.js +0 -29
  154. package/src/defaultConfig/sequence.js +0 -24
  155. package/src/defaultConfig/shadow.js +0 -3
  156. package/src/defaultConfig/spacing.js +0 -19
  157. package/src/defaultConfig/svg.js +0 -4
  158. package/src/defaultConfig/templates.js +0 -3
  159. package/src/defaultConfig/theme.js +0 -13
  160. package/src/defaultConfig/timing.js +0 -18
  161. package/src/defaultConfig/typography.js +0 -22
  162. package/src/defaultConfig/unit.js +0 -5
  163. package/src/factory.js +0 -135
  164. package/src/index.js +0 -24
  165. package/src/set.js +0 -353
  166. package/src/system/color.js +0 -327
  167. package/src/system/document.js +0 -16
  168. package/src/system/font.js +0 -66
  169. package/src/system/index.js +0 -12
  170. package/src/system/reset.js +0 -119
  171. package/src/system/shadow.js +0 -107
  172. package/src/system/spacing.js +0 -152
  173. package/src/system/svg.js +0 -132
  174. package/src/system/theme.js +0 -454
  175. package/src/system/timing.js +0 -32
  176. package/src/system/typography.js +0 -110
  177. package/src/tests/index.js +0 -4
  178. package/src/transforms/index.js +0 -270
  179. package/src/utils/color.js +0 -269
  180. package/src/utils/font.js +0 -116
  181. package/src/utils/index.js +0 -9
  182. package/src/utils/sequence.js +0 -386
  183. package/src/utils/sprite.js +0 -107
  184. package/src/utils/theme.js +0 -8
  185. package/src/utils/unit.js +0 -72
  186. package/src/utils/var.js +0 -129
@@ -1,454 +0,0 @@
1
- 'use strict'
2
-
3
- import { getColor } from './color.js'
4
- import { getActiveConfig } from '../factory.js'
5
- import { isCSSVar } from '../utils/color.js'
6
-
7
- import {
8
- isObject,
9
- isString,
10
- isObjectLike,
11
- isArray
12
- } from '@symbo.ls/utils'
13
-
14
- // Common CSS named colors — used to distinguish valid CSS color names
15
- // from unresolved design-system tokens (e.g. 'blackRussian', 'grayMid')
16
- const CSS_NAMED_COLORS = new Set([
17
- 'black', 'white', 'red', 'green', 'blue', 'yellow', 'orange', 'purple',
18
- 'pink', 'brown', 'gray', 'grey', 'cyan', 'magenta', 'lime', 'olive',
19
- 'navy', 'teal', 'aqua', 'maroon', 'silver', 'fuchsia', 'transparent',
20
- 'currentColor', 'currentcolor', 'inherit', 'initial', 'unset', 'none',
21
- 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque',
22
- 'blanchedalmond', 'blueviolet', 'burlywood', 'cadetblue', 'chartreuse',
23
- 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'darkblue',
24
- 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki',
25
- 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred',
26
- 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey',
27
- 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey',
28
- 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite',
29
- 'gold', 'goldenrod', 'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo',
30
- 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon',
31
- 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray',
32
- 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen',
33
- 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow',
34
- 'limegreen', 'linen', 'mediumaquamarine', 'mediumblue', 'mediumorchid',
35
- 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen',
36
- 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose',
37
- 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid',
38
- 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip',
39
- 'peachpuff', 'peru', 'plum', 'powderblue', 'rosybrown', 'royalblue',
40
- 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna',
41
- 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen',
42
- 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat',
43
- 'whitesmoke', 'yellowgreen', 'rebeccapurple'
44
- ])
45
-
46
- // A theme param is treated as a color-producing property when its name
47
- // contains one of these substrings. Mirrors the check in `setThemeValue`
48
- // so the broken-scheme pre-scan skips non-color props like `borderStyle`,
49
- // `boxShadow`, `backdropFilter`, `cursor`, etc. that would otherwise trip
50
- // the `/^[a-z][a-zA-Z]+$/` heuristic with values like 'solid' or 'pointer'.
51
- const COLOR_PARAM_TOKENS = ['color', 'Color', 'background', 'Background', 'fill', 'Fill', 'stroke', 'Stroke']
52
-
53
- const isColorParam = (param) => {
54
- for (let i = 0; i < COLOR_PARAM_TOKENS.length; i++) {
55
- if (param.includes(COLOR_PARAM_TOKENS[i])) return true
56
- }
57
- return false
58
- }
59
-
60
- const setThemeValue = theme => {
61
- const value = {}
62
- const { state, media, helpers, ...rest } = theme
63
- const keys = Object.keys(rest)
64
- keys.map(key => {
65
- const conditions = ['color', 'Color', 'background', 'border']
66
- const isColor = conditions.some(k => key.includes(k))
67
- return (value[key] = isColor ? getColor(theme[key]) : theme[key])
68
- })
69
- return value
70
- }
71
-
72
- const getThemeValue = theme => {
73
- if (theme.value) return theme.value
74
- theme.value = setThemeValue(theme)
75
- return theme.value
76
- }
77
-
78
- export const getTheme = (value, modifier) => {
79
- const CONFIG = getActiveConfig()
80
- if (CONFIG.useVariable) return getMediaTheme(value, modifier)
81
- const THEME = CONFIG.theme
82
-
83
- if (isString(value)) {
84
- const [theme, subtheme] = value.split(' ')
85
- const isOurTheme = THEME[theme]
86
- if (isOurTheme) {
87
- if (!subtheme && !modifier) return getThemeValue(isOurTheme)
88
- value = [theme, subtheme || modifier]
89
- }
90
- }
91
-
92
- if (isObjectLike(value) && value[1]) {
93
- const themeName = value[0]
94
- const subThemeName = value[1]
95
- const { helpers, media, state } = THEME[themeName]
96
-
97
- if (media && media[subThemeName]) return getThemeValue(media[subThemeName])
98
- if (helpers && helpers[subThemeName]) return getThemeValue(helpers[subThemeName])
99
- if (state && state[subThemeName]) return getThemeValue(state[subThemeName])
100
- } else if (isObject(value)) return setThemeValue(value)
101
- }
102
-
103
- const setInverseTheme = (theme, variant, value) => {
104
- if (isObject(variant)) {
105
- theme.variants.inverse.value = setThemeValue(variant)
106
- } else if (variant === true) {
107
- const { color, background } = value
108
- theme.variants.inverse = {
109
- value: {
110
- color: background,
111
- background: color
112
- }
113
- }
114
- }
115
- }
116
-
117
- const setPseudo = (theme, key, variant, themeValue) => {
118
- const result = getTheme(variant)
119
- themeValue[`&:${key}`] = result
120
- if (isObject(variant) && !variant.value) variant.value = result
121
- }
122
-
123
- const setSelectors = (theme, value) => {
124
- const { state } = theme
125
- if (!state) return
126
- const keys = Object.keys(state)
127
- keys.map(key => {
128
- const variant = state[key]
129
- setPseudo(theme, key, variant, value)
130
- return theme
131
- })
132
- return theme
133
- }
134
-
135
- const setPrefersScheme = (theme, key, variant, themeValue) => {
136
- const result = getTheme(variant)
137
- themeValue[`@media (prefers-color-scheme: ${key})`] = result
138
- if (isObject(variant) && !variant.value) variant.value = result
139
- }
140
-
141
- const setMedia = (theme, value) => {
142
- const { media } = theme
143
- if (!media) return
144
- const keys = Object.keys(media)
145
- keys.map(key => {
146
- const variant = media[key]
147
- if (key === 'dark' || key === 'light') setPrefersScheme(theme, key, variant, value)
148
- if (key === 'inverse') setInverseTheme(theme, variant, value)
149
- return theme
150
- })
151
- return theme
152
- }
153
-
154
- const setHelpers = (theme, value) => {
155
- const CONFIG = getActiveConfig()
156
- const { helpers } = theme
157
- if (!helpers) return
158
- const keys = Object.keys(helpers)
159
- keys.map(key => {
160
- const helper = helpers[key]
161
- if (isString(helper)) helpers[key] = CONFIG.theme[helper]
162
- else getThemeValue(helpers[key])
163
- return theme
164
- })
165
- return theme
166
- }
167
-
168
-
169
-
170
- export const setTheme = (val, key) => {
171
- const CONFIG = getActiveConfig()
172
- if (CONFIG.useVariable) return setMediaTheme(val, key)
173
-
174
- const { state, media, helpers } = val
175
- const value = setThemeValue(val, key)
176
- const vp = CONFIG.varPrefix ? CONFIG.varPrefix + '-' : ''
177
- const CSSvar = `--${vp}theme-${key}`
178
-
179
- setSelectors(val, value)
180
- setMedia(val, value)
181
- setHelpers(val, value)
182
-
183
- return { var: CSSvar, value, state, media, helpers }
184
- }
185
-
186
- const keySetters = { // eslint-disable-line
187
- '@': (theme, value) => setMedia(theme, value),
188
- ':': (theme, value) => setSelectors(theme, value),
189
- '.': (theme, value) => setHelpers(theme, value)
190
- }
191
-
192
- /**
193
- * Recursively generates auto-switching CSS vars from all @-scheme content.
194
- * - @dark/@light: uses prefers-color-scheme media queries + [data-theme] selectors
195
- * - Custom @schemes (@ocean, @sunset, etc.): uses [data-theme] selectors only
196
- * - globalTheme forced: sets non-suffixed vars directly in CSS_VARS
197
- *
198
- * @param {Object} schemes - { dark: {...}, light: {...}, ocean: {...} }
199
- * @param {string} varPrefix - var name prefix (e.g. 'document', 'primary-child')
200
- * @param {Object} CONFIG - active config
201
- */
202
- const generateAutoVars = (schemes, varPrefix, CONFIG) => {
203
- const { cssVars: CSS_VARS } = CONFIG
204
- if (!CONFIG.cssMediaVars) CONFIG.cssMediaVars = {}
205
- const MEDIA_VARS = CONFIG.cssMediaVars
206
- const globalTheme = CONFIG.globalTheme !== undefined ? CONFIG.globalTheme : 'auto'
207
-
208
- const result = {}
209
-
210
- // Collect union of all keys across all schemes
211
- const allKeys = new Set()
212
- for (const scheme in schemes) {
213
- if (schemes[scheme]) for (const k of Object.keys(schemes[scheme])) allKeys.add(k)
214
- }
215
-
216
- // Pre-scan: detect schemes with unresolvable color values. If any color in
217
- // a scheme fails to resolve, skip the ENTIRE scheme to avoid partial theme
218
- // application (e.g. white text without a dark background). Runs regardless
219
- // of `globalTheme` because every scheme is always emitted now.
220
- //
221
- // Only check params whose names indicate colors — otherwise legitimate
222
- // non-color values like `borderStyle: 'solid'` or `cursor: 'pointer'`
223
- // match the `/^[a-z][a-zA-Z]+$/` heuristic and falsely break the scheme,
224
- // which would silently drop the entire theme's CSS vars.
225
- const brokenSchemes = new Set()
226
- for (const param of allKeys) {
227
- const symb = param.slice(0, 1)
228
- if (symb === '@' || symb === '.' || symb === ':') continue
229
- if (!isColorParam(param)) continue
230
- for (const scheme in schemes) {
231
- if (brokenSchemes.has(scheme)) continue
232
- const val = schemes[scheme]?.[param]
233
- if (val === undefined) continue
234
- const color = getColor(val, `@${scheme}`)
235
- if (color === undefined) continue
236
- if (isString(color) && /^[a-z][a-zA-Z]+$/.test(color) && !CSS_NAMED_COLORS.has(color)) {
237
- brokenSchemes.add(scheme)
238
- }
239
- }
240
- }
241
-
242
- for (const param of allKeys) {
243
- const symb = param.slice(0, 1)
244
-
245
- // Check if any scheme has an object value for this param
246
- const hasObject = Object.values(schemes).some(s => isObjectLike(s?.[param]))
247
-
248
- if (symb === '.' && hasObject) {
249
- // Dot helper (.color-only, .child, etc.) — recurse
250
- const helperName = param.slice(1)
251
- const subSchemes = {}
252
- for (const scheme in schemes) {
253
- if (isObjectLike(schemes[scheme]?.[param])) subSchemes[scheme] = schemes[scheme][param]
254
- }
255
- result[param] = generateAutoVars(subSchemes, `${varPrefix}-${helperName}`, CONFIG)
256
- } else if (symb === ':' && hasObject) {
257
- // Pseudo selector (:hover, ::placeholder) — recurse
258
- const pseudoName = param.replace(/^:+/, '')
259
- const subSchemes = {}
260
- for (const scheme in schemes) {
261
- if (isObjectLike(schemes[scheme]?.[param])) subSchemes[scheme] = schemes[scheme][param]
262
- }
263
- result[param] = generateAutoVars(subSchemes, `${varPrefix}-${pseudoName}`, CONFIG)
264
- } else if (symb !== '@' && symb !== '.' && symb !== ':') {
265
- // Regular CSS param — generate auto-switching var.
266
- //
267
- // We always emit the FULL switch table — `:root` fallback + one
268
- // rule per scheme on `[data-theme="X"]` + `@media
269
- // (prefers-color-scheme: dark|light)` — regardless of whether the
270
- // user provided an initial `globalTheme`. A forced initial theme
271
- // only decides which value lands in the `:root` fallback; runtime
272
- // switching (via `changeGlobalTheme` → `data-theme` attribute)
273
- // must always work, and OS preference must still drive auto mode.
274
- const vp = CONFIG.varPrefix ? CONFIG.varPrefix + '-' : ''
275
- const autoVar = `--${vp}theme-${varPrefix}-${param}`
276
- const forced = globalTheme && globalTheme !== 'auto'
277
- ? String(globalTheme).replace(/^'|'$/g, '')
278
- : null
279
-
280
- let fallbackColor
281
- for (const scheme in schemes) {
282
- if (brokenSchemes.has(scheme)) continue
283
- const val = schemes[scheme]?.[param]
284
- if (val === undefined) continue
285
- const color = getColor(val, `@${scheme}`)
286
- if (color === undefined) continue
287
-
288
- // Pick the `:root` fallback: prefer the user's forced scheme if
289
- // any, else `light`, else the first resolved scheme.
290
- if ((forced && scheme === forced) ||
291
- (!forced && (scheme === 'light' || fallbackColor === undefined))) {
292
- fallbackColor = color
293
- }
294
-
295
- // `[data-theme="X"]` selector — works for any scheme incl. custom.
296
- const selector = `[data-theme="${scheme}"]`
297
- if (!MEDIA_VARS[selector]) MEDIA_VARS[selector] = {}
298
- MEDIA_VARS[selector][autoVar] = color
299
-
300
- // `prefers-color-scheme` media query only for standard light/dark.
301
- if (scheme === 'dark' || scheme === 'light') {
302
- const mq = `@media (prefers-color-scheme: ${scheme})`
303
- if (!MEDIA_VARS[mq]) MEDIA_VARS[mq] = {}
304
- MEDIA_VARS[mq][autoVar] = color
305
- }
306
- }
307
-
308
- if (fallbackColor !== undefined) {
309
- CSS_VARS[autoVar] = fallbackColor
310
- }
311
-
312
- result[param] = `var(${autoVar})`
313
- result[`.${param}`] = { [param]: result[param] }
314
- }
315
- }
316
-
317
- if (result.background || result.color || result.backgroundColor) {
318
- result['.inversed'] = {
319
- color: result.background || result.backgroundColor,
320
- background: result.color
321
- }
322
- }
323
-
324
- return result
325
- }
326
-
327
- export const setMediaTheme = (val, key, suffix, prefers) => {
328
- const CONFIG = getActiveConfig()
329
- const { cssVars: CSS_VARS } = CONFIG
330
- const theme = { value: val }
331
- const isTopLevel = !suffix && !prefers
332
-
333
- if (isObjectLike(val)) {
334
- // At top level: collect all @-schemes and generate auto-switching vars
335
- if (isTopLevel && CONFIG.useVariable) {
336
- const schemes = {}
337
- for (const param in val) {
338
- if (param.startsWith('@') && isObjectLike(val[param])) {
339
- schemes[param.slice(1)] = val[param]
340
- }
341
- }
342
-
343
- if (Object.keys(schemes).length) {
344
- const autoResult = generateAutoVars(schemes, key, CONFIG)
345
- Object.assign(theme, autoResult)
346
- }
347
- }
348
-
349
- for (const param in val) {
350
- const symb = param.slice(0, 1)
351
- const value = val[param]
352
- if (symb === '@' || symb === ':' || symb === '.') {
353
- const hasPrefers = symb === '@' && param
354
- theme[param] = setMediaTheme(value, key, param, prefers || hasPrefers)
355
- } else if (!isTopLevel) {
356
- const color = getColor(value, prefers)
357
- const metaSuffixes = [...new Set([prefers, suffix].filter(v => v).map(v => v.slice(1)))]
358
- const varmetaSuffixName = metaSuffixes.length ? '-' + metaSuffixes.join('-') : ''
359
- const vp = CONFIG.varPrefix ? CONFIG.varPrefix + '-' : ''
360
- const CSSVar = `--${vp}theme-${key}${varmetaSuffixName}-${param}`
361
- if (CONFIG.useVariable) {
362
- // Suffixed vars (--theme-key-dark-param) only when opted in
363
- if (CONFIG.useThemeSuffixedVars) CSS_VARS[CSSVar] = color
364
- theme[param] = `var(${CSSVar})`
365
- } else {
366
- theme[param] = color
367
- }
368
- theme[`.${param}`] = { [param]: theme[param] }
369
- }
370
- }
371
-
372
- // Only add .inversed if not already set by generateAutoVars
373
- if (!theme['.inversed'] && (theme.background || theme.color || theme.backgroundColor)) {
374
- theme['.inversed'] = {
375
- color: theme.background || theme.backgroundColor,
376
- background: theme.color
377
- }
378
- }
379
- }
380
-
381
- if (isString(val) && isCSSVar(val)) {
382
- const THEME = CONFIG.theme
383
- const value = THEME[val.slice(2)]
384
- const getReferenced = getMediaTheme(value, prefers)
385
- return getReferenced
386
- }
387
-
388
- return theme
389
- }
390
-
391
- const recursiveTheme = val => {
392
- const CONFIG = getActiveConfig()
393
- const obj = {}
394
- for (const param in val) {
395
- const symb = param.slice(0, 1)
396
- if (isObjectLike(val[param])) {
397
- if (symb === '@') {
398
- // Skip all @-schemes — CSS vars + data-theme handle switching
399
- continue
400
- } else if (symb === ':') {
401
- obj[`&${param}`] = recursiveTheme(val[param])
402
- } else if (symb === '.') {
403
- obj[`&${param}`] = recursiveTheme(val[param])
404
- }
405
- } else obj[param] = val[param]
406
- }
407
- return obj
408
- }
409
-
410
- const findModifierFromArray = (val, modifierArray) => {
411
- const currentMod = modifierArray.shift()
412
- if (val[currentMod]) return findModifierFromArray(val[currentMod], modifierArray)
413
- return val
414
- }
415
-
416
- const findModifier = (val, modifier) => {
417
- if (isArray(modifier)) return findModifierFromArray(val, modifier)
418
- else if (isString(modifier) && val[modifier]) return val[modifier]
419
- else return val
420
- }
421
-
422
- const checkForReference = (val, callback) => {
423
- if (isString(val) && isCSSVar(val)) return getMediaTheme(val.slice(2))
424
- return val
425
- }
426
-
427
- const checkThemeReference = (val) => checkForReference(val, checkThemeReference) // eslint-disable-line
428
-
429
- export const getMediaTheme = (value, modifier) => {
430
- const activeConfig = getActiveConfig()
431
-
432
- if (isString(value) && isCSSVar(value)) {
433
- value = getMediaTheme(value.slice(2))
434
- }
435
-
436
- if (!value || !isString(value)) {
437
- if (activeConfig.verbose) {
438
- console.warn(`${value} - Theme is not a string`)
439
- }
440
- return
441
- }
442
-
443
- const [themeName, ...themeModifiers] = isArray(value) ? value : value.split(' ')
444
- let themeValue = activeConfig.theme[themeName]
445
-
446
- if (themeValue && themeModifiers.length) {
447
- themeValue = findModifier(themeValue, themeModifiers)
448
- } else if (themeValue && modifier) {
449
- themeValue = findModifier(themeValue, modifier)
450
- }
451
-
452
- const resolvedTheme = recursiveTheme(themeValue)
453
- return resolvedTheme
454
- }
@@ -1,32 +0,0 @@
1
- 'use strict'
2
-
3
- import { toCamelCase } from '@symbo.ls/utils'
4
- import { getActiveConfig } from '../factory.js'
5
- import {
6
- applySequenceVars,
7
- generateSequence,
8
- getSequenceValuePropertyPair
9
- } from '../utils/index.js'
10
-
11
- export const applyTimingSequence = () => {
12
- const CONFIG = getActiveConfig()
13
- const { timing: TIMING } = CONFIG
14
- generateSequence(TIMING)
15
- applySequenceVars(TIMING)
16
- }
17
-
18
- export const getTimingFunction = value => {
19
- const CONFIG = getActiveConfig()
20
- const { timing: TIMING } = CONFIG
21
- return TIMING[value] || TIMING[toCamelCase(value)] || value
22
- }
23
-
24
- export const getTimingByKey = (value, property = 'timing') => {
25
- const CONFIG = getActiveConfig()
26
- const { timing: TIMING } = CONFIG
27
- return getSequenceValuePropertyPair(
28
- value,
29
- property,
30
- TIMING
31
- )
32
- }
@@ -1,110 +0,0 @@
1
- 'use strict'
2
-
3
- import { merge } from '@symbo.ls/utils'
4
- import { getActiveConfig } from '../factory.js'
5
-
6
- import {
7
- applyMediaSequenceVars,
8
- applySequenceVars,
9
- findHeadings,
10
- generateSequence,
11
- getSequenceValuePropertyPair
12
- } from '../utils/index.js'
13
-
14
- export const runThroughMedia = FACTORY => {
15
- const CONFIG = getActiveConfig()
16
- const { typography: TYPOGRAPHY, media: MEDIA } = CONFIG
17
-
18
- for (const prop in FACTORY) {
19
- const isPropMedia = prop.slice(0, 1) === '@'
20
- const mediaValue = FACTORY[prop]
21
- if (!isPropMedia) continue
22
-
23
- const { mediaRegenerate } = FACTORY
24
- const mediaName = prop.slice(1)
25
-
26
- const { type, base, ratio, range, subSequence, h1Matches, unit } = FACTORY
27
-
28
- merge(mediaValue, {
29
- type,
30
- base,
31
- ratio,
32
- range,
33
- subSequence,
34
- h1Matches,
35
- unit
36
- })
37
-
38
- const VIEWPORT_UNITS = new Set(['vw', 'vh', 'vmin', 'vmax', 'svw', 'svh', 'lvw', 'lvh', 'dvw', 'dvh'])
39
- const inheritedUnit = mediaValue.unit || unit
40
- const mediaUnit = (!mediaValue.unit && VIEWPORT_UNITS.has(unit)) ? 'rem' : inheritedUnit
41
- const query = MEDIA[mediaName]
42
- const media =
43
- '@media ' + (query === 'print' ? `${query}` : `screen and ${query}`)
44
- TYPOGRAPHY.templates[media] = {
45
- fontSize: mediaValue.base / TYPOGRAPHY.browserDefault + mediaUnit
46
- }
47
-
48
- if (!mediaRegenerate) {
49
- merge(mediaValue, {
50
- sequence: {},
51
- scales: {},
52
- vars: {}
53
- })
54
- generateSequence(mediaValue)
55
- applyMediaSequenceVars(FACTORY, prop)
56
- continue
57
- }
58
-
59
- merge(mediaValue, {
60
- sequence: {},
61
- scales: {},
62
- templates: {},
63
- vars: {}
64
- })
65
-
66
- generateSequence(mediaValue)
67
-
68
- applyMediaSequenceVars(FACTORY, prop)
69
- }
70
- }
71
-
72
- export const applyHeadings = props => {
73
- const CONFIG = getActiveConfig()
74
- if (props.h1Matches) {
75
- const unit = props.unit
76
- const HEADINGS = findHeadings(props)
77
- const { templates } = props
78
- for (const k in HEADINGS) {
79
- const headerName = `h${parseInt(k) + 1}`
80
- const headerStyle = templates[headerName]
81
- templates[headerName] = {
82
- fontSize: CONFIG.useVariable
83
- ? `var(${HEADINGS[k]?.variable})`
84
- : `${HEADINGS[k]?.scaling}${unit}`,
85
- margin: headerStyle ? headerStyle.margin : 0,
86
- lineHeight: headerStyle ? headerStyle.lineHeight : props.lineHeight,
87
- letterSpacing: headerStyle
88
- ? headerStyle.letterSpacing
89
- : props.letterSpacing,
90
- fontWeight: headerStyle ? headerStyle.fontWeight : 900 - k * 100
91
- }
92
- }
93
- }
94
- }
95
-
96
- export const applyTypographySequence = () => {
97
- const CONFIG = getActiveConfig()
98
- const { typography: TYPOGRAPHY } = CONFIG
99
-
100
- generateSequence(TYPOGRAPHY)
101
- applyHeadings(TYPOGRAPHY)
102
- applySequenceVars(TYPOGRAPHY)
103
- runThroughMedia(TYPOGRAPHY)
104
- }
105
-
106
- export const getFontSizeByKey = value => {
107
- const CONFIG = getActiveConfig()
108
- const { typography: TYPOGRAPHY } = CONFIG
109
- return getSequenceValuePropertyPair(value, 'fontSize', TYPOGRAPHY)
110
- }
@@ -1,4 +0,0 @@
1
- 'use strict'
2
-
3
- export const testWCAGAA = (colorA, colorB) => {}
4
- export const testWCAGAAA = (colorA, colorB) => {}