@wener/utils 1.1.26 → 1.1.29
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 +4 -0
- package/lib/arrays/MaybeArray.js +36 -25
- package/lib/arrays/MaybeArray.js.map +1 -1
- package/lib/arrays/arrayFromAsync.js +5 -7
- package/lib/arrays/arrayFromAsync.js.map +1 -1
- package/lib/asyncs/AsyncInterval.js +11 -12
- package/lib/asyncs/AsyncInterval.js.map +1 -1
- package/lib/asyncs/MaybePromise.js +3 -0
- package/lib/asyncs/MaybePromise.js.map +1 -0
- package/lib/asyncs/createAsyncIterator.js +37 -35
- package/lib/asyncs/createAsyncIterator.js.map +1 -1
- package/lib/asyncs/createLazyPromise.js +59 -60
- package/lib/asyncs/createLazyPromise.js.map +1 -1
- package/lib/asyncs/firstOfAsyncIterator.js +7 -9
- package/lib/asyncs/firstOfAsyncIterator.js.map +1 -1
- package/lib/asyncs/generatorOfStream.js +16 -0
- package/lib/asyncs/generatorOfStream.js.map +1 -0
- package/lib/asyncs/isIterator.js +3 -4
- package/lib/asyncs/isIterator.js.map +1 -1
- package/lib/asyncs/isPromise.js +3 -4
- package/lib/asyncs/isPromise.js.map +1 -1
- package/lib/asyncs/isThenable.js +6 -0
- package/lib/asyncs/isThenable.js.map +1 -0
- package/lib/asyncs/nextOfAsyncIterator.js +20 -14
- package/lib/asyncs/nextOfAsyncIterator.js.map +1 -1
- package/lib/asyncs/promiseOfCallback.js +17 -0
- package/lib/asyncs/promiseOfCallback.js.map +1 -0
- package/lib/asyncs/sleep.js +2 -3
- package/lib/asyncs/sleep.js.map +1 -1
- package/lib/asyncs/timeout.js +22 -26
- package/lib/asyncs/timeout.js.map +1 -1
- package/lib/browsers/copy.js +47 -45
- package/lib/browsers/copy.js.map +1 -1
- package/lib/browsers/download.js +38 -27
- package/lib/browsers/download.js.map +1 -1
- package/lib/browsers/getFileFromDataTransfer.js +41 -28
- package/lib/browsers/getFileFromDataTransfer.js.map +1 -1
- package/lib/browsers/loaders.js +43 -43
- package/lib/browsers/loaders.js.map +1 -1
- package/lib/crypto/base.js +5 -4
- package/lib/crypto/base.js.map +1 -1
- package/lib/crypto/getNodeCrypto.js +14 -13
- package/lib/crypto/getNodeCrypto.js.map +1 -1
- package/lib/crypto/getRandomValues.js +22 -26
- package/lib/crypto/getRandomValues.js.map +1 -1
- package/lib/crypto/hashing.js +42 -50
- package/lib/crypto/hashing.js.map +1 -1
- package/lib/crypto/md5.bench.js +21 -0
- package/lib/crypto/md5.bench.js.map +1 -0
- package/lib/crypto/md5.d.js +3 -0
- package/lib/crypto/md5.d.js.map +1 -0
- package/lib/crypto/md5.js +119 -121
- package/lib/crypto/md5.js.map +1 -1
- package/lib/crypto/pem/pem.js +32 -35
- package/lib/crypto/pem/pem.js.map +1 -1
- package/lib/crypto/randomUUID.js +12 -11
- package/lib/crypto/randomUUID.js.map +1 -1
- package/lib/crypto/ulid.js +123 -112
- package/lib/crypto/ulid.js.map +1 -1
- package/lib/errors/Errors.js +167 -149
- package/lib/errors/Errors.js.map +1 -1
- package/lib/fetch/createFetchWith.js +20 -23
- package/lib/fetch/createFetchWith.js.map +1 -1
- package/lib/fetch/createFetchWithLogging.js +20 -16
- package/lib/fetch/createFetchWithLogging.js.map +1 -1
- package/lib/fetch/createFetchWithRetry.js +61 -65
- package/lib/fetch/createFetchWithRetry.js.map +1 -1
- package/lib/fetch/dumpRequest.js +39 -42
- package/lib/fetch/dumpRequest.js.map +1 -1
- package/lib/fetch/dumpResponse.js +13 -20
- package/lib/fetch/dumpResponse.js.map +1 -1
- package/lib/fetch/index.js +7 -0
- package/lib/fetch/index.js.map +1 -0
- package/lib/fetch/types.js +3 -0
- package/lib/fetch/types.js.map +1 -0
- package/lib/http/HttpStatus.js +89 -80
- package/lib/http/HttpStatus.js.map +1 -1
- package/lib/i18n/createTranslate.js +48 -48
- package/lib/i18n/createTranslate.js.map +1 -1
- package/lib/index.js +30 -14
- package/lib/index.js.map +1 -1
- package/lib/io/AbstractEncoding.js +7 -0
- package/lib/io/AbstractEncoding.js.map +1 -0
- package/lib/io/ArrayBuffer.test-d.js +7 -0
- package/lib/io/ArrayBuffer.test-d.js.map +1 -0
- package/lib/io/ArrayBuffers.js +198 -172
- package/lib/io/ArrayBuffers.js.map +1 -1
- package/lib/io/Buffer.js +21 -20
- package/lib/io/Buffer.js.map +1 -1
- package/lib/io/base64.js +49 -48
- package/lib/io/base64.js.map +1 -1
- package/lib/io/isBuffer.js +7 -5
- package/lib/io/isBuffer.js.map +1 -1
- package/lib/io/isTransferable.js +23 -19
- package/lib/io/isTransferable.js.map +1 -1
- package/lib/isomorphics/getGlobalThis.js +17 -12
- package/lib/isomorphics/getGlobalThis.js.map +1 -1
- package/lib/isomorphics/structuredClone.js +71 -63
- package/lib/isomorphics/structuredClone.js.map +1 -1
- package/lib/langs/MaybeFunction.js +7 -7
- package/lib/langs/MaybeFunction.js.map +1 -1
- package/lib/langs/classOf.js +3 -4
- package/lib/langs/classOf.js.map +1 -1
- package/lib/langs/deepEqual.js +77 -85
- package/lib/langs/deepEqual.js.map +1 -1
- package/lib/langs/deepFreeze.js +20 -0
- package/lib/langs/deepFreeze.js.map +1 -0
- package/lib/langs/hashCode.ignored.js +112 -0
- package/lib/langs/hashCode.ignored.js.map +1 -0
- package/lib/langs/isClass.js +3 -4
- package/lib/langs/isClass.js.map +1 -1
- package/lib/langs/isDefined.js +3 -4
- package/lib/langs/isDefined.js.map +1 -1
- package/lib/langs/isEmptyObject.js +3 -5
- package/lib/langs/isEmptyObject.js.map +1 -1
- package/lib/langs/isFunction.js +5 -0
- package/lib/langs/isFunction.js.map +1 -0
- package/lib/langs/isPlainObject.js +7 -8
- package/lib/langs/isPlainObject.js.map +1 -1
- package/lib/langs/memoize.js +19 -21
- package/lib/langs/memoize.js.map +1 -1
- package/lib/langs/parseBoolean.js +26 -27
- package/lib/langs/parseBoolean.js.map +1 -1
- package/lib/langs/shallowClone.js +12 -12
- package/lib/langs/shallowClone.js.map +1 -1
- package/lib/langs/shallowEqual.js +21 -18
- package/lib/langs/shallowEqual.js.map +1 -1
- package/lib/libs/ms.js +123 -103
- package/lib/libs/ms.js.map +1 -1
- package/lib/logging/Logger.js +5 -0
- package/lib/logging/Logger.js.map +1 -0
- package/lib/logging/createChildLogger.js +12 -14
- package/lib/logging/createChildLogger.js.map +1 -1
- package/lib/logging/createLogger.js +59 -33
- package/lib/logging/createLogger.js.map +1 -1
- package/lib/logging/createNoopLogger.js +11 -12
- package/lib/logging/createNoopLogger.js.map +1 -1
- package/lib/logging/slog.js +143 -0
- package/lib/logging/slog.js.map +1 -0
- package/lib/maths/clamp.js +21 -0
- package/lib/maths/clamp.js.map +1 -0
- package/lib/maths/random.js +14 -15
- package/lib/maths/random.js.map +1 -1
- package/lib/modules/isModule.js +5 -4
- package/lib/modules/isModule.js.map +1 -1
- package/lib/modules/parseModuleId.js +36 -31
- package/lib/modules/parseModuleId.js.map +1 -1
- package/lib/objects/get.js +13 -11
- package/lib/objects/get.js.map +1 -1
- package/lib/objects/get.test-d.js +33 -0
- package/lib/objects/get.test-d.js.map +1 -0
- package/lib/objects/merge/index.js +3 -0
- package/lib/objects/merge/index.js.map +1 -0
- package/lib/objects/merge/isMergeableObject.js +11 -10
- package/lib/objects/merge/isMergeableObject.js.map +1 -1
- package/lib/objects/merge/merge.js +65 -66
- package/lib/objects/merge/merge.js.map +1 -1
- package/lib/objects/parseObjectPath.js +35 -23
- package/lib/objects/parseObjectPath.js.map +1 -1
- package/lib/objects/set.js +33 -34
- package/lib/objects/set.js.map +1 -1
- package/lib/schema/typebox/gen/codegen/common/encoder.js +100 -0
- package/lib/schema/typebox/gen/codegen/common/encoder.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/common/formatter.js +33 -0
- package/lib/schema/typebox/gen/codegen/common/formatter.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/common/index.js +5 -0
- package/lib/schema/typebox/gen/codegen/common/index.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/common/jsdoc.js +117 -0
- package/lib/schema/typebox/gen/codegen/common/jsdoc.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/compiler.js +367 -0
- package/lib/schema/typebox/gen/codegen/expression/compiler.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/errors.js +259 -0
- package/lib/schema/typebox/gen/codegen/expression/errors.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/evaluator.js +254 -0
- package/lib/schema/typebox/gen/codegen/expression/evaluator.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/expression.js +384 -0
- package/lib/schema/typebox/gen/codegen/expression/expression.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/index.js +6 -0
- package/lib/schema/typebox/gen/codegen/expression/index.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/index.js +5 -0
- package/lib/schema/typebox/gen/codegen/index.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/index.js +16 -0
- package/lib/schema/typebox/gen/codegen/model/index.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js +239 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-expression.js +359 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-expression.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js +217 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js +253 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js +47 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js +171 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js +33 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js +164 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js +218 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-value.js +43 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-value.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js +206 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yup.js +204 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yup.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-zod.js +227 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-zod.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model.js +27 -0
- package/lib/schema/typebox/gen/codegen/model/model.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/typescript/index.js +4 -0
- package/lib/schema/typebox/gen/codegen/typescript/index.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js +48 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js +596 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js.map +1 -0
- package/lib/schema/typebox/gen/index.js +3 -0
- package/lib/schema/typebox/gen/index.js.map +1 -0
- package/lib/schema/typebox/index.js +3 -0
- package/lib/schema/typebox/index.js.map +1 -0
- package/lib/schema/typebox/typebox.js +23 -0
- package/lib/schema/typebox/typebox.js.map +1 -0
- package/lib/server.js +2 -1
- package/lib/server.js.map +1 -1
- package/lib/servers/crypto/md5.js +3 -5
- package/lib/servers/crypto/md5.js.map +1 -1
- package/lib/servers/fetch/createFetchWithProxy.js +2 -4
- package/lib/servers/fetch/createFetchWithProxy.js.map +1 -1
- package/lib/servers/fetch/createFetchWithProxyByNodeFetch.js +34 -34
- package/lib/servers/fetch/createFetchWithProxyByNodeFetch.js.map +1 -1
- package/lib/servers/fetch/createFetchWithProxyByUndici.js +59 -45
- package/lib/servers/fetch/createFetchWithProxyByUndici.js.map +1 -1
- package/lib/servers/getPackageDir.js +8 -10
- package/lib/servers/getPackageDir.js.map +1 -1
- package/lib/servers/jsdom.js +3 -2
- package/lib/servers/jsdom.js.map +1 -1
- package/lib/servers/node-fetch.js +4 -3
- package/lib/servers/node-fetch.js.map +1 -1
- package/lib/servers/polyfill/polyfillBrowser.js +17 -0
- package/lib/servers/polyfill/polyfillBrowser.js.map +1 -0
- package/lib/servers/polyfill/polyfillCrypto.js +8 -10
- package/lib/servers/polyfill/polyfillCrypto.js.map +1 -1
- package/lib/servers/polyfill/polyfillFetch.js +23 -22
- package/lib/servers/polyfill/polyfillFetch.js.map +1 -1
- package/lib/servers/polyfill/polyfillJsDom.js +59 -52
- package/lib/servers/polyfill/polyfillJsDom.js.map +1 -1
- package/lib/servers/polyfill/polyfillWebSocket.js +13 -13
- package/lib/servers/polyfill/polyfillWebSocket.js.map +1 -1
- package/lib/servers/ws.js +3 -2
- package/lib/servers/ws.js.map +1 -1
- package/lib/strings/camelCase.js +51 -49
- package/lib/strings/camelCase.js.map +1 -1
- package/lib/strings/formatBytes.js +41 -15
- package/lib/strings/formatBytes.js.map +1 -1
- package/lib/strings/renderTemplate.js +27 -20
- package/lib/strings/renderTemplate.js.map +1 -1
- package/lib/typedoc.js +4 -0
- package/lib/typedoc.js.map +1 -0
- package/lib/types/global.d.js +2 -0
- package/lib/types/global.d.js.map +1 -0
- package/lib/types/index.d.js +6 -0
- package/lib/types/index.d.js.map +1 -0
- package/lib/validations/asserts.js +14 -0
- package/lib/validations/asserts.js.map +1 -0
- package/lib/validations/isUUID.js +3 -4
- package/lib/validations/isUUID.js.map +1 -1
- package/lib/validations/parseTimestamp.js +25 -21
- package/lib/validations/parseTimestamp.js.map +1 -1
- package/package.json +59 -44
- package/src/index.ts +3 -3
- package/src/langs/deepFreeze.ts +19 -0
- package/src/langs/hashCode.ignored.ts +125 -0
- package/src/libs/README.md +2 -0
- package/src/logging/slog.ts +121 -0
- package/src/maths/clamp.test.ts +19 -0
- package/src/maths/clamp.ts +23 -1
- package/src/objects/get.ts +14 -14
- package/src/objects/set.ts +5 -5
- package/src/schema/typebox/gen/codegen/common/encoder.ts +99 -0
- package/src/schema/typebox/gen/codegen/common/formatter.ts +31 -0
- package/src/schema/typebox/gen/codegen/common/index.ts +29 -0
- package/src/schema/typebox/gen/codegen/common/jsdoc.ts +93 -0
- package/src/schema/typebox/gen/codegen/expression/compiler.ts +377 -0
- package/src/schema/typebox/gen/codegen/expression/errors.ts +302 -0
- package/src/schema/typebox/gen/codegen/expression/evaluator.ts +268 -0
- package/src/schema/typebox/gen/codegen/expression/expression.ts +538 -0
- package/src/schema/typebox/gen/codegen/expression/index.ts +32 -0
- package/src/schema/typebox/gen/codegen/index.ts +29 -0
- package/src/schema/typebox/gen/codegen/model/index.ts +40 -0
- package/src/schema/typebox/gen/codegen/model/model-to-arktype.ts +266 -0
- package/src/schema/typebox/gen/codegen/model/model-to-expression.ts +378 -0
- package/src/schema/typebox/gen/codegen/model/model-to-grpc.ts +244 -0
- package/src/schema/typebox/gen/codegen/model/model-to-io-ts.ts +294 -0
- package/src/schema/typebox/gen/codegen/model/model-to-javascript.ts +42 -0
- package/src/schema/typebox/gen/codegen/model/model-to-json-schema.ts +166 -0
- package/src/schema/typebox/gen/codegen/model/model-to-typebox.ts +32 -0
- package/src/schema/typebox/gen/codegen/model/model-to-typescript.ts +189 -0
- package/src/schema/typebox/gen/codegen/model/model-to-valibot.ts +236 -0
- package/src/schema/typebox/gen/codegen/model/model-to-value.ts +42 -0
- package/src/schema/typebox/gen/codegen/model/model-to-yrel.ts +232 -0
- package/src/schema/typebox/gen/codegen/model/model-to-yup.ts +226 -0
- package/src/schema/typebox/gen/codegen/model/model-to-zod.ts +251 -0
- package/src/schema/typebox/gen/codegen/model/model.ts +33 -0
- package/src/schema/typebox/gen/codegen/typescript/index.ts +28 -0
- package/src/schema/typebox/gen/codegen/typescript/typescript-to-model.ts +61 -0
- package/src/schema/typebox/gen/codegen/typescript/typescript-to-typebox.ts +647 -0
- package/src/schema/typebox/gen/gen.test.ts +12 -0
- package/src/schema/typebox/gen/index.ts +1 -0
- package/src/schema/typebox/index.ts +1 -0
- package/src/schema/typebox/typebox.ts +34 -0
- package/src/servers/fetch/createFetchWithProxyByUndici.ts +16 -1
- package/src/types/index.d.ts +1 -0
- package/dist/LICENSE.txt +0 -1
- package/dist/cjs/getGlobalThis-304f74e0.js +0 -2
- package/dist/cjs/getGlobalThis-304f74e0.js.map +0 -1
- package/dist/cjs/index.cjs +0 -21
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/server.cjs +0 -2
- package/dist/cjs/server.cjs.map +0 -1
- package/dist/cjs/servers/jsdom.cjs +0 -2
- package/dist/cjs/servers/jsdom.cjs.map +0 -1
- package/dist/cjs/servers/node-fetch.cjs +0 -2
- package/dist/cjs/servers/node-fetch.cjs.map +0 -1
- package/dist/cjs/servers/ws.cjs +0 -2
- package/dist/cjs/servers/ws.cjs.map +0 -1
- package/dist/esm/getGlobalThis-b7ad0cf9.js +0 -2
- package/dist/esm/getGlobalThis-b7ad0cf9.js.map +0 -1
- package/dist/esm/index.js +0 -21
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/server.js +0 -2
- package/dist/esm/server.js.map +0 -1
- package/dist/esm/servers/jsdom.js +0 -2
- package/dist/esm/servers/jsdom.js.map +0 -1
- package/dist/esm/servers/node-fetch.js +0 -2
- package/dist/esm/servers/node-fetch.js.map +0 -1
- package/dist/esm/servers/ws.js +0 -2
- package/dist/esm/servers/ws.js.map +0 -1
- package/dist/system/getGlobalThis-8951eb0e.js +0 -2
- package/dist/system/getGlobalThis-8951eb0e.js.map +0 -1
- package/dist/system/index.js +0 -21
- package/dist/system/index.js.map +0 -1
- package/dist/system/server.js +0 -2
- package/dist/system/server.js.map +0 -1
- package/dist/system/servers/jsdom.js +0 -2
- package/dist/system/servers/jsdom.js.map +0 -1
- package/dist/system/servers/node-fetch.js +0 -2
- package/dist/system/servers/node-fetch.js.map +0 -1
- package/dist/system/servers/ws.js +0 -2
- package/dist/system/servers/ws.js.map +0 -1
- package/src/langs/hashCode.ts +0 -37
package/lib/asyncs/timeout.js
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
function timeout(v, ms) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw e;
|
|
19
|
-
}
|
|
20
|
-
);
|
|
1
|
+
export function timeout(v, ms) {
|
|
2
|
+
const error = new TimeoutError();
|
|
3
|
+
let timeout;
|
|
4
|
+
return Promise.race([
|
|
5
|
+
v,
|
|
6
|
+
new Promise((_resolve, reject)=>{
|
|
7
|
+
timeout = setTimeout(()=>{
|
|
8
|
+
reject(error);
|
|
9
|
+
}, ms);
|
|
10
|
+
})
|
|
11
|
+
]).then((v)=>{
|
|
12
|
+
clearTimeout(timeout);
|
|
13
|
+
return v;
|
|
14
|
+
}, (e)=>{
|
|
15
|
+
clearTimeout(timeout);
|
|
16
|
+
throw e;
|
|
17
|
+
});
|
|
21
18
|
}
|
|
22
|
-
class TimeoutError extends Error {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
export class TimeoutError extends Error {
|
|
20
|
+
constructor(){
|
|
21
|
+
super('TimeoutError');
|
|
22
|
+
}
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=timeout.js.map
|
|
25
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/asyncs/timeout.ts"],"sourcesContent":["export function timeout<T = any>(v: Promise<T>, ms: number): Promise<T> {\n const error = new TimeoutError();\n let timeout: any;\n return Promise.race([\n v,\n new Promise((_resolve, reject) => {\n timeout = setTimeout(() => {\n reject(error);\n }, ms);\n }),\n ]).then(\n (v) => {\n clearTimeout(timeout);\n return v;\n },\n (e) => {\n clearTimeout(timeout);\n throw e;\n },\n ) as Promise<T>;\n}\n\nexport class TimeoutError extends Error {\n constructor() {\n super('TimeoutError');\n }\n}\n"],"names":["timeout","v","ms","error","TimeoutError","Promise","race","_resolve","reject","setTimeout","then","clearTimeout","e","Error","constructor"],"mappings":"AAAA,OAAO,SAASA,QAAiBC,CAAa,EAAEC,EAAU;IACxD,MAAMC,QAAQ,IAAIC;IAClB,IAAIJ;IACJ,OAAOK,QAAQC,IAAI,CAAC;QAClBL;QACA,IAAII,QAAQ,CAACE,UAAUC;YACrBR,UAAUS,WAAW;gBACnBD,OAAOL;YACT,GAAGD;QACL;KACD,EAAEQ,IAAI,CACL,CAACT;QACCU,aAAaX;QACb,OAAOC;IACT,GACA,CAACW;QACCD,aAAaX;QACb,MAAMY;IACR;AAEJ;AAEA,OAAO,MAAMR,qBAAqBS;IAChCC,aAAc;QACZ,KAAK,CAAC;IACR;AACF"}
|
package/lib/browsers/copy.js
CHANGED
|
@@ -1,51 +1,53 @@
|
|
|
1
1
|
let _copy;
|
|
2
|
+
// https://gist.github.com/rproenca/64781c6a1329b48a455b645d361a9aa3
|
|
2
3
|
function initCopy() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
function createTextArea(text) {
|
|
8
|
-
textArea = document.createElement("textArea");
|
|
9
|
-
textArea.value = text;
|
|
10
|
-
document.body.appendChild(textArea);
|
|
11
|
-
}
|
|
12
|
-
function selectText() {
|
|
13
|
-
let range, selection;
|
|
14
|
-
if (isIOS()) {
|
|
15
|
-
range = document.createRange();
|
|
16
|
-
range.selectNodeContents(textArea);
|
|
17
|
-
selection = window.getSelection();
|
|
18
|
-
if (selection === null) {
|
|
19
|
-
console.error(`no selection`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
selection.removeAllRanges();
|
|
23
|
-
selection.addRange(range);
|
|
24
|
-
textArea.setSelectionRange(0, 999999);
|
|
25
|
-
} else {
|
|
26
|
-
textArea.select();
|
|
4
|
+
let textArea;
|
|
5
|
+
function isIOS() {
|
|
6
|
+
return navigator.userAgent.match(/ipad|iphone/i);
|
|
27
7
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
8
|
+
function createTextArea(text) {
|
|
9
|
+
textArea = document.createElement('textArea');
|
|
10
|
+
textArea.value = text;
|
|
11
|
+
document.body.appendChild(textArea);
|
|
12
|
+
}
|
|
13
|
+
function selectText() {
|
|
14
|
+
let range, selection;
|
|
15
|
+
if (isIOS()) {
|
|
16
|
+
range = document.createRange();
|
|
17
|
+
range.selectNodeContents(textArea);
|
|
18
|
+
selection = window.getSelection();
|
|
19
|
+
if (selection === null) {
|
|
20
|
+
console.error(`no selection`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
selection.removeAllRanges();
|
|
24
|
+
selection.addRange(range);
|
|
25
|
+
textArea.setSelectionRange(0, 999999);
|
|
26
|
+
} else {
|
|
27
|
+
textArea.select();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function copyToClipboard() {
|
|
31
|
+
document.execCommand('copy');
|
|
32
|
+
document.body.removeChild(textArea);
|
|
33
|
+
}
|
|
34
|
+
_copy = (text)=>{
|
|
35
|
+
createTextArea(text);
|
|
36
|
+
selectText();
|
|
37
|
+
copyToClipboard();
|
|
38
|
+
};
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Write text to clipboard
|
|
42
|
+
* @param content content
|
|
43
|
+
*/ export function copy(content) {
|
|
44
|
+
if (window.navigator?.clipboard?.writeText) {
|
|
45
|
+
return window.navigator.clipboard.writeText(content);
|
|
46
|
+
}
|
|
47
|
+
if (!_copy) {
|
|
48
|
+
initCopy();
|
|
49
|
+
}
|
|
50
|
+
return _copy(content);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=copy.js.map
|
|
53
|
+
//# sourceMappingURL=copy.js.map
|
package/lib/browsers/copy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/browsers/copy.ts"],"sourcesContent":["import type { MaybePromise } from '../asyncs/MaybePromise';\n\nlet _copy: (s: any) => MaybePromise<void>;\n\n// https://gist.github.com/rproenca/64781c6a1329b48a455b645d361a9aa3\nfunction initCopy() {\n let textArea: HTMLTextAreaElement;\n\n function isIOS() {\n return navigator.userAgent.match(/ipad|iphone/i);\n }\n\n function createTextArea(text: string) {\n textArea = document.createElement('textArea') as HTMLTextAreaElement;\n textArea.value = text;\n document.body.appendChild(textArea);\n }\n\n function selectText() {\n let range, selection;\n\n if (isIOS()) {\n range = document.createRange();\n range.selectNodeContents(textArea);\n selection = window.getSelection();\n if (selection === null) {\n console.error(`no selection`);\n return;\n }\n selection.removeAllRanges();\n selection.addRange(range);\n textArea.setSelectionRange(0, 999999);\n } else {\n textArea.select();\n }\n }\n\n function copyToClipboard() {\n document.execCommand('copy');\n document.body.removeChild(textArea);\n }\n\n _copy = (text) => {\n createTextArea(text);\n selectText();\n copyToClipboard();\n };\n}\n\n/**\n * Write text to clipboard\n * @param content content\n */\nexport function copy(content: string): MaybePromise<void> {\n if (window.navigator?.clipboard?.writeText) {\n return window.navigator.clipboard.writeText(content);\n }\n if (!_copy) {\n initCopy();\n }\n return _copy(content);\n}\n"],"names":["_copy","initCopy","textArea","isIOS","navigator","userAgent","match","createTextArea","text","document","createElement","value","body","appendChild","selectText","range","selection","createRange","selectNodeContents","window","getSelection","console","error","removeAllRanges","addRange","setSelectionRange","select","copyToClipboard","execCommand","removeChild","copy","content","clipboard","writeText"],"mappings":"AAEA,IAAIA;AAEJ,oEAAoE;AACpE,SAASC;IACP,IAAIC;IAEJ,SAASC;QACP,OAAOC,UAAUC,SAAS,CAACC,KAAK,CAAC;IACnC;IAEA,SAASC,eAAeC,IAAY;QAClCN,WAAWO,SAASC,aAAa,CAAC;QAClCR,SAASS,KAAK,GAAGH;QACjBC,SAASG,IAAI,CAACC,WAAW,CAACX;IAC5B;IAEA,SAASY;QACP,IAAIC,OAAOC;QAEX,IAAIb,SAAS;YACXY,QAAQN,SAASQ,WAAW;YAC5BF,MAAMG,kBAAkB,CAAChB;YACzBc,YAAYG,OAAOC,YAAY;YAC/B,IAAIJ,cAAc,MAAM;gBACtBK,QAAQC,KAAK,CAAC,CAAC,YAAY,CAAC;gBAC5B;YACF;YACAN,UAAUO,eAAe;YACzBP,UAAUQ,QAAQ,CAACT;YACnBb,SAASuB,iBAAiB,CAAC,GAAG;QAChC,OAAO;YACLvB,SAASwB,MAAM;QACjB;IACF;IAEA,SAASC;QACPlB,SAASmB,WAAW,CAAC;QACrBnB,SAASG,IAAI,CAACiB,WAAW,CAAC3B;IAC5B;IAEAF,QAAQ,CAACQ;QACPD,eAAeC;QACfM;QACAa;IACF;AACF;AAEA;;;CAGC,GACD,OAAO,SAASG,KAAKC,OAAe;IAClC,IAAIZ,OAAOf,SAAS,EAAE4B,WAAWC,WAAW;QAC1C,OAAOd,OAAOf,SAAS,CAAC4B,SAAS,CAACC,SAAS,CAACF;IAC9C;IACA,IAAI,CAAC/B,OAAO;QACVC;IACF;IACA,OAAOD,MAAM+B;AACf"}
|
package/lib/browsers/download.js
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Trigger browser download
|
|
3
|
+
* @param filename download as filename
|
|
4
|
+
* @param data data or url to download
|
|
5
|
+
* @param type content type
|
|
6
|
+
* @param raw if true, data is treated as raw data, not url
|
|
7
|
+
*/ export function download(filename, data, { type = 'application/octet-stream', raw = false } = {}) {
|
|
8
|
+
const a = document.createElement('a');
|
|
9
|
+
let closer = ()=>null;
|
|
10
|
+
try {
|
|
11
|
+
a.download = filename;
|
|
12
|
+
// console.info(`downloading ${name}`, data);
|
|
13
|
+
// url or data url
|
|
14
|
+
if (typeof data === 'string' && /^(https?:|data:)/.test(data) && !raw) {
|
|
15
|
+
a.href = data;
|
|
16
|
+
} else if (typeof data === 'string') {
|
|
17
|
+
data = new TextEncoder().encode(data);
|
|
18
|
+
}
|
|
19
|
+
if (data instanceof Uint8Array) {
|
|
20
|
+
data = new Blob([
|
|
21
|
+
data
|
|
22
|
+
], {
|
|
23
|
+
type
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
|
|
27
|
+
a.href = URL.createObjectURL(data);
|
|
28
|
+
closer = ()=>{
|
|
29
|
+
URL.revokeObjectURL(a.href);
|
|
30
|
+
};
|
|
31
|
+
} else {
|
|
32
|
+
console.error(`invalid download data`, data);
|
|
33
|
+
throw new Error(`can not download ${Object.getPrototypeOf(data)}`);
|
|
34
|
+
}
|
|
35
|
+
a.click();
|
|
36
|
+
} finally{
|
|
37
|
+
closer();
|
|
10
38
|
}
|
|
11
|
-
if (data instanceof Uint8Array) {
|
|
12
|
-
data = new Blob([data], { type });
|
|
13
|
-
}
|
|
14
|
-
if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
|
|
15
|
-
a.href = URL.createObjectURL(data);
|
|
16
|
-
closer = () => {
|
|
17
|
-
URL.revokeObjectURL(a.href);
|
|
18
|
-
};
|
|
19
|
-
} else {
|
|
20
|
-
console.error(`invalid download data`, data);
|
|
21
|
-
throw new Error(`can not download ${Object.getPrototypeOf(data)}`);
|
|
22
|
-
}
|
|
23
|
-
a.click();
|
|
24
|
-
} finally {
|
|
25
|
-
closer();
|
|
26
|
-
}
|
|
27
39
|
}
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=download.js.map
|
|
41
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/browsers/download.ts"],"sourcesContent":["/**\n * Trigger browser download\n * @param filename download as filename\n * @param data data or url to download\n * @param type content type\n * @param raw if true, data is treated as raw data, not url\n */\nexport function download(filename: string, data: any, { type = 'application/octet-stream', raw = false } = {}) {\n const a = document.createElement('a');\n let closer: () => void = () => null;\n try {\n a.download = filename;\n\n // console.info(`downloading ${name}`, data);\n\n // url or data url\n if (typeof data === 'string' && /^(https?:|data:)/.test(data) && !raw) {\n a.href = data;\n } else if (typeof data === 'string') {\n data = new TextEncoder().encode(data);\n }\n\n if (data instanceof Uint8Array) {\n data = new Blob([data], { type });\n }\n\n if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {\n a.href = URL.createObjectURL(data);\n closer = () => {\n URL.revokeObjectURL(a.href);\n };\n } else {\n console.error(`invalid download data`, data);\n throw new Error(`can not download ${Object.getPrototypeOf(data)}`);\n }\n a.click();\n } finally {\n closer();\n }\n}\n"],"names":["download","filename","data","type","raw","a","document","createElement","closer","test","href","TextEncoder","encode","Uint8Array","Blob","File","MediaSource","URL","createObjectURL","revokeObjectURL","console","error","Error","Object","getPrototypeOf","click"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,SAASC,QAAgB,EAAEC,IAAS,EAAE,EAAEC,OAAO,0BAA0B,EAAEC,MAAM,KAAK,EAAE,GAAG,CAAC,CAAC;IAC3G,MAAMC,IAAIC,SAASC,aAAa,CAAC;IACjC,IAAIC,SAAqB,IAAM;IAC/B,IAAI;QACFH,EAAEL,QAAQ,GAAGC;QAEb,6CAA6C;QAE7C,kBAAkB;QAClB,IAAI,OAAOC,SAAS,YAAY,mBAAmBO,IAAI,CAACP,SAAS,CAACE,KAAK;YACrEC,EAAEK,IAAI,GAAGR;QACX,OAAO,IAAI,OAAOA,SAAS,UAAU;YACnCA,OAAO,IAAIS,cAAcC,MAAM,CAACV;QAClC;QAEA,IAAIA,gBAAgBW,YAAY;YAC9BX,OAAO,IAAIY,KAAK;gBAACZ;aAAK,EAAE;gBAAEC;YAAK;QACjC;QAEA,IAAID,gBAAgBa,QAAQb,gBAAgBY,QAAQZ,gBAAgBc,aAAa;YAC/EX,EAAEK,IAAI,GAAGO,IAAIC,eAAe,CAAChB;YAC7BM,SAAS;gBACPS,IAAIE,eAAe,CAACd,EAAEK,IAAI;YAC5B;QACF,OAAO;YACLU,QAAQC,KAAK,CAAC,CAAC,qBAAqB,CAAC,EAAEnB;YACvC,MAAM,IAAIoB,MAAM,CAAC,iBAAiB,EAAEC,OAAOC,cAAc,CAACtB,MAAM,CAAC;QACnE;QACAG,EAAEoB,KAAK;IACT,SAAU;QACRjB;IACF;AACF"}
|
|
@@ -1,32 +1,45 @@
|
|
|
1
|
-
function getFileFromDataTransfer(dataTransfer) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return {};
|
|
5
|
-
}
|
|
6
|
-
const items = (_a = dataTransfer.items) != null ? _a : [];
|
|
7
|
-
if (items.length >= 2 && items[0].kind === "string" && items[1].kind === "file") {
|
|
8
|
-
const text = dataTransfer.getData("text");
|
|
9
|
-
const file = (_c = items[1].getAsFile()) != null ? _c : (_b = dataTransfer.files) == null ? void 0 : _b.item(0);
|
|
10
|
-
if (!file) {
|
|
11
|
-
console.error(`no file ${text}`, items[1]);
|
|
12
|
-
return {};
|
|
1
|
+
export function getFileFromDataTransfer(dataTransfer) {
|
|
2
|
+
if (!dataTransfer) {
|
|
3
|
+
return {};
|
|
13
4
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
const items = dataTransfer.items ?? [];
|
|
6
|
+
if (items.length >= 2 && items[0].kind === 'string' && items[1].kind === 'file') {
|
|
7
|
+
// name, file
|
|
8
|
+
const text = dataTransfer.getData('text');
|
|
9
|
+
const file = items[1].getAsFile() ?? dataTransfer.files?.item(0);
|
|
10
|
+
if (!file) {
|
|
11
|
+
console.error(`no file ${text}`, items[1]);
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
// let type = file.type;
|
|
15
|
+
// // fix type
|
|
16
|
+
// type = type;
|
|
17
|
+
// // NOTE paste file can not parse by libs
|
|
18
|
+
// if (type !== file.type) {
|
|
19
|
+
// const blob = file.slice(0, file.size);
|
|
20
|
+
// file = new File([blob], text, {type});
|
|
21
|
+
// }
|
|
22
|
+
return {
|
|
23
|
+
file,
|
|
24
|
+
name: text
|
|
25
|
+
};
|
|
26
|
+
} else if (items[0].kind === 'file') {
|
|
27
|
+
const file = items[0].getAsFile();
|
|
28
|
+
if (!file) {
|
|
29
|
+
console.error(`no file`, items[0]);
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
file,
|
|
34
|
+
name: file.name
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
console.debug(`file item not match`, Array.from(items).map((v)=>({
|
|
38
|
+
type: v.type,
|
|
39
|
+
kind: v.kind
|
|
40
|
+
})));
|
|
20
41
|
}
|
|
21
|
-
return {
|
|
22
|
-
} else {
|
|
23
|
-
console.debug(
|
|
24
|
-
`file item not match`,
|
|
25
|
-
Array.from(items).map((v) => ({ type: v.type, kind: v.kind }))
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return {};
|
|
42
|
+
return {};
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=getFileFromDataTransfer.js.map
|
|
45
|
+
//# sourceMappingURL=getFileFromDataTransfer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/browsers/getFileFromDataTransfer.ts"],"sourcesContent":["export function getFileFromDataTransfer(dataTransfer?: DataTransfer | null): { file?: File; name?: string } {\n if (!dataTransfer) {\n return {};\n }\n\n const items: DataTransferItemList = dataTransfer.items ?? [];\n\n if (items.length >= 2 && items[0].kind === 'string' && items[1].kind === 'file') {\n // name, file\n const text = dataTransfer.getData('text');\n const file = items[1].getAsFile() ?? dataTransfer.files?.item(0);\n if (!file) {\n console.error(`no file ${text}`, items[1]);\n return {};\n }\n\n // let type = file.type;\n // // fix type\n // type = type;\n // // NOTE paste file can not parse by libs\n // if (type !== file.type) {\n // const blob = file.slice(0, file.size);\n // file = new File([blob], text, {type});\n // }\n\n return { file, name: text };\n } else if (items[0].kind === 'file') {\n const file = items[0].getAsFile();\n if (!file) {\n console.error(`no file`, items[0]);\n return {};\n }\n return { file, name: file.name };\n } else {\n console.debug(\n `file item not match`,\n Array.from(items).map((v) => ({ type: v.type, kind: v.kind })),\n );\n }\n return {};\n}\n"],"names":["getFileFromDataTransfer","dataTransfer","items","length","kind","text","getData","file","getAsFile","files","item","console","error","name","debug","Array","from","map","v","type"],"mappings":"AAAA,OAAO,SAASA,wBAAwBC,YAAkC;IACxE,IAAI,CAACA,cAAc;QACjB,OAAO,CAAC;IACV;IAEA,MAAMC,QAA8BD,aAAaC,KAAK,IAAI,EAAE;IAE5D,IAAIA,MAAMC,MAAM,IAAI,KAAKD,KAAK,CAAC,EAAE,CAACE,IAAI,KAAK,YAAYF,KAAK,CAAC,EAAE,CAACE,IAAI,KAAK,QAAQ;QAC/E,aAAa;QACb,MAAMC,OAAOJ,aAAaK,OAAO,CAAC;QAClC,MAAMC,OAAOL,KAAK,CAAC,EAAE,CAACM,SAAS,MAAMP,aAAaQ,KAAK,EAAEC,KAAK;QAC9D,IAAI,CAACH,MAAM;YACTI,QAAQC,KAAK,CAAC,CAAC,QAAQ,EAAEP,KAAK,CAAC,EAAEH,KAAK,CAAC,EAAE;YACzC,OAAO,CAAC;QACV;QAEA,wBAAwB;QACxB,cAAc;QACd,eAAe;QACf,2CAA2C;QAC3C,4BAA4B;QAC5B,2CAA2C;QAC3C,2CAA2C;QAC3C,IAAI;QAEJ,OAAO;YAAEK;YAAMM,MAAMR;QAAK;IAC5B,OAAO,IAAIH,KAAK,CAAC,EAAE,CAACE,IAAI,KAAK,QAAQ;QACnC,MAAMG,OAAOL,KAAK,CAAC,EAAE,CAACM,SAAS;QAC/B,IAAI,CAACD,MAAM;YACTI,QAAQC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAEV,KAAK,CAAC,EAAE;YACjC,OAAO,CAAC;QACV;QACA,OAAO;YAAEK;YAAMM,MAAMN,KAAKM,IAAI;QAAC;IACjC,OAAO;QACLF,QAAQG,KAAK,CACX,CAAC,mBAAmB,CAAC,EACrBC,MAAMC,IAAI,CAACd,OAAOe,GAAG,CAAC,CAACC,IAAO,CAAA;gBAAEC,MAAMD,EAAEC,IAAI;gBAAEf,MAAMc,EAAEd,IAAI;YAAC,CAAA;IAE/D;IACA,OAAO,CAAC;AACV"}
|
package/lib/browsers/loaders.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
function load(el, resolve, reject, options) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
el.onload = ()=>{
|
|
3
|
+
resolve(el);
|
|
4
|
+
};
|
|
5
|
+
el.onerror = (e)=>{
|
|
6
|
+
el.remove();
|
|
7
|
+
reject(e);
|
|
8
|
+
};
|
|
9
|
+
const { attributes = {} } = options || {};
|
|
10
|
+
Object.entries(attributes).forEach(([k, v])=>{
|
|
11
|
+
el.setAttribute(k, v);
|
|
12
|
+
});
|
|
13
|
+
document.head.appendChild(el);
|
|
14
14
|
}
|
|
15
|
-
function loadScripts(src, options) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
export function loadScripts(src, options) {
|
|
16
|
+
if (Array.isArray(src)) {
|
|
17
|
+
return Promise.resolve().then(async ()=>{
|
|
18
|
+
const all = [];
|
|
19
|
+
for (const s of src){
|
|
20
|
+
all.push(await loadScripts(s));
|
|
21
|
+
}
|
|
22
|
+
return all;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// todo quote ?
|
|
26
|
+
const $ele = document.querySelector(`script[src="${src}"]`);
|
|
27
|
+
if ($ele) {
|
|
28
|
+
return Promise.resolve($ele);
|
|
29
|
+
}
|
|
30
|
+
return new Promise((resolve, reject)=>{
|
|
31
|
+
const el = document.createElement('script');
|
|
32
|
+
el.src = src;
|
|
33
|
+
load(el, resolve, reject, options);
|
|
23
34
|
});
|
|
24
|
-
}
|
|
25
|
-
const $ele = document.querySelector(`script[src="${src}"]`);
|
|
26
|
-
if ($ele) {
|
|
27
|
-
return Promise.resolve($ele);
|
|
28
|
-
}
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
const el = document.createElement("script");
|
|
31
|
-
el.src = src;
|
|
32
|
-
load(el, resolve, reject, options);
|
|
33
|
-
});
|
|
34
35
|
}
|
|
35
|
-
function loadStyles(href, options) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
export function loadStyles(href, options) {
|
|
37
|
+
const $ele = document.querySelector(`link[href="${href}"]`);
|
|
38
|
+
if ($ele) {
|
|
39
|
+
return Promise.resolve($ele);
|
|
40
|
+
}
|
|
41
|
+
return new Promise((resolve, reject)=>{
|
|
42
|
+
const el = document.createElement('link');
|
|
43
|
+
el.rel = 'stylesheet';
|
|
44
|
+
el.href = href;
|
|
45
|
+
load(el, resolve, reject, options);
|
|
46
|
+
});
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=loaders.js.map
|
|
49
|
+
//# sourceMappingURL=loaders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/browsers/loaders.ts"],"sourcesContent":["function load(\n el: HTMLScriptElement | HTMLLinkElement,\n resolve: (v: any) => void,\n reject: (v: any) => void,\n options: { attributes: Record<string, string> } | undefined,\n) {\n el.onload = () => {\n resolve(el);\n };\n el.onerror = (e) => {\n el.remove();\n reject(e);\n };\n const { attributes = {} } = options || {};\n Object.entries(attributes).forEach(([k, v]) => {\n el.setAttribute(k, v);\n });\n\n document.head.appendChild(el);\n}\n\nexport function loadScripts(\n src: string[],\n options?: { attributes: Record<string, string> },\n): Promise<HTMLScriptElement[]>;\nexport function loadScripts(src: string, options?: { attributes: Record<string, string> }): Promise<HTMLScriptElement>;\n\nexport function loadScripts(\n src: string | string[],\n options?: { attributes: Record<string, string> },\n): Promise<HTMLScriptElement | HTMLScriptElement[]> {\n if (Array.isArray(src)) {\n return Promise.resolve().then(async () => {\n const all = [];\n for (const s of src) {\n all.push(await loadScripts(s));\n }\n return all;\n });\n }\n // todo quote ?\n const $ele = document.querySelector(`script[src=\"${src}\"]`) as HTMLScriptElement;\n if ($ele) {\n return Promise.resolve($ele);\n }\n return new Promise((resolve, reject) => {\n const el = document.createElement('script');\n el.src = src;\n load(el, resolve, reject, options);\n });\n}\n\nexport function loadStyles(href: string, options?: { attributes: Record<string, string> }): Promise<HTMLLinkElement> {\n const $ele = document.querySelector(`link[href=\"${href}\"]`) as HTMLLinkElement;\n if ($ele) {\n return Promise.resolve($ele);\n }\n\n return new Promise((resolve, reject) => {\n const el = document.createElement('link');\n el.rel = 'stylesheet';\n el.href = href;\n load(el, resolve, reject, options);\n });\n}\n"],"names":["load","el","resolve","reject","options","onload","onerror","e","remove","attributes","Object","entries","forEach","k","v","setAttribute","document","head","appendChild","loadScripts","src","Array","isArray","Promise","then","all","s","push","$ele","querySelector","createElement","loadStyles","href","rel"],"mappings":"AAAA,SAASA,KACPC,EAAuC,EACvCC,OAAyB,EACzBC,MAAwB,EACxBC,OAA2D;IAE3DH,GAAGI,MAAM,GAAG;QACVH,QAAQD;IACV;IACAA,GAAGK,OAAO,GAAG,CAACC;QACZN,GAAGO,MAAM;QACTL,OAAOI;IACT;IACA,MAAM,EAAEE,aAAa,CAAC,CAAC,EAAE,GAAGL,WAAW,CAAC;IACxCM,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,GAAGC,EAAE;QACxCb,GAAGc,YAAY,CAACF,GAAGC;IACrB;IAEAE,SAASC,IAAI,CAACC,WAAW,CAACjB;AAC5B;AAQA,OAAO,SAASkB,YACdC,GAAsB,EACtBhB,OAAgD;IAEhD,IAAIiB,MAAMC,OAAO,CAACF,MAAM;QACtB,OAAOG,QAAQrB,OAAO,GAAGsB,IAAI,CAAC;YAC5B,MAAMC,MAAM,EAAE;YACd,KAAK,MAAMC,KAAKN,IAAK;gBACnBK,IAAIE,IAAI,CAAC,MAAMR,YAAYO;YAC7B;YACA,OAAOD;QACT;IACF;IACA,eAAe;IACf,MAAMG,OAAOZ,SAASa,aAAa,CAAC,CAAC,YAAY,EAAET,IAAI,EAAE,CAAC;IAC1D,IAAIQ,MAAM;QACR,OAAOL,QAAQrB,OAAO,CAAC0B;IACzB;IACA,OAAO,IAAIL,QAAQ,CAACrB,SAASC;QAC3B,MAAMF,KAAKe,SAASc,aAAa,CAAC;QAClC7B,GAAGmB,GAAG,GAAGA;QACTpB,KAAKC,IAAIC,SAASC,QAAQC;IAC5B;AACF;AAEA,OAAO,SAAS2B,WAAWC,IAAY,EAAE5B,OAAgD;IACvF,MAAMwB,OAAOZ,SAASa,aAAa,CAAC,CAAC,WAAW,EAAEG,KAAK,EAAE,CAAC;IAC1D,IAAIJ,MAAM;QACR,OAAOL,QAAQrB,OAAO,CAAC0B;IACzB;IAEA,OAAO,IAAIL,QAAQ,CAACrB,SAASC;QAC3B,MAAMF,KAAKe,SAASc,aAAa,CAAC;QAClC7B,GAAGgC,GAAG,GAAG;QACThC,GAAG+B,IAAI,GAAGA;QACVhC,KAAKC,IAAIC,SAASC,QAAQC;IAC5B;AACF"}
|
package/lib/crypto/base.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* hex string
|
|
3
|
+
*/ export function hex(s) {
|
|
4
|
+
return Array.from(new Uint8Array(s)).map((v)=>v.toString(16).padStart(2, '0')).join('');
|
|
3
5
|
}
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=base.js.map
|
|
7
|
+
//# sourceMappingURL=base.js.map
|
package/lib/crypto/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/crypto/base.ts"],"sourcesContent":["/**\n * hex string\n */\nexport function hex(s: Uint8Array | ArrayBuffer) {\n return Array.from(new Uint8Array(s))\n .map((v) => v.toString(16).padStart(2, '0'))\n .join('');\n}\n"],"names":["hex","s","Array","from","Uint8Array","map","v","toString","padStart","join"],"mappings":"AAAA;;CAEC,GACD,OAAO,SAASA,IAAIC,CAA2B;IAC7C,OAAOC,MAAMC,IAAI,CAAC,IAAIC,WAAWH,IAC9BI,GAAG,CAAC,CAACC,IAAMA,EAAEC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MACtCC,IAAI,CAAC;AACV"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
let nodeCrypto;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
// globalThis.process?.release?.name
|
|
3
|
+
// avoid process.browser
|
|
4
|
+
if (typeof window === 'undefined') {
|
|
5
|
+
try {
|
|
6
|
+
// avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774
|
|
7
|
+
if (typeof require === 'undefined') {
|
|
8
|
+
void import('crypto').then((v)=>nodeCrypto = v.default);
|
|
9
|
+
} else {
|
|
10
|
+
nodeCrypto = require('crypto');
|
|
11
|
+
}
|
|
12
|
+
} catch (e) {}
|
|
11
13
|
}
|
|
12
|
-
function getNodeCrypto() {
|
|
13
|
-
|
|
14
|
+
export function getNodeCrypto() {
|
|
15
|
+
return nodeCrypto;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=getNodeCrypto.js.map
|
|
18
|
+
//# sourceMappingURL=getNodeCrypto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/crypto/getNodeCrypto.ts"],"sourcesContent":["let nodeCrypto: Awaited<typeof import('node:crypto')>;\n// globalThis.process?.release?.name\n\n// avoid process.browser\nif (typeof window === 'undefined') {\n try {\n // avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774\n if (typeof require === 'undefined') {\n void import('crypto').then((v) => (nodeCrypto = v.default));\n } else {\n nodeCrypto = require('crypto');\n }\n } catch (e) {}\n}\nexport function getNodeCrypto() {\n return nodeCrypto;\n}\n"],"names":["nodeCrypto","window","require","then","v","default","e","getNodeCrypto"],"mappings":"AAAA,IAAIA;AACJ,oCAAoC;AAEpC,wBAAwB;AACxB,IAAI,OAAOC,WAAW,aAAa;IACjC,IAAI;QACF,oFAAoF;QACpF,IAAI,OAAOC,YAAY,aAAa;YAClC,KAAK,MAAM,CAAC,UAAUC,IAAI,CAAC,CAACC,IAAOJ,aAAaI,EAAEC,OAAO;QAC3D,OAAO;YACLL,aAAaE,QAAQ;QACvB;IACF,EAAE,OAAOI,GAAG,CAAC;AACf;AACA,OAAO,SAASC;IACd,OAAOP;AACT"}
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { getGlobalThis } from '../isomorphics/getGlobalThis.js';
|
|
2
|
-
import { getNodeCrypto } from './getNodeCrypto
|
|
3
|
-
|
|
4
|
-
var _a, _b, _c, _d;
|
|
2
|
+
import { getNodeCrypto } from './getNodeCrypto';
|
|
5
3
|
const globalThis = getGlobalThis();
|
|
6
|
-
let getRandomValues =
|
|
4
|
+
export let getRandomValues = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) || globalThis.msCrypto?.getRandomValues?.bind(globalThis.msCrypto) || _getRandomValues;
|
|
7
5
|
function _getRandomValues(buf) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return nodeCrypto.webcrypto.getRandomValues(buf);
|
|
13
|
-
}
|
|
14
|
-
if (nodeCrypto == null ? void 0 : nodeCrypto.randomBytes) {
|
|
15
|
-
if (!(buf instanceof Uint8Array)) {
|
|
16
|
-
throw new TypeError("expected Uint8Array");
|
|
6
|
+
const nodeCrypto = getNodeCrypto();
|
|
7
|
+
if (nodeCrypto?.webcrypto?.getRandomValues) {
|
|
8
|
+
getRandomValues = nodeCrypto?.webcrypto?.getRandomValues?.bind(nodeCrypto?.webcrypto);
|
|
9
|
+
return nodeCrypto.webcrypto.getRandomValues(buf);
|
|
17
10
|
}
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
if (nodeCrypto?.randomBytes) {
|
|
12
|
+
if (!(buf instanceof Uint8Array)) {
|
|
13
|
+
throw new TypeError('expected Uint8Array');
|
|
14
|
+
}
|
|
15
|
+
if (buf.length > 65536) {
|
|
16
|
+
const e = new Error();
|
|
17
|
+
e.code = 22;
|
|
18
|
+
e.message = `Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (${buf.length}) exceeds the number of bytes of entropy available via this API (65536).`;
|
|
19
|
+
e.name = 'QuotaExceededError';
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
22
|
+
const bytes = nodeCrypto.randomBytes(buf.length);
|
|
23
|
+
buf.set(bytes);
|
|
24
|
+
return buf;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
buf.set(bytes);
|
|
27
|
-
return buf;
|
|
28
|
-
}
|
|
29
|
-
throw new Error("[getRandomValues]: No secure random number generator available.");
|
|
26
|
+
throw new Error('[getRandomValues]: No secure random number generator available.');
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=getRandomValues.js.map
|
|
29
|
+
//# sourceMappingURL=getRandomValues.js.map
|