@ng-desktop/platform 0.0.0-stage → 0.4.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 +21 -0
- package/README.md +13 -2
- package/fesm2022/bridge-fs-compute.d.ts +19 -0
- package/fesm2022/bridge-fs-compute.js +107 -0
- package/fesm2022/bridge-sqlite.d.ts +11 -0
- package/fesm2022/bridge-sqlite.js +240 -0
- package/fesm2022/bridge.d.ts +168 -0
- package/fesm2022/bridge.js +421 -0
- package/fesm2022/css-style-parser.d.ts +33 -0
- package/fesm2022/css-style-parser.js +259 -0
- package/fesm2022/ecosystem-compat.d.ts +98 -0
- package/fesm2022/ecosystem-compat.js +281 -0
- package/fesm2022/image-loader.d.ts +8 -0
- package/fesm2022/image-loader.js +13 -0
- package/fesm2022/index.d.ts +12 -0
- package/fesm2022/index.js +12 -0
- package/fesm2022/native-directives.d.ts +178 -0
- package/fesm2022/native-directives.js +724 -0
- package/fesm2022/native-element.d.ts +73 -0
- package/fesm2022/native-element.js +212 -0
- package/fesm2022/native-renderer.d.ts +93 -0
- package/fesm2022/native-renderer.js +1106 -0
- package/fesm2022/native-title.d.ts +18 -0
- package/fesm2022/native-title.js +52 -0
- package/fesm2022/platform.d.ts +18 -0
- package/fesm2022/platform.js +46 -0
- package/fesm2022/system-providers.d.ts +43 -0
- package/fesm2022/system-providers.js +163 -0
- package/fesm2022/viewport-scroller.d.ts +24 -0
- package/fesm2022/viewport-scroller.js +65 -0
- package/fesm2022/virtual-list.component.d.ts +57 -0
- package/fesm2022/virtual-list.component.js +200 -0
- package/package.json +50 -4
|
@@ -0,0 +1,1106 @@
|
|
|
1
|
+
import { Injectable, Renderer2, } from '@angular/core';
|
|
2
|
+
import { ensureNgNativeBridge } from './bridge.js';
|
|
3
|
+
import { mapAlignKeyword, registerParsedStyles } from './css-style-parser.js';
|
|
4
|
+
import { NativeElementNode } from './native-element.js';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
const VIRTUAL_ANGULAR_TAGS = new Set([
|
|
7
|
+
'ng-container',
|
|
8
|
+
'ng-template',
|
|
9
|
+
'ng-content',
|
|
10
|
+
'ng-component',
|
|
11
|
+
'ng-virtual-list',
|
|
12
|
+
]);
|
|
13
|
+
const TEXT_BEARING_TAGS = new Set([
|
|
14
|
+
'ng-label',
|
|
15
|
+
'gtk-label',
|
|
16
|
+
'ng-button',
|
|
17
|
+
'gtk-button',
|
|
18
|
+
'ng-window',
|
|
19
|
+
'adw-window',
|
|
20
|
+
'ng-dialog',
|
|
21
|
+
'gtk-dialog',
|
|
22
|
+
'adw-dialog',
|
|
23
|
+
'ng-header-bar',
|
|
24
|
+
'adw-header-bar',
|
|
25
|
+
'gtk-header-bar',
|
|
26
|
+
'ng-check-button',
|
|
27
|
+
'gtk-check-button',
|
|
28
|
+
'ng-expander',
|
|
29
|
+
'gtk-expander',
|
|
30
|
+
'ng-entry',
|
|
31
|
+
'gtk-entry',
|
|
32
|
+
'ng-search-entry',
|
|
33
|
+
'gtk-search-entry',
|
|
34
|
+
'ng-password-entry',
|
|
35
|
+
'gtk-password-entry',
|
|
36
|
+
'ng-text-view',
|
|
37
|
+
'gtk-text-view',
|
|
38
|
+
]);
|
|
39
|
+
const TEXT_INPUT_TAGS = new Set([
|
|
40
|
+
'ng-entry',
|
|
41
|
+
'gtk-entry',
|
|
42
|
+
'ng-search-entry',
|
|
43
|
+
'gtk-search-entry',
|
|
44
|
+
'ng-password-entry',
|
|
45
|
+
'gtk-password-entry',
|
|
46
|
+
'ng-text-view',
|
|
47
|
+
'gtk-text-view',
|
|
48
|
+
]);
|
|
49
|
+
/**
|
|
50
|
+
* 1:1 mapping from standard HTML elements to native desktop widget primitives.
|
|
51
|
+
* Containers map to `ng-box` (1D Flexbox); text elements map to `ng-label`.
|
|
52
|
+
* Angular component selectors (e.g. `app-*`, `router-outlet`, `ng-container`) are omitted
|
|
53
|
+
* so they continue operating as virtual hosts.
|
|
54
|
+
*/
|
|
55
|
+
export const HTML_TO_NATIVE_TAG = {
|
|
56
|
+
div: 'ng-box',
|
|
57
|
+
section: 'ng-box',
|
|
58
|
+
main: 'ng-box',
|
|
59
|
+
article: 'ng-box',
|
|
60
|
+
aside: 'ng-box',
|
|
61
|
+
nav: 'ng-box',
|
|
62
|
+
header: 'ng-box',
|
|
63
|
+
footer: 'ng-box',
|
|
64
|
+
form: 'ng-box',
|
|
65
|
+
ul: 'ng-box',
|
|
66
|
+
ol: 'ng-box',
|
|
67
|
+
li: 'ng-box',
|
|
68
|
+
figure: 'ng-box',
|
|
69
|
+
figcaption: 'ng-box',
|
|
70
|
+
p: 'ng-label',
|
|
71
|
+
span: 'ng-label',
|
|
72
|
+
label: 'ng-label',
|
|
73
|
+
h1: 'ng-label',
|
|
74
|
+
h2: 'ng-label',
|
|
75
|
+
h3: 'ng-label',
|
|
76
|
+
h4: 'ng-label',
|
|
77
|
+
h5: 'ng-label',
|
|
78
|
+
h6: 'ng-label',
|
|
79
|
+
strong: 'ng-label',
|
|
80
|
+
em: 'ng-label',
|
|
81
|
+
small: 'ng-label',
|
|
82
|
+
code: 'ng-label',
|
|
83
|
+
pre: 'ng-label',
|
|
84
|
+
a: 'ng-label',
|
|
85
|
+
button: 'ng-button',
|
|
86
|
+
img: 'ng-image',
|
|
87
|
+
hr: 'ng-separator',
|
|
88
|
+
input: 'ng-entry',
|
|
89
|
+
textarea: 'ng-text-view',
|
|
90
|
+
select: 'ng-select',
|
|
91
|
+
progress: 'ng-progress-bar',
|
|
92
|
+
details: 'ng-expander',
|
|
93
|
+
dialog: 'ng-dialog',
|
|
94
|
+
table: 'ng-list',
|
|
95
|
+
menu: 'ng-popover',
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Resolves an Angular template element tag into a native desktop widget tag (`ng-*`, `gtk-*`,
|
|
99
|
+
* `adw-*`), returning `null` for virtual Angular hosts (`ng-container`, `router-outlet`, `app-*`).
|
|
100
|
+
*/
|
|
101
|
+
export function resolveNativeTag(tag) {
|
|
102
|
+
const lower = tag.trim().toLowerCase();
|
|
103
|
+
if (VIRTUAL_ANGULAR_TAGS.has(lower)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if (lower.startsWith('ng-') || lower.startsWith('adw-') || lower.startsWith('gtk-')) {
|
|
107
|
+
return lower;
|
|
108
|
+
}
|
|
109
|
+
return HTML_TO_NATIVE_TAG[lower] ?? null;
|
|
110
|
+
}
|
|
111
|
+
function isImageTag(tag) {
|
|
112
|
+
return tag === 'ng-image' || tag === 'adw-image' || tag === 'ng-picture' || tag === 'gtk-picture';
|
|
113
|
+
}
|
|
114
|
+
function parseHtmlBooleanFlag(value) {
|
|
115
|
+
if (value === undefined || value === null || value === false || value === 0) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (typeof value === 'string') {
|
|
119
|
+
const lower = value.trim().toLowerCase();
|
|
120
|
+
return lower !== 'false' && lower !== '0' && lower !== 'null' && lower !== 'undefined';
|
|
121
|
+
}
|
|
122
|
+
return Boolean(value);
|
|
123
|
+
}
|
|
124
|
+
function isInternalAngularAttr(name) {
|
|
125
|
+
return name.startsWith('_ngcontent-') || name.startsWith('_nghost-') || name === 'ng-version';
|
|
126
|
+
}
|
|
127
|
+
function mapNativeEventNames(eventName) {
|
|
128
|
+
switch (eventName) {
|
|
129
|
+
case 'click':
|
|
130
|
+
return ['clicked'];
|
|
131
|
+
case 'dblclick':
|
|
132
|
+
case 'doubleclick':
|
|
133
|
+
return ['dblclick'];
|
|
134
|
+
case 'contextmenu':
|
|
135
|
+
case 'rightclick':
|
|
136
|
+
return ['contextmenu'];
|
|
137
|
+
case 'mousedown':
|
|
138
|
+
case 'pointerdown':
|
|
139
|
+
return ['mousedown'];
|
|
140
|
+
case 'mouseup':
|
|
141
|
+
case 'pointerup':
|
|
142
|
+
return ['mouseup'];
|
|
143
|
+
case 'mouseenter':
|
|
144
|
+
case 'mouseover':
|
|
145
|
+
case 'pointerenter':
|
|
146
|
+
return ['mouseenter'];
|
|
147
|
+
case 'mouseleave':
|
|
148
|
+
case 'mouseout':
|
|
149
|
+
case 'pointerleave':
|
|
150
|
+
return ['mouseleave'];
|
|
151
|
+
case 'mousemove':
|
|
152
|
+
case 'pointermove':
|
|
153
|
+
return ['mousemove'];
|
|
154
|
+
case 'focus':
|
|
155
|
+
case 'focusin':
|
|
156
|
+
case 'windowFocus':
|
|
157
|
+
return ['focus'];
|
|
158
|
+
case 'blur':
|
|
159
|
+
case 'focusout':
|
|
160
|
+
case 'windowBlur':
|
|
161
|
+
return ['blur'];
|
|
162
|
+
case 'keydown':
|
|
163
|
+
return ['keydown'];
|
|
164
|
+
case 'keyup':
|
|
165
|
+
return ['keyup'];
|
|
166
|
+
case 'input':
|
|
167
|
+
return ['input'];
|
|
168
|
+
case 'change':
|
|
169
|
+
case 'valueChange':
|
|
170
|
+
return ['changed', 'value-changed', 'toggled'];
|
|
171
|
+
case 'submit':
|
|
172
|
+
case 'search':
|
|
173
|
+
case 'activate':
|
|
174
|
+
return ['activate'];
|
|
175
|
+
case 'cancel':
|
|
176
|
+
case 'escape':
|
|
177
|
+
case 'stopSearch':
|
|
178
|
+
return ['cancel'];
|
|
179
|
+
case 'scroll':
|
|
180
|
+
return ['scroll'];
|
|
181
|
+
case 'scrollEdge':
|
|
182
|
+
case 'scroll-edge':
|
|
183
|
+
return ['scroll-edge', 'edge-reached'];
|
|
184
|
+
case 'scrollBottom':
|
|
185
|
+
case 'scroll-bottom':
|
|
186
|
+
return ['scroll-bottom'];
|
|
187
|
+
case 'scrollTop':
|
|
188
|
+
case 'scroll-top':
|
|
189
|
+
return ['scroll-top'];
|
|
190
|
+
case 'wheel':
|
|
191
|
+
case 'mousewheel':
|
|
192
|
+
return ['wheel'];
|
|
193
|
+
case 'resize':
|
|
194
|
+
case 'windowResize':
|
|
195
|
+
case 'window-resize':
|
|
196
|
+
return ['resize'];
|
|
197
|
+
case 'maximize':
|
|
198
|
+
case 'windowMaximize':
|
|
199
|
+
return ['maximize'];
|
|
200
|
+
case 'closeRequest':
|
|
201
|
+
case 'close-request':
|
|
202
|
+
case 'beforeunload':
|
|
203
|
+
return ['close-request'];
|
|
204
|
+
case 'rowActivated':
|
|
205
|
+
case 'row-activated':
|
|
206
|
+
return ['row-activated'];
|
|
207
|
+
case 'closed':
|
|
208
|
+
case 'popoverClosed':
|
|
209
|
+
case 'close':
|
|
210
|
+
return ['closed'];
|
|
211
|
+
case 'dragenter':
|
|
212
|
+
return ['dragenter'];
|
|
213
|
+
case 'dragleave':
|
|
214
|
+
return ['dragleave'];
|
|
215
|
+
case 'drop':
|
|
216
|
+
return ['drop', 'files-dropped'];
|
|
217
|
+
default:
|
|
218
|
+
return [eventName];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function lazyControllerTokenFor(eventName) {
|
|
222
|
+
switch (eventName) {
|
|
223
|
+
case 'click':
|
|
224
|
+
case 'dblclick':
|
|
225
|
+
case 'doubleclick':
|
|
226
|
+
case 'mousedown':
|
|
227
|
+
case 'mouseup':
|
|
228
|
+
case 'pointerdown':
|
|
229
|
+
case 'pointerup':
|
|
230
|
+
return 'click';
|
|
231
|
+
case 'contextmenu':
|
|
232
|
+
case 'rightclick':
|
|
233
|
+
return 'contextmenu';
|
|
234
|
+
case 'mouseenter':
|
|
235
|
+
case 'mouseleave':
|
|
236
|
+
case 'mousemove':
|
|
237
|
+
case 'mouseover':
|
|
238
|
+
case 'mouseout':
|
|
239
|
+
case 'pointerenter':
|
|
240
|
+
case 'pointerleave':
|
|
241
|
+
case 'pointermove':
|
|
242
|
+
return 'motion';
|
|
243
|
+
case 'focus':
|
|
244
|
+
case 'blur':
|
|
245
|
+
case 'focusin':
|
|
246
|
+
case 'focusout':
|
|
247
|
+
return 'focus';
|
|
248
|
+
case 'keydown':
|
|
249
|
+
case 'keyup':
|
|
250
|
+
return 'keyboard';
|
|
251
|
+
case 'wheel':
|
|
252
|
+
case 'mousewheel':
|
|
253
|
+
return 'wheel';
|
|
254
|
+
case 'closeRequest':
|
|
255
|
+
case 'close-request':
|
|
256
|
+
case 'beforeunload':
|
|
257
|
+
return 'close-request';
|
|
258
|
+
default:
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function syncTargetFromPayload(target, parsed) {
|
|
263
|
+
if (!target) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (parsed['value'] !== undefined) {
|
|
267
|
+
target.value = String(parsed['value']);
|
|
268
|
+
}
|
|
269
|
+
if (typeof parsed['checked'] === 'boolean') {
|
|
270
|
+
target.checked = parsed['checked'];
|
|
271
|
+
}
|
|
272
|
+
else if (typeof parsed['active'] === 'boolean') {
|
|
273
|
+
target.checked = parsed['active'];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function normalizeNativeEventPayload(eventName, rawPayload, target) {
|
|
277
|
+
const tryParseJson = (raw) => {
|
|
278
|
+
if (typeof raw !== 'string')
|
|
279
|
+
return null;
|
|
280
|
+
const trimmed = raw.trim();
|
|
281
|
+
if (!trimmed.startsWith('{') || !trimmed.endsWith('}'))
|
|
282
|
+
return null;
|
|
283
|
+
try {
|
|
284
|
+
const parsed = JSON.parse(trimmed);
|
|
285
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
286
|
+
? parsed
|
|
287
|
+
: null;
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
let normalized;
|
|
294
|
+
if (typeof rawPayload === 'string') {
|
|
295
|
+
const parsed = tryParseJson(rawPayload);
|
|
296
|
+
normalized = parsed ? { type: eventName, ...parsed } : { type: eventName, value: rawPayload };
|
|
297
|
+
}
|
|
298
|
+
else if (typeof rawPayload === 'number' || typeof rawPayload === 'boolean') {
|
|
299
|
+
normalized = { type: eventName, value: rawPayload };
|
|
300
|
+
}
|
|
301
|
+
else if (rawPayload && typeof rawPayload === 'object' && !Array.isArray(rawPayload)) {
|
|
302
|
+
const obj = rawPayload;
|
|
303
|
+
const parsed = tryParseJson(obj['value']);
|
|
304
|
+
normalized = parsed ? { type: eventName, ...obj, ...parsed } : { type: eventName, ...obj };
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
normalized = { type: eventName };
|
|
308
|
+
}
|
|
309
|
+
syncTargetFromPayload(target, normalized);
|
|
310
|
+
if (target && normalized['target'] === undefined) {
|
|
311
|
+
normalized['target'] = target;
|
|
312
|
+
}
|
|
313
|
+
return normalized;
|
|
314
|
+
}
|
|
315
|
+
export class NativeRenderer2 extends Renderer2 {
|
|
316
|
+
data = Object.create(null);
|
|
317
|
+
destroyNode;
|
|
318
|
+
bridge;
|
|
319
|
+
nodesById;
|
|
320
|
+
nextId;
|
|
321
|
+
hooks;
|
|
322
|
+
materializedTextLabels = new Map();
|
|
323
|
+
imageLoadSeq = new WeakMap();
|
|
324
|
+
enabledEventTokens = new Map();
|
|
325
|
+
pendingVirtualListeners = new WeakMap();
|
|
326
|
+
constructor(bridge, nodesById, nextId, hooks) {
|
|
327
|
+
super();
|
|
328
|
+
this.bridge = bridge;
|
|
329
|
+
this.nodesById = nodesById;
|
|
330
|
+
this.nextId = nextId;
|
|
331
|
+
this.hooks = hooks;
|
|
332
|
+
this.destroyNode = (node) => {
|
|
333
|
+
if (node instanceof NativeElementNode) {
|
|
334
|
+
this.destroySubtreeNodes(node, true);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
destroySubtreeNodes(node, emitBridgeDestroy) {
|
|
339
|
+
for (const child of node.children) {
|
|
340
|
+
this.destroySubtreeNodes(child, emitBridgeDestroy && node.isVirtual);
|
|
341
|
+
}
|
|
342
|
+
this.nodesById.delete(node.id);
|
|
343
|
+
this.imageLoadSeq.delete(node);
|
|
344
|
+
this.enabledEventTokens.delete(node.id);
|
|
345
|
+
const pending = this.pendingVirtualListeners.get(node);
|
|
346
|
+
if (pending) {
|
|
347
|
+
for (const reg of pending) {
|
|
348
|
+
reg.disposed = true;
|
|
349
|
+
for (const unlisten of reg.activeUnsubs) {
|
|
350
|
+
unlisten();
|
|
351
|
+
}
|
|
352
|
+
reg.activeUnsubs.clear();
|
|
353
|
+
reg.attachedRealIds.clear();
|
|
354
|
+
}
|
|
355
|
+
this.pendingVirtualListeners.delete(node);
|
|
356
|
+
}
|
|
357
|
+
const materializedId = this.materializedTextLabels.get(node);
|
|
358
|
+
if (materializedId) {
|
|
359
|
+
this.materializedTextLabels.delete(node);
|
|
360
|
+
if (emitBridgeDestroy) {
|
|
361
|
+
this.bridge.destroyNode(materializedId);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (!node.isVirtual && emitBridgeDestroy) {
|
|
365
|
+
this.bridge.destroyNode(node.id);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
destroy() {
|
|
369
|
+
// Renderer lifecycle cleanup
|
|
370
|
+
}
|
|
371
|
+
createElement(name, _namespace) {
|
|
372
|
+
const id = this.nextId();
|
|
373
|
+
const trimmed = name.trim();
|
|
374
|
+
const resolvedTag = resolveNativeTag(trimmed);
|
|
375
|
+
const isNative = resolvedTag !== null;
|
|
376
|
+
const node = new NativeElementNode(id, resolvedTag ?? trimmed, false, !isNative, false);
|
|
377
|
+
this.nodesById.set(id, node);
|
|
378
|
+
if (resolvedTag !== null) {
|
|
379
|
+
this.hooks?.onRealElementCreated?.(resolvedTag, id);
|
|
380
|
+
this.bridge.createElement(id, resolvedTag);
|
|
381
|
+
if (resolvedTag === 'ng-window' || resolvedTag === 'adw-window') {
|
|
382
|
+
this.attachGlobalWindowIcon(id);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return node;
|
|
386
|
+
}
|
|
387
|
+
createComment(value) {
|
|
388
|
+
const id = this.nextId();
|
|
389
|
+
const cleanComment = value.trim() || 'anchor';
|
|
390
|
+
const node = new NativeElementNode(id, '#comment', true, false, false);
|
|
391
|
+
node.textContent = cleanComment;
|
|
392
|
+
this.nodesById.set(id, node);
|
|
393
|
+
this.bridge.createComment(id, cleanComment);
|
|
394
|
+
return node;
|
|
395
|
+
}
|
|
396
|
+
createText(value) {
|
|
397
|
+
const id = this.nextId();
|
|
398
|
+
const node = new NativeElementNode(id, '#text', false, true, true);
|
|
399
|
+
node.textContent = value;
|
|
400
|
+
this.nodesById.set(id, node);
|
|
401
|
+
return node;
|
|
402
|
+
}
|
|
403
|
+
appendChild(parent, newChild) {
|
|
404
|
+
if (!parent) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (newChild.parent) {
|
|
408
|
+
this.removeChild(newChild.parent, newChild);
|
|
409
|
+
}
|
|
410
|
+
newChild.parent = parent;
|
|
411
|
+
parent.children.push(newChild);
|
|
412
|
+
this.projectInsertion(parent, newChild, null, true);
|
|
413
|
+
}
|
|
414
|
+
insertBefore(parent, newChild, refChild, _isMove) {
|
|
415
|
+
if (!parent) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const prevParent = newChild.parent;
|
|
419
|
+
if (prevParent) {
|
|
420
|
+
const existingIdx = prevParent.children.indexOf(newChild);
|
|
421
|
+
if (existingIdx !== -1) {
|
|
422
|
+
prevParent.children.splice(existingIdx, 1);
|
|
423
|
+
}
|
|
424
|
+
const prevReal = this.findRealAncestor(prevParent);
|
|
425
|
+
const nextReal = this.findRealAncestor(parent);
|
|
426
|
+
if (prevParent !== parent && prevReal && prevReal !== nextReal && !newChild.isText) {
|
|
427
|
+
for (const realId of this.collectRealRootIds(newChild)) {
|
|
428
|
+
this.bridge.removeChild(prevReal.id, realId);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
newChild.parent = parent;
|
|
433
|
+
if (refChild) {
|
|
434
|
+
const refIdx = parent.children.indexOf(refChild);
|
|
435
|
+
if (refIdx !== -1) {
|
|
436
|
+
parent.children.splice(refIdx, 0, newChild);
|
|
437
|
+
this.projectInsertion(parent, newChild, refChild, false);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
parent.children.push(newChild);
|
|
442
|
+
this.projectInsertion(parent, newChild, null, false);
|
|
443
|
+
}
|
|
444
|
+
removeChild(parent, oldChild, _isHostElement) {
|
|
445
|
+
const targetParent = parent ?? oldChild.parent;
|
|
446
|
+
if (!targetParent) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const realParent = this.findRealAncestor(targetParent);
|
|
450
|
+
const materializedId = this.materializedTextLabels.get(oldChild);
|
|
451
|
+
const realIds = oldChild.isText ? [] : this.collectRealRootIds(oldChild);
|
|
452
|
+
const idx = targetParent.children.indexOf(oldChild);
|
|
453
|
+
if (idx !== -1) {
|
|
454
|
+
targetParent.children.splice(idx, 1);
|
|
455
|
+
}
|
|
456
|
+
oldChild.parent = null;
|
|
457
|
+
if (!realParent) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (oldChild.isText) {
|
|
461
|
+
if (materializedId) {
|
|
462
|
+
this.bridge.removeChild(realParent.id, materializedId);
|
|
463
|
+
}
|
|
464
|
+
else if (TEXT_BEARING_TAGS.has(realParent.tag)) {
|
|
465
|
+
this.syncTextBearingParent(realParent);
|
|
466
|
+
}
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
for (const realId of realIds) {
|
|
470
|
+
this.bridge.removeChild(realParent.id, realId);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
selectRootElement(selectorOrNode, _preserveContent) {
|
|
474
|
+
if (selectorOrNode instanceof NativeElementNode) {
|
|
475
|
+
return selectorOrNode;
|
|
476
|
+
}
|
|
477
|
+
const trimmed = selectorOrNode.trim();
|
|
478
|
+
const normalizedId = trimmed.replace(/^[#.]/, '') || 'ng_root';
|
|
479
|
+
const existing = this.nodesById.get(normalizedId);
|
|
480
|
+
if (existing) {
|
|
481
|
+
return existing;
|
|
482
|
+
}
|
|
483
|
+
const isRealWindow = trimmed.startsWith('#') || trimmed === 'ng-window' || trimmed === 'adw-window';
|
|
484
|
+
if (isRealWindow) {
|
|
485
|
+
const root = new NativeElementNode(normalizedId, 'ng-window', false, false, false);
|
|
486
|
+
this.nodesById.set(normalizedId, root);
|
|
487
|
+
this.hooks?.onRealElementCreated?.('ng-window', normalizedId);
|
|
488
|
+
this.bridge.createElement(normalizedId, 'ng-window');
|
|
489
|
+
this.attachGlobalWindowIcon(normalizedId);
|
|
490
|
+
return root;
|
|
491
|
+
}
|
|
492
|
+
const virtualRoot = new NativeElementNode(normalizedId, trimmed, false, true, false);
|
|
493
|
+
this.nodesById.set(normalizedId, virtualRoot);
|
|
494
|
+
return virtualRoot;
|
|
495
|
+
}
|
|
496
|
+
parentNode(node) {
|
|
497
|
+
return node.parent;
|
|
498
|
+
}
|
|
499
|
+
nextSibling(node) {
|
|
500
|
+
return node.nextSibling;
|
|
501
|
+
}
|
|
502
|
+
setAttribute(el, name, value, _namespace) {
|
|
503
|
+
if (isInternalAngularAttr(name)) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
el.attributes.set(name, value);
|
|
507
|
+
if (name === 'class' || name === 'className') {
|
|
508
|
+
this.syncClassList(el, value);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (el.isVirtual) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (name === 'disabled') {
|
|
515
|
+
const nextSensitive = parseHtmlBooleanFlag(value) ? 'false' : 'true';
|
|
516
|
+
el.attributes.set('sensitive', nextSensitive);
|
|
517
|
+
this.bridge.setAttribute(el.id, 'sensitive', nextSensitive);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (isImageTag(el.tag) && (name === 'src' || name === 'ngSrc')) {
|
|
521
|
+
this.handleImageSource(el, value);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
if (name === 'title' &&
|
|
525
|
+
(el.tag === 'ng-window' ||
|
|
526
|
+
el.tag === 'adw-window' ||
|
|
527
|
+
el.tag === 'ng-dialog' ||
|
|
528
|
+
el.tag === 'gtk-dialog' ||
|
|
529
|
+
el.tag === 'adw-dialog' ||
|
|
530
|
+
el.tag === 'ng-header-bar' ||
|
|
531
|
+
el.tag === 'adw-header-bar')) {
|
|
532
|
+
this.bridge.setText(el.id, value);
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
this.bridge.setAttribute(el.id, name, value);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
removeAttribute(el, name, _namespace) {
|
|
539
|
+
el.attributes.delete(name);
|
|
540
|
+
if (isInternalAngularAttr(name) || el.isVirtual) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (name === 'class' || name === 'className') {
|
|
544
|
+
const classesToRemove = [];
|
|
545
|
+
for (const cls of el.classes) {
|
|
546
|
+
classesToRemove.push(cls);
|
|
547
|
+
}
|
|
548
|
+
for (const cls of classesToRemove) {
|
|
549
|
+
this.removeClass(el, cls);
|
|
550
|
+
}
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (name === 'disabled') {
|
|
554
|
+
el.attributes.set('sensitive', 'true');
|
|
555
|
+
this.bridge.setAttribute(el.id, 'sensitive', 'true');
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
this.bridge.setAttribute(el.id, name, '');
|
|
559
|
+
}
|
|
560
|
+
addClass(el, name) {
|
|
561
|
+
el.classes.add(name);
|
|
562
|
+
if (!el.isVirtual) {
|
|
563
|
+
this.bridge.addClass(el.id, name);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
removeClass(el, name) {
|
|
567
|
+
el.classes.delete(name);
|
|
568
|
+
if (!el.isVirtual) {
|
|
569
|
+
this.bridge.removeClass(el.id, name);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
setStyle(el, style, value, _flags) {
|
|
573
|
+
if (value === null || value === undefined || value === false) {
|
|
574
|
+
this.removeStyle(el, style, _flags);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const strVal = String(value);
|
|
578
|
+
el.styles.set(style, strVal);
|
|
579
|
+
if (el.isVirtual) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const key = style.trim().toLowerCase();
|
|
583
|
+
const trimmed = strVal.trim();
|
|
584
|
+
if (key === 'flex' || key === 'flex-grow') {
|
|
585
|
+
const grow = Number.parseFloat(trimmed);
|
|
586
|
+
if (Number.isFinite(grow) && grow >= 1) {
|
|
587
|
+
this.bridge.setAttribute(el.id, 'hexpand', 'true');
|
|
588
|
+
}
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (key === 'flex-direction') {
|
|
592
|
+
this.bridge.setAttribute(el.id, 'orientation', trimmed.toLowerCase().startsWith('row') ? 'horizontal' : 'vertical');
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (key === 'gap' || key === 'row-gap' || key === 'column-gap') {
|
|
596
|
+
this.bridge.setAttribute(el.id, key === 'gap' ? 'spacing' : key.replace('-gap', '-spacing'), trimmed);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (key === 'width' && trimmed === '100%') {
|
|
600
|
+
this.bridge.setAttribute(el.id, 'hexpand', 'true');
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (key === 'height' && trimmed === '100%') {
|
|
604
|
+
this.bridge.setAttribute(el.id, 'vexpand', 'true');
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (key === 'justify-self') {
|
|
608
|
+
const aligned = mapAlignKeyword(trimmed);
|
|
609
|
+
if (aligned)
|
|
610
|
+
this.bridge.setAttribute(el.id, 'halign', aligned);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (key === 'align-self') {
|
|
614
|
+
const aligned = mapAlignKeyword(trimmed);
|
|
615
|
+
if (aligned)
|
|
616
|
+
this.bridge.setAttribute(el.id, 'valign', aligned);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
if (key === 'margin-left') {
|
|
620
|
+
this.bridge.setAttribute(el.id, 'margin-start', trimmed);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (key === 'margin-right') {
|
|
624
|
+
this.bridge.setAttribute(el.id, 'margin-end', trimmed);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
this.bridge.setAttribute(el.id, style, strVal);
|
|
628
|
+
}
|
|
629
|
+
removeStyle(el, style, _flags) {
|
|
630
|
+
el.styles.delete(style);
|
|
631
|
+
if (!el.isVirtual) {
|
|
632
|
+
this.bridge.setAttribute(el.id, style, '');
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
setProperty(el, name, value) {
|
|
636
|
+
if (isInternalAngularAttr(name)) {
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
const strVal = String(value ?? '');
|
|
640
|
+
if (name === 'className') {
|
|
641
|
+
this.syncClassList(el, strVal);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (el.isVirtual) {
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
if (name === 'disabled') {
|
|
648
|
+
const nextSensitive = parseHtmlBooleanFlag(value) ? 'false' : 'true';
|
|
649
|
+
el.attributes.set('sensitive', nextSensitive);
|
|
650
|
+
this.bridge.setAttribute(el.id, 'sensitive', nextSensitive);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (name === 'hidden') {
|
|
654
|
+
const nextVisible = parseHtmlBooleanFlag(value) ? 'false' : 'true';
|
|
655
|
+
el.attributes.set('visible', nextVisible);
|
|
656
|
+
this.bridge.setAttribute(el.id, 'visible', nextVisible);
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (name === 'checked') {
|
|
660
|
+
const checked = parseHtmlBooleanFlag(value);
|
|
661
|
+
el.checked = checked;
|
|
662
|
+
this.bridge.setAttribute(el.id, 'active', checked ? 'true' : 'false');
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (name === 'value' && TEXT_INPUT_TAGS.has(el.tag)) {
|
|
666
|
+
el.value = strVal;
|
|
667
|
+
this.bridge.setAttribute(el.id, 'value', strVal);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (isImageTag(el.tag) && (name === 'src' || name === 'ngSrc')) {
|
|
671
|
+
el.attributes.set(name, strVal);
|
|
672
|
+
this.handleImageSource(el, strVal);
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
if (name === 'textContent' ||
|
|
676
|
+
name === 'innerText' ||
|
|
677
|
+
name === 'label' ||
|
|
678
|
+
(name === 'text' && TEXT_BEARING_TAGS.has(el.tag)) ||
|
|
679
|
+
(name === 'title' &&
|
|
680
|
+
(el.tag === 'ng-window' ||
|
|
681
|
+
el.tag === 'adw-window' ||
|
|
682
|
+
el.tag === 'ng-dialog' ||
|
|
683
|
+
el.tag === 'gtk-dialog' ||
|
|
684
|
+
el.tag === 'adw-dialog' ||
|
|
685
|
+
el.tag === 'ng-header-bar' ||
|
|
686
|
+
el.tag === 'adw-header-bar'))) {
|
|
687
|
+
el.attributes.set(name, strVal);
|
|
688
|
+
el.textContent = strVal;
|
|
689
|
+
this.bridge.setText(el.id, strVal);
|
|
690
|
+
}
|
|
691
|
+
else {
|
|
692
|
+
el.attributes.set(name, strVal);
|
|
693
|
+
this.bridge.setAttribute(el.id, name, strVal);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
setValue(node, value) {
|
|
697
|
+
node.textContent = value;
|
|
698
|
+
if (node.isText) {
|
|
699
|
+
const realParent = this.findRealAncestor(node.parent);
|
|
700
|
+
if (!realParent) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
if (TEXT_BEARING_TAGS.has(realParent.tag)) {
|
|
704
|
+
this.syncTextBearingParent(realParent);
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
const existingMat = this.materializedTextLabels.get(node);
|
|
708
|
+
if (existingMat) {
|
|
709
|
+
this.bridge.setText(existingMat, value);
|
|
710
|
+
}
|
|
711
|
+
else if (value.trim().length > 0 && node.parent) {
|
|
712
|
+
this.materializeTextIntoContainer(node.parent, realParent, node, null, false);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
this.bridge.setText(node.id, value);
|
|
718
|
+
}
|
|
719
|
+
ensureLazyEventController(nodeId, tag, eventName) {
|
|
720
|
+
const token = lazyControllerTokenFor(eventName);
|
|
721
|
+
if (!token) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
const lowerTag = tag.trim().toLowerCase();
|
|
725
|
+
if ((lowerTag === 'ng-button' || lowerTag === 'gtk-button') && eventName === 'click') {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
let active = this.enabledEventTokens.get(nodeId);
|
|
729
|
+
if (!active) {
|
|
730
|
+
active = new Set();
|
|
731
|
+
this.enabledEventTokens.set(nodeId, active);
|
|
732
|
+
}
|
|
733
|
+
if (active.has(token)) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
active.add(token);
|
|
737
|
+
this.bridge.setAttribute(nodeId, 'event-mask', [...active].join(','));
|
|
738
|
+
}
|
|
739
|
+
listen(target, eventName, callback) {
|
|
740
|
+
const nativeEvents = mapNativeEventNames(eventName);
|
|
741
|
+
if (typeof target === 'string') {
|
|
742
|
+
const nodeId = target === 'window' || target === 'document' || target === 'body'
|
|
743
|
+
? (this.hooks?.getPrimaryWindowId?.() ?? 'win')
|
|
744
|
+
: target;
|
|
745
|
+
const isWindowGlobal = target === 'window' || target === 'document' || target === 'body';
|
|
746
|
+
if (!isWindowGlobal ||
|
|
747
|
+
(eventName !== 'focus' &&
|
|
748
|
+
eventName !== 'blur' &&
|
|
749
|
+
eventName !== 'windowFocus' &&
|
|
750
|
+
eventName !== 'windowBlur')) {
|
|
751
|
+
this.ensureLazyEventController(nodeId, 'ng-window', eventName);
|
|
752
|
+
}
|
|
753
|
+
const unsubs = nativeEvents.map((nativeEvent) => this.bridge.listen(nodeId, nativeEvent, (evt) => {
|
|
754
|
+
callback(normalizeNativeEventPayload(eventName, evt));
|
|
755
|
+
}));
|
|
756
|
+
return () => {
|
|
757
|
+
for (const unlisten of unsubs) {
|
|
758
|
+
unlisten();
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
if (target.isVirtual) {
|
|
763
|
+
const reg = {
|
|
764
|
+
nativeEvents,
|
|
765
|
+
eventName,
|
|
766
|
+
callback,
|
|
767
|
+
attachedRealIds: new Set(),
|
|
768
|
+
activeUnsubs: new Set(),
|
|
769
|
+
disposed: false,
|
|
770
|
+
};
|
|
771
|
+
let pendingSet = this.pendingVirtualListeners.get(target);
|
|
772
|
+
if (!pendingSet) {
|
|
773
|
+
pendingSet = new Set();
|
|
774
|
+
this.pendingVirtualListeners.set(target, pendingSet);
|
|
775
|
+
}
|
|
776
|
+
pendingSet.add(reg);
|
|
777
|
+
const currentRootIds = this.collectRealRootIds(target);
|
|
778
|
+
if (currentRootIds.length > 0) {
|
|
779
|
+
this.attachRegistrationToRealIds(reg, currentRootIds);
|
|
780
|
+
}
|
|
781
|
+
return () => {
|
|
782
|
+
reg.disposed = true;
|
|
783
|
+
pendingSet.delete(reg);
|
|
784
|
+
for (const unlisten of reg.activeUnsubs) {
|
|
785
|
+
unlisten();
|
|
786
|
+
}
|
|
787
|
+
reg.activeUnsubs.clear();
|
|
788
|
+
reg.attachedRealIds.clear();
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
this.ensureLazyEventController(target.id, target.tag, eventName);
|
|
792
|
+
const unsubs = nativeEvents.map((nativeEvent) => this.bridge.listen(target.id, nativeEvent, (evt) => {
|
|
793
|
+
callback(normalizeNativeEventPayload(eventName, evt, target));
|
|
794
|
+
}));
|
|
795
|
+
return () => {
|
|
796
|
+
for (const unlisten of unsubs) {
|
|
797
|
+
unlisten();
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
attachRegistrationToRealIds(reg, realIds) {
|
|
802
|
+
if (reg.disposed) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
for (const realId of realIds) {
|
|
806
|
+
if (reg.attachedRealIds.has(realId)) {
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
reg.attachedRealIds.add(realId);
|
|
810
|
+
const realNode = this.nodesById.get(realId);
|
|
811
|
+
const realTag = realNode?.tag ?? '';
|
|
812
|
+
this.ensureLazyEventController(realId, realTag, reg.eventName);
|
|
813
|
+
for (const nativeEvent of reg.nativeEvents) {
|
|
814
|
+
const unlisten = this.bridge.listen(realId, nativeEvent, (evt) => {
|
|
815
|
+
reg.callback(normalizeNativeEventPayload(reg.eventName, evt, realNode));
|
|
816
|
+
});
|
|
817
|
+
reg.activeUnsubs.add(unlisten);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
attachVirtualListenersForAncestors(startParent, realIds) {
|
|
822
|
+
let ancestor = startParent;
|
|
823
|
+
while (ancestor) {
|
|
824
|
+
if (ancestor.isVirtual) {
|
|
825
|
+
const regs = this.pendingVirtualListeners.get(ancestor);
|
|
826
|
+
if (regs) {
|
|
827
|
+
for (const reg of regs) {
|
|
828
|
+
this.attachRegistrationToRealIds(reg, realIds);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
ancestor = ancestor.parent;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
attachGlobalWindowIcon(windowId) {
|
|
836
|
+
const iconMeta = globalThis
|
|
837
|
+
.__NG_DESKTOP_ICON__;
|
|
838
|
+
if (iconMeta?.appId && iconMeta.relPath) {
|
|
839
|
+
this.bridge.setWindowIcon(windowId, iconMeta.appId, iconMeta.relPath);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
syncClassList(el, rawClasses) {
|
|
843
|
+
const nextClasses = new Set(rawClasses
|
|
844
|
+
.split(/\s+/)
|
|
845
|
+
.map((c) => c.trim())
|
|
846
|
+
.filter(Boolean));
|
|
847
|
+
const toRemove = [];
|
|
848
|
+
for (const existing of el.classes) {
|
|
849
|
+
if (!nextClasses.has(existing)) {
|
|
850
|
+
toRemove.push(existing);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
for (const existing of toRemove) {
|
|
854
|
+
this.removeClass(el, existing);
|
|
855
|
+
}
|
|
856
|
+
for (const added of nextClasses) {
|
|
857
|
+
if (!el.classes.has(added)) {
|
|
858
|
+
this.addClass(el, added);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
handleImageSource(el, src) {
|
|
863
|
+
const seq = (this.imageLoadSeq.get(el) ?? 0) + 1;
|
|
864
|
+
this.imageLoadSeq.set(el, seq);
|
|
865
|
+
if (src.startsWith('http://') || src.startsWith('https://')) {
|
|
866
|
+
if (typeof this.bridge.downloadImageAsync === 'function') {
|
|
867
|
+
void this.bridge.downloadImageAsync(src).then((res) => {
|
|
868
|
+
if (this.imageLoadSeq.get(el) === seq &&
|
|
869
|
+
res?.ok &&
|
|
870
|
+
res.path &&
|
|
871
|
+
this.nodesById.has(el.id)) {
|
|
872
|
+
this.bridge.setText(el.id, res.path);
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
else {
|
|
877
|
+
this.bridge.setText(el.id, this.bridge.resolveImageAsset(src));
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
this.bridge.setText(el.id, src);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
findRealAncestor(node) {
|
|
885
|
+
let cur = node;
|
|
886
|
+
while (cur) {
|
|
887
|
+
if (!cur.isVirtual && !cur.isText) {
|
|
888
|
+
return cur;
|
|
889
|
+
}
|
|
890
|
+
cur = cur.parent;
|
|
891
|
+
}
|
|
892
|
+
return null;
|
|
893
|
+
}
|
|
894
|
+
collectRealRootIds(node, out = []) {
|
|
895
|
+
if (!node.isVirtual && !node.isText) {
|
|
896
|
+
out.push(node.id);
|
|
897
|
+
return out;
|
|
898
|
+
}
|
|
899
|
+
if (node.isText) {
|
|
900
|
+
const matId = this.materializedTextLabels.get(node);
|
|
901
|
+
if (matId) {
|
|
902
|
+
out.push(matId);
|
|
903
|
+
}
|
|
904
|
+
return out;
|
|
905
|
+
}
|
|
906
|
+
for (const child of node.children) {
|
|
907
|
+
this.collectRealRootIds(child, out);
|
|
908
|
+
}
|
|
909
|
+
return out;
|
|
910
|
+
}
|
|
911
|
+
findFirstRealId(node) {
|
|
912
|
+
if (!node.isVirtual && !node.isText) {
|
|
913
|
+
return node.id;
|
|
914
|
+
}
|
|
915
|
+
if (node.isText) {
|
|
916
|
+
return this.materializedTextLabels.get(node) ?? null;
|
|
917
|
+
}
|
|
918
|
+
for (const child of node.children) {
|
|
919
|
+
const found = this.findFirstRealId(child);
|
|
920
|
+
if (found) {
|
|
921
|
+
return found;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return null;
|
|
925
|
+
}
|
|
926
|
+
findNextRealSiblingId(targetNode, realParent) {
|
|
927
|
+
let cur = targetNode;
|
|
928
|
+
while (cur && cur !== realParent) {
|
|
929
|
+
const parent = cur.parent;
|
|
930
|
+
if (!parent) {
|
|
931
|
+
break;
|
|
932
|
+
}
|
|
933
|
+
const siblings = parent.children;
|
|
934
|
+
const idx = siblings.indexOf(cur);
|
|
935
|
+
if (idx !== -1) {
|
|
936
|
+
for (let i = idx + 1; i < siblings.length; i += 1) {
|
|
937
|
+
const sibling = siblings[i];
|
|
938
|
+
if (sibling) {
|
|
939
|
+
const firstId = this.findFirstRealId(sibling);
|
|
940
|
+
if (firstId) {
|
|
941
|
+
return firstId;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
cur = parent;
|
|
947
|
+
}
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
collectTextContent(node) {
|
|
951
|
+
let out = '';
|
|
952
|
+
for (const child of node.children) {
|
|
953
|
+
if (child.isText) {
|
|
954
|
+
out += child.textContent;
|
|
955
|
+
}
|
|
956
|
+
else if (child.isVirtual) {
|
|
957
|
+
out += this.collectTextContent(child);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return out;
|
|
961
|
+
}
|
|
962
|
+
syncTextBearingParent(realParent) {
|
|
963
|
+
const text = this.collectTextContent(realParent);
|
|
964
|
+
this.bridge.setText(realParent.id, text);
|
|
965
|
+
}
|
|
966
|
+
materializeTextIntoContainer(logicalParent, realParent, textNode, refChild, isAppend) {
|
|
967
|
+
let labelId = this.materializedTextLabels.get(textNode);
|
|
968
|
+
const createdNow = !labelId;
|
|
969
|
+
if (!labelId) {
|
|
970
|
+
labelId = this.nextId();
|
|
971
|
+
this.materializedTextLabels.set(textNode, labelId);
|
|
972
|
+
this.bridge.createElement(labelId, 'ng-label');
|
|
973
|
+
}
|
|
974
|
+
this.bridge.setText(labelId, textNode.textContent);
|
|
975
|
+
const nextRealId = refChild || logicalParent !== realParent
|
|
976
|
+
? this.findNextRealSiblingId(textNode, realParent)
|
|
977
|
+
: null;
|
|
978
|
+
if (nextRealId) {
|
|
979
|
+
this.bridge.insertBefore(realParent.id, labelId, nextRealId);
|
|
980
|
+
}
|
|
981
|
+
else if (isAppend) {
|
|
982
|
+
this.bridge.appendChild(realParent.id, labelId);
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
this.bridge.insertBefore(realParent.id, labelId);
|
|
986
|
+
}
|
|
987
|
+
if (createdNow) {
|
|
988
|
+
this.attachVirtualListenersForAncestors(logicalParent, [labelId]);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
projectInsertion(parent, newChild, refChild, isAppend) {
|
|
992
|
+
let realRootIds = [];
|
|
993
|
+
if (!newChild.isText) {
|
|
994
|
+
realRootIds = this.collectRealRootIds(newChild);
|
|
995
|
+
if (realRootIds.length > 0) {
|
|
996
|
+
this.attachVirtualListenersForAncestors(parent, realRootIds);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const realParent = this.findRealAncestor(parent);
|
|
1000
|
+
if (!realParent) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
if (newChild.isText) {
|
|
1004
|
+
if (TEXT_BEARING_TAGS.has(realParent.tag)) {
|
|
1005
|
+
this.syncTextBearingParent(realParent);
|
|
1006
|
+
}
|
|
1007
|
+
else if (newChild.textContent.trim().length > 0) {
|
|
1008
|
+
this.materializeTextIntoContainer(parent, realParent, newChild, refChild, isAppend);
|
|
1009
|
+
}
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
if (realRootIds.length === 0) {
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
const nextRealId = refChild || parent !== realParent ? this.findNextRealSiblingId(newChild, realParent) : null;
|
|
1016
|
+
for (const realId of realRootIds) {
|
|
1017
|
+
if (nextRealId) {
|
|
1018
|
+
this.bridge.insertBefore(realParent.id, realId, nextRealId);
|
|
1019
|
+
}
|
|
1020
|
+
else if (isAppend) {
|
|
1021
|
+
this.bridge.appendChild(realParent.id, realId);
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
this.bridge.insertBefore(realParent.id, realId);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
export class NativeRendererFactory2 {
|
|
1030
|
+
bridge;
|
|
1031
|
+
nodesById = new Map();
|
|
1032
|
+
defaultRenderer;
|
|
1033
|
+
registeredTypeIds = new Set();
|
|
1034
|
+
nodeCounter = 1;
|
|
1035
|
+
primaryWindowId = null;
|
|
1036
|
+
primaryScrollId = null;
|
|
1037
|
+
constructor() {
|
|
1038
|
+
this.bridge = ensureNgNativeBridge();
|
|
1039
|
+
this.defaultRenderer = new NativeRenderer2(this.bridge, this.nodesById, () => `ng_node_${this.nodeCounter++}`, {
|
|
1040
|
+
onRealElementCreated: (tag, id) => {
|
|
1041
|
+
if (tag === 'ng-window' || tag === 'adw-window') {
|
|
1042
|
+
if (!this.primaryWindowId || !this.nodesById.has(this.primaryWindowId)) {
|
|
1043
|
+
this.primaryWindowId = id;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
else if (tag === 'ng-scroll' || tag === 'adw-scroll') {
|
|
1047
|
+
if (!this.primaryScrollId || !this.nodesById.has(this.primaryScrollId)) {
|
|
1048
|
+
this.primaryScrollId = id;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
getPrimaryWindowId: () => this.getPrimaryWindowId(),
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
createRenderer(_hostElement, type) {
|
|
1056
|
+
if (type?.styles?.length) {
|
|
1057
|
+
const typeKey = type.id || '__anonymous__';
|
|
1058
|
+
if (!this.registeredTypeIds.has(typeKey)) {
|
|
1059
|
+
this.registeredTypeIds.add(typeKey);
|
|
1060
|
+
registerParsedStyles(this.bridge, type.styles);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return this.defaultRenderer;
|
|
1064
|
+
}
|
|
1065
|
+
begin() {
|
|
1066
|
+
this.bridge.beginBatch?.();
|
|
1067
|
+
}
|
|
1068
|
+
end() {
|
|
1069
|
+
this.bridge.endBatch?.();
|
|
1070
|
+
}
|
|
1071
|
+
getPrimaryWindowId() {
|
|
1072
|
+
if (this.primaryWindowId && this.nodesById.has(this.primaryWindowId)) {
|
|
1073
|
+
return this.primaryWindowId;
|
|
1074
|
+
}
|
|
1075
|
+
for (const node of this.nodesById.values()) {
|
|
1076
|
+
if (!node.isVirtual && (node.tag === 'ng-window' || node.tag === 'adw-window')) {
|
|
1077
|
+
this.primaryWindowId = node.id;
|
|
1078
|
+
return node.id;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
this.primaryWindowId = null;
|
|
1082
|
+
return null;
|
|
1083
|
+
}
|
|
1084
|
+
getPrimaryScrollId() {
|
|
1085
|
+
if (this.primaryScrollId && this.nodesById.has(this.primaryScrollId)) {
|
|
1086
|
+
return this.primaryScrollId;
|
|
1087
|
+
}
|
|
1088
|
+
for (const node of this.nodesById.values()) {
|
|
1089
|
+
if (!node.isVirtual && (node.tag === 'ng-scroll' || node.tag === 'adw-scroll')) {
|
|
1090
|
+
this.primaryScrollId = node.id;
|
|
1091
|
+
return node.id;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
this.primaryScrollId = null;
|
|
1095
|
+
return null;
|
|
1096
|
+
}
|
|
1097
|
+
getNode(id) {
|
|
1098
|
+
return this.nodesById.get(id);
|
|
1099
|
+
}
|
|
1100
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeRendererFactory2, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1101
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeRendererFactory2, providedIn: 'root' });
|
|
1102
|
+
}
|
|
1103
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeRendererFactory2, decorators: [{
|
|
1104
|
+
type: Injectable,
|
|
1105
|
+
args: [{ providedIn: 'root' }]
|
|
1106
|
+
}], ctorParameters: () => [] });
|