@shival99/z-ui-svelte 0.1.9 → 0.1.11
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/dist/components/z-shimmer-text/ZShimmerText.svelte +17 -8
- package/dist/components/z-shimmer-text/ZShimmerText.svelte.d.ts +4 -0
- package/dist/components/z-toast/ZToastPillText.svelte +77 -77
- package/dist/components/z-tooltip/ZTooltipPanel.svelte +3 -2
- package/dist/components/z-tooltip/z-tooltip.define.d.ts +7 -0
- package/dist/components/z-tooltip/z-tooltip.define.js +5 -0
- package/dist/components/z-tooltip/z-tooltip.svelte.js +23 -3
- package/package.json +10 -9
|
@@ -12,29 +12,38 @@
|
|
|
12
12
|
zDuration?: number;
|
|
13
13
|
/** Hold the sweep: the text stays in its resting colour. */
|
|
14
14
|
zPaused?: boolean;
|
|
15
|
+
/** Resting colour of the text (any CSS colour; default the muted foreground). */
|
|
16
|
+
zBase?: string;
|
|
17
|
+
/** Colour of the sweeping highlight (default the foreground). */
|
|
18
|
+
zPeak?: string;
|
|
15
19
|
children?: Snippet;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
let { class: className, zText = '', zDuration = 2, zPaused = false, children }: Props = $props();
|
|
22
|
+
let { class: className, zText = '', zDuration = 2, zPaused = false, zBase, zPeak, children }: Props = $props();
|
|
19
23
|
</script>
|
|
20
24
|
|
|
21
25
|
<!-- A highlight sweeps across the text — "thinking…", "loading…" — without moving any layout. -->
|
|
22
26
|
<span
|
|
23
27
|
class={zMergeClasses('z-shimmer-text inline-block', zPaused && 'z-shimmer-text-paused', className)}
|
|
24
28
|
style:--z-shimmer-duration={`${zDuration}s`}
|
|
29
|
+
style:--z-shimmer-base={zBase}
|
|
30
|
+
style:--z-shimmer-peak={zPeak}
|
|
25
31
|
>
|
|
26
32
|
{#if children}{@render children()}{:else}{zTranslate(zText)}{/if}
|
|
27
33
|
</span>
|
|
28
34
|
|
|
29
35
|
<style>
|
|
30
36
|
.z-shimmer-text {
|
|
37
|
+
/* The gradient is 3x the text and never repeats: the highlight enters and leaves in the resting colour, so the
|
|
38
|
+
loop has no jump (a repeating gradient showed the previous tile's highlight when the sweep restarted). */
|
|
31
39
|
background-image: linear-gradient(
|
|
32
|
-
|
|
33
|
-
var(--muted-foreground)
|
|
34
|
-
var(--foreground) 50%,
|
|
35
|
-
var(--muted-foreground)
|
|
40
|
+
105deg,
|
|
41
|
+
var(--z-shimmer-base, var(--muted-foreground)) 40%,
|
|
42
|
+
var(--z-shimmer-peak, var(--foreground)) 50%,
|
|
43
|
+
var(--z-shimmer-base, var(--muted-foreground)) 60%
|
|
36
44
|
);
|
|
37
|
-
background-size:
|
|
45
|
+
background-size: 300% 100%;
|
|
46
|
+
background-repeat: no-repeat;
|
|
38
47
|
background-clip: text;
|
|
39
48
|
-webkit-background-clip: text;
|
|
40
49
|
color: transparent;
|
|
@@ -48,14 +57,14 @@
|
|
|
48
57
|
background-position: 100% 0;
|
|
49
58
|
}
|
|
50
59
|
to {
|
|
51
|
-
background-position:
|
|
60
|
+
background-position: 0% 0;
|
|
52
61
|
}
|
|
53
62
|
}
|
|
54
63
|
@media (prefers-reduced-motion: reduce) {
|
|
55
64
|
.z-shimmer-text {
|
|
56
65
|
animation: none;
|
|
57
66
|
background-image: none;
|
|
58
|
-
color: var(--muted-foreground);
|
|
67
|
+
color: var(--z-shimmer-base, var(--muted-foreground));
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
</style>
|
|
@@ -8,6 +8,10 @@ interface Props {
|
|
|
8
8
|
zDuration?: number;
|
|
9
9
|
/** Hold the sweep: the text stays in its resting colour. */
|
|
10
10
|
zPaused?: boolean;
|
|
11
|
+
/** Resting colour of the text (any CSS colour; default the muted foreground). */
|
|
12
|
+
zBase?: string;
|
|
13
|
+
/** Colour of the sweeping highlight (default the foreground). */
|
|
14
|
+
zPeak?: string;
|
|
11
15
|
children?: Snippet;
|
|
12
16
|
}
|
|
13
17
|
declare const ZShimmerText: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { Z_TOAST_PILL_EASE, Z_TOAST_PILL_MORPH_MS, zPillFadeBlur } from './z-toast.pill.motion';
|
|
3
|
-
import ZToastPillReveal from './ZToastPillReveal.svelte';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
text: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
let { text }: Props = $props();
|
|
10
|
-
|
|
11
|
-
let box = $state<HTMLElement | null>(null);
|
|
12
|
-
let measure = $state<HTMLElement | null>(null);
|
|
13
|
-
// Pinned (px) only while the line glides from the old text's width to the new one's.
|
|
14
|
-
let width = $state<number | null>(null);
|
|
15
|
-
let mounted = false;
|
|
16
|
-
// The first text is shown as is; every later one is revealed letter by letter. Read when a text block
|
|
17
|
-
// is created (never re-rendered from), so it is a plain object rather than state.
|
|
18
|
-
const shown = { value: false };
|
|
19
|
-
|
|
20
|
-
$effect(() => {
|
|
21
|
-
shown.value = true;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Before the text swaps, pin the width the line has now...
|
|
25
|
-
$effect.pre(() => {
|
|
26
|
-
void text;
|
|
27
|
-
if (mounted && box) {
|
|
28
|
-
width = box.offsetWidth;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// ...then let it glide to the new text's natural width.
|
|
33
|
-
$effect(() => {
|
|
34
|
-
void text;
|
|
35
|
-
if (!measure) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (!mounted) {
|
|
39
|
-
mounted = true;
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const next = measure.offsetWidth;
|
|
44
|
-
const frame = requestAnimationFrame(() => {
|
|
45
|
-
width = width === next ? null : next;
|
|
46
|
-
});
|
|
47
|
-
return () => cancelAnimationFrame(frame);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
function release(event: TransitionEvent): void {
|
|
51
|
-
if (event.propertyName === 'width') {
|
|
52
|
-
width = null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
</script>
|
|
56
|
-
|
|
57
|
-
<!-- The invisible copy sizes the line; the old text fades out over the new one in the same cell. -->
|
|
58
|
-
<span
|
|
59
|
-
bind:this={box}
|
|
60
|
-
class="relative inline-grid max-w-96 grid-cols-[minmax(0,1fr)] items-center overflow-hidden whitespace-nowrap motion-reduce:transition-none"
|
|
61
|
-
style:width={width === null ? undefined : `${width}px`}
|
|
62
|
-
style:transition="width {Z_TOAST_PILL_MORPH_MS}ms {Z_TOAST_PILL_EASE}"
|
|
63
|
-
ontransitionend={release}
|
|
64
|
-
>
|
|
65
|
-
<span bind:this={measure} class="invisible col-start-1 row-start-1 w-max whitespace-pre" aria-hidden="true">
|
|
66
|
-
{text}
|
|
67
|
-
</span>
|
|
68
|
-
{#key text}
|
|
69
|
-
<span class="col-start-1 row-start-1 min-w-0 truncate" out:zPillFadeBlur>
|
|
70
|
-
{#if shown.value}
|
|
71
|
-
<ZToastPillReveal {text} />
|
|
72
|
-
{:else}
|
|
73
|
-
{text}
|
|
74
|
-
{/if}
|
|
75
|
-
</span>
|
|
76
|
-
{/key}
|
|
77
|
-
</span>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Z_TOAST_PILL_EASE, Z_TOAST_PILL_MORPH_MS, zPillFadeBlur } from './z-toast.pill.motion';
|
|
3
|
+
import ZToastPillReveal from './ZToastPillReveal.svelte';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let { text }: Props = $props();
|
|
10
|
+
|
|
11
|
+
let box = $state<HTMLElement | null>(null);
|
|
12
|
+
let measure = $state<HTMLElement | null>(null);
|
|
13
|
+
// Pinned (px) only while the line glides from the old text's width to the new one's.
|
|
14
|
+
let width = $state<number | null>(null);
|
|
15
|
+
let mounted = false;
|
|
16
|
+
// The first text is shown as is; every later one is revealed letter by letter. Read when a text block
|
|
17
|
+
// is created (never re-rendered from), so it is a plain object rather than state.
|
|
18
|
+
const shown = { value: false };
|
|
19
|
+
|
|
20
|
+
$effect(() => {
|
|
21
|
+
shown.value = true;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Before the text swaps, pin the width the line has now...
|
|
25
|
+
$effect.pre(() => {
|
|
26
|
+
void text;
|
|
27
|
+
if (mounted && box) {
|
|
28
|
+
width = box.offsetWidth;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// ...then let it glide to the new text's natural width.
|
|
33
|
+
$effect(() => {
|
|
34
|
+
void text;
|
|
35
|
+
if (!measure) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!mounted) {
|
|
39
|
+
mounted = true;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const next = measure.offsetWidth;
|
|
44
|
+
const frame = requestAnimationFrame(() => {
|
|
45
|
+
width = width === next ? null : next;
|
|
46
|
+
});
|
|
47
|
+
return () => cancelAnimationFrame(frame);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function release(event: TransitionEvent): void {
|
|
51
|
+
if (event.propertyName === 'width') {
|
|
52
|
+
width = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<!-- The invisible copy sizes the line; the old text fades out over the new one in the same cell. -->
|
|
58
|
+
<span
|
|
59
|
+
bind:this={box}
|
|
60
|
+
class="relative inline-grid max-w-96 grid-cols-[minmax(0,1fr)] items-center overflow-hidden whitespace-nowrap motion-reduce:transition-none"
|
|
61
|
+
style:width={width === null ? undefined : `${width}px`}
|
|
62
|
+
style:transition="width {Z_TOAST_PILL_MORPH_MS}ms {Z_TOAST_PILL_EASE}"
|
|
63
|
+
ontransitionend={release}
|
|
64
|
+
>
|
|
65
|
+
<span bind:this={measure} class="invisible col-start-1 row-start-1 w-max whitespace-pre" aria-hidden="true">
|
|
66
|
+
{text}
|
|
67
|
+
</span>
|
|
68
|
+
{#key text}
|
|
69
|
+
<span class="col-start-1 row-start-1 min-w-0 truncate" out:zPillFadeBlur>
|
|
70
|
+
{#if shown.value}
|
|
71
|
+
<ZToastPillReveal {text} />
|
|
72
|
+
{:else}
|
|
73
|
+
{text}
|
|
74
|
+
{/if}
|
|
75
|
+
</span>
|
|
76
|
+
{/key}
|
|
77
|
+
</span>
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import { zTranslate } from '../../i18n/translate.svelte';
|
|
26
26
|
import { zOverlayContainer } from '../../overlay/container';
|
|
27
27
|
import { zSideOffset } from '../../overlay/side';
|
|
28
|
-
import { Z_TOOLTIP_SLIDE_DISTANCE } from './z-tooltip.define';
|
|
28
|
+
import { Z_TOOLTIP_SLIDE_DISTANCE, zTooltipTakeover } from './z-tooltip.define';
|
|
29
29
|
import { Z_EASE_DRAWER } from '../../motion/easing';
|
|
30
30
|
import { zPrefersReducedMotion } from '../../utils/browser';
|
|
31
31
|
import { zMergeClasses } from '../../utils/merge-classes';
|
|
@@ -114,7 +114,8 @@
|
|
|
114
114
|
const [dx, dy] = zSideOffset(side, Z_TOOLTIP_SLIDE_DISTANCE);
|
|
115
115
|
return {
|
|
116
116
|
// core-ui timing: 150ms both ways (z-duration-150 in, z-animate-out's 150ms out).
|
|
117
|
-
|
|
117
|
+
// An early dismiss (another tooltip taking over, or a press on the trigger) has no outro.
|
|
118
|
+
duration: zPrefersReducedMotion() || zTooltipTakeover.active ? 0 : 150,
|
|
118
119
|
// core-ui's z-animate-in/out curve: most of the change lands in the first frames, then it settles.
|
|
119
120
|
easing: Z_EASE_DRAWER,
|
|
120
121
|
css: (t: number) => `opacity:${t};transform:translate(${dx * (1 - t)}px, ${dy * (1 - t)}px)`,
|
|
@@ -10,3 +10,10 @@ export declare const Z_TOOLTIP_HOVER_GRACE_MS = 100;
|
|
|
10
10
|
export declare const Z_TOOLTIP_SKIP_DELAY_MS = 300;
|
|
11
11
|
/** Distance (px) of the core-ui tooltip slide (`z-slide-*-2`). */
|
|
12
12
|
export declare const Z_TOOLTIP_SLIDE_DISTANCE = 4;
|
|
13
|
+
/**
|
|
14
|
+
* Set while a tooltip is removed for another one, or by a press on its trigger: its outro is instant, so the
|
|
15
|
+
* tooltip is gone at once instead of fading out under the next one.
|
|
16
|
+
*/
|
|
17
|
+
export declare const zTooltipTakeover: {
|
|
18
|
+
active: boolean;
|
|
19
|
+
};
|
|
@@ -22,3 +22,8 @@ export const Z_TOOLTIP_HOVER_GRACE_MS = 100;
|
|
|
22
22
|
export const Z_TOOLTIP_SKIP_DELAY_MS = 300;
|
|
23
23
|
/** Distance (px) of the core-ui tooltip slide (`z-slide-*-2`). */
|
|
24
24
|
export const Z_TOOLTIP_SLIDE_DISTANCE = 4;
|
|
25
|
+
/**
|
|
26
|
+
* Set while a tooltip is removed for another one, or by a press on its trigger: its outro is instant, so the
|
|
27
|
+
* tooltip is gone at once instead of fading out under the next one.
|
|
28
|
+
*/
|
|
29
|
+
export const zTooltipTakeover = { active: false };
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { mount, unmount } from 'svelte';
|
|
2
|
-
import { Z_TOOLTIP_HOVER_GRACE_MS, Z_TOOLTIP_SKIP_DELAY_MS } from './z-tooltip.define';
|
|
2
|
+
import { Z_TOOLTIP_HOVER_GRACE_MS, Z_TOOLTIP_SKIP_DELAY_MS, zTooltipTakeover } from './z-tooltip.define';
|
|
3
3
|
import { zIsTextTruncated } from './z-tooltip.utils';
|
|
4
4
|
import ZTooltipPanel, {} from './ZTooltipPanel.svelte';
|
|
5
5
|
import { zOverlayContainer } from '../../overlay/container';
|
|
6
6
|
let tooltipCounter = 0;
|
|
7
7
|
/** When the last tooltip closed — moving straight to a neighbour skips the show delay. */
|
|
8
8
|
let lastHiddenAt = 0;
|
|
9
|
+
/**
|
|
10
|
+
* The tooltip shown last. Opening another one removes it at once (no fade), so two never overlap while the next
|
|
11
|
+
* one appears. Set in `show`, cleared in `dismissNow`.
|
|
12
|
+
*/
|
|
13
|
+
let activeDismiss = null;
|
|
9
14
|
export const zTooltipId = () => `z-tooltip-${++tooltipCounter}`;
|
|
10
15
|
/**
|
|
11
16
|
* Trigger wiring shared by `zTooltip()` and `<ZTooltip>`: delays, warm skip, Escape,
|
|
@@ -21,6 +26,10 @@ export function zBindTooltip(node, config, id, view) {
|
|
|
21
26
|
if (shown) {
|
|
22
27
|
return;
|
|
23
28
|
}
|
|
29
|
+
if (activeDismiss && activeDismiss !== dismissNow) {
|
|
30
|
+
activeDismiss();
|
|
31
|
+
}
|
|
32
|
+
activeDismiss = dismissNow;
|
|
24
33
|
shown = true;
|
|
25
34
|
const described = node.getAttribute('aria-describedby');
|
|
26
35
|
node.setAttribute('aria-describedby', described ? `${described} ${id}` : id);
|
|
@@ -75,6 +84,17 @@ export function zBindTooltip(node, config, id, view) {
|
|
|
75
84
|
};
|
|
76
85
|
const requestHide = () => schedule(false, trigger === 'hover' ? Math.max(hideDelay(), Z_TOOLTIP_HOVER_GRACE_MS) : hideDelay());
|
|
77
86
|
const hideNow = () => schedule(false, 0);
|
|
87
|
+
// Removed at once: no outro. Used when another tooltip takes over and on a press of the trigger.
|
|
88
|
+
const dismissNow = () => {
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
zTooltipTakeover.active = true;
|
|
91
|
+
hide();
|
|
92
|
+
// Svelte reads the transition duration when the outro starts, a microtask later: reset after that.
|
|
93
|
+
setTimeout(() => (zTooltipTakeover.active = false), 0);
|
|
94
|
+
if (activeDismiss === dismissNow) {
|
|
95
|
+
activeDismiss = null;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
78
98
|
function onEscape(event) {
|
|
79
99
|
if (event.key !== 'Escape' || event.isComposing) {
|
|
80
100
|
return;
|
|
@@ -83,7 +103,7 @@ export function zBindTooltip(node, config, id, view) {
|
|
|
83
103
|
event.preventDefault();
|
|
84
104
|
hideNow();
|
|
85
105
|
}
|
|
86
|
-
const onClick = () => (shown ?
|
|
106
|
+
const onClick = () => (shown ? dismissNow() : schedule(true, showDelay()));
|
|
87
107
|
const onOutside = (event) => {
|
|
88
108
|
if (shown && !anchor.contains(event.target)) {
|
|
89
109
|
hideNow();
|
|
@@ -106,7 +126,7 @@ export function zBindTooltip(node, config, id, view) {
|
|
|
106
126
|
[anchor, 'focusin', requestShow],
|
|
107
127
|
[anchor, 'focusout', requestHide],
|
|
108
128
|
// Pressing the trigger acts on it; the hint is no longer needed.
|
|
109
|
-
[anchor, 'pointerdown',
|
|
129
|
+
[anchor, 'pointerdown', dismissNow],
|
|
110
130
|
];
|
|
111
131
|
const onTrigger = trigger === 'hover' ? hoverListeners : [[anchor, 'click', onClick]];
|
|
112
132
|
// Global listeners exist only while this tooltip is open.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shival99/z-ui-svelte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Z-UI component library for Svelte 5 (runes, no CDK).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -55,6 +55,14 @@
|
|
|
55
55
|
"vite": "7.3.1",
|
|
56
56
|
"vitest": "4.1.10"
|
|
57
57
|
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"package": "svelte-package && node scripts/bundle-core-styles.mjs",
|
|
60
|
+
"prepublishOnly": "pnpm package",
|
|
61
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"generate:animated-icons": "node scripts/generate-animated-icons.mjs",
|
|
64
|
+
"lint": "eslint src"
|
|
65
|
+
},
|
|
58
66
|
"dependencies": {
|
|
59
67
|
"@dayflow/blossom-color-picker-svelte": "1.3.0",
|
|
60
68
|
"@floating-ui/dom": "1.8.0",
|
|
@@ -110,12 +118,5 @@
|
|
|
110
118
|
"@aiden0z/pptx-renderer": {
|
|
111
119
|
"optional": true
|
|
112
120
|
}
|
|
113
|
-
},
|
|
114
|
-
"scripts": {
|
|
115
|
-
"package": "svelte-package && node scripts/bundle-core-styles.mjs",
|
|
116
|
-
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
117
|
-
"test": "vitest run",
|
|
118
|
-
"generate:animated-icons": "node scripts/generate-animated-icons.mjs",
|
|
119
|
-
"lint": "eslint src"
|
|
120
121
|
}
|
|
121
|
-
}
|
|
122
|
+
}
|