@jsenv/plugin-toolbar 0.1.2 → 0.1.4

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.
Files changed (66) hide show
  1. package/dist/css/toolbar.css +683 -7
  2. package/dist/js/toolbar_core.js +1803 -8
  3. package/dist/js/toolbar_injector.js +4 -2
  4. package/dist/jsenv_plugin_toolbar.js +6 -3
  5. package/package.json +3 -3
  6. package/dist/css/document_execution_indicator.css +0 -87
  7. package/dist/css/globals.css +0 -75
  8. package/dist/css/server_indicator.css +0 -83
  9. package/dist/css/theme_light.css +0 -110
  10. package/dist/css/toolbar_menu_overflow.css +0 -59
  11. package/dist/css/toolbar_settings.css +0 -202
  12. package/dist/css/tooltips.css +0 -67
  13. package/dist/js/animation.js +0 -282
  14. package/dist/js/animation_actions.js +0 -7
  15. package/dist/js/animation_effects.js +0 -10
  16. package/dist/js/animation_signals.js +0 -4
  17. package/dist/js/changes_actions.js +0 -7
  18. package/dist/js/changes_indicator.js +0 -57
  19. package/dist/js/changes_signals.js +0 -2
  20. package/dist/js/document_execution_indicator.js +0 -62
  21. package/dist/js/document_index_link.js +0 -4
  22. package/dist/js/dom.js +0 -48
  23. package/dist/js/execution_actions.js +0 -46
  24. package/dist/js/execution_effects.js +0 -16
  25. package/dist/js/execution_signals.js +0 -17
  26. package/dist/js/hooks.mjs +0 -185
  27. package/dist/js/iframe_to_parent_href.js +0 -10
  28. package/dist/js/notification_actions.js +0 -60
  29. package/dist/js/notification_context.js +0 -1
  30. package/dist/js/notification_effects.js +0 -9
  31. package/dist/js/notification_signals.js +0 -5
  32. package/dist/js/parent_window_actions.js +0 -39
  33. package/dist/js/parent_window_context.js +0 -6
  34. package/dist/js/parent_window_effects.js +0 -15
  35. package/dist/js/parent_window_signals.js +0 -25
  36. package/dist/js/preact.mjs +0 -316
  37. package/dist/js/responsive.js +0 -104
  38. package/dist/js/server_actions.js +0 -7
  39. package/dist/js/server_effects.js +0 -9
  40. package/dist/js/server_indicator.js +0 -52
  41. package/dist/js/server_signals.js +0 -10
  42. package/dist/js/settings_actions.js +0 -7
  43. package/dist/js/settings_signals.js +0 -2
  44. package/dist/js/signals-core.mjs +0 -339
  45. package/dist/js/signals.mjs +0 -202
  46. package/dist/js/theme_actions.js +0 -7
  47. package/dist/js/theme_effects.js +0 -6
  48. package/dist/js/theme_signals.js +0 -4
  49. package/dist/js/toolbar_animation_setting.js +0 -21
  50. package/dist/js/toolbar_autoreload_setting.js +0 -67
  51. package/dist/js/toolbar_close_button.js +0 -14
  52. package/dist/js/toolbar_menu_overflow.js +0 -81
  53. package/dist/js/toolbar_notification_setting.js +0 -72
  54. package/dist/js/toolbar_open_actions.js +0 -7
  55. package/dist/js/toolbar_open_effects.js +0 -4
  56. package/dist/js/toolbar_open_signals.js +0 -4
  57. package/dist/js/toolbar_opening.js +0 -65
  58. package/dist/js/toolbar_overlay.js +0 -69
  59. package/dist/js/toolbar_settings.js +0 -44
  60. package/dist/js/toolbar_state_context.js +0 -1
  61. package/dist/js/toolbar_state_effects.js +0 -8
  62. package/dist/js/toolbar_state_signals.js +0 -17
  63. package/dist/js/toolbar_theme_setting.js +0 -13
  64. package/dist/js/toolbar_ui.js +0 -20
  65. package/dist/js/tooltip_actions.js +0 -6
  66. package/dist/js/variant.js +0 -53
@@ -1,8 +1,1803 @@
1
- import "./animation_effects.js";
2
- import "./execution_effects.js";
3
- import "./notification_effects.js";
4
- import "./parent_window_effects.js";
5
- import "./server_effects.js";
6
- import "./theme_effects.js";
7
- import "./toolbar_open_effects.js";
8
- import "./toolbar_state_effects.js";
1
+ var l$2;
2
+ l$2 = {
3
+ __e: function (n, l, u, i) {
4
+ for (var t, o, r; l = l.__;) if ((t = l.__c) && !t.__) try {
5
+ if ((o = t.constructor) && null != o.getDerivedStateFromError && (t.setState(o.getDerivedStateFromError(n)), r = t.__d), null != t.componentDidCatch && (t.componentDidCatch(n, i || {}), r = t.__d), r) return t.__E = t;
6
+ } catch (l) {
7
+ n = l;
8
+ }
9
+ throw n;
10
+ }
11
+ };
12
+
13
+ var t$1,
14
+ r$1,
15
+ u$1,
16
+ i$1,
17
+ o$1 = 0,
18
+ f$1 = [],
19
+ c$2 = [],
20
+ e$1 = l$2.__b,
21
+ a$2 = l$2.__r,
22
+ v$1 = l$2.diffed,
23
+ l$1 = l$2.__c,
24
+ m = l$2.unmount;
25
+ function d$2(t, u) {
26
+ l$2.__h && l$2.__h(r$1, t, o$1 || u), o$1 = 0;
27
+ var i = r$1.__H || (r$1.__H = {
28
+ __: [],
29
+ __h: []
30
+ });
31
+ return t >= i.__.length && i.__.push({
32
+ __V: c$2
33
+ }), i.__[t];
34
+ }
35
+ function F(n, r) {
36
+ var u = d$2(t$1++, 7);
37
+ return z(u.__H, r) ? (u.__V = n(), u.i = r, u.__h = n, u.__V) : u.__;
38
+ }
39
+ function b$1() {
40
+ for (var t; t = f$1.shift();) if (t.__P && t.__H) try {
41
+ t.__H.__h.forEach(k), t.__H.__h.forEach(w$1), t.__H.__h = [];
42
+ } catch (r) {
43
+ t.__H.__h = [], l$2.__e(r, t.__v);
44
+ }
45
+ }
46
+ l$2.__b = function (n) {
47
+ r$1 = null, e$1 && e$1(n);
48
+ }, l$2.__r = function (n) {
49
+ a$2 && a$2(n), t$1 = 0;
50
+ var i = (r$1 = n.__c).__H;
51
+ i && (u$1 === r$1 ? (i.__h = [], r$1.__h = [], i.__.forEach(function (n) {
52
+ n.__N && (n.__ = n.__N), n.__V = c$2, n.__N = n.i = void 0;
53
+ })) : (i.__h.forEach(k), i.__h.forEach(w$1), i.__h = [])), u$1 = r$1;
54
+ }, l$2.diffed = function (t) {
55
+ v$1 && v$1(t);
56
+ var o = t.__c;
57
+ o && o.__H && (o.__H.__h.length && (1 !== f$1.push(o) && i$1 === l$2.requestAnimationFrame || ((i$1 = l$2.requestAnimationFrame) || j)(b$1)), o.__H.__.forEach(function (n) {
58
+ n.i && (n.__H = n.i), n.__V !== c$2 && (n.__ = n.__V), n.i = void 0, n.__V = c$2;
59
+ })), u$1 = r$1 = null;
60
+ }, l$2.__c = function (t, r) {
61
+ r.some(function (t) {
62
+ try {
63
+ t.__h.forEach(k), t.__h = t.__h.filter(function (n) {
64
+ return !n.__ || w$1(n);
65
+ });
66
+ } catch (u) {
67
+ r.some(function (n) {
68
+ n.__h && (n.__h = []);
69
+ }), r = [], l$2.__e(u, t.__v);
70
+ }
71
+ }), l$1 && l$1(t, r);
72
+ }, l$2.unmount = function (t) {
73
+ m && m(t);
74
+ var r,
75
+ u = t.__c;
76
+ u && u.__H && (u.__H.__.forEach(function (n) {
77
+ try {
78
+ k(n);
79
+ } catch (n) {
80
+ r = n;
81
+ }
82
+ }), u.__H = void 0, r && l$2.__e(r, u.__v));
83
+ };
84
+ var g$1 = "function" == typeof requestAnimationFrame;
85
+ function j(n) {
86
+ var t,
87
+ r = function () {
88
+ clearTimeout(u), g$1 && cancelAnimationFrame(t), setTimeout(n);
89
+ },
90
+ u = setTimeout(r, 100);
91
+ g$1 && (t = requestAnimationFrame(r));
92
+ }
93
+ function k(n) {
94
+ var t = r$1,
95
+ u = n.__c;
96
+ "function" == typeof u && (n.__c = void 0, u()), r$1 = t;
97
+ }
98
+ function w$1(n) {
99
+ var t = r$1;
100
+ n.__c = n.__(), r$1 = t;
101
+ }
102
+ function z(n, t) {
103
+ return !n || n.length !== t.length || t.some(function (t, r) {
104
+ return t !== n[r];
105
+ });
106
+ }
107
+
108
+ function i() {
109
+ throw new Error("Cycle detected");
110
+ }
111
+ function t() {
112
+ if (h$1 > 1) {
113
+ h$1--;
114
+ return;
115
+ }
116
+ let i,
117
+ t = !1;
118
+ while (void 0 !== n) {
119
+ let s = n;
120
+ n = void 0;
121
+ f++;
122
+ while (void 0 !== s) {
123
+ const o = s.o;
124
+ s.o = void 0;
125
+ s.f &= -3;
126
+ if (!(8 & s.f) && v(s)) try {
127
+ s.c();
128
+ } catch (s) {
129
+ if (!t) {
130
+ i = s;
131
+ t = !0;
132
+ }
133
+ }
134
+ s = o;
135
+ }
136
+ }
137
+ f = 0;
138
+ h$1--;
139
+ if (t) throw i;
140
+ }
141
+ let o,
142
+ n,
143
+ h$1 = 0,
144
+ f = 0,
145
+ r = 0;
146
+ function e(i) {
147
+ if (void 0 === o) return;
148
+ let t = i.n;
149
+ if (void 0 === t || t.t !== o) {
150
+ t = {
151
+ i: 0,
152
+ S: i,
153
+ p: o.s,
154
+ n: void 0,
155
+ t: o,
156
+ e: void 0,
157
+ x: void 0,
158
+ r: t
159
+ };
160
+ if (void 0 !== o.s) o.s.n = t;
161
+ o.s = t;
162
+ i.n = t;
163
+ if (32 & o.f) i.S(t);
164
+ return t;
165
+ } else if (-1 === t.i) {
166
+ t.i = 0;
167
+ if (void 0 !== t.n) {
168
+ t.n.p = t.p;
169
+ if (void 0 !== t.p) t.p.n = t.n;
170
+ t.p = o.s;
171
+ t.n = void 0;
172
+ o.s.n = t;
173
+ o.s = t;
174
+ }
175
+ return t;
176
+ }
177
+ }
178
+ function c$1(i) {
179
+ this.v = i;
180
+ this.i = 0;
181
+ this.n = void 0;
182
+ this.t = void 0;
183
+ }
184
+ c$1.prototype.h = function () {
185
+ return !0;
186
+ };
187
+ c$1.prototype.S = function (i) {
188
+ if (this.t !== i && void 0 === i.e) {
189
+ i.x = this.t;
190
+ if (void 0 !== this.t) this.t.e = i;
191
+ this.t = i;
192
+ }
193
+ };
194
+ c$1.prototype.U = function (i) {
195
+ if (void 0 !== this.t) {
196
+ const t = i.e,
197
+ s = i.x;
198
+ if (void 0 !== t) {
199
+ t.x = s;
200
+ i.e = void 0;
201
+ }
202
+ if (void 0 !== s) {
203
+ s.e = t;
204
+ i.x = void 0;
205
+ }
206
+ if (i === this.t) this.t = s;
207
+ }
208
+ };
209
+ c$1.prototype.subscribe = function (i) {
210
+ const t = this;
211
+ return p$1(function () {
212
+ const s = t.value,
213
+ o = 32 & this.f;
214
+ this.f &= -33;
215
+ try {
216
+ i(s);
217
+ } finally {
218
+ this.f |= o;
219
+ }
220
+ });
221
+ };
222
+ c$1.prototype.valueOf = function () {
223
+ return this.value;
224
+ };
225
+ c$1.prototype.toString = function () {
226
+ return this.value + "";
227
+ };
228
+ c$1.prototype.peek = function () {
229
+ return this.v;
230
+ };
231
+ Object.defineProperty(c$1.prototype, "value", {
232
+ get() {
233
+ const i = e(this);
234
+ if (void 0 !== i) i.i = this.i;
235
+ return this.v;
236
+ },
237
+ set(s) {
238
+ if (s !== this.v) {
239
+ if (f > 100) i();
240
+ this.v = s;
241
+ this.i++;
242
+ r++;
243
+ h$1++;
244
+ try {
245
+ for (let i = this.t; void 0 !== i; i = i.x) i.t.N();
246
+ } finally {
247
+ t();
248
+ }
249
+ }
250
+ }
251
+ });
252
+ function u(i) {
253
+ return new c$1(i);
254
+ }
255
+ function v(i) {
256
+ for (let t = i.s; void 0 !== t; t = t.n) if (t.S.i !== t.i || !t.S.h() || t.S.i !== t.i) return !0;
257
+ return !1;
258
+ }
259
+ function d$1(i) {
260
+ for (let t = i.s; void 0 !== t; t = t.n) {
261
+ const s = t.S.n;
262
+ if (void 0 !== s) t.r = s;
263
+ t.S.n = t;
264
+ t.i = -1;
265
+ if (void 0 === t.n) {
266
+ i.s = t;
267
+ break;
268
+ }
269
+ }
270
+ }
271
+ function l(i) {
272
+ let t,
273
+ s = i.s;
274
+ while (void 0 !== s) {
275
+ const i = s.p;
276
+ if (-1 === s.i) {
277
+ s.S.U(s);
278
+ if (void 0 !== i) i.n = s.n;
279
+ if (void 0 !== s.n) s.n.p = i;
280
+ } else t = s;
281
+ s.S.n = s.r;
282
+ if (void 0 !== s.r) s.r = void 0;
283
+ s = i;
284
+ }
285
+ i.s = t;
286
+ }
287
+ function a$1(i) {
288
+ c$1.call(this, void 0);
289
+ this.x = i;
290
+ this.s = void 0;
291
+ this.g = r - 1;
292
+ this.f = 4;
293
+ }
294
+ (a$1.prototype = new c$1()).h = function () {
295
+ this.f &= -3;
296
+ if (1 & this.f) return !1;
297
+ if (32 == (36 & this.f)) return !0;
298
+ this.f &= -5;
299
+ if (this.g === r) return !0;
300
+ this.g = r;
301
+ this.f |= 1;
302
+ if (this.i > 0 && !v(this)) {
303
+ this.f &= -2;
304
+ return !0;
305
+ }
306
+ const i = o;
307
+ try {
308
+ d$1(this);
309
+ o = this;
310
+ const i = this.x();
311
+ if (16 & this.f || this.v !== i || 0 === this.i) {
312
+ this.v = i;
313
+ this.f &= -17;
314
+ this.i++;
315
+ }
316
+ } catch (i) {
317
+ this.v = i;
318
+ this.f |= 16;
319
+ this.i++;
320
+ }
321
+ o = i;
322
+ l(this);
323
+ this.f &= -2;
324
+ return !0;
325
+ };
326
+ a$1.prototype.S = function (i) {
327
+ if (void 0 === this.t) {
328
+ this.f |= 36;
329
+ for (let i = this.s; void 0 !== i; i = i.n) i.S.S(i);
330
+ }
331
+ c$1.prototype.S.call(this, i);
332
+ };
333
+ a$1.prototype.U = function (i) {
334
+ if (void 0 !== this.t) {
335
+ c$1.prototype.U.call(this, i);
336
+ if (void 0 === this.t) {
337
+ this.f &= -33;
338
+ for (let i = this.s; void 0 !== i; i = i.n) i.S.U(i);
339
+ }
340
+ }
341
+ };
342
+ a$1.prototype.N = function () {
343
+ if (!(2 & this.f)) {
344
+ this.f |= 6;
345
+ for (let i = this.t; void 0 !== i; i = i.x) i.t.N();
346
+ }
347
+ };
348
+ a$1.prototype.peek = function () {
349
+ if (!this.h()) i();
350
+ if (16 & this.f) throw this.v;
351
+ return this.v;
352
+ };
353
+ Object.defineProperty(a$1.prototype, "value", {
354
+ get() {
355
+ if (1 & this.f) i();
356
+ const t = e(this);
357
+ this.h();
358
+ if (void 0 !== t) t.i = this.i;
359
+ if (16 & this.f) throw this.v;
360
+ return this.v;
361
+ }
362
+ });
363
+ function w(i) {
364
+ return new a$1(i);
365
+ }
366
+ function y(i) {
367
+ const s = i.u;
368
+ i.u = void 0;
369
+ if ("function" == typeof s) {
370
+ h$1++;
371
+ const n = o;
372
+ o = void 0;
373
+ try {
374
+ s();
375
+ } catch (t) {
376
+ i.f &= -2;
377
+ i.f |= 8;
378
+ _(i);
379
+ throw t;
380
+ } finally {
381
+ o = n;
382
+ t();
383
+ }
384
+ }
385
+ }
386
+ function _(i) {
387
+ for (let t = i.s; void 0 !== t; t = t.n) t.S.U(t);
388
+ i.x = void 0;
389
+ i.s = void 0;
390
+ y(i);
391
+ }
392
+ function g(i) {
393
+ if (o !== this) throw new Error("Out-of-order effect");
394
+ l(this);
395
+ o = i;
396
+ this.f &= -2;
397
+ if (8 & this.f) _(this);
398
+ t();
399
+ }
400
+ function b(i) {
401
+ this.x = i;
402
+ this.u = void 0;
403
+ this.s = void 0;
404
+ this.o = void 0;
405
+ this.f = 32;
406
+ }
407
+ b.prototype.c = function () {
408
+ const i = this.S();
409
+ try {
410
+ if (!(8 & this.f) && void 0 !== this.x) this.u = this.x();
411
+ } finally {
412
+ i();
413
+ }
414
+ };
415
+ b.prototype.S = function () {
416
+ if (1 & this.f) i();
417
+ this.f |= 1;
418
+ this.f &= -9;
419
+ y(this);
420
+ d$1(this);
421
+ h$1++;
422
+ const t = o;
423
+ o = this;
424
+ return g.bind(this, t);
425
+ };
426
+ b.prototype.N = function () {
427
+ if (!(2 & this.f)) {
428
+ this.f |= 2;
429
+ this.o = n;
430
+ n = this;
431
+ }
432
+ };
433
+ b.prototype.d = function () {
434
+ this.f |= 8;
435
+ if (!(1 & this.f)) _(this);
436
+ };
437
+ function p$1(i) {
438
+ const t = new b(i);
439
+ try {
440
+ t.c();
441
+ } catch (i) {
442
+ t.d();
443
+ throw i;
444
+ }
445
+ return t.d.bind(t);
446
+ }
447
+
448
+ function c(t, e) {
449
+ l$2[t] = e.bind(null, l$2[t] || (() => {}));
450
+ }
451
+ let a;
452
+ function d(t) {
453
+ if (a) a();
454
+ a = t && t.S();
455
+ }
456
+ function p({
457
+ data: t
458
+ }) {
459
+ const i = useSignal(t);
460
+ i.value = t;
461
+ const n = F(() => {
462
+ let t = this.__v;
463
+ while (t = t.__) if (t.__c) {
464
+ t.__c.__$f |= 4;
465
+ break;
466
+ }
467
+ this.__$u.c = () => {
468
+ this.base.data = n.peek();
469
+ };
470
+ return w(() => {
471
+ let t = i.value.value;
472
+ return 0 === t ? 0 : !0 === t ? "" : t || "";
473
+ });
474
+ }, []);
475
+ return n.value;
476
+ }
477
+ p.displayName = "_st";
478
+ Object.defineProperties(c$1.prototype, {
479
+ constructor: {
480
+ configurable: !0,
481
+ value: void 0
482
+ },
483
+ type: {
484
+ configurable: !0,
485
+ value: p
486
+ },
487
+ props: {
488
+ configurable: !0,
489
+ get() {
490
+ return {
491
+ data: this
492
+ };
493
+ }
494
+ },
495
+ __b: {
496
+ configurable: !0,
497
+ value: 1
498
+ }
499
+ });
500
+ c("__b", (t, i) => {
501
+ if ("string" == typeof i.type) {
502
+ let t,
503
+ e = i.props;
504
+ for (let n in e) {
505
+ if ("children" === n) continue;
506
+ let o = e[n];
507
+ if (o instanceof c$1) {
508
+ if (!t) i.__np = t = {};
509
+ t[n] = o;
510
+ e[n] = o.peek();
511
+ }
512
+ }
513
+ }
514
+ t(i);
515
+ });
516
+ c("__r", (t, i) => {
517
+ d();
518
+ let e,
519
+ n = i.__c;
520
+ if (n) {
521
+ n.__$f &= -2;
522
+ e = n.__$u;
523
+ if (void 0 === e) n.__$u = e = function (t) {
524
+ let i;
525
+ p$1(function () {
526
+ i = this;
527
+ });
528
+ i.c = () => {
529
+ n.__$f |= 1;
530
+ n.setState({});
531
+ };
532
+ return i;
533
+ }();
534
+ }
535
+ d(e);
536
+ t(i);
537
+ });
538
+ c("__e", (t, i, e, n) => {
539
+ d();
540
+ t(i, e, n);
541
+ });
542
+ c("diffed", (t, i) => {
543
+ d();
544
+ let e;
545
+ if ("string" == typeof i.type && (e = i.__e)) {
546
+ let t = i.__np,
547
+ n = i.props;
548
+ if (t) {
549
+ let i = e.U;
550
+ if (i) for (let e in i) {
551
+ let n = i[e];
552
+ if (void 0 !== n && !(e in t)) {
553
+ n.d();
554
+ i[e] = void 0;
555
+ }
556
+ } else {
557
+ i = {};
558
+ e.U = i;
559
+ }
560
+ for (let o in t) {
561
+ let r = i[o],
562
+ f = t[o];
563
+ if (void 0 === r) {
564
+ r = h(e, o, f, n);
565
+ i[o] = r;
566
+ } else r.o(f, n);
567
+ }
568
+ }
569
+ }
570
+ t(i);
571
+ });
572
+ function h(t, i, e, n) {
573
+ const o = i in t && void 0 === t.ownerSVGElement,
574
+ r = u(e);
575
+ return {
576
+ o: (t, i) => {
577
+ r.value = t;
578
+ n = i;
579
+ },
580
+ d: p$1(() => {
581
+ const e = r.value.value;
582
+ if (n[i] !== e) {
583
+ n[i] = e;
584
+ if (o) t[i] = e;else if (e) t.setAttribute(i, e);else t.removeAttribute(i);
585
+ }
586
+ })
587
+ };
588
+ }
589
+ c("unmount", (t, i) => {
590
+ if ("string" == typeof i.type) {
591
+ let t = i.__e;
592
+ if (t) {
593
+ const i = t.U;
594
+ if (i) {
595
+ t.U = void 0;
596
+ for (let t in i) {
597
+ let e = i[t];
598
+ if (e) e.d();
599
+ }
600
+ }
601
+ }
602
+ } else {
603
+ let t = i.__c;
604
+ if (t) {
605
+ const i = t.__$u;
606
+ if (i) {
607
+ t.__$u = void 0;
608
+ i.d();
609
+ }
610
+ }
611
+ }
612
+ t(i);
613
+ });
614
+ c("__h", (t, i, e, n) => {
615
+ if (n < 3) i.__$f |= 2;
616
+ t(i, e, n);
617
+ });
618
+ function useSignal(t) {
619
+ return F(() => u(t), []);
620
+ }
621
+
622
+ const paramsFromParentWindow = {};
623
+ const searchParams = new URLSearchParams(window.location.search);
624
+ searchParams.forEach((value, key) => {
625
+ paramsFromParentWindow[key] = value === "" ? true : value;
626
+ });
627
+ const parentWindowReloader = window.parent.__reloader__;
628
+
629
+ const stateFromLocalStorage = localStorage.hasOwnProperty("jsenv_toolbar") ? JSON.parse(localStorage.getItem("jsenv_toolbar")) : {};
630
+
631
+ const animationsEnabledSignal = u(typeof stateFromLocalStorage.animationsEnabled === "boolean" ? stateFromLocalStorage.animationsEnabled : typeof paramsFromParentWindow.animationsEnabled === "boolean" ? paramsFromParentWindow.animationsEnabled : false);
632
+
633
+ p$1(() => {
634
+ const animationsEnabled = animationsEnabledSignal.value;
635
+ if (animationsEnabled) {
636
+ document.documentElement.removeAttribute("data-animation-disabled");
637
+ } else {
638
+ document.documentElement.setAttribute("data-animation-disabled", "");
639
+ }
640
+ });
641
+
642
+ const executionTooltipOpenedSignal = u(false);
643
+ const executionSignal = u({
644
+ status: "running"
645
+ });
646
+ const previousExecutionSignal = u(sessionStorage.hasOwnProperty(window.location.href) ? JSON.parse(sessionStorage.getItem(window.location.href)) : null);
647
+ window.parent.__supervisor__.getDocumentExecutionResult().then(({
648
+ status,
649
+ startTime,
650
+ endTime
651
+ }) => {
652
+ executionSignal.value = {
653
+ status,
654
+ startTime,
655
+ endTime
656
+ };
657
+ });
658
+
659
+ const notificationAPIDetected = typeof window.Notification === "function";
660
+
661
+ const notificationsEnabledSignal = u(typeof stateFromLocalStorage.notificationsEnabled === "boolean" ? stateFromLocalStorage.notificationsEnabled : typeof paramsFromParentWindow.notificationsEnabled === "boolean" ? paramsFromParentWindow.notificationsEnabled : false);
662
+ const notificationPermissionSignal = u(Notification.permission);
663
+
664
+ const enableNotifications = () => {
665
+ notificationsEnabledSignal.value = true;
666
+ };
667
+ const disableNotifications = () => {
668
+ notificationsEnabledSignal.value = false;
669
+ };
670
+ const arrayOfOpenedNotifications = [];
671
+ const notify = notificationAPIDetected ? async (title, {
672
+ clickToFocus = false,
673
+ clickToClose = false,
674
+ ...options
675
+ } = {}) => {
676
+ const notificationsEnabled = notificationsEnabledSignal.value;
677
+ if (!notificationsEnabled) {
678
+ return null;
679
+ }
680
+ if (Notification.permission !== "granted") {
681
+ return null;
682
+ }
683
+ const notification = new Notification(title, options);
684
+ arrayOfOpenedNotifications.push(notification);
685
+ notification.onclick = () => {
686
+ // but if the user navigated inbetween
687
+ // focusing window will show something else
688
+ // in that case it could be great to do something
689
+ // maybe like showing a message saying this execution
690
+ // is no longer visible
691
+ // we could also navigauate to this file execution but
692
+ // there is no guarantee re-executing the file would give same output
693
+ // and it would also trigger an other notification
694
+ if (clickToFocus) window.focus();
695
+ if (clickToClose) notification.close();
696
+ };
697
+ notification.onclose = () => {
698
+ const index = arrayOfOpenedNotifications.indexOf(notification);
699
+ if (index > -1) {
700
+ arrayOfOpenedNotifications.splice(index, 1);
701
+ }
702
+ };
703
+ return notification;
704
+ } : () => {};
705
+ const closeAllNotifications = () => {
706
+ // slice because arrayOfOpenedNotifications can be mutated while looping
707
+ arrayOfOpenedNotifications.slice().forEach(notification => {
708
+ notification.close();
709
+ });
710
+ };
711
+ let requestPromise;
712
+ const requestPermission = notificationAPIDetected ? async () => {
713
+ if (requestPromise) {
714
+ await requestPromise;
715
+ return;
716
+ }
717
+ requestPromise = Notification.requestPermission();
718
+ await requestPromise;
719
+ requestPromise = undefined;
720
+ notificationPermissionSignal.value = Notification.permission;
721
+ } : () => Promise.resolve();
722
+
723
+ const openExecutionTooltip = () => {
724
+ executionTooltipOpenedSignal.value = true;
725
+ };
726
+ const closeExecutionTooltip = () => {
727
+ executionTooltipOpenedSignal.value = false;
728
+ };
729
+ const notifyExecutionResult = (execution, previousExecution) => {
730
+ const executedFileRelativeUrl = window.location.href;
731
+ const notificationOptions = {
732
+ lang: "en",
733
+ icon: getFaviconHref(),
734
+ clickToFocus: true,
735
+ clickToClose: true
736
+ };
737
+ if (execution.status === "errored") {
738
+ if (previousExecution) {
739
+ if (previousExecution.status === "completed") {
740
+ notify("Broken", {
741
+ ...notificationOptions,
742
+ body: `${executedFileRelativeUrl} execution now failing.`
743
+ });
744
+ } else {
745
+ notify("Still failing", {
746
+ ...notificationOptions,
747
+ body: `${executedFileRelativeUrl} execution still failing.`
748
+ });
749
+ }
750
+ } else {
751
+ notify("Failing", {
752
+ ...notificationOptions,
753
+ body: `${executedFileRelativeUrl} execution failed.`
754
+ });
755
+ }
756
+ } else if (previousExecution && previousExecution.status === "errored") {
757
+ notify("Fixed", {
758
+ ...notificationOptions,
759
+ body: `${executedFileRelativeUrl} execution fixed.`
760
+ });
761
+ }
762
+ };
763
+ const getFaviconHref = () => {
764
+ const link = document.querySelector('link[rel="icon"]');
765
+ return link ? link.href : undefined;
766
+ };
767
+
768
+ p$1(() => {
769
+ const execution = executionSignal.value;
770
+ if (execution) {
771
+ sessionStorage.setItem(window.location.href, JSON.stringify(execution));
772
+ }
773
+ });
774
+ p$1(() => {
775
+ const execution = executionSignal.value;
776
+ const previousExecution = previousExecutionSignal.value;
777
+ if (execution) {
778
+ notifyExecutionResult(execution, previousExecution);
779
+ }
780
+ });
781
+
782
+ p$1(() => {
783
+ const notificationsEnabled = notificationsEnabledSignal.value;
784
+ if (!notificationsEnabled) {
785
+ closeAllNotifications();
786
+ }
787
+ });
788
+
789
+ const sendEventToParent = (name, data) => {
790
+ window.parent.postMessage({
791
+ __jsenv__: {
792
+ event: name,
793
+ data
794
+ }
795
+ }, "*");
796
+ };
797
+ const addExternalCommandCallback = (command, callback) => {
798
+ const messageEventCallback = messageEvent => {
799
+ const {
800
+ data
801
+ } = messageEvent;
802
+ if (typeof data !== "object") {
803
+ return;
804
+ }
805
+ const {
806
+ __jsenv__
807
+ } = data;
808
+ if (!__jsenv__) {
809
+ return;
810
+ }
811
+ if (__jsenv__.command !== command) {
812
+ return;
813
+ }
814
+ callback(...__jsenv__.args);
815
+ };
816
+ window.addEventListener("message", messageEventCallback);
817
+ return () => {
818
+ window.removeEventListener("message", messageEventCallback);
819
+ };
820
+ };
821
+ const enableAutoreload = () => {
822
+ parentWindowReloader.autoreload.enable();
823
+ };
824
+ const disableAutoreload = () => {
825
+ parentWindowReloader.autoreload.disable();
826
+ };
827
+
828
+ const serverTooltipOpenedSignal = u(false);
829
+ const serverConnectionSignal = u("default");
830
+ const serverEvents$1 = window.__server_events__;
831
+ if (serverEvents$1) {
832
+ serverEvents$1.readyState.onchange = () => {
833
+ serverConnectionSignal.value = serverEvents$1.readyState.value;
834
+ };
835
+ serverConnectionSignal.value = serverEvents$1.readyState.value;
836
+ }
837
+
838
+ const openServerTooltip = () => {
839
+ serverTooltipOpenedSignal.value = true;
840
+ };
841
+ const closeServerTooltip = () => {
842
+ serverTooltipOpenedSignal.value = false;
843
+ };
844
+
845
+ const closeAllTooltips = () => {
846
+ closeExecutionTooltip();
847
+ closeServerTooltip();
848
+ };
849
+
850
+ const openedSignal = u(typeof stateFromLocalStorage.opened === "boolean" ? stateFromLocalStorage.opened : typeof paramsFromParentWindow.opened === "boolean" ? paramsFromParentWindow.opened : false);
851
+
852
+ const getToolbarIframe = () => {
853
+ const iframes = Array.from(window.parent.document.querySelectorAll("iframe"));
854
+ return iframes.find(iframe => iframe.contentWindow === window);
855
+ };
856
+ const forceHideElement = element => {
857
+ element.setAttribute("data-force-hide", "");
858
+ };
859
+ const removeForceHideElement = element => {
860
+ element.removeAttribute("data-force-hide");
861
+ };
862
+ const setStyles = (element, styles) => {
863
+ const elementStyle = element.style;
864
+ const restoreStyles = Object.keys(styles).map(styleName => {
865
+ let restore;
866
+ if (styleName in elementStyle) {
867
+ const currentStyle = elementStyle[styleName];
868
+ restore = () => {
869
+ elementStyle[styleName] = currentStyle;
870
+ };
871
+ } else {
872
+ restore = () => {
873
+ delete elementStyle[styleName];
874
+ };
875
+ }
876
+ elementStyle[styleName] = styles[styleName];
877
+ return restore;
878
+ });
879
+ return () => {
880
+ restoreStyles.forEach(restore => restore());
881
+ };
882
+ };
883
+ const activateToolbarSection = element => {
884
+ element.setAttribute("data-active", "");
885
+ };
886
+ const deactivateToolbarSection = element => {
887
+ element.removeAttribute("data-active");
888
+ };
889
+
890
+ const startJavaScriptAnimation = ({
891
+ duration = 300,
892
+ timingFunction = t => t,
893
+ onProgress = () => {},
894
+ onCancel = () => {},
895
+ onComplete = () => {}
896
+ }) => {
897
+ if (isNaN(duration)) {
898
+ // console.warn(`duration must be a number, received ${duration}`)
899
+ return () => {};
900
+ }
901
+ duration = parseInt(duration, 10);
902
+ const startMs = performance.now();
903
+ let currentRequestAnimationFrameId;
904
+ let done = false;
905
+ let rawProgress = 0;
906
+ let progress = 0;
907
+ const handler = () => {
908
+ currentRequestAnimationFrameId = null;
909
+ const nowMs = performance.now();
910
+ rawProgress = Math.min((nowMs - startMs) / duration, 1);
911
+ progress = timingFunction(rawProgress);
912
+ done = rawProgress === 1;
913
+ onProgress({
914
+ done,
915
+ rawProgress,
916
+ progress
917
+ });
918
+ if (done) {
919
+ onComplete();
920
+ } else {
921
+ currentRequestAnimationFrameId = window.requestAnimationFrame(handler);
922
+ }
923
+ };
924
+ handler();
925
+ const stop = () => {
926
+ if (currentRequestAnimationFrameId) {
927
+ window.cancelAnimationFrame(currentRequestAnimationFrameId);
928
+ currentRequestAnimationFrameId = null;
929
+ }
930
+ if (!done) {
931
+ done = true;
932
+ onCancel({
933
+ rawProgress,
934
+ progress
935
+ });
936
+ }
937
+ };
938
+ return stop;
939
+ };
940
+
941
+ const initToolbarOpening = () => {
942
+ p$1(() => {
943
+ const opened = openedSignal.value;
944
+ if (opened) {
945
+ showToolbar();
946
+ } else {
947
+ hideToolbar();
948
+ }
949
+ });
950
+ };
951
+ let restoreToolbarIframeParentStyles = () => {};
952
+ let restoreToolbarIframeStyles = () => {};
953
+ const hideToolbar = () => {
954
+ closeAllTooltips();
955
+ restoreToolbarIframeParentStyles();
956
+ restoreToolbarIframeStyles();
957
+ document.documentElement.removeAttribute("data-toolbar-visible");
958
+ };
959
+
960
+ // (by the way it might be cool to have the toolbar auto show when)
961
+ // it has something to say (being disconnected from server)
962
+ const showToolbar = () => {
963
+ const animationsEnabled = animationsEnabledSignal.peek();
964
+ document.documentElement.setAttribute("data-toolbar-visible", "");
965
+ const toolbarIframe = getToolbarIframe();
966
+ const toolbarIframeParent = toolbarIframe.parentNode;
967
+ const parentWindow = window.parent;
968
+ const parentDocumentElement = parentWindow.document.compatMode === "CSS1Compat" ? parentWindow.document.documentElement : parentWindow.document.body;
969
+ const scrollYMax = parentDocumentElement.scrollHeight - parentWindow.innerHeight;
970
+ const scrollY = parentDocumentElement.scrollTop;
971
+ const scrollYRemaining = scrollYMax - scrollY;
972
+ setStyles(toolbarIframeParent, {
973
+ "transition-property": "padding-bottom",
974
+ "transition-duration": animationsEnabled ? "300ms" : "0s"
975
+ });
976
+ // maybe we should use js animation here because we would not conflict with css
977
+ restoreToolbarIframeParentStyles = setStyles(toolbarIframeParent, {
978
+ "scroll-padding-bottom": "40px",
979
+ // same here we should add 40px
980
+ "padding-bottom": "40px" // if there is already one we should add 40px
981
+ });
982
+
983
+ restoreToolbarIframeStyles = setStyles(toolbarIframe, {
984
+ height: "40px",
985
+ visibility: "visible"
986
+ });
987
+ if (scrollYRemaining < 40 && scrollYMax > 0) {
988
+ const scrollEnd = scrollY + 40;
989
+ startJavaScriptAnimation({
990
+ duration: 300,
991
+ onProgress: ({
992
+ progress
993
+ }) => {
994
+ const value = scrollY + (scrollEnd - scrollY) * progress;
995
+ parentDocumentElement.scrollTop = value;
996
+ }
997
+ });
998
+ }
999
+ };
1000
+
1001
+ const createHorizontalBreakpoint = breakpointValue => {
1002
+ return createBreakpoint(windowWidthMeasure, breakpointValue);
1003
+ };
1004
+ const createMeasure = ({
1005
+ compute,
1006
+ register
1007
+ }) => {
1008
+ let currentValue = compute();
1009
+ const get = () => compute();
1010
+ const changed = createSignal();
1011
+ let unregister = () => {};
1012
+ if (register) {
1013
+ unregister = register(() => {
1014
+ const value = compute();
1015
+ if (value !== currentValue) {
1016
+ const previousValue = value;
1017
+ currentValue = value;
1018
+ changed.notify(value, previousValue);
1019
+ }
1020
+ });
1021
+ }
1022
+ return {
1023
+ get,
1024
+ changed,
1025
+ unregister
1026
+ };
1027
+ };
1028
+ const createSignal = () => {
1029
+ const callbackArray = [];
1030
+ const listen = callback => {
1031
+ callbackArray.push(callback);
1032
+ return () => {
1033
+ const index = callbackArray.indexOf(callback);
1034
+ if (index > -1) {
1035
+ callbackArray.splice(index, 1);
1036
+ }
1037
+ };
1038
+ };
1039
+ const notify = (...args) => {
1040
+ callbackArray.slice().forEach(callback => {
1041
+ callback(...args);
1042
+ });
1043
+ };
1044
+ return {
1045
+ listen,
1046
+ notify
1047
+ };
1048
+ };
1049
+ const windowWidthMeasure = createMeasure({
1050
+ name: "window-width",
1051
+ compute: () => window.innerWidth,
1052
+ register: onchange => {
1053
+ window.addEventListener("resize", onchange);
1054
+ window.addEventListener("orientationchange", onchange);
1055
+ return () => {
1056
+ window.removeEventListener("resize", onchange);
1057
+ window.removeEventListener("orientationchange", onchange);
1058
+ };
1059
+ }
1060
+ });
1061
+ const createBreakpoint = (measure, breakpointValue) => {
1062
+ const getBreakpointState = () => {
1063
+ const value = measure.get();
1064
+ if (value < breakpointValue) {
1065
+ return "below";
1066
+ }
1067
+ if (value > breakpointValue) {
1068
+ return "above";
1069
+ }
1070
+ return "equals";
1071
+ };
1072
+ let currentBreakpointState = getBreakpointState();
1073
+ const isAbove = () => {
1074
+ return measure.get() > breakpointValue;
1075
+ };
1076
+ const isBelow = () => {
1077
+ return measure.get() < breakpointValue;
1078
+ };
1079
+ const breakpointChanged = createSignal();
1080
+ measure.changed.listen(() => {
1081
+ const breakpointState = getBreakpointState();
1082
+ if (breakpointState !== currentBreakpointState) {
1083
+ const breakpointStatePrevious = currentBreakpointState;
1084
+ currentBreakpointState = breakpointState;
1085
+ breakpointChanged.notify(breakpointState, breakpointStatePrevious);
1086
+ }
1087
+ });
1088
+ return {
1089
+ isAbove,
1090
+ isBelow,
1091
+ changed: breakpointChanged
1092
+ };
1093
+ };
1094
+
1095
+ // const windowScrollTop = createMeasure({
1096
+ // name: "window-scroll-top",
1097
+ // compute: () => window.scrollTop,
1098
+ // register: (onchange) => {
1099
+ // window.addEventListener("scroll", onchange)
1100
+ // return () => {
1101
+ // window.removeEventListener("scroll", onchange)
1102
+ // }
1103
+ // },
1104
+ // })
1105
+
1106
+ const WINDOW_SMALL_WIDTH = 420;
1107
+ const initToolbarMenuOverflow = () => {
1108
+ // apply responsive design on toolbar icons if needed + add listener on resize screen
1109
+ // ideally we should listen breakpoint once, for now restore toolbar
1110
+ const overflowMenuBreakpoint = createHorizontalBreakpoint(WINDOW_SMALL_WIDTH);
1111
+ const handleOverflowMenuBreakpoint = () => {
1112
+ responsiveToolbar(overflowMenuBreakpoint);
1113
+ };
1114
+ handleOverflowMenuBreakpoint();
1115
+ overflowMenuBreakpoint.changed.listen(handleOverflowMenuBreakpoint);
1116
+ document.querySelector("#menu_overflow_button").onclick = () => {
1117
+ if (overflowMenuIsOpened()) {
1118
+ closeOverflowMenu();
1119
+ } else {
1120
+ openOverflowMenu();
1121
+ }
1122
+ };
1123
+ };
1124
+ const responsiveToolbar = overflowMenuBreakpoint => {
1125
+ // close all tooltips in case opened
1126
+ closeAllTooltips();
1127
+ // close settings box in case opened
1128
+ deactivateToolbarSection(document.querySelector("#settings"));
1129
+ if (overflowMenuBreakpoint.isBelow()) {
1130
+ enableOverflow();
1131
+ } else {
1132
+ disableOverflow();
1133
+ }
1134
+ };
1135
+ let moves = [];
1136
+ const enableOverflow = () => {
1137
+ // move elements from toolbar to overflow menu
1138
+ const responsiveToolbarElements = document.querySelectorAll("[data-responsive-toolbar-element]");
1139
+ const overflowMenu = document.querySelector("#menu_overflow");
1140
+
1141
+ // keep a placeholder element to know where to move them back
1142
+ moves = Array.from(responsiveToolbarElements).map(element => {
1143
+ const placeholder = document.createElement("div");
1144
+ placeholder.style.display = "none";
1145
+ placeholder.setAttribute("data-placeholder", "");
1146
+ element.parentNode.replaceChild(placeholder, element);
1147
+ overflowMenu.appendChild(element);
1148
+ return {
1149
+ element,
1150
+ placeholder
1151
+ };
1152
+ });
1153
+ document.querySelector("#toolbar").setAttribute("data-menu-overflow-enabled", "");
1154
+ removeForceHideElement(document.querySelector("#menu_overflow_button"));
1155
+ };
1156
+ const disableOverflow = () => {
1157
+ // close overflow menu in case it's open & unselect toggleOverflowMenu button in case it's selected
1158
+ closeOverflowMenu();
1159
+ deactivateToolbarSection(document.querySelector("#menu_overflow"));
1160
+ moves.forEach(({
1161
+ element,
1162
+ placeholder
1163
+ }) => {
1164
+ placeholder.parentNode.replaceChild(element, placeholder);
1165
+ });
1166
+ moves = [];
1167
+ document.querySelector("#toolbar").removeAttribute("data-menu-overflow-enabled");
1168
+ forceHideElement(document.querySelector("#menu_overflow_button"));
1169
+ };
1170
+ const overflowMenuIsOpened = () => {
1171
+ const toolbar = document.querySelector("#toolbar");
1172
+ return toolbar.hasAttribute("data-menu-overflow-opened");
1173
+ };
1174
+ const openOverflowMenu = () => {
1175
+ const toolbar = document.querySelector("#toolbar");
1176
+ document.querySelector("#menu_overflow").setAttribute("data-animate", "");
1177
+ toolbar.setAttribute("data-menu-overflow-opened", "");
1178
+ };
1179
+ const closeOverflowMenu = () => {
1180
+ const toolbar = document.querySelector("#toolbar");
1181
+ toolbar.removeAttribute("data-menu-overflow-opened");
1182
+ document.querySelector("#menu_overflow").removeAttribute("data-animate");
1183
+ };
1184
+
1185
+ const settingsOpenedSignal = u(false);
1186
+
1187
+ const openSettings = () => {
1188
+ settingsOpenedSignal.value = true;
1189
+ };
1190
+ const closeSettings = () => {
1191
+ settingsOpenedSignal.value = false;
1192
+ };
1193
+
1194
+ const changesTooltipOpenedSignal = u(false);
1195
+
1196
+ const renderToolbarOverlay = () => {
1197
+ const toolbarOverlay = document.querySelector("#toolbar_overlay");
1198
+ toolbarOverlay.onclick = () => {
1199
+ closeAllTooltips();
1200
+ closeSettings();
1201
+ };
1202
+ p$1(() => {
1203
+ if (!window.parent) {
1204
+ // can happen while parent iframe reloads
1205
+ return;
1206
+ }
1207
+ const opened = openedSignal.value;
1208
+ const settingsOpened = settingsOpenedSignal.value;
1209
+ const executionTooltipOpened = executionTooltipOpenedSignal.value;
1210
+ const changesTooltipOpened = changesTooltipOpenedSignal.value;
1211
+ const serverTooltipOpened = serverTooltipOpenedSignal.value;
1212
+ if (!opened) {
1213
+ return;
1214
+ }
1215
+ if (settingsOpened || executionTooltipOpened || changesTooltipOpened || serverTooltipOpened) {
1216
+ enableIframeOverflowOnParentWindow();
1217
+ } else {
1218
+ disableIframeOverflowOnParentWindow();
1219
+ }
1220
+ });
1221
+ };
1222
+ const enableIframeOverflowOnParentWindow = () => {
1223
+ const iframe = getToolbarIframe();
1224
+ const transitionDuration = iframe.style.transitionDuration;
1225
+ setStyles(iframe, {
1226
+ "height": "100%",
1227
+ // we don't want to animate height transition
1228
+ // but if it was enabled, we'll restore it afterwards
1229
+ "transition-duration": "0ms"
1230
+ });
1231
+ if (transitionDuration) {
1232
+ setTimeout(() => {
1233
+ setStyles(iframe, {
1234
+ "transition-duration": transitionDuration
1235
+ });
1236
+ });
1237
+ }
1238
+ };
1239
+ const disableIframeOverflowOnParentWindow = () => {
1240
+ const iframe = getToolbarIframe();
1241
+ const transitionDuration = iframe.style.transitionDuration;
1242
+ setStyles(iframe, {
1243
+ "height": "40px",
1244
+ // we don't want to animate height transition
1245
+ // but if it was enabled, we'll restore it afterwards
1246
+ "transition-duration": "0ms"
1247
+ });
1248
+ if (transitionDuration) {
1249
+ setTimeout(() => {
1250
+ setStyles(iframe, {
1251
+ "transition-duration": transitionDuration
1252
+ });
1253
+ });
1254
+ }
1255
+ };
1256
+
1257
+ const setLinkHrefForParentWindow = (a, href) => {
1258
+ a.href = href;
1259
+ a.onclick = e => {
1260
+ if (e.ctrlKey || e.metaKey) {
1261
+ return;
1262
+ }
1263
+ e.preventDefault();
1264
+ window.parent.location.href = href;
1265
+ };
1266
+ };
1267
+
1268
+ const renderDocumentIndexLink = () => {
1269
+ setLinkHrefForParentWindow(document.querySelector("#document_index_link"), "/");
1270
+ };
1271
+
1272
+ const enableVariant = (rootNode, variables) => {
1273
+ const nodesNotMatching = Array.from(rootNode.querySelectorAll(`[${attributeIndicatingACondition}]`));
1274
+ nodesNotMatching.forEach(nodeNotMatching => {
1275
+ const conditionAttributeValue = nodeNotMatching.getAttribute(attributeIndicatingACondition);
1276
+ const matches = testCondition(conditionAttributeValue, variables);
1277
+ if (matches) {
1278
+ renameAttribute(nodeNotMatching, attributeIndicatingACondition, attributeIndicatingAMatch);
1279
+ }
1280
+ });
1281
+ const nodesMatching = Array.from(rootNode.querySelectorAll(`[${attributeIndicatingAMatch}]`));
1282
+ nodesMatching.forEach(nodeMatching => {
1283
+ const conditionAttributeValue = nodeMatching.getAttribute(attributeIndicatingAMatch);
1284
+ const matches = testCondition(conditionAttributeValue, variables);
1285
+ if (!matches) {
1286
+ renameAttribute(nodeMatching, attributeIndicatingAMatch, attributeIndicatingACondition);
1287
+ }
1288
+ });
1289
+ };
1290
+ const testCondition = (conditionAttributeValue, variables) => {
1291
+ const condition = parseCondition(conditionAttributeValue);
1292
+ return Object.keys(variables).some(key => {
1293
+ if (condition.key !== key) {
1294
+ return false;
1295
+ }
1296
+ // the condition do not specify a value, any value is ok
1297
+ if (condition.value === undefined) {
1298
+ return true;
1299
+ }
1300
+ if (condition.value === variables[key]) {
1301
+ return true;
1302
+ }
1303
+ return false;
1304
+ });
1305
+ };
1306
+ const parseCondition = conditionAttributeValue => {
1307
+ const colonIndex = conditionAttributeValue.indexOf(":");
1308
+ if (colonIndex === -1) {
1309
+ return {
1310
+ key: conditionAttributeValue,
1311
+ value: undefined
1312
+ };
1313
+ }
1314
+ return {
1315
+ key: conditionAttributeValue.slice(0, colonIndex),
1316
+ value: conditionAttributeValue.slice(colonIndex + 1)
1317
+ };
1318
+ };
1319
+ const attributeIndicatingACondition = `data-when`;
1320
+ const attributeIndicatingAMatch = `data-when-active`;
1321
+ const renameAttribute = (node, name, newName) => {
1322
+ node.setAttribute(newName, node.getAttribute(name));
1323
+ node.removeAttribute(name);
1324
+ };
1325
+
1326
+ const executionIndicator = document.querySelector("#document_execution_indicator");
1327
+ const renderDocumentExecutionIndicator = async () => {
1328
+ removeForceHideElement(document.querySelector("#document_execution_indicator"));
1329
+ p$1(() => {
1330
+ const execution = executionSignal.value;
1331
+ updateExecutionIndicator(execution);
1332
+ });
1333
+ p$1(() => {
1334
+ const executionTooltipOpened = executionTooltipOpenedSignal.value;
1335
+ if (executionTooltipOpened) {
1336
+ executionIndicator.setAttribute("data-tooltip-visible", "");
1337
+ } else {
1338
+ executionIndicator.removeAttribute("data-tooltip-visible");
1339
+ }
1340
+ });
1341
+ };
1342
+ const updateExecutionIndicator = ({
1343
+ status,
1344
+ startTime,
1345
+ endTime
1346
+ } = {}) => {
1347
+ enableVariant(executionIndicator, {
1348
+ execution: status
1349
+ });
1350
+ const variantNode = executionIndicator.querySelector("[data-when-active]");
1351
+ variantNode.querySelector("button").onclick = () => {
1352
+ const executionTooltipOpened = executionTooltipOpenedSignal.value;
1353
+ if (executionTooltipOpened) {
1354
+ closeExecutionTooltip();
1355
+ } else {
1356
+ openExecutionTooltip();
1357
+ }
1358
+ };
1359
+ variantNode.querySelector(".tooltip").textContent = computeText({
1360
+ status,
1361
+ startTime,
1362
+ endTime
1363
+ });
1364
+ };
1365
+
1366
+ // relative time: https://github.com/tc39/proposal-intl-relative-time/issues/118
1367
+ const computeText = ({
1368
+ status,
1369
+ startTime,
1370
+ endTime
1371
+ }) => {
1372
+ if (status === "completed") {
1373
+ return `Execution completed in ${endTime - startTime}ms`;
1374
+ }
1375
+ if (status === "errored") {
1376
+ return `Execution failed in ${endTime - startTime}ms`;
1377
+ }
1378
+ if (status === "running") {
1379
+ return "Executing...";
1380
+ }
1381
+ return "";
1382
+ };
1383
+
1384
+ const autoreloadEnabledSignal = u(false);
1385
+ const reloaderStatusSignal = u("idle");
1386
+ const changesSignal = u(0);
1387
+ if (parentWindowReloader) {
1388
+ if (!parentWindowReloader.autoreload.enabled && paramsFromParentWindow.autoreload) {
1389
+ autoreloadEnabledSignal.value = true;
1390
+ } else {
1391
+ autoreloadEnabledSignal.value = parentWindowReloader.autoreload.enabled;
1392
+ }
1393
+ parentWindowReloader.autoreload.onchange = () => {
1394
+ autoreloadEnabledSignal.value = parentWindowReloader.autoreload.enabled;
1395
+ };
1396
+ reloaderStatusSignal.value = parentWindowReloader.status.value;
1397
+ const onchange = parentWindowReloader.status.onchange;
1398
+ parentWindowReloader.status.onchange = () => {
1399
+ onchange();
1400
+ reloaderStatusSignal.value = parentWindowReloader.status.value;
1401
+ };
1402
+ changesSignal.value = parentWindowReloader.changes.value;
1403
+ parentWindowReloader.changes.onchange = () => {
1404
+ changesSignal.value = [...parentWindowReloader.changes.value];
1405
+ };
1406
+ }
1407
+
1408
+ const openChangesToolip = () => {
1409
+ changesTooltipOpenedSignal.value = true;
1410
+ };
1411
+ const closeChangesToolip = () => {
1412
+ changesTooltipOpenedSignal.value = false;
1413
+ };
1414
+
1415
+ const changesIndicator = document.querySelector("#changes_indicator");
1416
+ const renderChangesIndicator = () => {
1417
+ p$1(() => {
1418
+ const autoreloadEnabled = autoreloadEnabledSignal.value;
1419
+ const changes = changesSignal.value;
1420
+ const changeCount = changes.length;
1421
+ enableVariant(changesIndicator, {
1422
+ changes: !autoreloadEnabled && changeCount ? "yes" : "no"
1423
+ });
1424
+ if (changeCount) {
1425
+ changesIndicator.querySelector(".tooltip_text").innerHTML = computeTooltipText({
1426
+ changes
1427
+ });
1428
+ changesIndicator.querySelector(".tooltip_text a").onclick = () => {
1429
+ // eslint-disable-next-line no-alert
1430
+ window.alert(JSON.stringify(changes, null, " "));
1431
+ console.log(changes);
1432
+ };
1433
+ changesIndicator.querySelector(".changes_text").innerHTML = changeCount;
1434
+ }
1435
+ });
1436
+ changesIndicator.querySelector(".tooltip_action").onclick = () => {
1437
+ parentWindowReloader.reload();
1438
+ };
1439
+ p$1(() => {
1440
+ const changesTooltipOpened = changesTooltipOpenedSignal.value;
1441
+ if (changesTooltipOpened) {
1442
+ changesIndicator.setAttribute("data-tooltip-visible", "");
1443
+ } else {
1444
+ changesIndicator.removeAttribute("data-tooltip-visible");
1445
+ }
1446
+ });
1447
+ const button = changesIndicator.querySelector("button");
1448
+ button.onclick = () => {
1449
+ const changesTooltipOpened = changesTooltipOpenedSignal.value;
1450
+ if (changesTooltipOpened) {
1451
+ closeChangesToolip();
1452
+ } else {
1453
+ openChangesToolip();
1454
+ }
1455
+ };
1456
+ };
1457
+ const computeTooltipText = ({
1458
+ changes
1459
+ }) => {
1460
+ const changesCount = changes.length;
1461
+ if (changesCount === 1) {
1462
+ return `There is <a href="javascript:void(0)">1</a> change to apply`;
1463
+ }
1464
+ return `There is <a href="javascript:void(0)">${changesCount}<a> changes to apply`;
1465
+ };
1466
+
1467
+ const parentServerEvents = window.parent.__server_events__;
1468
+ const serverEvents = window.__server_events__;
1469
+ const serverIndicator = document.querySelector("#server_indicator");
1470
+ const renderServerIndicator = () => {
1471
+ removeForceHideElement(document.querySelector("#server_indicator"));
1472
+ p$1(() => {
1473
+ const serverConnection = serverConnectionSignal.value;
1474
+ updateServerIndicator(serverConnection);
1475
+ });
1476
+ p$1(() => {
1477
+ const serverTooltipOpened = serverTooltipOpenedSignal.value;
1478
+ if (serverTooltipOpened) {
1479
+ serverIndicator.setAttribute("data-tooltip-visible", "");
1480
+ } else {
1481
+ serverIndicator.removeAttribute("data-tooltip-visible");
1482
+ }
1483
+ });
1484
+ };
1485
+ const updateServerIndicator = connectionState => {
1486
+ enableVariant(serverIndicator, {
1487
+ connectionState
1488
+ });
1489
+ const variantNode = document.querySelector("#server_indicator > [data-when-active]");
1490
+ variantNode.querySelector("button").onclick = () => {
1491
+ const serverTooltipOpened = serverTooltipOpenedSignal.value;
1492
+ if (serverTooltipOpened) {
1493
+ closeServerTooltip();
1494
+ } else {
1495
+ openServerTooltip();
1496
+ }
1497
+ };
1498
+ if (connectionState === "connecting") {
1499
+ variantNode.querySelector("a").onclick = () => {
1500
+ if (parentServerEvents) {
1501
+ parentServerEvents.disconnect();
1502
+ }
1503
+ serverEvents.disconnect();
1504
+ };
1505
+ } else if (connectionState === "closed") {
1506
+ variantNode.querySelector("a").onclick = () => {
1507
+ if (parentServerEvents) {
1508
+ parentServerEvents.connect();
1509
+ }
1510
+ serverEvents.connect();
1511
+ };
1512
+ }
1513
+ };
1514
+
1515
+ const renderToolbarAutoreloadSetting = () => {
1516
+ const parentWindowReloader = window.parent.__reloader__;
1517
+ if (!parentWindowReloader) {
1518
+ disableAutoreloadSetting();
1519
+ return;
1520
+ }
1521
+ const autoreloadCheckbox = document.querySelector("#toggle_autoreload");
1522
+ p$1(() => {
1523
+ const autoreloadEnabled = autoreloadEnabledSignal.value;
1524
+ if (autoreloadEnabled) {
1525
+ autoreloadCheckbox.checked = true;
1526
+ } else {
1527
+ autoreloadCheckbox.checked = false;
1528
+ }
1529
+ });
1530
+ autoreloadCheckbox.onchange = () => {
1531
+ if (autoreloadCheckbox.checked) {
1532
+ enableAutoreload();
1533
+ } else {
1534
+ disableAutoreload();
1535
+ }
1536
+ };
1537
+ };
1538
+ const disableAutoreloadSetting = () => {
1539
+ document.querySelector(".settings_autoreload").setAttribute("data-disabled", "true");
1540
+ document.querySelector(".settings_autoreload").setAttribute("title", `Autoreload not enabled on server`);
1541
+ document.querySelector("#toggle_autoreload").disabled = true;
1542
+ };
1543
+
1544
+ // const changeLink = variantNode.querySelector(".eventsource-changes-link")
1545
+ // changeLink.innerHTML = reloadMessageCount
1546
+ // changeLink.onclick = () => {
1547
+ // console.log(reloadMessages)
1548
+ // // eslint-disable-next-line no-alert
1549
+ // window.parent.alert(JSON.stringify(reloadMessages, null, " "))
1550
+ // }
1551
+
1552
+ // const someFailed = reloadMessages.some((m) => m.status === "failed")
1553
+ // const somePending = reloadMessages.some((m) => m.status === "pending")
1554
+ // const applyLink = variantNode.querySelector(".eventsource-reload-link")
1555
+ // applyLink.innerHTML = someFailed
1556
+ // ? "failed"
1557
+ // : somePending
1558
+ // ? "applying..."
1559
+ // : "apply changes"
1560
+ // applyLink.onclick = someFailed
1561
+ // ? () => {
1562
+ // parentEventSourceClient.applyReloadMessageEffects()
1563
+ // }
1564
+ // : somePending
1565
+ // ? () => {}
1566
+ // : () => {
1567
+ // parentEventSourceClient.applyReloadMessageEffects()
1568
+ // }
1569
+
1570
+ // parentEventSourceClient.reloadMessagesSignal.onchange = () => {
1571
+ // updateEventSourceIndicator()
1572
+ // }
1573
+ // const autoreloadCheckbox = document.querySelector("#toggle-autoreload")
1574
+ // autoreloadCheckbox.checked = parentEventSourceClient.isAutoreloadEnabled()
1575
+ // autoreloadCheckbox.onchange = () => {
1576
+ // parentEventSourceClient.setAutoreloadPreference(autoreloadCheckbox.checked)
1577
+ // updateEventSourceIndicator()
1578
+ // }
1579
+
1580
+ const enableAnimations = () => {
1581
+ animationsEnabledSignal.value = true;
1582
+ };
1583
+ const disableAnimations = () => {
1584
+ animationsEnabledSignal.value = false;
1585
+ };
1586
+
1587
+ const renderToolbarAnimationSetting = () => {
1588
+ const animCheckbox = document.querySelector("#toggle_anims");
1589
+ p$1(() => {
1590
+ const animationsEnabled = animationsEnabledSignal.value;
1591
+ animCheckbox.checked = animationsEnabled;
1592
+ });
1593
+ animCheckbox.onchange = () => {
1594
+ if (animCheckbox.checked) {
1595
+ enableAnimations();
1596
+ } else {
1597
+ disableAnimations();
1598
+ }
1599
+ };
1600
+ // enable toolbar transition only after first render
1601
+ setTimeout(() => {
1602
+ document.querySelector("#toolbar").setAttribute("data-animate", "");
1603
+ });
1604
+ };
1605
+
1606
+ const notifCheckbox = document.querySelector("#toggle_notifs");
1607
+ const renderToolbarNotificationSetting = () => {
1608
+ p$1(() => {
1609
+ const notificationsEnabled = notificationsEnabledSignal.value;
1610
+ notifCheckbox.checked = notificationsEnabled;
1611
+ });
1612
+ p$1(() => {
1613
+ const notificationPermission = notificationPermissionSignal.value;
1614
+ if (!notificationAPIDetected) {
1615
+ applyNotificationNotAvailableEffects();
1616
+ return;
1617
+ }
1618
+ if (notificationPermission === "default") {
1619
+ applyNotificationDefaultEffects();
1620
+ return;
1621
+ }
1622
+ if (notificationPermission === "denied") {
1623
+ applyNotificationDeniedEffects();
1624
+ return;
1625
+ }
1626
+ if (notificationPermission === "granted") {
1627
+ applyNotificationGrantedEffects();
1628
+ return;
1629
+ }
1630
+ });
1631
+ };
1632
+ const applyNotificationNotAvailableEffects = () => {
1633
+ const notifSetting = document.querySelector(".settings_notification");
1634
+ notifSetting.setAttribute("data-disabled", "true");
1635
+ notifSetting.setAttribute("title", `Notification not available in the browser`);
1636
+ notifCheckbox.disabled = true;
1637
+ };
1638
+ const applyNotificationDefaultEffects = () => {
1639
+ applyNotificationNOTGrantedEffects();
1640
+ const notifSetting = document.querySelector(".settings_notification");
1641
+ notifSetting.removeAttribute("data-disabled");
1642
+ notifSetting.removeAttribute("title");
1643
+ };
1644
+ const applyNotificationDeniedEffects = () => {
1645
+ applyNotificationNOTGrantedEffects();
1646
+ const notifSetting = document.querySelector(".settings_notification");
1647
+ notifSetting.setAttribute("data-disabled", "true");
1648
+ notifSetting.setAttribute("title", `Notification denied`);
1649
+ };
1650
+ const applyNotificationGrantedEffects = () => {
1651
+ enableVariant(document.querySelector(".notification_text"), {
1652
+ notif_granted: "yes"
1653
+ });
1654
+ notifCheckbox.disabled = false;
1655
+ notifCheckbox.onchange = () => {
1656
+ if (notifCheckbox.checked) {
1657
+ enableNotifications();
1658
+ } else {
1659
+ disableNotifications();
1660
+ }
1661
+ };
1662
+ };
1663
+ const applyNotificationNOTGrantedEffects = () => {
1664
+ enableVariant(document.querySelector(".notification_text"), {
1665
+ notif_granted: "no"
1666
+ });
1667
+ notifCheckbox.disabled = true;
1668
+ notifCheckbox.checked = false;
1669
+ document.querySelector("a.request_notification_permission").onclick = () => {
1670
+ requestPermission();
1671
+ };
1672
+ };
1673
+
1674
+ const themeSignal = u(typeof stateFromLocalStorage.theme === "string" ? stateFromLocalStorage.theme : typeof paramsFromParentWindow.theme === "string" ? paramsFromParentWindow.theme : "dark");
1675
+
1676
+ const switchToLightTheme = () => {
1677
+ themeSignal.value = "light";
1678
+ };
1679
+ const switchToDefaultTheme = () => {
1680
+ themeSignal.value = "dark";
1681
+ };
1682
+
1683
+ const renderToolbarThemeSetting = () => {
1684
+ const checkbox = document.querySelector("#checkbox_dark_theme");
1685
+ checkbox.checked = themeSignal.value === "dark";
1686
+ checkbox.onchange = () => {
1687
+ if (checkbox.checked) {
1688
+ switchToDefaultTheme();
1689
+ } else {
1690
+ switchToLightTheme();
1691
+ }
1692
+ };
1693
+ };
1694
+
1695
+ const renderToolbarSettings = () => {
1696
+ document.querySelector("#settings_open_button").onclick = toggleSettings;
1697
+ document.querySelector("#settings_close_button").onclick = toggleSettings;
1698
+ disableWarningStyle();
1699
+ renderToolbarAutoreloadSetting();
1700
+ renderToolbarAnimationSetting();
1701
+ renderToolbarNotificationSetting();
1702
+ renderToolbarThemeSetting();
1703
+ p$1(() => {
1704
+ const settingsOpened = settingsOpenedSignal.value;
1705
+ if (settingsOpened) {
1706
+ activateToolbarSection(document.querySelector("#settings"));
1707
+ } else {
1708
+ deactivateToolbarSection(document.querySelector("#settings"));
1709
+ }
1710
+ });
1711
+ };
1712
+ const toggleSettings = () => {
1713
+ const settingsOpened = settingsOpenedSignal.value;
1714
+ if (settingsOpened) {
1715
+ closeSettings();
1716
+ } else {
1717
+ openSettings();
1718
+ }
1719
+ };
1720
+ const disableWarningStyle = () => {
1721
+ enableVariant(document.querySelector("#settings_open_button"), {
1722
+ has_warning: "no"
1723
+ });
1724
+ };
1725
+
1726
+ const openToolbar = () => {
1727
+ openedSignal.value = true;
1728
+ };
1729
+ const closeToolbar = () => {
1730
+ openedSignal.value = false;
1731
+ };
1732
+
1733
+ const renderToolbarCloseButton = () => {
1734
+ // if user click enter or space quickly while closing toolbar
1735
+ // it will cancel the closing
1736
+ // that's why I used toggleToolbar and not hideToolbar
1737
+ document.querySelector("#toolbar_close_button").onclick = () => {
1738
+ if (openedSignal.value) {
1739
+ closeToolbar();
1740
+ } else {
1741
+ openToolbar();
1742
+ }
1743
+ };
1744
+ };
1745
+
1746
+ const initToolbarUI = () => {
1747
+ initToolbarOpening();
1748
+ initToolbarMenuOverflow();
1749
+ renderToolbarOverlay();
1750
+ renderDocumentIndexLink();
1751
+ renderDocumentExecutionIndicator();
1752
+ renderChangesIndicator();
1753
+ renderServerIndicator();
1754
+ renderToolbarSettings();
1755
+ renderToolbarCloseButton();
1756
+ };
1757
+
1758
+ addExternalCommandCallback("initToolbar", () => {
1759
+ // for the first render, force disable animations
1760
+ const animationsEnabled = animationsEnabledSignal.value;
1761
+ if (animationsEnabled) {
1762
+ animationsEnabledSignal.value = false;
1763
+ }
1764
+ initToolbarUI();
1765
+ if (animationsEnabled) {
1766
+ animationsEnabledSignal.value = true;
1767
+ }
1768
+ });
1769
+ sendEventToParent("toolbar_ready");
1770
+
1771
+ p$1(() => {
1772
+ const serverConnection = serverConnectionSignal.value;
1773
+ if (serverConnection === "connecting" || serverConnection === "closed") {
1774
+ openServerTooltip();
1775
+ }
1776
+ });
1777
+
1778
+ p$1(() => {
1779
+ const theme = themeSignal.value;
1780
+ document.querySelector("html").setAttribute("data-theme", theme);
1781
+ });
1782
+
1783
+ addExternalCommandCallback("openToolbar", openToolbar);
1784
+ addExternalCommandCallback("closeToolbar", closeToolbar);
1785
+
1786
+ const toolbarStateSignal = w(() => {
1787
+ const opened = openedSignal.value;
1788
+ const theme = themeSignal.value;
1789
+ const animationsEnabled = animationsEnabledSignal.value;
1790
+ const notificationsEnabled = notificationsEnabledSignal.value;
1791
+ return {
1792
+ opened,
1793
+ theme,
1794
+ animationsEnabled,
1795
+ notificationsEnabled
1796
+ };
1797
+ });
1798
+
1799
+ p$1(() => {
1800
+ const toolbarState = toolbarStateSignal.value;
1801
+ localStorage.setItem("jsenv_toolbar", JSON.stringify(toolbarState));
1802
+ sendEventToParent("toolbar_state_change", toolbarState);
1803
+ });