@caperjs/core 0.1.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/LICENSE +22 -0
- package/README.md +62 -0
- package/cli/add.mjs +197 -0
- package/cli/audio/cc.mjs +128 -0
- package/cli/audio/index.mjs +42 -0
- package/cli/audio/utils.mjs +56 -0
- package/cli/create-caper.mjs +8 -0
- package/cli/create.mjs +351 -0
- package/cli/install-peerdeps.mjs +57 -0
- package/cli/update.mjs +9 -0
- package/cli/utils.mjs +81 -0
- package/cli/vite.mjs +55 -0
- package/cli/voiceover/generateVoiceoverCSV.mjs +158 -0
- package/cli/voiceover/index.mjs +1 -0
- package/cli.mjs +157 -0
- package/client.d.ts +7 -0
- package/config/assetpack.mjs +212 -0
- package/config/tsconfig.base.json +28 -0
- package/config/vite.mjs +2464 -0
- package/extras/css/accessibility.css +9 -0
- package/extras/css/fullscreen.css +28 -0
- package/extras/css/loader.css +67 -0
- package/extras/llms.txt +1602 -0
- package/lib/CaptionsPlugin-Dc8fIrjy.js +277 -0
- package/lib/CaptionsPlugin-Dc8fIrjy.js.map +1 -0
- package/lib/DataAdapter-BY2114sp.js +84 -0
- package/lib/DataAdapter-BY2114sp.js.map +1 -0
- package/lib/DebugRenderer-BJMLILqI.js +1385 -0
- package/lib/DebugRenderer-BJMLILqI.js.map +1 -0
- package/lib/DevToolsPlugin-wQ5rOkn0.js +31 -0
- package/lib/DevToolsPlugin-wQ5rOkn0.js.map +1 -0
- package/lib/GSAPPlugin-DHhSZKv8.js +350 -0
- package/lib/GSAPPlugin-DHhSZKv8.js.map +1 -0
- package/lib/LayoutPlugin-B-DF9SYM.js +1271 -0
- package/lib/LayoutPlugin-B-DF9SYM.js.map +1 -0
- package/lib/SpinePlugin-Dz_3dljz.js +6077 -0
- package/lib/SpinePlugin-Dz_3dljz.js.map +1 -0
- package/lib/StatsPlugin-Cg82JMBD.js +70 -0
- package/lib/StatsPlugin-Cg82JMBD.js.map +1 -0
- package/lib/VoiceOverPlugin-BR3ImT8C.js +114 -0
- package/lib/VoiceOverPlugin-BR3ImT8C.js.map +1 -0
- package/lib/caper.mjs +1233 -0
- package/lib/caper.mjs.map +1 -0
- package/lib/core/Application.d.ts +268 -0
- package/lib/core/Application.d.ts.map +1 -0
- package/lib/core/config.d.ts +39 -0
- package/lib/core/config.d.ts.map +1 -0
- package/lib/core/create.d.ts +41 -0
- package/lib/core/create.d.ts.map +1 -0
- package/lib/core/globals.d.ts +51 -0
- package/lib/core/globals.d.ts.map +1 -0
- package/lib/core/index.d.ts +7 -0
- package/lib/core/index.d.ts.map +1 -0
- package/lib/core/interfaces/IApplication.d.ts +566 -0
- package/lib/core/interfaces/IApplication.d.ts.map +1 -0
- package/lib/core/interfaces/IApplicationOptions.d.ts +65 -0
- package/lib/core/interfaces/IApplicationOptions.d.ts.map +1 -0
- package/lib/core/interfaces/ICoreFunctions.d.ts +49 -0
- package/lib/core/interfaces/ICoreFunctions.d.ts.map +1 -0
- package/lib/core/interfaces/ICoreSignals.d.ts +57 -0
- package/lib/core/interfaces/ICoreSignals.d.ts.map +1 -0
- package/lib/core/interfaces/IStorageCapability.d.ts +20 -0
- package/lib/core/interfaces/IStorageCapability.d.ts.map +1 -0
- package/lib/core/interfaces/IStorageCapability.test.d.ts +2 -0
- package/lib/core/interfaces/IStorageCapability.test.d.ts.map +1 -0
- package/lib/core/interfaces/index.d.ts +7 -0
- package/lib/core/interfaces/index.d.ts.map +1 -0
- package/lib/core/registries.d.ts +8 -0
- package/lib/core/registries.d.ts.map +1 -0
- package/lib/core/types.d.ts +12 -0
- package/lib/core/types.d.ts.map +1 -0
- package/lib/display/AnimatedSprite.d.ts +40 -0
- package/lib/display/AnimatedSprite.d.ts.map +1 -0
- package/lib/display/Camera.d.ts +102 -0
- package/lib/display/Camera.d.ts.map +1 -0
- package/lib/display/Container.d.ts +115 -0
- package/lib/display/Container.d.ts.map +1 -0
- package/lib/display/Entity.d.ts +46 -0
- package/lib/display/Entity.d.ts.map +1 -0
- package/lib/display/ParticleContainer.d.ts +58 -0
- package/lib/display/ParticleContainer.d.ts.map +1 -0
- package/lib/display/Scene.d.ts +250 -0
- package/lib/display/Scene.d.ts.map +1 -0
- package/lib/display/SceneTransition.d.ts +41 -0
- package/lib/display/SceneTransition.d.ts.map +1 -0
- package/lib/display/SpineAnimation.d.ts +76 -0
- package/lib/display/SpineAnimation.d.ts.map +1 -0
- package/lib/display/Svg.d.ts +5 -0
- package/lib/display/Svg.d.ts.map +1 -0
- package/lib/display/index.d.ts +10 -0
- package/lib/display/index.d.ts.map +1 -0
- package/lib/env.d.ts +6 -0
- package/lib/hello.d.ts +2 -0
- package/lib/hello.d.ts.map +1 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/mixins/animated.d.ts +53 -0
- package/lib/mixins/animated.d.ts.map +1 -0
- package/lib/mixins/factory/Factory.d.ts +8 -0
- package/lib/mixins/factory/Factory.d.ts.map +1 -0
- package/lib/mixins/factory/const.d.ts +67 -0
- package/lib/mixins/factory/const.d.ts.map +1 -0
- package/lib/mixins/factory/index.d.ts +8 -0
- package/lib/mixins/factory/index.d.ts.map +1 -0
- package/lib/mixins/factory/methods.d.ts +3 -0
- package/lib/mixins/factory/methods.d.ts.map +1 -0
- package/lib/mixins/factory/props.d.ts +160 -0
- package/lib/mixins/factory/props.d.ts.map +1 -0
- package/lib/mixins/factory/registry.d.ts +27 -0
- package/lib/mixins/factory/registry.d.ts.map +1 -0
- package/lib/mixins/factory/registry.test.d.ts +2 -0
- package/lib/mixins/factory/registry.test.d.ts.map +1 -0
- package/lib/mixins/factory/schema.d.ts +71 -0
- package/lib/mixins/factory/schema.d.ts.map +1 -0
- package/lib/mixins/factory/ui-registry.d.ts +20 -0
- package/lib/mixins/factory/ui-registry.d.ts.map +1 -0
- package/lib/mixins/factory/utils.d.ts +11 -0
- package/lib/mixins/factory/utils.d.ts.map +1 -0
- package/lib/mixins/focus.d.ts +15 -0
- package/lib/mixins/focus.d.ts.map +1 -0
- package/lib/mixins/index.d.ts +6 -0
- package/lib/mixins/index.d.ts.map +1 -0
- package/lib/mixins/interaction.d.ts +20 -0
- package/lib/mixins/interaction.d.ts.map +1 -0
- package/lib/mixins/signals.d.ts +15 -0
- package/lib/mixins/signals.d.ts.map +1 -0
- package/lib/plugins/AssetsPlugin.d.ts +79 -0
- package/lib/plugins/AssetsPlugin.d.ts.map +1 -0
- package/lib/plugins/DataAdapter.d.ts +95 -0
- package/lib/plugins/DataAdapter.d.ts.map +1 -0
- package/lib/plugins/DevToolsPlugin.d.ts +97 -0
- package/lib/plugins/DevToolsPlugin.d.ts.map +1 -0
- package/lib/plugins/FullScreenPlugin.d.ts +240 -0
- package/lib/plugins/FullScreenPlugin.d.ts.map +1 -0
- package/lib/plugins/GSAPPlugin.d.ts +634 -0
- package/lib/plugins/GSAPPlugin.d.ts.map +1 -0
- package/lib/plugins/KeyboardPlugin.d.ts +53 -0
- package/lib/plugins/KeyboardPlugin.d.ts.map +1 -0
- package/lib/plugins/LayoutPlugin.d.ts +100 -0
- package/lib/plugins/LayoutPlugin.d.ts.map +1 -0
- package/lib/plugins/LookupPlugin.d.ts +223 -0
- package/lib/plugins/LookupPlugin.d.ts.map +1 -0
- package/lib/plugins/Plugin.d.ts +132 -0
- package/lib/plugins/Plugin.d.ts.map +1 -0
- package/lib/plugins/Plugin.test.d.ts +2 -0
- package/lib/plugins/Plugin.test.d.ts.map +1 -0
- package/lib/plugins/PopupManagerPlugin.d.ts +108 -0
- package/lib/plugins/PopupManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/ResizerPlugin.d.ts +62 -0
- package/lib/plugins/ResizerPlugin.d.ts.map +1 -0
- package/lib/plugins/SceneManagerPlugin.d.ts +122 -0
- package/lib/plugins/SceneManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/StatsPlugin.d.ts +8 -0
- package/lib/plugins/StatsPlugin.d.ts.map +1 -0
- package/lib/plugins/TimerPlugin.d.ts +401 -0
- package/lib/plugins/TimerPlugin.d.ts.map +1 -0
- package/lib/plugins/WebEventsPlugin.d.ts +60 -0
- package/lib/plugins/WebEventsPlugin.d.ts.map +1 -0
- package/lib/plugins/actions/ActionsPlugin.d.ts +39 -0
- package/lib/plugins/actions/ActionsPlugin.d.ts.map +1 -0
- package/lib/plugins/actions/constants.d.ts +52 -0
- package/lib/plugins/actions/constants.d.ts.map +1 -0
- package/lib/plugins/actions/index.d.ts +5 -0
- package/lib/plugins/actions/index.d.ts.map +1 -0
- package/lib/plugins/actions/methods.d.ts +11 -0
- package/lib/plugins/actions/methods.d.ts.map +1 -0
- package/lib/plugins/actions/types.d.ts +25 -0
- package/lib/plugins/actions/types.d.ts.map +1 -0
- package/lib/plugins/audio/AudioChannel.d.ts +46 -0
- package/lib/plugins/audio/AudioChannel.d.ts.map +1 -0
- package/lib/plugins/audio/AudioChannel.test.d.ts +2 -0
- package/lib/plugins/audio/AudioChannel.test.d.ts.map +1 -0
- package/lib/plugins/audio/AudioInstance.d.ts +79 -0
- package/lib/plugins/audio/AudioInstance.d.ts.map +1 -0
- package/lib/plugins/audio/AudioManagerPlugin.d.ts +323 -0
- package/lib/plugins/audio/AudioManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/audio/VoiceOverPlugin.d.ts +69 -0
- package/lib/plugins/audio/VoiceOverPlugin.d.ts.map +1 -0
- package/lib/plugins/audio/index.d.ts +4 -0
- package/lib/plugins/audio/index.d.ts.map +1 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.d.ts +109 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.d.ts.map +1 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.test.d.ts +2 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.test.d.ts.map +1 -0
- package/lib/plugins/breakpoints/evaluate.d.ts +53 -0
- package/lib/plugins/breakpoints/evaluate.d.ts.map +1 -0
- package/lib/plugins/breakpoints/evaluate.test.d.ts +2 -0
- package/lib/plugins/breakpoints/evaluate.test.d.ts.map +1 -0
- package/lib/plugins/breakpoints/index.d.ts +4 -0
- package/lib/plugins/breakpoints/index.d.ts.map +1 -0
- package/lib/plugins/breakpoints/methods.d.ts +23 -0
- package/lib/plugins/breakpoints/methods.d.ts.map +1 -0
- package/lib/plugins/breakpoints/types.d.ts +70 -0
- package/lib/plugins/breakpoints/types.d.ts.map +1 -0
- package/lib/plugins/captions/CaptionsPlugin.d.ts +150 -0
- package/lib/plugins/captions/CaptionsPlugin.d.ts.map +1 -0
- package/lib/plugins/captions/CaptionsRenderer.d.ts +37 -0
- package/lib/plugins/captions/CaptionsRenderer.d.ts.map +1 -0
- package/lib/plugins/captions/index.d.ts +3 -0
- package/lib/plugins/captions/index.d.ts.map +1 -0
- package/lib/plugins/defaults.d.ts +4 -0
- package/lib/plugins/defaults.d.ts.map +1 -0
- package/lib/plugins/focus/FocusManagerPlugin.d.ts +148 -0
- package/lib/plugins/focus/FocusManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/focus/FocusOutliner.d.ts +32 -0
- package/lib/plugins/focus/FocusOutliner.d.ts.map +1 -0
- package/lib/plugins/focus/index.d.ts +3 -0
- package/lib/plugins/focus/index.d.ts.map +1 -0
- package/lib/plugins/i18nPlugin.d.ts +128 -0
- package/lib/plugins/i18nPlugin.d.ts.map +1 -0
- package/lib/plugins/index.d.ts +18 -0
- package/lib/plugins/index.d.ts.map +1 -0
- package/lib/plugins/input/AbstractControls.d.ts +8 -0
- package/lib/plugins/input/AbstractControls.d.ts.map +1 -0
- package/lib/plugins/input/Controls.d.ts +16 -0
- package/lib/plugins/input/Controls.d.ts.map +1 -0
- package/lib/plugins/input/InputPlugin.d.ts +52 -0
- package/lib/plugins/input/InputPlugin.d.ts.map +1 -0
- package/lib/plugins/input/constants.d.ts +8 -0
- package/lib/plugins/input/constants.d.ts.map +1 -0
- package/lib/plugins/input/index.d.ts +10 -0
- package/lib/plugins/input/index.d.ts.map +1 -0
- package/lib/plugins/input/interfaces.d.ts +30 -0
- package/lib/plugins/input/interfaces.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/KeyboardContols.d.ts +28 -0
- package/lib/plugins/input/keyboard/KeyboardContols.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/index.d.ts +3 -0
- package/lib/plugins/input/keyboard/index.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/interfaces.d.ts +18 -0
- package/lib/plugins/input/keyboard/interfaces.d.ts.map +1 -0
- package/lib/plugins/input/methods.d.ts +4 -0
- package/lib/plugins/input/methods.d.ts.map +1 -0
- package/lib/plugins/input/touch/TouchControls.d.ts +35 -0
- package/lib/plugins/input/touch/TouchControls.d.ts.map +1 -0
- package/lib/plugins/input/touch/constants.d.ts +14 -0
- package/lib/plugins/input/touch/constants.d.ts.map +1 -0
- package/lib/plugins/input/touch/index.d.ts +4 -0
- package/lib/plugins/input/touch/index.d.ts.map +1 -0
- package/lib/plugins/input/touch/interfaces.d.ts +15 -0
- package/lib/plugins/input/touch/interfaces.d.ts.map +1 -0
- package/lib/plugins/input/types.d.ts +32 -0
- package/lib/plugins/input/types.d.ts.map +1 -0
- package/lib/plugins/input/utils.d.ts +23 -0
- package/lib/plugins/input/utils.d.ts.map +1 -0
- package/lib/plugins/spine/SpinePlugin.d.ts +6 -0
- package/lib/plugins/spine/SpinePlugin.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/BatchableSpineSlot.d.ts +31 -0
- package/lib/plugins/spine/pixi-spine/BatchableSpineSlot.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/Spine.d.ts +211 -0
- package/lib/plugins/spine/pixi-spine/Spine.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/SpineDebugRenderer.d.ts +81 -0
- package/lib/plugins/spine/pixi-spine/SpineDebugRenderer.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/SpinePipe.d.ts +21 -0
- package/lib/plugins/spine/pixi-spine/SpinePipe.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/SpineTexture.d.ts +16 -0
- package/lib/plugins/spine/pixi-spine/SpineTexture.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/assets/atlasLoader.d.ts +10 -0
- package/lib/plugins/spine/pixi-spine/assets/atlasLoader.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/assets/skeletonLoader.d.ts +6 -0
- package/lib/plugins/spine/pixi-spine/assets/skeletonLoader.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatchGeometry.d.ts +5 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatchGeometry.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatcher.d.ts +22 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatcher.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintShader.d.ts +5 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintShader.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/darkTintBit.d.ts +51 -0
- package/lib/plugins/spine/pixi-spine/darktint/darkTintBit.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/index.d.ts +9 -0
- package/lib/plugins/spine/pixi-spine/index.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/require-shim.d.ts +34 -0
- package/lib/plugins/spine/pixi-spine/require-shim.d.ts.map +1 -0
- package/lib/registries-CYCaYKZI.js +6885 -0
- package/lib/registries-CYCaYKZI.js.map +1 -0
- package/lib/signals/Signal.d.ts +16 -0
- package/lib/signals/Signal.d.ts.map +1 -0
- package/lib/signals/Signal.test.d.ts +2 -0
- package/lib/signals/Signal.test.d.ts.map +1 -0
- package/lib/signals/index.d.ts +3 -0
- package/lib/signals/index.d.ts.map +1 -0
- package/lib/store/Store.d.ts +56 -0
- package/lib/store/Store.d.ts.map +1 -0
- package/lib/store/Store.test.d.ts +2 -0
- package/lib/store/Store.test.d.ts.map +1 -0
- package/lib/store/index.d.ts +2 -0
- package/lib/store/index.d.ts.map +1 -0
- package/lib/types/framework.d.ts +46 -0
- package/lib/types/gsap.d.ts +23 -0
- package/lib/ui/Button.d.ts +162 -0
- package/lib/ui/Button.d.ts.map +1 -0
- package/lib/ui/FlexContainer.d.ts +109 -0
- package/lib/ui/FlexContainer.d.ts.map +1 -0
- package/lib/ui/Input.d.ts +384 -0
- package/lib/ui/Input.d.ts.map +1 -0
- package/lib/ui/Joystick.d.ts +61 -0
- package/lib/ui/Joystick.d.ts.map +1 -0
- package/lib/ui/Popup.d.ts +109 -0
- package/lib/ui/Popup.d.ts.map +1 -0
- package/lib/ui/Toast.d.ts +131 -0
- package/lib/ui/Toast.d.ts.map +1 -0
- package/lib/ui/Toaster.d.ts +188 -0
- package/lib/ui/Toaster.d.ts.map +1 -0
- package/lib/ui/UICanvas.d.ts +155 -0
- package/lib/ui/UICanvas.d.ts.map +1 -0
- package/lib/ui/index.d.ts +9 -0
- package/lib/ui/index.d.ts.map +1 -0
- package/lib/utils/array.d.ts +11 -0
- package/lib/utils/array.d.ts.map +1 -0
- package/lib/utils/bind.d.ts +21 -0
- package/lib/utils/bind.d.ts.map +1 -0
- package/lib/utils/canvas.d.ts +2 -0
- package/lib/utils/canvas.d.ts.map +1 -0
- package/lib/utils/color.d.ts +66 -0
- package/lib/utils/color.d.ts.map +1 -0
- package/lib/utils/console/Logger.d.ts +15 -0
- package/lib/utils/console/Logger.d.ts.map +1 -0
- package/lib/utils/console/index.d.ts +2 -0
- package/lib/utils/console/index.d.ts.map +1 -0
- package/lib/utils/debug.d.ts +34 -0
- package/lib/utils/debug.d.ts.map +1 -0
- package/lib/utils/define.d.ts +100 -0
- package/lib/utils/define.d.ts.map +1 -0
- package/lib/utils/env.d.ts +4 -0
- package/lib/utils/env.d.ts.map +1 -0
- package/lib/utils/events.d.ts +12 -0
- package/lib/utils/events.d.ts.map +1 -0
- package/lib/utils/framework.d.ts +12 -0
- package/lib/utils/framework.d.ts.map +1 -0
- package/lib/utils/index.d.ts +28 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/map.d.ts +31 -0
- package/lib/utils/map.d.ts.map +1 -0
- package/lib/utils/math.d.ts +15 -0
- package/lib/utils/math.d.ts.map +1 -0
- package/lib/utils/misc.d.ts +13 -0
- package/lib/utils/misc.d.ts.map +1 -0
- package/lib/utils/number.d.ts +2 -0
- package/lib/utils/number.d.ts.map +1 -0
- package/lib/utils/object.d.ts +21 -0
- package/lib/utils/object.d.ts.map +1 -0
- package/lib/utils/padding.d.ts +4 -0
- package/lib/utils/padding.d.ts.map +1 -0
- package/lib/utils/pixi.d.ts +42 -0
- package/lib/utils/pixi.d.ts.map +1 -0
- package/lib/utils/platform.d.ts +20 -0
- package/lib/utils/platform.d.ts.map +1 -0
- package/lib/utils/point.d.ts +66 -0
- package/lib/utils/point.d.ts.map +1 -0
- package/lib/utils/promise/Queue.d.ts +60 -0
- package/lib/utils/promise/Queue.d.ts.map +1 -0
- package/lib/utils/promise/functions.d.ts +14 -0
- package/lib/utils/promise/functions.d.ts.map +1 -0
- package/lib/utils/promise/index.d.ts +3 -0
- package/lib/utils/promise/index.d.ts.map +1 -0
- package/lib/utils/random.d.ts +42 -0
- package/lib/utils/random.d.ts.map +1 -0
- package/lib/utils/rect.d.ts +26 -0
- package/lib/utils/rect.d.ts.map +1 -0
- package/lib/utils/set.d.ts +15 -0
- package/lib/utils/set.d.ts.map +1 -0
- package/lib/utils/string.d.ts +3 -0
- package/lib/utils/string.d.ts.map +1 -0
- package/lib/utils/text.d.ts +3 -0
- package/lib/utils/text.d.ts.map +1 -0
- package/lib/utils/typefilters.d.ts +4 -0
- package/lib/utils/typefilters.d.ts.map +1 -0
- package/lib/utils/types.d.ts +209 -0
- package/lib/utils/types.d.ts.map +1 -0
- package/lib/utils/vite.d.ts +25 -0
- package/lib/utils/vite.d.ts.map +1 -0
- package/lib/utils/web.d.ts +3 -0
- package/lib/utils/web.d.ts.map +1 -0
- package/lib/version.d.ts +3 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/webgl-check.d.ts +2 -0
- package/lib/webgl-check.d.ts.map +1 -0
- package/package.json +138 -0
- package/src/core/Application.ts +1091 -0
- package/src/core/config.ts +168 -0
- package/src/core/create.ts +186 -0
- package/src/core/globals.ts +299 -0
- package/src/core/index.ts +6 -0
- package/src/core/interfaces/IApplication.ts +628 -0
- package/src/core/interfaces/IApplicationOptions.ts +81 -0
- package/src/core/interfaces/ICoreFunctions.ts +86 -0
- package/src/core/interfaces/ICoreSignals.ts +77 -0
- package/src/core/interfaces/IStorageCapability.test.ts +27 -0
- package/src/core/interfaces/IStorageCapability.ts +26 -0
- package/src/core/interfaces/index.ts +6 -0
- package/src/core/registries.ts +7 -0
- package/src/core/types.ts +13 -0
- package/src/display/AnimatedSprite.ts +227 -0
- package/src/display/Camera.ts +371 -0
- package/src/display/Container.ts +240 -0
- package/src/display/Entity.ts +50 -0
- package/src/display/ParticleContainer.ts +107 -0
- package/src/display/Scene.ts +305 -0
- package/src/display/SceneTransition.ts +108 -0
- package/src/display/SpineAnimation.ts +170 -0
- package/src/display/Svg.ts +9 -0
- package/src/display/index.ts +11 -0
- package/src/env.d.ts +6 -0
- package/src/hello.ts +20 -0
- package/src/index.ts +17 -0
- package/src/mixins/animated.ts +340 -0
- package/src/mixins/factory/Factory.ts +24 -0
- package/src/mixins/factory/const.ts +363 -0
- package/src/mixins/factory/index.ts +7 -0
- package/src/mixins/factory/methods.ts +21 -0
- package/src/mixins/factory/props.ts +207 -0
- package/src/mixins/factory/registry.test.ts +83 -0
- package/src/mixins/factory/registry.ts +61 -0
- package/src/mixins/factory/schema.ts +153 -0
- package/src/mixins/factory/ui-registry.ts +54 -0
- package/src/mixins/factory/utils.ts +130 -0
- package/src/mixins/focus.ts +124 -0
- package/src/mixins/index.ts +5 -0
- package/src/mixins/interaction.ts +74 -0
- package/src/mixins/signals.ts +49 -0
- package/src/plugins/AssetsPlugin.ts +407 -0
- package/src/plugins/DataAdapter.ts +259 -0
- package/src/plugins/DevToolsPlugin.ts +103 -0
- package/src/plugins/FullScreenPlugin.ts +359 -0
- package/src/plugins/GSAPPlugin.ts +811 -0
- package/src/plugins/KeyboardPlugin.ts +160 -0
- package/src/plugins/LayoutPlugin.ts +127 -0
- package/src/plugins/LookupPlugin.ts +308 -0
- package/src/plugins/Plugin.test.ts +73 -0
- package/src/plugins/Plugin.ts +200 -0
- package/src/plugins/PopupManagerPlugin.ts +263 -0
- package/src/plugins/ResizerPlugin.ts +220 -0
- package/src/plugins/SceneManagerPlugin.ts +669 -0
- package/src/plugins/StatsPlugin.ts +24 -0
- package/src/plugins/TimerPlugin.ts +841 -0
- package/src/plugins/WebEventsPlugin.ts +132 -0
- package/src/plugins/actions/ActionsPlugin.ts +113 -0
- package/src/plugins/actions/constants.ts +45 -0
- package/src/plugins/actions/index.ts +4 -0
- package/src/plugins/actions/methods.ts +28 -0
- package/src/plugins/actions/types.ts +47 -0
- package/src/plugins/audio/AudioChannel.test.ts +101 -0
- package/src/plugins/audio/AudioChannel.ts +164 -0
- package/src/plugins/audio/AudioInstance.ts +228 -0
- package/src/plugins/audio/AudioManagerPlugin.ts +903 -0
- package/src/plugins/audio/VoiceOverPlugin.ts +354 -0
- package/src/plugins/audio/index.ts +3 -0
- package/src/plugins/breakpoints/BreakpointPlugin.test.ts +228 -0
- package/src/plugins/breakpoints/BreakpointPlugin.ts +293 -0
- package/src/plugins/breakpoints/evaluate.test.ts +239 -0
- package/src/plugins/breakpoints/evaluate.ts +201 -0
- package/src/plugins/breakpoints/index.ts +3 -0
- package/src/plugins/breakpoints/methods.ts +22 -0
- package/src/plugins/breakpoints/types.ts +86 -0
- package/src/plugins/captions/CaptionsPlugin.ts +468 -0
- package/src/plugins/captions/CaptionsRenderer.ts +184 -0
- package/src/plugins/captions/font/Sans.fnt +116 -0
- package/src/plugins/captions/font/Sans.png +0 -0
- package/src/plugins/captions/index.ts +2 -0
- package/src/plugins/defaults.ts +95 -0
- package/src/plugins/focus/FocusManagerPlugin.ts +773 -0
- package/src/plugins/focus/FocusOutliner.ts +111 -0
- package/src/plugins/focus/index.ts +2 -0
- package/src/plugins/i18nPlugin.ts +284 -0
- package/src/plugins/index.ts +17 -0
- package/src/plugins/input/AbstractControls.ts +15 -0
- package/src/plugins/input/Controls.ts +55 -0
- package/src/plugins/input/InputPlugin.ts +168 -0
- package/src/plugins/input/constants.ts +12 -0
- package/src/plugins/input/index.ts +9 -0
- package/src/plugins/input/interfaces.ts +37 -0
- package/src/plugins/input/keyboard/KeyboardContols.ts +182 -0
- package/src/plugins/input/keyboard/index.ts +2 -0
- package/src/plugins/input/keyboard/interfaces.ts +21 -0
- package/src/plugins/input/methods.ts +9 -0
- package/src/plugins/input/touch/TouchControls.ts +237 -0
- package/src/plugins/input/touch/constants.ts +34 -0
- package/src/plugins/input/touch/index.ts +3 -0
- package/src/plugins/input/touch/interfaces.ts +15 -0
- package/src/plugins/input/types.ts +41 -0
- package/src/plugins/input/utils.ts +10 -0
- package/src/plugins/spine/SpinePlugin.ts +14 -0
- package/src/plugins/spine/pixi-spine/BatchableSpineSlot.ts +138 -0
- package/src/plugins/spine/pixi-spine/Spine.ts +897 -0
- package/src/plugins/spine/pixi-spine/SpineDebugRenderer.ts +615 -0
- package/src/plugins/spine/pixi-spine/SpinePipe.ts +197 -0
- package/src/plugins/spine/pixi-spine/SpineTexture.ts +143 -0
- package/src/plugins/spine/pixi-spine/assets/atlasLoader.ts +156 -0
- package/src/plugins/spine/pixi-spine/assets/skeletonLoader.ts +80 -0
- package/src/plugins/spine/pixi-spine/darktint/DarkTintBatchGeometry.ts +92 -0
- package/src/plugins/spine/pixi-spine/darktint/DarkTintBatcher.ts +186 -0
- package/src/plugins/spine/pixi-spine/darktint/DarkTintShader.ts +74 -0
- package/src/plugins/spine/pixi-spine/darktint/darkTintBit.ts +77 -0
- package/src/plugins/spine/pixi-spine/index.ts +43 -0
- package/src/plugins/spine/pixi-spine/require-shim.ts +43 -0
- package/src/signals/Signal.test.ts +54 -0
- package/src/signals/Signal.ts +68 -0
- package/src/signals/index.ts +10 -0
- package/src/store/Store.test.ts +146 -0
- package/src/store/Store.ts +192 -0
- package/src/store/index.ts +1 -0
- package/src/types/framework.d.ts +47 -0
- package/src/types/gsap.d.ts +26 -0
- package/src/ui/Button.ts +454 -0
- package/src/ui/FlexContainer.ts +526 -0
- package/src/ui/Input.ts +1274 -0
- package/src/ui/Joystick.ts +288 -0
- package/src/ui/Popup.ts +242 -0
- package/src/ui/Toast.ts +399 -0
- package/src/ui/Toaster.ts +409 -0
- package/src/ui/UICanvas.ts +812 -0
- package/src/ui/index.ts +8 -0
- package/src/utils/array.ts +24 -0
- package/src/utils/bind.ts +79 -0
- package/src/utils/canvas.ts +26 -0
- package/src/utils/color.ts +126 -0
- package/src/utils/console/Logger.ts +86 -0
- package/src/utils/console/index.ts +1 -0
- package/src/utils/debug.ts +69 -0
- package/src/utils/define.ts +120 -0
- package/src/utils/env.ts +3 -0
- package/src/utils/events.ts +10 -0
- package/src/utils/framework.ts +45 -0
- package/src/utils/index.ts +27 -0
- package/src/utils/map.ts +59 -0
- package/src/utils/math.ts +19 -0
- package/src/utils/misc.ts +45 -0
- package/src/utils/number.ts +3 -0
- package/src/utils/object.ts +43 -0
- package/src/utils/padding.ts +43 -0
- package/src/utils/pixi.ts +116 -0
- package/src/utils/platform.ts +33 -0
- package/src/utils/point.ts +123 -0
- package/src/utils/promise/Queue.ts +125 -0
- package/src/utils/promise/functions.ts +16 -0
- package/src/utils/promise/index.ts +2 -0
- package/src/utils/random.ts +69 -0
- package/src/utils/rect.ts +50 -0
- package/src/utils/set.ts +32 -0
- package/src/utils/string.ts +9 -0
- package/src/utils/text.ts +30 -0
- package/src/utils/typefilters.ts +29 -0
- package/src/utils/types.ts +426 -0
- package/src/utils/vite.ts +41 -0
- package/src/utils/web.ts +7 -0
- package/src/version.ts +3 -0
- package/src/webgl-check.ts +12 -0
- package/templates/app/default/.eslintrc.json +21 -0
- package/templates/app/default/.meta.json +4 -0
- package/templates/app/default/.nvmrc +1 -0
- package/templates/app/default/.prettierrc.json +7 -0
- package/templates/app/default/README.md +8 -0
- package/templates/app/default/assets/audio{m}/music/Cheerful Annoyance.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Drumming Sticks.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Game Over.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Mishief Stroll.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Night at the Beach.ogg +0 -0
- package/templates/app/default/assets/audio{m}/sfx/click.ogg +0 -0
- package/templates/app/default/assets/audio{m}/sfx/hover.ogg +0 -0
- package/templates/app/default/assets/required{m}/caper.png +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/SpaceGrotesk-Bold{family=Space Grotesk}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/SpaceGrotesk-Medium{family=Space Grotesk}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/SpaceGrotesk-Regular{family=Space Grotesk}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/Syncopate-Bold{family=Syncopate}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/blue.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/green.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/grey.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/orange.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/purple.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/red.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/yellow.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_a/down.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_a/over.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_a/up.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_b/down.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_b/over.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_b/up.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/joystick/base.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/joystick/handle.png +0 -0
- package/templates/app/default/assets/required{m}/wordmark.svg +1 -0
- package/templates/app/default/assets/spine{m}/spineboy-pro.png +0 -0
- package/templates/app/default/assets/spine{m}/spineboy-pro.skel +0 -0
- package/templates/app/default/assets/spine{m}/spineboy-pro{fix}.atlas +94 -0
- package/templates/app/default/caper.config.ts +60 -0
- package/templates/app/default/index.html +23 -0
- package/templates/app/default/package.template.json +17 -0
- package/templates/app/default/public/favicon.ico +0 -0
- package/templates/app/default/src/__APPLICATION_NAME__.ts +3 -0
- package/templates/app/default/src/main.ts +9 -0
- package/templates/app/default/src/scenes/Base.ts +39 -0
- package/templates/app/default/src/scenes/Game.ts +34 -0
- package/templates/app/default/src/scenes/Splash.ts +70 -0
- package/templates/app/default/src/scenes/Start.ts +90 -0
- package/templates/app/default/src/utils/Constants.ts +3 -0
- package/templates/app/default/tsconfig.json +1 -0
- package/templates/plugin/package.template.json +33 -0
- package/templates/plugin/src/Plugin.template.ts +24 -0
- package/templates/plugin/src/index.template.ts +3 -0
- package/templates/plugin/tsconfig.template.json +43 -0
- package/templates/plugin/vite-env.template.d.ts +16 -0
- package/templates/plugin/vite.config.template.ts +19 -0
package/src/ui/Input.ts
ADDED
|
@@ -0,0 +1,1274 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Bounds,
|
|
3
|
+
CanvasTextMetrics,
|
|
4
|
+
FederatedEvent,
|
|
5
|
+
FederatedPointerEvent,
|
|
6
|
+
Graphics,
|
|
7
|
+
Container as PIXIContainer,
|
|
8
|
+
Rectangle,
|
|
9
|
+
Sprite,
|
|
10
|
+
Text,
|
|
11
|
+
Texture,
|
|
12
|
+
} from 'pixi.js';
|
|
13
|
+
|
|
14
|
+
import { Focusable, Interactive, TextProps, WithSignals } from '../mixins';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
EaseString,
|
|
18
|
+
ensurePadding,
|
|
19
|
+
getNearestCharacterIndex,
|
|
20
|
+
isAndroid,
|
|
21
|
+
isMobile,
|
|
22
|
+
isTouch,
|
|
23
|
+
Logger,
|
|
24
|
+
Padding,
|
|
25
|
+
PointLike,
|
|
26
|
+
resolvePointLike,
|
|
27
|
+
} from '../utils';
|
|
28
|
+
|
|
29
|
+
import { gsap } from 'gsap';
|
|
30
|
+
import { Container } from '../display';
|
|
31
|
+
import { Signal } from '../signals';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Options for styling the input background
|
|
35
|
+
* @interface BgStyleOptions
|
|
36
|
+
*/
|
|
37
|
+
export type BgStyleOptions = {
|
|
38
|
+
/** Border radius of the input background */
|
|
39
|
+
radius: number;
|
|
40
|
+
/** Fill style for the background */
|
|
41
|
+
fill: { color?: number; alpha?: number };
|
|
42
|
+
/** Stroke style for the background border */
|
|
43
|
+
stroke: { width?: number; color?: number; alpha?: number };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Color configuration options
|
|
48
|
+
* @interface ColorOptions
|
|
49
|
+
*/
|
|
50
|
+
export type ColorOptions = {
|
|
51
|
+
/** Color in hexadecimal format */
|
|
52
|
+
color: number;
|
|
53
|
+
/** Alpha transparency value (0-1) */
|
|
54
|
+
alpha: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Placeholder text configuration
|
|
59
|
+
* @interface PlaceholderOptions
|
|
60
|
+
*/
|
|
61
|
+
export type PlaceholderOptions = {
|
|
62
|
+
/** Text to display as placeholder */
|
|
63
|
+
text: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Focus overlay configuration for mobile/touch interactions
|
|
68
|
+
* @interface FocusOverlayOptions
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const overlaySettings = {
|
|
72
|
+
* activeFilter: ['mobile', 'touch'],
|
|
73
|
+
* marginTop: 60,
|
|
74
|
+
* scale: 2.5,
|
|
75
|
+
* backing: { active: true, color: 0x0 }
|
|
76
|
+
* };
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export type FocusOverlayOptions = {
|
|
80
|
+
/** Enable overlay for specific platforms */
|
|
81
|
+
mobile: boolean;
|
|
82
|
+
touch: boolean;
|
|
83
|
+
desktop: boolean;
|
|
84
|
+
/** Custom filter for when to show overlay */
|
|
85
|
+
activeFilter?: boolean | (() => boolean) | ('mobile' | 'touch' | 'desktop')[];
|
|
86
|
+
/** Scale factor for the overlay */
|
|
87
|
+
scale: number;
|
|
88
|
+
/** Top margin for the overlay */
|
|
89
|
+
marginTop: number;
|
|
90
|
+
/** Backing configuration */
|
|
91
|
+
backing: {
|
|
92
|
+
active: boolean;
|
|
93
|
+
options: Partial<ColorOptions>;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Extended placeholder options with animation and positioning
|
|
99
|
+
* @interface ExtraPlaceholderOptions
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const placeholderConfig = {
|
|
103
|
+
* positionOnType: 'top',
|
|
104
|
+
* offsetOnType: { x: 0, y: -20 },
|
|
105
|
+
* scaleOnType: { x: 0.8, y: 0.8 },
|
|
106
|
+
* animationOnType: {
|
|
107
|
+
* duration: 0.3,
|
|
108
|
+
* ease: 'sine.out',
|
|
109
|
+
* tint: 0x666666,
|
|
110
|
+
* alpha: 0.5
|
|
111
|
+
* }
|
|
112
|
+
* };
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
type ExtraPlaceholderOptions = {
|
|
116
|
+
/** Position of placeholder when typing */
|
|
117
|
+
positionOnType: 'top' | 'bottom';
|
|
118
|
+
/** Offset from original position when typing */
|
|
119
|
+
offsetOnType: PointLike;
|
|
120
|
+
/** Scale factor when typing */
|
|
121
|
+
scaleOnType: PointLike;
|
|
122
|
+
/** Animation configuration when typing */
|
|
123
|
+
animationOnType: {
|
|
124
|
+
duration: number;
|
|
125
|
+
ease: EaseString;
|
|
126
|
+
tint: number;
|
|
127
|
+
alpha: number;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Main configuration options for the Input component
|
|
133
|
+
* @interface InputOptions
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const input = new Input({
|
|
137
|
+
* value: 'Initial value',
|
|
138
|
+
* type: 'text',
|
|
139
|
+
* minWidth: 400,
|
|
140
|
+
* padding: [12, 15],
|
|
141
|
+
* placeholder: {
|
|
142
|
+
* text: 'Enter text...',
|
|
143
|
+
* color: 0x666666
|
|
144
|
+
* },
|
|
145
|
+
* bg: {
|
|
146
|
+
* radius: 10,
|
|
147
|
+
* stroke: { width: 2, color: 0x000000 }
|
|
148
|
+
* },
|
|
149
|
+
* focusOverlay: {
|
|
150
|
+
* activeFilter: ['mobile', 'touch'],
|
|
151
|
+
* scale: 2.5
|
|
152
|
+
* }
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export interface InputOptions extends Partial<TextProps> {
|
|
157
|
+
/** Initial value of the input */
|
|
158
|
+
value: string;
|
|
159
|
+
/** Input type (text, password, number, etc.) */
|
|
160
|
+
type: 'text' | 'password' | 'number' | 'email' | 'tel' | 'url';
|
|
161
|
+
/** Whether the input width is fixed */
|
|
162
|
+
fixed: boolean;
|
|
163
|
+
/** Pattern for input validation */
|
|
164
|
+
pattern: string;
|
|
165
|
+
/** Enable debug mode */
|
|
166
|
+
debug: boolean;
|
|
167
|
+
/** Minimum width of the input */
|
|
168
|
+
minWidth: number;
|
|
169
|
+
/** Padding configuration */
|
|
170
|
+
padding: Padding;
|
|
171
|
+
/** Maximum length of input */
|
|
172
|
+
maxLength?: number;
|
|
173
|
+
/** Whether to blur on Enter key */
|
|
174
|
+
blurOnEnter: boolean;
|
|
175
|
+
/** Custom regex for validation */
|
|
176
|
+
regex?: RegExp;
|
|
177
|
+
/** Background style configuration */
|
|
178
|
+
bg: Partial<BgStyleOptions>;
|
|
179
|
+
/** Placeholder configuration */
|
|
180
|
+
placeholder: Partial<PlaceholderOptions & ColorOptions & ExtraPlaceholderOptions>;
|
|
181
|
+
/** Selection highlight configuration */
|
|
182
|
+
selection: Partial<ColorOptions>;
|
|
183
|
+
/** Caret configuration */
|
|
184
|
+
caret: Partial<ColorOptions>;
|
|
185
|
+
/** Error state styling */
|
|
186
|
+
error?: {
|
|
187
|
+
input?: {
|
|
188
|
+
fill?: number;
|
|
189
|
+
};
|
|
190
|
+
bg?: Partial<Omit<BgStyleOptions, 'stroke'>>;
|
|
191
|
+
};
|
|
192
|
+
/** Focus overlay configuration */
|
|
193
|
+
focusOverlay: Partial<FocusOverlayOptions>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface InputProps extends Omit<InputOptions, 'padding'> {
|
|
197
|
+
padding: PointLike | Padding | number[] | number;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type InputDetail = {
|
|
201
|
+
value: string;
|
|
202
|
+
input: Input;
|
|
203
|
+
domElement: HTMLInputElement;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const defaultOptions: InputOptions = {
|
|
207
|
+
value: '',
|
|
208
|
+
type: 'text',
|
|
209
|
+
fixed: true,
|
|
210
|
+
pattern: '',
|
|
211
|
+
debug: false,
|
|
212
|
+
minWidth: 200,
|
|
213
|
+
padding: { top: 0, left: 0, bottom: 0, right: 0 },
|
|
214
|
+
blurOnEnter: true,
|
|
215
|
+
style: {
|
|
216
|
+
fontFamily: 'Arial',
|
|
217
|
+
fill: '#000000',
|
|
218
|
+
fontSize: 20,
|
|
219
|
+
fontWeight: 'bold',
|
|
220
|
+
},
|
|
221
|
+
bg: {
|
|
222
|
+
radius: 5,
|
|
223
|
+
fill: { color: 0xffffff },
|
|
224
|
+
stroke: { width: 1, color: 0x0 },
|
|
225
|
+
},
|
|
226
|
+
placeholder: {},
|
|
227
|
+
selection: { color: 0x00ff00 },
|
|
228
|
+
caret: {
|
|
229
|
+
color: 0x0,
|
|
230
|
+
alpha: 0.8,
|
|
231
|
+
},
|
|
232
|
+
focusOverlay: {
|
|
233
|
+
activeFilter: false,
|
|
234
|
+
scale: 1,
|
|
235
|
+
marginTop: 60,
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const AVAILABLE_TYPES = ['text', 'password', 'number', 'email', 'tel', 'url'];
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* A highly customizable input component with mobile/touch support
|
|
243
|
+
* @class Input
|
|
244
|
+
* @extends Focusable(Interactive(WithSignals(Container)))
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* // Basic text input
|
|
249
|
+
* const basicInput = new Input({
|
|
250
|
+
* minWidth: 400,
|
|
251
|
+
* placeholder: { text: 'Enter text' },
|
|
252
|
+
* padding: [12, 15]
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
255
|
+
* // Password input with validation
|
|
256
|
+
* const passwordInput = new Input({
|
|
257
|
+
* type: 'password',
|
|
258
|
+
* minWidth: 400,
|
|
259
|
+
* placeholder: { text: 'Enter password' },
|
|
260
|
+
* maxLength: 20,
|
|
261
|
+
* regex: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/
|
|
262
|
+
* });
|
|
263
|
+
*
|
|
264
|
+
* // Phone number input with validation
|
|
265
|
+
* const phoneInput = new Input({
|
|
266
|
+
* type: 'tel',
|
|
267
|
+
* regex: /^1?-?\(?([2-9][0-9]{2})\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/,
|
|
268
|
+
* error: {
|
|
269
|
+
* input: { fill: 0xff0000 },
|
|
270
|
+
* bg: { fill: 0xf5e0df }
|
|
271
|
+
* }
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export class Input extends Focusable(Interactive(WithSignals(Container))) {
|
|
276
|
+
/**
|
|
277
|
+
* Emitted when the Enter key is pressed
|
|
278
|
+
* @event onEnter
|
|
279
|
+
* @type {Signal<(detail: InputDetail) => void>}
|
|
280
|
+
*/
|
|
281
|
+
public onEnter: Signal<(detail: InputDetail) => void> = new Signal<(detail: InputDetail) => void>();
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Emitted when the input value changes
|
|
285
|
+
* @event onChange
|
|
286
|
+
* @type {Signal<(detail: InputDetail) => void>}
|
|
287
|
+
*/
|
|
288
|
+
public onChange: Signal<(detail: InputDetail) => void> = new Signal<(detail: InputDetail) => void>();
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Emitted when validation fails
|
|
292
|
+
* @event onError
|
|
293
|
+
* @type {Signal<(detail: InputDetail) => void>}
|
|
294
|
+
*/
|
|
295
|
+
public onError: Signal<(detail: InputDetail) => void> = new Signal<(detail: InputDetail) => void>();
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Input configuration options
|
|
299
|
+
* @type {InputOptions}
|
|
300
|
+
*/
|
|
301
|
+
public options: InputOptions;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Background graphics container
|
|
305
|
+
* @type {Graphics}
|
|
306
|
+
*/
|
|
307
|
+
public bg: Graphics;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Caret (cursor) container
|
|
311
|
+
* @type {PIXIContainer}
|
|
312
|
+
*/
|
|
313
|
+
public caret: PIXIContainer;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Text input container
|
|
317
|
+
* @type {Text}
|
|
318
|
+
*/
|
|
319
|
+
public input: Text;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Placeholder text container
|
|
323
|
+
* @type {Text}
|
|
324
|
+
*/
|
|
325
|
+
public placeholder: Text;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Current error state
|
|
329
|
+
* @type {boolean}
|
|
330
|
+
*/
|
|
331
|
+
public error: boolean;
|
|
332
|
+
|
|
333
|
+
// Protected properties
|
|
334
|
+
protected cursorAnimation: gsap.core.Tween;
|
|
335
|
+
protected domElement: HTMLInputElement;
|
|
336
|
+
protected selectionGraphics: Graphics;
|
|
337
|
+
protected cloneOverlay: Input;
|
|
338
|
+
protected overlayBacking: Sprite;
|
|
339
|
+
|
|
340
|
+
// Private properties
|
|
341
|
+
private _focusTimer: any;
|
|
342
|
+
private _pointerDownTimer: any;
|
|
343
|
+
private _inner: Container;
|
|
344
|
+
private _inputContainer: Container;
|
|
345
|
+
private _placeholderContainer: Container;
|
|
346
|
+
private _mask: Graphics;
|
|
347
|
+
private _lastWidth: number = 0;
|
|
348
|
+
private _lastHeight: number = 0;
|
|
349
|
+
private _placeholderPositioned: boolean = false;
|
|
350
|
+
private _placeholderAnimating: boolean = false;
|
|
351
|
+
private _caretPosition: number = -1;
|
|
352
|
+
private _selectionRect: Rectangle | null;
|
|
353
|
+
private _regex: RegExp;
|
|
354
|
+
private _value: string = '';
|
|
355
|
+
|
|
356
|
+
constructor(
|
|
357
|
+
options: Partial<InputProps>,
|
|
358
|
+
public isClone: boolean = false,
|
|
359
|
+
public clone: Input | null = null,
|
|
360
|
+
) {
|
|
361
|
+
super({ autoUpdate: true, autoResize: !isClone });
|
|
362
|
+
|
|
363
|
+
this.options = {
|
|
364
|
+
...defaultOptions,
|
|
365
|
+
...options,
|
|
366
|
+
style: {
|
|
367
|
+
...defaultOptions.style,
|
|
368
|
+
...(options?.style ?? {}),
|
|
369
|
+
},
|
|
370
|
+
padding: ensurePadding(options.padding ?? defaultOptions.padding),
|
|
371
|
+
bg: {
|
|
372
|
+
...defaultOptions.bg,
|
|
373
|
+
...(options.bg ?? {}),
|
|
374
|
+
},
|
|
375
|
+
focusOverlay: {
|
|
376
|
+
...defaultOptions.focusOverlay,
|
|
377
|
+
...(options.focusOverlay ?? {}),
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
if (this.options.layout && typeof this.options.layout === 'object') {
|
|
382
|
+
this.layout = { ...this.options.layout };
|
|
383
|
+
} else {
|
|
384
|
+
this.layout = { transformOrigin: 'top left' };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (!this.options.placeholder) {
|
|
388
|
+
this.options.placeholder = {
|
|
389
|
+
color: Number(this.options.style?.fill) ?? 0x666666,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
this._inner = this.add.container({
|
|
394
|
+
layout: { position: 'relative', top: 0, left: 0, width: '100%', height: '100%' },
|
|
395
|
+
});
|
|
396
|
+
this.addBg();
|
|
397
|
+
|
|
398
|
+
this._inputContainer = this._inner.add.container({
|
|
399
|
+
y: -2,
|
|
400
|
+
layout: {
|
|
401
|
+
position: 'absolute',
|
|
402
|
+
transformOrigin: 'top left',
|
|
403
|
+
inset: 0,
|
|
404
|
+
width: '100%',
|
|
405
|
+
height: '100%',
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
this._placeholderContainer = this._inner.add.container({
|
|
409
|
+
y: -2,
|
|
410
|
+
layout: {
|
|
411
|
+
position: 'absolute',
|
|
412
|
+
inset: 0,
|
|
413
|
+
transformOrigin: 'top left',
|
|
414
|
+
width: '100%',
|
|
415
|
+
height: '100%',
|
|
416
|
+
},
|
|
417
|
+
});
|
|
418
|
+
this._placeholderContainer.eventMode = 'none';
|
|
419
|
+
this.addSelection();
|
|
420
|
+
this.addCaret();
|
|
421
|
+
this.addInput();
|
|
422
|
+
this.addPlaceholder();
|
|
423
|
+
|
|
424
|
+
this.placeholder.text = this.options.placeholder.text || `Enter ${this.options.type}`;
|
|
425
|
+
|
|
426
|
+
this.input.eventMode = this.placeholder.eventMode = 'none';
|
|
427
|
+
|
|
428
|
+
if (isTouch) {
|
|
429
|
+
this.addSignalConnection(this.onInteraction('pointertap').connect(this.handleClick, -1));
|
|
430
|
+
}
|
|
431
|
+
this.addSignalConnection(this.onInteraction('click').connect(this.handleClick, -1));
|
|
432
|
+
|
|
433
|
+
if (this.options.fixed) {
|
|
434
|
+
const scale = this.isClone ? (this.clone?.options?.focusOverlay?.scale ?? 1) : 1;
|
|
435
|
+
this._mask = this._inner.add
|
|
436
|
+
.graphics()
|
|
437
|
+
.rect(
|
|
438
|
+
0,
|
|
439
|
+
0,
|
|
440
|
+
this.bg.width * scale - this.options.padding.left - this.options.padding.right,
|
|
441
|
+
this.bg.height * scale - this.options.padding.top - this.options.padding.bottom,
|
|
442
|
+
)
|
|
443
|
+
.fill({ color: 0x0 });
|
|
444
|
+
this._inputContainer.mask = this._mask;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Gets the current caret (cursor) position
|
|
450
|
+
* @readonly
|
|
451
|
+
* @returns {number} The caret position in pixels from the left
|
|
452
|
+
*/
|
|
453
|
+
get caretPosition() {
|
|
454
|
+
return this._caretPosition;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Gets the current selection rectangle
|
|
459
|
+
* @readonly
|
|
460
|
+
* @returns {Rectangle | null} The selection rectangle or null if no selection
|
|
461
|
+
*/
|
|
462
|
+
get selectionRect() {
|
|
463
|
+
return this._selectionRect;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Sets the validation regex
|
|
468
|
+
* @param {RegExp} value - The regular expression to use for validation
|
|
469
|
+
*/
|
|
470
|
+
set regex(value: RegExp) {
|
|
471
|
+
this._regex = value;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Gets whether the current input value is valid
|
|
476
|
+
* @readonly
|
|
477
|
+
* @returns {boolean} True if the input is valid
|
|
478
|
+
*/
|
|
479
|
+
get isValid(): boolean {
|
|
480
|
+
let result = false;
|
|
481
|
+
if (this.domElement) {
|
|
482
|
+
if (this._regex) {
|
|
483
|
+
result = this._regex.test(this._value);
|
|
484
|
+
} else {
|
|
485
|
+
if (this.options.type === 'text') {
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
this.domElement.required = true;
|
|
489
|
+
result = this.domElement.checkValidity();
|
|
490
|
+
this.domElement.required = false;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return result;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Gets the current input value
|
|
498
|
+
* @returns {string} The current value
|
|
499
|
+
*/
|
|
500
|
+
public get value() {
|
|
501
|
+
return this._value?.trim() ?? '';
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Sets the input value
|
|
506
|
+
* @param {string} value - The value to set
|
|
507
|
+
*/
|
|
508
|
+
public set value(value: string) {
|
|
509
|
+
if (this.domElement) {
|
|
510
|
+
this.domElement.value = value;
|
|
511
|
+
const event = new Event('input', {
|
|
512
|
+
bubbles: true,
|
|
513
|
+
cancelable: true,
|
|
514
|
+
});
|
|
515
|
+
this.domElement.dispatchEvent(event);
|
|
516
|
+
} else {
|
|
517
|
+
this._value = value;
|
|
518
|
+
this.input.text = value;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Resizes the input component
|
|
524
|
+
* Updates the clone overlay position if it exists
|
|
525
|
+
*/
|
|
526
|
+
resize() {
|
|
527
|
+
super.resize();
|
|
528
|
+
if (this.cloneOverlay) {
|
|
529
|
+
this._positionCloneOverlay();
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Redraws the background graphics
|
|
535
|
+
*/
|
|
536
|
+
resetBg() {
|
|
537
|
+
this.drawBg();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Called when the component is added to the display list
|
|
542
|
+
* Shows the cursor if this is a clone
|
|
543
|
+
*/
|
|
544
|
+
added() {
|
|
545
|
+
super.added();
|
|
546
|
+
if (this.isClone) {
|
|
547
|
+
this.showCursor();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Handles click/tap events on the input
|
|
553
|
+
* Creates the DOM element and positions the caret
|
|
554
|
+
* @param {FederatedEvent} [e] - The pointer event
|
|
555
|
+
*/
|
|
556
|
+
handleClick(e?: FederatedEvent) {
|
|
557
|
+
// check if this was a triggered event from the FocusMnagerPlugin
|
|
558
|
+
if ((e?.originalEvent as unknown as KeyboardEvent)?.key) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
clearTimeout(this._focusTimer);
|
|
562
|
+
clearTimeout(this._pointerDownTimer);
|
|
563
|
+
const nearestCharacterIndex = e ? getNearestCharacterIndex(this.input, e) : (this.input.text?.length ?? 0);
|
|
564
|
+
this.createDomElement(nearestCharacterIndex);
|
|
565
|
+
// this._focusDomElement(nearestCharacterIndex);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Focuses the input
|
|
570
|
+
* Creates the DOM element and shows the cursor
|
|
571
|
+
*/
|
|
572
|
+
focusIn() {
|
|
573
|
+
this.handleClick();
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
_focusDomElement(selection?: number) {
|
|
577
|
+
this._focusTimer = setTimeout(() => {
|
|
578
|
+
this._triggerFocusAndSelection(selection);
|
|
579
|
+
}, 100);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
_triggerFocusAndSelection(selection?: number) {
|
|
583
|
+
if (this.domElement) {
|
|
584
|
+
try {
|
|
585
|
+
this.domElement.focus();
|
|
586
|
+
this.domElement.click();
|
|
587
|
+
if (selection === undefined) {
|
|
588
|
+
this.domElement.selectionStart = this.domElement?.value?.length;
|
|
589
|
+
} else {
|
|
590
|
+
this.domElement.setSelectionRange(selection, selection, 'none');
|
|
591
|
+
}
|
|
592
|
+
} catch (e) {
|
|
593
|
+
// nothing
|
|
594
|
+
}
|
|
595
|
+
this._updateCaretAndSelection();
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
_checkPointerDownOutside(e: FederatedPointerEvent) {
|
|
600
|
+
const pos = this.toLocal(e.data.global);
|
|
601
|
+
if (this.getBounds().rectangle.contains(pos.x, pos.y)) {
|
|
602
|
+
this.focusIn();
|
|
603
|
+
} else {
|
|
604
|
+
this.focusOut();
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Blurs (unfocuses) the input
|
|
610
|
+
* Removes the DOM element and hides the cursor
|
|
611
|
+
*/
|
|
612
|
+
focusOut() {
|
|
613
|
+
this.domElement?.blur();
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
update() {
|
|
617
|
+
this.bg.x = 0;
|
|
618
|
+
this.bg.y = 0;
|
|
619
|
+
|
|
620
|
+
// size background
|
|
621
|
+
const bgHeight =
|
|
622
|
+
this.input.getLocalBounds().y +
|
|
623
|
+
this.input.style.fontSize +
|
|
624
|
+
this.options.padding.top +
|
|
625
|
+
this.options.padding.bottom;
|
|
626
|
+
|
|
627
|
+
const bgWidth = this.options.fixed
|
|
628
|
+
? this.options.minWidth
|
|
629
|
+
: Math.max(this.options.minWidth, this.input.width) + this.options.padding.left + this.options.padding.right;
|
|
630
|
+
|
|
631
|
+
// position inputs
|
|
632
|
+
// the 'align' property doesn't affect single line text,
|
|
633
|
+
// so we need to do this manually
|
|
634
|
+
const diff = this.options.minWidth - bgWidth + this.options.padding.left + this.options.padding.right;
|
|
635
|
+
const inputAvailableWidth = bgWidth - this.options.padding.left - this.options.padding.right;
|
|
636
|
+
|
|
637
|
+
switch (this.input.style.align) {
|
|
638
|
+
case 'center':
|
|
639
|
+
this.input.x = bgWidth / 2 - this.input.width / 2;
|
|
640
|
+
if (!this._placeholderPositioned) {
|
|
641
|
+
this.placeholder.x = bgWidth / 2 - this.placeholder.width / 2;
|
|
642
|
+
}
|
|
643
|
+
this._inner.x = diff >= 0 ? 0 : diff / 2;
|
|
644
|
+
if (this.options.fixed) {
|
|
645
|
+
const inputDiff = this.input.width - inputAvailableWidth;
|
|
646
|
+
if (inputDiff > 0) {
|
|
647
|
+
this.input.x -= inputDiff / 2;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
break;
|
|
651
|
+
case 'right':
|
|
652
|
+
this.input.x = bgWidth - this.options.padding.right - this.input.width;
|
|
653
|
+
if (!this._placeholderPositioned) {
|
|
654
|
+
this.placeholder.x = bgWidth - this.options.padding.right - this.placeholder.width;
|
|
655
|
+
}
|
|
656
|
+
this._inner.x = diff >= 0 ? 0 : diff;
|
|
657
|
+
break;
|
|
658
|
+
default:
|
|
659
|
+
this.input.x = this.options.padding.left;
|
|
660
|
+
if (!this._placeholderPositioned) {
|
|
661
|
+
this.placeholder.x = this.options.padding.left;
|
|
662
|
+
}
|
|
663
|
+
this._inner.x = 0;
|
|
664
|
+
if (this.options.fixed) {
|
|
665
|
+
const inputDiff = this.input.width - inputAvailableWidth;
|
|
666
|
+
if (inputDiff > 0) {
|
|
667
|
+
this.input.x -= inputDiff;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
this.input.y = this.options.padding.top;
|
|
674
|
+
if (!this._placeholderPositioned) {
|
|
675
|
+
this.placeholder.y = this.input.y;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (this.isClone && this.clone) {
|
|
679
|
+
const cloneScale = this.clone.options?.focusOverlay?.scale ?? 1;
|
|
680
|
+
this.error = this.clone.error;
|
|
681
|
+
this._value = this.clone.input.text;
|
|
682
|
+
this.input.text = this._value;
|
|
683
|
+
this._selectionRect = this.clone.selectionRect!.clone();
|
|
684
|
+
this._selectionRect.x *= cloneScale;
|
|
685
|
+
this._selectionRect.y *= cloneScale;
|
|
686
|
+
this._selectionRect.width *= cloneScale;
|
|
687
|
+
this._selectionRect.height *= cloneScale;
|
|
688
|
+
this._caretPosition = this.clone.caretPosition * cloneScale;
|
|
689
|
+
}
|
|
690
|
+
// position caret
|
|
691
|
+
this.caret.x = this._caretPosition >= 0 ? this.input.x + this._caretPosition : this.input.x + this.input.width + 1;
|
|
692
|
+
this.caret.y = this.input.y - 2;
|
|
693
|
+
this.caret.height = this.input.style.fontSize * 1.15;
|
|
694
|
+
|
|
695
|
+
// check if value is empty
|
|
696
|
+
if (this.value === '') {
|
|
697
|
+
this.placeholder.visible = true;
|
|
698
|
+
if (!this.isClone && this._placeholderPositioned && !this._placeholderAnimating) {
|
|
699
|
+
this._placeholderAnimating = true;
|
|
700
|
+
const tx = this.input.x;
|
|
701
|
+
const ty = this.input.y;
|
|
702
|
+
if (this.options.placeholder.animationOnType) {
|
|
703
|
+
this.addAnimation([
|
|
704
|
+
gsap.to(this.placeholder, {
|
|
705
|
+
x: tx,
|
|
706
|
+
y: ty,
|
|
707
|
+
tint: 0xffffff,
|
|
708
|
+
alpha: this.options.placeholder.alpha ?? 1,
|
|
709
|
+
duration: this.options.placeholder.animationOnType.duration || 0.4,
|
|
710
|
+
ease: this.options.placeholder.animationOnType.ease || 'sine.in',
|
|
711
|
+
overwrite: true,
|
|
712
|
+
onComplete: () => {
|
|
713
|
+
this._placeholderPositioned = false;
|
|
714
|
+
this._placeholderAnimating = false;
|
|
715
|
+
},
|
|
716
|
+
}),
|
|
717
|
+
gsap.to(this.placeholder.scale, {
|
|
718
|
+
x: 1,
|
|
719
|
+
y: 1,
|
|
720
|
+
duration: this.options.placeholder.animationOnType.duration || 0.4,
|
|
721
|
+
ease: this.options.placeholder.animationOnType.ease || 'sine.out',
|
|
722
|
+
overwrite: true,
|
|
723
|
+
}),
|
|
724
|
+
]);
|
|
725
|
+
} else {
|
|
726
|
+
this.placeholder.x = tx;
|
|
727
|
+
this.placeholder.y = ty;
|
|
728
|
+
this.placeholder.scale.set(1, 1);
|
|
729
|
+
this._placeholderPositioned = false;
|
|
730
|
+
this._placeholderAnimating = false;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
} else {
|
|
734
|
+
if (!this.isClone && this.options.placeholder.positionOnType) {
|
|
735
|
+
this.placeholder.visible = true;
|
|
736
|
+
if (!this._placeholderPositioned) {
|
|
737
|
+
this._placeholderPositioned = true;
|
|
738
|
+
let tx = this.placeholder.x;
|
|
739
|
+
let ty = this.placeholder.y;
|
|
740
|
+
switch (this.options.placeholder.positionOnType) {
|
|
741
|
+
case 'top':
|
|
742
|
+
ty = this.input.y - this.placeholder.height - this.options.padding.top;
|
|
743
|
+
break;
|
|
744
|
+
case 'bottom':
|
|
745
|
+
ty = this.input.y + this.input.height + this.options.padding.bottom;
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (this.options.placeholder.offsetOnType) {
|
|
750
|
+
const offset = resolvePointLike(this.options.placeholder.offsetOnType);
|
|
751
|
+
tx += offset.x;
|
|
752
|
+
ty += offset.y;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if (this.options.placeholder.animationOnType) {
|
|
756
|
+
this.addAnimation(
|
|
757
|
+
gsap.to(this.placeholder, {
|
|
758
|
+
x: tx,
|
|
759
|
+
y: ty,
|
|
760
|
+
duration: this.options.placeholder.animationOnType.duration || 0.4,
|
|
761
|
+
ease: this.options.placeholder.animationOnType.ease || 'none',
|
|
762
|
+
tint: this.options.placeholder.animationOnType.tint ?? null,
|
|
763
|
+
alpha: this.options.placeholder.animationOnType.alpha ?? this.options.placeholder.alpha ?? 1,
|
|
764
|
+
overwrite: true,
|
|
765
|
+
}),
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
if (this.options.placeholder.scaleOnType) {
|
|
769
|
+
const scale = resolvePointLike(this.options.placeholder.scaleOnType);
|
|
770
|
+
this.addAnimation(
|
|
771
|
+
gsap.to(this.placeholder.scale, {
|
|
772
|
+
x: scale.x,
|
|
773
|
+
y: scale.y,
|
|
774
|
+
duration: this.options.placeholder.animationOnType.duration || 0.4,
|
|
775
|
+
ease: this.options.placeholder.animationOnType.ease || 'none',
|
|
776
|
+
overwrite: true,
|
|
777
|
+
}),
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
} else {
|
|
781
|
+
this.placeholder.x = tx;
|
|
782
|
+
this.placeholder.y = ty;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
} else {
|
|
786
|
+
this.placeholder.visible = false;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
if (this.options.fixed) {
|
|
791
|
+
const scale = this.isClone ? (this.options?.focusOverlay?.scale ?? 1) : 1;
|
|
792
|
+
if (this._mask) {
|
|
793
|
+
this._mask
|
|
794
|
+
.clear()
|
|
795
|
+
.rect(0, 0, (bgWidth - this.options.padding.left - this.options.padding.right) * scale, bgHeight * scale)
|
|
796
|
+
.fill({ color: 0x0 });
|
|
797
|
+
this._mask.position.set(this.options.padding.left * scale, 0);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (bgWidth !== this._lastWidth) {
|
|
802
|
+
this.drawBg(bgWidth, bgHeight);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (this._selectionRect) {
|
|
806
|
+
this.drawSelection();
|
|
807
|
+
} else {
|
|
808
|
+
this.selectionGraphics?.clear();
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
if (this.cloneOverlay) {
|
|
812
|
+
this._positionCloneOverlay();
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
drawSelection() {
|
|
817
|
+
const rect = this._selectionRect;
|
|
818
|
+
if (!rect) {
|
|
819
|
+
this.selectionGraphics?.clear();
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
this.selectionGraphics?.clear();
|
|
823
|
+
this.selectionGraphics
|
|
824
|
+
.rect(rect.left + this.input.x, this.caret.y, rect.width, this.caret.height)
|
|
825
|
+
.fill({ color: this.options.selection.color });
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
drawBg(width: number = this._lastWidth, height: number = this._lastHeight) {
|
|
829
|
+
const opts =
|
|
830
|
+
(this.error || (this.isClone && this.clone?.error)) && this.options?.error?.bg
|
|
831
|
+
? { ...this.options.bg, ...this.options.error.bg }
|
|
832
|
+
: this.options.bg;
|
|
833
|
+
|
|
834
|
+
this.bg
|
|
835
|
+
.clear()
|
|
836
|
+
.roundRect(0, 0, width, height, opts?.radius ?? 0)
|
|
837
|
+
.fill(opts.fill)
|
|
838
|
+
.stroke({ ...(opts?.stroke || {}), alignment: 0 });
|
|
839
|
+
|
|
840
|
+
this._lastWidth = width;
|
|
841
|
+
this._lastHeight = height;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
destroy() {
|
|
845
|
+
console.log('input destroy', this);
|
|
846
|
+
clearTimeout(this._focusTimer);
|
|
847
|
+
clearTimeout(this._pointerDownTimer);
|
|
848
|
+
|
|
849
|
+
this.app.stage.off('pointerdown', this._checkPointerDownOutside);
|
|
850
|
+
|
|
851
|
+
this.hideCursor();
|
|
852
|
+
this.destroyDomElement();
|
|
853
|
+
|
|
854
|
+
super.destroy();
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
protected addBg() {
|
|
858
|
+
this.bg = this._inner.add
|
|
859
|
+
.graphics()
|
|
860
|
+
.roundRect(0, 0, 100, 50, this.options?.bg?.radius ?? 0)
|
|
861
|
+
.fill(this.options.bg.fill);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
protected addSelection() {
|
|
865
|
+
this.selectionGraphics = this._inputContainer.add.graphics();
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
protected addCaret() {
|
|
869
|
+
this.caret = this._inputContainer.add.sprite({
|
|
870
|
+
asset: Texture.WHITE,
|
|
871
|
+
width: 3,
|
|
872
|
+
height: 10,
|
|
873
|
+
tint: this.options.caret.color ?? 0x0,
|
|
874
|
+
alpha: 0,
|
|
875
|
+
visible: false,
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
protected addInput() {
|
|
880
|
+
// Seed the backing value alongside the display text — otherwise an input
|
|
881
|
+
// constructed with `value` reports `''` until the first edit, and
|
|
882
|
+
// update() keeps the placeholder visible over the rendered text.
|
|
883
|
+
this._value = this.options.value ?? '';
|
|
884
|
+
this.input = this._inputContainer.add.text({
|
|
885
|
+
...this.options,
|
|
886
|
+
style: { ...(this.options?.style || {}), padding: 2 },
|
|
887
|
+
text: this.options.value ?? '',
|
|
888
|
+
label: 'input',
|
|
889
|
+
resolution: 2,
|
|
890
|
+
roundPixels: true,
|
|
891
|
+
layout: false,
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
protected addPlaceholder() {
|
|
896
|
+
this.placeholder = this._placeholderContainer.add.text({
|
|
897
|
+
...this.options,
|
|
898
|
+
...this.options.placeholder,
|
|
899
|
+
style: {
|
|
900
|
+
...this.options.style,
|
|
901
|
+
fill: this.options.placeholder?.color ?? 0x666666,
|
|
902
|
+
},
|
|
903
|
+
resolution: 2,
|
|
904
|
+
label: 'placeholder',
|
|
905
|
+
roundPixels: true,
|
|
906
|
+
layout: true,
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
this.placeholder.style.align = this.input.style.align;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
protected createDomElement(selection?: number) {
|
|
913
|
+
if (this.isClone && this.clone?.domElement) {
|
|
914
|
+
this.domElement = this.clone.domElement;
|
|
915
|
+
this._addDomElementListeners();
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
clearTimeout(this._focusTimer);
|
|
919
|
+
clearTimeout(this._pointerDownTimer);
|
|
920
|
+
|
|
921
|
+
this.domElement = document.createElement('input');
|
|
922
|
+
this.domElement.type = 'text';
|
|
923
|
+
if (this.options.type && AVAILABLE_TYPES.includes(this.options.type)) {
|
|
924
|
+
this.domElement.type = this.options.type;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
if (this.options.pattern) {
|
|
928
|
+
this.domElement.pattern = this.options.pattern;
|
|
929
|
+
}
|
|
930
|
+
if (this.options.regex) {
|
|
931
|
+
this._regex = this.options.regex;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const pos = this.getGlobalPosition();
|
|
935
|
+
const bounds = this.getBounds();
|
|
936
|
+
bounds.x = pos.x;
|
|
937
|
+
bounds.y = pos.y;
|
|
938
|
+
bounds.width = this.width - this.options.padding.left;
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Overlays an HTMLInputElement
|
|
942
|
+
* allows the keyboard to be used on mobile devices
|
|
943
|
+
* mostly taken from @pixi/ui
|
|
944
|
+
* @see https://github.com/pixijs/ui/blob/main/src/Input.ts
|
|
945
|
+
*/
|
|
946
|
+
|
|
947
|
+
this.domElement.style.position = 'fixed';
|
|
948
|
+
this.domElement.style.border = 'none';
|
|
949
|
+
this.domElement.style.outline = 'none';
|
|
950
|
+
this.domElement.style.left = isAndroid ? `0` : `${bounds.left}px`;
|
|
951
|
+
this.domElement.style.top = isAndroid ? `0` : `${bounds.top}px`;
|
|
952
|
+
this.domElement.style.width = `${bounds.width}px`;
|
|
953
|
+
this.domElement.style.height = `${bounds.height}px`;
|
|
954
|
+
this.domElement.style.padding = '0';
|
|
955
|
+
|
|
956
|
+
if (this.options.debug) {
|
|
957
|
+
this.domElement.style.opacity = '0.8';
|
|
958
|
+
} else {
|
|
959
|
+
this.domElement.style.opacity = '0.0000001';
|
|
960
|
+
}
|
|
961
|
+
this.app.canvas.parentElement?.appendChild(this.domElement);
|
|
962
|
+
this.domElement.value = this.value;
|
|
963
|
+
this.domElement.setAttribute('placeholder', this.options?.placeholder?.text ?? '');
|
|
964
|
+
if (this.options?.maxLength) {
|
|
965
|
+
this.domElement.setAttribute('maxLength', this.options.maxLength.toString());
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
this._addDomElementListeners();
|
|
969
|
+
this._focusDomElement(selection);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
protected destroyDomElement() {
|
|
973
|
+
if (this.isClone) {
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
if (this.domElement) {
|
|
977
|
+
this._removeDomElementListeners();
|
|
978
|
+
this.domElement.remove();
|
|
979
|
+
|
|
980
|
+
if (this.domElement.parentNode) {
|
|
981
|
+
this.domElement.parentNode.removeChild(this.domElement);
|
|
982
|
+
}
|
|
983
|
+
// @ts-expect-error domelement can't be null
|
|
984
|
+
this.domElement = null;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
protected showCursor() {
|
|
989
|
+
this.caret.visible = true;
|
|
990
|
+
this.blinkCaret();
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
protected hideCursor() {
|
|
994
|
+
this.cursorAnimation?.kill();
|
|
995
|
+
this.caret.visible = false;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
protected blinkCaret() {
|
|
999
|
+
if (this.cursorAnimation) {
|
|
1000
|
+
this.cursorAnimation.kill();
|
|
1001
|
+
}
|
|
1002
|
+
this.cursorAnimation = gsap.fromTo(
|
|
1003
|
+
this.caret,
|
|
1004
|
+
{ alpha: 0 },
|
|
1005
|
+
{
|
|
1006
|
+
duration: 0.5,
|
|
1007
|
+
alpha: 1,
|
|
1008
|
+
yoyo: true,
|
|
1009
|
+
repeat: -1,
|
|
1010
|
+
overwrite: true,
|
|
1011
|
+
},
|
|
1012
|
+
);
|
|
1013
|
+
this.addAnimation(this.cursorAnimation);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
protected validate() {
|
|
1017
|
+
const hasError = this.error;
|
|
1018
|
+
if (this.isClone) {
|
|
1019
|
+
this.error = this.clone?.error || false;
|
|
1020
|
+
} else {
|
|
1021
|
+
this.error = !this.isValid;
|
|
1022
|
+
if (this.error && this.error !== hasError) {
|
|
1023
|
+
this.onError.emit({ input: this, domElement: this.domElement, value: this._value });
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
if (this.error !== hasError) {
|
|
1027
|
+
if (this.error && this.error !== hasError) {
|
|
1028
|
+
this.input.style.fill = this.options?.error?.input?.fill || 0x0;
|
|
1029
|
+
} else {
|
|
1030
|
+
this.input.style.fill = this.options.input?.style?.fill || 0x0;
|
|
1031
|
+
}
|
|
1032
|
+
this.drawBg();
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
if (this.cloneOverlay) {
|
|
1036
|
+
this.cloneOverlay.validate();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
private _removeDomElementListeners() {
|
|
1041
|
+
this.domElement.removeEventListener('focus', this._handleDomElementFocus, false);
|
|
1042
|
+
this.domElement.removeEventListener('blur', this._handleDomElementBlur, false);
|
|
1043
|
+
this.domElement.removeEventListener('input', this._handleDomElementChange, false);
|
|
1044
|
+
this.domElement.removeEventListener('keyup', this._handleDomElementKeyup, false);
|
|
1045
|
+
this.domElement.removeEventListener('keydown', this._handleDomElementKeydown, false);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
private _addDomElementListeners() {
|
|
1049
|
+
if (this.isClone) {
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
this._removeDomElementListeners();
|
|
1053
|
+
this.domElement.addEventListener('focus', this._handleDomElementFocus, false);
|
|
1054
|
+
this.domElement.addEventListener('blur', this._handleDomElementBlur, false);
|
|
1055
|
+
this.domElement.addEventListener('input', this._handleDomElementChange, false);
|
|
1056
|
+
this.domElement.addEventListener('keyup', this._handleDomElementKeyup, false);
|
|
1057
|
+
this.domElement.addEventListener('keydown', this._handleDomElementKeydown, false);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
private _handleFocus() {
|
|
1061
|
+
this._caretPosition = -1;
|
|
1062
|
+
this.showCursor();
|
|
1063
|
+
|
|
1064
|
+
clearTimeout(this._pointerDownTimer);
|
|
1065
|
+
|
|
1066
|
+
if (!this.isClone) {
|
|
1067
|
+
this._pointerDownTimer = setTimeout(() => {
|
|
1068
|
+
this.app.stage.on('pointerdown', this._checkPointerDownOutside);
|
|
1069
|
+
}, 250);
|
|
1070
|
+
|
|
1071
|
+
const hasOverlay = Boolean(this.options.focusOverlay.activeFilter);
|
|
1072
|
+
if (hasOverlay) {
|
|
1073
|
+
// decide if we should show an overlay
|
|
1074
|
+
if (this.cloneOverlay) {
|
|
1075
|
+
this._removeCloneOverlay();
|
|
1076
|
+
}
|
|
1077
|
+
const isList = Array.isArray(this.options.focusOverlay.activeFilter);
|
|
1078
|
+
let shouldShow = false;
|
|
1079
|
+
if (isList) {
|
|
1080
|
+
const filterList = this.options.focusOverlay.activeFilter as ('mobile' | 'touch' | 'desktop')[];
|
|
1081
|
+
if (
|
|
1082
|
+
(isMobile && filterList.includes('mobile')) ||
|
|
1083
|
+
(isTouch && filterList.includes('touch')) ||
|
|
1084
|
+
(!isMobile && !isTouch && filterList.includes('desktop'))
|
|
1085
|
+
) {
|
|
1086
|
+
shouldShow = true;
|
|
1087
|
+
}
|
|
1088
|
+
} else if (typeof this.options.focusOverlay.activeFilter === 'function') {
|
|
1089
|
+
shouldShow = this.options.focusOverlay.activeFilter();
|
|
1090
|
+
} else {
|
|
1091
|
+
shouldShow = hasOverlay;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
if (shouldShow) {
|
|
1095
|
+
const opts = structuredClone(this.options);
|
|
1096
|
+
const scale = this.options.focusOverlay?.scale || 1;
|
|
1097
|
+
opts.focusOverlay = { activeFilter: false };
|
|
1098
|
+
const fontSize = Number(opts.style?.fontSize || defaultOptions.style?.fontSize || 20) * scale;
|
|
1099
|
+
if (!opts.style) {
|
|
1100
|
+
opts.style = {};
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
opts.style.fontSize = fontSize;
|
|
1104
|
+
if (opts.padding) {
|
|
1105
|
+
opts.padding.left *= scale;
|
|
1106
|
+
opts.padding.top *= scale;
|
|
1107
|
+
opts.padding.right *= scale;
|
|
1108
|
+
opts.padding.bottom *= scale;
|
|
1109
|
+
}
|
|
1110
|
+
if (opts.bg?.radius) {
|
|
1111
|
+
opts.bg.radius *= scale;
|
|
1112
|
+
}
|
|
1113
|
+
if (opts.bg?.stroke?.width) {
|
|
1114
|
+
opts.bg.stroke.width *= scale;
|
|
1115
|
+
}
|
|
1116
|
+
if (opts.minWidth) {
|
|
1117
|
+
opts.minWidth *= scale;
|
|
1118
|
+
if (opts.minWidth > this.app.size.width) {
|
|
1119
|
+
opts.minWidth = this.app.size.width - (opts.bg?.stroke?.width ? opts.bg.stroke.width * 2 + 20 : 20);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
// should we show backing?
|
|
1124
|
+
if (this.options.focusOverlay?.backing?.active) {
|
|
1125
|
+
const backing = this.make.sprite({
|
|
1126
|
+
asset: Texture.WHITE,
|
|
1127
|
+
tint: this.options.focusOverlay.backing.options?.color ?? 0x0,
|
|
1128
|
+
alpha: this.options.focusOverlay.backing.options?.alpha ?? 0.8,
|
|
1129
|
+
width: this.app.size.width,
|
|
1130
|
+
height: this.app.size.height,
|
|
1131
|
+
eventMode: 'static',
|
|
1132
|
+
});
|
|
1133
|
+
this.overlayBacking = this.app.stage.addChild(backing);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
this.cloneOverlay = new Input(opts, true, this);
|
|
1137
|
+
this.cloneOverlay.label = `${this.label} -- clone`;
|
|
1138
|
+
this.cloneOverlay.alpha = 0;
|
|
1139
|
+
this.cloneOverlay.input.text = this.value;
|
|
1140
|
+
this.cloneOverlay.validate();
|
|
1141
|
+
this.app.stage.addChild(this.cloneOverlay);
|
|
1142
|
+
this._positionCloneOverlay();
|
|
1143
|
+
this._showCloneOverlay();
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
private _showCloneOverlay() {
|
|
1150
|
+
this.cloneOverlay.pivot.y = -20;
|
|
1151
|
+
this.addAnimation(gsap.to(this.cloneOverlay, { duration: 0.5, alpha: 0.8, ease: 'sine.out', delay: 0.1 }));
|
|
1152
|
+
this.addAnimation(gsap.to(this.cloneOverlay.pivot, { duration: 0.5, y: 0, ease: 'sine.out', delay: 0.1 }));
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
private _positionCloneOverlay() {
|
|
1156
|
+
if (!this.cloneOverlay) {
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
const w = this.cloneOverlay.options.minWidth;
|
|
1160
|
+
this.cloneOverlay.x = this.app.size.width * 0.5 - w * 0.5;
|
|
1161
|
+
this.cloneOverlay.y = this.options.focusOverlay?.marginTop || 20;
|
|
1162
|
+
if (this.overlayBacking) {
|
|
1163
|
+
this.overlayBacking.width = this.app.size.width;
|
|
1164
|
+
this.overlayBacking.height = this.app.size.height;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
private _removeCloneOverlay() {
|
|
1169
|
+
this.overlayBacking?.destroy();
|
|
1170
|
+
this.overlayBacking?.parent?.removeChild(this.overlayBacking);
|
|
1171
|
+
// @ts-expect-error cloneOverlay can't be null
|
|
1172
|
+
this.overlayBacking = null;
|
|
1173
|
+
this.cloneOverlay?.destroy();
|
|
1174
|
+
this.cloneOverlay?.parent?.removeChild(this.cloneOverlay);
|
|
1175
|
+
// @ts-expect-error cloneOverlay can't be null
|
|
1176
|
+
this.cloneOverlay = null;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
private _handleDomElementFocus() {
|
|
1180
|
+
this.app.stage.off('pointerdown', this._checkPointerDownOutside);
|
|
1181
|
+
this._handleFocus();
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
private _handleDomElementBlur() {
|
|
1185
|
+
if (this.isClone) {
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
clearTimeout(this._focusTimer);
|
|
1189
|
+
clearTimeout(this._pointerDownTimer);
|
|
1190
|
+
this.hideCursor();
|
|
1191
|
+
this._removeCloneOverlay();
|
|
1192
|
+
this.destroyDomElement();
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
private _handleDomElementKeyup() {
|
|
1196
|
+
this._updateCaretAndSelection();
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
private _handleDomElementKeydown(e: KeyboardEvent) {
|
|
1200
|
+
this._updateCaretAndSelection();
|
|
1201
|
+
if (!this.isClone && e.key === 'Enter') {
|
|
1202
|
+
if (this.options.blurOnEnter) {
|
|
1203
|
+
this.domElement.blur();
|
|
1204
|
+
}
|
|
1205
|
+
this.onEnter.emit({ input: this, value: this._value, domElement: this.domElement });
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
private _updateCaretAndSelection() {
|
|
1210
|
+
if (!this.domElement) {
|
|
1211
|
+
Logger.warn(this.label, 'No dom element');
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
const start = this.domElement.selectionStart || 0;
|
|
1215
|
+
const end = this.domElement.selectionEnd || -1;
|
|
1216
|
+
const direction = this.domElement.selectionDirection;
|
|
1217
|
+
let text = '';
|
|
1218
|
+
const value = this.options.type === 'password' ? this.input.text : this._value;
|
|
1219
|
+
if (end === undefined) {
|
|
1220
|
+
text = value.substring(0, start);
|
|
1221
|
+
const metrics = CanvasTextMetrics.measureText(text, this.input.style);
|
|
1222
|
+
this._caretPosition = metrics.width;
|
|
1223
|
+
this._selectionRect = null;
|
|
1224
|
+
} else {
|
|
1225
|
+
text = value.substring(start > end ? end : start, start > end ? start : end);
|
|
1226
|
+
const toStart = value.substring(0, start > end ? end : start);
|
|
1227
|
+
const leftMetrics = CanvasTextMetrics.measureText(toStart, this.input.style);
|
|
1228
|
+
const textMetrics = CanvasTextMetrics.measureText(text, this.input.style);
|
|
1229
|
+
this._selectionRect = new Rectangle(leftMetrics.width, 0, textMetrics.width, this.input.height);
|
|
1230
|
+
this._caretPosition =
|
|
1231
|
+
direction === 'backward' ? this._selectionRect.left : this._selectionRect.left + this._selectionRect.width;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
private _handleDomElementChange(e: Event) {
|
|
1236
|
+
const target = e.target as HTMLInputElement;
|
|
1237
|
+
if (target && !this.domElement) {
|
|
1238
|
+
this.domElement = target;
|
|
1239
|
+
}
|
|
1240
|
+
if (this.options.pattern !== '') {
|
|
1241
|
+
const filteredValue = target.value.replace(new RegExp(this.options.pattern, 'g'), '');
|
|
1242
|
+
target.value = filteredValue;
|
|
1243
|
+
this._value = filteredValue;
|
|
1244
|
+
} else {
|
|
1245
|
+
this._value = target.value;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
this.input.text =
|
|
1249
|
+
this.options.type === 'password'
|
|
1250
|
+
? this._value
|
|
1251
|
+
?.split('')
|
|
1252
|
+
.map(() => '*')
|
|
1253
|
+
.join('')
|
|
1254
|
+
: this._value;
|
|
1255
|
+
|
|
1256
|
+
this._updateCaretAndSelection();
|
|
1257
|
+
|
|
1258
|
+
if (!this.isClone) {
|
|
1259
|
+
this.onChange.emit({ input: this, domElement: this.domElement, value: this._value });
|
|
1260
|
+
this.validate();
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Gets the focusable area bounds
|
|
1266
|
+
* @returns {Bounds} The bounds of the input container
|
|
1267
|
+
*/
|
|
1268
|
+
getFocusArea(): Bounds {
|
|
1269
|
+
const bounds = this._inputContainer.getBounds();
|
|
1270
|
+
bounds.width = this._lastWidth;
|
|
1271
|
+
bounds.height = this._lastHeight;
|
|
1272
|
+
return bounds;
|
|
1273
|
+
}
|
|
1274
|
+
}
|