@wiajs/core 1.0.10 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * wia core v1.0.9
3
- * (c) 2015-2023 Sibyl Yu and contributors
2
+ * wia core v1.1.2
3
+ * (c) 2015-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  'use strict';
@@ -105,6 +105,10 @@ function clampInt(min, max, input) {
105
105
  return input < min ? min : input > max ? max : input;
106
106
  }
107
107
 
108
+ function clampDouble(min, max, input) {
109
+ return input < min ? min : input > max ? max : input;
110
+ }
111
+
108
112
  function sanitizeDegreesDouble(degrees) {
109
113
  return (degrees %= 360) < 0 && (degrees += 360), degrees;
110
114
  }
@@ -165,6 +169,10 @@ function yFromLstar(lstar) {
165
169
  return 100 * labInvf((lstar + 16) / 116);
166
170
  }
167
171
 
172
+ function lstarFromY(y) {
173
+ return 116 * labF(y / 100) - 16;
174
+ }
175
+
168
176
  function linearized(rgbComponent) {
169
177
  const normalized = rgbComponent / 255;
170
178
  return normalized <= .040449936 ? normalized / 12.92 * 100 : 100 * Math.pow((normalized + .055) / 1.055, 2.4);
@@ -246,6 +254,14 @@ class Cam16 {
246
254
  const alpha = 0 === this.chroma || 0 === this.j ? 0 : this.chroma / Math.sqrt(this.j / 100), t = Math.pow(alpha / Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), 1 / .9), hRad = this.hue * Math.PI / 180, eHue = .25 * (Math.cos(hRad + 2) + 3.8), ac = viewingConditions.aw * Math.pow(this.j / 100, 1 / viewingConditions.c / viewingConditions.z), p1 = eHue * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb, p2 = ac / viewingConditions.nbb, hSin = Math.sin(hRad), hCos = Math.cos(hRad), gamma = 23 * (p2 + .305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin), a = gamma * hCos, b = gamma * hSin, rA = (460 * p2 + 451 * a + 288 * b) / 1403, gA = (460 * p2 - 891 * a - 261 * b) / 1403, bA = (460 * p2 - 220 * a - 6300 * b) / 1403, rCBase = Math.max(0, 27.13 * Math.abs(rA) / (400 - Math.abs(rA))), rC = signum(rA) * (100 / viewingConditions.fl) * Math.pow(rCBase, 1 / .42), gCBase = Math.max(0, 27.13 * Math.abs(gA) / (400 - Math.abs(gA))), gC = signum(gA) * (100 / viewingConditions.fl) * Math.pow(gCBase, 1 / .42), bCBase = Math.max(0, 27.13 * Math.abs(bA) / (400 - Math.abs(bA))), bC = signum(bA) * (100 / viewingConditions.fl) * Math.pow(bCBase, 1 / .42), rF = rC / viewingConditions.rgbD[0], gF = gC / viewingConditions.rgbD[1], bF = bC / viewingConditions.rgbD[2];
247
255
  return argbFromXyz(1.86206786 * rF - 1.01125463 * gF + .14918677 * bF, .38752654 * rF + .62144744 * gF - .00897398 * bF, -.0158415 * rF - .03412294 * gF + 1.04996444 * bF);
248
256
  }
257
+ static fromXyzInViewingConditions(x, y, z, viewingConditions) {
258
+ const rC = .401288 * x + .650173 * y - .051461 * z, gC = -.250268 * x + 1.204414 * y + .045854 * z, bC = -.002079 * x + .048952 * y + .953127 * z, rD = viewingConditions.rgbD[0] * rC, gD = viewingConditions.rgbD[1] * gC, bD = viewingConditions.rgbD[2] * bC, rAF = Math.pow(viewingConditions.fl * Math.abs(rD) / 100, .42), gAF = Math.pow(viewingConditions.fl * Math.abs(gD) / 100, .42), bAF = Math.pow(viewingConditions.fl * Math.abs(bD) / 100, .42), rA = 400 * signum(rD) * rAF / (rAF + 27.13), gA = 400 * signum(gD) * gAF / (gAF + 27.13), bA = 400 * signum(bD) * bAF / (bAF + 27.13), a = (11 * rA + -12 * gA + bA) / 11, b = (rA + gA - 2 * bA) / 9, u = (20 * rA + 20 * gA + 21 * bA) / 20, p2 = (40 * rA + 20 * gA + bA) / 20, atanDegrees = 180 * Math.atan2(b, a) / Math.PI, hue = atanDegrees < 0 ? atanDegrees + 360 : atanDegrees >= 360 ? atanDegrees - 360 : atanDegrees, hueRadians = hue * Math.PI / 180, ac = p2 * viewingConditions.nbb, J = 100 * Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z), Q = 4 / viewingConditions.c * Math.sqrt(J / 100) * (viewingConditions.aw + 4) * viewingConditions.fLRoot, huePrime = hue < 20.14 ? hue + 360 : hue, t = 5e4 / 13 * (1 / 4 * (Math.cos(huePrime * Math.PI / 180 + 2) + 3.8)) * viewingConditions.nc * viewingConditions.ncb * Math.sqrt(a * a + b * b) / (u + .305), alpha = Math.pow(t, .9) * Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), C = alpha * Math.sqrt(J / 100), M = C * viewingConditions.fLRoot, s = 50 * Math.sqrt(alpha * viewingConditions.c / (viewingConditions.aw + 4)), jstar = (1 + 100 * .007) * J / (1 + .007 * J), mstar = Math.log(1 + .0228 * M) / .0228, astar = mstar * Math.cos(hueRadians), bstar = mstar * Math.sin(hueRadians);
259
+ return new Cam16(hue, C, J, Q, M, s, jstar, astar, bstar);
260
+ }
261
+ xyzInViewingConditions(viewingConditions) {
262
+ const alpha = 0 === this.chroma || 0 === this.j ? 0 : this.chroma / Math.sqrt(this.j / 100), t = Math.pow(alpha / Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), 1 / .9), hRad = this.hue * Math.PI / 180, eHue = .25 * (Math.cos(hRad + 2) + 3.8), ac = viewingConditions.aw * Math.pow(this.j / 100, 1 / viewingConditions.c / viewingConditions.z), p1 = eHue * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb, p2 = ac / viewingConditions.nbb, hSin = Math.sin(hRad), hCos = Math.cos(hRad), gamma = 23 * (p2 + .305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin), a = gamma * hCos, b = gamma * hSin, rA = (460 * p2 + 451 * a + 288 * b) / 1403, gA = (460 * p2 - 891 * a - 261 * b) / 1403, bA = (460 * p2 - 220 * a - 6300 * b) / 1403, rCBase = Math.max(0, 27.13 * Math.abs(rA) / (400 - Math.abs(rA))), rC = signum(rA) * (100 / viewingConditions.fl) * Math.pow(rCBase, 1 / .42), gCBase = Math.max(0, 27.13 * Math.abs(gA) / (400 - Math.abs(gA))), gC = signum(gA) * (100 / viewingConditions.fl) * Math.pow(gCBase, 1 / .42), bCBase = Math.max(0, 27.13 * Math.abs(bA) / (400 - Math.abs(bA))), bC = signum(bA) * (100 / viewingConditions.fl) * Math.pow(bCBase, 1 / .42), rF = rC / viewingConditions.rgbD[0], gF = gC / viewingConditions.rgbD[1], bF = bC / viewingConditions.rgbD[2];
263
+ return [ 1.86206786 * rF - 1.01125463 * gF + .14918677 * bF, .38752654 * rF + .62144744 * gF - .00897398 * bF, -.0158415 * rF - .03412294 * gF + 1.04996444 * bF ];
264
+ }
249
265
  }
250
266
 
251
267
  class HctSolver {
@@ -406,6 +422,10 @@ class Hct {
406
422
  this.internalHue = cam.hue, this.internalChroma = cam.chroma, this.internalTone = lstarFromArgb(argb),
407
423
  this.argb = argb;
408
424
  }
425
+ inViewingConditions(vc) {
426
+ const viewedInVc = Cam16.fromInt(this.toInt()).xyzInViewingConditions(vc), recastInVc = Cam16.fromXyzInViewingConditions(viewedInVc[0], viewedInVc[1], viewedInVc[2], ViewingConditions.make());
427
+ return Hct.from(recastInVc.hue, recastInVc.chroma, lstarFromY(viewedInVc[1]));
428
+ }
409
429
  }
410
430
 
411
431
  class Blend {
@@ -423,22 +443,562 @@ class Blend {
423
443
  }
424
444
  }
425
445
 
446
+ class Contrast {
447
+ static ratioOfTones(toneA, toneB) {
448
+ return toneA = clampDouble(0, 100, toneA), toneB = clampDouble(0, 100, toneB), Contrast.ratioOfYs(yFromLstar(toneA), yFromLstar(toneB));
449
+ }
450
+ static ratioOfYs(y1, y2) {
451
+ const lighter = y1 > y2 ? y1 : y2;
452
+ return (lighter + 5) / ((lighter === y2 ? y1 : y2) + 5);
453
+ }
454
+ static lighter(tone, ratio) {
455
+ if (tone < 0 || tone > 100) return -1;
456
+ const darkY = yFromLstar(tone), lightY = ratio * (darkY + 5) - 5, realContrast = Contrast.ratioOfYs(lightY, darkY), delta = Math.abs(realContrast - ratio);
457
+ if (realContrast < ratio && delta > .04) return -1;
458
+ const returnValue = lstarFromY(lightY) + .4;
459
+ return returnValue < 0 || returnValue > 100 ? -1 : returnValue;
460
+ }
461
+ static darker(tone, ratio) {
462
+ if (tone < 0 || tone > 100) return -1;
463
+ const lightY = yFromLstar(tone), darkY = (lightY + 5) / ratio - 5, realContrast = Contrast.ratioOfYs(lightY, darkY), delta = Math.abs(realContrast - ratio);
464
+ if (realContrast < ratio && delta > .04) return -1;
465
+ const returnValue = lstarFromY(darkY) - .4;
466
+ return returnValue < 0 || returnValue > 100 ? -1 : returnValue;
467
+ }
468
+ static lighterUnsafe(tone, ratio) {
469
+ const lighterSafe = Contrast.lighter(tone, ratio);
470
+ return lighterSafe < 0 ? 100 : lighterSafe;
471
+ }
472
+ static darkerUnsafe(tone, ratio) {
473
+ const darkerSafe = Contrast.darker(tone, ratio);
474
+ return darkerSafe < 0 ? 0 : darkerSafe;
475
+ }
476
+ }
477
+
478
+ class DislikeAnalyzer {
479
+ static isDisliked(hct) {
480
+ const huePasses = Math.round(hct.hue) >= 90 && Math.round(hct.hue) <= 111, chromaPasses = Math.round(hct.chroma) > 16, tonePasses = Math.round(hct.tone) < 65;
481
+ return huePasses && chromaPasses && tonePasses;
482
+ }
483
+ static fixIfDisliked(hct) {
484
+ return DislikeAnalyzer.isDisliked(hct) ? Hct.from(hct.hue, hct.chroma, 70) : hct;
485
+ }
486
+ }
487
+
488
+ class DynamicColor {
489
+ static fromPalette(args) {
490
+ return new DynamicColor(args.name ?? "", args.palette, args.tone, args.isBackground ?? !1, args.background, args.secondBackground, args.contrastCurve, args.toneDeltaPair);
491
+ }
492
+ constructor(name, palette, tone, isBackground, background, secondBackground, contrastCurve, toneDeltaPair) {
493
+ if (this.name = name, this.palette = palette, this.tone = tone, this.isBackground = isBackground,
494
+ this.background = background, this.secondBackground = secondBackground, this.contrastCurve = contrastCurve,
495
+ this.toneDeltaPair = toneDeltaPair, this.hctCache = new Map, !background && secondBackground) throw new Error(`Color ${name} has secondBackgrounddefined, but background is not defined.`);
496
+ if (!background && contrastCurve) throw new Error(`Color ${name} has contrastCurvedefined, but background is not defined.`);
497
+ if (background && !contrastCurve) throw new Error(`Color ${name} has backgrounddefined, but contrastCurve is not defined.`);
498
+ }
499
+ getArgb(scheme) {
500
+ return this.getHct(scheme).toInt();
501
+ }
502
+ getHct(scheme) {
503
+ const cachedAnswer = this.hctCache.get(scheme);
504
+ if (null != cachedAnswer) return cachedAnswer;
505
+ const tone = this.getTone(scheme), answer = this.palette(scheme).getHct(tone);
506
+ return this.hctCache.size > 4 && this.hctCache.clear(), this.hctCache.set(scheme, answer),
507
+ answer;
508
+ }
509
+ getTone(scheme) {
510
+ const decreasingContrast = scheme.contrastLevel < 0;
511
+ if (this.toneDeltaPair) {
512
+ const toneDeltaPair = this.toneDeltaPair(scheme), roleA = toneDeltaPair.roleA, roleB = toneDeltaPair.roleB, delta = toneDeltaPair.delta, polarity = toneDeltaPair.polarity, stayTogether = toneDeltaPair.stayTogether, bgTone = this.background(scheme).getTone(scheme), aIsNearer = "nearer" === polarity || "lighter" === polarity && !scheme.isDark || "darker" === polarity && scheme.isDark, nearer = aIsNearer ? roleA : roleB, farther = aIsNearer ? roleB : roleA, amNearer = this.name === nearer.name, expansionDir = scheme.isDark ? 1 : -1, nContrast = nearer.contrastCurve.getContrast(scheme.contrastLevel), fContrast = farther.contrastCurve.getContrast(scheme.contrastLevel), nInitialTone = nearer.tone(scheme);
513
+ let nTone = Contrast.ratioOfTones(bgTone, nInitialTone) >= nContrast ? nInitialTone : DynamicColor.foregroundTone(bgTone, nContrast);
514
+ const fInitialTone = farther.tone(scheme);
515
+ let fTone = Contrast.ratioOfTones(bgTone, fInitialTone) >= fContrast ? fInitialTone : DynamicColor.foregroundTone(bgTone, fContrast);
516
+ return decreasingContrast && (nTone = DynamicColor.foregroundTone(bgTone, nContrast),
517
+ fTone = DynamicColor.foregroundTone(bgTone, fContrast)), (fTone - nTone) * expansionDir >= delta || (fTone = clampDouble(0, 100, nTone + delta * expansionDir),
518
+ (fTone - nTone) * expansionDir >= delta || (nTone = clampDouble(0, 100, fTone - delta * expansionDir))),
519
+ 50 <= nTone && nTone < 60 ? expansionDir > 0 ? (nTone = 60, fTone = Math.max(fTone, nTone + delta * expansionDir)) : (nTone = 49,
520
+ fTone = Math.min(fTone, nTone + delta * expansionDir)) : 50 <= fTone && fTone < 60 && (stayTogether ? expansionDir > 0 ? (nTone = 60,
521
+ fTone = Math.max(fTone, nTone + delta * expansionDir)) : (nTone = 49, fTone = Math.min(fTone, nTone + delta * expansionDir)) : fTone = expansionDir > 0 ? 60 : 49),
522
+ amNearer ? nTone : fTone;
523
+ }
524
+ {
525
+ let answer = this.tone(scheme);
526
+ if (null == this.background) return answer;
527
+ const bgTone = this.background(scheme).getTone(scheme), desiredRatio = this.contrastCurve.getContrast(scheme.contrastLevel);
528
+ if (Contrast.ratioOfTones(bgTone, answer) >= desiredRatio || (answer = DynamicColor.foregroundTone(bgTone, desiredRatio)),
529
+ decreasingContrast && (answer = DynamicColor.foregroundTone(bgTone, desiredRatio)),
530
+ this.isBackground && 50 <= answer && answer < 60 && (answer = Contrast.ratioOfTones(49, bgTone) >= desiredRatio ? 49 : 60),
531
+ this.secondBackground) {
532
+ const [bg1, bg2] = [ this.background, this.secondBackground ], [bgTone1, bgTone2] = [ bg1(scheme).getTone(scheme), bg2(scheme).getTone(scheme) ], [upper, lower] = [ Math.max(bgTone1, bgTone2), Math.min(bgTone1, bgTone2) ];
533
+ if (Contrast.ratioOfTones(upper, answer) >= desiredRatio && Contrast.ratioOfTones(lower, answer) >= desiredRatio) return answer;
534
+ const lightOption = Contrast.lighter(upper, desiredRatio), darkOption = Contrast.darker(lower, desiredRatio), availables = [];
535
+ -1 !== lightOption && availables.push(lightOption), -1 !== darkOption && availables.push(darkOption);
536
+ return DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2) ? lightOption < 0 ? 100 : lightOption : 1 === availables.length ? availables[0] : darkOption < 0 ? 0 : darkOption;
537
+ }
538
+ return answer;
539
+ }
540
+ }
541
+ static foregroundTone(bgTone, ratio) {
542
+ const lighterTone = Contrast.lighterUnsafe(bgTone, ratio), darkerTone = Contrast.darkerUnsafe(bgTone, ratio), lighterRatio = Contrast.ratioOfTones(lighterTone, bgTone), darkerRatio = Contrast.ratioOfTones(darkerTone, bgTone);
543
+ if (DynamicColor.tonePrefersLightForeground(bgTone)) {
544
+ const negligibleDifference = Math.abs(lighterRatio - darkerRatio) < .1 && lighterRatio < ratio && darkerRatio < ratio;
545
+ return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
546
+ }
547
+ return darkerRatio >= ratio || darkerRatio >= lighterRatio ? darkerTone : lighterTone;
548
+ }
549
+ static tonePrefersLightForeground(tone) {
550
+ return Math.round(tone) < 60;
551
+ }
552
+ static toneAllowsLightForeground(tone) {
553
+ return Math.round(tone) <= 49;
554
+ }
555
+ static enableLightForeground(tone) {
556
+ return DynamicColor.tonePrefersLightForeground(tone) && !DynamicColor.toneAllowsLightForeground(tone) ? 49 : tone;
557
+ }
558
+ }
559
+
560
+ var Variant;
561
+
562
+ !function(Variant) {
563
+ Variant[Variant.MONOCHROME = 0] = "MONOCHROME", Variant[Variant.NEUTRAL = 1] = "NEUTRAL",
564
+ Variant[Variant.TONAL_SPOT = 2] = "TONAL_SPOT", Variant[Variant.VIBRANT = 3] = "VIBRANT",
565
+ Variant[Variant.EXPRESSIVE = 4] = "EXPRESSIVE", Variant[Variant.FIDELITY = 5] = "FIDELITY",
566
+ Variant[Variant.CONTENT = 6] = "CONTENT", Variant[Variant.RAINBOW = 7] = "RAINBOW",
567
+ Variant[Variant.FRUIT_SALAD = 8] = "FRUIT_SALAD";
568
+ }(Variant || (Variant = {}));
569
+
570
+ class ContrastCurve {
571
+ constructor(low, normal, medium, high) {
572
+ this.low = low, this.normal = normal, this.medium = medium, this.high = high;
573
+ }
574
+ getContrast(contrastLevel) {
575
+ return contrastLevel <= -1 ? this.low : contrastLevel < 0 ? lerp(this.low, this.normal, (contrastLevel - -1) / 1) : contrastLevel < .5 ? lerp(this.normal, this.medium, (contrastLevel - 0) / .5) : contrastLevel < 1 ? lerp(this.medium, this.high, (contrastLevel - .5) / .5) : this.high;
576
+ }
577
+ }
578
+
579
+ class ToneDeltaPair {
580
+ constructor(roleA, roleB, delta, polarity, stayTogether) {
581
+ this.roleA = roleA, this.roleB = roleB, this.delta = delta, this.polarity = polarity,
582
+ this.stayTogether = stayTogether;
583
+ }
584
+ }
585
+
586
+ function isFidelity(scheme) {
587
+ return scheme.variant === Variant.FIDELITY || scheme.variant === Variant.CONTENT;
588
+ }
589
+
590
+ function isMonochrome(scheme) {
591
+ return scheme.variant === Variant.MONOCHROME;
592
+ }
593
+
594
+ function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
595
+ let answer = tone, closestToChroma = Hct.from(hue, chroma, tone);
596
+ if (closestToChroma.chroma < chroma) {
597
+ let chromaPeak = closestToChroma.chroma;
598
+ for (;closestToChroma.chroma < chroma; ) {
599
+ answer += byDecreasingTone ? -1 : 1;
600
+ const potentialSolution = Hct.from(hue, chroma, answer);
601
+ if (chromaPeak > potentialSolution.chroma) break;
602
+ if (Math.abs(potentialSolution.chroma - chroma) < .4) break;
603
+ Math.abs(potentialSolution.chroma - chroma) < Math.abs(closestToChroma.chroma - chroma) && (closestToChroma = potentialSolution),
604
+ chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
605
+ }
606
+ }
607
+ return answer;
608
+ }
609
+
610
+ function viewingConditionsForAlbers(scheme) {
611
+ return ViewingConditions.make(void 0, void 0, scheme.isDark ? 30 : 80, void 0, void 0);
612
+ }
613
+
614
+ function performAlbers(prealbers, scheme) {
615
+ const albersd = prealbers.inViewingConditions(viewingConditionsForAlbers(scheme));
616
+ return DynamicColor.tonePrefersLightForeground(prealbers.tone) && !DynamicColor.toneAllowsLightForeground(albersd.tone) ? DynamicColor.enableLightForeground(prealbers.tone) : DynamicColor.enableLightForeground(albersd.tone);
617
+ }
618
+
619
+ class MaterialDynamicColors {
620
+ static highestSurface(s) {
621
+ return s.isDark ? MaterialDynamicColors.surfaceBright : MaterialDynamicColors.surfaceDim;
622
+ }
623
+ }
624
+
625
+ MaterialDynamicColors.contentAccentToneDelta = 15, MaterialDynamicColors.primaryPaletteKeyColor = DynamicColor.fromPalette({
626
+ name: "primary_palette_key_color",
627
+ palette: s => s.primaryPalette,
628
+ tone: s => s.primaryPalette.keyColor.tone
629
+ }), MaterialDynamicColors.secondaryPaletteKeyColor = DynamicColor.fromPalette({
630
+ name: "secondary_palette_key_color",
631
+ palette: s => s.secondaryPalette,
632
+ tone: s => s.secondaryPalette.keyColor.tone
633
+ }), MaterialDynamicColors.tertiaryPaletteKeyColor = DynamicColor.fromPalette({
634
+ name: "tertiary_palette_key_color",
635
+ palette: s => s.tertiaryPalette,
636
+ tone: s => s.tertiaryPalette.keyColor.tone
637
+ }), MaterialDynamicColors.neutralPaletteKeyColor = DynamicColor.fromPalette({
638
+ name: "neutral_palette_key_color",
639
+ palette: s => s.neutralPalette,
640
+ tone: s => s.neutralPalette.keyColor.tone
641
+ }), MaterialDynamicColors.neutralVariantPaletteKeyColor = DynamicColor.fromPalette({
642
+ name: "neutral_variant_palette_key_color",
643
+ palette: s => s.neutralVariantPalette,
644
+ tone: s => s.neutralVariantPalette.keyColor.tone
645
+ }), MaterialDynamicColors.background = DynamicColor.fromPalette({
646
+ name: "background",
647
+ palette: s => s.neutralPalette,
648
+ tone: s => s.isDark ? 6 : 98,
649
+ isBackground: !0
650
+ }), MaterialDynamicColors.onBackground = DynamicColor.fromPalette({
651
+ name: "on_background",
652
+ palette: s => s.neutralPalette,
653
+ tone: s => s.isDark ? 90 : 10,
654
+ background: s => MaterialDynamicColors.background,
655
+ contrastCurve: new ContrastCurve(3, 3, 4.5, 7)
656
+ }), MaterialDynamicColors.surface = DynamicColor.fromPalette({
657
+ name: "surface",
658
+ palette: s => s.neutralPalette,
659
+ tone: s => s.isDark ? 6 : 98,
660
+ isBackground: !0
661
+ }), MaterialDynamicColors.surfaceDim = DynamicColor.fromPalette({
662
+ name: "surface_dim",
663
+ palette: s => s.neutralPalette,
664
+ tone: s => s.isDark ? 6 : 87,
665
+ isBackground: !0
666
+ }), MaterialDynamicColors.surfaceBright = DynamicColor.fromPalette({
667
+ name: "surface_bright",
668
+ palette: s => s.neutralPalette,
669
+ tone: s => s.isDark ? 24 : 98,
670
+ isBackground: !0
671
+ }), MaterialDynamicColors.surfaceContainerLowest = DynamicColor.fromPalette({
672
+ name: "surface_container_lowest",
673
+ palette: s => s.neutralPalette,
674
+ tone: s => s.isDark ? 4 : 100,
675
+ isBackground: !0
676
+ }), MaterialDynamicColors.surfaceContainerLow = DynamicColor.fromPalette({
677
+ name: "surface_container_low",
678
+ palette: s => s.neutralPalette,
679
+ tone: s => s.isDark ? 10 : 96,
680
+ isBackground: !0
681
+ }), MaterialDynamicColors.surfaceContainer = DynamicColor.fromPalette({
682
+ name: "surface_container",
683
+ palette: s => s.neutralPalette,
684
+ tone: s => s.isDark ? 12 : 94,
685
+ isBackground: !0
686
+ }), MaterialDynamicColors.surfaceContainerHigh = DynamicColor.fromPalette({
687
+ name: "surface_container_high",
688
+ palette: s => s.neutralPalette,
689
+ tone: s => s.isDark ? 17 : 92,
690
+ isBackground: !0
691
+ }), MaterialDynamicColors.surfaceContainerHighest = DynamicColor.fromPalette({
692
+ name: "surface_container_highest",
693
+ palette: s => s.neutralPalette,
694
+ tone: s => s.isDark ? 22 : 90,
695
+ isBackground: !0
696
+ }), MaterialDynamicColors.onSurface = DynamicColor.fromPalette({
697
+ name: "on_surface",
698
+ palette: s => s.neutralPalette,
699
+ tone: s => s.isDark ? 90 : 10,
700
+ background: s => MaterialDynamicColors.highestSurface(s),
701
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
702
+ }), MaterialDynamicColors.surfaceVariant = DynamicColor.fromPalette({
703
+ name: "surface_variant",
704
+ palette: s => s.neutralVariantPalette,
705
+ tone: s => s.isDark ? 30 : 90,
706
+ isBackground: !0
707
+ }), MaterialDynamicColors.onSurfaceVariant = DynamicColor.fromPalette({
708
+ name: "on_surface_variant",
709
+ palette: s => s.neutralVariantPalette,
710
+ tone: s => s.isDark ? 80 : 30,
711
+ background: s => MaterialDynamicColors.highestSurface(s),
712
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
713
+ }), MaterialDynamicColors.inverseSurface = DynamicColor.fromPalette({
714
+ name: "inverse_surface",
715
+ palette: s => s.neutralPalette,
716
+ tone: s => s.isDark ? 90 : 20
717
+ }), MaterialDynamicColors.inverseOnSurface = DynamicColor.fromPalette({
718
+ name: "inverse_on_surface",
719
+ palette: s => s.neutralPalette,
720
+ tone: s => s.isDark ? 20 : 95,
721
+ background: s => MaterialDynamicColors.inverseSurface,
722
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
723
+ }), MaterialDynamicColors.outline = DynamicColor.fromPalette({
724
+ name: "outline",
725
+ palette: s => s.neutralVariantPalette,
726
+ tone: s => s.isDark ? 60 : 50,
727
+ background: s => MaterialDynamicColors.highestSurface(s),
728
+ contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7)
729
+ }), MaterialDynamicColors.outlineVariant = DynamicColor.fromPalette({
730
+ name: "outline_variant",
731
+ palette: s => s.neutralVariantPalette,
732
+ tone: s => s.isDark ? 30 : 80,
733
+ background: s => MaterialDynamicColors.highestSurface(s),
734
+ contrastCurve: new ContrastCurve(1, 1, 3, 7)
735
+ }), MaterialDynamicColors.shadow = DynamicColor.fromPalette({
736
+ name: "shadow",
737
+ palette: s => s.neutralPalette,
738
+ tone: s => 0
739
+ }), MaterialDynamicColors.scrim = DynamicColor.fromPalette({
740
+ name: "scrim",
741
+ palette: s => s.neutralPalette,
742
+ tone: s => 0
743
+ }), MaterialDynamicColors.surfaceTint = DynamicColor.fromPalette({
744
+ name: "surface_tint",
745
+ palette: s => s.primaryPalette,
746
+ tone: s => s.isDark ? 80 : 40,
747
+ isBackground: !0
748
+ }), MaterialDynamicColors.primary = DynamicColor.fromPalette({
749
+ name: "primary",
750
+ palette: s => s.primaryPalette,
751
+ tone: s => isMonochrome(s) ? s.isDark ? 100 : 0 : s.isDark ? 80 : 40,
752
+ isBackground: !0,
753
+ background: s => MaterialDynamicColors.highestSurface(s),
754
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
755
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryContainer, MaterialDynamicColors.primary, 15, "nearer", !1)
756
+ }), MaterialDynamicColors.onPrimary = DynamicColor.fromPalette({
757
+ name: "on_primary",
758
+ palette: s => s.primaryPalette,
759
+ tone: s => isMonochrome(s) ? s.isDark ? 10 : 90 : s.isDark ? 20 : 100,
760
+ background: s => MaterialDynamicColors.primary,
761
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
762
+ }), MaterialDynamicColors.primaryContainer = DynamicColor.fromPalette({
763
+ name: "primary_container",
764
+ palette: s => s.primaryPalette,
765
+ tone: s => isFidelity(s) ? performAlbers(s.sourceColorHct, s) : isMonochrome(s) ? s.isDark ? 85 : 25 : s.isDark ? 30 : 90,
766
+ isBackground: !0,
767
+ background: s => MaterialDynamicColors.highestSurface(s),
768
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
769
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryContainer, MaterialDynamicColors.primary, 15, "nearer", !1)
770
+ }), MaterialDynamicColors.onPrimaryContainer = DynamicColor.fromPalette({
771
+ name: "on_primary_container",
772
+ palette: s => s.primaryPalette,
773
+ tone: s => isFidelity(s) ? DynamicColor.foregroundTone(MaterialDynamicColors.primaryContainer.tone(s), 4.5) : isMonochrome(s) ? s.isDark ? 0 : 100 : s.isDark ? 90 : 10,
774
+ background: s => MaterialDynamicColors.primaryContainer,
775
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
776
+ }), MaterialDynamicColors.inversePrimary = DynamicColor.fromPalette({
777
+ name: "inverse_primary",
778
+ palette: s => s.primaryPalette,
779
+ tone: s => s.isDark ? 40 : 80,
780
+ background: s => MaterialDynamicColors.inverseSurface,
781
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
782
+ }), MaterialDynamicColors.secondary = DynamicColor.fromPalette({
783
+ name: "secondary",
784
+ palette: s => s.secondaryPalette,
785
+ tone: s => s.isDark ? 80 : 40,
786
+ isBackground: !0,
787
+ background: s => MaterialDynamicColors.highestSurface(s),
788
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
789
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryContainer, MaterialDynamicColors.secondary, 15, "nearer", !1)
790
+ }), MaterialDynamicColors.onSecondary = DynamicColor.fromPalette({
791
+ name: "on_secondary",
792
+ palette: s => s.secondaryPalette,
793
+ tone: s => isMonochrome(s) ? s.isDark ? 10 : 100 : s.isDark ? 20 : 100,
794
+ background: s => MaterialDynamicColors.secondary,
795
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
796
+ }), MaterialDynamicColors.secondaryContainer = DynamicColor.fromPalette({
797
+ name: "secondary_container",
798
+ palette: s => s.secondaryPalette,
799
+ tone: s => {
800
+ const initialTone = s.isDark ? 30 : 90;
801
+ if (isMonochrome(s)) return s.isDark ? 30 : 85;
802
+ if (!isFidelity(s)) return initialTone;
803
+ let answer = findDesiredChromaByTone(s.secondaryPalette.hue, s.secondaryPalette.chroma, initialTone, !s.isDark);
804
+ return answer = performAlbers(s.secondaryPalette.getHct(answer), s), answer;
805
+ },
806
+ isBackground: !0,
807
+ background: s => MaterialDynamicColors.highestSurface(s),
808
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
809
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryContainer, MaterialDynamicColors.secondary, 15, "nearer", !1)
810
+ }), MaterialDynamicColors.onSecondaryContainer = DynamicColor.fromPalette({
811
+ name: "on_secondary_container",
812
+ palette: s => s.secondaryPalette,
813
+ tone: s => isFidelity(s) ? DynamicColor.foregroundTone(MaterialDynamicColors.secondaryContainer.tone(s), 4.5) : s.isDark ? 90 : 10,
814
+ background: s => MaterialDynamicColors.secondaryContainer,
815
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
816
+ }), MaterialDynamicColors.tertiary = DynamicColor.fromPalette({
817
+ name: "tertiary",
818
+ palette: s => s.tertiaryPalette,
819
+ tone: s => isMonochrome(s) ? s.isDark ? 90 : 25 : s.isDark ? 80 : 40,
820
+ isBackground: !0,
821
+ background: s => MaterialDynamicColors.highestSurface(s),
822
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
823
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryContainer, MaterialDynamicColors.tertiary, 15, "nearer", !1)
824
+ }), MaterialDynamicColors.onTertiary = DynamicColor.fromPalette({
825
+ name: "on_tertiary",
826
+ palette: s => s.tertiaryPalette,
827
+ tone: s => isMonochrome(s) ? s.isDark ? 10 : 90 : s.isDark ? 20 : 100,
828
+ background: s => MaterialDynamicColors.tertiary,
829
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
830
+ }), MaterialDynamicColors.tertiaryContainer = DynamicColor.fromPalette({
831
+ name: "tertiary_container",
832
+ palette: s => s.tertiaryPalette,
833
+ tone: s => {
834
+ if (isMonochrome(s)) return s.isDark ? 60 : 49;
835
+ if (!isFidelity(s)) return s.isDark ? 30 : 90;
836
+ const albersTone = performAlbers(s.tertiaryPalette.getHct(s.sourceColorHct.tone), s), proposedHct = s.tertiaryPalette.getHct(albersTone);
837
+ return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
838
+ },
839
+ isBackground: !0,
840
+ background: s => MaterialDynamicColors.highestSurface(s),
841
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
842
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryContainer, MaterialDynamicColors.tertiary, 15, "nearer", !1)
843
+ }), MaterialDynamicColors.onTertiaryContainer = DynamicColor.fromPalette({
844
+ name: "on_tertiary_container",
845
+ palette: s => s.tertiaryPalette,
846
+ tone: s => isMonochrome(s) ? s.isDark ? 0 : 100 : isFidelity(s) ? DynamicColor.foregroundTone(MaterialDynamicColors.tertiaryContainer.tone(s), 4.5) : s.isDark ? 90 : 10,
847
+ background: s => MaterialDynamicColors.tertiaryContainer,
848
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
849
+ }), MaterialDynamicColors.error = DynamicColor.fromPalette({
850
+ name: "error",
851
+ palette: s => s.errorPalette,
852
+ tone: s => s.isDark ? 80 : 40,
853
+ isBackground: !0,
854
+ background: s => MaterialDynamicColors.highestSurface(s),
855
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
856
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.errorContainer, MaterialDynamicColors.error, 15, "nearer", !1)
857
+ }), MaterialDynamicColors.onError = DynamicColor.fromPalette({
858
+ name: "on_error",
859
+ palette: s => s.errorPalette,
860
+ tone: s => s.isDark ? 20 : 100,
861
+ background: s => MaterialDynamicColors.error,
862
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
863
+ }), MaterialDynamicColors.errorContainer = DynamicColor.fromPalette({
864
+ name: "error_container",
865
+ palette: s => s.errorPalette,
866
+ tone: s => s.isDark ? 30 : 90,
867
+ isBackground: !0,
868
+ background: s => MaterialDynamicColors.highestSurface(s),
869
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
870
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.errorContainer, MaterialDynamicColors.error, 15, "nearer", !1)
871
+ }), MaterialDynamicColors.onErrorContainer = DynamicColor.fromPalette({
872
+ name: "on_error_container",
873
+ palette: s => s.errorPalette,
874
+ tone: s => s.isDark ? 90 : 10,
875
+ background: s => MaterialDynamicColors.errorContainer,
876
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
877
+ }), MaterialDynamicColors.primaryFixed = DynamicColor.fromPalette({
878
+ name: "primary_fixed",
879
+ palette: s => s.primaryPalette,
880
+ tone: s => isMonochrome(s) ? 40 : 90,
881
+ isBackground: !0,
882
+ background: s => MaterialDynamicColors.highestSurface(s),
883
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
884
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryFixed, MaterialDynamicColors.primaryFixedDim, 10, "lighter", !0)
885
+ }), MaterialDynamicColors.primaryFixedDim = DynamicColor.fromPalette({
886
+ name: "primary_fixed_dim",
887
+ palette: s => s.primaryPalette,
888
+ tone: s => isMonochrome(s) ? 30 : 80,
889
+ isBackground: !0,
890
+ background: s => MaterialDynamicColors.highestSurface(s),
891
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
892
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryFixed, MaterialDynamicColors.primaryFixedDim, 10, "lighter", !0)
893
+ }), MaterialDynamicColors.onPrimaryFixed = DynamicColor.fromPalette({
894
+ name: "on_primary_fixed",
895
+ palette: s => s.primaryPalette,
896
+ tone: s => isMonochrome(s) ? 100 : 10,
897
+ background: s => MaterialDynamicColors.primaryFixedDim,
898
+ secondBackground: s => MaterialDynamicColors.primaryFixed,
899
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
900
+ }), MaterialDynamicColors.onPrimaryFixedVariant = DynamicColor.fromPalette({
901
+ name: "on_primary_fixed_variant",
902
+ palette: s => s.primaryPalette,
903
+ tone: s => isMonochrome(s) ? 90 : 30,
904
+ background: s => MaterialDynamicColors.primaryFixedDim,
905
+ secondBackground: s => MaterialDynamicColors.primaryFixed,
906
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
907
+ }), MaterialDynamicColors.secondaryFixed = DynamicColor.fromPalette({
908
+ name: "secondary_fixed",
909
+ palette: s => s.secondaryPalette,
910
+ tone: s => isMonochrome(s) ? 80 : 90,
911
+ isBackground: !0,
912
+ background: s => MaterialDynamicColors.highestSurface(s),
913
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
914
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryFixed, MaterialDynamicColors.secondaryFixedDim, 10, "lighter", !0)
915
+ }), MaterialDynamicColors.secondaryFixedDim = DynamicColor.fromPalette({
916
+ name: "secondary_fixed_dim",
917
+ palette: s => s.secondaryPalette,
918
+ tone: s => isMonochrome(s) ? 70 : 80,
919
+ isBackground: !0,
920
+ background: s => MaterialDynamicColors.highestSurface(s),
921
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
922
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryFixed, MaterialDynamicColors.secondaryFixedDim, 10, "lighter", !0)
923
+ }), MaterialDynamicColors.onSecondaryFixed = DynamicColor.fromPalette({
924
+ name: "on_secondary_fixed",
925
+ palette: s => s.secondaryPalette,
926
+ tone: s => 10,
927
+ background: s => MaterialDynamicColors.secondaryFixedDim,
928
+ secondBackground: s => MaterialDynamicColors.secondaryFixed,
929
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
930
+ }), MaterialDynamicColors.onSecondaryFixedVariant = DynamicColor.fromPalette({
931
+ name: "on_secondary_fixed_variant",
932
+ palette: s => s.secondaryPalette,
933
+ tone: s => isMonochrome(s) ? 25 : 30,
934
+ background: s => MaterialDynamicColors.secondaryFixedDim,
935
+ secondBackground: s => MaterialDynamicColors.secondaryFixed,
936
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
937
+ }), MaterialDynamicColors.tertiaryFixed = DynamicColor.fromPalette({
938
+ name: "tertiary_fixed",
939
+ palette: s => s.tertiaryPalette,
940
+ tone: s => isMonochrome(s) ? 40 : 90,
941
+ isBackground: !0,
942
+ background: s => MaterialDynamicColors.highestSurface(s),
943
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
944
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryFixed, MaterialDynamicColors.tertiaryFixedDim, 10, "lighter", !0)
945
+ }), MaterialDynamicColors.tertiaryFixedDim = DynamicColor.fromPalette({
946
+ name: "tertiary_fixed_dim",
947
+ palette: s => s.tertiaryPalette,
948
+ tone: s => isMonochrome(s) ? 30 : 80,
949
+ isBackground: !0,
950
+ background: s => MaterialDynamicColors.highestSurface(s),
951
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
952
+ toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryFixed, MaterialDynamicColors.tertiaryFixedDim, 10, "lighter", !0)
953
+ }), MaterialDynamicColors.onTertiaryFixed = DynamicColor.fromPalette({
954
+ name: "on_tertiary_fixed",
955
+ palette: s => s.tertiaryPalette,
956
+ tone: s => isMonochrome(s) ? 100 : 10,
957
+ background: s => MaterialDynamicColors.tertiaryFixedDim,
958
+ secondBackground: s => MaterialDynamicColors.tertiaryFixed,
959
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
960
+ }), MaterialDynamicColors.onTertiaryFixedVariant = DynamicColor.fromPalette({
961
+ name: "on_tertiary_fixed_variant",
962
+ palette: s => s.tertiaryPalette,
963
+ tone: s => isMonochrome(s) ? 90 : 30,
964
+ background: s => MaterialDynamicColors.tertiaryFixedDim,
965
+ secondBackground: s => MaterialDynamicColors.tertiaryFixed,
966
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
967
+ });
968
+
426
969
  class TonalPalette {
427
970
  static fromInt(argb) {
428
971
  const hct = Hct.fromInt(argb);
429
- return TonalPalette.fromHueAndChroma(hct.hue, hct.chroma);
972
+ return TonalPalette.fromHct(hct);
973
+ }
974
+ static fromHct(hct) {
975
+ return new TonalPalette(hct.hue, hct.chroma, hct);
430
976
  }
431
977
  static fromHueAndChroma(hue, chroma) {
432
- return new TonalPalette(hue, chroma);
978
+ return new TonalPalette(hue, chroma, TonalPalette.createKeyColor(hue, chroma));
433
979
  }
434
- constructor(hue, chroma) {
435
- this.hue = hue, this.chroma = chroma, this.cache = new Map;
980
+ constructor(hue, chroma, keyColor) {
981
+ this.hue = hue, this.chroma = chroma, this.keyColor = keyColor, this.cache = new Map;
982
+ }
983
+ static createKeyColor(hue, chroma) {
984
+ let smallestDeltaHct = Hct.from(hue, chroma, 50), smallestDelta = Math.abs(smallestDeltaHct.chroma - chroma);
985
+ for (let delta = 1; delta < 50; delta += 1) {
986
+ if (Math.round(chroma) === Math.round(smallestDeltaHct.chroma)) return smallestDeltaHct;
987
+ const hctAdd = Hct.from(hue, chroma, 50 + delta), hctAddDelta = Math.abs(hctAdd.chroma - chroma);
988
+ hctAddDelta < smallestDelta && (smallestDelta = hctAddDelta, smallestDeltaHct = hctAdd);
989
+ const hctSubtract = Hct.from(hue, chroma, 50 - delta), hctSubtractDelta = Math.abs(hctSubtract.chroma - chroma);
990
+ hctSubtractDelta < smallestDelta && (smallestDelta = hctSubtractDelta, smallestDeltaHct = hctSubtract);
991
+ }
992
+ return smallestDeltaHct;
436
993
  }
437
994
  tone(tone) {
438
995
  let argb = this.cache.get(tone);
439
996
  return void 0 === argb && (argb = Hct.from(this.hue, this.chroma, tone).toInt(),
440
997
  this.cache.set(tone, argb)), argb;
441
998
  }
999
+ getHct(tone) {
1000
+ return Hct.fromInt(this.tone(tone));
1001
+ }
442
1002
  }
443
1003
 
444
1004
  class CorePalette {
@@ -1475,7 +2035,7 @@ class Event {
1475
2035
  const eventsArray = Array.isArray(events) ? events : events.split(' ');
1476
2036
 
1477
2037
  // 本对象事件
1478
- // ['local:event'] or ['.event'],不向父组件传递
2038
+ // ['local::event'] or ['.event'],不向父组件传递
1479
2039
  const selfEvents = eventsArray.map(ev => ev.replace(/local::|^[.]/, ''));
1480
2040
 
1481
2041
  // 非本对象事件,向上传递时,转换为对象,记录来源
@@ -1650,6 +2210,12 @@ class Page extends Event {
1650
2210
  this.emit('pageBack', this);
1651
2211
  }
1652
2212
 
2213
+ change(view) {
2214
+ this.emit('local::change', view);
2215
+ // 向上触发跨页面事件,存在安全问题
2216
+ this.emit('pageChange', this);
2217
+ }
2218
+
1653
2219
  hide(view) {
1654
2220
  this.emit('local::hide', view);
1655
2221
  // 向上触发跨页面事件,存在安全问题
@@ -1665,13 +2231,16 @@ class Page extends Event {
1665
2231
 
1666
2232
  /**
1667
2233
  * Wia app、router等继承类,通过模块化扩展类功能
2234
+ * 使用 use 装载,注解可能完成类似功能
2235
+ * 不装载则需在代码中按普通泪,单独引用、创建、使用
2236
+ * 装载的模块可能影响其他模块
1668
2237
  */
1669
2238
 
1670
2239
  class Module extends Event {
1671
2240
  constructor(params = {}, parents = []) {
1672
2241
  super(params, parents);
1673
- const self = this;
1674
- self.params = params;
2242
+ const self = this;
2243
+ self.params = params;
1675
2244
  }
1676
2245
 
1677
2246
  // eslint-disable-next-line
@@ -1711,10 +2280,7 @@ class Module extends Event {
1711
2280
  if (!instance.modules) return;
1712
2281
 
1713
2282
  // 从原型中获得的模块类引用
1714
- const module =
1715
- typeof moduleName === 'string'
1716
- ? instance.modules[moduleName]
1717
- : moduleName;
2283
+ const module = typeof moduleName === 'string' ? instance.modules[moduleName] : moduleName;
1718
2284
  if (!module) return;
1719
2285
 
1720
2286
  // 扩展实例的方法和属性,Extend instance methods and props
@@ -1731,8 +2297,16 @@ class Module extends Event {
1731
2297
 
1732
2298
  // 将扩展模块中的on加载到实例的事件侦听中,比如 init 在实例初始化时被调用
1733
2299
  if (module.on && instance.on) {
1734
- Object.keys(module.on).forEach(moduleEventName => {
1735
- instance.on(moduleEventName, module.on[moduleEventName]);
2300
+ Object.keys(module.on).forEach(eventName => {
2301
+ // 避免模块事件异常溢出影响其他模块
2302
+ const fn = () => {
2303
+ try {
2304
+ module.on[eventName]();
2305
+ } catch (e) {
2306
+ console.log(`${moduleName}.on${eventName} exp:${e.message}`);
2307
+ }
2308
+ };
2309
+ instance.on(eventName, fn);
1736
2310
  });
1737
2311
  }
1738
2312
 
@@ -1742,10 +2316,8 @@ class Module extends Event {
1742
2316
  Object.keys(module.vnode).forEach(vnodeId => {
1743
2317
  Object.keys(module.vnode[vnodeId]).forEach(hookName => {
1744
2318
  const handler = module.vnode[vnodeId][hookName];
1745
- if (!instance.vnodeHooks[hookName])
1746
- instance.vnodeHooks[hookName] = {};
1747
- if (!instance.vnodeHooks[hookName][vnodeId])
1748
- instance.vnodeHooks[hookName][vnodeId] = [];
2319
+ if (!instance.vnodeHooks[hookName]) instance.vnodeHooks[hookName] = {};
2320
+ if (!instance.vnodeHooks[hookName][vnodeId]) instance.vnodeHooks[hookName][vnodeId] = [];
1749
2321
  instance.vnodeHooks[hookName][vnodeId].push(handler.bind(instance));
1750
2322
  });
1751
2323
  });
@@ -1784,9 +2356,7 @@ class Module extends Event {
1784
2356
  static installModule(module, ...params) {
1785
2357
  const Class = this;
1786
2358
  if (!Class.prototype.modules) Class.prototype.modules = {};
1787
- const name =
1788
- module.name ||
1789
- `${Object.keys(Class.prototype.modules).length}_${$.now()}`;
2359
+ const name = module.name || `${Object.keys(Class.prototype.modules).length}_${$.now()}`;
1790
2360
  // 原型属性中引用该模块类,类实例
1791
2361
  Class.prototype.modules[name] = module;
1792
2362
  // 模块如果定义了原型,则将模块原型加载到类原型
@@ -1809,7 +2379,7 @@ class Module extends Event {
1809
2379
  }
1810
2380
 
1811
2381
  /**
1812
- * 加载类扩展模块到类
2382
+ * 加载扩展模块到类
1813
2383
  * @param {*} module
1814
2384
  * @param {...any} params
1815
2385
  */
@@ -2163,7 +2733,8 @@ const Resize = {
2163
2733
  };
2164
2734
 
2165
2735
  /**
2166
- * document 绑定click事件
2736
+ * document 绑定click事件,传递到 app.on
2737
+ * 触发所有子模块的 clicks
2167
2738
  * 支持touch则绑定touch,否则绑定click
2168
2739
  * 无论touch 还是 click事件,都会触发事件响应函数
2169
2740
  * @param {*} cb
@@ -2254,6 +2825,556 @@ const Click = {
2254
2825
  },
2255
2826
  };
2256
2827
 
2828
+ /* eslint-disable no-nested-ternary */
2829
+
2830
+
2831
+ const {extend: extend$1} = Utils;
2832
+ const {device: device$1, support: support$1} = $;
2833
+
2834
+ function initTouch() {
2835
+ const app = this;
2836
+ const params = app.params.touch;
2837
+ const useRipple = params[`${app.theme}TouchRipple`];
2838
+
2839
+ if (device$1.ios && device$1.webView) {
2840
+ // Strange hack required for iOS 8 webview to work on inputs
2841
+ window.addEventListener('touchstart', () => {});
2842
+ }
2843
+
2844
+ let touchStartX;
2845
+ let touchStartY;
2846
+ let targetElement;
2847
+ let isMoved;
2848
+ let tapHoldFired;
2849
+ let tapHoldTimeout;
2850
+ let preventClick;
2851
+
2852
+ let activableElement;
2853
+ let activeTimeout;
2854
+
2855
+ let rippleWave;
2856
+ let rippleTarget;
2857
+ let rippleTimeout;
2858
+
2859
+ function findActivableElement(el) {
2860
+ const target = $(el);
2861
+ const parents = target.parents(params.activeStateElements);
2862
+ if (target.closest('.no-active-state').length) {
2863
+ return null;
2864
+ }
2865
+ let activable;
2866
+ if (target.is(params.activeStateElements)) {
2867
+ activable = target;
2868
+ }
2869
+ if (parents.length > 0) {
2870
+ activable = activable ? activable.add(parents) : parents;
2871
+ }
2872
+ if (activable && activable.length > 1) {
2873
+ const newActivable = [];
2874
+ let preventPropagation;
2875
+ for (let i = 0; i < activable.length; i += 1) {
2876
+ if (!preventPropagation) {
2877
+ newActivable.push(activable[i]);
2878
+ if (
2879
+ activable.eq(i).hasClass('prevent-active-state-propagation') ||
2880
+ activable.eq(i).hasClass('no-active-state-propagation')
2881
+ ) {
2882
+ preventPropagation = true;
2883
+ }
2884
+ }
2885
+ }
2886
+ activable = $(newActivable);
2887
+ }
2888
+ return activable || target;
2889
+ }
2890
+
2891
+ function isInsideScrollableView(el) {
2892
+ const pageContent = el.parents('.page-content');
2893
+ return pageContent.length > 0;
2894
+ }
2895
+
2896
+ function addActive() {
2897
+ if (!activableElement) return;
2898
+ activableElement.addClass('active-state');
2899
+ }
2900
+ function removeActive() {
2901
+ if (!activableElement) return;
2902
+ activableElement.removeClass('active-state');
2903
+ activableElement = null;
2904
+ }
2905
+
2906
+ // Ripple handlers
2907
+ function findRippleElement(el) {
2908
+ const rippleElements = params.touchRippleElements;
2909
+ const $el = $(el);
2910
+ if ($el.is(rippleElements)) {
2911
+ if ($el.hasClass('no-ripple')) {
2912
+ return false;
2913
+ }
2914
+ return $el;
2915
+ }
2916
+ if ($el.parents(rippleElements).length > 0) {
2917
+ const rippleParent = $el.parents(rippleElements).eq(0);
2918
+ if (rippleParent.hasClass('no-ripple')) {
2919
+ return false;
2920
+ }
2921
+ return rippleParent;
2922
+ }
2923
+ return false;
2924
+ }
2925
+
2926
+ function createRipple($el, x, y) {
2927
+ if (!$el) return;
2928
+ rippleWave = app.touchRipple.create(app, $el, x, y);
2929
+ }
2930
+
2931
+ function removeRipple() {
2932
+ if (!rippleWave) return;
2933
+ rippleWave.remove();
2934
+ rippleWave = undefined;
2935
+ rippleTarget = undefined;
2936
+ }
2937
+ function rippleTouchStart(el) {
2938
+ rippleTarget = findRippleElement(el);
2939
+ if (!rippleTarget || rippleTarget.length === 0) {
2940
+ rippleTarget = undefined;
2941
+ return;
2942
+ }
2943
+ const inScrollable = isInsideScrollableView(rippleTarget);
2944
+
2945
+ if (!inScrollable) {
2946
+ removeRipple();
2947
+ createRipple(rippleTarget, touchStartX, touchStartY);
2948
+ } else {
2949
+ clearTimeout(rippleTimeout);
2950
+ rippleTimeout = setTimeout(() => {
2951
+ removeRipple();
2952
+ createRipple(rippleTarget, touchStartX, touchStartY);
2953
+ }, 80);
2954
+ }
2955
+ }
2956
+ function rippleTouchMove() {
2957
+ clearTimeout(rippleTimeout);
2958
+ removeRipple();
2959
+ }
2960
+ function rippleTouchEnd() {
2961
+ if (!rippleWave && rippleTarget && !isMoved) {
2962
+ clearTimeout(rippleTimeout);
2963
+ createRipple(rippleTarget, touchStartX, touchStartY);
2964
+ setTimeout(removeRipple, 0);
2965
+ } else {
2966
+ removeRipple();
2967
+ }
2968
+ }
2969
+
2970
+ // Mouse Handlers
2971
+ function handleMouseDown(e) {
2972
+ const $activableEl = findActivableElement(e.target);
2973
+ if ($activableEl) {
2974
+ $activableEl.addClass('active-state');
2975
+ if ('which' in e && e.which === 3) {
2976
+ setTimeout(() => {
2977
+ $('.active-state').removeClass('active-state');
2978
+ }, 0);
2979
+ }
2980
+ }
2981
+
2982
+ if (useRipple) {
2983
+ touchStartX = e.pageX;
2984
+ touchStartY = e.pageY;
2985
+ rippleTouchStart(e.target, e.pageX, e.pageY);
2986
+ }
2987
+ }
2988
+ function handleMouseMove() {
2989
+ if (!params.activeStateOnMouseMove) {
2990
+ $('.active-state').removeClass('active-state');
2991
+ }
2992
+ if (useRipple) {
2993
+ rippleTouchMove();
2994
+ }
2995
+ }
2996
+ function handleMouseUp() {
2997
+ $('.active-state').removeClass('active-state');
2998
+ if (useRipple) {
2999
+ rippleTouchEnd();
3000
+ }
3001
+ }
3002
+
3003
+ function handleTouchCancel() {
3004
+ targetElement = null;
3005
+
3006
+ // Remove Active State
3007
+ clearTimeout(activeTimeout);
3008
+ clearTimeout(tapHoldTimeout);
3009
+ if (params.activeState) {
3010
+ removeActive();
3011
+ }
3012
+
3013
+ // Remove Ripple
3014
+ if (useRipple) {
3015
+ rippleTouchEnd();
3016
+ }
3017
+ }
3018
+
3019
+ let isScrolling;
3020
+ let isSegmentedStrong = false;
3021
+ let segmentedStrongEl = null;
3022
+
3023
+ const touchMoveActivableIos = '.dialog-button, .actions-button';
3024
+ let isTouchMoveActivable = false;
3025
+ let touchmoveActivableEl = null;
3026
+
3027
+ function handleTouchStart(e) {
3028
+ if (!e.isTrusted) return true;
3029
+ isMoved = false;
3030
+ tapHoldFired = false;
3031
+ preventClick = false;
3032
+ isScrolling = undefined;
3033
+ if (e.targetTouches.length > 1) {
3034
+ if (activableElement) removeActive();
3035
+ return true;
3036
+ }
3037
+ if (e.touches.length > 1 && activableElement) {
3038
+ removeActive();
3039
+ }
3040
+ if (params.tapHold) {
3041
+ if (tapHoldTimeout) clearTimeout(tapHoldTimeout);
3042
+ tapHoldTimeout = setTimeout(() => {
3043
+ if (e && e.touches && e.touches.length > 1) return;
3044
+ tapHoldFired = true;
3045
+ e.preventDefault();
3046
+ preventClick = true;
3047
+ $(e.target).trigger('taphold', e);
3048
+ app.emit('taphold', e);
3049
+ }, params.tapHoldDelay);
3050
+ }
3051
+ targetElement = e.target;
3052
+ touchStartX = e.targetTouches[0].pageX;
3053
+ touchStartY = e.targetTouches[0].pageY;
3054
+ isSegmentedStrong = e.target.closest(
3055
+ '.segmented-strong .button-active, .segmented-strong .tab-link-active'
3056
+ );
3057
+ isTouchMoveActivable = app.theme === 'ios' && e.target.closest(touchMoveActivableIos);
3058
+ if (isSegmentedStrong) {
3059
+ segmentedStrongEl = isSegmentedStrong.closest('.segmented-strong');
3060
+ }
3061
+
3062
+ if (params.activeState) {
3063
+ activableElement = findActivableElement(targetElement);
3064
+ if (activableElement && !isInsideScrollableView(activableElement)) {
3065
+ addActive();
3066
+ } else if (activableElement) {
3067
+ activeTimeout = setTimeout(addActive, 80);
3068
+ }
3069
+ }
3070
+ if (useRipple) {
3071
+ rippleTouchStart(targetElement);
3072
+ }
3073
+ return true;
3074
+ }
3075
+
3076
+ function handleTouchMove(e) {
3077
+ if (!e.isTrusted) return;
3078
+ let touch;
3079
+ let distance;
3080
+ let shouldRemoveActive = true;
3081
+
3082
+ if (e.type === 'touchmove') {
3083
+ touch = e.targetTouches[0];
3084
+ distance = params.touchClicksDistanceThreshold;
3085
+ }
3086
+
3087
+ const touchCurrentX = e.targetTouches[0].pageX;
3088
+ const touchCurrentY = e.targetTouches[0].pageY;
3089
+
3090
+ if (typeof isScrolling === 'undefined') {
3091
+ isScrolling = !!(
3092
+ isScrolling || Math.abs(touchCurrentY - touchStartY) > Math.abs(touchCurrentX - touchStartX)
3093
+ );
3094
+ }
3095
+
3096
+ if (isTouchMoveActivable || (!isScrolling && isSegmentedStrong && segmentedStrongEl)) {
3097
+ if (e.cancelable) e.preventDefault();
3098
+ }
3099
+
3100
+ if (!isScrolling && isSegmentedStrong && segmentedStrongEl) {
3101
+ const elementFromPoint = document.elementFromPoint(
3102
+ e.targetTouches[0].clientX,
3103
+ e.targetTouches[0].clientY
3104
+ );
3105
+ const buttonEl = elementFromPoint.closest(
3106
+ '.segmented-strong .button:not(.button-active):not(.tab-link-active)'
3107
+ );
3108
+ if (buttonEl && segmentedStrongEl.contains(buttonEl)) {
3109
+ $(buttonEl).trigger('click', 'f7Segmented');
3110
+ targetElement = buttonEl;
3111
+ }
3112
+ }
3113
+
3114
+ if (distance && touch) {
3115
+ const {pageX, pageY} = touch;
3116
+ if (Math.abs(pageX - touchStartX) > distance || Math.abs(pageY - touchStartY) > distance) {
3117
+ isMoved = true;
3118
+ }
3119
+ } else {
3120
+ isMoved = true;
3121
+ }
3122
+
3123
+ if (isMoved) {
3124
+ preventClick = true;
3125
+ // Keep active state on touchMove (for dialog and actions buttons)
3126
+ if (isTouchMoveActivable) {
3127
+ const elementFromPoint = document.elementFromPoint(
3128
+ e.targetTouches[0].clientX,
3129
+ e.targetTouches[0].clientY
3130
+ );
3131
+ touchmoveActivableEl = elementFromPoint.closest(touchMoveActivableIos);
3132
+ if (
3133
+ touchmoveActivableEl &&
3134
+ activableElement &&
3135
+ activableElement[0] === touchmoveActivableEl
3136
+ ) {
3137
+ shouldRemoveActive = false;
3138
+ } else if (touchmoveActivableEl) {
3139
+ setTimeout(() => {
3140
+ activableElement = findActivableElement(touchmoveActivableEl);
3141
+ addActive();
3142
+ });
3143
+ }
3144
+ }
3145
+ if (params.tapHold) {
3146
+ clearTimeout(tapHoldTimeout);
3147
+ }
3148
+ if (params.activeState && shouldRemoveActive) {
3149
+ clearTimeout(activeTimeout);
3150
+ removeActive();
3151
+ }
3152
+ if (useRipple) {
3153
+ rippleTouchMove();
3154
+ }
3155
+ }
3156
+ }
3157
+
3158
+ function handleTouchEnd(e) {
3159
+ if (!e.isTrusted) return true;
3160
+ isScrolling = undefined;
3161
+ isSegmentedStrong = false;
3162
+ segmentedStrongEl = null;
3163
+ isTouchMoveActivable = false;
3164
+ clearTimeout(activeTimeout);
3165
+ clearTimeout(tapHoldTimeout);
3166
+ if (touchmoveActivableEl) {
3167
+ $(touchmoveActivableEl).trigger('click', 'f7TouchMoveActivable');
3168
+ touchmoveActivableEl = null;
3169
+ }
3170
+ if (document.activeElement === e.target) {
3171
+ if (params.activeState) removeActive();
3172
+ if (useRipple) {
3173
+ rippleTouchEnd();
3174
+ }
3175
+ return true;
3176
+ }
3177
+ if (params.activeState) {
3178
+ addActive();
3179
+ setTimeout(removeActive, 0);
3180
+ }
3181
+ if (useRipple) {
3182
+ rippleTouchEnd();
3183
+ }
3184
+ if ((params.tapHoldPreventClicks && tapHoldFired) || preventClick) {
3185
+ if (e.cancelable) e.preventDefault();
3186
+ preventClick = true;
3187
+ return false;
3188
+ }
3189
+ return true;
3190
+ }
3191
+
3192
+ function handleClick(e) {
3193
+ const isOverswipe = e && e.detail && e.detail === 'f7Overswipe';
3194
+ const isSegmented = e && e.detail && e.detail === 'f7Segmented';
3195
+ // eslint-disable-next-line
3196
+ const isTouchMoveActivable = e && e.detail && e.detail === 'f7TouchMoveActivable';
3197
+ let localPreventClick = preventClick;
3198
+ if (targetElement && e.target !== targetElement) {
3199
+ if (isOverswipe || isSegmented || isTouchMoveActivable) {
3200
+ localPreventClick = false;
3201
+ } else {
3202
+ localPreventClick = true;
3203
+ }
3204
+ } else if (isTouchMoveActivable) {
3205
+ localPreventClick = false;
3206
+ }
3207
+ if (params.tapHold && params.tapHoldPreventClicks && tapHoldFired) {
3208
+ localPreventClick = true;
3209
+ }
3210
+ if (localPreventClick) {
3211
+ e.stopImmediatePropagation();
3212
+ e.stopPropagation();
3213
+ e.preventDefault();
3214
+ }
3215
+
3216
+ if (params.tapHold) {
3217
+ tapHoldTimeout = setTimeout(
3218
+ () => {
3219
+ tapHoldFired = false;
3220
+ },
3221
+ device$1.ios || device$1.androidChrome ? 100 : 400
3222
+ );
3223
+ }
3224
+ preventClick = false;
3225
+ targetElement = null;
3226
+
3227
+ return !localPreventClick;
3228
+ }
3229
+
3230
+ /**
3231
+ * document touch �¼����ݸ� app.on
3232
+ * @param {*} name
3233
+ * @param {*} e
3234
+ */
3235
+ function emitAppTouchEvent(name, e) {
3236
+ app.emit({
3237
+ events: name,
3238
+ data: [e],
3239
+ });
3240
+ }
3241
+
3242
+ function appTouchStartActive(e) {
3243
+ emitAppTouchEvent('touchstart touchstart:active', e);
3244
+ }
3245
+
3246
+ function appTouchMoveActive(e) {
3247
+ emitAppTouchEvent('touchmove touchmove:active', e);
3248
+ }
3249
+
3250
+ function appTouchEndActive(e) {
3251
+ emitAppTouchEvent('touchend touchend:active', e);
3252
+ }
3253
+
3254
+ function appTouchStartPassive(e) {
3255
+ emitAppTouchEvent('touchstart:passive', e);
3256
+ }
3257
+
3258
+ function appTouchMovePassive(e) {
3259
+ emitAppTouchEvent('touchmove:passive', e);
3260
+ }
3261
+
3262
+ function appTouchEndPassive(e) {
3263
+ emitAppTouchEvent('touchend:passive', e);
3264
+ }
3265
+
3266
+ const passiveListener = support$1.passiveListener ? {passive: true} : false;
3267
+ const passiveListenerCapture = support$1.passiveListener ? {passive: true, capture: true} : true;
3268
+ const activeListener = support$1.passiveListener ? {passive: false} : false;
3269
+ const activeListenerCapture = support$1.passiveListener ? {passive: false, capture: true} : true;
3270
+
3271
+ // document touch �¼� ���ݸ� app.on
3272
+ if (support$1.passiveListener) {
3273
+ document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListenerCapture);
3274
+ document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
3275
+ document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
3276
+
3277
+ document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListenerCapture);
3278
+ document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
3279
+ document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
3280
+ } else {
3281
+ document.addEventListener(
3282
+ app.touchEvents.start,
3283
+ e => {
3284
+ appTouchStartActive(e);
3285
+ appTouchStartPassive(e);
3286
+ },
3287
+ true
3288
+ );
3289
+ document.addEventListener(
3290
+ app.touchEvents.move,
3291
+ e => {
3292
+ appTouchMoveActive(e);
3293
+ appTouchMovePassive(e);
3294
+ },
3295
+ false
3296
+ );
3297
+ document.addEventListener(
3298
+ app.touchEvents.end,
3299
+ e => {
3300
+ appTouchEndActive(e);
3301
+ appTouchEndPassive(e);
3302
+ },
3303
+ false
3304
+ );
3305
+ }
3306
+
3307
+ if (support$1.touch) {
3308
+ app.on('click', handleClick);
3309
+ app.on('touchstart', handleTouchStart);
3310
+ app.on('touchmove', handleTouchMove);
3311
+ app.on('touchend', handleTouchEnd);
3312
+ document.addEventListener('touchcancel', handleTouchCancel, {passive: true});
3313
+ } else if (params.activeState) {
3314
+ app.on('touchstart', handleMouseDown);
3315
+ app.on('touchmove', handleMouseMove);
3316
+ app.on('touchend', handleMouseUp);
3317
+ document.addEventListener('pointercancel', handleMouseUp, {passive: true});
3318
+ }
3319
+
3320
+ document.addEventListener('contextmenu', e => {
3321
+ if (
3322
+ params.disableContextMenu &&
3323
+ (device$1.ios ||
3324
+ device$1.android ||
3325
+ device$1.cordova ||
3326
+ (window.Capacitor && window.Capacitor.isNative))
3327
+ ) {
3328
+ e.preventDefault();
3329
+ }
3330
+ if (useRipple) {
3331
+ if (activableElement) removeActive();
3332
+ rippleTouchEnd();
3333
+ }
3334
+ });
3335
+ }
3336
+
3337
+ const Touch = {
3338
+ name: 'touch',
3339
+ params: {
3340
+ touch: {
3341
+ // Clicks
3342
+ touchClicksDistanceThreshold: 5,
3343
+ // ContextMenu
3344
+ disableContextMenu: false,
3345
+ // Tap Hold
3346
+ tapHold: false,
3347
+ tapHoldDelay: 750,
3348
+ tapHoldPreventClicks: true,
3349
+ // Active State
3350
+ activeState: true,
3351
+ activeStateElements:
3352
+ 'a, button, label, span, .actions-button, .stepper-button, .stepper-button-plus, .stepper-button-minus, .card-expandable, .link, .item-link, .accordion-item-toggle',
3353
+ activeStateOnMouseMove: false,
3354
+ mdTouchRipple: true,
3355
+ iosTouchRipple: false,
3356
+ touchRippleElements:
3357
+ '.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',
3358
+ touchRippleInsetElements:
3359
+ '.ripple-inset, .icon-only, .searchbar-disable-button, .input-clear-button, .notification-close-button, .md .navbar .link.back',
3360
+ },
3361
+ },
3362
+
3363
+ create() {
3364
+ const app = this;
3365
+ extend$1(app, {
3366
+ touchEvents: {
3367
+ start: support$1.touch ? 'touchstart' : support$1.pointerEvents ? 'pointerdown' : 'mousedown',
3368
+ move: support$1.touch ? 'touchmove' : support$1.pointerEvents ? 'pointermove' : 'mousemove',
3369
+ end: support$1.touch ? 'touchend' : support$1.pointerEvents ? 'pointerup' : 'mouseup',
3370
+ },
3371
+ });
3372
+ },
3373
+ on: {
3374
+ init: initTouch,
3375
+ },
3376
+ };
3377
+
2257
3378
  const SW = {
2258
3379
  registrations: [],
2259
3380
  register(path, scope) {
@@ -2525,7 +3646,7 @@ class App extends Module {
2525
3646
  const app = this;
2526
3647
  if (!app.colorsStyleEl) {
2527
3648
  app.colorsStyleEl = document.createElement('style');
2528
- document.head.appendChild(app.colorsStyleEl);
3649
+ document.head.prepend(app.colorsStyleEl);
2529
3650
  }
2530
3651
 
2531
3652
  app.colorsStyleEl.textContent = colorThemeCSSStyles(app.colors);
@@ -2618,8 +3739,8 @@ class App extends Module {
2618
3739
  const app = this;
2619
3740
  const html = document.querySelector('html');
2620
3741
  if (app.mq.dark && app.mq.light) {
2621
- app.mq.dark.addListener(app.colorSchemeListener);
2622
- app.mq.light.addListener(app.colorSchemeListener);
3742
+ app.mq.dark.addEventListener('change', app.colorSchemeListener);
3743
+ app.mq.light.addEventListener('change', app.colorSchemeListener);
2623
3744
  }
2624
3745
  if (app.mq.dark && app.mq.dark.matches) {
2625
3746
  html.classList.add('dark');
@@ -2636,8 +3757,8 @@ class App extends Module {
2636
3757
  if (!window.matchMedia) return;
2637
3758
 
2638
3759
  const app = this;
2639
- if (app.mq.dark) app.mq.dark.removeListener(app.colorSchemeListener);
2640
- if (app.mq.light) app.mq.light.removeListener(app.colorSchemeListener);
3760
+ if (app.mq.dark) app.mq.dark.removeEventListener('change', app.colorSchemeListener);
3761
+ if (app.mq.light) app.mq.light.removeEventListener('change', app.colorSchemeListener);
2641
3762
  }
2642
3763
 
2643
3764
  setDarkMode(mode) {
@@ -2853,6 +3974,7 @@ App.utils = Utils;
2853
3974
  App.use([
2854
3975
  Resize, // 控制屏幕大小
2855
3976
  Click, // 触发UI组件的点击(Click 或 Touch)事件
3977
+ Touch, // 触发app.on(Touch事件)
2856
3978
  SW$1, // ServiceWorker
2857
3979
 
2858
3980
  //INSTALL_COMPONENTS