@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.
Files changed (81) hide show
  1. package/README.md +6 -1
  2. package/dist/base.js +4 -0
  3. package/dist/buttons.d.ts +82 -0
  4. package/dist/buttons.js +505 -0
  5. package/dist/cards.d.ts +30 -0
  6. package/dist/cards.js +183 -0
  7. package/dist/cdn/{appointment-wMGBoHw9.js → appointment-DOXBUwIU.js} +1 -1
  8. package/dist/cdn/{base-Dg1Mb8Jk.js → base-D4tCOysh.js} +1 -1
  9. package/dist/cdn/{basic-B5ZxgagA.js → basic-DuY4RslZ.js} +1 -1
  10. package/dist/cdn/buttons-BaK6bx3w.js +1 -0
  11. package/dist/cdn/calendar-BulPeVAJ.js +16 -0
  12. package/dist/cdn/card-BKiwJF34.js +1 -0
  13. package/dist/cdn/cards-DKarXHsC.js +1 -0
  14. package/dist/cdn/charts-ETYOAJyB.js +1 -0
  15. package/dist/cdn/chat-D5ZIMnNp.js +4 -0
  16. package/dist/cdn/choice-DBvC2Puo.js +1 -0
  17. package/dist/cdn/{combobox-CBT7yp94.js → combobox-BGuPAAt3.js} +1 -1
  18. package/dist/cdn/{commerce-CsyixnVK.js → commerce-SzWdpWJG.js} +1 -1
  19. package/dist/cdn/content-BgfBfy8j.js +1 -0
  20. package/dist/cdn/controls--OMZkJYe.js +1 -0
  21. package/dist/cdn/display-BfYWAjNu.js +1 -0
  22. package/dist/cdn/{fields-Cx84-qz1.js → fields-B-jTUQiI.js} +1 -1
  23. package/dist/cdn/forms-DgRiYmdV.js +1 -0
  24. package/dist/cdn/{holidays-DO82gXhM.js → holidays-Cu6IfbTL.js} +1 -1
  25. package/dist/cdn/hours-CeiVqPKD.js +1 -0
  26. package/dist/cdn/inputs-BkJ70Xkc.js +1 -0
  27. package/dist/cdn/kashi-elements.js +1 -1
  28. package/dist/cdn/legal-id-Mt8FX0fV.js +1 -0
  29. package/dist/cdn/{map-DlpA916P.js → map-TfSt3CjL.js} +2 -2
  30. package/dist/cdn/media-BRBINvzU.js +1 -0
  31. package/dist/cdn/{menu-CqTvk8Ok.js → menu-DTNVFXrb.js} +1 -1
  32. package/dist/cdn/money-CjGI2VIQ.js +1 -0
  33. package/dist/cdn/{nav-BHv7H1Fy.js → nav-CT5RVOzy.js} +1 -1
  34. package/dist/cdn/{overlay-BIEEJ4Sh.js → overlay-CS8piW6X.js} +1 -1
  35. package/dist/cdn/parts-5fVaWtRe.js +1 -0
  36. package/dist/cdn/pickers-BwDRsDRo.js +1 -0
  37. package/dist/cdn/relative-OC1fV3Xh.js +1 -0
  38. package/dist/cdn/rich-text-CS6xEim6.js +1 -0
  39. package/dist/cdn/sheets-eVMx4d-5.js +1 -0
  40. package/dist/cdn/{table-B5XwDDS9.js → table-tgB4iwcM.js} +1 -1
  41. package/dist/cdn/{text-Bml-pVjo.js → text-C6fzEBBh.js} +1 -1
  42. package/dist/cdn/{time-DrXgFeQy.js → time-CkqqUKJv.js} +1 -1
  43. package/dist/cdn/{time-BQsTSvql.js → time-CwOYrtK-.js} +1 -1
  44. package/dist/cdn/validate-Dr2f6i6s.js +1 -0
  45. package/dist/cdn/work-DoNAKgVU.js +1 -0
  46. package/dist/cdn.js +11 -0
  47. package/dist/chat.d.ts +127 -0
  48. package/dist/chat.js +734 -0
  49. package/dist/choice.d.ts +98 -0
  50. package/dist/choice.js +597 -0
  51. package/dist/content.d.ts +164 -0
  52. package/dist/content.js +726 -0
  53. package/dist/hours.d.ts +29 -0
  54. package/dist/hours.js +179 -0
  55. package/dist/index.d.ts +64 -2
  56. package/dist/index.js +22 -1
  57. package/dist/manifest.json +849 -2
  58. package/dist/media.d.ts +51 -0
  59. package/dist/media.js +363 -0
  60. package/dist/overlay.d.ts +2 -1
  61. package/dist/overlay.js +42 -11
  62. package/dist/parts.d.ts +31 -0
  63. package/dist/parts.js +114 -0
  64. package/dist/qr.d.ts +7 -0
  65. package/dist/qr.js +271 -0
  66. package/dist/rich-text.d.ts +40 -0
  67. package/dist/rich-text.js +375 -0
  68. package/dist/sheets.d.ts +128 -0
  69. package/dist/sheets.js +661 -0
  70. package/dist/validate.d.ts +40 -0
  71. package/dist/validate.js +224 -0
  72. package/dist/work.d.ts +117 -0
  73. package/dist/work.js +895 -0
  74. package/package.json +4 -4
  75. package/dist/cdn/calendar-Cjp5Rqer.js +0 -16
  76. package/dist/cdn/charts-DvQ4OwdS.js +0 -1
  77. package/dist/cdn/controls-B-s4IF_4.js +0 -1
  78. package/dist/cdn/display-MorJMDEF.js +0 -1
  79. package/dist/cdn/forms-CQeP9iiW.js +0 -1
  80. package/dist/cdn/inputs-Bqcs9Xy7.js +0 -1
  81. package/dist/cdn/pickers-BT9VPT4o.js +0 -1
@@ -0,0 +1,51 @@
1
+ import { HTMLBase } from "./base.js";
2
+ export interface GalleryImage {
3
+ src: string;
4
+ alt: string;
5
+ caption?: string;
6
+ /** تصویر کوچک شبکه؛ بدون آن همان src */
7
+ thumb?: string;
8
+ width?: number;
9
+ height?: number;
10
+ }
11
+ /**
12
+ * شبکهٔ تصویرهای کوچک که هر کدام در نمایش تمام‌صفحه (Lightbox) باز می‌شود: فلش‌ها (در راست‌به‌چپ، چپ یعنی بعدی)، Home و End،
13
+ * کشیدن انگشت، بزرگ‌نمایی با کلیک و نوار تصویرهای کوچک. تصویرها از فرزندان <img> (data-full تصویر بزرگ، data-caption زیرنویس)
14
+ * یا element.images. columns، aspect، max (بقیه با «+n») و loop.
15
+ */
16
+ export declare class KashiGallery extends HTMLBase {
17
+ static observedAttributes: string[];
18
+ private data;
19
+ private grid;
20
+ private box;
21
+ private index;
22
+ private zoom;
23
+ private swipe;
24
+ private dx;
25
+ private opener;
26
+ connectedCallback(): void;
27
+ attributeChangedCallback(n: string, old: string | null, next: string | null): void;
28
+ get images(): GalleryImage[];
29
+ set images(v: GalleryImage[]);
30
+ private render;
31
+ /** باز کردن نمایش تمام‌صفحه روی تصویر index */
32
+ openAt(index: number, opener?: HTMLElement): void;
33
+ close(): void;
34
+ private buildBox;
35
+ private go;
36
+ private paintBox;
37
+ }
38
+ /**
39
+ * کد QR به شکل SVG بدون کتابخانه؛ فارسی هم با UTF-8. value، size (پیکسل)، level (L، M، Q، H)، margin و rounded.
40
+ * عنصر slot="logo" وسط کد می‌نشیند (سطح خطا خودکار H می‌شود). کد همیشه تیره روی روشن است تا دوربین‌ها بخوانندش.
41
+ */
42
+ export declare class KashiQrCode extends HTMLBase {
43
+ static observedAttributes: string[];
44
+ private logo;
45
+ private built;
46
+ connectedCallback(): void;
47
+ attributeChangedCallback(_n: string, old: string | null, next: string | null): void;
48
+ get value(): string;
49
+ set value(v: string);
50
+ private render;
51
+ }
package/dist/media.js ADDED
@@ -0,0 +1,363 @@
1
+ // گالری تصاویر با نمایش تمام‌صفحه، و کد QR بدون کتابخانهٔ جانبی.
2
+ import { afterParse, bool, define, emit, esc, HTMLBase, msg, num } from "./base.js";
3
+ import { closeAnimated, icon, isRtl, jsonAttr, numAttr, takeSlot } from "./parts.js";
4
+ import { encodeQr } from "./qr.js";
5
+ const svg = (d) => icon(`<path d="${d}"/>`, 1.8);
6
+ const ZOOM_IN = svg("M8.5 14a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11ZM17 17l-4.2-4.2M6 8.5h5M8.5 6v5");
7
+ const ZOOM_OUT = svg("M8.5 14a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11ZM17 17l-4.2-4.2M6 8.5h5");
8
+ /**
9
+ * شبکهٔ تصویرهای کوچک که هر کدام در نمایش تمام‌صفحه (Lightbox) باز می‌شود: فلش‌ها (در راست‌به‌چپ، چپ یعنی بعدی)، Home و End،
10
+ * کشیدن انگشت، بزرگ‌نمایی با کلیک و نوار تصویرهای کوچک. تصویرها از فرزندان <img> (data-full تصویر بزرگ، data-caption زیرنویس)
11
+ * یا element.images. columns، aspect، max (بقیه با «+n») و loop.
12
+ */
13
+ export class KashiGallery extends HTMLBase {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.data = null;
17
+ this.grid = null;
18
+ this.box = null;
19
+ this.index = 0;
20
+ this.zoom = null;
21
+ this.swipe = null;
22
+ this.dx = 0;
23
+ this.opener = null;
24
+ }
25
+ connectedCallback() {
26
+ afterParse(() => {
27
+ if (!this.isConnected)
28
+ return;
29
+ if (!this.grid) {
30
+ if (this.data === null && !this.hasAttribute("images")) {
31
+ this.data = [...this.querySelectorAll(":scope > img")].map((img) => ({
32
+ src: img.dataset.full ?? img.getAttribute("src") ?? "",
33
+ thumb: img.dataset.full ? img.getAttribute("src") ?? undefined : undefined,
34
+ alt: img.alt,
35
+ caption: img.dataset.caption,
36
+ width: img.width || undefined,
37
+ height: img.height || undefined,
38
+ }));
39
+ }
40
+ this.grid = document.createElement("ul");
41
+ this.grid.className = "k-gallery";
42
+ this.replaceChildren(this.grid);
43
+ this.grid.addEventListener("click", (e) => {
44
+ const b = e.target.closest(".k-gallery__item");
45
+ if (b)
46
+ this.openAt(Number(b.dataset.index), b);
47
+ });
48
+ }
49
+ this.render();
50
+ });
51
+ }
52
+ attributeChangedCallback(n, old, next) {
53
+ if (old === next)
54
+ return;
55
+ if (n === "images")
56
+ this.data = null;
57
+ if (this.grid)
58
+ this.render();
59
+ }
60
+ get images() {
61
+ return this.data ?? jsonAttr(this, "images", []);
62
+ }
63
+ set images(v) {
64
+ this.data = [...(v ?? [])];
65
+ if (this.grid)
66
+ this.render();
67
+ }
68
+ render() {
69
+ const M = msg(), L = M.lightbox;
70
+ const images = this.images;
71
+ const max = numAttr(this, "max");
72
+ const shown = max && images.length > max ? images.slice(0, max) : images;
73
+ const rest = images.length - shown.length;
74
+ const g = this.grid;
75
+ g.setAttribute("aria-label", this.getAttribute("label") ?? L.gallery);
76
+ const cols = numAttr(this, "columns");
77
+ if (cols)
78
+ g.style.setProperty("--k-gallery-cols", String(cols));
79
+ else
80
+ g.style.removeProperty("--k-gallery-cols");
81
+ g.style.setProperty("--k-gallery-aspect", this.getAttribute("aspect") ?? "1 / 1");
82
+ g.innerHTML = shown.map((img, j) => {
83
+ const more = rest > 0 && j === shown.length - 1;
84
+ return `<li><button type="button" class="k-gallery__item" data-index="${j}" aria-label="${esc(more ? `${L.open(img.alt)} +${num(this, rest)}` : L.open(img.alt))}"><img src="${esc(img.thumb ?? img.src)}" alt="" loading="lazy"${img.width ? ` width="${img.width}"` : ""}${img.height ? ` height="${img.height}"` : ""}>${more ? `<span class="k-gallery__more" aria-hidden="true">+${num(this, rest)}</span>` : ""}</button></li>`;
85
+ }).join("");
86
+ }
87
+ /** باز کردن نمایش تمام‌صفحه روی تصویر index */
88
+ openAt(index, opener) {
89
+ if (!this.images.length)
90
+ return;
91
+ this.opener = opener ?? document.activeElement;
92
+ this.index = Math.max(0, Math.min(index, this.images.length - 1));
93
+ this.zoom = null;
94
+ if (!this.box)
95
+ this.buildBox();
96
+ this.paintBox(0);
97
+ const d = this.box;
98
+ d.removeAttribute("data-closing");
99
+ if (!d.open)
100
+ d.showModal?.();
101
+ d.querySelector("[data-act=close]").focus();
102
+ emit(this, "kashi-open", { index: this.index });
103
+ }
104
+ close() {
105
+ if (this.box?.open)
106
+ closeAnimated(this.box);
107
+ }
108
+ buildBox() {
109
+ const d = document.createElement("dialog");
110
+ d.className = "k-lightbox";
111
+ d.setAttribute("aria-labelledby", "");
112
+ d.innerHTML = `<h2 class="k-sr-only"></h2><div class="k-lightbox__bar"><span class="k-lightbox__counter" aria-live="polite"></span><button type="button" class="k-lightbox__btn" data-act="zoom"></button><button type="button" class="k-lightbox__btn" data-act="close">${svg("M5 5l10 10M15 5 5 15")}</button></div><div class="k-lightbox__stage"><figure class="k-lightbox__figure"><img class="k-lightbox__img" draggable="false" alt=""><figcaption class="k-lightbox__caption" dir="auto"></figcaption></figure><button type="button" class="k-lightbox__nav k-lightbox__nav--prev" data-act="prev">${svg("m8 5 5 5-5 5")}</button><button type="button" class="k-lightbox__nav k-lightbox__nav--next" data-act="next">${svg("m12 5-5 5 5 5")}</button></div><div class="k-lightbox__thumbs"></div>`;
113
+ const title = d.querySelector("h2");
114
+ title.id = `${this.tagName.toLowerCase()}-lb-${Math.random().toString(36).slice(2, 8)}`;
115
+ d.setAttribute("aria-labelledby", title.id);
116
+ this.append(d);
117
+ this.box = d;
118
+ d.addEventListener("cancel", (e) => {
119
+ e.preventDefault();
120
+ if (this.zoom) {
121
+ this.zoom = null;
122
+ this.paintBox(0);
123
+ }
124
+ else
125
+ this.close();
126
+ });
127
+ d.addEventListener("close", () => {
128
+ this.opener?.focus?.();
129
+ emit(this, "kashi-close", {});
130
+ });
131
+ d.addEventListener("keydown", (e) => {
132
+ const rtl = isRtl(d);
133
+ const count = this.images.length;
134
+ if (e.key === "ArrowRight")
135
+ this.go(this.index + (rtl ? -1 : 1));
136
+ else if (e.key === "ArrowLeft")
137
+ this.go(this.index + (rtl ? 1 : -1));
138
+ else if (e.key === "Home")
139
+ this.go(0);
140
+ else if (e.key === "End")
141
+ this.go(count - 1);
142
+ else
143
+ return;
144
+ e.preventDefault();
145
+ });
146
+ d.addEventListener("click", (e) => {
147
+ const t = e.target;
148
+ if (t === d || t.classList.contains("k-lightbox__stage"))
149
+ return this.close();
150
+ const act = t.closest("[data-act]")?.dataset.act;
151
+ if (act === "close")
152
+ this.close();
153
+ else if (act === "zoom") {
154
+ this.zoom = this.zoom ? null : { x: 50, y: 50 };
155
+ this.paintBox(0);
156
+ }
157
+ else if (act === "prev")
158
+ this.go(this.index - 1);
159
+ else if (act === "next")
160
+ this.go(this.index + 1);
161
+ const th = t.closest("[data-thumb]");
162
+ if (th)
163
+ this.go(Number(th.dataset.thumb));
164
+ });
165
+ const img = d.querySelector(".k-lightbox__img");
166
+ img.addEventListener("click", (e) => {
167
+ if (Math.abs(this.dx) > 4)
168
+ return;
169
+ const r = img.getBoundingClientRect();
170
+ this.zoom = this.zoom ? null : { x: ((e.clientX - r.left) / r.width) * 100, y: ((e.clientY - r.top) / r.height) * 100 };
171
+ this.paintBox(0);
172
+ });
173
+ img.addEventListener("pointermove", (e) => {
174
+ if (!this.zoom || e.pointerType === "touch")
175
+ return;
176
+ const r = img.getBoundingClientRect();
177
+ this.zoom = { x: ((e.clientX - r.left) / r.width) * 100, y: ((e.clientY - r.top) / r.height) * 100 };
178
+ img.style.transformOrigin = `${this.zoom.x}% ${this.zoom.y}%`;
179
+ });
180
+ const stage = d.querySelector(".k-lightbox__stage");
181
+ const fig = d.querySelector(".k-lightbox__figure");
182
+ stage.addEventListener("pointerdown", (e) => {
183
+ if (this.zoom || e.target.closest("button"))
184
+ return;
185
+ this.swipe = { x: e.clientX, y: e.clientY, id: e.pointerId };
186
+ });
187
+ stage.addEventListener("pointermove", (e) => {
188
+ if (this.swipe?.id !== e.pointerId)
189
+ return;
190
+ this.dx = e.clientX - this.swipe.x;
191
+ fig.style.translate = `${this.dx}px 0`;
192
+ fig.style.transition = "none";
193
+ });
194
+ const end = (e) => {
195
+ const s = this.swipe;
196
+ this.swipe = null;
197
+ fig.style.translate = "";
198
+ fig.style.transition = "";
199
+ const dx = this.dx;
200
+ setTimeout(() => (this.dx = 0), 0);
201
+ if (!s || s.id !== e.pointerId)
202
+ return;
203
+ if (Math.abs(dx) > 60 && Math.abs(dx) > Math.abs(e.clientY - s.y))
204
+ this.go(this.index + ((dx < 0) !== isRtl(d) ? 1 : -1));
205
+ };
206
+ stage.addEventListener("pointerup", end);
207
+ stage.addEventListener("pointercancel", end);
208
+ }
209
+ go(to) {
210
+ const count = this.images.length;
211
+ if (!count)
212
+ return;
213
+ const next = bool(this, "loop") ? (to + count) % count : Math.max(0, Math.min(count - 1, to));
214
+ if (next === this.index)
215
+ return;
216
+ const dir = next > this.index ? 1 : -1;
217
+ this.index = next;
218
+ this.zoom = null;
219
+ this.paintBox(dir);
220
+ emit(this, "kashi-change", { index: next });
221
+ }
222
+ paintBox(dir) {
223
+ const L = msg().lightbox;
224
+ const d = this.box;
225
+ const images = this.images;
226
+ const count = images.length;
227
+ const i = this.index;
228
+ const img = images[i];
229
+ const loop = bool(this, "loop");
230
+ d.querySelector("h2").textContent = L.label;
231
+ d.querySelector(".k-lightbox__counter").textContent = L.counter(num(this, i + 1), num(this, count));
232
+ const zb = d.querySelector("[data-act=zoom]");
233
+ zb.innerHTML = this.zoom ? ZOOM_OUT : ZOOM_IN;
234
+ zb.setAttribute("aria-label", this.zoom ? L.zoomOut : L.zoomIn);
235
+ zb.setAttribute("aria-pressed", String(!!this.zoom));
236
+ d.querySelector("[data-act=close]").setAttribute("aria-label", L.close);
237
+ const fig = d.querySelector(".k-lightbox__figure");
238
+ const el = fig.querySelector("img");
239
+ if (dir) {
240
+ // تصویر تازه با انیمیشن ورود از همان سمت
241
+ fig.dataset.dir = dir > 0 ? "next" : "prev";
242
+ fig.style.animation = "none";
243
+ void fig.offsetWidth;
244
+ fig.style.animation = "";
245
+ }
246
+ if (el.getAttribute("src") !== img.src)
247
+ el.src = img.src;
248
+ el.alt = img.alt;
249
+ if (img.width)
250
+ el.width = img.width;
251
+ else
252
+ el.removeAttribute("width");
253
+ if (img.height)
254
+ el.height = img.height;
255
+ else
256
+ el.removeAttribute("height");
257
+ el.toggleAttribute("data-zoom", !!this.zoom);
258
+ el.style.transformOrigin = this.zoom ? `${this.zoom.x}% ${this.zoom.y}%` : "";
259
+ const cap = fig.querySelector("figcaption");
260
+ cap.textContent = img.caption ?? "";
261
+ cap.hidden = !img.caption;
262
+ const prev = d.querySelector("[data-act=prev]"), next = d.querySelector("[data-act=next]");
263
+ prev.hidden = next.hidden = count < 2;
264
+ prev.setAttribute("aria-label", L.prev);
265
+ next.setAttribute("aria-label", L.next);
266
+ prev.disabled = !loop && i === 0;
267
+ next.disabled = !loop && i === count - 1;
268
+ const thumbs = d.querySelector(".k-lightbox__thumbs");
269
+ const showThumbs = this.getAttribute("thumbnails") !== "false" && count > 1;
270
+ thumbs.hidden = !showThumbs;
271
+ if (showThumbs) {
272
+ if (thumbs.children.length !== count)
273
+ thumbs.innerHTML = images.map((t, j) => `<button type="button" class="k-lightbox__thumb" data-thumb="${j}" aria-label="${esc(t.alt)}"><img src="${esc(t.thumb ?? t.src)}" alt="" loading="lazy" draggable="false"></button>`).join("");
274
+ thumbs.querySelectorAll("[data-thumb]").forEach((b, j) => {
275
+ if (j === i)
276
+ b.setAttribute("aria-current", "true");
277
+ else
278
+ b.removeAttribute("aria-current");
279
+ });
280
+ thumbs.querySelector(`[data-thumb="${i}"]`)?.scrollIntoView?.({ block: "nearest", inline: "center" });
281
+ }
282
+ // پیش‌بارگذاری تصویرهای کناری
283
+ for (const j of [i - 1, i + 1]) {
284
+ const s = images[(j + count) % count]?.src;
285
+ if (s && typeof Image === "function")
286
+ new Image().src = s;
287
+ }
288
+ }
289
+ }
290
+ KashiGallery.observedAttributes = ["images", "columns", "aspect", "max", "loop", "label", "thumbnails"];
291
+ // ---------- کد QR ----------
292
+ /**
293
+ * کد QR به شکل SVG بدون کتابخانه؛ فارسی هم با UTF-8. value، size (پیکسل)، level (L، M، Q، H)، margin و rounded.
294
+ * عنصر slot="logo" وسط کد می‌نشیند (سطح خطا خودکار H می‌شود). کد همیشه تیره روی روشن است تا دوربین‌ها بخوانندش.
295
+ */
296
+ export class KashiQrCode extends HTMLBase {
297
+ constructor() {
298
+ super(...arguments);
299
+ this.logo = null;
300
+ this.built = false;
301
+ }
302
+ connectedCallback() {
303
+ afterParse(() => {
304
+ if (!this.isConnected)
305
+ return;
306
+ if (!this.built) {
307
+ this.built = true;
308
+ this.logo = takeSlot(this, "logo")[0] ?? null;
309
+ }
310
+ this.render();
311
+ });
312
+ }
313
+ attributeChangedCallback(_n, old, next) {
314
+ if (this.built && old !== next)
315
+ this.render();
316
+ }
317
+ get value() {
318
+ return this.getAttribute("value") ?? "";
319
+ }
320
+ set value(v) {
321
+ this.setAttribute("value", String(v ?? ""));
322
+ }
323
+ render() {
324
+ const M = msg();
325
+ const value = this.value;
326
+ const size = numAttr(this, "size", 160);
327
+ const margin = Math.max(0, numAttr(this, "margin", 4));
328
+ const rounded = this.getAttribute("rounded") !== "false";
329
+ const lvl = (this.logo ? "H" : (this.getAttribute("level") ?? "M").toUpperCase());
330
+ const matrix = encodeQr(value, ["L", "M", "Q", "H"].includes(lvl) ? lvl : "M");
331
+ if (!matrix) {
332
+ this.innerHTML = `<p class="k-hint k-hint--error">${esc(M.qr.tooLong)}</p>`;
333
+ return;
334
+ }
335
+ const n = matrix.length;
336
+ const full = n + margin * 2;
337
+ const inFinder = (x, y) => (x < 7 && y < 7) || (x >= n - 7 && y < 7) || (x < 7 && y >= n - 7);
338
+ const hole = this.logo ? Math.ceil(n * 0.22) | 1 : 0;
339
+ const h0 = (n - hole) / 2;
340
+ const inHole = (x, y) => hole > 0 && x >= h0 - 0.5 && x < h0 + hole - 0.5 && y >= h0 - 0.5 && y < h0 + hole - 0.5;
341
+ let d = "";
342
+ for (let y = 0; y < n; y++)
343
+ for (let x = 0; x < n; x++)
344
+ if (matrix[y][x] && !inFinder(x, y) && !inHole(x, y))
345
+ d += `M${x + margin} ${y + margin}h1v1h-1z`;
346
+ const r = rounded ? 1 : 0;
347
+ const finder = (fx, fy) => {
348
+ const x = fx + margin, y = fy + margin, k = r * 1.6, s = 7 - r * 3.2;
349
+ return `<g><path fill-rule="evenodd" d="M${x + k} ${y}h${s}a${k} ${k} 0 0 1 ${k} ${k}v${s}a${k} ${k} 0 0 1 -${k} ${k}h-${s}a${k} ${k} 0 0 1 -${k} -${k}v-${s}a${k} ${k} 0 0 1 ${k} -${k}zM${x + 1} ${y + 1}v5h5v-5z"/><rect x="${x + 2}" y="${y + 2}" width="3" height="3" rx="${r * 0.8}"/></g>`;
350
+ };
351
+ this.innerHTML = `<span class="k-qr" style="inline-size: ${size}px; block-size: ${size}px"><svg viewBox="0 0 ${full} ${full}" width="${size}" height="${size}" role="img" aria-label="${esc(this.getAttribute("label") ?? M.qr.label(value))}"${rounded ? "" : ' shape-rendering="crispEdges"'}><rect width="${full}" height="${full}" class="k-qr__bg" rx="${rounded ? 2 : 0}"/><g class="k-qr__fg"><path d="${d}"/>${finder(0, 0)}${finder(n - 7, 0)}${finder(0, n - 7)}</g></svg></span>`;
352
+ if (this.logo) {
353
+ const l = document.createElement("span");
354
+ l.className = "k-qr__logo";
355
+ l.style.inlineSize = `${(hole / full) * 100 * 0.9}%`;
356
+ l.append(this.logo);
357
+ this.querySelector(".k-qr").append(l);
358
+ }
359
+ }
360
+ }
361
+ KashiQrCode.observedAttributes = ["value", "size", "level", "margin", "rounded", "label"];
362
+ define("kashi-gallery", KashiGallery, "block");
363
+ define("kashi-qr-code", KashiQrCode);
package/dist/overlay.d.ts CHANGED
@@ -58,7 +58,8 @@ export declare class KashiTooltip extends HTMLBase {
58
58
  connectedCallback(): void;
59
59
  private setup;
60
60
  disconnectedCallback(): void;
61
- attributeChangedCallback(): void;
61
+ attributeChangedCallback(name: string): void;
62
+ private trigger;
62
63
  private place;
63
64
  private open;
64
65
  private close;
package/dist/overlay.js CHANGED
@@ -280,6 +280,7 @@ export class KashiTooltip extends HTMLBase {
280
280
  super(...arguments);
281
281
  this.tip = null;
282
282
  this.key = uid("kashi-tip");
283
+ this.trigger = null;
283
284
  this.place = () => placeTip(this, this.tip, this.getAttribute("placement") || "top");
284
285
  this.onKey = (e) => {
285
286
  if (e.key === "Escape") {
@@ -302,30 +303,39 @@ export class KashiTooltip extends HTMLBase {
302
303
  this.append(tip);
303
304
  this.tip = tip;
304
305
  const trigger = this.firstElementChild !== tip ? this.firstElementChild : null;
305
- if (trigger)
306
- trigger.setAttribute("aria-describedby", [trigger.getAttribute("aria-describedby"), this.key].filter(Boolean).join(" "));
307
306
  this.addEventListener("mouseenter", () => this.show(Number(this.getAttribute("delay") ?? 300)));
307
+ this.trigger = trigger;
308
308
  this.addEventListener("mouseleave", () => this.hide());
309
309
  this.addEventListener("focusin", () => this.show(0));
310
310
  this.addEventListener("focusout", () => this.hide());
311
311
  }
312
312
  this.decorate();
313
+ if (this.hasAttribute("open"))
314
+ this.open();
313
315
  }
314
316
  disconnectedCallback() {
315
317
  clearTimeout(this.timer);
316
318
  this.close();
317
319
  }
318
- attributeChangedCallback() {
319
- if (this.tip)
320
- this.decorate();
321
- if (this.tip && !this.tip.hidden)
320
+ attributeChangedCallback(name) {
321
+ if (!this.tip)
322
+ return;
323
+ this.decorate();
324
+ if (name === "open" || name === "disabled") {
325
+ if (this.hasAttribute("open") && !this.hasAttribute("disabled"))
326
+ this.open();
327
+ else
328
+ this.close();
329
+ }
330
+ if (!this.tip.hidden)
322
331
  this.place();
323
332
  }
324
333
  open() {
325
334
  const tip = this.tip;
326
- if (!tip.hidden)
335
+ if (!tip.hidden || this.hasAttribute("disabled"))
327
336
  return;
328
337
  tip.hidden = false;
338
+ emit(this, "kashi-toggle", { open: true });
329
339
  this.place();
330
340
  document.addEventListener("keydown", this.onKey);
331
341
  addEventListener("scroll", this.place, { capture: true, passive: true });
@@ -334,6 +344,11 @@ export class KashiTooltip extends HTMLBase {
334
344
  close() {
335
345
  if (!this.tip)
336
346
  return;
347
+ // با ویژگی open، راهنما کنترل‌شده است و hover یا فوکوس آن را نمی‌بندد
348
+ if (this.hasAttribute("open") && !this.hasAttribute("disabled") && this.isConnected)
349
+ return;
350
+ if (!this.tip.hidden)
351
+ emit(this, "kashi-toggle", { open: false });
337
352
  this.tip.hidden = true;
338
353
  unplaceTip(this.tip);
339
354
  document.removeEventListener("keydown", this.onKey);
@@ -341,9 +356,25 @@ export class KashiTooltip extends HTMLBase {
341
356
  removeEventListener("resize", this.place);
342
357
  }
343
358
  decorate() {
359
+ const tip = this.tip;
344
360
  const placement = this.getAttribute("placement");
345
- this.tip.className = `k-tooltip${placement && placement !== "top" ? ` k-tooltip--${placement}` : ""}`;
346
- this.tip.textContent = this.getAttribute("content") ?? "";
361
+ const heading = this.getAttribute("heading");
362
+ const shortcut = this.getAttribute("shortcut");
363
+ tip.className = `k-tooltip${placement && placement !== "top" ? ` k-tooltip--${placement}` : ""}${heading ? " k-tooltip--rich" : ""}`;
364
+ const content = esc(this.getAttribute("content") ?? "");
365
+ tip.innerHTML = (heading ? `<span class="k-tooltip__title">${esc(heading)}</span><span class="k-tooltip__body">${content}</span>` : content)
366
+ + (shortcut ? `<kbd class="k-tooltip__kbd" dir="ltr">${esc(shortcut)}</kbd>` : "");
367
+ // غیرفعال: راهنما به عنصر وصل نمی‌ماند تا صفحه‌خوان متن پنهان را نخواند
368
+ const t = this.trigger;
369
+ if (t) {
370
+ const ids = (t.getAttribute("aria-describedby") ?? "").split(" ").filter((x) => x && x !== this.key);
371
+ if (!this.hasAttribute("disabled"))
372
+ ids.push(this.key);
373
+ if (ids.length)
374
+ t.setAttribute("aria-describedby", ids.join(" "));
375
+ else
376
+ t.removeAttribute("aria-describedby");
377
+ }
347
378
  }
348
379
  show(wait) {
349
380
  clearTimeout(this.timer);
@@ -351,10 +382,10 @@ export class KashiTooltip extends HTMLBase {
351
382
  }
352
383
  hide() {
353
384
  clearTimeout(this.timer);
354
- this.timer = setTimeout(() => this.close(), 100);
385
+ this.timer = setTimeout(() => this.close(), Number(this.getAttribute("close-delay") ?? 100));
355
386
  }
356
387
  }
357
- KashiTooltip.observedAttributes = ["content", "placement"];
388
+ KashiTooltip.observedAttributes = ["content", "placement", "heading", "shortcut", "disabled", "open"];
358
389
  /** دکمهٔ کپی در کلیپ‌بورد با بازخورد «کپی شد» برای چشم و صفحه‌خوان */
359
390
  export class KashiCopyButton extends HTMLBase {
360
391
  constructor() {
@@ -0,0 +1,31 @@
1
+ /** کلاس‌ها بدون مقدارهای خالی */
2
+ export declare const cx: (...list: (string | false | null | undefined)[]) => string;
3
+ /** فرزندان مستقیم با slot داده‌شده را از جایشان برمی‌دارد؛ slot هم برداشته می‌شود چون Shadow DOM نداریم */
4
+ export declare function takeSlot(host: Element, name: string): Element[];
5
+ /** بقیهٔ فرزندان (بدون slot)، شامل متن */
6
+ export declare function unslotted(host: Element): Node[];
7
+ /** فرزند معنادار دارد؛ فاصلهٔ خالی حساب نمی‌شود */
8
+ export declare const hasContent: (nodes: Node[]) => boolean;
9
+ /** ویژگی JSON؛ اگر نامعتبر بود fallback */
10
+ export declare function jsonAttr<T>(el: Element, name: string, fallback: T): T;
11
+ /** عدد از ویژگی؛ خالی یا نامعتبر یعنی fallback */
12
+ export declare function numAttr(el: Element, name: string, fallback: number): number;
13
+ export declare function numAttr(el: Element, name: string, fallback?: number): number | undefined;
14
+ export declare const reduced: () => boolean;
15
+ export declare const isRtl: (el: Element | null) => boolean;
16
+ /** تاریخ از رشتهٔ ISO یا Date */
17
+ export declare function toDate(v: unknown): Date | null;
18
+ export declare const icon: (body: string, width?: number) => string;
19
+ export declare const GRIP: string;
20
+ /**
21
+ * حرکت نرم موارد پس از جابه‌جایی (FLIP): پیش از تغییر DOM جای موارد را بگیرید (measure) و بعد play را صدا بزنید.
22
+ * موردی که دستی کشیده می‌شود ([data-dragging]) حرکت نمی‌گیرد.
23
+ */
24
+ export declare function flip(items: HTMLElement[]): () => void;
25
+ /** کپی در کلیپ‌بورد؛ true یعنی موفق */
26
+ export declare function copyText(text: string): Promise<boolean>;
27
+ /**
28
+ * باز و بسته کردن <dialog> بومی با انیمیشن خروج (data-closing)؛ با «کاهش حرکت» فوراً بسته می‌شود.
29
+ * done پس از بسته شدن واقعی صدا زده می‌شود.
30
+ */
31
+ export declare function closeAnimated(d: HTMLDialogElement, returnValue?: string): void;