@unicom-cloud/ui-common 0.1.46 → 0.1.48
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/.virtual/_rolldown/runtime.js +3 -1
- package/animation/Animation.d.ts +2 -1
- package/animation/Animation.js +30 -28
- package/animation/constants.js +3 -1
- package/animation/context.js +3 -1
- package/animation/index.d.ts +4 -0
- package/animation/index.js +5 -3
- package/animation/style/index.js +3 -1
- package/animation/utils.js +3 -1
- package/base/Base.js +3 -1
- package/base/constants.js +3 -1
- package/base/context.js +3 -1
- package/base/index.d.ts +0 -1
- package/base/index.js +3 -1
- package/base/style/index.js +3 -1
- package/base/utils.js +3 -1
- package/border-beam/BorderBeam.d.ts +2 -0
- package/border-beam/BorderBeam.js +37 -31
- package/border-beam/Effect.js +3 -1
- package/border-beam/constants.js +3 -1
- package/border-beam/context.js +3 -1
- package/border-beam/hooks/useBorderSize.js +3 -1
- package/border-beam/hooks/useChildDom.js +10 -8
- package/border-beam/index.d.ts +4 -0
- package/border-beam/index.js +4 -2
- package/border-beam/style/index.js +3 -1
- package/border-beam/utils.js +4 -2
- package/development/Development.d.ts +2 -1
- package/development/Development.js +24 -16
- package/development/constants.js +3 -1
- package/development/context.js +3 -1
- package/development/index.d.ts +4 -1
- package/development/index.js +4 -2
- package/development/style/index.js +3 -1
- package/development/utils.js +3 -1
- package/empty/Empty.d.ts +2 -2
- package/empty/Empty.js +20 -13
- package/empty/constants.js +3 -1
- package/empty/context.js +3 -1
- package/empty/index.d.ts +4 -1
- package/empty/index.js +5 -3
- package/empty/style/index.js +3 -1
- package/empty/utils.js +3 -1
- package/flex/Flex.d.ts +3 -8
- package/flex/Flex.js +45 -42
- package/flex/FlexVertical.d.ts +10 -0
- package/flex/FlexVertical.js +19 -0
- package/flex/constants.js +3 -1
- package/flex/context.js +3 -1
- package/flex/index.d.ts +9 -4
- package/flex/index.js +8 -5
- package/flex/interface.d.ts +14 -7
- package/flex/style/index.js +3 -1
- package/flex/utils.d.ts +7 -3
- package/flex/utils.js +27 -18
- package/grid/Grid.d.ts +10 -0
- package/grid/Grid.js +58 -0
- package/grid/Item.d.ts +10 -0
- package/grid/Item.js +40 -0
- package/grid/constants.js +4 -0
- package/grid/context.d.ts +12 -0
- package/grid/context.js +13 -0
- package/grid/index.d.ts +35 -0
- package/grid/index.js +18 -0
- package/grid/interface.d.ts +89 -0
- package/grid/style/index.css +1 -0
- package/grid/style/index.js +5 -0
- package/grid/utils.d.ts +3 -0
- package/grid/utils.js +26 -0
- package/higher-order/index.js +3 -1
- package/higher-order/with-speech-synthesis/context.js +5 -3
- package/higher-order/with-speech-synthesis/index.d.ts +2 -1
- package/higher-order/with-speech-synthesis/index.js +4 -2
- package/higher-order/with-speech-synthesis/style/index.js +3 -1
- package/higher-order/with-speech-synthesis/withSpeechSynthesis.js +62 -57
- package/hoc/withContext.js +3 -1
- package/hooks/create-deep-compare-effect/index.js +8 -6
- package/hooks/create-update-effect/index.js +3 -1
- package/hooks/create-use-storage-state/index.js +24 -22
- package/hooks/index.d.ts +3 -2
- package/hooks/index.js +7 -4
- package/hooks/use-async-effect/index.js +12 -10
- package/hooks/use-boolean/index.js +3 -1
- package/hooks/use-click-away/index.js +3 -1
- package/hooks/use-computed-state/index.d.ts +1 -1
- package/hooks/use-computed-state/index.js +3 -1
- package/hooks/use-controllable-value/index.js +34 -39
- package/hooks/use-cookie-state/index.js +14 -12
- package/hooks/use-count-down/index.js +9 -7
- package/hooks/use-counter/index.js +16 -14
- package/hooks/use-create/index.js +3 -1
- package/hooks/use-creation/index.js +3 -1
- package/hooks/use-debounce/index.js +3 -1
- package/hooks/use-debounce-effect/index.js +3 -1
- package/hooks/use-debounce-fn/index.js +11 -9
- package/hooks/use-deep-compare-effect/index.js +3 -1
- package/hooks/use-deep-compare-layout-effect/index.js +3 -1
- package/hooks/use-document-visibility/index.js +3 -1
- package/hooks/use-drag/index.js +21 -19
- package/hooks/use-drag-move/index.js +31 -29
- package/hooks/use-drop/index.js +31 -29
- package/hooks/use-effect-event/index.js +3 -1
- package/hooks/use-event/index.js +5 -3
- package/hooks/use-event-emitter/index.js +3 -1
- package/hooks/use-event-listener/index.js +3 -1
- package/hooks/use-event-target/index.js +10 -8
- package/hooks/use-external/index.js +30 -28
- package/hooks/use-favicon/index.js +3 -1
- package/hooks/use-focus-within/index.js +3 -1
- package/hooks/use-force-update/index.js +3 -1
- package/hooks/use-fullscreen/index.js +20 -18
- package/hooks/use-get-state/index.d.ts +1 -1
- package/hooks/use-get-state/index.js +3 -1
- package/hooks/use-history-travel/index.js +23 -21
- package/hooks/use-hover/index.js +3 -1
- package/hooks/use-id/index.js +7 -5
- package/hooks/use-in-viewport/index.js +17 -14
- package/hooks/use-infinite-scroll/index.js +47 -45
- package/hooks/use-intersection-observer/index.js +11 -8
- package/hooks/use-intersection-observers/index.js +28 -21
- package/hooks/use-interval/index.js +9 -7
- package/hooks/use-is-first-render/index.js +3 -1
- package/hooks/use-isomorphic-layout-effect/index.js +3 -1
- package/hooks/use-key-press/index.js +30 -28
- package/hooks/use-keyboard-event/index.js +3 -1
- package/hooks/use-latest/index.js +3 -1
- package/hooks/use-listen-window-resize/index.js +3 -1
- package/hooks/use-local-storage-state/index.js +3 -1
- package/hooks/use-lock-fn/index.js +3 -1
- package/hooks/use-long-press/index.js +3 -1
- package/hooks/use-map/index.js +3 -1
- package/hooks/use-media/index.js +13 -11
- package/hooks/use-memo/index.js +3 -1
- package/hooks/use-memoized-fn/index.js +9 -7
- package/hooks/use-merge-component-props/index.d.ts +14 -0
- package/hooks/use-merge-component-props/index.js +14 -0
- package/hooks/use-merge-value/index.js +13 -11
- package/hooks/use-mobile/index.js +3 -1
- package/hooks/use-mount/index.js +8 -6
- package/hooks/use-mouse/index.js +3 -1
- package/hooks/use-move/index.js +3 -1
- package/hooks/use-mutation-observer/index.js +3 -1
- package/hooks/use-mutation-observers/index.js +28 -21
- package/hooks/use-network/index.js +10 -8
- package/hooks/use-online-status/index.js +3 -1
- package/hooks/use-overflow-hidden/index.js +3 -1
- package/hooks/use-override-ref/index.js +3 -1
- package/hooks/use-pagination/index.js +3 -1
- package/hooks/use-paste-image/index.js +15 -13
- package/hooks/use-persist-callback/index.js +3 -1
- package/hooks/use-prefers-color-scheme-dark/index.js +3 -1
- package/hooks/use-previous/index.d.ts +1 -1
- package/hooks/use-previous/index.js +3 -1
- package/hooks/use-raf-interval/index.js +17 -15
- package/hooks/use-raf-state/index.js +3 -1
- package/hooks/use-raf-timeout/index.js +16 -14
- package/hooks/use-reactive/index.js +26 -24
- package/hooks/use-ref-latest/index.js +3 -1
- package/hooks/use-ref-map/index.d.ts +3 -0
- package/hooks/use-ref-map/index.js +14 -0
- package/hooks/use-refs/index.d.ts +1 -2
- package/hooks/use-refs/index.js +8 -12
- package/hooks/use-request/index.js +3 -1
- package/hooks/use-request/src/Fetch.js +11 -9
- package/hooks/use-request/src/plugins/useAutoRunPlugin.js +3 -1
- package/hooks/use-request/src/plugins/useCachePlugin.js +3 -1
- package/hooks/use-request/src/plugins/useDebouncePlugin.js +14 -12
- package/hooks/use-request/src/plugins/useLoadingDelayPlugin.js +3 -1
- package/hooks/use-request/src/plugins/usePollingPlugin.js +3 -1
- package/hooks/use-request/src/plugins/useRefreshOnWindowFocusPlugin.js +3 -1
- package/hooks/use-request/src/plugins/useRetryPlugin.js +3 -1
- package/hooks/use-request/src/plugins/useThrottlePlugin.js +7 -5
- package/hooks/use-request/src/useRequest.js +3 -1
- package/hooks/use-request/src/useRequestImplement.js +39 -37
- package/hooks/use-request/src/utils/cache.js +3 -1
- package/hooks/use-request/src/utils/cachePromise.js +3 -1
- package/hooks/use-request/src/utils/cacheSubscribe.js +3 -1
- package/hooks/use-request/src/utils/isDocumentVisible.js +3 -1
- package/hooks/use-request/src/utils/isOnline.js +6 -4
- package/hooks/use-request/src/utils/limit.js +3 -1
- package/hooks/use-request/src/utils/subscribeFocus.js +3 -1
- package/hooks/use-request/src/utils/subscribeReVisible.js +3 -1
- package/hooks/use-reset-state/index.js +9 -7
- package/hooks/use-resize-observer/index.js +3 -1
- package/hooks/use-resize-observers/index.js +28 -21
- package/hooks/use-responsive/index.js +3 -1
- package/hooks/use-safe-state/index.d.ts +1 -1
- package/hooks/use-safe-state/index.js +3 -1
- package/hooks/use-scroll/index.js +3 -1
- package/hooks/use-selections/index.js +21 -19
- package/hooks/use-session-storage-state/index.js +3 -1
- package/hooks/use-set/index.js +3 -1
- package/hooks/use-set-state/index.d.ts +7 -2
- package/hooks/use-set-state/index.js +15 -13
- package/hooks/use-size/index.js +22 -20
- package/hooks/use-state-callback/index.d.ts +2 -2
- package/hooks/use-state-callback/index.js +13 -11
- package/hooks/use-state-with-promise/index.js +15 -13
- package/hooks/use-sync-state/index.d.ts +1 -1
- package/hooks/use-sync-state/index.js +10 -8
- package/hooks/use-text-selection/index.js +3 -1
- package/hooks/use-theme/index.js +3 -1
- package/hooks/use-throttle/index.js +3 -1
- package/hooks/use-throttle-effect/index.js +3 -1
- package/hooks/use-throttle-fn/index.js +11 -9
- package/hooks/use-throttle-fn-with-raf/index.js +14 -12
- package/hooks/use-timeout/index.js +9 -7
- package/hooks/use-title/index.js +3 -1
- package/hooks/use-toggle/index.js +10 -8
- package/hooks/use-tracked-effect/index.js +3 -1
- package/hooks/use-unmount/index.js +10 -8
- package/hooks/use-unmounted-ref/index.js +3 -1
- package/hooks/use-update/index.js +13 -11
- package/hooks/use-update-effect/index.js +3 -1
- package/hooks/use-update-layout-effect/index.js +3 -1
- package/hooks/use-url-state/index.js +11 -9
- package/hooks/use-virtual-list/index.js +35 -33
- package/hooks/use-watch/index.d.ts +1 -1
- package/hooks/use-watch/index.js +9 -7
- package/hooks/use-web-socket/index.js +3 -1
- package/hooks/use-why-did-you-update/index.js +3 -1
- package/hooks/use-window-size/index.js +17 -15
- package/hooks/utils/createEffectWithTarget.js +3 -1
- package/hooks/utils/depsAreSame.js +3 -1
- package/hooks/utils/depsEqual.js +4 -2
- package/hooks/utils/domTarget.js +7 -5
- package/hooks/utils/getDocumentOrShadow.js +3 -1
- package/hooks/utils/index.js +3 -1
- package/hooks/utils/isAppleDevice.js +3 -1
- package/hooks/utils/isBrowser.js +3 -1
- package/hooks/utils/isDev.js +3 -1
- package/hooks/utils/rect.js +3 -1
- package/hooks/utils/useDeepCompareWithTarget.js +3 -1
- package/hooks/utils/useEffectWithTarget.js +3 -1
- package/hooks/utils/useIsomorphicLayoutEffectWithTarget.js +3 -1
- package/hooks/utils/useLayoutEffectWithTarget.js +3 -1
- package/icons/file/File.d.ts +2 -1
- package/icons/file/File.js +39 -34
- package/icons/file/context.js +5 -3
- package/icons/file/index.d.ts +4 -1
- package/icons/file/index.js +4 -2
- package/icons/file/style/index.js +3 -1
- package/index.d.ts +3 -3
- package/index.js +572 -652
- package/morphicons/adapters/canvas.d.ts +43 -0
- package/morphicons/adapters/index.d.ts +3 -0
- package/morphicons/adapters/mask.d.ts +42 -0
- package/morphicons/adapters/svg.d.ts +8 -0
- package/morphicons/core/interpolate.d.ts +6 -0
- package/morphicons/core/interpolate.js +29 -0
- package/morphicons/core/normalize.d.ts +16 -0
- package/morphicons/core/normalize.js +166 -0
- package/morphicons/core/parse.d.ts +27 -0
- package/morphicons/core/parse.js +131 -0
- package/morphicons/core/plan.d.ts +64 -0
- package/morphicons/core/plan.js +198 -0
- package/morphicons/core/resample.d.ts +18 -0
- package/morphicons/core/resample.js +132 -0
- package/morphicons/core/serialize.d.ts +7 -0
- package/morphicons/core/serialize.js +32 -0
- package/morphicons/core/spring.d.ts +30 -0
- package/morphicons/core/spring.js +39 -0
- package/morphicons/core/types.d.ts +27 -0
- package/morphicons/dom/controller.d.ts +53 -0
- package/morphicons/dom/index.d.ts +46 -0
- package/morphicons/dom/index.js +111 -0
- package/morphicons/element/index.d.ts +39 -0
- package/morphicons/index.d.ts +8 -0
- package/morphicons/index.js +12 -0
- package/morphicons/react/index.d.ts +36 -0
- package/morphicons/react/index.js +104 -0
- package/package.json +1 -1
- package/progress/Progress.js +24 -22
- package/progress/constants.js +3 -1
- package/progress/context.js +4 -0
- package/progress/index.js +3 -1
- package/progress/style/index.js +3 -1
- package/progress/utils.js +3 -1
- package/resize-observer/Collection.js +3 -1
- package/resize-observer/ResizeObserver.d.ts +2 -0
- package/resize-observer/ResizeObserver.js +23 -16
- package/resize-observer/SingleObserver.js +35 -33
- package/resize-observer/constants.js +3 -1
- package/resize-observer/context.js +3 -1
- package/resize-observer/index.d.ts +4 -1
- package/resize-observer/index.js +4 -2
- package/resize-observer/observerUtil.js +3 -1
- package/resize-observer/style/index.js +3 -1
- package/resize-observer/utils.js +3 -1
- package/space/Space.d.ts +3 -8
- package/space/Space.js +60 -51
- package/space/SpaceVertical.d.ts +10 -0
- package/space/SpaceVertical.js +16 -0
- package/space/constants.js +3 -1
- package/space/context.js +3 -1
- package/space/index.d.ts +7 -2
- package/space/index.js +6 -3
- package/space/interface.d.ts +3 -25
- package/space/style/index.js +3 -1
- package/space/utils.js +3 -1
- package/style/global.less +31 -1
- package/style.css +1 -1
- package/suspense-fallback-test/SuspenseFallbackTest.d.ts +2 -0
- package/suspense-fallback-test/SuspenseFallbackTest.js +11 -4
- package/suspense-fallback-test/constants.js +3 -1
- package/suspense-fallback-test/context.js +3 -1
- package/suspense-fallback-test/index.d.ts +4 -1
- package/suspense-fallback-test/index.js +4 -2
- package/suspense-fallback-test/style/index.js +3 -1
- package/suspense-fallback-test/utils.js +3 -1
- package/test.js +3 -1
- package/timer/Timer.d.ts +2 -0
- package/timer/Timer.js +23 -17
- package/timer/constants.js +3 -1
- package/timer/context.js +3 -1
- package/timer/index.d.ts +4 -1
- package/timer/index.js +4 -2
- package/timer/style/index.js +3 -1
- package/timer/utils.js +3 -1
- package/transition/Transition.d.ts +2 -1
- package/transition/Transition.js +77 -67
- package/transition/TransitionCSS.d.ts +2 -1
- package/transition/TransitionCSS.js +28 -26
- package/transition/TransitionGroup.d.ts +2 -1
- package/transition/TransitionGroup.js +38 -36
- package/transition/TransitionStyle.d.ts +2 -1
- package/transition/TransitionStyle.js +22 -20
- package/transition/constants.js +3 -1
- package/transition/context.js +3 -1
- package/transition/index.d.ts +21 -13
- package/transition/index.js +8 -6
- package/transition/style/index.js +3 -1
- package/transition/utils.js +45 -43
- package/utils/callOrReturn.js +3 -1
- package/utils/callbackOriginRef.d.ts +1 -2
- package/utils/callbackOriginRef.js +3 -1
- package/utils/caseName.d.ts +1 -1
- package/utils/caseName.js +5 -3
- package/utils/className.d.ts +1 -1
- package/utils/className.js +5 -3
- package/utils/confetti.d.ts +20 -0
- package/utils/confetti.js +31 -0
- package/utils/constants.js +3 -1
- package/utils/copy.js +3 -1
- package/utils/css.js +3 -1
- package/utils/date.js +3 -1
- package/utils/dayjs.js +3 -1
- package/utils/document.js +3 -1
- package/utils/dom.js +38 -35
- package/utils/emitter.js +3 -1
- package/utils/file.js +3 -1
- package/utils/fileRead.js +3 -1
- package/utils/fileToDataURL.js +3 -1
- package/utils/fillNBSP.js +4 -2
- package/utils/getCompatProp.d.ts +9 -0
- package/utils/getCompatProp.js +12 -0
- package/utils/getElement.js +16 -14
- package/utils/getHighlightText.js +20 -17
- package/utils/getHotkeyHandler.js +13 -11
- package/utils/getPrefixCls.d.ts +2 -0
- package/utils/getPrefixCls.js +11 -0
- package/utils/getScrollBarHeight.js +3 -1
- package/utils/getScrollBarSize.js +9 -7
- package/utils/getScrollBarWidth.js +3 -1
- package/utils/getScrollParent.js +3 -1
- package/utils/getStringLength.js +3 -1
- package/utils/getURLSearchByParams.d.ts +2 -0
- package/utils/getURLSearchByParams.js +10 -0
- package/utils/include.js +3 -1
- package/utils/index.d.ts +7 -0
- package/utils/index.js +272 -354
- package/utils/initAllLineClamp.js +3 -1
- package/utils/intersectionObserver.js +17 -15
- package/utils/is.d.ts +2 -6
- package/utils/is.js +29 -139
- package/utils/keyboardCode.js +3 -1
- package/utils/lodash.d.ts +2 -1
- package/utils/lodash.js +55 -52
- package/utils/math.js +3 -1
- package/utils/mergeProps.d.ts +3 -1
- package/utils/mergeProps.js +15 -8
- package/utils/mergedToString.js +14 -11
- package/utils/migrateLegacyProps.d.ts +14 -0
- package/utils/migrateLegacyProps.js +19 -0
- package/utils/mutationObserver.js +15 -13
- package/utils/names.d.ts +24 -20
- package/utils/names.js +43 -35
- package/utils/object.js +3 -1
- package/utils/omit.js +3 -1
- package/utils/pad.js +3 -1
- package/utils/pick.d.ts +7 -2
- package/utils/pick.js +11 -9
- package/utils/pinyin.js +3 -1
- package/utils/react19Adapter.js +3 -1
- package/utils/reactNode.js +11 -9
- package/utils/ref.js +23 -19
- package/utils/resizeObserver.js +7 -5
- package/utils/saveAs.d.ts +1 -1
- package/utils/saveAs.js +5 -3
- package/utils/screenfull.js +3 -1
- package/utils/scrollIntoViewIfNeeded.js +3 -1
- package/utils/scrollTo.js +7 -5
- package/utils/setCreateRoot.js +14 -11
- package/utils/setDarkTheme.js +16 -14
- package/utils/setDir.js +7 -5
- package/utils/setPrimaryColor.js +4 -2
- package/utils/setTheme.js +14 -12
- package/utils/string.js +3 -1
- package/utils/style.js +3 -1
- package/utils/tinycolor.js +3 -1
- package/utils/toArray.js +7 -5
- package/utils/tree.js +3 -1
- package/utils/tunnel.d.ts +6 -5
- package/utils/tunnel.js +22 -20
- package/utils/tween.js +3 -1
- package/utils/uuid.js +3 -1
- package/utils/validate.js +3 -1
- package/utils/warning.js +3 -1
- package/version/index.d.ts +0 -1
- package/version/index.js +10 -8
- package/hooks/use-merge-props/index.d.ts +0 -5
- package/hooks/use-merge-props/index.js +0 -10
- package/typewriter/Typewriter.d.ts +0 -8
- package/typewriter/Typewriter.js +0 -69
- package/typewriter/constants.js +0 -2
- package/typewriter/context.d.ts +0 -3
- package/typewriter/context.js +0 -10
- package/typewriter/index.d.ts +0 -15
- package/typewriter/index.js +0 -13
- package/typewriter/interface.d.ts +0 -17
- package/typewriter/style/index.css +0 -1
- package/typewriter/style/index.js +0 -3
- package/typewriter/utils.js +0 -2
- /package/{typewriter → grid}/constants.d.ts +0 -0
- /package/{typewriter → grid}/hooks/index.d.ts +0 -0
- /package/{typewriter → grid}/style/index.d.ts +0 -0
- /package/{typewriter/utils.d.ts → progress/context.d.ts} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PathEl } from '../dom/index';
|
|
2
|
+
/** The 2D context surface the target drives — structural, so a real
|
|
3
|
+
* CanvasRenderingContext2D, an OffscreenCanvasRenderingContext2D or a test
|
|
4
|
+
* fake all satisfy it. Only what canvasTarget actually touches. */
|
|
5
|
+
export interface Canvas2DContext {
|
|
6
|
+
canvas: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
lineWidth: number;
|
|
11
|
+
lineCap: string;
|
|
12
|
+
lineJoin: string;
|
|
13
|
+
strokeStyle: string | object;
|
|
14
|
+
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
15
|
+
clearRect(x: number, y: number, w: number, h: number): void;
|
|
16
|
+
stroke(path: object): void;
|
|
17
|
+
}
|
|
18
|
+
/** Anything that can hand out a 2D context (an HTMLCanvasElement, an
|
|
19
|
+
* OffscreenCanvas, or a fake in tests). */
|
|
20
|
+
export interface CanvasSurface {
|
|
21
|
+
getContext(contextId: '2d'): Canvas2DContext | null;
|
|
22
|
+
}
|
|
23
|
+
export interface CanvasTargetOptions {
|
|
24
|
+
/** Grid the icon's coordinates live on (Lucide/Iconify default: "0 0 24 24").
|
|
25
|
+
* Used to map the geometry onto the backing store. */
|
|
26
|
+
viewBox?: string;
|
|
27
|
+
/** Stroke width in grid units (Lucide's default is 2). */
|
|
28
|
+
strokeWidth?: number;
|
|
29
|
+
/** Stroke color. Defaults to the canvas' computed CSS color when it is a
|
|
30
|
+
* styled element; otherwise the context's current `strokeStyle` stands. */
|
|
31
|
+
color?: string;
|
|
32
|
+
/** Clear the canvas before each frame. Turn off for manual compositing or
|
|
33
|
+
* trails — every frame then draws on top of the last. Default true. */
|
|
34
|
+
clear?: boolean;
|
|
35
|
+
/** Called after every drawn frame — the texture consumer's dirty signal
|
|
36
|
+
* (e.g. re-upload the canvas with `texImage2D`, or blit it into a scene). */
|
|
37
|
+
onWrite?: () => void;
|
|
38
|
+
}
|
|
39
|
+
/** Adapts a canvas (or its 2D context) into a `PathEl` whose writes stroke
|
|
40
|
+
* the morph's geometry onto the canvas, so
|
|
41
|
+
* `createMorph(canvasTarget(canvas), icon)` animates pixels instead of an
|
|
42
|
+
* inline `<svg><path>`. */
|
|
43
|
+
export declare function canvasTarget(surface: CanvasSurface | Canvas2DContext, opts?: CanvasTargetOptions): PathEl;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PathEl } from '../dom/index';
|
|
2
|
+
/** The subset of an element's inline style the mask target writes — structural
|
|
3
|
+
* so a real HTMLElement's `.style` satisfies it (and a test fake supplies
|
|
4
|
+
* just these). */
|
|
5
|
+
export interface MaskStyle {
|
|
6
|
+
maskImage: string;
|
|
7
|
+
webkitMaskImage: string;
|
|
8
|
+
backgroundColor: string;
|
|
9
|
+
}
|
|
10
|
+
/** An element the mask target can drive (an HTMLElement, or a fake in tests). */
|
|
11
|
+
export interface MaskEl {
|
|
12
|
+
style: MaskStyle;
|
|
13
|
+
}
|
|
14
|
+
export interface MaskTargetOptions {
|
|
15
|
+
/** Stroke width of the mask geometry (Lucide's default is 2). */
|
|
16
|
+
strokeWidth?: number;
|
|
17
|
+
/** Grid the icon's coordinates live on (Lucide/Iconify default: "0 0 24 24").
|
|
18
|
+
* Used to map the geometry onto the element's box. */
|
|
19
|
+
viewBox?: string;
|
|
20
|
+
/** Set `background-color: currentColor` on first setup so the element shows
|
|
21
|
+
* through the mask in the current text color, standalone (no icon class).
|
|
22
|
+
* Turn off to keep an existing paint (e.g. a `bg-*` utility). Default true. */
|
|
23
|
+
paint?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** What `maskTarget` returns: the driver's write contract plus a `dispose`
|
|
26
|
+
* that removes the hidden mask node (call it after `morph.destroy()` when
|
|
27
|
+
* the element unmounts). */
|
|
28
|
+
export interface MaskPathEl extends PathEl {
|
|
29
|
+
dispose(): void;
|
|
30
|
+
}
|
|
31
|
+
/** Adapts an element into a `PathEl` whose writes drive a referenced SVG
|
|
32
|
+
* mask, so `createMorph(maskTarget(el), icon)` animates a mask-styled
|
|
33
|
+
* element instead of an inline `<svg><path>`.
|
|
34
|
+
*
|
|
35
|
+
* DOUBLE BUFFER, on purpose: WebKit does not reliably repaint a masked
|
|
36
|
+
* element when the CONTENT of its referenced `<mask>` mutates — a lone mask
|
|
37
|
+
* whose inner path `d` changes per frame renders frozen in Safari until the
|
|
38
|
+
* flight ends. So the target keeps TWO masks and every `d` write lands on
|
|
39
|
+
* the back buffer and re-points `mask-image` at it: the property VALUE flips
|
|
40
|
+
* (`url(#a)` ↔ `url(#b)`) each frame, which forces reference re-resolution
|
|
41
|
+
* in every engine. Chromium/Gecko pay nothing extra for it. */
|
|
42
|
+
export declare function maskTarget(el: MaskEl, opts?: MaskTargetOptions): MaskPathEl;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IconInput } from '../core/types';
|
|
2
|
+
/** SVG markup → an IconInput the pipeline can lower. Strips non-rendered
|
|
3
|
+
* containers, rejects what can't be honestly morphed (a fill-drawn icon with
|
|
4
|
+
* no stroke, a transform, an unsupported element), and re-grids onto 24 via
|
|
5
|
+
* the viewBox when one is present — so an off-grid collection lands on the
|
|
6
|
+
* shared grid automatically. Returns a `d` (when a viewBox forced a fit) or
|
|
7
|
+
* an IconNode. */
|
|
8
|
+
export declare function svgToIcon(markup: string): IconInput;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MorphPlan } from './plan';
|
|
2
|
+
/** Preallocated output buffers for a plan (zero allocation per frame). */
|
|
3
|
+
export declare function allocOutputs(plan: MorphPlan): Float64Array[];
|
|
4
|
+
export declare function interpPolar(plan: MorphPlan, t: number, out: Float64Array[]): void;
|
|
5
|
+
/** Raw coordinate lerp (same correspondence, no decomposition). */
|
|
6
|
+
export declare function interpLinear(plan: MorphPlan, t: number, out: Float64Array[]): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* 潘启宝 2026-09-11 17:27:45 星期五 山东省济南市 */
|
|
2
|
+
/* 世界因你而美丽 */
|
|
3
|
+
//#region components/common/morphicons/core/interpolate.ts
|
|
4
|
+
function e(e) {
|
|
5
|
+
return e.items.map(() => new Float64Array(2 * e.n));
|
|
6
|
+
}
|
|
7
|
+
function t(e, t, n) {
|
|
8
|
+
for (let r = 0; r < e.items.length; r++) {
|
|
9
|
+
let i = e.items[r], a = n[r], o = e.n, s = Math.exp(i.lnSigma * t), c = i.theta * t, l = Math.cos(c) * s, u = Math.sin(c) * s, d, f;
|
|
10
|
+
if (i.block) {
|
|
11
|
+
let [e, n] = i.block.off, [r, a] = i.block.drift;
|
|
12
|
+
d = i.ca[0] + r * t + (e * l - n * u - e), f = i.ca[1] + a * t + (e * u + n * l - n);
|
|
13
|
+
} else d = i.ca[0] + (i.cb[0] - i.ca[0]) * t, f = i.ca[1] + (i.cb[1] - i.ca[1]) * t;
|
|
14
|
+
for (let e = 0; e < o; e++) {
|
|
15
|
+
let n = i.aC[2 * e] + (i.bT[2 * e] - i.aC[2 * e]) * t, r = i.aC[2 * e + 1] + (i.bT[2 * e + 1] - i.aC[2 * e + 1]) * t;
|
|
16
|
+
a[2 * e] = d + n * l - r * u, a[2 * e + 1] = f + n * u + r * l;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function n(e, t, n) {
|
|
21
|
+
for (let r = 0; r < e.items.length; r++) {
|
|
22
|
+
let i = e.items[r], a = n[r], o = e.n;
|
|
23
|
+
for (let e = 0; e < o; e++) a[2 * e] = i.a[2 * e] + (i.bO[2 * e] - i.a[2 * e]) * t, a[2 * e + 1] = i.a[2 * e + 1] + (i.bO[2 * e + 1] - i.a[2 * e + 1]) * t;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { e as allocOutputs, n as interpLinear, t as interpPolar };
|
|
28
|
+
/* 欲穷千里目,更上一层楼 */
|
|
29
|
+
/* 独立思考,明辨是非 */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CubicPath, IconInput } from './types';
|
|
2
|
+
/** Control-point offset for a quarter circle: (4/3)·tan(π/8) ≈ 0.5523. */
|
|
3
|
+
export declare const KAPPA: number;
|
|
4
|
+
/** Icon (IconNode or `d` string) → list of cubic subpaths. */
|
|
5
|
+
export declare function iconToCubics(input: IconInput): CubicPath[];
|
|
6
|
+
/** A source viewBox: `24`, `"0 0 20 20"` or `[minX, minY, w, h]`. */
|
|
7
|
+
export type ViewBox = number | string | readonly [number, number, number, number];
|
|
8
|
+
/** Re-grids an icon drawn on `viewBox` onto the shared `grid` (24 by default),
|
|
9
|
+
* centred and preserving aspect ratio — the SVG `xMidYMid meet` rule.
|
|
10
|
+
*
|
|
11
|
+
* Both endpoints of a morph must live on the same coordinate space. Lucide and
|
|
12
|
+
* Tabler already draw on 24×24; packs on 20 (Heroicons solid) or 32 (Carbon)
|
|
13
|
+
* do not, and mixing them unfitted makes Procrustes read the scale/offset gap
|
|
14
|
+
* as rotation. Apply once at module scope (not per render) and pass the
|
|
15
|
+
* resulting `d` anywhere an icon is accepted. */
|
|
16
|
+
export declare function fitIcon(input: IconInput, viewBox: ViewBox, grid?: number): string;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/* 潘启宝 2026-09-11 17:27:45 星期五 山东省济南市 */
|
|
2
|
+
/* 世界因你而美丽 */
|
|
3
|
+
import { parsePath as e } from "./parse.js";
|
|
4
|
+
import { cubicsToPathD as t } from "./serialize.js";
|
|
5
|
+
//#region components/common/morphicons/core/normalize.ts
|
|
6
|
+
var n = 4 / 3 * Math.tan(Math.PI / 8), r = 2 * Math.PI;
|
|
7
|
+
function i(e, t) {
|
|
8
|
+
let n = [e, t], i = e, a = t, o = (e, t, r, o, s, c) => {
|
|
9
|
+
n.push(e, t, r, o, s, c), i = s, a = c;
|
|
10
|
+
}, s = (e, t) => {
|
|
11
|
+
Math.abs(e - i) < 1e-12 && Math.abs(t - a) < 1e-12 || o(i + (e - i) / 3, a + (t - a) / 3, i + 2 * (e - i) / 3, a + 2 * (t - a) / 3, e, t);
|
|
12
|
+
};
|
|
13
|
+
return [
|
|
14
|
+
o,
|
|
15
|
+
s,
|
|
16
|
+
(e, t, n, r) => {
|
|
17
|
+
o(i + 2 / 3 * (e - i), a + 2 / 3 * (t - a), n + 2 / 3 * (e - n), r + 2 / 3 * (t - r), n, r);
|
|
18
|
+
},
|
|
19
|
+
(e, t, n, c, l, u, d) => {
|
|
20
|
+
let f = i, p = a;
|
|
21
|
+
if (Math.abs(u - f) < 1e-12 && Math.abs(d - p) < 1e-12) return;
|
|
22
|
+
let m = Math.abs(e), h = Math.abs(t);
|
|
23
|
+
if (m < 1e-12 || h < 1e-12) {
|
|
24
|
+
s(u, d);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let g = n * Math.PI / 180, _ = Math.cos(g), v = Math.sin(g), y = (f - u) / 2, b = (p - d) / 2, x = _ * y + v * b, S = -v * y + _ * b, C = x * x / (m * m) + S * S / (h * h);
|
|
28
|
+
if (C > 1) {
|
|
29
|
+
let e = Math.sqrt(C);
|
|
30
|
+
m *= e, h *= e;
|
|
31
|
+
}
|
|
32
|
+
let w = m * m, T = h * h, E = x * x, D = S * S, O = (w * T - w * D - T * E) / (w * D + T * E);
|
|
33
|
+
O < 0 && (O = 0);
|
|
34
|
+
let k = (c === l ? -1 : 1) * Math.sqrt(O), A = k * m * S / h, j = -k * h * x / m, M = _ * A - v * j + (f + u) / 2, N = v * A + _ * j + (p + d) / 2, P = Math.atan2((S - j) / h, (x - A) / m), F = Math.atan2((-S - j) / h, (-x - A) / m) - P;
|
|
35
|
+
l === 0 && F > 0 ? F -= r : l === 1 && F < 0 && (F += r);
|
|
36
|
+
let I = Math.max(1, Math.ceil(Math.abs(F) / (Math.PI / 2) - 1e-9)), L = F / I, R = 4 / 3 * Math.tan(L / 4), z = (e) => M + m * Math.cos(e) * _ - h * Math.sin(e) * v, B = (e) => N + m * Math.cos(e) * v + h * Math.sin(e) * _, V = (e) => -m * Math.sin(e) * _ - h * Math.cos(e) * v, H = (e) => -m * Math.sin(e) * v + h * Math.cos(e) * _, U = P, W = f, G = p;
|
|
37
|
+
for (let e = 1; e <= I; e++) {
|
|
38
|
+
let t = P + L * e, n = e === I ? u : z(t), r = e === I ? d : B(t);
|
|
39
|
+
o(W + R * V(U), G + R * H(U), n - R * V(t), r - R * H(t), n, r), U = t, W = n, G = r;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
(e) => (e && s(n[0], n[1]), n.length < 8 ? null : {
|
|
43
|
+
pts: Float64Array.from(n),
|
|
44
|
+
closed: e
|
|
45
|
+
})
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
function a(e) {
|
|
49
|
+
let [t, n, r, a, o] = i(e.x0, e.y0);
|
|
50
|
+
for (let i of e.segs) switch (i[0]) {
|
|
51
|
+
case "L":
|
|
52
|
+
n(i[1], i[2]);
|
|
53
|
+
break;
|
|
54
|
+
case "C":
|
|
55
|
+
t(i[1], i[2], i[3], i[4], i[5], i[6]);
|
|
56
|
+
break;
|
|
57
|
+
case "Q":
|
|
58
|
+
r(i[1], i[2], i[3], i[4]);
|
|
59
|
+
break;
|
|
60
|
+
case "A": a(i[1], i[2], i[3], i[4], i[5], i[6], i[7]);
|
|
61
|
+
}
|
|
62
|
+
return o(e.closed);
|
|
63
|
+
}
|
|
64
|
+
function o(e, t, n = 0) {
|
|
65
|
+
let r = e[t];
|
|
66
|
+
if (r === void 0) return n;
|
|
67
|
+
let i = typeof r == "number" ? r : Number(r);
|
|
68
|
+
return Number.isFinite(i) ? i : n;
|
|
69
|
+
}
|
|
70
|
+
function s(e) {
|
|
71
|
+
let t = String(e ?? "").trim();
|
|
72
|
+
if (!t) return [];
|
|
73
|
+
let n = t.split(/[\s,]+/).map(Number);
|
|
74
|
+
if (n.some((e) => !Number.isFinite(e))) throw Error(`morphicons: invalid points: "${t}"`);
|
|
75
|
+
return n;
|
|
76
|
+
}
|
|
77
|
+
function c(e, t) {
|
|
78
|
+
if (e.length < 4) return null;
|
|
79
|
+
let [, n, , , r] = i(e[0], e[1]);
|
|
80
|
+
for (let t = 2; t + 1 < e.length; t += 2) n(e[t], e[t + 1]);
|
|
81
|
+
return r(t);
|
|
82
|
+
}
|
|
83
|
+
function l(e, t, r, a) {
|
|
84
|
+
if (r < 1e-12 || a < 1e-12) return null;
|
|
85
|
+
let o = n * r, s = n * a, c = e + r, l = e - r, u = t + a, d = t - a, [f, , , , p] = i(c, t);
|
|
86
|
+
return f(c, t + s, e + o, u, e, u), f(e - o, u, l, t + s, l, t), f(l, t - s, e - o, d, e, d), f(e + o, d, c, t - s, c, t), p(!0);
|
|
87
|
+
}
|
|
88
|
+
function u(e) {
|
|
89
|
+
let t = o(e, "x"), r = o(e, "y"), a = o(e, "width"), s = o(e, "height");
|
|
90
|
+
if (a < 1e-12 || s < 1e-12) return null;
|
|
91
|
+
let l = o(e, "rx", NaN), u = o(e, "ry", NaN);
|
|
92
|
+
if (Number.isNaN(l) && (l = Number.isNaN(u) ? 0 : u), Number.isNaN(u) && (u = l), l = Math.min(Math.max(l, 0), a / 2), u = Math.min(Math.max(u, 0), s / 2), l < 1e-12 || u < 1e-12) return c([
|
|
93
|
+
t,
|
|
94
|
+
r,
|
|
95
|
+
t + a,
|
|
96
|
+
r,
|
|
97
|
+
t + a,
|
|
98
|
+
r + s,
|
|
99
|
+
t,
|
|
100
|
+
r + s
|
|
101
|
+
], !0);
|
|
102
|
+
let d = t + l, f = t + a - l, p = t + a, m = r + u, h = r + s - u, g = r + s, _ = n * l, v = n * u, [y, b, , , x] = i(d, r);
|
|
103
|
+
return b(f, r), y(f + _, r, p, m - v, p, m), b(p, h), y(p, h + v, f + _, g, f, g), b(d, g), y(d - _, g, t, h + v, t, h), b(t, m), y(t, m - v, d - _, r, d, r), x(!0);
|
|
104
|
+
}
|
|
105
|
+
function d(t) {
|
|
106
|
+
let n = [], r = (e) => {
|
|
107
|
+
e && n.push(e);
|
|
108
|
+
};
|
|
109
|
+
if (typeof t == "string") {
|
|
110
|
+
for (let n of e(t)) r(a(n));
|
|
111
|
+
return n;
|
|
112
|
+
}
|
|
113
|
+
for (let [n, d] of t) switch (n) {
|
|
114
|
+
case "path":
|
|
115
|
+
for (let t of e(String(d.d ?? ""))) r(a(t));
|
|
116
|
+
break;
|
|
117
|
+
case "line": {
|
|
118
|
+
let [, e, , , t] = i(o(d, "x1"), o(d, "y1"));
|
|
119
|
+
e(o(d, "x2"), o(d, "y2")), r(t(!1));
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "circle": {
|
|
123
|
+
let e = o(d, "r");
|
|
124
|
+
r(l(o(d, "cx"), o(d, "cy"), e, e));
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case "ellipse":
|
|
128
|
+
r(l(o(d, "cx"), o(d, "cy"), o(d, "rx"), o(d, "ry")));
|
|
129
|
+
break;
|
|
130
|
+
case "rect":
|
|
131
|
+
r(u(d));
|
|
132
|
+
break;
|
|
133
|
+
case "polyline":
|
|
134
|
+
r(c(s(d.points), !1));
|
|
135
|
+
break;
|
|
136
|
+
case "polygon":
|
|
137
|
+
r(c(s(d.points), !0));
|
|
138
|
+
break;
|
|
139
|
+
default: throw Error(`morphicons: unsupported tag <${n}>`);
|
|
140
|
+
}
|
|
141
|
+
return n;
|
|
142
|
+
}
|
|
143
|
+
function f(e) {
|
|
144
|
+
let t = typeof e == "number" ? [
|
|
145
|
+
0,
|
|
146
|
+
0,
|
|
147
|
+
e,
|
|
148
|
+
e
|
|
149
|
+
] : typeof e == "string" ? e.trim().split(/[\s,]+/).map(Number) : e, [n, r, i, a] = t;
|
|
150
|
+
if (t.length !== 4 || !(i > 0) || !(a > 0) || !Number.isFinite(n) || !Number.isFinite(r)) throw Error(`morphicons: invalid viewBox "${String(e)}"`);
|
|
151
|
+
return [
|
|
152
|
+
n,
|
|
153
|
+
r,
|
|
154
|
+
i,
|
|
155
|
+
a
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
function p(e, n, r = 24) {
|
|
159
|
+
let [i, a, o, s] = f(n), c = Math.min(r / o, r / s), l = (r - o * c) / 2 - i * c, u = (r - s * c) / 2 - a * c, p = d(e);
|
|
160
|
+
for (let { pts: e } of p) for (let t = 0; t < e.length; t += 2) e[t] = e[t] * c + l, e[t + 1] = e[t + 1] * c + u;
|
|
161
|
+
return t(p);
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
export { n as KAPPA, p as fitIcon, d as iconToCubics };
|
|
165
|
+
/* 欲穷千里目,更上一层楼 */
|
|
166
|
+
/* 独立思考,明辨是非 */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Raw absolute segment (shorthands already resolved), as a labeled tuple —
|
|
2
|
+
* compact in the bundle (no object keys the minifier can't mangle). */
|
|
3
|
+
export type RawSeg = readonly ['L', x: number, y: number] | readonly [
|
|
4
|
+
'C',
|
|
5
|
+
x1: number,
|
|
6
|
+
y1: number,
|
|
7
|
+
x2: number,
|
|
8
|
+
y2: number,
|
|
9
|
+
x: number,
|
|
10
|
+
y: number
|
|
11
|
+
] | readonly ['Q', x1: number, y1: number, x: number, y: number] | readonly [
|
|
12
|
+
'A',
|
|
13
|
+
rx: number,
|
|
14
|
+
ry: number,
|
|
15
|
+
rotDeg: number,
|
|
16
|
+
large: 0 | 1,
|
|
17
|
+
sweep: 0 | 1,
|
|
18
|
+
x: number,
|
|
19
|
+
y: number
|
|
20
|
+
];
|
|
21
|
+
export interface RawSubpath {
|
|
22
|
+
x0: number;
|
|
23
|
+
y0: number;
|
|
24
|
+
segs: RawSeg[];
|
|
25
|
+
closed: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function parsePath(d: string): RawSubpath[];
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
function e(e) {
|
|
2
|
+
let t = [], n = e.length, r = 0, i = 0, a = 0, o = 0, s = 0, c = null, l = "", u = 0, d = 0, f = "", p = !1, m = (e) => {
|
|
3
|
+
throw Error(`morphicons: ${e} at d[${r}]`);
|
|
4
|
+
}, h = (e) => e >= 48 && e <= 57, g = () => {
|
|
5
|
+
for (; r < n;) {
|
|
6
|
+
let t = e.charCodeAt(r);
|
|
7
|
+
if (t === 32 || t === 9 || t === 10 || t === 13 || t === 12 || t === 44) r++;
|
|
8
|
+
else break;
|
|
9
|
+
}
|
|
10
|
+
}, _ = () => {
|
|
11
|
+
g();
|
|
12
|
+
let t = r;
|
|
13
|
+
r < n && (e[r] === "+" || e[r] === "-") && r++;
|
|
14
|
+
let i = !1;
|
|
15
|
+
for (; r < n && h(e.charCodeAt(r));) r++, i = !0;
|
|
16
|
+
if (r < n && e[r] === ".") for (r++; r < n && h(e.charCodeAt(r));) r++, i = !0;
|
|
17
|
+
if (i || m("expected number"), r < n && (e[r] === "e" || e[r] === "E")) {
|
|
18
|
+
let t = r;
|
|
19
|
+
r++, r < n && (e[r] === "+" || e[r] === "-") && r++;
|
|
20
|
+
let i = !1;
|
|
21
|
+
for (; r < n && h(e.charCodeAt(r));) r++, i = !0;
|
|
22
|
+
i || (r = t);
|
|
23
|
+
}
|
|
24
|
+
return Number(e.slice(t, r));
|
|
25
|
+
}, v = () => {
|
|
26
|
+
g();
|
|
27
|
+
let t = e[r];
|
|
28
|
+
return t === "0" || t === "1" ? (r++, +(t === "1")) : m("expected arc flag (0|1)");
|
|
29
|
+
}, y = () => (p || m("path must start with M/m"), c || (c = {
|
|
30
|
+
x0: i,
|
|
31
|
+
y0: a,
|
|
32
|
+
segs: [],
|
|
33
|
+
closed: !1
|
|
34
|
+
}, t.push(c)), c), b = !1, x = () => _() + (b ? i : 0), S = () => _() + (b ? a : 0);
|
|
35
|
+
for (; g(), !(r >= n);) {
|
|
36
|
+
let n = e[r];
|
|
37
|
+
switch ("MmLlHhVvCcSsQqTtAaZz".includes(n) ? (l = n, r++) : l === "" ? m("path must start with M/m") : l === "M" ? l = "L" : l === "m" ? l = "l" : (l === "Z" || l === "z") && m("stray data after Z"), b = l >= "a", b ? l.toUpperCase() : l) {
|
|
38
|
+
case "M": {
|
|
39
|
+
p = !0;
|
|
40
|
+
let e = x(), n = S();
|
|
41
|
+
i = e, a = n, o = e, s = n, c = {
|
|
42
|
+
x0: e,
|
|
43
|
+
y0: n,
|
|
44
|
+
segs: [],
|
|
45
|
+
closed: !1
|
|
46
|
+
}, t.push(c), f = "";
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case "L": {
|
|
50
|
+
let e = x(), t = S();
|
|
51
|
+
y().segs.push([
|
|
52
|
+
"L",
|
|
53
|
+
e,
|
|
54
|
+
t
|
|
55
|
+
]), i = e, a = t, f = "";
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case "H": {
|
|
59
|
+
let e = x();
|
|
60
|
+
y().segs.push([
|
|
61
|
+
"L",
|
|
62
|
+
e,
|
|
63
|
+
a
|
|
64
|
+
]), i = e, f = "";
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "V": {
|
|
68
|
+
let e = S();
|
|
69
|
+
y().segs.push([
|
|
70
|
+
"L",
|
|
71
|
+
i,
|
|
72
|
+
e
|
|
73
|
+
]), a = e, f = "";
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "C":
|
|
77
|
+
case "S": {
|
|
78
|
+
let e, t;
|
|
79
|
+
l === "C" || l === "c" ? (e = x(), t = S()) : (e = f === "C" ? 2 * i - u : i, t = f === "C" ? 2 * a - d : a);
|
|
80
|
+
let n = x(), r = S(), o = x(), s = S();
|
|
81
|
+
y().segs.push([
|
|
82
|
+
"C",
|
|
83
|
+
e,
|
|
84
|
+
t,
|
|
85
|
+
n,
|
|
86
|
+
r,
|
|
87
|
+
o,
|
|
88
|
+
s
|
|
89
|
+
]), u = n, d = r, i = o, a = s, f = "C";
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case "Q":
|
|
93
|
+
case "T": {
|
|
94
|
+
let e, t;
|
|
95
|
+
l === "Q" || l === "q" ? (e = x(), t = S()) : (e = f === "Q" ? 2 * i - u : i, t = f === "Q" ? 2 * a - d : a);
|
|
96
|
+
let n = x(), r = S();
|
|
97
|
+
y().segs.push([
|
|
98
|
+
"Q",
|
|
99
|
+
e,
|
|
100
|
+
t,
|
|
101
|
+
n,
|
|
102
|
+
r
|
|
103
|
+
]), u = e, d = t, i = n, a = r, f = "Q";
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case "A": {
|
|
107
|
+
let e = _(), t = _(), n = _(), r = v(), o = v(), s = x(), c = S();
|
|
108
|
+
y().segs.push([
|
|
109
|
+
"A",
|
|
110
|
+
e,
|
|
111
|
+
t,
|
|
112
|
+
n,
|
|
113
|
+
r,
|
|
114
|
+
o,
|
|
115
|
+
s,
|
|
116
|
+
c
|
|
117
|
+
]), i = s, a = c, f = "";
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "Z":
|
|
121
|
+
c &&= (c.closed = !0, null), i = o, a = s, f = "";
|
|
122
|
+
break;
|
|
123
|
+
default: m(`unsupported command "${l}"`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return t.filter((e) => e.segs.length > 0);
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { e as parsePath };
|
|
130
|
+
/* 欲穷千里目,更上一层楼 */
|
|
131
|
+
/* 独立思考,明辨是非 */
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Sampled } from './types';
|
|
2
|
+
export interface Similarity {
|
|
3
|
+
theta: number;
|
|
4
|
+
sigma: number;
|
|
5
|
+
res: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Alignment extends Similarity {
|
|
8
|
+
ca: readonly [number, number];
|
|
9
|
+
cb: readonly [number, number];
|
|
10
|
+
/** A with the chosen correspondence (re-indexed only if A is the closed loop). */
|
|
11
|
+
a: Float64Array;
|
|
12
|
+
/** B with the chosen correspondence (orientation and circular offset). */
|
|
13
|
+
b: Float64Array;
|
|
14
|
+
}
|
|
15
|
+
export interface PlanItem {
|
|
16
|
+
/** Points of A with the chosen correspondence (if A is a closed loop it
|
|
17
|
+
* may come circularly re-indexed: same points, different cut). */
|
|
18
|
+
a: Float64Array;
|
|
19
|
+
/** A centered on its centroid. */
|
|
20
|
+
aC: Float64Array;
|
|
21
|
+
/** B brought into A's frame: R(−θ)·(b − c_B)/σ. */
|
|
22
|
+
bT: Float64Array;
|
|
23
|
+
/** B oriented, raw (for linear mode and for exact t=1). */
|
|
24
|
+
bO: Float64Array;
|
|
25
|
+
ca: readonly [number, number];
|
|
26
|
+
cb: readonly [number, number];
|
|
27
|
+
theta: number;
|
|
28
|
+
lnSigma: number;
|
|
29
|
+
res: number;
|
|
30
|
+
/** true if both endpoints are closed loops: the subpath flies with Z.
|
|
31
|
+
* Closed → open flies open: the loop opens at the chosen cut. */
|
|
32
|
+
closed: boolean;
|
|
33
|
+
/** Block transport (set by the global hybrid, else null): mid-flight the
|
|
34
|
+
* centroid rides the shared similarity around the global centroid instead
|
|
35
|
+
* of lerping — off = c_A − g_A; drift closes c(1) = c_B exactly. */
|
|
36
|
+
block: {
|
|
37
|
+
off: readonly [number, number];
|
|
38
|
+
drift: readonly [number, number];
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
export interface MorphPlan {
|
|
42
|
+
items: PlanItem[];
|
|
43
|
+
n: number;
|
|
44
|
+
}
|
|
45
|
+
export declare function centroid(p: Float64Array): [number, number];
|
|
46
|
+
export declare function polyLen(p: Float64Array): number;
|
|
47
|
+
export declare function reversePts(p: Float64Array): Float64Array;
|
|
48
|
+
/** Circular re-indexing of a loop: out[i] = p[(i+off) mod n]. Same point
|
|
49
|
+
* set, different cut point — the circular degree of freedom of closed paths. */
|
|
50
|
+
export declare function rotatePts(p: Float64Array, off: number): Float64Array;
|
|
51
|
+
/** Optimal similarity (θ, σ) minimizing Σ|σ·R(θ)·(a−c_A) − (b−c_B)|².
|
|
52
|
+
* θ* = atan2(S_xy − S_yx, S_xx + S_yy); σ* by zero derivative.
|
|
53
|
+
* res = RMS residual normalized by b's energy (0 → same shape). */
|
|
54
|
+
export declare function procrustes(a: Float64Array, b: Float64Array, ca: readonly [number, number], cb: readonly [number, number]): Similarity;
|
|
55
|
+
/** Best index-to-index correspondence between a and b: tries both traversal
|
|
56
|
+
* directions and, if there is a closed loop, its N circular offsets,
|
|
57
|
+
* scoring with score = res + λ·|θ|/π. The freedom is applied to ONE cloud
|
|
58
|
+
* — the closed one (b if both are); varying both at once would be
|
|
59
|
+
* redundant. */
|
|
60
|
+
export declare function alignPair(aPts: Float64Array, bPts: Float64Array, aClosed?: boolean, bClosed?: boolean): Alignment;
|
|
61
|
+
/** Builds the morph plan between two lists of sampled subpaths. The plan is
|
|
62
|
+
* cacheable and serializable; it accepts any list — including intermediate
|
|
63
|
+
* shapes (interruptions). */
|
|
64
|
+
export declare function buildPlan(srcSubs: readonly Sampled[], dstSubs: readonly Sampled[]): MorphPlan;
|