@ng-native/nativescript 0.22.2 → 0.23.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/dist/native-script.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* }
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
import { InjectionToken, type EnvironmentProviders } from '@angular/core';
|
|
20
|
+
import { InjectionToken, type EnvironmentProviders, type Signal } from '@angular/core';
|
|
21
21
|
import * as i0 from "@angular/core";
|
|
22
22
|
export type NativeScriptPlatform = 'ios' | 'android';
|
|
23
23
|
/** What the service needs of NativeScript, on the platform the app is on. */
|
|
@@ -61,6 +61,13 @@ export declare class NativeScript {
|
|
|
61
61
|
static readonly RUNTIME: InjectionToken<NativeScriptRuntime | null>;
|
|
62
62
|
private readonly runtime;
|
|
63
63
|
private readonly errors;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the runtime is here and in the build. False where there is no runtime - in Node, on
|
|
66
|
+
* the web and on macOS - where `call()` answers `undefined` and `runOnUI()` resolves to it; and
|
|
67
|
+
* false in a build without NativeScript, where `call()` with a function for the platform throws
|
|
68
|
+
* and `runOnUI()` rejects, saying so. `nativeViewHandle()` throws in both.
|
|
69
|
+
*/
|
|
70
|
+
readonly available: Signal<boolean>;
|
|
64
71
|
/** The platform NativeScript is installed on; null in Node and on the web. */
|
|
65
72
|
readonly platform: NativeScriptPlatform | null;
|
|
66
73
|
constructor();
|
package/dist/native-script.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* }
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
import { ErrorHandler, InjectionToken, Service, inject, makeEnvironmentProviders, provideEnvironmentInitializer, } from '@angular/core';
|
|
20
|
+
import { ErrorHandler, InjectionToken, Service, inject, makeEnvironmentProviders, provideEnvironmentInitializer, signal, } from '@angular/core';
|
|
21
21
|
import * as i0 from "@angular/core";
|
|
22
22
|
/** NativeScript's `androidContext`, once a runtime is made: see `androidContext` below. */
|
|
23
23
|
let contextOf = null;
|
|
@@ -93,6 +93,13 @@ export class NativeScript {
|
|
|
93
93
|
static RUNTIME = new InjectionToken('angular-native.nativeScriptRuntime', { factory: nativeScriptRuntime });
|
|
94
94
|
runtime = inject(NativeScript.RUNTIME);
|
|
95
95
|
errors = inject(ErrorHandler);
|
|
96
|
+
/**
|
|
97
|
+
* Whether the runtime is here and in the build. False where there is no runtime - in Node, on
|
|
98
|
+
* the web and on macOS - where `call()` answers `undefined` and `runOnUI()` resolves to it; and
|
|
99
|
+
* false in a build without NativeScript, where `call()` with a function for the platform throws
|
|
100
|
+
* and `runOnUI()` rejects, saying so. `nativeViewHandle()` throws in both.
|
|
101
|
+
*/
|
|
102
|
+
available = signal(this.runtime !== null && !this.runtime.missing).asReadonly();
|
|
96
103
|
/** The platform NativeScript is installed on; null in Node and on the web. */
|
|
97
104
|
platform = this.runtime?.platform ?? null;
|
|
98
105
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-script.js","sourceRoot":"","sources":["../src/native-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,OAAO,EACP,MAAM,EACN,wBAAwB,EACxB,6BAA6B,GAE9B,MAAM,eAAe,CAAC;;AAgCvB,2FAA2F;AAC3F,IAAI,SAAS,GAA2B,IAAI,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,SAAS,EAAE,EAAE,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED,MAAM,OAAO,GACX,+FAA+F;IAC/F,0FAA0F;IAC1F,kDAAkD,CAAC;AAErD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB;IACjC,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAI,OAAO,CAAC,cAAc,CAAkC,CAAC,QAAQ,CAAC,EAAE,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EAAE,gBAAgB,IAAI,SAAS,CAAC,gBAAgB,CAAC;IAE/D,gEAAgE;IAChE,cAAc,CAAC,KAAwB;QACrC,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK;YAAE,OAAO;QACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,OAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,gDAAgD,IAAI,GAAG,CAAC,CAAC,CAAC;YAC9F,CAAC;QACH,CAAC;IACH,CAAC;uGApDU,YAAY;wGAAZ,YAAY;;2FAAZ,YAAY;kBADxB,OAAO;;AA6DR;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA+B,EAAE;IACnE,OAAO,wBAAwB,CAAC;QAC9B,6BAA6B,CAAC,GAAG,EAAE,CACjC,MAAM,CAAC,YAAY,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAC9D;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * NativeScript's runtime, installed once and reached through one service.\n *\n * `@nativescript/react-native` puts every iOS SDK symbol and every Android class on the JavaScript\n * runtime over JSI. The service installs it, picks the function for the platform the app is on, and\n * says what is wrong in a build without it, so a component does none of that.\n *\n * ```ts\n * bootstrapApplication(App, { providers: [provideNativeScript()] });\n *\n * export class DeviceName {\n * private readonly native = inject(NativeScript);\n * protected readonly model = this.native.call({\n * ios: () => UIDevice.currentDevice.model,\n * android: () => android.os.Build.MODEL,\n * });\n * }\n * ```\n */\nimport {\n ErrorHandler,\n InjectionToken,\n Service,\n inject,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n type EnvironmentProviders,\n} from '@angular/core';\n\nexport type NativeScriptPlatform = 'ios' | 'android';\n\n/** What the service needs of NativeScript, on the platform the app is on. */\nexport interface NativeScriptRuntime {\n readonly platform: NativeScriptPlatform;\n /** Install the native API on the JavaScript runtime, with iOS's classes as globals. Idempotent. */\n install(): void;\n /** Run a worklet on the platform's main thread. */\n runOnUI<A extends unknown[], R>(worklet: (...args: A) => R, ...args: A): Promise<R>;\n /** Load a system framework whose classes the metadata names but the binary does not link. */\n loadFramework(name: string): boolean;\n /**\n * The handle `NativeScriptUIView` shows a view by: a UIView's pointer on iOS, a registry name on\n * Android. A worklet, so the main thread can be handed it. Throws for a value that is not a view.\n */\n nativeViewHandle(view: unknown): string;\n /** Why there is no runtime on a platform that should have one: a build without it, or Expo Go. */\n readonly missing?: Error;\n}\n\n/** The subset of `@nativescript/react-native`'s default export used here. */\ninterface NativeScriptModule {\n isAvailable(): boolean;\n init(metadataPath?: string, options?: { globals?: boolean }): boolean;\n runOnUI<A extends unknown[], R>(worklet: (...args: A) => R, ...args: A): Promise<R>;\n loadFramework(name: string): boolean;\n nativeViewHandle(view: unknown): string;\n androidContext(): unknown;\n}\n\n/** NativeScript's `androidContext`, once a runtime is made: see `androidContext` below. */\nlet contextOf: (() => unknown) | null = null;\n\n/**\n * The Context to build an Android view with, the current Activity, as `new\n * android.widget.TextView(androidContext())` needs. `null` on iOS, in Node, and before NativeScript\n * is installed. A function of this package's, so a component file can name it without importing\n * `@nativescript/react-native`, which Node cannot load.\n */\nexport function androidContext(): unknown {\n return contextOf?.() ?? null;\n}\n\nconst MISSING =\n '[angular-native] @nativescript/react-native is not in this build of the app. Install it, add ' +\n '\"@ng-native/nativescript\" to the plugins in app.json and rebuild (\"npx expo run:ios\" or ' +\n '\"npx expo run:android\"). Expo Go cannot load it.';\n\n/**\n * The runtime for the platform the app is on, or null where there is none to install: Node, where\n * a test runs, and the web. On a device without the native half, Expo Go among them, it is one\n * that says so as it is used: the rest of the app still runs, and the feature that needs NativeScript\n * fails with what to do about it, as a missing Expo module does.\n */\nexport function nativeScriptRuntime(): NativeScriptRuntime | null {\n let platform: string;\n try {\n platform = (require('react-native') as { Platform: { OS: string } }).Platform.OS;\n } catch {\n return null;\n }\n if (platform !== 'ios' && platform !== 'android') return null;\n const ns = (require('@nativescript/react-native') as { default: NativeScriptModule }).default;\n if (!ns.isAvailable()) {\n const missing = new Error(MISSING);\n return {\n platform,\n missing,\n install: () => {},\n runOnUI: () => Promise.reject(missing),\n loadFramework: () => true,\n nativeViewHandle: () => {\n throw missing;\n },\n };\n }\n contextOf = platform === 'android' ? ns.androidContext : null;\n return {\n platform,\n // Globals on iOS: `UIDevice.currentDevice` rather than `NativeScript.getClass('UIDevice')`. The\n // package defaults them off so UIKit is not touched from the JavaScript thread by accident;\n // `runOnUI` is still the way to touch a view. Android's packages are globals either way.\n install: () => void ns.init('', { globals: platform === 'ios' }),\n runOnUI: (worklet, ...args) => ns.runOnUI(worklet, ...args),\n // Android loads classes from the APK's classpath; there is nothing to load.\n loadFramework: (name) => platform !== 'ios' || ns.loadFramework(name),\n nativeViewHandle: ns.nativeViewHandle,\n };\n}\n\n/** Where there is no runtime. A worklet, as the runtime's own is; an object, as `nsView` explains. */\nconst noRuntime = {\n nativeViewHandle(view: unknown): string {\n 'worklet';\n throw new Error(`[angular-native] No NativeScript runtime to take ${String(view)}'s handle.`);\n },\n};\n\n/**\n * NativeScript, installed. Injecting it installs the runtime, once for the process; a test that\n * renders a component using it gets a service whose `platform` is null and whose calls answer\n * `undefined`, with no simulator.\n */\n@Service()\nexport class NativeScript {\n /** Overridden in a test to stand in for the native runtime. */\n static readonly RUNTIME = new InjectionToken<NativeScriptRuntime | null>(\n 'angular-native.nativeScriptRuntime',\n { factory: nativeScriptRuntime },\n );\n\n private readonly runtime = inject(NativeScript.RUNTIME);\n private readonly errors = inject(ErrorHandler);\n\n /** The platform NativeScript is installed on; null in Node and on the web. */\n readonly platform: NativeScriptPlatform | null = this.runtime?.platform ?? null;\n\n constructor() {\n this.runtime?.install();\n }\n\n /**\n * Call the function for this platform, synchronously, on the JavaScript thread, and answer what\n * it returns. `undefined` on a platform the object has no function for, and where there is no\n * runtime. Reading a value or calling a non-UI API is fine here on both platforms; a view is\n * touched through `runOnUI`. Throws in a build without NativeScript, rather than leave the\n * function to fail on the first native class it names.\n */\n call<T>(calls: { readonly ios?: () => T; readonly android?: () => T }): T | undefined {\n const call = this.platform && calls[this.platform];\n if (call && this.runtime?.missing) throw this.runtime.missing;\n return call ? call() : undefined;\n }\n\n /**\n * Run a worklet on the platform's main thread, where views can be touched, and answer what it\n * returns. On iOS it runs on the Worklets UI runtime and captures what it reads by value; on\n * Android it borrows this runtime while the JavaScript thread waits. Either way pass state as\n * arguments rather than reading `this` inside it.\n */\n runOnUI<A extends unknown[], R>(worklet: (...args: A) => R, ...args: A): Promise<R | undefined> {\n return this.runtime ? this.runtime.runOnUI(worklet, ...args) : Promise.resolve(undefined);\n }\n\n /** The handle `<ns-view>` binds for a view; see `NativeScriptRuntime.nativeViewHandle`. */\n readonly nativeViewHandle: (view: unknown) => string =\n this.runtime?.nativeViewHandle ?? noRuntime.nativeViewHandle;\n\n /** Load each named system framework (iOS), such as SceneKit. */\n loadFrameworks(names: readonly string[]): void {\n if (this.platform !== 'ios') return;\n for (const name of names) {\n if (!this.runtime!.loadFramework(name)) {\n this.errors.handleError(new Error(`[angular-native] NativeScript could not load ${name}.`));\n }\n }\n }\n}\n\nexport interface NativeScriptOptions {\n /** System frameworks to load on iOS before anything under these providers runs. */\n readonly frameworks?: readonly string[];\n}\n\n/**\n * Install NativeScript as these providers' injector is created: at bootstrap for the app's, or as\n * a route is first entered for a route's, so a feature that needs SceneKit pays for it there.\n */\nexport function provideNativeScript(options: NativeScriptOptions = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n provideEnvironmentInitializer(() =>\n inject(NativeScript).loadFrameworks(options.frameworks ?? []),\n ),\n ]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"native-script.js","sourceRoot":"","sources":["../src/native-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,OAAO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Ac,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAC9D;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * NativeScript's runtime, installed once and reached through one service.\n *\n * `@nativescript/react-native` puts every iOS SDK symbol and every Android class on the JavaScript\n * runtime over JSI. The service installs it, picks the function for the platform the app is on, and\n * says what is wrong in a build without it, so a component does none of that.\n *\n * ```ts\n * bootstrapApplication(App, { providers: [provideNativeScript()] });\n *\n * export class DeviceName {\n * private readonly native = inject(NativeScript);\n * protected readonly model = this.native.call({\n * ios: () => UIDevice.currentDevice.model,\n * android: () => android.os.Build.MODEL,\n * });\n * }\n * ```\n */\nimport {\n ErrorHandler,\n InjectionToken,\n Service,\n inject,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n type EnvironmentProviders,\n signal,\n type Signal,\n} from '@angular/core';\n\nexport type NativeScriptPlatform = 'ios' | 'android';\n\n/** What the service needs of NativeScript, on the platform the app is on. */\nexport interface NativeScriptRuntime {\n readonly platform: NativeScriptPlatform;\n /** Install the native API on the JavaScript runtime, with iOS's classes as globals. Idempotent. */\n install(): void;\n /** Run a worklet on the platform's main thread. */\n runOnUI<A extends unknown[], R>(worklet: (...args: A) => R, ...args: A): Promise<R>;\n /** Load a system framework whose classes the metadata names but the binary does not link. */\n loadFramework(name: string): boolean;\n /**\n * The handle `NativeScriptUIView` shows a view by: a UIView's pointer on iOS, a registry name on\n * Android. A worklet, so the main thread can be handed it. Throws for a value that is not a view.\n */\n nativeViewHandle(view: unknown): string;\n /** Why there is no runtime on a platform that should have one: a build without it, or Expo Go. */\n readonly missing?: Error;\n}\n\n/** The subset of `@nativescript/react-native`'s default export used here. */\ninterface NativeScriptModule {\n isAvailable(): boolean;\n init(metadataPath?: string, options?: { globals?: boolean }): boolean;\n runOnUI<A extends unknown[], R>(worklet: (...args: A) => R, ...args: A): Promise<R>;\n loadFramework(name: string): boolean;\n nativeViewHandle(view: unknown): string;\n androidContext(): unknown;\n}\n\n/** NativeScript's `androidContext`, once a runtime is made: see `androidContext` below. */\nlet contextOf: (() => unknown) | null = null;\n\n/**\n * The Context to build an Android view with, the current Activity, as `new\n * android.widget.TextView(androidContext())` needs. `null` on iOS, in Node, and before NativeScript\n * is installed. A function of this package's, so a component file can name it without importing\n * `@nativescript/react-native`, which Node cannot load.\n */\nexport function androidContext(): unknown {\n return contextOf?.() ?? null;\n}\n\nconst MISSING =\n '[angular-native] @nativescript/react-native is not in this build of the app. Install it, add ' +\n '\"@ng-native/nativescript\" to the plugins in app.json and rebuild (\"npx expo run:ios\" or ' +\n '\"npx expo run:android\"). Expo Go cannot load it.';\n\n/**\n * The runtime for the platform the app is on, or null where there is none to install: Node, where\n * a test runs, and the web. On a device without the native half, Expo Go among them, it is one\n * that says so as it is used: the rest of the app still runs, and the feature that needs NativeScript\n * fails with what to do about it, as a missing Expo module does.\n */\nexport function nativeScriptRuntime(): NativeScriptRuntime | null {\n let platform: string;\n try {\n platform = (require('react-native') as { Platform: { OS: string } }).Platform.OS;\n } catch {\n return null;\n }\n if (platform !== 'ios' && platform !== 'android') return null;\n const ns = (require('@nativescript/react-native') as { default: NativeScriptModule }).default;\n if (!ns.isAvailable()) {\n const missing = new Error(MISSING);\n return {\n platform,\n missing,\n install: () => {},\n runOnUI: () => Promise.reject(missing),\n loadFramework: () => true,\n nativeViewHandle: () => {\n throw missing;\n },\n };\n }\n contextOf = platform === 'android' ? ns.androidContext : null;\n return {\n platform,\n // Globals on iOS: `UIDevice.currentDevice` rather than `NativeScript.getClass('UIDevice')`. The\n // package defaults them off so UIKit is not touched from the JavaScript thread by accident;\n // `runOnUI` is still the way to touch a view. Android's packages are globals either way.\n install: () => void ns.init('', { globals: platform === 'ios' }),\n runOnUI: (worklet, ...args) => ns.runOnUI(worklet, ...args),\n // Android loads classes from the APK's classpath; there is nothing to load.\n loadFramework: (name) => platform !== 'ios' || ns.loadFramework(name),\n nativeViewHandle: ns.nativeViewHandle,\n };\n}\n\n/** Where there is no runtime. A worklet, as the runtime's own is; an object, as `nsView` explains. */\nconst noRuntime = {\n nativeViewHandle(view: unknown): string {\n 'worklet';\n throw new Error(`[angular-native] No NativeScript runtime to take ${String(view)}'s handle.`);\n },\n};\n\n/**\n * NativeScript, installed. Injecting it installs the runtime, once for the process; a test that\n * renders a component using it gets a service whose `platform` is null and whose calls answer\n * `undefined`, with no simulator.\n */\n@Service()\nexport class NativeScript {\n /** Overridden in a test to stand in for the native runtime. */\n static readonly RUNTIME = new InjectionToken<NativeScriptRuntime | null>(\n 'angular-native.nativeScriptRuntime',\n { factory: nativeScriptRuntime },\n );\n\n private readonly runtime = inject(NativeScript.RUNTIME);\n private readonly errors = inject(ErrorHandler);\n\n /**\n * Whether the runtime is here and in the build. False where there is no runtime - in Node, on\n * the web and on macOS - where `call()` answers `undefined` and `runOnUI()` resolves to it; and\n * false in a build without NativeScript, where `call()` with a function for the platform throws\n * and `runOnUI()` rejects, saying so. `nativeViewHandle()` throws in both.\n */\n readonly available: Signal<boolean> = signal(\n this.runtime !== null && !this.runtime.missing,\n ).asReadonly();\n\n /** The platform NativeScript is installed on; null in Node and on the web. */\n readonly platform: NativeScriptPlatform | null = this.runtime?.platform ?? null;\n\n constructor() {\n this.runtime?.install();\n }\n\n /**\n * Call the function for this platform, synchronously, on the JavaScript thread, and answer what\n * it returns. `undefined` on a platform the object has no function for, and where there is no\n * runtime. Reading a value or calling a non-UI API is fine here on both platforms; a view is\n * touched through `runOnUI`. Throws in a build without NativeScript, rather than leave the\n * function to fail on the first native class it names.\n */\n call<T>(calls: { readonly ios?: () => T; readonly android?: () => T }): T | undefined {\n const call = this.platform && calls[this.platform];\n if (call && this.runtime?.missing) throw this.runtime.missing;\n return call ? call() : undefined;\n }\n\n /**\n * Run a worklet on the platform's main thread, where views can be touched, and answer what it\n * returns. On iOS it runs on the Worklets UI runtime and captures what it reads by value; on\n * Android it borrows this runtime while the JavaScript thread waits. Either way pass state as\n * arguments rather than reading `this` inside it.\n */\n runOnUI<A extends unknown[], R>(worklet: (...args: A) => R, ...args: A): Promise<R | undefined> {\n return this.runtime ? this.runtime.runOnUI(worklet, ...args) : Promise.resolve(undefined);\n }\n\n /** The handle `<ns-view>` binds for a view; see `NativeScriptRuntime.nativeViewHandle`. */\n readonly nativeViewHandle: (view: unknown) => string =\n this.runtime?.nativeViewHandle ?? noRuntime.nativeViewHandle;\n\n /** Load each named system framework (iOS), such as SceneKit. */\n loadFrameworks(names: readonly string[]): void {\n if (this.platform !== 'ios') return;\n for (const name of names) {\n if (!this.runtime!.loadFramework(name)) {\n this.errors.handleError(new Error(`[angular-native] NativeScript could not load ${name}.`));\n }\n }\n }\n}\n\nexport interface NativeScriptOptions {\n /** System frameworks to load on iOS before anything under these providers runs. */\n readonly frameworks?: readonly string[];\n}\n\n/**\n * Install NativeScript as these providers' injector is created: at bootstrap for the app's, or as\n * a route is first entered for a route's, so a feature that needs SceneKit pays for it there.\n */\nexport function provideNativeScript(options: NativeScriptOptions = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n provideEnvironmentInitializer(() =>\n inject(NativeScript).loadFrameworks(options.frameworks ?? []),\n ),\n ]);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/nativescript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "NativeScript's iOS and Android APIs in Angular Native: provideNativeScript, a NativeScript service and a <native-view> for a UIView built in TypeScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "dist/index.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ng-native/fabric": "0.
|
|
17
|
+
"@ng-native/fabric": "0.23.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@angular/core": "^22.0.0",
|