ember-nativescript 0.0.0-stage → 0.1.2

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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +421 -2
  3. package/dist/components/NativeFrame.d.ts +28 -0
  4. package/dist/components/NativeFrame.d.ts.map +1 -0
  5. package/dist/components/NativeFrame.js +39 -0
  6. package/dist/components/NativeFrame.js.map +1 -0
  7. package/dist/components/NativeList.d.ts +32 -0
  8. package/dist/components/NativeList.d.ts.map +1 -0
  9. package/dist/components/NativeList.js +44 -0
  10. package/dist/components/NativeList.js.map +1 -0
  11. package/dist/components/Platform.d.ts +21 -0
  12. package/dist/components/Platform.d.ts.map +1 -0
  13. package/dist/components/Platform.js +22 -0
  14. package/dist/components/Platform.js.map +1 -0
  15. package/dist/src/adapter.d.ts +51 -0
  16. package/dist/src/adapter.d.ts.map +1 -0
  17. package/dist/src/bind.d.ts +12 -0
  18. package/dist/src/bind.d.ts.map +1 -0
  19. package/dist/src/bind.js +32 -0
  20. package/dist/src/bind.js.map +1 -0
  21. package/dist/src/dom.d.ts +104 -0
  22. package/dist/src/dom.d.ts.map +1 -0
  23. package/dist/src/dom.js +329 -0
  24. package/dist/src/dom.js.map +1 -0
  25. package/dist/src/elements.d.ts +17 -0
  26. package/dist/src/elements.d.ts.map +1 -0
  27. package/dist/src/elements.js +52 -0
  28. package/dist/src/elements.js.map +1 -0
  29. package/dist/src/fake-adapter.d.ts +117 -0
  30. package/dist/src/fake-adapter.d.ts.map +1 -0
  31. package/dist/src/fake-adapter.js +400 -0
  32. package/dist/src/fake-adapter.js.map +1 -0
  33. package/dist/src/frame-host.d.ts +12 -0
  34. package/dist/src/frame-host.d.ts.map +1 -0
  35. package/dist/src/frame-host.js +34 -0
  36. package/dist/src/frame-host.js.map +1 -0
  37. package/dist/src/index.d.ts +18 -0
  38. package/dist/src/index.d.ts.map +1 -0
  39. package/dist/src/index.js +17 -0
  40. package/dist/src/list.d.ts +21 -0
  41. package/dist/src/list.d.ts.map +1 -0
  42. package/dist/src/list.js +96 -0
  43. package/dist/src/list.js.map +1 -0
  44. package/dist/src/modifier.d.ts +11 -0
  45. package/dist/src/modifier.d.ts.map +1 -0
  46. package/dist/src/modifier.js +27 -0
  47. package/dist/src/modifier.js.map +1 -0
  48. package/dist/src/native-view.d.ts +11 -0
  49. package/dist/src/native-view.d.ts.map +1 -0
  50. package/dist/src/native-view.js +28 -0
  51. package/dist/src/native-view.js.map +1 -0
  52. package/dist/src/nativescript-adapter.d.ts +26 -0
  53. package/dist/src/nativescript-adapter.d.ts.map +1 -0
  54. package/dist/src/nativescript-adapter.js +172 -0
  55. package/dist/src/nativescript-adapter.js.map +1 -0
  56. package/dist/src/nativescript-app.d.ts +18 -0
  57. package/dist/src/nativescript-app.d.ts.map +1 -0
  58. package/dist/src/nativescript-app.js +32 -0
  59. package/dist/src/nativescript-app.js.map +1 -0
  60. package/dist/src/navigator.d.ts +65 -0
  61. package/dist/src/navigator.d.ts.map +1 -0
  62. package/dist/src/navigator.js +141 -0
  63. package/dist/src/navigator.js.map +1 -0
  64. package/dist/src/owner.d.ts +39 -0
  65. package/dist/src/owner.d.ts.map +1 -0
  66. package/dist/src/owner.js +185 -0
  67. package/dist/src/owner.js.map +1 -0
  68. package/dist/src/platform.d.ts +5 -0
  69. package/dist/src/platform.d.ts.map +1 -0
  70. package/dist/src/platform.js +11 -0
  71. package/dist/src/platform.js.map +1 -0
  72. package/dist/src/render.d.ts +18 -0
  73. package/dist/src/render.d.ts.map +1 -0
  74. package/dist/src/render.js +32 -0
  75. package/dist/src/render.js.map +1 -0
  76. package/dist/src/testing-core.d.ts +147 -0
  77. package/dist/src/testing-core.d.ts.map +1 -0
  78. package/dist/src/testing-core.js +110 -0
  79. package/dist/src/testing-core.js.map +1 -0
  80. package/dist/src/testing.d.ts +38 -0
  81. package/dist/src/testing.d.ts.map +1 -0
  82. package/dist/src/testing.js +74 -0
  83. package/dist/src/testing.js.map +1 -0
  84. package/dist/src/vendor-excludes.d.ts +6 -0
  85. package/dist/src/vendor-excludes.d.ts.map +1 -0
  86. package/dist/src/vendor-excludes.js +38 -0
  87. package/dist/src/vendor-excludes.js.map +1 -0
  88. package/dist/src/vite.d.ts +10 -0
  89. package/dist/src/vite.d.ts.map +1 -0
  90. package/dist/src/vite.js +14 -0
  91. package/dist/src/vite.js.map +1 -0
  92. package/dist/src/vitest.d.ts +5 -0
  93. package/dist/src/vitest.d.ts.map +1 -0
  94. package/dist/src/vitest.js +23 -0
  95. package/dist/src/vitest.js.map +1 -0
  96. package/dist/types/glint.d.ts +164 -0
  97. package/dist/vendor/runtime--fcdnjmJ.js +43 -0
  98. package/dist/vendor/runtime--fcdnjmJ.js.map +1 -0
  99. package/package.json +105 -4
@@ -0,0 +1,32 @@
1
+ import { Application, Frame } from "@nativescript/core";
2
+ import { createOwner } from "./owner.js";
3
+ import { NativeScriptAdapter } from "./nativescript-adapter.js";
4
+ import { FrameNavigationHost } from "./frame-host.js";
5
+ import { Navigator } from "./navigator.js";
6
+ import { createDocument } from "./render.js";
7
+ // src/nativescript-app.ts
8
+ function createNativeApp(options) {
9
+ const document = createDocument(new NativeScriptAdapter());
10
+ const owner = createOwner({
11
+ services: options.services,
12
+ modules: options.modules
13
+ });
14
+ const frame = new Frame();
15
+ const navigator = new Navigator(document, new FrameNavigationHost(frame), owner);
16
+ owner.register("service:navigator", navigator, { instantiate: false });
17
+ Application.run({ create() {
18
+ navigator.navigate(options.main, {
19
+ args: options.args,
20
+ name: "main",
21
+ animated: false
22
+ });
23
+ return frame;
24
+ } });
25
+ return {
26
+ owner,
27
+ navigator
28
+ };
29
+ }
30
+ export { FrameNavigationHost, createNativeApp };
31
+
32
+ //# sourceMappingURL=nativescript-app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativescript-app.js","names":["Application","Frame","createOwner","NativeScriptAdapter","FrameNavigationHost","Navigator","createDocument","createNativeApp","options","document","owner","services","modules","frame","navigator","register","instantiate","run","create","navigate","main","args","name","animated"],"sources":["../../src/nativescript-app.ts"],"sourcesContent":["// Starts an Ember app on NativeScript: a document whose elements are NativeScript views, an owner for services, a\n// Frame for screens, and the first screen. The Navigator is the `navigator` service, so any component can\n// `@service navigator` to move between screens; screens also get it as `@nav`.\n//\n// createNativeApp({ main: Home, services: { session: SessionService } });\n\nimport { Application, Frame } from '@nativescript/core';\n\nimport { createOwner, type Modules, type NativeOwner, type ServiceEntry } from './owner.ts';\nimport { NativeScriptAdapter } from './nativescript-adapter.ts';\nimport { FrameNavigationHost } from './frame-host.ts';\nimport { type FrameHost, Navigator } from './navigator.ts';\nimport { createDocument } from './render.ts';\n\nexport interface NativeAppOptions {\n /** The first screen. */\n main: object;\n args?: Record<string, unknown>;\n /** Services by name, or a module glob of ./services. */\n services?: Record<string, ServiceEntry>;\n modules?: Modules;\n}\n\nexport interface NativeApp {\n owner: NativeOwner;\n navigator: Navigator;\n}\n\nexport { FrameNavigationHost };\n\nexport function createNativeApp(options: NativeAppOptions): NativeApp {\n const document = createDocument(new NativeScriptAdapter());\n const owner = createOwner({ services: options.services, modules: options.modules });\n const frame = new Frame();\n const navigator = new Navigator(document, new FrameNavigationHost(frame) as FrameHost, owner);\n owner.register('service:navigator', navigator, { instantiate: false });\n\n Application.run({\n create() {\n // A Frame queues navigations made before it is loaded and runs them once it is.\n navigator.navigate(options.main, { args: options.args, name: 'main', animated: false });\n return frame;\n },\n });\n\n return { owner, navigator };\n}\n"],"mappings":";;;;;;;AA8BA,SAAgBO,gBAAgBC,SAAsC;CACpE,MAAMC,WAAWH,eAAe,IAAIH,oBAAoB,CAAC;CACzD,MAAMO,QAAQR,YAAY;EAAES,UAAUH,QAAQG;EAAUC,SAASJ,QAAQI;CAAQ,CAAC;CAClF,MAAMC,QAAQ,IAAIZ,MAAM;CACxB,MAAMa,YAAY,IAAIT,UAAUI,UAAU,IAAIL,oBAAoBS,KAAK,GAAgBH,KAAK;CAC5FA,MAAMK,SAAS,qBAAqBD,WAAW,EAAEE,aAAa,MAAM,CAAC;CAErEhB,YAAYiB,IAAI,EACdC,SAAS;EAEPJ,UAAUK,SAASX,QAAQY,MAAM;GAAEC,MAAMb,QAAQa;GAAMC,MAAM;GAAQC,UAAU;EAAM,CAAC;EACtF,OAAOV;CACT,EACF,CAAC;CAED,OAAO;EAAEH;EAAOI;CAAU;AAC5B"}
@@ -0,0 +1,65 @@
1
+ import type { NativeDocument } from './dom.js';
2
+ import { type NativeRoot } from './render.js';
3
+ export interface ShowOptions {
4
+ animated: boolean;
5
+ /** Passed to the host as is: a NativeScript NavigationTransition. */
6
+ transition?: unknown;
7
+ clearHistory: boolean;
8
+ backstackVisible: boolean;
9
+ }
10
+ export interface ModalHostOptions {
11
+ fullscreen: boolean;
12
+ animated: boolean;
13
+ stretched: boolean;
14
+ /** The host calls this once the modal is gone, with the result it was closed with (none when dismissed). */
15
+ onClose: (result?: unknown) => void;
16
+ }
17
+ export interface FrameHost<View = unknown> {
18
+ show(page: View, options: ShowOptions): void;
19
+ back(): void;
20
+ showModal(view: View, options: ModalHostOptions): void;
21
+ closeModal(view: View, result: unknown): void;
22
+ }
23
+ export interface NavigateOptions {
24
+ args?: Record<string, unknown>;
25
+ /** A name for the screen, for `navigator.current` and tests. */
26
+ name?: string;
27
+ /** Animates the change of page. Defaults to true except for the first screen. */
28
+ animated?: boolean;
29
+ transition?: unknown;
30
+ /** Drops every screen before this one: there is nothing to go back to. */
31
+ clearHistory?: boolean;
32
+ /** False to leave this screen out of the back stack once the next one is shown (a splash, a login). */
33
+ backstackVisible?: boolean;
34
+ }
35
+ export interface ModalOptions {
36
+ args?: Record<string, unknown>;
37
+ fullscreen?: boolean;
38
+ animated?: boolean;
39
+ stretched?: boolean;
40
+ /** The tag of the view the modal renders into. */
41
+ root?: string;
42
+ }
43
+ export declare class Navigator {
44
+ #private;
45
+ readonly document: NativeDocument;
46
+ readonly host: FrameHost;
47
+ readonly owner: object;
48
+ /** How many screens are in the stack. */
49
+ depth: number;
50
+ /** The name of the screen on top. */
51
+ current: string | undefined;
52
+ /** How many modals are open. */
53
+ modals: number;
54
+ constructor(document: NativeDocument, host: FrameHost, owner?: object);
55
+ get canGoBack(): boolean;
56
+ navigate: (component: object, options?: NavigateOptions) => NativeRoot;
57
+ /** Goes back a screen. The screen is destroyed when its page has left. */
58
+ back: () => void;
59
+ showModal: <Result = unknown>(component: object, options?: ModalOptions) => Promise<Result | undefined>;
60
+ /** Closes the modal on top with a result, as its own `@closeModal` would. */
61
+ closeModal: (result?: unknown) => void;
62
+ /** Destroys every screen, and closes open modals with no result. For a frame that goes away (a tab's). */
63
+ destroy: () => void;
64
+ }
65
+ //# sourceMappingURL=navigator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigator.d.ts","sourceRoot":"","sources":["../../src/navigator.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,aAAa,CAAC;AAE5D,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,qEAAqE;IACrE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,4GAA4G;IAC5G,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,SAAS,CAAC,IAAI,GAAG,OAAO;IACvC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC7C,IAAI,IAAI,IAAI,CAAC;IACb,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAA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OAAO,EAAE,WAAW,MAAM,EAAE,UAAS,YAAiB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgCxG;IAEF,6EAA6E;IAC7E,UAAU,GAAI,SAAS,OAAO,KAAG,IAAI,CAEnC;IAEF,0GAA0G;IAC1G,OAAO,QAAO,IAAI,CAIhB;CAkBH"}
@@ -0,0 +1,141 @@
1
+ import { tracked } from "@glimmer/tracking";
2
+ import { renderNative } from "./render.js";
3
+ import { b as decorateFieldV2, i as initializeDeferredDecorator } from "../vendor/runtime--fcdnjmJ.js";
4
+ // src/navigator.ts
5
+ var Navigator = class {
6
+ static {
7
+ decorateFieldV2(this.prototype, "depth", [tracked], function() {
8
+ return 0;
9
+ });
10
+ }
11
+ #depth = (initializeDeferredDecorator(this, "depth"), void 0);
12
+ /** How many screens are in the stack. */
13
+ static {
14
+ decorateFieldV2(this.prototype, "current", [tracked]);
15
+ }
16
+ #current = (initializeDeferredDecorator(this, "current"), void 0);
17
+ /** The name of the screen on top. */
18
+ static {
19
+ decorateFieldV2(this.prototype, "modals", [tracked], function() {
20
+ return 0;
21
+ });
22
+ }
23
+ #modals = (initializeDeferredDecorator(this, "modals"), void 0);
24
+ /** How many modals are open. */
25
+ #stack = [];
26
+ #closers = [];
27
+ #dropped = [];
28
+ constructor(document, host, owner = {}) {
29
+ this.document = document;
30
+ this.host = host;
31
+ this.owner = owner;
32
+ }
33
+ get canGoBack() {
34
+ return this.depth > 1;
35
+ }
36
+ navigate = (component, options = {}) => {
37
+ const root = renderNative(component, {
38
+ document: this.document,
39
+ root: "page",
40
+ owner: this.owner,
41
+ args: {
42
+ ...options.args,
43
+ nav: this
44
+ }
45
+ });
46
+ const onNavigatedTo = () => this.#destroyDropped();
47
+ const onNavigatedFrom = (data) => {
48
+ if (data.isBackNavigation) this.#popped(screen);
49
+ };
50
+ const screen = {
51
+ name: options.name ?? "screen",
52
+ root,
53
+ backstackVisible: options.backstackVisible ?? true,
54
+ release() {
55
+ root.element.removeEventListener("navigatedTo", onNavigatedTo);
56
+ root.element.removeEventListener("navigatedFrom", onNavigatedFrom);
57
+ root.destroy();
58
+ }
59
+ };
60
+ const previous = this.#stack.at(-1);
61
+ if (options.clearHistory) this.#dropped.push(...this.#stack.splice(0));
62
+ else if (previous && !previous.backstackVisible) this.#dropped.push(this.#stack.pop());
63
+ root.element.addEventListener("navigatedTo", onNavigatedTo);
64
+ root.element.addEventListener("navigatedFrom", onNavigatedFrom);
65
+ this.#stack.push(screen);
66
+ this.#changed();
67
+ this.host.show(root.view, {
68
+ animated: options.animated ?? this.#stack.length + this.#dropped.length > 1,
69
+ transition: options.transition,
70
+ clearHistory: options.clearHistory ?? false,
71
+ backstackVisible: screen.backstackVisible
72
+ });
73
+ return root;
74
+ };
75
+ /** Goes back a screen. The screen is destroyed when its page has left. */
76
+ back = () => {
77
+ if (this.#stack.length > 1) this.host.back();
78
+ };
79
+ showModal = (component, options = {}) => {
80
+ return new Promise((resolve) => {
81
+ let open = true;
82
+ let root;
83
+ const closeModal = (result) => {
84
+ if (open && root) this.host.closeModal(root.view, result);
85
+ };
86
+ const onClose = (result) => {
87
+ if (!open) return;
88
+ open = false;
89
+ this.#closers.splice(this.#closers.indexOf(closeModal), 1);
90
+ this.modals = this.#closers.length;
91
+ root?.destroy();
92
+ resolve(result);
93
+ };
94
+ root = renderNative(component, {
95
+ document: this.document,
96
+ root: options.root ?? "contentView",
97
+ owner: this.owner,
98
+ args: {
99
+ ...options.args,
100
+ nav: this,
101
+ closeModal
102
+ }
103
+ });
104
+ this.#closers.push(closeModal);
105
+ this.modals = this.#closers.length;
106
+ this.host.showModal(root.view, {
107
+ fullscreen: options.fullscreen ?? false,
108
+ animated: options.animated ?? true,
109
+ stretched: options.stretched ?? false,
110
+ onClose
111
+ });
112
+ });
113
+ };
114
+ /** Closes the modal on top with a result, as its own `@closeModal` would. */
115
+ closeModal = (result) => {
116
+ this.#closers.at(-1)?.(result);
117
+ };
118
+ /** Destroys every screen, and closes open modals with no result. For a frame that goes away (a tab's). */
119
+ destroy = () => {
120
+ for (const screen of [...this.#stack.splice(0), ...this.#dropped.splice(0)]) screen.release();
121
+ this.#changed();
122
+ for (const close of [...this.#closers].reverse()) close();
123
+ };
124
+ #popped(screen) {
125
+ const index = this.#stack.indexOf(screen);
126
+ if (index === -1) return;
127
+ this.#stack.splice(index, 1);
128
+ this.#changed();
129
+ screen.release();
130
+ }
131
+ #changed() {
132
+ this.depth = this.#stack.length;
133
+ this.current = this.#stack.at(-1)?.name;
134
+ }
135
+ #destroyDropped() {
136
+ for (const screen of this.#dropped.splice(0)) screen.release();
137
+ }
138
+ };
139
+ export { Navigator };
140
+
141
+ //# sourceMappingURL=navigator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigator.js","names":["tracked","renderNative","g","i","Navigator","prototype","depth","current","modals","constructor","document","host","owner","canGoBack","navigate","component","options","root","args","nav","onNavigatedTo","onNavigatedFrom","data","isBackNavigation","screen","name","backstackVisible","release","element","removeEventListener","destroy","previous","at","clearHistory","push","splice","pop","addEventListener","show","view","animated","length","transition","back","showModal","Promise","resolve","open","closeModal","result","onClose","indexOf","fullscreen","stretched","close","reverse","index"],"sources":["../../src/navigator.ts"],"sourcesContent":["// Screens and modals, the way NativeScript-Vue's navigateTo, navigateBack, showModal and closeModal work.\n//\n// Each screen is a component rendered into its own <page>, shown through the host (NativeScript's Frame on a\n// device, an array in tests). The page's own events keep the stack honest: a page leaves with `navigatedFrom` and\n// `isBackNavigation`, whether the back came from here, from Android's back button or from iOS's swipe, and that is\n// when its render is destroyed. Pages the Frame drops without a back (clearHistory, backstackVisible: false) are\n// destroyed once the next page has arrived (`navigatedTo`).\n//\n// A modal is a component rendered into a view of its own and shown over the current page. It gets `@closeModal`;\n// showModal() resolves with what it passes, or with undefined when the user dismisses it.\n\nimport { tracked } from '@glimmer/tracking';\n\nimport type { NativeDocument } from './dom.ts';\nimport { type NativeRoot, renderNative } from './render.ts';\n\nexport interface ShowOptions {\n animated: boolean;\n /** Passed to the host as is: a NativeScript NavigationTransition. */\n transition?: unknown;\n clearHistory: boolean;\n backstackVisible: boolean;\n}\n\nexport interface ModalHostOptions {\n fullscreen: boolean;\n animated: boolean;\n stretched: boolean;\n /** The host calls this once the modal is gone, with the result it was closed with (none when dismissed). */\n onClose: (result?: unknown) => void;\n}\n\nexport interface FrameHost<View = unknown> {\n show(page: View, options: ShowOptions): void;\n back(): void;\n showModal(view: View, options: ModalHostOptions): void;\n closeModal(view: View, result: unknown): void;\n}\n\nexport interface NavigateOptions {\n args?: Record<string, unknown>;\n /** A name for the screen, for `navigator.current` and tests. */\n name?: string;\n /** Animates the change of page. Defaults to true except for the first screen. */\n animated?: boolean;\n transition?: unknown;\n /** Drops every screen before this one: there is nothing to go back to. */\n clearHistory?: boolean;\n /** False to leave this screen out of the back stack once the next one is shown (a splash, a login). */\n backstackVisible?: boolean;\n}\n\nexport interface ModalOptions {\n args?: Record<string, unknown>;\n fullscreen?: boolean;\n animated?: boolean;\n stretched?: boolean;\n /** The tag of the view the modal renders into. */\n root?: string;\n}\n\ninterface Screen {\n name: string;\n root: NativeRoot;\n backstackVisible: boolean;\n /** Stops listening to the page and destroys the render. */\n release(): void;\n}\n\ninterface NavigatedData {\n isBackNavigation?: boolean;\n}\n\nexport class Navigator {\n /** How many screens are in the stack. */\n @tracked depth = 0;\n /** The name of the screen on top. */\n @tracked current: string | undefined;\n /** How many modals are open. */\n @tracked modals = 0;\n readonly #stack: Screen[] = [];\n readonly #closers: Array<(result?: unknown) => void> = [];\n // Screens the Frame dropped without a back, destroyed when the next page has arrived.\n #dropped: Screen[] = [];\n\n constructor(\n readonly document: NativeDocument,\n readonly host: FrameHost,\n readonly owner: object = {},\n ) {}\n\n get canGoBack(): boolean {\n return this.depth > 1;\n }\n\n navigate = (component: object, options: NavigateOptions = {}): NativeRoot => {\n const root = renderNative(component, {\n document: this.document,\n root: 'page',\n owner: this.owner,\n args: { ...options.args, nav: this },\n });\n const onNavigatedTo = (): void => this.#destroyDropped();\n const onNavigatedFrom = (data: unknown): void => {\n if ((data as NavigatedData).isBackNavigation) this.#popped(screen);\n };\n const screen: Screen = {\n name: options.name ?? 'screen',\n root,\n backstackVisible: options.backstackVisible ?? true,\n release() {\n root.element.removeEventListener('navigatedTo', onNavigatedTo);\n root.element.removeEventListener('navigatedFrom', onNavigatedFrom);\n root.destroy();\n },\n };\n const previous = this.#stack.at(-1);\n\n if (options.clearHistory) this.#dropped.push(...this.#stack.splice(0));\n else if (previous && !previous.backstackVisible) this.#dropped.push(this.#stack.pop()!);\n\n root.element.addEventListener('navigatedTo', onNavigatedTo);\n root.element.addEventListener('navigatedFrom', onNavigatedFrom);\n\n this.#stack.push(screen);\n this.#changed();\n this.host.show(root.view, {\n animated: options.animated ?? this.#stack.length + this.#dropped.length > 1,\n transition: options.transition,\n clearHistory: options.clearHistory ?? false,\n backstackVisible: screen.backstackVisible,\n });\n return root;\n };\n\n /** Goes back a screen. The screen is destroyed when its page has left. */\n back = (): void => {\n if (this.#stack.length > 1) this.host.back();\n };\n\n showModal = <Result = unknown>(component: object, options: ModalOptions = {}): Promise<Result | undefined> => {\n return new Promise((resolve) => {\n let open = true;\n let root: NativeRoot | undefined;\n\n const closeModal = (result?: unknown): void => {\n if (open && root) this.host.closeModal(root.view, result);\n };\n const onClose = (result?: unknown): void => {\n if (!open) return;\n open = false;\n this.#closers.splice(this.#closers.indexOf(closeModal), 1);\n this.modals = this.#closers.length;\n root?.destroy();\n resolve(result as Result | undefined);\n };\n\n root = renderNative(component, {\n document: this.document,\n root: options.root ?? 'contentView',\n owner: this.owner,\n args: { ...options.args, nav: this, closeModal },\n });\n this.#closers.push(closeModal);\n this.modals = this.#closers.length;\n this.host.showModal(root.view, {\n fullscreen: options.fullscreen ?? false,\n animated: options.animated ?? true,\n stretched: options.stretched ?? false,\n onClose,\n });\n });\n };\n\n /** Closes the modal on top with a result, as its own `@closeModal` would. */\n closeModal = (result?: unknown): void => {\n this.#closers.at(-1)?.(result);\n };\n\n /** Destroys every screen, and closes open modals with no result. For a frame that goes away (a tab's). */\n destroy = (): void => {\n for (const screen of [...this.#stack.splice(0), ...this.#dropped.splice(0)]) screen.release();\n this.#changed();\n for (const close of [...this.#closers].reverse()) close();\n };\n\n #popped(screen: Screen): void {\n const index = this.#stack.indexOf(screen);\n if (index === -1) return;\n this.#stack.splice(index, 1);\n this.#changed();\n screen.release();\n }\n\n #changed(): void {\n this.depth = this.#stack.length;\n this.current = this.#stack.at(-1)?.name;\n }\n\n #destroyDropped(): void {\n for (const screen of this.#dropped.splice(0)) screen.release();\n }\n}\n"],"mappings":";;;;AAyEA,IAAaI,YAAb,MAAuB;CAAA;EAAAF,gBAAA,KAAAG,WAAA,SAAA,CAEpBL,OAAO,GAAA,WAAA;GAAA,OAAS;EAAC,CAAA;CAAA;CAAA,UAAAG,4BAAA,MAAA,OAAA,GAAA,KAAA;;CADlB;EAAAD,gBAAA,KAAAG,WAAA,WAAA,CAGCL,OAAO,CAAA;CAAA;CAAA,YAAAG,4BAAA,MAAA,SAAA,GAAA,KAAA;;CADR;EAAAD,gBAAA,KAAAG,WAAA,UAAA,CAGCL,OAAO,GAAA,WAAA;GAAA,OAAU;EAAC,CAAA;CAAA;CAAA,WAAAG,4BAAA,MAAA,QAAA,GAAA,KAAA;;CACV,SAAmB,CAAA;CACnB,WAA8C,CAAA;CAEvD,WAAqB,CAAA;CAErBM,YACWC,UACAC,MACAC,QAAgB,CAAC,GAC1B;EAAA,KAHSF,WAAAA;EAAwB,KACxBC,OAAAA;EAAe,KACfC,QAAAA;CACR;CAEH,IAAIC,YAAqB;EACvB,OAAO,KAAKP,QAAQ;CACtB;CAEAQ,YAAYC,WAAmBC,UAA2B,CAAC,MAAkB;EAC3E,MAAMC,OAAOhB,aAAac,WAAW;GACnCL,UAAU,KAAKA;GACfO,MAAM;GACNL,OAAO,KAAKA;GACZM,MAAM;IAAE,GAAGF,QAAQE;IAAMC,KAAK;GAAK;EACrC,CAAC;EACD,MAAMC,sBAA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CAAC,EAAEP;CACrC;CAEA,kBAAwB;EACtB,KAAK,MAAMD,UAAU,KAAK,SAASW,OAAO,CAAC,GAAGX,OAAOG,QAAQ;CAC/D;AACF"}
@@ -0,0 +1,39 @@
1
+ import '@ember/renderer';
2
+ import { type Factory, type FullName, type RegisterOptions } from '@ember/owner';
3
+ import type Owner from '@ember/owner';
4
+ export type Modules = Record<string, unknown>;
5
+ export type ServiceEntry = Factory<object> | (new (...args: never[]) => object) | object;
6
+ export interface CreateOwnerOptions {
7
+ /** Module map from `import.meta.glob('./services/**\/*.ts', { eager: true })`. */
8
+ modules?: Modules;
9
+ /**
10
+ * Services by name: `{ cart: CartService, 'auth/jwt': JwtService, config: existingInstance }`.
11
+ * Classes and Ember factories are instantiated lazily as singletons; plain objects are registered as instances.
12
+ */
13
+ services?: Record<string, ServiceEntry>;
14
+ }
15
+ export interface NativeOwner extends Owner {
16
+ readonly isDestroying: boolean;
17
+ readonly isDestroyed: boolean;
18
+ destroy(): void;
19
+ ownerInjection(): object;
20
+ resolveRegistration(fullName: FullName): Factory<object> | object | undefined;
21
+ hasRegistration(fullName: FullName): boolean;
22
+ unregister(fullName: FullName): void;
23
+ registerOptions(fullName: FullName, options: RegisterOptions): void;
24
+ registeredOption<K extends keyof RegisterOptions>(fullName: FullName, optionName: K): RegisterOptions[K] | undefined;
25
+ registeredOptions(fullName: FullName): RegisterOptions | undefined;
26
+ registerOptionsForType(type: string, options: RegisterOptions): void;
27
+ registeredOptionsForType(type: string): RegisterOptions | undefined;
28
+ }
29
+ /**
30
+ * An owner for services and `@service` injections in your screens, built either from a Vite module glob or an
31
+ * explicit `services` map:
32
+ *
33
+ * createOwner(import.meta.glob('./services/**\/*.ts', { eager: true }));
34
+ * createOwner({ services: { cart: CartService, config: appConfig } });
35
+ *
36
+ * Services are made on first lookup and live as long as the owner.
37
+ */
38
+ export declare function createOwner(modulesOrOptions?: Modules | CreateOwnerOptions): NativeOwner;
39
+ //# sourceMappingURL=owner.d.ts.map
@@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AG,SAAS,CAAC;IACrH,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,eAAe,GAAG,SAAS,CAAC;IACnE,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IACrE,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;CACrE;AA0QD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,gBAAgB,GAAE,OAAO,GAAG,kBAAuB,GAAG,WAAW,CAqB5F"}
@@ -0,0 +1,185 @@
1
+ import "@ember/renderer";
2
+ import { associateDestroyableChild, destroy, isDestroyed, isDestroying, registerDestructor } from "@ember/destroyable";
3
+ import { getOwner, setOwner } from "@ember/owner";
4
+ // src/owner.ts
5
+ var FILE_EXTENSION = /\.\w{1,4}$/;
6
+ var LEADING_RELATIVE = /^(?:\.\.?\/)+/;
7
+ var CAMEL_BOUNDARY = /([a-z\d])([A-Z])/g;
8
+ var SPACES_AND_UNDERSCORES = /[ _]/g;
9
+ function dasherize(value) {
10
+ return value.replace(CAMEL_BOUNDARY, "$1_$2").toLowerCase().replace(SPACES_AND_UNDERSCORES, "-");
11
+ }
12
+ function normalizeModulePath(path) {
13
+ return path.replace(FILE_EXTENSION, "").replace(LEADING_RELATIVE, "");
14
+ }
15
+ function normalizeFullName(fullName) {
16
+ const colon = fullName.indexOf(":");
17
+ if (colon === -1) return fullName;
18
+ const type = fullName.slice(0, colon);
19
+ const rawName = fullName.slice(colon + 1);
20
+ return `${type}:${type === "component" || type === "helper" || type === "modifier" || type === "template" && rawName.startsWith("components/") ? rawName.replace(/_/g, "-") : dasherize(rawName.replace(/\./g, "/"))}`;
21
+ }
22
+ function extractDefault(module) {
23
+ return module !== null && typeof module === "object" && "default" in module ? module.default : module;
24
+ }
25
+ function isFactory(value) {
26
+ return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.create === "function";
27
+ }
28
+ var LightweightOwner = class {
29
+ #modules = /* @__PURE__ */ new Map();
30
+ #registrations = /* @__PURE__ */ new Map();
31
+ #options = /* @__PURE__ */ new Map();
32
+ #typeOptions = /* @__PURE__ */ new Map();
33
+ #cache = /* @__PURE__ */ new Map();
34
+ constructor(modules) {
35
+ for (const path in modules) if (Object.hasOwn(modules, path)) this.#modules.set(normalizeModulePath(path), modules[path]);
36
+ registerDestructor(this, () => {
37
+ this.#cache.clear();
38
+ });
39
+ }
40
+ get isDestroying() {
41
+ return isDestroying(this);
42
+ }
43
+ get isDestroyed() {
44
+ return isDestroyed(this);
45
+ }
46
+ destroy() {
47
+ destroy(this);
48
+ }
49
+ ownerInjection() {
50
+ const injection = {};
51
+ setOwner(injection, this);
52
+ return injection;
53
+ }
54
+ register(fullName, factory, options) {
55
+ const normalized = normalizeFullName(fullName);
56
+ this.#registrations.set(normalized, factory);
57
+ this.#cache.delete(normalized);
58
+ if (options) this.#options.set(normalized, {
59
+ ...this.#options.get(normalized),
60
+ ...options
61
+ });
62
+ }
63
+ unregister(fullName) {
64
+ const normalized = normalizeFullName(fullName);
65
+ this.#registrations.delete(normalized);
66
+ this.#options.delete(normalized);
67
+ this.#cache.delete(normalized);
68
+ }
69
+ hasRegistration(fullName) {
70
+ return this.#resolve(normalizeFullName(fullName)) !== void 0;
71
+ }
72
+ resolveRegistration(fullName) {
73
+ return this.#resolve(normalizeFullName(fullName));
74
+ }
75
+ registerOptions(fullName, options) {
76
+ const normalized = normalizeFullName(fullName);
77
+ this.#options.set(normalized, {
78
+ ...this.#options.get(normalized),
79
+ ...options
80
+ });
81
+ }
82
+ registeredOption(fullName, optionName) {
83
+ return this.#effectiveOption(normalizeFullName(fullName), optionName);
84
+ }
85
+ registeredOptions(fullName) {
86
+ return this.#options.get(normalizeFullName(fullName));
87
+ }
88
+ registerOptionsForType(type, options) {
89
+ this.#typeOptions.set(type, {
90
+ ...this.#typeOptions.get(type),
91
+ ...options
92
+ });
93
+ }
94
+ registeredOptionsForType(type) {
95
+ return this.#typeOptions.get(type);
96
+ }
97
+ lookup(fullName, options) {
98
+ if (isDestroyed(this)) return;
99
+ const normalized = normalizeFullName(fullName);
100
+ const singleton = options?.singleton ?? this.#effectiveOption(normalized, "singleton") ?? true;
101
+ if (singleton && this.#cache.has(normalized)) return this.#cache.get(normalized);
102
+ const factory = this.#resolve(normalized);
103
+ if (factory === void 0) return;
104
+ const instantiate = options?.instantiate ?? this.#effectiveOption(normalized, "instantiate") ?? true;
105
+ const instance = instantiate ? this.#instantiate(factory) : factory;
106
+ if (singleton) {
107
+ this.#cache.set(normalized, instance);
108
+ if (instantiate && !isDestroying(this) && instance !== null && (typeof instance === "object" || typeof instance === "function")) associateDestroyableChild(this, instance);
109
+ }
110
+ return instance;
111
+ }
112
+ factoryFor(fullName) {
113
+ const normalized = normalizeFullName(fullName);
114
+ const factory = this.#resolve(normalized);
115
+ if (factory === void 0) return;
116
+ return {
117
+ class: factory,
118
+ create: (initialValues) => this.#instantiate(factory, initialValues)
119
+ };
120
+ }
121
+ #effectiveOption(normalized, key) {
122
+ const perName = this.#options.get(normalized)?.[key];
123
+ if (perName !== void 0) return perName;
124
+ const type = normalized.slice(0, normalized.indexOf(":"));
125
+ return this.#typeOptions.get(type)?.[key];
126
+ }
127
+ #resolve(normalized) {
128
+ if (this.#registrations.has(normalized)) return this.#registrations.get(normalized);
129
+ const colon = normalized.indexOf(":");
130
+ if (colon === -1) return;
131
+ const type = normalized.slice(0, colon);
132
+ const name = normalized.slice(colon + 1);
133
+ if (name === "main" && this.#modules.has(type)) return extractDefault(this.#modules.get(type));
134
+ const target = `${type === "config" ? type : `${type}s`}/${name}`;
135
+ if (this.#modules.has(target)) return extractDefault(this.#modules.get(target));
136
+ if (type === "component" && this.#modules.has(`${target}/index`)) return extractDefault(this.#modules.get(`${target}/index`));
137
+ }
138
+ #instantiate(factory, initialValues) {
139
+ let instance;
140
+ if (isFactory(factory)) {
141
+ const props = initialValues ? Object.assign(this.ownerInjection(), initialValues) : this.ownerInjection();
142
+ instance = factory.create(props);
143
+ } else if (typeof factory === "function") {
144
+ const Ctor = factory;
145
+ instance = initialValues !== void 0 ? new Ctor(this, initialValues) : new Ctor(this);
146
+ } else return factory;
147
+ if (instance !== null && (typeof instance === "object" || typeof instance === "function") && !getOwner(instance)) setOwner(instance, this);
148
+ return instance;
149
+ }
150
+ };
151
+ function isCreateOwnerOptions(input) {
152
+ let hasOptionKey = false;
153
+ for (const key in input) {
154
+ if (!Object.hasOwn(input, key)) continue;
155
+ if (key !== "modules" && key !== "services") return false;
156
+ const value = input[key];
157
+ if (value !== void 0 && (typeof value !== "object" || value === null || "default" in value)) return false;
158
+ hasOptionKey = true;
159
+ }
160
+ return hasOptionKey;
161
+ }
162
+ /**
163
+ * An owner for services and `@service` injections in your screens, built either from a Vite module glob or an
164
+ * explicit `services` map:
165
+ *
166
+ * createOwner(import.meta.glob('./services/**\/*.ts', { eager: true }));
167
+ * createOwner({ services: { cart: CartService, config: appConfig } });
168
+ *
169
+ * Services are made on first lookup and live as long as the owner.
170
+ */
171
+ function createOwner(modulesOrOptions = {}) {
172
+ if (!isCreateOwnerOptions(modulesOrOptions)) return new LightweightOwner(modulesOrOptions);
173
+ const owner = new LightweightOwner(modulesOrOptions.modules ?? {});
174
+ const services = modulesOrOptions.services;
175
+ if (services) for (const name in services) {
176
+ if (!Object.hasOwn(services, name)) continue;
177
+ const entry = extractDefault(services[name]);
178
+ const shouldInstantiate = isFactory(entry) || typeof entry === "function";
179
+ owner.register(`service:${name}`, entry, { instantiate: shouldInstantiate });
180
+ }
181
+ return owner;
182
+ }
183
+ export { createOwner };
184
+
185
+ //# sourceMappingURL=owner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner.js","names":["associateDestroyableChild","destroy","isDestroyed","isDestroying","registerDestructor","getOwner","setOwner","FILE_EXTENSION","LEADING_RELATIVE","CAMEL_BOUNDARY","SPACES_AND_UNDERSCORES","dasherize","value","replace","toLowerCase","normalizeModulePath","path","normalizeFullName","fullName","colon","indexOf","type","slice","rawName","name","startsWith","extractDefault","module","default","isFactory","create","LightweightOwner","modules","Map","options","constructor","Object","hasOwn","set","clear","ownerInjection","injection","register","factory","normalized","delete","get","unregister","hasRegistration","undefined","resolveRegistration","registerOptions","registeredOption","optionName","registeredOptions","registerOptionsForType","registeredOptionsForType","lookup","singleton","has","instantiate","instance","factoryFor","class","initialValues","key","perName","target","props","assign","Ctor","isCreateOwnerOptions","input","hasOptionKey","createOwner","modulesOrOptions","owner","services","entry","shouldInstantiate"],"sources":["../../src/owner.ts"],"sourcesContent":["// An owner for `@service` and `getOwner(this)`, without booting @ember/application (no router, no classic container).\n// Ported from inertia-ember's createOwner, by the same author. Importing @ember/renderer first sets up the global\n// context (scheduleDestroy) that @ember/destroyable needs.\nimport '@ember/renderer';\nimport { associateDestroyableChild, destroy, isDestroyed, isDestroying, registerDestructor } from '@ember/destroyable';\nimport {\n type Factory,\n type FactoryManager,\n type FullName,\n getOwner,\n type RegisterOptions,\n setOwner,\n} from '@ember/owner';\nimport type Owner from '@ember/owner';\n\nexport type Modules = Record<string, unknown>;\n\nexport type ServiceEntry = Factory<object> | (new (...args: never[]) => object) | object;\n\nexport interface CreateOwnerOptions {\n /** Module map from `import.meta.glob('./services/**\\/*.ts', { eager: true })`. */\n modules?: Modules;\n /**\n * Services by name: `{ cart: CartService, 'auth/jwt': JwtService, config: existingInstance }`.\n * Classes and Ember factories are instantiated lazily as singletons; plain objects are registered as instances.\n */\n services?: Record<string, ServiceEntry>;\n}\n\nexport interface NativeOwner extends Owner {\n readonly isDestroying: boolean;\n readonly isDestroyed: boolean;\n destroy(): void;\n ownerInjection(): object;\n resolveRegistration(fullName: FullName): Factory<object> | object | undefined;\n hasRegistration(fullName: FullName): boolean;\n unregister(fullName: FullName): void;\n registerOptions(fullName: FullName, options: RegisterOptions): void;\n registeredOption<K extends keyof RegisterOptions>(fullName: FullName, optionName: K): RegisterOptions[K] | undefined;\n registeredOptions(fullName: FullName): RegisterOptions | undefined;\n registerOptionsForType(type: string, options: RegisterOptions): void;\n registeredOptionsForType(type: string): RegisterOptions | undefined;\n}\n\nconst FILE_EXTENSION = /\\.\\w{1,4}$/;\nconst LEADING_RELATIVE = /^(?:\\.\\.?\\/)+/;\nconst CAMEL_BOUNDARY = /([a-z\\d])([A-Z])/g;\nconst SPACES_AND_UNDERSCORES = /[ _]/g;\n\nfunction dasherize(value: string): string {\n return value.replace(CAMEL_BOUNDARY, '$1_$2').toLowerCase().replace(SPACES_AND_UNDERSCORES, '-');\n}\n\nfunction normalizeModulePath(path: string): string {\n return path.replace(FILE_EXTENSION, '').replace(LEADING_RELATIVE, '');\n}\n\nfunction normalizeFullName(fullName: string): FullName {\n const colon = fullName.indexOf(':');\n if (colon === -1) {\n return fullName as FullName;\n }\n\n const type = fullName.slice(0, colon);\n const rawName = fullName.slice(colon + 1);\n const name =\n type === 'component' ||\n type === 'helper' ||\n type === 'modifier' ||\n (type === 'template' && rawName.startsWith('components/'))\n ? rawName.replace(/_/g, '-')\n : dasherize(rawName.replace(/\\./g, '/'));\n\n return `${type}:${name}` as FullName;\n}\n\nfunction extractDefault(module: unknown): unknown {\n return module !== null && typeof module === 'object' && 'default' in module\n ? (module as { default: unknown }).default\n : module;\n}\n\nfunction isFactory(value: unknown): value is Factory<object> {\n return (\n value !== null &&\n (typeof value === 'object' || typeof value === 'function') &&\n typeof (value as Factory<object>).create === 'function'\n );\n}\n\nclass LightweightOwner implements NativeOwner {\n #modules = new Map<string, unknown>();\n #registrations = new Map<string, unknown>();\n #options = new Map<string, RegisterOptions>();\n #typeOptions = new Map<string, RegisterOptions>();\n #cache = new Map<string, unknown>();\n\n constructor(modules: Modules) {\n for (const path in modules) {\n if (Object.hasOwn(modules, path)) {\n this.#modules.set(normalizeModulePath(path), modules[path]);\n }\n }\n\n registerDestructor(this, () => {\n this.#cache.clear();\n });\n }\n\n get isDestroying(): boolean {\n return isDestroying(this);\n }\n\n get isDestroyed(): boolean {\n return isDestroyed(this);\n }\n\n destroy(): void {\n destroy(this);\n }\n\n ownerInjection(): object {\n const injection = {};\n setOwner(injection, this);\n return injection;\n }\n\n register(fullName: FullName, factory: Factory<object> | object, options?: RegisterOptions): void {\n const normalized = normalizeFullName(fullName);\n this.#registrations.set(normalized, factory);\n this.#cache.delete(normalized);\n\n if (options) {\n this.#options.set(normalized, { ...this.#options.get(normalized), ...options });\n }\n }\n\n unregister(fullName: FullName): void {\n const normalized = normalizeFullName(fullName);\n this.#registrations.delete(normalized);\n this.#options.delete(normalized);\n this.#cache.delete(normalized);\n }\n\n hasRegistration(fullName: FullName): boolean {\n return this.#resolve(normalizeFullName(fullName)) !== undefined;\n }\n\n resolveRegistration(fullName: FullName): Factory<object> | object | undefined {\n return this.#resolve(normalizeFullName(fullName)) as Factory<object> | object | undefined;\n }\n\n registerOptions(fullName: FullName, options: RegisterOptions): void {\n const normalized = normalizeFullName(fullName);\n this.#options.set(normalized, { ...this.#options.get(normalized), ...options });\n }\n\n registeredOption<K extends keyof RegisterOptions>(fullName: FullName, optionName: K): RegisterOptions[K] | undefined {\n return this.#effectiveOption(normalizeFullName(fullName), optionName);\n }\n\n registeredOptions(fullName: FullName): RegisterOptions | undefined {\n return this.#options.get(normalizeFullName(fullName));\n }\n\n registerOptionsForType(type: string, options: RegisterOptions): void {\n this.#typeOptions.set(type, { ...this.#typeOptions.get(type), ...options });\n }\n\n registeredOptionsForType(type: string): RegisterOptions | undefined {\n return this.#typeOptions.get(type);\n }\n\n lookup<Type extends string, Name extends string>(fullName: FullName<Type, Name>, options?: RegisterOptions): any {\n if (isDestroyed(this)) {\n return undefined;\n }\n\n const normalized = normalizeFullName(fullName);\n const singleton = options?.singleton ?? this.#effectiveOption(normalized, 'singleton') ?? true;\n\n if (singleton && this.#cache.has(normalized)) {\n return this.#cache.get(normalized);\n }\n\n const factory = this.#resolve(normalized);\n if (factory === undefined) {\n return undefined;\n }\n\n const instantiate = options?.instantiate ?? this.#effectiveOption(normalized, 'instantiate') ?? true;\n const instance = instantiate ? this.#instantiate(factory) : factory;\n\n if (singleton) {\n this.#cache.set(normalized, instance);\n\n if (\n instantiate &&\n !isDestroying(this) &&\n instance !== null &&\n (typeof instance === 'object' || typeof instance === 'function')\n ) {\n associateDestroyableChild(this, instance);\n }\n }\n\n return instance;\n }\n\n factoryFor<Type extends string, Name extends string>(fullName: FullName<Type, Name>): any {\n const normalized = normalizeFullName(fullName);\n const factory = this.#resolve(normalized);\n\n if (factory === undefined) {\n return undefined;\n }\n\n return {\n class: factory as Factory<object>,\n create: (initialValues?: Record<string, unknown>) => this.#instantiate(factory, initialValues) as object,\n } satisfies FactoryManager<object>;\n }\n\n #effectiveOption<K extends keyof RegisterOptions>(normalized: FullName, key: K): RegisterOptions[K] | undefined {\n const perName = this.#options.get(normalized)?.[key];\n if (perName !== undefined) {\n return perName;\n }\n\n const type = normalized.slice(0, normalized.indexOf(':'));\n return this.#typeOptions.get(type)?.[key];\n }\n\n #resolve(normalized: FullName): unknown {\n if (this.#registrations.has(normalized)) {\n return this.#registrations.get(normalized);\n }\n\n const colon = normalized.indexOf(':');\n if (colon === -1) {\n return undefined;\n }\n\n const type = normalized.slice(0, colon);\n const name = normalized.slice(colon + 1);\n\n if (name === 'main' && this.#modules.has(type)) {\n return extractDefault(this.#modules.get(type));\n }\n\n const dir = type === 'config' ? type : `${type}s`;\n const target = `${dir}/${name}`;\n\n if (this.#modules.has(target)) {\n return extractDefault(this.#modules.get(target));\n }\n\n if (type === 'component' && this.#modules.has(`${target}/index`)) {\n return extractDefault(this.#modules.get(`${target}/index`));\n }\n\n return undefined;\n }\n\n #instantiate(factory: unknown, initialValues?: Record<string, unknown>): unknown {\n let instance: unknown;\n\n if (isFactory(factory)) {\n const props = initialValues ? Object.assign(this.ownerInjection(), initialValues) : this.ownerInjection();\n instance = factory.create(props);\n } else if (typeof factory === 'function') {\n const Ctor = factory as new (owner: Owner, initialValues?: Record<string, unknown>) => object;\n instance = initialValues !== undefined ? new Ctor(this, initialValues) : new Ctor(this);\n } else {\n return factory;\n }\n\n if (instance !== null && (typeof instance === 'object' || typeof instance === 'function') && !getOwner(instance)) {\n setOwner(instance, this);\n }\n\n return instance;\n }\n}\n\nfunction isCreateOwnerOptions(input: Modules | CreateOwnerOptions): input is CreateOwnerOptions {\n let hasOptionKey = false;\n\n for (const key in input) {\n if (!Object.hasOwn(input, key)) {\n continue;\n }\n\n if (key !== 'modules' && key !== 'services') {\n return false;\n }\n\n const value = (input as Record<string, unknown>)[key];\n if (value !== undefined && (typeof value !== 'object' || value === null || 'default' in value)) {\n return false;\n }\n\n hasOptionKey = true;\n }\n\n return hasOptionKey;\n}\n\n/**\n * An owner for services and `@service` injections in your screens, built either from a Vite module glob or an\n * explicit `services` map:\n *\n * createOwner(import.meta.glob('./services/**\\/*.ts', { eager: true }));\n * createOwner({ services: { cart: CartService, config: appConfig } });\n *\n * Services are made on first lookup and live as long as the owner.\n */\nexport function createOwner(modulesOrOptions: Modules | CreateOwnerOptions = {}): NativeOwner {\n if (!isCreateOwnerOptions(modulesOrOptions)) {\n return new LightweightOwner(modulesOrOptions);\n }\n\n const owner = new LightweightOwner(modulesOrOptions.modules ?? {});\n const services = modulesOrOptions.services;\n\n if (services) {\n for (const name in services) {\n if (!Object.hasOwn(services, name)) {\n continue;\n }\n\n const entry = extractDefault(services[name]);\n const shouldInstantiate = isFactory(entry) || typeof entry === 'function';\n owner.register(`service:${name}`, entry as Factory<object> | object, { instantiate: shouldInstantiate });\n }\n }\n\n return owner;\n}\n"],"mappings":";;;;AA4CA,IAAMO,iBAAiB;AACvB,IAAMC,mBAAmB;AACzB,IAAMC,iBAAiB;AACvB,IAAMC,yBAAyB;AAE/B,SAASC,UAAUC,OAAuB;CACxC,OAAOA,MAAMC,QAAQJ,gBAAgB,OAAO,CAAC,CAACK,YAAY,CAAC,CAACD,QAAQH,wBAAwB,GAAG;AACjG;AAEA,SAASK,oBAAoBC,MAAsB;CACjD,OAAOA,KAAKH,QAAQN,gBAAgB,EAAE,CAAC,CAACM,QAAQL,k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pC,OAAOC,OAAOmC,OAAOP,GAAG,GAC3B;EAGF,IAAIA,QAAQ,aAAaA,QAAQ,YAC/B,OAAO;EAGT,MAAMrD,QAAS4D,MAAkCP;EACjD,IAAIrD,UAAUqC,KAAAA,MAAc,OAAOrC,UAAU,YAAYA,UAAU,QAAQ,aAAaA,QACtF,OAAO;EAGT6D,eAAe;CACjB;CAEA,OAAOA;AACT;;;;;;;;;;AAWA,SAAgBC,YAAYC,mBAAiD,CAAC,GAAgB;CAC5F,IAAI,CAACJ,qBAAqBI,gBAAgB,GACxC,OAAO,IAAI5C,iBAAiB4C,gBAAgB;CAG9C,MAAMC,QAAQ,IAAI7C,iBAAiB4C,iBAAiB3C,WAAW,CAAC,CAAC;CACjE,MAAM6C,WAAWF,iBAAiBE;CAElC,IAAIA,UACF,KAAK,MAAMrD,QAAQqD,UAAU;EAC3B,IAAI,CAACzC,OAAOC,OAAOwC,UAAUrD,IAAI,GAC/B;EAGF,MAAMsD,QAAQpD,eAAemD,SAASrD,KAAK;EAC3C,MAAMuD,oBAAoBlD,UAAUiD,KAAK,KAAK,OAAOA,UAAU;EAC/DF,MAAMlC,SAAS,WAAWlB,QAAQsD,OAAmC,EAAElB,aAAamB,kBAAkB,CAAC;CACzG;CAGF,OAAOH;AACT"}
@@ -0,0 +1,5 @@
1
+ export declare function setPlatform(platform: 'ios' | 'android' | undefined): void;
2
+ export declare const platform: () => "ios" | "android" | undefined;
3
+ export declare const isIOS: () => boolean;
4
+ export declare const isAndroid: () => boolean;
5
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,CAAC,QAAQ,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAEzE;AAED,eAAO,MAAM,QAAQ,QAAO,KAAK,GAAG,SAAS,GAAG,SAAoB,CAAC;AACrE,eAAO,MAAM,KAAK,QAAO,OAA4B,CAAC;AACtD,eAAO,MAAM,SAAS,QAAO,OAAgC,CAAC"}
@@ -0,0 +1,11 @@
1
+ // src/platform.ts
2
+ var current;
3
+ function setPlatform(platform) {
4
+ current = platform;
5
+ }
6
+ var platform = () => current;
7
+ var isIOS = () => current === "ios";
8
+ var isAndroid = () => current === "android";
9
+ export { isAndroid, isIOS, platform, setPlatform };
10
+
11
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","names":[],"sources":["../../src/platform.ts"],"sourcesContent":["// Which platform the app runs on, for templates: {{#if (isIOS)}}…{{/if}}. Set from the adapter when a document is\n// created, which happens once, before anything renders.\nlet current: 'ios' | 'android' | undefined;\n\nexport function setPlatform(platform: 'ios' | 'android' | undefined): void {\n current = platform;\n}\n\nexport const platform = (): 'ios' | 'android' | undefined => current;\nexport const isIOS = (): boolean => current === 'ios';\nexport const isAndroid = (): boolean => current === 'android';\n"],"mappings":";AAEA,IAAI;AAEJ,SAAgB,YAAY,UAA+C;CACzE,UAAU;AACZ;AAEA,IAAa,iBAAgD;AAC7D,IAAa,cAAuB,YAAY;AAChD,IAAa,kBAA2B,YAAY"}
@@ -0,0 +1,18 @@
1
+ import type { NativeAdapter } from './adapter.js';
2
+ import { NativeDocument, NativeElement } from './dom.js';
3
+ export interface NativeRoot<View = unknown> {
4
+ /** The root element; its view is what the toolkit shows. */
5
+ element: NativeElement;
6
+ view: View;
7
+ destroy(): void;
8
+ }
9
+ export interface RenderNativeOptions {
10
+ document: NativeDocument;
11
+ /** The tag of the root view the component renders into, such as `page` or `stackLayout`. */
12
+ root?: string;
13
+ args?: Record<string, unknown>;
14
+ owner?: object;
15
+ }
16
+ export declare function createDocument(adapter: NativeAdapter): NativeDocument;
17
+ export declare function renderNative<View>(component: object, { document, root, args, owner }: RenderNativeOptions): NativeRoot<View>;
18
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/render.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQzD,MAAM,WAAW,UAAU,CAAC,IAAI,GAAG,OAAO;IACxC,4DAA4D;IAC5D,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,cAAc,CAAC;IACzB,4FAA4F;IAC5F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,cAAc,CAGrE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAC/B,SAAS,EAAE,MAAM,EACjB,EAAE,QAAQ,EAAE,IAAa,EAAE,IAAI,EAAE,KAAU,EAAE,EAAE,mBAAmB,GACjE,UAAU,CAAC,IAAI,CAAC,CAgBlB"}
@@ -0,0 +1,32 @@
1
+ import { renderComponent } from "@ember/renderer";
2
+ import { NativeDocument, NativeElement } from "./dom.js";
3
+ import { setPlatform } from "./platform.js";
4
+ // src/render.ts
5
+ var globals = globalThis;
6
+ globals.Element ??= NativeElement;
7
+ function createDocument(adapter) {
8
+ setPlatform(adapter.platform);
9
+ return new NativeDocument(adapter);
10
+ }
11
+ function renderNative(component, { document, root = "page", args, owner = {} }) {
12
+ const element = document.createElement(root);
13
+ if (!element.view) throw new Error(`[ember-nativescript] <${root}> has no view, so it can't be a root.`);
14
+ const result = renderComponent(component, {
15
+ into: element,
16
+ owner,
17
+ args,
18
+ env: {
19
+ document,
20
+ isInteractive: true,
21
+ hasDOM: true
22
+ }
23
+ });
24
+ return {
25
+ element,
26
+ view: element.view,
27
+ destroy: () => result.destroy()
28
+ };
29
+ }
30
+ export { createDocument, renderNative };
31
+
32
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","names":["renderComponent","NativeDocument","NativeElement","setPlatform","globals","globalThis","Element","createDocument","adapter","platform","renderNative","component","document","root","args","owner","element","createElement","view","Error","result","into","env","isInteractive","hasDOM","destroy"],"sources":["../../src/render.ts"],"sourcesContent":["// Renders Ember components into native views with Ember's public `renderComponent`, which takes the\n// document to build with (`env.document`). Nothing private from Ember is used here.\n\nimport { renderComponent } from '@ember/renderer';\n\nimport type { NativeAdapter } from './adapter.ts';\nimport { NativeDocument, NativeElement } from './dom.ts';\nimport { setPlatform } from './platform.ts';\n\n// `renderComponent` checks `into instanceof Element` before clearing its target. Neither Node nor\n// NativeScript has a global Element, so the shim's element class stands in for it.\nconst globals = globalThis as { Element?: unknown };\nglobals.Element ??= NativeElement;\n\nexport interface NativeRoot<View = unknown> {\n /** The root element; its view is what the toolkit shows. */\n element: NativeElement;\n view: View;\n destroy(): void;\n}\n\nexport interface RenderNativeOptions {\n document: NativeDocument;\n /** The tag of the root view the component renders into, such as `page` or `stackLayout`. */\n root?: string;\n args?: Record<string, unknown>;\n owner?: object;\n}\n\nexport function createDocument(adapter: NativeAdapter): NativeDocument {\n setPlatform(adapter.platform);\n return new NativeDocument(adapter);\n}\n\nexport function renderNative<View>(\n component: object,\n { document, root = 'page', args, owner = {} }: RenderNativeOptions,\n): NativeRoot<View> {\n const element = document.createElement(root);\n if (!element.view) throw new Error(`[ember-nativescript] <${root}> has no view, so it can't be a root.`);\n\n const result = renderComponent(component, {\n into: element as unknown as Element,\n owner,\n args,\n env: { document: document as unknown as Document, isInteractive: true, hasDOM: true } as never,\n });\n\n return {\n element,\n view: element.view as View,\n destroy: () => result.destroy(),\n };\n}\n"],"mappings":";;;;AAWA,IAAMI,UAAUC;AAChBD,QAAQE,YAAYJ;AAiBpB,SAAgBK,eAAeC,SAAwC;CACrEL,YAAYK,QAAQC,QAAQ;CAC5B,OAAO,IAAIR,eAAeO,OAAO;AACnC;AAEA,SAAgBE,aACdC,WACA,EAAEC,UAAUC,OAAO,QAAQC,MAAMC,QAAQ,CAAC,KACxB;CAClB,MAAMC,UAAUJ,SAASK,cAAcJ,IAAI;CAC3C,IAAI,CAACG,QAAQE,MAAM,MAAM,IAAIC,MAAM,yBAAyBN,KAAI,sCAAuC;CAEvG,MAAMO,SAASpB,gBAAgBW,WAAW;EACxCU,MAAML;EACND;EACAD;EACAQ,KAAK;GAAYV;GAAiCW,eAAe;GAAMC,QAAQ;EAAK;CACtF,CAAC;CAED,OAAO;EACLR;EACAE,MAAMF,QAAQE;EACdO,eAAeL,OAAOK,QAAQ;CAChC;AACF"}