@lovrozagar/flare 0.8.0 → 0.9.1
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.
- package/README.md +23 -0
- package/package.json +1 -1
- package/src/plugins/cn-theme.ts +36 -0
- package/src/plugins/sx-ast/index.ts +157 -14
- package/src/plugins/sx-ast/rewrite.ts +11 -2
- package/src/plugins/tw-compile.ts +152 -38
- package/src/styles/cn-vendor/NOTICE.md +9 -5
- package/src/styles/cn-vendor/compiler.ts +1160 -0
- package/src/styles/cn-vendor/config.ts +136 -0
- package/src/styles/cn-vendor/default-config.generated.ts +26 -0
- package/src/styles/cn-vendor/theme-css.ts +180 -0
- package/src/styles/cn-vendor/validators.ts +122 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026 shadcn
|
|
5
|
+
*
|
|
6
|
+
* Vendored from https://github.com/shadcn-ui/cn
|
|
7
|
+
* tag cn@0.4.0
|
|
8
|
+
* commit 84db83298f69a229d6f1ffc5d8c8d99ef451fb49
|
|
9
|
+
* Source: packages/cn/src/validators.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Validator predicates with semantics identical to tailwind-merge 3.7.0's
|
|
13
|
+
// src/lib/validators.ts (MIT, Dany Castillo — see README.md). The runtime
|
|
14
|
+
// engine compiles these to span opcodes; these plain-string implementations
|
|
15
|
+
// are used by the compiler's classifier and by custom configs.
|
|
16
|
+
|
|
17
|
+
const arbitraryValueRegex = /^\[(?:(\w[\w-]*):)?(.+)\]$/i
|
|
18
|
+
const arbitraryVariableRegex = /^\((?:(\w[\w-]*):)?(.+)\)$/i
|
|
19
|
+
const fractionRegex = /^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/
|
|
20
|
+
const tshirtUnitRegex = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
|
|
21
|
+
const lengthUnitRegex =
|
|
22
|
+
/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/
|
|
23
|
+
const colorFunctionRegex = /^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/
|
|
24
|
+
const shadowRegex =
|
|
25
|
+
/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
|
|
26
|
+
const imageRegex =
|
|
27
|
+
/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/
|
|
28
|
+
|
|
29
|
+
export const isFraction = (v: string) => fractionRegex.test(v)
|
|
30
|
+
export const isNumber = (v: string) => !!v && !Number.isNaN(Number(v))
|
|
31
|
+
export const isInteger = (v: string) => !!v && Number.isInteger(Number(v))
|
|
32
|
+
export const isPercent = (v: string) =>
|
|
33
|
+
v.endsWith("%") && isNumber(v.slice(0, -1))
|
|
34
|
+
export const isTshirtSize = (v: string) => tshirtUnitRegex.test(v)
|
|
35
|
+
export const isAny = () => true
|
|
36
|
+
|
|
37
|
+
const isLengthOnly = (v: string) =>
|
|
38
|
+
lengthUnitRegex.test(v) && !colorFunctionRegex.test(v)
|
|
39
|
+
const isNever = () => false
|
|
40
|
+
const isShadow = (v: string) => shadowRegex.test(v)
|
|
41
|
+
const isImage = (v: string) => imageRegex.test(v)
|
|
42
|
+
|
|
43
|
+
export const isAnyNonArbitrary = (v: string) =>
|
|
44
|
+
!isArbitraryValue(v) && !isArbitraryVariable(v)
|
|
45
|
+
|
|
46
|
+
export const isNamedContainerQuery = (v: string) =>
|
|
47
|
+
v.startsWith("@container") &&
|
|
48
|
+
((v[10] === "/" && v[11] !== undefined) ||
|
|
49
|
+
(v[11] === "s" && v[16] !== undefined && v.startsWith("-size/", 10)) ||
|
|
50
|
+
(v[11] === "n" && v[18] !== undefined && v.startsWith("-normal/", 10)))
|
|
51
|
+
|
|
52
|
+
type LabelTest = (label: string) => boolean
|
|
53
|
+
type ValueTest = (value: string) => boolean
|
|
54
|
+
|
|
55
|
+
const getIsArbitraryValue = (
|
|
56
|
+
value: string,
|
|
57
|
+
testLabel: LabelTest,
|
|
58
|
+
testValue: ValueTest
|
|
59
|
+
) => {
|
|
60
|
+
const result = arbitraryValueRegex.exec(value)
|
|
61
|
+
if (result) {
|
|
62
|
+
if (result[1]) return testLabel(result[1])
|
|
63
|
+
return testValue(result[2]!)
|
|
64
|
+
}
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const getIsArbitraryVariable = (
|
|
69
|
+
value: string,
|
|
70
|
+
testLabel: LabelTest,
|
|
71
|
+
shouldMatchNoLabel = false
|
|
72
|
+
) => {
|
|
73
|
+
const result = arbitraryVariableRegex.exec(value)
|
|
74
|
+
if (result) {
|
|
75
|
+
if (result[1]) return testLabel(result[1])
|
|
76
|
+
return shouldMatchNoLabel
|
|
77
|
+
}
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const isLabelPosition = (l: string) => l === "position" || l === "percentage"
|
|
82
|
+
const isLabelImage = (l: string) => l === "image" || l === "url"
|
|
83
|
+
const isLabelSize = (l: string) =>
|
|
84
|
+
l === "length" || l === "size" || l === "bg-size"
|
|
85
|
+
const isLabelLength = (l: string) => l === "length"
|
|
86
|
+
const isLabelNumber = (l: string) => l === "number"
|
|
87
|
+
const isLabelFamilyName = (l: string) => l === "family-name"
|
|
88
|
+
const isLabelWeight = (l: string) => l === "number" || l === "weight"
|
|
89
|
+
const isLabelShadow = (l: string) => l === "shadow"
|
|
90
|
+
|
|
91
|
+
export const isArbitrarySize = (v: string) =>
|
|
92
|
+
getIsArbitraryValue(v, isLabelSize, isNever)
|
|
93
|
+
export const isArbitraryValue = (v: string) => arbitraryValueRegex.test(v)
|
|
94
|
+
export const isArbitraryLength = (v: string) =>
|
|
95
|
+
getIsArbitraryValue(v, isLabelLength, isLengthOnly)
|
|
96
|
+
export const isArbitraryNumber = (v: string) =>
|
|
97
|
+
getIsArbitraryValue(v, isLabelNumber, isNumber)
|
|
98
|
+
export const isArbitraryWeight = (v: string) =>
|
|
99
|
+
getIsArbitraryValue(v, isLabelWeight, isAny)
|
|
100
|
+
export const isArbitraryFamilyName = (v: string) =>
|
|
101
|
+
getIsArbitraryValue(v, isLabelFamilyName, isNever)
|
|
102
|
+
export const isArbitraryPosition = (v: string) =>
|
|
103
|
+
getIsArbitraryValue(v, isLabelPosition, isNever)
|
|
104
|
+
export const isArbitraryImage = (v: string) =>
|
|
105
|
+
getIsArbitraryValue(v, isLabelImage, isImage)
|
|
106
|
+
export const isArbitraryShadow = (v: string) =>
|
|
107
|
+
getIsArbitraryValue(v, isLabelShadow, isShadow)
|
|
108
|
+
export const isArbitraryVariable = (v: string) => arbitraryVariableRegex.test(v)
|
|
109
|
+
export const isArbitraryVariableLength = (v: string) =>
|
|
110
|
+
getIsArbitraryVariable(v, isLabelLength)
|
|
111
|
+
export const isArbitraryVariableFamilyName = (v: string) =>
|
|
112
|
+
getIsArbitraryVariable(v, isLabelFamilyName)
|
|
113
|
+
export const isArbitraryVariablePosition = (v: string) =>
|
|
114
|
+
getIsArbitraryVariable(v, isLabelPosition)
|
|
115
|
+
export const isArbitraryVariableSize = (v: string) =>
|
|
116
|
+
getIsArbitraryVariable(v, isLabelSize)
|
|
117
|
+
export const isArbitraryVariableImage = (v: string) =>
|
|
118
|
+
getIsArbitraryVariable(v, isLabelImage)
|
|
119
|
+
export const isArbitraryVariableShadow = (v: string) =>
|
|
120
|
+
getIsArbitraryVariable(v, isLabelShadow, true)
|
|
121
|
+
export const isArbitraryVariableWeight = (v: string) =>
|
|
122
|
+
getIsArbitraryVariable(v, isLabelWeight, true)
|