@ng-desktop/platform 0.3.0 → 0.4.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.
Files changed (56) hide show
  1. package/README.md +43 -7
  2. package/fesm2022/bridge-fs-compute.d.ts +1 -1
  3. package/fesm2022/bridge-fs-compute.js +5 -2
  4. package/fesm2022/bridge-sqlite.d.ts +0 -1
  5. package/fesm2022/bridge-sqlite.js +2 -12
  6. package/fesm2022/bridge.d.ts +62 -2
  7. package/fesm2022/bridge.js +406 -219
  8. package/fesm2022/css-style-parser.d.ts +33 -0
  9. package/fesm2022/css-style-parser.js +259 -0
  10. package/fesm2022/ecosystem-compat.d.ts +0 -1
  11. package/fesm2022/ecosystem-compat.js +9 -10
  12. package/fesm2022/image-loader.d.ts +1 -2
  13. package/fesm2022/image-loader.js +1 -2
  14. package/fesm2022/index.d.ts +5 -3
  15. package/fesm2022/index.js +4 -2
  16. package/fesm2022/native-directives.d.ts +188 -0
  17. package/fesm2022/native-directives.js +742 -0
  18. package/fesm2022/native-element.d.ts +7 -2
  19. package/fesm2022/native-element.js +21 -2
  20. package/fesm2022/native-renderer.d.ts +44 -3
  21. package/fesm2022/native-renderer.js +951 -44
  22. package/fesm2022/native-title.d.ts +1 -1
  23. package/fesm2022/native-title.js +17 -5
  24. package/fesm2022/platform.d.ts +2 -2
  25. package/fesm2022/platform.js +8 -2
  26. package/fesm2022/system-providers.d.ts +2 -1
  27. package/fesm2022/system-providers.js +63 -13
  28. package/fesm2022/viewport-scroller.d.ts +2 -1
  29. package/fesm2022/viewport-scroller.js +19 -7
  30. package/fesm2022/virtual-list.component.d.ts +57 -0
  31. package/fesm2022/virtual-list.component.js +200 -0
  32. package/package.json +4 -2
  33. package/fesm2022/bridge-fs-compute.d.ts.map +0 -1
  34. package/fesm2022/bridge-fs-compute.js.map +0 -1
  35. package/fesm2022/bridge-sqlite.d.ts.map +0 -1
  36. package/fesm2022/bridge-sqlite.js.map +0 -1
  37. package/fesm2022/bridge.d.ts.map +0 -1
  38. package/fesm2022/bridge.js.map +0 -1
  39. package/fesm2022/ecosystem-compat.d.ts.map +0 -1
  40. package/fesm2022/ecosystem-compat.js.map +0 -1
  41. package/fesm2022/image-loader.d.ts.map +0 -1
  42. package/fesm2022/image-loader.js.map +0 -1
  43. package/fesm2022/index.d.ts.map +0 -1
  44. package/fesm2022/index.js.map +0 -1
  45. package/fesm2022/native-element.d.ts.map +0 -1
  46. package/fesm2022/native-element.js.map +0 -1
  47. package/fesm2022/native-renderer.d.ts.map +0 -1
  48. package/fesm2022/native-renderer.js.map +0 -1
  49. package/fesm2022/native-title.d.ts.map +0 -1
  50. package/fesm2022/native-title.js.map +0 -1
  51. package/fesm2022/platform.d.ts.map +0 -1
  52. package/fesm2022/platform.js.map +0 -1
  53. package/fesm2022/system-providers.d.ts.map +0 -1
  54. package/fesm2022/system-providers.js.map +0 -1
  55. package/fesm2022/viewport-scroller.d.ts.map +0 -1
  56. package/fesm2022/viewport-scroller.js.map +0 -1
@@ -8,6 +8,7 @@ export declare const NATIVE_WINDOW_NODE_ID: InjectionToken<string>;
8
8
  export declare class NativeTitleService {
9
9
  private readonly bridge;
10
10
  private readonly windowNodeId;
11
+ private readonly rendererFactory;
11
12
  readonly title: import("@angular/core").WritableSignal<string>;
12
13
  getTitle(): string;
13
14
  setTitle(newTitle: string): void;
@@ -15,4 +16,3 @@ export declare class NativeTitleService {
15
16
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
16
17
  }
17
18
  export declare function provideNativeTitle(windowNodeId?: string): EnvironmentProviders;
18
- //# sourceMappingURL=native-title.d.ts.map
@@ -1,7 +1,16 @@
1
1
  import { inject, Injectable, InjectionToken, makeEnvironmentProviders, signal, } from '@angular/core';
2
2
  import { Title } from '@angular/platform-browser';
3
3
  import { ensureNgNativeBridge } from './bridge.js';
4
+ import { NativeRendererFactory2 } from './native-renderer.js';
4
5
  import * as i0 from "@angular/core";
6
+ function injectOptionalRendererFactory() {
7
+ try {
8
+ return inject(NativeRendererFactory2, { optional: true });
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
5
14
  export const NATIVE_WINDOW_NODE_ID = new InjectionToken('NATIVE_WINDOW_NODE_ID', {
6
15
  providedIn: 'root',
7
16
  factory: () => 'win',
@@ -13,6 +22,7 @@ export const NATIVE_WINDOW_NODE_ID = new InjectionToken('NATIVE_WINDOW_NODE_ID',
13
22
  export class NativeTitleService {
14
23
  bridge = ensureNgNativeBridge();
15
24
  windowNodeId = inject(NATIVE_WINDOW_NODE_ID);
25
+ rendererFactory = injectOptionalRendererFactory();
16
26
  title = signal('ng-native-app', /* @ts-ignore */
17
27
  ...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
18
28
  getTitle() {
@@ -20,13 +30,16 @@ export class NativeTitleService {
20
30
  }
21
31
  setTitle(newTitle) {
22
32
  const normalized = String(newTitle ?? '').trim() || 'ng-native-app';
33
+ const targetId = this.windowNodeId === 'win'
34
+ ? (this.rendererFactory?.getPrimaryWindowId() ?? this.windowNodeId)
35
+ : this.windowNodeId;
23
36
  this.title.set(normalized);
24
- this.bridge.setText(this.windowNodeId, normalized);
37
+ this.bridge.setText(targetId, normalized);
25
38
  }
26
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeTitleService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
27
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeTitleService, providedIn: 'root' });
39
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeTitleService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
40
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeTitleService, providedIn: 'root' });
28
41
  }
29
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeTitleService, decorators: [{
42
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeTitleService, decorators: [{
30
43
  type: Injectable,
31
44
  args: [{ providedIn: 'root' }]
32
45
  }] });
@@ -37,4 +50,3 @@ export function provideNativeTitle(windowNodeId = 'win') {
37
50
  { provide: Title, useExisting: NativeTitleService },
38
51
  ]);
39
52
  }
40
- //# sourceMappingURL=native-title.js.map
@@ -1,4 +1,4 @@
1
- import { ApplicationConfig, EnvironmentProviders, Type } from '@angular/core';
1
+ import { ApplicationConfig, ApplicationRef, EnvironmentProviders, Type } from '@angular/core';
2
2
  import { NgNativeBridge } from './bridge';
3
3
  /**
4
4
  * Provides the Angular Native Desktop platform (`NativeRendererFactory2`, Zoneless reactivity,
@@ -10,9 +10,9 @@ export interface NativeBootstrapContext {
10
10
  readonly rootComponent: Type<unknown>;
11
11
  readonly bridge: NgNativeBridge;
12
12
  readonly config: ApplicationConfig;
13
+ readonly appRefPromise?: Promise<ApplicationRef>;
13
14
  }
14
15
  /**
15
16
  * Bootstraps an Angular root component against the Rust `RenderEngine` via `globalThis.__NG_NATIVE__`.
16
17
  */
17
18
  export declare function bootstrapNativeApplication(rootComponent: Type<unknown>, appConfig?: ApplicationConfig): NativeBootstrapContext;
18
- //# sourceMappingURL=platform.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { makeEnvironmentProviders, provideZonelessChangeDetection, RendererFactory2, } from '@angular/core';
2
+ import { bootstrapApplication } from '@angular/platform-browser';
2
3
  import { ensureNgNativeBridge } from './bridge.js';
3
4
  import { provideNativeImageLoader } from './image-loader.js';
4
5
  import { NativeRendererFactory2 } from './native-renderer.js';
@@ -14,7 +15,8 @@ export function provideNativePlatform() {
14
15
  ensureNgNativeBridge();
15
16
  return makeEnvironmentProviders([
16
17
  provideZonelessChangeDetection(),
17
- { provide: RendererFactory2, useClass: NativeRendererFactory2 },
18
+ NativeRendererFactory2,
19
+ { provide: RendererFactory2, useExisting: NativeRendererFactory2 },
18
20
  provideNativeImageLoader(),
19
21
  provideNativeTitle(),
20
22
  provideNativeViewportScroller(),
@@ -31,10 +33,14 @@ export function bootstrapNativeApplication(rootComponent, appConfig) {
31
33
  const mergedConfig = {
32
34
  providers: [provideNativePlatform(), ...(appConfig?.providers ?? [])],
33
35
  };
36
+ const isIvyComponent = 'ɵcmp' in rootComponent;
37
+ const appRefPromise = isIvyComponent
38
+ ? bootstrapApplication(rootComponent, mergedConfig)
39
+ : undefined;
34
40
  return {
35
41
  rootComponent,
36
42
  bridge,
37
43
  config: mergedConfig,
44
+ ...(appRefPromise ? { appRefPromise } : {}),
38
45
  };
39
46
  }
40
- //# sourceMappingURL=platform.js.map
@@ -19,6 +19,8 @@ export declare function matchesKeyboardEvent(eventName: string, payload: NativeK
19
19
  */
20
20
  export declare class NativeKeyEventsPlugin extends EventManagerPlugin {
21
21
  private readonly bridge;
22
+ private readonly rendererFactory;
23
+ private readonly enabledKeyboardNodes;
22
24
  constructor();
23
25
  supports(eventName: string): boolean;
24
26
  addEventListener(element: unknown, eventName: string, handler: (event: unknown) => void): () => void;
@@ -39,4 +41,3 @@ export declare class NativeSystemErrorHandler implements ErrorHandler {
39
41
  export declare function provideSystemLocale(): EnvironmentProviders;
40
42
  export declare function provideNativeErrorHandler(): EnvironmentProviders;
41
43
  export declare function provideNativeKeyEvents(): EnvironmentProviders;
42
- //# sourceMappingURL=system-providers.d.ts.map
@@ -1,8 +1,17 @@
1
1
  import { DATE_PIPE_DEFAULT_TIMEZONE } from '@angular/common';
2
- import { ErrorHandler, Injectable, LOCALE_ID, makeEnvironmentProviders, signal, } from '@angular/core';
2
+ import { ErrorHandler, inject, Injectable, LOCALE_ID, makeEnvironmentProviders, signal, } from '@angular/core';
3
3
  import { EVENT_MANAGER_PLUGINS, EventManagerPlugin } from '@angular/platform-browser';
4
4
  import { ensureNgNativeBridge } from './bridge.js';
5
+ import { NativeRendererFactory2 } from './native-renderer.js';
5
6
  import * as i0 from "@angular/core";
7
+ function injectOptionalRendererFactory() {
8
+ try {
9
+ return inject(NativeRendererFactory2, { optional: true });
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ }
6
15
  function normalizeKeyToken(raw) {
7
16
  const lower = raw.trim().toLowerCase();
8
17
  if (lower === 'esc')
@@ -37,12 +46,45 @@ export function matchesKeyboardEvent(eventName, payload) {
37
46
  wantAlt === Boolean(payload.altKey) &&
38
47
  wantMeta === Boolean(payload.metaKey));
39
48
  }
49
+ function normalizeKeyPayload(raw) {
50
+ if (typeof raw === 'string') {
51
+ const trimmed = raw.trim();
52
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
53
+ try {
54
+ return JSON.parse(trimmed);
55
+ }
56
+ catch {
57
+ return { key: raw };
58
+ }
59
+ }
60
+ return { key: raw };
61
+ }
62
+ if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
63
+ const obj = raw;
64
+ const rawValue = obj['value'];
65
+ if (typeof rawValue === 'string') {
66
+ const trimmed = rawValue.trim();
67
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
68
+ try {
69
+ return { ...obj, ...JSON.parse(trimmed) };
70
+ }
71
+ catch {
72
+ return obj;
73
+ }
74
+ }
75
+ }
76
+ return obj;
77
+ }
78
+ return {};
79
+ }
40
80
  /**
41
81
  * Angular `EventManagerPlugin` translating `(keydown.<mod>.<key>)` and `(keyup.<mod>.<key>)`
42
82
  * bindings onto native `GtkShortcutController` / `GtkEventControllerKey` listeners.
43
83
  */
44
84
  export class NativeKeyEventsPlugin extends EventManagerPlugin {
45
85
  bridge = ensureNgNativeBridge();
86
+ rendererFactory = injectOptionalRendererFactory();
87
+ enabledKeyboardNodes = new Set();
46
88
  constructor() {
47
89
  super(null);
48
90
  }
@@ -52,22 +94,31 @@ export class NativeKeyEventsPlugin extends EventManagerPlugin {
52
94
  }
53
95
  addEventListener(element, eventName, handler) {
54
96
  const baseEvent = eventName.trim().toLowerCase().startsWith('keyup.') ? 'keyup' : 'keydown';
97
+ const primaryWin = this.rendererFactory?.getPrimaryWindowId() ?? 'win';
55
98
  const nodeId = typeof element === 'string'
56
- ? element
99
+ ? element === 'window' || element === 'document' || element === 'body'
100
+ ? primaryWin
101
+ : element
57
102
  : typeof element === 'object' && element !== null && 'id' in element
58
- ? String(element.id)
59
- : 'win';
103
+ ? 'isVirtual' in element && element.isVirtual
104
+ ? primaryWin
105
+ : String(element.id)
106
+ : primaryWin;
107
+ if (!this.enabledKeyboardNodes.has(nodeId)) {
108
+ this.enabledKeyboardNodes.add(nodeId);
109
+ this.bridge.setAttribute(nodeId, 'event-mask', 'keyboard');
110
+ }
60
111
  return this.bridge.listen(nodeId, baseEvent, (rawEvent) => {
61
- const payload = (rawEvent ?? {});
112
+ const payload = normalizeKeyPayload(rawEvent);
62
113
  if (matchesKeyboardEvent(eventName, payload)) {
63
- handler(rawEvent);
114
+ handler(payload);
64
115
  }
65
116
  });
66
117
  }
67
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeKeyEventsPlugin, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
68
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeKeyEventsPlugin });
118
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeKeyEventsPlugin, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
119
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeKeyEventsPlugin });
69
120
  }
70
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeKeyEventsPlugin, decorators: [{
121
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeKeyEventsPlugin, decorators: [{
71
122
  type: Injectable
72
123
  }], ctorParameters: () => [] });
73
124
  /**
@@ -83,10 +134,10 @@ export class NativeSystemErrorHandler {
83
134
  this.lastError.set(message);
84
135
  this.bridge.logSystemError(message);
85
136
  }
86
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeSystemErrorHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
87
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeSystemErrorHandler, providedIn: 'root' });
137
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeSystemErrorHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
138
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeSystemErrorHandler, providedIn: 'root' });
88
139
  }
89
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeSystemErrorHandler, decorators: [{
140
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeSystemErrorHandler, decorators: [{
90
141
  type: Injectable,
91
142
  args: [{ providedIn: 'root' }]
92
143
  }] });
@@ -110,4 +161,3 @@ export function provideNativeKeyEvents() {
110
161
  { provide: EVENT_MANAGER_PLUGINS, useClass: NativeKeyEventsPlugin, multi: true },
111
162
  ]);
112
163
  }
113
- //# sourceMappingURL=system-providers.js.map
@@ -7,9 +7,11 @@ import * as i0 from "@angular/core";
7
7
  */
8
8
  export declare class NativeViewportScroller extends ViewportScroller {
9
9
  private readonly bridge;
10
+ private readonly rendererFactory;
10
11
  private scrollPosition;
11
12
  private offsetFn;
12
13
  private scrollRestoration;
14
+ private targetScrollId;
13
15
  setOffset(offset: [number, number] | (() => [number, number])): void;
14
16
  getScrollPosition(): [number, number];
15
17
  scrollToPosition(position: [number, number]): void;
@@ -20,4 +22,3 @@ export declare class NativeViewportScroller extends ViewportScroller {
20
22
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
21
23
  }
22
24
  export declare function provideNativeViewportScroller(): EnvironmentProviders;
23
- //# sourceMappingURL=viewport-scroller.d.ts.map
@@ -1,16 +1,29 @@
1
1
  import { ViewportScroller } from '@angular/common';
2
- import { Injectable, makeEnvironmentProviders } from '@angular/core';
2
+ import { inject, Injectable, makeEnvironmentProviders } from '@angular/core';
3
3
  import { ensureNgNativeBridge } from './bridge.js';
4
+ import { NativeRendererFactory2 } from './native-renderer.js';
4
5
  import * as i0 from "@angular/core";
6
+ function injectOptionalRendererFactory() {
7
+ try {
8
+ return inject(NativeRendererFactory2, { optional: true });
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
5
14
  /**
6
15
  * DOM-free Angular `ViewportScroller` backed by native `GtkScrolledWindow` adjustments
7
16
  * (`NSScrollView` on macOS, `ScrollViewer` on WinUI 3).
8
17
  */
9
18
  export class NativeViewportScroller extends ViewportScroller {
10
19
  bridge = ensureNgNativeBridge();
20
+ rendererFactory = injectOptionalRendererFactory();
11
21
  scrollPosition = [0, 0];
12
22
  offsetFn = () => [0, 0];
13
23
  scrollRestoration = 'auto';
24
+ targetScrollId() {
25
+ return this.rendererFactory?.getPrimaryScrollId() ?? 'scroll';
26
+ }
14
27
  setOffset(offset) {
15
28
  this.offsetFn = typeof offset === 'function' ? offset : () => offset;
16
29
  }
@@ -22,14 +35,14 @@ export class NativeViewportScroller extends ViewportScroller {
22
35
  const x = Math.max(0, position[0] - ox);
23
36
  const y = Math.max(0, position[1] - oy);
24
37
  this.scrollPosition = [x, y];
25
- this.bridge.setAttribute('scroll', 'scroll-to', `${x},${y}`);
38
+ this.bridge.setAttribute(this.targetScrollId(), 'scroll-to', `${x},${y}`);
26
39
  }
27
40
  scrollToAnchor(anchor) {
28
41
  const clean = anchor.replace(/^#/, '').trim();
29
42
  if (!clean) {
30
43
  return;
31
44
  }
32
- this.bridge.setAttribute('scroll', 'scroll-anchor', clean);
45
+ this.bridge.setAttribute(this.targetScrollId(), 'scroll-anchor', clean);
33
46
  }
34
47
  setHistoryScrollRestoration(scrollRestoration) {
35
48
  this.scrollRestoration = scrollRestoration;
@@ -37,10 +50,10 @@ export class NativeViewportScroller extends ViewportScroller {
37
50
  getHistoryScrollRestoration() {
38
51
  return this.scrollRestoration;
39
52
  }
40
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeViewportScroller, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
41
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeViewportScroller, providedIn: 'root' });
53
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeViewportScroller, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
54
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeViewportScroller, providedIn: 'root' });
42
55
  }
43
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeViewportScroller, decorators: [{
56
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeViewportScroller, decorators: [{
44
57
  type: Injectable,
45
58
  args: [{ providedIn: 'root' }]
46
59
  }] });
@@ -50,4 +63,3 @@ export function provideNativeViewportScroller() {
50
63
  { provide: ViewportScroller, useExisting: NativeViewportScroller },
51
64
  ]);
52
65
  }
53
- //# sourceMappingURL=viewport-scroller.js.map
@@ -0,0 +1,57 @@
1
+ import { TemplateRef } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /** Inclusive start / exclusive end index range and spacer heights for a virtualized viewport. */
4
+ export interface VirtualSliceRange {
5
+ startIndex: number;
6
+ endIndex: number;
7
+ totalItems: number;
8
+ topSpacerHeight: number;
9
+ bottomSpacerHeight: number;
10
+ }
11
+ /** Template context provided to each rendered item row in `<ng-virtual-list>`. */
12
+ export interface NativeVirtualItemContext<T> {
13
+ $implicit: T;
14
+ index: number;
15
+ }
16
+ /** Internal materialized slice entry paired with its stable tracking key. */
17
+ export interface NativeVirtualListEntry<T> {
18
+ item: T;
19
+ index: number;
20
+ key: unknown;
21
+ }
22
+ /** Payload emitted when a row inside `<ng-virtual-list>` is activated natively. */
23
+ export interface NativeVirtualRowActivatedEvent<T> {
24
+ index: number;
25
+ item: T;
26
+ }
27
+ /**
28
+ * Computes the visible item slice and spacer heights for a fixed-row-height viewport.
29
+ */
30
+ export declare function computeVirtualSliceRange(totalItems: number, scrollTop: number, viewportHeight: number, itemHeight: number, overscan?: number): VirtualSliceRange;
31
+ /**
32
+ * Virtualized native desktop list component rendering only the visible viewport slice + overscan
33
+ * inside an `<ng-scroll>` + `<ng-list>` hierarchy to keep native widget counts bounded at scale.
34
+ */
35
+ export declare class NativeVirtualListComponent<T = unknown> {
36
+ readonly items: import("@angular/core").InputSignal<readonly T[]>;
37
+ readonly itemHeight: import("@angular/core").InputSignal<number>;
38
+ readonly viewportHeight: import("@angular/core").InputSignal<number>;
39
+ readonly overscan: import("@angular/core").InputSignal<number>;
40
+ readonly selectionMode: import("@angular/core").InputSignal<"none" | "single" | "browse" | "multiple">;
41
+ readonly showSeparators: import("@angular/core").InputSignal<boolean>;
42
+ readonly trackBy: import("@angular/core").InputSignal<(index: number, item: T) => unknown>;
43
+ readonly itemTemplateInput: import("@angular/core").InputSignal<TemplateRef<NativeVirtualItemContext<T>> | null>;
44
+ readonly projectedTemplate: import("@angular/core").Signal<TemplateRef<NativeVirtualItemContext<T>> | undefined>;
45
+ readonly rangeChange: import("@angular/core").OutputEmitterRef<VirtualSliceRange>;
46
+ readonly rowActivated: import("@angular/core").OutputEmitterRef<NativeVirtualRowActivatedEvent<T>>;
47
+ readonly scrollTop: import("@angular/core").WritableSignal<number>;
48
+ readonly resolvedTemplate: import("@angular/core").Signal<TemplateRef<NativeVirtualItemContext<T>> | null>;
49
+ readonly range: import("@angular/core").Signal<VirtualSliceRange>;
50
+ readonly visibleEntries: import("@angular/core").Signal<readonly NativeVirtualListEntry<T>[]>;
51
+ private lastEmittedRangeKey;
52
+ constructor();
53
+ onNativeScroll(event: unknown): void;
54
+ onRowActivated(event: unknown): void;
55
+ static ɵfac: i0.ɵɵFactoryDeclaration<NativeVirtualListComponent<any>, never>;
56
+ static ɵcmp: i0.ɵɵComponentDeclaration<NativeVirtualListComponent<any>, "ng-virtual-list", never, { "items": { "alias": "items"; "required": false; "isSignal": true; }; "itemHeight": { "alias": "itemHeight"; "required": false; "isSignal": true; }; "viewportHeight": { "alias": "viewportHeight"; "required": false; "isSignal": true; }; "overscan": { "alias": "overscan"; "required": false; "isSignal": true; }; "selectionMode": { "alias": "selectionMode"; "required": false; "isSignal": true; }; "showSeparators": { "alias": "showSeparators"; "required": false; "isSignal": true; }; "trackBy": { "alias": "trackBy"; "required": false; "isSignal": true; }; "itemTemplateInput": { "alias": "itemTemplate"; "required": false; "isSignal": true; }; }, { "rangeChange": "rangeChange"; "rowActivated": "rowActivated"; }, ["projectedTemplate"], never, true, never>;
57
+ }
@@ -0,0 +1,200 @@
1
+ import { NgTemplateOutlet } from '@angular/common';
2
+ import { ChangeDetectionStrategy, Component, computed, contentChild, effect, input, output, signal, TemplateRef, } from '@angular/core';
3
+ import { NativeContainerDirective, NativeElementDirective, NativeListDirective, NativeTextWidgetDirective, } from './native-directives.js';
4
+ import * as i0 from "@angular/core";
5
+ /**
6
+ * Computes the visible item slice and spacer heights for a fixed-row-height viewport.
7
+ */
8
+ export function computeVirtualSliceRange(totalItems, scrollTop, viewportHeight, itemHeight, overscan = 4) {
9
+ const safeTotal = Math.max(0, Math.floor(totalItems));
10
+ if (safeTotal === 0) {
11
+ return {
12
+ startIndex: 0,
13
+ endIndex: 0,
14
+ totalItems: 0,
15
+ topSpacerHeight: 0,
16
+ bottomSpacerHeight: 0,
17
+ };
18
+ }
19
+ const safeItemHeight = Math.max(1, itemHeight);
20
+ const safeViewport = Math.max(safeItemHeight, viewportHeight);
21
+ const safeOverscan = Math.max(0, Math.floor(overscan));
22
+ const maxScrollTop = Math.max(0, safeTotal * safeItemHeight - safeViewport);
23
+ const clampedScrollTop = Math.min(Math.max(0, scrollTop), maxScrollTop);
24
+ const firstVisible = Math.floor(clampedScrollTop / safeItemHeight);
25
+ const visibleCount = Math.ceil(safeViewport / safeItemHeight);
26
+ const startIndex = Math.max(0, firstVisible - safeOverscan);
27
+ const endIndex = Math.min(safeTotal, firstVisible + visibleCount + safeOverscan);
28
+ return {
29
+ startIndex,
30
+ endIndex,
31
+ totalItems: safeTotal,
32
+ topSpacerHeight: startIndex * safeItemHeight,
33
+ bottomSpacerHeight: (safeTotal - endIndex) * safeItemHeight,
34
+ };
35
+ }
36
+ /**
37
+ * Virtualized native desktop list component rendering only the visible viewport slice + overscan
38
+ * inside an `<ng-scroll>` + `<ng-list>` hierarchy to keep native widget counts bounded at scale.
39
+ */
40
+ export class NativeVirtualListComponent {
41
+ items = input([], /* @ts-ignore */
42
+ ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
43
+ itemHeight = input(48, /* @ts-ignore */
44
+ ...(ngDevMode ? [{ debugName: "itemHeight" }] : /* istanbul ignore next */ []));
45
+ viewportHeight = input(480, /* @ts-ignore */
46
+ ...(ngDevMode ? [{ debugName: "viewportHeight" }] : /* istanbul ignore next */ []));
47
+ overscan = input(4, /* @ts-ignore */
48
+ ...(ngDevMode ? [{ debugName: "overscan" }] : /* istanbul ignore next */ []));
49
+ selectionMode = input('single', /* @ts-ignore */
50
+ ...(ngDevMode ? [{ debugName: "selectionMode" }] : /* istanbul ignore next */ []));
51
+ showSeparators = input(false, /* @ts-ignore */
52
+ ...(ngDevMode ? [{ debugName: "showSeparators" }] : /* istanbul ignore next */ []));
53
+ trackBy = input((index, _item) => index, /* @ts-ignore */
54
+ ...(ngDevMode ? [{ debugName: "trackBy" }] : /* istanbul ignore next */ []));
55
+ itemTemplateInput = input(null, { ...(ngDevMode ? { debugName: "itemTemplateInput" } : /* istanbul ignore next */ {}), alias: 'itemTemplate' });
56
+ projectedTemplate = contentChild(TemplateRef, /* @ts-ignore */
57
+ ...(ngDevMode ? [{ debugName: "projectedTemplate" }] : /* istanbul ignore next */ []));
58
+ rangeChange = output();
59
+ rowActivated = output();
60
+ scrollTop = signal(0, /* @ts-ignore */
61
+ ...(ngDevMode ? [{ debugName: "scrollTop" }] : /* istanbul ignore next */ []));
62
+ resolvedTemplate = computed(() => this.itemTemplateInput() ?? this.projectedTemplate() ?? null, /* @ts-ignore */
63
+ ...(ngDevMode ? [{ debugName: "resolvedTemplate" }] : /* istanbul ignore next */ []));
64
+ range = computed(() => computeVirtualSliceRange(this.items().length, this.scrollTop(), this.viewportHeight(), this.itemHeight(), this.overscan()), /* @ts-ignore */
65
+ ...(ngDevMode ? [{ debugName: "range" }] : /* istanbul ignore next */ []));
66
+ visibleEntries = computed(() => {
67
+ const source = this.items();
68
+ const { startIndex, endIndex } = this.range();
69
+ const trackFn = this.trackBy();
70
+ const entries = [];
71
+ for (let idx = startIndex; idx < endIndex; idx += 1) {
72
+ const item = source[idx];
73
+ entries.push({ item, index: idx, key: trackFn(idx, item) });
74
+ }
75
+ return entries;
76
+ }, /* @ts-ignore */
77
+ ...(ngDevMode ? [{ debugName: "visibleEntries" }] : /* istanbul ignore next */ []));
78
+ lastEmittedRangeKey = '';
79
+ constructor() {
80
+ effect(() => {
81
+ const next = this.range();
82
+ const key = `${next.startIndex}:${next.endIndex}:${next.totalItems}`;
83
+ if (key !== this.lastEmittedRangeKey) {
84
+ this.lastEmittedRangeKey = key;
85
+ this.rangeChange.emit(next);
86
+ }
87
+ });
88
+ }
89
+ onNativeScroll(event) {
90
+ if (!event || typeof event !== 'object') {
91
+ return;
92
+ }
93
+ const obj = event;
94
+ let top = obj['scrollTop'];
95
+ if (typeof top !== 'number' && obj['target'] && typeof obj['target'] === 'object') {
96
+ top = obj['target']['scrollTop'];
97
+ }
98
+ if (typeof top === 'number' && Number.isFinite(top)) {
99
+ this.scrollTop.set(Math.max(0, top));
100
+ }
101
+ }
102
+ onRowActivated(event) {
103
+ if (!event || typeof event !== 'object') {
104
+ return;
105
+ }
106
+ const obj = event;
107
+ const rawIdx = typeof obj['value'] === 'number'
108
+ ? obj['value']
109
+ : typeof obj['index'] === 'number'
110
+ ? obj['index']
111
+ : -1;
112
+ const localIdx = Math.floor(rawIdx);
113
+ const entry = this.visibleEntries()[localIdx];
114
+ if (entry) {
115
+ this.rowActivated.emit({ index: entry.index, item: entry.item });
116
+ }
117
+ }
118
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeVirtualListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
119
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: NativeVirtualListComponent, isStandalone: true, selector: "ng-virtual-list", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, itemHeight: { classPropertyName: "itemHeight", publicName: "itemHeight", isSignal: true, isRequired: false, transformFunction: null }, viewportHeight: { classPropertyName: "viewportHeight", publicName: "viewportHeight", isSignal: true, isRequired: false, transformFunction: null }, overscan: { classPropertyName: "overscan", publicName: "overscan", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null }, showSeparators: { classPropertyName: "showSeparators", publicName: "showSeparators", isSignal: true, isRequired: false, transformFunction: null }, trackBy: { classPropertyName: "trackBy", publicName: "trackBy", isSignal: true, isRequired: false, transformFunction: null }, itemTemplateInput: { classPropertyName: "itemTemplateInput", publicName: "itemTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { rangeChange: "rangeChange", rowActivated: "rowActivated" }, queries: [{ propertyName: "projectedTemplate", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], ngImport: i0, template: `
120
+ <ng-scroll
121
+ [hexpand]="true"
122
+ [vexpand]="true"
123
+ [min-height]="viewportHeight()"
124
+ (scroll)="onNativeScroll($event)"
125
+ >
126
+ <ng-box orientation="vertical" [spacing]="0" [hexpand]="true">
127
+ @if (range().topSpacerHeight > 0) {
128
+ <ng-box [height]="range().topSpacerHeight"></ng-box>
129
+ }
130
+ <ng-list
131
+ [selection-mode]="selectionMode()"
132
+ [show-separators]="showSeparators()"
133
+ (rowActivated)="onRowActivated($event)"
134
+ >
135
+ @for (entry of visibleEntries(); track entry.key) {
136
+ @if (resolvedTemplate(); as tpl) {
137
+ <ng-container
138
+ [ngTemplateOutlet]="tpl"
139
+ [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
140
+ ></ng-container>
141
+ } @else {
142
+ <ng-label [text]="'' + entry.item"></ng-label>
143
+ }
144
+ }
145
+ </ng-list>
146
+ @if (range().bottomSpacerHeight > 0) {
147
+ <ng-box [height]="range().bottomSpacerHeight"></ng-box>
148
+ }
149
+ </ng-box>
150
+ </ng-scroll>
151
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: NativeElementDirective, selector: "ng-window,adw-window,ng-dialog,gtk-dialog,adw-dialog,ng-header-bar,adw-header-bar,gtk-header-bar,ng-scroll,gtk-scrolled-window,ng-box,gtk-box,ng-grid,gtk-grid,ng-separator,gtk-separator,ng-button,gtk-button,ng-label,gtk-label,ng-entry,gtk-entry,ng-switch,gtk-switch,ng-checkbox,ng-check,ng-check-button,gtk-check-button,ng-slider,ng-scale,gtk-scale,ng-select,ng-dropdown,gtk-dropdown,gtk-drop-down,ng-image,adw-image,gtk-picture,ng-picture,ng-level-bar,gtk-level-bar,ng-flow,ng-flow-box,gtk-flow-box,ng-spinner,gtk-spinner,ng-progress-bar,gtk-progress-bar,ng-paned,gtk-paned,ng-stack,gtk-stack,adw-navigation-view,ng-expander,gtk-expander,ng-text-view,gtk-text-view,ng-password-entry,gtk-password-entry,ng-spin-button,gtk-spin-button,ng-search-entry,gtk-search-entry,ng-clamp,adw-clamp,ng-list,ng-table,gtk-list-box,gtk-list-view,ng-popover,gtk-popover,ng-menu,adw-entry-row,adw-password-entry-row,adw-switch-row,adw-combo-row,adw-spin-row", inputs: ["hexpand", "vexpand", "halign", "valign", "width", "height", "min-width", "min-height", "margin", "margin-top", "margin-bottom", "margin-start", "margin-end", "visible", "sensitive", "disabled", "tooltip", "event-mask", "drop-target"] }, { kind: "directive", type: NativeContainerDirective, selector: "ng-box,gtk-box,ng-grid,gtk-grid,ng-flow,ng-flow-box,gtk-flow-box,ng-paned,gtk-paned,ng-scroll,gtk-scrolled-window,ng-stack,gtk-stack,adw-navigation-view,ng-expander,gtk-expander,ng-clamp,adw-clamp,ng-separator,gtk-separator", inputs: ["orientation", "spacing", "gap", "row-spacing", "column-spacing", "min-children", "max-children", "min-per-row", "max-per-row", "homogeneous", "position", "visible-child", "active-page", "transition", "transition-type", "label", "title", "expanded", "open", "max-size", "maximum-size", "scroll-to", "scroll-anchor"] }, { kind: "directive", type: NativeListDirective, selector: "ng-list,ng-table,gtk-list-box,gtk-list-view", inputs: ["selection-mode", "selectionMode", "show-separators", "showSeparators", "separators"] }, { kind: "directive", type: NativeTextWidgetDirective, selector: "ng-button,gtk-button,ng-label,gtk-label", inputs: ["label", "text", "wrap", "selectable", "ellipsize"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
152
+ }
153
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeVirtualListComponent, decorators: [{
154
+ type: Component,
155
+ args: [{
156
+ selector: 'ng-virtual-list',
157
+ standalone: true,
158
+ changeDetection: ChangeDetectionStrategy.OnPush,
159
+ imports: [
160
+ NgTemplateOutlet,
161
+ NativeElementDirective,
162
+ NativeContainerDirective,
163
+ NativeListDirective,
164
+ NativeTextWidgetDirective,
165
+ ],
166
+ template: `
167
+ <ng-scroll
168
+ [hexpand]="true"
169
+ [vexpand]="true"
170
+ [min-height]="viewportHeight()"
171
+ (scroll)="onNativeScroll($event)"
172
+ >
173
+ <ng-box orientation="vertical" [spacing]="0" [hexpand]="true">
174
+ @if (range().topSpacerHeight > 0) {
175
+ <ng-box [height]="range().topSpacerHeight"></ng-box>
176
+ }
177
+ <ng-list
178
+ [selection-mode]="selectionMode()"
179
+ [show-separators]="showSeparators()"
180
+ (rowActivated)="onRowActivated($event)"
181
+ >
182
+ @for (entry of visibleEntries(); track entry.key) {
183
+ @if (resolvedTemplate(); as tpl) {
184
+ <ng-container
185
+ [ngTemplateOutlet]="tpl"
186
+ [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
187
+ ></ng-container>
188
+ } @else {
189
+ <ng-label [text]="'' + entry.item"></ng-label>
190
+ }
191
+ }
192
+ </ng-list>
193
+ @if (range().bottomSpacerHeight > 0) {
194
+ <ng-box [height]="range().bottomSpacerHeight"></ng-box>
195
+ }
196
+ </ng-box>
197
+ </ng-scroll>
198
+ `,
199
+ }]
200
+ }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], itemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeight", required: false }] }], viewportHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewportHeight", required: false }] }], overscan: [{ type: i0.Input, args: [{ isSignal: true, alias: "overscan", required: false }] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], showSeparators: [{ type: i0.Input, args: [{ isSignal: true, alias: "showSeparators", required: false }] }], trackBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "trackBy", required: false }] }], itemTemplateInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemTemplate", required: false }] }], projectedTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], rangeChange: [{ type: i0.Output, args: ["rangeChange"] }], rowActivated: [{ type: i0.Output, args: ["rowActivated"] }] } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-desktop/platform",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "@ng-desktop/platform for Angular Desktop Engine",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -30,7 +30,8 @@
30
30
  "files": [
31
31
  "fesm2022",
32
32
  "README.md",
33
- "LICENSE"
33
+ "LICENSE",
34
+ "!**/*.map"
34
35
  ],
35
36
  "main": "./fesm2022/index.js",
36
37
  "module": "./fesm2022/index.js",
@@ -45,6 +46,7 @@
45
46
  }
46
47
  },
47
48
  "peerDependencies": {
49
+ "@angular/common": ">=22.0.0",
48
50
  "@angular/core": ">=22.0.0"
49
51
  }
50
52
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"bridge-fs-compute.d.ts","sourceRoot":"","sources":["../../../../packages/platform-native/src/bridge-fs-compute.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAmCD,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,KAAK,EAAE,MAAM,EACb,KAAK,SAAK,GACT,kBAAkB,EAAE,CAetB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUzD;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IACnD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,WAAW,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,SAAqB,GAAG,MAAM;IAcxF,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAYjD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAShC,gBAAgB,IAAI,MAAM,EAAE;CAK7B"}