@virid/vue 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +248 -220
- package/README.zh.md +236 -211
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +109 -0
- package/dist/index.d.ts +69 -23
- package/dist/index.js +14 -559
- package/dist/index.js.map +1 -0
- package/package.json +29 -20
- package/dist/index.d.mts +0 -63
- package/dist/index.mjs +0 -525
package/dist/index.js
CHANGED
|
@@ -1,559 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
ControllerMessage: () => ControllerMessage,
|
|
24
|
-
Env: () => Env,
|
|
25
|
-
Inherit: () => Inherit,
|
|
26
|
-
Listener: () => Listener,
|
|
27
|
-
OnHook: () => OnHook,
|
|
28
|
-
Project: () => Project,
|
|
29
|
-
Responsive: () => Responsive,
|
|
30
|
-
Use: () => Use,
|
|
31
|
-
VuePlugin: () => VuePlugin,
|
|
32
|
-
Watch: () => Watch,
|
|
33
|
-
useController: () => useController
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
|
|
37
|
-
// decorators/constants.ts
|
|
38
|
-
var virid_METADATA = {
|
|
39
|
-
COMPONENT: "virid:component",
|
|
40
|
-
CONTROLLER: "virid:controller",
|
|
41
|
-
PROJECT: "virid:project_metadata",
|
|
42
|
-
WATCH: "virid:watch_metadata",
|
|
43
|
-
MESSAGE: "virid:message",
|
|
44
|
-
RESPONSIVE: "virid:responsive",
|
|
45
|
-
LIFE_CRICLE: "virid:life_cricle",
|
|
46
|
-
USE_HOOKS: "virid:use_hooks",
|
|
47
|
-
CONTROLLER_LISTENERS: "virid:controller_listeners",
|
|
48
|
-
INHERIT: "virid:inherit",
|
|
49
|
-
ATTR: "virid:attr"
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// decorators/vue.ts
|
|
53
|
-
function Watch(arg1, arg2, arg3) {
|
|
54
|
-
return (target, methodName) => {
|
|
55
|
-
const existing = Reflect.getMetadata(virid_METADATA.WATCH, target) || [];
|
|
56
|
-
if (typeof arg2 === "function") {
|
|
57
|
-
existing.push({
|
|
58
|
-
type: "component",
|
|
59
|
-
componentClass: arg1,
|
|
60
|
-
source: arg2,
|
|
61
|
-
options: arg3,
|
|
62
|
-
methodName
|
|
63
|
-
});
|
|
64
|
-
} else {
|
|
65
|
-
existing.push({
|
|
66
|
-
type: "local",
|
|
67
|
-
source: arg1,
|
|
68
|
-
options: arg2,
|
|
69
|
-
methodName
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
Reflect.defineMetadata(virid_METADATA.WATCH, existing, target);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
__name(Watch, "Watch");
|
|
76
|
-
function Project(arg1, arg2) {
|
|
77
|
-
return (target, propertyKey, descriptor) => {
|
|
78
|
-
const existing = Reflect.getMetadata(virid_METADATA.PROJECT, target) || [];
|
|
79
|
-
const metadata = {
|
|
80
|
-
propertyKey,
|
|
81
|
-
isAccessor: !!(descriptor?.get || descriptor?.set),
|
|
82
|
-
// 这里的逻辑和 Watch 保持高度一致
|
|
83
|
-
type: typeof arg2 === "function" ? "component" : "local",
|
|
84
|
-
componentClass: typeof arg2 === "function" ? arg1 : null,
|
|
85
|
-
source: typeof arg2 === "function" ? arg2 : arg1
|
|
86
|
-
};
|
|
87
|
-
existing.push(metadata);
|
|
88
|
-
Reflect.defineMetadata(virid_METADATA.PROJECT, existing, target);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
__name(Project, "Project");
|
|
92
|
-
function Responsive(shallow = false) {
|
|
93
|
-
return (target, propertyKey) => {
|
|
94
|
-
const props = Reflect.getMetadata(virid_METADATA.RESPONSIVE, target) || [];
|
|
95
|
-
props.push({
|
|
96
|
-
propertyKey,
|
|
97
|
-
shallow
|
|
98
|
-
});
|
|
99
|
-
Reflect.defineMetadata(virid_METADATA.RESPONSIVE, props, target);
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
__name(Responsive, "Responsive");
|
|
103
|
-
function OnHook(hookName) {
|
|
104
|
-
return (target, methodName) => {
|
|
105
|
-
const existing = Reflect.getMetadata(virid_METADATA.LIFE_CRICLE, target) || [];
|
|
106
|
-
existing.push({
|
|
107
|
-
hookName,
|
|
108
|
-
methodName
|
|
109
|
-
});
|
|
110
|
-
Reflect.defineMetadata(virid_METADATA.LIFE_CRICLE, existing, target);
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
__name(OnHook, "OnHook");
|
|
114
|
-
function Use(hookFactory) {
|
|
115
|
-
return (target, propertyKey) => {
|
|
116
|
-
const existing = Reflect.getMetadata(virid_METADATA.USE_HOOKS, target) || [];
|
|
117
|
-
existing.push({
|
|
118
|
-
propertyKey,
|
|
119
|
-
hookFactory
|
|
120
|
-
});
|
|
121
|
-
Reflect.defineMetadata(virid_METADATA.USE_HOOKS, existing, target);
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
__name(Use, "Use");
|
|
125
|
-
function Inherit(token, id, selector) {
|
|
126
|
-
return (target, propertyKey) => {
|
|
127
|
-
const metadata = Reflect.getMetadata(virid_METADATA.INHERIT, target) || [];
|
|
128
|
-
metadata.push({
|
|
129
|
-
propertyKey,
|
|
130
|
-
token,
|
|
131
|
-
id,
|
|
132
|
-
selector
|
|
133
|
-
});
|
|
134
|
-
Reflect.defineMetadata(virid_METADATA.INHERIT, metadata, target);
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
__name(Inherit, "Inherit");
|
|
138
|
-
function Env() {
|
|
139
|
-
return (_target, _propertyKey) => {
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
__name(Env, "Env");
|
|
143
|
-
function Listener(eventClass, priority = 0, single = true) {
|
|
144
|
-
return (target, propertyKey) => {
|
|
145
|
-
const listeners = Reflect.getMetadata(virid_METADATA.CONTROLLER_LISTENERS, target) || [];
|
|
146
|
-
listeners.push({
|
|
147
|
-
propertyKey,
|
|
148
|
-
eventClass,
|
|
149
|
-
priority,
|
|
150
|
-
single
|
|
151
|
-
});
|
|
152
|
-
Reflect.defineMetadata(virid_METADATA.CONTROLLER_LISTENERS, listeners, target);
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
__name(Listener, "Listener");
|
|
156
|
-
|
|
157
|
-
// decorators/types.ts
|
|
158
|
-
var import_core = require("@virid/core");
|
|
159
|
-
var ControllerMessage = class extends import_core.SingleMessage {
|
|
160
|
-
static {
|
|
161
|
-
__name(this, "ControllerMessage");
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// adapters/bind.ts
|
|
166
|
-
var import_vue = require("vue");
|
|
167
|
-
var import_core2 = require("@virid/core");
|
|
168
|
-
|
|
169
|
-
// app.ts
|
|
170
|
-
var activeApp = null;
|
|
171
|
-
function activateApp(instance) {
|
|
172
|
-
activeApp = instance;
|
|
173
|
-
}
|
|
174
|
-
__name(activateApp, "activateApp");
|
|
175
|
-
var viridApp = new Proxy({}, {
|
|
176
|
-
get(_, prop) {
|
|
177
|
-
return (...args) => {
|
|
178
|
-
if (!activeApp) {
|
|
179
|
-
console.warn(`[Virid Vue] App method "${String(prop)}" called before initialization.`);
|
|
180
|
-
if (prop === "register") {
|
|
181
|
-
return () => {
|
|
182
|
-
console.warn("[Virid Vue] Cleanup ignored: source listener was never registered.");
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
return void 0;
|
|
186
|
-
}
|
|
187
|
-
const targetMethod = activeApp[prop];
|
|
188
|
-
if (typeof targetMethod === "function") {
|
|
189
|
-
return targetMethod.apply(activeApp, args);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// adapters/bind.ts
|
|
196
|
-
var GlobalRegistry = class {
|
|
197
|
-
static {
|
|
198
|
-
__name(this, "GlobalRegistry");
|
|
199
|
-
}
|
|
200
|
-
static globalRegistry = (0, import_vue.shallowReactive)(/* @__PURE__ */ new Map());
|
|
201
|
-
static set(id, instance) {
|
|
202
|
-
if (!this.globalRegistry.has(id)) {
|
|
203
|
-
this.globalRegistry.set(id, instance);
|
|
204
|
-
return () => {
|
|
205
|
-
this.globalRegistry.delete(id);
|
|
206
|
-
return true;
|
|
207
|
-
};
|
|
208
|
-
} else {
|
|
209
|
-
import_core2.MessageWriter.error(new Error(`[Virid UseController] Duplicate ID: Controller ${id} already exists`));
|
|
210
|
-
return () => false;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
static get(id) {
|
|
214
|
-
if (!this.globalRegistry.has(id)) {
|
|
215
|
-
import_core2.MessageWriter.error(new Error(`[Virid UseController] ID Not Found: No Controller found with ID: ${id}`));
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
return this.globalRegistry.get(id);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
function bindProject(proto, instance, rawDeps) {
|
|
222
|
-
const projects = Reflect.getMetadata(virid_METADATA.PROJECT, proto);
|
|
223
|
-
projects?.forEach((config) => {
|
|
224
|
-
const { propertyKey, isAccessor, type, componentClass, source } = config;
|
|
225
|
-
let c;
|
|
226
|
-
let setter = /* @__PURE__ */ __name(() => {
|
|
227
|
-
import_core2.MessageWriter.error(new Error(`[Virid Shield] Property "${propertyKey}" is read-only.
|
|
228
|
-
If you need to mutate, define an explicit setter and ensure the dependency is injected.`));
|
|
229
|
-
}, "setter");
|
|
230
|
-
const getTarget = /* @__PURE__ */ __name(() => {
|
|
231
|
-
const target = type === "component" ? viridApp.get(componentClass) : instance;
|
|
232
|
-
if (target && !target.__ccs_processed__) {
|
|
233
|
-
bindResponsive(target);
|
|
234
|
-
}
|
|
235
|
-
return target;
|
|
236
|
-
}, "getTarget");
|
|
237
|
-
if (isAccessor) {
|
|
238
|
-
const rawDescriptor = Object.getOwnPropertyDescriptor(proto, propertyKey);
|
|
239
|
-
if (rawDescriptor?.set) {
|
|
240
|
-
import_core2.MessageWriter.warn(`[Virid Project] Possible Implicit Modification:
|
|
241
|
-
Manual Set on "${propertyKey}".If this is not intentional, please do not use set.`);
|
|
242
|
-
setter = /* @__PURE__ */ __name((val) => {
|
|
243
|
-
const elevatedContext = new Proxy(instance, {
|
|
244
|
-
get(target, key) {
|
|
245
|
-
if (typeof key === "string" && rawDeps[key]) {
|
|
246
|
-
return rawDeps[key];
|
|
247
|
-
}
|
|
248
|
-
return Reflect.get(target, key);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
rawDescriptor?.set?.call(elevatedContext, val);
|
|
252
|
-
}, "setter");
|
|
253
|
-
}
|
|
254
|
-
c = (0, import_vue.computed)({
|
|
255
|
-
get: /* @__PURE__ */ __name(() => {
|
|
256
|
-
return rawDescriptor?.get?.call(instance);
|
|
257
|
-
}, "get"),
|
|
258
|
-
set: setter
|
|
259
|
-
});
|
|
260
|
-
} else {
|
|
261
|
-
c = (0, import_vue.computed)(() => {
|
|
262
|
-
const target = getTarget();
|
|
263
|
-
return source(target);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
const currentDescriptor = Object.getOwnPropertyDescriptor(instance, propertyKey);
|
|
267
|
-
if (currentDescriptor && currentDescriptor.configurable === false) return;
|
|
268
|
-
Object.defineProperty(instance, propertyKey, {
|
|
269
|
-
get: /* @__PURE__ */ __name(() => c.value, "get"),
|
|
270
|
-
set: /* @__PURE__ */ __name((val) => c.value = val, "set"),
|
|
271
|
-
enumerable: true,
|
|
272
|
-
configurable: true
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
__name(bindProject, "bindProject");
|
|
277
|
-
function bindWatch(proto, instance) {
|
|
278
|
-
const watches = Reflect.getMetadata(virid_METADATA.WATCH, proto) || [];
|
|
279
|
-
const stops = [];
|
|
280
|
-
watches.forEach((config) => {
|
|
281
|
-
const { type, source, methodName, options, componentClass } = config;
|
|
282
|
-
const target = type === "component" ? viridApp.get(componentClass) : instance;
|
|
283
|
-
if (target && !target.__ccs_processed__) {
|
|
284
|
-
bindResponsive(target);
|
|
285
|
-
}
|
|
286
|
-
const getter = /* @__PURE__ */ __name(() => {
|
|
287
|
-
try {
|
|
288
|
-
return source(target);
|
|
289
|
-
} catch (e) {
|
|
290
|
-
import_core2.MessageWriter.error(e, `[Virid Watch] Getter error in ${methodName}`);
|
|
291
|
-
return void 0;
|
|
292
|
-
}
|
|
293
|
-
}, "getter");
|
|
294
|
-
const callback = instance[methodName].bind(instance);
|
|
295
|
-
const stop = (0, import_vue.watch)(getter, (newVal, oldVal) => {
|
|
296
|
-
callback(newVal, oldVal);
|
|
297
|
-
}, {
|
|
298
|
-
...options
|
|
299
|
-
});
|
|
300
|
-
stops.push(stop);
|
|
301
|
-
});
|
|
302
|
-
return stops;
|
|
303
|
-
}
|
|
304
|
-
__name(bindWatch, "bindWatch");
|
|
305
|
-
function bindResponsive(instance) {
|
|
306
|
-
if (!instance || typeof instance !== "object") return;
|
|
307
|
-
if (Object.prototype.hasOwnProperty.call(instance, "__ccs_processed__")) return;
|
|
308
|
-
Object.defineProperty(instance, "__ccs_processed__", {
|
|
309
|
-
value: true,
|
|
310
|
-
enumerable: false
|
|
311
|
-
});
|
|
312
|
-
const props = Reflect.getMetadata(virid_METADATA.RESPONSIVE, instance) || [];
|
|
313
|
-
props.forEach((config) => {
|
|
314
|
-
const key = config.propertyKey;
|
|
315
|
-
const rawValue = instance[key];
|
|
316
|
-
const descriptor = Object.getOwnPropertyDescriptor(instance, key);
|
|
317
|
-
if (descriptor && descriptor.get) return;
|
|
318
|
-
const internalState = config.shallow ? (0, import_vue.shallowRef)(rawValue) : (0, import_vue.ref)(rawValue);
|
|
319
|
-
Object.defineProperty(instance, key, {
|
|
320
|
-
get: /* @__PURE__ */ __name(() => internalState.value, "get"),
|
|
321
|
-
set: /* @__PURE__ */ __name((val) => {
|
|
322
|
-
internalState.value = val;
|
|
323
|
-
}, "set"),
|
|
324
|
-
enumerable: true,
|
|
325
|
-
configurable: true
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
Reflect.ownKeys(instance).forEach((key) => {
|
|
329
|
-
if (key === "__ccs_processed__") return;
|
|
330
|
-
const val = instance[key];
|
|
331
|
-
if (val && typeof val === "object" && !(0, import_vue.isRef)(val)) {
|
|
332
|
-
bindResponsive(val);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
__name(bindResponsive, "bindResponsive");
|
|
337
|
-
function createDeepShield(target, rootName, path = "") {
|
|
338
|
-
if (target === null || typeof target !== "object") {
|
|
339
|
-
return target;
|
|
340
|
-
}
|
|
341
|
-
if (target.__ccs_shield__) return target;
|
|
342
|
-
return new Proxy(target, {
|
|
343
|
-
get(obj, prop) {
|
|
344
|
-
if (prop === "__ccs_shield__") return true;
|
|
345
|
-
if (prop === "__raw__") return obj;
|
|
346
|
-
const value = Reflect.get(obj, prop);
|
|
347
|
-
const currentPath = path ? `${path}.${String(prop)}` : String(prop);
|
|
348
|
-
return createDeepShield(value, rootName, currentPath);
|
|
349
|
-
},
|
|
350
|
-
set(_obj, prop) {
|
|
351
|
-
const currentPath = path ? `${path}.${String(prop)}` : String(prop);
|
|
352
|
-
const errorMsg = [
|
|
353
|
-
`[Virid DeepShield]`,
|
|
354
|
-
`------------------------------------------------`,
|
|
355
|
-
`Component: ${rootName}`,
|
|
356
|
-
`Code: this.${rootName}.${currentPath}`,
|
|
357
|
-
`Result: Rejected`,
|
|
358
|
-
`Repair suggestion: Please use @ Project (${currentPath}) to create a projection in the Controller.`,
|
|
359
|
-
`------------------------------------------------`
|
|
360
|
-
].join("\n");
|
|
361
|
-
import_core2.MessageWriter.error(new Error(errorMsg));
|
|
362
|
-
return false;
|
|
363
|
-
},
|
|
364
|
-
deleteProperty(_obj, prop) {
|
|
365
|
-
import_core2.MessageWriter.error(new Error(`[Virid DeepShield] Physical Protection:
|
|
366
|
-
Prohibit Deletion of Component Attributes ${String(prop)}`));
|
|
367
|
-
return false;
|
|
368
|
-
},
|
|
369
|
-
// 拦截 Object.defineProperty 等底层操作
|
|
370
|
-
defineProperty() {
|
|
371
|
-
import_core2.MessageWriter.error(new Error(`[Virid DeepShield] Physical Protection:
|
|
372
|
-
Prohibit redefining component attribute structure`));
|
|
373
|
-
return false;
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
__name(createDeepShield, "createDeepShield");
|
|
378
|
-
function bindHooks(proto, instance) {
|
|
379
|
-
const hooks = Reflect.getMetadata(virid_METADATA.LIFE_CRICLE, proto);
|
|
380
|
-
hooks?.forEach((config) => {
|
|
381
|
-
const { hookName, methodName } = config;
|
|
382
|
-
const fn = instance[methodName].bind(instance);
|
|
383
|
-
switch (hookName) {
|
|
384
|
-
case "onMounted":
|
|
385
|
-
(0, import_vue.onMounted)(fn);
|
|
386
|
-
break;
|
|
387
|
-
case "onUnmounted":
|
|
388
|
-
(0, import_vue.onUnmounted)(fn);
|
|
389
|
-
break;
|
|
390
|
-
case "onUpdated":
|
|
391
|
-
(0, import_vue.onUpdated)(fn);
|
|
392
|
-
break;
|
|
393
|
-
case "onActivated":
|
|
394
|
-
(0, import_vue.onActivated)(fn);
|
|
395
|
-
break;
|
|
396
|
-
case "onDeactivated":
|
|
397
|
-
(0, import_vue.onDeactivated)(fn);
|
|
398
|
-
break;
|
|
399
|
-
case "onSetup":
|
|
400
|
-
fn();
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
__name(bindHooks, "bindHooks");
|
|
406
|
-
function bindUseHooks(proto, instance) {
|
|
407
|
-
const hooks = Reflect.getMetadata(virid_METADATA.USE_HOOKS, proto);
|
|
408
|
-
hooks?.forEach((config) => {
|
|
409
|
-
const hookResult = config.hookFactory();
|
|
410
|
-
instance[config.propertyKey] = hookResult;
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
__name(bindUseHooks, "bindUseHooks");
|
|
414
|
-
function bindListener(proto, instance) {
|
|
415
|
-
const listenerConfigs = Reflect.getMetadata(virid_METADATA.CONTROLLER_LISTENERS, proto) || [];
|
|
416
|
-
const unbindFunctions = [];
|
|
417
|
-
listenerConfigs.forEach(({ propertyKey, eventClass, priority, single }) => {
|
|
418
|
-
const originalMethod = instance[propertyKey];
|
|
419
|
-
const wrappedHandler = /* @__PURE__ */ __name(function(msgs) {
|
|
420
|
-
const message = single && Array.isArray(msgs) ? msgs[msgs.length - 1] : msgs;
|
|
421
|
-
if (msgs.length > 0) {
|
|
422
|
-
originalMethod.apply(instance, [
|
|
423
|
-
message
|
|
424
|
-
]);
|
|
425
|
-
}
|
|
426
|
-
}, "wrappedHandler");
|
|
427
|
-
const taskContext = {
|
|
428
|
-
params: eventClass,
|
|
429
|
-
targetClass: instance.constructor,
|
|
430
|
-
methodName: propertyKey,
|
|
431
|
-
originalMethod
|
|
432
|
-
};
|
|
433
|
-
wrappedHandler.ccsContext = taskContext;
|
|
434
|
-
const unregister = viridApp.register(eventClass, wrappedHandler, priority);
|
|
435
|
-
unbindFunctions.push(unregister);
|
|
436
|
-
});
|
|
437
|
-
return unbindFunctions;
|
|
438
|
-
}
|
|
439
|
-
__name(bindListener, "bindListener");
|
|
440
|
-
function bindInherit(proto, instance) {
|
|
441
|
-
const inherits = Reflect.getMetadata(virid_METADATA.INHERIT, proto);
|
|
442
|
-
if (!inherits) return;
|
|
443
|
-
inherits.forEach(({ propertyKey, token, id, selector }) => {
|
|
444
|
-
const tunnel = (0, import_vue.computed)(() => {
|
|
445
|
-
const target = GlobalRegistry.get(id);
|
|
446
|
-
if (!target) {
|
|
447
|
-
import_core2.MessageWriter.warn(`[Virid Inherit] Warning:
|
|
448
|
-
Inherit target not found: ${id}`);
|
|
449
|
-
return null;
|
|
450
|
-
}
|
|
451
|
-
return selector ? selector(target) : target;
|
|
452
|
-
});
|
|
453
|
-
Object.defineProperty(instance, propertyKey, {
|
|
454
|
-
get: /* @__PURE__ */ __name(() => {
|
|
455
|
-
const val = tunnel.value;
|
|
456
|
-
return val ? createDeepShield(val, propertyKey, "") : null;
|
|
457
|
-
}, "get"),
|
|
458
|
-
set: /* @__PURE__ */ __name(() => {
|
|
459
|
-
import_core2.MessageWriter.error(new Error(`[Virid Inherit] No Modification:
|
|
460
|
-
Attempted to set read-only Inherit property: ${propertyKey}`));
|
|
461
|
-
}, "set"),
|
|
462
|
-
enumerable: true,
|
|
463
|
-
configurable: true
|
|
464
|
-
});
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
__name(bindInherit, "bindInherit");
|
|
468
|
-
|
|
469
|
-
// adapters/hooks.ts
|
|
470
|
-
var import_vue2 = require("vue");
|
|
471
|
-
var import_core3 = require("@virid/core");
|
|
472
|
-
function useController(token, options) {
|
|
473
|
-
const instance = viridApp.get(token);
|
|
474
|
-
bindResponsive(instance);
|
|
475
|
-
const reactiveContext = options?.context || (0, import_vue2.useAttrs)();
|
|
476
|
-
if (reactiveContext) {
|
|
477
|
-
injectContext(reactiveContext, instance);
|
|
478
|
-
}
|
|
479
|
-
const isController = Reflect.hasMetadata(virid_METADATA.CONTROLLER, token);
|
|
480
|
-
const rawDeps = {};
|
|
481
|
-
if (isController) {
|
|
482
|
-
Object.keys(instance).forEach((key) => {
|
|
483
|
-
const dep = instance[key];
|
|
484
|
-
if (dep && typeof dep === "object" && dep.constructor) {
|
|
485
|
-
if (Reflect.hasMetadata(virid_METADATA.COMPONENT, dep.constructor)) {
|
|
486
|
-
rawDeps[key] = dep;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
const proto = Object.getPrototypeOf(instance);
|
|
492
|
-
bindProject(proto, instance, rawDeps);
|
|
493
|
-
bindUseHooks(proto, instance);
|
|
494
|
-
const stops = bindWatch(proto, instance);
|
|
495
|
-
const unbindList = bindListener(proto, instance);
|
|
496
|
-
if (isController) {
|
|
497
|
-
Object.keys(rawDeps).forEach((key) => {
|
|
498
|
-
instance[key] = createDeepShield(rawDeps[key], key, "");
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
bindHooks(proto, instance);
|
|
502
|
-
bindInherit(proto, instance);
|
|
503
|
-
let unbindRegister = /* @__PURE__ */ __name(() => true, "unbindRegister");
|
|
504
|
-
if (options?.id) {
|
|
505
|
-
unbindRegister = GlobalRegistry.set(options?.id, instance);
|
|
506
|
-
}
|
|
507
|
-
(0, import_vue2.onUnmounted)(() => {
|
|
508
|
-
stops.forEach((stop) => stop());
|
|
509
|
-
unbindList.forEach((unreg) => unreg());
|
|
510
|
-
unbindRegister();
|
|
511
|
-
});
|
|
512
|
-
return instance;
|
|
513
|
-
}
|
|
514
|
-
__name(useController, "useController");
|
|
515
|
-
function injectContext(context, instance) {
|
|
516
|
-
if (context && typeof context === "object") {
|
|
517
|
-
Object.keys(context).forEach((key) => {
|
|
518
|
-
Object.defineProperty(instance, key, {
|
|
519
|
-
// Getter 确保了 @Watch 的依赖收集能一路穿透到 Vue 源头
|
|
520
|
-
get: /* @__PURE__ */ __name(() => context[key], "get"),
|
|
521
|
-
// 处理写入逻辑
|
|
522
|
-
set: /* @__PURE__ */ __name((val) => {
|
|
523
|
-
if (context[key] === val) return;
|
|
524
|
-
try {
|
|
525
|
-
context[key] = val;
|
|
526
|
-
} catch (e) {
|
|
527
|
-
import_core3.MessageWriter.error(e, `[Virid Context] Set Failed:
|
|
528
|
-
"${key}" is only readable.`);
|
|
529
|
-
}
|
|
530
|
-
}, "set"),
|
|
531
|
-
enumerable: true,
|
|
532
|
-
configurable: true
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
__name(injectContext, "injectContext");
|
|
538
|
-
|
|
539
|
-
// index.ts
|
|
540
|
-
var VuePlugin = {
|
|
541
|
-
name: "@virid/vue",
|
|
542
|
-
install(app, _options) {
|
|
543
|
-
activateApp(app);
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
547
|
-
0 && (module.exports = {
|
|
548
|
-
ControllerMessage,
|
|
549
|
-
Env,
|
|
550
|
-
Inherit,
|
|
551
|
-
Listener,
|
|
552
|
-
OnHook,
|
|
553
|
-
Project,
|
|
554
|
-
Responsive,
|
|
555
|
-
Use,
|
|
556
|
-
VuePlugin,
|
|
557
|
-
Watch,
|
|
558
|
-
useController
|
|
559
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @virid/vue v0.0.1
|
|
3
|
+
* Vue adapter for virid, projecting logic sovereignty to reactive UI
|
|
4
|
+
*/
|
|
5
|
+
var C=Object.defineProperty;var N=(t,e,r)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e)=>C(t,"name",{value:e,configurable:!0});var x=(t,e,r)=>N(t,typeof e!="symbol"?e+"":e,r);import{VIRID_METADATA as U}from"@virid/core";var l={...U,RESPONSIVE:"virid:vue:responsive",LIFE_CIRCLE:"virid:vue:life-circle",HOOK:"virid:vue:hook",LISTENER:"virid:vue:listener",INHERIT:"virid:vue:inherit",ATTR:"virid:vue:attr",PROJECT:"virid:vue:project",WATCH:"virid:vue:watch"};import{watch as F,computed as S,ref as M,shallowReactive as K,onMounted as J,onUnmounted as z,onUpdated as Y,onActivated as B,onDeactivated as q,shallowRef as P}from"vue";import{MessageWriter as R,EventMessage as Q,SingleMessage as X}from"@virid/core";var v=null;function w(t){let e=i(r=>(r&&I(r),r),"bindResponsiveHook");t.addActivationHook(e),v=t}i(w,"activateApp");var b=new Proxy({},{get(t,e){return(...r)=>{if(!v)return console.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`),e==="register"?()=>{console.warn("[Virid Vue] Cleanup ignored: source listener was never registered.")}:void 0;let o=v[e];if(typeof o=="function")return o.apply(v,r)}}});import{MessageWriter as _}from"@virid/core";var O=new WeakMap;function g(t,e,r=""){if(t===null||typeof t!="object"&&typeof t!="function")return t;if(O.has(t))return O.get(t);let o=new Proxy(t,{get(s,n,c){let u=Reflect.get(s,n,c),f=r?`${r}.${String(n)}`:String(n);return typeof u=="function"?(...d)=>{if(!W(s,n)){let h=["[Virid Shield] Rejected",`Method: ${e}....${f}()`,"Reason: Unauthorized access to unsafe method."].join(`
|
|
6
|
+
`);return _.error(new Error(h)),null}let p=u.apply(s,d);return g(p,e,`${f}()`)}:g(u,e,f)},set(s,n){let c=r?`${r}.${String(n)}`:String(n),u=["[Virid Shield]","------------------------------------------------",`Component: ${e}`,`Code: ${e}....${c}`,"Result: Rejected","Reason: This object is write protected and cannot be modified.","------------------------------------------------"].join(`
|
|
7
|
+
`);return _.error(new Error(u)),!1},deleteProperty(s,n){return _.error(new Error(`[Virid Shield] Physical Protection:
|
|
8
|
+
Prohibit Deletion of Component Attributes ${String(n)}`)),!1},defineProperty(){return _.error(new Error(`[Virid Shield] Physical Protection:
|
|
9
|
+
Prohibit redefining component attribute structure`)),!1}});return O.set(t,o),o}i(g,"createDeepShield");function W(t,e){if(new Set([Symbol.iterator,Symbol.asyncIterator,Symbol.toStringTag,"toString","valueOf","toJSON","constructor"]).has(e))return!0;let o=t.constructor?.name;if({Map:new Set(["get","has","keys","values","entries","forEach","size"]),Set:new Set(["has","keys","values","entries","forEach","size"]),Array:new Set(["length","map","filter","reduce","slice","find","includes","findIndex","every","some","at","join","concat","flat","flatMap","indexOf","lastIndexOf"]),String:new Set(["length","slice","substring","substr","split","includes","startsWith","endsWith","indexOf","replace","replaceAll","trim","toLowerCase","toUpperCase"])}[o]?.has(e))return!0;let n=Reflect.getMetadata(l.SAFE,t);return!!(n instanceof Set&&n.has(e))}i(W,"isShieldException");var A=class A{static set(e,r){return this.globalRegistry.has(e)?(R.error(new Error(`[Virid UseController] Duplicate ID: Controller ${e} already exists`)),()=>!1):(this.globalRegistry.set(e,r),()=>(this.globalRegistry.delete(e),!0))}static get(e){return this.globalRegistry.has(e)?this.globalRegistry.get(e):(R.error(new Error(`[Virid UseController] ID Not Found: No Controller found with ID: ${e}`)),null)}};i(A,"GlobalRegistry"),x(A,"globalRegistry",K(new Map));var y=A;function T(t,e){Reflect.getMetadata(l.PROJECT,t)?.forEach(o=>{let{key:s,isAccessor:n,type:c,componentClass:u,source:f}=o,d,p=i(a=>{R.error(new Error(`[Virid Project] Read-only: Property "${s}" in "${e.constructor.name}" is a protected projection.
|
|
10
|
+
`))},"readOnlySetter");if(n){if(c==="component"){R.error(new Error(`[Virid Project] Architecture Violation: Manual get/set is forbidden on ${u} projection "${s}". Please use functional source.`));return}let a=Object.getOwnPropertyDescriptor(t,s);d=S({get:i(()=>a?.get?.call(e),"get"),set:i(m=>{a?.set?a.set.call(e,m):p(m)},"set")})}else d=S({get:i(()=>{let a=c==="component",m=a?b.get(u):e,E=f(m);return a?g(E,u.name,s):E},"get"),set:p});let h=Object.getOwnPropertyDescriptor(e,s);h&&h.configurable===!1||Object.defineProperty(e,s,{get:i(()=>d.value,"get"),set:i(a=>d.value=a,"set"),enumerable:!0,configurable:!0})})}i(T,"bindProject");function V(t,e){let r=Reflect.getMetadata(l.WATCH,t)||[],o=[];return r.forEach(s=>{let{type:n,source:c,methodName:u,options:f,componentClass:d}=s,p=n==="component"?b.get(d):e;p&&!p.__ccs_processed__&&I(p);let h=i(()=>{try{return c(p)}catch(E){R.error(E,`[Virid Watch] Getter error in ${u}`);return}},"getter"),a=e[u].bind(e),m=F(h,(E,H)=>{a(E,H)},{...f});o.push(m)}),o}i(V,"bindWatch");function I(t){return!t||typeof t!="object"||t.__virid_responsive_processed__||(Object.defineProperty(t,"__virid_responsive_processed__",{value:!0,enumerable:!1}),(Reflect.getMetadata(l.RESPONSIVE,t)||[]).forEach(r=>{let o=r.key,s=Object.getOwnPropertyDescriptor(t,o),n=s?.get?.__virid_box__;if(n){let c=n.value,u=r.shallow?P(c):M(c),f=new Proxy(u,{get(d,p){let h=d.value,a=Reflect.get(h,p);return typeof a=="function"?a.bind(h):a},set(d,p,h){return Reflect.set(d.value,p,h)}});n.value=f}else{if(s&&s.get)return;let c=t[o],u=r.shallow?P(c):M(c);Object.defineProperty(t,o,{get:i(()=>u.value,"get"),set:i(f=>{u.value=f},"set"),enumerable:!0,configurable:!0})}}),Reflect.ownKeys(t).forEach(r=>{if(r==="__virid_responsive_processed__")return;let o=t[r];o&&typeof o=="object"&&I(o)})),t}i(I,"bindResponsive");function j(t,e){Reflect.getMetadata(l.LIFE_CIRCLE,t)?.forEach(o=>{let{hookName:s,methodName:n}=o,c=e[n].bind(e);switch(s){case"onMounted":J(c);break;case"onUnmounted":z(c);break;case"onUpdated":Y(c);break;case"onActivated":B(c);break;case"onDeactivated":q(c);break;case"onSetup":c();break}})}i(j,"bindHooks");function L(t,e){Reflect.getMetadata(l.HOOK,t)?.forEach(o=>{let s=o.hookFactory();e[o.key]=s})}i(L,"bindUseHooks");function D(t,e){let r=Reflect.getMetadata(l.LISTENER,t)||[],o=[];return r.forEach(({key:s,messageClass:n,priority:c,single:u})=>{let f=e[s],d=i(function(a){let m=Array.isArray(a)?a[0]:a,E;if(!(m instanceof n))return R.error(new Error(`[Virid Listener] Type Mismatch: Expected ${n.name}, but received ${m?.constructor.name}`)),null;if(m instanceof X)u&&(E=Array.isArray(a)?a[a.length-1]:a),E=Array.isArray(a)?a:[a];else if(m instanceof Q)E=[a];else throw new Error(`[Virid System] unknown Message Types: Message ${n.name} is not a subclass of SingleMessage or EventMessage!`);f.apply(e,E)},"wrappedHandler"),p={params:[n],targetClass:e.constructor,methodName:s,originalMethod:f};d.systemContext=p;let h=b.register(n,d,c);o.push(h)}),o}i(D,"bindListener");function $(t,e){let r=Reflect.getMetadata(l.INHERIT,t);r&&r.forEach(({key:o,_token:s,id:n,selector:c})=>{let u=S(()=>{let f=y.get(n);return f?c?c(f):f:(R.warn(`[Virid Inherit] Warning:
|
|
11
|
+
Inherit target not found: ${n}`),null)});Object.defineProperty(e,o,{get:i(()=>{let f=u.value;return f?g(f,o,""):null},"get"),set:i(()=>{R.error(new Error(`[Virid Inherit] No Modification:
|
|
12
|
+
Attempted to set read-only Inherit property: ${o}`))},"set"),enumerable:!0,configurable:!0})})}i($,"bindInherit");import{onUnmounted as Z,useAttrs as G}from"vue";import{MessageWriter as k}from"@virid/core";function ee(t,e){let r=b.get(t),o=e?.context||G();if(o&&te(o,r),!Reflect.hasMetadata(l.CONTROLLER,t)){k.error(new Error(`[Virid Controller] ${t.name} is not a Controller.Use @Controller to inject it.`));return}let n=Object.getPrototypeOf(r);L(n,r),$(n,r),T(n,r);let c=D(n,r);j(n,r);let u=V(n,r),f=i(()=>!0,"unbindRegister");return e?.id&&(f=y.set(e.id,r)),Z(()=>{u.forEach(d=>d()),c.forEach(d=>d()),f()}),r}i(ee,"useController");function te(t,e){t&&typeof t=="object"&&Object.keys(t).forEach(r=>{Object.defineProperty(e,r,{get:i(()=>t[r],"get"),set:i(o=>{if(t[r]!==o)try{t[r]=o}catch(s){k.error(s,`[Virid Context] Set Failed:
|
|
13
|
+
"${r}" is only readable.`)}},"set"),enumerable:!0,configurable:!0})})}i(te,"injectContext");import{MessageWriter as re}from"@virid/core";function Pe(t,e,r){return(o,s)=>{let n=Reflect.getMetadata(l.WATCH,o)||[];typeof e=="function"?n.push({type:"component",componentClass:t,source:e,options:r,methodName:s}):n.push({type:"local",componentClass:null,source:t,options:e,methodName:s}),Reflect.defineMetadata(l.WATCH,n,o)}}i(Pe,"Watch");function Te(t,e){return(r,o,s)=>{let n=Reflect.getMetadata(l.PROJECT,r)||[],c=!!(s?.get||s?.set);if(!t&&!e&&!c){re.error(new Error("[Virid Project] Invalid Usage: @Project() can only be used on getter or setter."));return}let u={key:o,isAccessor:c,type:typeof e=="function"?"component":"local",componentClass:typeof e=="function"?t:null,source:typeof e=="function"?e:c?null:t};n.push(u),Reflect.defineMetadata(l.PROJECT,n,r)}}i(Te,"Project");function Ve(t=!1){return(e,r)=>{let o=Reflect.getMetadata(l.RESPONSIVE,e)||[];o.push({key:r,shallow:t}),Reflect.defineMetadata(l.RESPONSIVE,o,e)}}i(Ve,"Responsive");function je(t){return(e,r)=>{let o=Reflect.getMetadata(l.LIFE_CIRCLE,e)||[];o.push({hookName:t,methodName:r}),Reflect.defineMetadata(l.LIFE_CIRCLE,o,e)}}i(je,"OnHook");function Le(t){return(e,r)=>{let o=Reflect.getMetadata(l.HOOK,e)||[];o.push({key:r,hookFactory:t}),Reflect.defineMetadata(l.HOOK,o,e)}}i(Le,"Use");function De(t,e,r){return(o,s)=>{let n=Reflect.getMetadata(l.INHERIT,o)||[];n.push({key:s,token:t,id:e,selector:r}),Reflect.defineMetadata(l.INHERIT,n,o)}}i(De,"Inherit");function $e(){return(t,e)=>{}}i($e,"Env");function ke({messageClass:t,priority:e=0,single:r=!0}){return(o,s)=>{let n=Reflect.getMetadata(l.LISTENER,o)||[];n.push({key:s,messageClass:t,priority:e,single:r}),Reflect.defineMetadata(l.LISTENER,n,o)}}i(ke,"Listener");var Je={name:"@virid/vue",install(t,e){w(t)}};export{$e as Env,De as Inherit,ke as Listener,je as OnHook,Te as Project,Ve as Responsive,Le as Use,Je as VuePlugin,Pe as Watch,ee as useController};
|
|
14
|
+
//# sourceMappingURL=index.js.map
|