@erplora/outfitkit 0.1.1

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 (210) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +457 -0
  3. package/dist/base/anchor.d.ts +13 -0
  4. package/dist/base/define.d.ts +1 -0
  5. package/dist/base/relay.d.ts +1 -0
  6. package/dist/cdn.d.ts +96 -0
  7. package/dist/components/ok-app-launcher/ok-app-launcher.d.ts +57 -0
  8. package/dist/components/ok-audio/ok-audio.d.ts +45 -0
  9. package/dist/components/ok-avatar/ok-avatar.d.ts +36 -0
  10. package/dist/components/ok-avatar-group/ok-avatar-group.d.ts +38 -0
  11. package/dist/components/ok-bar-list/ok-bar-list.d.ts +36 -0
  12. package/dist/components/ok-bento/ok-bento.d.ts +17 -0
  13. package/dist/components/ok-bento-item/ok-bento-item.d.ts +34 -0
  14. package/dist/components/ok-calculator/ok-calculator.d.ts +46 -0
  15. package/dist/components/ok-calendar/ok-calendar.d.ts +63 -0
  16. package/dist/components/ok-carousel/ok-carousel.d.ts +48 -0
  17. package/dist/components/ok-chart/ok-chart.d.ts +55 -0
  18. package/dist/components/ok-chat/ok-chat.d.ts +54 -0
  19. package/dist/components/ok-coachmark/ok-coachmark.d.ts +69 -0
  20. package/dist/components/ok-code/ok-code.d.ts +28 -0
  21. package/dist/components/ok-color-picker/ok-color-picker.d.ts +63 -0
  22. package/dist/components/ok-combo/ok-combo.d.ts +46 -0
  23. package/dist/components/ok-command-palette/ok-command-palette.d.ts +72 -0
  24. package/dist/components/ok-contact-form/ok-contact-form.d.ts +54 -0
  25. package/dist/components/ok-cropper/ok-cropper.d.ts +60 -0
  26. package/dist/components/ok-cta-band/ok-cta-band.d.ts +18 -0
  27. package/dist/components/ok-currency/ok-currency.d.ts +31 -0
  28. package/dist/components/ok-data-table/ok-data-table.d.ts +312 -0
  29. package/dist/components/ok-date-picker/ok-date-picker.d.ts +81 -0
  30. package/dist/components/ok-detail-list/ok-detail-list.d.ts +30 -0
  31. package/dist/components/ok-diff/ok-diff.d.ts +38 -0
  32. package/dist/components/ok-donut/ok-donut.d.ts +38 -0
  33. package/dist/components/ok-drawer/ok-drawer.d.ts +56 -0
  34. package/dist/components/ok-dropzone/ok-dropzone.d.ts +48 -0
  35. package/dist/components/ok-empty-state/ok-empty-state.d.ts +16 -0
  36. package/dist/components/ok-error-page/ok-error-page.d.ts +77 -0
  37. package/dist/components/ok-event-card/ok-event-card.d.ts +56 -0
  38. package/dist/components/ok-feature-card/ok-feature-card.d.ts +23 -0
  39. package/dist/components/ok-file-item/ok-file-item.d.ts +31 -0
  40. package/dist/components/ok-file-manager/ok-file-manager.d.ts +145 -0
  41. package/dist/components/ok-footer/ok-footer.d.ts +10 -0
  42. package/dist/components/ok-funnel/ok-funnel.d.ts +31 -0
  43. package/dist/components/ok-gallery/ok-gallery.d.ts +34 -0
  44. package/dist/components/ok-gauge/ok-gauge.d.ts +49 -0
  45. package/dist/components/ok-heatmap/ok-heatmap.d.ts +45 -0
  46. package/dist/components/ok-hero/ok-hero.d.ts +10 -0
  47. package/dist/components/ok-hover-card/ok-hover-card.d.ts +76 -0
  48. package/dist/components/ok-icon-tile/ok-icon-tile.d.ts +24 -0
  49. package/dist/components/ok-image/ok-image.d.ts +56 -0
  50. package/dist/components/ok-inline-feedback/ok-inline-feedback.d.ts +33 -0
  51. package/dist/components/ok-invoice/ok-invoice.d.ts +137 -0
  52. package/dist/components/ok-json-viewer/ok-json-viewer.d.ts +31 -0
  53. package/dist/components/ok-kanban/ok-kanban.d.ts +56 -0
  54. package/dist/components/ok-kbd/ok-kbd.d.ts +21 -0
  55. package/dist/components/ok-keyboard/ok-keyboard.d.ts +35 -0
  56. package/dist/components/ok-kpi/ok-kpi.d.ts +24 -0
  57. package/dist/components/ok-language-select/ok-language-select.d.ts +31 -0
  58. package/dist/components/ok-lightbox/ok-lightbox.d.ts +59 -0
  59. package/dist/components/ok-logo-cloud/ok-logo-cloud.d.ts +14 -0
  60. package/dist/components/ok-loyalty-card/ok-loyalty-card.d.ts +35 -0
  61. package/dist/components/ok-mail/ok-mail.d.ts +117 -0
  62. package/dist/components/ok-menu/ok-menu.d.ts +75 -0
  63. package/dist/components/ok-menubar/ok-menubar.d.ts +75 -0
  64. package/dist/components/ok-navbar/ok-navbar.d.ts +42 -0
  65. package/dist/components/ok-notification-center/ok-notification-center.d.ts +79 -0
  66. package/dist/components/ok-org-chart/ok-org-chart.d.ts +67 -0
  67. package/dist/components/ok-otp/ok-otp.d.ts +31 -0
  68. package/dist/components/ok-page-header/ok-page-header.d.ts +23 -0
  69. package/dist/components/ok-pagination/ok-pagination.d.ts +44 -0
  70. package/dist/components/ok-pdf/ok-pdf.d.ts +32 -0
  71. package/dist/components/ok-phone/ok-phone.d.ts +48 -0
  72. package/dist/components/ok-pinpad/ok-pinpad.d.ts +29 -0
  73. package/dist/components/ok-pricing-card/ok-pricing-card.d.ts +31 -0
  74. package/dist/components/ok-product-card/ok-product-card.d.ts +25 -0
  75. package/dist/components/ok-qr/ok-qr.d.ts +24 -0
  76. package/dist/components/ok-qty-stepper/ok-qty-stepper.d.ts +35 -0
  77. package/dist/components/ok-range-dual/ok-range-dual.d.ts +38 -0
  78. package/dist/components/ok-rating/ok-rating.d.ts +33 -0
  79. package/dist/components/ok-receipt/ok-receipt.d.ts +103 -0
  80. package/dist/components/ok-reveal/ok-reveal.d.ts +21 -0
  81. package/dist/components/ok-rich-text/ok-rich-text.d.ts +46 -0
  82. package/dist/components/ok-scheduler/ok-scheduler.d.ts +74 -0
  83. package/dist/components/ok-select-card/ok-select-card.d.ts +37 -0
  84. package/dist/components/ok-signature/ok-signature.d.ts +55 -0
  85. package/dist/components/ok-skeleton/ok-skeleton.d.ts +40 -0
  86. package/dist/components/ok-sparkline/ok-sparkline.d.ts +27 -0
  87. package/dist/components/ok-split-button/ok-split-button.d.ts +49 -0
  88. package/dist/components/ok-splitter/ok-splitter.d.ts +36 -0
  89. package/dist/components/ok-stat/ok-stat.d.ts +16 -0
  90. package/dist/components/ok-status-dot/ok-status-dot.d.ts +24 -0
  91. package/dist/components/ok-status-pill/ok-status-pill.d.ts +22 -0
  92. package/dist/components/ok-stepper/ok-stepper.d.ts +33 -0
  93. package/dist/components/ok-store/ok-store.d.ts +33 -0
  94. package/dist/components/ok-tag-input/ok-tag-input.d.ts +39 -0
  95. package/dist/components/ok-testimonial/ok-testimonial.d.ts +21 -0
  96. package/dist/components/ok-time-picker/ok-time-picker.d.ts +50 -0
  97. package/dist/components/ok-timeline/ok-timeline.d.ts +33 -0
  98. package/dist/components/ok-tree/ok-tree.d.ts +46 -0
  99. package/dist/components/ok-video/ok-video.d.ts +49 -0
  100. package/dist/components/ok-widget-board/ok-widget-board.d.ts +71 -0
  101. package/dist/components/ok-wizard/ok-wizard.d.ts +30 -0
  102. package/dist/define.js +8 -0
  103. package/dist/erplora.css +112 -0
  104. package/dist/index.d.ts +158 -0
  105. package/dist/index.js +197 -0
  106. package/dist/layout.css +338 -0
  107. package/dist/ok-app-launcher.js +396 -0
  108. package/dist/ok-audio.js +308 -0
  109. package/dist/ok-avatar-group.js +158 -0
  110. package/dist/ok-avatar.js +179 -0
  111. package/dist/ok-bar-list.js +189 -0
  112. package/dist/ok-bento-item.js +168 -0
  113. package/dist/ok-bento.js +63 -0
  114. package/dist/ok-calculator.js +406 -0
  115. package/dist/ok-calendar.js +541 -0
  116. package/dist/ok-carousel.js +352 -0
  117. package/dist/ok-chart.js +325 -0
  118. package/dist/ok-chat.js +320 -0
  119. package/dist/ok-coachmark.js +500 -0
  120. package/dist/ok-code.js +190 -0
  121. package/dist/ok-color-picker.js +569 -0
  122. package/dist/ok-combo.js +294 -0
  123. package/dist/ok-command-palette.js +448 -0
  124. package/dist/ok-contact-form.js +288 -0
  125. package/dist/ok-cropper.js +404 -0
  126. package/dist/ok-cta-band.js +134 -0
  127. package/dist/ok-currency.js +172 -0
  128. package/dist/ok-data-table.js +1281 -0
  129. package/dist/ok-date-picker.js +736 -0
  130. package/dist/ok-detail-list.js +156 -0
  131. package/dist/ok-diff.js +200 -0
  132. package/dist/ok-donut.js +280 -0
  133. package/dist/ok-drawer.js +357 -0
  134. package/dist/ok-dropzone.js +376 -0
  135. package/dist/ok-empty-state.js +104 -0
  136. package/dist/ok-error-page.js +547 -0
  137. package/dist/ok-event-card.js +384 -0
  138. package/dist/ok-feature-card.js +152 -0
  139. package/dist/ok-file-item.js +259 -0
  140. package/dist/ok-file-manager.js +1116 -0
  141. package/dist/ok-footer.js +67 -0
  142. package/dist/ok-funnel.js +181 -0
  143. package/dist/ok-gallery.js +293 -0
  144. package/dist/ok-gauge.js +385 -0
  145. package/dist/ok-heatmap.js +268 -0
  146. package/dist/ok-hero.js +43 -0
  147. package/dist/ok-hover-card.js +480 -0
  148. package/dist/ok-icon-tile.js +123 -0
  149. package/dist/ok-image.js +471 -0
  150. package/dist/ok-inline-feedback.js +221 -0
  151. package/dist/ok-invoice.js +229 -0
  152. package/dist/ok-json-viewer.js +330 -0
  153. package/dist/ok-kanban.js +427 -0
  154. package/dist/ok-kbd.js +159 -0
  155. package/dist/ok-keyboard.js +402 -0
  156. package/dist/ok-kpi.js +147 -0
  157. package/dist/ok-language-select.js +188 -0
  158. package/dist/ok-lightbox.js +490 -0
  159. package/dist/ok-logo-cloud.js +92 -0
  160. package/dist/ok-loyalty-card.js +353 -0
  161. package/dist/ok-mail.js +562 -0
  162. package/dist/ok-menu.js +529 -0
  163. package/dist/ok-menubar.js +628 -0
  164. package/dist/ok-navbar.js +306 -0
  165. package/dist/ok-notification-center.js +545 -0
  166. package/dist/ok-org-chart.js +619 -0
  167. package/dist/ok-otp.js +199 -0
  168. package/dist/ok-page-header.js +202 -0
  169. package/dist/ok-pagination.js +366 -0
  170. package/dist/ok-pdf.js +160 -0
  171. package/dist/ok-phone.js +225 -0
  172. package/dist/ok-pinpad.js +171 -0
  173. package/dist/ok-pricing-card.js +184 -0
  174. package/dist/ok-product-card.js +178 -0
  175. package/dist/ok-qr.js +652 -0
  176. package/dist/ok-qty-stepper.js +212 -0
  177. package/dist/ok-range-dual.js +280 -0
  178. package/dist/ok-rating.js +199 -0
  179. package/dist/ok-receipt.js +183 -0
  180. package/dist/ok-reveal.js +94 -0
  181. package/dist/ok-rich-text.js +538 -0
  182. package/dist/ok-scheduler.js +518 -0
  183. package/dist/ok-select-card.js +231 -0
  184. package/dist/ok-signature.js +267 -0
  185. package/dist/ok-skeleton.js +345 -0
  186. package/dist/ok-sparkline.js +150 -0
  187. package/dist/ok-split-button.js +251 -0
  188. package/dist/ok-splitter.js +289 -0
  189. package/dist/ok-stat.js +77 -0
  190. package/dist/ok-status-dot.js +163 -0
  191. package/dist/ok-status-pill.js +123 -0
  192. package/dist/ok-stepper.js +299 -0
  193. package/dist/ok-store.js +83 -0
  194. package/dist/ok-tag-input.js +358 -0
  195. package/dist/ok-testimonial.js +136 -0
  196. package/dist/ok-time-picker.js +472 -0
  197. package/dist/ok-timeline.js +251 -0
  198. package/dist/ok-tree.js +266 -0
  199. package/dist/ok-video.js +362 -0
  200. package/dist/ok-widget-board.js +265 -0
  201. package/dist/ok-wizard.js +153 -0
  202. package/dist/outfitkit.js +96 -0
  203. package/dist/shared/anchor.js +14 -0
  204. package/dist/store/controller.d.ts +17 -0
  205. package/dist/store/idb.d.ts +16 -0
  206. package/dist/store/store.d.ts +39 -0
  207. package/dist/store-controller.js +31 -0
  208. package/dist/store.js +182 -0
  209. package/dist/theme.example.css +70 -0
  210. package/package.json +147 -0
@@ -0,0 +1,231 @@
1
+ import { LitElement, css, html } from "lit";
2
+ import { property } from "lit/decorators.js";
3
+ import { define } from "./define.js";
4
+ var __defProp = Object.defineProperty;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = void 0;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = decorator(target, key, result) || result;
10
+ if (result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ class OkSelectCard extends LitElement {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.mode = "checkbox";
17
+ this.value = "";
18
+ this.checked = false;
19
+ this.disabled = false;
20
+ }
21
+ static {
22
+ this.styles = css`
23
+ :host {
24
+ display: block;
25
+ width: 100%;
26
+ /* Tokens propios estilo Ionic (overridables): --ok-* → --ion-* → hex. */
27
+ --bg: var(--ok-surface, var(--ion-background-color, #ffffff));
28
+ --bg-hover: var(--ok-surface-hover, var(--ion-color-step-50, #f2f3f5));
29
+ --border-color: var(--ok-border-color, var(--ion-border-color, #d7d8da));
30
+ --radius: var(--ok-radius-md, 12px);
31
+ --text-color: var(--ok-text-color, var(--ion-text-color, #1f2933));
32
+ --muted-color: var(--ok-color-medium, var(--ion-color-medium, #92949c));
33
+ --brand: var(--ok-color-primary, var(--ion-color-primary, #3880ff));
34
+ /* Fondo suave de marca: si no hay token, se deriva del brand con transparencia. */
35
+ --brand-soft: var(--ok-color-primary-soft, var(--ion-color-primary-tint, rgba(56, 128, 255, 0.1)));
36
+ --gap: 0.75rem;
37
+ --pad: 0.875rem;
38
+ }
39
+
40
+ :host([disabled]) {
41
+ opacity: 0.5;
42
+ pointer-events: none;
43
+ }
44
+
45
+ .card {
46
+ display: flex;
47
+ align-items: flex-start;
48
+ gap: var(--gap);
49
+ width: 100%;
50
+ box-sizing: border-box;
51
+ padding: var(--pad);
52
+ border: 1px solid var(--border-color);
53
+ border-radius: var(--radius);
54
+ background: var(--bg);
55
+ cursor: pointer;
56
+ transition:
57
+ background 0.16s ease,
58
+ border-color 0.16s ease,
59
+ box-shadow 0.16s ease;
60
+ /* Sin selección de texto accidental al clicar la fila. */
61
+ user-select: none;
62
+ -webkit-tap-highlight-color: transparent;
63
+ }
64
+
65
+ .card:hover {
66
+ background: var(--bg-hover);
67
+ }
68
+
69
+ /* Estado marcado: borde + fondo de marca. */
70
+ .card[data-checked] {
71
+ background: var(--brand-soft);
72
+ border-color: var(--brand);
73
+ }
74
+
75
+ /* Foco accesible visible sobre toda la fila. */
76
+ .card:focus-visible {
77
+ outline: none;
78
+ box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--brand);
79
+ }
80
+
81
+ .control {
82
+ flex-shrink: 0;
83
+ /* Alinear el control con la primera línea del label. */
84
+ margin-top: 0.0625rem;
85
+ pointer-events: none; /* el click lo gobierna la fila */
86
+ }
87
+
88
+ .icon {
89
+ flex-shrink: 0;
90
+ display: inline-grid;
91
+ place-items: center;
92
+ width: 1.5rem;
93
+ height: 1.5rem;
94
+ color: var(--muted-color);
95
+ }
96
+
97
+ .card[data-checked] .icon {
98
+ color: var(--brand);
99
+ }
100
+
101
+ ion-icon {
102
+ font-size: 1.375rem;
103
+ }
104
+
105
+ .body {
106
+ flex: 1;
107
+ min-width: 0;
108
+ display: flex;
109
+ flex-direction: column;
110
+ gap: 0.125rem;
111
+ }
112
+
113
+ .label {
114
+ margin: 0;
115
+ font-size: 0.9375rem;
116
+ font-weight: 600;
117
+ line-height: 1.3;
118
+ color: var(--text-color);
119
+ }
120
+
121
+ .description {
122
+ margin: 0;
123
+ font-size: 0.8125rem;
124
+ line-height: 1.4;
125
+ color: var(--muted-color);
126
+ }
127
+ `;
128
+ }
129
+ onToggle() {
130
+ if (this.disabled) return;
131
+ if (this.mode === "radio") {
132
+ if (this.checked) return;
133
+ this.checked = true;
134
+ this.uncheckSiblings();
135
+ } else {
136
+ this.checked = !this.checked;
137
+ }
138
+ this.emitChange();
139
+ }
140
+ /** Desmarca el resto de ok-select-card del mismo name (grupo radio). */
141
+ uncheckSiblings() {
142
+ if (!this.name) return;
143
+ const root = this.getRootNode() ?? document;
144
+ const group = root.querySelectorAll("ok-select-card");
145
+ group.forEach((card) => {
146
+ if (card !== this && card.mode === "radio" && card.name === this.name && card.checked) {
147
+ card.checked = false;
148
+ }
149
+ });
150
+ }
151
+ emitChange() {
152
+ const detail = { checked: this.checked, value: this.value };
153
+ this.dispatchEvent(
154
+ new CustomEvent("ok-change", {
155
+ detail,
156
+ bubbles: true,
157
+ composed: true
158
+ })
159
+ );
160
+ }
161
+ onKeydown(e) {
162
+ if (e.key === " " || e.key === "Enter") {
163
+ e.preventDefault();
164
+ this.onToggle();
165
+ }
166
+ }
167
+ render() {
168
+ const isRadio = this.mode === "radio";
169
+ const role = isRadio ? "radio" : "checkbox";
170
+ const control = isRadio ? html`<ion-radio
171
+ class="control"
172
+ aria-hidden="true"
173
+ ?disabled=${this.disabled}
174
+ .value=${this.value}
175
+ ></ion-radio>` : html`<ion-checkbox
176
+ class="control"
177
+ aria-hidden="true"
178
+ ?checked=${this.checked}
179
+ ?disabled=${this.disabled}
180
+ ></ion-checkbox>`;
181
+ return html`
182
+ <div
183
+ class="card"
184
+ role=${role}
185
+ tabindex=${this.disabled ? -1 : 0}
186
+ aria-checked=${this.checked ? "true" : "false"}
187
+ aria-disabled=${this.disabled ? "true" : "false"}
188
+ aria-label=${this.label ?? this.value}
189
+ ?data-checked=${this.checked}
190
+ @click=${this.onToggle}
191
+ @keydown=${this.onKeydown}
192
+ >
193
+ ${control}
194
+ ${this.icon ? html`<span class="icon"><ion-icon name=${this.icon}></ion-icon></span>` : null}
195
+ <div class="body">
196
+ ${this.label ? html`<p class="label">${this.label}</p>` : null}
197
+ ${this.description ? html`<p class="description">${this.description}</p>` : null}
198
+ <slot></slot>
199
+ </div>
200
+ </div>
201
+ `;
202
+ }
203
+ }
204
+ __decorateClass([
205
+ property()
206
+ ], OkSelectCard.prototype, "mode");
207
+ __decorateClass([
208
+ property()
209
+ ], OkSelectCard.prototype, "name");
210
+ __decorateClass([
211
+ property()
212
+ ], OkSelectCard.prototype, "value");
213
+ __decorateClass([
214
+ property({ type: Boolean, reflect: true })
215
+ ], OkSelectCard.prototype, "checked");
216
+ __decorateClass([
217
+ property({ type: Boolean, reflect: true })
218
+ ], OkSelectCard.prototype, "disabled");
219
+ __decorateClass([
220
+ property()
221
+ ], OkSelectCard.prototype, "label");
222
+ __decorateClass([
223
+ property()
224
+ ], OkSelectCard.prototype, "description");
225
+ __decorateClass([
226
+ property()
227
+ ], OkSelectCard.prototype, "icon");
228
+ define("ok-select-card", OkSelectCard);
229
+ export {
230
+ OkSelectCard
231
+ };
@@ -0,0 +1,267 @@
1
+ import { LitElement, css, html } from "lit";
2
+ import { property, query } from "lit/decorators.js";
3
+ import { define } from "./define.js";
4
+ var __defProp = Object.defineProperty;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = void 0;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = decorator(target, key, result) || result;
10
+ if (result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ const DEFAULT_LABELS = {
14
+ clear: "Clear",
15
+ export: "Export",
16
+ exportFilename: "signature.png"
17
+ };
18
+ class OkSignature extends LitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.penColor = "";
22
+ this.lineWidth = 2.5;
23
+ this.background = "";
24
+ this.height = 200;
25
+ this.showExport = false;
26
+ this.labels = {};
27
+ this.ctx = null;
28
+ this.drawing = false;
29
+ this.lastX = 0;
30
+ this.lastY = 0;
31
+ this.hasInk = false;
32
+ }
33
+ static {
34
+ this.styles = css`
35
+ :host {
36
+ /* Vars overridable (estilo Ionic), default = cadena --ok-* → --ion-* → hex */
37
+ --color: var(--ok-text, var(--ion-text-color, #1c1b17));
38
+ --border-color: var(--ok-border, rgba(var(--ion-text-color-rgb, 28, 27, 23), 0.18));
39
+ --bg: var(--ok-surface, var(--ion-background-color, #ffffff));
40
+ --border-radius: var(--ok-radius, 10px);
41
+ --height: 200px;
42
+ --font: var(--ok-font, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
43
+
44
+ /* Ocupa el ancho del contenedor y es responsive. */
45
+ display: block;
46
+ width: 100%;
47
+ color: var(--color);
48
+ font-family: var(--font);
49
+ }
50
+ /* Marco del lienzo. */
51
+ .pad {
52
+ position: relative;
53
+ width: 100%;
54
+ height: var(--height);
55
+ box-sizing: border-box;
56
+ border: 1px solid var(--border-color);
57
+ border-radius: var(--border-radius);
58
+ background: var(--bg);
59
+ overflow: hidden;
60
+ }
61
+ canvas {
62
+ display: block;
63
+ width: 100%;
64
+ height: 100%;
65
+ /* Evita que el navegador interprete el gesto como scroll/zoom mientras se firma. */
66
+ touch-action: none;
67
+ cursor: crosshair;
68
+ }
69
+ /* Barra de acciones bajo el lienzo. */
70
+ .actions {
71
+ display: flex;
72
+ flex-wrap: wrap;
73
+ gap: 0.4rem;
74
+ justify-content: flex-end;
75
+ margin-top: 0.5rem;
76
+ }
77
+ ion-button {
78
+ margin: 0;
79
+ }
80
+ `;
81
+ }
82
+ get t() {
83
+ return { ...DEFAULT_LABELS, ...this.labels };
84
+ }
85
+ firstUpdated() {
86
+ this.ctx = this.canvas.getContext("2d");
87
+ this.setupCanvas();
88
+ this.ro = new ResizeObserver(() => this.setupCanvas(true));
89
+ this.ro.observe(this.canvas);
90
+ }
91
+ updated(changed) {
92
+ if (changed.has("height")) {
93
+ this.style.setProperty("--height", `${this.height}px`);
94
+ }
95
+ }
96
+ disconnectedCallback() {
97
+ super.disconnectedCallback();
98
+ this.ro?.disconnect();
99
+ }
100
+ // Ajusta la resolución interna del canvas a devicePixelRatio (nitidez) y reaplica el fondo
101
+ // y los estilos de trazo. Si `preserve`, conserva la firma actual reescalándola.
102
+ setupCanvas(preserve = false) {
103
+ if (!this.canvas || !this.ctx) return;
104
+ const rect = this.canvas.getBoundingClientRect();
105
+ if (rect.width === 0 || rect.height === 0) return;
106
+ const dpr = window.devicePixelRatio || 1;
107
+ let snapshot = null;
108
+ if (preserve && this.canvas.width > 0 && this.canvas.height > 0) {
109
+ try {
110
+ snapshot = this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height);
111
+ } catch {
112
+ snapshot = null;
113
+ }
114
+ }
115
+ this.canvas.width = Math.round(rect.width * dpr);
116
+ this.canvas.height = Math.round(rect.height * dpr);
117
+ this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
118
+ this.paintBackground();
119
+ if (snapshot) {
120
+ this.ctx.save();
121
+ this.ctx.setTransform(1, 0, 0, 1, 0, 0);
122
+ this.ctx.putImageData(snapshot, 0, 0);
123
+ this.ctx.restore();
124
+ }
125
+ this.applyStroke();
126
+ }
127
+ // Pinta el fondo (si se definió un color); si no, queda transparente.
128
+ paintBackground() {
129
+ if (!this.ctx || !this.canvas) return;
130
+ const rect = this.canvas.getBoundingClientRect();
131
+ this.ctx.clearRect(0, 0, rect.width, rect.height);
132
+ if (this.background) {
133
+ this.ctx.fillStyle = this.background;
134
+ this.ctx.fillRect(0, 0, rect.width, rect.height);
135
+ }
136
+ }
137
+ // Configura el estilo del trazo (color, grosor, uniones redondeadas para suavizar).
138
+ applyStroke() {
139
+ if (!this.ctx) return;
140
+ this.ctx.lineWidth = this.lineWidth;
141
+ this.ctx.lineCap = "round";
142
+ this.ctx.lineJoin = "round";
143
+ this.ctx.strokeStyle = this.penColor || getComputedStyle(this).getPropertyValue("--color").trim() || "#1c1b17";
144
+ }
145
+ // Convierte el evento de puntero a coordenadas CSS relativas al canvas.
146
+ pos(e) {
147
+ const rect = this.canvas.getBoundingClientRect();
148
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top };
149
+ }
150
+ onPointerDown(e) {
151
+ if (!this.ctx) return;
152
+ e.preventDefault();
153
+ this.drawing = true;
154
+ this.applyStroke();
155
+ const { x, y } = this.pos(e);
156
+ this.lastX = x;
157
+ this.lastY = y;
158
+ this.ctx.beginPath();
159
+ this.ctx.moveTo(x, y);
160
+ this.ctx.lineTo(x + 0.01, y + 0.01);
161
+ this.ctx.stroke();
162
+ this.canvas.setPointerCapture?.(e.pointerId);
163
+ }
164
+ onPointerMove(e) {
165
+ if (!this.drawing || !this.ctx) return;
166
+ e.preventDefault();
167
+ const { x, y } = this.pos(e);
168
+ const midX = (this.lastX + x) / 2;
169
+ const midY = (this.lastY + y) / 2;
170
+ this.ctx.beginPath();
171
+ this.ctx.moveTo(this.lastX, this.lastY);
172
+ this.ctx.quadraticCurveTo(this.lastX, this.lastY, midX, midY);
173
+ this.ctx.stroke();
174
+ this.lastX = x;
175
+ this.lastY = y;
176
+ this.hasInk = true;
177
+ }
178
+ onPointerUp(e) {
179
+ if (!this.drawing) return;
180
+ this.drawing = false;
181
+ this.canvas.releasePointerCapture?.(e.pointerId);
182
+ this.dispatchEvent(
183
+ new CustomEvent("ok-change", {
184
+ detail: { empty: !this.hasInk },
185
+ bubbles: true,
186
+ composed: true
187
+ })
188
+ );
189
+ }
190
+ // ---- API pública --------------------------------------------------------
191
+ /** Limpia el lienzo y emite `ok-clear`. */
192
+ clear() {
193
+ this.hasInk = false;
194
+ this.paintBackground();
195
+ this.applyStroke();
196
+ this.dispatchEvent(new CustomEvent("ok-clear", { bubbles: true, composed: true }));
197
+ }
198
+ /** Devuelve la firma como data URL (def 'image/png'). */
199
+ toDataURL(type = "image/png") {
200
+ return this.canvas ? this.canvas.toDataURL(type) : "";
201
+ }
202
+ /** True si no se ha dibujado nada todavía. */
203
+ isEmpty() {
204
+ return !this.hasInk;
205
+ }
206
+ render() {
207
+ return html`
208
+ <div class="pad">
209
+ <canvas
210
+ @pointerdown=${this.onPointerDown}
211
+ @pointermove=${this.onPointerMove}
212
+ @pointerup=${this.onPointerUp}
213
+ @pointercancel=${this.onPointerUp}
214
+ @pointerleave=${this.onPointerUp}
215
+ ></canvas>
216
+ </div>
217
+ <div class="actions">
218
+ <ion-button fill="clear" size="small" @click=${() => this.clear()}>
219
+ <ion-icon slot="start" name="trash-outline"></ion-icon>
220
+ ${this.t.clear}
221
+ </ion-button>
222
+ ${this.showExport ? html`<ion-button
223
+ fill="solid"
224
+ size="small"
225
+ @click=${() => this.onExport()}
226
+ >
227
+ <ion-icon slot="start" name="download-outline"></ion-icon>
228
+ ${this.t.export}
229
+ </ion-button>` : ""}
230
+ </div>
231
+ `;
232
+ }
233
+ // Dispara la descarga de la firma como PNG (solo si hay tinta).
234
+ onExport() {
235
+ if (this.isEmpty()) return;
236
+ const url = this.toDataURL();
237
+ const a = document.createElement("a");
238
+ a.href = url;
239
+ a.download = this.t.exportFilename;
240
+ a.click();
241
+ }
242
+ }
243
+ __decorateClass([
244
+ property({ attribute: "pen-color" })
245
+ ], OkSignature.prototype, "penColor");
246
+ __decorateClass([
247
+ property({ type: Number, attribute: "line-width" })
248
+ ], OkSignature.prototype, "lineWidth");
249
+ __decorateClass([
250
+ property()
251
+ ], OkSignature.prototype, "background");
252
+ __decorateClass([
253
+ property({ type: Number })
254
+ ], OkSignature.prototype, "height");
255
+ __decorateClass([
256
+ property({ type: Boolean, attribute: "show-export" })
257
+ ], OkSignature.prototype, "showExport");
258
+ __decorateClass([
259
+ property({ attribute: false })
260
+ ], OkSignature.prototype, "labels");
261
+ __decorateClass([
262
+ query("canvas")
263
+ ], OkSignature.prototype, "canvas");
264
+ define("ok-signature", OkSignature);
265
+ export {
266
+ OkSignature
267
+ };