@tarojs/taro-h5 4.0.0-beta.2 → 4.0.0-beta.21

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 (46) hide show
  1. package/dist/api/base/index.d.ts +1 -1
  2. package/dist/api/base/index.js +1 -1
  3. package/dist/api/base/index.js.map +1 -1
  4. package/dist/api/device/clipboard.js +6 -0
  5. package/dist/api/device/clipboard.js.map +1 -1
  6. package/dist/api/device/network.js.map +1 -1
  7. package/dist/api/device/sms.js.map +1 -1
  8. package/dist/api/index.js +1 -0
  9. package/dist/api/index.js.map +1 -1
  10. package/dist/api/location/chooseLocation.js +2 -2
  11. package/dist/api/location/chooseLocation.js.map +1 -1
  12. package/dist/api/network/request/index.js +9 -7
  13. package/dist/api/network/request/index.js.map +1 -1
  14. package/dist/api/network/websocket/index.d.ts +2 -1
  15. package/dist/api/network/websocket/index.js +1 -1
  16. package/dist/api/network/websocket/index.js.map +1 -1
  17. package/dist/api/storage/index.js.map +1 -1
  18. package/dist/api/ui/animation/index.js +68 -38
  19. package/dist/api/ui/animation/index.js.map +1 -1
  20. package/dist/api/ui/interaction/actionSheet.d.ts +12 -0
  21. package/dist/api/ui/interaction/actionSheet.js +34 -12
  22. package/dist/api/ui/interaction/actionSheet.js.map +1 -1
  23. package/dist/api/ui/interaction/index.js +2 -1
  24. package/dist/api/ui/interaction/index.js.map +1 -1
  25. package/dist/api/ui/interaction/modal.d.ts +2 -0
  26. package/dist/api/ui/interaction/modal.js +3 -1
  27. package/dist/api/ui/interaction/modal.js.map +1 -1
  28. package/dist/api/ui/navigation-bar/index.js +3 -2
  29. package/dist/api/ui/navigation-bar/index.js.map +1 -1
  30. package/dist/api/wxml/IntersectionObserver.js +2 -1
  31. package/dist/api/wxml/IntersectionObserver.js.map +1 -1
  32. package/dist/api/wxml/MediaQueryObserver.js.map +1 -1
  33. package/dist/api/wxml/index.js.map +1 -1
  34. package/dist/api/wxml/nodesRef.js +5 -2
  35. package/dist/api/wxml/nodesRef.js.map +1 -1
  36. package/dist/index.cjs.d.ts +26 -2
  37. package/dist/index.cjs.js +2130 -2059
  38. package/dist/index.cjs.js.map +1 -1
  39. package/dist/index.esm.d.ts +26 -2
  40. package/dist/index.esm.js +2131 -2061
  41. package/dist/index.esm.js.map +1 -1
  42. package/dist/index.js +1 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/utils/handler.js +4 -0
  45. package/dist/utils/handler.js.map +1 -1
  46. package/package.json +7 -8
package/dist/index.cjs.js CHANGED
@@ -92,6 +92,10 @@ class CallbackManager {
92
92
  this.callbacks.splice(pos, 1);
93
93
  }
94
94
  }
95
+ else {
96
+ // Note: 参数为空,则取消所有的事件监听
97
+ this.callbacks = [];
98
+ }
95
99
  };
96
100
  /** 获取回调函数数量 */
97
101
  this.count = () => {
@@ -701,7 +705,7 @@ function arrayBufferToBase64(arrayBuffer) {
701
705
  return base64Js.fromByteArray(arrayBuffer);
702
706
  }
703
707
  function base64ToArrayBuffer(base64) {
704
- return base64Js.toByteArray(base64);
708
+ return base64Js.toByteArray(base64).buffer;
705
709
  }
706
710
 
707
711
  const TextBaseLineMap = {
@@ -1474,2203 +1478,2263 @@ const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetStorage')
1474
1478
  const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync');
1475
1479
  const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage');
1476
1480
 
1477
- /**
1478
- * 剪贴板部分的api参考了Chameleon项目的实现:
1479
- *
1480
- * setClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/setClipBoardData
1481
- * getClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/getClipBoardData
1482
- */
1483
- const CLIPBOARD_STORAGE_NAME = 'taro_clipboard';
1484
- document.addEventListener('copy', () => {
1485
- var _a;
1486
- setStorage({
1487
- key: CLIPBOARD_STORAGE_NAME,
1488
- data: (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString()
1489
- }).catch(e => {
1490
- console.error(e);
1491
- });
1492
- });
1493
- /**
1494
- * 设置系统剪贴板的内容
1495
- */
1496
- const setClipboardData = ({ data, success, fail, complete }) => tslib.__awaiter(void 0, void 0, void 0, function* () {
1497
- const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete });
1498
- try {
1499
- setStorageSync(CLIPBOARD_STORAGE_NAME, data);
1500
- /**
1501
- * 已于 iPhone 6s Plus iOS 13.1.3 上的 Safari 测试通过
1502
- * iOS < 10 的系统可能无法使用编程方式访问剪贴板,参考:
1503
- * https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios/34046084
1504
- */
1505
- if (shared.isFunction(document.execCommand)) {
1506
- const textarea = document.createElement('textarea');
1507
- textarea.readOnly = true;
1508
- textarea.value = data;
1509
- textarea.style.position = 'absolute';
1510
- textarea.style.width = '100px';
1511
- textarea.style.left = '-10000px';
1512
- document.body.appendChild(textarea);
1513
- textarea.select();
1514
- textarea.setSelectionRange(0, textarea.value.length);
1515
- document.execCommand('copy');
1516
- document.body.removeChild(textarea);
1517
- }
1518
- else {
1519
- throw new Error('Unsupported Function: \'document.execCommand\'.');
1520
- }
1521
- return handle.success();
1481
+ const noop = function () { };
1482
+ class ActionSheet {
1483
+ constructor() {
1484
+ this.options = {
1485
+ alertText: '',
1486
+ itemList: [],
1487
+ itemColor: '#000000',
1488
+ success: noop,
1489
+ fail: noop,
1490
+ complete: noop,
1491
+ };
1492
+ this.style = {
1493
+ maskStyle: {
1494
+ position: 'fixed',
1495
+ 'z-index': '1000',
1496
+ top: '0',
1497
+ right: '0',
1498
+ left: '0',
1499
+ bottom: '0',
1500
+ background: 'rgba(0,0,0,0.6)',
1501
+ },
1502
+ actionSheetStyle: {
1503
+ 'z-index': '4999',
1504
+ position: 'fixed',
1505
+ left: '0',
1506
+ bottom: '0',
1507
+ '-webkit-transform': 'translate(0, 100%)',
1508
+ transform: 'translate(0, 100%)',
1509
+ width: '100%',
1510
+ 'line-height': '1.6',
1511
+ background: '#EFEFF4',
1512
+ '-webkit-transition': '-webkit-transform .3s',
1513
+ transition: 'transform .3s',
1514
+ 'border-radius': '15px 15px 0 0',
1515
+ },
1516
+ menuStyle: {
1517
+ 'background-color': '#FCFCFD',
1518
+ 'border-radius': '15px 15px 0 0',
1519
+ },
1520
+ cellStyle: {
1521
+ position: 'relative',
1522
+ padding: '10px 0',
1523
+ 'text-align': 'center',
1524
+ 'font-size': '18px',
1525
+ },
1526
+ titleStyle: {
1527
+ position: 'relative',
1528
+ padding: '10px 0',
1529
+ 'text-align': 'center',
1530
+ 'font-size': '16px',
1531
+ color: 'rgba(0,0,0,0.8)',
1532
+ display: 'none',
1533
+ },
1534
+ cancelStyle: {
1535
+ 'margin-top': '6px',
1536
+ padding: '10px 0',
1537
+ 'text-align': 'center',
1538
+ 'font-size': '18px',
1539
+ color: '#000000',
1540
+ 'background-color': '#FCFCFD',
1541
+ },
1542
+ };
1543
+ this.lastConfig = {};
1522
1544
  }
1523
- catch (e) {
1524
- return handle.fail({ errMsg: e.message });
1545
+ create(options = {}) {
1546
+ return new Promise((resolve) => {
1547
+ // style
1548
+ const { maskStyle, actionSheetStyle, menuStyle, cellStyle, titleStyle, cancelStyle } = this.style;
1549
+ // configuration
1550
+ const config = Object.assign(Object.assign({}, this.options), options);
1551
+ this.lastConfig = config;
1552
+ // wrapper
1553
+ this.el = document.createElement('div');
1554
+ this.el.className = 'taro__actionSheet';
1555
+ this.el.style.opacity = '0';
1556
+ this.el.style.transition = 'opacity 0.2s linear';
1557
+ // mask
1558
+ this.mask = document.createElement('div');
1559
+ this.mask.setAttribute('style', inlineStyle(maskStyle));
1560
+ // actionSheet
1561
+ this.actionSheet = document.createElement('div');
1562
+ this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
1563
+ // menu
1564
+ this.menu = document.createElement('div');
1565
+ this.menu.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, menuStyle), { color: config.itemColor })));
1566
+ // cells
1567
+ this.cells = config.itemList.map((item, index) => {
1568
+ const cell = document.createElement('div');
1569
+ cell.className = 'taro-actionsheet__cell';
1570
+ cell.setAttribute('style', inlineStyle(cellStyle));
1571
+ cell.textContent = item;
1572
+ cell.dataset.tapIndex = `${index}`;
1573
+ cell.onclick = (e) => {
1574
+ this.hide();
1575
+ const target = e.currentTarget;
1576
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
1577
+ resolve(index);
1578
+ };
1579
+ return cell;
1580
+ });
1581
+ // title
1582
+ this.title = document.createElement('div');
1583
+ this.title.setAttribute('style', inlineStyle(titleStyle));
1584
+ this.title.className = 'taro-actionsheet__cell';
1585
+ this.title.textContent = config.alertText;
1586
+ this.title.style.display = config.alertText ? 'block' : 'none';
1587
+ // cancel
1588
+ this.cancel = document.createElement('div');
1589
+ this.cancel.setAttribute('style', inlineStyle(cancelStyle));
1590
+ this.cancel.textContent = '取消';
1591
+ // result
1592
+ this.menu.appendChild(this.title);
1593
+ this.cells.forEach((item) => this.menu.appendChild(item));
1594
+ this.actionSheet.appendChild(this.menu);
1595
+ this.actionSheet.appendChild(this.cancel);
1596
+ this.el.appendChild(this.mask);
1597
+ this.el.appendChild(this.actionSheet);
1598
+ // callbacks
1599
+ const cb = () => {
1600
+ this.hide();
1601
+ resolve('cancel');
1602
+ };
1603
+ this.mask.onclick = cb;
1604
+ this.cancel.onclick = cb;
1605
+ // show immediately
1606
+ document.body.appendChild(this.el);
1607
+ setTimeout(() => {
1608
+ this.el.style.opacity = '1';
1609
+ setTransform(this.actionSheet, 'translate(0, 0)');
1610
+ }, 0);
1611
+ });
1525
1612
  }
1526
- });
1527
- /**
1528
- * 获取系统剪贴板的内容
1529
- */
1530
- const getClipboardData = ({ success, fail, complete } = {}) => tslib.__awaiter(void 0, void 0, void 0, function* () {
1531
- const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
1532
- try {
1533
- const data = getStorageSync(CLIPBOARD_STORAGE_NAME);
1534
- return handle.success({ data });
1613
+ show(options = {}) {
1614
+ return new Promise((resolve) => {
1615
+ const config = Object.assign(Object.assign({}, this.options), options);
1616
+ this.lastConfig = config;
1617
+ if (this.hideOpacityTimer)
1618
+ clearTimeout(this.hideOpacityTimer);
1619
+ if (this.hideDisplayTimer)
1620
+ clearTimeout(this.hideDisplayTimer);
1621
+ // itemColor
1622
+ if (config.itemColor)
1623
+ this.menu.style.color = config.itemColor;
1624
+ // cells
1625
+ const { cellStyle } = this.style;
1626
+ config.itemList.forEach((item, index) => {
1627
+ let cell;
1628
+ if (this.cells[index]) {
1629
+ // assign new content
1630
+ cell = this.cells[index];
1631
+ }
1632
+ else {
1633
+ // create new cell
1634
+ cell = document.createElement('div');
1635
+ cell.className = 'taro-actionsheet__cell';
1636
+ cell.setAttribute('style', inlineStyle(cellStyle));
1637
+ cell.dataset.tapIndex = `${index}`;
1638
+ this.cells.push(cell);
1639
+ this.menu.appendChild(cell);
1640
+ }
1641
+ cell.textContent = item;
1642
+ cell.onclick = (e) => {
1643
+ this.hide();
1644
+ const target = e.currentTarget;
1645
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
1646
+ resolve(index);
1647
+ };
1648
+ });
1649
+ const cellsLen = this.cells.length;
1650
+ const itemListLen = config.itemList.length;
1651
+ if (cellsLen > itemListLen) {
1652
+ for (let i = itemListLen; i < cellsLen; i++) {
1653
+ this.menu.removeChild(this.cells[i]);
1654
+ }
1655
+ this.cells.splice(itemListLen);
1656
+ }
1657
+ this.title.textContent = config.alertText;
1658
+ this.title.style.display = config.alertText ? 'block' : 'none';
1659
+ // callbacks
1660
+ const cb = () => {
1661
+ this.hide();
1662
+ resolve('cancel');
1663
+ };
1664
+ this.mask.onclick = cb;
1665
+ this.cancel.onclick = cb;
1666
+ // show
1667
+ this.el.style.display = 'block';
1668
+ setTimeout(() => {
1669
+ this.el.style.opacity = '1';
1670
+ setTransform(this.actionSheet, 'translate(0, 0)');
1671
+ }, 0);
1672
+ });
1535
1673
  }
1536
- catch (e) {
1537
- return handle.fail({ errMsg: e.message });
1674
+ hide() {
1675
+ if (this.hideOpacityTimer)
1676
+ clearTimeout(this.hideOpacityTimer);
1677
+ if (this.hideDisplayTimer)
1678
+ clearTimeout(this.hideDisplayTimer);
1679
+ this.hideOpacityTimer = setTimeout(() => {
1680
+ this.el.style.opacity = '0';
1681
+ setTransform(this.actionSheet, 'translate(0, 100%)');
1682
+ this.hideDisplayTimer = setTimeout(() => {
1683
+ this.el.style.display = 'none';
1684
+ }, 200);
1685
+ }, 0);
1538
1686
  }
1539
- });
1687
+ }
1540
1688
 
1541
- const callbackManager$2 = new CallbackManager();
1542
- let compassListener;
1543
- /**
1544
- * Note: 按系统类型获取对应绝对 orientation 事件名,因为安卓系统中直接监听 deviceorientation 事件得到的不是绝对 orientation
1545
- */
1546
- const deviceorientationEventName = ['absolutedeviceorientation', 'deviceorientationabsolute', 'deviceorientation'].find(item => {
1547
- if ('on' + item in window) {
1548
- return item;
1549
- }
1550
- }) || '';
1551
- /**
1552
- * 停止监听罗盘数据
1553
- */
1554
- const stopCompass = ({ success, fail, complete } = {}) => {
1555
- const handle = new MethodHandler({ name: 'stopCompass', success, fail, complete });
1556
- try {
1557
- window.removeEventListener(deviceorientationEventName, compassListener, true);
1558
- return handle.success();
1559
- }
1560
- catch (e) {
1561
- return handle.fail({ errMsg: e.message });
1562
- }
1563
- };
1564
- let CompassChangeTrigger = false;
1565
- /**
1566
- * 开始监听罗盘数据
1567
- */
1568
- const startCompass = ({ success, fail, complete } = {}) => {
1569
- const handle = new MethodHandler({ name: 'startCompass', success, fail, complete });
1570
- try {
1571
- if (deviceorientationEventName !== '') {
1572
- if (compassListener) {
1573
- stopCompass();
1574
- }
1575
- compassListener = throttle((evt) => {
1576
- const isAndroid = getDeviceInfo().system === 'AndroidOS';
1577
- if (isAndroid && !evt.absolute && !CompassChangeTrigger) {
1578
- CompassChangeTrigger = true;
1579
- console.warn('Warning: In \'onCompassChange\', your browser is not supported to get the orientation relative to the earth, the orientation data will be related to the initial orientation of the device .');
1580
- }
1581
- const alpha = evt.alpha || 0;
1582
- /**
1583
- * 由于平台差异,accuracy 在 iOS/Android 的值不同。
1584
- * - iOS:accuracy 是一个 number 类型的值,表示相对于磁北极的偏差。0 表示设备指向磁北,90 表示指向东,180 表示指向南,依此类推。
1585
- * - Android:accuracy 是一个 string 类型的枚举值。
1586
- */
1587
- const accuracy = isAndroid ? evt.absolute ? 'high' : 'medium' : alpha;
1588
- callbackManager$2.trigger({
1589
- direction: 360 - alpha,
1590
- accuracy: accuracy
1591
- });
1592
- }, 5000);
1593
- window.addEventListener(deviceorientationEventName, compassListener, true);
1594
- }
1595
- else {
1596
- throw new Error('compass is not supported');
1597
- }
1598
- return handle.success();
1599
- }
1600
- catch (e) {
1601
- return handle.fail({ errMsg: e.message });
1602
- }
1603
- };
1604
- /**
1605
- * 监听罗盘数据变化事件。频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
1606
- */
1607
- const onCompassChange = callback => {
1608
- callbackManager$2.add(callback);
1609
- };
1610
- /**
1611
- * 取消监听罗盘数据变化事件,参数为空,则取消所有的事件监听。
1612
- */
1613
- const offCompassChange = callback => {
1614
- callbackManager$2.remove(callback);
1615
- };
1616
-
1617
- // 联系人
1618
- const chooseContact = /* @__PURE__ */ temporarilyNotSupport('chooseContact');
1619
- const addPhoneContact = /* @__PURE__ */ temporarilyNotSupport('addPhoneContact');
1620
-
1621
- // 加密
1622
- const getRandomValues = /* @__PURE__ */ temporarilyNotSupport('getRandomValues');
1623
-
1624
- // 陀螺仪
1625
- const stopGyroscope = /* @__PURE__ */ temporarilyNotSupport('stopGyroscope');
1626
- const startGyroscope = /* @__PURE__ */ temporarilyNotSupport('startGyroscope');
1627
- const onGyroscopeChange = /* @__PURE__ */ temporarilyNotSupport('onGyroscopeChange');
1628
- const offGyroscopeChange = /* @__PURE__ */ temporarilyNotSupport('offGyroscopeChange');
1629
-
1630
- // 蓝牙-信标(Beacon)
1631
- const stopBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('stopBeaconDiscovery');
1632
- const startBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('startBeaconDiscovery');
1633
- const onBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('onBeaconUpdate');
1634
- const onBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('onBeaconServiceChange');
1635
- const offBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('offBeaconUpdate');
1636
- const offBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('offBeaconServiceChange');
1637
- const getBeacons = /* @__PURE__ */ temporarilyNotSupport('getBeacons');
1638
-
1639
- // 键盘
1640
- const onKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('onKeyboardHeightChange');
1641
- const offKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('offKeyboardHeightChange');
1642
- const hideKeyboard = /* @__PURE__ */ temporarilyNotSupport('hideKeyboard');
1643
- const getSelectedTextRange = /* @__PURE__ */ temporarilyNotSupport('getSelectedTextRange');
1644
-
1645
- // 内存
1646
- const onMemoryWarning = /* @__PURE__ */ temporarilyNotSupport('onMemoryWarning');
1647
- const offMemoryWarning = /* @__PURE__ */ temporarilyNotSupport('offMemoryWarning');
1648
-
1649
- const callbackManager$1 = new CallbackManager();
1650
- let deviceMotionListener;
1651
- const INTERVAL_MAP = {
1652
- game: {
1653
- interval: 20,
1654
- frequency: 50
1655
- },
1656
- ui: {
1657
- interval: 60,
1658
- frequency: 16.67
1659
- },
1660
- normal: {
1661
- interval: 200,
1662
- frequency: 5
1663
- }
1664
- };
1665
- /**
1666
- * 停止监听设备方向的变化。
1667
- */
1668
- const stopDeviceMotionListening = ({ success, fail, complete } = {}) => {
1669
- const handle = new MethodHandler({ name: 'stopDeviceMotionListening', success, fail, complete });
1670
- try {
1671
- window.removeEventListener('deviceorientation', deviceMotionListener, true);
1672
- return handle.success();
1673
- }
1674
- catch (e) {
1675
- return handle.fail({ errMsg: e.message });
1676
- }
1677
- };
1678
- /**
1679
- * 开始监听设备方向的变化。
1680
- */
1681
- const startDeviceMotionListening = ({ interval = 'normal', success, fail, complete } = {}) => {
1682
- const handle = new MethodHandler({ name: 'startDeviceMotionListening', success, fail, complete });
1683
- try {
1684
- const intervalObj = INTERVAL_MAP[interval];
1685
- if (window.DeviceOrientationEvent) {
1686
- if (deviceMotionListener) {
1687
- stopDeviceMotionListening();
1688
- }
1689
- deviceMotionListener = throttle((evt) => {
1690
- callbackManager$1.trigger({
1691
- alpha: evt.alpha,
1692
- beta: evt.beta,
1693
- gamma: evt.gamma
1694
- });
1695
- }, intervalObj.interval);
1696
- window.addEventListener('deviceorientation', deviceMotionListener, true);
1697
- }
1698
- else {
1699
- throw new Error('deviceMotion is not supported');
1700
- }
1701
- return handle.success();
1702
- }
1703
- catch (e) {
1704
- return handle.fail({ errMsg: e.message });
1705
- }
1706
- };
1707
- /**
1708
- * 监听设备方向变化事件。
1709
- */
1710
- const onDeviceMotionChange = callback => {
1711
- callbackManager$1.add(callback);
1712
- };
1713
- /**
1714
- * 取消监听设备方向变化事件,参数为空,则取消所有的事件监听。
1715
- */
1716
- const offDeviceMotionChange = callback => {
1717
- callbackManager$1.remove(callback);
1718
- };
1719
-
1720
- function getConnection() {
1721
- // @ts-ignore
1722
- return navigator.connection || navigator.mozConnection || navigator.webkitConnection || navigator.msConnection;
1723
- }
1724
- const getNetworkType = (options = {}) => {
1725
- const connection = getConnection();
1726
- const { success, fail, complete } = options;
1727
- const handle = new MethodHandler({ name: 'getNetworkType', success, fail, complete });
1728
- let networkType = 'unknown';
1729
- // 浏览器不支持获取网络状态
1730
- if (!connection) {
1731
- return handle.success({ networkType });
1732
- }
1733
- // Supports only the navigator.connection.type value which doesn't match the latest spec.
1734
- // https://www.davidbcalhoun.com/2010/using-navigator-connection-android/
1735
- if (!isNaN(Number(connection.type))) {
1736
- switch (connection.type) {
1737
- // @ts-ignore
1738
- case connection.WIFI:
1739
- networkType = 'wifi';
1740
- break;
1741
- // @ts-ignore
1742
- case connection.CELL_3G:
1743
- networkType = '3g';
1744
- break;
1745
- // @ts-ignore
1746
- case connection.CELL_2G:
1747
- networkType = '2g';
1748
- break;
1749
- default:
1750
- // ETHERNET, UNKNOWN
1751
- networkType = 'unknown';
1752
- }
1753
- }
1754
- else if (connection.type) {
1755
- // @ts-ignore
1756
- networkType = connection.type; // Only supports the type value.
1757
- // @ts-ignore
1758
- }
1759
- else if (connection.effectiveType) {
1760
- // @ts-ignore
1761
- networkType = connection.effectiveType;
1762
- }
1763
- return handle.success({ networkType });
1764
- };
1765
- const networkStatusManager = new CallbackManager();
1766
- const networkStatusListener = () => tslib.__awaiter(void 0, void 0, void 0, function* () {
1767
- const { networkType } = yield getNetworkType();
1768
- const isConnected = networkType !== 'none';
1769
- const obj = { isConnected, networkType };
1770
- networkStatusManager.trigger(obj);
1771
- });
1772
- /**
1773
- * 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
1774
- * - 出现三次以上连接超时
1775
- * - 出现三次 rtt 超过 400
1776
- * - 出现三次以上的丢包
1777
- * > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
1778
- */
1779
- const onNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('onNetworkWeakChange');
1780
- const onNetworkStatusChange = callback => {
1781
- networkStatusManager.add(callback);
1782
- const connection = getConnection();
1783
- if (connection && networkStatusManager.count() === 1) {
1784
- connection.addEventListener('change', networkStatusListener);
1785
- }
1786
- };
1787
- const offNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('offNetworkWeakChange');
1788
- const offNetworkStatusChange = callback => {
1789
- networkStatusManager.remove(callback);
1790
- const connection = getConnection();
1791
- if (connection && networkStatusManager.count() === 0) {
1792
- connection.removeEventListener('change', networkStatusListener);
1793
- }
1794
- };
1795
- const getLocalIPAddress = /* @__PURE__ */ temporarilyNotSupport('getLocalIPAddress');
1796
-
1797
- // NFC
1798
- const stopHCE = /* @__PURE__ */ temporarilyNotSupport('stopHCE');
1799
- const startHCE = /* @__PURE__ */ temporarilyNotSupport('startHCE');
1800
- const sendHCEMessage = /* @__PURE__ */ temporarilyNotSupport('sendHCEMessage');
1801
- const onHCEMessage = /* @__PURE__ */ temporarilyNotSupport('onHCEMessage');
1802
- const offHCEMessage = /* @__PURE__ */ temporarilyNotSupport('offHCEMessage');
1803
- const getNFCAdapter = /* @__PURE__ */ temporarilyNotSupport('getNFCAdapter');
1804
- const getHCEState = /* @__PURE__ */ temporarilyNotSupport('getHCEState');
1805
-
1806
- const makePhoneCall = (options) => {
1807
- // options must be an Object
1808
- const isObject = shouldBeObject(options);
1809
- if (!isObject.flag) {
1810
- const res = { errMsg: `makePhoneCall:fail ${isObject.msg}` };
1811
- console.error(res.errMsg);
1812
- return Promise.reject(res);
1813
- }
1814
- const { phoneNumber, success, fail, complete } = options;
1815
- const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete });
1816
- if (typeof phoneNumber !== 'string') {
1817
- return handle.fail({
1818
- errMsg: getParameterError({
1819
- para: 'phoneNumber',
1820
- correct: 'String',
1821
- wrong: phoneNumber
1822
- })
1823
- });
1824
- }
1825
- window.location.href = `tel:${phoneNumber}`;
1826
- return handle.success();
1827
- };
1828
-
1829
- // 扫码
1830
- const scanCode = /* @__PURE__ */ processOpenApi({
1831
- name: 'scanQRCode',
1832
- defaultOptions: { needResult: 1 },
1833
- formatResult: res => ({
1834
- errMsg: res.errMsg === 'scanQRCode:ok' ? 'scanCode:ok' : res.errMsg,
1835
- result: res.resultStr
1836
- })
1837
- });
1838
-
1839
- // 屏幕
1840
- const setVisualEffectOnCapture = /* @__PURE__ */ temporarilyNotSupport('setVisualEffectOnCapture');
1841
- const setScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('setScreenBrightness');
1842
- const setKeepScreenOn = /* @__PURE__ */ temporarilyNotSupport('setKeepScreenOn');
1843
- const onUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('onUserCaptureScreen');
1844
- const offUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('offUserCaptureScreen');
1845
- const getScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('getScreenBrightness');
1846
- const onScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('onScreenRecordingStateChanged');
1847
- const offScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('offScreenRecordingStateChanged');
1848
- const getScreenRecordingState = /* @__PURE__ */ temporarilyNotSupport('getScreenRecordingState');
1849
-
1850
- // 短信
1851
- const sendSms = /* @__PURE__ */ temporarilyNotSupport('sendSms');
1852
-
1853
- const vibrator = function vibrator(mm) {
1854
- try {
1855
- return window.navigator.vibrate(mm);
1856
- }
1857
- catch (e) {
1858
- console.warn('当前浏览器不支持 vibrate。');
1859
- }
1860
- };
1861
- /**
1862
- * 使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
1863
- */
1864
- const vibrateShort = ({ success, fail, complete } = {}) => {
1865
- const handle = new MethodHandler({ name: 'vibrateShort', success, fail, complete });
1866
- if (vibrator(15)) {
1867
- return handle.success();
1868
- }
1869
- else {
1870
- return handle.fail({ errMsg: 'style is not support' });
1871
- }
1872
- };
1873
- /**
1874
- * 使手机发生较长时间的振动(400 ms)
1875
- */
1876
- const vibrateLong = ({ success, fail, complete } = {}) => {
1877
- const handle = new MethodHandler({ name: 'vibrateLong', success, fail, complete });
1878
- if (vibrator(400)) {
1879
- return handle.success();
1880
- }
1881
- else {
1882
- return handle.fail({ errMsg: 'style is not support' });
1883
- }
1884
- };
1885
-
1886
- // Wi-Fi
1887
- const stopWifi = /* @__PURE__ */ temporarilyNotSupport('stopWifi');
1888
- const startWifi = /* @__PURE__ */ temporarilyNotSupport('startWifi');
1889
- const setWifiList = /* @__PURE__ */ temporarilyNotSupport('setWifiList');
1890
- const onWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('onWifiConnectedWithPartialInfo');
1891
- const onWifiConnected = /* @__PURE__ */ temporarilyNotSupport('onWifiConnected');
1892
- const onGetWifiList = /* @__PURE__ */ temporarilyNotSupport('onGetWifiList');
1893
- const offWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('offWifiConnectedWithPartialInfo');
1894
- const offWifiConnected = /* @__PURE__ */ temporarilyNotSupport('offWifiConnected');
1895
- const offGetWifiList = /* @__PURE__ */ temporarilyNotSupport('offGetWifiList');
1896
- const getWifiList = /* @__PURE__ */ temporarilyNotSupport('getWifiList');
1897
- const getConnectedWifi = /* @__PURE__ */ temporarilyNotSupport('getConnectedWifi');
1898
- const connectWifi = /* @__PURE__ */ temporarilyNotSupport('connectWifi');
1899
-
1900
- // 第三方平台
1901
- const getExtConfigSync = /* @__PURE__ */ temporarilyNotSupport('getExtConfigSync');
1902
- const getExtConfig = /* @__PURE__ */ temporarilyNotSupport('getExtConfig');
1903
-
1904
- // 文件
1905
- const saveFileToDisk = /* @__PURE__ */ temporarilyNotSupport('saveFileToDisk');
1906
- const saveFile = /* @__PURE__ */ temporarilyNotSupport('saveFile');
1907
- const removeSavedFile = /* @__PURE__ */ temporarilyNotSupport('removeSavedFile');
1908
- const openDocument = /* @__PURE__ */ temporarilyNotSupport('openDocument');
1909
- const getSavedFileList = /* @__PURE__ */ temporarilyNotSupport('getSavedFileList');
1910
- const getSavedFileInfo = /* @__PURE__ */ temporarilyNotSupport('getSavedFileInfo');
1911
- const getFileSystemManager = /* @__PURE__ */ temporarilyNotSupport('getFileSystemManager');
1912
- const getFileInfo = /* @__PURE__ */ temporarilyNotSupport('getFileInfo');
1913
-
1914
- const getApp = function () {
1915
- return Taro.getCurrentInstance().app;
1916
- };
1917
- // 自定义组件
1918
- const getCurrentInstance = Taro.getCurrentInstance;
1919
-
1920
- const getLocationByW3CApi = (options) => {
1921
- var _a;
1922
- // 断言 options 必须是 Object
1923
- const isObject = shouldBeObject(options);
1924
- if (!isObject.flag) {
1925
- const res = { errMsg: `getLocation:fail ${isObject.msg}` };
1926
- console.error(res.errMsg);
1927
- return Promise.reject(res);
1928
- }
1929
- // 解构回调函数
1930
- const { success, fail, complete } = options;
1931
- const handle = new MethodHandler({ name: 'getLocation', success, fail, complete });
1932
- // const defaultMaximumAge = 5 * 1000
1933
- const positionOptions = {
1934
- enableHighAccuracy: options.isHighAccuracy || (options.altitude != null),
1935
- // maximumAge: defaultMaximumAge, // 允许取多久以内的缓存位置
1936
- timeout: options.highAccuracyExpireTime // 高精度定位超时时间
1937
- };
1938
- // Web端API实现暂时仅支持GPS坐标系
1939
- if (((_a = options.type) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== 'WGS84') {
1940
- return handle.fail({
1941
- errMsg: 'This coordinate system type is not temporarily supported'
1942
- });
1943
- }
1944
- // 判断当前浏览器是否支持位置API
1945
- const geolocationSupported = navigator.geolocation;
1946
- if (!geolocationSupported) {
1947
- return handle.fail({
1948
- errMsg: 'The current browser does not support this feature'
1949
- });
1689
+ class Modal {
1690
+ constructor() {
1691
+ this.options = {
1692
+ title: '',
1693
+ content: '',
1694
+ showCancel: true,
1695
+ cancelText: '取消',
1696
+ cancelColor: '#000000',
1697
+ confirmText: '确定',
1698
+ confirmColor: '#3CC51F'
1699
+ };
1700
+ this.style = {
1701
+ maskStyle: {
1702
+ position: 'fixed',
1703
+ 'z-index': '1000',
1704
+ top: '0',
1705
+ right: '0',
1706
+ left: '0',
1707
+ bottom: '0',
1708
+ background: 'rgba(0,0,0,0.6)'
1709
+ },
1710
+ modalStyle: {
1711
+ 'z-index': '4999',
1712
+ position: 'fixed',
1713
+ top: '50%',
1714
+ left: '50%',
1715
+ transform: 'translate(-50%, -50%)',
1716
+ width: '80%',
1717
+ 'max-width': '300px',
1718
+ 'border-radius': '3px',
1719
+ 'text-align': 'center',
1720
+ 'line-height': '1.6',
1721
+ overflow: 'hidden',
1722
+ background: '#FFFFFF'
1723
+ },
1724
+ titleStyle: {
1725
+ padding: '20px 24px 9px',
1726
+ 'font-size': '18px'
1727
+ },
1728
+ textStyle: {
1729
+ padding: '0 24px 12px',
1730
+ 'min-height': '40px',
1731
+ 'font-size': '15px',
1732
+ 'line-height': '1.3',
1733
+ color: '#808080',
1734
+ 'word-wrap': 'break-word',
1735
+ 'word-break': 'break-all',
1736
+ },
1737
+ footStyle: {
1738
+ position: 'relative',
1739
+ 'line-height': '48px',
1740
+ 'font-size': '18px',
1741
+ display: 'flex'
1742
+ },
1743
+ btnStyle: {
1744
+ position: 'relative',
1745
+ '-webkit-box-flex': '1',
1746
+ '-webkit-flex': '1',
1747
+ flex: '1'
1748
+ }
1749
+ };
1950
1750
  }
1951
- // 开始获取位置
1952
- return new Promise((resolve, reject) => {
1953
- navigator.geolocation.getCurrentPosition((position) => {
1954
- const result = {
1955
- /** 位置的精确度 */
1956
- accuracy: position.coords.accuracy,
1957
- /** 高度,单位 m */
1958
- altitude: position.coords.altitude,
1959
- /** 水平精度,单位 m */
1960
- horizontalAccuracy: position.coords.accuracy,
1961
- /** 纬度,范围为 -90~90,负数表示南纬 */
1962
- latitude: position.coords.latitude,
1963
- /** 经度,范围为 -180~180,负数表示西经 */
1964
- longitude: position.coords.longitude,
1965
- /** 速度,单位 m/s */
1966
- speed: position.coords.speed,
1967
- /** 垂直精度,单位 m(Android 无法获取,返回 0) */
1968
- verticalAccuracy: position.coords.altitudeAccuracy || 0,
1969
- /** 调用结果,自动补充 */
1970
- errMsg: ''
1751
+ create(options = {}) {
1752
+ return new Promise((resolve) => {
1753
+ var _a, _b;
1754
+ // style
1755
+ const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
1756
+ // configuration
1757
+ const config = Object.assign(Object.assign({}, this.options), options);
1758
+ // wrapper
1759
+ this.el = document.createElement('div');
1760
+ this.el.className = 'taro__modal';
1761
+ this.el.style.opacity = '0';
1762
+ this.el.style.transition = 'opacity 0.2s linear';
1763
+ const eventHandler = (e) => {
1764
+ e.stopPropagation();
1765
+ e.preventDefault();
1971
1766
  };
1972
- handle.success(result, { resolve, reject });
1973
- }, (error) => {
1974
- handle.fail({ errMsg: error.message }, { resolve, reject });
1975
- }, positionOptions);
1976
- });
1977
- };
1978
- const getLocation = /* @__PURE__ */ processOpenApi({
1979
- name: 'getLocation',
1980
- standardMethod: getLocationByW3CApi
1981
- });
1982
-
1983
- function styleInject(css, ref) {
1984
- if ( ref === void 0 ) ref = {};
1985
- var insertAt = ref.insertAt;
1986
-
1987
- if (!css || typeof document === 'undefined') { return; }
1988
-
1989
- var head = document.head || document.getElementsByTagName('head')[0];
1990
- var style = document.createElement('style');
1991
- style.type = 'text/css';
1992
-
1993
- if (insertAt === 'top') {
1994
- if (head.firstChild) {
1995
- head.insertBefore(style, head.firstChild);
1996
- } else {
1997
- head.appendChild(style);
1998
- }
1999
- } else {
2000
- head.appendChild(style);
2001
- }
2002
-
2003
- if (style.styleSheet) {
2004
- style.styleSheet.cssText = css;
2005
- } else {
2006
- style.appendChild(document.createTextNode(css));
2007
- }
2008
- }
2009
-
2010
- var css_248z = ".taro_choose_location{background-color:#fff;display:flex;flex-direction:column;height:100%;position:fixed;top:100%;transition:top .3s ease;width:100%;z-index:1}.taro_choose_location_bar{background-color:#ededed;color:#090909;display:flex;flex:0 95px;height:95px}.taro_choose_location_back{flex:0 45px;height:30px;margin-top:30px;position:relative;width:33px}.taro_choose_location_back:before{border:15px solid transparent;border-right-color:#090909;content:\"\";display:block;height:0;left:0;position:absolute;top:0;width:0}.taro_choose_location_back:after{border:15px solid transparent;border-right-color:#ededed;content:\"\";display:block;height:0;left:3px;position:absolute;top:0;width:0}.taro_choose_location_title{flex:1;line-height:95px;padding-left:30px}.taro_choose_location_submit{background-color:#08bf62;border:none;color:#fff;font-size:28px;height:60px;line-height:60px;margin:18px 30px 0 0;padding:0;width:110px}.taro_choose_location_frame{flex:1}";
2011
- var stylesheet=".taro_choose_location{background-color:#fff;display:flex;flex-direction:column;height:100%;position:fixed;top:100%;transition:top .3s ease;width:100%;z-index:1}.taro_choose_location_bar{background-color:#ededed;color:#090909;display:flex;flex:0 95px;height:95px}.taro_choose_location_back{flex:0 45px;height:30px;margin-top:30px;position:relative;width:33px}.taro_choose_location_back:before{border:15px solid transparent;border-right-color:#090909;content:\"\";display:block;height:0;left:0;position:absolute;top:0;width:0}.taro_choose_location_back:after{border:15px solid transparent;border-right-color:#ededed;content:\"\";display:block;height:0;left:3px;position:absolute;top:0;width:0}.taro_choose_location_title{flex:1;line-height:95px;padding-left:30px}.taro_choose_location_submit{background-color:#08bf62;border:none;color:#fff;font-size:28px;height:60px;line-height:60px;margin:18px 30px 0 0;padding:0;width:110px}.taro_choose_location_frame{flex:1}";
2012
- styleInject(css_248z,{"insertAt":"top"});
2013
-
2014
- let container = null;
2015
- function createLocationChooser(handler, key = LOCATION_APIKEY, mapOpt = {}) {
2016
- var _a, _b, _c;
2017
- const { latitude, longitude } = mapOpt, opts = tslib.__rest(mapOpt, ["latitude", "longitude"]);
2018
- const query = Object.assign({ key, type: 1, coord: ((_a = mapOpt.coord) !== null && _a !== void 0 ? _a : [latitude, longitude].every(e => Number(e) >= 0)) ? `${latitude},${longitude}` : undefined, referer: 'myapp' }, opts);
2019
- if (!container) {
2020
- const html = `
2021
- <div class='taro_choose_location'>
2022
- <div class='taro_choose_location_bar'>
2023
- <div class='taro_choose_location_back'></div>
2024
- <p class='taro_choose_location_title'>位置</p>
2025
- <button class='taro_choose_location_submit'>完成</button>
2026
- </div>
2027
- <iframe class='taro_choose_location_frame' frameborder='0' src="https://apis.map.qq.com/tools/locpicker?${queryString.stringify(query, { arrayFormat: 'comma', skipNull: true })}" />
2028
- </div>
2029
- `;
2030
- container = document.createElement('div');
2031
- container.innerHTML = html;
2032
- }
2033
- const main = container.querySelector('.taro_choose_location');
2034
- function show() {
2035
- setTimeout(() => {
2036
- main.style.top = '0';
1767
+ // mask
1768
+ const mask = document.createElement('div');
1769
+ mask.className = 'taro-modal__mask';
1770
+ mask.setAttribute('style', inlineStyle(maskStyle));
1771
+ mask.ontouchmove = eventHandler;
1772
+ // modal
1773
+ const modal = document.createElement('div');
1774
+ modal.className = 'taro-modal__content';
1775
+ modal.setAttribute('style', inlineStyle(modalStyle));
1776
+ modal.ontouchmove = eventHandler;
1777
+ // title
1778
+ const titleCSS = config.title ? titleStyle : Object.assign(Object.assign({}, titleStyle), { display: 'none' });
1779
+ this.title = document.createElement('div');
1780
+ this.title.className = 'taro-modal__title';
1781
+ this.title.setAttribute('style', inlineStyle(titleCSS));
1782
+ this.title.textContent = config.title;
1783
+ // text
1784
+ const textCSS = config.title ? textStyle : Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
1785
+ this.text = document.createElement('div');
1786
+ this.text.className = 'taro-modal__text';
1787
+ this.text.setAttribute('style', inlineStyle(textCSS));
1788
+ this.text.textContent = config.content;
1789
+ // foot
1790
+ const foot = document.createElement('div');
1791
+ foot.className = 'taro-modal__foot';
1792
+ foot.setAttribute('style', inlineStyle(footStyle));
1793
+ // cancel button
1794
+ const cancelCSS = Object.assign(Object.assign({}, btnStyle), { color: config.cancelColor, display: config.showCancel ? 'block' : 'none' });
1795
+ this.cancel = document.createElement('div');
1796
+ this.cancel.className = 'taro-model__btn taro-model__cancel';
1797
+ this.cancel.setAttribute('style', inlineStyle(cancelCSS));
1798
+ this.cancel.textContent = config.cancelText;
1799
+ this.cancel.onclick = () => {
1800
+ this.hide();
1801
+ resolve('cancel');
1802
+ };
1803
+ // confirm button
1804
+ this.confirm = document.createElement('div');
1805
+ this.confirm.className = 'taro-model__btn taro-model__confirm';
1806
+ this.confirm.setAttribute('style', inlineStyle(btnStyle));
1807
+ this.confirm.style.color = config.confirmColor;
1808
+ this.confirm.textContent = config.confirmText;
1809
+ this.confirm.onclick = () => {
1810
+ this.hide();
1811
+ resolve('confirm');
1812
+ };
1813
+ // result
1814
+ foot.appendChild(this.cancel);
1815
+ foot.appendChild(this.confirm);
1816
+ modal.appendChild(this.title);
1817
+ modal.appendChild(this.text);
1818
+ modal.appendChild(foot);
1819
+ this.el.appendChild(mask);
1820
+ this.el.appendChild(modal);
1821
+ // show immediately
1822
+ document.body.appendChild(this.el);
1823
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
1824
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
1825
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
2037
1826
  });
2038
1827
  }
2039
- function hide() {
2040
- main.style.top = '100%';
2041
- }
2042
- function back() {
2043
- hide();
2044
- handler({ errMsg: 'cancel' });
2045
- }
2046
- function submit() {
2047
- hide();
2048
- handler();
2049
- }
2050
- function remove() {
2051
- container === null || container === void 0 ? void 0 : container.remove();
2052
- container = null;
2053
- window.removeEventListener('popstate', back);
2054
- }
2055
- (_b = container.querySelector('.taro_choose_location_back')) === null || _b === void 0 ? void 0 : _b.addEventListener('click', back);
2056
- (_c = container.querySelector('.taro_choose_location_submit')) === null || _c === void 0 ? void 0 : _c.addEventListener('click', submit);
2057
- window.addEventListener('popstate', back);
2058
- return {
2059
- show,
2060
- remove,
2061
- container,
2062
- };
2063
- }
2064
- /**
2065
- * 打开地图选择位置。
2066
- */
2067
- const chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
2068
- const key = LOCATION_APIKEY;
2069
- const handle = new MethodHandler({ name: 'chooseLocation', success, fail, complete });
2070
- return new Promise((resolve, reject) => {
2071
- const chooseLocation = {};
2072
- if (!key) {
2073
- console.warn('chooseLocation api 依赖腾讯地图定位api,需要在 defineConstants 中配置 LOCATION_APIKEY');
2074
- return handle.fail({
2075
- errMsg: 'LOCATION_APIKEY needed'
2076
- }, { resolve, reject });
2077
- }
2078
- const onMessage = event => {
2079
- // 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
2080
- const loc = event.data;
2081
- // 防止其他应用也会向该页面 post 信息,需判断 module 是否为'locationPicker'
2082
- if (!loc || loc.module !== 'locationPicker')
2083
- return;
2084
- chooseLocation.name = loc.poiname;
2085
- chooseLocation.address = loc.poiaddress;
2086
- chooseLocation.latitude = loc.latlng.lat;
2087
- chooseLocation.longitude = loc.latlng.lng;
2088
- };
2089
- const chooser = createLocationChooser(res => {
2090
- window.removeEventListener('message', onMessage, false);
2091
- setTimeout(() => {
2092
- chooser.remove();
2093
- }, 300);
2094
- if (res) {
2095
- return handle.fail(res, { resolve, reject });
2096
- }
2097
- else {
2098
- if (chooseLocation.latitude && chooseLocation.longitude) {
2099
- return handle.success(chooseLocation, { resolve, reject });
2100
- }
2101
- else {
2102
- return handle.fail({}, { resolve, reject });
2103
- }
1828
+ show(options = {}) {
1829
+ return new Promise((resolve) => {
1830
+ var _a, _b;
1831
+ const config = Object.assign(Object.assign({}, this.options), options);
1832
+ if (this.hideOpacityTimer)
1833
+ clearTimeout(this.hideOpacityTimer);
1834
+ if (this.hideDisplayTimer)
1835
+ clearTimeout(this.hideDisplayTimer);
1836
+ // title & text
1837
+ const { textStyle } = this.style;
1838
+ if (config.title) {
1839
+ this.title.textContent = config.title;
1840
+ // none => block
1841
+ this.title.style.display = 'block';
1842
+ this.text.setAttribute('style', inlineStyle(textStyle));
2104
1843
  }
2105
- }, key, mapOpts);
2106
- document.body.appendChild(chooser.container);
2107
- window.addEventListener('message', onMessage, false);
2108
- chooser.show();
2109
- });
2110
- };
2111
-
2112
- // 位置
2113
- const stopLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('stopLocationUpdate');
2114
- const startLocationUpdateBackground = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdateBackground');
2115
- const startLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdate');
2116
- const openLocation = /* @__PURE__ */ processOpenApi({
2117
- name: 'openLocation',
2118
- defaultOptions: { scale: 18 }
2119
- });
2120
- const onLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('onLocationChangeError');
2121
- const onLocationChange = /* @__PURE__ */ temporarilyNotSupport('onLocationChange');
2122
- const offLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('offLocationChangeError');
2123
- const offLocationChange = /* @__PURE__ */ temporarilyNotSupport('offLocationChange');
2124
- const choosePoi = /* @__PURE__ */ temporarilyNotSupport('choosePoi');
2125
- const getFuzzyLocation = /* @__PURE__ */ temporarilyNotSupport('getFuzzyLocation');
1844
+ else {
1845
+ this.title.textContent = '';
1846
+ // block => none
1847
+ this.title.style.display = 'none';
1848
+ const textCSS = Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
1849
+ this.text.setAttribute('style', inlineStyle(textCSS));
1850
+ }
1851
+ this.text.textContent = config.content || '';
1852
+ // showCancel
1853
+ this.cancel.style.display = config.showCancel ? 'block' : 'none';
1854
+ // cancelText
1855
+ this.cancel.textContent = config.cancelText || '';
1856
+ // cancelColor
1857
+ this.cancel.style.color = config.cancelColor || '';
1858
+ // confirmText
1859
+ this.confirm.textContent = config.confirmText || '';
1860
+ // confirmColor
1861
+ this.confirm.style.color = config.confirmColor || '';
1862
+ // cbs
1863
+ this.cancel.onclick = () => {
1864
+ this.hide();
1865
+ resolve('cancel');
1866
+ };
1867
+ this.confirm.onclick = () => {
1868
+ this.hide();
1869
+ resolve('confirm');
1870
+ };
1871
+ // show
1872
+ this.el.style.display = 'block';
1873
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
1874
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
1875
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
1876
+ });
1877
+ }
1878
+ hide() {
1879
+ if (this.hideOpacityTimer)
1880
+ clearTimeout(this.hideOpacityTimer);
1881
+ if (this.hideDisplayTimer)
1882
+ clearTimeout(this.hideDisplayTimer);
1883
+ this.currentPath = null;
1884
+ this.hideOpacityTimer = setTimeout(() => {
1885
+ this.el.style.opacity = '0';
1886
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
1887
+ }, 0);
1888
+ }
1889
+ }
2126
1890
 
2127
- class InnerAudioContext {
1891
+ class Toast {
2128
1892
  constructor() {
2129
- this.__startTime = 0;
2130
- this.__isFirstPlay = true;
2131
- this.play = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.play(); };
2132
- this.pause = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.pause(); };
2133
- this.stop = () => {
2134
- this.pause();
2135
- this.seek(0);
2136
- this.stopStack.trigger();
1893
+ this.options = {
1894
+ title: '',
1895
+ icon: 'none',
1896
+ image: '',
1897
+ duration: 1500,
1898
+ mask: false
2137
1899
  };
2138
- this.seek = (position) => {
2139
- if (this.Instance) {
2140
- this.Instance.currentTime = position;
1900
+ this.style = {
1901
+ maskStyle: {
1902
+ position: 'fixed',
1903
+ 'z-index': '1000',
1904
+ top: '0',
1905
+ right: '0',
1906
+ left: '0',
1907
+ bottom: '0'
1908
+ },
1909
+ toastStyle: {
1910
+ 'z-index': '5000',
1911
+ 'box-sizing': 'border-box',
1912
+ display: 'flex',
1913
+ 'flex-direction': 'column',
1914
+ 'justify-content': 'center',
1915
+ '-webkit-justify-content': 'center',
1916
+ position: 'fixed',
1917
+ top: '50%',
1918
+ left: '50%',
1919
+ 'min-width': '120px',
1920
+ 'max-width': '200px',
1921
+ 'min-height': '120px',
1922
+ padding: '15px',
1923
+ transform: 'translate(-50%, -50%)',
1924
+ 'border-radius': '5px',
1925
+ 'text-align': 'center',
1926
+ 'line-height': '1.6',
1927
+ color: '#FFFFFF',
1928
+ background: 'rgba(17, 17, 17, 0.7)'
1929
+ },
1930
+ successStyle: {
1931
+ margin: '6px auto',
1932
+ width: '38px',
1933
+ height: '38px',
1934
+ background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTQ4OTYzMjA0IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjQzNDgiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNMjE5Ljk1MiA1MTIuNTc2bDIxMC40MzIgMjEwLjQzMi00NS4yNDggNDUuMjU2LTIxMC40MzItMjEwLjQzMnoiIHAtaWQ9IjQzNDkiIGZpbGw9IiNmZmZmZmYiPjwvcGF0aD48cGF0aCBkPSJNNzk5LjY3MiAyNjIuMjY0bDQ1LjI1NiA0NS4yNTYtNDYwLjQ2NCA0NjAuNDY0LTQ1LjI1Ni00NS4yNTZ6IiBwLWlkPSI0MzUwIiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
1935
+ 'background-size': '100%'
1936
+ },
1937
+ errrorStyle: {
1938
+ margin: '6px auto',
1939
+ width: '38px',
1940
+ height: '38px',
1941
+ background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTUxMDU1MTgzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjE0MDc2IiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PHBhdGggZD0iTTUxMiA2NEMyNjQuNTggNjQgNjQgMjY0LjU4IDY0IDUxMnMyMDAuNTggNDQ4IDQ0OCA0NDggNDQ4LTIwMC41OCA0NDgtNDQ4Uzc1OS40MiA2NCA1MTIgNjR6IG0wIDc1MmEzNiAzNiAwIDEgMSAzNi0zNiAzNiAzNiAwIDAgMS0zNiAzNnogbTUxLjgzLTU1MS45NUw1NDggNjM2YTM2IDM2IDAgMCAxLTcyIDBsLTE1LjgzLTM3MS45NWMtMC4xLTEuMzMtMC4xNy0yLjY4LTAuMTctNC4wNWE1MiA1MiAwIDAgMSAxMDQgMGMwIDEuMzctMC4wNyAyLjcyLTAuMTcgNC4wNXoiIHAtaWQ9IjE0MDc3IiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
1942
+ 'background-size': '100%'
1943
+ },
1944
+ loadingStyle: {
1945
+ margin: '6px auto',
1946
+ width: '38px',
1947
+ height: '38px',
1948
+ '-webkit-animation': 'taroLoading 1s steps(12, end) infinite',
1949
+ animation: 'taroLoading 1s steps(12, end) infinite',
1950
+ background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iMTIwIiB2aWV3Qm94PSIwIDAgMTAwIDEwMCI+PHBhdGggZmlsbD0ibm9uZSIgZD0iTTAgMGgxMDB2MTAwSDB6Ii8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTlFOUU5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTMwKSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iIzk4OTY5NyIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgzMCAxMDUuOTggNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjOUI5OTlBIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDYwIDc1Ljk4IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0EzQTFBMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSg5MCA2NSA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNBQkE5QUEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoMTIwIDU4LjY2IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0IyQjJCMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgxNTAgNTQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjQkFCOEI5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDE4MCA1MCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDMkMwQzEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTE1MCA0NS45OCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDQkNCQ0IiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTEyMCA0MS4zNCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNEMkQyRDIiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTkwIDM1IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0RBREFEQSIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgtNjAgMjQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTJFMkUyIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKC0zMCAtNS45OCA2NSkiLz48L3N2Zz4=) no-repeat',
1951
+ 'background-size': '100%'
1952
+ },
1953
+ imageStyle: {
1954
+ margin: '6px auto',
1955
+ width: '40px',
1956
+ height: '40px',
1957
+ background: 'transparent no-repeat',
1958
+ 'background-size': '100%'
1959
+ },
1960
+ textStyle: {
1961
+ margin: '0',
1962
+ 'font-size': '16px'
2141
1963
  }
2142
1964
  };
2143
- /**
2144
- * @TODO destroy得并不干净
2145
- */
2146
- this.destroy = () => {
2147
- this.stop();
2148
- if (this.Instance) {
2149
- this.Instance = undefined;
2150
- }
1965
+ }
1966
+ create(options = {}, _type = 'toast') {
1967
+ var _a, _b;
1968
+ // style
1969
+ const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style;
1970
+ // configuration
1971
+ const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
1972
+ // wrapper
1973
+ this.el = document.createElement('div');
1974
+ this.el.className = 'taro__toast';
1975
+ this.el.style.opacity = '0';
1976
+ this.el.style.transition = 'opacity 0.1s linear';
1977
+ this.el.ontouchmove = (e) => {
1978
+ e.stopPropagation();
1979
+ e.preventDefault();
2151
1980
  };
2152
- this.onCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', callback); };
2153
- this.onPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('play', callback); };
2154
- this.onPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('pause', callback); };
2155
- this.onStop = (callback = () => { }) => this.stopStack.add(callback);
2156
- this.onEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', callback); };
2157
- this.onTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('timeupdate', callback); };
2158
- this.onError = (callback) => this.errorStack.add(callback);
2159
- this.onWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('waiting', callback); };
2160
- this.onSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeking', callback); };
2161
- this.onSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeked', callback); };
2162
- this.offCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', callback); };
2163
- this.offPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('play', callback); };
2164
- this.offPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('pause', callback); };
2165
- this.offStop = (callback = () => { }) => this.stopStack.remove(callback);
2166
- this.offEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', callback); };
2167
- this.offTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('timeupdate', callback); };
2168
- this.offError = (callback = () => { }) => this.errorStack.remove(callback);
2169
- this.offWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('waiting', callback); };
2170
- this.offSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeking', callback); };
2171
- this.offSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeked', callback); };
2172
- this.Instance = new Audio();
2173
- this.errorStack = new CallbackManager();
2174
- this.stopStack = new CallbackManager();
2175
- this.Instance.onerror = this.errorStack.trigger;
2176
- Taro.eventCenter.on('__taroRouterChange', () => { this.stop(); });
2177
- this.onPlay(() => {
2178
- if (this.__isFirstPlay) {
2179
- this.__isFirstPlay = false;
2180
- this.seek(this.startTime);
2181
- }
2182
- });
1981
+ // mask
1982
+ this.mask = document.createElement('div');
1983
+ this.mask.setAttribute('style', inlineStyle(maskStyle));
1984
+ this.mask.style.display = config.mask ? 'block' : 'none';
1985
+ // icon
1986
+ this.icon = document.createElement('p');
1987
+ if (config.image) {
1988
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, imageStyle), { 'background-image': `url(${config.image})` })));
1989
+ }
1990
+ else {
1991
+ const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
1992
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, iconStyle), (config.icon === 'none' ? { display: 'none' } : {}))));
1993
+ }
1994
+ // toast
1995
+ this.toast = document.createElement('div');
1996
+ this.toast.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, toastStyle), (config.icon === 'none' ? {
1997
+ 'min-height': '0',
1998
+ padding: '10px 15px'
1999
+ } : {}))));
2000
+ // title
2001
+ this.title = document.createElement('p');
2002
+ this.title.setAttribute('style', inlineStyle(textStyle));
2003
+ this.title.textContent = config.title;
2004
+ // result
2005
+ this.toast.appendChild(this.icon);
2006
+ this.toast.appendChild(this.title);
2007
+ this.el.appendChild(this.mask);
2008
+ this.el.appendChild(this.toast);
2009
+ // show immediately
2010
+ document.body.appendChild(this.el);
2011
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
2012
+ this.type = config._type;
2013
+ // disappear after duration
2014
+ config.duration >= 0 && this.hide(config.duration, this.type);
2015
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
2016
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
2017
+ return '';
2183
2018
  }
2184
- set autoplay(e) { this.setProperty('autoplay', e); }
2185
- get autoplay() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.autoplay) || false; }
2186
- get buffered() {
2187
- const { currentTime = 0, buffered: timeRange } = this.Instance || {};
2188
- if (timeRange) {
2189
- for (let i = 0; i < timeRange.length; i++) {
2190
- if (timeRange.start(i) <= currentTime && timeRange.end(i) >= currentTime) {
2191
- return timeRange.end(i);
2192
- }
2019
+ show(options = {}, _type = 'toast') {
2020
+ var _a, _b;
2021
+ const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
2022
+ if (this.hideOpacityTimer)
2023
+ clearTimeout(this.hideOpacityTimer);
2024
+ if (this.hideDisplayTimer)
2025
+ clearTimeout(this.hideDisplayTimer);
2026
+ // title
2027
+ this.title.textContent = config.title || '';
2028
+ // mask
2029
+ this.mask.style.display = config.mask ? 'block' : 'none';
2030
+ // image
2031
+ const { toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle } = this.style;
2032
+ if (config.image) {
2033
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, imageStyle), { 'background-image': `url(${config.image})` })));
2034
+ }
2035
+ else {
2036
+ if (!config.image && config.icon) {
2037
+ const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
2038
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, iconStyle), (config.icon === 'none' ? { display: 'none' } : {}))));
2193
2039
  }
2194
2040
  }
2195
- return 0;
2041
+ // toast
2042
+ this.toast.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, toastStyle), (config.icon === 'none' ? {
2043
+ 'min-height': '0',
2044
+ padding: '10px 15px'
2045
+ } : {}))));
2046
+ // show
2047
+ this.el.style.display = 'block';
2048
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
2049
+ this.type = config._type;
2050
+ // disappear after duration
2051
+ config.duration >= 0 && this.hide(config.duration, this.type);
2052
+ // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
2053
+ this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
2054
+ return '';
2196
2055
  }
2197
- get currentTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.currentTime) || 0; }
2198
- set currentTime(e) { this.seek(e); }
2199
- get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
2200
- set loop(e) { this.setProperty('loop', e); }
2201
- get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
2202
- get paused() { var _a, _b; return (_b = (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : true; }
2203
- set src(e) { this.setProperty('src', e); }
2204
- get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
2205
- set volume(e) { this.setProperty('volume', e); }
2206
- get volume() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.volume) || 0; }
2207
- set playbackRate(e) { this.setProperty('playbackRate', e); }
2208
- get playbackRate() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.playbackRate) || 0; }
2209
- set obeyMuteSwitch(_e) { permanentlyNotSupport('InnerAudioContext.obeyMuteSwitch')(); }
2210
- get obeyMuteSwitch() { return true; }
2211
- set startTime(e) { this.__startTime = e; }
2212
- get startTime() { return this.__startTime || 0; }
2213
- set referrerPolicy(e) { var _a; (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.setAttribute('referrerpolicy', e); }
2214
- get referrerPolicy() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.getAttribute('referrerpolicy')) || 'origin'; }
2215
- setProperty(key, value) {
2216
- if (this.Instance) {
2217
- this.Instance[key] = value;
2218
- }
2056
+ hide(duration = 0, type = '') {
2057
+ if (type && type !== this.type)
2058
+ return;
2059
+ if (this.hideOpacityTimer)
2060
+ clearTimeout(this.hideOpacityTimer);
2061
+ if (this.hideDisplayTimer)
2062
+ clearTimeout(this.hideDisplayTimer);
2063
+ this.currentPath = null;
2064
+ this.hideOpacityTimer = setTimeout(() => {
2065
+ this.el.style.opacity = '0';
2066
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 100);
2067
+ }, duration);
2219
2068
  }
2220
2069
  }
2221
2070
 
2222
- // 音频
2223
- const stopVoice = /* @__PURE__ */ temporarilyNotSupport('stopVoice');
2224
- const setInnerAudioOption = /* @__PURE__ */ temporarilyNotSupport('setInnerAudioOption');
2225
- const playVoice = /* @__PURE__ */ temporarilyNotSupport('playVoice');
2226
- const pauseVoice = /* @__PURE__ */ temporarilyNotSupport('pauseVoice');
2227
- const getAvailableAudioSources = /* @__PURE__ */ temporarilyNotSupport('getAvailableAudioSources');
2228
- const createWebAudioContext = /* @__PURE__ */ temporarilyNotSupport('createWebAudioContext');
2229
- const createMediaAudioPlayer = /* @__PURE__ */ temporarilyNotSupport('createMediaAudioPlayer');
2230
- /**
2231
- * 创建内部 audio 上下文 InnerAudioContext 对象。
2232
- */
2233
- const createInnerAudioContext = () => new InnerAudioContext();
2234
- const createAudioContext = /* @__PURE__ */ temporarilyNotSupport('createAudioContext');
2235
-
2236
- class BackgroundAudioManager {
2237
- constructor() {
2238
- this.__startTime = 0;
2239
- this.play = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.play(); };
2240
- this.pause = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.pause(); };
2241
- this.seek = (position) => {
2242
- if (this.Instance) {
2243
- this.Instance.currentTime = position;
2244
- }
2245
- };
2246
- this.stop = () => {
2247
- this.pause();
2248
- this.seek(0);
2249
- this.stopStack.trigger();
2250
- };
2251
- this.onCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', callback); };
2252
- this.onWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('waiting', callback); };
2253
- this.onError = (callback) => this.errorStack.add(callback);
2254
- this.onPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('play', callback); };
2255
- this.onPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('pause', callback); };
2256
- this.onSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeking', callback); };
2257
- this.onSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeked', callback); };
2258
- this.onEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', callback); };
2259
- this.onStop = (callback = () => { }) => this.stopStack.add(callback);
2260
- this.onTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('timeupdate', callback); };
2261
- this.onPrev = permanentlyNotSupport('BackgroundAudioManager.onPrev');
2262
- this.onNext = permanentlyNotSupport('BackgroundAudioManager.onNext');
2263
- this.offCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', callback); };
2264
- this.offWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('waiting', callback); };
2265
- this.offError = (callback = () => { }) => this.errorStack.remove(callback);
2266
- this.offPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('play', callback); };
2267
- this.offPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('pause', callback); };
2268
- this.offSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeking', callback); };
2269
- this.offSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeked', callback); };
2270
- this.offEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', callback); };
2271
- this.offStop = (callback = () => { }) => this.stopStack.remove(callback);
2272
- this.offTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('timeupdate', callback); };
2273
- this.offPrev = permanentlyNotSupport('BackgroundAudioManager.offPrev');
2274
- this.offNext = permanentlyNotSupport('BackgroundAudioManager.offNext');
2275
- this.Instance = new Audio();
2276
- this.errorStack = new CallbackManager();
2277
- this.stopStack = new CallbackManager();
2278
- this.Instance.onerror = this.errorStack.trigger;
2279
- this.Instance.autoplay = true;
2280
- this.onPlay(() => {
2281
- if (this.currentTime !== this.startTime) {
2282
- this.seek(this.startTime);
2283
- }
2071
+ // 交互
2072
+ let status = 'default';
2073
+ // inject necessary style
2074
+ function init(doc) {
2075
+ if (status === 'ready')
2076
+ return;
2077
+ const taroStyle = doc.createElement('style');
2078
+ taroStyle.textContent =
2079
+ '@font-face{font-weight:normal;font-style:normal;font-family:"taro";src:url("data:application/x-font-ttf;charset=utf-8;base64, AAEAAAALAIAAAwAwR1NVQrD+s+0AAAE4AAAAQk9TLzJWs0t/AAABfAAAAFZjbWFwqVgGvgAAAeAAAAGGZ2x5Zph7qG0AAANwAAAAdGhlYWQRFoGhAAAA4AAAADZoaGVhCCsD7AAAALwAAAAkaG10eAg0AAAAAAHUAAAADGxvY2EADAA6AAADaAAAAAhtYXhwAQ4AJAAAARgAAAAgbmFtZYrphEEAAAPkAAACVXBvc3S3shtSAAAGPAAAADUAAQAAA+gAAABaA+gAAAAAA+gAAQAAAAAAAAAAAAAAAAAAAAMAAQAAAAEAAADih+FfDzz1AAsD6AAAAADXB57LAAAAANcHnssAAP/sA+gDOgAAAAgAAgAAAAAAAAABAAAAAwAYAAEAAAAAAAIAAAAKAAoAAAD/AAAAAAAAAAEAAAAKAB4ALAABREZMVAAIAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAAAAQK8AZAABQAIAnoCvAAAAIwCegK8AAAB4AAxAQIAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABAAHjqCAPoAAAAWgPoABQAAAABAAAAAAAAA+gAAABkAAAD6AAAAAAABQAAAAMAAAAsAAAABAAAAV4AAQAAAAAAWAADAAEAAAAsAAMACgAAAV4ABAAsAAAABgAEAAEAAgB46gj//wAAAHjqCP//AAAAAAABAAYABgAAAAEAAgAAAQYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAKAAAAAAAAAACAAAAeAAAAHgAAAABAADqCAAA6ggAAAACAAAAAAAAAAwAOgABAAD/7AAyABQAAgAANzMVFB4UKAAAAAABAAAAAAO7AzoAFwAAEy4BPwE+AR8BFjY3ATYWFycWFAcBBiInPQoGBwUHGgzLDCELAh0LHwsNCgr9uQoeCgGzCyEOCw0HCZMJAQoBvgkCCg0LHQv9sQsKAAAAAAAAEgDeAAEAAAAAAAAAHQAAAAEAAAAAAAEABAAdAAEAAAAAAAIABwAhAAEAAAAAAAMABAAoAAEAAAAAAAQABAAsAAEAAAAAAAUACwAwAAEAAAAAAAYABAA7AAEAAAAAAAoAKwA/AAEAAAAAAAsAEwBqAAMAAQQJAAAAOgB9AAMAAQQJAAEACAC3AAMAAQQJAAIADgC/AAMAAQQJAAMACADNAAMAAQQJAAQACADVAAMAAQQJAAUAFgDdAAMAAQQJAAYACADzAAMAAQQJAAoAVgD7AAMAAQQJAAsAJgFRCiAgQ3JlYXRlZCBieSBmb250LWNhcnJpZXIKICB3ZXVpUmVndWxhcndldWl3ZXVpVmVyc2lvbiAxLjB3ZXVpR2VuZXJhdGVkIGJ5IHN2ZzJ0dGYgZnJvbSBGb250ZWxsbyBwcm9qZWN0Lmh0dHA6Ly9mb250ZWxsby5jb20ACgAgACAAQwByAGUAYQB0AGUAZAAgAGIAeQAgAGYAbwBuAHQALQBjAGEAcgByAGkAZQByAAoAIAAgAHcAZQB1AGkAUgBlAGcAdQBsAGEAcgB3AGUAdQBpAHcAZQB1AGkAVgBlAHIAcwBpAG8AbgAgADEALgAwAHcAZQB1AGkARwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABzAHYAZwAyAHQAdABmACAAZgByAG8AbQAgAEYAbwBuAHQAZQBsAGwAbwAgAHAAcgBvAGoAZQBjAHQALgBoAHQAdABwADoALwAvAGYAbwBuAHQAZQBsAGwAbwAuAGMAbwBtAAAAAAIAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwECAQMBBAABeAd1bmlFQTA4AAAAAAA=") format("truetype");}@-webkit-keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}@keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}.taro-modal__foot:after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);} .taro-model__btn:active {background-color: #EEEEEE}.taro-model__btn:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;width: 1px;bottom: 0;border-left: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleX(0.5);transform: scaleX(0.5);}.taro-actionsheet__cell:not(:last-child):after {content: "";position: absolute;left: 0;bottom: 0;right: 0;height: 1px;border-top: 1px solid #e5e5e5;color: #e5e5e5;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}';
2080
+ doc.querySelector('head').appendChild(taroStyle);
2081
+ status = 'ready';
2082
+ }
2083
+ const toast = new Toast();
2084
+ const modal = new Modal();
2085
+ const actionSheet = new ActionSheet();
2086
+ const showToast = (options = { title: '' }) => {
2087
+ init(document);
2088
+ options = Object.assign({
2089
+ title: '',
2090
+ icon: 'success',
2091
+ image: '',
2092
+ duration: 1500,
2093
+ mask: false
2094
+ }, options);
2095
+ const { success, fail, complete } = options;
2096
+ const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
2097
+ if (typeof options.title !== 'string') {
2098
+ return handle.fail({
2099
+ errMsg: getParameterError({
2100
+ para: 'title',
2101
+ correct: 'String',
2102
+ wrong: options.title
2103
+ })
2104
+ });
2105
+ }
2106
+ if (typeof options.duration !== 'number') {
2107
+ return handle.fail({
2108
+ errMsg: getParameterError({
2109
+ para: 'duration',
2110
+ correct: 'Number',
2111
+ wrong: options.duration
2112
+ })
2113
+ });
2114
+ }
2115
+ if (options.image && typeof options.image !== 'string')
2116
+ options.image = '';
2117
+ options.mask = !!options.mask;
2118
+ let errMsg = '';
2119
+ if (!toast.el) {
2120
+ errMsg = toast.create(options, 'toast');
2121
+ }
2122
+ else {
2123
+ errMsg = toast.show(options, 'toast');
2124
+ }
2125
+ return handle.success({ errMsg });
2126
+ };
2127
+ const hideToast = ({ noConflict = false, success, fail, complete } = {}) => {
2128
+ const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
2129
+ if (!toast.el)
2130
+ return handle.success();
2131
+ toast.hide(0, noConflict ? 'toast' : '');
2132
+ return handle.success();
2133
+ };
2134
+ const showLoading = (options = { title: '' }) => {
2135
+ init(document);
2136
+ options = Object.assign({
2137
+ title: '',
2138
+ mask: false
2139
+ }, options);
2140
+ const { success, fail, complete } = options;
2141
+ const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
2142
+ const config = {
2143
+ icon: 'loading',
2144
+ image: '',
2145
+ duration: -1
2146
+ };
2147
+ options = Object.assign({}, options, config);
2148
+ if (typeof options.title !== 'string') {
2149
+ return handle.fail({
2150
+ errMsg: getParameterError({
2151
+ para: 'title',
2152
+ correct: 'String',
2153
+ wrong: options.title
2154
+ })
2155
+ });
2156
+ }
2157
+ options.mask = !!options.mask;
2158
+ let errMsg = '';
2159
+ if (!toast.el) {
2160
+ errMsg = toast.create(options, 'loading');
2161
+ }
2162
+ else {
2163
+ errMsg = toast.show(options, 'loading');
2164
+ }
2165
+ return handle.success({ errMsg });
2166
+ };
2167
+ const hideLoading = ({ noConflict = false, success, fail, complete } = {}) => {
2168
+ const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
2169
+ if (!toast.el)
2170
+ return handle.success();
2171
+ toast.hide(0, noConflict ? 'loading' : '');
2172
+ return handle.success();
2173
+ };
2174
+ const showModal = (options = {}) => tslib.__awaiter(void 0, void 0, void 0, function* () {
2175
+ init(document);
2176
+ options = Object.assign({
2177
+ title: '',
2178
+ content: '',
2179
+ showCancel: true,
2180
+ cancelText: '取消',
2181
+ cancelColor: '#000000',
2182
+ confirmText: '确定',
2183
+ confirmColor: '#3CC51F'
2184
+ }, options);
2185
+ const { success, fail, complete } = options;
2186
+ const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
2187
+ if (typeof options.title !== 'string') {
2188
+ return handle.fail({
2189
+ errMsg: getParameterError({
2190
+ para: 'title',
2191
+ correct: 'String',
2192
+ wrong: options.title
2193
+ })
2194
+ });
2195
+ }
2196
+ if (typeof options.content !== 'string') {
2197
+ return handle.fail({
2198
+ errMsg: getParameterError({
2199
+ para: 'content',
2200
+ correct: 'String',
2201
+ wrong: options.content
2202
+ })
2203
+ });
2204
+ }
2205
+ if (typeof options.cancelText !== 'string') {
2206
+ return handle.fail({
2207
+ errMsg: getParameterError({
2208
+ para: 'cancelText',
2209
+ correct: 'String',
2210
+ wrong: options.cancelText
2211
+ })
2284
2212
  });
2285
2213
  }
2286
- set src(e) { this.setProperty('src', e); }
2287
- get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
2288
- set startTime(e) { this.__startTime = e; }
2289
- get startTime() { return this.__startTime || 0; }
2290
- set title(e) { this.dataset('title', e); }
2291
- get title() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.title) || ''; }
2292
- set epname(e) { this.dataset('epname', e); }
2293
- get epname() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.epname) || ''; }
2294
- set singer(e) { this.dataset('singer', e); }
2295
- get singer() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.singer) || ''; }
2296
- set coverImgUrl(e) { this.dataset('coverImgUrl', e); }
2297
- get coverImgUrl() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.coverImgUrl) || ''; }
2298
- set webUrl(e) { this.dataset('webUrl', e); }
2299
- get webUrl() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.webUrl) || ''; }
2300
- set protocol(e) { this.dataset('protocol', e); }
2301
- get protocol() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.protocol) || ''; }
2302
- set playbackRate(e) { this.setProperty('playbackRate', e); }
2303
- get playbackRate() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.playbackRate) || 0; }
2304
- get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
2305
- get currentTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.currentTime) || 0; }
2306
- get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || false; }
2307
- get buffered() {
2308
- const { currentTime = 0, buffered: timeRange } = this.Instance || {};
2309
- if (timeRange) {
2310
- for (let i = 0; i < timeRange.length; i++) {
2311
- if (timeRange.start(i) <= currentTime && timeRange.end(i) >= currentTime) {
2312
- return timeRange.end(i);
2313
- }
2314
- }
2315
- }
2316
- return 0;
2214
+ if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
2215
+ return handle.fail({
2216
+ errMsg: 'cancelText length should not larger then 4 Chinese characters'
2217
+ });
2317
2218
  }
2318
- set referrerPolicy(e) { var _a; (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.setAttribute('referrerpolicy', e); }
2319
- get referrerPolicy() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.getAttribute('referrerpolicy')) || 'origin'; }
2320
- setProperty(key, value) {
2321
- if (this.Instance) {
2322
- this.Instance[key] = value;
2323
- }
2219
+ if (typeof options.confirmText !== 'string') {
2220
+ return handle.fail({
2221
+ errMsg: getParameterError({
2222
+ para: 'confirmText',
2223
+ correct: 'String',
2224
+ wrong: options.confirmText
2225
+ })
2226
+ });
2324
2227
  }
2325
- dataset(key, value) {
2326
- if (this.Instance) {
2327
- this.Instance.dataset[key] = value;
2328
- }
2228
+ if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
2229
+ return handle.fail({
2230
+ errMsg: 'confirmText length should not larger then 4 Chinese characters'
2231
+ });
2329
2232
  }
2330
- }
2331
-
2332
- // 背景音频
2333
- const stopBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('stopBackgroundAudio');
2334
- const seekBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('seekBackgroundAudio');
2335
- const playBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('playBackgroundAudio');
2336
- const pauseBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('pauseBackgroundAudio');
2337
- const onBackgroundAudioStop = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioStop');
2338
- const onBackgroundAudioPlay = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioPlay');
2339
- const onBackgroundAudioPause = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioPause');
2340
- const getBackgroundAudioPlayerState = /* @__PURE__ */ temporarilyNotSupport('getBackgroundAudioPlayerState');
2341
- /**
2342
- * 获取全局唯一的背景音频管理器
2343
- */
2344
- const getBackgroundAudioManager = () => new BackgroundAudioManager();
2345
-
2346
- // 相机
2347
- const createCameraContext = /* @__PURE__ */ temporarilyNotSupport('createCameraContext');
2348
-
2349
- const saveImageToPhotosAlbum = (options) => {
2350
- const methodName = 'saveImageToPhotosAlbum';
2351
- // options must be an Object
2352
- const isObject = shouldBeObject(options);
2353
- if (!isObject.flag) {
2354
- const res = { errMsg: `${methodName}:fail ${isObject.msg}` };
2355
- console.error(res.errMsg);
2356
- return Promise.reject(res);
2233
+ if (typeof options.cancelColor !== 'string') {
2234
+ return handle.fail({
2235
+ errMsg: getParameterError({
2236
+ para: 'cancelColor',
2237
+ correct: 'String',
2238
+ wrong: options.cancelColor
2239
+ })
2240
+ });
2357
2241
  }
2358
- const { filePath, success, fail, complete, } = options;
2359
- const handle = new MethodHandler({ name: methodName, success, fail, complete });
2360
- if (typeof filePath !== 'string') {
2242
+ if (typeof options.confirmColor !== 'string') {
2361
2243
  return handle.fail({
2362
2244
  errMsg: getParameterError({
2363
- para: 'filePath',
2245
+ para: 'confirmColor',
2364
2246
  correct: 'String',
2365
- wrong: filePath
2247
+ wrong: options.confirmColor
2366
2248
  })
2367
2249
  });
2368
2250
  }
2369
- createDownload(filePath);
2370
- return handle.success();
2371
- };
2372
-
2373
- /**
2374
- * 获取图片信息。网络图片需先配置download域名才能生效。
2375
- */
2376
- const getImageInfo = (options) => {
2377
- // options must be an Object
2378
- const isObject = shouldBeObject(options);
2379
- if (!isObject.flag) {
2380
- const res = { errMsg: `getImageInfo:fail ${isObject.msg}` };
2381
- console.error(res.errMsg);
2382
- return Promise.reject(res);
2251
+ options.showCancel = !!options.showCancel;
2252
+ let result = '';
2253
+ if (!modal.el) {
2254
+ result = yield modal.create(options);
2383
2255
  }
2384
- const getBase64Image = (image) => {
2385
- try {
2386
- const canvas = document.createElement('canvas');
2387
- canvas.width = image.width;
2388
- canvas.height = image.height;
2389
- const ctx = canvas.getContext('2d');
2390
- ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(image, 0, 0, image.width, image.height);
2391
- return canvas.toDataURL('image/png');
2392
- }
2393
- catch (e) {
2394
- console.error('getImageInfo:get base64 fail', e);
2395
- }
2396
- };
2397
- const { src, success, fail, complete } = options;
2398
- const handle = new MethodHandler({ name: 'getImageInfo', success, fail, complete });
2399
- return new Promise((resolve, reject) => {
2400
- const image = new Image();
2401
- image.crossOrigin = '';
2402
- image.onload = () => {
2403
- handle.success({
2404
- width: image.naturalWidth,
2405
- height: image.naturalHeight,
2406
- path: getBase64Image(image) || src
2407
- }, { resolve, reject });
2408
- };
2409
- image.onerror = (e) => {
2410
- handle.fail({
2411
- errMsg: e.message
2412
- }, { resolve, reject });
2413
- };
2414
- image.src = src;
2415
- });
2416
- };
2417
-
2418
- /**
2419
- * previewImage api基于开源的React组件[react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer)开发,感谢!
2420
- */
2421
- /**
2422
- * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。
2423
- */
2424
- const previewImage = (options) => tslib.__awaiter(void 0, void 0, void 0, function* () {
2425
- // TODO 改为通过 window.__taroAppConfig 获取配置的 Swiper 插件创建节点
2426
- components.defineCustomElementTaroSwiperCore();
2427
- components.defineCustomElementTaroSwiperItemCore();
2428
- function loadImage(url, loadFail) {
2429
- return new Promise((resolve) => {
2430
- const item = document.createElement('taro-swiper-item-core');
2431
- item.style.cssText = 'display:flex;align-items:start;justify-content:center;overflow-y:scroll;';
2432
- const image = new Image();
2433
- image.style.maxWidth = '100%';
2434
- image.src = url;
2435
- const div = document.createElement('div');
2436
- div.classList.add('swiper-zoom-container');
2437
- div.style.cssText = 'display:flex;align-items:center;justify-content:center;max-width:100%;min-height:100%;';
2438
- div.appendChild(image);
2439
- item.appendChild(div);
2440
- // Note: 等待图片加载完后返回,会导致轮播被卡住
2441
- resolve(item);
2442
- if (shared.isFunction(loadFail)) {
2443
- image.addEventListener('error', (err) => {
2444
- loadFail({ errMsg: err.message });
2445
- });
2446
- }
2256
+ else {
2257
+ result = yield modal.show(options);
2258
+ }
2259
+ const res = { cancel: !1, confirm: !1 };
2260
+ res[result] = !0;
2261
+ return handle.success(res);
2262
+ });
2263
+ function hideModal() {
2264
+ if (!modal.el)
2265
+ return;
2266
+ modal.hide();
2267
+ }
2268
+ const showActionSheet = (options = { itemList: [] }, methodName = 'showActionSheet') => tslib.__awaiter(void 0, void 0, void 0, function* () {
2269
+ init(document);
2270
+ options = Object.assign({
2271
+ itemColor: '#000000',
2272
+ itemList: []
2273
+ }, options);
2274
+ const { success, fail, complete } = options;
2275
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
2276
+ // list item String
2277
+ if (!Array.isArray(options.itemList)) {
2278
+ return handle.fail({
2279
+ errMsg: getParameterError({
2280
+ para: 'itemList',
2281
+ correct: 'Array',
2282
+ wrong: options.itemList
2283
+ })
2447
2284
  });
2448
2285
  }
2449
- // options must be an Object
2450
- const isObject = shouldBeObject(options);
2451
- if (!isObject.flag) {
2452
- const res = { errMsg: `previewImage:fail ${isObject.msg}` };
2453
- console.error(res.errMsg);
2454
- return Promise.reject(res);
2286
+ if (options.itemList.length < 1) {
2287
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
2455
2288
  }
2456
- const { urls = [], current = '', success, fail, complete } = options;
2457
- const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
2458
- const container = document.createElement('div');
2459
- const removeHandler = () => {
2460
- runtime.eventCenter.off('__taroRouterChange', removeHandler);
2461
- container.remove();
2462
- };
2463
- // 路由改变后应该关闭预览框
2464
- runtime.eventCenter.on('__taroRouterChange', removeHandler);
2465
- container.classList.add('preview-image');
2466
- container.style.cssText =
2467
- 'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
2468
- container.addEventListener('click', removeHandler);
2469
- const swiper = document.createElement('taro-swiper-core');
2470
- // @ts-ignore
2471
- swiper.full = true;
2472
- // @ts-ignore
2473
- swiper.zoom = true;
2474
- let children = [];
2475
- try {
2476
- children = yield Promise.all(urls.map((e) => loadImage(e, fail)));
2289
+ if (options.itemList.length > 6) {
2290
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
2291
+ }
2292
+ for (let i = 0; i < options.itemList.length; i++) {
2293
+ if (typeof options.itemList[i] !== 'string') {
2294
+ return handle.fail({
2295
+ errMsg: getParameterError({
2296
+ para: `itemList[${i}]`,
2297
+ correct: 'String',
2298
+ wrong: options.itemList[i]
2299
+ })
2300
+ });
2301
+ }
2477
2302
  }
2478
- catch (error) {
2303
+ if (typeof options.itemColor !== 'string') {
2479
2304
  return handle.fail({
2480
- errMsg: error,
2305
+ errMsg: getParameterError({
2306
+ para: 'itemColor',
2307
+ correct: 'String',
2308
+ wrong: options.itemColor
2309
+ })
2481
2310
  });
2482
2311
  }
2483
- for (let i = 0; i < children.length; i++) {
2484
- const child = children[i];
2485
- swiper.appendChild(child);
2312
+ let result = '';
2313
+ if (!actionSheet.el) {
2314
+ result = yield actionSheet.create(options);
2315
+ }
2316
+ else {
2317
+ result = yield actionSheet.show(options);
2318
+ }
2319
+ if (typeof result === 'string') {
2320
+ return handle.fail(({ errMsg: result }));
2321
+ }
2322
+ else {
2323
+ return handle.success(({ tapIndex: result }));
2324
+ }
2325
+ });
2326
+ Taro.eventCenter.on('__afterTaroRouterChange', () => {
2327
+ var _a, _b;
2328
+ if (toast.currentPath && toast.currentPath !== ((_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path)) {
2329
+ hideToast();
2330
+ hideLoading();
2331
+ }
2332
+ if (modal.currentPath && modal.currentPath !== ((_b = runtime.Current.page) === null || _b === void 0 ? void 0 : _b.path)) {
2333
+ hideModal();
2486
2334
  }
2487
- const currentIndex = typeof current === 'number' ? current : urls.indexOf(current);
2488
- swiper.current = currentIndex;
2489
- container.appendChild(swiper);
2490
- document.body.appendChild(container);
2491
- return handle.success();
2492
2335
  });
2336
+ const enableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('enableAlertBeforeUnload');
2337
+ const disableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('disableAlertBeforeUnload');
2493
2338
 
2494
2339
  /**
2495
- * H5 下的 styleSheet 操作
2496
- * @author leeenx
2340
+ * 剪贴板部分的api参考了Chameleon项目的实现:
2341
+ *
2342
+ * setClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/setClipBoardData
2343
+ * getClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/getClipBoardData
2497
2344
  */
2498
- class StyleSheet {
2499
- constructor() {
2500
- this.$style = null;
2501
- this.sheet = null;
2502
- this.appendStyleSheet = () => {
2503
- if (this.$style) {
2504
- const head = document.getElementsByTagName('head')[0];
2505
- this.$style.setAttribute('type', 'text/css');
2506
- this.$style.setAttribute('data-type', 'Taro');
2507
- head.appendChild(this.$style);
2508
- this.sheet = this.$style.sheet;
2509
- }
2510
- if (this.sheet && !('insertRule' in this.sheet)) {
2511
- console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
2512
- }
2513
- };
2514
- // 添加样式命令
2515
- this.add = (cssText, index = 0) => {
2516
- var _a;
2517
- if (this.sheet === null) {
2518
- // $style 未插入到 DOM
2519
- this.appendStyleSheet();
2520
- }
2521
- (_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
2522
- };
2523
- this.$style = document.createElement('style');
2524
- }
2525
- }
2526
- const styleSheet = new StyleSheet();
2527
- // 监听事件
2528
- let TRANSITION_END = 'transitionend';
2529
- let TRANSFORM = 'transform';
2530
- const $detect = document.createElement('div');
2531
- $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;';
2532
- if ($detect.style['animation-name'] === 'standard') {
2533
- // 支持标准写法
2534
- TRANSITION_END = 'transitionend';
2535
- TRANSFORM = 'transform';
2536
- }
2537
- else if ($detect.style['-webkit-animation-name'] === 'webkit') {
2538
- // webkit 前缀
2539
- TRANSITION_END = 'webkitTransitionEnd';
2540
- TRANSFORM = '-webkit-transform';
2541
- }
2542
- else if ($detect.style['-moz-animation-name'] === 'moz') {
2543
- // moz 前缀
2544
- TRANSITION_END = 'mozTransitionEnd';
2545
- TRANSFORM = '-moz-transform';
2546
- }
2547
- else if ($detect.style['-ms-animation-name'] === 'ms') {
2548
- // ms 前缀
2549
- TRANSITION_END = 'msTransitionEnd';
2550
- TRANSFORM = '-ms-transform';
2551
- }
2552
- let animId = 0;
2553
- class Animation {
2554
- constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
2555
- // 属性组合
2556
- this.rules = [];
2557
- // transform 对象
2558
- this.transform = [`${TRANSFORM}:`];
2559
- // 组合动画
2560
- this.steps = [];
2561
- // 动画 map ----- 永久保留
2562
- this.animationMap = {};
2563
- // animationMap 的长度
2564
- this.animationMapCount = 0;
2565
- // 默认值
2566
- this.setDefault(duration, delay, timingFunction, transformOrigin);
2567
- this.unit = unit;
2568
- // atom 环境下,animation 属性不会显示,所以要改成 data-animation
2569
- let animAttr = 'animation';
2570
- // 动画 id
2571
- this.id = ++animId;
2572
- // 监听事件
2573
- document.body.addEventListener(TRANSITION_END, (e) => {
2574
- const target = e.target;
2575
- if (target.getAttribute(animAttr) === null) {
2576
- animAttr = 'data-animation';
2577
- }
2578
- const animData = target.getAttribute(animAttr);
2579
- // 没有动画存在
2580
- if (animData === null)
2581
- return;
2582
- const [animName, animPath] = animData.split('__');
2583
- if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
2584
- const [animIndex, __stepIndex = 0] = animPath.split('--');
2585
- const stepIndex = Number(__stepIndex);
2586
- // 动画总的关键帧
2587
- const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
2588
- const animStepsMaxIndex = animStepsCount - 1;
2589
- if (stepIndex < animStepsMaxIndex) {
2590
- // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
2591
- target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
2592
- if (animAttr === 'animation') {
2593
- // Nerv 环境,animation & data-animation 双重保险
2594
- target.setAttribute('data-animation', `${animName}__${animIndex}--${stepIndex + 1}`);
2595
- }
2596
- }
2597
- }
2345
+ const CLIPBOARD_STORAGE_NAME = 'taro_clipboard';
2346
+ document.addEventListener('copy', () => {
2347
+ var _a;
2348
+ setStorage({
2349
+ key: CLIPBOARD_STORAGE_NAME,
2350
+ data: (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString()
2351
+ }).catch(e => {
2352
+ console.error(e);
2353
+ });
2354
+ });
2355
+ /**
2356
+ * 设置系统剪贴板的内容
2357
+ */
2358
+ const setClipboardData = ({ data, success, fail, complete }) => tslib.__awaiter(void 0, void 0, void 0, function* () {
2359
+ const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete });
2360
+ try {
2361
+ setStorageSync(CLIPBOARD_STORAGE_NAME, data);
2362
+ /**
2363
+ * 已于 iPhone 6s Plus iOS 13.1.3 上的 Safari 测试通过
2364
+ * iOS < 10 的系统可能无法使用编程方式访问剪贴板,参考:
2365
+ * https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios/34046084
2366
+ */
2367
+ if (shared.isFunction(document.execCommand)) {
2368
+ const textarea = document.createElement('textarea');
2369
+ textarea.readOnly = true;
2370
+ textarea.value = data;
2371
+ textarea.style.position = 'absolute';
2372
+ textarea.style.width = '100px';
2373
+ textarea.style.left = '-10000px';
2374
+ document.body.appendChild(textarea);
2375
+ textarea.select();
2376
+ textarea.setSelectionRange(0, textarea.value.length);
2377
+ document.execCommand('copy');
2378
+ document.body.removeChild(textarea);
2379
+ }
2380
+ else {
2381
+ throw new Error('Unsupported Function: \'document.execCommand\'.');
2382
+ }
2383
+ showToast({
2384
+ title: '内容已复制',
2385
+ icon: 'none',
2386
+ duration: 1500
2598
2387
  });
2388
+ return handle.success();
2599
2389
  }
2600
- transformUnit(...args) {
2601
- const ret = [];
2602
- args.forEach(each => {
2603
- ret.push(isNaN(each) ? each : `${each}${this.unit}`);
2604
- });
2605
- return ret;
2390
+ catch (e) {
2391
+ return handle.fail({ errMsg: e.message });
2606
2392
  }
2607
- // 设置默认值
2608
- setDefault(duration, delay, timingFunction, transformOrigin) {
2609
- this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
2393
+ });
2394
+ /**
2395
+ * 获取系统剪贴板的内容
2396
+ */
2397
+ const getClipboardData = ({ success, fail, complete } = {}) => tslib.__awaiter(void 0, void 0, void 0, function* () {
2398
+ const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
2399
+ try {
2400
+ const data = getStorageSync(CLIPBOARD_STORAGE_NAME);
2401
+ return handle.success({ data });
2610
2402
  }
2611
- matrix(a, b, c, d, tx, ty) {
2612
- this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`);
2613
- return this;
2403
+ catch (e) {
2404
+ return handle.fail({ errMsg: e.message });
2614
2405
  }
2615
- matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
2616
- this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`);
2617
- return this;
2406
+ });
2407
+
2408
+ const callbackManager$2 = new CallbackManager();
2409
+ let compassListener;
2410
+ /**
2411
+ * Note: 按系统类型获取对应绝对 orientation 事件名,因为安卓系统中直接监听 deviceorientation 事件得到的不是绝对 orientation
2412
+ */
2413
+ const deviceorientationEventName = ['absolutedeviceorientation', 'deviceorientationabsolute', 'deviceorientation'].find(item => {
2414
+ if ('on' + item in window) {
2415
+ return item;
2618
2416
  }
2619
- rotate(angle) {
2620
- this.transform.push(`rotate(${angle}deg)`);
2621
- return this;
2417
+ }) || '';
2418
+ /**
2419
+ * 停止监听罗盘数据
2420
+ */
2421
+ const stopCompass = ({ success, fail, complete } = {}) => {
2422
+ const handle = new MethodHandler({ name: 'stopCompass', success, fail, complete });
2423
+ try {
2424
+ window.removeEventListener(deviceorientationEventName, compassListener, true);
2425
+ return handle.success();
2622
2426
  }
2623
- rotate3d(x, y, z, angle) {
2624
- if (typeof y !== 'number') {
2625
- this.transform.push(`rotate3d(${x})`);
2427
+ catch (e) {
2428
+ return handle.fail({ errMsg: e.message });
2429
+ }
2430
+ };
2431
+ let CompassChangeTrigger = false;
2432
+ /**
2433
+ * 开始监听罗盘数据
2434
+ */
2435
+ const startCompass = ({ success, fail, complete } = {}) => {
2436
+ const handle = new MethodHandler({ name: 'startCompass', success, fail, complete });
2437
+ try {
2438
+ if (deviceorientationEventName !== '') {
2439
+ if (compassListener) {
2440
+ stopCompass();
2441
+ }
2442
+ compassListener = throttle((evt) => {
2443
+ const isAndroid = getDeviceInfo().system === 'AndroidOS';
2444
+ if (isAndroid && !evt.absolute && !CompassChangeTrigger) {
2445
+ CompassChangeTrigger = true;
2446
+ console.warn('Warning: In \'onCompassChange\', your browser is not supported to get the orientation relative to the earth, the orientation data will be related to the initial orientation of the device .');
2447
+ }
2448
+ const alpha = evt.alpha || 0;
2449
+ /**
2450
+ * 由于平台差异,accuracy 在 iOS/Android 的值不同。
2451
+ * - iOS:accuracy 是一个 number 类型的值,表示相对于磁北极的偏差。0 表示设备指向磁北,90 表示指向东,180 表示指向南,依此类推。
2452
+ * - Android:accuracy 是一个 string 类型的枚举值。
2453
+ */
2454
+ const accuracy = isAndroid ? evt.absolute ? 'high' : 'medium' : alpha;
2455
+ callbackManager$2.trigger({
2456
+ direction: 360 - alpha,
2457
+ accuracy: accuracy
2458
+ });
2459
+ }, 5000);
2460
+ window.addEventListener(deviceorientationEventName, compassListener, true);
2626
2461
  }
2627
2462
  else {
2628
- this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`);
2463
+ throw new Error('compass is not supported');
2629
2464
  }
2630
- return this;
2465
+ return handle.success();
2631
2466
  }
2632
- rotateX(angle) {
2633
- this.transform.push(`rotateX(${angle}deg)`);
2634
- return this;
2467
+ catch (e) {
2468
+ return handle.fail({ errMsg: e.message });
2635
2469
  }
2636
- rotateY(angle) {
2637
- this.transform.push(`rotateY(${angle}deg)`);
2638
- return this;
2470
+ };
2471
+ /**
2472
+ * 监听罗盘数据变化事件。频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
2473
+ */
2474
+ const onCompassChange = callback => {
2475
+ callbackManager$2.add(callback);
2476
+ };
2477
+ /**
2478
+ * 取消监听罗盘数据变化事件,参数为空,则取消所有的事件监听。
2479
+ */
2480
+ const offCompassChange = callback => {
2481
+ callbackManager$2.remove(callback);
2482
+ };
2483
+
2484
+ // 联系人
2485
+ const chooseContact = /* @__PURE__ */ temporarilyNotSupport('chooseContact');
2486
+ const addPhoneContact = /* @__PURE__ */ temporarilyNotSupport('addPhoneContact');
2487
+
2488
+ // 加密
2489
+ const getRandomValues = /* @__PURE__ */ temporarilyNotSupport('getRandomValues');
2490
+
2491
+ // 陀螺仪
2492
+ const stopGyroscope = /* @__PURE__ */ temporarilyNotSupport('stopGyroscope');
2493
+ const startGyroscope = /* @__PURE__ */ temporarilyNotSupport('startGyroscope');
2494
+ const onGyroscopeChange = /* @__PURE__ */ temporarilyNotSupport('onGyroscopeChange');
2495
+ const offGyroscopeChange = /* @__PURE__ */ temporarilyNotSupport('offGyroscopeChange');
2496
+
2497
+ // 蓝牙-信标(Beacon)
2498
+ const stopBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('stopBeaconDiscovery');
2499
+ const startBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('startBeaconDiscovery');
2500
+ const onBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('onBeaconUpdate');
2501
+ const onBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('onBeaconServiceChange');
2502
+ const offBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('offBeaconUpdate');
2503
+ const offBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('offBeaconServiceChange');
2504
+ const getBeacons = /* @__PURE__ */ temporarilyNotSupport('getBeacons');
2505
+
2506
+ // 键盘
2507
+ const onKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('onKeyboardHeightChange');
2508
+ const offKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('offKeyboardHeightChange');
2509
+ const hideKeyboard = /* @__PURE__ */ temporarilyNotSupport('hideKeyboard');
2510
+ const getSelectedTextRange = /* @__PURE__ */ temporarilyNotSupport('getSelectedTextRange');
2511
+
2512
+ // 内存
2513
+ const onMemoryWarning = /* @__PURE__ */ temporarilyNotSupport('onMemoryWarning');
2514
+ const offMemoryWarning = /* @__PURE__ */ temporarilyNotSupport('offMemoryWarning');
2515
+
2516
+ const callbackManager$1 = new CallbackManager();
2517
+ let deviceMotionListener;
2518
+ const INTERVAL_MAP = {
2519
+ game: {
2520
+ interval: 20,
2521
+ frequency: 50
2522
+ },
2523
+ ui: {
2524
+ interval: 60,
2525
+ frequency: 16.67
2526
+ },
2527
+ normal: {
2528
+ interval: 200,
2529
+ frequency: 5
2639
2530
  }
2640
- rotateZ(angle) {
2641
- this.transform.push(`rotateZ(${angle}deg)`);
2642
- return this;
2531
+ };
2532
+ /**
2533
+ * 停止监听设备方向的变化。
2534
+ */
2535
+ const stopDeviceMotionListening = ({ success, fail, complete } = {}) => {
2536
+ const handle = new MethodHandler({ name: 'stopDeviceMotionListening', success, fail, complete });
2537
+ try {
2538
+ window.removeEventListener('deviceorientation', deviceMotionListener, true);
2539
+ return handle.success();
2643
2540
  }
2644
- scale(x, y) {
2645
- this.transform.push(`scale(${x}, ${y})`);
2646
- return this;
2541
+ catch (e) {
2542
+ return handle.fail({ errMsg: e.message });
2647
2543
  }
2648
- scale3d(x, y, z) {
2649
- this.transform.push(`scale3d(${x}, ${y}, ${z})`);
2650
- return this;
2544
+ };
2545
+ /**
2546
+ * 开始监听设备方向的变化。
2547
+ */
2548
+ const startDeviceMotionListening = ({ interval = 'normal', success, fail, complete } = {}) => {
2549
+ const handle = new MethodHandler({ name: 'startDeviceMotionListening', success, fail, complete });
2550
+ try {
2551
+ const intervalObj = INTERVAL_MAP[interval];
2552
+ if (window.DeviceOrientationEvent) {
2553
+ if (deviceMotionListener) {
2554
+ stopDeviceMotionListening();
2555
+ }
2556
+ deviceMotionListener = throttle((evt) => {
2557
+ callbackManager$1.trigger({
2558
+ alpha: evt.alpha,
2559
+ beta: evt.beta,
2560
+ gamma: evt.gamma
2561
+ });
2562
+ }, intervalObj.interval);
2563
+ window.addEventListener('deviceorientation', deviceMotionListener, true);
2564
+ }
2565
+ else {
2566
+ throw new Error('deviceMotion is not supported');
2567
+ }
2568
+ return handle.success();
2651
2569
  }
2652
- scaleX(scale) {
2653
- this.transform.push(`scaleX(${scale})`);
2654
- return this;
2570
+ catch (e) {
2571
+ return handle.fail({ errMsg: e.message });
2655
2572
  }
2656
- scaleY(scale) {
2657
- this.transform.push(`scaleY(${scale})`);
2658
- return this;
2573
+ };
2574
+ /**
2575
+ * 监听设备方向变化事件。
2576
+ */
2577
+ const onDeviceMotionChange = callback => {
2578
+ callbackManager$1.add(callback);
2579
+ };
2580
+ /**
2581
+ * 取消监听设备方向变化事件,参数为空,则取消所有的事件监听。
2582
+ */
2583
+ const offDeviceMotionChange = callback => {
2584
+ callbackManager$1.remove(callback);
2585
+ };
2586
+
2587
+ function getConnection() {
2588
+ // @ts-ignore
2589
+ return navigator.connection || navigator.mozConnection || navigator.webkitConnection || navigator.msConnection;
2590
+ }
2591
+ const getNetworkType = (options = {}) => {
2592
+ const connection = getConnection();
2593
+ const { success, fail, complete } = options;
2594
+ const handle = new MethodHandler({ name: 'getNetworkType', success, fail, complete });
2595
+ let networkType = 'unknown';
2596
+ // 浏览器不支持获取网络状态
2597
+ if (!connection) {
2598
+ return handle.success({ networkType });
2659
2599
  }
2660
- scaleZ(scale) {
2661
- this.transform.push(`scaleZ(${scale})`);
2662
- return this;
2600
+ // Supports only the navigator.connection.type value which doesn't match the latest spec.
2601
+ // https://www.davidbcalhoun.com/2010/using-navigator-connection-android/
2602
+ if (!isNaN(Number(connection.type))) {
2603
+ switch (connection.type) {
2604
+ // @ts-ignore
2605
+ case connection.WIFI:
2606
+ networkType = 'wifi';
2607
+ break;
2608
+ // @ts-ignore
2609
+ case connection.CELL_3G:
2610
+ networkType = '3g';
2611
+ break;
2612
+ // @ts-ignore
2613
+ case connection.CELL_2G:
2614
+ networkType = '2g';
2615
+ break;
2616
+ default:
2617
+ // ETHERNET, UNKNOWN
2618
+ networkType = 'unknown';
2619
+ }
2663
2620
  }
2664
- skew(x, y) {
2665
- this.transform.push(`skew(${x}, ${y})`);
2666
- return this;
2621
+ else if (connection.type) {
2622
+ // @ts-ignore
2623
+ networkType = connection.type; // Only supports the type value.
2624
+ // @ts-ignore
2667
2625
  }
2668
- skewX(angle) {
2669
- this.transform.push(`skewX(${angle})`);
2670
- return this;
2626
+ else if (connection.effectiveType) {
2627
+ // @ts-ignore
2628
+ networkType = connection.effectiveType;
2671
2629
  }
2672
- skewY(angle) {
2673
- this.transform.push(`skewY(${angle})`);
2674
- return this;
2630
+ return handle.success({ networkType });
2631
+ };
2632
+ const networkStatusManager = new CallbackManager();
2633
+ const networkStatusListener = () => tslib.__awaiter(void 0, void 0, void 0, function* () {
2634
+ const { networkType } = yield getNetworkType();
2635
+ const isConnected = networkType !== 'none';
2636
+ const obj = { isConnected, networkType };
2637
+ networkStatusManager.trigger(obj);
2638
+ });
2639
+ /**
2640
+ * 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
2641
+ * - 出现三次以上连接超时
2642
+ * - 出现三次 rtt 超过 400
2643
+ * - 出现三次以上的丢包
2644
+ * > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
2645
+ */
2646
+ const onNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('onNetworkWeakChange');
2647
+ const onNetworkStatusChange = callback => {
2648
+ networkStatusManager.add(callback);
2649
+ const connection = getConnection();
2650
+ if (connection && networkStatusManager.count() === 1) {
2651
+ connection.addEventListener('change', networkStatusListener);
2675
2652
  }
2676
- translate(x, y) {
2677
- [x, y] = this.transformUnit(x, y);
2678
- this.transform.push(`translate(${x}, ${y})`);
2679
- return this;
2653
+ };
2654
+ const offNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('offNetworkWeakChange');
2655
+ const offNetworkStatusChange = callback => {
2656
+ networkStatusManager.remove(callback);
2657
+ const connection = getConnection();
2658
+ if (connection && networkStatusManager.count() === 0) {
2659
+ connection.removeEventListener('change', networkStatusListener);
2680
2660
  }
2681
- translate3d(x, y, z) {
2682
- [x, y, z] = this.transformUnit(x, y, z);
2683
- this.transform.push(`translate3d(${x}, ${y}, ${z})`);
2684
- return this;
2661
+ };
2662
+ const getLocalIPAddress = /* @__PURE__ */ temporarilyNotSupport('getLocalIPAddress');
2663
+
2664
+ // NFC
2665
+ const stopHCE = /* @__PURE__ */ temporarilyNotSupport('stopHCE');
2666
+ const startHCE = /* @__PURE__ */ temporarilyNotSupport('startHCE');
2667
+ const sendHCEMessage = /* @__PURE__ */ temporarilyNotSupport('sendHCEMessage');
2668
+ const onHCEMessage = /* @__PURE__ */ temporarilyNotSupport('onHCEMessage');
2669
+ const offHCEMessage = /* @__PURE__ */ temporarilyNotSupport('offHCEMessage');
2670
+ const getNFCAdapter = /* @__PURE__ */ temporarilyNotSupport('getNFCAdapter');
2671
+ const getHCEState = /* @__PURE__ */ temporarilyNotSupport('getHCEState');
2672
+
2673
+ const makePhoneCall = (options) => {
2674
+ // options must be an Object
2675
+ const isObject = shouldBeObject(options);
2676
+ if (!isObject.flag) {
2677
+ const res = { errMsg: `makePhoneCall:fail ${isObject.msg}` };
2678
+ console.error(res.errMsg);
2679
+ return Promise.reject(res);
2685
2680
  }
2686
- translateX(translate) {
2687
- [translate] = this.transformUnit(translate);
2688
- this.transform.push(`translateX(${translate})`);
2689
- return this;
2681
+ const { phoneNumber, success, fail, complete } = options;
2682
+ const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete });
2683
+ if (typeof phoneNumber !== 'string') {
2684
+ return handle.fail({
2685
+ errMsg: getParameterError({
2686
+ para: 'phoneNumber',
2687
+ correct: 'String',
2688
+ wrong: phoneNumber
2689
+ })
2690
+ });
2690
2691
  }
2691
- translateY(translate) {
2692
- [translate] = this.transformUnit(translate);
2693
- this.transform.push(`translateY(${translate})`);
2694
- return this;
2692
+ window.location.href = `tel:${phoneNumber}`;
2693
+ return handle.success();
2694
+ };
2695
+
2696
+ // 扫码
2697
+ const scanCode = /* @__PURE__ */ processOpenApi({
2698
+ name: 'scanQRCode',
2699
+ defaultOptions: { needResult: 1 },
2700
+ formatResult: res => ({
2701
+ errMsg: res.errMsg === 'scanQRCode:ok' ? 'scanCode:ok' : res.errMsg,
2702
+ result: res.resultStr
2703
+ })
2704
+ });
2705
+
2706
+ // 屏幕
2707
+ const setVisualEffectOnCapture = /* @__PURE__ */ temporarilyNotSupport('setVisualEffectOnCapture');
2708
+ const setScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('setScreenBrightness');
2709
+ const setKeepScreenOn = /* @__PURE__ */ temporarilyNotSupport('setKeepScreenOn');
2710
+ const onUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('onUserCaptureScreen');
2711
+ const offUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('offUserCaptureScreen');
2712
+ const getScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('getScreenBrightness');
2713
+ const onScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('onScreenRecordingStateChanged');
2714
+ const offScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('offScreenRecordingStateChanged');
2715
+ const getScreenRecordingState = /* @__PURE__ */ temporarilyNotSupport('getScreenRecordingState');
2716
+
2717
+ // 短信
2718
+ const sendSms = /* @__PURE__ */ temporarilyNotSupport('sendSms');
2719
+
2720
+ const vibrator = function vibrator(mm) {
2721
+ try {
2722
+ return window.navigator.vibrate(mm);
2695
2723
  }
2696
- translateZ(translate) {
2697
- [translate] = this.transformUnit(translate);
2698
- this.transform.push(`translateZ(${translate})`);
2699
- return this;
2724
+ catch (e) {
2725
+ console.warn('当前浏览器不支持 vibrate。');
2700
2726
  }
2701
- opacity(value) {
2702
- this.rules.push(`opacity: ${value}`);
2703
- return this;
2727
+ };
2728
+ /**
2729
+ * 使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
2730
+ */
2731
+ const vibrateShort = ({ success, fail, complete } = {}) => {
2732
+ const handle = new MethodHandler({ name: 'vibrateShort', success, fail, complete });
2733
+ if (vibrator(15)) {
2734
+ return handle.success();
2704
2735
  }
2705
- backgroundColor(value) {
2706
- this.rules.push(`background-color: ${value}`);
2707
- return this;
2736
+ else {
2737
+ return handle.fail({ errMsg: 'style is not support' });
2708
2738
  }
2709
- width(value) {
2710
- [value] = this.transformUnit(value);
2711
- this.rules.push(`width: ${value}`);
2712
- return this;
2739
+ };
2740
+ /**
2741
+ * 使手机发生较长时间的振动(400 ms)
2742
+ */
2743
+ const vibrateLong = ({ success, fail, complete } = {}) => {
2744
+ const handle = new MethodHandler({ name: 'vibrateLong', success, fail, complete });
2745
+ if (vibrator(400)) {
2746
+ return handle.success();
2713
2747
  }
2714
- height(value) {
2715
- [value] = this.transformUnit(value);
2716
- this.rules.push(`height: ${value}`);
2717
- return this;
2748
+ else {
2749
+ return handle.fail({ errMsg: 'style is not support' });
2718
2750
  }
2719
- top(value) {
2720
- [value] = this.transformUnit(value);
2721
- this.rules.push(`top: ${value}`);
2722
- return this;
2751
+ };
2752
+
2753
+ // Wi-Fi
2754
+ const stopWifi = /* @__PURE__ */ temporarilyNotSupport('stopWifi');
2755
+ const startWifi = /* @__PURE__ */ temporarilyNotSupport('startWifi');
2756
+ const setWifiList = /* @__PURE__ */ temporarilyNotSupport('setWifiList');
2757
+ const onWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('onWifiConnectedWithPartialInfo');
2758
+ const onWifiConnected = /* @__PURE__ */ temporarilyNotSupport('onWifiConnected');
2759
+ const onGetWifiList = /* @__PURE__ */ temporarilyNotSupport('onGetWifiList');
2760
+ const offWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('offWifiConnectedWithPartialInfo');
2761
+ const offWifiConnected = /* @__PURE__ */ temporarilyNotSupport('offWifiConnected');
2762
+ const offGetWifiList = /* @__PURE__ */ temporarilyNotSupport('offGetWifiList');
2763
+ const getWifiList = /* @__PURE__ */ temporarilyNotSupport('getWifiList');
2764
+ const getConnectedWifi = /* @__PURE__ */ temporarilyNotSupport('getConnectedWifi');
2765
+ const connectWifi = /* @__PURE__ */ temporarilyNotSupport('connectWifi');
2766
+
2767
+ // 第三方平台
2768
+ const getExtConfigSync = /* @__PURE__ */ temporarilyNotSupport('getExtConfigSync');
2769
+ const getExtConfig = /* @__PURE__ */ temporarilyNotSupport('getExtConfig');
2770
+
2771
+ // 文件
2772
+ const saveFileToDisk = /* @__PURE__ */ temporarilyNotSupport('saveFileToDisk');
2773
+ const saveFile = /* @__PURE__ */ temporarilyNotSupport('saveFile');
2774
+ const removeSavedFile = /* @__PURE__ */ temporarilyNotSupport('removeSavedFile');
2775
+ const openDocument = /* @__PURE__ */ temporarilyNotSupport('openDocument');
2776
+ const getSavedFileList = /* @__PURE__ */ temporarilyNotSupport('getSavedFileList');
2777
+ const getSavedFileInfo = /* @__PURE__ */ temporarilyNotSupport('getSavedFileInfo');
2778
+ const getFileSystemManager = /* @__PURE__ */ temporarilyNotSupport('getFileSystemManager');
2779
+ const getFileInfo = /* @__PURE__ */ temporarilyNotSupport('getFileInfo');
2780
+
2781
+ const getApp = function () {
2782
+ return Taro.getCurrentInstance().app;
2783
+ };
2784
+ // 自定义组件
2785
+ const getCurrentInstance = Taro.getCurrentInstance;
2786
+
2787
+ const getLocationByW3CApi = (options) => {
2788
+ var _a;
2789
+ // 断言 options 必须是 Object
2790
+ const isObject = shouldBeObject(options);
2791
+ if (!isObject.flag) {
2792
+ const res = { errMsg: `getLocation:fail ${isObject.msg}` };
2793
+ console.error(res.errMsg);
2794
+ return Promise.reject(res);
2723
2795
  }
2724
- right(value) {
2725
- [value] = this.transformUnit(value);
2726
- this.rules.push(`right: ${value}`);
2727
- return this;
2796
+ // 解构回调函数
2797
+ const { success, fail, complete } = options;
2798
+ const handle = new MethodHandler({ name: 'getLocation', success, fail, complete });
2799
+ // const defaultMaximumAge = 5 * 1000
2800
+ const positionOptions = {
2801
+ enableHighAccuracy: options.isHighAccuracy || (options.altitude != null),
2802
+ // maximumAge: defaultMaximumAge, // 允许取多久以内的缓存位置
2803
+ timeout: options.highAccuracyExpireTime // 高精度定位超时时间
2804
+ };
2805
+ // Web端API实现暂时仅支持GPS坐标系
2806
+ if (((_a = options.type) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== 'WGS84') {
2807
+ return handle.fail({
2808
+ errMsg: 'This coordinate system type is not temporarily supported'
2809
+ });
2728
2810
  }
2729
- bottom(value) {
2730
- [value] = this.transformUnit(value);
2731
- this.rules.push(`bottom: ${value}`);
2732
- return this;
2811
+ // 判断当前浏览器是否支持位置API
2812
+ const geolocationSupported = navigator.geolocation;
2813
+ if (!geolocationSupported) {
2814
+ return handle.fail({
2815
+ errMsg: 'The current browser does not support this feature'
2816
+ });
2733
2817
  }
2734
- left(value) {
2735
- [value] = this.transformUnit(value);
2736
- this.rules.push(`left: ${value}`);
2737
- return this;
2818
+ // 开始获取位置
2819
+ return new Promise((resolve, reject) => {
2820
+ navigator.geolocation.getCurrentPosition((position) => {
2821
+ const result = {
2822
+ /** 位置的精确度 */
2823
+ accuracy: position.coords.accuracy,
2824
+ /** 高度,单位 m */
2825
+ altitude: position.coords.altitude,
2826
+ /** 水平精度,单位 m */
2827
+ horizontalAccuracy: position.coords.accuracy,
2828
+ /** 纬度,范围为 -90~90,负数表示南纬 */
2829
+ latitude: position.coords.latitude,
2830
+ /** 经度,范围为 -180~180,负数表示西经 */
2831
+ longitude: position.coords.longitude,
2832
+ /** 速度,单位 m/s */
2833
+ speed: position.coords.speed,
2834
+ /** 垂直精度,单位 m(Android 无法获取,返回 0) */
2835
+ verticalAccuracy: position.coords.altitudeAccuracy || 0,
2836
+ /** 调用结果,自动补充 */
2837
+ errMsg: ''
2838
+ };
2839
+ handle.success(result, { resolve, reject });
2840
+ }, (error) => {
2841
+ handle.fail({ errMsg: error.message }, { resolve, reject });
2842
+ }, positionOptions);
2843
+ });
2844
+ };
2845
+ const getLocation = /* @__PURE__ */ processOpenApi({
2846
+ name: 'getLocation',
2847
+ standardMethod: getLocationByW3CApi
2848
+ });
2849
+
2850
+ function styleInject(css, ref) {
2851
+ if ( ref === void 0 ) ref = {};
2852
+ var insertAt = ref.insertAt;
2853
+
2854
+ if (!css || typeof document === 'undefined') { return; }
2855
+
2856
+ var head = document.head || document.getElementsByTagName('head')[0];
2857
+ var style = document.createElement('style');
2858
+ style.type = 'text/css';
2859
+
2860
+ if (insertAt === 'top') {
2861
+ if (head.firstChild) {
2862
+ head.insertBefore(style, head.firstChild);
2863
+ } else {
2864
+ head.appendChild(style);
2738
2865
  }
2739
- // 关键帧载入
2740
- step(arg = {}) {
2741
- const { DEFAULT } = this;
2742
- const { duration = DEFAULT.duration, delay = DEFAULT.delay, timingFunction = DEFAULT.timingFunction, transformOrigin = DEFAULT.transformOrigin } = arg;
2743
- // 生成一条 transition 动画
2744
- this.steps.push([
2745
- this.rules.map(rule => `${rule}!important`).join(';'),
2746
- `${this.transform.join(' ')}!important`,
2747
- `${TRANSFORM}-origin: ${transformOrigin}`,
2748
- `transition: all ${duration}ms ${timingFunction} ${delay}ms`
2749
- ]
2750
- .filter(item => item !== '' && item !== `${TRANSFORM}:`)
2751
- .join(';'));
2752
- // 清空 rules 和 transform
2753
- this.rules = [];
2754
- this.transform = [`${TRANSFORM}:`];
2755
- return this;
2866
+ } else {
2867
+ head.appendChild(style);
2868
+ }
2869
+
2870
+ if (style.styleSheet) {
2871
+ style.styleSheet.cssText = css;
2872
+ } else {
2873
+ style.appendChild(document.createTextNode(css));
2874
+ }
2875
+ }
2876
+
2877
+ var css_248z = ".taro_choose_location{background-color:#fff;display:flex;flex-direction:column;height:100%;position:fixed;top:100%;transition:top .3s ease;width:100%;z-index:1}.taro_choose_location_bar{background-color:#ededed;color:#090909;display:flex;flex:0 95px;height:95px}.taro_choose_location_back{flex:0 45px;height:30px;margin-top:30px;position:relative;width:33px}.taro_choose_location_back:before{border:15px solid transparent;border-right-color:#090909;content:\"\";display:block;height:0;left:0;position:absolute;top:0;width:0}.taro_choose_location_back:after{border:15px solid transparent;border-right-color:#ededed;content:\"\";display:block;height:0;left:3px;position:absolute;top:0;width:0}.taro_choose_location_title{flex:1;line-height:95px;padding-left:30px}.taro_choose_location_submit{background-color:#08bf62;border:none;color:#fff;font-size:28px;height:60px;line-height:60px;margin:18px 30px 0 0;padding:0;width:110px}.taro_choose_location_frame{flex:1}";
2878
+ var stylesheet=".taro_choose_location{background-color:#fff;display:flex;flex-direction:column;height:100%;position:fixed;top:100%;transition:top .3s ease;width:100%;z-index:1}.taro_choose_location_bar{background-color:#ededed;color:#090909;display:flex;flex:0 95px;height:95px}.taro_choose_location_back{flex:0 45px;height:30px;margin-top:30px;position:relative;width:33px}.taro_choose_location_back:before{border:15px solid transparent;border-right-color:#090909;content:\"\";display:block;height:0;left:0;position:absolute;top:0;width:0}.taro_choose_location_back:after{border:15px solid transparent;border-right-color:#ededed;content:\"\";display:block;height:0;left:3px;position:absolute;top:0;width:0}.taro_choose_location_title{flex:1;line-height:95px;padding-left:30px}.taro_choose_location_submit{background-color:#08bf62;border:none;color:#fff;font-size:28px;height:60px;line-height:60px;margin:18px 30px 0 0;padding:0;width:110px}.taro_choose_location_frame{flex:1}";
2879
+ styleInject(css_248z,{"insertAt":"top"});
2880
+
2881
+ let container = null;
2882
+ function createLocationChooser(handler, key = LOCATION_APIKEY, mapOpt = {}) {
2883
+ var _a, _b, _c;
2884
+ const { latitude, longitude } = mapOpt, opts = tslib.__rest(mapOpt, ["latitude", "longitude"]);
2885
+ const query = Object.assign({ key, type: 1, coord: ((_a = mapOpt.coord) !== null && _a !== void 0 ? _a : [latitude, longitude].every(e => Number(e) >= 0)) ? `${latitude},${longitude}` : undefined, referer: 'myapp' }, opts);
2886
+ if (!container) {
2887
+ const html = `
2888
+ <div class='taro_choose_location'>
2889
+ <div class='taro_choose_location_bar'>
2890
+ <div class='taro_choose_location_back'></div>
2891
+ <p class='taro_choose_location_title'>位置</p>
2892
+ <button class='taro_choose_location_submit'>完成</button>
2893
+ </div>
2894
+ <iframe class='taro_choose_location_frame' frameborder='0' src="https://apis.map.qq.com/tools/locpicker?${queryString.stringify(query, { arrayFormat: 'comma', skipNull: true })}" />
2895
+ </div>
2896
+ `;
2897
+ container = document.createElement('div');
2898
+ container.innerHTML = html;
2756
2899
  }
2757
- // 创建底层数据
2758
- createAnimationData() {
2759
- const animIndex = `taro-h5-poly-fill/${this.id}/create-animation__${this.animationMapCount++}`;
2760
- // 记录动画分几个 step
2761
- this.animationMap[animIndex] = this.steps.length;
2762
- // 吐出 step
2763
- this.steps.forEach((step, index) => {
2764
- const selector = index === 0
2765
- ? `[animation="${animIndex}"], [data-animation="${animIndex}"]`
2766
- : `[animation="${animIndex}--${index}"], [data-animation="${animIndex}--${index}"]`;
2767
- styleSheet.add(`${selector} { ${step} }`);
2768
- });
2769
- // 清空 steps
2770
- this.steps = [];
2771
- return animIndex;
2900
+ const main = container.querySelector('.taro_choose_location');
2901
+ function show() {
2902
+ setTimeout(() => {
2903
+ main.style.top = '0';
2904
+ });
2772
2905
  }
2773
- // 动画数据产出
2774
- export() {
2775
- return this.createAnimationData();
2906
+ function hide() {
2907
+ main.style.top = '100%';
2908
+ }
2909
+ function back() {
2910
+ hide();
2911
+ handler({ errMsg: 'cancel' });
2912
+ }
2913
+ function submit() {
2914
+ hide();
2915
+ handler();
2916
+ }
2917
+ function remove() {
2918
+ container === null || container === void 0 ? void 0 : container.remove();
2919
+ container = null;
2920
+ window.removeEventListener('popstate', back);
2776
2921
  }
2922
+ (_b = container.querySelector('.taro_choose_location_back')) === null || _b === void 0 ? void 0 : _b.addEventListener('click', back);
2923
+ (_c = container.querySelector('.taro_choose_location_submit')) === null || _c === void 0 ? void 0 : _c.addEventListener('click', submit);
2924
+ window.addEventListener('popstate', back);
2925
+ return {
2926
+ show,
2927
+ remove,
2928
+ container,
2929
+ };
2777
2930
  }
2778
- // h5 的 createAnimation
2779
- const createAnimation = (option) => {
2780
- return new Animation(option);
2781
- };
2782
-
2783
- // 背景
2784
- const setBackgroundTextStyle = /* @__PURE__ */ temporarilyNotSupport('setBackgroundTextStyle');
2785
- const setBackgroundColor = /* @__PURE__ */ temporarilyNotSupport('setBackgroundColor');
2786
-
2787
- // 自定义组件
2788
- const nextTick = Taro.nextTick;
2789
-
2790
- // 字体
2791
- const loadFontFace = (options) => tslib.__awaiter(void 0, void 0, void 0, function* () {
2792
- options = Object.assign({ global: false }, options);
2793
- const { success, fail, complete, family, source, desc = {} } = options;
2794
- const handle = new MethodHandler({ name: 'loadFontFace', success, fail, complete });
2795
- // @ts-ignore
2796
- const fonts = document.fonts;
2797
- if (fonts) {
2798
- // @ts-ignore
2799
- const fontFace = new FontFace(family, source, desc);
2800
- try {
2801
- yield fontFace.load();
2802
- fonts.add(fontFace);
2803
- return handle.success({ status: 'loaded' });
2804
- }
2805
- catch (error) {
2931
+ /**
2932
+ * 打开地图选择位置。
2933
+ */
2934
+ const chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
2935
+ const handle = new MethodHandler({ name: 'chooseLocation', success, fail, complete });
2936
+ return new Promise((resolve, reject) => {
2937
+ const chooseLocation = {};
2938
+ if (typeof LOCATION_APIKEY === 'undefined') {
2939
+ console.warn('chooseLocation api 依赖腾讯地图定位api,需要在 defineConstants 中配置 LOCATION_APIKEY');
2806
2940
  return handle.fail({
2807
- status: 'error',
2808
- errMsg: error.message || error,
2809
- });
2810
- }
2811
- }
2812
- else {
2813
- const style = document.createElement('style');
2814
- let innerText = `font-family:"${family}";src:${source};font-style:${desc.style || 'normal'};font-weight:${desc.weight || 'normal'};font-variant:${desc.variant || 'normal'};`;
2815
- if (desc.ascentOverride) {
2816
- innerText += `ascent-override:${desc.ascentOverride};`;
2817
- }
2818
- if (desc.descentOverride) {
2819
- innerText += `descent-override:${desc.descentOverride};`;
2820
- }
2821
- if (desc.featureSettings) {
2822
- innerText += `font-feature-settings:${desc.featureSettings};`;
2823
- }
2824
- if (desc.lineGapOverride) {
2825
- innerText += `line-gap-override:${desc.lineGapOverride};`;
2826
- }
2827
- if (desc.stretch) {
2828
- innerText += `font-stretch:${desc.stretch};`;
2829
- }
2830
- if (desc.unicodeRange) {
2831
- innerText += `unicode-range:${desc.unicodeRange};`;
2832
- }
2833
- if (desc.variationSettings) {
2834
- innerText += `font-variation-settings:${desc.variationSettings};`;
2941
+ errMsg: 'LOCATION_APIKEY needed'
2942
+ }, { resolve, reject });
2835
2943
  }
2836
- style.innerText = `@font-face{${innerText}}`;
2837
- document.head.appendChild(style);
2838
- return handle.success({ status: 'loaded' });
2839
- }
2840
- });
2841
-
2842
- const noop = function () { };
2843
- class ActionSheet {
2844
- constructor() {
2845
- this.options = {
2846
- itemList: [],
2847
- itemColor: '#000000',
2848
- success: noop,
2849
- fail: noop,
2850
- complete: noop
2851
- };
2852
- this.style = {
2853
- maskStyle: {
2854
- position: 'fixed',
2855
- 'z-index': '1000',
2856
- top: '0',
2857
- right: '0',
2858
- left: '0',
2859
- bottom: '0',
2860
- background: 'rgba(0,0,0,0.6)'
2861
- },
2862
- actionSheetStyle: {
2863
- 'z-index': '4999',
2864
- position: 'fixed',
2865
- left: '0',
2866
- bottom: '0',
2867
- '-webkit-transform': 'translate(0, 100%)',
2868
- transform: 'translate(0, 100%)',
2869
- width: '100%',
2870
- 'line-height': '1.6',
2871
- background: '#EFEFF4',
2872
- '-webkit-transition': '-webkit-transform .3s',
2873
- transition: 'transform .3s'
2874
- },
2875
- menuStyle: {
2876
- 'background-color': '#FCFCFD'
2877
- },
2878
- cellStyle: {
2879
- position: 'relative',
2880
- padding: '10px 0',
2881
- 'text-align': 'center',
2882
- 'font-size': '18px'
2883
- },
2884
- cancelStyle: {
2885
- 'margin-top': '6px',
2886
- padding: '10px 0',
2887
- 'text-align': 'center',
2888
- 'font-size': '18px',
2889
- color: '#000000',
2890
- 'background-color': '#FCFCFD'
2891
- }
2944
+ const key = LOCATION_APIKEY;
2945
+ const onMessage = event => {
2946
+ // 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
2947
+ const loc = event.data;
2948
+ // 防止其他应用也会向该页面 post 信息,需判断 module 是否为'locationPicker'
2949
+ if (!loc || loc.module !== 'locationPicker')
2950
+ return;
2951
+ chooseLocation.name = loc.poiname;
2952
+ chooseLocation.address = loc.poiaddress;
2953
+ chooseLocation.latitude = loc.latlng.lat;
2954
+ chooseLocation.longitude = loc.latlng.lng;
2892
2955
  };
2893
- this.lastConfig = {};
2894
- }
2895
- create(options = {}) {
2896
- return new Promise((resolve) => {
2897
- // style
2898
- const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
2899
- // configuration
2900
- const config = Object.assign(Object.assign({}, this.options), options);
2901
- this.lastConfig = config;
2902
- // wrapper
2903
- this.el = document.createElement('div');
2904
- this.el.className = 'taro__actionSheet';
2905
- this.el.style.opacity = '0';
2906
- this.el.style.transition = 'opacity 0.2s linear';
2907
- // mask
2908
- this.mask = document.createElement('div');
2909
- this.mask.setAttribute('style', inlineStyle(maskStyle));
2910
- // actionSheet
2911
- this.actionSheet = document.createElement('div');
2912
- this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
2913
- // menu
2914
- this.menu = document.createElement('div');
2915
- this.menu.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, menuStyle), { color: config.itemColor })));
2916
- // cells
2917
- this.cells = config.itemList.map((item, index) => {
2918
- const cell = document.createElement('div');
2919
- cell.className = 'taro-actionsheet__cell';
2920
- cell.setAttribute('style', inlineStyle(cellStyle));
2921
- cell.textContent = item;
2922
- cell.dataset.tapIndex = `${index}`;
2923
- cell.onclick = e => {
2924
- this.hide();
2925
- const target = e.currentTarget;
2926
- const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
2927
- resolve(index);
2928
- };
2929
- return cell;
2930
- });
2931
- // cancel
2932
- this.cancel = document.createElement('div');
2933
- this.cancel.setAttribute('style', inlineStyle(cancelStyle));
2934
- this.cancel.textContent = '取消';
2935
- // result
2936
- this.cells.forEach(item => this.menu.appendChild(item));
2937
- this.actionSheet.appendChild(this.menu);
2938
- this.actionSheet.appendChild(this.cancel);
2939
- this.el.appendChild(this.mask);
2940
- this.el.appendChild(this.actionSheet);
2941
- // callbacks
2942
- const cb = () => {
2943
- this.hide();
2944
- resolve('cancel');
2945
- };
2946
- this.mask.onclick = cb;
2947
- this.cancel.onclick = cb;
2948
- // show immediately
2949
- document.body.appendChild(this.el);
2956
+ const chooser = createLocationChooser(res => {
2957
+ window.removeEventListener('message', onMessage, false);
2950
2958
  setTimeout(() => {
2951
- this.el.style.opacity = '1';
2952
- setTransform(this.actionSheet, 'translate(0, 0)');
2953
- }, 0);
2954
- });
2955
- }
2956
- show(options = {}) {
2957
- return new Promise((resolve) => {
2958
- const config = Object.assign(Object.assign({}, this.options), options);
2959
- this.lastConfig = config;
2960
- if (this.hideOpacityTimer)
2961
- clearTimeout(this.hideOpacityTimer);
2962
- if (this.hideDisplayTimer)
2963
- clearTimeout(this.hideDisplayTimer);
2964
- // itemColor
2965
- if (config.itemColor)
2966
- this.menu.style.color = config.itemColor;
2967
- // cells
2968
- const { cellStyle } = this.style;
2969
- config.itemList.forEach((item, index) => {
2970
- let cell;
2971
- if (this.cells[index]) {
2972
- // assign new content
2973
- cell = this.cells[index];
2974
- }
2975
- else {
2976
- // create new cell
2977
- cell = document.createElement('div');
2978
- cell.className = 'taro-actionsheet__cell';
2979
- cell.setAttribute('style', inlineStyle(cellStyle));
2980
- cell.dataset.tapIndex = `${index}`;
2981
- this.cells.push(cell);
2982
- this.menu.appendChild(cell);
2983
- }
2984
- cell.textContent = item;
2985
- cell.onclick = e => {
2986
- this.hide();
2987
- const target = e.currentTarget;
2988
- const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
2989
- resolve(index);
2990
- };
2991
- });
2992
- const cellsLen = this.cells.length;
2993
- const itemListLen = config.itemList.length;
2994
- if (cellsLen > itemListLen) {
2995
- for (let i = itemListLen; i < cellsLen; i++) {
2996
- this.menu.removeChild(this.cells[i]);
2959
+ chooser.remove();
2960
+ }, 300);
2961
+ if (res) {
2962
+ return handle.fail(res, { resolve, reject });
2963
+ }
2964
+ else {
2965
+ if (chooseLocation.latitude && chooseLocation.longitude) {
2966
+ return handle.success(chooseLocation, { resolve, reject });
2967
+ }
2968
+ else {
2969
+ return handle.fail({}, { resolve, reject });
2997
2970
  }
2998
- this.cells.splice(itemListLen);
2999
2971
  }
3000
- // callbacks
3001
- const cb = () => {
3002
- this.hide();
3003
- resolve('cancel');
3004
- };
3005
- this.mask.onclick = cb;
3006
- this.cancel.onclick = cb;
3007
- // show
3008
- this.el.style.display = 'block';
3009
- setTimeout(() => {
3010
- this.el.style.opacity = '1';
3011
- setTransform(this.actionSheet, 'translate(0, 0)');
3012
- }, 0);
3013
- });
3014
- }
3015
- hide() {
3016
- if (this.hideOpacityTimer)
3017
- clearTimeout(this.hideOpacityTimer);
3018
- if (this.hideDisplayTimer)
3019
- clearTimeout(this.hideDisplayTimer);
3020
- this.hideOpacityTimer = setTimeout(() => {
3021
- this.el.style.opacity = '0';
3022
- setTransform(this.actionSheet, 'translate(0, 100%)');
3023
- this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
3024
- }, 0);
3025
- }
3026
- }
2972
+ }, key, mapOpts);
2973
+ document.body.appendChild(chooser.container);
2974
+ window.addEventListener('message', onMessage, false);
2975
+ chooser.show();
2976
+ });
2977
+ };
3027
2978
 
3028
- class Modal {
2979
+ // 位置
2980
+ const stopLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('stopLocationUpdate');
2981
+ const startLocationUpdateBackground = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdateBackground');
2982
+ const startLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdate');
2983
+ const openLocation = /* @__PURE__ */ processOpenApi({
2984
+ name: 'openLocation',
2985
+ defaultOptions: { scale: 18 }
2986
+ });
2987
+ const onLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('onLocationChangeError');
2988
+ const onLocationChange = /* @__PURE__ */ temporarilyNotSupport('onLocationChange');
2989
+ const offLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('offLocationChangeError');
2990
+ const offLocationChange = /* @__PURE__ */ temporarilyNotSupport('offLocationChange');
2991
+ const choosePoi = /* @__PURE__ */ temporarilyNotSupport('choosePoi');
2992
+ const getFuzzyLocation = /* @__PURE__ */ temporarilyNotSupport('getFuzzyLocation');
2993
+
2994
+ class InnerAudioContext {
3029
2995
  constructor() {
3030
- this.options = {
3031
- title: '',
3032
- content: '',
3033
- showCancel: true,
3034
- cancelText: '取消',
3035
- cancelColor: '#000000',
3036
- confirmText: '确定',
3037
- confirmColor: '#3CC51F'
2996
+ this.__startTime = 0;
2997
+ this.__isFirstPlay = true;
2998
+ this.play = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.play(); };
2999
+ this.pause = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.pause(); };
3000
+ this.stop = () => {
3001
+ this.pause();
3002
+ this.seek(0);
3003
+ this.stopStack.trigger();
3038
3004
  };
3039
- this.style = {
3040
- maskStyle: {
3041
- position: 'fixed',
3042
- 'z-index': '1000',
3043
- top: '0',
3044
- right: '0',
3045
- left: '0',
3046
- bottom: '0',
3047
- background: 'rgba(0,0,0,0.6)'
3048
- },
3049
- modalStyle: {
3050
- 'z-index': '4999',
3051
- position: 'fixed',
3052
- top: '50%',
3053
- left: '50%',
3054
- transform: 'translate(-50%, -50%)',
3055
- width: '80%',
3056
- 'max-width': '300px',
3057
- 'border-radius': '3px',
3058
- 'text-align': 'center',
3059
- 'line-height': '1.6',
3060
- overflow: 'hidden',
3061
- background: '#FFFFFF'
3062
- },
3063
- titleStyle: {
3064
- padding: '20px 24px 9px',
3065
- 'font-size': '18px'
3066
- },
3067
- textStyle: {
3068
- padding: '0 24px 12px',
3069
- 'min-height': '40px',
3070
- 'font-size': '15px',
3071
- 'line-height': '1.3',
3072
- color: '#808080'
3073
- },
3074
- footStyle: {
3075
- position: 'relative',
3076
- 'line-height': '48px',
3077
- 'font-size': '18px',
3078
- display: 'flex'
3079
- },
3080
- btnStyle: {
3081
- position: 'relative',
3082
- '-webkit-box-flex': '1',
3083
- '-webkit-flex': '1',
3084
- flex: '1'
3005
+ this.seek = (position) => {
3006
+ if (this.Instance) {
3007
+ this.Instance.currentTime = position;
3085
3008
  }
3086
3009
  };
3087
- }
3088
- create(options = {}) {
3089
- return new Promise((resolve) => {
3090
- var _a, _b;
3091
- // style
3092
- const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
3093
- // configuration
3094
- const config = Object.assign(Object.assign({}, this.options), options);
3095
- // wrapper
3096
- this.el = document.createElement('div');
3097
- this.el.className = 'taro__modal';
3098
- this.el.style.opacity = '0';
3099
- this.el.style.transition = 'opacity 0.2s linear';
3100
- const eventHandler = (e) => {
3101
- e.stopPropagation();
3102
- e.preventDefault();
3103
- };
3104
- // mask
3105
- const mask = document.createElement('div');
3106
- mask.className = 'taro-modal__mask';
3107
- mask.setAttribute('style', inlineStyle(maskStyle));
3108
- mask.ontouchmove = eventHandler;
3109
- // modal
3110
- const modal = document.createElement('div');
3111
- modal.className = 'taro-modal__content';
3112
- modal.setAttribute('style', inlineStyle(modalStyle));
3113
- modal.ontouchmove = eventHandler;
3114
- // title
3115
- const titleCSS = config.title ? titleStyle : Object.assign(Object.assign({}, titleStyle), { display: 'none' });
3116
- this.title = document.createElement('div');
3117
- this.title.className = 'taro-modal__title';
3118
- this.title.setAttribute('style', inlineStyle(titleCSS));
3119
- this.title.textContent = config.title;
3120
- // text
3121
- const textCSS = config.title ? textStyle : Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
3122
- this.text = document.createElement('div');
3123
- this.text.className = 'taro-modal__text';
3124
- this.text.setAttribute('style', inlineStyle(textCSS));
3125
- this.text.textContent = config.content;
3126
- // foot
3127
- const foot = document.createElement('div');
3128
- foot.className = 'taro-modal__foot';
3129
- foot.setAttribute('style', inlineStyle(footStyle));
3130
- // cancel button
3131
- const cancelCSS = Object.assign(Object.assign({}, btnStyle), { color: config.cancelColor, display: config.showCancel ? 'block' : 'none' });
3132
- this.cancel = document.createElement('div');
3133
- this.cancel.className = 'taro-model__btn taro-model__cancel';
3134
- this.cancel.setAttribute('style', inlineStyle(cancelCSS));
3135
- this.cancel.textContent = config.cancelText;
3136
- this.cancel.onclick = () => {
3137
- this.hide();
3138
- resolve('cancel');
3139
- };
3140
- // confirm button
3141
- this.confirm = document.createElement('div');
3142
- this.confirm.className = 'taro-model__btn taro-model__confirm';
3143
- this.confirm.setAttribute('style', inlineStyle(btnStyle));
3144
- this.confirm.style.color = config.confirmColor;
3145
- this.confirm.textContent = config.confirmText;
3146
- this.confirm.onclick = () => {
3147
- this.hide();
3148
- resolve('confirm');
3149
- };
3150
- // result
3151
- foot.appendChild(this.cancel);
3152
- foot.appendChild(this.confirm);
3153
- modal.appendChild(this.title);
3154
- modal.appendChild(this.text);
3155
- modal.appendChild(foot);
3156
- this.el.appendChild(mask);
3157
- this.el.appendChild(modal);
3158
- // show immediately
3159
- document.body.appendChild(this.el);
3160
- setTimeout(() => { this.el.style.opacity = '1'; }, 0);
3161
- // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
3162
- this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
3163
- });
3164
- }
3165
- show(options = {}) {
3166
- return new Promise((resolve) => {
3167
- var _a, _b;
3168
- const config = Object.assign(Object.assign({}, this.options), options);
3169
- if (this.hideOpacityTimer)
3170
- clearTimeout(this.hideOpacityTimer);
3171
- if (this.hideDisplayTimer)
3172
- clearTimeout(this.hideDisplayTimer);
3173
- // title & text
3174
- const { textStyle } = this.style;
3175
- if (config.title) {
3176
- this.title.textContent = config.title;
3177
- // none => block
3178
- this.title.style.display = 'block';
3179
- this.text.setAttribute('style', inlineStyle(textStyle));
3010
+ /**
3011
+ * @TODO destroy得并不干净
3012
+ */
3013
+ this.destroy = () => {
3014
+ this.stop();
3015
+ if (this.Instance) {
3016
+ this.Instance = undefined;
3180
3017
  }
3181
- else {
3182
- this.title.textContent = '';
3183
- // block => none
3184
- this.title.style.display = 'none';
3185
- const textCSS = Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
3186
- this.text.setAttribute('style', inlineStyle(textCSS));
3018
+ };
3019
+ this.onCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', callback); };
3020
+ this.onPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('play', callback); };
3021
+ this.onPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('pause', callback); };
3022
+ this.onStop = (callback = () => { }) => this.stopStack.add(callback);
3023
+ this.onEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', callback); };
3024
+ this.onTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('timeupdate', callback); };
3025
+ this.onError = (callback) => this.errorStack.add(callback);
3026
+ this.onWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('waiting', callback); };
3027
+ this.onSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeking', callback); };
3028
+ this.onSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeked', callback); };
3029
+ this.offCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', callback); };
3030
+ this.offPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('play', callback); };
3031
+ this.offPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('pause', callback); };
3032
+ this.offStop = (callback = () => { }) => this.stopStack.remove(callback);
3033
+ this.offEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', callback); };
3034
+ this.offTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('timeupdate', callback); };
3035
+ this.offError = (callback = () => { }) => this.errorStack.remove(callback);
3036
+ this.offWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('waiting', callback); };
3037
+ this.offSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeking', callback); };
3038
+ this.offSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeked', callback); };
3039
+ this.Instance = new Audio();
3040
+ this.errorStack = new CallbackManager();
3041
+ this.stopStack = new CallbackManager();
3042
+ this.Instance.onerror = this.errorStack.trigger;
3043
+ Taro.eventCenter.on('__taroRouterChange', () => { this.stop(); });
3044
+ this.onPlay(() => {
3045
+ if (this.__isFirstPlay) {
3046
+ this.__isFirstPlay = false;
3047
+ this.seek(this.startTime);
3187
3048
  }
3188
- this.text.textContent = config.content || '';
3189
- // showCancel
3190
- this.cancel.style.display = config.showCancel ? 'block' : 'none';
3191
- // cancelText
3192
- this.cancel.textContent = config.cancelText || '';
3193
- // cancelColor
3194
- this.cancel.style.color = config.cancelColor || '';
3195
- // confirmText
3196
- this.confirm.textContent = config.confirmText || '';
3197
- // confirmColor
3198
- this.confirm.style.color = config.confirmColor || '';
3199
- // cbs
3200
- this.cancel.onclick = () => {
3201
- this.hide();
3202
- resolve('cancel');
3203
- };
3204
- this.confirm.onclick = () => {
3205
- this.hide();
3206
- resolve('confirm');
3207
- };
3208
- // show
3209
- this.el.style.display = 'block';
3210
- setTimeout(() => { this.el.style.opacity = '1'; }, 0);
3211
- // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
3212
- this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
3213
3049
  });
3214
3050
  }
3215
- hide() {
3216
- if (this.hideOpacityTimer)
3217
- clearTimeout(this.hideOpacityTimer);
3218
- if (this.hideDisplayTimer)
3219
- clearTimeout(this.hideDisplayTimer);
3220
- this.currentPath = null;
3221
- this.hideOpacityTimer = setTimeout(() => {
3222
- this.el.style.opacity = '0';
3223
- this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
3224
- }, 0);
3051
+ set autoplay(e) { this.setProperty('autoplay', e); }
3052
+ get autoplay() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.autoplay) || false; }
3053
+ get buffered() {
3054
+ const { currentTime = 0, buffered: timeRange } = this.Instance || {};
3055
+ if (timeRange) {
3056
+ for (let i = 0; i < timeRange.length; i++) {
3057
+ if (timeRange.start(i) <= currentTime && timeRange.end(i) >= currentTime) {
3058
+ return timeRange.end(i);
3059
+ }
3060
+ }
3061
+ }
3062
+ return 0;
3063
+ }
3064
+ get currentTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.currentTime) || 0; }
3065
+ set currentTime(e) { this.seek(e); }
3066
+ get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
3067
+ set loop(e) { this.setProperty('loop', e); }
3068
+ get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
3069
+ get paused() { var _a, _b; return (_b = (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : true; }
3070
+ set src(e) { this.setProperty('src', e); }
3071
+ get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
3072
+ set volume(e) { this.setProperty('volume', e); }
3073
+ get volume() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.volume) || 0; }
3074
+ set playbackRate(e) { this.setProperty('playbackRate', e); }
3075
+ get playbackRate() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.playbackRate) || 0; }
3076
+ set obeyMuteSwitch(_e) { permanentlyNotSupport('InnerAudioContext.obeyMuteSwitch')(); }
3077
+ get obeyMuteSwitch() { return true; }
3078
+ set startTime(e) { this.__startTime = e; }
3079
+ get startTime() { return this.__startTime || 0; }
3080
+ set referrerPolicy(e) { var _a; (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.setAttribute('referrerpolicy', e); }
3081
+ get referrerPolicy() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.getAttribute('referrerpolicy')) || 'origin'; }
3082
+ setProperty(key, value) {
3083
+ if (this.Instance) {
3084
+ this.Instance[key] = value;
3085
+ }
3225
3086
  }
3226
3087
  }
3227
3088
 
3228
- class Toast {
3089
+ // 音频
3090
+ const stopVoice = /* @__PURE__ */ temporarilyNotSupport('stopVoice');
3091
+ const setInnerAudioOption = /* @__PURE__ */ temporarilyNotSupport('setInnerAudioOption');
3092
+ const playVoice = /* @__PURE__ */ temporarilyNotSupport('playVoice');
3093
+ const pauseVoice = /* @__PURE__ */ temporarilyNotSupport('pauseVoice');
3094
+ const getAvailableAudioSources = /* @__PURE__ */ temporarilyNotSupport('getAvailableAudioSources');
3095
+ const createWebAudioContext = /* @__PURE__ */ temporarilyNotSupport('createWebAudioContext');
3096
+ const createMediaAudioPlayer = /* @__PURE__ */ temporarilyNotSupport('createMediaAudioPlayer');
3097
+ /**
3098
+ * 创建内部 audio 上下文 InnerAudioContext 对象。
3099
+ */
3100
+ const createInnerAudioContext = () => new InnerAudioContext();
3101
+ const createAudioContext = /* @__PURE__ */ temporarilyNotSupport('createAudioContext');
3102
+
3103
+ class BackgroundAudioManager {
3229
3104
  constructor() {
3230
- this.options = {
3231
- title: '',
3232
- icon: 'none',
3233
- image: '',
3234
- duration: 1500,
3235
- mask: false
3236
- };
3237
- this.style = {
3238
- maskStyle: {
3239
- position: 'fixed',
3240
- 'z-index': '1000',
3241
- top: '0',
3242
- right: '0',
3243
- left: '0',
3244
- bottom: '0'
3245
- },
3246
- toastStyle: {
3247
- 'z-index': '5000',
3248
- 'box-sizing': 'border-box',
3249
- display: 'flex',
3250
- 'flex-direction': 'column',
3251
- 'justify-content': 'center',
3252
- '-webkit-justify-content': 'center',
3253
- position: 'fixed',
3254
- top: '50%',
3255
- left: '50%',
3256
- 'min-width': '120px',
3257
- 'max-width': '200px',
3258
- 'min-height': '120px',
3259
- padding: '15px',
3260
- transform: 'translate(-50%, -50%)',
3261
- 'border-radius': '5px',
3262
- 'text-align': 'center',
3263
- 'line-height': '1.6',
3264
- color: '#FFFFFF',
3265
- background: 'rgba(17, 17, 17, 0.7)'
3266
- },
3267
- successStyle: {
3268
- margin: '6px auto',
3269
- width: '38px',
3270
- height: '38px',
3271
- background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTQ4OTYzMjA0IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjQzNDgiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNMjE5Ljk1MiA1MTIuNTc2bDIxMC40MzIgMjEwLjQzMi00NS4yNDggNDUuMjU2LTIxMC40MzItMjEwLjQzMnoiIHAtaWQ9IjQzNDkiIGZpbGw9IiNmZmZmZmYiPjwvcGF0aD48cGF0aCBkPSJNNzk5LjY3MiAyNjIuMjY0bDQ1LjI1NiA0NS4yNTYtNDYwLjQ2NCA0NjAuNDY0LTQ1LjI1Ni00NS4yNTZ6IiBwLWlkPSI0MzUwIiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
3272
- 'background-size': '100%'
3273
- },
3274
- errrorStyle: {
3275
- margin: '6px auto',
3276
- width: '38px',
3277
- height: '38px',
3278
- background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTUxMDU1MTgzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjE0MDc2IiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PHBhdGggZD0iTTUxMiA2NEMyNjQuNTggNjQgNjQgMjY0LjU4IDY0IDUxMnMyMDAuNTggNDQ4IDQ0OCA0NDggNDQ4LTIwMC41OCA0NDgtNDQ4Uzc1OS40MiA2NCA1MTIgNjR6IG0wIDc1MmEzNiAzNiAwIDEgMSAzNi0zNiAzNiAzNiAwIDAgMS0zNiAzNnogbTUxLjgzLTU1MS45NUw1NDggNjM2YTM2IDM2IDAgMCAxLTcyIDBsLTE1LjgzLTM3MS45NWMtMC4xLTEuMzMtMC4xNy0yLjY4LTAuMTctNC4wNWE1MiA1MiAwIDAgMSAxMDQgMGMwIDEuMzctMC4wNyAyLjcyLTAuMTcgNC4wNXoiIHAtaWQ9IjE0MDc3IiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
3279
- 'background-size': '100%'
3280
- },
3281
- loadingStyle: {
3282
- margin: '6px auto',
3283
- width: '38px',
3284
- height: '38px',
3285
- '-webkit-animation': 'taroLoading 1s steps(12, end) infinite',
3286
- animation: 'taroLoading 1s steps(12, end) infinite',
3287
- background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iMTIwIiB2aWV3Qm94PSIwIDAgMTAwIDEwMCI+PHBhdGggZmlsbD0ibm9uZSIgZD0iTTAgMGgxMDB2MTAwSDB6Ii8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTlFOUU5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTMwKSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iIzk4OTY5NyIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgzMCAxMDUuOTggNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjOUI5OTlBIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDYwIDc1Ljk4IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0EzQTFBMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSg5MCA2NSA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNBQkE5QUEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoMTIwIDU4LjY2IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0IyQjJCMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgxNTAgNTQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjQkFCOEI5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDE4MCA1MCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDMkMwQzEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTE1MCA0NS45OCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDQkNCQ0IiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTEyMCA0MS4zNCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNEMkQyRDIiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTkwIDM1IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0RBREFEQSIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgtNjAgMjQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTJFMkUyIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKC0zMCAtNS45OCA2NSkiLz48L3N2Zz4=) no-repeat',
3288
- 'background-size': '100%'
3289
- },
3290
- imageStyle: {
3291
- margin: '6px auto',
3292
- width: '40px',
3293
- height: '40px',
3294
- background: 'transparent no-repeat',
3295
- 'background-size': '100%'
3296
- },
3297
- textStyle: {
3298
- margin: '0',
3299
- 'font-size': '16px'
3105
+ this.__startTime = 0;
3106
+ this.play = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.play(); };
3107
+ this.pause = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.pause(); };
3108
+ this.seek = (position) => {
3109
+ if (this.Instance) {
3110
+ this.Instance.currentTime = position;
3300
3111
  }
3301
3112
  };
3302
- }
3303
- create(options = {}, _type = 'toast') {
3304
- var _a, _b;
3305
- // style
3306
- const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style;
3307
- // configuration
3308
- const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
3309
- // wrapper
3310
- this.el = document.createElement('div');
3311
- this.el.className = 'taro__toast';
3312
- this.el.style.opacity = '0';
3313
- this.el.style.transition = 'opacity 0.1s linear';
3314
- this.el.ontouchmove = (e) => {
3315
- e.stopPropagation();
3316
- e.preventDefault();
3113
+ this.stop = () => {
3114
+ this.pause();
3115
+ this.seek(0);
3116
+ this.stopStack.trigger();
3317
3117
  };
3318
- // mask
3319
- this.mask = document.createElement('div');
3320
- this.mask.setAttribute('style', inlineStyle(maskStyle));
3321
- this.mask.style.display = config.mask ? 'block' : 'none';
3322
- // icon
3323
- this.icon = document.createElement('p');
3324
- if (config.image) {
3325
- this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, imageStyle), { 'background-image': `url(${config.image})` })));
3118
+ this.onCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', callback); };
3119
+ this.onWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('waiting', callback); };
3120
+ this.onError = (callback) => this.errorStack.add(callback);
3121
+ this.onPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('play', callback); };
3122
+ this.onPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('pause', callback); };
3123
+ this.onSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeking', callback); };
3124
+ this.onSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeked', callback); };
3125
+ this.onEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', callback); };
3126
+ this.onStop = (callback = () => { }) => this.stopStack.add(callback);
3127
+ this.onTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('timeupdate', callback); };
3128
+ this.onPrev = permanentlyNotSupport('BackgroundAudioManager.onPrev');
3129
+ this.onNext = permanentlyNotSupport('BackgroundAudioManager.onNext');
3130
+ this.offCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', callback); };
3131
+ this.offWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('waiting', callback); };
3132
+ this.offError = (callback = () => { }) => this.errorStack.remove(callback);
3133
+ this.offPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('play', callback); };
3134
+ this.offPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('pause', callback); };
3135
+ this.offSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeking', callback); };
3136
+ this.offSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeked', callback); };
3137
+ this.offEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', callback); };
3138
+ this.offStop = (callback = () => { }) => this.stopStack.remove(callback);
3139
+ this.offTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('timeupdate', callback); };
3140
+ this.offPrev = permanentlyNotSupport('BackgroundAudioManager.offPrev');
3141
+ this.offNext = permanentlyNotSupport('BackgroundAudioManager.offNext');
3142
+ this.Instance = new Audio();
3143
+ this.errorStack = new CallbackManager();
3144
+ this.stopStack = new CallbackManager();
3145
+ this.Instance.onerror = this.errorStack.trigger;
3146
+ this.Instance.autoplay = true;
3147
+ this.onPlay(() => {
3148
+ if (this.currentTime !== this.startTime) {
3149
+ this.seek(this.startTime);
3150
+ }
3151
+ });
3152
+ }
3153
+ set src(e) { this.setProperty('src', e); }
3154
+ get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
3155
+ set startTime(e) { this.__startTime = e; }
3156
+ get startTime() { return this.__startTime || 0; }
3157
+ set title(e) { this.dataset('title', e); }
3158
+ get title() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.title) || ''; }
3159
+ set epname(e) { this.dataset('epname', e); }
3160
+ get epname() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.epname) || ''; }
3161
+ set singer(e) { this.dataset('singer', e); }
3162
+ get singer() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.singer) || ''; }
3163
+ set coverImgUrl(e) { this.dataset('coverImgUrl', e); }
3164
+ get coverImgUrl() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.coverImgUrl) || ''; }
3165
+ set webUrl(e) { this.dataset('webUrl', e); }
3166
+ get webUrl() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.webUrl) || ''; }
3167
+ set protocol(e) { this.dataset('protocol', e); }
3168
+ get protocol() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.protocol) || ''; }
3169
+ set playbackRate(e) { this.setProperty('playbackRate', e); }
3170
+ get playbackRate() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.playbackRate) || 0; }
3171
+ get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
3172
+ get currentTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.currentTime) || 0; }
3173
+ get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || false; }
3174
+ get buffered() {
3175
+ const { currentTime = 0, buffered: timeRange } = this.Instance || {};
3176
+ if (timeRange) {
3177
+ for (let i = 0; i < timeRange.length; i++) {
3178
+ if (timeRange.start(i) <= currentTime && timeRange.end(i) >= currentTime) {
3179
+ return timeRange.end(i);
3180
+ }
3181
+ }
3326
3182
  }
3327
- else {
3328
- const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
3329
- this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, iconStyle), (config.icon === 'none' ? { display: 'none' } : {}))));
3183
+ return 0;
3184
+ }
3185
+ set referrerPolicy(e) { var _a; (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.setAttribute('referrerpolicy', e); }
3186
+ get referrerPolicy() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.getAttribute('referrerpolicy')) || 'origin'; }
3187
+ setProperty(key, value) {
3188
+ if (this.Instance) {
3189
+ this.Instance[key] = value;
3330
3190
  }
3331
- // toast
3332
- this.toast = document.createElement('div');
3333
- this.toast.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, toastStyle), (config.icon === 'none' ? {
3334
- 'min-height': '0',
3335
- padding: '10px 15px'
3336
- } : {}))));
3337
- // title
3338
- this.title = document.createElement('p');
3339
- this.title.setAttribute('style', inlineStyle(textStyle));
3340
- this.title.textContent = config.title;
3341
- // result
3342
- this.toast.appendChild(this.icon);
3343
- this.toast.appendChild(this.title);
3344
- this.el.appendChild(this.mask);
3345
- this.el.appendChild(this.toast);
3346
- // show immediately
3347
- document.body.appendChild(this.el);
3348
- setTimeout(() => { this.el.style.opacity = '1'; }, 0);
3349
- this.type = config._type;
3350
- // disappear after duration
3351
- config.duration >= 0 && this.hide(config.duration, this.type);
3352
- // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
3353
- this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
3354
- return '';
3355
3191
  }
3356
- show(options = {}, _type = 'toast') {
3357
- var _a, _b;
3358
- const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
3359
- if (this.hideOpacityTimer)
3360
- clearTimeout(this.hideOpacityTimer);
3361
- if (this.hideDisplayTimer)
3362
- clearTimeout(this.hideDisplayTimer);
3363
- // title
3364
- this.title.textContent = config.title || '';
3365
- // mask
3366
- this.mask.style.display = config.mask ? 'block' : 'none';
3367
- // image
3368
- const { toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle } = this.style;
3369
- if (config.image) {
3370
- this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, imageStyle), { 'background-image': `url(${config.image})` })));
3192
+ dataset(key, value) {
3193
+ if (this.Instance) {
3194
+ this.Instance.dataset[key] = value;
3371
3195
  }
3372
- else {
3373
- if (!config.image && config.icon) {
3374
- const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
3375
- this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, iconStyle), (config.icon === 'none' ? { display: 'none' } : {}))));
3376
- }
3196
+ }
3197
+ }
3198
+
3199
+ // 背景音频
3200
+ const stopBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('stopBackgroundAudio');
3201
+ const seekBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('seekBackgroundAudio');
3202
+ const playBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('playBackgroundAudio');
3203
+ const pauseBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('pauseBackgroundAudio');
3204
+ const onBackgroundAudioStop = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioStop');
3205
+ const onBackgroundAudioPlay = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioPlay');
3206
+ const onBackgroundAudioPause = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioPause');
3207
+ const getBackgroundAudioPlayerState = /* @__PURE__ */ temporarilyNotSupport('getBackgroundAudioPlayerState');
3208
+ /**
3209
+ * 获取全局唯一的背景音频管理器
3210
+ */
3211
+ const getBackgroundAudioManager = () => new BackgroundAudioManager();
3212
+
3213
+ // 相机
3214
+ const createCameraContext = /* @__PURE__ */ temporarilyNotSupport('createCameraContext');
3215
+
3216
+ const saveImageToPhotosAlbum = (options) => {
3217
+ const methodName = 'saveImageToPhotosAlbum';
3218
+ // options must be an Object
3219
+ const isObject = shouldBeObject(options);
3220
+ if (!isObject.flag) {
3221
+ const res = { errMsg: `${methodName}:fail ${isObject.msg}` };
3222
+ console.error(res.errMsg);
3223
+ return Promise.reject(res);
3224
+ }
3225
+ const { filePath, success, fail, complete, } = options;
3226
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
3227
+ if (typeof filePath !== 'string') {
3228
+ return handle.fail({
3229
+ errMsg: getParameterError({
3230
+ para: 'filePath',
3231
+ correct: 'String',
3232
+ wrong: filePath
3233
+ })
3234
+ });
3235
+ }
3236
+ createDownload(filePath);
3237
+ return handle.success();
3238
+ };
3239
+
3240
+ /**
3241
+ * 获取图片信息。网络图片需先配置download域名才能生效。
3242
+ */
3243
+ const getImageInfo = (options) => {
3244
+ // options must be an Object
3245
+ const isObject = shouldBeObject(options);
3246
+ if (!isObject.flag) {
3247
+ const res = { errMsg: `getImageInfo:fail ${isObject.msg}` };
3248
+ console.error(res.errMsg);
3249
+ return Promise.reject(res);
3250
+ }
3251
+ const getBase64Image = (image) => {
3252
+ try {
3253
+ const canvas = document.createElement('canvas');
3254
+ canvas.width = image.width;
3255
+ canvas.height = image.height;
3256
+ const ctx = canvas.getContext('2d');
3257
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(image, 0, 0, image.width, image.height);
3258
+ return canvas.toDataURL('image/png');
3377
3259
  }
3378
- // toast
3379
- this.toast.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, toastStyle), (config.icon === 'none' ? {
3380
- 'min-height': '0',
3381
- padding: '10px 15px'
3382
- } : {}))));
3383
- // show
3384
- this.el.style.display = 'block';
3385
- setTimeout(() => { this.el.style.opacity = '1'; }, 0);
3386
- this.type = config._type;
3387
- // disappear after duration
3388
- config.duration >= 0 && this.hide(config.duration, this.type);
3389
- // Current.page不存在时说明路由还未挂载,此时需根据url来分配将要渲染的页面path
3390
- this.currentPath = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : getCurrentPath();
3391
- return '';
3260
+ catch (e) {
3261
+ console.error('getImageInfo:get base64 fail', e);
3262
+ }
3263
+ };
3264
+ const { src, success, fail, complete } = options;
3265
+ const handle = new MethodHandler({ name: 'getImageInfo', success, fail, complete });
3266
+ return new Promise((resolve, reject) => {
3267
+ const image = new Image();
3268
+ image.crossOrigin = '';
3269
+ image.onload = () => {
3270
+ handle.success({
3271
+ width: image.naturalWidth,
3272
+ height: image.naturalHeight,
3273
+ path: getBase64Image(image) || src
3274
+ }, { resolve, reject });
3275
+ };
3276
+ image.onerror = (e) => {
3277
+ handle.fail({
3278
+ errMsg: e.message
3279
+ }, { resolve, reject });
3280
+ };
3281
+ image.src = src;
3282
+ });
3283
+ };
3284
+
3285
+ /**
3286
+ * previewImage api基于开源的React组件[react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer)开发,感谢!
3287
+ */
3288
+ /**
3289
+ * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。
3290
+ */
3291
+ const previewImage = (options) => tslib.__awaiter(void 0, void 0, void 0, function* () {
3292
+ // TODO 改为通过 window.__taroAppConfig 获取配置的 Swiper 插件创建节点
3293
+ components.defineCustomElementTaroSwiperCore();
3294
+ components.defineCustomElementTaroSwiperItemCore();
3295
+ function loadImage(url, loadFail) {
3296
+ return new Promise((resolve) => {
3297
+ const item = document.createElement('taro-swiper-item-core');
3298
+ item.style.cssText = 'display:flex;align-items:start;justify-content:center;overflow-y:scroll;';
3299
+ const image = new Image();
3300
+ image.style.maxWidth = '100%';
3301
+ image.src = url;
3302
+ const div = document.createElement('div');
3303
+ div.classList.add('swiper-zoom-container');
3304
+ div.style.cssText = 'display:flex;align-items:center;justify-content:center;max-width:100%;min-height:100%;';
3305
+ div.appendChild(image);
3306
+ item.appendChild(div);
3307
+ // Note: 等待图片加载完后返回,会导致轮播被卡住
3308
+ resolve(item);
3309
+ if (shared.isFunction(loadFail)) {
3310
+ image.addEventListener('error', (err) => {
3311
+ loadFail({ errMsg: err.message });
3312
+ });
3313
+ }
3314
+ });
3392
3315
  }
3393
- hide(duration = 0, type = '') {
3394
- if (type && type !== this.type)
3395
- return;
3396
- if (this.hideOpacityTimer)
3397
- clearTimeout(this.hideOpacityTimer);
3398
- if (this.hideDisplayTimer)
3399
- clearTimeout(this.hideDisplayTimer);
3400
- this.currentPath = null;
3401
- this.hideOpacityTimer = setTimeout(() => {
3402
- this.el.style.opacity = '0';
3403
- this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 100);
3404
- }, duration);
3316
+ // options must be an Object
3317
+ const isObject = shouldBeObject(options);
3318
+ if (!isObject.flag) {
3319
+ const res = { errMsg: `previewImage:fail ${isObject.msg}` };
3320
+ console.error(res.errMsg);
3321
+ return Promise.reject(res);
3322
+ }
3323
+ const { urls = [], current = '', success, fail, complete } = options;
3324
+ const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
3325
+ const container = document.createElement('div');
3326
+ const removeHandler = () => {
3327
+ runtime.eventCenter.off('__taroRouterChange', removeHandler);
3328
+ container.remove();
3329
+ };
3330
+ // 路由改变后应该关闭预览框
3331
+ runtime.eventCenter.on('__taroRouterChange', removeHandler);
3332
+ container.classList.add('preview-image');
3333
+ container.style.cssText =
3334
+ 'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
3335
+ container.addEventListener('click', removeHandler);
3336
+ const swiper = document.createElement('taro-swiper-core');
3337
+ // @ts-ignore
3338
+ swiper.full = true;
3339
+ // @ts-ignore
3340
+ swiper.zoom = true;
3341
+ let children = [];
3342
+ try {
3343
+ children = yield Promise.all(urls.map((e) => loadImage(e, fail)));
3344
+ }
3345
+ catch (error) {
3346
+ return handle.fail({
3347
+ errMsg: error,
3348
+ });
3349
+ }
3350
+ for (let i = 0; i < children.length; i++) {
3351
+ const child = children[i];
3352
+ swiper.appendChild(child);
3353
+ }
3354
+ const currentIndex = typeof current === 'number' ? current : urls.indexOf(current);
3355
+ swiper.current = currentIndex;
3356
+ container.appendChild(swiper);
3357
+ document.body.appendChild(container);
3358
+ return handle.success();
3359
+ });
3360
+
3361
+ /**
3362
+ * H5 下的 styleSheet 操作
3363
+ * @author leeenx
3364
+ */
3365
+ class StyleSheet {
3366
+ constructor() {
3367
+ this.$style = null;
3368
+ this.sheet = null;
3369
+ this.appendStyleSheet = () => {
3370
+ if (this.$style) {
3371
+ const head = document.getElementsByTagName('head')[0];
3372
+ this.$style.setAttribute('type', 'text/css');
3373
+ this.$style.setAttribute('data-type', 'Taro');
3374
+ head.appendChild(this.$style);
3375
+ this.sheet = this.$style.sheet;
3376
+ }
3377
+ if (this.sheet && !('insertRule' in this.sheet)) {
3378
+ console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
3379
+ }
3380
+ };
3381
+ // 添加样式命令
3382
+ this.add = (cssText, index = 0) => {
3383
+ var _a;
3384
+ if (this.sheet === null) {
3385
+ // $style 未插入到 DOM
3386
+ this.appendStyleSheet();
3387
+ }
3388
+ (_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
3389
+ };
3390
+ this.$style = document.createElement('style');
3405
3391
  }
3406
3392
  }
3407
-
3408
- // 交互
3409
- let status = 'default';
3410
- // inject necessary style
3411
- function init(doc) {
3412
- if (status === 'ready')
3413
- return;
3414
- const taroStyle = doc.createElement('style');
3415
- taroStyle.textContent = '@font-face{font-weight:normal;font-style:normal;font-family:"taro";src:url("data:application/x-font-ttf;charset=utf-8;base64, AAEAAAALAIAAAwAwR1NVQrD+s+0AAAE4AAAAQk9TLzJWs0t/AAABfAAAAFZjbWFwqVgGvgAAAeAAAAGGZ2x5Zph7qG0AAANwAAAAdGhlYWQRFoGhAAAA4AAAADZoaGVhCCsD7AAAALwAAAAkaG10eAg0AAAAAAHUAAAADGxvY2EADAA6AAADaAAAAAhtYXhwAQ4AJAAAARgAAAAgbmFtZYrphEEAAAPkAAACVXBvc3S3shtSAAAGPAAAADUAAQAAA+gAAABaA+gAAAAAA+gAAQAAAAAAAAAAAAAAAAAAAAMAAQAAAAEAAADih+FfDzz1AAsD6AAAAADXB57LAAAAANcHnssAAP/sA+gDOgAAAAgAAgAAAAAAAAABAAAAAwAYAAEAAAAAAAIAAAAKAAoAAAD/AAAAAAAAAAEAAAAKAB4ALAABREZMVAAIAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAAAAQK8AZAABQAIAnoCvAAAAIwCegK8AAAB4AAxAQIAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABAAHjqCAPoAAAAWgPoABQAAAABAAAAAAAAA+gAAABkAAAD6AAAAAAABQAAAAMAAAAsAAAABAAAAV4AAQAAAAAAWAADAAEAAAAsAAMACgAAAV4ABAAsAAAABgAEAAEAAgB46gj//wAAAHjqCP//AAAAAAABAAYABgAAAAEAAgAAAQYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAKAAAAAAAAAACAAAAeAAAAHgAAAABAADqCAAA6ggAAAACAAAAAAAAAAwAOgABAAD/7AAyABQAAgAANzMVFB4UKAAAAAABAAAAAAO7AzoAFwAAEy4BPwE+AR8BFjY3ATYWFycWFAcBBiInPQoGBwUHGgzLDCELAh0LHwsNCgr9uQoeCgGzCyEOCw0HCZMJAQoBvgkCCg0LHQv9sQsKAAAAAAAAEgDeAAEAAAAAAAAAHQAAAAEAAAAAAAEABAAdAAEAAAAAAAIABwAhAAEAAAAAAAMABAAoAAEAAAAAAAQABAAsAAEAAAAAAAUACwAwAAEAAAAAAAYABAA7AAEAAAAAAAoAKwA/AAEAAAAAAAsAEwBqAAMAAQQJAAAAOgB9AAMAAQQJAAEACAC3AAMAAQQJAAIADgC/AAMAAQQJAAMACADNAAMAAQQJAAQACADVAAMAAQQJAAUAFgDdAAMAAQQJAAYACADzAAMAAQQJAAoAVgD7AAMAAQQJAAsAJgFRCiAgQ3JlYXRlZCBieSBmb250LWNhcnJpZXIKICB3ZXVpUmVndWxhcndldWl3ZXVpVmVyc2lvbiAxLjB3ZXVpR2VuZXJhdGVkIGJ5IHN2ZzJ0dGYgZnJvbSBGb250ZWxsbyBwcm9qZWN0Lmh0dHA6Ly9mb250ZWxsby5jb20ACgAgACAAQwByAGUAYQB0AGUAZAAgAGIAeQAgAGYAbwBuAHQALQBjAGEAcgByAGkAZQByAAoAIAAgAHcAZQB1AGkAUgBlAGcAdQBsAGEAcgB3AGUAdQBpAHcAZQB1AGkAVgBlAHIAcwBpAG8AbgAgADEALgAwAHcAZQB1AGkARwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABzAHYAZwAyAHQAdABmACAAZgByAG8AbQAgAEYAbwBuAHQAZQBsAGwAbwAgAHAAcgBvAGoAZQBjAHQALgBoAHQAdABwADoALwAvAGYAbwBuAHQAZQBsAGwAbwAuAGMAbwBtAAAAAAIAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwECAQMBBAABeAd1bmlFQTA4AAAAAAA=") format("truetype");}@-webkit-keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}@keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}.taro-modal__foot:after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);} .taro-model__btn:active {background-color: #EEEEEE}.taro-model__btn:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;width: 1px;bottom: 0;border-left: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleX(0.5);transform: scaleX(0.5);}.taro-actionsheet__cell:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #e5e5e5;color: #e5e5e5;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}';
3416
- doc.querySelector('head').appendChild(taroStyle);
3417
- status = 'ready';
3393
+ const styleSheet = new StyleSheet();
3394
+ // 监听事件
3395
+ let TRANSITION_END = 'transitionend';
3396
+ let TRANSFORM = 'transform';
3397
+ const $detect = document.createElement('div');
3398
+ $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;';
3399
+ if ($detect.style['animation-name'] === 'standard') {
3400
+ // 支持标准写法
3401
+ TRANSITION_END = 'transitionend';
3402
+ TRANSFORM = 'transform';
3418
3403
  }
3419
- const toast = new Toast();
3420
- const modal = new Modal();
3421
- const actionSheet = new ActionSheet();
3422
- const showToast = (options = { title: '' }) => {
3423
- init(document);
3424
- options = Object.assign({
3425
- title: '',
3426
- icon: 'success',
3427
- image: '',
3428
- duration: 1500,
3429
- mask: false
3430
- }, options);
3431
- const { success, fail, complete } = options;
3432
- const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
3433
- if (typeof options.title !== 'string') {
3434
- return handle.fail({
3435
- errMsg: getParameterError({
3436
- para: 'title',
3437
- correct: 'String',
3438
- wrong: options.title
3439
- })
3404
+ else if ($detect.style['-webkit-animation-name'] === 'webkit') {
3405
+ // webkit 前缀
3406
+ TRANSITION_END = 'webkitTransitionEnd';
3407
+ TRANSFORM = '-webkit-transform';
3408
+ }
3409
+ else if ($detect.style['-moz-animation-name'] === 'moz') {
3410
+ // moz 前缀
3411
+ TRANSITION_END = 'mozTransitionEnd';
3412
+ TRANSFORM = '-moz-transform';
3413
+ }
3414
+ else if ($detect.style['-ms-animation-name'] === 'ms') {
3415
+ // ms 前缀
3416
+ TRANSITION_END = 'msTransitionEnd';
3417
+ TRANSFORM = '-ms-transform';
3418
+ }
3419
+ let animId = 0;
3420
+ class Animation {
3421
+ constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
3422
+ // 属性组合
3423
+ this.rules = [];
3424
+ // transform 对象
3425
+ this.transform = [];
3426
+ // 组合动画
3427
+ this.steps = [];
3428
+ // 动画 map ----- 永久保留
3429
+ this.animationMap = {};
3430
+ // animationMap 的长度
3431
+ this.animationMapCount = 0;
3432
+ // 历史动画
3433
+ this.historyAnimations = [];
3434
+ // 历史规则
3435
+ this.historyRules = [];
3436
+ // 默认值
3437
+ this.setDefault(duration, delay, timingFunction, transformOrigin);
3438
+ this.unit = unit;
3439
+ // atom 环境下,animation 属性不会显示,所以要改成 data-animation
3440
+ let animAttr = 'animation';
3441
+ // 动画 id
3442
+ this.id = ++animId;
3443
+ // 监听事件
3444
+ document.body.addEventListener(TRANSITION_END, (e) => {
3445
+ const target = e.target;
3446
+ if (target.getAttribute(animAttr) === null) {
3447
+ animAttr = 'data-animation';
3448
+ }
3449
+ const animData = target.getAttribute(animAttr);
3450
+ // 没有动画存在
3451
+ if (animData === null)
3452
+ return;
3453
+ const [animName, animPath] = animData.split('__');
3454
+ if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
3455
+ const [animIndex, __stepIndex = 0] = animPath.split('--');
3456
+ const stepIndex = Number(__stepIndex);
3457
+ // 动画总的关键帧
3458
+ const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
3459
+ const animStepsMaxIndex = animStepsCount - 1;
3460
+ if (stepIndex < animStepsMaxIndex) {
3461
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
3462
+ target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
3463
+ if (animAttr === 'data-animation') {
3464
+ // Nerv 环境,animation & data-animation 双重保险
3465
+ target.setAttribute('animation', `${animName}__${animIndex}--${stepIndex + 1}`);
3466
+ }
3467
+ }
3468
+ }
3440
3469
  });
3441
3470
  }
3442
- if (typeof options.duration !== 'number') {
3443
- return handle.fail({
3444
- errMsg: getParameterError({
3445
- para: 'duration',
3446
- correct: 'Number',
3447
- wrong: options.duration
3448
- })
3471
+ transformUnit(...args) {
3472
+ const ret = [];
3473
+ args.forEach(each => {
3474
+ ret.push(isNaN(each) ? each : `${each}${this.unit}`);
3449
3475
  });
3476
+ return ret;
3450
3477
  }
3451
- if (options.image && typeof options.image !== 'string')
3452
- options.image = '';
3453
- options.mask = !!options.mask;
3454
- let errMsg = '';
3455
- if (!toast.el) {
3456
- errMsg = toast.create(options, 'toast');
3478
+ // 设置默认值
3479
+ setDefault(duration, delay, timingFunction, transformOrigin) {
3480
+ this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
3457
3481
  }
3458
- else {
3459
- errMsg = toast.show(options, 'toast');
3482
+ matrix(a, b, c, d, tx, ty) {
3483
+ this.transform.push({ key: 'matrix', transform: `matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})` });
3484
+ return this;
3460
3485
  }
3461
- return handle.success({ errMsg });
3462
- };
3463
- const hideToast = ({ noConflict = false, success, fail, complete } = {}) => {
3464
- const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
3465
- if (!toast.el)
3466
- return handle.success();
3467
- toast.hide(0, noConflict ? 'toast' : '');
3468
- return handle.success();
3469
- };
3470
- const showLoading = (options = { title: '' }) => {
3471
- init(document);
3472
- options = Object.assign({
3473
- title: '',
3474
- mask: false
3475
- }, options);
3476
- const { success, fail, complete } = options;
3477
- const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
3478
- const config = {
3479
- icon: 'loading',
3480
- image: '',
3481
- duration: -1
3482
- };
3483
- options = Object.assign({}, options, config);
3484
- if (typeof options.title !== 'string') {
3485
- return handle.fail({
3486
- errMsg: getParameterError({
3487
- para: 'title',
3488
- correct: 'String',
3489
- wrong: options.title
3490
- })
3486
+ matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
3487
+ this.transform.push({
3488
+ key: 'matrix3d',
3489
+ transform: `matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`,
3491
3490
  });
3491
+ return this;
3492
3492
  }
3493
- options.mask = !!options.mask;
3494
- let errMsg = '';
3495
- if (!toast.el) {
3496
- errMsg = toast.create(options, 'loading');
3493
+ rotate(angle) {
3494
+ this.transform.push({ key: 'rotate', transform: `rotate(${angle}deg)` });
3495
+ return this;
3497
3496
  }
3498
- else {
3499
- errMsg = toast.show(options, 'loading');
3497
+ rotate3d(x, y, z, angle) {
3498
+ if (typeof y !== 'number') {
3499
+ this.transform.push({ key: 'rotate3d', transform: `rotate3d(${x})` });
3500
+ }
3501
+ else {
3502
+ this.transform.push({ key: 'rotate3d', transform: `rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)` });
3503
+ }
3504
+ return this;
3500
3505
  }
3501
- return handle.success({ errMsg });
3502
- };
3503
- const hideLoading = ({ noConflict = false, success, fail, complete } = {}) => {
3504
- const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
3505
- if (!toast.el)
3506
- return handle.success();
3507
- toast.hide(0, noConflict ? 'loading' : '');
3508
- return handle.success();
3509
- };
3510
- const showModal = (options = {}) => tslib.__awaiter(void 0, void 0, void 0, function* () {
3511
- init(document);
3512
- options = Object.assign({
3513
- title: '',
3514
- content: '',
3515
- showCancel: true,
3516
- cancelText: '取消',
3517
- cancelColor: '#000000',
3518
- confirmText: '确定',
3519
- confirmColor: '#3CC51F'
3520
- }, options);
3521
- const { success, fail, complete } = options;
3522
- const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
3523
- if (typeof options.title !== 'string') {
3524
- return handle.fail({
3525
- errMsg: getParameterError({
3526
- para: 'title',
3527
- correct: 'String',
3528
- wrong: options.title
3529
- })
3530
- });
3506
+ rotateX(angle) {
3507
+ this.transform.push({ key: 'rotateX', transform: `rotateX(${angle}deg)` });
3508
+ return this;
3531
3509
  }
3532
- if (typeof options.content !== 'string') {
3533
- return handle.fail({
3534
- errMsg: getParameterError({
3535
- para: 'content',
3536
- correct: 'String',
3537
- wrong: options.content
3538
- })
3539
- });
3510
+ rotateY(angle) {
3511
+ this.transform.push({ key: 'rotateY', transform: `rotateY(${angle}deg)` });
3512
+ return this;
3513
+ }
3514
+ rotateZ(angle) {
3515
+ this.transform.push({ key: 'rotateZ', transform: `rotateZ(${angle}deg)` });
3516
+ return this;
3517
+ }
3518
+ scale(x, y) {
3519
+ const scaleY = (typeof y !== 'undefined' && y !== null) ? y : x;
3520
+ this.transform.push({ key: 'scale', transform: `scale(${x}, ${scaleY})` });
3521
+ return this;
3522
+ }
3523
+ scale3d(x, y, z) {
3524
+ this.transform.push({ key: 'scale3d', transform: `scale3d(${x}, ${y}, ${z})` });
3525
+ return this;
3526
+ }
3527
+ scaleX(scale) {
3528
+ this.transform.push({ key: 'scaleX', transform: `scaleX(${scale})` });
3529
+ return this;
3530
+ }
3531
+ scaleY(scale) {
3532
+ this.transform.push({ key: 'scaleY', transform: `scaleY(${scale})` });
3533
+ return this;
3534
+ }
3535
+ scaleZ(scale) {
3536
+ this.transform.push({ key: 'scaleZ', transform: `scaleZ(${scale})` });
3537
+ return this;
3538
+ }
3539
+ skew(x, y) {
3540
+ this.transform.push({ key: 'skew', transform: `skew(${x}deg, ${y}deg)` });
3541
+ return this;
3540
3542
  }
3541
- if (typeof options.cancelText !== 'string') {
3542
- return handle.fail({
3543
- errMsg: getParameterError({
3544
- para: 'cancelText',
3545
- correct: 'String',
3546
- wrong: options.cancelText
3547
- })
3548
- });
3543
+ skewX(angle) {
3544
+ this.transform.push({ key: 'skewX', transform: `skewX(${angle}deg)` });
3545
+ return this;
3549
3546
  }
3550
- if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
3551
- return handle.fail({
3552
- errMsg: 'cancelText length should not larger then 4 Chinese characters'
3553
- });
3547
+ skewY(angle) {
3548
+ this.transform.push({ key: 'skewY', transform: `skewY(${angle}deg)` });
3549
+ return this;
3554
3550
  }
3555
- if (typeof options.confirmText !== 'string') {
3556
- return handle.fail({
3557
- errMsg: getParameterError({
3558
- para: 'confirmText',
3559
- correct: 'String',
3560
- wrong: options.confirmText
3561
- })
3562
- });
3551
+ translate(x, y) {
3552
+ [x, y] = this.transformUnit(x, y);
3553
+ this.transform.push({ key: 'translate', transform: `translate(${x}, ${y})` });
3554
+ return this;
3563
3555
  }
3564
- if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
3565
- return handle.fail({
3566
- errMsg: 'confirmText length should not larger then 4 Chinese characters'
3567
- });
3556
+ translate3d(x, y, z) {
3557
+ [x, y, z] = this.transformUnit(x, y, z);
3558
+ this.transform.push({ key: 'translate3d', transform: `translate3d(${x}, ${y}, ${z})` });
3559
+ return this;
3568
3560
  }
3569
- if (typeof options.cancelColor !== 'string') {
3570
- return handle.fail({
3571
- errMsg: getParameterError({
3572
- para: 'cancelColor',
3573
- correct: 'String',
3574
- wrong: options.cancelColor
3575
- })
3576
- });
3561
+ translateX(translate) {
3562
+ [translate] = this.transformUnit(translate);
3563
+ this.transform.push({ key: 'translateX', transform: `translateX(${translate})` });
3564
+ return this;
3577
3565
  }
3578
- if (typeof options.confirmColor !== 'string') {
3579
- return handle.fail({
3580
- errMsg: getParameterError({
3581
- para: 'confirmColor',
3582
- correct: 'String',
3583
- wrong: options.confirmColor
3584
- })
3585
- });
3566
+ translateY(translate) {
3567
+ [translate] = this.transformUnit(translate);
3568
+ this.transform.push({ key: 'translateY', transform: `translateY(${translate})` });
3569
+ return this;
3586
3570
  }
3587
- options.showCancel = !!options.showCancel;
3588
- let result = '';
3589
- if (!modal.el) {
3590
- result = yield modal.create(options);
3571
+ translateZ(translate) {
3572
+ [translate] = this.transformUnit(translate);
3573
+ this.transform.push({ key: 'translateZ', transform: `translateZ(${translate})` });
3574
+ return this;
3591
3575
  }
3592
- else {
3593
- result = yield modal.show(options);
3576
+ opacity(value) {
3577
+ this.rules.push({ key: 'opacity', rule: `opacity: ${value}` });
3578
+ return this;
3594
3579
  }
3595
- const res = { cancel: !1, confirm: !1 };
3596
- res[result] = !0;
3597
- return handle.success(res);
3598
- });
3599
- function hideModal() {
3600
- if (!modal.el)
3601
- return;
3602
- modal.hide();
3603
- }
3604
- const showActionSheet = (options = { itemList: [] }, methodName = 'showActionSheet') => tslib.__awaiter(void 0, void 0, void 0, function* () {
3605
- init(document);
3606
- options = Object.assign({
3607
- itemColor: '#000000',
3608
- itemList: []
3609
- }, options);
3610
- const { success, fail, complete } = options;
3611
- const handle = new MethodHandler({ name: methodName, success, fail, complete });
3612
- // list item String
3613
- if (!Array.isArray(options.itemList)) {
3614
- return handle.fail({
3615
- errMsg: getParameterError({
3616
- para: 'itemList',
3617
- correct: 'Array',
3618
- wrong: options.itemList
3619
- })
3620
- });
3580
+ backgroundColor(value) {
3581
+ this.rules.push({ key: 'backgroundColor', rule: `background-color: ${value}` });
3582
+ return this;
3621
3583
  }
3622
- if (options.itemList.length < 1) {
3623
- return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
3584
+ width(value) {
3585
+ [value] = this.transformUnit(value);
3586
+ this.rules.push({ key: 'width', rule: `width: ${value}` });
3587
+ return this;
3624
3588
  }
3625
- if (options.itemList.length > 6) {
3626
- return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
3589
+ height(value) {
3590
+ [value] = this.transformUnit(value);
3591
+ this.rules.push({ key: 'height', rule: `height: ${value}` });
3592
+ return this;
3627
3593
  }
3628
- for (let i = 0; i < options.itemList.length; i++) {
3629
- if (typeof options.itemList[i] !== 'string') {
3630
- return handle.fail({
3631
- errMsg: getParameterError({
3632
- para: `itemList[${i}]`,
3633
- correct: 'String',
3634
- wrong: options.itemList[i]
3635
- })
3636
- });
3637
- }
3594
+ top(value) {
3595
+ [value] = this.transformUnit(value);
3596
+ this.rules.push({ key: 'top', rule: `top: ${value}` });
3597
+ return this;
3638
3598
  }
3639
- if (typeof options.itemColor !== 'string') {
3640
- return handle.fail({
3641
- errMsg: getParameterError({
3642
- para: 'itemColor',
3643
- correct: 'String',
3644
- wrong: options.itemColor
3645
- })
3646
- });
3599
+ right(value) {
3600
+ [value] = this.transformUnit(value);
3601
+ this.rules.push({ key: 'right', rule: `right: ${value}` });
3602
+ return this;
3647
3603
  }
3648
- let result = '';
3649
- if (!actionSheet.el) {
3650
- result = yield actionSheet.create(options);
3604
+ bottom(value) {
3605
+ [value] = this.transformUnit(value);
3606
+ this.rules.push({ key: 'bottom', rule: `bottom: ${value}` });
3607
+ return this;
3651
3608
  }
3652
- else {
3653
- result = yield actionSheet.show(options);
3609
+ left(value) {
3610
+ [value] = this.transformUnit(value);
3611
+ this.rules.push({ key: 'left', rule: `left: ${value}` });
3612
+ return this;
3654
3613
  }
3655
- if (typeof result === 'string') {
3656
- return handle.fail(({ errMsg: result }));
3614
+ // 关键帧载入
3615
+ step(arg = {}) {
3616
+ const { DEFAULT } = this;
3617
+ const { duration = DEFAULT.duration, delay = DEFAULT.delay, timingFunction = DEFAULT.timingFunction, transformOrigin = DEFAULT.transformOrigin, } = arg;
3618
+ // 生成一条 transition 动画
3619
+ this.transform.map((t0) => {
3620
+ const index = this.historyAnimations.findIndex((t1) => t1.key === t0.key);
3621
+ if (index === -1) {
3622
+ this.historyAnimations.push(t0);
3623
+ }
3624
+ else {
3625
+ this.historyAnimations[index] = t0;
3626
+ }
3627
+ });
3628
+ const transforms = this.historyAnimations.map((t) => t.transform);
3629
+ const transformSequence = transforms.length > 0 ? `${TRANSFORM}:${transforms.join(' ')}!important` : '';
3630
+ this.rules.map((r0) => {
3631
+ const index = this.historyRules.findIndex((r1) => r1.key === r0.key);
3632
+ if (index === -1) {
3633
+ this.historyRules.push(r0);
3634
+ }
3635
+ else {
3636
+ this.historyRules[index] = r0;
3637
+ }
3638
+ });
3639
+ const rules = this.historyRules.map((t) => t.rule);
3640
+ const ruleSequence = rules.length > 0 ? rules.map((rule) => `${rule}!important`).join(';') : '';
3641
+ this.steps.push([
3642
+ ruleSequence,
3643
+ transformSequence,
3644
+ `${TRANSFORM}-origin: ${transformOrigin}`,
3645
+ `transition: all ${duration}ms ${timingFunction} ${delay}ms`,
3646
+ ]
3647
+ .filter((item) => item !== '')
3648
+ .join(';'));
3649
+ // 清空 rules 和 transform
3650
+ this.rules = [];
3651
+ this.transform = [];
3652
+ return this;
3657
3653
  }
3658
- else {
3659
- return handle.success(({ tapIndex: result }));
3654
+ // 创建底层数据
3655
+ createAnimationData() {
3656
+ const animIndex = `taro-h5-poly-fill/${this.id}/create-animation__${this.animationMapCount++}`;
3657
+ // 记录动画分几个 step
3658
+ this.animationMap[animIndex] = this.steps.length;
3659
+ // 吐出 step
3660
+ this.steps.forEach((step, index) => {
3661
+ const selector = index === 0
3662
+ ? `[animation="${animIndex}"], [data-animation="${animIndex}"]`
3663
+ : `[animation="${animIndex}--${index}"], [data-animation="${animIndex}--${index}"]`;
3664
+ styleSheet.add(`${selector} { ${step} }`);
3665
+ });
3666
+ // 清空 steps
3667
+ this.steps = [];
3668
+ return animIndex;
3660
3669
  }
3661
- });
3662
- Taro.eventCenter.on('__afterTaroRouterChange', () => {
3663
- var _a, _b;
3664
- if (toast.currentPath && toast.currentPath !== ((_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path)) {
3665
- hideToast();
3666
- hideLoading();
3670
+ // 动画数据产出
3671
+ export() {
3672
+ return this.createAnimationData();
3667
3673
  }
3668
- if (modal.currentPath && modal.currentPath !== ((_b = runtime.Current.page) === null || _b === void 0 ? void 0 : _b.path)) {
3669
- hideModal();
3674
+ }
3675
+ // h5 的 createAnimation
3676
+ const createAnimation = (option) => {
3677
+ return new Animation(option);
3678
+ };
3679
+
3680
+ // 背景
3681
+ const setBackgroundTextStyle = /* @__PURE__ */ temporarilyNotSupport('setBackgroundTextStyle');
3682
+ const setBackgroundColor = /* @__PURE__ */ temporarilyNotSupport('setBackgroundColor');
3683
+
3684
+ // 自定义组件
3685
+ const nextTick = Taro.nextTick;
3686
+
3687
+ // 字体
3688
+ const loadFontFace = (options) => tslib.__awaiter(void 0, void 0, void 0, function* () {
3689
+ options = Object.assign({ global: false }, options);
3690
+ const { success, fail, complete, family, source, desc = {} } = options;
3691
+ const handle = new MethodHandler({ name: 'loadFontFace', success, fail, complete });
3692
+ // @ts-ignore
3693
+ const fonts = document.fonts;
3694
+ if (fonts) {
3695
+ // @ts-ignore
3696
+ const fontFace = new FontFace(family, source, desc);
3697
+ try {
3698
+ yield fontFace.load();
3699
+ fonts.add(fontFace);
3700
+ return handle.success({ status: 'loaded' });
3701
+ }
3702
+ catch (error) {
3703
+ return handle.fail({
3704
+ status: 'error',
3705
+ errMsg: error.message || error,
3706
+ });
3707
+ }
3708
+ }
3709
+ else {
3710
+ const style = document.createElement('style');
3711
+ let innerText = `font-family:"${family}";src:${source};font-style:${desc.style || 'normal'};font-weight:${desc.weight || 'normal'};font-variant:${desc.variant || 'normal'};`;
3712
+ if (desc.ascentOverride) {
3713
+ innerText += `ascent-override:${desc.ascentOverride};`;
3714
+ }
3715
+ if (desc.descentOverride) {
3716
+ innerText += `descent-override:${desc.descentOverride};`;
3717
+ }
3718
+ if (desc.featureSettings) {
3719
+ innerText += `font-feature-settings:${desc.featureSettings};`;
3720
+ }
3721
+ if (desc.lineGapOverride) {
3722
+ innerText += `line-gap-override:${desc.lineGapOverride};`;
3723
+ }
3724
+ if (desc.stretch) {
3725
+ innerText += `font-stretch:${desc.stretch};`;
3726
+ }
3727
+ if (desc.unicodeRange) {
3728
+ innerText += `unicode-range:${desc.unicodeRange};`;
3729
+ }
3730
+ if (desc.variationSettings) {
3731
+ innerText += `font-variation-settings:${desc.variationSettings};`;
3732
+ }
3733
+ style.innerText = `@font-face{${innerText}}`;
3734
+ document.head.appendChild(style);
3735
+ return handle.success({ status: 'loaded' });
3670
3736
  }
3671
3737
  });
3672
- const enableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('enableAlertBeforeUnload');
3673
- const disableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('disableAlertBeforeUnload');
3674
3738
 
3675
3739
  // 菜单
3676
3740
  const getMenuButtonBoundingClientRect = /* @__PURE__ */ temporarilyNotSupport('getMenuButtonBoundingClientRect');
@@ -3703,12 +3767,13 @@ function setNavigationBarTitle(options) {
3703
3767
  * 设置页面导航条颜色
3704
3768
  */
3705
3769
  const setNavigationBarColor = (options) => {
3706
- const { backgroundColor, success, fail, complete } = options;
3770
+ const { backgroundColor, frontColor, success, fail, complete } = options;
3707
3771
  const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
3708
3772
  const meta = document.createElement('meta');
3709
3773
  meta.setAttribute('name', 'theme-color');
3710
3774
  meta.setAttribute('content', backgroundColor);
3711
3775
  document.head.appendChild(meta);
3776
+ router.setNavigationBarStyle({ frontColor, backgroundColor });
3712
3777
  return handle.success();
3713
3778
  };
3714
3779
  const hideNavigationBarLoading = /* @__PURE__ */ temporarilyNotSupport('hideNavigationBarLoading');
@@ -4781,7 +4846,10 @@ function _request(options = {}) {
4781
4846
  const { success, complete, fail } = options;
4782
4847
  const params = {};
4783
4848
  const res = {};
4784
- let { cache = 'default', credentials, data, dataType, header = {}, jsonp, method = 'GET', mode, responseType, signal, timeout = 60000, url = '' } = options, opts = tslib.__rest(options, ["cache", "credentials", "data", "dataType", "header", "jsonp", "method", "mode", "responseType", "signal", "timeout", "url"]);
4849
+ let { cache = 'default', credentials, data, dataType, header = {}, jsonp, method = 'GET', mode, responseType, signal, timeout, url = '' } = options, opts = tslib.__rest(options, ["cache", "credentials", "data", "dataType", "header", "jsonp", "method", "mode", "responseType", "signal", "timeout", "url"]);
4850
+ if (typeof timeout !== 'number') {
4851
+ timeout = NETWORK_TIMEOUT;
4852
+ }
4785
4853
  Object.assign(params, opts);
4786
4854
  if (jsonp) {
4787
4855
  // @ts-ignore
@@ -4847,12 +4915,10 @@ function _request(options = {}) {
4847
4915
  else {
4848
4916
  controller = new window.AbortController();
4849
4917
  params.signal = controller.signal;
4850
- if (typeof timeout === 'number') {
4851
- timeoutTimer = setTimeout(function () {
4852
- if (controller)
4853
- controller.abort();
4854
- }, timeout);
4855
- }
4918
+ timeoutTimer = setTimeout(function () {
4919
+ if (controller)
4920
+ controller.abort();
4921
+ }, timeout);
4856
4922
  }
4857
4923
  params.credentials = credentials;
4858
4924
  const p = fetch(url, params)
@@ -5427,7 +5493,8 @@ class TaroH5IntersectionObserver {
5427
5493
  intersectionRatio: entry.intersectionRatio,
5428
5494
  intersectionRect: entry.intersectionRect,
5429
5495
  relativeRect: entry.rootBounds || { left: 0, right: 0, top: 0, bottom: 0 },
5430
- time: entry.time
5496
+ // 使用时间戳而不是entry.time,跟微信小程序一致
5497
+ time: Date.now(),
5431
5498
  };
5432
5499
  // web端会默认首次触发
5433
5500
  if (!this._isInited && this._options.initialRatio <= Math.min.apply(Math, this._options.thresholds)) {
@@ -5575,15 +5642,18 @@ class NodesRef {
5575
5642
  }
5576
5643
  fields(fields, cb) {
5577
5644
  const { _selector, _component, _single, _selectorQuery } = this;
5578
- const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields;
5645
+ const { id, dataset, rect, size, scrollOffset, context, node, properties = [], computedStyle = [] } = fields;
5579
5646
  _selectorQuery._push(_selector, _component, _single, {
5580
5647
  id,
5581
5648
  dataset,
5582
5649
  rect,
5583
5650
  size,
5584
5651
  scrollOffset,
5652
+ context,
5653
+ node,
5654
+ nodeCanvasType: node,
5585
5655
  properties,
5586
- computedStyle
5656
+ computedStyle,
5587
5657
  }, cb);
5588
5658
  return _selectorQuery;
5589
5659
  }
@@ -5938,6 +6008,7 @@ exports.ENV_TYPE = ENV_TYPE;
5938
6008
  exports.Events = Events;
5939
6009
  exports.Link = Link;
5940
6010
  exports.NodesRef = NodesRef;
6011
+ exports.SocketTask = SocketTask;
5941
6012
  exports.addCard = addCard;
5942
6013
  exports.addFileToFavorites = addFileToFavorites;
5943
6014
  exports.addInterceptor = addInterceptor;