plass-ui 1.0.0 → 1.0.2
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 +165 -0
- package/dist/components/accordion/PlAccordion.js +1 -131
- package/dist/components/accordion/index.js +1 -1
- package/dist/components/alert/PlAlert.js +1 -109
- package/dist/components/alert/index.js +1 -1
- package/dist/components/animate-appear/PlAnimateAppear.js +1 -71
- package/dist/components/animate-appear/index.js +1 -1
- package/dist/components/animate-blink/PlAnimateBlink.js +1 -47
- package/dist/components/animate-blink/index.js +1 -1
- package/dist/components/animate-fade/PlAnimateFade.js +1 -48
- package/dist/components/animate-fade/index.js +1 -1
- package/dist/components/animate-grow/PlAnimateGrow.js +1 -49
- package/dist/components/animate-grow/index.js +1 -1
- package/dist/components/animate-headline/PlAnimateHeadline.js +1 -120
- package/dist/components/animate-headline/index.js +1 -1
- package/dist/components/animate-lighting/PlAnimateLighting.js +1 -65
- package/dist/components/animate-lighting/index.js +1 -1
- package/dist/components/animate-marquee/PlAnimateMarquee.js +1 -94
- package/dist/components/animate-marquee/index.js +1 -1
- package/dist/components/animate-rotate/PlAnimateRotate.js +1 -50
- package/dist/components/animate-rotate/index.js +1 -1
- package/dist/components/animate-slide/PlAnimateSlide.js +1 -49
- package/dist/components/animate-slide/index.js +1 -1
- package/dist/components/animate-typing/PlAnimateTyping.js +1 -177
- package/dist/components/animate-typing/index.js +1 -1
- package/dist/components/animate-zoom/PlAnimateZoom.js +1 -45
- package/dist/components/animate-zoom/index.js +1 -1
- package/dist/components/aspect-ratio/PlAspectRatio.js +1 -58
- package/dist/components/aspect-ratio/index.js +1 -1
- package/dist/components/avatar/PlAvatar.js +1 -121
- package/dist/components/avatar/index.js +1 -1
- package/dist/components/badge/PlBadge.js +1 -168
- package/dist/components/badge/index.js +1 -1
- package/dist/components/blockquote/PlBlockquote.js +1 -112
- package/dist/components/blockquote/index.js +1 -1
- package/dist/components/bottom-navigation/PlBottomNavigation.js +1 -141
- package/dist/components/bottom-navigation/index.js +1 -1
- package/dist/components/box/PlBox.js +1 -46
- package/dist/components/box/index.js +1 -1
- package/dist/components/breadcrumb/PlBreadcrumb.js +1 -201
- package/dist/components/breadcrumb/index.js +1 -1
- package/dist/components/button/PlButton.js +1 -196
- package/dist/components/button/index.js +1 -1
- package/dist/components/button-group/PlButtonGroup.js +1 -64
- package/dist/components/button-group/index.js +1 -1
- package/dist/components/card/PlCard.js +1 -102
- package/dist/components/card/index.js +1 -1
- package/dist/components/carousel/PlCarousel.js +1 -177
- package/dist/components/carousel/index.js +1 -1
- package/dist/components/chat-bubble/PlChatBubble.js +1 -206
- package/dist/components/chat-bubble/index.js +1 -1
- package/dist/components/checkbox/PlCheckbox.js +1 -100
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/chip/PlChip.js +1 -144
- package/dist/components/chip/index.js +1 -1
- package/dist/components/collapsible/PlCollapsible.js +1 -65
- package/dist/components/collapsible/index.js +1 -1
- package/dist/components/combobox/PlCombobox.js +1 -199
- package/dist/components/combobox/index.js +1 -1
- package/dist/components/container/PlContainer.js +1 -47
- package/dist/components/container/index.js +1 -1
- package/dist/components/date-picker/PlDatePicker.js +1 -87
- package/dist/components/date-picker/index.js +1 -1
- package/dist/components/date-range-picker/PlDateRangePicker.js +1 -152
- package/dist/components/date-range-picker/index.js +1 -1
- package/dist/components/date-time-picker/PlDateTimePicker.js +1 -106
- package/dist/components/date-time-picker/index.js +1 -1
- package/dist/components/divider/PlDivider.js +1 -107
- package/dist/components/divider/index.js +1 -1
- package/dist/components/drawer/PlDrawer.js +1 -190
- package/dist/components/drawer/index.js +1 -1
- package/dist/components/file-picker/PlFilePicker.js +1 -274
- package/dist/components/file-picker/index.js +1 -1
- package/dist/components/floating-bottom-navigation/PlFloatingBottomNavigation.js +1 -291
- package/dist/components/floating-bottom-navigation/index.js +1 -1
- package/dist/components/grid/PlGrid.js +1 -51
- package/dist/components/grid/PlGridItem.js +1 -34
- package/dist/components/grid/index.js +1 -2
- package/dist/components/highlight/PlHighlight.js +1 -185
- package/dist/components/highlight/index.js +1 -1
- package/dist/components/hot-keys/PlHotKeys.js +1 -294
- package/dist/components/hot-keys/index.js +1 -1
- package/dist/components/icon/PlIcon.js +1 -58
- package/dist/components/icon/index.js +1 -1
- package/dist/components/icon-button/PlIconButton.js +1 -37
- package/dist/components/icon-button/index.js +1 -1
- package/dist/components/list/PlList.js +1 -160
- package/dist/components/list/index.js +1 -1
- package/dist/components/menu/PlMenu.js +1 -209
- package/dist/components/menu/index.js +1 -1
- package/dist/components/modal/PlModal.js +1 -150
- package/dist/components/modal/index.js +1 -1
- package/dist/components/number-field/PlNumberField.js +1 -111
- package/dist/components/number-field/index.js +1 -1
- package/dist/components/otp-field/PlOtpField.js +1 -109
- package/dist/components/otp-field/index.js +1 -1
- package/dist/components/overlay/PlOverlay.js +1 -77
- package/dist/components/overlay/index.js +1 -1
- package/dist/components/pagination/PlPagination.js +1 -159
- package/dist/components/pagination/index.js +1 -1
- package/dist/components/panes/PlPanes.js +1 -324
- package/dist/components/panes/index.js +1 -1
- package/dist/components/pill/PlPill.js +1 -154
- package/dist/components/pill/index.js +1 -1
- package/dist/components/popover/PlPopover.js +1 -113
- package/dist/components/popover/index.js +1 -1
- package/dist/components/progress-box/PlProgressBox.js +1 -34
- package/dist/components/progress-box/index.js +1 -1
- package/dist/components/progress-circular/PlProgressCircular.js +1 -47
- package/dist/components/progress-circular/index.js +1 -1
- package/dist/components/progress-linear/PlProgressLinear.js +1 -40
- package/dist/components/progress-linear/index.js +1 -1
- package/dist/components/radio-group/PlRadioGroup.js +1 -99
- package/dist/components/radio-group/index.js +1 -1
- package/dist/components/rating/PlRating.js +1 -101
- package/dist/components/rating/index.js +1 -1
- package/dist/components/scroll-zone/PlScrollZone.js +1 -411
- package/dist/components/scroll-zone/index.js +1 -1
- package/dist/components/segmented-button/PlSegmentedButton.js +1 -206
- package/dist/components/segmented-button/index.js +1 -1
- package/dist/components/select/PlSelect.js +1 -115
- package/dist/components/select/index.js +1 -1
- package/dist/components/skeleton/PlSkeleton.js +1 -142
- package/dist/components/skeleton/index.js +1 -1
- package/dist/components/slider/PlSlider.js +1 -132
- package/dist/components/slider/index.js +1 -1
- package/dist/components/spoiler/PlSpoiler.js +1 -74
- package/dist/components/spoiler/index.js +1 -1
- package/dist/components/switch/PlSwitch.js +1 -131
- package/dist/components/switch/index.js +1 -1
- package/dist/components/table/PlTable.js +1 -210
- package/dist/components/table/index.js +1 -1
- package/dist/components/tabs/PlTabs.js +1 -182
- package/dist/components/tabs/index.js +1 -1
- package/dist/components/text-field/PlTextField.js +1 -126
- package/dist/components/text-field/index.js +1 -1
- package/dist/components/text-link/PlTextLink.js +1 -136
- package/dist/components/text-link/index.js +1 -1
- package/dist/components/time-picker/PlTimePicker.js +1 -97
- package/dist/components/time-picker/index.js +1 -1
- package/dist/components/timeline/PlTimeline.js +1 -207
- package/dist/components/timeline/index.js +1 -1
- package/dist/components/toast/PlToast.js +1 -174
- package/dist/components/toast/index.js +1 -1
- package/dist/components/toolbar/PlToolbar.js +1 -65
- package/dist/components/toolbar/index.js +1 -1
- package/dist/components/tooltip/PlTooltip.js +1 -117
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/typography/PlTypography.js +1 -143
- package/dist/components/typography/index.js +1 -1
- package/dist/index.js +1 -75
- package/dist/internal/animate.js +1 -318
- package/dist/internal/button-group.js +2 -19
- package/dist/internal/calendar.js +1 -501
- package/dist/internal/date.js +1 -353
- package/dist/internal/format.js +1 -41
- package/dist/internal/grid.js +1 -143
- package/dist/internal/icons.js +1 -138
- package/dist/internal/menu.js +1 -18
- package/dist/internal/picker.js +1 -139
- package/dist/internal/progress.js +1 -167
- package/dist/internal/sizer.js +1 -35
- package/dist/internal/styles.js +1 -636
- package/dist/types.js +0 -8
- package/package.json +5 -3
|
@@ -1,49 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
-
import { isInfinite, useAnimateElement } from '../../internal/animate.js';
|
|
4
|
-
import { cx } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* Content unfolding from a point.
|
|
7
|
-
*
|
|
8
|
-
* The difference from Zoom is `origin` and how far it travels: a Grow starts
|
|
9
|
-
* close to its final size and can be anchored to an edge, so it reads as
|
|
10
|
-
* something opening out of the thing beside it — a panel out of a toolbar, a
|
|
11
|
-
* card out of the row it belongs to. A Zoom starts much smaller and always from
|
|
12
|
-
* the middle.
|
|
13
|
-
*
|
|
14
|
-
* Short travel is what makes it safe on glass. A sheet growing from 0.8 stays
|
|
15
|
-
* recognisably the same sheet the whole way, and the blur behind it never has
|
|
16
|
-
* to resolve a surface that is a fifth of the size it is about to be.
|
|
17
|
-
*/
|
|
18
|
-
export const PlAnimateGrow = /* @__PURE__ */ React.forwardRef(function PlAnimateGrow({ duration = 320, delay = 0, easing, repeat = 1, alternate, paused, trigger = 'mount', play, once = true, threshold = 0.2, mode = 'in', from = 0.8, origin = 'center', fade = true, render, className, style, children, ...props }, ref) {
|
|
19
|
-
const animate = useAnimateElement({
|
|
20
|
-
effect: 'grow',
|
|
21
|
-
duration,
|
|
22
|
-
delay,
|
|
23
|
-
easing,
|
|
24
|
-
repeat,
|
|
25
|
-
alternate,
|
|
26
|
-
mode,
|
|
27
|
-
scale: from,
|
|
28
|
-
opacity: fade ? 0 : 1,
|
|
29
|
-
trigger,
|
|
30
|
-
play,
|
|
31
|
-
once,
|
|
32
|
-
threshold,
|
|
33
|
-
paused,
|
|
34
|
-
infinite: isInfinite(repeat)
|
|
35
|
-
});
|
|
36
|
-
return useRender({
|
|
37
|
-
render,
|
|
38
|
-
ref: [ref, animate.ref],
|
|
39
|
-
props: {
|
|
40
|
-
...props,
|
|
41
|
-
className: cx(animate.className, className),
|
|
42
|
-
// `transform-origin` governs the standalone `scale` property too, which
|
|
43
|
-
// is what lets the effect stay off the `transform` shorthand entirely.
|
|
44
|
-
style: { transformOrigin: origin, ...animate.style, ...style },
|
|
45
|
-
...animate.props,
|
|
46
|
-
children
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
1
|
+
"use client";import*as e from"react";import{useRender as r}from"@base-ui/react/use-render";import{isInfinite as t,useAnimateElement as a}from"../../internal/animate.js";import{cx as n}from"../../internal/styles.js";export const PlAnimateGrow=/* @__PURE__ */e.forwardRef(function PlAnimateGrow({duration:e=320,delay:o=0,easing:i,repeat:s=1,alternate:l,paused:m,trigger:c="mount",play:d,once:p=!0,threshold:f=.2,mode:u="in",from:g=.8,origin:y="center",fade:h=!0,render:w,className:N,style:j,children:A,...G},P){const b=a({effect:"grow",duration:e,delay:o,easing:i,repeat:s,alternate:l,mode:u,scale:g,opacity:h?0:1,trigger:c,play:d,once:p,threshold:f,paused:m,infinite:t(s)});return r({render:w,ref:[P,b.ref],props:{...G,className:n(b.className,N),style:{transformOrigin:y,...b.style,...j},...b.props,children:A}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlAnimateGrow}from"./PlAnimateGrow.js";
|
|
@@ -1,120 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { isInfinite, lengthValue, useAnimationRun, usePrefersReducedMotion } from '../../internal/animate.js';
|
|
4
|
-
import { cx } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* One line replacing the one above it, on a timer.
|
|
7
|
-
*
|
|
8
|
-
* Every line sits in the same grid cell, so the box is as tall as the longest of
|
|
9
|
-
* them from the first frame and never resizes as the reel turns — which is the
|
|
10
|
-
* whole difficulty with this effect, and the reason the lines that are not
|
|
11
|
-
* showing keep their space with `visibility` rather than being taken out of the
|
|
12
|
-
* layout.
|
|
13
|
-
*
|
|
14
|
-
* It is deliberately not a ticker. A line comes up, it stops, and it is held
|
|
15
|
-
* long enough to read; `interval` is counted from the moment it arrives rather
|
|
16
|
-
* than from the start of the cycle, so raising `duration` does not quietly eat
|
|
17
|
-
* the reading time.
|
|
18
|
-
*
|
|
19
|
-
* Use it for a set of phrases where any one of them would have done — three
|
|
20
|
-
* ways of saying what a product is, a rotating set of customer names. What it is
|
|
21
|
-
* not for is content a reader has to see, because there is no guarantee they are
|
|
22
|
-
* looking during the two seconds it is up, and a screen reader is given the line
|
|
23
|
-
* that happens to be showing rather than the set.
|
|
24
|
-
*/
|
|
25
|
-
export const PlAnimateHeadline = /* @__PURE__ */ React.forwardRef(function PlAnimateHeadline({ duration = 460, delay = 0, easing, repeat = 'infinite', paused, trigger = 'mount', play, once = true, threshold = 0.2, interval = 2600, index, defaultIndex = 0, onIndexChange, loop = true, rise = '100%', className, style, children, ...props }, ref) {
|
|
26
|
-
const run = useAnimationRun({
|
|
27
|
-
trigger,
|
|
28
|
-
play,
|
|
29
|
-
once,
|
|
30
|
-
threshold,
|
|
31
|
-
paused,
|
|
32
|
-
infinite: isInfinite(repeat)
|
|
33
|
-
});
|
|
34
|
-
const reduced = usePrefersReducedMotion();
|
|
35
|
-
const items = React.Children.toArray(children);
|
|
36
|
-
const count = items.length;
|
|
37
|
-
const [uncontrolled, setUncontrolled] = React.useState(defaultIndex);
|
|
38
|
-
const active = Math.min(index ?? uncontrolled, Math.max(count - 1, 0));
|
|
39
|
-
/** The line on its way out. Cleared once its animation has had its time. */
|
|
40
|
-
const [leaving, setLeaving] = React.useState(null);
|
|
41
|
-
const previous = React.useRef(active);
|
|
42
|
-
React.useEffect(() => {
|
|
43
|
-
if (previous.current !== active) {
|
|
44
|
-
setLeaving(previous.current);
|
|
45
|
-
previous.current = active;
|
|
46
|
-
}
|
|
47
|
-
}, [active]);
|
|
48
|
-
React.useEffect(() => {
|
|
49
|
-
if (leaving === null) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const timer = setTimeout(() => setLeaving(null), duration);
|
|
53
|
-
return () => clearTimeout(timer);
|
|
54
|
-
}, [leaving, duration]);
|
|
55
|
-
const advance = React.useCallback(() => {
|
|
56
|
-
const next = active + 1;
|
|
57
|
-
if (next >= count) {
|
|
58
|
-
if (!loop) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (index === undefined) {
|
|
62
|
-
setUncontrolled(0);
|
|
63
|
-
}
|
|
64
|
-
onIndexChange?.(0);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (index === undefined) {
|
|
68
|
-
setUncontrolled(next);
|
|
69
|
-
}
|
|
70
|
-
onIndexChange?.(next);
|
|
71
|
-
}, [active, count, loop, index, onIndexChange]);
|
|
72
|
-
/**
|
|
73
|
-
* The reel only turns on its own when it was not handed an `index`. A
|
|
74
|
-
* controlled Headline is somebody else's timer, and a second one running
|
|
75
|
-
* underneath it would fight for the same state.
|
|
76
|
-
*/
|
|
77
|
-
const turned = React.useRef(false);
|
|
78
|
-
React.useEffect(() => {
|
|
79
|
-
if (index !== undefined || count < 2 || run.state !== 'running') {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (!loop && active === count - 1) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// `delay` is what happens before the reel starts turning at all, so it is
|
|
86
|
-
// added once rather than to every line — which is what an `interval` is.
|
|
87
|
-
const timer = setTimeout(() => {
|
|
88
|
-
turned.current = true;
|
|
89
|
-
advance();
|
|
90
|
-
}, interval + (turned.current ? 0 : delay));
|
|
91
|
-
return () => clearTimeout(timer);
|
|
92
|
-
}, [index, count, run.state, interval, delay, advance, loop, active]);
|
|
93
|
-
return (_jsx("div", { ref: (node) => {
|
|
94
|
-
run.ref(node);
|
|
95
|
-
if (typeof ref === 'function') {
|
|
96
|
-
ref(node);
|
|
97
|
-
}
|
|
98
|
-
else if (ref) {
|
|
99
|
-
ref.current = node;
|
|
100
|
-
}
|
|
101
|
-
}, className: cx('plass-headline', className), style: {
|
|
102
|
-
'--p-anim-duration': `${duration}ms`,
|
|
103
|
-
'--p-anim-rise': lengthValue(rise),
|
|
104
|
-
...(easing ? { '--p-anim-ease': easing } : {}),
|
|
105
|
-
'--p-anim-state': run.state,
|
|
106
|
-
...style
|
|
107
|
-
}, "data-plass-animation": "headline", "data-state": run.state, ...run.handlers, ...props, children: items.map((child, position) => {
|
|
108
|
-
const state = position === active ? 'active' : position === leaving && !reduced ? 'leaving' : undefined;
|
|
109
|
-
const wrap = (content, key) => (_jsx("span", { className: "plass-headline-item", "data-state": state, children: content }, key));
|
|
110
|
-
if (!React.isValidElement(child)) {
|
|
111
|
-
return wrap(child, position);
|
|
112
|
-
}
|
|
113
|
-
const childProps = child.props;
|
|
114
|
-
return React.cloneElement(child, {
|
|
115
|
-
key: position,
|
|
116
|
-
className: cx('plass-headline-item', childProps.className),
|
|
117
|
-
'data-state': state
|
|
118
|
-
});
|
|
119
|
-
}) }));
|
|
120
|
-
});
|
|
1
|
+
"use client";import{jsx as e}from"react/jsx-runtime";import*as t from"react";import{isInfinite as n,lengthValue as a,useAnimationRun as r,usePrefersReducedMotion as i}from"../../internal/animate.js";import{cx as s}from"../../internal/styles.js";export const PlAnimateHeadline=/* @__PURE__ */t.forwardRef(function PlAnimateHeadline({duration:l=460,delay:o=0,easing:u,repeat:c="infinite",paused:m,trigger:d="mount",play:f,once:p=!0,threshold:h=.2,interval:g=2600,index:v,defaultIndex:y=0,onIndexChange:x,loop:E=!0,rise:N="100%",className:j,style:T,children:A,...C},R){const k=r({trigger:d,play:f,once:p,threshold:h,paused:m,infinite:n(c)}),H=i(),I=t.Children.toArray(A),M=I.length,[P,S]=t.useState(y),b=Math.min(v??P,Math.max(M-1,0)),[w,V]=t.useState(null),$=t.useRef(b);t.useEffect(()=>{$.current!==b&&(V($.current),$.current=b)},[b]),t.useEffect(()=>{if(null===w)return;const e=setTimeout(()=>V(null),l);return()=>clearTimeout(e)},[w,l]);const q=t.useCallback(()=>{const e=b+1;if(e>=M){if(!E)return;return void 0===v&&S(0),void x?.(0)}void 0===v&&S(e),x?.(e)},[b,M,E,v,x]),z=t.useRef(!1);return t.useEffect(()=>{if(void 0!==v||M<2||"running"!==k.state)return;if(!E&&b===M-1)return;const e=setTimeout(()=>{z.current=!0,q()},g+(z.current?0:o));return()=>clearTimeout(e)},[v,M,k.state,g,o,q,E,b]),e("div",{ref:e=>{k.ref(e),"function"==typeof R?R(e):R&&(R.current=e)},className:s("plass-headline",j),style:{"--p-anim-duration":`${l}ms`,"--p-anim-rise":a(N),...u?{"--p-anim-ease":u}:{},"--p-anim-state":k.state,...T},"data-plass-animation":"headline","data-state":k.state,...k.handlers,...C,children:I.map((n,a)=>{const r=a===b?"active":a!==w||H?void 0:"leaving";if(!t.isValidElement(n))return e("span",{className:"plass-headline-item","data-state":r,children:n},a);const i=n.props;return t.cloneElement(n,{key:a,className:s("plass-headline-item",i.className),"data-state":r})})})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlAnimateHeadline}from"./PlAnimateHeadline.js";
|
|
@@ -1,65 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
-
import { isInfinite, useAnimateElement } from '../../internal/animate.js';
|
|
4
|
-
import { cx, radiusClasses } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* A light travelling around the outside of something.
|
|
7
|
-
*
|
|
8
|
-
* The light is **behind** the content rather than on it, so what a reader sees
|
|
9
|
-
* is a glow escaping from under the edges — which is why it works on a PlCard
|
|
10
|
-
* or a PlButton without touching anything about how they are drawn. Nothing
|
|
11
|
-
* inside is altered, nothing is overlaid, and the content stays exactly as
|
|
12
|
-
* legible as it was.
|
|
13
|
-
*
|
|
14
|
-
* The arc itself is a gradient that turns between the two ends of the family,
|
|
15
|
-
* which is the same rule every filled surface in the library follows: a flat
|
|
16
|
-
* coloured arc would be paint, and nothing here is paint.
|
|
17
|
-
*
|
|
18
|
-
* Use it to mark the one thing on a screen that is currently live — the row
|
|
19
|
-
* that is processing, the field being checked, the plan being recommended. It
|
|
20
|
-
* draws attention with light rather than by moving anything, which is the only
|
|
21
|
-
* way this library has of saying "here" without also saying "and it moved".
|
|
22
|
-
*
|
|
23
|
-
* `size` has to agree with the radius of what is inside it. The glow follows
|
|
24
|
-
* the wrapper's own corners, so an `lg` card in an `xs` Lighting will show light
|
|
25
|
-
* poking out of four corners the card has already rounded away.
|
|
26
|
-
*/
|
|
27
|
-
export const PlAnimateLighting = /* @__PURE__ */ React.forwardRef(function PlAnimateLighting({ duration = 3000, delay = 0, easing, repeat = 'infinite', alternate, paused, trigger = 'mount', play, once = true, threshold = 0.2, color = 'primary', glow, size = 'md', spread = 3, arc = 50, blur = 5, reverse = false, render, className, style, children, ...props }, ref) {
|
|
28
|
-
const animate = useAnimateElement({
|
|
29
|
-
// The keyframe runs on a pseudo-element rather than on the root, so there
|
|
30
|
-
// is no effect class to apply here — only the slots it reads.
|
|
31
|
-
effect: null,
|
|
32
|
-
duration,
|
|
33
|
-
delay,
|
|
34
|
-
easing,
|
|
35
|
-
repeat,
|
|
36
|
-
alternate,
|
|
37
|
-
mode: reverse ? 'out' : 'in',
|
|
38
|
-
trigger,
|
|
39
|
-
play,
|
|
40
|
-
once,
|
|
41
|
-
threshold,
|
|
42
|
-
paused,
|
|
43
|
-
infinite: isInfinite(repeat)
|
|
44
|
-
});
|
|
45
|
-
return useRender({
|
|
46
|
-
render,
|
|
47
|
-
ref: [ref, animate.ref],
|
|
48
|
-
props: {
|
|
49
|
-
...props,
|
|
50
|
-
className: cx('plass-anim-lighting', radiusClasses[size], className),
|
|
51
|
-
style: {
|
|
52
|
-
...animate.style,
|
|
53
|
-
'--p-anim-glow-from': glow ?? `var(--plass-${color}-solid)`,
|
|
54
|
-
'--p-anim-glow-to': glow ?? `var(--plass-${color}-solid-to)`,
|
|
55
|
-
'--p-anim-glow-width': `${spread}px`,
|
|
56
|
-
'--p-anim-glow-arc': `${arc}deg`,
|
|
57
|
-
'--p-anim-glow-blur': `${blur}px`,
|
|
58
|
-
...style
|
|
59
|
-
},
|
|
60
|
-
...animate.props,
|
|
61
|
-
'data-plass-animation': 'lighting',
|
|
62
|
-
children
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
1
|
+
"use client";import*as e from"react";import{useRender as r}from"@base-ui/react/use-render";import{isInfinite as a,useAnimateElement as i}from"../../internal/animate.js";import{cx as t,radiusClasses as n}from"../../internal/styles.js";export const PlAnimateLighting=/* @__PURE__ */e.forwardRef(function PlAnimateLighting({duration:e=3e3,delay:l=0,easing:o,repeat:s="infinite",alternate:p,paused:m,trigger:d="mount",play:g,once:c=!0,threshold:f=.2,color:u="primary",glow:h,size:y="md",spread:w=3,arc:$=50,blur:b=5,reverse:v=!1,render:x,className:j,style:A,children:L,...N},P){const z=i({effect:null,duration:e,delay:l,easing:o,repeat:s,alternate:p,mode:v?"out":"in",trigger:d,play:g,once:c,threshold:f,paused:m,infinite:a(s)});return r({render:x,ref:[P,z.ref],props:{...N,className:t("plass-anim-lighting",n[y],j),style:{...z.style,"--p-anim-glow-from":h??`var(--plass-${u}-solid)`,"--p-anim-glow-to":h??`var(--plass-${u}-solid-to)`,"--p-anim-glow-width":`${w}px`,"--p-anim-glow-arc":`${$}deg`,"--p-anim-glow-blur":`${b}px`,...A},...z.props,"data-plass-animation":"lighting",children:L}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlAnimateLighting}from"./PlAnimateLighting.js";
|
|
@@ -1,94 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { isInfinite, lengthValue, repeatValue, directionValue, useAnimationRun } from '../../internal/animate.js';
|
|
4
|
-
import { cx } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* Content scrolling steadily past, forever.
|
|
7
|
-
*
|
|
8
|
-
* The content is laid down twice, and each copy travels exactly its own length
|
|
9
|
-
* plus the gap — so the moment the first copy has left, the second is standing
|
|
10
|
-
* precisely where it began. There is no seam, no jump and no frame where the
|
|
11
|
-
* strip is empty, and none of that depends on measuring anything.
|
|
12
|
-
*
|
|
13
|
-
* What *is* measured is only the speed. A duration would mean a strip of four
|
|
14
|
-
* logos and a strip of forty crossing the same box in the same time, with the
|
|
15
|
-
* long one becoming unreadable; `speed` is pixels per second, so both move at
|
|
16
|
-
* the pace of a reader instead. The strip is re-measured whenever it changes
|
|
17
|
-
* size.
|
|
18
|
-
*
|
|
19
|
-
* `pauseOnHover` is on by default and is not decoration: content moving past a
|
|
20
|
-
* pointer cannot be clicked reliably, and a link inside a marquee that never
|
|
21
|
-
* stops is a link nobody can follow.
|
|
22
|
-
*
|
|
23
|
-
* Only the first copy is read out. The rest carry `aria-hidden`, or a screen
|
|
24
|
-
* reader would announce everything on the strip as many times as it was laid
|
|
25
|
-
* down.
|
|
26
|
-
*/
|
|
27
|
-
export const PlAnimateMarquee = /* @__PURE__ */ React.forwardRef(function PlAnimateMarquee({ duration, delay = 0, easing, repeat = 'infinite', alternate, paused, trigger = 'mount', play, once = true, threshold = 0.2, orientation = 'horizontal', reverse = false, speed = 60, gap = '2rem', copies = 2, pauseOnHover = true, className, style, children, ...props }, ref) {
|
|
28
|
-
const run = useAnimationRun({
|
|
29
|
-
trigger,
|
|
30
|
-
play,
|
|
31
|
-
once,
|
|
32
|
-
threshold,
|
|
33
|
-
paused,
|
|
34
|
-
infinite: isInfinite(repeat)
|
|
35
|
-
});
|
|
36
|
-
const boxRef = React.useRef(null);
|
|
37
|
-
const trackRef = React.useRef(null);
|
|
38
|
-
const [travel, setTravel] = React.useState(0);
|
|
39
|
-
const vertical = orientation === 'vertical';
|
|
40
|
-
/**
|
|
41
|
-
* How far one copy has to go, in pixels: its own length plus the gap after
|
|
42
|
-
* it. The gap is read back off the computed style rather than parsed out of
|
|
43
|
-
* the prop, because `'2rem'` is only a number once a font size has been
|
|
44
|
-
* resolved — and the one on the page is the one that matters.
|
|
45
|
-
*/
|
|
46
|
-
React.useEffect(() => {
|
|
47
|
-
const box = boxRef.current;
|
|
48
|
-
const track = trackRef.current;
|
|
49
|
-
if (!box || !track) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const measure = () => {
|
|
53
|
-
const styles = getComputedStyle(box);
|
|
54
|
-
const gapPx = parseFloat(vertical ? styles.rowGap : styles.columnGap) || 0;
|
|
55
|
-
const size = vertical ? track.offsetHeight : track.offsetWidth;
|
|
56
|
-
setTravel(size + gapPx);
|
|
57
|
-
};
|
|
58
|
-
measure();
|
|
59
|
-
if (typeof ResizeObserver === 'undefined') {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const observer = new ResizeObserver(measure);
|
|
63
|
-
observer.observe(track);
|
|
64
|
-
observer.observe(box);
|
|
65
|
-
return () => observer.disconnect();
|
|
66
|
-
}, [vertical, children]);
|
|
67
|
-
// An explicit duration wins; otherwise the measurement decides, and until the
|
|
68
|
-
// first measurement lands there is a sane number rather than `0ms`, which
|
|
69
|
-
// browsers read as "finish immediately".
|
|
70
|
-
const runDuration = duration ?? (travel > 0 ? (travel / speed) * 1000 : 12000);
|
|
71
|
-
const track = (index) => (_jsx("div", { ref: index === 0 ? trackRef : undefined, className: "plass-marquee-track", "aria-hidden": index === 0 ? undefined : 'true', children: children }, index));
|
|
72
|
-
return (_jsx("div", { ref: (node) => {
|
|
73
|
-
boxRef.current = node;
|
|
74
|
-
run.ref(node);
|
|
75
|
-
if (typeof ref === 'function') {
|
|
76
|
-
ref(node);
|
|
77
|
-
}
|
|
78
|
-
else if (ref) {
|
|
79
|
-
ref.current = node;
|
|
80
|
-
}
|
|
81
|
-
}, className: cx('plass-marquee', vertical && 'plass-marquee-vertical', className), style: {
|
|
82
|
-
'--p-anim-gap': lengthValue(gap),
|
|
83
|
-
// Linear unless a caller insists otherwise: an eased marquee slows at
|
|
84
|
-
// both ends of a loop that has no ends, which reads as the page
|
|
85
|
-
// stuttering.
|
|
86
|
-
...(easing ? { '--p-anim-ease': easing } : {}),
|
|
87
|
-
'--p-anim-duration': `${Math.round(runDuration)}ms`,
|
|
88
|
-
'--p-anim-delay': `${delay}ms`,
|
|
89
|
-
'--p-anim-repeat': repeatValue(repeat),
|
|
90
|
-
'--p-anim-direction': directionValue(reverse ? 'out' : 'in', alternate),
|
|
91
|
-
'--p-anim-state': run.state,
|
|
92
|
-
...style
|
|
93
|
-
}, "data-plass-animation": "marquee", "data-state": run.state, "data-pause-on-hover": pauseOnHover ? '' : undefined, ...run.handlers, ...props, children: Array.from({ length: Math.max(1, copies) }, (_, index) => track(index)) }));
|
|
94
|
-
});
|
|
1
|
+
"use client";import{jsx as e}from"react/jsx-runtime";import*as t from"react";import{isInfinite as a,lengthValue as r,repeatValue as n,directionValue as s,useAnimationRun as i}from"../../internal/animate.js";import{cx as o}from"../../internal/styles.js";export const PlAnimateMarquee=/* @__PURE__ */t.forwardRef(function PlAnimateMarquee({duration:l,delay:u=0,easing:m,repeat:p="infinite",alternate:c,paused:d,trigger:f="mount",play:h,once:v=!0,threshold:y=.2,orientation:g="horizontal",reverse:q=!1,speed:R=60,gap:b="2rem",copies:j=2,pauseOnHover:x=!0,className:M,style:w,children:z,...A},N){const O=i({trigger:f,play:h,once:v,threshold:y,paused:d,infinite:a(p)}),G=t.useRef(null),H=t.useRef(null),[P,S]=t.useState(0),$="vertical"===g;t.useEffect(()=>{const e=G.current,t=H.current;if(!e||!t)return;const measure=()=>{const a=getComputedStyle(e),r=parseFloat($?a.rowGap:a.columnGap)||0,n=$?t.offsetHeight:t.offsetWidth;S(n+r)};if(measure(),"undefined"==typeof ResizeObserver)return;const a=new ResizeObserver(measure);return a.observe(t),a.observe(e),()=>a.disconnect()},[$,z]);const k=l??(P>0?P/R*1e3:12e3);return e("div",{ref:e=>{G.current=e,O.ref(e),"function"==typeof N?N(e):N&&(N.current=e)},className:o("plass-marquee",$&&"plass-marquee-vertical",M),style:{"--p-anim-gap":r(b),...m?{"--p-anim-ease":m}:{},"--p-anim-duration":`${Math.round(k)}ms`,"--p-anim-delay":`${u}ms`,"--p-anim-repeat":n(p),"--p-anim-direction":s(q?"out":"in",c),"--p-anim-state":O.state,...w},"data-plass-animation":"marquee","data-state":O.state,"data-pause-on-hover":x?"":void 0,...O.handlers,...A,children:Array.from({length:Math.max(1,j)},(t,a)=>(t=>e("div",{ref:0===t?H:void 0,className:"plass-marquee-track","aria-hidden":0===t?void 0:"true",children:z},t))(a))})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlAnimateMarquee}from"./PlAnimateMarquee.js";
|
|
@@ -1,50 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
-
import { isInfinite, useAnimateElement } from '../../internal/animate.js';
|
|
4
|
-
import { cx } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* Content turning about a point.
|
|
7
|
-
*
|
|
8
|
-
* Two angles rather than one, which is what lets this be both effects a
|
|
9
|
-
* rotation is ever used for. `from` alone is an arrival — something swinging
|
|
10
|
-
* into place and stopping. `from` and `to` together with `repeat="infinite"`
|
|
11
|
-
* and `easing="linear"` is a spin that never lands, which is what a badge, a
|
|
12
|
-
* loading mark or a decorative glyph wants.
|
|
13
|
-
*
|
|
14
|
-
* Rotation is the one movement the design language allows on a glyph without
|
|
15
|
-
* argument — a chevron is turned rather than redrawn all over the library. What
|
|
16
|
-
* it is not for is text: a rotated word is resampled along its whole length,
|
|
17
|
-
* which is precisely what the rule against transforming a control exists to
|
|
18
|
-
* prevent.
|
|
19
|
-
*/
|
|
20
|
-
export const PlAnimateRotate = /* @__PURE__ */ React.forwardRef(function PlAnimateRotate({ duration = 440, delay = 0, easing, repeat = 1, alternate, paused, trigger = 'mount', play, once = true, threshold = 0.2, mode = 'in', from = -180, to = 0, origin = 'center', fade = true, render, className, style, children, ...props }, ref) {
|
|
21
|
-
const animate = useAnimateElement({
|
|
22
|
-
effect: 'rotate',
|
|
23
|
-
duration,
|
|
24
|
-
delay,
|
|
25
|
-
easing,
|
|
26
|
-
repeat,
|
|
27
|
-
alternate,
|
|
28
|
-
mode,
|
|
29
|
-
angle: `${from}deg`,
|
|
30
|
-
angleTo: `${to}deg`,
|
|
31
|
-
opacity: fade ? 0 : 1,
|
|
32
|
-
trigger,
|
|
33
|
-
play,
|
|
34
|
-
once,
|
|
35
|
-
threshold,
|
|
36
|
-
paused,
|
|
37
|
-
infinite: isInfinite(repeat)
|
|
38
|
-
});
|
|
39
|
-
return useRender({
|
|
40
|
-
render,
|
|
41
|
-
ref: [ref, animate.ref],
|
|
42
|
-
props: {
|
|
43
|
-
...props,
|
|
44
|
-
className: cx(animate.className, className),
|
|
45
|
-
style: { transformOrigin: origin, ...animate.style, ...style },
|
|
46
|
-
...animate.props,
|
|
47
|
-
children
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
});
|
|
1
|
+
"use client";import*as e from"react";import{useRender as r}from"@base-ui/react/use-render";import{isInfinite as t,useAnimateElement as a}from"../../internal/animate.js";import{cx as n}from"../../internal/styles.js";export const PlAnimateRotate=/* @__PURE__ */e.forwardRef(function PlAnimateRotate({duration:e=440,delay:o=0,easing:i,repeat:s=1,alternate:l,paused:d,trigger:m="mount",play:c,once:p=!0,threshold:f=.2,mode:g="in",from:u=-180,to:y=0,origin:h="center",fade:N=!0,render:R,className:j,style:A,children:P,...$},b){const w=a({effect:"rotate",duration:e,delay:o,easing:i,repeat:s,alternate:l,mode:g,angle:`${u}deg`,angleTo:`${y}deg`,opacity:N?0:1,trigger:m,play:c,once:p,threshold:f,paused:d,infinite:t(s)});return r({render:R,ref:[b,w.ref],props:{...$,className:n(w.className,j),style:{transformOrigin:h,...w.style,...A},...w.props,children:P}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlAnimateRotate}from"./PlAnimateRotate.js";
|
|
@@ -1,49 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
-
import { isInfinite, slideOffsets, useAnimateElement } from '../../internal/animate.js';
|
|
4
|
-
import { cx } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* Content travelling in from one edge.
|
|
7
|
-
*
|
|
8
|
-
* The default distance is the element's own size, so it starts exactly out of
|
|
9
|
-
* frame and arrives without ever having been half drawn somewhere it does not
|
|
10
|
-
* belong. Put it in a box with `overflow: hidden` and the effect is a panel
|
|
11
|
-
* appearing from behind that box's edge.
|
|
12
|
-
*
|
|
13
|
-
* A slide moves the element, so what is *around* it does not move: this is a
|
|
14
|
-
* `translate` rather than a change of layout, and nothing on the page reflows
|
|
15
|
-
* while it runs. For a much shorter travel over a list of things, one after
|
|
16
|
-
* another, use PlAnimateAppear.
|
|
17
|
-
*/
|
|
18
|
-
export const PlAnimateSlide = /* @__PURE__ */ React.forwardRef(function PlAnimateSlide({ duration = 360, delay = 0, easing, repeat = 1, alternate, paused, trigger = 'mount', play, once = true, threshold = 0.2, mode = 'in', from = 'bottom', distance = '100%', fade = true, render, className, style, children, ...props }, ref) {
|
|
19
|
-
const { x, y } = slideOffsets(from, distance);
|
|
20
|
-
const animate = useAnimateElement({
|
|
21
|
-
effect: 'slide',
|
|
22
|
-
duration,
|
|
23
|
-
delay,
|
|
24
|
-
easing,
|
|
25
|
-
repeat,
|
|
26
|
-
alternate,
|
|
27
|
-
mode,
|
|
28
|
-
x,
|
|
29
|
-
y,
|
|
30
|
-
opacity: fade ? 0 : 1,
|
|
31
|
-
trigger,
|
|
32
|
-
play,
|
|
33
|
-
once,
|
|
34
|
-
threshold,
|
|
35
|
-
paused,
|
|
36
|
-
infinite: isInfinite(repeat)
|
|
37
|
-
});
|
|
38
|
-
return useRender({
|
|
39
|
-
render,
|
|
40
|
-
ref: [ref, animate.ref],
|
|
41
|
-
props: {
|
|
42
|
-
...props,
|
|
43
|
-
className: cx(animate.className, className),
|
|
44
|
-
style: { ...animate.style, ...style },
|
|
45
|
-
...animate.props,
|
|
46
|
-
children
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
1
|
+
"use client";import*as e from"react";import{useRender as r}from"@base-ui/react/use-render";import{isInfinite as t,slideOffsets as a,useAnimateElement as n}from"../../internal/animate.js";import{cx as i}from"../../internal/styles.js";export const PlAnimateSlide=/* @__PURE__ */e.forwardRef(function PlAnimateSlide({duration:e=360,delay:s=0,easing:o,repeat:l=1,alternate:d,paused:m,trigger:c="mount",play:p,once:f=!0,threshold:y=.2,mode:u="in",from:g="bottom",distance:h="100%",fade:x=!0,render:N,className:b,style:j,children:A,...P},S){const{x:w,y:R}=a(g,h),k=n({effect:"slide",duration:e,delay:s,easing:o,repeat:l,alternate:d,mode:u,x:w,y:R,opacity:x?0:1,trigger:c,play:p,once:f,threshold:y,paused:m,infinite:t(l)});return r({render:N,ref:[S,k.ref],props:{...P,className:i(k.className,b),style:{...k.style,...j},...k.props,children:A}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlAnimateSlide}from"./PlAnimateSlide.js";
|
|
@@ -1,177 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { isInfinite, useAnimationRun, usePrefersReducedMotion } from '../../internal/animate.js';
|
|
4
|
-
import { srOnlyClasses } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* Everything typeable in a node, flattened.
|
|
7
|
-
*
|
|
8
|
-
* Elements are deliberately not walked into. A typewriter reveals a string one
|
|
9
|
-
* grapheme at a time, and there is no honest way to reveal half of a `<strong>`
|
|
10
|
-
* — the effect is over text, so its input is text.
|
|
11
|
-
*/
|
|
12
|
-
function textOf(node) {
|
|
13
|
-
if (typeof node === 'string' || typeof node === 'number') {
|
|
14
|
-
return String(node);
|
|
15
|
-
}
|
|
16
|
-
if (Array.isArray(node)) {
|
|
17
|
-
return node.map(textOf).join('');
|
|
18
|
-
}
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The text split the way a reader would split it.
|
|
23
|
-
*
|
|
24
|
-
* Not `[...text]`, and not `text.split('')`. A code point is not a character:
|
|
25
|
-
* `👩👩👧` is seven of them, `한` typed on a Korean keyboard can be three, and a
|
|
26
|
-
* typewriter that advances by code points spends four frames assembling an
|
|
27
|
-
* emoji out of parts that mean nothing on their own. `Intl.Segmenter` knows
|
|
28
|
-
* where the boundaries actually are; the spread is the fallback for a runtime
|
|
29
|
-
* that does not have it.
|
|
30
|
-
*/
|
|
31
|
-
function graphemesOf(text, locale) {
|
|
32
|
-
if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
|
|
33
|
-
const segmenter = new Intl.Segmenter(locale, { granularity: 'grapheme' });
|
|
34
|
-
return [...segmenter.segment(text)].map((segment) => segment.segment);
|
|
35
|
-
}
|
|
36
|
-
return [...text];
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Text appearing one character at a time.
|
|
40
|
-
*
|
|
41
|
-
* The whole string is in the document from the first frame — in a clipped box
|
|
42
|
-
* for a screen reader, which reads it once and is not made to sit through the
|
|
43
|
-
* performance — and what animates is a visible copy that is `aria-hidden`. So
|
|
44
|
-
* the effect costs a reader who cannot see it nothing, and costs a reader who
|
|
45
|
-
* can nothing either: the box is not laid out from the characters that have
|
|
46
|
-
* arrived, so the text around it does not reflow on every frame.
|
|
47
|
-
*
|
|
48
|
-
* `repeat`, `hold` and `erase` are what make it a loop: type, hold, delete,
|
|
49
|
-
* type again. Without `erase` a repeat clears in one frame, which is right for
|
|
50
|
-
* a line that is being replaced rather than rewritten.
|
|
51
|
-
*
|
|
52
|
-
* Only text is typed. Pass a string, or strings; an element among the children
|
|
53
|
-
* contributes its text and nothing about its markup, because there is no honest
|
|
54
|
-
* way to reveal half of a link.
|
|
55
|
-
*/
|
|
56
|
-
export const PlAnimateTyping = /* @__PURE__ */ React.forwardRef(function PlAnimateTyping({ text, speed = 24, hold = 1400, erase = false, eraseSpeed, caret = true, caretChar = '|', duration, delay = 0, repeat = 1, paused, trigger = 'mount', play, once = true, threshold = 0.2, className, style, children, ...props }, ref) {
|
|
57
|
-
const run = useAnimationRun({
|
|
58
|
-
trigger,
|
|
59
|
-
play,
|
|
60
|
-
once,
|
|
61
|
-
threshold,
|
|
62
|
-
paused,
|
|
63
|
-
infinite: isInfinite(repeat)
|
|
64
|
-
});
|
|
65
|
-
const reduced = usePrefersReducedMotion();
|
|
66
|
-
const source = text ?? textOf(children);
|
|
67
|
-
const graphemes = React.useMemo(() => graphemesOf(source), [source]);
|
|
68
|
-
const total = graphemes.length;
|
|
69
|
-
const [shown, setShown] = React.useState(0);
|
|
70
|
-
/**
|
|
71
|
-
* How far along it is, outside React's state.
|
|
72
|
-
*
|
|
73
|
-
* The typing loop is a chain of timeouts rather than a render, so pausing
|
|
74
|
-
* tears it down and resuming builds a new one — and a new one has to know
|
|
75
|
-
* where the old one stopped. Reading `shown` would put the effect in a loop
|
|
76
|
-
* with its own output.
|
|
77
|
-
*/
|
|
78
|
-
const progress = React.useRef(0);
|
|
79
|
-
/**
|
|
80
|
-
* `duration` is honoured as the time for the whole string, because a caller
|
|
81
|
-
* who has set a duration on every other PlAnimate component will reach for it
|
|
82
|
-
* here too. `speed` is the natural unit for a typewriter — a long paragraph
|
|
83
|
-
* and a short one should be typed at the same pace, not in the same time — so
|
|
84
|
-
* it is the default and the duration overrides it.
|
|
85
|
-
*/
|
|
86
|
-
const typeDelay = duration && total > 0 ? duration / total : 1000 / Math.max(speed, 1);
|
|
87
|
-
const deleteDelay = 1000 / Math.max(eraseSpeed ?? speed * 2, 1);
|
|
88
|
-
// A new string starts a new performance rather than continuing the last.
|
|
89
|
-
React.useEffect(() => {
|
|
90
|
-
progress.current = 0;
|
|
91
|
-
}, [total]);
|
|
92
|
-
React.useEffect(() => {
|
|
93
|
-
if (reduced || total === 0) {
|
|
94
|
-
// Not "nothing happens" — the text is simply there, which is the only
|
|
95
|
-
// outcome that still delivers what the component was carrying.
|
|
96
|
-
setShown(total);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (!run.started) {
|
|
100
|
-
// Waiting is empty, not finished: a typewriter that showed its whole
|
|
101
|
-
// string until it scrolled into view and then blanked would be worse than
|
|
102
|
-
// no effect at all.
|
|
103
|
-
progress.current = 0;
|
|
104
|
-
setShown(0);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (paused) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
let cancelled = false;
|
|
111
|
-
let timer;
|
|
112
|
-
let count = progress.current;
|
|
113
|
-
let pass = 1;
|
|
114
|
-
let deleting = false;
|
|
115
|
-
const passes = repeat === 'infinite' ? Infinity : Math.max(1, repeat);
|
|
116
|
-
if (count >= total && passes === 1) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const step = () => {
|
|
120
|
-
if (cancelled) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (deleting) {
|
|
124
|
-
count -= 1;
|
|
125
|
-
progress.current = count;
|
|
126
|
-
setShown(count);
|
|
127
|
-
if (count <= 0) {
|
|
128
|
-
deleting = false;
|
|
129
|
-
pass += 1;
|
|
130
|
-
}
|
|
131
|
-
timer = setTimeout(step, deleting ? deleteDelay : typeDelay);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
count += 1;
|
|
135
|
-
progress.current = count;
|
|
136
|
-
setShown(count);
|
|
137
|
-
if (count < total) {
|
|
138
|
-
timer = setTimeout(step, typeDelay);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (pass >= passes) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (erase) {
|
|
145
|
-
deleting = true;
|
|
146
|
-
timer = setTimeout(step, hold);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
pass += 1;
|
|
150
|
-
timer = setTimeout(() => {
|
|
151
|
-
if (cancelled) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
count = 0;
|
|
155
|
-
progress.current = 0;
|
|
156
|
-
setShown(0);
|
|
157
|
-
timer = setTimeout(step, typeDelay);
|
|
158
|
-
}, hold);
|
|
159
|
-
};
|
|
160
|
-
setShown(count);
|
|
161
|
-
// Resuming picks up at the next character; starting waits out the delay.
|
|
162
|
-
timer = setTimeout(step, count === 0 ? delay : typeDelay);
|
|
163
|
-
return () => {
|
|
164
|
-
cancelled = true;
|
|
165
|
-
clearTimeout(timer);
|
|
166
|
-
};
|
|
167
|
-
}, [run.started, paused, reduced, total, typeDelay, deleteDelay, delay, hold, erase, repeat]);
|
|
168
|
-
return (_jsxs("div", { ref: (node) => {
|
|
169
|
-
run.ref(node);
|
|
170
|
-
if (typeof ref === 'function') {
|
|
171
|
-
ref(node);
|
|
172
|
-
}
|
|
173
|
-
else if (ref) {
|
|
174
|
-
ref.current = node;
|
|
175
|
-
}
|
|
176
|
-
}, className: className, style: style, "data-plass-animation": "typing", "data-state": run.state, ...run.handlers, ...props, children: [_jsx("span", { className: srOnlyClasses, children: source }), _jsxs("span", { "aria-hidden": "true", className: "whitespace-pre-wrap", children: [graphemes.slice(0, shown).join(''), caret ? _jsx("span", { className: "plass-caret", children: caretChar }) : null] })] }));
|
|
177
|
-
});
|
|
1
|
+
"use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as r from"react";import{isInfinite as n,useAnimationRun as a,usePrefersReducedMotion as i}from"../../internal/animate.js";import{srOnlyClasses as s}from"../../internal/styles.js";function textOf(e){return"string"==typeof e||"number"==typeof e?String(e):Array.isArray(e)?e.map(textOf).join(""):""}export const PlAnimateTyping=/* @__PURE__ */r.forwardRef(function PlAnimateTyping({text:o,speed:u=24,hold:m=1400,erase:c=!1,eraseSpeed:l,caret:f=!0,caretChar:p="|",duration:d,delay:h=0,repeat:g=1,paused:y,trigger:x="mount",play:T,once:j=!0,threshold:v=.2,className:N,style:S,children:w,...A},M){const O=a({trigger:x,play:T,once:j,threshold:v,paused:y,infinite:n(g)}),I=i(),E=o??textOf(w),P=r.useMemo(()=>function graphemesOf(e,t){return"undefined"!=typeof Intl&&"Segmenter"in Intl?[...new Intl.Segmenter(t,{granularity:"grapheme"}).segment(e)].map(e=>e.segment):[...e]}(E),[E]),R=P.length,[b,C]=r.useState(0),k=r.useRef(0),q=d&&R>0?d/R:1e3/Math.max(u,1),z=1e3/Math.max(l??2*u,1);return r.useEffect(()=>{k.current=0},[R]),r.useEffect(()=>{if(I||0===R)return void C(R);if(!O.started)return k.current=0,void C(0);if(y)return;let e,t=!1,r=k.current,n=1,a=!1;const i="infinite"===g?1/0:Math.max(1,g);if(r>=R&&1===i)return;const step=()=>{if(!t){if(a)return r-=1,k.current=r,C(r),r<=0&&(a=!1,n+=1),void(e=setTimeout(step,a?z:q));if(r+=1,k.current=r,C(r),r<R)e=setTimeout(step,q);else if(!(n>=i)){if(c)return a=!0,void(e=setTimeout(step,m));n+=1,e=setTimeout(()=>{t||(r=0,k.current=0,C(0),e=setTimeout(step,q))},m)}}};return C(r),e=setTimeout(step,0===r?h:q),()=>{t=!0,clearTimeout(e)}},[O.started,y,I,R,q,z,h,m,c,g]),t("div",{ref:e=>{O.ref(e),"function"==typeof M?M(e):M&&(M.current=e)},className:N,style:S,"data-plass-animation":"typing","data-state":O.state,...O.handlers,...A,children:[e("span",{className:s,children:E}),t("span",{"aria-hidden":"true",className:"whitespace-pre-wrap",children:[P.slice(0,b).join(""),f?e("span",{className:"plass-caret",children:p}):null]})]})});
|