@wiajs/core 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.0.9
2
+ * wia core v1.0.10
3
3
  * (c) 2015-2023 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -2206,6 +2206,464 @@
2206
2206
  }
2207
2207
  };
2208
2208
 
2209
+ var extend$1 = Utils.extend;
2210
+ var _$$1 = $,
2211
+ device$1 = _$$1.device,
2212
+ support$1 = _$$1.support;
2213
+ function initTouch() {
2214
+ var app = this;
2215
+ var params = app.params.touch;
2216
+ var useRipple = params[app.theme + "TouchRipple"];
2217
+ if (device$1.ios && device$1.webView) {
2218
+ window.addEventListener('touchstart', function () {});
2219
+ }
2220
+ var touchStartX;
2221
+ var touchStartY;
2222
+ var targetElement;
2223
+ var isMoved;
2224
+ var tapHoldFired;
2225
+ var tapHoldTimeout;
2226
+ var preventClick;
2227
+ var activableElement;
2228
+ var activeTimeout;
2229
+ var rippleWave;
2230
+ var rippleTarget;
2231
+ var rippleTimeout;
2232
+ function findActivableElement(el) {
2233
+ var target = $(el);
2234
+ var parents = target.parents(params.activeStateElements);
2235
+ if (target.closest('.no-active-state').length) {
2236
+ return null;
2237
+ }
2238
+ var activable;
2239
+ if (target.is(params.activeStateElements)) {
2240
+ activable = target;
2241
+ }
2242
+ if (parents.length > 0) {
2243
+ activable = activable ? activable.add(parents) : parents;
2244
+ }
2245
+ if (activable && activable.length > 1) {
2246
+ var newActivable = [];
2247
+ var preventPropagation;
2248
+ for (var i = 0; i < activable.length; i += 1) {
2249
+ if (!preventPropagation) {
2250
+ newActivable.push(activable[i]);
2251
+ if (activable.eq(i).hasClass('prevent-active-state-propagation') || activable.eq(i).hasClass('no-active-state-propagation')) {
2252
+ preventPropagation = true;
2253
+ }
2254
+ }
2255
+ }
2256
+ activable = $(newActivable);
2257
+ }
2258
+ return activable || target;
2259
+ }
2260
+ function isInsideScrollableView(el) {
2261
+ var pageContent = el.parents('.page-content');
2262
+ return pageContent.length > 0;
2263
+ }
2264
+ function addActive() {
2265
+ if (!activableElement) return;
2266
+ activableElement.addClass('active-state');
2267
+ }
2268
+ function removeActive() {
2269
+ if (!activableElement) return;
2270
+ activableElement.removeClass('active-state');
2271
+ activableElement = null;
2272
+ }
2273
+ function findRippleElement(el) {
2274
+ var rippleElements = params.touchRippleElements;
2275
+ var $el = $(el);
2276
+ if ($el.is(rippleElements)) {
2277
+ if ($el.hasClass('no-ripple')) {
2278
+ return false;
2279
+ }
2280
+ return $el;
2281
+ }
2282
+ if ($el.parents(rippleElements).length > 0) {
2283
+ var rippleParent = $el.parents(rippleElements).eq(0);
2284
+ if (rippleParent.hasClass('no-ripple')) {
2285
+ return false;
2286
+ }
2287
+ return rippleParent;
2288
+ }
2289
+ return false;
2290
+ }
2291
+ function createRipple($el, x, y) {
2292
+ if (!$el) return;
2293
+ rippleWave = app.touchRipple.create(app, $el, x, y);
2294
+ }
2295
+ function removeRipple() {
2296
+ if (!rippleWave) return;
2297
+ rippleWave.remove();
2298
+ rippleWave = undefined;
2299
+ rippleTarget = undefined;
2300
+ }
2301
+ function rippleTouchStart(el) {
2302
+ rippleTarget = findRippleElement(el);
2303
+ if (!rippleTarget || rippleTarget.length === 0) {
2304
+ rippleTarget = undefined;
2305
+ return;
2306
+ }
2307
+ var inScrollable = isInsideScrollableView(rippleTarget);
2308
+ if (!inScrollable) {
2309
+ removeRipple();
2310
+ createRipple(rippleTarget, touchStartX, touchStartY);
2311
+ } else {
2312
+ clearTimeout(rippleTimeout);
2313
+ rippleTimeout = setTimeout(function () {
2314
+ removeRipple();
2315
+ createRipple(rippleTarget, touchStartX, touchStartY);
2316
+ }, 80);
2317
+ }
2318
+ }
2319
+ function rippleTouchMove() {
2320
+ clearTimeout(rippleTimeout);
2321
+ removeRipple();
2322
+ }
2323
+ function rippleTouchEnd() {
2324
+ if (!rippleWave && rippleTarget && !isMoved) {
2325
+ clearTimeout(rippleTimeout);
2326
+ createRipple(rippleTarget, touchStartX, touchStartY);
2327
+ setTimeout(removeRipple, 0);
2328
+ } else {
2329
+ removeRipple();
2330
+ }
2331
+ }
2332
+ function handleMouseDown(e) {
2333
+ var $activableEl = findActivableElement(e.target);
2334
+ if ($activableEl) {
2335
+ $activableEl.addClass('active-state');
2336
+ if ('which' in e && e.which === 3) {
2337
+ setTimeout(function () {
2338
+ $('.active-state').removeClass('active-state');
2339
+ }, 0);
2340
+ }
2341
+ }
2342
+ if (useRipple) {
2343
+ touchStartX = e.pageX;
2344
+ touchStartY = e.pageY;
2345
+ rippleTouchStart(e.target, e.pageX, e.pageY);
2346
+ }
2347
+ }
2348
+ function handleMouseMove() {
2349
+ if (!params.activeStateOnMouseMove) {
2350
+ $('.active-state').removeClass('active-state');
2351
+ }
2352
+ if (useRipple) {
2353
+ rippleTouchMove();
2354
+ }
2355
+ }
2356
+ function handleMouseUp() {
2357
+ $('.active-state').removeClass('active-state');
2358
+ if (useRipple) {
2359
+ rippleTouchEnd();
2360
+ }
2361
+ }
2362
+ function handleTouchCancel() {
2363
+ targetElement = null;
2364
+ clearTimeout(activeTimeout);
2365
+ clearTimeout(tapHoldTimeout);
2366
+ if (params.activeState) {
2367
+ removeActive();
2368
+ }
2369
+ if (useRipple) {
2370
+ rippleTouchEnd();
2371
+ }
2372
+ }
2373
+ var isScrolling;
2374
+ var isSegmentedStrong = false;
2375
+ var segmentedStrongEl = null;
2376
+ var touchMoveActivableIos = '.dialog-button, .actions-button';
2377
+ var isTouchMoveActivable = false;
2378
+ var touchmoveActivableEl = null;
2379
+ function handleTouchStart(e) {
2380
+ if (!e.isTrusted) return true;
2381
+ isMoved = false;
2382
+ tapHoldFired = false;
2383
+ preventClick = false;
2384
+ isScrolling = undefined;
2385
+ if (e.targetTouches.length > 1) {
2386
+ if (activableElement) removeActive();
2387
+ return true;
2388
+ }
2389
+ if (e.touches.length > 1 && activableElement) {
2390
+ removeActive();
2391
+ }
2392
+ if (params.tapHold) {
2393
+ if (tapHoldTimeout) clearTimeout(tapHoldTimeout);
2394
+ tapHoldTimeout = setTimeout(function () {
2395
+ if (e && e.touches && e.touches.length > 1) return;
2396
+ tapHoldFired = true;
2397
+ e.preventDefault();
2398
+ preventClick = true;
2399
+ $(e.target).trigger('taphold', e);
2400
+ app.emit('taphold', e);
2401
+ }, params.tapHoldDelay);
2402
+ }
2403
+ targetElement = e.target;
2404
+ touchStartX = e.targetTouches[0].pageX;
2405
+ touchStartY = e.targetTouches[0].pageY;
2406
+ isSegmentedStrong = e.target.closest('.segmented-strong .button-active, .segmented-strong .tab-link-active');
2407
+ isTouchMoveActivable = app.theme === 'ios' && e.target.closest(touchMoveActivableIos);
2408
+ if (isSegmentedStrong) {
2409
+ segmentedStrongEl = isSegmentedStrong.closest('.segmented-strong');
2410
+ }
2411
+ if (params.activeState) {
2412
+ activableElement = findActivableElement(targetElement);
2413
+ if (activableElement && !isInsideScrollableView(activableElement)) {
2414
+ addActive();
2415
+ } else if (activableElement) {
2416
+ activeTimeout = setTimeout(addActive, 80);
2417
+ }
2418
+ }
2419
+ if (useRipple) {
2420
+ rippleTouchStart(targetElement);
2421
+ }
2422
+ return true;
2423
+ }
2424
+ function handleTouchMove(e) {
2425
+ if (!e.isTrusted) return;
2426
+ var touch;
2427
+ var distance;
2428
+ var shouldRemoveActive = true;
2429
+ if (e.type === 'touchmove') {
2430
+ touch = e.targetTouches[0];
2431
+ distance = params.touchClicksDistanceThreshold;
2432
+ }
2433
+ var touchCurrentX = e.targetTouches[0].pageX;
2434
+ var touchCurrentY = e.targetTouches[0].pageY;
2435
+ if (typeof isScrolling === 'undefined') {
2436
+ isScrolling = !!(isScrolling || Math.abs(touchCurrentY - touchStartY) > Math.abs(touchCurrentX - touchStartX));
2437
+ }
2438
+ if (isTouchMoveActivable || !isScrolling && isSegmentedStrong && segmentedStrongEl) {
2439
+ if (e.cancelable) e.preventDefault();
2440
+ }
2441
+ if (!isScrolling && isSegmentedStrong && segmentedStrongEl) {
2442
+ var elementFromPoint = document.elementFromPoint(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
2443
+ var buttonEl = elementFromPoint.closest('.segmented-strong .button:not(.button-active):not(.tab-link-active)');
2444
+ if (buttonEl && segmentedStrongEl.contains(buttonEl)) {
2445
+ $(buttonEl).trigger('click', 'f7Segmented');
2446
+ targetElement = buttonEl;
2447
+ }
2448
+ }
2449
+ if (distance && touch) {
2450
+ var _touch = touch,
2451
+ pageX = _touch.pageX,
2452
+ pageY = _touch.pageY;
2453
+ if (Math.abs(pageX - touchStartX) > distance || Math.abs(pageY - touchStartY) > distance) {
2454
+ isMoved = true;
2455
+ }
2456
+ } else {
2457
+ isMoved = true;
2458
+ }
2459
+ if (isMoved) {
2460
+ preventClick = true;
2461
+ if (isTouchMoveActivable) {
2462
+ var _elementFromPoint = document.elementFromPoint(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
2463
+ touchmoveActivableEl = _elementFromPoint.closest(touchMoveActivableIos);
2464
+ if (touchmoveActivableEl && activableElement && activableElement[0] === touchmoveActivableEl) {
2465
+ shouldRemoveActive = false;
2466
+ } else if (touchmoveActivableEl) {
2467
+ setTimeout(function () {
2468
+ activableElement = findActivableElement(touchmoveActivableEl);
2469
+ addActive();
2470
+ });
2471
+ }
2472
+ }
2473
+ if (params.tapHold) {
2474
+ clearTimeout(tapHoldTimeout);
2475
+ }
2476
+ if (params.activeState && shouldRemoveActive) {
2477
+ clearTimeout(activeTimeout);
2478
+ removeActive();
2479
+ }
2480
+ if (useRipple) {
2481
+ rippleTouchMove();
2482
+ }
2483
+ }
2484
+ }
2485
+ function handleTouchEnd(e) {
2486
+ if (!e.isTrusted) return true;
2487
+ isScrolling = undefined;
2488
+ isSegmentedStrong = false;
2489
+ segmentedStrongEl = null;
2490
+ isTouchMoveActivable = false;
2491
+ clearTimeout(activeTimeout);
2492
+ clearTimeout(tapHoldTimeout);
2493
+ if (touchmoveActivableEl) {
2494
+ $(touchmoveActivableEl).trigger('click', 'f7TouchMoveActivable');
2495
+ touchmoveActivableEl = null;
2496
+ }
2497
+ if (document.activeElement === e.target) {
2498
+ if (params.activeState) removeActive();
2499
+ if (useRipple) {
2500
+ rippleTouchEnd();
2501
+ }
2502
+ return true;
2503
+ }
2504
+ if (params.activeState) {
2505
+ addActive();
2506
+ setTimeout(removeActive, 0);
2507
+ }
2508
+ if (useRipple) {
2509
+ rippleTouchEnd();
2510
+ }
2511
+ if (params.tapHoldPreventClicks && tapHoldFired || preventClick) {
2512
+ if (e.cancelable) e.preventDefault();
2513
+ preventClick = true;
2514
+ return false;
2515
+ }
2516
+ return true;
2517
+ }
2518
+ function handleClick(e) {
2519
+ var isOverswipe = e && e.detail && e.detail === 'f7Overswipe';
2520
+ var isSegmented = e && e.detail && e.detail === 'f7Segmented';
2521
+ var isTouchMoveActivable = e && e.detail && e.detail === 'f7TouchMoveActivable';
2522
+ var localPreventClick = preventClick;
2523
+ if (targetElement && e.target !== targetElement) {
2524
+ if (isOverswipe || isSegmented || isTouchMoveActivable) {
2525
+ localPreventClick = false;
2526
+ } else {
2527
+ localPreventClick = true;
2528
+ }
2529
+ } else if (isTouchMoveActivable) {
2530
+ localPreventClick = false;
2531
+ }
2532
+ if (params.tapHold && params.tapHoldPreventClicks && tapHoldFired) {
2533
+ localPreventClick = true;
2534
+ }
2535
+ if (localPreventClick) {
2536
+ e.stopImmediatePropagation();
2537
+ e.stopPropagation();
2538
+ e.preventDefault();
2539
+ }
2540
+ if (params.tapHold) {
2541
+ tapHoldTimeout = setTimeout(function () {
2542
+ tapHoldFired = false;
2543
+ }, device$1.ios || device$1.androidChrome ? 100 : 400);
2544
+ }
2545
+ preventClick = false;
2546
+ targetElement = null;
2547
+ return !localPreventClick;
2548
+ }
2549
+ function emitAppTouchEvent(name, e) {
2550
+ app.emit({
2551
+ events: name,
2552
+ data: [e]
2553
+ });
2554
+ }
2555
+ function appTouchStartActive(e) {
2556
+ emitAppTouchEvent('touchstart touchstart:active', e);
2557
+ }
2558
+ function appTouchMoveActive(e) {
2559
+ emitAppTouchEvent('touchmove touchmove:active', e);
2560
+ }
2561
+ function appTouchEndActive(e) {
2562
+ emitAppTouchEvent('touchend touchend:active', e);
2563
+ }
2564
+ function appTouchStartPassive(e) {
2565
+ emitAppTouchEvent('touchstart:passive', e);
2566
+ }
2567
+ function appTouchMovePassive(e) {
2568
+ emitAppTouchEvent('touchmove:passive', e);
2569
+ }
2570
+ function appTouchEndPassive(e) {
2571
+ emitAppTouchEvent('touchend:passive', e);
2572
+ }
2573
+ var passiveListener = support$1.passiveListener ? {
2574
+ passive: true
2575
+ } : false;
2576
+ var passiveListenerCapture = support$1.passiveListener ? {
2577
+ passive: true,
2578
+ capture: true
2579
+ } : true;
2580
+ var activeListener = support$1.passiveListener ? {
2581
+ passive: false
2582
+ } : false;
2583
+ var activeListenerCapture = support$1.passiveListener ? {
2584
+ passive: false,
2585
+ capture: true
2586
+ } : true;
2587
+ if (support$1.passiveListener) {
2588
+ document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListenerCapture);
2589
+ document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
2590
+ document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
2591
+ document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListenerCapture);
2592
+ document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
2593
+ document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
2594
+ } else {
2595
+ document.addEventListener(app.touchEvents.start, function (e) {
2596
+ appTouchStartActive(e);
2597
+ appTouchStartPassive(e);
2598
+ }, true);
2599
+ document.addEventListener(app.touchEvents.move, function (e) {
2600
+ appTouchMoveActive(e);
2601
+ appTouchMovePassive(e);
2602
+ }, false);
2603
+ document.addEventListener(app.touchEvents.end, function (e) {
2604
+ appTouchEndActive(e);
2605
+ appTouchEndPassive(e);
2606
+ }, false);
2607
+ }
2608
+ if (support$1.touch) {
2609
+ app.on('click', handleClick);
2610
+ app.on('touchstart', handleTouchStart);
2611
+ app.on('touchmove', handleTouchMove);
2612
+ app.on('touchend', handleTouchEnd);
2613
+ document.addEventListener('touchcancel', handleTouchCancel, {
2614
+ passive: true
2615
+ });
2616
+ } else if (params.activeState) {
2617
+ app.on('touchstart', handleMouseDown);
2618
+ app.on('touchmove', handleMouseMove);
2619
+ app.on('touchend', handleMouseUp);
2620
+ document.addEventListener('pointercancel', handleMouseUp, {
2621
+ passive: true
2622
+ });
2623
+ }
2624
+ document.addEventListener('contextmenu', function (e) {
2625
+ if (params.disableContextMenu && (device$1.ios || device$1.android || device$1.cordova || window.Capacitor && window.Capacitor.isNative)) {
2626
+ e.preventDefault();
2627
+ }
2628
+ if (useRipple) {
2629
+ if (activableElement) removeActive();
2630
+ rippleTouchEnd();
2631
+ }
2632
+ });
2633
+ }
2634
+ var Touch = {
2635
+ name: 'touch',
2636
+ params: {
2637
+ touch: {
2638
+ touchClicksDistanceThreshold: 5,
2639
+ disableContextMenu: false,
2640
+ tapHold: false,
2641
+ tapHoldDelay: 750,
2642
+ tapHoldPreventClicks: true,
2643
+ activeState: true,
2644
+ activeStateElements: 'a, button, label, span, .actions-button, .stepper-button, .stepper-button-plus, .stepper-button-minus, .card-expandable, .link, .item-link, .accordion-item-toggle',
2645
+ activeStateOnMouseMove: false,
2646
+ mdTouchRipple: true,
2647
+ iosTouchRipple: false,
2648
+ touchRippleElements: '.ripple, .link, .item-link, .list label.item-content, .list-button, .links-list a, .button, button, .input-clear-button, .dialog-button, .tab-link, .item-radio, .item-checkbox, .actions-button, .searchbar-disable-button, .fab a, .checkbox, .radio, .data-table .sortable-cell:not(.input-cell), .notification-close-button, .stepper-button, .stepper-button-minus, .stepper-button-plus, .list.accordion-list .accordion-item-toggle',
2649
+ touchRippleInsetElements: '.ripple-inset, .icon-only, .searchbar-disable-button, .input-clear-button, .notification-close-button, .md .navbar .link.back'
2650
+ }
2651
+ },
2652
+ create: function create() {
2653
+ var app = this;
2654
+ extend$1(app, {
2655
+ touchEvents: {
2656
+ start: support$1.touch ? 'touchstart' : support$1.pointerEvents ? 'pointerdown' : 'mousedown',
2657
+ move: support$1.touch ? 'touchmove' : support$1.pointerEvents ? 'pointermove' : 'mousemove',
2658
+ end: support$1.touch ? 'touchend' : support$1.pointerEvents ? 'pointerup' : 'mouseup'
2659
+ }
2660
+ });
2661
+ },
2662
+ on: {
2663
+ init: initTouch
2664
+ }
2665
+ };
2666
+
2209
2667
  var SW = {
2210
2668
  registrations: [],
2211
2669
  register: function register(path, scope) {
@@ -2675,7 +3133,7 @@
2675
3133
  App.support = support;
2676
3134
  App.device = device;
2677
3135
  App.utils = Utils;
2678
- App.use([Resize, Click, SW$1]);
3136
+ App.use([Resize, Click, Touch, SW$1]);
2679
3137
 
2680
3138
  var _opts = {
2681
3139
  normal: 'nor',