@moonwitness/ui 7.3.0 → 8.0.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 +16 -0
- package/dist/pixelfx-boundary.js +1 -1
- package/package.json +2 -3
- package/scripts/consumer-smoke.mjs +0 -45
- package/scripts/generate-icons.mjs +0 -110
- package/scripts/generate-token-artifacts.mjs +0 -90
- package/scripts/icon-svg-to-jsx.mjs +0 -249
- package/scripts/verification-diagnostics.mjs +0 -40
- package/scripts/verify-package.mjs +0 -412
- package/src/cartoon/anime-avatar.tsx +0 -628
- package/src/cartoon/anime-stage.tsx +0 -458
- package/src/cartoon/index.tsx +0 -542
- package/src/cartoon.tsx +0 -645
- package/src/characters.ts +0 -625
- package/src/components/accordion.tsx +0 -77
- package/src/components/alert.tsx +0 -139
- package/src/components/appearance-menu.tsx +0 -181
- package/src/components/artwork-frame.tsx +0 -49
- package/src/components/audio.tsx +0 -97
- package/src/components/avatar.tsx +0 -75
- package/src/components/badge.tsx +0 -94
- package/src/components/brand-mark.tsx +0 -73
- package/src/components/breadcrumbs.tsx +0 -98
- package/src/components/button.tsx +0 -340
- package/src/components/card.tsx +0 -171
- package/src/components/character-badge.tsx +0 -58
- package/src/components/character-preview.tsx +0 -104
- package/src/components/character-stage.tsx +0 -225
- package/src/components/chart.tsx +0 -481
- package/src/components/checkbox.tsx +0 -64
- package/src/components/comic-panel.tsx +0 -301
- package/src/components/comic-theater.tsx +0 -170
- package/src/components/command.tsx +0 -189
- package/src/components/confirm-dialog.tsx +0 -129
- package/src/components/copy-button.tsx +0 -62
- package/src/components/date-picker.tsx +0 -126
- package/src/components/dialog.tsx +0 -164
- package/src/components/dna-icon.tsx +0 -77
- package/src/components/dropdown-menu.tsx +0 -87
- package/src/components/effects.tsx +0 -1021
- package/src/components/empty-state.tsx +0 -93
- package/src/components/epistemic-branch-panel.tsx +0 -101
- package/src/components/error-state.tsx +0 -137
- package/src/components/field.tsx +0 -96
- package/src/components/filter-facet-bar.tsx +0 -91
- package/src/components/inbox-popover.tsx +0 -146
- package/src/components/input.tsx +0 -25
- package/src/components/kanban-board.tsx +0 -190
- package/src/components/label.tsx +0 -19
- package/src/components/layered-scene.tsx +0 -555
- package/src/components/log-console.tsx +0 -261
- package/src/components/metric-tile.tsx +0 -99
- package/src/components/mode-picker.tsx +0 -149
- package/src/components/motion-timeline.tsx +0 -848
- package/src/components/number-input.tsx +0 -104
- package/src/components/page-header.tsx +0 -123
- package/src/components/pagination.tsx +0 -83
- package/src/components/panel.tsx +0 -121
- package/src/components/paper-note.tsx +0 -77
- package/src/components/popover.tsx +0 -72
- package/src/components/progress.tsx +0 -127
- package/src/components/quest-card.tsx +0 -319
- package/src/components/radio-group.tsx +0 -50
- package/src/components/riot-sticker.tsx +0 -151
- package/src/components/scene-particles.tsx +0 -196
- package/src/components/scene-transitions.tsx +0 -130
- package/src/components/section-ribbon.tsx +0 -94
- package/src/components/select-field.tsx +0 -27
- package/src/components/select.tsx +0 -81
- package/src/components/separator.tsx +0 -58
- package/src/components/sheet.tsx +0 -96
- package/src/components/skeleton.tsx +0 -35
- package/src/components/sketch-annotation.tsx +0 -87
- package/src/components/smart-button-box.tsx +0 -114
- package/src/components/speech-bubble.tsx +0 -116
- package/src/components/spinner.tsx +0 -69
- package/src/components/sprite-player.tsx +0 -412
- package/src/components/status-bar.tsx +0 -63
- package/src/components/status-pill.tsx +0 -68
- package/src/components/switch.tsx +0 -76
- package/src/components/table.tsx +0 -163
- package/src/components/tabs.tsx +0 -101
- package/src/components/tag-input.tsx +0 -170
- package/src/components/textarea.tsx +0 -25
- package/src/components/toast.tsx +0 -14
- package/src/components/toolbar.tsx +0 -39
- package/src/components/tooltip.tsx +0 -49
- package/src/components/update-banner.tsx +0 -220
- package/src/components/xv-primitives.tsx +0 -256
- package/src/css-exports.ts +0 -142
- package/src/dna.tsx +0 -137
- package/src/game/boss-hud.tsx +0 -384
- package/src/game/index.tsx +0 -886
- package/src/game/tactical.tsx +0 -245
- package/src/game.tsx +0 -770
- package/src/icons/activity.tsx +0 -38
- package/src/icons/add.tsx +0 -38
- package/src/icons/addon.tsx +0 -37
- package/src/icons/anime-anger.tsx +0 -37
- package/src/icons/anime-shock.tsx +0 -37
- package/src/icons/anime-sparkle.tsx +0 -38
- package/src/icons/anime-sweatdrop.tsx +0 -38
- package/src/icons/archive.tsx +0 -37
- package/src/icons/arrow-left.tsx +0 -37
- package/src/icons/arrow-right.tsx +0 -37
- package/src/icons/attachment.tsx +0 -38
- package/src/icons/bank.tsx +0 -37
- package/src/icons/bolt.tsx +0 -37
- package/src/icons/book-open.tsx +0 -37
- package/src/icons/bookmark.tsx +0 -37
- package/src/icons/boss-skull.tsx +0 -40
- package/src/icons/calendar-clock.tsx +0 -40
- package/src/icons/calendar.tsx +0 -38
- package/src/icons/check-circle.tsx +0 -38
- package/src/icons/check-square.tsx +0 -38
- package/src/icons/check.tsx +0 -37
- package/src/icons/chevron-right.tsx +0 -37
- package/src/icons/chevrons-left.tsx +0 -37
- package/src/icons/chevrons-right.tsx +0 -37
- package/src/icons/clapperboard.tsx +0 -38
- package/src/icons/clock.tsx +0 -38
- package/src/icons/close.tsx +0 -37
- package/src/icons/code.tsx +0 -37
- package/src/icons/columns.tsx +0 -38
- package/src/icons/combo-flame.tsx +0 -38
- package/src/icons/company.tsx +0 -38
- package/src/icons/credit-card.tsx +0 -38
- package/src/icons/critical-star.tsx +0 -37
- package/src/icons/currency.tsx +0 -38
- package/src/icons/delete.tsx +0 -37
- package/src/icons/document.tsx +0 -38
- package/src/icons/download.tsx +0 -37
- package/src/icons/dpad.tsx +0 -38
- package/src/icons/edit.tsx +0 -38
- package/src/icons/element-fire.tsx +0 -37
- package/src/icons/element-ice.tsx +0 -38
- package/src/icons/element-solar.tsx +0 -38
- package/src/icons/element-void.tsx +0 -38
- package/src/icons/element-volt.tsx +0 -38
- package/src/icons/element-wind.tsx +0 -37
- package/src/icons/error.tsx +0 -38
- package/src/icons/external-link.tsx +0 -38
- package/src/icons/field.tsx +0 -38
- package/src/icons/file-spreadsheet.tsx +0 -38
- package/src/icons/filter.tsx +0 -37
- package/src/icons/gacha-ticket.tsx +0 -38
- package/src/icons/gamepad.tsx +0 -40
- package/src/icons/globe.tsx +0 -38
- package/src/icons/grid.tsx +0 -40
- package/src/icons/hash.tsx +0 -37
- package/src/icons/heart-hp.tsx +0 -38
- package/src/icons/history.tsx +0 -37
- package/src/icons/home.tsx +0 -37
- package/src/icons/image.tsx +0 -39
- package/src/icons/impact-slash.tsx +0 -38
- package/src/icons/inbox.tsx +0 -38
- package/src/icons/index.ts +0 -120
- package/src/icons/info.tsx +0 -38
- package/src/icons/jobs.tsx +0 -38
- package/src/icons/katana.tsx +0 -38
- package/src/icons/key.tsx +0 -38
- package/src/icons/keyboard.tsx +0 -38
- package/src/icons/keyframe-diamond.tsx +0 -38
- package/src/icons/knowledge.tsx +0 -38
- package/src/icons/language.tsx +0 -39
- package/src/icons/lock.tsx +0 -38
- package/src/icons/logout.tsx +0 -37
- package/src/icons/loot-chest.tsx +0 -39
- package/src/icons/mail.tsx +0 -38
- package/src/icons/mana-crystal.tsx +0 -38
- package/src/icons/map-pin.tsx +0 -38
- package/src/icons/mecha-helm.tsx +0 -38
- package/src/icons/menu.tsx +0 -37
- package/src/icons/message.tsx +0 -38
- package/src/icons/model.tsx +0 -38
- package/src/icons/moon.tsx +0 -37
- package/src/icons/notification.tsx +0 -38
- package/src/icons/partner.tsx +0 -41
- package/src/icons/pause.tsx +0 -37
- package/src/icons/phone.tsx +0 -37
- package/src/icons/play.tsx +0 -37
- package/src/icons/potion-flask.tsx +0 -40
- package/src/icons/quest-scroll.tsx +0 -39
- package/src/icons/radar-ping.tsx +0 -40
- package/src/icons/refresh.tsx +0 -38
- package/src/icons/relation.tsx +0 -40
- package/src/icons/save.tsx +0 -38
- package/src/icons/search.tsx +0 -38
- package/src/icons/security.tsx +0 -38
- package/src/icons/send.tsx +0 -38
- package/src/icons/settings.tsx +0 -39
- package/src/icons/shield-crest.tsx +0 -38
- package/src/icons/shuriken.tsx +0 -38
- package/src/icons/signal-off.tsx +0 -37
- package/src/icons/signal.tsx +0 -37
- package/src/icons/skill-node.tsx +0 -40
- package/src/icons/smartphone.tsx +0 -38
- package/src/icons/sort-ascending.tsx +0 -37
- package/src/icons/sort-descending.tsx +0 -37
- package/src/icons/sort.tsx +0 -37
- package/src/icons/sparkle.tsx +0 -38
- package/src/icons/speech-burst.tsx +0 -37
- package/src/icons/story.tsx +0 -37
- package/src/icons/sun.tsx +0 -38
- package/src/icons/tag.tsx +0 -38
- package/src/icons/team.tsx +0 -40
- package/src/icons/trophy-crown.tsx +0 -39
- package/src/icons/upload.tsx +0 -37
- package/src/icons/user.tsx +0 -38
- package/src/icons/users.tsx +0 -39
- package/src/icons/visibility-off.tsx +0 -38
- package/src/icons/visibility.tsx +0 -38
- package/src/icons/volume-off.tsx +0 -37
- package/src/icons/volume.tsx +0 -37
- package/src/icons/warning.tsx +0 -38
- package/src/icons/workflow.tsx +0 -40
- package/src/icons.tsx +0 -965
- package/src/index.ts +0 -89
- package/src/lib/asset-registry.ts +0 -534
- package/src/lib/audio-runtime.ts +0 -314
- package/src/lib/character-adapter.ts +0 -370
- package/src/lib/character-registry.ts +0 -2368
- package/src/lib/cn.ts +0 -6
- package/src/lib/compose-refs.ts +0 -16
- package/src/lib/sanitize-url.ts +0 -51
- package/src/lib/scene-camera.ts +0 -483
- package/src/lib/scene-playback.ts +0 -622
- package/src/lib/scene-soundscape.ts +0 -151
- package/src/lib/scene-test-harness.ts +0 -200
- package/src/lib/scene-timeline.ts +0 -398
- package/src/lib/use-animation-visibility.ts +0 -45
- package/src/lib/use-modal-focus.ts +0 -270
- package/src/lib/use-reduced-motion.ts +0 -37
- package/src/motion/easing-presets.ts +0 -262
- package/src/motion/index.tsx +0 -894
- package/src/motion/physics.ts +0 -259
- package/src/motion/timeline-math.ts +0 -358
- package/src/motion.tsx +0 -639
- package/src/pixelfx-boundary.ts +0 -188
- package/src/pixelfx-registry.ts +0 -1190
- package/src/pixelfx-types.d.ts +0 -73
- package/src/pixelfx.tsx +0 -1022
- package/src/provider.tsx +0 -63
- package/src/skin-catalog.ts +0 -306
- package/src/skin-tokens.ts +0 -425
- package/src/ssr/init-script.ts +0 -281
- package/src/ssr/resolve-skin.ts +0 -217
- package/src/ssr/theme-mismatch-dev.ts +0 -181
- package/src/templates/battle-arena.tsx +0 -688
- package/src/templates/index.tsx +0 -314
- package/src/templates.tsx +0 -225
- package/src/themes/dna-presets.ts +0 -119
- package/src/themes/index.ts +0 -56
- package/src/themes/provider.tsx +0 -183
- package/src/themes/types.ts +0 -111
- package/src/themes.ts +0 -9
- package/src/token-exporter.ts +0 -12
- package/src/token-exporters.ts +0 -343
- package/src/token-seeds.ts +0 -335
- package/src/token-snapshot.ts +0 -179
- package/src/utils.ts +0 -58
package/src/lib/cn.ts
DELETED
package/src/lib/compose-refs.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ForwardedRef, MutableRefObject, Ref } from "react";
|
|
2
|
-
|
|
3
|
-
type AnyRef<T> = Ref<T> | ForwardedRef<T> | undefined;
|
|
4
|
-
|
|
5
|
-
/** Assign a value to a callback, object, or forwarded ref. */
|
|
6
|
-
export function setRef<T>(ref: AnyRef<T>, value: T | null): void {
|
|
7
|
-
if (typeof ref === "function") ref(value);
|
|
8
|
-
else if (ref) (ref as MutableRefObject<T | null>).current = value;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** Combine an external ref with an internal or child ref without losing either. */
|
|
12
|
-
export function composeRefs<T>(...refs: AnyRef<T>[]) {
|
|
13
|
-
return (value: T | null): void => {
|
|
14
|
-
for (const ref of refs) setRef(ref, value);
|
|
15
|
-
};
|
|
16
|
-
}
|
package/src/lib/sanitize-url.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const SAFE_PROTOCOLS = new Set(["http:", "https:", "mailto:", "tel:"]);
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Validates a caller-supplied URL before binding it to an anchor `href`.
|
|
5
|
-
* Blocks executable schemes such as `javascript:`, `data:`, and `vbscript:`
|
|
6
|
-
* while preserving relative paths, fragment links, and standard web protocols.
|
|
7
|
-
*/
|
|
8
|
-
export function sanitizeUrl(
|
|
9
|
-
url: string | undefined | null,
|
|
10
|
-
): string | undefined {
|
|
11
|
-
if (typeof url !== "string") return undefined;
|
|
12
|
-
const trimmed = url.trim();
|
|
13
|
-
if (!trimmed) return undefined;
|
|
14
|
-
|
|
15
|
-
// Reject ASCII control characters or whitespace-smuggled schemes
|
|
16
|
-
// eslint-disable-next-line no-control-regex
|
|
17
|
-
if (/[\u0000-\u001F\u007F]/.test(trimmed)) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Allow fragment, query, and relative paths (but reject protocol-relative `//`)
|
|
22
|
-
if (
|
|
23
|
-
trimmed.startsWith("#") ||
|
|
24
|
-
trimmed.startsWith("?") ||
|
|
25
|
-
trimmed.startsWith("./") ||
|
|
26
|
-
trimmed.startsWith("../")
|
|
27
|
-
) {
|
|
28
|
-
return trimmed;
|
|
29
|
-
}
|
|
30
|
-
if (trimmed.startsWith("/")) {
|
|
31
|
-
return trimmed.startsWith("//") ? undefined : trimmed;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// If the string has no scheme separator before the first path/query/hash delimiter, treat as relative path
|
|
35
|
-
const schemeMatch = trimmed.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);
|
|
36
|
-
if (!schemeMatch) {
|
|
37
|
-
return trimmed;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const protocol = `${schemeMatch[1].toLowerCase()}:`;
|
|
41
|
-
if (!SAFE_PROTOCOLS.has(protocol)) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const parsed = new URL(trimmed);
|
|
47
|
-
return SAFE_PROTOCOLS.has(parsed.protocol) ? trimmed : undefined;
|
|
48
|
-
} catch {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
}
|
package/src/lib/scene-camera.ts
DELETED
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
export interface CameraState {
|
|
2
|
-
readonly x: number;
|
|
3
|
-
readonly y: number;
|
|
4
|
-
readonly zoom: number;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface CameraBounds {
|
|
8
|
-
readonly minX: number;
|
|
9
|
-
readonly maxX: number;
|
|
10
|
-
readonly minY: number;
|
|
11
|
-
readonly maxY: number;
|
|
12
|
-
readonly minZoom: number;
|
|
13
|
-
readonly maxZoom: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ParallaxInput {
|
|
17
|
-
readonly x: number;
|
|
18
|
-
readonly y: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ParallaxOffset {
|
|
22
|
-
readonly translateX: number;
|
|
23
|
-
readonly translateY: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface SceneCameraOptions {
|
|
27
|
-
readonly bounds?: Partial<CameraBounds>;
|
|
28
|
-
readonly initial?: Partial<CameraState>;
|
|
29
|
-
readonly reducedMotion?: boolean;
|
|
30
|
-
readonly operationalMode?: boolean;
|
|
31
|
-
readonly pointerStrength?: number;
|
|
32
|
-
readonly scrollStrength?: number;
|
|
33
|
-
readonly panStep?: number;
|
|
34
|
-
readonly zoomStep?: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface KeyboardCameraActionOptions {
|
|
38
|
-
readonly panStep?: number;
|
|
39
|
-
readonly zoomStep?: number;
|
|
40
|
-
readonly reducedMotion?: boolean;
|
|
41
|
-
readonly operationalMode?: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface KeyboardCameraActionResult {
|
|
45
|
-
readonly handled: boolean;
|
|
46
|
-
readonly state: CameraState;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface KeyboardEventLike {
|
|
50
|
-
readonly key: string;
|
|
51
|
-
preventDefault?: () => void;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type SceneCameraListener = (state: CameraState) => void;
|
|
55
|
-
|
|
56
|
-
export interface SceneCameraController {
|
|
57
|
-
getState(): CameraState;
|
|
58
|
-
getRawState(): CameraState;
|
|
59
|
-
getBounds(): CameraBounds;
|
|
60
|
-
setCamera(next: Partial<CameraState>): CameraState;
|
|
61
|
-
panBy(deltaX: number, deltaY: number): CameraState;
|
|
62
|
-
zoomBy(deltaZoom: number): CameraState;
|
|
63
|
-
setPointer(normalizedX: number, normalizedY: number): CameraState;
|
|
64
|
-
setScrollProgress(progress: number): CameraState;
|
|
65
|
-
setReducedMotion(reduced: boolean): CameraState;
|
|
66
|
-
setOperationalMode(operational: boolean): CameraState;
|
|
67
|
-
handleKeyDown(event: KeyboardEventLike): KeyboardCameraActionResult;
|
|
68
|
-
reset(): CameraState;
|
|
69
|
-
computeParallax(parallax: ParallaxInput, maxShiftPx?: number): ParallaxOffset;
|
|
70
|
-
subscribe(listener: SceneCameraListener): () => void;
|
|
71
|
-
dispose(): void;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const DEFAULT_CAMERA_BOUNDS: CameraBounds = {
|
|
75
|
-
minX: -1,
|
|
76
|
-
maxX: 1,
|
|
77
|
-
minY: -1,
|
|
78
|
-
maxY: 1,
|
|
79
|
-
minZoom: 1,
|
|
80
|
-
maxZoom: 1.35,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const IDENTITY_CAMERA: CameraState = {
|
|
84
|
-
x: 0,
|
|
85
|
-
y: 0,
|
|
86
|
-
zoom: 1,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const DEFAULT_PAN_STEP = 0.15;
|
|
90
|
-
const DEFAULT_ZOOM_STEP = 0.1;
|
|
91
|
-
const DEFAULT_POINTER_STRENGTH = 0.35;
|
|
92
|
-
const DEFAULT_SCROLL_STRENGTH = 0.25;
|
|
93
|
-
const DEFAULT_MAX_PARALLAX_SHIFT_PX = 24;
|
|
94
|
-
|
|
95
|
-
function clampNumber(value: number, min: number, max: number): number {
|
|
96
|
-
if (!Number.isFinite(value)) return min;
|
|
97
|
-
const clamped = Math.min(max, Math.max(min, value));
|
|
98
|
-
return Object.is(clamped, -0) ? 0 : clamped;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function normalizeZero(value: number): number {
|
|
102
|
-
return Object.is(value, -0) ? 0 : value;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function resolveCameraBounds(bounds?: Partial<CameraBounds>): CameraBounds {
|
|
106
|
-
const minX = Number.isFinite(bounds?.minX)
|
|
107
|
-
? (bounds!.minX as number)
|
|
108
|
-
: DEFAULT_CAMERA_BOUNDS.minX;
|
|
109
|
-
const maxX = Number.isFinite(bounds?.maxX)
|
|
110
|
-
? (bounds!.maxX as number)
|
|
111
|
-
: DEFAULT_CAMERA_BOUNDS.maxX;
|
|
112
|
-
const minY = Number.isFinite(bounds?.minY)
|
|
113
|
-
? (bounds!.minY as number)
|
|
114
|
-
: DEFAULT_CAMERA_BOUNDS.minY;
|
|
115
|
-
const maxY = Number.isFinite(bounds?.maxY)
|
|
116
|
-
? (bounds!.maxY as number)
|
|
117
|
-
: DEFAULT_CAMERA_BOUNDS.maxY;
|
|
118
|
-
const minZoom =
|
|
119
|
-
Number.isFinite(bounds?.minZoom) && (bounds!.minZoom as number) > 0
|
|
120
|
-
? (bounds!.minZoom as number)
|
|
121
|
-
: DEFAULT_CAMERA_BOUNDS.minZoom;
|
|
122
|
-
const maxZoom =
|
|
123
|
-
Number.isFinite(bounds?.maxZoom) && (bounds!.maxZoom as number) > 0
|
|
124
|
-
? (bounds!.maxZoom as number)
|
|
125
|
-
: DEFAULT_CAMERA_BOUNDS.maxZoom;
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
minX: Math.min(minX, maxX),
|
|
129
|
-
maxX: Math.max(minX, maxX),
|
|
130
|
-
minY: Math.min(minY, maxY),
|
|
131
|
-
maxY: Math.max(minY, maxY),
|
|
132
|
-
minZoom: Math.min(minZoom, maxZoom),
|
|
133
|
-
maxZoom: Math.max(minZoom, maxZoom),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function clampCameraState(
|
|
138
|
-
candidate: Partial<CameraState>,
|
|
139
|
-
bounds: CameraBounds,
|
|
140
|
-
): CameraState {
|
|
141
|
-
const baseX = candidate.x ?? 0;
|
|
142
|
-
const baseY = candidate.y ?? 0;
|
|
143
|
-
const baseZoom = candidate.zoom ?? 1;
|
|
144
|
-
return {
|
|
145
|
-
x: clampNumber(baseX, bounds.minX, bounds.maxX),
|
|
146
|
-
y: clampNumber(baseY, bounds.minY, bounds.maxY),
|
|
147
|
-
zoom: clampNumber(baseZoom, bounds.minZoom, bounds.maxZoom),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function isSameCamera(first: CameraState, second: CameraState): boolean {
|
|
152
|
-
return (
|
|
153
|
-
first.x === second.x && first.y === second.y && first.zoom === second.zoom
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function computeLayerParallax(
|
|
158
|
-
camera: CameraState,
|
|
159
|
-
parallax: ParallaxInput,
|
|
160
|
-
options?: {
|
|
161
|
-
readonly reducedMotion?: boolean;
|
|
162
|
-
readonly operationalMode?: boolean;
|
|
163
|
-
readonly maxShiftPx?: number;
|
|
164
|
-
},
|
|
165
|
-
): ParallaxOffset {
|
|
166
|
-
if (options?.reducedMotion || options?.operationalMode) {
|
|
167
|
-
return { translateX: 0, translateY: 0 };
|
|
168
|
-
}
|
|
169
|
-
const maxShiftPx =
|
|
170
|
-
typeof options?.maxShiftPx === "number" &&
|
|
171
|
-
Number.isFinite(options.maxShiftPx) &&
|
|
172
|
-
options.maxShiftPx >= 0
|
|
173
|
-
? options.maxShiftPx
|
|
174
|
-
: DEFAULT_MAX_PARALLAX_SHIFT_PX;
|
|
175
|
-
const factorX = clampNumber(parallax.x, -1, 1);
|
|
176
|
-
const factorY = clampNumber(parallax.y, -1, 1);
|
|
177
|
-
const translateX = normalizeZero(-camera.x * factorX * maxShiftPx);
|
|
178
|
-
const translateY = normalizeZero(-camera.y * factorY * maxShiftPx);
|
|
179
|
-
return { translateX, translateY };
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function applyKeyboardCameraAction(
|
|
183
|
-
state: CameraState,
|
|
184
|
-
key: string,
|
|
185
|
-
bounds?: Partial<CameraBounds>,
|
|
186
|
-
options?: KeyboardCameraActionOptions,
|
|
187
|
-
): KeyboardCameraActionResult {
|
|
188
|
-
if (options?.reducedMotion || options?.operationalMode) {
|
|
189
|
-
return { handled: false, state: IDENTITY_CAMERA };
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const resolvedBounds = resolveCameraBounds(bounds);
|
|
193
|
-
const panStep =
|
|
194
|
-
typeof options?.panStep === "number" &&
|
|
195
|
-
Number.isFinite(options.panStep) &&
|
|
196
|
-
options.panStep > 0
|
|
197
|
-
? options.panStep
|
|
198
|
-
: DEFAULT_PAN_STEP;
|
|
199
|
-
const zoomStep =
|
|
200
|
-
typeof options?.zoomStep === "number" &&
|
|
201
|
-
Number.isFinite(options.zoomStep) &&
|
|
202
|
-
options.zoomStep > 0
|
|
203
|
-
? options.zoomStep
|
|
204
|
-
: DEFAULT_ZOOM_STEP;
|
|
205
|
-
|
|
206
|
-
switch (key) {
|
|
207
|
-
case "ArrowLeft":
|
|
208
|
-
return {
|
|
209
|
-
handled: true,
|
|
210
|
-
state: clampCameraState(
|
|
211
|
-
{ x: state.x - panStep, y: state.y, zoom: state.zoom },
|
|
212
|
-
resolvedBounds,
|
|
213
|
-
),
|
|
214
|
-
};
|
|
215
|
-
case "ArrowRight":
|
|
216
|
-
return {
|
|
217
|
-
handled: true,
|
|
218
|
-
state: clampCameraState(
|
|
219
|
-
{ x: state.x + panStep, y: state.y, zoom: state.zoom },
|
|
220
|
-
resolvedBounds,
|
|
221
|
-
),
|
|
222
|
-
};
|
|
223
|
-
case "ArrowUp":
|
|
224
|
-
return {
|
|
225
|
-
handled: true,
|
|
226
|
-
state: clampCameraState(
|
|
227
|
-
{ x: state.x, y: state.y - panStep, zoom: state.zoom },
|
|
228
|
-
resolvedBounds,
|
|
229
|
-
),
|
|
230
|
-
};
|
|
231
|
-
case "ArrowDown":
|
|
232
|
-
return {
|
|
233
|
-
handled: true,
|
|
234
|
-
state: clampCameraState(
|
|
235
|
-
{ x: state.x, y: state.y + panStep, zoom: state.zoom },
|
|
236
|
-
resolvedBounds,
|
|
237
|
-
),
|
|
238
|
-
};
|
|
239
|
-
case "+":
|
|
240
|
-
case "=":
|
|
241
|
-
return {
|
|
242
|
-
handled: true,
|
|
243
|
-
state: clampCameraState(
|
|
244
|
-
{ x: state.x, y: state.y, zoom: state.zoom + zoomStep },
|
|
245
|
-
resolvedBounds,
|
|
246
|
-
),
|
|
247
|
-
};
|
|
248
|
-
case "-":
|
|
249
|
-
case "_":
|
|
250
|
-
return {
|
|
251
|
-
handled: true,
|
|
252
|
-
state: clampCameraState(
|
|
253
|
-
{ x: state.x, y: state.y, zoom: state.zoom - zoomStep },
|
|
254
|
-
resolvedBounds,
|
|
255
|
-
),
|
|
256
|
-
};
|
|
257
|
-
case "0":
|
|
258
|
-
case "Home":
|
|
259
|
-
return {
|
|
260
|
-
handled: true,
|
|
261
|
-
state: clampCameraState(IDENTITY_CAMERA, resolvedBounds),
|
|
262
|
-
};
|
|
263
|
-
default:
|
|
264
|
-
return {
|
|
265
|
-
handled: false,
|
|
266
|
-
state: clampCameraState(state, resolvedBounds),
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export function createSceneCameraController(
|
|
272
|
-
options: SceneCameraOptions = {},
|
|
273
|
-
): SceneCameraController {
|
|
274
|
-
const bounds = resolveCameraBounds(options.bounds);
|
|
275
|
-
const pointerStrength = clampNumber(
|
|
276
|
-
options.pointerStrength ?? DEFAULT_POINTER_STRENGTH,
|
|
277
|
-
0,
|
|
278
|
-
1,
|
|
279
|
-
);
|
|
280
|
-
const scrollStrength = clampNumber(
|
|
281
|
-
options.scrollStrength ?? DEFAULT_SCROLL_STRENGTH,
|
|
282
|
-
0,
|
|
283
|
-
1,
|
|
284
|
-
);
|
|
285
|
-
const panStep =
|
|
286
|
-
typeof options.panStep === "number" &&
|
|
287
|
-
Number.isFinite(options.panStep) &&
|
|
288
|
-
options.panStep > 0
|
|
289
|
-
? options.panStep
|
|
290
|
-
: DEFAULT_PAN_STEP;
|
|
291
|
-
const zoomStep =
|
|
292
|
-
typeof options.zoomStep === "number" &&
|
|
293
|
-
Number.isFinite(options.zoomStep) &&
|
|
294
|
-
options.zoomStep > 0
|
|
295
|
-
? options.zoomStep
|
|
296
|
-
: DEFAULT_ZOOM_STEP;
|
|
297
|
-
|
|
298
|
-
let reducedMotion = Boolean(options.reducedMotion);
|
|
299
|
-
let operationalMode = Boolean(options.operationalMode);
|
|
300
|
-
let manualState: CameraState = clampCameraState(
|
|
301
|
-
options.initial ?? IDENTITY_CAMERA,
|
|
302
|
-
bounds,
|
|
303
|
-
);
|
|
304
|
-
let pointerOffsetX = 0;
|
|
305
|
-
let pointerOffsetY = 0;
|
|
306
|
-
let scrollOffsetY = 0;
|
|
307
|
-
let disposed = false;
|
|
308
|
-
const listeners = new Set<SceneCameraListener>();
|
|
309
|
-
|
|
310
|
-
function computeRawState(): CameraState {
|
|
311
|
-
return clampCameraState(
|
|
312
|
-
{
|
|
313
|
-
x: manualState.x + pointerOffsetX,
|
|
314
|
-
y: manualState.y + pointerOffsetY + scrollOffsetY,
|
|
315
|
-
zoom: manualState.zoom,
|
|
316
|
-
},
|
|
317
|
-
bounds,
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function computeEffectiveState(): CameraState {
|
|
322
|
-
if (reducedMotion || operationalMode) {
|
|
323
|
-
return IDENTITY_CAMERA;
|
|
324
|
-
}
|
|
325
|
-
return computeRawState();
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
let lastEmittedState = computeEffectiveState();
|
|
329
|
-
|
|
330
|
-
function notifyIfChanged(): CameraState {
|
|
331
|
-
const nextState = computeEffectiveState();
|
|
332
|
-
if (!disposed && !isSameCamera(lastEmittedState, nextState)) {
|
|
333
|
-
lastEmittedState = nextState;
|
|
334
|
-
for (const listener of listeners) {
|
|
335
|
-
listener(nextState);
|
|
336
|
-
}
|
|
337
|
-
} else {
|
|
338
|
-
lastEmittedState = nextState;
|
|
339
|
-
}
|
|
340
|
-
return nextState;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return {
|
|
344
|
-
getState(): CameraState {
|
|
345
|
-
return computeEffectiveState();
|
|
346
|
-
},
|
|
347
|
-
|
|
348
|
-
getRawState(): CameraState {
|
|
349
|
-
return computeRawState();
|
|
350
|
-
},
|
|
351
|
-
|
|
352
|
-
getBounds(): CameraBounds {
|
|
353
|
-
return bounds;
|
|
354
|
-
},
|
|
355
|
-
|
|
356
|
-
setCamera(next: Partial<CameraState>): CameraState {
|
|
357
|
-
if (disposed) return computeEffectiveState();
|
|
358
|
-
manualState = clampCameraState(
|
|
359
|
-
{
|
|
360
|
-
x: next.x ?? manualState.x,
|
|
361
|
-
y: next.y ?? manualState.y,
|
|
362
|
-
zoom: next.zoom ?? manualState.zoom,
|
|
363
|
-
},
|
|
364
|
-
bounds,
|
|
365
|
-
);
|
|
366
|
-
return notifyIfChanged();
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
panBy(deltaX: number, deltaY: number): CameraState {
|
|
370
|
-
if (disposed) return computeEffectiveState();
|
|
371
|
-
const safeDeltaX = Number.isFinite(deltaX) ? deltaX : 0;
|
|
372
|
-
const safeDeltaY = Number.isFinite(deltaY) ? deltaY : 0;
|
|
373
|
-
manualState = clampCameraState(
|
|
374
|
-
{
|
|
375
|
-
x: manualState.x + safeDeltaX,
|
|
376
|
-
y: manualState.y + safeDeltaY,
|
|
377
|
-
zoom: manualState.zoom,
|
|
378
|
-
},
|
|
379
|
-
bounds,
|
|
380
|
-
);
|
|
381
|
-
return notifyIfChanged();
|
|
382
|
-
},
|
|
383
|
-
|
|
384
|
-
zoomBy(deltaZoom: number): CameraState {
|
|
385
|
-
if (disposed) return computeEffectiveState();
|
|
386
|
-
const safeDelta = Number.isFinite(deltaZoom) ? deltaZoom : 0;
|
|
387
|
-
manualState = clampCameraState(
|
|
388
|
-
{
|
|
389
|
-
x: manualState.x,
|
|
390
|
-
y: manualState.y,
|
|
391
|
-
zoom: manualState.zoom + safeDelta,
|
|
392
|
-
},
|
|
393
|
-
bounds,
|
|
394
|
-
);
|
|
395
|
-
return notifyIfChanged();
|
|
396
|
-
},
|
|
397
|
-
|
|
398
|
-
setPointer(normalizedX: number, normalizedY: number): CameraState {
|
|
399
|
-
if (disposed) return computeEffectiveState();
|
|
400
|
-
const clampedX = clampNumber(normalizedX, -1, 1);
|
|
401
|
-
const clampedY = clampNumber(normalizedY, -1, 1);
|
|
402
|
-
pointerOffsetX = normalizeZero(clampedX * pointerStrength);
|
|
403
|
-
pointerOffsetY = normalizeZero(clampedY * pointerStrength);
|
|
404
|
-
return notifyIfChanged();
|
|
405
|
-
},
|
|
406
|
-
|
|
407
|
-
setScrollProgress(progress: number): CameraState {
|
|
408
|
-
if (disposed) return computeEffectiveState();
|
|
409
|
-
const clampedProgress = clampNumber(progress, 0, 1);
|
|
410
|
-
const centered = clampedProgress * 2 - 1;
|
|
411
|
-
scrollOffsetY = normalizeZero(centered * scrollStrength);
|
|
412
|
-
return notifyIfChanged();
|
|
413
|
-
},
|
|
414
|
-
|
|
415
|
-
setReducedMotion(reduced: boolean): CameraState {
|
|
416
|
-
if (disposed) return computeEffectiveState();
|
|
417
|
-
reducedMotion = Boolean(reduced);
|
|
418
|
-
return notifyIfChanged();
|
|
419
|
-
},
|
|
420
|
-
|
|
421
|
-
setOperationalMode(operational: boolean): CameraState {
|
|
422
|
-
if (disposed) return computeEffectiveState();
|
|
423
|
-
operationalMode = Boolean(operational);
|
|
424
|
-
return notifyIfChanged();
|
|
425
|
-
},
|
|
426
|
-
|
|
427
|
-
handleKeyDown(event: KeyboardEventLike): KeyboardCameraActionResult {
|
|
428
|
-
if (disposed) {
|
|
429
|
-
return { handled: false, state: computeEffectiveState() };
|
|
430
|
-
}
|
|
431
|
-
const result = applyKeyboardCameraAction(manualState, event.key, bounds, {
|
|
432
|
-
panStep,
|
|
433
|
-
zoomStep,
|
|
434
|
-
reducedMotion,
|
|
435
|
-
operationalMode,
|
|
436
|
-
});
|
|
437
|
-
if (result.handled) {
|
|
438
|
-
event.preventDefault?.();
|
|
439
|
-
if (event.key === "0" || event.key === "Home") {
|
|
440
|
-
pointerOffsetX = 0;
|
|
441
|
-
pointerOffsetY = 0;
|
|
442
|
-
scrollOffsetY = 0;
|
|
443
|
-
}
|
|
444
|
-
manualState = result.state;
|
|
445
|
-
return { handled: true, state: notifyIfChanged() };
|
|
446
|
-
}
|
|
447
|
-
return { handled: false, state: computeEffectiveState() };
|
|
448
|
-
},
|
|
449
|
-
|
|
450
|
-
reset(): CameraState {
|
|
451
|
-
if (disposed) return computeEffectiveState();
|
|
452
|
-
manualState = clampCameraState(IDENTITY_CAMERA, bounds);
|
|
453
|
-
pointerOffsetX = 0;
|
|
454
|
-
pointerOffsetY = 0;
|
|
455
|
-
scrollOffsetY = 0;
|
|
456
|
-
return notifyIfChanged();
|
|
457
|
-
},
|
|
458
|
-
|
|
459
|
-
computeParallax(
|
|
460
|
-
parallax: ParallaxInput,
|
|
461
|
-
maxShiftPx?: number,
|
|
462
|
-
): ParallaxOffset {
|
|
463
|
-
return computeLayerParallax(computeEffectiveState(), parallax, {
|
|
464
|
-
reducedMotion,
|
|
465
|
-
operationalMode,
|
|
466
|
-
maxShiftPx,
|
|
467
|
-
});
|
|
468
|
-
},
|
|
469
|
-
|
|
470
|
-
subscribe(listener: SceneCameraListener): () => void {
|
|
471
|
-
if (disposed) return () => {};
|
|
472
|
-
listeners.add(listener);
|
|
473
|
-
return () => {
|
|
474
|
-
listeners.delete(listener);
|
|
475
|
-
};
|
|
476
|
-
},
|
|
477
|
-
|
|
478
|
-
dispose(): void {
|
|
479
|
-
disposed = true;
|
|
480
|
-
listeners.clear();
|
|
481
|
-
},
|
|
482
|
-
};
|
|
483
|
-
}
|