@jetpack-desktop/client 0.1.2-rc.1 → 0.1.3-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -9
- package/dist/client.d.ts +48 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +395 -49
- package/dist/client.js.map +1 -1
- package/dist/control-bar.d.ts +56 -9
- package/dist/control-bar.d.ts.map +1 -1
- package/dist/control-bar.js +932 -75
- package/dist/control-bar.js.map +1 -1
- package/dist/download-url.d.ts +16 -0
- package/dist/download-url.d.ts.map +1 -0
- package/dist/download-url.js +18 -0
- package/dist/download-url.js.map +1 -0
- package/dist/i18n.d.ts +59 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +192 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/log-terminal.d.ts +8 -0
- package/dist/log-terminal.d.ts.map +1 -1
- package/dist/log-terminal.js +157 -17
- package/dist/log-terminal.js.map +1 -1
- package/dist/types.d.ts +109 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/wasm/jetpack_wasm.d.ts +18 -6
- package/wasm/jetpack_wasm.js +56 -23
- package/wasm/jetpack_wasm_bg.wasm +0 -0
- package/wasm/jetpack_wasm_bg.wasm.d.ts +9 -6
package/dist/control-bar.js
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
|
+
import { resolveJetPackDownloadUrl } from './download-url.js';
|
|
2
|
+
import { createI18n, resolveLanguage } from './i18n.js';
|
|
1
3
|
const DEFAULT_CONTROL_CENTER_URL = 'http://127.0.0.1:9470/#apps';
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
+
const CONTROL_BAR_LOCALES = {
|
|
5
|
+
en: {
|
|
6
|
+
defaultAppName: 'JetPack App',
|
|
7
|
+
statusConnecting: 'Connecting',
|
|
8
|
+
statusRunning: 'Running',
|
|
9
|
+
statusStopped: 'Stopped',
|
|
10
|
+
statusError: 'Error',
|
|
11
|
+
downloadJetpack: 'Download JetPack',
|
|
12
|
+
controlCenter: 'Control Center',
|
|
13
|
+
launch: 'Launch',
|
|
14
|
+
launching: 'Launching...',
|
|
15
|
+
stop: 'Stop',
|
|
16
|
+
stopping: 'Stopping...',
|
|
17
|
+
modalTitle: 'Stop Worker Process?',
|
|
18
|
+
modalMessage: 'Stopping this worker may discard unsaved work or active tasks. Do you want to continue?',
|
|
19
|
+
modalCancel: 'Cancel',
|
|
20
|
+
modalConfirm: 'Stop Worker',
|
|
21
|
+
poweredBy: 'Powered by JetPack',
|
|
22
|
+
installWaitText: 'Click "Download JetPack" above — waiting for JetPack to start...',
|
|
23
|
+
installDefaultMessage: 'To use {appName}, install and run the free JetPack app.',
|
|
24
|
+
installPosterAlt: '{appName} poster',
|
|
25
|
+
},
|
|
26
|
+
uk: {
|
|
27
|
+
defaultAppName: 'Застосунок JetPack',
|
|
28
|
+
statusConnecting: 'Підключення',
|
|
29
|
+
statusRunning: 'Працює',
|
|
30
|
+
statusStopped: 'Зупинено',
|
|
31
|
+
statusError: 'Помилка',
|
|
32
|
+
downloadJetpack: 'Завантажити JetPack',
|
|
33
|
+
controlCenter: 'Центр керування',
|
|
34
|
+
launch: 'Запустити',
|
|
35
|
+
launching: 'Запуск...',
|
|
36
|
+
stop: 'Зупинити',
|
|
37
|
+
stopping: 'Зупинення...',
|
|
38
|
+
modalTitle: 'Зупинити робочий процес?',
|
|
39
|
+
modalMessage: 'Зупинка цього процесу може призвести до втрати незбереженої роботи або активних завдань. Продовжити?',
|
|
40
|
+
modalCancel: 'Скасувати',
|
|
41
|
+
modalConfirm: 'Зупинити процес',
|
|
42
|
+
poweredBy: 'Працює на JetPack',
|
|
43
|
+
installWaitText: 'Натисніть «Завантажити JetPack» угорі — очікування запуску JetPack...',
|
|
44
|
+
installDefaultMessage: 'Щоб користуватися {appName}, встановіть і запустіть безкоштовний застосунок JetPack.',
|
|
45
|
+
installPosterAlt: 'Постер {appName}',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
4
48
|
const CONTROL_BAR_STYLES = `
|
|
5
49
|
:host {
|
|
6
50
|
all: initial;
|
|
@@ -74,6 +118,25 @@ const CONTROL_BAR_STYLES = `
|
|
|
74
118
|
text-overflow: ellipsis;
|
|
75
119
|
}
|
|
76
120
|
|
|
121
|
+
.jp-env-badge {
|
|
122
|
+
display: inline-flex;
|
|
123
|
+
align-items: center;
|
|
124
|
+
padding: 2px 7px;
|
|
125
|
+
border-radius: 999px;
|
|
126
|
+
font-size: 10px;
|
|
127
|
+
font-weight: 700;
|
|
128
|
+
letter-spacing: 0.06em;
|
|
129
|
+
text-transform: uppercase;
|
|
130
|
+
color: #f0b72f;
|
|
131
|
+
background: rgba(210, 153, 34, 0.16);
|
|
132
|
+
border: 1px solid rgba(210, 153, 34, 0.48);
|
|
133
|
+
flex-shrink: 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.jp-env-badge[hidden] {
|
|
137
|
+
display: none;
|
|
138
|
+
}
|
|
139
|
+
|
|
77
140
|
.jp-right {
|
|
78
141
|
display: flex;
|
|
79
142
|
align-items: center;
|
|
@@ -160,8 +223,7 @@ const CONTROL_BAR_STYLES = `
|
|
|
160
223
|
}
|
|
161
224
|
|
|
162
225
|
.jp-link-btn,
|
|
163
|
-
.jp-
|
|
164
|
-
.jp-stop-btn,
|
|
226
|
+
.jp-action-btn,
|
|
165
227
|
.jp-modal-btn {
|
|
166
228
|
appearance: none;
|
|
167
229
|
font: inherit;
|
|
@@ -191,37 +253,32 @@ const CONTROL_BAR_STYLES = `
|
|
|
191
253
|
}
|
|
192
254
|
|
|
193
255
|
.jp-download-btn,
|
|
194
|
-
.jp-
|
|
256
|
+
.jp-action-btn[data-jp-action="launch"] {
|
|
195
257
|
color: #ffffff;
|
|
196
258
|
background: #1f6feb;
|
|
197
259
|
border: 1px solid #388bfd;
|
|
198
260
|
}
|
|
199
261
|
|
|
200
262
|
.jp-download-btn:hover,
|
|
201
|
-
.jp-
|
|
263
|
+
.jp-action-btn[data-jp-action="launch"]:hover:not(:disabled) {
|
|
202
264
|
background: #388bfd;
|
|
203
265
|
border-color: #58a6ff;
|
|
204
266
|
color: #ffffff;
|
|
205
267
|
}
|
|
206
268
|
|
|
207
|
-
.jp-
|
|
208
|
-
opacity: 0.55;
|
|
209
|
-
cursor: not-allowed;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
.jp-stop-btn {
|
|
269
|
+
.jp-action-btn[data-jp-action="stop"] {
|
|
213
270
|
color: #ffdcd9;
|
|
214
271
|
background: rgba(248, 81, 73, 0.18);
|
|
215
272
|
border: 1px solid rgba(248, 81, 73, 0.5);
|
|
216
273
|
}
|
|
217
274
|
|
|
218
|
-
.jp-
|
|
275
|
+
.jp-action-btn[data-jp-action="stop"]:hover:not(:disabled) {
|
|
219
276
|
background: rgba(248, 81, 73, 0.3);
|
|
220
277
|
border-color: #f85149;
|
|
221
278
|
color: #ffffff;
|
|
222
279
|
}
|
|
223
280
|
|
|
224
|
-
.jp-
|
|
281
|
+
.jp-action-btn:disabled {
|
|
225
282
|
opacity: 0.45;
|
|
226
283
|
cursor: not-allowed;
|
|
227
284
|
}
|
|
@@ -303,69 +360,409 @@ const CONTROL_BAR_STYLES = `
|
|
|
303
360
|
}
|
|
304
361
|
}
|
|
305
362
|
`;
|
|
363
|
+
const INSTALL_BANNER_STYLES = `
|
|
364
|
+
:host {
|
|
365
|
+
all: initial;
|
|
366
|
+
position: fixed;
|
|
367
|
+
inset: 0;
|
|
368
|
+
z-index: 2147483645;
|
|
369
|
+
pointer-events: none;
|
|
370
|
+
font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
371
|
+
color: #f0f6fc;
|
|
372
|
+
-webkit-font-smoothing: antialiased;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
:host([hidden]) {
|
|
376
|
+
display: none !important;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
*, *::before, *::after {
|
|
380
|
+
box-sizing: border-box;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.jp-install-backdrop {
|
|
384
|
+
position: fixed;
|
|
385
|
+
left: 0;
|
|
386
|
+
right: 0;
|
|
387
|
+
top: var(--jp-control-bar-bottom, 48px);
|
|
388
|
+
bottom: var(--jetpack-log-terminal-offset, 0px);
|
|
389
|
+
pointer-events: auto;
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
justify-content: center;
|
|
393
|
+
padding: 24px 20px;
|
|
394
|
+
background: rgba(8, 12, 19, 0.72);
|
|
395
|
+
backdrop-filter: blur(14px);
|
|
396
|
+
-webkit-backdrop-filter: blur(14px);
|
|
397
|
+
overflow-y: auto;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
.jp-install-card {
|
|
401
|
+
position: relative;
|
|
402
|
+
z-index: 2;
|
|
403
|
+
width: 100%;
|
|
404
|
+
max-width: 440px;
|
|
405
|
+
display: flex;
|
|
406
|
+
flex-direction: column;
|
|
407
|
+
align-items: center;
|
|
408
|
+
text-align: center;
|
|
409
|
+
gap: 16px;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
.jp-poster-frame {
|
|
413
|
+
width: 100%;
|
|
414
|
+
max-width: 380px;
|
|
415
|
+
aspect-ratio: 16 / 9;
|
|
416
|
+
border-radius: 14px;
|
|
417
|
+
overflow: hidden;
|
|
418
|
+
border: 1px solid rgba(121, 192, 255, 0.28);
|
|
419
|
+
background: linear-gradient(145deg, #141d2e 0%, #0b111b 100%);
|
|
420
|
+
box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
|
|
421
|
+
position: relative;
|
|
422
|
+
display: flex;
|
|
423
|
+
align-items: center;
|
|
424
|
+
justify-content: center;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.jp-poster-img {
|
|
428
|
+
width: 100%;
|
|
429
|
+
height: 100%;
|
|
430
|
+
object-fit: cover;
|
|
431
|
+
display: block;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.jp-poster-img[hidden] {
|
|
435
|
+
display: none;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.jp-poster-fallback {
|
|
439
|
+
position: relative;
|
|
440
|
+
width: 100%;
|
|
441
|
+
height: 100%;
|
|
442
|
+
padding: 20px;
|
|
443
|
+
display: flex;
|
|
444
|
+
flex-direction: column;
|
|
445
|
+
align-items: center;
|
|
446
|
+
justify-content: center;
|
|
447
|
+
gap: 10px;
|
|
448
|
+
overflow: hidden;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.jp-poster-fallback[hidden] {
|
|
452
|
+
display: none;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.jp-poster-grid {
|
|
456
|
+
position: absolute;
|
|
457
|
+
inset: 0;
|
|
458
|
+
background-image:
|
|
459
|
+
linear-gradient(rgba(88, 166, 255, 0.08) 1px, transparent 1px),
|
|
460
|
+
linear-gradient(90deg, rgba(88, 166, 255, 0.08) 1px, transparent 1px);
|
|
461
|
+
background-size: 22px 22px;
|
|
462
|
+
mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 0.9) 25%, transparent 85%);
|
|
463
|
+
pointer-events: none;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
.jp-poster-emblem {
|
|
467
|
+
position: relative;
|
|
468
|
+
z-index: 1;
|
|
469
|
+
width: 52px;
|
|
470
|
+
height: 52px;
|
|
471
|
+
border-radius: 14px;
|
|
472
|
+
display: flex;
|
|
473
|
+
align-items: center;
|
|
474
|
+
justify-content: center;
|
|
475
|
+
background: rgba(31, 111, 235, 0.16);
|
|
476
|
+
border: 1px solid rgba(88, 166, 255, 0.35);
|
|
477
|
+
box-shadow: 0 10px 26px rgba(31, 111, 235, 0.25);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.jp-poster-emblem svg {
|
|
481
|
+
width: 30px;
|
|
482
|
+
height: 30px;
|
|
483
|
+
display: block;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.jp-poster-app-name {
|
|
487
|
+
position: relative;
|
|
488
|
+
z-index: 1;
|
|
489
|
+
font-size: 16px;
|
|
490
|
+
font-weight: 700;
|
|
491
|
+
color: #f0f6fc;
|
|
492
|
+
letter-spacing: -0.01em;
|
|
493
|
+
max-width: 100%;
|
|
494
|
+
overflow: hidden;
|
|
495
|
+
text-overflow: ellipsis;
|
|
496
|
+
white-space: nowrap;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
.jp-poster-powered {
|
|
500
|
+
position: relative;
|
|
501
|
+
z-index: 1;
|
|
502
|
+
font-size: 11px;
|
|
503
|
+
font-weight: 600;
|
|
504
|
+
letter-spacing: 0.06em;
|
|
505
|
+
text-transform: uppercase;
|
|
506
|
+
color: #79c0ff;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.jp-install-message-box {
|
|
510
|
+
width: 100%;
|
|
511
|
+
background: rgba(19, 25, 36, 0.92);
|
|
512
|
+
border: 1px solid #2e3b52;
|
|
513
|
+
border-radius: 12px;
|
|
514
|
+
padding: 14px 18px;
|
|
515
|
+
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.45);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.jp-install-message {
|
|
519
|
+
margin: 0;
|
|
520
|
+
font-size: 15px;
|
|
521
|
+
font-weight: 600;
|
|
522
|
+
line-height: 1.45;
|
|
523
|
+
color: #f0f6fc;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
.jp-install-wait {
|
|
527
|
+
margin-top: 8px;
|
|
528
|
+
display: inline-flex;
|
|
529
|
+
align-items: center;
|
|
530
|
+
justify-content: center;
|
|
531
|
+
gap: 8px;
|
|
532
|
+
font-size: 12px;
|
|
533
|
+
font-weight: 500;
|
|
534
|
+
color: #9fb0c7;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.jp-install-wait-dot {
|
|
538
|
+
width: 8px;
|
|
539
|
+
height: 8px;
|
|
540
|
+
border-radius: 50%;
|
|
541
|
+
background: #58a6ff;
|
|
542
|
+
box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
|
|
543
|
+
animation: jp-pulse 1.6s ease-in-out infinite;
|
|
544
|
+
flex-shrink: 0;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
@keyframes jp-pulse {
|
|
548
|
+
0%, 100% {
|
|
549
|
+
opacity: 1;
|
|
550
|
+
transform: scale(1);
|
|
551
|
+
}
|
|
552
|
+
50% {
|
|
553
|
+
opacity: 0.55;
|
|
554
|
+
transform: scale(0.86);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.jp-install-arrow-svg {
|
|
559
|
+
position: fixed;
|
|
560
|
+
inset: 0;
|
|
561
|
+
width: 100%;
|
|
562
|
+
height: 100%;
|
|
563
|
+
pointer-events: none;
|
|
564
|
+
z-index: 3;
|
|
565
|
+
overflow: visible;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
.jp-install-arrow-svg[hidden] {
|
|
569
|
+
display: none;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
.jp-install-arrow-path {
|
|
573
|
+
fill: none;
|
|
574
|
+
stroke: #58a6ff;
|
|
575
|
+
stroke-width: 2.75;
|
|
576
|
+
stroke-linecap: round;
|
|
577
|
+
stroke-dasharray: 8 6;
|
|
578
|
+
filter: drop-shadow(0 2px 8px rgba(56, 139, 253, 0.55));
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
.jp-install-arrow-head {
|
|
582
|
+
fill: #58a6ff;
|
|
583
|
+
}
|
|
584
|
+
`;
|
|
306
585
|
const JETPACK_LOGO_SVG = '<svg class="jp-logo-svg" viewBox="0 0 24 24" fill="none" aria-hidden="true">' +
|
|
307
586
|
'<rect width="24" height="24" rx="6" fill="#1F6FEB"/>' +
|
|
308
587
|
'<path d="M12 4.5L16.5 11H13.5V16.5L9.5 12H11.5V4.5H12Z" fill="#FFFFFF"/>' +
|
|
309
588
|
'<path d="M8.5 16.5L12 20L15.5 16.5H8.5Z" fill="#79C0FF"/>' +
|
|
310
589
|
'</svg>';
|
|
311
|
-
|
|
590
|
+
const ACTIVE_CONTROL_BARS_REGISTRY_KEY = Symbol.for('jetpack.controlBar.activeByDocument');
|
|
591
|
+
function getActiveControlBarRegistry() {
|
|
592
|
+
const g = globalThis;
|
|
593
|
+
let registry = g[ACTIVE_CONTROL_BARS_REGISTRY_KEY];
|
|
594
|
+
if (!registry) {
|
|
595
|
+
registry = new WeakMap();
|
|
596
|
+
g[ACTIVE_CONTROL_BARS_REGISTRY_KEY] = registry;
|
|
597
|
+
}
|
|
598
|
+
return registry;
|
|
599
|
+
}
|
|
600
|
+
function isLoopbackHost(hostname) {
|
|
601
|
+
const lower = hostname.toLowerCase();
|
|
602
|
+
return lower === '127.0.0.1' || lower === 'localhost' || lower === '[::1]' || lower === '::1';
|
|
603
|
+
}
|
|
604
|
+
export function sanitizePosterUrl(rawUrl) {
|
|
312
605
|
if (typeof rawUrl !== 'string')
|
|
313
606
|
return null;
|
|
314
607
|
const trimmed = rawUrl.trim();
|
|
315
|
-
if (!trimmed || /[\s\u0000-\u001f\u007f]/.test(trimmed)) {
|
|
608
|
+
if (!trimmed || /[\s\u0000-\u001f\u007f]/.test(trimmed) || trimmed.includes('\\')) {
|
|
316
609
|
return null;
|
|
317
610
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
611
|
+
if (trimmed.startsWith('/')) {
|
|
612
|
+
if (trimmed.startsWith('//')) {
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
const pathOnly = trimmed.split(/[?#]/, 1)[0] || '';
|
|
616
|
+
const segments = pathOnly.split('/');
|
|
617
|
+
if (segments.some((seg) => seg === '..' || seg.toLowerCase() === '%2e%2e')) {
|
|
321
618
|
return null;
|
|
322
619
|
}
|
|
323
|
-
return
|
|
620
|
+
return trimmed;
|
|
621
|
+
}
|
|
622
|
+
let parsed;
|
|
623
|
+
try {
|
|
624
|
+
parsed = new URL(trimmed);
|
|
324
625
|
}
|
|
325
626
|
catch {
|
|
326
627
|
return null;
|
|
327
628
|
}
|
|
629
|
+
if (parsed.username || parsed.password || !parsed.hostname) {
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
if (parsed.protocol === 'https:') {
|
|
633
|
+
// Allowed
|
|
634
|
+
}
|
|
635
|
+
else if (parsed.protocol === 'http:' && isLoopbackHost(parsed.hostname)) {
|
|
636
|
+
// Allowed loopback HTTP for local development/tests
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
const pathSegments = parsed.pathname.split('/');
|
|
642
|
+
if (pathSegments.some((seg) => seg === '..' || seg.toLowerCase() === '%2e%2e')) {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
return parsed.toString();
|
|
646
|
+
}
|
|
647
|
+
function resolveMetaPosterCandidate() {
|
|
648
|
+
if (typeof document === 'undefined' || typeof document.querySelector !== 'function') {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
const selectors = [
|
|
652
|
+
'meta[property="og:image"]',
|
|
653
|
+
'meta[name="og:image"]',
|
|
654
|
+
'meta[name="twitter:image"]',
|
|
655
|
+
'meta[property="twitter:image"]',
|
|
656
|
+
];
|
|
657
|
+
for (const selector of selectors) {
|
|
658
|
+
try {
|
|
659
|
+
const el = document.querySelector(selector);
|
|
660
|
+
const content = el?.getAttribute?.('content');
|
|
661
|
+
const safe = sanitizePosterUrl(content);
|
|
662
|
+
if (safe) {
|
|
663
|
+
return safe;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
catch {
|
|
667
|
+
// Ignore query errors in partial mock DOMs
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
function createSvgNode(tag) {
|
|
673
|
+
if (typeof document.createElementNS === 'function') {
|
|
674
|
+
return document.createElementNS('http://www.w3.org/2000/svg', tag);
|
|
675
|
+
}
|
|
676
|
+
return document.createElement(tag);
|
|
677
|
+
}
|
|
678
|
+
function clamp(val, min, max) {
|
|
679
|
+
if (max < min)
|
|
680
|
+
return min;
|
|
681
|
+
return Math.min(max, Math.max(min, val));
|
|
328
682
|
}
|
|
329
683
|
/**
|
|
330
684
|
* Shadow-DOM isolated top control bar for standalone and third-party JetPack web applications.
|
|
331
685
|
*
|
|
332
686
|
* Displays the JetPack logo, current app name, live worker status (`Connecting`, `Running`,
|
|
333
|
-
* `Stopped`, `Error`), `"Control Center"` link, `"Stop"` button,
|
|
334
|
-
* modal when stopping could lose unsaved work
|
|
687
|
+
* `Stopped`, `Error`), `"Control Center"` link, unified `"Launch"` / `"Stop"` action button,
|
|
688
|
+
* an encapsulated confirmation modal when stopping could lose unsaved work, and a blocking
|
|
689
|
+
* install-gate overlay when JetPack Desktop is unreachable (`DAEMON_NOT_RUNNING`).
|
|
335
690
|
*/
|
|
336
691
|
export class JetPackControlBar {
|
|
337
692
|
options;
|
|
693
|
+
i18n;
|
|
338
694
|
status;
|
|
339
695
|
currentDownloadUrl = null;
|
|
340
696
|
stopping = false;
|
|
341
|
-
|
|
697
|
+
launching = false;
|
|
342
698
|
modalOpen = false;
|
|
699
|
+
posterLoadFailed = false;
|
|
700
|
+
lastResolvedPosterUrl = null;
|
|
343
701
|
host = null;
|
|
344
702
|
shadow = null;
|
|
703
|
+
headerEl = null;
|
|
345
704
|
appNameEl = null;
|
|
705
|
+
envBadgeEl = null;
|
|
346
706
|
statusPillEl = null;
|
|
347
707
|
statusTextEl = null;
|
|
348
708
|
errorNoteEl = null;
|
|
349
709
|
statusNoteEl = null;
|
|
350
710
|
downloadLinkEl = null;
|
|
351
711
|
controlCenterLinkEl = null;
|
|
352
|
-
|
|
353
|
-
stopBtnEl = null;
|
|
712
|
+
actionBtnEl = null;
|
|
354
713
|
modalBackdropEl = null;
|
|
355
714
|
modalTitleEl = null;
|
|
356
715
|
modalMessageEl = null;
|
|
357
716
|
modalCancelBtnEl = null;
|
|
358
717
|
modalConfirmBtnEl = null;
|
|
718
|
+
installBannerHost = null;
|
|
719
|
+
installBannerShadow = null;
|
|
720
|
+
installBackdropEl = null;
|
|
721
|
+
installCardEl = null;
|
|
722
|
+
installPosterImgEl = null;
|
|
723
|
+
installPosterFallbackEl = null;
|
|
724
|
+
installPosterAppNameEl = null;
|
|
725
|
+
installPosterPoweredEl = null;
|
|
726
|
+
installMessageBoxEl = null;
|
|
727
|
+
installMessageEl = null;
|
|
728
|
+
installWaitTextEl = null;
|
|
729
|
+
installArrowSvgEl = null;
|
|
730
|
+
installArrowPathEl = null;
|
|
359
731
|
keydownHandler = null;
|
|
732
|
+
layoutListenersAttached = false;
|
|
733
|
+
resizeObserver = null;
|
|
734
|
+
windowLayoutHandler = null;
|
|
735
|
+
arrowRafId = null;
|
|
360
736
|
constructor(options = {}) {
|
|
361
737
|
this.options = { ...options };
|
|
738
|
+
const initialLocale = options.language !== undefined
|
|
739
|
+
? resolveLanguage({
|
|
740
|
+
preferredLanguage: options.language,
|
|
741
|
+
search: '',
|
|
742
|
+
supportedLocales: ['en', 'uk'],
|
|
743
|
+
})
|
|
744
|
+
: resolveLanguage({ supportedLocales: ['en', 'uk'] });
|
|
745
|
+
this.i18n = createI18n({
|
|
746
|
+
catalogs: CONTROL_BAR_LOCALES,
|
|
747
|
+
initialLocale,
|
|
748
|
+
});
|
|
362
749
|
this.status = options.initialStatus ?? 'Connecting';
|
|
363
750
|
this.currentDownloadUrl =
|
|
364
|
-
this.status === 'Error' ?
|
|
751
|
+
this.status === 'Error' ? resolveJetPackDownloadUrl(options.downloadUrl) : null;
|
|
365
752
|
if (typeof document !== 'undefined' && options.mountTarget !== null) {
|
|
366
753
|
this.mount(options.mountTarget);
|
|
367
754
|
}
|
|
368
755
|
}
|
|
756
|
+
/** Returns the currently active UI language (`'en'` or `'uk'`). */
|
|
757
|
+
getLanguage() {
|
|
758
|
+
return this.i18n.getLocale();
|
|
759
|
+
}
|
|
760
|
+
/** Switches the Shadow-DOM chrome language (`'en'` or `'uk'`, falling back to `'en'`) and re-renders immediately. */
|
|
761
|
+
setLanguage(language) {
|
|
762
|
+
this.options.language = language;
|
|
763
|
+
this.i18n.setLocale(language);
|
|
764
|
+
this.syncUi();
|
|
765
|
+
}
|
|
369
766
|
/** Mounts the control bar host element at the top of `target` (or `document.body`). */
|
|
370
767
|
mount(target) {
|
|
371
768
|
if (typeof document === 'undefined') {
|
|
@@ -375,12 +772,33 @@ export class JetPackControlBar {
|
|
|
375
772
|
if (!container) {
|
|
376
773
|
return false;
|
|
377
774
|
}
|
|
775
|
+
const registry = getActiveControlBarRegistry();
|
|
776
|
+
const prevActive = registry.get(document);
|
|
777
|
+
if (prevActive && prevActive !== this) {
|
|
778
|
+
prevActive.markSupersededAndUnmount();
|
|
779
|
+
}
|
|
378
780
|
if (!this.host) {
|
|
379
781
|
this.buildDom();
|
|
380
782
|
}
|
|
783
|
+
if (!this.installBannerHost) {
|
|
784
|
+
this.buildInstallBannerDom();
|
|
785
|
+
}
|
|
381
786
|
if (!this.host) {
|
|
382
787
|
return false;
|
|
383
788
|
}
|
|
789
|
+
if (typeof document.querySelectorAll === 'function') {
|
|
790
|
+
try {
|
|
791
|
+
const staleNodes = document.querySelectorAll('[data-jetpack-control-bar="true"], #jetpack-control-bar-host, [data-jetpack-install-banner="true"], #jetpack-install-banner-host');
|
|
792
|
+
for (const node of Array.from(staleNodes)) {
|
|
793
|
+
if (node !== this.host && node !== this.installBannerHost && node.parentNode) {
|
|
794
|
+
node.parentNode.removeChild(node);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
catch {
|
|
799
|
+
// Ignore query failures in restricted/mock DOM environments
|
|
800
|
+
}
|
|
801
|
+
}
|
|
384
802
|
if (this.host.parentNode !== container) {
|
|
385
803
|
if (container.firstChild) {
|
|
386
804
|
container.insertBefore(this.host, container.firstChild);
|
|
@@ -389,37 +807,93 @@ export class JetPackControlBar {
|
|
|
389
807
|
container.appendChild(this.host);
|
|
390
808
|
}
|
|
391
809
|
}
|
|
810
|
+
registry.set(document, this);
|
|
392
811
|
this.syncUi();
|
|
393
812
|
return true;
|
|
394
813
|
}
|
|
395
|
-
/** Unmounts and cleans up the control bar host and event listeners. */
|
|
814
|
+
/** Unmounts and cleans up the control bar host, install-gate overlay, and event listeners. */
|
|
396
815
|
unmount() {
|
|
397
816
|
this.closeModal();
|
|
817
|
+
this.detachInstallLayoutTracking();
|
|
398
818
|
if (this.keydownHandler && typeof document !== 'undefined') {
|
|
399
819
|
document.removeEventListener('keydown', this.keydownHandler);
|
|
400
820
|
this.keydownHandler = null;
|
|
401
821
|
}
|
|
822
|
+
if (typeof document !== 'undefined') {
|
|
823
|
+
const registry = getActiveControlBarRegistry();
|
|
824
|
+
if (registry.get(document) === this) {
|
|
825
|
+
registry.delete(document);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
402
828
|
if (this.host && this.host.parentNode) {
|
|
403
829
|
this.host.parentNode.removeChild(this.host);
|
|
404
830
|
}
|
|
831
|
+
if (this.installBannerHost && this.installBannerHost.parentNode) {
|
|
832
|
+
this.installBannerHost.parentNode.removeChild(this.installBannerHost);
|
|
833
|
+
}
|
|
405
834
|
this.host = null;
|
|
406
835
|
this.shadow = null;
|
|
836
|
+
this.headerEl = null;
|
|
837
|
+
this.appNameEl = null;
|
|
838
|
+
this.envBadgeEl = null;
|
|
839
|
+
this.statusPillEl = null;
|
|
840
|
+
this.statusTextEl = null;
|
|
841
|
+
this.errorNoteEl = null;
|
|
842
|
+
this.statusNoteEl = null;
|
|
843
|
+
this.downloadLinkEl = null;
|
|
844
|
+
this.controlCenterLinkEl = null;
|
|
845
|
+
this.actionBtnEl = null;
|
|
846
|
+
this.modalBackdropEl = null;
|
|
847
|
+
this.modalTitleEl = null;
|
|
848
|
+
this.modalMessageEl = null;
|
|
849
|
+
this.modalCancelBtnEl = null;
|
|
850
|
+
this.modalConfirmBtnEl = null;
|
|
851
|
+
this.installBannerHost = null;
|
|
852
|
+
this.installBannerShadow = null;
|
|
853
|
+
this.installBackdropEl = null;
|
|
854
|
+
this.installCardEl = null;
|
|
855
|
+
this.installPosterImgEl = null;
|
|
856
|
+
this.installPosterFallbackEl = null;
|
|
857
|
+
this.installPosterAppNameEl = null;
|
|
858
|
+
this.installPosterPoweredEl = null;
|
|
859
|
+
this.installMessageBoxEl = null;
|
|
860
|
+
this.installMessageEl = null;
|
|
861
|
+
this.installWaitTextEl = null;
|
|
862
|
+
this.installArrowSvgEl = null;
|
|
863
|
+
this.installArrowPathEl = null;
|
|
864
|
+
}
|
|
865
|
+
markSupersededAndUnmount() {
|
|
866
|
+
const cb = this.options.onSuperseded;
|
|
867
|
+
this.unmount();
|
|
868
|
+
cb?.();
|
|
407
869
|
}
|
|
408
870
|
/** Updates mutable configuration options on the mounted bar. */
|
|
409
871
|
updateOptions(partial) {
|
|
872
|
+
const posterChanged = 'posterUrl' in partial || 'installBanner' in partial;
|
|
410
873
|
this.options = { ...this.options, ...partial };
|
|
874
|
+
if ('language' in partial) {
|
|
875
|
+
this.i18n.setLocale(partial.language);
|
|
876
|
+
}
|
|
877
|
+
if (posterChanged) {
|
|
878
|
+
this.posterLoadFailed = false;
|
|
879
|
+
}
|
|
411
880
|
if (this.status === 'Error' && 'downloadUrl' in partial) {
|
|
412
|
-
this.currentDownloadUrl =
|
|
881
|
+
this.currentDownloadUrl = resolveJetPackDownloadUrl(partial.downloadUrl);
|
|
413
882
|
}
|
|
414
883
|
this.syncUi();
|
|
415
884
|
}
|
|
885
|
+
/** Updates install-gate overlay options (`false` disables, or object updates `posterUrl`/`message`). */
|
|
886
|
+
setInstallBannerOptions(installBanner) {
|
|
887
|
+
this.updateOptions({ installBanner });
|
|
888
|
+
}
|
|
416
889
|
/** Updates the live worker status pill, optional detail text, and optional HTTPS download link. */
|
|
417
890
|
setStatus(status, detail, statusOptions) {
|
|
418
891
|
this.status = status;
|
|
892
|
+
if (status === 'Running' || status === 'Error') {
|
|
893
|
+
this.launching = false;
|
|
894
|
+
}
|
|
419
895
|
this.currentDownloadUrl =
|
|
420
|
-
status === 'Error'
|
|
421
|
-
? sanitizeHttpsDownloadUrl(statusOptions?.downloadUrl ?? this.options.downloadUrl)
|
|
422
|
-
: null;
|
|
896
|
+
status === 'Error' ? resolveJetPackDownloadUrl(statusOptions?.downloadUrl) : null;
|
|
423
897
|
if (this.errorNoteEl) {
|
|
424
898
|
const msg = status === 'Error' && detail ? detail.trim() : '';
|
|
425
899
|
this.errorNoteEl.textContent = msg;
|
|
@@ -439,6 +913,10 @@ export class JetPackControlBar {
|
|
|
439
913
|
getStatus() {
|
|
440
914
|
return this.status;
|
|
441
915
|
}
|
|
916
|
+
/** Returns `true` when the blocking install-gate overlay is currently visible. */
|
|
917
|
+
isInstallBannerVisible() {
|
|
918
|
+
return Boolean(this.installBannerHost && !this.installBannerHost.hidden);
|
|
919
|
+
}
|
|
442
920
|
/** Updates the displayed application name in the control bar. */
|
|
443
921
|
setAppName(appName) {
|
|
444
922
|
this.options.appName = appName;
|
|
@@ -457,25 +935,32 @@ export class JetPackControlBar {
|
|
|
457
935
|
getShadowRoot() {
|
|
458
936
|
return this.shadow;
|
|
459
937
|
}
|
|
938
|
+
/** Returns the install-gate overlay host element, or `null` if unmounted. */
|
|
939
|
+
getInstallBannerHostElement() {
|
|
940
|
+
return this.installBannerHost;
|
|
941
|
+
}
|
|
942
|
+
/** Returns the open ShadowRoot isolating the install-gate overlay styles and DOM. */
|
|
943
|
+
getInstallBannerShadowRoot() {
|
|
944
|
+
return this.installBannerShadow;
|
|
945
|
+
}
|
|
460
946
|
/** Returns `true` when the Shadow-DOM stop confirmation modal is open. */
|
|
461
947
|
isModalOpen() {
|
|
462
948
|
return this.modalOpen;
|
|
463
949
|
}
|
|
464
950
|
/**
|
|
465
|
-
* Handles a
|
|
466
|
-
* Invokes `options.onRelaunch()` and transitions to `'Running'` on success.
|
|
951
|
+
* Handles a Launch button click while `status === 'Stopped'`.
|
|
952
|
+
* Invokes `options.onLaunch()` (or legacy `options.onRelaunch()`) and transitions to `'Running'` on success.
|
|
467
953
|
*/
|
|
468
|
-
async
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
typeof this.options.onRelaunch !== 'function') {
|
|
954
|
+
async triggerLaunch() {
|
|
955
|
+
const launchHandler = this.options.onLaunch ?? this.options.onRelaunch;
|
|
956
|
+
if (this.status !== 'Stopped' || this.launching || typeof launchHandler !== 'function') {
|
|
472
957
|
return false;
|
|
473
958
|
}
|
|
474
|
-
this.
|
|
959
|
+
this.launching = true;
|
|
475
960
|
this.syncUi();
|
|
476
961
|
try {
|
|
477
|
-
await
|
|
478
|
-
this.
|
|
962
|
+
await launchHandler();
|
|
963
|
+
this.launching = false;
|
|
479
964
|
if (this.status === 'Stopped') {
|
|
480
965
|
this.setStatus('Running');
|
|
481
966
|
}
|
|
@@ -485,12 +970,24 @@ export class JetPackControlBar {
|
|
|
485
970
|
return true;
|
|
486
971
|
}
|
|
487
972
|
catch (err) {
|
|
488
|
-
this.
|
|
973
|
+
this.launching = false;
|
|
489
974
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
490
|
-
|
|
975
|
+
const dlUrl = err &&
|
|
976
|
+
typeof err === 'object' &&
|
|
977
|
+
'downloadUrl' in err &&
|
|
978
|
+
typeof err.downloadUrl === 'string'
|
|
979
|
+
? err.downloadUrl
|
|
980
|
+
: this.status === 'Error'
|
|
981
|
+
? (this.currentDownloadUrl ?? undefined)
|
|
982
|
+
: undefined;
|
|
983
|
+
this.setStatus('Error', error.message, dlUrl ? { downloadUrl: dlUrl } : undefined);
|
|
491
984
|
return false;
|
|
492
985
|
}
|
|
493
986
|
}
|
|
987
|
+
/** Backwards-compatible alias for `triggerLaunch()`. */
|
|
988
|
+
async triggerRelaunch() {
|
|
989
|
+
return this.triggerLaunch();
|
|
990
|
+
}
|
|
494
991
|
/**
|
|
495
992
|
* Handles a Stop button click: opens the styled Shadow-DOM confirmation modal if
|
|
496
993
|
* `warnOnUnsavedWork` evaluates to `true` or `onBeforeStop` is configured (with
|
|
@@ -525,14 +1022,35 @@ export class JetPackControlBar {
|
|
|
525
1022
|
}
|
|
526
1023
|
return typeof this.options.onBeforeStop === 'function';
|
|
527
1024
|
}
|
|
1025
|
+
shouldShowInstallBanner() {
|
|
1026
|
+
return (this.options.installBanner !== false &&
|
|
1027
|
+
this.status === 'Error' &&
|
|
1028
|
+
this.currentDownloadUrl !== null &&
|
|
1029
|
+
this.host !== null &&
|
|
1030
|
+
this.host.parentNode !== null);
|
|
1031
|
+
}
|
|
1032
|
+
resolveSafePosterCandidate() {
|
|
1033
|
+
const bannerOpts = typeof this.options.installBanner === 'object' && this.options.installBanner !== null
|
|
1034
|
+
? this.options.installBanner
|
|
1035
|
+
: null;
|
|
1036
|
+
const explicit = typeof bannerOpts?.posterUrl === 'string' && bannerOpts.posterUrl.trim().length > 0
|
|
1037
|
+
? bannerOpts.posterUrl
|
|
1038
|
+
: typeof this.options.posterUrl === 'string' && this.options.posterUrl.trim().length > 0
|
|
1039
|
+
? this.options.posterUrl
|
|
1040
|
+
: null;
|
|
1041
|
+
if (explicit !== null) {
|
|
1042
|
+
return sanitizePosterUrl(explicit);
|
|
1043
|
+
}
|
|
1044
|
+
return resolveMetaPosterCandidate();
|
|
1045
|
+
}
|
|
528
1046
|
openModal() {
|
|
529
1047
|
this.modalOpen = true;
|
|
530
1048
|
if (this.modalTitleEl) {
|
|
531
|
-
this.modalTitleEl.textContent = this.options.stopConfirmTitle ??
|
|
1049
|
+
this.modalTitleEl.textContent = this.options.stopConfirmTitle ?? this.i18n.t('modalTitle');
|
|
532
1050
|
}
|
|
533
1051
|
if (this.modalMessageEl) {
|
|
534
1052
|
this.modalMessageEl.textContent =
|
|
535
|
-
this.options.stopConfirmMessage ??
|
|
1053
|
+
this.options.stopConfirmMessage ?? this.i18n.t('modalMessage');
|
|
536
1054
|
}
|
|
537
1055
|
if (this.modalBackdropEl) {
|
|
538
1056
|
this.modalBackdropEl.hidden = false;
|
|
@@ -614,10 +1132,16 @@ export class JetPackControlBar {
|
|
|
614
1132
|
const appNameEl = document.createElement('span');
|
|
615
1133
|
appNameEl.className = 'jp-app-name';
|
|
616
1134
|
appNameEl.setAttribute('data-jp-field', 'app-name');
|
|
1135
|
+
const envBadgeEl = document.createElement('span');
|
|
1136
|
+
envBadgeEl.className = 'jp-env-badge';
|
|
1137
|
+
envBadgeEl.setAttribute('data-jp-field', 'env-badge');
|
|
1138
|
+
envBadgeEl.textContent = 'DEV';
|
|
1139
|
+
envBadgeEl.hidden = true;
|
|
617
1140
|
left.appendChild(brand);
|
|
618
1141
|
left.appendChild(divider);
|
|
619
1142
|
left.appendChild(appNameEl);
|
|
620
|
-
|
|
1143
|
+
left.appendChild(envBadgeEl);
|
|
1144
|
+
// Right cluster: optional error/status note + live status pill + Control Center link + unified Launch/Stop action button
|
|
621
1145
|
const right = document.createElement('div');
|
|
622
1146
|
right.className = 'jp-right';
|
|
623
1147
|
const errorNoteEl = document.createElement('span');
|
|
@@ -651,30 +1175,25 @@ export class JetPackControlBar {
|
|
|
651
1175
|
ccLink.target = '_blank';
|
|
652
1176
|
ccLink.rel = 'noopener noreferrer';
|
|
653
1177
|
ccLink.textContent = 'Control Center';
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
stopBtn.setAttribute('data-jp-action', 'stop');
|
|
667
|
-
stopBtn.textContent = 'Stop';
|
|
668
|
-
stopBtn.addEventListener('click', () => {
|
|
669
|
-
void this.triggerStop();
|
|
1178
|
+
const actionBtn = document.createElement('button');
|
|
1179
|
+
actionBtn.type = 'button';
|
|
1180
|
+
actionBtn.className = 'jp-action-btn';
|
|
1181
|
+
actionBtn.setAttribute('data-jp-action', 'launch');
|
|
1182
|
+
actionBtn.textContent = 'Launch';
|
|
1183
|
+
actionBtn.addEventListener('click', () => {
|
|
1184
|
+
if (this.status === 'Running') {
|
|
1185
|
+
void this.triggerStop();
|
|
1186
|
+
}
|
|
1187
|
+
else if (this.status === 'Stopped') {
|
|
1188
|
+
void this.triggerLaunch();
|
|
1189
|
+
}
|
|
670
1190
|
});
|
|
671
1191
|
right.appendChild(errorNoteEl);
|
|
672
1192
|
right.appendChild(statusNoteEl);
|
|
673
1193
|
right.appendChild(downloadLink);
|
|
674
1194
|
right.appendChild(statusPillEl);
|
|
675
1195
|
right.appendChild(ccLink);
|
|
676
|
-
right.appendChild(
|
|
677
|
-
right.appendChild(stopBtn);
|
|
1196
|
+
right.appendChild(actionBtn);
|
|
678
1197
|
header.appendChild(left);
|
|
679
1198
|
header.appendChild(right);
|
|
680
1199
|
shadow.appendChild(header);
|
|
@@ -733,56 +1252,394 @@ export class JetPackControlBar {
|
|
|
733
1252
|
}
|
|
734
1253
|
this.host = host;
|
|
735
1254
|
this.shadow = shadow;
|
|
1255
|
+
this.headerEl = header;
|
|
736
1256
|
this.appNameEl = appNameEl;
|
|
1257
|
+
this.envBadgeEl = envBadgeEl;
|
|
737
1258
|
this.statusPillEl = statusPillEl;
|
|
738
1259
|
this.statusTextEl = statusTextEl;
|
|
739
1260
|
this.errorNoteEl = errorNoteEl;
|
|
740
1261
|
this.statusNoteEl = statusNoteEl;
|
|
741
1262
|
this.downloadLinkEl = downloadLink;
|
|
742
1263
|
this.controlCenterLinkEl = ccLink;
|
|
743
|
-
this.
|
|
744
|
-
this.stopBtnEl = stopBtn;
|
|
1264
|
+
this.actionBtnEl = actionBtn;
|
|
745
1265
|
this.modalBackdropEl = backdrop;
|
|
746
1266
|
this.modalTitleEl = modalTitle;
|
|
747
1267
|
this.modalMessageEl = modalMessage;
|
|
748
1268
|
this.modalCancelBtnEl = cancelBtn;
|
|
749
1269
|
this.modalConfirmBtnEl = confirmBtn;
|
|
750
1270
|
}
|
|
1271
|
+
buildInstallBannerDom() {
|
|
1272
|
+
const bannerHost = document.createElement('div');
|
|
1273
|
+
bannerHost.id = 'jetpack-install-banner-host';
|
|
1274
|
+
bannerHost.setAttribute('data-jetpack-install-banner', 'true');
|
|
1275
|
+
bannerHost.hidden = true;
|
|
1276
|
+
bannerHost.style.display = 'none';
|
|
1277
|
+
const shadow = bannerHost.attachShadow({ mode: 'open' });
|
|
1278
|
+
const style = document.createElement('style');
|
|
1279
|
+
style.textContent = INSTALL_BANNER_STYLES;
|
|
1280
|
+
shadow.appendChild(style);
|
|
1281
|
+
const backdrop = document.createElement('div');
|
|
1282
|
+
backdrop.className = 'jp-install-backdrop';
|
|
1283
|
+
backdrop.setAttribute('data-jp-field', 'install-backdrop');
|
|
1284
|
+
backdrop.setAttribute('role', 'dialog');
|
|
1285
|
+
backdrop.setAttribute('aria-modal', 'true');
|
|
1286
|
+
const card = document.createElement('div');
|
|
1287
|
+
card.className = 'jp-install-card';
|
|
1288
|
+
card.setAttribute('data-jp-field', 'install-card');
|
|
1289
|
+
const posterFrame = document.createElement('div');
|
|
1290
|
+
posterFrame.className = 'jp-poster-frame';
|
|
1291
|
+
posterFrame.setAttribute('data-jp-field', 'install-poster');
|
|
1292
|
+
const posterImg = document.createElement('img');
|
|
1293
|
+
posterImg.className = 'jp-poster-img';
|
|
1294
|
+
posterImg.setAttribute('data-jp-field', 'install-poster-img');
|
|
1295
|
+
posterImg.hidden = true;
|
|
1296
|
+
posterImg.addEventListener('error', () => {
|
|
1297
|
+
this.posterLoadFailed = true;
|
|
1298
|
+
this.syncInstallBannerUi();
|
|
1299
|
+
});
|
|
1300
|
+
const posterFallback = document.createElement('div');
|
|
1301
|
+
posterFallback.className = 'jp-poster-fallback';
|
|
1302
|
+
posterFallback.setAttribute('data-jp-field', 'install-poster-fallback');
|
|
1303
|
+
const grid = document.createElement('div');
|
|
1304
|
+
grid.className = 'jp-poster-grid';
|
|
1305
|
+
grid.setAttribute('aria-hidden', 'true');
|
|
1306
|
+
const emblem = document.createElement('div');
|
|
1307
|
+
emblem.className = 'jp-poster-emblem';
|
|
1308
|
+
emblem.innerHTML = JETPACK_LOGO_SVG;
|
|
1309
|
+
const fallbackAppName = document.createElement('div');
|
|
1310
|
+
fallbackAppName.className = 'jp-poster-app-name';
|
|
1311
|
+
fallbackAppName.setAttribute('data-jp-field', 'install-poster-app-name');
|
|
1312
|
+
const poweredLabel = document.createElement('div');
|
|
1313
|
+
poweredLabel.className = 'jp-poster-powered';
|
|
1314
|
+
poweredLabel.setAttribute('data-jp-field', 'install-poster-powered');
|
|
1315
|
+
poweredLabel.textContent = this.i18n.t('poweredBy');
|
|
1316
|
+
posterFallback.appendChild(grid);
|
|
1317
|
+
posterFallback.appendChild(emblem);
|
|
1318
|
+
posterFallback.appendChild(fallbackAppName);
|
|
1319
|
+
posterFallback.appendChild(poweredLabel);
|
|
1320
|
+
posterFrame.appendChild(posterImg);
|
|
1321
|
+
posterFrame.appendChild(posterFallback);
|
|
1322
|
+
const messageBox = document.createElement('div');
|
|
1323
|
+
messageBox.className = 'jp-install-message-box';
|
|
1324
|
+
messageBox.setAttribute('data-jp-field', 'install-message-box');
|
|
1325
|
+
const messageEl = document.createElement('p');
|
|
1326
|
+
messageEl.className = 'jp-install-message';
|
|
1327
|
+
messageEl.setAttribute('data-jp-field', 'install-message');
|
|
1328
|
+
const waitEl = document.createElement('div');
|
|
1329
|
+
waitEl.className = 'jp-install-wait';
|
|
1330
|
+
waitEl.setAttribute('data-jp-field', 'install-wait');
|
|
1331
|
+
const waitDot = document.createElement('span');
|
|
1332
|
+
waitDot.className = 'jp-install-wait-dot';
|
|
1333
|
+
waitDot.setAttribute('aria-hidden', 'true');
|
|
1334
|
+
const waitText = document.createElement('span');
|
|
1335
|
+
waitText.setAttribute('data-jp-field', 'install-wait-text');
|
|
1336
|
+
waitText.textContent = this.i18n.t('installWaitText');
|
|
1337
|
+
waitEl.appendChild(waitDot);
|
|
1338
|
+
waitEl.appendChild(waitText);
|
|
1339
|
+
messageBox.appendChild(messageEl);
|
|
1340
|
+
messageBox.appendChild(waitEl);
|
|
1341
|
+
card.appendChild(posterFrame);
|
|
1342
|
+
card.appendChild(messageBox);
|
|
1343
|
+
backdrop.appendChild(card);
|
|
1344
|
+
// Inline SVG arrow pointing from install message to the "Download JetPack" button
|
|
1345
|
+
const arrowSvg = createSvgNode('svg');
|
|
1346
|
+
arrowSvg.setAttribute('class', 'jp-install-arrow-svg');
|
|
1347
|
+
arrowSvg.setAttribute('data-jp-field', 'install-arrow-svg');
|
|
1348
|
+
arrowSvg.setAttribute('aria-hidden', 'true');
|
|
1349
|
+
arrowSvg.hidden = true;
|
|
1350
|
+
const defs = createSvgNode('defs');
|
|
1351
|
+
const marker = createSvgNode('marker');
|
|
1352
|
+
marker.setAttribute('id', 'jp-install-arrowhead');
|
|
1353
|
+
marker.setAttribute('markerWidth', '12');
|
|
1354
|
+
marker.setAttribute('markerHeight', '12');
|
|
1355
|
+
marker.setAttribute('refX', '9');
|
|
1356
|
+
marker.setAttribute('refY', '6');
|
|
1357
|
+
marker.setAttribute('orient', 'auto');
|
|
1358
|
+
marker.setAttribute('markerUnits', 'userSpaceOnUse');
|
|
1359
|
+
const markerPoly = createSvgNode('polygon');
|
|
1360
|
+
markerPoly.setAttribute('points', '0,1.5 11,6 0,10.5 2.5,6');
|
|
1361
|
+
markerPoly.setAttribute('class', 'jp-install-arrow-head');
|
|
1362
|
+
marker.appendChild(markerPoly);
|
|
1363
|
+
defs.appendChild(marker);
|
|
1364
|
+
const arrowPath = createSvgNode('path');
|
|
1365
|
+
arrowPath.setAttribute('class', 'jp-install-arrow-path');
|
|
1366
|
+
arrowPath.setAttribute('data-jp-field', 'install-arrow-path');
|
|
1367
|
+
arrowPath.setAttribute('marker-end', 'url(#jp-install-arrowhead)');
|
|
1368
|
+
arrowSvg.appendChild(defs);
|
|
1369
|
+
arrowSvg.appendChild(arrowPath);
|
|
1370
|
+
shadow.appendChild(backdrop);
|
|
1371
|
+
shadow.appendChild(arrowSvg);
|
|
1372
|
+
this.installBannerHost = bannerHost;
|
|
1373
|
+
this.installBannerShadow = shadow;
|
|
1374
|
+
this.installBackdropEl = backdrop;
|
|
1375
|
+
this.installCardEl = card;
|
|
1376
|
+
this.installPosterImgEl = posterImg;
|
|
1377
|
+
this.installPosterFallbackEl = posterFallback;
|
|
1378
|
+
this.installPosterAppNameEl = fallbackAppName;
|
|
1379
|
+
this.installPosterPoweredEl = poweredLabel;
|
|
1380
|
+
this.installMessageBoxEl = messageBox;
|
|
1381
|
+
this.installMessageEl = messageEl;
|
|
1382
|
+
this.installWaitTextEl = waitText;
|
|
1383
|
+
this.installArrowSvgEl = arrowSvg;
|
|
1384
|
+
this.installArrowPathEl = arrowPath;
|
|
1385
|
+
}
|
|
1386
|
+
getStatusLabel(status) {
|
|
1387
|
+
switch (status) {
|
|
1388
|
+
case 'Connecting':
|
|
1389
|
+
return this.i18n.t('statusConnecting');
|
|
1390
|
+
case 'Running':
|
|
1391
|
+
return this.i18n.t('statusRunning');
|
|
1392
|
+
case 'Stopped':
|
|
1393
|
+
return this.i18n.t('statusStopped');
|
|
1394
|
+
case 'Error':
|
|
1395
|
+
default:
|
|
1396
|
+
return this.i18n.t('statusError');
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
751
1399
|
syncUi() {
|
|
752
|
-
const resolvedName = this.options.appName?.trim() || this.options.appId?.trim() || '
|
|
1400
|
+
const resolvedName = this.options.appName?.trim() || this.options.appId?.trim() || this.i18n.t('defaultAppName');
|
|
753
1401
|
if (this.appNameEl) {
|
|
754
1402
|
this.appNameEl.textContent = resolvedName;
|
|
755
1403
|
}
|
|
1404
|
+
if (this.envBadgeEl) {
|
|
1405
|
+
this.envBadgeEl.hidden = this.options.env !== 'dev';
|
|
1406
|
+
}
|
|
756
1407
|
if (this.statusPillEl) {
|
|
757
1408
|
this.statusPillEl.setAttribute('data-status', this.status);
|
|
758
1409
|
}
|
|
759
1410
|
if (this.statusTextEl) {
|
|
760
|
-
this.statusTextEl.textContent = this.status;
|
|
1411
|
+
this.statusTextEl.textContent = this.getStatusLabel(this.status);
|
|
761
1412
|
}
|
|
762
1413
|
if (this.downloadLinkEl) {
|
|
763
1414
|
const showDownload = this.status === 'Error' && this.currentDownloadUrl !== null;
|
|
764
1415
|
this.downloadLinkEl.hidden = !showDownload;
|
|
765
1416
|
this.downloadLinkEl.href = showDownload ? this.currentDownloadUrl : '';
|
|
1417
|
+
this.downloadLinkEl.textContent = this.i18n.t('downloadJetpack');
|
|
766
1418
|
}
|
|
767
1419
|
if (this.controlCenterLinkEl) {
|
|
768
1420
|
this.controlCenterLinkEl.href = this.options.controlCenterUrl ?? DEFAULT_CONTROL_CENTER_URL;
|
|
1421
|
+
this.controlCenterLinkEl.textContent = this.i18n.t('controlCenter');
|
|
769
1422
|
}
|
|
770
|
-
if (this.
|
|
771
|
-
|
|
772
|
-
this.
|
|
773
|
-
|
|
774
|
-
|
|
1423
|
+
if (this.actionBtnEl) {
|
|
1424
|
+
this.actionBtnEl.hidden = false;
|
|
1425
|
+
if (this.status === 'Running') {
|
|
1426
|
+
this.actionBtnEl.setAttribute('data-jp-action', 'stop');
|
|
1427
|
+
this.actionBtnEl.disabled = this.stopping;
|
|
1428
|
+
this.actionBtnEl.textContent = this.stopping
|
|
1429
|
+
? this.i18n.t('stopping')
|
|
1430
|
+
: this.i18n.t('stop');
|
|
1431
|
+
}
|
|
1432
|
+
else {
|
|
1433
|
+
const hasLaunchHandler = typeof (this.options.onLaunch ?? this.options.onRelaunch) === 'function';
|
|
1434
|
+
this.actionBtnEl.setAttribute('data-jp-action', 'launch');
|
|
1435
|
+
this.actionBtnEl.disabled =
|
|
1436
|
+
this.status !== 'Stopped' || this.launching || !hasLaunchHandler;
|
|
1437
|
+
this.actionBtnEl.textContent = this.launching
|
|
1438
|
+
? this.i18n.t('launching')
|
|
1439
|
+
: this.i18n.t('launch');
|
|
1440
|
+
}
|
|
775
1441
|
}
|
|
776
|
-
if (this.
|
|
777
|
-
this.
|
|
778
|
-
|
|
1442
|
+
if (this.modalTitleEl) {
|
|
1443
|
+
this.modalTitleEl.textContent = this.options.stopConfirmTitle ?? this.i18n.t('modalTitle');
|
|
1444
|
+
}
|
|
1445
|
+
if (this.modalMessageEl) {
|
|
1446
|
+
this.modalMessageEl.textContent =
|
|
1447
|
+
this.options.stopConfirmMessage ?? this.i18n.t('modalMessage');
|
|
779
1448
|
}
|
|
780
1449
|
if (this.modalCancelBtnEl) {
|
|
1450
|
+
this.modalCancelBtnEl.textContent = this.i18n.t('modalCancel');
|
|
781
1451
|
this.modalCancelBtnEl.disabled = this.stopping;
|
|
782
1452
|
}
|
|
783
1453
|
if (this.modalConfirmBtnEl) {
|
|
1454
|
+
this.modalConfirmBtnEl.textContent = this.i18n.t('modalConfirm');
|
|
784
1455
|
this.modalConfirmBtnEl.disabled = this.stopping;
|
|
785
1456
|
}
|
|
1457
|
+
this.syncInstallBannerUi(resolvedName);
|
|
1458
|
+
}
|
|
1459
|
+
syncInstallBannerUi(resolvedName) {
|
|
1460
|
+
if (!this.installBannerHost)
|
|
1461
|
+
return;
|
|
1462
|
+
const appDisplayName = resolvedName ??
|
|
1463
|
+
(this.options.appName?.trim() || this.options.appId?.trim() || this.i18n.t('defaultAppName'));
|
|
1464
|
+
const visible = this.shouldShowInstallBanner();
|
|
1465
|
+
this.installBannerHost.hidden = !visible;
|
|
1466
|
+
this.installBannerHost.style.display = visible ? 'block' : 'none';
|
|
1467
|
+
this.installBannerHost.setAttribute('data-visible', visible ? 'true' : 'false');
|
|
1468
|
+
if (!visible) {
|
|
1469
|
+
this.detachInstallLayoutTracking();
|
|
1470
|
+
if (this.installArrowSvgEl) {
|
|
1471
|
+
this.installArrowSvgEl.hidden = true;
|
|
1472
|
+
}
|
|
1473
|
+
if (this.installBannerHost.parentNode) {
|
|
1474
|
+
this.installBannerHost.parentNode.removeChild(this.installBannerHost);
|
|
1475
|
+
}
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
const container = this.host?.parentNode;
|
|
1479
|
+
if (container && this.installBannerHost.parentNode !== container) {
|
|
1480
|
+
container.appendChild(this.installBannerHost);
|
|
1481
|
+
}
|
|
1482
|
+
const candidateUrl = this.resolveSafePosterCandidate();
|
|
1483
|
+
if (candidateUrl !== this.lastResolvedPosterUrl) {
|
|
1484
|
+
this.lastResolvedPosterUrl = candidateUrl;
|
|
1485
|
+
this.posterLoadFailed = false;
|
|
1486
|
+
}
|
|
1487
|
+
const usePosterImg = Boolean(candidateUrl && !this.posterLoadFailed);
|
|
1488
|
+
if (this.installPosterImgEl) {
|
|
1489
|
+
if (usePosterImg && candidateUrl) {
|
|
1490
|
+
if (this.installPosterImgEl.src !== candidateUrl) {
|
|
1491
|
+
this.installPosterImgEl.src = candidateUrl;
|
|
1492
|
+
}
|
|
1493
|
+
this.installPosterImgEl.alt = this.i18n.t('installPosterAlt', { appName: appDisplayName });
|
|
1494
|
+
this.installPosterImgEl.hidden = false;
|
|
1495
|
+
}
|
|
1496
|
+
else {
|
|
1497
|
+
this.installPosterImgEl.hidden = true;
|
|
1498
|
+
this.installPosterImgEl.removeAttribute('src');
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
if (this.installPosterFallbackEl) {
|
|
1502
|
+
this.installPosterFallbackEl.hidden = usePosterImg;
|
|
1503
|
+
}
|
|
1504
|
+
if (this.installPosterAppNameEl) {
|
|
1505
|
+
this.installPosterAppNameEl.textContent = appDisplayName;
|
|
1506
|
+
}
|
|
1507
|
+
if (this.installPosterPoweredEl) {
|
|
1508
|
+
this.installPosterPoweredEl.textContent = this.i18n.t('poweredBy');
|
|
1509
|
+
}
|
|
1510
|
+
if (this.installWaitTextEl) {
|
|
1511
|
+
this.installWaitTextEl.textContent = this.i18n.t('installWaitText');
|
|
1512
|
+
}
|
|
1513
|
+
const customMsg = typeof this.options.installBanner === 'object' && this.options.installBanner !== null
|
|
1514
|
+
? this.options.installBanner.message?.trim()
|
|
1515
|
+
: undefined;
|
|
1516
|
+
if (this.installMessageEl) {
|
|
1517
|
+
this.installMessageEl.textContent =
|
|
1518
|
+
customMsg && customMsg.length > 0
|
|
1519
|
+
? customMsg
|
|
1520
|
+
: this.i18n.t('installDefaultMessage', { appName: appDisplayName });
|
|
1521
|
+
}
|
|
1522
|
+
this.attachInstallLayoutTracking();
|
|
1523
|
+
this.scheduleInstallArrowUpdate();
|
|
1524
|
+
}
|
|
1525
|
+
attachInstallLayoutTracking() {
|
|
1526
|
+
if (this.layoutListenersAttached)
|
|
1527
|
+
return;
|
|
1528
|
+
this.layoutListenersAttached = true;
|
|
1529
|
+
if (typeof ResizeObserver === 'function' && !this.resizeObserver) {
|
|
1530
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
1531
|
+
this.scheduleInstallArrowUpdate();
|
|
1532
|
+
});
|
|
1533
|
+
if (this.headerEl)
|
|
1534
|
+
this.resizeObserver.observe(this.headerEl);
|
|
1535
|
+
if (this.installCardEl)
|
|
1536
|
+
this.resizeObserver.observe(this.installCardEl);
|
|
1537
|
+
if (this.downloadLinkEl)
|
|
1538
|
+
this.resizeObserver.observe(this.downloadLinkEl);
|
|
1539
|
+
}
|
|
1540
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
1541
|
+
this.windowLayoutHandler = () => {
|
|
1542
|
+
this.scheduleInstallArrowUpdate();
|
|
1543
|
+
};
|
|
1544
|
+
window.addEventListener('resize', this.windowLayoutHandler);
|
|
1545
|
+
window.addEventListener('scroll', this.windowLayoutHandler, true);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
detachInstallLayoutTracking() {
|
|
1549
|
+
this.layoutListenersAttached = false;
|
|
1550
|
+
if (this.arrowRafId !== null && typeof cancelAnimationFrame === 'function') {
|
|
1551
|
+
cancelAnimationFrame(this.arrowRafId);
|
|
1552
|
+
this.arrowRafId = null;
|
|
1553
|
+
}
|
|
1554
|
+
if (this.resizeObserver) {
|
|
1555
|
+
this.resizeObserver.disconnect();
|
|
1556
|
+
this.resizeObserver = null;
|
|
1557
|
+
}
|
|
1558
|
+
if (this.windowLayoutHandler &&
|
|
1559
|
+
typeof window !== 'undefined' &&
|
|
1560
|
+
typeof window.removeEventListener === 'function') {
|
|
1561
|
+
window.removeEventListener('resize', this.windowLayoutHandler);
|
|
1562
|
+
window.removeEventListener('scroll', this.windowLayoutHandler, true);
|
|
1563
|
+
}
|
|
1564
|
+
this.windowLayoutHandler = null;
|
|
1565
|
+
}
|
|
1566
|
+
scheduleInstallArrowUpdate() {
|
|
1567
|
+
this.updateInstallArrowGeometry();
|
|
1568
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
1569
|
+
if (this.arrowRafId !== null && typeof cancelAnimationFrame === 'function') {
|
|
1570
|
+
cancelAnimationFrame(this.arrowRafId);
|
|
1571
|
+
}
|
|
1572
|
+
this.arrowRafId = requestAnimationFrame(() => {
|
|
1573
|
+
this.arrowRafId = null;
|
|
1574
|
+
this.updateInstallArrowGeometry();
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
updateInstallArrowGeometry() {
|
|
1579
|
+
if (!this.shouldShowInstallBanner())
|
|
1580
|
+
return;
|
|
1581
|
+
const headerRect = this.headerEl && typeof this.headerEl.getBoundingClientRect === 'function'
|
|
1582
|
+
? this.headerEl.getBoundingClientRect()
|
|
1583
|
+
: null;
|
|
1584
|
+
const barBottom = headerRect && headerRect.bottom > 0 ? Math.ceil(headerRect.bottom) : 48;
|
|
1585
|
+
if (this.installBackdropEl) {
|
|
1586
|
+
this.installBackdropEl.style.setProperty?.('--jp-control-bar-bottom', `${barBottom}px`);
|
|
1587
|
+
}
|
|
1588
|
+
if (!this.installArrowSvgEl || !this.installArrowPathEl) {
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
const btnRect = this.downloadLinkEl &&
|
|
1592
|
+
!this.downloadLinkEl.hidden &&
|
|
1593
|
+
typeof this.downloadLinkEl.getBoundingClientRect === 'function'
|
|
1594
|
+
? this.downloadLinkEl.getBoundingClientRect()
|
|
1595
|
+
: null;
|
|
1596
|
+
const msgRect = this.installMessageBoxEl && typeof this.installMessageBoxEl.getBoundingClientRect === 'function'
|
|
1597
|
+
? this.installMessageBoxEl.getBoundingClientRect()
|
|
1598
|
+
: null;
|
|
1599
|
+
if (!btnRect ||
|
|
1600
|
+
!msgRect ||
|
|
1601
|
+
btnRect.width <= 0 ||
|
|
1602
|
+
btnRect.height <= 0 ||
|
|
1603
|
+
msgRect.width <= 0 ||
|
|
1604
|
+
msgRect.height <= 0) {
|
|
1605
|
+
this.installArrowSvgEl.hidden = true;
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
const vw = (typeof window !== 'undefined' && window.innerWidth) ||
|
|
1609
|
+
(typeof document !== 'undefined' && document.documentElement?.clientWidth) ||
|
|
1610
|
+
1024;
|
|
1611
|
+
const vh = (typeof window !== 'undefined' && window.innerHeight) ||
|
|
1612
|
+
(typeof document !== 'undefined' && document.documentElement?.clientHeight) ||
|
|
1613
|
+
768;
|
|
1614
|
+
const tx = clamp(btnRect.left + btnRect.width / 2, 16, vw - 16);
|
|
1615
|
+
const ty = Math.max(barBottom + 6, btnRect.bottom + 8);
|
|
1616
|
+
const hasRightRoom = vw - msgRect.right >= 56;
|
|
1617
|
+
const sx = hasRightRoom
|
|
1618
|
+
? msgRect.right + 12
|
|
1619
|
+
: clamp(msgRect.right - 24, 24, vw - 24);
|
|
1620
|
+
const sy = hasRightRoom
|
|
1621
|
+
? msgRect.top + msgRect.height * 0.45
|
|
1622
|
+
: msgRect.top - 8;
|
|
1623
|
+
if (sy <= ty + 20) {
|
|
1624
|
+
this.installArrowSvgEl.hidden = true;
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
const mx = clamp((sx + tx) / 2 + (hasRightRoom ? 44 : 28), 24, vw - 24);
|
|
1628
|
+
const my = (sy + ty) / 2;
|
|
1629
|
+
const c1x = clamp(sx + (hasRightRoom ? 68 : 36), 16, vw - 16);
|
|
1630
|
+
const c1y = sy - 10;
|
|
1631
|
+
const c2x = clamp(mx + 42, 16, vw - 16);
|
|
1632
|
+
const c2y = my + 34;
|
|
1633
|
+
const c3x = clamp(mx - 42, 16, vw - 16);
|
|
1634
|
+
const c3y = my - 34;
|
|
1635
|
+
const c4x = tx;
|
|
1636
|
+
const c4y = ty + 42;
|
|
1637
|
+
const pathData = `M ${sx.toFixed(1)} ${sy.toFixed(1)} ` +
|
|
1638
|
+
`C ${c1x.toFixed(1)} ${c1y.toFixed(1)}, ${c2x.toFixed(1)} ${c2y.toFixed(1)}, ${mx.toFixed(1)} ${my.toFixed(1)} ` +
|
|
1639
|
+
`C ${c3x.toFixed(1)} ${c3y.toFixed(1)}, ${c4x.toFixed(1)} ${c4y.toFixed(1)}, ${tx.toFixed(1)} ${ty.toFixed(1)}`;
|
|
1640
|
+
this.installArrowSvgEl.setAttribute('viewBox', `0 0 ${vw} ${vh}`);
|
|
1641
|
+
this.installArrowPathEl.setAttribute('d', pathData);
|
|
1642
|
+
this.installArrowSvgEl.hidden = false;
|
|
786
1643
|
}
|
|
787
1644
|
}
|
|
788
1645
|
//# sourceMappingURL=control-bar.js.map
|