report-studio 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +171 -22
  3. package/dist/designer-qy59eEux.js +3416 -0
  4. package/dist/designer.js +2 -3209
  5. package/dist/index.js +2 -2
  6. package/dist/react-designer.js +41 -0
  7. package/dist/react.js +60 -0
  8. package/dist/{viewer-D-c0lKzQ.js → viewer-xa17tyMJ.js} +682 -537
  9. package/package.json +105 -66
  10. package/src/cli/serve.js +135 -135
  11. package/src/designer/designer.js +2054 -1900
  12. package/src/designer/dialog.js +708 -708
  13. package/src/designer/fields.js +51 -2
  14. package/src/designer/icons.js +5 -0
  15. package/src/designer/index.html +28 -28
  16. package/src/designer/main.js +39 -39
  17. package/src/designer/menu.js +2 -2
  18. package/src/designer/panel.js +21 -1
  19. package/src/designer/sample-data.js +180 -9
  20. package/src/designer/structure.js +87 -6
  21. package/src/designer/styles.css +1654 -1616
  22. package/src/designer/tokens.js +9 -0
  23. package/src/engine/csv.js +350 -315
  24. package/src/engine/group.js +128 -65
  25. package/src/engine/index.js +35 -34
  26. package/src/engine/measure.js +13 -12
  27. package/src/engine/paginate.js +8 -4
  28. package/src/engine/resolve.js +37 -0
  29. package/src/engine/tables.js +87 -0
  30. package/src/engine/validate.js +97 -22
  31. package/src/index.html +79 -79
  32. package/src/index.js +51 -50
  33. package/src/preview/chrome.css +505 -505
  34. package/src/preview/chrome.js +147 -147
  35. package/src/preview/index.html +28 -28
  36. package/src/preview/viewer.js +763 -745
  37. package/src/react/designer.js +87 -0
  38. package/src/react/index.js +117 -0
  39. package/src/render/items.js +94 -1
  40. package/src/render/report.css +30 -0
  41. package/src/server/routes.js +331 -331
  42. package/src/shared/brand.css +29 -29
  43. package/src/shared/dropdown.css +136 -136
  44. package/src/shared/modal.css +125 -125
  45. package/src/shared/store.js +145 -145
  46. package/src/shared/theme.css +72 -72
  47. package/src/shared/window.js +138 -138
  48. package/types/designer.d.ts +85 -0
  49. package/types/index.d.ts +204 -0
  50. package/types/layout.d.ts +179 -0
  51. package/types/react-designer.d.ts +29 -0
  52. package/types/react.d.ts +30 -0
  53. package/types/vite.d.ts +18 -0
@@ -0,0 +1,3416 @@
1
+ import { A as e, E as t, I as n, L as r, O as i, S as a, T as o, a as s, c, d as l, f as u, k as d, l as f, n as p, o as m, p as h, r as g, s as _, t as ee, u as v, w as y, x as b } from "./viewer-xa17tyMJ.js";
2
+ //#region src/designer/fields.js
3
+ var x = [
4
+ {
5
+ label: "Helvetica",
6
+ value: "Helvetica, Arial, sans-serif"
7
+ },
8
+ {
9
+ label: "Arial",
10
+ value: "Arial, Helvetica, sans-serif"
11
+ },
12
+ {
13
+ label: "Verdana",
14
+ value: "Verdana, Geneva, sans-serif"
15
+ },
16
+ {
17
+ label: "Trebuchet",
18
+ value: "\"Trebuchet MS\", Helvetica, sans-serif"
19
+ },
20
+ {
21
+ label: "Georgia",
22
+ value: "Georgia, \"Times New Roman\", serif"
23
+ },
24
+ {
25
+ label: "Times",
26
+ value: "\"Times New Roman\", Times, serif"
27
+ },
28
+ {
29
+ label: "Courier",
30
+ value: "\"Courier New\", Courier, monospace"
31
+ }
32
+ ], S = [{
33
+ label: "Regular",
34
+ value: "normal"
35
+ }, {
36
+ label: "Bold",
37
+ value: "bold"
38
+ }], te = [{
39
+ label: "Upright",
40
+ value: "normal"
41
+ }, {
42
+ label: "Italic",
43
+ value: "italic"
44
+ }], C = [
45
+ {
46
+ label: "Left",
47
+ value: "left"
48
+ },
49
+ {
50
+ label: "Centre",
51
+ value: "center"
52
+ },
53
+ {
54
+ label: "Right",
55
+ value: "right"
56
+ }
57
+ ], w = [
58
+ {
59
+ label: "Fit inside",
60
+ value: "contain"
61
+ },
62
+ {
63
+ label: "Fill and crop",
64
+ value: "cover"
65
+ },
66
+ {
67
+ label: "Stretch",
68
+ value: "fill"
69
+ }
70
+ ], T = [{
71
+ label: "Horizontal",
72
+ value: "horizontal"
73
+ }, {
74
+ label: "Vertical",
75
+ value: "vertical"
76
+ }], E = [
77
+ {
78
+ label: "Solid",
79
+ value: "solid"
80
+ },
81
+ {
82
+ label: "Dashed",
83
+ value: "dashed"
84
+ },
85
+ {
86
+ label: "Dotted",
87
+ value: "dotted"
88
+ },
89
+ {
90
+ label: "Double",
91
+ value: "double"
92
+ }
93
+ ], D = [...E, {
94
+ label: "None",
95
+ value: "none"
96
+ }], O = (e, t, n = {}) => ({
97
+ key: e,
98
+ label: t,
99
+ type: "number",
100
+ ...n
101
+ });
102
+ function k(e) {
103
+ let t = e.rowHeight ?? 0, n = e.showHeader ? e.headerHeight ?? t : t, r = Math.min(t || Infinity, n || Infinity);
104
+ return Number.isFinite(r) ? Math.max(1, Math.floor(r / 2)) : 1;
105
+ }
106
+ var A = [
107
+ {
108
+ key: "field",
109
+ label: "Field",
110
+ type: "text"
111
+ },
112
+ {
113
+ key: "label",
114
+ label: "Label",
115
+ type: "text"
116
+ },
117
+ {
118
+ key: "width",
119
+ label: "Width",
120
+ type: "number",
121
+ min: 1
122
+ },
123
+ {
124
+ key: "align",
125
+ label: "Align",
126
+ type: "choice",
127
+ options: C
128
+ }
129
+ ];
130
+ function ne(e) {
131
+ if (!e) return [];
132
+ let t = {
133
+ title: "Position and size",
134
+ fields: [
135
+ O("x", "X"),
136
+ O("y", "Y"),
137
+ O("w", "Width", { min: 1 }),
138
+ ...e.type === "table" ? [] : [O("h", "Height", { min: 1 })]
139
+ ]
140
+ };
141
+ return e.type === "box" ? [
142
+ t,
143
+ {
144
+ title: "Border",
145
+ fields: [
146
+ {
147
+ key: "style.borderStyle",
148
+ label: "Style",
149
+ type: "choice",
150
+ options: D
151
+ },
152
+ O("style.borderWidth", "Width", { min: 1 }),
153
+ {
154
+ key: "style.borderColor",
155
+ label: "Colour",
156
+ type: "color"
157
+ },
158
+ O("style.radius", "Corner", { min: 0 })
159
+ ]
160
+ },
161
+ {
162
+ title: "Fill",
163
+ fields: [{
164
+ key: "style.background",
165
+ label: "Background",
166
+ type: "color",
167
+ hint: "Leave a box unfilled to frame what is behind it"
168
+ }]
169
+ }
170
+ ] : e.type === "image" ? [{
171
+ title: "Picture",
172
+ fields: [
173
+ {
174
+ key: "src",
175
+ label: "Image",
176
+ type: "image",
177
+ hint: "Stored in the layout file. Keep it small - a logo, not a photograph"
178
+ },
179
+ {
180
+ key: "field",
181
+ label: "From data",
182
+ type: "text",
183
+ nullable: !0,
184
+ hint: "A data path such as company.logo, whose value is the picture's URL. It replaces the stored image when present"
185
+ },
186
+ {
187
+ key: "fit",
188
+ label: "Fit",
189
+ type: "choice",
190
+ options: w
191
+ },
192
+ {
193
+ key: "alt",
194
+ label: "Description",
195
+ type: "text",
196
+ hint: "Read out by a screen reader in place of the picture"
197
+ }
198
+ ]
199
+ }, t] : e.type === "line" ? [t, {
200
+ title: "Line",
201
+ fields: [
202
+ {
203
+ key: "orientation",
204
+ label: "Runs",
205
+ type: "choice",
206
+ options: T
207
+ },
208
+ O("style.thickness", "Thickness", { min: 1 }),
209
+ {
210
+ key: "style.lineStyle",
211
+ label: "Style",
212
+ type: "choice",
213
+ options: E
214
+ },
215
+ {
216
+ key: "style.color",
217
+ label: "Colour",
218
+ type: "color"
219
+ }
220
+ ]
221
+ }] : e.type === "table" ? [
222
+ t,
223
+ {
224
+ title: "Data",
225
+ fields: [{
226
+ key: "dataset",
227
+ label: "Dataset",
228
+ type: "text",
229
+ nullable: !0,
230
+ hint: "The key in the data object whose rows this table draws. Blank reads the report's dataset"
231
+ }, {
232
+ key: "groupBy",
233
+ label: "Group by",
234
+ type: "text",
235
+ nullable: !0,
236
+ hint: "A field to group these rows by, or blank. One table in a report can be grouped"
237
+ }]
238
+ },
239
+ {
240
+ title: "Rows",
241
+ fields: [O("rowHeight", "Row height", { min: 1 })]
242
+ },
243
+ {
244
+ title: "Header",
245
+ fields: [
246
+ {
247
+ key: "showHeader",
248
+ label: "Show header",
249
+ type: "toggle"
250
+ },
251
+ O("headerHeight", "Height", { min: 1 }),
252
+ {
253
+ key: "style.headerBackground",
254
+ label: "Fill",
255
+ type: "color"
256
+ },
257
+ {
258
+ key: "style.headerColor",
259
+ label: "Text",
260
+ type: "color",
261
+ hint: "Leave these alone to keep the stylesheet's own header"
262
+ }
263
+ ]
264
+ },
265
+ {
266
+ title: "Appearance",
267
+ fields: [
268
+ {
269
+ key: "style.fontFamily",
270
+ label: "Font",
271
+ type: "choice",
272
+ options: x
273
+ },
274
+ O("style.fontSize", "Font size", { min: 1 }),
275
+ {
276
+ key: "style.color",
277
+ label: "Text",
278
+ type: "color"
279
+ },
280
+ {
281
+ key: "wrap",
282
+ label: "Wrap cells",
283
+ type: "toggle",
284
+ hint: "A cell wider than its column runs onto another line and the row grows; turn this off to keep every row one line, cut off with an ellipsis"
285
+ },
286
+ {
287
+ key: "style.borderStyle",
288
+ label: "Borders",
289
+ type: "choice",
290
+ options: D
291
+ },
292
+ O("style.borderWidth", "Border width", {
293
+ min: 1,
294
+ max: k(e)
295
+ }),
296
+ {
297
+ key: "style.borderColor",
298
+ label: "Border colour",
299
+ type: "color"
300
+ }
301
+ ]
302
+ }
303
+ ] : [
304
+ {
305
+ title: "Content",
306
+ fields: [{
307
+ key: "value",
308
+ label: "Value",
309
+ type: "textarea",
310
+ hint: "Placeholders in braces: {customer.name}, {page}, {sum(amount)}"
311
+ }]
312
+ },
313
+ t,
314
+ {
315
+ title: "Type",
316
+ fields: [
317
+ {
318
+ key: "style.fontFamily",
319
+ label: "Font",
320
+ type: "choice",
321
+ options: x
322
+ },
323
+ O("style.fontSize", "Size", { min: 1 }),
324
+ {
325
+ key: "style.fontWeight",
326
+ label: "Weight",
327
+ type: "choice",
328
+ options: S
329
+ },
330
+ {
331
+ key: "style.fontStyle",
332
+ label: "Style",
333
+ type: "choice",
334
+ options: te
335
+ },
336
+ {
337
+ key: "style.align",
338
+ label: "Align",
339
+ type: "choice",
340
+ options: C
341
+ },
342
+ {
343
+ key: "style.color",
344
+ label: "Colour",
345
+ type: "color"
346
+ }
347
+ ]
348
+ }
349
+ ];
350
+ }
351
+ var j = [
352
+ {
353
+ label: "A2",
354
+ width: 1587,
355
+ height: 2245
356
+ },
357
+ {
358
+ label: "A3",
359
+ width: 1123,
360
+ height: 1587
361
+ },
362
+ {
363
+ label: "A4",
364
+ width: 794,
365
+ height: 1123
366
+ },
367
+ {
368
+ label: "A5",
369
+ width: 559,
370
+ height: 794
371
+ },
372
+ {
373
+ label: "A6",
374
+ width: 397,
375
+ height: 559
376
+ },
377
+ {
378
+ label: "Letter",
379
+ width: 816,
380
+ height: 1056
381
+ },
382
+ {
383
+ label: "Legal",
384
+ width: 816,
385
+ height: 1344
386
+ },
387
+ {
388
+ label: "Tabloid",
389
+ width: 1056,
390
+ height: 1632
391
+ }
392
+ ], M = "custom";
393
+ function N(e) {
394
+ if (e?.paper === "custom") return M;
395
+ let t = e?.width, n = e?.height, r = j.find((e) => e.width === t && e.height === n || e.height === t && e.width === n);
396
+ return r ? r.label : M;
397
+ }
398
+ function P(e) {
399
+ return (e?.width ?? 0) > (e?.height ?? 0) ? "landscape" : "portrait";
400
+ }
401
+ function re(e, t) {
402
+ let n = j.find((e) => e.label === t);
403
+ if (!n) return e.page.paper === "custom" ? !1 : (e.page.paper = M, !0);
404
+ let r = P(e.page) === "landscape", i = r ? n.height : n.width, a = r ? n.width : n.height, o = e.page.paper === M;
405
+ return delete e.page.paper, e.page.width === i && e.page.height === a ? o : (e.page.width = i, e.page.height = a, !0);
406
+ }
407
+ function ie(e, t) {
408
+ if (t === "landscape" == (P(e.page) === "landscape")) return !1;
409
+ let { width: n, height: r } = e.page;
410
+ return e.page.width = r, e.page.height = n, !0;
411
+ }
412
+ function F(e) {
413
+ let t = N(e.page) === M, n = {
414
+ key: "paper",
415
+ label: "Paper",
416
+ type: "choice",
417
+ rebuilds: !0,
418
+ options: [...j.map((e) => ({
419
+ value: e.label,
420
+ label: `${e.label} ${e.width} x ${e.height}`
421
+ })), {
422
+ value: M,
423
+ label: "Custom"
424
+ }],
425
+ read: (e) => N(e.page),
426
+ write: (e, t) => re(e, t)
427
+ };
428
+ return t ? [
429
+ n,
430
+ O("page.width", "Width", { min: 1 }),
431
+ O("page.height", "Height", { min: 1 })
432
+ ] : [n, {
433
+ key: "orientation",
434
+ label: "Orientation",
435
+ type: "choice",
436
+ rebuilds: !0,
437
+ options: [{
438
+ value: "portrait",
439
+ label: "Portrait"
440
+ }, {
441
+ value: "landscape",
442
+ label: "Landscape"
443
+ }],
444
+ read: (e) => P(e.page),
445
+ write: (e, t) => ie(e, t)
446
+ }];
447
+ }
448
+ function I(e) {
449
+ return e ? [
450
+ {
451
+ title: "Report",
452
+ fields: [
453
+ {
454
+ key: "name",
455
+ label: "Name",
456
+ type: "text"
457
+ },
458
+ {
459
+ key: "dataset",
460
+ label: "Dataset",
461
+ type: "text",
462
+ nullable: !0,
463
+ hint: "The key in the data object that drives the rows, for every table that does not name its own"
464
+ },
465
+ {
466
+ key: "groupBy",
467
+ label: "Group by",
468
+ type: "text",
469
+ nullable: !0,
470
+ hint: "A field name, or blank for no grouping. Groups the first table, unless a table sets its own"
471
+ }
472
+ ]
473
+ },
474
+ {
475
+ title: "Page",
476
+ fields: F(e)
477
+ },
478
+ {
479
+ title: "Margins",
480
+ fields: [
481
+ O("page.margin.top", "Top", { min: 0 }),
482
+ O("page.margin.right", "Right", { min: 0 }),
483
+ O("page.margin.bottom", "Bottom", { min: 0 }),
484
+ O("page.margin.left", "Left", { min: 0 })
485
+ ]
486
+ }
487
+ ] : [];
488
+ }
489
+ function ae(e) {
490
+ return I(e).flatMap((e) => e.fields);
491
+ }
492
+ function oe(e) {
493
+ return ne(e).flatMap((e) => e.fields);
494
+ }
495
+ function L(e) {
496
+ return e.split(".");
497
+ }
498
+ function R(e, t) {
499
+ if (t.read) return t.read(e);
500
+ let n = e;
501
+ for (let e of L(t.key)) {
502
+ if (n == null) return;
503
+ n = n[e];
504
+ }
505
+ return n;
506
+ }
507
+ function se(e, t, n) {
508
+ let r = ce(t, n);
509
+ if (r === void 0) return !1;
510
+ if (t.write) return t.write(e, r);
511
+ let i = L(t.key), a = i.pop(), o = e;
512
+ for (let e of i) (o[e] == null || typeof o[e] != "object") && (o[e] = {}), o = o[e];
513
+ return o[a] === r ? !1 : (o[a] = r, !0);
514
+ }
515
+ function ce(e, t) {
516
+ if (e.type === "toggle") return !!t;
517
+ if (e.type === "number") {
518
+ if (t === "" || t == null) return;
519
+ let n = Number(t);
520
+ if (!Number.isFinite(n)) return;
521
+ let r = e.min == null ? n : Math.max(n, e.min);
522
+ return e.max == null ? r : Math.min(r, e.max);
523
+ }
524
+ if (t != null) return e.nullable && t === "" ? null : String(t);
525
+ }
526
+ //#endregion
527
+ //#region src/designer/blank.js
528
+ function le() {
529
+ return {
530
+ version: 1,
531
+ name: "Untitled report",
532
+ page: {
533
+ width: 794,
534
+ height: 1123,
535
+ margin: {
536
+ top: 40,
537
+ right: 40,
538
+ bottom: 40,
539
+ left: 40
540
+ }
541
+ },
542
+ dataset: null,
543
+ groupBy: null,
544
+ bands: [
545
+ {
546
+ type: "pageHeader",
547
+ height: 60,
548
+ items: []
549
+ },
550
+ {
551
+ type: "detail",
552
+ items: []
553
+ },
554
+ {
555
+ type: "pageFooter",
556
+ height: 40,
557
+ items: []
558
+ }
559
+ ]
560
+ };
561
+ }
562
+ function ue(e) {
563
+ return e == null ? !0 : typeof e != "object" || Array.isArray(e) ? !1 : Object.keys(e).length === 0;
564
+ }
565
+ var de = 3, fe = [
566
+ "nw",
567
+ "n",
568
+ "ne",
569
+ "e",
570
+ "se",
571
+ "s",
572
+ "sw",
573
+ "w"
574
+ ], pe = ["e", "w"];
575
+ function me(e) {
576
+ return Math.round(e / 10) * 10;
577
+ }
578
+ function z(t) {
579
+ return {
580
+ x: t.x ?? 0,
581
+ y: t.y ?? 0,
582
+ w: t.w ?? 0,
583
+ h: e(t)
584
+ };
585
+ }
586
+ function B(e) {
587
+ return e.type === "table" ? "x" : "xy";
588
+ }
589
+ function V(e) {
590
+ return e === "x" ? [...pe] : [...fe];
591
+ }
592
+ function H(e, t, n) {
593
+ return {
594
+ x: me(e.x + t),
595
+ y: me(e.y + n)
596
+ };
597
+ }
598
+ function he(e, t, n, r, i = "xy") {
599
+ let { x: a, y: o, w: s, h: c } = t;
600
+ return e.includes("w") ? (s = Math.max(t.w - n, 20), a = t.x + t.w - s) : e.includes("e") && (s = Math.max(t.w + n, 20)), i === "xy" && (e.includes("n") ? (c = Math.max(t.h - r, 12), o = t.y + t.h - c) : e.includes("s") && (c = Math.max(t.h + r, 12))), {
601
+ x: a,
602
+ y: o,
603
+ w: s,
604
+ h: c
605
+ };
606
+ }
607
+ function ge(e, t) {
608
+ e.x = t.x, e.y = t.y, t.w != null && (e.w = t.w), t.h != null && e.type !== "table" && (e.h = t.h);
609
+ }
610
+ function _e(e, { minor: t = 10, major: n = 50 } = {}) {
611
+ let r = [];
612
+ if (!(e > 0) || !(t > 0)) return r;
613
+ for (let i = 0; i <= e; i += t) r.push({
614
+ at: i,
615
+ major: i % n === 0
616
+ });
617
+ let i = r.at(-1);
618
+ return i && i.at !== e && r.push({
619
+ at: e,
620
+ major: !0
621
+ }), r;
622
+ }
623
+ function U(e) {
624
+ let t = e?.guides, n = (e) => (Array.isArray(e) ? e : []).filter(ve).map(Number).filter(Number.isFinite).sort((e, t) => e - t);
625
+ return {
626
+ x: n(t?.x),
627
+ y: n(t?.y)
628
+ };
629
+ }
630
+ function ve(e) {
631
+ return typeof e == "number" || typeof e == "string" && e.trim() !== "";
632
+ }
633
+ function W(e) {
634
+ (!e.guides || typeof e.guides != "object") && (e.guides = {
635
+ x: [],
636
+ y: []
637
+ });
638
+ for (let t of ["x", "y"]) Array.isArray(e.guides[t]) || (e.guides[t] = []);
639
+ return e.guides;
640
+ }
641
+ function ye(e, t, n) {
642
+ if (!ve(n)) return null;
643
+ let r = Math.round(Number(n));
644
+ if (!Number.isFinite(r)) return null;
645
+ let i = W(e);
646
+ return i[t].includes(r) || (i[t].push(r), i[t].sort((e, t) => e - t)), r;
647
+ }
648
+ function be(e, t, n) {
649
+ let r = W(e), i = r[t].indexOf(Math.round(Number(n)));
650
+ return i === -1 ? !1 : (r[t].splice(i, 1), !0);
651
+ }
652
+ function xe(e, t, n, r) {
653
+ return be(e, t, n), ye(e, t, r);
654
+ }
655
+ function Se(e, t, n, r = 4) {
656
+ let i = null;
657
+ for (let a of U(e)[t]) {
658
+ let e = Math.abs(a - n);
659
+ e <= r && (i === null || e < Math.abs(i - n)) && (i = a);
660
+ }
661
+ return i;
662
+ }
663
+ function Ce(e, t) {
664
+ let n = U(e);
665
+ return t ? {
666
+ x: n.x,
667
+ y: n.y.map((e) => e - (t.originY ?? 0)).filter((e) => e >= 0 && e <= (t.h ?? 0))
668
+ } : {
669
+ x: n.x,
670
+ y: []
671
+ };
672
+ }
673
+ //#endregion
674
+ //#region src/designer/canvas.js
675
+ var we = [
676
+ "pageHeader",
677
+ "reportHeader",
678
+ "reportFooter",
679
+ "pageFooter"
680
+ ];
681
+ function Te(e) {
682
+ return Array.from({ length: de }, () => Object.fromEntries((e || []).map((e) => [e.field, e.field])));
683
+ }
684
+ function G(t) {
685
+ return t.type === "text" ? {
686
+ ...t,
687
+ text: t.value
688
+ } : t.type === "table" ? {
689
+ ...t,
690
+ row: Te(t.columns),
691
+ measuredHeight: e(t)
692
+ } : t;
693
+ }
694
+ function K(e) {
695
+ let { page: t } = e, n = t.height - t.margin.top - t.margin.bottom, r = Object.fromEntries((e.bands || []).map((e) => [e.type, e])), i = a({
696
+ bands: r,
697
+ contentHeight: n,
698
+ isFirstPage: !0,
699
+ isLastPage: !0
700
+ }), o = [];
701
+ for (let e of we) {
702
+ let t = i[e];
703
+ t && r[e] && o.push({
704
+ type: e,
705
+ ...t,
706
+ band: r[e]
707
+ });
708
+ }
709
+ let s = i.detail, c = r.groupHeader, l = r.groupFooter, u = c ? b(c, n) : 0, d = l ? b(l, n) : 0;
710
+ return c && o.push({
711
+ type: "groupHeader",
712
+ top: s.top,
713
+ height: u,
714
+ band: c
715
+ }), r.detail && o.push({
716
+ type: "detail",
717
+ top: s.top + u,
718
+ height: Math.max(s.height - u - d, 0),
719
+ band: r.detail
720
+ }), l && o.push({
721
+ type: "groupFooter",
722
+ top: s.top + s.height - d,
723
+ height: d,
724
+ band: l
725
+ }), o;
726
+ }
727
+ function Ee(e, t) {
728
+ let n = [...e.band.items || []].sort((e, t) => (e.y ?? 0) - (t.y ?? 0)).map(G);
729
+ return `
730
+ <div class="band dz-zone" data-band-type="${v(e.type)}"
731
+ style="position:absolute;top:${e.top + t.top}px;left:${t.left}px;right:${t.right}px;height:${e.height}px">
732
+ ${u(n)}
733
+ </div>`;
734
+ }
735
+ function q(e, t) {
736
+ U(e);
737
+ let n = (e, t) => _e(e).map((e) => `
738
+ <span class="dz-tick${e.major ? " is-major" : ""}"
739
+ style="${t === "x" ? "left" : "top"}:${e.at}px"
740
+ >${e.major ? `<i>${e.at}</i>` : ""}</span>`).join(""), r = (t) => `
741
+ <span class="dz-ruler-guides" data-role="ruler-guides"
742
+ data-axis="${t}">${De(e, t)}</span>`;
743
+ return `
744
+ <div class="dz-ruler-corner" data-role="ruler-corner"></div>
745
+
746
+ <div class="dz-ruler dz-ruler-x" data-role="ruler" data-axis="x"
747
+ style="width:${t.w}px" aria-hidden="true">
748
+ ${n(t.w, "x")}${r("x")}
749
+ </div>
750
+
751
+ <div class="dz-ruler dz-ruler-y" data-role="ruler" data-axis="y"
752
+ style="height:${t.h}px" aria-hidden="true">
753
+ ${n(t.h, "y")}${r("y")}
754
+ </div>`;
755
+ }
756
+ function De(e, t) {
757
+ return U(e)[t].map((e) => `
758
+ <span class="dz-ruler-guide"
759
+ style="${t === "x" ? "left" : "top"}:${e}px"></span>`).join("");
760
+ }
761
+ function Oe(e) {
762
+ let t = e.page.margin, n = U(e), r = n.x.map((e) => `
763
+ <span class="dz-rule dz-rule-v" data-role="guide" data-axis="x"
764
+ data-at="${e}" style="left:${e + t.left}px"></span>`), i = n.y.map((e) => `
765
+ <span class="dz-rule dz-rule-h" data-role="guide" data-axis="y"
766
+ data-at="${e}" style="top:${e + t.top}px"></span>`);
767
+ return [...r, ...i].join("");
768
+ }
769
+ function ke(e, t) {
770
+ return `<span class="dz-tag" data-band-tag="${v(e.type)}"
771
+ style="top:${e.top + t.top}px">${v(e.type)}</span>`;
772
+ }
773
+ function Ae(e, t) {
774
+ if (!t) return null;
775
+ let n = e.page.margin, r = K(e).find((e) => e.type === t.band);
776
+ if (!r) return null;
777
+ let i = (r.band.items || []).find((e) => e.id === t.id);
778
+ if (!i) return null;
779
+ let a = z(i);
780
+ return {
781
+ item: i,
782
+ box: {
783
+ ...a,
784
+ x: a.x + n.left,
785
+ y: a.y + r.top + n.top
786
+ }
787
+ };
788
+ }
789
+ function J(e, { withHandles: t = !0, primary: n = !0 } = {}) {
790
+ let { box: r, item: i } = e, a = t ? V(B(i)).map((e) => `<span class="dz-handle dz-handle-${e}" data-handle="${e}"></span>`).join("") : "";
791
+ return `
792
+ <div class="dz-select${n ? "" : " is-secondary"}" data-role="select"
793
+ data-select-id="${v(i.id)}"
794
+ style="top:${r.y}px;left:${r.x}px;width:${r.w}px;height:${r.h}px">
795
+ ${a}
796
+ </div>`;
797
+ }
798
+ function je(e, t) {
799
+ return (t || []).map((t) => Ae(e, t)).filter(Boolean);
800
+ }
801
+ function Me(e, t = null, { rulers: n = !1 } = {}) {
802
+ let { page: r } = e, i = r.margin, a = K(e), o = je(e, t == null ? [] : [].concat(t)), s = `width:${r.width}px;height:${r.height}px;padding-top:${i.top}px;padding-right:${i.right}px;padding-bottom:${i.bottom}px;padding-left:${i.left}px;`, c = {
803
+ w: r.width - i.left - i.right,
804
+ h: r.height - i.top - i.bottom
805
+ };
806
+ return `
807
+ <div class="dz-sheet${n ? " has-rulers" : ""}"
808
+ style="--page-height:${r.height}px;--dz-margin-left:${i.left}px;
809
+ --dz-margin-top:${i.top}px">
810
+ ${n ? q(e, c) : ""}
811
+ <div class="dz-gutter">
812
+ ${a.map((e) => ke(e, i)).join("")}
813
+ </div>
814
+ <div class="page dz-page" style="${s}">
815
+ <div class="dz-rules" data-role="rules"
816
+ >${n ? Oe(e) : ""}</div>
817
+ ${a.map((e) => Ee(e, i)).join("")}
818
+ ${o.map((e, t) => J(e, {
819
+ withHandles: o.length === 1,
820
+ primary: t === o.length - 1
821
+ })).join("")}
822
+ <div class="dz-guides" data-role="guides"></div>
823
+ </div>
824
+ </div>`;
825
+ }
826
+ function Ne(e, t) {
827
+ let n = K(e).find((e) => e.type === t);
828
+ if (!n) return null;
829
+ let r = e.page.margin;
830
+ return {
831
+ left: r.left,
832
+ top: n.top + r.top,
833
+ w: e.page.width - r.left - r.right,
834
+ h: n.height,
835
+ originX: 0,
836
+ originY: n.top
837
+ };
838
+ }
839
+ function Pe(e, t = [], n = []) {
840
+ if (!e) return "";
841
+ let r = (t) => t + e.left, i = (t) => t + e.top, a = t.map((e) => e.axis === "x" ? `<span class="dz-guide dz-guide-v${e.centre ? " is-centre" : ""}"
842
+ style="left:${r(e.at)}px;top:${i(e.from)}px;
843
+ height:${Math.max(e.to - e.from, 0)}px"></span>` : `<span class="dz-guide dz-guide-h${e.centre ? " is-centre" : ""}"
844
+ style="top:${i(e.at)}px;left:${r(e.from)}px;
845
+ width:${Math.max(e.to - e.from, 0)}px"></span>`), o = n.map((e) => {
846
+ let t = Math.max(e.to - e.from, 0), n = `<i>${Math.round(e.distance)}</i>`, a = e.toBand ? " is-band" : "";
847
+ return e.axis === "y" ? `<span class="dz-gap dz-gap-v${a}"
848
+ style="left:${r(e.at)}px;top:${i(e.from)}px;
849
+ height:${t}px">${n}</span>` : `<span class="dz-gap dz-gap-h${a}"
850
+ style="top:${i(e.at)}px;left:${r(e.from)}px;
851
+ width:${t}px">${n}</span>`;
852
+ });
853
+ return [...a, ...o].join("");
854
+ }
855
+ function Fe(e, t, n) {
856
+ let r = K(e).find((e) => e.type === t);
857
+ return r ? r.top + n : null;
858
+ }
859
+ function Ie(e, t) {
860
+ let n = K(e);
861
+ if (!n.length) return null;
862
+ let r = [...n].sort((e, t) => e.top - t.top);
863
+ for (let e of r) if (t >= e.top && t < e.top + e.height) return e.type;
864
+ return t < r[0].top ? r[0].type : r.at(-1).type;
865
+ }
866
+ function Le(e, t, n) {
867
+ let r = Fe(e, t, n?.y ?? 0);
868
+ return r === null ? null : Ie(e, r);
869
+ }
870
+ var Re = .01;
871
+ function ze(e) {
872
+ return [
873
+ {
874
+ at: e.x,
875
+ centre: !1
876
+ },
877
+ {
878
+ at: e.x + (e.w ?? 0) / 2,
879
+ centre: !0
880
+ },
881
+ {
882
+ at: e.x + (e.w ?? 0),
883
+ centre: !1
884
+ }
885
+ ];
886
+ }
887
+ function Be(e) {
888
+ return [
889
+ {
890
+ at: e.y,
891
+ centre: !1
892
+ },
893
+ {
894
+ at: e.y + (e.h ?? 0) / 2,
895
+ centre: !0
896
+ },
897
+ {
898
+ at: e.y + (e.h ?? 0),
899
+ centre: !1
900
+ }
901
+ ];
902
+ }
903
+ function Ve(e) {
904
+ if (!e?.length) return null;
905
+ let t = Math.min(...e.map((e) => e.x)), n = Math.min(...e.map((e) => e.y)), r = Math.max(...e.map((e) => e.x + (e.w ?? 0))), i = Math.max(...e.map((e) => e.y + (e.h ?? 0)));
906
+ return {
907
+ x: t,
908
+ y: n,
909
+ w: r - t,
910
+ h: i - n
911
+ };
912
+ }
913
+ function He(e, t, n, r = []) {
914
+ let i = n === "x" ? ze : Be, a = (r || []).filter(Number.isFinite).map((e) => ({
915
+ at: e,
916
+ centre: !1,
917
+ box: null
918
+ })), o = (e || []).flatMap((e) => i(e).map((t) => ({
919
+ ...t,
920
+ box: e
921
+ }))), s = n === "x" ? t?.w ?? 0 : t?.h ?? 0, c = t ? i({
922
+ x: 0,
923
+ y: 0,
924
+ w: s,
925
+ h: s
926
+ }).map((e) => ({
927
+ ...e,
928
+ box: null
929
+ })) : [];
930
+ return [
931
+ ...a,
932
+ ...o,
933
+ ...c
934
+ ];
935
+ }
936
+ function Y(e, t, n = 6) {
937
+ let r = null;
938
+ for (let i of e) for (let e of t) {
939
+ let t = e.at - i.at;
940
+ Math.abs(t) > n || (!r || Math.abs(t) < Math.abs(r.delta) - Re) && (r = {
941
+ delta: t,
942
+ at: e.at
943
+ });
944
+ }
945
+ return r;
946
+ }
947
+ function Ue(e, t, n, r, i) {
948
+ let a = t.filter((e) => Math.abs(e.at - n) < Re);
949
+ if (!a.length) return [];
950
+ let o = a.some((e) => e.box === null), s = a.map((e) => e.box).filter(Boolean), c = r === "x" ? (e) => [e.y, e.y + (e.h ?? 0)] : (e) => [e.x, e.x + (e.w ?? 0)], l = r === "x" ? i?.h ?? 0 : i?.w ?? 0, u = [...c(e), ...s.flatMap(c)];
951
+ return [{
952
+ axis: r,
953
+ at: n,
954
+ from: o ? 0 : Math.min(...u),
955
+ to: o ? l : Math.max(...u),
956
+ centre: a.every((e) => e.centre)
957
+ }];
958
+ }
959
+ function We(e, t, n, { snap: r = 6, guides: i } = {}) {
960
+ if (!e) return {
961
+ dx: 0,
962
+ dy: 0,
963
+ lines: []
964
+ };
965
+ let a = He(t, n, "x", i?.x), o = He(t, n, "y", i?.y), s = Y(ze(e), a, r), c = Y(Be(e), o, r), l = s?.delta ?? 0, u = c?.delta ?? 0, d = {
966
+ ...e,
967
+ x: e.x + l,
968
+ y: e.y + u
969
+ };
970
+ return {
971
+ dx: l,
972
+ dy: u,
973
+ lines: [...s ? Ue(d, a, s.at, "x", n) : [], ...c ? Ue(d, o, c.at, "y", n) : []]
974
+ };
975
+ }
976
+ function Ge(e, t, n) {
977
+ let [r, i] = n === "x" ? ["x", "w"] : ["y", "h"];
978
+ return e[r] < t[r] + (t[i] ?? 0) && e[r] + (e[i] ?? 0) > t[r];
979
+ }
980
+ function Ke(e, t, n, r) {
981
+ let i = r === "up" || r === "down", a = i ? "y" : "x", o = i ? "x" : "y", [s, c] = i ? ["y", "h"] : ["x", "w"], l = e[s], u = e[s] + (e[c] ?? 0), d = r === "up" || r === "left", f = (t || []).filter((t) => Ge(e, t, o) ? d ? t[s] + (t[c] ?? 0) <= l : t[s] >= u : !1), p = i ? n?.h ?? 0 : n?.w ?? 0, m = f.length ? d ? Math.max(...f.map((e) => e[s] + (e[c] ?? 0))) : Math.min(...f.map((e) => e[s])) : d ? 0 : p, h = d ? l - m : m - u;
982
+ if (!(h >= 0)) return null;
983
+ let g = f.find((e) => Math.abs((d ? e[s] + (e[c] ?? 0) : e[s]) - m) < Re), _ = g ? [Math.max(e[o], g[o]), Math.min(e[o] + (e[i ? "w" : "h"] ?? 0), g[o] + (g[i ? "w" : "h"] ?? 0))] : [e[o], e[o] + (e[i ? "w" : "h"] ?? 0)];
984
+ return {
985
+ side: r,
986
+ axis: a,
987
+ at: (_[0] + _[1]) / 2,
988
+ from: d ? m : u,
989
+ to: d ? l : m,
990
+ distance: h,
991
+ toBand: f.length === 0
992
+ };
993
+ }
994
+ function qe(e, t, n) {
995
+ return e ? [
996
+ "up",
997
+ "down",
998
+ "left",
999
+ "right"
1000
+ ].map((r) => Ke(e, t, n, r)).filter(Boolean) : [];
1001
+ }
1002
+ function Je(e, t, n, r = {}) {
1003
+ let i = Ve(e);
1004
+ if (!i) return {
1005
+ dx: 0,
1006
+ dy: 0,
1007
+ lines: [],
1008
+ gaps: []
1009
+ };
1010
+ let { dx: a, dy: o, lines: s } = We(i, t, n, r);
1011
+ return {
1012
+ dx: a,
1013
+ dy: o,
1014
+ lines: s,
1015
+ gaps: qe({
1016
+ ...i,
1017
+ x: i.x + a,
1018
+ y: i.y + o
1019
+ }, t, n)
1020
+ };
1021
+ }
1022
+ //#endregion
1023
+ //#region src/designer/select.js
1024
+ function Ye({ canvas: e, getLayout: t, getSelection: n, select: r, commit: i, remove: a = () => {}, duplicate: o = () => !1, getZoom: s = () => 1, enabled: c = () => !0, onTarget: l = () => {}, onGuides: u = () => {}, rulers: d = () => !1 }) {
1025
+ let f = null, p = 0, m = !1, h = e.ownerDocument;
1026
+ function g(t) {
1027
+ let n = e.querySelector(".dz-page");
1028
+ if (!n) return null;
1029
+ let r = n.getBoundingClientRect(), i = s() || 1, a = h.defaultView?.getComputedStyle(n);
1030
+ return {
1031
+ x: (t.clientX - r.left) / i - parseFloat(a?.paddingLeft || 0),
1032
+ y: (t.clientY - r.top) / i - parseFloat(a?.paddingTop || 0)
1033
+ };
1034
+ }
1035
+ function _(e) {
1036
+ return e?.closest("[data-band-type]")?.dataset.bandType ?? null;
1037
+ }
1038
+ function ee(e) {
1039
+ let t = e?.closest("[data-item-id]");
1040
+ if (!t) return null;
1041
+ let n = _(t);
1042
+ return n ? {
1043
+ band: n,
1044
+ id: t.dataset.itemId,
1045
+ node: t
1046
+ } : null;
1047
+ }
1048
+ function v(e) {
1049
+ return e ? ((t().bands || []).find((t) => t.type === e.band)?.items || []).find((t) => t.id === e.id) ?? null : null;
1050
+ }
1051
+ function y(e, n) {
1052
+ let r = (t().bands || []).find((t) => t.type === e), i = new Set(n.map((e) => e.where.id));
1053
+ return (r?.items || []).filter((e) => !i.has(e.id)).map(z);
1054
+ }
1055
+ function b() {
1056
+ return (n() || []).map((e) => ({
1057
+ where: e,
1058
+ item: v(e)
1059
+ })).filter((e) => e.item);
1060
+ }
1061
+ function x() {
1062
+ return b().at(-1) ?? null;
1063
+ }
1064
+ function S(e) {
1065
+ if (!c() || e.button !== 0 || d() && te(e)) return;
1066
+ let t = e.target.closest?.("[data-handle]");
1067
+ if (t) {
1068
+ let n = x();
1069
+ if (!n) return;
1070
+ w(e, {
1071
+ mode: "resize",
1072
+ handle: t.dataset.handle,
1073
+ item: n.item
1074
+ });
1075
+ return;
1076
+ }
1077
+ let i = ee(e.target);
1078
+ if (!i) {
1079
+ r(null);
1080
+ return;
1081
+ }
1082
+ let a = {
1083
+ band: i.band,
1084
+ id: i.id
1085
+ }, s = (n() || []).some((e) => e.band === a.band && e.id === a.id);
1086
+ if (e.shiftKey) {
1087
+ r(a, { add: !0 });
1088
+ return;
1089
+ }
1090
+ if (e.altKey && (s || r(a), o())) {
1091
+ w(e, {
1092
+ mode: "move",
1093
+ collapseTo: null
1094
+ });
1095
+ return;
1096
+ }
1097
+ s || r(a), w(e, {
1098
+ mode: "move",
1099
+ collapseTo: s ? a : null
1100
+ });
1101
+ }
1102
+ function te(e) {
1103
+ let n = e.target.closest?.("[data-role=\"ruler\"]"), r = g(e);
1104
+ if (!r) return !1;
1105
+ if (n) {
1106
+ let a = n.dataset.axis, o = ye(t(), a, r[a]);
1107
+ return o === null ? !1 : (f = {
1108
+ mode: "guide",
1109
+ axis: a,
1110
+ at: o,
1111
+ created: !0,
1112
+ moved: !1,
1113
+ key: `guide:${++p}`
1114
+ }, C(e), i({
1115
+ live: !0,
1116
+ key: f.key
1117
+ }), !0);
1118
+ }
1119
+ if (!e.target.closest?.(".dz-page")) return !1;
1120
+ for (let n of ["x", "y"]) {
1121
+ let i = Se(t(), n, r[n]);
1122
+ if (i !== null) return f = {
1123
+ mode: "guide",
1124
+ axis: n,
1125
+ at: i,
1126
+ created: !1,
1127
+ moved: !1,
1128
+ key: `guide:${++p}`
1129
+ }, C(e), !0;
1130
+ }
1131
+ return !1;
1132
+ }
1133
+ function C(t) {
1134
+ e.setPointerCapture?.(t.pointerId), e.classList.add("is-dragging"), t.preventDefault();
1135
+ }
1136
+ function w(e, t) {
1137
+ let n = t.mode === "move" ? b().map((e) => ({
1138
+ ...e,
1139
+ box: z(e.item)
1140
+ })) : [];
1141
+ f = {
1142
+ ...t,
1143
+ group: n,
1144
+ band: x()?.where.band ?? null,
1145
+ target: null,
1146
+ startX: e.clientX,
1147
+ startY: e.clientY,
1148
+ box: t.item ? z(t.item) : null,
1149
+ moved: !1
1150
+ }, C(e);
1151
+ }
1152
+ function T(e) {
1153
+ if (!f) return;
1154
+ if (f.mode === "guide") {
1155
+ let n = g(e);
1156
+ if (!n) return;
1157
+ f.moved = !0, f.at = xe(t(), f.axis, f.at, n[f.axis]), i({
1158
+ live: !0,
1159
+ key: f.key
1160
+ });
1161
+ return;
1162
+ }
1163
+ let n = s() || 1, r = (e.clientX - f.startX) / n, a = (e.clientY - f.startY) / n;
1164
+ if (k(e.altKey), !f.moved && Math.abs(r) < 1 && Math.abs(a) < 1) return;
1165
+ if (f.moved = !0, f.mode === "resize") {
1166
+ ge(f.item, he(f.handle, f.box, r, a, B(f.item))), i({ live: !0 });
1167
+ return;
1168
+ }
1169
+ for (let e of f.group) ge(e.item, {
1170
+ ...e.box,
1171
+ ...H(e.box, r, a)
1172
+ });
1173
+ E(f.group);
1174
+ let o = t(), c = /* @__PURE__ */ new Set();
1175
+ for (let e of f.group) {
1176
+ let t = Le(o, e.where.band, e.item);
1177
+ t && t !== e.where.band && c.add(t);
1178
+ }
1179
+ f.target = c.size ? [...c] : null, l(f.target), i({ live: !0 });
1180
+ }
1181
+ function E(e) {
1182
+ let n = f?.band ? Ne(t(), f.band) : null;
1183
+ if (!n || !e.length) {
1184
+ u(null);
1185
+ return;
1186
+ }
1187
+ let r = y(f.band, e), i = Je(e.map((e) => z(e.item)), r, n, { guides: d() ? Ce(t(), n) : void 0 });
1188
+ if (i.dx || i.dy) for (let t of e) ge(t.item, {
1189
+ ...z(t.item),
1190
+ x: (t.item.x ?? 0) + i.dx,
1191
+ y: (t.item.y ?? 0) + i.dy
1192
+ });
1193
+ u({
1194
+ band: f.band,
1195
+ lines: i.lines,
1196
+ gaps: m ? i.gaps : []
1197
+ });
1198
+ }
1199
+ function D() {
1200
+ let e = b(), n = e.at(-1)?.where ?? null, r = n ? Ne(t(), n.band) : null;
1201
+ if (!r || !e.length) {
1202
+ u(null);
1203
+ return;
1204
+ }
1205
+ let i = e.map((e) => z(e.item));
1206
+ u({
1207
+ band: n.band,
1208
+ lines: [],
1209
+ gaps: qe(Ve(i), y(n.band, e), r)
1210
+ });
1211
+ }
1212
+ function O() {
1213
+ if (f?.mode === "move") {
1214
+ E(f.group);
1215
+ return;
1216
+ }
1217
+ if (m) {
1218
+ D();
1219
+ return;
1220
+ }
1221
+ u(null);
1222
+ }
1223
+ function k(e) {
1224
+ return e === m ? !1 : (m = e, !0);
1225
+ }
1226
+ function A(n) {
1227
+ if (!f) return;
1228
+ if (e.releasePointerCapture?.(n.pointerId), e.classList.remove("is-dragging"), f.mode === "guide") {
1229
+ let { axis: e, at: n, key: r } = f;
1230
+ f = null;
1231
+ let a = ne(e);
1232
+ (n === null || n < 0 || a !== null && n > a) && be(t(), e, n), i({
1233
+ live: !1,
1234
+ key: r
1235
+ });
1236
+ return;
1237
+ }
1238
+ let a = f.moved, o = f.target, s = f.collapseTo;
1239
+ f = null, l(null), k(n.altKey), a ? i({
1240
+ live: !1,
1241
+ band: o
1242
+ }) : s && r(s), O();
1243
+ }
1244
+ function ne(e) {
1245
+ let n = t()?.page;
1246
+ return n?.margin ? e === "x" ? n.width - n.margin.left - n.margin.right : n.height - n.margin.top - n.margin.bottom : null;
1247
+ }
1248
+ function j(e) {
1249
+ if (!c() || e.target.closest?.("input, textarea, select")) return;
1250
+ if (e.key === "Alt") {
1251
+ k(!0) && O(), e.preventDefault();
1252
+ return;
1253
+ }
1254
+ if (e.key === "Escape") {
1255
+ r(null);
1256
+ return;
1257
+ }
1258
+ if (e.key === "Delete" || e.key === "Backspace") {
1259
+ if (!b().length) return;
1260
+ e.preventDefault(), a();
1261
+ return;
1262
+ }
1263
+ let t = {
1264
+ ArrowLeft: [-1, 0],
1265
+ ArrowRight: [1, 0],
1266
+ ArrowUp: [0, -1],
1267
+ ArrowDown: [0, 1]
1268
+ }[e.key];
1269
+ if (!t) return;
1270
+ let n = b();
1271
+ if (!n.length) return;
1272
+ let o = e.shiftKey ? 10 : 1;
1273
+ for (let { item: e } of n) e.x = (e.x ?? 0) + t[0] * o, e.y = (e.y ?? 0) + t[1] * o;
1274
+ e.preventDefault(), i({ live: !1 });
1275
+ }
1276
+ function M(e) {
1277
+ e.key === "Alt" && k(!1) && O();
1278
+ }
1279
+ function N() {
1280
+ k(!1) && O();
1281
+ }
1282
+ return e.addEventListener("pointerdown", S), e.addEventListener("pointermove", T), e.addEventListener("pointerup", A), e.addEventListener("pointercancel", A), h.addEventListener("keydown", j), h.addEventListener("keyup", M), h.defaultView?.addEventListener("blur", N), function() {
1283
+ e.removeEventListener("pointerdown", S), e.removeEventListener("pointermove", T), e.removeEventListener("pointerup", A), e.removeEventListener("pointercancel", A), h.removeEventListener("keydown", j), h.removeEventListener("keyup", M), h.defaultView?.removeEventListener("blur", N);
1284
+ };
1285
+ }
1286
+ //#endregion
1287
+ //#region src/designer/structure.js
1288
+ var Xe = [
1289
+ "pageHeader",
1290
+ "reportHeader",
1291
+ "groupHeader",
1292
+ "detail",
1293
+ "groupFooter",
1294
+ "reportFooter",
1295
+ "pageFooter"
1296
+ ], Ze = {
1297
+ pageHeader: 40,
1298
+ reportHeader: 80,
1299
+ groupHeader: 36,
1300
+ groupFooter: 36,
1301
+ reportFooter: 60,
1302
+ pageFooter: 40
1303
+ }, Qe = {
1304
+ reportHeader: "First page only",
1305
+ pageHeader: "Every page",
1306
+ groupHeader: "Before each group",
1307
+ detail: "The rows",
1308
+ groupFooter: "After each group",
1309
+ reportFooter: "Last page only",
1310
+ pageFooter: "Every page"
1311
+ };
1312
+ function $e(e) {
1313
+ return Array.isArray(e?.bands) ? e.bands : [];
1314
+ }
1315
+ function et(e) {
1316
+ return $e(e).flatMap((e) => e.items || []).filter((e) => e?.type === "table").length;
1317
+ }
1318
+ function tt(e) {
1319
+ return Array.isArray(e?.bands);
1320
+ }
1321
+ function nt(e) {
1322
+ let t = et(e);
1323
+ if (t === 0) return e.dataset ?? null;
1324
+ let n = e.dataset || "rows", r = new Set($e(e).flatMap((e) => e.items || []).filter((e) => e?.type === "table").map((t) => t.dataset ?? e.dataset));
1325
+ for (let e = t + 1;; e++) if (!r.has(`${n}${e}`)) return `${n}${e}`;
1326
+ }
1327
+ function rt(e, t) {
1328
+ e.y = ct(t), delete e.groupBy;
1329
+ }
1330
+ function X(e, t) {
1331
+ return $e(e).find((e) => e.type === t) ?? null;
1332
+ }
1333
+ function it(e, t) {
1334
+ return X(e, t) != null;
1335
+ }
1336
+ function at(e, t) {
1337
+ if (!Xe.includes(t) || it(e, t)) return null;
1338
+ let n = {
1339
+ type: t,
1340
+ items: []
1341
+ };
1342
+ Ze[t] != null && (n.height = Ze[t]), Array.isArray(e.bands) || (e.bands = []);
1343
+ let r = (e) => Xe.indexOf(e), i = e.bands.findIndex((e) => r(e.type) > r(t));
1344
+ return i === -1 ? e.bands.push(n) : e.bands.splice(i, 0, n), n;
1345
+ }
1346
+ function ot(e, t) {
1347
+ let n = $e(e).findIndex((e) => e.type === t);
1348
+ return n === -1 ? !1 : (e.bands.splice(n, 1), !0);
1349
+ }
1350
+ function st(e) {
1351
+ return new Set($e(e).flatMap((e) => (e.items || []).map((e) => e.id)));
1352
+ }
1353
+ function Z(e, t) {
1354
+ let n = st(e);
1355
+ for (let e = 1;; e++) {
1356
+ let r = `${t}-${e}`;
1357
+ if (!n.has(r)) return r;
1358
+ }
1359
+ }
1360
+ function ct(t) {
1361
+ let n = t.items || [];
1362
+ if (!n.length) return 0;
1363
+ let r = Math.max(...n.map((t) => (t.y ?? 0) + e(t)));
1364
+ return Math.ceil(r / 10) * 10;
1365
+ }
1366
+ function lt(e) {
1367
+ let { page: t } = e;
1368
+ return t.width - t.margin.left - t.margin.right;
1369
+ }
1370
+ function ut(e, t) {
1371
+ return {
1372
+ id: Z(e, "text"),
1373
+ type: "text",
1374
+ x: 0,
1375
+ y: ct(t),
1376
+ w: 200,
1377
+ h: 20,
1378
+ value: "Text",
1379
+ style: {
1380
+ fontFamily: x[0].value,
1381
+ fontSize: 12,
1382
+ fontWeight: "normal",
1383
+ fontStyle: "normal",
1384
+ color: "#000000",
1385
+ align: "left",
1386
+ background: null,
1387
+ border: null,
1388
+ padding: 0
1389
+ }
1390
+ };
1391
+ }
1392
+ function dt(e, t, n = "horizontal") {
1393
+ let r = n === "vertical";
1394
+ return {
1395
+ id: Z(e, "line"),
1396
+ type: "line",
1397
+ x: 0,
1398
+ y: ct(t),
1399
+ w: r ? 12 : lt(e),
1400
+ h: r ? 80 : 12,
1401
+ orientation: r ? "vertical" : "horizontal",
1402
+ style: {
1403
+ thickness: 1,
1404
+ lineStyle: "solid",
1405
+ color: "#000000"
1406
+ }
1407
+ };
1408
+ }
1409
+ function ft(e, t) {
1410
+ return {
1411
+ id: Z(e, "box"),
1412
+ type: "box",
1413
+ x: 0,
1414
+ y: ct(t),
1415
+ w: lt(e),
1416
+ h: 80,
1417
+ style: {
1418
+ borderStyle: "solid",
1419
+ borderWidth: 1,
1420
+ borderColor: "#000000",
1421
+ background: null,
1422
+ radius: 0
1423
+ }
1424
+ };
1425
+ }
1426
+ function pt(e, t) {
1427
+ return {
1428
+ id: Z(e, "image"),
1429
+ type: "image",
1430
+ x: 0,
1431
+ y: ct(t),
1432
+ w: 160,
1433
+ h: 80,
1434
+ src: null,
1435
+ field: null,
1436
+ fit: "contain",
1437
+ alt: ""
1438
+ };
1439
+ }
1440
+ function mt(e) {
1441
+ return {
1442
+ field: `field${e}`,
1443
+ label: `Column ${e}`,
1444
+ width: 50,
1445
+ align: "left"
1446
+ };
1447
+ }
1448
+ function ht(e, t, n = 3) {
1449
+ let r = Math.max(1, Math.floor(Number(n) || 3));
1450
+ return {
1451
+ id: Z(e, "table"),
1452
+ type: "table",
1453
+ x: 0,
1454
+ y: ct(t),
1455
+ w: lt(e),
1456
+ dataset: nt(e),
1457
+ rowHeight: 24,
1458
+ headerHeight: 28,
1459
+ showHeader: !0,
1460
+ wrap: !0,
1461
+ columns: Array.from({ length: r }, (e, t) => mt(t + 1)),
1462
+ style: {
1463
+ fontFamily: "Helvetica, Arial, sans-serif",
1464
+ fontSize: 12,
1465
+ color: "#000000",
1466
+ borderStyle: "solid",
1467
+ borderWidth: 1,
1468
+ borderColor: "#cccccc"
1469
+ }
1470
+ };
1471
+ }
1472
+ function gt(e, t, n) {
1473
+ let r = X(e, t);
1474
+ return r ? (r.items ??= [], r.items.push(n), n) : null;
1475
+ }
1476
+ var _t = 10;
1477
+ function vt(e) {
1478
+ return String(e.id ?? "").replace(/-\d+$/, "") || e.type || "item";
1479
+ }
1480
+ function yt(e, t, n) {
1481
+ if (!Number.isFinite(e?.page?.width)) return Math.max(0, t);
1482
+ let r = Math.max(0, lt(e) - (n ?? 0));
1483
+ return Math.min(Math.max(0, t), r);
1484
+ }
1485
+ function bt(e, t, n) {
1486
+ let r = X(e, t);
1487
+ if (!r) return null;
1488
+ let i = (r.items || []).find((e) => e.id === n);
1489
+ if (!i || i.type === "table" && !tt(e)) return null;
1490
+ let a = structuredClone(i);
1491
+ return a.id = Z(e, vt(i)), a.x = yt(e, (i.x ?? 0) + _t, a.w), a.y = Math.max(0, (i.y ?? 0) + _t), a.type === "table" && rt(a, r), r.items ??= [], r.items.push(a), a;
1492
+ }
1493
+ function xt(e, t) {
1494
+ return Number.isFinite(e?.page?.height) ? K(e).find((e) => e.type === t)?.height ?? null : null;
1495
+ }
1496
+ function St(t, n, r, i) {
1497
+ let a = xt(t, n);
1498
+ if (a == null) return Math.max(0, r);
1499
+ let o = Math.max(0, a - e(i));
1500
+ return Math.min(Math.max(0, r), o);
1501
+ }
1502
+ function Ct(e, t, n) {
1503
+ let r = X(e, t);
1504
+ if (!r) return [];
1505
+ r.items ??= [];
1506
+ let i = [];
1507
+ for (let { band: a, item: o } of n || []) {
1508
+ if (!o || o.type === "table" && !tt(e)) continue;
1509
+ let n = structuredClone(o), s = Math.max(0, (o.y ?? 0) + _t);
1510
+ n.id = Z(e, vt(o)), n.x = yt(e, (o.x ?? 0) + _t, n.w), n.y = a === t ? s : St(e, t, s, n), n.type === "table" && rt(n, r), r.items.push(n), i.push(n);
1511
+ }
1512
+ return i;
1513
+ }
1514
+ function wt(e, t, n) {
1515
+ let r = X(e, t);
1516
+ if (!r) return !1;
1517
+ let i = (r.items || []).findIndex((e) => e.id === n);
1518
+ return i === -1 ? !1 : (r.items.splice(i, 1), !0);
1519
+ }
1520
+ function Tt(e, t, n, r) {
1521
+ if (t === n) return !1;
1522
+ let i = X(e, t), a = X(e, n);
1523
+ if (!i || !a) return !1;
1524
+ let o = (i.items || []).find((e) => e.id === r);
1525
+ if (!o) return !1;
1526
+ let s = Fe(e, t, o.y ?? 0);
1527
+ wt(e, t, r), gt(e, n, o);
1528
+ let c = Fe(e, n, 0);
1529
+ return s !== null && c !== null && (o.y = Math.round(s - c)), !0;
1530
+ }
1531
+ function Et(e) {
1532
+ e.columns ??= [];
1533
+ let t = mt(e.columns.length + 1);
1534
+ return e.columns.push(t), t;
1535
+ }
1536
+ function Dt(e, t) {
1537
+ return !Array.isArray(e.columns) || e.columns.length <= 1 || t < 0 || t >= e.columns.length ? !1 : (e.columns.splice(t, 1), !0);
1538
+ }
1539
+ function Ot(e, t) {
1540
+ return t && it(e, t.band) ? t.band : it(e, "detail") ? "detail" : $e(e)[0]?.type ?? null;
1541
+ }
1542
+ //#endregion
1543
+ //#region src/designer/panel.js
1544
+ function kt(e) {
1545
+ return `
1546
+ <div class="dz-panel-head">
1547
+ <span class="dz-panel-type">${v(e.type)}</span>
1548
+ <span class="dz-panel-id">${v(e.id)}</span>
1549
+ </div>
1550
+ ${Mt(e, ne(e))}
1551
+ ${e.type === "table" ? Ft(e) : ""}`;
1552
+ }
1553
+ function At(e) {
1554
+ return `
1555
+ <div class="dz-panel-head">
1556
+ <span class="dz-panel-type">${e.length} items</span>
1557
+ </div>
1558
+
1559
+ <section class="dz-section">
1560
+ <ul class="dz-selected">
1561
+ ${e.map((e) => `
1562
+ <li>
1563
+ <span class="dz-selected-type">${v(e.type)}</span>
1564
+ <span class="dz-selected-id">${v(e.id)}</span>
1565
+ </li>`).join("")}
1566
+ </ul>
1567
+
1568
+ <p class="dz-hint">
1569
+ Drag to move them together, or use the arrow keys.
1570
+ Select one on its own to change its properties.
1571
+ </p>
1572
+ </section>`;
1573
+ }
1574
+ function jt(e) {
1575
+ return `
1576
+ <div class="dz-panel-head">
1577
+ <span class="dz-panel-type">report</span>
1578
+ <span class="dz-panel-id">${v(e.name ?? "Untitled")}</span>
1579
+ </div>
1580
+ ${Mt(e, I(e))}
1581
+ ${It(e)}`;
1582
+ }
1583
+ function Mt(e, t) {
1584
+ return t.map((t) => `
1585
+ <section class="dz-section">
1586
+ <h3>${v(t.title)}</h3>
1587
+ ${t.fields.map((t) => Nt(e, t)).join("")}
1588
+ </section>`).join("");
1589
+ }
1590
+ function Nt(e, t, n = "") {
1591
+ let r = R(e, t), i = `dz-f-${t.key.replace(/\./g, "-")}${n ? `-${n}` : ""}`, a = n ? `data-field="${v(t.key)}" data-column="${v(n)}"` : `data-field="${v(t.key)}"`, o = t.type === "textarea" ? `<span class="dz-field-top">
1592
+ <label for="${i}">${v(t.label)}</label>
1593
+ <button type="button" class="dz-brace" data-action="insert-brace"
1594
+ data-for="${v(t.key)}"
1595
+ title="Wrap the selected text in braces, or insert a pair"
1596
+ aria-label="Insert a placeholder">{&nbsp;}</button>
1597
+ </span>` : `<label for="${i}">${v(t.label)}</label>`;
1598
+ return `
1599
+ <div class="dz-field dz-field-${t.type}">
1600
+ ${o}
1601
+ ${Pt(i, a, t, r)}
1602
+ ${t.hint ? `<p class="dz-hint">${v(t.hint)}</p>` : ""}
1603
+ </div>`;
1604
+ }
1605
+ function Pt(e, t, n, r) {
1606
+ switch (n.type) {
1607
+ case "textarea": return `
1608
+ <div class="dz-value">
1609
+ <div class="dz-value-marks" data-role="marks" aria-hidden="true"
1610
+ >${zt(r ?? "")}</div>
1611
+ <textarea id="${e}" ${t} rows="2"
1612
+ spellcheck="false">${v(r ?? "")}</textarea>
1613
+ </div>`;
1614
+ case "choice": return `<select id="${e}" ${t}>${n.options.map((e) => `<option value="${v(e.value)}"${e.value === r ? " selected" : ""}
1615
+ >${v(e.label)}</option>`).join("")}</select>`;
1616
+ case "color": return `<input type="color" id="${e}" ${t}
1617
+ value="${v(r ?? "#000000")}">`;
1618
+ case "toggle": return `<input type="checkbox" id="${e}" ${t}
1619
+ ${r ? "checked" : ""}>`;
1620
+ case "image": return `
1621
+ <div class="dz-image" id="${e}">
1622
+ ${r ? `<img class="dz-image-thumb" src="${v(l(r))}" alt="">` : "<span class=\"dz-image-none\">No image stored</span>"}
1623
+ <div class="dz-image-actions">
1624
+ <button type="button" class="dz-add-row"
1625
+ data-action="upload-image">${r ? "Replace" : "Upload"}</button>
1626
+ ${r ? "<button type=\"button\" class=\"dz-add-row\"\n data-action=\"clear-image\">Remove</button>" : ""}
1627
+ </div>
1628
+ </div>`;
1629
+ case "text": return `<input type="text" id="${e}" ${t}
1630
+ value="${v(r ?? "")}" spellcheck="false">`;
1631
+ default: return `<input type="number" id="${e}" ${t}
1632
+ value="${v(r ?? "")}"
1633
+ ${n.min == null ? "" : `min="${n.min}"`}
1634
+ ${n.max == null ? "" : `max="${n.max}"`} step="1">`;
1635
+ }
1636
+ }
1637
+ function Ft(e) {
1638
+ let t = e.columns || [];
1639
+ return `
1640
+ <section class="dz-section dz-columns">
1641
+ <h3>Columns</h3>
1642
+ ${t.map((e, n) => `
1643
+ <div class="dz-column">
1644
+ <div class="dz-column-head">
1645
+ <span>${n + 1}</span>
1646
+ ${t.length > 1 ? `
1647
+ <button type="button" class="dz-icon"
1648
+ data-action="remove-column" data-index="${n}"
1649
+ title="Remove this column"
1650
+ aria-label="Remove column ${n + 1}">&times;</button>` : ""}
1651
+ </div>
1652
+ ${A.map((t) => Nt(e, t, String(n))).join("")}
1653
+ </div>`).join("")}
1654
+ <button type="button" class="dz-add-row" data-action="add-column">
1655
+ Add column</button>
1656
+ </section>`;
1657
+ }
1658
+ function It(e) {
1659
+ return `
1660
+ <section class="dz-section dz-bands">
1661
+ <h3>Bands</h3>
1662
+ ${Xe.map((t) => {
1663
+ let n = X(e, t), r = it(e, t);
1664
+ return `
1665
+ <div class="dz-band-row${r ? " is-on" : ""}">
1666
+ <label class="dz-band-name">
1667
+ <input type="checkbox" data-band="${v(t)}" ${r ? "checked" : ""}>
1668
+ <span>${v(t)}</span>
1669
+ </label>
1670
+ ${r && t !== "detail" ? `<input type="text" class="dz-band-height"
1671
+ data-band-height="${v(t)}"
1672
+ value="${v(n.height ?? "")}"
1673
+ placeholder="auto" spellcheck="false"
1674
+ aria-label="${v(t)} height">` : `<span class="dz-band-height-none">${t === "detail" ? "what is left" : ""}</span>`}
1675
+ <p class="dz-hint">${v(Qe[t] ?? "")}</p>
1676
+ </div>`;
1677
+ }).join("")}
1678
+ </section>`;
1679
+ }
1680
+ function Lt({ panel: e, getTarget: t, getItem: n, changed: r, act: i, toggleBand: a, setBandHeight: o }) {
1681
+ function s(e) {
1682
+ let t = (e.closest?.(".dz-value"))?.querySelector("[data-role=\"marks\"]");
1683
+ t && (t.innerHTML = zt(e.value));
1684
+ }
1685
+ function c(e) {
1686
+ let i = e.target.closest?.("[data-field], [data-band], [data-band-height]");
1687
+ if (!i) return;
1688
+ if (i.tagName === "TEXTAREA" && s(i), i.dataset.band != null) {
1689
+ a(i.dataset.band, i.checked);
1690
+ return;
1691
+ }
1692
+ if (i.dataset.bandHeight != null) {
1693
+ o(i.dataset.bandHeight, i.value);
1694
+ return;
1695
+ }
1696
+ if (i.dataset.column != null) {
1697
+ let e = n()?.columns?.[Number(i.dataset.column)];
1698
+ if (!e) return;
1699
+ let t = A.find((e) => e.key === i.dataset.field);
1700
+ t && se(e, t, i.value) && r(`column:${i.dataset.column}:${t.key}`);
1701
+ return;
1702
+ }
1703
+ let c = t();
1704
+ if (!c) return;
1705
+ let l = c.fields.find((e) => e.key === i.dataset.field);
1706
+ if (!l) return;
1707
+ let u = l.type === "toggle" ? i.checked : i.value;
1708
+ se(c.target, l, u) && r(`field:${l.key}`, { rebuild: !!l.rebuilds });
1709
+ }
1710
+ function l(e) {
1711
+ let t = e.target.closest?.("[data-action]");
1712
+ if (t) {
1713
+ if (e.preventDefault(), t.dataset.action === "insert-brace") {
1714
+ let e = t.closest(".dz-field")?.querySelector("textarea");
1715
+ e && Bt(e);
1716
+ return;
1717
+ }
1718
+ i(t.dataset.action, t.dataset);
1719
+ }
1720
+ }
1721
+ function u(e) {
1722
+ let t = e.target;
1723
+ if (t.tagName !== "TEXTAREA") return;
1724
+ let n = t.closest(".dz-value")?.querySelector("[data-role=\"marks\"]");
1725
+ n && (n.scrollTop = t.scrollTop);
1726
+ }
1727
+ return e.addEventListener("scroll", u, !0), e.addEventListener("input", c), e.addEventListener("change", c), e.addEventListener("click", l), function() {
1728
+ e.removeEventListener("scroll", u, !0), e.removeEventListener("input", c), e.removeEventListener("change", c), e.removeEventListener("click", l);
1729
+ };
1730
+ }
1731
+ function Rt(e, t, n) {
1732
+ let r = t ?? n;
1733
+ if (!r) return;
1734
+ let i = t ? oe(t) : ae(n);
1735
+ for (let n of e.querySelectorAll("[data-field]")) {
1736
+ if (n === n.ownerDocument.activeElement) continue;
1737
+ let e = n.dataset.column != null, a = e ? t?.columns?.[Number(n.dataset.column)] : r;
1738
+ if (!a) continue;
1739
+ let o = (e ? A : i).find((e) => e.key === n.dataset.field);
1740
+ if (!o) continue;
1741
+ let s = R(a, o);
1742
+ if (o.type === "toggle") n.checked = !!s;
1743
+ else if (s != null && (n.value = String(s), n.tagName === "TEXTAREA")) {
1744
+ let e = n.closest(".dz-value")?.querySelector("[data-role=\"marks\"]");
1745
+ e && (e.innerHTML = zt(n.value));
1746
+ }
1747
+ }
1748
+ }
1749
+ function zt(e) {
1750
+ return `${v(String(e ?? "")).replace(/\{[^{}]*\}/g, (e) => `<mark class="dz-mark">${e}</mark>`)}\n`;
1751
+ }
1752
+ function Bt(e) {
1753
+ let t = e.selectionStart ?? e.value.length, n = e.selectionEnd ?? t, r = e.value.slice(t, n);
1754
+ e.value = `${e.value.slice(0, t)}{${r}}${e.value.slice(n)}`;
1755
+ let i = t + 1 + r.length;
1756
+ e.focus(), e.setSelectionRange(i, i), e.dispatchEvent(new Event("input", { bubbles: !0 }));
1757
+ }
1758
+ //#endregion
1759
+ //#region src/designer/icons.js
1760
+ var Q = (e) => `<svg viewBox="0 0 16 16" width="16" height="16"
1761
+ fill="none" stroke="currentColor" stroke-width="1.5"
1762
+ stroke-linecap="round" stroke-linejoin="round"
1763
+ aria-hidden="true" focusable="false">${e}</svg>`, Vt = {
1764
+ text: Q("<path d=\"M3 3.75h10M8 3.75v8.5M6.25 12.25h3.5\"/>"),
1765
+ table: Q("<rect x=\"2.25\" y=\"3.25\" width=\"11.5\" height=\"9.5\" rx=\"1.25\"/>\n <path d=\"M2.25 6.5h11.5M6.5 6.5v6.25M10 6.5v6.25\"/>"),
1766
+ image: Q("<rect x=\"2.25\" y=\"3.25\" width=\"11.5\" height=\"9.5\" rx=\"1.25\"/>\n <path d=\"m2.75 11.5 3.5-3.5 2.5 2.5 1.5-1.5 3 3\"/>\n <circle cx=\"10.25\" cy=\"6.25\" r=\"1\"/>"),
1767
+ box: Q("<rect x=\"2.5\" y=\"3.75\" width=\"11\" height=\"8.5\" rx=\"1.25\"/>"),
1768
+ line: Q("<path d=\"M2 8h3.5M7.25 8h1.5M10.5 8H14\"/>"),
1769
+ ruler: Q("<rect x=\"1.75\" y=\"5.25\" width=\"12.5\" height=\"5.5\" rx=\"1\"/>\n <path d=\"M4.5 5.25v2M7 5.25v3M9.5 5.25v2M12 5.25v3\"/>"),
1770
+ undo: Q("<path d=\"M6 4.5 2.75 7.75 6 11\"/>\n <path d=\"M2.75 7.75h6.75a3.75 3.75 0 0 1 0 7.5H7\"/>"),
1771
+ redo: Q("<path d=\"M10 4.5l3.25 3.25L10 11\"/>\n <path d=\"M13.25 7.75H6.5a3.75 3.75 0 0 0 0 7.5H9\"/>"),
1772
+ open: Q("<path d=\"M1.75 12.5V4a.75.75 0 0 1 .75-.75h3.4l1.5 1.75h5.35\n a.75.75 0 0 1 .75.75v1.5\"/>\n <path d=\"M1.75 12.5 3.6 7.5h11.15l-1.85 5z\"/>"),
1773
+ field: Q("<path d=\"M6.25 2.75c-1.5 0-2 .8-2 2v1.4c0 .9-.55 1.5-1.5 1.85\n .95.35 1.5.95 1.5 1.85v1.4c0 1.2.5 2 2 2\"/>\n <path d=\"M9.75 2.75c1.5 0 2 .8 2 2v1.4c0 .9.55 1.5 1.5 1.85\n -.95.35-1.5.95-1.5 1.85v1.4c0 1.2-.5 2-2 2\"/>"),
1774
+ external: Q("<path d=\"M9.5 2.75h3.75V6.5\"/>\n <path d=\"M13.25 2.75 7.5 8.5\"/>\n <path d=\"M11.5 9.25v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7\n a1 1 0 0 1 1-1h3\"/>"),
1775
+ preview: Q("<path d=\"M1 8s2.6-4.25 7-4.25S15 8 15 8s-2.6 4.25-7 4.25S1 8 1 8z\"/>\n <circle cx=\"8\" cy=\"8\" r=\"1.9\"/>"),
1776
+ design: Q("<path d=\"M11.4 2.85 13.15 4.6 5.3 12.45l-2.4.65.65-2.4z\"/>\n <path d=\"M10.15 4.1l1.75 1.75\"/>"),
1777
+ data: Q("<ellipse cx=\"8\" cy=\"4\" rx=\"5.25\" ry=\"2\"/>\n <path d=\"M2.75 4v8c0 1.1 2.35 2 5.25 2s5.25-.9 5.25-2V4\"/>\n <path d=\"M2.75 8c0 1.1 2.35 2 5.25 2s5.25-.9 5.25-2\"/>"),
1778
+ duplicate: Q("<rect x=\"2.5\" y=\"2.5\" width=\"8\" height=\"8\" rx=\"1.25\"/>\n <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.25\"/>"),
1779
+ copy: Q("<path d=\"M6 2.25h3.6L12.25 4.9v5.85a.75.75 0 0 1-.75.75H6\n a.75.75 0 0 1-.75-.75V3a.75.75 0 0 1 .75-.75z\"/>\n <path d=\"M9.35 2.4v2.65h2.75\"/>\n <path d=\"M3.9 5.5H3a.75.75 0 0 0-.75.75V13a.75.75 0 0 0 .75.75h5.4\n a.75.75 0 0 0 .75-.75v-.75\"/>"),
1780
+ delete: Q("<path d=\"M2.75 4.5h10.5\"/>\n <path d=\"M6.25 4.5V3.25a.75.75 0 0 1 .75-.75h2a.75.75 0 0 1 .75.75V4.5\"/>\n <path d=\"M4.4 4.5l.55 8.15a.85.85 0 0 0 .85.8h4.4a.85.85 0 0 0 .85-.8L11.6 4.5\"/>\n <path d=\"M6.85 7v3.75M9.15 7v3.75\"/>"),
1781
+ paste: Q("<path d=\"M6.25 3.25H4.5a.75.75 0 0 0-.75.75v8.75\n a.75.75 0 0 0 .75.75h7a.75.75 0 0 0 .75-.75V4\n a.75.75 0 0 0-.75-.75H9.75\"/>\n <rect x=\"6.25\" y=\"1.75\" width=\"3.5\" height=\"2.75\" rx=\".85\"/>"),
1782
+ save: Q("<path d=\"M2.75 3.25h8.5l2.5 2.5v7a.5.5 0 0 1-.5.5h-11\n a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5z\"/>\n <path d=\"M5 3.25v3.5h5.5v-3.5M5 13.25V9.5h6v3.75\"/>")
1783
+ };
1784
+ function $(e) {
1785
+ return Vt[e] ?? "";
1786
+ }
1787
+ function Ht({ count: e = 0, canPaste: t = !1, canDuplicate: n = !0 } = {}) {
1788
+ let r = e > 1 ? ` ${e} items` : "", i = {
1789
+ action: "paste-items",
1790
+ glyph: "paste",
1791
+ label: "Paste",
1792
+ hint: "ctrl+V",
1793
+ disabled: !t
1794
+ };
1795
+ return e < 1 ? [i] : [
1796
+ {
1797
+ action: "duplicate-item",
1798
+ glyph: "duplicate",
1799
+ label: n ? `Duplicate${r}` : "This cannot be duplicated",
1800
+ hint: "ctrl+D, or alt-drag",
1801
+ disabled: !n
1802
+ },
1803
+ {
1804
+ action: "copy-items",
1805
+ glyph: "copy",
1806
+ label: `Copy${r}`,
1807
+ hint: "ctrl+C"
1808
+ },
1809
+ i,
1810
+ { separator: !0 },
1811
+ {
1812
+ action: "delete-item",
1813
+ glyph: "delete",
1814
+ label: `Delete${r}`,
1815
+ hint: "del",
1816
+ tone: "danger"
1817
+ }
1818
+ ];
1819
+ }
1820
+ function Ut(e) {
1821
+ return `<div class="dz-menu" data-role="menu" role="menu"
1822
+ aria-label="Item actions">${e.map((e) => e.separator ? "<span class=\"dz-menu-sep\" aria-hidden=\"true\"></span>" : `<button type="button" role="menuitem"
1823
+ class="dz-menu-item${e.tone ? ` is-${v(e.tone)}` : ""}"
1824
+ data-action="${v(e.action)}"
1825
+ title="${v(e.label)} (${v(e.hint)})"
1826
+ aria-label="${v(e.label)}"
1827
+ ${e.disabled ? "disabled" : ""}
1828
+ >${$(e.glyph)}</button>`).join("")}</div>`;
1829
+ }
1830
+ function Wt(e, t, n, r = 8) {
1831
+ let i = (e, t, n) => Math.min(Math.max(r, e), Math.max(r, n - t - r));
1832
+ return {
1833
+ left: i(e.x, t.width, n.width),
1834
+ top: i(e.y, t.height, n.height)
1835
+ };
1836
+ }
1837
+ //#endregion
1838
+ //#region src/designer/toast.js
1839
+ function Gt(e, t) {
1840
+ return !Array.isArray(e) || !Array.isArray(t) || e.length !== t.length ? !1 : e.every((e, n) => e === t[n]);
1841
+ }
1842
+ function Kt(e) {
1843
+ let t = e.length > 1;
1844
+ return `
1845
+ <div class="dz-toast dz-problems" role="alert" data-role="problems">
1846
+ <div class="dz-toast-text">
1847
+ <strong class="dz-toast-title">This report will not render yet</strong>
1848
+ <ul>${e.map((e) => `<li>${v(e)}</li>`).join("")}</ul>
1849
+ </div>
1850
+ <button type="button" class="dz-toast-close"
1851
+ data-action="dismiss-problems"
1852
+ title="Dismiss${t ? ` ${e.length} problems` : ""}"
1853
+ aria-label="Dismiss${t ? ` ${e.length} problems` : ""}"
1854
+ >&times;</button>
1855
+ </div>`;
1856
+ }
1857
+ //#endregion
1858
+ //#region src/shared/prefix.js
1859
+ var qt = "/__reports";
1860
+ //#endregion
1861
+ //#region src/shared/store.js
1862
+ function Jt({ prefix: e = qt, fetch: t = (...e) => globalThis.fetch(...e) } = {}) {
1863
+ async function n(n, r) {
1864
+ let i;
1865
+ try {
1866
+ i = await t(`${e}${n}`, r);
1867
+ } catch (e) {
1868
+ throw new Yt("Cannot reach the report server. Start it with `npx report-studio design`.", {
1869
+ cause: e,
1870
+ offline: !0
1871
+ });
1872
+ }
1873
+ let a = await i.json().catch(() => null);
1874
+ if (!i.ok) throw new Yt(a?.error ?? `the server answered ${i.status}`, { status: i.status });
1875
+ return a;
1876
+ }
1877
+ return {
1878
+ async list() {
1879
+ let e = await n("", { method: "GET" });
1880
+ return Array.isArray(e?.reports) ? e.reports : [];
1881
+ },
1882
+ load(e) {
1883
+ return n(`/${encodeURIComponent(e)}`, { method: "GET" });
1884
+ },
1885
+ save(e, t) {
1886
+ return n(`/${encodeURIComponent(e)}`, {
1887
+ method: "PUT",
1888
+ headers: { "Content-Type": "application/json" },
1889
+ body: JSON.stringify(t)
1890
+ });
1891
+ },
1892
+ remove(e) {
1893
+ return n(`/${encodeURIComponent(e)}`, { method: "DELETE" });
1894
+ },
1895
+ async loadData(e) {
1896
+ try {
1897
+ return await n(`/${encodeURIComponent(e)}/data`, { method: "GET" });
1898
+ } catch (e) {
1899
+ if (e.status === 404) return null;
1900
+ throw e;
1901
+ }
1902
+ },
1903
+ saveData(e, t) {
1904
+ return n(`/${encodeURIComponent(e)}/data`, {
1905
+ method: "PUT",
1906
+ headers: { "Content-Type": "application/json" },
1907
+ body: JSON.stringify(t, null, 2)
1908
+ });
1909
+ }
1910
+ };
1911
+ }
1912
+ var Yt = class extends Error {
1913
+ constructor(e, { cause: t, status: n = null, offline: r = !1 } = {}) {
1914
+ super(e, { cause: t }), this.name = "StoreError", this.status = n, this.offline = r;
1915
+ }
1916
+ };
1917
+ function Xt(e) {
1918
+ let t = String(e ?? "").trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64).replace(/-+$/, "");
1919
+ return /^[a-z0-9]/.test(t) ? t : "";
1920
+ }
1921
+ //#endregion
1922
+ //#region src/designer/sample-data.js
1923
+ var Zt = 6, Qt = ["North", "South"], $t = /(amount|amt|price|qty|quantity|total|subtotal|cost|rate|balance|discount|tax)$/i, en = /\{\s*(\w+)\(([^)]*)\)\s*\}/g, tn = /(date|day|when)$/i, nn = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAAAAADRSSBWAAAAC0lEQVR4nGO4eRcAApIBt+wBgUAAAAAASUVORK5CYII=";
1924
+ function rn(e) {
1925
+ let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
1926
+ for (let i of Array.isArray(e?.bands) ? e.bands : []) {
1927
+ let e = t(i.type);
1928
+ for (let t of i.items || []) if (!(t.type !== "text" || typeof t.value != "string")) for (let [, i] of t.value.matchAll(y)) {
1929
+ let t = i.trim();
1930
+ !t || o(t) || (t.includes(".") || !e ? n.add(t) : r.add(t));
1931
+ }
1932
+ }
1933
+ return {
1934
+ root: [...n],
1935
+ row: [...r]
1936
+ };
1937
+ }
1938
+ function an(e) {
1939
+ let t = /* @__PURE__ */ new Set();
1940
+ for (let n of Array.isArray(e?.bands) ? e.bands : []) for (let e of n.items || []) {
1941
+ if (e.type !== "image" || typeof e.field != "string") continue;
1942
+ let n = e.field.trim();
1943
+ n && t.add(n);
1944
+ }
1945
+ return [...t];
1946
+ }
1947
+ function on(e) {
1948
+ let t = /* @__PURE__ */ new Map(), i = e?.dataset || "rows", a = (e) => (t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e));
1949
+ for (let t of Array.isArray(e?.bands) ? e.bands : []) for (let e of t.items || []) {
1950
+ if (e.type !== "table") continue;
1951
+ let t = a(e.dataset || i);
1952
+ for (let n of e.columns || []) n?.field && t.add(n.field);
1953
+ }
1954
+ let { row: o } = rn(e), s = r(e), c = s?.by ?? e?.groupBy ?? null;
1955
+ if (o.length || c) {
1956
+ let t = a(s && n(s.table, e) || i);
1957
+ for (let e of o) t.add(e);
1958
+ c && t.add(c);
1959
+ }
1960
+ for (let t of pn(e)) a(t.dataset).add(t.field);
1961
+ return t;
1962
+ }
1963
+ function sn(e) {
1964
+ let t = {}, { root: n } = rn(e), r = dn(e);
1965
+ for (let n of an(e)) mn(t, n, nn);
1966
+ for (let e of n) mn(t, e);
1967
+ let i = fn(e);
1968
+ for (let [n, a] of on(e)) t[n] = hn([...a], i.get(n) ?? null, r);
1969
+ return t;
1970
+ }
1971
+ function cn(e, t) {
1972
+ let n = sn(t);
1973
+ if (typeof e != "object" || !e || Array.isArray(e)) return {
1974
+ data: n,
1975
+ added: !0
1976
+ };
1977
+ let r = structuredClone(e);
1978
+ return {
1979
+ data: r,
1980
+ added: ln(r, n)
1981
+ };
1982
+ }
1983
+ function ln(e, t) {
1984
+ let n = !1;
1985
+ for (let [r, i] of Object.entries(t)) {
1986
+ let t = e[r];
1987
+ if (t === void 0) {
1988
+ e[r] = structuredClone(i), n = !0;
1989
+ continue;
1990
+ }
1991
+ un(t) && un(i) && ln(t, i) && (n = !0);
1992
+ }
1993
+ return n;
1994
+ }
1995
+ function un(e) {
1996
+ return typeof e == "object" && !!e && !Array.isArray(e);
1997
+ }
1998
+ function dn(e) {
1999
+ let t = /* @__PURE__ */ new Set();
2000
+ for (let n of Array.isArray(e?.bands) ? e.bands : []) for (let e of n.items || []) if (e.type === "text") for (let [, , n] of String(e.value ?? "").matchAll(en)) {
2001
+ let e = n.trim();
2002
+ e && (t.add(e), e.includes(".") && t.add(e.slice(e.indexOf(".") + 1)));
2003
+ }
2004
+ return t;
2005
+ }
2006
+ function fn(e) {
2007
+ let t = /* @__PURE__ */ new Map(), i = r(e);
2008
+ return i && t.set(n(i.table, e) || e?.dataset || "rows", i.by), t;
2009
+ }
2010
+ function pn(e) {
2011
+ let t = [];
2012
+ for (let n of Array.isArray(e?.bands) ? e.bands : []) for (let e of n.items || []) if (e.type === "text") for (let [, , n] of String(e.value ?? "").matchAll(en)) {
2013
+ let [e, ...r] = n.trim().split("."), i = r.join(".");
2014
+ e && i && t.push({
2015
+ dataset: e,
2016
+ field: i
2017
+ });
2018
+ }
2019
+ return t;
2020
+ }
2021
+ function mn(e, t, n) {
2022
+ let r = t.split(".").filter(Boolean);
2023
+ if (!r.length) return;
2024
+ let i = r.pop(), a = e;
2025
+ for (let e of r) (a[e] == null || typeof a[e] != "object") && (a[e] = {}), a = a[e];
2026
+ a[i] === void 0 && (a[i] = n ?? gn(i, 0));
2027
+ }
2028
+ function hn(e, t, n = /* @__PURE__ */ new Set()) {
2029
+ return e.length ? Array.from({ length: Zt }, (r, i) => {
2030
+ let a = {};
2031
+ for (let r of e) a[r] = r === t ? Qt[i % Qt.length] : gn(r, i, n.has(r));
2032
+ return a;
2033
+ }) : [];
2034
+ }
2035
+ function gn(e, t, n = !1) {
2036
+ return n || $t.test(e) ? (t + 1) * 250 : tn.test(e) ? `2026-06-${String(t % 28 + 1).padStart(2, "0")}` : `${_n(e)} ${t + 1}`;
2037
+ }
2038
+ function _n(e) {
2039
+ let t = String(e).replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").trim().toLowerCase();
2040
+ return t.charAt(0).toUpperCase() + t.slice(1);
2041
+ }
2042
+ //#endregion
2043
+ //#region src/designer/tokens.js
2044
+ var vn = "field", yn = [
2045
+ {
2046
+ id: "page",
2047
+ prefer: [
2048
+ "pageFooter",
2049
+ "reportFooter",
2050
+ "pageHeader"
2051
+ ],
2052
+ label: "Page number",
2053
+ value: "{page}",
2054
+ note: "The page this is printed on"
2055
+ },
2056
+ {
2057
+ id: "page-of",
2058
+ prefer: [
2059
+ "pageFooter",
2060
+ "reportFooter",
2061
+ "pageHeader"
2062
+ ],
2063
+ label: "Page X of Y",
2064
+ value: "Page {page} of {totalPages}",
2065
+ note: "The usual footer line, written out"
2066
+ },
2067
+ {
2068
+ id: "total-pages",
2069
+ prefer: [
2070
+ "pageFooter",
2071
+ "reportFooter",
2072
+ "pageHeader"
2073
+ ],
2074
+ label: "Total pages",
2075
+ value: "{totalPages}",
2076
+ note: "How many pages the report came to"
2077
+ },
2078
+ {
2079
+ id: "today",
2080
+ prefer: [
2081
+ "pageHeader",
2082
+ "reportHeader",
2083
+ "pageFooter"
2084
+ ],
2085
+ label: "Today",
2086
+ value: "{today}",
2087
+ note: "The date the report was run"
2088
+ },
2089
+ {
2090
+ id: "count",
2091
+ prefer: ["groupFooter", "reportFooter"],
2092
+ label: "Row count",
2093
+ value: "{count()}",
2094
+ note: "How many rows are in scope",
2095
+ aggregate: !0
2096
+ },
2097
+ {
2098
+ id: "sum",
2099
+ prefer: ["groupFooter", "reportFooter"],
2100
+ label: "Sum",
2101
+ value: `{sum(${vn})}`,
2102
+ note: "Added up over the rows in scope",
2103
+ field: !0,
2104
+ aggregate: !0
2105
+ },
2106
+ {
2107
+ id: "avg",
2108
+ prefer: ["groupFooter", "reportFooter"],
2109
+ label: "Average",
2110
+ value: `{avg(${vn})}`,
2111
+ note: "The mean of the rows in scope",
2112
+ field: !0,
2113
+ aggregate: !0
2114
+ },
2115
+ {
2116
+ id: "min",
2117
+ prefer: ["groupFooter", "reportFooter"],
2118
+ label: "Smallest",
2119
+ value: `{min(${vn})}`,
2120
+ field: !0,
2121
+ aggregate: !0
2122
+ },
2123
+ {
2124
+ id: "max",
2125
+ prefer: ["groupFooter", "reportFooter"],
2126
+ label: "Largest",
2127
+ value: `{max(${vn})}`,
2128
+ field: !0,
2129
+ aggregate: !0
2130
+ }
2131
+ ];
2132
+ function bn(e) {
2133
+ return yn.find((t) => t.id === e) ?? null;
2134
+ }
2135
+ function xn(e) {
2136
+ return !!e?.field;
2137
+ }
2138
+ var Sn = ["groupHeader", "groupFooter"];
2139
+ function Cn(e, t) {
2140
+ return e?.aggregate ? Sn.includes(t) ? "group" : "report" : null;
2141
+ }
2142
+ function wn(e, t) {
2143
+ return e ? !e.bands?.length || e.bands.includes(t) : !1;
2144
+ }
2145
+ function Tn(e, t) {
2146
+ return e ? xn(e) ? e.value.replace(vn, String(t || vn)) : e.value : "";
2147
+ }
2148
+ function En(e) {
2149
+ let t = /* @__PURE__ */ new Set();
2150
+ for (let [, n] of on(e)) for (let e of n) t.add(e);
2151
+ e?.groupBy && t.add(e.groupBy);
2152
+ for (let n of Array.isArray(e?.bands) ? e.bands : []) for (let e of n.items || []) e?.type === "table" && typeof e.groupBy == "string" && e.groupBy && t.add(e.groupBy);
2153
+ return [...t].sort();
2154
+ }
2155
+ function Dn(e, t) {
2156
+ let n = Xe.filter((t) => it(e, t));
2157
+ if (!t?.bands?.length) return n;
2158
+ let r = n.filter((e) => t.bands.includes(e));
2159
+ return r.length ? r : n;
2160
+ }
2161
+ function On(e, t, n = null) {
2162
+ let r = Dn(e, t);
2163
+ if (!r.length) return null;
2164
+ for (let e of t?.prefer ?? []) if (r.includes(e)) return e;
2165
+ return n && r.includes(n) && wn(t, n) ? n : r[0];
2166
+ }
2167
+ function kn(e, t) {
2168
+ let n = xn(e) || e?.id === "count" || e?.id === "page" || e?.id === "total-pages";
2169
+ return {
2170
+ value: Tn(e, t),
2171
+ w: e?.id === "page-of" ? 200 : 120,
2172
+ align: n ? "right" : "left"
2173
+ };
2174
+ }
2175
+ //#endregion
2176
+ //#region src/designer/dialog.js
2177
+ var An = 20;
2178
+ function jn(e) {
2179
+ return Fn(e, "column-dialog", In(), (e, t) => {
2180
+ let n = e.querySelector("[data-role=\"count\"]");
2181
+ n.focus(), n.select(), e.querySelector("form").addEventListener("submit", (e) => {
2182
+ e.preventDefault();
2183
+ let r = Math.round(Number(n.value));
2184
+ t(Number.isFinite(r) && r > 0 ? Math.min(r, An) : 3);
2185
+ });
2186
+ });
2187
+ }
2188
+ function Mn(e, t) {
2189
+ let n = t || [];
2190
+ return Fn(e, "open-dialog", Ln(n), (e, t) => {
2191
+ e.querySelector("[data-role=\"new\"]")?.addEventListener("click", () => t({ blank: !0 }));
2192
+ let r = e.querySelector("[data-role=\"report-dropdown\"]"), i = e.querySelector("[data-role=\"confirm\"]");
2193
+ if (!r || !n.length) {
2194
+ e.querySelector("[data-role=\"new\"]")?.focus();
2195
+ return;
2196
+ }
2197
+ let a = m(r), o = e.querySelector("[data-role=\"report-meta\"]"), s = () => {
2198
+ let e = n.find((e) => e.id === a.value) ?? n[0];
2199
+ e && (o.textContent = `${e.id}.json${e.readable === !1 ? " - will not parse" : ""}${Rn(e.updatedAt)}`, o.toggleAttribute("data-unreadable", e.readable === !1));
2200
+ };
2201
+ a.addEventListener("change", s), s(), i.addEventListener("click", () => t({ id: a.value })), i.focus(), e.addEventListener("dz-closing", () => a.destroy());
2202
+ });
2203
+ }
2204
+ function Nn(e, t = "") {
2205
+ return Fn(e, "save-dialog", zn(t), (e, t) => {
2206
+ let n = e.querySelector("[data-role=\"report-name\"]"), r = e.querySelector("[data-role=\"filename\"]"), i = e.querySelector("[data-role=\"confirm\"]"), a = () => {
2207
+ let e = Xt(n.value);
2208
+ r.textContent = e ? `${e}.json` : "needs a letter or a digit", i.disabled = !e;
2209
+ };
2210
+ n.addEventListener("input", a), a(), n.focus(), n.select(), e.querySelector("form").addEventListener("submit", (e) => {
2211
+ e.preventDefault();
2212
+ let r = Xt(n.value);
2213
+ r && t({
2214
+ id: r,
2215
+ name: n.value.trim() || r
2216
+ });
2217
+ });
2218
+ });
2219
+ }
2220
+ function Pn(e, t = "") {
2221
+ return Fn(e, "discard-dialog", Bn(t), (e, t) => {
2222
+ e.querySelector("[data-role=\"discard\"]").addEventListener("click", () => t(!0)), e.querySelector("[data-role=\"cancel\"]").focus();
2223
+ }).then((e) => e === !0);
2224
+ }
2225
+ function Fn(e, t, n, r) {
2226
+ return new Promise((i) => {
2227
+ let a = e.ownerDocument.createElement("div");
2228
+ a.className = "modal", a.dataset.role = t, a.innerHTML = n, e.appendChild(a);
2229
+ let o = !1;
2230
+ function s(e) {
2231
+ o || (o = !0, a.dispatchEvent(new CustomEvent("dz-closing")), a.remove(), i(e));
2232
+ }
2233
+ function c(e) {
2234
+ e.key === "Escape" && (e.stopPropagation(), e.preventDefault(), s(null));
2235
+ }
2236
+ for (let e of a.querySelectorAll("[data-role=\"cancel\"], [data-role=\"backdrop\"]")) e.addEventListener("click", () => s(null));
2237
+ a.addEventListener("keydown", c, !0), r(a, s);
2238
+ });
2239
+ }
2240
+ function In() {
2241
+ return `
2242
+ <div class="modal-backdrop" data-role="backdrop"></div>
2243
+
2244
+ <div class="modal-card" role="dialog" aria-modal="true"
2245
+ aria-labelledby="dz-columns-title">
2246
+ <h2 id="dz-columns-title">Add table</h2>
2247
+
2248
+ <form>
2249
+ <div class="dz-field dz-field-count">
2250
+ <label for="dz-columns">Columns</label>
2251
+ <input type="number" id="dz-columns" data-role="count"
2252
+ value="3" min="1" max="${An}"
2253
+ step="1" required>
2254
+ </div>
2255
+
2256
+ <p class="modal-summary">
2257
+ Each column starts 50px wide. Rows come from your data, so there
2258
+ is no count to set here.
2259
+ </p>
2260
+
2261
+ <div class="modal-actions">
2262
+ <button type="button" data-role="cancel">Cancel</button>
2263
+ <button type="submit" class="is-primary" data-role="confirm">Add</button>
2264
+ </div>
2265
+ </form>
2266
+ </div>`;
2267
+ }
2268
+ function Ln(e) {
2269
+ let t = e || [], n = `
2270
+ <div class="dz-field dz-field-picker">
2271
+ <label id="dz-open-label">Report</label>
2272
+
2273
+ <div class="dropdown" data-role="report-dropdown">
2274
+ <button type="button" class="dropdown-trigger"
2275
+ aria-haspopup="listbox" aria-expanded="false"
2276
+ aria-labelledby="dz-open-label">
2277
+ <span class="dropdown-value"></span>
2278
+ <span class="dropdown-caret" aria-hidden="true"></span>
2279
+ </button>
2280
+
2281
+ <ul class="dropdown-menu" role="listbox"
2282
+ aria-labelledby="dz-open-label" hidden>${t.map((e, t) => `
2283
+ <li class="dropdown-item" role="option" tabindex="-1"
2284
+ data-value="${v(e.id)}"
2285
+ ${t === 0 ? "data-selected=\"true\"" : ""}
2286
+ >${v(e.name || e.id)}</li>`).join("")}</ul>
2287
+ </div>
2288
+ </div>
2289
+
2290
+ <p class="dz-report-meta" data-role="report-meta" aria-live="polite"></p>`;
2291
+ return `
2292
+ <div class="modal-backdrop" data-role="backdrop"></div>
2293
+
2294
+ <div class="modal-card is-roomy" role="dialog" aria-modal="true"
2295
+ aria-labelledby="dz-open-title">
2296
+ <h2 id="dz-open-title">Open report</h2>
2297
+
2298
+ ${t.length ? n : "<p class=\"modal-summary\">\n No reports saved yet. Start a new one and save it.</p>"}
2299
+
2300
+ <div class="modal-actions">
2301
+ <button type="button" data-role="cancel">Cancel</button>
2302
+ <button type="button" data-role="new">New report</button>
2303
+ ${t.length ? "<button type=\"button\" class=\"is-primary\" data-role=\"confirm\">Open</button>" : ""}
2304
+ </div>
2305
+ </div>`;
2306
+ }
2307
+ function Rn(e) {
2308
+ if (!e) return "";
2309
+ let t = new Date(e);
2310
+ return Number.isNaN(t.getTime()) ? "" : ` - ${t.toLocaleDateString(void 0, {
2311
+ day: "numeric",
2312
+ month: "short",
2313
+ year: "numeric"
2314
+ })}`;
2315
+ }
2316
+ function zn(e) {
2317
+ return `
2318
+ <div class="modal-backdrop" data-role="backdrop"></div>
2319
+
2320
+ <div class="modal-card" role="dialog" aria-modal="true"
2321
+ aria-labelledby="dz-save-title">
2322
+ <h2 id="dz-save-title">Save report</h2>
2323
+
2324
+ <form>
2325
+ <div class="dz-field dz-field-text">
2326
+ <label for="dz-save-name">Name</label>
2327
+ <input type="text" id="dz-save-name" data-role="report-name"
2328
+ value="${v(e)}" spellcheck="false" required>
2329
+ </div>
2330
+
2331
+ <p class="modal-summary">
2332
+ Saved as <code data-role="filename"></code>
2333
+ </p>
2334
+
2335
+ <div class="modal-actions">
2336
+ <button type="button" data-role="cancel">Cancel</button>
2337
+ <button type="submit" class="is-primary" data-role="confirm">Save</button>
2338
+ </div>
2339
+ </form>
2340
+ </div>`;
2341
+ }
2342
+ function Bn(e) {
2343
+ return `
2344
+ <div class="modal-backdrop" data-role="backdrop"></div>
2345
+
2346
+ <div class="modal-card" role="dialog" aria-modal="true"
2347
+ aria-labelledby="dz-discard-title">
2348
+ <h2 id="dz-discard-title">Unsaved changes</h2>
2349
+
2350
+ <p class="modal-summary">
2351
+ ${e ? `<strong>${v(e)}</strong>` : "This report"} has changes that have not been saved. Opening another
2352
+ report closes this one, and the changes go with it.
2353
+ </p>
2354
+
2355
+ <div class="modal-actions">
2356
+ <button type="button" class="is-danger" data-role="discard">Discard changes</button>
2357
+ <button type="button" class="is-primary" data-role="cancel">Keep editing</button>
2358
+ </div>
2359
+ </div>`;
2360
+ }
2361
+ function Vn(e, t, { id: n = null, generated: r = !1 } = {}) {
2362
+ return Fn(e, "data-dialog", Hn(t, n, r), (e, t) => {
2363
+ let n = e.querySelector("[data-role=\"payload\"]"), r = e.querySelector("[data-role=\"parse-error\"]"), i = e.querySelector("[data-role=\"confirm\"]"), a = () => {
2364
+ try {
2365
+ let e = JSON.parse(n.value), t = typeof e == "object" && !!e && !Array.isArray(e);
2366
+ r.textContent = t ? "" : "The payload must be a JSON object keyed by dataset name.", i.disabled = !t;
2367
+ } catch (e) {
2368
+ r.textContent = e.message, i.disabled = !0;
2369
+ }
2370
+ };
2371
+ n.addEventListener("input", a), a(), n.focus(), i.addEventListener("click", () => {
2372
+ try {
2373
+ t(JSON.parse(n.value));
2374
+ } catch {}
2375
+ });
2376
+ });
2377
+ }
2378
+ function Hn(e, t, n) {
2379
+ let r = t ? `${t}.data.json` : "a .data.json beside the report";
2380
+ return `
2381
+ <div class="modal-backdrop" data-role="backdrop"></div>
2382
+
2383
+ <div class="modal-card is-wide" role="dialog" aria-modal="true"
2384
+ aria-labelledby="dz-data-title">
2385
+ <h2 id="dz-data-title">Report data</h2>
2386
+
2387
+ <p class="modal-summary">
2388
+ ${n ? "These keys were read off the report - every placeholder, every\n column, and the field it groups by. Replace the sample values\n with real ones." : "The data this report is currently previewed with."}
2389
+ Saved as <code>${v(r)}</code>.
2390
+ </p>
2391
+
2392
+ <textarea class="dz-payload" data-role="payload" rows="16"
2393
+ spellcheck="false" aria-label="Report data"
2394
+ >${v(JSON.stringify(e, null, 2))}</textarea>
2395
+
2396
+ <p class="dz-parse-error" data-role="parse-error" aria-live="polite"></p>
2397
+
2398
+ <div class="modal-actions">
2399
+ <button type="button" data-role="cancel">Cancel</button>
2400
+ <button type="button" class="is-primary" data-role="confirm">Save data</button>
2401
+ </div>
2402
+ </div>`;
2403
+ }
2404
+ function Un(e, t, n = null) {
2405
+ let r = En(t);
2406
+ return Fn(e, "token-dialog", Kn(t, r, n), (e, i) => {
2407
+ let a = e.querySelector("[data-role=\"field-row\"]"), o = e.querySelector("[data-role=\"token-warning\"]"), s = e.querySelector("[data-role=\"confirm\"]"), c = r.length ? m(e.querySelector("[data-role=\"field-dropdown\"]")) : null, l = e.querySelector("[data-role=\"band-dropdown\"]"), u = null, d = () => bn(e.querySelector("[name=\"dz-token\"]:checked")?.value);
2408
+ function f(e) {
2409
+ u?.destroy();
2410
+ let r = Dn(t, e), i = On(t, e, n);
2411
+ l.innerHTML = Jn("band", r.map((e) => ({
2412
+ value: e,
2413
+ label: e
2414
+ })), i), u = m(l), u.addEventListener("change", () => p());
2415
+ }
2416
+ function p({ retarget: e = !1 } = {}) {
2417
+ let t = d();
2418
+ if (!t) return;
2419
+ a.hidden = !xn(t), e && f(t);
2420
+ let n = u.value, r = wn(t, n), i = r ? Gn(t, n) : Wn(t, n);
2421
+ o.textContent = i, o.hidden = !i, o.classList.toggle("is-note", r), s.textContent = r ? "Insert" : "Insert anyway";
2422
+ }
2423
+ for (let t of e.querySelectorAll("[name=\"dz-token\"]")) t.addEventListener("change", () => p({ retarget: !0 }));
2424
+ p({ retarget: !0 }), s.addEventListener("click", () => {
2425
+ let e = d();
2426
+ e && i({
2427
+ ...kn(e, xn(e) ? c?.value || "field" : void 0),
2428
+ band: u.value
2429
+ });
2430
+ }), e.querySelector("[name=\"dz-token\"]")?.focus(), e.addEventListener("dz-closing", () => {
2431
+ c?.destroy(), u?.destroy();
2432
+ });
2433
+ });
2434
+ }
2435
+ function Wn(e, t) {
2436
+ return `${e.label} prints nothing in a ${t}.`;
2437
+ }
2438
+ function Gn(e, t) {
2439
+ let n = Cn(e, t);
2440
+ return n === "group" ? `In a ${t}, ${e.label.toLowerCase()} is worked out over each group's own rows, once per group.` : n === "report" ? `In a ${t}, ${e.label.toLowerCase()} is worked out over every row in the report.` : "";
2441
+ }
2442
+ function Kn(e, t, n) {
2443
+ let r = yn[0];
2444
+ return `
2445
+ <div class="modal-backdrop" data-role="backdrop"></div>
2446
+
2447
+ <div class="modal-card is-roomy" role="dialog" aria-modal="true"
2448
+ aria-labelledby="dz-token-title">
2449
+ <h2 id="dz-token-title">Insert field</h2>
2450
+
2451
+ <div class="dz-tokens" role="radiogroup" aria-labelledby="dz-token-title">
2452
+ ${yn.map((e, t) => `
2453
+ <label class="dz-token">
2454
+ <input type="radio" name="dz-token" value="${v(e.id)}"
2455
+ ${t === 0 ? "checked" : ""}>
2456
+ <span class="dz-token-body">
2457
+ <span class="dz-token-name">${v(e.label)}</span>
2458
+ <code class="dz-token-syntax">${v(e.value)}</code>
2459
+ ${e.note ? `<span class="dz-token-note">${v(e.note)}</span>` : ""}
2460
+ </span>
2461
+ </label>`).join("")}
2462
+ </div>
2463
+
2464
+ ${qn("field", "Field", t.map((e) => ({
2465
+ value: e,
2466
+ label: e
2467
+ })), t[0], {
2468
+ hidden: !xn(r),
2469
+ empty: "No fields yet - add a table first"
2470
+ })}
2471
+
2472
+ ${qn("band", "Band", Dn(e, r).map((e) => ({
2473
+ value: e,
2474
+ label: e
2475
+ })), On(e, r, n))}
2476
+
2477
+ <p class="dz-token-warning" data-role="token-warning" aria-live="polite" hidden></p>
2478
+
2479
+ <div class="modal-actions">
2480
+ <button type="button" data-role="cancel">Cancel</button>
2481
+ <button type="button" class="is-primary" data-role="confirm">Insert</button>
2482
+ </div>
2483
+ </div>`;
2484
+ }
2485
+ function qn(e, t, n, r, { hidden: i = !1, empty: a = "" } = {}) {
2486
+ return n.length ? `
2487
+ <div class="dz-field dz-field-picker" data-role="${e}-row"${i ? " hidden" : ""}>
2488
+ <label id="dz-${e}-label">${v(t)}</label>
2489
+
2490
+ <div class="dropdown" data-role="${e}-dropdown">
2491
+ ${Jn(e, n, r)}
2492
+ </div>
2493
+ </div>` : `<p class="modal-summary">${v(a)}</p>`;
2494
+ }
2495
+ function Jn(e, t, n) {
2496
+ return `
2497
+ <button type="button" class="dropdown-trigger"
2498
+ aria-haspopup="listbox" aria-expanded="false"
2499
+ aria-labelledby="dz-${e}-label">
2500
+ <span class="dropdown-value"></span>
2501
+ <span class="dropdown-caret" aria-hidden="true"></span>
2502
+ </button>
2503
+
2504
+ <ul class="dropdown-menu" role="listbox"
2505
+ aria-labelledby="dz-${e}-label" hidden>
2506
+ ${t.map((e) => `
2507
+ <li class="dropdown-item" role="option" tabindex="-1"
2508
+ data-value="${v(e.value)}"
2509
+ ${e.value === n ? "data-selected=\"true\"" : ""}
2510
+ >${v(e.label)}</li>`).join("")}
2511
+ </ul>`;
2512
+ }
2513
+ function Yn(e, t, { limit: n = 12 } = {}) {
2514
+ let r;
2515
+ try {
2516
+ r = h(e, t ?? {});
2517
+ } catch (e) {
2518
+ return {
2519
+ markup: Xn(e),
2520
+ pageCount: 0,
2521
+ error: e?.message ?? String(e)
2522
+ };
2523
+ }
2524
+ let i = r.pages.length;
2525
+ return {
2526
+ markup: `
2527
+ ${f(i > n ? {
2528
+ ...r,
2529
+ pages: r.pages.slice(0, n)
2530
+ } : r)}
2531
+ ${i > n ? Zn(i, n) : ""}`,
2532
+ pageCount: i,
2533
+ error: null
2534
+ };
2535
+ }
2536
+ function Xn(e) {
2537
+ return `
2538
+ <div class="dz-problems" role="alert">
2539
+ <h2>This report will not run yet</h2>
2540
+ <ul>${(e instanceof i && e.issues?.length ? e.issues : [e?.message ?? String(e)]).map((e) => `<li>${v(e)}</li>`).join("")}</ul>
2541
+ </div>`;
2542
+ }
2543
+ function Zn(e, t) {
2544
+ return `
2545
+ <p class="dz-truncated">
2546
+ Showing the first ${t} of ${v(e)} pages.
2547
+ Open the preview screen to read them all.
2548
+ </p>`;
2549
+ }
2550
+ //#endregion
2551
+ //#region src/designer/history.js
2552
+ var Qn = 100, $n = (e) => structuredClone(e), er = (e, t) => JSON.stringify(e) === JSON.stringify(t);
2553
+ function tr(e, { limit: t = Qn } = {}) {
2554
+ let n = [$n(e)], r = 0, i = null;
2555
+ return {
2556
+ push(e, a = null) {
2557
+ return er(e, n[r]) ? !1 : (r < n.length - 1 && (n = n.slice(0, r + 1), i = null), a != null && a === i ? (n[r] = $n(e), !0) : (n.push($n(e)), r++, i = a, n.length > t && (n.shift(), r--), !0));
2558
+ },
2559
+ undo() {
2560
+ return r === 0 ? null : (r--, i = null, $n(n[r]));
2561
+ },
2562
+ redo() {
2563
+ return r >= n.length - 1 ? null : (r++, i = null, $n(n[r]));
2564
+ },
2565
+ get canUndo() {
2566
+ return r > 0;
2567
+ },
2568
+ get canRedo() {
2569
+ return r < n.length - 1;
2570
+ },
2571
+ get length() {
2572
+ return n.length;
2573
+ },
2574
+ reset(e) {
2575
+ n = [$n(e)], r = 0, i = null;
2576
+ }
2577
+ };
2578
+ }
2579
+ //#endregion
2580
+ //#region src/designer/designer.js
2581
+ var nr = [
2582
+ "image/png",
2583
+ "image/jpeg",
2584
+ "image/gif",
2585
+ "image/webp"
2586
+ ], rr = 1024 * 1024, ir = 200 * 1024, ar = (e) => `${Math.round(e / 1024)} KB`, or = [
2587
+ "list",
2588
+ "load",
2589
+ "save"
2590
+ ];
2591
+ function sr(e) {
2592
+ if (e == null) return;
2593
+ if (typeof e == "string") throw TypeError(`createDesigner: store must be an object with list, load and save functions, not a path ("${e}"). To keep reports in a folder, leave store out and serve the folder: \`npx report-studio design --dir ${e}\`, or reportStudio({ dir: '${e}' }) from 'report-studio/vite' in your vite.config.`);
2594
+ let t = or.filter((t) => typeof e?.[t] != "function");
2595
+ if (t.length > 0) throw TypeError(`createDesigner: store is missing ${t.join(", ")} - it must be an object with list, load and save functions (see the store contract), or left out to use the dev server's routes.`);
2596
+ }
2597
+ function cr({ width: e, height: t, features: n, ...r } = {}) {
2598
+ let i = c({
2599
+ title: r.layout?.name ? `${r.layout.name} - Designer` : "Report designer",
2600
+ width: e,
2601
+ height: t,
2602
+ features: n
2603
+ });
2604
+ if (!i) return null;
2605
+ let a = lr({
2606
+ ...r,
2607
+ mount: i.mount
2608
+ }), o = _(globalThis, i.window, a.destroy);
2609
+ return {
2610
+ ...a,
2611
+ window: i.window,
2612
+ destroy() {
2613
+ o(), a.destroy(), i.close();
2614
+ }
2615
+ };
2616
+ }
2617
+ function lr({ mount: e, layout: t, id: n = null, store: r, guardUnload: i = !0, onChange: a = null } = {}) {
2618
+ let o = typeof e == "string" ? document.querySelector(e) : e;
2619
+ if (!o) throw Error(`createDesigner: no element for mount ${JSON.stringify(e)}. Add <div id="report-designer"></div> to the page first.`);
2620
+ let c = o.ownerDocument;
2621
+ sr(r);
2622
+ let l = r ?? Jt(), u = {
2623
+ zoom: 1,
2624
+ fitWidth: !1,
2625
+ rulers: !1,
2626
+ layout: ue(t) ? le() : t,
2627
+ selection: [],
2628
+ id: n,
2629
+ dirty: !1,
2630
+ clipboard: [],
2631
+ mode: "design",
2632
+ dismissed: null
2633
+ }, f = tr(u.layout);
2634
+ o.classList.add("report-designer"), o.tabIndex = -1, o.innerHTML = ur(u.layout);
2635
+ let _ = o.querySelector("[data-role=\"canvas\"]"), v = o.querySelector("[data-role=\"stage\"]"), y = o.querySelector("[data-role=\"zoom-layer\"]"), b = o.querySelector("[data-role=\"panel\"]"), x = o.querySelector("[data-role=\"bar\"]"), S = o.querySelector("[data-role=\"foot\"]"), te = o.querySelector(".dz-main"), C = o.querySelector("[data-role=\"toasts\"]"), w = o.querySelector("[data-role=\"pages\"]");
2636
+ function T() {
2637
+ return u.selection.at(-1) ?? null;
2638
+ }
2639
+ function E(e) {
2640
+ return e ? (X(u.layout, e.band)?.items || []).find((t) => t.id === e.id) ?? null : null;
2641
+ }
2642
+ function D() {
2643
+ return E(T());
2644
+ }
2645
+ function O() {
2646
+ return u.selection.map(E).filter(Boolean);
2647
+ }
2648
+ function k() {
2649
+ let e = d(u.layout);
2650
+ if (u.mode === "preview") {
2651
+ let t = Yn(u.layout, u.data);
2652
+ return y.innerHTML = t.markup, w.textContent = t.error ? "" : `${t.pageCount} page${t.pageCount === 1 ? "" : "s"}`, A(e), de(), e;
2653
+ }
2654
+ w.textContent = "";
2655
+ let t = "";
2656
+ try {
2657
+ t = Me(u.layout, u.selection, { rulers: u.rulers });
2658
+ } catch {
2659
+ t = "";
2660
+ }
2661
+ return y.innerHTML = t, A(e), de(), e;
2662
+ }
2663
+ function A(e) {
2664
+ let t = u.mode !== "design" || e.length === 0 || Gt(e, u.dismissed);
2665
+ C.innerHTML = t ? "" : Kt(e), e.length === 0 && (u.dismissed = null);
2666
+ }
2667
+ function ne() {
2668
+ j();
2669
+ let e = je(u.layout, u.selection);
2670
+ for (let [t, { item: n, box: r }] of e.entries()) {
2671
+ let e = u.selection[t], i = _.querySelector(`[data-role="select"][data-select-id="${dr(n.id)}"]`);
2672
+ i && Object.assign(i.style, {
2673
+ top: `${r.y}px`,
2674
+ left: `${r.x}px`,
2675
+ width: `${r.w}px`,
2676
+ height: `${r.h}px`
2677
+ });
2678
+ let a = _.querySelector(`[data-band-type="${dr(e.band)}"] [data-item-id="${dr(n.id)}"]`);
2679
+ a && (Object.assign(a.style, {
2680
+ top: `${n.y}px`,
2681
+ left: `${n.x}px`,
2682
+ width: `${n.w}px`
2683
+ }), n.type !== "table" && (a.style.height = `${n.h}px`));
2684
+ }
2685
+ }
2686
+ function j() {
2687
+ let e = _.querySelector("[data-role=\"rules\"]");
2688
+ e && (e.innerHTML = u.rulers ? Oe(u.layout) : "");
2689
+ for (let e of _.querySelectorAll("[data-role=\"ruler-guides\"]")) e.innerHTML = De(u.layout, e.dataset.axis);
2690
+ }
2691
+ function M() {
2692
+ if (u.mode === "preview") return;
2693
+ let e = u.selection.length;
2694
+ b.innerHTML = e > 1 ? At(O()) : D() ? kt(D()) : jt(u.layout);
2695
+ }
2696
+ let N = (e, t) => e?.band === t?.band && e?.id === t?.id;
2697
+ function P(e, { add: t = !1 } = {}) {
2698
+ let n = e == null ? [] : [].concat(e), r;
2699
+ if (!t) r = n;
2700
+ else {
2701
+ r = [...u.selection];
2702
+ for (let e of n) {
2703
+ let t = r.findIndex((t) => N(t, e));
2704
+ t === -1 ? r.push(e) : r.splice(t, 1);
2705
+ }
2706
+ }
2707
+ r.length === u.selection.length && r.every((e, t) => N(e, u.selection[t])) || (u.selection = r, k(), M());
2708
+ }
2709
+ function re(e = null) {
2710
+ f.push(u.layout, e) && (u.dirty = !0, I(), ie());
2711
+ }
2712
+ function ie() {
2713
+ if (typeof a == "function") try {
2714
+ a(u.layout);
2715
+ } catch (e) {
2716
+ console.error("createDesigner: onChange threw", e);
2717
+ }
2718
+ }
2719
+ function F(e = null) {
2720
+ k(), M(), re(e);
2721
+ }
2722
+ function I() {
2723
+ x.querySelector("[data-role=\"name\"]").textContent = u.layout.name ?? "", x.querySelector("[data-role=\"undo\"]").disabled = !f.canUndo, x.querySelector("[data-role=\"redo\"]").disabled = !f.canRedo;
2724
+ let e = x.querySelector("[data-role=\"size\"]");
2725
+ e && u.layout.page && (e.innerHTML = `${u.layout.page.width} &times; ${u.layout.page.height}`);
2726
+ let t = x.querySelector("[data-role=\"rulers\"]");
2727
+ t.setAttribute("aria-pressed", String(u.rulers)), t.classList.toggle("is-on", u.rulers);
2728
+ let n = S.querySelector("[data-role=\"add-table\"]");
2729
+ n.disabled = !tt(u.layout), x.dataset.dirty = String(u.dirty);
2730
+ let r = x.querySelector("[data-role=\"status\"]");
2731
+ r.textContent = u.dirty ? "Unsaved changes" : u.id ? `Saved as ${u.id}.json` : "Not saved yet";
2732
+ }
2733
+ function L(e, { id: t, dirty: n }) {
2734
+ u.layout = e, u.selection = [], u.mode = "design", u.data = null, t !== void 0 && (u.id = t), n !== void 0 && (u.dirty = n), Ee(), ie();
2735
+ }
2736
+ function R(e, t) {
2737
+ gt(u.layout, e, t), u.selection = [{
2738
+ band: e,
2739
+ id: t.id
2740
+ }], F(`add:${t.id}`), B(e);
2741
+ }
2742
+ function se(e) {
2743
+ let t = new Set(e == null ? [] : [].concat(e));
2744
+ for (let e of _.querySelectorAll("[data-band-type]")) e.classList.toggle("is-target", t.has(e.dataset.bandType));
2745
+ for (let e of _.querySelectorAll("[data-band-tag]")) e.classList.toggle("is-target", t.has(e.dataset.bandTag));
2746
+ }
2747
+ function ce(e) {
2748
+ let t = _.querySelector("[data-role=\"guides\"]");
2749
+ t && (t.innerHTML = e ? Pe(Ne(u.layout, e.band), e.lines, e.gaps) : "");
2750
+ }
2751
+ function de() {
2752
+ y.style.transformOrigin = "top left", y.style.transform = `scale(${u.zoom})`;
2753
+ let e = y.offsetWidth, t = y.offsetHeight;
2754
+ e && t && (v.style.width = `${e * u.zoom}px`, v.style.height = `${t * u.zoom}px`), fe();
2755
+ }
2756
+ function fe() {
2757
+ if (G && !u.fitWidth) {
2758
+ let e = g.find((e) => Math.abs(e - u.zoom) < 1e-9);
2759
+ G.value = e === void 0 ? "fit" : String(e);
2760
+ }
2761
+ x.querySelector("[data-role=\"zoom-out\"]").disabled = !u.fitWidth && u.zoom <= p, x.querySelector("[data-role=\"zoom-in\"]").disabled = !u.fitWidth && u.zoom >= ee;
2762
+ }
2763
+ function pe(e) {
2764
+ u.fitWidth = !1, u.zoom = Math.min(Math.max(e, p), ee), de();
2765
+ }
2766
+ function me() {
2767
+ u.fitWidth = !0, G && (G.value = "fit");
2768
+ let e = _.clientWidth - 48, t = y.offsetWidth;
2769
+ e > 0 && t > 0 && (u.zoom = Math.min(Math.max(e / t, p), ee)), de();
2770
+ }
2771
+ function z(e) {
2772
+ let t = u.zoom;
2773
+ pe((e > 0 ? g.find((e) => e > t + 1e-9) : [...g].reverse().find((e) => e < t - 1e-9)) ?? t);
2774
+ }
2775
+ function B(e) {
2776
+ clearTimeout(B.timer), se(e), B.timer = setTimeout(() => se(null), 1200);
2777
+ }
2778
+ let V = null;
2779
+ function H() {
2780
+ V?.remove(), V = null;
2781
+ }
2782
+ function he(e, t) {
2783
+ H(), te.insertAdjacentHTML("beforeend", Ut(Ht({
2784
+ count: u.selection.length,
2785
+ canPaste: u.clipboard.length > 0,
2786
+ canDuplicate: tt(u.layout) || !O().some((e) => e.type === "table")
2787
+ }))), V = te.querySelector("[data-role=\"menu\"]"), V.addEventListener("click", _e);
2788
+ let n = te.getBoundingClientRect(), r = V.getBoundingClientRect(), i = Wt({
2789
+ x: e - n.left,
2790
+ y: t - n.top
2791
+ }, {
2792
+ width: r.width,
2793
+ height: r.height
2794
+ }, {
2795
+ width: n.width,
2796
+ height: n.height
2797
+ });
2798
+ V.style.left = `${i.left}px`, V.style.top = `${i.top}px`, V.querySelector("button:not([disabled])")?.focus();
2799
+ }
2800
+ function ge(e) {
2801
+ if (u.mode !== "design") return;
2802
+ e.preventDefault();
2803
+ let t = e.target.closest?.("[data-item-id]"), n = t?.closest("[data-band-type]")?.dataset.bandType ?? null;
2804
+ if (t && n) {
2805
+ let e = {
2806
+ band: n,
2807
+ id: t.dataset.itemId
2808
+ };
2809
+ u.selection.some((t) => t.band === e.band && t.id === e.id) || P(e);
2810
+ } else P(null);
2811
+ he(e.clientX, e.clientY);
2812
+ }
2813
+ function _e(e) {
2814
+ let t = e.target.closest?.("[data-action]");
2815
+ !t || t.disabled || (e.preventDefault(), H(), W(t.dataset.action, t.dataset));
2816
+ }
2817
+ function U(e) {
2818
+ V && !V.contains(e.target) && H();
2819
+ }
2820
+ function ve(e) {
2821
+ V && e.key === "Escape" && H();
2822
+ }
2823
+ function W(e, t) {
2824
+ let n = D();
2825
+ switch (e) {
2826
+ case "add-text": {
2827
+ let e = Ot(u.layout, T());
2828
+ if (!e) return;
2829
+ R(e, ut(u.layout, X(u.layout, e)));
2830
+ return;
2831
+ }
2832
+ case "add-box": {
2833
+ let e = Ot(u.layout, T());
2834
+ if (!e) return;
2835
+ R(e, ft(u.layout, X(u.layout, e)));
2836
+ return;
2837
+ }
2838
+ case "add-image": {
2839
+ let e = Ot(u.layout, T());
2840
+ if (!e) return;
2841
+ R(e, pt(u.layout, X(u.layout, e)));
2842
+ return;
2843
+ }
2844
+ case "upload-image":
2845
+ if (n?.type !== "image") return;
2846
+ ke(n);
2847
+ return;
2848
+ case "clear-image":
2849
+ if (n?.type !== "image" || !n.src) return;
2850
+ n.src = null, F(`image:${n.id}`);
2851
+ return;
2852
+ case "add-line": {
2853
+ let e = Ot(u.layout, T());
2854
+ if (!e) return;
2855
+ R(e, dt(u.layout, X(u.layout, e), t?.orientation));
2856
+ return;
2857
+ }
2858
+ case "add-field":
2859
+ Un(o, u.layout, T()?.band ?? null).then((e) => {
2860
+ if (!e) return;
2861
+ let t = X(u.layout, e.band);
2862
+ if (!t) return;
2863
+ let n = ut(u.layout, t);
2864
+ n.value = e.value, n.w = e.w, n.style.align = e.align, R(e.band, n);
2865
+ });
2866
+ return;
2867
+ case "add-table": {
2868
+ let e = Ot(u.layout, T());
2869
+ if (!e || !tt(u.layout)) return;
2870
+ jn(o).then((t) => {
2871
+ t != null && R(e, ht(u.layout, X(u.layout, e), t));
2872
+ });
2873
+ return;
2874
+ }
2875
+ case "duplicate-item": {
2876
+ if (!u.selection.length) return;
2877
+ let e = [...u.selection], t = [];
2878
+ for (let n of e) {
2879
+ let e = bt(u.layout, n.band, n.id);
2880
+ e && t.push({
2881
+ band: n.band,
2882
+ id: e.id
2883
+ });
2884
+ }
2885
+ if (!t.length) return;
2886
+ u.selection = t, F(`duplicate:${t.map((e) => e.id).join(",")}`), B([...new Set(t.map((e) => e.band))]);
2887
+ return;
2888
+ }
2889
+ case "dismiss-problems":
2890
+ u.dismissed = d(u.layout), C.innerHTML = "";
2891
+ return;
2892
+ case "copy-items": {
2893
+ if (!u.selection.length) return;
2894
+ let e = u.selection.map((e) => ({
2895
+ band: e.band,
2896
+ item: E(e)
2897
+ })).filter((e) => e.item).map((e) => ({
2898
+ band: e.band,
2899
+ item: structuredClone(e.item)
2900
+ }));
2901
+ if (!e.length) return;
2902
+ u.clipboard = e, q(e.length > 1 ? `Copied ${e.length} items` : "Copied", { ms: 2e3 });
2903
+ return;
2904
+ }
2905
+ case "paste-items": {
2906
+ if (!u.clipboard.length) return;
2907
+ let e = Ot(u.layout, T());
2908
+ if (!e) return;
2909
+ let t = Ct(u.layout, e, u.clipboard);
2910
+ if (!t.length) return;
2911
+ u.clipboard = t.map((t) => ({
2912
+ band: e,
2913
+ item: structuredClone(t)
2914
+ })), u.selection = t.map((t) => ({
2915
+ band: e,
2916
+ id: t.id
2917
+ })), F(`paste:${t.map((e) => e.id).join(",")}`), B(e);
2918
+ return;
2919
+ }
2920
+ case "delete-item": {
2921
+ if (!u.selection.length) return;
2922
+ let e = u.selection.map((e) => e.id).join(",");
2923
+ for (let e of u.selection) wt(u.layout, e.band, e.id);
2924
+ u.selection = [], F(`delete:${e}`);
2925
+ return;
2926
+ }
2927
+ case "add-column":
2928
+ if (n?.type !== "table") return;
2929
+ Et(n), F(`column:add:${n.id}`);
2930
+ return;
2931
+ case "remove-column":
2932
+ if (n?.type !== "table") return;
2933
+ Dt(n, Number(t.index)) && F(`column:remove:${n.id}`);
2934
+ return;
2935
+ case "undo": {
2936
+ let e = f.undo();
2937
+ e && L(e, { dirty: !0 });
2938
+ return;
2939
+ }
2940
+ case "redo": {
2941
+ let e = f.redo();
2942
+ e && L(e, { dirty: !0 });
2943
+ return;
2944
+ }
2945
+ case "open": return be();
2946
+ case "save": return xe();
2947
+ case "data": return Ce();
2948
+ case "open-window": return we();
2949
+ case "zoom-in": return z(1);
2950
+ case "zoom-out": return z(-1);
2951
+ case "toggle-rulers":
2952
+ u.rulers = !u.rulers, k(), I();
2953
+ return;
2954
+ case "toggle-preview": return K();
2955
+ }
2956
+ }
2957
+ async function ye() {
2958
+ return !u.dirty || Pn(o, u.layout?.name ?? "");
2959
+ }
2960
+ async function be() {
2961
+ if (!await ye()) return;
2962
+ let e;
2963
+ try {
2964
+ e = await l.list();
2965
+ } catch (e) {
2966
+ return J(e);
2967
+ }
2968
+ let t = await Mn(o, e);
2969
+ if (t) {
2970
+ if (t.blank) {
2971
+ L(le(), {
2972
+ id: null,
2973
+ dirty: !1
2974
+ }), f.reset(u.layout), I();
2975
+ return;
2976
+ }
2977
+ try {
2978
+ L(await l.load(t.id), {
2979
+ id: t.id,
2980
+ dirty: !1
2981
+ }), f.reset(u.layout), I();
2982
+ } catch (e) {
2983
+ J(e);
2984
+ }
2985
+ }
2986
+ }
2987
+ async function xe() {
2988
+ let e = u.id;
2989
+ if (!e) {
2990
+ let t = await Nn(o, u.layout.name ?? "");
2991
+ if (!t) return;
2992
+ e = t.id, u.layout.name = t.name;
2993
+ }
2994
+ try {
2995
+ await l.save(e, u.layout), u.id = e, u.dirty = !1, I(), await Se(e);
2996
+ } catch (e) {
2997
+ J(e);
2998
+ }
2999
+ }
3000
+ async function Se(e) {
3001
+ if (!(!l.loadData || !l.saveData)) try {
3002
+ let { data: t, added: n } = cn(await l.loadData(e), u.layout);
3003
+ n && await l.saveData(e, t);
3004
+ } catch {}
3005
+ }
3006
+ async function Ce() {
3007
+ let e = null;
3008
+ if (u.id && l.loadData) try {
3009
+ e = await l.loadData(u.id);
3010
+ } catch (e) {
3011
+ return J(e);
3012
+ }
3013
+ let t = e == null, n = await Vn(o, cn(e, u.layout).data, {
3014
+ id: u.id,
3015
+ generated: t
3016
+ });
3017
+ if (n) {
3018
+ if (!u.id) return J(/* @__PURE__ */ Error("Save the report first - its data file is named after it."));
3019
+ try {
3020
+ await l.saveData(u.id, n);
3021
+ } catch (e) {
3022
+ J(e);
3023
+ }
3024
+ }
3025
+ }
3026
+ function we() {
3027
+ let e;
3028
+ try {
3029
+ e = h(u.layout, u.data ?? sn(u.layout));
3030
+ } catch (e) {
3031
+ J(e);
3032
+ return;
3033
+ }
3034
+ let t = s({
3035
+ paginated: e,
3036
+ title: u.layout?.name || "Report"
3037
+ });
3038
+ if (!t) {
3039
+ q("The browser blocked the report window - allow pop-ups for this page", {
3040
+ problem: !0,
3041
+ ms: 6e3
3042
+ });
3043
+ return;
3044
+ }
3045
+ Te.add(t);
3046
+ }
3047
+ let Te = /* @__PURE__ */ new Set(), G = null;
3048
+ async function K() {
3049
+ if (u.mode === "preview") {
3050
+ u.mode = "design", u.data = null, Ee();
3051
+ return;
3052
+ }
3053
+ let e = null;
3054
+ if (u.id && l.loadData) try {
3055
+ e = await l.loadData(u.id);
3056
+ } catch {}
3057
+ u.data = cn(e, u.layout).data, u.mode = "preview", u.selection = [], Ee();
3058
+ }
3059
+ function Ee() {
3060
+ o.dataset.mode = u.mode;
3061
+ let e = x.querySelector("[data-action=\"toggle-preview\"]"), t = u.mode === "preview";
3062
+ e.innerHTML = $(t ? "design" : "preview"), e.title = t ? "Back to the design (ctrl+E)" : "Run the report (ctrl+E)", e.setAttribute("aria-label", e.title), e.setAttribute("aria-pressed", String(t)), k(), M(), I();
3063
+ }
3064
+ function q(e, { problem: t = !1, ms: n = 6e3 } = {}) {
3065
+ let r = x.querySelector("[data-role=\"status\"]");
3066
+ r.textContent = e, t ? r.dataset.problem = "true" : delete r.dataset.problem, clearTimeout(J.timer), J.timer = setTimeout(() => {
3067
+ delete r.dataset.problem, I();
3068
+ }, n);
3069
+ }
3070
+ function ke(e) {
3071
+ let t = c.createElement("input");
3072
+ t.type = "file", t.accept = nr.join(","), t.addEventListener("change", () => {
3073
+ let n = t.files?.[0];
3074
+ if (!n) return;
3075
+ if (!nr.includes(n.type)) {
3076
+ q(`${n.name} is not a PNG, JPEG, GIF or WebP image`, { problem: !0 });
3077
+ return;
3078
+ }
3079
+ if (n.size > rr) {
3080
+ q(`${n.name} is ${ar(n.size)} - too large to store in a layout. Bind the image to a data field and supply its URL instead`, { problem: !0 });
3081
+ return;
3082
+ }
3083
+ let r = new (c.defaultView ?? globalThis).FileReader();
3084
+ r.addEventListener("load", () => {
3085
+ Ae(e) && (e.src = String(r.result), F(`image:${e.id}`), n.size > ir && q(`Stored ${n.name} (${ar(n.size)}) in the layout - every copy of the report carries it`));
3086
+ }), r.addEventListener("error", () => J(r.error)), r.readAsDataURL(n);
3087
+ }), t.click();
3088
+ }
3089
+ function Ae(e) {
3090
+ return (u.layout.bands ?? []).some((t) => (t.items ?? []).includes(e));
3091
+ }
3092
+ function J(e) {
3093
+ q(e instanceof Yt ? e.message : `Something went wrong: ${e?.message ?? e}`, { problem: !0 });
3094
+ }
3095
+ function Fe(e, t) {
3096
+ t ? at(u.layout, e) : (ot(u.layout, e), u.selection = u.selection.filter((t) => t.band !== e)), F(`band:${e}`);
3097
+ }
3098
+ function Ie(e, t) {
3099
+ let n = X(u.layout, e);
3100
+ if (!n) return;
3101
+ let r = String(t).trim();
3102
+ if (r === "") delete n.height;
3103
+ else if (/^-?[\d.]+\s*%$/.test(r)) n.height = r;
3104
+ else if (Number.isFinite(Number(r))) n.height = Number(r);
3105
+ else return;
3106
+ k(), re(`band-height:${e}`);
3107
+ }
3108
+ o.dataset.mode = u.mode, G = m(x.querySelector("[data-role=\"zoom-dropdown\"]")), G.addEventListener("change", () => {
3109
+ G.value === "fit" ? me() : pe(Number(G.value));
3110
+ });
3111
+ let Re = () => {
3112
+ u.fitWidth && me();
3113
+ }, ze = c.defaultView ?? globalThis;
3114
+ ze.addEventListener("resize", Re);
3115
+ let Be = (e) => {
3116
+ u.dirty && (e.preventDefault(), e.returnValue = "");
3117
+ };
3118
+ i && ze.addEventListener("beforeunload", Be), k(), M(), I();
3119
+ let Ve = Ye({
3120
+ canvas: _,
3121
+ getLayout: () => u.layout,
3122
+ getSelection: () => u.selection,
3123
+ select: P,
3124
+ remove: () => W("delete-item"),
3125
+ duplicate: () => {
3126
+ let e = u.selection.map((e) => e.id).join(",");
3127
+ return W("duplicate-item"), u.selection.map((e) => e.id).join(",") !== e;
3128
+ },
3129
+ enabled: () => u.mode === "design",
3130
+ getZoom: () => u.zoom,
3131
+ rulers: () => u.rulers,
3132
+ onTarget: se,
3133
+ onGuides: ce,
3134
+ commit: ({ live: e, band: t, key: n = null }) => {
3135
+ if (!e && t?.length) {
3136
+ let e = !1;
3137
+ u.selection = u.selection.map((t) => {
3138
+ let n = E(t), r = n ? Le(u.layout, t.band, n) : null;
3139
+ return r && r !== t.band && Tt(u.layout, t.band, r, t.id) ? (e = !0, {
3140
+ band: r,
3141
+ id: t.id
3142
+ }) : t;
3143
+ }), e && M();
3144
+ }
3145
+ e ? ne() : k(), Rt(b, D(), u.layout), e || re(n ?? `move:${u.selection.map((e) => e.id).join(",")}`);
3146
+ }
3147
+ }), He = Lt({
3148
+ panel: b,
3149
+ getTarget: () => {
3150
+ let e = D();
3151
+ return e ? {
3152
+ target: e,
3153
+ fields: oe(e)
3154
+ } : {
3155
+ target: u.layout,
3156
+ fields: ae(u.layout)
3157
+ };
3158
+ },
3159
+ getItem: D,
3160
+ changed: (e, { rebuild: t = !1 } = {}) => {
3161
+ k(), t && M(), re(e);
3162
+ },
3163
+ act: W,
3164
+ toggleBand: Fe,
3165
+ setBandHeight: Ie
3166
+ });
3167
+ function Y(e) {
3168
+ let t = e.target.closest?.("[data-action]");
3169
+ t && (e.preventDefault(), W(t.dataset.action, t.dataset));
3170
+ }
3171
+ function Ue(e) {
3172
+ return o.contains(e.target) ? !0 : e.target === c.body || e.target === c.documentElement;
3173
+ }
3174
+ function We(e) {
3175
+ let t = e.target.closest?.("input, textarea, select, button, a, label, [tabindex]");
3176
+ t && t !== o || o.focus({ preventScroll: !0 });
3177
+ }
3178
+ function Ge(e) {
3179
+ if (!Ue(e)) return;
3180
+ let t = e.key.toLowerCase();
3181
+ if (t === "z" && !e.ctrlKey && !e.metaKey) {
3182
+ if (e.target.closest?.("input, textarea, select")) return;
3183
+ e.preventDefault(), z(e.altKey ? -1 : 1);
3184
+ return;
3185
+ }
3186
+ if (e.ctrlKey || e.metaKey) {
3187
+ if (t === "c" || t === "v") {
3188
+ if (e.target.closest?.("input, textarea, select") || t === "c" && String(globalThis.getSelection?.() ?? "")) return;
3189
+ e.preventDefault(), W(t === "c" ? "copy-items" : "paste-items");
3190
+ return;
3191
+ }
3192
+ if (t === "s") {
3193
+ e.preventDefault(), W("save");
3194
+ return;
3195
+ }
3196
+ if (t === "o") {
3197
+ e.preventDefault(), W("open");
3198
+ return;
3199
+ }
3200
+ if (t === "e") {
3201
+ e.preventDefault(), W("toggle-preview");
3202
+ return;
3203
+ }
3204
+ if (t === "0") {
3205
+ e.preventDefault(), pe(1);
3206
+ return;
3207
+ }
3208
+ if (t === "z") {
3209
+ e.preventDefault(), W(e.shiftKey || e.altKey ? "redo" : "undo");
3210
+ return;
3211
+ }
3212
+ if (t === "y") {
3213
+ e.preventDefault(), W("redo");
3214
+ return;
3215
+ }
3216
+ t === "d" && (e.preventDefault(), W("duplicate-item"));
3217
+ }
3218
+ }
3219
+ return x.addEventListener("click", Y), S.addEventListener("click", Y), C.addEventListener("click", Y), o.addEventListener("pointerdown", We), c.addEventListener("keydown", Ge), _.addEventListener("contextmenu", ge), _.addEventListener("scroll", H), c.addEventListener("pointerdown", U), c.addEventListener("keydown", ve), {
3220
+ get layout() {
3221
+ return u.layout;
3222
+ },
3223
+ get mode() {
3224
+ return u.mode;
3225
+ },
3226
+ togglePreview: K,
3227
+ get sampleData() {
3228
+ return sn(u.layout);
3229
+ },
3230
+ get selection() {
3231
+ return T();
3232
+ },
3233
+ get selections() {
3234
+ return [...u.selection];
3235
+ },
3236
+ select: P,
3237
+ get id() {
3238
+ return u.id;
3239
+ },
3240
+ get dirty() {
3241
+ return u.dirty;
3242
+ },
3243
+ open(e, t = null) {
3244
+ return L(ue(e) ? le() : e, {
3245
+ id: t,
3246
+ dirty: !1
3247
+ }), f.reset(u.layout), I(), d(u.layout);
3248
+ },
3249
+ save: xe,
3250
+ redraw: k,
3251
+ destroy() {
3252
+ Ve(), He(), x.removeEventListener("click", Y), S.removeEventListener("click", Y), C.removeEventListener("click", Y), o.removeEventListener("pointerdown", We), c.removeEventListener("keydown", Ge), _.removeEventListener("contextmenu", ge), _.removeEventListener("scroll", H), c.removeEventListener("pointerdown", U), c.removeEventListener("keydown", ve), (c.defaultView ?? globalThis).removeEventListener("resize", Re), ze.removeEventListener("beforeunload", Be), G?.destroy(), H(), clearTimeout(J.timer), clearTimeout(B.timer);
3253
+ for (let e of Te) e.destroy();
3254
+ Te.clear(), o.innerHTML = "", o.classList.remove("report-designer");
3255
+ }
3256
+ };
3257
+ }
3258
+ function ur(e) {
3259
+ let t = e.page ? `${e.page.width} &times; ${e.page.height}` : "";
3260
+ return `
3261
+ <header class="dz-bar" data-role="bar">
3262
+ <span class="dz-brand">Report Studio</span>
3263
+
3264
+ <span class="dz-title">
3265
+ <span class="dz-name" data-role="name">${fr(e.name ?? "")}</span>
3266
+ <span class="dz-status" data-role="status">Not saved yet</span>
3267
+ </span>
3268
+
3269
+ <div class="dz-bar-group">
3270
+ <button type="button" class="dz-tool" data-role="undo" data-action="undo"
3271
+ title="Undo (ctrl+Z)" aria-label="Undo" disabled
3272
+ >${$("undo")}</button>
3273
+ <button type="button" class="dz-tool" data-role="redo" data-action="redo"
3274
+ title="Redo (ctrl+alt+Z or ctrl+shift+Z)" aria-label="Redo" disabled
3275
+ >${$("redo")}</button>
3276
+ </div>
3277
+
3278
+ <div class="dz-bar-group">
3279
+ <button type="button" class="dz-tool" data-action="open"
3280
+ title="Open a report (ctrl+O)" aria-label="Open a report"
3281
+ >${$("open")}</button>
3282
+ <button type="button" class="dz-tool" data-action="save"
3283
+ title="Save (ctrl+S)" aria-label="Save"
3284
+ >${$("save")}</button>
3285
+ <button type="button" class="dz-tool" data-action="data"
3286
+ title="The data this report needs" aria-label="Report data"
3287
+ >${$("data")}</button>
3288
+ </div>
3289
+
3290
+ <div class="dz-bar-group">
3291
+ <button type="button" class="dz-tool" data-role="rulers"
3292
+ data-action="toggle-rulers"
3293
+ title="Rulers and guides - drag off a ruler to place one"
3294
+ aria-label="Rulers and guides" aria-pressed="false"
3295
+ >${$("ruler")}</button>
3296
+ <button type="button" class="dz-tool" data-action="toggle-preview"
3297
+ title="Run the report (ctrl+E)" aria-label="Run the report"
3298
+ aria-pressed="false"
3299
+ >${$("preview")}</button>
3300
+
3301
+ <!--
3302
+ A button, not a link: the window is built from the design as it
3303
+ stands rather than fetched from a URL, so it works on a report
3304
+ that has never been saved - which a link to the preview screen
3305
+ could not, because that screen reads the report off the disk.
3306
+ -->
3307
+ <button type="button" class="dz-tool" data-role="open-preview"
3308
+ data-action="open-window"
3309
+ title="Open the report in its own window"
3310
+ aria-label="Open the report in its own window"
3311
+ >${$("external")}</button>
3312
+ </div>
3313
+
3314
+ <span class="dz-pages" data-role="pages"></span>
3315
+ <span class="dz-size" data-role="size">${t}</span>
3316
+
3317
+ <!--
3318
+ The same three controls the viewer has, in the same order and with
3319
+ the same shortcuts. A designer and a preview of the same report
3320
+ should not zoom differently.
3321
+ -->
3322
+ <div class="dz-bar-group dz-zoom-group">
3323
+ <button type="button" class="dz-tool" data-role="zoom-out"
3324
+ data-action="zoom-out"
3325
+ title="Zoom out (alt+Z)" aria-label="Zoom out">&#8722;</button>
3326
+
3327
+ <div class="dropdown" data-role="zoom-dropdown">
3328
+ <button type="button" class="dropdown-trigger" data-role="zoom"
3329
+ aria-haspopup="listbox" aria-expanded="false"
3330
+ aria-label="Zoom level">
3331
+ <span class="dropdown-value">100%</span>
3332
+ <span class="dropdown-caret" aria-hidden="true"></span>
3333
+ </button>
3334
+
3335
+ <ul class="dropdown-menu" data-role="zoom-menu" role="listbox"
3336
+ aria-label="Zoom level" hidden>
3337
+ <li class="dropdown-item" role="option" tabindex="-1"
3338
+ data-value="fit">Fit width</li>
3339
+ ${g.map((e) => `
3340
+ <li class="dropdown-item" role="option" tabindex="-1"
3341
+ data-value="${e}"${e === 1 ? " data-selected=\"true\"" : ""}
3342
+ >${Math.round(e * 100)}%</li>`).join("")}
3343
+ </ul>
3344
+ </div>
3345
+
3346
+ <button type="button" class="dz-tool" data-role="zoom-in"
3347
+ data-action="zoom-in"
3348
+ title="Zoom in (Z)" aria-label="Zoom in">&#43;</button>
3349
+ </div>
3350
+ </header>
3351
+
3352
+ <div class="dz-body">
3353
+ <div class="dz-main">
3354
+ <div class="dz-canvas" data-role="canvas">
3355
+ <!--
3356
+ Two boxes for one job. The inner one is scaled, and a
3357
+ transform changes nothing about layout - so at 200% there
3358
+ would be nothing to scroll. The outer one is given the
3359
+ scaled size in px, and is what the canvas scrolls.
3360
+ -->
3361
+ <div class="dz-stage" data-role="stage">
3362
+ <div class="dz-zoom-layer" data-role="zoom-layer"></div>
3363
+ </div>
3364
+ </div>
3365
+
3366
+ <!--
3367
+ The tools sit under the page rather than in the bar: the bar is
3368
+ about the report as a whole, and these act on the band you are
3369
+ looking at. Icon-only, so the strip stays out of the way of the
3370
+ thing being designed - the label lives on the button for a
3371
+ screen reader and in the tooltip for everyone else.
3372
+ -->
3373
+ <footer class="dz-foot" data-role="foot">
3374
+ <button type="button" class="dz-tool" data-action="add-text"
3375
+ title="Add a text box" aria-label="Add a text box"
3376
+ >${$("text")}</button>
3377
+ <button type="button" class="dz-tool" data-role="add-table"
3378
+ data-action="add-table"
3379
+ title="Add a table" aria-label="Add a table"
3380
+ >${$("table")}</button>
3381
+ <button type="button" class="dz-tool" data-action="add-line"
3382
+ title="Add a line" aria-label="Add a line"
3383
+ >${$("line")}</button>
3384
+ <button type="button" class="dz-tool" data-action="add-box"
3385
+ title="Add a box" aria-label="Add a box"
3386
+ >${$("box")}</button>
3387
+ <button type="button" class="dz-tool" data-action="add-image"
3388
+ title="Add an image" aria-label="Add an image"
3389
+ >${$("image")}</button>
3390
+ <button type="button" class="dz-tool" data-action="add-field"
3391
+ title="Insert a page number, date or total"
3392
+ aria-label="Insert a field"
3393
+ >${$("field")}</button>
3394
+ </footer>
3395
+
3396
+ <!--
3397
+ The corner messages, in the page area rather than the window.
3398
+ Pinned to the window they would hang over the properties rail -
3399
+ which is where the band switches are, and so where most of what
3400
+ the validator complains about is actually fixed.
3401
+ -->
3402
+ <div class="dz-toasts" data-role="toasts"></div>
3403
+ </div>
3404
+
3405
+ <aside class="dz-panel" data-role="panel" aria-label="Properties"></aside>
3406
+ </div>`;
3407
+ }
3408
+ function dr(e) {
3409
+ let t = String(e);
3410
+ return globalThis.CSS?.escape ? CSS.escape(t) : JSON.stringify(t).slice(1, -1);
3411
+ }
3412
+ function fr(e) {
3413
+ return e == null ? "" : String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
3414
+ }
3415
+ //#endregion
3416
+ export { cr as n, lr as t };