@virid/amber 0.1.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/LICENSE +190 -0
- package/README.md +1 -0
- package/README.zh.md +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +176 -0
- package/dist/index.d.ts +176 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
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 @@
|
|
|
1
|
+
todo
|
package/README.zh.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
todo
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @virid/amber v0.0.1
|
|
3
|
+
* Add replay, redo, undo and other functions to virid
|
|
4
|
+
*/
|
|
5
|
+
var y=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var j=(r,t,e)=>t in r?y(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var a=(r,t)=>y(r,"name",{value:t,configurable:!0});var L=(r,t)=>{for(var e in t)y(r,e,{get:t[e],enumerable:!0})},P=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!N.call(r,o)&&o!==e&&y(r,o,{get:()=>t[o],enumerable:!(i=$(t,o))||i.enumerable});return r};var F=r=>P(y({},"__esModule",{value:!0}),r);var d=(r,t,e)=>j(r,typeof t!="symbol"?t+"":t,e);var G={};L(G,{Amber:()=>z,AmberPlugin:()=>q,Backup:()=>Q,RestoreDirection:()=>T,activateConfig:()=>O,afterExecuteHooks:()=>w,afterTickHooks:()=>_,amberComponentStore:()=>f,amberTickStore:()=>u});module.exports=F(G);var S=require("@virid/core");var h=require("@virid/core");var U=require("@virid/core"),s={...U.VIRID_METADATA,BACKUP:"virid:amber:backup",VERSION:"virid:amber:version",CUSTOM_METHOD:"virid:amber:custom-method"};var T=(function(r){return r.UNDO="UNDO",r.REDO="REDO",r})({});function V(r,t=5){if(r===null||typeof r!="object")return r;if(t<=0)return Array.isArray(r)?[]:{};if(Array.isArray(r))return r.map(o=>V(o,t-1));let e={},i=Object.keys(r);for(let o of i){if(o.startsWith("_"))continue;let n=r[o];typeof n!="function"&&(e[o]=typeof n=="object"&&n!==null?V(n,t-1):n)}return e}a(V,"_serialization");function D(r,t){!r||!t||Object.keys(t).forEach(e=>{let i=t[e],o=r[e];o&&typeof o=="object"&&i&&typeof i=="object"&&!Array.isArray(i)?D(o,i):r[e]=i})}a(D,"_deserialization");function R(r,t,e=3){if(r===t)return!1;if(typeof r!=typeof t||r===null||t===null)return!0;if(Array.isArray(r)){if(!Array.isArray(t)||r.length!==t.length)return!0;for(let o=0;o<r.length;o++)if(R(r[o],t[o],e-1))return!0;return!1}let i=Object.keys(r);for(let o of i){let n=r[o],c=t[o];if(typeof n=="object"&&n!==null){if(e<=0)continue;if(R(n,c,e-1))return!0}else if(n!==c)return!0}return!1}a(R,"_diff");var M={serialization:V,deserialization:D,diff:R};function O(r){M=Object.assign(M,r)}a(O,"activateConfig");var p,W=(p=class{constructor(t=20){d(this,"tickHistory",[]);d(this,"baseTick",0);d(this,"maxTickLength",20);d(this,"currentTick",0);this.maxTickLength=t}getMinTick(){return this.baseTick}getMaxTick(){return this.tickHistory.length===0?0:this.baseTick+this.tickHistory.length-1}updateTickHistory(){this.currentTick<this.baseTick+this.tickHistory.length&&this.tickHistory.splice(this.currentTick-this.baseTick+1);let t=new Map(f.currentHistory);this.tickHistory.push(t),this.tickHistory.length>this.maxTickLength&&(this.tickHistory.shift(),this.baseTick++);let e=this.baseTick+this.tickHistory.length-1;this.currentTick=e}travel(t){let e=t-this.baseTick,i=this.tickHistory[e];if(!i){h.MessageWriter.error(new Error(`[Virid Amber] Travel Error: Tick ${t} is out of history range.`));return}let o=t<this.currentTick?T.UNDO:T.REDO,n=[];for(let[c,m]of i){let l=f.getCurrentData(c);if(m!==l){let b=l;f.deserializeComponent(c,m),f.seal(c);let v=Reflect.getMetadata(s.CUSTOM_METHOD,c);v?.onRestore&&n.push({strategy:v,oldData:b,newData:m})}let E=A.get(c)}this.currentTick=t,n.forEach(({strategy:c,oldData:m,newData:l})=>{c.onRestore(m,l,o)})}resetTickStore(){this.tickHistory=[],this.baseTick=0,this.currentTick=0,this.updateTickHistory()}},a(p,"AmberTickStore"),p),g,K=(g=class{constructor(t=20){d(this,"componentHistory",new Map);d(this,"biasVersions",new Map);d(this,"maxComponentHistorySize",20);d(this,"currentHistory",new Map);this.maxComponentHistorySize=t}serializeComponent(t){let e=A.get(t);if(!e)return h.MessageWriter.error(new Error(`[Virid Amber] Serialize Error: Component ${t.name} is not registered.`)),null;let o=Reflect.getMetadata(s.CUSTOM_METHOD,t)?.serialize||M.serialization;try{return o(e)}catch(n){h.MessageWriter.error(n,`[Virid Amber] Serialize Error: Component ${t.name} serialization error`)}return null}deserializeComponent(t,e){let i=A.get(t);if(!i){h.MessageWriter.error(new Error(`[Virid Amber] Deserialize Error: Component ${t.name} is not registered.`));return}if(!e){h.MessageWriter.error(new Error(`[Virid Amber] Deserialize Error: Component ${t.name} data is ${e}!.`));return}let n=Reflect.getMetadata(s.CUSTOM_METHOD,t)?.deserialize||M.deserialization;try{n(i,e)}catch(c){h.MessageWriter.error(c,`[Virid Amber] Deserialize Error: Component ${t.name} deserialize error`)}}diffComponent(t,e){let i=A.get(t);if(!i)return h.MessageWriter.error(new Error(`[Virid Amber] Diff Error: Component ${t.name} is not registered.`)),!1;if(!e)return h.MessageWriter.error(new Error(`[Virid Amber] Diff Error: Component ${t.name} data is ${e}!.`)),!1;let n=Reflect.getMetadata(s.CUSTOM_METHOD,t)?.diff||M.diff;try{return n(i,e)}catch(c){h.MessageWriter.error(c,`[Virid Amber] Diff Error: Component ${t.name} diff error`)}return!1}initComponent(t){let e=t.constructor,o=Reflect.getMetadata(s.CUSTOM_METHOD,e)?.serialize||M.serialization,n;try{n=o(t)}catch(c){h.MessageWriter.error(c,`[Virid Amber] Serialize Error: Component ${e.name} serialization error`);return}this.componentHistory.set(e,[]),this.biasVersions.set(e,0),this.componentHistory.get(e).push(n),this.currentHistory.set(e,n),Reflect.defineMetadata(s.VERSION,0,e)}getCurrentData(t){return this.currentHistory.get(t)}getMinVersion(t){return this.biasVersions.get(t)??0}getMaxVersion(t){let e=this.componentHistory.get(t),i=this.biasVersions.get(t)??0;return!e||e.length===0?i:i+e.length-1}seal(t){let e=this.componentHistory.get(t);e||h.MessageWriter.error(new Error(`[Virid Amber] Seal Error: Component ${t.name} is not initialized.`));let i=this.biasVersions.get(t),o=this.getCurrentData(t);if(o&&!this.diffComponent(t,o))return;let n=Reflect.getMetadata(s.CUSTOM_METHOD,t);n?.onBeforeBackup&&n.onBeforeBackup(o);let c=Reflect.getMetadata(s.VERSION,t)||0,m=i+e.length-1;c<m&&e.splice(c-i+1);let l=this.serializeComponent(t);if(!l){h.MessageWriter.error(new Error(`[Virid Amber] Seal Error: Component ${t.name} is not serializable.`));return}e.push(l),this.currentHistory.set(t,l),e.length>this.maxComponentHistorySize&&(e.shift(),this.biasVersions.set(t,i+1));let E=this.biasVersions.get(t)+e.length-1;Reflect.defineMetadata(s.VERSION,E,t),n?.onAfterBackup&&n.onAfterBackup(l)}seek(t,e){let i=this.componentHistory.get(t);if(!i)return h.MessageWriter.error(new Error(`[Virid Amber] Seal Error: Component ${t.name} is not initialized.`)),!1;let o=this.biasVersions.get(t)||0,n=e-o;if(n<0||n>=i.length)return!1;let c=this.getCurrentData(t),m=i[n],l=Reflect.getMetadata(s.VERSION,t)||0,E=e<l?T.UNDO:T.REDO;this.deserializeComponent(t,m),this.currentHistory.set(t,m),Reflect.defineMetadata(s.VERSION,e,t);let b=Reflect.getMetadata(s.CUSTOM_METHOD,t);return b?.onRestore&&b.onRestore(c,m,E),u.updateTickHistory(),!0}resetComponentInternal(t){let e=this.serializeComponent(t);e&&(this.componentHistory.set(t,[e]),this.biasVersions.set(t,0),this.currentHistory.set(t,e),Reflect.defineMetadata(s.VERSION,0,t))}resetComponent(t){this.resetComponentInternal(t),u.updateTickHistory()}},a(g,"AmberComponentStore"),g),u=new W,f=new K;var I=class I{static getVersion(t){return Reflect.getMetadata(s.VERSION,t)||0}static canUndo(t){let e=this.getVersion(t),i=f.getMinVersion(t);return e>i}static canRedo(t){let e=this.getVersion(t),i=f.getMaxVersion(t);return e<i}static undo(t){if(!this.canUndo(t))return!1;let e=this.getVersion(t);return f.seek(t,e-1)}static redo(t){if(!this.canRedo(t))return!1;let e=this.getVersion(t);return f.seek(t,e+1)}static undoTick(){if(!this.canUndoTick())return!1;let t=u.currentTick-1;return u.travel(t),!0}static redoTick(){if(!this.canRedoTick())return!1;let t=u.currentTick+1;return u.travel(t),!0}static canUndoTick(){let t=u.currentTick,e=u.getMinTick();return t>e}static canRedoTick(){let t=u.currentTick,e=u.getMaxTick();return t<e}static resetTick(){u.resetTickStore()}static resetComponent(t){f.resetComponent(t)}static resetAll(){Array.from(f.componentHistory.keys()).forEach(e=>{f.resetComponentInternal(e)}),u.resetTickStore()}};a(I,"Amber");var z=I;var k=require("@virid/core");var H=new Set,w=a((r,t)=>{if(r instanceof k.ErrorMessage||r instanceof k.WarnMessage||r instanceof k.InfoMessage)return;(r instanceof k.AtomicModifyMessage?[...t.context.params,r.ComponentClass]:t.context.params).forEach(i=>{Reflect.hasMetadata(s.BACKUP,i)&&H.add(i)})},"afterExecuteHooks"),_=a(r=>{H.size!==0&&(H.forEach(t=>{f.seal(t)}),u.updateTickHistory(),H.clear())},"afterTickHooks");var x=null;function B(r,t){r.onAfterTick(_,!0),r.onAfterExecute(S.BaseMessage,w,!0),t&&O(t);let e=a(i=>(i&&Reflect.hasMetadata(s.VERSION,i.constructor)&&f.initComponent(i),i),"amberInitHook");r.addActivationHook(e),x=r}a(B,"activateApp");var A=new Proxy({},{get(r,t){return(...e)=>{if(!x)return S.MessageWriter.warn(`[Virid Vue] App method "${String(t)}" called before initialization.`),null;let i=x[t];if(typeof i=="function")return i.apply(x,e)}}});function Q(r){return t=>{Reflect.defineMetadata(s.BACKUP,!0,t),Reflect.defineMetadata(s.VERSION,0,t),r&&Reflect.defineMetadata(s.CUSTOM_METHOD,r,t)}}a(Q,"Backup");var q={name:"@virid/amber",install(r,t){B(r,t)}};0&&(module.exports={Amber,AmberPlugin,Backup,RestoreDirection,activateConfig,afterExecuteHooks,afterTickHooks,amberComponentStore,amberTickStore});
|
|
6
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/app.ts","../src/amber/store.ts","../src/decorators/constant.ts","../src/interfaces/decorator.ts","../src/amber/utils.ts","../src/amber/amber.ts","../src/amber/hooks.ts","../src/decorators/decorator.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: Add replay, redo, undo and other functions to virid.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nimport { activateApp } from \"./app\";\nimport { PluginOptions } from \"./interfaces\";\nexport * from \"./amber\";\nexport * from \"./decorators\";\nexport * from \"./interfaces\";\nexport const AmberPlugin: ViridPlugin<PluginOptions> = {\n name: \"@virid/amber\",\n install(app: ViridApp, options) {\n activateApp(app, options);\n },\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { type ViridApp, MessageWriter, BaseMessage } from \"@virid/core\";\nimport {\n amberComponentStore,\n afterExecuteHooks,\n afterTickHooks,\n activateConfig,\n} from \"./amber\";\nimport type { PluginOptions } from \"./interfaces\";\nimport { VIRID_AMBER_METADATA } from \"./decorators/constant\";\nexport interface IViridApp {\n get(identifier: any): any;\n}\n\nlet activeApp: IViridApp | null = null;\n\nexport function activateApp(app: ViridApp, options: PluginOptions) {\n //注册钩子\n app.onAfterTick(afterTickHooks, true);\n app.onAfterExecute(BaseMessage, afterExecuteHooks, true);\n //看看用户提供的配置\n if (options) activateConfig(options);\n const amberInitHook = (instance) => {\n if (\n instance &&\n Reflect.hasMetadata(VIRID_AMBER_METADATA.VERSION, instance.constructor)\n ) {\n //实例化的时候,init第一个版本\n amberComponentStore.initComponent(instance);\n }\n return instance;\n };\n app.addActivationHook(amberInitHook);\n activeApp = app;\n}\n\n/**\n * viridApp 代理\n */\nexport const viridApp: IViridApp = new Proxy({} as IViridApp, {\n get(_, prop: keyof IViridApp) {\n return (...args: any[]) => {\n // 检查实例是否存在\n if (!activeApp) {\n MessageWriter.warn(\n `[Virid Vue] App method \"${String(prop)}\" called before initialization.`,\n );\n return null;\n }\n\n // 正常转发调用\n // 使用 Reflect 确保 this 指向正确,或者直接从 activeApp 调用\n const targetMethod = activeApp[prop];\n if (typeof targetMethod === \"function\") {\n // @ts-ignore\n return targetMethod.apply(activeApp, args);\n }\n };\n },\n});\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { MessageWriter } from \"@virid/core\";\nimport { viridApp } from \"../app\";\nimport { VIRID_AMBER_METADATA } from \"../decorators/constant\";\nimport { RestoreDirection, type PluginOptions } from \"../interfaces\";\nimport {\n type VersionMetadata,\n type CustomMethodMetadata,\n} from \"../interfaces\";\n\nimport { _serialization, _deserialization, _diff } from \"./utils\";\nlet config: Required<PluginOptions> = {\n serialization: _serialization,\n deserialization: _deserialization,\n diff: _diff, // 默认总是备份\n};\n\nexport function activateConfig(customConfig: PluginOptions) {\n config = Object.assign(config, customConfig);\n}\n\nclass AmberTickStore {\n // 快照镜像\n private tickHistory: Array<Map<any, any>> = [];\n\n // 记录数组第 0 位对应的真实 Tick 号\n public baseTick = 0;\n\n public maxTickLength = 20;\n // 当前处于哪个逻辑 Tick\n public currentTick = 0;\n\n constructor(maxTickLength: number = 20) {\n this.maxTickLength = maxTickLength;\n }\n /**\n * 获取最小可用Tick\n */\n public getMinTick(): number {\n return this.baseTick;\n }\n\n /**\n * 获取最大的Tick\n */\n public getMaxTick(): number {\n if (this.tickHistory.length === 0) return 0;\n return this.baseTick + this.tickHistory.length - 1;\n }\n /**\n * 记录当前的宏观快照\n */\n public updateTickHistory() {\n // 剪枝\n if (this.currentTick < this.baseTick + this.tickHistory.length) {\n // 剪掉后面的平行宇宙\n this.tickHistory.splice(this.currentTick - this.baseTick + 1);\n }\n\n // 增加加新快照\n const snapshot = new Map(amberComponentStore.currentHistory);\n this.tickHistory.push(snapshot);\n\n // 滑动窗口处理\n if (this.tickHistory.length > this.maxTickLength) {\n this.tickHistory.shift();\n this.baseTick++;\n }\n const newLogicalTick = this.baseTick + this.tickHistory.length - 1;\n // 更新指针到最新产生的这个 Tick\n this.currentTick = newLogicalTick;\n }\n\n /**\n * 全局时空旅行\n */\n public travel(targetTick: number) {\n // 计算物理索引\n const index = targetTick - this.baseTick;\n const historyMap = this.tickHistory[index];\n\n if (!historyMap) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Travel Error: Tick ${targetTick} is out of history range.`,\n ),\n );\n return;\n }\n\n const direction =\n targetTick < this.currentTick\n ? RestoreDirection.UNDO\n : RestoreDirection.REDO;\n\n // 准备一个队列,用于最后统一执行钩子\n const restoreQueue: Array<{\n strategy: any;\n oldData: any;\n newData: any;\n }> = [];\n // 遍历快照中的所有组件类\n for (const [compClass, historicalData] of historyMap) {\n const currentData = amberComponentStore.getCurrentData(compClass);\n // 只有数据不一致时才处理\n if (historicalData !== currentData) {\n const oldData = currentData;\n // 执行物理恢复\n amberComponentStore.deserializeComponent(compClass, historicalData);\n\n // 更新微观层的快照记录\n amberComponentStore.seal(compClass);\n\n // 收集钩子\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n if (customMethod?.onRestore) {\n restoreQueue.push({\n strategy: customMethod,\n oldData,\n newData: historicalData,\n });\n }\n }\n const instance = viridApp.get(compClass);\n }\n\n // 更新宏观时空指针\n this.currentTick = targetTick;\n\n // 统一派发副作用钩子\n restoreQueue.forEach(({ strategy, oldData, newData }) => {\n strategy.onRestore(oldData, newData, direction);\n });\n }\n /**\n * 重置宏观时间轴\n */\n public resetTickStore() {\n // 彻底清空旧的磁带\n this.tickHistory = [];\n this.baseTick = 0;\n this.currentTick = 0;\n\n // 立刻保存一份当前的“现状”作为新起点\n this.updateTickHistory();\n }\n}\n\nclass AmberComponentStore {\n public componentHistory = new Map<any, any[]>();\n // 记录每个组件消失的历史总数\n public biasVersions = new Map<any, number>();\n public maxComponentHistorySize = 20;\n // 记录当前每个组件都是什么版本\n public currentHistory = new Map<any, any>();\n // 记录每个组件消失的历史总数\n constructor(maxComponentHistorySize: number = 20) {\n this.maxComponentHistorySize = maxComponentHistorySize;\n }\n /**\n * 将component 的数据进行序列化\n */\n public serializeComponent(compClass: any) {\n const instance = viridApp.get(compClass);\n if (!instance) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Serialize Error: Component ${compClass.name} is not registered.`,\n ),\n );\n return null;\n }\n\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const serializeFn = customMethod?.serialize || config.serialization;\n try {\n return serializeFn(instance);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Serialize Error: Component ${compClass.name} serialization error`,\n );\n }\n return null;\n }\n /**\n * 将component 的数据反序列化\n */\n public deserializeComponent(compClass: any, data: any) {\n const instance = viridApp.get(compClass);\n if (!instance) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Deserialize Error: Component ${compClass.name} is not registered.`,\n ),\n );\n return;\n }\n if (!data) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Deserialize Error: Component ${compClass.name} data is ${data}!.`,\n ),\n );\n return;\n }\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const deserializeFn =\n customMethod?.deserialize || config.deserialization;\n try {\n deserializeFn(instance, data);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Deserialize Error: Component ${compClass.name} deserialize error`,\n );\n }\n return;\n }\n /**\n * 对比diff\n */\n public diffComponent(compClass: any, old_data: any): boolean {\n const instance = viridApp.get(compClass);\n if (!instance) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Diff Error: Component ${compClass.name} is not registered.`,\n ),\n );\n return false;\n }\n if (!old_data) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Diff Error: Component ${compClass.name} data is ${old_data}!.`,\n ),\n );\n return false;\n }\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const diffFn = customMethod?.diff || config.diff;\n try {\n return diffFn(instance, old_data);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Diff Error: Component ${compClass.name} diff error`,\n );\n }\n return false;\n }\n\n /**\n * 初始化组件的历史记录结构\n */\n public initComponent(instance: any) {\n const compClass = instance.constructor;\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const serializeFn = customMethod?.serialize || config.serialization;\n let data;\n try {\n data = serializeFn(instance);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Serialize Error: Component ${compClass.name} serialization error`,\n );\n return;\n }\n this.componentHistory.set(compClass, []);\n this.biasVersions.set(compClass, 0);\n\n // 将初始数据推入\n this.componentHistory.get(compClass)!.push(data);\n this.currentHistory.set(compClass, data);\n\n // 初始版本设为 0\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, 0, compClass);\n }\n /**\n * 获取组件当前逻辑版本对应的快照数据\n */\n public getCurrentData(compClass: any): any {\n return this.currentHistory.get(compClass);\n }\n\n /**\n * 获取组件在当前滑动窗口内的最小可用版本\n */\n public getMinVersion(compClass: any): number {\n return this.biasVersions.get(compClass) ?? 0;\n }\n\n /**\n * 获取组件在当前物理栈内存在的最大版本(包括撤销后的“未来”)\n */\n public getMaxVersion(compClass: any): number {\n const stack = this.componentHistory.get(compClass);\n const bias = this.biasVersions.get(compClass) ?? 0;\n if (!stack || stack.length === 0) return bias;\n return bias + stack.length - 1;\n }\n\n /**\n * 给一个component 打快照\n * @param compClass 构造函数\n * @returns\n */\n public seal(compClass: any) {\n const stack = this.componentHistory.get(compClass);\n if (!stack) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Seal Error: Component ${compClass.name} is not initialized.`,\n ),\n );\n }\n const baseVersion = this.biasVersions.get(compClass);\n\n const currentSnapshot = this.getCurrentData(compClass);\n // diff判断\n if (currentSnapshot && !this.diffComponent(compClass, currentSnapshot)) {\n return;\n }\n\n const customMethod: CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n if (customMethod?.onBeforeBackup) {\n customMethod.onBeforeBackup(currentSnapshot);\n }\n\n // 剪枝\n const currentLogicalVersion:VersionMetadata =\n Reflect.getMetadata(VIRID_AMBER_METADATA.VERSION, compClass) || 0;\n const latestLogicalVersion = baseVersion + stack.length - 1;\n if (currentLogicalVersion < latestLogicalVersion) {\n stack.splice(currentLogicalVersion - baseVersion + 1);\n }\n\n // 序列化\n const newData = this.serializeComponent(compClass);\n if (!newData) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Seal Error: Component ${compClass.name} is not serializable.`,\n ),\n );\n return;\n }\n stack.push(newData);\n this.currentHistory.set(compClass, newData);\n // 滑动窗口与元数据更新\n if (stack.length > this.maxComponentHistorySize) {\n stack.shift();\n this.biasVersions.set(compClass, baseVersion + 1);\n }\n\n const newLogicalVersion =\n this.biasVersions.get(compClass)! + stack.length - 1;\n Reflect.defineMetadata(\n VIRID_AMBER_METADATA.VERSION,\n newLogicalVersion,\n compClass,\n );\n if (customMethod?.onAfterBackup) {\n customMethod.onAfterBackup(newData);\n }\n }\n /**\n * 回退到指定版本\n * @param compClass component构造函数\n * @param targetVersion 目标版本\n * @returns\n */\n public seek(compClass: any, targetVersion: number): boolean {\n // 边界检查\n const stack = this.componentHistory.get(compClass);\n if (!stack) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Seal Error: Component ${compClass.name} is not initialized.`,\n ),\n );\n return false;\n }\n const baseVersion = this.biasVersions.get(compClass) || 0;\n\n const physicalIndex = targetVersion - baseVersion;\n if (physicalIndex < 0 || physicalIndex >= stack.length) return false;\n\n // 状态对比准备\n const oldData = this.getCurrentData(compClass);\n const newData = stack[physicalIndex];\n const currentVersion:VersionMetadata =\n Reflect.getMetadata(VIRID_AMBER_METADATA.VERSION, compClass) || 0;\n\n const direction =\n targetVersion < currentVersion\n ? RestoreDirection.UNDO\n : RestoreDirection.REDO;\n\n // 执行反序列化\n this.deserializeComponent(compClass, newData);\n\n // 时空指针同步\n this.currentHistory.set(compClass, newData);\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, targetVersion, compClass);\n\n // 触发业务钩子\n const customMethod: CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n if (customMethod?.onRestore) {\n customMethod.onRestore(oldData, newData, direction);\n }\n\n // 告诉时间轴,有个零件变了\n amberTickStore.updateTickHistory();\n return true;\n }\n /**\n * 重置逻辑\n */\n public resetComponentInternal(compClass: any) {\n const newData = this.serializeComponent(compClass);\n if (!newData) return;\n\n // 物理清理\n this.componentHistory.set(compClass, [newData]);\n this.biasVersions.set(compClass, 0);\n this.currentHistory.set(compClass, newData);\n\n // 元数据归零\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, 0, compClass);\n }\n\n public resetComponent(compClass: any) {\n this.resetComponentInternal(compClass);\n // 只有局部重置时,才主动触发宏观记录\n amberTickStore.updateTickHistory();\n }\n}\n\nexport const amberTickStore = new AmberTickStore();\nexport const amberComponentStore = new AmberComponentStore();\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { VIRID_METADATA } from \"@virid/core\";\nexport const VIRID_AMBER_METADATA = {\n ...VIRID_METADATA,\n BACKUP: \"virid:amber:backup\",\n VERSION: \"virid:amber:version\",\n CUSTOM_METHOD: \"virid:amber:custom-method\",\n} as const;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nexport enum RestoreDirection {\n UNDO = \"UNDO\",\n REDO = \"REDO\",\n}\n\nexport interface BackupStrategy<T = any, C = any> {\n /**\n * 自定义序列化:将实例转换为可存储的对象\n */\n serialize?: (instance: T) => C;\n\n /**\n * 自定义反序列化:将数据灌回实例\n */\n deserialize?: (instance: T, data: C) => void;\n\n /**\n * 自定义 Diff:返回 true 表示有变化,需要触发备份\n */\n diff?: (oldData: C, instance: T) => boolean;\n onBeforeBackup?: (oldData: C) => void;\n onAfterBackup?: (newData: C) => void;\n onRestore?: (oldData: C, newData: C, direction: RestoreDirection) => void;\n}\n\nexport type VersionMetadata = number;\nexport type BackupMetadata = boolean;\nexport type CustomMethodMetadata = BackupStrategy;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\n/**\n * 默认 serialization\n */\nexport function _serialization(instance: any, depth = 5): any {\n if (instance === null || typeof instance !== \"object\") return instance;\n if (depth <= 0) return Array.isArray(instance) ? [] : {};\n\n if (Array.isArray(instance)) {\n return instance.map((item) => _serialization(item, depth - 1));\n }\n\n const snapshot: any = {};\n const keys = Object.keys(instance);\n\n for (const key of keys) {\n if (key.startsWith(\"_\")) continue;\n\n const value = instance[key];\n if (typeof value === \"function\") continue;\n\n snapshot[key] =\n typeof value === \"object\" && value !== null\n ? _serialization(value, depth - 1)\n : value;\n }\n return snapshot;\n}\n/**\n * 默认 deserialization\n */\nexport function _deserialization(instance: any, snapshot: any) {\n if (!instance || !snapshot) return;\n\n Object.keys(snapshot).forEach((key) => {\n const newVal = snapshot[key];\n const oldVal = instance[key];\n // 继续递归,而不是直接覆盖对象引用\n if (\n oldVal &&\n typeof oldVal === \"object\" &&\n newVal &&\n typeof newVal === \"object\" &&\n !Array.isArray(newVal)\n ) {\n _deserialization(oldVal, newVal);\n } else {\n // 直接赋值\n instance[key] = newVal;\n }\n });\n}\n/**\n * 默认 Diff\n */\nexport function _diff(oldData: any, instance: any, depth = 3): boolean {\n // 基础类型或引用相同,直接认为没变\n if (oldData === instance) return false;\n\n // 类型不一致,肯定变了\n if (\n typeof oldData !== typeof instance ||\n oldData === null ||\n instance === null\n ) {\n return true;\n }\n // 处理数组\n if (Array.isArray(oldData)) {\n if (!Array.isArray(instance) || oldData.length !== instance.length)\n return true;\n for (let i = 0; i < oldData.length; i++) {\n if (_diff(oldData[i], instance[i], depth - 1)) return true;\n }\n return false;\n }\n\n // 处理对象\n const keys = Object.keys(oldData);\n\n for (const key of keys) {\n const valOld = oldData[key];\n const valNew = instance[key];\n\n if (typeof valOld === \"object\" && valOld !== null) {\n // 达到最大深度限制,不再递归,保守起见认为变了\n if (depth <= 0) continue;\n\n if (_diff(valOld, valNew, depth - 1)) return true;\n } else {\n // 基础类型对比\n if (valOld !== valNew) return true;\n }\n }\n return false;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { amberComponentStore, amberTickStore } from \"./store\";\nimport { VIRID_AMBER_METADATA } from \"../decorators/constant\";\n\nexport class Amber {\n /**\n * 获取组件当前的逻辑版本号\n */\n public static getVersion(compClass: any): number {\n return Reflect.getMetadata(VIRID_AMBER_METADATA.VERSION, compClass) || 0;\n }\n\n public static canUndo(compClass: any): boolean {\n const current = this.getVersion(compClass);\n const min = amberComponentStore.getMinVersion(compClass);\n\n return current > min;\n }\n\n public static canRedo(compClass: any): boolean {\n const current = this.getVersion(compClass);\n const max = amberComponentStore.getMaxVersion(compClass);\n\n return current < max;\n }\n\n /**\n * 局部撤销:将单个组件回退一个版本\n * 结果:产生新 Tick,代表“我回到了过去”\n */\n public static undo(compClass: any): boolean {\n if (!this.canUndo(compClass)) return false;\n const current = this.getVersion(compClass);\n const result = amberComponentStore.seek(compClass, current - 1);\n\n return result;\n }\n\n /**\n * 局部重做:将单个组件向前进一个版本\n */\n public static redo(compClass: any): boolean {\n if (!this.canRedo(compClass)) return false;\n const current = this.getVersion(compClass);\n const result = amberComponentStore.seek(compClass, current + 1);\n\n return result;\n }\n /**\n * 全局撤销\n */\n public static undoTick(): boolean {\n if (!this.canUndoTick()) return false;\n const targetTick = amberTickStore.currentTick - 1;\n amberTickStore.travel(targetTick);\n return true;\n }\n\n /**\n * 全局重做\n */\n public static redoTick(): boolean {\n if (!this.canRedoTick()) return false;\n const targetTick = amberTickStore.currentTick + 1;\n amberTickStore.travel(targetTick);\n return true;\n }\n\n /**\n * UI 状态判断:是否还能点撤销\n */\n public static canUndoTick(): boolean {\n const currentTick = amberTickStore.currentTick;\n const minTick = amberTickStore.getMinTick();\n\n return currentTick > minTick;\n }\n\n /**\n * UI 状态判断:是否还能点重做\n */\n public static canRedoTick(): boolean {\n const currentTick = amberTickStore.currentTick;\n const maxTick = amberTickStore.getMaxTick();\n\n return currentTick < maxTick;\n }\n\n /**\n * 重置宏观时间轴\n * 清空所有全局快照,用户无法再进行 undoTick/redoTick,\n * 但各个组件当前的微观版本栈保持不变。\n */\n public static resetTick(): void {\n amberTickStore.resetTickStore();\n }\n\n /**\n * 重置特定组件的历史\n * 该组件的旧版本被物理抹除,当前状态变为 V0。\n * 会自动触发一次 updateTickHistory,记录这一时刻的全局状态。\n */\n public static resetComponent(compClass: any): void {\n amberComponentStore.resetComponent(compClass);\n }\n // 建议添加到 Amber 类中\n public static resetAll(): void {\n // 获取所有存活组件\n const classes = Array.from(amberComponentStore.componentHistory.keys());\n // 清空每个组件(静默重置,不触发 updateTickHistory)\n classes.forEach((compClass) => {\n // 我们可以给 resetComponent 加个参数,或者拆分出一个内部方法\n amberComponentStore.resetComponentInternal(compClass);\n });\n // 重置宏观磁带\n amberTickStore.resetTickStore();\n }\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport {\n type ExecuteHook,\n type TickHook,\n AtomicModifyMessage,\n BaseMessage,\n ErrorMessage,\n WarnMessage,\n InfoMessage,\n} from \"@virid/core\";\nimport { amberComponentStore, amberTickStore } from \"./store\";\nimport { VIRID_AMBER_METADATA } from \"../decorators/constant\";\n\nconst dirtyBuffer = new Set<any>();\n\nexport const afterExecuteHooks: ExecuteHook<BaseMessage> = (\n message,\n context,\n) => {\n if (\n message instanceof ErrorMessage ||\n message instanceof WarnMessage ||\n message instanceof InfoMessage\n )\n return;\n\n const allParams =\n message instanceof AtomicModifyMessage\n ? [...context.context.params, message.ComponentClass]\n : context.context.params;\n\n allParams.forEach((paramClass) => {\n if (Reflect.hasMetadata(VIRID_AMBER_METADATA.BACKUP, paramClass)) {\n dirtyBuffer.add(paramClass);\n }\n });\n};\n\nexport const afterTickHooks: TickHook = (_context) => {\n if (dirtyBuffer.size === 0) return;\n\n // 微观更新\n dirtyBuffer.forEach((compClass) => {\n amberComponentStore.seal(compClass);\n });\n\n // 宏观更新\n amberTickStore.updateTickHistory();\n\n // 清理缓存,准备下一轮\n dirtyBuffer.clear();\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { VIRID_AMBER_METADATA } from \"./constant\";\nimport { type BackupStrategy } from \"../interfaces\";\n\n/**\n * @description: 标记 Backup 身份并配置自定义备份策略\n * @param strategy 可选的自定义序列化/反序列化/Diff 方案\n */\nexport function Backup<T extends new (...args: any[]) => any, C = any>(\n strategy?: BackupStrategy<InstanceType<T>, C>,\n) {\n return (target: T) => {\n // 标记需要备份\n Reflect.defineMetadata(VIRID_AMBER_METADATA.BACKUP, true, target);\n // 初始化版本号\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, 0, target);\n // 如果用户给了自定义方法,存入元数据\n if (strategy) {\n Reflect.defineMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n strategy,\n target,\n );\n }\n };\n}\n"],"mappings":";;;;ulBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,gBAAAC,EAAA,WAAAC,EAAA,qBAAAC,EAAA,mBAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAX,GCKA,IAAAY,EAA0D,uBCA1D,IAAAC,EAA8B,uBCA9B,IAAAC,EAA+B,uBAClBC,EAAuB,CAClC,GAAGC,iBACHC,OAAQ,qBACRC,QAAS,sBACTC,cAAe,2BACjB,ECNO,IAAKC,GAAAA,SAAAA,EAAAA,oCAAAA,QCGL,SAASC,EAAeC,EAAeC,EAAQ,EAAC,CACrD,GAAID,IAAa,MAAQ,OAAOA,GAAa,SAAU,OAAOA,EAC9D,GAAIC,GAAS,EAAG,OAAOC,MAAMC,QAAQH,CAAAA,EAAY,CAAA,EAAK,CAAC,EAEvD,GAAIE,MAAMC,QAAQH,CAAAA,EAChB,OAAOA,EAASI,IAAKC,GAASN,EAAeM,EAAMJ,EAAQ,CAAA,CAAA,EAG7D,IAAMK,EAAgB,CAAC,EACjBC,EAAOC,OAAOD,KAAKP,CAAAA,EAEzB,QAAWS,KAAOF,EAAM,CACtB,GAAIE,EAAIC,WAAW,GAAA,EAAM,SAEzB,IAAMC,EAAQX,EAASS,CAAAA,EACnB,OAAOE,GAAU,aAErBL,EAASG,CAAAA,EACP,OAAOE,GAAU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DD,GACFE,QAAQC,eACNC,EAAqBG,cACrBP,EACAC,CAAAA,CAGN,CACF,CAjBgBF,EAAAA,EAAAA,URWT,IAAMS,EAA0C,CACrDC,KAAM,eACNC,QAAQC,EAAeC,EAAO,CAC5BC,EAAYF,EAAKC,CAAAA,CACnB,CACF","names":["index_exports","__export","Amber","AmberPlugin","Backup","RestoreDirection","activateConfig","afterExecuteHooks","afterTickHooks","amberComponentStore","amberTickStore","__toCommonJS","import_core","import_core","import_core","VIRID_AMBER_METADATA","VIRID_METADATA","BACKUP","VERSION","CUSTOM_METHOD","RestoreDirection","_serialization","instance","depth","Array","isArray","map","item","snapshot","keys","Object","key","startsWith","value","_deserialization","forEach","newVal","oldVal","_diff","oldData","length","i","valOld","valNew","config","serialization","_serialization","deserialization","_deserialization","diff","_diff","activateConfig","customConfig","Object","assign","_a","AmberTickStore","maxTickLength","tickHistory","baseTick","currentTick","getMinTick","getMaxTick","length","updateTickHistory","splice","snapshot","Map","amberComponentStore","currentHistory","push","shift","newLogicalTick","travel","targetTick","index","historyMap","MessageWriter","error","Error","direction","RestoreDirection","UNDO","REDO","restoreQueue","compClass","historicalData","currentData","getCurrentData","oldData","deserializeComponent","seal","customMethod","Reflect","getMetadata","VIRID_AMBER_METADATA","CUSTOM_METHOD","onRestore","strategy","newData","instance","viridApp","get","forEach","resetTickStore","AmberComponentStore","maxComponentHistorySize","componentHistory","biasVersions","serializeComponent","name","serializeFn","serialize","e","data","deserializeFn","deserialize","diffComponent","old_data","diffFn","initComponent","set","defineMetadata","VERSION","getMinVersion","getMaxVersion","stack","bias","baseVersion","currentSnapshot","onBeforeBackup","currentLogicalVersion","latestLogicalVersion","newLogicalVersion","onAfterBackup","seek","targetVersion","physicalIndex","currentVersion","amberTickStore","resetComponentInternal","resetComponent","Amber","getVersion","compClass","Reflect","getMetadata","VIRID_AMBER_METADATA","VERSION","canUndo","current","min","amberComponentStore","getMinVersion","canRedo","max","getMaxVersion","undo","seek","redo","undoTick","canUndoTick","targetTick","amberTickStore","currentTick","travel","redoTick","canRedoTick","minTick","getMinTick","maxTick","getMaxTick","resetTick","resetTickStore","resetComponent","resetAll","Array","from","componentHistory","keys","forEach","resetComponentInternal","_Amber","import_core","dirtyBuffer","Set","afterExecuteHooks","__name","message","context","ErrorMessage","WarnMessage","InfoMessage","AtomicModifyMessage","params","ComponentClass","forEach","paramClass","Reflect","hasMetadata","VIRID_AMBER_METADATA","BACKUP","add","afterTickHooks","_context","size","compClass","amberComponentStore","seal","amberTickStore","updateTickHistory","clear","activeApp","activateApp","app","options","onAfterTick","afterTickHooks","onAfterExecute","BaseMessage","afterExecuteHooks","activateConfig","amberInitHook","__name","instance","Reflect","hasMetadata","VIRID_AMBER_METADATA","VERSION","amberComponentStore","initComponent","addActivationHook","viridApp","Proxy","get","_","prop","args","MessageWriter","warn","String","targetMethod","apply","Backup","strategy","target","Reflect","defineMetadata","VIRID_AMBER_METADATA","BACKUP","VERSION","CUSTOM_METHOD","AmberPlugin","name","install","app","options","activateApp"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ExecuteHook, BaseMessage, TickHook, ViridPlugin } from '@virid/core';
|
|
2
|
+
|
|
3
|
+
interface PluginOptions {
|
|
4
|
+
serialization?: (instance: any) => any;
|
|
5
|
+
deserialization?: (instance: any, data: any) => any;
|
|
6
|
+
diff?: (data: any, instance: any) => boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare enum RestoreDirection {
|
|
10
|
+
UNDO = "UNDO",
|
|
11
|
+
REDO = "REDO"
|
|
12
|
+
}
|
|
13
|
+
interface BackupStrategy<T = any, C = any> {
|
|
14
|
+
/**
|
|
15
|
+
* 自定义序列化:将实例转换为可存储的对象
|
|
16
|
+
*/
|
|
17
|
+
serialize?: (instance: T) => C;
|
|
18
|
+
/**
|
|
19
|
+
* 自定义反序列化:将数据灌回实例
|
|
20
|
+
*/
|
|
21
|
+
deserialize?: (instance: T, data: C) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 自定义 Diff:返回 true 表示有变化,需要触发备份
|
|
24
|
+
*/
|
|
25
|
+
diff?: (oldData: C, instance: T) => boolean;
|
|
26
|
+
onBeforeBackup?: (oldData: C) => void;
|
|
27
|
+
onAfterBackup?: (newData: C) => void;
|
|
28
|
+
onRestore?: (oldData: C, newData: C, direction: RestoreDirection) => void;
|
|
29
|
+
}
|
|
30
|
+
type VersionMetadata = number;
|
|
31
|
+
type BackupMetadata = boolean;
|
|
32
|
+
type CustomMethodMetadata = BackupStrategy;
|
|
33
|
+
|
|
34
|
+
declare class Amber {
|
|
35
|
+
/**
|
|
36
|
+
* 获取组件当前的逻辑版本号
|
|
37
|
+
*/
|
|
38
|
+
static getVersion(compClass: any): number;
|
|
39
|
+
static canUndo(compClass: any): boolean;
|
|
40
|
+
static canRedo(compClass: any): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* 局部撤销:将单个组件回退一个版本
|
|
43
|
+
* 结果:产生新 Tick,代表“我回到了过去”
|
|
44
|
+
*/
|
|
45
|
+
static undo(compClass: any): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 局部重做:将单个组件向前进一个版本
|
|
48
|
+
*/
|
|
49
|
+
static redo(compClass: any): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* 全局撤销
|
|
52
|
+
*/
|
|
53
|
+
static undoTick(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 全局重做
|
|
56
|
+
*/
|
|
57
|
+
static redoTick(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* UI 状态判断:是否还能点撤销
|
|
60
|
+
*/
|
|
61
|
+
static canUndoTick(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* UI 状态判断:是否还能点重做
|
|
64
|
+
*/
|
|
65
|
+
static canRedoTick(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 重置宏观时间轴
|
|
68
|
+
* 清空所有全局快照,用户无法再进行 undoTick/redoTick,
|
|
69
|
+
* 但各个组件当前的微观版本栈保持不变。
|
|
70
|
+
*/
|
|
71
|
+
static resetTick(): void;
|
|
72
|
+
/**
|
|
73
|
+
* 重置特定组件的历史
|
|
74
|
+
* 该组件的旧版本被物理抹除,当前状态变为 V0。
|
|
75
|
+
* 会自动触发一次 updateTickHistory,记录这一时刻的全局状态。
|
|
76
|
+
*/
|
|
77
|
+
static resetComponent(compClass: any): void;
|
|
78
|
+
static resetAll(): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare const afterExecuteHooks: ExecuteHook<BaseMessage>;
|
|
82
|
+
declare const afterTickHooks: TickHook;
|
|
83
|
+
|
|
84
|
+
declare function activateConfig(customConfig: PluginOptions): void;
|
|
85
|
+
declare class AmberTickStore {
|
|
86
|
+
private tickHistory;
|
|
87
|
+
baseTick: number;
|
|
88
|
+
maxTickLength: number;
|
|
89
|
+
currentTick: number;
|
|
90
|
+
constructor(maxTickLength?: number);
|
|
91
|
+
/**
|
|
92
|
+
* 获取最小可用Tick
|
|
93
|
+
*/
|
|
94
|
+
getMinTick(): number;
|
|
95
|
+
/**
|
|
96
|
+
* 获取最大的Tick
|
|
97
|
+
*/
|
|
98
|
+
getMaxTick(): number;
|
|
99
|
+
/**
|
|
100
|
+
* 记录当前的宏观快照
|
|
101
|
+
*/
|
|
102
|
+
updateTickHistory(): void;
|
|
103
|
+
/**
|
|
104
|
+
* 全局时空旅行
|
|
105
|
+
*/
|
|
106
|
+
travel(targetTick: number): void;
|
|
107
|
+
/**
|
|
108
|
+
* 重置宏观时间轴
|
|
109
|
+
*/
|
|
110
|
+
resetTickStore(): void;
|
|
111
|
+
}
|
|
112
|
+
declare class AmberComponentStore {
|
|
113
|
+
componentHistory: Map<any, any[]>;
|
|
114
|
+
biasVersions: Map<any, number>;
|
|
115
|
+
maxComponentHistorySize: number;
|
|
116
|
+
currentHistory: Map<any, any>;
|
|
117
|
+
constructor(maxComponentHistorySize?: number);
|
|
118
|
+
/**
|
|
119
|
+
* 将component 的数据进行序列化
|
|
120
|
+
*/
|
|
121
|
+
serializeComponent(compClass: any): any;
|
|
122
|
+
/**
|
|
123
|
+
* 将component 的数据反序列化
|
|
124
|
+
*/
|
|
125
|
+
deserializeComponent(compClass: any, data: any): void;
|
|
126
|
+
/**
|
|
127
|
+
* 对比diff
|
|
128
|
+
*/
|
|
129
|
+
diffComponent(compClass: any, old_data: any): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* 初始化组件的历史记录结构
|
|
132
|
+
*/
|
|
133
|
+
initComponent(instance: any): void;
|
|
134
|
+
/**
|
|
135
|
+
* 获取组件当前逻辑版本对应的快照数据
|
|
136
|
+
*/
|
|
137
|
+
getCurrentData(compClass: any): any;
|
|
138
|
+
/**
|
|
139
|
+
* 获取组件在当前滑动窗口内的最小可用版本
|
|
140
|
+
*/
|
|
141
|
+
getMinVersion(compClass: any): number;
|
|
142
|
+
/**
|
|
143
|
+
* 获取组件在当前物理栈内存在的最大版本(包括撤销后的“未来”)
|
|
144
|
+
*/
|
|
145
|
+
getMaxVersion(compClass: any): number;
|
|
146
|
+
/**
|
|
147
|
+
* 给一个component 打快照
|
|
148
|
+
* @param compClass 构造函数
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
seal(compClass: any): void;
|
|
152
|
+
/**
|
|
153
|
+
* 回退到指定版本
|
|
154
|
+
* @param compClass component构造函数
|
|
155
|
+
* @param targetVersion 目标版本
|
|
156
|
+
* @returns
|
|
157
|
+
*/
|
|
158
|
+
seek(compClass: any, targetVersion: number): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* 重置逻辑
|
|
161
|
+
*/
|
|
162
|
+
resetComponentInternal(compClass: any): void;
|
|
163
|
+
resetComponent(compClass: any): void;
|
|
164
|
+
}
|
|
165
|
+
declare const amberTickStore: AmberTickStore;
|
|
166
|
+
declare const amberComponentStore: AmberComponentStore;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @description: 标记 Backup 身份并配置自定义备份策略
|
|
170
|
+
* @param strategy 可选的自定义序列化/反序列化/Diff 方案
|
|
171
|
+
*/
|
|
172
|
+
declare function Backup<T extends new (...args: any[]) => any, C = any>(strategy?: BackupStrategy<InstanceType<T>, C>): (target: T) => void;
|
|
173
|
+
|
|
174
|
+
declare const AmberPlugin: ViridPlugin<PluginOptions>;
|
|
175
|
+
|
|
176
|
+
export { Amber, AmberPlugin, Backup, type BackupMetadata, type BackupStrategy, type CustomMethodMetadata, type PluginOptions, RestoreDirection, type VersionMetadata, activateConfig, afterExecuteHooks, afterTickHooks, amberComponentStore, amberTickStore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ExecuteHook, BaseMessage, TickHook, ViridPlugin } from '@virid/core';
|
|
2
|
+
|
|
3
|
+
interface PluginOptions {
|
|
4
|
+
serialization?: (instance: any) => any;
|
|
5
|
+
deserialization?: (instance: any, data: any) => any;
|
|
6
|
+
diff?: (data: any, instance: any) => boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare enum RestoreDirection {
|
|
10
|
+
UNDO = "UNDO",
|
|
11
|
+
REDO = "REDO"
|
|
12
|
+
}
|
|
13
|
+
interface BackupStrategy<T = any, C = any> {
|
|
14
|
+
/**
|
|
15
|
+
* 自定义序列化:将实例转换为可存储的对象
|
|
16
|
+
*/
|
|
17
|
+
serialize?: (instance: T) => C;
|
|
18
|
+
/**
|
|
19
|
+
* 自定义反序列化:将数据灌回实例
|
|
20
|
+
*/
|
|
21
|
+
deserialize?: (instance: T, data: C) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 自定义 Diff:返回 true 表示有变化,需要触发备份
|
|
24
|
+
*/
|
|
25
|
+
diff?: (oldData: C, instance: T) => boolean;
|
|
26
|
+
onBeforeBackup?: (oldData: C) => void;
|
|
27
|
+
onAfterBackup?: (newData: C) => void;
|
|
28
|
+
onRestore?: (oldData: C, newData: C, direction: RestoreDirection) => void;
|
|
29
|
+
}
|
|
30
|
+
type VersionMetadata = number;
|
|
31
|
+
type BackupMetadata = boolean;
|
|
32
|
+
type CustomMethodMetadata = BackupStrategy;
|
|
33
|
+
|
|
34
|
+
declare class Amber {
|
|
35
|
+
/**
|
|
36
|
+
* 获取组件当前的逻辑版本号
|
|
37
|
+
*/
|
|
38
|
+
static getVersion(compClass: any): number;
|
|
39
|
+
static canUndo(compClass: any): boolean;
|
|
40
|
+
static canRedo(compClass: any): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* 局部撤销:将单个组件回退一个版本
|
|
43
|
+
* 结果:产生新 Tick,代表“我回到了过去”
|
|
44
|
+
*/
|
|
45
|
+
static undo(compClass: any): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 局部重做:将单个组件向前进一个版本
|
|
48
|
+
*/
|
|
49
|
+
static redo(compClass: any): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* 全局撤销
|
|
52
|
+
*/
|
|
53
|
+
static undoTick(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 全局重做
|
|
56
|
+
*/
|
|
57
|
+
static redoTick(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* UI 状态判断:是否还能点撤销
|
|
60
|
+
*/
|
|
61
|
+
static canUndoTick(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* UI 状态判断:是否还能点重做
|
|
64
|
+
*/
|
|
65
|
+
static canRedoTick(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 重置宏观时间轴
|
|
68
|
+
* 清空所有全局快照,用户无法再进行 undoTick/redoTick,
|
|
69
|
+
* 但各个组件当前的微观版本栈保持不变。
|
|
70
|
+
*/
|
|
71
|
+
static resetTick(): void;
|
|
72
|
+
/**
|
|
73
|
+
* 重置特定组件的历史
|
|
74
|
+
* 该组件的旧版本被物理抹除,当前状态变为 V0。
|
|
75
|
+
* 会自动触发一次 updateTickHistory,记录这一时刻的全局状态。
|
|
76
|
+
*/
|
|
77
|
+
static resetComponent(compClass: any): void;
|
|
78
|
+
static resetAll(): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare const afterExecuteHooks: ExecuteHook<BaseMessage>;
|
|
82
|
+
declare const afterTickHooks: TickHook;
|
|
83
|
+
|
|
84
|
+
declare function activateConfig(customConfig: PluginOptions): void;
|
|
85
|
+
declare class AmberTickStore {
|
|
86
|
+
private tickHistory;
|
|
87
|
+
baseTick: number;
|
|
88
|
+
maxTickLength: number;
|
|
89
|
+
currentTick: number;
|
|
90
|
+
constructor(maxTickLength?: number);
|
|
91
|
+
/**
|
|
92
|
+
* 获取最小可用Tick
|
|
93
|
+
*/
|
|
94
|
+
getMinTick(): number;
|
|
95
|
+
/**
|
|
96
|
+
* 获取最大的Tick
|
|
97
|
+
*/
|
|
98
|
+
getMaxTick(): number;
|
|
99
|
+
/**
|
|
100
|
+
* 记录当前的宏观快照
|
|
101
|
+
*/
|
|
102
|
+
updateTickHistory(): void;
|
|
103
|
+
/**
|
|
104
|
+
* 全局时空旅行
|
|
105
|
+
*/
|
|
106
|
+
travel(targetTick: number): void;
|
|
107
|
+
/**
|
|
108
|
+
* 重置宏观时间轴
|
|
109
|
+
*/
|
|
110
|
+
resetTickStore(): void;
|
|
111
|
+
}
|
|
112
|
+
declare class AmberComponentStore {
|
|
113
|
+
componentHistory: Map<any, any[]>;
|
|
114
|
+
biasVersions: Map<any, number>;
|
|
115
|
+
maxComponentHistorySize: number;
|
|
116
|
+
currentHistory: Map<any, any>;
|
|
117
|
+
constructor(maxComponentHistorySize?: number);
|
|
118
|
+
/**
|
|
119
|
+
* 将component 的数据进行序列化
|
|
120
|
+
*/
|
|
121
|
+
serializeComponent(compClass: any): any;
|
|
122
|
+
/**
|
|
123
|
+
* 将component 的数据反序列化
|
|
124
|
+
*/
|
|
125
|
+
deserializeComponent(compClass: any, data: any): void;
|
|
126
|
+
/**
|
|
127
|
+
* 对比diff
|
|
128
|
+
*/
|
|
129
|
+
diffComponent(compClass: any, old_data: any): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* 初始化组件的历史记录结构
|
|
132
|
+
*/
|
|
133
|
+
initComponent(instance: any): void;
|
|
134
|
+
/**
|
|
135
|
+
* 获取组件当前逻辑版本对应的快照数据
|
|
136
|
+
*/
|
|
137
|
+
getCurrentData(compClass: any): any;
|
|
138
|
+
/**
|
|
139
|
+
* 获取组件在当前滑动窗口内的最小可用版本
|
|
140
|
+
*/
|
|
141
|
+
getMinVersion(compClass: any): number;
|
|
142
|
+
/**
|
|
143
|
+
* 获取组件在当前物理栈内存在的最大版本(包括撤销后的“未来”)
|
|
144
|
+
*/
|
|
145
|
+
getMaxVersion(compClass: any): number;
|
|
146
|
+
/**
|
|
147
|
+
* 给一个component 打快照
|
|
148
|
+
* @param compClass 构造函数
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
seal(compClass: any): void;
|
|
152
|
+
/**
|
|
153
|
+
* 回退到指定版本
|
|
154
|
+
* @param compClass component构造函数
|
|
155
|
+
* @param targetVersion 目标版本
|
|
156
|
+
* @returns
|
|
157
|
+
*/
|
|
158
|
+
seek(compClass: any, targetVersion: number): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* 重置逻辑
|
|
161
|
+
*/
|
|
162
|
+
resetComponentInternal(compClass: any): void;
|
|
163
|
+
resetComponent(compClass: any): void;
|
|
164
|
+
}
|
|
165
|
+
declare const amberTickStore: AmberTickStore;
|
|
166
|
+
declare const amberComponentStore: AmberComponentStore;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @description: 标记 Backup 身份并配置自定义备份策略
|
|
170
|
+
* @param strategy 可选的自定义序列化/反序列化/Diff 方案
|
|
171
|
+
*/
|
|
172
|
+
declare function Backup<T extends new (...args: any[]) => any, C = any>(strategy?: BackupStrategy<InstanceType<T>, C>): (target: T) => void;
|
|
173
|
+
|
|
174
|
+
declare const AmberPlugin: ViridPlugin<PluginOptions>;
|
|
175
|
+
|
|
176
|
+
export { Amber, AmberPlugin, Backup, type BackupMetadata, type BackupStrategy, type CustomMethodMetadata, type PluginOptions, RestoreDirection, type VersionMetadata, activateConfig, afterExecuteHooks, afterTickHooks, amberComponentStore, amberTickStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @virid/amber v0.0.1
|
|
3
|
+
* Add replay, redo, undo and other functions to virid
|
|
4
|
+
*/
|
|
5
|
+
var D=Object.defineProperty;var v=(r,t,e)=>t in r?D(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var a=(r,t)=>D(r,"name",{value:t,configurable:!0});var d=(r,t,e)=>v(r,typeof t!="symbol"?t+"":t,e);import{MessageWriter as P,BaseMessage as F}from"@virid/core";import{MessageWriter as h}from"@virid/core";import{VIRID_METADATA as U}from"@virid/core";var s={...U,BACKUP:"virid:amber:backup",VERSION:"virid:amber:version",CUSTOM_METHOD:"virid:amber:custom-method"};var p=(function(r){return r.UNDO="UNDO",r.REDO="REDO",r})({});function E(r,t=5){if(r===null||typeof r!="object")return r;if(t<=0)return Array.isArray(r)?[]:{};if(Array.isArray(r))return r.map(n=>E(n,t-1));let e={},i=Object.keys(r);for(let n of i){if(n.startsWith("_"))continue;let o=r[n];typeof o!="function"&&(e[n]=typeof o=="object"&&o!==null?E(o,t-1):o)}return e}a(E,"_serialization");function H(r,t){!r||!t||Object.keys(t).forEach(e=>{let i=t[e],n=r[e];n&&typeof n=="object"&&i&&typeof i=="object"&&!Array.isArray(i)?H(n,i):r[e]=i})}a(H,"_deserialization");function b(r,t,e=3){if(r===t)return!1;if(typeof r!=typeof t||r===null||t===null)return!0;if(Array.isArray(r)){if(!Array.isArray(t)||r.length!==t.length)return!0;for(let n=0;n<r.length;n++)if(b(r[n],t[n],e-1))return!0;return!1}let i=Object.keys(r);for(let n of i){let o=r[n],c=t[n];if(typeof o=="object"&&o!==null){if(e<=0)continue;if(b(o,c,e-1))return!0}else if(o!==c)return!0}return!1}a(b,"_diff");var k={serialization:E,deserialization:H,diff:b};function O(r){k=Object.assign(k,r)}a(O,"activateConfig");var T,B=(T=class{constructor(t=20){d(this,"tickHistory",[]);d(this,"baseTick",0);d(this,"maxTickLength",20);d(this,"currentTick",0);this.maxTickLength=t}getMinTick(){return this.baseTick}getMaxTick(){return this.tickHistory.length===0?0:this.baseTick+this.tickHistory.length-1}updateTickHistory(){this.currentTick<this.baseTick+this.tickHistory.length&&this.tickHistory.splice(this.currentTick-this.baseTick+1);let t=new Map(f.currentHistory);this.tickHistory.push(t),this.tickHistory.length>this.maxTickLength&&(this.tickHistory.shift(),this.baseTick++);let e=this.baseTick+this.tickHistory.length-1;this.currentTick=e}travel(t){let e=t-this.baseTick,i=this.tickHistory[e];if(!i){h.error(new Error(`[Virid Amber] Travel Error: Tick ${t} is out of history range.`));return}let n=t<this.currentTick?p.UNDO:p.REDO,o=[];for(let[c,m]of i){let l=f.getCurrentData(c);if(m!==l){let A=l;f.deserializeComponent(c,m),f.seal(c);let S=Reflect.getMetadata(s.CUSTOM_METHOD,c);S?.onRestore&&o.push({strategy:S,oldData:A,newData:m})}let y=g.get(c)}this.currentTick=t,o.forEach(({strategy:c,oldData:m,newData:l})=>{c.onRestore(m,l,n)})}resetTickStore(){this.tickHistory=[],this.baseTick=0,this.currentTick=0,this.updateTickHistory()}},a(T,"AmberTickStore"),T),M,$=(M=class{constructor(t=20){d(this,"componentHistory",new Map);d(this,"biasVersions",new Map);d(this,"maxComponentHistorySize",20);d(this,"currentHistory",new Map);this.maxComponentHistorySize=t}serializeComponent(t){let e=g.get(t);if(!e)return h.error(new Error(`[Virid Amber] Serialize Error: Component ${t.name} is not registered.`)),null;let n=Reflect.getMetadata(s.CUSTOM_METHOD,t)?.serialize||k.serialization;try{return n(e)}catch(o){h.error(o,`[Virid Amber] Serialize Error: Component ${t.name} serialization error`)}return null}deserializeComponent(t,e){let i=g.get(t);if(!i){h.error(new Error(`[Virid Amber] Deserialize Error: Component ${t.name} is not registered.`));return}if(!e){h.error(new Error(`[Virid Amber] Deserialize Error: Component ${t.name} data is ${e}!.`));return}let o=Reflect.getMetadata(s.CUSTOM_METHOD,t)?.deserialize||k.deserialization;try{o(i,e)}catch(c){h.error(c,`[Virid Amber] Deserialize Error: Component ${t.name} deserialize error`)}}diffComponent(t,e){let i=g.get(t);if(!i)return h.error(new Error(`[Virid Amber] Diff Error: Component ${t.name} is not registered.`)),!1;if(!e)return h.error(new Error(`[Virid Amber] Diff Error: Component ${t.name} data is ${e}!.`)),!1;let o=Reflect.getMetadata(s.CUSTOM_METHOD,t)?.diff||k.diff;try{return o(i,e)}catch(c){h.error(c,`[Virid Amber] Diff Error: Component ${t.name} diff error`)}return!1}initComponent(t){let e=t.constructor,n=Reflect.getMetadata(s.CUSTOM_METHOD,e)?.serialize||k.serialization,o;try{o=n(t)}catch(c){h.error(c,`[Virid Amber] Serialize Error: Component ${e.name} serialization error`);return}this.componentHistory.set(e,[]),this.biasVersions.set(e,0),this.componentHistory.get(e).push(o),this.currentHistory.set(e,o),Reflect.defineMetadata(s.VERSION,0,e)}getCurrentData(t){return this.currentHistory.get(t)}getMinVersion(t){return this.biasVersions.get(t)??0}getMaxVersion(t){let e=this.componentHistory.get(t),i=this.biasVersions.get(t)??0;return!e||e.length===0?i:i+e.length-1}seal(t){let e=this.componentHistory.get(t);e||h.error(new Error(`[Virid Amber] Seal Error: Component ${t.name} is not initialized.`));let i=this.biasVersions.get(t),n=this.getCurrentData(t);if(n&&!this.diffComponent(t,n))return;let o=Reflect.getMetadata(s.CUSTOM_METHOD,t);o?.onBeforeBackup&&o.onBeforeBackup(n);let c=Reflect.getMetadata(s.VERSION,t)||0,m=i+e.length-1;c<m&&e.splice(c-i+1);let l=this.serializeComponent(t);if(!l){h.error(new Error(`[Virid Amber] Seal Error: Component ${t.name} is not serializable.`));return}e.push(l),this.currentHistory.set(t,l),e.length>this.maxComponentHistorySize&&(e.shift(),this.biasVersions.set(t,i+1));let y=this.biasVersions.get(t)+e.length-1;Reflect.defineMetadata(s.VERSION,y,t),o?.onAfterBackup&&o.onAfterBackup(l)}seek(t,e){let i=this.componentHistory.get(t);if(!i)return h.error(new Error(`[Virid Amber] Seal Error: Component ${t.name} is not initialized.`)),!1;let n=this.biasVersions.get(t)||0,o=e-n;if(o<0||o>=i.length)return!1;let c=this.getCurrentData(t),m=i[o],l=Reflect.getMetadata(s.VERSION,t)||0,y=e<l?p.UNDO:p.REDO;this.deserializeComponent(t,m),this.currentHistory.set(t,m),Reflect.defineMetadata(s.VERSION,e,t);let A=Reflect.getMetadata(s.CUSTOM_METHOD,t);return A?.onRestore&&A.onRestore(c,m,y),u.updateTickHistory(),!0}resetComponentInternal(t){let e=this.serializeComponent(t);e&&(this.componentHistory.set(t,[e]),this.biasVersions.set(t,0),this.currentHistory.set(t,e),Reflect.defineMetadata(s.VERSION,0,t))}resetComponent(t){this.resetComponentInternal(t),u.updateTickHistory()}},a(M,"AmberComponentStore"),M),u=new B,f=new $;var x=class x{static getVersion(t){return Reflect.getMetadata(s.VERSION,t)||0}static canUndo(t){let e=this.getVersion(t),i=f.getMinVersion(t);return e>i}static canRedo(t){let e=this.getVersion(t),i=f.getMaxVersion(t);return e<i}static undo(t){if(!this.canUndo(t))return!1;let e=this.getVersion(t);return f.seek(t,e-1)}static redo(t){if(!this.canRedo(t))return!1;let e=this.getVersion(t);return f.seek(t,e+1)}static undoTick(){if(!this.canUndoTick())return!1;let t=u.currentTick-1;return u.travel(t),!0}static redoTick(){if(!this.canRedoTick())return!1;let t=u.currentTick+1;return u.travel(t),!0}static canUndoTick(){let t=u.currentTick,e=u.getMinTick();return t>e}static canRedoTick(){let t=u.currentTick,e=u.getMaxTick();return t<e}static resetTick(){u.resetTickStore()}static resetComponent(t){f.resetComponent(t)}static resetAll(){Array.from(f.componentHistory.keys()).forEach(e=>{f.resetComponentInternal(e)}),u.resetTickStore()}};a(x,"Amber");var z=x;import{AtomicModifyMessage as C,ErrorMessage as N,WarnMessage as j,InfoMessage as L}from"@virid/core";var V=new Set,I=a((r,t)=>{if(r instanceof N||r instanceof j||r instanceof L)return;(r instanceof C?[...t.context.params,r.ComponentClass]:t.context.params).forEach(i=>{Reflect.hasMetadata(s.BACKUP,i)&&V.add(i)})},"afterExecuteHooks"),w=a(r=>{V.size!==0&&(V.forEach(t=>{f.seal(t)}),u.updateTickHistory(),V.clear())},"afterTickHooks");var R=null;function _(r,t){r.onAfterTick(w,!0),r.onAfterExecute(F,I,!0),t&&O(t);let e=a(i=>(i&&Reflect.hasMetadata(s.VERSION,i.constructor)&&f.initComponent(i),i),"amberInitHook");r.addActivationHook(e),R=r}a(_,"activateApp");var g=new Proxy({},{get(r,t){return(...e)=>{if(!R)return P.warn(`[Virid Vue] App method "${String(t)}" called before initialization.`),null;let i=R[t];if(typeof i=="function")return i.apply(R,e)}}});function Ht(r){return t=>{Reflect.defineMetadata(s.BACKUP,!0,t),Reflect.defineMetadata(s.VERSION,0,t),r&&Reflect.defineMetadata(s.CUSTOM_METHOD,r,t)}}a(Ht,"Backup");var It={name:"@virid/amber",install(r,t){_(r,t)}};export{z as Amber,It as AmberPlugin,Ht as Backup,p as RestoreDirection,O as activateConfig,I as afterExecuteHooks,w as afterTickHooks,f as amberComponentStore,u as amberTickStore};
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/app.ts","../src/amber/store.ts","../src/decorators/constant.ts","../src/interfaces/decorator.ts","../src/amber/utils.ts","../src/amber/amber.ts","../src/amber/hooks.ts","../src/decorators/decorator.ts","../src/index.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { type ViridApp, MessageWriter, BaseMessage } from \"@virid/core\";\nimport {\n amberComponentStore,\n afterExecuteHooks,\n afterTickHooks,\n activateConfig,\n} from \"./amber\";\nimport type { PluginOptions } from \"./interfaces\";\nimport { VIRID_AMBER_METADATA } from \"./decorators/constant\";\nexport interface IViridApp {\n get(identifier: any): any;\n}\n\nlet activeApp: IViridApp | null = null;\n\nexport function activateApp(app: ViridApp, options: PluginOptions) {\n //注册钩子\n app.onAfterTick(afterTickHooks, true);\n app.onAfterExecute(BaseMessage, afterExecuteHooks, true);\n //看看用户提供的配置\n if (options) activateConfig(options);\n const amberInitHook = (instance) => {\n if (\n instance &&\n Reflect.hasMetadata(VIRID_AMBER_METADATA.VERSION, instance.constructor)\n ) {\n //实例化的时候,init第一个版本\n amberComponentStore.initComponent(instance);\n }\n return instance;\n };\n app.addActivationHook(amberInitHook);\n activeApp = app;\n}\n\n/**\n * viridApp 代理\n */\nexport const viridApp: IViridApp = new Proxy({} as IViridApp, {\n get(_, prop: keyof IViridApp) {\n return (...args: any[]) => {\n // 检查实例是否存在\n if (!activeApp) {\n MessageWriter.warn(\n `[Virid Vue] App method \"${String(prop)}\" called before initialization.`,\n );\n return null;\n }\n\n // 正常转发调用\n // 使用 Reflect 确保 this 指向正确,或者直接从 activeApp 调用\n const targetMethod = activeApp[prop];\n if (typeof targetMethod === \"function\") {\n // @ts-ignore\n return targetMethod.apply(activeApp, args);\n }\n };\n },\n});\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { MessageWriter } from \"@virid/core\";\nimport { viridApp } from \"../app\";\nimport { VIRID_AMBER_METADATA } from \"../decorators/constant\";\nimport { RestoreDirection, type PluginOptions } from \"../interfaces\";\nimport {\n type VersionMetadata,\n type CustomMethodMetadata,\n} from \"../interfaces\";\n\nimport { _serialization, _deserialization, _diff } from \"./utils\";\nlet config: Required<PluginOptions> = {\n serialization: _serialization,\n deserialization: _deserialization,\n diff: _diff, // 默认总是备份\n};\n\nexport function activateConfig(customConfig: PluginOptions) {\n config = Object.assign(config, customConfig);\n}\n\nclass AmberTickStore {\n // 快照镜像\n private tickHistory: Array<Map<any, any>> = [];\n\n // 记录数组第 0 位对应的真实 Tick 号\n public baseTick = 0;\n\n public maxTickLength = 20;\n // 当前处于哪个逻辑 Tick\n public currentTick = 0;\n\n constructor(maxTickLength: number = 20) {\n this.maxTickLength = maxTickLength;\n }\n /**\n * 获取最小可用Tick\n */\n public getMinTick(): number {\n return this.baseTick;\n }\n\n /**\n * 获取最大的Tick\n */\n public getMaxTick(): number {\n if (this.tickHistory.length === 0) return 0;\n return this.baseTick + this.tickHistory.length - 1;\n }\n /**\n * 记录当前的宏观快照\n */\n public updateTickHistory() {\n // 剪枝\n if (this.currentTick < this.baseTick + this.tickHistory.length) {\n // 剪掉后面的平行宇宙\n this.tickHistory.splice(this.currentTick - this.baseTick + 1);\n }\n\n // 增加加新快照\n const snapshot = new Map(amberComponentStore.currentHistory);\n this.tickHistory.push(snapshot);\n\n // 滑动窗口处理\n if (this.tickHistory.length > this.maxTickLength) {\n this.tickHistory.shift();\n this.baseTick++;\n }\n const newLogicalTick = this.baseTick + this.tickHistory.length - 1;\n // 更新指针到最新产生的这个 Tick\n this.currentTick = newLogicalTick;\n }\n\n /**\n * 全局时空旅行\n */\n public travel(targetTick: number) {\n // 计算物理索引\n const index = targetTick - this.baseTick;\n const historyMap = this.tickHistory[index];\n\n if (!historyMap) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Travel Error: Tick ${targetTick} is out of history range.`,\n ),\n );\n return;\n }\n\n const direction =\n targetTick < this.currentTick\n ? RestoreDirection.UNDO\n : RestoreDirection.REDO;\n\n // 准备一个队列,用于最后统一执行钩子\n const restoreQueue: Array<{\n strategy: any;\n oldData: any;\n newData: any;\n }> = [];\n // 遍历快照中的所有组件类\n for (const [compClass, historicalData] of historyMap) {\n const currentData = amberComponentStore.getCurrentData(compClass);\n // 只有数据不一致时才处理\n if (historicalData !== currentData) {\n const oldData = currentData;\n // 执行物理恢复\n amberComponentStore.deserializeComponent(compClass, historicalData);\n\n // 更新微观层的快照记录\n amberComponentStore.seal(compClass);\n\n // 收集钩子\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n if (customMethod?.onRestore) {\n restoreQueue.push({\n strategy: customMethod,\n oldData,\n newData: historicalData,\n });\n }\n }\n const instance = viridApp.get(compClass);\n }\n\n // 更新宏观时空指针\n this.currentTick = targetTick;\n\n // 统一派发副作用钩子\n restoreQueue.forEach(({ strategy, oldData, newData }) => {\n strategy.onRestore(oldData, newData, direction);\n });\n }\n /**\n * 重置宏观时间轴\n */\n public resetTickStore() {\n // 彻底清空旧的磁带\n this.tickHistory = [];\n this.baseTick = 0;\n this.currentTick = 0;\n\n // 立刻保存一份当前的“现状”作为新起点\n this.updateTickHistory();\n }\n}\n\nclass AmberComponentStore {\n public componentHistory = new Map<any, any[]>();\n // 记录每个组件消失的历史总数\n public biasVersions = new Map<any, number>();\n public maxComponentHistorySize = 20;\n // 记录当前每个组件都是什么版本\n public currentHistory = new Map<any, any>();\n // 记录每个组件消失的历史总数\n constructor(maxComponentHistorySize: number = 20) {\n this.maxComponentHistorySize = maxComponentHistorySize;\n }\n /**\n * 将component 的数据进行序列化\n */\n public serializeComponent(compClass: any) {\n const instance = viridApp.get(compClass);\n if (!instance) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Serialize Error: Component ${compClass.name} is not registered.`,\n ),\n );\n return null;\n }\n\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const serializeFn = customMethod?.serialize || config.serialization;\n try {\n return serializeFn(instance);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Serialize Error: Component ${compClass.name} serialization error`,\n );\n }\n return null;\n }\n /**\n * 将component 的数据反序列化\n */\n public deserializeComponent(compClass: any, data: any) {\n const instance = viridApp.get(compClass);\n if (!instance) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Deserialize Error: Component ${compClass.name} is not registered.`,\n ),\n );\n return;\n }\n if (!data) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Deserialize Error: Component ${compClass.name} data is ${data}!.`,\n ),\n );\n return;\n }\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const deserializeFn =\n customMethod?.deserialize || config.deserialization;\n try {\n deserializeFn(instance, data);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Deserialize Error: Component ${compClass.name} deserialize error`,\n );\n }\n return;\n }\n /**\n * 对比diff\n */\n public diffComponent(compClass: any, old_data: any): boolean {\n const instance = viridApp.get(compClass);\n if (!instance) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Diff Error: Component ${compClass.name} is not registered.`,\n ),\n );\n return false;\n }\n if (!old_data) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Diff Error: Component ${compClass.name} data is ${old_data}!.`,\n ),\n );\n return false;\n }\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const diffFn = customMethod?.diff || config.diff;\n try {\n return diffFn(instance, old_data);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Diff Error: Component ${compClass.name} diff error`,\n );\n }\n return false;\n }\n\n /**\n * 初始化组件的历史记录结构\n */\n public initComponent(instance: any) {\n const compClass = instance.constructor;\n const customMethod:CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n const serializeFn = customMethod?.serialize || config.serialization;\n let data;\n try {\n data = serializeFn(instance);\n } catch (e) {\n MessageWriter.error(\n e,\n `[Virid Amber] Serialize Error: Component ${compClass.name} serialization error`,\n );\n return;\n }\n this.componentHistory.set(compClass, []);\n this.biasVersions.set(compClass, 0);\n\n // 将初始数据推入\n this.componentHistory.get(compClass)!.push(data);\n this.currentHistory.set(compClass, data);\n\n // 初始版本设为 0\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, 0, compClass);\n }\n /**\n * 获取组件当前逻辑版本对应的快照数据\n */\n public getCurrentData(compClass: any): any {\n return this.currentHistory.get(compClass);\n }\n\n /**\n * 获取组件在当前滑动窗口内的最小可用版本\n */\n public getMinVersion(compClass: any): number {\n return this.biasVersions.get(compClass) ?? 0;\n }\n\n /**\n * 获取组件在当前物理栈内存在的最大版本(包括撤销后的“未来”)\n */\n public getMaxVersion(compClass: any): number {\n const stack = this.componentHistory.get(compClass);\n const bias = this.biasVersions.get(compClass) ?? 0;\n if (!stack || stack.length === 0) return bias;\n return bias + stack.length - 1;\n }\n\n /**\n * 给一个component 打快照\n * @param compClass 构造函数\n * @returns\n */\n public seal(compClass: any) {\n const stack = this.componentHistory.get(compClass);\n if (!stack) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Seal Error: Component ${compClass.name} is not initialized.`,\n ),\n );\n }\n const baseVersion = this.biasVersions.get(compClass);\n\n const currentSnapshot = this.getCurrentData(compClass);\n // diff判断\n if (currentSnapshot && !this.diffComponent(compClass, currentSnapshot)) {\n return;\n }\n\n const customMethod: CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n if (customMethod?.onBeforeBackup) {\n customMethod.onBeforeBackup(currentSnapshot);\n }\n\n // 剪枝\n const currentLogicalVersion:VersionMetadata =\n Reflect.getMetadata(VIRID_AMBER_METADATA.VERSION, compClass) || 0;\n const latestLogicalVersion = baseVersion + stack.length - 1;\n if (currentLogicalVersion < latestLogicalVersion) {\n stack.splice(currentLogicalVersion - baseVersion + 1);\n }\n\n // 序列化\n const newData = this.serializeComponent(compClass);\n if (!newData) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Seal Error: Component ${compClass.name} is not serializable.`,\n ),\n );\n return;\n }\n stack.push(newData);\n this.currentHistory.set(compClass, newData);\n // 滑动窗口与元数据更新\n if (stack.length > this.maxComponentHistorySize) {\n stack.shift();\n this.biasVersions.set(compClass, baseVersion + 1);\n }\n\n const newLogicalVersion =\n this.biasVersions.get(compClass)! + stack.length - 1;\n Reflect.defineMetadata(\n VIRID_AMBER_METADATA.VERSION,\n newLogicalVersion,\n compClass,\n );\n if (customMethod?.onAfterBackup) {\n customMethod.onAfterBackup(newData);\n }\n }\n /**\n * 回退到指定版本\n * @param compClass component构造函数\n * @param targetVersion 目标版本\n * @returns\n */\n public seek(compClass: any, targetVersion: number): boolean {\n // 边界检查\n const stack = this.componentHistory.get(compClass);\n if (!stack) {\n MessageWriter.error(\n new Error(\n `[Virid Amber] Seal Error: Component ${compClass.name} is not initialized.`,\n ),\n );\n return false;\n }\n const baseVersion = this.biasVersions.get(compClass) || 0;\n\n const physicalIndex = targetVersion - baseVersion;\n if (physicalIndex < 0 || physicalIndex >= stack.length) return false;\n\n // 状态对比准备\n const oldData = this.getCurrentData(compClass);\n const newData = stack[physicalIndex];\n const currentVersion:VersionMetadata =\n Reflect.getMetadata(VIRID_AMBER_METADATA.VERSION, compClass) || 0;\n\n const direction =\n targetVersion < currentVersion\n ? RestoreDirection.UNDO\n : RestoreDirection.REDO;\n\n // 执行反序列化\n this.deserializeComponent(compClass, newData);\n\n // 时空指针同步\n this.currentHistory.set(compClass, newData);\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, targetVersion, compClass);\n\n // 触发业务钩子\n const customMethod: CustomMethodMetadata = Reflect.getMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n compClass,\n );\n if (customMethod?.onRestore) {\n customMethod.onRestore(oldData, newData, direction);\n }\n\n // 告诉时间轴,有个零件变了\n amberTickStore.updateTickHistory();\n return true;\n }\n /**\n * 重置逻辑\n */\n public resetComponentInternal(compClass: any) {\n const newData = this.serializeComponent(compClass);\n if (!newData) return;\n\n // 物理清理\n this.componentHistory.set(compClass, [newData]);\n this.biasVersions.set(compClass, 0);\n this.currentHistory.set(compClass, newData);\n\n // 元数据归零\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, 0, compClass);\n }\n\n public resetComponent(compClass: any) {\n this.resetComponentInternal(compClass);\n // 只有局部重置时,才主动触发宏观记录\n amberTickStore.updateTickHistory();\n }\n}\n\nexport const amberTickStore = new AmberTickStore();\nexport const amberComponentStore = new AmberComponentStore();\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { VIRID_METADATA } from \"@virid/core\";\nexport const VIRID_AMBER_METADATA = {\n ...VIRID_METADATA,\n BACKUP: \"virid:amber:backup\",\n VERSION: \"virid:amber:version\",\n CUSTOM_METHOD: \"virid:amber:custom-method\",\n} as const;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nexport enum RestoreDirection {\n UNDO = \"UNDO\",\n REDO = \"REDO\",\n}\n\nexport interface BackupStrategy<T = any, C = any> {\n /**\n * 自定义序列化:将实例转换为可存储的对象\n */\n serialize?: (instance: T) => C;\n\n /**\n * 自定义反序列化:将数据灌回实例\n */\n deserialize?: (instance: T, data: C) => void;\n\n /**\n * 自定义 Diff:返回 true 表示有变化,需要触发备份\n */\n diff?: (oldData: C, instance: T) => boolean;\n onBeforeBackup?: (oldData: C) => void;\n onAfterBackup?: (newData: C) => void;\n onRestore?: (oldData: C, newData: C, direction: RestoreDirection) => void;\n}\n\nexport type VersionMetadata = number;\nexport type BackupMetadata = boolean;\nexport type CustomMethodMetadata = BackupStrategy;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\n/**\n * 默认 serialization\n */\nexport function _serialization(instance: any, depth = 5): any {\n if (instance === null || typeof instance !== \"object\") return instance;\n if (depth <= 0) return Array.isArray(instance) ? [] : {};\n\n if (Array.isArray(instance)) {\n return instance.map((item) => _serialization(item, depth - 1));\n }\n\n const snapshot: any = {};\n const keys = Object.keys(instance);\n\n for (const key of keys) {\n if (key.startsWith(\"_\")) continue;\n\n const value = instance[key];\n if (typeof value === \"function\") continue;\n\n snapshot[key] =\n typeof value === \"object\" && value !== null\n ? _serialization(value, depth - 1)\n : value;\n }\n return snapshot;\n}\n/**\n * 默认 deserialization\n */\nexport function _deserialization(instance: any, snapshot: any) {\n if (!instance || !snapshot) return;\n\n Object.keys(snapshot).forEach((key) => {\n const newVal = snapshot[key];\n const oldVal = instance[key];\n // 继续递归,而不是直接覆盖对象引用\n if (\n oldVal &&\n typeof oldVal === \"object\" &&\n newVal &&\n typeof newVal === \"object\" &&\n !Array.isArray(newVal)\n ) {\n _deserialization(oldVal, newVal);\n } else {\n // 直接赋值\n instance[key] = newVal;\n }\n });\n}\n/**\n * 默认 Diff\n */\nexport function _diff(oldData: any, instance: any, depth = 3): boolean {\n // 基础类型或引用相同,直接认为没变\n if (oldData === instance) return false;\n\n // 类型不一致,肯定变了\n if (\n typeof oldData !== typeof instance ||\n oldData === null ||\n instance === null\n ) {\n return true;\n }\n // 处理数组\n if (Array.isArray(oldData)) {\n if (!Array.isArray(instance) || oldData.length !== instance.length)\n return true;\n for (let i = 0; i < oldData.length; i++) {\n if (_diff(oldData[i], instance[i], depth - 1)) return true;\n }\n return false;\n }\n\n // 处理对象\n const keys = Object.keys(oldData);\n\n for (const key of keys) {\n const valOld = oldData[key];\n const valNew = instance[key];\n\n if (typeof valOld === \"object\" && valOld !== null) {\n // 达到最大深度限制,不再递归,保守起见认为变了\n if (depth <= 0) continue;\n\n if (_diff(valOld, valNew, depth - 1)) return true;\n } else {\n // 基础类型对比\n if (valOld !== valNew) return true;\n }\n }\n return false;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { amberComponentStore, amberTickStore } from \"./store\";\nimport { VIRID_AMBER_METADATA } from \"../decorators/constant\";\n\nexport class Amber {\n /**\n * 获取组件当前的逻辑版本号\n */\n public static getVersion(compClass: any): number {\n return Reflect.getMetadata(VIRID_AMBER_METADATA.VERSION, compClass) || 0;\n }\n\n public static canUndo(compClass: any): boolean {\n const current = this.getVersion(compClass);\n const min = amberComponentStore.getMinVersion(compClass);\n\n return current > min;\n }\n\n public static canRedo(compClass: any): boolean {\n const current = this.getVersion(compClass);\n const max = amberComponentStore.getMaxVersion(compClass);\n\n return current < max;\n }\n\n /**\n * 局部撤销:将单个组件回退一个版本\n * 结果:产生新 Tick,代表“我回到了过去”\n */\n public static undo(compClass: any): boolean {\n if (!this.canUndo(compClass)) return false;\n const current = this.getVersion(compClass);\n const result = amberComponentStore.seek(compClass, current - 1);\n\n return result;\n }\n\n /**\n * 局部重做:将单个组件向前进一个版本\n */\n public static redo(compClass: any): boolean {\n if (!this.canRedo(compClass)) return false;\n const current = this.getVersion(compClass);\n const result = amberComponentStore.seek(compClass, current + 1);\n\n return result;\n }\n /**\n * 全局撤销\n */\n public static undoTick(): boolean {\n if (!this.canUndoTick()) return false;\n const targetTick = amberTickStore.currentTick - 1;\n amberTickStore.travel(targetTick);\n return true;\n }\n\n /**\n * 全局重做\n */\n public static redoTick(): boolean {\n if (!this.canRedoTick()) return false;\n const targetTick = amberTickStore.currentTick + 1;\n amberTickStore.travel(targetTick);\n return true;\n }\n\n /**\n * UI 状态判断:是否还能点撤销\n */\n public static canUndoTick(): boolean {\n const currentTick = amberTickStore.currentTick;\n const minTick = amberTickStore.getMinTick();\n\n return currentTick > minTick;\n }\n\n /**\n * UI 状态判断:是否还能点重做\n */\n public static canRedoTick(): boolean {\n const currentTick = amberTickStore.currentTick;\n const maxTick = amberTickStore.getMaxTick();\n\n return currentTick < maxTick;\n }\n\n /**\n * 重置宏观时间轴\n * 清空所有全局快照,用户无法再进行 undoTick/redoTick,\n * 但各个组件当前的微观版本栈保持不变。\n */\n public static resetTick(): void {\n amberTickStore.resetTickStore();\n }\n\n /**\n * 重置特定组件的历史\n * 该组件的旧版本被物理抹除,当前状态变为 V0。\n * 会自动触发一次 updateTickHistory,记录这一时刻的全局状态。\n */\n public static resetComponent(compClass: any): void {\n amberComponentStore.resetComponent(compClass);\n }\n // 建议添加到 Amber 类中\n public static resetAll(): void {\n // 获取所有存活组件\n const classes = Array.from(amberComponentStore.componentHistory.keys());\n // 清空每个组件(静默重置,不触发 updateTickHistory)\n classes.forEach((compClass) => {\n // 我们可以给 resetComponent 加个参数,或者拆分出一个内部方法\n amberComponentStore.resetComponentInternal(compClass);\n });\n // 重置宏观磁带\n amberTickStore.resetTickStore();\n }\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport {\n type ExecuteHook,\n type TickHook,\n AtomicModifyMessage,\n BaseMessage,\n ErrorMessage,\n WarnMessage,\n InfoMessage,\n} from \"@virid/core\";\nimport { amberComponentStore, amberTickStore } from \"./store\";\nimport { VIRID_AMBER_METADATA } from \"../decorators/constant\";\n\nconst dirtyBuffer = new Set<any>();\n\nexport const afterExecuteHooks: ExecuteHook<BaseMessage> = (\n message,\n context,\n) => {\n if (\n message instanceof ErrorMessage ||\n message instanceof WarnMessage ||\n message instanceof InfoMessage\n )\n return;\n\n const allParams =\n message instanceof AtomicModifyMessage\n ? [...context.context.params, message.ComponentClass]\n : context.context.params;\n\n allParams.forEach((paramClass) => {\n if (Reflect.hasMetadata(VIRID_AMBER_METADATA.BACKUP, paramClass)) {\n dirtyBuffer.add(paramClass);\n }\n });\n};\n\nexport const afterTickHooks: TickHook = (_context) => {\n if (dirtyBuffer.size === 0) return;\n\n // 微观更新\n dirtyBuffer.forEach((compClass) => {\n amberComponentStore.seal(compClass);\n });\n\n // 宏观更新\n amberTickStore.updateTickHistory();\n\n // 清理缓存,准备下一轮\n dirtyBuffer.clear();\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Amber\n */\nimport { VIRID_AMBER_METADATA } from \"./constant\";\nimport { type BackupStrategy } from \"../interfaces\";\n\n/**\n * @description: 标记 Backup 身份并配置自定义备份策略\n * @param strategy 可选的自定义序列化/反序列化/Diff 方案\n */\nexport function Backup<T extends new (...args: any[]) => any, C = any>(\n strategy?: BackupStrategy<InstanceType<T>, C>,\n) {\n return (target: T) => {\n // 标记需要备份\n Reflect.defineMetadata(VIRID_AMBER_METADATA.BACKUP, true, target);\n // 初始化版本号\n Reflect.defineMetadata(VIRID_AMBER_METADATA.VERSION, 0, target);\n // 如果用户给了自定义方法,存入元数据\n if (strategy) {\n Reflect.defineMetadata(\n VIRID_AMBER_METADATA.CUSTOM_METHOD,\n strategy,\n target,\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: Add replay, redo, undo and other functions to virid.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nimport { activateApp } from \"./app\";\nimport { PluginOptions } from \"./interfaces\";\nexport * from \"./amber\";\nexport * from \"./decorators\";\nexport * from \"./interfaces\";\nexport const AmberPlugin: ViridPlugin<PluginOptions> = {\n name: \"@virid/amber\",\n install(app: ViridApp, options) {\n activateApp(app, options);\n },\n};\n"],"mappings":";;;;uNAKA,OAAwBA,iBAAAA,EAAeC,eAAAA,MAAmB,cCA1D,OAASC,iBAAAA,MAAqB,cCA9B,OAASC,kBAAAA,MAAsB,cACxB,IAAMC,EAAuB,CAClC,GAAGD,EACHE,OAAQ,qBACRC,QAAS,sBACTC,cAAe,2BACjB,ECNO,IAAKC,GAAAA,SAAAA,EAAAA,oCAAAA,QCGL,SAASC,EAAeC,EAAeC,EAAQ,EAAC,CACrD,GAAID,IAAa,MAAQ,OAAOA,GAAa,SAAU,OAAOA,EAC9D,GAAIC,GAAS,EAAG,OAAOC,MAAMC,QAAQH,CAAAA,EAAY,CAAA,EAAK,CAAC,EAEvD,GAAIE,MAAMC,QAAQH,CAAAA,EAChB,OAAOA,E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,2BAA2BC,OAAOJ,CAAAA,CAAAA,iCAAsC,EAEnE,KAKT,IAAMK,EAAe7B,EAAUwB,CAAAA,EAC/B,GAAI,OAAOK,GAAiB,WAE1B,OAAOA,EAAaC,MAAM9B,EAAWyB,CAAAA,CAEzC,CACF,CACF,CAAA,EOnDO,SAASM,GACdC,EAA6C,CAE7C,OAAQC,GAAAA,CAENC,QAAQC,eAAeC,EAAqBC,OAAQ,GAAMJ,CAAAA,EAE1DC,QAAQC,eAAeC,EAAqBE,QAAS,EAAGL,CAAAA,EAEpDD,GACFE,QAAQC,eACNC,EAAqBG,cACrBP,EACAC,CAAAA,CAGN,CACF,CAjBgBF,EAAAA,GAAAA,UCWT,IAAMS,GAA0C,CACrDC,KAAM,eACNC,QAAQC,EAAeC,EAAO,CAC5BC,EAAYF,EAAKC,CAAAA,CACnB,CACF","names":["MessageWriter","BaseMessage","MessageWriter","VIRID_METADATA","VIRID_AMBER_METADATA","BACKUP","VERSION","CUSTOM_METHOD","RestoreDirection","_serialization","instance","depth","Array","isArray","map","item","snapshot","keys","Object","key","startsWith","value","_deserialization","forEach","newVal","oldVal","_diff","oldData","length","i","valOld","valNew","config","serialization","_serialization","deserialization","_deserialization","diff","_diff","activateConfig","customConfig","Object","assign","_a","AmberTickStore","maxTickLength","tickHistory","baseTick","currentTick","getMinTick","getMaxTick","length","updateTickHistory","splice","snapshot","Map","amberComponentStore","currentHistory","push","shift","newLogicalTick","travel","targetTick","index","historyMap","MessageWriter","error","Error","direction","RestoreDirection","UNDO","REDO","restoreQueue","compClass","historicalData","currentData","getCurrentData","oldData","deserializeComponent","seal","customMethod","Reflect","getMetadata","VIRID_AMBER_METADATA","CUSTOM_METHOD","onRestore","strategy","newData","instance","viridApp","get","forEach","resetTickStore","AmberComponentStore","maxComponentHistorySize","componentHistory","biasVersions","serializeComponent","name","serializeFn","serialize","e","data","deserializeFn","deserialize","diffComponent","old_data","diffFn","initComponent","set","defineMetadata","VERSION","getMinVersion","getMaxVersion","stack","bias","baseVersion","currentSnapshot","onBeforeBackup","currentLogicalVersion","latestLogicalVersion","newLogicalVersion","onAfterBackup","seek","targetVersion","physicalIndex","currentVersion","amberTickStore","resetComponentInternal","resetComponent","Amber","getVersion","compClass","Reflect","getMetadata","VIRID_AMBER_METADATA","VERSION","canUndo","current","min","amberComponentStore","getMinVersion","canRedo","max","getMaxVersion","undo","seek","redo","undoTick","canUndoTick","targetTick","amberTickStore","currentTick","travel","redoTick","canRedoTick","minTick","getMinTick","maxTick","getMaxTick","resetTick","resetTickStore","resetComponent","resetAll","Array","from","componentHistory","keys","forEach","resetComponentInternal","_Amber","AtomicModifyMessage","ErrorMessage","WarnMessage","InfoMessage","dirtyBuffer","Set","afterExecuteHooks","__name","message","context","ErrorMessage","WarnMessage","InfoMessage","AtomicModifyMessage","params","ComponentClass","forEach","paramClass","Reflect","hasMetadata","VIRID_AMBER_METADATA","BACKUP","add","afterTickHooks","_context","size","compClass","amberComponentStore","seal","amberTickStore","updateTickHistory","clear","activeApp","activateApp","app","options","onAfterTick","afterTickHooks","onAfterExecute","BaseMessage","afterExecuteHooks","activateConfig","amberInitHook","__name","instance","Reflect","hasMetadata","VIRID_AMBER_METADATA","VERSION","amberComponentStore","initComponent","addActivationHook","viridApp","Proxy","get","_","prop","args","MessageWriter","warn","String","targetMethod","apply","Backup","strategy","target","Reflect","defineMetadata","VIRID_AMBER_METADATA","BACKUP","VERSION","CUSTOM_METHOD","AmberPlugin","name","install","app","options","activateApp"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@virid/amber",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Add replay, redo, undo and other functions to virid",
|
|
6
|
+
"author": "Ailrid",
|
|
7
|
+
"license": "Apache 2.0",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"replay",
|
|
10
|
+
"redo",
|
|
11
|
+
"undo",
|
|
12
|
+
"message"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/ArisuYuki/virid.git"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@virid/core": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup --config tsup.config.ts",
|
|
41
|
+
"example": "node --import @swc-node/register/esm-register examples/index.ts"
|
|
42
|
+
}
|
|
43
|
+
}
|