1 | 'use strict';
|
2 |
|
3 | const index = require('./index-a0a08b2a.js');
|
4 |
|
5 | const getPlatforms = (win) => setupPlatforms(win);
|
6 | const isPlatform = (winOrPlatform, platform) => {
|
7 | if (typeof winOrPlatform === 'string') {
|
8 | platform = winOrPlatform;
|
9 | winOrPlatform = undefined;
|
10 | }
|
11 | return getPlatforms(winOrPlatform).includes(platform);
|
12 | };
|
13 | const setupPlatforms = (win = window) => {
|
14 | if (typeof win === 'undefined') {
|
15 | return [];
|
16 | }
|
17 | win.Ionic = win.Ionic || {};
|
18 | let platforms = win.Ionic.platforms;
|
19 | if (platforms == null) {
|
20 | platforms = win.Ionic.platforms = detectPlatforms(win);
|
21 | platforms.forEach(p => win.document.documentElement.classList.add(`plt-${p}`));
|
22 | }
|
23 | return platforms;
|
24 | };
|
25 | const detectPlatforms = (win) => Object.keys(PLATFORMS_MAP).filter(p => PLATFORMS_MAP[p](win));
|
26 | const isMobileWeb = (win) => isMobile(win) && !isHybrid(win);
|
27 | const isIpad = (win) => {
|
28 |
|
29 | if (testUserAgent(win, /iPad/i)) {
|
30 | return true;
|
31 | }
|
32 |
|
33 | if (testUserAgent(win, /Macintosh/i) && isMobile(win)) {
|
34 | return true;
|
35 | }
|
36 | return false;
|
37 | };
|
38 | const isIphone = (win) => testUserAgent(win, /iPhone/i);
|
39 | const isIOS = (win) => testUserAgent(win, /iPhone|iPod/i) || isIpad(win);
|
40 | const isAndroid = (win) => testUserAgent(win, /android|sink/i);
|
41 | const isAndroidTablet = (win) => {
|
42 | return isAndroid(win) && !testUserAgent(win, /mobile/i);
|
43 | };
|
44 | const isPhablet = (win) => {
|
45 | const width = win.innerWidth;
|
46 | const height = win.innerHeight;
|
47 | const smallest = Math.min(width, height);
|
48 | const largest = Math.max(width, height);
|
49 | return (smallest > 390 && smallest < 520) &&
|
50 | (largest > 620 && largest < 800);
|
51 | };
|
52 | const isTablet = (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 (isIpad(win) ||
|
58 | isAndroidTablet(win) ||
|
59 | ((smallest > 460 && smallest < 820) &&
|
60 | (largest > 780 && largest < 1400)));
|
61 | };
|
62 | const isMobile = (win) => matchMedia(win, '(any-pointer:coarse)');
|
63 | const isDesktop = (win) => !isMobile(win);
|
64 | const isHybrid = (win) => isCordova(win) || isCapacitorNative(win);
|
65 | const isCordova = (win) => !!(win['cordova'] || win['phonegap'] || win['PhoneGap']);
|
66 | const isCapacitorNative = (win) => {
|
67 | const capacitor = win['Capacitor'];
|
68 | return !!(capacitor && capacitor.isNative);
|
69 | };
|
70 | const isElectron = (win) => testUserAgent(win, /electron/i);
|
71 | const isPWA = (win) => !!(win.matchMedia('(display-mode: standalone)').matches || win.navigator.standalone);
|
72 | const testUserAgent = (win, expr) => expr.test(win.navigator.userAgent);
|
73 | const matchMedia = (win, query) => win.matchMedia(query).matches;
|
74 | const PLATFORMS_MAP = {
|
75 | 'ipad': isIpad,
|
76 | 'iphone': isIphone,
|
77 | 'ios': isIOS,
|
78 | 'android': isAndroid,
|
79 | 'phablet': isPhablet,
|
80 | 'tablet': isTablet,
|
81 | 'cordova': isCordova,
|
82 | 'capacitor': isCapacitorNative,
|
83 | 'electron': isElectron,
|
84 | 'pwa': isPWA,
|
85 | 'mobile': isMobile,
|
86 | 'mobileweb': isMobileWeb,
|
87 | 'desktop': isDesktop,
|
88 | 'hybrid': isHybrid
|
89 | };
|
90 |
|
91 | class Config {
|
92 | constructor() {
|
93 | this.m = new Map();
|
94 | }
|
95 | reset(configObj) {
|
96 | this.m = new Map(Object.entries(configObj));
|
97 | }
|
98 | get(key, fallback) {
|
99 | const value = this.m.get(key);
|
100 | return value !== undefined ? value : fallback;
|
101 | }
|
102 | getBoolean(key, fallback = false) {
|
103 | const val = this.m.get(key);
|
104 | if (val === undefined) {
|
105 | return fallback;
|
106 | }
|
107 | if (typeof val === 'string') {
|
108 | return val === 'true';
|
109 | }
|
110 | return !!val;
|
111 | }
|
112 | getNumber(key, fallback) {
|
113 | const val = parseFloat(this.m.get(key));
|
114 | return isNaN(val) ? (fallback !== undefined ? fallback : NaN) : val;
|
115 | }
|
116 | set(key, value) {
|
117 | this.m.set(key, value);
|
118 | }
|
119 | }
|
120 | const config = new Config();
|
121 | const configFromSession = (win) => {
|
122 | try {
|
123 | const configStr = win.sessionStorage.getItem(IONIC_SESSION_KEY);
|
124 | return configStr !== null ? JSON.parse(configStr) : {};
|
125 | }
|
126 | catch (e) {
|
127 | return {};
|
128 | }
|
129 | };
|
130 | const saveConfig = (win, c) => {
|
131 | try {
|
132 | win.sessionStorage.setItem(IONIC_SESSION_KEY, JSON.stringify(c));
|
133 | }
|
134 | catch (e) {
|
135 | return;
|
136 | }
|
137 | };
|
138 | const configFromURL = (win) => {
|
139 | const configObj = {};
|
140 | win.location.search
|
141 | .slice(1)
|
142 | .split('&')
|
143 | .map(entry => entry.split('='))
|
144 | .map(([key, value]) => [decodeURIComponent(key), decodeURIComponent(value)])
|
145 | .filter(([key]) => startsWith(key, IONIC_PREFIX))
|
146 | .map(([key, value]) => [key.slice(IONIC_PREFIX.length), value])
|
147 | .forEach(([key, value]) => {
|
148 | configObj[key] = value;
|
149 | });
|
150 | return configObj;
|
151 | };
|
152 | const startsWith = (input, search) => {
|
153 | return input.substr(0, search.length) === search;
|
154 | };
|
155 | const IONIC_PREFIX = 'ionic:';
|
156 | const IONIC_SESSION_KEY = 'ionic-persist-config';
|
157 |
|
158 | let defaultMode;
|
159 | const getIonMode = (ref) => {
|
160 | return (ref && index.getMode(ref)) || defaultMode;
|
161 | };
|
162 | const initialize = (userConfig = {}) => {
|
163 | if (typeof window === 'undefined') {
|
164 | return;
|
165 | }
|
166 | const doc = window.document;
|
167 | const win = window;
|
168 | const Ionic = win.Ionic = win.Ionic || {};
|
169 |
|
170 | setupPlatforms(win);
|
171 |
|
172 |
|
173 | const configObj = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, configFromSession(win)), { persistConfig: false }), Ionic.config), configFromURL(win)), userConfig);
|
174 | config.reset(configObj);
|
175 | if (config.getBoolean('persistConfig')) {
|
176 | saveConfig(win, configObj);
|
177 | }
|
178 |
|
179 |
|
180 |
|
181 | Ionic.config = config;
|
182 | Ionic.mode = defaultMode = config.get('mode', (doc.documentElement.getAttribute('mode')) || (isPlatform(win, 'ios') ? 'ios' : 'md'));
|
183 | config.set('mode', defaultMode);
|
184 | doc.documentElement.setAttribute('mode', defaultMode);
|
185 | doc.documentElement.classList.add(defaultMode);
|
186 | if (config.getBoolean('_testing')) {
|
187 | config.set('animated', false);
|
188 | }
|
189 | const isIonicElement = (elm) => elm.tagName && elm.tagName.startsWith('ION-');
|
190 | const isAllowedIonicModeValue = (elmMode) => ['ios', 'md'].includes(elmMode);
|
191 | index.setMode((elm) => {
|
192 | while (elm) {
|
193 | const elmMode = elm.mode || elm.getAttribute('mode');
|
194 | if (elmMode) {
|
195 | if (isAllowedIonicModeValue(elmMode)) {
|
196 | return elmMode;
|
197 | }
|
198 | else if (isIonicElement(elm)) {
|
199 | console.warn('Invalid ionic mode: "' + elmMode + '", expected: "ios" or "md"');
|
200 | }
|
201 | }
|
202 | elm = elm.parentElement;
|
203 | }
|
204 | return defaultMode;
|
205 | });
|
206 | };
|
207 |
|
208 | exports.config = config;
|
209 | exports.getIonMode = getIonMode;
|
210 | exports.getPlatforms = getPlatforms;
|
211 | exports.initialize = initialize;
|
212 | exports.isPlatform = isPlatform;
|