@jcsoftdev/ui 0.3.0 → 0.5.0
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 +200 -1
- package/README.md +56 -3
- package/bin/ui-theme.mjs +13 -2
- package/dist/atoms/button/button.d.ts +8 -1
- package/dist/atoms/button/button.js +10 -3
- package/dist/atoms/checkbox/checkbox.js +3 -1
- package/dist/atoms/chip/chip.d.ts +11 -3
- package/dist/atoms/chip/chip.js +8 -1
- package/dist/atoms/chip/index.d.ts +1 -1
- package/dist/atoms/chip/index.js +2 -0
- package/dist/atoms/divider/divider.d.ts +15 -0
- package/dist/atoms/divider/divider.js +27 -0
- package/dist/atoms/divider/index.d.ts +1 -0
- package/dist/atoms/divider/index.js +1 -0
- package/dist/atoms/due-chip/due-chip.d.ts +31 -0
- package/dist/atoms/due-chip/due-chip.js +41 -0
- package/dist/atoms/due-chip/index.d.ts +2 -0
- package/dist/atoms/due-chip/index.js +6 -0
- package/dist/atoms/due-chip/model.d.ts +25 -0
- package/dist/atoms/due-chip/model.js +44 -0
- package/dist/atoms/icon-button/icon-button.d.ts +22 -0
- package/dist/atoms/icon-button/icon-button.js +38 -0
- package/dist/atoms/icon-button/index.d.ts +1 -0
- package/dist/atoms/icon-button/index.js +8 -0
- package/dist/atoms/index.d.ts +6 -0
- package/dist/atoms/index.js +6 -0
- package/dist/atoms/internal/hit-area.d.ts +6 -0
- package/dist/atoms/internal/hit-area.js +4 -0
- package/dist/atoms/kbd/index.d.ts +1 -0
- package/dist/atoms/kbd/index.js +4 -0
- package/dist/atoms/kbd/kbd.d.ts +7 -0
- package/dist/atoms/kbd/kbd.js +17 -0
- package/dist/atoms/radio-group/radio-group.js +6 -2
- package/dist/atoms/seal/index.d.ts +1 -0
- package/dist/atoms/seal/index.js +4 -0
- package/dist/atoms/seal/seal.d.ts +30 -0
- package/dist/atoms/seal/seal.js +71 -0
- package/dist/atoms/spinner/index.d.ts +1 -0
- package/dist/atoms/spinner/index.js +5 -0
- package/dist/atoms/spinner/spinner.d.ts +19 -0
- package/dist/atoms/spinner/spinner.js +31 -0
- package/dist/atoms/switch/switch.js +3 -1
- package/dist/auth/auth-illustration/auth-illustration.d.ts +35 -0
- package/dist/auth/auth-illustration/auth-illustration.js +72 -0
- package/dist/auth/auth-illustration/index.d.ts +3 -0
- package/dist/auth/auth-illustration/index.js +11 -0
- package/dist/auth/auth-illustration/look.d.ts +30 -0
- package/dist/auth/auth-illustration/look.js +0 -0
- package/dist/auth/auth-illustration/model.d.ts +133 -0
- package/dist/auth/auth-illustration/model.js +202 -0
- package/dist/auth/auth-illustration/use-art-pointer.d.ts +9 -0
- package/dist/auth/auth-illustration/use-art-pointer.js +69 -0
- package/dist/auth/auth-layout/auth-layout.d.ts +80 -0
- package/dist/auth/auth-layout/auth-layout.js +190 -0
- package/dist/auth/auth-layout/index.d.ts +1 -0
- package/dist/auth/auth-layout/index.js +1 -0
- package/dist/auth/character/character.d.ts +12 -0
- package/dist/auth/character/character.js +333 -0
- package/dist/auth/character/index.d.ts +1 -0
- package/dist/auth/character/index.js +1 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +4 -0
- package/dist/auth/internal/auth-context.d.ts +17 -0
- package/dist/auth/internal/auth-context.js +10 -0
- package/dist/auth/internal/auth-styles.d.ts +1 -0
- package/dist/auth/internal/auth-styles.js +29 -0
- package/dist/auth/internal/portal-glyphs.d.ts +6 -0
- package/dist/auth/internal/portal-glyphs.js +39 -0
- package/dist/auth/login-form/context.d.ts +51 -0
- package/dist/auth/login-form/context.js +12 -0
- package/dist/auth/login-form/index.d.ts +2 -0
- package/dist/auth/login-form/index.js +23 -0
- package/dist/auth/login-form/login-form.d.ts +66 -0
- package/dist/auth/login-form/login-form.js +233 -0
- package/dist/auth/login-form/parts.d.ts +71 -0
- package/dist/auth/login-form/parts.js +371 -0
- package/dist/auth/looks/auth-illustration-any.d.ts +16 -0
- package/dist/auth/looks/auth-illustration-any.js +24 -0
- package/dist/auth/looks/index.d.ts +1 -0
- package/dist/auth/looks/index.js +1 -0
- package/dist/auth/mosaic/index.d.ts +1 -0
- package/dist/auth/mosaic/index.js +1 -0
- package/dist/auth/mosaic/mosaic.d.ts +11 -0
- package/dist/auth/mosaic/mosaic.js +195 -0
- package/dist/auth/slabs/index.d.ts +1 -0
- package/dist/auth/slabs/index.js +1 -0
- package/dist/auth/slabs/slabs.d.ts +13 -0
- package/dist/auth/slabs/slabs.js +136 -0
- package/dist/auth/stack/index.d.ts +1 -0
- package/dist/auth/stack/index.js +1 -0
- package/dist/auth/stack/stack.d.ts +6 -0
- package/dist/auth/stack/stack.js +222 -0
- package/dist/auth/statement/index.d.ts +1 -0
- package/dist/auth/statement/index.js +1 -0
- package/dist/auth/statement/statement.d.ts +13 -0
- package/dist/auth/statement/statement.js +99 -0
- package/dist/calendar/date-calendar/date-calendar.d.ts +32 -0
- package/dist/calendar/date-calendar/date-calendar.js +189 -0
- package/dist/calendar/date-calendar/index.d.ts +1 -0
- package/dist/calendar/date-calendar/index.js +6 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/internal/date-utils.d.ts +26 -0
- package/dist/calendar/internal/date-utils.js +95 -1
- package/dist/containers/aside/aside.d.ts +14 -0
- package/dist/containers/aside/aside.js +25 -0
- package/dist/containers/aside/index.d.ts +1 -0
- package/dist/containers/aside/index.js +5 -0
- package/dist/containers/banner/banner.d.ts +4 -1
- package/dist/containers/banner/banner.js +9 -1
- package/dist/containers/description-list/description-list.d.ts +29 -6
- package/dist/containers/description-list/description-list.js +47 -6
- package/dist/containers/feed/feed.d.ts +23 -0
- package/dist/containers/feed/feed.js +77 -0
- package/dist/containers/feed/index.d.ts +2 -0
- package/dist/containers/feed/index.js +10 -0
- package/dist/containers/feed/model.d.ts +19 -0
- package/dist/containers/feed/model.js +38 -0
- package/dist/containers/index.d.ts +6 -0
- package/dist/containers/index.js +6 -0
- package/dist/containers/kpi/kpi.d.ts +50 -8
- package/dist/containers/kpi/kpi.js +91 -39
- package/dist/containers/list-detail/index.d.ts +1 -0
- package/dist/containers/list-detail/index.js +20 -0
- package/dist/containers/list-detail/list-detail.d.ts +55 -0
- package/dist/containers/list-detail/list-detail.js +221 -0
- package/dist/containers/note/index.d.ts +1 -0
- package/dist/containers/note/index.js +4 -0
- package/dist/containers/note/note.d.ts +13 -0
- package/dist/containers/note/note.js +27 -0
- package/dist/containers/section/index.d.ts +1 -0
- package/dist/containers/section/index.js +6 -0
- package/dist/containers/section/section.d.ts +68 -0
- package/dist/containers/section/section.js +198 -0
- package/dist/containers/shortcuts/index.d.ts +1 -0
- package/dist/containers/shortcuts/index.js +8 -0
- package/dist/containers/shortcuts/shortcuts.d.ts +18 -0
- package/dist/containers/shortcuts/shortcuts.js +50 -0
- package/dist/containers/table/selection.d.ts +9 -0
- package/dist/containers/table/selection.js +20 -0
- package/dist/containers/table/table.d.ts +66 -4
- package/dist/containers/table/table.js +128 -7
- package/dist/containers/timeline/index.d.ts +1 -1
- package/dist/containers/timeline/index.js +4 -2
- package/dist/containers/timeline/timeline.d.ts +32 -5
- package/dist/containers/timeline/timeline.js +154 -90
- package/dist/forms/chip-group/chip-group.d.ts +54 -0
- package/dist/forms/chip-group/chip-group.js +114 -0
- package/dist/forms/chip-group/index.d.ts +1 -0
- package/dist/forms/chip-group/index.js +6 -0
- package/dist/forms/combobox/combobox.d.ts +60 -0
- package/dist/forms/combobox/combobox.js +281 -0
- package/dist/forms/combobox/index.d.ts +1 -0
- package/dist/forms/combobox/index.js +6 -0
- package/dist/forms/date-picker/date-picker.d.ts +40 -0
- package/dist/forms/date-picker/date-picker.js +183 -0
- package/dist/forms/date-picker/date-time-picker.d.ts +43 -0
- package/dist/forms/date-picker/date-time-picker.js +121 -0
- package/dist/forms/date-picker/index.d.ts +2 -0
- package/dist/forms/date-picker/index.js +10 -0
- package/dist/forms/date-picker/model.d.ts +35 -0
- package/dist/forms/date-picker/model.js +83 -0
- package/dist/forms/dropzone/dropzone.d.ts +30 -2
- package/dist/forms/dropzone/dropzone.js +153 -23
- package/dist/forms/field/field.d.ts +16 -10
- package/dist/forms/field/field.js +41 -5
- package/dist/forms/index.d.ts +5 -0
- package/dist/forms/index.js +5 -0
- package/dist/forms/input/index.d.ts +1 -1
- package/dist/forms/input/index.js +4 -1
- package/dist/forms/input/input.d.ts +21 -5
- package/dist/forms/input/input.js +75 -9
- package/dist/forms/input-icon/input-icon.d.ts +1 -1
- package/dist/forms/internal/listbox-items.d.ts +18 -0
- package/dist/forms/internal/listbox-items.js +88 -0
- package/dist/forms/internal/listbox.d.ts +44 -0
- package/dist/forms/internal/listbox.js +74 -0
- package/dist/forms/number-stepper/model.d.ts +16 -0
- package/dist/forms/number-stepper/model.js +23 -0
- package/dist/forms/number-stepper/number-stepper.d.ts +36 -6
- package/dist/forms/number-stepper/number-stepper.js +86 -37
- package/dist/forms/password-input/index.d.ts +1 -0
- package/dist/forms/password-input/index.js +1 -0
- package/dist/forms/password-input/password-input.d.ts +16 -0
- package/dist/forms/password-input/password-input.js +45 -0
- package/dist/forms/select-menu/index.d.ts +1 -0
- package/dist/forms/select-menu/index.js +6 -0
- package/dist/forms/select-menu/select-menu.d.ts +35 -0
- package/dist/forms/select-menu/select-menu.js +230 -0
- package/dist/i18n/strings.d.ts +153 -0
- package/dist/i18n/strings.js +86 -2
- package/dist/i18n/ui-strings-provider.d.ts +1 -1
- package/dist/i18n/ui-strings-provider.js +6 -2
- package/dist/icons/eye.d.ts +2 -0
- package/dist/icons/eye.js +11 -0
- package/dist/icons/graduation-cap.d.ts +2 -0
- package/dist/icons/graduation-cap.js +12 -0
- package/dist/icons/house.d.ts +2 -0
- package/dist/icons/house.js +11 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +8 -0
- package/dist/icons/mail.d.ts +2 -0
- package/dist/icons/mail.js +11 -0
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/stepper/index.d.ts +1 -1
- package/dist/navigation/stepper/index.js +3 -1
- package/dist/navigation/stepper/stepper.d.ts +8 -0
- package/dist/navigation/stepper/stepper.js +68 -45
- package/dist/navigation/tabs/index.d.ts +1 -0
- package/dist/navigation/tabs/index.js +6 -0
- package/dist/navigation/tabs/tabs-nav.d.ts +37 -0
- package/dist/navigation/tabs/tabs-nav.js +57 -0
- package/dist/navigation/wizard/index.d.ts +1 -0
- package/dist/navigation/wizard/index.js +6 -0
- package/dist/navigation/wizard/model.d.ts +33 -0
- package/dist/navigation/wizard/model.js +34 -0
- package/dist/navigation/wizard/wizard.d.ts +45 -0
- package/dist/navigation/wizard/wizard.js +169 -0
- package/dist/overlays/alert-dialog/alert-dialog.d.ts +103 -0
- package/dist/overlays/alert-dialog/alert-dialog.js +342 -0
- package/dist/overlays/alert-dialog/index.d.ts +1 -0
- package/dist/overlays/alert-dialog/index.js +26 -0
- package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +17 -1
- package/dist/overlays/dropdown-menu/dropdown-menu.js +12 -4
- package/dist/overlays/dropdown-menu/index.d.ts +1 -1
- package/dist/overlays/dropdown-menu/index.js +8 -2
- package/dist/overlays/index.d.ts +2 -0
- package/dist/overlays/index.js +2 -0
- package/dist/overlays/testing/index.d.ts +5 -0
- package/dist/overlays/testing/index.js +4 -0
- package/dist/overlays/toaster/index.d.ts +2 -1
- package/dist/overlays/toaster/index.js +4 -2
- package/dist/overlays/toaster/toast-store.d.ts +6 -2
- package/dist/overlays/toaster/toast.d.ts +3 -0
- package/dist/overlays/toaster/toast.js +3 -0
- package/dist/overlays/toaster/toaster.d.ts +3 -0
- package/dist/overlays/toaster/toaster.js +36 -3
- package/dist/overlays/tooltip/index.d.ts +1 -0
- package/dist/overlays/tooltip/index.js +4 -0
- package/dist/overlays/tooltip/model.d.ts +10 -0
- package/dist/overlays/tooltip/model.js +13 -0
- package/dist/overlays/tooltip/tooltip.d.ts +41 -0
- package/dist/overlays/tooltip/tooltip.js +116 -0
- package/dist/primitives/use-dismissable-layer.js +1 -1
- package/dist/states/error-state/error-state.d.ts +6 -1
- package/dist/states/error-state/error-state.js +13 -9
- package/dist/states/skeleton/skeleton.d.ts +8 -2
- package/dist/states/skeleton/skeleton.js +44 -2
- package/icons/svg/eye.svg +4 -0
- package/icons/svg/graduation-cap.svg +5 -0
- package/icons/svg/house.svg +4 -0
- package/icons/svg/mail.svg +4 -0
- package/package.json +2 -2
- package/scripts/build-theme.mjs +12 -1
- package/src/atoms/button/button.tsx +25 -3
- package/src/atoms/checkbox/checkbox.tsx +3 -1
- package/src/atoms/chip/chip.tsx +18 -3
- package/src/atoms/chip/index.ts +2 -0
- package/src/atoms/divider/divider.tsx +40 -0
- package/src/atoms/divider/index.ts +1 -0
- package/src/atoms/due-chip/due-chip.tsx +75 -0
- package/src/atoms/due-chip/index.ts +2 -0
- package/src/atoms/due-chip/model.ts +67 -0
- package/src/atoms/icon-button/icon-button.tsx +58 -0
- package/src/atoms/icon-button/index.ts +6 -0
- package/src/atoms/index.ts +6 -0
- package/src/atoms/internal/hit-area.ts +7 -0
- package/src/atoms/kbd/index.ts +1 -0
- package/src/atoms/kbd/kbd.tsx +20 -0
- package/src/atoms/radio-group/radio-group.tsx +8 -2
- package/src/atoms/seal/index.ts +1 -0
- package/src/atoms/seal/seal.tsx +107 -0
- package/src/atoms/spinner/index.ts +1 -0
- package/src/atoms/spinner/spinner.tsx +49 -0
- package/src/atoms/switch/switch.tsx +3 -1
- package/src/auth/auth-illustration/auth-illustration.tsx +100 -0
- package/src/auth/auth-illustration/index.ts +8 -0
- package/src/auth/auth-illustration/look.ts +32 -0
- package/src/auth/auth-illustration/model.ts +330 -0
- package/src/auth/auth-illustration/use-art-pointer.ts +78 -0
- package/src/auth/auth-layout/auth-layout.tsx +282 -0
- package/src/auth/auth-layout/index.ts +1 -0
- package/src/auth/character/character.tsx +346 -0
- package/src/auth/character/index.ts +1 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/internal/auth-context.ts +26 -0
- package/src/auth/internal/auth-styles.tsx +39 -0
- package/src/auth/internal/portal-glyphs.tsx +32 -0
- package/src/auth/login-form/context.ts +78 -0
- package/src/auth/login-form/index.ts +21 -0
- package/src/auth/login-form/login-form.tsx +330 -0
- package/src/auth/login-form/parts.tsx +457 -0
- package/src/auth/looks/auth-illustration-any.tsx +38 -0
- package/src/auth/looks/index.ts +1 -0
- package/src/auth/mosaic/index.ts +1 -0
- package/src/auth/mosaic/mosaic.tsx +255 -0
- package/src/auth/slabs/index.ts +1 -0
- package/src/auth/slabs/slabs.tsx +181 -0
- package/src/auth/stack/index.ts +1 -0
- package/src/auth/stack/stack.tsx +267 -0
- package/src/auth/statement/index.ts +1 -0
- package/src/auth/statement/statement.tsx +122 -0
- package/src/calendar/date-calendar/date-calendar.tsx +230 -0
- package/src/calendar/date-calendar/index.ts +5 -0
- package/src/calendar/index.ts +1 -0
- package/src/calendar/internal/date-utils.ts +115 -0
- package/src/containers/aside/aside.tsx +40 -0
- package/src/containers/aside/index.ts +1 -0
- package/src/containers/banner/banner.tsx +18 -1
- package/src/containers/description-list/description-list.tsx +85 -9
- package/src/containers/feed/feed.tsx +99 -0
- package/src/containers/feed/index.ts +8 -0
- package/src/containers/feed/model.ts +54 -0
- package/src/containers/index.ts +6 -0
- package/src/containers/kpi/kpi.tsx +161 -62
- package/src/containers/list-detail/index.ts +15 -0
- package/src/containers/list-detail/list-detail.tsx +293 -0
- package/src/containers/note/index.ts +1 -0
- package/src/containers/note/note.tsx +38 -0
- package/src/containers/section/index.ts +11 -0
- package/src/containers/section/section.tsx +281 -0
- package/src/containers/shortcuts/index.ts +6 -0
- package/src/containers/shortcuts/shortcuts.tsx +92 -0
- package/src/containers/table/selection.ts +26 -0
- package/src/containers/table/table.tsx +215 -13
- package/src/containers/timeline/index.ts +3 -0
- package/src/containers/timeline/timeline.tsx +204 -93
- package/src/forms/chip-group/chip-group.tsx +184 -0
- package/src/forms/chip-group/index.ts +8 -0
- package/src/forms/combobox/combobox.tsx +359 -0
- package/src/forms/combobox/index.ts +7 -0
- package/src/forms/date-picker/date-picker.tsx +239 -0
- package/src/forms/date-picker/date-time-picker.tsx +178 -0
- package/src/forms/date-picker/index.ts +10 -0
- package/src/forms/date-picker/model.ts +108 -0
- package/src/forms/dropzone/dropzone.tsx +217 -35
- package/src/forms/field/field.tsx +72 -7
- package/src/forms/index.ts +5 -0
- package/src/forms/input/index.ts +8 -1
- package/src/forms/input/input.tsx +99 -12
- package/src/forms/input-icon/input-icon.tsx +1 -1
- package/src/forms/internal/listbox-items.tsx +103 -0
- package/src/forms/internal/listbox.ts +124 -0
- package/src/forms/number-stepper/model.ts +35 -0
- package/src/forms/number-stepper/number-stepper.tsx +132 -42
- package/src/forms/password-input/index.ts +1 -0
- package/src/forms/password-input/password-input.tsx +57 -0
- package/src/forms/select-menu/index.ts +7 -0
- package/src/forms/select-menu/select-menu.tsx +280 -0
- package/src/i18n/strings.ts +153 -0
- package/src/i18n/ui-strings-provider.tsx +15 -4
- package/src/icons/eye.tsx +12 -0
- package/src/icons/graduation-cap.tsx +13 -0
- package/src/icons/house.tsx +12 -0
- package/src/icons/index.ts +4 -0
- package/src/icons/mail.tsx +12 -0
- package/src/navigation/index.ts +1 -0
- package/src/navigation/stepper/index.ts +7 -1
- package/src/navigation/stepper/stepper.tsx +41 -5
- package/src/navigation/tabs/index.ts +7 -0
- package/src/navigation/tabs/tabs-nav.tsx +131 -0
- package/src/navigation/wizard/index.ts +7 -0
- package/src/navigation/wizard/model.ts +61 -0
- package/src/navigation/wizard/wizard.tsx +222 -0
- package/src/overlays/alert-dialog/alert-dialog.tsx +486 -0
- package/src/overlays/alert-dialog/index.ts +19 -0
- package/src/overlays/dropdown-menu/dropdown-menu.tsx +29 -4
- package/src/overlays/dropdown-menu/index.ts +3 -0
- package/src/overlays/index.ts +2 -0
- package/src/overlays/testing/index.ts +5 -0
- package/src/overlays/toaster/index.ts +2 -0
- package/src/overlays/toaster/toast-store.ts +6 -2
- package/src/overlays/toaster/toast.ts +6 -0
- package/src/overlays/toaster/toaster.tsx +44 -2
- package/src/overlays/tooltip/index.ts +1 -0
- package/src/overlays/tooltip/model.ts +18 -0
- package/src/overlays/tooltip/tooltip.tsx +166 -0
- package/src/primitives/use-dismissable-layer.ts +7 -2
- package/src/states/error-state/error-state.tsx +19 -8
- package/src/states/skeleton/skeleton.tsx +68 -2
- package/styles/tailwind.css +33 -30
- package/styles/theme.css +33 -30
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ComponentPropsWithoutRef,
|
|
5
|
+
type ReactNode,
|
|
6
|
+
useEffect,
|
|
7
|
+
useId,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { cn } from "../../utils/cn.js";
|
|
12
|
+
import { useOptionalAuth } from "../internal/auth-context.js";
|
|
13
|
+
import { AuthStyles } from "../internal/auth-styles.js";
|
|
14
|
+
import { Slabs } from "../slabs/slabs.js";
|
|
15
|
+
import type { AuthLook } from "./look.js";
|
|
16
|
+
import { type AuthState, clamp01, ERROR_HOLD_MS, shownState } from "./model.js";
|
|
17
|
+
import { useArtPointer } from "./use-art-pointer.js";
|
|
18
|
+
|
|
19
|
+
export interface AuthIllustrationProps extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
|
|
20
|
+
/**
|
|
21
|
+
* The look, a component from its own entry (`Stack` from `@jcsoftdev/ui/auth/stack`, and so on).
|
|
22
|
+
* Defaults to `Slabs`; looks you do not pass stay out of your bundle. For a string `variant`
|
|
23
|
+
* use `AuthIllustrationAny` from `@jcsoftdev/ui/auth/looks`.
|
|
24
|
+
*/
|
|
25
|
+
look?: AuthLook;
|
|
26
|
+
/** What the screen is doing. Inside an `AuthLayout` it follows the layout's state. */
|
|
27
|
+
state?: AuthState;
|
|
28
|
+
/** Fill of the whole form, 0 to 1. Inside an `AuthLayout` it follows the layout's progress. */
|
|
29
|
+
progress?: number;
|
|
30
|
+
/** Index of the portal being used (0 to 2); that slab rises above the others. */
|
|
31
|
+
activeIndex?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Accessible name of the image. Without it the illustration is decorative and hidden from
|
|
34
|
+
* assistive technology. Ignored by text looks (`Statement`): their text is the content, so they
|
|
35
|
+
* are never an `img` and never hidden.
|
|
36
|
+
*/
|
|
37
|
+
label?: string;
|
|
38
|
+
/** Text looks (`Statement`) only: the headline (a string animates word by word). Defaults to the UI string `welcomeBack`. */
|
|
39
|
+
headline?: ReactNode;
|
|
40
|
+
/** Text looks only: a supporting line under the headline. */
|
|
41
|
+
caption?: ReactNode;
|
|
42
|
+
/** Text looks only: content beside the arrow pill, such as a link. */
|
|
43
|
+
action?: ReactNode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Isometric illustration of the three portals that reacts to the sign-in state with CSS
|
|
48
|
+
* transitions only. Colours come from the theme tokens (`--accent`, `--surface`, `--ink`), so dark
|
|
49
|
+
* mode and every accent apply on their own. With reduced motion it rests assembled and still.
|
|
50
|
+
*/
|
|
51
|
+
export function AuthIllustration({
|
|
52
|
+
look: Look = Slabs,
|
|
53
|
+
state: stateProp,
|
|
54
|
+
progress: progressProp,
|
|
55
|
+
activeIndex: activeIndexProp,
|
|
56
|
+
label,
|
|
57
|
+
headline,
|
|
58
|
+
caption,
|
|
59
|
+
action,
|
|
60
|
+
className,
|
|
61
|
+
...props
|
|
62
|
+
}: AuthIllustrationProps) {
|
|
63
|
+
const auth = useOptionalAuth();
|
|
64
|
+
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
65
|
+
const state = stateProp ?? auth?.state ?? "idle";
|
|
66
|
+
const progress = clamp01(progressProp ?? auth?.progress ?? 0);
|
|
67
|
+
const activeIndex = activeIndexProp ?? auth?.activeIndex ?? 0;
|
|
68
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
69
|
+
useArtPointer(ref);
|
|
70
|
+
const [errorHeld, setErrorHeld] = useState(false);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
setErrorHeld(false);
|
|
73
|
+
if (state !== "error") return;
|
|
74
|
+
const timer = setTimeout(() => setErrorHeld(true), ERROR_HOLD_MS);
|
|
75
|
+
return () => clearTimeout(timer);
|
|
76
|
+
}, [state]);
|
|
77
|
+
const shown = shownState(state, errorHeld);
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
{...props}
|
|
81
|
+
ref={ref}
|
|
82
|
+
{...(Look.text ? {} : label ? { role: "img", "aria-label": label } : { "aria-hidden": true })}
|
|
83
|
+
data-state={shown}
|
|
84
|
+
data-panel={auth?.panel}
|
|
85
|
+
data-variant={Look.variant}
|
|
86
|
+
className={cn("ui-auth-art @container/art w-full min-w-0", className)}
|
|
87
|
+
>
|
|
88
|
+
<AuthStyles />
|
|
89
|
+
<Look
|
|
90
|
+
state={shown}
|
|
91
|
+
progress={progress}
|
|
92
|
+
activeIndex={activeIndex}
|
|
93
|
+
uid={uid}
|
|
94
|
+
headline={headline}
|
|
95
|
+
caption={caption}
|
|
96
|
+
action={action}
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import type { AuthState } from "./model.js";
|
|
3
|
+
|
|
4
|
+
/** What every illustration look receives. State and progress come already clamped. */
|
|
5
|
+
export interface AuthVariantProps {
|
|
6
|
+
state: AuthState;
|
|
7
|
+
/** Fill of the whole form, 0 to 1. */
|
|
8
|
+
progress: number;
|
|
9
|
+
/** Index of the portal in use (0 to 2). */
|
|
10
|
+
activeIndex: number;
|
|
11
|
+
/** Unique per rendered illustration; use it to prefix SVG ids (patterns, gradients, clip paths). */
|
|
12
|
+
uid: string;
|
|
13
|
+
/** Text looks only (`statement`): the main line; a string animates word by word. */
|
|
14
|
+
headline?: ReactNode;
|
|
15
|
+
/** Text looks only: a supporting line under the headline. */
|
|
16
|
+
caption?: ReactNode;
|
|
17
|
+
/** Text looks only: content placed beside the arrow pill, such as a link. */
|
|
18
|
+
action?: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A look is a component with {@link AuthVariantProps}. It renders inside a `@container/art` element,
|
|
23
|
+
* so it adapts to the width it is given with `@sm/art:` classes or `@container art (min-width: ...)`
|
|
24
|
+
* rules, and it reads `data-state` from the wrapper for state-driven CSS. Two optional static
|
|
25
|
+
* properties describe it to `AuthIllustration` without a registry: `variant` is the name written
|
|
26
|
+
* to `data-variant`, and `text` marks a look made of text people read, which is then not hidden
|
|
27
|
+
* from assistive technology.
|
|
28
|
+
*/
|
|
29
|
+
export type AuthLook = ComponentType<AuthVariantProps> & {
|
|
30
|
+
variant?: string;
|
|
31
|
+
text?: boolean;
|
|
32
|
+
};
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/** What the sign-in screen is doing. It is the only input of the illustration besides `progress`. */
|
|
2
|
+
export type AuthState = "idle" | "typing" | "password" | "error" | "success";
|
|
3
|
+
|
|
4
|
+
export const AUTH_STATES: readonly AuthState[] = [
|
|
5
|
+
"idle",
|
|
6
|
+
"typing",
|
|
7
|
+
"password",
|
|
8
|
+
"error",
|
|
9
|
+
"success",
|
|
10
|
+
] as const;
|
|
11
|
+
|
|
12
|
+
export const clamp01 = (value: number): number =>
|
|
13
|
+
Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0;
|
|
14
|
+
|
|
15
|
+
/** `progress` is the fill of the whole form: the identifier is the first half, the password the second. */
|
|
16
|
+
export const IDENTIFIER_SHARE = 0.5;
|
|
17
|
+
|
|
18
|
+
const SPREAD = { idle: 0.85, error: 1.35, success: 0 } as const;
|
|
19
|
+
const TYPING = { start: 0.65, end: 0.35 } as const;
|
|
20
|
+
const PASSWORD = { start: 0.22, end: 0.05 } as const;
|
|
21
|
+
|
|
22
|
+
const lerp = (from: number, to: number, t: number) => from + (to - from) * clamp01(t);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How far the three slabs sit apart: 0 is assembled, 1 is the loose resting layout. The slabs
|
|
26
|
+
* drift together as the form fills (first the identifier, then the password), fly apart on an
|
|
27
|
+
* error and lock together on success.
|
|
28
|
+
*/
|
|
29
|
+
export function slabSpread(state: AuthState, progress: number): number {
|
|
30
|
+
const p = clamp01(progress);
|
|
31
|
+
switch (state) {
|
|
32
|
+
case "typing":
|
|
33
|
+
return lerp(TYPING.start, TYPING.end, p / IDENTIFIER_SHARE);
|
|
34
|
+
case "password":
|
|
35
|
+
return lerp(PASSWORD.start, PASSWORD.end, (p - IDENTIFIER_SHARE) / (1 - IDENTIFIER_SHARE));
|
|
36
|
+
default:
|
|
37
|
+
return SPREAD[state];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const SLAB_COUNT = 3;
|
|
42
|
+
|
|
43
|
+
/** Apex of the first slab's top face in the 640x520 art box. */
|
|
44
|
+
const SLAB_BASE = { x: 277, y: 149 } as const;
|
|
45
|
+
/** Position of each slab when assembled, relative to {@link SLAB_BASE}. */
|
|
46
|
+
const SLAB_ASSEMBLED = [
|
|
47
|
+
{ x: 0, y: 0 },
|
|
48
|
+
{ x: 86.6, y: 50 },
|
|
49
|
+
{ x: 0, y: 100 },
|
|
50
|
+
] as const;
|
|
51
|
+
/** How far each slab travels (x, y) and rises (lift) at `spread` 1. */
|
|
52
|
+
const SLAB_TRAVEL = [
|
|
53
|
+
{ x: -120, y: 14, lift: 34 },
|
|
54
|
+
{ x: 104, y: -44, lift: 62 },
|
|
55
|
+
{ x: 14, y: 78, lift: 14 },
|
|
56
|
+
] as const;
|
|
57
|
+
const ACTIVE_LIFT = 20;
|
|
58
|
+
|
|
59
|
+
export interface SlabPlacement {
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
lift: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const round = (value: number) => Math.round(value * 100) / 100;
|
|
66
|
+
|
|
67
|
+
/** Position and height of one slab. The slab at `activeIndex` rises a little above the rest. */
|
|
68
|
+
export function slabPlacement(index: number, spread: number, activeIndex: number): SlabPlacement {
|
|
69
|
+
const assembled = SLAB_ASSEMBLED[index];
|
|
70
|
+
const travel = SLAB_TRAVEL[index];
|
|
71
|
+
if (!assembled || !travel) return { x: SLAB_BASE.x, y: SLAB_BASE.y, lift: 0 };
|
|
72
|
+
return {
|
|
73
|
+
x: round(SLAB_BASE.x + assembled.x + travel.x * spread),
|
|
74
|
+
y: round(SLAB_BASE.y + assembled.y + travel.y * spread),
|
|
75
|
+
lift: round(travel.lift * spread + (index === activeIndex ? ACTIVE_LIFT : 0)),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface SparkVector {
|
|
80
|
+
dx: number;
|
|
81
|
+
dy: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Offsets of the success burst. Deterministic, so server and client render the same markup. */
|
|
85
|
+
export function sparkVectors(count = 12): SparkVector[] {
|
|
86
|
+
return Array.from({ length: count }, (_, n) => {
|
|
87
|
+
const angle = (n / count) * Math.PI * 2;
|
|
88
|
+
const distance = 90 + ((n * 37) % 90);
|
|
89
|
+
return { dx: round(Math.cos(angle) * distance), dy: round(Math.sin(angle) * distance * 0.7) };
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** How long an error stays on screen before the illustration settles back to the password state. */
|
|
94
|
+
export const ERROR_HOLD_MS = 1100;
|
|
95
|
+
|
|
96
|
+
/** The state the art shows: an error that has been held long enough reads as `password` again. */
|
|
97
|
+
export function shownState(state: AuthState, errorHeld: boolean): AuthState {
|
|
98
|
+
return state === "error" && errorHeld ? "password" : state;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Characters of the identifier at which its half of the form reads full; one keystroke moves `progress` by 1/(2 x this). */
|
|
102
|
+
export const KEYSTROKES_PER_FIELD = 10;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Fill of the whole form: the identifier grows its half by length, the password adds its half in
|
|
106
|
+
* one step as soon as it is not empty. The password's length never reaches `progress`, because
|
|
107
|
+
* `progress` is written to the DOM (styles, classes) where session-replay tools do not mask it.
|
|
108
|
+
*/
|
|
109
|
+
export function formProgress(identifierLength: number, passwordFilled: boolean): number {
|
|
110
|
+
const identifier = Math.min(1, Math.max(0, identifierLength) / KEYSTROKES_PER_FIELD);
|
|
111
|
+
return (identifier + (passwordFilled ? 1 : 0)) / 2;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface Keystroke {
|
|
115
|
+
/** Keystrokes so far across both fields. */
|
|
116
|
+
count: number;
|
|
117
|
+
/** Which of the three pieces reacts to this keystroke. */
|
|
118
|
+
target: number;
|
|
119
|
+
/**
|
|
120
|
+
* Alternates every time the same piece reacts again, so CSS can swap between two identical
|
|
121
|
+
* keyframes and restart the animation without JavaScript timers.
|
|
122
|
+
*/
|
|
123
|
+
phase: 0 | 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The keystroke a `progress` value stands for. */
|
|
127
|
+
export function keystroke(progress: number, pieces = 3): Keystroke {
|
|
128
|
+
const count = Math.round(clamp01(progress) * KEYSTROKES_PER_FIELD * 2);
|
|
129
|
+
return { count, target: count % pieces, phase: (Math.floor(count / pieces) % 2) as 0 | 1 };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface PointerOffset {
|
|
133
|
+
x: number;
|
|
134
|
+
y: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Where a pointer is relative to a box, as -1 to 1 on each axis from its center (clamped, so a
|
|
139
|
+
* pointer far over the form still reads as "all the way to that side").
|
|
140
|
+
*/
|
|
141
|
+
export function pointerOffset(
|
|
142
|
+
point: { x: number; y: number },
|
|
143
|
+
box: { left: number; top: number; width: number; height: number },
|
|
144
|
+
): PointerOffset {
|
|
145
|
+
const axis = (value: number, start: number, size: number) =>
|
|
146
|
+
size > 0
|
|
147
|
+
? Math.round(Math.max(-1, Math.min(1, (value - start - size / 2) / (size / 2))) * 1000) / 1000
|
|
148
|
+
: 0;
|
|
149
|
+
return { x: axis(point.x, box.left, box.width), y: axis(point.y, box.top, box.height) };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* ---------------------------------------------------------------- isometric geometry */
|
|
153
|
+
|
|
154
|
+
const ISO_X = 0.866;
|
|
155
|
+
const ISO_Y = 0.5;
|
|
156
|
+
|
|
157
|
+
/** Screen position of a point in isometric space: `u` runs right-down, `v` left-down, `z` up. */
|
|
158
|
+
export function isoPoint(u: number, v: number, z = 0): { x: number; y: number } {
|
|
159
|
+
return { x: round(ISO_X * (u - v)), y: round(ISO_Y * (u + v) - z) };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const pathOf = (points: readonly { x: number; y: number }[]) =>
|
|
163
|
+
`M${points.map((p) => `${p.x} ${p.y}`).join("L")}Z`;
|
|
164
|
+
|
|
165
|
+
export interface IsoBox {
|
|
166
|
+
top: string;
|
|
167
|
+
/** Face along the front-left edge (`v` at its maximum). */
|
|
168
|
+
left: string;
|
|
169
|
+
/** Face along the front-right edge (`u` at its maximum). */
|
|
170
|
+
right: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The three visible faces of a `w` by `d` by `h` box standing on the origin, centred on it. */
|
|
174
|
+
export function isoBox(w: number, d: number, h: number): IsoBox {
|
|
175
|
+
const [u0, u1, v0, v1] = [-w / 2, w / 2, -d / 2, d / 2];
|
|
176
|
+
return {
|
|
177
|
+
top: pathOf([
|
|
178
|
+
isoPoint(u0, v0, h),
|
|
179
|
+
isoPoint(u1, v0, h),
|
|
180
|
+
isoPoint(u1, v1, h),
|
|
181
|
+
isoPoint(u0, v1, h),
|
|
182
|
+
]),
|
|
183
|
+
left: pathOf([
|
|
184
|
+
isoPoint(u0, v1, h),
|
|
185
|
+
isoPoint(u1, v1, h),
|
|
186
|
+
isoPoint(u1, v1, 0),
|
|
187
|
+
isoPoint(u0, v1, 0),
|
|
188
|
+
]),
|
|
189
|
+
right: pathOf([
|
|
190
|
+
isoPoint(u1, v0, h),
|
|
191
|
+
isoPoint(u1, v1, h),
|
|
192
|
+
isoPoint(u1, v1, 0),
|
|
193
|
+
isoPoint(u1, v0, 0),
|
|
194
|
+
]),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* ---------------------------------------------------------------- stack */
|
|
199
|
+
|
|
200
|
+
export interface StackBook {
|
|
201
|
+
/** Footprint along `u` and `v`, and thickness. */
|
|
202
|
+
w: number;
|
|
203
|
+
d: number;
|
|
204
|
+
h: number;
|
|
205
|
+
/** Offset from the tower's axis, in isometric units, so the pile looks hand stacked. */
|
|
206
|
+
du: number;
|
|
207
|
+
dv: number;
|
|
208
|
+
/** Colour role, 0 to 3. */
|
|
209
|
+
tone: number;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The books of the tower from the bottom up. Narrow containers show only the first ones. */
|
|
213
|
+
export const STACK_BOOKS: readonly StackBook[] = [
|
|
214
|
+
{ w: 178, d: 128, h: 30, du: 0, dv: 0, tone: 0 },
|
|
215
|
+
{ w: 152, d: 112, h: 22, du: 8, dv: -6, tone: 1 },
|
|
216
|
+
{ w: 164, d: 104, h: 26, du: -10, dv: 6, tone: 2 },
|
|
217
|
+
{ w: 140, d: 112, h: 20, du: 6, dv: 4, tone: 3 },
|
|
218
|
+
{ w: 150, d: 98, h: 24, du: -6, dv: -8, tone: 1 },
|
|
219
|
+
{ w: 128, d: 100, h: 20, du: 4, dv: 6, tone: 0 },
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
/** How many books a container shows: fewer when it is narrow. */
|
|
223
|
+
export const STACK_COUNTS = [4, 5, 6] as const;
|
|
224
|
+
export type StackCount = (typeof STACK_COUNTS)[number];
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Books resting in a tower of `count`: the foundation is always there, the rest land one by one
|
|
228
|
+
* as the form fills, and all of them are down on success.
|
|
229
|
+
*/
|
|
230
|
+
export function stackPlaced(state: AuthState, progress: number, count: number): number {
|
|
231
|
+
if (state === "success") return count;
|
|
232
|
+
return Math.min(count, 1 + Math.floor(clamp01(progress) * (count - 1) + 1e-9));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface StackSlot {
|
|
236
|
+
/** Screen offset of the book's ground centre from the tower's base. */
|
|
237
|
+
x: number;
|
|
238
|
+
y: number;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Where each book sits, from its offsets and the thickness of the books under it. */
|
|
242
|
+
export function stackSlots(books: readonly StackBook[] = STACK_BOOKS): StackSlot[] {
|
|
243
|
+
let z = 0;
|
|
244
|
+
return books.map((book) => {
|
|
245
|
+
const at = isoPoint(book.du, book.dv, z);
|
|
246
|
+
z += book.h;
|
|
247
|
+
return at;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Top centre of the tower of `count` books, where the success flag is planted. */
|
|
252
|
+
export function stackTop(count: number, books: readonly StackBook[] = STACK_BOOKS): StackSlot {
|
|
253
|
+
const shown = books.slice(0, count);
|
|
254
|
+
const last = shown[shown.length - 1];
|
|
255
|
+
if (!last) return { x: 0, y: 0 };
|
|
256
|
+
const z = shown.reduce((sum, book) => sum + book.h, 0);
|
|
257
|
+
return isoPoint(last.du, last.dv, z);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* ---------------------------------------------------------------- mosaic */
|
|
261
|
+
|
|
262
|
+
/** Tiles per side of the mosaic floor; its container picks one by width. */
|
|
263
|
+
export const MOSAIC_SIZES = [4, 5, 6] as const;
|
|
264
|
+
export type MosaicSize = (typeof MOSAIC_SIZES)[number];
|
|
265
|
+
|
|
266
|
+
/** Diagonals of an `n` by `n` floor that are lit: they fill from the back corner as the form fills. */
|
|
267
|
+
export function mosaicFilled(state: AuthState, progress: number, n: number): number {
|
|
268
|
+
const diagonals = n * 2 - 1;
|
|
269
|
+
if (state === "success") return diagonals;
|
|
270
|
+
return Math.min(diagonals, Math.floor(clamp01(progress) * diagonals + 1e-9));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface MosaicTile {
|
|
274
|
+
row: number;
|
|
275
|
+
col: number;
|
|
276
|
+
/** Diagonal from the back corner, 0 to 2n-2: the fill and the error sweep follow it. */
|
|
277
|
+
diagonal: number;
|
|
278
|
+
/** Steps from the centre: the success ripple follows it. */
|
|
279
|
+
ring: number;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function mosaicTiles(n: number): MosaicTile[] {
|
|
283
|
+
const middle = (n - 1) / 2;
|
|
284
|
+
return Array.from({ length: n * n }, (_, k) => {
|
|
285
|
+
const row = Math.floor(k / n);
|
|
286
|
+
const col = k % n;
|
|
287
|
+
return {
|
|
288
|
+
row,
|
|
289
|
+
col,
|
|
290
|
+
diagonal: row + col,
|
|
291
|
+
ring: Math.round(Math.abs(row - middle) + Math.abs(col - middle)),
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Row and column of the tile carrying each portal's glyph, for each floor size. */
|
|
297
|
+
export const MOSAIC_GLYPH_TILES: Readonly<
|
|
298
|
+
Record<MosaicSize, readonly (readonly [number, number])[]>
|
|
299
|
+
> = {
|
|
300
|
+
4: [
|
|
301
|
+
[1, 0],
|
|
302
|
+
[0, 2],
|
|
303
|
+
[2, 3],
|
|
304
|
+
],
|
|
305
|
+
5: [
|
|
306
|
+
[1, 1],
|
|
307
|
+
[0, 3],
|
|
308
|
+
[3, 3],
|
|
309
|
+
],
|
|
310
|
+
6: [
|
|
311
|
+
[1, 1],
|
|
312
|
+
[1, 4],
|
|
313
|
+
[4, 3],
|
|
314
|
+
],
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/** The tile that glints on a keystroke: it jumps around the floor instead of marching in order. */
|
|
318
|
+
export function mosaicGlint(count: number, n: number): number {
|
|
319
|
+
return count > 0 ? (count * 7) % (n * n) : -1;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/* ------------------------------------------------------------- character */
|
|
323
|
+
|
|
324
|
+
/** Lamps along the character's board; they fill with progress. */
|
|
325
|
+
export const BOARD_LIGHTS = 5;
|
|
326
|
+
|
|
327
|
+
export function boardLit(state: AuthState, progress: number): number {
|
|
328
|
+
if (state === "success") return BOARD_LIGHTS;
|
|
329
|
+
return Math.min(BOARD_LIGHTS, Math.floor(clamp01(progress) * BOARD_LIGHTS + 1e-9));
|
|
330
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { type RefObject, useEffect } from "react";
|
|
4
|
+
import { pointerOffset } from "./model.js";
|
|
5
|
+
|
|
6
|
+
const FINE_POINTER = "(hover: hover) and (pointer: fine)";
|
|
7
|
+
const REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Writes where the pointer is, relative to the art, as `--px` and `--py` (-1 to 1) on the art
|
|
11
|
+
* element. It listens on the surrounding `AuthLayout` so the art also reacts while the pointer is
|
|
12
|
+
* over the form. One write per animation frame at most; nothing runs for touch, coarse pointers or
|
|
13
|
+
* reduced motion, and it follows those settings when they change while the page is open (the art
|
|
14
|
+
* recentres when the parallax switches off). The listeners go away with the component.
|
|
15
|
+
*/
|
|
16
|
+
export function useArtPointer(ref: RefObject<HTMLElement | null>): void {
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const art = ref.current;
|
|
19
|
+
if (!art || typeof window.matchMedia !== "function") return;
|
|
20
|
+
const fine = window.matchMedia(FINE_POINTER);
|
|
21
|
+
const reduced = window.matchMedia(REDUCED_MOTION);
|
|
22
|
+
const area: HTMLElement = art.closest<HTMLElement>("[data-layout]") ?? art;
|
|
23
|
+
let frame = 0;
|
|
24
|
+
let point: { x: number; y: number } | null = null;
|
|
25
|
+
let listening = false;
|
|
26
|
+
|
|
27
|
+
const write = () => {
|
|
28
|
+
frame = 0;
|
|
29
|
+
if (!point) {
|
|
30
|
+
art.style.setProperty("--px", "0");
|
|
31
|
+
art.style.setProperty("--py", "0");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const offset = pointerOffset(point, art.getBoundingClientRect());
|
|
35
|
+
art.style.setProperty("--px", String(offset.x));
|
|
36
|
+
art.style.setProperty("--py", String(offset.y));
|
|
37
|
+
};
|
|
38
|
+
const schedule = () => {
|
|
39
|
+
if (!frame) frame = requestAnimationFrame(write);
|
|
40
|
+
};
|
|
41
|
+
const move = (event: PointerEvent) => {
|
|
42
|
+
if (event.pointerType !== "mouse" && event.pointerType !== "pen") return;
|
|
43
|
+
point = { x: event.clientX, y: event.clientY };
|
|
44
|
+
schedule();
|
|
45
|
+
};
|
|
46
|
+
const leave = () => {
|
|
47
|
+
point = null;
|
|
48
|
+
schedule();
|
|
49
|
+
};
|
|
50
|
+
const stop = () => {
|
|
51
|
+
if (!listening) return;
|
|
52
|
+
listening = false;
|
|
53
|
+
area.removeEventListener("pointermove", move);
|
|
54
|
+
area.removeEventListener("pointerleave", leave);
|
|
55
|
+
if (frame) cancelAnimationFrame(frame);
|
|
56
|
+
frame = 0;
|
|
57
|
+
point = null;
|
|
58
|
+
art.style.removeProperty("--px");
|
|
59
|
+
art.style.removeProperty("--py");
|
|
60
|
+
};
|
|
61
|
+
const sync = () => {
|
|
62
|
+
if (!fine.matches || reduced.matches) return stop();
|
|
63
|
+
if (listening) return;
|
|
64
|
+
listening = true;
|
|
65
|
+
area.addEventListener("pointermove", move, { passive: true });
|
|
66
|
+
area.addEventListener("pointerleave", leave, { passive: true });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
sync();
|
|
70
|
+
fine.addEventListener("change", sync);
|
|
71
|
+
reduced.addEventListener("change", sync);
|
|
72
|
+
return () => {
|
|
73
|
+
fine.removeEventListener("change", sync);
|
|
74
|
+
reduced.removeEventListener("change", sync);
|
|
75
|
+
stop();
|
|
76
|
+
};
|
|
77
|
+
}, [ref]);
|
|
78
|
+
}
|