@cloudlet/toast 1.3.0 → 1.4.0-rc.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/CHANGELOG.md +112 -0
- package/README.md +5 -1
- package/dist/agent.d.ts +334 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +494 -0
- package/dist/agent.js.map +1 -0
- package/dist/contracts/events.d.ts +14 -0
- package/dist/contracts/events.d.ts.map +1 -1
- package/dist/contracts/internal.d.ts +16 -2
- package/dist/contracts/internal.d.ts.map +1 -1
- package/dist/contracts/notifications.d.ts +16 -0
- package/dist/contracts/notifications.d.ts.map +1 -1
- package/dist/contracts/snapshots.d.ts +8 -0
- package/dist/contracts/snapshots.d.ts.map +1 -1
- package/dist/core/actions.d.ts +69 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +160 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/agent-port.d.ts +116 -0
- package/dist/core/agent-port.d.ts.map +1 -0
- package/dist/core/agent-port.js +138 -0
- package/dist/core/agent-port.js.map +1 -0
- package/dist/core/bridge.d.ts.map +1 -1
- package/dist/core/bridge.js +120 -231
- package/dist/core/bridge.js.map +1 -1
- package/dist/core/controller.d.ts +44 -9
- package/dist/core/controller.d.ts.map +1 -1
- package/dist/core/controller.js +367 -292
- package/dist/core/controller.js.map +1 -1
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +103 -94
- package/dist/core/validation.js.map +1 -1
- package/dist/react/card.d.ts.map +1 -1
- package/dist/react/card.js +3 -3
- package/dist/react/card.js.map +1 -1
- package/dist/react/host.d.ts.map +1 -1
- package/dist/react/host.js +257 -246
- package/dist/react/host.js.map +1 -1
- package/dist/react.d.ts +7 -0
- package/dist/react.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/agent.ts +879 -0
- package/src/contracts/events.ts +15 -0
- package/src/contracts/internal.ts +14 -1
- package/src/contracts/notifications.ts +16 -0
- package/src/contracts/snapshots.ts +8 -0
- package/src/core/actions.ts +149 -0
- package/src/core/agent-port.ts +237 -0
- package/src/core/bridge.ts +19 -105
- package/src/core/controller.ts +183 -56
- package/src/core/validation.ts +6 -3
- package/src/react/card.tsx +4 -3
- package/src/react/host.tsx +26 -3
- package/src/react.ts +7 -0
package/src/react/host.tsx
CHANGED
|
@@ -141,6 +141,8 @@ function createHostRuntime(owner: Host) {
|
|
|
141
141
|
motion?.setConstants(constants);
|
|
142
142
|
};
|
|
143
143
|
let reduced = false;
|
|
144
|
+
/** Re-resolves reduced motion (system, `reducedMotion`, an ancestor's attribute); set while mounted. */
|
|
145
|
+
let syncReduced: (() => void) | null = null;
|
|
144
146
|
let hovering = false;
|
|
145
147
|
let observer: ResizeObserver | null = null;
|
|
146
148
|
/** Live layout box of the shell (the target shape); the SVG and clip follow it. */
|
|
@@ -692,7 +694,12 @@ function createHostRuntime(owner: Host) {
|
|
|
692
694
|
announcer.mount(root);
|
|
693
695
|
swipe = createSwipe(root, { begin: beginSwipe, claimsWheel, now: () => view.performance.now() });
|
|
694
696
|
const media = view.matchMedia?.('(prefers-reduced-motion: reduce)');
|
|
695
|
-
|
|
697
|
+
// The app's setting can only add calm: the system, the prop or `data-reduced-motion` on any
|
|
698
|
+
// ancestor (by presence, as the registry components read it). The search starts at the parent,
|
|
699
|
+
// so the host's own output attribute never feeds back.
|
|
700
|
+
let fromAncestor = !!root.parentElement?.closest('[data-reduced-motion]');
|
|
701
|
+
const resolveReduced = () => (media?.matches ?? false) || owner.props.options.reducedMotion === true || fromAncestor;
|
|
702
|
+
reduced = resolveReduced();
|
|
696
703
|
root.dataset.reducedMotion = String(reduced);
|
|
697
704
|
motion = createShellMotion({
|
|
698
705
|
now: () => view.performance.now(), requestFrame: callback => view.requestAnimationFrame(callback),
|
|
@@ -700,11 +707,22 @@ function createHostRuntime(owner: Host) {
|
|
|
700
707
|
timeScale: owner.props.options.motion?.timeScale, constants,
|
|
701
708
|
});
|
|
702
709
|
const preference = () => {
|
|
703
|
-
|
|
710
|
+
const next = resolveReduced();
|
|
711
|
+
if (next === reduced) return;
|
|
712
|
+
reduced = next;
|
|
704
713
|
root.dataset.reducedMotion = String(reduced);
|
|
705
714
|
if (reduced) swipe?.cancel();
|
|
706
715
|
motion?.setReducedMotion(reduced);
|
|
707
716
|
};
|
|
717
|
+
syncReduced = preference;
|
|
718
|
+
// Only the ancestor chain, only this attribute: the host's own attribute is not observed.
|
|
719
|
+
const ancestors = view.MutationObserver ? new view.MutationObserver(() => {
|
|
720
|
+
fromAncestor = !!root.parentElement?.closest('[data-reduced-motion]');
|
|
721
|
+
preference();
|
|
722
|
+
}) : null;
|
|
723
|
+
for (let node = root.parentElement; node && ancestors; node = node.parentElement) {
|
|
724
|
+
ancestors.observe(node, { attributes: true, attributeFilter: ['data-reduced-motion'] });
|
|
725
|
+
}
|
|
708
726
|
// `auto` follows the same breakpoint as the stylesheet: re-render when it flips.
|
|
709
727
|
const wide = view.matchMedia?.('(min-width: 48rem)');
|
|
710
728
|
// `data-resolved-theme` follows the system scheme while the theme is `system`.
|
|
@@ -737,7 +755,11 @@ function createHostRuntime(owner: Host) {
|
|
|
737
755
|
if (scheme) listeners.push([scheme, 'change', followScheme]);
|
|
738
756
|
if (view.visualViewport) listeners.push([view.visualViewport, 'resize', relayout], [view.visualViewport, 'scroll', measureViewport]);
|
|
739
757
|
for (const [target, type, listener, capture] of listeners) target.addEventListener(type, listener, capture);
|
|
740
|
-
cleanup = () => {
|
|
758
|
+
cleanup = () => {
|
|
759
|
+
for (const [target, type, listener, capture] of listeners) target.removeEventListener(type, listener, capture);
|
|
760
|
+
ancestors?.disconnect();
|
|
761
|
+
syncReduced = null;
|
|
762
|
+
};
|
|
741
763
|
// Measure HTML only: the clip's layout box never depends on animated values.
|
|
742
764
|
observer = view.ResizeObserver ? new view.ResizeObserver(() => { measure(); acknowledgePresentation(); }) : null;
|
|
743
765
|
if (clipRef.current) observer?.observe(clipRef.current);
|
|
@@ -792,6 +814,7 @@ function createHostRuntime(owner: Host) {
|
|
|
792
814
|
if (armed && !clearable(owner.props)) disarm(false);
|
|
793
815
|
motion?.setTimeScale(owner.props.options.motion?.timeScale);
|
|
794
816
|
syncConstants();
|
|
817
|
+
syncReduced?.();
|
|
795
818
|
// A swipe never continues on another record or state (arrival, programmatic dismiss, Escape).
|
|
796
819
|
const next = shellView(owner.props.snapshot);
|
|
797
820
|
if (gestureTarget && (gestureTarget.handle !== next.presented?.handle || gestureTarget.open !== next.open)) swipe?.cancel();
|
package/src/react.ts
CHANGED
|
@@ -185,6 +185,13 @@ export interface ToasterProps {
|
|
|
185
185
|
readonly clearAll?: boolean;
|
|
186
186
|
/** Read on every render. */
|
|
187
187
|
readonly motion?: ToasterMotion;
|
|
188
|
+
/**
|
|
189
|
+
* The app's own reduced-motion setting. `true` removes motion whatever the system says; `false`
|
|
190
|
+
* and omitting it follow the system and `data-reduced-motion` on an ancestor (that attribute
|
|
191
|
+
* counts by presence, with any value). An app cannot turn motion on against the system's
|
|
192
|
+
* `prefers-reduced-motion: reduce`. Read on every render.
|
|
193
|
+
*/
|
|
194
|
+
readonly reducedMotion?: boolean;
|
|
188
195
|
/** Extra classes per part, added to the own `cloudlet-*` classes (never replacing them). Read on every render. */
|
|
189
196
|
readonly classNames?: Partial<Record<CloudletPart, string>>;
|
|
190
197
|
}
|