ranuts 0.4.0-alpha.1 → 0.4.0-alpha.3
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 +40 -4
- package/README.md +11 -16
- package/README.zh-CN.md +11 -16
- package/dist/{color-Dohr9BXX.js → color-DPV7TsVU.js} +1 -1
- package/dist/i18n-Bq-f7htr.js +1 -0
- package/dist/index.js +1 -1
- package/dist/src/node/index.js +1 -1
- package/dist/src/utils/async.d.ts +30 -0
- package/dist/src/utils/behavior.d.ts +0 -14
- package/dist/src/utils/bom.d.ts +2 -22
- package/dist/src/utils/color.d.ts +75 -0
- package/dist/src/utils/device.d.ts +0 -1
- package/dist/src/utils/dom.d.ts +26 -0
- package/dist/src/utils/event.d.ts +34 -0
- package/dist/src/utils/i18n/index.js +1 -1
- package/dist/src/utils/i18n.d.ts +64 -14
- package/dist/src/utils/index.d.ts +22 -16
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/number.d.ts +60 -0
- package/dist/src/utils/obj.d.ts +0 -11
- package/dist/src/utils/placement.d.ts +40 -0
- package/dist/src/utils/speech.d.ts +86 -0
- package/dist/src/utils/str.d.ts +35 -8
- package/dist/src/utils/time.d.ts +104 -2
- package/dist/src/utils/visual/application.d.ts +10 -0
- package/dist/src/utils/visual/index.d.ts +5 -2
- package/dist/src/utils/visual/index.js +1 -1
- package/dist/src/utils/visual/render/filter.d.ts +43 -0
- package/dist/src/utils/visual/render/render.d.ts +6 -0
- package/dist/src/utils/visual/render/renderTarget.d.ts +13 -0
- package/dist/src/utils/visual/render/utils/earcut.d.ts +45 -0
- package/dist/src/utils/visual/render/webGlRenderer.d.ts +4 -0
- package/dist/test/utils/autosize.test.d.ts +1 -0
- package/dist/test/utils/color-grade.test.d.ts +1 -0
- package/dist/test/utils/event.test.d.ts +1 -0
- package/dist/test/utils/i18n.test.d.ts +1 -0
- package/dist/test/utils/interp.test.d.ts +1 -0
- package/dist/test/utils/placement.test.d.ts +1 -0
- package/dist/test/utils/speech.test.d.ts +1 -0
- package/dist/test/utils/time.test.d.ts +1 -0
- package/dist/test/utils/truncate.test.d.ts +1 -0
- package/dist/test/utils/visual/filter.test.d.ts +1 -0
- package/dist/umd/index.umd.cjs +1 -1
- package/dist/umd/node/node.umd.cjs +1 -1
- package/dist/umd/utils/utils.umd.cjs +1 -1
- package/dist/utils-CYrYCt5o.js +1 -0
- package/docs/API.md +67 -26
- package/package.json +24 -13
- package/dist/i18n-Cf5TtRb4.js +0 -1
- package/dist/utils-8TVtLBjA.js +0 -1
package/dist/src/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as s}from"../../enums-BAgbyGdH.js";import{
|
|
1
|
+
import{i as s}from"../../enums-BAgbyGdH.js";import{$ as a,A as t,B as n,C as o,D as r,E as m,F as i,G as p,H as f,I as j,J as c,K as l,L as u,M as h,N as b,O as d,P as e,Q as g,R as v,S as x,T as y,U as _,V as k,W as w,X as z,Y as A,Z as B,_ as C,a as D,at as E,b as F,c as H,d as I,et as L,f as M,g as N,h as P,i as R,it as S,j as T,k as U,l as V,m as q,n as G,nt as J,o as K,ot as O,p as Q,q as W,r as X,rt as Y,s as Z,st as $,t as ss,tt as as,u as ts,v as ns,w as os,x as rs,y as ms,z as is}from"../../color-DPV7TsVU.js";import{$ as ps,$t as fs,A as js,At as cs,B as ls,Bt as us,C as hs,Ct as bs,D as ds,Dt as es,E as gs,Et as vs,F as xs,Ft as ys,G as _s,Gt as ks,H as ws,Ht as zs,I as As,It as Bs,J as Cs,Jt as Ds,K as Es,Kt as Fs,L as Hs,Lt as Is,M as Ls,Mt as Ms,N as Ns,Nt as Ps,O as Rs,Ot as Ss,P as Ts,Pt as Us,Q as Vs,Qt as qs,R as Gs,Rt as Js,S as Ks,St as Os,T as Qs,Tt as Ws,U as Xs,Ut as Ys,V as Zs,Vt as $s,W as sa,Wt as aa,X as ta,Xt as na,Y as oa,Yt as ra,Z as ma,Zt as ia,_ as pa,_n as fa,_t as ja,a as ca,an as la,at as ua,b as ha,bn as ba,bt as da,c as ea,cn as ga,ct as va,d as xa,dn as ya,dt as _a,en as ka,et as wa,f as za,fn as Aa,ft as Ba,g as Ca,gn as Da,gt as Ea,h as Fa,hn as Ha,ht as Ia,i as La,in as Ma,it as Na,j as Pa,jt as Ra,k as Sa,kt as Ta,l as Ua,ln as Va,lt as qa,m as Ga,mn as Ja,mt as Ka,n as Oa,nn as Qa,nt as Wa,o as Xa,on as Ya,ot as Za,p as $a,pn as st,pt as at,q as tt,qt as nt,r as ot,rn as rt,rt as mt,s as it,sn as pt,st as ft,t as jt,tn as ct,tt as lt,u as ut,un as ht,ut as bt,v as dt,vn as et,vt as gt,w as vt,wt as xt,x as yt,xt as _t,y as kt,yn as wt,yt as zt,z as At,zt as Bt}from"../../utils-CYrYCt5o.js";import{A as Ct,B as Dt,C as Et,D as Ft,E as Ht,F as It,H as Lt,I as Mt,L as Nt,M as Pt,N as Rt,P as St,R as Tt,S as Ut,T as Vt,U as qt,V as Gt,_ as Jt,a as Kt,b as Ot,c as Qt,d as Wt,f as Xt,g as Yt,h as Zt,i as $t,j as sn,k as an,l as tn,m as nn,n as on,o as rn,p as mn,r as pn,s as fn,t as jn,u as cn,v as ln,w as un,x as hn,y as bn,z as dn}from"../../i18n-Bq-f7htr.js";import{n as en,t as gn}from"../../chain-CTywmh_H.js";export{ta as ADOPTED_SHEET_MARKER,ma as ADOPTED_STYLE_MARKER,Us as AudioRecorder,nt as BRIDGE_MARKER,Ds as BridgeManager,gn as Chain,ra as Client,ss as Color,G as ColorScheme,na as DEFAULT_CHANNEL,zt as EventManager,X as FMT,R as HEX_COLOR_REGEX,D as Hsl,K as Hsla,jn as I18nCore,an as MOBILE_MEDIA_QUERY,la as Mathjs,l as MessageCodec,f as MimeType,Xa as Monitor,ia as Platform,qs as PostMessageBridge,ot as QuestQueue,Z as RGBA_REGEX,H as RGB_REGEX,V as Rgb,ts as Rgba,s as SyncHook,Ra as TOTP,vt as TimeoutError,Cs as WebDB,As as WorkerClient,Fa as ZIP_DEFLATE,Ca as ZIP_STORED,fs as acceptPortBridge,Os as addClassToElement,Ya as addNumSym,Vs as adoptSheetText,ps as adoptStyles,Wt as appendUrl,W as arrayBufferToString,bs as autosizeTextarea,I as blendMultiply,M as blendOverlay,Q as blendScreen,ka as bridgeManager,q as brightnessContrast,_s as buildOffsets,c as checkEncoding,Ba as circ,pt as clamp,A as clearBr,z as clearStr,ys as cloneDeep,P as componentToHex,cs as compose,ws as computePlacement,Xt as connection,wa as convertImageToBase64,N as cosinePalette,pa as crc32,en as create,ut as createData,xt as createDocumentFragment,da as createDoubleTapDetector,oa as createHandoff,on as createI18n,Xs as createLocalePath,mn as createObjectURL,ct as createPortBridge,Qs as createRaceGuard,Ms as createSignal,rt as createSpeechRecognizer,fn as createStore,dt as createZip,at as cubic,Ct as currentDevice,lt as cutRound,Ss as debounce,gs as deferred,ds as delay,$t as detectLanguage,nn as durationHandler,Zt as encodeUrl,Ws as escapeHtml,Ka as expo,Za as fanShapedByArc,Bs as filterObj,ga as fit,Mt as formatDate,Nt as formatDuration,Is as formatJson,Tt as formatRelative,Yt as getAllQueryString,ft as getAngle,va as getArcPointerByDeg,Jt as getCookie,ln as getCookieByName,_ as getExtensions,bn as getFrame,Wa as getImage,qa as getLinearGradient,B as getMatchingSentences,mt as getMatrix,w as getMime,Ga as getPerformance,Ot as getPixelRatio,g as getRandomString,xa as getReportUrl,La as getStatus,bt as getTangentByPointer,hn as getWindow,Ta as handleConsole,_t as handleError,ea as handleFetchHook,Ua as handleXhrHook,C as hexToAlpha,ns as hexToHsb,ms as hexToHsv,F as hexToRgb,rs as hsbToHsl,x as hsbToRgb,o as hslToHsb,os as hslToHsv,y as hslToRgb,m as hsvToHsl,r as hsvToRgb,d as hue2rgb,Ut as imageRequest,Es as indexForOffset,kt as inflateRaw,Va as inverseLerp,sn as isClient,Js as isEqual,Na as isImageSize,Et as isInIframe,Pt as isMobile,un as isSafari,Ma as isSpeechRecognitionSupported,a as isString,js as isUrlCached,Rt as isWeiXin,ht as lerp,U as linearToSrgb,ya as linearstep,jt as loadScript,Qt as localStorageGetItem,tn as localStorageRemoveItem,cn as localStorageSetItem,t as luma,St as matchMediaQuery,Aa as mathjs,L as md5,aa as memoize,Bt as merge,us as mergeExports,Kt as navigatorLanguage,Pa as networkAllowsDownload,Vt as networkSpeed,Ys as noop,ks as once,ua as opacity,Qa as openPortBridge,sa as paginateText,st as parseChineseNumber,Ja as parseEnglishNumber,Ha as parseRomanNumber,dn as parseVttCueTiming,Dt as parseVttTimestamp,Da as perToNum,Gt as performanceTime,Ls as prefetchUrl,Ns as prefetchUrls,Ts as prefetchWhenIdle,Ia as quad,Ea as quart,Ht as queryFlag,$s as querystring,ja as quint,T as randomColor,as as randomString,fa as range,Gs as readFileAsArrayBuffer,At as readFileAsDataURL,ls as readFileAsText,Zs as readFileAsUint8Array,ha as readZipEntries,yt as readZipEntry,et as remap,vs as removeClassToElement,zs as replaceOld,za as report,Ft as requestUrlToBuffer,rn as resolveLocale,Ks as rewriteZip,h as rgbToHex,b as rgbToHsb,e as rgbToHsl,i as rgbToHsv,j as rgbaString,u as rgbaToHex,v as rgbaToRgb,_a as roundRectByArc,is as saturation,Oa as scriptOnLoad,tt as segmentByRanges,Hs as serveWorker,es as setFontSize2html,p as setMime,$a as setReportUrl,gt as sine,Fs as singleFlight,wt as smoothstep,n as srgbToLinear,ca as status,J as strParse,Ps as subscribers,it as throttle,Lt as timeFormat,qt as timestampToTime,Y as toFullWidth,S as toHalfWidth,E as toString,ba as transformNumber,O as transformText,$ as truncate,pn as useI18n,k as vibrance,It as watchMediaQuery,xs as whenIdle,Rs as withTimeout,Sa as withTimeoutFallback,hs as zipHasEntry};
|
|
@@ -79,4 +79,64 @@ export declare const parseRomanNumber: (value: string) => number | null;
|
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
81
81
|
export declare const parseEnglishNumber: (value: string) => number | null;
|
|
82
|
+
/**
|
|
83
|
+
* @description: Clamp `value` into the inclusive range `[min, max]`.
|
|
84
|
+
* @param {number} value
|
|
85
|
+
* @param {number} min
|
|
86
|
+
* @param {number} max
|
|
87
|
+
* @return {number}
|
|
88
|
+
*/
|
|
89
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
90
|
+
/**
|
|
91
|
+
* @description: Linear interpolation from `a` to `b` by `t` (t=0 → a, t=1 → b). Not clamped.
|
|
92
|
+
* @param {number} a start value
|
|
93
|
+
* @param {number} b end value
|
|
94
|
+
* @param {number} t interpolation factor
|
|
95
|
+
* @return {number}
|
|
96
|
+
*/
|
|
97
|
+
export declare const lerp: (a: number, b: number, t: number) => number;
|
|
98
|
+
/**
|
|
99
|
+
* @description: Inverse of `lerp` — where `value` sits between `a` and `b`, as 0..1. Returns 0 when `a === b`. Not clamped.
|
|
100
|
+
* @param {number} a start value
|
|
101
|
+
* @param {number} b end value
|
|
102
|
+
* @param {number} value probed value
|
|
103
|
+
* @return {number}
|
|
104
|
+
*/
|
|
105
|
+
export declare const inverseLerp: (a: number, b: number, value: number) => number;
|
|
106
|
+
/**
|
|
107
|
+
* @description: Linearly remap `value` from range `[a1, a2]` onto `[b1, b2]`. Not clamped (GLSL-style map).
|
|
108
|
+
* @param {number} value
|
|
109
|
+
* @param {number} a1 input range start
|
|
110
|
+
* @param {number} a2 input range end
|
|
111
|
+
* @param {number} b1 output range start
|
|
112
|
+
* @param {number} b2 output range end
|
|
113
|
+
* @return {number}
|
|
114
|
+
*/
|
|
115
|
+
export declare const remap: (value: number, a1: number, a2: number, b1: number, b2: number) => number;
|
|
116
|
+
/**
|
|
117
|
+
* @description: Remap `value` from `[a1, a2]` onto `[b1, b2]` and clamp to the output range — the shader `fit`.
|
|
118
|
+
* @param {number} value
|
|
119
|
+
* @param {number} a1 input range start
|
|
120
|
+
* @param {number} a2 input range end
|
|
121
|
+
* @param {number} b1 output range start
|
|
122
|
+
* @param {number} b2 output range end
|
|
123
|
+
* @return {number}
|
|
124
|
+
*/
|
|
125
|
+
export declare const fit: (value: number, a1: number, a2: number, b1: number, b2: number) => number;
|
|
126
|
+
/**
|
|
127
|
+
* @description: Linear ramp — 0 below `edge0`, 1 above `edge1`, a straight line between (the shader `linearstep`, no smoothing).
|
|
128
|
+
* @param {number} edge0
|
|
129
|
+
* @param {number} edge1
|
|
130
|
+
* @param {number} x
|
|
131
|
+
* @return {number}
|
|
132
|
+
*/
|
|
133
|
+
export declare const linearstep: (edge0: number, edge1: number, x: number) => number;
|
|
134
|
+
/**
|
|
135
|
+
* @description: Smooth Hermite interpolation between 0 and 1 for `edge0 < x < edge1` (GLSL `smoothstep`).
|
|
136
|
+
* @param {number} edge0
|
|
137
|
+
* @param {number} edge1
|
|
138
|
+
* @param {number} x
|
|
139
|
+
* @return {number}
|
|
140
|
+
*/
|
|
141
|
+
export declare const smoothstep: (edge0: number, edge1: number, x: number) => number;
|
|
82
142
|
export {};
|
package/dist/src/utils/obj.d.ts
CHANGED
|
@@ -64,20 +64,9 @@ export declare function replaceOld(source: any, name: string, replacement: (...a
|
|
|
64
64
|
* @return {Object}
|
|
65
65
|
*/
|
|
66
66
|
export declare const mergeExports: (obj: Record<string, string>, exports: Record<string, string>) => Record<string, string>;
|
|
67
|
-
/**
|
|
68
|
-
* @description: Define a property on the global object
|
|
69
|
-
* @param {string} name
|
|
70
|
-
* @param {string} value
|
|
71
|
-
* @return {*}
|
|
72
|
-
*/
|
|
73
|
-
export declare const setAttributeByGlobal: (name: string, value: unknown) => void;
|
|
74
67
|
/**
|
|
75
68
|
* Deep-compare two values, in the manner of Lodash's isEqual.
|
|
76
69
|
*/
|
|
77
|
-
/**
|
|
78
|
-
* Whether two primitives are the same value, handling the special cases NaN and -0/+0.
|
|
79
|
-
*/
|
|
80
|
-
export declare function sameValueZero(x: any, y: any): boolean;
|
|
81
70
|
/**
|
|
82
71
|
* Whether the value is object-like
|
|
83
72
|
*/
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type Placement = 'top' | 'bottom' | 'left' | 'right';
|
|
2
|
+
export interface PlacementRect {
|
|
3
|
+
top: number;
|
|
4
|
+
left: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ComputePlacementOptions {
|
|
9
|
+
/** Anchor (trigger) rect, in viewport coordinates (e.g. `getBoundingClientRect()`). */
|
|
10
|
+
anchor: PlacementRect;
|
|
11
|
+
/** The floating panel's own size. */
|
|
12
|
+
floating: {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
/** Preferred side. Flips to the opposite side when it lacks room and the opposite side has more. */
|
|
17
|
+
placement: Placement;
|
|
18
|
+
/** Gap kept between the anchor and the floating panel, in px. */
|
|
19
|
+
offset?: number;
|
|
20
|
+
/** Region the panel must stay inside, in viewport coordinates. Defaults to the window viewport. */
|
|
21
|
+
boundary?: PlacementRect;
|
|
22
|
+
/** Minimum gap kept between the panel and the boundary edge when shifting, in px. */
|
|
23
|
+
padding?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface ComputedPlacement {
|
|
26
|
+
top: number;
|
|
27
|
+
left: number;
|
|
28
|
+
/** The side actually used, after flip. */
|
|
29
|
+
placement: Placement;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Position a floating panel relative to an anchor rect: flips to the opposite
|
|
33
|
+
* side when the preferred side doesn't have room and the opposite side has
|
|
34
|
+
* more, then shifts along the cross axis to stay within `boundary`. Mirrors
|
|
35
|
+
* Floating UI's `flip`/`shift` middleware, minus the dependency.
|
|
36
|
+
*
|
|
37
|
+
* Coordinates are viewport-relative throughout (same space as `anchor`); the
|
|
38
|
+
* caller adds `scrollX`/`scrollY` when writing `position: absolute` styles.
|
|
39
|
+
*/
|
|
40
|
+
export declare const computePlacement: (options: ComputePlacementOptions) => ComputedPlacement;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Speech recognition (dictation) over the Web Speech API.
|
|
3
|
+
*
|
|
4
|
+
* This is the counterpart to `AudioRecorder`, which captures audio *bytes*; this one asks the
|
|
5
|
+
* platform to turn speech into *text*. The browser API is still prefixed on WebKit, is absent
|
|
6
|
+
* from `lib.dom`, and reports several routine non-events (a silent pause, a programmatic stop)
|
|
7
|
+
* through the same error channel as a denied microphone — so it is worth wrapping once.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* `denied` means the user or the browser refused the microphone — worth surfacing.
|
|
11
|
+
* `noSpeech` and `aborted` are routine (a silent pause, a programmatic `stop()`) and are
|
|
12
|
+
* usually not worth showing anyone; they are reported rather than swallowed so the caller
|
|
13
|
+
* decides. Everything else is `failed`.
|
|
14
|
+
*/
|
|
15
|
+
export type SpeechErrorKind = 'denied' | 'noSpeech' | 'aborted' | 'failed';
|
|
16
|
+
export interface SpeechError {
|
|
17
|
+
kind: SpeechErrorKind;
|
|
18
|
+
/** The raw `error` string from the platform event. */
|
|
19
|
+
detail: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SpeechRecognizerOptions {
|
|
22
|
+
/**
|
|
23
|
+
* BCP 47 tag for the language being spoken, e.g. `'en-US'`, `'zh-CN'`. Pass a function to
|
|
24
|
+
* have it read at the start of each capture, which is what an app whose UI language can
|
|
25
|
+
* change mid-session wants.
|
|
26
|
+
*/
|
|
27
|
+
lang?: string | (() => string);
|
|
28
|
+
/** Keep listening across pauses instead of stopping at the first one. Default `true`. */
|
|
29
|
+
continuous?: boolean;
|
|
30
|
+
/** Emit partial results as the speaker talks. Default `true`. */
|
|
31
|
+
interimResults?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Called as text arrives, with the transcript of the **whole capture so far** — not just
|
|
34
|
+
* the newest fragment — because interim results are revised as recognition firms up.
|
|
35
|
+
*/
|
|
36
|
+
onResult?: (transcript: string, isFinal: boolean) => void;
|
|
37
|
+
onError?: (error: SpeechError) => void;
|
|
38
|
+
onStart?: () => void;
|
|
39
|
+
/** Fires once per capture, however it ended: stopped, timed out, or errored. */
|
|
40
|
+
onEnd?: () => void;
|
|
41
|
+
}
|
|
42
|
+
export interface SpeechRecognizer {
|
|
43
|
+
/** `false` when the platform has no speech recognition; every method is then a no-op. */
|
|
44
|
+
readonly supported: boolean;
|
|
45
|
+
/** Whether a capture is currently running. */
|
|
46
|
+
readonly active: boolean;
|
|
47
|
+
/** Begin a capture. Ignored if one is already running. */
|
|
48
|
+
start(): void;
|
|
49
|
+
/** End the current capture; results already recognized are kept. `onEnd` follows. */
|
|
50
|
+
stop(): void;
|
|
51
|
+
/** End the current capture and discard pending results. */
|
|
52
|
+
abort(): void;
|
|
53
|
+
/** Start if idle, stop if running — the behaviour a single microphone button wants. */
|
|
54
|
+
toggle(): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description: Whether this runtime can recognize speech. Checked at call time, so it is safe
|
|
58
|
+
* to import this module during server-side rendering.
|
|
59
|
+
* @return {boolean}
|
|
60
|
+
*/
|
|
61
|
+
export declare const isSpeechRecognitionSupported: () => boolean;
|
|
62
|
+
/**
|
|
63
|
+
* @description: Create a dictation session over the Web Speech API.
|
|
64
|
+
*
|
|
65
|
+
* A recognizer is reusable: `start` builds a fresh native instance each time, so options read
|
|
66
|
+
* through a function (notably `lang`) are re-read per capture.
|
|
67
|
+
*
|
|
68
|
+
* On a platform without speech recognition this returns an inert recognizer with
|
|
69
|
+
* `supported === false` rather than throwing — check that field to hide your microphone button.
|
|
70
|
+
*
|
|
71
|
+
* @param {SpeechRecognizerOptions} options
|
|
72
|
+
* @return {SpeechRecognizer}
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const mic = createSpeechRecognizer({
|
|
76
|
+
* lang: () => currentLocale(),
|
|
77
|
+
* onResult: (text) => { input.value = text; },
|
|
78
|
+
* onError: (e) => { if (e.kind === 'denied') toast('Microphone access was refused'); },
|
|
79
|
+
* onEnd: () => button.classList.remove('recording'),
|
|
80
|
+
* onStart: () => button.classList.add('recording'),
|
|
81
|
+
* });
|
|
82
|
+
* if (!mic.supported) button.style.display = 'none';
|
|
83
|
+
* button.addEventListener('click', () => mic.toggle());
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare const createSpeechRecognizer: (options?: SpeechRecognizerOptions) => SpeechRecognizer;
|
package/dist/src/utils/str.d.ts
CHANGED
|
@@ -12,16 +12,8 @@ export declare const strParse: (str?: string, sep?: string | RegExp, eq?: string
|
|
|
12
12
|
* @return {string} the resulting plain text
|
|
13
13
|
*/
|
|
14
14
|
export declare const clearBr: (str?: string) => string;
|
|
15
|
-
/**
|
|
16
|
-
* @description: Parse a string into XML using the given MIME type
|
|
17
|
-
* @param {string} xmlStr
|
|
18
|
-
* @param {DOMParserSupportedType} format
|
|
19
|
-
* @return {Document}
|
|
20
|
-
*/
|
|
21
|
-
export declare const str2Xml: (xmlStr: string, format?: DOMParserSupportedType) => HTMLElement | undefined;
|
|
22
15
|
export declare const isString: (obj: unknown) => boolean;
|
|
23
16
|
export declare function randomString(len?: number): string;
|
|
24
|
-
export declare function changeHumpToLowerCase(str: string): string;
|
|
25
17
|
interface ClearStrOption {
|
|
26
18
|
urlencoded?: boolean;
|
|
27
19
|
}
|
|
@@ -64,6 +56,41 @@ export declare const toHalfWidth: (value: string) => string;
|
|
|
64
56
|
* @return {string}
|
|
65
57
|
*/
|
|
66
58
|
export declare const toFullWidth: (value: string) => string;
|
|
59
|
+
/** Which end of the string gets dropped when it is too long. */
|
|
60
|
+
export type TruncatePosition = 'end' | 'start' | 'middle';
|
|
61
|
+
export interface TruncateOptions {
|
|
62
|
+
/** Ceiling for the returned string, ellipsis included. */
|
|
63
|
+
length: number;
|
|
64
|
+
/** Default `'end'`. */
|
|
65
|
+
position?: TruncatePosition;
|
|
66
|
+
/** Default `'…'`. */
|
|
67
|
+
ellipsis?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @description: Shorten a string to a maximum length, marking the cut with an ellipsis.
|
|
71
|
+
*
|
|
72
|
+
* `position` decides which end survives, and that choice carries real information:
|
|
73
|
+
*
|
|
74
|
+
* - `'end'` (default) keeps the beginning — right for prose and titles.
|
|
75
|
+
* - `'start'` keeps the **tail**, which is what a file path wants. `/Users/someone/work/…`
|
|
76
|
+
* are the bytes a reader already knows; `…/src/utils/str.ts` is the part they need.
|
|
77
|
+
* - `'middle'` keeps both ends, for identifiers whose head *and* tail are meaningful, such as
|
|
78
|
+
* a hash or an account number.
|
|
79
|
+
*
|
|
80
|
+
* The result never exceeds `length`, so a `length` shorter than the ellipsis returns a
|
|
81
|
+
* truncated ellipsis rather than overflowing.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} value
|
|
84
|
+
* @param {TruncateOptions | number} options a bare number is shorthand for `{ length }`
|
|
85
|
+
* @return {string}
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* truncate('the quick brown fox', 12); // 'the quick b…'
|
|
89
|
+
* truncate('/Users/me/code/app/src/index.ts', { length: 20, position: 'start' }); // '…de/app/src/index.ts'
|
|
90
|
+
* truncate('0xabcdef0123456789', { length: 11, position: 'middle' }); // '0xabc…56789'
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare const truncate: (value: string, options: TruncateOptions | number) => string;
|
|
67
94
|
export interface TransformText {
|
|
68
95
|
encoding: string;
|
|
69
96
|
content: string;
|
package/dist/src/utils/time.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Accepted everywhere a moment in time is taken; `undefined` means "now". */
|
|
2
|
+
export type DateInput = number | string | Date;
|
|
1
3
|
/**
|
|
2
4
|
* @description: Format a date with a token pattern. Accepts a timestamp, a date string, a
|
|
3
5
|
* `Date`, or nothing (meaning now). Wrap literal text in `[]` to keep it out of the substitution.
|
|
@@ -26,7 +28,7 @@
|
|
|
26
28
|
* formatDate(new Date(), 'YYYY[年]MM[月]DD[日] hh:mm a'); // '2026年07月25日 02:30 pm' (escaped literals)
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
|
-
export declare const formatDate: (value?:
|
|
31
|
+
export declare const formatDate: (value?: DateInput, pattern?: string) => string;
|
|
30
32
|
/**
|
|
31
33
|
* @description: Turn a timestamp into a `Date` carrying a `format` method.
|
|
32
34
|
* @deprecated Use [`formatDate`](#formatdate). This returns a `Date` with an extra method
|
|
@@ -39,12 +41,112 @@ export declare const formatDate: (value?: number | string | Date, pattern?: stri
|
|
|
39
41
|
export declare function timestampToTime(timestamp?: number | string): Date & {
|
|
40
42
|
format?: Function;
|
|
41
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* @description: Format an elapsed number of **seconds** as a colon-separated clock duration,
|
|
46
|
+
* the shape media players use for a playhead: `mm:ss`, widening to `hh:mm:ss` past an hour.
|
|
47
|
+
*
|
|
48
|
+
* This is a length of time, not a point in time — for the latter see
|
|
49
|
+
* [`formatDate`](#formatdate) (absolute) and [`formatRelative`](#formatrelative) (relative).
|
|
50
|
+
*
|
|
51
|
+
* @param {number} seconds elapsed seconds; negatives clamp to `0`
|
|
52
|
+
* @return {string} the duration, or `''` when the input is not a finite number — a player
|
|
53
|
+
* asks for `video.duration` before metadata loads and gets `NaN`, and an empty label reads
|
|
54
|
+
* better there than `NaN:NaN`
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* formatDuration(0); // '00:00'
|
|
58
|
+
* formatDuration(65); // '01:05'
|
|
59
|
+
* formatDuration(3661); // '01:01:01'
|
|
60
|
+
* formatDuration(NaN); // ''
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const formatDuration: (seconds: number) => string;
|
|
42
64
|
/**
|
|
43
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.
|
|
44
69
|
* @param {number} time
|
|
45
|
-
* @return {
|
|
70
|
+
* @return {string}
|
|
46
71
|
*/
|
|
47
72
|
export declare const timeFormat: (time: number) => string;
|
|
73
|
+
/**
|
|
74
|
+
* @description: Parse a WebVTT/SRT-style timestamp — `HH:MM:SS.mmm` or `MM:SS.mmm` (the hour
|
|
75
|
+
* component is optional) — into seconds. The inverse of [`formatDuration`](#formatduration),
|
|
76
|
+
* for anything that reads cue timings back out of subtitle/thumbnail-sprite manifests rather
|
|
77
|
+
* than formatting a duration for display.
|
|
78
|
+
* @param {string} raw the timestamp text, e.g. `'00:01:05.250'` or `'01:05.250'`
|
|
79
|
+
* @return {number | undefined} seconds, or `undefined` when `raw` doesn't match the pattern
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* parseVttTimestamp('00:00:05.000'); // 5
|
|
83
|
+
* parseVttTimestamp('01:05.250'); // 65.25
|
|
84
|
+
* parseVttTimestamp('01:00:00.000'); // 3600
|
|
85
|
+
* parseVttTimestamp('not a timestamp'); // undefined
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare const parseVttTimestamp: (raw: string) => number | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* @description: Parse a WebVTT cue timing line — `<start> --> <end>`, optionally followed by
|
|
91
|
+
* cue settings (`align:start line:0`) after the end timestamp, which are ignored. Built on
|
|
92
|
+
* [`parseVttTimestamp`](#parsevtttimestamp) for each side.
|
|
93
|
+
* @param {string} line the timing line, e.g. `'00:00:00.000 --> 00:00:05.000 align:start line:0'`
|
|
94
|
+
* @return {{ start: number; end: number } | undefined} `undefined` when either side fails to parse
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* parseVttCueTiming('00:00:00.000 --> 00:00:05.000'); // { start: 0, end: 5 }
|
|
98
|
+
* parseVttCueTiming('00:00:05.000 --> 00:00:10.000 align:start line:0'); // { start: 5, end: 10 }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare const parseVttCueTiming: (line: string) => {
|
|
102
|
+
start: number;
|
|
103
|
+
end: number;
|
|
104
|
+
} | undefined;
|
|
105
|
+
/** `'compact'` is ours; the other three are `Intl.RelativeTimeFormat` styles. */
|
|
106
|
+
export type RelativeStyle = 'long' | 'short' | 'narrow' | 'compact';
|
|
107
|
+
export interface FormatRelativeOptions {
|
|
108
|
+
/** What to measure against. Defaults to the current time. */
|
|
109
|
+
now?: DateInput;
|
|
110
|
+
/** BCP 47 tag(s); defaults to the runtime's locale. Ignored by the `compact` style. */
|
|
111
|
+
locale?: string | string[];
|
|
112
|
+
/** Defaults to `'long'` (`'3 days ago'`). */
|
|
113
|
+
style?: RelativeStyle;
|
|
114
|
+
/**
|
|
115
|
+
* `'auto'` (the default here) swaps in idioms where a language has them — `yesterday`
|
|
116
|
+
* rather than `1 day ago`, `now` rather than `in 0 seconds`. `'always'` keeps the number.
|
|
117
|
+
*/
|
|
118
|
+
numeric?: 'always' | 'auto';
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @description: Format a point in time relative to another — "3 days ago", "in 2 hours".
|
|
122
|
+
*
|
|
123
|
+
* Localization is delegated to the platform's `Intl.RelativeTimeFormat`, which has been
|
|
124
|
+
* available in every major browser since 2020 and knows each language's plural and
|
|
125
|
+
* inflection rules. This function supplies only the part `Intl` deliberately leaves out:
|
|
126
|
+
* picking *which* unit to express the gap in.
|
|
127
|
+
*
|
|
128
|
+
* Like `Intl` itself it reports a **single** unit — a gap of 3 days and 6 hours is
|
|
129
|
+
* "3 days ago", never "3 days and 6 hours ago".
|
|
130
|
+
*
|
|
131
|
+
* The extra `compact` style is the dense badge form seen next to list items (`5m`, `3h`,
|
|
132
|
+
* `2d`). It is a magnitude only: it carries **no direction**, so a future timestamp reads
|
|
133
|
+
* the same as a past one. Use it for feeds of past events, and any other style when the
|
|
134
|
+
* reader has to tell past from future.
|
|
135
|
+
*
|
|
136
|
+
* @param {DateInput} value the moment to describe
|
|
137
|
+
* @param {FormatRelativeOptions} options
|
|
138
|
+
* @return {string} the description, or `''` when either end cannot be parsed
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const twoHoursAgo = Date.now() - 2 * 3600_000;
|
|
142
|
+
* formatRelative(twoHoursAgo); // '2 hours ago'
|
|
143
|
+
* formatRelative(twoHoursAgo, { style: 'short' }); // '2 hr. ago'
|
|
144
|
+
* formatRelative(twoHoursAgo, { style: 'compact' }); // '2h'
|
|
145
|
+
* formatRelative(twoHoursAgo, { locale: 'zh-CN' }); // '2 小时前'
|
|
146
|
+
* formatRelative(Date.now() + 60_000); // 'in 1 minute'
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare const formatRelative: (value: DateInput, options?: FormatRelativeOptions) => string;
|
|
48
150
|
/**
|
|
49
151
|
* @description: Current timestamp
|
|
50
152
|
* @return {*}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Container } from '@/utils/visual/vertex/container';
|
|
2
2
|
import { EventSystem } from '@/utils/visual/event';
|
|
3
|
+
import type { Filter } from '@/utils/visual/render/filter';
|
|
3
4
|
import type { IApplicationOptions } from '@/utils/visual/types';
|
|
4
5
|
export declare class Application {
|
|
5
6
|
private readonly renderer;
|
|
@@ -21,6 +22,15 @@ export declare class Application {
|
|
|
21
22
|
* app.start();
|
|
22
23
|
*/
|
|
23
24
|
static create(options: IApplicationOptions): Promise<Application>;
|
|
25
|
+
/**
|
|
26
|
+
* Full-screen post-processing passes applied after the scene is drawn, in order. WebGL only
|
|
27
|
+
* (the Canvas backend ignores them).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* app.filters = [new ColorAdjustFilter({ saturation: 1.4, contrast: 1.1 })];
|
|
31
|
+
*/
|
|
32
|
+
get filters(): Filter[];
|
|
33
|
+
set filters(filters: Filter[]);
|
|
24
34
|
render(): void;
|
|
25
35
|
start(): void;
|
|
26
36
|
stop(): void;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Application } from '@/utils/visual/application';
|
|
2
2
|
import { Container } from '@/utils/visual/vertex/container';
|
|
3
3
|
import { Graphics } from '@/utils/visual/graphics/graphics';
|
|
4
|
+
import { ColorAdjustFilter, Filter } from '@/utils/visual/render/filter';
|
|
5
|
+
import { WebGLRenderTarget } from '@/utils/visual/render/renderTarget';
|
|
4
6
|
import { BYTES_PER_VERTEX, LINE_CAP, LINE_JOIN, MAX_VERTEX_COUNT, RENDERER_TYPE, SHAPE_TYPE } from '@/utils/visual/enums';
|
|
5
7
|
import type { IApplicationOptions, IFillStyleOptions, ILineStyleOptions } from '@/utils/visual/types';
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
+
import type { ColorAdjustOptions } from '@/utils/visual/render/filter';
|
|
9
|
+
export { Application, Container, Graphics, Filter, ColorAdjustFilter, WebGLRenderTarget, SHAPE_TYPE, LINE_CAP, LINE_JOIN, RENDERER_TYPE, MAX_VERTEX_COUNT, BYTES_PER_VERTEX, };
|
|
10
|
+
export type { IApplicationOptions, IFillStyleOptions, ILineStyleOptions, ColorAdjustOptions };
|