@gravionlabs/helix-ui 22.2.12 → 22.2.14
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.
- package/fesm2022/gravionlabs-helix-ui-chart.mjs +14 -14
- package/fesm2022/gravionlabs-helix-ui-chart.mjs.map +1 -1
- package/fesm2022/gravionlabs-helix-ui-validators.mjs.map +1 -1
- package/fesm2022/gravionlabs-helix-ui.mjs +1298 -1301
- package/fesm2022/gravionlabs-helix-ui.mjs.map +1 -1
- package/package.json +1 -1
- package/types/gravionlabs-helix-ui.d.ts +0 -180
|
@@ -29,21 +29,21 @@ var HxChart = class HxChart {
|
|
|
29
29
|
#zone = inject(NgZone);
|
|
30
30
|
#loader = inject(HX_CHART_LOADER);
|
|
31
31
|
#platform = inject(PLATFORM_ID);
|
|
32
|
-
canvas = viewChild.required("canvas", ...ngDevMode ? [{ debugName: "canvas" }] :
|
|
33
|
-
type = input("bar", ...ngDevMode ? [{ debugName: "type" }] :
|
|
34
|
-
data = input({}, ...ngDevMode ? [{ debugName: "data" }] :
|
|
35
|
-
options = input({}, ...ngDevMode ? [{ debugName: "options" }] :
|
|
36
|
-
plugins = input([], ...ngDevMode ? [{ debugName: "plugins" }] :
|
|
37
|
-
width = input(...ngDevMode ? [void 0, { debugName: "width" }] :
|
|
38
|
-
height = input(...ngDevMode ? [void 0, { debugName: "height" }] :
|
|
32
|
+
canvas = viewChild.required("canvas", ...ngDevMode ? [{ debugName: "canvas" }] : /* istanbul ignore next */ []);
|
|
33
|
+
type = input("bar", ...ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []);
|
|
34
|
+
data = input({}, ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
|
|
35
|
+
options = input({}, ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
|
|
36
|
+
plugins = input([], ...ngDevMode ? [{ debugName: "plugins" }] : /* istanbul ignore next */ []);
|
|
37
|
+
width = input(...ngDevMode ? [void 0, { debugName: "width" }] : /* istanbul ignore next */ []);
|
|
38
|
+
height = input(...ngDevMode ? [void 0, { debugName: "height" }] : /* istanbul ignore next */ []);
|
|
39
39
|
responsive = input(true, {
|
|
40
|
-
...ngDevMode ? { debugName: "responsive" } :
|
|
40
|
+
...ngDevMode ? { debugName: "responsive" } : /* istanbul ignore next */ {},
|
|
41
41
|
transform: (v) => v !== false && v !== "false"
|
|
42
42
|
});
|
|
43
|
-
ariaLabel = input(...ngDevMode ? [void 0, { debugName: "ariaLabel" }] :
|
|
44
|
-
ariaLabelledBy = input(...ngDevMode ? [void 0, { debugName: "ariaLabelledBy" }] :
|
|
43
|
+
ariaLabel = input(...ngDevMode ? [void 0, { debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
|
|
44
|
+
ariaLabelledBy = input(...ngDevMode ? [void 0, { debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []);
|
|
45
45
|
themeDelay = input(50, {
|
|
46
|
-
...ngDevMode ? { debugName: "themeDelay" } :
|
|
46
|
+
...ngDevMode ? { debugName: "themeDelay" } : /* istanbul ignore next */ {},
|
|
47
47
|
transform: numberAttribute
|
|
48
48
|
});
|
|
49
49
|
dataSelect = output();
|
|
@@ -214,7 +214,7 @@ var HxChart = class HxChart {
|
|
|
214
214
|
}
|
|
215
215
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
216
216
|
minVersion: "12.0.0",
|
|
217
|
-
version: "22.2.
|
|
217
|
+
version: "22.2.3",
|
|
218
218
|
ngImport: i0,
|
|
219
219
|
type: HxChart,
|
|
220
220
|
deps: [],
|
|
@@ -222,7 +222,7 @@ var HxChart = class HxChart {
|
|
|
222
222
|
});
|
|
223
223
|
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
224
224
|
minVersion: "17.2.0",
|
|
225
|
-
version: "22.2.
|
|
225
|
+
version: "22.2.3",
|
|
226
226
|
type: HxChart,
|
|
227
227
|
isStandalone: true,
|
|
228
228
|
selector: "hx-chart",
|
|
@@ -326,7 +326,7 @@ var HxChart = class HxChart {
|
|
|
326
326
|
};
|
|
327
327
|
i0.ɵɵngDeclareClassMetadata({
|
|
328
328
|
minVersion: "12.0.0",
|
|
329
|
-
version: "22.2.
|
|
329
|
+
version: "22.2.3",
|
|
330
330
|
ngImport: i0,
|
|
331
331
|
type: HxChart,
|
|
332
332
|
decorators: [{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gravionlabs-helix-ui-chart.mjs","names":[],"sources":["../../../projects/ui/chart/chart.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n afterNextRender,\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n effect,\n InjectionToken,\n inject,\n input,\n NgZone,\n numberAttribute,\n output,\n PLATFORM_ID,\n untracked,\n viewChild,\n} from '@angular/core';\n\nexport type HxChartType =\n | 'bar'\n | 'line'\n | 'scatter'\n | 'bubble'\n | 'pie'\n | 'doughnut'\n | 'polarArea'\n | 'radar';\n\n/** What `(dataSelect)` carries: the click and what chart.js found under it. */\nexport interface HxChartSelectEvent {\n originalEvent: Event;\n /** The nearest element under the pointer (chart.js `{ datasetIndex, index, element }`). */\n element: unknown;\n /** The elements of that dataset. */\n dataset: unknown[];\n}\n\n/** The part of chart.js this component uses; the real module is `chart.js/auto`. */\nexport interface HxChartModule {\n default: new (canvas: HTMLCanvasElement, config: unknown) => HxChartInstance;\n}\n\nexport interface HxChartInstance {\n data: unknown;\n options: unknown;\n update(mode?: string): void;\n destroy(): void;\n getElementsAtEventForMode(\n event: Event,\n mode: string,\n options: object,\n useFinalPosition: boolean,\n ): unknown[];\n}\n\n/**\n * Loads chart.js. The default is a dynamic `import('chart.js/auto')`, so chart.js is only fetched by apps that show\n * a chart; provide another function to register a smaller set of chart.js parts or to replace it in tests.\n */\nexport const HX_CHART_LOADER = new InjectionToken<() => Promise<HxChartModule>>('HX_CHART_LOADER', {\n providedIn: 'root',\n factory: () => () => import('chart.js/auto') as unknown as Promise<HxChartModule>,\n});\n\n/** Colours of the datasets that do not set their own, as tokens in the order they are used. */\nconst PALETTE = [\n '--h-primary-color',\n '--h-orange-500',\n '--h-green-500',\n '--h-purple-500',\n '--h-sky-500',\n '--h-red-500',\n '--h-yellow-500',\n '--h-teal-500',\n];\n\ntype Json = Record<string, unknown>;\n\n/** The parts of chart.js data and datasets that are read here; everything else is passed on untouched. */\ninterface ChartDataLike extends Json {\n datasets?: unknown;\n}\ninterface DatasetLike extends Json {\n data?: unknown;\n backgroundColor?: unknown;\n borderColor?: unknown;\n}\n\nconst isObject = (value: unknown): value is Json =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** `defaults` underneath, `overrides` on top; objects merge, everything else is replaced. */\nfunction merge(defaults: Json, overrides: Json): Json {\n const out: Json = { ...defaults };\n for (const [key, value] of Object.entries(overrides)) {\n const base = out[key];\n out[key] = isObject(base) && isObject(value) ? merge(base, value) : value;\n }\n return out;\n}\n\n/**\n * A chart.js chart whose colours, grid and font come from the Helix tokens.\n *\n * ```html\n * <hx-chart type=\"bar\" [data]=\"data\" [options]=\"options\" height=\"20rem\" ariaLabel=\"Sales per month\">\n * <table hxChartFallback>…the same numbers as text…</table>\n * </hx-chart>\n * ```\n *\n * chart.js is an optional peer dependency, loaded with a dynamic import (see `HX_CHART_LOADER`) the first time a\n * chart is shown. Datasets without colours get the Helix palette; text, grid and legend colours come from\n * `--h-text-muted-color` and `--h-content-border-color` of the element. Your `options` win over these defaults.\n * The chart is redrawn when `class` or `style` of `<html>` change (dark mode, the primary colour).\n *\n * The canvas is an `img` named by `ariaLabel` / `ariaLabelledBy`; content marked `hxChartFallback` becomes the\n * canvas fallback content, which assistive technology reads: put the numbers there as text or as a table.\n */\n@Component({\n selector: 'hx-chart',\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: { class: 'hx-chart' },\n template: `\n <div class=\"hx-chart-frame\" [style.width]=\"width() ?? null\" [style.height]=\"height() ?? null\">\n <canvas\n #canvas\n class=\"hx-chart-canvas\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n (click)=\"onClick($event)\"\n ><ng-content select=\"[hxChartFallback]\" /></canvas>\n </div>\n `,\n})\nexport class HxChart {\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n readonly #zone = inject(NgZone);\n readonly #loader = inject(HX_CHART_LOADER);\n readonly #platform = inject(PLATFORM_ID);\n private readonly canvas = viewChild.required<ElementRef<HTMLCanvasElement>>('canvas');\n\n readonly type = input<HxChartType>('bar');\n /** chart.js data: `{ labels, datasets }`. Pass a new object to update the chart. */\n readonly data = input<ChartDataLike>({});\n /** chart.js options, on top of the token defaults. Pass a new object to update the chart. */\n readonly options = input<Json>({});\n /** Extra chart.js plugins for this chart. */\n readonly plugins = input<readonly unknown[]>([]);\n /** CSS width of the frame, e.g. `30rem`; the chart fills its container by default. */\n readonly width = input<string>();\n /** CSS height of the frame; without it chart.js keeps its aspect ratio. */\n readonly height = input<string>();\n /** Resize with the container. */\n readonly responsive = input(true, { transform: (v: unknown) => v !== false && v !== 'false' });\n readonly ariaLabel = input<string>();\n readonly ariaLabelledBy = input<string>();\n /** Delay of a redraw after the theme changed, in ms; the style change is usually followed by more. */\n readonly themeDelay = input(50, { transform: numberAttribute });\n\n /** A data point or dataset was clicked. */\n readonly dataSelect = output<HxChartSelectEvent>();\n\n #chart: HxChartInstance | undefined;\n #chartType: HxChartType | undefined;\n #ready = false;\n #loading = false;\n #observer: MutationObserver | undefined;\n #timer: ReturnType<typeof setTimeout> | undefined;\n\n constructor() {\n afterNextRender(() => {\n this.#ready = true;\n void this.#render();\n this.#watchTheme();\n });\n effect(() => {\n this.type();\n this.data();\n this.options();\n this.plugins();\n this.responsive();\n this.width();\n this.height();\n untracked(() => {\n if (this.#ready) void this.#render();\n });\n });\n inject(DestroyRef).onDestroy(() => {\n clearTimeout(this.#timer);\n this.#observer?.disconnect();\n this.#chart?.destroy();\n this.#chart = undefined;\n this.#ready = false;\n });\n }\n\n /** The chart.js instance, once it exists; `undefined` before chart.js has loaded. */\n get chart(): HxChartInstance | undefined {\n return this.#chart;\n }\n\n /** Redraws the chart, e.g. after the theme changed in a way the component cannot see. */\n refresh(): void {\n if (this.#chart) {\n this.#apply(this.#chart);\n this.#chart.update();\n }\n }\n\n protected onClick(event: MouseEvent): void {\n const chart = this.#chart;\n if (!chart) return;\n const element = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false);\n const dataset = chart.getElementsAtEventForMode(event, 'dataset', { intersect: true }, false);\n if (element?.[0] && dataset)\n this.dataSelect.emit({ originalEvent: event, element: element[0], dataset });\n }\n\n async #render(): Promise<void> {\n if (!isPlatformBrowser(this.#platform)) return;\n const type = this.type();\n if (this.#chart && this.#chartType === type) {\n this.#apply(this.#chart);\n this.#chart.update();\n return;\n }\n if (this.#loading) return;\n this.#loading = true;\n try {\n const module = await this.#loader();\n if (!this.#ready) return; // destroyed while chart.js loaded\n this.#chart?.destroy();\n const Chart = module.default;\n this.#zone.runOutsideAngular(() => {\n this.#chart = new Chart(this.canvas().nativeElement, {\n type: this.type(),\n data: this.#themedData(),\n options: this.#themedOptions(),\n plugins: [...this.plugins()],\n });\n });\n this.#chartType = this.type();\n } catch (error) {\n console.error(\n 'hx-chart: chart.js could not be loaded. Is the peer dependency \"chart.js\" installed?',\n error,\n );\n return;\n } finally {\n this.#loading = false;\n }\n // inputs may have changed while chart.js loaded\n if (this.#chart && this.#chartType !== this.type()) await this.#render();\n }\n\n #apply(chart: HxChartInstance): void {\n chart.data = this.#themedData();\n chart.options = this.#themedOptions();\n }\n\n #token(name: string): string {\n return getComputedStyle(this.#host).getPropertyValue(name).trim();\n }\n\n /** The datasets with palette colours where they set none. The input is not changed. */\n #themedData(): Json {\n const data = this.data();\n const datasets = data.datasets;\n if (!Array.isArray(datasets)) return data;\n const palette = PALETTE.map((name) => this.#token(name)).filter(Boolean);\n if (palette.length === 0) return data;\n const perPoint = ['pie', 'doughnut', 'polarArea'].includes(this.type());\n return {\n ...data,\n datasets: datasets.map((dataset: DatasetLike, i: number) => {\n if (!isObject(dataset)) return dataset;\n const color = palette[i % palette.length];\n const count = Array.isArray(dataset.data) ? dataset.data.length : 0;\n const points = Array.from({ length: count }, (_, n) => palette[n % palette.length]);\n const filled = this.type() === 'line' || this.type() === 'radar';\n return {\n ...dataset,\n backgroundColor:\n dataset.backgroundColor ??\n (perPoint ? points : filled ? `color-mix(in srgb, ${color}, transparent 80%)` : color),\n borderColor:\n dataset.borderColor ?? (perPoint ? this.#token('--h-content-background') : color),\n };\n }),\n };\n }\n\n #themedOptions(): Json {\n const text = this.#token('--h-text-color');\n const muted = this.#token('--h-text-muted-color');\n const grid = this.#token('--h-content-border-color');\n const axis = { ticks: { color: muted }, grid: { color: grid }, border: { color: grid } };\n const radial = {\n ticks: { color: muted, backdropColor: 'transparent' },\n grid: { color: grid },\n angleLines: { color: grid },\n pointLabels: { color: text },\n };\n const type = this.type();\n const scales =\n type === 'radar' || type === 'polarArea'\n ? { r: radial }\n : type === 'pie' || type === 'doughnut'\n ? {}\n : { x: axis, y: axis };\n const defaults: Json = {\n responsive: this.responsive(),\n maintainAspectRatio: !(this.height() || this.width()),\n color: muted,\n borderColor: grid,\n plugins: { legend: { labels: { color: text } } },\n scales,\n };\n return merge(defaults, this.options());\n }\n\n #watchTheme(): void {\n if (typeof MutationObserver === 'undefined') return;\n this.#observer = new MutationObserver(() => {\n clearTimeout(this.#timer);\n this.#timer = setTimeout(() => this.refresh(), this.themeDelay());\n });\n this.#observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['class', 'style', 'data-theme'],\n });\n }\n}\n"],"mappings":";;;AA4DA,MAAa,kBAAkB,IAAI,eAA6C,mBAAmB;CACjG,YAAY;CACZ,qBAAqB,OAAO;AAC7B,CAAA;AAGD,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAcD,MAAM,YAAY,UAChB,OA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AA;EAAA,SAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,OAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,QAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,YAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,WAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,gBAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,YAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,YAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,YAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"gravionlabs-helix-ui-chart.mjs","names":[],"sources":["../../../projects/ui/chart/chart.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n afterNextRender,\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n effect,\n InjectionToken,\n inject,\n input,\n NgZone,\n numberAttribute,\n output,\n PLATFORM_ID,\n untracked,\n viewChild,\n} from '@angular/core';\n\nexport type HxChartType =\n | 'bar'\n | 'line'\n | 'scatter'\n | 'bubble'\n | 'pie'\n | 'doughnut'\n | 'polarArea'\n | 'radar';\n\n/** What `(dataSelect)` carries: the click and what chart.js found under it. */\nexport interface HxChartSelectEvent {\n originalEvent: Event;\n /** The nearest element under the pointer (chart.js `{ datasetIndex, index, element }`). */\n element: unknown;\n /** The elements of that dataset. */\n dataset: unknown[];\n}\n\n/** The part of chart.js this component uses; the real module is `chart.js/auto`. */\nexport interface HxChartModule {\n default: new (canvas: HTMLCanvasElement, config: unknown) => HxChartInstance;\n}\n\nexport interface HxChartInstance {\n data: unknown;\n options: unknown;\n update(mode?: string): void;\n destroy(): void;\n getElementsAtEventForMode(\n event: Event,\n mode: string,\n options: object,\n useFinalPosition: boolean,\n ): unknown[];\n}\n\n/**\n * Loads chart.js. The default is a dynamic `import('chart.js/auto')`, so chart.js is only fetched by apps that show\n * a chart; provide another function to register a smaller set of chart.js parts or to replace it in tests.\n */\nexport const HX_CHART_LOADER = new InjectionToken<() => Promise<HxChartModule>>('HX_CHART_LOADER', {\n providedIn: 'root',\n factory: () => () => import('chart.js/auto') as unknown as Promise<HxChartModule>,\n});\n\n/** Colours of the datasets that do not set their own, as tokens in the order they are used. */\nconst PALETTE = [\n '--h-primary-color',\n '--h-orange-500',\n '--h-green-500',\n '--h-purple-500',\n '--h-sky-500',\n '--h-red-500',\n '--h-yellow-500',\n '--h-teal-500',\n];\n\ntype Json = Record<string, unknown>;\n\n/** The parts of chart.js data and datasets that are read here; everything else is passed on untouched. */\ninterface ChartDataLike extends Json {\n datasets?: unknown;\n}\ninterface DatasetLike extends Json {\n data?: unknown;\n backgroundColor?: unknown;\n borderColor?: unknown;\n}\n\nconst isObject = (value: unknown): value is Json =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** `defaults` underneath, `overrides` on top; objects merge, everything else is replaced. */\nfunction merge(defaults: Json, overrides: Json): Json {\n const out: Json = { ...defaults };\n for (const [key, value] of Object.entries(overrides)) {\n const base = out[key];\n out[key] = isObject(base) && isObject(value) ? merge(base, value) : value;\n }\n return out;\n}\n\n/**\n * A chart.js chart whose colours, grid and font come from the Helix tokens.\n *\n * ```html\n * <hx-chart type=\"bar\" [data]=\"data\" [options]=\"options\" height=\"20rem\" ariaLabel=\"Sales per month\">\n * <table hxChartFallback>…the same numbers as text…</table>\n * </hx-chart>\n * ```\n *\n * chart.js is an optional peer dependency, loaded with a dynamic import (see `HX_CHART_LOADER`) the first time a\n * chart is shown. Datasets without colours get the Helix palette; text, grid and legend colours come from\n * `--h-text-muted-color` and `--h-content-border-color` of the element. Your `options` win over these defaults.\n * The chart is redrawn when `class` or `style` of `<html>` change (dark mode, the primary colour).\n *\n * The canvas is an `img` named by `ariaLabel` / `ariaLabelledBy`; content marked `hxChartFallback` becomes the\n * canvas fallback content, which assistive technology reads: put the numbers there as text or as a table.\n */\n@Component({\n selector: 'hx-chart',\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: { class: 'hx-chart' },\n template: `\n <div class=\"hx-chart-frame\" [style.width]=\"width() ?? null\" [style.height]=\"height() ?? null\">\n <canvas\n #canvas\n class=\"hx-chart-canvas\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n (click)=\"onClick($event)\"\n ><ng-content select=\"[hxChartFallback]\" /></canvas>\n </div>\n `,\n})\nexport class HxChart {\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n readonly #zone = inject(NgZone);\n readonly #loader = inject(HX_CHART_LOADER);\n readonly #platform = inject(PLATFORM_ID);\n private readonly canvas = viewChild.required<ElementRef<HTMLCanvasElement>>('canvas');\n\n readonly type = input<HxChartType>('bar');\n /** chart.js data: `{ labels, datasets }`. Pass a new object to update the chart. */\n readonly data = input<ChartDataLike>({});\n /** chart.js options, on top of the token defaults. Pass a new object to update the chart. */\n readonly options = input<Json>({});\n /** Extra chart.js plugins for this chart. */\n readonly plugins = input<readonly unknown[]>([]);\n /** CSS width of the frame, e.g. `30rem`; the chart fills its container by default. */\n readonly width = input<string>();\n /** CSS height of the frame; without it chart.js keeps its aspect ratio. */\n readonly height = input<string>();\n /** Resize with the container. */\n readonly responsive = input(true, { transform: (v: unknown) => v !== false && v !== 'false' });\n readonly ariaLabel = input<string>();\n readonly ariaLabelledBy = input<string>();\n /** Delay of a redraw after the theme changed, in ms; the style change is usually followed by more. */\n readonly themeDelay = input(50, { transform: numberAttribute });\n\n /** A data point or dataset was clicked. */\n readonly dataSelect = output<HxChartSelectEvent>();\n\n #chart: HxChartInstance | undefined;\n #chartType: HxChartType | undefined;\n #ready = false;\n #loading = false;\n #observer: MutationObserver | undefined;\n #timer: ReturnType<typeof setTimeout> | undefined;\n\n constructor() {\n afterNextRender(() => {\n this.#ready = true;\n void this.#render();\n this.#watchTheme();\n });\n effect(() => {\n this.type();\n this.data();\n this.options();\n this.plugins();\n this.responsive();\n this.width();\n this.height();\n untracked(() => {\n if (this.#ready) void this.#render();\n });\n });\n inject(DestroyRef).onDestroy(() => {\n clearTimeout(this.#timer);\n this.#observer?.disconnect();\n this.#chart?.destroy();\n this.#chart = undefined;\n this.#ready = false;\n });\n }\n\n /** The chart.js instance, once it exists; `undefined` before chart.js has loaded. */\n get chart(): HxChartInstance | undefined {\n return this.#chart;\n }\n\n /** Redraws the chart, e.g. after the theme changed in a way the component cannot see. */\n refresh(): void {\n if (this.#chart) {\n this.#apply(this.#chart);\n this.#chart.update();\n }\n }\n\n protected onClick(event: MouseEvent): void {\n const chart = this.#chart;\n if (!chart) return;\n const element = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false);\n const dataset = chart.getElementsAtEventForMode(event, 'dataset', { intersect: true }, false);\n if (element?.[0] && dataset)\n this.dataSelect.emit({ originalEvent: event, element: element[0], dataset });\n }\n\n async #render(): Promise<void> {\n if (!isPlatformBrowser(this.#platform)) return;\n const type = this.type();\n if (this.#chart && this.#chartType === type) {\n this.#apply(this.#chart);\n this.#chart.update();\n return;\n }\n if (this.#loading) return;\n this.#loading = true;\n try {\n const module = await this.#loader();\n if (!this.#ready) return; // destroyed while chart.js loaded\n this.#chart?.destroy();\n const Chart = module.default;\n this.#zone.runOutsideAngular(() => {\n this.#chart = new Chart(this.canvas().nativeElement, {\n type: this.type(),\n data: this.#themedData(),\n options: this.#themedOptions(),\n plugins: [...this.plugins()],\n });\n });\n this.#chartType = this.type();\n } catch (error) {\n console.error(\n 'hx-chart: chart.js could not be loaded. Is the peer dependency \"chart.js\" installed?',\n error,\n );\n return;\n } finally {\n this.#loading = false;\n }\n // inputs may have changed while chart.js loaded\n if (this.#chart && this.#chartType !== this.type()) await this.#render();\n }\n\n #apply(chart: HxChartInstance): void {\n chart.data = this.#themedData();\n chart.options = this.#themedOptions();\n }\n\n #token(name: string): string {\n return getComputedStyle(this.#host).getPropertyValue(name).trim();\n }\n\n /** The datasets with palette colours where they set none. The input is not changed. */\n #themedData(): Json {\n const data = this.data();\n const datasets = data.datasets;\n if (!Array.isArray(datasets)) return data;\n const palette = PALETTE.map((name) => this.#token(name)).filter(Boolean);\n if (palette.length === 0) return data;\n const perPoint = ['pie', 'doughnut', 'polarArea'].includes(this.type());\n return {\n ...data,\n datasets: datasets.map((dataset: DatasetLike, i: number) => {\n if (!isObject(dataset)) return dataset;\n const color = palette[i % palette.length];\n const count = Array.isArray(dataset.data) ? dataset.data.length : 0;\n const points = Array.from({ length: count }, (_, n) => palette[n % palette.length]);\n const filled = this.type() === 'line' || this.type() === 'radar';\n return {\n ...dataset,\n backgroundColor:\n dataset.backgroundColor ??\n (perPoint ? points : filled ? `color-mix(in srgb, ${color}, transparent 80%)` : color),\n borderColor:\n dataset.borderColor ?? (perPoint ? this.#token('--h-content-background') : color),\n };\n }),\n };\n }\n\n #themedOptions(): Json {\n const text = this.#token('--h-text-color');\n const muted = this.#token('--h-text-muted-color');\n const grid = this.#token('--h-content-border-color');\n const axis = { ticks: { color: muted }, grid: { color: grid }, border: { color: grid } };\n const radial = {\n ticks: { color: muted, backdropColor: 'transparent' },\n grid: { color: grid },\n angleLines: { color: grid },\n pointLabels: { color: text },\n };\n const type = this.type();\n const scales =\n type === 'radar' || type === 'polarArea'\n ? { r: radial }\n : type === 'pie' || type === 'doughnut'\n ? {}\n : { x: axis, y: axis };\n const defaults: Json = {\n responsive: this.responsive(),\n maintainAspectRatio: !(this.height() || this.width()),\n color: muted,\n borderColor: grid,\n plugins: { legend: { labels: { color: text } } },\n scales,\n };\n return merge(defaults, this.options());\n }\n\n #watchTheme(): void {\n if (typeof MutationObserver === 'undefined') return;\n this.#observer = new MutationObserver(() => {\n clearTimeout(this.#timer);\n this.#timer = setTimeout(() => this.refresh(), this.themeDelay());\n });\n this.#observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['class', 'style', 'data-theme'],\n });\n }\n}\n"],"mappings":";;;AA4DA,MAAa,kBAAkB,IAAI,eAA6C,mBAAmB;CACjG,YAAY;CACZ,qBAAqB,OAAO;AAC7B,CAAA;AAGD,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAcD,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAGrE,SAAS,MAAM,UAAgB,WAAe;CAC5C,MAAM,MAAY,EAAE,GAAG,SAAQ;CAC/B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;EACpD,MAAM,OAAO,IAAI;EACjB,IAAI,OAAO,SAAS,IAAI,KAAK,SAAS,KAAK,IAAI,MAAM,MAAM,KAAK,IAAI;CACtE;CACA,OAAO;AACT;AAoCA,IAAa,UAAb,MAAa,QAAO;CACT,QAAQ,OAAgC,UAAU,CAAC,CAAC;CACpD,QAAQ,OAAO,MAAM;CACrB,UAAU,OAAO,eAAe;CAChC,YAAY,OAAO,WAAW;CACtB,SAAS,UAAU,SAAwC,UAAS,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;CAE5E,OAAO,MAAmB,OAAM,GAAA,YAA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BAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,YAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,YAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,YAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gravionlabs-helix-ui-validators.mjs","names":[],"sources":["../../../projects/ui/validators/validator-key.enum.ts","../../../projects/ui/validators/validators.ts"],"sourcesContent":["export enum ValidatorKey {\n Required = 'Required',\n Email = 'Email',\n Number = 'Number',\n Integer = 'Integer',\n Min = 'Min',\n Max = 'Max',\n MinLength = 'MinLength',\n MaxLength = 'MaxLength',\n Pattern = 'Pattern',\n Date = 'Date',\n OneOf = 'OneOf',\n AllOf = 'AllOf',\n}\n","import type { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';\nimport { FormControl, Validators as NgValidators } from '@angular/forms';\nimport { ValidatorKey } from './validator-key.enum';\n\nexport type ValidatorMessage = (value: any) => string;\n\nconst EMPTY_VALUES = ['', null, undefined];\n\nconst isEmptyValue = (v: unknown): boolean => EMPTY_VALUES.includes(v as string);\n\nconst checkEmpty =\n (allowEmpty: boolean, check: (value: unknown) => boolean) =>\n (ctrl: AbstractControl): boolean =>\n allowEmpty\n ? isEmptyValue(ctrl.value) || check(ctrl.value)\n : !isEmptyValue(ctrl.value) && check(ctrl.value);\n\nconst buildValidator =\n (\n isValid: (ctrl: AbstractControl) => boolean,\n key: ValidatorKey,\n msg: string | ValidatorMessage,\n ): ValidatorFn =>\n (ctrl: AbstractControl): ValidationErrors | null =>\n isValid(ctrl) ? null : { [key]: typeof msg === 'function' ? msg(ctrl.value) : msg };\n\nexport { buildValidator, checkEmpty, EMPTY_VALUES, isEmptyValue };\n\nexport const Validators = {\n required: (msg: string | ValidatorMessage): ValidatorFn => {\n const predicate = (ctrl: AbstractControl): boolean => !isEmptyValue(ctrl.value);\n return buildValidator(predicate, ValidatorKey.Required, msg);\n },\n\n email: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => {\n const ctrl = new FormControl(value);\n return NgValidators.email(ctrl) === null;\n };\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Email, msg);\n },\n\n pattern: (msg: string | ValidatorMessage, regex: RegExp, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => regex.test(value as string);\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Pattern, msg);\n },\n\n date: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => {\n const d = new Date(value as string | number | Date);\n return !Number.isNaN(d.getTime());\n };\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Date, msg);\n },\n\n number: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean =>\n typeof value !== 'boolean' && !Number.isNaN(Number(value));\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Number, msg);\n },\n\n integer: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => {\n if (typeof value === 'boolean') return false;\n const num = Number(value);\n return !Number.isNaN(num) && num % 1 === 0;\n };\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Integer, msg);\n },\n\n min: (msg: string | ValidatorMessage, minimum: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => Number(value) >= minimum;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Min, msg);\n },\n\n max: (msg: string | ValidatorMessage, maximum: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => Number(value) <= maximum;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Max, msg);\n },\n\n minLength: (msg: string | ValidatorMessage, min: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => (value as { length: number }).length >= min;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.MinLength, msg);\n },\n\n maxLength: (msg: string | ValidatorMessage, max: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => (value as { length: number }).length <= max;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.MaxLength, msg);\n },\n\n oneOf: (msg: string | ValidatorMessage, options: unknown[]): ValidatorFn => {\n const anyEmptyMember = EMPTY_VALUES.some((v) => options.includes(v));\n return (ctrl: AbstractControl): ValidationErrors | null => {\n const value = ctrl.value;\n if (anyEmptyMember && isEmptyValue(value)) return null;\n if (options.includes(value)) return null;\n return { [ValidatorKey.OneOf]: typeof msg === 'function' ? msg(value) : msg };\n };\n },\n\n allOf: (msg: string | ValidatorMessage, options: unknown[], allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean =>\n Array.isArray(value) && value.every((v) => options.includes(v));\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.AllOf, msg);\n },\n};\n"],"mappings":";AAAA,IAAY;CAAZ,SAAY,cAAY;CACtB,aAAA,cAAA;CACA,aAAA,WAAA;CACA,aAAA,YAAA;CACA,aAAA,aAAA;CACA,aAAA,SAAA;CACA,aAAA,SAAA;CACA,aAAA,eAAA;CACA,aAAA,eAAA;CACA,aAAA,aAAA;CACA,aAAA,UAAA;CACA,aAAA,WAAA;CACA,aAAA,WAAA;AACF,EAAA,CAbY,iBAAA,eAAY,CAAA,EAAA;ACMxB,MAAM,eAAe;CAAC;CAAI;CAAM;AAAS;AAEzC,MAAM,gBAAgB,MAAwB,aAAa,SAAS,CAAW;AAE/E,MAAM,cACH,YAAqB,WACrB,SACC,aACI,aAAa,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK,IAC5C,CAAC,aAAa,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK;AAErD,MAAM,kBAEF,SACA,KACA,SAED,SACC,QAAQ,IAAI,IAAI,OAAO,GAAG,MAAM,OAAO,QAAQ,aAAa,IAAI,KAAK,KAAK,IAAI,IAAG;AAIrF,MAAa,aAAa;CACxB,WAAW,QAA+C;EACxD,MAAM,aAAa,SAAmC,CAAC,aAAa,KAAK,KAAK;EAC9E,OAAO,eAAe,WAAW,aAAa,UAAU,GAAG;CAC7D;CAEA,QAAQ,KAAgC,aAAa,SAAqB;EACxE,MAAM,SAAS,UAA2B;GACxC,MAAM,OAAO,IAAI,YAAY,KAAK;GAClC,
|
|
1
|
+
{"version":3,"file":"gravionlabs-helix-ui-validators.mjs","names":["NgValidators"],"sources":["../../../projects/ui/validators/validator-key.enum.ts","../../../projects/ui/validators/validators.ts"],"sourcesContent":["export enum ValidatorKey {\n Required = 'Required',\n Email = 'Email',\n Number = 'Number',\n Integer = 'Integer',\n Min = 'Min',\n Max = 'Max',\n MinLength = 'MinLength',\n MaxLength = 'MaxLength',\n Pattern = 'Pattern',\n Date = 'Date',\n OneOf = 'OneOf',\n AllOf = 'AllOf',\n}\n","import type { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';\nimport { FormControl, Validators as NgValidators } from '@angular/forms';\nimport { ValidatorKey } from './validator-key.enum';\n\nexport type ValidatorMessage = (value: any) => string;\n\nconst EMPTY_VALUES = ['', null, undefined];\n\nconst isEmptyValue = (v: unknown): boolean => EMPTY_VALUES.includes(v as string);\n\nconst checkEmpty =\n (allowEmpty: boolean, check: (value: unknown) => boolean) =>\n (ctrl: AbstractControl): boolean =>\n allowEmpty\n ? isEmptyValue(ctrl.value) || check(ctrl.value)\n : !isEmptyValue(ctrl.value) && check(ctrl.value);\n\nconst buildValidator =\n (\n isValid: (ctrl: AbstractControl) => boolean,\n key: ValidatorKey,\n msg: string | ValidatorMessage,\n ): ValidatorFn =>\n (ctrl: AbstractControl): ValidationErrors | null =>\n isValid(ctrl) ? null : { [key]: typeof msg === 'function' ? msg(ctrl.value) : msg };\n\nexport { buildValidator, checkEmpty, EMPTY_VALUES, isEmptyValue };\n\nexport const Validators = {\n required: (msg: string | ValidatorMessage): ValidatorFn => {\n const predicate = (ctrl: AbstractControl): boolean => !isEmptyValue(ctrl.value);\n return buildValidator(predicate, ValidatorKey.Required, msg);\n },\n\n email: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => {\n const ctrl = new FormControl(value);\n return NgValidators.email(ctrl) === null;\n };\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Email, msg);\n },\n\n pattern: (msg: string | ValidatorMessage, regex: RegExp, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => regex.test(value as string);\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Pattern, msg);\n },\n\n date: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => {\n const d = new Date(value as string | number | Date);\n return !Number.isNaN(d.getTime());\n };\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Date, msg);\n },\n\n number: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean =>\n typeof value !== 'boolean' && !Number.isNaN(Number(value));\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Number, msg);\n },\n\n integer: (msg: string | ValidatorMessage, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => {\n if (typeof value === 'boolean') return false;\n const num = Number(value);\n return !Number.isNaN(num) && num % 1 === 0;\n };\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Integer, msg);\n },\n\n min: (msg: string | ValidatorMessage, minimum: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => Number(value) >= minimum;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Min, msg);\n },\n\n max: (msg: string | ValidatorMessage, maximum: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => Number(value) <= maximum;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.Max, msg);\n },\n\n minLength: (msg: string | ValidatorMessage, min: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => (value as { length: number }).length >= min;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.MinLength, msg);\n },\n\n maxLength: (msg: string | ValidatorMessage, max: number, allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean => (value as { length: number }).length <= max;\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.MaxLength, msg);\n },\n\n oneOf: (msg: string | ValidatorMessage, options: unknown[]): ValidatorFn => {\n const anyEmptyMember = EMPTY_VALUES.some((v) => options.includes(v));\n return (ctrl: AbstractControl): ValidationErrors | null => {\n const value = ctrl.value;\n if (anyEmptyMember && isEmptyValue(value)) return null;\n if (options.includes(value)) return null;\n return { [ValidatorKey.OneOf]: typeof msg === 'function' ? msg(value) : msg };\n };\n },\n\n allOf: (msg: string | ValidatorMessage, options: unknown[], allowEmpty = true): ValidatorFn => {\n const check = (value: unknown): boolean =>\n Array.isArray(value) && value.every((v) => options.includes(v));\n return buildValidator(checkEmpty(allowEmpty, check), ValidatorKey.AllOf, msg);\n },\n};\n"],"mappings":";AAAA,IAAY;CAAZ,SAAY,cAAY;CACtB,aAAA,cAAA;CACA,aAAA,WAAA;CACA,aAAA,YAAA;CACA,aAAA,aAAA;CACA,aAAA,SAAA;CACA,aAAA,SAAA;CACA,aAAA,eAAA;CACA,aAAA,eAAA;CACA,aAAA,aAAA;CACA,aAAA,UAAA;CACA,aAAA,WAAA;CACA,aAAA,WAAA;AACF,EAAA,CAbY,iBAAA,eAAY,CAAA,EAAA;ACMxB,MAAM,eAAe;CAAC;CAAI;CAAM;AAAS;AAEzC,MAAM,gBAAgB,MAAwB,aAAa,SAAS,CAAW;AAE/E,MAAM,cACH,YAAqB,WACrB,SACC,aACI,aAAa,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK,IAC5C,CAAC,aAAa,KAAK,KAAK,KAAK,MAA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