yummies 5.4.6 → 5.4.8
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/async.cjs +70 -0
- package/async.d.cts +28 -0
- package/async.d.cts.map +1 -0
- package/async.d.ts +28 -0
- package/async.d.ts.map +1 -0
- package/async.js +62 -0
- package/common.cjs +18 -0
- package/common.d.cts +15 -0
- package/common.d.cts.map +1 -0
- package/common.d.ts +15 -0
- package/common.d.ts.map +1 -0
- package/common.js +14 -0
- package/complex/counter.cjs +21 -0
- package/complex/counter.d.cts +15 -0
- package/complex/counter.d.cts.map +1 -0
- package/complex/counter.d.ts +15 -0
- package/complex/counter.d.ts.map +1 -0
- package/complex/counter.js +17 -0
- package/complex/global-config.cjs +46 -0
- package/complex/global-config.d.cts +11 -0
- package/complex/global-config.d.cts.map +1 -0
- package/complex/global-config.d.ts +11 -0
- package/complex/global-config.d.ts.map +1 -0
- package/complex/global-config.js +41 -0
- package/complex/index.cjs +19 -0
- package/complex/index.d.cts +4 -0
- package/complex/index.d.cts.map +1 -0
- package/complex/index.d.ts +4 -0
- package/complex/index.d.ts.map +1 -0
- package/complex/index.js +3 -0
- package/complex/modules-factory.cjs +50 -0
- package/complex/modules-factory.d.cts +49 -0
- package/complex/modules-factory.d.cts.map +1 -0
- package/complex/modules-factory.d.ts +49 -0
- package/complex/modules-factory.d.ts.map +1 -0
- package/complex/modules-factory.js +46 -0
- package/cookie.cjs +13 -0
- package/cookie.d.cts +3 -0
- package/cookie.d.cts.map +1 -0
- package/cookie.d.ts +3 -0
- package/cookie.d.ts.map +1 -0
- package/cookie.js +9 -0
- package/css.cjs +28 -0
- package/css.d.cts +36 -0
- package/css.d.cts.map +1 -0
- package/css.d.ts +36 -0
- package/css.d.ts.map +1 -0
- package/css.js +20 -0
- package/data.cjs +58 -0
- package/data.d.cts +4 -0
- package/data.d.cts.map +1 -0
- package/data.d.ts +4 -0
- package/data.d.ts.map +1 -0
- package/data.js +52 -0
- package/date-time.cjs +171 -0
- package/date-time.d.cts +28 -0
- package/date-time.d.cts.map +1 -0
- package/date-time.d.ts +28 -0
- package/date-time.d.ts.map +1 -0
- package/date-time.js +160 -0
- package/device.cjs +28 -0
- package/device.d.cts +8 -0
- package/device.d.cts.map +1 -0
- package/device.d.ts +8 -0
- package/device.d.ts.map +1 -0
- package/device.js +21 -0
- package/encodings.cjs +270 -0
- package/encodings.d.cts +2 -0
- package/encodings.d.cts.map +1 -0
- package/encodings.d.ts +2 -0
- package/encodings.d.ts.map +1 -0
- package/encodings.js +267 -0
- package/errors.cjs +34 -0
- package/errors.d.cts +19 -0
- package/errors.d.cts.map +1 -0
- package/errors.d.ts +19 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +30 -0
- package/file.cjs +29 -0
- package/file.d.cts +3 -0
- package/file.d.cts.map +1 -0
- package/file.d.ts +3 -0
- package/file.d.ts.map +1 -0
- package/file.js +24 -0
- package/format/_exports.cjs +20 -0
- package/format/_exports.d.cts +5 -0
- package/format/_exports.d.cts.map +1 -0
- package/format/_exports.d.ts +5 -0
- package/format/_exports.d.ts.map +1 -0
- package/format/_exports.js +4 -0
- package/format/constants.cjs +6 -0
- package/format/constants.d.cts +4 -0
- package/format/constants.d.cts.map +1 -0
- package/format/constants.d.ts +4 -0
- package/format/constants.d.ts.map +1 -0
- package/{src/format/constants.ts → format/constants.js} +0 -2
- package/format/index.cjs +40 -0
- package/format/index.d.cts +3 -0
- package/format/index.d.cts.map +1 -0
- package/format/index.d.ts +3 -0
- package/format/index.d.ts.map +1 -0
- package/{src/format/index.ts → format/index.js} +1 -2
- package/format/number.cjs +48 -0
- package/format/number.d.cts +36 -0
- package/format/number.d.cts.map +1 -0
- package/format/number.d.ts +36 -0
- package/format/number.d.ts.map +1 -0
- package/format/number.js +44 -0
- package/format/percent.cjs +27 -0
- package/format/percent.d.cts +15 -0
- package/format/percent.d.cts.map +1 -0
- package/format/percent.d.ts +15 -0
- package/format/percent.d.ts.map +1 -0
- package/format/percent.js +23 -0
- package/format/skip-spaces.cjs +8 -0
- package/format/skip-spaces.d.cts +5 -0
- package/format/skip-spaces.d.cts.map +1 -0
- package/format/skip-spaces.d.ts +5 -0
- package/format/skip-spaces.d.ts.map +1 -0
- package/format/skip-spaces.js +4 -0
- package/html.cjs +202 -0
- package/html.d.cts +44 -0
- package/html.d.cts.map +1 -0
- package/html.d.ts +44 -0
- package/html.d.ts.map +1 -0
- package/html.js +182 -0
- package/id.cjs +76 -0
- package/id.d.cts +63 -0
- package/id.d.cts.map +1 -0
- package/id.d.ts +63 -0
- package/id.d.ts.map +1 -0
- package/{src/id.ts → id.js} +6 -16
- package/imports.cjs +45 -0
- package/imports.d.cts +15 -0
- package/imports.d.cts.map +1 -0
- package/imports.d.ts +15 -0
- package/imports.d.ts.map +1 -0
- package/imports.js +40 -0
- package/math.cjs +23 -0
- package/math.d.cts +13 -0
- package/math.d.cts.map +1 -0
- package/math.d.ts +13 -0
- package/math.d.ts.map +1 -0
- package/math.js +17 -0
- package/media.cjs +115 -0
- package/media.d.cts +20 -0
- package/media.d.cts.map +1 -0
- package/media.d.ts +20 -0
- package/media.d.ts.map +1 -0
- package/media.js +103 -0
- package/mobx/apply-observable.cjs +16 -0
- package/mobx/apply-observable.d.cts +4 -0
- package/mobx/apply-observable.d.cts.map +1 -0
- package/mobx/apply-observable.d.ts +4 -0
- package/mobx/apply-observable.d.ts.map +1 -0
- package/mobx/apply-observable.js +12 -0
- package/mobx/create-enhanced-atom.cjs +16 -0
- package/mobx/create-enhanced-atom.d.cts +11 -0
- package/mobx/create-enhanced-atom.d.cts.map +1 -0
- package/mobx/create-enhanced-atom.d.ts +11 -0
- package/mobx/create-enhanced-atom.d.ts.map +1 -0
- package/mobx/create-enhanced-atom.js +12 -0
- package/mobx/deep-observable-struct.cjs +61 -0
- package/mobx/deep-observable-struct.d.cts +7 -0
- package/mobx/deep-observable-struct.d.cts.map +1 -0
- package/mobx/deep-observable-struct.d.ts +7 -0
- package/mobx/deep-observable-struct.d.ts.map +1 -0
- package/mobx/deep-observable-struct.js +57 -0
- package/mobx/get-mobx-administration.cjs +6 -0
- package/mobx/get-mobx-administration.d.cts +6 -0
- package/mobx/get-mobx-administration.d.cts.map +1 -0
- package/mobx/get-mobx-administration.d.ts +6 -0
- package/mobx/get-mobx-administration.d.ts.map +1 -0
- package/mobx/get-mobx-administration.js +2 -0
- package/mobx/index.cjs +21 -0
- package/mobx/index.d.cts +6 -0
- package/mobx/index.d.cts.map +1 -0
- package/mobx/index.d.ts +6 -0
- package/mobx/index.d.ts.map +1 -0
- package/mobx/index.js +5 -0
- package/mobx/lazy-observe.cjs +47 -0
- package/mobx/lazy-observe.d.cts +8 -0
- package/mobx/lazy-observe.d.cts.map +1 -0
- package/mobx/lazy-observe.d.ts +8 -0
- package/mobx/lazy-observe.d.ts.map +1 -0
- package/mobx/lazy-observe.js +43 -0
- package/ms.cjs +22 -0
- package/ms.d.cts +19 -0
- package/ms.d.cts.map +1 -0
- package/ms.d.ts +19 -0
- package/ms.d.ts.map +1 -0
- package/ms.js +18 -0
- package/number.cjs +16 -0
- package/number.d.cts +8 -0
- package/number.d.cts.map +1 -0
- package/number.d.ts +8 -0
- package/number.d.ts.map +1 -0
- package/number.js +13 -0
- package/package.json +163 -5
- package/parser/_exports.cjs +19 -0
- package/parser/_exports.d.cts +4 -0
- package/parser/_exports.d.cts.map +1 -0
- package/parser/_exports.d.ts +4 -0
- package/parser/_exports.d.ts.map +1 -0
- package/parser/_exports.js +3 -0
- package/parser/index.cjs +40 -0
- package/parser/index.d.cts +3 -0
- package/parser/index.d.cts.map +1 -0
- package/parser/index.d.ts +3 -0
- package/parser/index.d.ts.map +1 -0
- package/{src/parser/index.ts → parser/index.js} +1 -2
- package/parser/number.cjs +48 -0
- package/parser/number.d.cts +21 -0
- package/parser/number.d.cts.map +1 -0
- package/parser/number.d.ts +21 -0
- package/parser/number.d.ts.map +1 -0
- package/parser/number.js +44 -0
- package/parser/percent.cjs +8 -0
- package/parser/percent.d.cts +4 -0
- package/parser/percent.d.cts.map +1 -0
- package/parser/percent.d.ts +4 -0
- package/parser/percent.d.ts.map +1 -0
- package/parser/percent.js +4 -0
- package/parser/string.cjs +18 -0
- package/parser/string.d.cts +7 -0
- package/parser/string.d.cts.map +1 -0
- package/parser/string.d.ts +7 -0
- package/parser/string.d.ts.map +1 -0
- package/parser/string.js +14 -0
- package/price.cjs +21 -0
- package/price.d.cts +6 -0
- package/price.d.cts.map +1 -0
- package/price.d.ts +6 -0
- package/price.d.ts.map +1 -0
- package/price.js +17 -0
- package/random.cjs +25 -0
- package/random.d.cts +9 -0
- package/random.d.cts.map +1 -0
- package/random.d.ts +9 -0
- package/random.d.ts.map +1 -0
- package/random.js +14 -0
- package/react/hooks/index.cjs +37 -0
- package/react/hooks/index.d.cts +22 -0
- package/react/hooks/index.d.cts.map +1 -0
- package/react/hooks/index.d.ts +22 -0
- package/react/hooks/index.d.ts.map +1 -0
- package/react/hooks/index.js +21 -0
- package/react/hooks/use-abort-controller.cjs +15 -0
- package/react/hooks/use-abort-controller.d.cts +2 -0
- package/react/hooks/use-abort-controller.d.cts.map +1 -0
- package/react/hooks/use-abort-controller.d.ts +2 -0
- package/react/hooks/use-abort-controller.d.ts.map +1 -0
- package/react/hooks/use-abort-controller.js +11 -0
- package/react/hooks/use-abort-signal.cjs +8 -0
- package/react/hooks/use-abort-signal.d.cts +2 -0
- package/react/hooks/use-abort-signal.d.cts.map +1 -0
- package/react/hooks/use-abort-signal.d.ts +2 -0
- package/react/hooks/use-abort-signal.d.ts.map +1 -0
- package/react/hooks/use-abort-signal.js +4 -0
- package/react/hooks/use-click-outside.cjs +17 -0
- package/react/hooks/use-click-outside.d.cts +9 -0
- package/react/hooks/use-click-outside.d.cts.map +1 -0
- package/react/hooks/use-click-outside.d.ts +9 -0
- package/react/hooks/use-click-outside.d.ts.map +1 -0
- package/react/hooks/use-click-outside.js +13 -0
- package/react/hooks/use-constant.cjs +19 -0
- package/react/hooks/use-constant.d.cts +9 -0
- package/react/hooks/use-constant.d.cts.map +1 -0
- package/react/hooks/use-constant.d.ts +9 -0
- package/react/hooks/use-constant.d.ts.map +1 -0
- package/{src/react/hooks/use-constant.ts → react/hooks/use-constant.js} +6 -9
- package/react/hooks/use-define-ref.cjs +19 -0
- package/react/hooks/use-define-ref.d.cts +10 -0
- package/react/hooks/use-define-ref.d.cts.map +1 -0
- package/react/hooks/use-define-ref.d.ts +10 -0
- package/react/hooks/use-define-ref.d.ts.map +1 -0
- package/{src/react/hooks/use-define-ref.ts → react/hooks/use-define-ref.js} +7 -10
- package/react/hooks/use-element-ref.cjs +12 -0
- package/react/hooks/use-element-ref.d.cts +2 -0
- package/react/hooks/use-element-ref.d.cts.map +1 -0
- package/react/hooks/use-element-ref.d.ts +2 -0
- package/react/hooks/use-element-ref.d.ts.map +1 -0
- package/react/hooks/use-element-ref.js +8 -0
- package/react/hooks/use-event-listener.cjs +17 -0
- package/react/hooks/use-event-listener.d.cts +8 -0
- package/react/hooks/use-event-listener.d.cts.map +1 -0
- package/react/hooks/use-event-listener.d.ts +8 -0
- package/react/hooks/use-event-listener.d.ts.map +1 -0
- package/react/hooks/use-event-listener.js +13 -0
- package/react/hooks/use-event.cjs +23 -0
- package/react/hooks/use-event.d.cts +3 -0
- package/react/hooks/use-event.d.cts.map +1 -0
- package/react/hooks/use-event.d.ts +3 -0
- package/react/hooks/use-event.d.ts.map +1 -0
- package/react/hooks/use-event.js +19 -0
- package/react/hooks/use-flag.cjs +19 -0
- package/react/hooks/use-flag.d.cts +8 -0
- package/react/hooks/use-flag.d.cts.map +1 -0
- package/react/hooks/use-flag.d.ts +8 -0
- package/react/hooks/use-flag.d.ts.map +1 -0
- package/react/hooks/use-flag.js +15 -0
- package/react/hooks/use-force-update.cjs +11 -0
- package/react/hooks/use-force-update.d.cts +2 -0
- package/react/hooks/use-force-update.d.cts.map +1 -0
- package/react/hooks/use-force-update.d.ts +2 -0
- package/react/hooks/use-force-update.d.ts.map +1 -0
- package/react/hooks/use-force-update.js +7 -0
- package/react/hooks/use-initial-height.cjs +15 -0
- package/react/hooks/use-initial-height.d.cts +5 -0
- package/react/hooks/use-initial-height.d.cts.map +1 -0
- package/react/hooks/use-initial-height.d.ts +5 -0
- package/react/hooks/use-initial-height.d.ts.map +1 -0
- package/react/hooks/use-initial-height.js +11 -0
- package/react/hooks/use-instance.cjs +31 -0
- package/react/hooks/use-instance.d.cts +27 -0
- package/react/hooks/use-instance.d.cts.map +1 -0
- package/react/hooks/use-instance.d.ts +27 -0
- package/react/hooks/use-instance.d.ts.map +1 -0
- package/{src/react/hooks/use-instance.ts → react/hooks/use-instance.js} +9 -31
- package/react/hooks/use-intersection-observer.cjs +14 -0
- package/react/hooks/use-intersection-observer.d.cts +2 -0
- package/react/hooks/use-intersection-observer.d.cts.map +1 -0
- package/react/hooks/use-intersection-observer.d.ts +2 -0
- package/react/hooks/use-intersection-observer.d.ts.map +1 -0
- package/react/hooks/use-intersection-observer.js +10 -0
- package/react/hooks/use-last-defined-value.cjs +12 -0
- package/react/hooks/use-last-defined-value.d.cts +2 -0
- package/react/hooks/use-last-defined-value.d.cts.map +1 -0
- package/react/hooks/use-last-defined-value.d.ts +2 -0
- package/react/hooks/use-last-defined-value.d.ts.map +1 -0
- package/react/hooks/use-last-defined-value.js +8 -0
- package/react/hooks/use-last-value-ref.cjs +12 -0
- package/react/hooks/use-last-value-ref.d.cts +2 -0
- package/react/hooks/use-last-value-ref.d.cts.map +1 -0
- package/react/hooks/use-last-value-ref.d.ts +2 -0
- package/react/hooks/use-last-value-ref.d.ts.map +1 -0
- package/react/hooks/use-last-value-ref.js +8 -0
- package/react/hooks/use-life-cycle.cjs +14 -0
- package/react/hooks/use-life-cycle.d.cts +5 -0
- package/react/hooks/use-life-cycle.d.cts.map +1 -0
- package/react/hooks/use-life-cycle.d.ts +5 -0
- package/react/hooks/use-life-cycle.d.ts.map +1 -0
- package/react/hooks/use-life-cycle.js +10 -0
- package/react/hooks/use-resize-observer.cjs +15 -0
- package/react/hooks/use-resize-observer.d.cts +2 -0
- package/react/hooks/use-resize-observer.d.cts.map +1 -0
- package/react/hooks/use-resize-observer.d.ts +2 -0
- package/react/hooks/use-resize-observer.d.ts.map +1 -0
- package/react/hooks/use-resize-observer.js +11 -0
- package/react/hooks/use-sync-ref.cjs +10 -0
- package/react/hooks/use-sync-ref.d.cts +2 -0
- package/react/hooks/use-sync-ref.d.cts.map +1 -0
- package/react/hooks/use-sync-ref.d.ts +2 -0
- package/react/hooks/use-sync-ref.d.ts.map +1 -0
- package/react/hooks/use-sync-ref.js +6 -0
- package/react/hooks/use-toggle.cjs +10 -0
- package/react/hooks/use-toggle.d.cts +2 -0
- package/react/hooks/use-toggle.d.cts.map +1 -0
- package/react/hooks/use-toggle.d.ts +2 -0
- package/react/hooks/use-toggle.d.ts.map +1 -0
- package/react/hooks/use-toggle.js +6 -0
- package/react/hooks/use-value.cjs +12 -0
- package/react/hooks/use-value.d.cts +5 -0
- package/react/hooks/use-value.d.cts.map +1 -0
- package/react/hooks/use-value.d.ts +5 -0
- package/react/hooks/use-value.d.ts.map +1 -0
- package/react/hooks/use-value.js +8 -0
- package/react/hooks/use-visibility-state.cjs +18 -0
- package/react/hooks/use-visibility-state.d.cts +2 -0
- package/react/hooks/use-visibility-state.d.cts.map +1 -0
- package/react/hooks/use-visibility-state.d.ts +2 -0
- package/react/hooks/use-visibility-state.d.ts.map +1 -0
- package/react/hooks/use-visibility-state.js +14 -0
- package/react/index.cjs +17 -0
- package/react/index.d.cts +2 -0
- package/react/index.d.cts.map +1 -0
- package/react/index.d.ts +2 -0
- package/react/index.d.ts.map +1 -0
- package/react/index.js +1 -0
- package/sound.cjs +16 -0
- package/sound.d.cts +7 -0
- package/sound.d.cts.map +1 -0
- package/sound.d.ts +7 -0
- package/sound.d.ts.map +1 -0
- package/sound.js +12 -0
- package/storage.cjs +48 -0
- package/storage.d.cts +39 -0
- package/storage.d.cts.map +1 -0
- package/storage.d.ts +39 -0
- package/storage.d.ts.map +1 -0
- package/storage.js +43 -0
- package/text.cjs +53 -0
- package/text.d.cts +15 -0
- package/text.d.cts.map +1 -0
- package/text.d.ts +15 -0
- package/text.d.ts.map +1 -0
- package/text.js +48 -0
- package/type-guard/_exports.cjs +129 -0
- package/type-guard/_exports.d.cts +86 -0
- package/type-guard/_exports.d.cts.map +1 -0
- package/type-guard/_exports.d.ts +86 -0
- package/type-guard/_exports.d.ts.map +1 -0
- package/type-guard/_exports.js +125 -0
- package/type-guard/index.cjs +40 -0
- package/type-guard/index.d.cts +3 -0
- package/type-guard/index.d.cts.map +1 -0
- package/type-guard/index.d.ts +3 -0
- package/type-guard/index.d.ts.map +1 -0
- package/{src/type-guard/index.ts → type-guard/index.js} +1 -2
- package/utility-types.d.ts +396 -0
- package/utils/types.cjs +2 -0
- package/utils/types.d.cts +395 -0
- package/utils/types.d.cts.map +1 -0
- package/utils/types.d.ts +395 -0
- package/utils/types.d.ts.map +1 -0
- package/utils/types.js +1 -0
- package/vibrate.cjs +12 -0
- package/vibrate.d.cts +5 -0
- package/vibrate.d.cts.map +1 -0
- package/vibrate.d.ts +5 -0
- package/vibrate.d.ts.map +1 -0
- package/vibrate.js +8 -0
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.github/FUNDING.yml +0 -1
- package/.github/workflows/main.yml +0 -34
- package/.github/workflows/version-or-publish.yml +0 -45
- package/.nvmrc +0 -1
- package/.vscode/settings.json +0 -19
- package/CHANGELOG.md +0 -215
- package/CONTRIBUTING.md +0 -8
- package/Makefile +0 -7
- package/biome.json +0 -3
- package/commitfmt.toml +0 -18
- package/lefthook.yml +0 -14
- package/scripts/post-build.ts +0 -71
- package/src/async.ts +0 -86
- package/src/common.ts +0 -26
- package/src/complex/counter.test.ts +0 -41
- package/src/complex/counter.ts +0 -40
- package/src/complex/global-config.ts +0 -55
- package/src/complex/index.ts +0 -3
- package/src/complex/modules-factory.ts +0 -65
- package/src/cookie.ts +0 -11
- package/src/css.ts +0 -60
- package/src/data.test.ts +0 -99
- package/src/data.ts +0 -65
- package/src/date-time.test.ts +0 -119
- package/src/date-time.ts +0 -236
- package/src/device.ts +0 -42
- package/src/encodings.ts +0 -270
- package/src/errors.ts +0 -40
- package/src/file.ts +0 -25
- package/src/format/_exports.ts +0 -4
- package/src/format/number.test.ts +0 -16
- package/src/format/number.ts +0 -96
- package/src/format/percent.ts +0 -40
- package/src/format/skip-spaces.ts +0 -4
- package/src/html.ts +0 -238
- package/src/imports.ts +0 -52
- package/src/math.ts +0 -20
- package/src/media.ts +0 -134
- package/src/mobx/apply-observable.ts +0 -20
- package/src/mobx/create-enhanced-atom.ts +0 -28
- package/src/mobx/deep-observable-struct.test.ts +0 -69
- package/src/mobx/deep-observable-struct.ts +0 -69
- package/src/mobx/get-mobx-administration.ts +0 -10
- package/src/mobx/index.ts +0 -5
- package/src/mobx/lazy-observe.ts +0 -59
- package/src/ms.ts +0 -20
- package/src/number.ts +0 -14
- package/src/parser/_exports.ts +0 -3
- package/src/parser/number.test.ts +0 -38
- package/src/parser/number.ts +0 -73
- package/src/parser/percent.ts +0 -11
- package/src/parser/string.ts +0 -29
- package/src/price.ts +0 -33
- package/src/random.ts +0 -27
- package/src/react/hooks/index.ts +0 -21
- package/src/react/hooks/use-abort-controller.ts +0 -15
- package/src/react/hooks/use-abort-signal.ts +0 -5
- package/src/react/hooks/use-click-outside.ts +0 -27
- package/src/react/hooks/use-element-ref.ts +0 -11
- package/src/react/hooks/use-event-listener.ts +0 -29
- package/src/react/hooks/use-event.ts +0 -23
- package/src/react/hooks/use-flag.ts +0 -27
- package/src/react/hooks/use-force-update.ts +0 -9
- package/src/react/hooks/use-initial-height.ts +0 -16
- package/src/react/hooks/use-intersection-observer.ts +0 -18
- package/src/react/hooks/use-last-defined-value.ts +0 -9
- package/src/react/hooks/use-last-value-ref.ts +0 -11
- package/src/react/hooks/use-life-cycle.ts +0 -17
- package/src/react/hooks/use-resize-observer.ts +0 -14
- package/src/react/hooks/use-sync-ref.ts +0 -7
- package/src/react/hooks/use-toggle.ts +0 -9
- package/src/react/hooks/use-value.ts +0 -10
- package/src/react/hooks/use-visibility-state.ts +0 -19
- package/src/react/index.ts +0 -1
- package/src/sound.ts +0 -15
- package/src/storage.ts +0 -137
- package/src/text.test.ts +0 -91
- package/src/text.ts +0 -60
- package/src/type-guard/_exports.ts +0 -154
- package/src/type-guard/index.test.ts +0 -127
- package/src/vibrate.ts +0 -8
- package/tsconfig.json +0 -26
- package/tsconfig.test.json +0 -33
- package/vitest.config.ts +0 -20
package/src/html.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import DOMPurify, { type Config as DOMPurifyConfig } from 'dompurify';
|
|
2
|
-
|
|
3
|
-
import { blobToUrl } from './media.js';
|
|
4
|
-
import type { Maybe } from './utils/types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Вытаскивает RGB из любого цвета
|
|
8
|
-
*
|
|
9
|
-
* Не рекомендуется к использованию так как вызывает reflow
|
|
10
|
-
*/
|
|
11
|
-
export const getComputedColor = (color?: string): string | null => {
|
|
12
|
-
if (!color) return null;
|
|
13
|
-
|
|
14
|
-
const d = document.createElement('div');
|
|
15
|
-
d.style.color = color;
|
|
16
|
-
document.body.append(d);
|
|
17
|
-
const rgbcolor = globalThis.getComputedStyle(d).color;
|
|
18
|
-
const match =
|
|
19
|
-
/rgba?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*\d+[.d+]*)*\)/g.exec(rgbcolor);
|
|
20
|
-
|
|
21
|
-
d.remove();
|
|
22
|
-
|
|
23
|
-
if (!match) return null;
|
|
24
|
-
|
|
25
|
-
return `${match[1]}, ${match[2]}, ${match[3]}`;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const downloadUsingAnchor = (
|
|
29
|
-
urlOrBlob: string | Blob,
|
|
30
|
-
fileName?: string,
|
|
31
|
-
) => {
|
|
32
|
-
const url = blobToUrl(urlOrBlob);
|
|
33
|
-
|
|
34
|
-
const a = document.createElement('a');
|
|
35
|
-
a.href = url;
|
|
36
|
-
|
|
37
|
-
a.download = fileName ?? 'file';
|
|
38
|
-
|
|
39
|
-
a.target = '_blank';
|
|
40
|
-
|
|
41
|
-
document.body.append(a);
|
|
42
|
-
|
|
43
|
-
a.click();
|
|
44
|
-
|
|
45
|
-
a.remove();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Surrounds string in an anchor tag
|
|
50
|
-
*/
|
|
51
|
-
export function wrapTextToTagLink(link: string) {
|
|
52
|
-
const descr = String(link).replace(/^(https?:\/{0,2})?(w{3}\.)?/, 'www.');
|
|
53
|
-
if (!/^https?:\/{2}/.test(link)) link = `http://${link}`;
|
|
54
|
-
return `<a href=${link} target="_blank">${descr}</a>`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const collectOffsetTop = (element: HTMLElement | null) => {
|
|
58
|
-
let offsetTop = 0;
|
|
59
|
-
let node = element;
|
|
60
|
-
|
|
61
|
-
while (node != null) {
|
|
62
|
-
offsetTop += node.offsetTop;
|
|
63
|
-
node = node.parentElement;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return offsetTop;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const skipEvent = (e: Event) => {
|
|
70
|
-
e.preventDefault();
|
|
71
|
-
e.stopPropagation();
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const globalScrollIntoViewForY = (node: HTMLElement) => {
|
|
77
|
-
const scrollContainer = document.body;
|
|
78
|
-
const pageHeight = window.innerHeight;
|
|
79
|
-
const nodeBounding = node.getBoundingClientRect();
|
|
80
|
-
const scrollPagesCount = scrollContainer.scrollHeight / pageHeight;
|
|
81
|
-
|
|
82
|
-
const scrollPageNumber = Math.min(
|
|
83
|
-
Math.max(nodeBounding.top / pageHeight, 1),
|
|
84
|
-
scrollPagesCount,
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
window.scroll({
|
|
88
|
-
top: scrollPageNumber * pageHeight,
|
|
89
|
-
behavior: 'smooth',
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const sanitizeDefaults: DOMPurifyConfig = {
|
|
94
|
-
ALLOWED_TAGS: [
|
|
95
|
-
'a',
|
|
96
|
-
'article',
|
|
97
|
-
'b',
|
|
98
|
-
'blockquote',
|
|
99
|
-
'br',
|
|
100
|
-
'caption',
|
|
101
|
-
'code',
|
|
102
|
-
'del',
|
|
103
|
-
'details',
|
|
104
|
-
'div',
|
|
105
|
-
'em',
|
|
106
|
-
'h1',
|
|
107
|
-
'h2',
|
|
108
|
-
'h3',
|
|
109
|
-
'h4',
|
|
110
|
-
'h5',
|
|
111
|
-
'h6',
|
|
112
|
-
'hr',
|
|
113
|
-
'i',
|
|
114
|
-
'img',
|
|
115
|
-
'ins',
|
|
116
|
-
'kbd',
|
|
117
|
-
'li',
|
|
118
|
-
'main',
|
|
119
|
-
'ol',
|
|
120
|
-
'p',
|
|
121
|
-
'pre',
|
|
122
|
-
'section',
|
|
123
|
-
'span',
|
|
124
|
-
'strong',
|
|
125
|
-
'sub',
|
|
126
|
-
'summary',
|
|
127
|
-
'sup',
|
|
128
|
-
'table',
|
|
129
|
-
'tbody',
|
|
130
|
-
'td',
|
|
131
|
-
'th',
|
|
132
|
-
'thead',
|
|
133
|
-
'tr',
|
|
134
|
-
'u',
|
|
135
|
-
'ul',
|
|
136
|
-
],
|
|
137
|
-
ALLOWED_ATTR: ['href', 'target', 'name', 'src', 'class'],
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export const sanitizeHtml = (html: Maybe<string>, config?: DOMPurifyConfig) => {
|
|
141
|
-
return DOMPurify.sanitize(html || '', {
|
|
142
|
-
...sanitizeDefaults,
|
|
143
|
-
...config,
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const checkElementHasParent = (
|
|
148
|
-
element: HTMLElement | null,
|
|
149
|
-
parent: Maybe<HTMLElement>,
|
|
150
|
-
) => {
|
|
151
|
-
let node = element;
|
|
152
|
-
|
|
153
|
-
if (!parent) return false;
|
|
154
|
-
|
|
155
|
-
while (node != null) {
|
|
156
|
-
if (node === parent) {
|
|
157
|
-
return true;
|
|
158
|
-
} else {
|
|
159
|
-
node = node.parentElement;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return false;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Executes a function within a view transition if supported by the browser.
|
|
168
|
-
*
|
|
169
|
-
* @param {VoidFunction} fn - The function to be executed.
|
|
170
|
-
* @returns {ViewTransition} - The result of the executed function.
|
|
171
|
-
*
|
|
172
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition | MDN: Document.startViewTransition}
|
|
173
|
-
*/
|
|
174
|
-
export const startViewTransitionSafety = (
|
|
175
|
-
fn: VoidFunction,
|
|
176
|
-
params?: { disabled?: boolean },
|
|
177
|
-
) => {
|
|
178
|
-
if (document.startViewTransition && !params?.disabled) {
|
|
179
|
-
return document.startViewTransition(fn);
|
|
180
|
-
}
|
|
181
|
-
fn();
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Вычисляет размер скроллбара
|
|
186
|
-
*/
|
|
187
|
-
export const calcScrollbarWidth = () => {
|
|
188
|
-
const outer = document.createElement('div');
|
|
189
|
-
|
|
190
|
-
outer.style.visibility = 'hidden';
|
|
191
|
-
outer.style.width = '100px';
|
|
192
|
-
outer.style.overflow = 'scroll';
|
|
193
|
-
|
|
194
|
-
document.body.append(outer);
|
|
195
|
-
|
|
196
|
-
const inner = document.createElement('div');
|
|
197
|
-
inner.style.width = '100%';
|
|
198
|
-
|
|
199
|
-
outer.append(inner);
|
|
200
|
-
|
|
201
|
-
const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
|
|
202
|
-
|
|
203
|
-
outer.parentNode?.removeChild(outer);
|
|
204
|
-
|
|
205
|
-
return scrollbarWidth;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Calculates the inner height of an HTML element, accounting for padding.
|
|
210
|
-
*/
|
|
211
|
-
export function getElementInnerHeight(element: HTMLElement) {
|
|
212
|
-
const { clientHeight } = element;
|
|
213
|
-
const { paddingTop, paddingBottom } = getComputedStyle(element);
|
|
214
|
-
return (
|
|
215
|
-
clientHeight -
|
|
216
|
-
Number.parseFloat(paddingTop) -
|
|
217
|
-
Number.parseFloat(paddingBottom)
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Calculates the inner width of an HTML element, accounting for padding.
|
|
223
|
-
*/
|
|
224
|
-
export function getElementInnerWidth(el: HTMLElement) {
|
|
225
|
-
const { clientWidth } = el;
|
|
226
|
-
const { paddingLeft, paddingRight } = getComputedStyle(el);
|
|
227
|
-
return (
|
|
228
|
-
clientWidth -
|
|
229
|
-
Number.parseFloat(paddingLeft) -
|
|
230
|
-
Number.parseFloat(paddingRight)
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export const isPrefersDarkTheme = () =>
|
|
235
|
-
!!globalThis.matchMedia?.('(prefers-color-scheme: dark)')?.matches;
|
|
236
|
-
|
|
237
|
-
export const isPrefersLightTheme = () =>
|
|
238
|
-
!!globalThis.matchMedia?.('(prefers-color-scheme: light)')?.matches;
|
package/src/imports.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { sleep } from './async.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Функция ленивой загрузки модуля, с возможностью вызова доп. попыток
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* fetchLazyModule(() => import("./test.ts"), 3) // начнет загрузку test.ts
|
|
8
|
-
* // Произошла ошибка загрузки test.ts, тогда fetchLazyModule повторно вызовет fn()
|
|
9
|
-
* // Вызывать будет столько раз сколько указано attempts (по умолчанию 3)
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export const fetchLazyModule = async <T>(
|
|
13
|
-
fetchModule: () => Promise<T>,
|
|
14
|
-
attempts = 3,
|
|
15
|
-
delay = 1000,
|
|
16
|
-
): Promise<T> => {
|
|
17
|
-
const attemptsArray = Array.from<typeof fetchModule>({
|
|
18
|
-
length: attempts,
|
|
19
|
-
}).fill(fetchModule);
|
|
20
|
-
|
|
21
|
-
let lastError: null | Error = null;
|
|
22
|
-
|
|
23
|
-
for await (const attempt of attemptsArray) {
|
|
24
|
-
try {
|
|
25
|
-
if (lastError !== null) {
|
|
26
|
-
await sleep(delay);
|
|
27
|
-
}
|
|
28
|
-
return await attempt();
|
|
29
|
-
} catch (error) {
|
|
30
|
-
lastError = error as Error;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
throw lastError;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type PackedAsyncModule<T> = Promise<T | { default: T }>;
|
|
37
|
-
|
|
38
|
-
export const unpackAsyncModule = async <T>(
|
|
39
|
-
maybeModule: T | PackedAsyncModule<T>,
|
|
40
|
-
): Promise<T> => {
|
|
41
|
-
if (maybeModule instanceof Promise) {
|
|
42
|
-
const data = (await maybeModule) as any;
|
|
43
|
-
|
|
44
|
-
if ((data as any).default) {
|
|
45
|
-
return (data as any).default;
|
|
46
|
-
} else {
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return maybeModule;
|
|
52
|
-
};
|
package/src/math.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Maybe } from './utils/types.js';
|
|
2
|
-
|
|
3
|
-
export function degToRad(deg: number) {
|
|
4
|
-
return deg * (Math.PI / 180);
|
|
5
|
-
}
|
|
6
|
-
export function radToDeg(rad: number) {
|
|
7
|
-
return rad * (180 / Math.PI);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Получить процент от числа
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* percentFrom(500, 2000) // 25
|
|
15
|
-
* percentFrom(1000, 2000) // 50
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {
|
|
19
|
-
return ((value ?? 0) / (from ?? 0)) * 100 || 0;
|
|
20
|
-
};
|
package/src/media.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { degToRad } from './math.js';
|
|
2
|
-
|
|
3
|
-
export function blobToBase64(blob: Blob): Promise<string> {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
const reader = new FileReader();
|
|
6
|
-
reader.onloadend = () => resolve(reader.result as string);
|
|
7
|
-
reader.onerror = reject;
|
|
8
|
-
reader.readAsDataURL(blob);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const blobToUrl = (urlOrBlob: string | Blob) =>
|
|
13
|
-
urlOrBlob instanceof Blob ? URL.createObjectURL(urlOrBlob) : urlOrBlob;
|
|
14
|
-
|
|
15
|
-
export const fileToBlob = (file: File) => {
|
|
16
|
-
return new Blob([file], { type: file.type });
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const imageToBlob = (
|
|
20
|
-
imageElement: HTMLImageElement,
|
|
21
|
-
mimeType: string = 'image/png',
|
|
22
|
-
) => {
|
|
23
|
-
const canvas = document.createElement('canvas');
|
|
24
|
-
|
|
25
|
-
canvas.width = imageElement.naturalWidth || 300;
|
|
26
|
-
canvas.height = imageElement.naturalHeight || 300;
|
|
27
|
-
|
|
28
|
-
canvas.getContext('2d')!.drawImage(imageElement, 0, 0);
|
|
29
|
-
|
|
30
|
-
const dataUri = canvas.toDataURL(mimeType, 1);
|
|
31
|
-
const base64data = dataUri.split(',')[1];
|
|
32
|
-
const base64MimeType = dataUri.split(';')[0].slice(5);
|
|
33
|
-
|
|
34
|
-
const bytes = globalThis.atob(base64data);
|
|
35
|
-
const buf = new ArrayBuffer(bytes.length);
|
|
36
|
-
const array = new Uint8Array(buf);
|
|
37
|
-
|
|
38
|
-
for (let index = 0; index < bytes.length; index++) {
|
|
39
|
-
array[index] = bytes.charCodeAt(index);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const blob = new Blob([array], { type: base64MimeType });
|
|
43
|
-
|
|
44
|
-
return blob;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Загружает и отрисовывает изображение с использованием Image
|
|
49
|
-
*
|
|
50
|
-
* @returns {Promise<HTMLImageElement>}
|
|
51
|
-
*/
|
|
52
|
-
export const renderImage = (urlOrBlob: Blob | string) =>
|
|
53
|
-
new Promise<HTMLImageElement>((resolve, reject) => {
|
|
54
|
-
const image = new Image();
|
|
55
|
-
image.src = blobToUrl(urlOrBlob);
|
|
56
|
-
image.onload = () => resolve(image);
|
|
57
|
-
image.onerror = () => reject();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
function cropImageFromCanvas(context: CanvasRenderingContext2D) {
|
|
61
|
-
const canvas = context.canvas;
|
|
62
|
-
let w = canvas.width;
|
|
63
|
-
let h = canvas.height;
|
|
64
|
-
const pix: { x: number[]; y: number[] } = { x: [], y: [] };
|
|
65
|
-
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
66
|
-
let x: number;
|
|
67
|
-
let y: number;
|
|
68
|
-
let index: number;
|
|
69
|
-
|
|
70
|
-
for (y = 0; y < h; y++) {
|
|
71
|
-
for (x = 0; x < w; x++) {
|
|
72
|
-
index = (y * w + x) * 4;
|
|
73
|
-
if (imageData.data[index + 3] > 0) {
|
|
74
|
-
pix.x.push(x);
|
|
75
|
-
pix.y.push(y);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
pix.x.sort((a, b) => a - b);
|
|
80
|
-
pix.y.sort((a, b) => a - b);
|
|
81
|
-
const n = pix.x.length - 1;
|
|
82
|
-
|
|
83
|
-
w = 1 + pix.x[n] - pix.x[0];
|
|
84
|
-
h = 1 + pix.y[n] - pix.y[0];
|
|
85
|
-
const cut = context.getImageData(pix.x[0], pix.y[0], w, h);
|
|
86
|
-
|
|
87
|
-
canvas.width = w;
|
|
88
|
-
canvas.height = h;
|
|
89
|
-
context.putImageData(cut, 0, 0);
|
|
90
|
-
return canvas;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// TODO: ломает iphone с огромными изображениями
|
|
94
|
-
export const rotateImage = (image: HTMLImageElement, angle: number) => {
|
|
95
|
-
const maxSize = Math.max(image.width, image.height);
|
|
96
|
-
const canvas = document.createElement('canvas');
|
|
97
|
-
canvas.width = maxSize;
|
|
98
|
-
canvas.height = maxSize;
|
|
99
|
-
const context = canvas.getContext('2d')!;
|
|
100
|
-
context.save();
|
|
101
|
-
context.translate(canvas.width / 2, canvas.height / 2);
|
|
102
|
-
context.rotate(degToRad(angle));
|
|
103
|
-
context.drawImage(image, -image.width / 2, -image.height / 2);
|
|
104
|
-
context.restore();
|
|
105
|
-
cropImageFromCanvas(context);
|
|
106
|
-
return renderImage(canvas.toDataURL('image/png'));
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
interface DecodedDataUrl {
|
|
110
|
-
mimeType?: string;
|
|
111
|
-
data?: string;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/*
|
|
115
|
-
* Returning object which contains base64 data and mime type of passed data url string.
|
|
116
|
-
* */
|
|
117
|
-
export function decodeDataUrl(url: string): DecodedDataUrl {
|
|
118
|
-
const regex = /^data:(.*);base64,\s?(.*)$/;
|
|
119
|
-
const matches = new RegExp(regex).exec(url);
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
mimeType: matches?.[1],
|
|
123
|
-
data: matches?.[2],
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const isHttpUrl = (url: string): boolean => {
|
|
128
|
-
return url.startsWith('https://') || url.startsWith('http://');
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const isBase64Image = (str: string): boolean => {
|
|
132
|
-
const { mimeType, data } = decodeDataUrl(str);
|
|
133
|
-
return !!(data && mimeType?.startsWith('image/'));
|
|
134
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { makeObservable } from 'mobx';
|
|
2
|
-
import type { AnyObject } from '../utils/types.js';
|
|
3
|
-
|
|
4
|
-
export type ObservableAnnotationsArray = [string, any][];
|
|
5
|
-
|
|
6
|
-
export const applyObservable = (
|
|
7
|
-
context: AnyObject,
|
|
8
|
-
annotationsArray: ObservableAnnotationsArray,
|
|
9
|
-
useDecorators?: boolean,
|
|
10
|
-
) => {
|
|
11
|
-
if (useDecorators) {
|
|
12
|
-
annotationsArray.forEach(([field, annotation]) => {
|
|
13
|
-
annotation(context, field);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
makeObservable(context);
|
|
17
|
-
} else {
|
|
18
|
-
makeObservable(context, Object.fromEntries(annotationsArray));
|
|
19
|
-
}
|
|
20
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createAtom, type IAtom } from 'mobx';
|
|
2
|
-
import type { AnyObject } from '../utils/types.js';
|
|
3
|
-
|
|
4
|
-
export interface IEnhancedAtom<TMeta extends AnyObject = AnyObject>
|
|
5
|
-
extends IAtom {
|
|
6
|
-
meta: TMeta;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates an enhanced atom with meta data
|
|
11
|
-
* And bind `reportChanged` and `reportObserved` method to the atom
|
|
12
|
-
*/
|
|
13
|
-
export const createEnhancedAtom = <TMeta extends AnyObject>(
|
|
14
|
-
name: string,
|
|
15
|
-
onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,
|
|
16
|
-
onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,
|
|
17
|
-
meta?: TMeta,
|
|
18
|
-
): IEnhancedAtom<TMeta> => {
|
|
19
|
-
const atom = createAtom(
|
|
20
|
-
name,
|
|
21
|
-
onBecomeObservedHandler && (() => onBecomeObservedHandler?.(atom)),
|
|
22
|
-
onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler?.(atom)),
|
|
23
|
-
) as IEnhancedAtom<TMeta>;
|
|
24
|
-
atom.meta = meta ?? ({} as TMeta);
|
|
25
|
-
atom.reportChanged = atom.reportChanged.bind(atom);
|
|
26
|
-
atom.reportObserved = atom.reportObserved.bind(atom);
|
|
27
|
-
return atom;
|
|
28
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { reaction } from 'mobx';
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { DeepObservableStruct } from './deep-observable-struct';
|
|
4
|
-
|
|
5
|
-
const dataSet = {
|
|
6
|
-
values: {
|
|
7
|
-
a1: 1,
|
|
8
|
-
a2: 'string',
|
|
9
|
-
a3: 'strign',
|
|
10
|
-
a4: 1,
|
|
11
|
-
a5: { a5_1: 0, a5_2: 0, a5_3: 0, a5_4: 0 },
|
|
12
|
-
a6: {
|
|
13
|
-
a6_1: ['1', '2', '3'],
|
|
14
|
-
a6_2: false,
|
|
15
|
-
a6_3: false,
|
|
16
|
-
a6_4: ['1', '2', '3'],
|
|
17
|
-
a6_5: [],
|
|
18
|
-
},
|
|
19
|
-
a7: {},
|
|
20
|
-
a8: {
|
|
21
|
-
a8_1: { a8_1_1: true, a8_1_2: '' },
|
|
22
|
-
},
|
|
23
|
-
a9: 'string',
|
|
24
|
-
a10: 'string',
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
describe('DeepObservableStruct', () => {
|
|
29
|
-
it('should set data correctly', () => {
|
|
30
|
-
const sourceValue = structuredClone(dataSet);
|
|
31
|
-
const struct = new DeepObservableStruct(sourceValue);
|
|
32
|
-
|
|
33
|
-
expect(struct.data).toEqual(structuredClone(dataSet));
|
|
34
|
-
|
|
35
|
-
const nextData = structuredClone(dataSet);
|
|
36
|
-
nextData.values.a8.a8_1.a8_1_2 = 'new value';
|
|
37
|
-
|
|
38
|
-
struct.set(nextData);
|
|
39
|
-
|
|
40
|
-
expect(struct.data).toEqual(nextData);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should MobX reaction ignores all updates expect real changes', () => {
|
|
44
|
-
const sourceValue = structuredClone(dataSet);
|
|
45
|
-
const struct = new DeepObservableStruct(sourceValue);
|
|
46
|
-
|
|
47
|
-
expect(struct.data).toEqual(structuredClone(dataSet));
|
|
48
|
-
|
|
49
|
-
const reaction1Spy = vi.fn();
|
|
50
|
-
const reaction2Spy = vi.fn();
|
|
51
|
-
const reaction3Spy = vi.fn();
|
|
52
|
-
const reaction4Spy = vi.fn();
|
|
53
|
-
|
|
54
|
-
reaction(() => struct.data.values.a2, reaction1Spy);
|
|
55
|
-
reaction(() => struct.data.values.a8, reaction2Spy);
|
|
56
|
-
reaction(() => struct.data.values.a8.a8_1, reaction3Spy);
|
|
57
|
-
reaction(() => struct.data.values.a8.a8_1.a8_1_2, reaction4Spy);
|
|
58
|
-
|
|
59
|
-
const nextData = structuredClone(dataSet);
|
|
60
|
-
nextData.values.a8.a8_1.a8_1_2 = 'new value';
|
|
61
|
-
|
|
62
|
-
struct.set(nextData);
|
|
63
|
-
|
|
64
|
-
expect(reaction1Spy).not.toBeCalled();
|
|
65
|
-
expect(reaction2Spy).not.toBeCalled();
|
|
66
|
-
expect(reaction3Spy).not.toBeCalled();
|
|
67
|
-
expect(reaction4Spy).toBeCalledTimes(1);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
-
import { typeGuard } from '../type-guard/index.js';
|
|
3
|
-
import type { AnyObject } from '../utils/types.js';
|
|
4
|
-
|
|
5
|
-
export class DeepObservableStruct<TData extends AnyObject> {
|
|
6
|
-
data: TData;
|
|
7
|
-
|
|
8
|
-
constructor(data: TData) {
|
|
9
|
-
this.data = data;
|
|
10
|
-
|
|
11
|
-
makeObservable(this, {
|
|
12
|
-
data: observable.deep,
|
|
13
|
-
set: action,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set(newData: Partial<TData>) {
|
|
18
|
-
type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];
|
|
19
|
-
|
|
20
|
-
const stack: StackItem[] = Object.keys(this.data).map((key) => [
|
|
21
|
-
key,
|
|
22
|
-
this.data,
|
|
23
|
-
newData,
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
let currentIndex = 0;
|
|
27
|
-
let stackLength = stack.length;
|
|
28
|
-
|
|
29
|
-
while (currentIndex < stackLength) {
|
|
30
|
-
const [key, currObservableData, newData] = stack[currentIndex];
|
|
31
|
-
const newValue = newData[key];
|
|
32
|
-
const currValue = currObservableData[key];
|
|
33
|
-
|
|
34
|
-
currentIndex++;
|
|
35
|
-
|
|
36
|
-
if (key in newData) {
|
|
37
|
-
if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {
|
|
38
|
-
const newValueKeys = Object.keys(newValue);
|
|
39
|
-
|
|
40
|
-
Object.keys(currValue).forEach((childKey) => {
|
|
41
|
-
if (!(childKey in newValue)) {
|
|
42
|
-
delete currObservableData[key][childKey];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
newValueKeys.forEach((childKey) => {
|
|
47
|
-
const length = stack.push([
|
|
48
|
-
childKey,
|
|
49
|
-
currObservableData[key],
|
|
50
|
-
newValue,
|
|
51
|
-
]);
|
|
52
|
-
stackLength = length;
|
|
53
|
-
});
|
|
54
|
-
} else if (newValue !== currValue) {
|
|
55
|
-
currObservableData[key] = newValue;
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
delete currObservableData[key];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
Object.keys(newData).forEach((newDataKey) => {
|
|
63
|
-
if (!this.data[newDataKey]) {
|
|
64
|
-
// @ts-expect-error
|
|
65
|
-
this.data[newDataKey] = newData[newDataKey];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { $mobx, type AnnotationMapEntry } from 'mobx';
|
|
2
|
-
import type { AnyObject } from '../utils/types.js';
|
|
3
|
-
|
|
4
|
-
type ObservableObjectAdministration = Parameters<
|
|
5
|
-
Exclude<AnnotationMapEntry, boolean>['make_']
|
|
6
|
-
>[0];
|
|
7
|
-
|
|
8
|
-
export const getMobxAdministration = (
|
|
9
|
-
context: AnyObject,
|
|
10
|
-
): ObservableObjectAdministration => context[$mobx];
|