@maliardic/ma-ui 0.0.0-stage → 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 (56) hide show
  1. package/FONT_AWESOME_LICENSE.txt +165 -0
  2. package/LICENSE +21 -0
  3. package/README.md +77 -2
  4. package/fesm2022/maliardic-ma-ui-chart.mjs +261 -0
  5. package/fesm2022/maliardic-ma-ui-chart.mjs.map +1 -0
  6. package/fesm2022/maliardic-ma-ui-editor.mjs +457 -0
  7. package/fesm2022/maliardic-ma-ui-editor.mjs.map +1 -0
  8. package/fesm2022/maliardic-ma-ui.mjs +13466 -0
  9. package/fesm2022/maliardic-ma-ui.mjs.map +1 -0
  10. package/package.json +76 -3
  11. package/styles/components/_accordion.scss +172 -0
  12. package/styles/components/_badge.scss +160 -0
  13. package/styles/components/_button.scss +123 -0
  14. package/styles/components/_chart.scss +12 -0
  15. package/styles/components/_checkbox.scss +88 -0
  16. package/styles/components/_command-menu.scss +49 -0
  17. package/styles/components/_date-picker.scss +247 -0
  18. package/styles/components/_dialog.scss +144 -0
  19. package/styles/components/_drawer.scss +165 -0
  20. package/styles/components/_editor.scss +260 -0
  21. package/styles/components/_file-list.scss +59 -0
  22. package/styles/components/_file-upload.scss +141 -0
  23. package/styles/components/_input-number.scss +18 -0
  24. package/styles/components/_input.scss +197 -0
  25. package/styles/components/_listbox.scss +88 -0
  26. package/styles/components/_menu-search.scss +72 -0
  27. package/styles/components/_menu.scss +177 -0
  28. package/styles/components/_multi-select.scss +216 -0
  29. package/styles/components/_popover.scss +63 -0
  30. package/styles/components/_progress-bar.scss +123 -0
  31. package/styles/components/_progress-spinner.scss +108 -0
  32. package/styles/components/_radio.scss +79 -0
  33. package/styles/components/_select.scss +320 -0
  34. package/styles/components/_switch.scss +63 -0
  35. package/styles/components/_table.scss +599 -0
  36. package/styles/components/_tabs.scss +130 -0
  37. package/styles/components/_textarea.scss +4 -0
  38. package/styles/components/_tiered-menu.scss +96 -0
  39. package/styles/components/_toast.scss +155 -0
  40. package/styles/components/_tooltip.scss +63 -0
  41. package/styles/components.scss +30 -0
  42. package/styles/core.scss +46 -0
  43. package/styles/index.scss +5 -0
  44. package/styles/ma-ui.css +5 -0
  45. package/styles/tokens.scss +368 -0
  46. package/types/maliardic-ma-ui-chart.d.ts +44 -0
  47. package/types/maliardic-ma-ui-editor.d.ts +130 -0
  48. package/types/maliardic-ma-ui.d.ts +3553 -0
  49. package/webfonts/fa-brands-400.ttf +0 -0
  50. package/webfonts/fa-brands-400.woff2 +0 -0
  51. package/webfonts/fa-regular-400.ttf +0 -0
  52. package/webfonts/fa-regular-400.woff2 +0 -0
  53. package/webfonts/fa-solid-900.ttf +0 -0
  54. package/webfonts/fa-solid-900.woff2 +0 -0
  55. package/webfonts/fa-v4compatibility.ttf +0 -0
  56. package/webfonts/fa-v4compatibility.woff2 +0 -0
@@ -0,0 +1,165 @@
1
+ Fonticons, Inc. (https://fontawesome.com)
2
+
3
+ --------------------------------------------------------------------------------
4
+
5
+ Font Awesome Free License
6
+
7
+ Font Awesome Free is free, open source, and GPL friendly. You can use it for
8
+ commercial projects, open source projects, or really almost whatever you want.
9
+ Full Font Awesome Free license: https://fontawesome.com/license/free.
10
+
11
+ --------------------------------------------------------------------------------
12
+
13
+ # Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
14
+
15
+ The Font Awesome Free download is licensed under a Creative Commons
16
+ Attribution 4.0 International License and applies to all icons packaged
17
+ as SVG and JS file types.
18
+
19
+ --------------------------------------------------------------------------------
20
+
21
+ # Fonts: SIL OFL 1.1 License
22
+
23
+ In the Font Awesome Free download, the SIL OFL license applies to all icons
24
+ packaged as web and desktop font files.
25
+
26
+ Copyright (c) 2024 Fonticons, Inc. (https://fontawesome.com)
27
+ with Reserved Font Name: "Font Awesome".
28
+
29
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
30
+ This license is copied below, and is also available with a FAQ at:
31
+ http://scripts.sil.org/OFL
32
+
33
+ SIL OPEN FONT LICENSE
34
+ Version 1.1 - 26 February 2007
35
+
36
+ PREAMBLE
37
+ The goals of the Open Font License (OFL) are to stimulate worldwide
38
+ development of collaborative font projects, to support the font creation
39
+ efforts of academic and linguistic communities, and to provide a free and
40
+ open framework in which fonts may be shared and improved in partnership
41
+ with others.
42
+
43
+ The OFL allows the licensed fonts to be used, studied, modified and
44
+ redistributed freely as long as they are not sold by themselves. The
45
+ fonts, including any derivative works, can be bundled, embedded,
46
+ redistributed and/or sold with any software provided that any reserved
47
+ names are not used by derivative works. The fonts and derivatives,
48
+ however, cannot be released under any other type of license. The
49
+ requirement for fonts to remain under this license does not apply
50
+ to any document created using the fonts or their derivatives.
51
+
52
+ DEFINITIONS
53
+ "Font Software" refers to the set of files released by the Copyright
54
+ Holder(s) under this license and clearly marked as such. This may
55
+ include source files, build scripts and documentation.
56
+
57
+ "Reserved Font Name" refers to any names specified as such after the
58
+ copyright statement(s).
59
+
60
+ "Original Version" refers to the collection of Font Software components as
61
+ distributed by the Copyright Holder(s).
62
+
63
+ "Modified Version" refers to any derivative made by adding to, deleting,
64
+ or substituting — in part or in whole — any of the components of the
65
+ Original Version, by changing formats or by porting the Font Software to a
66
+ new environment.
67
+
68
+ "Author" refers to any designer, engineer, programmer, technical
69
+ writer or other person who contributed to the Font Software.
70
+
71
+ PERMISSION & CONDITIONS
72
+ Permission is hereby granted, free of charge, to any person obtaining
73
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
74
+ redistribute, and sell modified and unmodified copies of the Font
75
+ Software, subject to the following conditions:
76
+
77
+ 1) Neither the Font Software nor any of its individual components,
78
+ in Original or Modified Versions, may be sold by itself.
79
+
80
+ 2) Original or Modified Versions of the Font Software may be bundled,
81
+ redistributed and/or sold with any software, provided that each copy
82
+ contains the above copyright notice and this license. These can be
83
+ included either as stand-alone text files, human-readable headers or
84
+ in the appropriate machine-readable metadata fields within text or
85
+ binary files as long as those fields can be easily viewed by the user.
86
+
87
+ 3) No Modified Version of the Font Software may use the Reserved Font
88
+ Name(s) unless explicit written permission is granted by the corresponding
89
+ Copyright Holder. This restriction only applies to the primary font name as
90
+ presented to the users.
91
+
92
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
93
+ Software shall not be used to promote, endorse or advertise any
94
+ Modified Version, except to acknowledge the contribution(s) of the
95
+ Copyright Holder(s) and the Author(s) or with their explicit written
96
+ permission.
97
+
98
+ 5) The Font Software, modified or unmodified, in part or in whole,
99
+ must be distributed entirely under this license, and must not be
100
+ distributed under any other license. The requirement for fonts to
101
+ remain under this license does not apply to any document created
102
+ using the Font Software.
103
+
104
+ TERMINATION
105
+ This license becomes null and void if any of the above conditions are
106
+ not met.
107
+
108
+ DISCLAIMER
109
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
110
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
111
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
112
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
113
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
114
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
115
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
116
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
117
+ OTHER DEALINGS IN THE FONT SOFTWARE.
118
+
119
+ --------------------------------------------------------------------------------
120
+
121
+ # Code: MIT License (https://opensource.org/licenses/MIT)
122
+
123
+ In the Font Awesome Free download, the MIT license applies to all non-font and
124
+ non-icon files.
125
+
126
+ Copyright 2024 Fonticons, Inc.
127
+
128
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
129
+ this software and associated documentation files (the "Software"), to deal in the
130
+ Software without restriction, including without limitation the rights to use, copy,
131
+ modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
132
+ and to permit persons to whom the Software is furnished to do so, subject to the
133
+ following conditions:
134
+
135
+ The above copyright notice and this permission notice shall be included in all
136
+ copies or substantial portions of the Software.
137
+
138
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
139
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
140
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
141
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
142
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
143
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
144
+
145
+ --------------------------------------------------------------------------------
146
+
147
+ # Attribution
148
+
149
+ Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
150
+ Awesome Free files already contain embedded comments with sufficient
151
+ attribution, so you shouldn't need to do anything additional when using these
152
+ files normally.
153
+
154
+ We've kept attribution comments terse, so we ask that you do not actively work
155
+ to remove them from files, especially code. They're a great way for folks to
156
+ learn about Font Awesome.
157
+
158
+ --------------------------------------------------------------------------------
159
+
160
+ # Brand Icons
161
+
162
+ All brand icons are trademarks of their respective owners. The use of these
163
+ trademarks does not indicate endorsement of the trademark holder by Font
164
+ Awesome, nor vice versa. **Please do not use brand logos for any purpose except
165
+ to represent the company, product, or service to which they refer.**
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 maliardic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,78 @@
1
- # Temporary Holding Version
1
+ # @maliardic/ma-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Standalone Angular UI components, directives and CSS variable themes.
4
+
5
+ ## Install
6
+
7
+ Requires Angular 22.2 and Angular CDK 22.1 or later within major version 22.
8
+
9
+ ```sh
10
+ npm install @maliardic/ma-ui
11
+ ```
12
+
13
+ Import the theme once in the application's global stylesheet:
14
+
15
+ ```scss
16
+ @use '@maliardic/ma-ui/styles';
17
+ ```
18
+
19
+ Font Awesome is installed automatically as a dependency. On npm 7+, compatible
20
+ missing peer dependencies such as Angular CDK are installed automatically too.
21
+ Existing incompatible Angular/CDK versions must be updated in the application;
22
+ installing this package does not upgrade them automatically.
23
+
24
+ The theme includes Font Awesome icons/fonts and the structural Angular CDK overlay
25
+ styles. Tailwind and a separate Font Awesome CSS import are not required.
26
+ For applications without Sass, add `@maliardic/ma-ui/styles/ma-ui.css` to the
27
+ application's global styles configuration instead.
28
+
29
+ ## Table example
30
+
31
+ ```ts
32
+ import { Component } from '@angular/core';
33
+ import { MTable } from '@maliardic/ma-ui';
34
+
35
+ @Component({
36
+ selector: 'app-example',
37
+ imports: [MTable],
38
+ template: `<m-table [value]="users" [columns]="columns"
39
+ [pageSize]="10" [rowsPerPageOptions]="[10, 20, 50]" />`,
40
+ })
41
+ export class Example {
42
+ readonly users = [{ id: 1, name: 'Ada' }];
43
+ readonly columns = [{ field: 'name', header: 'Name', sortable: true }];
44
+ }
45
+ ```
46
+
47
+ `[(pageSize)]` is supported when the application needs to track the user's choice.
48
+
49
+ ## Optional chart and editor
50
+
51
+ These have separate entry points and optional peer dependencies. Applications using
52
+ only the main entry point do not need Chart.js or Tiptap.
53
+
54
+ ```sh
55
+ npm install chart.js@^4.5.1
56
+ ```
57
+
58
+ ```ts
59
+ import { MChart } from '@maliardic/ma-ui/chart';
60
+ ```
61
+
62
+ ```sh
63
+ npm install @tiptap/core@^3.30.0 @tiptap/pm@^3.30.0 @tiptap/starter-kit@^3.30.0 @tiptap/extension-link@^3.30.0 @tiptap/extension-placeholder@^3.30.0
64
+ ```
65
+
66
+ ```ts
67
+ import { MEditor } from '@maliardic/ma-ui/editor';
68
+ ```
69
+
70
+ ## Themes
71
+
72
+ Use `.m-light` or `.m-dark` on a container and override the `--m-*` CSS variables.
73
+ Overlay components inherit theme settings from their host. Keep custom theme
74
+ overrides after the library stylesheet.
75
+
76
+ ## License
77
+
78
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,261 @@
1
+ import * as i0 from "@angular/core";
2
+ import { Component, ElementRef, afterNextRender, effect, inject, input, signal, viewChild } from "@angular/core";
3
+ function copy(value) {
4
+ if (Array.isArray(value)) return value.map(copy);
5
+ if (value && Object.getPrototypeOf(value) === Object.prototype) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, copy(item)]));
6
+ return value;
7
+ }
8
+ function merge(base, overrides) {
9
+ const result = copy(base);
10
+ for (const [key, value] of Object.entries(overrides)) {
11
+ if (value === void 0) continue;
12
+ result[key] = value && Object.getPrototypeOf(value) === Object.prototype ? merge(result[key] && typeof result[key] === "object" ? result[key] : {}, value) : copy(value);
13
+ }
14
+ return result;
15
+ }
16
+ var MChart = class MChart {
17
+ type = input("bar", ...ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []);
18
+ data = input.required(...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
19
+ options = input({}, ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
20
+ ariaLabel = input("Chart", ...ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
21
+ failed = signal(false, ...ngDevMode ? [{ debugName: "failed" }] : /* istanbul ignore next */ []);
22
+ host = inject(ElementRef);
23
+ canvas = viewChild.required("canvas", ...ngDevMode ? [{ debugName: "canvas" }] : /* istanbul ignore next */ []);
24
+ constructorRef = signal(null, ...ngDevMode ? [{ debugName: "constructorRef" }] : /* istanbul ignore next */ []);
25
+ chart;
26
+ chartType;
27
+ observer;
28
+ destroyed = false;
29
+ constructor() {
30
+ afterNextRender(() => {
31
+ import("chart.js/auto").then(({ default: ChartConstructor }) => {
32
+ if (this.destroyed) return;
33
+ this.constructorRef.set(ChartConstructor);
34
+ this.observer = new MutationObserver(() => this.refreshTheme());
35
+ for (let node = this.host.nativeElement; node; node = node.parentElement) this.observer.observe(node, {
36
+ attributes: true,
37
+ attributeFilter: ["class", "style"]
38
+ });
39
+ }).catch(() => {
40
+ if (!this.destroyed) this.failed.set(true);
41
+ });
42
+ });
43
+ effect(() => {
44
+ const ChartConstructor = this.constructorRef();
45
+ if (!ChartConstructor) return;
46
+ const type = this.type();
47
+ const data = copy(this.data());
48
+ const options = this.themedOptions();
49
+ if (this.chart && this.chartType === type) {
50
+ this.chart.data = data;
51
+ this.chart.options = options;
52
+ this.chart.update();
53
+ } else {
54
+ this.chart?.destroy();
55
+ this.chartType = type;
56
+ this.chart = new ChartConstructor(this.canvas().nativeElement, {
57
+ type,
58
+ data,
59
+ options
60
+ });
61
+ }
62
+ });
63
+ }
64
+ themedOptions() {
65
+ const style = getComputedStyle(this.host.nativeElement);
66
+ const color = style.getPropertyValue("--m-color-text").trim() || style.color;
67
+ const gridColor = style.getPropertyValue("--m-color-border").trim();
68
+ const font = {
69
+ family: style.fontFamily,
70
+ size: parseFloat(style.fontSize)
71
+ };
72
+ const axis = {
73
+ ticks: {
74
+ color,
75
+ font
76
+ },
77
+ grid: { color: gridColor },
78
+ border: { color: gridColor },
79
+ title: {
80
+ color,
81
+ font
82
+ }
83
+ };
84
+ const type = this.type();
85
+ const scales = {};
86
+ if (type === "radar" || type === "polarArea") scales["r"] = {
87
+ ...axis,
88
+ angleLines: { color: gridColor },
89
+ pointLabels: {
90
+ color,
91
+ font
92
+ }
93
+ };
94
+ else if (type !== "pie" && type !== "doughnut") {
95
+ scales["x"] = axis;
96
+ scales["y"] = axis;
97
+ }
98
+ for (const key of Object.keys(this.options().scales ?? {})) scales[key] ??= axis;
99
+ return merge({
100
+ responsive: true,
101
+ maintainAspectRatio: false,
102
+ color,
103
+ font,
104
+ scales,
105
+ plugins: {
106
+ legend: { labels: {
107
+ color,
108
+ font
109
+ } },
110
+ title: {
111
+ color,
112
+ font
113
+ },
114
+ subtitle: {
115
+ color,
116
+ font
117
+ }
118
+ }
119
+ }, this.options());
120
+ }
121
+ refreshTheme() {
122
+ if (!this.chart || this.destroyed) return;
123
+ this.chart.options = this.themedOptions();
124
+ this.chart.update("none");
125
+ }
126
+ ngOnDestroy() {
127
+ this.destroyed = true;
128
+ this.observer?.disconnect();
129
+ this.chart?.destroy();
130
+ }
131
+ static ɵfac = i0.ɵɵngDeclareFactory({
132
+ minVersion: "12.0.0",
133
+ version: "22.2.0",
134
+ ngImport: i0,
135
+ type: MChart,
136
+ deps: [],
137
+ target: i0.ɵɵFactoryTarget.Component
138
+ });
139
+ static ɵcmp = i0.ɵɵngDeclareComponent({
140
+ minVersion: "17.0.0",
141
+ version: "22.2.0",
142
+ type: MChart,
143
+ isStandalone: true,
144
+ selector: "m-chart",
145
+ inputs: {
146
+ type: {
147
+ classPropertyName: "type",
148
+ publicName: "type",
149
+ isSignal: true,
150
+ isRequired: false,
151
+ transformFunction: null
152
+ },
153
+ data: {
154
+ classPropertyName: "data",
155
+ publicName: "data",
156
+ isSignal: true,
157
+ isRequired: true,
158
+ transformFunction: null
159
+ },
160
+ options: {
161
+ classPropertyName: "options",
162
+ publicName: "options",
163
+ isSignal: true,
164
+ isRequired: false,
165
+ transformFunction: null
166
+ },
167
+ ariaLabel: {
168
+ classPropertyName: "ariaLabel",
169
+ publicName: "ariaLabel",
170
+ isSignal: true,
171
+ isRequired: false,
172
+ transformFunction: null
173
+ }
174
+ },
175
+ host: { classAttribute: "m-chart" },
176
+ viewQueries: [{
177
+ propertyName: "canvas",
178
+ first: true,
179
+ predicate: ["canvas"],
180
+ descendants: true,
181
+ isSignal: true
182
+ }],
183
+ ngImport: i0,
184
+ template: `
185
+ <div class="m-chart__container">
186
+ <canvas #canvas role="img" [attr.aria-label]="ariaLabel()">{{
187
+ ariaLabel()
188
+ }}</canvas>
189
+ </div>
190
+ @if (failed()) {
191
+ <span role="status">Chart could not be loaded.</span>
192
+ }
193
+ `,
194
+ isInline: true
195
+ });
196
+ };
197
+ i0.ɵɵngDeclareClassMetadata({
198
+ minVersion: "12.0.0",
199
+ version: "22.2.0",
200
+ ngImport: i0,
201
+ type: MChart,
202
+ decorators: [{
203
+ type: Component,
204
+ args: [{
205
+ selector: "m-chart",
206
+ template: `
207
+ <div class="m-chart__container">
208
+ <canvas #canvas role="img" [attr.aria-label]="ariaLabel()">{{
209
+ ariaLabel()
210
+ }}</canvas>
211
+ </div>
212
+ @if (failed()) {
213
+ <span role="status">Chart could not be loaded.</span>
214
+ }
215
+ `,
216
+ host: { class: "m-chart" }
217
+ }]
218
+ }],
219
+ ctorParameters: () => [],
220
+ propDecorators: {
221
+ type: [{
222
+ type: i0.Input,
223
+ args: [{
224
+ isSignal: true,
225
+ alias: "type",
226
+ required: false
227
+ }]
228
+ }],
229
+ data: [{
230
+ type: i0.Input,
231
+ args: [{
232
+ isSignal: true,
233
+ alias: "data",
234
+ required: true
235
+ }]
236
+ }],
237
+ options: [{
238
+ type: i0.Input,
239
+ args: [{
240
+ isSignal: true,
241
+ alias: "options",
242
+ required: false
243
+ }]
244
+ }],
245
+ ariaLabel: [{
246
+ type: i0.Input,
247
+ args: [{
248
+ isSignal: true,
249
+ alias: "ariaLabel",
250
+ required: false
251
+ }]
252
+ }],
253
+ canvas: [{
254
+ type: i0.ViewChild,
255
+ args: ["canvas", { isSignal: true }]
256
+ }]
257
+ }
258
+ });
259
+ export { MChart };
260
+
261
+ //# sourceMappingURL=maliardic-ma-ui-chart.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maliardic-ma-ui-chart.mjs","names":[],"sources":["../../../projects/ma-ui/chart/src/lib/chart.ts"],"sourcesContent":["import {\n Component,\n ElementRef,\n OnDestroy,\n afterNextRender,\n effect,\n inject,\n input,\n type InputSignal,\n signal,\n viewChild,\n} from \"@angular/core\";\nimport type { Chart, ChartData, ChartOptions, ChartType } from \"chart.js\";\n\n// Copy plain configuration objects only: callbacks, gradients and other instances retain identity.\nfunction copy<T>(value: T): T {\n if (Array.isArray(value)) return value.map(copy) as T;\n if (value && Object.getPrototypeOf(value) === Object.prototype) {\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, copy(item)]),\n ) as T;\n }\n return value;\n}\n\nfunction merge(\n base: Record<string, any>,\n overrides: Record<string, any>,\n): Record<string, any> {\n const result = copy(base);\n for (const [key, value] of Object.entries(overrides)) {\n if (value === undefined) continue;\n result[key] =\n value && Object.getPrototypeOf(value) === Object.prototype\n ? merge(\n result[key] && typeof result[key] === \"object\" ? result[key] : {},\n value,\n )\n : copy(value);\n }\n return result;\n}\n\n@Component({\n selector: \"m-chart\",\n template: `\n <div class=\"m-chart__container\">\n <canvas #canvas role=\"img\" [attr.aria-label]=\"ariaLabel()\">{{\n ariaLabel()\n }}</canvas>\n </div>\n @if (failed()) {\n <span role=\"status\">Chart could not be loaded.</span>\n }\n `,\n host: { class: \"m-chart\" },\n})\nexport class MChart implements OnDestroy {\n readonly type = input<ChartType>(\"bar\");\n readonly data = input.required<ChartData>();\n readonly options: InputSignal<ChartOptions> = input<ChartOptions>({});\n readonly ariaLabel = input(\"Chart\");\n protected readonly failed = signal(false);\n\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly canvas =\n viewChild.required<ElementRef<HTMLCanvasElement>>(\"canvas\");\n private readonly constructorRef = signal<typeof Chart | null>(null);\n private chart?: Chart;\n private chartType?: ChartType;\n private observer?: MutationObserver;\n private destroyed = false;\n\n constructor() {\n afterNextRender(() => {\n void import(\"chart.js/auto\")\n .then(({ default: ChartConstructor }) => {\n if (this.destroyed) return;\n this.constructorRef.set(ChartConstructor);\n this.observer = new MutationObserver(() => this.refreshTheme());\n for (\n let node: HTMLElement | null = this.host.nativeElement;\n node;\n node = node.parentElement\n ) {\n this.observer.observe(node, {\n attributes: true,\n attributeFilter: [\"class\", \"style\"],\n });\n }\n })\n .catch(() => {\n if (!this.destroyed) this.failed.set(true);\n });\n });\n effect(() => {\n const ChartConstructor = this.constructorRef();\n if (!ChartConstructor) return;\n const type = this.type();\n const data = copy(this.data());\n const options = this.themedOptions();\n if (this.chart && this.chartType === type) {\n this.chart.data = data;\n this.chart.options = options;\n this.chart.update();\n } else {\n this.chart?.destroy();\n this.chartType = type;\n this.chart = new ChartConstructor(this.canvas().nativeElement, {\n type,\n data,\n options,\n });\n }\n });\n }\n\n private themedOptions(): ChartOptions {\n const style = getComputedStyle(this.host.nativeElement);\n const color =\n style.getPropertyValue(\"--m-color-text\").trim() || style.color;\n const gridColor = style.getPropertyValue(\"--m-color-border\").trim();\n const font = { family: style.fontFamily, size: parseFloat(style.fontSize) };\n const axis = {\n ticks: { color, font },\n grid: { color: gridColor },\n border: { color: gridColor },\n title: { color, font },\n };\n const type = this.type();\n const scales: Record<string, unknown> = {};\n if (type === \"radar\" || type === \"polarArea\") {\n scales[\"r\"] = {\n ...axis,\n angleLines: { color: gridColor },\n pointLabels: { color, font },\n };\n } else if (type !== \"pie\" && type !== \"doughnut\") {\n scales[\"x\"] = axis;\n scales[\"y\"] = axis;\n }\n for (const key of Object.keys(this.options().scales ?? {})) {\n scales[key] ??= axis;\n }\n return merge(\n {\n responsive: true,\n maintainAspectRatio: false,\n color,\n font,\n scales,\n plugins: {\n legend: { labels: { color, font } },\n title: { color, font },\n subtitle: { color, font },\n },\n },\n this.options(),\n ) as ChartOptions;\n }\n\n private refreshTheme(): void {\n if (!this.chart || this.destroyed) return;\n this.chart.options = this.themedOptions();\n this.chart.update(\"none\");\n }\n\n ngOnDestroy(): void {\n this.destroyed = true;\n this.observer?.disconnect();\n this.chart?.destroy();\n }\n}\n"],"mappings":";;AAeA,SAAS,KAAQ,OAAQ;CACvB,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,IAAI;CAC/C,IAAI,SAAS,OAAO,eAAe,KAAK,MAAM,OAAO,WACnD,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC;CAGjE,OAAO;AACT;AAEA,SAAS,MACP,MACA,WAA8B;CAE9B,MAAM,SAAS,KAAK,IAAI;CACxB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;EACpD,IAAI,UAAU,QAAW;EACzB,OAAO,OACL,SAAS,OAAO,eAAe,KAAK,MAAM,OAAO,YAC7C,MACE,OAAO,QAAQ,OAAO,OAAO,SAAS,WAAW,OAAO,OAAO,CAAA,GAC/D,KAAK,IAEP,KAAK,KAAK;CAClB;CACA,OAAO;AACT;AAgBA,IAAa,SAAb,MAAa,OAAM;CACR,OAAO,MAAiB,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAC9B,OAAO,MAAM,SAAqB,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