@nativescript/core 9.0.0-alpha.2 → 9.0.0-alpha.20

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 (225) hide show
  1. package/application/application-common.d.ts +1 -0
  2. package/application/application-common.js +45 -3
  3. package/application/application-common.js.map +1 -1
  4. package/application/application.android.js +12 -30
  5. package/application/application.android.js.map +1 -1
  6. package/application/application.ios.js +17 -1
  7. package/application/application.ios.js.map +1 -1
  8. package/application/helpers-common.d.ts +12 -2
  9. package/application/helpers-common.js +37 -3
  10. package/application/helpers-common.js.map +1 -1
  11. package/application/helpers.android.js.map +1 -1
  12. package/application-settings/index.android.js.map +1 -1
  13. package/connectivity/index.android.js.map +1 -1
  14. package/core-types/index.d.ts +2 -1
  15. package/core-types/index.js +1 -0
  16. package/core-types/index.js.map +1 -1
  17. package/css/css-tree-parser.js +2 -2
  18. package/css/css-tree-parser.js.map +1 -1
  19. package/debugger/webinspector-network.android.js.map +1 -1
  20. package/file-system/file-system-access.android.js +31 -31
  21. package/file-system/file-system-access.android.js.map +1 -1
  22. package/file-system/file-system-access.ios.js +3 -4
  23. package/file-system/file-system-access.ios.js.map +1 -1
  24. package/file-system/index.d.ts +2 -2
  25. package/file-system/index.js.map +1 -1
  26. package/fps-meter/fps-native.android.d.ts +1 -2
  27. package/fps-meter/fps-native.android.js.map +1 -1
  28. package/fps-meter/fps-native.ios.d.ts +1 -2
  29. package/fps-meter/fps-native.ios.js.map +1 -1
  30. package/global-types.d.ts +7 -8
  31. package/globals/global-utils.d.ts +27 -0
  32. package/globals/global-utils.js +67 -0
  33. package/globals/global-utils.js.map +1 -0
  34. package/globals/index.d.ts +3 -7
  35. package/globals/index.js +234 -271
  36. package/globals/index.js.map +1 -1
  37. package/http/http-request/index.d.ts +4 -0
  38. package/http/index.d.ts +5 -104
  39. package/http/index.js +1 -1
  40. package/http/index.js.map +1 -1
  41. package/image-asset/index.android.js +3 -3
  42. package/image-asset/index.android.js.map +1 -1
  43. package/index.d.ts +7 -6
  44. package/index.js +1 -0
  45. package/index.js.map +1 -1
  46. package/inspector_modules.d.ts +3 -0
  47. package/inspector_modules.js +142 -3
  48. package/inspector_modules.js.map +1 -1
  49. package/module-name-resolver/index.d.ts +13 -14
  50. package/module-name-resolver/index.js.map +1 -1
  51. package/module-name-resolver/qualifier-matcher/index.d.ts +6 -12
  52. package/module-name-resolver/qualifier-matcher/index.js +5 -5
  53. package/module-name-resolver/qualifier-matcher/index.js.map +1 -1
  54. package/package.json +12 -9
  55. package/platforms/android/widgets-release.aar +0 -0
  56. package/profiling/index.js +0 -4
  57. package/profiling/index.js.map +1 -1
  58. package/timer/index.android.js +15 -7
  59. package/timer/index.android.js.map +1 -1
  60. package/ui/action-bar/index.android.d.ts +0 -4
  61. package/ui/action-bar/index.android.js +1 -1
  62. package/ui/action-bar/index.android.js.map +1 -1
  63. package/ui/action-bar/index.ios.d.ts +1 -11
  64. package/ui/action-bar/index.ios.js +26 -0
  65. package/ui/action-bar/index.ios.js.map +1 -1
  66. package/ui/activity-indicator/index.android.d.ts +0 -3
  67. package/ui/activity-indicator/index.ios.d.ts +0 -3
  68. package/ui/animation/index.ios.js +38 -27
  69. package/ui/animation/index.ios.js.map +1 -1
  70. package/ui/builder/binding-builder.d.ts +12 -15
  71. package/ui/builder/component-builder/index.js +3 -3
  72. package/ui/builder/component-builder/index.js.map +1 -1
  73. package/ui/builder/index.d.ts +179 -59
  74. package/ui/builder/index.js +35 -7
  75. package/ui/builder/index.js.map +1 -1
  76. package/ui/button/index.android.d.ts +0 -6
  77. package/ui/button/index.android.js +2 -0
  78. package/ui/button/index.android.js.map +1 -1
  79. package/ui/button/index.ios.d.ts +0 -11
  80. package/ui/core/properties/index.d.ts +4 -3
  81. package/ui/core/properties/index.js +66 -52
  82. package/ui/core/properties/index.js.map +1 -1
  83. package/ui/core/view/index.android.d.ts +18 -45
  84. package/ui/core/view/index.android.js +489 -112
  85. package/ui/core/view/index.android.js.map +1 -1
  86. package/ui/core/view/index.d.ts +26 -0
  87. package/ui/core/view/index.ios.d.ts +8 -31
  88. package/ui/core/view/index.ios.js +74 -18
  89. package/ui/core/view/index.ios.js.map +1 -1
  90. package/ui/core/view/view-common.d.ts +15 -0
  91. package/ui/core/view/view-common.js +13 -0
  92. package/ui/core/view/view-common.js.map +1 -1
  93. package/ui/core/view/view-helper/index.ios.d.ts +1 -0
  94. package/ui/core/view/view-helper/index.ios.js +20 -0
  95. package/ui/core/view/view-helper/index.ios.js.map +1 -1
  96. package/ui/core/view/view-interfaces.d.ts +19 -0
  97. package/ui/core/view-base/index.d.ts +6 -2
  98. package/ui/core/view-base/index.js +1 -1
  99. package/ui/core/view-base/index.js.map +1 -1
  100. package/ui/date-picker/index.android.d.ts +0 -6
  101. package/ui/date-picker/index.ios.d.ts +0 -12
  102. package/ui/dialogs/index.android.js +8 -7
  103. package/ui/dialogs/index.android.js.map +1 -1
  104. package/ui/dialogs/index.ios.js +4 -2
  105. package/ui/dialogs/index.ios.js.map +1 -1
  106. package/ui/editable-text-base/editable-text-base-common.js +1 -1
  107. package/ui/editable-text-base/editable-text-base-common.js.map +1 -1
  108. package/ui/editable-text-base/index.android.d.ts +1 -12
  109. package/ui/editable-text-base/index.android.js +3 -0
  110. package/ui/editable-text-base/index.android.js.map +1 -1
  111. package/ui/editable-text-base/index.ios.d.ts +1 -6
  112. package/ui/editable-text-base/index.ios.js +3 -0
  113. package/ui/editable-text-base/index.ios.js.map +1 -1
  114. package/ui/embedding/index.android.d.ts +1 -1
  115. package/ui/embedding/index.d.ts +1 -1
  116. package/ui/frame/activity.android.js +3 -0
  117. package/ui/frame/activity.android.js.map +1 -1
  118. package/ui/frame/fragment.transitions.android.d.ts +3 -0
  119. package/ui/frame/fragment.transitions.android.js +53 -10
  120. package/ui/frame/fragment.transitions.android.js.map +1 -1
  121. package/ui/frame/fragment.transitions.d.ts +9 -1
  122. package/ui/frame/frame-common.d.ts +1 -1
  123. package/ui/frame/frame-common.js.map +1 -1
  124. package/ui/frame/frame-helper-for-android.js.map +1 -1
  125. package/ui/frame/frame-interfaces.d.ts +45 -9
  126. package/ui/frame/index.android.d.ts +13 -3
  127. package/ui/frame/index.android.js +63 -62
  128. package/ui/frame/index.android.js.map +1 -1
  129. package/ui/frame/index.d.ts +1 -41
  130. package/ui/frame/index.ios.d.ts +3 -2
  131. package/ui/frame/index.ios.js.map +1 -1
  132. package/ui/html-view/index.android.d.ts +0 -8
  133. package/ui/html-view/index.ios.d.ts +0 -5
  134. package/ui/image/index.android.d.ts +0 -4
  135. package/ui/image/index.ios.d.ts +2 -2
  136. package/ui/image/index.ios.js +0 -1
  137. package/ui/image/index.ios.js.map +1 -1
  138. package/ui/index.d.ts +9 -4
  139. package/ui/index.js +13 -4
  140. package/ui/index.js.map +1 -1
  141. package/ui/layouts/dock-layout/index.android.d.ts +0 -1
  142. package/ui/layouts/flexbox-layout/index.android.d.ts +0 -5
  143. package/ui/layouts/flexbox-layout/index.ios.js +25 -13
  144. package/ui/layouts/flexbox-layout/index.ios.js.map +1 -1
  145. package/ui/layouts/index.d.ts +3 -1
  146. package/ui/layouts/index.js.map +1 -1
  147. package/ui/layouts/layout-base.android.d.ts +0 -6
  148. package/ui/layouts/layout-base.ios.d.ts +0 -2
  149. package/ui/list-picker/index.android.d.ts +0 -3
  150. package/ui/list-picker/index.ios.d.ts +0 -3
  151. package/ui/list-view/index.android.d.ts +0 -5
  152. package/ui/list-view/index.ios.d.ts +0 -3
  153. package/ui/page/index.android.d.ts +0 -6
  154. package/ui/page/index.d.ts +0 -8
  155. package/ui/page/index.ios.d.ts +0 -2
  156. package/ui/page/index.ios.js +6 -1
  157. package/ui/page/index.ios.js.map +1 -1
  158. package/ui/page/page-common.d.ts +0 -2
  159. package/ui/page/page-common.js +0 -6
  160. package/ui/page/page-common.js.map +1 -1
  161. package/ui/progress/index.android.d.ts +0 -5
  162. package/ui/progress/index.ios.d.ts +0 -5
  163. package/ui/scroll-view/index.android.d.ts +0 -3
  164. package/ui/scroll-view/index.ios.d.ts +0 -2
  165. package/ui/search-bar/index.android.d.ts +2 -14
  166. package/ui/search-bar/index.android.js +0 -2
  167. package/ui/search-bar/index.android.js.map +1 -1
  168. package/ui/search-bar/index.ios.d.ts +1 -10
  169. package/ui/search-bar/index.ios.js +0 -2
  170. package/ui/search-bar/index.ios.js.map +1 -1
  171. package/ui/segmented-bar/index.android.d.ts +0 -9
  172. package/ui/segmented-bar/index.ios.d.ts +0 -5
  173. package/ui/slider/index.android.d.ts +0 -6
  174. package/ui/slider/index.ios.d.ts +0 -6
  175. package/ui/styling/background.android.js +1 -1
  176. package/ui/styling/background.android.js.map +1 -1
  177. package/ui/styling/css-stroke.js.map +1 -1
  178. package/ui/styling/font.android.js +2 -2
  179. package/ui/styling/font.android.js.map +1 -1
  180. package/ui/styling/style-scope.js +5 -13
  181. package/ui/styling/style-scope.js.map +1 -1
  182. package/ui/switch/index.android.d.ts +0 -5
  183. package/ui/switch/index.ios.d.ts +0 -6
  184. package/ui/switch/index.ios.js +0 -13
  185. package/ui/switch/index.ios.js.map +1 -1
  186. package/ui/tab-view/index.android.d.ts +0 -16
  187. package/ui/tab-view/index.android.js.map +1 -1
  188. package/ui/tab-view/index.ios.d.ts +0 -10
  189. package/ui/text-base/index.android.d.ts +5 -28
  190. package/ui/text-base/index.android.js +12 -16
  191. package/ui/text-base/index.android.js.map +1 -1
  192. package/ui/text-base/index.ios.d.ts +0 -16
  193. package/ui/text-field/index.android.js +3 -0
  194. package/ui/text-field/index.android.js.map +1 -1
  195. package/ui/text-field/index.ios.d.ts +0 -13
  196. package/ui/text-field/index.ios.js +1 -1
  197. package/ui/text-field/index.ios.js.map +1 -1
  198. package/ui/text-view/index.ios.d.ts +0 -15
  199. package/ui/time-picker/index.ios.d.ts +0 -9
  200. package/ui/transition/page-transition.android.d.ts +1 -1
  201. package/ui/transition/page-transition.android.js +19 -5
  202. package/ui/transition/page-transition.android.js.map +1 -1
  203. package/ui/web-view/web-view-common.d.ts +0 -1
  204. package/utils/common.js +1 -1
  205. package/utils/common.js.map +1 -1
  206. package/utils/constants.android.d.ts +1 -0
  207. package/utils/constants.android.js +3 -0
  208. package/utils/constants.android.js.map +1 -1
  209. package/utils/constants.d.ts +1 -0
  210. package/utils/constants.ios.d.ts +1 -0
  211. package/utils/constants.ios.js +3 -0
  212. package/utils/constants.ios.js.map +1 -1
  213. package/utils/debug-source.js +1 -1
  214. package/utils/debug-source.js.map +1 -1
  215. package/utils/index.android.js +7 -7
  216. package/utils/layout-helper/index.android.js +3 -3
  217. package/utils/native-helper-for-android.d.ts +11 -0
  218. package/utils/native-helper-for-android.js +100 -0
  219. package/utils/native-helper-for-android.js.map +1 -1
  220. package/utils/native-helper.android.d.ts +13 -1
  221. package/utils/native-helper.android.js +8 -1
  222. package/utils/native-helper.android.js.map +1 -1
  223. package/utils/native-helper.d.ts +137 -201
  224. package/utils/native-helper.ios.js +0 -3
  225. package/utils/native-helper.ios.js.map +1 -1
@@ -0,0 +1,67 @@
1
+ import { Observable } from '../data/observable';
2
+ import { trace as profilingTrace, time, uptime, level as profilingLevel } from '../profiling';
3
+ // console.log('here in globals/global-utils!');
4
+ /**
5
+ * Manages internal framework global state
6
+ */
7
+ export class NativeScriptGlobalState {
8
+ constructor() {
9
+ this.launched = false;
10
+ this._appInstanceReady = false;
11
+ // console.log('creating NativeScriptGlobals...')
12
+ this.events = new Observable();
13
+ this._setLaunched = this._setLaunchedFn.bind(this);
14
+ this.events.on('launch', this._setLaunched);
15
+ if (profilingLevel() > 0) {
16
+ this.events.on('displayed', () => {
17
+ const duration = uptime();
18
+ const end = time();
19
+ const start = end - duration;
20
+ profilingTrace(`Displayed in ${duration.toFixed(2)}ms`, start, end);
21
+ });
22
+ }
23
+ }
24
+ get appInstanceReady() {
25
+ return this._appInstanceReady;
26
+ }
27
+ set appInstanceReady(value) {
28
+ this._appInstanceReady = value;
29
+ // app instance ready, wire up any app events waiting in startup queue
30
+ if (this.appEventWiring && this.appEventWiring.length) {
31
+ for (const callback of this.appEventWiring) {
32
+ callback();
33
+ }
34
+ // cleanup
35
+ this.appEventWiring = null;
36
+ }
37
+ }
38
+ /**
39
+ * Ability for classes to initialize app event handling early even before the app instance is ready during boot cycle avoiding boot race conditions
40
+ * @param callback wire up any global event handling inside the callback
41
+ */
42
+ addEventWiring(callback) {
43
+ if (this._appInstanceReady) {
44
+ callback();
45
+ }
46
+ else {
47
+ if (!this.appEventWiring) {
48
+ this.appEventWiring = [];
49
+ }
50
+ this.appEventWiring.push(callback);
51
+ }
52
+ }
53
+ _setLaunchedFn() {
54
+ // console.log('NativeScriptGlobals launch fired!');
55
+ this.launched = true;
56
+ this.events.off('launch', this._setLaunched);
57
+ this._setLaunched = null;
58
+ }
59
+ }
60
+ export function getNativeScriptGlobals() {
61
+ if (!global.NativeScriptGlobals) {
62
+ // init global state handler
63
+ global.NativeScriptGlobals = new NativeScriptGlobalState();
64
+ }
65
+ return global.NativeScriptGlobals;
66
+ }
67
+ //# sourceMappingURL=global-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-utils.js","sourceRoot":"","sources":["../../../../packages/core/globals/global-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9F,gDAAgD;AAEhD;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAOnC;QALA,aAAQ,GAAG,KAAK,CAAC;QAGT,sBAAiB,GAAG,KAAK,CAAC;QAGjC,iDAAiD;QACjD,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,cAAc,EAAE,GAAG,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;gBAChC,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;gBAC1B,MAAM,GAAG,GAAG,IAAI,EAAE,CAAC;gBACnB,MAAM,KAAK,GAAG,GAAG,GAAG,QAAQ,CAAC;gBAC7B,cAAc,CAAC,gBAAgB,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YACrE,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,IAAI,gBAAgB;QACnB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAC/B,CAAC;IAED,IAAI,gBAAgB,CAAC,KAAc;QAClC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;QAC/B,sEAAsE;QACtE,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;YACvD,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;gBAC5C,QAAQ,EAAE,CAAC;YACZ,CAAC;YACD,UAAU;YACV,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC5B,CAAC;IACF,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,QAAoB;QAClC,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC5B,QAAQ,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;gBAC1B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC;IACF,CAAC;IAEO,cAAc;QACrB,oDAAoD;QACpD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC1B,CAAC;CACD;AACD,MAAM,UAAU,sBAAsB;IACrC,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;QACjC,4BAA4B;QAC5B,MAAM,CAAC,mBAAmB,GAAG,IAAI,uBAAuB,EAAE,CAAC;IAC5D,CAAC;IACD,OAAO,MAAM,CAAC,mBAAmB,CAAC;AACnC,CAAC"}
@@ -1,7 +1,3 @@
1
- import { Observable } from '../data/observable';
2
- export declare class NativeScriptGlobalState {
3
- events: Observable;
4
- launched: boolean;
5
- }
6
- export function installPolyfills(moduleName: string, exportNames: string[]): void;
7
- export function initGlobal(): void;
1
+ import '../fetch';
2
+ export declare function installPolyfills(moduleName: string, exportNames: string[]): void;
3
+ import '../application';
package/globals/index.js CHANGED
@@ -1,6 +1,4 @@
1
1
  import tslib from 'tslib';
2
- import { Observable } from '../data/observable';
3
- import { trace as profilingTrace, time, uptime, level as profilingLevel } from '../profiling';
4
2
  import * as timer from '../timer';
5
3
  import * as animationFrame from '../animation-frame';
6
4
  import * as mediaQueryList from '../media-query-list';
@@ -11,11 +9,11 @@ import * as fetchPolyfill from '../fetch';
11
9
  import * as wgc from '../wgc';
12
10
  import * as cryptoImpl from '../wgc/crypto';
13
11
  import * as subtleCryptoImpl from '../wgc/crypto/SubtleCrypto';
14
- console.log('here in globals/index!');
15
- console.log(`typeof __dirname:`, typeof __dirname);
16
- // commonjs builds will have __dirname defined, but es6 modules will not
12
+ // console.log('here in globals/index!');
13
+ // console.log(`typeof __dirname:`, typeof __dirname);
14
+ // commonjs builds will have __dirname defined, but esm builds will not
17
15
  global.__dirname = typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname;
18
- console.log('global.__dirname', global.__dirname);
16
+ // console.log('global.__dirname', global.__dirname);
19
17
  if (typeof global.__metadata === 'undefined') {
20
18
  /**
21
19
  * TS decorator metadata helper.
@@ -34,6 +32,195 @@ if (typeof global.__metadata === 'undefined') {
34
32
  // no-op if no Reflect.metadata
35
33
  };
36
34
  }
35
+ // ts-helpers
36
+ // Required by V8 snapshot generator
37
+ if (!global.__extends) {
38
+ global.__extends = function (d, b) {
39
+ for (const p in b) {
40
+ if (b.hasOwnProperty(p)) {
41
+ d[p] = b[p];
42
+ }
43
+ }
44
+ function __() {
45
+ this.constructor = d;
46
+ }
47
+ d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
48
+ };
49
+ }
50
+ // Bind the tslib helpers to global scope.
51
+ // This is needed when we don't use importHelpers, which
52
+ // breaks extending native-classes
53
+ for (const fnName of Object.getOwnPropertyNames(tslib)) {
54
+ if (typeof tslib[fnName] !== 'function') {
55
+ continue;
56
+ }
57
+ if (fnName in global) {
58
+ // Don't override globals that are already defined (ex. __extends)
59
+ continue;
60
+ }
61
+ global[fnName] = tslib[fnName];
62
+ }
63
+ // module helpers
64
+ const defaultExtensionMap = {
65
+ '.js': '.js',
66
+ '.ts': '.js',
67
+ '.kt': '.js',
68
+ '.css': '.css',
69
+ '.scss': '.css',
70
+ '.less': '.css',
71
+ '.sass': '.css',
72
+ '.xml': '.xml',
73
+ };
74
+ global.moduleResolvers = [global.require];
75
+ global.registerModule = function (name, loader) {
76
+ modules.set(name, { loader, moduleId: name });
77
+ };
78
+ global._unregisterModule = function _unregisterModule(name) {
79
+ modules.delete(name);
80
+ };
81
+ global.registerBundlerModules = function registerBundlerModules(context, extensionMap = {}) {
82
+ const registerWithName = (nickName, moduleId) => {
83
+ modules.set(nickName, {
84
+ moduleId,
85
+ loader: () => {
86
+ return context(moduleId);
87
+ },
88
+ });
89
+ };
90
+ const registerModuleById = (moduleId) => {
91
+ const extDotIndex = moduleId.lastIndexOf('.');
92
+ const base = moduleId.substring(0, extDotIndex);
93
+ const originalExt = moduleId.substring(extDotIndex);
94
+ const registerExt = extensionMap[originalExt] || defaultExtensionMap[originalExt] || originalExt;
95
+ // We prefer source files for webpack scenarios before compilation leftovers,
96
+ // e. g. if we get a .js and .ts for the same module, the .js is probably the compiled version of the .ts file,
97
+ // so we register the .ts with higher priority, similar is the case with us preferring the .scss to .css
98
+ const isSourceFile = originalExt !== registerExt;
99
+ const registerName = base + registerExt;
100
+ if (registerName.startsWith('./') && registerName.endsWith('.js')) {
101
+ const jsNickNames = [
102
+ // This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc);
103
+ registerName.substring(2, registerName.length - 3),
104
+ // This is for supporting module names like "./main/main-page"
105
+ registerName.substring(0, registerName.length - 3),
106
+ // This is for supporting module names like "main/main-page.js"
107
+ registerName.substring(2),
108
+ ];
109
+ jsNickNames.forEach((jsNickName) => {
110
+ if (isSourceFile || !global.moduleExists(jsNickName)) {
111
+ registerWithName(jsNickName, moduleId);
112
+ }
113
+ });
114
+ }
115
+ else if (registerName.startsWith('./')) {
116
+ const moduleNickNames = [
117
+ // This is for supporting module names like "main/main-page.xml"
118
+ registerName.substring(2),
119
+ ];
120
+ moduleNickNames.forEach((moduleNickName) => {
121
+ if (!global.moduleExists(moduleNickName)) {
122
+ registerWithName(moduleNickName, moduleId);
123
+ }
124
+ });
125
+ }
126
+ if (isSourceFile || !global.moduleExists(registerName)) {
127
+ registerWithName(registerName, moduleId);
128
+ }
129
+ };
130
+ context.keys().forEach(registerModuleById);
131
+ };
132
+ global.moduleExists = function moduleExists(name) {
133
+ return modules.has(name);
134
+ };
135
+ global.getRegisteredModules = function getRegisteredModules() {
136
+ return Array.from(modules.keys());
137
+ };
138
+ /**
139
+ * Polyfills
140
+ */
141
+ // This method iterates all the keys in the source exports object and copies them to the destination exports one.
142
+ // Note: the method will not check for naming collisions and will override any already existing entries in the destination exports.
143
+ global.moduleMerge = function (sourceExports, destExports) {
144
+ for (const key in sourceExports) {
145
+ destExports[key] = sourceExports[key];
146
+ }
147
+ };
148
+ global.zonedCallback = function (callback) {
149
+ if (global.zone) {
150
+ // Zone v0.5.* style callback wrapping
151
+ return global.zone.bind(callback);
152
+ }
153
+ if (global.Zone) {
154
+ // Zone v0.6.* style callback wrapping
155
+ return global.Zone.current.wrap(callback);
156
+ }
157
+ else {
158
+ return callback;
159
+ }
160
+ };
161
+ global.System = {
162
+ import(path) {
163
+ return new Promise((resolve, reject) => {
164
+ try {
165
+ resolve(global.require(path));
166
+ }
167
+ catch (e) {
168
+ reject(e);
169
+ }
170
+ });
171
+ },
172
+ };
173
+ // Custom decorators
174
+ global.Deprecated = function (target, key, descriptor) {
175
+ if (descriptor) {
176
+ const originalMethod = descriptor.value;
177
+ descriptor.value = function (...args) {
178
+ console.log(`${key.toString()} is deprecated`);
179
+ return originalMethod.apply(this, args);
180
+ };
181
+ return descriptor;
182
+ }
183
+ else {
184
+ console.log(`${(target && target.name) || target} is deprecated`);
185
+ return target;
186
+ }
187
+ };
188
+ global.Experimental = function (target, key, descriptor) {
189
+ if (descriptor) {
190
+ const originalMethod = descriptor.value;
191
+ descriptor.value = function (...args) {
192
+ console.log(`${key.toString()} is experimental`);
193
+ return originalMethod.apply(this, args);
194
+ };
195
+ return descriptor;
196
+ }
197
+ else {
198
+ console.log(`${(target && target.name) || target} is experimental`);
199
+ return target;
200
+ }
201
+ };
202
+ const modules = new Map();
203
+ // console.log(`globals/index, __COMMONJS__:`, __COMMONJS__);
204
+ global.loadModule = function loadModule(name) {
205
+ const moduleInfo = modules.get(name);
206
+ if (moduleInfo) {
207
+ const result = moduleInfo.loader(name);
208
+ if (result?.enableAutoAccept) {
209
+ result.enableAutoAccept();
210
+ }
211
+ return result;
212
+ }
213
+ if (__COMMONJS__) {
214
+ for (const resolver of global.moduleResolvers) {
215
+ const result = resolver(name);
216
+ if (result) {
217
+ modules.set(name, { moduleId: name, loader: () => result });
218
+ return result;
219
+ }
220
+ }
221
+ }
222
+ return null;
223
+ };
37
224
  function registerOnGlobalContext(moduleName, exportName) {
38
225
  Object.defineProperty(global, exportName, {
39
226
  get: function () {
@@ -51,62 +238,6 @@ function registerOnGlobalContext(moduleName, exportName) {
51
238
  configurable: true,
52
239
  });
53
240
  }
54
- /**
55
- * Manages internal framework global state
56
- */
57
- export class NativeScriptGlobalState {
58
- constructor() {
59
- this.launched = false;
60
- this._appInstanceReady = false;
61
- // console.log('creating NativeScriptGlobals...')
62
- this.events = new Observable();
63
- this._setLaunched = this._setLaunchedFn.bind(this);
64
- this.events.on('launch', this._setLaunched);
65
- if (profilingLevel() > 0) {
66
- this.events.on('displayed', () => {
67
- const duration = uptime();
68
- const end = time();
69
- const start = end - duration;
70
- profilingTrace(`Displayed in ${duration.toFixed(2)}ms`, start, end);
71
- });
72
- }
73
- }
74
- get appInstanceReady() {
75
- return this._appInstanceReady;
76
- }
77
- set appInstanceReady(value) {
78
- this._appInstanceReady = value;
79
- // app instance ready, wire up any app events waiting in startup queue
80
- if (this.appEventWiring && this.appEventWiring.length) {
81
- for (const callback of this.appEventWiring) {
82
- callback();
83
- }
84
- // cleanup
85
- this.appEventWiring = null;
86
- }
87
- }
88
- /**
89
- * Ability for classes to initialize app event handling early even before the app instance is ready during boot cycle avoiding boot race conditions
90
- * @param callback wire up any global event handling inside the callback
91
- */
92
- addEventWiring(callback) {
93
- if (this._appInstanceReady) {
94
- callback();
95
- }
96
- else {
97
- if (!this.appEventWiring) {
98
- this.appEventWiring = [];
99
- }
100
- this.appEventWiring.push(callback);
101
- }
102
- }
103
- _setLaunchedFn() {
104
- // console.log('NativeScriptGlobals launch fired!');
105
- this.launched = true;
106
- this.events.off('launch', this._setLaunched);
107
- this._setLaunched = null;
108
- }
109
- }
110
241
  export function installPolyfills(moduleName, exportNames) {
111
242
  if (global.__snapshot) {
112
243
  const loadedModule = global.loadModule(moduleName);
@@ -116,175 +247,12 @@ export function installPolyfills(moduleName, exportNames) {
116
247
  exportNames.forEach((exportName) => registerOnGlobalContext(moduleName, exportName));
117
248
  }
118
249
  }
119
- export function initGlobal() {
120
- if (!global.NativeScriptHasInitGlobal) {
121
- global.NativeScriptHasInitGlobal = true;
122
- // init global state handler
123
- global.NativeScriptGlobals = new NativeScriptGlobalState();
124
- // ts-helpers
125
- // Required by V8 snapshot generator
126
- if (!global.__extends) {
127
- global.__extends = function (d, b) {
128
- for (const p in b) {
129
- if (b.hasOwnProperty(p)) {
130
- d[p] = b[p];
131
- }
132
- }
133
- function __() {
134
- this.constructor = d;
135
- }
136
- d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
137
- };
138
- }
139
- // Bind the tslib helpers to global scope.
140
- // This is needed when we don't use importHelpers, which
141
- // breaks extending native-classes
142
- for (const fnName of Object.getOwnPropertyNames(tslib)) {
143
- if (typeof tslib[fnName] !== 'function') {
144
- continue;
145
- }
146
- if (fnName in global) {
147
- // Don't override globals that are already defined (ex. __extends)
148
- continue;
149
- }
150
- global[fnName] = tslib[fnName];
151
- }
152
- // module helpers
153
- const modules = new Map();
154
- const modulesLoadedForUI = new Set();
155
- const defaultExtensionMap = {
156
- '.js': '.js',
157
- '.ts': '.js',
158
- '.kt': '.js',
159
- '.css': '.css',
160
- '.scss': '.css',
161
- '.less': '.css',
162
- '.sass': '.css',
163
- '.xml': '.xml',
164
- };
165
- // Cast to <any> because moduleResolvers is read-only in definitions
166
- global.moduleResolvers = [global.require];
167
- global.registerModule = function (name, loader) {
168
- modules.set(name, { loader, moduleId: name });
169
- };
170
- global._unregisterModule = function _unregisterModule(name) {
171
- modules.delete(name);
172
- };
173
- global._isModuleLoadedForUI = function _isModuleLoadedForUI(moduleName) {
174
- return modulesLoadedForUI.has(moduleName);
175
- };
176
- global.registerWebpackModules = function registerWebpackModules(context, extensionMap = {}) {
177
- context.keys().forEach((moduleId) => {
178
- const extDotIndex = moduleId.lastIndexOf('.');
179
- const base = moduleId.substr(0, extDotIndex);
180
- const originalExt = moduleId.substr(extDotIndex);
181
- const registerExt = extensionMap[originalExt] || defaultExtensionMap[originalExt] || originalExt;
182
- // We prefer source files for webpack scenarios before compilation leftovers,
183
- // e. g. if we get a .js and .ts for the same module, the .js is probably the compiled version of the .ts file,
184
- // so we register the .ts with higher priority, similar is the case with us preferring the .scss to .css
185
- const isSourceFile = originalExt !== registerExt;
186
- const registerName = base + registerExt;
187
- const registerWithName = (nickName) => {
188
- modules.set(nickName, {
189
- moduleId,
190
- loader: () => {
191
- return context(moduleId);
192
- },
193
- });
194
- };
195
- if (registerName.startsWith('./') && registerName.endsWith('.js')) {
196
- const jsNickNames = [
197
- // This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc);
198
- registerName.substr(2, registerName.length - 5),
199
- // This is for supporting module names like "./main/main-page"
200
- registerName.substr(0, registerName.length - 3),
201
- // This is for supporting module names like "main/main-page.js"
202
- registerName.substr(2),
203
- ];
204
- jsNickNames.forEach((jsNickName) => {
205
- if (isSourceFile || !global.moduleExists(jsNickName)) {
206
- registerWithName(jsNickName);
207
- }
208
- });
209
- }
210
- else if (registerName.startsWith('./')) {
211
- const moduleNickNames = [
212
- // This is for supporting module names like "main/main-page.xml"
213
- registerName.substr(2),
214
- ];
215
- moduleNickNames.forEach((moduleNickName) => {
216
- if (!global.moduleExists(moduleNickName)) {
217
- registerWithName(moduleNickName);
218
- }
219
- });
220
- }
221
- if (isSourceFile || !global.moduleExists(registerName)) {
222
- registerWithName(registerName);
223
- }
224
- });
225
- };
226
- global.moduleExists = function moduleExists(name) {
227
- return modules.has(name);
228
- };
229
- global.loadModule = function loadModule(name, isUIModule = false) {
230
- const moduleInfo = modules.get(name);
231
- if (moduleInfo) {
232
- if (isUIModule) {
233
- modulesLoadedForUI.add(moduleInfo.moduleId);
234
- }
235
- const result = moduleInfo.loader(name);
236
- if (result.enableAutoAccept) {
237
- result.enableAutoAccept();
238
- }
239
- return result;
240
- }
241
- for (const resolver of global.moduleResolvers) {
242
- const result = resolver(name);
243
- if (result) {
244
- modules.set(name, { moduleId: name, loader: () => result });
245
- return result;
246
- }
247
- }
248
- };
249
- global.getRegisteredModules = function getRegisteredModules() {
250
- return Array.from(modules.keys());
251
- };
252
- /**
253
- * Polyfills
254
- */
255
- // This method iterates all the keys in the source exports object and copies them to the destination exports one.
256
- // Note: the method will not check for naming collisions and will override any already existing entries in the destination exports.
257
- global.moduleMerge = function (sourceExports, destExports) {
258
- for (const key in sourceExports) {
259
- destExports[key] = sourceExports[key];
260
- }
261
- };
262
- global.zonedCallback = function (callback) {
263
- if (global.zone) {
264
- // Zone v0.5.* style callback wrapping
265
- return global.zone.bind(callback);
266
- }
267
- if (global.Zone) {
268
- // Zone v0.6.* style callback wrapping
269
- return global.Zone.current.wrap(callback);
270
- }
271
- else {
272
- return callback;
273
- }
274
- };
275
- global.System = {
276
- import(path) {
277
- return new Promise((resolve, reject) => {
278
- try {
279
- resolve(global.require(path));
280
- }
281
- catch (e) {
282
- reject(e);
283
- }
284
- });
285
- },
286
- };
287
- // DOM api polyfills
250
+ if (!global.NativeScriptHasPolyfilled) {
251
+ global.NativeScriptHasPolyfilled = true;
252
+ // console.log('Installing polyfills...');
253
+ // DOM api polyfills
254
+ const glb = global;
255
+ if (__COMMONJS__) {
288
256
  global.registerModule('timer', () => timer);
289
257
  installPolyfills('timer', ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval']);
290
258
  global.registerModule('animation', () => animationFrame);
@@ -303,47 +271,42 @@ export function initGlobal() {
303
271
  installPolyfills('crypto', ['Crypto']);
304
272
  global.registerModule('subtle', () => subtleCryptoImpl);
305
273
  installPolyfills('subtle-crypto', ['Subtle']);
306
- global.crypto = new global.Crypto();
307
- // global.registerModule('abortcontroller', () => require('../abortcontroller'));
308
- // installPolyfills('abortcontroller', ['AbortController', 'AbortSignal']);
309
- // Custom decorators
310
- global.Deprecated = function (target, key, descriptor) {
311
- if (descriptor) {
312
- const originalMethod = descriptor.value;
313
- descriptor.value = function (...args) {
314
- console.log(`${key.toString()} is deprecated`);
315
- return originalMethod.apply(this, args);
316
- };
317
- return descriptor;
318
- }
319
- else {
320
- console.log(`${(target && target.name) || target} is deprecated`);
321
- return target;
322
- }
323
- };
324
- global.Experimental = function (target, key, descriptor) {
325
- if (descriptor) {
326
- const originalMethod = descriptor.value;
327
- descriptor.value = function (...args) {
328
- console.log(`${key.toString()} is experimental`);
329
- return originalMethod.apply(this, args);
330
- };
331
- return descriptor;
332
- }
333
- else {
334
- console.log(`${(target && target.name) || target} is experimental`);
335
- return target;
336
- }
337
- };
338
274
  }
339
- }
340
- function isTestingEnv() {
341
- return typeof jest !== 'undefined' || global.__UNIT_TEST__;
342
- }
343
- console.log('global.NativeScriptHasInitGlobal:', global.NativeScriptHasInitGlobal);
344
- console.log('isTestingEnv():', isTestingEnv());
345
- if (!global.NativeScriptHasInitGlobal && !isTestingEnv()) {
346
- initGlobal();
275
+ else {
276
+ // timers
277
+ glb.setTimeout = timer.setTimeout;
278
+ glb.clearTimeout = timer.clearTimeout;
279
+ glb.setInterval = timer.setInterval;
280
+ glb.clearInterval = timer.clearInterval;
281
+ // animation frame
282
+ glb.requestAnimationFrame = animationFrame.requestAnimationFrame;
283
+ glb.cancelAnimationFrame = animationFrame.cancelAnimationFrame;
284
+ // media query list
285
+ glb.matchMedia = mediaQueryList.matchMedia;
286
+ glb.MediaQueryList = mediaQueryList.MediaQueryList;
287
+ // text
288
+ glb.TextDecoder = text.TextDecoder;
289
+ glb.TextEncoder = text.TextEncoder;
290
+ // xhr
291
+ glb.XMLHttpRequest = xhrImpl.XMLHttpRequest;
292
+ glb.FormData = xhrImpl.FormData;
293
+ glb.Blob = xhrImpl.Blob;
294
+ glb.File = xhrImpl.File;
295
+ glb.FileReader = xhrImpl.FileReader;
296
+ // fetch
297
+ glb.fetch = fetchPolyfill.fetch;
298
+ glb.Headers = fetchPolyfill.Headers;
299
+ glb.Request = fetchPolyfill.Request;
300
+ glb.Response = fetchPolyfill.Response;
301
+ // wgc
302
+ glb.atob = wgc.atob;
303
+ glb.btoa = wgc.btoa;
304
+ // wgc
305
+ glb.SubtleCrypto = subtleCryptoImpl.SubtleCrypto;
306
+ }
307
+ glb.crypto = new cryptoImpl.Crypto();
308
+ // global.registerModule('abortcontroller', () => require('../abortcontroller'));
309
+ // installPolyfills('abortcontroller', ['AbortController', 'AbortSignal']);
347
310
  }
348
311
  // ensure the Application instance is initialized before any other module imports it.
349
312
  import '../application';