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
|
@@ -8,20 +8,18 @@ import { Console } from './Console.mjs';
|
|
|
8
8
|
import { Derived } from './Derived.mjs';
|
|
9
9
|
import { Effect } from './Effect.mjs';
|
|
10
10
|
import { Paths } from './Paths.mjs';
|
|
11
|
-
import { SafeExit } from './SafeExit.mjs';
|
|
12
11
|
import { Signal } from './Signal.mjs';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @template POST
|
|
21
|
-
* @typedef {import('./WorkerThread.mjs').WorkerThread<RECEIVE, POST>} WorkerThread
|
|
14
|
+
* it supposed to be able to call on browser too
|
|
15
|
+
* ```js
|
|
16
|
+
* import { SafeExit } from './SafeExit.mjs';
|
|
17
|
+
* ```
|
|
18
|
+
* need to add cleaner for SafeExit.instance?.addCallback
|
|
22
19
|
*/
|
|
20
|
+
|
|
23
21
|
/**
|
|
24
|
-
* @typedef {import('../
|
|
22
|
+
* @typedef {import('../typehints/VivthCleanup.mjs').VivthCleanup} VivthCleanup
|
|
25
23
|
*/
|
|
26
24
|
|
|
27
25
|
/**
|
|
@@ -29,8 +27,18 @@ import { Signal } from './Signal.mjs';
|
|
|
29
27
|
* - class helper to create `Worker` instance;
|
|
30
28
|
* - before any `Worker` functionaily to be used, you need to setup it with `WorkerThread.setup` and `WorkerMainThread.setup` before runing anytyhing;
|
|
31
29
|
* @template {WorkerThread<any, any>} WT
|
|
30
|
+
* @implements {VivthCleanup}
|
|
32
31
|
*/
|
|
33
32
|
export class WorkerMainThread {
|
|
33
|
+
/**
|
|
34
|
+
* @template POST
|
|
35
|
+
* @typedef {import('./WorkerResult.mjs').WorkerResult<POST>} WorkerResult
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* @template RECEIVE
|
|
39
|
+
* @template POST
|
|
40
|
+
* @typedef {import('./WorkerThread.mjs').WorkerThread<RECEIVE, POST>} WorkerThread
|
|
41
|
+
*/
|
|
34
42
|
/**
|
|
35
43
|
* @type {boolean}
|
|
36
44
|
*/
|
|
@@ -56,7 +64,7 @@ export class WorkerMainThread {
|
|
|
56
64
|
* ```
|
|
57
65
|
* @example
|
|
58
66
|
* import { Worker } from 'node:worker_threads';
|
|
59
|
-
* import { WorkerMainThread } from 'vivth';
|
|
67
|
+
* import { WorkerMainThread } from 'vivth/neutral';
|
|
60
68
|
*
|
|
61
69
|
* WorkerMainThread.setup({
|
|
62
70
|
* workerClass: Worker,
|
|
@@ -73,10 +81,10 @@ export class WorkerMainThread {
|
|
|
73
81
|
* });
|
|
74
82
|
*/
|
|
75
83
|
static setup = ({ workerClass, pathValidator }) => {
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
if (
|
|
85
|
+
/** */
|
|
86
|
+
WorkerMainThread.#isRegistered
|
|
87
|
+
) {
|
|
80
88
|
Console.warn({ message: 'WorkerMainThread.setup, can only be called once' });
|
|
81
89
|
return;
|
|
82
90
|
}
|
|
@@ -103,28 +111,14 @@ export class WorkerMainThread {
|
|
|
103
111
|
type: 'module',
|
|
104
112
|
});
|
|
105
113
|
/**
|
|
106
|
-
* @template {WorkerThread<any, any>} WT
|
|
107
114
|
* @description
|
|
108
115
|
* - create Worker_instance;
|
|
109
|
-
* @param {
|
|
110
|
-
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>}
|
|
111
|
-
* @returns {WorkerMainThread<WT>}
|
|
116
|
+
* @param {import('../bundler/adds/PathFSBundles.mjs').PathFSBundles} handler
|
|
117
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} options
|
|
112
118
|
* @example
|
|
113
|
-
* import { WorkerMainThread } from 'vivth';
|
|
119
|
+
* import { WorkerMainThread } from 'vivth/neutral';
|
|
114
120
|
*
|
|
115
|
-
* export const myDoubleWorker = WorkerMainThread.
|
|
116
|
-
*/
|
|
117
|
-
static newVivthWorker(handler, options = {}) {
|
|
118
|
-
return new WorkerMainThread(handler, options);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @private
|
|
122
|
-
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
|
|
123
|
-
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
|
|
124
|
-
* @example
|
|
125
|
-
* import { WorkerMainThread } from 'vivth';
|
|
126
|
-
*
|
|
127
|
-
* export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
|
|
121
|
+
* export const myDoubleWorker = new WorkerMainThread(PathFSBundles.vivthBundles('./doubleWorkerThread.mjs'));
|
|
128
122
|
*/
|
|
129
123
|
constructor(handler, options = {}) {
|
|
130
124
|
/**
|
|
@@ -134,7 +128,7 @@ export class WorkerMainThread {
|
|
|
134
128
|
const listener = (ev) => {
|
|
135
129
|
this.#proxyReceiver.value = ev;
|
|
136
130
|
};
|
|
137
|
-
WorkerMainThread.#workerFilehandler(handler, options, this, listener);
|
|
131
|
+
WorkerMainThread.#workerFilehandler(handler.path, options, this, listener);
|
|
138
132
|
}
|
|
139
133
|
/**
|
|
140
134
|
* @type {import('./Signal.mjs').Signal<import('./WorkerResult.mjs').WorkerResult<WT["POST"]>|MessageEvent<import('./WorkerResult.mjs').WorkerResult<WT["POST"]>>>}
|
|
@@ -153,94 +147,97 @@ export class WorkerMainThread {
|
|
|
153
147
|
static async #workerFilehandler(handler, options, worker, listener) {
|
|
154
148
|
const pathValidator = WorkerMainThread.pathValidator;
|
|
155
149
|
const [resolvedPath_, error] = await TryAsync(async () => {
|
|
156
|
-
if (Paths.root === undefined) {
|
|
157
|
-
throw new Error('path root undefined');
|
|
158
|
-
}
|
|
159
150
|
return await pathValidator({
|
|
160
151
|
worker: handler,
|
|
161
152
|
root: Paths.root,
|
|
162
153
|
});
|
|
163
154
|
});
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
155
|
+
if (
|
|
156
|
+
/** */
|
|
157
|
+
error
|
|
158
|
+
) {
|
|
159
|
+
Console.error(
|
|
160
|
+
{
|
|
161
|
+
error,
|
|
162
|
+
pathValidator,
|
|
163
|
+
message: 'invalid pathValidator inputed to `WorkerMainThread`;',
|
|
164
|
+
},
|
|
165
|
+
{ now: true },
|
|
166
|
+
);
|
|
170
167
|
return;
|
|
171
168
|
}
|
|
172
169
|
const resolvedPath = resolvedPath_;
|
|
173
170
|
const runtime = GetRuntime();
|
|
174
171
|
const workerClass = WorkerMainThread.workerClass;
|
|
175
172
|
if (
|
|
176
|
-
|
|
173
|
+
/** */
|
|
177
174
|
!workerClass
|
|
178
175
|
) {
|
|
179
|
-
Console.error('invalid `Worker` inputed to `WorkerMainThread`;');
|
|
176
|
+
Console.error('invalid `Worker` inputed to `WorkerMainThread`;', { now: true });
|
|
180
177
|
return;
|
|
181
178
|
}
|
|
182
|
-
const [, errorCreatingWorker] = await Tries({
|
|
179
|
+
const [[key], errorCreatingWorker] = await Tries({
|
|
183
180
|
browser: async () => {
|
|
184
|
-
if (
|
|
185
|
-
|
|
181
|
+
if (
|
|
182
|
+
/** */
|
|
183
|
+
runtime !== 'browser'
|
|
184
|
+
) {
|
|
185
|
+
throw 'not a browser';
|
|
186
186
|
}
|
|
187
|
-
const worker_ = (worker.#worker.value = new workerClass(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
throw
|
|
187
|
+
const worker_ = (worker.#worker.value = new workerClass(resolvedPath, {
|
|
188
|
+
...options,
|
|
189
|
+
...WorkerMainThread.#options,
|
|
190
|
+
}));
|
|
191
|
+
if (
|
|
192
|
+
/** */
|
|
193
|
+
'onmessage' in worker_ ===
|
|
194
|
+
false
|
|
195
|
+
) {
|
|
196
|
+
throw 'not a browser';
|
|
197
197
|
}
|
|
198
198
|
worker_.onmessage = listener;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
});
|
|
203
|
-
}
|
|
199
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
200
|
+
// worker_.onmessage = null;
|
|
201
|
+
// });
|
|
204
202
|
},
|
|
205
203
|
nonBrowser: async () => {
|
|
206
|
-
if (workerClass !== (await import('node:worker_threads')).Worker) {
|
|
207
|
-
throw "Worker are not impored from 'node:worker_threads'";
|
|
208
|
-
}
|
|
209
204
|
const worker_ = (worker.#worker.value = new workerClass(resolvedPath, {
|
|
210
205
|
...options,
|
|
211
206
|
...WorkerMainThread.#options,
|
|
212
207
|
}));
|
|
213
|
-
if (
|
|
214
|
-
|
|
208
|
+
if (
|
|
209
|
+
/** */
|
|
210
|
+
'addEventListener' in worker_
|
|
211
|
+
) {
|
|
215
212
|
worker_.addEventListener('message', listener);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
213
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
214
|
+
// worker_.removeEventListener('message', listener);
|
|
215
|
+
// });
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (
|
|
219
|
+
/** */
|
|
220
|
+
'addListener' in worker_
|
|
221
|
+
) {
|
|
223
222
|
worker_.addListener('message', listener);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
throw new Error('not a standard non browser');
|
|
223
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
224
|
+
// worker_.removeListener('message', listener);
|
|
225
|
+
// });
|
|
226
|
+
return;
|
|
231
227
|
}
|
|
228
|
+
throw 'not a standard non browser';
|
|
232
229
|
},
|
|
233
230
|
});
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
231
|
+
if (
|
|
232
|
+
/** */
|
|
233
|
+
!key
|
|
234
|
+
) {
|
|
235
|
+
Console.error({ errorCreatingWorker }, { now: true });
|
|
239
236
|
return;
|
|
240
237
|
}
|
|
241
|
-
SafeExit.instance
|
|
242
|
-
|
|
243
|
-
});
|
|
238
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
239
|
+
// worker.terminate();
|
|
240
|
+
// });
|
|
244
241
|
}
|
|
245
242
|
/**
|
|
246
243
|
* lazyly generated because node version need to await
|
|
@@ -255,7 +252,11 @@ export class WorkerMainThread {
|
|
|
255
252
|
#handler = new Effect(async ({ subscribe }) => {
|
|
256
253
|
const postData = subscribe(this.#proxyPost).value;
|
|
257
254
|
const worker = subscribe(this.#worker).value;
|
|
258
|
-
if (
|
|
255
|
+
if (
|
|
256
|
+
/** */
|
|
257
|
+
worker === undefined ||
|
|
258
|
+
postData === undefined
|
|
259
|
+
) {
|
|
259
260
|
return;
|
|
260
261
|
}
|
|
261
262
|
worker.postMessage(postData, []);
|
|
@@ -263,9 +264,9 @@ export class WorkerMainThread {
|
|
|
263
264
|
/**
|
|
264
265
|
* @description
|
|
265
266
|
* - terminate all signals that are used on this instance;
|
|
266
|
-
* @return {void}
|
|
267
|
+
* @return {Promise<void>}
|
|
267
268
|
*/
|
|
268
|
-
|
|
269
|
+
vivthCleanup = async () => {
|
|
269
270
|
this.postMessage(closeWorkerThreadEventObject);
|
|
270
271
|
/**
|
|
271
272
|
* this is more for browser, as most of this are automatically cleaned with `SafeExit`;
|
|
@@ -282,7 +283,7 @@ export class WorkerMainThread {
|
|
|
282
283
|
* - result signal of the processed message;
|
|
283
284
|
* @type {Derived<WorkerResult<WT["POST"]>>}
|
|
284
285
|
* @example
|
|
285
|
-
* import { Effect } from 'vivth';
|
|
286
|
+
* import { Effect } from 'vivth/neutral';
|
|
286
287
|
* import { myDoubleWorker } from './myDoubleWorker.mjs';
|
|
287
288
|
*
|
|
288
289
|
* const doubleReceiverSignal = myDoubleWorker.receiverSignal;
|
|
@@ -293,7 +294,10 @@ export class WorkerMainThread {
|
|
|
293
294
|
*/
|
|
294
295
|
receiverSignal = new Derived(async ({ subscribe }) => {
|
|
295
296
|
const val = subscribe(this.#proxyReceiver).value;
|
|
296
|
-
if (
|
|
297
|
+
if (
|
|
298
|
+
/** */
|
|
299
|
+
val instanceof MessageEvent
|
|
300
|
+
) {
|
|
297
301
|
return val.data;
|
|
298
302
|
}
|
|
299
303
|
return val;
|
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
/// <reference lib='dom' />
|
|
2
3
|
|
|
3
4
|
import { closeWorkerThreadEventObject } from '../common/eventObjects.mjs';
|
|
4
5
|
import { EventCheck } from '../function/EventCheck.mjs';
|
|
6
|
+
import { LazyFactory } from '../function/LazyFactory.mjs';
|
|
5
7
|
import { Tries } from '../function/Tries.mjs';
|
|
6
8
|
import { TryAsync } from '../function/TryAsync.mjs';
|
|
7
9
|
import { Console } from './Console.mjs';
|
|
8
10
|
import { QChannel } from './QChannel.mjs';
|
|
9
11
|
import { WorkerResult } from './WorkerResult.mjs';
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @typedef { import('../typehints/VivthCleanup.mjs').VivthCleanup } VivthCleanup
|
|
15
|
+
*/
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* @description
|
|
13
19
|
* - class helper for `WorkerThread` creation;
|
|
14
20
|
* - before any `Worker` functionaily to be used, you need to setup it with `WorkerThread.setup` and `WorkerMainThread.setup` before runing anytyhing;
|
|
15
21
|
* @template RECEIVE
|
|
16
22
|
* @template POST
|
|
23
|
+
* @implements {VivthCleanup}
|
|
17
24
|
*/
|
|
18
25
|
export class WorkerThread {
|
|
26
|
+
vivthCleanup = async () => {
|
|
27
|
+
WorkerThread.#refs?.parentPort?.removeAllListeners();
|
|
28
|
+
WorkerThread.#refs?.parentPort?.close();
|
|
29
|
+
};
|
|
19
30
|
/**
|
|
20
|
-
* @
|
|
31
|
+
* @returns {QChannel<WorkerThread>}
|
|
32
|
+
*/
|
|
33
|
+
#q = LazyFactory(() => new QChannel('WorkerThread'));
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {import('../typehints/QCBReturn.mjs').QCBReturn} QCBReturn
|
|
21
36
|
*/
|
|
22
37
|
/**
|
|
23
38
|
* @type {Parameters<typeof WorkerThread["setup"]>[0]|undefined}
|
|
@@ -35,8 +50,8 @@ export class WorkerThread {
|
|
|
35
50
|
* ```
|
|
36
51
|
* @returns {typeof WorkerThread<RECEIVE, POST>}
|
|
37
52
|
* @example
|
|
38
|
-
* import { WorkerThread } from 'vivth';
|
|
39
53
|
* import { parentPort } from 'node:worker_threads';
|
|
54
|
+
* import { WorkerThread } from 'vivth/neutral';
|
|
40
55
|
*
|
|
41
56
|
* export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
|
|
42
57
|
*/
|
|
@@ -44,10 +59,6 @@ export class WorkerThread {
|
|
|
44
59
|
WorkerThread.#refs = refs;
|
|
45
60
|
return WorkerThread;
|
|
46
61
|
}
|
|
47
|
-
/**
|
|
48
|
-
* @returns {QChannel<WorkerThread>}
|
|
49
|
-
*/
|
|
50
|
-
#qChannel = new QChannel('`WorkerThread` individuals');
|
|
51
62
|
/**
|
|
52
63
|
* @param {any} ev
|
|
53
64
|
*/
|
|
@@ -82,30 +93,26 @@ export class WorkerThread {
|
|
|
82
93
|
* @param {MessageEvent<RECEIVE>|RECEIVE} ev
|
|
83
94
|
* @returns {Promise<void>}
|
|
84
95
|
*/
|
|
85
|
-
// @ts-expect-error
|
|
86
96
|
self.onmessage = async function (ev) {
|
|
87
97
|
const [, error] = await TryAsync(async () => {
|
|
88
98
|
ev = ev instanceof MessageEvent ? ev.data : ev;
|
|
89
99
|
if (WorkerThread.#isCloseWorkerEvent(ev)) {
|
|
90
|
-
this_.#
|
|
91
|
-
// @ts-expect-error
|
|
100
|
+
this_.#q.close();
|
|
92
101
|
self.onmessage = null;
|
|
93
102
|
return;
|
|
94
103
|
}
|
|
95
|
-
const [data, error] = await this_.#
|
|
104
|
+
const [data, error] = await this_.#q.callback(this, async ({ isLastOnQ }) => {
|
|
96
105
|
// @ts-expect-error
|
|
97
106
|
return await handler(ev, isLastOnQ);
|
|
98
107
|
});
|
|
99
108
|
if (error) {
|
|
100
109
|
throw error;
|
|
101
110
|
}
|
|
102
|
-
// @ts-expect-error
|
|
103
111
|
self.postMessage(new WorkerResult(data, undefined));
|
|
104
112
|
});
|
|
105
113
|
if (error === undefined) {
|
|
106
114
|
return;
|
|
107
115
|
}
|
|
108
|
-
// @ts-expect-error
|
|
109
116
|
self.postMessage(new WorkerResult(undefined, error?.message ?? 'Unknown error'));
|
|
110
117
|
};
|
|
111
118
|
},
|
|
@@ -125,11 +132,11 @@ export class WorkerThread {
|
|
|
125
132
|
const [, error] = await TryAsync(async () => {
|
|
126
133
|
ev = ev instanceof MessageEvent ? ev.data : ev;
|
|
127
134
|
if (WorkerThread.#isCloseWorkerEvent(ev)) {
|
|
128
|
-
this_.#
|
|
135
|
+
this_.#q.close();
|
|
129
136
|
parentPort.off('message', listener);
|
|
130
137
|
return;
|
|
131
138
|
}
|
|
132
|
-
const [data, error] = await this_.#
|
|
139
|
+
const [data, error] = await this_.#q.callback(this_, async ({ isLastOnQ }) => {
|
|
133
140
|
// @ts-expect-error
|
|
134
141
|
return await handler(ev, isLastOnQ);
|
|
135
142
|
});
|
|
@@ -145,11 +152,11 @@ export class WorkerThread {
|
|
|
145
152
|
};
|
|
146
153
|
parentPort.on('message', listener);
|
|
147
154
|
},
|
|
148
|
-
}).then(([,
|
|
149
|
-
if (
|
|
155
|
+
}).then(([, errorMakingWorkerThread]) => {
|
|
156
|
+
if (errorMakingWorkerThread === undefined || !errorMakingWorkerThread.size) {
|
|
150
157
|
return;
|
|
151
158
|
}
|
|
152
|
-
Console.error(
|
|
159
|
+
Console.error({ errorMakingWorkerThread }, { now: true });
|
|
153
160
|
});
|
|
154
161
|
}
|
|
155
162
|
/**
|
package/src/common/Base64URL.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
import { ForOfSync } from '../function/ForOfSync.mjs';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* @description
|
|
5
7
|
* - create inline base64 url;
|
|
@@ -17,7 +19,8 @@
|
|
|
17
19
|
* ```
|
|
18
20
|
* @returns {string}
|
|
19
21
|
* @example
|
|
20
|
-
* import { Base64URL } from 'vivth'
|
|
22
|
+
* import { Base64URL } from 'vivth/neutral';
|
|
23
|
+
*
|
|
21
24
|
* import fileString from './fileString.mjs';
|
|
22
25
|
*
|
|
23
26
|
* // example for browser;
|
|
@@ -26,8 +29,8 @@
|
|
|
26
29
|
export function Base64URL(fileString, mimeType, btoaFunction) {
|
|
27
30
|
const utf8 = new TextEncoder().encode(fileString);
|
|
28
31
|
let binary = '';
|
|
29
|
-
|
|
32
|
+
ForOfSync(utf8, (byte) => {
|
|
30
33
|
binary += String.fromCharCode(byte);
|
|
31
|
-
}
|
|
34
|
+
});
|
|
32
35
|
return `data:${mimeType.toString()};base64,${btoaFunction(binary)}`;
|
|
33
36
|
}
|
|
@@ -4,21 +4,34 @@ import { readFile } from 'node:fs/promises';
|
|
|
4
4
|
|
|
5
5
|
import { lookup } from 'mime-types';
|
|
6
6
|
|
|
7
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
8
|
+
import { Console } from '../class/Console.mjs';
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* @description
|
|
9
12
|
* - create inline base64 url;
|
|
10
13
|
* - usage:
|
|
11
14
|
* >- can be extremely usefull to display file on desktop app webview, without exposing http server;
|
|
12
|
-
* >- when using `
|
|
15
|
+
* >- when using `FSasar`, use [Base64URL](#base64url) instead;
|
|
13
16
|
* @param {string} filePath
|
|
14
|
-
* @returns {Promise<string>}
|
|
17
|
+
* @returns {Promise<{data:string, mime:string|false}|undefined>}
|
|
15
18
|
* @example
|
|
16
19
|
* import { join } from 'node:path'
|
|
17
20
|
*
|
|
18
|
-
* import { Base64URLFromFile
|
|
21
|
+
* import { Base64URLFromFile } from 'vivth/node';
|
|
22
|
+
* import { Paths } from 'vivth/neutral';
|
|
19
23
|
*
|
|
20
24
|
* await Base64URLFromFile(join(Paths.root, '/path/to/file'));
|
|
21
25
|
*/
|
|
22
26
|
export async function Base64URLFromFile(filePath) {
|
|
23
|
-
|
|
27
|
+
const [res, errorBase64URLFromFile] = await TryAsync(async () => {
|
|
28
|
+
const mime = lookup(filePath);
|
|
29
|
+
const data = `data:${lookup(filePath)};base64,${await readFile(filePath, { encoding: 'base64' })}`;
|
|
30
|
+
return { data, mime };
|
|
31
|
+
});
|
|
32
|
+
if (errorBase64URLFromFile) {
|
|
33
|
+
Console.error({ errorBase64URLFromFile });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
return res;
|
|
24
37
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* - class helper for `vivth` `Bundled` values;
|
|
6
|
+
*/
|
|
7
|
+
export class BundledV {
|
|
8
|
+
static #isBundled = false;
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* - readonly value of whether the script run after being bundled with `vivth` or not;
|
|
12
|
+
* @readonly
|
|
13
|
+
* @type {boolean}
|
|
14
|
+
* @example
|
|
15
|
+
* import { BundledV } from 'vivth/neutral';
|
|
16
|
+
*
|
|
17
|
+
* if(BundledV.isBundled){
|
|
18
|
+
* // code
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
static get isBundled() {
|
|
22
|
+
return BundledV.#isBundled;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @description
|
|
26
|
+
* - to create `unbundled` only codeBlock;
|
|
27
|
+
* >- when properly bundled via `vivth` bundling mechanism, this code block will be removed;
|
|
28
|
+
* @param {()=>void} callback
|
|
29
|
+
* @param {import('./VivthUnBundledCodeBlock.mjs').VivthUnBundledCodeBlock} _closing
|
|
30
|
+
* - must be filled for regexp detection;
|
|
31
|
+
* @returns {void}
|
|
32
|
+
* @example
|
|
33
|
+
* import { BundledV } from 'vivth/neutral';
|
|
34
|
+
*
|
|
35
|
+
* BundledV.vivthUnBundledCodeBlock(() => {
|
|
36
|
+
* // code
|
|
37
|
+
* }, 'vivthUnBundledCodeBlock')
|
|
38
|
+
*/
|
|
39
|
+
static vivthUnBundledCodeBlock = (callback, _closing) => {
|
|
40
|
+
if (BundledV.isBundled) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
callback();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -5,7 +5,7 @@ import { LazyFactory } from '../function/LazyFactory.mjs';
|
|
|
5
5
|
import { Timeout } from '../function/Timeout.mjs';
|
|
6
6
|
import { TryAsync } from '../function/TryAsync.mjs';
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const q = LazyFactory(() => new QChannel('CreateStringID'));
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @description
|
|
@@ -13,21 +13,22 @@ const qchannel = LazyFactory(() => new QChannel('CreateStringID'));
|
|
|
13
13
|
* - the asynchrounous nature is to prevent race condition that might resulting same Id being generated;
|
|
14
14
|
* >- queued using QChannel;
|
|
15
15
|
* @param {string} [prefix]
|
|
16
|
+
* @param {string} [suffix]
|
|
16
17
|
* @returns {ReturnType<typeof TryAsync<string>>}
|
|
17
18
|
* @example
|
|
18
|
-
* import { CreateStringID } from 'vivth';
|
|
19
|
+
* import { CreateStringID } from 'vivth/neutral';
|
|
19
20
|
*
|
|
20
21
|
* (async () => {
|
|
21
|
-
* const [myUniqueID, errorCreatingUniqueID] = await CreateStringID('myPrefix');
|
|
22
|
+
* const [myUniqueID, errorCreatingUniqueID] = await CreateStringID('myPrefix', 'mySuffix');
|
|
22
23
|
* if(errorCreatingUniqueID) {
|
|
23
24
|
* return;
|
|
24
25
|
* }
|
|
25
|
-
* Console.log(myUniqueID); // `myPrefix${Date.now()}`
|
|
26
|
+
* Console.log(myUniqueID); // `myPrefix${Date.now()}mySuffix`
|
|
26
27
|
* })()
|
|
27
28
|
*/
|
|
28
|
-
export async function CreateStringID(prefix = '') {
|
|
29
|
-
return await
|
|
29
|
+
export async function CreateStringID(prefix = '', suffix = '') {
|
|
30
|
+
return await q.callback('newStringID', async () => {
|
|
30
31
|
await Timeout(1);
|
|
31
|
-
return `${prefix}${Date.now()}`;
|
|
32
|
+
return `${prefix}${Date.now()}${suffix}`;
|
|
32
33
|
});
|
|
33
34
|
}
|