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