ranuts 0.4.1-alpha.1 → 0.5.0
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 +178 -26
- 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 -90
- package/README.pt.md +62 -0
- package/README.zh-CN.md +35 -89
- 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 +306 -1
- package/dist/src/_virtual/_rolldown/runtime/index.js +12 -0
- package/dist/src/conversation/engine.d.ts +109 -0
- package/dist/src/conversation/engine.js +101 -0
- package/dist/src/conversation/index.d.ts +12 -0
- package/dist/src/conversation/index.js +4 -0
- package/dist/src/conversation/types.d.ts +99 -0
- package/dist/src/stream/accumulator.d.ts +51 -0
- package/dist/src/stream/accumulator.js +79 -0
- package/dist/src/stream/budget.d.ts +89 -0
- package/dist/src/stream/budget.js +45 -0
- package/dist/src/stream/index.d.ts +25 -0
- package/dist/src/stream/index.js +11 -0
- package/dist/src/stream/sse.d.ts +51 -0
- package/dist/src/stream/sse.js +61 -0
- package/dist/src/stream/types.d.ts +106 -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.d.ts +1 -0
- package/dist/src/utils/canvas.js +103 -0
- package/dist/src/utils/chain.js +76 -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.d.ts +51 -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 +81 -77
- package/dist/src/utils/index.js +306 -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.d.ts +20 -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.d.ts +42 -5
- 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 +1 -1
- package/dist/src/utils/script.js +46 -0
- package/dist/src/utils/scroll.d.ts +93 -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 -6
- package/dist/src/utils/str.js +395 -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 +86 -65
- package/package.json +20 -15
- 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-B_KMM8UX.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-BJIS1fR1.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/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/encodeUrl.test.d.ts +0 -1
- package/dist/test/escapeHtml.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/server.test.d.ts +0 -1
- package/dist/test/status.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-BNwhohXq.js +0 -1
- package/dist/vite.config.d.ts +0 -8
- package/dist/vitest.config.d.ts +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./src/utils/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1 +1,306 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createBottomFollower as r } from "./src/utils/scroll.js";
|
|
2
|
+
import { diffLines as t } from "./src/utils/diff.js";
|
|
3
|
+
import { SyncHook as i } from "./src/utils/subscribe.js";
|
|
4
|
+
import { MessageCodec as n, arrayBufferToString as s, checkEncoding as p, clearBr as l, clearStr as c, csvEscape as g, fenceCode as f, getMatchingSentences as d, getRandomString as u, isString as T, randomString as h, slugify as b, strParse as R, toFullWidth as E, toHalfWidth as S, toString as y, transformText as B, truncate as A, truncateWithMarker as H } from "./src/utils/str.js";
|
|
5
|
+
import { Mathjs as D, addNumSym as C, clamp as x, fit as v, formatBytes as I, inverseLerp as P, lerp as L, linearstep as U, mathjs as F, parseChineseNumber as O, parseEnglishNumber as _, parseRomanNumber as k, perToNum as w, range as G, remap as N, smoothstep as q, transformNumber as W } from "./src/utils/number.js";
|
|
6
|
+
import { createSpeechRecognizer as Z, isSpeechRecognitionSupported as Q } from "./src/utils/speech.js";
|
|
7
|
+
import { formatDate as j, formatDuration as K, formatRelative as V, parseVttCueTiming as Y, parseVttTimestamp as J, performanceTime as $ } from "./src/utils/time.js";
|
|
8
|
+
import { appendUrl as re, connection as oe, createObjectURL as te, durationHandler as ae, encodeUrl as ie, getAllQueryString as me, getCookie as ne, getCookieByName as se, getFrame as pe, getPixelRatio as le, getWindow as ce, imageRequest as ge, isInIframe as fe, isSafari as de, networkSpeed as ue, queryFlag as Te, requestUrlToBuffer as he } from "./src/utils/bom.js";
|
|
9
|
+
import { BRIDGE_MARKER as Re, BridgeManager as Ee, Client as Se, DEFAULT_CHANNEL as ye, Platform as Be, PostMessageBridge as Ae, acceptPortBridge as He, bridgeManager as Me, createPortBridge as De, openPortBridge as Ce } from "./src/utils/bridge.js";
|
|
10
|
+
import { once as ve, singleFlight as Ie } from "./src/utils/memoize.js";
|
|
11
|
+
import { noop as Le } from "./src/utils/noop.js";
|
|
12
|
+
import { cloneDeep as Fe, filterObj as Oe, formatJson as _e, isEqual as ke, merge as we, mergeExports as Ge, querystring as Ne, replaceOld as qe } from "./src/utils/obj.js";
|
|
13
|
+
import { MimeType as ze, getExtensions as Ze, getMime as Qe, setMime as Xe } from "./src/utils/mimeType.js";
|
|
14
|
+
import { AudioRecorder as Ke } from "./src/utils/audioRecorder.js";
|
|
15
|
+
import { createSignal as Ye, subscribers as Je } from "./src/utils/signal.js";
|
|
16
|
+
import { TOTP as er } from "./src/utils/totp/totp.js";
|
|
17
|
+
import { createStore as or, localStorageGetItem as tr, localStorageRemoveItem as ar, localStorageSetItem as ir } from "./src/utils/storage.js";
|
|
18
|
+
import { compose as nr } from "./src/utils/compose.js";
|
|
19
|
+
import { handleConsole as pr } from "./src/utils/console.js";
|
|
20
|
+
import { debounce as cr } from "./src/utils/debounce.js";
|
|
21
|
+
import { MOBILE_MEDIA_QUERY as fr, currentDevice as dr, isMobile as ur, isWeiXin as Tr, matchMediaQuery as hr, watchMediaQuery as br } from "./src/utils/device.js";
|
|
22
|
+
import { Chain as Er, create as Sr } from "./src/utils/chain.js";
|
|
23
|
+
import { addClassToElement as Br, autosizeTextarea as Ar, createDocumentFragment as Hr, escapeHtml as Mr, removeClassToElement as Dr, setFontSize2html as Cr } from "./src/utils/dom.js";
|
|
24
|
+
import { handleError as vr } from "./src/utils/error.js";
|
|
25
|
+
import { EventManager as Pr, createDoubleTapDetector as Lr } from "./src/utils/event.js";
|
|
26
|
+
import { circ as Fr, cubic as Or, expo as _r, quad as kr, quart as wr, quint as Gr, sine as Nr } from "./src/utils/tween.js";
|
|
27
|
+
import { fanShapedByArc as Wr, getAngle as zr, getArcPointerByDeg as Zr, getLinearGradient as Qr, getTangentByPointer as Xr, roundRectByArc as jr } from "./src/utils/canvas.js";
|
|
28
|
+
import { convertImageToBase64 as Vr, cutRound as Yr, getImage as Jr, getMatrix as $r, isImageSize as eo, opacity as ro } from "./src/utils/img.js";
|
|
29
|
+
import { ADOPTED_SHEET_MARKER as to, ADOPTED_STYLE_MARKER as ao, adoptSheetText as io, adoptStyles as mo } from "./src/utils/style.js";
|
|
30
|
+
import { WebDB as so, createHandoff as po } from "./src/utils/idb.js";
|
|
31
|
+
import { buildOffsets as co, indexForOffset as go, segmentByRanges as fo } from "./src/utils/segment.js";
|
|
32
|
+
import { paginateText as To } from "./src/utils/paginate.js";
|
|
33
|
+
import { detectLanguage as bo, navigatorLanguage as Ro, resolveLocale as Eo } from "./src/utils/lang.js";
|
|
34
|
+
import { I18nCore as yo, createI18n as Bo, useI18n as Ao } from "./src/utils/i18n/index.js";
|
|
35
|
+
import { createLocalePath as Mo } from "./src/utils/localePath.js";
|
|
36
|
+
import { alignCrossAxis as Co, computePlacement as xo } from "./src/utils/placement.js";
|
|
37
|
+
import { readFileAsArrayBuffer as Io, readFileAsDataURL as Po, readFileAsText as Lo, readFileAsUint8Array as Uo } from "./src/utils/file.js";
|
|
38
|
+
import { base64ToBytes as Oo, base64UrlToBytes as _o, bytesToBase64 as ko, bytesToBase64Url as wo, concatBytes as Go, decodeTextBytes as No, fetchMaybeGzip as qo, gunzipMaybe as Wo, isGzip as zo, isHtmlDocument as Zo, isZipContainer as Qo, saveFileToDisk as Xo } from "./src/utils/binary.js";
|
|
39
|
+
import { UNAMBIGUOUS_ALPHABET as Ko, safeEqual as Vo, secureRandomString as Yo, secureToken as Jo } from "./src/utils/secure.js";
|
|
40
|
+
import { WorkerClient as et, serveWorker as rt } from "./src/utils/worker.js";
|
|
41
|
+
import { isUrlCached as tt, networkAllowsDownload as at, prefetchUrl as it, prefetchUrls as mt, prefetchWhenIdle as nt, whenIdle as st } from "./src/utils/prefetch.js";
|
|
42
|
+
import { TimeoutError as lt, createRaceGuard as ct, deferred as gt, delay as ft, withTimeout as dt, withTimeoutFallback as ut } from "./src/utils/async.js";
|
|
43
|
+
import { ZIP_DEFLATE as ht, ZIP_STORED as bt, crc32 as Rt, createZip as Et, inflateRaw as St, readZipEntries as yt, readZipEntry as Bt, rewriteZip as At, zipHasEntry as Ht } from "./src/utils/zip.js";
|
|
44
|
+
import { getPerformance as Dt } from "./src/utils/performance.js";
|
|
45
|
+
import { createData as xt, getReportUrl as vt, report as It, setReportUrl as Pt } from "./src/utils/report.js";
|
|
46
|
+
import { handleFetchHook as Ut, handleXhrHook as Ft } from "./src/utils/request.js";
|
|
47
|
+
import { throttle as _t } from "./src/utils/throttle.js";
|
|
48
|
+
import { Monitor as wt } from "./src/utils/monitor.js";
|
|
49
|
+
import { getStatus as Nt, status as qt } from "./src/utils/network.js";
|
|
50
|
+
import { QuestQueue as zt } from "./src/utils/queue.js";
|
|
51
|
+
import { loadScript as Qt, scriptOnLoad as Xt } from "./src/utils/script.js";
|
|
52
|
+
import { Color as Kt, ColorScheme as Vt, HEX_COLOR_REGEX as Yt, Hsl as Jt, Hsla as $t, RGBA_REGEX as ea, RGB_REGEX as ra, Rgb as oa, Rgba as ta, blendMultiply as aa, blendOverlay as ia, blendScreen as ma, brightnessContrast as na, componentToHex as sa, cosinePalette as pa, hexToAlpha as la, hexToHsb as ca, hexToHsv as ga, hexToRgb as fa, hsbToHsl as da, hsbToRgb as ua, hslToHsb as Ta, hslToHsv as ha, hslToRgb as ba, hsvToHsl as Ra, hsvToRgb as Ea, hue2rgb as Sa, linearToSrgb as ya, luma as Ba, randomColor as Aa, rgbToHex as Ha, rgbToHsb as Ma, rgbToHsl as Da, rgbToHsv as Ca, rgbaString as xa, rgbaToHex as va, rgbaToRgb as Ia, saturation as Pa, srgbToLinear as La, vibrance as Ua } from "./src/utils/color.js";
|
|
53
|
+
export {
|
|
54
|
+
to as ADOPTED_SHEET_MARKER,
|
|
55
|
+
ao as ADOPTED_STYLE_MARKER,
|
|
56
|
+
Ke as AudioRecorder,
|
|
57
|
+
Re as BRIDGE_MARKER,
|
|
58
|
+
Ee as BridgeManager,
|
|
59
|
+
Er as Chain,
|
|
60
|
+
Se as Client,
|
|
61
|
+
Kt as Color,
|
|
62
|
+
Vt as ColorScheme,
|
|
63
|
+
ye as DEFAULT_CHANNEL,
|
|
64
|
+
Pr as EventManager,
|
|
65
|
+
Yt as HEX_COLOR_REGEX,
|
|
66
|
+
Jt as Hsl,
|
|
67
|
+
$t as Hsla,
|
|
68
|
+
yo as I18nCore,
|
|
69
|
+
fr as MOBILE_MEDIA_QUERY,
|
|
70
|
+
D as Mathjs,
|
|
71
|
+
n as MessageCodec,
|
|
72
|
+
ze as MimeType,
|
|
73
|
+
wt as Monitor,
|
|
74
|
+
Be as Platform,
|
|
75
|
+
Ae as PostMessageBridge,
|
|
76
|
+
zt as QuestQueue,
|
|
77
|
+
ea as RGBA_REGEX,
|
|
78
|
+
ra as RGB_REGEX,
|
|
79
|
+
oa as Rgb,
|
|
80
|
+
ta as Rgba,
|
|
81
|
+
i as SyncHook,
|
|
82
|
+
er as TOTP,
|
|
83
|
+
lt as TimeoutError,
|
|
84
|
+
Ko as UNAMBIGUOUS_ALPHABET,
|
|
85
|
+
so as WebDB,
|
|
86
|
+
et as WorkerClient,
|
|
87
|
+
ht as ZIP_DEFLATE,
|
|
88
|
+
bt as ZIP_STORED,
|
|
89
|
+
He as acceptPortBridge,
|
|
90
|
+
Br as addClassToElement,
|
|
91
|
+
C as addNumSym,
|
|
92
|
+
io as adoptSheetText,
|
|
93
|
+
mo as adoptStyles,
|
|
94
|
+
Co as alignCrossAxis,
|
|
95
|
+
re as appendUrl,
|
|
96
|
+
s as arrayBufferToString,
|
|
97
|
+
Ar as autosizeTextarea,
|
|
98
|
+
Oo as base64ToBytes,
|
|
99
|
+
_o as base64UrlToBytes,
|
|
100
|
+
aa as blendMultiply,
|
|
101
|
+
ia as blendOverlay,
|
|
102
|
+
ma as blendScreen,
|
|
103
|
+
Me as bridgeManager,
|
|
104
|
+
na as brightnessContrast,
|
|
105
|
+
co as buildOffsets,
|
|
106
|
+
ko as bytesToBase64,
|
|
107
|
+
wo as bytesToBase64Url,
|
|
108
|
+
p as checkEncoding,
|
|
109
|
+
Fr as circ,
|
|
110
|
+
x as clamp,
|
|
111
|
+
l as clearBr,
|
|
112
|
+
c as clearStr,
|
|
113
|
+
Fe as cloneDeep,
|
|
114
|
+
sa as componentToHex,
|
|
115
|
+
nr as compose,
|
|
116
|
+
xo as computePlacement,
|
|
117
|
+
Go as concatBytes,
|
|
118
|
+
oe as connection,
|
|
119
|
+
Vr as convertImageToBase64,
|
|
120
|
+
pa as cosinePalette,
|
|
121
|
+
Rt as crc32,
|
|
122
|
+
Sr as create,
|
|
123
|
+
r as createBottomFollower,
|
|
124
|
+
xt as createData,
|
|
125
|
+
Hr as createDocumentFragment,
|
|
126
|
+
Lr as createDoubleTapDetector,
|
|
127
|
+
po as createHandoff,
|
|
128
|
+
Bo as createI18n,
|
|
129
|
+
Mo as createLocalePath,
|
|
130
|
+
te as createObjectURL,
|
|
131
|
+
De as createPortBridge,
|
|
132
|
+
ct as createRaceGuard,
|
|
133
|
+
Ye as createSignal,
|
|
134
|
+
Z as createSpeechRecognizer,
|
|
135
|
+
or as createStore,
|
|
136
|
+
Et as createZip,
|
|
137
|
+
g as csvEscape,
|
|
138
|
+
Or as cubic,
|
|
139
|
+
dr as currentDevice,
|
|
140
|
+
Yr as cutRound,
|
|
141
|
+
cr as debounce,
|
|
142
|
+
No as decodeTextBytes,
|
|
143
|
+
gt as deferred,
|
|
144
|
+
ft as delay,
|
|
145
|
+
bo as detectLanguage,
|
|
146
|
+
t as diffLines,
|
|
147
|
+
ae as durationHandler,
|
|
148
|
+
ie as encodeUrl,
|
|
149
|
+
Mr as escapeHtml,
|
|
150
|
+
_r as expo,
|
|
151
|
+
Wr as fanShapedByArc,
|
|
152
|
+
f as fenceCode,
|
|
153
|
+
qo as fetchMaybeGzip,
|
|
154
|
+
Oe as filterObj,
|
|
155
|
+
v as fit,
|
|
156
|
+
I as formatBytes,
|
|
157
|
+
j as formatDate,
|
|
158
|
+
K as formatDuration,
|
|
159
|
+
_e as formatJson,
|
|
160
|
+
V as formatRelative,
|
|
161
|
+
me as getAllQueryString,
|
|
162
|
+
zr as getAngle,
|
|
163
|
+
Zr as getArcPointerByDeg,
|
|
164
|
+
ne as getCookie,
|
|
165
|
+
se as getCookieByName,
|
|
166
|
+
Ze as getExtensions,
|
|
167
|
+
pe as getFrame,
|
|
168
|
+
Jr as getImage,
|
|
169
|
+
Qr as getLinearGradient,
|
|
170
|
+
d as getMatchingSentences,
|
|
171
|
+
$r as getMatrix,
|
|
172
|
+
Qe as getMime,
|
|
173
|
+
Dt as getPerformance,
|
|
174
|
+
le as getPixelRatio,
|
|
175
|
+
u as getRandomString,
|
|
176
|
+
vt as getReportUrl,
|
|
177
|
+
Nt as getStatus,
|
|
178
|
+
Xr as getTangentByPointer,
|
|
179
|
+
ce as getWindow,
|
|
180
|
+
Wo as gunzipMaybe,
|
|
181
|
+
pr as handleConsole,
|
|
182
|
+
vr as handleError,
|
|
183
|
+
Ut as handleFetchHook,
|
|
184
|
+
Ft as handleXhrHook,
|
|
185
|
+
la as hexToAlpha,
|
|
186
|
+
ca as hexToHsb,
|
|
187
|
+
ga as hexToHsv,
|
|
188
|
+
fa as hexToRgb,
|
|
189
|
+
da as hsbToHsl,
|
|
190
|
+
ua as hsbToRgb,
|
|
191
|
+
Ta as hslToHsb,
|
|
192
|
+
ha as hslToHsv,
|
|
193
|
+
ba as hslToRgb,
|
|
194
|
+
Ra as hsvToHsl,
|
|
195
|
+
Ea as hsvToRgb,
|
|
196
|
+
Sa as hue2rgb,
|
|
197
|
+
ge as imageRequest,
|
|
198
|
+
go as indexForOffset,
|
|
199
|
+
St as inflateRaw,
|
|
200
|
+
P as inverseLerp,
|
|
201
|
+
ke as isEqual,
|
|
202
|
+
zo as isGzip,
|
|
203
|
+
Zo as isHtmlDocument,
|
|
204
|
+
eo as isImageSize,
|
|
205
|
+
fe as isInIframe,
|
|
206
|
+
ur as isMobile,
|
|
207
|
+
de as isSafari,
|
|
208
|
+
Q as isSpeechRecognitionSupported,
|
|
209
|
+
T as isString,
|
|
210
|
+
tt as isUrlCached,
|
|
211
|
+
Tr as isWeiXin,
|
|
212
|
+
Qo as isZipContainer,
|
|
213
|
+
L as lerp,
|
|
214
|
+
ya as linearToSrgb,
|
|
215
|
+
U as linearstep,
|
|
216
|
+
Qt as loadScript,
|
|
217
|
+
tr as localStorageGetItem,
|
|
218
|
+
ar as localStorageRemoveItem,
|
|
219
|
+
ir as localStorageSetItem,
|
|
220
|
+
Ba as luma,
|
|
221
|
+
hr as matchMediaQuery,
|
|
222
|
+
F as mathjs,
|
|
223
|
+
we as merge,
|
|
224
|
+
Ge as mergeExports,
|
|
225
|
+
Ro as navigatorLanguage,
|
|
226
|
+
at as networkAllowsDownload,
|
|
227
|
+
ue as networkSpeed,
|
|
228
|
+
Le as noop,
|
|
229
|
+
ve as once,
|
|
230
|
+
ro as opacity,
|
|
231
|
+
Ce as openPortBridge,
|
|
232
|
+
To as paginateText,
|
|
233
|
+
O as parseChineseNumber,
|
|
234
|
+
_ as parseEnglishNumber,
|
|
235
|
+
k as parseRomanNumber,
|
|
236
|
+
Y as parseVttCueTiming,
|
|
237
|
+
J as parseVttTimestamp,
|
|
238
|
+
w as perToNum,
|
|
239
|
+
$ as performanceTime,
|
|
240
|
+
it as prefetchUrl,
|
|
241
|
+
mt as prefetchUrls,
|
|
242
|
+
nt as prefetchWhenIdle,
|
|
243
|
+
kr as quad,
|
|
244
|
+
wr as quart,
|
|
245
|
+
Te as queryFlag,
|
|
246
|
+
Ne as querystring,
|
|
247
|
+
Gr as quint,
|
|
248
|
+
Aa as randomColor,
|
|
249
|
+
h as randomString,
|
|
250
|
+
G as range,
|
|
251
|
+
Io as readFileAsArrayBuffer,
|
|
252
|
+
Po as readFileAsDataURL,
|
|
253
|
+
Lo as readFileAsText,
|
|
254
|
+
Uo as readFileAsUint8Array,
|
|
255
|
+
yt as readZipEntries,
|
|
256
|
+
Bt as readZipEntry,
|
|
257
|
+
N as remap,
|
|
258
|
+
Dr as removeClassToElement,
|
|
259
|
+
qe as replaceOld,
|
|
260
|
+
It as report,
|
|
261
|
+
he as requestUrlToBuffer,
|
|
262
|
+
Eo as resolveLocale,
|
|
263
|
+
At as rewriteZip,
|
|
264
|
+
Ha as rgbToHex,
|
|
265
|
+
Ma as rgbToHsb,
|
|
266
|
+
Da as rgbToHsl,
|
|
267
|
+
Ca as rgbToHsv,
|
|
268
|
+
xa as rgbaString,
|
|
269
|
+
va as rgbaToHex,
|
|
270
|
+
Ia as rgbaToRgb,
|
|
271
|
+
jr as roundRectByArc,
|
|
272
|
+
Vo as safeEqual,
|
|
273
|
+
Pa as saturation,
|
|
274
|
+
Xo as saveFileToDisk,
|
|
275
|
+
Xt as scriptOnLoad,
|
|
276
|
+
Yo as secureRandomString,
|
|
277
|
+
Jo as secureToken,
|
|
278
|
+
fo as segmentByRanges,
|
|
279
|
+
rt as serveWorker,
|
|
280
|
+
Cr as setFontSize2html,
|
|
281
|
+
Xe as setMime,
|
|
282
|
+
Pt as setReportUrl,
|
|
283
|
+
Nr as sine,
|
|
284
|
+
Ie as singleFlight,
|
|
285
|
+
b as slugify,
|
|
286
|
+
q as smoothstep,
|
|
287
|
+
La as srgbToLinear,
|
|
288
|
+
qt as status,
|
|
289
|
+
R as strParse,
|
|
290
|
+
Je as subscribers,
|
|
291
|
+
_t as throttle,
|
|
292
|
+
E as toFullWidth,
|
|
293
|
+
S as toHalfWidth,
|
|
294
|
+
y as toString,
|
|
295
|
+
W as transformNumber,
|
|
296
|
+
B as transformText,
|
|
297
|
+
A as truncate,
|
|
298
|
+
H as truncateWithMarker,
|
|
299
|
+
Ao as useI18n,
|
|
300
|
+
Ua as vibrance,
|
|
301
|
+
br as watchMediaQuery,
|
|
302
|
+
st as whenIdle,
|
|
303
|
+
dt as withTimeout,
|
|
304
|
+
ut as withTimeoutFallback,
|
|
305
|
+
Ht as zipHasEntry
|
|
306
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine that runs {@link ConversationNodeDefinition}s over an event log.
|
|
3
|
+
*/
|
|
4
|
+
import type { ConversationNode, ConversationNodeDefinition } from "./types.js";
|
|
5
|
+
/** Defers work to the next paint, or to a microtask where there is no paint. */
|
|
6
|
+
export type FrameScheduler = (run: () => void) => () => void;
|
|
7
|
+
/** How to construct an engine. */
|
|
8
|
+
export interface ConversationEngineOptions<Event> {
|
|
9
|
+
/**
|
|
10
|
+
* The registered definitions. Every event is offered to all of them, so two definitions
|
|
11
|
+
* may both claim one event — that is how a single log event can drive, say, both a
|
|
12
|
+
* message node and a separate status node.
|
|
13
|
+
*
|
|
14
|
+
* Declared over `unknown` state so definitions with different state types register side
|
|
15
|
+
* by side; a concrete `ConversationNodeDefinition<Event, MyState>` assigns here without
|
|
16
|
+
* a cast, and its own methods stay fully typed at the definition site.
|
|
17
|
+
*/
|
|
18
|
+
definitions: readonly ConversationNodeDefinition<Event, unknown>[];
|
|
19
|
+
/** Overrides frame scheduling; supply a manual one to make cadence deterministic in tests. */
|
|
20
|
+
scheduler?: FrameScheduler;
|
|
21
|
+
}
|
|
22
|
+
/** A running conversation projection. */
|
|
23
|
+
export interface ConversationEngine<Event> {
|
|
24
|
+
/**
|
|
25
|
+
* Offers one event to every definition and notifies subscribers per the resulting
|
|
26
|
+
* cadence.
|
|
27
|
+
*
|
|
28
|
+
* @param event The event to project.
|
|
29
|
+
*/
|
|
30
|
+
push(event: Event): void;
|
|
31
|
+
/**
|
|
32
|
+
* Runs a burst of pushes as one publication.
|
|
33
|
+
*
|
|
34
|
+
* Without it, replaying a stored conversation is quadratic: every event publishes, every
|
|
35
|
+
* publication hands subscribers the whole node list, and a DOM subscriber walks all of it
|
|
36
|
+
* — so restoring n messages costs O(n²) row visits, each re-writing content that has not
|
|
37
|
+
* changed. Measured on a 600-message transcript that was 5.4 seconds of blocked main
|
|
38
|
+
* thread; the same replay batched is one pass.
|
|
39
|
+
*
|
|
40
|
+
* The cadence of the single publication is the highest any event in the burst asked for,
|
|
41
|
+
* which is the same escalation rule that applies within one event. A burst that accepted
|
|
42
|
+
* nothing publishes nothing.
|
|
43
|
+
*
|
|
44
|
+
* Nesting is flat: an inner batch joins the outer one rather than publishing early.
|
|
45
|
+
*
|
|
46
|
+
* @param run The pushes to run.
|
|
47
|
+
*/
|
|
48
|
+
batch(run: () => void): void;
|
|
49
|
+
/** @returns The current nodes, ordered by the event that started each one. */
|
|
50
|
+
nodes(): readonly ConversationNode[];
|
|
51
|
+
/**
|
|
52
|
+
* Registers a subscriber.
|
|
53
|
+
*
|
|
54
|
+
* @param listener Called with the current nodes whenever a publication lands, and with
|
|
55
|
+
* the keys whose state changed since the previous publication. A subscriber that writes
|
|
56
|
+
* to the DOM should touch only those: on a long transcript the node list is mostly
|
|
57
|
+
* unchanged every frame, and rewriting all of it once per delta is the difference
|
|
58
|
+
* between a transcript that streams and one that stalls. `undefined` means every node
|
|
59
|
+
* changed, which is what a reset reports.
|
|
60
|
+
* @returns A function that removes the subscriber.
|
|
61
|
+
*/
|
|
62
|
+
subscribe(listener: (nodes: readonly ConversationNode[], changed: ReadonlySet<string> | undefined) => void): () => void;
|
|
63
|
+
/**
|
|
64
|
+
* Drops one node and every node started after it.
|
|
65
|
+
*
|
|
66
|
+
* This is what editing, regenerating, and branching are made of: all three mean "the
|
|
67
|
+
* conversation diverges here", and what follows the divergence is no longer part of it.
|
|
68
|
+
* Without this the only way back is {@link ConversationEngine.reset} and a full replay,
|
|
69
|
+
* which throws away every node that did not change and makes the view flash.
|
|
70
|
+
*
|
|
71
|
+
* Ordering is by `seq` — when a node opened — not by position, so a node that has been
|
|
72
|
+
* updating since before the cut survives even though its latest update came after it.
|
|
73
|
+
* That is the same rule the node order itself follows.
|
|
74
|
+
*
|
|
75
|
+
* @param key The `kind:id` of the first node to drop.
|
|
76
|
+
* @returns How many nodes were dropped. Zero means the key names no live node, which is
|
|
77
|
+
* a caller's cue that its own idea of the conversation is stale — silently dropping
|
|
78
|
+
* nothing would leave the old tail on screen under freshly pushed events.
|
|
79
|
+
*/
|
|
80
|
+
truncate(key: string): number;
|
|
81
|
+
/** Drops every node and pending publication, keeping the definitions. */
|
|
82
|
+
reset(): void;
|
|
83
|
+
/** Cancels any pending publication and drops subscribers. */
|
|
84
|
+
destroy(): void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates an engine over a set of definitions.
|
|
88
|
+
*
|
|
89
|
+
* Semantics worth knowing before writing a definition:
|
|
90
|
+
*
|
|
91
|
+
* - **Every definition sees every event.** Claims are independent; the engine never stops
|
|
92
|
+
* at the first match.
|
|
93
|
+
* - **An `update` claim for an id with no open node is dropped.** That is the honest
|
|
94
|
+
* outcome when the start event was never seen — trimmed from a paged window, or emitted
|
|
95
|
+
* before the definition was registered — and inventing a node from a partial update
|
|
96
|
+
* would render something that never existed.
|
|
97
|
+
* - **Order is fixed at `start`.** A node that keeps updating stays where it opened, so a
|
|
98
|
+
* streaming message does not jump to the end of the list on every delta.
|
|
99
|
+
* - **Cadence escalates, never relaxes.** An `immediate` publication while a frame is
|
|
100
|
+
* pending fires now and cancels the frame; an `animation-frame` publication while one is
|
|
101
|
+
* already pending joins it.
|
|
102
|
+
* - **`truncate` cuts by `seq`, not by position.** A node that opened before the cut
|
|
103
|
+
* survives even if its most recent update came after it — the same rule node order
|
|
104
|
+
* follows, so what a reader sees above the cut is exactly what stays.
|
|
105
|
+
*
|
|
106
|
+
* @param options Definitions and optional scheduler.
|
|
107
|
+
* @returns The engine.
|
|
108
|
+
*/
|
|
109
|
+
export declare function createConversationEngine<Event>(options: ConversationEngineOptions<Event>): ConversationEngine<Event>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var A = (m) => {
|
|
2
|
+
if (typeof requestAnimationFrame == "function") {
|
|
3
|
+
const q = requestAnimationFrame(m);
|
|
4
|
+
return () => cancelAnimationFrame(q);
|
|
5
|
+
}
|
|
6
|
+
let a = !1;
|
|
7
|
+
return queueMicrotask(() => {
|
|
8
|
+
a || m();
|
|
9
|
+
}), () => {
|
|
10
|
+
a = !0;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
function F(m) {
|
|
14
|
+
const { definitions: a, scheduler: q = A } = m, g = /* @__PURE__ */ new Set();
|
|
15
|
+
for (const e of a) {
|
|
16
|
+
if (g.has(e.kind)) throw new Error(`conversation: duplicate definition kind "${e.kind}"`);
|
|
17
|
+
g.add(e.kind);
|
|
18
|
+
}
|
|
19
|
+
let t = [];
|
|
20
|
+
const d = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Set();
|
|
21
|
+
let c = /* @__PURE__ */ new Set(), y = 0, r = null, p = 0, u = "none", f = null;
|
|
22
|
+
const w = () => (f ??= t.map((e) => Object.freeze({ ...e })), f), v = () => {
|
|
23
|
+
const e = w(), n = c === null ? void 0 : new Set(c);
|
|
24
|
+
c = /* @__PURE__ */ new Set();
|
|
25
|
+
for (const i of [...h]) i(e, n);
|
|
26
|
+
}, k = (e) => {
|
|
27
|
+
if (e !== "none") {
|
|
28
|
+
if (p > 0) {
|
|
29
|
+
e === "immediate" ? u = "immediate" : u === "none" && (u = "animation-frame");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (e === "immediate") {
|
|
33
|
+
r?.(), r = null, v();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
r === null && (r = q(() => {
|
|
37
|
+
r = null, v();
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}, x = { previous(e) {
|
|
41
|
+
for (let n = t.length - 1; n >= 0; n -= 1) if (t[n].kind === e) return Object.freeze({ ...t[n] });
|
|
42
|
+
} };
|
|
43
|
+
return {
|
|
44
|
+
push(e) {
|
|
45
|
+
let n = "none";
|
|
46
|
+
for (const i of a) {
|
|
47
|
+
const s = i.match(e);
|
|
48
|
+
if (s === null) continue;
|
|
49
|
+
const o = `${i.kind}:${s.id}`, l = d.get(o);
|
|
50
|
+
if (s.role === "start") {
|
|
51
|
+
const b = {
|
|
52
|
+
key: o,
|
|
53
|
+
kind: i.kind,
|
|
54
|
+
id: s.id,
|
|
55
|
+
seq: l?.seq ?? (y += 1),
|
|
56
|
+
state: i.start(e, x)
|
|
57
|
+
};
|
|
58
|
+
l === void 0 ? t.push(b) : t[t.indexOf(l)] = b, d.set(o, b);
|
|
59
|
+
} else if (l !== void 0) l.state = i.update(l.state, e);
|
|
60
|
+
else continue;
|
|
61
|
+
f = null, c?.add(o);
|
|
62
|
+
const S = i.publication?.(e) ?? "immediate";
|
|
63
|
+
S === "immediate" ? n = "immediate" : S === "animation-frame" && n === "none" && (n = "animation-frame");
|
|
64
|
+
}
|
|
65
|
+
k(n);
|
|
66
|
+
},
|
|
67
|
+
truncate(e) {
|
|
68
|
+
const n = d.get(e);
|
|
69
|
+
if (n === void 0) return 0;
|
|
70
|
+
const i = t.filter((o) => o.seq < n.seq), s = t.length - i.length;
|
|
71
|
+
for (const o of t) o.seq >= n.seq && d.delete(o.key);
|
|
72
|
+
return t = i, f = null, k("immediate"), s;
|
|
73
|
+
},
|
|
74
|
+
batch(e) {
|
|
75
|
+
p += 1;
|
|
76
|
+
try {
|
|
77
|
+
e();
|
|
78
|
+
} finally {
|
|
79
|
+
if (p -= 1, p === 0) {
|
|
80
|
+
const n = u;
|
|
81
|
+
u = "none", k(n);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
nodes: w,
|
|
86
|
+
subscribe(e) {
|
|
87
|
+
return h.add(e), () => {
|
|
88
|
+
h.delete(e);
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
reset() {
|
|
92
|
+
t = [], d.clear(), y = 0, f = null, c = null, k("immediate");
|
|
93
|
+
},
|
|
94
|
+
destroy() {
|
|
95
|
+
r?.(), r = null, h.clear();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
F as createConversationEngine
|
|
101
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ranuts/conversation` — project an append-only event log into renderable nodes.
|
|
3
|
+
*
|
|
4
|
+
* Pairs with `ranuts/stream`, which produces the events, and with `createBottomFollower`
|
|
5
|
+
* from `ranuts/utils`, which keeps the resulting view pinned to its floor. No DOM here:
|
|
6
|
+
* the projection is testable, and server-renderable, on its own.
|
|
7
|
+
*
|
|
8
|
+
* @module ranuts/conversation
|
|
9
|
+
*/
|
|
10
|
+
export type { ConversationMatch, ConversationNode, ConversationNodeDefinition, ConversationPublication, ConversationReader, } from "./types.js";
|
|
11
|
+
export type { ConversationEngine, ConversationEngineOptions, FrameScheduler } from "./engine.js";
|
|
12
|
+
export { createConversationEngine } from "./engine.js";
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vocabulary for turning an append-only event log into the nodes a conversation view
|
|
3
|
+
* renders.
|
|
4
|
+
*
|
|
5
|
+
* The alternative — a view that switches on event type and mutates a component tree — puts
|
|
6
|
+
* ordering, identity, and partial-update reconciliation in the view, where every new kind
|
|
7
|
+
* of content has to be threaded through by hand. Here each kind of content is an
|
|
8
|
+
* independently registered state machine: it says which events are its own, folds them
|
|
9
|
+
* into its own state, and never learns that the others exist. Adding a kind is adding a
|
|
10
|
+
* definition, not editing a renderer.
|
|
11
|
+
*
|
|
12
|
+
* @module ranuts/conversation
|
|
13
|
+
*/
|
|
14
|
+
/** A definition's claim on one event. */
|
|
15
|
+
export interface ConversationMatch {
|
|
16
|
+
/**
|
|
17
|
+
* Identity of the node this event belongs to, unique within the definition's `kind`.
|
|
18
|
+
* The same id across events is what makes an update an update.
|
|
19
|
+
*/
|
|
20
|
+
id: string;
|
|
21
|
+
/** `start` opens a node; `update` folds into the one already open under `id`. */
|
|
22
|
+
role: 'start' | 'update';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* When subscribers should see the result of one accepted event.
|
|
26
|
+
*
|
|
27
|
+
* This is the throttle for streaming. A text delta arriving per token wants
|
|
28
|
+
* `animation-frame`, which coalesces every delta between two paints into one
|
|
29
|
+
* notification; a discrete fact — a tool result, an approval — wants `immediate`, because
|
|
30
|
+
* it is one event and waiting a frame only adds latency. `none` records the event without
|
|
31
|
+
* waking the view at all, for state a later publication will carry anyway.
|
|
32
|
+
*/
|
|
33
|
+
export type ConversationPublication = 'none' | 'animation-frame' | 'immediate';
|
|
34
|
+
/** One live node, as a view sees it. */
|
|
35
|
+
export interface ConversationNode<State = unknown> {
|
|
36
|
+
/** `kind:id` — stable for the node's whole life, and unique across definitions. */
|
|
37
|
+
readonly key: string;
|
|
38
|
+
readonly kind: string;
|
|
39
|
+
readonly id: string;
|
|
40
|
+
/**
|
|
41
|
+
* Ordinal of the event that started this node. Nodes are ordered by it, so a node that
|
|
42
|
+
* updates for a long time — a streaming message — keeps its place instead of jumping to
|
|
43
|
+
* the end on every delta.
|
|
44
|
+
*/
|
|
45
|
+
readonly seq: number;
|
|
46
|
+
readonly state: State;
|
|
47
|
+
}
|
|
48
|
+
/** Strictly-backward lookup offered to a definition while it starts a node. */
|
|
49
|
+
export interface ConversationReader {
|
|
50
|
+
/**
|
|
51
|
+
* Finds the most recently started node of `kind` that already exists.
|
|
52
|
+
*
|
|
53
|
+
* Backward only, and deliberately: a definition that could see nodes started after it
|
|
54
|
+
* would produce a different result depending on when it ran, and replaying the same log
|
|
55
|
+
* would not reproduce the same view.
|
|
56
|
+
*
|
|
57
|
+
* @param kind The definition kind to look for.
|
|
58
|
+
* @returns The nearest preceding node, or undefined when none is open.
|
|
59
|
+
*/
|
|
60
|
+
previous<State>(kind: string): ConversationNode<State> | undefined;
|
|
61
|
+
}
|
|
62
|
+
/** One independently registered event-to-node state machine. */
|
|
63
|
+
export interface ConversationNodeDefinition<Event, State> {
|
|
64
|
+
/** Namespace for this definition's node ids. Must be unique in one engine. */
|
|
65
|
+
readonly kind: string;
|
|
66
|
+
/**
|
|
67
|
+
* Decides whether this event is this definition's business.
|
|
68
|
+
*
|
|
69
|
+
* Runs against the raw event with no access to engine state, so it stays a pure
|
|
70
|
+
* classification and cannot depend on what has been rendered so far.
|
|
71
|
+
*
|
|
72
|
+
* @param event The event being offered.
|
|
73
|
+
* @returns The claim, or null to ignore the event.
|
|
74
|
+
*/
|
|
75
|
+
match(event: Event): ConversationMatch | null;
|
|
76
|
+
/**
|
|
77
|
+
* Builds the initial state for a newly opened node.
|
|
78
|
+
*
|
|
79
|
+
* @param event The event that started it.
|
|
80
|
+
* @param reader Backward lookup over nodes already open.
|
|
81
|
+
* @returns The node's initial state.
|
|
82
|
+
*/
|
|
83
|
+
start(event: Event, reader: ConversationReader): State;
|
|
84
|
+
/**
|
|
85
|
+
* Folds one further event into an open node.
|
|
86
|
+
*
|
|
87
|
+
* @param state The node's current state.
|
|
88
|
+
* @param event The event being folded in.
|
|
89
|
+
* @returns The node's next state.
|
|
90
|
+
*/
|
|
91
|
+
update(state: State, event: Event): State;
|
|
92
|
+
/**
|
|
93
|
+
* Chooses when subscribers see this event's result. Defaults to `immediate`.
|
|
94
|
+
*
|
|
95
|
+
* @param event The accepted event.
|
|
96
|
+
* @returns The requested cadence.
|
|
97
|
+
*/
|
|
98
|
+
publication?(event: Event): ConversationPublication;
|
|
99
|
+
}
|