@kashi-ui/elements 2.18.0 → 2.20.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/dist/time.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ import { HTMLBase } from "./base.js";
2
+ type View = "hour" | "minute";
3
+ /**
4
+ * صفحهٔ ساعت عقربه‌ای ۲۴ساعته: اول ساعت، بعد دقیقه. کلیک، کشیدن یا کیبورد (↑↓←→، Home/End، Enter).
5
+ * رویدادها: kashi-change با هر انتخاب، kashi-complete وقتی دقیقه انتخاب شد.
6
+ */
7
+ export declare class KashiTimeClock extends HTMLBase {
8
+ static observedAttributes: string[];
9
+ private current;
10
+ private mode;
11
+ private valueSet;
12
+ private rendered;
13
+ private dragging;
14
+ connectedCallback(): void;
15
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
16
+ /** ساعت به شکل HH:MM، یا رشتهٔ خالی */
17
+ get value(): string;
18
+ set value(v: string);
19
+ /** "hour" یا "minute" */
20
+ get view(): View;
21
+ set view(v: View);
22
+ focus(options?: FocusOptions): void;
23
+ private get step();
24
+ private get lo();
25
+ private get hi();
26
+ private hourOk;
27
+ private minuteOk;
28
+ private f;
29
+ private set;
30
+ private setMode;
31
+ private pickHour;
32
+ private pickMinute;
33
+ private fromPoint;
34
+ private pointer;
35
+ private onKey;
36
+ /** پوسته یک بار ساخته می‌شود و صفحه (dial) همان عنصر می‌ماند تا فوکوس و صفحه‌خوان با هر کلید از دست نروند */
37
+ private build;
38
+ private render;
39
+ }
40
+ /**
41
+ * انتخاب ساعت: تایپ مستقیم (۰۹:۳۰) یا انتخاب از صفحهٔ ساعت؛ تغییرها تا «تأیید» پیش‌نویس‌اند و Esc بدون تغییر می‌بندد.
42
+ * با name، مقدار به شکل HH:MM با ارقام لاتین در فرم ارسال می‌شود.
43
+ */
44
+ export declare class KashiTimePicker extends HTMLBase {
45
+ static observedAttributes: string[];
46
+ private current;
47
+ private invalid;
48
+ private valueSet;
49
+ private rendered;
50
+ private key;
51
+ private input;
52
+ private toggle;
53
+ private pop;
54
+ connectedCallback(): void;
55
+ disconnectedCallback(): void;
56
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
57
+ /** ساعت به شکل HH:MM، یا رشتهٔ خالی */
58
+ get value(): string;
59
+ set value(v: string);
60
+ focus(options?: FocusOptions): void;
61
+ private get step();
62
+ private get lo();
63
+ private get hi();
64
+ private show;
65
+ private get openLabel();
66
+ private render;
67
+ private paint;
68
+ private commitText;
69
+ private commit;
70
+ /** باز کردن صفحهٔ ساعت */
71
+ open(): void;
72
+ /** بستن صفحهٔ ساعت بدون ثبت؛ فوکوس به دکمهٔ ساعت برمی‌گردد */
73
+ close(returnFocus?: boolean): void;
74
+ private onOutside;
75
+ }
76
+ export {};
package/dist/time.js ADDED
@@ -0,0 +1,466 @@
1
+ // صفحهٔ ساعت و انتخاب ساعت؛ همتای TimeClock و TimePicker در @kashi-ui/react با همان کلاس‌های k-clock و k-timepicker.
2
+ import { formatTime, parseTime, toFaDigits } from "@kashi-ui/persian";
3
+ import { define, digitsOf, emit, esc, fieldHTML, HTMLBase, msg, setMessages, syncHidden, uid } from "./base.js";
4
+ const DAY = 24 * 60;
5
+ const pad = (n) => String(n).padStart(2, "0");
6
+ const toMin = (s) => {
7
+ const t = s ? parseTime(s) : null;
8
+ return t ? t.hours * 60 + t.minutes : null;
9
+ };
10
+ const fmt = (m) => formatTime({ hours: Math.floor(m / 60), minutes: m % 60 });
11
+ // شعاع حلقه‌ها به درصدِ پهنای صفحه؛ ۱ تا ۱۲ داخل، ۰۰ و ۱۳ تا ۲۳ بیرون
12
+ const OUTER = 40;
13
+ const INNER = 26;
14
+ const isInner = (h) => h >= 1 && h <= 12;
15
+ const hourAngle = (h) => (h % 12) * 30;
16
+ const CLOCK = '<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="10" cy="10" r="7"/><path d="M10 6v4l2.5 2"/></svg>';
17
+ /**
18
+ * صفحهٔ ساعت عقربه‌ای ۲۴ساعته: اول ساعت، بعد دقیقه. کلیک، کشیدن یا کیبورد (↑↓←→، Home/End، Enter).
19
+ * رویدادها: kashi-change با هر انتخاب، kashi-complete وقتی دقیقه انتخاب شد.
20
+ */
21
+ export class KashiTimeClock extends HTMLBase {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.current = null;
25
+ this.mode = "hour";
26
+ this.valueSet = false;
27
+ this.rendered = false;
28
+ this.dragging = false;
29
+ }
30
+ connectedCallback() {
31
+ if (!this.rendered) {
32
+ if (!this.valueSet)
33
+ this.current = toMin(this.getAttribute("value"));
34
+ if (this.getAttribute("view") === "minute")
35
+ this.mode = "minute";
36
+ }
37
+ this.render();
38
+ }
39
+ attributeChangedCallback(name, old, next) {
40
+ if (!this.rendered || old === next)
41
+ return;
42
+ if (name === "value")
43
+ this.current = toMin(next);
44
+ if (name === "view")
45
+ this.mode = next === "minute" ? "minute" : "hour";
46
+ this.render();
47
+ }
48
+ /** ساعت به شکل HH:MM، یا رشتهٔ خالی */
49
+ get value() {
50
+ return this.current === null ? "" : fmt(this.current);
51
+ }
52
+ set value(v) {
53
+ this.valueSet = true;
54
+ this.current = toMin(v);
55
+ if (this.rendered)
56
+ this.render();
57
+ }
58
+ /** "hour" یا "minute" */
59
+ get view() {
60
+ return this.mode;
61
+ }
62
+ set view(v) {
63
+ this.mode = v === "minute" ? "minute" : "hour";
64
+ if (this.rendered)
65
+ this.render();
66
+ }
67
+ focus(options) {
68
+ this.querySelector(".k-clock__dial")?.focus(options);
69
+ }
70
+ get step() {
71
+ return Math.max(1, Number(this.getAttribute("step")) || 5);
72
+ }
73
+ get lo() {
74
+ return toMin(this.getAttribute("min")) ?? 0;
75
+ }
76
+ get hi() {
77
+ return toMin(this.getAttribute("max")) ?? DAY - 1;
78
+ }
79
+ hourOk(h) {
80
+ return h * 60 + 59 >= this.lo && h * 60 <= this.hi;
81
+ }
82
+ minuteOk(h, m) {
83
+ return h * 60 + m >= this.lo && h * 60 + m <= this.hi;
84
+ }
85
+ f(s) {
86
+ return digitsOf(this) === "latin" ? s : toFaDigits(s);
87
+ }
88
+ set(mins) {
89
+ const v = Math.min(this.hi, Math.max(this.lo, mins));
90
+ const changed = v !== this.current;
91
+ this.current = v;
92
+ this.render();
93
+ if (changed)
94
+ emit(this, "kashi-change", { value: fmt(v) });
95
+ }
96
+ setMode(v) {
97
+ this.mode = v;
98
+ this.render();
99
+ }
100
+ pickHour(h) {
101
+ if (this.hourOk(h))
102
+ this.set(h * 60 + (this.current === null ? 0 : this.current % 60));
103
+ }
104
+ pickMinute(m) {
105
+ const h = this.current === null ? Math.floor(this.lo / 60) : Math.floor(this.current / 60);
106
+ if (!this.minuteOk(h, m))
107
+ return false;
108
+ this.set(h * 60 + m);
109
+ return true;
110
+ }
111
+ fromPoint(e, dial) {
112
+ const r = dial.getBoundingClientRect();
113
+ const dx = e.clientX - (r.left + r.width / 2);
114
+ const dy = e.clientY - (r.top + r.height / 2);
115
+ const angle = (Math.atan2(dx, -dy) * 180) / Math.PI + 360;
116
+ const dist = (Math.hypot(dx, dy) / r.width) * 100;
117
+ if (this.mode === "hour") {
118
+ const i = Math.round(angle / 30) % 12;
119
+ return dist < (OUTER + INNER) / 2 ? (i === 0 ? 12 : i) : i === 0 ? 0 : i + 12;
120
+ }
121
+ return (Math.round(Math.round(angle / 6) / this.step) * this.step) % 60;
122
+ }
123
+ pointer(e, dial) {
124
+ const v = this.fromPoint(e, dial);
125
+ return this.mode === "hour" ? (this.pickHour(v), false) : this.pickMinute(v);
126
+ }
127
+ onKey(e) {
128
+ const k = e.key;
129
+ if (k === "Enter" || k === " ") {
130
+ e.preventDefault();
131
+ if (this.current === null)
132
+ return;
133
+ if (this.mode === "hour")
134
+ this.setMode("minute");
135
+ else
136
+ emit(this, "kashi-complete", { value: this.value });
137
+ return;
138
+ }
139
+ const base = this.current ?? this.lo;
140
+ const up = k === "ArrowUp" || k === "ArrowRight";
141
+ const down = k === "ArrowDown" || k === "ArrowLeft";
142
+ let next;
143
+ if (this.mode === "hour") {
144
+ if (up || down) {
145
+ // ساعت مجاز بعدی یا قبلی؛ در ۲۳ به ۰۰ برمی‌گردد
146
+ let n = Math.floor(base / 60);
147
+ for (let i = 0; i < 24; i++) {
148
+ n = (n + (up ? 1 : 23)) % 24;
149
+ if (this.hourOk(n))
150
+ break;
151
+ }
152
+ next = n * 60 + (base % 60);
153
+ }
154
+ else if (k === "Home")
155
+ next = this.lo;
156
+ else if (k === "End")
157
+ next = Math.floor(this.hi / 60) * 60 + (base % 60);
158
+ else
159
+ return;
160
+ }
161
+ else {
162
+ const mm = base % 60, hh = base - mm, step = this.step;
163
+ if (up)
164
+ next = hh + ((Math.floor(mm / step) * step + step) % 60);
165
+ else if (down)
166
+ next = hh + ((Math.ceil(mm / step) * step - step + 60) % 60);
167
+ else if (k === "Home")
168
+ next = hh;
169
+ else if (k === "End")
170
+ next = hh + Math.floor(59 / step) * step;
171
+ else
172
+ return;
173
+ }
174
+ e.preventDefault();
175
+ this.set(next);
176
+ }
177
+ /** پوسته یک بار ساخته می‌شود و صفحه (dial) همان عنصر می‌ماند تا فوکوس و صفحه‌خوان با هر کلید از دست نروند */
178
+ build() {
179
+ const M = msg().timePicker;
180
+ this.innerHTML = `<div class="k-clock" role="group"><div class="k-clock__header" dir="ltr">`
181
+ + `<button type="button" class="k-clock__unit" data-view="hour"></button><span class="k-clock__sep" aria-hidden="true">:</span>`
182
+ + `<button type="button" class="k-clock__unit" data-view="minute"></button></div>`
183
+ + `<div class="k-clock__dial" role="slider" tabindex="0" dir="ltr" aria-valuemin="0"></div></div>`;
184
+ const dial = this.querySelector(".k-clock__dial");
185
+ for (const b of this.querySelectorAll(".k-clock__unit"))
186
+ b.addEventListener("click", () => this.setMode(b.dataset.view));
187
+ dial.addEventListener("keydown", (e) => this.onKey(e));
188
+ dial.addEventListener("pointerdown", (e) => {
189
+ if (e.button !== 0)
190
+ return;
191
+ e.preventDefault();
192
+ dial.focus();
193
+ this.dragging = true;
194
+ dial.setPointerCapture?.(e.pointerId);
195
+ this.pointer(e, dial);
196
+ });
197
+ dial.addEventListener("pointermove", (e) => {
198
+ if (this.dragging)
199
+ this.pointer(e, dial);
200
+ });
201
+ dial.addEventListener("pointerup", (e) => {
202
+ if (!this.dragging)
203
+ return;
204
+ this.dragging = false;
205
+ const picked = this.pointer(e, dial);
206
+ if (this.mode === "hour")
207
+ this.setMode("minute");
208
+ else if (picked)
209
+ emit(this, "kashi-complete", { value: this.value });
210
+ });
211
+ dial.addEventListener("pointercancel", () => (this.dragging = false));
212
+ }
213
+ render() {
214
+ if (!this.querySelector(":scope > .k-clock"))
215
+ this.build();
216
+ const M = msg().timePicker;
217
+ const h = this.current === null ? null : Math.floor(this.current / 60);
218
+ const m = this.current === null ? null : this.current % 60;
219
+ const hour = this.mode === "hour";
220
+ const nums = hour
221
+ ? Array.from({ length: 24 }, (_, hh) => ({ label: hh === 0 ? "00" : String(hh), angle: hourAngle(hh), r: isInner(hh) ? INNER : OUTER, ring: isInner(hh) ? "inner" : "outer", on: h === hh, off: !this.hourOk(hh) }))
222
+ : Array.from({ length: 12 }, (_, i) => ({ label: pad(i * 5), angle: i * 30, r: OUTER, ring: "outer", on: m === i * 5, off: h !== null && !this.minuteOk(h, i * 5) }));
223
+ const handAngle = this.current === null ? null : hour ? hourAngle(h) : m * 6;
224
+ const handR = hour && h !== null && isInner(h) ? INNER : OUTER;
225
+ const numHTML = nums.map((n) => {
226
+ const a = (n.angle * Math.PI) / 180;
227
+ return `<span class="k-clock__num" data-ring="${n.ring}"${n.on ? ' data-selected=""' : ""}${n.off ? ' data-disabled=""' : ""} aria-hidden="true" style="left:${+(50 + Math.sin(a) * n.r).toFixed(2)}%;top:${+(50 - Math.cos(a) * n.r).toFixed(2)}%">${this.f(n.label)}</span>`;
228
+ }).join("");
229
+ const valueNow = hour ? h : m;
230
+ this.querySelector(".k-clock").setAttribute("aria-label", this.getAttribute("aria-label") ?? M.clock);
231
+ for (const [b, v, n, label] of [
232
+ [this.querySelector('.k-clock__unit[data-view="hour"]'), "hour", h, M.hour],
233
+ [this.querySelector('.k-clock__unit[data-view="minute"]'), "minute", m, M.minute],
234
+ ]) {
235
+ b.textContent = n === null ? "--" : this.f(pad(n));
236
+ b.setAttribute("aria-pressed", String(this.mode === v));
237
+ b.setAttribute("aria-label", n === null ? label : `${label} ${this.f(pad(n))}`);
238
+ }
239
+ const dial = this.querySelector(".k-clock__dial");
240
+ dial.dataset.view = this.mode;
241
+ dial.setAttribute("aria-label", hour ? M.hour : M.minute);
242
+ dial.setAttribute("aria-valuemax", hour ? "23" : "59");
243
+ if (valueNow === null) {
244
+ dial.removeAttribute("aria-valuenow");
245
+ dial.removeAttribute("aria-valuetext");
246
+ }
247
+ else {
248
+ dial.setAttribute("aria-valuenow", String(valueNow));
249
+ dial.setAttribute("aria-valuetext", this.f(this.value));
250
+ }
251
+ dial.innerHTML = `<span class="k-clock__center" aria-hidden="true"></span>`
252
+ + (handAngle === null ? "" : `<span class="k-clock__hand" aria-hidden="true"${!hour && m % 5 ? ' data-free=""' : ""} style="height:${handR}%;rotate:${handAngle}deg"></span>`)
253
+ + numHTML;
254
+ this.rendered = true;
255
+ }
256
+ }
257
+ KashiTimeClock.observedAttributes = ["value", "view", "min", "max", "step", "digits", "aria-label"];
258
+ /**
259
+ * انتخاب ساعت: تایپ مستقیم (۰۹:۳۰) یا انتخاب از صفحهٔ ساعت؛ تغییرها تا «تأیید» پیش‌نویس‌اند و Esc بدون تغییر می‌بندد.
260
+ * با name، مقدار به شکل HH:MM با ارقام لاتین در فرم ارسال می‌شود.
261
+ */
262
+ export class KashiTimePicker extends HTMLBase {
263
+ constructor() {
264
+ super(...arguments);
265
+ this.current = null;
266
+ this.invalid = false;
267
+ this.valueSet = false;
268
+ this.rendered = false;
269
+ this.key = uid("kashi-timepicker");
270
+ this.pop = null;
271
+ this.onOutside = (e) => {
272
+ if (!this.contains(e.target))
273
+ this.close(false);
274
+ };
275
+ }
276
+ connectedCallback() {
277
+ if (!this.rendered && !this.valueSet)
278
+ this.current = toMin(this.getAttribute("value"));
279
+ this.render();
280
+ }
281
+ disconnectedCallback() {
282
+ this.close(false);
283
+ }
284
+ attributeChangedCallback(name, old, next) {
285
+ if (!this.rendered || old === next)
286
+ return;
287
+ if (name === "value")
288
+ this.value = next ?? "";
289
+ else
290
+ this.render();
291
+ }
292
+ /** ساعت به شکل HH:MM، یا رشتهٔ خالی */
293
+ get value() {
294
+ return this.current === null ? "" : fmt(this.current);
295
+ }
296
+ set value(v) {
297
+ this.valueSet = true;
298
+ this.current = toMin(v);
299
+ this.invalid = false;
300
+ if (this.rendered)
301
+ this.paint();
302
+ }
303
+ focus(options) {
304
+ this.input?.focus(options);
305
+ }
306
+ get step() {
307
+ return Math.max(1, Number(this.getAttribute("step")) || 5);
308
+ }
309
+ get lo() {
310
+ return toMin(this.getAttribute("min")) ?? 0;
311
+ }
312
+ get hi() {
313
+ return toMin(this.getAttribute("max")) ?? DAY - 1;
314
+ }
315
+ show(m) {
316
+ return m === null ? "" : digitsOf(this) === "latin" ? fmt(m) : toFaDigits(fmt(m));
317
+ }
318
+ get openLabel() {
319
+ return this.getAttribute("open-label") ?? msg().timePicker.open;
320
+ }
321
+ render() {
322
+ const id = this.key;
323
+ const ariaLabel = this.getAttribute("aria-label");
324
+ const label = this.hasAttribute("label") ? this.getAttribute("label") : ariaLabel ? null : msg().persianInput.time;
325
+ const required = this.hasAttribute("required");
326
+ const disabled = this.hasAttribute("disabled");
327
+ const fa = digitsOf(this) === "fa";
328
+ this.close(false);
329
+ this.querySelector(":scope > .k-timepicker")?.remove();
330
+ const control = `<div class="k-input"${disabled ? ' data-state="disabled"' : ""}><input id="${id}" class="k-input__control" type="text" inputmode="numeric" dir="ltr" autocomplete="off" placeholder="${esc(this.getAttribute("placeholder") ?? (fa ? "۰۹:۳۰" : "09:30"))}"${required ? " required" : ""}${disabled ? " disabled" : ""}${!label && ariaLabel ? ` aria-label="${esc(ariaLabel)}"` : ""}><span class="k-input__addon"><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-datepicker__toggle" aria-haspopup="dialog" aria-expanded="false"${disabled ? " disabled" : ""}>${CLOCK}</button></span></div>`;
331
+ this.insertAdjacentHTML("afterbegin", `<div class="k-datepicker k-timepicker">${fieldHTML({ id, label, required, control })}</div>`);
332
+ this.input = this.querySelector("input.k-input__control");
333
+ this.toggle = this.querySelector(".k-datepicker__toggle");
334
+ this.input.addEventListener("blur", () => this.commitText());
335
+ this.input.addEventListener("keydown", (e) => {
336
+ if (e.key === "Enter")
337
+ this.commitText();
338
+ if (e.key !== "ArrowUp" && e.key !== "ArrowDown")
339
+ return;
340
+ e.preventDefault();
341
+ const base = toMin(this.input.value) ?? this.current ?? this.lo;
342
+ const s = this.step;
343
+ const next = e.key === "ArrowUp" ? Math.floor(base / s) * s + s : Math.ceil(base / s) * s - s;
344
+ this.commit(Math.min(this.hi, Math.max(this.lo, next)));
345
+ });
346
+ this.toggle.addEventListener("click", () => (this.pop ? this.close() : this.open()));
347
+ this.rendered = true;
348
+ this.paint();
349
+ }
350
+ paint(syncText = true) {
351
+ if (syncText)
352
+ this.input.value = this.show(this.current);
353
+ const text = this.invalid === "range"
354
+ ? msg().invalid.timeRange(this.show(this.lo), this.show(this.hi))
355
+ : this.invalid ? msg().invalid.time : null;
356
+ this.input.setCustomValidity(text ?? "");
357
+ this.toggle.setAttribute("aria-label", this.current === null ? this.openLabel : `${this.openLabel}${msg().common.list}${this.show(this.current)}`);
358
+ setMessages(this.querySelector(".k-field"), this.input, this.key, this.getAttribute("error") || text, this.getAttribute("hint"));
359
+ syncHidden(this, this.getAttribute("name"), this.value);
360
+ }
361
+ commitText() {
362
+ const t = this.input.value.trim();
363
+ if (!t)
364
+ return this.commit(null);
365
+ const m = toMin(t);
366
+ if (m === null)
367
+ this.invalid = "format";
368
+ else if (m < this.lo || m > this.hi)
369
+ this.invalid = "range";
370
+ else
371
+ return this.commit(m);
372
+ this.paint(false);
373
+ }
374
+ commit(m) {
375
+ const changed = m !== this.current;
376
+ this.current = m;
377
+ this.invalid = false;
378
+ this.paint();
379
+ if (changed)
380
+ emit(this, "kashi-change", { value: this.value });
381
+ }
382
+ /** باز کردن صفحهٔ ساعت */
383
+ open() {
384
+ if (this.pop || this.hasAttribute("disabled"))
385
+ return;
386
+ const wrap = this.querySelector(".k-timepicker");
387
+ const box = this.querySelector(".k-input");
388
+ const pop = document.createElement("div");
389
+ pop.className = "k-datepicker__popover k-timepicker__popover";
390
+ pop.id = `${this.key}-clock`;
391
+ pop.setAttribute("role", "dialog");
392
+ pop.setAttribute("aria-label", this.openLabel);
393
+ pop.style.insetBlockStart = `${box.offsetTop + box.offsetHeight + 6}px`;
394
+ const clock = document.createElement("kashi-time-clock");
395
+ for (const a of ["min", "max", "step", "digits"]) {
396
+ const v = this.getAttribute(a);
397
+ if (v !== null)
398
+ clock.setAttribute(a, v);
399
+ }
400
+ if (this.current !== null)
401
+ clock.value = fmt(this.current);
402
+ const footer = document.createElement("div");
403
+ footer.className = "k-timepicker__footer";
404
+ footer.innerHTML = (this.hasAttribute("no-now") ? "<span></span>" : `<button type="button" class="k-btn k-btn--link" data-now>${esc(msg().timePicker.now)}</button>`)
405
+ + `<button type="button" class="k-btn k-btn--primary k-btn--sm" data-confirm${this.current === null ? " disabled" : ""}>${esc(msg().common.confirm)}</button>`;
406
+ const confirm = footer.querySelector("[data-confirm]");
407
+ // تغییرهای روی ساعت پیش‌نویس‌اند؛ فقط «تأیید» آن‌ها را ثبت می‌کند
408
+ clock.addEventListener("kashi-change", (e) => {
409
+ e.stopPropagation();
410
+ confirm.disabled = false;
411
+ });
412
+ clock.addEventListener("kashi-complete", (e) => {
413
+ e.stopPropagation();
414
+ confirm.focus();
415
+ });
416
+ footer.querySelector("[data-now]")?.addEventListener("click", () => {
417
+ const d = new Date();
418
+ const s = this.step;
419
+ const mins = (Math.round((d.getHours() * 60 + d.getMinutes()) / s) * s) % DAY;
420
+ clock.value = fmt(Math.min(this.hi, Math.max(this.lo, mins)));
421
+ clock.view = "minute";
422
+ confirm.disabled = false;
423
+ confirm.focus();
424
+ });
425
+ confirm.addEventListener("click", () => {
426
+ this.commit(toMin(clock.value));
427
+ this.close();
428
+ });
429
+ pop.addEventListener("keydown", (e) => {
430
+ if (e.key === "Escape") {
431
+ e.stopPropagation();
432
+ this.close();
433
+ }
434
+ });
435
+ pop.addEventListener("focusout", (e) => {
436
+ // رویداد دیررسِ پنجرهٔ قبلی (پس از Esc و باز کردن دوباره) نباید پنجرهٔ تازه را ببندد
437
+ if (this.pop !== pop)
438
+ return;
439
+ const next = e.relatedTarget;
440
+ if (next && !this.contains(next))
441
+ this.close(false);
442
+ });
443
+ pop.append(clock, footer);
444
+ wrap.append(pop);
445
+ this.pop = pop;
446
+ this.toggle.setAttribute("aria-expanded", "true");
447
+ this.toggle.setAttribute("aria-controls", pop.id);
448
+ document.addEventListener("pointerdown", this.onOutside);
449
+ clock.focus();
450
+ }
451
+ /** بستن صفحهٔ ساعت بدون ثبت؛ فوکوس به دکمهٔ ساعت برمی‌گردد */
452
+ close(returnFocus = true) {
453
+ if (!this.pop)
454
+ return;
455
+ this.pop.remove();
456
+ this.pop = null;
457
+ document.removeEventListener("pointerdown", this.onOutside);
458
+ this.toggle.setAttribute("aria-expanded", "false");
459
+ this.toggle.removeAttribute("aria-controls");
460
+ if (returnFocus)
461
+ this.toggle.focus();
462
+ }
463
+ }
464
+ KashiTimePicker.observedAttributes = ["label", "hint", "error", "value", "min", "max", "step", "digits", "required", "disabled", "name", "placeholder", "open-label", "no-now", "aria-label"];
465
+ define("kashi-time-clock", KashiTimeClock, "block");
466
+ define("kashi-time-picker", KashiTimePicker, "block");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashi-ui/elements",
3
- "version": "2.18.0",
3
+ "version": "2.20.0",
4
4
  "description": "وب کامپوننت‌های کاشی: فیلدهای فارسی، تقویم شمسی و کامپوننت‌های تعاملی بدون React؛ برای HTML، Vue، Svelte، Angular و وردپرس",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,6 +11,7 @@
11
11
  "default": "./dist/index.js"
12
12
  },
13
13
  "./cdn": "./dist/cdn/kashi-elements.js",
14
+ "./manifest.json": "./dist/manifest.json",
14
15
  "./*.js": {
15
16
  "types": "./dist/*.d.ts",
16
17
  "default": "./dist/*.js"
@@ -23,15 +24,15 @@
23
24
  ],
24
25
  "sideEffects": true,
25
26
  "scripts": {
26
- "build": "node scripts/sync-map.mjs && tsc -p tsconfig.json && node scripts/bundle.mjs",
27
+ "build": "node scripts/sync-map.mjs && tsc -p tsconfig.json && node scripts/bundle.mjs && node scripts/manifest.mjs",
27
28
  "test": "node --test test/*.test.mjs"
28
29
  },
29
30
  "dependencies": {
30
- "@kashi-ui/bank-logos": "^2.18.0",
31
- "@kashi-ui/persian": "^2.18.0"
31
+ "@kashi-ui/bank-logos": "^2.20.0",
32
+ "@kashi-ui/persian": "^2.20.0"
32
33
  },
33
34
  "peerDependencies": {
34
- "@kashi-ui/css": "^2.18.0"
35
+ "@kashi-ui/css": "^2.20.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "happy-dom": "^21.0.4",