@kashi-ui/elements 2.22.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/base.js +4 -0
- package/dist/buttons.d.ts +82 -0
- package/dist/buttons.js +505 -0
- package/dist/cards.d.ts +30 -0
- package/dist/cards.js +183 -0
- package/dist/cdn/{appointment-wMGBoHw9.js → appointment-DOXBUwIU.js} +1 -1
- package/dist/cdn/{base-Dg1Mb8Jk.js → base-D4tCOysh.js} +1 -1
- package/dist/cdn/{basic-B5ZxgagA.js → basic-DuY4RslZ.js} +1 -1
- package/dist/cdn/buttons-BaK6bx3w.js +1 -0
- package/dist/cdn/calendar-BulPeVAJ.js +16 -0
- package/dist/cdn/card-BKiwJF34.js +1 -0
- package/dist/cdn/cards-DKarXHsC.js +1 -0
- package/dist/cdn/charts-ETYOAJyB.js +1 -0
- package/dist/cdn/chat-D5ZIMnNp.js +4 -0
- package/dist/cdn/choice-DBvC2Puo.js +1 -0
- package/dist/cdn/{combobox-CBT7yp94.js → combobox-BGuPAAt3.js} +1 -1
- package/dist/cdn/{commerce-CsyixnVK.js → commerce-SzWdpWJG.js} +1 -1
- package/dist/cdn/content-BgfBfy8j.js +1 -0
- package/dist/cdn/controls--OMZkJYe.js +1 -0
- package/dist/cdn/display-BfYWAjNu.js +1 -0
- package/dist/cdn/{fields-Cx84-qz1.js → fields-B-jTUQiI.js} +1 -1
- package/dist/cdn/forms-DgRiYmdV.js +1 -0
- package/dist/cdn/{holidays-DO82gXhM.js → holidays-Cu6IfbTL.js} +1 -1
- package/dist/cdn/hours-CeiVqPKD.js +1 -0
- package/dist/cdn/inputs-BkJ70Xkc.js +1 -0
- package/dist/cdn/kashi-elements.js +1 -1
- package/dist/cdn/legal-id-Mt8FX0fV.js +1 -0
- package/dist/cdn/{map-DlpA916P.js → map-TfSt3CjL.js} +2 -2
- package/dist/cdn/media-BRBINvzU.js +1 -0
- package/dist/cdn/{menu-CqTvk8Ok.js → menu-DTNVFXrb.js} +1 -1
- package/dist/cdn/money-CjGI2VIQ.js +1 -0
- package/dist/cdn/{nav-BHv7H1Fy.js → nav-CT5RVOzy.js} +1 -1
- package/dist/cdn/{overlay-BIEEJ4Sh.js → overlay-CS8piW6X.js} +1 -1
- package/dist/cdn/parts-5fVaWtRe.js +1 -0
- package/dist/cdn/pickers-BwDRsDRo.js +1 -0
- package/dist/cdn/relative-OC1fV3Xh.js +1 -0
- package/dist/cdn/rich-text-CS6xEim6.js +1 -0
- package/dist/cdn/sheets-eVMx4d-5.js +1 -0
- package/dist/cdn/{table-B5XwDDS9.js → table-tgB4iwcM.js} +1 -1
- package/dist/cdn/{text-Bml-pVjo.js → text-C6fzEBBh.js} +1 -1
- package/dist/cdn/{time-DrXgFeQy.js → time-CkqqUKJv.js} +1 -1
- package/dist/cdn/{time-BQsTSvql.js → time-CwOYrtK-.js} +1 -1
- package/dist/cdn/validate-Dr2f6i6s.js +1 -0
- package/dist/cdn/work-DoNAKgVU.js +1 -0
- package/dist/cdn.js +11 -0
- package/dist/chat.d.ts +127 -0
- package/dist/chat.js +734 -0
- package/dist/choice.d.ts +98 -0
- package/dist/choice.js +597 -0
- package/dist/content.d.ts +164 -0
- package/dist/content.js +726 -0
- package/dist/hours.d.ts +29 -0
- package/dist/hours.js +179 -0
- package/dist/index.d.ts +64 -2
- package/dist/index.js +22 -1
- package/dist/manifest.json +849 -2
- package/dist/media.d.ts +51 -0
- package/dist/media.js +363 -0
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.js +42 -11
- package/dist/parts.d.ts +31 -0
- package/dist/parts.js +114 -0
- package/dist/qr.d.ts +7 -0
- package/dist/qr.js +271 -0
- package/dist/rich-text.d.ts +40 -0
- package/dist/rich-text.js +375 -0
- package/dist/sheets.d.ts +128 -0
- package/dist/sheets.js +661 -0
- package/dist/validate.d.ts +40 -0
- package/dist/validate.js +224 -0
- package/dist/work.d.ts +117 -0
- package/dist/work.js +895 -0
- package/package.json +4 -4
- package/dist/cdn/calendar-Cjp5Rqer.js +0 -16
- package/dist/cdn/charts-DvQ4OwdS.js +0 -1
- package/dist/cdn/controls-B-s4IF_4.js +0 -1
- package/dist/cdn/display-MorJMDEF.js +0 -1
- package/dist/cdn/forms-CQeP9iiW.js +0 -1
- package/dist/cdn/inputs-Bqcs9Xy7.js +0 -1
- package/dist/cdn/pickers-BT9VPT4o.js +0 -1
package/dist/content.js
ADDED
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
// عنصرهای نمایشی: نشان، آواتار، جداکننده، اسکلت، کارت، حالت خالی، کارت شاخص، هشدار، سنجه، نوار پیشرفت، خط زمانی و مراحل.
|
|
2
|
+
// همان کلاسهای k-* نسخهٔ React؛ محتوای خود کاربر یک بار در ساختار چیده میشود و تغییر ویژگیها همانجا اعمال میشود.
|
|
3
|
+
import { formatNumber, formatRelative } from "@kashi-ui/persian";
|
|
4
|
+
import { afterParse, bool, define, digitsOf, esc, HTMLBase, ICONS, lang, msg, num } from "./base.js";
|
|
5
|
+
import { cx, hasContent, icon, numAttr, takeSlot, toDate, unslotted } from "./parts.js";
|
|
6
|
+
/** پایهٔ عنصرهایی که فرزندانشان را یک بار در ساختار کاشی میچینند */
|
|
7
|
+
class Wrap extends HTMLBase {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.built = false;
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
afterParse(() => {
|
|
14
|
+
if (!this.isConnected)
|
|
15
|
+
return;
|
|
16
|
+
if (!this.built) {
|
|
17
|
+
this.built = true;
|
|
18
|
+
this.build();
|
|
19
|
+
}
|
|
20
|
+
this.update();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
attributeChangedCallback(_n, old, next) {
|
|
24
|
+
if (this.built && old !== next)
|
|
25
|
+
this.update();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const X = '<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="m6 6 8 8M14 6l-8 8"/></svg>';
|
|
29
|
+
// ---------- نشان ----------
|
|
30
|
+
/**
|
|
31
|
+
* نشان کوچک وضعیت یا دسته: tone، variant (soft، solid، outline)، size، dot و square.
|
|
32
|
+
* با removable دکمهٔ حذف میگیرد؛ رویداد kashi-remove قابل لغو است و بدون لغو خود نشان حذف میشود.
|
|
33
|
+
*/
|
|
34
|
+
export class KashiBadge extends Wrap {
|
|
35
|
+
build() {
|
|
36
|
+
const iconEl = takeSlot(this, "icon")[0];
|
|
37
|
+
this.box = document.createElement("span");
|
|
38
|
+
if (iconEl) {
|
|
39
|
+
const s = document.createElement("span");
|
|
40
|
+
s.className = "k-badge__icon";
|
|
41
|
+
s.setAttribute("aria-hidden", "true");
|
|
42
|
+
s.append(iconEl);
|
|
43
|
+
this.box.append(s);
|
|
44
|
+
}
|
|
45
|
+
this.text = document.createElement("span");
|
|
46
|
+
this.text.style.display = "contents";
|
|
47
|
+
this.text.append(...this.childNodes);
|
|
48
|
+
this.box.append(this.text);
|
|
49
|
+
this.append(this.box);
|
|
50
|
+
this.box.addEventListener("click", (e) => {
|
|
51
|
+
if (!e.target.closest(".k-badge__remove"))
|
|
52
|
+
return;
|
|
53
|
+
const ev = new CustomEvent("kashi-remove", { bubbles: true, cancelable: true, detail: { value: this.text.textContent?.trim() ?? "" } });
|
|
54
|
+
if (this.dispatchEvent(ev))
|
|
55
|
+
this.remove();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
update() {
|
|
59
|
+
const tone = this.getAttribute("tone") ?? "neutral";
|
|
60
|
+
const variant = this.getAttribute("variant") ?? "soft";
|
|
61
|
+
const size = this.getAttribute("size") ?? "md";
|
|
62
|
+
const removable = bool(this, "removable");
|
|
63
|
+
this.box.className = cx("k-badge", tone !== "neutral" && `k-badge--${tone}`, variant !== "soft" && `k-badge--${variant}`, size !== "md" && `k-badge--${size}`, bool(this, "square") && "k-badge--square", removable && "k-badge--removable");
|
|
64
|
+
this.box.dataset.tone = tone;
|
|
65
|
+
this.box.dataset.variant = variant;
|
|
66
|
+
const dot = this.box.querySelector(":scope > .k-badge__dot");
|
|
67
|
+
if (bool(this, "dot") && !dot)
|
|
68
|
+
this.box.insertAdjacentHTML("afterbegin", '<span class="k-badge__dot" aria-hidden="true"></span>');
|
|
69
|
+
else if (!bool(this, "dot"))
|
|
70
|
+
dot?.remove();
|
|
71
|
+
const btn = this.box.querySelector(":scope > .k-badge__remove");
|
|
72
|
+
if (removable) {
|
|
73
|
+
const text = this.text.textContent?.trim() ?? "";
|
|
74
|
+
const label = this.getAttribute("remove-label") ?? (text ? msg().common.remove(text) : msg().common.removeShort);
|
|
75
|
+
if (btn)
|
|
76
|
+
btn.setAttribute("aria-label", label);
|
|
77
|
+
else
|
|
78
|
+
this.box.insertAdjacentHTML("beforeend", `<button type="button" class="k-badge__remove" aria-label="${esc(label)}">${X}</button>`);
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
btn?.remove();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
KashiBadge.observedAttributes = ["tone", "variant", "size", "dot", "square", "removable", "remove-label"];
|
|
85
|
+
// ---------- آواتار ----------
|
|
86
|
+
const TONES = ["brand", "info", "success", "warning", "error"];
|
|
87
|
+
/** حروف اول دو کلمهٔ اول؛ با نیمفاصله تا حروف فارسی به هم نچسبند */
|
|
88
|
+
export const initials = (name, max = 2) => name.trim().split(/\s+/).slice(0, max).map((w) => w[0] ?? "").join("").toUpperCase();
|
|
89
|
+
/** رنگ ثابت از روی نام */
|
|
90
|
+
export function autoTone(name) {
|
|
91
|
+
let h = 0;
|
|
92
|
+
for (const ch of name.trim())
|
|
93
|
+
h = (h * 31 + ch.codePointAt(0)) >>> 0;
|
|
94
|
+
return TONES[h % TONES.length];
|
|
95
|
+
}
|
|
96
|
+
/** تصویر یا حروف اول شخص؛ با status نشان آنلاین، و color="auto" رنگ ثابت از روی نام */
|
|
97
|
+
export class KashiAvatar extends HTMLBase {
|
|
98
|
+
constructor() {
|
|
99
|
+
super(...arguments);
|
|
100
|
+
this.failed = false;
|
|
101
|
+
}
|
|
102
|
+
connectedCallback() {
|
|
103
|
+
this.render();
|
|
104
|
+
}
|
|
105
|
+
attributeChangedCallback(n, old, next) {
|
|
106
|
+
if (old === next || !this.isConnected)
|
|
107
|
+
return;
|
|
108
|
+
if (n === "src")
|
|
109
|
+
this.failed = false;
|
|
110
|
+
this.render();
|
|
111
|
+
}
|
|
112
|
+
render() {
|
|
113
|
+
const name = this.getAttribute("name") ?? "";
|
|
114
|
+
const size = this.getAttribute("size") ?? "md";
|
|
115
|
+
const color = this.getAttribute("color");
|
|
116
|
+
const tone = color === "auto" ? autoTone(name) : color ?? (bool(this, "brand") ? "brand" : "neutral");
|
|
117
|
+
const status = this.getAttribute("status");
|
|
118
|
+
const statusText = status ? this.getAttribute("status-label") ?? msg().avatar[status] : null;
|
|
119
|
+
const src = this.getAttribute("src");
|
|
120
|
+
const label = statusText ? `${name}${msg().common.list}${statusText}` : name;
|
|
121
|
+
const inner = src && !this.failed
|
|
122
|
+
? `<img class="k-avatar__image" src="${esc(src)}" alt="">`
|
|
123
|
+
: `<span aria-hidden="true">${esc(initials(name, size === "xs" || size === "sm" ? 1 : 2))}</span>`;
|
|
124
|
+
this.innerHTML = `<span role="img" aria-label="${esc(label)}" data-tone="${tone}" class="${cx("k-avatar", size !== "md" && `k-avatar--${size}`, bool(this, "square") && "k-avatar--square", tone !== "neutral" && `k-avatar--${tone}`)}">${inner}${status ? `<span class="k-avatar__status k-avatar__status--${status}" aria-hidden="true"></span>` : ""}</span>`;
|
|
125
|
+
this.querySelector("img")?.addEventListener("error", () => {
|
|
126
|
+
this.failed = true;
|
|
127
|
+
this.render();
|
|
128
|
+
}, { once: true });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
KashiAvatar.observedAttributes = ["name", "src", "size", "square", "brand", "color", "status", "status-label"];
|
|
132
|
+
/** چند آواتار روی هم؛ با max بقیه به شکل «+۳» */
|
|
133
|
+
export class KashiAvatarGroup extends Wrap {
|
|
134
|
+
build() {
|
|
135
|
+
this.box = document.createElement("div");
|
|
136
|
+
this.box.setAttribute("role", "group");
|
|
137
|
+
this.box.className = "k-avatar-group";
|
|
138
|
+
this.box.append(...this.childNodes);
|
|
139
|
+
this.append(this.box);
|
|
140
|
+
}
|
|
141
|
+
update() {
|
|
142
|
+
this.box.querySelector(":scope > [data-more]")?.remove();
|
|
143
|
+
const items = [...this.box.children].filter((c) => c.tagName === "KASHI-AVATAR" || c.classList.contains("k-avatar"));
|
|
144
|
+
const max = numAttr(this, "max");
|
|
145
|
+
items.forEach((it, i) => (it.hidden = !!max && i >= max));
|
|
146
|
+
const extra = max ? Math.max(0, items.length - max) : 0;
|
|
147
|
+
if (!extra)
|
|
148
|
+
return;
|
|
149
|
+
const size = this.getAttribute("size") ?? "md";
|
|
150
|
+
const label = this.getAttribute("more-label")?.replace("{n}", num(this, extra)) ?? msg().avatar.more(num(this, extra));
|
|
151
|
+
this.box.insertAdjacentHTML("beforeend", `<span data-more role="img" aria-label="${esc(label)}" class="${cx("k-avatar", size !== "md" && `k-avatar--${size}`)}"><span aria-hidden="true">+${num(this, extra)}</span></span>`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
KashiAvatarGroup.observedAttributes = ["max", "size", "more-label"];
|
|
155
|
+
// ---------- جداکننده ----------
|
|
156
|
+
/** خط جداکننده، با label متن وسط (مثل «یا») و vertical برای ستون */
|
|
157
|
+
export class KashiDivider extends HTMLBase {
|
|
158
|
+
connectedCallback() {
|
|
159
|
+
this.render();
|
|
160
|
+
}
|
|
161
|
+
attributeChangedCallback() {
|
|
162
|
+
if (this.isConnected)
|
|
163
|
+
this.render();
|
|
164
|
+
}
|
|
165
|
+
render() {
|
|
166
|
+
const label = this.getAttribute("label");
|
|
167
|
+
const vertical = bool(this, "vertical");
|
|
168
|
+
this.innerHTML = `<div role="separator"${vertical ? ' aria-orientation="vertical"' : ""} class="${cx("k-divider", vertical && "k-divider--vertical")}">${label ? `<span>${esc(label)}</span>` : ""}</div>`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
KashiDivider.observedAttributes = ["label", "vertical"];
|
|
172
|
+
// ---------- اسکلت ----------
|
|
173
|
+
const size = (v) => (v === null ? null : /^\d+(\.\d+)?$/.test(v) ? `${v}px` : v);
|
|
174
|
+
/** جای خالی هنگام بارگذاری؛ width، height، circle و lines. روی ظرف والد aria-busy="true" بگذارید */
|
|
175
|
+
export class KashiSkeleton extends HTMLBase {
|
|
176
|
+
connectedCallback() {
|
|
177
|
+
this.render();
|
|
178
|
+
}
|
|
179
|
+
attributeChangedCallback() {
|
|
180
|
+
if (this.isConnected)
|
|
181
|
+
this.render();
|
|
182
|
+
}
|
|
183
|
+
render() {
|
|
184
|
+
const w = size(this.getAttribute("width"));
|
|
185
|
+
const circle = bool(this, "circle");
|
|
186
|
+
const h = size(this.getAttribute("height")) ?? (circle ? w : null);
|
|
187
|
+
const style = [w && `--k-skeleton-width: ${w}`, h && `--k-skeleton-height: ${h}`].filter(Boolean).join("; ");
|
|
188
|
+
const st = style ? ` style="${esc(style)}"` : "";
|
|
189
|
+
const lines = numAttr(this, "lines", 0);
|
|
190
|
+
this.innerHTML = lines > 0
|
|
191
|
+
? `<span class="k-skeleton-group" aria-hidden="true"${st}>${'<span class="k-skeleton k-skeleton--text"></span>'.repeat(Math.min(50, lines))}</span>`
|
|
192
|
+
: `<span class="${cx("k-skeleton", circle && "k-skeleton--circle")}" aria-hidden="true"${st}></span>`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
KashiSkeleton.observedAttributes = ["width", "height", "circle", "lines"];
|
|
196
|
+
// ---------- کارت ----------
|
|
197
|
+
/**
|
|
198
|
+
* کارت با heading و description؛ عنصر slot="media" تصویر بالای کارت، slot="actions" دکمههای سربرگ و slot="footer" پایین کارت.
|
|
199
|
+
* بقیهٔ محتوا بدنهٔ کارت است. variant، padding، flat و interactive مثل React.
|
|
200
|
+
*/
|
|
201
|
+
export class KashiCard extends Wrap {
|
|
202
|
+
build() {
|
|
203
|
+
const media = takeSlot(this, "media");
|
|
204
|
+
const actions = takeSlot(this, "actions");
|
|
205
|
+
const footer = takeSlot(this, "footer");
|
|
206
|
+
const body = unslotted(this);
|
|
207
|
+
this.box = document.createElement("article");
|
|
208
|
+
for (const m of media) {
|
|
209
|
+
m.classList.add("k-card__media");
|
|
210
|
+
if (m instanceof HTMLImageElement && !m.style.aspectRatio)
|
|
211
|
+
m.style.aspectRatio = "16 / 9";
|
|
212
|
+
this.box.append(m);
|
|
213
|
+
}
|
|
214
|
+
this.header = document.createElement("header");
|
|
215
|
+
this.header.innerHTML = `<div class="k-card__heading"></div>`;
|
|
216
|
+
if (actions.length) {
|
|
217
|
+
const a = document.createElement("div");
|
|
218
|
+
a.className = "k-card__actions";
|
|
219
|
+
a.append(...actions);
|
|
220
|
+
this.header.append(a);
|
|
221
|
+
}
|
|
222
|
+
this.box.append(this.header);
|
|
223
|
+
if (hasContent(body)) {
|
|
224
|
+
const b = document.createElement("div");
|
|
225
|
+
b.className = "k-card__body";
|
|
226
|
+
b.append(...body);
|
|
227
|
+
this.box.append(b);
|
|
228
|
+
}
|
|
229
|
+
if (footer.length) {
|
|
230
|
+
const f = document.createElement("footer");
|
|
231
|
+
f.className = "k-card__footer";
|
|
232
|
+
f.append(...footer);
|
|
233
|
+
this.box.append(f);
|
|
234
|
+
}
|
|
235
|
+
this.append(this.box);
|
|
236
|
+
}
|
|
237
|
+
update() {
|
|
238
|
+
const variant = this.getAttribute("variant") ?? "outlined";
|
|
239
|
+
const pad = this.getAttribute("padding") ?? "md";
|
|
240
|
+
this.box.className = cx("k-card", bool(this, "flat") && "k-card--flat", bool(this, "interactive") && "k-card--interactive", variant !== "outlined" && `k-card--${variant}`, pad !== "md" && `k-card--pad-${pad}`);
|
|
241
|
+
this.box.dataset.variant = variant;
|
|
242
|
+
const heading = this.getAttribute("heading");
|
|
243
|
+
const desc = this.getAttribute("description");
|
|
244
|
+
const hasActions = !!this.header.querySelector(".k-card__actions");
|
|
245
|
+
this.header.className = cx("k-card__header", hasActions && "k-card__header--actions");
|
|
246
|
+
this.header.hidden = !heading && !desc && !hasActions;
|
|
247
|
+
const level = Math.min(6, Math.max(1, numAttr(this, "heading-level", 3)));
|
|
248
|
+
const holder = this.header.querySelector(".k-card__heading");
|
|
249
|
+
holder.innerHTML = `${heading ? `<h${level} class="k-card__title">${esc(heading)}</h${level}>` : ""}${desc ? `<p class="k-card__description">${esc(desc)}</p>` : ""}`;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
KashiCard.observedAttributes = ["heading", "description", "heading-level", "variant", "padding", "flat", "interactive"];
|
|
253
|
+
// ---------- حالت خالی ----------
|
|
254
|
+
const P = (d) => icon(d, 1.5);
|
|
255
|
+
const EMPTY_ICONS = {
|
|
256
|
+
noData: P('<path d="M7.25 2.75h5.5c3.6 0 4.5.9 4.5 4.5v5.5c0 3.6-.9 4.5-4.5 4.5h-5.5c-3.6 0-4.5-.9-4.5-4.5v-5.5c0-3.6.9-4.5 4.5-4.5Z"/><path d="M2.75 10.75h3.1c.55 0 1 .3 1.25.75l.5.95c.25.45.7.75 1.25.75h2.3c.55 0 1-.3 1.25-.75l.5-.95c.25-.45.7-.75 1.25-.75h3.1"/>'),
|
|
257
|
+
noResults: P('<circle cx="9.1" cy="9.1" r="6.2"/><path d="m14.9 14.9 2.3 2.3M7.2 7.2l3.8 3.8M11 7.2l-3.8 3.8"/>'),
|
|
258
|
+
error: P('<path d="M8.33 3.9c.74-1.3 2.6-1.3 3.34 0l5.6 9.75c.74 1.3-.2 2.85-1.67 2.85H4.4c-1.48 0-2.41-1.56-1.67-2.85Z"/><path d="M10 7.9v3.1M10 13.6v.01"/>'),
|
|
259
|
+
offline: P('<path d="M2.75 7.6a10.5 10.5 0 0 1 14.5 0M5.2 10.3a7 7 0 0 1 9.6 0M7.7 12.95a3.5 3.5 0 0 1 4.6 0M10 15.75v.01"/><path d="m3 3 14 14"/>'),
|
|
260
|
+
noAccess: P('<path d="M7.25 8.25h5.5c2.6 0 3.25.65 3.25 3.25v2.75c0 2.6-.65 3.25-3.25 3.25h-5.5C4.65 17.5 4 16.85 4 14.25V11.5c0-2.6.65-3.25 3.25-3.25Z"/><path d="M6.9 8.3V6.4a3.1 3.1 0 0 1 6.2 0v1.9M10 11.6v2.2"/>'),
|
|
261
|
+
done: P('<circle cx="10" cy="10" r="7.25"/><path d="m6.75 10.1 2.2 2.2 4.3-4.5"/>'),
|
|
262
|
+
};
|
|
263
|
+
const PRESETS = ["noData", "noResults", "error", "offline", "noAccess", "done"];
|
|
264
|
+
/** «no-data» و «noData» هر دو پذیرفته میشوند */
|
|
265
|
+
const presetOf = (v) => {
|
|
266
|
+
if (!v)
|
|
267
|
+
return null;
|
|
268
|
+
const k = v.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
269
|
+
return PRESETS.includes(k) ? k : null;
|
|
270
|
+
};
|
|
271
|
+
/** حالت خالی: preset (no-data، no-results، error، offline، no-access، done) با متن آماده، یا heading و description دلخواه؛ slot="actions" دکمهها */
|
|
272
|
+
export class KashiEmptyState extends Wrap {
|
|
273
|
+
constructor() {
|
|
274
|
+
super(...arguments);
|
|
275
|
+
this.customIcon = null;
|
|
276
|
+
this.actions = null;
|
|
277
|
+
}
|
|
278
|
+
build() {
|
|
279
|
+
this.customIcon = takeSlot(this, "icon")[0] ?? null;
|
|
280
|
+
const actions = takeSlot(this, "actions");
|
|
281
|
+
this.box = document.createElement("div");
|
|
282
|
+
this.box.innerHTML = '<span class="k-empty__icon" aria-hidden="true"></span><p class="k-empty__title"></p><p class="k-empty__description"></p>';
|
|
283
|
+
if (this.customIcon)
|
|
284
|
+
this.box.firstElementChild.append(this.customIcon);
|
|
285
|
+
const rest = unslotted(this);
|
|
286
|
+
if (actions.length || hasContent(rest)) {
|
|
287
|
+
this.actions = document.createElement("div");
|
|
288
|
+
this.actions.className = "k-empty__actions";
|
|
289
|
+
this.actions.append(...actions, ...(hasContent(rest) ? rest : []));
|
|
290
|
+
this.box.append(this.actions);
|
|
291
|
+
}
|
|
292
|
+
this.replaceChildren(this.box);
|
|
293
|
+
}
|
|
294
|
+
update() {
|
|
295
|
+
const preset = presetOf(this.getAttribute("preset"));
|
|
296
|
+
const size = this.getAttribute("size") ?? "md";
|
|
297
|
+
const text = preset ? msg().empty[preset] : undefined;
|
|
298
|
+
this.box.className = cx("k-empty", size !== "md" && `k-empty--${size}`, bool(this, "bordered") && "k-empty--bordered");
|
|
299
|
+
if (preset)
|
|
300
|
+
this.box.dataset.preset = preset;
|
|
301
|
+
else
|
|
302
|
+
delete this.box.dataset.preset;
|
|
303
|
+
if (preset === "error" || preset === "offline")
|
|
304
|
+
this.box.setAttribute("role", "status");
|
|
305
|
+
else
|
|
306
|
+
this.box.removeAttribute("role");
|
|
307
|
+
const iconBox = this.box.querySelector(".k-empty__icon");
|
|
308
|
+
if (!this.customIcon)
|
|
309
|
+
iconBox.innerHTML = preset ? EMPTY_ICONS[preset] : "";
|
|
310
|
+
iconBox.hidden = !iconBox.firstChild;
|
|
311
|
+
const title = this.getAttribute("heading") ?? text?.[0] ?? "";
|
|
312
|
+
const desc = this.getAttribute("description") ?? text?.[1] ?? "";
|
|
313
|
+
const t = this.box.querySelector(".k-empty__title");
|
|
314
|
+
const d = this.box.querySelector(".k-empty__description");
|
|
315
|
+
t.textContent = title;
|
|
316
|
+
t.hidden = !title;
|
|
317
|
+
d.textContent = desc;
|
|
318
|
+
d.hidden = !desc;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
KashiEmptyState.observedAttributes = ["preset", "heading", "description", "size", "bordered"];
|
|
322
|
+
// ---------- کارت شاخص ----------
|
|
323
|
+
const ARROW = (up) => icon(up ? '<path d="M10 15V5m0 0-4 4m4-4 4 4"/>' : '<path d="M10 5v10m0 0-4-4m4 4 4-4"/>', 1.8);
|
|
324
|
+
/**
|
|
325
|
+
* کارت شاخص کلیدی (KPI): label، value، unit، change (درصد تغییر) و caption؛ invert-trend برای شاخصهایی که کاهششان خوب است.
|
|
326
|
+
* slot="icon" آیکون و بقیهٔ محتوا (مثلاً kashi-sparkline) پایین کارت.
|
|
327
|
+
*/
|
|
328
|
+
export class KashiStatCard extends Wrap {
|
|
329
|
+
build() {
|
|
330
|
+
const ic = takeSlot(this, "icon")[0];
|
|
331
|
+
const chart = unslotted(this);
|
|
332
|
+
this.box = document.createElement("div");
|
|
333
|
+
this.box.className = "k-stat";
|
|
334
|
+
this.box.innerHTML = '<div class="k-stat__head"><p class="k-stat__label"></p></div><p class="k-stat__value"><span></span><span class="k-stat__unit"></span></p><div class="k-stat__foot"></div>';
|
|
335
|
+
if (ic) {
|
|
336
|
+
const s = document.createElement("span");
|
|
337
|
+
s.className = "k-stat__icon";
|
|
338
|
+
s.setAttribute("aria-hidden", "true");
|
|
339
|
+
s.append(ic);
|
|
340
|
+
this.box.firstElementChild.prepend(s);
|
|
341
|
+
}
|
|
342
|
+
if (hasContent(chart)) {
|
|
343
|
+
const c = document.createElement("div");
|
|
344
|
+
c.className = "k-stat__chart";
|
|
345
|
+
c.append(...chart);
|
|
346
|
+
this.box.append(c);
|
|
347
|
+
}
|
|
348
|
+
this.replaceChildren(this.box);
|
|
349
|
+
}
|
|
350
|
+
update() {
|
|
351
|
+
const M = msg();
|
|
352
|
+
const change = numAttr(this, "change");
|
|
353
|
+
this.box.querySelector(".k-stat__label").textContent = this.getAttribute("label") ?? "";
|
|
354
|
+
const raw = this.getAttribute("value") ?? "";
|
|
355
|
+
this.box.querySelector(".k-stat__value > span").textContent = /^-?[\d.,]+$/.test(raw) ? num(this, raw) : raw;
|
|
356
|
+
const unit = this.box.querySelector(".k-stat__unit");
|
|
357
|
+
unit.textContent = this.getAttribute("unit") ?? "";
|
|
358
|
+
unit.hidden = !unit.textContent;
|
|
359
|
+
if (bool(this, "loading"))
|
|
360
|
+
this.box.setAttribute("aria-busy", "true");
|
|
361
|
+
else
|
|
362
|
+
this.box.removeAttribute("aria-busy");
|
|
363
|
+
const dir = change === undefined ? null : change > 0 ? "up" : change < 0 ? "down" : "flat";
|
|
364
|
+
const good = dir === "flat" ? "flat" : (dir === "up") !== bool(this, "invert-trend") ? "up" : "down";
|
|
365
|
+
const up = this.getAttribute("up-label") ?? M.stat.up, down = this.getAttribute("down-label") ?? M.stat.down, flat = this.getAttribute("flat-label") ?? M.stat.flat;
|
|
366
|
+
const pct = change === undefined ? "" : M.common.percent(num(this, Math.abs(Math.round(change * 10) / 10)).replace(".", M.common.decimal));
|
|
367
|
+
const caption = this.getAttribute("caption");
|
|
368
|
+
const foot = this.box.querySelector(".k-stat__foot");
|
|
369
|
+
foot.hidden = !dir && !caption;
|
|
370
|
+
foot.innerHTML = `${dir ? `<span class="k-trend k-trend--${good}">${dir !== "flat" ? ARROW(dir === "up") : ""}<span aria-hidden="true">${esc(dir === "flat" ? flat : pct)}</span><span class="k-sr-only">${esc(dir === "flat" ? flat : `${pct} ${dir === "up" ? up : down}`)}</span></span>` : ""}${caption ? `<span>${esc(caption)}</span>` : ""}`;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
KashiStatCard.observedAttributes = ["label", "value", "unit", "change", "invert-trend", "caption", "loading", "up-label", "down-label", "flat-label"];
|
|
374
|
+
// ---------- هشدار ----------
|
|
375
|
+
const ALERT_ICON = { neutral: ICONS.info, brand: ICONS.info, info: ICONS.info, success: ICONS.success, warning: ICONS.warning, error: ICONS.error };
|
|
376
|
+
/**
|
|
377
|
+
* پیام هشدار داخل صفحه: tone، heading و متن خود عنصر؛ slot="actions" دکمهها و slot="icon" آیکون دلخواه (icon="false" بدون آیکون).
|
|
378
|
+
* با dismissible دکمهٔ بستن؛ kashi-close قابل لغو است و بدون لغو عنصر پنهان میشود.
|
|
379
|
+
*/
|
|
380
|
+
export class KashiAlert extends Wrap {
|
|
381
|
+
constructor() {
|
|
382
|
+
super(...arguments);
|
|
383
|
+
this.customIcon = null;
|
|
384
|
+
}
|
|
385
|
+
build() {
|
|
386
|
+
this.customIcon = takeSlot(this, "icon")[0] ?? null;
|
|
387
|
+
const actions = takeSlot(this, "actions");
|
|
388
|
+
const body = unslotted(this);
|
|
389
|
+
this.box = document.createElement("div");
|
|
390
|
+
this.box.innerHTML = '<span class="k-alert__icon" aria-hidden="true"></span><div class="k-alert__content"><p class="k-alert__title"></p></div>';
|
|
391
|
+
const content = this.box.querySelector(".k-alert__content");
|
|
392
|
+
if (hasContent(body)) {
|
|
393
|
+
const d = document.createElement("div");
|
|
394
|
+
d.className = "k-alert__description";
|
|
395
|
+
d.append(...body);
|
|
396
|
+
content.append(d);
|
|
397
|
+
}
|
|
398
|
+
if (actions.length) {
|
|
399
|
+
const a = document.createElement("div");
|
|
400
|
+
a.className = "k-alert__actions";
|
|
401
|
+
a.append(...actions);
|
|
402
|
+
content.append(a);
|
|
403
|
+
}
|
|
404
|
+
if (this.customIcon)
|
|
405
|
+
this.box.firstElementChild.append(this.customIcon);
|
|
406
|
+
this.replaceChildren(this.box);
|
|
407
|
+
this.box.addEventListener("click", (e) => {
|
|
408
|
+
if (e.target.closest(".k-alert__close"))
|
|
409
|
+
this.close();
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
update() {
|
|
413
|
+
const tone = this.getAttribute("tone") ?? "neutral";
|
|
414
|
+
this.box.className = cx("k-alert", tone !== "neutral" && `k-alert--${tone}`, bool(this, "tinted") && "k-alert--tinted", this.getAttribute("layout") === "banner" && "k-alert--banner", this.getAttribute("size") === "sm" && "k-alert--sm");
|
|
415
|
+
this.box.dataset.tone = tone;
|
|
416
|
+
this.box.setAttribute("role", tone === "error" || tone === "warning" ? "alert" : "status");
|
|
417
|
+
const ic = this.box.querySelector(".k-alert__icon");
|
|
418
|
+
ic.hidden = this.getAttribute("icon") === "false";
|
|
419
|
+
if (!this.customIcon)
|
|
420
|
+
ic.innerHTML = ALERT_ICON[tone] ?? ICONS.info;
|
|
421
|
+
const title = this.box.querySelector(".k-alert__title");
|
|
422
|
+
title.textContent = this.getAttribute("heading") ?? "";
|
|
423
|
+
title.hidden = !title.textContent;
|
|
424
|
+
let btn = this.box.querySelector(":scope > .k-alert__close");
|
|
425
|
+
if (bool(this, "dismissible")) {
|
|
426
|
+
if (!btn) {
|
|
427
|
+
this.box.insertAdjacentHTML("beforeend", `<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-alert__close">${ICONS.close}</button>`);
|
|
428
|
+
btn = this.box.querySelector(":scope > .k-alert__close");
|
|
429
|
+
}
|
|
430
|
+
btn.setAttribute("aria-label", this.getAttribute("close-label") ?? msg().alert.close);
|
|
431
|
+
}
|
|
432
|
+
else
|
|
433
|
+
btn?.remove();
|
|
434
|
+
}
|
|
435
|
+
/** بستن هشدار؛ با preventDefault روی kashi-close بسته نمیشود */
|
|
436
|
+
close() {
|
|
437
|
+
const ev = new CustomEvent("kashi-close", { bubbles: true, cancelable: true, detail: {} });
|
|
438
|
+
if (this.dispatchEvent(ev))
|
|
439
|
+
this.hidden = true;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
KashiAlert.observedAttributes = ["tone", "heading", "tinted", "layout", "size", "dismissible", "close-label", "icon"];
|
|
443
|
+
// ---------- سنجه ----------
|
|
444
|
+
/**
|
|
445
|
+
* سنجهٔ یک مقدار در برابر سقف (فضای ذخیره، سهمیه): label، value، max، warning (پیشفرض ۸۰٪) و critical (۹۵٪).
|
|
446
|
+
* وضعیت با متن و آیکون هم گفته میشود، نه فقط رنگ. unit واحد کنار عددها.
|
|
447
|
+
*/
|
|
448
|
+
export class KashiMeter extends HTMLBase {
|
|
449
|
+
constructor() {
|
|
450
|
+
super(...arguments);
|
|
451
|
+
this.box = null;
|
|
452
|
+
}
|
|
453
|
+
connectedCallback() {
|
|
454
|
+
if (!this.box) {
|
|
455
|
+
this.box = document.createElement("div");
|
|
456
|
+
this.box.className = "k-meter";
|
|
457
|
+
this.box.innerHTML = '<div class="k-meter__head"><span class="k-meter__label"></span><span class="k-meter__value"></span></div><div class="k-meter__track" role="meter" aria-valuemin="0"><span class="k-meter__fill"></span><span class="k-meter__mark" aria-hidden="true"></span></div><p class="k-meter__status" aria-hidden="true"></p>';
|
|
458
|
+
this.replaceChildren(this.box);
|
|
459
|
+
}
|
|
460
|
+
this.update();
|
|
461
|
+
}
|
|
462
|
+
attributeChangedCallback() {
|
|
463
|
+
if (this.box)
|
|
464
|
+
this.update();
|
|
465
|
+
}
|
|
466
|
+
update() {
|
|
467
|
+
const M = msg();
|
|
468
|
+
const max = numAttr(this, "max", 100) || 100;
|
|
469
|
+
const warning = numAttr(this, "warning", max * 0.8), critical = numAttr(this, "critical", max * 0.95);
|
|
470
|
+
const v = Math.min(max, Math.max(0, numAttr(this, "value", 0)));
|
|
471
|
+
const status = v >= critical ? "critical" : v >= warning ? "warning" : "ok";
|
|
472
|
+
const pct = Math.round((v / max) * 100);
|
|
473
|
+
const text = this.getAttribute(`${status}-label`) ?? M.meter[status];
|
|
474
|
+
const unit = this.getAttribute("unit");
|
|
475
|
+
const fmt = (x) => `${formatNumber(Math.round(x * 100) / 100, { digits: digitsOf(this) })}${unit ? ` ${unit}` : ""}`;
|
|
476
|
+
const of = this.getAttribute("of");
|
|
477
|
+
const label = this.getAttribute("label") ?? "";
|
|
478
|
+
const box = this.box;
|
|
479
|
+
box.dataset.status = status;
|
|
480
|
+
box.querySelector(".k-meter__label").textContent = label;
|
|
481
|
+
box.querySelector(".k-meter__value").innerHTML = `${esc(fmt(v))} <span>${esc(of ?? "/")} ${esc(fmt(max))}</span>`;
|
|
482
|
+
const track = box.querySelector(".k-meter__track");
|
|
483
|
+
track.setAttribute("aria-valuenow", String(v));
|
|
484
|
+
track.setAttribute("aria-valuemax", String(max));
|
|
485
|
+
track.setAttribute("aria-valuetext", `${of ? `${fmt(v)} ${of} ${fmt(max)}` : M.common.of(fmt(v), fmt(max))}${M.common.list}${M.common.percent(num(this, pct))}${M.common.list}${text}`);
|
|
486
|
+
if (label)
|
|
487
|
+
track.setAttribute("aria-label", label);
|
|
488
|
+
box.querySelector(".k-meter__fill").style.inlineSize = `${pct}%`;
|
|
489
|
+
box.querySelector(".k-meter__mark").style.insetInlineStart = `${(warning / max) * 100}%`;
|
|
490
|
+
box.querySelector(".k-meter__status").innerHTML = `${icon(`<path d="${status === "ok" ? "m5 10.5 3.2 3L15 7" : "M10 3 2.5 16.5h15ZM10 8v4M10 14.5h.01"}"/>`, 1.8)}${esc(text)} · ${esc(M.common.percent(num(this, pct)))}`;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
KashiMeter.observedAttributes = ["label", "value", "max", "warning", "critical", "unit", "of", "ok-label", "warning-label", "critical-label", "digits"];
|
|
494
|
+
// ---------- پیشرفت ----------
|
|
495
|
+
/** نوار یا حلقهٔ پیشرفت (variant="circular")؛ بدون value «نامعین». label، show-value، size و tone */
|
|
496
|
+
export class KashiProgress extends HTMLBase {
|
|
497
|
+
constructor() {
|
|
498
|
+
super(...arguments);
|
|
499
|
+
this.kind = "";
|
|
500
|
+
}
|
|
501
|
+
connectedCallback() {
|
|
502
|
+
this.update();
|
|
503
|
+
}
|
|
504
|
+
attributeChangedCallback() {
|
|
505
|
+
if (this.isConnected)
|
|
506
|
+
this.update();
|
|
507
|
+
}
|
|
508
|
+
update() {
|
|
509
|
+
const M = msg();
|
|
510
|
+
const max = numAttr(this, "max", 100) || 100;
|
|
511
|
+
const value = numAttr(this, "value");
|
|
512
|
+
const pct = value === undefined ? undefined : Math.max(0, Math.min(100, (value / max) * 100));
|
|
513
|
+
const text = pct === undefined ? undefined : M.common.percent(num(this, Math.round(pct)));
|
|
514
|
+
const label = this.getAttribute("label");
|
|
515
|
+
const size = this.getAttribute("size") ?? "md";
|
|
516
|
+
const tone = this.getAttribute("tone") ?? "brand";
|
|
517
|
+
const circular = this.getAttribute("variant") === "circular";
|
|
518
|
+
const show = bool(this, "show-value");
|
|
519
|
+
const kind = `${circular}-${!!label}`;
|
|
520
|
+
if (kind !== this.kind) {
|
|
521
|
+
this.kind = kind;
|
|
522
|
+
this.innerHTML = circular
|
|
523
|
+
? '<div role="progressbar" aria-valuemin="0"><svg viewBox="0 0 40 40" aria-hidden="true"><circle class="k-progress-ring__track" cx="20" cy="20" r="16"/><circle class="k-progress-ring__bar" cx="20" cy="20" r="16"/></svg><span class="k-progress-ring__value" aria-hidden="true"></span></div>'
|
|
524
|
+
: `${label ? '<div class="k-progress-field"><div class="k-progress-field__head" aria-hidden="true"><span class="k-progress-field__label"></span><span class="k-progress-field__value"></span></div>' : ""}<div role="progressbar" aria-valuemin="0"><div class="k-progress__bar"></div></div>${label ? "</div>" : ""}`;
|
|
525
|
+
}
|
|
526
|
+
const bar = this.querySelector('[role="progressbar"]');
|
|
527
|
+
bar.setAttribute("aria-valuemax", String(max));
|
|
528
|
+
for (const [k, v] of [["aria-valuenow", value === undefined ? null : String(value)], ["aria-valuetext", text ?? null], ["aria-label", this.getAttribute("aria-label") ?? label]]) {
|
|
529
|
+
if (v === null)
|
|
530
|
+
bar.removeAttribute(k);
|
|
531
|
+
else
|
|
532
|
+
bar.setAttribute(k, v);
|
|
533
|
+
}
|
|
534
|
+
if (circular) {
|
|
535
|
+
const c = 2 * Math.PI * 16;
|
|
536
|
+
bar.className = cx("k-progress-ring", size !== "md" && `k-progress-ring--${size}`, tone !== "brand" && `k-progress--${tone}`, pct === undefined && "k-progress-ring--indeterminate");
|
|
537
|
+
const ring = bar.querySelector(".k-progress-ring__bar");
|
|
538
|
+
ring.setAttribute("stroke-dasharray", String(c));
|
|
539
|
+
ring.setAttribute("stroke-dashoffset", String(pct === undefined ? c * 0.7 : c * (1 - pct / 100)));
|
|
540
|
+
const val = bar.querySelector(".k-progress-ring__value");
|
|
541
|
+
val.textContent = show && text ? text : "";
|
|
542
|
+
val.hidden = !val.textContent;
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
bar.className = cx("k-progress", size !== "md" && `k-progress--${size}`, tone !== "brand" && `k-progress--${tone}`);
|
|
546
|
+
const fill = bar.querySelector(".k-progress__bar");
|
|
547
|
+
if (pct === undefined)
|
|
548
|
+
fill.style.removeProperty("--k-value");
|
|
549
|
+
else
|
|
550
|
+
fill.style.setProperty("--k-value", `${pct}%`);
|
|
551
|
+
if (label) {
|
|
552
|
+
this.querySelector(".k-progress-field__label").textContent = label;
|
|
553
|
+
const v = this.querySelector(".k-progress-field__value");
|
|
554
|
+
v.textContent = show && text ? text : "";
|
|
555
|
+
v.hidden = !v.textContent;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
KashiProgress.observedAttributes = ["value", "max", "label", "show-value", "size", "tone", "variant", "aria-label"];
|
|
560
|
+
const DOT = '<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="3" fill="currentColor"/></svg>';
|
|
561
|
+
const ISO = /^\d{4}-\d{2}-\d{2}([T ][\d:.]+(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
562
|
+
/**
|
|
563
|
+
* خط زمانی رویدادها: هر فرزند با data-title یک رویداد است (data-time تاریخ ISO یا متن، data-tone رنگ، محتوای فرزند کادر زیر عنوان)،
|
|
564
|
+
* یا با JavaScript: element.items = [{ title, time, tone, content }].
|
|
565
|
+
*/
|
|
566
|
+
export class KashiTimeline extends HTMLBase {
|
|
567
|
+
constructor() {
|
|
568
|
+
super(...arguments);
|
|
569
|
+
this.list = null;
|
|
570
|
+
this.data = [];
|
|
571
|
+
this.timer = null;
|
|
572
|
+
}
|
|
573
|
+
connectedCallback() {
|
|
574
|
+
afterParse(() => {
|
|
575
|
+
if (!this.isConnected)
|
|
576
|
+
return;
|
|
577
|
+
if (!this.list) {
|
|
578
|
+
if (!this.data.length)
|
|
579
|
+
this.data = [...this.children].filter((c) => c.hasAttribute("data-title")).map((c) => {
|
|
580
|
+
const el = c;
|
|
581
|
+
return { item: { title: el.dataset.title ?? "", time: el.dataset.time, tone: el.dataset.tone }, nodes: [...el.childNodes] };
|
|
582
|
+
});
|
|
583
|
+
this.list = document.createElement("ol");
|
|
584
|
+
this.list.className = "k-timeline";
|
|
585
|
+
this.replaceChildren(this.list);
|
|
586
|
+
}
|
|
587
|
+
this.render();
|
|
588
|
+
if (this.list.querySelector("time[data-iso]"))
|
|
589
|
+
this.timer ?? (this.timer = setInterval(() => this.refreshTimes(), 60000));
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
disconnectedCallback() {
|
|
593
|
+
if (this.timer)
|
|
594
|
+
clearInterval(this.timer);
|
|
595
|
+
this.timer = null;
|
|
596
|
+
}
|
|
597
|
+
attributeChangedCallback() {
|
|
598
|
+
if (this.list)
|
|
599
|
+
this.render();
|
|
600
|
+
}
|
|
601
|
+
get items() {
|
|
602
|
+
return this.data.map((d) => d.item);
|
|
603
|
+
}
|
|
604
|
+
set items(list) {
|
|
605
|
+
this.data = (list ?? []).map((item) => ({ item, nodes: [] }));
|
|
606
|
+
if (this.list)
|
|
607
|
+
this.render();
|
|
608
|
+
}
|
|
609
|
+
timeText(t) {
|
|
610
|
+
if (!ISO.test(t))
|
|
611
|
+
return t;
|
|
612
|
+
const d = toDate(t);
|
|
613
|
+
return d ? formatRelative(d, { locale: lang(), digits: digitsOf(this) }) : t;
|
|
614
|
+
}
|
|
615
|
+
refreshTimes() {
|
|
616
|
+
this.list?.querySelectorAll("time[data-iso]").forEach((el) => (el.textContent = this.timeText(el.dateTime)));
|
|
617
|
+
}
|
|
618
|
+
render() {
|
|
619
|
+
const list = this.list;
|
|
620
|
+
list.replaceChildren();
|
|
621
|
+
for (const { item, nodes } of this.data) {
|
|
622
|
+
const li = document.createElement("li");
|
|
623
|
+
li.className = "k-timeline__item";
|
|
624
|
+
if (item.tone && item.tone !== "neutral")
|
|
625
|
+
li.dataset.tone = item.tone;
|
|
626
|
+
const time = item.time ? (ISO.test(item.time) ? `<time class="k-timeline__time" data-iso datetime="${esc(item.time)}">${esc(this.timeText(item.time))}</time>` : `<span class="k-timeline__time">${esc(item.time)}</span>`) : "";
|
|
627
|
+
li.innerHTML = `<span class="k-timeline__marker" aria-hidden="true">${DOT}</span><div class="k-timeline__body"><p class="k-timeline__title">${esc(item.title)}</p>${time}</div>`;
|
|
628
|
+
if (hasContent(nodes) || item.content) {
|
|
629
|
+
const c = document.createElement("div");
|
|
630
|
+
c.className = "k-timeline__content";
|
|
631
|
+
if (hasContent(nodes))
|
|
632
|
+
c.append(...nodes);
|
|
633
|
+
else
|
|
634
|
+
c.textContent = item.content;
|
|
635
|
+
li.querySelector(".k-timeline__body").append(c);
|
|
636
|
+
}
|
|
637
|
+
list.append(li);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
KashiTimeline.observedAttributes = ["digits"];
|
|
642
|
+
const CHECK = icon('<path d="m5 10.5 3.2 3L15 7"/>', 2.2);
|
|
643
|
+
/**
|
|
644
|
+
* مراحل یک فرایند: current شمارهٔ مرحلهٔ فعلی از صفر. هر فرزند <li> یک مرحله است (data-description توضیح)،
|
|
645
|
+
* یا steps='[{"title":"…"}]'. orientation="vertical" برای ستون.
|
|
646
|
+
*/
|
|
647
|
+
export class KashiStepper extends HTMLBase {
|
|
648
|
+
constructor() {
|
|
649
|
+
super(...arguments);
|
|
650
|
+
this.list = null;
|
|
651
|
+
this.data = [];
|
|
652
|
+
}
|
|
653
|
+
connectedCallback() {
|
|
654
|
+
afterParse(() => {
|
|
655
|
+
if (!this.isConnected)
|
|
656
|
+
return;
|
|
657
|
+
if (!this.list) {
|
|
658
|
+
if (!this.data.length && !this.hasAttribute("steps")) {
|
|
659
|
+
this.data = [...this.children].filter((c) => c.tagName === "LI").map((c) => ({ title: c.textContent?.trim() ?? "", description: c.dataset.description }));
|
|
660
|
+
}
|
|
661
|
+
this.list = document.createElement("ol");
|
|
662
|
+
this.replaceChildren(this.list);
|
|
663
|
+
}
|
|
664
|
+
this.render();
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
attributeChangedCallback(n, old, next) {
|
|
668
|
+
if (!this.list || old === next)
|
|
669
|
+
return;
|
|
670
|
+
if (n === "steps")
|
|
671
|
+
this.data = [];
|
|
672
|
+
this.render();
|
|
673
|
+
}
|
|
674
|
+
get steps() {
|
|
675
|
+
return this.data.length ? this.data : this.parsed();
|
|
676
|
+
}
|
|
677
|
+
set steps(v) {
|
|
678
|
+
this.data = [...(v ?? [])];
|
|
679
|
+
if (this.list)
|
|
680
|
+
this.render();
|
|
681
|
+
}
|
|
682
|
+
/** شمارهٔ مرحلهٔ فعلی از صفر */
|
|
683
|
+
get current() {
|
|
684
|
+
return numAttr(this, "current", 0);
|
|
685
|
+
}
|
|
686
|
+
set current(v) {
|
|
687
|
+
this.setAttribute("current", String(v));
|
|
688
|
+
}
|
|
689
|
+
parsed() {
|
|
690
|
+
try {
|
|
691
|
+
const v = JSON.parse(this.getAttribute("steps") ?? "[]");
|
|
692
|
+
return Array.isArray(v) ? v.map((s) => (typeof s === "string" ? { title: s } : s)) : [];
|
|
693
|
+
}
|
|
694
|
+
catch {
|
|
695
|
+
return [];
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
render() {
|
|
699
|
+
const M = msg();
|
|
700
|
+
const list = this.list;
|
|
701
|
+
const steps = this.steps;
|
|
702
|
+
const current = this.current;
|
|
703
|
+
list.className = cx("k-steps", this.getAttribute("orientation") === "vertical" && "k-steps--vertical");
|
|
704
|
+
list.setAttribute("aria-label", this.getAttribute("label") ?? M.stepper.label);
|
|
705
|
+
const complete = this.getAttribute("complete-label") ?? M.stepper.complete;
|
|
706
|
+
const currentLabel = this.getAttribute("current-label") ?? M.stepper.current;
|
|
707
|
+
list.innerHTML = steps.map((s, i) => {
|
|
708
|
+
const status = i < current ? "complete" : i === current ? "current" : "upcoming";
|
|
709
|
+
return `<li class="k-steps__step" data-status="${status}"${status === "current" ? ' aria-current="step"' : ""}><span class="k-steps__marker" aria-hidden="true">${status === "complete" ? CHECK : num(this, i + 1)}</span><span class="k-steps__title">${esc(s.title)}${status !== "upcoming" ? `<span class="k-sr-only">${esc(`${M.common.list}${status === "complete" ? complete : currentLabel}`)}</span>` : ""}</span>${s.description ? `<span class="k-steps__description">${esc(s.description)}</span>` : ""}</li>`;
|
|
710
|
+
}).join("");
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
KashiStepper.observedAttributes = ["current", "orientation", "label", "steps", "complete-label", "current-label", "digits"];
|
|
714
|
+
define("kashi-badge", KashiBadge);
|
|
715
|
+
define("kashi-avatar", KashiAvatar);
|
|
716
|
+
define("kashi-avatar-group", KashiAvatarGroup);
|
|
717
|
+
define("kashi-divider", KashiDivider, "contents");
|
|
718
|
+
define("kashi-skeleton", KashiSkeleton);
|
|
719
|
+
define("kashi-card", KashiCard, "block");
|
|
720
|
+
define("kashi-empty-state", KashiEmptyState, "block");
|
|
721
|
+
define("kashi-stat-card", KashiStatCard, "block");
|
|
722
|
+
define("kashi-alert", KashiAlert, "block");
|
|
723
|
+
define("kashi-meter", KashiMeter, "block");
|
|
724
|
+
define("kashi-progress", KashiProgress, "block");
|
|
725
|
+
define("kashi-timeline", KashiTimeline, "block");
|
|
726
|
+
define("kashi-stepper", KashiStepper, "block");
|