@thibezer/ui-components-kit 2.24.1 → 2.25.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 (154) hide show
  1. package/CHANGELOG.md +83 -1
  2. package/dist/botao.cjs +12 -1
  3. package/dist/botao.js +162 -3
  4. package/dist/camadas.cjs +311 -1
  5. package/dist/camadas.js +3244 -148
  6. package/dist/campo-texto.cjs +16 -1
  7. package/dist/campo-texto.js +308 -7
  8. package/dist/canvas.cjs +22 -22
  9. package/dist/canvas.js +230 -233
  10. package/dist/card.cjs +20 -1
  11. package/dist/card.js +145 -2
  12. package/dist/components/ui-canvas-prancha/index.d.ts +1 -1
  13. package/dist/components/ui-canvas-prancha/prancha-teclado.d.ts +26 -0
  14. package/dist/components/ui-canvas-prancha/ui-canvas-prancha-base.d.ts +9 -0
  15. package/dist/components/ui-canvas-prancha/ui-canvas-prancha.d.ts +2 -2
  16. package/dist/components/ui-editor-prancha/editor-barra.d.ts +19 -0
  17. package/dist/components/ui-editor-prancha/editor-modos.d.ts +35 -0
  18. package/dist/components/ui-editor-prancha/editor-tipos.d.ts +4 -0
  19. package/dist/components/ui-editor-prancha/index.d.ts +1 -0
  20. package/dist/components/ui-editor-prancha/ui-editor-prancha.d.ts +63 -7
  21. package/dist/core/alvo-digitavel.d.ts +3 -0
  22. package/dist/core.cjs +1 -1
  23. package/dist/core.js +43 -54
  24. package/dist/{cores-utils-BrdynxRd.js → cores-utils-DMyqWvZh.js} +2 -2
  25. package/dist/cores.cjs +32 -1
  26. package/dist/cores.js +300 -13
  27. package/dist/custom-elements.json +11945 -11071
  28. package/dist/data.cjs +28 -1
  29. package/dist/data.js +286 -99
  30. package/dist/{feature_caixa-2Sxv3tGa.js → feature_caixa-BVc5LenS.js} +42 -42
  31. package/dist/{feature_desenho-BVHivWIB.js → feature_desenho-CC8Mp5Gp.js} +2 -2
  32. package/dist/feedback.cjs +52 -1
  33. package/dist/feedback.js +655 -25
  34. package/dist/forms.cjs +66 -1
  35. package/dist/forms.js +1216 -39
  36. package/dist/{geometria-px-DUs5FgLE.js → geometria-px-DHMPUsxC.js} +47 -47
  37. package/dist/index.cjs +67 -1
  38. package/dist/index.js +1476 -274
  39. package/dist/kit-base-BmkPi5Rz.cjs +2 -0
  40. package/dist/kit-base-CBXA66aM.js +1084 -0
  41. package/dist/mapa.cjs +5 -5
  42. package/dist/mapa.js +16 -17
  43. package/dist/modal.cjs +18 -1
  44. package/dist/modal.js +235 -29
  45. package/dist/motor.js +49 -49
  46. package/dist/prancha-nucleo.cjs +3 -1
  47. package/dist/prancha-nucleo.js +3120 -277
  48. package/dist/prancha.cjs +38 -1
  49. package/dist/prancha.js +3470 -228
  50. package/dist/register.cjs +1 -1
  51. package/dist/register.js +3 -20
  52. package/dist/seletor-mapa-base.cjs +13 -13
  53. package/dist/seletor-mapa-base.js +3 -5
  54. package/dist/tabela.cjs +142 -1
  55. package/dist/tabela.js +3773 -92
  56. package/dist/tipos-elementos.d.ts +7 -3
  57. package/dist/tipos-vue.d.ts +6 -3
  58. package/dist/tools.cjs +16 -1
  59. package/dist/tools.js +1564 -26
  60. package/dist/{ui-seletor-cor-Cd8jkzXG.js → ui-seletor-cor-CPjA9vhZ.js} +8 -9
  61. package/dist/ui-seletor-cor-D_ifitEN.cjs +83 -0
  62. package/dist/utils-ClVgqVyJ.cjs +1 -0
  63. package/dist/utils-DrHoxxmf.js +83 -0
  64. package/package.json +43 -2
  65. package/dist/acessibilidade-CSzX-DkG.cjs +0 -1
  66. package/dist/acessibilidade-CUlSXc2X.js +0 -38
  67. package/dist/altura-controle-ukMRPckR.cjs +0 -1
  68. package/dist/altura-controle-vxQiXG4q.js +0 -62
  69. package/dist/alvo-digitavel-CzCvNVQ3.js +0 -23
  70. package/dist/alvo-digitavel-DbH0hYFf.cjs +0 -1
  71. package/dist/degrade-CIxvOTUv.cjs +0 -1
  72. package/dist/degrade-gDa5sW__.js +0 -119
  73. package/dist/feature_caixa-CnYPKVFS.cjs +0 -1
  74. package/dist/feature_caixa-DCs9ZeSk.js +0 -1038
  75. package/dist/feature_historico-BAIYk1Me.cjs +0 -3
  76. package/dist/feature_historico-C4h9y5fu.js +0 -3039
  77. package/dist/form-atalhos-7JTYvumA.cjs +0 -1
  78. package/dist/form-atalhos-DDTlpgaB.js +0 -203
  79. package/dist/form-erros-CwPz7Jr4.cjs +0 -1
  80. package/dist/form-erros-DT5HklfD.js +0 -184
  81. package/dist/form-submissao-C-SPRKgT.js +0 -61
  82. package/dist/form-submissao-DxKO5MHI.cjs +0 -1
  83. package/dist/form-validacao-BlQFxUVj.js +0 -104
  84. package/dist/form-validacao-DIeyQVH5.cjs +0 -1
  85. package/dist/geometria-px-DKrWq_XY.js +0 -639
  86. package/dist/leaflet-CEPcxGWV.cjs +0 -1
  87. package/dist/leaflet-DOq10gfg.js +0 -84
  88. package/dist/leaflet-loader-94z5VsdY.cjs +0 -2
  89. package/dist/leaflet-loader-Cjcdgj5R.js +0 -21
  90. package/dist/listener-bag-D5omxZ9h.cjs +0 -1
  91. package/dist/listener-bag-DQgv7OON.js +0 -34
  92. package/dist/motor-By2te6PZ.js +0 -1400
  93. package/dist/motor-CkMxd378.cjs +0 -1
  94. package/dist/opcoes-CupvWVIm.js +0 -24
  95. package/dist/opcoes-vdAUY5OI.cjs +0 -1
  96. package/dist/parts-CaoQiCfI.js +0 -7
  97. package/dist/parts-vQa2873h.cjs +0 -1
  98. package/dist/prancha-paleta-BZ-9QDgh.js +0 -5276
  99. package/dist/prancha-paleta-Bb24vP71.cjs +0 -17
  100. package/dist/ssr-safe-5cWfJP-s.js +0 -10
  101. package/dist/ssr-safe-CiHD1adl.cjs +0 -1
  102. package/dist/svg-seguro-ChVJ2L2z.js +0 -74
  103. package/dist/svg-seguro-J2RM1Ssf.cjs +0 -1
  104. package/dist/ui-badge-DE58YSBY.cjs +0 -28
  105. package/dist/ui-badge-KgmI3jOD.js +0 -201
  106. package/dist/ui-botao-Dz8YvmiA.cjs +0 -12
  107. package/dist/ui-botao-zLkcMMyP.js +0 -168
  108. package/dist/ui-bus-CUd99VJi.js +0 -177
  109. package/dist/ui-bus-XqBLlTYQ.cjs +0 -1
  110. package/dist/ui-camadas-DoHPnbQm.js +0 -3133
  111. package/dist/ui-camadas-Vx7wYD4D.cjs +0 -311
  112. package/dist/ui-campo-texto-Dliyt9qr.cjs +0 -16
  113. package/dist/ui-campo-texto-btevggO3.js +0 -379
  114. package/dist/ui-card-7IEYbCN0.js +0 -150
  115. package/dist/ui-card-Bx8EyzYY.cjs +0 -20
  116. package/dist/ui-card-C-EJoKnm.js +0 -150
  117. package/dist/ui-card-DFnRp9bl.js +0 -146
  118. package/dist/ui-card-DrWVJQKw.cjs +0 -20
  119. package/dist/ui-card-DsIjHMmG.cjs +0 -20
  120. package/dist/ui-controle-cores-B1w_Yl69.cjs +0 -32
  121. package/dist/ui-controle-cores-BRjMvmMn.js +0 -291
  122. package/dist/ui-controle-cores-BcH9k2Fa.js +0 -292
  123. package/dist/ui-controle-cores-CvSTP6gJ.cjs +0 -32
  124. package/dist/ui-editor-prancha-CIngI6yI.js +0 -2886
  125. package/dist/ui-editor-prancha-DorSe6sC.cjs +0 -31
  126. package/dist/ui-linha-2kY7TNUJ.cjs +0 -38
  127. package/dist/ui-linha-B4mBRm1x.cjs +0 -61
  128. package/dist/ui-linha-DTEIIww4.js +0 -1167
  129. package/dist/ui-linha-KFF86FW5.js +0 -752
  130. package/dist/ui-modal-BrXzVZ65.js +0 -216
  131. package/dist/ui-modal-lARKzEVZ.cjs +0 -18
  132. package/dist/ui-paleta-ferramentas-Bu6JaT0s.js +0 -1245
  133. package/dist/ui-paleta-ferramentas-D3Jhwt26.cjs +0 -21
  134. package/dist/ui-paleta-ferramentas-DebHYiwd.js +0 -1615
  135. package/dist/ui-paleta-ferramentas-Dgejtluh.js +0 -1423
  136. package/dist/ui-paleta-ferramentas-hzyo8wBt.cjs +0 -22
  137. package/dist/ui-paleta-ferramentas-jWuICjW8.cjs +0 -22
  138. package/dist/ui-seletor-cor-0RLjcME6.cjs +0 -83
  139. package/dist/ui-seletor-cor-CMuuW-Ym.cjs +0 -83
  140. package/dist/ui-seletor-cor-DFIQ1sin.js +0 -405
  141. package/dist/ui-skeleton-BLEV6h3k.js +0 -653
  142. package/dist/ui-skeleton-B_XTaGrX.cjs +0 -52
  143. package/dist/ui-switch-BXIDwC-Y.cjs +0 -66
  144. package/dist/ui-switch-Ctxk-jKS.js +0 -1212
  145. package/dist/ui-tabela-CXxqbwXv.cjs +0 -7
  146. package/dist/ui-tabela-Cd0vOwnT.js +0 -1459
  147. package/dist/ui-tabela-propriedades-C5cIF5ES.js +0 -3779
  148. package/dist/ui-tabela-propriedades-CJyo568n.js +0 -3517
  149. package/dist/ui-tabela-propriedades-D96Djx-q.cjs +0 -136
  150. package/dist/ui-tabela-propriedades-Wa34hfIr.cjs +0 -142
  151. package/dist/ui-tabela-propriedades-ahQhQauu.js +0 -2329
  152. package/dist/ui-tabela-propriedades-w9JWhjHy.cjs +0 -142
  153. package/dist/zero-js-triggers-CJT988bR.js +0 -83
  154. package/dist/zero-js-triggers-CgM9IIQB.cjs +0 -1
@@ -1,3039 +0,0 @@
1
- var to = Object.defineProperty;
2
- var no = (a, t, n) => t in a ? to(a, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[t] = n;
3
- var I = (a, t, n) => no(a, typeof t != "symbol" ? t + "" : t, n);
4
- import { b as oo, a as eo, p as ro, f as io, c as so, d as co, T as uo, e as Qa, h as ca, i as lo, m as fo, r as ho, j as mo, n as $t, k as po, l as An, o as xa, q as go, s as yo, t as bo, u as Mo } from "./feature_caixa-2Sxv3tGa.js";
5
- import { n as In, h as Xt, a as va, o as xo, q as Pn, r as vo, s as Ao, u as z, v as Io, w as Bt, I as Po, x as lt, y as $o, z as So, j as jo, k as Eo, A as zo, B as Lo } from "./geometria-px-DUs5FgLE.js";
6
- import { e as St } from "./cores-utils-BrdynxRd.js";
7
- function qa(a) {
8
- const t = a.length;
9
- if (t < 3) return 0;
10
- let n = 0;
11
- for (let o = 0; o < t; o++) {
12
- const e = a[o], r = a[(o + 1) % t];
13
- n += e[0] * r[1] - r[0] * e[1];
14
- }
15
- return n / 2;
16
- }
17
- function No(a) {
18
- const [t, ...n] = a;
19
- if (!t) return 0;
20
- const o = Math.abs(qa(t)) - n.reduce((e, r) => e + Math.abs(qa(r)), 0);
21
- return Number.isFinite(o) ? Math.max(0, o) : 0;
22
- }
23
- function Co(a, t = !1) {
24
- let n = 0;
25
- for (let o = 1; o < a.length; o++) n += Math.hypot(a[o][0] - a[o - 1][0], a[o][1] - a[o - 1][1]);
26
- return t && a.length > 2 && (n += Math.hypot(a[0][0] - a[a.length - 1][0], a[0][1] - a[a.length - 1][1])), n;
27
- }
28
- function qo(a) {
29
- const t = a[0], n = a[1];
30
- return {
31
- paraXY: (o) => [o[0] - t, o[1] - n],
32
- deXY: (o) => [t + o[0], n + o[1]]
33
- };
34
- }
35
- const A = Object.freeze({
36
- tipo: "plano",
37
- unidade: "mm",
38
- distancia: (a, t) => Math.hypot(t[0] - a[0], t[1] - a[1]),
39
- comprimento: Co,
40
- area: No,
41
- planoLocal: qo,
42
- deslocar: (a, t, n) => [a[0] + t, a[1] + n],
43
- pontoDaBorda: (a, t) => [a[0] + t, a[1]],
44
- pontoDeMedidaDoRaio: (a, t) => [a[0] + t, a[1]],
45
- extremosDoCirculo(a, t) {
46
- const n = Math.abs(t);
47
- return [[a[0] - n, a[1] - n], [a[0] + n, a[1] + n]];
48
- },
49
- fatorEixo: () => 1
50
- }), jt = Object.freeze({
51
- mm: 1,
52
- cm: 10,
53
- pt: 25.4 / 72,
54
- pol: 25.4,
55
- px: 25.4 / 96
56
- });
57
- function $n(a) {
58
- return typeof a == "string" && Object.prototype.hasOwnProperty.call(jt, a);
59
- }
60
- function Tr(a, t) {
61
- return !Number.isFinite(a) || !$n(t) ? NaN : a * jt[t];
62
- }
63
- function kr(a, t) {
64
- return !Number.isFinite(a) || !$n(t) ? NaN : a / jt[t];
65
- }
66
- const Sn = 1e-12, ha = (a) => typeof a == "number" && Number.isFinite(a), ta = Object.freeze({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
67
- function Rr(a, t, n, o, e, r) {
68
- return { a, b: t, c: n, d: o, e, f: r };
69
- }
70
- function Da(a) {
71
- if (!a || typeof a != "object") return !1;
72
- const t = a;
73
- return ha(t.a) && ha(t.b) && ha(t.c) && ha(t.d) && ha(t.e) && ha(t.f);
74
- }
75
- function Aa(a) {
76
- return Da(a) ? { a: a.a, b: a.b, c: a.c, d: a.d, e: a.e, f: a.f } : ta;
77
- }
78
- const Va = (a) => a.a * a.d - a.b * a.c, Do = (a) => !(Math.abs(Va(a)) > Sn), Fr = (a, t = 0) => Math.abs(a.a - 1) <= t && Math.abs(a.b) <= t && Math.abs(a.c) <= t && Math.abs(a.d - 1) <= t && Math.abs(a.e) <= t && Math.abs(a.f) <= t;
79
- function _r(a, t, n = 1e-9) {
80
- return Math.abs(a.a - t.a) <= n && Math.abs(a.b - t.b) <= n && Math.abs(a.c - t.c) <= n && Math.abs(a.d - t.d) <= n && Math.abs(a.e - t.e) <= n && Math.abs(a.f - t.f) <= n;
81
- }
82
- function ua(a, t) {
83
- return {
84
- a: a.a * t.a + a.c * t.b,
85
- b: a.b * t.a + a.d * t.b,
86
- c: a.a * t.c + a.c * t.d,
87
- d: a.b * t.c + a.d * t.d,
88
- e: a.a * t.e + a.c * t.f + a.e,
89
- f: a.b * t.e + a.d * t.f + a.f
90
- };
91
- }
92
- function Et(...a) {
93
- let t = ta;
94
- for (const n of a) t = ua(n, t);
95
- return t;
96
- }
97
- function la(a) {
98
- if (!Da(a)) return null;
99
- const t = Va(a);
100
- if (!(Math.abs(t) > Sn)) return null;
101
- const n = {
102
- a: a.d / t,
103
- b: -a.b / t,
104
- c: -a.c / t,
105
- d: a.a / t,
106
- e: (a.c * a.f - a.d * a.e) / t,
107
- f: (a.b * a.e - a.a * a.f) / t
108
- };
109
- return Da(n) ? n : null;
110
- }
111
- function P(a, t) {
112
- return [a.a * t[0] + a.c * t[1] + a.e, a.b * t[0] + a.d * t[1] + a.f];
113
- }
114
- function Gr(a, t) {
115
- return [a.a * t[0] + a.c * t[1], a.b * t[0] + a.d * t[1]];
116
- }
117
- function Xr(a, t) {
118
- return t.map((n) => P(a, n));
119
- }
120
- const q = (a, t) => ({ a: 1, b: 0, c: 0, d: 1, e: a, f: t });
121
- function zt(a, t) {
122
- return t ? Et(q(-t[0], -t[1]), a, q(t[0], t[1])) : a;
123
- }
124
- const Lt = (a, t = a, n) => zt({ a, b: 0, c: 0, d: t, e: 0, f: 0 }, n);
125
- function jn(a, t) {
126
- const n = Math.cos(a), o = Math.sin(a);
127
- return zt({ a: n, b: o, c: -o, d: n, e: 0, f: 0 }, t);
128
- }
129
- const Ut = (a, t = 0, n) => zt({ a: 1, b: t, c: a, d: 1, e: 0, f: 0 }, n);
130
- function Oo(a, t) {
131
- return Lt(a === "horizontal" ? -1 : 1, a === "vertical" ? -1 : 1, t);
132
- }
133
- function Br(a) {
134
- const t = Aa(a), n = Math.hypot(t.a, t.b);
135
- if (n === 0)
136
- return { translacaoX: t.e, translacaoY: t.f, rotacao: 0, escalaX: 0, escalaY: Math.hypot(t.c, t.d), cisalhamento: 0 };
137
- const o = Math.atan2(t.b, t.a), e = Va(t) / n, r = Math.cos(o), i = Math.sin(o), s = e === 0 ? 0 : (t.c * r + t.d * i) / e;
138
- return { translacaoX: t.e, translacaoY: t.f, rotacao: o, escalaX: n, escalaY: e, cisalhamento: s };
139
- }
140
- function Ur(a) {
141
- const t = Math.cos(a.rotacao), n = Math.sin(a.rotacao), o = t * a.escalaX, e = n * a.escalaX, r = (t * a.cisalhamento - n) * a.escalaY, i = (n * a.cisalhamento + t) * a.escalaY;
142
- return Aa({ a: o, b: e, c: r, d: i, e: a.translacaoX, f: a.translacaoY });
143
- }
144
- const ga = 0.5522847498307936, wo = 0.8, To = 1.2, ko = 0.55, S = (a) => typeof a == "number" && Number.isFinite(a), Ro = "sans-serif", Fo = /^[\p{L}\p{N}\s,'"_-]{1,120}$/u;
145
- function En(a) {
146
- return typeof a == "string" && Fo.test(a.trim()) ? a.trim() : Ro;
147
- }
148
- let Ba = null, ft = 0;
149
- function Hr(a) {
150
- Ba = typeof a == "function" ? a : null, ft++;
151
- }
152
- const Vr = () => Ba !== null;
153
- function _o(a, t, n) {
154
- const o = Math.max([...a].length, 1) * n * ko;
155
- if (!Ba) return o;
156
- try {
157
- const e = Ba(a, t, n);
158
- return S(e) && e >= 0 ? Math.max(e, n * 0.1) : o;
159
- } catch {
160
- return o;
161
- }
162
- }
163
- class Ya {
164
- constructor() {
165
- I(this, "mapa", /* @__PURE__ */ new WeakMap());
166
- }
167
- tem(t) {
168
- var n;
169
- return ((n = this.mapa.get(t)) == null ? void 0 : n.v) === ft;
170
- }
171
- obter(t) {
172
- return this.mapa.get(t).valor;
173
- }
174
- gravar(t, n) {
175
- this.mapa.set(t, { v: ft, valor: n });
176
- }
177
- }
178
- const Ht = (a, t) => a[0] === t[0] && a[1] === t[1];
179
- function zn(a, t, n) {
180
- const o = (n ?? [0, 0, 0, 0]).map((r) => S(r) && r > 0 ? r : 0), e = Math.min(
181
- 1,
182
- o[0] + o[1] > 0 ? a / (o[0] + o[1]) : 1,
183
- o[3] + o[2] > 0 ? a / (o[3] + o[2]) : 1,
184
- o[0] + o[3] > 0 ? t / (o[0] + o[3]) : 1,
185
- o[1] + o[2] > 0 ? t / (o[1] + o[2]) : 1
186
- );
187
- return e < 1 ? o.map((r) => r * e) : o;
188
- }
189
- function Go(a, t) {
190
- const n = [];
191
- for (const o of a) {
192
- const e = n[n.length - 1];
193
- if (e && Ht(e.ponto, o.ponto)) {
194
- const r = { ponto: e.ponto };
195
- e.entrada && (r.entrada = e.entrada), o.saida && (r.saida = o.saida), n[n.length - 1] = r;
196
- } else
197
- n.push({ ...o });
198
- }
199
- if (n.length > 1 && Ht(n[0].ponto, n[n.length - 1].ponto)) {
200
- const o = n.pop(), e = n[0], r = { ponto: e.ponto };
201
- o.entrada && (r.entrada = o.entrada), e.saida && (r.saida = e.saida), n[0] = r;
202
- }
203
- return n;
204
- }
205
- function Xo(a, t, n) {
206
- if (!(S(a) && S(t) && a > 0 && t > 0)) return null;
207
- const o = -a / 2, e = a / 2, r = -t / 2, i = t / 2, [s, c, u, f] = zn(a, t, n);
208
- if (s === 0 && c === 0 && u === 0 && f === 0)
209
- return { tipo: "Polygon", aneis: [[[o, r], [e, r], [e, i], [o, i]]] };
210
- const d = s * ga, l = c * ga, h = u * ga, m = f * ga, g = [];
211
- s > 0 ? g.push({ ponto: [o + s, r], entrada: [o + s - d, r] }) : g.push({ ponto: [o, r] }), c > 0 ? g.push({ ponto: [e - c, r], saida: [e - c + l, r] }, { ponto: [e, r + c], entrada: [e, r + c - l] }) : g.push({ ponto: [e, r] }), u > 0 ? g.push({ ponto: [e, i - u], saida: [e, i - u + h] }, { ponto: [e - u, i], entrada: [e - u + h, i] }) : g.push({ ponto: [e, i] }), f > 0 ? g.push({ ponto: [o + f, i], saida: [o + f - m, i] }, { ponto: [o, i - f], entrada: [o, i - f + m] }) : g.push({ ponto: [o, i] }), s > 0 && g.push({ ponto: [o, r + s], saida: [o, r + s - d] });
212
- const y = Go(g);
213
- return y.length < 3 ? null : { tipo: "Polygon", aneis: [va(y, !0)], curva: y };
214
- }
215
- const Bo = (a, t, n) => [a * Math.cos(n), t * Math.sin(n)], Uo = (a, t, n) => [-a * Math.sin(n), t * Math.cos(n)];
216
- function Ho(a, t, n, o, e) {
217
- const r = o / e, i = 4 / 3 * Math.tan(r / 4), s = [];
218
- for (let c = 0; c <= e; c++) {
219
- const u = n + c * r, f = Bo(a, t, u), d = Uo(a, t, u), l = { ponto: f };
220
- c > 0 && (l.entrada = [f[0] - i * d[0], f[1] - i * d[1]]), c < e && (l.saida = [f[0] + i * d[0], f[1] + i * d[1]]), s.push(l);
221
- }
222
- return s;
223
- }
224
- function Vo(a) {
225
- if (!S(a.inicio) || !S(a.fim)) return null;
226
- const t = 2 * Math.PI;
227
- let n = (a.fim - a.inicio) % t;
228
- return n <= 0 && (n += t), n;
229
- }
230
- function Yo(a, t, n) {
231
- if (!(S(a) && S(t) && a > 0 && t > 0)) return null;
232
- const o = n ? Vo(n) : 2 * Math.PI;
233
- if (o === null) return null;
234
- if (!n || o >= 2 * Math.PI - 1e-12) {
235
- const c = a * ga, u = t * ga, f = [
236
- { ponto: [a, 0], entrada: [a, -u], saida: [a, u] },
237
- { ponto: [0, t], entrada: [c, t], saida: [-c, t] },
238
- { ponto: [-a, 0], entrada: [-a, u], saida: [-a, -u] },
239
- { ponto: [0, -t], entrada: [-c, -t], saida: [c, -t] }
240
- ];
241
- return { tipo: "Polygon", aneis: [va(f, !0)], curva: f };
242
- }
243
- const e = n.fechamento ?? "aberto", r = Math.max(e === "corda" ? 2 : 1, Math.ceil(o / (Math.PI / 2) - 1e-9)), i = Ho(a, t, n.inicio, o, r);
244
- if (e === "aberto") return { tipo: "LineString", coordenadas: va(i, !1), curva: i };
245
- const s = e === "fatia" ? [...i, { ponto: [0, 0] }] : i;
246
- return { tipo: "Polygon", aneis: [va(s, !0)], curva: s };
247
- }
248
- function Wo(a, t) {
249
- if (!(S(a) && a > 0 && S(t))) return null;
250
- const n = eo([0, 0], [0, -a], Math.round(t), A);
251
- return n ? { tipo: "Polygon", aneis: [n] } : null;
252
- }
253
- function Zo(a, t, n) {
254
- if (!(S(a) && S(t) && a > 0 && t > 0 && S(n))) return null;
255
- const o = oo([0, 0], [0, -a], Math.round(n), A, Math.min(1, t / a));
256
- return o ? { tipo: "Polygon", aneis: [o] } : null;
257
- }
258
- function Jo(a) {
259
- if (!(S(a.tamanho) && a.tamanho > 0)) return null;
260
- const t = String(a.texto ?? "").split(`
261
- `), n = En(a.fonte), o = S(a.largura) && a.largura > 0 ? a.largura : t.reduce((i, s) => Math.max(i, _o(s, n, a.tamanho)), 0), e = t.length * a.tamanho * To;
262
- return { x: a.alinhamento === "centro" ? -o / 2 : a.alinhamento === "direita" ? -o : 0, y: -a.tamanho * wo, largura: o, altura: e };
263
- }
264
- function wa(a) {
265
- var t, n, o, e;
266
- switch (a.tipo) {
267
- case "retangulo":
268
- return Xo(a.largura, a.altura, a.raios);
269
- case "elipse":
270
- return Yo(a.rx, a.ry, a.arco);
271
- case "poligono-regular":
272
- return Wo(a.raio, a.lados);
273
- case "estrela":
274
- return Zo(a.raioExterno, a.raioInterno, a.pontas);
275
- case "linha":
276
- return S((t = a.de) == null ? void 0 : t[0]) && S((n = a.de) == null ? void 0 : n[1]) && S((o = a.ate) == null ? void 0 : o[0]) && S((e = a.ate) == null ? void 0 : e[1]) ? { tipo: "LineString", coordenadas: [[a.de[0], a.de[1]], [a.ate[0], a.ate[1]]] } : null;
277
- case "caminho":
278
- return a.geometria && (a.geometria.tipo === "LineString" || a.geometria.tipo === "Polygon") ? a.geometria : null;
279
- case "texto": {
280
- const r = Jo(a);
281
- if (!r) return null;
282
- const i = r.x + r.largura, s = r.y + r.altura;
283
- return { tipo: "Polygon", aneis: [[[r.x, r.y], [i, r.y], [i, s], [r.x, s]]] };
284
- }
285
- default:
286
- return null;
287
- }
288
- }
289
- function E(a) {
290
- return a.transformacao && Da(a.transformacao) ? a.transformacao : ta;
291
- }
292
- function Qo(a, t) {
293
- const n = (e) => P(t, e);
294
- if (a.tipo === "Polygon") {
295
- const e = { tipo: "Polygon", aneis: a.aneis.map((r) => r.map(n)) };
296
- return a.curva ? { ...e, curva: Xt(a.curva, n) } : e;
297
- }
298
- const o = a.partes && a.partes.length > 1 ? { tipo: "LineString", coordenadas: a.coordenadas.map(n), partes: a.partes.map((e) => e.map(n)) } : { tipo: "LineString", coordenadas: a.coordenadas.map(n) };
299
- return a.curva ? { ...o, curva: Xt(a.curva, n) } : o;
300
- }
301
- const Ka = new Ya(), at = new Ya(), tt = new Ya(), nt = new Ya();
302
- function Nt(a) {
303
- if (!a || typeof a != "object") return null;
304
- if (tt.tem(a)) return tt.obter(a);
305
- let t = null;
306
- try {
307
- t = wa(a);
308
- } catch {
309
- t = null;
310
- }
311
- return tt.gravar(a, t), t;
312
- }
313
- function w(a) {
314
- if (!a || typeof a != "object") return null;
315
- if (Ka.tem(a)) return Ka.obter(a);
316
- let t = null;
317
- try {
318
- const n = Nt(a.geometria);
319
- t = n ? Qo(n, E(a)) : null;
320
- } catch {
321
- t = null;
322
- }
323
- return Ka.gravar(a, t), t;
324
- }
325
- const Ct = ([[a, t], [n, o]]) => [a, t, n, o].every(S) ? { x: a, y: t, largura: n - a, altura: o - t } : null;
326
- function qt(a) {
327
- const t = a == null ? void 0 : a.geometria;
328
- if (!t || typeof t != "object") return null;
329
- if (nt.tem(t)) return nt.obter(t);
330
- const n = Nt(t), o = n ? Ct(In(n, A)) : null;
331
- return nt.gravar(t, o), o;
332
- }
333
- function Ko(a) {
334
- const t = qt(a);
335
- if (!t) return null;
336
- const n = E(a), o = [[t.x, t.y], [t.x + t.largura, t.y], [t.x + t.largura, t.y + t.altura], [t.x, t.y + t.altura]].map((c) => P(n, c));
337
- let e = 1 / 0, r = 1 / 0, i = -1 / 0, s = -1 / 0;
338
- for (const [c, u] of o)
339
- c < e && (e = c), c > i && (i = c), u < r && (r = u), u > s && (s = u);
340
- return Ct([[e, r], [i, s]]);
341
- }
342
- function Ia(a) {
343
- if (at.tem(a)) return at.obter(a);
344
- const t = w(a), n = t ? Ct(In(t, A)) : null;
345
- return a && typeof a == "object" && at.gravar(a, n), n;
346
- }
347
- const Yr = (a) => !!a && a.tipo === "Polygon", Na = "#000000", Ln = 0.25, ae = 4, Vt = 25.4 / 96, C = (a) => typeof a == "number" && Number.isFinite(a), ya = (a, t) => C(a) ? Math.min(1, Math.max(0, a)) : t;
348
- function te(a, t, n = 1, o = "butt") {
349
- const e = C(t) && t > 0 ? t / Vt : 1;
350
- return ro(Io(a, e, n, o)).map((r) => Math.round(r * Vt * 1e4) / 1e4);
351
- }
352
- const dt = {
353
- normal: "source-over",
354
- multiplicar: "multiply",
355
- tela: "screen",
356
- sobrepor: "overlay",
357
- escurecer: "darken",
358
- clarear: "lighten",
359
- "subexposicao-cor": "color-dodge",
360
- "superexposicao-cor": "color-burn",
361
- "luz-dura": "hard-light",
362
- "luz-suave": "soft-light",
363
- diferenca: "difference",
364
- exclusao: "exclusion",
365
- matiz: "hue",
366
- saturacao: "saturation",
367
- cor: "color",
368
- luminosidade: "luminosity"
369
- }, Nn = Object.keys(dt), ot = { deslocamento: [1.5, 1.5], desfoque: 1, opacidade: 0.5 };
370
- function Dt(a) {
371
- if (!a || typeof a != "object") return null;
372
- const t = Array.isArray(a.deslocamento) && C(a.deslocamento[0]) && C(a.deslocamento[1]) ? a.deslocamento : ot.deslocamento, n = (e) => Math.max(-1e3, Math.min(1e3, e)), o = {
373
- dx: n(t[0]),
374
- dy: n(t[1]),
375
- desfoque: C(a.desfoque) && a.desfoque >= 0 ? Math.min(100, a.desfoque) : ot.desfoque,
376
- cor: z(a.cor, Na),
377
- opacidade: ya(a.opacidade, ot.opacidade)
378
- };
379
- return o.opacidade > 0 ? o : null;
380
- }
381
- function ne(a) {
382
- return a.filter((t) => t && C(t.posicao)).map((t) => ({ posicao: Math.min(1, Math.max(0, t.posicao)), cor: z(t.cor, Na), opacidade: ya(t.opacidade, 1) })).sort((t, n) => t.posicao - n.posicao);
383
- }
384
- function oe(a, t) {
385
- if (!a || !Array.isArray(a.paradas)) return;
386
- const n = ne(a.paradas);
387
- if (n.length === 0) return;
388
- const o = n.reduce((r, i) => Math.abs(i.posicao - 0.5) < Math.abs(r.posicao - 0.5) ? i : r, n[0]);
389
- return {
390
- def: a.tipo === "radial" ? { ...a, paradas: n } : { tipo: "linear", de: a.de, ate: a.ate, paradas: n },
391
- corDegradacao: t ? z(t, o.cor) : o.cor,
392
- opacidadeDegradacao: o.opacidade ?? 1
393
- };
394
- }
395
- const ee = (a) => {
396
- const t = a.transformacao;
397
- return t && C(t.a) && C(t.b) ? Math.atan2(t.b, t.a) : 0;
398
- }, Yt = /* @__PURE__ */ new WeakMap();
399
- function Ta(a) {
400
- if (!a || typeof a != "object") return ht(a);
401
- let t = Yt.get(a);
402
- return t || (t = ht(a), Yt.set(a, t)), t;
403
- }
404
- function ht(a) {
405
- var d, l, h;
406
- const t = (a == null ? void 0 : a.aparencia) ?? {}, n = ((d = a == null ? void 0 : a.geometria) == null ? void 0 : d.tipo) === "texto", o = !n && ((l = Nt(a == null ? void 0 : a.geometria)) == null ? void 0 : l.tipo) === "Polygon";
407
- let e = null;
408
- const r = t.traco;
409
- if (r !== null && !(n && r === void 0)) {
410
- const m = r ?? {}, g = C(m.espessura) && m.espessura > 0 ? m.espessura : m.espessura === 0 ? 0 : Ln;
411
- if (g > 0) {
412
- const y = xo(m.terminacao) ?? "butt", p = Pn(m.tipoLinha);
413
- e = {
414
- cor: z(m.cor, Na),
415
- largura: g,
416
- opacidade: ya(m.opacidade, 1),
417
- tracejado: p && p !== "continua" ? te(p, g, Ao(m.escalaTipoLinha), y) : [],
418
- terminacao: y,
419
- juncao: vo(m.juncao) ?? "miter",
420
- limitePonta: C(m.limitePonta) && m.limitePonta >= 1 ? m.limitePonta : ae,
421
- alinhamento: o && (m.alinhamento === "dentro" || m.alinhamento === "fora") ? m.alinhamento : "centro"
422
- }, !o && m.pontaInicio && (e.pontaInicio = m.pontaInicio), !o && m.pontaFim && (e.pontaFim = m.pontaFim);
423
- }
424
- }
425
- let i = null;
426
- const s = t.preenchimento === void 0 && n ? {} : t.preenchimento;
427
- if (s && (o || n)) {
428
- const m = (s.cor ?? "").trim().toLowerCase(), g = m === "none" || m === "transparent", y = n ? void 0 : oe(s.gradiente, s.cor);
429
- if (!g || y) {
430
- const p = a.geometria.tipo === "caminho" && ((h = a.geometria.geometria) == null ? void 0 : h.tipo) === "Polygon" && a.geometria.geometria.aneis.length > 1;
431
- i = {
432
- cor: z(s.cor, (y == null ? void 0 : y.corDegradacao) ?? Na),
433
- opacidade: ya(s.opacidade, 1),
434
- regra: s.regra ?? (p ? "evenodd" : "nonzero")
435
- }, y && (i.gradiente = y);
436
- }
437
- }
438
- let c = null;
439
- const u = t.hachura;
440
- u && o && !n && (c = {
441
- angulo: (C(u.angulo) ? u.angulo : 45) * Math.PI / 180 + ee(a),
442
- espacamento: C(u.espacamento) && u.espacamento > 0 ? Math.max(0.1, u.espacamento) : 2,
443
- cor: z(u.cor, (e == null ? void 0 : e.cor) ?? Na),
444
- largura: C(u.espessura) && u.espessura > 0 ? u.espessura : 0.18,
445
- opacidade: ya(u.opacidade, 1),
446
- cruzada: u.cruzada === !0
447
- });
448
- const f = typeof t.mesclagem == "string" && Object.prototype.hasOwnProperty.call(dt, t.mesclagem) ? t.mesclagem : "normal";
449
- return {
450
- traco: e,
451
- preenchimento: i,
452
- hachura: c,
453
- opacidade: ya(t.opacidade, 1),
454
- mesclagem: f === "normal" ? null : dt[f],
455
- sombra: Dt(t.sombra)
456
- };
457
- }
458
- function re(a, t) {
459
- const n = C(t) ? Math.min(1, Math.max(0, t)) : 1;
460
- if (n >= 1) return a;
461
- const o = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(a.trim());
462
- if (!o) return a;
463
- let e = o[1];
464
- e.length === 3 && (e = e.split("").map((u) => u + u).join(""));
465
- const r = parseInt(e.slice(0, 2), 16), i = parseInt(e.slice(2, 4), 16), s = parseInt(e.slice(4, 6), 16), c = e.length === 8 ? parseInt(e.slice(6, 8), 16) / 255 : 1;
466
- return `rgba(${r},${i},${s},${Math.round(c * n * 1e3) / 1e3})`;
467
- }
468
- const N = (a) => typeof a == "number" && Number.isFinite(a), O = (a) => N(a) && a > 0, U = (a) => Array.isArray(a) && a.length >= 2 && N(a[0]) && N(a[1]), K = (a) => [a[0], a[1]], ie = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]), se = ["triangulo", "triangulo-aberto", "aberta", "circulo", "quadrado", "losango", "barra"], Wt = 360, ce = 1e5, ba = (a) => N(a) ? Math.min(1, Math.max(0, a)) : void 0, Zt = (a, t, n) => N(a) ? Math.min(n, Math.max(t, Math.round(a))) : null;
469
- function et(a, t) {
470
- if (!Array.isArray(a) || a.length === 0) return null;
471
- const n = [];
472
- for (const o of a) {
473
- if (!Array.isArray(o) || o.length < t || o.length > ce || !o.every(U)) return null;
474
- n.push(o.map(K));
475
- }
476
- return n;
477
- }
478
- function ue(a) {
479
- var n;
480
- if (!a || typeof a != "object") return null;
481
- const t = a;
482
- if (t.tipo === "Polygon") {
483
- const o = et(t.aneis, 3);
484
- if (!o) return null;
485
- const e = o.length === 1 ? Bt(t.curva, 3) : null;
486
- return e ? { tipo: "Polygon", aneis: o, curva: e } : { tipo: "Polygon", aneis: o };
487
- }
488
- if (t.tipo === "LineString") {
489
- const o = (n = et([t.coordenadas], 2)) == null ? void 0 : n[0];
490
- if (!o) return null;
491
- const e = Array.isArray(t.partes) && t.partes.length > 1 ? et(t.partes, 2) : null, r = e ? null : Bt(t.curva, 2);
492
- return e ? { tipo: "LineString", coordenadas: e[0], partes: e } : r ? { tipo: "LineString", coordenadas: o, curva: r } : { tipo: "LineString", coordenadas: o };
493
- }
494
- return null;
495
- }
496
- function le(a) {
497
- if (!a || typeof a != "object") return null;
498
- const t = a;
499
- switch (t.tipo) {
500
- case "retangulo": {
501
- if (!O(t.largura) || !O(t.altura)) return null;
502
- const n = Array.isArray(t.raios) && t.raios.length === 4 ? t.raios.map((o) => N(o) && o > 0 ? o : 0) : void 0;
503
- return n && n.some((o) => o > 0) ? { tipo: "retangulo", largura: t.largura, altura: t.altura, raios: n } : { tipo: "retangulo", largura: t.largura, altura: t.altura };
504
- }
505
- case "elipse": {
506
- if (!O(t.rx) || !O(t.ry)) return null;
507
- const n = t.arco;
508
- if (n && typeof n == "object") {
509
- if (!N(n.inicio) || !N(n.fim) || n.inicio === n.fim) return null;
510
- const o = n.fechamento === "corda" || n.fechamento === "fatia" ? n.fechamento : "aberto";
511
- return { tipo: "elipse", rx: t.rx, ry: t.ry, arco: { inicio: n.inicio, fim: n.fim, fechamento: o } };
512
- }
513
- return { tipo: "elipse", rx: t.rx, ry: t.ry };
514
- }
515
- case "poligono-regular": {
516
- const n = Zt(t.lados, 3, Wt);
517
- return O(t.raio) && n !== null ? { tipo: "poligono-regular", raio: t.raio, lados: n } : null;
518
- }
519
- case "estrela": {
520
- const n = Zt(t.pontas, 3, Wt);
521
- return !O(t.raioExterno) || !O(t.raioInterno) || n === null ? null : { tipo: "estrela", raioExterno: t.raioExterno, raioInterno: Math.min(t.raioInterno, t.raioExterno), pontas: n };
522
- }
523
- case "linha":
524
- return U(t.de) && U(t.ate) ? { tipo: "linha", de: K(t.de), ate: K(t.ate) } : null;
525
- case "caminho": {
526
- const n = ue(t.geometria);
527
- return n ? { tipo: "caminho", geometria: n } : null;
528
- }
529
- case "texto": {
530
- if (!O(t.tamanho)) return null;
531
- const o = { tipo: "texto", texto: typeof t.texto == "string" ? t.texto : t.texto === void 0 || t.texto === null ? "" : String(t.texto), tamanho: t.tamanho };
532
- return typeof t.fonte == "string" && t.fonte.trim() && (o.fonte = t.fonte), O(t.largura) && (o.largura = t.largura), (t.alinhamento === "centro" || t.alinhamento === "direita" || t.alinhamento === "esquerda") && (o.alinhamento = t.alinhamento), o;
533
- }
534
- default:
535
- return null;
536
- }
537
- }
538
- function Jt(a) {
539
- if (!a || typeof a != "object") return;
540
- const t = a;
541
- if (se.includes(t.estilo))
542
- return O(t.escala) ? { estilo: t.estilo, escala: Math.min(t.escala, 100) } : { estilo: t.estilo };
543
- }
544
- const Ca = (a) => typeof a == "string" && a.trim() && a.length <= 64 ? a.trim() : void 0, fe = 64;
545
- function de(a) {
546
- if (!Array.isArray(a)) return null;
547
- const t = [];
548
- for (const n of a.slice(0, fe)) {
549
- if (!n || typeof n != "object") continue;
550
- const o = n, e = Ca(o.cor);
551
- if (!e || !N(o.posicao)) continue;
552
- const r = { posicao: Math.min(1, Math.max(0, o.posicao)), cor: e }, i = ba(o.opacidade);
553
- i !== void 0 && (r.opacidade = i), t.push(r);
554
- }
555
- return t.sort((n, o) => n.posicao - o.posicao), t.length >= 1 ? t : null;
556
- }
557
- function he(a) {
558
- if (!a || typeof a != "object") return;
559
- const t = a, n = de(t.paradas);
560
- if (n) {
561
- if (t.tipo === "linear" && U(t.de) && U(t.ate)) return { tipo: "linear", de: K(t.de), ate: K(t.ate), paradas: n };
562
- if (t.tipo === "radial" && U(t.centro) && O(t.raio)) {
563
- const o = { tipo: "radial", centro: K(t.centro), raio: Math.min(t.raio, 100), paradas: n };
564
- return U(t.foco) && (o.foco = K(t.foco)), o;
565
- }
566
- }
567
- }
568
- function me(a) {
569
- if (!a || typeof a != "object") return;
570
- const t = a;
571
- return Xa({
572
- angulo: N(t.angulo) ? t.angulo : void 0,
573
- espacamento: O(t.espacamento) ? Math.max(0.1, Math.min(t.espacamento, 1e3)) : void 0,
574
- cor: Ca(t.cor),
575
- espessura: N(t.espessura) && t.espessura >= 0 ? Math.min(t.espessura, 100) : void 0,
576
- opacidade: ba(t.opacidade),
577
- cruzada: t.cruzada === !0 ? !0 : void 0
578
- });
579
- }
580
- function Xa(a) {
581
- for (const t of Object.keys(a)) a[t] === void 0 && delete a[t];
582
- return a;
583
- }
584
- function pe(a) {
585
- if (!a || typeof a != "object") return;
586
- const t = a, n = {};
587
- if (t.traco === null) n.traco = null;
588
- else if (t.traco && typeof t.traco == "object") {
589
- const e = t.traco, r = Xa({
590
- cor: Ca(e.cor),
591
- espessura: N(e.espessura) && e.espessura >= 0 ? Math.min(e.espessura, 1e3) : void 0,
592
- opacidade: ba(e.opacidade),
593
- tipoLinha: Pn(e.tipoLinha),
594
- escalaTipoLinha: O(e.escalaTipoLinha) ? e.escalaTipoLinha : void 0,
595
- terminacao: e.terminacao === "arredondada" || e.terminacao === "reta" || e.terminacao === "quadrada" ? e.terminacao : void 0,
596
- juncao: e.juncao === "arredondada" || e.juncao === "chanfrada" || e.juncao === "angular" ? e.juncao : void 0,
597
- limitePonta: N(e.limitePonta) && e.limitePonta >= 1 ? Math.min(e.limitePonta, 100) : void 0,
598
- alinhamento: e.alinhamento === "dentro" || e.alinhamento === "fora" || e.alinhamento === "centro" ? e.alinhamento : void 0,
599
- pontaInicio: Jt(e.pontaInicio),
600
- pontaFim: Jt(e.pontaFim)
601
- });
602
- n.traco = r;
603
- }
604
- if (t.preenchimento === null) n.preenchimento = null;
605
- else if (t.preenchimento && typeof t.preenchimento == "object") {
606
- const e = t.preenchimento, r = Xa({
607
- cor: Ca(e.cor),
608
- opacidade: ba(e.opacidade),
609
- regra: e.regra === "evenodd" || e.regra === "nonzero" ? e.regra : void 0,
610
- gradiente: he(e.gradiente)
611
- });
612
- n.preenchimento = r;
613
- }
614
- if (t.hachura === null) n.hachura = null;
615
- else {
616
- const e = me(t.hachura);
617
- e && (n.hachura = e);
618
- }
619
- const o = ba(t.opacidade);
620
- if (o !== void 0 && (n.opacidade = o), typeof t.mesclagem == "string" && Nn.includes(t.mesclagem) && (n.mesclagem = t.mesclagem), t.sombra === null) n.sombra = null;
621
- else if (t.sombra && typeof t.sombra == "object") {
622
- const e = t.sombra;
623
- n.sombra = Xa({
624
- deslocamento: U(e.deslocamento) ? [Math.max(-1e3, Math.min(1e3, e.deslocamento[0])), Math.max(-1e3, Math.min(1e3, e.deslocamento[1]))] : void 0,
625
- desfoque: N(e.desfoque) && e.desfoque >= 0 ? Math.min(e.desfoque, 100) : void 0,
626
- cor: Ca(e.cor),
627
- opacidade: ba(e.opacidade)
628
- });
629
- }
630
- return n;
631
- }
632
- function ge(a) {
633
- if (!a || typeof a != "object" || Array.isArray(a)) return;
634
- const t = {};
635
- for (const n of Object.keys(a)) ie.has(n) || (t[n] = a[n]);
636
- return t;
637
- }
638
- function Cn(a) {
639
- if (!a || typeof a != "object" || Array.isArray(a)) return "nao-objeto";
640
- const t = a, n = typeof t.id == "string" ? t.id.trim() : typeof t.id == "number" && Number.isFinite(t.id) ? String(t.id) : "";
641
- if (!n) return "id-invalido";
642
- const o = le(t.geometria);
643
- if (!o) return "geometria-invalida";
644
- const e = { id: n, geometria: o };
645
- typeof t.nome == "string" && (e.nome = t.nome), t.transformacao !== void 0 && t.transformacao !== null && (e.transformacao = Da(t.transformacao) ? Aa(t.transformacao) : Aa(null)), U(t.pivo) && (e.pivo = K(t.pivo));
646
- const r = pe(t.aparencia);
647
- r && (e.aparencia = r), t.bloqueado === !0 && (e.bloqueado = !0), t.oculto === !0 && (e.oculto = !0), typeof t.camadaId == "string" && t.camadaId && (e.camadaId = t.camadaId), typeof t.grupoId == "string" && t.grupoId && (e.grupoId = t.grupoId), N(t.ordem) && (e.ordem = t.ordem), t.mascara === !0 && (e.mascara = !0), typeof t.recorteId == "string" && t.recorteId && (e.recorteId = t.recorteId);
648
- const i = ge(t.propriedades);
649
- return i && (e.propriedades = i), e;
650
- }
651
- function ye(a) {
652
- const t = Cn(a);
653
- return typeof t == "string" ? null : t;
654
- }
655
- function Wr(a) {
656
- const t = { elementos: [], recusados: [] };
657
- if (!Array.isArray(a)) return t;
658
- const n = /* @__PURE__ */ new Set();
659
- return a.forEach((o, e) => {
660
- const r = Cn(o);
661
- if (typeof r == "string") {
662
- const i = o && typeof o == "object" && typeof o.id == "string" ? o.id : void 0;
663
- t.recusados.push({ indice: e, id: i, motivo: r });
664
- return;
665
- }
666
- if (n.has(r.id)) {
667
- t.recusados.push({ indice: e, id: r.id, motivo: "id-duplicado" });
668
- return;
669
- }
670
- n.add(r.id), t.elementos.push(r);
671
- }), t;
672
- }
673
- const j = (a) => typeof a == "number" && Number.isFinite(a);
674
- function fa(a, t) {
675
- const n = { ...t, id: a.id };
676
- return a.nome !== void 0 && (n.nome = a.nome), a.aparencia !== void 0 && (n.aparencia = a.aparencia), a.camadaId !== void 0 && (n.camadaId = a.camadaId), a.grupoId !== void 0 && (n.grupoId = a.grupoId), a.propriedades !== void 0 && (n.propriedades = a.propriedades), n;
677
- }
678
- function Ot(a) {
679
- if (!a || ![a.x, a.y, a.largura, a.altura].every(j)) return null;
680
- const t = a.largura < 0 ? a.x + a.largura : a.x, n = a.altura < 0 ? a.y + a.altura : a.y;
681
- return { x: t, y: n, largura: Math.abs(a.largura), altura: Math.abs(a.altura) };
682
- }
683
- const Zr = (a, t) => ({
684
- x: Math.min(a[0], t[0]),
685
- y: Math.min(a[1], t[1]),
686
- largura: Math.abs(t[0] - a[0]),
687
- altura: Math.abs(t[1] - a[1])
688
- }), qn = (a) => [a.x + a.largura / 2, a.y + a.altura / 2];
689
- function _a(a, t, n) {
690
- const o = Ot(t);
691
- if (!o || o.largura <= 0 || o.altura <= 0) return null;
692
- const e = typeof n == "number" ? [n, n, n, n] : n, r = e && e.some((c) => j(c) && c > 0) ? { tipo: "retangulo", largura: o.largura, altura: o.altura, raios: e.map((c) => j(c) && c > 0 ? c : 0) } : { tipo: "retangulo", largura: o.largura, altura: o.altura }, [i, s] = qn(o);
693
- return fa(a, { geometria: r, transformacao: q(i, s) });
694
- }
695
- function Qt(a, t) {
696
- const n = Ot(t);
697
- if (!n || n.largura <= 0 || n.altura <= 0) return null;
698
- const [o, e] = qn(n);
699
- return fa(a, { geometria: { tipo: "elipse", rx: n.largura / 2, ry: n.altura / 2 }, transformacao: q(o, e) });
700
- }
701
- function Jr(a, t, n, o = 6) {
702
- return !j(t == null ? void 0 : t[0]) || !j(t == null ? void 0 : t[1]) || !j(n) || n <= 0 || !j(o) || o < 3 ? null : fa(a, { geometria: { tipo: "poligono-regular", raio: n, lados: Math.min(360, Math.round(o)) }, transformacao: q(t[0], t[1]) });
703
- }
704
- function Qr(a, t, n, o, e = 5) {
705
- return !j(t == null ? void 0 : t[0]) || !j(t == null ? void 0 : t[1]) || !j(n) || !j(o) || n <= 0 || o <= 0 || !j(e) || e < 3 ? null : fa(a, {
706
- geometria: { tipo: "estrela", raioExterno: n, raioInterno: Math.min(o, n), pontas: Math.min(360, Math.round(e)) },
707
- transformacao: q(t[0], t[1])
708
- });
709
- }
710
- function Sa(a, t, n) {
711
- if (![t == null ? void 0 : t[0], t == null ? void 0 : t[1], n == null ? void 0 : n[0], n == null ? void 0 : n[1]].every(j)) return null;
712
- const o = (t[0] + n[0]) / 2, e = (t[1] + n[1]) / 2;
713
- return fa(a, {
714
- geometria: { tipo: "linha", de: [t[0] - o, t[1] - e], ate: [n[0] - o, n[1] - e] },
715
- transformacao: q(o, e)
716
- });
717
- }
718
- function Kr(a, t) {
719
- return !t || t.tipo !== "LineString" && t.tipo !== "Polygon" ? null : fa(a, { geometria: { tipo: "caminho", geometria: t } });
720
- }
721
- function ai(a, t, n, o) {
722
- return !j(t == null ? void 0 : t[0]) || !j(t == null ? void 0 : t[1]) || !j(o) || o <= 0 ? null : fa(a, { geometria: { tipo: "texto", texto: typeof n == "string" ? n : String(n ?? ""), tamanho: o }, transformacao: q(t[0], t[1]) });
723
- }
724
- const be = ["no", "n", "ne", "e", "se", "s", "so", "o"], rt = 1e-4, L = (a) => typeof a == "number" && Number.isFinite(a);
725
- function wt(a) {
726
- const t = qt(a);
727
- return t ? { quadro: E(a), min: [t.x, t.y], max: [t.x + t.largura, t.y + t.altura] } : null;
728
- }
729
- function Me(a) {
730
- if (a.length === 1) return wt(a[0]);
731
- let t = 1 / 0, n = 1 / 0, o = -1 / 0, e = -1 / 0;
732
- for (const r of a) {
733
- const i = Ia(r);
734
- i && (t = Math.min(t, i.x), n = Math.min(n, i.y), o = Math.max(o, i.x + i.largura), e = Math.max(e, i.y + i.altura));
735
- }
736
- return t <= o && n <= e ? { quadro: ta, min: [t, n], max: [o, e] } : null;
737
- }
738
- function F(a, t) {
739
- const n = (a.min[0] + a.max[0]) / 2, o = (a.min[1] + a.max[1]) / 2;
740
- switch (t) {
741
- case "no":
742
- return [a.min[0], a.min[1]];
743
- case "n":
744
- return [n, a.min[1]];
745
- case "ne":
746
- return [a.max[0], a.min[1]];
747
- case "e":
748
- return [a.max[0], o];
749
- case "se":
750
- return [a.max[0], a.max[1]];
751
- case "s":
752
- return [n, a.max[1]];
753
- case "so":
754
- return [a.min[0], a.max[1]];
755
- case "o":
756
- return [a.min[0], o];
757
- default:
758
- return [n, o];
759
- }
760
- }
761
- const mt = { no: "se", n: "s", ne: "so", e: "o", se: "no", s: "n", so: "ne", o: "e" };
762
- function ti(a, t = 6) {
763
- const n = (f) => P(a.quadro, f), o = Object.fromEntries(be.map((f) => [f, n(F(a, f))])), e = n(F(a, "centro")), r = o.n;
764
- let i = r[0] - e[0], s = r[1] - e[1];
765
- const c = Math.hypot(i, s);
766
- c > 1e-9 ? (i /= c, s /= c) : (i = 0, s = -1);
767
- const u = L(t) ? t : 6;
768
- return { cantos: [o.no, o.ne, o.se, o.so], alcas: o, centro: e, rotacao: [r[0] + i * u, r[1] + s * u] };
769
- }
770
- function pt(a, t) {
771
- const n = la(a.quadro);
772
- return n ? Et(n, t, a.quadro) : null;
773
- }
774
- const Kt = (a) => Math.abs(a) < rt ? a < 0 ? -rt : rt : a;
775
- function ni(a, t, n, o = {}) {
776
- if (!a || !mt[t] || !L(n == null ? void 0 : n[0]) || !L(n == null ? void 0 : n[1])) return null;
777
- const e = la(a.quadro);
778
- if (!e) return null;
779
- const r = P(e, n), i = F(a, t), s = F(a, o.doCentro ? "centro" : mt[t]), c = t !== "n" && t !== "s", u = t !== "e" && t !== "o", f = i[0] - s[0], d = i[1] - s[1];
780
- let l = c && Math.abs(f) > 1e-12 ? (r[0] - s[0]) / f : 1, h = u && Math.abs(d) > 1e-12 ? (r[1] - s[1]) / d : 1;
781
- if (o.proporcional) {
782
- const m = u ? c && Math.abs(l) >= Math.abs(h) ? l : h : l;
783
- l = m, h = m;
784
- }
785
- return !L(l) || !L(h) ? null : pt(a, Lt(Kt(l), Kt(h), s));
786
- }
787
- function oi(a, t, n, o) {
788
- if (![a == null ? void 0 : a[0], a == null ? void 0 : a[1], t == null ? void 0 : t[0], t == null ? void 0 : t[1], n == null ? void 0 : n[0], n == null ? void 0 : n[1]].every(L)) return { matriz: ta, angulo: 0 };
789
- const r = t[0] - a[0], i = t[1] - a[1], s = n[0] - a[0], c = n[1] - a[1];
790
- if (Math.hypot(r, i) < 1e-9 || Math.hypot(s, c) < 1e-9) return { matriz: ta, angulo: 0 };
791
- let u = Math.atan2(r * c - i * s, r * s + i * c);
792
- return L(o) && o > 0 && (u = Math.round(u / o) * o), { matriz: jn(u, a), angulo: u };
793
- }
794
- function ei(a, t, n) {
795
- if (!a || !["n", "s", "e", "o"].includes(t) || !L(n == null ? void 0 : n[0]) || !L(n == null ? void 0 : n[1])) return null;
796
- const o = la(a.quadro);
797
- if (!o) return null;
798
- const e = P(o, n), r = F(a, t), i = F(a, mt[t]);
799
- if (t === "n" || t === "s") {
800
- const c = r[1] - i[1];
801
- return Math.abs(c) < 1e-12 ? null : pt(a, Ut((e[0] - r[0]) / c, 0, i));
802
- }
803
- const s = r[0] - i[0];
804
- return Math.abs(s) < 1e-12 ? null : pt(a, Ut(0, (e[1] - r[1]) / s, i));
805
- }
806
- function Wa(a, t) {
807
- const n = E(a), o = ua(t, n);
808
- return [o.a, o.b, o.c, o.d, o.e, o.f].every(L) ? { ...a, transformacao: o } : a;
809
- }
810
- const ri = (a, t, n) => L(t) && L(n) ? Wa(a, q(t, n)) : a;
811
- function Dn(a) {
812
- const t = Me(a);
813
- return t ? P(t.quadro, F(t, "centro")) : null;
814
- }
815
- function ii(a) {
816
- if (a.pivo && L(a.pivo[0]) && L(a.pivo[1])) return P(E(a), a.pivo);
817
- const t = wt(a);
818
- return t ? P(t.quadro, F(t, "centro")) : null;
819
- }
820
- function On(a, t) {
821
- return a.map((n) => n.bloqueado ? n : Wa(n, t));
822
- }
823
- function si(a, t, n) {
824
- const o = n ?? Dn(a);
825
- return o ? On(a, Oo(t, o)) : [...a];
826
- }
827
- function ci(a, t, n) {
828
- const o = n ?? Dn(a);
829
- return o && L(t) ? On(a, jn(t, o)) : [...a];
830
- }
831
- const wn = (a) => typeof a == "number" && Number.isFinite(a);
832
- function Pa(a) {
833
- const t = Array.isArray(a) ? a : [], n = /* @__PURE__ */ new Map();
834
- t.forEach((e, r) => {
835
- e && typeof e.id == "string" && !n.has(e.id) && n.set(e.id, { i: r, c: e });
836
- });
837
- const o = (e) => e && typeof e.camadaId == "string" ? n.get(e.camadaId) : void 0;
838
- return {
839
- indice: (e) => {
840
- var r;
841
- return ((r = o(e)) == null ? void 0 : r.i) ?? t.length;
842
- },
843
- visivel: (e) => {
844
- var r;
845
- return !!e && !e.oculto && ((r = o(e)) == null ? void 0 : r.c.visivel) !== !1;
846
- },
847
- travado: (e) => {
848
- var r;
849
- return !!e && (!!e.bloqueado || ((r = o(e)) == null ? void 0 : r.c.bloqueada) === !0);
850
- },
851
- opacidade: (e) => {
852
- var i;
853
- const r = (i = o(e)) == null ? void 0 : i.c.opacidade;
854
- return wn(r) ? Math.min(1, Math.max(0, r)) : 1;
855
- }
856
- };
857
- }
858
- function ui(a) {
859
- if (!Array.isArray(a)) return [];
860
- const t = /* @__PURE__ */ new Set(), n = [];
861
- for (const o of a) {
862
- if (!o || typeof o != "object") continue;
863
- const e = o, r = typeof e.id == "string" ? e.id.trim() : "";
864
- if (!r || t.has(r)) continue;
865
- t.add(r);
866
- const i = { id: r };
867
- typeof e.nome == "string" && (i.nome = e.nome), e.visivel === !1 && (i.visivel = !1), e.bloqueada === !0 && (i.bloqueada = !0), wn(e.opacidade) && (i.opacidade = Math.min(1, Math.max(0, e.opacidade))), n.push(i);
868
- }
869
- return n;
870
- }
871
- const li = Ln, V = (a) => typeof a == "number" && Number.isFinite(a);
872
- function xe(a) {
873
- const t = Ta(a).preenchimento;
874
- return !!t && (t.opacidade > 0 || !!t.gradiente);
875
- }
876
- function ve(a) {
877
- const t = Ta(a).traco;
878
- return t ? t.largura / 2 : 0;
879
- }
880
- function ka(a, t) {
881
- const n = t && !Array.isArray(t) && typeof t.indice == "function" ? t : Pa(t);
882
- return a.map((o, e) => ({ el: o, c: o ? n.indice(o) : 0, chave: V(o == null ? void 0 : o.ordem) ? o.ordem : e, i: e })).sort((o, e) => o.c - e.c || o.chave - e.chave || o.i - e.i).map((o) => o.el);
883
- }
884
- function Ae(a, t) {
885
- let n = 1 / 0;
886
- const o = t.tipo === "Polygon" ? t.aneis.map((e) => ({ pts: e, fechado: !0 })) : (t.partes && t.partes.length > 1 ? t.partes : [t.coordenadas]).map((e) => ({ pts: e, fechado: !1 }));
887
- for (const { pts: e, fechado: r } of o) {
888
- const i = e.length;
889
- i === 1 && (n = Math.min(n, Math.hypot(a[0] - e[0][0], a[1] - e[0][1])));
890
- for (let s = 1; s < i; s++) n = Math.min(n, lt(a[0], a[1], e[s - 1][0], e[s - 1][1], e[s][0], e[s][1]));
891
- r && i > 2 && (n = Math.min(n, lt(a[0], a[1], e[i - 1][0], e[i - 1][1], e[0][0], e[0][1])));
892
- }
893
- return n;
894
- }
895
- const Tt = (a, t, n) => !!a && !a.mascara && n.visivel(a) && (t || !n.travado(a));
896
- function Ie(a, t, n = 1) {
897
- const o = Ia(a), e = w(a);
898
- if (!o || !e) return null;
899
- const r = (V(n) && n >= 0 ? n : 1) + ve(a);
900
- if (t[0] < o.x - r || t[0] > o.x + o.largura + r || t[1] < o.y - r || t[1] > o.y + o.altura + r) return null;
901
- if (e.tipo === "Polygon" && (xe(a) || a.geometria.tipo === "texto") && so(t, e.aneis)) return 0;
902
- const s = Ae(t, e);
903
- return s <= r ? s : null;
904
- }
905
- function Pe(a, t, n = {}) {
906
- if (!V(a == null ? void 0 : a[0]) || !V(a == null ? void 0 : a[1])) return [];
907
- const o = n.incluirBloqueados === !0, e = Pa(n.camadas), r = [], i = ka(t, e);
908
- for (let s = i.length - 1; s >= 0; s--) {
909
- const c = i[s];
910
- if (!Tt(c, o, e)) continue;
911
- const u = Ie(c, a, n.tolerancia);
912
- u !== null && r.push({ elemento: c, distancia: u });
913
- }
914
- return r;
915
- }
916
- function fi(a, t, n = {}) {
917
- var o;
918
- return ((o = Pe(a, t, n)[0]) == null ? void 0 : o.elemento) ?? null;
919
- }
920
- function kt(a) {
921
- const t = w(a);
922
- if (!t) return null;
923
- const n = { id: a.id, camadaId: a.camadaId ?? "", geometria: t, propriedades: {} };
924
- return a.oculto && (n.oculta = !0), a.bloqueado && (n.bloqueada = !0), n;
925
- }
926
- const $e = (a) => ({ x: a[0], y: a[1] });
927
- function di(a, t, n, o = {}) {
928
- if (!a || ![a.x, a.y, a.largura, a.altura].every(V)) return [];
929
- const e = {
930
- x1: Math.min(a.x, a.x + a.largura),
931
- y1: Math.min(a.y, a.y + a.altura),
932
- x2: Math.max(a.x, a.x + a.largura),
933
- y2: Math.max(a.y, a.y + a.altura)
934
- }, r = o.incluirBloqueados === !0, i = Pa(o.camadas);
935
- return t.filter((s) => {
936
- if (!Tt(s, r, i)) return !1;
937
- const c = kt(s);
938
- return !!c && io(c, e, $e, n, A);
939
- });
940
- }
941
- function hi(a, t, n = {}) {
942
- if (!Array.isArray(a) || a.length < 3) return [];
943
- const o = n.incluirBloqueados === !0, e = Pa(n.camadas), r = a.filter((i) => V(i == null ? void 0 : i[0]) && V(i == null ? void 0 : i[1])).map((i) => [i[0], i[1]]);
944
- return t.filter((i) => {
945
- if (!Tt(i, o, e)) return !1;
946
- const s = kt(i);
947
- return !!s && co(s, r);
948
- });
949
- }
950
- function an(a) {
951
- const t = Ko(a);
952
- if (!t) return null;
953
- const n = t.x + t.largura, o = t.y + t.altura;
954
- return { id: a.id, camadaId: a.camadaId ?? "", geometria: { tipo: "Polygon", aneis: [[[t.x, t.y], [n, t.y], [n, o], [t.x, o]]] }, propriedades: {} };
955
- }
956
- class mi {
957
- constructor() {
958
- I(this, "indice", new Po(A));
959
- I(this, "elementos", /* @__PURE__ */ new Map());
960
- }
961
- get tamanho() {
962
- return this.elementos.size;
963
- }
964
- definir(t) {
965
- this.elementos.clear();
966
- const n = [];
967
- for (const o of t) {
968
- const e = o ? an(o) : null;
969
- e && (this.elementos.set(o.id, o), n.push(e));
970
- }
971
- this.indice.construir(n);
972
- }
973
- atualizar(t) {
974
- const n = t ? an(t) : null;
975
- if (!n) {
976
- t != null && t.id && this.remover(t.id);
977
- return;
978
- }
979
- this.elementos.set(t.id, t), this.indice.atualizar(n);
980
- }
981
- /**
982
- * Atualiza um lote (ex.: soltar uma seleção arrastada). Acima de 10% do índice remonta tudo de uma vez, que sai mais
983
- * barato que milhares de atualizações incrementais (cada compactação remontaria a árvore).
984
- */
985
- atualizarVarios(t) {
986
- if (t.length > Math.max(32, this.elementos.size * 0.1)) {
987
- const n = new Map(this.elementos);
988
- for (const o of t) o != null && o.id && n.set(o.id, o);
989
- this.definir([...n.values()]);
990
- return;
991
- }
992
- for (const n of t) this.atualizar(n);
993
- }
994
- remover(t) {
995
- this.elementos.delete(t), this.indice.remover(t);
996
- }
997
- obter(t) {
998
- return this.elementos.get(t);
999
- }
1000
- /** Elementos cujo envelope (conservador) toca a caixa (mm): candidatos para o teste fino. */
1001
- consultarCaixa(t, n = 0) {
1002
- if (!t || ![t.x, t.y, t.largura, t.altura, n].every(V)) return [];
1003
- const o = this.indice.consultar({
1004
- minLat: Math.min(t.x, t.x + t.largura) - n,
1005
- maxLat: Math.max(t.x, t.x + t.largura) + n,
1006
- minLon: Math.min(t.y, t.y + t.altura) - n,
1007
- maxLon: Math.max(t.y, t.y + t.altura) + n
1008
- }), e = [];
1009
- for (const r of new Set(o)) {
1010
- const i = this.elementos.get(r);
1011
- i && e.push(i);
1012
- }
1013
- return e;
1014
- }
1015
- /** Candidatos perto do ponto (mm), para o hit-test e o snap não percorrerem todos. */
1016
- consultarPonto(t, n) {
1017
- return this.consultarCaixa({ x: t[0], y: t[1], largura: 0, altura: 0 }, V(n) && n > 0 ? n : 0);
1018
- }
1019
- }
1020
- const Se = ["vertice", "canto", "centro", "meio", "guia", "aresta", "grade"], W = (a) => typeof a == "number" && Number.isFinite(a);
1021
- function pi(a, t, n, o = {}, e = []) {
1022
- if (!W(a == null ? void 0 : a[0]) || !W(a == null ? void 0 : a[1]) || !W(n) || n <= 0) return null;
1023
- const r = W(o.toleranciaPx) && o.toleranciaPx >= 0 ? o.toleranciaPx : uo, i = new Set(e), s = n, c = (p) => ({ x: p[0] * s, y: p[1] * s }), u = { x: a[0] * s, y: a[1] * s }, f = (p) => Math.hypot(p[0] * s - u.x, p[1] * s - u.y), d = t.filter((p) => p && !p.oculto && !i.has(p.id)), l = [];
1024
- for (const p of d) {
1025
- const M = kt(p);
1026
- M && l.push({ ...M, bloqueada: !1 });
1027
- }
1028
- const h = /* @__PURE__ */ new Map(), m = (p) => {
1029
- const M = h.get(p.tipo);
1030
- p.distanciaPx <= r && (!M || p.distanciaPx < M.distanciaPx) && h.set(p.tipo, p);
1031
- }, g = (p) => {
1032
- p && m({ tipo: p.tipo, coordenada: [p.coordenada[0], p.coordenada[1]], distanciaPx: p.distanciaPx, elementoId: p.feicaoId });
1033
- };
1034
- if (o.vertice !== !1 && g(Qa(u, l, c, { toleranciaPx: r, vertice: !0, meio: !1, aresta: !1 })), o.meio !== !1 && g(Qa(u, l, c, { toleranciaPx: r, vertice: !1, meio: !0, aresta: !1 })), o.aresta !== !1 && g(Qa(u, l, c, { toleranciaPx: r, vertice: !1, meio: !1, aresta: !0 })), o.canto !== !1 || o.centro !== !1)
1035
- for (const p of d) {
1036
- const M = wt(p);
1037
- if (M) {
1038
- if (o.canto !== !1)
1039
- for (const b of ["no", "ne", "se", "so"]) {
1040
- const x = P(M.quadro, F(M, b));
1041
- m({ tipo: "canto", coordenada: x, distanciaPx: f(x), elementoId: p.id });
1042
- }
1043
- if (o.centro !== !1) {
1044
- const b = P(M.quadro, F(M, "centro"));
1045
- m({ tipo: "centro", coordenada: b, distanciaPx: f(b), elementoId: p.id });
1046
- }
1047
- }
1048
- }
1049
- for (const p of o.guias ?? []) {
1050
- if (!p || !W(p.posicao)) continue;
1051
- const M = p.orientacao === "horizontal" ? [a[0], p.posicao] : [p.posicao, a[1]];
1052
- m({ tipo: "guia", coordenada: M, distanciaPx: f(M), guia: p });
1053
- }
1054
- const y = o.grade;
1055
- if (y && W(y.espacamento) && y.espacamento > 0) {
1056
- const p = y.origem && W(y.origem[0]) && W(y.origem[1]) ? y.origem : [0, 0], M = y.espacamento, b = [p[0] + Math.round((a[0] - p[0]) / M) * M, p[1] + Math.round((a[1] - p[1]) / M) * M];
1057
- m({ tipo: "grade", coordenada: b, distanciaPx: f(b) });
1058
- }
1059
- for (const p of Se) {
1060
- const M = h.get(p);
1061
- if (M) return M;
1062
- }
1063
- return null;
1064
- }
1065
- const Ua = (a) => typeof a == "number" && Number.isFinite(a), je = (a) => Array.isArray(a) && Ua(a[0]) && Ua(a[1]);
1066
- function ea(a) {
1067
- return !a || a.bloqueado || !a.geometria || a.geometria.tipo === "texto" ? null : wa(a.geometria);
1068
- }
1069
- function gi(a) {
1070
- if (!(a != null && a.geometria) || a.geometria.tipo === "texto") return null;
1071
- if (a.geometria.tipo === "caminho") return a;
1072
- const t = wa(a.geometria);
1073
- return t ? { ...a, geometria: { tipo: "caminho", geometria: t } } : null;
1074
- }
1075
- const $a = (a, t) => ({ ...a, geometria: { tipo: "caminho", geometria: t } });
1076
- function Rt(a, t) {
1077
- if (!je(t)) return null;
1078
- const n = la(E(a));
1079
- return n ? P(n, t) : null;
1080
- }
1081
- function yi(a) {
1082
- const t = ea(a);
1083
- if (!t) return [];
1084
- const n = E(a);
1085
- return ca(t, A).map((o) => P(n, o));
1086
- }
1087
- function bi(a) {
1088
- const t = ea(a);
1089
- if (!t) return [];
1090
- const n = E(a);
1091
- return ($t(t) ?? []).map((o) => ({
1092
- ...o.entrada ? { entrada: P(n, o.entrada) } : {},
1093
- ...o.saida ? { saida: P(n, o.saida) } : {}
1094
- }));
1095
- }
1096
- function Mi(a, t, n) {
1097
- const o = ea(a), e = o ? Rt(a, n) : null;
1098
- if (!o || !e) return null;
1099
- const r = ca(o, A).slice();
1100
- return !Number.isInteger(t) || t < 0 || t >= r.length ? null : (r[t] = e, $a(a, An(o, r, A)));
1101
- }
1102
- function xi(a, t, n, o) {
1103
- const e = ea(a), r = E(a), i = la(r);
1104
- if (!e || !i || !Ua(n) || !Ua(o)) return null;
1105
- const s = ca(e, A).slice(), c = t.filter((u) => Number.isInteger(u) && u >= 0 && u < s.length);
1106
- if (c.length === 0) return null;
1107
- for (const u of new Set(c)) {
1108
- const f = P(r, s[u]);
1109
- s[u] = P(i, [f[0] + n, f[1] + o]);
1110
- }
1111
- return $a(a, An(e, s, A));
1112
- }
1113
- function vi(a, t, n) {
1114
- const o = ea(a), e = o ? Rt(a, n) : null;
1115
- if (!o || !e) return null;
1116
- const r = ca(o, A).length;
1117
- return !Number.isInteger(t) || t < 0 || t >= r || o.tipo === "LineString" && t >= r - 1 ? null : $a(a, lo(o, t, e));
1118
- }
1119
- function Ai(a, t) {
1120
- const n = ea(a);
1121
- if (!n || !Number.isInteger(t) || ca(n, A).length <= fo(n)) return null;
1122
- const o = ho(n, t);
1123
- return o ? $a(a, o) : null;
1124
- }
1125
- function Ii(a, t) {
1126
- const n = ea(a), o = n ? ca(n, A).length : 0;
1127
- if (!n || !Number.isInteger(t) || t < 0 || t >= o) return null;
1128
- const e = mo(n, t);
1129
- return e === n ? null : $a(a, e);
1130
- }
1131
- function Pi(a, t, n, o, e = !0) {
1132
- const r = ea(a), i = r ? Rt(a, o) : null, s = r ? ca(r, A).length : 0;
1133
- return !r || !i || n !== "entrada" && n !== "saida" || !Number.isInteger(t) || t < 0 || t >= s ? null : $a(a, po(r, t, n, i, e));
1134
- }
1135
- const Ee = [
1136
- "retangulo",
1137
- "retangulo-arredondado",
1138
- "moldura-dupla",
1139
- "elipse",
1140
- "circulo",
1141
- "triangulo",
1142
- "losango",
1143
- "linha-horizontal",
1144
- "linha-vertical",
1145
- "linha-diagonal",
1146
- "seta",
1147
- "seta-dupla"
1148
- ], $i = ["continuo", "tracejado", "pontilhado", "traco-ponto"], ze = Object.freeze({
1149
- continuo: "continua",
1150
- tracejado: "tracejada",
1151
- pontilhado: "pontilhada",
1152
- "traco-ponto": "traco-ponto"
1153
- });
1154
- function Le(a) {
1155
- return typeof a == "string" && Ee.includes(a);
1156
- }
1157
- const Ne = Object.freeze({
1158
- retangulo: "Retângulo",
1159
- "retangulo-arredondado": "Retângulo arredondado",
1160
- "moldura-dupla": "Moldura dupla (ABNT)",
1161
- elipse: "Elipse",
1162
- circulo: "Círculo",
1163
- triangulo: "Triângulo",
1164
- losango: "Losango",
1165
- "linha-horizontal": "Linha horizontal",
1166
- "linha-vertical": "Linha vertical",
1167
- "linha-diagonal": "Linha diagonal",
1168
- seta: "Seta",
1169
- "seta-dupla": "Seta dupla"
1170
- }), Ce = {
1171
- retangulo: "molduras",
1172
- "moldura-dupla": "molduras",
1173
- "retangulo-arredondado": "formas",
1174
- elipse: "formas",
1175
- circulo: "formas",
1176
- triangulo: "formas",
1177
- losango: "formas",
1178
- "linha-horizontal": "linhas",
1179
- "linha-vertical": "linhas",
1180
- "linha-diagonal": "linhas",
1181
- seta: "setas",
1182
- "seta-dupla": "setas"
1183
- }, Si = Object.freeze(
1184
- ["retangulo", "moldura-dupla", "retangulo-arredondado", "elipse", "circulo", "triangulo", "losango", "linha-horizontal", "linha-vertical", "linha-diagonal", "seta", "seta-dupla"].map((a) => Object.freeze({ valor: a, rotulo: Ne[a], grupo: Ce[a], usaQuadro: a === "retangulo" || a === "moldura-dupla" }))
1185
- ), Ra = (a) => typeof a == "number" && Number.isFinite(a), Ea = (a, t) => Ra(a) && a > 0 ? a : t, tn = (a) => Ra(a) ? Math.min(1, Math.max(0, a)) : void 0;
1186
- function D(a, t, n = {}) {
1187
- const o = tn(a.opacidadeTraco), e = tn(a.opacidadePreenchimento);
1188
- return { traco: a.semTraco === !0 ? null : {
1189
- cor: a.corTraco ?? "#000000",
1190
- espessura: Ea(a.espessura, 0.35),
1191
- tipoLinha: ze[a.estiloTraco ?? "continuo"] ?? "continua",
1192
- ...o !== void 0 ? { opacidade: o } : {},
1193
- ...t && (a.alinhamentoTraco === "dentro" || a.alinhamentoTraco === "fora") ? { alinhamento: a.alinhamentoTraco } : {},
1194
- ...n
1195
- }, preenchimento: t && a.corPreenchimento ? { cor: a.corPreenchimento, ...e !== void 0 ? { opacidade: e } : {} } : null };
1196
- }
1197
- function ja(a, t, n) {
1198
- const o = Ra(n) && n > 0 ? n : 0, e = Math.hypot(t[0] - a[0], t[1] - a[1]);
1199
- if (o === 0 || !(e > 2 * o)) return [a, t];
1200
- const r = (t[0] - a[0]) / e, i = (t[1] - a[1]) / e;
1201
- return [[a[0] + r * o, a[1] + i * o], [t[0] - r * o, t[1] - i * o]];
1202
- }
1203
- function nn(a, t, n, o, e) {
1204
- const r = t.x + t.largura / 2, i = t.y + t.altura / 2, s = {
1205
- id: a,
1206
- geometria: { tipo: "caminho", geometria: { tipo: "Polygon", aneis: [n] } },
1207
- transformacao: q(r, i),
1208
- aparencia: o
1209
- };
1210
- return e && (s.camadaId = e), s;
1211
- }
1212
- function ji(a, t, n = {}) {
1213
- const o = Ot(t);
1214
- if (!o || !Le(a)) return [];
1215
- const e = typeof n.id == "string" && n.id ? n.id : "predefinicao", r = { id: e, camadaId: n.camadaId }, i = o.largura, s = o.altura, c = (d) => d ? [d] : [], u = n.ponta ?? { estilo: "triangulo" }, f = i > 0 && s > 0;
1216
- switch (a) {
1217
- case "retangulo":
1218
- return f ? c(_a({ ...r, aparencia: D(n, !0) }, o)) : [];
1219
- case "retangulo-arredondado":
1220
- return f ? c(_a({ ...r, aparencia: D(n, !0) }, o, Ea(n.raio, Math.min(i, s) * 0.1))) : [];
1221
- case "moldura-dupla": {
1222
- if (!f) return [];
1223
- const d = Ea(n.espacamento, 1.5);
1224
- if (2 * d >= Math.min(i, s)) return [];
1225
- const l = `${e}-grupo`, h = n.preenchimentoNa === "externa", m = _a({ ...r, grupoId: l, aparencia: D(n, h) }, o), g = _a(
1226
- { id: `${e}-2`, camadaId: n.camadaId, grupoId: l, aparencia: D({ ...n, espessura: Ea(n.espessuraInterna, Ea(n.espessura, 0.35) * 2) }, !h) },
1227
- { x: o.x + d, y: o.y + d, largura: i - 2 * d, altura: s - 2 * d }
1228
- );
1229
- return m && g ? [m, g] : [];
1230
- }
1231
- case "elipse":
1232
- return f ? c(Qt({ ...r, aparencia: D(n, !0) }, o)) : [];
1233
- case "circulo": {
1234
- if (!f) return [];
1235
- const d = Math.min(i, s);
1236
- return c(Qt({ ...r, aparencia: D(n, !0) }, { x: o.x + (i - d) / 2, y: o.y + (s - d) / 2, largura: d, altura: d }));
1237
- }
1238
- case "triangulo":
1239
- return f ? [nn(e, o, [[0, -s / 2], [i / 2, s / 2], [-i / 2, s / 2]], D(n, !0), n.camadaId)] : [];
1240
- case "losango":
1241
- return f ? [nn(e, o, [[0, -s / 2], [i / 2, 0], [0, s / 2], [-i / 2, 0]], D(n, !0), n.camadaId)] : [];
1242
- case "linha-horizontal": {
1243
- const [d, l] = ja([o.x, o.y + s / 2], [o.x + i, o.y + s / 2], n.recuo);
1244
- return i > 0 ? c(Sa({ ...r, aparencia: D(n, !1) }, d, l)) : [];
1245
- }
1246
- case "linha-vertical": {
1247
- const [d, l] = ja([o.x + i / 2, o.y], [o.x + i / 2, o.y + s], n.recuo);
1248
- return s > 0 ? c(Sa({ ...r, aparencia: D(n, !1) }, d, l)) : [];
1249
- }
1250
- case "linha-diagonal": {
1251
- const [d, l] = ja([o.x, o.y], [o.x + i, o.y + s], n.recuo);
1252
- return f ? c(Sa({ ...r, aparencia: D(n, !1) }, d, l)) : [];
1253
- }
1254
- case "seta": {
1255
- const [d, l] = ja([o.x, o.y + s / 2], [o.x + i, o.y + s / 2], n.recuo);
1256
- return i > 0 ? c(Sa({ ...r, aparencia: D(n, !1, { pontaFim: u }) }, d, l)) : [];
1257
- }
1258
- case "seta-dupla": {
1259
- const [d, l] = ja([o.x, o.y + s / 2], [o.x + i, o.y + s / 2], n.recuo);
1260
- return i > 0 ? c(Sa({ ...r, aparencia: D(n, !1, { pontaInicio: u, pontaFim: u }) }, d, l)) : [];
1261
- }
1262
- }
1263
- }
1264
- const Ei = ["A0", "A1", "A2", "A3", "A4"], qe = Object.freeze({
1265
- A0: [841, 1189],
1266
- A1: [594, 841],
1267
- A2: [420, 594],
1268
- A3: [297, 420],
1269
- A4: [210, 297]
1270
- });
1271
- function De(a) {
1272
- const t = a === "A0" || a === "A1" ? 10 : 7;
1273
- return { esquerda: 25, direita: t, superior: t, inferior: t };
1274
- }
1275
- function Oe(a, t, n) {
1276
- if (!n || ![a, t, n.esquerda, n.direita, n.superior, n.inferior].every(Ra) || [n.esquerda, n.direita, n.superior, n.inferior].some((r) => r < 0)) return null;
1277
- const o = a - n.esquerda - n.direita, e = t - n.superior - n.inferior;
1278
- return o > 0 && e > 0 ? { x: n.esquerda, y: n.superior, largura: o, altura: e } : null;
1279
- }
1280
- function zi(a, t = "retrato", n = {}) {
1281
- const o = qe[a];
1282
- if (!o) return null;
1283
- const [e, r] = t === "paisagem" ? [o[1], o[0]] : o, i = { ...De(a) };
1284
- for (const s of ["esquerda", "direita", "superior", "inferior"]) Ra(n[s]) && n[s] >= 0 && (i[s] = n[s]);
1285
- return Oe(e, r, i);
1286
- }
1287
- const ia = (a) => typeof a == "number" && Number.isFinite(a);
1288
- function we(a, t) {
1289
- const n = ia(a) && a > 0 ? a : 0.25, o = ia(t) && t > 0 ? Math.min(100, Math.max(0.1, t)) : 1;
1290
- return Math.max(2, 5 * n) * o;
1291
- }
1292
- const on = 24;
1293
- function Te(a, t, n, o) {
1294
- if (!a || !ia(t == null ? void 0 : t[0]) || !ia(t == null ? void 0 : t[1]) || !ia(n == null ? void 0 : n[0]) || !ia(n == null ? void 0 : n[1])) return null;
1295
- const e = Math.hypot(n[0], n[1]);
1296
- if (!(e > 1e-12)) return null;
1297
- const r = [n[0] / e, n[1] / e], i = -r[1], s = r[0], c = we(o, a.escala), u = 0.4 * c, f = (l, h) => [t[0] + r[0] * l + i * h, t[1] + r[1] * l + s * h];
1298
- switch (a.estilo) {
1299
- case "triangulo":
1300
- return { pontos: [t, f(-c, u), f(-c, -u)], fechada: !0, preenchida: !0, recuo: c / 2 };
1301
- case "triangulo-aberto":
1302
- return { pontos: [t, f(-c, u), f(-c, -u)], fechada: !0, preenchida: !1, recuo: c };
1303
- case "aberta":
1304
- return { pontos: [f(-c, u), t, f(-c, -u)], fechada: !1, preenchida: !1, recuo: 0 };
1305
- case "barra":
1306
- return { pontos: [f(0, u), f(0, -u)], fechada: !1, preenchida: !1, recuo: 0 };
1307
- case "quadrado": {
1308
- const l = c / 3;
1309
- return { pontos: [f(l, l), f(l, -l), f(-l, -l), f(-l, l)], fechada: !0, preenchida: !0, recuo: l };
1310
- }
1311
- case "losango":
1312
- return { pontos: [f(c / 2, 0), f(0, u), f(-c / 2, 0), f(0, -u)], fechada: !0, preenchida: !0, recuo: c / 4 };
1313
- case "circulo": {
1314
- const l = c / 3, h = [];
1315
- for (let m = 0; m < on; m++) {
1316
- const g = 2 * Math.PI * m / on;
1317
- h.push([t[0] + l * Math.cos(g), t[1] + l * Math.sin(g)]);
1318
- }
1319
- return { pontos: h, fechada: !0, preenchida: !0, recuo: l };
1320
- }
1321
- default:
1322
- return null;
1323
- }
1324
- }
1325
- function ke(a, t) {
1326
- const n = a.length;
1327
- if (n < 2) return null;
1328
- const o = t ? a[n - 1] : a[0];
1329
- for (let e = 1; e < n; e++) {
1330
- const r = t ? a[n - 1 - e] : a[e], i = o[0] - r[0], s = o[1] - r[1];
1331
- if (Math.hypot(i, s) > 1e-9) return [i, s];
1332
- }
1333
- return null;
1334
- }
1335
- const en = 4e3;
1336
- function rn(a, t, n, o, e, r) {
1337
- if (![a, t, n, o, e, r].every(ia) || r <= 0 || n < a || o < t) return [];
1338
- const i = Math.cos(e), s = Math.sin(e), c = -s, u = i, f = [[a, t], [n, t], [n, o], [a, o]], d = f.map(([b, x]) => b * c + x * u), l = Math.min(...d), h = Math.max(...d);
1339
- let m = r;
1340
- (h - l) / m > en && (m = (h - l) / en);
1341
- const g = f.map(([b, x]) => b * i + x * s), y = Math.min(...g) - m, p = Math.max(...g) + m, M = [];
1342
- for (let b = Math.ceil(l / m); b * m <= h; b++) {
1343
- const x = b * m;
1344
- M.push([[c * x + i * y, u * x + s * y], [c * x + i * p, u * x + s * p]]);
1345
- }
1346
- return M;
1347
- }
1348
- const ma = (a) => typeof a == "number" && Number.isFinite(a);
1349
- function Tn(a) {
1350
- const t = $o(a), n = a.tipo === "Polygon";
1351
- if (t) {
1352
- const r = So(t, n).map((i) => i.cmd === "C" ? { c: "C", c1: i.pts[0], c2: i.pts[1], p: i.pts[2] } : { c: i.cmd, p: i.pts[0] });
1353
- return n && r.push({ c: "Z" }), r;
1354
- }
1355
- const o = a.tipo === "Polygon" ? a.aneis : a.partes && a.partes.length > 1 ? a.partes : [a.coordenadas], e = [];
1356
- for (const r of o)
1357
- if (r.length !== 0) {
1358
- e.push({ c: "M", p: r[0] });
1359
- for (let i = 1; i < r.length; i++) e.push({ c: "L", p: r[i] });
1360
- n && e.push({ c: "Z" });
1361
- }
1362
- return e;
1363
- }
1364
- const kn = (a) => a.length < 3 ? [] : [{ c: "M", p: a[0] }, ...a.slice(1).map((t) => ({ c: "L", p: t })), { c: "Z" }];
1365
- function Re(a, t) {
1366
- if (t.alinhamento === "centro" || a.tipo !== "Polygon") return null;
1367
- const n = t.alinhamento === "fora" ? t.largura / 2 : -t.largura / 2, o = xa({ tipo: "Polygon", aneis: [a.aneis[0]] }, n, A);
1368
- return o ? kn(o) : null;
1369
- }
1370
- function Fe(a, t, n) {
1371
- if (!(n > 0) || a.length < 2) return;
1372
- const o = t ? a.length - 1 : 0, e = t ? a[a.length - 2] : a[1], r = a[o];
1373
- if (r.c === "Z" || e.c === "Z" || (t ? r.c !== "L" : e.c !== "L")) return;
1374
- const i = r.p, s = e.p, c = Math.hypot(i[0] - s[0], i[1] - s[1]);
1375
- if (c <= n * 1.01) return;
1376
- const u = n / c;
1377
- a[o] = { ...r, p: [i[0] + (s[0] - i[0]) * u, i[1] + (s[1] - i[1]) * u] };
1378
- }
1379
- function _e(a) {
1380
- const t = qt(a);
1381
- if (!t || !(t.largura > 0) || !(t.altura > 0)) return null;
1382
- const n = Et(Lt(t.largura, t.altura), q(t.x, t.y), E(a));
1383
- return Do(n) ? null : n;
1384
- }
1385
- function Ge(a) {
1386
- var s;
1387
- if (!a || typeof a != "object" || a.oculto) return null;
1388
- const t = w(a);
1389
- if (!t) return null;
1390
- const n = Ta(a), o = { id: String(a.id), opacidade: n.opacidade, preenchimento: null, hachura: null, traco: null, pontas: [], texto: null }, e = a.geometria.tipo === "texto" ? a.geometria : null;
1391
- if (e)
1392
- return n.preenchimento && (o.texto = {
1393
- linhas: String(e.texto ?? "").split(`
1394
- `),
1395
- tamanho: e.tamanho,
1396
- fonte: En(e.fonte),
1397
- alinhamento: e.alinhamento === "centro" ? "center" : e.alinhamento === "direita" ? "right" : "left",
1398
- cor: n.preenchimento.cor,
1399
- opacidade: n.preenchimento.opacidade,
1400
- matriz: E(a),
1401
- entrelinha: 1.2
1402
- }), sn(o, n, t), o;
1403
- const r = Tn(t);
1404
- if (n.preenchimento && t.tipo === "Polygon") {
1405
- const c = n.preenchimento;
1406
- o.preenchimento = { caminho: r, regra: c.regra, cor: c.cor, opacidade: c.opacidade };
1407
- const u = c.gradiente ? _e(a) : null;
1408
- c.gradiente && u && (o.preenchimento.gradiente = { def: c.gradiente.def, quadro: u, opacidadeDegradacao: c.gradiente.opacidadeDegradacao });
1409
- }
1410
- if (n.hachura && t.tipo === "Polygon") {
1411
- const c = n.hachura, u = Ia(a);
1412
- if (u) {
1413
- const f = u.x + u.largura, d = u.y + u.altura, l = rn(u.x, u.y, f, d, c.angulo, c.espacamento);
1414
- c.cruzada && l.push(...rn(u.x, u.y, f, d, c.angulo + Math.PI / 2, c.espacamento)), l.length > 0 && (o.hachura = { recorte: r, regra: ((s = n.preenchimento) == null ? void 0 : s.regra) ?? "nonzero", linhas: l, cor: c.cor, largura: c.largura, opacidade: c.opacidade });
1415
- }
1416
- }
1417
- const i = n.traco;
1418
- if (i) {
1419
- const c = Re(t, i) ?? r.slice();
1420
- if (t.tipo === "LineString") {
1421
- const u = t.partes && t.partes.length > 1 ? t.partes : [t.coordenadas], f = [[!1, i.pontaInicio], [!0, i.pontaFim]];
1422
- for (const [d, l] of f) {
1423
- if (!l) continue;
1424
- const h = d ? u[u.length - 1] : u[0], m = ke(h, d), g = m ? Te(l, d ? h[h.length - 1] : h[0], m, i.largura) : null;
1425
- if (!g) continue;
1426
- u.length === 1 && Fe(c, d, g.recuo);
1427
- const y = [{ c: "M", p: g.pontos[0] }, ...g.pontos.slice(1).map((p) => ({ c: "L", p }))];
1428
- g.fechada && y.push({ c: "Z" }), o.pontas.push({ caminho: y, preenchida: g.preenchida, cor: i.cor, largura: i.largura, opacidade: i.opacidade });
1429
- }
1430
- }
1431
- o.traco = {
1432
- caminho: c,
1433
- cor: i.cor,
1434
- largura: i.largura,
1435
- opacidade: i.opacidade,
1436
- tracejado: i.tracejado,
1437
- terminacao: i.terminacao,
1438
- juncao: i.juncao,
1439
- limitePonta: i.limitePonta
1440
- };
1441
- }
1442
- return sn(o, n, t), o;
1443
- }
1444
- function Xe(a, t, n) {
1445
- const o = (s, c) => ({ caminho: s, modo: "encher", regra: c, largura: 0, tracejado: [], terminacao: "butt", juncao: "miter" }), e = [], r = a.preenchimento ?? (a.hachura ? { caminho: a.hachura.recorte, regra: a.hachura.regra } : null), i = a.traco;
1446
- if (r && i && t && n.tipo === "Polygon" && n.aneis.length === 1 && t.alinhamento !== "dentro" && i.tracejado.length === 0) {
1447
- const s = xa({ tipo: "Polygon", aneis: [n.aneis[0]] }, t.alinhamento === "fora" ? t.largura : t.largura / 2, A);
1448
- if (s) return [o(kn(s), "nonzero")];
1449
- }
1450
- r && e.push(o(r.caminho, r.regra)), i && e.push({ caminho: i.caminho, modo: "tracar", regra: "nonzero", largura: i.largura, tracejado: i.tracejado, terminacao: i.terminacao, juncao: i.juncao });
1451
- for (const s of a.pontas)
1452
- e.push(s.preenchida ? o(s.caminho, "nonzero") : { caminho: s.caminho, modo: "tracar", regra: "nonzero", largura: s.largura, tracejado: [], terminacao: "butt", juncao: "miter" });
1453
- return e;
1454
- }
1455
- function sn(a, t, n) {
1456
- t.mesclagem && (a.mesclagem = t.mesclagem);
1457
- const o = t.sombra;
1458
- if (!o) return;
1459
- const e = a.texto ? [] : Xe(a, t.traco, n);
1460
- e.length === 0 && !a.texto || (a.sombra = { dx: o.dx, dy: o.dy, desfoque: o.desfoque, cor: o.cor, opacidade: o.opacidade, partes: e, texto: a.texto });
1461
- }
1462
- const it = /* @__PURE__ */ new WeakMap();
1463
- function Rn(a) {
1464
- if (!a || typeof a != "object") return null;
1465
- if (it.has(a)) return it.get(a);
1466
- let t = null;
1467
- try {
1468
- t = Ge(a);
1469
- } catch {
1470
- t = null;
1471
- }
1472
- return it.set(a, t), t;
1473
- }
1474
- function Fn(a, t) {
1475
- if (!Array.isArray(a)) return [];
1476
- const n = a.filter((i) => i && typeof i == "object"), o = Pa(t), e = new Map(n.map((i) => [i.id, i])), r = [];
1477
- for (const i of ka(n, o)) {
1478
- if (i.mascara || !o.visivel(i)) continue;
1479
- const s = Rn(i);
1480
- if (!s) continue;
1481
- let c = s;
1482
- const u = o.opacidade(i);
1483
- u < 1 && (c = { ...c, opacidade: c.opacidade * u });
1484
- const f = i.recorteId ? e.get(i.recorteId) : void 0, d = f && f.mascara ? w(f) : null;
1485
- d && d.tipo === "Polygon" && (c = { ...c, recorte: { caminho: Tn(d), regra: d.aneis.length > 1 ? "evenodd" : "nonzero" } }), r.push(c);
1486
- }
1487
- return r;
1488
- }
1489
- const T = (a) => a.every((t) => t.c === "Z" || ma(t.p[0]) && ma(t.p[1]) && (t.c !== "C" || ma(t.c1[0]) && ma(t.c1[1]) && ma(t.c2[0]) && ma(t.c2[1]))), _n = 3, gt = (a) => typeof a == "number" && Number.isFinite(a);
1490
- function H(a, t, n, o = 0, e = 0, r = 0) {
1491
- !gt(t) || !gt(n) || (a.x0 = Math.min(a.x0, t + e - o), a.y0 = Math.min(a.y0, n + r - o), a.x1 = Math.max(a.x1, t + e + o), a.y1 = Math.max(a.y1, n + r + o));
1492
- }
1493
- function za(a, t, n = 0, o = 0, e = 0) {
1494
- for (const r of t)
1495
- r.c !== "Z" && (H(a, r.p[0], r.p[1], n, o, e), r.c === "C" && (H(a, r.c1[0], r.c1[1], n, o, e), H(a, r.c2[0], r.c2[1], n, o, e)));
1496
- }
1497
- const Z = (a, t) => {
1498
- const n = t[0] - a[0], o = t[1] - a[1], e = Math.hypot(n, o);
1499
- return e > 1e-12 ? [n / e, o / e] : null;
1500
- };
1501
- function Be(a) {
1502
- const t = [], n = [];
1503
- let o = [], e = [0, 0], r = [0, 0], i = !1;
1504
- const s = (c) => {
1505
- for (let u = 0; u + 1 < o.length; u++) t.push({ p: o[u].para, entrada: o[u].fim, saida: o[u + 1].ini });
1506
- c && o.length > 1 ? t.push({ p: o[0].de, entrada: o[o.length - 1].fim, saida: o[0].ini }) : !c && o.length > 0 && n.push(o[0].de, o[o.length - 1].para), o = [];
1507
- };
1508
- for (const c of a) {
1509
- if (c.c === "M") {
1510
- i && s(!1), i = !0, e = c.p, r = c.p;
1511
- continue;
1512
- }
1513
- if (i)
1514
- if (c.c === "L") {
1515
- const u = Z(e, c.p);
1516
- o.push({ de: e, para: c.p, ini: u, fim: u }), e = c.p;
1517
- } else if (c.c === "C")
1518
- o.push({ de: e, para: c.p, ini: Z(e, c.c1) ?? Z(e, c.c2) ?? Z(e, c.p), fim: Z(c.c2, c.p) ?? Z(c.c1, c.p) ?? Z(e, c.p) }), e = c.p;
1519
- else {
1520
- const u = Z(e, r);
1521
- u && o.push({ de: e, para: r, ini: u, fim: u }), s(!0), i = !1;
1522
- }
1523
- }
1524
- return i && s(!1), { vertices: t, extremos: n };
1525
- }
1526
- function st(a, t, n, o, e, r, i = 0, s = 0, c = 0) {
1527
- const u = n / 2;
1528
- if (za(a, t, u + c, i, s), !(u > 0)) return;
1529
- const { vertices: f, extremos: d } = Be(t);
1530
- if (o === "miter") {
1531
- const l = e >= 1 ? e : 4;
1532
- for (const h of f) {
1533
- if (!h.entrada || !h.saida) continue;
1534
- const m = Math.max(-1, Math.min(1, h.entrada[0] * h.saida[0] + h.entrada[1] * h.saida[1])), g = Math.sqrt((1 + m) / 2);
1535
- if (!(g > 1e-9)) continue;
1536
- const y = 1 / g;
1537
- if (y > l) continue;
1538
- const p = h.entrada[0] - h.saida[0], M = h.entrada[1] - h.saida[1], b = Math.hypot(p, M);
1539
- b > 1e-12 && H(a, h.p[0] + p / b * u * y, h.p[1] + M / b * u * y, c, i, s);
1540
- }
1541
- }
1542
- if (r === "square") for (const l of d) H(a, l[0], l[1], u * Math.SQRT2 + c, i, s);
1543
- }
1544
- function Ue(a, t, n) {
1545
- t.preenchimento && za(a, t.preenchimento.caminho), t.hachura && za(a, t.hachura.recorte);
1546
- const o = t.traco;
1547
- o && st(a, o.caminho, o.largura, o.juncao, o.limitePonta, o.terminacao);
1548
- for (const r of t.pontas)
1549
- r.preenchida ? za(a, r.caminho) : st(a, r.caminho, r.largura, "miter", (o == null ? void 0 : o.limitePonta) ?? 4, "butt");
1550
- const e = t.sombra;
1551
- if (n && e) {
1552
- const r = e.desfoque > 0 ? e.desfoque * _n : 0;
1553
- for (const i of e.partes)
1554
- i.modo === "tracar" ? st(a, i.caminho, i.largura, i.juncao, 4, i.terminacao, e.dx, e.dy, r) : za(a, i.caminho, r, e.dx, e.dy);
1555
- }
1556
- }
1557
- function Li(a, t = {}) {
1558
- var i;
1559
- const n = Array.isArray(a) ? a : a ? [a] : [], o = t.sombra !== !1, e = new Set((t.camadas ?? []).filter((s) => s && s.visivel === !1).map((s) => s.id)), r = { x0: 1 / 0, y0: 1 / 0, x1: -1 / 0, y1: -1 / 0 };
1560
- for (const s of n) {
1561
- const c = s;
1562
- if (!(!c || typeof c != "object" || c.oculto || c.mascara) && !(c.camadaId !== void 0 && e.has(c.camadaId)))
1563
- try {
1564
- const u = Rn(c);
1565
- if (!u) continue;
1566
- if (Ue(r, u, o), ((i = c.geometria) == null ? void 0 : i.tipo) === "texto") {
1567
- const f = Ia(c);
1568
- if (f) {
1569
- H(r, f.x, f.y), H(r, f.x + f.largura, f.y + f.altura);
1570
- const d = u.sombra;
1571
- if (o && d) {
1572
- const l = d.desfoque > 0 ? d.desfoque * _n : 0;
1573
- H(r, f.x, f.y, l, d.dx, d.dy), H(r, f.x + f.largura, f.y + f.altura, l, d.dx, d.dy);
1574
- }
1575
- }
1576
- }
1577
- } catch {
1578
- }
1579
- }
1580
- return !(r.x0 <= r.x1 && r.y0 <= r.y1) || ![r.x0, r.y0, r.x1, r.y1].every(gt) ? null : { x: r.x0, y: r.y0, largura: r.x1 - r.x0, altura: r.y1 - r.y0 };
1581
- }
1582
- const cn = ["save", "restore", "beginPath", "moveTo", "lineTo", "bezierCurveTo", "closePath", "fill", "stroke", "clip", "setLineDash", "fillRect"], un = ["fillStyle", "strokeStyle", "lineWidth", "lineCap", "lineJoin", "globalAlpha"], Ma = (a, t) => {
1583
- try {
1584
- return typeof a[t] == "function";
1585
- } catch {
1586
- return !1;
1587
- }
1588
- };
1589
- function Gn(a) {
1590
- return !a || typeof a != "object" && typeof a != "function" ? "nenhuma" : Ma(a, "setTransform") ? "absoluta" : Ma(a, "transform") ? "relativa" : "nenhuma";
1591
- }
1592
- function Ni(a) {
1593
- const t = !!a && (typeof a == "object" || typeof a == "function"), n = Gn(a), o = [], e = [], r = (i) => {
1594
- try {
1595
- return a[i] !== void 0;
1596
- } catch {
1597
- return !1;
1598
- }
1599
- };
1600
- if (!t) return { obrigatorios: [...cn, ...un, "setTransform"], opcionais: ["gradiente", "texto", "mesclagem", "filtro", "miterLimit"], transformacao: n };
1601
- for (const i of cn) Ma(a, i) || o.push(i);
1602
- for (const i of un) r(i) || o.push(i);
1603
- return n === "nenhuma" && o.push("setTransform"), (!Ma(a, "createLinearGradient") || !Ma(a, "createRadialGradient")) && e.push("gradiente"), (!Ma(a, "fillText") || !r("font") || !r("textAlign") || !r("textBaseline")) && e.push("texto"), r("globalCompositeOperation") || e.push("mesclagem"), r("filter") || e.push("filtro"), r("miterLimit") || e.push("miterLimit"), { obrigatorios: o, opcionais: e, transformacao: n };
1604
- }
1605
- function He(a) {
1606
- let t = ta;
1607
- const n = [], o = {
1608
- save: () => {
1609
- n.push(t), a.save();
1610
- },
1611
- restore: () => {
1612
- t = n.pop() ?? t, a.restore();
1613
- },
1614
- setTransform: (e, r, i, s, c, u) => {
1615
- const f = Aa({ a: e, b: r, c: i, d: s, e: c, f: u }), d = la(t);
1616
- if (!d) throw new Error("transform corrente singular: não dá para posicionar a matriz de forma relativa");
1617
- const l = ua(d, f);
1618
- a.transform(l.a, l.b, l.c, l.d, l.e, l.f), t = f;
1619
- }
1620
- };
1621
- return new Proxy(a, {
1622
- get(e, r) {
1623
- if (typeof r == "string" && r in o) return o[r];
1624
- const i = Reflect.get(e, r, e);
1625
- return typeof i == "function" ? i.bind(e) : i;
1626
- },
1627
- set(e, r, i) {
1628
- return Reflect.set(e, r, i, e);
1629
- }
1630
- });
1631
- }
1632
- let yt = !1;
1633
- function ln(a) {
1634
- if (!yt) {
1635
- yt = !0;
1636
- try {
1637
- typeof console < "u" && typeof console.warn == "function" && console.warn(`[ui-canvas-prancha] ${a}`);
1638
- } catch {
1639
- }
1640
- }
1641
- }
1642
- function Ci() {
1643
- yt = !1;
1644
- }
1645
- const bt = 24, Ve = 256, Ha = (a) => typeof a == "number" && Number.isFinite(a);
1646
- function fn(a) {
1647
- const t = a.trim(), n = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(t);
1648
- if (n) {
1649
- let e = n[1];
1650
- return e.length === 3 && (e = e.split("").map((r) => r + r).join("")), [parseInt(e.slice(0, 2), 16), parseInt(e.slice(2, 4), 16), parseInt(e.slice(4, 6), 16)];
1651
- }
1652
- const o = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(t);
1653
- return o ? [Number(o[1]), Number(o[2]), Number(o[3])] : null;
1654
- }
1655
- function Ye(a, t) {
1656
- const n = a.filter((r) => r && Ha(r.posicao)).map((r) => ({ ...r, posicao: Math.min(1, Math.max(0, r.posicao)) })).sort((r, i) => r.posicao - i.posicao);
1657
- if (n.length === 0) return { cor: "#000000", opacidade: 1 };
1658
- const o = (r) => Ha(r.opacidade) ? Math.min(1, Math.max(0, r.opacidade)) : 1;
1659
- if (t <= n[0].posicao) return { cor: n[0].cor, opacidade: o(n[0]) };
1660
- const e = n[n.length - 1];
1661
- if (t >= e.posicao) return { cor: e.cor, opacidade: o(e) };
1662
- for (let r = 0; r + 1 < n.length; r++) {
1663
- const i = n[r], s = n[r + 1];
1664
- if (t < i.posicao || t > s.posicao) continue;
1665
- const c = s.posicao > i.posicao ? (t - i.posicao) / (s.posicao - i.posicao) : 0, u = fn(i.cor), f = fn(s.cor), d = o(i) + (o(s) - o(i)) * c;
1666
- if (!u || !f) return { cor: c < 0.5 ? i.cor : s.cor, opacidade: d };
1667
- const l = (h) => Math.round(u[h] + (f[h] - u[h]) * c);
1668
- return { cor: `rgb(${l(0)},${l(1)},${l(2)})`, opacidade: d };
1669
- }
1670
- return { cor: e.cor, opacidade: o(e) };
1671
- }
1672
- function We(a, t = bt) {
1673
- if (!a || a.tipo !== "linear" || !Array.isArray(a.paradas) || a.paradas.length === 0) return null;
1674
- const [n, o] = a.de ?? [NaN, NaN], [e, r] = a.ate ?? [NaN, NaN];
1675
- if (![n, o, e, r].every(Ha)) return null;
1676
- const i = e - n, s = r - o, c = Math.hypot(i, s);
1677
- if (!(c > 1e-12)) return null;
1678
- const u = Ha(t) ? Math.min(Ve, Math.max(2, Math.round(t))) : bt, f = -s / c, d = i / c, l = 1e3, h = [];
1679
- for (let m = 0; m < u; m++) {
1680
- const g = m === 0 ? -l : m / u, y = m === u - 1 ? l : (m + 1) / u, { cor: p, opacidade: M } = Ye(a.paradas, (m + 0.5) / u), b = [n + i * g, o + s * g], x = [n + i * y, o + s * y];
1681
- h.push({
1682
- pontos: [[b[0] + f * l, b[1] + d * l], [x[0] + f * l, x[1] + d * l], [x[0] - f * l, x[1] - d * l], [b[0] - f * l, b[1] - d * l]],
1683
- cor: p,
1684
- opacidade: M
1685
- });
1686
- }
1687
- return h;
1688
- }
1689
- const aa = (a, t) => a.setTransform(t.a, t.b, t.c, t.d, t.e, t.f);
1690
- function pa(a, t) {
1691
- for (const n of t)
1692
- n.c === "M" ? a.moveTo(n.p[0], n.p[1]) : n.c === "L" ? a.lineTo(n.p[0], n.p[1]) : n.c === "C" ? a.bezierCurveTo(n.c1[0], n.c1[1], n.c2[0], n.c2[1], n.p[0], n.p[1]) : a.closePath();
1693
- }
1694
- const Mt = (a, t) => t === "evenodd" ? a.fill("evenodd") : a.fill(), xt = (a, t) => t === "evenodd" ? a.clip("evenodd") : a.clip();
1695
- function Ze(a, t) {
1696
- const n = t.gradiente;
1697
- if (!n) return null;
1698
- const o = n.def;
1699
- let e = null;
1700
- if (o.tipo === "linear" && typeof a.createLinearGradient == "function")
1701
- e = a.createLinearGradient(o.de[0], o.de[1], o.ate[0], o.ate[1]);
1702
- else if (o.tipo === "radial" && typeof a.createRadialGradient == "function") {
1703
- const r = o.foco ?? o.centro;
1704
- e = a.createRadialGradient(r[0], r[1], 0, o.centro[0], o.centro[1], o.raio);
1705
- }
1706
- if (!e) return null;
1707
- for (const r of o.paradas) e.addColorStop(r.posicao, re(r.cor, r.opacidade ?? 1));
1708
- return e;
1709
- }
1710
- const Je = (a) => Math.sqrt(Math.abs(a.a * a.d - a.b * a.c)) || 1;
1711
- function Xn(a, t, n, o, e) {
1712
- aa(a, ua(n, t.matriz)), a.font = `${t.tamanho}px ${t.fonte}`, a.textAlign = t.alinhamento, a.textBaseline = "alphabetic", a.fillStyle = o, a.globalAlpha = e, t.linhas.forEach((r, i) => a.fillText(r, 0, i * t.tamanho * t.entrelinha));
1713
- }
1714
- function Qe(a, t, n, o, e) {
1715
- const r = ua(n, q(t.dx, t.dy)), i = t.desfoque > 0 && typeof a.filter == "string";
1716
- t.desfoque > 0 && !i && (e.degradacoes.desfoque = (e.degradacoes.desfoque ?? 0) + 1), a.save(), i && (a.filter = `blur(${t.desfoque * Je(n)}px)`), aa(a, r);
1717
- for (const s of t.partes)
1718
- T(s.caminho) && (a.beginPath(), pa(a, s.caminho), a.globalAlpha = t.opacidade * o, s.modo === "encher" ? (a.fillStyle = t.cor, Mt(a, s.regra)) : (a.strokeStyle = t.cor, a.lineWidth = s.largura, a.lineCap = s.terminacao, a.lineJoin = s.juncao, a.setLineDash(s.tracejado), a.stroke()));
1719
- t.texto && typeof a.fillText == "function" && Xn(a, t.texto, r, t.cor, t.opacidade * o), i && (a.filter = "none"), a.restore(), e.sombras++;
1720
- }
1721
- function Ke(a, t, n, o, e) {
1722
- const r = t.gradiente, i = r ? We(r.def, e) : null;
1723
- if (!r || !i) return !1;
1724
- a.save(), xt(a, t.regra), aa(a, ua(n, r.quadro));
1725
- for (const s of i) {
1726
- a.beginPath(), a.moveTo(s.pontos[0][0], s.pontos[0][1]);
1727
- for (let c = 1; c < 4; c++) a.lineTo(s.pontos[c][0], s.pontos[c][1]);
1728
- a.closePath(), a.fillStyle = s.cor, a.globalAlpha = t.opacidade * o * s.opacidade, a.fill();
1729
- }
1730
- return a.restore(), !0;
1731
- }
1732
- function ar(a, t, n, o, e = 0) {
1733
- const r = t.opacidade;
1734
- a.save(), aa(a, n), t.recorte && T(t.recorte.caminho) && (a.beginPath(), pa(a, t.recorte.caminho), xt(a, t.recorte.regra)), t.mesclagem && (typeof a.globalCompositeOperation == "string" ? a.globalCompositeOperation = t.mesclagem : o.degradacoes.mesclagem = (o.degradacoes.mesclagem ?? 0) + 1), t.sombra && (Qe(a, t.sombra, n, r, o), aa(a, n));
1735
- const i = t.preenchimento;
1736
- if (i && T(i.caminho)) {
1737
- a.beginPath(), pa(a, i.caminho);
1738
- const f = i.gradiente ? Ze(a, i) : null;
1739
- f && i.gradiente ? (aa(a, ua(n, i.gradiente.quadro)), a.fillStyle = f, a.globalAlpha = i.opacidade * r, Mt(a, i.regra), aa(a, n), o.gradientes++) : i.gradiente && e > 0 && Ke(a, i, n, t.opacidade, e) ? o.gradientesEmFaixas = (o.gradientesEmFaixas ?? 0) + 1 : (i.gradiente && o.degradacoes.gradiente++, a.fillStyle = i.cor, a.globalAlpha = i.opacidade * r * (i.gradiente ? i.gradiente.opacidadeDegradacao : 1), Mt(a, i.regra)), o.preenchimentos++;
1740
- }
1741
- const s = t.hachura;
1742
- if (s && T(s.recorte)) {
1743
- a.save(), a.beginPath(), pa(a, s.recorte), xt(a, s.regra), a.beginPath();
1744
- for (const [f, d] of s.linhas)
1745
- a.moveTo(f[0], f[1]), a.lineTo(d[0], d[1]);
1746
- a.strokeStyle = s.cor, a.lineWidth = s.largura, a.lineCap = "butt", a.setLineDash([]), a.globalAlpha = s.opacidade * r, a.stroke(), a.restore(), o.hachuras++;
1747
- }
1748
- const c = t.traco;
1749
- c && T(c.caminho) && (a.beginPath(), pa(a, c.caminho), a.strokeStyle = c.cor, a.lineWidth = c.largura, a.lineCap = c.terminacao, a.lineJoin = c.juncao, a.miterLimit = c.limitePonta, a.setLineDash(c.tracejado), a.globalAlpha = c.opacidade * r, a.stroke(), o.tracos++);
1750
- for (const f of t.pontas)
1751
- T(f.caminho) && (a.beginPath(), pa(a, f.caminho), a.globalAlpha = f.opacidade * r, f.preenchida ? (a.fillStyle = f.cor, a.fill()) : (a.strokeStyle = f.cor, a.lineWidth = f.largura, a.lineJoin = "miter", a.setLineDash([]), a.stroke()), o.pontas++);
1752
- const u = t.texto;
1753
- u && (typeof a.fillText == "function" ? (Xn(a, u, n, u.cor, u.opacidade * r), o.textos++) : o.degradacoes.texto++), a.restore();
1754
- }
1755
- const dn = /* @__PURE__ */ new WeakMap();
1756
- function tr(a, t = {}) {
1757
- if (!Array.isArray(a)) return Object.freeze([]);
1758
- if (t.cache) {
1759
- const o = dn.get(a);
1760
- if (o && o.camadas === t.camadas) return o.plano;
1761
- }
1762
- let n;
1763
- try {
1764
- n = Object.freeze(Fn(a, t.camadas));
1765
- } catch {
1766
- n = Object.freeze([]);
1767
- }
1768
- return t.cache && dn.set(a, { camadas: t.camadas, plano: n }), n;
1769
- }
1770
- function hn(a, t) {
1771
- a.falhas++, a.primeiraFalha === void 0 && (a.primeiraFalha = t);
1772
- }
1773
- function nr(a, t, n = {}) {
1774
- const o = {
1775
- itens: 0,
1776
- preenchimentos: 0,
1777
- gradientes: 0,
1778
- hachuras: 0,
1779
- tracos: 0,
1780
- pontas: 0,
1781
- textos: 0,
1782
- sombras: 0,
1783
- degradacoes: { gradiente: 0, texto: 0 },
1784
- falhas: 0,
1785
- transformacao: "nenhuma"
1786
- };
1787
- if (!a) return o;
1788
- const e = Gn(a), r = n.transformacao === "relativa" && typeof a.transform == "function" ? "relativa" : n.transformacao === "absoluta" ? e === "absoluta" ? "absoluta" : "nenhuma" : e;
1789
- o.transformacao = r;
1790
- const i = Array.isArray(t) ? t : [], s = n.gradienteEmFaixas, c = s === !0 ? bt : typeof s == "number" && Number.isFinite(s) && s >= 2 ? Math.min(256, Math.round(s)) : 0;
1791
- if (r === "nenhuma")
1792
- return o.falhas = Math.max(1, i.length), o.primeiraFalha = "o contexto não tem setTransform nem transform: nada foi pintado", ln(`${o.primeiraFalha}. Implemente setTransform (absoluto) ou transform; veja diagnosticarContexto().`), o;
1793
- const u = r === "relativa" ? He(a) : a, f = n.matriz ? Aa(n.matriz) : ta, d = n.fundo;
1794
- if (d && [d.largura, d.altura].every((l) => Number.isFinite(l) && l > 0))
1795
- try {
1796
- u.save(), aa(u, f), u.globalAlpha = 1, u.fillStyle = z(d.cor, "#ffffff"), u.fillRect(0, 0, d.largura, d.altura), u.restore();
1797
- } catch (l) {
1798
- hn(o, l instanceof Error ? l.message : String(l));
1799
- try {
1800
- u.restore();
1801
- } catch {
1802
- }
1803
- }
1804
- for (const l of i)
1805
- try {
1806
- ar(u, l, f, o, c), o.itens++;
1807
- } catch (h) {
1808
- hn(o, h instanceof Error ? h.message : String(h));
1809
- try {
1810
- u.restore();
1811
- } catch {
1812
- }
1813
- }
1814
- return o.falhas > 0 && ln(`${o.falhas} falha(s) ao pintar; primeira: ${o.primeiraFalha}`), o;
1815
- }
1816
- function qi(a, t, n = {}) {
1817
- return nr(a, tr(t, { camadas: n.camadas }), n);
1818
- }
1819
- const ct = (a) => typeof a == "number" && Number.isFinite(a);
1820
- function or(a) {
1821
- const t = 10 ** a;
1822
- return (n) => {
1823
- const o = Math.round(n * t) / t;
1824
- return Object.is(o, -0) || o === 0 ? "0" : String(o);
1825
- };
1826
- }
1827
- const R = (a) => St(a);
1828
- function Q(a, t) {
1829
- let n = "";
1830
- for (const o of a)
1831
- o.c === "Z" ? n += "Z" : o.c === "C" ? n += `C${t(o.c1[0])} ${t(o.c1[1])} ${t(o.c2[0])} ${t(o.c2[1])} ${t(o.p[0])} ${t(o.p[1])}` : n += `${o.c}${t(o.p[0])} ${t(o.p[1])}`;
1832
- return n;
1833
- }
1834
- const Bn = (a, t) => `matrix(${[a.a, a.b, a.c, a.d, a.e, a.f].map(t).join(" ")})`, B = (a, t, n) => t < 1 ? ` ${a}="${n(Math.max(0, t))}"` : "";
1835
- function Un(a, t, n, o) {
1836
- const e = a.alinhamento === "center" ? "middle" : a.alinhamento === "right" ? "end" : "start", r = a.linhas.map((i, s) => `<tspan x="0" y="${o(s * a.tamanho * a.entrelinha)}">${St(i)}</tspan>`).join("");
1837
- return `<text transform="${Bn(a.matriz, o)}" font-size="${o(a.tamanho)}" font-family="${R(a.fonte)}" text-anchor="${e}" fill="${R(z(t, "#000000"))}" xml:space="preserve"${B("fill-opacity", n, o)}>${r}</text>`;
1838
- }
1839
- function er(a) {
1840
- let t = 1 / 0, n = 1 / 0, o = -1 / 0, e = -1 / 0;
1841
- for (const r of a) for (const i of r) {
1842
- if (i.c === "Z") continue;
1843
- const s = i.c === "C" ? [i.c1, i.c2, i.p] : [i.p];
1844
- for (const [c, u] of s)
1845
- c < t && (t = c), c > o && (o = c), u < n && (n = u), u > e && (e = u);
1846
- }
1847
- return Number.isFinite(t) ? [t, n, o, e] : null;
1848
- }
1849
- function rr(a, t, n, o) {
1850
- const e = R(z(a.cor, "#000000")), r = a.partes.filter((c) => T(c.caminho)).map((c) => c.modo === "encher" ? `<path d="${Q(c.caminho, t)}" fill="${e}" fill-rule="${c.regra}" stroke="none"/>` : `<path d="${Q(c.caminho, t)}" fill="none" stroke="${e}" stroke-width="${t(c.largura)}" stroke-linecap="${c.terminacao}" stroke-linejoin="${c.juncao}"${c.tracejado.length > 0 ? ` stroke-dasharray="${c.tracejado.map(t).join(" ")}"` : ""}/>`);
1851
- if (a.texto && r.push(Un(a.texto, a.cor, 1, t)), r.length === 0) return "";
1852
- let i = "";
1853
- const s = er(a.partes.map((c) => c.caminho));
1854
- if (a.desfoque > 0) {
1855
- const c = `pr-s${o.n++}`, u = a.desfoque * 3 + Math.max(0, ...a.partes.map((d) => d.largura)), f = s ? ` filterUnits="userSpaceOnUse" x="${t(s[0] - u)}" y="${t(s[1] - u)}" width="${t(s[2] - s[0] + 2 * u)}" height="${t(s[3] - s[1] + 2 * u)}"` : ' x="-50%" y="-50%" width="200%" height="200%"';
1856
- n.push(`<filter id="${c}"${f}><feGaussianBlur stdDeviation="${t(a.desfoque)}"/></filter>`), i = ` filter="url(#${c})"`;
1857
- }
1858
- return `<g transform="translate(${t(a.dx)} ${t(a.dy)})"${B("opacity", a.opacidade, t)}><g${i}>${r.join("")}</g></g>`;
1859
- }
1860
- function ir(a, t, n, o) {
1861
- const e = [];
1862
- a.sombra && e.push(rr(a.sombra, t, n, o));
1863
- const r = a.preenchimento;
1864
- if (r && T(r.caminho)) {
1865
- let d = R(z(r.cor, "#000000"));
1866
- if (r.gradiente) {
1867
- const l = `pr-g${o.n++}`, h = r.gradiente.def, m = h.paradas.map((y) => `<stop offset="${t(y.posicao)}" stop-color="${R(z(y.cor, "#000000"))}"${B("stop-opacity", y.opacidade ?? 1, t)}/>`).join(""), g = `id="${l}" gradientUnits="userSpaceOnUse" gradientTransform="${Bn(r.gradiente.quadro, t)}"`;
1868
- n.push(h.tipo === "linear" ? `<linearGradient ${g} x1="${t(h.de[0])}" y1="${t(h.de[1])}" x2="${t(h.ate[0])}" y2="${t(h.ate[1])}">${m}</linearGradient>` : `<radialGradient ${g} cx="${t(h.centro[0])}" cy="${t(h.centro[1])}" r="${t(h.raio)}" fx="${t((h.foco ?? h.centro)[0])}" fy="${t((h.foco ?? h.centro)[1])}">${m}</radialGradient>`), d = `url(#${l})`;
1869
- }
1870
- e.push(`<path d="${Q(r.caminho, t)}" fill="${d}" fill-rule="${r.regra}" stroke="none"${B("fill-opacity", r.opacidade, t)}/>`);
1871
- }
1872
- const i = a.hachura;
1873
- if (i && T(i.recorte)) {
1874
- const d = `pr-c${o.n++}`;
1875
- n.push(`<clipPath id="${d}"><path d="${Q(i.recorte, t)}" clip-rule="${i.regra}"/></clipPath>`);
1876
- const l = i.linhas.map(([h, m]) => `M${t(h[0])} ${t(h[1])}L${t(m[0])} ${t(m[1])}`).join("");
1877
- e.push(`<path d="${l}" clip-path="url(#${d})" fill="none" stroke="${R(z(i.cor, "#000000"))}" stroke-width="${t(i.largura)}" stroke-linecap="butt"${B("stroke-opacity", i.opacidade, t)}/>`);
1878
- }
1879
- const s = a.traco;
1880
- if (s && T(s.caminho)) {
1881
- const d = s.tracejado.length > 0 ? ` stroke-dasharray="${s.tracejado.map(t).join(" ")}"` : "";
1882
- e.push(`<path d="${Q(s.caminho, t)}" fill="none" stroke="${R(z(s.cor, "#000000"))}" stroke-width="${t(s.largura)}" stroke-linecap="${s.terminacao}" stroke-linejoin="${s.juncao}" stroke-miterlimit="${t(s.limitePonta)}"${d}${B("stroke-opacity", s.opacidade, t)}/>`);
1883
- }
1884
- for (const d of a.pontas) {
1885
- if (!T(d.caminho)) continue;
1886
- const l = R(z(d.cor, "#000000"));
1887
- e.push(d.preenchida ? `<path d="${Q(d.caminho, t)}" fill="${l}" stroke="none"${B("fill-opacity", d.opacidade, t)}/>` : `<path d="${Q(d.caminho, t)}" fill="none" stroke="${l}" stroke-width="${t(d.largura)}" stroke-linejoin="miter"${B("stroke-opacity", d.opacidade, t)}/>`);
1888
- }
1889
- const c = a.texto;
1890
- if (c && e.push(Un(c, c.cor, c.opacidade, t)), e.every((d) => d === "")) return "";
1891
- let u = "";
1892
- if (a.recorte && T(a.recorte.caminho)) {
1893
- const d = `pr-m${o.n++}`;
1894
- n.push(`<clipPath id="${d}"><path d="${Q(a.recorte.caminho, t)}" clip-rule="${a.recorte.regra}"/></clipPath>`), u = ` clip-path="url(#${d})"`;
1895
- }
1896
- const f = a.mesclagem && /^[a-z-]+$/.test(a.mesclagem) ? ` style="mix-blend-mode:${a.mesclagem}"` : "";
1897
- return `<g data-id="${R(a.id)}"${B("opacity", a.opacidade, t)}${u}${f}>${e.join("")}</g>`;
1898
- }
1899
- function Di(a, t) {
1900
- const n = ct(t == null ? void 0 : t.casas) ? Math.min(8, Math.max(0, Math.round(t.casas))) : 4, o = or(n), e = ct(t == null ? void 0 : t.largura) && t.largura > 0 ? t.largura : 1, r = ct(t == null ? void 0 : t.altura) && t.altura > 0 ? t.altura : 1, i = [], s = { n: 0 }, c = [];
1901
- for (const l of Fn(a, t == null ? void 0 : t.camadas))
1902
- try {
1903
- c.push(ir(l, o, i, s));
1904
- } catch {
1905
- }
1906
- const u = t != null && t.titulo ? `<title>${St(t.titulo)}</title>` : "", f = t != null && t.fundo ? `<rect x="0" y="0" width="${o(e)}" height="${o(r)}" fill="${R(z(t.fundo, "#ffffff"))}"/>` : "", d = i.length > 0 ? `<defs>${i.join("")}</defs>` : "";
1907
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${o(e)}mm" height="${o(r)}mm" viewBox="0 0 ${o(e)} ${o(r)}">${u}${d}${f}${c.join("")}</svg>`;
1908
- }
1909
- const La = (a) => typeof a == "number" && Number.isFinite(a), mn = (a) => !!a && La(a.x) && La(a.y) && La(a.largura) && La(a.altura) && a.largura >= 0 && a.altura >= 0, pn = (a) => [a.x, a.x + a.largura / 2, a.x + a.largura], gn = (a) => [a.y, a.y + a.altura / 2, a.y + a.altura];
1910
- function yn(a, t, n, o) {
1911
- let e = null;
1912
- for (const r of t)
1913
- for (const i of n(r))
1914
- for (const s of a) {
1915
- const c = i - s;
1916
- Math.abs(c) <= o && (!e || Math.abs(c) < Math.abs(e.delta)) && (e = { delta: c, posicao: i, alvo: r });
1917
- }
1918
- return e;
1919
- }
1920
- function bn(a, t, n, o) {
1921
- const [e, r, i, s] = a === "vertical" ? [n.y, n.y + n.altura, o.y, o.y + o.altura] : [n.x, n.x + n.largura, o.x, o.x + o.largura], c = { orientacao: a, posicao: t, de: Math.min(e, i), ate: Math.max(r, s) };
1922
- return r < i ? c.distancia = i - r : s < e && (c.distancia = e - s), c;
1923
- }
1924
- function Oi(a, t, n) {
1925
- const o = { correcao: [0, 0], linhas: [] };
1926
- if (!mn(a) || !La(n) || n < 0 || !Array.isArray(t)) return o;
1927
- const e = t.filter(mn), r = yn(pn(a), e, pn, n), i = yn(gn(a), e, gn, n), s = (r == null ? void 0 : r.delta) ?? 0, c = (i == null ? void 0 : i.delta) ?? 0, u = { ...a, x: a.x + s, y: a.y + c }, f = [];
1928
- return r && f.push(bn("vertical", r.posicao, u, r.alvo)), i && f.push(bn("horizontal", i.posicao, u, i.alvo)), { correcao: [s, c], linhas: f };
1929
- }
1930
- const na = (a) => typeof a == "number" && Number.isFinite(a);
1931
- function Hn(a, t) {
1932
- const n = a.largura / 2, o = a.altura / 2;
1933
- return [
1934
- { c: [-n, -o], d: [1, 1] },
1935
- { c: [n, -o], d: [-1, 1] },
1936
- { c: [n, o], d: [-1, -1] },
1937
- { c: [-n, o], d: [1, -1] }
1938
- ][t];
1939
- }
1940
- const Za = (a) => {
1941
- var t;
1942
- return !!a && ((t = a.geometria) == null ? void 0 : t.tipo) === "retangulo" && na(a.geometria.largura) && na(a.geometria.altura) && a.geometria.largura > 0 && a.geometria.altura > 0;
1943
- };
1944
- function sr(a) {
1945
- const t = Math.sqrt(Math.abs(Va(E(a))));
1946
- return na(t) && t > 1e-9 ? t : 1;
1947
- }
1948
- function Vn(a) {
1949
- return Za(a) ? zn(a.geometria.largura, a.geometria.altura, a.geometria.raios) : null;
1950
- }
1951
- function wi(a, t) {
1952
- if (!Za(a) || a.bloqueado) return null;
1953
- const n = Vn(a), o = a.geometria, e = na(t) && t > 0 ? Math.min(t / sr(a), Math.min(o.largura, o.altura) / 2) : 0, r = E(a);
1954
- return [0, 1, 2, 3].map((i) => {
1955
- const { c: s, d: c } = Hn(o, i), u = Math.max(n[i], e);
1956
- return P(r, [s[0] + c[0] * u, s[1] + c[1] * u]);
1957
- });
1958
- }
1959
- function Ti(a, t, n) {
1960
- if (!Za(a) || !Number.isInteger(t) || t < 0 || t > 3 || !na(n == null ? void 0 : n[0]) || !na(n == null ? void 0 : n[1])) return null;
1961
- const o = la(E(a));
1962
- if (!o) return null;
1963
- const e = P(o, n), { c: r, d: i } = Hn(a.geometria, t);
1964
- return ((e[0] - r[0]) * i[0] + (e[1] - r[1]) * i[1]) / 2;
1965
- }
1966
- function Mn(a, t, n) {
1967
- if (!Za(a) || a.bloqueado || !na(n)) return null;
1968
- const o = a.geometria, e = Math.min(Math.max(0, n), Math.min(o.largura, o.altura) / 2), r = Vn(a), i = t === null ? [e, e, e, e] : r.map((c, u) => u === t ? e : c), s = i.some((c) => c > 0) ? { tipo: "retangulo", largura: o.largura, altura: o.altura, raios: i } : { tipo: "retangulo", largura: o.largura, altura: o.altura };
1969
- return { ...a, geometria: s };
1970
- }
1971
- function ki(a, t) {
1972
- if (typeof t == "number") return Mn(a, null, t);
1973
- if (!Array.isArray(t) || t.length !== 4 || !t.every(na)) return null;
1974
- let n = a;
1975
- for (let o = 0; o < 4 && n; o++) n = Mn(n, o, t[o]);
1976
- return n;
1977
- }
1978
- const Oa = (a) => typeof a == "number" && Number.isFinite(a);
1979
- function Ri(a, t) {
1980
- const n = new Set(t), o = new Set(a.filter((e) => n.has(e.id) && e.grupoId).map((e) => e.grupoId));
1981
- return a.filter((e) => n.has(e.id) || e.grupoId !== void 0 && o.has(e.grupoId)).map((e) => e.id);
1982
- }
1983
- const Yn = (a) => {
1984
- if (a.ordem === void 0) return a;
1985
- const { ordem: t, ...n } = a;
1986
- return n;
1987
- };
1988
- function Fi(a, t, n, o) {
1989
- const e = new Set(t), r = Pa(o), i = ka(a, r).map(Yn);
1990
- if (n === "frente" || n === "tras") {
1991
- const c = /* @__PURE__ */ new Map();
1992
- for (const f of i) {
1993
- const d = r.indice(f);
1994
- c.has(d) || c.set(d, []), c.get(d).push(f);
1995
- }
1996
- const u = [];
1997
- for (const f of [...c.keys()].sort((d, l) => d - l)) {
1998
- const d = c.get(f), l = d.filter((m) => e.has(m.id)), h = d.filter((m) => !e.has(m.id));
1999
- u.push(...n === "frente" ? [...h, ...l] : [...l, ...h]);
2000
- }
2001
- return u;
2002
- }
2003
- const s = [...i];
2004
- if (n === "avancar")
2005
- for (let c = s.length - 2; c >= 0; c--) {
2006
- if (!e.has(s[c].id)) continue;
2007
- const u = s.findIndex((d, l) => l > c && !e.has(d.id) && r.indice(d) === r.indice(s[c]));
2008
- if (u < 0) continue;
2009
- const [f] = s.splice(c, 1);
2010
- s.splice(u, 0, f);
2011
- }
2012
- else
2013
- for (let c = 1; c < s.length; c++) {
2014
- if (!e.has(s[c].id)) continue;
2015
- let u = -1;
2016
- for (let d = c - 1; d >= 0; d--) if (!e.has(s[d].id) && r.indice(s[d]) === r.indice(s[c])) {
2017
- u = d;
2018
- break;
2019
- }
2020
- if (u < 0) continue;
2021
- const [f] = s.splice(c, 1);
2022
- s.splice(u, 0, f);
2023
- }
2024
- return s;
2025
- }
2026
- function _i(a, t, n, o) {
2027
- const e = new Set(t);
2028
- if (e.size < 2 || typeof n != "string" || !n) return [...a];
2029
- const r = ka(a, o).map(Yn), i = r.filter((u) => e.has(u.id)).map((u) => ({ ...u, grupoId: n })), s = r.map((u) => e.has(u.id)).lastIndexOf(!0), c = [];
2030
- return r.forEach((u, f) => {
2031
- e.has(u.id) || c.push(u), f === s && c.push(...i);
2032
- }), c;
2033
- }
2034
- function Gi(a, t) {
2035
- const n = new Set(t), o = new Set(a.filter((e) => n.has(e.id) && e.grupoId).map((e) => e.grupoId));
2036
- return a.map((e) => {
2037
- if (!e.grupoId || !o.has(e.grupoId)) return e;
2038
- const { grupoId: r, ...i } = e;
2039
- return i;
2040
- });
2041
- }
2042
- function Wn(a) {
2043
- if (a.length === 0) return null;
2044
- const t = Math.min(...a.map((r) => r.x)), n = Math.min(...a.map((r) => r.y)), o = Math.max(...a.map((r) => r.x + r.largura)), e = Math.max(...a.map((r) => r.y + r.altura));
2045
- return [t, n, o, e].every(Oa) ? { x: t, y: n, largura: o - t, altura: e - n } : null;
2046
- }
2047
- function Zn(a) {
2048
- const t = /* @__PURE__ */ new Map();
2049
- for (const o of a) {
2050
- const e = o.grupoId ? `g\0${o.grupoId}` : `e\0${o.id}`;
2051
- t.has(e) || t.set(e, []), t.get(e).push(o);
2052
- }
2053
- const n = [];
2054
- for (const o of t.values()) {
2055
- const e = Wn(o.map(Ia).filter((r) => !!r));
2056
- e && n.push({ membros: o, caixa: e });
2057
- }
2058
- return n;
2059
- }
2060
- const vt = (a, t, n) => t === 0 && n === 0 ? [] : a.membros.filter((o) => !o.bloqueado).map((o) => Wa(o, q(t, n)));
2061
- function Xi(a, t, n = { tipo: "selecao" }) {
2062
- let o = Zn(a), e = null;
2063
- if ((n == null ? void 0 : n.tipo) === "caixa") {
2064
- const i = n.caixa;
2065
- e = i && [i.x, i.y, i.largura, i.altura].every(Oa) ? i : null;
2066
- } else if ((n == null ? void 0 : n.tipo) === "chave") {
2067
- const i = o.find((s) => s.membros.some((c) => c.id === n.id));
2068
- e = (i == null ? void 0 : i.caixa) ?? null, o = o.filter((s) => s !== i);
2069
- } else {
2070
- if (o.length < 2) return [];
2071
- e = Wn(o.map((i) => i.caixa));
2072
- }
2073
- if (!e) return [];
2074
- const r = [];
2075
- for (const i of o) {
2076
- const s = i.caixa;
2077
- let c = 0, u = 0;
2078
- switch (t) {
2079
- case "esquerda":
2080
- c = e.x - s.x;
2081
- break;
2082
- case "direita":
2083
- c = e.x + e.largura - (s.x + s.largura);
2084
- break;
2085
- case "centro-horizontal":
2086
- c = e.x + e.largura / 2 - (s.x + s.largura / 2);
2087
- break;
2088
- case "topo":
2089
- u = e.y - s.y;
2090
- break;
2091
- case "base":
2092
- u = e.y + e.altura - (s.y + s.altura);
2093
- break;
2094
- case "centro-vertical":
2095
- u = e.y + e.altura / 2 - (s.y + s.altura / 2);
2096
- break;
2097
- default:
2098
- return [];
2099
- }
2100
- r.push(...vt(i, c, u));
2101
- }
2102
- return r;
2103
- }
2104
- function Bi(a, t, n = "espacos", o) {
2105
- const e = t === "horizontal", r = Zn(a), i = Oa(o) && n === "espacos";
2106
- if (r.length < (i ? 2 : 3)) return [];
2107
- const s = (g) => e ? g.x : g.y, c = (g) => e ? g.largura : g.altura;
2108
- r.sort((g, y) => s(g.caixa) + c(g.caixa) / 2 - (s(y.caixa) + c(y.caixa) / 2));
2109
- const u = r[0].caixa, f = r[r.length - 1].caixa, d = [];
2110
- if (n === "centros") {
2111
- const g = s(u) + c(u) / 2, y = (s(f) + c(f) / 2 - g) / (r.length - 1);
2112
- return r.forEach((p, M) => {
2113
- const b = g + y * M - (s(p.caixa) + c(p.caixa) / 2);
2114
- d.push(...vt(p, e ? b : 0, e ? 0 : b));
2115
- }), d;
2116
- }
2117
- const l = r.reduce((g, y) => g + c(y.caixa), 0), h = i ? o : (s(f) + c(f) - s(u) - l) / (r.length - 1);
2118
- let m = s(u);
2119
- for (const g of r) {
2120
- const y = m - s(g.caixa);
2121
- d.push(...vt(g, e ? y : 0, e ? 0 : y)), m += c(g.caixa) + h;
2122
- }
2123
- return d;
2124
- }
2125
- function Ui(a, t, n = [0, 0]) {
2126
- var s;
2127
- const o = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map();
2128
- for (const c of a) o.set(c.id, t(((s = c.geometria) == null ? void 0 : s.tipo) ?? "elemento"));
2129
- const [r, i] = Oa(n == null ? void 0 : n[0]) && Oa(n == null ? void 0 : n[1]) ? n : [0, 0];
2130
- return a.map((c) => {
2131
- const u = JSON.parse(JSON.stringify(c));
2132
- return u.id = o.get(c.id), c.grupoId && (e.has(c.grupoId) || e.set(c.grupoId, t("grupo")), u.grupoId = e.get(c.grupoId)), c.recorteId && (o.has(c.recorteId) ? u.recorteId = o.get(c.recorteId) : delete u.recorteId), delete u.ordem, r === 0 && i === 0 ? u : Wa(u, q(r, i));
2133
- });
2134
- }
2135
- function Hi(a, t) {
2136
- return a.map((n) => {
2137
- if (!t) {
2138
- const { aparencia: o, ...e } = n;
2139
- return e;
2140
- }
2141
- return { ...n, aparencia: JSON.parse(JSON.stringify(t)) };
2142
- });
2143
- }
2144
- const sa = (a) => typeof a == "number" && Number.isFinite(a);
2145
- function oa(a, t, n = a.id) {
2146
- const { transformacao: o, pivo: e, ...r } = a;
2147
- return { ...r, id: n, geometria: { tipo: "caminho", geometria: t } };
2148
- }
2149
- function Vi(a, t = 0.01) {
2150
- const n = a.map((e) => ({ e, c: w(e) })).filter((e) => e.c && e.e.geometria.tipo !== "texto");
2151
- if (n.length < 2) return { motivo: "selecao-insuficiente" };
2152
- const o = sa(t) && t >= 0 ? t : 0.01;
2153
- if (n.every((e) => e.c.tipo === "LineString")) {
2154
- const e = n.flatMap((i) => {
2155
- const s = i.c;
2156
- return s.partes && s.partes.length > 1 ? s.partes : [s.coordenadas];
2157
- }), r = go(e, o, A);
2158
- return r ? { ok: oa(n[0].e, { tipo: "LineString", coordenadas: r }) } : { motivo: "sem-ligacao" };
2159
- }
2160
- if (n.length === 2 && n.every((e) => e.c.tipo === "Polygon")) {
2161
- const [e, r] = n.map((s) => s.c.aneis[0]), i = yo(e, r, o, A);
2162
- return i ? { ok: oa(n[0].e, { tipo: "Polygon", aneis: [i] }) } : { motivo: "sem-ligacao" };
2163
- }
2164
- return { motivo: "tipos-incompativeis" };
2165
- }
2166
- function Yi(a, t, n) {
2167
- const o = w(a), e = w(t);
2168
- if (!o || !e) return { motivo: "degenerado" };
2169
- if (o.tipo !== "Polygon" || a.geometria.tipo === "texto") return { motivo: "sem-forma-fechada" };
2170
- if (e.tipo !== "LineString") return { motivo: "tipos-incompativeis" };
2171
- const r = bo(o.aneis[0], e.coordenadas, A);
2172
- return r ? { ok: r.map((i) => oa(a, { tipo: "Polygon", aneis: [i] }, n("caminho"))) } : { motivo: "sem-intersecao" };
2173
- }
2174
- function Wi(a, t, n) {
2175
- var r;
2176
- const o = w(a);
2177
- if (!o || a.geometria.tipo === "texto") return { motivo: ((r = a.geometria) == null ? void 0 : r.tipo) === "texto" ? "texto" : "degenerado" };
2178
- if (!sa(t) || t === 0) return { motivo: "degenerado" };
2179
- const e = xa(o.tipo === "Polygon" ? { tipo: "Polygon", aneis: [o.aneis[0]] } : { tipo: "LineString", coordenadas: o.coordenadas }, t, A);
2180
- return e ? { ok: oa(a, { tipo: "Polygon", aneis: [e] }, n) } : { motivo: "degenerado" };
2181
- }
2182
- function Zi(a, t) {
2183
- var r;
2184
- const n = w(a);
2185
- if (!n || a.geometria.tipo === "texto") return { motivo: ((r = a.geometria) == null ? void 0 : r.tipo) === "texto" ? "texto" : "degenerado" };
2186
- const o = sa(t) && t > 0 ? t : 0.1;
2187
- if (n.tipo === "Polygon") return { ok: oa(a, { tipo: "Polygon", aneis: n.aneis.map((i) => zo(i, o, 1)) }) };
2188
- const e = (n.partes && n.partes.length > 1 ? n.partes : [n.coordenadas]).map((i) => Lo(i, o, 1));
2189
- return { ok: oa(a, e.length > 1 ? { tipo: "LineString", coordenadas: e[0], partes: e } : { tipo: "LineString", coordenadas: e[0] }) };
2190
- }
2191
- function Ji(a) {
2192
- var i;
2193
- const t = w(a), n = Ta(a).traco;
2194
- if (!t || a.geometria.tipo === "texto") return { motivo: ((i = a.geometria) == null ? void 0 : i.tipo) === "texto" ? "texto" : "degenerado" };
2195
- if (!n) return { motivo: "degenerado" };
2196
- const o = n.largura / 2;
2197
- let e = null;
2198
- if (t.tipo === "LineString") {
2199
- const s = xa({ tipo: "LineString", coordenadas: t.coordenadas }, o, A);
2200
- e = s ? { tipo: "Polygon", aneis: [s] } : null;
2201
- } else {
2202
- const s = xa({ tipo: "Polygon", aneis: [t.aneis[0]] }, o, A), c = xa({ tipo: "Polygon", aneis: [t.aneis[0]] }, -o, A);
2203
- e = s ? { tipo: "Polygon", aneis: c ? [s, c] : [s] } : null;
2204
- }
2205
- if (!e) return { motivo: "degenerado" };
2206
- const r = oa(a, e);
2207
- return r.aparencia = { ...a.aparencia ?? {}, traco: null, preenchimento: { cor: n.cor, opacidade: n.opacidade, regra: "evenodd" }, hachura: null }, { ok: r };
2208
- }
2209
- function Qi(a, t, n, o) {
2210
- const e = new Set(t), r = ka(a.filter((s) => e.has(s.id)), o);
2211
- if (r.length < 2) return { motivo: "selecao-insuficiente" };
2212
- const i = [...r].reverse().find((s) => {
2213
- var c;
2214
- return s.geometria.tipo !== "texto" && ((c = w(s)) == null ? void 0 : c.tipo) === "Polygon";
2215
- });
2216
- return i ? {
2217
- ok: a.map((s) => s.id === i.id ? { ...s, mascara: !0, grupoId: n } : e.has(s.id) ? { ...s, recorteId: i.id, grupoId: n } : s)
2218
- } : { motivo: "sem-forma-fechada" };
2219
- }
2220
- function Ki(a, t) {
2221
- const n = new Set(t), o = new Set(a.filter((r) => n.has(r.id) && r.grupoId).map((r) => r.grupoId)), e = new Set(a.filter((r) => r.mascara && (n.has(r.id) || r.grupoId && o.has(r.grupoId))).map((r) => r.id));
2222
- return e.size === 0 ? [...a] : a.map((r) => {
2223
- if (e.has(r.id)) {
2224
- const { mascara: i, ...s } = r;
2225
- return s;
2226
- }
2227
- if (r.recorteId && e.has(r.recorteId)) {
2228
- const { recorteId: i, ...s } = r;
2229
- return s;
2230
- }
2231
- return r;
2232
- });
2233
- }
2234
- function as(a, t, n) {
2235
- const o = a != null && a.geometria && a.geometria.tipo !== "texto" ? wa(a.geometria) : null, e = o ? $t(o) : null;
2236
- if (!e || !sa(t == null ? void 0 : t[0]) || !sa(t == null ? void 0 : t[1])) return null;
2237
- const r = E(a);
2238
- let i = null;
2239
- return e.forEach((s, c) => {
2240
- const u = P(r, s.ponto), f = Math.hypot(u[0] - t[0], u[1] - t[1]);
2241
- f <= n && (!i || f < i.d) && (i = { i: c, d: f });
2242
- }), i ? i.i : null;
2243
- }
2244
- function ts(a, t, n) {
2245
- const o = a != null && a.geometria && a.geometria.tipo !== "texto" ? wa(a.geometria) : null, e = o ? $t(o) : null;
2246
- if (!o || !e || !sa(t == null ? void 0 : t[0]) || !sa(t == null ? void 0 : t[1])) return null;
2247
- const r = E(a);
2248
- let i = null;
2249
- for (const [s, c] of Mo(o)) {
2250
- const [u, f] = jo(e[s], e[c]);
2251
- let d = P(r, e[s].ponto);
2252
- for (let l = 1; l <= 16; l++) {
2253
- const h = P(r, Eo(e[s].ponto, u, f, e[c].ponto, l / 16)), m = lt(t[0], t[1], d[0], d[1], h[0], h[1]);
2254
- m <= n && (!i || m < i.d) && (i = { i: s, d: m }), d = h;
2255
- }
2256
- }
2257
- return i ? i.i : null;
2258
- }
2259
- class cr {
2260
- constructor(t, n, o) {
2261
- I(this, "celulas", /* @__PURE__ */ new Map());
2262
- I(this, "seq", 0);
2263
- this.q = t, this.x0 = n, this.y0 = o;
2264
- }
2265
- /** Hash da célula (colisões são inofensivas: a distância é conferida vértice a vértice). */
2266
- celula(t, n) {
2267
- return (Math.imul(t | 0, 73856093) ^ Math.imul(n | 0, 19349663)) >>> 0;
2268
- }
2269
- /** O vértice de `p`: um já registrado a até `q`, ou um novo. */
2270
- registrar(t, n) {
2271
- const o = Math.floor((t - this.x0) / this.q), e = Math.floor((n - this.y0) / this.q);
2272
- let r = null, i = this.q * this.q;
2273
- for (let f = -1; f <= 1; f++)
2274
- for (let d = -1; d <= 1; d++) {
2275
- const l = this.celulas.get(this.celula(o + f, e + d));
2276
- if (l)
2277
- for (const h of l) {
2278
- const m = (h.p[0] - t) ** 2 + (h.p[1] - n) ** 2;
2279
- m <= i && (i = m, r = h);
2280
- }
2281
- }
2282
- if (r) return r;
2283
- const s = { p: [t, n], id: this.seq++ }, c = this.celula(o, e), u = this.celulas.get(c);
2284
- return u ? u.push(s) : this.celulas.set(c, [s]), s;
2285
- }
2286
- }
2287
- const ur = (a) => Math.min(a.a.p[0], a.b.p[0]), lr = (a) => Math.max(a.a.p[0], a.b.p[0]), fr = (a) => Math.min(a.a.p[1], a.b.p[1]), dr = (a) => Math.max(a.a.p[1], a.b.p[1]);
2288
- function Ga(a, t, n) {
2289
- if (t.id === a.a.id || t.id === a.b.id) return 0;
2290
- const [o, e] = a.a.p, r = a.b.p[0] - o, i = a.b.p[1] - e, s = r * r + i * i;
2291
- if (!(s > 0)) return 0;
2292
- const c = ((t.p[0] - o) * r + (t.p[1] - e) * i) / s, u = n / Math.sqrt(s);
2293
- return c <= u || c >= 1 - u || Math.abs((t.p[0] - o) * i - (t.p[1] - e) * r) / Math.sqrt(s) > n ? 0 : (a.cortes.push(t), 1);
2294
- }
2295
- function hr(a, t, n, o) {
2296
- let e = Ga(a, t.a, o) + Ga(a, t.b, o) + Ga(t, a.a, o) + Ga(t, a.b, o);
2297
- const [r, i] = a.a.p, [s, c] = t.a.p, u = a.b.p[0] - r, f = a.b.p[1] - i, d = t.b.p[0] - s, l = t.b.p[1] - c, h = u * l - f * d, m = Math.hypot(u, f), g = Math.hypot(d, l);
2298
- if (!(Math.abs(h) > 1e-12 * m * g)) return e;
2299
- const y = ((s - r) * l - (c - i) * d) / h, p = ((s - r) * f - (c - i) * u) / h, M = o / m, b = o / g;
2300
- if (y <= M || y >= 1 - M || p <= b || p >= 1 - b) return e;
2301
- const x = n.registrar(r + y * u, i + y * f);
2302
- return x.id !== a.a.id && x.id !== a.b.id && (a.cortes.push(x), e++), x.id !== t.a.id && x.id !== t.b.id && (t.cortes.push(x), e++), e;
2303
- }
2304
- function mr(a, t, n) {
2305
- const o = a.length, e = new Float64Array(o), r = new Float64Array(o), i = new Float64Array(o), s = new Float64Array(o);
2306
- for (let l = 0; l < o; l++) {
2307
- const h = a[l];
2308
- e[l] = ur(h), r[l] = lr(h), i[l] = fr(h), s[l] = dr(h);
2309
- }
2310
- const c = Array.from({ length: o }, (l, h) => h).sort((l, h) => e[l] - e[h]), u = new Int32Array(o);
2311
- let f = 0, d = 0;
2312
- for (const l of c) {
2313
- const h = e[l] - n, m = i[l] - n, g = s[l] + n;
2314
- let y = 0;
2315
- for (let p = 0; p < f; p++) {
2316
- const M = u[p];
2317
- r[M] < h || (u[y++] = M, !(s[M] < m || i[M] > g) && (d += hr(a[l], a[M], t, n)));
2318
- }
2319
- f = y, u[f++] = l;
2320
- }
2321
- return d;
2322
- }
2323
- function pr(a) {
2324
- const t = /* @__PURE__ */ new Set(), n = [];
2325
- for (const o of a) {
2326
- const [e, r] = o.a.p, i = o.b.p[0] - e, s = o.b.p[1] - r, c = (f) => (f.p[0] - e) * i + (f.p[1] - r) * s, u = [o.a, ...[...o.cortes].sort((f, d) => c(f) - c(d)), o.b];
2327
- for (let f = 1; f < u.length; f++) {
2328
- const d = u[f - 1], l = u[f];
2329
- if (d.id === l.id) continue;
2330
- const h = d.id < l.id ? d.id * 67108864 + l.id : l.id * 67108864 + d.id;
2331
- t.has(h) || (t.add(h), n.push({ a: d, b: l }));
2332
- }
2333
- }
2334
- return n;
2335
- }
2336
- class Jn {
2337
- constructor(t, n, o) {
2338
- I(this, "coords");
2339
- I(this, "operandos");
2340
- I(this, "faixas");
2341
- I(this, "y0");
2342
- I(this, "altura");
2343
- I(this, "nf");
2344
- I(this, "maxX");
2345
- const e = t.length;
2346
- this.coords = new Float64Array(e * 4), this.operandos = new Int32Array(e), this.maxX = new Float64Array(e);
2347
- const r = Math.max(1, Math.min(4096, Math.ceil(e / 6)));
2348
- this.nf = r;
2349
- const i = Array.from({ length: r }, () => []);
2350
- this.y0 = n, this.altura = o > n ? (o - n) / r : 1, t.forEach((c, u) => {
2351
- this.maxX[u] = Math.max(c.a.p[0], c.b.p[0]), this.coords[u * 4] = c.a.p[0], this.coords[u * 4 + 1] = c.a.p[1], this.coords[u * 4 + 2] = c.b.p[0], this.coords[u * 4 + 3] = c.b.p[1], this.operandos[u] = c.operando;
2352
- const f = this.faixa(Math.min(c.a.p[1], c.b.p[1])), d = this.faixa(Math.max(c.a.p[1], c.b.p[1]));
2353
- for (let l = f; l <= d; l++) i[l].push(u);
2354
- });
2355
- const s = this.maxX;
2356
- this.faixas = i.map((c) => Int32Array.from(c.sort((u, f) => s[f] - s[u])));
2357
- }
2358
- faixa(t) {
2359
- const n = Math.floor((t - this.y0) / this.altura);
2360
- return n < 0 ? 0 : n >= this.nf ? this.nf - 1 : n;
2361
- }
2362
- /**
2363
- * Número de voltas de (x, y) em cada operando, em `v.voltas`; só os operandos com aresta cruzada pelo raio entram em
2364
- * `v.tocados` (os demais têm 0 voltas). A consulta zera só o que a anterior tocou.
2365
- */
2366
- voltas(t, n, o) {
2367
- const e = o.voltas;
2368
- for (let c = 0; c < o.n; c++) e[o.tocados[c]] = 0;
2369
- o.n = 0;
2370
- const r = this.coords, i = this.maxX, s = this.faixas[this.faixa(n)];
2371
- for (let c = 0; c < s.length; c++) {
2372
- const u = s[c];
2373
- if (i[u] < t) break;
2374
- const f = r[u * 4], d = r[u * 4 + 1], l = r[u * 4 + 2], h = r[u * 4 + 3];
2375
- let m = 0;
2376
- if (d <= n ? h > n && (l - f) * (n - d) - (t - f) * (h - d) > 0 && (m = 1) : h <= n && (l - f) * (n - d) - (t - f) * (h - d) < 0 && (m = -1), m === 0) continue;
2377
- const g = this.operandos[u];
2378
- o.marcado[g] || (o.marcado[g] = 1, o.tocados[o.n++] = g), e[g] += m;
2379
- }
2380
- for (let c = 0; c < o.n; c++) o.marcado[o.tocados[c]] = 0;
2381
- }
2382
- }
2383
- class At {
2384
- constructor(t) {
2385
- I(this, "voltas");
2386
- I(this, "tocados");
2387
- I(this, "marcado");
2388
- I(this, "n", 0);
2389
- this.voltas = new Int32Array(t), this.tocados = new Int32Array(t), this.marcado = new Uint8Array(t);
2390
- }
2391
- }
2392
- const gr = (a, t) => t === "evenodd" ? (a & 1) !== 0 : a !== 0;
2393
- function xn(a, t, n) {
2394
- let o = 0, e = !1;
2395
- for (let r = 0; r < t.n; r++) {
2396
- const i = t.tocados[r];
2397
- if (gr(t.voltas[i], n[i])) {
2398
- if (o++, i === 0 && (e = !0), a === "uniao") return !0;
2399
- if (a === "subtracao" && i !== 0) return !1;
2400
- }
2401
- }
2402
- return a === "uniao" ? !1 : a === "intersecao" ? n.length > 0 && o === n.length : a === "subtracao" ? e : (o & 1) === 1;
2403
- }
2404
- function ns(a, t, n) {
2405
- let o = !1;
2406
- for (let e = 0, r = n.length - 1; e < n.length; r = e++) {
2407
- const [i, s] = n[e], [c, u] = n[r];
2408
- s > t != u > t && a < (c - i) * (t - s) / (u - s) + i && (o = !o);
2409
- }
2410
- return o;
2411
- }
2412
- function yr(a) {
2413
- let t = a;
2414
- for (let n = 0; n < 4; n++) {
2415
- const o = t.length;
2416
- if (o < 3) return t;
2417
- const e = [];
2418
- for (let r = 0; r < o; r++) {
2419
- const i = e.length > 0 ? e[e.length - 1] : t[(r - 1 + o) % o], s = t[r], c = t[(r + 1) % o], u = s[0] - i[0], f = s[1] - i[1], d = c[0] - s[0], l = c[1] - s[1], h = u * l - f * d;
2420
- Math.abs(h) <= 1e-12 * Math.hypot(u, f) * Math.hypot(d, l) || e.push(s);
2421
- }
2422
- if (e.length === o) return e;
2423
- t = e;
2424
- }
2425
- return t;
2426
- }
2427
- function br(a) {
2428
- const t = /* @__PURE__ */ new Map();
2429
- a.forEach((r, i) => {
2430
- const s = t.get(r.a.id);
2431
- s ? s.push(i) : t.set(r.a.id, [i]);
2432
- });
2433
- const n = new Uint8Array(a.length), o = [];
2434
- let e = 0;
2435
- for (let r = 0; r < a.length; r++) {
2436
- if (n[r]) continue;
2437
- const i = a[r].a.id, s = [a[r].a.p];
2438
- let c = r, u = !1;
2439
- for (let f = 0; f <= a.length; f++) {
2440
- n[c] = 1;
2441
- const d = a[c];
2442
- if (d.b.id === i) {
2443
- u = !0;
2444
- break;
2445
- }
2446
- s.push(d.b.p);
2447
- const l = (t.get(d.b.id) ?? []).filter((h) => !n[h]);
2448
- if (l.length === 0) break;
2449
- c = l.length === 1 ? l[0] : Mr(d, l, a);
2450
- }
2451
- u && s.length >= 3 ? o.push(s) : e++;
2452
- }
2453
- return { aneis: o, descartadas: e };
2454
- }
2455
- function Mr(a, t, n) {
2456
- const o = a.b.p[0] - a.a.p[0], e = a.b.p[1] - a.a.p[1];
2457
- let r = t[0], i = -1 / 0;
2458
- for (const s of t) {
2459
- const c = n[s], u = c.b.p[0] - c.a.p[0], f = c.b.p[1] - c.a.p[1], d = Math.atan2(o * f - e * u, o * u + e * f);
2460
- d > i && (i = d, r = s);
2461
- }
2462
- return r;
2463
- }
2464
- function xr(a, t, n) {
2465
- const o = [], e = [];
2466
- for (const i of a) {
2467
- const s = yr(i);
2468
- if (s.length < 3) continue;
2469
- const c = qa(s);
2470
- Math.abs(c) <= t || (c > 0 ? o.push({ anel: s, area: c, poligono: { exterior: s, furos: [] } }) : e.push({ anel: s, area: -c }));
2471
- }
2472
- o.sort((i, s) => i.area - s.area);
2473
- let r = 0;
2474
- if (e.length > 0) {
2475
- let i = 1 / 0, s = -1 / 0;
2476
- const c = [];
2477
- o.forEach((d, l) => d.anel.forEach((h, m) => {
2478
- h[1] < i && (i = h[1]), h[1] > s && (s = h[1]), c.push({ a: { p: h }, b: { p: d.anel[(m + 1) % d.anel.length] }, operando: l });
2479
- }));
2480
- const u = new Jn(c, i, s), f = new At(o.length);
2481
- for (const d of e) {
2482
- const [l, h] = [d.anel[0], d.anel[1]], m = Math.hypot(h[0] - l[0], h[1] - l[1]) || 1, g = Math.min(n, m * 0.1);
2483
- u.voltas((l[0] + h[0]) / 2 + (h[1] - l[1]) / m * g, (l[1] + h[1]) / 2 - (h[0] - l[0]) / m * g, f);
2484
- let y = -1;
2485
- for (let p = 0; p < f.n; p++) {
2486
- const M = f.tocados[p];
2487
- f.voltas[M] !== 0 && o[M].area > d.area && (y < 0 || M < y) && (y = M);
2488
- }
2489
- y >= 0 ? o[y].poligono.furos.push(d.anel) : r++;
2490
- }
2491
- }
2492
- return { poligonos: o.map((i) => i.poligono), descartados: r };
2493
- }
2494
- const vr = ["uniao", "subtracao", "intersecao", "exclusao"], It = (a) => typeof a == "number" && Number.isFinite(a), vn = () => ({
2495
- poligonos: [],
2496
- estatisticas: { segmentos: 0, cortes: 0, pecas: 0, bordas: 0, aneis: 0, descartados: 0 }
2497
- });
2498
- function Ar(a) {
2499
- if (!Array.isArray(a)) return [];
2500
- const t = a.filter((n) => Array.isArray(n) && It(n[0]) && It(n[1]));
2501
- return t.length > 1 && t[0][0] === t[t.length - 1][0] && t[0][1] === t[t.length - 1][1] && t.pop(), t;
2502
- }
2503
- function Ir(a, t, n = {}) {
2504
- if (!Array.isArray(a) || !vr.includes(t)) return vn();
2505
- const o = a.map((v) => ({
2506
- aneis: (Array.isArray(v == null ? void 0 : v.aneis) ? v.aneis : []).map(Ar).filter((Y) => Y.length >= 3),
2507
- regra: (v == null ? void 0 : v.regra) === "evenodd" ? "evenodd" : "nonzero"
2508
- }));
2509
- let e = 1 / 0, r = 1 / 0, i = -1 / 0, s = -1 / 0;
2510
- for (const v of o) for (const Y of v.aneis) for (const [G, $] of Y)
2511
- G < e && (e = G), G > i && (i = G), $ < r && (r = $), $ > s && (s = $);
2512
- const c = Math.max(i - e, s - r);
2513
- if (!(c > 0) || !Number.isFinite(c)) return vn();
2514
- const u = It(n.tolerancia) ? Math.min(1e-3, Math.max(1e-12, n.tolerancia)) : 1e-9, f = c * u, d = f * 2, l = new cr(f, e, r), h = [];
2515
- o.forEach((v, Y) => {
2516
- for (const G of v.aneis) {
2517
- const $ = G.map(([k, ra]) => l.registrar(k, ra)).filter((k, ra, Fa) => ra === 0 || k.id !== Fa[ra - 1].id);
2518
- if ($.length > 1 && $[0].id === $[$.length - 1].id && $.pop(), !($.length < 3))
2519
- for (let k = 0; k < $.length; k++) h.push({ a: $[k], b: $[(k + 1) % $.length], operando: Y, cortes: [] });
2520
- }
2521
- });
2522
- const m = { segmentos: h.length, cortes: 0, pecas: 0, bordas: 0, aneis: 0, descartados: 0 };
2523
- if (h.length === 0) return { poligonos: [], estatisticas: m };
2524
- m.cortes = mr(h, l, d);
2525
- const g = pr(h);
2526
- m.pecas = g.length;
2527
- const y = new Jn(h, r, s), p = o.map((v) => v.regra), M = new At(o.length), b = new At(o.length), x = c * 1e-6, _ = [];
2528
- for (const v of g) {
2529
- const Y = v.b.p[0] - v.a.p[0], G = v.b.p[1] - v.a.p[1], $ = Math.hypot(Y, G);
2530
- if (!($ > 0)) continue;
2531
- const k = Math.min(x, $ * 0.1), ra = (v.a.p[0] + v.b.p[0]) / 2, Fa = (v.a.p[1] + v.b.p[1]) / 2, Ft = -G / $ * k, _t = Y / $ * k;
2532
- y.voltas(ra + Ft, Fa + _t, M), y.voltas(ra - Ft, Fa - _t, b);
2533
- const Gt = xn(t, M, p), ao = xn(t, b, p);
2534
- Gt !== ao && _.push(Gt ? { a: v.a, b: v.b } : { a: v.b, b: v.a });
2535
- }
2536
- m.bordas = _.length;
2537
- const { aneis: da, descartadas: Ja } = br(_);
2538
- m.aneis = da.length;
2539
- const { poligonos: Qn, descartados: Kn } = xr(da, f * f, x);
2540
- return m.descartados = Ja + Kn, { poligonos: Qn.map(Pr), estatisticas: m };
2541
- }
2542
- const Pr = (a) => ({
2543
- exterior: a.exterior.map(([t, n]) => [t, n]),
2544
- furos: a.furos.map((t) => t.map(([n, o]) => [n, o]))
2545
- });
2546
- function os(a) {
2547
- let t = 0;
2548
- for (const n of a ?? []) {
2549
- t += Math.abs(qa(n.exterior));
2550
- for (const o of n.furos) t -= Math.abs(qa(o));
2551
- }
2552
- return t;
2553
- }
2554
- function $r(a) {
2555
- var e, r, i;
2556
- if (!a || typeof a != "object" || a.mascara || ((e = a.geometria) == null ? void 0 : e.tipo) === "texto" || ((r = a.geometria) == null ? void 0 : r.tipo) === "linha") return null;
2557
- const t = w(a);
2558
- if (!t) return null;
2559
- if (t.tipo === "Polygon") {
2560
- const s = t.curva && t.aneis.length === 1 ? [va(t.curva, !0)] : t.aneis, c = ((i = Ta(a).preenchimento) == null ? void 0 : i.regra) ?? (s.length > 1 ? "evenodd" : "nonzero");
2561
- return { aneis: s, regra: c };
2562
- }
2563
- const o = (t.partes && t.partes.length > 1 ? t.partes : [t.curva ? va(t.curva, !1) : t.coordenadas]).filter((s) => s.length >= 3);
2564
- return o.length > 0 ? { aneis: o, regra: "nonzero" } : null;
2565
- }
2566
- function es(a, t) {
2567
- const n = (Array.isArray(a) ? a : []).map((c) => ({ e: c, r: $r(c) })).filter((c) => c.r !== null);
2568
- if (n.length < 2) return { motivo: "selecao-insuficiente" };
2569
- const o = t === "subtracao" ? n[0].e : n[n.length - 1].e, { poligonos: e } = Ir(n.map((c) => c.r), t);
2570
- if (e.length === 0) return { motivo: t === "intersecao" ? "sem-intersecao" : "resultado-vazio" };
2571
- const r = e.flatMap((c) => [c.exterior, ...c.furos]), i = oa(o, { tipo: "Polygon", aneis: r }), s = o.aparencia ?? {};
2572
- return s.preenchimento && r.length > 1 && (i.aparencia = { ...s, preenchimento: { ...s.preenchimento, regra: "evenodd" } }), { ok: { resultado: i, usados: n.map((c) => c.e.id) } };
2573
- }
2574
- const Sr = [
2575
- "elemento.nome",
2576
- "elemento.bloqueado",
2577
- "elemento.oculto",
2578
- "geometria.x",
2579
- "geometria.y",
2580
- "geometria.largura",
2581
- "geometria.altura",
2582
- "geometria.rotacao",
2583
- "geometria.raio",
2584
- "traco.ativo",
2585
- "traco.cor",
2586
- "traco.espessura",
2587
- "traco.opacidade",
2588
- "traco.tipoLinha",
2589
- "traco.escalaTipoLinha",
2590
- "traco.terminacao",
2591
- "traco.juncao",
2592
- "traco.alinhamento",
2593
- "traco.pontaInicio",
2594
- "traco.pontaFim",
2595
- "preenchimento.ativo",
2596
- "preenchimento.cor",
2597
- "preenchimento.opacidade",
2598
- "preenchimento.regra",
2599
- "hachura.ativa",
2600
- "hachura.angulo",
2601
- "hachura.espacamento",
2602
- "hachura.cor",
2603
- "hachura.cruzada",
2604
- "efeitos.opacidade",
2605
- "efeitos.mesclagem",
2606
- "sombra.ativa",
2607
- "sombra.dx",
2608
- "sombra.dy",
2609
- "sombra.desfoque",
2610
- "sombra.cor",
2611
- "sombra.opacidade"
2612
- ], jr = (a) => typeof a == "string" && Sr.includes(a), Er = (a) => a.startsWith("geometria."), Pt = (a) => typeof a == "number" && Number.isFinite(a), X = (a) => Math.round(a * 1e6) / 1e6;
2613
- function zr(a) {
2614
- const t = a.transformacao;
2615
- return t && Pt(t.a) && Pt(t.b) ? X(Math.atan2(t.b, t.a) * 180 / Math.PI) : 0;
2616
- }
2617
- function rs(a, t) {
2618
- var n, o, e, r, i, s, c, u, f, d, l, h, m, g, y;
2619
- if (!(!a || typeof a != "object" || !a.geometria))
2620
- try {
2621
- const p = a.aparencia ?? {}, M = ht(a), b = p.traco ?? void 0, x = t.startsWith("geometria.") ? Ia(a) : null;
2622
- switch (t) {
2623
- case "elemento.nome":
2624
- return a.nome ?? "";
2625
- case "elemento.bloqueado":
2626
- return a.bloqueado === !0;
2627
- case "elemento.oculto":
2628
- return a.oculto === !0;
2629
- case "geometria.x":
2630
- return x ? X(x.x) : void 0;
2631
- case "geometria.y":
2632
- return x ? X(x.y) : void 0;
2633
- case "geometria.largura":
2634
- return x ? X(x.largura) : void 0;
2635
- case "geometria.altura":
2636
- return x ? X(x.altura) : void 0;
2637
- case "geometria.rotacao":
2638
- return zr(a);
2639
- case "geometria.raio": {
2640
- if (a.geometria.tipo !== "retangulo") return;
2641
- const da = a.geometria.raios ?? [0, 0, 0, 0];
2642
- return da.every((Ja) => Ja === da[0]) ? da[0] : null;
2643
- }
2644
- case "traco.ativo":
2645
- return M.traco !== null;
2646
- case "traco.cor":
2647
- return ((n = M.traco) == null ? void 0 : n.cor) ?? (b == null ? void 0 : b.cor) ?? "#000000";
2648
- case "traco.espessura":
2649
- return ((o = M.traco) == null ? void 0 : o.largura) ?? (b == null ? void 0 : b.espessura) ?? 0.25;
2650
- case "traco.opacidade":
2651
- return X((((e = M.traco) == null ? void 0 : e.opacidade) ?? (b == null ? void 0 : b.opacidade) ?? 1) * 100);
2652
- case "traco.tipoLinha":
2653
- return (b == null ? void 0 : b.tipoLinha) ?? "continua";
2654
- case "traco.escalaTipoLinha":
2655
- return (b == null ? void 0 : b.escalaTipoLinha) ?? 1;
2656
- case "traco.terminacao":
2657
- return (b == null ? void 0 : b.terminacao) ?? "reta";
2658
- case "traco.juncao":
2659
- return (b == null ? void 0 : b.juncao) ?? "angular";
2660
- case "traco.alinhamento":
2661
- return (b == null ? void 0 : b.alinhamento) ?? "centro";
2662
- case "traco.pontaInicio":
2663
- return ((r = b == null ? void 0 : b.pontaInicio) == null ? void 0 : r.estilo) ?? "nenhuma";
2664
- case "traco.pontaFim":
2665
- return ((i = b == null ? void 0 : b.pontaFim) == null ? void 0 : i.estilo) ?? "nenhuma";
2666
- case "preenchimento.ativo":
2667
- return M.preenchimento !== null;
2668
- case "preenchimento.cor":
2669
- return ((s = M.preenchimento) == null ? void 0 : s.cor) ?? ((c = p.preenchimento) == null ? void 0 : c.cor) ?? "#ffffff";
2670
- case "preenchimento.opacidade":
2671
- return X((((u = M.preenchimento) == null ? void 0 : u.opacidade) ?? 1) * 100);
2672
- case "preenchimento.regra":
2673
- return ((f = M.preenchimento) == null ? void 0 : f.regra) ?? ((d = p.preenchimento) == null ? void 0 : d.regra) ?? "nonzero";
2674
- case "hachura.ativa":
2675
- return !!p.hachura;
2676
- case "hachura.angulo":
2677
- return ((l = p.hachura) == null ? void 0 : l.angulo) ?? 45;
2678
- case "hachura.espacamento":
2679
- return ((h = p.hachura) == null ? void 0 : h.espacamento) ?? 2;
2680
- case "hachura.cor":
2681
- return ((m = M.hachura) == null ? void 0 : m.cor) ?? ((g = p.hachura) == null ? void 0 : g.cor) ?? "#000000";
2682
- case "hachura.cruzada":
2683
- return ((y = p.hachura) == null ? void 0 : y.cruzada) === !0;
2684
- case "efeitos.opacidade":
2685
- return X(M.opacidade * 100);
2686
- case "efeitos.mesclagem":
2687
- return p.mesclagem ?? "normal";
2688
- case "sombra.ativa":
2689
- return !!p.sombra;
2690
- }
2691
- const _ = Dt(p.sombra ?? {}) ?? { dx: 1.5, dy: 1.5, desfoque: 1, cor: "#000000", opacidade: 0 };
2692
- switch (t) {
2693
- case "sombra.dx":
2694
- return _.dx;
2695
- case "sombra.dy":
2696
- return _.dy;
2697
- case "sombra.desfoque":
2698
- return _.desfoque;
2699
- case "sombra.cor":
2700
- return _.cor;
2701
- case "sombra.opacidade":
2702
- return X(_.opacidade * 100);
2703
- }
2704
- } catch {
2705
- return;
2706
- }
2707
- }
2708
- const Lr = (a) => {
2709
- const t = typeof a == "string" && a.trim() !== "" ? Number(a.replace(",", ".")) : a;
2710
- return Pt(t) ? t : null;
2711
- }, Nr = (a) => typeof a == "string" ? a : null, Cr = (a) => typeof a == "boolean" ? a : a === "true" ? !0 : a === "false" ? !1 : null;
2712
- function J(a) {
2713
- return a && typeof a == "object" ? { ...a } : {};
2714
- }
2715
- function is(a, t, n) {
2716
- if (!a || typeof a != "object" || !jr(t) || Er(t)) return null;
2717
- const o = { ...a.aparencia ?? {} }, e = { ...a }, [r, i] = t.split("."), s = Lr(n), c = Cr(n), u = Nr(n), f = s === null ? null : Math.min(1, Math.max(0, s / 100));
2718
- if (r === "elemento")
2719
- if (i === "nome") {
2720
- if (u === null) return null;
2721
- u.trim() === "" ? delete e.nome : e.nome = u;
2722
- } else {
2723
- if (c === null) return null;
2724
- c ? e[i] = !0 : delete e[i];
2725
- }
2726
- else if (r === "traco")
2727
- if (i === "ativo") {
2728
- if (c === null) return null;
2729
- o.traco = c ? J(o.traco) : null;
2730
- } else {
2731
- const l = J(o.traco);
2732
- if (i === "cor" && u !== null) l.cor = u;
2733
- else if (i === "espessura" && s !== null && s >= 0) l.espessura = s;
2734
- else if (i === "opacidade" && f !== null) l.opacidade = f;
2735
- else if (i === "escalaTipoLinha" && s !== null && s > 0) l.escalaTipoLinha = s;
2736
- else if (i === "tipoLinha" && u !== null) l.tipoLinha = u;
2737
- else if (i === "terminacao" && u !== null && ["reta", "arredondada", "quadrada"].includes(u)) l.terminacao = u;
2738
- else if (i === "juncao" && u !== null && ["angular", "arredondada", "chanfrada"].includes(u)) l.juncao = u;
2739
- else if (i === "alinhamento" && u !== null && ["centro", "dentro", "fora"].includes(u)) l.alinhamento = u;
2740
- else if ((i === "pontaInicio" || i === "pontaFim") && u !== null)
2741
- u === "nenhuma" ? delete l[i] : l[i] = { ...l[i] ?? {}, estilo: u };
2742
- else return null;
2743
- o.traco = l;
2744
- }
2745
- else if (r === "preenchimento")
2746
- if (i === "ativo") {
2747
- if (c === null) return null;
2748
- o.preenchimento = c ? { cor: "#ffffff", ...J(o.preenchimento) } : null;
2749
- } else {
2750
- const l = J(o.preenchimento);
2751
- if (i === "cor" && u !== null)
2752
- l.cor = u, delete l.gradiente;
2753
- else if (i === "opacidade" && f !== null) l.opacidade = f;
2754
- else if (i === "regra" && (u === "nonzero" || u === "evenodd")) l.regra = u;
2755
- else return null;
2756
- o.preenchimento = l;
2757
- }
2758
- else if (r === "hachura")
2759
- if (i === "ativa") {
2760
- if (c === null) return null;
2761
- o.hachura = c ? J(o.hachura) : null;
2762
- } else {
2763
- const l = J(o.hachura);
2764
- if (i === "angulo" && s !== null) l.angulo = s;
2765
- else if (i === "espacamento" && s !== null && s > 0) l.espacamento = s;
2766
- else if (i === "cor" && u !== null) l.cor = u;
2767
- else if (i === "cruzada" && c !== null) l.cruzada = c;
2768
- else return null;
2769
- o.hachura = l;
2770
- }
2771
- else if (r === "efeitos")
2772
- if (i === "opacidade" && f !== null) o.opacidade = f;
2773
- else if (i === "mesclagem" && u !== null && Nn.includes(u))
2774
- u === "normal" ? delete o.mesclagem : o.mesclagem = u;
2775
- else return null;
2776
- else if (r === "sombra")
2777
- if (i === "ativa") {
2778
- if (c === null) return null;
2779
- o.sombra = c ? J(o.sombra) : null;
2780
- } else {
2781
- const l = J(o.sombra), h = Dt({ ...l, opacidade: 1 });
2782
- if (i === "dx" && s !== null) l.deslocamento = [s, h.dy];
2783
- else if (i === "dy" && s !== null) l.deslocamento = [h.dx, s];
2784
- else if (i === "desfoque" && s !== null && s >= 0) l.desfoque = s;
2785
- else if (i === "cor" && u !== null) l.cor = u;
2786
- else if (i === "opacidade" && f !== null) l.opacidade = f;
2787
- else return null;
2788
- o.sombra = l;
2789
- }
2790
- else return null;
2791
- return r !== "elemento" && (e.aparencia = o), ye(e) ?? null;
2792
- }
2793
- const ut = (a) => typeof a == "number" && Number.isFinite(a);
2794
- class ss {
2795
- constructor(t = {}) {
2796
- I(this, "desfazeres", []);
2797
- I(this, "refazeres", []);
2798
- I(this, "limite");
2799
- I(this, "janela");
2800
- I(this, "ultimaChave", null);
2801
- I(this, "ultimoInstante", -1 / 0);
2802
- this.limite = ut(t.limite) && t.limite >= 1 ? Math.floor(t.limite) : 100, this.janela = ut(t.janelaRajadaMs) && t.janelaRajadaMs >= 0 ? t.janelaRajadaMs : 1e3;
2803
- }
2804
- get podeDesfazer() {
2805
- return this.desfazeres.length > 0;
2806
- }
2807
- get podeRefazer() {
2808
- return this.refazeres.length > 0;
2809
- }
2810
- get passos() {
2811
- return this.desfazeres.length;
2812
- }
2813
- /**
2814
- * Registra uma mudança: `antes` é o estado anterior a ela. Devolve `true` se abriu um passo novo e `false` se a mudança
2815
- * entrou na rajada do passo anterior. Qualquer registro apaga o que havia para refazer.
2816
- */
2817
- registrar(t, n = {}) {
2818
- const o = ut(n.agora) ? n.agora : Date.now(), e = typeof n.chave == "string" && n.chave ? n.chave : null, r = e !== null && e === this.ultimaChave && o - this.ultimoInstante <= this.janela && o >= this.ultimoInstante && this.desfazeres.length > 0;
2819
- return this.refazeres = [], this.ultimaChave = e, this.ultimoInstante = o, r ? !1 : (this.desfazeres.push(t), this.desfazeres.length > this.limite && this.desfazeres.splice(0, this.desfazeres.length - this.limite), !0);
2820
- }
2821
- /** Volta um passo: recebe o estado atual (que vai para o refazer) e devolve o anterior, ou `null` se não há. */
2822
- desfazer(t) {
2823
- const n = this.desfazeres.pop();
2824
- return n === void 0 ? null : (this.refazeres.push(t), this.encerrarRajada(), n);
2825
- }
2826
- /** Refaz um passo: recebe o estado atual (que volta para o desfazer) e devolve o seguinte, ou `null` se não há. */
2827
- refazer(t) {
2828
- const n = this.refazeres.pop();
2829
- return n === void 0 ? null : (this.desfazeres.push(t), this.encerrarRajada(), n);
2830
- }
2831
- /** Fecha a rajada em andamento: a próxima mudança, mesmo com a mesma chave, abre um passo novo. */
2832
- encerrarRajada() {
2833
- this.ultimaChave = null, this.ultimoInstante = -1 / 0;
2834
- }
2835
- /**
2836
- * Reescreve todos os estados guardados (desfazer e refazer) com `fn`. Serve para trocar uma referência estável em todo o
2837
- * histórico (ex.: o app troca o id provisório de um elemento) sem perder os passos.
2838
- */
2839
- transformar(t) {
2840
- this.desfazeres = this.desfazeres.map(t), this.refazeres = this.refazeres.map(t);
2841
- }
2842
- limpar() {
2843
- this.desfazeres = [], this.refazeres = [], this.encerrarRajada();
2844
- }
2845
- }
2846
- export {
2847
- Jo as $,
2848
- be as A,
2849
- Hi as B,
2850
- Na as C,
2851
- qe as D,
2852
- Sn as E,
2853
- Ve as F,
2854
- es as G,
2855
- ss as H,
2856
- ta as I,
2857
- Xr as J,
2858
- ga as K,
2859
- ae as L,
2860
- en as M,
2861
- Gr as N,
2862
- vr as O,
2863
- Ee as P,
2864
- qa as Q,
2865
- Ne as R,
2866
- ot as S,
2867
- ze as T,
2868
- os as U,
2869
- ln as V,
2870
- pi as W,
2871
- Me as X,
2872
- Zr as Y,
2873
- Oe as Z,
2874
- zi as _,
2875
- rt as a,
2876
- si as a$,
2877
- Ot as a0,
2878
- wt as a1,
2879
- Tn as a2,
2880
- T as a3,
2881
- Q as a4,
2882
- Dn as a5,
2883
- Ut as a6,
2884
- is as a7,
2885
- Mn as a8,
2886
- oa as a9,
2887
- Gi as aA,
2888
- qi as aB,
2889
- nr as aC,
2890
- Wi as aD,
2891
- Va as aE,
2892
- Ni as aF,
2893
- ke as aG,
2894
- Bi as aH,
2895
- Yi as aI,
2896
- Ui as aJ,
2897
- Yr as aK,
2898
- Fr as aL,
2899
- Da as aM,
2900
- Le as aN,
2901
- Er as aO,
2902
- jr as aP,
2903
- Do as aQ,
2904
- $n as aR,
2905
- fi as aS,
2906
- di as aT,
2907
- hi as aU,
2908
- Pe as aV,
2909
- zt as aW,
2910
- Ko as aX,
2911
- Li as aY,
2912
- Lt as aZ,
2913
- Oo as a_,
2914
- Et as aa,
2915
- we as ab,
2916
- Ji as ac,
2917
- Yo as ad,
2918
- Zo as ae,
2919
- wa as af,
2920
- Nt as ag,
2921
- w as ah,
2922
- Wo as ai,
2923
- Xo as aj,
2924
- Ii as ak,
2925
- gi as al,
2926
- re as am,
2927
- Ye as an,
2928
- Kr as ao,
2929
- Qt as ap,
2930
- Qr as aq,
2931
- Sa as ar,
2932
- Qi as as,
2933
- Jr as at,
2934
- _a as au,
2935
- ai as av,
2936
- kr as aw,
2937
- Br as ax,
2938
- Hr as ay,
2939
- ki as az,
2940
- A as b,
2941
- Vr as b$,
2942
- Ai as b0,
2943
- Ri as b1,
2944
- Di as b2,
2945
- We as b3,
2946
- kt as b4,
2947
- En as b5,
2948
- Te as b6,
2949
- ji as b7,
2950
- ci as b8,
2951
- Oi as b9,
2952
- me as bA,
2953
- Ir as bB,
2954
- ka as bC,
2955
- te as bD,
2956
- Tr as bE,
2957
- ii as bF,
2958
- tr as bG,
2959
- Ge as bH,
2960
- Fn as bI,
2961
- Rn as bJ,
2962
- ns as bK,
2963
- F as bL,
2964
- ti as bM,
2965
- Ti as bN,
2966
- zn as bO,
2967
- Vn as bP,
2968
- Ur as bQ,
2969
- Ci as bR,
2970
- $r as bS,
2971
- Fi as bT,
2972
- ht as bU,
2973
- Dt as bV,
2974
- jn as bW,
2975
- zr as bX,
2976
- oi as bY,
2977
- Aa as bZ,
2978
- Zi as b_,
2979
- _r as ba,
2980
- la as bb,
2981
- Ki as bc,
2982
- qt as bd,
2983
- Ia as be,
2984
- rn as bf,
2985
- Pa as bg,
2986
- wi as bh,
2987
- De as bi,
2988
- Rr as bj,
2989
- ei as bk,
2990
- ni as bl,
2991
- E as bm,
2992
- ve as bn,
2993
- Gn as bo,
2994
- Pi as bp,
2995
- Mi as bq,
2996
- xi as br,
2997
- ri as bs,
2998
- ua as bt,
2999
- pe as bu,
3000
- ui as bv,
3001
- ye as bw,
3002
- Wr as bx,
3003
- le as by,
3004
- he as bz,
3005
- li as c,
3006
- xe as c0,
3007
- Ie as c1,
3008
- Qo as c2,
3009
- Wa as c3,
3010
- On as c4,
3011
- q as c5,
3012
- ts as c6,
3013
- Vi as c7,
3014
- rs as c8,
3015
- Vo as c9,
3016
- Ln as d,
3017
- $i as e,
3018
- bt as f,
3019
- Ro as g,
3020
- Ei as h,
3021
- Sr as i,
3022
- Si as j,
3023
- mi as k,
3024
- dt as l,
3025
- Vt as m,
3026
- jt as n,
3027
- Nn as o,
3028
- Se as p,
3029
- He as q,
3030
- vi as r,
3031
- _i as s,
3032
- bi as t,
3033
- Xi as u,
3034
- Cn as v,
3035
- as as w,
3036
- yi as x,
3037
- Ta as y,
3038
- P as z
3039
- };