@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.
@@ -0,0 +1,73 @@
1
+ export interface NativeDomRect {
2
+ readonly x: number;
3
+ readonly y: number;
4
+ readonly width: number;
5
+ readonly height: number;
6
+ readonly top: number;
7
+ readonly left: number;
8
+ readonly right: number;
9
+ readonly bottom: number;
10
+ }
11
+ export interface NativeElementEvent {
12
+ readonly type: string;
13
+ readonly target?: NativeElementNode;
14
+ readonly detail?: unknown;
15
+ }
16
+ export type NativeEventListener = (event: NativeElementEvent) => void;
17
+ /** Returns the currently focused `NativeElementNode`, mirroring `document.activeElement`. */
18
+ export declare function getNativeActiveElement(): NativeElementNode | null;
19
+ /** Programmatically updates the active `NativeElementNode` for headless ARIA focus tracking. */
20
+ export declare function setNativeActiveElement(node: NativeElementNode | null): void;
21
+ /**
22
+ * Lightweight scene-graph proxy node used by `NativeRenderer2` and headless ARIA/CDK utilities.
23
+ * Supports synchronous tree traversal, WAI-ARIA attribute reflection, focus state, `classList`,
24
+ * and DOM-compatible event dispatch without crossing FFI.
25
+ */
26
+ export declare class NativeElementNode {
27
+ readonly id: string;
28
+ readonly tag: string;
29
+ readonly isComment: boolean;
30
+ readonly isVirtual: boolean;
31
+ readonly isText: boolean;
32
+ parent: NativeElementNode | null;
33
+ readonly children: NativeElementNode[];
34
+ readonly attributes: Map<string, string>;
35
+ readonly classes: Set<string>;
36
+ readonly styles: Map<string, string>;
37
+ private readonly listeners;
38
+ textContent: string;
39
+ readonly classList: {
40
+ add: (...tokens: string[]) => void;
41
+ remove: (...tokens: string[]) => void;
42
+ toggle: (token: string, force?: boolean) => boolean;
43
+ contains: (token: string) => boolean;
44
+ };
45
+ constructor(id: string, tag: string, isComment?: boolean, isVirtual?: boolean, isText?: boolean);
46
+ get tagName(): string;
47
+ get nodeName(): string;
48
+ get parentNode(): NativeElementNode | null;
49
+ get firstChild(): NativeElementNode | null;
50
+ get lastChild(): NativeElementNode | null;
51
+ get previousSibling(): NativeElementNode | null;
52
+ get nextSibling(): NativeElementNode | null;
53
+ get childNodes(): readonly NativeElementNode[];
54
+ get tabIndex(): number;
55
+ set tabIndex(value: number);
56
+ get role(): string | null;
57
+ set role(value: string | null);
58
+ get value(): string;
59
+ set value(val: string);
60
+ get checked(): boolean;
61
+ set checked(val: boolean);
62
+ getAttribute(name: string): string | null;
63
+ setAttribute(name: string, value: string): void;
64
+ removeAttribute(name: string): void;
65
+ hasAttribute(name: string): boolean;
66
+ focus(): void;
67
+ blur(): void;
68
+ contains(other: NativeElementNode | null): boolean;
69
+ addEventListener(type: string, listener: NativeEventListener): void;
70
+ removeEventListener(type: string, listener: NativeEventListener): void;
71
+ dispatchEvent(event: NativeElementEvent | string): boolean;
72
+ getBoundingClientRect(): NativeDomRect;
73
+ }
@@ -0,0 +1,212 @@
1
+ let activeNativeElement = null;
2
+ /** Returns the currently focused `NativeElementNode`, mirroring `document.activeElement`. */
3
+ export function getNativeActiveElement() {
4
+ return activeNativeElement;
5
+ }
6
+ /** Programmatically updates the active `NativeElementNode` for headless ARIA focus tracking. */
7
+ export function setNativeActiveElement(node) {
8
+ activeNativeElement = node;
9
+ }
10
+ /**
11
+ * Lightweight scene-graph proxy node used by `NativeRenderer2` and headless ARIA/CDK utilities.
12
+ * Supports synchronous tree traversal, WAI-ARIA attribute reflection, focus state, `classList`,
13
+ * and DOM-compatible event dispatch without crossing FFI.
14
+ */
15
+ export class NativeElementNode {
16
+ id;
17
+ tag;
18
+ isComment;
19
+ isVirtual;
20
+ isText;
21
+ parent = null;
22
+ children = [];
23
+ attributes = new Map();
24
+ classes = new Set();
25
+ styles = new Map();
26
+ listeners = new Map();
27
+ textContent = '';
28
+ classList;
29
+ constructor(id, tag, isComment = false, isVirtual = false, isText = false) {
30
+ this.id = id;
31
+ this.tag = tag;
32
+ this.isComment = isComment;
33
+ this.isVirtual = isVirtual;
34
+ this.isText = isText;
35
+ this.classList = {
36
+ add: (...tokens) => {
37
+ for (const token of tokens) {
38
+ if (token.trim()) {
39
+ this.classes.add(token.trim());
40
+ }
41
+ }
42
+ },
43
+ remove: (...tokens) => {
44
+ for (const token of tokens) {
45
+ this.classes.delete(token);
46
+ }
47
+ },
48
+ toggle: (token, force) => {
49
+ const shouldAdd = force ?? !this.classes.has(token);
50
+ if (shouldAdd) {
51
+ this.classes.add(token);
52
+ }
53
+ else {
54
+ this.classes.delete(token);
55
+ }
56
+ return shouldAdd;
57
+ },
58
+ contains: (token) => this.classes.has(token),
59
+ };
60
+ }
61
+ get tagName() {
62
+ return this.tag.toUpperCase();
63
+ }
64
+ get nodeName() {
65
+ return this.isComment ? '#comment' : this.tag.toUpperCase();
66
+ }
67
+ get parentNode() {
68
+ return this.parent;
69
+ }
70
+ get firstChild() {
71
+ return this.children[0] ?? null;
72
+ }
73
+ get lastChild() {
74
+ return this.children.length > 0 ? (this.children[this.children.length - 1] ?? null) : null;
75
+ }
76
+ get previousSibling() {
77
+ if (!this.parent) {
78
+ return null;
79
+ }
80
+ const idx = this.parent.children.indexOf(this);
81
+ if (idx <= 0) {
82
+ return null;
83
+ }
84
+ return this.parent.children[idx - 1] ?? null;
85
+ }
86
+ get nextSibling() {
87
+ if (!this.parent) {
88
+ return null;
89
+ }
90
+ const idx = this.parent.children.indexOf(this);
91
+ if (idx === -1 || idx + 1 >= this.parent.children.length) {
92
+ return null;
93
+ }
94
+ return this.parent.children[idx + 1] ?? null;
95
+ }
96
+ get childNodes() {
97
+ return this.children;
98
+ }
99
+ get tabIndex() {
100
+ const raw = this.attributes.get('tabindex');
101
+ if (raw === undefined) {
102
+ return -1;
103
+ }
104
+ const parsed = Number.parseInt(raw, 10);
105
+ return Number.isNaN(parsed) ? -1 : parsed;
106
+ }
107
+ set tabIndex(value) {
108
+ this.attributes.set('tabindex', String(value));
109
+ }
110
+ get role() {
111
+ return this.attributes.get('role') ?? null;
112
+ }
113
+ set role(value) {
114
+ if (value === null) {
115
+ this.attributes.delete('role');
116
+ }
117
+ else {
118
+ this.attributes.set('role', value);
119
+ }
120
+ }
121
+ get value() {
122
+ return this.attributes.get('value') ?? this.textContent;
123
+ }
124
+ set value(val) {
125
+ const normalized = String(val ?? '');
126
+ this.textContent = normalized;
127
+ this.attributes.set('value', normalized);
128
+ }
129
+ get checked() {
130
+ return this.attributes.get('active') === 'true' || this.attributes.get('checked') === 'true';
131
+ }
132
+ set checked(val) {
133
+ const strVal = val ? 'true' : 'false';
134
+ this.attributes.set('active', strVal);
135
+ this.attributes.set('checked', strVal);
136
+ }
137
+ getAttribute(name) {
138
+ return this.attributes.get(name) ?? null;
139
+ }
140
+ setAttribute(name, value) {
141
+ this.attributes.set(name, String(value));
142
+ }
143
+ removeAttribute(name) {
144
+ this.attributes.delete(name);
145
+ }
146
+ hasAttribute(name) {
147
+ return this.attributes.has(name);
148
+ }
149
+ focus() {
150
+ const previous = getNativeActiveElement();
151
+ if (previous && previous !== this) {
152
+ previous.blur();
153
+ }
154
+ setNativeActiveElement(this);
155
+ this.dispatchEvent({ type: 'focus', target: this });
156
+ }
157
+ blur() {
158
+ if (getNativeActiveElement() === this) {
159
+ setNativeActiveElement(null);
160
+ }
161
+ this.dispatchEvent({ type: 'blur', target: this });
162
+ }
163
+ contains(other) {
164
+ let cursor = other;
165
+ while (cursor) {
166
+ if (cursor === this) {
167
+ return true;
168
+ }
169
+ cursor = cursor.parent;
170
+ }
171
+ return false;
172
+ }
173
+ addEventListener(type, listener) {
174
+ let bucket = this.listeners.get(type);
175
+ if (!bucket) {
176
+ bucket = new Set();
177
+ this.listeners.set(type, bucket);
178
+ }
179
+ bucket.add(listener);
180
+ }
181
+ removeEventListener(type, listener) {
182
+ this.listeners.get(type)?.delete(listener);
183
+ }
184
+ dispatchEvent(event) {
185
+ const normalized = typeof event === 'string'
186
+ ? { type: event, target: this }
187
+ : { type: event.type, target: event.target ?? this, detail: event.detail };
188
+ const bucket = this.listeners.get(normalized.type);
189
+ if (bucket) {
190
+ for (const listener of bucket) {
191
+ listener(normalized);
192
+ }
193
+ }
194
+ return true;
195
+ }
196
+ getBoundingClientRect() {
197
+ const rawW = Number(this.attributes.get('width') ?? 0);
198
+ const rawH = Number(this.attributes.get('height') ?? 0);
199
+ const width = Number.isFinite(rawW) ? rawW : 0;
200
+ const height = Number.isFinite(rawH) ? rawH : 0;
201
+ return {
202
+ x: 0,
203
+ y: 0,
204
+ width,
205
+ height,
206
+ top: 0,
207
+ left: 0,
208
+ right: width,
209
+ bottom: height,
210
+ };
211
+ }
212
+ }
@@ -0,0 +1,93 @@
1
+ import { Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2 } from '@angular/core';
2
+ import { NgNativeBridge } from './bridge';
3
+ import { NativeElementNode } from './native-element';
4
+ import * as i0 from "@angular/core";
5
+ /**
6
+ * 1:1 mapping from standard HTML elements to native desktop widget primitives.
7
+ * Containers map to `ng-box` (1D Flexbox); text elements map to `ng-label`.
8
+ * Angular component selectors (e.g. `app-*`, `router-outlet`, `ng-container`) are omitted
9
+ * so they continue operating as virtual hosts.
10
+ */
11
+ export declare const HTML_TO_NATIVE_TAG: Readonly<Record<string, string>>;
12
+ /**
13
+ * Resolves an Angular template element tag into a native desktop widget tag (`ng-*`, `gtk-*`,
14
+ * `adw-*`), returning `null` for virtual Angular hosts (`ng-container`, `router-outlet`, `app-*`).
15
+ */
16
+ export declare function resolveNativeTag(tag: string): string | null;
17
+ /**
18
+ * Custom Angular `Renderer2` implementation that translates Ivy template instructions
19
+ * (`createElement`, `createComment`, `insertBefore`, `removeChild`, `setAttribute`, `listen`)
20
+ * into `globalThis.__NG_NATIVE__` scene graph commands.
21
+ */
22
+ interface NativeRendererHooks {
23
+ onRealElementCreated?: (tag: string, id: string) => void;
24
+ getPrimaryWindowId?: () => string | null;
25
+ }
26
+ export declare class NativeRenderer2 extends Renderer2 {
27
+ readonly data: {
28
+ [key: string]: unknown;
29
+ };
30
+ destroyNode: ((node: unknown) => void) | null;
31
+ private readonly bridge;
32
+ private readonly nodesById;
33
+ private readonly nextId;
34
+ private readonly hooks?;
35
+ private readonly materializedTextLabels;
36
+ private readonly imageLoadSeq;
37
+ private readonly enabledEventTokens;
38
+ private readonly pendingVirtualListeners;
39
+ constructor(bridge: NgNativeBridge, nodesById: Map<string, NativeElementNode>, nextId: () => string, hooks?: NativeRendererHooks);
40
+ private destroySubtreeNodes;
41
+ destroy(): void;
42
+ createElement(name: string, _namespace?: string | null): NativeElementNode;
43
+ createComment(value: string): NativeElementNode;
44
+ createText(value: string): NativeElementNode;
45
+ appendChild(parent: NativeElementNode, newChild: NativeElementNode): void;
46
+ insertBefore(parent: NativeElementNode, newChild: NativeElementNode, refChild: NativeElementNode | null, _isMove?: boolean): void;
47
+ removeChild(parent: NativeElementNode | null, oldChild: NativeElementNode, _isHostElement?: boolean): void;
48
+ selectRootElement(selectorOrNode: string | NativeElementNode, _preserveContent?: boolean): NativeElementNode;
49
+ parentNode(node: NativeElementNode): NativeElementNode | null;
50
+ nextSibling(node: NativeElementNode): NativeElementNode | null;
51
+ setAttribute(el: NativeElementNode, name: string, value: string, _namespace?: string | null): void;
52
+ removeAttribute(el: NativeElementNode, name: string, _namespace?: string | null): void;
53
+ addClass(el: NativeElementNode, name: string): void;
54
+ removeClass(el: NativeElementNode, name: string): void;
55
+ setStyle(el: NativeElementNode, style: string, value: unknown, _flags?: RendererStyleFlags2): void;
56
+ removeStyle(el: NativeElementNode, style: string, _flags?: RendererStyleFlags2): void;
57
+ setProperty(el: NativeElementNode, name: string, value: unknown): void;
58
+ setValue(node: NativeElementNode, value: string): void;
59
+ private ensureLazyEventController;
60
+ listen(target: 'window' | 'document' | 'body' | NativeElementNode, eventName: string, callback: (event: unknown) => boolean | void): () => void;
61
+ private attachRegistrationToRealIds;
62
+ private attachVirtualListenersForAncestors;
63
+ private attachGlobalWindowIcon;
64
+ private syncClassList;
65
+ private handleImageSource;
66
+ private findRealAncestor;
67
+ private collectRealRootIds;
68
+ private findFirstRealId;
69
+ private findNextRealSiblingId;
70
+ private collectTextContent;
71
+ private syncTextBearingParent;
72
+ private materializeTextIntoContainer;
73
+ private projectInsertion;
74
+ }
75
+ export declare class NativeRendererFactory2 implements RendererFactory2 {
76
+ private readonly bridge;
77
+ private readonly nodesById;
78
+ private readonly defaultRenderer;
79
+ private readonly registeredTypeIds;
80
+ private nodeCounter;
81
+ private primaryWindowId;
82
+ private primaryScrollId;
83
+ constructor();
84
+ createRenderer(_hostElement: unknown, type: RendererType2 | null): Renderer2;
85
+ begin(): void;
86
+ end(): void;
87
+ getPrimaryWindowId(): string | null;
88
+ getPrimaryScrollId(): string | null;
89
+ getNode(id: string): NativeElementNode | undefined;
90
+ static ɵfac: i0.ɵɵFactoryDeclaration<NativeRendererFactory2, never>;
91
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
92
+ }
93
+ export {};