vivth 1.4.10 → 1.5.1
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/README.md +6060 -2037
- package/README.src.md +22 -14
- package/bun.lock +154 -194
- package/dev/auto/.src.ignore +28 -0
- package/dev/auto-doc.mjs +137 -0
- package/generated/types/generated/vivth/exports/all.d.mts +145 -0
- package/generated/types/generated/vivth/exports/neutral.d.mts +105 -0
- package/generated/types/generated/vivth/exports/node.d.mts +40 -0
- package/generated/types/src/bundler/CompileAS.d.mts +30 -0
- package/generated/types/src/bundler/CompileJS.d.mts +109 -0
- package/{types → generated/types}/src/bundler/CreateESPlugin.d.mts +1 -1
- package/{types → generated/types}/src/bundler/EsBundler.d.mts +9 -7
- package/generated/types/src/bundler/FSAnalyzer.d.mts +58 -0
- package/generated/types/src/bundler/FSasar.bundled.d.mts +28 -0
- package/generated/types/src/bundler/FSasar.d.mts +51 -0
- package/generated/types/src/bundler/FileSelfMapper.d.mts +137 -0
- package/generated/types/src/bundler/JSDirMapper.d.mts +128 -0
- package/generated/types/src/bundler/RunWatchThenCompileJSOnSafeExit.d.mts +63 -0
- package/generated/types/src/bundler/adds/BrowserExternals.d.mts +21 -0
- package/generated/types/src/bundler/adds/CreateTransform.d.mts +26 -0
- package/generated/types/src/bundler/adds/LastEditedUnix.d.mts +5 -0
- package/generated/types/src/bundler/adds/NodeModuleList.d.mts +15 -0
- package/generated/types/src/bundler/adds/PathFSBundles.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSBundles.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSDir.bundled.d.mts +30 -0
- package/generated/types/src/bundler/adds/PathFSDir.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSFile.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSFile.d.mts +40 -0
- package/{types → generated/types}/src/bundler/adds/ToBundledJSPlugin.d.mts +6 -6
- package/generated/types/src/bundler/adds/autoExternalize.d.mts +2 -0
- package/generated/types/src/bundler/adds/emptyBufferValue.d.mts +1 -0
- package/generated/types/src/bundler/adds/isModuleTheBundledVersion.d.mts +1 -0
- package/generated/types/src/bundler/adds/onEndEsBuildErrorLogger.d.mts +1 -0
- package/generated/types/src/bundler/adds/resolveJSDependencyPath.d.mts +1 -0
- package/generated/types/src/class/AwaitSignal.d.mts +48 -0
- package/generated/types/src/class/Console.d.mts +82 -0
- package/generated/types/src/class/DataLog.d.mts +25 -0
- package/generated/types/src/class/Derived.d.mts +74 -0
- package/generated/types/src/class/Effect.d.mts +213 -0
- package/{types → generated/types}/src/class/EnvSignal.d.mts +6 -2
- package/generated/types/src/class/EsWatcher.d.mts +36 -0
- package/{types → generated/types}/src/class/EventSignal.d.mts +39 -39
- package/generated/types/src/class/FSDirArchWatcher.d.mts +110 -0
- package/{types → generated/types}/src/class/FileSafe.d.mts +32 -16
- package/generated/types/src/class/ForEach.d.mts +57 -0
- package/generated/types/src/class/ForSignal.d.mts +63 -0
- package/generated/types/src/class/GetterSetter.d.mts +38 -0
- package/generated/types/src/class/JSONFileHandler.d.mts +50 -0
- package/{types → generated/types}/src/class/ListSignal.d.mts +49 -15
- package/{types → generated/types}/src/class/LitExp.d.mts +18 -18
- package/generated/types/src/class/ObjectSignal.d.mts +267 -0
- package/generated/types/src/class/Paths.d.mts +95 -0
- package/generated/types/src/class/Prettivy.d.mts +26 -0
- package/{types → generated/types}/src/class/QChannel.d.mts +24 -16
- package/generated/types/src/class/SafeExit.d.mts +69 -0
- package/{types → generated/types}/src/class/Setup.d.mts +29 -16
- package/{types → generated/types}/src/class/Signal.d.mts +29 -15
- package/generated/types/src/class/SignalCollection.d.mts +96 -0
- package/{types → generated/types}/src/class/WalkThrough.d.mts +4 -19
- package/generated/types/src/class/WorkerMainThread.bundled.d.mts +83 -0
- package/{types → generated/types}/src/class/WorkerMainThread.d.mts +33 -39
- package/{types → generated/types}/src/class/WorkerThread.d.mts +11 -5
- package/{types → generated/types}/src/common/Base64URL.d.mts +2 -1
- package/generated/types/src/common/Base64URLFromFile.d.mts +20 -0
- package/generated/types/src/common/BundledV.bundled.d.mts +3 -0
- package/generated/types/src/common/BundledV.d.mts +36 -0
- package/{types → generated/types}/src/common/CreateStringID.d.mts +5 -4
- package/generated/types/src/common/EnvMode.d.mts +79 -0
- package/generated/types/src/common/FactoryKey.d.mts +9 -0
- package/generated/types/src/common/Preferrence.d.mts +25 -0
- package/{types → generated/types}/src/common/Trace.d.mts +1 -1
- package/{types → generated/types}/src/common/TracePath.d.mts +1 -1
- package/generated/types/src/common/VivthUnBundledCodeBlock.d.mts +6 -0
- package/generated/types/src/doc/JSautoDOC.d.mts +172 -0
- package/generated/types/src/doc/cleanPreserveTypedef.d.mts +1 -0
- package/{types/src/doc/parsedFile.d.mts → generated/types/src/doc/parsedFileForDOC.d.mts} +56 -27
- package/generated/types/src/function/ClearRequireCache.d.mts +1 -0
- package/{types → generated/types}/src/function/CreateImmutable.d.mts +5 -4
- package/{types → generated/types}/src/function/EventCheck.d.mts +3 -1
- package/{types → generated/types}/src/function/EventObject.d.mts +2 -6
- package/generated/types/src/function/ForInAsync.d.mts +36 -0
- package/generated/types/src/function/ForInSync.d.mts +36 -0
- package/generated/types/src/function/ForOfAsync.d.mts +25 -0
- package/generated/types/src/function/ForOfSync.d.mts +36 -0
- package/generated/types/src/function/GetBufferFromRelativePath.d.mts +15 -0
- package/generated/types/src/function/GetFilesFromDir.d.mts +14 -0
- package/generated/types/src/function/GetMaxFilenameLength.d.mts +9 -0
- package/generated/types/src/function/GetModuleEsbuildPlatform.d.mts +13 -0
- package/{types → generated/types}/src/function/GetNamedImportAlias.d.mts +1 -1
- package/generated/types/src/function/GetRuntime.d.mts +2 -0
- package/generated/types/src/function/InstantiateAssemblyScript.d.mts +15 -0
- package/{types → generated/types}/src/function/IsAsync.d.mts +1 -1
- package/generated/types/src/function/IsInstanceOf.d.mts +25 -0
- package/generated/types/src/function/IsSameFile.d.mts +16 -0
- package/generated/types/src/function/IsStringLooksLikeAPath.d.mts +16 -0
- package/generated/types/src/function/IsTypeOf.d.mts +25 -0
- package/{types → generated/types}/src/function/LazyFactory.d.mts +9 -10
- package/generated/types/src/function/MonkeyPatch.d.mts +33 -0
- package/generated/types/src/function/NewAnimationTimeline.d.mts +24 -0
- package/generated/types/src/function/NewChainable.d.mts +35 -0
- package/generated/types/src/function/NewDynamicsExport.d.mts +49 -0
- package/generated/types/src/function/NewObjectWrapper.d.mts +10 -0
- package/generated/types/src/function/ObjectRegistrar.d.mts +17 -0
- package/generated/types/src/function/ParseSQLFile.d.mts +25 -0
- package/generated/types/src/function/PipeAsync.d.mts +19 -0
- package/generated/types/src/function/PipeSync.d.mts +17 -0
- package/generated/types/src/function/SafeImport.d.mts +21 -0
- package/generated/types/src/function/TemplateLiteral.d.mts +23 -0
- package/{types → generated/types}/src/function/Timeout.d.mts +1 -1
- package/{types → generated/types}/src/function/Tries.d.mts +4 -4
- package/{types → generated/types}/src/function/TryAsync.d.mts +2 -2
- package/{types → generated/types}/src/function/TryNew.d.mts +1 -1
- package/generated/types/src/function/TsToMjs.d.mts +27 -0
- package/generated/types/src/function/UniqueFSTempName.d.mts +9 -0
- package/generated/types/src/function/errorToMessage.d.mts +5 -0
- package/generated/types/src/neinth/VivthyNeinth.d.mts +202 -0
- package/generated/types/src/typehints/ArrayToKeys.d.mts +23 -0
- package/generated/types/src/typehints/AssemblyScriptExportsType.d.mts +4 -0
- package/generated/types/src/typehints/AssemblyScriptLoaderInstantiate.d.mts +4 -0
- package/generated/types/src/typehints/AutoDocASOptions.d.mts +15 -0
- package/generated/types/src/typehints/ChainableType.d.mts +3 -0
- package/generated/types/src/typehints/ComponentDecorator_Constructor.d.mts +3 -0
- package/generated/types/src/typehints/ConsoleAdditionalSettingType.d.mts +3 -0
- package/generated/types/src/typehints/Decorator.d.mts +11 -0
- package/generated/types/src/typehints/DecoratorMonkeyPatch.d.mts +15 -0
- package/{types/src/types → generated/types/src/typehints}/DevTestCB.d.mts +2 -2
- package/generated/types/src/typehints/EnvModeType.d.mts +4 -0
- package/generated/types/src/typehints/ListArg.d.mts +4 -0
- package/generated/types/src/typehints/MonkeyPatchedType.d.mts +1 -0
- package/generated/types/src/typehints/ParametersFollowingN.d.mts +13 -0
- package/generated/types/src/typehints/PrefixedKeysOf.d.mts +1 -0
- package/generated/types/src/typehints/Runtime.d.mts +4 -0
- package/generated/types/src/typehints/SafeImportReturnType.d.mts +1 -0
- package/generated/types/src/typehints/StylePropRefType.d.mts +2 -0
- package/generated/types/src/typehints/TemplateLiteralValueHandler.d.mts +10 -0
- package/generated/types/src/typehints/VLifecycleCallbacks.d.mts +6 -0
- package/generated/types/src/typehints/VivthCleanup.d.mts +12 -0
- package/generated/types/src/web/BrowserDirMapper.d.mts +70 -0
- package/generated/types/src/web/EnsureValidTag.d.mts +7 -0
- package/generated/types/src/web/ViteAddDynamics.d.mts +28 -0
- package/generated/types/src/web/ViteGetAllHTMLFile.d.mts +9 -0
- package/generated/types/src/web/WC_extendsA.d.mts +135 -0
- package/generated/types/src/web/WC_extendsB.d.mts +135 -0
- package/generated/types/src/web/bindings/WC_StyleProp_bind.d.mts +42 -0
- package/generated/types/src/web/bindings/WC_createElement_bind.d.mts +51 -0
- package/generated/types/src/web/bindings/WC_createNamedSlot.d.mts +26 -0
- package/generated/types/src/web/bindings/WC_litRender_bind.d.mts +20 -0
- package/generated/types/src/web/bindings/WC_litStyleMap.d.mts +7 -0
- package/generated/types/src/web/common/CSS.d.mts +23 -0
- package/generated/types/src/web/common/E.d.mts +41 -0
- package/generated/types/src/web/common/NewStyleSheetAsync.d.mts +15 -0
- package/generated/types/src/web/common/NewStyleSheetSync.d.mts +15 -0
- package/generated/types/src/web/common/WC_TagName_type.d.mts +15 -0
- package/generated/types/src/web/signals/IsInViewPortSignal.d.mts +52 -0
- package/generated/types/src/web/signals/ObserverSignal.d.mts +32 -0
- package/generated/types/src/web/signals/WC_litRef.d.mts +26 -0
- package/generated/types/src/web/signals/WC_loopedSiblingsRef.d.mts +44 -0
- package/generated/vivth/exports/all.mjs +233 -0
- package/generated/vivth/exports/neutral.mjs +193 -0
- package/generated/vivth/exports/node.mjs +46 -0
- package/package.json +78 -42
- package/src/bundler/CompileAS.mjs +36 -0
- package/src/bundler/CompileJS.mjs +98 -171
- package/src/bundler/CreateESPlugin.mjs +1 -1
- package/src/bundler/EsBundler.mjs +38 -13
- package/src/bundler/FSAnalyzer.mjs +253 -0
- package/src/bundler/FSasar.bundled.mjs +128 -0
- package/src/bundler/FSasar.mjs +96 -0
- package/src/bundler/FileSelfMapper.mjs +491 -0
- package/src/bundler/JSDirMapper.mjs +528 -0
- package/src/bundler/RunWatchThenCompileJSOnSafeExit.mjs +129 -0
- package/src/bundler/adds/BrowserExternals.mjs +37 -0
- package/src/bundler/adds/CreateTransform.mjs +36 -0
- package/src/bundler/adds/LastEditedUnix.mjs +12 -0
- package/src/bundler/adds/NodeModuleList.mjs +33 -0
- package/src/bundler/adds/PathFSBundles.bundled.mjs +41 -0
- package/src/bundler/adds/PathFSBundles.mjs +91 -0
- package/src/bundler/adds/PathFSDir.bundled.mjs +53 -0
- package/src/bundler/adds/PathFSDir.mjs +100 -0
- package/src/bundler/adds/PathFSFile.bundled.mjs +40 -0
- package/src/bundler/adds/PathFSFile.mjs +85 -0
- package/src/bundler/adds/ToBundledJSPlugin.mjs +116 -55
- package/src/bundler/adds/autoExternalize.mjs +81 -0
- package/src/bundler/adds/emptyBufferValue.mjs +5 -0
- package/src/bundler/adds/isModuleTheBundledVersion.mjs +10 -0
- package/src/bundler/adds/onEndEsBuildErrorLogger.mjs +34 -0
- package/src/bundler/adds/resolveJSDependencyPath.mjs +17 -0
- package/src/class/AwaitSignal.mjs +119 -0
- package/src/class/Console.mjs +36 -14
- package/src/class/DataLog.mjs +29 -0
- package/src/class/Derived.mjs +67 -55
- package/src/class/Effect.mjs +270 -84
- package/src/class/EnvSignal.mjs +11 -8
- package/src/class/EsWatcher.mjs +60 -0
- package/src/class/EventSignal.mjs +46 -58
- package/src/class/FSDirArchWatcher.mjs +246 -0
- package/src/class/FileSafe.mjs +72 -24
- package/src/class/ForEach.mjs +78 -0
- package/src/class/ForSignal.mjs +115 -0
- package/src/class/GetterSetter.mjs +40 -0
- package/src/class/JSONFileHandler.mjs +90 -0
- package/src/class/ListSignal.mjs +68 -26
- package/src/class/LitExp.mjs +59 -36
- package/src/class/ObjectSignal.mjs +225 -0
- package/src/class/Paths.mjs +56 -20
- package/src/class/Prettivy.mjs +51 -0
- package/src/class/QChannel.mjs +48 -26
- package/src/class/SafeExit.mjs +156 -99
- package/src/class/Setup.mjs +28 -16
- package/src/class/Signal.mjs +50 -27
- package/src/class/SignalCollection.mjs +130 -0
- package/src/class/WalkThrough.mjs +6 -23
- package/src/class/{WorkerMainThreadBundled.mjs → WorkerMainThread.bundled.mjs} +56 -77
- package/src/class/WorkerMainThread.mjs +98 -94
- package/src/class/WorkerThread.mjs +24 -17
- package/src/common/Base64URL.mjs +6 -3
- package/src/common/Base64URLFromFile.mjs +17 -4
- package/src/common/BundledV.bundled.mjs +7 -0
- package/src/common/BundledV.mjs +45 -0
- package/src/common/CreateStringID.mjs +8 -7
- package/src/common/EnvMode.mjs +172 -0
- package/src/common/FactoryKey.mjs +11 -0
- package/src/common/Preferrence.mjs +27 -0
- package/src/common/Trace.mjs +1 -1
- package/src/common/TracePath.mjs +53 -3
- package/src/common/VivthUnBundledCodeBlock.mjs +8 -0
- package/src/doc/JSautoDOC.mjs +673 -284
- package/src/doc/cleanPreserveTypedef.mjs +27 -0
- package/src/doc/correctBeforeParse.mjs +57 -48
- package/src/doc/{parsedFile.mjs → parsedFileForDOC.mjs} +133 -120
- package/src/function/ClearRequireCache.mjs +33 -0
- package/src/function/CreateImmutable.mjs +40 -37
- package/src/function/EventCheck.mjs +5 -2
- package/src/function/EventObject.mjs +2 -6
- package/src/function/ForInAsync.mjs +76 -0
- package/src/function/ForInSync.mjs +87 -0
- package/src/function/ForOfAsync.mjs +61 -0
- package/src/function/ForOfSync.mjs +70 -0
- package/src/function/GetBufferFromRelativePath.mjs +25 -0
- package/src/function/GetFilesFromDir.mjs +49 -0
- package/src/function/GetMaxFilenameLength.mjs +32 -0
- package/src/function/GetModuleEsbuildPlatform.mjs +118 -0
- package/src/function/GetNamedImportAlias.mjs +2 -2
- package/src/function/GetRuntime.mjs +10 -14
- package/src/function/InstantiateAssemblyScript.mjs +22 -0
- package/src/function/IsAsync.mjs +1 -1
- package/src/function/IsInstanceOf.mjs +29 -0
- package/src/function/IsSameFile.mjs +41 -0
- package/src/function/IsStringLooksLikeAPath.mjs +20 -0
- package/src/function/IsTypeOf.mjs +27 -0
- package/src/function/IsTypeOf.mts +31 -0
- package/src/function/LazyFactory.mjs +25 -23
- package/src/function/MonkeyPatch.mjs +38 -0
- package/src/function/NewAnimationTimeline.mjs +55 -0
- package/src/function/NewChainable.mjs +69 -0
- package/src/function/NewDynamicsExport.mjs +312 -0
- package/src/function/NewObjectWrapper.mjs +14 -0
- package/src/function/ObjectRegistrar.mjs +23 -0
- package/src/function/ParseSQLFile.mjs +129 -0
- package/src/function/PipeAsync.mjs +30 -0
- package/src/function/PipeSync.mjs +28 -0
- package/src/function/SafeImport.mjs +77 -0
- package/src/function/TemplateLiteral.mjs +42 -23
- package/src/function/Timeout.mjs +4 -4
- package/src/function/Tries.mjs +22 -16
- package/src/function/TryAsync.mjs +3 -2
- package/src/function/TryNew.mjs +1 -1
- package/src/function/TsToMjs.mjs +184 -21
- package/src/function/UniqueFSTempName.mjs +33 -0
- package/src/function/errorToMessage.mjs +21 -0
- package/src/function/resolveErrorArray.mjs +15 -1
- package/src/neinth/VivthyNeinth.mjs +487 -0
- package/src/typehints/ArrayToKeys.mjs +17 -0
- package/src/typehints/ArrayToKeys.mts +31 -0
- package/src/typehints/AssemblyScriptExportsType.mjs +7 -0
- package/src/typehints/AssemblyScriptLoaderInstantiate.mjs +7 -0
- package/src/typehints/AutoDocASOptions.mjs +14 -0
- package/src/typehints/ChainableType.mjs +11 -0
- package/src/typehints/ComponentDecorator_Constructor.mjs +10 -0
- package/src/typehints/ConsoleAdditionalSettingType.mjs +6 -0
- package/src/typehints/Decorator.mjs +9 -0
- package/src/typehints/Decorator.mts +31 -0
- package/src/typehints/DecoratorMonkeyPatch.mjs +10 -0
- package/src/typehints/DecoratorMonkeyPatch.mts +43 -0
- package/src/{types → typehints}/DevTestCB.mjs +2 -2
- package/src/typehints/EnvModeType.mjs +6 -0
- package/src/{types → typehints}/ListArg.mjs +1 -1
- package/src/{types → typehints}/LitExpResultType.mjs +1 -1
- package/src/typehints/MonkeyPatchedType.mjs +13 -0
- package/src/typehints/ParametersFollowingN.mjs +8 -0
- package/src/typehints/ParametersFollowingN.mts +17 -0
- package/src/typehints/PrefixedKeysOf.mjs +9 -0
- package/src/typehints/Runtime.mjs +6 -0
- package/src/typehints/SafeImportReturnType.mjs +6 -0
- package/src/typehints/StylePropRefType.mjs +12 -0
- package/src/typehints/TemplateLiteralValueHandler.mjs +14 -0
- package/src/typehints/VLifecycleCallbacks.mjs +10 -0
- package/src/typehints/VivthCleanup.mjs +14 -0
- package/src/web/BrowserDirMapper.mjs +255 -0
- package/src/web/EnsureValidTag.mjs +5 -0
- package/src/web/EnsureValidTag.mts +10 -0
- package/src/web/ViteAddDynamics.mjs +34 -0
- package/src/web/ViteGetAllHTMLFile.mjs +97 -0
- package/src/web/WC_extendsA.mjs +330 -0
- package/src/web/WC_extendsB.mjs +332 -0
- package/src/web/bindings/WC_StyleProp_bind.mjs +70 -0
- package/src/web/bindings/WC_createElement_bind.mjs +95 -0
- package/src/web/bindings/WC_createNamedSlot.mjs +29 -0
- package/src/web/bindings/WC_litRender_bind.mjs +26 -0
- package/src/web/bindings/WC_litStyleMap.mjs +14 -0
- package/src/web/common/CSS.mjs +35 -0
- package/src/web/common/E.mjs +126 -0
- package/src/web/common/NewStyleSheetAsync.mjs +21 -0
- package/src/web/common/NewStyleSheetSync.mjs +21 -0
- package/src/web/common/WC_TagName_type.mjs +10 -0
- package/src/web/common/WC_TagName_type.mts +36 -0
- package/src/web/signals/IsInViewPortSignal.mjs +140 -0
- package/src/web/signals/ObserverSignal.mjs +93 -0
- package/src/web/signals/WC_litRef.mjs +61 -0
- package/src/web/signals/WC_loopedSiblingsRef.mjs +100 -0
- package/tsconfig.json +44 -41
- package/index.mjs +0 -91
- package/src/bundler/FSInline.mjs +0 -67
- package/src/bundler/FSInlineAnalyzer.mjs +0 -228
- package/src/bundler/FSInlineBundled.mjs +0 -38
- package/src/bundler/adds/externals.mjs +0 -8
- package/src/class/ListDerived.mjs +0 -42
- package/src/common/Dev.mjs +0 -142
- package/src/common/DevBundled.mjs +0 -5
- package/src/common/lazie.mjs +0 -3
- package/src/types/IsListSignal.mjs +0 -6
- package/src/types/Runtime.mjs +0 -6
- package/src/types/VivthDevCodeBlockStringType.mjs +0 -6
- package/types/index.d.mts +0 -58
- package/types/src/bundler/CompileJS.d.mts +0 -119
- package/types/src/bundler/FSInline.d.mts +0 -50
- package/types/src/bundler/FSInlineAnalyzer.d.mts +0 -37
- package/types/src/bundler/FSInlineBundled.d.mts +0 -22
- package/types/src/bundler/adds/externals.d.mts +0 -1
- package/types/src/class/Console.d.mts +0 -71
- package/types/src/class/Derived.d.mts +0 -98
- package/types/src/class/Effect.d.mts +0 -216
- package/types/src/class/ListDerived.d.mts +0 -38
- package/types/src/class/Paths.d.mts +0 -69
- package/types/src/class/SafeExit.d.mts +0 -103
- package/types/src/class/WorkerMainThreadBundled.d.mts +0 -83
- package/types/src/common/Base64URLFromFile.d.mts +0 -16
- package/types/src/common/Dev.d.mts +0 -68
- package/types/src/common/DevBundled.d.mts +0 -3
- package/types/src/common/lazie.d.mts +0 -1
- package/types/src/doc/JSautoDOC.d.mts +0 -83
- package/types/src/function/GetRuntime.d.mts +0 -2
- package/types/src/function/TemplateLiteral.d.mts +0 -22
- package/types/src/function/TsToMjs.d.mts +0 -23
- package/types/src/types/IsListSignal.d.mts +0 -4
- package/types/src/types/ListArg.d.mts +0 -4
- package/types/src/types/Runtime.d.mts +0 -4
- package/types/src/types/VivthDevCodeBlockStringType.d.mts +0 -4
- /package/{types → generated/types}/src/bundler/adds/pluginVivthBundle.d.mts +0 -0
- /package/{types → generated/types}/src/class/WorkerResult.d.mts +0 -0
- /package/{types → generated/types}/src/common/EventNameSpace.d.mts +0 -0
- /package/{types → generated/types}/src/common/eventObjects.d.mts +0 -0
- /package/{types → generated/types}/src/common/keys.d.mts +0 -0
- /package/{types → generated/types}/src/doc/correctBeforeParse.d.mts +0 -0
- /package/{types → generated/types}/src/function/TrySync.d.mts +0 -0
- /package/{types → generated/types}/src/function/resolveErrorArray.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/AnyButUndefined.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/ExtnameType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpKeyType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpResultType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/MutationType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBFIFOReturn.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBReturn.d.mts +0 -0
- /package/src/{types → typehints}/AnyButUndefined.mjs +0 -0
- /package/src/{types → typehints}/ExtnameType.mjs +0 -0
- /package/src/{types → typehints}/LitExpKeyType.mjs +0 -0
- /package/src/{types → typehints}/MutationType.mjs +0 -0
- /package/src/{types → typehints}/QCBFIFOReturn.mjs +0 -0
- /package/src/{types → typehints}/QCBReturn.mjs +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { build } from 'esbuild';
|
|
6
|
+
|
|
7
|
+
import { ForOfSync } from './ForOfSync.mjs';
|
|
8
|
+
import { Paths } from '../class/Paths.mjs';
|
|
9
|
+
import { TryAsync } from './TryAsync.mjs';
|
|
10
|
+
import { SafeImport } from './SafeImport.mjs';
|
|
11
|
+
import { Console } from '../class/Console.mjs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {Set<string>} platforms
|
|
15
|
+
* @param {string} path
|
|
16
|
+
* @returns {Promise<void>}
|
|
17
|
+
*/
|
|
18
|
+
const checkByImportWithoutCache = async (platforms, path) => {
|
|
19
|
+
const [, errorCheckingNodePlatform] = await SafeImport(path);
|
|
20
|
+
if (errorCheckingNodePlatform) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
platforms.add('node');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {Set<string>} platforms
|
|
28
|
+
* @param {string} path
|
|
29
|
+
* @returns {Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
const browserBuilder = async (platforms, path) => {
|
|
32
|
+
await build({
|
|
33
|
+
entryPoints: [path],
|
|
34
|
+
platform: 'browser',
|
|
35
|
+
bundle: true,
|
|
36
|
+
write: false,
|
|
37
|
+
mainFields: ['module', 'main'],
|
|
38
|
+
logLevel: 'silent',
|
|
39
|
+
target: 'esnext',
|
|
40
|
+
format: 'esm',
|
|
41
|
+
absWorkingDir: dirname(path),
|
|
42
|
+
});
|
|
43
|
+
platforms.add('browser');
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @type {Set<string>}
|
|
48
|
+
*/
|
|
49
|
+
const errorsSet = new Set();
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @description
|
|
53
|
+
* - get valid esbuild platform name for a module path;
|
|
54
|
+
* @param { string } path
|
|
55
|
+
* @returns { Promise<'browser'|'node'|'neutral'|'unsupported'> }
|
|
56
|
+
* @example
|
|
57
|
+
* // D://lib-root/myModule.mjs
|
|
58
|
+
* import process from 'node:process'; // lookupA;
|
|
59
|
+
* import { GetModuleEsbuildPlatform } from "vivth/node";
|
|
60
|
+
*
|
|
61
|
+
* await GetModuleEsbuildPlatform('./myModule.mjs'); // 'node'; caused of lookupA;
|
|
62
|
+
*/
|
|
63
|
+
export async function GetModuleEsbuildPlatform(path) {
|
|
64
|
+
path = Paths.normalize(path);
|
|
65
|
+
/**
|
|
66
|
+
* @type { Set<string> }
|
|
67
|
+
*/
|
|
68
|
+
const platforms = new Set();
|
|
69
|
+
|
|
70
|
+
await Promise.all(
|
|
71
|
+
ForOfSync(
|
|
72
|
+
[
|
|
73
|
+
async () => {
|
|
74
|
+
await browserBuilder(platforms, path);
|
|
75
|
+
},
|
|
76
|
+
async () => {
|
|
77
|
+
await checkByImportWithoutCache(platforms, path);
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
async (cb) => {
|
|
81
|
+
return await TryAsync(cb);
|
|
82
|
+
},
|
|
83
|
+
)[0],
|
|
84
|
+
);
|
|
85
|
+
if (platforms.has('node') && platforms.has('browser')) {
|
|
86
|
+
if (errorsSet.has(path)) {
|
|
87
|
+
errorsSet.delete(path);
|
|
88
|
+
Console.info(
|
|
89
|
+
{ path, message: 'GetModuleEsbuildPlatform platform issue has been fixed' },
|
|
90
|
+
{ now: true },
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return 'neutral';
|
|
94
|
+
}
|
|
95
|
+
if (platforms.has('browser')) {
|
|
96
|
+
if (errorsSet.has(path)) {
|
|
97
|
+
errorsSet.delete(path);
|
|
98
|
+
Console.info(
|
|
99
|
+
{ path, message: 'GetModuleEsbuildPlatform platform issue has been fixed' },
|
|
100
|
+
{ now: true },
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return 'browser';
|
|
104
|
+
}
|
|
105
|
+
if (platforms.has('node')) {
|
|
106
|
+
if (errorsSet.has(path)) {
|
|
107
|
+
errorsSet.delete(path);
|
|
108
|
+
Console.info(
|
|
109
|
+
{ path, message: 'GetModuleEsbuildPlatform platform issue has been fixed' },
|
|
110
|
+
{ now: true },
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return 'node';
|
|
114
|
+
}
|
|
115
|
+
errorsSet.add(path);
|
|
116
|
+
Console.error({ GetModuleEsbuildPlatformErrorsSet: errorsSet }, { now: true });
|
|
117
|
+
return 'unsupported';
|
|
118
|
+
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @param {string} packageName
|
|
11
11
|
* @returns {string|undefined}
|
|
12
12
|
* @example
|
|
13
|
-
* import { GetNamedImportAlias } from 'vivth';
|
|
13
|
+
* import { GetNamedImportAlias } from 'vivth/neutral';
|
|
14
14
|
*
|
|
15
15
|
* const checkNoAlias = `
|
|
16
16
|
* import { something } from 'packageName';
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
export function GetNamedImportAlias(content, moduleName, packageName) {
|
|
25
25
|
const checkIfImportingFromVivthRegex = new RegExp(
|
|
26
26
|
`(import\\s+{\\s*[\\s\\S]*(?<imported>${moduleName})\\s+as\\s+(?<alias>[a-zA-Z0-9]+)[\\s\\S]*\\s*}\\s+from\\s+['"]${packageName}['"])|(import\\s+{\\s*[\\s\\S]*(?<imported>${moduleName})[\\s\\S]*\\s*}\\s+from\\s+['"]${packageName}['"])`,
|
|
27
|
-
'g'
|
|
27
|
+
'g',
|
|
28
28
|
);
|
|
29
29
|
const matched = checkIfImportingFromVivthRegex.exec(content);
|
|
30
30
|
if (!matched || !matched.groups) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
import { IsTypeOf } from './IsTypeOf.mjs';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
|
-
* @typedef {import("../
|
|
6
|
+
* @typedef {import("../typehints/Runtime.mjs").Runtime} Runtime
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -14,26 +16,20 @@ let runtime;
|
|
|
14
16
|
* - detects the current JavaScript runtime;
|
|
15
17
|
* @type {()=>Runtime}
|
|
16
18
|
* @example
|
|
17
|
-
* import { GetRuntime }
|
|
19
|
+
* import { GetRuntime } from 'vivth/neutral';
|
|
18
20
|
*
|
|
19
21
|
* const runtime = GetRuntime();
|
|
20
22
|
*/
|
|
21
23
|
export function GetRuntime() {
|
|
22
24
|
if (runtime === undefined) {
|
|
23
|
-
if (
|
|
24
|
-
runtime = 'bun';
|
|
25
|
-
}
|
|
26
|
-
// @ts-expect-error
|
|
27
|
-
else if (typeof Deno !== 'undefined') {
|
|
28
|
-
runtime = 'deno';
|
|
29
|
-
} else if (typeof process !== 'undefined' && process.versions?.node) {
|
|
30
|
-
runtime = 'node';
|
|
31
|
-
} else if (
|
|
25
|
+
if (
|
|
32
26
|
// @ts-expect-error
|
|
33
|
-
|
|
34
|
-
// @ts-expect-error
|
|
35
|
-
typeof document !== 'undefined'
|
|
27
|
+
!IsTypeOf(Bun, 'undefined')
|
|
36
28
|
) {
|
|
29
|
+
runtime = 'bun';
|
|
30
|
+
} else if (!IsTypeOf(process, 'undefined') && process.versions?.node) {
|
|
31
|
+
runtime = 'node';
|
|
32
|
+
} else if (!IsTypeOf(window, 'undefined') && !IsTypeOf(document, 'undefined')) {
|
|
37
33
|
runtime = 'browser';
|
|
38
34
|
} else {
|
|
39
35
|
runtime = 'unknown';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { instantiate } from '@assemblyscript/loader';
|
|
4
|
+
import { FSasar } from '../bundler/FSasar.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* - function wrapper for `.asar` `.wasm` from `AssemblyScript` asset;
|
|
9
|
+
* - conventions for using this class in conjuction with `JSautoDOC`:
|
|
10
|
+
* @template {Record<string, unknown>} RESULTTYPE
|
|
11
|
+
* @param {import('../bundler/adds/PathFSFile.mjs').PathFSFile} filePathFromProject
|
|
12
|
+
* - call `PathFSFile.vivthFile`;
|
|
13
|
+
* @param {Parameters<import('../typehints/AssemblyScriptLoaderInstantiate.mjs').AssemblyScriptLoaderInstantiate<RESULTTYPE>>[1]} [imports]
|
|
14
|
+
* @returns {Promise<import('../typehints/AssemblyScriptExportsType.mjs').AssemblyScriptExportsType<RESULTTYPE>>}
|
|
15
|
+
* @example
|
|
16
|
+
* import { PathFSFile, InstantiateAssemblyScript } from 'vivth/node';
|
|
17
|
+
*
|
|
18
|
+
* InstantiateAssemblyScript(PathFSFile.vivthFile('../function/myAsm.wasm'));;
|
|
19
|
+
*/
|
|
20
|
+
export async function InstantiateAssemblyScript(filePathFromProject, imports) {
|
|
21
|
+
return await instantiate(Buffer.from(await FSasar.file(filePathFromProject)), imports);
|
|
22
|
+
}
|
package/src/function/IsAsync.mjs
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* A type-safe `instanceof` helper.
|
|
6
|
+
* @template OBJ
|
|
7
|
+
* @param {unknown} obj - The object to test
|
|
8
|
+
* @param {new (...args: any[]) => OBJ} classRef - A constructor reference for T
|
|
9
|
+
* @returns {obj is OBJ}
|
|
10
|
+
* @example
|
|
11
|
+
* import { IsInstanceOf, Signal, Effect } from 'vivth/neutral';
|
|
12
|
+
*
|
|
13
|
+
* const a = new Signal(0);
|
|
14
|
+
* IsInstanceOf(a, Signal); // true
|
|
15
|
+
* IsInstanceOf(a, Effect); // false
|
|
16
|
+
*
|
|
17
|
+
* // but why not
|
|
18
|
+
* if(!(a instanceof Signal)){
|
|
19
|
+
* //
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // here's why
|
|
23
|
+
* if(!IsInstanceOf(a, Signal)){
|
|
24
|
+
* //
|
|
25
|
+
* };
|
|
26
|
+
*/
|
|
27
|
+
export function IsInstanceOf(obj, classRef) {
|
|
28
|
+
return obj instanceof classRef;
|
|
29
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { resolve } from 'path-unified';
|
|
4
|
+
import { IsStringLooksLikeAPath } from './IsStringLooksLikeAPath.mjs';
|
|
5
|
+
import { Console } from '../class/Console.mjs';
|
|
6
|
+
import { Paths } from '../class/Paths.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} url
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
const stripFileUrl = (url) => {
|
|
13
|
+
return url.startsWith('file://') ? url.slice(7) : url;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @description
|
|
18
|
+
* - check if two path is the same file;
|
|
19
|
+
* @param {string} pathA
|
|
20
|
+
* @param {string} pathB
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
* @example
|
|
23
|
+
* // `D://myFile.mjs` cwd at `D://`
|
|
24
|
+
* import { IsSameFile } from "vivth/node";
|
|
25
|
+
*
|
|
26
|
+
* IsSameFile('D:\\mFile.mjs', 'D://mFile.mjs') // true;
|
|
27
|
+
* IsSameFile('//mFile.mjs', 'D://mFile.mjs') // true;
|
|
28
|
+
* // both path are auto resolved to Paths.root;
|
|
29
|
+
* IsSameFile('D:\\mFile.mjs', 'D:\\notmfile.mjs') // false;
|
|
30
|
+
*/
|
|
31
|
+
export function IsSameFile(pathA, pathB) {
|
|
32
|
+
if (!IsStringLooksLikeAPath(pathA) || !IsStringLooksLikeAPath(pathB)) {
|
|
33
|
+
Console.warn(`'${pathA}' AND/OR '${pathB}' is not a valid path`);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const cleanA = resolve(Paths.diskAbsolute(stripFileUrl(pathA)));
|
|
37
|
+
const cleanB = resolve(Paths.diskAbsolute(stripFileUrl(pathB)));
|
|
38
|
+
const result = cleanA === cleanB;
|
|
39
|
+
// Console.log({ result, cleanA, cleanB });
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* - check if string lookslike a path;
|
|
6
|
+
* @param {string} spec
|
|
7
|
+
* @returns {boolean}
|
|
8
|
+
* @example
|
|
9
|
+
* import { IsStringLooksLikeAPath } from 'vivth/neutral';
|
|
10
|
+
*
|
|
11
|
+
* looksLikePath("./foo.mjs"); // true
|
|
12
|
+
* looksLikePath("../bar.ts"); // true
|
|
13
|
+
* looksLikePath("/usr/lib.js"); // true
|
|
14
|
+
* looksLikePath("C:\\lib\\mod"); // true
|
|
15
|
+
* looksLikePath("react"); // false
|
|
16
|
+
* looksLikePath("node:path"); // false
|
|
17
|
+
*/
|
|
18
|
+
export function IsStringLooksLikeAPath(spec) {
|
|
19
|
+
return /^(\.{1,2}\/|\/|[A-Za-z]:\\)/.test(spec) || /[\\/]/.test(spec);
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const TypeMap = {
|
|
2
|
+
string: "",
|
|
3
|
+
number: 0,
|
|
4
|
+
boolean: true,
|
|
5
|
+
object: {},
|
|
6
|
+
function: () => {
|
|
7
|
+
},
|
|
8
|
+
undefined: void 0,
|
|
9
|
+
symbol: /* @__PURE__ */ Symbol(),
|
|
10
|
+
bigint: 0n
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @preserve
|
|
14
|
+
* @description
|
|
15
|
+
* A type-safe `typeof` helper.
|
|
16
|
+
* @template {keyof typeof TypeMap} K
|
|
17
|
+
* @param {unknown} object - The value to check.
|
|
18
|
+
* @param {K} type - The type string to compare against.
|
|
19
|
+
* @returns {object is typeof TypeMap[K]} - Returns true if the type matches, narrowing the type.
|
|
20
|
+
*/
|
|
21
|
+
function IsTypeOf(object, type) {
|
|
22
|
+
return typeof object === type;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
IsTypeOf,
|
|
26
|
+
TypeMap
|
|
27
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map of 'typeof' string results to their actual TypeScript types.
|
|
3
|
+
* Using a constant object allows for type-safe extraction without
|
|
4
|
+
* manual conditional mapping.
|
|
5
|
+
*/
|
|
6
|
+
export const TypeMap = {
|
|
7
|
+
string: '',
|
|
8
|
+
number: 0,
|
|
9
|
+
boolean: true,
|
|
10
|
+
object: {},
|
|
11
|
+
function: () => {},
|
|
12
|
+
undefined: undefined,
|
|
13
|
+
symbol: Symbol(),
|
|
14
|
+
bigint: 0n,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @preserve
|
|
19
|
+
* @description
|
|
20
|
+
* A type-safe `typeof` helper.
|
|
21
|
+
* @template {keyof typeof TypeMap} K
|
|
22
|
+
* @param {unknown} object - The value to check.
|
|
23
|
+
* @param {K} type - The type string to compare against.
|
|
24
|
+
* @returns {object is typeof TypeMap[K]} - Returns true if the type matches, narrowing the type.
|
|
25
|
+
*/
|
|
26
|
+
export function IsTypeOf<K extends keyof typeof TypeMap>(
|
|
27
|
+
object: unknown,
|
|
28
|
+
type: K,
|
|
29
|
+
): object is (typeof TypeMap)[K] {
|
|
30
|
+
return typeof object === type;
|
|
31
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { FactoryKey } from '../common/FactoryKey.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @description
|
|
@@ -8,12 +8,14 @@ import { unwrapLazy } from '../common/lazie.mjs';
|
|
|
8
8
|
* >- usefull for lazily instantiating an object, since instance naturally have props/methods;
|
|
9
9
|
* @template FACTORY
|
|
10
10
|
* @param {() => FACTORY} factory
|
|
11
|
-
* @returns {FACTORY & {[
|
|
12
|
-
* - the
|
|
13
|
-
*
|
|
14
|
-
* >-
|
|
11
|
+
* @returns {FACTORY & {[FactoryKey]: FACTORY}}
|
|
12
|
+
* - the FactoryKey prop can be accessed to force instatiation/call;
|
|
13
|
+
* - usefull for Object that has different accessor behaviour when being get via Proxy, including but not limited too:
|
|
14
|
+
* >- `Set<any>`;
|
|
15
|
+
* >- `Map<any, any>`;
|
|
16
|
+
* >- non referenced object, like `Effect`;
|
|
15
17
|
* @example
|
|
16
|
-
* import { LazyFactory } from
|
|
18
|
+
* import { LazyFactory, FactoryKey } from 'vivth/neutral';
|
|
17
19
|
*
|
|
18
20
|
* class MyClass{
|
|
19
21
|
* constructor() {
|
|
@@ -33,45 +35,45 @@ import { unwrapLazy } from '../common/lazie.mjs';
|
|
|
33
35
|
* const a = myInstance; // not yet initiated;
|
|
34
36
|
* const b = a.myProp // imediately initiated;
|
|
35
37
|
* // OR
|
|
36
|
-
* myInstance[
|
|
38
|
+
* myInstance[FactoryKey] // forcefully call factory generator;
|
|
37
39
|
*/
|
|
38
40
|
export function LazyFactory(factory) {
|
|
39
41
|
/**
|
|
40
42
|
* @type {FACTORY|undefined}
|
|
41
43
|
*/
|
|
42
44
|
let instance;
|
|
45
|
+
const generateIfUndefined = () => {
|
|
46
|
+
if (instance !== undefined) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
instance = factory();
|
|
50
|
+
};
|
|
43
51
|
// @ts-expect-error
|
|
44
52
|
return new Proxy(
|
|
45
|
-
|
|
53
|
+
/** */
|
|
54
|
+
() => {},
|
|
46
55
|
{
|
|
47
56
|
get(_, prop) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return () => instance;
|
|
53
|
-
}
|
|
54
|
-
if (instance === undefined) {
|
|
55
|
-
instance = factory();
|
|
57
|
+
generateIfUndefined();
|
|
58
|
+
if (prop === FactoryKey) {
|
|
59
|
+
return instance;
|
|
56
60
|
}
|
|
57
61
|
// @ts-expect-error
|
|
58
62
|
return instance[prop];
|
|
59
63
|
},
|
|
60
64
|
set(_, prop, newValue) {
|
|
61
|
-
|
|
62
|
-
instance = factory();
|
|
63
|
-
}
|
|
65
|
+
generateIfUndefined();
|
|
64
66
|
// @ts-expect-error
|
|
65
67
|
instance[prop] = newValue;
|
|
66
68
|
return true;
|
|
67
69
|
},
|
|
68
70
|
apply(_, thisArg, args) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
generateIfUndefined();
|
|
72
|
+
if (typeof instance !== 'function') {
|
|
73
|
+
throw new TypeError('LazyFactory: instance is not callable');
|
|
71
74
|
}
|
|
72
|
-
// @ts-expect-error
|
|
73
75
|
return Reflect.apply(instance, thisArg, args);
|
|
74
76
|
},
|
|
75
|
-
}
|
|
77
|
+
},
|
|
76
78
|
);
|
|
77
79
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @import {MonkeyPatchedType} from '../typehints/MonkeyPatchedType.mjs'
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Monkey‑patch an environmental API by replacing a property on a parent object
|
|
9
|
+
* with a new function or class. This allows you to intercept or override
|
|
10
|
+
* browser/Node globals (e.g. `XMLHttpRequest`, `Worker`, `fetch`) without
|
|
11
|
+
* modifying the rest of your application code.
|
|
12
|
+
*
|
|
13
|
+
* ## Notes
|
|
14
|
+
* - Run this before other code that consumes the patched API.
|
|
15
|
+
* - Existing instances created before patching are unaffected.
|
|
16
|
+
* - If the property is non‑writable, assignment will throw.
|
|
17
|
+
* - For classes, always call `super(...args)` in your constructor.
|
|
18
|
+
* - For functions, preserve the call signature to avoid type errors.
|
|
19
|
+
*
|
|
20
|
+
* @template {Object} PAR
|
|
21
|
+
* @template {keyof PAR} KEY
|
|
22
|
+
* @param {PAR} parent - The parent object holding the property (e.g. `window`).
|
|
23
|
+
* @param {KEY} key - The property name on the parent to replace.
|
|
24
|
+
* @param {(
|
|
25
|
+
* arg0:{originalObject:PAR[KEY]}
|
|
26
|
+
* ) => MonkeyPatchedType<PAR[KEY]>
|
|
27
|
+
* } newObjectGenerator
|
|
28
|
+
* - Function that receives the original object and returns the patched version.
|
|
29
|
+
* - For classes: extend `originalObject` and override methods.
|
|
30
|
+
* - For functions: spread arguments(and when necessary, delegate to `originalObject`).
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
33
|
+
export function MonkeyPatch(parent, key, newObjectGenerator) {
|
|
34
|
+
const originalObject = parent[key];
|
|
35
|
+
/** @type {any} */
|
|
36
|
+
const newObject = newObjectGenerator({ originalObject });
|
|
37
|
+
parent[key] = newObject;
|
|
38
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { TrySync } from './TrySync.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* - create animation timeline helper;
|
|
8
|
+
* @param {Object} options
|
|
9
|
+
* @param {number} options.fps
|
|
10
|
+
* - frame per second;
|
|
11
|
+
* @param {{seconds:number}|{frames:number}} options.duration
|
|
12
|
+
* @param {(frame:{index:number, total:number, percentage:number})=>void} callback
|
|
13
|
+
* - called every frame until duration ends;
|
|
14
|
+
* @returns {()=>void}
|
|
15
|
+
* - early clearInterval callback;
|
|
16
|
+
*/
|
|
17
|
+
export function NewAnimationTimeline({ fps, duration }, callback) {
|
|
18
|
+
/** @type {ReturnType<typeof setInterval> | undefined} */
|
|
19
|
+
let interval;
|
|
20
|
+
let totalFrames;
|
|
21
|
+
if ('frames' in duration) {
|
|
22
|
+
totalFrames = duration.frames;
|
|
23
|
+
} else {
|
|
24
|
+
totalFrames = Math.round(fps * duration.seconds);
|
|
25
|
+
}
|
|
26
|
+
let currentFrame = 0;
|
|
27
|
+
const clear = () => {
|
|
28
|
+
clearInterval(interval);
|
|
29
|
+
};
|
|
30
|
+
interval = setInterval(() => {
|
|
31
|
+
const [, errorAnimate] = TrySync(() => {
|
|
32
|
+
currentFrame++;
|
|
33
|
+
callback({
|
|
34
|
+
get index() {
|
|
35
|
+
return currentFrame;
|
|
36
|
+
},
|
|
37
|
+
get total() {
|
|
38
|
+
return totalFrames;
|
|
39
|
+
},
|
|
40
|
+
get percentage() {
|
|
41
|
+
return currentFrame / totalFrames;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
if (errorAnimate) {
|
|
46
|
+
console.error({ errorAnimate });
|
|
47
|
+
clear();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (currentFrame >= totalFrames && interval) {
|
|
51
|
+
clear();
|
|
52
|
+
}
|
|
53
|
+
}, 1000 / fps);
|
|
54
|
+
return clear;
|
|
55
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* - Wraps a target object in a chainable;
|
|
6
|
+
* - example:
|
|
7
|
+
* ```html
|
|
8
|
+
* <canvas id="myCanvas" width="400" height="400"></canvas>
|
|
9
|
+
* ```
|
|
10
|
+
* - chain call are synchronous without awaiting;
|
|
11
|
+
* >- if the method are async, it could cause race condition;
|
|
12
|
+
* @template {object} OBJ
|
|
13
|
+
* @param {OBJ} ctx
|
|
14
|
+
* @returns {import("../typehints/ChainableType.mjs").ChainableType<OBJ>}
|
|
15
|
+
* @example
|
|
16
|
+
* import { NewChainable, TrySync } from 'vivth/neutral';
|
|
17
|
+
*
|
|
18
|
+
* TrySync(()=>{
|
|
19
|
+
* const canvas = document.getElementById('myCanvas');
|
|
20
|
+
* if (!canvas) {
|
|
21
|
+
* return;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* const ctx2D = canvas.getContext('2d');
|
|
25
|
+
*
|
|
26
|
+
* // instead of repeating call method from `ctx2D`, you can:
|
|
27
|
+
* NewChainable(ctx2D)
|
|
28
|
+
* .beginPath()
|
|
29
|
+
* .moveTo(50, 50)
|
|
30
|
+
* .lineTo(200, 50)
|
|
31
|
+
* .lineTo(200, 200)
|
|
32
|
+
* .closePath()
|
|
33
|
+
* .stroke();
|
|
34
|
+
* // .this to get ctx2D reference;
|
|
35
|
+
* })
|
|
36
|
+
*/
|
|
37
|
+
export function NewChainable(ctx) {
|
|
38
|
+
/**
|
|
39
|
+
* @type {import("../typehints/ChainableType.mjs").ChainableType<OBJ>}
|
|
40
|
+
*/
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
let proxy = null;
|
|
43
|
+
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
proxy = new Proxy(ctx, {
|
|
46
|
+
get(target, prop, receiver) {
|
|
47
|
+
if (prop === 'this') {
|
|
48
|
+
return ctx;
|
|
49
|
+
}
|
|
50
|
+
const value = Reflect.get(target, prop, receiver);
|
|
51
|
+
|
|
52
|
+
if (typeof value === 'function') {
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
return (...args) => {
|
|
55
|
+
value.apply(target, args);
|
|
56
|
+
return proxy;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return value;
|
|
61
|
+
},
|
|
62
|
+
set(target, prop, value) {
|
|
63
|
+
// @ts-expect-error
|
|
64
|
+
target[prop] = value;
|
|
65
|
+
return true;
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return proxy;
|
|
69
|
+
}
|