@ithinkdt/ui 4.0.0-100 → 4.0.0-101

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ithinkdt/ui",
3
- "version": "4.0.0-100",
3
+ "version": "4.0.0-101",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "iThinkDT UI",
@@ -14,7 +14,7 @@
14
14
  "esm",
15
15
  "auto-imports.*",
16
16
  "locale.*",
17
- "unocss.*"
17
+ "unocss*"
18
18
  ],
19
19
  "main": "./esm/index.js",
20
20
  "module": "./esm/index.js",
@@ -0,0 +1,5 @@
1
+ import { Preset, PresetWind4Theme } from 'unocss'
2
+
3
+ declare const ithinkdt: (options?: { namespace?: string | undefined }) => Preset<PresetWind4Theme>[]
4
+
5
+ export default ithinkdt
@@ -0,0 +1,163 @@
1
+ import { presetWind4, transformerDirectives, transformerVariantGroup } from 'unocss'
2
+
3
+ const ithinkdt = (options = {}) => {
4
+ const { namespace: ns } = options
5
+
6
+ let wind4, postprocess
7
+ if (ns) {
8
+ wind4 = () => {
9
+ const plugin = presetWind4({
10
+ variablePrefix: `${ns}-`,
11
+ preflights: {
12
+ reset: false,
13
+ property: {
14
+ selector: `.${ns} :where(*, ::before, ::after)`,
15
+ },
16
+ },
17
+ })
18
+
19
+ return {
20
+ ...plugin,
21
+ preflights: plugin.preflights?.map((preflight) => {
22
+ if (preflight.layer === 'theme') {
23
+ return {
24
+ ...preflight,
25
+ async getCSS(ctx) {
26
+ let result = await preflight.getCSS?.(ctx)
27
+ if (result) {
28
+ result = result.replace(':root, :host', `.${ns}`)
29
+ }
30
+ return result
31
+ },
32
+ }
33
+ } else if (preflight.layer === 'properties') {
34
+ return {
35
+ ...preflight,
36
+ async getCSS(ctx) {
37
+ let result = await preflight.getCSS?.(ctx)
38
+ if (result) {
39
+ result = result
40
+ .replaceAll('--un-', `--${ns}-`)
41
+ }
42
+ return result
43
+ },
44
+ }
45
+ }
46
+ return preflight
47
+ }),
48
+ }
49
+ }
50
+ postprocess = [
51
+ (p) => {
52
+ if (p.selector.includes('--un-')) {
53
+ p.selector = p.selector.replaceAll('--un-', `--${ns}-`)
54
+ } else if (p.selector.endsWith(String.raw`.\-`)) {
55
+ if (p.selector.startsWith('.dark ')) {
56
+ p.selector = `.dark & ${p.selector.slice(6)}`
57
+ }
58
+ } else {
59
+ p.selector = p.selector.startsWith('.dark ') ? `.dark .${ns} ${p.selector.slice(6)}` : `.${ns} ${p.selector}`
60
+ }
61
+ },
62
+ ]
63
+ } else { wind4 = presetWind4 }
64
+
65
+ const alphas = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
66
+ const ithinkdt = {
67
+ name: 'preset-ithinkdt',
68
+ options,
69
+ theme: {
70
+ colors: {
71
+ ...Object.fromEntries(
72
+ ['primary', 'success', 'warning', 'danger'].map(name => [
73
+ name,
74
+ {
75
+ DEFAULT: `var(--color-${name})`,
76
+ ...Object.fromEntries(alphas.map(alpha => [`${alpha}`, `color-mix(in oklab, var(--color-${name}) ${alpha / 10}%, #fff ${(1000 - alpha) / 10}%)`])),
77
+ ...Object.fromEntries(
78
+ ['hover', 'active'].flatMap(level => [
79
+ [level, `var(--color-${name}-${level})`],
80
+ ...alphas.map(alpha => [`${level}-${alpha}`, `color-mix(in oklab, var(--color-${name}-${level}) ${alpha / 10}%, #fff ${(1000 - alpha) / 10}%)`]),
81
+ ]),
82
+ ),
83
+ },
84
+ ]),
85
+ ),
86
+ text: {
87
+ DEFAULT: `var(--color-text)`,
88
+ ...Object.fromEntries(alphas.map(alpha => [`${alpha}`, `color-mix(in oklab, var(--color-text) ${alpha / 10}%, #fff ${(1000 - alpha) / 10}%)`])),
89
+ },
90
+ base: { DEFAULT: `var(--color-base)` },
91
+ },
92
+ radius: Object.fromEntries(
93
+ ['xs', 'sm', 'md', 'lg'].map(size => [size, `var(--rounded-${size})`]),
94
+ ),
95
+ },
96
+ variants: [
97
+ // stuck:
98
+ (matcher) => {
99
+ const array = ['top', 'right', 'bottom', 'left']
100
+ const index = array.findIndex(it => matcher.startsWith(`stuck-${it}:`))
101
+ if (index === -1)
102
+ return matcher
103
+ return {
104
+ matcher: matcher.slice(7 + array[index].length),
105
+ handle: (input, next) => next({
106
+ ...input,
107
+ parent: `${input.parent ? `${input.parent} $$ ` : ''} @container scroll-state(stuck: ${array[index]})`,
108
+ }),
109
+ }
110
+ },
111
+ ],
112
+ rules: [
113
+ ['scroll-state', { 'container-type': 'scroll-state' }],
114
+ [
115
+ /^bg-img-(.*)$/,
116
+ ([_, r]) => {
117
+ return {
118
+ 'background-image': r[0] === '[' && r.at(-1) === ']' ? r.slice(1, -1) : r,
119
+ }
120
+ },
121
+ ],
122
+ [
123
+ /^mask-(.*)$/,
124
+ ([_, r]) => {
125
+ const mask = `var(--un-icon) no-repeat`
126
+ return {
127
+ '--un-icon': r[0] === '[' && r.at(-1) === ']' ? r.slice(1, -1) : r,
128
+ mask,
129
+ 'mask-size': '100% 100%',
130
+ }
131
+ },
132
+ ],
133
+ ],
134
+ shortcuts: [
135
+ [
136
+ /^card-(.*)$/,
137
+ ([_, size]) => {
138
+ const i = ['none', 'sm', 'md', 'lg'].indexOf(size)
139
+ if (i === -1) return
140
+ const p = [0, 2, 4, 5][i]
141
+ return `rounded-${size} px-${p + 1} py-${p} bg-white dark:bg-dark ease-in-out transition-shadow
142
+ hover:shadow-[0_1px_2px_0_rgba(0_0_0_/_0.03),0_1px_6px_-1px_rgba(0_0_0_/_0.02),0_2px_4px_0_rgba(0_0_0_/_0.02)]`
143
+ },
144
+ { autocomplete: ['card-none', 'card-sm', 'card-md', 'card-lg'] },
145
+ ],
146
+ {
147
+ 'ell': 'truncate',
148
+ 'ell-2': 'line-clamp-2',
149
+ 'ell-3': 'line-clamp-3',
150
+ 'flex-center': 'flex justify-center items-center',
151
+ 'card': `card-md`,
152
+ },
153
+ ],
154
+ transformers: [transformerDirectives(), transformerVariantGroup()],
155
+ postprocess: postprocess,
156
+ }
157
+ return [
158
+ wind4(),
159
+ ithinkdt,
160
+ ]
161
+ }
162
+
163
+ export default ithinkdt