@knotx/decorators 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +601 -0
- package/dist/index.d.cts +370 -0
- package/dist/index.d.mts +370 -0
- package/dist/index.d.ts +370 -0
- package/dist/index.mjs +586 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 格桑
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const core = require('@knotx/core');
|
|
4
|
+
const rxjs = require('rxjs');
|
|
5
|
+
const lodashEs = require('lodash-es');
|
|
6
|
+
const jsxRuntime = require('@knotx/jsx/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function requireEngine(plugin) {
|
|
9
|
+
const engineSymbol = core.getSymbol("engine");
|
|
10
|
+
if (!Reflect.has(plugin, engineSymbol)) {
|
|
11
|
+
Reflect.set(plugin, engineSymbol, new rxjs.BehaviorSubject(null));
|
|
12
|
+
}
|
|
13
|
+
return Reflect.get(plugin, engineSymbol);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function edgeOperator() {
|
|
17
|
+
return function(_target, { name, static: isStatic, private: isPrivate, addInitializer }) {
|
|
18
|
+
if (isStatic || isPrivate) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
addInitializer(function() {
|
|
22
|
+
const operator = Reflect.get(this, name);
|
|
23
|
+
if (typeof operator !== "function") {
|
|
24
|
+
throw new TypeError("Edge operator must be a function");
|
|
25
|
+
}
|
|
26
|
+
requireEngine(this).subscribe((engine) => {
|
|
27
|
+
if (!engine)
|
|
28
|
+
return;
|
|
29
|
+
const boundOperator = operator.bind(this);
|
|
30
|
+
Reflect.set(this, name, (...args) => {
|
|
31
|
+
const operations = boundOperator(...args);
|
|
32
|
+
if (Array.isArray(operations)) {
|
|
33
|
+
engine.dispatchEdgeOperation({
|
|
34
|
+
type: "batch",
|
|
35
|
+
operations
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return operations;
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const edgePipeSymbol = Symbol("edgePipe");
|
|
46
|
+
function edgePipe() {
|
|
47
|
+
return function(_target, { name, static: isStatic, private: isPrivate, addInitializer }) {
|
|
48
|
+
if (isStatic || isPrivate) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
addInitializer(function() {
|
|
52
|
+
const pipeFactory = Reflect.get(this, name);
|
|
53
|
+
if (typeof pipeFactory !== "function") {
|
|
54
|
+
throw new TypeError("Edge pipe must be a function");
|
|
55
|
+
}
|
|
56
|
+
requireEngine(this).subscribe((engine) => {
|
|
57
|
+
if (!engine)
|
|
58
|
+
return;
|
|
59
|
+
const pipe = pipeFactory.call(this);
|
|
60
|
+
engine.addEdgePipe(pipe);
|
|
61
|
+
if (!this[edgePipeSymbol]) {
|
|
62
|
+
this[edgePipeSymbol] = {};
|
|
63
|
+
}
|
|
64
|
+
this[edgePipeSymbol][name] = pipe;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function edgeType(type) {
|
|
71
|
+
return function(_target, { name, static: isStatic, private: isPrivate, addInitializer }) {
|
|
72
|
+
if (isStatic || isPrivate) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
addInitializer(function() {
|
|
76
|
+
const renderer = Reflect.get(this, name);
|
|
77
|
+
if (typeof renderer !== "function") {
|
|
78
|
+
throw new TypeError("Edge renderer must be a function");
|
|
79
|
+
}
|
|
80
|
+
requireEngine(this).subscribe((engine) => engine == null ? void 0 : engine.registerEdgeRenderer(type, renderer.bind(this)));
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function injectData(context, engineKey, selector) {
|
|
86
|
+
context.addInitializer(function() {
|
|
87
|
+
const engine$ = requireEngine(this);
|
|
88
|
+
Reflect.defineProperty(this, context.name, {
|
|
89
|
+
get() {
|
|
90
|
+
const engine = engine$.value;
|
|
91
|
+
if (!engine) {
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
const engineKey$ = `${String(engineKey)}$`;
|
|
95
|
+
const paths = lodashEs.get(engine, engineKey$) ? [engineKey$] : [engineKey];
|
|
96
|
+
return core.Runtime.getInstance().getValue(engine, { paths, selector });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function injectMethod(context, methodKey) {
|
|
103
|
+
context.addInitializer(function() {
|
|
104
|
+
Reflect.set(this, context.name, (...methodArgs) => {
|
|
105
|
+
const engine = requireEngine(this).value;
|
|
106
|
+
const engineMethod = engine == null ? void 0 : engine[methodKey];
|
|
107
|
+
if (!engineMethod || typeof engineMethod !== "function") {
|
|
108
|
+
throw new Error(`Engine method ${String(methodKey)} not found`);
|
|
109
|
+
}
|
|
110
|
+
return Reflect.apply(engineMethod, engine, methodArgs);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function injectPluginData(context, pluginName, property, selector) {
|
|
116
|
+
context.addInitializer(function() {
|
|
117
|
+
const engine$ = requireEngine(this);
|
|
118
|
+
Reflect.defineProperty(this, context.name, {
|
|
119
|
+
get() {
|
|
120
|
+
const engine = engine$.value;
|
|
121
|
+
if (!engine) {
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
124
|
+
const paths = ["_pluginDataContainer", pluginName, property];
|
|
125
|
+
return core.Runtime.getInstance().getValue(engine, { paths, selector });
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function createInjectableProxy(engine, accessRecord) {
|
|
132
|
+
return new Proxy({}, {
|
|
133
|
+
get(_, prop) {
|
|
134
|
+
if (prop === Symbol.toPrimitive || prop === "toString" || prop === "valueOf") {
|
|
135
|
+
return () => "[object Injectable]";
|
|
136
|
+
}
|
|
137
|
+
if (typeof prop !== "string") {
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
if (prop in engine) {
|
|
141
|
+
const engineProp = engine[prop];
|
|
142
|
+
if (typeof engineProp === "function") {
|
|
143
|
+
throw new TypeError(`Engine method ${String(prop)} cannot be accessed via injectable`);
|
|
144
|
+
}
|
|
145
|
+
if (isBehaviorSubject(engineProp)) {
|
|
146
|
+
accessRecord.subjects.push(engineProp);
|
|
147
|
+
accessRecord.paths.push([prop]);
|
|
148
|
+
return engineProp;
|
|
149
|
+
}
|
|
150
|
+
if (engineProp && typeof engineProp === "object") {
|
|
151
|
+
return createEnginePropertyProxy(engine, prop, engineProp, accessRecord);
|
|
152
|
+
}
|
|
153
|
+
return engineProp;
|
|
154
|
+
}
|
|
155
|
+
return createPluginPropertyProxy(engine, prop, accessRecord);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function createEnginePropertyProxy(engine, propName, propValue, accessRecord) {
|
|
160
|
+
return new Proxy({}, {
|
|
161
|
+
get(_, subProp) {
|
|
162
|
+
if (subProp === Symbol.toPrimitive || subProp === "toString" || subProp === "valueOf") {
|
|
163
|
+
return () => `[object Injectable.${String(propName)}]`;
|
|
164
|
+
}
|
|
165
|
+
if (typeof subProp !== "string") {
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
const nestedProp = propValue[subProp];
|
|
169
|
+
if (isBehaviorSubject(nestedProp)) {
|
|
170
|
+
accessRecord.subjects.push(nestedProp);
|
|
171
|
+
accessRecord.paths.push([propName, subProp]);
|
|
172
|
+
return nestedProp;
|
|
173
|
+
}
|
|
174
|
+
if (nestedProp && typeof nestedProp === "object") {
|
|
175
|
+
return createNestedPropertyProxy(engine, [propName, subProp], nestedProp, accessRecord);
|
|
176
|
+
}
|
|
177
|
+
return nestedProp;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function createNestedPropertyProxy(engine, path, propValue, accessRecord) {
|
|
182
|
+
return new Proxy({}, {
|
|
183
|
+
get(_, subProp) {
|
|
184
|
+
if (subProp === Symbol.toPrimitive || subProp === "toString" || subProp === "valueOf") {
|
|
185
|
+
return () => `[object Injectable.${path.join(".")}]`;
|
|
186
|
+
}
|
|
187
|
+
if (typeof subProp !== "string") {
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
const nestedProp = propValue[subProp];
|
|
191
|
+
if (isBehaviorSubject(nestedProp)) {
|
|
192
|
+
accessRecord.subjects.push(nestedProp);
|
|
193
|
+
accessRecord.paths.push([...path, subProp]);
|
|
194
|
+
return nestedProp;
|
|
195
|
+
}
|
|
196
|
+
if (nestedProp && typeof nestedProp === "object") {
|
|
197
|
+
return createNestedPropertyProxy(engine, [...path, subProp], nestedProp, accessRecord);
|
|
198
|
+
}
|
|
199
|
+
return nestedProp;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function createPluginPropertyProxy(engine, pluginName, accessRecord) {
|
|
204
|
+
return new Proxy({}, {
|
|
205
|
+
get(_, prop) {
|
|
206
|
+
if (prop === Symbol.toPrimitive || prop === "toString" || prop === "valueOf") {
|
|
207
|
+
return () => `[object Injectable.${String(pluginName)}]`;
|
|
208
|
+
}
|
|
209
|
+
if (typeof prop !== "string") {
|
|
210
|
+
return void 0;
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const paths = ["_pluginDataContainer", pluginName, prop];
|
|
214
|
+
const pluginData = lodashEs.get(engine, paths);
|
|
215
|
+
if (isBehaviorSubject(pluginData)) {
|
|
216
|
+
accessRecord.subjects.push(pluginData);
|
|
217
|
+
accessRecord.paths.push(paths);
|
|
218
|
+
return pluginData.value;
|
|
219
|
+
}
|
|
220
|
+
return pluginData;
|
|
221
|
+
} catch (e) {
|
|
222
|
+
return void 0;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function isBehaviorSubject(value) {
|
|
228
|
+
return value instanceof rxjs.BehaviorSubject;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function injectable(context, injectableSelector) {
|
|
232
|
+
const injectableStateSymbol = Symbol(`injectable:${String(context.name)}`);
|
|
233
|
+
context.addInitializer(function() {
|
|
234
|
+
const engine$ = requireEngine(this);
|
|
235
|
+
Reflect.set(this, injectableStateSymbol, {
|
|
236
|
+
initialized: false,
|
|
237
|
+
accessRecord: null,
|
|
238
|
+
wrappedSubject$: null,
|
|
239
|
+
subscription: null,
|
|
240
|
+
selector: null,
|
|
241
|
+
matcher: null,
|
|
242
|
+
paths: []
|
|
243
|
+
});
|
|
244
|
+
Reflect.defineProperty(this, context.name, {
|
|
245
|
+
get() {
|
|
246
|
+
const engine = engine$.value;
|
|
247
|
+
if (!engine) {
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
const state = this[injectableStateSymbol];
|
|
251
|
+
if (!state.initialized) {
|
|
252
|
+
state.initialized = true;
|
|
253
|
+
const accessRecord = {
|
|
254
|
+
subjects: [],
|
|
255
|
+
paths: []
|
|
256
|
+
};
|
|
257
|
+
const injectable2 = createInjectableProxy(engine, accessRecord);
|
|
258
|
+
injectableSelector(injectable2, {});
|
|
259
|
+
if (accessRecord.subjects.length > 0) {
|
|
260
|
+
const combinedObservable$ = rxjs.combineLatest(accessRecord.subjects);
|
|
261
|
+
const wrappedSubject$ = new rxjs.BehaviorSubject(
|
|
262
|
+
accessRecord.subjects.map((subject) => subject.value)
|
|
263
|
+
);
|
|
264
|
+
const subscription = combinedObservable$.subscribe(wrappedSubject$);
|
|
265
|
+
state.accessRecord = accessRecord;
|
|
266
|
+
state.wrappedSubject$ = wrappedSubject$;
|
|
267
|
+
state.subscription = subscription;
|
|
268
|
+
state.matcher = () => state.wrappedSubject$;
|
|
269
|
+
}
|
|
270
|
+
state.selector = (_, context2) => {
|
|
271
|
+
const injectable3 = createInjectableProxy(engine, { subjects: [], paths: [] });
|
|
272
|
+
return injectableSelector(injectable3, context2 || {});
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return core.Runtime.getInstance().getValue(engine, state);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function injectDecorator(arg0, arg1, arg2) {
|
|
282
|
+
return function(_, context) {
|
|
283
|
+
var _a;
|
|
284
|
+
if (typeof arg0 === "function") {
|
|
285
|
+
return injectable(context, arg0);
|
|
286
|
+
}
|
|
287
|
+
if (typeof arg1 === "string") {
|
|
288
|
+
return injectPluginData(context, arg0, arg1, arg2);
|
|
289
|
+
}
|
|
290
|
+
const engineKey = arg0;
|
|
291
|
+
const isMethod = typeof ((_a = Reflect.getOwnPropertyDescriptor(core.Engine.prototype, engineKey)) == null ? void 0 : _a.value) === "function";
|
|
292
|
+
if (isMethod) {
|
|
293
|
+
return injectMethod(context, engineKey);
|
|
294
|
+
}
|
|
295
|
+
return injectData(context, engineKey, arg1);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function createInjectProxy(...presets) {
|
|
300
|
+
return new Proxy(
|
|
301
|
+
new Object(() => {
|
|
302
|
+
}),
|
|
303
|
+
{
|
|
304
|
+
get(_, prop) {
|
|
305
|
+
return createInjectProxy(...presets, prop);
|
|
306
|
+
},
|
|
307
|
+
apply(_, thisArg, args) {
|
|
308
|
+
return Reflect.apply(injectDecorator, thisArg, [...presets, ...args]);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
const inject = createInjectProxy();
|
|
314
|
+
|
|
315
|
+
function register(property) {
|
|
316
|
+
return function(_, context) {
|
|
317
|
+
if (context.kind !== "field" && context.kind !== "getter") {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
context.addInitializer(function() {
|
|
321
|
+
const subject = new rxjs.BehaviorSubject(Reflect.get(this, context.name));
|
|
322
|
+
const engine$ = requireEngine(this);
|
|
323
|
+
engine$.subscribe((engine) => engine == null ? void 0 : engine.registerPluginData(this.name, property, subject));
|
|
324
|
+
Reflect.defineProperty(this, context.name, {
|
|
325
|
+
get() {
|
|
326
|
+
const engine = engine$.value;
|
|
327
|
+
if (!engine) {
|
|
328
|
+
return void 0;
|
|
329
|
+
}
|
|
330
|
+
return core.Runtime.getInstance().getValue(engine, { paths: ["_pluginDataContainer", this.name, property] });
|
|
331
|
+
},
|
|
332
|
+
set(value) {
|
|
333
|
+
if (context.kind === "field") {
|
|
334
|
+
subject.next(value);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function layer(layer2, offset) {
|
|
343
|
+
return function(_target, { name, kind, static: isStatic, private: isPrivate, addInitializer }) {
|
|
344
|
+
if (kind === "method" && typeof name === "string" && !isStatic && !isPrivate) {
|
|
345
|
+
addInitializer(function() {
|
|
346
|
+
var _a;
|
|
347
|
+
const layers = (_a = Reflect.get(this, core.getSymbol("layer"))) != null ? _a : {};
|
|
348
|
+
layers[name] = { layer: layer2, offset };
|
|
349
|
+
Reflect.set(this, core.getSymbol("layer"), layers);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
var __defProp = Object.defineProperty;
|
|
356
|
+
var __defProps = Object.defineProperties;
|
|
357
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
358
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
359
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
360
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
361
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
362
|
+
var __spreadValues = (a, b) => {
|
|
363
|
+
for (var prop in b || (b = {}))
|
|
364
|
+
if (__hasOwnProp.call(b, prop))
|
|
365
|
+
__defNormalProp(a, prop, b[prop]);
|
|
366
|
+
if (__getOwnPropSymbols)
|
|
367
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
368
|
+
if (__propIsEnum.call(b, prop))
|
|
369
|
+
__defNormalProp(a, prop, b[prop]);
|
|
370
|
+
}
|
|
371
|
+
return a;
|
|
372
|
+
};
|
|
373
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
374
|
+
function getPositionStyle(position, container, offset = {}) {
|
|
375
|
+
const { x = 0, y = 0 } = offset;
|
|
376
|
+
const { width, height } = container;
|
|
377
|
+
const baseStyle = {
|
|
378
|
+
position: "absolute",
|
|
379
|
+
top: 0,
|
|
380
|
+
left: 0
|
|
381
|
+
};
|
|
382
|
+
switch (position) {
|
|
383
|
+
case "top":
|
|
384
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
385
|
+
transform: `translate(calc(${width / 2}px - 50%), ${y}px)`
|
|
386
|
+
});
|
|
387
|
+
case "bottom":
|
|
388
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
389
|
+
transform: `translate(calc(${width / 2}px - 50%), calc(${height}px - 100% + ${y}px))`
|
|
390
|
+
});
|
|
391
|
+
case "left":
|
|
392
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
393
|
+
transform: `translate(${x}px, calc(${height / 2}px - 50%))`
|
|
394
|
+
});
|
|
395
|
+
case "right":
|
|
396
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
397
|
+
transform: `translate(calc(${width}px - 100% + ${x}px), calc(${height / 2}px - 50%))`
|
|
398
|
+
});
|
|
399
|
+
case "center":
|
|
400
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
401
|
+
transform: `translate(calc(${width / 2}px - 50% + ${x}px), calc(${height / 2}px - 50% + ${y}px))`
|
|
402
|
+
});
|
|
403
|
+
case "left-top":
|
|
404
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
405
|
+
transform: `translate(${x}px, ${y}px)`
|
|
406
|
+
});
|
|
407
|
+
case "right-top":
|
|
408
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
409
|
+
transform: `translate(calc(${width}px - 100% + ${x}px), ${y}px)`
|
|
410
|
+
});
|
|
411
|
+
case "left-bottom":
|
|
412
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
413
|
+
transform: `translate(${x}px, calc(${height}px - 100% + ${y}px))`
|
|
414
|
+
});
|
|
415
|
+
case "right-bottom":
|
|
416
|
+
return __spreadProps(__spreadValues({}, baseStyle), {
|
|
417
|
+
transform: `translate(calc(${width}px - 100% + ${x}px), calc(${height}px - 100% + ${y}px))`
|
|
418
|
+
});
|
|
419
|
+
default:
|
|
420
|
+
return baseStyle;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function createPanelWrapper(position, offset = {}) {
|
|
424
|
+
return function PanelWrapper({ children, container }) {
|
|
425
|
+
const style = getPositionStyle(position, container, offset);
|
|
426
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style, children });
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function ContainerListener({
|
|
430
|
+
getContainer,
|
|
431
|
+
children,
|
|
432
|
+
position,
|
|
433
|
+
offset
|
|
434
|
+
}) {
|
|
435
|
+
const container = core.use(getContainer);
|
|
436
|
+
const Wrapper = createPanelWrapper(position, offset);
|
|
437
|
+
return container.width > 0 && container.height > 0 ? /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { container, children }) : null;
|
|
438
|
+
}
|
|
439
|
+
function panel(position, offset) {
|
|
440
|
+
return function(_target, { name, kind, static: isStatic, private: isPrivate, addInitializer }) {
|
|
441
|
+
if (kind === "method" && typeof name === "string" && !isStatic && !isPrivate) {
|
|
442
|
+
addInitializer(function() {
|
|
443
|
+
var _a;
|
|
444
|
+
const layers = (_a = Reflect.get(this, core.getSymbol("layer"))) != null ? _a : {};
|
|
445
|
+
const originalRender = Reflect.get(this, name);
|
|
446
|
+
Reflect.set(this, name, function(...args) {
|
|
447
|
+
const result = originalRender == null ? void 0 : originalRender.apply(this, args);
|
|
448
|
+
const engine = requireEngine(this).value;
|
|
449
|
+
if (!engine || !result) {
|
|
450
|
+
return result;
|
|
451
|
+
}
|
|
452
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
453
|
+
ContainerListener,
|
|
454
|
+
{
|
|
455
|
+
getContainer: () => core.Runtime.getInstance().getValue(engine, { paths: ["container$"] }),
|
|
456
|
+
position,
|
|
457
|
+
offset,
|
|
458
|
+
children: result
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
});
|
|
462
|
+
layers[name] = { layer: core.Layer.Foreground };
|
|
463
|
+
Reflect.set(this, core.getSymbol("layer"), layers);
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function nodeOperator() {
|
|
470
|
+
return function(_target, { name, static: isStatic, private: isPrivate, addInitializer }) {
|
|
471
|
+
if (isStatic || isPrivate) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
addInitializer(function() {
|
|
475
|
+
const operator = Reflect.get(this, name);
|
|
476
|
+
if (typeof operator !== "function") {
|
|
477
|
+
throw new TypeError("Node operator must be a function");
|
|
478
|
+
}
|
|
479
|
+
requireEngine(this).subscribe((engine) => {
|
|
480
|
+
if (!engine)
|
|
481
|
+
return;
|
|
482
|
+
const boundOperator = operator.bind(this);
|
|
483
|
+
Reflect.set(this, name, (...args) => {
|
|
484
|
+
const operations = boundOperator(...args);
|
|
485
|
+
if (Array.isArray(operations)) {
|
|
486
|
+
engine.dispatchNodeOperation({
|
|
487
|
+
type: "batch",
|
|
488
|
+
operations
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
return operations;
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const nodePipeSymbol = Symbol("nodePipe");
|
|
499
|
+
function nodePipe() {
|
|
500
|
+
return function(_target, { name, static: isStatic, private: isPrivate, addInitializer }) {
|
|
501
|
+
if (isStatic || isPrivate) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
addInitializer(function() {
|
|
505
|
+
const pipeFactory = Reflect.get(this, name);
|
|
506
|
+
if (typeof pipeFactory !== "function") {
|
|
507
|
+
throw new TypeError("Node pipe must be a function");
|
|
508
|
+
}
|
|
509
|
+
requireEngine(this).subscribe((engine) => {
|
|
510
|
+
if (!engine)
|
|
511
|
+
return;
|
|
512
|
+
const pipe = pipeFactory.call(this);
|
|
513
|
+
engine.addNodePipe(pipe);
|
|
514
|
+
if (!this[nodePipeSymbol]) {
|
|
515
|
+
this[nodePipeSymbol] = {};
|
|
516
|
+
}
|
|
517
|
+
this[nodePipeSymbol][name] = pipe;
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function nodeType(type) {
|
|
524
|
+
return function(_target, { name, static: isStatic, private: isPrivate, addInitializer }) {
|
|
525
|
+
if (isStatic || isPrivate) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
addInitializer(function() {
|
|
529
|
+
const renderer = Reflect.get(this, name);
|
|
530
|
+
if (typeof renderer !== "function") {
|
|
531
|
+
throw new TypeError("Node renderer must be a function");
|
|
532
|
+
}
|
|
533
|
+
requireEngine(this).subscribe((engine) => engine == null ? void 0 : engine.registerNodeRenderer(type, renderer.bind(this)));
|
|
534
|
+
});
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function OnInit(originalMethod, context) {
|
|
539
|
+
if (context.kind !== "method") {
|
|
540
|
+
console.warn("OnInit decorator can only be applied to methods");
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
context.addInitializer(function() {
|
|
544
|
+
this.onInit = () => {
|
|
545
|
+
originalMethod.call(this);
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
function OnDestroy(originalMethod, context) {
|
|
550
|
+
if (context.kind !== "method") {
|
|
551
|
+
console.warn("OnDestroy decorator can only be applied to methods");
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
context.addInitializer(function() {
|
|
555
|
+
this.onDestroy = () => {
|
|
556
|
+
originalMethod.call(this);
|
|
557
|
+
};
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function observable() {
|
|
562
|
+
return function(_, context) {
|
|
563
|
+
if (context.kind !== "field") {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
context.addInitializer(function() {
|
|
567
|
+
const subject = new rxjs.BehaviorSubject(Reflect.get(this, context.name));
|
|
568
|
+
const engine$ = requireEngine(this);
|
|
569
|
+
Reflect.defineProperty(this, context.name, {
|
|
570
|
+
get() {
|
|
571
|
+
const engine = engine$.value;
|
|
572
|
+
if (!engine) {
|
|
573
|
+
return subject.value;
|
|
574
|
+
}
|
|
575
|
+
return core.Runtime.getInstance().getValue(engine, {
|
|
576
|
+
paths: [],
|
|
577
|
+
matcher: () => subject
|
|
578
|
+
});
|
|
579
|
+
},
|
|
580
|
+
set(value) {
|
|
581
|
+
subject.next(value);
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
exports.OnDestroy = OnDestroy;
|
|
589
|
+
exports.OnInit = OnInit;
|
|
590
|
+
exports.createPanelWrapper = createPanelWrapper;
|
|
591
|
+
exports.edgeOperator = edgeOperator;
|
|
592
|
+
exports.edgePipe = edgePipe;
|
|
593
|
+
exports.edgeType = edgeType;
|
|
594
|
+
exports.inject = inject;
|
|
595
|
+
exports.layer = layer;
|
|
596
|
+
exports.nodeOperator = nodeOperator;
|
|
597
|
+
exports.nodePipe = nodePipe;
|
|
598
|
+
exports.nodeType = nodeType;
|
|
599
|
+
exports.observable = observable;
|
|
600
|
+
exports.panel = panel;
|
|
601
|
+
exports.register = register;
|