@mono-lit/helper 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/accordion-core-DaNyPWRr.js +277 -0
  2. package/dist/alert-core-DWtHbX_-.js +134 -0
  3. package/dist/breadcrumb-list-core-Dh68T8Cf.js +747 -0
  4. package/dist/{mono-button-CLkHg3WW.js → button-core-DerXg84Q.js} +3 -276
  5. package/dist/button-dropdown-core-DKYEOyjy.js +654 -0
  6. package/dist/button-utils-D5-66M02.js +63 -0
  7. package/dist/card-utils-l80qAmrN.js +312 -0
  8. package/dist/chart-core-DV7hD3ZY.js +801 -0
  9. package/dist/checkbox-utils-DKdrhAzF.js +337 -0
  10. package/dist/chip-utils-DpRrd7Zj.js +403 -0
  11. package/dist/{data-source-controller-C6C4ej_M.js → data-source-controller-DS_JLrmS.js} +1 -1
  12. package/dist/{data-source-options-fxT5QIX4.js → data-source-options-DJUNU26C.js} +6 -6
  13. package/dist/{data-source-read-BL266IW0.js → data-source-read-uKJpRAzx.js} +2 -2
  14. package/dist/date-core-CyuSyvvG.js +734 -0
  15. package/dist/drawer-core-DbFWvNln.js +759 -0
  16. package/dist/dropdown-core-BCH1pK14.js +511 -0
  17. package/dist/dropdown-table-core-SfHUJVFq.js +1342 -0
  18. package/dist/export.js +1 -1
  19. package/dist/{field-path-BabiMrrA.js → field-path-DK2VBWHl.js} +1 -1
  20. package/dist/field-tooltip.css_raw-DVblekCl.js +5 -0
  21. package/dist/{field-validation.css_raw-Cx6SGrfP.js → field-validation.css_raw-BU7C6173.js} +1 -170
  22. package/dist/file-upload-core-Cz_dBQMx.js +624 -0
  23. package/dist/filter-builder-core-DyWjbBP7.js +381 -0
  24. package/dist/{filter-builder-B6Y2mmbM.js → filter-builder-vbqIuPhX.js} +1 -1
  25. package/dist/{filter-eval-ChDSaAUH.js → filter-eval-CqeBnMYh.js} +1 -1
  26. package/dist/{filter-odata-Bi27XUpQ.js → filter-odata-GsczYKNC.js} +1 -1
  27. package/dist/{hydration-flush-BaE9gN3C.js → hydration-flush-Volt9X7Q.js} +2 -1071
  28. package/dist/index.js +11 -11
  29. package/dist/{index.node-DTqDBca7.js → index.node-Csy9zrr1.js} +4 -4
  30. package/dist/index.node.js +11 -11
  31. package/dist/input-utils-BglY-k0H.js +1145 -0
  32. package/dist/menu-core-DkAYuCZ2.js +831 -0
  33. package/dist/modal-core-CSBSPN_m.js +844 -0
  34. package/dist/mono-button-DVvZ03P-.js +280 -0
  35. package/dist/{mono-button.shadow-DqZMpcqY.js → mono-button.shadow-BANxMGln.js} +6 -594
  36. package/dist/{mono-data-chart-NKPdAgVq.js → mono-data-chart-ChF4J9RT.js} +6 -6
  37. package/dist/{mono-data-dropdown-B2iRpJuI.js → mono-data-dropdown-Bgj2PDfm.js} +1 -1
  38. package/dist/{mono-data-grid-llJCX9MC.js → mono-data-grid-DJkp96N-.js} +144 -46
  39. package/dist/{mono-event-BPku9HpS.js → mono-event-CAZf0F_k.js} +14 -9
  40. package/dist/{mono-form-controller-BrA10erm.js → mono-form-controller-DxZLvyg6.js} +2 -1
  41. package/dist/mono-table-checkbox-core-BKOMx8R5.js +5288 -0
  42. package/dist/nav-core-B5qU2dzn.js +225 -0
  43. package/dist/{normalize-error-D93O4q8g.js → normalize-error-BEcd1tmS.js} +2 -2
  44. package/dist/nuxt.js +1 -1
  45. package/dist/otp-core-DXg3vFLh.js +758 -0
  46. package/dist/radio-utils-Dk9Tl1jz.js +319 -0
  47. package/dist/rich-text-editor-core-Ddd_QaLn.js +1280 -0
  48. package/dist/select-utils-BgArYHk8.js +2140 -0
  49. package/dist/sidebar-core-CD6txDo3.js +583 -0
  50. package/dist/slider-core-vcWr321-.js +1014 -0
  51. package/dist/src/components/dropdown-table/dropdown-table-core.d.ts +2 -2
  52. package/dist/src/components/dropdown-table/dropdown-table-types.d.ts +1 -1
  53. package/dist/src/components/dropdown-table/index.d.ts +1 -1
  54. package/dist/src/components/dropdown-table/index.shadow.d.ts +1 -1
  55. package/dist/src/components/dropdown-table/mono-data-dropdown.d.ts +1 -1
  56. package/dist/src/components/form/form-types.d.ts +9 -3
  57. package/dist/src/components/input/input-core.d.ts +1 -1
  58. package/dist/src/components/input/input-types.d.ts +1 -1
  59. package/dist/src/components/otp/otp-core.d.ts +1 -1
  60. package/dist/src/components/select/select-core.d.ts +1 -1
  61. package/dist/src/components/select/select-types.d.ts +1 -1
  62. package/dist/src/components/slider/slider-core.d.ts +1 -1
  63. package/dist/src/components/slider/slider-types.d.ts +1 -1
  64. package/dist/src/components/table/filter-suggestion.d.ts +171 -0
  65. package/dist/src/components/table/index.d.ts +5 -4
  66. package/dist/src/components/table/index.shadow.d.ts +5 -4
  67. package/dist/src/components/table/mono-data-grid.d.ts +22 -3
  68. package/dist/src/components/table/mono-table-empty-core.d.ts +37 -0
  69. package/dist/src/components/table/mono-table-search-core.d.ts +22 -3
  70. package/dist/src/components/table/table-types.d.ts +74 -4
  71. package/dist/src/components/tag-input/tag-input-core.d.ts +1 -1
  72. package/dist/src/components/tag-input/tag-input-types.d.ts +1 -1
  73. package/dist/src/components/textarea/textarea-core.d.ts +1 -1
  74. package/dist/src/composables/mono-event.d.ts +7 -1
  75. package/dist/src/entries/index.d.ts +8 -6
  76. package/dist/src/entries/index.node.d.ts +8 -6
  77. package/dist/src/search/index.d.ts +1 -1
  78. package/dist/src/utils/group-count.d.ts +36 -0
  79. package/dist/switch-utils-CTZ4id2V.js +338 -0
  80. package/dist/tabs-core-r5-B8k_N.js +317 -0
  81. package/dist/tag-input-utils-D2JA90DQ.js +3060 -0
  82. package/dist/textarea-utils-VU1KeXm8.js +821 -0
  83. package/dist/ui/accordion.js +2 -274
  84. package/dist/ui/alert.js +2 -131
  85. package/dist/ui/breadcrumb.js +4 -745
  86. package/dist/ui/button-dropdown.js +4 -652
  87. package/dist/ui/button.js +2 -63
  88. package/dist/ui/card.js +2 -310
  89. package/dist/ui/chart.js +4 -800
  90. package/dist/ui/checkbox.js +4 -335
  91. package/dist/ui/chip.js +4 -402
  92. package/dist/ui/date.js +3 -732
  93. package/dist/ui/drawer.js +3 -757
  94. package/dist/ui/dropdown-table.js +5 -1341
  95. package/dist/ui/dropdown.js +4 -509
  96. package/dist/ui/file-upload.js +3 -622
  97. package/dist/ui/filter.js +5 -380
  98. package/dist/ui/form.js +1 -1
  99. package/dist/ui/index.css +118 -1
  100. package/dist/ui/input.js +3 -1141
  101. package/dist/ui/menu.js +4 -828
  102. package/dist/ui/modal.js +4 -843
  103. package/dist/ui/nav.js +4 -223
  104. package/dist/ui/otp.js +4 -756
  105. package/dist/ui/radio.js +4 -317
  106. package/dist/ui/rich-text-editor.js +4 -1278
  107. package/dist/ui/select.js +5 -2138
  108. package/dist/ui/shadow/accordion.js +4 -273
  109. package/dist/ui/shadow/alert.js +4 -130
  110. package/dist/ui/shadow/breadcrumb.js +5 -744
  111. package/dist/ui/shadow/button-dropdown.js +6 -652
  112. package/dist/ui/shadow/button.js +3 -63
  113. package/dist/ui/shadow/card.js +4 -309
  114. package/dist/ui/shadow/chart.js +6 -1576
  115. package/dist/ui/shadow/checkbox.js +4 -334
  116. package/dist/ui/shadow/chip.js +4 -396
  117. package/dist/ui/shadow/date.js +7 -731
  118. package/dist/ui/shadow/drawer.js +4 -756
  119. package/dist/ui/shadow/dropdown-table.js +8 -1762
  120. package/dist/ui/shadow/dropdown.js +4 -508
  121. package/dist/ui/shadow/file-upload.js +4 -620
  122. package/dist/ui/shadow/filter.js +7 -379
  123. package/dist/ui/shadow/input.js +6 -1140
  124. package/dist/ui/shadow/menu.js +5 -828
  125. package/dist/ui/shadow/modal.js +6 -1063
  126. package/dist/ui/shadow/nav.js +5 -223
  127. package/dist/ui/shadow/otp.js +6 -754
  128. package/dist/ui/shadow/radio.js +4 -316
  129. package/dist/ui/shadow/rich-text-editor.js +4 -1276
  130. package/dist/ui/shadow/select.js +6 -2136
  131. package/dist/ui/shadow/sidebar.js +5 -581
  132. package/dist/ui/shadow/slider.js +5 -1010
  133. package/dist/ui/shadow/switch.js +4 -335
  134. package/dist/ui/shadow/table.js +10 -4501
  135. package/dist/ui/shadow/tabs.js +6 -315
  136. package/dist/ui/shadow/tag-input.js +7 -3057
  137. package/dist/ui/shadow/textarea.js +6 -817
  138. package/dist/ui/sidebar.js +3 -581
  139. package/dist/ui/slider.js +4 -1012
  140. package/dist/ui/switch.js +4 -336
  141. package/dist/ui/table.js +9 -4502
  142. package/dist/ui/tabs.js +4 -315
  143. package/dist/ui/tag-input.js +5 -3058
  144. package/dist/ui/textarea.js +4 -819
  145. package/dist/{vite-CivRCJaf.js → vite-CfW7z2wn.js} +21 -14
  146. package/dist/vite.js +1 -1
  147. package/dist/vue.d.ts +3 -2
  148. package/package.json +10 -11
  149. package/dist/chip-strip-bNfLn52Z.js +0 -215
  150. package/dist/data-source-controller-Dx6IQ2CN.js +0 -243
  151. package/dist/data-source-options-BM4r4PRw.js +0 -558
  152. package/dist/data-source-read-HyBCRg1t.js +0 -242
  153. package/dist/excel-BXzr3uI1.js +0 -784
  154. package/dist/export-ixRdCS2y.js +0 -2388
  155. package/dist/field-tooltip-addon-CWCp19mJ.js +0 -702
  156. package/dist/field-tooltip.css_raw-U5UeTa2d.js +0 -269
  157. package/dist/filter-builder-C0T3pMx2.js +0 -208
  158. package/dist/form-control-core-BbiACMtL.js +0 -226
  159. package/dist/icon-ClxnYhBG.js +0 -19
  160. package/dist/import-Dc4eXC02.js +0 -612
  161. package/dist/light-slots-_no0r2Z-.js +0 -246
  162. package/dist/markdown-uGlE_OfJ.js +0 -20191
  163. package/dist/mono-data-grid-e9ZVBlNN.js +0 -4240
  164. package/dist/normalize-error-BmLbgANw.js +0 -1048
package/dist/ui/chart.js CHANGED
@@ -1,805 +1,9 @@
1
- import { a as errorTitle, i as errorText, n as describeError } from "../normalize-error-D93O4q8g.js";
2
- import { f as toCssSize, y as monoPendingGrace } from "../mono-ui-kvLVIf1V.js";
3
- import { n as detachEventHandlers, t as applyProps } from "../element-props-xvw0EB7H.js";
4
- import { i as composeApply, n as buildChartApply, r as buildChartOdataRequest, t as monoChart } from "../mono-data-chart-NKPdAgVq.js";
1
+ import { i as composeApply, n as buildChartApply, r as buildChartOdataRequest, t as monoChart } from "../mono-data-chart-ChF4J9RT.js";
5
2
  import { t as customElement } from "../mono-element-CKcT0rwv.js";
6
- import { a as defineHybridPropAliases, i as defineHybridPropAlias, o as numberStringConverter, r as booleanStringConverter, t as __decorate } from "../decorate-DbYFpi8R.js";
7
- import { t as dispatchMonoEvent } from "../mono-event-BPku9HpS.js";
8
- import { c as spinnerIcon, s as refreshIcon } from "../field-icons-t8rXRCKs.js";
9
- import { LitElement, html, isServer, nothing } from "lit";
10
- import { property, query, state } from "lit/decorators.js";
11
- import { styleMap } from "lit/directives/style-map.js";
3
+ import { t as __decorate } from "../decorate-DbYFpi8R.js";
4
+ import { n as loadChartJs, t as MonoChartCore } from "../chart-core-DV7hD3ZY.js";
5
+ import { LitElement } from "lit";
12
6
 
13
- //#region src/components/chart/chart-core.ts
14
- /**
15
- * The mono color names a chart accepts wherever a color is expected. They map to
16
- * the `--_mono-chart-<name>` resolvers in chart.css, which chain through the
17
- * public `--mono-chart-*` overrides to the Basecoat tokens — `chart-1` … `chart-5`
18
- * are Basecoat's own chart palette (`--chart-1` … `--chart-5`), the roles are the
19
- * page's. `surface` is internal: the hairline between slices.
20
- */
21
- const MONO_COLOR_NAMES = /* @__PURE__ */ new Set([
22
- "chart-1",
23
- "chart-2",
24
- "chart-3",
25
- "chart-4",
26
- "chart-5",
27
- "primary",
28
- "secondary",
29
- "accent",
30
- "success",
31
- "warning",
32
- "danger",
33
- "info",
34
- "surface"
35
- ]);
36
- /** Used before the element is in the DOM (SSR) or if a token resolves empty — ONE, light. */
37
- const MONO_COLOR_FALLBACK = {
38
- "chart-1": "oklch(0.859 0.069 267.7)",
39
- "chart-2": "oklch(0.735 0.12 268.04)",
40
- "chart-3": "oklch(0.61 0.12 267.95)",
41
- "chart-4": "oklch(0.485 0.119 267.92)",
42
- "chart-5": "oklch(0.36 0.12 268.21)",
43
- primary: "oklch(0.299 0.119 267.96)",
44
- secondary: "oklch(0.554 0.041 257.42)",
45
- accent: "oklch(0.735 0.12 268.04)",
46
- success: "oklch(0.5239 0.0917 180.004)",
47
- warning: "oklch(0.5423 0.1066 70.504)",
48
- danger: "oklch(0.561 0.202 26.71)",
49
- info: "oklch(0.431 0.163 267.72)",
50
- surface: "oklch(0.973 0.007 268.55)"
51
- };
52
- /** The tooltip lines come from the data (labels, formatted values) — never markup. */
53
- function escapeHtml(s) {
54
- return s.replace(/[&<>"']/g, (c) => ({
55
- "&": "&amp;",
56
- "<": "&lt;",
57
- ">": "&gt;",
58
- "\"": "&quot;",
59
- "'": "&#39;"
60
- })[c]);
61
- }
62
- /**
63
- * Cached loader for the OPTIONAL `chart.js` peer.
64
- *
65
- * `chart.js/auto` self-registers every controller/scale/element — the right
66
- * trade here because the library is externalized, so the consumer's bundler
67
- * owns the cost and tree-shaking on our side would buy nothing.
68
- */
69
- let _chartPromise = null;
70
- function loadChartJs() {
71
- _chartPromise ??= import("chart.js/auto").then((m) => m?.default ?? m).catch((err) => {
72
- _chartPromise = null;
73
- throw new Error("[mono-chart] needs the optional peer dependency \"chart.js\". Install it in your app: pnpm add chart.js@4.5.1" + (err?.message ? ` (original error: ${err.message})` : ""));
74
- });
75
- return _chartPromise;
76
- }
77
- /**
78
- * `MonoChartCore` — render-mode-agnostic logic for the chart elements.
79
- *
80
- * It owns the imperative Chart.js lifecycle, following the same shape as the
81
- * flatpickr wrapper in `date-core.ts`: create in `firstUpdated` behind an
82
- * `isServer` guard and a dynamic import, split `updated()` into a cheap data
83
- * update vs a full rebuild, and destroy in `disconnectedCallback` BEFORE
84
- * `super`. A `ResizeObserver` is added on top because, unlike flatpickr, a
85
- * canvas needs to be told when its box changes.
86
- */
87
- const MonoChartCore = (superClass) => {
88
- class MonoChartCoreClass extends superClass {
89
- constructor(...args) {
90
- super(...args);
91
- this.aspectRatio = 2;
92
- this.legend = true;
93
- this.title = "";
94
- this.stacked = false;
95
- this.cssClass = {};
96
- this.cssClassName = "";
97
- this.loadingText = "Loading…";
98
- this.retryLabel = "Retry";
99
- this.loading = false;
100
- this.loadingError = null;
101
- this._appFailure = null;
102
- this._error = "";
103
- this._chart = null;
104
- this._buildToken = 0;
105
- this._onThemeChanged = () => {
106
- if (isServer || !this._chart) return;
107
- requestAnimationFrame(() => {
108
- if (!this._chart) return;
109
- const palette = this._colors;
110
- if (palette?.length) this.dataChart?.setColors(palette);
111
- else this.dataChart?._setColorResolver((c) => this._resolveColor(c));
112
- this.rebuild();
113
- });
114
- };
115
- this._applyQueued = false;
116
- this._onRetry = (event) => {
117
- event.stopPropagation();
118
- const error = this._dsError;
119
- if (!error) return;
120
- const fromApp = !!this._appFailure;
121
- dispatchMonoEvent(this, "retry", {
122
- error,
123
- source: fromApp ? "app" : "dataSource"
124
- });
125
- if (!fromApp) this.dataChart?.retry();
126
- };
127
- this._externalTooltip = (context) => {
128
- const el = this._tooltipEl;
129
- if (!el) return;
130
- const tip = context.tooltip;
131
- if (!tip || tip.opacity === 0) {
132
- el.removeAttribute("data-open");
133
- el.setAttribute("aria-hidden", "true");
134
- return;
135
- }
136
- const title = tip.title ?? [];
137
- const bodies = (tip.body ?? []).map((b) => b.lines ?? []);
138
- const colors = tip.labelColors ?? [];
139
- const parts = [];
140
- for (const t of title) parts.push(`<div class="mono-chart-tooltip-title">${escapeHtml(String(t))}</div>`);
141
- bodies.forEach((lines, i) => {
142
- const swatch = colors[i]?.backgroundColor ?? colors[i]?.borderColor;
143
- for (const line of lines) {
144
- const m = /^(.*?):\s*(.+)$/.exec(String(line));
145
- const text = m ? `<span class="mono-chart-tooltip-label">${escapeHtml(m[1])}</span><span class="mono-chart-tooltip-value">${escapeHtml(m[2])}</span>` : `<span class="mono-chart-tooltip-label">${escapeHtml(String(line))}</span>`;
146
- parts.push(`<div class="mono-chart-tooltip-row">${swatch ? `<span class="mono-chart-tooltip-swatch" style="background:${escapeHtml(String(swatch))}"></span>` : ""}${text}</div>`);
147
- }
148
- });
149
- el.innerHTML = parts.join("");
150
- const width = el.parentElement?.clientWidth ?? context.chart.width;
151
- const gap = 8;
152
- el.setAttribute("data-open", "");
153
- el.setAttribute("aria-hidden", "false");
154
- const h = el.offsetHeight;
155
- const w = el.offsetWidth;
156
- const side = tip.caretY - h - gap < 0 ? "bottom" : "top";
157
- el.setAttribute("data-side", side);
158
- const x = Math.min(Math.max(tip.caretX, w / 2), Math.max(width - w / 2, w / 2));
159
- el.style.left = `${x}px`;
160
- el.style.top = `${tip.caretY}px`;
161
- };
162
- defineHybridPropAliases(this, [
163
- "dataChart",
164
- "chartOptions",
165
- "aspectRatio",
166
- "cssClass",
167
- "loadingText",
168
- "loadingError"
169
- ]);
170
- defineHybridPropAlias(this, "controlChart", "dataChart");
171
- for (const alias of ["css-class", "cssclass"]) Object.defineProperty(this, alias, {
172
- get: () => this.cssClass,
173
- set: (value) => this._setCssClass(value),
174
- configurable: true,
175
- enumerable: false
176
- });
177
- }
178
- static {
179
- this.monoPendingAuto = "data";
180
- }
181
- _monoPendingReady() {
182
- const ctrl = this.dataChart;
183
- if (!ctrl) return this.data != null || monoPendingGrace(this);
184
- if (ctrl.loading) return false;
185
- return monoPendingGrace(this) || ctrl.data().datasets.length > 0;
186
- }
187
- static {
188
- this._rebuildKeys = [
189
- "type",
190
- "chartOptions",
191
- "legend",
192
- "title",
193
- "stacked",
194
- "aspectRatio"
195
- ];
196
- }
197
- static get observedAttributes() {
198
- return [
199
- ...super.observedAttributes ?? [],
200
- "aspectratio",
201
- "chartoptions",
202
- "css-class",
203
- "cssclass",
204
- "colors"
205
- ];
206
- }
207
- attributeChangedCallback(name, old, value) {
208
- super.attributeChangedCallback(name, old, value);
209
- if (old === value) return;
210
- if (name === "css-class" || name === "cssclass") this._setCssClass(value);
211
- else if (name === "colors") this.colors = value ?? void 0;
212
- }
213
- _setCssClass(value) {
214
- if (value == null) {
215
- this.cssClass = {};
216
- this.cssClassName = "";
217
- return;
218
- }
219
- if (typeof value === "object") {
220
- this.cssClass = value;
221
- return;
222
- }
223
- const trimmed = String(value).trim();
224
- if (!trimmed) {
225
- this.cssClass = {};
226
- this.cssClassName = "";
227
- return;
228
- }
229
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) try {
230
- this.cssClass = JSON.parse(trimmed);
231
- return;
232
- } catch {}
233
- this.cssClassName = trimmed;
234
- }
235
- /** The live chart.js instance, or null before it mounts. */
236
- get chart() {
237
- return this._chart;
238
- }
239
- connectedCallback() {
240
- super.connectedCallback();
241
- this._subscribe();
242
- if (!isServer) {
243
- window.addEventListener("theme-changed", this._onThemeChanged);
244
- this._watchMode();
245
- }
246
- }
247
- disconnectedCallback() {
248
- this._off?.();
249
- this._off = void 0;
250
- if (!isServer) {
251
- window.removeEventListener("theme-changed", this._onThemeChanged);
252
- this._modeObserver?.disconnect();
253
- this._modeObserver = void 0;
254
- this._modeQuery?.removeEventListener("change", this._onThemeChanged);
255
- this._modeQuery = void 0;
256
- }
257
- this._destroyChart();
258
- super.disconnectedCallback();
259
- }
260
- /**
261
- * Dark mode is the same tokens flipped by the `.dark` class on `<html>` /
262
- * `<body>` (or the OS, under `color-scheme: system`) — and nothing fires
263
- * `theme-changed` for that: VitePress's appearance toggle and a consumer's
264
- * own switch just swap the class. Watch the class and the media query and
265
- * treat a flip exactly like a theme change.
266
- */
267
- _watchMode() {
268
- if (typeof MutationObserver === "undefined") return;
269
- let dark = document.documentElement.classList.contains("dark") || document.body?.classList.contains("dark");
270
- this._modeObserver = new MutationObserver(() => {
271
- const next = document.documentElement.classList.contains("dark") || document.body?.classList.contains("dark");
272
- if (next === dark) return;
273
- dark = next;
274
- this._onThemeChanged();
275
- });
276
- this._modeObserver.observe(document.documentElement, {
277
- attributes: true,
278
- attributeFilter: ["class"]
279
- });
280
- if (document.body) this._modeObserver.observe(document.body, {
281
- attributes: true,
282
- attributeFilter: ["class"]
283
- });
284
- this._modeQuery = window.matchMedia?.("(prefers-color-scheme: dark)");
285
- this._modeQuery?.addEventListener?.("change", this._onThemeChanged);
286
- }
287
- willUpdate(changed) {
288
- if (changed.has("loadingError")) {
289
- const v = this.loadingError;
290
- this._appFailure = v == null || v === false || v === "" ? null : describeError(v === true ? void 0 : v);
291
- }
292
- super.willUpdate?.(changed);
293
- if (changed.has("dataChart")) this._subscribe();
294
- }
295
- _subscribe() {
296
- this._off?.();
297
- detachEventHandlers(this);
298
- this._off = this.dataChart?.subscribe(() => {
299
- this._scheduleApplyProps();
300
- this.requestUpdate();
301
- });
302
- if (!isServer) this.dataChart?._setColorResolver((c) => this._resolveColor(c));
303
- this._scheduleApplyProps();
304
- }
305
- /**
306
- * Drive the apply from `update()` as well as `_subscribe()` — every render
307
- * reaches here, so a controller that arrives late (or a `setProps` between
308
- * subscriptions) can't be missed. Same arrangement as
309
- * `table-controller-core`, which documents why `_subscribe` alone is fragile.
310
- */
311
- update(changed) {
312
- this._scheduleApplyProps();
313
- super.update(changed);
314
- }
315
- /**
316
- * Deferred + de-duplicated: the apply writes reactive props, and doing that
317
- * inside the update cycle would trip Lit's change-in-update warning.
318
- */
319
- _scheduleApplyProps() {
320
- if (isServer) return;
321
- if (this._applyQueued) return;
322
- if (typeof queueMicrotask !== "function") {
323
- this._applyControllerProps();
324
- return;
325
- }
326
- this._applyQueued = true;
327
- queueMicrotask(() => {
328
- this._applyQueued = false;
329
- this._applyControllerProps();
330
- });
331
- }
332
- /**
333
- * Pull `controlMonoChart({ props })` onto this element, so the template needs
334
- * nothing but the controller binding.
335
- *
336
- * The CONTROLLER WINS for keys it declares (matching `controlMonoTable` and
337
- * `controlMonoForm`); keys it doesn't mention are left to whatever the
338
- * template set. `applyProps` supplies the skip-undefined, read-only and
339
- * equality guards. `?.props` is optional-called so a controller built before
340
- * this option existed simply contributes nothing.
341
- */
342
- _applyControllerProps() {
343
- applyProps(this, this.dataChart?.props?.());
344
- }
345
- /**
346
- * Effective type. A preset's locked type wins (a `<mono-chart-pie>` is a pie),
347
- * then an explicit element `type`, then the controller's, then `'bar'`.
348
- */
349
- get _type() {
350
- return this._presetType ?? this.type ?? this.dataChart?.type ?? "bar";
351
- }
352
- /** Effective data: the element's raw `data` wins, else the controller's. */
353
- get _data() {
354
- return this.data ?? this.dataChart?.data() ?? {
355
- labels: [],
356
- datasets: []
357
- };
358
- }
359
- get _loading() {
360
- return !!this.dataChart?.loading;
361
- }
362
- /** The FIRST load (or a retry) is in flight — nothing to show yet, so a spinner. */
363
- get _dsBusy() {
364
- if (this.loading) return true;
365
- const c = this.dataChart;
366
- return !this.data && !!c && c.loading && !c.hasLoaded && !c.error;
367
- }
368
- /** The app's `loading-error`, else the controller's failed load (the peer-load `_error` is separate). */
369
- get _dsError() {
370
- if (this.loading) return null;
371
- return this._appFailure ?? (this.data ? null : this.dataChart?.error ?? null);
372
- }
373
- /** Spinner over the first load; the failure + ↻ after one failed. */
374
- _renderSourceState() {
375
- const err = this._dsError;
376
- if (err) return html`
377
- <div class="mono-chart-state" mono-ds-state="error" role="alert">
378
- <span class="mono-chart-state-text" title=${errorTitle(err)}>${errorText(err)}</span>
379
- <button
380
- type="button"
381
- mono-ds-retry
382
- aria-label=${this.retryLabel}
383
- title=${this.retryLabel}
384
- @click=${this._onRetry}
385
- >
386
- ${refreshIcon()}
387
- </button>
388
- </div>
389
- `;
390
- if (this._dsBusy) return html`
391
- <div class="mono-chart-state" mono-ds-state="loading" role="status">
392
- <span mono-ds-spinner>${spinnerIcon()}</span>
393
- <span class="mono-chart-state-text">${this.loadingText}</span>
394
- </div>
395
- `;
396
- return nothing;
397
- }
398
- get _empty() {
399
- const d = this._data;
400
- return !d.datasets?.length || d.datasets.every((s) => !s.data?.length);
401
- }
402
- /** Palette from the `colors` prop, as an array. */
403
- /** The raw `colors` prop as a list, before name resolution. */
404
- get _colorList() {
405
- const c = this.colors;
406
- if (!c) return null;
407
- if (Array.isArray(c)) return c.filter(Boolean);
408
- return String(c).split(",").map((s) => s.trim()).filter(Boolean);
409
- }
410
- /**
411
- * The palette handed to Chart.js: the `colors` list if given, else the single
412
- * `color` accent, else null (the controller keeps its own default).
413
- * Mono color NAMES are resolved to real values here — see `_resolveColor`.
414
- */
415
- get _colors() {
416
- const list = this._colorList ?? (this.color ? [this.color] : null);
417
- if (!list?.length) return null;
418
- return list.map((c) => this._resolveColor(c));
419
- }
420
- /**
421
- * The element's own computed style scope.
422
- *
423
- * Read from the inner `.mono-chart` wrapper, not the host: in the shadow
424
- * build the custom properties are declared inside the shadow root, so the
425
- * host would return empty strings.
426
- */
427
- _styleScope() {
428
- if (isServer) return null;
429
- return this.renderRoot?.querySelector?.(".mono-chart") ?? this;
430
- }
431
- /**
432
- * Turn a mono color NAME into the value the canvas needs.
433
- *
434
- * Chart.js paints onto a bitmap and never resolves `var()`, so `success` (or
435
- * a literal `var(--x)`) would render as transparent. Names map to the
436
- * component's `--_mono-chart-*` resolvers, which chain through the public
437
- * `--mono-chart-*` overrides down to the Basecoat tokens — so a consumer
438
- * who re-themes the app gets re-themed charts for free. Anything that isn't
439
- * a known name (a hex, `rgb()`, `hsl()`) is passed through untouched.
440
- */
441
- _resolveColor(value) {
442
- const name = value.trim();
443
- if (!MONO_COLOR_NAMES.has(name)) return name;
444
- const scope = this._styleScope();
445
- if (!scope) return MONO_COLOR_FALLBACK[name] ?? name;
446
- const prop = name.startsWith("chart-") ? `--_mono-chart-${name.slice(6)}` : `--_mono-chart-${name}`;
447
- return getComputedStyle(scope).getPropertyValue(prop).trim() || MONO_COLOR_FALLBACK[name] || name;
448
- }
449
- /**
450
- * The inks and type Chart.js paints the chrome with — read off the element's
451
- * own box, where chart.css resolved them from the Basecoat tokens: legend
452
- * and title in `--foreground`, ticks in `--muted-foreground`, the grid in
453
- * `--border`, the tooltip as a popover, the page font at text-xs.
454
- */
455
- _themeColors() {
456
- const fallback = {
457
- text: "oklch(0.372 0.039 257.29)",
458
- muted: "oklch(0.554 0.041 257.42)",
459
- grid: "oklch(0.929 0.013 255.51)",
460
- tooltipBg: "oklch(1 0 0)",
461
- tooltipColor: "oklch(0.372 0.039 257.29)",
462
- tooltipBorder: "oklch(0.929 0.013 255.51)",
463
- fontFamily: "ui-sans-serif, system-ui, sans-serif",
464
- fontSize: 12,
465
- radius: 8,
466
- barRadius: 8
467
- };
468
- const scope = this._styleScope();
469
- if (!scope) return fallback;
470
- const cs = getComputedStyle(scope);
471
- const read = (name, fb) => cs.getPropertyValue(name).trim() || fb;
472
- const px = (v, fb, min = 1) => {
473
- const n = parseFloat(v);
474
- return Number.isFinite(n) && n >= min ? n : fb;
475
- };
476
- return {
477
- text: read("--_mono-chart-text", fallback.text),
478
- muted: read("--_mono-chart-muted", fallback.muted),
479
- grid: read("--_mono-chart-grid", fallback.grid),
480
- tooltipBg: read("--_mono-chart-tooltip-bg", fallback.tooltipBg),
481
- tooltipColor: read("--_mono-chart-tooltip-color", fallback.tooltipColor),
482
- tooltipBorder: read("--_mono-chart-tooltip-border", fallback.tooltipBorder),
483
- fontFamily: cs.fontFamily || fallback.fontFamily,
484
- fontSize: px(cs.fontSize, fallback.fontSize),
485
- radius: px(cs.borderTopLeftRadius, fallback.radius, 0),
486
- barRadius: px(getComputedStyle(this.renderRoot?.querySelector?.(".mono-chart-canvas-wrap") ?? scope).borderTopLeftRadius, fallback.barRadius, 0)
487
- };
488
- }
489
- /** Merge the element's presentational props with the consumer's raw options. */
490
- _buildOptions() {
491
- const theme = this._themeColors();
492
- const legendOn = this.legend !== false && this.legend !== "false";
493
- const legendPos = typeof this.legend === "string" && this.legend !== "true" ? this.legend : "top";
494
- const scaled = this._type !== "pie" && this._type !== "doughnut" && this._type !== "polarArea";
495
- const base = {
496
- responsive: true,
497
- maintainAspectRatio: !this.height,
498
- aspectRatio: this.aspectRatio,
499
- font: {
500
- family: theme.fontFamily,
501
- size: theme.fontSize
502
- },
503
- color: theme.text,
504
- plugins: {
505
- legend: {
506
- display: legendOn,
507
- position: legendPos,
508
- labels: {
509
- color: theme.text,
510
- font: {
511
- family: theme.fontFamily,
512
- size: theme.fontSize
513
- },
514
- boxWidth: theme.fontSize,
515
- boxHeight: theme.fontSize,
516
- useBorderRadius: true,
517
- borderRadius: Math.round(theme.fontSize / 4)
518
- }
519
- },
520
- title: this.title ? {
521
- display: true,
522
- text: this.title,
523
- color: theme.text,
524
- font: {
525
- family: theme.fontFamily,
526
- size: theme.fontSize + 2,
527
- weight: 500
528
- }
529
- } : { display: false },
530
- tooltip: {
531
- enabled: false,
532
- external: this._externalTooltip,
533
- backgroundColor: theme.tooltipBg,
534
- titleColor: theme.tooltipColor,
535
- bodyColor: theme.tooltipColor,
536
- borderColor: theme.tooltipBorder,
537
- borderWidth: 1,
538
- cornerRadius: theme.radius,
539
- padding: {
540
- x: 12,
541
- y: 6
542
- },
543
- titleFont: {
544
- family: theme.fontFamily,
545
- size: theme.fontSize,
546
- weight: 500
547
- },
548
- bodyFont: {
549
- family: theme.fontFamily,
550
- size: theme.fontSize
551
- },
552
- boxPadding: 4,
553
- usePointStyle: true
554
- }
555
- },
556
- onClick: (_e, els) => {
557
- const hit = els?.[0];
558
- if (!hit) return;
559
- this.dataChart?._emitPoint?.(hit.datasetIndex, hit.index);
560
- }
561
- };
562
- if (scaled) {
563
- base.elements = { bar: { borderRadius: theme.barRadius } };
564
- base.interaction = {
565
- mode: "index",
566
- intersect: false
567
- };
568
- base.scales = {
569
- x: {
570
- stacked: this.stacked,
571
- ticks: {
572
- color: theme.muted,
573
- font: {
574
- family: theme.fontFamily,
575
- size: theme.fontSize
576
- }
577
- },
578
- grid: { color: theme.grid },
579
- border: { color: theme.grid }
580
- },
581
- y: {
582
- stacked: this.stacked,
583
- ticks: {
584
- color: theme.muted,
585
- font: {
586
- family: theme.fontFamily,
587
- size: theme.fontSize
588
- }
589
- },
590
- grid: { color: theme.grid },
591
- border: { color: theme.grid }
592
- }
593
- };
594
- }
595
- return deepMerge(deepMerge(base, this.dataChart?.options() ?? {}), this.chartOptions ?? {});
596
- }
597
- async firstUpdated(changed) {
598
- super.firstUpdated?.(changed);
599
- if (isServer) return;
600
- this.dataChart?._setColorResolver((c) => this._resolveColor(c));
601
- const palette = this._colors;
602
- if (palette?.length) this.dataChart?.setColors(palette);
603
- this._syncTypeToController();
604
- await this._createChart();
605
- }
606
- updated(changed) {
607
- super.updated?.(changed);
608
- if (isServer) return;
609
- if (changed.has("colors") || changed.has("color")) {
610
- const palette = this._colors;
611
- if (palette?.length) this.dataChart?.setColors(palette);
612
- }
613
- this._syncTypeToController();
614
- if (!this._chart) {
615
- if (!this._error && !this._empty) this._createChart();
616
- return;
617
- }
618
- if (MonoChartCoreClass._rebuildKeys.some((k) => changed.has(k))) {
619
- this.rebuild();
620
- return;
621
- }
622
- if (this._chart.config?.type !== this._type) {
623
- this.rebuild();
624
- return;
625
- }
626
- this._applyData();
627
- }
628
- /**
629
- * Tell the controller which type actually won.
630
- *
631
- * The projection depends on it: pie-family charts colour every SLICE, bar
632
- * and line colour each DATASET. A preset (`<mono-chart-pie>`) fixes its type
633
- * on the element, so without this the controller would still think it was
634
- * projecting for the default `bar` and every slice would come out the same
635
- * colour. `setType` early-returns when unchanged, so this settles in one
636
- * extra update rather than looping.
637
- *
638
- * NOTE: the type is controller state, so pointing a bar element and a pie
639
- * element at ONE shared controller makes them fight — give each its own.
640
- */
641
- _syncTypeToController() {
642
- const grid = this.dataChart;
643
- if (grid && grid.type !== this._type) grid.setType(this._type);
644
- }
645
- async _createChart() {
646
- if (isServer || this._chart) return;
647
- if (!this._canvas) return;
648
- const token = ++this._buildToken;
649
- let Chart;
650
- try {
651
- Chart = await loadChartJs();
652
- } catch (err) {
653
- this._error = err?.message ?? String(err);
654
- return;
655
- }
656
- if (token !== this._buildToken || !this.isConnected || !this._canvas) return;
657
- try {
658
- this._chart = new Chart(this._canvas, {
659
- type: this._type,
660
- data: this._cloneData(),
661
- options: this._buildOptions()
662
- });
663
- this._error = "";
664
- this.dataChart?._attachInstance(this._chart);
665
- this._observeResize();
666
- } catch (err) {
667
- this._error = err?.message ?? String(err);
668
- }
669
- }
670
- /**
671
- * Hand chart.js its own copy. It mutates `data` in place (adding computed
672
- * metadata), so sharing the controller's projected object would corrupt it.
673
- */
674
- _cloneData() {
675
- const d = this._data;
676
- return {
677
- labels: [...d.labels ?? []],
678
- datasets: (d.datasets ?? []).map((s) => ({
679
- ...s,
680
- data: [...s.data ?? []]
681
- }))
682
- };
683
- }
684
- _applyData() {
685
- if (!this._chart) return;
686
- const next = this._cloneData();
687
- this._chart.data.labels = next.labels;
688
- this._chart.data.datasets = next.datasets;
689
- this._chart.update();
690
- }
691
- /** Destroy + recreate. Needed for `type` and structural option changes. */
692
- rebuild() {
693
- if (isServer) return;
694
- this._destroyChart();
695
- this._createChart();
696
- }
697
- _destroyChart() {
698
- this._buildToken++;
699
- this._ro?.disconnect();
700
- this._ro = void 0;
701
- try {
702
- this._chart?.destroy();
703
- } catch {}
704
- this._chart = null;
705
- this.dataChart?._attachInstance(null);
706
- this._tooltipEl?.removeAttribute("data-open");
707
- }
708
- /**
709
- * Chart.js `responsive` already listens for window resizes, but not for a
710
- * container that changes size on its own (a sidebar opening, a flex reflow).
711
- */
712
- _observeResize() {
713
- if (this._ro || typeof ResizeObserver === "undefined") return;
714
- const wrap = this.renderRoot?.querySelector?.(".mono-chart-canvas-wrap");
715
- if (!wrap) return;
716
- this._ro = new ResizeObserver(() => this._chart?.resize());
717
- this._ro.observe(wrap);
718
- }
719
- _cls(base, key) {
720
- const extra = this.cssClass?.[key];
721
- return extra ? `${base} ${extra}` : base;
722
- }
723
- get _rootClasses() {
724
- return [
725
- "mono-chart",
726
- this._loading ? "loading" : "",
727
- this.cssClassName,
728
- this.cssClass?.root
729
- ].filter(Boolean).join(" ");
730
- }
731
- _wrapStyle() {
732
- const s = {};
733
- const w = toCssSize(this.width);
734
- const h = toCssSize(this.height);
735
- if (w) s.width = w;
736
- if (h) s.height = h;
737
- return s;
738
- }
739
- renderChart() {
740
- return html`
741
- <div
742
- class=${this._rootClasses}
743
- ?mono-ds-loading=${this._dsBusy}
744
- ?mono-ds-error=${!!this._dsError}
745
- aria-busy=${this._dsBusy ? "true" : nothing}
746
- >
747
- ${this._error ? html`<div class=${this._cls("mono-chart-message error", "message")} role="alert">
748
- ${this._error}
749
- </div>` : nothing}
750
- <div class="mono-chart-canvas-wrap" style=${styleMap(this._wrapStyle())}>
751
- <canvas class=${this._cls("", "canvas")} role="img"></canvas>
752
- <div class="mono-chart-tooltip" role="tooltip" aria-hidden="true"></div>
753
- ${this._renderSourceState()}
754
- </div>
755
- </div>
756
- `;
757
- }
758
- }
759
- __decorate([property({ attribute: false })], MonoChartCoreClass.prototype, "dataChart", void 0);
760
- __decorate([property({ type: String })], MonoChartCoreClass.prototype, "type", void 0);
761
- __decorate([property({ attribute: false })], MonoChartCoreClass.prototype, "data", void 0);
762
- __decorate([property({ attribute: false })], MonoChartCoreClass.prototype, "chartOptions", void 0);
763
- __decorate([property({ type: String })], MonoChartCoreClass.prototype, "width", void 0);
764
- __decorate([property({ type: String })], MonoChartCoreClass.prototype, "height", void 0);
765
- __decorate([property({
766
- attribute: "aspect-ratio",
767
- converter: numberStringConverter
768
- })], MonoChartCoreClass.prototype, "aspectRatio", void 0);
769
- __decorate([property()], MonoChartCoreClass.prototype, "legend", void 0);
770
- __decorate([property({ type: String })], MonoChartCoreClass.prototype, "title", void 0);
771
- __decorate([property({ converter: booleanStringConverter })], MonoChartCoreClass.prototype, "stacked", void 0);
772
- __decorate([property({ type: String })], MonoChartCoreClass.prototype, "color", void 0);
773
- __decorate([property({ attribute: false })], MonoChartCoreClass.prototype, "colors", void 0);
774
- __decorate([property({ attribute: false })], MonoChartCoreClass.prototype, "cssClass", void 0);
775
- __decorate([property({ attribute: false })], MonoChartCoreClass.prototype, "cssClassName", void 0);
776
- __decorate([property({
777
- type: String,
778
- attribute: "loading-text"
779
- })], MonoChartCoreClass.prototype, "loadingText", void 0);
780
- __decorate([property({
781
- type: String,
782
- attribute: "retry-label"
783
- })], MonoChartCoreClass.prototype, "retryLabel", void 0);
784
- __decorate([property({ converter: booleanStringConverter })], MonoChartCoreClass.prototype, "loading", void 0);
785
- __decorate([property({ attribute: "loading-error" })], MonoChartCoreClass.prototype, "loadingError", void 0);
786
- __decorate([state()], MonoChartCoreClass.prototype, "_error", void 0);
787
- __decorate([query("canvas")], MonoChartCoreClass.prototype, "_canvas", void 0);
788
- __decorate([query(".mono-chart-tooltip")], MonoChartCoreClass.prototype, "_tooltipEl", void 0);
789
- return MonoChartCoreClass;
790
- };
791
- /** Shallow-recursive merge; arrays and non-plain values are replaced wholesale. */
792
- function deepMerge(base, over) {
793
- const out = { ...base };
794
- for (const [k, v] of Object.entries(over)) {
795
- const prev = out[k];
796
- if (v && typeof v === "object" && !Array.isArray(v) && prev && typeof prev === "object" && !Array.isArray(prev)) out[k] = deepMerge(prev, v);
797
- else out[k] = v;
798
- }
799
- return out;
800
- }
801
-
802
- //#endregion
803
7
  //#region src/components/chart/mono-chart.ts
804
8
  let MonoChart = class MonoChart extends MonoChartCore(LitElement) {
805
9
  createRenderRoot() {