compostrap 0.0.0-stage → 1.0.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.
- package/dist/css/auth.css +166 -0
- package/dist/css/blog.css +512 -0
- package/dist/css/chart.css +99 -0
- package/dist/css/compostrap.css +5052 -0
- package/dist/css/dashboard.css +360 -0
- package/dist/css/datagrid.css +64 -0
- package/dist/css/datepicker.css +514 -0
- package/dist/css/dialogs.css +185 -0
- package/dist/css/dropzone.css +86 -0
- package/dist/css/elements.css +181 -0
- package/dist/css/empty.css +94 -0
- package/dist/css/gallery.css +122 -0
- package/dist/css/lightbox.css +144 -0
- package/dist/css/number-input.css +100 -0
- package/dist/css/otp-input.css +177 -0
- package/dist/css/password-toggle.css +52 -0
- package/dist/css/rating.css +95 -0
- package/dist/css/selection.css +59 -0
- package/dist/css/settings.css +85 -0
- package/dist/css/shop.css +1026 -0
- package/dist/css/sidebar-menu.css +439 -0
- package/dist/css/sidebar.css +95 -0
- package/dist/css/spinner.css +102 -0
- package/dist/css/strength.css +118 -0
- package/dist/css/theme-switcher.css +5 -0
- package/dist/css/theme.css +13034 -0
- package/dist/css/tooltip.css +158 -0
- package/dist/js/chart.js +257 -0
- package/dist/js/datepicker.js +82 -0
- package/dist/js/dialogs.js +7 -0
- package/dist/js/dropzone.js +15 -0
- package/dist/js/index.js +24 -0
- package/dist/js/lightbox.js +77 -0
- package/dist/js/number-input.js +44 -0
- package/dist/js/otp-input.js +182 -0
- package/dist/js/password-toggle.js +16 -0
- package/dist/js/selection.js +32 -0
- package/dist/js/sidebar-menu.js +76 -0
- package/dist/js/sidebar.js +120 -0
- package/dist/js/spinner.js +27 -0
- package/dist/js/strength.js +87 -0
- package/dist/js/theme-switcher.js +98 -0
- package/dist/js/tooltip.js +17 -0
- package/docs/auth.md +25 -0
- package/docs/blog.md +85 -0
- package/docs/chart.md +39 -0
- package/docs/datagrid.md +64 -0
- package/docs/datepicker.md +35 -0
- package/docs/dialogs.md +81 -0
- package/docs/dropzone.md +23 -0
- package/docs/elements.md +38 -0
- package/docs/empty.md +25 -0
- package/docs/gallery.md +23 -0
- package/docs/layout.md +143 -0
- package/docs/lightbox.md +18 -0
- package/docs/number-input.md +19 -0
- package/docs/otp-input.md +52 -0
- package/docs/password-toggle.md +21 -0
- package/docs/rating.md +15 -0
- package/docs/selection.md +52 -0
- package/docs/settings.md +25 -0
- package/docs/shop.md +140 -0
- package/docs/spinner.md +51 -0
- package/docs/strength.md +26 -0
- package/docs/theme-switcher.md +60 -0
- package/docs/theme.md +100 -0
- package/docs/tooltip.md +30 -0
- package/license +21 -0
- package/package.json +106 -6
- package/readme.md +198 -0
- package/src/illustrations/empty.svg +15 -0
- package/src/illustrations/forbidden.svg +16 -0
- package/src/illustrations/maintenance.svg +14 -0
- package/src/illustrations/not-found.svg +22 -0
- package/src/illustrations/server-error.svg +21 -0
- package/src/js/chart.js +359 -0
- package/src/js/datepicker.js +154 -0
- package/src/js/dialogs.js +25 -0
- package/src/js/dropzone.js +35 -0
- package/src/js/index.js +29 -0
- package/src/js/lightbox.js +165 -0
- package/src/js/number-input.js +87 -0
- package/src/js/otp-input.js +401 -0
- package/src/js/password-toggle.js +45 -0
- package/src/js/selection.js +114 -0
- package/src/js/sidebar-menu.js +178 -0
- package/src/js/sidebar.js +326 -0
- package/src/js/spinner.js +76 -0
- package/src/js/strength.js +115 -0
- package/src/js/theme-switcher.js +197 -0
- package/src/js/tooltip.js +46 -0
- package/src/scss/_bootstrap.scss +9 -0
- package/src/scss/_variables.scss +58 -0
- package/src/scss/auth/_index.scss +210 -0
- package/src/scss/auth.scss +5 -0
- package/src/scss/blog/_article.scss +181 -0
- package/src/scss/blog/_comments.scss +108 -0
- package/src/scss/blog/_index.scss +18 -0
- package/src/scss/blog/_list.scss +246 -0
- package/src/scss/blog/_page.scss +138 -0
- package/src/scss/blog.scss +5 -0
- package/src/scss/chart/_index.scss +114 -0
- package/src/scss/chart.scss +5 -0
- package/src/scss/compostrap.scss +29 -0
- package/src/scss/dashboard/_content.scss +25 -0
- package/src/scss/dashboard/_dropdown.scss +71 -0
- package/src/scss/dashboard/_index.scss +9 -0
- package/src/scss/dashboard/_nanobar.scss +34 -0
- package/src/scss/dashboard/_navbar.scss +314 -0
- package/src/scss/dashboard/_theme.scss +27 -0
- package/src/scss/dashboard.scss +5 -0
- package/src/scss/datagrid/_index.scss +111 -0
- package/src/scss/datagrid.scss +5 -0
- package/src/scss/datepicker/_index.scss +557 -0
- package/src/scss/datepicker.scss +5 -0
- package/src/scss/dialogs/_index.scss +8 -0
- package/src/scss/dialogs/_modal.scss +82 -0
- package/src/scss/dialogs/_offcanvas.scss +13 -0
- package/src/scss/dialogs/_search.scss +79 -0
- package/src/scss/dialogs/_toast.scss +61 -0
- package/src/scss/dialogs.scss +5 -0
- package/src/scss/dropzone/_index.scss +111 -0
- package/src/scss/dropzone.scss +5 -0
- package/src/scss/elements/_datagrid-filter.scss +21 -0
- package/src/scss/elements/_index.scss +9 -0
- package/src/scss/elements/_list-row.scss +40 -0
- package/src/scss/elements/_loading.scss +47 -0
- package/src/scss/elements/_stat.scss +73 -0
- package/src/scss/elements/_status-dot.scss +38 -0
- package/src/scss/elements.scss +5 -0
- package/src/scss/empty/_index.scss +117 -0
- package/src/scss/empty.scss +5 -0
- package/src/scss/gallery/_index.scss +162 -0
- package/src/scss/gallery.scss +5 -0
- package/src/scss/lightbox/_index.scss +171 -0
- package/src/scss/lightbox.scss +5 -0
- package/src/scss/number-input/_index.scss +143 -0
- package/src/scss/number-input.scss +5 -0
- package/src/scss/otp-input/_index.scss +214 -0
- package/src/scss/otp-input.scss +5 -0
- package/src/scss/password-toggle/_index.scss +82 -0
- package/src/scss/password-toggle.scss +5 -0
- package/src/scss/rating/_index.scss +121 -0
- package/src/scss/rating.scss +5 -0
- package/src/scss/selection/_index.scss +84 -0
- package/src/scss/selection.scss +5 -0
- package/src/scss/settings/_index.scss +6 -0
- package/src/scss/settings/_nav-list.scss +52 -0
- package/src/scss/settings/_setting-row.scss +50 -0
- package/src/scss/settings.scss +5 -0
- package/src/scss/shop/_bar.scss +64 -0
- package/src/scss/shop/_catalog.scss +308 -0
- package/src/scss/shop/_checkout.scss +204 -0
- package/src/scss/shop/_filters.scss +116 -0
- package/src/scss/shop/_hero.scss +130 -0
- package/src/scss/shop/_index.scss +22 -0
- package/src/scss/shop/_page.scss +154 -0
- package/src/scss/shop/_reviews.scss +165 -0
- package/src/scss/shop/_stepper.scss +159 -0
- package/src/scss/shop.scss +5 -0
- package/src/scss/sidebar/_body.scss +8 -0
- package/src/scss/sidebar/_index.scss +8 -0
- package/src/scss/sidebar/_sidebar.scss +89 -0
- package/src/scss/sidebar/_theme.scss +7 -0
- package/src/scss/sidebar/_wrapper.scss +17 -0
- package/src/scss/sidebar-menu/_compact.scss +174 -0
- package/src/scss/sidebar-menu/_index.scss +9 -0
- package/src/scss/sidebar-menu/_list.scss +131 -0
- package/src/scss/sidebar-menu/_pills.scss +82 -0
- package/src/scss/sidebar-menu/_scrollbar.scss +53 -0
- package/src/scss/sidebar-menu/_theme.scss +109 -0
- package/src/scss/sidebar-menu.scss +5 -0
- package/src/scss/sidebar.scss +5 -0
- package/src/scss/spinner/_index.scss +130 -0
- package/src/scss/spinner.scss +5 -0
- package/src/scss/strength/_index.scss +118 -0
- package/src/scss/strength.scss +5 -0
- package/src/scss/theme/_accordion.scss +20 -0
- package/src/scss/theme/_alerts.scss +24 -0
- package/src/scss/theme/_avatar.scss +37 -0
- package/src/scss/theme/_badges.scss +53 -0
- package/src/scss/theme/_base.scss +9 -0
- package/src/scss/theme/_breadcrumb.scss +64 -0
- package/src/scss/theme/_buttons.scss +200 -0
- package/src/scss/theme/_cards.scss +17 -0
- package/src/scss/theme/_colors.scss +139 -0
- package/src/scss/theme/_forms.scss +175 -0
- package/src/scss/theme/_index.scss +18 -0
- package/src/scss/theme/_navs.scss +15 -0
- package/src/scss/theme/_overlays.scss +128 -0
- package/src/scss/theme/_tables.scss +59 -0
- package/src/scss/theme/_variables.scss +194 -0
- package/src/scss/theme-switcher/_index.scss +9 -0
- package/src/scss/theme-switcher.scss +5 -0
- package/src/scss/theme.scss +9 -0
- package/src/scss/tooltip/_index.scss +177 -0
- package/src/scss/tooltip.scss +5 -0
- package/README.md +0 -3
package/src/js/chart.js
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Charts: Chart.js in the look of the theme, written as markup, so a template can print a chart without JavaScript of
|
|
3
|
+
* its own. A <canvas data-chart="{…}"> in a .chart box becomes a chart; the colors, the font, the grid and the
|
|
4
|
+
* tooltip come from the tokens of the theme (--chart-1…4, --chart-muted, --chart-grid), and the charts are drawn
|
|
5
|
+
* again when the theme of the page changes.
|
|
6
|
+
*
|
|
7
|
+
* <div class="chart" style="--chart-height: 16rem">
|
|
8
|
+
* <canvas data-chart='{"type": "area", "labels": ["1. 11.", "2. 11."], "series": [{"name": "Revenue", "data": [120, 180]}],
|
|
9
|
+
* "format": {"style": "currency", "currency": "USD", "maximumFractionDigits": 0}}' aria-label="Revenue"></canvas>
|
|
10
|
+
* </div>
|
|
11
|
+
*
|
|
12
|
+
* type: "area" (one series over time), "line", "bar" (columns), "bar-horizontal" (ranked bars with their values at
|
|
13
|
+
* the ends), "sparkline" (a small
|
|
14
|
+
* trend without axes, the last point in the accent). A series takes the next categorical color, or its own:
|
|
15
|
+
* "color": 1–4 or "muted" (the gray of the context series). "format" are the options of Intl.NumberFormat for the
|
|
16
|
+
* values, "locale" their language (the lang of the page by default); null is a missing value (the line ends there). Two or more series get a legend; every chart
|
|
17
|
+
* gets a table of its values for screen readers.
|
|
18
|
+
*/
|
|
19
|
+
import {
|
|
20
|
+
BarController,
|
|
21
|
+
BarElement,
|
|
22
|
+
CategoryScale,
|
|
23
|
+
Chart,
|
|
24
|
+
Filler,
|
|
25
|
+
LinearScale,
|
|
26
|
+
LineController,
|
|
27
|
+
LineElement,
|
|
28
|
+
PointElement,
|
|
29
|
+
Tooltip,
|
|
30
|
+
} from 'chart.js';
|
|
31
|
+
|
|
32
|
+
Chart.register(BarController, BarElement, CategoryScale, Filler, LinearScale, LineController, LineElement, PointElement, Tooltip);
|
|
33
|
+
|
|
34
|
+
// a vertical hairline at the hovered position of a line or an area chart
|
|
35
|
+
const crosshair = {
|
|
36
|
+
id: 'csCrosshair',
|
|
37
|
+
afterDatasetsDraw(chart) {
|
|
38
|
+
const active = chart.tooltip?.getActiveElements();
|
|
39
|
+
if (!active?.length || chart.config.type !== 'line' || chart.$csSparkline) return;
|
|
40
|
+
const { ctx, chartArea } = chart;
|
|
41
|
+
const x = active[0].element.x;
|
|
42
|
+
ctx.save();
|
|
43
|
+
ctx.beginPath();
|
|
44
|
+
ctx.moveTo(x, chartArea.top);
|
|
45
|
+
ctx.lineTo(x, chartArea.bottom);
|
|
46
|
+
ctx.lineWidth = 1;
|
|
47
|
+
ctx.strokeStyle = chart.$csTheme.axis;
|
|
48
|
+
ctx.stroke();
|
|
49
|
+
ctx.restore();
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// the value at the end of each ranked bar, in the text color (a bar chart with one series only)
|
|
54
|
+
const barValues = {
|
|
55
|
+
id: 'csBarValues',
|
|
56
|
+
afterDatasetsDraw(chart) {
|
|
57
|
+
if (!chart.$csBarValues) return;
|
|
58
|
+
const { ctx } = chart;
|
|
59
|
+
const meta = chart.getDatasetMeta(0);
|
|
60
|
+
ctx.save();
|
|
61
|
+
ctx.font = `500 14px ${chart.$csTheme.font}`;
|
|
62
|
+
ctx.fillStyle = chart.$csTheme.body;
|
|
63
|
+
ctx.textBaseline = 'middle';
|
|
64
|
+
meta.data.forEach((bar, i) => {
|
|
65
|
+
ctx.fillText(chart.$csBarValues.format(chart.data.datasets[0].data[i]), bar.x + 8, bar.y);
|
|
66
|
+
});
|
|
67
|
+
ctx.restore();
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export class Charts {
|
|
72
|
+
static _charts = new Map();
|
|
73
|
+
static _observer = null;
|
|
74
|
+
/** CSS colors already converted to rgba(), by their text. */
|
|
75
|
+
static _colors = new Map();
|
|
76
|
+
|
|
77
|
+
/** Draws every canvas[data-chart] below the root that is not drawn yet. */
|
|
78
|
+
static init(root = document) {
|
|
79
|
+
root.querySelectorAll('canvas[data-chart]').forEach((canvas) => {
|
|
80
|
+
if (!this._charts.has(canvas)) this.create(canvas);
|
|
81
|
+
});
|
|
82
|
+
if (!this._observer) {
|
|
83
|
+
// only a real change of the theme: a theme switch sets the attribute on its start too, mostly to the same
|
|
84
|
+
// value, which drew every chart twice
|
|
85
|
+
this._observer = new MutationObserver((mutations) => {
|
|
86
|
+
const theme = document.documentElement.getAttribute('data-bs-theme');
|
|
87
|
+
if (mutations.some((mutation) => mutation.oldValue !== theme)) {
|
|
88
|
+
this.refresh();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
this._observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-bs-theme'], attributeOldValue: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Draws all charts again, e.g. after the theme changed. */
|
|
96
|
+
static refresh() {
|
|
97
|
+
for (const [canvas, chart] of this._charts) {
|
|
98
|
+
if (!canvas.isConnected) {
|
|
99
|
+
chart.destroy();
|
|
100
|
+
this._charts.delete(canvas);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
chart.destroy();
|
|
104
|
+
this.create(canvas);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static create(canvas) {
|
|
109
|
+
const config = JSON.parse(canvas.dataset.chart);
|
|
110
|
+
const theme = this._theme(canvas);
|
|
111
|
+
const locale = config.locale || document.documentElement.lang || undefined;
|
|
112
|
+
const number = new Intl.NumberFormat(locale, config.format || {});
|
|
113
|
+
const compact = new Intl.NumberFormat(locale, { ...(config.format || {}), notation: 'compact', maximumFractionDigits: 1 });
|
|
114
|
+
const type = config.type || 'line';
|
|
115
|
+
const sparkline = type === 'sparkline';
|
|
116
|
+
const horizontal = type === 'bar-horizontal';
|
|
117
|
+
const bar = type === 'bar' || horizontal;
|
|
118
|
+
|
|
119
|
+
const datasets = config.series.map((series, i) => {
|
|
120
|
+
const color = series.color === 'muted' ? theme.muted : theme.colors[((series.color || i + 1) - 1) % theme.colors.length];
|
|
121
|
+
if (bar) {
|
|
122
|
+
return {
|
|
123
|
+
label: series.name,
|
|
124
|
+
data: series.data,
|
|
125
|
+
backgroundColor: color,
|
|
126
|
+
hoverBackgroundColor: this._alpha(color, .8),
|
|
127
|
+
borderRadius: 4,
|
|
128
|
+
borderSkipped: 'start',
|
|
129
|
+
maxBarThickness: 24,
|
|
130
|
+
categoryPercentage: .7,
|
|
131
|
+
barPercentage: .9,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const last = series.data.length - 1;
|
|
135
|
+
return {
|
|
136
|
+
label: series.name,
|
|
137
|
+
data: series.data,
|
|
138
|
+
borderColor: color,
|
|
139
|
+
backgroundColor: this._alpha(color, .1),
|
|
140
|
+
borderWidth: sparkline ? 1.5 : 2,
|
|
141
|
+
fill: type === 'area' || (sparkline && i === 0) ? 'origin' : false,
|
|
142
|
+
cubicInterpolationMode: 'monotone',
|
|
143
|
+
pointRadius: sparkline ? series.data.map((_, j) => (j === last ? 3 : 0)) : 0,
|
|
144
|
+
pointBackgroundColor: sparkline ? theme.colors[0] : color,
|
|
145
|
+
pointBorderColor: theme.surface,
|
|
146
|
+
pointBorderWidth: 2,
|
|
147
|
+
pointHoverRadius: sparkline ? 3 : 4,
|
|
148
|
+
pointHoverBorderWidth: 2,
|
|
149
|
+
pointHoverBorderColor: theme.surface,
|
|
150
|
+
pointHoverBackgroundColor: color,
|
|
151
|
+
borderCapStyle: 'round',
|
|
152
|
+
borderJoinStyle: 'round',
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const valueAxis = {
|
|
157
|
+
beginAtZero: true,
|
|
158
|
+
border: { display: false },
|
|
159
|
+
grid: { color: theme.grid, lineWidth: 1, drawTicks: false },
|
|
160
|
+
ticks: { color: theme.text, font: { size: 12 }, padding: 8, maxTicksLimit: 5, callback: (value) => compact.format(value) },
|
|
161
|
+
};
|
|
162
|
+
const categoryAxis = {
|
|
163
|
+
border: { display: false },
|
|
164
|
+
grid: { display: false },
|
|
165
|
+
ticks: { color: theme.text, font: { size: 12 }, maxRotation: 0, autoSkipPadding: 16, padding: 6 },
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const chart = new Chart(canvas, {
|
|
169
|
+
type: bar ? 'bar' : 'line',
|
|
170
|
+
data: { labels: config.labels, datasets },
|
|
171
|
+
plugins: [crosshair, barValues],
|
|
172
|
+
options: {
|
|
173
|
+
responsive: true,
|
|
174
|
+
maintainAspectRatio: false,
|
|
175
|
+
animation: false,
|
|
176
|
+
indexAxis: horizontal ? 'y' : 'x',
|
|
177
|
+
layout: { padding: sparkline ? 4 : 0 },
|
|
178
|
+
interaction: { mode: 'index', intersect: false, axis: horizontal ? 'y' : 'x' },
|
|
179
|
+
font: { family: theme.font },
|
|
180
|
+
scales: sparkline
|
|
181
|
+
? { x: { display: false }, y: { display: false, beginAtZero: false } }
|
|
182
|
+
: horizontal
|
|
183
|
+
? { x: { ...valueAxis, grace: '32%', ticks: { ...valueAxis.ticks, display: false }, grid: { display: false } }, y: { ...categoryAxis, ticks: { ...categoryAxis.ticks, color: theme.body, font: { size: 14 } } } }
|
|
184
|
+
: { x: categoryAxis, y: valueAxis },
|
|
185
|
+
plugins: {
|
|
186
|
+
legend: { display: false },
|
|
187
|
+
tooltip: { enabled: false, external: sparkline ? undefined : (context) => this._tooltip(context, number) },
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
chart.$csTheme = theme;
|
|
192
|
+
chart.$csSparkline = sparkline;
|
|
193
|
+
if (horizontal && datasets.length === 1) {
|
|
194
|
+
// ranked bars carry their values at their ends, so the value axis is left out
|
|
195
|
+
chart.$csBarValues = number;
|
|
196
|
+
chart.update();
|
|
197
|
+
}
|
|
198
|
+
this._charts.set(canvas, chart);
|
|
199
|
+
|
|
200
|
+
if (!sparkline) {
|
|
201
|
+
this._legend(canvas, config, datasets, bar);
|
|
202
|
+
}
|
|
203
|
+
this._table(canvas, config, number);
|
|
204
|
+
return chart;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// the colors of the theme at the place of the canvas (a dark box inside a light page too)
|
|
208
|
+
static _theme(canvas) {
|
|
209
|
+
const style = getComputedStyle(canvas);
|
|
210
|
+
const get = (name) => this._rgb(style.getPropertyValue(name).trim(), canvas);
|
|
211
|
+
return {
|
|
212
|
+
colors: [1, 2, 3, 4].map((n) => get(`--chart-${n}`)),
|
|
213
|
+
muted: get('--chart-muted'),
|
|
214
|
+
grid: get('--chart-grid'),
|
|
215
|
+
axis: get('--chart-axis'),
|
|
216
|
+
text: get('--bs-secondary-color'),
|
|
217
|
+
body: get('--bs-body-color'),
|
|
218
|
+
surface: get('--chart-surface'),
|
|
219
|
+
font: style.getPropertyValue('--bs-body-font-family').trim(),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// a canvas takes plain colors only: any CSS color (a token with color-mix too) as rgb(); the value of a token read
|
|
224
|
+
// from the computed style has no var() left, so the result depends on the text only and is kept for the page (a
|
|
225
|
+
// probe and a pixel read for every color of every chart forced a style recalculation each time)
|
|
226
|
+
static _rgb(color, context) {
|
|
227
|
+
const cached = this._colors.get(color);
|
|
228
|
+
if (cached) {
|
|
229
|
+
return cached;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const probe = document.createElement('span');
|
|
233
|
+
probe.style.color = color;
|
|
234
|
+
probe.style.display = 'none';
|
|
235
|
+
context.parentElement.append(probe);
|
|
236
|
+
const computed = getComputedStyle(probe).color;
|
|
237
|
+
probe.remove();
|
|
238
|
+
let rgba;
|
|
239
|
+
const plain = computed.match(/^rgba?\((\d+), (\d+), (\d+)(?:, ([\d.]+))?\)$/);
|
|
240
|
+
if (plain) {
|
|
241
|
+
rgba = `rgba(${plain[1]}, ${plain[2]}, ${plain[3]}, ${Number(plain[4] ?? 1).toFixed(3)})`;
|
|
242
|
+
} else {
|
|
243
|
+
// oklch, color(srgb …) and the like: the canvas converts them
|
|
244
|
+
const pixel = (this._pixel ??= document.createElement('canvas').getContext('2d', { willReadFrequently: true }));
|
|
245
|
+
pixel.clearRect(0, 0, 1, 1);
|
|
246
|
+
pixel.fillStyle = computed;
|
|
247
|
+
pixel.fillRect(0, 0, 1, 1);
|
|
248
|
+
const [r, g, b, a] = pixel.getImageData(0, 0, 1, 1).data;
|
|
249
|
+
rgba = `rgba(${r}, ${g}, ${b}, ${(a / 255).toFixed(3)})`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
this._colors.set(color, rgba);
|
|
253
|
+
return rgba;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
static _alpha(color, alpha) {
|
|
257
|
+
return color.replace(/rgba\((\d+), (\d+), (\d+), [\d.]+\)/, `rgba($1, $2, $3, ${alpha})`);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// the tooltip in HTML: the label of the position, then a row per series with its value first
|
|
261
|
+
static _tooltip({ chart, tooltip }, number) {
|
|
262
|
+
const box = chart.canvas.closest('.chart');
|
|
263
|
+
let element = box.querySelector(':scope > .chart-tooltip');
|
|
264
|
+
if (!element) {
|
|
265
|
+
element = document.createElement('div');
|
|
266
|
+
element.className = 'chart-tooltip';
|
|
267
|
+
element.setAttribute('aria-hidden', 'true');
|
|
268
|
+
box.append(element);
|
|
269
|
+
}
|
|
270
|
+
if (tooltip.opacity === 0 || !tooltip.dataPoints?.length) {
|
|
271
|
+
element.classList.remove('show');
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
element.replaceChildren();
|
|
276
|
+
const title = document.createElement('div');
|
|
277
|
+
title.className = 'chart-tooltip-title';
|
|
278
|
+
title.textContent = tooltip.dataPoints[0].label;
|
|
279
|
+
element.append(title);
|
|
280
|
+
for (const point of tooltip.dataPoints) {
|
|
281
|
+
if (point.raw === null || point.raw === undefined) continue;
|
|
282
|
+
const row = document.createElement('div');
|
|
283
|
+
row.className = 'chart-tooltip-row';
|
|
284
|
+
const key = document.createElement('span');
|
|
285
|
+
key.className = 'chart-key';
|
|
286
|
+
key.style.setProperty('--chart-key-color', point.dataset.borderColor || point.dataset.backgroundColor);
|
|
287
|
+
const value = document.createElement('strong');
|
|
288
|
+
value.textContent = number.format(point.raw);
|
|
289
|
+
row.append(key, value);
|
|
290
|
+
if (chart.data.datasets.length > 1 || point.dataset.label) {
|
|
291
|
+
const name = document.createElement('span');
|
|
292
|
+
name.className = 'chart-tooltip-name';
|
|
293
|
+
name.textContent = point.dataset.label;
|
|
294
|
+
row.append(name);
|
|
295
|
+
}
|
|
296
|
+
element.append(row);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// beside the hovered position, kept inside the box
|
|
300
|
+
const x = tooltip.caretX;
|
|
301
|
+
const y = tooltip.caretY;
|
|
302
|
+
element.classList.add('show');
|
|
303
|
+
const width = element.offsetWidth;
|
|
304
|
+
const left = x + 12 + width > box.clientWidth ? x - 12 - width : x + 12;
|
|
305
|
+
element.style.left = `${Math.max(0, left)}px`;
|
|
306
|
+
element.style.top = `${Math.max(0, Math.min(y - element.offsetHeight / 2, box.clientHeight - element.offsetHeight))}px`;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// a legend above the chart for two or more series: a line key for lines, a square for bars
|
|
310
|
+
static _legend(canvas, config, datasets, bar) {
|
|
311
|
+
const box = canvas.closest('.chart');
|
|
312
|
+
box.previousElementSibling?.classList.contains('chart-legend') && box.previousElementSibling.remove();
|
|
313
|
+
if (datasets.length < 2) return;
|
|
314
|
+
const legend = document.createElement('div');
|
|
315
|
+
legend.className = 'chart-legend';
|
|
316
|
+
datasets.forEach((dataset) => {
|
|
317
|
+
const item = document.createElement('span');
|
|
318
|
+
item.className = 'chart-legend-item';
|
|
319
|
+
const key = document.createElement('span');
|
|
320
|
+
key.className = bar ? 'chart-key chart-key-box' : 'chart-key';
|
|
321
|
+
key.style.setProperty('--chart-key-color', dataset.borderColor || dataset.backgroundColor);
|
|
322
|
+
item.append(key, document.createTextNode(dataset.label));
|
|
323
|
+
legend.append(item);
|
|
324
|
+
});
|
|
325
|
+
box.before(legend);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// the values as a table for screen readers (the canvas is only a picture)
|
|
329
|
+
static _table(canvas, config, number) {
|
|
330
|
+
const box = canvas.closest('.chart');
|
|
331
|
+
box.querySelector(':scope > table')?.remove();
|
|
332
|
+
const table = document.createElement('table');
|
|
333
|
+
table.className = 'visually-hidden';
|
|
334
|
+
const caption = document.createElement('caption');
|
|
335
|
+
caption.textContent = canvas.getAttribute('aria-label') || '';
|
|
336
|
+
const head = document.createElement('tr');
|
|
337
|
+
head.append(document.createElement('th'));
|
|
338
|
+
config.series.forEach((series) => {
|
|
339
|
+
const th = document.createElement('th');
|
|
340
|
+
th.textContent = series.name;
|
|
341
|
+
head.append(th);
|
|
342
|
+
});
|
|
343
|
+
table.append(caption, head);
|
|
344
|
+
config.labels.forEach((label, i) => {
|
|
345
|
+
const tr = document.createElement('tr');
|
|
346
|
+
const th = document.createElement('th');
|
|
347
|
+
th.textContent = label;
|
|
348
|
+
tr.append(th);
|
|
349
|
+
config.series.forEach((series) => {
|
|
350
|
+
const td = document.createElement('td');
|
|
351
|
+
td.textContent = series.data[i] === null || series.data[i] === undefined ? '–' : number.format(series.data[i]);
|
|
352
|
+
tr.append(td);
|
|
353
|
+
});
|
|
354
|
+
table.append(tr);
|
|
355
|
+
});
|
|
356
|
+
canvas.setAttribute('role', 'img');
|
|
357
|
+
box.append(table);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Datepicker: a calendar of Vanilla Calendar Pro under an input with data-bs-toggle="datepicker", configured like the
|
|
3
|
+
* datepicker of Bootstrap 6 (the same data attributes). The value of the input is an ISO date (2026-11-07), which a
|
|
4
|
+
* server understands; data-bs-date-format="locale" writes it in the language of the page instead (for display only).
|
|
5
|
+
* A choice fires input and change on the input. An element with data-bs-inline="true" shows the calendar in the page,
|
|
6
|
+
* with an <input type="hidden"> inside for the value.
|
|
7
|
+
*
|
|
8
|
+
* Attributes: data-bs-date-min, data-bs-date-max (ISO dates or "today"), data-bs-selection-mode ("single", "multiple",
|
|
9
|
+
* "multiple-ranged"), data-bs-display-months-count, data-bs-first-weekday (1 = Monday), data-bs-locale (the lang of the
|
|
10
|
+
* page by default), data-bs-date-format ("iso" or "locale"), data-bs-inline, data-bs-selection-time-mode (24 or 12: a time
|
|
11
|
+
* under the calendar, the value is then "2026-11-07 14:30"; the calendar stays open after a click on a day).
|
|
12
|
+
*
|
|
13
|
+
* <input type="text" class="form-control" data-bs-toggle="datepicker" data-bs-date-min="today" autocomplete="off">
|
|
14
|
+
*/
|
|
15
|
+
import { Calendar, months, time as timeExtension } from 'vanilla-calendar-pro';
|
|
16
|
+
|
|
17
|
+
const SELECTOR = '[data-bs-toggle="datepicker"]';
|
|
18
|
+
|
|
19
|
+
export class Datepicker {
|
|
20
|
+
static options = {
|
|
21
|
+
firstWeekday: 1,
|
|
22
|
+
locale: null,
|
|
23
|
+
dateFormat: 'iso',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static _calendars = new WeakMap();
|
|
27
|
+
static _initialized = false;
|
|
28
|
+
|
|
29
|
+
/** Starts the datepickers; the options are defaults for all of them, the data attributes of an input win. */
|
|
30
|
+
static init(options = {}) {
|
|
31
|
+
this.options = { ...this.options, ...options };
|
|
32
|
+
document.querySelectorAll(`${SELECTOR}[data-bs-inline="true"]`).forEach((element) => this.get(element));
|
|
33
|
+
if (this._initialized) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this._initialized = true;
|
|
38
|
+
document.addEventListener('focusin', (event) => {
|
|
39
|
+
const input = event.target.closest?.(SELECTOR);
|
|
40
|
+
// the first focus creates the calendar and opens it, later ones are opened by the calendar itself (it
|
|
41
|
+
// knows when the focus only returns to the input after a choice)
|
|
42
|
+
if (input && input.tagName === 'INPUT' && !input.disabled && !input.readOnly && !this._calendars.has(input)) {
|
|
43
|
+
this.get(input).show();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// a focus or a press outside closes the calendar (Vanilla Calendar Pro closes it on a click only)
|
|
47
|
+
const outside = (event) => {
|
|
48
|
+
document.querySelectorAll('[data-vc="calendar"][data-vc-input]:not([data-vc-calendar-hidden])').forEach((element) => {
|
|
49
|
+
const input = element.__compostrapInput;
|
|
50
|
+
if (input && !input.contains(event.target) && !element.contains(event.target)) {
|
|
51
|
+
this._calendars.get(input)?.hide();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
document.addEventListener('focusin', outside);
|
|
56
|
+
document.addEventListener('pointerdown', outside);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The calendar of an input (or of an inline element), created on first use. */
|
|
60
|
+
static get(element) {
|
|
61
|
+
let calendar = this._calendars.get(element);
|
|
62
|
+
if (!calendar) {
|
|
63
|
+
calendar = this._create(element);
|
|
64
|
+
this._calendars.set(element, calendar);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return calendar;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static _create(element) {
|
|
71
|
+
const data = element.dataset;
|
|
72
|
+
const inline = data.bsInline === 'true';
|
|
73
|
+
const input = element.tagName === 'INPUT' ? element : element.querySelector('input');
|
|
74
|
+
const mode = data.bsSelectionMode || 'single';
|
|
75
|
+
const format = data.bsDateFormat || this.options.dateFormat;
|
|
76
|
+
const locale = data.bsLocale || this.options.locale || document.documentElement.lang || 'default';
|
|
77
|
+
const count = Number(data.bsDisplayMonthsCount) || 1;
|
|
78
|
+
const timeMode = [12, 24].includes(Number(data.bsSelectionTimeMode)) ? Number(data.bsSelectionTimeMode) : false;
|
|
79
|
+
const value = input?.dataset.bsValue || input?.value || '';
|
|
80
|
+
const selected = this._parse(value);
|
|
81
|
+
const time = timeMode ? value.match(/\d{1,2}:\d{2}(?:\s?[AP]M)?/i)?.[0] : null;
|
|
82
|
+
|
|
83
|
+
// writes the chosen dates (and the time) into the input
|
|
84
|
+
const write = (self) => {
|
|
85
|
+
const dates = [...self.context.selectedDates];
|
|
86
|
+
if (input) {
|
|
87
|
+
input.dataset.bsValue = dates.join(',');
|
|
88
|
+
input.value = this._format(dates, mode, format, locale) + (timeMode && dates.length ? ' ' + self.context.selectedTime : '');
|
|
89
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
90
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return dates;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const calendar = new Calendar(element, {
|
|
97
|
+
extensions: timeMode ? [months, timeExtension] : [months],
|
|
98
|
+
inputMode: !inline,
|
|
99
|
+
openOnFocus: true,
|
|
100
|
+
positionToInput: 'left',
|
|
101
|
+
firstWeekday: Number(data.bsFirstWeekday ?? this.options.firstWeekday),
|
|
102
|
+
locale,
|
|
103
|
+
selectionDatesMode: mode,
|
|
104
|
+
selectedDates: selected,
|
|
105
|
+
displayMonthsCount: count,
|
|
106
|
+
type: count > 1 ? 'multiple' : 'default',
|
|
107
|
+
themeAttrDetect: 'html[data-bs-theme]',
|
|
108
|
+
...(timeMode ? { selectionTimeMode: timeMode } : {}),
|
|
109
|
+
...(time ? { selectedTime: time } : {}),
|
|
110
|
+
...(selected[0] ? { selectedMonth: Number(selected[0].slice(5, 7)) - 1, selectedYear: Number(selected[0].slice(0, 4)) } : {}),
|
|
111
|
+
...(data.bsDateMin ? { dateMin: data.bsDateMin } : {}),
|
|
112
|
+
...(data.bsDateMax ? { dateMax: data.bsDateMax } : {}),
|
|
113
|
+
onInit: (self) => {
|
|
114
|
+
self.context.mainElement.__compostrapInput = element;
|
|
115
|
+
// the calendar stands at the end of the page; in a modal or an offcanvas Bootstrap keeps the focus
|
|
116
|
+
// inside the dialog and took it back from the calendar (which closed before a click reached it), so
|
|
117
|
+
// the focus in the calendar is kept from the focus trap
|
|
118
|
+
self.context.mainElement.addEventListener('focusin', (event) => {
|
|
119
|
+
if (element.closest('.modal, .offcanvas')) {
|
|
120
|
+
event.stopPropagation();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
onClickDate: (self) => {
|
|
125
|
+
const dates = write(self);
|
|
126
|
+
// with a time the calendar stays open, so the time can be set after the day
|
|
127
|
+
if (!inline && !timeMode && ((mode === 'single' && dates.length) || (mode === 'multiple-ranged' && dates.length > 1))) {
|
|
128
|
+
setTimeout(() => self.hide(), 100);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
onChangeTime: (self) => {
|
|
132
|
+
if (self.context.selectedDates.length) {
|
|
133
|
+
write(self);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
calendar.init();
|
|
138
|
+
return calendar;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ISO dates of a value: "2026-11-07", "2026-11-07,2026-11-09" or "2026-11-07 – 2026-11-09"
|
|
142
|
+
static _parse(value) {
|
|
143
|
+
return value.match(/\d{4}-\d{2}-\d{2}/g) || [];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static _format(dates, mode, format, locale) {
|
|
147
|
+
const text = (date) => {
|
|
148
|
+
if (format !== 'locale') return date;
|
|
149
|
+
const [y, m, d] = date.split('-').map(Number);
|
|
150
|
+
return new Date(y, m - 1, d).toLocaleDateString(locale === 'default' ? undefined : locale);
|
|
151
|
+
};
|
|
152
|
+
return dates.map(text).join(mode === 'multiple-ranged' ? ' – ' : ', ');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dialogs: a modal and an offcanvas of Bootstrap are not closed by a click outside of them, so a form in one is
|
|
3
|
+
* not lost by a slip of the mouse; they are closed by their cross, their Cancel button (data-bs-dismiss) and Esc.
|
|
4
|
+
* It changes the default `backdrop` option of Bootstrap to 'static', so it holds for every dialog created after
|
|
5
|
+
* init(), also for those loaded later (AJAX snippets) or opened from a script.
|
|
6
|
+
*
|
|
7
|
+
* A dialog that should close by a click outside says so itself (a search, a menu):
|
|
8
|
+
*
|
|
9
|
+
* <div class="modal fade" data-bs-backdrop="true">…</div>
|
|
10
|
+
*
|
|
11
|
+
* Dialogs.init() takes Bootstrap from `window.bootstrap`; a project that imports it as a module passes it:
|
|
12
|
+
*
|
|
13
|
+
* import { Modal, Offcanvas } from 'bootstrap';
|
|
14
|
+
* Dialogs.init({ Modal, Offcanvas });
|
|
15
|
+
*/
|
|
16
|
+
export class Dialogs {
|
|
17
|
+
static init(bootstrap = globalThis.bootstrap) {
|
|
18
|
+
for (const component of [bootstrap?.Modal, bootstrap?.Offcanvas]) {
|
|
19
|
+
// Default is the object every new instance takes its options from
|
|
20
|
+
if (component?.Default) {
|
|
21
|
+
component.Default.backdrop = 'static';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The script of a dropzone (.dropzone with a .dropzone-input): highlights the area while files are dragged over it
|
|
3
|
+
* (class is-dragover), writes the names of the chosen files into [data-dropzone-files] and, with the attribute
|
|
4
|
+
* data-dropzone-submit on the input, submits its form at once (an AJAX form of Naja catches the submit event).
|
|
5
|
+
* Call init() again after new content is loaded, a dropzone is bound only once.
|
|
6
|
+
*/
|
|
7
|
+
export class DropzoneInput {
|
|
8
|
+
static init(root = document) {
|
|
9
|
+
root.querySelectorAll('.dropzone').forEach((zone) => {
|
|
10
|
+
const input = zone.querySelector('.dropzone-input');
|
|
11
|
+
if (!input || zone.dataset.dropzoneInitialized === 'true') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
zone.dataset.dropzoneInitialized = 'true';
|
|
16
|
+
const files = zone.querySelector('[data-dropzone-files]');
|
|
17
|
+
const highlight = (on) => zone.classList.toggle('is-dragover', on);
|
|
18
|
+
|
|
19
|
+
input.addEventListener('dragenter', () => highlight(true));
|
|
20
|
+
input.addEventListener('dragover', () => highlight(true));
|
|
21
|
+
input.addEventListener('dragleave', () => highlight(false));
|
|
22
|
+
input.addEventListener('drop', () => highlight(false));
|
|
23
|
+
|
|
24
|
+
input.addEventListener('change', () => {
|
|
25
|
+
if (files) {
|
|
26
|
+
files.textContent = [...input.files].map((file) => file.name).join(', ');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (input.files.length > 0 && input.hasAttribute('data-dropzone-submit') && input.form) {
|
|
30
|
+
input.form.requestSubmit();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/js/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Sidebar } from './sidebar.js';
|
|
2
|
+
import { SidebarMenu } from './sidebar-menu.js';
|
|
3
|
+
import { ThemeSwitcher } from './theme-switcher.js';
|
|
4
|
+
import { DropzoneInput } from './dropzone.js';
|
|
5
|
+
import { Lightbox } from './lightbox.js';
|
|
6
|
+
import { Strength } from './strength.js';
|
|
7
|
+
import { PasswordToggle } from './password-toggle.js';
|
|
8
|
+
import { NumberInput } from './number-input.js';
|
|
9
|
+
import { OtpInput } from './otp-input.js';
|
|
10
|
+
import { RowSelection } from './selection.js';
|
|
11
|
+
import { Spinner } from './spinner.js';
|
|
12
|
+
import { Dialogs } from './dialogs.js';
|
|
13
|
+
import { CssTooltip } from './tooltip.js';
|
|
14
|
+
|
|
15
|
+
export class SidebarSkeleton {
|
|
16
|
+
static init() {
|
|
17
|
+
Sidebar.init();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class SidebarMenuApp {
|
|
22
|
+
static init() {
|
|
23
|
+
SidebarMenu.init();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { Sidebar, SidebarMenu, ThemeSwitcher, DropzoneInput, Lightbox, Strength, PasswordToggle, NumberInput, OtpInput, RowSelection, Spinner, Dialogs, CssTooltip };
|
|
28
|
+
|
|
29
|
+
// Datepicker is imported from 'compostrap/datepicker' only: it needs the optional vanilla-calendar-pro
|