ionic-global-6dea5a96.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. 'use strict';
  5. const index$1 = require('./index-2e236a04.js');
  6. const index = require('./index-cc858e97.js');
  7. const getPlatforms = (win) => setupPlatforms(win);
  8. const isPlatform = (winOrPlatform, platform) => {
  9. if (typeof winOrPlatform === 'string') {
  10. platform = winOrPlatform;
  11. winOrPlatform = undefined;
  12. }
  13. return getPlatforms(winOrPlatform).includes(platform);
  14. };
  15. const setupPlatforms = (win = window) => {
  16. if (typeof win === 'undefined') {
  17. return [];
  18. }
  19. win.Ionic = win.Ionic || {};
  20. let platforms = win.Ionic.platforms;
  21. if (platforms == null) {
  22. platforms = win.Ionic.platforms = detectPlatforms(win);
  23. platforms.forEach((p) => win.document.documentElement.classList.add(`plt-${p}`));
  24. }
  25. return platforms;
  26. };
  27. const detectPlatforms = (win) => {
  28. const customPlatformMethods = index.config.get('platform');
  29. return Object.keys(PLATFORMS_MAP).filter((p) => {
  30. const customMethod = customPlatformMethods === null || customPlatformMethods === void 0 ? void 0 : customPlatformMethods[p];
  31. return typeof customMethod === 'function' ? customMethod(win) : PLATFORMS_MAP[p](win);
  32. });
  33. };
  34. const isMobileWeb = (win) => isMobile(win) && !isHybrid(win);
  35. const isIpad = (win) => {
  36. // iOS 12 and below
  37. if (testUserAgent(win, /iPad/i)) {
  38. return true;
  39. }
  40. // iOS 13+
  41. if (testUserAgent(win, /Macintosh/i) && isMobile(win)) {
  42. return true;
  43. }
  44. return false;
  45. };
  46. const isIphone = (win) => testUserAgent(win, /iPhone/i);
  47. const isIOS = (win) => testUserAgent(win, /iPhone|iPod/i) || isIpad(win);
  48. const isAndroid = (win) => testUserAgent(win, /android|sink/i);
  49. const isAndroidTablet = (win) => {
  50. return isAndroid(win) && !testUserAgent(win, /mobile/i);
  51. };
  52. const isPhablet = (win) => {
  53. const width = win.innerWidth;
  54. const height = win.innerHeight;
  55. const smallest = Math.min(width, height);
  56. const largest = Math.max(width, height);
  57. return smallest > 390 && smallest < 520 && largest > 620 && largest < 800;
  58. };
  59. const isTablet = (win) => {
  60. const width = win.innerWidth;
  61. const height = win.innerHeight;
  62. const smallest = Math.min(width, height);
  63. const largest = Math.max(width, height);
  64. return isIpad(win) || isAndroidTablet(win) || (smallest > 460 && smallest < 820 && largest > 780 && largest < 1400);
  65. };
  66. const isMobile = (win) => matchMedia(win, '(any-pointer:coarse)');
  67. const isDesktop = (win) => !isMobile(win);
  68. const isHybrid = (win) => isCordova(win) || isCapacitorNative(win);
  69. const isCordova = (win) => !!(win['cordova'] || win['phonegap'] || win['PhoneGap']);
  70. const isCapacitorNative = (win) => {
  71. const capacitor = win['Capacitor'];
  72. // TODO(ROU-11693): Remove when we no longer support Capacitor 2, which does not have isNativePlatform
  73. return !!((capacitor === null || capacitor === void 0 ? void 0 : capacitor.isNative) || ((capacitor === null || capacitor === void 0 ? void 0 : capacitor.isNativePlatform) && !!capacitor.isNativePlatform()));
  74. };
  75. const isElectron = (win) => testUserAgent(win, /electron/i);
  76. const isPWA = (win) => { var _a; return !!(((_a = win.matchMedia) === null || _a === void 0 ? void 0 : _a.call(win, '(display-mode: standalone)').matches) || win.navigator.standalone); };
  77. const testUserAgent = (win, expr) => expr.test(win.navigator.userAgent);
  78. const matchMedia = (win, query) => { var _a; return (_a = win.matchMedia) === null || _a === void 0 ? void 0 : _a.call(win, query).matches; };
  79. const PLATFORMS_MAP = {
  80. ipad: isIpad,
  81. iphone: isIphone,
  82. ios: isIOS,
  83. android: isAndroid,
  84. phablet: isPhablet,
  85. tablet: isTablet,
  86. cordova: isCordova,
  87. capacitor: isCapacitorNative,
  88. electron: isElectron,
  89. pwa: isPWA,
  90. mobile: isMobile,
  91. mobileweb: isMobileWeb,
  92. desktop: isDesktop,
  93. hybrid: isHybrid,
  94. };
  95. // TODO(FW-2832): types
  96. let defaultMode;
  97. const getIonMode = (ref) => {
  98. return (ref && index$1.getMode(ref)) || defaultMode;
  99. };
  100. const initialize = (userConfig = {}) => {
  101. if (typeof window === 'undefined') {
  102. return;
  103. }
  104. const doc = window.document;
  105. const win = window;
  106. const Ionic = (win.Ionic = win.Ionic || {});
  107. // create the Ionic.config from raw config object (if it exists)
  108. // and convert Ionic.config into a ConfigApi that has a get() fn
  109. const configObj = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, index.configFromSession(win)), { persistConfig: false }), Ionic.config), index.configFromURL(win)), userConfig);
  110. index.config.reset(configObj);
  111. if (index.config.getBoolean('persistConfig')) {
  112. index.saveConfig(win, configObj);
  113. }
  114. // Setup platforms
  115. setupPlatforms(win);
  116. // first see if the mode was set as an attribute on <html>
  117. // which could have been set by the user, or by pre-rendering
  118. // otherwise get the mode via config settings, and fallback to md
  119. Ionic.config = index.config;
  120. Ionic.mode = defaultMode = index.config.get('mode', doc.documentElement.getAttribute('mode') || (isPlatform(win, 'ios') ? 'ios' : 'md'));
  121. index.config.set('mode', defaultMode);
  122. doc.documentElement.setAttribute('mode', defaultMode);
  123. doc.documentElement.classList.add(defaultMode);
  124. if (index.config.getBoolean('_testing')) {
  125. index.config.set('animated', false);
  126. }
  127. const isIonicElement = (elm) => { var _a; return (_a = elm.tagName) === null || _a === void 0 ? void 0 : _a.startsWith('ION-'); };
  128. const isAllowedIonicModeValue = (elmMode) => ['ios', 'md'].includes(elmMode);
  129. index$1.setMode((elm) => {
  130. while (elm) {
  131. const elmMode = elm.mode || elm.getAttribute('mode');
  132. if (elmMode) {
  133. if (isAllowedIonicModeValue(elmMode)) {
  134. return elmMode;
  135. }
  136. else if (isIonicElement(elm)) {
  137. index.printIonWarning('Invalid ionic mode: "' + elmMode + '", expected: "ios" or "md"');
  138. }
  139. }
  140. elm = elm.parentElement;
  141. }
  142. return defaultMode;
  143. });
  144. };
  145. exports.getIonMode = getIonMode;
  146. exports.getPlatforms = getPlatforms;
  147. exports.initialize = initialize;
  148. exports.isPlatform = isPlatform;