@thibezer/ui-components-kit 2.24.0 → 2.24.2

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 (150) hide show
  1. package/CHANGELOG.md +69 -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 +18 -0
  14. package/dist/components/ui-canvas-prancha/ui-canvas-prancha-base.d.ts +4 -0
  15. package/dist/components/ui-card/ui-card.d.ts +4 -0
  16. package/dist/components/ui-editor-prancha/editor-modos.d.ts +10 -0
  17. package/dist/components/ui-editor-prancha/editor-tipos.d.ts +4 -0
  18. package/dist/components/ui-editor-prancha/index.d.ts +1 -0
  19. package/dist/components/ui-editor-prancha/ui-editor-prancha.d.ts +39 -6
  20. package/dist/core.cjs +1 -1
  21. package/dist/core.js +44 -55
  22. package/dist/{cores-utils-BrdynxRd.js → cores-utils-DMyqWvZh.js} +2 -2
  23. package/dist/cores.cjs +32 -1
  24. package/dist/cores.js +300 -13
  25. package/dist/custom-elements.json +33962 -33439
  26. package/dist/data.cjs +28 -1
  27. package/dist/data.js +286 -99
  28. package/dist/{feature_caixa-2Sxv3tGa.js → feature_caixa-BVc5LenS.js} +42 -42
  29. package/dist/{feature_desenho-BVHivWIB.js → feature_desenho-CC8Mp5Gp.js} +2 -2
  30. package/dist/feedback.cjs +52 -1
  31. package/dist/feedback.js +655 -25
  32. package/dist/forms.cjs +66 -1
  33. package/dist/forms.js +1216 -39
  34. package/dist/{geometria-px-DUs5FgLE.js → geometria-px-DHMPUsxC.js} +47 -47
  35. package/dist/index.cjs +67 -1
  36. package/dist/index.js +1476 -274
  37. package/dist/kit-base-CGqj9aiD.cjs +2 -0
  38. package/dist/kit-base-_THn4w3u.js +1079 -0
  39. package/dist/mapa.cjs +5 -5
  40. package/dist/mapa.js +16 -17
  41. package/dist/modal.cjs +18 -1
  42. package/dist/modal.js +235 -29
  43. package/dist/motor.js +49 -49
  44. package/dist/prancha-nucleo.cjs +3 -1
  45. package/dist/prancha-nucleo.js +3120 -277
  46. package/dist/prancha.cjs +38 -1
  47. package/dist/prancha.js +3233 -228
  48. package/dist/register.cjs +1 -1
  49. package/dist/register.js +3 -20
  50. package/dist/seletor-mapa-base.cjs +13 -13
  51. package/dist/seletor-mapa-base.js +3 -5
  52. package/dist/tabela.cjs +142 -1
  53. package/dist/tabela.js +3773 -92
  54. package/dist/tipos-elementos.d.ts +5 -1
  55. package/dist/tipos-vue.d.ts +4 -1
  56. package/dist/tools.cjs +16 -1
  57. package/dist/tools.js +1564 -26
  58. package/dist/ui-seletor-cor-BGw8SBPm.cjs +83 -0
  59. package/dist/{ui-seletor-cor-Cd8jkzXG.js → ui-seletor-cor-B_twSm-V.js} +8 -9
  60. package/dist/utils-ClVgqVyJ.cjs +1 -0
  61. package/dist/utils-DrHoxxmf.js +83 -0
  62. package/package.json +43 -2
  63. package/dist/acessibilidade-CSzX-DkG.cjs +0 -1
  64. package/dist/acessibilidade-CUlSXc2X.js +0 -38
  65. package/dist/altura-controle-ukMRPckR.cjs +0 -1
  66. package/dist/altura-controle-vxQiXG4q.js +0 -62
  67. package/dist/alvo-digitavel-CzCvNVQ3.js +0 -23
  68. package/dist/alvo-digitavel-DbH0hYFf.cjs +0 -1
  69. package/dist/degrade-CIxvOTUv.cjs +0 -1
  70. package/dist/degrade-gDa5sW__.js +0 -119
  71. package/dist/feature_caixa-CnYPKVFS.cjs +0 -1
  72. package/dist/feature_caixa-DCs9ZeSk.js +0 -1038
  73. package/dist/feature_historico-BAIYk1Me.cjs +0 -3
  74. package/dist/feature_historico-C4h9y5fu.js +0 -3039
  75. package/dist/form-atalhos-7JTYvumA.cjs +0 -1
  76. package/dist/form-atalhos-DDTlpgaB.js +0 -203
  77. package/dist/form-erros-CwPz7Jr4.cjs +0 -1
  78. package/dist/form-erros-DT5HklfD.js +0 -184
  79. package/dist/form-submissao-C-SPRKgT.js +0 -61
  80. package/dist/form-submissao-DxKO5MHI.cjs +0 -1
  81. package/dist/form-validacao-BlQFxUVj.js +0 -104
  82. package/dist/form-validacao-DIeyQVH5.cjs +0 -1
  83. package/dist/geometria-px-DKrWq_XY.js +0 -639
  84. package/dist/leaflet-CEPcxGWV.cjs +0 -1
  85. package/dist/leaflet-DOq10gfg.js +0 -84
  86. package/dist/leaflet-loader-94z5VsdY.cjs +0 -2
  87. package/dist/leaflet-loader-Cjcdgj5R.js +0 -21
  88. package/dist/listener-bag-D5omxZ9h.cjs +0 -1
  89. package/dist/listener-bag-DQgv7OON.js +0 -34
  90. package/dist/motor-By2te6PZ.js +0 -1400
  91. package/dist/motor-CkMxd378.cjs +0 -1
  92. package/dist/opcoes-CupvWVIm.js +0 -24
  93. package/dist/opcoes-vdAUY5OI.cjs +0 -1
  94. package/dist/parts-CaoQiCfI.js +0 -7
  95. package/dist/parts-vQa2873h.cjs +0 -1
  96. package/dist/prancha-paleta-BZ-9QDgh.js +0 -5276
  97. package/dist/prancha-paleta-Bb24vP71.cjs +0 -17
  98. package/dist/ssr-safe-5cWfJP-s.js +0 -10
  99. package/dist/ssr-safe-CiHD1adl.cjs +0 -1
  100. package/dist/svg-seguro-ChVJ2L2z.js +0 -74
  101. package/dist/svg-seguro-J2RM1Ssf.cjs +0 -1
  102. package/dist/ui-badge-DE58YSBY.cjs +0 -28
  103. package/dist/ui-badge-KgmI3jOD.js +0 -201
  104. package/dist/ui-botao-Dz8YvmiA.cjs +0 -12
  105. package/dist/ui-botao-zLkcMMyP.js +0 -168
  106. package/dist/ui-bus-CUd99VJi.js +0 -177
  107. package/dist/ui-bus-XqBLlTYQ.cjs +0 -1
  108. package/dist/ui-camadas-DoHPnbQm.js +0 -3133
  109. package/dist/ui-camadas-Vx7wYD4D.cjs +0 -311
  110. package/dist/ui-campo-texto-Dliyt9qr.cjs +0 -16
  111. package/dist/ui-campo-texto-btevggO3.js +0 -379
  112. package/dist/ui-card-7IEYbCN0.js +0 -150
  113. package/dist/ui-card-Bx8EyzYY.cjs +0 -20
  114. package/dist/ui-card-DFnRp9bl.js +0 -146
  115. package/dist/ui-card-DrWVJQKw.cjs +0 -20
  116. package/dist/ui-controle-cores-B1w_Yl69.cjs +0 -32
  117. package/dist/ui-controle-cores-BRjMvmMn.js +0 -291
  118. package/dist/ui-controle-cores-BcH9k2Fa.js +0 -292
  119. package/dist/ui-controle-cores-CvSTP6gJ.cjs +0 -32
  120. package/dist/ui-editor-prancha-CIngI6yI.js +0 -2886
  121. package/dist/ui-editor-prancha-DorSe6sC.cjs +0 -31
  122. package/dist/ui-linha-2kY7TNUJ.cjs +0 -38
  123. package/dist/ui-linha-B4mBRm1x.cjs +0 -61
  124. package/dist/ui-linha-DTEIIww4.js +0 -1167
  125. package/dist/ui-linha-KFF86FW5.js +0 -752
  126. package/dist/ui-modal-BrXzVZ65.js +0 -216
  127. package/dist/ui-modal-lARKzEVZ.cjs +0 -18
  128. package/dist/ui-paleta-ferramentas-Bu6JaT0s.js +0 -1245
  129. package/dist/ui-paleta-ferramentas-D3Jhwt26.cjs +0 -21
  130. package/dist/ui-paleta-ferramentas-DebHYiwd.js +0 -1615
  131. package/dist/ui-paleta-ferramentas-Dgejtluh.js +0 -1423
  132. package/dist/ui-paleta-ferramentas-hzyo8wBt.cjs +0 -22
  133. package/dist/ui-paleta-ferramentas-jWuICjW8.cjs +0 -22
  134. package/dist/ui-seletor-cor-0RLjcME6.cjs +0 -83
  135. package/dist/ui-seletor-cor-CMuuW-Ym.cjs +0 -83
  136. package/dist/ui-seletor-cor-DFIQ1sin.js +0 -405
  137. package/dist/ui-skeleton-BLEV6h3k.js +0 -653
  138. package/dist/ui-skeleton-B_XTaGrX.cjs +0 -52
  139. package/dist/ui-switch-BXIDwC-Y.cjs +0 -66
  140. package/dist/ui-switch-Ctxk-jKS.js +0 -1212
  141. package/dist/ui-tabela-CXxqbwXv.cjs +0 -7
  142. package/dist/ui-tabela-Cd0vOwnT.js +0 -1459
  143. package/dist/ui-tabela-propriedades-C5cIF5ES.js +0 -3779
  144. package/dist/ui-tabela-propriedades-CJyo568n.js +0 -3517
  145. package/dist/ui-tabela-propriedades-D96Djx-q.cjs +0 -136
  146. package/dist/ui-tabela-propriedades-Wa34hfIr.cjs +0 -142
  147. package/dist/ui-tabela-propriedades-ahQhQauu.js +0 -2329
  148. package/dist/ui-tabela-propriedades-w9JWhjHy.cjs +0 -142
  149. package/dist/zero-js-triggers-CJT988bR.js +0 -83
  150. package/dist/zero-js-triggers-CgM9IIQB.cjs +0 -1
@@ -1,2886 +0,0 @@
1
- var Re = Object.defineProperty;
2
- var Le = (t, a, e) => a in t ? Re(t, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[a] = e;
3
- var f = (t, a, e) => Le(t, typeof a != "symbol" ? a + "" : a, e);
4
- import { S as Ya, d as Qa } from "./ssr-safe-5cWfJP-s.js";
5
- import { L as ba } from "./listener-bag-DQgv7OON.js";
6
- import { U as ae } from "./ui-bus-CUd99VJi.js";
7
- import { k as Oe, H as Ne, bx as je, v as Ge, aa as Ea, c5 as F, aZ as O, bg as $e, bv as Be, b1 as He, W as ee, d as Ve, C as Ke, bW as ya, a$ as Ue, aM as te, c4 as T, az as Ze, bw as Xe, br as re, b0 as ie, a5 as We, au as Je, ap as Ye, at as Qe, aq as at, c3 as oe, ar as et, b as tt, ao as xa, bE as rt, av as it, Y as ot, bT as st, s as nt, aA as ct, u as lt, aH as ut, bC as B, B as se, as as dt, bc as ht, c7 as ft, aI as mt, aD as pt, aJ as ne, b_ as gt, ac as vt, al as bt, aB as N, a1 as yt, x as Sa, t as ce, X as Pa, bM as le, ah as Aa, z as St, bL as Pt, A as At, bP as ue, bN as de, be as X, a8 as Mt, bp as zt, bq as Ct, bY as Et, bk as xt, bl as Tt, b9 as wt, bh as It, aX as Dt, aS as ra, c6 as qt, r as _t, w as Ft, ak as kt, aT as Rt, aw as Lt, Z as he, O as Ot, G as Nt, aR as jt, b$ as Gt, ay as $t, bZ as Bt, aN as Ht, b7 as Vt, aY as Ta, b2 as Kt, aP as Ut, aO as Zt, a7 as Xt, bX as Wt, o as Jt, c8 as Yt, bU as Qt, j as wa } from "./feature_historico-C4h9y5fu.js";
8
- import { u as ar, T as er } from "./geometria-px-DUs5FgLE.js";
9
- import { S as tr } from "./feature_desenho-BVHivWIB.js";
10
- import { f as rr, a as Ia } from "./alvo-digitavel-CzCvNVQ3.js";
11
- const ir = ":host{--ui-prancha-mesa: var(--ui-cor-fundo);--ui-prancha-papel: var(--ui-cor-papel);--ui-prancha-borda-papel: var(--ui-cor-borda);--ui-prancha-grade: var(--ui-cor-grade-papel);--ui-prancha-selecao: var(--ui-cor-primaria);--ui-prancha-alca: var(--ui-cor-superficie);--ui-prancha-guia: var(--ui-cor-guia);--ui-prancha-guia-inteligente: var(--ui-cor-guia-inteligente);--ui-prancha-snap: var(--ui-cor-destaque);--ui-prancha-regua: var(--ui-cor-fundo-elevado);--ui-prancha-texto-regua: var(--ui-cor-texto-secundario);--ui-prancha-tamanho-regua: 20px;display:block;position:relative;min-height:240px;min-width:240px;height:100%;background:var(--ui-cor-fundo);color:var(--ui-cor-texto);font-family:var(--ui-fonte-base);outline:none;contain:layout paint}:host([hidden]){display:none}.raiz{position:absolute;top:0;right:0;bottom:0;left:0;display:grid;grid-template-columns:var(--ui-prancha-tamanho-regua) 1fr;grid-template-rows:var(--ui-prancha-tamanho-regua) 1fr}:host([sem-reguas]) .raiz{grid-template-columns:0 1fr;grid-template-rows:0 1fr}:host([sem-reguas]) .regua,:host([sem-reguas]) .canto{display:none}.canto{background:var(--ui-prancha-regua);border-right:1px solid var(--ui-cor-borda);border-bottom:1px solid var(--ui-cor-borda)}.regua{display:block;width:100%;height:100%;background:var(--ui-prancha-regua);cursor:default;touch-action:none}.regua-h{border-bottom:1px solid var(--ui-cor-borda);cursor:s-resize}.regua-v{border-right:1px solid var(--ui-cor-borda);cursor:e-resize}.viewport{position:relative;overflow:hidden;background:var(--ui-prancha-mesa);touch-action:none;cursor:default}.viewport:focus-visible{outline:2px solid var(--ui-cor-primaria);outline-offset:-2px}.viewport[data-cursor=mao]{cursor:grab}.viewport[data-cursor=arrastando]{cursor:grabbing}.viewport[data-cursor=mira]{cursor:crosshair}.viewport[data-cursor=mover]{cursor:move}.viewport[data-cursor=girar]{cursor:alias}.viewport[data-cursor=ancora]{cursor:pointer}.camada{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%;display:block;pointer-events:none}.status{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap}@media (pointer: coarse){:host{--ui-prancha-tamanho-regua: 24px}}";
12
- function or() {
13
- return `
14
- <style>${ir}</style>
15
- <div class="raiz" part="base">
16
- <div class="canto" part="canto-reguas" aria-hidden="true"></div>
17
- <canvas class="regua regua-h" id="regua-h" part="regua regua-horizontal" aria-hidden="true"></canvas>
18
- <canvas class="regua regua-v" id="regua-v" part="regua regua-vertical" aria-hidden="true"></canvas>
19
- <div class="viewport" id="viewport" part="viewport" tabindex="0" role="application"
20
- aria-roledescription="prancha de desenho" aria-label="Prancha" aria-describedby="ajuda">
21
- <canvas class="camada" id="camada-base" part="canvas"></canvas>
22
- <canvas class="camada" id="camada-sobreposicao" part="sobreposicao"></canvas>
23
- </div>
24
- <div class="status" id="ajuda">Atalhos: V seleção, A seleção direta, H mão, M retângulo, L elipse, P caneta, barra invertida linha, T texto. Setas movem, Shift multiplica por 10. Delete exclui. Ctrl+Z desfaz. Ctrl+0 ajusta a folha.</div>
25
- <div class="status" id="status" part="status" role="status" aria-live="polite"></div>
26
- </div>
27
- `;
28
- }
29
- function Da(t, a) {
30
- const e = new Map(t.map((o) => [o.id, o])), r = new Map(a.map((o) => [o.id, o])), i = { adicionados: [], atualizados: [], removidos: [] };
31
- for (const [o, s] of r) {
32
- const n = e.get(o);
33
- n ? n !== s && i.atualizados.push(s) : i.adicionados.push(s);
34
- }
35
- for (const [o, s] of e) r.has(o) || i.removidos.push(s);
36
- return i;
37
- }
38
- const ma = (t) => t.adicionados.length + t.atualizados.length + t.removidos.length === 0;
39
- class sr {
40
- constructor() {
41
- f(this, "lista", []);
42
- f(this, "porId", /* @__PURE__ */ new Map());
43
- f(this, "posicoes", /* @__PURE__ */ new Map());
44
- f(this, "_selecao", []);
45
- f(this, "indice", new Oe());
46
- f(this, "historico", new Ne({ limite: 100, janelaRajadaMs: 1e3 }));
47
- /** Contador de mudanças do documento (carga, edição, desfazer/refazer, renomear): base do `modificado` do componente. */
48
- f(this, "revisao", 0);
49
- f(this, "ouvinteMudanca", null);
50
- }
51
- /** Registra quem é avisado depois de cada mudança do documento (o componente avalia o `modificado`). */
52
- ouvirMudancas(a) {
53
- this.ouvinteMudanca = a;
54
- }
55
- mudou() {
56
- var a;
57
- this.revisao++;
58
- try {
59
- (a = this.ouvinteMudanca) == null || a.call(this);
60
- } catch {
61
- }
62
- }
63
- get elementos() {
64
- return this.lista;
65
- }
66
- obter(a) {
67
- return this.porId.get(a);
68
- }
69
- get selecao() {
70
- return this._selecao;
71
- }
72
- elementosSelecionados() {
73
- return this._selecao.map((a) => this.porId.get(a)).filter((a) => !!a);
74
- }
75
- /** Troca tudo (carga de documento): normaliza, recomeça o histórico e limpa a seleção. */
76
- definir(a) {
77
- const e = je(a);
78
- return this.aplicar(e.elementos), this.indice.definir(e.elementos), this.historico.limpar(), this._selecao = [], this.mudou(), e;
79
- }
80
- aplicar(a) {
81
- this.lista = a, this.porId = new Map(a.map((e) => [e.id, e])), this.posicoes = new Map(a.map((e, r) => [e.id, r]));
82
- }
83
- /** Os elementos na ordem da lista do documento (o índice espacial devolve em outra ordem). */
84
- naOrdemDoDocumento(a) {
85
- return [...a].sort((e, r) => (this.posicoes.get(e.id) ?? 0) - (this.posicoes.get(r.id) ?? 0));
86
- }
87
- /** Mudança central: grava o passo no histórico, atualiza índice e seleção e devolve a diferença. */
88
- substituir(a, e = {}) {
89
- const r = this.lista, i = Da(r, a);
90
- return ma(i) && r.length === a.length && r.every((o, s) => o === a[s]) || (e.registrar !== !1 && this.historico.registrar(r, { chave: e.chave, agora: e.agora }), this.aplicar(a), this.sincronizarIndice(i), this._selecao = this._selecao.filter((o) => this.porId.has(o)), this.mudou()), i;
91
- }
92
- sincronizarIndice(a) {
93
- for (const r of a.removidos) this.indice.remover(r.id);
94
- const e = [...a.adicionados, ...a.atualizados];
95
- e.length > 0 && this.indice.atualizarVarios(e);
96
- }
97
- /** Aplica o lote do app (normalizado; ids repetidos e inválidos recusados). */
98
- aplicarLote(a, e = !0) {
99
- const r = { adicionados: [], atualizados: [], removidos: [], recusados: [] }, i = new Map(this.lista.map((d) => [d.id, d])), o = this.lista.map((d) => d.id), s = new Set((Array.isArray(a == null ? void 0 : a.remover) ? a.remover : []).filter((d) => typeof d == "string"));
100
- for (const d of s)
101
- i.delete(d) && r.removidos.push(d);
102
- const n = (d, h) => {
103
- Array.isArray(d) && d.forEach((u, m) => {
104
- const p = Ge(u);
105
- if (typeof p == "string") {
106
- r.recusados.push({ indice: m, motivo: p });
107
- return;
108
- }
109
- const v = i.has(p.id);
110
- if (h === "adicionar" && v) {
111
- r.recusados.push({ indice: m, id: p.id, motivo: "id-duplicado" });
112
- return;
113
- }
114
- if (h === "atualizar" && !v) {
115
- r.recusados.push({ indice: m, id: p.id, motivo: "id-invalido" });
116
- return;
117
- }
118
- h === "adicionar" && o.push(p.id), i.set(p.id, p), (h === "adicionar" ? r.adicionados : r.atualizados).push(p.id);
119
- });
120
- };
121
- n(a == null ? void 0 : a.adicionar, "adicionar"), n(a == null ? void 0 : a.atualizar, "atualizar");
122
- const c = /* @__PURE__ */ new Set(), l = [];
123
- for (const d of o) {
124
- const h = i.get(d);
125
- h && !c.has(d) && (c.add(d), l.push(h));
126
- }
127
- return { resultado: r, diferenca: this.substituir(l, { registrar: e }) };
128
- }
129
- desfazer() {
130
- const a = this.historico.desfazer(this.lista);
131
- return a ? this.restaurar(a) : null;
132
- }
133
- refazer() {
134
- const a = this.historico.refazer(this.lista);
135
- return a ? this.restaurar(a) : null;
136
- }
137
- restaurar(a) {
138
- const e = Da(this.lista, a);
139
- return this.aplicar(a), this.sincronizarIndice(e), this._selecao = this._selecao.filter((r) => this.porId.has(r)), this.mudou(), e;
140
- }
141
- /** Troca o id de um elemento em tudo (lista, índice, seleção e histórico). `false` se não existe ou o novo já existe. */
142
- renomear(a, e) {
143
- if (typeof e != "string" || !e.trim() || !this.porId.has(a) || this.porId.has(e)) return !1;
144
- const r = (o) => o.map((s) => s.id === a ? { ...s, id: e } : s), i = r(this.lista);
145
- return this.indice.remover(a), this.aplicar(i), this.indice.atualizar(this.porId.get(e)), this.historico.transformar(r), this._selecao = this._selecao.map((o) => o === a ? e : o), this.mudou(), !0;
146
- }
147
- /** Muda a seleção; devolve se mudou. Só ids existentes, não bloqueados nem ocultos, sem repetição, na ordem dada. */
148
- selecionar(a, e = "substituir") {
149
- const r = a.filter((n, c) => {
150
- const l = this.porId.get(n);
151
- return !!l && !l.bloqueado && !l.oculto && a.indexOf(n) === c;
152
- }), i = this._selecao;
153
- let o;
154
- e === "substituir" ? o = r : e === "adicionar" ? o = [...i, ...r.filter((n) => !i.includes(n))] : e === "remover" ? o = i.filter((n) => !r.includes(n)) : o = [...i.filter((n) => !r.includes(n)), ...r.filter((n) => !i.includes(n))];
155
- const s = o.length !== i.length || o.some((n, c) => n !== i[c]);
156
- return s && (this._selecao = o), s;
157
- }
158
- }
159
- const $ = 96 / 25.4, ua = $ * 0.02, da = $ * 64, z = (t) => typeof t == "number" && Number.isFinite(t);
160
- class nr {
161
- constructor() {
162
- f(this, "zoom", $);
163
- f(this, "pan", [0, 0]);
164
- f(this, "largura", 0);
165
- f(this, "altura", 0);
166
- f(this, "dpr", 1);
167
- }
168
- get zoomPercentual() {
169
- return this.zoom / $ * 100;
170
- }
171
- /** Folha (mm) → px CSS da área de desenho. */
172
- matrizTela() {
173
- return Ea(O(this.zoom), F(this.pan[0], this.pan[1]));
174
- }
175
- /** Folha (mm) → px do dispositivo (com o dpr): a matriz do pintor. */
176
- matrizDispositivo() {
177
- return Ea(O(this.zoom), F(this.pan[0], this.pan[1]), O(this.dpr));
178
- }
179
- paraFolha(a, e) {
180
- return [(a - this.pan[0]) / this.zoom, (e - this.pan[1]) / this.zoom];
181
- }
182
- paraTela(a) {
183
- return [a[0] * this.zoom + this.pan[0], a[1] * this.zoom + this.pan[1]];
184
- }
185
- /** Muda o tamanho da área de desenho (px CSS) e o dpr; valores inválidos são ignorados. */
186
- redimensionar(a, e, r = 1) {
187
- z(a) && a >= 0 && (this.largura = a), z(e) && e >= 0 && (this.altura = e), z(r) && r > 0 && (this.dpr = Math.min(r, 4));
188
- }
189
- /** Zoom absoluto mantendo parado o ponto de tela `foco` (padrão: o centro). Devolve se mudou. */
190
- definirZoom(a, e) {
191
- if (!z(a) || a <= 0) return !1;
192
- const r = Math.min(da, Math.max(ua, a));
193
- if (r === this.zoom) return !1;
194
- const i = e && z(e[0]) && z(e[1]) ? e : [this.largura / 2, this.altura / 2], o = this.paraFolha(i[0], i[1]);
195
- return this.zoom = r, this.pan = [i[0] - o[0] * r, i[1] - o[1] * r], !0;
196
- }
197
- zoomRelativo(a, e) {
198
- return z(a) && a > 0 ? this.definirZoom(this.zoom * a, e) : !1;
199
- }
200
- deslocar(a, e) {
201
- return !z(a) || !z(e) || a === 0 && e === 0 ? !1 : (this.pan = [this.pan[0] + a, this.pan[1] + e], !0);
202
- }
203
- /** Zoom absoluto mantendo o CENTRO da caixa (mm) no centro da área de desenho (usado no teto de zoom do enquadramento). */
204
- definirZoomCentrado(a, e) {
205
- return !z(a) || a <= 0 || !e || ![e.x, e.y, e.largura, e.altura].every(z) ? !1 : (this.zoom = Math.min(da, Math.max(ua, a)), this.pan = [this.largura / 2 - (e.x + e.largura / 2) * this.zoom, this.altura / 2 - (e.y + e.altura / 2) * this.zoom], !0);
206
- }
207
- /** Enquadra a caixa (mm) com `margem` px em volta. Sem tamanho de área de desenho, não faz nada. */
208
- enquadrar(a, e = 24) {
209
- if (!a || ![a.x, a.y, a.largura, a.altura].every(z) || this.largura <= 0 || this.altura <= 0) return !1;
210
- const r = Math.max(a.largura, 1e-6), i = Math.max(a.altura, 1e-6), o = Math.max(1, this.largura - 2 * e), s = Math.max(1, this.altura - 2 * e);
211
- return this.zoom = Math.min(da, Math.max(ua, Math.min(o / r, s / i))), this.pan = [this.largura / 2 - (a.x + r / 2) * this.zoom, this.altura / 2 - (a.y + i / 2) * this.zoom], !0;
212
- }
213
- }
214
- function cr() {
215
- return {
216
- hoverId: null,
217
- caixaSelecao: null,
218
- substitutos: /* @__PURE__ */ new Map(),
219
- previa: null,
220
- pontosPrevia: [],
221
- snap: null,
222
- linhasInteligentes: [],
223
- guiaArrastada: null,
224
- pivo: null,
225
- edicao: null,
226
- rotulo: null,
227
- ponteiro: null,
228
- copiasEmGesto: []
229
- };
230
- }
231
- function j(t) {
232
- t.caixaSelecao = null, t.substitutos = /* @__PURE__ */ new Map(), t.previa = null, t.pontosPrevia = [], t.snap = null, t.linhasInteligentes = [], t.guiaArrastada = null, t.rotulo = null, t.copiasEmGesto = [];
233
- }
234
- const qa = Object.freeze({
235
- mesa: "--ui-prancha-mesa",
236
- papel: "--ui-prancha-papel",
237
- bordaPapel: "--ui-prancha-borda-papel",
238
- grade: "--ui-prancha-grade",
239
- selecao: "--ui-prancha-selecao",
240
- alca: "--ui-prancha-alca",
241
- guia: "--ui-prancha-guia",
242
- guiaInteligente: "--ui-prancha-guia-inteligente",
243
- snap: "--ui-prancha-snap",
244
- regua: "--ui-prancha-regua",
245
- textoRegua: "--ui-prancha-texto-regua"
246
- }), pa = Object.freeze({
247
- mesa: "#0b0b0d",
248
- papel: "#ffffff",
249
- bordaPapel: "rgba(255, 255, 255, 0.08)",
250
- grade: "rgba(59, 155, 255, 0.22)",
251
- selecao: "#00E08A",
252
- alca: "#141417",
253
- guia: "#3b9bff",
254
- guiaInteligente: "#ff4fd8",
255
- snap: "#00E08A",
256
- regua: "#1a1a1e",
257
- textoRegua: "#9696a6"
258
- });
259
- function lr(t) {
260
- var r;
261
- const a = { ...pa };
262
- if (!t || typeof getComputedStyle != "function") return a;
263
- let e = null;
264
- try {
265
- e = getComputedStyle(t);
266
- } catch {
267
- return a;
268
- }
269
- for (const i of Object.keys(qa)) {
270
- const o = (r = e.getPropertyValue(qa[i])) == null ? void 0 : r.trim();
271
- o && (a[i] = ar(o, pa[i]));
272
- }
273
- return a;
274
- }
275
- const ur = {
276
- selecao: "Seleção",
277
- "selecao-direta": "Seleção direta",
278
- mao: "Mão",
279
- retangulo: "Retângulo",
280
- elipse: "Elipse",
281
- "poligono-regular": "Polígono regular",
282
- estrela: "Estrela",
283
- linha: "Linha",
284
- seta: "Seta",
285
- polilinha: "Polilinha",
286
- poligono: "Polígono",
287
- caneta: "Caneta",
288
- texto: "Texto"
289
- };
290
- function dr(t) {
291
- return t <= 0 ? "Nenhum elemento selecionado" : t === 1 ? "1 elemento selecionado" : `${t} elementos selecionados`;
292
- }
293
- function hr(t) {
294
- return `Ferramenta ${ur[t] ?? t}`;
295
- }
296
- function ia(t) {
297
- return `Zoom ${Math.round(t)}%`;
298
- }
299
- function fr(t, a) {
300
- t && t.textContent !== a && (t.textContent = a);
301
- }
302
- class mr {
303
- constructor(a) {
304
- f(this, "doc", new sr());
305
- f(this, "vista", new nr());
306
- f(this, "ui", cr());
307
- f(this, "cores", { ...pa });
308
- f(this, "guias", []);
309
- f(this, "ferramenta", "selecao");
310
- f(this, "opcoesFerramentas", {});
311
- f(this, "folha", { largura: 210, altura: 297 });
312
- f(this, "grade", 10);
313
- f(this, "mostrarGrade", !1);
314
- f(this, "snapLigado", !0);
315
- f(this, "guiasInteligentes", !0);
316
- f(this, "unidade", "mm");
317
- f(this, "passoTeclado", 1);
318
- f(this, "somenteLeitura", !1);
319
- /** Margens da folha em mm (guias automáticas e quadro das pré-definições de moldura); `null` = sem margens. */
320
- f(this, "margens", null);
321
- /** Gera o id provisório de um elemento novo; o app pode trocar (`gerarId` do host) ou renomear depois. */
322
- f(this, "gerarId");
323
- f(this, "sequencia", 0);
324
- /** Camadas da prancha (ordem = empilhamento), a camada dos elementos novos e o grupo isolado (duplo clique). */
325
- f(this, "camadas", []);
326
- f(this, "camadaAtiva", null);
327
- f(this, "isolado", null);
328
- /** Última transformação aplicada à seleção, para o Ctrl+D ("transformar de novo"). */
329
- f(this, "ultimaTransformacao", null);
330
- f(this, "cacheMapa", null);
331
- /** Elementos para a base: os do documento com os substitutos do gesto em andamento no lugar. */
332
- f(this, "cacheBase", null);
333
- this.dep = a, this.gerarId = (e) => `${e}-${Date.now().toString(36)}-${(++this.sequencia).toString(36)}`;
334
- }
335
- emitir(a, e, r = !1) {
336
- return this.dep.emitir(a, e, r);
337
- }
338
- agendar() {
339
- this.dep.agendar();
340
- }
341
- anunciar(a) {
342
- this.dep.anunciar(a);
343
- }
344
- recusar(a, e, r) {
345
- this.emitir("prancha-recusa", r === void 0 ? { acao: a, motivo: e } : { acao: a, motivo: e, id: r });
346
- }
347
- /** Regras das camadas atuais (em cache pela lista). */
348
- mapa() {
349
- return (!this.cacheMapa || this.cacheMapa.camadas !== this.camadas) && (this.cacheMapa = { camadas: this.camadas, mapa: $e(this.camadas) }), this.cacheMapa.mapa;
350
- }
351
- /** Pode ser selecionado agora: visível, destravado (ele e a camada), não é máscara e está no grupo isolado, se houver. */
352
- podeSelecionar(a) {
353
- const e = this.mapa();
354
- return !!a && !a.mascara && e.visivel(a) && !e.travado(a) && (this.isolado === null || a.grupoId === this.isolado);
355
- }
356
- /** Elementos perto do ponto (pelo índice), visíveis, na ordem do documento (para o desempate do empilhamento). */
357
- candidatosEm(a, e) {
358
- const r = this.mapa();
359
- return this.doc.naOrdemDoDocumento(this.doc.indice.consultarPonto(a, e).filter((i) => r.visivel(i)));
360
- }
361
- definirCamadas(a) {
362
- this.camadas = Be(a), this.camadaAtiva && !this.camadas.some((e) => e.id === this.camadaAtiva) && (this.camadaAtiva = null), this.emitir("prancha-camadas", { camadas: this.camadas.map((e) => ({ ...e })) }), this.podarSelecao(), this.agendar();
363
- }
364
- /** Isola um grupo (só os membros se selecionam; o resto fica esmaecido) ou sai do isolamento (`null`). */
365
- isolar(a) {
366
- const e = typeof a == "string" && this.doc.elementos.some((r) => r.grupoId === a) ? a : null;
367
- e !== this.isolado && (this.isolado = e, this.emitir("prancha-isolamento", { grupoId: e }), this.anunciar(e ? "Grupo isolado" : "Saiu do grupo"), this.podarSelecao(), this.agendar());
368
- }
369
- /** Tira da seleção o que deixou de ser selecionável (camada oculta ou bloqueada, fora do grupo isolado). */
370
- podarSelecao() {
371
- const a = this.doc.selecao.filter((e) => this.podeSelecionar(this.doc.obter(e)));
372
- a.length !== this.doc.selecao.length && this.selecionar(a, "substituir", !1);
373
- }
374
- /**
375
- * Elementos da BASE: os do documento, sem os que estão num gesto (arrasto, alça, âncora). A lista fica a mesma durante o
376
- * gesto inteiro, então a base não é repintada a cada quadro; os elementos em gesto vão na sobreposição
377
- * (`elementosEmGesto`), por cima, como a prévia de arrasto dos editores vetoriais.
378
- */
379
- elementosVisiveis() {
380
- const a = this.ui.substitutos;
381
- if (a.size === 0) return this.doc.elementos;
382
- const e = [...a.keys()].join("\0"), r = this.cacheBase;
383
- if (r && r.elementos === this.doc.elementos && r.ids === e) return r.base;
384
- const i = this.doc.elementos.filter((o) => !a.has(o.id));
385
- return this.cacheBase = { elementos: this.doc.elementos, ids: e, base: i }, i;
386
- }
387
- /** Elementos transformados pelo gesto em andamento, na ordem de empilhamento. */
388
- elementosEmGesto() {
389
- const a = this.ui.substitutos, e = a.size === 0 ? [] : this.doc.elementos.filter((r) => a.has(r.id)).map((r) => a.get(r.id));
390
- return this.ui.copiasEmGesto.length > 0 ? [...e, ...this.ui.copiasEmGesto] : e;
391
- }
392
- /** Emite os eventos da diferença (criados, atualizados, removidos) com o motivo. */
393
- emitirDiferenca(a, e) {
394
- a.adicionados.length > 0 && this.emitir("prancha-elemento-criado", { elementos: a.adicionados, motivo: e }), a.atualizados.length > 0 && this.emitir("prancha-elemento-atualizado", { elementos: a.atualizados, motivo: e }), a.removidos.length > 0 && this.emitir("prancha-elemento-removido", { ids: a.removidos.map((r) => r.id), elementos: a.removidos, motivo: e });
395
- }
396
- emitirHistorico() {
397
- this.emitir("prancha-historico", { podeDesfazer: this.doc.historico.podeDesfazer, podeRefazer: this.doc.historico.podeRefazer });
398
- }
399
- /** Mudança do usuário: histórico + eventos + repintura. `chave` junta rajadas (setas, scrubber) num passo. */
400
- aplicar(a, e, r) {
401
- const i = this.doc.selecao.join("\0"), o = this.doc.elementos.map((c) => c.id).join("\0"), s = this.doc.substituir(a, { chave: r });
402
- return this.doc.elementos.map((c) => c.id).join("\0") !== o && s.adicionados.length === 0 && s.removidos.length === 0 && (this.emitir("prancha-ordem", { ids: this.doc.elementos.map((c) => c.id), motivo: e }), ma(s) && this.emitirHistorico()), ma(s) || (this.emitirDiferenca(s, e), this.emitirHistorico(), this.ui.edicao && !this.doc.obter(this.ui.edicao.id) && (this.ui.edicao = null), this.doc.selecao.join("\0") !== i && this.emitirSelecao()), this.agendar(), s;
403
- }
404
- /** Substitui elementos pelo id (os demais ficam como estão). */
405
- aplicarSubstituicoes(a, e, r) {
406
- const i = new Map(a.map((o) => [o.id, o]));
407
- return this.aplicar(this.doc.elementos.map((o) => i.get(o.id) ?? o), e, r);
408
- }
409
- emitirSelecao() {
410
- const a = this.doc.elementosSelecionados();
411
- this.emitir("prancha-selecao", { ids: a.map((e) => e.id), elementos: a }), this.anunciar(dr(a.length));
412
- }
413
- /**
414
- * Muda a seleção. Fora do isolamento, um membro de grupo seleciona o grupo inteiro (`expandir`). Só entra o que pode ser
415
- * selecionado (camadas, máscara, isolamento).
416
- */
417
- selecionar(a, e = "substituir", r = !0) {
418
- const i = Array.isArray(a) ? a.filter((n) => typeof n == "string") : [], o = (r && this.isolado === null ? He(this.doc.elementos, i) : i).filter((n) => e === "remover" || this.podeSelecionar(this.doc.obter(n)));
419
- return this.doc.selecionar(o, e) ? (this.ui.pivo = null, this.ui.edicao && !this.doc.selecao.includes(this.ui.edicao.id) && this.encerrarEdicao(), this.emitirSelecao(), this.agendar(), !0) : !1;
420
- }
421
- definirFerramenta(a) {
422
- a !== this.ferramenta && (j(this.ui), a !== "selecao-direta" && this.ui.edicao && this.encerrarEdicao(), this.ferramenta = a, this.emitir("prancha-ferramenta", { ferramenta: a }), this.anunciar(hr(a)), this.agendar());
423
- }
424
- iniciarEdicao(a) {
425
- var r;
426
- const e = this.doc.obter(a);
427
- return e ? e.bloqueado ? (this.recusar("editar-ancoras", "bloqueado", a), !1) : e.geometria.tipo === "texto" ? (this.recusar("editar-ancoras", "texto-sem-ancoras", a), !1) : (((r = this.ui.edicao) == null ? void 0 : r.id) === a || (this.ui.edicao && this.encerrarEdicao(), this.ui.edicao = { id: a, ancoras: [] }, this.doc.selecionar([a]), this.emitirSelecao(), this.emitir("prancha-edicao-iniciada", { elemento: e }), this.agendar()), !0) : !1;
428
- }
429
- encerrarEdicao() {
430
- const a = this.ui.edicao;
431
- if (!a) return;
432
- this.ui.edicao = null;
433
- const e = this.doc.obter(a.id);
434
- e && this.emitir("prancha-edicao-concluida", { elemento: e }), this.agendar();
435
- }
436
- desfazer() {
437
- const a = this.doc.desfazer();
438
- return a ? (this.posHistorico(a, "desfazer"), !0) : (this.recusar("desfazer", "nada-a-desfazer"), !1);
439
- }
440
- refazer() {
441
- const a = this.doc.refazer();
442
- return a ? (this.posHistorico(a, "refazer"), !0) : (this.recusar("refazer", "nada-a-refazer"), !1);
443
- }
444
- posHistorico(a, e) {
445
- j(this.ui), this.ui.edicao && !this.doc.obter(this.ui.edicao.id) && (this.ui.edicao = null), this.emitirDiferenca(a, e), this.emitirHistorico(), this.anunciar(e === "desfazer" ? "Desfeito" : "Refeito"), this.agendar();
446
- }
447
- /** Tolerância de snap em px (toque precisa de mais). */
448
- toleranciaPx(a = !1) {
449
- return a ? 16 : 8;
450
- }
451
- /**
452
- * Snap do ponto (mm) aos elementos perto (pelo índice), às guias e (opcional) à grade. Grava o resultado no estado
453
- * (para a sobreposição marcar). Snap desligado ou Alt: devolve o próprio ponto.
454
- */
455
- snapPonto(a, e = {}) {
456
- if (!this.snapLigado || e.desligado)
457
- return this.ui.snap = null, { ponto: a, resultado: null };
458
- const r = this.toleranciaPx(e.toque), i = r / this.vista.zoom + 1, o = this.candidatosEm(a, i).filter((n) => !n.mascara), s = ee(a, o, this.vista.zoom, {
459
- toleranciaPx: r,
460
- guias: this.guias,
461
- grade: e.grade !== !1 && this.mostrarGrade ? { espacamento: this.grade } : null
462
- }, e.excluir ?? []);
463
- return this.ui.snap = s, { ponto: s ? s.coordenada : a, resultado: s };
464
- }
465
- /** Emite a vista (zoom/pan) e repinta. */
466
- emitirVista() {
467
- const a = this.vista;
468
- this.emitir("prancha-vista", { zoom: a.zoom, zoomPercentual: a.zoomPercentual, pan: [a.pan[0], a.pan[1]] }), this.agendar();
469
- }
470
- emitirGuias() {
471
- this.emitir("prancha-guias", { guias: this.guias.map((a) => ({ ...a })) }), this.agendar();
472
- }
473
- /** Aparência dos elementos novos (cópia; padrão traço preto 0,25 mm sem preenchimento). */
474
- aparenciaNova() {
475
- const a = this.opcoesFerramentas.aparencia;
476
- return a ? JSON.parse(JSON.stringify(a)) : { traco: { cor: Ke, espessura: Ve }, preenchimento: null };
477
- }
478
- }
479
- const Z = (t) => typeof t == "number" && Number.isFinite(t);
480
- function ca(t, a) {
481
- if (t.somenteLeitura)
482
- return t.recusar(a, "somente-leitura"), null;
483
- const e = t.doc.elementosSelecionados().filter((r) => !r.bloqueado);
484
- return e.length === 0 ? (t.recusar(a, "sem-selecao"), null) : e;
485
- }
486
- function W(t, a, e = "comando", r) {
487
- if (!te(a)) return !1;
488
- const i = ca(t, "transformar");
489
- return i ? (t.aplicarSubstituicoes(T(i, a), e, r), !0) : !1;
490
- }
491
- const fe = (t, a, e, r = "comando", i) => Z(a) && Z(e) && W(t, F(a, e), r, i);
492
- function la(t) {
493
- return t.ui.pivo ?? We(t.doc.elementosSelecionados());
494
- }
495
- function me(t, a, e, r = "comando") {
496
- const i = e ?? la(t);
497
- return Z(a) && !!i && W(t, ya(a * Math.PI / 180, i), r);
498
- }
499
- function ga(t, a, e = a, r, i = "comando") {
500
- const o = r ?? la(t);
501
- return !Z(a) || !Z(e) || a === 0 || e === 0 || !o ? !1 : W(t, O(a, e, o), i);
502
- }
503
- function pr(t, a, e = "comando") {
504
- if (a !== "horizontal" && a !== "vertical") return !1;
505
- const r = ca(t, "espelhar");
506
- return r ? (t.aplicarSubstituicoes(Ue(r, a, la(t) ?? void 0), e), !0) : !1;
507
- }
508
- function pe(t, a = "remover") {
509
- const e = ca(t, "remover");
510
- if (!e) return !1;
511
- const r = new Set(e.map((i) => i.id));
512
- return t.aplicar(t.doc.elementos.filter((i) => !r.has(i.id)), a), !0;
513
- }
514
- function ge(t) {
515
- return t.selecionar(t.doc.elementos.filter((a) => !a.bloqueado && !a.oculto).map((a) => a.id));
516
- }
517
- function gr(t, a) {
518
- const e = t.doc.elementos.filter((s) => !s.bloqueado && !s.oculto);
519
- if (e.length === 0) return !1;
520
- const r = t.doc.selecao[t.doc.selecao.length - 1], i = e.findIndex((s) => s.id === r), o = e[i < 0 ? a > 0 ? 0 : e.length - 1 : (i + a + e.length) % e.length];
521
- return t.selecionar([o.id]);
522
- }
523
- function w(t, a, e) {
524
- var i;
525
- if (t.somenteLeitura)
526
- return t.recusar("criar", "somente-leitura"), [];
527
- const r = [];
528
- for (const o of a) {
529
- const s = ((i = o == null ? void 0 : o.geometria) == null ? void 0 : i.tipo) ?? "elemento", n = o != null && o.id && !t.doc.obter(o.id) && !r.some((d) => d.id === o.id) ? o.id : t.gerarId(s), c = !(o != null && o.camadaId) && t.camadaAtiva ? { camadaId: t.camadaAtiva } : {}, l = Xe({ ...o, id: n, ...c });
530
- l ? r.push(l) : t.recusar("criar", "geometria-invalida");
531
- }
532
- return r.length === 0 ? [] : (t.aplicar([...t.doc.elementos, ...r], e), t.selecionar(r.map((o) => o.id)), t.anunciar(r.length === 1 ? "Elemento criado" : `${r.length} elementos criados`), r);
533
- }
534
- function vr(t, a, e, r) {
535
- const i = t.ui.edicao, o = i ? t.doc.obter(i.id) : void 0;
536
- if (!i || !o || i.ancoras.length === 0) return !1;
537
- const s = re(o, i.ancoras, a, e);
538
- return s ? (t.aplicarSubstituicoes([s], "editar-ancoras", r), !0) : (t.recusar("editar-ancoras", "matriz-singular", o.id), !1);
539
- }
540
- function br(t) {
541
- const a = t.ui.edicao;
542
- let e = a ? t.doc.obter(a.id) : void 0;
543
- if (!a || !e || a.ancoras.length === 0) return !1;
544
- let r = !1;
545
- for (const i of [...a.ancoras].sort((o, s) => s - o)) {
546
- const o = ie(e, i);
547
- if (!o) {
548
- t.recusar("excluir-ancora", "minimo-de-ancoras", e.id);
549
- break;
550
- }
551
- e = o, r = !0;
552
- }
553
- return r ? (a.ancoras = [], t.aplicarSubstituicoes([e], "editar-ancoras"), !0) : !1;
554
- }
555
- function ve(t, a) {
556
- const e = ca(t, "definir-raios");
557
- if (!e) return !1;
558
- const r = e.map((i) => Ze(i, a)).filter((i) => !!i);
559
- return r.length === 0 ? (t.recusar("definir-raios", "tipo-nao-suportado"), !1) : (t.aplicarSubstituicoes(r, "cantos"), !0);
560
- }
561
- const ea = ["retangulo", "elipse", "poligono-regular", "estrela", "linha", "seta"], be = { polilinha: "linha", poligono: "poligono", caneta: "caneta" }, yr = "__previa__", Sr = 3, Pr = 8, Ar = 400, Mr = 4, oa = (t) => ea.includes(t) || t in be || t === "texto";
562
- function _a(t, a, e, r) {
563
- let i = a[0] - t[0], o = a[1] - t[1];
564
- if (e) {
565
- const s = Math.max(Math.abs(i), Math.abs(o));
566
- i = (i < 0 ? -1 : 1) * s, o = (o < 0 ? -1 : 1) * s;
567
- }
568
- return r ? { x: t[0] - Math.abs(i), y: t[1] - Math.abs(o), largura: 2 * Math.abs(i), altura: 2 * Math.abs(o) } : ot(t, [t[0] + i, t[1] + o]);
569
- }
570
- function zr(t, a) {
571
- const e = a[0] - t[0], r = a[1] - t[1], i = Math.hypot(e, r), o = Math.round(Math.atan2(r, e) / (Math.PI / 4)) * (Math.PI / 4);
572
- return [t[0] + i * Math.cos(o), t[1] + i * Math.sin(o)];
573
- }
574
- class Cr {
575
- constructor(a) {
576
- f(this, "arrasto", null);
577
- f(this, "sessao", null);
578
- f(this, "puxandoAlca", !1);
579
- f(this, "ultimoClique", null);
580
- this.c = a;
581
- }
582
- get emAndamento() {
583
- return !!this.arrasto || !!this.sessao && this.sessao.nos > 0;
584
- }
585
- base(a = {}) {
586
- return { id: yr, aparencia: this.c.aparenciaNova(), ...a };
587
- }
588
- /** Elemento da forma de arrasto entre `inicio` e `atual` (null se degenerado). */
589
- construir(a, e, r, i) {
590
- const o = this.c.opcoesFerramentas;
591
- if (a === "retangulo" || a === "elipse") {
592
- const s = _a(e, r, i.shift, i.alt);
593
- return a === "retangulo" ? Je(this.base(), s, o.raioCantos) : Ye(this.base(), s);
594
- }
595
- if (a === "poligono-regular" || a === "estrela") {
596
- const s = Math.hypot(r[0] - e[0], r[1] - e[1]), n = a === "poligono-regular" ? Qe(this.base(), e, s, o.lados ?? 6) : at(this.base(), e, s, s * (o.proporcaoInterna ?? 0.45), o.pontas ?? 5);
597
- if (!n || i.shift) return n;
598
- const c = Math.atan2(r[1] - e[1], r[0] - e[0]) + Math.PI / 2;
599
- return oe(n, ya(c, e));
600
- }
601
- if (a === "linha" || a === "seta") {
602
- const s = i.shift ? zr(e, r) : r, n = this.c.aparenciaNova();
603
- return a === "seta" && (n.traco = { ...n.traco ?? {}, pontaFim: o.ponta ?? { estilo: "triangulo" } }), et(this.base({ aparencia: n }), e, s);
604
- }
605
- return null;
606
- }
607
- pressionar(a, e, r) {
608
- const i = this.c.ferramenta, { ponto: o } = this.c.snapPonto(a, { toque: r.toque, desligado: r.alt && !ea.includes(i) });
609
- if (ea.includes(i)) {
610
- this.arrasto = { inicio: o, atual: o, inicioPx: e };
611
- return;
612
- }
613
- if (i === "texto") {
614
- this.solicitarTexto(o);
615
- return;
616
- }
617
- const s = be[i];
618
- if (!s) return;
619
- this.sessao || (this.sessao = new tr(s, !1, { espaco: tt }));
620
- const n = this.sessao, c = Date.now(), l = !!this.ultimoClique && c - this.ultimoClique.t <= Ar && Math.hypot(e[0] - this.ultimoClique.x, e[1] - this.ultimoClique.y) <= Mr;
621
- this.ultimoClique = { t: c, x: e[0], y: e[1] };
622
- const d = n.primeiro;
623
- if (d && n.fechaNoPrimeiro) {
624
- const h = this.c.vista.paraTela(d);
625
- if (Math.hypot(h[0] - e[0], h[1] - e[1]) <= Pr) {
626
- this.finalizar(n.concluirFechando());
627
- return;
628
- }
629
- }
630
- if (l && s !== "caneta") {
631
- this.concluir();
632
- return;
633
- }
634
- n.clicar(o), s === "caneta" && (this.puxandoAlca = !0), this.atualizarPrevia();
635
- }
636
- mover(a, e, r) {
637
- const i = this.c.ferramenta;
638
- if (this.arrasto) {
639
- const { ponto: o } = this.c.snapPonto(a, { toque: r.toque });
640
- this.arrasto.atual = o, this.c.ui.previa = this.construir(i, this.arrasto.inicio, o, r);
641
- const s = _a(this.arrasto.inicio, o, r.shift, r.alt), n = (c) => Math.round(c * 10) / 10;
642
- this.c.ui.rotulo = { texto: `${n(s.largura)} × ${n(s.altura)} mm`, em: o }, this.c.agendar();
643
- return;
644
- }
645
- if (this.sessao) {
646
- const { ponto: o } = this.c.snapPonto(a, { toque: r.toque, desligado: r.alt });
647
- this.puxandoAlca ? this.sessao.definirAlca(o) : this.sessao.mover(o), this.atualizarPrevia();
648
- } else oa(i) && (this.c.snapPonto(a, { toque: r.toque, desligado: r.alt }), this.c.agendar());
649
- }
650
- soltar(a, e, r) {
651
- this.puxandoAlca = !1;
652
- const i = this.arrasto;
653
- if (!i) return;
654
- this.arrasto = null;
655
- const o = this.c.ui.previa;
656
- if (j(this.c.ui), !o || Math.hypot(e[0] - i.inicioPx[0], e[1] - i.inicioPx[1]) < Sr) {
657
- this.c.recusar("desenhar", "forma-pequena"), this.c.agendar();
658
- return;
659
- }
660
- w(this.c, [{ ...o, id: "" }], "ferramenta");
661
- }
662
- atualizarPrevia() {
663
- const a = this.sessao;
664
- if (!a) return;
665
- const e = a.previa();
666
- this.c.ui.previa = e && (e.tipo === "LineString" || e.tipo === "Polygon") ? xa(this.base(), e) : null, this.c.ui.pontosPrevia = a.ferramenta === "caneta" ? a.ancoras.map((r) => r.ponto) : [...a.pontos], this.c.agendar();
667
- }
668
- finalizar(a) {
669
- if (this.sessao = null, this.ultimoClique = null, j(this.c.ui), a && (a.tipo === "LineString" || a.tipo === "Polygon")) {
670
- const e = xa({ id: "", aparencia: this.c.aparenciaNova() }, a);
671
- e && w(this.c, [e], "ferramenta");
672
- } else
673
- this.c.recusar("desenhar", "geometria-invalida");
674
- this.c.agendar();
675
- }
676
- concluir() {
677
- const a = this.sessao;
678
- return !a || !a.podeConcluir ? !1 : (this.finalizar(a.concluir()), !0);
679
- }
680
- cancelar() {
681
- this.arrasto = null, this.sessao = null, this.puxandoAlca = !1, this.ultimoClique = null, j(this.c.ui), this.c.agendar();
682
- }
683
- /** Enter, Esc e Backspace durante o desenho; devolve se tratou. */
684
- tecla(a) {
685
- return a === "Enter" && this.sessao ? this.concluir() || !0 : a === "Escape" && this.emAndamento ? (this.cancelar(), !0) : a === "Backspace" && this.sessao && this.sessao.nos > 0 ? (this.sessao.desfazer(), this.sessao.nos === 0 ? this.cancelar() : this.atualizarPrevia(), !0) : !1;
686
- }
687
- /** Teclado: Enter com a ferramenta ativa e nada em andamento cria a forma padrão (40 × 30 mm) no centro da vista. */
688
- criarNoCentro() {
689
- const a = this.c.ferramenta, e = this.c.vista, r = e.largura > 0 ? e.paraFolha(e.largura / 2, e.altura / 2) : [this.c.folha.largura / 2, this.c.folha.altura / 2];
690
- if (a === "texto")
691
- return this.solicitarTexto(r), !0;
692
- if (!ea.includes(a)) return !1;
693
- const i = this.construir(a, [r[0] - 20, r[1] - 15], [r[0] + 20, r[1] + 15], { shift: !1, alt: !1 });
694
- return !!i && w(this.c, [{ ...i, id: "" }], "ferramenta").length > 0;
695
- }
696
- solicitarTexto(a) {
697
- const e = this.c.opcoesFerramentas, r = e.tamanhoTexto && e.tamanhoTexto > 0 ? e.tamanhoTexto : rt(12, "pt"), i = (n) => {
698
- var l;
699
- const c = it({ id: "", aparencia: { preenchimento: { cor: ((l = this.c.aparenciaNova().traco) == null ? void 0 : l.cor) ?? void 0 } } }, a, n, r);
700
- return c ? w(this.c, [c], "texto")[0] ?? null : null;
701
- }, o = { posicao: a, concluir: (n) => i(typeof n == "string" ? n : String(n ?? "")) };
702
- this.c.emitir("prancha-texto-solicitado", o, !0) || i(e.textoPadrao ?? "Texto");
703
- }
704
- }
705
- const K = 5, q = { elementos: [], colagens: 0 }, va = (t) => typeof t == "number" && Number.isFinite(t);
706
- function y(t, a, e = 1) {
707
- if (t.somenteLeitura)
708
- return t.recusar(a, "somente-leitura"), null;
709
- const r = t.doc.elementosSelecionados().filter((i) => !t.mapa().travado(i));
710
- return r.length < e ? (t.recusar(a, "sem-selecao"), null) : r;
711
- }
712
- function J(t, a, e) {
713
- return "ok" in e ? e.ok : (t.recusar(a, e.motivo === "texto" ? "texto-sem-ancoras" : e.motivo === "tipos-incompativeis" || e.motivo === "sem-forma-fechada" ? "tipo-nao-suportado" : "geometria-invalida"), null);
714
- }
715
- function D(t, a) {
716
- const e = y(t, "ordem");
717
- return !e || !["frente", "tras", "avancar", "recuar"].includes(a) ? !1 : (t.aplicar(st(t.doc.elementos, e.map((r) => r.id), a, t.camadas), "ordem"), !0);
718
- }
719
- function ye(t) {
720
- const a = y(t, "agrupar", 2);
721
- return a ? (t.aplicar(nt(t.doc.elementos, a.map((e) => e.id), t.gerarId("grupo"), t.camadas), "agrupar"), !0) : !1;
722
- }
723
- function Se(t) {
724
- const a = y(t, "desagrupar");
725
- if (!a) return !1;
726
- const e = a.map((r) => r.id);
727
- return t.isolado && a.some((r) => r.grupoId === t.isolado) && t.isolar(null), t.aplicar(ct(t.doc.elementos, e), "desagrupar"), !0;
728
- }
729
- function sa(t, a) {
730
- const e = y(t, a === "bloqueado" ? "bloquear" : "ocultar");
731
- if (!e) return !1;
732
- const r = new Set(e.map((i) => i.id));
733
- return t.selecionar([]), t.aplicar(t.doc.elementos.map((i) => r.has(i.id) ? { ...i, [a]: !0 } : i), a === "bloqueado" ? "bloquear" : "ocultar"), !0;
734
- }
735
- function na(t, a) {
736
- if (t.somenteLeitura)
737
- return t.recusar("liberar", "somente-leitura"), !1;
738
- const e = [], r = t.doc.elementos.map((i) => {
739
- if (!i[a]) return i;
740
- e.push(i.id);
741
- const o = { ...i };
742
- return delete o[a], o;
743
- });
744
- return e.length === 0 ? !1 : (t.aplicar(r, a === "bloqueado" ? "bloquear" : "ocultar"), t.selecionar(e), !0);
745
- }
746
- function Er(t, a, e = "selecao") {
747
- const r = y(t, "alinhar");
748
- if (!r) return !1;
749
- let i = { tipo: "selecao" };
750
- e === "folha" ? i = { tipo: "caixa", caixa: { x: 0, y: 0, largura: t.folha.largura, altura: t.folha.altura } } : e === "chave" ? i = { tipo: "chave", id: t.doc.selecao[0] } : e && typeof e == "object" && (i = { tipo: "caixa", caixa: e });
751
- const o = lt(r, a, i);
752
- return o.length === 0 ? !1 : (t.aplicarSubstituicoes(o, "alinhar"), !0);
753
- }
754
- function xr(t, a, e = "espacos", r) {
755
- const i = y(t, "distribuir", 2);
756
- if (!i) return !1;
757
- const o = ut(i, a === "vertical" ? "vertical" : "horizontal", e === "centros" ? "centros" : "espacos", va(r) ? r : void 0);
758
- return o.length === 0 ? !1 : (t.aplicarSubstituicoes(o, "distribuir"), !0);
759
- }
760
- function Ma(t, a, e, r) {
761
- const i = ne(B(a, t.camadas), t.gerarId, e);
762
- return w(t, i, r);
763
- }
764
- function Tr(t, a = [K, K]) {
765
- const e = y(t, "duplicar");
766
- if (!e) return !1;
767
- const r = va(a == null ? void 0 : a[0]) && va(a == null ? void 0 : a[1]) ? a : [K, K], i = Ma(t, e, r, "duplicar");
768
- return t.ultimaTransformacao = { matriz: F(r[0], r[1]), duplicar: !0 }, i.length > 0;
769
- }
770
- function Fa(t, a, e = !1) {
771
- te(a) && (t.ultimaTransformacao = { matriz: a, duplicar: e });
772
- }
773
- function Pe(t) {
774
- const a = t.ultimaTransformacao;
775
- if (!a)
776
- return t.recusar("transformar-de-novo", "nada-a-refazer"), !1;
777
- const e = y(t, "transformar-de-novo");
778
- if (!e) return !1;
779
- if (a.duplicar) {
780
- const i = Ma(t, e, [0, 0], "duplicar");
781
- return i.length === 0 ? !1 : (t.aplicarSubstituicoes(T(i, a.matriz), "transformar"), t.ultimaTransformacao = a, !0);
782
- }
783
- const r = W(t, a.matriz, "transformar");
784
- return t.ultimaTransformacao = a, r;
785
- }
786
- function za(t) {
787
- var e, r, i, o;
788
- const a = t.doc.elementosSelecionados();
789
- if (a.length === 0)
790
- return t.recusar("copiar", "sem-selecao"), !1;
791
- q.elementos = JSON.parse(JSON.stringify(B(a, t.camadas))), q.colagens = 0;
792
- try {
793
- const s = typeof navigator < "u" ? navigator : void 0;
794
- (o = (i = (r = (e = s == null ? void 0 : s.clipboard) == null ? void 0 : e.writeText) == null ? void 0 : r.call(e, JSON.stringify({ tipo: "ui-canvas-prancha", elementos: q.elementos }))) == null ? void 0 : i.catch) == null || o.call(i, () => {
795
- });
796
- } catch {
797
- }
798
- return t.anunciar(a.length === 1 ? "Elemento copiado" : `${a.length} elementos copiados`), !0;
799
- }
800
- function Ae(t) {
801
- const a = y(t, "recortar");
802
- if (!a || !za(t)) return !1;
803
- const e = new Set(a.map((r) => r.id));
804
- return t.aplicar(t.doc.elementos.filter((r) => !e.has(r.id)), "recortar"), !0;
805
- }
806
- function Me(t, a = !1) {
807
- if (q.elementos.length === 0)
808
- return t.recusar("colar", "sem-selecao"), !1;
809
- if (t.somenteLeitura)
810
- return t.recusar("colar", "somente-leitura"), !1;
811
- q.colagens++;
812
- const e = a ? 0 : K * q.colagens;
813
- return Ma(t, q.elementos, [e, e], "colar").length > 0;
814
- }
815
- function wr(t, a) {
816
- const e = a.aparencia ? JSON.parse(JSON.stringify(a.aparencia)) : void 0;
817
- t.emitir("prancha-conta-gotas", { elemento: a, aparencia: e });
818
- const r = t.doc.elementosSelecionados().filter((i) => i.id !== a.id && !t.mapa().travado(i));
819
- return r.length === 0 ? (t.opcoesFerramentas = { ...t.opcoesFerramentas, aparencia: e }, t.anunciar("Aparência guardada para as formas novas"), !0) : t.somenteLeitura ? (t.recusar("conta-gotas", "somente-leitura"), !1) : (t.aplicarSubstituicoes(se(r, e), "conta-gotas"), !0);
820
- }
821
- function Ir(t, a) {
822
- const e = y(t, "aparencia");
823
- return e ? (t.aplicarSubstituicoes(se(e, a ?? void 0), "aparencia"), !0) : !1;
824
- }
825
- function Dr(t, a) {
826
- const e = y(t, "mover-camada");
827
- return !e || typeof a != "string" || !t.camadas.some((r) => r.id === a) ? (e && t.recusar("mover-camada", "id-invalido", typeof a == "string" ? a : void 0), !1) : (t.aplicarSubstituicoes(e.map((r) => ({ ...r, camadaId: a })), "camada"), !0);
828
- }
829
- function ze(t) {
830
- const a = y(t, "mascara", 2);
831
- if (!a) return !1;
832
- const e = J(t, "mascara", dt(t.doc.elementos, a.map((r) => r.id), t.gerarId("grupo"), t.camadas));
833
- return e ? (t.aplicar(e, "mascara"), !0) : !1;
834
- }
835
- function Ce(t) {
836
- const a = y(t, "liberar-mascara");
837
- if (!a) return !1;
838
- const e = ht(t.doc.elementos, a.map((r) => r.id));
839
- return e.every((r, i) => r === t.doc.elementos[i]) ? (t.recusar("liberar-mascara", "tipo-nao-suportado"), !1) : (t.aplicar(e, "mascara"), !0);
840
- }
841
- function Ee(t, a = 0.01) {
842
- const e = y(t, "unir", 2);
843
- if (!e) return !1;
844
- const r = B(e, t.camadas), i = J(t, "unir", ft(r, a));
845
- if (!i) return !1;
846
- const o = new Set(r.slice(1).map((s) => s.id));
847
- return t.aplicar(t.doc.elementos.filter((s) => !o.has(s.id)).map((s) => s.id === i.id ? i : s), "unir"), !0;
848
- }
849
- function qr(t) {
850
- const a = y(t, "dividir", 2);
851
- if (!a) return !1;
852
- const e = B(a, t.camadas), r = [...e].reverse().find((n) => n.geometria.tipo === "linha" || n.geometria.tipo === "caminho" && n.geometria.geometria.tipo === "LineString"), i = e.find((n) => n !== r);
853
- if (!r || !i)
854
- return t.recusar("dividir", "tipo-nao-suportado"), !1;
855
- const o = J(t, "dividir", mt(i, r, t.gerarId));
856
- if (!o) return !1;
857
- const s = [];
858
- for (const n of t.doc.elementos)
859
- n.id !== r.id && (n.id === i.id ? s.push(...o) : s.push(n));
860
- return t.aplicar(s, "dividir"), t.selecionar(o.map((n) => n.id)), !0;
861
- }
862
- function _r(t, a) {
863
- const e = y(t, "deslocar-caminho");
864
- if (!e) return !1;
865
- const r = e.map((i) => J(t, "deslocar-caminho", pt(i, a, t.gerarId("caminho")))).filter((i) => !!i);
866
- return r.length > 0 && w(t, r, "deslocar-caminho").length > 0;
867
- }
868
- function Ca(t, a, e, r) {
869
- const i = y(t, a);
870
- if (!i) return !1;
871
- const o = [];
872
- for (const s of i) {
873
- const n = r(s), c = n && typeof n == "object" && ("ok" in n || "motivo" in n) ? J(t, a, n) : n;
874
- c && o.push(c);
875
- }
876
- return o.length === 0 ? !1 : (t.aplicarSubstituicoes(o, e), !0);
877
- }
878
- const Fr = (t, a = 0.2) => Ca(t, "simplificar", "simplificar", (e) => gt(e, a)), kr = (t) => Ca(t, "contorno-traco", "contorno-traco", (a) => vt(a)), Rr = (t) => Ca(t, "converter-caminho", "converter-caminho", (a) => a.geometria.tipo === "caminho" ? null : bt(a)), Lr = 7, xe = 22, ka = 6, G = (t, a) => t.setTransform(a, 0, 0, a, 0, 0);
879
- function A(t, a, e = !0) {
880
- if (a.length !== 0) {
881
- t.moveTo(a[0][0], a[0][1]);
882
- for (let r = 1; r < a.length; r++) t.lineTo(a[r][0], a[r][1]);
883
- e && t.closePath();
884
- }
885
- }
886
- function ha(t, a, e, r, i) {
887
- const o = e / 2;
888
- t.beginPath(), A(t, [[a[0] - o, a[1] - o], [a[0] + o, a[1] - o], [a[0] + o, a[1] + o], [a[0] - o, a[1] + o]]), t.fillStyle = r, t.fill(), t.strokeStyle = i, t.stroke();
889
- }
890
- function Y(t, a, e) {
891
- const r = [];
892
- for (let i = 0; i < 16; i++) r.push([a[0] + e * Math.cos(i * Math.PI / 8), a[1] + e * Math.sin(i * Math.PI / 8)]);
893
- A(t, r);
894
- }
895
- function Or(t, a) {
896
- const e = a.grade;
897
- if (!e || !(e > 0)) return;
898
- const { vista: r, folha: i } = a;
899
- let o = e;
900
- for (; o * r.zoom < 8; ) o *= 2;
901
- const [s, n] = r.paraTela([0, 0]), [c, l] = r.paraTela([i.largura, i.altura]);
902
- t.beginPath();
903
- for (let d = 0; d <= i.largura + 1e-9; d += o) {
904
- const h = Math.round(r.paraTela([d, 0])[0]) + 0.5;
905
- t.moveTo(h, n), t.lineTo(h, l);
906
- }
907
- for (let d = 0; d <= i.altura + 1e-9; d += o) {
908
- const h = Math.round(r.paraTela([0, d])[1]) + 0.5;
909
- t.moveTo(s, h), t.lineTo(c, h);
910
- }
911
- t.strokeStyle = a.cores.grade, t.lineWidth = 1, t.setLineDash([]), t.globalAlpha = 1, t.stroke();
912
- }
913
- function Nr(t, a, e, r) {
914
- const i = a.matrizDispositivo();
915
- t.setTransform(i.a, i.b, i.c, i.d, i.e, i.f), t.globalAlpha = 0.6, t.fillStyle = r, t.fillRect(0, 0, e.largura, e.altura);
916
- }
917
- function jr(t, a) {
918
- const { vista: e, folha: r, cores: i } = a;
919
- t.save(), G(t, e.dpr), t.globalAlpha = 1, t.fillStyle = i.mesa, t.fillRect(0, 0, e.largura, e.altura), t.restore();
920
- const o = e.matrizDispositivo();
921
- N(t, [], { matriz: o, fundo: { cor: i.papel, largura: r.largura, altura: r.altura } }), t.save(), G(t, e.dpr), Or(t, a), t.restore(), N(t, a.elementos, { matriz: o, camadas: a.camadas }), a.isolados && a.isolados.length > 0 && (t.save(), Nr(t, e, r, i.papel), t.restore(), N(t, a.isolados, { matriz: o, camadas: a.camadas })), t.save(), G(t, e.dpr);
922
- const [s, n] = e.paraTela([0, 0]), [c, l] = e.paraTela([r.largura, r.altura]);
923
- t.beginPath(), A(t, [[s, n], [c, n], [c, l], [s, l]]), t.strokeStyle = i.bordaPapel, t.lineWidth = 1, t.stroke();
924
- const d = a.margens;
925
- if (d && d.largura > 0 && d.altura > 0) {
926
- const [h, u] = e.paraTela([d.x, d.y]), [m, p] = e.paraTela([d.x + d.largura, d.y + d.altura]);
927
- t.beginPath(), A(t, [[h, u], [m, u], [m, p], [h, p]]), t.strokeStyle = i.guiaInteligente, t.globalAlpha = 0.6, t.setLineDash([6, 4]), t.stroke(), t.setLineDash([]), t.globalAlpha = 1;
928
- }
929
- t.restore();
930
- }
931
- function Ra(t, a, e) {
932
- const r = Aa(a);
933
- if (!r) return;
934
- const i = r.tipo === "Polygon" ? r.aneis : r.partes && r.partes.length > 1 ? r.partes : [r.coordenadas];
935
- for (const o of i) A(t, o.map((s) => e.paraTela(s)), r.tipo === "Polygon");
936
- }
937
- function La(t, a) {
938
- return ["no", "ne", "se", "so"].map((e) => a.paraTela(St(t.quadro, Pt(t, e))));
939
- }
940
- function Oa(t, a, e) {
941
- if (a.orientacao === "horizontal") {
942
- const r = Math.round(e.paraTela([0, a.posicao])[1]) + 0.5;
943
- t.moveTo(0, r), t.lineTo(e.largura, r);
944
- } else {
945
- const r = Math.round(e.paraTela([a.posicao, 0])[0]) + 0.5;
946
- t.moveTo(r, 0), t.lineTo(r, e.altura);
947
- }
948
- }
949
- function fa(t, a, e, r) {
950
- typeof t.fillText == "function" && (t.font = "11px sans-serif", t.fillStyle = r, t.fillText(a, e[0], e[1]));
951
- }
952
- function Gr(t, a) {
953
- const { vista: e, cores: r, ui: i } = a;
954
- t.save(), G(t, e.dpr), typeof t.clearRect == "function" && t.clearRect(0, 0, e.largura, e.altura), t.globalAlpha = 1, t.lineWidth = 1, t.setLineDash([]), t.beginPath();
955
- for (const s of a.guias) Oa(t, s, e);
956
- t.strokeStyle = r.guia, t.stroke(), i.guiaArrastada && (t.beginPath(), Oa(t, i.guiaArrastada.guia, e), t.setLineDash([4, 3]), t.stroke(), t.setLineDash([])), a.hover && !a.selecionados.includes(a.hover) && (t.beginPath(), Ra(t, a.hover, e), t.strokeStyle = r.selecao, t.stroke()), a.emGesto.length > 0 && (N(t, a.emGesto, { matriz: e.matrizDispositivo() }), G(t, e.dpr), t.globalAlpha = 1, t.lineWidth = 1, t.setLineDash([])), i.previa && (N(t, [i.previa], { matriz: e.matrizDispositivo() }), G(t, e.dpr), t.globalAlpha = 1, t.lineWidth = 1, t.setLineDash([]));
957
- for (const s of i.pontosPrevia) ha(t, e.paraTela(s), ka, r.alca, r.selecao);
958
- const o = i.edicao ? a.selecionados.find((s) => s.id === i.edicao.id) ?? null : null;
959
- for (const s of a.selecionados) {
960
- const n = yt(s);
961
- !n || s === o || (t.beginPath(), A(t, La(n, e)), t.strokeStyle = r.selecao, t.stroke());
962
- }
963
- if (o && i.edicao) {
964
- t.beginPath(), Ra(t, o, e), t.strokeStyle = r.selecao, t.stroke();
965
- const s = Sa(o), n = ce(o);
966
- t.beginPath(), i.edicao.ancoras.forEach((c) => {
967
- const l = s[c], d = n[c];
968
- if (!(!l || !d))
969
- for (const h of [d.entrada, d.saida]) h && A(t, [e.paraTela(l), e.paraTela(h)], !1);
970
- }), t.stroke(), i.edicao.ancoras.forEach((c) => {
971
- const l = n[c];
972
- if (l)
973
- for (const d of [l.entrada, l.saida])
974
- d && (t.beginPath(), Y(t, e.paraTela(d), 3), t.fillStyle = r.selecao, t.fill());
975
- }), s.forEach((c, l) => ha(t, e.paraTela(c), ka, i.edicao.ancoras.includes(l) ? r.selecao : r.alca, r.selecao));
976
- } else if (a.caixaTransformacao && a.selecionados.length > 0) {
977
- const s = Pa(a.selecionados);
978
- if (s) {
979
- const n = le(s, xe / e.zoom);
980
- t.beginPath(), A(t, La(s, e)), A(t, [e.paraTela(n.alcas.n), e.paraTela(n.rotacao)], !1), t.strokeStyle = r.selecao, t.stroke();
981
- for (const l of Object.values(n.alcas)) ha(t, e.paraTela(l), Lr, r.alca, r.selecao);
982
- t.beginPath(), Y(t, e.paraTela(n.rotacao), 4), t.fillStyle = r.alca, t.fill(), t.stroke();
983
- for (const l of a.marcasCantos ?? [])
984
- t.beginPath(), Y(t, e.paraTela(l), 3.5), t.fillStyle = r.alca, t.fill(), t.strokeStyle = r.selecao, t.stroke();
985
- const c = e.paraTela(i.pivo ?? n.centro);
986
- t.beginPath(), Y(t, c, 4), A(t, [[c[0] - 7, c[1]], [c[0] + 7, c[1]]], !1), A(t, [[c[0], c[1] - 7], [c[0], c[1] + 7]], !1), t.stroke();
987
- }
988
- }
989
- if (i.linhasInteligentes.length > 0) {
990
- t.beginPath();
991
- for (const s of i.linhasInteligentes) {
992
- const n = e.paraTela(s.orientacao === "vertical" ? [s.posicao, s.de] : [s.de, s.posicao]), c = e.paraTela(s.orientacao === "vertical" ? [s.posicao, s.ate] : [s.ate, s.posicao]);
993
- A(t, [n, c], !1);
994
- }
995
- t.strokeStyle = r.guiaInteligente, t.stroke();
996
- for (const s of i.linhasInteligentes) {
997
- if (s.distancia === void 0) continue;
998
- const n = e.paraTela(s.orientacao === "vertical" ? [s.posicao, (s.de + s.ate) / 2] : [(s.de + s.ate) / 2, s.posicao]);
999
- fa(t, `${Math.round(s.distancia * 100) / 100} mm`, [n[0] + 4, n[1] - 4], r.guiaInteligente);
1000
- }
1001
- }
1002
- if (i.caixaSelecao) {
1003
- const s = e.paraTela(i.caixaSelecao.de), n = e.paraTela(i.caixaSelecao.ate);
1004
- t.beginPath(), A(t, [s, [n[0], s[1]], n, [s[0], n[1]]]), t.setLineDash(i.caixaSelecao.crossing ? [5, 3] : []), t.strokeStyle = r.selecao, t.stroke(), t.setLineDash([]);
1005
- }
1006
- if (i.snap) {
1007
- const s = e.paraTela(i.snap.coordenada);
1008
- t.beginPath(), A(t, [[s[0] - 5, s[1] - 5], [s[0] + 5, s[1] - 5], [s[0] + 5, s[1] + 5], [s[0] - 5, s[1] + 5]]), t.strokeStyle = r.snap, t.stroke(), fa(t, i.snap.tipo, [s[0] + 8, s[1] - 8], r.snap);
1009
- }
1010
- if (i.rotulo) {
1011
- const s = e.paraTela(i.rotulo.em);
1012
- fa(t, i.rotulo.texto, [s[0] + 12, s[1] + 18], r.selecao);
1013
- }
1014
- t.restore();
1015
- }
1016
- const $r = 14;
1017
- function Te(t) {
1018
- const a = t.doc.elementosSelecionados();
1019
- return a.length !== 1 || t.ferramenta !== "selecao" || t.somenteLeitura ? null : It(t.ui.substitutos.get(a[0].id) ?? a[0], $r / t.vista.zoom);
1020
- }
1021
- const _ = (t, a) => Math.hypot(t[0] - a[0], t[1] - a[1]);
1022
- function Na(t, a, e) {
1023
- const r = t.doc.elementosSelecionados(), i = r.length > 0 ? Pa(r) : null;
1024
- if (!i) return null;
1025
- const o = e ? 19 : 6, s = t.vista, n = le(i, xe / s.zoom), c = Te(t);
1026
- if (c) {
1027
- const l = c.findIndex((d) => _(s.paraTela(d), a) <= o);
1028
- if (l >= 0) return { tipo: "canto", canto: l };
1029
- }
1030
- if (_(s.paraTela(t.ui.pivo ?? n.centro), a) <= o) return { tipo: "pivo" };
1031
- if (_(s.paraTela(n.rotacao), a) <= o) return { tipo: "rotacao" };
1032
- for (const l of At) if (_(s.paraTela(n.alcas[l]), a) <= o) return { tipo: "escala", alca: l };
1033
- return null;
1034
- }
1035
- function Br(t, a, e, r) {
1036
- const i = t.doc.elementosSelecionados().filter((n) => !n.bloqueado), o = Pa(i);
1037
- if (!o || i.length === 0) return null;
1038
- if (a.tipo === "pivo") return { tipo: "pivo" };
1039
- if (a.tipo === "canto") {
1040
- const n = i[0], c = ue(n), l = de(n, a.canto ?? 0, e);
1041
- return i.length !== 1 || !c || l === null ? null : { tipo: "canto", original: n, indice: a.canto ?? 0, raio0: c[a.canto ?? 0], profundidade0: l };
1042
- }
1043
- if (a.tipo === "rotacao") return { tipo: "rotacao", pivo: la(t) ?? e, inicio: e, originais: i };
1044
- const s = a.alca;
1045
- return r.ctrl && (s === "n" || s === "s" || s === "e" || s === "o") ? { tipo: "cisalhamento", caixa: o, alca: s, originais: i } : { tipo: "escala", caixa: o, alca: s, originais: i };
1046
- }
1047
- function Hr(t, a, e) {
1048
- const r = 50 / t.vista.zoom, i = t.doc.indice.consultarCaixa(a, r).filter((s) => !e.has(s.id) && !s.oculto), o = [{ x: 0, y: 0, largura: t.folha.largura, altura: t.folha.altura }];
1049
- for (const s of i.slice(0, 200)) {
1050
- const n = X(s);
1051
- n && o.push(n);
1052
- }
1053
- return o;
1054
- }
1055
- function Vr(t) {
1056
- let a = 1 / 0, e = 1 / 0, r = -1 / 0, i = -1 / 0;
1057
- for (const o of t) {
1058
- const s = Dt(o);
1059
- s && (a = Math.min(a, s.x), e = Math.min(e, s.y), r = Math.max(r, s.x + s.largura), i = Math.max(i, s.y + s.altura));
1060
- }
1061
- return a <= r ? { x: a, y: e, largura: r - a, altura: i - e } : null;
1062
- }
1063
- function Kr(t, a, e = !1, r = !1) {
1064
- const i = t.doc.elementosSelecionados().filter((n) => !n.bloqueado);
1065
- if (i.length === 0) return null;
1066
- const o = i.length <= 200 ? i.length === 1 ? X(i[0]) : Vr(i) : null, s = t.snapLigado && i.length <= 200 ? ee(a, i, t.vista.zoom, { toleranciaPx: t.toleranciaPx(e), meio: !1, aresta: !1 }) : null;
1067
- return { tipo: "mover", inicio: s ? s.coordenada : a, originais: i, caixa: o, duplicar: r };
1068
- }
1069
- function Ur(t, a, e, r) {
1070
- var s, n, c;
1071
- const i = t.ui;
1072
- i.linhasInteligentes = [], i.snap = null;
1073
- let o = [];
1074
- switch (a.tipo) {
1075
- case "pivo":
1076
- i.pivo = t.snapPonto(e, { toque: r.toque, desligado: r.alt }).ponto;
1077
- break;
1078
- case "mover": {
1079
- let l = e[0] - a.inicio[0], d = e[1] - a.inicio[1];
1080
- r.shift && (Math.abs(l) >= Math.abs(d) ? d = 0 : l = 0);
1081
- const h = new Set(a.originais.map((m) => m.id));
1082
- if ((!r.alt || a.duplicar) && t.snapLigado) {
1083
- const m = t.snapPonto([a.inicio[0] + l, a.inicio[1] + d], { excluir: h, grade: !1, toque: r.toque });
1084
- if (m.resultado)
1085
- l = m.ponto[0] - a.inicio[0], d = m.ponto[1] - a.inicio[1];
1086
- else if (a.caixa && t.guiasInteligentes) {
1087
- const p = { ...a.caixa, x: a.caixa.x + l, y: a.caixa.y + d }, v = wt(p, Hr(t, p, h), 6 / t.vista.zoom);
1088
- if (l += v.correcao[0], d += v.correcao[1], i.linhasInteligentes = v.linhas, v.linhas.length === 0) {
1089
- const b = t.snapPonto([a.inicio[0] + l, a.inicio[1] + d], { excluir: h, toque: r.toque });
1090
- ((s = b.resultado) == null ? void 0 : s.tipo) === "grade" && (l = b.ponto[0] - a.inicio[0], d = b.ponto[1] - a.inicio[1]);
1091
- }
1092
- }
1093
- }
1094
- a.matriz = F(l, d), o = T(a.originais, a.matriz), a.duplicar && (i.copiasEmGesto = o, o = []);
1095
- const u = (m) => Math.round(m * 100) / 100;
1096
- i.rotulo = { texto: `Δ ${u(l)}, ${u(d)} mm`, em: e };
1097
- break;
1098
- }
1099
- case "escala": {
1100
- const l = t.snapPonto(e, { excluir: a.originais.map((h) => h.id), toque: r.toque }).ponto, d = Tt(a.caixa, a.alca, l, { proporcional: r.shift, doCentro: r.alt });
1101
- d && (a.matriz = d, o = T(a.originais, d));
1102
- break;
1103
- }
1104
- case "cisalhamento": {
1105
- const l = xt(a.caixa, a.alca, e);
1106
- l && (a.matriz = l, o = T(a.originais, l));
1107
- break;
1108
- }
1109
- case "rotacao": {
1110
- const l = Et(a.pivo, a.inicio, e, r.shift ? Math.PI / 4 : void 0);
1111
- a.matriz = l.matriz, o = T(a.originais, l.matriz), i.rotulo = { texto: `${Math.round(l.angulo * 180 / Math.PI * 10) / 10}°`, em: e };
1112
- break;
1113
- }
1114
- case "ancora": {
1115
- const l = ((n = i.edicao) == null ? void 0 : n.ancoras) ?? [];
1116
- if (l.length > 1 && l.includes(a.indice)) {
1117
- const d = re(a.original, l, e[0] - a.inicio[0], e[1] - a.inicio[1]);
1118
- d && (o = [d]);
1119
- } else {
1120
- const d = t.snapPonto(e, { excluir: [a.original.id], toque: r.toque, desligado: r.alt }).ponto, h = Ct(a.original, a.indice, d);
1121
- h && (o = [h]);
1122
- }
1123
- break;
1124
- }
1125
- case "alca-bezier": {
1126
- const l = zt(a.original, a.indice, a.qual, e, !r.alt);
1127
- l && (o = [l]);
1128
- break;
1129
- }
1130
- case "canto": {
1131
- const l = de(a.original, a.indice, e);
1132
- if (l === null) break;
1133
- const d = Mt(a.original, r.alt ? a.indice : null, a.raio0 + l - a.profundidade0);
1134
- if (d) {
1135
- o = [d];
1136
- const h = ((c = ue(d)) == null ? void 0 : c[a.indice]) ?? 0;
1137
- i.rotulo = { texto: `R ${Math.round(h * 100) / 100} mm`, em: e };
1138
- }
1139
- break;
1140
- }
1141
- }
1142
- i.substitutos = new Map(o.map((l) => [l.id, l])), t.agendar();
1143
- }
1144
- function Zr(t, a) {
1145
- const e = [...t.ui.substitutos.values()];
1146
- if (t.ui.substitutos = /* @__PURE__ */ new Map(), t.ui.copiasEmGesto = [], t.ui.linhasInteligentes = [], t.ui.snap = null, t.ui.rotulo = null, a.tipo === "mover" && a.duplicar) {
1147
- if (a.matriz) {
1148
- const i = T(ne(a.originais, t.gerarId), a.matriz);
1149
- w(t, i, "duplicar"), Fa(t, a.matriz, !0);
1150
- }
1151
- t.agendar();
1152
- return;
1153
- }
1154
- if ((a.tipo === "mover" || a.tipo === "escala" || a.tipo === "rotacao" || a.tipo === "cisalhamento") && a.matriz && e.length > 0 && Fa(t, a.matriz, !1), a.tipo === "pivo" || e.length === 0) {
1155
- t.agendar();
1156
- return;
1157
- }
1158
- const r = a.tipo === "mover" ? "mover" : a.tipo === "ancora" || a.tipo === "alca-bezier" ? "editar-ancoras" : a.tipo === "canto" ? "cantos" : "transformar";
1159
- (a.tipo === "rotacao" || a.tipo === "escala" || a.tipo === "cisalhamento") && t.ui.pivo && a.tipo !== "rotacao" && (t.ui.pivo = null), t.aplicarSubstituicoes(e, r);
1160
- }
1161
- function ja(t, a, e) {
1162
- const r = t.ui.edicao, i = r ? t.doc.obter(r.id) : void 0;
1163
- if (!r || !i) return null;
1164
- const o = e ? 19 : 6, s = t.vista, n = ce(i);
1165
- for (const d of r.ancoras) {
1166
- const h = n[d];
1167
- if (h != null && h.saida && _(s.paraTela(h.saida), a) <= o) return { tipo: "alca", indice: d, qual: "saida" };
1168
- if (h != null && h.entrada && _(s.paraTela(h.entrada), a) <= o) return { tipo: "alca", indice: d, qual: "entrada" };
1169
- }
1170
- const c = Sa(i);
1171
- let l = null;
1172
- return c.forEach((d, h) => {
1173
- const u = _(s.paraTela(d), a);
1174
- u <= o && (!l || u < l.d) && (l = { indice: h, d: u });
1175
- }), l ? { tipo: "ancora", indice: l.indice } : null;
1176
- }
1177
- function Xr(t, a, e) {
1178
- const r = t.ui.edicao, i = r ? t.doc.obter(r.id) : void 0;
1179
- if (!i) return [];
1180
- const o = Math.min(a[0], e[0]), s = Math.max(a[0], e[0]), n = Math.min(a[1], e[1]), c = Math.max(a[1], e[1]);
1181
- return Sa(i).map((l, d) => l[0] >= o && l[0] <= s && l[1] >= n && l[1] <= c ? d : -1).filter((l) => l >= 0);
1182
- }
1183
- const Wr = ["conta-gotas", "adicionar-ancora", "excluir-ancora", "converter-ancora"], Jr = (t) => Wr.includes(t), we = (t, a) => (a ? 19 : 8) / t.vista.zoom;
1184
- function Yr(t, a, e) {
1185
- const r = we(t, e), i = t.doc.elementosSelecionados(), o = ra(a, t.candidatosEm(a, r + 2), { tolerancia: r, camadas: t.camadas });
1186
- return o && !i.includes(o) ? [...i, o] : i;
1187
- }
1188
- function Qr(t, a, e) {
1189
- const r = t.ferramenta, i = we(t, e);
1190
- if (r === "conta-gotas") {
1191
- const o = ra(a, t.candidatosEm(a, i + 2), { tolerancia: i, camadas: t.camadas, incluirBloqueados: !0 });
1192
- return o ? wr(t, o) : !1;
1193
- }
1194
- if (t.somenteLeitura)
1195
- return t.recusar("editar-ancoras", "somente-leitura"), !1;
1196
- for (const o of Yr(t, a, e)) {
1197
- if (!t.podeSelecionar(o)) continue;
1198
- let s = null;
1199
- if (r === "adicionar-ancora") {
1200
- const n = qt(o, a, i);
1201
- if (n === null) continue;
1202
- s = _t(o, n, a);
1203
- } else {
1204
- const n = Ft(o, a, i);
1205
- if (n === null) continue;
1206
- if (s = r === "excluir-ancora" ? ie(o, n) : kt(o, n), !s)
1207
- return t.recusar(r, r === "excluir-ancora" ? "minimo-de-ancoras" : "tipo-nao-suportado", o.id), !1;
1208
- }
1209
- return s ? (t.aplicarSubstituicoes([s], "editar-ancoras"), t.doc.selecao.includes(s.id) || t.selecionar([s.id], "substituir", !1), !0) : (t.recusar(r, o.geometria.tipo === "texto" ? "texto-sem-ancoras" : "tipo-nao-suportado", o.id), !1);
1210
- }
1211
- return !1;
1212
- }
1213
- const ai = 4, Ga = 3;
1214
- class ei {
1215
- constructor(a, e, r) {
1216
- f(this, "gesto", { tipo: "nenhum" });
1217
- /** Espaço segurado (pan temporário). */
1218
- f(this, "espaco", !1);
1219
- f(this, "ultimoClique", null);
1220
- this.c = a, this.viewport = e, this.ferramentas = r;
1221
- }
1222
- conectar(a, e, r) {
1223
- a.add(this.viewport, "pointerdown", (i) => this.pressionar(i)), a.add(this.viewport, "pointermove", (i) => this.mover(i)), a.add(this.viewport, "pointerup", (i) => this.soltar(i)), a.add(this.viewport, "pointercancel", () => this.cancelar()), a.add(this.viewport, "pointerleave", () => this.sair()), a.add(this.viewport, "wheel", (i) => this.roda(i), { passive: !1 }), a.add(this.viewport, "contextmenu", (i) => {
1224
- this.ferramentas.emAndamento && i.preventDefault();
1225
- }), a.add(e, "pointerdown", (i) => this.puxarGuia(i, "horizontal")), a.add(r, "pointerdown", (i) => this.puxarGuia(i, "vertical"));
1226
- }
1227
- get ocupado() {
1228
- return this.gesto.tipo !== "nenhum" || this.ferramentas.emAndamento;
1229
- }
1230
- local(a) {
1231
- var r, i;
1232
- const e = (i = (r = this.viewport).getBoundingClientRect) == null ? void 0 : i.call(r);
1233
- return [a.clientX - ((e == null ? void 0 : e.left) ?? 0), a.clientY - ((e == null ? void 0 : e.top) ?? 0)];
1234
- }
1235
- mod(a) {
1236
- return { shift: a.shiftKey, alt: a.altKey, ctrl: a.ctrlKey || a.metaKey, toque: a.pointerType === "touch" };
1237
- }
1238
- capturar(a) {
1239
- var e, r;
1240
- try {
1241
- (r = (e = this.viewport).setPointerCapture) == null || r.call(e, a.pointerId);
1242
- } catch {
1243
- }
1244
- }
1245
- cursor(a) {
1246
- this.viewport.dataset.cursor !== a && (this.viewport.dataset.cursor = a);
1247
- }
1248
- guiaSob(a) {
1249
- const e = this.c.vista;
1250
- for (let r = this.c.guias.length - 1; r >= 0; r--) {
1251
- const i = this.c.guias[r];
1252
- if ((i.orientacao === "horizontal" ? Math.abs(e.paraTela([0, i.posicao])[1] - a[1]) : Math.abs(e.paraTela([i.posicao, 0])[0] - a[0])) <= ai) return r;
1253
- }
1254
- return null;
1255
- }
1256
- pressionar(a) {
1257
- if (a.button === 2) return;
1258
- try {
1259
- this.viewport.focus({ preventScroll: !0 });
1260
- } catch {
1261
- }
1262
- const e = this.local(a), r = this.c.vista.paraFolha(e[0], e[1]), i = this.mod(a), o = this.c.ferramenta;
1263
- if (this.capturar(a), a.button === 1 || this.espaco || o === "mao") {
1264
- this.gesto = { tipo: "pan", inicioPx: e, panInicial: [...this.c.vista.pan] }, this.cursor("arrastando");
1265
- return;
1266
- }
1267
- if (Jr(o)) {
1268
- Qr(this.c, r, i.toque);
1269
- return;
1270
- }
1271
- if (oa(o)) {
1272
- if (this.c.somenteLeitura) {
1273
- this.c.recusar("desenhar", "somente-leitura");
1274
- return;
1275
- }
1276
- this.gesto = { tipo: "desenho" }, this.ferramentas.pressionar(r, e, i);
1277
- return;
1278
- }
1279
- const s = Date.now(), n = !i.shift && !!this.ultimoClique && s - this.ultimoClique.t <= 400 && Math.hypot(e[0] - this.ultimoClique.x, e[1] - this.ultimoClique.y) <= 4;
1280
- if (this.ultimoClique = n ? null : { t: s, x: e[0], y: e[1] }, o === "selecao-direta" && this.c.ui.edicao) {
1281
- const u = ja(this.c, e, i.toque), m = this.c.doc.obter(this.c.ui.edicao.id);
1282
- if (u && m && !this.c.somenteLeitura) {
1283
- const p = this.c.ui.edicao;
1284
- u.tipo === "alca" ? this.gesto = { tipo: "selecao", gesto: { tipo: "alca-bezier", original: m, indice: u.indice, qual: u.qual }, inicioPx: e, moveu: !1 } : (i.shift ? p.ancoras = p.ancoras.includes(u.indice) ? p.ancoras.filter((v) => v !== u.indice) : [...p.ancoras, u.indice] : p.ancoras.includes(u.indice) || (p.ancoras = [u.indice]), this.gesto = { tipo: "selecao", gesto: { tipo: "ancora", original: m, indice: u.indice, inicio: r }, inicioPx: e, moveu: !1 }), this.c.agendar();
1285
- return;
1286
- }
1287
- }
1288
- if (o === "selecao" && !this.c.somenteLeitura) {
1289
- const u = Na(this.c, e, i.toque);
1290
- if (u) {
1291
- const m = Br(this.c, u, r, i);
1292
- if (m) {
1293
- this.gesto = { tipo: "selecao", gesto: m, inicioPx: e, moveu: !1 };
1294
- return;
1295
- }
1296
- }
1297
- }
1298
- const c = (i.toque ? 12 : 4) / this.c.vista.zoom, l = this.c.candidatosEm(r, c + 2).filter((u) => this.c.podeSelecionar(u)), d = ra(r, l, { tolerancia: c, camadas: this.c.camadas });
1299
- if (d) {
1300
- if (n && o === "selecao") {
1301
- if (d.grupoId && this.c.isolado !== d.grupoId) {
1302
- this.c.isolar(d.grupoId), this.c.selecionar([d.id], "substituir", !1);
1303
- return;
1304
- }
1305
- this.c.definirFerramenta("selecao-direta"), this.c.iniciarEdicao(d.id);
1306
- return;
1307
- }
1308
- if (o === "selecao-direta" ? this.c.iniciarEdicao(d.id) : i.shift ? this.c.selecionar([d.id], "alternar") : this.c.doc.selecao.includes(d.id) || this.c.selecionar([d.id]), this.c.somenteLeitura || !this.c.doc.selecao.includes(d.id)) return;
1309
- const u = Kr(this.c, r, i.toque, i.alt && o === "selecao");
1310
- u && (this.gesto = { tipo: "selecao", gesto: u, inicioPx: e, moveu: !1 });
1311
- return;
1312
- }
1313
- if (n && this.c.isolado) {
1314
- this.c.isolar(null);
1315
- return;
1316
- }
1317
- const h = o === "selecao" && !this.c.somenteLeitura ? this.guiaSob(e) : null;
1318
- if (h !== null) {
1319
- this.gesto = { tipo: "guia", indice: h }, this.c.ui.guiaArrastada = { guia: { ...this.c.guias[h] }, indice: h };
1320
- return;
1321
- }
1322
- this.gesto = { tipo: "caixa", de: r, dePx: e, aditivo: i.shift, moveu: !1 };
1323
- }
1324
- mover(a) {
1325
- const e = this.local(a), r = this.c.vista.paraFolha(e[0], e[1]), i = this.mod(a);
1326
- this.c.ui.ponteiro = r, this.c.emitir("prancha-ponteiro", { coordenada: r });
1327
- const o = this.gesto;
1328
- switch (o.tipo) {
1329
- case "pan":
1330
- this.c.vista.pan = [o.panInicial[0] + e[0] - o.inicioPx[0], o.panInicial[1] + e[1] - o.inicioPx[1]], this.c.emitirVista();
1331
- return;
1332
- case "desenho":
1333
- this.ferramentas.mover(r, e, i);
1334
- return;
1335
- case "selecao":
1336
- if (!o.moveu && Math.hypot(e[0] - o.inicioPx[0], e[1] - o.inicioPx[1]) < Ga) return;
1337
- o.moveu = !0, Ur(this.c, o.gesto, r, i);
1338
- return;
1339
- case "guia": {
1340
- const s = this.c.ui.guiaArrastada;
1341
- s && (s.guia = { ...s.guia, posicao: s.guia.orientacao === "horizontal" ? r[1] : r[0] }), this.c.agendar();
1342
- return;
1343
- }
1344
- case "caixa":
1345
- if (!o.moveu && Math.hypot(e[0] - o.dePx[0], e[1] - o.dePx[1]) < Ga) return;
1346
- o.moveu = !0, this.c.ui.caixaSelecao = { de: o.de, ate: r, crossing: r[0] < o.de[0] }, this.c.agendar();
1347
- return;
1348
- }
1349
- if (oa(this.c.ferramenta)) {
1350
- this.ferramentas.mover(r, e, i), this.cursor("mira");
1351
- return;
1352
- }
1353
- this.atualizarHover(r, e, i.toque);
1354
- }
1355
- atualizarHover(a, e, r) {
1356
- const i = this.c.ferramenta;
1357
- if (i === "mao" || this.espaco) {
1358
- this.cursor("mao");
1359
- return;
1360
- }
1361
- const o = i === "selecao" ? Na(this.c, e, r) : null, s = 4 / this.c.vista.zoom, n = ra(a, this.c.candidatosEm(a, s + 2).filter((l) => this.c.podeSelecionar(l)), { tolerancia: s, camadas: this.c.camadas }), c = (n == null ? void 0 : n.id) ?? null;
1362
- this.cursor(o ? o.tipo === "rotacao" ? "girar" : "mover" : i === "selecao-direta" && ja(this.c, e, r) ? "ancora" : n ? "mover" : "padrao"), c !== this.c.ui.hoverId ? (this.c.ui.hoverId = c, this.c.agendar()) : this.c.ui.ponteiro && this.c.agendar();
1363
- }
1364
- soltar(a) {
1365
- var o, s;
1366
- const e = this.local(a), r = this.c.vista.paraFolha(e[0], e[1]), i = this.gesto;
1367
- this.gesto = { tipo: "nenhum" };
1368
- try {
1369
- (s = (o = this.viewport).releasePointerCapture) == null || s.call(o, a.pointerId);
1370
- } catch {
1371
- }
1372
- switch (i.tipo) {
1373
- case "pan":
1374
- this.cursor(this.espaco || this.c.ferramenta === "mao" ? "mao" : "padrao");
1375
- return;
1376
- case "desenho":
1377
- this.ferramentas.soltar(r, e, this.mod(a));
1378
- return;
1379
- case "selecao":
1380
- i.moveu ? Zr(this.c, i.gesto) : this.c.agendar();
1381
- return;
1382
- case "guia":
1383
- this.soltarGuia(i.indice, e);
1384
- return;
1385
- case "caixa":
1386
- this.soltarCaixa(i, r);
1387
- return;
1388
- default:
1389
- return;
1390
- }
1391
- }
1392
- soltarCaixa(a, e) {
1393
- if (this.c.ui.caixaSelecao = null, !a.moveu) {
1394
- this.c.ui.edicao && this.c.ferramenta === "selecao-direta" && this.c.encerrarEdicao(), a.aditivo || this.c.selecionar([]), this.c.agendar();
1395
- return;
1396
- }
1397
- if (this.c.ferramenta === "selecao-direta" && this.c.ui.edicao) {
1398
- this.c.ui.edicao.ancoras = Xr(this.c, a.de, e), this.c.agendar();
1399
- return;
1400
- }
1401
- const r = { x: Math.min(a.de[0], e[0]), y: Math.min(a.de[1], e[1]), largura: Math.abs(e[0] - a.de[0]), altura: Math.abs(e[1] - a.de[1]) }, i = e[0] < a.de[0] ? "crossing" : "window", o = this.c.doc.indice.consultarCaixa(r).filter((n) => this.c.podeSelecionar(n)), s = Rt(r, o, i, { camadas: this.c.camadas }).map((n) => n.id);
1402
- this.c.selecionar(s, a.aditivo ? "adicionar" : "substituir") || this.c.agendar();
1403
- }
1404
- puxarGuia(a, e) {
1405
- if (a.button !== 0 || this.c.somenteLeitura) return;
1406
- const r = this.local(a), i = this.c.vista.paraFolha(r[0], r[1]);
1407
- this.capturar(a), this.gesto = { tipo: "guia", indice: null }, this.c.ui.guiaArrastada = { guia: { orientacao: e, posicao: e === "horizontal" ? i[1] : i[0] }, indice: null }, this.c.agendar();
1408
- }
1409
- soltarGuia(a, e) {
1410
- const r = this.c.ui.guiaArrastada;
1411
- if (this.c.ui.guiaArrastada = null, !r) return;
1412
- const i = r.guia.orientacao === "horizontal" ? e[1] < 0 : e[0] < 0;
1413
- a === null ? i || (this.c.guias = [...this.c.guias, r.guia]) : i ? this.c.guias = this.c.guias.filter((o, s) => s !== a) : this.c.guias = this.c.guias.map((o, s) => s === a ? r.guia : o), this.c.emitirGuias();
1414
- }
1415
- roda(a) {
1416
- a.preventDefault();
1417
- const e = this.local(a), r = a.deltaMode === 1 ? a.deltaY * 16 : a.deltaY;
1418
- if (a.shiftKey && !a.ctrlKey) {
1419
- this.c.vista.deslocar(-r, 0), this.c.emitirVista();
1420
- return;
1421
- }
1422
- this.c.vista.zoomRelativo(Math.exp(-r * 15e-4), e) && (this.c.emitirVista(), this.c.anunciar(ia(this.c.vista.zoomPercentual)));
1423
- }
1424
- sair() {
1425
- this.gesto.tipo === "nenhum" && (this.c.ui.ponteiro = null, this.c.ui.hoverId = null, this.c.ui.snap = null, this.c.emitir("prancha-ponteiro", { coordenada: null }), this.c.agendar());
1426
- }
1427
- /** Cancela qualquer gesto (Esc, perda de ponteiro): nada muda no documento. */
1428
- cancelar() {
1429
- this.gesto = { tipo: "nenhum" }, this.ferramentas.cancelar(), j(this.c.ui), this.c.agendar();
1430
- }
1431
- }
1432
- function ti(t, a = 50) {
1433
- if (!(t > 0) || !Number.isFinite(t)) return 1;
1434
- const e = a / t, r = 10 ** Math.floor(Math.log10(e));
1435
- for (const i of [1, 2, 5, 10]) if (i * r >= e) return i * r;
1436
- return 10 * r;
1437
- }
1438
- function ri(t, a) {
1439
- const { vista: e, cores: r, comprimento: i, espessura: o } = a, s = a.orientacao === "horizontal";
1440
- t.save(), t.setTransform(e.dpr, 0, 0, e.dpr, 0, 0), t.globalAlpha = 1, t.fillStyle = r.regua, t.fillRect(0, 0, s ? i : o, s ? o : i);
1441
- const n = 1 / Lt(1, a.unidade), c = e.zoom * n, l = ti(c), d = l / (l * c >= 100 ? 10 : 5), h = (s ? e.pan[0] : e.pan[1]) + a.deslocamento, u = Math.floor(-h / c / d) * d, m = (i - h) / c;
1442
- t.beginPath();
1443
- const p = [];
1444
- for (let v = u, b = 0; v <= m && b < 5e3; v += d, b++) {
1445
- const M = Math.round(h + v * c) + 0.5, E = Math.abs(v / l - Math.round(v / l)) < 1e-6, x = E ? o : o * 0.3;
1446
- s ? (t.moveTo(M, o), t.lineTo(M, o - x)) : (t.moveTo(o, M), t.lineTo(o - x, M)), E && p.push([String(Math.round(v * 1e3) / 1e3), M]);
1447
- }
1448
- if (t.strokeStyle = r.textoRegua, t.lineWidth = 1, t.setLineDash([]), t.stroke(), typeof t.fillText == "function") {
1449
- t.font = "9px sans-serif", t.fillStyle = r.textoRegua;
1450
- for (const [v, b] of p)
1451
- s ? t.fillText(v, b + 2, 9) : t.fillText(v, 1, b + 10);
1452
- }
1453
- if (a.ponteiro) {
1454
- const v = e.paraTela(a.ponteiro), b = Math.round((s ? v[0] : v[1]) + a.deslocamento) + 0.5;
1455
- t.beginPath(), s ? (t.moveTo(b, 0), t.lineTo(b, o)) : (t.moveTo(0, b), t.lineTo(o, b)), t.strokeStyle = r.selecao, t.stroke();
1456
- }
1457
- t.restore();
1458
- }
1459
- const $a = (t) => {
1460
- var a;
1461
- try {
1462
- return ((a = t.getContext) == null ? void 0 : a.call(t, "2d")) ?? null;
1463
- } catch {
1464
- return null;
1465
- }
1466
- };
1467
- class ii {
1468
- constructor(a, e, r) {
1469
- f(this, "pedido", null);
1470
- f(this, "contextos", /* @__PURE__ */ new Map());
1471
- f(this, "ultimaBase", { elementos: null, texto: "" });
1472
- f(this, "quadros", 0);
1473
- f(this, "pinturasBase", 0);
1474
- this.c = a, this.cv = e, this.fabrica = r;
1475
- }
1476
- /** Esquece os contextos (a fábrica mudou) e força a próxima pintura da base. */
1477
- reiniciar() {
1478
- this.contextos.clear(), this.ultimaBase = { elementos: null, texto: "" };
1479
- }
1480
- ctx(a, e) {
1481
- return this.contextos.has(a) || this.contextos.set(a, this.fabrica()(e, a)), this.contextos.get(a) ?? null;
1482
- }
1483
- agendar() {
1484
- this.pedido || (typeof requestAnimationFrame == "function" ? this.pedido = { tipo: "raf", id: requestAnimationFrame(() => {
1485
- this.pedido = null, this.pintar();
1486
- }) } : typeof setTimeout == "function" && (this.pedido = { tipo: "timeout", id: setTimeout(() => {
1487
- this.pedido = null, this.pintar();
1488
- }, 16) }));
1489
- }
1490
- cancelar() {
1491
- this.pedido && (this.pedido.tipo === "raf" && typeof cancelAnimationFrame == "function" ? cancelAnimationFrame(this.pedido.id) : clearTimeout(this.pedido.id), this.pedido = null);
1492
- }
1493
- ajustar(a, e, r, i) {
1494
- const o = Math.max(0, Math.round(e * i)), s = Math.max(0, Math.round(r * i));
1495
- return a.width === o && a.height === s ? !1 : (a.width = o, a.height = s, !0);
1496
- }
1497
- /** Mede a área de desenho; devolve se o tamanho mudou. */
1498
- medir() {
1499
- const a = this.c.vista, e = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, r = `${a.largura}x${a.altura}@${a.dpr}`;
1500
- a.redimensionar(this.cv.viewport.clientWidth || 0, this.cv.viewport.clientHeight || 0, e);
1501
- const i = r !== `${a.largura}x${a.altura}@${a.dpr}`;
1502
- return i && (this.ultimaBase = { elementos: null, texto: "" }), i;
1503
- }
1504
- /** Pinta agora (o que estiver agendado é descartado). */
1505
- pintar() {
1506
- this.cancelar(), this.quadros++;
1507
- const a = this.c, e = a.vista;
1508
- if (e.largura <= 0 || e.altura <= 0) return;
1509
- const r = this.ajustar(this.cv.base, e.largura, e.altura, e.dpr);
1510
- this.ajustar(this.cv.sobreposicao, e.largura, e.altura, e.dpr);
1511
- const i = a.elementosVisiveis(), o = [
1512
- e.zoom,
1513
- e.pan[0],
1514
- e.pan[1],
1515
- e.largura,
1516
- e.altura,
1517
- e.dpr,
1518
- a.folha.largura,
1519
- a.folha.altura,
1520
- a.mostrarGrade ? a.grade : 0,
1521
- Object.values(a.cores).join(),
1522
- JSON.stringify(a.camadas),
1523
- a.isolado ?? "",
1524
- JSON.stringify(a.margens)
1525
- ].join("|"), s = this.ctx("base", this.cv.base);
1526
- if (s && (r || i !== this.ultimaBase.elementos || o !== this.ultimaBase.texto)) {
1527
- try {
1528
- const c = a.isolado ? i.filter((l) => l.grupoId === a.isolado) : null;
1529
- jr(s, { vista: e, folha: a.folha, cores: a.cores, elementos: i, grade: a.mostrarGrade ? a.grade : null, camadas: a.camadas, isolados: c, margens: a.margens ? he(a.folha.largura, a.folha.altura, a.margens) : null }), this.pinturasBase++;
1530
- } catch {
1531
- }
1532
- this.ultimaBase = { elementos: i, texto: o };
1533
- }
1534
- const n = this.ctx("sobreposicao", this.cv.sobreposicao);
1535
- if (n)
1536
- try {
1537
- const c = a.ui.hoverId ? a.doc.obter(a.ui.hoverId) ?? null : null, l = a.doc.elementosSelecionados().map((d) => a.ui.substitutos.get(d.id) ?? d);
1538
- Gr(n, { vista: e, cores: a.cores, ui: a.ui, selecionados: l, emGesto: a.elementosEmGesto(), hover: c, guias: a.guias, caixaTransformacao: a.ferramenta === "selecao", marcasCantos: Te(a) });
1539
- } catch {
1540
- }
1541
- this.pintarReguas();
1542
- }
1543
- pintarReguas() {
1544
- const a = this.c;
1545
- for (const [e, r, i] of [["regua-horizontal", this.cv.reguaH, "horizontal"], ["regua-vertical", this.cv.reguaV, "vertical"]]) {
1546
- const o = i === "horizontal" ? r.clientWidth : r.clientHeight, s = i === "horizontal" ? r.clientHeight : r.clientWidth;
1547
- if (!(o > 0 && s > 0)) continue;
1548
- this.ajustar(r, i === "horizontal" ? o : s, i === "horizontal" ? s : o, a.vista.dpr);
1549
- const n = this.ctx(e, r);
1550
- if (n)
1551
- try {
1552
- ri(n, { orientacao: i, vista: a.vista, unidade: a.unidade, comprimento: o, espessura: s, cores: a.cores, ponteiro: a.ui.ponteiro, deslocamento: 0 });
1553
- } catch {
1554
- }
1555
- }
1556
- }
1557
- }
1558
- function k(t, a) {
1559
- if (!Ot.includes(a))
1560
- return t.recusar("pathfinder", "comando-desconhecido"), !1;
1561
- const e = y(t, "pathfinder", 2);
1562
- if (!e) return !1;
1563
- const r = Nt(B(e, t.camadas), a);
1564
- if (!("ok" in r)) {
1565
- const n = r.motivo === "sem-intersecao" || r.motivo === "resultado-vazio";
1566
- return t.recusar("pathfinder", n ? "resultado-vazio" : "tipo-nao-suportado"), !1;
1567
- }
1568
- const { resultado: i, usados: o } = r.ok, s = new Set(o.filter((n) => n !== i.id));
1569
- return t.aplicar(t.doc.elementos.filter((n) => !s.has(n.id)).map((n) => n.id === i.id ? i : n), "pathfinder"), t.selecionar([i.id]), !0;
1570
- }
1571
- const Ie = /* @__PURE__ */ new WeakSet(), Ba = /* @__PURE__ */ new WeakSet(), Ki = (t) => !!t && Ie.has(t);
1572
- function oi(t) {
1573
- Ie.add(t);
1574
- }
1575
- const Ha = { Digit1: "uniao", Digit2: "subtracao", Digit3: "intersecao", Digit4: "exclusao" }, Va = {
1576
- v: "selecao",
1577
- a: "selecao-direta",
1578
- h: "mao",
1579
- m: "retangulo",
1580
- l: "elipse",
1581
- p: "caneta",
1582
- "\\": "linha",
1583
- t: "texto"
1584
- };
1585
- function si(t, a, e, r) {
1586
- if (r.defaultPrevented || rr(r)) return !1;
1587
- const i = r.key, o = r.ctrlKey || r.metaKey, s = i.length === 1 ? i.toLowerCase() : i;
1588
- if (i === " " && !o)
1589
- return Ia(r) ? !1 : (a.espaco || (a.espaco = !0, t.agendar()), !0);
1590
- if (a.ferramentas.tecla(i)) return !0;
1591
- if (o) {
1592
- const c = r.code ?? "";
1593
- return r.altKey && r.shiftKey && c in Ha ? k(t, Ha[c]) || !0 : c === "BracketRight" || i === "]" || i === "}" ? D(t, r.shiftKey ? "frente" : "avancar") || !0 : c === "BracketLeft" || i === "[" || i === "{" ? D(t, r.shiftKey ? "tras" : "recuar") || !0 : s === "g" ? (r.shiftKey ? Se(t) : ye(t)) || !0 : c === "Digit2" || i === "2" ? (r.altKey ? na(t, "bloqueado") : sa(t, "bloqueado")) || !0 : c === "Digit3" || i === "3" ? (r.altKey ? na(t, "oculto") : sa(t, "oculto")) || !0 : c === "Digit7" || i === "7" ? (r.altKey ? Ce(t) : ze(t)) || !0 : s === "c" && !r.shiftKey ? za(t) || !0 : s === "x" ? Ae(t) || !0 : s === "v" ? Me(t, r.shiftKey) || !0 : s === "d" ? Pe(t) || !0 : s === "j" ? Ee(t) || !0 : s === "z" && !r.shiftKey ? (t.desfazer(), !0) : s === "z" && r.shiftKey || s === "y" ? (t.refazer(), !0) : s === "a" ? (ge(t), !0) : i === "0" ? (e.ajustarFolha(), !0) : i === "1" ? (e.definirZoomPercentual(100), !0) : i === "=" || i === "+" ? (t.vista.zoomRelativo(1.25), t.emitirVista(), t.anunciar(ia(t.vista.zoomPercentual)), !0) : i === "-" ? (t.vista.zoomRelativo(0.8), t.emitirVista(), t.anunciar(ia(t.vista.zoomPercentual)), !0) : !1;
1594
- }
1595
- if (r.altKey && (i === "=" || i === "+")) return ga(t, 1.1, 1.1, void 0, "teclado") || !0;
1596
- if (r.altKey && i === "-") return ga(t, 0.9, 0.9, void 0, "teclado") || !0;
1597
- if (i.startsWith("Arrow")) {
1598
- if (a.ocupado) return !0;
1599
- const c = t.passoTeclado * (r.shiftKey ? 10 : 1), l = i === "ArrowLeft" ? -c : i === "ArrowRight" ? c : 0, d = i === "ArrowUp" ? -c : i === "ArrowDown" ? c : 0;
1600
- if (t.ui.edicao && t.ui.edicao.ancoras.length > 0) vr(t, l, d, "teclado-ancoras");
1601
- else if (t.doc.selecao.length > 0) fe(t, l, d, "teclado", "teclado-mover");
1602
- else return !1;
1603
- return !0;
1604
- }
1605
- if (i === "Delete" || i === "Backspace") {
1606
- if (t.ui.edicao && t.ui.edicao.ancoras.length > 0) br(t);
1607
- else if (t.doc.selecao.length > 0) pe(t);
1608
- else return !1;
1609
- return !0;
1610
- }
1611
- if (i === "Escape")
1612
- return a.ocupado ? (a.cancelar(), !0) : t.ui.edicao ? (t.encerrarEdicao(), !0) : t.isolado ? (t.isolar(null), !0) : t.doc.selecao.length > 0 ? (t.selecionar([]), !0) : (Ba.has(r) || (Ba.add(r), t.emitir("prancha-esc-sem-efeito", {})), !1);
1613
- if (i === "Enter")
1614
- return Ia(r) ? !1 : oa(t.ferramenta) ? a.ferramentas.criarNoCentro() || !0 : t.doc.selecao.length === 1 && !t.ui.edicao ? (t.definirFerramenta("selecao-direta"), t.iniciarEdicao(t.doc.selecao[0]) || !0) : !1;
1615
- if (i === "PageDown" || i === "PageUp") return gr(t, i === "PageDown" ? 1 : -1) || !0;
1616
- if (s === "r" && !r.altKey) return me(t, r.shiftKey ? -15 : 15, void 0, "teclado") || !0;
1617
- const n = r.altKey ? null : s === "i" && !r.shiftKey ? "conta-gotas" : i === "+" || i === "=" ? "adicionar-ancora" : i === "-" ? "excluir-ancora" : s === "c" && r.shiftKey ? "converter-ancora" : null;
1618
- return n ? (a.ocupado && a.cancelar(), t.definirFerramenta(n), !0) : !r.altKey && !r.shiftKey && Va[s] ? (a.ocupado && a.cancelar(), t.definirFerramenta(Va[s]), !0) : !1;
1619
- }
1620
- function ni(t, a, e) {
1621
- e.key === " " && a.espaco && (a.espaco = !1, t.agendar());
1622
- }
1623
- const De = [
1624
- "selecao",
1625
- "selecao-direta",
1626
- "mao",
1627
- "retangulo",
1628
- "elipse",
1629
- "poligono-regular",
1630
- "estrela",
1631
- "linha",
1632
- "seta",
1633
- "polilinha",
1634
- "poligono",
1635
- "caneta",
1636
- "texto",
1637
- // Fase 4
1638
- "conta-gotas",
1639
- "adicionar-ancora",
1640
- "excluir-ancora",
1641
- "converter-ancora"
1642
- ];
1643
- function qe(t) {
1644
- return typeof t == "string" && De.includes(t);
1645
- }
1646
- const ci = "prancha:comando", li = [
1647
- "definirFerramenta",
1648
- "selecionarElementos",
1649
- "alternarSelecaoElemento",
1650
- "limparSelecao",
1651
- "selecionarTudo",
1652
- "desfazer",
1653
- "refazer",
1654
- "moverSelecao",
1655
- "girarSelecao",
1656
- "escalarSelecao",
1657
- "espelharSelecao",
1658
- "transformarSelecao",
1659
- "removerSelecao",
1660
- "definirRaiosCantos",
1661
- "inserirPredefinicao",
1662
- "ajustarFolha",
1663
- "ajustarSelecao",
1664
- "definirZoom",
1665
- "aproximar",
1666
- "afastar",
1667
- "deslocarVista",
1668
- "definirGuias",
1669
- "adicionarGuia",
1670
- "removerGuia",
1671
- "definirSnap",
1672
- "editarAncoras",
1673
- "concluirEdicao",
1674
- "definirOpcoesFerramentas",
1675
- // Fase 4
1676
- "definirCamadas",
1677
- "definirCamadaAtiva",
1678
- "moverSelecaoParaCamada",
1679
- "isolarGrupo",
1680
- "ordenarSelecao",
1681
- "trazerParaFrente",
1682
- "enviarParaTras",
1683
- "avancar",
1684
- "recuar",
1685
- "agruparSelecao",
1686
- "desagruparSelecao",
1687
- "bloquearSelecao",
1688
- "ocultarSelecao",
1689
- "desbloquearTudo",
1690
- "mostrarTudo",
1691
- "alinharSelecao",
1692
- "distribuirSelecao",
1693
- "duplicarSelecao",
1694
- "transformarDeNovo",
1695
- "copiar",
1696
- "recortar",
1697
- "colar",
1698
- "aplicarAparencia",
1699
- "criarMascara",
1700
- "liberarMascara",
1701
- "unirSelecao",
1702
- "dividirSelecao",
1703
- "deslocarCaminho",
1704
- "simplificarSelecao",
1705
- "contornarTraco",
1706
- "converterEmCaminho",
1707
- // Fase 5
1708
- "pathfinder",
1709
- "unirFormas",
1710
- "subtrairFrente",
1711
- "intersectarFormas",
1712
- "excluirSobreposicao",
1713
- // Fase 6
1714
- "aplicarPropriedade",
1715
- "alterarElementos"
1716
- ];
1717
- function ui(t) {
1718
- return typeof t == "string" && li.includes(t);
1719
- }
1720
- function di(t, a) {
1721
- return ae.on(ci, (e) => {
1722
- !e || typeof e != "object" || e.alvo !== void 0 && e.alvo !== t.id || a(e.comando, Array.isArray(e.args) ? e.args : []);
1723
- });
1724
- }
1725
- const _e = [
1726
- "largura",
1727
- "altura",
1728
- "unidade",
1729
- "grade",
1730
- "mostrar-grade",
1731
- "sem-reguas",
1732
- "sem-snap",
1733
- "sem-guias-inteligentes",
1734
- "ferramenta",
1735
- "rotulo",
1736
- "somente-leitura",
1737
- "passo-teclado",
1738
- "margens",
1739
- "teclado",
1740
- "ajustar-ao-abrir"
1741
- ];
1742
- function Fe(t) {
1743
- if (!t) return null;
1744
- const a = t.trim().split(/[\s,;]+/).map((e) => parseFloat(e.replace(",", ".")));
1745
- return a.length !== 1 && a.length !== 4 || !a.every((e) => Number.isFinite(e) && e >= 0 && e <= 1e5) ? null : a.length === 1 ? { esquerda: a[0], direita: a[0], superior: a[0], inferior: a[0] } : { esquerda: a[0], direita: a[1], superior: a[2], inferior: a[3] };
1746
- }
1747
- const Ka = (t) => t === "conteudo" || t === "nenhum" ? t : "folha", Q = (t, a, e, r) => {
1748
- const i = t === null ? NaN : parseFloat(t.replace(",", "."));
1749
- return Number.isFinite(i) && i >= e && i <= r ? i : a;
1750
- };
1751
- function hi(t, a, e) {
1752
- switch (a) {
1753
- case "largura": {
1754
- const r = Q(e, 210, 1, 1e5), i = r !== t.folha.largura;
1755
- return t.folha = { ...t.folha, largura: r }, i;
1756
- }
1757
- case "altura": {
1758
- const r = Q(e, 297, 1, 1e5), i = r !== t.folha.altura;
1759
- return t.folha = { ...t.folha, altura: r }, i;
1760
- }
1761
- case "unidade":
1762
- t.unidade = e && jt(e) ? e : "mm";
1763
- break;
1764
- case "grade":
1765
- t.grade = Q(e, 10, 0.1, 1e4);
1766
- break;
1767
- case "mostrar-grade":
1768
- t.mostrarGrade = e !== null && e !== "false";
1769
- break;
1770
- case "sem-snap":
1771
- t.snapLigado = e === null || e === "false";
1772
- break;
1773
- case "sem-guias-inteligentes":
1774
- t.guiasInteligentes = e === null || e === "false";
1775
- break;
1776
- case "ferramenta":
1777
- t.definirFerramenta(e && qe(e) ? e : "selecao");
1778
- break;
1779
- case "somente-leitura":
1780
- t.somenteLeitura = e !== null && e !== "false";
1781
- break;
1782
- case "passo-teclado":
1783
- t.passoTeclado = Q(e, 1, 1e-3, 1e3);
1784
- break;
1785
- case "margens":
1786
- t.margens = Fe(e);
1787
- break;
1788
- }
1789
- return t.agendar(), !1;
1790
- }
1791
- const Ua = 100, fi = 4e3;
1792
- function mi(t) {
1793
- let a;
1794
- const e = /* @__PURE__ */ new Map();
1795
- return (r, i, o) => {
1796
- var c;
1797
- if (a === void 0)
1798
- try {
1799
- const l = (c = t()) == null ? void 0 : c.getContext("2d");
1800
- a = l && typeof l.measureText == "function" ? l : null;
1801
- } catch {
1802
- a = null;
1803
- }
1804
- if (!a) return null;
1805
- const s = `${i}\0${r}`;
1806
- let n = e.get(s);
1807
- if (n === void 0) {
1808
- try {
1809
- a.font = `${Ua}px ${i}`;
1810
- const l = a.measureText(r).width;
1811
- n = Number.isFinite(l) && l >= 0 ? l / Ua : null;
1812
- } catch {
1813
- n = null;
1814
- }
1815
- e.size >= fi && e.clear(), e.set(s, n);
1816
- }
1817
- return n === null ? null : n * o;
1818
- };
1819
- }
1820
- function pi() {
1821
- if (Gt() || typeof document > "u") return !1;
1822
- const t = mi(() => document.createElement("canvas"));
1823
- return t("M", "sans-serif", 1) === null ? !1 : ($t(t), !0);
1824
- }
1825
- class gi extends Ya {
1826
- constructor() {
1827
- super();
1828
- f(this, "shadow");
1829
- f(this, "bag", new ba());
1830
- f(this, "c");
1831
- f(this, "interacao");
1832
- f(this, "render");
1833
- f(this, "viewport");
1834
- f(this, "status");
1835
- f(this, "observador", null);
1836
- f(this, "desligarBus", []);
1837
- f(this, "ponteiroSobre", !1);
1838
- f(this, "focoDentro", !1);
1839
- f(this, "enquadrou", !1);
1840
- f(this, "_fabrica", $a);
1841
- f(this, "revisaoSalva", 0);
1842
- f(this, "_modificado", !1);
1843
- f(this, "conteudoEnquadrado", !1);
1844
- f(this, "_pronto");
1845
- f(this, "resolverPronto", null);
1846
- f(this, "fimPronto", 0);
1847
- f(this, "carregando", !1);
1848
- this.shadow = this.attachShadow({ mode: "open" }), this.shadow.innerHTML = or();
1849
- const e = (r) => this.shadow.getElementById(r);
1850
- this.viewport = e("viewport"), this.status = e("status"), this.c = new mr({
1851
- emitir: (r, i, o) => {
1852
- const s = new CustomEvent(r, { detail: i, bubbles: !0, composed: !0, cancelable: !!o });
1853
- return this.dispatchEvent(s), s.defaultPrevented;
1854
- },
1855
- agendar: () => {
1856
- var r;
1857
- return (r = this.render) == null ? void 0 : r.agendar();
1858
- },
1859
- anunciar: (r) => fr(this.status, r)
1860
- }), this._pronto = new Promise((r) => {
1861
- this.resolverPronto = r;
1862
- }), this.c.doc.ouvirMudancas(() => this.avaliarModificado()), this.interacao = new ei(this.c, this.viewport, new Cr(this.c)), this.render = new ii(this.c, {
1863
- viewport: this.viewport,
1864
- base: e("camada-base"),
1865
- sobreposicao: e("camada-sobreposicao"),
1866
- reguaH: e("regua-h"),
1867
- reguaV: e("regua-v")
1868
- }, () => this._fabrica);
1869
- }
1870
- static get observedAttributes() {
1871
- return _e;
1872
- }
1873
- connectedCallback() {
1874
- var e;
1875
- this.bag.cleanup(), this.interacao.conectar(this.bag, this.shadow.getElementById("regua-h"), this.shadow.getElementById("regua-v")), this.bag.add(this, "pointerenter", () => {
1876
- this.ponteiroSobre = !0;
1877
- }), this.bag.add(this, "pointerleave", () => {
1878
- this.ponteiroSobre = !1;
1879
- }), this.bag.add(this, "focusin", () => {
1880
- this.focoDentro = !0;
1881
- }), this.bag.add(this, "focusout", () => {
1882
- this.focoDentro = !1;
1883
- }), this.bag.add(this.viewport, "keydown", (r) => this.tecla(r, !0)), typeof window < "u" && (this.bag.add(window, "keydown", (r) => {
1884
- this.tecladoExclusivo() && this.tecla(r, !0, !0);
1885
- }, { capture: !0 }), this.bag.add(window, "keydown", (r) => this.tecla(r)), this.bag.add(window, "keyup", (r) => ni(this.c, this.interacao, r)), this.bag.add(window, "blur", () => {
1886
- this.interacao.espaco = !1;
1887
- })), typeof ResizeObserver == "function" && ((e = this.observador) == null || e.disconnect(), this.observador = new ResizeObserver(() => this.redimensionar()), this.observador.observe(this.viewport)), this.desligarBus.forEach((r) => r()), this.desligarBus = [
1888
- di(this, (r, i) => this.executarComando(r, i)),
1889
- ae.on("tema:alterado", () => this.atualizarCores())
1890
- ], pi() && this.c.doc.indice.definir(this.c.doc.elementos), this.atualizarCores(), this.atualizarRotulo(), this.c.margens = Fe(this.getAttribute("margens")), this.redimensionar(), this.prepararPronto();
1891
- }
1892
- disconnectedCallback() {
1893
- var e;
1894
- this.fimPronto && typeof cancelAnimationFrame == "function" && cancelAnimationFrame(this.fimPronto), this.fimPronto = 0, this.bag.cleanup(), (e = this.observador) == null || e.disconnect(), this.observador = null, this.desligarBus.forEach((r) => r()), this.desligarBus = [], this.render.cancelar(), this.interacao.cancelar();
1895
- }
1896
- attributeChangedCallback(e, r, i) {
1897
- if (e === "rotulo") {
1898
- this.atualizarRotulo();
1899
- return;
1900
- }
1901
- if (e === "teclado") return;
1902
- hi(this.c, e, i) && !this.enquadrou && this.ajustarFolha();
1903
- }
1904
- /** Resolve `pronto` quando a área de desenho foi medida; sem layout (teste, aba oculta), dois quadros depois. */
1905
- prepararPronto() {
1906
- if (this.resolverPronto) {
1907
- if (this.c.vista.largura > 0) {
1908
- this.concluirPronto();
1909
- return;
1910
- }
1911
- typeof requestAnimationFrame == "function" && !this.fimPronto ? this.fimPronto = requestAnimationFrame(() => {
1912
- this.fimPronto = requestAnimationFrame(() => {
1913
- this.fimPronto = 0, this.concluirPronto();
1914
- });
1915
- }) : typeof requestAnimationFrame != "function" && this.concluirPronto();
1916
- }
1917
- }
1918
- concluirPronto() {
1919
- const e = this.resolverPronto;
1920
- e && (this.resolverPronto = null, e(), this.dispatchEvent(new CustomEvent("prancha-pronta", { bubbles: !0, composed: !0, detail: {} })));
1921
- }
1922
- atualizarRotulo() {
1923
- this.viewport.setAttribute("aria-label", this.getAttribute("rotulo") || "Prancha");
1924
- }
1925
- atualizarCores() {
1926
- this.c.cores = lr(this), this.render.reiniciar(), this.c.agendar();
1927
- }
1928
- redimensionar() {
1929
- if (this.render.medir(), !this.enquadrou && this.c.vista.largura > 0) {
1930
- const e = Ka(this.getAttribute("ajustar-ao-abrir"));
1931
- e === "conteudo" && this.c.doc.elementos.length > 0 ? (this.ajustarElementos(), this.conteudoEnquadrado = !0) : e !== "nenhum" && this.c.vista.enquadrar({ x: 0, y: 0, largura: this.c.folha.largura, altura: this.c.folha.altura }), this.enquadrou = !0;
1932
- }
1933
- this.render.pintar(), this.prepararPronto();
1934
- }
1935
- tecladoExclusivo() {
1936
- return this.getAttribute("teclado") === "exclusivo";
1937
- }
1938
- tecla(e, r = !1, i = !1) {
1939
- !r && !this.focoDentro && !this.ponteiroSobre || !i && e.defaultPrevented && this.tecladoExclusivo() || si(this.c, this.interacao, { ajustarFolha: () => this.ajustarFolha(), definirZoomPercentual: (o) => this.definirZoom(o) }, e) && (e.preventDefault(), e.stopPropagation(), i && e.stopImmediatePropagation(), oi(e));
1940
- }
1941
- // ---------- modificado, revisão e ciclo de vida ----------
1942
- /** O documento mudou desde a carga (`definirElementos`) ou desde `marcarComoSalvo()`. */
1943
- get modificado() {
1944
- return this._modificado;
1945
- }
1946
- /** Contador de mudanças do documento (carga, edição, desfazer/refazer, renomear). */
1947
- get revisao() {
1948
- return this.c.doc.revisao;
1949
- }
1950
- /** Registra o estado atual como o salvo: `modificado` volta a `false` (e `prancha-modificado` só emite na transição). */
1951
- marcarComoSalvo() {
1952
- this.revisaoSalva = this.c.doc.revisao, this.avaliarModificado();
1953
- }
1954
- avaliarModificado() {
1955
- if (this.carregando) return;
1956
- const e = this.c.doc.revisao !== this.revisaoSalva;
1957
- e !== this._modificado && (this._modificado = e, this.c.emitir("prancha-modificado", { modificado: e, revisao: this.c.doc.revisao }));
1958
- }
1959
- /**
1960
- * Resolve quando a área de desenho foi medida e a prancha consegue enquadrar (ou, sem layout, dois quadros depois da
1961
- * conexão). Também emite `prancha-pronta` uma vez.
1962
- */
1963
- get pronto() {
1964
- return this._pronto;
1965
- }
1966
- /** Dá o foco à área de desenho (o `focus()` do host entrega o foco ao viewport, onde o teclado da prancha escuta). */
1967
- focus(e) {
1968
- this.viewport.focus(e);
1969
- }
1970
- // ---------- propriedades ----------
1971
- /** Ferramenta ativa. */
1972
- get ferramenta() {
1973
- return this.c.ferramenta;
1974
- }
1975
- set ferramenta(e) {
1976
- this.definirFerramenta(e);
1977
- }
1978
- /** Elementos do documento (na ordem de empilhamento). */
1979
- get elementos() {
1980
- return [...this.c.doc.elementos];
1981
- }
1982
- /** Ids selecionados. */
1983
- get selecao() {
1984
- return [...this.c.doc.selecao];
1985
- }
1986
- get podeDesfazer() {
1987
- return this.c.doc.historico.podeDesfazer;
1988
- }
1989
- get podeRefazer() {
1990
- return this.c.doc.historico.podeRefazer;
1991
- }
1992
- /** Id provisório dos elementos criados pelo usuário (o app pode trocar por um gerador próprio). */
1993
- get gerarId() {
1994
- return this.c.gerarId;
1995
- }
1996
- set gerarId(e) {
1997
- typeof e == "function" && (this.c.gerarId = e);
1998
- }
1999
- /** Fábrica do contexto 2D de cada canvas (padrão `getContext('2d')`); serve para pintar com um contexto próprio ou de teste. */
2000
- get fabricaContexto() {
2001
- return this._fabrica;
2002
- }
2003
- set fabricaContexto(e) {
2004
- this._fabrica = typeof e == "function" ? e : $a, this.render.reiniciar(), this.c.agendar();
2005
- }
2006
- // ---------- dados (sincronização do app: não emite prancha-elemento-*) ----------
2007
- /** Carrega o documento (normaliza; recomeça o histórico e a seleção). Devolve os recusados. */
2008
- definirElementos(e) {
2009
- this.carregando = !0;
2010
- const r = (() => {
2011
- try {
2012
- return this.c.doc.definir(e);
2013
- } finally {
2014
- this.carregando = !1;
2015
- }
2016
- })();
2017
- return this.c.ui.edicao = null, this.c.emitirHistorico(), this.marcarComoSalvo(), !this.conteudoEnquadrado && this.enquadrou && Ka(this.getAttribute("ajustar-ao-abrir")) === "conteudo" && r.elementos.length > 0 && (this.conteudoEnquadrado = !0, this.ajustarElementos()), this.c.agendar(), { aceitos: r.elementos.length, recusados: r.recusados };
2018
- }
2019
- /** Lote de mudanças do app (adicionar, atualizar, remover) de uma vez. */
2020
- aplicarLote(e, r = {}) {
2021
- const { resultado: i } = this.c.doc.aplicarLote(e, r.historico !== !1);
2022
- return this.c.emitirHistorico(), this.c.agendar(), i;
2023
- }
2024
- adicionarElemento(e, r) {
2025
- return this.aplicarLote({ adicionar: [e] }, r).adicionados.length === 1;
2026
- }
2027
- atualizarElemento(e, r) {
2028
- return this.aplicarLote({ atualizar: [e] }, r).atualizados.length === 1;
2029
- }
2030
- removerElemento(e, r) {
2031
- return this.aplicarLote({ remover: [e] }, r).removidos.length === 1;
2032
- }
2033
- obterElementos() {
2034
- return this.elementos;
2035
- }
2036
- obterElemento(e) {
2037
- return this.c.doc.obter(e) ?? null;
2038
- }
2039
- /** Troca o id provisório pelo definitivo em tudo (documento, seleção e histórico). */
2040
- renomearElemento(e, r) {
2041
- var o;
2042
- const i = this.c.doc.renomear(e, r);
2043
- return i && ((o = this.c.ui.edicao) == null ? void 0 : o.id) === e && (this.c.ui.edicao.id = r), i;
2044
- }
2045
- // ---------- seleção e ferramentas ----------
2046
- selecionarElementos(e) {
2047
- return this.c.selecionar(Array.isArray(e) ? e : []);
2048
- }
2049
- alternarSelecaoElemento(e) {
2050
- return this.c.selecionar([e], "alternar");
2051
- }
2052
- limparSelecao() {
2053
- return this.c.selecionar([]);
2054
- }
2055
- selecionarTudo() {
2056
- return ge(this.c);
2057
- }
2058
- obterSelecao() {
2059
- return this.c.doc.elementosSelecionados();
2060
- }
2061
- definirFerramenta(e) {
2062
- this.interacao.cancelar(), this.c.definirFerramenta(qe(e) ? e : "selecao");
2063
- }
2064
- definirOpcoesFerramentas(e) {
2065
- this.c.opcoesFerramentas = e && typeof e == "object" ? { ...e } : {};
2066
- }
2067
- obterOpcoesFerramentas() {
2068
- return { ...this.c.opcoesFerramentas };
2069
- }
2070
- /** Entra na seleção direta (âncoras) do elemento. */
2071
- editarAncoras(e) {
2072
- const r = typeof e == "string" ? this.c.doc.obter(e) : void 0;
2073
- return r ? r.bloqueado || r.geometria.tipo === "texto" ? this.c.iniciarEdicao(e) : (this.c.definirFerramenta("selecao-direta"), this.c.iniciarEdicao(e)) : (this.c.recusar("editar-ancoras", "id-invalido", typeof e == "string" ? e : void 0), !1);
2074
- }
2075
- concluirEdicao() {
2076
- this.c.encerrarEdicao();
2077
- }
2078
- // ---------- histórico e comandos sobre a seleção (emitem prancha-elemento-*) ----------
2079
- desfazer() {
2080
- return this.c.desfazer();
2081
- }
2082
- refazer() {
2083
- return this.c.refazer();
2084
- }
2085
- moverSelecao(e, r) {
2086
- return fe(this.c, e, r);
2087
- }
2088
- girarSelecao(e, r) {
2089
- return me(this.c, e, r);
2090
- }
2091
- escalarSelecao(e, r, i) {
2092
- return ga(this.c, e, r ?? e, i);
2093
- }
2094
- espelharSelecao(e) {
2095
- return pr(this.c, e);
2096
- }
2097
- transformarSelecao(e) {
2098
- return W(this.c, Bt(e));
2099
- }
2100
- removerSelecao() {
2101
- return pe(this.c);
2102
- }
2103
- /** Raios dos cantos dos retângulos selecionados, em mm (número = os quatro; ou [sup. esq., sup. dir., inf. dir., inf. esq.]). */
2104
- definirRaiosCantos(e) {
2105
- return ve(this.c, e);
2106
- }
2107
- /**
2108
- * Insere uma pré-definição (moldura, seta...) e a deixa selecionada. Sem `caixa`: com `opcoes.quadro: 'margens'` (e o
2109
- * atributo `margens`), o quadro das margens; senão, uma caixa no CENTRO DA ÁREA VISÍVEL, de tamanho proporcional ao zoom
2110
- * (cerca de 35% da largura e 25% da altura visíveis, limitada à folha), para a forma nascer à vista.
2111
- */
2112
- inserirPredefinicao(e, r, i = {}) {
2113
- if (!Ht(e))
2114
- return this.c.recusar("inserir-predefinicao", "geometria-invalida"), [];
2115
- const { quadro: o, ...s } = i ?? {}, n = r ?? (o === "margens" && this.c.margens ? he(this.c.folha.largura, this.c.folha.altura, this.c.margens) : null) ?? this.caixaNaVista(), c = Vt(e, n, { ...s, id: s.id ?? this.c.gerarId(e) });
2116
- return w(this.c, c, "predefinicao");
2117
- }
2118
- /** Caixa (mm) no centro da área visível, proporcional ao zoom e dentro da folha; sem vista medida, 60 × 40 mm no centro da folha. */
2119
- caixaNaVista() {
2120
- const e = this.c.folha, r = this.c.vista;
2121
- let i = 0, o = 0, s = e.largura, n = e.altura;
2122
- if (r.largura > 0 && r.altura > 0) {
2123
- const v = r.paraFolha(0, 0), b = r.paraFolha(r.largura, r.altura), M = Math.max(0, v[0]), E = Math.max(0, v[1]), x = Math.min(e.largura, b[0]), H = Math.min(e.altura, b[1]);
2124
- x > M && H > E && (i = M, o = E, s = x, n = H);
2125
- }
2126
- const c = (s - i) * (r.largura > 0 ? 0.35 : 0.3), l = (n - o) * (r.largura > 0 ? 0.25 : 0.15), d = Math.max(1, Math.min(c, e.largura)), h = Math.max(1, Math.min(l, e.altura)), u = r.largura > 0 && r.altura > 0 ? r.paraFolha(r.largura / 2, r.altura / 2) : [(i + s) / 2, (o + n) / 2], m = Math.min(e.largura, Math.max(0, u[0])), p = Math.min(e.altura, Math.max(0, u[1]));
2127
- return { x: m - d / 2, y: p - h / 2, largura: d, altura: h };
2128
- }
2129
- // ---------- vista ----------
2130
- ajustarFolha() {
2131
- this.render.medir(), this.c.vista.enquadrar({ x: 0, y: 0, largura: this.c.folha.largura, altura: this.c.folha.altura }) && (this.enquadrou = !0), this.c.emitirVista();
2132
- }
2133
- ajustarSelecao() {
2134
- const e = this.c.doc.elementosSelecionados();
2135
- if (e.length === 0) {
2136
- this.c.recusar("ajustar-selecao", "sem-selecao");
2137
- return;
2138
- }
2139
- const r = Ta(e);
2140
- r && this.c.vista.enquadrar(r, 48) && this.c.emitirVista();
2141
- }
2142
- /**
2143
- * Enquadra os elementos (os `ids`, ou todos) SEM mexer na seleção, com teto de zoom (`zoomMaximo`, em %: um elemento
2144
- * pequeno não é ampliado absurdamente). Devolve se enquadrou.
2145
- */
2146
- ajustarElementos(e, r = {}) {
2147
- const i = Array.isArray(e) ? e.map((l) => this.c.doc.obter(l)).filter((l) => !!l) : [...this.c.doc.elementos], o = Ta(i);
2148
- if (!o) return !1;
2149
- const s = Number.isFinite(r == null ? void 0 : r.margem) && r.margem >= 0 ? r.margem : 48, n = Number.isFinite(r == null ? void 0 : r.zoomMaximo) && r.zoomMaximo > 0 ? r.zoomMaximo : 800;
2150
- if (!this.c.vista.enquadrar(o, s)) return !1;
2151
- const c = n / 100 * $;
2152
- return this.c.vista.zoom > c && this.c.vista.definirZoomCentrado(c, o), this.c.emitirVista(), !0;
2153
- }
2154
- /** Zoom em % (100% = tamanho real a 96 dpi), no centro da vista. */
2155
- definirZoom(e) {
2156
- this.c.vista.definirZoom(e / 100 * $) && (this.c.emitirVista(), this.c.anunciar(ia(this.c.vista.zoomPercentual)));
2157
- }
2158
- aproximar() {
2159
- this.definirZoom(this.c.vista.zoomPercentual * 1.25);
2160
- }
2161
- afastar() {
2162
- this.definirZoom(this.c.vista.zoomPercentual * 0.8);
2163
- }
2164
- deslocarVista(e, r) {
2165
- this.c.vista.deslocar(e, r) && this.c.emitirVista();
2166
- }
2167
- obterVista() {
2168
- const e = this.c.vista;
2169
- return { zoom: e.zoom, zoomPercentual: e.zoomPercentual, pan: [e.pan[0], e.pan[1]] };
2170
- }
2171
- /** Ponto da área de desenho (px CSS) → folha (mm), e o inverso. */
2172
- paraFolha(e, r) {
2173
- return this.c.vista.paraFolha(e, r);
2174
- }
2175
- paraTela(e) {
2176
- return this.c.vista.paraTela(e);
2177
- }
2178
- // ---------- guias e snap ----------
2179
- definirGuias(e) {
2180
- this.c.guias = (Array.isArray(e) ? e : []).filter((r) => r && (r.orientacao === "horizontal" || r.orientacao === "vertical") && Number.isFinite(r.posicao)).map((r) => ({ ...r })), this.c.emitirGuias();
2181
- }
2182
- adicionarGuia(e) {
2183
- this.definirGuias([...this.c.guias, e]);
2184
- }
2185
- removerGuia(e) {
2186
- this.definirGuias(this.c.guias.filter((r, i) => i !== e));
2187
- }
2188
- obterGuias() {
2189
- return this.c.guias.map((e) => ({ ...e }));
2190
- }
2191
- definirSnap(e) {
2192
- this.toggleAttribute("sem-snap", !e);
2193
- }
2194
- // ---------- exportação ----------
2195
- /** SVG da folha com os elementos (o mesmo plano de pintura da tela). */
2196
- exportarSvg(e = {}) {
2197
- return Kt(this.c.doc.elementos, { largura: this.c.folha.largura, altura: this.c.folha.altura, fundo: "#ffffff", ...e });
2198
- }
2199
- /** Pinta os elementos num contexto próprio (ex.: o PDF vetorial do app) com o mesmo código da tela. */
2200
- desenharEm(e, r = {}) {
2201
- return N(e, this.c.doc.elementos, r);
2202
- }
2203
- /** Mede e pinta agora (sem esperar o próximo quadro). */
2204
- renderizarAgora() {
2205
- this.render.medir(), this.render.pintar();
2206
- }
2207
- /** Executa um comando público pelo nome (o mesmo que o `ui-bus` usa). Comando desconhecido emite `prancha-recusa`. */
2208
- executarComando(e, r = []) {
2209
- if (!ui(e)) {
2210
- this.c.recusar("executar-comando", "comando-desconhecido");
2211
- return;
2212
- }
2213
- const i = this[e];
2214
- try {
2215
- return i.apply(this, Array.isArray(r) ? r : []);
2216
- } catch {
2217
- this.c.recusar(e, "geometria-invalida");
2218
- return;
2219
- }
2220
- }
2221
- }
2222
- const Za = (t) => {
2223
- const a = typeof t == "string" && t.trim() !== "" ? Number(t.replace(",", ".")) : t;
2224
- return typeof a == "number" && Number.isFinite(a) ? a : null;
2225
- };
2226
- function vi(t) {
2227
- let a = 1 / 0, e = 1 / 0, r = -1 / 0, i = -1 / 0;
2228
- for (const o of t) {
2229
- const s = X(o);
2230
- s && (a = Math.min(a, s.x), e = Math.min(e, s.y), r = Math.max(r, s.x + s.largura), i = Math.max(i, s.y + s.altura));
2231
- }
2232
- return Number.isFinite(a) ? { x: a, y: e, largura: r - a, altura: i - e } : null;
2233
- }
2234
- function bi(t, a, e) {
2235
- const r = vi(t);
2236
- if (!r) return null;
2237
- let i = null;
2238
- if (a === "geometria.x") i = F(e - r.x, 0);
2239
- else if (a === "geometria.y") i = F(0, e - r.y);
2240
- else if (a === "geometria.largura" && e > 0 && r.largura > 0) i = O(e / r.largura, 1, [r.x, r.y]);
2241
- else if (a === "geometria.altura" && e > 0 && r.altura > 0) i = O(1, e / r.altura, [r.x, r.y]);
2242
- else if (a === "geometria.rotacao")
2243
- return t.map((o) => {
2244
- const s = X(o);
2245
- if (!s) return o;
2246
- const n = (e - Wt(o)) * Math.PI / 180;
2247
- return oe(o, ya(n, [s.x + s.largura / 2, s.y + s.altura / 2]));
2248
- });
2249
- return i ? T(t, i) : null;
2250
- }
2251
- function yi(t, a, e) {
2252
- if (t.somenteLeitura)
2253
- return t.recusar("propriedade", "somente-leitura"), !1;
2254
- if (!Ut(a))
2255
- return t.recusar("propriedade", "comando-desconhecido"), !1;
2256
- const r = t.doc.elementosSelecionados();
2257
- if (r.length === 0)
2258
- return t.recusar("propriedade", "sem-selecao"), !1;
2259
- const i = a === "elemento.bloqueado" || a === "elemento.oculto" ? r : r.filter((s) => !t.mapa().travado(s));
2260
- if (i.length === 0)
2261
- return t.recusar("propriedade", "bloqueado"), !1;
2262
- if (a === "geometria.raio") {
2263
- const s = Za(e);
2264
- return s === null || s < 0 ? (t.recusar("propriedade", "geometria-invalida"), !1) : ve(t, s);
2265
- }
2266
- let o;
2267
- if (Zt(a)) {
2268
- const s = Za(e);
2269
- o = s === null ? null : bi(i, a, s);
2270
- } else {
2271
- const s = i.map((n) => Xt(n, a, e));
2272
- o = s.every((n) => n !== null) ? s : null;
2273
- }
2274
- return o ? (t.aplicarSubstituicoes(o, "propriedades", `propriedade:${a}`), !0) : (t.recusar("propriedade", "geometria-invalida"), !1);
2275
- }
2276
- function Si(t, a, e) {
2277
- if (t.somenteLeitura)
2278
- return t.recusar("alterar", "somente-leitura"), !1;
2279
- if (!e || typeof e != "object" || !Array.isArray(a))
2280
- return t.recusar("alterar", "geometria-invalida"), !1;
2281
- const r = a.map((o) => typeof o == "string" ? t.doc.obter(o) : void 0).filter((o) => !!o);
2282
- if (r.length === 0 || e.camadaId !== void 0 && e.camadaId !== null && !t.camadas.some((o) => o.id === e.camadaId))
2283
- return t.recusar("alterar", "id-invalido"), !1;
2284
- const i = r.map((o) => {
2285
- const s = { ...o };
2286
- e.nome !== void 0 && (typeof e.nome == "string" && e.nome.trim() !== "" ? s.nome = e.nome : delete s.nome);
2287
- for (const n of ["oculto", "bloqueado"])
2288
- typeof e[n] == "boolean" && (e[n] ? s[n] = !0 : delete s[n]);
2289
- return e.camadaId !== void 0 && (e.camadaId ? s.camadaId = e.camadaId : delete s.camadaId), s;
2290
- });
2291
- return t.aplicarSubstituicoes(i, "propriedades"), !0;
2292
- }
2293
- const Pi = {
2294
- retangulo: "Retângulo",
2295
- elipse: "Elipse",
2296
- "poligono-regular": "Polígono",
2297
- estrela: "Estrela",
2298
- linha: "Linha",
2299
- caminho: "Caminho",
2300
- texto: "Texto"
2301
- }, ke = (t) => {
2302
- var a;
2303
- return Pi[(a = t == null ? void 0 : t.geometria) == null ? void 0 : a.tipo] ?? "Elemento";
2304
- }, Ai = {
2305
- normal: "Normal",
2306
- multiplicar: "Multiplicar",
2307
- tela: "Tela",
2308
- sobrepor: "Sobrepor",
2309
- escurecer: "Escurecer",
2310
- clarear: "Clarear",
2311
- "subexposicao-cor": "Subexposição de cores",
2312
- "superexposicao-cor": "Superexposição de cores",
2313
- "luz-dura": "Luz direta",
2314
- "luz-suave": "Luz indireta",
2315
- diferenca: "Diferença",
2316
- exclusao: "Exclusão",
2317
- matiz: "Matiz",
2318
- saturacao: "Saturação",
2319
- cor: "Cor",
2320
- luminosidade: "Luminosidade"
2321
- }, Mi = {
2322
- continua: "Contínua",
2323
- tracejada: "Tracejada",
2324
- "tracejada-curta": "Tracejada curta",
2325
- "tracejada-longa": "Tracejada longa",
2326
- pontilhada: "Pontilhada",
2327
- "traco-ponto": "Traço-ponto"
2328
- }, U = (t) => t.map(([a, e]) => ({ id: a, rotulo: e })), Xa = U([["nenhuma", "Nenhuma"], ["triangulo", "Triângulo"], ["triangulo-aberto", "Triângulo vazado"], ["aberta", "Aberta"], ["circulo", "Círculo"], ["quadrado", "Quadrado"], ["losango", "Losango"], ["barra", "Barra"]]);
2329
- function g(t, a, e, r, i = {}) {
2330
- const o = t.map((c) => Yt(c, a)).filter((c) => c !== void 0);
2331
- if (o.length === 0) return null;
2332
- const s = (c) => JSON.stringify(c);
2333
- return o.every((c) => s(c) === s(o[0])) && o[0] !== null ? { id: a, rotulo: e, tipo: r, valor: o[0], ...i } : { id: a, rotulo: e, tipo: r, valor: null, misto: !0, ...i };
2334
- }
2335
- const C = { unidade: "mm", casasDecimais: 2, passo: 0.5 }, aa = { unidade: "%", casasDecimais: 0, passo: 5, min: 0, max: 100 }, R = (t) => t.filter((a) => a !== null);
2336
- function zi(t) {
2337
- let a = 1 / 0, e = 1 / 0, r = -1 / 0, i = -1 / 0;
2338
- for (const n of t) {
2339
- const c = X(n);
2340
- c && (a = Math.min(a, c.x), e = Math.min(e, c.y), r = Math.max(r, c.x + c.largura), i = Math.max(i, c.y + c.altura));
2341
- }
2342
- const o = (n) => Math.round(n * 1e6) / 1e6, s = Number.isFinite(a) ? [
2343
- { id: "geometria.x", rotulo: "X", tipo: "numero", valor: o(a), ...C },
2344
- { id: "geometria.y", rotulo: "Y", tipo: "numero", valor: o(e), ...C },
2345
- { id: "geometria.largura", rotulo: "Largura", tipo: "numero", valor: o(r - a), ...C, min: 0 },
2346
- { id: "geometria.altura", rotulo: "Altura", tipo: "numero", valor: o(i - e), ...C, min: 0 }
2347
- ] : [];
2348
- return s.push(g(t, "geometria.rotacao", "Rotação", "numero", { unidade: "°", casasDecimais: 2, passo: 15 })), t.every((n) => n.geometria.tipo === "retangulo") && s.push(g(t, "geometria.raio", "Raio dos cantos", "numero", { ...C, min: 0 })), R(s);
2349
- }
2350
- const I = (t) => String(Math.round(t * 100) / 100).replace(".", ",");
2351
- function Ci(t) {
2352
- const a = t && Number.isFinite(t.largura) && Number.isFinite(t.altura) ? t : null, e = [{ id: "dica", rotulo: "Seleção", tipo: "readonly", valor: "Selecione um elemento para editar", dica: "Clique num elemento ou arraste um retângulo de seleção." }];
2353
- if (a) {
2354
- e.push({ id: "folha.tamanho", rotulo: "Folha", tipo: "readonly", valor: `${I(a.largura)} × ${I(a.altura)} mm` }), a.unidade && e.push({ id: "folha.unidade", rotulo: "Unidade", tipo: "readonly", valor: a.unidade }), Number.isFinite(a.grade) && e.push({ id: "folha.grade", rotulo: "Grade", tipo: "readonly", valor: `${I(a.grade)} mm` });
2355
- const r = a.margens;
2356
- r && e.push({ id: "folha.margens", rotulo: "Margens", tipo: "readonly", valor: `${I(r.esquerda)} / ${I(r.direita)} / ${I(r.superior)} / ${I(r.inferior)} mm`, dica: "esquerda / direita / superior / inferior" });
2357
- }
2358
- return [{ id: "folha", titulo: "Folha", aberto: !0, propriedades: e }];
2359
- }
2360
- function Ei(t) {
2361
- const a = Array.isArray(t) ? t.filter((c) => c && typeof c == "object" && c.geometria) : [];
2362
- if (a.length === 0) return [];
2363
- const e = a.filter((c) => c.geometria.tipo === "texto"), r = a.filter((c) => {
2364
- var l;
2365
- return c.geometria.tipo !== "texto" && ((l = Aa(c)) == null ? void 0 : l.tipo) === "Polygon";
2366
- }), i = a.length > e.length, o = a.length === 1 ? ke(a[0]) : `${a.length} elementos`, s = [
2367
- {
2368
- id: "elemento",
2369
- titulo: "Elemento",
2370
- aberto: !0,
2371
- propriedades: R([
2372
- { id: "elemento.tipo", rotulo: "Tipo", tipo: "readonly", valor: o },
2373
- g(a, "elemento.nome", "Nome", "texto"),
2374
- g(a, "elemento.bloqueado", "Bloqueado", "booleano"),
2375
- g(a, "elemento.oculto", "Oculto", "booleano")
2376
- ])
2377
- },
2378
- { id: "geometria", titulo: "Posição e tamanho", aberto: !0, propriedades: zi(a) }
2379
- ];
2380
- if (i) {
2381
- const c = a.filter((l) => l.geometria.tipo !== "texto");
2382
- s.push({
2383
- id: "traco",
2384
- titulo: "Traço",
2385
- aberto: !0,
2386
- propriedades: R([
2387
- g(c, "traco.ativo", "Com traço", "booleano"),
2388
- g(c, "traco.cor", "Cor", "cor"),
2389
- g(c, "traco.espessura", "Espessura", "numero", { ...C, passo: 0.05, min: 0 }),
2390
- g(c, "traco.opacidade", "Opacidade", "numero", aa),
2391
- g(c, "traco.tipoLinha", "Tipo de linha", "linha", { opcoes: er.map((l) => ({ id: l, rotulo: Mi[l] ?? l })) }),
2392
- g(c, "traco.escalaTipoLinha", "Escala da linha", "numero", { casasDecimais: 2, passo: 0.1, min: 0 }),
2393
- g(c, "traco.terminacao", "Terminação", "selecao", { opcoes: U([["reta", "Reta"], ["arredondada", "Arredondada"], ["quadrada", "Quadrada"]]) }),
2394
- g(c, "traco.juncao", "Junção", "selecao", { opcoes: U([["angular", "Angular"], ["arredondada", "Arredondada"], ["chanfrada", "Chanfrada"]]) }),
2395
- r.length === c.length ? g(c, "traco.alinhamento", "Alinhamento", "selecao", { opcoes: U([["centro", "Centro"], ["dentro", "Dentro"], ["fora", "Fora"]]) }) : null,
2396
- r.length === 0 ? g(c, "traco.pontaInicio", "Ponta inicial", "selecao", { opcoes: Xa }) : null,
2397
- r.length === 0 ? g(c, "traco.pontaFim", "Ponta final", "selecao", { opcoes: Xa }) : null
2398
- ])
2399
- });
2400
- }
2401
- return [...r, ...e].length === a.length && s.push({
2402
- id: "preenchimento",
2403
- titulo: "Preenchimento",
2404
- aberto: !0,
2405
- propriedades: R([
2406
- g(a, "preenchimento.ativo", "Com preenchimento", "booleano"),
2407
- g(a, "preenchimento.cor", "Cor", "cor"),
2408
- g(a, "preenchimento.opacidade", "Opacidade", "numero", aa),
2409
- e.length === 0 ? g(a, "preenchimento.regra", "Regra", "selecao", { opcoes: U([["nonzero", "Diferente de zero"], ["evenodd", "Par-ímpar"]]) }) : null
2410
- ])
2411
- }), r.length === a.length && s.push({
2412
- id: "hachura",
2413
- titulo: "Hachura",
2414
- aberto: !1,
2415
- propriedades: R([
2416
- g(a, "hachura.ativa", "Com hachura", "booleano"),
2417
- g(a, "hachura.angulo", "Ângulo", "numero", { unidade: "°", casasDecimais: 1, passo: 15 }),
2418
- g(a, "hachura.espacamento", "Espaçamento", "numero", { ...C, min: 0.1 }),
2419
- g(a, "hachura.cor", "Cor", "cor"),
2420
- g(a, "hachura.cruzada", "Cruzada", "booleano")
2421
- ])
2422
- }), s.push({
2423
- id: "efeitos",
2424
- titulo: "Efeitos",
2425
- aberto: !1,
2426
- propriedades: R([
2427
- g(a, "efeitos.opacidade", "Opacidade", "numero", aa),
2428
- g(a, "efeitos.mesclagem", "Mesclagem", "selecao", { opcoes: Jt.map((c) => ({ id: c, rotulo: Ai[c] })) }),
2429
- g(a, "sombra.ativa", "Sombra", "booleano"),
2430
- g(a, "sombra.dx", "Sombra X", "numero", C),
2431
- g(a, "sombra.dy", "Sombra Y", "numero", C),
2432
- g(a, "sombra.desfoque", "Desfoque", "numero", { ...C, min: 0 }),
2433
- g(a, "sombra.cor", "Cor da sombra", "cor"),
2434
- g(a, "sombra.opacidade", "Opacidade da sombra", "numero", aa)
2435
- ])
2436
- }), s.filter((c) => c.propriedades.length > 0);
2437
- }
2438
- const L = "prancha:sem-camada", Wa = (t) => typeof t == "string" && t !== L ? t : null;
2439
- function xi(t, a = [], e = {}) {
2440
- const r = Array.isArray(t) ? t.filter((u) => u && typeof u == "object" && u.geometria) : [], i = Array.isArray(a) ? a.filter((u) => u && typeof u.id == "string") : [], o = new Set(i.map((u) => u.id)), s = i.length === 0 && ((e == null ? void 0 : e.ocultarSemCamada) === !0 || (e == null ? void 0 : e.modo) === "simples"), n = (u) => u.camadaId && o.has(u.camadaId) ? u.camadaId : s ? "" : L, c = /* @__PURE__ */ new Map();
2441
- for (const u of r) c.set(n(u), (c.get(n(u)) ?? 0) + 1);
2442
- const l = [];
2443
- !s && (c.has(L) || i.length === 0) && l.push({ id: L, name: "Sem camada", visible: !0, locked: !1, opacity: 1, order: 0, count: c.get(L) ?? 0 });
2444
- for (const u of [...i].reverse())
2445
- l.push({
2446
- id: u.id,
2447
- name: u.nome ?? u.id,
2448
- visible: u.visivel !== !1,
2449
- locked: u.bloqueada === !0,
2450
- opacity: typeof u.opacidade == "number" && Number.isFinite(u.opacidade) ? Math.min(1, Math.max(0, u.opacidade)) : 1,
2451
- order: l.length,
2452
- count: c.get(u.id) ?? 0
2453
- });
2454
- const d = /* @__PURE__ */ new Map(), h = [...B(r, i)].reverse().map((u) => {
2455
- var E, x, H;
2456
- const m = ke(u);
2457
- let p = u.nome;
2458
- if (!p) {
2459
- const V = (d.get(m) ?? 0) + 1;
2460
- d.set(m, V), p = `${m} ${V}`;
2461
- }
2462
- const b = u.geometria.tipo === "texto" ? "Text" : ((E = Aa(u)) == null ? void 0 : E.tipo) === "Polygon" ? "Polygon" : "LineString";
2463
- let M;
2464
- try {
2465
- const V = Qt(u);
2466
- M = ((x = V.preenchimento) == null ? void 0 : x.cor) ?? ((H = V.traco) == null ? void 0 : H.cor);
2467
- } catch {
2468
- M = void 0;
2469
- }
2470
- return { id: u.id, name: p, layerId: n(u), type: b, geometryType: b, visible: u.oculto !== !0, locked: u.bloqueado === !0, color: M };
2471
- });
2472
- return { camadas: l, feicoes: h };
2473
- }
2474
- function Ti(t, a, e) {
2475
- const r = Array.isArray(t) ? t : [];
2476
- return !e || typeof e != "object" ? [...r] : r.map((i) => {
2477
- if (i.id !== a) return i;
2478
- const o = { ...i };
2479
- return typeof e.visivel == "boolean" && (o.visivel = e.visivel), typeof e.bloqueada == "boolean" && (o.bloqueada = e.bloqueada), typeof e.opacidade == "number" && Number.isFinite(e.opacidade) && (o.opacidade = Math.min(1, Math.max(0, e.opacidade))), typeof e.nome == "string" && e.nome.trim() !== "" && (o.nome = e.nome), o;
2480
- });
2481
- }
2482
- function wi(t, a) {
2483
- const e = Array.isArray(t) ? t : [], r = new Map(e.map((n) => [n.id, n])), i = /* @__PURE__ */ new Set(), o = [];
2484
- for (const n of Array.isArray(a) ? a : []) {
2485
- const c = typeof n == "string" ? r.get(n) : void 0;
2486
- c && !i.has(c.id) && (i.add(c.id), o.push(c));
2487
- }
2488
- return [...e.filter((n) => !i.has(n.id)), ...o.reverse()];
2489
- }
2490
- class Ii extends gi {
2491
- static get observedAttributes() {
2492
- return _e;
2493
- }
2494
- // ---------- camadas e isolamento ----------
2495
- /** Camadas da prancha (a primeira fica atrás). Elementos sem camada ficam por cima. */
2496
- definirCamadas(a) {
2497
- this.c.definirCamadas(a);
2498
- }
2499
- obterCamadas() {
2500
- return this.c.camadas.map((a) => ({ ...a }));
2501
- }
2502
- /** Camada que recebe os elementos novos (desenhados, colados, pré-definições); `null` = sem camada. */
2503
- definirCamadaAtiva(a) {
2504
- this.c.camadaAtiva = typeof a == "string" && this.c.camadas.some((e) => e.id === a) ? a : null;
2505
- }
2506
- moverSelecaoParaCamada(a) {
2507
- return Dr(this.c, a);
2508
- }
2509
- /** Isola um grupo (só os membros se selecionam) ou sai do isolamento com `null`. */
2510
- isolarGrupo(a) {
2511
- this.c.isolar(a);
2512
- }
2513
- // ---------- ordem, grupos, bloquear e ocultar ----------
2514
- ordenarSelecao(a) {
2515
- return D(this.c, a);
2516
- }
2517
- trazerParaFrente() {
2518
- return D(this.c, "frente");
2519
- }
2520
- enviarParaTras() {
2521
- return D(this.c, "tras");
2522
- }
2523
- avancar() {
2524
- return D(this.c, "avancar");
2525
- }
2526
- recuar() {
2527
- return D(this.c, "recuar");
2528
- }
2529
- agruparSelecao() {
2530
- return ye(this.c);
2531
- }
2532
- desagruparSelecao() {
2533
- return Se(this.c);
2534
- }
2535
- bloquearSelecao() {
2536
- return sa(this.c, "bloqueado");
2537
- }
2538
- ocultarSelecao() {
2539
- return sa(this.c, "oculto");
2540
- }
2541
- desbloquearTudo() {
2542
- return na(this.c, "bloqueado");
2543
- }
2544
- mostrarTudo() {
2545
- return na(this.c, "oculto");
2546
- }
2547
- // ---------- alinhar, distribuir, duplicar ----------
2548
- /** Alinha à seleção, à folha, ao primeiro selecionado (`'chave'`) ou a uma caixa em mm (as margens, o quadro). */
2549
- alinharSelecao(a, e = "selecao") {
2550
- return Er(this.c, a, e);
2551
- }
2552
- /** Distribui centros ou espaços (iguais, ou `espacamento` fixo em mm). */
2553
- distribuirSelecao(a, e = "espacos", r) {
2554
- return xr(this.c, a, e, r);
2555
- }
2556
- duplicarSelecao(a) {
2557
- return Tr(this.c, a);
2558
- }
2559
- /** Ctrl+D: repete a última transformação (duplicando, se ela foi uma cópia). */
2560
- transformarDeNovo() {
2561
- return Pe(this.c);
2562
- }
2563
- // ---------- área de transferência e aparência ----------
2564
- copiar() {
2565
- return za(this.c);
2566
- }
2567
- recortar() {
2568
- return Ae(this.c);
2569
- }
2570
- /** Cola deslocado a cada colagem, ou no mesmo lugar (`noLugar`). */
2571
- colar(a = !1) {
2572
- return Me(this.c, a);
2573
- }
2574
- aplicarAparencia(a) {
2575
- return Ir(this.c, a);
2576
- }
2577
- // ---------- máscara e operações de caminho ----------
2578
- criarMascara() {
2579
- return ze(this.c);
2580
- }
2581
- liberarMascara() {
2582
- return Ce(this.c);
2583
- }
2584
- unirSelecao(a) {
2585
- return Ee(this.c, a);
2586
- }
2587
- dividirSelecao() {
2588
- return qr(this.c);
2589
- }
2590
- /** Deslocar caminho (offset): cria um contorno novo a `distancia` mm (negativo = para dentro). */
2591
- deslocarCaminho(a) {
2592
- return _r(this.c, a);
2593
- }
2594
- simplificarSelecao(a) {
2595
- return Fr(this.c, a);
2596
- }
2597
- contornarTraco() {
2598
- return kr(this.c);
2599
- }
2600
- converterEmCaminho() {
2601
- return Rr(this.c);
2602
- }
2603
- // ---------- Pathfinder (Fase 5) ----------
2604
- /**
2605
- * Operação booleana sobre a seleção: `'uniao'`, `'subtracao'` (o mais atrás menos os outros), `'intersecao'` ou
2606
- * `'exclusao'`. O resultado é um caminho composto com o id e a aparência do mais à frente (na subtração, do mais atrás).
2607
- */
2608
- pathfinder(a) {
2609
- return k(this.c, a);
2610
- }
2611
- /** Ctrl+Alt+Shift+1. */
2612
- unirFormas() {
2613
- return k(this.c, "uniao");
2614
- }
2615
- /** Ctrl+Alt+Shift+2 ("menos frente"). */
2616
- subtrairFrente() {
2617
- return k(this.c, "subtracao");
2618
- }
2619
- /** Ctrl+Alt+Shift+3. */
2620
- intersectarFormas() {
2621
- return k(this.c, "intersecao");
2622
- }
2623
- /** Ctrl+Alt+Shift+4. */
2624
- excluirSobreposicao() {
2625
- return k(this.c, "exclusao");
2626
- }
2627
- // ---------- painéis (Fase 6) ----------
2628
- /**
2629
- * Categorias para o `<ui-tabela-propriedades>` com a seleção atual. Sem seleção: a categoria "Folha" (tamanho, unidade,
2630
- * grade, margens, somente leitura) com a dica "Selecione um elemento para editar", em vez de um painel vazio.
2631
- */
2632
- categoriasDePropriedades() {
2633
- const a = this.c.doc.elementosSelecionados();
2634
- return a.length > 0 ? Ei(a) : Ci({ largura: this.c.folha.largura, altura: this.c.folha.altura, unidade: this.c.unidade, grade: this.c.grade, margens: this.c.margens });
2635
- }
2636
- /**
2637
- * Aplica um campo do painel de propriedades à seleção (o `id` e o `valor` do `ui-propriedade-alterada`). Ação do usuário:
2638
- * histórico (rajada no mesmo campo = um passo) e `prancha-elemento-atualizado` com motivo `propriedades`.
2639
- */
2640
- aplicarPropriedade(a, e) {
2641
- return yi(this.c, a, e);
2642
- }
2643
- /** Dados para o `<ui-camadas>` (`painel.definirCamadas(d.camadas, d.feicoes)`), da frente para trás. */
2644
- dadosParaPainelDeCamadas(a) {
2645
- return xi(this.c.doc.elementos, this.c.camadas, a);
2646
- }
2647
- /** Oculta, trava, renomeia ou muda de camada elementos pelo id (o painel de camadas), inclusive travados. */
2648
- alterarElementos(a, e) {
2649
- return Si(this.c, a, e);
2650
- }
2651
- }
2652
- Qa("ui-canvas-prancha", Ii);
2653
- const S = (t) => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`, ta = {
2654
- selecao: S('<path d="M5 3l14 8-6 2-3 6z" fill="currentColor"/>'),
2655
- "selecao-direta": S('<path d="M5 3l14 8-6 2-3 6z"/>'),
2656
- mao: S('<path d="M18 11V6a2 2 0 0 0-4 0M14 10V4a2 2 0 0 0-4 0v2M10 10.5V6a2 2 0 0 0-4 0v8M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.9-5.9-2.4L3.4 16a2 2 0 0 1 3.2-2.4L8 15"/>'),
2657
- retangulo: S('<rect x="3" y="5" width="18" height="14" rx="1"/>'),
2658
- elipse: S('<ellipse cx="12" cy="12" rx="9" ry="7"/>'),
2659
- "poligono-regular": S('<path d="M12 3l8 5v8l-8 5-8-5V8z"/>'),
2660
- estrela: S('<path d="M12 3l2.6 5.6 6.1.7-4.5 4.2 1.2 6L12 16.6 6.6 19.5l1.2-6L3.3 9.3l6.1-.7z"/>'),
2661
- linha: S('<line x1="5" y1="19" x2="19" y2="5"/>'),
2662
- seta: S('<line x1="5" y1="19" x2="19" y2="5"/><path d="M11 5h8v8"/>'),
2663
- polilinha: S('<polyline points="3 17 9 11 13 15 21 7"/>'),
2664
- poligono: S('<path d="M4 18l3-12 10 2 3 9z"/>'),
2665
- caneta: S('<path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/><path d="M2 2l7.6 7.6"/>'),
2666
- texto: S('<path d="M4 7V4h16v3M9 20h6M12 4v16"/>'),
2667
- "conta-gotas": S('<path d="M14 4l6 6M17 7l-9 9-4 1 1-4 9-9"/>'),
2668
- "adicionar-ancora": S('<path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5"/><path d="M4 20h6M7 17v6"/>'),
2669
- "excluir-ancora": S('<path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5"/><path d="M4 20h6"/>'),
2670
- "converter-ancora": S('<path d="M4 20L12 4l8 16"/><path d="M8 12h8"/>')
2671
- }, P = (t, a, e) => ({ id: t, rotulo: a, icone: ta[t], tipo: "ferramenta", ...e ? { atalho: e } : {} }), Di = Object.freeze([
2672
- P("selecao", "Seleção", "V"),
2673
- P("selecao-direta", "Seleção direta", "A"),
2674
- { id: "grupo-caneta", rotulo: "Caneta", icone: ta.caneta, tipo: "ferramenta", filhos: [
2675
- P("caneta", "Caneta", "P"),
2676
- P("adicionar-ancora", "Adicionar âncora", "+"),
2677
- P("excluir-ancora", "Excluir âncora", "-"),
2678
- P("converter-ancora", "Converter âncora", "Shift+C")
2679
- ] },
2680
- P("texto", "Texto", "T"),
2681
- { id: "grupo-linhas", rotulo: "Linhas", icone: ta.linha, tipo: "ferramenta", filhos: [
2682
- P("linha", "Linha", "\\"),
2683
- P("seta", "Seta"),
2684
- P("polilinha", "Polilinha"),
2685
- P("poligono", "Polígono")
2686
- ] },
2687
- { id: "grupo-formas", rotulo: "Formas", icone: ta.retangulo, tipo: "ferramenta", filhos: [
2688
- P("retangulo", "Retângulo", "M"),
2689
- P("elipse", "Elipse", "L"),
2690
- P("poligono-regular", "Polígono regular"),
2691
- P("estrela", "Estrela")
2692
- ] },
2693
- P("conta-gotas", "Conta-gotas", "I"),
2694
- P("mao", "Mão", "H")
2695
- ]);
2696
- function qi(t) {
2697
- return typeof t == "string" && De.includes(t) ? t : null;
2698
- }
2699
- const _i = ["prancha-elemento-criado", "prancha-elemento-atualizado", "prancha-elemento-removido", "prancha-ordem", "prancha-camadas"], Fi = (t) => t.detail ?? {};
2700
- function ki(t) {
2701
- const { prancha: a, paleta: e, camadas: r, propriedades: i } = t ?? {};
2702
- if (!a) return () => {
2703
- };
2704
- const o = new ba(), s = (h, u, m) => o.add(h, u, (p) => {
2705
- try {
2706
- m(Fi(p));
2707
- } catch {
2708
- }
2709
- });
2710
- e && (e.ferramentas = Di, e.valor = a.ferramenta, s(e, "ui-change", (h) => {
2711
- const u = qi(h.valor);
2712
- u && a.definirFerramenta(u);
2713
- }), s(a, "prancha-ferramenta", (h) => {
2714
- e.valor = h.ferramenta;
2715
- }));
2716
- const n = () => {
2717
- i && (i.categorias = a.categoriasDePropriedades());
2718
- };
2719
- i && s(i, "ui-propriedade-alterada", (h) => {
2720
- a.aplicarPropriedade(h.id, h.valor);
2721
- });
2722
- const c = () => {
2723
- var u;
2724
- if (!r) return;
2725
- const h = a.dadosParaPainelDeCamadas({ ocultarSemCamada: t.listaPlana !== !1 });
2726
- r.definirCamadas(h.camadas, h.feicoes), (u = r.selecionarFeicoes) == null || u.call(r, a.selecao);
2727
- }, l = (h, u) => {
2728
- h !== L && a.definirCamadas(Ti(a.obterCamadas(), h, u));
2729
- };
2730
- if (r) {
2731
- const h = r;
2732
- s(h, "ui-camada-visibilidade", (u) => l(u.camadaId, { visivel: u.visivel })), s(h, "ui-camada-bloqueio", (u) => l(u.camadaId, { bloqueada: u.bloqueado })), s(h, "ui-camada-opacidade", (u) => l(u.camadaId, { opacidade: u.opacidade })), s(h, "ui-camada-renomeada", (u) => l(u.camadaId, { nome: u.novoNome })), s(h, "ui-camada-selecionada", (u) => a.definirCamadaAtiva(Wa(u.camadaId))), s(h, "ui-camadas-reordenadas", (u) => {
2733
- a.definirCamadas(wi(a.obterCamadas(), (u.camadas ?? []).map((m) => m.id)));
2734
- }), s(h, "ui-camada-adicionar", () => {
2735
- const u = a.obterCamadas();
2736
- let m = u.length + 1;
2737
- for (; u.some((p) => p.id === `camada-${m}`); ) m++;
2738
- a.definirCamadas([...u, { id: `camada-${m}`, nome: `Camada ${m}` }]);
2739
- }), s(h, "ui-feicao-selecionada", (u) => a.selecionarElementos([u.feicaoId])), s(h, "ui-feicoes-selecionadas", (u) => a.selecionarElementos(u.feicoesIds ?? [])), s(h, "ui-feicao-visibilidade", (u) => a.alterarElementos([u.feicaoId], { oculto: !u.visivel })), s(h, "ui-feicao-bloqueio", (u) => a.alterarElementos([u.feicaoId], { bloqueado: u.bloqueado })), s(h, "ui-feicao-renomeada", (u) => a.alterarElementos([u.feicaoId], { nome: u.novoNome })), s(h, "ui-feicao-movida", (u) => a.alterarElementos([u.feicaoId], { camadaId: Wa(u.camadaDestinoId) }));
2740
- }
2741
- for (const h of _i) o.add(a, h, () => {
2742
- c(), n();
2743
- });
2744
- o.add(a, "prancha-selecao", () => {
2745
- var h;
2746
- (h = r == null ? void 0 : r.selecionarFeicoes) == null || h.call(r, a.selecao), n();
2747
- }), c(), n();
2748
- let d = !0;
2749
- return () => {
2750
- d && (d = !1, o.cleanup());
2751
- };
2752
- }
2753
- const Ri = ":host{display:block;min-height:360px;min-width:320px;height:100%;color:var(--ui-cor-texto);font-family:var(--ui-fonte-base);box-sizing:border-box}:host([hidden]){display:none}.raiz{display:grid;grid-template-rows:auto 1fr auto;height:100%;min-height:inherit;gap:var(--ui-espaco-sm);box-sizing:border-box}.barra,.acoes{display:flex;flex-wrap:wrap;gap:var(--ui-espaco-xs);align-items:center}.acoes{justify-content:flex-end}.area{display:flex;gap:var(--ui-espaco-sm);align-items:stretch;min-height:0;min-width:0}.area>ui-paleta-ferramentas{flex:0 0 auto}.area>ui-canvas-prancha{flex:1 1 auto;min-width:0;height:auto}.lateral{flex:0 0 var(--ui-editor-prancha-lateral, 300px);display:flex;flex-direction:column;gap:var(--ui-espaco-sm);min-width:0}.lateral>ui-tabela-propriedades{flex:1 1 auto;min-height:200px}button{font:inherit;font-size:var(--ui-tamanho-corpo-sm);color:var(--ui-cor-texto);background:var(--ui-cor-superficie);border:1px solid var(--ui-cor-borda);border-radius:var(--ui-raio-sm);padding:var(--ui-espaco-xs) var(--ui-espaco-md);cursor:pointer}button:hover{border-color:var(--ui-cor-primaria)}button:focus-visible{outline:2px solid var(--ui-cor-primaria);outline-offset:2px}button.primario{background:var(--ui-cor-primaria);color:var(--ui-cor-texto-sobre-primaria, #000);border-color:var(--ui-cor-primaria)}@media (max-width: 720px){.area{flex-direction:column}.lateral{flex:0 0 auto}}", Ja = ["largura", "altura", "unidade", "grade", "mostrar-grade", "margens", "ajustar-ao-abrir", "somente-leitura", "sem-snap", "sem-reguas", "rotulo"];
2754
- class Li extends Ya {
2755
- constructor() {
2756
- super();
2757
- f(this, "shadow");
2758
- f(this, "bag", new ba());
2759
- f(this, "desligarPaineis", null);
2760
- f(this, "_prancha");
2761
- f(this, "paleta");
2762
- f(this, "painelCamadas");
2763
- f(this, "painelPropriedades");
2764
- this.shadow = this.attachShadow({ mode: "open" }), this.shadow.innerHTML = `
2765
- <style>${Ri}</style>
2766
- <div class="raiz" part="base">
2767
- <div class="barra" part="barra" id="barra" role="toolbar" aria-label="Pré-definições"></div>
2768
- <div class="area">
2769
- <ui-paleta-ferramentas id="paleta" orientacao="vertical" atalhos></ui-paleta-ferramentas>
2770
- <ui-canvas-prancha id="prancha" part="prancha" teclado="exclusivo" ajustar-ao-abrir="folha"></ui-canvas-prancha>
2771
- <div class="lateral" part="lateral">
2772
- <ui-camadas id="camadas" densidade="compacto" mostrar-mapas-base="false" mostrar-rodape="false" persistir="false" altura="260"></ui-camadas>
2773
- <ui-tabela-propriedades id="propriedades" titulo="Aparência" modo-aplicar="imediato"></ui-tabela-propriedades>
2774
- </div>
2775
- </div>
2776
- <div class="acoes" part="acoes">
2777
- <button type="button" id="cancelar">Cancelar</button>
2778
- <button type="button" id="concluir" class="primario">Concluir</button>
2779
- </div>
2780
- </div>`;
2781
- const e = (i) => this.shadow.getElementById(i);
2782
- this._prancha = e("prancha"), this.paleta = e("paleta"), this.painelCamadas = e("camadas"), this.painelPropriedades = e("propriedades");
2783
- const r = e("barra");
2784
- for (const i of wa) {
2785
- const o = document.createElement("button");
2786
- o.type = "button", o.dataset.predefinicao = i.valor, o.textContent = i.rotulo, r.appendChild(o);
2787
- }
2788
- }
2789
- static get observedAttributes() {
2790
- return [...Ja, "teclado"];
2791
- }
2792
- connectedCallback() {
2793
- var e;
2794
- this.bag.cleanup(), (e = this.desligarPaineis) == null || e.call(this), this.sincronizarAtributos(), this.desligarPaineis = ki({
2795
- prancha: this._prancha,
2796
- paleta: this.paleta,
2797
- camadas: this.painelCamadas,
2798
- propriedades: this.painelPropriedades
2799
- }), this.bag.add(this.shadow.getElementById("concluir"), "click", () => this.concluir()), this.bag.add(this.shadow.getElementById("cancelar"), "click", () => this.cancelar()), this.bag.add(this.shadow.getElementById("barra"), "click", (r) => {
2800
- var s, n;
2801
- const i = (n = (s = r.target) == null ? void 0 : s.closest) == null ? void 0 : n.call(s, "button[data-predefinicao]"), o = wa.find((c) => c.valor === (i == null ? void 0 : i.dataset.predefinicao));
2802
- o && this._prancha.inserirPredefinicao(o.valor, void 0, o.usaQuadro ? { quadro: "margens" } : {});
2803
- }), this.bag.add(this._prancha, "prancha-esc-sem-efeito", () => this.cancelar());
2804
- }
2805
- disconnectedCallback() {
2806
- var e;
2807
- this.bag.cleanup(), (e = this.desligarPaineis) == null || e.call(this), this.desligarPaineis = null;
2808
- }
2809
- attributeChangedCallback(e, r, i) {
2810
- this.repassar(e, i);
2811
- }
2812
- repassar(e, r) {
2813
- const i = e === "teclado" ? "teclado" : e, o = e === "teclado" ? r === "local" ? null : "exclusivo" : r;
2814
- o === null ? this._prancha.removeAttribute(i) : this._prancha.setAttribute(i, o);
2815
- }
2816
- sincronizarAtributos() {
2817
- for (const e of Ja) this.repassar(e, this.getAttribute(e));
2818
- this.repassar("teclado", this.getAttribute("teclado"));
2819
- }
2820
- // ---------- API ----------
2821
- /** A prancha interna (para usar a API completa: ferramentas, vista, exportação). */
2822
- get prancha() {
2823
- return this._prancha;
2824
- }
2825
- /** Elementos do desenho. Ao atribuir, carrega (normaliza) e marca como salvo. */
2826
- get elementos() {
2827
- return this._prancha.obterElementos();
2828
- }
2829
- set elementos(e) {
2830
- this._prancha.definirElementos(Array.isArray(e) ? e : []);
2831
- }
2832
- get camadas() {
2833
- return this._prancha.obterCamadas();
2834
- }
2835
- set camadas(e) {
2836
- this._prancha.definirCamadas(Array.isArray(e) ? e : []);
2837
- }
2838
- get modificado() {
2839
- return this._prancha.modificado;
2840
- }
2841
- marcarComoSalvo() {
2842
- this._prancha.marcarComoSalvo();
2843
- }
2844
- /** Resolve quando a prancha mediu o layout e consegue enquadrar. */
2845
- get pronto() {
2846
- return this._prancha.pronto;
2847
- }
2848
- /** Confirma: emite `editor-concluir` com os dados atuais. */
2849
- concluir() {
2850
- const e = { elementos: this._prancha.obterElementos(), camadas: this._prancha.obterCamadas(), modificado: this._prancha.modificado };
2851
- this.dispatchEvent(new CustomEvent("editor-concluir", { detail: e, bubbles: !0, composed: !0 }));
2852
- }
2853
- /** Cancela: emite `editor-cancelar`. */
2854
- cancelar() {
2855
- const e = { modificado: this._prancha.modificado };
2856
- this.dispatchEvent(new CustomEvent("editor-cancelar", { detail: e, bubbles: !0, composed: !0 }));
2857
- }
2858
- focus(e) {
2859
- this._prancha.focus(e);
2860
- }
2861
- }
2862
- Qa("ui-editor-prancha", Li);
2863
- export {
2864
- _e as A,
2865
- L as C,
2866
- Di as F,
2867
- $ as P,
2868
- Ii as U,
2869
- ci as a,
2870
- li as b,
2871
- De as c,
2872
- gi as d,
2873
- Li as e,
2874
- Wa as f,
2875
- Ti as g,
2876
- wi as h,
2877
- Ei as i,
2878
- Ci as j,
2879
- xi as k,
2880
- qe as l,
2881
- Ki as m,
2882
- qi as n,
2883
- Fe as o,
2884
- ki as p,
2885
- ke as r
2886
- };