vanspod 0.1.2 → 0.2.0

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,235 +1,310 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.connectionMascotScript = exports.connectionMascotStyles = exports.connectionMascot = void 0;
4
+ exports.patrolKeyframes = patrolKeyframes;
5
+ exports.fittedPatrol = fittedPatrol;
4
6
  /** Keep the original brand artwork; animate its layers in the browser. */
5
- exports.connectionMascot = `<div class="connection-mascot">
6
- <div class="mascot-traveler">
7
- <div class="mascot-arrival">
8
- <button type="button" class="mascot-play" aria-label="和法鬥超人打招呼" title="和法鬥超人打招呼">
9
- <span class="mascot-idle">
10
- <span class="mascot-facing">
11
- <svg class="mascot-art" viewBox="0 0 1024 1024" aria-hidden="true" focusable="false">
12
- <defs>
13
- <clipPath id="mascot-arm-clip"><path d="M85 320H220L235 400L222 462L241 508L254 530L207 589L149 522L104 451L85 410Z"/></clipPath>
14
- <mask id="mascot-arm-mask"><rect width="1024" height="1024" fill="white"/><path d="M85 320H220L235 400L222 462L241 508L254 530L207 589L149 522L104 451L85 410Z" fill="black"/></mask>
15
- <clipPath id="mascot-left-foot-clip"><rect x="235" y="915" width="175" height="100"/></clipPath>
16
- <clipPath id="mascot-right-foot-clip"><rect x="490" y="927" width="185" height="88"/></clipPath>
17
- <clipPath id="mascot-logo-clip"><rect x="283" y="612" width="315" height="105"/></clipPath>
18
- <filter id="mascot-logo-alpha" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB">
19
- <feColorMatrix in="SourceGraphic" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 32 -32 0 0.6" result="lettering"/>
20
- <feColorMatrix in="SourceGraphic" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 -16 0 0 3.5" result="outline"/>
21
- <feComposite in="lettering" in2="outline" operator="arithmetic" k2="1" k3="1" result="ink"/>
22
- <feComposite in="SourceGraphic" in2="ink" operator="in"/>
23
- </filter>
24
- <filter id="mascot-logo-erase" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB">
25
- <feColorMatrix in="SourceGraphic" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 -32 0 0.6" result="lettering"/>
26
- <feColorMatrix in="SourceGraphic" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -16 0 0 3.5" result="outline"/>
27
- <feComposite in="lettering" in2="outline" operator="arithmetic" k2="1" k3="1"/>
28
- </filter>
29
- <linearGradient id="mascot-shirt-fill"><stop stop-color="#3d6878"/><stop offset="0.5" stop-color="#3a677a"/><stop offset="1" stop-color="#356270"/></linearGradient>
30
- <mask id="mascot-detail-mask"><rect width="1024" height="1024" fill="white"/><rect x="235" y="915" width="175" height="100" fill="black"/><rect x="490" y="927" width="185" height="88" fill="black"/><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-logo-clip)" filter="url(#mascot-logo-erase)"/></mask>
31
- <clipPath id="mascot-body-clip"><path d="M0 0H1024V490H700L670 534L739 601L768 638L765 681L740 718L702 749L691 778L668 803L646 813V1024H0Z"/></clipPath>
32
- <clipPath id="mascot-cape-clip"><path d="M688 490L1024 490V850H640V789L670 760L704 730L744 679L744 620L668 545Z"/></clipPath>
33
- <clipPath id="mascot-eyes-clip"><ellipse cx="334" cy="359" rx="52" ry="43"/><ellipse cx="535" cy="369" rx="53" ry="43"/></clipPath>
34
- </defs>
35
- <g class="mascot-cape"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-cape-clip)"/></g>
36
- <rect x="283" y="612" width="315" height="105" fill="url(#mascot-shirt-fill)"/>
37
- <g mask="url(#mascot-detail-mask)"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-body-clip)" mask="url(#mascot-arm-mask)"/></g>
38
- <g class="mascot-foot mascot-left-foot"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-left-foot-clip)"/></g>
39
- <g class="mascot-foot mascot-right-foot"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-right-foot-clip)"/></g>
40
- <g class="mascot-logo"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-logo-clip)" filter="url(#mascot-logo-alpha)"/></g>
41
- <g class="mascot-arm"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-arm-clip)"/></g>
42
- <g class="mascot-blink" clip-path="url(#mascot-eyes-clip)"><image href="/fadou-superhero-blink.png" x="11" y="4" width="1024" height="1024"/></g>
43
- </svg>
44
- </span>
45
- </span>
46
- </button>
47
- </div>
48
- </div>
49
- <button type="button" class="mascot-pause" aria-label="暫停法鬥超人動畫" aria-pressed="false" title="暫停動畫"><svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M8 5v14M16 5v14" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
7
+ exports.connectionMascot = `<div class="connection-mascot">
8
+ <div class="mascot-traveler">
9
+ <div class="mascot-arrival">
10
+ <button type="button" class="mascot-play" aria-label="和法鬥超人打招呼" title="和法鬥超人打招呼">
11
+ <span class="mascot-idle">
12
+ <span class="mascot-facing">
13
+ <svg class="mascot-art" viewBox="0 0 1024 1024" aria-hidden="true" focusable="false">
14
+ <defs>
15
+ <clipPath id="mascot-arm-clip"><path d="M85 320H220L235 400L222 462L241 508L254 530L207 589L149 522L104 451L85 410Z"/></clipPath>
16
+ <mask id="mascot-arm-mask"><rect width="1024" height="1024" fill="white"/><path d="M85 320H220L235 400L222 462L241 508L254 530L207 589L149 522L104 451L85 410Z" fill="black"/></mask>
17
+ <clipPath id="mascot-left-foot-clip"><rect x="235" y="915" width="175" height="100"/></clipPath>
18
+ <clipPath id="mascot-right-foot-clip"><rect x="490" y="927" width="185" height="88"/></clipPath>
19
+ <clipPath id="mascot-logo-clip"><rect x="283" y="612" width="315" height="105"/></clipPath>
20
+ <filter id="mascot-logo-alpha" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB">
21
+ <feColorMatrix in="SourceGraphic" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 32 -32 0 0.6" result="lettering"/>
22
+ <feColorMatrix in="SourceGraphic" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 -16 0 0 3.5" result="outline"/>
23
+ <feComposite in="lettering" in2="outline" operator="arithmetic" k2="1" k3="1" result="ink"/>
24
+ <feComposite in="SourceGraphic" in2="ink" operator="in"/>
25
+ </filter>
26
+ <filter id="mascot-logo-erase" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB">
27
+ <feColorMatrix in="SourceGraphic" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 -32 0 0.6" result="lettering"/>
28
+ <feColorMatrix in="SourceGraphic" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -16 0 0 3.5" result="outline"/>
29
+ <feComposite in="lettering" in2="outline" operator="arithmetic" k2="1" k3="1"/>
30
+ </filter>
31
+ <linearGradient id="mascot-shirt-fill"><stop stop-color="#3d6878"/><stop offset="0.5" stop-color="#3a677a"/><stop offset="1" stop-color="#356270"/></linearGradient>
32
+ <mask id="mascot-detail-mask"><rect width="1024" height="1024" fill="white"/><rect x="235" y="915" width="175" height="100" fill="black"/><rect x="490" y="927" width="185" height="88" fill="black"/><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-logo-clip)" filter="url(#mascot-logo-erase)"/></mask>
33
+ <clipPath id="mascot-body-clip"><path d="M0 0H1024V490H700L670 534L739 601L768 638L765 681L740 718L702 749L691 778L668 803L646 813V1024H0Z"/></clipPath>
34
+ <clipPath id="mascot-cape-clip"><path d="M688 490L1024 490V850H640V789L670 760L704 730L744 679L744 620L668 545Z"/></clipPath>
35
+ <clipPath id="mascot-eyes-clip"><ellipse cx="334" cy="359" rx="52" ry="43"/><ellipse cx="535" cy="369" rx="53" ry="43"/></clipPath>
36
+ </defs>
37
+ <g class="mascot-cape"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-cape-clip)"/></g>
38
+ <rect x="283" y="612" width="315" height="105" fill="url(#mascot-shirt-fill)"/>
39
+ <g mask="url(#mascot-detail-mask)"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-body-clip)" mask="url(#mascot-arm-mask)"/></g>
40
+ <g class="mascot-foot mascot-left-foot"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-left-foot-clip)"/></g>
41
+ <g class="mascot-foot mascot-right-foot"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-right-foot-clip)"/></g>
42
+ <g class="mascot-logo"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-logo-clip)" filter="url(#mascot-logo-alpha)"/></g>
43
+ <g class="mascot-arm"><image href="/fadou-superhero.png" width="1024" height="1024" clip-path="url(#mascot-arm-clip)"/></g>
44
+ <g class="mascot-blink" clip-path="url(#mascot-eyes-clip)"><image href="/fadou-superhero-blink.png" x="11" y="4" width="1024" height="1024"/></g>
45
+ </svg>
46
+ </span>
47
+ </span>
48
+ </button>
49
+ </div>
50
+ </div>
51
+ <button type="button" class="mascot-pause" aria-label="暫停法鬥超人動畫" aria-pressed="false" title="暫停動畫"><svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M8 5v14M16 5v14" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
50
52
  </div>`;
51
- // One lap: centre → left (6s), rest (6s), right (12s), rest (6s), centre (6s).
52
- // Both feet settle at each edge; no stepping in place during the rests.
53
- function footstepKeyframes(name, direction) {
54
- const frames = [];
55
- for (const [start, end] of [[0, 6], [12, 24], [30, 36]]) {
56
- for (let time = start; time <= end; time += 0.5) {
57
- const phase = (time - start) % 1;
58
- const angle = time === start || time === end ? 0 : (phase === 0.5 ? -5 : 5) * direction;
59
- frames.push(`${time / 36 * 100}% { transform: translateY(${angle < 0 ? -6 : 0}px) rotate(${angle}deg); }`);
53
+ /**
54
+ * One lap: centre → left, rest (6s), right, rest (6s), centre. At scale 1 the
55
+ * walks take 6s, 12s and 6s (a 36s lap) across the 教室設定 card; a wider lane
56
+ * passes a larger scale so the walks stretch while the pace, the step cadence
57
+ * and the rests stay the same. Both feet settle at each edge; no stepping in
58
+ * place during the rests. Self-contained: the inspector page injects its
59
+ * source to refit the lap to the lane's width.
60
+ */
61
+ function patrolKeyframes(suffix, scale) {
62
+ const reachLeft = 6 * scale, leaveLeft = reachLeft + 6;
63
+ const reachRight = leaveLeft + 12 * scale, leaveRight = reachRight + 6;
64
+ const lap = leaveRight + 6 * scale;
65
+ // 152px = the traveler's 136px width plus its 8px inset on each side.
66
+ const at = (time) => `${Number((time / lap * 100).toFixed(6))}%`;
67
+ const feet = (name, direction) => {
68
+ const frames = [];
69
+ for (const [start, end] of [[0, reachLeft], [leaveLeft, reachRight], [leaveRight, lap]]) {
70
+ const steps = Math.floor((end - start) / 0.5 + 0.001);
71
+ for (let step = 0; step <= steps; step++) {
72
+ const time = start + step * 0.5;
73
+ const edge = step === 0 || end - time < 0.001;
74
+ const angle = edge ? 0 : (step % 2 === 1 ? -5 : 5) * direction;
75
+ frames.push(`${at(time)} { transform: translateY(${angle < 0 ? -6 : 0}px) rotate(${angle}deg); }`);
76
+ }
77
+ if (end - (start + steps * 0.5) >= 0.001)
78
+ frames.push(`${at(end)} { transform: translateY(0px) rotate(0deg); }`);
60
79
  }
61
- }
62
- return `@keyframes ${name} { ${frames.join("\n")} }`;
80
+ return `@keyframes ${name}${suffix} { ${frames.join("\n")} }`;
81
+ };
82
+ const css = `@keyframes mascot-walk${suffix} {
83
+ 0%, 100% { transform: translateX(max(0px, calc((100cqw - 152px) / 2))); }
84
+ ${at(reachLeft)}, ${at(leaveLeft)} { transform: translateX(0); }
85
+ ${at(reachRight)}, ${at(leaveRight)} { transform: translateX(max(0px, calc(100cqw - 152px))); }
86
+ }
87
+ @keyframes mascot-turn${suffix} {
88
+ 0% { transform: scaleX(1); }
89
+ ${at(reachLeft)} { transform: scaleX(-1); }
90
+ ${at(reachRight)}, 100% { transform: scaleX(1); }
91
+ }
92
+ ${feet("mascot-left-step", 1)}
93
+ ${feet("mascot-right-step", -1)}`;
94
+ return { lap, marks: [0, reachLeft, leaveLeft, reachRight, leaveRight, lap], css };
63
95
  }
64
- exports.connectionMascotStyles = `
65
- .settings-card[data-setting="連線"]:has(.connection-mascot) { row-gap: 0; }
66
- .settings-card[data-setting="連線"]:has(.connection-mascot) .settings-content { padding-top: 16px; }
67
- .settings-card[data-setting="連線"]:has(.connection-mascot) .connection-feedback { order: -1; }
68
- .connection-mascot { position: relative; flex: 1 0 144px; width: 100%; min-height: 144px; overflow: hidden; container-type: inline-size; }
69
- /* Compensate for the PNG's transparent space below the soles. */
70
- .mascot-traveler { position: absolute; bottom: -4px; left: 8px; width: 136px; max-width: calc(100% - 16px); animation: mascot-walk 36s linear 780ms infinite both; }
71
- .mascot-facing { display: block; animation: mascot-turn 36s linear 780ms infinite; }
72
- .mascot-logo { transform-origin: 440.5px 664.5px; animation: mascot-turn 36s linear 780ms infinite; }
73
- .mascot-left-foot { transform-origin: 322px 915px; animation: mascot-left-step 36s linear 780ms infinite; }
74
- .mascot-right-foot { transform-origin: 580px 927px; animation: mascot-right-step 36s linear 780ms infinite; }
75
- .mascot-waiting { flex-basis: 164px; min-height: 164px; padding: 12px 148px 32px 0; }
76
- .mascot-waiting .mascot-traveler { left: auto; right: 8px; transform: none; }
77
- .mascot-waiting .mascot-traveler, .mascot-waiting .mascot-facing, .mascot-waiting .mascot-logo, .mascot-waiting .mascot-foot, .mascot-waiting .mascot-arrival { animation: none; }
78
- .mascot-speech { position: relative; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--input); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
79
- .mascot-speech:has(> .connection-feedback:empty) { display: none; }
80
- .mascot-speech::after { content: ''; position: absolute; right: -7px; top: 28px; width: 12px; height: 12px; background: var(--input); border-right: 1px solid var(--line); border-top: 1px solid var(--line); transform: rotate(45deg); }
81
- .mascot-quote { color: var(--text); }
82
- .mascot-speech .connection-error, .mascot-speech .connection-message { padding: 0; margin-top: 6px; border-radius: 0; background: transparent; color: var(--muted); font-size: 11px; }
83
- .mascot-speech .connection-error svg, .mascot-speech .connection-message svg { display: none; }
84
- .mascot-speaking .connection-message { margin-top: 0; color: var(--text); font-size: 12px; }
85
- .mascot-speaking { flex-basis: 144px; min-height: 144px; padding-bottom: 0; }
86
- main button.mascot-speech-close { margin-top: 6px; padding: 4px 0; min-height: 24px; background: transparent; color: var(--muted); border: 0; border-radius: 4px; font-size: 11px; }
87
- main button.mascot-speech-close:hover { color: var(--text); }
88
- main button.mascot-pause { position: absolute; right: 0; bottom: 0; display: grid; place-items: center; min-height: 24px; width: 24px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); opacity: 0.65; }
89
- main button.mascot-pause:hover, main button.mascot-pause:focus-visible { opacity: 1; background: var(--input); }
90
- .connection-mascot:hover .mascot-traveler, .connection-mascot:hover .mascot-facing, .connection-mascot:hover .mascot-logo, .connection-mascot:hover .mascot-foot,
91
- .connection-mascot:focus-within .mascot-traveler, .connection-mascot:focus-within .mascot-facing, .connection-mascot:focus-within .mascot-logo, .connection-mascot:focus-within .mascot-foot,
92
- .connection-mascot[data-paused] * { animation-play-state: paused; }
93
- .mascot-arrival { animation: mascot-arrive 780ms cubic-bezier(0.22, 1, 0.36, 1) both; transform-origin: center bottom; }
94
- main button.mascot-play { display: block; width: 136px; max-width: 100%; min-height: 0; padding: 0; border: 0; border-radius: 16px; background: transparent; color: inherit; touch-action: manipulation; }
95
- .mascot-play:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
96
- .mascot-play:active { transform: scale(0.97); }
97
- .mascot-idle { display: block; user-select: none; transform-origin: 50% 97%; animation: mascot-breathe 3200ms ease-in-out 780ms infinite; }
98
- .mascot-art { display: block; width: 100%; height: auto; overflow: visible; }
99
- .mascot-cape { transform-origin: 680px 530px; animation: mascot-cape 2400ms ease-in-out infinite; }
100
- .mascot-arm { transform-origin: 235px 540px; }
101
- .mascot-blink { opacity: 0; animation: mascot-blink 7400ms steps(1, end) infinite; }
102
- @keyframes mascot-arrive {
103
- 0% { opacity: 0; transform: translateY(16px) scale(0.9); }
104
- 35% { opacity: 1; transform: translateY(-7px) scale(1.02); }
105
- 60% { transform: translateY(2px) scale(0.99); }
106
- 80% { transform: translateY(-2px) scale(1); }
107
- 100% { opacity: 1; transform: translateY(0) scale(1); }
108
- }
109
- @keyframes mascot-breathe {
110
- 0%, 100% { transform: translateY(0) scale(1); }
111
- 50% { transform: scale(1.012, 1.018); }
112
- }
113
- @keyframes mascot-cape {
114
- 0%, 100% { transform: rotate(0deg) scale(1); }
115
- 50% { transform: rotate(-1.5deg) scale(1.012, 0.99); }
116
- }
117
- @keyframes mascot-blink {
118
- 0%, 42%, 85%, 90%, 100% { opacity: 0; }
119
- 40%, 83%, 88% { opacity: 1; }
120
- }
121
- @keyframes mascot-walk {
122
- 0%, 100% { transform: translateX(max(0px, calc((100cqw - 152px) / 2))); }
123
- 16.666667%, 33.333333% { transform: translateX(0); }
124
- 66.666667%, 83.333333% { transform: translateX(max(0px, calc(100cqw - 152px))); }
125
- }
126
- @keyframes mascot-turn {
127
- 0%, 16.666667% { transform: scaleX(1); }
128
- 18%, 66.666667% { transform: scaleX(-1); }
129
- 68%, 100% { transform: scaleX(1); }
130
- }
131
- ${footstepKeyframes("mascot-left-step", 1)}
132
- ${footstepKeyframes("mascot-right-step", -1)}
133
- @media (prefers-reduced-motion: reduce) {
134
- .mascot-arrival, .mascot-idle, .mascot-cape, .mascot-blink, .mascot-traveler, .mascot-facing, .mascot-logo, .mascot-foot { animation: none; }
135
- .mascot-traveler { left: 50%; transform: translateX(-50%); }
136
- .mascot-waiting .mascot-traveler { left: auto; transform: none; }
137
- main button.mascot-pause { display: none; }
138
- .mascot-play:active { transform: none; }
139
- }
140
- @media (prefers-contrast: more) { .mascot-play:focus-visible { outline-width: 3px; } }
96
+ const BASE_PATROL = patrolKeyframes("", 1);
97
+ /** The 教室設定 card's lane is 356px wide: the base lap walks 204px each way. */
98
+ const BASE_LANE = 356;
99
+ const TRAVELER_SPAN = 152;
100
+ exports.connectionMascotStyles = `
101
+ .settings-card[data-setting="連線"]:has(.connection-mascot) { row-gap: 0; }
102
+ .settings-card[data-setting="連線"]:has(.connection-mascot) .settings-content { padding-top: 16px; }
103
+ .settings-card[data-setting="連線"]:has(.connection-mascot) .connection-feedback { order: -1; }
104
+ .connection-mascot { position: relative; flex: 1 0 144px; width: 100%; min-height: 144px; overflow: hidden; container-type: inline-size; }
105
+ /* Compensate for the PNG's transparent space below the soles. */
106
+ .mascot-traveler { position: absolute; bottom: -4px; left: 8px; width: 136px; max-width: calc(100% - 16px); animation: mascot-walk ${BASE_PATROL.lap}s linear 780ms infinite both; }
107
+ /* 走到端點直接換邊,不播翻面過渡。 */
108
+ .mascot-facing { display: block; animation: mascot-turn ${BASE_PATROL.lap}s step-end 780ms infinite; }
109
+ .mascot-logo { transform-origin: 440.5px 664.5px; animation: mascot-turn ${BASE_PATROL.lap}s step-end 780ms infinite; }
110
+ .mascot-left-foot { transform-origin: 322px 915px; animation: mascot-left-step ${BASE_PATROL.lap}s linear 780ms infinite; }
111
+ .mascot-right-foot { transform-origin: 580px 927px; animation: mascot-right-step ${BASE_PATROL.lap}s linear 780ms infinite; }
112
+ .mascot-waiting { flex-basis: 164px; min-height: 164px; padding: 12px 148px 32px 0; }
113
+ .mascot-waiting .mascot-traveler { left: auto; right: 8px; transform: none; }
114
+ .mascot-waiting .mascot-traveler, .mascot-waiting .mascot-facing, .mascot-waiting .mascot-logo, .mascot-waiting .mascot-foot, .mascot-waiting .mascot-arrival { animation: none; }
115
+ .mascot-speech { position: relative; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--input); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
116
+ .mascot-speech:has(> .connection-feedback:empty) { display: none; }
117
+ .mascot-speech::after { content: ''; position: absolute; right: -7px; top: 28px; width: 12px; height: 12px; background: var(--input); border-right: 1px solid var(--line); border-top: 1px solid var(--line); transform: rotate(45deg); }
118
+ .mascot-quote { color: var(--text); }
119
+ .mascot-speech .connection-error, .mascot-speech .connection-message { padding: 0; margin-top: 6px; border-radius: 0; background: transparent; color: var(--muted); font-size: 11px; }
120
+ .mascot-speech .connection-error svg, .mascot-speech .connection-message svg { display: none; }
121
+ .mascot-speaking .connection-message { margin-top: 0; color: var(--text); font-size: 12px; }
122
+ .mascot-speaking { flex-basis: 144px; min-height: 144px; padding-bottom: 0; }
123
+ main button.mascot-speech-close { margin-top: 6px; padding: 4px 0; min-height: 24px; background: transparent; color: var(--muted); border: 0; border-radius: 4px; font-size: 11px; }
124
+ main button.mascot-speech-close:hover { color: var(--text); }
125
+ main button.mascot-pause { position: absolute; right: 0; bottom: 0; display: grid; place-items: center; min-height: 24px; width: 24px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); opacity: 0.65; }
126
+ main button.mascot-pause:hover, main button.mascot-pause:focus-visible { opacity: 1; background: var(--input); }
127
+ .connection-mascot:hover .mascot-traveler, .connection-mascot:hover .mascot-facing, .connection-mascot:hover .mascot-logo, .connection-mascot:hover .mascot-foot,
128
+ .connection-mascot:focus-within .mascot-traveler, .connection-mascot:focus-within .mascot-facing, .connection-mascot:focus-within .mascot-logo, .connection-mascot:focus-within .mascot-foot,
129
+ .connection-mascot[data-paused] * { animation-play-state: paused; }
130
+ .mascot-arrival { animation: mascot-arrive 780ms cubic-bezier(0.22, 1, 0.36, 1) both; transform-origin: center bottom; }
131
+ main button.mascot-play { display: block; width: 136px; max-width: 100%; min-height: 0; padding: 0; border: 0; border-radius: 16px; background: transparent; color: inherit; touch-action: manipulation; }
132
+ .mascot-play:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
133
+ .mascot-play:active { transform: scale(0.97); }
134
+ .mascot-idle { display: block; user-select: none; transform-origin: 50% 97%; animation: mascot-breathe 3200ms ease-in-out 780ms infinite; }
135
+ .mascot-art { display: block; width: 100%; height: auto; overflow: visible; }
136
+ .mascot-cape { transform-origin: 680px 530px; animation: mascot-cape 2400ms ease-in-out infinite; }
137
+ .mascot-arm { transform-origin: 235px 540px; }
138
+ .mascot-blink { opacity: 0; animation: mascot-blink 7400ms steps(1, end) infinite; }
139
+ @keyframes mascot-arrive {
140
+ 0% { opacity: 0; transform: translateY(16px) scale(0.9); }
141
+ 35% { opacity: 1; transform: translateY(-7px) scale(1.02); }
142
+ 60% { transform: translateY(2px) scale(0.99); }
143
+ 80% { transform: translateY(-2px) scale(1); }
144
+ 100% { opacity: 1; transform: translateY(0) scale(1); }
145
+ }
146
+ @keyframes mascot-breathe {
147
+ 0%, 100% { transform: translateY(0) scale(1); }
148
+ 50% { transform: scale(1.012, 1.018); }
149
+ }
150
+ @keyframes mascot-cape {
151
+ 0%, 100% { transform: rotate(0deg) scale(1); }
152
+ 50% { transform: rotate(-1.5deg) scale(1.012, 0.99); }
153
+ }
154
+ @keyframes mascot-blink {
155
+ 0%, 42%, 85%, 90%, 100% { opacity: 0; }
156
+ 40%, 83%, 88% { opacity: 1; }
157
+ }
158
+ ${BASE_PATROL.css}
159
+ @media (prefers-reduced-motion: reduce) {
160
+ .mascot-arrival, .mascot-idle, .mascot-cape, .mascot-blink, .mascot-traveler, .mascot-facing, .mascot-logo, .mascot-foot { animation: none; }
161
+ .mascot-traveler { left: 50%; transform: translateX(-50%); }
162
+ .mascot-waiting .mascot-traveler { left: auto; transform: none; }
163
+ main button.mascot-pause { display: none; }
164
+ .mascot-play:active { transform: none; }
165
+ }
166
+ @media (prefers-contrast: more) { .mascot-play:focus-visible { outline-width: 3px; } }
141
167
  `;
142
- exports.connectionMascotScript = `
143
- var mascotSpeechDismissed = false;
144
- function updateCopyFeedback(updated) {
145
- var card = document.querySelector('[data-setting="連線"]');
146
- var nextCard = updated.querySelector('[data-setting="連線"]');
147
- var stage = card?.querySelector('.connection-mascot') || document.querySelector('.classroom-update .connection-mascot');
148
- var nextStage = nextCard?.querySelector('.connection-mascot');
149
- if (!stage || !nextStage || !nextCard.querySelector('.connection-copy')) return false;
150
- var speech = nextStage.querySelector('.mascot-speech');
151
- var feedback = nextCard.querySelector('.settings-content > .connection-feedback');
152
- if (!speech && !feedback) return false;
153
- card.querySelector('.settings-content > .connection-feedback')?.remove();
154
- stage.querySelector('.mascot-speech')?.remove();
155
- if (nextStage.classList.contains('mascot-speaking')) {
156
- if (!speech) return false;
157
- mascotSpeechDismissed = false;
158
- stage.classList.add('mascot-waiting', 'mascot-speaking');
159
- stage.prepend(speech);
160
- } else {
161
- if (stage.classList.contains('mascot-speaking')) hideMascotSpeech(stage);
162
- card.querySelector('.settings-content').append(feedback);
163
- }
164
- return true;
165
- }
166
- function hideMascotSpeech(stage) {
167
- stage.querySelector('.mascot-speech')?.remove();
168
- stage.classList.remove('mascot-waiting', 'mascot-speaking');
169
- stage.getAnimations({ subtree: true }).forEach(function (animation) {
170
- if (animation.animationName === 'mascot-arrive') animation.currentTime = 780;
171
- if (['mascot-walk', 'mascot-turn', 'mascot-left-step', 'mascot-right-step'].includes(animation.animationName)) animation.currentTime = 27780;
172
- });
173
- }
174
- function mascotAnimationState() {
175
- var mascot = document.querySelector('.connection-mascot');
176
- return { speechDismissed: mascotSpeechDismissed, paused: mascot?.hasAttribute('data-paused') || false, animations: mascot ? mascot.getAnimations({ subtree: true }).filter(function (animation) {
177
- return typeof animation.animationName === 'string';
178
- }).map(function (animation) {
179
- return { name: animation.animationName, time: animation.currentTime };
180
- }) : [] };
181
- }
182
- function restoreMascotAnimationState(state) {
183
- var mascot = document.querySelector('.connection-mascot');
184
- if (!mascot) return;
185
- mascotSpeechDismissed = Boolean(state.speechDismissed);
186
- if (mascotSpeechDismissed && mascot.classList.contains('mascot-speaking')) hideMascotSpeech(mascot);
187
- if (state.paused) {
188
- mascot.setAttribute('data-paused', '');
189
- var pause = mascot.querySelector('.mascot-pause');
190
- pause.setAttribute('aria-pressed', 'true');
191
- pause.setAttribute('aria-label', '繼續法鬥超人動畫');
192
- pause.title = '繼續動畫';
193
- }
194
- mascot.getAnimations({ subtree: true }).forEach(function (animation) {
195
- var saved = (state.animations || []).find(function (value) { return value.name === animation.animationName; });
196
- if (saved && saved.time !== null) animation.currentTime = saved.time;
197
- });
198
- }
199
- document.addEventListener('click', function (event) {
200
- var close = event.target.closest?.('.mascot-speech-close');
201
- if (close && !close.disabled) {
202
- var speaking = close.closest('.connection-mascot');
203
- mascotSpeechDismissed = true;
204
- hideMascotSpeech(speaking);
205
- document.querySelector('[data-setting="連線"] .connection-copy')?.focus({ preventScroll: true });
206
- return;
207
- }
208
- var pause = event.target.closest?.('.mascot-pause');
209
- if (pause && !pause.disabled) {
210
- var stage = pause.closest('.connection-mascot');
211
- var paused = stage.toggleAttribute('data-paused');
212
- pause.setAttribute('aria-pressed', String(paused));
213
- pause.setAttribute('aria-label', paused ? '繼續法鬥超人動畫' : '暫停法鬥超人動畫');
214
- pause.title = paused ? '繼續動畫' : '暫停動畫';
215
- return;
216
- }
217
- var button = event.target.closest?.('.mascot-play');
218
- if (!button || button.disabled) return;
219
- var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
220
- var arm = button.querySelector('.mascot-arm');
221
- arm.getAnimations().forEach(function (animation) { animation.cancel(); });
222
- if (!reduced) arm.animate([
223
- { transform: 'rotate(0deg)' }, { transform: 'rotate(-8deg)', offset: 0.25 },
224
- { transform: 'rotate(5deg)', offset: 0.5 }, { transform: 'rotate(-6deg)', offset: 0.75 },
225
- { transform: 'rotate(0deg)' }
226
- ], { duration: 800, easing: 'ease-in-out' });
227
- button.getAnimations().forEach(function (animation) { animation.cancel(); });
228
- button.animate(reduced ? [{ opacity: 0.65 }, { opacity: 1 }] : [
229
- { transform: 'translateY(0) rotate(0deg)' },
230
- { transform: 'translateY(-8px) rotate(-4deg)', offset: 0.35 },
231
- { transform: 'translateY(-3px) rotate(3deg)', offset: 0.65 },
232
- { transform: 'translateY(0) rotate(0deg)' }
233
- ], { duration: reduced ? 180 : 600, easing: 'ease-out' });
234
- });
168
+ exports.connectionMascotScript = `
169
+ var mascotSpeechDismissed = false;
170
+ function updateCopyFeedback(updated) {
171
+ var card = document.querySelector('[data-setting="連線"]');
172
+ var nextCard = updated.querySelector('[data-setting="連線"]');
173
+ var stage = card?.querySelector('.connection-mascot') || document.querySelector('.classroom-update .connection-mascot');
174
+ var nextStage = nextCard?.querySelector('.connection-mascot');
175
+ if (!stage || !nextStage || !nextCard.querySelector('.connection-copy')) return false;
176
+ var speech = nextStage.querySelector('.mascot-speech');
177
+ var feedback = nextCard.querySelector('.settings-content > .connection-feedback');
178
+ if (!speech && !feedback) return false;
179
+ card.querySelector('.settings-content > .connection-feedback')?.remove();
180
+ stage.querySelector('.mascot-speech')?.remove();
181
+ if (nextStage.classList.contains('mascot-speaking')) {
182
+ if (!speech) return false;
183
+ mascotSpeechDismissed = false;
184
+ stage.classList.add('mascot-waiting', 'mascot-speaking');
185
+ stage.prepend(speech);
186
+ } else {
187
+ if (stage.classList.contains('mascot-speaking')) hideMascotSpeech(stage);
188
+ card.querySelector('.settings-content').append(feedback);
189
+ }
190
+ return true;
191
+ }
192
+ function hideMascotSpeech(stage) {
193
+ stage.querySelector('.mascot-speech')?.remove();
194
+ stage.classList.remove('mascot-waiting', 'mascot-speaking');
195
+ stage.getAnimations({ subtree: true }).forEach(function (animation) {
196
+ if (animation.animationName === 'mascot-arrive') animation.currentTime = 780;
197
+ if (['mascot-walk', 'mascot-turn', 'mascot-left-step', 'mascot-right-step'].includes(animation.animationName)) animation.currentTime = 27780;
198
+ });
199
+ }
200
+ function mascotAnimationState() {
201
+ var mascot = document.querySelector('.connection-mascot');
202
+ return { speechDismissed: mascotSpeechDismissed, paused: mascot?.hasAttribute('data-paused') || false, animations: mascot ? mascot.getAnimations({ subtree: true }).filter(function (animation) {
203
+ return typeof animation.animationName === 'string';
204
+ }).map(function (animation) {
205
+ return { name: animation.animationName, time: animation.currentTime };
206
+ }) : [] };
207
+ }
208
+ function restoreMascotAnimationState(state) {
209
+ var mascot = document.querySelector('.connection-mascot');
210
+ if (!mascot) return;
211
+ mascotSpeechDismissed = Boolean(state.speechDismissed);
212
+ if (mascotSpeechDismissed && mascot.classList.contains('mascot-speaking')) hideMascotSpeech(mascot);
213
+ if (state.paused) {
214
+ mascot.setAttribute('data-paused', '');
215
+ var pause = mascot.querySelector('.mascot-pause');
216
+ pause.setAttribute('aria-pressed', 'true');
217
+ pause.setAttribute('aria-label', '繼續法鬥超人動畫');
218
+ pause.title = '繼續動畫';
219
+ }
220
+ mascot.getAnimations({ subtree: true }).forEach(function (animation) {
221
+ var saved = (state.animations || []).find(function (value) { return value.name === animation.animationName; });
222
+ if (saved && saved.time !== null) animation.currentTime = saved.time;
223
+ });
224
+ }
225
+ document.addEventListener('click', function (event) {
226
+ var close = event.target.closest?.('.mascot-speech-close');
227
+ if (close && !close.disabled) {
228
+ var speaking = close.closest('.connection-mascot');
229
+ mascotSpeechDismissed = true;
230
+ hideMascotSpeech(speaking);
231
+ document.querySelector('[data-setting="連線"] .connection-copy')?.focus({ preventScroll: true });
232
+ return;
233
+ }
234
+ var pause = event.target.closest?.('.mascot-pause');
235
+ if (pause && !pause.disabled) {
236
+ var stage = pause.closest('.connection-mascot');
237
+ var paused = stage.toggleAttribute('data-paused');
238
+ pause.setAttribute('aria-pressed', String(paused));
239
+ pause.setAttribute('aria-label', paused ? '繼續法鬥超人動畫' : '暫停法鬥超人動畫');
240
+ pause.title = paused ? '繼續動畫' : '暫停動畫';
241
+ return;
242
+ }
243
+ var button = event.target.closest?.('.mascot-play');
244
+ if (!button || button.disabled) return;
245
+ var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
246
+ var arm = button.querySelector('.mascot-arm');
247
+ arm.getAnimations().forEach(function (animation) { animation.cancel(); });
248
+ if (!reduced) arm.animate([
249
+ { transform: 'rotate(0deg)' }, { transform: 'rotate(-8deg)', offset: 0.25 },
250
+ { transform: 'rotate(5deg)', offset: 0.5 }, { transform: 'rotate(-6deg)', offset: 0.75 },
251
+ { transform: 'rotate(0deg)' }
252
+ ], { duration: 800, easing: 'ease-in-out' });
253
+ button.getAnimations().forEach(function (animation) { animation.cancel(); });
254
+ button.animate(reduced ? [{ opacity: 0.65 }, { opacity: 1 }] : [
255
+ { transform: 'translateY(0) rotate(0deg)' },
256
+ { transform: 'translateY(-8px) rotate(-4deg)', offset: 0.35 },
257
+ { transform: 'translateY(-3px) rotate(3deg)', offset: 0.65 },
258
+ { transform: 'translateY(0) rotate(0deg)' }
259
+ ], { duration: reduced ? 180 : 600, easing: 'ease-out' });
260
+ });
235
261
  `;
262
+ /**
263
+ * A lane of any width: the page script rewrites the "-fit" keyframes for the
264
+ * lane's measured width, so 法鬥超人 walks at the 教室設定 card's pace instead of
265
+ * covering a longer (or shorter) lane in the same lap. Use all three parts.
266
+ */
267
+ function fittedPatrol(scope) {
268
+ const lap = `var(--patrol-lap, ${BASE_PATROL.lap}s)`;
269
+ const styles = `
270
+ @media (prefers-reduced-motion: no-preference) {
271
+ ${scope} .mascot-traveler { animation-name: mascot-walk-fit; animation-duration: ${lap}; }
272
+ ${scope} .mascot-facing, ${scope} .mascot-logo { animation-name: mascot-turn-fit; animation-duration: ${lap}; }
273
+ ${scope} .mascot-left-foot { animation-name: mascot-left-step-fit; animation-duration: ${lap}; }
274
+ ${scope} .mascot-right-foot { animation-name: mascot-right-step-fit; animation-duration: ${lap}; }
275
+ }`;
276
+ const sheet = `<style id="mascot-patrol-fit">${patrolKeyframes("-fit", 1).css}</style>`;
277
+ const script = `(function () {
278
+ ${patrolKeyframes.toString()}
279
+ var stage = document.querySelector(${JSON.stringify(`${scope} .connection-mascot`)});
280
+ var sheet = document.getElementById("mascot-patrol-fit");
281
+ if (!stage || !sheet || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
282
+ var DELAY = 780;
283
+ var applied = Object.assign({ scale: 1 }, patrolKeyframes("-fit", 1));
284
+ // Same leg, same share of it: a refit keeps 法鬥超人 where he was instead of jumping.
285
+ function remap(time, from, to) {
286
+ var leg = 0;
287
+ while (leg < from.length - 2 && time >= from[leg + 1]) leg++;
288
+ var share = (time - from[leg]) / (from[leg + 1] - from[leg]);
289
+ return to[leg] + share * (to[leg + 1] - to[leg]);
290
+ }
291
+ function fit() {
292
+ var scale = Math.max(0.25, (stage.clientWidth - ${TRAVELER_SPAN}) / ${BASE_LANE - TRAVELER_SPAN});
293
+ if (Math.abs(scale - applied.scale) < 0.01) return;
294
+ var patrol = patrolKeyframes("-fit", scale);
295
+ var walking = stage.getAnimations({ subtree: true }).filter(function (animation) {
296
+ return /-fit$/.test(animation.animationName) && animation.currentTime >= DELAY;
297
+ }).map(function (animation) {
298
+ return { animation: animation, time: ((animation.currentTime - DELAY) / 1000) % applied.lap };
299
+ });
300
+ sheet.textContent = patrol.css;
301
+ stage.style.setProperty("--patrol-lap", patrol.lap + "s");
302
+ walking.forEach(function (entry) { entry.animation.currentTime = DELAY + remap(entry.time, applied.marks, patrol.marks) * 1000; });
303
+ applied = Object.assign({ scale: scale }, patrol);
304
+ }
305
+ fit();
306
+ var settle;
307
+ new ResizeObserver(function () { clearTimeout(settle); settle = setTimeout(fit, 150); }).observe(stage);
308
+ })();`;
309
+ return { styles, sheet, script };
310
+ }