vunor 0.4.3 → 0.4.4
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/CHANGELOG.md +13 -1
- package/README.md +31 -5
- package/dist/theme.d.mts +15 -2
- package/dist/theme.mjs +29 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `replaceShortcut` from `vunor/theme`: replaces a built-in shortcut instead of merging into it. A shortcut of yours with the same name as a built-in one is merged with it (its classes are appended); mark your entry to drop vunor's definition and keep only your classes: `vunorShortcuts(defineShortcuts({ press: replaceShortcut({ 'active:': 'scale-95' }) }))`. It takes any form a normal entry takes (a string, an array or a shortcut object) and goes on the shortcut name, not on a variant key. In `mergeVunorShortcuts([a, b, c])` a marked entry drops the definitions of its name from the earlier lists, later lists merge on top of it as usual, and the mark survives the merge, so a map composed with `mergeVunorShortcuts` and passed to `vunorShortcuts()` still replaces the built-in shortcut.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- `vunorShortcuts()` no longer changes the exported `mergedVunorShortcuts` object (it turned its shortcut objects into strings in place), and an array entry (`'my-row': ['p-2', 'm-1']`) now becomes `p-2 m-1` (it became `0p-2 1m-1`).
|
|
12
|
+
- In a shortcut object, an array item holding several classes gets the variant prefix on each class: `{ 'hover:': ['p-2 m-1'] }` becomes `hover:p-2 hover:m-1` (it became `hover:p-2 m-1`).
|
|
13
|
+
- The `press` notes for 0.4.2 advised `transition-[scale]` to ease the press, but that class generates no CSS. Use `[transition-property:scale] duration-150`.
|
|
14
|
+
|
|
3
15
|
## 0.4.3
|
|
4
16
|
|
|
5
17
|
### Changed
|
|
@@ -10,7 +22,7 @@
|
|
|
10
22
|
|
|
11
23
|
### Added
|
|
12
24
|
|
|
13
|
-
- `press` shortcut: press feedback for any clickable. An enabled element shrinks to `scale: var(--press-scale, 0.97)` while it is `:active`, on touch and mouse. It ignores `data-active`, which Reka UI and vunor use for "current" (selected tab, pressed toggle, open popover trigger). It uses the `scale` property, so it stacks with translate/rotate utilities, sets no transition (add `transition-
|
|
25
|
+
- `press` shortcut: press feedback for any clickable. An enabled element shrinks to `scale: var(--press-scale, 0.97)` while it is `:active`, on touch and mouse. It ignores `data-active`, which Reka UI and vunor use for "current" (selected tab, pressed toggle, open popover trigger). It uses the `scale` property, so it stacks with translate/rotate utilities, sets no transition (add `[transition-property:scale] duration-150` to ease it) and clears the iOS tap highlight. An app that passes its own `press` shortcut to `vunorShortcuts()` gets vunor's rule merged into it; mark the app's one with `replaceShortcut` (0.4.4) or rename it.
|
|
14
26
|
- `whenHover`, `whenHoverIdle` and `whenCanHover` from `vunor/theme`: variant-prefix keys for your own shortcuts that apply hover only on devices whose primary input can hover. Use `whenHoverIdle` when the shortcut also paints `active:`.
|
|
15
27
|
- `whenEnabled` and `whenDisabled` from `vunor/theme`: the variant-prefix keys for vunor's shared disabled definition, needed to override c8 states (see below).
|
|
16
28
|
|
package/README.md
CHANGED
|
@@ -223,7 +223,7 @@ defineShortcuts({
|
|
|
223
223
|
|
|
224
224
|
### Why Objects Instead of Strings?
|
|
225
225
|
|
|
226
|
-
**Because they merge.** When two shortcut objects define the same key, `mergeVunorShortcuts()`
|
|
226
|
+
**Because they merge.** When two shortcut objects define the same key, `mergeVunorShortcuts()` merges them, appending the later entry's classes. This is the key to Vunor's customization model: you can surgically override a single variant of a built-in style without rewriting the whole shortcut.
|
|
227
227
|
|
|
228
228
|
For example, to make all filled buttons pill-shaped while keeping every other variant (hover, active, dark mode, disabled) intact:
|
|
229
229
|
|
|
@@ -232,10 +232,10 @@ import { vunorShortcuts, defineShortcuts } from 'vunor/theme'
|
|
|
232
232
|
|
|
233
233
|
const myOverrides = defineShortcuts({
|
|
234
234
|
'c8-filled': {
|
|
235
|
-
'': 'rounded-full', //
|
|
235
|
+
'': 'rounded-full', // added to the base classes
|
|
236
236
|
},
|
|
237
237
|
'i8-flat': {
|
|
238
|
-
'': 'border-b-2', //
|
|
238
|
+
'': 'border-b-2', // added to the base classes
|
|
239
239
|
},
|
|
240
240
|
})
|
|
241
241
|
|
|
@@ -245,10 +245,36 @@ export default defineConfig({
|
|
|
245
245
|
})
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
Your `'c8-filled'.'':`
|
|
248
|
+
Your `'c8-filled'.'':` classes are added to the base classes of `c8-filled`, while all its `hover:`, `dark:`, `active:` variants remain intact from the defaults. Everything flows through a single merge pipeline, producing consistent CSS passed to UnoCSS.
|
|
249
249
|
|
|
250
250
|
`vunorShortcuts()` returns the merged default shortcuts for all built-in styles (c8, i8, card, dialog, etc.). Pass your overrides as the first argument -- they take priority.
|
|
251
251
|
|
|
252
|
+
### Replacing a Built-in Shortcut
|
|
253
|
+
|
|
254
|
+
To drop a built-in shortcut and use only your own classes under its name, mark your entry with `replaceShortcut`:
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
import { defineShortcuts, replaceShortcut, vunorShortcuts } from 'vunor/theme'
|
|
258
|
+
|
|
259
|
+
const mine = defineShortcuts({
|
|
260
|
+
// vunor's own `press` is dropped; only these classes remain
|
|
261
|
+
'press': replaceShortcut({ 'active:': 'scale-95' }),
|
|
262
|
+
// a normal entry still merges into vunor's c8-filled
|
|
263
|
+
'c8-filled': { '': 'rounded-full' },
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
export default defineConfig({
|
|
267
|
+
presets: [presetVunor()],
|
|
268
|
+
shortcuts: [vunorShortcuts(mine)],
|
|
269
|
+
})
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`replaceShortcut` takes any form a normal entry takes (a string, an array or a shortcut object). Put it on the shortcut name, not on a variant key inside a shortcut (there it has no effect). In `mergeVunorShortcuts([a, b, c])` a marked entry drops the definitions of its name from the earlier lists, and entries in later lists merge on top of it as usual. The mark survives the merge, so `vunorShortcuts(mergeVunorShortcuts([x, y]))` still replaces the built-in shortcut when `y` marks it.
|
|
273
|
+
|
|
274
|
+
Without vunor's merge, plain UnoCSS does the same: a shortcut in a later map of the `shortcuts` array replaces an earlier one of the same name, so `shortcuts: [vunorShortcuts(), { press: 'active:scale-95' }]` also drops vunor's `press`.
|
|
275
|
+
|
|
276
|
+
An app shortcut with the same name as a built-in one is merged with it unless it is marked: when a vunor release adds a shortcut whose name your app already uses, mark your app's one with `replaceShortcut` (or rename it).
|
|
277
|
+
|
|
252
278
|
---
|
|
253
279
|
|
|
254
280
|
## Semantic CSS Classes
|
|
@@ -329,7 +355,7 @@ vunorShortcuts(
|
|
|
329
355
|
|
|
330
356
|
`whenEnabled` and `whenDisabled` are the variant-prefix keys for the shared disabled definition above. Use them in your own shortcuts so a state matches the same elements vunor treats as disabled: `{ [whenEnabled]: { 'active:': 'bg-current/20' }, [whenDisabled]: 'cursor-not-allowed' }`.
|
|
331
357
|
|
|
332
|
-
For press feedback on any clickable, add `press`: it shrinks an enabled element slightly while it is `:active` (`[--press-scale:0.9]` changes the amount; add `transition-
|
|
358
|
+
For press feedback on any clickable, add `press`: it shrinks an enabled element slightly while it is `:active` (`[--press-scale:0.9]` changes the amount; add `[transition-property:scale] duration-150` to ease it). It ignores `data-active`, which Reka UI and vunor use for "current" (selected tab, pressed toggle, open popover trigger).
|
|
333
359
|
|
|
334
360
|
The `btn` layout primitive fades a disabled element to opacity 0.8. That is a default: `disabled-soft` (0.4) or a `disabled:opacity-*` utility replaces it, whether written on the element or composed with `btn` in your own shortcut (`'my-btn': 'btn disabled-soft'`).
|
|
335
361
|
|
package/dist/theme.d.mts
CHANGED
|
@@ -370,9 +370,22 @@ declare const rawVunorShortcuts: TVunorShortcut[];
|
|
|
370
370
|
* @returns string
|
|
371
371
|
*/
|
|
372
372
|
declare function toUnoShortcut(obj: TVunorShortcut): string;
|
|
373
|
+
/**
|
|
374
|
+
* Marks a top-level shortcut entry as a replacement: when shortcuts are merged
|
|
375
|
+
* (`mergeVunorShortcuts`, `vunorShortcuts`), it drops every earlier definition of
|
|
376
|
+
* the same name instead of merging into it. Later entries still merge on top of it.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* vunorShortcuts(defineShortcuts({ press: replaceShortcut({ 'active:': 'scale-95' }) }))
|
|
380
|
+
*
|
|
381
|
+
* @param value the shortcut, in any form a normal entry accepts
|
|
382
|
+
* @returns the shortcut's class string in a marked array
|
|
383
|
+
*/
|
|
384
|
+
declare const replaceShortcut: (value: string | string[] | TVunorShortcut) => string[];
|
|
373
385
|
/**
|
|
374
386
|
* Merges an array of vunor shortcuts
|
|
375
|
-
* Items from the beginning have less priority
|
|
387
|
+
* Items from the beginning have less priority. An entry marked with
|
|
388
|
+
* `replaceShortcut` drops the earlier entries of its name.
|
|
376
389
|
*
|
|
377
390
|
* @param shortcuts TVunorShortcut[]
|
|
378
391
|
* @returns TVunorShortcut
|
|
@@ -397,4 +410,4 @@ declare const mergedVunorShortcuts: TVunorShortcut;
|
|
|
397
410
|
*/
|
|
398
411
|
declare function vunorShortcuts(customShortcuts?: TVunorShortcut, baseShortcuts?: TVunorShortcut): Record<string, string>;
|
|
399
412
|
//#endregion
|
|
400
|
-
export { type TVunorLayerPaletteAdvanced, type TVunorMainPaletteAdvanced, type TVunorPaletteColor, type TVunorPaletteOptions, type TVunorShortcut, type TVunorSurfaceConfig, type TVunorTheme, componentClasses, defineShortcuts, getComponentClasses, mergeVunorShortcuts, mergedVunorShortcuts, presetVunor, rawVunorShortcuts, toUnoShortcut, vunorShortcuts, whenCanHover, whenDisabled, whenEnabled, whenHover, whenHoverIdle };
|
|
413
|
+
export { type TVunorLayerPaletteAdvanced, type TVunorMainPaletteAdvanced, type TVunorPaletteColor, type TVunorPaletteOptions, type TVunorShortcut, type TVunorSurfaceConfig, type TVunorTheme, componentClasses, defineShortcuts, getComponentClasses, mergeVunorShortcuts, mergedVunorShortcuts, presetVunor, rawVunorShortcuts, replaceShortcut, toUnoShortcut, vunorShortcuts, whenCanHover, whenDisabled, whenEnabled, whenHover, whenHoverIdle };
|
package/dist/theme.mjs
CHANGED
|
@@ -527,11 +527,28 @@ function toUnoShortcut(obj) {
|
|
|
527
527
|
}
|
|
528
528
|
function prepareScArray(input) {
|
|
529
529
|
if (typeof input === "string") return input.split(" ");
|
|
530
|
-
if (Array.isArray(input)) return input;
|
|
530
|
+
if (Array.isArray(input)) return input.flatMap((item) => item.split(" "));
|
|
531
531
|
const a = [];
|
|
532
532
|
for (const [key, val] of Object.entries(input)) a.push(...prepareScArray(val).map((v) => `${key}${v}`));
|
|
533
533
|
return a;
|
|
534
534
|
}
|
|
535
|
+
const REPLACE = Symbol.for("vunor.replaceShortcut");
|
|
536
|
+
/** A shortcut value as one UnoCSS class string */
|
|
537
|
+
const toClassString = (value = "") => typeof value === "string" ? value : Array.isArray(value) ? value.join(" ") : toUnoShortcut(value);
|
|
538
|
+
const markReplacement = (classes) => Object.defineProperty(classes, REPLACE, { value: true });
|
|
539
|
+
const isReplacement = (value) => Array.isArray(value) && REPLACE in value;
|
|
540
|
+
/**
|
|
541
|
+
* Marks a top-level shortcut entry as a replacement: when shortcuts are merged
|
|
542
|
+
* (`mergeVunorShortcuts`, `vunorShortcuts`), it drops every earlier definition of
|
|
543
|
+
* the same name instead of merging into it. Later entries still merge on top of it.
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* vunorShortcuts(defineShortcuts({ press: replaceShortcut({ 'active:': 'scale-95' }) }))
|
|
547
|
+
*
|
|
548
|
+
* @param value the shortcut, in any form a normal entry accepts
|
|
549
|
+
* @returns the shortcut's class string in a marked array
|
|
550
|
+
*/
|
|
551
|
+
const replaceShortcut = (value) => markReplacement([toClassString(value)]);
|
|
535
552
|
/**
|
|
536
553
|
* Merges source vunor shortcut with target vunor shortcut
|
|
537
554
|
* The target vunor shortcut has more power
|
|
@@ -546,9 +563,12 @@ const mergeTwoVunorShortcuts = (target, source) => {
|
|
|
546
563
|
for (const key of Array.from(keys)) {
|
|
547
564
|
const inSource = Object.prototype.hasOwnProperty.call(source, key);
|
|
548
565
|
const inTarget = Object.prototype.hasOwnProperty.call(target, key);
|
|
549
|
-
|
|
566
|
+
const targetEntry = target[key];
|
|
567
|
+
if (inSource && isReplacement(source[key])) result[key] = source[key];
|
|
568
|
+
else if (inSource && inTarget && isReplacement(targetEntry)) result[key] = markReplacement([...targetEntry, toClassString(source[key])]);
|
|
569
|
+
else if (inSource && inTarget) {
|
|
550
570
|
let sourceValue = source[key];
|
|
551
|
-
let targetValue =
|
|
571
|
+
let targetValue = targetEntry;
|
|
552
572
|
if (Array.isArray(sourceValue)) sourceValue = sourceValue.join(" ");
|
|
553
573
|
if (Array.isArray(targetValue)) targetValue = targetValue.join(" ");
|
|
554
574
|
if (typeof sourceValue === "string" && typeof targetValue === "string") result[key] = `${targetValue} ${sourceValue}`;
|
|
@@ -562,7 +582,8 @@ const mergeTwoVunorShortcuts = (target, source) => {
|
|
|
562
582
|
};
|
|
563
583
|
/**
|
|
564
584
|
* Merges an array of vunor shortcuts
|
|
565
|
-
* Items from the beginning have less priority
|
|
585
|
+
* Items from the beginning have less priority. An entry marked with
|
|
586
|
+
* `replaceShortcut` drops the earlier entries of its name.
|
|
566
587
|
*
|
|
567
588
|
* @param shortcuts TVunorShortcut[]
|
|
568
589
|
* @returns TVunorShortcut
|
|
@@ -2569,8 +2590,9 @@ const mergedVunorShortcuts = mergeVunorShortcuts(rawVunorShortcuts);
|
|
|
2569
2590
|
*/
|
|
2570
2591
|
function vunorShortcuts(customShortcuts, baseShortcuts = mergedVunorShortcuts) {
|
|
2571
2592
|
const merged = customShortcuts ? mergeVunorShortcuts([baseShortcuts, customShortcuts]) : baseShortcuts;
|
|
2572
|
-
|
|
2573
|
-
|
|
2593
|
+
const result = {};
|
|
2594
|
+
for (const [key, val] of Object.entries(merged)) result[key] = toClassString(val);
|
|
2595
|
+
return result;
|
|
2574
2596
|
}
|
|
2575
2597
|
//#endregion
|
|
2576
|
-
export { componentClasses, defineShortcuts, getComponentClasses, mergeVunorShortcuts, mergedVunorShortcuts, presetVunor, rawVunorShortcuts, toUnoShortcut, vunorShortcuts, whenCanHover, whenDisabled, whenEnabled, whenHover, whenHoverIdle };
|
|
2598
|
+
export { componentClasses, defineShortcuts, getComponentClasses, mergeVunorShortcuts, mergedVunorShortcuts, presetVunor, rawVunorShortcuts, replaceShortcut, toUnoShortcut, vunorShortcuts, whenCanHover, whenDisabled, whenEnabled, whenHover, whenHoverIdle };
|