@tatamicks/core 1.0.2 → 1.0.3

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.
@@ -0,0 +1,875 @@
1
+ import { jsxs as q, jsx as N } from "react/jsx-runtime";
2
+ import { useMemo as A, useCallback as O } from "react";
3
+ var Z = /* @__PURE__ */ ((t) => (t.left = "left", t.center = "center", t.right = "right", t))(Z || {}), Q = /* @__PURE__ */ ((t) => (t.top = "top", t.center = "center", t.bottom = "bottom", t))(Q || {});
4
+ const Gt = {
5
+ kind: "alignment",
6
+ defaultProps: {
7
+ horizontal: "left",
8
+ vertical: "center"
9
+ /* center */
10
+ }
11
+ }, Ht = {
12
+ kind: "checkboxStyle",
13
+ defaultProps: {
14
+ styleConfig: {
15
+ checkboxSize: { value: 16, unit: "px" },
16
+ borderWidth: { value: 1, unit: "px" },
17
+ borderColor: "#000000",
18
+ checkWidth: { value: 3.5, unit: "px" },
19
+ checkColor: "#000000",
20
+ backgroundColor: "#ffffff",
21
+ checkedBackgroundColor: "#ffffff"
22
+ }
23
+ }
24
+ }, G = "application/x-tatamicks-block", S = "application/x-tatamicks-block-kind-";
25
+ function Vt(t, e, r) {
26
+ if (!t.dataTransfer) return;
27
+ const n = { kind: e, defaultSize: r };
28
+ t.dataTransfer.setData(G, JSON.stringify(n)), t.dataTransfer.setData(`${S}${e}`, ""), t.dataTransfer.effectAllowed = "copy";
29
+ }
30
+ function Wt(t) {
31
+ if (!t.dataTransfer) return null;
32
+ const e = t.dataTransfer.getData(G);
33
+ if (!e) return null;
34
+ try {
35
+ return JSON.parse(e);
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+ function Ft(t) {
41
+ if (!t.dataTransfer) return null;
42
+ const e = Array.from(t.dataTransfer.types).find(
43
+ (r) => r.startsWith(S)
44
+ );
45
+ return e ? e.slice(S.length) : null;
46
+ }
47
+ const Kt = {
48
+ colCount: 20,
49
+ rowCount: 28
50
+ };
51
+ var tt = /* @__PURE__ */ ((t) => (t.A4 = "A4", t.B5 = "B5", t.A3 = "A3", t.LETTER = "Letter", t.LEGAL = "Legal", t.CUSTOM = "Custom", t))(tt || {});
52
+ const et = {
53
+ A4: {
54
+ preset: "A4",
55
+ width: { value: 210, unit: "mm" },
56
+ height: { value: 297, unit: "mm" }
57
+ },
58
+ A3: {
59
+ preset: "A3",
60
+ width: { value: 297, unit: "mm" },
61
+ height: { value: 420, unit: "mm" }
62
+ },
63
+ B5: {
64
+ preset: "B5",
65
+ width: { value: 182, unit: "mm" },
66
+ height: { value: 257, unit: "mm" }
67
+ },
68
+ Letter: {
69
+ preset: "Letter",
70
+ width: { value: 8.5, unit: "inch" },
71
+ height: { value: 11, unit: "inch" }
72
+ },
73
+ Legal: {
74
+ preset: "Legal",
75
+ width: { value: 8.5, unit: "inch" },
76
+ height: { value: 14, unit: "inch" }
77
+ },
78
+ Custom: {
79
+ preset: "Custom",
80
+ width: { value: 210, unit: "mm" },
81
+ height: { value: 297, unit: "mm" }
82
+ }
83
+ }, rt = {
84
+ top: { value: 10, unit: "mm" },
85
+ right: { value: 10, unit: "mm" },
86
+ bottom: { value: 10, unit: "mm" },
87
+ left: { value: 10, unit: "mm" }
88
+ }, Xt = {
89
+ size: et.A4,
90
+ margin: rt
91
+ }, zt = {
92
+ // ==================== GridLayer (10-90) ====================
93
+ GRID_CANVAS: 10,
94
+ MARGIN_OVERLAY: 20,
95
+ GRID_OVERLAY: 30,
96
+ BORDER_OVERLAY: 40,
97
+ // ==================== BlockLayer (100-999,999) ====================
98
+ BLOCK_LAYER_MIN: 100,
99
+ BLOCK_LAYER_MAX: 999999,
100
+ BLOCK_LAYER_STEP: 100,
101
+ // ==================== InteractionLayer (2,000,000+) ====================
102
+ SELECT_BLOCK: 2e6,
103
+ INTERACTION_LAYER_BASE: 21e5,
104
+ BLOCK_GHOST: 22e5,
105
+ HOVER_OUTLINE: 23e5,
106
+ EDIT_BLOCK: 24e5,
107
+ BLOCK_SELECT_BORDER: 25e5,
108
+ BLOCK_HANDLES: 26e5,
109
+ SELECTION_ACTION_BAR: 265e4,
110
+ GRID_GHOST: 27e5,
111
+ DROPDOWN: 34e5
112
+ }, Jt = {
113
+ BG: 10,
114
+ CONTENT: 50,
115
+ GUIDE: 70,
116
+ BORDER: 80,
117
+ VALIDATION: 90
118
+ };
119
+ function Yt(t, e) {
120
+ const r = t.match(/^(\d+(?:\.\d+)?)([a-zA-Z%]+)$/);
121
+ if (!r)
122
+ throw new Error(`Invalid dimension string: ${t}`);
123
+ const n = Number(r[1]), o = r[2];
124
+ if (!e.includes(o))
125
+ throw new Error(`Invalid unit: ${o}`);
126
+ return { value: n, unit: o };
127
+ }
128
+ function qt(t) {
129
+ return `${t.value}${t.unit}`;
130
+ }
131
+ const b = 96, nt = 10, H = 25.4, ot = 0.352778, at = H / b, h = {
132
+ fromCm: (t) => t * nt,
133
+ fromInch: (t) => t * H,
134
+ fromPt: (t) => t * ot,
135
+ fromPx: (t) => t * at,
136
+ fromDim(t) {
137
+ switch (t.unit) {
138
+ case "mm":
139
+ return t.value;
140
+ case "cm":
141
+ return h.fromCm(t.value);
142
+ case "inch":
143
+ return h.fromInch(t.value);
144
+ case "pt":
145
+ return h.fromPt(t.value);
146
+ case "px":
147
+ return h.fromPx(t.value);
148
+ case "fr":
149
+ case "%":
150
+ throw new Error(
151
+ `Cannot convert ${t.unit} to mm. Use physical units only.`
152
+ );
153
+ default: {
154
+ const e = t.unit;
155
+ throw new Error(`Unsupported unit: ${e}`);
156
+ }
157
+ }
158
+ }
159
+ }, it = 25.4, st = 2.54, ct = 72, l = {
160
+ fromMm: (t, e = b) => t * e / it,
161
+ fromCm: (t, e = b) => t * e / st,
162
+ fromInch: (t, e = b) => t * e,
163
+ fromPt: (t, e = b) => t * e / ct,
164
+ // CSS px(96dpi 基準)を指定 DPI のスクリーン物理 px に変換
165
+ fromPx: (t, e = b) => t * e / b,
166
+ fromDim(t, e = b, r) {
167
+ switch (t.unit) {
168
+ case "mm":
169
+ return l.fromMm(t.value, e);
170
+ case "cm":
171
+ return l.fromCm(t.value, e);
172
+ case "inch":
173
+ return l.fromInch(t.value, e);
174
+ case "pt":
175
+ return l.fromPt(t.value, e);
176
+ case "px":
177
+ return l.fromPx(t.value, e);
178
+ case "%":
179
+ if (r === void 0)
180
+ throw new Error("Base size must be defined for percentage values.");
181
+ return t.value / 100 * r;
182
+ case "fr":
183
+ throw new Error(
184
+ `Cannot convert ${t.unit} to px. Use physical units only.`
185
+ );
186
+ default: {
187
+ const n = t.unit;
188
+ throw new Error(`Unsupported unit: ${n}`);
189
+ }
190
+ }
191
+ }
192
+ }, ut = {
193
+ "flex-start": "left",
194
+ center: "center",
195
+ "flex-end": "right"
196
+ }, lt = {
197
+ "flex-start": "top",
198
+ center: "center",
199
+ "flex-end": "bottom"
200
+ };
201
+ function ft(t) {
202
+ return typeof t == "object" && t !== null && t.value === 1 && t.unit === "fr";
203
+ }
204
+ function j(t) {
205
+ const e = {};
206
+ for (let r = 0; r < t.length; r++) {
207
+ const n = t[r];
208
+ n !== void 0 && !ft(n) && (e[r] = n);
209
+ }
210
+ return e;
211
+ }
212
+ function V(t) {
213
+ if (typeof t != "object" || t === null)
214
+ throw new Error("grid must be an object");
215
+ const e = t;
216
+ if (Array.isArray(e.cols) && Array.isArray(e.rows)) {
217
+ const r = e.cols, n = e.rows, o = {
218
+ colCount: r.length,
219
+ rowCount: n.length
220
+ }, a = j(r);
221
+ Object.keys(a).length > 0 && (o.cols = a);
222
+ const s = j(n);
223
+ return Object.keys(s).length > 0 && (o.rows = s), o;
224
+ }
225
+ return t;
226
+ }
227
+ function mt(t) {
228
+ if (!("isIndividual" in t))
229
+ return t;
230
+ const e = { ...t }, r = e.isIndividual ?? !0;
231
+ if (delete e.isIndividual, r)
232
+ e.bulk = !1, delete e.all;
233
+ else if (e.bulk = !0, e.all === void 0) {
234
+ const n = e.top ?? e.right ?? e.bottom ?? e.left;
235
+ n !== void 0 && (e.all = n);
236
+ }
237
+ return e;
238
+ }
239
+ function ht(t) {
240
+ const e = { ...t };
241
+ if ("justifyContent" in e) {
242
+ const r = e.justifyContent;
243
+ e.horizontal = ut[r] ?? r, delete e.justifyContent;
244
+ }
245
+ if ("alignItems" in e) {
246
+ const r = e.alignItems;
247
+ e.vertical = lt[r] ?? r, delete e.alignItems;
248
+ }
249
+ return e;
250
+ }
251
+ function dt(t) {
252
+ if (typeof t != "object" || t === null)
253
+ return t;
254
+ let e = { ...t };
255
+ return e = mt(e), e = ht(e), e;
256
+ }
257
+ function gt(t) {
258
+ if (typeof t != "object" || t === null) return t;
259
+ const e = { ...t };
260
+ if (typeof e.border != "object" || e.border === null) return e;
261
+ const r = { ...e.border }, n = r.all, o = (a) => typeof a == "object" && a !== null && typeof a.type == "string";
262
+ if (o(n)) {
263
+ for (const a of ["top", "right", "bottom", "left"])
264
+ o(r[a]) || (r[a] = n);
265
+ delete r.all;
266
+ }
267
+ return e.border = r, e;
268
+ }
269
+ function W(t, e) {
270
+ if (typeof t != "object" || t === null) return t;
271
+ const r = { ...t };
272
+ "props" in r && (r.props = dt(r.props)), "style" in r && (r.style = gt(r.style));
273
+ const n = typeof r.kind == "string" ? r.kind : void 0;
274
+ if (n && e) {
275
+ const o = e[n];
276
+ o != null && o.migrateProps && (r.props = o.migrateProps(r.props));
277
+ }
278
+ return r;
279
+ }
280
+ function bt(t, e) {
281
+ if (typeof t != "object" || t === null)
282
+ throw new Error("page must be an object");
283
+ const r = { ...t };
284
+ return "grid" in r && (r.grid = V(r.grid)), Array.isArray(r.blocks) && (r.blocks = r.blocks.map((n) => W(n, e))), {
285
+ grid: r.grid,
286
+ blocks: r.blocks,
287
+ ...r.blockDefaults !== void 0 ? { blockDefaults: r.blockDefaults } : {},
288
+ ...r.metaData !== void 0 ? { metaData: r.metaData } : {}
289
+ };
290
+ }
291
+ function pt(t) {
292
+ return typeof t == "object" && t !== null && !("pages" in t) && "grid" in t && "blocks" in t;
293
+ }
294
+ function wt(t) {
295
+ return typeof t == "object" && t !== null && "pages" in t;
296
+ }
297
+ function Mt(t, e) {
298
+ if (typeof t != "object" || t === null)
299
+ throw new Error("Book must be a JSON object");
300
+ const r = { ...t };
301
+ return Array.isArray(r.pages) && (r.pages = r.pages.map((n) => bt(n, e))), {
302
+ paper: r.paper,
303
+ pages: r.pages,
304
+ ...r.metaData !== void 0 ? { metaData: r.metaData } : {}
305
+ };
306
+ }
307
+ function Et(t, e) {
308
+ if (typeof t != "object" || t === null)
309
+ throw new Error("Schema must be a JSON object");
310
+ const r = { ...t }, n = {};
311
+ if ("grid" in r && (n.grid = V(r.grid), delete r.grid), "blocks" in r) {
312
+ const s = r.blocks;
313
+ Array.isArray(s) && (n.blocks = s.map((c) => W(c, e))), delete r.blocks;
314
+ }
315
+ "metaData" in r && (n.metaData = r.metaData, delete r.metaData);
316
+ const o = {};
317
+ "paper" in r && (o.paper = r.paper, delete r.paper);
318
+ const a = {
319
+ grid: n.grid,
320
+ blocks: n.blocks ?? [],
321
+ ...n.metaData !== void 0 ? { metaData: n.metaData } : {}
322
+ };
323
+ return {
324
+ paper: o.paper,
325
+ pages: [a]
326
+ };
327
+ }
328
+ function vt(t, e) {
329
+ if (pt(t))
330
+ return Et(t, e);
331
+ if (wt(t))
332
+ return Mt(t, e);
333
+ throw new Error(
334
+ `入力データの形式を判別できません。
335
+ 形式 A(旧 FormSchema): トップレベルに 'grid' と 'blocks' が必要
336
+ 形式 B(Book): トップレベルに 'pages' が必要`
337
+ );
338
+ }
339
+ function I(t) {
340
+ if (t === null) return !0;
341
+ switch (typeof t) {
342
+ case "string":
343
+ case "number":
344
+ case "boolean":
345
+ return !0;
346
+ case "object":
347
+ return Array.isArray(t) ? t.every(I) : Object.getPrototypeOf(t) === Object.prototype ? Object.values(t).every(I) : !1;
348
+ default:
349
+ return !1;
350
+ }
351
+ }
352
+ function T(t) {
353
+ if (t === null || typeof t != "object" || Array.isArray(t) || Object.getPrototypeOf(t) !== Object.prototype)
354
+ throw new Error("values must be a plain object");
355
+ const e = t;
356
+ for (const [r, n] of Object.entries(e))
357
+ if (!I(n))
358
+ throw new Error(`values["${r}"] contains an invalid value`);
359
+ return e;
360
+ }
361
+ function Zt(t) {
362
+ let e;
363
+ try {
364
+ e = JSON.parse(t);
365
+ } catch {
366
+ throw new SyntaxError("invalid JSON for values");
367
+ }
368
+ return T(e);
369
+ }
370
+ function kt(t) {
371
+ if (typeof t != "object" || t === null) return !1;
372
+ const e = t;
373
+ return !(typeof e.colCount != "number" || e.colCount < 1 || typeof e.rowCount != "number" || e.rowCount < 1);
374
+ }
375
+ function yt(t) {
376
+ if (typeof t == "string") return !0;
377
+ if (typeof t != "object" || t === null) return !1;
378
+ const e = t;
379
+ if (typeof e.path != "string") return !1;
380
+ const r = (n) => n === null || typeof n == "string" || typeof n == "number" || typeof n == "boolean";
381
+ return "eq" in e ? r(e.eq) : "neq" in e ? r(e.neq) : !1;
382
+ }
383
+ function Dt(t) {
384
+ if (typeof t != "object" || t === null) return !1;
385
+ const e = t;
386
+ if (typeof e.id != "string" || typeof e.kind != "string" || typeof e.layout != "object" || e.layout === null) return !1;
387
+ const r = e.layout;
388
+ if (typeof r.x != "number" || typeof r.y != "number" || typeof r.w != "number" || typeof r.h != "number" || typeof e.props != "object" || e.props === null || Array.isArray(e.props))
389
+ return !1;
390
+ try {
391
+ T(e.props);
392
+ } catch {
393
+ return !1;
394
+ }
395
+ return !("initValue" in e && !I(e.initValue) || "hiddenBinding" in e && !yt(e.hiddenBinding));
396
+ }
397
+ function F(t) {
398
+ if (typeof t != "object" || t === null)
399
+ throw new Error("Page must be an object");
400
+ const e = t;
401
+ if (e.id !== void 0 && typeof e.id != "string")
402
+ throw new Error("Page.id must be a string if provided");
403
+ if (!kt(e.grid))
404
+ throw new Error("Invalid grid definition");
405
+ if (!Array.isArray(e.blocks))
406
+ throw new Error("blocks must be an array");
407
+ if (!e.blocks.every(Dt))
408
+ throw new Error("Invalid block definition in blocks array");
409
+ if (e.metaData !== void 0) {
410
+ if (typeof e.metaData != "object" || e.metaData === null)
411
+ throw new Error("metaData must be an object if provided");
412
+ try {
413
+ T(e.metaData);
414
+ } catch (r) {
415
+ throw new Error(
416
+ `Invalid metaData: ${r instanceof Error ? r.message : String(r)}`
417
+ );
418
+ }
419
+ }
420
+ if (e.blockDefaults !== void 0) {
421
+ if (typeof e.blockDefaults != "object" || e.blockDefaults === null || Array.isArray(e.blockDefaults))
422
+ throw new Error("blockDefaults must be a plain object if provided");
423
+ const r = e.blockDefaults;
424
+ for (const [n, o] of Object.entries(r))
425
+ try {
426
+ T(o);
427
+ } catch (a) {
428
+ throw new Error(
429
+ `Invalid blockDefaults["${n}"]: ${a instanceof Error ? a.message : String(a)}`
430
+ );
431
+ }
432
+ }
433
+ return t;
434
+ }
435
+ function Pt(t) {
436
+ if (typeof t != "object" || t === null)
437
+ throw new Error("Book must be an object");
438
+ const e = t;
439
+ if (!Array.isArray(e.pages) || e.pages.length === 0)
440
+ throw new Error("Book must have at least one page in pages");
441
+ if (e.pages.forEach((r, n) => {
442
+ try {
443
+ F(r);
444
+ } catch (o) {
445
+ throw new Error(
446
+ `Invalid Page at pages[${n}]: ${o instanceof Error ? o.message : String(o)}`
447
+ );
448
+ }
449
+ }), !e.paper || typeof e.paper != "object")
450
+ throw new Error("Book.paper is required and must be an object");
451
+ return t;
452
+ }
453
+ function Qt(t) {
454
+ return JSON.stringify(t);
455
+ }
456
+ function te(t) {
457
+ return JSON.stringify(t);
458
+ }
459
+ function ee(t) {
460
+ let e;
461
+ try {
462
+ e = JSON.parse(t);
463
+ } catch {
464
+ throw new SyntaxError("invalid JSON for Page");
465
+ }
466
+ return F(e);
467
+ }
468
+ function re(t) {
469
+ let e;
470
+ try {
471
+ e = JSON.parse(t);
472
+ } catch {
473
+ throw new SyntaxError("invalid JSON for Book");
474
+ }
475
+ return Pt(vt(e));
476
+ }
477
+ function ne({
478
+ checked: t,
479
+ styleConfig: e
480
+ }) {
481
+ const r = (e == null ? void 0 : e.borderColor) ?? "#000000", n = (e == null ? void 0 : e.checkColor) ?? "#000000", o = t ? (e == null ? void 0 : e.checkedBackgroundColor) ?? "#ffffff" : (e == null ? void 0 : e.backgroundColor) ?? "#ffffff", a = e != null && e.borderWidth ? l.fromDim(e.borderWidth) : 1, s = e != null && e.checkWidth ? l.fromDim(e.checkWidth) : 3.5;
482
+ return /* @__PURE__ */ q(
483
+ "svg",
484
+ {
485
+ viewBox: "0 0 20 20",
486
+ xmlns: "http://www.w3.org/2000/svg",
487
+ style: { width: "100%", height: "100%", display: "block" },
488
+ "aria-hidden": "true",
489
+ children: [
490
+ /* @__PURE__ */ N(
491
+ "rect",
492
+ {
493
+ x: "2",
494
+ y: "2",
495
+ width: "16",
496
+ height: "16",
497
+ rx: "2",
498
+ ry: "2",
499
+ fill: o,
500
+ stroke: r,
501
+ strokeWidth: a
502
+ }
503
+ ),
504
+ t && /* @__PURE__ */ N(
505
+ "path",
506
+ {
507
+ d: "M3 11l4 4L17 4",
508
+ fill: "none",
509
+ stroke: n,
510
+ strokeWidth: s,
511
+ strokeLinecap: "round",
512
+ strokeLinejoin: "round"
513
+ }
514
+ )
515
+ ]
516
+ }
517
+ );
518
+ }
519
+ var At = /* @__PURE__ */ ((t) => (t.SOLID = "solid", t.DASHED = "dashed", t.DOTTED = "dotted", t))(At || {}), _t = /* @__PURE__ */ ((t) => (t.FORM = "Form", t.EDIT = "Edit", t.VIEW = "View", t))(_t || {});
520
+ const i = {
521
+ MM: "mm",
522
+ CM: "cm",
523
+ FR: "fr",
524
+ INCH: "inch",
525
+ PT: "pt",
526
+ PX: "px",
527
+ PERCENT: "%"
528
+ }, oe = [
529
+ i.MM,
530
+ i.CM,
531
+ i.FR,
532
+ i.INCH,
533
+ i.PT,
534
+ i.PX,
535
+ i.PERCENT
536
+ ], ae = [
537
+ i.MM,
538
+ i.CM,
539
+ i.INCH,
540
+ i.PT,
541
+ i.PX
542
+ ], ie = [i.MM, i.CM, i.INCH], se = [
543
+ i.MM,
544
+ i.CM,
545
+ i.FR,
546
+ i.INCH,
547
+ i.PT,
548
+ i.PX
549
+ ], ce = [i.PX, i.PT, i.MM], ue = [i.PT, i.PX, i.MM], le = [
550
+ i.MM,
551
+ i.PT,
552
+ i.PX,
553
+ i.PERCENT
554
+ ], fe = [
555
+ i.MM,
556
+ i.CM,
557
+ i.INCH,
558
+ i.PT,
559
+ i.PX,
560
+ i.PERCENT
561
+ ];
562
+ var xt = /* @__PURE__ */ ((t) => (t.normal = "normal", t.breakWord = "break-word", t.breakAll = "break-all", t))(xt || {}), It = /* @__PURE__ */ ((t) => (t.normal = "normal", t.nowrap = "nowrap", t.pre = "pre", t.preWrap = "pre-wrap", t.preLine = "pre-line", t))(It || {}), Tt = /* @__PURE__ */ ((t) => (t.text = "text", t.number = "number", t.email = "email", t.tel = "tel", t.url = "url", t.date = "date", t.password = "password", t))(Tt || {});
563
+ const me = {
564
+ kind: "textBehavior",
565
+ defaultProps: {
566
+ lineHeight: 1.2,
567
+ multiline: !0,
568
+ wordWrap: "normal",
569
+ whiteSpace: "normal"
570
+ /* normal */
571
+ }
572
+ }, he = {
573
+ kind: "textValidation",
574
+ defaultProps: {
575
+ inputType: "text"
576
+ /* text */
577
+ }
578
+ };
579
+ function de(t) {
580
+ return `move-arrow-session-${t}`;
581
+ }
582
+ function ge(t, e) {
583
+ return `layout-${t}-${[...e].sort().join(",")}`;
584
+ }
585
+ function be(t) {
586
+ return `binding-${t}`;
587
+ }
588
+ function pe(t) {
589
+ return `initValue-${t}`;
590
+ }
591
+ function we(t) {
592
+ return `grid-size-${t}`;
593
+ }
594
+ function Me(t) {
595
+ return `resize-arrow-session-${t}`;
596
+ }
597
+ const K = { value: 1, unit: "fr" };
598
+ function Ot(t) {
599
+ return Array.from(
600
+ { length: t.colCount },
601
+ (e, r) => {
602
+ var n;
603
+ return ((n = t.cols) == null ? void 0 : n[r]) ?? K;
604
+ }
605
+ );
606
+ }
607
+ function Rt(t) {
608
+ return Array.from(
609
+ { length: t.rowCount },
610
+ (e, r) => {
611
+ var n;
612
+ return ((n = t.rows) == null ? void 0 : n[r]) ?? K;
613
+ }
614
+ );
615
+ }
616
+ function Ee(t) {
617
+ const e = {};
618
+ for (let r = 0; r < t.length; r++) {
619
+ const n = t[r];
620
+ n !== void 0 && !(n.value === 1 && n.unit === "fr") && (e[r] = n);
621
+ }
622
+ return {
623
+ colCount: t.length,
624
+ cols: Object.keys(e).length > 0 ? e : void 0
625
+ };
626
+ }
627
+ function ve(t) {
628
+ const e = {};
629
+ for (let r = 0; r < t.length; r++) {
630
+ const n = t[r];
631
+ n !== void 0 && !(n.value === 1 && n.unit === "fr") && (e[r] = n);
632
+ }
633
+ return {
634
+ rowCount: t.length,
635
+ rows: Object.keys(e).length > 0 ? e : void 0
636
+ };
637
+ }
638
+ function St(t) {
639
+ const e = A(() => Ot(t), [t]), r = A(() => Rt(t), [t]);
640
+ return { expandedCols: e, expandedRows: r };
641
+ }
642
+ function Nt(t) {
643
+ if (t.length === 0) return [];
644
+ const e = [];
645
+ let r = 0;
646
+ for (const n of t) {
647
+ const o = n + r, a = Math.round(o);
648
+ e.push(a), r = o - a;
649
+ }
650
+ return e;
651
+ }
652
+ const jt = 8, Bt = 32, Ct = 64, Lt = 512, B = (t, e, r) => Math.min(Math.max(t, e), r);
653
+ function C(t) {
654
+ const e = t.length - 1, r = e >= 1 ? t[e] ?? 0 : 0, n = t.length >= 1 ? r / e : 0, o = B(Math.ceil(Math.log2(e + 1)), jt, Bt), a = B(n * 2, Ct, Lt);
655
+ return { step: o, windowPx: a };
656
+ }
657
+ function R(t, e) {
658
+ const r = e.length - 1;
659
+ if (r <= 0 || e[0] === void 0 || t < e[0] || e[r] === void 0) return -1;
660
+ if (t >= e[r]) return r - 1;
661
+ let n = 1, o = r;
662
+ for (; n <= o; ) {
663
+ const a = n + o >>> 1, s = e[a];
664
+ if (s === void 0) {
665
+ o = a - 1;
666
+ continue;
667
+ }
668
+ s <= t ? n = a + 1 : o = a - 1;
669
+ }
670
+ return n - 1;
671
+ }
672
+ function L(t, e, r) {
673
+ const n = t.length - 1;
674
+ let o = 0;
675
+ return (a) => {
676
+ if (n <= 0 || t[0] === void 0 || a < t[0] || t[n] === void 0) return -1;
677
+ if (a >= t[n]) return n - 1;
678
+ const s = t[o], c = t[o + 1];
679
+ if (s === void 0 || c === void 0) return -1;
680
+ if (s <= a && a < c) return o;
681
+ const g = s - r, v = c + r;
682
+ if (a < g || a >= v)
683
+ return o = R(a, t), o;
684
+ let _ = 0;
685
+ const x = t[o + 1];
686
+ if (x !== void 0 && a >= x)
687
+ for (; o + 1 < n; ) {
688
+ const k = t[o + 1];
689
+ if (k === void 0 || a < k) break;
690
+ if (o++, ++_ > e)
691
+ return o = R(a, t), o;
692
+ }
693
+ else
694
+ for (; o > 0; ) {
695
+ const k = t[o];
696
+ if (k === void 0 || a >= k) break;
697
+ if (o--, ++_ > e)
698
+ return o = R(a, t), o;
699
+ }
700
+ return o;
701
+ };
702
+ }
703
+ function $(t, e) {
704
+ if (t.length === 0) return [];
705
+ let r = 0, n = 0;
706
+ const o = t.map((c) => {
707
+ if (c.unit === "fr")
708
+ return r += c.value, null;
709
+ const g = h.fromDim(c);
710
+ return n += g, g;
711
+ });
712
+ if (r === 0)
713
+ return o;
714
+ const s = Math.max(0, e - n) / r;
715
+ return o.map((c, g) => {
716
+ if (c != null) return c;
717
+ const v = t[g];
718
+ if (!v) throw new Error(`dims[${g}] is undefined`);
719
+ return v.value * s;
720
+ });
721
+ }
722
+ function U(t, e = b) {
723
+ const r = t.map((n) => l.fromMm(n, e));
724
+ return Nt(r);
725
+ }
726
+ function ke(t, e, r = b) {
727
+ const { expandedCols: n, expandedRows: o } = St(e), a = A(() => {
728
+ var y;
729
+ const d = t.orientation ? t.size.height : t.size.width, M = t.orientation ? t.size.width : t.size.height, p = h.fromDim(d), E = h.fromDim(M), f = t.margin.bulk && ((y = t.margin.all) != null && y.unit) ? h.fromDim(t.margin.all) : void 0, u = f ?? h.fromDim(t.margin.top), m = f ?? h.fromDim(t.margin.bottom), w = f ?? h.fromDim(t.margin.left), D = f ?? h.fromDim(t.margin.right);
730
+ return {
731
+ canvasWidthMm: p,
732
+ canvasHeightMm: E,
733
+ marginTopMm: u,
734
+ marginBottomMm: m,
735
+ marginLeftMm: w,
736
+ marginRightMm: D,
737
+ contentWidthMm: Math.max(0, p - w - D),
738
+ contentHeightMm: Math.max(
739
+ 0,
740
+ E - u - m
741
+ )
742
+ };
743
+ }, [t]), s = A(() => {
744
+ const {
745
+ canvasWidthMm: d,
746
+ canvasHeightMm: M,
747
+ marginTopMm: p,
748
+ marginBottomMm: E,
749
+ marginLeftMm: f,
750
+ marginRightMm: u,
751
+ contentWidthMm: m,
752
+ contentHeightMm: w
753
+ } = a;
754
+ return {
755
+ canvas: {
756
+ width: l.fromMm(d, r),
757
+ height: l.fromMm(M, r)
758
+ },
759
+ margin: {
760
+ top: l.fromMm(p, r),
761
+ bottom: l.fromMm(E, r),
762
+ left: l.fromMm(f, r),
763
+ right: l.fromMm(u, r)
764
+ },
765
+ content: {
766
+ width: l.fromMm(m, r),
767
+ height: l.fromMm(w, r)
768
+ }
769
+ };
770
+ }, [a, r]), { gridPosPx: c, colIndexer: g, rowIndexer: v } = A(() => {
771
+ const { contentWidthMm: d, contentHeightMm: M } = a, p = U($(n, d), r), E = U($(o, M), r), f = [0];
772
+ for (const P of p)
773
+ f.push((f[f.length - 1] ?? 0) + P);
774
+ const u = [0];
775
+ for (const P of E)
776
+ u.push((u[u.length - 1] ?? 0) + P);
777
+ const { step: m, windowPx: w } = C(f), { step: D, windowPx: y } = C(u);
778
+ return {
779
+ gridPosPx: { cols: f, rows: u },
780
+ colIndexer: L(f, m, w),
781
+ rowIndexer: L(u, D, y)
782
+ };
783
+ }, [a, n, o, r]), _ = O(
784
+ (d) => g(d - s.margin.left),
785
+ [g, s]
786
+ ), x = O(
787
+ (d) => v(d - s.margin.top),
788
+ [v, s]
789
+ ), k = O(
790
+ (d) => {
791
+ const { x: M, y: p, w: E, h: f } = d.layout, u = c.cols, m = c.rows;
792
+ if (!u.length || !m.length)
793
+ return { left: 0, top: 0, width: 0, height: 0 };
794
+ const w = Math.min(Math.max(0, M), u.length - 1), D = Math.min(Math.max(0, M + E), u.length - 1), y = Math.min(Math.max(0, p), m.length - 1), P = Math.min(Math.max(0, p + f), m.length - 1), X = (u[w] ?? 0) + s.margin.left, z = (m[y] ?? 0) + s.margin.top, J = (u[D] ?? 0) - (u[w] ?? 0), Y = (m[P] ?? 0) - (m[y] ?? 0);
795
+ return { left: X, top: z, width: J, height: Y };
796
+ },
797
+ [c, s]
798
+ );
799
+ return {
800
+ paperPx: s,
801
+ gridPosPx: c,
802
+ getColIndex: _,
803
+ getRowIndex: x,
804
+ getBlockRectPx: k
805
+ };
806
+ }
807
+ const ye = '[data-sidebar="true"]', De = { "data-sidebar": "true" };
808
+ export {
809
+ de as $,
810
+ ae as A,
811
+ ce as B,
812
+ Vt as C,
813
+ b as D,
814
+ Yt as E,
815
+ ue as F,
816
+ se as G,
817
+ Z as H,
818
+ Tt as I,
819
+ me as J,
820
+ he as K,
821
+ At as L,
822
+ h as M,
823
+ _t as N,
824
+ l as O,
825
+ tt as P,
826
+ F as Q,
827
+ T as R,
828
+ De as S,
829
+ ne as T,
830
+ i as U,
831
+ Q as V,
832
+ It as W,
833
+ be as X,
834
+ Jt as Y,
835
+ zt as Z,
836
+ Me as _,
837
+ Kt as a,
838
+ pe as a0,
839
+ St as a1,
840
+ Ft as a2,
841
+ G as a3,
842
+ Wt as a4,
843
+ Ee as a5,
844
+ ve as a6,
845
+ ye as a7,
846
+ Ot as a8,
847
+ Rt as a9,
848
+ ge as aa,
849
+ we as ab,
850
+ Xt as b,
851
+ rt as c,
852
+ et as d,
853
+ re as e,
854
+ ee as f,
855
+ Zt as g,
856
+ pt as h,
857
+ wt as i,
858
+ Mt as j,
859
+ Et as k,
860
+ bt as l,
861
+ vt as m,
862
+ Qt as n,
863
+ oe as o,
864
+ Pt as p,
865
+ le as q,
866
+ ie as r,
867
+ te as s,
868
+ fe as t,
869
+ ke as u,
870
+ xt as v,
871
+ Gt as w,
872
+ Ht as x,
873
+ qt as y,
874
+ I as z
875
+ };