@nativescript/vite 0.0.1 → 0.0.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 (257) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +44 -0
  3. package/{dist/configuration → configuration}/angular.d.ts +1 -1
  4. package/configuration/angular.js +480 -0
  5. package/configuration/angular.js.map +1 -0
  6. package/configuration/base.d.ts +5 -0
  7. package/configuration/base.js +494 -0
  8. package/configuration/base.js.map +1 -0
  9. package/configuration/javascript.d.ts +4 -0
  10. package/configuration/javascript.js +151 -0
  11. package/configuration/javascript.js.map +1 -0
  12. package/{dist/configuration → configuration}/react.d.ts +1 -1
  13. package/{dist/configuration → configuration}/react.js +18 -17
  14. package/configuration/react.js.map +1 -0
  15. package/{dist/configuration → configuration}/solid.d.ts +1 -1
  16. package/{dist/configuration → configuration}/solid.js +17 -16
  17. package/configuration/solid.js.map +1 -0
  18. package/configuration/typescript.d.ts +4 -0
  19. package/configuration/typescript.js +175 -0
  20. package/configuration/typescript.js.map +1 -0
  21. package/{dist/configuration → configuration}/vue.d.ts +1 -1
  22. package/configuration/vue.js +163 -0
  23. package/configuration/vue.js.map +1 -0
  24. package/helpers/angular-linker.d.ts +13 -0
  25. package/helpers/angular-linker.js +181 -0
  26. package/helpers/angular-linker.js.map +1 -0
  27. package/helpers/cli-flags.d.ts +1 -0
  28. package/helpers/cli-flags.js +15 -0
  29. package/helpers/cli-flags.js.map +1 -0
  30. package/{dist/helpers → helpers}/commonjs-plugins.js +14 -13
  31. package/helpers/commonjs-plugins.js.map +1 -0
  32. package/{dist/helpers → helpers}/config-as-json.d.ts +1 -1
  33. package/{dist/helpers → helpers}/config-as-json.js +7 -6
  34. package/helpers/config-as-json.js.map +1 -0
  35. package/helpers/css-platform-plugin.d.ts +10 -0
  36. package/helpers/css-platform-plugin.js +76 -0
  37. package/helpers/css-platform-plugin.js.map +1 -0
  38. package/helpers/css-tree.js +22 -0
  39. package/helpers/css-tree.js.map +1 -0
  40. package/{dist/helpers → helpers}/dynamic-import-plugin.js +8 -7
  41. package/helpers/dynamic-import-plugin.js.map +1 -0
  42. package/helpers/esbuild-platform-resolver.d.ts +14 -0
  43. package/helpers/esbuild-platform-resolver.js +93 -0
  44. package/helpers/esbuild-platform-resolver.js.map +1 -0
  45. package/helpers/external-configs.d.ts +6 -0
  46. package/helpers/external-configs.js +34 -0
  47. package/helpers/external-configs.js.map +1 -0
  48. package/{dist/helpers → helpers}/flavor.d.ts +1 -0
  49. package/helpers/flavor.js +51 -0
  50. package/helpers/flavor.js.map +1 -0
  51. package/{dist/helpers → helpers}/global-defines.d.ts +11 -2
  52. package/helpers/global-defines.js +24 -0
  53. package/helpers/global-defines.js.map +1 -0
  54. package/helpers/logging.d.ts +13 -0
  55. package/helpers/logging.js +111 -0
  56. package/helpers/logging.js.map +1 -0
  57. package/helpers/main-entry.d.ts +10 -0
  58. package/helpers/main-entry.js +215 -0
  59. package/helpers/main-entry.js.map +1 -0
  60. package/{dist/helpers → helpers}/module-resolution.js +4 -3
  61. package/helpers/module-resolution.js.map +1 -0
  62. package/helpers/module-runner-patch.d.ts +3 -0
  63. package/helpers/module-runner-patch.js +63 -0
  64. package/helpers/module-runner-patch.js.map +1 -0
  65. package/helpers/nativeclass-transform.d.ts +7 -0
  66. package/helpers/nativeclass-transform.js +158 -0
  67. package/helpers/nativeclass-transform.js.map +1 -0
  68. package/helpers/nativeclass-transformer-plugin.d.ts +5 -0
  69. package/helpers/nativeclass-transformer-plugin.js +23 -0
  70. package/helpers/nativeclass-transformer-plugin.js.map +1 -0
  71. package/{dist/helpers → helpers}/nativescript-package-resolver.js +18 -17
  72. package/helpers/nativescript-package-resolver.js.map +1 -0
  73. package/helpers/ns-cli-plugins.d.ts +14 -0
  74. package/helpers/ns-cli-plugins.js +165 -0
  75. package/helpers/ns-cli-plugins.js.map +1 -0
  76. package/helpers/package-platform-aliases.d.ts +10 -0
  77. package/{dist/helpers → helpers}/package-platform-aliases.js +19 -23
  78. package/helpers/package-platform-aliases.js.map +1 -0
  79. package/helpers/postcss-platform-config.d.ts +13 -0
  80. package/helpers/postcss-platform-config.js +97 -0
  81. package/helpers/postcss-platform-config.js.map +1 -0
  82. package/helpers/prelink-angular.d.ts +2 -0
  83. package/helpers/prelink-angular.js +117 -0
  84. package/helpers/prelink-angular.js.map +1 -0
  85. package/helpers/preserve-imports.d.ts +2 -0
  86. package/helpers/preserve-imports.js +38 -0
  87. package/helpers/preserve-imports.js.map +1 -0
  88. package/{dist/helpers → helpers}/project.js +2 -4
  89. package/helpers/project.js.map +1 -0
  90. package/helpers/resolver.d.ts +4 -0
  91. package/{dist/helpers → helpers}/resolver.js +7 -6
  92. package/helpers/resolver.js.map +1 -0
  93. package/helpers/theme-core-plugins.d.ts +14 -0
  94. package/helpers/theme-core-plugins.js +121 -0
  95. package/helpers/theme-core-plugins.js.map +1 -0
  96. package/helpers/ts-config-paths.d.ts +10 -0
  97. package/{dist/helpers → helpers}/ts-config-paths.js +73 -72
  98. package/helpers/ts-config-paths.js.map +1 -0
  99. package/{dist/helpers → helpers}/utils.d.ts +6 -0
  100. package/{dist/helpers → helpers}/utils.js +28 -34
  101. package/helpers/utils.js.map +1 -0
  102. package/{dist/helpers → helpers}/workers.js +15 -16
  103. package/helpers/workers.js.map +1 -0
  104. package/hmr/client/css-handler.d.ts +4 -0
  105. package/hmr/client/css-handler.js +78 -0
  106. package/hmr/client/css-handler.js.map +1 -0
  107. package/hmr/client/index.d.ts +13 -0
  108. package/hmr/client/index.js +1550 -0
  109. package/hmr/client/index.js.map +1 -0
  110. package/hmr/client/utils.d.ts +38 -0
  111. package/hmr/client/utils.js +426 -0
  112. package/hmr/client/utils.js.map +1 -0
  113. package/hmr/entry-runtime.d.ts +8 -0
  114. package/hmr/entry-runtime.js +135 -0
  115. package/hmr/entry-runtime.js.map +1 -0
  116. package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
  117. package/hmr/frameworks/angular/server/strategy.js +101 -0
  118. package/hmr/frameworks/angular/server/strategy.js.map +1 -0
  119. package/hmr/frameworks/vue/client/index.d.ts +22 -0
  120. package/hmr/frameworks/vue/client/index.js +1537 -0
  121. package/hmr/frameworks/vue/client/index.js.map +1 -0
  122. package/hmr/frameworks/vue/server/compiler.d.ts +11 -0
  123. package/hmr/frameworks/vue/server/compiler.js +26 -0
  124. package/hmr/frameworks/vue/server/compiler.js.map +1 -0
  125. package/hmr/frameworks/vue/server/sfc-transforms.d.ts +14 -0
  126. package/hmr/frameworks/vue/server/sfc-transforms.js +282 -0
  127. package/hmr/frameworks/vue/server/sfc-transforms.js.map +1 -0
  128. package/hmr/frameworks/vue/server/strategy.d.ts +2 -0
  129. package/hmr/frameworks/vue/server/strategy.js +273 -0
  130. package/hmr/frameworks/vue/server/strategy.js.map +1 -0
  131. package/hmr/helpers/ast-extract.d.ts +6 -0
  132. package/hmr/helpers/ast-extract.js +72 -0
  133. package/hmr/helpers/ast-extract.js.map +1 -0
  134. package/hmr/helpers/ast-normalizer.d.ts +7 -0
  135. package/hmr/helpers/ast-normalizer.js +772 -0
  136. package/hmr/helpers/ast-normalizer.js.map +1 -0
  137. package/hmr/helpers/babel.d.ts +3 -0
  138. package/hmr/helpers/babel.js +17 -0
  139. package/hmr/helpers/babel.js.map +1 -0
  140. package/hmr/helpers/sanitize.d.ts +6 -0
  141. package/hmr/helpers/sanitize.js +55 -0
  142. package/hmr/helpers/sanitize.js.map +1 -0
  143. package/hmr/helpers/vendor-rewrite.d.ts +1 -0
  144. package/hmr/helpers/vendor-rewrite.js +35 -0
  145. package/hmr/helpers/vendor-rewrite.js.map +1 -0
  146. package/hmr/server/compiler.d.ts +2 -0
  147. package/hmr/server/compiler.js +75 -0
  148. package/hmr/server/compiler.js.map +1 -0
  149. package/hmr/server/constants.d.ts +14 -0
  150. package/hmr/server/constants.js +23 -0
  151. package/hmr/server/constants.js.map +1 -0
  152. package/hmr/server/core-sanitize.d.ts +32 -0
  153. package/hmr/server/core-sanitize.js +134 -0
  154. package/hmr/server/core-sanitize.js.map +1 -0
  155. package/hmr/server/framework-strategy.d.ts +68 -0
  156. package/hmr/server/framework-strategy.js +2 -0
  157. package/hmr/server/framework-strategy.js.map +1 -0
  158. package/hmr/server/index.d.ts +5 -0
  159. package/hmr/server/index.js +19 -0
  160. package/hmr/server/index.js.map +1 -0
  161. package/hmr/server/vite-plugin.d.ts +5 -0
  162. package/hmr/server/vite-plugin.js +44 -0
  163. package/hmr/server/vite-plugin.js.map +1 -0
  164. package/hmr/server/websocket.d.ts +15 -0
  165. package/hmr/server/websocket.js +5528 -0
  166. package/hmr/server/websocket.js.map +1 -0
  167. package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
  168. package/hmr/shared/runtime/http-only-boot.js +107 -0
  169. package/hmr/shared/runtime/http-only-boot.js.map +1 -0
  170. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  171. package/hmr/shared/runtime/root-placeholder.js +142 -0
  172. package/hmr/shared/runtime/root-placeholder.js.map +1 -0
  173. package/hmr/shared/runtime/vendor-bootstrap.d.ts +1 -0
  174. package/hmr/shared/runtime/vendor-bootstrap.js +134 -0
  175. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -0
  176. package/hmr/shared/vendor/manifest-loader.d.ts +9 -0
  177. package/hmr/shared/vendor/manifest-loader.js +38 -0
  178. package/hmr/shared/vendor/manifest-loader.js.map +1 -0
  179. package/hmr/shared/vendor/manifest.d.ts +34 -0
  180. package/hmr/shared/vendor/manifest.js +787 -0
  181. package/hmr/shared/vendor/manifest.js.map +1 -0
  182. package/hmr/shared/vendor/registry.d.ts +9 -0
  183. package/hmr/shared/vendor/registry.js +62 -0
  184. package/hmr/shared/vendor/registry.js.map +1 -0
  185. package/hmr/vendor-bootstrap.d.ts +3 -0
  186. package/hmr/vendor-bootstrap.js +32 -0
  187. package/hmr/vendor-bootstrap.js.map +1 -0
  188. package/{dist/index.d.ts → index.d.ts} +2 -0
  189. package/{dist/index.js → index.js} +3 -0
  190. package/index.js.map +1 -0
  191. package/package.json +39 -30
  192. package/{dist/polyfills → polyfills}/mdn-data-at-rules.js +1 -0
  193. package/polyfills/mdn-data-at-rules.js.map +1 -0
  194. package/{dist/polyfills → polyfills}/mdn-data-properties.js +1 -0
  195. package/polyfills/mdn-data-properties.js.map +1 -0
  196. package/{dist/polyfills → polyfills}/mdn-data-syntaxes.js +1 -0
  197. package/polyfills/mdn-data-syntaxes.js.map +1 -0
  198. package/{dist/polyfills → polyfills}/module.js +1 -0
  199. package/polyfills/module.js.map +1 -0
  200. package/runtime/core-aliases-early.d.ts +1 -0
  201. package/runtime/core-aliases-early.js +334 -0
  202. package/runtime/core-aliases-early.js.map +1 -0
  203. package/shims/angular-animations-stub.d.ts +8 -0
  204. package/shims/angular-animations-stub.js +14 -0
  205. package/shims/angular-animations-stub.js.map +1 -0
  206. package/shims/node-module.d.ts +5 -0
  207. package/shims/node-module.js +13 -0
  208. package/shims/node-module.js.map +1 -0
  209. package/{dist/shims → shims}/react-reconciler-constants.js +2 -1
  210. package/shims/react-reconciler-constants.js.map +1 -0
  211. package/{dist/shims → shims}/react-reconciler.js +1 -0
  212. package/shims/react-reconciler.js.map +1 -0
  213. package/{dist/shims → shims}/set-value.js +5 -1
  214. package/shims/set-value.js.map +1 -0
  215. package/transformers/NativeClass/index.d.ts +2 -0
  216. package/transformers/NativeClass/index.js +222 -0
  217. package/transformers/NativeClass/index.js.map +1 -0
  218. package/dist/configuration/angular.js +0 -30
  219. package/dist/configuration/base.d.ts +0 -13
  220. package/dist/configuration/base.js +0 -228
  221. package/dist/configuration/old-without-merge-base.d.ts +0 -13
  222. package/dist/configuration/old-without-merge-base.js +0 -249
  223. package/dist/configuration/vue.js +0 -45
  224. package/dist/helpers/css-tree.js +0 -21
  225. package/dist/helpers/flavor.js +0 -40
  226. package/dist/helpers/global-defines.js +0 -18
  227. package/dist/helpers/main-entry.d.ts +0 -5
  228. package/dist/helpers/main-entry.js +0 -75
  229. package/dist/helpers/ns-cli-plugins.d.ts +0 -17
  230. package/dist/helpers/ns-cli-plugins.js +0 -128
  231. package/dist/helpers/package-platform-aliases.d.ts +0 -4
  232. package/dist/helpers/resolver.d.ts +0 -4
  233. package/dist/helpers/ts-config-paths.d.ts +0 -4
  234. package/dist/hmr/hmr-angular.d.ts +0 -1
  235. package/dist/hmr/hmr-angular.js +0 -34
  236. package/dist/hmr/hmr-bridge.d.ts +0 -18
  237. package/dist/hmr/hmr-bridge.js +0 -154
  238. package/dist/hmr/hmr-client.d.ts +0 -5
  239. package/dist/hmr/hmr-client.js +0 -93
  240. package/dist/hmr/hmr-server.d.ts +0 -20
  241. package/dist/hmr/hmr-server.js +0 -179
  242. package/dist/transformers/NativeClass/index.d.ts +0 -5
  243. package/dist/transformers/NativeClass/index.js +0 -46
  244. /package/{dist/helpers → helpers}/commonjs-plugins.d.ts +0 -0
  245. /package/{dist/helpers → helpers}/css-tree.d.ts +0 -0
  246. /package/{dist/helpers → helpers}/dynamic-import-plugin.d.ts +0 -0
  247. /package/{dist/helpers → helpers}/module-resolution.d.ts +0 -0
  248. /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
  249. /package/{dist/helpers → helpers}/project.d.ts +0 -0
  250. /package/{dist/helpers → helpers}/workers.d.ts +0 -0
  251. /package/{dist/polyfills → polyfills}/mdn-data-at-rules.d.ts +0 -0
  252. /package/{dist/polyfills → polyfills}/mdn-data-properties.d.ts +0 -0
  253. /package/{dist/polyfills → polyfills}/mdn-data-syntaxes.d.ts +0 -0
  254. /package/{dist/polyfills → polyfills}/module.d.ts +0 -0
  255. /package/{dist/shims → shims}/react-reconciler-constants.d.ts +0 -0
  256. /package/{dist/shims → shims}/react-reconciler.d.ts +0 -0
  257. /package/{dist/shims → shims}/set-value.d.ts +0 -0
@@ -0,0 +1,1537 @@
1
+ import { attachDiagnosticsToFrame, deriveHttpOrigin, getCore, getCurrentApp, getGraphVersion, getHMRWsUrl, getHttpOriginForVite, normalizeSpec, safeDynImport, safeReadDefault, setCurrentApp } from '../../../client/utils.js';
2
+ // Optional runtime knob: allow disabling assembler path in favor of variant-only flow
3
+ const DISABLE_ASM = !!globalThis.__NS_HMR_DISABLE_ASM__;
4
+ // Module-scoped state to avoid leaking into globalThis
5
+ let nsVueInitDone = false; // nativescript-vue init guard
6
+ let nsStartDone = false; // start() guard
7
+ // Track SFC changes by graph version to prioritize SFC root reset before non-Vue evaluation
8
+ let sfcChangedVersion = null;
9
+ export const sfcChangedIds = new Set();
10
+ // Map of original SFC source absolute/relative path -> compiled sfc-*.mjs filename written to Documents
11
+ export const sfcArtifactMap = new Map();
12
+ // Install dev shims for nativescript-vue navigation to observe and (optionally) rescue
13
+ export function installNsVueDevShims() {
14
+ try {
15
+ const g = globalThis;
16
+ const reg = g.__nsVendorRegistry;
17
+ const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
18
+ const getMod = (id) => {
19
+ try {
20
+ if (reg && reg.has(id))
21
+ return reg.get(id);
22
+ }
23
+ catch { }
24
+ try {
25
+ if (typeof req === 'function')
26
+ return req(id);
27
+ }
28
+ catch { }
29
+ return null;
30
+ };
31
+ const nv = getMod('nativescript-vue');
32
+ const rh = getMod('nativescript-vue/dist/runtimeHelpers');
33
+ const wrap = (orig, label) => {
34
+ if (typeof orig !== 'function')
35
+ return orig;
36
+ if (orig.__ns_wrapped__)
37
+ return orig; // idempotent
38
+ const wrapped = function __ns_nav_wrap(component, params) {
39
+ try {
40
+ if (__NS_ENV_VERBOSE__) {
41
+ console.log('[diag][nv][navigateTo]', {
42
+ from: label,
43
+ hasComp: !!component,
44
+ paramKeys: Object.keys(params || {}),
45
+ });
46
+ }
47
+ return orig.apply(this, arguments);
48
+ }
49
+ catch (e) {
50
+ try {
51
+ console.warn('[diag][nv][navigateTo][error]', (e && e.message) || e);
52
+ }
53
+ catch { }
54
+ try {
55
+ // Rescue path: attempt navigation via authoritative app Frame
56
+ return globalThis.__nsNavigateUsingApp?.(component, params);
57
+ }
58
+ catch { }
59
+ throw e;
60
+ }
61
+ };
62
+ try {
63
+ wrapped.__ns_wrapped__ = true;
64
+ }
65
+ catch { }
66
+ return wrapped;
67
+ };
68
+ if (nv) {
69
+ try {
70
+ if (nv.navigateTo)
71
+ nv.navigateTo = wrap(nv.navigateTo, 'nv');
72
+ if (nv.$navigateTo)
73
+ nv.$navigateTo = wrap(nv.$navigateTo, '$nv');
74
+ }
75
+ catch { }
76
+ }
77
+ if (rh) {
78
+ try {
79
+ if (rh.navigateTo)
80
+ rh.navigateTo = wrap(rh.navigateTo, 'rh');
81
+ }
82
+ catch { }
83
+ }
84
+ }
85
+ catch { }
86
+ }
87
+ // initial root component for back fallback
88
+ let ORIG_ROOT_COMPONENT = null;
89
+ // Ensure Vue runtime global functions exist before evaluating SFC artifacts that rely on globalThis.* indirections.
90
+ export function ensureVueGlobals() {
91
+ try {
92
+ const g = globalThis;
93
+ const vueAlready = g.defineComponent && g.resolveComponent && g.createVNode;
94
+ const req = globalThis.__nsVendorRegistry?.get ? globalThis.__nsVendorRequire || globalThis.__nsRequire || globalThis.require : globalThis.__nsRequire || globalThis.require;
95
+ const registry = globalThis.__nsVendorRegistry;
96
+ let nvMod = null;
97
+ let vueMod = null;
98
+ // Prefer nativescript-vue first so createApp has .start and NSVRoot is available
99
+ if (registry && registry.has('nativescript-vue')) {
100
+ nvMod = registry.get('nativescript-vue');
101
+ }
102
+ if (registry && registry.has('vue')) {
103
+ vueMod = registry.get('vue');
104
+ }
105
+ if (!nvMod && typeof req === 'function') {
106
+ try {
107
+ nvMod = req('nativescript-vue');
108
+ }
109
+ catch { }
110
+ }
111
+ if (!vueMod && typeof req === 'function') {
112
+ try {
113
+ vueMod = req('vue');
114
+ }
115
+ catch { }
116
+ if (!vueMod) {
117
+ try {
118
+ vueMod = req('@vue/runtime-core');
119
+ }
120
+ catch { }
121
+ }
122
+ }
123
+ const baseMod = nvMod || vueMod;
124
+ let chosenMod = baseMod;
125
+ if (!chosenMod) {
126
+ // Last-ditch attempts on known ids
127
+ try {
128
+ chosenMod = req && typeof req === 'function' ? req('nativescript-vue') : null;
129
+ }
130
+ catch { }
131
+ if (!chosenMod) {
132
+ try {
133
+ chosenMod = req && typeof req === 'function' ? req('vue') : null;
134
+ }
135
+ catch { }
136
+ }
137
+ if (!chosenMod)
138
+ return;
139
+ }
140
+ if (!vueMod) {
141
+ // Last-ditch attempts on known ids
142
+ try {
143
+ vueMod = req && typeof req === 'function' ? req('vue') : null;
144
+ }
145
+ catch { }
146
+ if (!vueMod) {
147
+ try {
148
+ vueMod = req && typeof req === 'function' ? req('nativescript-vue') : null;
149
+ }
150
+ catch { }
151
+ }
152
+ if (!vueMod)
153
+ return;
154
+ }
155
+ // Polyfill essential runtime helpers often imported from 'vue' by compiled SFC render code
156
+ try {
157
+ const polyNormalizeClass = (val) => {
158
+ if (!val)
159
+ return '';
160
+ if (typeof val === 'string')
161
+ return val;
162
+ if (Array.isArray(val))
163
+ return val.map(polyNormalizeClass).filter(Boolean).join(' ');
164
+ if (typeof val === 'object')
165
+ return Object.keys(val)
166
+ .filter((k) => !!val[k])
167
+ .join(' ');
168
+ return '';
169
+ };
170
+ const polyNormalizeStyle = (val) => {
171
+ if (!val)
172
+ return null;
173
+ if (Array.isArray(val))
174
+ return val.reduce((acc, v) => Object.assign(acc, polyNormalizeStyle(v) || {}), {});
175
+ if (typeof val === 'string') {
176
+ const out = {};
177
+ val.split(';').forEach((pair) => {
178
+ const idx = pair.indexOf(':');
179
+ if (idx > -1) {
180
+ const k = pair.slice(0, idx).trim();
181
+ const v = pair.slice(idx + 1).trim();
182
+ if (k)
183
+ out[k] = v;
184
+ }
185
+ });
186
+ return out;
187
+ }
188
+ if (typeof val === 'object')
189
+ return { ...val };
190
+ return null;
191
+ };
192
+ const polyToDisplayString = (val) => {
193
+ try {
194
+ if (val == null)
195
+ return '';
196
+ if (typeof val === 'object')
197
+ return JSON.stringify(val);
198
+ return String(val);
199
+ }
200
+ catch {
201
+ return String(val);
202
+ }
203
+ };
204
+ const vmAny = vueMod;
205
+ if (vmAny && typeof vmAny === 'object') {
206
+ if (!('normalizeClass' in vmAny))
207
+ vmAny.normalizeClass = polyNormalizeClass;
208
+ if (!('normalizeStyle' in vmAny))
209
+ vmAny.normalizeStyle = polyNormalizeStyle;
210
+ if (!('toDisplayString' in vmAny))
211
+ vmAny.toDisplayString = polyToDisplayString;
212
+ }
213
+ // Do not assign polyfills onto globalThis; compiled helpers are wired via alias() below
214
+ }
215
+ catch { }
216
+ const runtime = (chosenMod && (chosenMod.default ?? chosenMod)) || chosenMod;
217
+ const { defineComponent, resolveComponent, createVNode, createTextVNode, createCommentVNode,
218
+ // We deliberately pull createApp here but assign it globally below to avoid mixing module instances
219
+ createApp: _createApp, Fragment, withCtx, openBlock, createBlock, createElementVNode, createElementBlock, renderSlot, mergeProps, toHandlers, renderList, normalizeProps, guardReactiveProps, withDirectives, resolveDirective, withModifiers, withKeys, isRef, ref, shallowRef, unref, computed, onMounted, onBeforeUnmount, onUnmounted, watch, nextTick, vShow, } = (runtime || {});
220
+ // Assign only if not already set to avoid clobbering potentially patched versions.
221
+ if (!vueAlready) {
222
+ g.defineComponent || (g.defineComponent = defineComponent);
223
+ g.resolveComponent || (g.resolveComponent = resolveComponent);
224
+ g.createVNode || (g.createVNode = createVNode);
225
+ g.createTextVNode || (g.createTextVNode = createTextVNode);
226
+ g.createCommentVNode || (g.createCommentVNode = createCommentVNode);
227
+ g.Fragment || (g.Fragment = Fragment);
228
+ // Critical: ensure createApp and runtime-bound classes/functions reference the same module instance
229
+ try {
230
+ g.createApp || (g.createApp = _createApp || runtime?.createApp || nvMod?.createApp || vueMod?.createApp);
231
+ }
232
+ catch { }
233
+ try {
234
+ g.NSVRoot || (g.NSVRoot = runtime?.NSVRoot || nvMod?.NSVRoot || vueMod?.NSVRoot);
235
+ }
236
+ catch { }
237
+ try {
238
+ g.registerElement || (g.registerElement = runtime?.registerElement || nvMod?.registerElement || vueMod?.registerElement);
239
+ }
240
+ catch { }
241
+ try {
242
+ g.start || (g.start = runtime?.start || nvMod?.start || vueMod?.start);
243
+ }
244
+ catch { }
245
+ g.withCtx || (g.withCtx = withCtx);
246
+ g.openBlock || (g.openBlock = openBlock);
247
+ g.createBlock || (g.createBlock = createBlock);
248
+ g.createElementVNode || (g.createElementVNode = createElementVNode || createVNode);
249
+ g.createElementBlock || (g.createElementBlock = createElementBlock || createBlock);
250
+ g.renderSlot || (g.renderSlot = renderSlot);
251
+ g.mergeProps || (g.mergeProps = mergeProps);
252
+ g.toHandlers || (g.toHandlers = toHandlers);
253
+ g.renderList || (g.renderList = renderList);
254
+ g.normalizeProps || (g.normalizeProps = normalizeProps);
255
+ g.guardReactiveProps || (g.guardReactiveProps = guardReactiveProps);
256
+ g.withDirectives || (g.withDirectives = withDirectives);
257
+ g.resolveDirective || (g.resolveDirective = resolveDirective);
258
+ g.withModifiers || (g.withModifiers = withModifiers);
259
+ g.withKeys || (g.withKeys = withKeys);
260
+ g.isRef || (g.isRef = isRef);
261
+ g.ref || (g.ref = ref);
262
+ g.shallowRef || (g.shallowRef = shallowRef);
263
+ g.unref || (g.unref = unref);
264
+ g.computed || (g.computed = computed);
265
+ g.onMounted || (g.onMounted = onMounted);
266
+ g.onBeforeUnmount || (g.onBeforeUnmount = onBeforeUnmount);
267
+ g.onUnmounted || (g.onUnmounted = onUnmounted);
268
+ g.watch || (g.watch = watch);
269
+ g.nextTick || (g.nextTick = nextTick);
270
+ // Built-in directives
271
+ g.vShow || (g.vShow = vShow);
272
+ // Create underscore aliases to satisfy compiled helper identifiers (e.g. _renderSlot)
273
+ try {
274
+ const alias = (from, to) => {
275
+ try {
276
+ const val = g[from];
277
+ const key = to || '_' + from;
278
+ if (val && !(key in g))
279
+ g[key] = val;
280
+ }
281
+ catch { }
282
+ };
283
+ alias('renderSlot');
284
+ alias('normalizeClass');
285
+ alias('normalizeStyle');
286
+ alias('toDisplayString');
287
+ alias('openBlock');
288
+ alias('createElementBlock');
289
+ alias('createElementVNode');
290
+ alias('createVNode');
291
+ alias('createBlock');
292
+ alias('normalizeProps');
293
+ alias('guardReactiveProps');
294
+ alias('mergeProps');
295
+ alias('toHandlers');
296
+ alias('withCtx');
297
+ alias('withDirectives');
298
+ alias('resolveComponent');
299
+ alias('resolveDirective');
300
+ alias('withModifiers');
301
+ alias('withKeys');
302
+ alias('isRef');
303
+ alias('unref');
304
+ alias('vShow');
305
+ alias('Fragment', '_Fragment');
306
+ }
307
+ catch { }
308
+ }
309
+ // Navigation helpers: no longer patched onto globalThis; use __nsNavigateUsingApp via imports or app instance
310
+ // If Vue was already present originally we still ensure nav helpers; that's why we delayed early return.
311
+ }
312
+ catch { }
313
+ }
314
+ // Ensure Pinia is installed on the given Vue app during HMR remounts.
315
+ // We keep a singleton Pinia instance on globalThis to preserve store state across resets when possible.
316
+ export function ensurePiniaOnApp(app) {
317
+ try {
318
+ if (!app || typeof app.use !== 'function')
319
+ return;
320
+ const g = globalThis;
321
+ // If this app already has a Pinia provide, skip
322
+ try {
323
+ const prov = app?._context?.provides;
324
+ if (prov) {
325
+ const hasString = Object.prototype.hasOwnProperty.call(prov, 'pinia');
326
+ const knownSym = g.__NS_PINIA_SYMBOL__;
327
+ const hasKnownSym = knownSym ? Object.prototype.hasOwnProperty.call(prov, knownSym) : false;
328
+ const hasSym = hasKnownSym || Object.getOwnPropertySymbols(prov).some((s) => /pinia/i.test(s.description || ''));
329
+ if (hasString || hasSym)
330
+ return;
331
+ }
332
+ }
333
+ catch { }
334
+ // If a global Pinia instance is already present, just use it and avoid importing new copies
335
+ if (g.__NS_HMR_PINIA__) {
336
+ try {
337
+ app.use(g.__NS_HMR_PINIA__);
338
+ }
339
+ catch { }
340
+ // Attempt to set active pinia if API is available
341
+ try {
342
+ const registry = g.__nsVendorRegistry;
343
+ const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
344
+ let piniaMod = null;
345
+ if (registry && registry.has('pinia'))
346
+ piniaMod = registry.get('pinia');
347
+ if (!piniaMod && typeof req === 'function') {
348
+ try {
349
+ piniaMod = req('pinia');
350
+ }
351
+ catch { }
352
+ }
353
+ const resolved = (piniaMod && (piniaMod.default ?? piniaMod)) || null;
354
+ const setActivePinia = resolved?.setActivePinia;
355
+ if (typeof setActivePinia === 'function')
356
+ setActivePinia(g.__NS_HMR_PINIA__);
357
+ }
358
+ catch { }
359
+ return;
360
+ }
361
+ // Prefer vendor registry/require to load 'pinia'
362
+ const registry = g.__nsVendorRegistry;
363
+ const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
364
+ let piniaMod = null;
365
+ if (registry && registry.has('pinia')) {
366
+ piniaMod = registry.get('pinia');
367
+ }
368
+ if (!piniaMod && typeof req === 'function') {
369
+ try {
370
+ piniaMod = req('pinia');
371
+ }
372
+ catch { }
373
+ }
374
+ if (!piniaMod)
375
+ return;
376
+ const resolved = (piniaMod && (piniaMod.default ?? piniaMod)) || null;
377
+ const createPinia = resolved?.createPinia;
378
+ const setActivePinia = resolved?.setActivePinia;
379
+ if (typeof createPinia !== 'function')
380
+ return;
381
+ // Reuse across HMR cycles
382
+ const pinia = (g.__NS_HMR_PINIA__ || (g.__NS_HMR_PINIA__ = createPinia()));
383
+ try {
384
+ app.use(pinia);
385
+ }
386
+ catch { }
387
+ try {
388
+ if (typeof setActivePinia === 'function')
389
+ setActivePinia(pinia);
390
+ }
391
+ catch { }
392
+ }
393
+ catch { }
394
+ }
395
+ // Prefer nativescript-vue's own bootstrap to set up element registry and built-ins
396
+ export function ensureNsVueBootstrap() {
397
+ try {
398
+ const g = globalThis;
399
+ if (nsVueInitDone)
400
+ return;
401
+ const reg = g.__nsVendorRegistry;
402
+ const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
403
+ if (typeof req !== 'function')
404
+ return;
405
+ // Try full init, which should register core elements and built-in components
406
+ try {
407
+ const nv = req('nativescript-vue/dist/nativescript');
408
+ const init = (nv && (nv.init || nv.default?.init)) || undefined;
409
+ if (typeof init === 'function') {
410
+ init();
411
+ nsVueInitDone = true;
412
+ if (__NS_ENV_VERBOSE__)
413
+ console.log('[hmr-client] nativescript-vue init() executed');
414
+ return;
415
+ }
416
+ }
417
+ catch { }
418
+ // Fallback: register core elements only
419
+ try {
420
+ const elems = req('nativescript-vue/dist/nativescript/elements');
421
+ const fn = (elems && (elems.registerCoreElements || elems.default?.registerCoreElements)) || undefined;
422
+ if (typeof fn === 'function') {
423
+ fn();
424
+ if (__NS_ENV_VERBOSE__)
425
+ console.log('[hmr-client] registerCoreElements executed');
426
+ }
427
+ }
428
+ catch { }
429
+ }
430
+ catch { }
431
+ }
432
+ // Install built-in components from nativescript-vue onto the given app (idempotent)
433
+ function installBuiltInComponentsOnApp(app) {
434
+ try {
435
+ if (!app || typeof app.component !== 'function')
436
+ return;
437
+ const g = globalThis;
438
+ const reg = g.__nsVendorRegistry;
439
+ const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
440
+ if (typeof req !== 'function')
441
+ return;
442
+ const comps = (() => {
443
+ try {
444
+ return req('nativescript-vue/dist/components');
445
+ }
446
+ catch {
447
+ return null;
448
+ }
449
+ })();
450
+ const built = comps && (comps.BUILT_IN_COMPONENTS || comps.default?.BUILT_IN_COMPONENTS);
451
+ if (!built || typeof built !== 'object')
452
+ return;
453
+ const ctx = app._context;
454
+ const registered = new Set(Object.keys((ctx && ctx.components) || {}));
455
+ for (const [name, def] of Object.entries(built)) {
456
+ try {
457
+ if (!registered.has(name)) {
458
+ app.component(name, def);
459
+ registered.add(name);
460
+ }
461
+ }
462
+ catch { }
463
+ }
464
+ if (__NS_ENV_VERBOSE__) {
465
+ console.log('[hmr-client] installed built-in components:', Array.from(registered).join(','));
466
+ }
467
+ }
468
+ catch { }
469
+ }
470
+ // Ensure the Pinia instance is also active in the HTTP ESM module world and that we provide
471
+ // the exact piniaSymbol exported by that module, so getActivePinia() and inject() both succeed
472
+ // regardless of which module copy a component imports.
473
+ async function syncPiniaAcrossEsm(app) {
474
+ try {
475
+ const g = globalThis;
476
+ const piniaInst = g.__NS_HMR_PINIA__ || app?._context?.provides?.pinia;
477
+ if (!piniaInst)
478
+ return;
479
+ // Resolve Pinia from ESM world and set active
480
+ let esmUrl = null;
481
+ try {
482
+ esmUrl = await requestModuleFromServer('pinia');
483
+ }
484
+ catch { }
485
+ if (esmUrl) {
486
+ try {
487
+ const mod = await safeDynImport(esmUrl);
488
+ const resolved = (mod && (mod.default ?? mod)) || mod;
489
+ const setActivePinia = resolved?.setActivePinia || mod?.setActivePinia;
490
+ const piniaSymbol = resolved?.piniaSymbol || mod?.piniaSymbol;
491
+ if (typeof setActivePinia === 'function') {
492
+ try {
493
+ setActivePinia(piniaInst);
494
+ }
495
+ catch { }
496
+ }
497
+ if (piniaSymbol && app?._context?.provides && !app._context.provides[piniaSymbol]) {
498
+ try {
499
+ app._context.provides[piniaSymbol] = piniaInst;
500
+ }
501
+ catch { }
502
+ try {
503
+ g.__NS_PINIA_SYMBOL__ = piniaSymbol;
504
+ }
505
+ catch { }
506
+ }
507
+ }
508
+ catch (e) {
509
+ if (__NS_ENV_VERBOSE__)
510
+ console.warn('[hmr-client] syncPiniaAcrossEsm failed import', e);
511
+ }
512
+ }
513
+ }
514
+ catch { }
515
+ }
516
+ function bridgePiniaProvides(app, existingApp) {
517
+ try {
518
+ const g = globalThis;
519
+ if (!app || !app._context)
520
+ return;
521
+ const newProv = app._context.provides || (app._context.provides = {});
522
+ // Determine pinia instance to bind
523
+ let piniaInst = g.__NS_HMR_PINIA__;
524
+ if (!piniaInst)
525
+ piniaInst = newProv['pinia'];
526
+ if (!piniaInst && existingApp)
527
+ piniaInst = existingApp?._context?.provides?.['pinia'];
528
+ if (!piniaInst && existingApp) {
529
+ const syms = Object.getOwnPropertySymbols(existingApp?._context?.provides || {});
530
+ for (const s of syms) {
531
+ if (/pinia/i.test(s.description || '')) {
532
+ piniaInst = existingApp._context.provides[s];
533
+ break;
534
+ }
535
+ }
536
+ }
537
+ if (!piniaInst)
538
+ return;
539
+ // Collect candidate symbols to bind
540
+ const candidates = [];
541
+ try {
542
+ const known = g.__NS_PINIA_SYMBOL__;
543
+ if (known && typeof known === 'symbol')
544
+ candidates.push(known);
545
+ }
546
+ catch { }
547
+ try {
548
+ const vendorReg = g.__nsVendorRegistry;
549
+ const req = vendorReg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
550
+ let vmod = null;
551
+ if (vendorReg && vendorReg.has('pinia'))
552
+ vmod = vendorReg.get('pinia');
553
+ else if (typeof req === 'function') {
554
+ try {
555
+ vmod = req('pinia');
556
+ }
557
+ catch { }
558
+ }
559
+ const resolved = (vmod && (vmod.default ?? vmod)) || vmod;
560
+ const vendorSym = resolved?.piniaSymbol || vmod?.piniaSymbol;
561
+ if (vendorSym && typeof vendorSym === 'symbol')
562
+ candidates.push(vendorSym);
563
+ // Also set active pinia on vendor module if possible
564
+ const setActivePinia = resolved?.setActivePinia || vmod?.setActivePinia;
565
+ if (typeof setActivePinia === 'function') {
566
+ try {
567
+ setActivePinia(piniaInst);
568
+ }
569
+ catch { }
570
+ }
571
+ }
572
+ catch { }
573
+ try {
574
+ const oldProv = existingApp?._context?.provides || {};
575
+ const oldSyms = Object.getOwnPropertySymbols(oldProv || {});
576
+ for (const s of oldSyms) {
577
+ if (/pinia/i.test(s.description || ''))
578
+ candidates.push(s);
579
+ }
580
+ }
581
+ catch { }
582
+ // De-duplicate symbols
583
+ const uniq = [];
584
+ for (const s of candidates) {
585
+ if (typeof s === 'symbol' && !uniq.includes(s))
586
+ uniq.push(s);
587
+ }
588
+ // Bind all symbols to the same instance
589
+ for (const s of uniq) {
590
+ try {
591
+ newProv[s] = piniaInst;
592
+ }
593
+ catch { }
594
+ }
595
+ // Also ensure string key for any code that looks up string provides
596
+ try {
597
+ if (!newProv['pinia'])
598
+ newProv['pinia'] = piniaInst;
599
+ }
600
+ catch { }
601
+ try {
602
+ g.__NS_PINIA_SYMBOL__ || (g.__NS_PINIA_SYMBOL__ = uniq[0] || undefined);
603
+ }
604
+ catch { }
605
+ if (__NS_ENV_VERBOSE__) {
606
+ try {
607
+ const syms = Object.getOwnPropertySymbols(newProv).map((s) => s.description || String(s));
608
+ console.log('[hmr-client] bridged pinia provides', {
609
+ stringKey: !!newProv['pinia'],
610
+ symbols: syms,
611
+ });
612
+ }
613
+ catch { }
614
+ }
615
+ }
616
+ catch { }
617
+ }
618
+ export function handleVueSfcRegistry(msg) {
619
+ try {
620
+ const entries = msg.entries || [];
621
+ // Mapping-only: record presence for quick readiness checks (no disk writes in HTTP mode)
622
+ for (const e of entries) {
623
+ addSfcMapping(e.path, e.fileName);
624
+ }
625
+ if (__NS_ENV_VERBOSE__)
626
+ console.log('[hmr][sfc-registry] entries=', entries.length, 'map size', sfcArtifactMap.size);
627
+ }
628
+ catch (e) {
629
+ console.warn('[hmr-client][sfc-registry] install failed', e);
630
+ }
631
+ }
632
+ export async function handleVueSfcRegistryUpdate(msg, graphVersion) {
633
+ try {
634
+ if (typeof msg.path === 'string' && /\.vue$/i.test(msg.path)) {
635
+ // Gate updates: only remount if this path is actually marked as changed in the current delta
636
+ try {
637
+ const base = String(msg.path).split('?')[0];
638
+ const inChanged = sfcChangedIds.has(base) || sfcChangedIds.has(msg.path);
639
+ const versionsMatch = sfcChangedVersion != null && sfcChangedVersion === graphVersion;
640
+ if (!inChanged || !versionsMatch) {
641
+ // Be resilient to out-of-order delivery: treat the registry update itself
642
+ // as authoritative signal that this SFC changed for the announced version.
643
+ // This unblocks remounts when the delta was dropped or applied earlier than we recorded.
644
+ try {
645
+ const effectiveVersion = typeof msg.version === 'number' ? msg.version : graphVersion;
646
+ sfcChangedVersion = effectiveVersion;
647
+ sfcChangedIds.add(base);
648
+ if (__NS_ENV_VERBOSE__)
649
+ console.log('[hmr][sfc-registry-update] accepting as change (out-of-order)', { path: msg.path, graphVersion, sfcChangedVersion });
650
+ }
651
+ catch { }
652
+ }
653
+ }
654
+ catch { }
655
+ try {
656
+ ensureVueGlobals();
657
+ const changedPath = String(msg.path);
658
+ // Prefer remounting the SFC that actually changed so you immediately see it
659
+ // (e.g., editing Details.vue should remount Details.vue even if Home.vue is currently displayed).
660
+ // This keeps existing behavior intact when the changed file is already the root.
661
+ const targetPath = changedPath;
662
+ const comp = await loadSfcComponent(targetPath, 'sfc_update');
663
+ return comp;
664
+ }
665
+ catch (e) {
666
+ console.warn('[hmr-client] update path failed for', msg.path, e);
667
+ }
668
+ }
669
+ return;
670
+ }
671
+ catch (e) {
672
+ console.warn('[hmr-client][sfc-registry] update failed', e);
673
+ }
674
+ }
675
+ export function recordVuePayloadChanges(changed, graphVersion) {
676
+ // Record .vue changes seen in this delta
677
+ let sawVue = false;
678
+ for (const m of changed) {
679
+ if (m && typeof m.id === 'string' && /\.vue$/i.test(m.id)) {
680
+ sfcChangedIds.add(m.id);
681
+ sawVue = true;
682
+ }
683
+ }
684
+ if (sawVue)
685
+ sfcChangedVersion = graphVersion;
686
+ }
687
+ async function waitForSfcMapping(id, timeoutMs = 350) {
688
+ if (!/\.vue$/i.test(id))
689
+ return true;
690
+ const base = id.split('?')[0];
691
+ const srcIdx = base.indexOf('/src/');
692
+ const rel = srcIdx !== -1 ? base.slice(srcIdx) : base;
693
+ if (sfcArtifactMap.has(rel) || sfcArtifactMap.has(base))
694
+ return true;
695
+ const start = Date.now();
696
+ while (Date.now() - start < timeoutMs) {
697
+ await new Promise((r) => setTimeout(r, 30));
698
+ if (sfcArtifactMap.has(rel) || sfcArtifactMap.has(base))
699
+ return true;
700
+ }
701
+ return false;
702
+ }
703
+ // Map a graph id (possibly a .vue source path) to actual import spec
704
+ export function addSfcMapping(originalPath, fileName) {
705
+ try {
706
+ if (!originalPath || !fileName)
707
+ return;
708
+ const base = originalPath.split('?')[0];
709
+ const norm = normalizeSpec(base);
710
+ // Also derive a relative variant if under /src/ to handle lookups that slice to /src/ portion
711
+ let rel = norm;
712
+ const srcIdx = norm.indexOf('/src/');
713
+ if (srcIdx !== -1)
714
+ rel = norm.slice(srcIdx);
715
+ sfcArtifactMap.set(norm, fileName);
716
+ if (rel !== norm)
717
+ sfcArtifactMap.set(rel, fileName);
718
+ }
719
+ catch { }
720
+ }
721
+ // Build explicit SFC variant URL (script/template). Always preserves the variant query.
722
+ function resolveSfcVariantSpec(id, type, cacheBustTag) {
723
+ const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
724
+ const base = id.split('?')[0];
725
+ if (!origin)
726
+ return base + `?vue&type=${type}`;
727
+ const safePath = base.startsWith('/') ? base : '/' + base;
728
+ const ver = typeof getGraphVersion() === 'number' && getGraphVersion() > 0 ? String(getGraphVersion()) : '0';
729
+ let url = origin + `/ns/sfc/${ver}` + safePath + `?vue&type=${type}`;
730
+ return url;
731
+ }
732
+ // Resolve deterministic SFC assembler ESM module
733
+ function resolveSfcAssemblerSpec(id, cacheBustTag) {
734
+ const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
735
+ const base = id.split('?')[0];
736
+ if (!origin)
737
+ return base; // fallback: device will likely fail; origin should be available in dev
738
+ const safePath = base.startsWith('/') ? base : '/' + base;
739
+ const ver = typeof getGraphVersion() === 'number' && getGraphVersion() > 0 ? String(getGraphVersion()) : '0';
740
+ let url = origin + `/ns/asm/${ver}` + `?path=${encodeURIComponent(safePath)}`;
741
+ try {
742
+ if (globalThis.__NS_HMR_ASM_DIAG__) {
743
+ url += '&diag=1';
744
+ }
745
+ }
746
+ catch { }
747
+ return url;
748
+ }
749
+ // Resolve metadata endpoint for an SFC
750
+ function resolveSfcMetaSpec(id, cacheBustTag) {
751
+ const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
752
+ const base = id.split('?')[0];
753
+ if (!origin)
754
+ return base;
755
+ const safePath = base.startsWith('/') ? base : '/' + base;
756
+ const ver = typeof getGraphVersion() === 'number' && getGraphVersion() > 0 ? String(getGraphVersion()) : '0';
757
+ let url = origin + `/ns/sfc-meta/${ver}` + `?path=${encodeURIComponent(safePath)}`;
758
+ return url;
759
+ }
760
+ async function fetchSfcMeta(id, tag) {
761
+ try {
762
+ const url = resolveSfcMetaSpec(id, tag + '_meta');
763
+ const res = await fetch(url, { method: 'GET' });
764
+ if (!res.ok)
765
+ return null;
766
+ const json = await res.json();
767
+ return json;
768
+ }
769
+ catch {
770
+ return null;
771
+ }
772
+ }
773
+ // Safely load a component for a .vue SFC. Prefer deterministic assembler first to avoid
774
+ // any variant-compile or TDZ flakiness; only fall back to variant assembly if needed.
775
+ export async function loadSfcComponent(targetVuePath, tag) {
776
+ // Minimal mode removed: always go through deterministic assembler + device reset
777
+ // Ensure Vue globals exist BEFORE evaluating variant modules; their top-level aliasing reads globalThis.* once.
778
+ ensureVueGlobals();
779
+ // Consult metadata to choose optimal path
780
+ let meta = null;
781
+ try {
782
+ meta = await fetchSfcMeta(targetVuePath, tag);
783
+ }
784
+ catch { }
785
+ if (__NS_ENV_VERBOSE__ && meta) {
786
+ try {
787
+ console.log('[hmr][vue-reset][meta]', targetVuePath, meta);
788
+ }
789
+ catch { }
790
+ }
791
+ // Prefer deterministic assembler first so AST normalization (including nav helpers) always applies.
792
+ try {
793
+ if (!DISABLE_ASM) {
794
+ const asmMod = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm_first'));
795
+ const asmComp = asmMod?.default ?? asmMod;
796
+ if (asmComp && typeof asmComp === 'object') {
797
+ if (__NS_ENV_VERBOSE__)
798
+ console.log('[hmr][vue-reset][diag] using assembler-first component');
799
+ return asmComp;
800
+ }
801
+ }
802
+ }
803
+ catch (e) {
804
+ if (__NS_ENV_VERBOSE__)
805
+ console.warn('[hmr][vue-reset][diag] assembler-first failed; trying variants', e);
806
+ }
807
+ // 1) Variant assembly (script then template) – closest to browser behavior
808
+ try {
809
+ // Import script variant FIRST to avoid TDZ due to cyclic evaluation between script/template.
810
+ const scriptMod = await safeDynImport(resolveSfcVariantSpec(targetVuePath, 'script', tag + '_script'));
811
+ // Ensure script default is readable before importing the template; this enforces a stable order.
812
+ const base = await safeReadDefault(scriptMod);
813
+ // Now import the template render implementation
814
+ const templateMod = await safeDynImport(resolveSfcVariantSpec(targetVuePath, 'template', tag + '_template'));
815
+ if (__NS_ENV_VERBOSE__) {
816
+ try {
817
+ const sKeys = scriptMod ? Object.keys(scriptMod).join(',') : '<none>';
818
+ const tKeys = templateMod ? Object.keys(templateMod).join(',') : '<none>';
819
+ console.log('[hmr][vue-reset][diag] variant-imports', targetVuePath, 'script.keys=', sKeys, 'template.keys=', tKeys);
820
+ try {
821
+ console.log('[hmr][vue-reset][diag] scriptMod:', scriptMod);
822
+ }
823
+ catch { }
824
+ try {
825
+ console.log('[hmr][vue-reset][diag] templateMod:', {
826
+ render: typeof templateMod?.render,
827
+ });
828
+ }
829
+ catch { }
830
+ }
831
+ catch { }
832
+ }
833
+ // Only use variant assembly when the script provides a real component options object.
834
+ const render = templateMod?.render;
835
+ const scriptExports = scriptMod || {};
836
+ const exportKeys = Object.keys(scriptExports).filter((k) => k !== 'default' && k !== '__esModule');
837
+ if (base && typeof base === 'object') {
838
+ // If variant template didn't produce a render, try assembler as a targeted fallback.
839
+ if (!render) {
840
+ try {
841
+ if (__NS_ENV_VERBOSE__)
842
+ console.log('[hmr][vue-reset][diag] no render from template variant; attempting assembler for', targetVuePath);
843
+ const asmMod = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm_norender'));
844
+ const asmComp = asmMod?.default ?? asmMod;
845
+ if (asmComp && typeof asmComp === 'object' && typeof asmComp.render === 'function') {
846
+ try {
847
+ base.render = asmComp.render;
848
+ }
849
+ catch { }
850
+ }
851
+ }
852
+ catch (e) {
853
+ if (__NS_ENV_VERBOSE__)
854
+ console.warn('[hmr][vue-reset][diag] assembler no-render fallback failed', e);
855
+ }
856
+ }
857
+ else {
858
+ try {
859
+ base.render = render;
860
+ }
861
+ catch { }
862
+ }
863
+ // Merge named exports (likely locally-declared components) into the component's components map
864
+ if (exportKeys.length) {
865
+ try {
866
+ base.components = base.components || {};
867
+ for (const k of exportKeys) {
868
+ try {
869
+ base.components[k] = scriptExports[k];
870
+ }
871
+ catch { }
872
+ }
873
+ }
874
+ catch { }
875
+ }
876
+ if (__NS_ENV_VERBOSE__) {
877
+ try {
878
+ console.log('[hmr][vue-reset][diag] assembled.component (from script default) keys=', Object.keys(base).join(','), 'has.render=', !!base.render, 'components=', Object.keys(base.components || {}).join(','));
879
+ }
880
+ catch { }
881
+ }
882
+ return base;
883
+ }
884
+ // If script default is absent (common with <script setup> or named exports), but we have a template render,
885
+ // prefer loading the full SFC first if the script provided no named exports — the full SFC may contain
886
+ // compiled metadata (local components, hoisted helpers) that variant assembly can't reconstruct.
887
+ if (!base && typeof render === 'function') {
888
+ if (!exportKeys.length) {
889
+ if (__NS_ENV_VERBOSE__)
890
+ console.log('[hmr][vue-reset][diag] no script exports detected; attempting assembler import for', targetVuePath);
891
+ try {
892
+ const asm = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm'));
893
+ const compAsm = asm?.default ?? asm;
894
+ if (compAsm && typeof compAsm === 'object') {
895
+ if (__NS_ENV_VERBOSE__)
896
+ console.log('[hmr][vue-reset][diag] assembler import succeeded and will be used');
897
+ return compAsm;
898
+ }
899
+ }
900
+ catch (e) {
901
+ if (__NS_ENV_VERBOSE__)
902
+ console.warn('[hmr][vue-reset][diag] assembler import failed, will synthesize as fallback', e);
903
+ }
904
+ }
905
+ // Synthesize a minimal component and attach named exports as local components so template resolveComponent works.
906
+ try {
907
+ ensureVueGlobals();
908
+ const comp = globalThis.defineComponent
909
+ ? globalThis.defineComponent({
910
+ name: targetVuePath.split('/').pop() || 'AnonymousSFC',
911
+ render,
912
+ })
913
+ : {
914
+ name: targetVuePath.split('/').pop() || 'AnonymousSFC',
915
+ render,
916
+ };
917
+ if (exportKeys.length) {
918
+ try {
919
+ comp.components = comp.components || {};
920
+ for (const k of exportKeys) {
921
+ try {
922
+ comp.components[k] = scriptExports[k];
923
+ }
924
+ catch { }
925
+ }
926
+ }
927
+ catch { }
928
+ }
929
+ if (__NS_ENV_VERBOSE__) {
930
+ try {
931
+ console.log('[hmr][vue-reset][diag] synthesized.component keys=', Object.keys(comp).join(','), 'components=', Object.keys(comp.components || {}).join(','));
932
+ }
933
+ catch { }
934
+ }
935
+ return comp;
936
+ }
937
+ catch (e) {
938
+ if (__NS_ENV_VERBOSE__)
939
+ console.warn('[hmr][vue-reset][diag] synthesize component failed', e);
940
+ }
941
+ }
942
+ // Otherwise fall through to full SFC import.
943
+ }
944
+ catch (e2) {
945
+ if (__NS_ENV_VERBOSE__)
946
+ console.warn('[hmr][vue-reset][variant-import] failed; will try full SFC', targetVuePath, e2);
947
+ }
948
+ // 2) Final fallback: assembler import (after a short delay to let dependents settle)
949
+ try {
950
+ if (DISABLE_ASM)
951
+ throw new Error('asm disabled by __NS_HMR_DISABLE_ASM__');
952
+ await new Promise((r) => setTimeout(r, 10));
953
+ const mod = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm_final'));
954
+ try {
955
+ const comp = await safeReadDefault(mod);
956
+ if (comp)
957
+ return comp;
958
+ }
959
+ catch (err) {
960
+ if (__NS_ENV_VERBOSE__)
961
+ console.warn('[hmr][vue-reset][asm-import-default-read] error', targetVuePath, err);
962
+ }
963
+ }
964
+ catch (e) {
965
+ if (__NS_ENV_VERBOSE__)
966
+ console.warn('[hmr][vue-reset][asm-import] failed', targetVuePath, e);
967
+ }
968
+ // Final soft fallback: return a minimal placeholder so rerender can proceed and surface UI
969
+ return null;
970
+ }
971
+ export function getRootForVue(newComponent, state) {
972
+ const t0 = Date.now();
973
+ if (__NS_ENV_VERBOSE__)
974
+ console.log('[hmr-client] [createRoot] begin');
975
+ ensureVueGlobals();
976
+ const g = globalThis;
977
+ const AppFactory = g.createApp;
978
+ let RootCtor = g.NSVRoot;
979
+ // Hygiene: unmount any existing app instance to avoid duplicate lifecycle hooks
980
+ try {
981
+ const existing = (getCurrentApp() || g.__NS_VUE_APP__);
982
+ if (existing && typeof existing.unmount === 'function') {
983
+ if (__NS_ENV_VERBOSE__)
984
+ console.log('[hmr-client] [createRoot] unmounting existing app before remount');
985
+ try {
986
+ existing.unmount();
987
+ }
988
+ catch { }
989
+ }
990
+ }
991
+ catch { }
992
+ try {
993
+ if (!RootCtor) {
994
+ const registry = g.__nsVendorRegistry;
995
+ const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
996
+ let domMod = null;
997
+ if (registry && registry.has('nativescript-vue/dist/dom')) {
998
+ domMod = registry.get('nativescript-vue/dist/dom');
999
+ if (__NS_ENV_VERBOSE__)
1000
+ console.log('[hmr-client] [createRoot] NS DOM from vendor registry');
1001
+ }
1002
+ else if (typeof req === 'function') {
1003
+ try {
1004
+ domMod = req('nativescript-vue/dist/dom');
1005
+ if (__NS_ENV_VERBOSE__)
1006
+ console.log('[hmr-client] [createRoot] NS DOM via require');
1007
+ }
1008
+ catch (e) {
1009
+ if (__NS_ENV_VERBOSE__)
1010
+ console.warn('[hmr-client] [createRoot] NS DOM require failed', e);
1011
+ }
1012
+ }
1013
+ if (domMod) {
1014
+ const nsDom = (domMod && (domMod.default ?? domMod)) || domMod;
1015
+ const ctor = nsDom?.NSVRoot || (nsDom?.default && nsDom.default.NSVRoot) || domMod?.NSVRoot;
1016
+ if (ctor)
1017
+ RootCtor = ctor;
1018
+ }
1019
+ }
1020
+ }
1021
+ catch { }
1022
+ const existingApp = getCurrentApp() || g.__NS_VUE_APP__;
1023
+ try {
1024
+ ensureNsVueBootstrap();
1025
+ if (__NS_ENV_VERBOSE__)
1026
+ console.log('[hmr-client] [createRoot] ensured NS-Vue bootstrap');
1027
+ }
1028
+ catch (e) {
1029
+ if (__NS_ENV_VERBOSE__)
1030
+ console.warn('[hmr-client] [createRoot] ensureNsVueBootstrap failed', e);
1031
+ }
1032
+ try {
1033
+ if (typeof g.start === 'function' && !nsStartDone) {
1034
+ if (__NS_ENV_VERBOSE__)
1035
+ console.log('[hmr-client] [createRoot] invoking global start()');
1036
+ g.start();
1037
+ nsStartDone = true;
1038
+ }
1039
+ }
1040
+ catch (e) {
1041
+ if (__NS_ENV_VERBOSE__)
1042
+ console.warn('[hmr-client] [createRoot] start() failed', e);
1043
+ }
1044
+ if (!RootCtor)
1045
+ throw new Error('NSVRoot constructor unavailable during HMR remount');
1046
+ let app;
1047
+ try {
1048
+ const mk = globalThis.__NS_HMR_CREATE_APP__;
1049
+ if (typeof mk === 'function') {
1050
+ app = mk(newComponent);
1051
+ if (__NS_ENV_VERBOSE__)
1052
+ console.log('[hmr-client] [createRoot] app created via custom factory');
1053
+ }
1054
+ }
1055
+ catch (e) {
1056
+ if (__NS_ENV_VERBOSE__)
1057
+ console.warn('[hmr-client] [createRoot] custom app factory failed', e);
1058
+ }
1059
+ if (!app) {
1060
+ app = AppFactory(newComponent);
1061
+ if (__NS_ENV_VERBOSE__)
1062
+ console.log('[hmr-client] [createRoot] app created via createApp');
1063
+ }
1064
+ try {
1065
+ const registry = g.__nsVendorRegistry;
1066
+ const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
1067
+ let rh = null;
1068
+ if (registry && registry.has('nativescript-vue/dist/runtimeHelpers'))
1069
+ rh = registry.get('nativescript-vue/dist/runtimeHelpers');
1070
+ if (!rh && typeof req === 'function') {
1071
+ try {
1072
+ rh = req('nativescript-vue/dist/runtimeHelpers');
1073
+ }
1074
+ catch { }
1075
+ }
1076
+ const setRootApp = rh && (rh.setRootApp || rh.default?.setRootApp);
1077
+ if (typeof setRootApp === 'function') {
1078
+ setRootApp(app);
1079
+ if (__NS_ENV_VERBOSE__)
1080
+ console.log('[hmr-client] [createRoot] runtimeHelpers.setRootApp applied');
1081
+ }
1082
+ try {
1083
+ let nv = null;
1084
+ if (registry && registry.has('nativescript-vue'))
1085
+ nv = registry.get('nativescript-vue');
1086
+ if (!nv && typeof req === 'function') {
1087
+ try {
1088
+ nv = req('nativescript-vue');
1089
+ }
1090
+ catch { }
1091
+ }
1092
+ const setRootApp2 = nv && (nv.setRootApp || nv.default?.setRootApp);
1093
+ if (typeof setRootApp2 === 'function') {
1094
+ setRootApp2(app);
1095
+ if (__NS_ENV_VERBOSE__)
1096
+ console.log('[hmr-client] [createRoot] nativescript-vue.setRootApp applied');
1097
+ }
1098
+ }
1099
+ catch { }
1100
+ }
1101
+ catch { }
1102
+ try {
1103
+ const hook = globalThis.__NS_HMR_INSTALL_PLUGINS__;
1104
+ if (typeof hook === 'function') {
1105
+ hook(app);
1106
+ if (__NS_ENV_VERBOSE__)
1107
+ console.log('[hmr-client] [createRoot] plugins installed');
1108
+ }
1109
+ }
1110
+ catch (e) {
1111
+ if (__NS_ENV_VERBOSE__)
1112
+ console.warn('[hmr-client] [createRoot] plugin install failed', e);
1113
+ }
1114
+ try {
1115
+ ensurePiniaOnApp(app);
1116
+ if (__NS_ENV_VERBOSE__)
1117
+ console.log('[hmr-client] [createRoot] Pinia ensured on app');
1118
+ }
1119
+ catch (e) {
1120
+ if (__NS_ENV_VERBOSE__)
1121
+ console.warn('[hmr-client] [createRoot] ensurePiniaOnApp failed', e);
1122
+ }
1123
+ try {
1124
+ (async () => {
1125
+ try {
1126
+ await syncPiniaAcrossEsm(app);
1127
+ if (__NS_ENV_VERBOSE__)
1128
+ console.log('[hmr-client] [createRoot] Pinia state sync requested');
1129
+ }
1130
+ catch (e) {
1131
+ if (__NS_ENV_VERBOSE__)
1132
+ console.warn('[hmr-client] [createRoot] syncPiniaAcrossEsm failed', e);
1133
+ }
1134
+ })();
1135
+ }
1136
+ catch { }
1137
+ try {
1138
+ bridgePiniaProvides(app, existingApp);
1139
+ if (__NS_ENV_VERBOSE__)
1140
+ console.log('[hmr-client] [createRoot] provides bridged from previous app');
1141
+ }
1142
+ catch (e) {
1143
+ if (__NS_ENV_VERBOSE__)
1144
+ console.warn('[hmr-client] [createRoot] bridgePiniaProvides failed', e);
1145
+ }
1146
+ try {
1147
+ installBuiltInComponentsOnApp(app);
1148
+ if (__NS_ENV_VERBOSE__)
1149
+ console.log('[hmr-client] [createRoot] built-in components installed');
1150
+ }
1151
+ catch (e) {
1152
+ if (__NS_ENV_VERBOSE__)
1153
+ console.warn('[hmr-client] [createRoot] installBuiltInComponentsOnApp failed', e);
1154
+ }
1155
+ const root = new RootCtor();
1156
+ const vm = typeof app.runWithContext === 'function' ? app.runWithContext(() => app.mount(root)) : app.mount(root);
1157
+ setCurrentApp(app);
1158
+ if (__NS_ENV_VERBOSE__) {
1159
+ try {
1160
+ console.log('[hmr-client] [createRoot] mount result', {
1161
+ hasEl: !!vm?.$el,
1162
+ elType: vm?.$el?.constructor?.name,
1163
+ hasNativeView: !!vm?.$el?.nativeView,
1164
+ nativeViewType: vm?.$el?.nativeView?.constructor?.name,
1165
+ elapsedMs: Date.now() - t0,
1166
+ });
1167
+ }
1168
+ catch { }
1169
+ }
1170
+ const findNativeView = (element) => {
1171
+ if (element?.nativeView)
1172
+ return element.nativeView;
1173
+ const children = element?.childNodes || element?.children || [];
1174
+ for (const child of children) {
1175
+ const res = findNativeView(child);
1176
+ if (res)
1177
+ return res;
1178
+ }
1179
+ return null;
1180
+ };
1181
+ const findFrameNativeView = (element) => {
1182
+ if (!element)
1183
+ return null;
1184
+ const nv = element.nativeView;
1185
+ if (nv) {
1186
+ const ctorName = String(nv?.constructor?.name || '').replace(/^_+/, '');
1187
+ if (ctorName === 'Frame' || /^Frame(\$\d+)?$/.test(ctorName))
1188
+ return nv;
1189
+ }
1190
+ const kids = element?.childNodes || element?.children || [];
1191
+ for (const k of kids) {
1192
+ const res = findFrameNativeView(k);
1193
+ if (res)
1194
+ return res;
1195
+ }
1196
+ return null;
1197
+ };
1198
+ const findPageNativeView = (element) => {
1199
+ if (!element)
1200
+ return null;
1201
+ const nv = element.nativeView;
1202
+ if (nv) {
1203
+ const ctorName = String(nv?.constructor?.name || '').replace(/^_+/, '');
1204
+ if (ctorName === 'Page' || /^Page(\$\d+)?$/.test(ctorName))
1205
+ return nv;
1206
+ }
1207
+ const kids = element?.childNodes || element?.children || [];
1208
+ for (const k of kids) {
1209
+ const res = findPageNativeView(k);
1210
+ if (res)
1211
+ return res;
1212
+ }
1213
+ return null;
1214
+ };
1215
+ // Prefer adopting a Frame if the component produced one. This avoids nesting a Frame inside
1216
+ // the placeholder Frame and ensures a single authoritative Frame for app navigation.
1217
+ const nativeView = findFrameNativeView(vm?.$el) || findPageNativeView(vm?.$el) || findNativeView(vm?.$el);
1218
+ const GPage = getCore('Page');
1219
+ // Decide root type and cache it
1220
+ if (nativeView) {
1221
+ const ctorName = String(nativeView?.constructor?.name || '').replace(/^_+/, '');
1222
+ if (__NS_ENV_VERBOSE__)
1223
+ console.log('[hmr-client] [createRoot] nativeView found', {
1224
+ ctorName,
1225
+ });
1226
+ // Treat Frame as authoritative root regardless of whether it already has a currentPage.
1227
+ // This avoids producing a Frame inside a wrapper Page which can lead to blank content in complex apps.
1228
+ if (ctorName === 'Frame' || /^Frame(\$\d+)?$/.test(ctorName)) {
1229
+ try {
1230
+ attachDiagnosticsToFrame(nativeView);
1231
+ }
1232
+ catch { }
1233
+ if (__NS_ENV_VERBOSE__)
1234
+ console.log('[hmr-client] [createRoot] root kind=frame (adopting component Frame)');
1235
+ state.setRootKind('frame');
1236
+ state.setCachedRoot(nativeView);
1237
+ return state.getCachedRoot();
1238
+ }
1239
+ if (ctorName === 'Page' || /^Page(\$\d+)?$/.test(ctorName)) {
1240
+ if (__NS_ENV_VERBOSE__)
1241
+ console.log('[hmr-client] [createRoot] root kind=page');
1242
+ state.setRootKind('page');
1243
+ state.setCachedRoot(nativeView);
1244
+ return state.getCachedRoot();
1245
+ }
1246
+ // Treat Frame$N as Frame as well
1247
+ if (ctorName === 'Frame_OLD_NEVER_REACHED') {
1248
+ // If a Frame is produced, prefer adopting the Frame as the new root to ensure a single authoritative Frame.
1249
+ // Extracting the Page and navigating a placeholder Frame can split realms and break app-controlled navigation.
1250
+ let pageCandidate = undefined;
1251
+ try {
1252
+ pageCandidate = nativeView.currentPage || nativeView._currentEntry?.resolvedPage;
1253
+ }
1254
+ catch { }
1255
+ if (pageCandidate) {
1256
+ if (__NS_ENV_VERBOSE__)
1257
+ console.log('[hmr-client] [createRoot] Frame root with currentPage detected; adopting Frame as root');
1258
+ state.setRootKind('frame');
1259
+ state.setCachedRoot(nativeView);
1260
+ return state.getCachedRoot();
1261
+ }
1262
+ // No currentPage yet; construct a Page wrapper and mount the component inside it
1263
+ try {
1264
+ if (__NS_ENV_VERBOSE__)
1265
+ console.log('[hmr-client] [createRoot] no currentPage; creating Page wrapper for navigation-first');
1266
+ const registry = globalThis.__nsVendorRegistry;
1267
+ const req = registry?.get ? globalThis.__nsVendorRequire || globalThis.__nsRequire || globalThis.require : globalThis.__nsRequire || globalThis.require;
1268
+ let vueMod = null;
1269
+ if (registry && registry.has('vue'))
1270
+ vueMod = registry.get('vue');
1271
+ if (!vueMod && typeof req === 'function') {
1272
+ try {
1273
+ vueMod = req('vue');
1274
+ }
1275
+ catch { }
1276
+ }
1277
+ const h = vueMod?.h;
1278
+ const WrappedRoot = h
1279
+ ? {
1280
+ name: 'HMRPageWrapper',
1281
+ setup() {
1282
+ return () => h('Page', null, [h(newComponent)]);
1283
+ },
1284
+ }
1285
+ : null;
1286
+ if (WrappedRoot) {
1287
+ const g = globalThis;
1288
+ const AppFactory = g.createApp;
1289
+ let app2 = AppFactory(WrappedRoot);
1290
+ try {
1291
+ const reg2 = g.__nsVendorRegistry;
1292
+ const req2 = reg2?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
1293
+ let rh2 = null;
1294
+ if (reg2 && reg2.has('nativescript-vue/dist/runtimeHelpers'))
1295
+ rh2 = reg2.get('nativescript-vue/dist/runtimeHelpers');
1296
+ if (!rh2 && typeof req2 === 'function') {
1297
+ try {
1298
+ rh2 = req2('nativescript-vue/dist/runtimeHelpers');
1299
+ }
1300
+ catch { }
1301
+ }
1302
+ const setRootApp2a = rh2 && (rh2.setRootApp || rh2.default?.setRootApp);
1303
+ if (typeof setRootApp2a === 'function')
1304
+ setRootApp2a(app2);
1305
+ try {
1306
+ let nv2 = null;
1307
+ if (reg2 && reg2.has('nativescript-vue'))
1308
+ nv2 = reg2.get('nativescript-vue');
1309
+ if (!nv2 && typeof req2 === 'function') {
1310
+ try {
1311
+ nv2 = req2('nativescript-vue');
1312
+ }
1313
+ catch { }
1314
+ }
1315
+ const setRootApp2b = nv2 && (nv2.setRootApp || nv2.default?.setRootApp);
1316
+ if (typeof setRootApp2b === 'function')
1317
+ setRootApp2b(app2);
1318
+ }
1319
+ catch { }
1320
+ }
1321
+ catch { }
1322
+ try {
1323
+ const hook = globalThis.__NS_HMR_INSTALL_PLUGINS__;
1324
+ if (typeof hook === 'function')
1325
+ hook(app2);
1326
+ }
1327
+ catch { }
1328
+ try {
1329
+ ensurePiniaOnApp(app2);
1330
+ }
1331
+ catch { }
1332
+ try {
1333
+ bridgePiniaProvides(app2, getCurrentApp() || globalThis.__NS_VUE_APP__);
1334
+ }
1335
+ catch { }
1336
+ try {
1337
+ installBuiltInComponentsOnApp(app2);
1338
+ }
1339
+ catch { }
1340
+ const RootCtor2 = globalThis.NSVRoot || RootCtor;
1341
+ const root2 = new RootCtor2();
1342
+ const vm2 = typeof app2.runWithContext === 'function' ? app2.runWithContext(() => app2.mount(root2)) : app2.mount(root2);
1343
+ setCurrentApp(app2);
1344
+ const findNativeView2 = (element) => {
1345
+ if (element?.nativeView)
1346
+ return element.nativeView;
1347
+ const kids = element?.childNodes || element?.children || [];
1348
+ for (const c of kids) {
1349
+ const r = findNativeView2(c);
1350
+ if (r)
1351
+ return r;
1352
+ }
1353
+ return null;
1354
+ };
1355
+ const findPageNativeView2 = (element) => {
1356
+ if (!element)
1357
+ return null;
1358
+ const nv = element.nativeView;
1359
+ if (nv) {
1360
+ const ctorName = String(nv?.constructor?.name || '').replace(/^_+/, '');
1361
+ if (ctorName === 'Page' || /^Page(\$\d+)?$/.test(ctorName))
1362
+ return nv;
1363
+ }
1364
+ const kids = element?.childNodes || element?.children || [];
1365
+ for (const k of kids) {
1366
+ const r = findPageNativeView2(k);
1367
+ if (r)
1368
+ return r;
1369
+ }
1370
+ return null;
1371
+ };
1372
+ const nv2 = findPageNativeView2(vm2?.$el) || findNativeView2(vm2?.$el);
1373
+ const ctor2 = String(nv2?.constructor?.name || '').replace(/^_+/, '');
1374
+ if (ctor2 === 'Page' || /^Page(\$\d+)?$/.test(ctor2)) {
1375
+ // Hide wrapper ActionBar to avoid double bars when a Frame is nested inside
1376
+ try {
1377
+ nv2.actionBarHidden = true;
1378
+ }
1379
+ catch { }
1380
+ if (__NS_ENV_VERBOSE__)
1381
+ console.log('[hmr-client] [createRoot] Page wrapper created successfully');
1382
+ state.setRootKind('page');
1383
+ state.setCachedRoot(nv2);
1384
+ return state.getCachedRoot();
1385
+ }
1386
+ if (__NS_ENV_VERBOSE__)
1387
+ console.warn('[hmr-client] [createRoot] Page wrapper did not yield Page; got', ctor2);
1388
+ }
1389
+ }
1390
+ catch (e) {
1391
+ if (__NS_ENV_VERBOSE__)
1392
+ console.warn('[hmr-client] [createRoot] Page wrapper attempt failed', e);
1393
+ }
1394
+ if (__NS_ENV_VERBOSE__)
1395
+ console.log('[hmr-client] [createRoot] root kind=frame (no currentPage)');
1396
+ state.setRootKind('frame');
1397
+ state.setCachedRoot(nativeView);
1398
+ return state.getCachedRoot();
1399
+ }
1400
+ if (GPage) {
1401
+ const page = new GPage();
1402
+ page.content = nativeView;
1403
+ // If we're wrapping a view inside a Page purely to drive navigation,
1404
+ // hide the default ActionBar to avoid duplicate bars.
1405
+ try {
1406
+ page.actionBarHidden = true;
1407
+ }
1408
+ catch { }
1409
+ if (__NS_ENV_VERBOSE__)
1410
+ console.log('[hmr-client] [createRoot] wrapped nativeView in Page (root kind=page)');
1411
+ state.setRootKind('page');
1412
+ state.setCachedRoot(page);
1413
+ return state.getCachedRoot();
1414
+ }
1415
+ }
1416
+ // fallback page
1417
+ if (GPage) {
1418
+ if (__NS_ENV_VERBOSE__)
1419
+ console.log('[hmr-client] [createRoot] fallback empty Page');
1420
+ state.setRootKind('page');
1421
+ state.setCachedRoot(new GPage());
1422
+ return state.getCachedRoot();
1423
+ }
1424
+ state.setRootKind('page');
1425
+ state.setCachedRoot({});
1426
+ return state.getCachedRoot();
1427
+ }
1428
+ /** Install a robust $navigateBack wrapper once that falls back to remounting the
1429
+ * original root component if there's no usable Frame history. This keeps dev UX
1430
+ * predictable when testing deep links or isolated component mounts.
1431
+ */
1432
+ export function ensureBackWrapperInstalled(performResetRoot, getCore) {
1433
+ try {
1434
+ const g = globalThis;
1435
+ // Provide global back-remount hooks for bridges to call
1436
+ if (!g.__nsAttemptBackRemount) {
1437
+ g.__nsAttemptBackRemount = () => {
1438
+ try {
1439
+ const orig = g.__NS_HMR_ORIG_ROOT_COMPONENT__ || ORIG_ROOT_COMPONENT;
1440
+ if (orig) {
1441
+ performResetRoot(orig);
1442
+ return true;
1443
+ }
1444
+ }
1445
+ catch { }
1446
+ return false;
1447
+ };
1448
+ }
1449
+ if (!g.__NS_HMR_ON_NAVIGATE_BACK) {
1450
+ g.__NS_HMR_ON_NAVIGATE_BACK = () => {
1451
+ try {
1452
+ g.__nsAttemptBackRemount && g.__nsAttemptBackRemount();
1453
+ }
1454
+ catch { }
1455
+ };
1456
+ }
1457
+ if (g.__NS_HMR_BACK_WRAPPED__)
1458
+ return;
1459
+ const originalBack = g.$navigateBack;
1460
+ // Mark wrapped before assigning to avoid re-entrancy races
1461
+ g.__NS_HMR_BACK_WRAPPED__ = true;
1462
+ g.$navigateBack = (...args) => {
1463
+ try {
1464
+ const F = getCore('Frame');
1465
+ const top = F?.topmost?.();
1466
+ if (top && top.canGoBack?.()) {
1467
+ if (typeof originalBack === 'function')
1468
+ return originalBack(...args);
1469
+ // If originalBack is not a function, try Frame fallback
1470
+ try {
1471
+ return top.goBack?.();
1472
+ }
1473
+ catch { }
1474
+ return;
1475
+ }
1476
+ }
1477
+ catch (e) {
1478
+ // fall through to fallback
1479
+ }
1480
+ // Fallback: reset to original root component if available
1481
+ const orig = g.__NS_HMR_ORIG_ROOT_COMPONENT__ || ORIG_ROOT_COMPONENT;
1482
+ if (orig) {
1483
+ try {
1484
+ // Reuse the proven remount pipeline for consistency
1485
+ performResetRoot(orig);
1486
+ return;
1487
+ }
1488
+ catch (e) {
1489
+ console.warn('[hmr-client] Fallback back nav failed:', e);
1490
+ }
1491
+ }
1492
+ console.warn('[hmr-client] No usable Frame and no original root component available; cannot navigate back.');
1493
+ };
1494
+ }
1495
+ catch { }
1496
+ }
1497
+ async function requestModuleFromServer(name) {
1498
+ try {
1499
+ // Derive the dev-server origin (mirrors other resolver helpers in this file)
1500
+ const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
1501
+ if (!origin)
1502
+ return null;
1503
+ // Candidate URL patterns that a Vite-like server might expose for resolving modules to importable URLs.
1504
+ const candidates = [
1505
+ // Vite serves bare imports under /@modules/<name>
1506
+ `${origin.replace(/\/$/, '')}/@modules/${encodeURIComponent(name)}`,
1507
+ // Some setups use @id for resolved module ids
1508
+ `${origin.replace(/\/$/, '')}/@id/${encodeURIComponent(name)}`,
1509
+ // Custom-ish endpoint pattern used elsewhere in this project style
1510
+ `${origin.replace(/\/$/, '')}/ns/esmmod?name=${encodeURIComponent(name)}`,
1511
+ ];
1512
+ // Probe each candidate with a lightweight HEAD request first; if allowed, return the candidate URL.
1513
+ for (const url of candidates) {
1514
+ try {
1515
+ const res = await fetch(url, { method: 'HEAD' });
1516
+ if (res && (res.ok || res.status === 200))
1517
+ return url;
1518
+ }
1519
+ catch {
1520
+ // ignore and try next
1521
+ }
1522
+ }
1523
+ // As a final attempt, try GET on the first candidate and return if we get a module-like response.
1524
+ try {
1525
+ const url = candidates[0];
1526
+ const res = await fetch(url, { method: 'GET' });
1527
+ if (res && res.ok)
1528
+ return url;
1529
+ }
1530
+ catch { }
1531
+ return null;
1532
+ }
1533
+ catch {
1534
+ return null;
1535
+ }
1536
+ }
1537
+ //# sourceMappingURL=index.js.map