@capacitor/core 6.2.0 → 7.0.0-alpha.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.
- package/cordova.js +33 -163
- package/dist/capacitor.js +1 -1
- package/dist/capacitor.js.map +1 -1
- package/dist/index.cjs.js +21 -91
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +22 -90
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/types/definitions.d.ts +0 -20
- package/types/global.d.ts +0 -19
- package/types/index.d.ts +2 -4
- package/types/web-plugin.d.ts +0 -18
- package/types/legacy/legacy-definitions.d.ts +0 -37
- package/types/legacy/legacy-web-plugin-merge.d.ts +0 -3
package/cordova.js
CHANGED
|
@@ -41,10 +41,7 @@
|
|
|
41
41
|
var resultantId = id;
|
|
42
42
|
// Its a relative path, so lop off the last portion and add the id (minus "./")
|
|
43
43
|
if (id.charAt(0) === '.') {
|
|
44
|
-
resultantId =
|
|
45
|
-
module.id.slice(0, module.id.lastIndexOf(SEPARATOR)) +
|
|
46
|
-
SEPARATOR +
|
|
47
|
-
id.slice(2);
|
|
44
|
+
resultantId = module.id.slice(0, module.id.lastIndexOf(SEPARATOR)) + SEPARATOR + id.slice(2);
|
|
48
45
|
}
|
|
49
46
|
return require(resultantId);
|
|
50
47
|
};
|
|
@@ -58,8 +55,7 @@
|
|
|
58
55
|
if (!modules[id]) {
|
|
59
56
|
throw 'module ' + id + ' not found';
|
|
60
57
|
} else if (id in inProgressModules) {
|
|
61
|
-
var cycle =
|
|
62
|
-
requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
|
|
58
|
+
var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
|
|
63
59
|
throw 'Cycle in require graph: ' + cycle;
|
|
64
60
|
}
|
|
65
61
|
if (modules[id].factory) {
|
|
@@ -259,13 +255,7 @@
|
|
|
259
255
|
* Called by native code when returning successful result from an action.
|
|
260
256
|
*/
|
|
261
257
|
callbackSuccess: function (callbackId, args) {
|
|
262
|
-
cordova.callbackFromNative(
|
|
263
|
-
callbackId,
|
|
264
|
-
true,
|
|
265
|
-
args.status,
|
|
266
|
-
[args.message],
|
|
267
|
-
args.keepCallback,
|
|
268
|
-
);
|
|
258
|
+
cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
|
|
269
259
|
},
|
|
270
260
|
|
|
271
261
|
/**
|
|
@@ -274,25 +264,13 @@
|
|
|
274
264
|
callbackError: function (callbackId, args) {
|
|
275
265
|
// TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
|
|
276
266
|
// Derive success from status.
|
|
277
|
-
cordova.callbackFromNative(
|
|
278
|
-
callbackId,
|
|
279
|
-
false,
|
|
280
|
-
args.status,
|
|
281
|
-
[args.message],
|
|
282
|
-
args.keepCallback,
|
|
283
|
-
);
|
|
267
|
+
cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
|
|
284
268
|
},
|
|
285
269
|
|
|
286
270
|
/**
|
|
287
271
|
* Called by native code when returning the result from an action.
|
|
288
272
|
*/
|
|
289
|
-
callbackFromNative: function (
|
|
290
|
-
callbackId,
|
|
291
|
-
isSuccess,
|
|
292
|
-
status,
|
|
293
|
-
args,
|
|
294
|
-
keepCallback,
|
|
295
|
-
) {
|
|
273
|
+
callbackFromNative: function (callbackId, isSuccess, status, args, keepCallback) {
|
|
296
274
|
try {
|
|
297
275
|
var callback = cordova.callbacks[callbackId];
|
|
298
276
|
if (callback) {
|
|
@@ -314,13 +292,7 @@
|
|
|
314
292
|
}
|
|
315
293
|
}
|
|
316
294
|
} catch (err) {
|
|
317
|
-
var msg =
|
|
318
|
-
'Error in ' +
|
|
319
|
-
(isSuccess ? 'Success' : 'Error') +
|
|
320
|
-
' callbackId: ' +
|
|
321
|
-
callbackId +
|
|
322
|
-
' : ' +
|
|
323
|
-
err;
|
|
295
|
+
var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err;
|
|
324
296
|
console && console.log && console.log(msg);
|
|
325
297
|
cordova.fireWindowEvent('cordovacallbackerror', { message: msg });
|
|
326
298
|
throw err;
|
|
@@ -418,10 +390,7 @@
|
|
|
418
390
|
};
|
|
419
391
|
|
|
420
392
|
base64.toArrayBuffer = function (str) {
|
|
421
|
-
var decodedStr =
|
|
422
|
-
typeof atob !== 'undefined'
|
|
423
|
-
? atob(str)
|
|
424
|
-
: Buffer.from(str, 'base64').toString('binary'); // eslint-disable-line no-undef
|
|
393
|
+
var decodedStr = typeof atob !== 'undefined' ? atob(str) : Buffer.from(str, 'base64').toString('binary'); // eslint-disable-line no-undef
|
|
425
394
|
var arrayBuffer = new ArrayBuffer(decodedStr.length);
|
|
426
395
|
var array = new Uint8Array(arrayBuffer);
|
|
427
396
|
for (var i = 0, len = decodedStr.length; i < len; i++) {
|
|
@@ -437,8 +406,7 @@
|
|
|
437
406
|
* platforms tested.
|
|
438
407
|
*/
|
|
439
408
|
|
|
440
|
-
var b64_6bit =
|
|
441
|
-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
409
|
+
var b64_6bit = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
442
410
|
var b64_12bit;
|
|
443
411
|
|
|
444
412
|
var b64_12bitTable = function () {
|
|
@@ -527,35 +495,20 @@
|
|
|
527
495
|
if (clobber) {
|
|
528
496
|
// Clobber if it doesn't exist.
|
|
529
497
|
if (typeof parent[key] === 'undefined') {
|
|
530
|
-
assignOrWrapInDeprecateGetter(
|
|
531
|
-
parent,
|
|
532
|
-
key,
|
|
533
|
-
result,
|
|
534
|
-
obj.deprecated,
|
|
535
|
-
);
|
|
498
|
+
assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
|
|
536
499
|
} else if (typeof obj.path !== 'undefined') {
|
|
537
500
|
// If merging, merge properties onto parent, otherwise, clobber.
|
|
538
501
|
if (merge) {
|
|
539
502
|
recursiveMerge(parent[key], result);
|
|
540
503
|
} else {
|
|
541
|
-
assignOrWrapInDeprecateGetter(
|
|
542
|
-
parent,
|
|
543
|
-
key,
|
|
544
|
-
result,
|
|
545
|
-
obj.deprecated,
|
|
546
|
-
);
|
|
504
|
+
assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
|
|
547
505
|
}
|
|
548
506
|
}
|
|
549
507
|
result = parent[key];
|
|
550
508
|
} else {
|
|
551
509
|
// Overwrite if not currently defined.
|
|
552
510
|
if (typeof parent[key] === 'undefined') {
|
|
553
|
-
assignOrWrapInDeprecateGetter(
|
|
554
|
-
parent,
|
|
555
|
-
key,
|
|
556
|
-
result,
|
|
557
|
-
obj.deprecated,
|
|
558
|
-
);
|
|
511
|
+
assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
|
|
559
512
|
} else {
|
|
560
513
|
// Set result to what already exists, so we can build children into it if they exist.
|
|
561
514
|
result = parent[key];
|
|
@@ -566,13 +519,7 @@
|
|
|
566
519
|
include(result, obj.children, clobber, merge);
|
|
567
520
|
}
|
|
568
521
|
} catch (e) {
|
|
569
|
-
utils.alert(
|
|
570
|
-
'Exception building Cordova JS globals: ' +
|
|
571
|
-
e +
|
|
572
|
-
' for key "' +
|
|
573
|
-
key +
|
|
574
|
-
'"',
|
|
575
|
-
);
|
|
522
|
+
utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"');
|
|
576
523
|
}
|
|
577
524
|
});
|
|
578
525
|
}
|
|
@@ -591,10 +538,7 @@
|
|
|
591
538
|
// If the target object is a constructor override off prototype.
|
|
592
539
|
clobber(target.prototype, prop, src[prop]);
|
|
593
540
|
} else {
|
|
594
|
-
if (
|
|
595
|
-
typeof src[prop] === 'object' &&
|
|
596
|
-
typeof target[prop] === 'object'
|
|
597
|
-
) {
|
|
541
|
+
if (typeof src[prop] === 'object' && typeof target[prop] === 'object') {
|
|
598
542
|
recursiveMerge(target[prop], src[prop]);
|
|
599
543
|
} else {
|
|
600
544
|
clobber(target, prop, src[prop]);
|
|
@@ -737,13 +681,9 @@
|
|
|
737
681
|
};
|
|
738
682
|
|
|
739
683
|
function checkSubscriptionArgument(argument) {
|
|
740
|
-
if (
|
|
741
|
-
typeof argument !== 'function' &&
|
|
742
|
-
typeof argument.handleEvent !== 'function'
|
|
743
|
-
) {
|
|
684
|
+
if (typeof argument !== 'function' && typeof argument.handleEvent !== 'function') {
|
|
744
685
|
throw new Error(
|
|
745
|
-
'Must provide a function or an EventListener object ' +
|
|
746
|
-
'implementing the handleEvent interface.',
|
|
686
|
+
'Must provide a function or an EventListener object ' + 'implementing the handleEvent interface.',
|
|
747
687
|
);
|
|
748
688
|
}
|
|
749
689
|
}
|
|
@@ -755,17 +695,11 @@
|
|
|
755
695
|
* and a guid that can be used to stop subscribing to the channel.
|
|
756
696
|
* Returns the guid.
|
|
757
697
|
*/
|
|
758
|
-
Channel.prototype.subscribe = function (
|
|
759
|
-
eventListenerOrFunction,
|
|
760
|
-
eventListener,
|
|
761
|
-
) {
|
|
698
|
+
Channel.prototype.subscribe = function (eventListenerOrFunction, eventListener) {
|
|
762
699
|
checkSubscriptionArgument(eventListenerOrFunction);
|
|
763
700
|
var handleEvent, guid;
|
|
764
701
|
|
|
765
|
-
if (
|
|
766
|
-
eventListenerOrFunction &&
|
|
767
|
-
typeof eventListenerOrFunction === 'object'
|
|
768
|
-
) {
|
|
702
|
+
if (eventListenerOrFunction && typeof eventListenerOrFunction === 'object') {
|
|
769
703
|
// Received an EventListener object implementing the handleEvent interface
|
|
770
704
|
handleEvent = eventListenerOrFunction.handleEvent;
|
|
771
705
|
eventListener = eventListenerOrFunction;
|
|
@@ -808,10 +742,7 @@
|
|
|
808
742
|
checkSubscriptionArgument(eventListenerOrFunction);
|
|
809
743
|
var handleEvent, guid, handler;
|
|
810
744
|
|
|
811
|
-
if (
|
|
812
|
-
eventListenerOrFunction &&
|
|
813
|
-
typeof eventListenerOrFunction === 'object'
|
|
814
|
-
) {
|
|
745
|
+
if (eventListenerOrFunction && typeof eventListenerOrFunction === 'object') {
|
|
815
746
|
// Received an EventListener object implementing the handleEvent interface
|
|
816
747
|
handleEvent = eventListenerOrFunction.handleEvent;
|
|
817
748
|
} else {
|
|
@@ -1013,11 +944,7 @@
|
|
|
1013
944
|
};
|
|
1014
945
|
if (window.androidBridge) {
|
|
1015
946
|
window.androidBridge.postMessage(JSON.stringify(command));
|
|
1016
|
-
} else if (
|
|
1017
|
-
window.webkit &&
|
|
1018
|
-
window.webkit.messageHandlers &&
|
|
1019
|
-
window.webkit.messageHandlers.bridge
|
|
1020
|
-
) {
|
|
947
|
+
} else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.bridge) {
|
|
1021
948
|
window.webkit.messageHandlers.bridge.postMessage(command);
|
|
1022
949
|
}
|
|
1023
950
|
};
|
|
@@ -1043,13 +970,7 @@
|
|
|
1043
970
|
var actionArgs = command[3];
|
|
1044
971
|
var callbacks = cordova.callbacks[callbackId] || {};
|
|
1045
972
|
|
|
1046
|
-
execProxy(
|
|
1047
|
-
callbacks.success,
|
|
1048
|
-
callbacks.fail,
|
|
1049
|
-
service,
|
|
1050
|
-
action,
|
|
1051
|
-
actionArgs,
|
|
1052
|
-
);
|
|
973
|
+
execProxy(callbacks.success, callbacks.fail, service, action, actionArgs);
|
|
1053
974
|
|
|
1054
975
|
commandString = commandQueue.shift();
|
|
1055
976
|
}
|
|
@@ -1107,23 +1028,11 @@
|
|
|
1107
1028
|
return json;
|
|
1108
1029
|
};
|
|
1109
1030
|
|
|
1110
|
-
capacitorExec.nativeCallback = function (
|
|
1111
|
-
callbackId,
|
|
1112
|
-
status,
|
|
1113
|
-
message,
|
|
1114
|
-
keepCallback,
|
|
1115
|
-
debug,
|
|
1116
|
-
) {
|
|
1031
|
+
capacitorExec.nativeCallback = function (callbackId, status, message, keepCallback, debug) {
|
|
1117
1032
|
var success = status === 0 || status === 1;
|
|
1118
1033
|
var args = convertMessageToArgsNativeToJs(message);
|
|
1119
1034
|
Promise.resolve().then(function () {
|
|
1120
|
-
cordova.callbackFromNative(
|
|
1121
|
-
callbackId,
|
|
1122
|
-
success,
|
|
1123
|
-
status,
|
|
1124
|
-
args,
|
|
1125
|
-
keepCallback,
|
|
1126
|
-
); // eslint-disable-line
|
|
1035
|
+
cordova.callbackFromNative(callbackId, success, status, args, keepCallback); // eslint-disable-line
|
|
1127
1036
|
});
|
|
1128
1037
|
};
|
|
1129
1038
|
|
|
@@ -1186,9 +1095,7 @@
|
|
|
1186
1095
|
},
|
|
1187
1096
|
|
|
1188
1097
|
get: function (service, action) {
|
|
1189
|
-
return CommandProxyMap[service]
|
|
1190
|
-
? CommandProxyMap[service][action]
|
|
1191
|
-
: null;
|
|
1098
|
+
return CommandProxyMap[service] ? CommandProxyMap[service][action] : null;
|
|
1192
1099
|
},
|
|
1193
1100
|
};
|
|
1194
1101
|
});
|
|
@@ -1202,10 +1109,7 @@
|
|
|
1202
1109
|
var pluginloader = require('cordova/pluginloader');
|
|
1203
1110
|
var utils = require('cordova/utils');
|
|
1204
1111
|
|
|
1205
|
-
var platformInitChannelsArray = [
|
|
1206
|
-
channel.onNativeReady,
|
|
1207
|
-
channel.onPluginsReady,
|
|
1208
|
-
];
|
|
1112
|
+
var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
|
|
1209
1113
|
|
|
1210
1114
|
function logUnfiredChannels(arr) {
|
|
1211
1115
|
for (var i = 0; i < arr.length; ++i) {
|
|
@@ -1255,14 +1159,10 @@
|
|
|
1255
1159
|
channel.onPause = cordova.addDocumentEventHandler('pause');
|
|
1256
1160
|
channel.onResume = cordova.addDocumentEventHandler('resume');
|
|
1257
1161
|
channel.onActivated = cordova.addDocumentEventHandler('activated');
|
|
1258
|
-
channel.onDeviceReady =
|
|
1259
|
-
cordova.addStickyDocumentEventHandler('deviceready');
|
|
1162
|
+
channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
|
|
1260
1163
|
|
|
1261
1164
|
// Listen for DOMContentLoaded and notify our channel subscribers.
|
|
1262
|
-
if (
|
|
1263
|
-
document.readyState === 'complete' ||
|
|
1264
|
-
document.readyState === 'interactive'
|
|
1265
|
-
) {
|
|
1165
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
1266
1166
|
channel.onDOMContentLoaded.fire();
|
|
1267
1167
|
} else {
|
|
1268
1168
|
document.addEventListener(
|
|
@@ -1328,12 +1228,7 @@
|
|
|
1328
1228
|
deprecationMap = {};
|
|
1329
1229
|
};
|
|
1330
1230
|
|
|
1331
|
-
function addEntry(
|
|
1332
|
-
strategy,
|
|
1333
|
-
moduleName,
|
|
1334
|
-
symbolPath,
|
|
1335
|
-
opt_deprecationMessage,
|
|
1336
|
-
) {
|
|
1231
|
+
function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
|
|
1337
1232
|
if (!(moduleName in moduleMap)) {
|
|
1338
1233
|
throw new Error('Module ' + moduleName + ' does not exist.');
|
|
1339
1234
|
}
|
|
@@ -1344,11 +1239,7 @@
|
|
|
1344
1239
|
}
|
|
1345
1240
|
|
|
1346
1241
|
// Note: Android 2.3 does have Function.bind().
|
|
1347
|
-
exports.clobbers = function (
|
|
1348
|
-
moduleName,
|
|
1349
|
-
symbolPath,
|
|
1350
|
-
opt_deprecationMessage,
|
|
1351
|
-
) {
|
|
1242
|
+
exports.clobbers = function (moduleName, symbolPath, opt_deprecationMessage) {
|
|
1352
1243
|
addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
|
|
1353
1244
|
};
|
|
1354
1245
|
|
|
@@ -1356,11 +1247,7 @@
|
|
|
1356
1247
|
addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
|
|
1357
1248
|
};
|
|
1358
1249
|
|
|
1359
|
-
exports.defaults = function (
|
|
1360
|
-
moduleName,
|
|
1361
|
-
symbolPath,
|
|
1362
|
-
opt_deprecationMessage,
|
|
1363
|
-
) {
|
|
1250
|
+
exports.defaults = function (moduleName, symbolPath, opt_deprecationMessage) {
|
|
1364
1251
|
addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
|
|
1365
1252
|
};
|
|
1366
1253
|
|
|
@@ -1399,10 +1286,7 @@
|
|
|
1399
1286
|
|
|
1400
1287
|
var deprecationMsg =
|
|
1401
1288
|
symbolPath in deprecationMap
|
|
1402
|
-
? 'Access made to deprecated symbol: ' +
|
|
1403
|
-
symbolPath +
|
|
1404
|
-
'. ' +
|
|
1405
|
-
deprecationMsg
|
|
1289
|
+
? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg
|
|
1406
1290
|
: null;
|
|
1407
1291
|
var parentObj = prepareNamespace(namespace, context);
|
|
1408
1292
|
var target = parentObj[lastName];
|
|
@@ -1413,12 +1297,7 @@
|
|
|
1413
1297
|
if (!(symbolPath in origSymbols)) {
|
|
1414
1298
|
origSymbols[symbolPath] = target;
|
|
1415
1299
|
}
|
|
1416
|
-
builder.assignOrWrapInDeprecateGetter(
|
|
1417
|
-
parentObj,
|
|
1418
|
-
lastName,
|
|
1419
|
-
module,
|
|
1420
|
-
deprecationMsg,
|
|
1421
|
-
);
|
|
1300
|
+
builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
|
|
1422
1301
|
}
|
|
1423
1302
|
}
|
|
1424
1303
|
};
|
|
@@ -1578,12 +1457,7 @@
|
|
|
1578
1457
|
* Does a deep clone of the object.
|
|
1579
1458
|
*/
|
|
1580
1459
|
utils.clone = function (obj) {
|
|
1581
|
-
if (
|
|
1582
|
-
!obj ||
|
|
1583
|
-
typeof obj === 'function' ||
|
|
1584
|
-
utils.isDate(obj) ||
|
|
1585
|
-
typeof obj !== 'object'
|
|
1586
|
-
) {
|
|
1460
|
+
if (!obj || typeof obj === 'function' || utils.isDate(obj) || typeof obj !== 'object') {
|
|
1587
1461
|
return obj;
|
|
1588
1462
|
}
|
|
1589
1463
|
|
|
@@ -1602,11 +1476,7 @@
|
|
|
1602
1476
|
// https://issues.apache.org/jira/browse/CB-11522 'unknown' type may be returned in
|
|
1603
1477
|
// custom protocol activation case on Windows Phone 8.1 causing "No such interface supported" exception
|
|
1604
1478
|
// on cloning.
|
|
1605
|
-
if (
|
|
1606
|
-
(!(i in retVal) || retVal[i] !== obj[i]) &&
|
|
1607
|
-
typeof obj[i] !== 'undefined' &&
|
|
1608
|
-
typeof obj[i] !== 'unknown'
|
|
1609
|
-
) {
|
|
1479
|
+
if ((!(i in retVal) || retVal[i] !== obj[i]) && typeof obj[i] !== 'undefined' && typeof obj[i] !== 'unknown') {
|
|
1610
1480
|
// eslint-disable-line valid-typeof
|
|
1611
1481
|
retVal[i] = utils.clone(obj[i]);
|
|
1612
1482
|
}
|
package/dist/capacitor.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! Capacitor: https://capacitorjs.com/ - MIT License */
|
|
2
|
-
var capacitorExports=function(e){"use strict";const t=(e=>e.CapacitorPlatforms=(e=>{const t=new Map;t.set("web",{name:"web"});const n=e.CapacitorPlatforms||{currentPlatform:{name:"web"},platforms:t};return n.addPlatform=(e,t)=>{n.platforms.set(e,t)},n.setPlatform=e=>{n.platforms.has(e)&&(n.currentPlatform=n.platforms.get(e))},n})(e))("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}),n=t.addPlatform,r=t.setPlatform;var
|
|
2
|
+
var capacitorExports=function(e){"use strict";const t=(e=>e.CapacitorPlatforms=(e=>{const t=new Map;t.set("web",{name:"web"});const n=e.CapacitorPlatforms||{currentPlatform:{name:"web"},platforms:t};return n.addPlatform=(e,t)=>{n.platforms.set(e,t)},n.setPlatform=e=>{n.platforms.has(e)&&(n.currentPlatform=n.platforms.get(e))},n})(e))("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}),n=t.addPlatform,r=t.setPlatform;var s;e.ExceptionCode=void 0,(s=e.ExceptionCode||(e.ExceptionCode={})).Unimplemented="UNIMPLEMENTED",s.Unavailable="UNAVAILABLE";class i extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}}const o=t=>{var n,r,s,o,a;const l=t.CapacitorCustomPlatform||null,d=t.Capacitor||{},c=d.Plugins=d.Plugins||{},u=t.CapacitorPlatforms,m=(null===(n=null==u?void 0:u.currentPlatform)||void 0===n?void 0:n.getPlatform)||(()=>null!==l?l.name:(e=>{var t,n;return(null==e?void 0:e.androidBridge)?"android":(null===(n=null===(t=null==e?void 0:e.webkit)||void 0===t?void 0:t.messageHandlers)||void 0===n?void 0:n.bridge)?"ios":"web"})(t)),p=(null===(r=null==u?void 0:u.currentPlatform)||void 0===r?void 0:r.isNativePlatform)||(()=>"web"!==m()),f=(null===(s=null==u?void 0:u.currentPlatform)||void 0===s?void 0:s.isPluginAvailable)||(e=>{const t=w.get(e);return!!(null==t?void 0:t.platforms.has(m()))||!!h(e)}),h=(null===(o=null==u?void 0:u.currentPlatform)||void 0===o?void 0:o.getPluginHeader)||(e=>{var t;return null===(t=d.PluginHeaders)||void 0===t?void 0:t.find((t=>t.name===e))}),w=new Map,g=(null===(a=null==u?void 0:u.currentPlatform)||void 0===a?void 0:a.registerPlugin)||((t,n={})=>{const r=w.get(t);if(r)return console.warn(`Capacitor plugin "${t}" already registered. Cannot register plugins twice.`),r.proxy;const s=m(),o=h(t);let a;const u=r=>{let c;const u=(...u)=>{const m=(async()=>(!a&&s in n?a=a="function"==typeof n[s]?await n[s]():n[s]:null!==l&&!a&&"web"in n&&(a=a="function"==typeof n.web?await n.web():n.web),a))().then((n=>{const a=((n,r)=>{var a,l;if(!o){if(n)return null===(l=n[r])||void 0===l?void 0:l.bind(n);throw new i(`"${t}" plugin is not implemented on ${s}`,e.ExceptionCode.Unimplemented)}{const e=null==o?void 0:o.methods.find((e=>r===e.name));if(e)return"promise"===e.rtype?e=>d.nativePromise(t,r.toString(),e):(e,n)=>d.nativeCallback(t,r.toString(),e,n);if(n)return null===(a=n[r])||void 0===a?void 0:a.bind(n)}})(n,r);if(a){const e=a(...u);return c=null==e?void 0:e.remove,e}throw new i(`"${t}.${r}()" is not implemented on ${s}`,e.ExceptionCode.Unimplemented)}));return"addListener"===r&&(m.remove=async()=>c()),m};return u.toString=()=>`${r.toString()}() { [capacitor code] }`,Object.defineProperty(u,"name",{value:r,writable:!1,configurable:!1}),u},p=u("addListener"),f=u("removeListener"),g=(e,t)=>{const n=p({eventName:e},t),r=async()=>{const r=await n;f({eventName:e,callbackId:r},t)},s=new Promise((e=>n.then((()=>e({remove:r})))));return s.remove=async()=>{console.warn("Using addListener() without 'await' is deprecated."),await r()},s},v=new Proxy({},{get(e,t){switch(t){case"$$typeof":return;case"toJSON":return()=>({});case"addListener":return o?g:p;case"removeListener":return f;default:return u(t)}}});return c[t]=v,w.set(t,{name:t,proxy:v,platforms:new Set([...Object.keys(n),...o?[s]:[]])}),v});return d.convertFileSrc||(d.convertFileSrc=e=>e),d.getPlatform=m,d.handleError=e=>t.console.error(e),d.isNativePlatform=p,d.isPluginAvailable=f,d.registerPlugin=g,d.Exception=i,d.DEBUG=!!d.DEBUG,d.isLoggingEnabled=!!d.isLoggingEnabled,d},a=(e=>e.Capacitor=o(e))("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}),l=a.registerPlugin;class d{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(e,t){let n=!1;this.listeners[e]||(this.listeners[e]=[],n=!0),this.listeners[e].push(t);const r=this.windowListeners[e];r&&!r.registered&&this.addWindowListener(r),n&&this.sendRetainedArgumentsForEvent(e);return Promise.resolve({remove:async()=>this.removeListener(e,t)})}async removeAllListeners(){this.listeners={};for(const e in this.windowListeners)this.removeWindowListener(this.windowListeners[e]);this.windowListeners={}}notifyListeners(e,t,n){const r=this.listeners[e];if(r)r.forEach((e=>e(t)));else if(n){let n=this.retainedEventArguments[e];n||(n=[]),n.push(t),this.retainedEventArguments[e]=n}}hasListeners(e){return!!this.listeners[e].length}registerWindowListener(e,t){this.windowListeners[t]={registered:!1,windowEventName:e,pluginEventName:t,handler:e=>{this.notifyListeners(t,e)}}}unimplemented(t="not implemented"){return new a.Exception(t,e.ExceptionCode.Unimplemented)}unavailable(t="not available"){return new a.Exception(t,e.ExceptionCode.Unavailable)}async removeListener(e,t){const n=this.listeners[e];if(!n)return;const r=n.indexOf(t);this.listeners[e].splice(r,1),this.listeners[e].length||this.removeWindowListener(this.windowListeners[e])}addWindowListener(e){window.addEventListener(e.windowEventName,e.handler),e.registered=!0}removeWindowListener(e){e&&(window.removeEventListener(e.windowEventName,e.handler),e.registered=!1)}sendRetainedArgumentsForEvent(e){const t=this.retainedEventArguments[e];t&&(delete this.retainedEventArguments[e],t.forEach((t=>{this.notifyListeners(e,t)})))}}const c=l("WebView"),u=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),m=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);class p extends d{async getCookies(){const e=document.cookie,t={};return e.split(";").forEach((e=>{if(e.length<=0)return;let[n,r]=e.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");n=m(n).trim(),r=m(r).trim(),t[n]=r})),t}async setCookie(e){try{const t=u(e.key),n=u(e.value),r=`; expires=${(e.expires||"").replace("expires=","")}`,s=(e.path||"/").replace("path=",""),i=null!=e.url&&e.url.length>0?`domain=${e.url}`:"";document.cookie=`${t}=${n||""}${r}; path=${s}; ${i};`}catch(e){return Promise.reject(e)}}async deleteCookie(e){try{document.cookie=`${e.key}=; Max-Age=0`}catch(e){return Promise.reject(e)}}async clearCookies(){try{const e=document.cookie.split(";")||[];for(const t of e)document.cookie=t.replace(/^ +/,"").replace(/=.*/,`=;expires=${(new Date).toUTCString()};path=/`)}catch(e){return Promise.reject(e)}}async clearAllCookies(){try{await this.clearCookies()}catch(e){return Promise.reject(e)}}}const f=l("CapacitorCookies",{web:()=>new p}),h=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),r=((e={})=>{const t=Object.keys(e);return Object.keys(e).map((e=>e.toLocaleLowerCase())).reduce(((n,r,s)=>(n[r]=e[t[s]],n)),{})})(e.headers)["content-type"]||"";if("string"==typeof e.data)n.body=e.data;else if(r.includes("application/x-www-form-urlencoded")){const t=new URLSearchParams;for(const[n,r]of Object.entries(e.data||{}))t.set(n,r);n.body=t.toString()}else if(r.includes("multipart/form-data")||e.data instanceof FormData){const t=new FormData;if(e.data instanceof FormData)e.data.forEach(((e,n)=>{t.append(n,e)}));else for(const n of Object.keys(e.data))t.append(n,e.data[n]);n.body=t;const r=new Headers(n.headers);r.delete("content-type"),n.headers=r}else(r.includes("application/json")||"object"==typeof e.data)&&(n.body=JSON.stringify(e.data));return n};class w extends d{async request(e){const t=h(e,e.webFetchExtra),n=((e,t=!0)=>e?Object.entries(e).reduce(((e,n)=>{const[r,s]=n;let i,o;return Array.isArray(s)?(o="",s.forEach((e=>{i=t?encodeURIComponent(e):e,o+=`${r}=${i}&`})),o.slice(0,-1)):(i=t?encodeURIComponent(s):s,o=`${r}=${i}`),`${e}&${o}`}),"").substr(1):null)(e.params,e.shouldEncodeUrlParams),r=n?`${e.url}?${n}`:e.url,s=await fetch(r,t),i=s.headers.get("content-type")||"";let o,a,{responseType:l="text"}=s.ok?e:{};switch(i.includes("application/json")&&(l="json"),l){case"arraybuffer":case"blob":a=await s.blob(),o=await(async e=>new Promise(((t,n)=>{const r=new FileReader;r.onload=()=>{const e=r.result;t(e.indexOf(",")>=0?e.split(",")[1]:e)},r.onerror=e=>n(e),r.readAsDataURL(e)})))(a);break;case"json":o=await s.json();break;default:o=await s.text()}const d={};return s.headers.forEach(((e,t)=>{d[t]=e})),{data:o,headers:d,status:s.status,url:s.url}}async get(e){return this.request(Object.assign(Object.assign({},e),{method:"GET"}))}async post(e){return this.request(Object.assign(Object.assign({},e),{method:"POST"}))}async put(e){return this.request(Object.assign(Object.assign({},e),{method:"PUT"}))}async patch(e){return this.request(Object.assign(Object.assign({},e),{method:"PATCH"}))}async delete(e){return this.request(Object.assign(Object.assign({},e),{method:"DELETE"}))}}const g=l("CapacitorHttp",{web:()=>new w});return e.Capacitor=a,e.CapacitorCookies=f,e.CapacitorException=i,e.CapacitorHttp=g,e.CapacitorPlatforms=t,e.WebPlugin=d,e.WebView=c,e.addPlatform=n,e.buildRequestInit=h,e.registerPlugin=l,e.setPlatform=r,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
3
3
|
//# sourceMappingURL=capacitor.js.map
|