@virid/std 0.0.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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Ailrid
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # @virid/std
2
+
3
+ `@virid/std` 是 `@virid/core`的官方标准库,负责提供一组开箱即用的实用消息控制流操作。提供了原生的异步流、消息组、防抖节流等支持。
4
+
5
+ ## 🔌启用插件
6
+
7
+ ```ts
8
+ import { createVirid, Component, System, EventMessage } from "@virid/core";
9
+ import { nextTick, StdPlugin } from "@virid/std";
10
+
11
+ const app = createVirid().use(StdPlugin, {});
12
+ ```
13
+
14
+ ## 🛠️ @virid/std 核心 API 概览
15
+
16
+ ### nextTick
17
+
18
+ - **功能**:类似于`vue`中的`nextTick`,但该`Tick`指的是一个`virid`的宏观`Tick`,因此,当执行时该`Tick`内的所有同步`System`已经全部执行完毕,对于异步控制,则需要使用`@AsyncQueue`装饰器
19
+ - **示例:**
20
+
21
+ ```ts
22
+ nextTick(() => {
23
+ IncreaseBMessage.send();
24
+ IncreaseAMessage.send();
25
+ IncreaseBMessage.send();
26
+ });
27
+ ```
28
+
29
+ ### `@AsyncQueue()`
30
+
31
+ - **功能**:`@AsyncQueue()`提供了一个开箱即用的异步消息控制,该装饰器接受一个参数key,对于key相同的message,将严格按照先后顺序执行,而不会出现异步竟态问题。
32
+ - **示例:**
33
+
34
+ ```ts
35
+ @AsyncQueue("increase")
36
+ class IncreaseAMessage extends EventMessage {}
37
+ @AsyncQueue("increase")
38
+ class IncreaseBMessage extends EventMessage {}
39
+ @AsyncQueue("decrease")
40
+ class DecreaseMessage extends EventMessage {}
41
+
42
+ // 按以下顺序发送消息
43
+ // 由于IncreaseMessage和IncreaseBMessage的key是相同的,
44
+ // 即使存在异步操作,以下三条消息也必须按顺序执行
45
+ IncreaseAMessage.send();
46
+ IncreaseBMessage.send();
47
+ IncreaseAMessage.send();
48
+ // 由于DecaseMessage和其他消息之间的key不同
49
+ // DecaseMessage不会等待上述消息
50
+ // 但是,以下三条消息将按顺序执行
51
+ DecreaseMessage.send();
52
+ DecreaseMessage.send();
53
+ DecreaseMessage.send();
54
+ ```
55
+
56
+ ### `executeGroup`
57
+
58
+ - **功能**:`executeGroup`是一组消息的集合,将一组消息严格按照先后顺序一次性执行,并且当途中出错时取消后续逻辑。
59
+ - **示例:**
60
+
61
+ ```ts
62
+ const a = await executeGroup(
63
+ [
64
+ new IncreaseAMessage(),
65
+ new IncreaseBMessage(),
66
+ new IncreaseAMessage(),
67
+ new DecreaseMessage(),
68
+ ],
69
+ "first",
70
+ );
71
+ if (a) {
72
+ console.log("[ExecuteGroup] Success");
73
+ } else {
74
+ console.log("[ExecuteGroup] Failed");
75
+ }
76
+ ```
77
+
78
+ ### `@Debounce()/@Throttle`
79
+
80
+ - **功能**:开箱即用的防抖与节流支持。只需要一行代码即可实现。
81
+ - **示例:**
82
+
83
+ ```ts
84
+ // 100ms防抖:停止触发100ms后只执行一次
85
+ // 后一个参数用于聚合消息
86
+ @Debounce(100, (current, next) => {
87
+ current.val += next.val;
88
+ })
89
+ class SetTimerAMessage extends EventMessage {
90
+ constructor(public val: number) {
91
+ super();
92
+ }
93
+ }
94
+
95
+ // 100ms节流:100ms内只允许一次触发
96
+ @Throttle(500)
97
+ class IncreaseBMessage extends EventMessage {}
98
+ ```
package/README.zh.md ADDED
@@ -0,0 +1,109 @@
1
+ # @virid/std
2
+
3
+ **@virid/std** is the official standard library for **@virid/core**. It provides a set of out-of-the-box utility message control flow operations, featuring native support for asynchronous streams, message grouping, debouncing, throttling, and more.
4
+
5
+ ### 🔌 Enabling the Plugin
6
+
7
+ ```ts
8
+ import { createVirid, Component, System, EventMessage } from "@virid/core";
9
+ import { nextTick, StdPlugin } from "@virid/std";
10
+
11
+ const app = createVirid().use(StdPlugin, {});
12
+ ```
13
+
14
+ ## 🛠️ @virid/std Core API Overview
15
+
16
+ ### `nextTick`
17
+
18
+ - **Function**: Similar to `nextTick` in Vue, but refers to a **Virid Macro Tick**. When executed, all synchronous Systems within the current Tick have finished running. For asynchronous control, use the `@AsyncQueue` decorator.
19
+ - **Example**:
20
+
21
+ ```ts
22
+ nextTick(() => {
23
+ IncreaseBMessage.send();
24
+ IncreaseAMessage.send();
25
+ IncreaseBMessage.send();
26
+ });
27
+ ```
28
+
29
+ ------
30
+
31
+ ### `@AsyncQueue(key: string)`
32
+
33
+ - **Function**: Provides out-of-the-box asynchronous message control. It accepts a `key` parameter; messages sharing the same `key` are executed in strict sequential order, preventing asynchronous race conditions.
34
+ - **Example**:
35
+
36
+ TypeScript
37
+
38
+ ```ts
39
+ @AsyncQueue("increase")
40
+ class IncreaseAMessage extends EventMessage {}
41
+
42
+ @AsyncQueue("increase")
43
+ class IncreaseBMessage extends EventMessage {}
44
+
45
+ @AsyncQueue("decrease")
46
+ class DecreaseMessage extends EventMessage {}
47
+
48
+ // Messages sent in the following order:
49
+ // Because IncreaseAMessage and IncreaseBMessage share the same key,
50
+ // they will execute sequentially even if they contain async operations.
51
+ IncreaseAMessage.send();
52
+ IncreaseBMessage.send();
53
+ IncreaseAMessage.send();
54
+
55
+ // Since DecreaseMessage has a different key, it does not wait for the above.
56
+ // However, the three DecreaseMessages below will execute in their own sequence.
57
+ DecreaseMessage.send();
58
+ DecreaseMessage.send();
59
+ DecreaseMessage.send();
60
+ ```
61
+
62
+ ------
63
+
64
+ ### **`executeGroup`**
65
+
66
+ - **Function**: A collection of messages that executes a group in strict sequential order. If an error occurs during execution, subsequent logic is cancelled.
67
+ - **Example**:
68
+
69
+ ```ts
70
+ const success = await executeGroup(
71
+ [
72
+ new IncreaseAMessage(),
73
+ new IncreaseBMessage(),
74
+ new IncreaseAMessage(),
75
+ new DecreaseMessage(),
76
+ ],
77
+ "first"
78
+ );
79
+
80
+ if (success) {
81
+ console.log("[ExecuteGroup] Success");
82
+ } else {
83
+ console.log("[ExecuteGroup] Failed");
84
+ }
85
+ ```
86
+
87
+ ------
88
+
89
+ ### `@Debounce()` / `@Throttle()`
90
+
91
+ - **Function**: Out-of-the-box support for debouncing and throttling. Can be implemented with a single line of code.
92
+ - **Example**:
93
+
94
+ ```ts
95
+ // 100ms Debounce: Executes only once after 100ms of inactivity.
96
+ // The second parameter is used to aggregate messages.
97
+ @Debounce(100, (current, next) => {
98
+ current.val += next.val;
99
+ })
100
+ class SetTimerAMessage extends EventMessage {
101
+ constructor(public val: number) {
102
+ super();
103
+ }
104
+ }
105
+
106
+ // 500ms Throttle: Limits execution to once every 500ms.
107
+ @Throttle(500)
108
+ class IncreaseBMessage extends EventMessage {}
109
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @virid/std v0.0.1
3
+ * The virid standard library provides commonly used features in development
4
+ */
5
+ var f=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var n=(e,t)=>f(e,"name",{value:t,configurable:!0});var H=(e,t)=>{for(var o in t)f(e,o,{get:t[o],enumerable:!0})},U=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of _(t))!$.call(e,c)&&c!==o&&f(e,c,{get:()=>t[c],enumerable:!(r=P(t,c))||r.enumerable});return e};var W=e=>U(f({},"__esModule",{value:!0}),e);var L={};H(L,{AsyncQueue:()=>F,Debounce:()=>R,StdPlugin:()=>J,Throttle:()=>j,activateAsyncQueue:()=>E,activateDeTh:()=>A,activateGroupMessages:()=>h,activateMessages:()=>G,activateNextTick:()=>M,activateUtils:()=>w,executeGroup:()=>B,nextTick:()=>V});module.exports=W(L);var p=[];function N(){if(p.length!=0){for(let e of p)e();p=[]}}n(N,"afterTickHook");function V(e){p.push(e)}n(V,"nextTick");function M(e){e.onAfterTick(N)}n(M,"activateNextTick");var u=require("@virid/core");var l=new Map,v=new Map,d=new Map,m=new Map;function Q(e){for(let t of d.get(e))v.delete(t);d.delete(e),l.delete(e),m.delete(e)}n(Q,"clearGroup");function z(e,t,o){let r=v.get(e);if(r){let c=l.get(r);if(o){if(c.length>0){let{resolve:i}=c.shift();i(),c.length==0&&(m.get(r)(!0),Q(r))}}else m.get(r)(!1),Q(r),u.MessageWriter.error(new Error(`[ExecuteGroup] Queue Execution Failed: Due to an error in the System execution triggered by ${e.constructor.name}, the message group '${r}' has been cancelled`))}}n(z,"afterExecuteHook");async function B(e,t="default"){if(l.has(t))return u.MessageWriter.error(new Error(`[ExecuteGroup] Unavailable ID: The id '${t}' not yet executed`)),Promise.resolve(!1);let o=[];d.set(t,e),e.forEach((i,s)=>{let x;s==e.length-1?x=n(()=>{},"resolve"):x=n(()=>u.MessageWriter.write(e[s+1]),"resolve"),o.push({message:i,resolve:x}),v.set(i,t)});let r,c=new Promise(i=>{r=i});return m.set(t,r),l.set(t,o),u.MessageWriter.write(e[0]),c}n(B,"executeGroup");function h(e){e.onAfterExecute(u.EventMessage,z)}n(h,"activateGroupMessages");function w(e){M(e),h(e)}n(w,"activateUtils");var T=require("@virid/core");var y=new Map,k=new Map;function F(e="default"){return function(t){y.set(t,e)}}n(F,"AsyncQueue");function I(e,t){let o=y.get(e.constructor);if(o&&e instanceof T.EventMessage){let r=k.get(o)||[];r.push({message:e,next:t}),k.set(o,r),r.length==1&&t()}else t()}n(I,"middleWare");function K(e,t){let o=y.get(e.constructor);if(o){let r=k.get(o);r.at(0)?.message===e&&(r.shift(),r.at(0)?.next())}}n(K,"afterExecuteHook");function E(e){e.useMiddleware(I),e.onAfterExecute(T.EventMessage,K)}n(E,"activateAsyncQueue");var D=new Map,a=new Map,C=new Map,b=new Map;function R(e=100,t=()=>{}){return function(o){D.set(o,{time:e,merge:t})}}n(R,"Debounce");function j(e=100){return function(t){C.set(t,e)}}n(j,"Throttle");function q(e,t){let o=e.constructor,r=D.get(o);if(r){let i=a.get(o);if(i){clearTimeout(i.timer),r.merge(e,i.message);let s=setTimeout(()=>{a.delete(o),t()},r.time);a.set(o,{message:e,timer:s})}else{let s=setTimeout(()=>{a.delete(o),t()},r.time);a.set(o,{message:e,timer:s})}return}let c=C.get(o);if(c){let i=Date.now(),s=b.get(o)||0;if(i-s>=c)b.set(o,i),t();else return;return}t()}n(q,"middleWare");function A(e){e.useMiddleware(q)}n(A,"activateDeTh");function G(e){E(e),A(e)}n(G,"activateMessages");var g=null;function S(e){w(e),G(e),g=e}n(S,"activateApp");var he=new Proxy({},{get(e,t){return(...o)=>{if(!g)return console.warn(`[Virid Std] App method "${String(t)}" called before initialization.`),t==="register"?()=>{console.warn("[Virid Std] Cleanup ignored: source listener was never registered.")}:void 0;let r=g[t];if(typeof r=="function")return Reflect.apply(r,g,o)}}});var J={name:"@virid/std",install(e,t){S(e)}};0&&(module.exports={AsyncQueue,Debounce,StdPlugin,Throttle,activateAsyncQueue,activateDeTh,activateGroupMessages,activateMessages,activateNextTick,activateUtils,executeGroup,nextTick});
6
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/utils/nexttick.ts","../src/utils/message-group.ts","../src/utils/index.ts","../src/messages/async.ts","../src/messages/deth.ts","../src/messages/index.ts","../src/app.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: The virid standard library provides commonly used features in development.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nexport * from \"./utils\";\nexport * from \"./messages\";\nimport { activateApp } from \"./app\";\nexport const StdPlugin: ViridPlugin = {\n name: \"@virid/std\",\n install(app: ViridApp, _options) {\n activateApp(app);\n },\n};\n","import { type ViridApp } from \"@virid/core\";\n\n// 一个简单的nextTick函数\nlet tickTaskQueue: Array<() => void> = [];\n\nfunction afterTickHook() {\n if (tickTaskQueue.length == 0) return;\n for (const task of tickTaskQueue) {\n task();\n }\n tickTaskQueue = [];\n}\n\nexport function nextTick(task: () => void) {\n tickTaskQueue.push(task);\n}\n\nexport function activateNextTick(app: ViridApp) {\n app.onAfterTick(afterTickHook);\n}\n","import {\n EventMessage,\n type ViridApp,\n type ExecuteHookContext,\n MessageWriter,\n} from \"@virid/core\";\ninterface ExecuteContext {\n message: EventMessage;\n resolve: () => void;\n}\n// 每个key中缓存的执行组队列\nconst executeGroupMap = new Map<string, ExecuteContext[]>();\nconst messageKeyMap = new Map<EventMessage, string>();\nconst keyMessageMap = new Map<string, EventMessage[]>();\nconst callBackMap = new Map<string, (success: boolean) => void>();\n\nfunction clearGroup(id: string) {\n for (const message of keyMessageMap.get(id)!) {\n messageKeyMap.delete(message);\n }\n keyMessageMap.delete(id);\n executeGroupMap.delete(id);\n callBackMap.delete(id);\n}\n\nfunction afterExecuteHook(\n message: EventMessage,\n _hookContext: ExecuteHookContext,\n success: boolean,\n) {\n const key = messageKeyMap.get(message);\n if (key) {\n const executeGroup = executeGroupMap.get(key)!;\n if (success) {\n // 只有当前任务执行成功,才继续下一个\n if (executeGroup.length > 0) {\n const { resolve } = executeGroup.shift()!;\n resolve();\n if (executeGroup.length == 0) {\n callBackMap.get(key)!(true);\n clearGroup(key);\n }\n }\n } else {\n callBackMap.get(key)!(false);\n clearGroup(key);\n // 如果出错了,直接取消执行队列\n MessageWriter.error(\n new Error(\n `[ExecuteGroup] Queue Execution Failed: Due to an error in the System execution triggered by ${message.constructor.name}, the message group '${key}' has been cancelled`,\n ),\n );\n }\n }\n}\nexport async function executeGroup(\n messages: EventMessage[],\n id: string = \"default\",\n): Promise<boolean> {\n // 构造一串promise并且把resolve存起来,每个resolve会启动下一个promise\n if (executeGroupMap.has(id)) {\n MessageWriter.error(\n new Error(\n `[ExecuteGroup] Unavailable ID: The id '${id}' not yet executed`,\n ),\n );\n return Promise.resolve(false);\n }\n // 注册这一个执行组\n const executeChain: ExecuteContext[] = [];\n keyMessageMap.set(id, messages);\n messages.forEach((message, index) => {\n let resolve: () => void;\n if (index == messages.length - 1) {\n resolve = () => {};\n } else {\n resolve = () => MessageWriter.write(messages[index + 1]);\n }\n executeChain.push({\n message,\n resolve,\n });\n messageKeyMap.set(message, id);\n });\n let resolver: (success: boolean) => void;\n const promise = new Promise<boolean>((res) => {\n resolver = res;\n });\n callBackMap.set(id, resolver!);\n\n executeGroupMap.set(id, executeChain);\n\n // 立刻触发第一个\n MessageWriter.write(messages[0]);\n return promise;\n}\n\nexport function activateGroupMessages(app: ViridApp) {\n app.onAfterExecute(EventMessage, afterExecuteHook);\n}\n","import { activateNextTick } from \"./nexttick\";\nimport { activateGroupMessages } from \"./message-group\";\nimport { type ViridApp } from \"@virid/core\";\nexport function activateUtils(app: ViridApp) {\n activateNextTick(app)\n activateGroupMessages(app);\n}\n\nexport * from \"./message-group\";\nexport * from \"./nexttick\";\n","import {\n EventMessage,\n type ViridApp,\n type ExecuteHookContext,\n type Newable,\n BaseMessage,\n} from \"@virid/core\";\ninterface QueueContext {\n message: EventMessage;\n next: () => void;\n}\n\n// 消息和key的对应关系\nconst asyncMessageMap = new Map<Newable<EventMessage>, string>();\n// 每个key中缓存的消息序列\nconst asyncMessageQueue = new Map<string, QueueContext[]>();\n\n/**\n * * 注册异步队列消息\n */\nexport function AsyncQueue(key: string = \"default\") {\n return function (target: Newable<EventMessage>) {\n asyncMessageMap.set(target, key);\n };\n}\n\n/**\n * * 拦截所有异步消息\n */\nfunction middleWare(message: BaseMessage, next: () => void): void {\n const key = asyncMessageMap.get(message.constructor as Newable<EventMessage>);\n if (key && message instanceof EventMessage) {\n const currentQueue = asyncMessageQueue.get(key) || [];\n currentQueue.push({ message, next });\n asyncMessageQueue.set(key, currentQueue);\n // 如果没有暂存队列,立刻放行\n if (currentQueue.length == 1) next();\n } else {\n next();\n }\n}\n\nfunction afterExecuteHook(\n message: EventMessage,\n _hookContext: ExecuteHookContext,\n) {\n // 当前消息是否是需要排序的\n const key = asyncMessageMap.get(message.constructor as Newable<EventMessage>);\n if (key) {\n // 如果此消息正是队列头部记录的message\n // 那么立刻这一个,然后投递另一个后继消息\n const currentQueue = asyncMessageQueue.get(key)!;\n if (currentQueue.at(0)?.message === message) {\n currentQueue.shift();\n currentQueue.at(0)?.next();\n }\n }\n}\n\nexport function activateAsyncQueue(app: ViridApp) {\n app.useMiddleware(middleWare);\n app.onAfterExecute(EventMessage, afterExecuteHook);\n}\n","import { type ViridApp, type Newable, BaseMessage } from \"@virid/core\";\n\ninterface DebounceContext<T> {\n time: number;\n merge: (currentMessage: T, nextMessage: T) => void;\n}\n\ninterface DebounceTask {\n message: BaseMessage;\n timer: any;\n}\n\nconst debounceMap = new Map<Newable<BaseMessage>, DebounceContext<any>>();\n// 存储每个消息类对应的当前防抖任务(包含合并后的消息内容和计时器)\nconst prevDebounceTask = new Map<Newable<BaseMessage>, DebounceTask>();\n\nconst throttleMap = new Map<Newable<BaseMessage>, number>();\n// 存储每个消息类上一次真正执行的时间戳\nconst prevThTime = new Map<Newable<BaseMessage>, number>();\n\n/**\n * 防抖装饰器:连续触发的消息会合并,直到停止触发一段时间后才执行\n */\nexport function Debounce<T extends BaseMessage>(\n time: number = 100,\n merge: (currentMessage: T, nextMessage: T) => void = () => {},\n) {\n return function (target: Newable<T>) {\n debounceMap.set(target, {\n time,\n merge,\n });\n };\n}\n\n/**\n * 节流装饰器:限制消息触发的频率\n */\nexport function Throttle(time: number = 100) {\n return function (target: Newable<BaseMessage>) {\n throttleMap.set(target, time);\n };\n}\n\nfunction middleWare(message: BaseMessage, next: () => void): void {\n const messageClass = message.constructor as Newable<BaseMessage>;\n // 处理防抖\n const de = debounceMap.get(messageClass);\n\n if (de) {\n const prevTask = prevDebounceTask.get(messageClass);\n // 如果之前已经有在排队的任务,清除旧计时器并合并消息\n if (prevTask) {\n clearTimeout(prevTask.timer);\n de.merge(message, prevTask.message);\n const newTimer = setTimeout(() => {\n prevDebounceTask.delete(messageClass);\n next();\n }, de.time);\n\n prevDebounceTask.set(messageClass, {\n message: message,\n timer: newTimer,\n });\n } else {\n // 第一次触发\n const timer = setTimeout(() => {\n prevDebounceTask.delete(messageClass);\n next();\n }, de.time);\n prevDebounceTask.set(messageClass, { message, timer });\n }\n return; // 拦截当前消息,不立即向下执行\n }\n // 处理节流\n const th = throttleMap.get(messageClass);\n if (th) {\n const now = Date.now();\n const lastTime = prevThTime.get(messageClass) || 0;\n if (now - lastTime >= th) {\n prevThTime.set(messageClass, now);\n next();\n } else {\n // 时间不够,直接丢弃该消息\n return;\n }\n return;\n }\n next();\n}\n\nexport function activateDeTh(app: ViridApp) {\n app.useMiddleware(middleWare);\n}\n","import { type ViridApp } from \"@virid/core\";\nimport { activateAsyncQueue } from \"./async\";\nimport { activateDeTh } from \"./deth\";\nexport * from \"./async\";\nexport * from \"./deth\";\n\nexport function activateMessages(app: ViridApp) {\n activateAsyncQueue(app);\n activateDeTh(app);\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Std\n */\n\nimport { type ViridApp } from \"@virid/core\";\nimport { activateUtils } from \"./utils\";\nimport { activateMessages } from \"./messages\";\nlet activeApp: ViridApp | null = null;\n\n/**\n * 激活真正的 App 实例\n */\nexport function activateApp(app: ViridApp) {\n activateUtils(app);\n activateMessages(app);\n activeApp = app;\n}\n\n/**\n * viridApp 代理\n */\nexport const viridApp: ViridApp = new Proxy({} as ViridApp, {\n get(_, prop: keyof ViridApp) {\n return (...args: any[]) => {\n if (!activeApp) {\n console.warn(\n `[Virid Std] App method \"${String(prop)}\" called before initialization.`,\n );\n\n if (prop === \"register\") {\n return () => {\n console.warn(\n \"[Virid Std] Cleanup ignored: source listener was never registered.\",\n );\n };\n }\n return undefined;\n }\n const targetMethod = activeApp[prop];\n if (typeof targetMethod === \"function\") {\n return Reflect.apply(targetMethod, activeApp, args);\n }\n };\n },\n});\n"],"mappings":";;;;+cAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,aAAAC,EAAA,cAAAC,EAAA,aAAAC,EAAA,uBAAAC,EAAA,iBAAAC,EAAA,0BAAAC,EAAA,qBAAAC,EAAA,qB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AGC,EAAoB,CACzB,MAAO,IAAIC,IAAAA,CACT,GAAI,CAACV,EAKH,OAJAW,QAAQC,KACN,2BAA2BC,OAAOJ,CAAAA,CAAAA,iCAAsC,EAGtEA,IAAS,WACJ,IAAA,CACLE,QAAQC,KACN,oEAAA,CAEJ,EAEF,OAEF,IAAME,EAAed,EAAUS,CAAAA,EAC/B,GAAI,OAAOK,GAAiB,WAC1B,OAAOC,QAAQC,MAAMF,EAAcd,EAAWU,CAAAA,CAElD,CACF,CACF,CAAA,EPzBO,IAAMO,EAAyB,CACpCC,KAAM,aACNC,QAAQC,EAAeC,EAAQ,CAC7BC,EAAYF,CAAAA,CACd,CACF","names":["index_exports","__export","AsyncQueue","Debounce","StdPlugin","Throttle","activateAsyncQueue","activateDeTh","activateGroupMessages","activateMessages","activateNextTick","activateUtils","executeGroup","nextTick","__toCommonJS","tickTaskQueue","afterTickHook","length","task","nextTick","push","activateNextTick","app","onAfterTick","import_core","executeGroupMap","Map","messageKeyMap","keyMessageMap","callBackMap","clearGroup","id","message","get","delete","afterExecuteHook","_hookContext","success","key","executeGroup","length","resolve","shift","MessageWriter","error","Error","name","messages","has","Promise","executeChain","set","forEach","index","__name","write","push","resolver","promise","res","activateGroupMessages","app","onAfterExecute","EventMessage","activateUtils","app","activateNextTick","activateGroupMessages","import_core","asyncMessageMap","Map","asyncMessageQueue","AsyncQueue","key","target","set","middleWare","message","next","get","EventMessage","currentQueue","push","length","afterExecuteHook","_hookContext","at","shift","activateAsyncQueue","app","useMiddleware","onAfterExecute","debounceMap","Map","prevDebounceTask","throttleMap","prevThTime","Debounce","time","merge","target","set","Throttle","middleWare","message","next","messageClass","de","get","prevTask","clearTimeout","timer","newTimer","setTimeout","delete","th","now","Date","lastTime","activateDeTh","app","useMiddleware","activateMessages","app","activateAsyncQueue","activateDeTh","activeApp","activateApp","app","activateUtils","activateMessages","viridApp","Proxy","get","_","prop","args","console","warn","String","targetMethod","Reflect","apply","StdPlugin","name","install","app","_options","activateApp"]}
@@ -0,0 +1,31 @@
1
+ import { ViridApp, EventMessage, Newable, BaseMessage, ViridPlugin } from '@virid/core';
2
+
3
+ declare function executeGroup(messages: EventMessage[], id?: string): Promise<boolean>;
4
+ declare function activateGroupMessages(app: ViridApp): void;
5
+
6
+ declare function nextTick(task: () => void): void;
7
+ declare function activateNextTick(app: ViridApp): void;
8
+
9
+ declare function activateUtils(app: ViridApp): void;
10
+
11
+ /**
12
+ * * 注册异步队列消息
13
+ */
14
+ declare function AsyncQueue(key?: string): (target: Newable<EventMessage>) => void;
15
+ declare function activateAsyncQueue(app: ViridApp): void;
16
+
17
+ /**
18
+ * 防抖装饰器:连续触发的消息会合并,直到停止触发一段时间后才执行
19
+ */
20
+ declare function Debounce<T extends BaseMessage>(time?: number, merge?: (currentMessage: T, nextMessage: T) => void): (target: Newable<T>) => void;
21
+ /**
22
+ * 节流装饰器:限制消息触发的频率
23
+ */
24
+ declare function Throttle(time?: number): (target: Newable<BaseMessage>) => void;
25
+ declare function activateDeTh(app: ViridApp): void;
26
+
27
+ declare function activateMessages(app: ViridApp): void;
28
+
29
+ declare const StdPlugin: ViridPlugin;
30
+
31
+ export { AsyncQueue, Debounce, StdPlugin, Throttle, activateAsyncQueue, activateDeTh, activateGroupMessages, activateMessages, activateNextTick, activateUtils, executeGroup, nextTick };
@@ -0,0 +1,31 @@
1
+ import { ViridApp, EventMessage, Newable, BaseMessage, ViridPlugin } from '@virid/core';
2
+
3
+ declare function executeGroup(messages: EventMessage[], id?: string): Promise<boolean>;
4
+ declare function activateGroupMessages(app: ViridApp): void;
5
+
6
+ declare function nextTick(task: () => void): void;
7
+ declare function activateNextTick(app: ViridApp): void;
8
+
9
+ declare function activateUtils(app: ViridApp): void;
10
+
11
+ /**
12
+ * * 注册异步队列消息
13
+ */
14
+ declare function AsyncQueue(key?: string): (target: Newable<EventMessage>) => void;
15
+ declare function activateAsyncQueue(app: ViridApp): void;
16
+
17
+ /**
18
+ * 防抖装饰器:连续触发的消息会合并,直到停止触发一段时间后才执行
19
+ */
20
+ declare function Debounce<T extends BaseMessage>(time?: number, merge?: (currentMessage: T, nextMessage: T) => void): (target: Newable<T>) => void;
21
+ /**
22
+ * 节流装饰器:限制消息触发的频率
23
+ */
24
+ declare function Throttle(time?: number): (target: Newable<BaseMessage>) => void;
25
+ declare function activateDeTh(app: ViridApp): void;
26
+
27
+ declare function activateMessages(app: ViridApp): void;
28
+
29
+ declare const StdPlugin: ViridPlugin;
30
+
31
+ export { AsyncQueue, Debounce, StdPlugin, Throttle, activateAsyncQueue, activateDeTh, activateGroupMessages, activateMessages, activateNextTick, activateUtils, executeGroup, nextTick };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @virid/std v0.0.1
3
+ * The virid standard library provides commonly used features in development
4
+ */
5
+ var S=Object.defineProperty;var o=(e,t)=>S(e,"name",{value:t,configurable:!0});var a=[];function P(){if(a.length!=0){for(let e of a)e();a=[]}}o(P,"afterTickHook");function V(e){a.push(e)}o(V,"nextTick");function h(e){e.onAfterTick(P)}o(h,"activateNextTick");import{EventMessage as _,MessageWriter as f}from"@virid/core";var p=new Map,M=new Map,x=new Map,l=new Map;function w(e){for(let t of x.get(e))M.delete(t);x.delete(e),p.delete(e),l.delete(e)}o(w,"clearGroup");function $(e,t,n){let r=M.get(e);if(r){let i=p.get(r);if(n){if(i.length>0){let{resolve:c}=i.shift();c(),i.length==0&&(l.get(r)(!0),w(r))}}else l.get(r)(!1),w(r),f.error(new Error(`[ExecuteGroup] Queue Execution Failed: Due to an error in the System execution triggered by ${e.constructor.name}, the message group '${r}' has been cancelled`))}}o($,"afterExecuteHook");async function I(e,t="default"){if(p.has(t))return f.error(new Error(`[ExecuteGroup] Unavailable ID: The id '${t}' not yet executed`)),Promise.resolve(!1);let n=[];x.set(t,e),e.forEach((c,s)=>{let g;s==e.length-1?g=o(()=>{},"resolve"):g=o(()=>f.write(e[s+1]),"resolve"),n.push({message:c,resolve:g}),M.set(c,t)});let r,i=new Promise(c=>{r=c});return l.set(t,r),p.set(t,n),f.write(e[0]),i}o(I,"executeGroup");function k(e){e.onAfterExecute(_,$)}o(k,"activateGroupMessages");function T(e){h(e),k(e)}o(T,"activateUtils");import{EventMessage as y}from"@virid/core";var v=new Map,d=new Map;function Z(e="default"){return function(t){v.set(t,e)}}o(Z,"AsyncQueue");function H(e,t){let n=v.get(e.constructor);if(n&&e instanceof y){let r=d.get(n)||[];r.push({message:e,next:t}),d.set(n,r),r.length==1&&t()}else t()}o(H,"middleWare");function U(e,t){let n=v.get(e.constructor);if(n){let r=d.get(n);r.at(0)?.message===e&&(r.shift(),r.at(0)?.next())}}o(U,"afterExecuteHook");function E(e){e.useMiddleware(H),e.onAfterExecute(y,U)}o(E,"activateAsyncQueue");var G=new Map,u=new Map,Q=new Map,A=new Map;function oe(e=100,t=()=>{}){return function(n){G.set(n,{time:e,merge:t})}}o(oe,"Debounce");function re(e=100){return function(t){Q.set(t,e)}}o(re,"Throttle");function W(e,t){let n=e.constructor,r=G.get(n);if(r){let c=u.get(n);if(c){clearTimeout(c.timer),r.merge(e,c.message);let s=setTimeout(()=>{u.delete(n),t()},r.time);u.set(n,{message:e,timer:s})}else{let s=setTimeout(()=>{u.delete(n),t()},r.time);u.set(n,{message:e,timer:s})}return}let i=Q.get(n);if(i){let c=Date.now(),s=A.get(n)||0;if(c-s>=i)A.set(n,c),t();else return;return}t()}o(W,"middleWare");function b(e){e.useMiddleware(W)}o(b,"activateDeTh");function D(e){E(e),b(e)}o(D,"activateMessages");var m=null;function C(e){T(e),D(e),m=e}o(C,"activateApp");var ge=new Proxy({},{get(e,t){return(...n)=>{if(!m)return console.warn(`[Virid Std] App method "${String(t)}" called before initialization.`),t==="register"?()=>{console.warn("[Virid Std] Cleanup ignored: source listener was never registered.")}:void 0;let r=m[t];if(typeof r=="function")return Reflect.apply(r,m,n)}}});var ve={name:"@virid/std",install(e,t){C(e)}};export{Z as AsyncQueue,oe as Debounce,ve as StdPlugin,re as Throttle,E as activateAsyncQueue,b as activateDeTh,k as activateGroupMessages,D as activateMessages,h as activateNextTick,T as activateUtils,I as executeGroup,V as nextTick};
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/nexttick.ts","../src/utils/message-group.ts","../src/utils/index.ts","../src/messages/async.ts","../src/messages/deth.ts","../src/messages/index.ts","../src/app.ts","../src/index.ts"],"sourcesContent":["import { type ViridApp } from \"@virid/core\";\n\n// 一个简单的nextTick函数\nlet tickTaskQueue: Array<() => void> = [];\n\nfunction afterTickHook() {\n if (tickTaskQueue.length == 0) return;\n for (const task of tickTaskQueue) {\n task();\n }\n tickTaskQueue = [];\n}\n\nexport function nextTick(task: () => void) {\n tickTaskQueue.push(task);\n}\n\nexport function activateNextTick(app: ViridApp) {\n app.onAfterTick(afterTickHook);\n}\n","import {\n EventMessage,\n type ViridApp,\n type ExecuteHookContext,\n MessageWriter,\n} from \"@virid/core\";\ninterface ExecuteContext {\n message: EventMessage;\n resolve: () => void;\n}\n// 每个key中缓存的执行组队列\nconst executeGroupMap = new Map<string, ExecuteContext[]>();\nconst messageKeyMap = new Map<EventMessage, string>();\nconst keyMessageMap = new Map<string, EventMessage[]>();\nconst callBackMap = new Map<string, (success: boolean) => void>();\n\nfunction clearGroup(id: string) {\n for (const message of keyMessageMap.get(id)!) {\n messageKeyMap.delete(message);\n }\n keyMessageMap.delete(id);\n executeGroupMap.delete(id);\n callBackMap.delete(id);\n}\n\nfunction afterExecuteHook(\n message: EventMessage,\n _hookContext: ExecuteHookContext,\n success: boolean,\n) {\n const key = messageKeyMap.get(message);\n if (key) {\n const executeGroup = executeGroupMap.get(key)!;\n if (success) {\n // 只有当前任务执行成功,才继续下一个\n if (executeGroup.length > 0) {\n const { resolve } = executeGroup.shift()!;\n resolve();\n if (executeGroup.length == 0) {\n callBackMap.get(key)!(true);\n clearGroup(key);\n }\n }\n } else {\n callBackMap.get(key)!(false);\n clearGroup(key);\n // 如果出错了,直接取消执行队列\n MessageWriter.error(\n new Error(\n `[ExecuteGroup] Queue Execution Failed: Due to an error in the System execution triggered by ${message.constructor.name}, the message group '${key}' has been cancelled`,\n ),\n );\n }\n }\n}\nexport async function executeGroup(\n messages: EventMessage[],\n id: string = \"default\",\n): Promise<boolean> {\n // 构造一串promise并且把resolve存起来,每个resolve会启动下一个promise\n if (executeGroupMap.has(id)) {\n MessageWriter.error(\n new Error(\n `[ExecuteGroup] Unavailable ID: The id '${id}' not yet executed`,\n ),\n );\n return Promise.resolve(false);\n }\n // 注册这一个执行组\n const executeChain: ExecuteContext[] = [];\n keyMessageMap.set(id, messages);\n messages.forEach((message, index) => {\n let resolve: () => void;\n if (index == messages.length - 1) {\n resolve = () => {};\n } else {\n resolve = () => MessageWriter.write(messages[index + 1]);\n }\n executeChain.push({\n message,\n resolve,\n });\n messageKeyMap.set(message, id);\n });\n let resolver: (success: boolean) => void;\n const promise = new Promise<boolean>((res) => {\n resolver = res;\n });\n callBackMap.set(id, resolver!);\n\n executeGroupMap.set(id, executeChain);\n\n // 立刻触发第一个\n MessageWriter.write(messages[0]);\n return promise;\n}\n\nexport function activateGroupMessages(app: ViridApp) {\n app.onAfterExecute(EventMessage, afterExecuteHook);\n}\n","import { activateNextTick } from \"./nexttick\";\nimport { activateGroupMessages } from \"./message-group\";\nimport { type ViridApp } from \"@virid/core\";\nexport function activateUtils(app: ViridApp) {\n activateNextTick(app)\n activateGroupMessages(app);\n}\n\nexport * from \"./message-group\";\nexport * from \"./nexttick\";\n","import {\n EventMessage,\n type ViridApp,\n type ExecuteHookContext,\n type Newable,\n BaseMessage,\n} from \"@virid/core\";\ninterface QueueContext {\n message: EventMessage;\n next: () => void;\n}\n\n// 消息和key的对应关系\nconst asyncMessageMap = new Map<Newable<EventMessage>, string>();\n// 每个key中缓存的消息序列\nconst asyncMessageQueue = new Map<string, QueueContext[]>();\n\n/**\n * * 注册异步队列消息\n */\nexport function AsyncQueue(key: string = \"default\") {\n return function (target: Newable<EventMessage>) {\n asyncMessageMap.set(target, key);\n };\n}\n\n/**\n * * 拦截所有异步消息\n */\nfunction middleWare(message: BaseMessage, next: () => void): void {\n const key = asyncMessageMap.get(message.constructor as Newable<EventMessage>);\n if (key && message instanceof EventMessage) {\n const currentQueue = asyncMessageQueue.get(key) || [];\n currentQueue.push({ message, next });\n asyncMessageQueue.set(key, currentQueue);\n // 如果没有暂存队列,立刻放行\n if (currentQueue.length == 1) next();\n } else {\n next();\n }\n}\n\nfunction afterExecuteHook(\n message: EventMessage,\n _hookContext: ExecuteHookContext,\n) {\n // 当前消息是否是需要排序的\n const key = asyncMessageMap.get(message.constructor as Newable<EventMessage>);\n if (key) {\n // 如果此消息正是队列头部记录的message\n // 那么立刻这一个,然后投递另一个后继消息\n const currentQueue = asyncMessageQueue.get(key)!;\n if (currentQueue.at(0)?.message === message) {\n currentQueue.shift();\n currentQueue.at(0)?.next();\n }\n }\n}\n\nexport function activateAsyncQueue(app: ViridApp) {\n app.useMiddleware(middleWare);\n app.onAfterExecute(EventMessage, afterExecuteHook);\n}\n","import { type ViridApp, type Newable, BaseMessage } from \"@virid/core\";\n\ninterface DebounceContext<T> {\n time: number;\n merge: (currentMessage: T, nextMessage: T) => void;\n}\n\ninterface DebounceTask {\n message: BaseMessage;\n timer: any;\n}\n\nconst debounceMap = new Map<Newable<BaseMessage>, DebounceContext<any>>();\n// 存储每个消息类对应的当前防抖任务(包含合并后的消息内容和计时器)\nconst prevDebounceTask = new Map<Newable<BaseMessage>, DebounceTask>();\n\nconst throttleMap = new Map<Newable<BaseMessage>, number>();\n// 存储每个消息类上一次真正执行的时间戳\nconst prevThTime = new Map<Newable<BaseMessage>, number>();\n\n/**\n * 防抖装饰器:连续触发的消息会合并,直到停止触发一段时间后才执行\n */\nexport function Debounce<T extends BaseMessage>(\n time: number = 100,\n merge: (currentMessage: T, nextMessage: T) => void = () => {},\n) {\n return function (target: Newable<T>) {\n debounceMap.set(target, {\n time,\n merge,\n });\n };\n}\n\n/**\n * 节流装饰器:限制消息触发的频率\n */\nexport function Throttle(time: number = 100) {\n return function (target: Newable<BaseMessage>) {\n throttleMap.set(target, time);\n };\n}\n\nfunction middleWare(message: BaseMessage, next: () => void): void {\n const messageClass = message.constructor as Newable<BaseMessage>;\n // 处理防抖\n const de = debounceMap.get(messageClass);\n\n if (de) {\n const prevTask = prevDebounceTask.get(messageClass);\n // 如果之前已经有在排队的任务,清除旧计时器并合并消息\n if (prevTask) {\n clearTimeout(prevTask.timer);\n de.merge(message, prevTask.message);\n const newTimer = setTimeout(() => {\n prevDebounceTask.delete(messageClass);\n next();\n }, de.time);\n\n prevDebounceTask.set(messageClass, {\n message: message,\n timer: newTimer,\n });\n } else {\n // 第一次触发\n const timer = setTimeout(() => {\n prevDebounceTask.delete(messageClass);\n next();\n }, de.time);\n prevDebounceTask.set(messageClass, { message, timer });\n }\n return; // 拦截当前消息,不立即向下执行\n }\n // 处理节流\n const th = throttleMap.get(messageClass);\n if (th) {\n const now = Date.now();\n const lastTime = prevThTime.get(messageClass) || 0;\n if (now - lastTime >= th) {\n prevThTime.set(messageClass, now);\n next();\n } else {\n // 时间不够,直接丢弃该消息\n return;\n }\n return;\n }\n next();\n}\n\nexport function activateDeTh(app: ViridApp) {\n app.useMiddleware(middleWare);\n}\n","import { type ViridApp } from \"@virid/core\";\nimport { activateAsyncQueue } from \"./async\";\nimport { activateDeTh } from \"./deth\";\nexport * from \"./async\";\nexport * from \"./deth\";\n\nexport function activateMessages(app: ViridApp) {\n activateAsyncQueue(app);\n activateDeTh(app);\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Std\n */\n\nimport { type ViridApp } from \"@virid/core\";\nimport { activateUtils } from \"./utils\";\nimport { activateMessages } from \"./messages\";\nlet activeApp: ViridApp | null = null;\n\n/**\n * 激活真正的 App 实例\n */\nexport function activateApp(app: ViridApp) {\n activateUtils(app);\n activateMessages(app);\n activeApp = app;\n}\n\n/**\n * viridApp 代理\n */\nexport const viridApp: ViridApp = new Proxy({} as ViridApp, {\n get(_, prop: keyof ViridApp) {\n return (...args: any[]) => {\n if (!activeApp) {\n console.warn(\n `[Virid Std] App method \"${String(prop)}\" called before initialization.`,\n );\n\n if (prop === \"register\") {\n return () => {\n console.warn(\n \"[Virid Std] Cleanup ignored: source listener was never registered.\",\n );\n };\n }\n return undefined;\n }\n const targetMethod = activeApp[prop];\n if (typeof targetMethod === \"function\") {\n return Reflect.apply(targetMethod, activeApp, args);\n }\n };\n },\n});\n","/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: The virid standard library provides commonly used features in development.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nexport * from \"./utils\";\nexport * from \"./messages\";\nimport { activateApp } from \"./app\";\nexport const StdPlugin: ViridPlugin = {\n name: \"@virid/std\",\n install(app: ViridApp, _options) {\n activateApp(app);\n },\n};\n"],"mappings":";;;;+EAGA,IAAIA,EAAmC,CAAA,EAEvC,SAASC,GAAAA,CACP,GAAID,EAAcE,QAAU,EAC5B,SAAWC,KAAQH,EACjBG,EAAAA,EAEFH,EAAgB,CAAA,EAClB,CANSC,EAAAA,EAAAA,iBAQF,SAASG,EAASD,EAAgB,CACvCH,EAAcK,KAAKF,CAAAA,CACrB,CAFgBC,EAAAA,EAAAA,YAIT,SAASE,EAAiBC,EAAa,CAC5CA,EAAIC,YAAYP,CAAAA,CAClB,CAFgBK,EAAAA,EAAAA,oBCjBhB,OACEG,gBAAAA,EAGAC,iBAAAA,MACK,cAMP,IAAMC,EAAkB,IAAIC,IACtBC,EAAgB,IAAID,IAC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app","onAfterTick","EventMessage","MessageWriter","executeGroupMap","Map","messageKeyMap","keyMessageMap","callBackMap","clearGroup","id","message","get","delete","afterExecuteHook","_hookContext","success","key","executeGroup","length","resolve","shift","MessageWriter","error","Error","name","messages","has","Promise","executeChain","set","forEach","index","__name","write","push","resolver","promise","res","activateGroupMessages","app","onAfterExecute","EventMessage","activateUtils","app","activateNextTick","activateGroupMessages","EventMessage","asyncMessageMap","Map","asyncMessageQueue","AsyncQueue","key","target","set","middleWare","message","next","get","EventMessage","currentQueue","push","length","afterExecuteHook","_hookContext","at","shift","activateAsyncQueue","app","useMiddleware","onAfterExecute","debounceMap","Map","prevDebounceTask","throttleMap","prevThTime","Debounce","time","merge","target","set","Throttle","middleWare","message","next","messageClass","de","get","prevTask","clearTimeout","timer","newTimer","setTimeout","delete","th","now","Date","lastTime","activateDeTh","app","useMiddleware","activateMessages","app","activateAsyncQueue","activateDeTh","activeApp","activateApp","app","activateUtils","activateMessages","viridApp","Proxy","get","_","prop","args","console","warn","String","targetMethod","Reflect","apply","StdPlugin","name","install","app","_options","activateApp"]}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@virid/std",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "The virid standard library provides commonly used features in development",
6
+ "author": "Ailrid",
7
+ "license": "Apache 2.0",
8
+ "keywords": [
9
+ "virid",
10
+ "std"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Ailrid/virid.git"
15
+ },
16
+ "main": "./dist/index.cjs",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "registry": "https://registry.npmjs.org/"
32
+ },
33
+ "dependencies": {},
34
+ "peerDependencies": {
35
+ "@virid/core": "0.2.5"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup --config tsup.config.ts",
39
+ "dev": "tsup --config tsup.config.ts --watch",
40
+ "typecheck": "tsc --noEmit"
41
+ }
42
+ }