@funstack/ui 0.1.0-alpha.20 → 0.1.0-alpha.22
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/alert-dialog/alert-dialog-root.mjs +2 -1
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -1
- package/dist/avatar/avatar-context.mjs +24 -0
- package/dist/avatar/avatar-context.mjs.map +1 -0
- package/dist/avatar/avatar-fallback.d.mts +32 -0
- package/dist/avatar/avatar-fallback.d.mts.map +1 -0
- package/dist/avatar/avatar-fallback.mjs +31 -0
- package/dist/avatar/avatar-fallback.mjs.map +1 -0
- package/dist/avatar/avatar-image.d.mts +37 -0
- package/dist/avatar/avatar-image.d.mts.map +1 -0
- package/dist/avatar/avatar-image.mjs +91 -0
- package/dist/avatar/avatar-image.mjs.map +1 -0
- package/dist/avatar/avatar-root.d.mts +48 -0
- package/dist/avatar/avatar-root.d.mts.map +1 -0
- package/dist/avatar/avatar-root.mjs +81 -0
- package/dist/avatar/avatar-root.mjs.map +1 -0
- package/dist/avatar/index.d.mts +24 -0
- package/dist/avatar/index.d.mts.map +1 -0
- package/dist/avatar/index.mjs +24 -0
- package/dist/avatar/index.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +14 -3
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs +7 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +1 -0
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +20 -2
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.mjs +6 -4
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/docs/components/avatar.md +354 -0
- package/dist/docs/components/drawer.md +622 -0
- package/dist/docs/components/menu.md +1 -1
- package/dist/docs/components/menubar.md +309 -0
- package/dist/docs/components/meter.md +1 -1
- package/dist/docs/components/navigation-menu.md +501 -0
- package/dist/docs/components/number-field.md +2 -2
- package/dist/docs/components/otp-field.md +508 -0
- package/dist/docs/components/progress.md +1 -1
- package/dist/docs/components/radio-group.md +1 -1
- package/dist/docs/components/scroll-area.md +294 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/concepts/direction-and-locales.md +106 -0
- package/dist/docs/index.md +8 -1
- package/dist/docs/roadmap.md +13 -0
- package/dist/drawer/drawer-close.d.mts +26 -0
- package/dist/drawer/drawer-close.d.mts.map +1 -0
- package/dist/drawer/drawer-close.mjs +19 -0
- package/dist/drawer/drawer-close.mjs.map +1 -0
- package/dist/drawer/drawer-description.d.mts +23 -0
- package/dist/drawer/drawer-description.d.mts.map +1 -0
- package/dist/drawer/drawer-description.mjs +18 -0
- package/dist/drawer/drawer-description.mjs.map +1 -0
- package/dist/drawer/drawer-form.d.mts +24 -0
- package/dist/drawer/drawer-form.d.mts.map +1 -0
- package/dist/drawer/drawer-form.mjs +19 -0
- package/dist/drawer/drawer-form.mjs.map +1 -0
- package/dist/drawer/drawer-popup.d.mts +77 -0
- package/dist/drawer/drawer-popup.d.mts.map +1 -0
- package/dist/drawer/drawer-popup.mjs +124 -0
- package/dist/drawer/drawer-popup.mjs.map +1 -0
- package/dist/drawer/drawer-root.d.mts +31 -0
- package/dist/drawer/drawer-root.d.mts.map +1 -0
- package/dist/drawer/drawer-root.mjs +23 -0
- package/dist/drawer/drawer-root.mjs.map +1 -0
- package/dist/drawer/drawer-swipe.d.mts +5 -0
- package/dist/drawer/drawer-swipe.d.mts.map +1 -0
- package/dist/drawer/drawer-swipe.mjs +193 -0
- package/dist/drawer/drawer-swipe.mjs.map +1 -0
- package/dist/drawer/drawer-title.d.mts +23 -0
- package/dist/drawer/drawer-title.d.mts.map +1 -0
- package/dist/drawer/drawer-title.mjs +18 -0
- package/dist/drawer/drawer-title.mjs.map +1 -0
- package/dist/drawer/drawer-trigger.d.mts +23 -0
- package/dist/drawer/drawer-trigger.d.mts.map +1 -0
- package/dist/drawer/drawer-trigger.mjs +18 -0
- package/dist/drawer/drawer-trigger.mjs.map +1 -0
- package/dist/drawer/index.d.mts +34 -0
- package/dist/drawer/index.d.mts.map +1 -0
- package/dist/drawer/index.mjs +33 -0
- package/dist/drawer/index.mjs.map +1 -0
- package/dist/index.d.mts +29 -2
- package/dist/index.mjs +6 -1
- package/dist/internal/menubar-context.mjs +12 -0
- package/dist/internal/menubar-context.mjs.map +1 -0
- package/dist/internal/overlay/trigger-ref.mjs +1 -1
- package/dist/internal/overlay/trigger-ref.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +3 -2
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.mjs +2 -2
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/range-value.mjs +5 -3
- package/dist/internal/range-value.mjs.map +1 -1
- package/dist/internal/swipe-arithmetic.mjs +75 -0
- package/dist/internal/swipe-arithmetic.mjs.map +1 -0
- package/dist/internal/swipe.mjs +169 -0
- package/dist/internal/swipe.mjs.map +1 -0
- package/dist/menu/menu-context-trigger.mjs +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +34 -7
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +10 -3
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +53 -5
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menubar/index.d.mts +3 -0
- package/dist/menubar/index.mjs +1 -0
- package/dist/menubar/menubar.d.mts +49 -0
- package/dist/menubar/menubar.d.mts.map +1 -0
- package/dist/menubar/menubar.mjs +147 -0
- package/dist/menubar/menubar.mjs.map +1 -0
- package/dist/meter/meter-root.d.mts +3 -2
- package/dist/meter/meter-root.d.mts.map +1 -1
- package/dist/meter/meter-root.mjs.map +1 -1
- package/dist/multi-select/multi-select-root.mjs +1 -1
- package/dist/multi-select/multi-select-trigger.mjs +1 -1
- package/dist/navigation-menu/index.d.mts +32 -0
- package/dist/navigation-menu/index.d.mts.map +1 -0
- package/dist/navigation-menu/index.mjs +32 -0
- package/dist/navigation-menu/index.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-context.mjs +19 -0
- package/dist/navigation-menu/navigation-menu-context.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts +79 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.mjs +80 -0
- package/dist/navigation-menu/navigation-menu-item.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts +48 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.mjs +66 -0
- package/dist/navigation-menu/navigation-menu-link.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.mjs +30 -0
- package/dist/navigation-menu/navigation-menu-list.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts +102 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs +93 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.mjs +27 -0
- package/dist/navigation-menu/navigation-menu-root.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts +32 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs +42 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs.map +1 -0
- package/dist/otp-field/index.d.mts +23 -0
- package/dist/otp-field/index.d.mts.map +1 -0
- package/dist/otp-field/index.mjs +23 -0
- package/dist/otp-field/index.mjs.map +1 -0
- package/dist/otp-field/otp-field-context.mjs +13 -0
- package/dist/otp-field/otp-field-context.mjs.map +1 -0
- package/dist/otp-field/otp-field-filter.d.mts +5 -0
- package/dist/otp-field/otp-field-filter.d.mts.map +1 -0
- package/dist/otp-field/otp-field-filter.mjs +135 -0
- package/dist/otp-field/otp-field-filter.mjs.map +1 -0
- package/dist/otp-field/otp-field-input.d.mts +41 -0
- package/dist/otp-field/otp-field-input.d.mts.map +1 -0
- package/dist/otp-field/otp-field-input.mjs +177 -0
- package/dist/otp-field/otp-field-input.mjs.map +1 -0
- package/dist/otp-field/otp-field-root.d.mts +152 -0
- package/dist/otp-field/otp-field-root.d.mts.map +1 -0
- package/dist/otp-field/otp-field-root.mjs +400 -0
- package/dist/otp-field/otp-field-root.mjs.map +1 -0
- package/dist/otp-field/otp-field-slot.d.mts +52 -0
- package/dist/otp-field/otp-field-slot.d.mts.map +1 -0
- package/dist/otp-field/otp-field-slot.mjs +67 -0
- package/dist/otp-field/otp-field-slot.mjs.map +1 -0
- package/dist/popover/index.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/progress/progress-root.d.mts +3 -2
- package/dist/progress/progress-root.d.mts.map +1 -1
- package/dist/progress/progress-root.mjs.map +1 -1
- package/package.json +7 -1
- package/skills/funstack-ui-knowledge/SKILL.md +8 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PopoverTriggerProps, PopoverTriggerState } from "../popover/popover-trigger.mjs";
|
|
2
|
+
//#region src/navigation-menu/navigation-menu-trigger.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* State of `NavigationMenu.Trigger`: Popover.Trigger's (design 6), passed to the function forms
|
|
5
|
+
* of `className`, `style`, `children` and `render`.
|
|
6
|
+
*/
|
|
7
|
+
export type NavigationMenuTriggerState = PopoverTriggerState;
|
|
8
|
+
/**
|
|
9
|
+
* Props of `NavigationMenu.Trigger`: Popover.Trigger's, unchanged (design 6).
|
|
10
|
+
*
|
|
11
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
12
|
+
*/
|
|
13
|
+
export type NavigationMenuTriggerProps = PopoverTriggerProps;
|
|
14
|
+
/**
|
|
15
|
+
* The toggle of one panel: `<button type="button" popovertarget>` with no `aria-expanded` (the
|
|
16
|
+
* browser exposes the popover's state on its invoker). Opens on a click (Enter, Space); never on
|
|
17
|
+
* hover. In JS-free mode the browser toggles the panel and the Popup keeps `data-open` current;
|
|
18
|
+
* in library mode the click is cancelled and dispatched through the Item's transition, with
|
|
19
|
+
* optimistic `data-open` and `data-pending` until the change has landed.
|
|
20
|
+
*
|
|
21
|
+
* Owned keys (conventions 1.2): Popover.Trigger's: `type`, `disabled`, `popoverTarget`,
|
|
22
|
+
* `aria-expanded`, `onClick` (library mode), `data-open`, `data-pending`, `data-disabled`;
|
|
23
|
+
* `commandfor`, `command` and `popoverTargetAction` reserved.
|
|
24
|
+
*
|
|
25
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
26
|
+
*/
|
|
27
|
+
export declare function NavigationMenuTrigger({ disabled, className, style, children, render, ...rest }: NavigationMenuTriggerProps): import("react").ReactNode;
|
|
28
|
+
export declare namespace NavigationMenuTrigger {
|
|
29
|
+
var displayName: string;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//# sourceMappingURL=navigation-menu-trigger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-trigger.d.mts","names":[],"sources":["../../src/navigation-menu/navigation-menu-trigger.tsx"],"mappings":";;;;;;YAWY,6BAA6B;;;;;;YAO7B,6BAA6B;;;;;;;;;;;;;;wBAezB,wBACd,UACA,WACA,OACA,UACA,WACG,QACF,6CAA0B;yBAPb"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
+
import { useNavigationMenuItemContext } from "./navigation-menu-context.mjs";
|
|
4
|
+
import { usePopoverTrigger } from "../internal/overlay/use-popover-trigger.mjs";
|
|
5
|
+
//#region src/navigation-menu/navigation-menu-trigger.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The toggle of one panel: `<button type="button" popovertarget>` with no `aria-expanded` (the
|
|
8
|
+
* browser exposes the popover's state on its invoker). Opens on a click (Enter, Space); never on
|
|
9
|
+
* hover. In JS-free mode the browser toggles the panel and the Popup keeps `data-open` current;
|
|
10
|
+
* in library mode the click is cancelled and dispatched through the Item's transition, with
|
|
11
|
+
* optimistic `data-open` and `data-pending` until the change has landed.
|
|
12
|
+
*
|
|
13
|
+
* Owned keys (conventions 1.2): Popover.Trigger's: `type`, `disabled`, `popoverTarget`,
|
|
14
|
+
* `aria-expanded`, `onClick` (library mode), `data-open`, `data-pending`, `data-disabled`;
|
|
15
|
+
* `commandfor`, `command` and `popoverTargetAction` reserved.
|
|
16
|
+
*
|
|
17
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
18
|
+
*/
|
|
19
|
+
function NavigationMenuTrigger({ disabled = false, className, style, children, render, ...rest }) {
|
|
20
|
+
const ctx = useNavigationMenuItemContext("NavigationMenu.Trigger");
|
|
21
|
+
const { state, libraryProps, ref } = usePopoverTrigger(ctx, {
|
|
22
|
+
part: "NavigationMenu.Trigger",
|
|
23
|
+
disabled,
|
|
24
|
+
render
|
|
25
|
+
});
|
|
26
|
+
return useRender({
|
|
27
|
+
defaultElement: "button",
|
|
28
|
+
render,
|
|
29
|
+
state,
|
|
30
|
+
className,
|
|
31
|
+
style,
|
|
32
|
+
children,
|
|
33
|
+
props: rest,
|
|
34
|
+
libraryProps,
|
|
35
|
+
ref
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
NavigationMenuTrigger.displayName = "NavigationMenuTrigger";
|
|
39
|
+
//#endregion
|
|
40
|
+
export { NavigationMenuTrigger };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=navigation-menu-trigger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-trigger.mjs","names":[],"sources":["../../src/navigation-menu/navigation-menu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef } from \"react\";\nimport { usePopoverTrigger } from \"../internal/overlay/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { PopoverTriggerProps, PopoverTriggerState } from \"../popover/popover-trigger.js\";\nimport { useNavigationMenuItemContext } from \"./navigation-menu-context.js\";\n\n/**\n * State of `NavigationMenu.Trigger`: Popover.Trigger's (design 6), passed to the function forms\n * of `className`, `style`, `children` and `render`.\n */\nexport type NavigationMenuTriggerState = PopoverTriggerState;\n\n/**\n * Props of `NavigationMenu.Trigger`: Popover.Trigger's, unchanged (design 6).\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport type NavigationMenuTriggerProps = PopoverTriggerProps;\n\n/**\n * The toggle of one panel: `<button type=\"button\" popovertarget>` with no `aria-expanded` (the\n * browser exposes the popover's state on its invoker). Opens on a click (Enter, Space); never on\n * hover. In JS-free mode the browser toggles the panel and the Popup keeps `data-open` current;\n * in library mode the click is cancelled and dispatched through the Item's transition, with\n * optimistic `data-open` and `data-pending` until the change has landed.\n *\n * Owned keys (conventions 1.2): Popover.Trigger's: `type`, `disabled`, `popoverTarget`,\n * `aria-expanded`, `onClick` (library mode), `data-open`, `data-pending`, `data-disabled`;\n * `commandfor`, `command` and `popoverTargetAction` reserved.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport function NavigationMenuTrigger({\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: NavigationMenuTriggerProps) {\n const ctx = useNavigationMenuItemContext(\"NavigationMenu.Trigger\");\n const { state, libraryProps, ref } = usePopoverTrigger(ctx, {\n part: \"NavigationMenu.Trigger\",\n disabled,\n render,\n });\n\n return useRender<ComponentPropsWithRef<\"button\">, NavigationMenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nNavigationMenuTrigger.displayName = \"NavigationMenuTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,SAAgB,sBAAsB,EACpC,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QAC0B;CAC7B,MAAM,MAAM,6BAA6B,wBAAwB;CACjE,MAAM,EAAE,OAAO,cAAc,QAAQ,kBAAkB,KAAK;EAC1D,MAAM;EACN;EACA;CACF,CAAC;CAED,OAAO,UAAuE;EAC5E,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,sBAAsB,cAAc"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OTPFieldCharset } from "./otp-field-filter.mjs";
|
|
2
|
+
import { OTPFieldCompleteDetails, OTPFieldRoot, OTPFieldRootProps, OTPFieldState, OTPFieldValueChangeDetails } from "./otp-field-root.mjs";
|
|
3
|
+
import { OTPFieldInput, OTPFieldInputProps } from "./otp-field-input.mjs";
|
|
4
|
+
import { OTPFieldSlot, OTPFieldSlotProps, OTPFieldSlotState } from "./otp-field-slot.mjs";
|
|
5
|
+
//#region src/otp-field/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* OTPField: a field for a short code the user received elsewhere (an SMS or email code, an
|
|
8
|
+
* authenticator's digits, a PIN). `Root` (`div`, owns the text) > `Input` (the one
|
|
9
|
+
* `<input autocomplete="one-time-code">`, covering the Root with transparent text) + `Slot`s
|
|
10
|
+
* (`aria-hidden` spans that draw one character each, `data-filled`, `data-active`). The text is
|
|
11
|
+
* urgent (`value` / `defaultValue` / `onValueChange`); a complete code runs `completeAction` in the
|
|
12
|
+
* Root's transition with `data-pending`, and `submitOnComplete` submits the Input's form.
|
|
13
|
+
*
|
|
14
|
+
* @see https://ui.funstack.work/components/otp-field
|
|
15
|
+
*/
|
|
16
|
+
export declare const OTPField: {
|
|
17
|
+
readonly Root: typeof OTPFieldRoot;
|
|
18
|
+
readonly Input: typeof OTPFieldInput;
|
|
19
|
+
readonly Slot: typeof OTPFieldSlot;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export type { OTPFieldCharset, OTPFieldCompleteDetails, OTPFieldInputProps, OTPFieldRootProps, OTPFieldSlotProps, OTPFieldSlotState, OTPFieldState, OTPFieldValueChangeDetails };
|
|
23
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/otp-field/index.ts"],"mappings":";;;;;;;;;;;;;;;qBAca;WACX,aAAI;WACJ,cAAK;WACL,aAAI"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OTPFieldInput } from "./otp-field-input.mjs";
|
|
2
|
+
import { OTPFieldRoot } from "./otp-field-root.mjs";
|
|
3
|
+
import { OTPFieldSlot } from "./otp-field-slot.mjs";
|
|
4
|
+
//#region src/otp-field/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* OTPField: a field for a short code the user received elsewhere (an SMS or email code, an
|
|
7
|
+
* authenticator's digits, a PIN). `Root` (`div`, owns the text) > `Input` (the one
|
|
8
|
+
* `<input autocomplete="one-time-code">`, covering the Root with transparent text) + `Slot`s
|
|
9
|
+
* (`aria-hidden` spans that draw one character each, `data-filled`, `data-active`). The text is
|
|
10
|
+
* urgent (`value` / `defaultValue` / `onValueChange`); a complete code runs `completeAction` in the
|
|
11
|
+
* Root's transition with `data-pending`, and `submitOnComplete` submits the Input's form.
|
|
12
|
+
*
|
|
13
|
+
* @see https://ui.funstack.work/components/otp-field
|
|
14
|
+
*/
|
|
15
|
+
const OTPField = {
|
|
16
|
+
Root: OTPFieldRoot,
|
|
17
|
+
Input: OTPFieldInput,
|
|
18
|
+
Slot: OTPFieldSlot
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { OTPField };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/otp-field/index.ts"],"sourcesContent":["import { OTPFieldInput } from \"./otp-field-input.js\";\nimport { OTPFieldRoot } from \"./otp-field-root.js\";\nimport { OTPFieldSlot } from \"./otp-field-slot.js\";\n\n/**\n * OTPField: a field for a short code the user received elsewhere (an SMS or email code, an\n * authenticator's digits, a PIN). `Root` (`div`, owns the text) > `Input` (the one\n * `<input autocomplete=\"one-time-code\">`, covering the Root with transparent text) + `Slot`s\n * (`aria-hidden` spans that draw one character each, `data-filled`, `data-active`). The text is\n * urgent (`value` / `defaultValue` / `onValueChange`); a complete code runs `completeAction` in the\n * Root's transition with `data-pending`, and `submitOnComplete` submits the Input's form.\n *\n * @see https://ui.funstack.work/components/otp-field\n */\nexport const OTPField = {\n Root: OTPFieldRoot,\n Input: OTPFieldInput,\n Slot: OTPFieldSlot,\n} as const;\n\nexport type {\n OTPFieldRootProps,\n OTPFieldState,\n OTPFieldValueChangeDetails,\n OTPFieldCompleteDetails,\n} from \"./otp-field-root.js\";\nexport type { OTPFieldInputProps } from \"./otp-field-input.js\";\nexport type { OTPFieldSlotProps, OTPFieldSlotState } from \"./otp-field-slot.js\";\nexport type { OTPFieldCharset } from \"./otp-field-filter.js\";\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,WAAW;CACtB,MAAM;CACN,OAAO;CACP,MAAM;AACR"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, use } from "react";
|
|
3
|
+
//#region src/otp-field/otp-field-context.ts
|
|
4
|
+
const OTPFieldContext = createContext(null);
|
|
5
|
+
function useOTPFieldContext(part) {
|
|
6
|
+
const context = use(OTPFieldContext);
|
|
7
|
+
if (context === null) throw new Error(`${part} must be rendered inside an OTPField.Root.`);
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { OTPFieldContext, useOTPFieldContext };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=otp-field-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp-field-context.mjs","names":[],"sources":["../../src/otp-field/otp-field-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { ChangeEvent, RefObject } from \"react\";\nimport type { OTPFieldCharset } from \"./otp-field-filter.js\";\nimport type { OTPFieldState } from \"./otp-field-root.js\";\n\nexport interface OTPFieldContextValue {\n /** The state every part's function props receive. */\n readonly state: OTPFieldState;\n readonly charset: OTPFieldCharset;\n /** Own `name` ?? the Field's. */\n readonly name: string | undefined;\n readonly form: string | undefined;\n /** Own `required` || the Field's. */\n readonly required: boolean;\n /** Inside a `Field.Root`: whether an error is shown. `undefined` outside a Field. */\n readonly fieldInvalid: boolean | undefined;\n /** The text the Input renders: the raw text while a composition is open, else the value. */\n readonly inputText: string;\n /** The active slots, `[from, to)` (design 4.3). */\n readonly active: readonly [from: number, to: number];\n readonly experimentalWebOTP: boolean;\n /** The Input element. */\n readonly inputRef: RefObject<HTMLInputElement | null>;\n /** The Input's `onChange`: the filter of design 4.1. */\n readonly change: (event: ChangeEvent<HTMLInputElement>) => void;\n /** The Input's native listeners (installed by the Input on its element). */\n readonly beforeInput: (event: InputEvent) => void;\n readonly compositionStart: () => void;\n readonly compositionEnd: (event: CompositionEvent) => void;\n readonly selectionChanged: () => void;\n readonly blurred: () => void;\n readonly click: (event: MouseEvent) => void;\n /** The Input's mount: adopts text typed, autofilled or restored before hydration (design 9). */\n readonly inputMounted: () => void;\n /** A WebOTP credential's code (design 8). */\n readonly webOTPCode: (code: string) => void;\n /** The pending WebOTP request, aborted when the code is completed by hand. */\n readonly webOTPAbort: RefObject<AbortController | null>;\n /** A completion happened: no WebOTP request starts any more (design 8). */\n readonly webOTPDone: RefObject<boolean>;\n /** Registers a Slot's element under its index; returns the cleanup. */\n readonly registerSlot: (index: number, element: HTMLElement) => () => void;\n}\n\nexport const OTPFieldContext = createContext<OTPFieldContextValue | null>(null);\n\nexport function useOTPFieldContext(part: string): OTPFieldContextValue {\n const context = use(OTPFieldContext);\n if (context === null) throw new Error(`${part} must be rendered inside an OTPField.Root.`);\n return context;\n}\n"],"mappings":";;;AA6CA,MAAa,kBAAkB,cAA2C,IAAI;AAE9E,SAAgB,mBAAmB,MAAoC;CACrE,MAAM,UAAU,IAAI,eAAe;CACnC,IAAI,YAAY,MAAM,MAAM,IAAI,MAAM,GAAG,KAAK,2CAA2C;CACzF,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp-field-filter.d.mts","names":[],"sources":["../../src/otp-field/otp-field-filter.ts"],"mappings":";;YAIY"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
//#region src/otp-field/otp-field-filter.ts
|
|
2
|
+
const CHARSETS = {
|
|
3
|
+
numeric: {
|
|
4
|
+
test: /^[0-9]$/,
|
|
5
|
+
inputMode: "numeric",
|
|
6
|
+
pattern: "[0-9]"
|
|
7
|
+
},
|
|
8
|
+
alphanumeric: {
|
|
9
|
+
test: /^[A-Za-z0-9]$/,
|
|
10
|
+
inputMode: "text",
|
|
11
|
+
pattern: "[A-Za-z0-9]"
|
|
12
|
+
},
|
|
13
|
+
alphabetic: {
|
|
14
|
+
test: /^[A-Za-z]$/,
|
|
15
|
+
inputMode: "text",
|
|
16
|
+
pattern: "[A-Za-z]"
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function rule(charset) {
|
|
20
|
+
return CHARSETS[charset] ?? CHARSETS.numeric;
|
|
21
|
+
}
|
|
22
|
+
/** `inputmode` for a charset: `numeric` for digits, `text` otherwise. */
|
|
23
|
+
function charsetInputMode(charset) {
|
|
24
|
+
return rule(charset).inputMode;
|
|
25
|
+
}
|
|
26
|
+
/** The derived `pattern`: `[0-9]{6}` for six digits. */
|
|
27
|
+
function charsetPattern(charset, length) {
|
|
28
|
+
return `${rule(charset).pattern}{${length}}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Keeps the characters of `charset` in `text`, in order. Full-width digits (U+FF10 to U+FF19,
|
|
32
|
+
* what a Japanese or Chinese IME types) are converted to ASCII for `"numeric"` (section 3).
|
|
33
|
+
* Letters keep their case.
|
|
34
|
+
*/
|
|
35
|
+
function filterChars(text, charset) {
|
|
36
|
+
const { test } = rule(charset);
|
|
37
|
+
const numeric = charset === "numeric";
|
|
38
|
+
let kept = "";
|
|
39
|
+
for (const raw of text) {
|
|
40
|
+
let char = raw;
|
|
41
|
+
if (numeric) {
|
|
42
|
+
const code = raw.codePointAt(0);
|
|
43
|
+
if (code >= 65296 && code <= 65305) char = String.fromCharCode(code - 65296 + 48);
|
|
44
|
+
}
|
|
45
|
+
if (test.test(char)) kept += char;
|
|
46
|
+
}
|
|
47
|
+
return kept;
|
|
48
|
+
}
|
|
49
|
+
/** `filterChars`, cut to `length`: what a value may hold. */
|
|
50
|
+
function normalizeCode(text, charset, length) {
|
|
51
|
+
return filterChars(text, charset).slice(0, Math.max(0, length));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Applies one `input` event to the value (design/components/otp-field.md 4.1). The browser has
|
|
55
|
+
* already edited the text; this computes what the filtered text and the caret should be:
|
|
56
|
+
*
|
|
57
|
+
* 1. the inserted run is what the browser put between the kept prefix and suffix of the text
|
|
58
|
+
* before the edit, filtered by `charset`;
|
|
59
|
+
* 2. a run of `length` characters or more replaces everything (a pasted full code);
|
|
60
|
+
* 3. a selected range is replaced by the run;
|
|
61
|
+
* 4. a collapsed caret overtypes: the run replaces as many characters as it has;
|
|
62
|
+
* 5. a complete code with the caret at its end treats the last position as the caret's;
|
|
63
|
+
* 6. a deletion, and an `input` with no `beforeinput`, is `filter(dom)`;
|
|
64
|
+
* 7. the result is cut to `length`, the caret goes after the run.
|
|
65
|
+
*
|
|
66
|
+
* An insertion the filter dropped entirely leaves the value as it was and restores the
|
|
67
|
+
* selection (section 4.2: "no feedback beyond the text not changing").
|
|
68
|
+
*/
|
|
69
|
+
function applyEdit(input) {
|
|
70
|
+
const { before, dom, caret, inputType, charset, length } = input;
|
|
71
|
+
const insertion = inputType.startsWith("insert");
|
|
72
|
+
const fallback = () => {
|
|
73
|
+
const value = normalizeCode(dom, charset, length);
|
|
74
|
+
return {
|
|
75
|
+
value,
|
|
76
|
+
caret: caret === null ? null : Math.min(filterChars(dom.slice(0, caret), charset).length, value.length),
|
|
77
|
+
kept: 0,
|
|
78
|
+
selection: null
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
if (before === null || !insertion) return fallback();
|
|
82
|
+
const { text, selectionStart, selectionEnd } = before;
|
|
83
|
+
let start = Math.min(selectionStart, selectionEnd);
|
|
84
|
+
let end = Math.max(selectionStart, selectionEnd);
|
|
85
|
+
const prefix = text.slice(0, start);
|
|
86
|
+
const suffix = text.slice(end);
|
|
87
|
+
if (dom.length < prefix.length + suffix.length || !dom.startsWith(prefix) || !dom.endsWith(suffix)) return fallback();
|
|
88
|
+
const kept = filterChars(dom.slice(start, dom.length - suffix.length), charset);
|
|
89
|
+
if (kept.length === 0) {
|
|
90
|
+
const value = normalizeCode(text, charset, length);
|
|
91
|
+
return {
|
|
92
|
+
value,
|
|
93
|
+
caret: null,
|
|
94
|
+
kept: 0,
|
|
95
|
+
selection: [Math.min(start, value.length), Math.min(end, value.length)]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (kept.length >= length) return {
|
|
99
|
+
value: kept.slice(0, length),
|
|
100
|
+
caret: length,
|
|
101
|
+
kept: kept.length,
|
|
102
|
+
selection: null
|
|
103
|
+
};
|
|
104
|
+
const base = normalizeCode(text, charset, length);
|
|
105
|
+
start = Math.min(start, base.length);
|
|
106
|
+
end = Math.min(end, base.length);
|
|
107
|
+
let next;
|
|
108
|
+
if (start !== end) next = base.slice(0, start) + kept + base.slice(end);
|
|
109
|
+
else {
|
|
110
|
+
if (base.length >= length && start >= length) start = length - 1;
|
|
111
|
+
next = base.slice(0, start) + kept + base.slice(start + kept.length);
|
|
112
|
+
}
|
|
113
|
+
next = next.slice(0, length);
|
|
114
|
+
return {
|
|
115
|
+
value: next,
|
|
116
|
+
caret: Math.min(start + kept.length, length),
|
|
117
|
+
kept: kept.length,
|
|
118
|
+
selection: null
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** The active slots for a selection (section 4.3): `[from, to)`, empty when not focused. */
|
|
122
|
+
function activeRange(focused, selectionStart, selectionEnd, length) {
|
|
123
|
+
if (!focused || selectionStart === null || length <= 0) return [0, 0];
|
|
124
|
+
const start = Math.min(selectionStart, selectionEnd ?? selectionStart);
|
|
125
|
+
const end = Math.max(selectionStart, selectionEnd ?? selectionStart);
|
|
126
|
+
if (start === end) {
|
|
127
|
+
const slot = Math.min(start, length - 1);
|
|
128
|
+
return [slot, slot + 1];
|
|
129
|
+
}
|
|
130
|
+
return [Math.min(start, length), Math.min(end, length)];
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { activeRange, applyEdit, charsetInputMode, charsetPattern, filterChars, normalizeCode };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=otp-field-filter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp-field-filter.mjs","names":[],"sources":["../../src/otp-field/otp-field-filter.ts"],"sourcesContent":["// Directive-free: the pure filter of an OTPField (design/components/otp-field.md 4.1) and the\n// `charset` table (section 3). No hook, no DOM.\n\n/** Which characters a code may contain (design/components/otp-field.md 3). */\nexport type OTPFieldCharset = \"numeric\" | \"alphanumeric\" | \"alphabetic\";\n\ninterface CharsetRule {\n /** One kept character, after the full-width conversion. */\n readonly test: RegExp;\n readonly inputMode: \"numeric\" | \"text\";\n /** The `pattern` character class. */\n readonly pattern: string;\n}\n\nconst CHARSETS: Record<OTPFieldCharset, CharsetRule> = {\n numeric: { test: /^[0-9]$/, inputMode: \"numeric\", pattern: \"[0-9]\" },\n alphanumeric: { test: /^[A-Za-z0-9]$/, inputMode: \"text\", pattern: \"[A-Za-z0-9]\" },\n alphabetic: { test: /^[A-Za-z]$/, inputMode: \"text\", pattern: \"[A-Za-z]\" },\n};\n\nfunction rule(charset: OTPFieldCharset): CharsetRule {\n return CHARSETS[charset] ?? CHARSETS.numeric;\n}\n\n/** `inputmode` for a charset: `numeric` for digits, `text` otherwise. */\nexport function charsetInputMode(charset: OTPFieldCharset): \"numeric\" | \"text\" {\n return rule(charset).inputMode;\n}\n\n/** The derived `pattern`: `[0-9]{6}` for six digits. */\nexport function charsetPattern(charset: OTPFieldCharset, length: number): string {\n return `${rule(charset).pattern}{${length}}`;\n}\n\n/**\n * Keeps the characters of `charset` in `text`, in order. Full-width digits (U+FF10 to U+FF19,\n * what a Japanese or Chinese IME types) are converted to ASCII for `\"numeric\"` (section 3).\n * Letters keep their case.\n */\nexport function filterChars(text: string, charset: OTPFieldCharset): string {\n const { test } = rule(charset);\n const numeric = charset === \"numeric\";\n let kept = \"\";\n for (const raw of text) {\n let char = raw;\n if (numeric) {\n const code = raw.codePointAt(0)!;\n if (code >= 0xff10 && code <= 0xff19) char = String.fromCharCode(code - 0xff10 + 48);\n }\n if (test.test(char)) kept += char;\n }\n return kept;\n}\n\n/** `filterChars`, cut to `length`: what a value may hold. */\nexport function normalizeCode(text: string, charset: OTPFieldCharset, length: number): string {\n return filterChars(text, charset).slice(0, Math.max(0, length));\n}\n\n/** The input's text and selection when `beforeinput` fired. */\nexport interface EditBefore {\n readonly text: string;\n readonly selectionStart: number;\n readonly selectionEnd: number;\n}\n\nexport interface EditInput {\n /** The record from `beforeinput`; `null` when no `beforeinput` preceded the `input` (rule 6). */\n readonly before: EditBefore | null;\n /** The input's text after the browser's edit. */\n readonly dom: string;\n /** The input's `selectionStart` after the browser's edit (`null`: unknown). */\n readonly caret: number | null;\n /** `InputEvent.inputType` (`\"\"` when unknown). */\n readonly inputType: string;\n readonly charset: OTPFieldCharset;\n readonly length: number;\n}\n\nexport interface EditResult {\n /** The filtered value. */\n readonly value: string;\n /** Where the caret goes (collapsed), or `null` for \"where the browser left it\". */\n readonly caret: number | null;\n /**\n * Characters the edit inserted and the filter kept: `0` for a deletion and for an insertion\n * the filter dropped entirely (a letter typed into a numeric field). Completion runs only for\n * an edit that kept something or changed the value.\n */\n readonly kept: number;\n /** The selection to restore when the edit was dropped entirely: the one before it. */\n readonly selection: readonly [start: number, end: number] | null;\n}\n\n/**\n * Applies one `input` event to the value (design/components/otp-field.md 4.1). The browser has\n * already edited the text; this computes what the filtered text and the caret should be:\n *\n * 1. the inserted run is what the browser put between the kept prefix and suffix of the text\n * before the edit, filtered by `charset`;\n * 2. a run of `length` characters or more replaces everything (a pasted full code);\n * 3. a selected range is replaced by the run;\n * 4. a collapsed caret overtypes: the run replaces as many characters as it has;\n * 5. a complete code with the caret at its end treats the last position as the caret's;\n * 6. a deletion, and an `input` with no `beforeinput`, is `filter(dom)`;\n * 7. the result is cut to `length`, the caret goes after the run.\n *\n * An insertion the filter dropped entirely leaves the value as it was and restores the\n * selection (section 4.2: \"no feedback beyond the text not changing\").\n */\nexport function applyEdit(input: EditInput): EditResult {\n const { before, dom, caret, inputType, charset, length } = input;\n const insertion = inputType.startsWith(\"insert\");\n\n const fallback = (): EditResult => {\n const value = normalizeCode(dom, charset, length);\n // The caret keeps its place among the characters the filter kept before it.\n const at =\n caret === null\n ? null\n : Math.min(filterChars(dom.slice(0, caret), charset).length, value.length);\n return { value, caret: at, kept: 0, selection: null };\n };\n\n if (before === null || !insertion) return fallback();\n\n const { text, selectionStart, selectionEnd } = before;\n let start = Math.min(selectionStart, selectionEnd);\n let end = Math.max(selectionStart, selectionEnd);\n const prefix = text.slice(0, start);\n const suffix = text.slice(end);\n // Rule 1: the browser replaced [start, end) with the run; anything else (an engine that edits\n // elsewhere) falls back to rule 6.\n if (\n dom.length < prefix.length + suffix.length ||\n !dom.startsWith(prefix) ||\n !dom.endsWith(suffix)\n ) {\n return fallback();\n }\n const run = dom.slice(start, dom.length - suffix.length);\n const kept = filterChars(run, charset);\n\n if (kept.length === 0) {\n // Dropped entirely: the text before the edit, the selection where it was.\n const value = normalizeCode(text, charset, length);\n return {\n value,\n caret: null,\n kept: 0,\n selection: [Math.min(start, value.length), Math.min(end, value.length)],\n };\n }\n\n // Rule 2: a full code replaces everything.\n if (kept.length >= length) {\n return { value: kept.slice(0, length), caret: length, kept: kept.length, selection: null };\n }\n\n const base = normalizeCode(text, charset, length);\n start = Math.min(start, base.length);\n end = Math.min(end, base.length);\n let next: string;\n if (start !== end) {\n // Rule 3: the selected range is replaced.\n next = base.slice(0, start) + kept + base.slice(end);\n } else {\n // Rule 5: at the end of a complete code the last position is the caret's.\n if (base.length >= length && start >= length) start = length - 1;\n // Rule 4: overtype.\n next = base.slice(0, start) + kept + base.slice(start + kept.length);\n }\n next = next.slice(0, length);\n return {\n value: next,\n caret: Math.min(start + kept.length, length),\n kept: kept.length,\n selection: null,\n };\n}\n\n/** The active slots for a selection (section 4.3): `[from, to)`, empty when not focused. */\nexport function activeRange(\n focused: boolean,\n selectionStart: number | null,\n selectionEnd: number | null,\n length: number,\n): readonly [from: number, to: number] {\n if (!focused || selectionStart === null || length <= 0) return [0, 0];\n const start = Math.min(selectionStart, selectionEnd ?? selectionStart);\n const end = Math.max(selectionStart, selectionEnd ?? selectionStart);\n if (start === end) {\n const slot = Math.min(start, length - 1);\n return [slot, slot + 1];\n }\n return [Math.min(start, length), Math.min(end, length)];\n}\n"],"mappings":";AAcA,MAAM,WAAiD;CACrD,SAAS;EAAE,MAAM;EAAW,WAAW;EAAW,SAAS;CAAQ;CACnE,cAAc;EAAE,MAAM;EAAiB,WAAW;EAAQ,SAAS;CAAc;CACjF,YAAY;EAAE,MAAM;EAAc,WAAW;EAAQ,SAAS;CAAW;AAC3E;AAEA,SAAS,KAAK,SAAuC;CACnD,OAAO,SAAS,YAAY,SAAS;AACvC;;AAGA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O,CAAC,GAAG,CAAC;CACpE,MAAM,QAAQ,KAAK,IAAI,gBAAgB,gBAAgB,cAAc;CACrE,MAAM,MAAM,KAAK,IAAI,gBAAgB,gBAAgB,cAAc;CACnE,IAAI,UAAU,KAAK;EACjB,MAAM,OAAO,KAAK,IAAI,OAAO,SAAS,CAAC;EACvC,OAAO,CAAC,MAAM,OAAO,CAAC;CACxB;CACA,OAAO,CAAC,KAAK,IAAI,OAAO,MAAM,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC;AACxD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { OTPFieldState } from "./otp-field-root.mjs";
|
|
3
|
+
import { CSSProperties, ComponentPropsWithRef } from "react";
|
|
4
|
+
//#region src/otp-field/otp-field-input.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props of `OTPField.Input`.
|
|
7
|
+
*
|
|
8
|
+
* @see https://ui.funstack.work/components/otp-field
|
|
9
|
+
*/
|
|
10
|
+
export interface OTPFieldInputProps extends Omit<ComponentPropsWithRef<"input">, "type" | "value" | "defaultValue" | "maxLength" | "minLength" | "pattern" | "name" | "form" | "required" | "disabled" | "readOnly" | "onChange" | "className" | "style" | "children"> {
|
|
11
|
+
/** Class name, or a function of the state that returns one. */
|
|
12
|
+
className?: StateValue<string | undefined, OTPFieldState>;
|
|
13
|
+
/**
|
|
14
|
+
* Inline style, or a function of the state that returns one. The library's own inline style
|
|
15
|
+
* (the Input covers the Root with transparent text) wins over these keys.
|
|
16
|
+
*/
|
|
17
|
+
style?: StateValue<CSSProperties | undefined, OTPFieldState>;
|
|
18
|
+
/** Must render an `<input>`. */
|
|
19
|
+
render?: RenderProp<ComponentPropsWithRef<"input">, OTPFieldState>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The one text input of an OTPField (design/components/otp-field.md 1, 4): `type="text"`,
|
|
23
|
+
* `autocomplete="one-time-code"`, `inputmode` and `pattern` from the Root's `charset`, covering
|
|
24
|
+
* the Root with transparent text. The only focusable and the only element assistive technology
|
|
25
|
+
* sees. Registers with an enclosing `Field.Root` as `Field.Control` does.
|
|
26
|
+
*
|
|
27
|
+
* Owned keys (conventions 1.2): `type`, `value`, `pattern`, `name`, `form`, `required`,
|
|
28
|
+
* `disabled`, `readOnly`, `onChange` (and the library's native `beforeinput`, composition,
|
|
29
|
+
* selection and click listeners), the inline style above, the Field's `id`, `aria-describedby`
|
|
30
|
+
* (token-merged) and `aria-invalid`, `data-complete`, `data-pending`, `data-disabled`,
|
|
31
|
+
* `data-invalid`. Defaults the consumer's own prop replaces: `autoComplete="one-time-code"`,
|
|
32
|
+
* `inputMode`, `autoCapitalize="off"`, `autoCorrect="off"`, `spellCheck={false}`.
|
|
33
|
+
*
|
|
34
|
+
* @see https://ui.funstack.work/components/otp-field
|
|
35
|
+
*/
|
|
36
|
+
export declare function OTPFieldInput({ className, style, render, ...rest }: OTPFieldInputProps): import("react").ReactNode;
|
|
37
|
+
export declare namespace OTPFieldInput {
|
|
38
|
+
var displayName: string;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//# sourceMappingURL=otp-field-input.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp-field-input.d.mts","names":[],"sources":["../../src/otp-field/otp-field-input.tsx"],"mappings":";;;;;;;;;iBAuBiB,2BAA2B,KAC1C;;EAkBA,YAAY,+BAA+B;;;;;EAK3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,gCAAgC;;;;;;;;;;;;;;;;;wBAyCtC,gBAAgB,WAAW,OAAO,WAAW,QAAQ,qCAAkB;yBAAvE"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
4
|
+
import { useLatest } from "../internal/use-latest.mjs";
|
|
5
|
+
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
6
|
+
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
7
|
+
import { useFieldControl } from "../internal/form/use-field-control.mjs";
|
|
8
|
+
import { useFormOwnerEvent } from "../internal/form/use-form-owner-event.mjs";
|
|
9
|
+
import { useOTPFieldContext } from "./otp-field-context.mjs";
|
|
10
|
+
import { charsetInputMode, charsetPattern } from "./otp-field-filter.mjs";
|
|
11
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
|
|
12
|
+
//#region src/otp-field/otp-field-input.tsx
|
|
13
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
14
|
+
/**
|
|
15
|
+
* The Input covers the Root with transparent text and caret (design 6). Functional, owned; the
|
|
16
|
+
* outline is left to the consumer. Provisional until the device probes are done (changelog).
|
|
17
|
+
*/
|
|
18
|
+
const INPUT_STYLE = {
|
|
19
|
+
position: "absolute",
|
|
20
|
+
inset: 0,
|
|
21
|
+
inlineSize: "100%",
|
|
22
|
+
blockSize: "100%",
|
|
23
|
+
margin: 0,
|
|
24
|
+
padding: 0,
|
|
25
|
+
border: 0,
|
|
26
|
+
background: "transparent",
|
|
27
|
+
color: "transparent",
|
|
28
|
+
caretColor: "transparent",
|
|
29
|
+
forcedColorAdjust: "none"
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The one text input of an OTPField (design/components/otp-field.md 1, 4): `type="text"`,
|
|
33
|
+
* `autocomplete="one-time-code"`, `inputmode` and `pattern` from the Root's `charset`, covering
|
|
34
|
+
* the Root with transparent text. The only focusable and the only element assistive technology
|
|
35
|
+
* sees. Registers with an enclosing `Field.Root` as `Field.Control` does.
|
|
36
|
+
*
|
|
37
|
+
* Owned keys (conventions 1.2): `type`, `value`, `pattern`, `name`, `form`, `required`,
|
|
38
|
+
* `disabled`, `readOnly`, `onChange` (and the library's native `beforeinput`, composition,
|
|
39
|
+
* selection and click listeners), the inline style above, the Field's `id`, `aria-describedby`
|
|
40
|
+
* (token-merged) and `aria-invalid`, `data-complete`, `data-pending`, `data-disabled`,
|
|
41
|
+
* `data-invalid`. Defaults the consumer's own prop replaces: `autoComplete="one-time-code"`,
|
|
42
|
+
* `inputMode`, `autoCapitalize="off"`, `autoCorrect="off"`, `spellCheck={false}`.
|
|
43
|
+
*
|
|
44
|
+
* @see https://ui.funstack.work/components/otp-field
|
|
45
|
+
*/
|
|
46
|
+
function OTPFieldInput({ className, style, render, ...rest }) {
|
|
47
|
+
const ctx = useOTPFieldContext("OTPField.Input");
|
|
48
|
+
const { state, inputRef, experimentalWebOTP, webOTPAbort } = ctx;
|
|
49
|
+
const field = useFieldControl({
|
|
50
|
+
labelable: true,
|
|
51
|
+
name: ctx.name,
|
|
52
|
+
disabled: state.disabled,
|
|
53
|
+
required: ctx.required,
|
|
54
|
+
id: rest.id,
|
|
55
|
+
component: "OTPField.Input"
|
|
56
|
+
});
|
|
57
|
+
const checkElement = useElementCheck(isDev && ((element) => element.tagName !== "INPUT" ? `OTPField.Input: rendered <${element.tagName.toLowerCase()}>. Render an <input>: the field's text, autofill and form value live in it.` : null));
|
|
58
|
+
const libraryRef = useCallback((element) => {
|
|
59
|
+
checkElement?.(element);
|
|
60
|
+
inputRef.current = element;
|
|
61
|
+
return () => {
|
|
62
|
+
if (inputRef.current === element) inputRef.current = null;
|
|
63
|
+
};
|
|
64
|
+
}, [checkElement, inputRef]);
|
|
65
|
+
const ref = useMergedRefs(libraryRef, field.ref);
|
|
66
|
+
const { beforeInput, compositionStart, compositionEnd, selectionChanged, blurred, click, inputMounted, webOTPCode } = ctx;
|
|
67
|
+
useLayoutEffect(() => {
|
|
68
|
+
const input = inputRef.current;
|
|
69
|
+
if (input === null) return;
|
|
70
|
+
const listeners = [
|
|
71
|
+
["beforeinput", beforeInput],
|
|
72
|
+
["compositionstart", compositionStart],
|
|
73
|
+
["compositionend", compositionEnd],
|
|
74
|
+
["selectionchange", selectionChanged],
|
|
75
|
+
["select", selectionChanged],
|
|
76
|
+
["focus", selectionChanged],
|
|
77
|
+
["keyup", selectionChanged],
|
|
78
|
+
["blur", blurred],
|
|
79
|
+
["click", click]
|
|
80
|
+
];
|
|
81
|
+
for (const [type, listener] of listeners) input.addEventListener(type, listener);
|
|
82
|
+
selectionChanged();
|
|
83
|
+
return () => {
|
|
84
|
+
for (const [type, listener] of listeners) input.removeEventListener(type, listener);
|
|
85
|
+
};
|
|
86
|
+
}, [
|
|
87
|
+
inputRef,
|
|
88
|
+
beforeInput,
|
|
89
|
+
compositionStart,
|
|
90
|
+
compositionEnd,
|
|
91
|
+
selectionChanged,
|
|
92
|
+
blurred,
|
|
93
|
+
click
|
|
94
|
+
]);
|
|
95
|
+
const mounted = useRef(false);
|
|
96
|
+
useLayoutEffect(() => {
|
|
97
|
+
if (mounted.current) return;
|
|
98
|
+
mounted.current = true;
|
|
99
|
+
inputMounted();
|
|
100
|
+
}, [inputMounted]);
|
|
101
|
+
const webOTPCodeRef = useLatest(webOTPCode);
|
|
102
|
+
const { webOTPDone } = ctx;
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!experimentalWebOTP || !("OTPCredential" in window) || webOTPDone.current) return;
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
webOTPAbort.current = controller;
|
|
107
|
+
const request = {
|
|
108
|
+
otp: { transport: ["sms"] },
|
|
109
|
+
signal: controller.signal
|
|
110
|
+
};
|
|
111
|
+
navigator.credentials.get(request).then((credential) => {
|
|
112
|
+
if (controller.signal.aborted) return;
|
|
113
|
+
const code = credential?.code;
|
|
114
|
+
if (typeof code === "string") webOTPCodeRef.current(code);
|
|
115
|
+
}, () => {});
|
|
116
|
+
return () => {
|
|
117
|
+
controller.abort();
|
|
118
|
+
if (webOTPAbort.current === controller) webOTPAbort.current = null;
|
|
119
|
+
};
|
|
120
|
+
}, [
|
|
121
|
+
experimentalWebOTP,
|
|
122
|
+
webOTPAbort,
|
|
123
|
+
webOTPDone,
|
|
124
|
+
webOTPCodeRef
|
|
125
|
+
]);
|
|
126
|
+
useFormOwnerEvent(inputRef, "submit", () => {
|
|
127
|
+
webOTPAbort.current?.abort();
|
|
128
|
+
webOTPAbort.current = null;
|
|
129
|
+
});
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!isDev) return;
|
|
132
|
+
const input = inputRef.current;
|
|
133
|
+
if (input === null) return;
|
|
134
|
+
if (!((input.labels?.length ?? 0) > 0 || (input.getAttribute("aria-label") ?? "").trim() !== "" || (input.getAttribute("aria-labelledby") ?? "").trim() !== "")) console.error("OTPField.Input: the input has no accessible name. Associate a <label for>, use Field.Label, or give it aria-label / aria-labelledby.");
|
|
135
|
+
}, []);
|
|
136
|
+
const dataInvalid = ctx.fieldInvalid === void 0 ? {} : { "data-invalid": dataAttr(ctx.fieldInvalid) };
|
|
137
|
+
const libraryProps = {
|
|
138
|
+
...field.attributes,
|
|
139
|
+
type: "text",
|
|
140
|
+
value: ctx.inputText,
|
|
141
|
+
pattern: charsetPattern(ctx.charset, state.length),
|
|
142
|
+
name: field.name,
|
|
143
|
+
form: ctx.form,
|
|
144
|
+
required: field.required,
|
|
145
|
+
disabled: field.disabled,
|
|
146
|
+
readOnly: state.readOnly,
|
|
147
|
+
onChange: ctx.change,
|
|
148
|
+
style: INPUT_STYLE,
|
|
149
|
+
"data-complete": dataAttr(state.complete),
|
|
150
|
+
"data-pending": dataAttr(state.pending),
|
|
151
|
+
"data-disabled": dataAttr(state.disabled),
|
|
152
|
+
...dataInvalid
|
|
153
|
+
};
|
|
154
|
+
return useRender({
|
|
155
|
+
defaultElement: "input",
|
|
156
|
+
render,
|
|
157
|
+
state,
|
|
158
|
+
className,
|
|
159
|
+
style,
|
|
160
|
+
children: void 0,
|
|
161
|
+
props: {
|
|
162
|
+
autoComplete: "one-time-code",
|
|
163
|
+
inputMode: charsetInputMode(ctx.charset),
|
|
164
|
+
autoCapitalize: "off",
|
|
165
|
+
autoCorrect: "off",
|
|
166
|
+
spellCheck: false,
|
|
167
|
+
...rest
|
|
168
|
+
},
|
|
169
|
+
libraryProps,
|
|
170
|
+
ref
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
OTPFieldInput.displayName = "OTPFieldInput";
|
|
174
|
+
//#endregion
|
|
175
|
+
export { OTPFieldInput };
|
|
176
|
+
|
|
177
|
+
//# sourceMappingURL=otp-field-input.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp-field-input.mjs","names":[],"sources":["../../src/otp-field/otp-field-input.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useLayoutEffect, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { useFieldControl } from \"../internal/form/use-field-control.js\";\nimport { useFormOwnerEvent } from \"../internal/form/use-form-owner-event.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useOTPFieldContext } from \"./otp-field-context.js\";\nimport { charsetInputMode, charsetPattern } from \"./otp-field-filter.js\";\nimport type { OTPFieldState } from \"./otp-field-root.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Props of `OTPField.Input`.\n *\n * @see https://ui.funstack.work/components/otp-field\n */\nexport interface OTPFieldInputProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"type\"\n | \"value\"\n | \"defaultValue\"\n | \"maxLength\"\n | \"minLength\"\n | \"pattern\"\n | \"name\"\n | \"form\"\n | \"required\"\n | \"disabled\"\n | \"readOnly\"\n | \"onChange\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Class name, or a function of the state that returns one. */\n className?: StateValue<string | undefined, OTPFieldState>;\n /**\n * Inline style, or a function of the state that returns one. The library's own inline style\n * (the Input covers the Root with transparent text) wins over these keys.\n */\n style?: StateValue<CSSProperties | undefined, OTPFieldState>;\n /** Must render an `<input>`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, OTPFieldState>;\n}\n\n/**\n * The Input covers the Root with transparent text and caret (design 6). Functional, owned; the\n * outline is left to the consumer. Provisional until the device probes are done (changelog).\n */\nconst INPUT_STYLE: CSSProperties = {\n position: \"absolute\",\n inset: 0,\n inlineSize: \"100%\",\n blockSize: \"100%\",\n margin: 0,\n padding: 0,\n border: 0,\n background: \"transparent\",\n color: \"transparent\",\n caretColor: \"transparent\",\n forcedColorAdjust: \"none\",\n};\n\n/** The WebOTP request (design 8); not in the DOM typings yet. */\ninterface OTPCredentialRequest extends CredentialRequestOptions {\n otp: { transport: string[] };\n}\n\n/**\n * The one text input of an OTPField (design/components/otp-field.md 1, 4): `type=\"text\"`,\n * `autocomplete=\"one-time-code\"`, `inputmode` and `pattern` from the Root's `charset`, covering\n * the Root with transparent text. The only focusable and the only element assistive technology\n * sees. Registers with an enclosing `Field.Root` as `Field.Control` does.\n *\n * Owned keys (conventions 1.2): `type`, `value`, `pattern`, `name`, `form`, `required`,\n * `disabled`, `readOnly`, `onChange` (and the library's native `beforeinput`, composition,\n * selection and click listeners), the inline style above, the Field's `id`, `aria-describedby`\n * (token-merged) and `aria-invalid`, `data-complete`, `data-pending`, `data-disabled`,\n * `data-invalid`. Defaults the consumer's own prop replaces: `autoComplete=\"one-time-code\"`,\n * `inputMode`, `autoCapitalize=\"off\"`, `autoCorrect=\"off\"`, `spellCheck={false}`.\n *\n * @see https://ui.funstack.work/components/otp-field\n */\nexport function OTPFieldInput({ className, style, render, ...rest }: OTPFieldInputProps) {\n const ctx = useOTPFieldContext(\"OTPField.Input\");\n const { state, inputRef, experimentalWebOTP, webOTPAbort } = ctx;\n\n const field = useFieldControl({\n labelable: true,\n name: ctx.name,\n disabled: state.disabled,\n required: ctx.required,\n id: rest.id,\n component: \"OTPField.Input\",\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName !== \"INPUT\"\n ? `OTPField.Input: rendered <${element.tagName.toLowerCase()}>. Render an <input>: ` +\n \"the field's text, autofill and form value live in it.\"\n : null),\n );\n const libraryRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n inputRef.current = element as HTMLInputElement;\n return () => {\n if (inputRef.current === element) inputRef.current = null;\n };\n },\n [checkElement, inputRef],\n );\n const ref = useMergedRefs<HTMLElement>(libraryRef, field.ref);\n\n // --- Native listeners (design 4): React has no `beforeinput` and no `selectionchange`. -------\n\n const {\n beforeInput,\n compositionStart,\n compositionEnd,\n selectionChanged,\n blurred,\n click,\n inputMounted,\n webOTPCode,\n } = ctx;\n useLayoutEffect(() => {\n const input = inputRef.current;\n if (input === null) return;\n const listeners: [string, (event: never) => void][] = [\n [\"beforeinput\", beforeInput],\n [\"compositionstart\", compositionStart],\n [\"compositionend\", compositionEnd],\n [\"selectionchange\", selectionChanged],\n [\"select\", selectionChanged],\n [\"focus\", selectionChanged],\n [\"keyup\", selectionChanged],\n [\"blur\", blurred],\n [\"click\", click],\n ];\n for (const [type, listener] of listeners) {\n input.addEventListener(type, listener as EventListener);\n }\n // Focused before hydration (or by `autoFocus`): no `focus` event will tell the Root.\n selectionChanged();\n return () => {\n for (const [type, listener] of listeners) {\n input.removeEventListener(type, listener as EventListener);\n }\n };\n }, [inputRef, beforeInput, compositionStart, compositionEnd, selectionChanged, blurred, click]);\n\n // Text typed, autofilled or restored before hydration is adopted once (design 9).\n const mounted = useRef(false);\n useLayoutEffect(() => {\n if (mounted.current) return;\n mounted.current = true;\n inputMounted();\n }, [inputMounted]);\n\n // --- WebOTP (design 8) ------------------------------------------------------------------------\n\n // Keyed on the flag alone: the request lives as long as the Input (and the flag), and the code\n // is handed over through the latest callback.\n const webOTPCodeRef = useLatest(webOTPCode);\n const { webOTPDone } = ctx;\n useEffect(() => {\n if (!experimentalWebOTP || !(\"OTPCredential\" in window) || webOTPDone.current) return;\n const controller = new AbortController();\n webOTPAbort.current = controller;\n const request: OTPCredentialRequest = {\n otp: { transport: [\"sms\"] },\n signal: controller.signal,\n };\n navigator.credentials.get(request).then(\n (credential) => {\n if (controller.signal.aborted) return;\n const code = (credential as { code?: unknown } | null)?.code;\n if (typeof code === \"string\") webOTPCodeRef.current(code);\n },\n // Declined, no message, aborted: the normal outcomes.\n () => {},\n );\n return () => {\n controller.abort();\n if (webOTPAbort.current === controller) webOTPAbort.current = null;\n };\n }, [experimentalWebOTP, webOTPAbort, webOTPDone, webOTPCodeRef]);\n useFormOwnerEvent(inputRef, \"submit\", () => {\n webOTPAbort.current?.abort();\n webOTPAbort.current = null;\n });\n\n // --- Development: an unnamed input (design 5) -------------------------------------------------\n\n useEffect(() => {\n if (!isDev) return;\n const input = inputRef.current;\n if (input === null) return;\n const named =\n (input.labels?.length ?? 0) > 0 ||\n (input.getAttribute(\"aria-label\") ?? \"\").trim() !== \"\" ||\n (input.getAttribute(\"aria-labelledby\") ?? \"\").trim() !== \"\";\n if (!named) {\n console.error(\n \"OTPField.Input: the input has no accessible name. Associate a <label for>, use \" +\n \"Field.Label, or give it aria-label / aria-labelledby.\",\n );\n }\n // Mount only.\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // --- Render -----------------------------------------------------------------------------------\n\n const dataInvalid =\n ctx.fieldInvalid === undefined ? {} : { \"data-invalid\": dataAttr(ctx.fieldInvalid) };\n const libraryProps: ComponentPropsWithRef<\"input\"> & DataAttributes = {\n ...field.attributes,\n type: \"text\",\n value: ctx.inputText,\n pattern: charsetPattern(ctx.charset, state.length),\n name: field.name,\n form: ctx.form,\n required: field.required,\n disabled: field.disabled,\n readOnly: state.readOnly,\n onChange: ctx.change,\n style: INPUT_STYLE,\n \"data-complete\": dataAttr(state.complete),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(state.disabled),\n ...dataInvalid,\n };\n\n return useRender<ComponentPropsWithRef<\"input\">, OTPFieldState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: {\n autoComplete: \"one-time-code\",\n inputMode: charsetInputMode(ctx.charset),\n autoCapitalize: \"off\",\n autoCorrect: \"off\",\n spellCheck: false,\n ...rest,\n },\n libraryProps,\n ref,\n });\n}\n\nOTPFieldInput.displayName = \"OTPFieldInput\";\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;AAwCvC,MAAM,cAA6B;CACjC,UAAU;CACV,OAAO;CACP,YAAY;CACZ,WAAW;CACX,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,OAAO;CACP,YAAY;CACZ,mBAAmB;AACrB;;;;;;;;;;;;;;;;AAsBA,SAAgB,cAAc,EAAE,WAAW,OAAO,QAAQ,GAAG,QAA4B;CACvF,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,EAAE,OAAO,UAAU,oBAAoB,gBAAgB;CAE7D,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,IAAI;EACV,UAAU,MAAM;EAChB,UAAU,IAAI;EACd,IAAI,KAAK;EACT,WAAW;CACb,CAAC;CAED,MAAM,eAAe,gBACnB,WACI,YACA,QAAQ,YAAY,UAChB,6BAA6B,QAAQ,QAAQ,YAAY,EAAE,+EAE3D,KACV;CACA,MAAM,aAAa,aAChB,YAAyB;EACxB,eAAe,OAAO;EACtB,SAAS,UAAU;EACnB,aAAa;GACX,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;EACvD;CACF,GACA,CAAC,cAAc,QAAQ,CACzB;CACA,MAAM,MAAM,cAA2B,YAAY,MAAM,GAAG;CAI5D,MAAM,EACJ,aACA,kBACA,gBACA,kBACA,SACA,OACA,cACA,eACE;CACJ,sBAAsB;EACpB,MAAM,QAAQ,SAAS;EACvB,IAAI,UAAU,MAAM;EACpB,MAAM,YAAgD;GACpD,CAAC,eAAe,WAAW;GAC3B,CAAC,oBAAoB,gBAAgB;GACrC,CA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