ranuts 0.4.1-alpha.2 → 0.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/CLAUDE.md +23 -16
- package/README.de.md +62 -0
- package/README.es.md +62 -0
- package/README.fa.md +62 -0
- package/README.ja.md +62 -0
- package/README.ko.md +62 -0
- package/README.md +35 -92
- package/README.pt.md +62 -0
- package/README.zh-CN.md +35 -91
- package/dist/iife/index.iife.js +4 -0
- package/dist/iife/utils.iife.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +307 -1
- package/dist/src/_virtual/_rolldown/runtime/index.js +12 -0
- package/dist/src/conversation/engine.d.ts +1 -1
- package/dist/src/conversation/engine.js +101 -0
- package/dist/src/conversation/index.d.ts +3 -3
- package/dist/src/conversation/index.js +4 -1
- package/dist/src/stream/accumulator.d.ts +1 -1
- package/dist/src/stream/accumulator.js +79 -0
- package/dist/src/stream/budget.d.ts +1 -1
- package/dist/src/stream/budget.js +45 -0
- package/dist/src/stream/index.d.ts +7 -7
- package/dist/src/stream/index.js +11 -1
- package/dist/src/stream/sse.d.ts +1 -1
- package/dist/src/stream/sse.js +61 -0
- package/dist/src/sw/index.js +52 -1
- package/dist/src/utils/async.js +49 -0
- package/dist/src/utils/audioRecorder.js +1121 -0
- package/dist/src/utils/behavior.js +9 -0
- package/dist/src/utils/binary.js +89 -0
- package/dist/src/utils/bom.d.ts +31 -9
- package/dist/src/utils/bom.js +165 -0
- package/dist/src/utils/bridge.js +310 -0
- package/dist/src/utils/canvas.js +103 -0
- package/dist/src/utils/chain.js +76 -0
- package/dist/src/utils/charset.d.ts +15 -0
- package/dist/src/utils/charset.js +21 -0
- package/dist/src/utils/color.d.ts +0 -1
- package/dist/src/utils/color.js +312 -0
- package/dist/src/utils/compose.js +22 -0
- package/dist/src/utils/console.js +22 -0
- package/dist/src/utils/debounce.js +18 -0
- package/dist/src/utils/device.d.ts +0 -9
- package/dist/src/utils/device.js +31 -0
- package/dist/src/utils/diff.js +110 -0
- package/dist/src/utils/dom.d.ts +1 -1
- package/dist/src/utils/dom.js +89 -0
- package/dist/src/utils/error.js +11 -0
- package/dist/src/utils/event.d.ts +3 -3
- package/dist/src/utils/event.js +39 -0
- package/dist/src/utils/file.js +14 -0
- package/dist/src/utils/func.js +4 -0
- package/dist/src/utils/i18n/index.js +79 -1
- package/dist/src/utils/idb.js +177 -0
- package/dist/src/utils/img.d.ts +1 -1
- package/dist/src/utils/img.js +68 -0
- package/dist/src/utils/index.d.ts +82 -80
- package/dist/src/utils/index.js +307 -1
- package/dist/src/utils/lang.d.ts +23 -6
- package/dist/src/utils/lang.js +42 -0
- package/dist/src/utils/localePath.js +48 -0
- package/dist/src/utils/memoize.d.ts +1 -7
- package/dist/src/utils/memoize.js +16 -0
- package/dist/src/utils/mimeType.js +841 -0
- package/dist/src/utils/monitor.js +84 -0
- package/dist/src/utils/network.js +117 -0
- package/dist/src/utils/noop.js +5 -0
- package/dist/src/utils/number.js +185 -0
- package/dist/src/utils/obj.d.ts +2 -2
- package/dist/src/utils/obj.js +140 -0
- package/dist/src/utils/paginate.js +93 -0
- package/dist/src/utils/performance.js +26 -0
- package/dist/src/utils/placement.js +37 -0
- package/dist/src/utils/prefetch.js +69 -0
- package/dist/src/utils/queue.js +46 -0
- package/dist/src/utils/report.js +44 -0
- package/dist/src/utils/request.js +35 -0
- package/dist/src/utils/script.d.ts +4 -2
- package/dist/src/utils/script.js +45 -0
- package/dist/src/utils/scroll.d.ts +2 -0
- package/dist/src/utils/scroll.js +62 -0
- package/dist/src/utils/secure.js +36 -0
- package/dist/src/utils/segment.js +43 -0
- package/dist/src/utils/signal.d.ts +1 -1
- package/dist/src/utils/signal.js +13 -0
- package/dist/src/utils/speech.js +59 -0
- package/dist/src/utils/storage.js +53 -0
- package/dist/src/utils/str.d.ts +0 -21
- package/dist/src/utils/str.js +377 -0
- package/dist/src/utils/style.js +29 -0
- package/dist/src/utils/subscribe.js +58 -0
- package/dist/src/utils/throttle.js +17 -0
- package/dist/src/utils/time.d.ts +0 -21
- package/dist/src/utils/time.js +97 -0
- package/dist/src/utils/totp/sha/common.d.ts +1 -1
- package/dist/src/utils/totp/sha/common.js +201 -0
- package/dist/src/utils/totp/sha/converters.d.ts +1 -1
- package/dist/src/utils/totp/sha/converters.js +188 -0
- package/dist/src/utils/totp/sha/primitives_32.js +55 -0
- package/dist/src/utils/totp/sha/primitives_64.js +85 -0
- package/dist/src/utils/totp/sha/sha.d.ts +1 -1
- package/dist/src/utils/totp/sha/sha.js +30 -0
- package/dist/src/utils/totp/sha/sha1.d.ts +2 -2
- package/dist/src/utils/totp/sha/sha1.js +51 -0
- package/dist/src/utils/totp/sha/sha256.d.ts +2 -2
- package/dist/src/utils/totp/sha/sha256.js +56 -0
- package/dist/src/utils/totp/sha/sha3.d.ts +3 -3
- package/dist/src/utils/totp/sha/sha3.js +253 -0
- package/dist/src/utils/totp/sha/sha512.d.ts +3 -3
- package/dist/src/utils/totp/sha/sha512.js +177 -0
- package/dist/src/utils/totp/totp.js +49 -0
- package/dist/src/utils/tween.js +59 -0
- package/dist/src/utils/visual/application.d.ts +4 -4
- package/dist/src/utils/visual/application.js +42 -0
- package/dist/src/utils/visual/enums.js +19 -0
- package/dist/src/utils/visual/event/boundary.d.ts +2 -2
- package/dist/src/utils/visual/event/boundary.js +93 -0
- package/dist/src/utils/visual/event/event.d.ts +1 -1
- package/dist/src/utils/visual/event/event.js +34 -0
- package/dist/src/utils/visual/event/index.d.ts +4 -4
- package/dist/src/utils/visual/event/types.d.ts +2 -2
- package/dist/src/utils/visual/event/types.js +23 -0
- package/dist/src/utils/visual/graphics/graphics.d.ts +8 -8
- package/dist/src/utils/visual/graphics/graphics.js +168 -0
- package/dist/src/utils/visual/graphics/graphicsData.d.ts +3 -3
- package/dist/src/utils/visual/graphics/graphicsData.js +12 -0
- package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +7 -7
- package/dist/src/utils/visual/graphics/graphicsGeometry.js +39 -0
- package/dist/src/utils/visual/graphics/index.d.ts +3 -3
- package/dist/src/utils/visual/index.d.ts +8 -8
- package/dist/src/utils/visual/index.js +20 -1
- package/dist/src/utils/visual/math/bezier.js +15 -0
- package/dist/src/utils/visual/math/enums.js +6 -0
- package/dist/src/utils/visual/math/index.d.ts +4 -4
- package/dist/src/utils/visual/math/matrix.d.ts +1 -1
- package/dist/src/utils/visual/math/matrix.js +59 -0
- package/dist/src/utils/visual/math/transform.d.ts +2 -2
- package/dist/src/utils/visual/math/transform.js +50 -0
- package/dist/src/utils/visual/render/batchRenderer.d.ts +4 -4
- package/dist/src/utils/visual/render/batchRenderer.js +59 -0
- package/dist/src/utils/visual/render/canvasRenderer.d.ts +3 -3
- package/dist/src/utils/visual/render/canvasRenderer.js +17 -0
- package/dist/src/utils/visual/render/filter.d.ts +1 -1
- package/dist/src/utils/visual/render/filter.js +92 -0
- package/dist/src/utils/visual/render/index.d.ts +2 -2
- package/dist/src/utils/visual/render/index.js +20 -0
- package/dist/src/utils/visual/render/render.d.ts +4 -4
- package/dist/src/utils/visual/render/render.js +19 -0
- package/dist/src/utils/visual/render/renderTarget.js +28 -0
- package/dist/src/utils/visual/render/utils/batch/index.d.ts +4 -4
- package/dist/src/utils/visual/render/utils/batch/index.js +88 -0
- package/dist/src/utils/visual/render/utils/earcut.js +328 -0
- package/dist/src/utils/visual/render/utils/float.js +65 -0
- package/dist/src/utils/visual/render/utils/index.js +50 -0
- package/dist/src/utils/visual/render/utils/verticy.d.ts +2 -2
- package/dist/src/utils/visual/render/utils/verticy.js +162 -0
- package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +1 -1
- package/dist/src/utils/visual/render/utils/webgl/initShader.js +31 -0
- package/dist/src/utils/visual/render/utils/webgl/shaders.js +22 -0
- package/dist/src/utils/visual/render/utils/webgpu/shaders.js +32 -0
- package/dist/src/utils/visual/render/webGPURenderer.d.ts +2 -2
- package/dist/src/utils/visual/render/webGPURenderer.js +185 -0
- package/dist/src/utils/visual/render/webGlRenderer.d.ts +2 -2
- package/dist/src/utils/visual/render/webGlRenderer.js +88 -0
- package/dist/src/utils/visual/shape/circle.d.ts +3 -3
- package/dist/src/utils/visual/shape/circle.js +17 -0
- package/dist/src/utils/visual/shape/ellipse.d.ts +3 -3
- package/dist/src/utils/visual/shape/ellipse.js +18 -0
- package/dist/src/utils/visual/shape/index.d.ts +6 -6
- package/dist/src/utils/visual/shape/polygon.d.ts +3 -3
- package/dist/src/utils/visual/shape/polygon.js +29 -0
- package/dist/src/utils/visual/shape/rectangle.d.ts +3 -3
- package/dist/src/utils/visual/shape/rectangle.js +18 -0
- package/dist/src/utils/visual/shape/roundedRectangle.d.ts +3 -3
- package/dist/src/utils/visual/shape/roundedRectangle.js +32 -0
- package/dist/src/utils/visual/shape/shape.d.ts +2 -2
- package/dist/src/utils/visual/shape/shape.js +5 -0
- package/dist/src/utils/visual/style/fill.js +18 -0
- package/dist/src/utils/visual/style/index.d.ts +2 -2
- package/dist/src/utils/visual/style/line.d.ts +2 -2
- package/dist/src/utils/visual/style/line.js +18 -0
- package/dist/src/utils/visual/types.d.ts +1 -1
- package/dist/src/utils/visual/vertex/container.d.ts +5 -5
- package/dist/src/utils/visual/vertex/container.js +54 -0
- package/dist/src/utils/visual/vertex/point.js +37 -0
- package/dist/src/utils/visual/vertex/vertex.d.ts +7 -7
- package/dist/src/utils/visual/vertex/vertex.js +76 -0
- package/dist/src/utils/worker.js +89 -0
- package/dist/src/utils/zip.js +161 -0
- package/dist/src/vnode/h.d.ts +1 -1
- package/dist/src/vnode/h.js +22 -0
- package/dist/src/vnode/hooks.d.ts +1 -1
- package/dist/src/vnode/htmlDomApi.js +94 -0
- package/dist/src/vnode/index.d.ts +16 -16
- package/dist/src/vnode/index.js +28 -1
- package/dist/src/vnode/init.d.ts +1 -1
- package/dist/src/vnode/init.js +104 -0
- package/dist/src/vnode/is.d.ts +1 -1
- package/dist/src/vnode/is.js +20 -0
- package/dist/src/vnode/modules/attributes.d.ts +1 -1
- package/dist/src/vnode/modules/attributes.js +21 -0
- package/dist/src/vnode/modules/class.d.ts +1 -1
- package/dist/src/vnode/modules/class.js +18 -0
- package/dist/src/vnode/modules/index.js +15 -0
- package/dist/src/vnode/modules/listeners.d.ts +1 -1
- package/dist/src/vnode/modules/listeners.js +36 -0
- package/dist/src/vnode/modules/props.d.ts +1 -1
- package/dist/src/vnode/modules/props.js +17 -0
- package/dist/src/vnode/modules/style.d.ts +1 -1
- package/dist/src/vnode/modules/style.js +52 -0
- package/dist/src/vnode/vnode.d.ts +6 -6
- package/dist/src/vnode/vnode.js +13 -0
- package/dist/third-party/jschardet/LICENSE.txt +504 -0
- package/dist/third-party/jschardet/NOTICE.txt +33 -0
- package/docs/API.md +8 -64
- package/package.json +14 -18
- package/dist/bin/generate-api-docs.d.ts +0 -1
- package/dist/build/build.es.d.ts +0 -2
- package/dist/build/build.umd.d.ts +0 -2
- package/dist/build/build.umd.node.d.ts +0 -2
- package/dist/build/build.umd.utils.d.ts +0 -2
- package/dist/chain-CTywmh_H.js +0 -1
- package/dist/color-BTvZUuf-.js +0 -1
- package/dist/enums-BAgbyGdH.js +0 -1
- package/dist/examples/clone-deep-example.d.ts +0 -1
- package/dist/examples/is-equal-example.d.ts +0 -1
- package/dist/i18n-DW21b_DJ.js +0 -1
- package/dist/plugins/vite-plugins-banner.d.ts +0 -2
- package/dist/rolldown-runtime-I3TIJKkN.js +0 -1
- package/dist/src/node/appendFile.d.ts +0 -7
- package/dist/src/node/body.d.ts +0 -9
- package/dist/src/node/color.d.ts +0 -7
- package/dist/src/node/command.d.ts +0 -8
- package/dist/src/node/ctx2req.d.ts +0 -5
- package/dist/src/node/fileInfo.d.ts +0 -7
- package/dist/src/node/fs.d.ts +0 -7
- package/dist/src/node/get.d.ts +0 -10
- package/dist/src/node/getIPAdress.d.ts +0 -1
- package/dist/src/node/index.d.ts +0 -25
- package/dist/src/node/index.js +0 -1
- package/dist/src/node/isColorSupported.d.ts +0 -2
- package/dist/src/node/paresUrl.d.ts +0 -19
- package/dist/src/node/readDir.d.ts +0 -6
- package/dist/src/node/readFile.d.ts +0 -9
- package/dist/src/node/router.d.ts +0 -42
- package/dist/src/node/send.d.ts +0 -7
- package/dist/src/node/server.d.ts +0 -18
- package/dist/src/node/startTask.d.ts +0 -2
- package/dist/src/node/stream.d.ts +0 -15
- package/dist/src/node/taskEnd.d.ts +0 -2
- package/dist/src/node/traverse.d.ts +0 -17
- package/dist/src/node/watchFile.d.ts +0 -8
- package/dist/src/node/writeFile.d.ts +0 -8
- package/dist/src/node/ws.d.ts +0 -8
- package/dist/src/utils/visual/render/utils/batch/index.test.d.ts +0 -1
- package/dist/src/utils/visual/render/utils/index.test.d.ts +0 -1
- package/dist/test/binary.test.d.ts +0 -1
- package/dist/test/bridge.test.d.ts +0 -1
- package/dist/test/budget.test.d.ts +0 -1
- package/dist/test/canvas.test.d.ts +0 -1
- package/dist/test/clearBr.test.d.ts +0 -1
- package/dist/test/cloneDeep.test.d.ts +0 -1
- package/dist/test/color.test.d.ts +0 -1
- package/dist/test/command.test.d.ts +0 -1
- package/dist/test/conversation.test.d.ts +0 -1
- package/dist/test/diff.test.d.ts +0 -1
- package/dist/test/encodeUrl.test.d.ts +0 -1
- package/dist/test/escapeHtml.test.d.ts +0 -1
- package/dist/test/formatBytes.test.d.ts +0 -1
- package/dist/test/is-equal.test.d.ts +0 -1
- package/dist/test/mimeType.test.d.ts +0 -1
- package/dist/test/package-exports.test.d.ts +0 -1
- package/dist/test/scroll.test.d.ts +0 -1
- package/dist/test/server.test.d.ts +0 -1
- package/dist/test/status.test.d.ts +0 -1
- package/dist/test/stream.test.d.ts +0 -1
- package/dist/test/sw.test.d.ts +0 -1
- package/dist/test/totp.test.d.ts +0 -1
- package/dist/test/tween.test.d.ts +0 -1
- package/dist/test/utils/async.test.d.ts +0 -1
- package/dist/test/utils/autosize.test.d.ts +0 -1
- package/dist/test/utils/color-grade.test.d.ts +0 -1
- package/dist/test/utils/compose.test.d.ts +0 -1
- package/dist/test/utils/event.test.d.ts +0 -1
- package/dist/test/utils/file-read.test.d.ts +0 -1
- package/dist/test/utils/format.test.d.ts +0 -1
- package/dist/test/utils/i18n.test.d.ts +0 -1
- package/dist/test/utils/idb-collection.test.d.ts +0 -1
- package/dist/test/utils/idb.test.d.ts +0 -1
- package/dist/test/utils/instrumentation.test.d.ts +0 -1
- package/dist/test/utils/interp.test.d.ts +0 -1
- package/dist/test/utils/lang.test.d.ts +0 -1
- package/dist/test/utils/locale-path.test.d.ts +0 -1
- package/dist/test/utils/media-query.test.d.ts +0 -1
- package/dist/test/utils/mergeObj.test.d.ts +0 -1
- package/dist/test/utils/number-parse.test.d.ts +0 -1
- package/dist/test/utils/paginate.test.d.ts +0 -1
- package/dist/test/utils/placement.test.d.ts +0 -1
- package/dist/test/utils/prefetch.test.d.ts +0 -1
- package/dist/test/utils/query-storage.test.d.ts +0 -1
- package/dist/test/utils/queue.test.d.ts +0 -1
- package/dist/test/utils/report-config.test.d.ts +0 -1
- package/dist/test/utils/report-image.test.d.ts +0 -1
- package/dist/test/utils/secure.test.d.ts +0 -1
- package/dist/test/utils/segment.test.d.ts +0 -1
- package/dist/test/utils/signal-once.test.d.ts +0 -1
- package/dist/test/utils/single-flight.test.d.ts +0 -1
- package/dist/test/utils/speech.test.d.ts +0 -1
- package/dist/test/utils/text-boundary.test.d.ts +0 -1
- package/dist/test/utils/time.test.d.ts +0 -1
- package/dist/test/utils/timing.test.d.ts +0 -1
- package/dist/test/utils/truncate.test.d.ts +0 -1
- package/dist/test/utils/visual/filter.test.d.ts +0 -1
- package/dist/test/utils/worker-client.test.d.ts +0 -1
- package/dist/test/utils/worker-serve.test.d.ts +0 -1
- package/dist/test/utils/zip.test.d.ts +0 -1
- package/dist/test/visual/math.test.d.ts +0 -1
- package/dist/test/visual-application.test.d.ts +0 -1
- package/dist/test/visual-batch.test.d.ts +0 -1
- package/dist/test/visual-math.test.d.ts +0 -1
- package/dist/test/vnode/index.d.ts +0 -1
- package/dist/test/vnode/server.d.ts +0 -2
- package/dist/test/vnode/vnode.d.ts +0 -1
- package/dist/test/vnode.test.d.ts +0 -1
- package/dist/test/websocket.test.d.ts +0 -1
- package/dist/test/writeFile.test.d.ts +0 -1
- package/dist/umd/index.umd.cjs +0 -1
- package/dist/umd/node/node.umd.cjs +0 -1
- package/dist/umd/utils/utils.umd.cjs +0 -1
- package/dist/utils-B4FnyUzW.js +0 -1
- package/dist/vite.config.d.ts +0 -8
- package/dist/vitest.config.d.ts +0 -2
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
var w = (r = "", e = "", t = "") => {
|
|
2
|
+
const n = {}, o = r.split(e);
|
|
3
|
+
return o.length > 0 && o.forEach((c) => {
|
|
4
|
+
const [h = "", s = ""] = c.split(t);
|
|
5
|
+
u(h) && (n[u(h)] = u(s));
|
|
6
|
+
}), n;
|
|
7
|
+
}, g = (r = "") => {
|
|
8
|
+
if (r.length === 0) return "";
|
|
9
|
+
let e = "", t = 0;
|
|
10
|
+
for (const n of r)
|
|
11
|
+
if (!/\s/.test(n)) {
|
|
12
|
+
if (n === "<") {
|
|
13
|
+
t++;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (n === ">" && t > 0) {
|
|
17
|
+
t--;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
t === 0 && (e += n);
|
|
21
|
+
}
|
|
22
|
+
return e;
|
|
23
|
+
}, p = (r) => window.toString.call(r) === "[object String]";
|
|
24
|
+
function m(r = 8) {
|
|
25
|
+
const e = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
|
|
26
|
+
let n = "";
|
|
27
|
+
for (let o = 0; o < r; o++) n += e.charAt(Math.floor(Math.random() * 48));
|
|
28
|
+
return `${Date.now()}-${n}`;
|
|
29
|
+
}
|
|
30
|
+
var u = (r, e = {}) => {
|
|
31
|
+
const { urlencoded: t = !0 } = e, n = String.prototype.trim.call(r);
|
|
32
|
+
return t ? decodeURIComponent(n).replace(/"|'/g, "") : n.replace(/"|'/g, "");
|
|
33
|
+
};
|
|
34
|
+
function E(r, e) {
|
|
35
|
+
if (!r || !e) return [];
|
|
36
|
+
const t = [], n = new RegExp(e, "gi");
|
|
37
|
+
let o;
|
|
38
|
+
for (; (o = n.exec(r)) !== null; ) {
|
|
39
|
+
const s = o.index;
|
|
40
|
+
let a = s;
|
|
41
|
+
for (; a > 0; ) {
|
|
42
|
+
const d = r[a - 1];
|
|
43
|
+
if (d === "。" || d === "." || d === `
|
|
44
|
+
` || d === "!" || d === "?" || d === "?") break;
|
|
45
|
+
a--;
|
|
46
|
+
}
|
|
47
|
+
let l = s + e.length;
|
|
48
|
+
for (; l < r.length; ) {
|
|
49
|
+
const d = r[l];
|
|
50
|
+
if (d === "。" || d === "." || d === `
|
|
51
|
+
` || d === "!" || d === "?" || d === "?") {
|
|
52
|
+
l++;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
l++;
|
|
56
|
+
}
|
|
57
|
+
const f = r.slice(a, l).trim();
|
|
58
|
+
f && t.push({
|
|
59
|
+
sentence: f,
|
|
60
|
+
start: a,
|
|
61
|
+
end: l
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const c = [], h = [];
|
|
65
|
+
t.sort((s, a) => a.sentence.length - s.sentence.length);
|
|
66
|
+
for (const s of t) h.some((a) => !(s.end <= a.start || s.start >= a.end)) || (c.push(s.sentence), h.push({
|
|
67
|
+
start: s.start,
|
|
68
|
+
end: s.end
|
|
69
|
+
}));
|
|
70
|
+
return [...new Set(c)];
|
|
71
|
+
}
|
|
72
|
+
var C = (r) => String(r), A = (r) => r.replace(/[!-~]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 65248)).replace(/\u3000/g, " "), S = (r) => r.replace(/[!-~]/g, (e) => String.fromCharCode(e.charCodeAt(0) + 65248)).replace(/ /g, " "), R = (r, e) => {
|
|
73
|
+
const { length: t, position: n = "end", ellipsis: o = "…" } = typeof e == "number" ? { length: e } : e;
|
|
74
|
+
if (!r) return r;
|
|
75
|
+
const c = Array.from(r), h = Array.from(o);
|
|
76
|
+
if (c.length <= t) return r;
|
|
77
|
+
if (t <= h.length) return h.slice(0, Math.max(0, t)).join("");
|
|
78
|
+
const s = t - h.length;
|
|
79
|
+
if (n === "start") return o + c.slice(c.length - s).join("");
|
|
80
|
+
if (n === "middle") {
|
|
81
|
+
const a = Math.ceil(s / 2);
|
|
82
|
+
return c.slice(0, a).join("") + o + c.slice(c.length - (s - a)).join("");
|
|
83
|
+
}
|
|
84
|
+
return c.slice(0, s).join("") + o;
|
|
85
|
+
}, b = (r = 8) => Math.random().toString(36).substring(2, r + 2), i = class extends Error {
|
|
86
|
+
code;
|
|
87
|
+
constructor(r, e) {
|
|
88
|
+
super(r), this.code = e, this.name = "MessageCodecError";
|
|
89
|
+
}
|
|
90
|
+
}, v = {
|
|
91
|
+
encode(r) {
|
|
92
|
+
try {
|
|
93
|
+
const e = JSON.stringify(r), t = new TextEncoder().encode(e);
|
|
94
|
+
let n = "";
|
|
95
|
+
const o = 32768;
|
|
96
|
+
for (let c = 0; c < t.length; c += o) n += String.fromCharCode.apply(null, Array.from(t.subarray(c, c + o)));
|
|
97
|
+
return btoa(n);
|
|
98
|
+
} catch {
|
|
99
|
+
return "";
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
decode(r) {
|
|
103
|
+
try {
|
|
104
|
+
const e = atob(r), t = new Uint8Array(e.length);
|
|
105
|
+
for (let o = 0; o < e.length; o++) t[o] = e.charCodeAt(o);
|
|
106
|
+
const n = new TextDecoder().decode(t);
|
|
107
|
+
return JSON.parse(n);
|
|
108
|
+
} catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
async encodeFile(r) {
|
|
113
|
+
try {
|
|
114
|
+
const e = await r.arrayBuffer();
|
|
115
|
+
return this.encode({
|
|
116
|
+
type: "File",
|
|
117
|
+
name: r.name,
|
|
118
|
+
mimeType: r.type,
|
|
119
|
+
size: r.size,
|
|
120
|
+
lastModified: r.lastModified,
|
|
121
|
+
content: new Uint8Array(e)
|
|
122
|
+
});
|
|
123
|
+
} catch (e) {
|
|
124
|
+
throw new i(`Failed to encode file: ${e instanceof Error ? e.message : "Unknown error"}`, "FILE_ENCODE_ERROR");
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
decodeFile(r) {
|
|
128
|
+
try {
|
|
129
|
+
const e = this.decode(r);
|
|
130
|
+
if (e.type !== "File") throw new i(`Expected File type but got ${e.type}`, "INVALID_FILE_TYPE");
|
|
131
|
+
const t = e, n = t.content instanceof Uint8Array ? t.content.buffer.slice(0) : t.content;
|
|
132
|
+
return new File([n], t.name, {
|
|
133
|
+
type: t.mimeType,
|
|
134
|
+
lastModified: t.lastModified
|
|
135
|
+
});
|
|
136
|
+
} catch (e) {
|
|
137
|
+
throw e instanceof i ? e : new i(`Failed to decode file: ${e instanceof Error ? e.message : "Unknown error"}`, "FILE_DECODE_ERROR");
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
async encodeBlob(r) {
|
|
141
|
+
try {
|
|
142
|
+
const e = await r.arrayBuffer();
|
|
143
|
+
return this.encode({
|
|
144
|
+
type: "Blob",
|
|
145
|
+
mimeType: r.type,
|
|
146
|
+
size: r.size,
|
|
147
|
+
content: new Uint8Array(e)
|
|
148
|
+
});
|
|
149
|
+
} catch (e) {
|
|
150
|
+
throw new i(`Failed to encode blob: ${e instanceof Error ? e.message : "Unknown error"}`, "BLOB_ENCODE_ERROR");
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
decodeBlob(r) {
|
|
154
|
+
try {
|
|
155
|
+
const e = this.decode(r);
|
|
156
|
+
if (e.type !== "Blob") throw new i(`Expected Blob type but got ${e.type}`, "INVALID_BLOB_TYPE");
|
|
157
|
+
const t = e, n = t.content instanceof Uint8Array ? t.content.buffer.slice(0) : t.content;
|
|
158
|
+
return new Blob([n], { type: t.mimeType });
|
|
159
|
+
} catch (e) {
|
|
160
|
+
throw e instanceof i ? e : new i(`Failed to decode blob: ${e instanceof Error ? e.message : "Unknown error"}`, "BLOB_DECODE_ERROR");
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
encodeDate(r) {
|
|
164
|
+
try {
|
|
165
|
+
return this.encode({
|
|
166
|
+
type: "Date",
|
|
167
|
+
value: r.toISOString()
|
|
168
|
+
});
|
|
169
|
+
} catch (e) {
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
decodeDate(r) {
|
|
174
|
+
try {
|
|
175
|
+
const e = this.decode(r);
|
|
176
|
+
if (e.type !== "Date") throw new Error("Invalid encoded Date data");
|
|
177
|
+
return new Date(e.value);
|
|
178
|
+
} catch (e) {
|
|
179
|
+
throw e;
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
encodeRegExp(r) {
|
|
183
|
+
try {
|
|
184
|
+
return this.encode({
|
|
185
|
+
type: "RegExp",
|
|
186
|
+
source: r.source,
|
|
187
|
+
flags: r.flags
|
|
188
|
+
});
|
|
189
|
+
} catch (e) {
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
decodeRegExp(r) {
|
|
194
|
+
try {
|
|
195
|
+
const e = this.decode(r);
|
|
196
|
+
if (e.type !== "RegExp") throw new Error("Invalid encoded RegExp data");
|
|
197
|
+
return new RegExp(e.source, e.flags);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
throw e;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
encodeMap(r) {
|
|
203
|
+
try {
|
|
204
|
+
return this.encode({
|
|
205
|
+
type: "Map",
|
|
206
|
+
value: Array.from(r.entries())
|
|
207
|
+
});
|
|
208
|
+
} catch (e) {
|
|
209
|
+
throw e;
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
decodeMap(r) {
|
|
213
|
+
try {
|
|
214
|
+
const e = this.decode(r);
|
|
215
|
+
if (e.type !== "Map") throw new Error("Invalid encoded Map data");
|
|
216
|
+
return new Map(e.value);
|
|
217
|
+
} catch (e) {
|
|
218
|
+
throw e;
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
encodeSet(r) {
|
|
222
|
+
try {
|
|
223
|
+
return this.encode({
|
|
224
|
+
type: "Set",
|
|
225
|
+
value: Array.from(r)
|
|
226
|
+
});
|
|
227
|
+
} catch (e) {
|
|
228
|
+
throw e;
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
decodeSet(r) {
|
|
232
|
+
try {
|
|
233
|
+
const e = this.decode(r);
|
|
234
|
+
if (e.type !== "Set") throw new Error("Invalid encoded Set data");
|
|
235
|
+
return new Set(e.value);
|
|
236
|
+
} catch (e) {
|
|
237
|
+
throw e;
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
encodeError(r) {
|
|
241
|
+
try {
|
|
242
|
+
return this.encode({
|
|
243
|
+
type: "Error",
|
|
244
|
+
name: r.name,
|
|
245
|
+
message: r.message,
|
|
246
|
+
stack: r.stack
|
|
247
|
+
});
|
|
248
|
+
} catch (e) {
|
|
249
|
+
throw e;
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
decodeError(r) {
|
|
253
|
+
try {
|
|
254
|
+
const e = this.decode(r);
|
|
255
|
+
if (e.type !== "Error") throw new Error("Invalid encoded Error data");
|
|
256
|
+
const t = new Error(e.message);
|
|
257
|
+
return t.name = e.name, t.stack = e.stack, t;
|
|
258
|
+
} catch (e) {
|
|
259
|
+
throw e;
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
encodeArrayBuffer(r) {
|
|
263
|
+
try {
|
|
264
|
+
return this.encode({
|
|
265
|
+
type: "ArrayBuffer",
|
|
266
|
+
value: Array.from(new Uint8Array(r))
|
|
267
|
+
});
|
|
268
|
+
} catch (e) {
|
|
269
|
+
throw e;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
decodeArrayBuffer(r) {
|
|
273
|
+
try {
|
|
274
|
+
const e = this.decode(r);
|
|
275
|
+
if (e.type !== "ArrayBuffer") throw new Error("Invalid encoded ArrayBuffer data");
|
|
276
|
+
return new Uint8Array(e.value).buffer;
|
|
277
|
+
} catch (e) {
|
|
278
|
+
throw e;
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
encodeTypedArray(r) {
|
|
282
|
+
try {
|
|
283
|
+
return this.encode({
|
|
284
|
+
type: "TypedArray",
|
|
285
|
+
constructor: r.constructor.name,
|
|
286
|
+
value: Array.from(new Uint8Array(r.buffer, r.byteOffset, r.byteLength))
|
|
287
|
+
});
|
|
288
|
+
} catch {
|
|
289
|
+
return "";
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
decodeTypedArray(r) {
|
|
293
|
+
try {
|
|
294
|
+
const e = this.decode(r);
|
|
295
|
+
if (e.type !== "TypedArray") throw new Error("Invalid encoded TypedArray data");
|
|
296
|
+
const t = window[e.constructor];
|
|
297
|
+
return new t(e.value);
|
|
298
|
+
} catch (e) {
|
|
299
|
+
throw e;
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
async encodeFileChunked(r, e = 16384) {
|
|
303
|
+
try {
|
|
304
|
+
if (e <= 0) throw new i("Chunk size must be greater than 0", "INVALID_CHUNK_SIZE");
|
|
305
|
+
const t = Math.ceil(r.size / e), n = [];
|
|
306
|
+
for (let o = 0; o < t; o++) {
|
|
307
|
+
const c = o * e, h = Math.min(c + e, r.size), s = await r.slice(c, h).arrayBuffer(), a = String.fromCharCode.apply(null, Array.from(new Uint8Array(s)));
|
|
308
|
+
n.push({
|
|
309
|
+
name: r.name,
|
|
310
|
+
type: r.type,
|
|
311
|
+
size: r.size,
|
|
312
|
+
lastModified: r.lastModified,
|
|
313
|
+
totalChunks: t,
|
|
314
|
+
chunkIndex: o,
|
|
315
|
+
data: a
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return n;
|
|
319
|
+
} catch (t) {
|
|
320
|
+
throw t instanceof i ? t : new i(`Failed to encode file chunks: ${t instanceof Error ? t.message : "Unknown error"}`, "FILE_CHUNK_ENCODE_ERROR");
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
async decodeFileChunked(r) {
|
|
324
|
+
try {
|
|
325
|
+
if (!r.length) throw new i("No chunks provided", "NO_CHUNKS");
|
|
326
|
+
const { type: e, lastModified: t, totalChunks: n } = r[0];
|
|
327
|
+
if (r.length !== n) throw new i(`Missing chunks. Expected ${n}, got ${r.length}`, "INCOMPLETE_CHUNKS");
|
|
328
|
+
r.sort((a, l) => a.chunkIndex - l.chunkIndex);
|
|
329
|
+
for (let a = 0; a < r.length; a++) if (r[a].chunkIndex !== a) throw new i(`Invalid chunk index at position ${a}`, "INVALID_CHUNK_ORDER");
|
|
330
|
+
const o = await Promise.all(r.map(async (a) => {
|
|
331
|
+
const l = a.data, f = new Uint8Array(l.length);
|
|
332
|
+
for (let d = 0; d < l.length; d++) f[d] = l.charCodeAt(d);
|
|
333
|
+
return f;
|
|
334
|
+
})), c = r.reduce((a, l) => a + l.data.length, 0), h = new Uint8Array(c);
|
|
335
|
+
let s = 0;
|
|
336
|
+
for (const a of o)
|
|
337
|
+
h.set(a, s), s += a.length;
|
|
338
|
+
return new File([h.buffer.slice(0)], r[0].name, {
|
|
339
|
+
type: e,
|
|
340
|
+
lastModified: t
|
|
341
|
+
});
|
|
342
|
+
} catch (e) {
|
|
343
|
+
throw e instanceof i ? e : new i(`Failed to decode file chunks: ${e instanceof Error ? e.message : "Unknown error"}`, "FILE_CHUNK_DECODE_ERROR");
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}, I = (r, e, t = "…[truncated]") => r.length > e ? r.slice(0, e) + t : r, M = (r, e = "") => {
|
|
347
|
+
const t = Math.max(0, ...Array.from(r.matchAll(/`+/g), (o) => o[0].length)), n = "`".repeat(Math.max(3, t + 1));
|
|
348
|
+
return `${n}${e}
|
|
349
|
+
${r}
|
|
350
|
+
${n}`;
|
|
351
|
+
}, y = (r) => {
|
|
352
|
+
let e = 0, t = r.length;
|
|
353
|
+
for (; e < t && r[e] === "-"; ) e++;
|
|
354
|
+
for (; t > e && r[t - 1] === "-"; ) t--;
|
|
355
|
+
return r.slice(e, t);
|
|
356
|
+
}, D = (r, e = 60) => y(y(r.toLowerCase().replace(/[^a-z0-9]+/g, "-")).slice(0, e)), B = (r) => {
|
|
357
|
+
const e = String(r), t = /^[=+\-@]/.test(e) ? `'${e}` : e;
|
|
358
|
+
return /[",\n\r]/.test(t) ? `"${t.replace(/"/g, '""')}"` : t;
|
|
359
|
+
};
|
|
360
|
+
export {
|
|
361
|
+
v as MessageCodec,
|
|
362
|
+
g as clearBr,
|
|
363
|
+
u as clearStr,
|
|
364
|
+
B as csvEscape,
|
|
365
|
+
M as fenceCode,
|
|
366
|
+
E as getMatchingSentences,
|
|
367
|
+
b as getRandomString,
|
|
368
|
+
p as isString,
|
|
369
|
+
m as randomString,
|
|
370
|
+
D as slugify,
|
|
371
|
+
w as strParse,
|
|
372
|
+
S as toFullWidth,
|
|
373
|
+
A as toHalfWidth,
|
|
374
|
+
C as toString,
|
|
375
|
+
R as truncate,
|
|
376
|
+
I as truncateWithMarker
|
|
377
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var d = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), y = "data-adopted-style", S = "data-adopted-sheet", a = (n, e, r) => {
|
|
2
|
+
if (typeof CSSStyleSheet > "u") return !1;
|
|
3
|
+
try {
|
|
4
|
+
if (!r.has(e)) {
|
|
5
|
+
const l = new CSSStyleSheet();
|
|
6
|
+
l.replaceSync(e), r.set(e, l);
|
|
7
|
+
}
|
|
8
|
+
const t = r.get(e);
|
|
9
|
+
return n.adoptedStyleSheets.includes(t) || (n.adoptedStyleSheets = [...n.adoptedStyleSheets, t]), !0;
|
|
10
|
+
} catch {
|
|
11
|
+
return !1;
|
|
12
|
+
}
|
|
13
|
+
}, f = (n, e, r = y) => {
|
|
14
|
+
if (!(typeof document > "u") && e && !a(n, e, d) && !n.querySelector(`style[${r}]`)) {
|
|
15
|
+
const t = document.createElement("style");
|
|
16
|
+
t.setAttribute(r, ""), t.textContent = e, n.appendChild(t);
|
|
17
|
+
}
|
|
18
|
+
}, i = (n, e, r = S) => {
|
|
19
|
+
if (!(typeof document > "u") && e && !a(n, e, u) && !Array.from(n.querySelectorAll(`style[${r}]`)).some((t) => t.textContent === e)) {
|
|
20
|
+
const t = document.createElement("style");
|
|
21
|
+
t.setAttribute(r, ""), t.textContent = e, n.appendChild(t);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
S as ADOPTED_SHEET_MARKER,
|
|
26
|
+
y as ADOPTED_STYLE_MARKER,
|
|
27
|
+
i as adoptSheetText,
|
|
28
|
+
f as adoptStyles
|
|
29
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var i = "NEW_LISTENER", n = class {
|
|
2
|
+
_events = /* @__PURE__ */ new Map();
|
|
3
|
+
tap = (l, c) => {
|
|
4
|
+
this._events.get(l) && l !== /* @__PURE__ */ Symbol.for("NEW_LISTENER") && this.call(Symbol.for(i), l);
|
|
5
|
+
const a = this._events.get(l) || /* @__PURE__ */ new Set();
|
|
6
|
+
return typeof c == "function" ? a.add({
|
|
7
|
+
name: l,
|
|
8
|
+
callback: c
|
|
9
|
+
}) : a.add(c), this._events.set(l, a), this;
|
|
10
|
+
};
|
|
11
|
+
call = (l, ...c) => ((this._events.get(l) || /* @__PURE__ */ new Set()).forEach((a) => {
|
|
12
|
+
const { callback: s } = a;
|
|
13
|
+
s(...c);
|
|
14
|
+
}), this);
|
|
15
|
+
callSync = async (l, ...c) => {
|
|
16
|
+
const a = this._events.get(l) || /* @__PURE__ */ new Set();
|
|
17
|
+
for (const s of a) {
|
|
18
|
+
const { callback: t } = s;
|
|
19
|
+
await t(...c);
|
|
20
|
+
}
|
|
21
|
+
return this;
|
|
22
|
+
};
|
|
23
|
+
once = (l, c) => {
|
|
24
|
+
let a;
|
|
25
|
+
if (typeof c == "function") a = {
|
|
26
|
+
name: l,
|
|
27
|
+
callback: (...s) => {
|
|
28
|
+
c(...s), this.off(l, a);
|
|
29
|
+
},
|
|
30
|
+
initialCallback: c
|
|
31
|
+
};
|
|
32
|
+
else {
|
|
33
|
+
const { callback: s } = c;
|
|
34
|
+
a = {
|
|
35
|
+
name: l,
|
|
36
|
+
callback: (...t) => {
|
|
37
|
+
s(...t), this.off(l, a);
|
|
38
|
+
},
|
|
39
|
+
initialCallback: s
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return this.tap(l, a), this;
|
|
43
|
+
};
|
|
44
|
+
off = (l, c) => {
|
|
45
|
+
const a = [...this._events.get(l) || /* @__PURE__ */ new Set()].filter((s) => {
|
|
46
|
+
if (typeof c == "function") return s.callback !== c && s.initialCallback !== c;
|
|
47
|
+
{
|
|
48
|
+
const { callback: t } = c;
|
|
49
|
+
return s.callback !== t && s.initialCallback !== t;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return this._events.set(l, new Set(a)), this;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
i as NEW_LISTENER,
|
|
57
|
+
n as SyncHook
|
|
58
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function c(r, a = 300) {
|
|
2
|
+
let u = 0, l = null, n, t = null;
|
|
3
|
+
const s = () => {
|
|
4
|
+
if (l = null, !t) return;
|
|
5
|
+
const o = t, e = n;
|
|
6
|
+
t = null, n = void 0, u = Date.now(), r.apply(e, o);
|
|
7
|
+
}, i = function(...o) {
|
|
8
|
+
const e = a - (Date.now() - u);
|
|
9
|
+
n = this, t = o, e <= 0 ? (l !== null && (clearTimeout(l), l = null), s()) : l === null && (l = setTimeout(s, e));
|
|
10
|
+
};
|
|
11
|
+
return i.cancel = () => {
|
|
12
|
+
l !== null && clearTimeout(l), l = null, t = null, n = void 0;
|
|
13
|
+
}, i.pending = () => l !== null, i;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
c as throttle
|
|
17
|
+
};
|
package/dist/src/utils/time.d.ts
CHANGED
|
@@ -29,18 +29,6 @@ export type DateInput = number | string | Date;
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
export declare const formatDate: (value?: DateInput, pattern?: string) => string;
|
|
32
|
-
/**
|
|
33
|
-
* @description: Turn a timestamp into a `Date` carrying a `format` method.
|
|
34
|
-
* @deprecated Use [`formatDate`](#formatdate). This returns a `Date` with an extra method
|
|
35
|
-
* bolted onto the instance, which does not survive serialization, breaks `instanceof`-based
|
|
36
|
-
* type narrowing on the extra property, and is untypeable beyond `Function`. Its `format`
|
|
37
|
-
* now delegates to `formatDate`, so the token handling is fixed here too.
|
|
38
|
-
* @param {number | string} timestamp omit for the current time
|
|
39
|
-
* @return {Date & { format?: Function }}
|
|
40
|
-
*/
|
|
41
|
-
export declare function timestampToTime(timestamp?: number | string): Date & {
|
|
42
|
-
format?: Function;
|
|
43
|
-
};
|
|
44
32
|
/**
|
|
45
33
|
* @description: Format an elapsed number of **seconds** as a colon-separated clock duration,
|
|
46
34
|
* the shape media players use for a playhead: `mm:ss`, widening to `hh:mm:ss` past an hour.
|
|
@@ -61,15 +49,6 @@ export declare function timestampToTime(timestamp?: number | string): Date & {
|
|
|
61
49
|
* ```
|
|
62
50
|
*/
|
|
63
51
|
export declare const formatDuration: (seconds: number) => string;
|
|
64
|
-
/**
|
|
65
|
-
* @description: Format a number of seconds as a colon-separated duration
|
|
66
|
-
* @deprecated Renamed to [`formatDuration`](#formatduration) — `timeFormat` said nothing about
|
|
67
|
-
* *which* of the three time formats it was, and read backwards from its `formatDate` sibling.
|
|
68
|
-
* This alias stays for compatibility and behaves identically.
|
|
69
|
-
* @param {number} time
|
|
70
|
-
* @return {string}
|
|
71
|
-
*/
|
|
72
|
-
export declare const timeFormat: (time: number) => string;
|
|
73
52
|
/**
|
|
74
53
|
* @description: Parse a WebVTT/SRT-style timestamp — `HH:MM:SS.mmm` or `MM:SS.mmm` (the hour
|
|
75
54
|
* component is optional) — into seconds. The inverse of [`formatDuration`](#formatduration),
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var o = (e, r = 2) => String(e).padStart(r, "0"), l = (e) => e == null ? /* @__PURE__ */ new Date() : new Date(e), T = /YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|SSS|A|a|\[([^[\]]*)]/g, w = (e, r = "YYYY-MM-DD HH:mm:ss") => {
|
|
2
|
+
const t = l(e);
|
|
3
|
+
if (Number.isNaN(t.getTime())) return "Invalid Date";
|
|
4
|
+
const n = t.getHours(), a = n % 12 || 12, m = {
|
|
5
|
+
YYYY: String(t.getFullYear()),
|
|
6
|
+
YY: o(t.getFullYear() % 100),
|
|
7
|
+
MM: o(t.getMonth() + 1),
|
|
8
|
+
M: String(t.getMonth() + 1),
|
|
9
|
+
DD: o(t.getDate()),
|
|
10
|
+
D: String(t.getDate()),
|
|
11
|
+
HH: o(n),
|
|
12
|
+
H: String(n),
|
|
13
|
+
hh: o(a),
|
|
14
|
+
h: String(a),
|
|
15
|
+
mm: o(t.getMinutes()),
|
|
16
|
+
m: String(t.getMinutes()),
|
|
17
|
+
ss: o(t.getSeconds()),
|
|
18
|
+
s: String(t.getSeconds()),
|
|
19
|
+
SSS: o(t.getMilliseconds(), 3),
|
|
20
|
+
A: n < 12 ? "AM" : "PM",
|
|
21
|
+
a: n < 12 ? "am" : "pm"
|
|
22
|
+
};
|
|
23
|
+
return r.replace(T, (d, u) => u !== void 0 ? u : m[d]);
|
|
24
|
+
}, y = (e) => {
|
|
25
|
+
if (!Number.isFinite(e)) return "";
|
|
26
|
+
const r = Math.max(0, Math.trunc(e)), t = Math.trunc(r / 3600), n = Math.trunc(r % 3600 / 60), a = o(r % 60);
|
|
27
|
+
return t === 0 ? `${o(n)}:${a}` : `${o(t)}:${o(n)}:${a}`;
|
|
28
|
+
}, b = /(?:(\d{2,}):)?(\d{2}):(\d{2})\.(\d{3})/, Y = (e) => {
|
|
29
|
+
const r = e.trim().match(b);
|
|
30
|
+
if (!r) return;
|
|
31
|
+
const [, t, n, a, m] = r;
|
|
32
|
+
return (t ? Number(t) * 3600 : 0) + Number(n) * 60 + Number(a) + Number(m) / 1e3;
|
|
33
|
+
}, H = (e) => {
|
|
34
|
+
const [r, t] = e.split("-->");
|
|
35
|
+
if (!r || !t) return;
|
|
36
|
+
const n = Y(r), a = Y(t.trim().split(/\s+/)[0] ?? "");
|
|
37
|
+
if (!(n === void 0 || a === void 0))
|
|
38
|
+
return {
|
|
39
|
+
start: n,
|
|
40
|
+
end: a
|
|
41
|
+
};
|
|
42
|
+
}, c = [
|
|
43
|
+
["year", 315576e5],
|
|
44
|
+
["month", 26298e5],
|
|
45
|
+
["week", 6048e5],
|
|
46
|
+
["day", 864e5],
|
|
47
|
+
["hour", 36e5],
|
|
48
|
+
["minute", 6e4],
|
|
49
|
+
["second", 1e3]
|
|
50
|
+
], D = {
|
|
51
|
+
year: "y",
|
|
52
|
+
quarter: "q",
|
|
53
|
+
month: "mo",
|
|
54
|
+
week: "w",
|
|
55
|
+
day: "d",
|
|
56
|
+
hour: "h",
|
|
57
|
+
minute: "m",
|
|
58
|
+
second: "s"
|
|
59
|
+
}, N = /* @__PURE__ */ new Map(), $ = (e, r, t) => {
|
|
60
|
+
if (typeof Intl > "u" || typeof Intl.RelativeTimeFormat != "function") return;
|
|
61
|
+
const n = `${String(e)}|${r}|${t}`;
|
|
62
|
+
let a = N.get(n);
|
|
63
|
+
return a || (a = new Intl.RelativeTimeFormat(e, {
|
|
64
|
+
style: r,
|
|
65
|
+
numeric: t
|
|
66
|
+
}), N.set(n, a)), a;
|
|
67
|
+
}, I = (e, r = {}) => {
|
|
68
|
+
const { now: t, locale: n, style: a = "long", numeric: m = "auto" } = r, d = l(e).getTime(), u = l(t).getTime();
|
|
69
|
+
if (Number.isNaN(d) || Number.isNaN(u)) return "";
|
|
70
|
+
const v = d - u, M = Math.abs(v);
|
|
71
|
+
let s = c.findIndex(([, h]) => M >= h);
|
|
72
|
+
s === -1 && (s = c.length - 1);
|
|
73
|
+
const p = v < 0 ? -1 : 1;
|
|
74
|
+
let [g, f] = c[s], i = p * Math.round(M / f);
|
|
75
|
+
if (s > 0 && Math.abs(i) * f >= c[s - 1][1] && ([g, f] = c[s - 1], i = p * Math.round(M / f)), a === "compact") return `${Math.abs(i)}${D[g] ?? ""}`;
|
|
76
|
+
const S = $(n, a, m);
|
|
77
|
+
if (!S) {
|
|
78
|
+
const h = D[g] ?? "";
|
|
79
|
+
return i < 0 ? `${Math.abs(i)}${h} ago` : `in ${i}${h}`;
|
|
80
|
+
}
|
|
81
|
+
return S.format(i, g);
|
|
82
|
+
}, F = () => {
|
|
83
|
+
if (typeof document < "u") return performance.now();
|
|
84
|
+
if (typeof process < "u") {
|
|
85
|
+
const [e, r] = process.hrtime();
|
|
86
|
+
return e * 1e3 + r / 1e6;
|
|
87
|
+
}
|
|
88
|
+
return Date.now();
|
|
89
|
+
};
|
|
90
|
+
export {
|
|
91
|
+
w as formatDate,
|
|
92
|
+
y as formatDuration,
|
|
93
|
+
I as formatRelative,
|
|
94
|
+
H as parseVttCueTiming,
|
|
95
|
+
Y as parseVttTimestamp,
|
|
96
|
+
F as performanceTime
|
|
97
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EncodingType, FixedLengthOptionsEncodingType, FixedLengthOptionsNoEncodingType, FormatNoTextType, FormatType, GenericInputType, packedValue } from
|
|
1
|
+
import type { EncodingType, FixedLengthOptionsEncodingType, FixedLengthOptionsNoEncodingType, FormatNoTextType, FormatType, GenericInputType, packedValue } from "./custom_types.js";
|
|
2
2
|
export declare const TWO_PWR_32 = 4294967296;
|
|
3
3
|
export declare const K_sha2: number[];
|
|
4
4
|
export declare const H_trunc: number[];
|