@kashi-ui/elements 0.25.0 → 0.26.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 +2 -1
- package/dist/appointment.d.ts +40 -0
- package/dist/appointment.js +174 -0
- package/dist/base.js +2 -0
- package/dist/basic.d.ts +43 -0
- package/dist/basic.js +223 -0
- package/dist/cdn/appointment-DkMxtSWi.js +1 -0
- package/dist/cdn/base-DfzNTdQk.js +1 -0
- package/dist/cdn/basic-B5n1okZO.js +1 -0
- package/dist/cdn/calendar-oMlnK1_D.js +16 -0
- package/dist/cdn/{charts-DNOWi4sJ.js → charts-SHKq2S4I.js} +1 -1
- package/dist/cdn/{combobox-ZGrZ5okg.js → combobox-DiGy7lAB.js} +1 -1
- package/dist/cdn/{controls-K-OZcjg4.js → controls-C6zwNYWs.js} +1 -1
- package/dist/cdn/{display-C975tS7j.js → display-DZFW9EEX.js} +1 -1
- package/dist/cdn/{fields-BUTaSN8m.js → fields-D2hmrvVR.js} +1 -1
- package/dist/cdn/forms-CeItYHFx.js +1 -0
- package/dist/cdn/holidays-BwsAEOI1.js +1 -0
- package/dist/cdn/{inputs-BjOddAM7.js → inputs-DuP7P3ka.js} +1 -1
- package/dist/cdn/kashi-elements.js +1 -1
- package/dist/cdn/{map-BHuusa4t.js → map-w5X2fTQI.js} +1 -1
- package/dist/cdn/{menu-DhrqyLgy.js → menu-Cga7QOfs.js} +1 -1
- package/dist/cdn/{nav-D_w5BV_K.js → nav-CwPZ20z-.js} +1 -1
- package/dist/cdn/{overlay-DX9un2xm.js → overlay-BDzwsBN5.js} +1 -1
- package/dist/cdn/{pickers-BFLpUruK.js → pickers-BOpaZ-7q.js} +1 -1
- package/dist/cdn/{table-DPQfDMs-.js → table-BdF43L5q.js} +1 -1
- package/dist/cdn/time-DXw4vOne.js +1 -0
- package/dist/cdn.js +2 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +4 -1
- package/package.json +4 -4
- package/dist/cdn/base-Cmq7zeIG.js +0 -1
- package/dist/cdn/calendar-Dm3fq2bs.js +0 -16
- package/dist/cdn/forms-C-effPKn.js +0 -1
package/dist/index.js
CHANGED
|
@@ -10,12 +10,14 @@ import { KashiDataTable } from "./table.js";
|
|
|
10
10
|
import { KashiChipGroup, KashiInlineEdit, KashiKeyboardFix, KashiMultiSelect, KashiPasswordStrength, KashiPersianTextarea, KashiPlateInput, KashiSlider, KashiTimeInput, } from "./forms.js";
|
|
11
11
|
import { KashiColorPicker, KashiDateRangePicker, KashiFileUpload, KashiMonthPicker } from "./pickers.js";
|
|
12
12
|
import { KashiActivityHeatmap, KashiBarChart, KashiBarList, KashiLineChart, KashiPieChart, KashiProportionBar, KashiSparkline, } from "./charts.js";
|
|
13
|
+
import { KashiBanner, KashiInput, KashiTextarea } from "./basic.js";
|
|
14
|
+
import { KashiAppointmentPicker } from "./appointment.js";
|
|
13
15
|
import { KashiCarousel, KashiCommandPalette, KashiContextMenu, KashiSideNav, KashiSplitter, KashiTour, KashiTreeView } from "./nav.js";
|
|
14
16
|
import { KashiCalendar, KashiDatePicker } from "./calendar.js";
|
|
15
17
|
import { KashiCountdown, KashiDate, KashiMoney, KashiRelativeTime } from "./display.js";
|
|
16
18
|
import { KashiCopyButton, KashiDialog, KashiTabs, KashiTooltip } from "./overlay.js";
|
|
17
19
|
import { KashiToaster, toast } from "./toast.js";
|
|
18
|
-
export { KashiCardNumber, KashiIban, KashiLandline, KashiLegalId, KashiMobile, KashiNationalId, KashiPostalCode, KashiPrice, KashiOtp, KashiProvinceSelect, KashiCombobox, KashiCitySelect, KashiIranMap, KashiAddressForm, KashiCalendar, KashiDatePicker, KashiCountdown, KashiDate, KashiMoney, KashiRelativeTime, KashiCopyButton, KashiDialog, KashiTabs, KashiTooltip, KashiToaster, toast, KashiDropdownMenu, KashiPopover, KashiTagInput, KashiNumberInput, KashiRating, KashiPagination, KashiDataTable, KashiMultiSelect, KashiSlider, KashiChipGroup, KashiPasswordStrength, KashiPersianTextarea, KashiKeyboardFix, KashiTimeInput, KashiPlateInput, KashiInlineEdit, KashiDateRangePicker, KashiMonthPicker, KashiFileUpload, KashiColorPicker, KashiBarChart, KashiLineChart, KashiPieChart, KashiBarList, KashiProportionBar, KashiSparkline, KashiActivityHeatmap, KashiCommandPalette, KashiContextMenu, KashiCarousel, KashiTreeView, KashiTour, KashiSplitter, KashiSideNav, };
|
|
20
|
+
export { KashiCardNumber, KashiIban, KashiLandline, KashiLegalId, KashiMobile, KashiNationalId, KashiPostalCode, KashiPrice, KashiOtp, KashiProvinceSelect, KashiCombobox, KashiCitySelect, KashiIranMap, KashiAddressForm, KashiCalendar, KashiDatePicker, KashiCountdown, KashiDate, KashiMoney, KashiRelativeTime, KashiCopyButton, KashiDialog, KashiTabs, KashiTooltip, KashiToaster, toast, KashiDropdownMenu, KashiPopover, KashiTagInput, KashiNumberInput, KashiRating, KashiPagination, KashiDataTable, KashiMultiSelect, KashiSlider, KashiChipGroup, KashiPasswordStrength, KashiPersianTextarea, KashiKeyboardFix, KashiTimeInput, KashiPlateInput, KashiInlineEdit, KashiDateRangePicker, KashiMonthPicker, KashiFileUpload, KashiColorPicker, KashiBarChart, KashiLineChart, KashiPieChart, KashiBarList, KashiProportionBar, KashiSparkline, KashiActivityHeatmap, KashiCommandPalette, KashiContextMenu, KashiCarousel, KashiTreeView, KashiTour, KashiSplitter, KashiSideNav, KashiInput, KashiTextarea, KashiBanner, KashiAppointmentPicker, };
|
|
19
21
|
export { KashiDigitsInput } from "./inputs.js";
|
|
20
22
|
/** نام همهٔ عنصرها؛ مثلاً برای isCustomElement در Vue */
|
|
21
23
|
export const KASHI_ELEMENTS = [
|
|
@@ -29,4 +31,5 @@ export const KASHI_ELEMENTS = [
|
|
|
29
31
|
"kashi-date-range-picker", "kashi-month-picker", "kashi-file-upload", "kashi-color-picker",
|
|
30
32
|
"kashi-bar-chart", "kashi-line-chart", "kashi-pie-chart", "kashi-bar-list", "kashi-proportion-bar", "kashi-sparkline", "kashi-activity-heatmap",
|
|
31
33
|
"kashi-command-palette", "kashi-context-menu", "kashi-carousel", "kashi-tree-view", "kashi-tour", "kashi-splitter", "kashi-side-nav",
|
|
34
|
+
"kashi-input", "kashi-textarea", "kashi-banner", "kashi-appointment-picker",
|
|
32
35
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashi-ui/elements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "وب کامپوننتهای کاشی: فیلدهای فارسی، تقویم شمسی و کامپوننتهای تعاملی بدون React؛ برای HTML، Vue، Svelte، Angular و وردپرس",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"test": "node --test test/*.test.mjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@kashi-ui/bank-logos": "^0.
|
|
31
|
-
"@kashi-ui/persian": "^0.
|
|
30
|
+
"@kashi-ui/bank-logos": "^0.26.0",
|
|
31
|
+
"@kashi-ui/persian": "^0.26.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@kashi-ui/css": "^0.
|
|
34
|
+
"@kashi-ui/css": "^0.26.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"happy-dom": "^21.0.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=typeof HTMLElement>`u`?class{}:HTMLElement,t=[],n=[];let r=null;function i(e,i,o=`inline`){if(typeof customElements>`u`||customElements.get(e)||(o===`block`&&t.push(e),o===`contents`&&n.push(e),a(i),customElements.define(e,i),typeof document>`u`))return;r||(r=document.createElement(`style`),r.dataset.kashiElements=``,document.head.prepend(r));let s=[t.length&&`:where(${t.join(`,`)}) { display: block; }`,n.length&&`:where(${n.join(`,`)}) { display: contents; }`].filter(Boolean);r.textContent=`@layer kashi.elements { ${s.join(` `)} }`}function a(t){let n=/* @__PURE__ */ new Set;for(let r=t.prototype;r&&r!==e.prototype;r=Object.getPrototypeOf(r))for(let[e,t]of Object.entries(Object.getOwnPropertyDescriptors(r)))t.set&&n.add(e);let r=t.prototype.connectedCallback;t.prototype.connectedCallback=function(){for(let e of n){if(!Object.prototype.hasOwnProperty.call(this,e))continue;let t=this[e];delete this[e],this[e]=t}r?.call(this)}}function o(e){typeof document<`u`&&document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,e,{once:!0}):e()}let s=0;const c=e=>`${e}-${(++s).toString(36)}`,l={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},u=e=>String(e??``).replace(/[&<>"']/g,e=>l[e]),d=(e,t,n=!1)=>{let r=e.getAttribute(t);return r===null?n:r!==`false`};function f(e,t,n){e.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0,composed:!0}))}const p=(e,t=1.7,n=!1)=>`<svg${n?` data-k-mirror=""`:``} viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="${t}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,m={close:p(`<path d="m5 5 10 10M15 5 5 15"/>`),info:p(`<circle cx="10" cy="10" r="7.5"/><path d="M10 13.5V9.5M10 6.5h.01"/>`),success:p(`<circle cx="10" cy="10" r="7.5"/><path d="m6.75 10 2.25 2.25 4.25-4.5"/>`),warning:p(`<path d="M8.6 3.4 2.4 14a1.6 1.6 0 0 0 1.4 2.4h12.4a1.6 1.6 0 0 0 1.4-2.4L11.4 3.4a1.6 1.6 0 0 0-2.8 0Z"/><path d="M10 7.5v3.25M10 13.5h.01"/>`),error:p(`<circle cx="10" cy="10" r="7.5"/><path d="M10 6.5v4M10 13.5h.01"/>`),copy:p(`<rect x="7" y="7" width="10" height="10" rx="2"/><path d="M13 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"/>`),check:p(`<path d="m5 10.5 3.2 3L15 7"/>`,2),calendar:p(`<rect x="3" y="4.5" width="14" height="12.5" rx="2"/><path d="M3 8.5h14M7 3v3M13 3v3"/>`),prev:p(`<path d="m12 5-5 5 5 5"/>`,1.7,!0),next:p(`<path d="m8 5 5 5-5 5"/>`,1.7,!0)};function h({id:e,label:t,required:n,optional:r,control:i}){return`<div class="k-field">${t?`<div class="k-field__label-row"><label class="k-label" for="${e}">${u(t)}${n?`<span class="k-label__required" aria-hidden="true">*</span>`:``}${r?`<span class="k-label__optional">${u(r)}</span>`:``}</label></div>`:``}${i}</div>`}function g(e,t,n,r,i,a){if(e.querySelector(`:scope > .k-field__hint-row`)?.remove(),r?e.setAttribute(`data-invalid`,``):e.removeAttribute(`data-invalid`),r||i){let t=document.createElement(`div`);t.className=`k-field__hint-row`,t.innerHTML=`<div class="k-field__hints">${r?`<p class="k-hint k-hint--error" id="${n}-error">${u(r)}</p>`:``}${i?`<p class="k-hint" id="${n}-hint">${u(i)}</p>`:``}</div>`,e.append(t)}let o=[a,r?`${n}-error`:null,i?`${n}-hint`:null].filter(Boolean).join(` `);o?t.setAttribute(`aria-describedby`,o):t.removeAttribute(`aria-describedby`),r?t.setAttribute(`aria-invalid`,`true`):t.removeAttribute(`aria-invalid`);let s=t.closest(`.k-input, .k-select, .k-otp`);s?.classList.contains(`k-input`)&&(r?s.setAttribute(`data-state`,`invalid`):s.getAttribute(`data-state`)===`invalid`&&s.removeAttribute(`data-state`))}function _(e,t,n){let r=e.querySelector(`:scope > input[type=hidden][data-kashi-value]`);t?(r||(r=document.createElement(`input`),r.type=`hidden`,r.dataset.kashiValue=``,e.append(r)),r.name=t,r.value=n):r?.remove()}export{i as a,h as c,c as d,d as i,g as l,m as n,f as o,o as r,u as s,e as t,_ as u};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,i as r,l as i,n as a,o,s,t as c,u as l}from"./base-Cmq7zeIG.js";import{i as u}from"./digits-DE1YGT94.js";import{a as d,c as f,d as p,i as m,l as h,n as g,o as _,r as v,s as y,t as b,u as x}from"./jalali-BiM5Kfep.js";const S={"1-1":`عید نوروز`,"1-2":`عید نوروز`,"1-3":`عید نوروز`,"1-4":`عید نوروز`,"1-12":`روز جمهوری اسلامی`,"1-13":`روز طبیعت`,"3-14":`رحلت امام خمینی`,"3-15":`قیام ۱۵ خرداد`,"11-22":`پیروزی انقلاب اسلامی`,"12-29":`ملی شدن صنعت نفت`};function C(e,{extra:t={},friday:n=!0}={}){let{jm:r,jd:i}=p(e);return t[`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`]??t[`${r}-${i}`]??S[`${r}-${i}`]??(n&&e.getDay()===5?`جمعه`:null)}const w=(e,t)=>!!e&&!!t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),T=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),E=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),D=e=>`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()}`;function O(e,t){let{jy:n,jm:r,jd:i}=p(e),a=n*12+(r-1)+t,o=Math.floor(a/12),s=a-o*12+1;return h(o,s,Math.min(i,_(o,s)))}const k=e=>e?d(e.trim())??f(e):null;var A=class extends c{constructor(){super(...arguments),this.rangeValue=null,this.hover=null,this.selected=null,this.valueSet=!1,this.focused=T(/* @__PURE__ */ new Date),this.refocus=!1,this.rendered=!1,this.key=n(`kashi-cal`),this.onClick=e=>{let t=e.target.closest(`button`);if(!t||!this.contains(t))return;let n=t.dataset.nav;if(n)this.go(O(this.focused,n===`prev`?-1:1),!1);else if(t.dataset.today!==void 0){let e=/* @__PURE__ */ new Date;this.pick(new Date(e.getFullYear(),e.getMonth(),e.getDate()))}else if(t.dataset.day){let[e,n,r]=t.dataset.day.split(`-`).map(Number);this.pick(new Date(e,n-1,r))}},this.onSelect=e=>{let t=e.target;if(!t.matches?.(`.k-calendar__select`))return;e.stopPropagation();let{jy:n,jm:r,jd:i}=p(this.focused),a=t.dataset.part===`year`?Number(t.value):n,o=t.dataset.part===`month`?Number(t.value):r;this.go(h(a,o,Math.min(i,_(a,o))),!1),this.querySelector(`.k-calendar__select[data-part="${t.dataset.part}"]`)?.focus()},this.onKey=e=>{if(!e.target.classList?.contains(`k-calendar__day`))return;let t=getComputedStyle(this).direction===`rtl`,n=this.focused,r=y(n),i={ArrowLeft:()=>E(n,t?1:-1),ArrowRight:()=>E(n,t?-1:1),ArrowUp:()=>E(n,-7),ArrowDown:()=>E(n,7),Home:()=>E(n,-r),End:()=>E(n,6-r),PageUp:()=>O(n,e.shiftKey?-12:-1),PageDown:()=>O(n,e.shiftKey?12:1)};i[e.key]&&(e.preventDefault(),this.go(i[e.key]()))}}get range(){return this.rangeValue}set range(e){this.rangeValue=e,e?.start&&(this.focused=this.clamp(T(e.start))),this.rendered&&this.render()}connectedCallback(){if(!this.rendered){this.valueSet||(this.selected=k(this.getAttribute(`value`))),this.focused=this.clamp(T(this.selected??/* @__PURE__ */ new Date)),this.addEventListener(`click`,this.onClick),this.addEventListener(`keydown`,this.onKey),this.addEventListener(`change`,this.onSelect);let e=e=>{let t=e.target.closest?.(`.k-calendar__day`)?.dataset.day;if(!this.rangeValue?.start||this.rangeValue.end||!t)return;let[n,r,i]=t.split(`-`).map(Number);this.hover=new Date(n,r-1,i),this.paintRange()};this.addEventListener(`pointerover`,e),this.addEventListener(`focusin`,e)}this.rendered=!0,this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`&&(this.selected=k(n),this.selected&&(this.focused=T(this.selected))),this.render())}get value(){return this.selected?x(this.selected):``}set value(e){this.valueSet=!0,this.selected=k(e??``),this.selected&&(this.focused=T(this.selected)),this.rendered&&this.render()}get date(){return this.selected}set date(e){this.value=e?x(e):``}focus(){this.querySelector(`.k-calendar__day[tabindex="0"]`)?.focus()}get min(){return k(this.getAttribute(`min`))}get max(){return k(this.getAttribute(`max`))}clamp(e){let t=this.min,n=this.max;return t&&e<t?T(t):n&&e>n?T(n):e}disabled(e){let t=this.min,n=this.max;return!!t&&e<t||!!n&&e>n||!!this.isDateDisabled?.(e)}holiday(e){return this.holidayOf?this.holidayOf(e)||null:r(this,`holidays`)?C(e):null}go(e,t=!0){this.focused=this.clamp(e),this.refocus=t,this.render()}pick(e){this.disabled(e)||(this.selected=e,this.focused=e,this.refocus=!0,this.render(),l(this,this.getAttribute(`name`),this.value),o(this,`kashi-change`,{value:this.value,date:e}))}paintRange(){let e=this.rangeValue;if(!e)return;let t=e.start?T(e.start):null,n=e.end?T(e.end):null,r=t&&!n&&this.hover?this.hover:null,[i,a]=t&&(n||r)?[t,n??r].sort((e,t)=>+e-t):[t,t];this.querySelectorAll(`td[data-date]`).forEach(e=>{let[t,r,o]=e.dataset.date.split(`-`).map(Number),s=new Date(t,r-1,o),c=!!i&&!!a&&s>=i&&s<=a;e.setAttribute(`aria-selected`,String(c)),e.toggleAttribute(`data-in-range`,c&&!!n),e.toggleAttribute(`data-preview`,c&&!n),e.toggleAttribute(`data-range-start`,!!i&&w(s,i)),e.toggleAttribute(`data-range-end`,!!a&&w(s,a))})}render(){let e=this.getAttribute(`digits`)===`latin`?`latin`:`fa`,t=t=>e===`fa`?u(t):String(t),n=T(/* @__PURE__ */ new Date),{jy:r,jm:i}=p(this.focused),o=h(r,i,1),c=_(r,i),d=[...Array(y(o)).fill(null),...Array.from({length:c},(e,t)=>E(o,t))];for(;d.length%7;)d.push(null);let f=this.min,x=this.max,S=f?p(f).jy:p(n).jy-100,C=x?p(x).jy:p(n).jy+20,O=Array.from({length:Math.max(0,C-S+1)},(e,t)=>S+t);O.includes(r)||O.push(r),O.sort((e,t)=>e-t);let k=!!f&&o<=T(f),A=!!x&&h(r,i,c)>=T(x),j=[];for(let r=0;r<d.length;r+=7)j.push(`<tr>${d.slice(r,r+7).map(r=>{if(!r)return`<td role="gridcell"></td>`;let i=this.holiday(r),a=m(r,{style:`full`,digits:e})+(i?`، تعطیل${i===`جمعه`?``:`: ${i}`}`:``);return`<td role="gridcell" data-date="${D(r)}" aria-selected="${w(r,this.selected)}"><button type="button" class="k-calendar__day" data-day="${D(r)}" tabindex="${w(r,this.focused)?0:-1}" aria-label="${s(a)}"${i&&i!==`جمعه`?` title="${s(i)}"`:``}${i?` data-holiday=""`:``}${w(r,n)?` aria-current="date"`:``}${this.disabled(r)?` aria-disabled="true"`:``}>${t(p(r).jd)}</button></td>`}).join(``)}</tr>`);let M=this.getAttribute(`today-label`);this.innerHTML=`<div class="k-calendar" role="group" aria-label="${s(this.getAttribute(`label`)??`تقویم`)}">
|
|
2
|
-
<div class="k-calendar__header">
|
|
3
|
-
<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-nav="prev" aria-label="ماه قبل"${k?` disabled`:``}>${a.prev}</button>
|
|
4
|
-
<div class="k-calendar__selects">
|
|
5
|
-
<select class="k-calendar__select" data-part="month" aria-label="ماه">${b.map((e,t)=>`<option value="${t+1}"${t+1===i?` selected`:``}>${e}</option>`).join(``)}</select>
|
|
6
|
-
<select class="k-calendar__select" data-part="year" aria-label="سال">${O.map(e=>`<option value="${e}"${e===r?` selected`:``}>${t(e)}</option>`).join(``)}</select>
|
|
7
|
-
</div>
|
|
8
|
-
<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-nav="next" aria-label="ماه بعد"${A?` disabled`:``}>${a.next}</button>
|
|
9
|
-
</div>
|
|
10
|
-
<h2 class="k-sr-only" id="${this.key}-title" aria-live="polite">${b[i-1]} ${t(r)}</h2>
|
|
11
|
-
<table class="k-calendar__grid" role="grid" aria-labelledby="${this.key}-title">
|
|
12
|
-
<thead><tr>${v.map((e,t)=>`<th scope="col" abbr="${g[t]}">${e}</th>`).join(``)}</tr></thead>
|
|
13
|
-
<tbody>${j.join(``)}</tbody>
|
|
14
|
-
</table>
|
|
15
|
-
${M?`<div class="k-calendar__footer"><button type="button" class="k-btn k-btn--link" data-today>${s(M)}</button></div>`:``}
|
|
16
|
-
</div>`,l(this,this.getAttribute(`name`),this.value),this.paintRange(),this.refocus&&(this.refocus=!1,this.querySelector(`[data-day="${D(this.focused)}"]`)?.focus())}};A.observedAttributes=[`value`,`min`,`max`,`digits`,`holidays`,`label`,`today-label`,`name`];var j=class extends c{constructor(){super(...arguments),this.selected=null,this.valueSet=!1,this.invalid=!1,this.rendered=!1,this.key=n(`kashi-date`),this.pop=null,this.onOutside=e=>{this.contains(e.target)||this.close(!1)}}connectedCallback(){!this.rendered&&!this.valueSet&&(this.selected=k(this.getAttribute(`value`))),this.render()}disconnectedCallback(){this.close(!1)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?(this.selected=k(n),this.invalid=!1,this.paint()):this.render())}get value(){return this.selected?x(this.selected):``}set value(e){this.valueSet=!0,this.selected=k(e??``),this.invalid=!1,this.rendered&&this.paint()}get date(){return this.selected}set date(e){this.value=e?x(e):``}focus(e){this.input?.focus(e)}get digits(){return this.getAttribute(`digits`)===`latin`?`latin`:`fa`}fmt(e){return e?m(e,{digits:this.digits}):``}render(){let e=this.key,n=this.getAttribute(`aria-label`),r=this.hasAttribute(`label`)?this.getAttribute(`label`):n?null:`تاریخ`,i=this.hasAttribute(`required`),o=this.hasAttribute(`disabled`),c=this.getAttribute(`placeholder`)??(this.digits===`fa`?`۱۴۰۳/۰۱/۰۱`:`1403/01/01`);this.close(!1),this.querySelector(`:scope > .k-datepicker`)?.remove();let l=`<div class="k-input"${o?` data-state="disabled"`:``}><input id="${e}" class="k-input__control" type="text" dir="ltr" autocomplete="off" placeholder="${s(c)}"${i?` required`:``}${o?` disabled`:``}${!r&&n?` aria-label="${s(n)}"`:``}><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"${o?` disabled`:``}>${a.calendar}</button></span></div>`;this.insertAdjacentHTML(`afterbegin`,`<div class="k-datepicker">${t({id:e,label:r,required:i,control:l})}</div>`),this.input=this.querySelector(`input.k-input__control`),this.toggle=this.querySelector(`.k-datepicker__toggle`),this.input.addEventListener(`blur`,()=>this.commitText()),this.input.addEventListener(`keydown`,e=>{e.key===`Enter`&&this.commitText()}),this.toggle.addEventListener(`click`,()=>this.pop?this.close():this.open()),this.rendered=!0,this.paint()}paint(){let e=this.fmt(this.selected);!this.invalid&&this.input.value!==e&&(this.input.value=e);let t=this.getAttribute(`open-label`)??`انتخاب تاریخ از تقویم`;this.toggle.setAttribute(`aria-label`,this.selected?`${t}، ${m(this.selected,{style:`full`,digits:this.digits})}`:t);let n=this.getAttribute(`invalid-message`)??`این تاریخ معتبر نیست؛ آن را به شکل ۱۴۰۳/۰۵/۱۲ وارد کنید.`;this.input.setCustomValidity(this.invalid?n:``),i(this.querySelector(`.k-field`),this.input,this.key,this.getAttribute(`error`)||(this.invalid?n:null),this.getAttribute(`hint`)),l(this,this.getAttribute(`name`),this.value)}commitText(){let e=this.input.value.trim();if(!e)return this.commit(null);let t=f(e),n=k(this.getAttribute(`min`)),r=k(this.getAttribute(`max`));t&&!(n&&t<n)&&!(r&&t>r)&&!this.isDateDisabled?.(t)?this.commit(t):(this.invalid=!0,this.paint())}commit(e){let t=!w(e,this.selected)||e===null!=(this.selected===null);this.selected=e,this.invalid=!1,this.input.value=this.fmt(e),this.paint(),t&&o(this,`kashi-change`,{value:this.value,date:e})}open(){if(this.pop||this.hasAttribute(`disabled`))return;let e=this.querySelector(`.k-datepicker`),t=this.querySelector(`.k-input`),n=document.createElement(`div`);n.className=`k-datepicker__popover`,n.id=`${this.key}-calendar`,n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-label`,this.getAttribute(`open-label`)??`انتخاب تاریخ از تقویم`),n.style.insetBlockStart=`${t.offsetTop+t.offsetHeight+6}px`;let r=document.createElement(`kashi-calendar`);for(let e of[`min`,`max`,`digits`,`holidays`]){let t=this.getAttribute(e);t!==null&&r.setAttribute(e,t)}this.selected&&r.setAttribute(`value`,x(this.selected)),r.setAttribute(`today-label`,this.getAttribute(`today-label`)??`امروز`),r.isDateDisabled=this.isDateDisabled,r.addEventListener(`kashi-change`,e=>{e.stopPropagation(),this.commit(e.detail.date),this.close()}),n.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.stopPropagation(),this.close())}),n.addEventListener(`focusout`,e=>{let t=e.relatedTarget;t&&!this.contains(t)&&this.close(!1)}),n.append(r),e.append(n),this.pop=n,this.toggle.setAttribute(`aria-expanded`,`true`),this.toggle.setAttribute(`aria-controls`,n.id),document.addEventListener(`pointerdown`,this.onOutside),r.focus()}close(e=!0){this.pop&&(this.pop.remove(),this.pop=null,document.removeEventListener(`pointerdown`,this.onOutside),this.toggle.setAttribute(`aria-expanded`,`false`),this.toggle.removeAttribute(`aria-controls`),e&&this.toggle.focus())}};j.observedAttributes=[`label`,`hint`,`error`,`required`,`disabled`,`value`,`min`,`max`,`digits`,`holidays`,`name`,`placeholder`,`invalid-message`,`aria-label`],e(`kashi-calendar`,A,`block`),e(`kashi-date-picker`,j,`block`);export{A as KashiCalendar,j as KashiDatePicker};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,i as r,l as i,o as a,r as o,s,t as c,u as l}from"./base-Cmq7zeIG.js";import{i as u,n as d,t as f}from"./digits-DE1YGT94.js";import{t as p}from"./text-D1U32D6K.js";import{searchText as m}from"./combobox-ZGrZ5okg.js";const h=[`الف`,`ب`,`پ`,`ت`,`ث`,`ج`,`د`,`ز`,`س`,`ش`,`ص`,`ط`,`ع`,`ف`,`ق`,`ک`,`گ`,`ل`,`م`,`ن`,`و`,`ه`,`ی`,`ژ`],g={الف:`government`,پ:`police`,ث:`police`,ت:`taxi`,ع:`public`,ک:`agricultural`,ش:`army`,ز:`defense`,ف:`defense`,ژ:`disabled`};function _(e){return g[e]??`private`}function v(e){let t=d(e.first??``),n=d(e.middle??``),r=d(e.region??``);return/^[1-9]\d$/.test(t)&&/^[1-9]\d{2}$/.test(n)&&/^[1-9]\d$/.test(r)&&h.includes(e.letter??``)}function y(e,{digits:t=`fa`}={}){let n=e=>t===`fa`?u(d(e)):d(e);return`${n(e.first)} ${e.letter} ${n(e.middle)} ایران ${n(e.region)}`}function b(e){let t=e.trim();if(!t)return null;let n=t.split(/[:٫.،,\s]/).map(d).filter(Boolean),r,i;if(n.length>=2)[r,i]=[Number(n[0]),Number(n[1])];else{let e=d(t);e.length<=2?[r,i]=[Number(e),0]:[r,i]=[Number(e.slice(0,-2)),Number(e.slice(-2))]}return r>=0&&r<24&&i>=0&&i<60?{hours:r,minutes:i}:null}function x({hours:e,minutes:t}){return`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`}const S=`ضصثقفغعهخحجچپشسیبلاتنمکگظطزرذدپوژ؟آ`,C=/* @__PURE__ */ new Map,w=/* @__PURE__ */ new Map;[...`qwertyuiop[]\\asdfghjkl;'zxcvbnm,C?H`].forEach((e,t)=>{C.set(e,S[t]),w.has(S[t])||w.set(S[t],e)});function T(e,t=`fa`){let n=t===`fa`?C:w;return[...e].map(e=>n.get(t===`fa`&&e!==`C`&&e!==`H`?e.toLowerCase():e)??e).join(``)}function E(e){let t=e.trim();if(!t||/[\u0600-\u06FF]/.test(t)||!/[a-z]/i.test(t))return!1;let n=t.split(/\s+/).filter(e=>/[a-z]/i.test(e)),r=n.filter(e=>/[a-z][;'[\],\\]|[;'[\],\\][a-z]/i.test(e)||e.length>=3&&!/[aeiouy]/i.test(e));return r.length>0&&r.length*2>=n.length}const D=`<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 10.5 3.2 3L15 7"/></svg>`,O=`<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>`;function k(e,t,n){if(e.querySelectorAll(`:scope > input[type=hidden][data-kashi-value]`).forEach(e=>e.remove()),t)for(let r of n)e.insertAdjacentHTML(`beforeend`,`<input type="hidden" data-kashi-value name="${s(t)}" value="${s(r)}">`)}function A(e){let t=[...e.querySelectorAll(`:scope > option`)].map(e=>({value:e.value,label:e.textContent?.trim()??e.value,description:e.dataset.description,disabled:e.disabled,selected:e.hasAttribute(`selected`)}));return e.querySelectorAll(`:scope > option`).forEach(e=>e.remove()),t}var j=class extends c{constructor(){super(...arguments),this.list=null,this.chosen=[],this.query=``,this.active=-1,this.isOpen=!1,this.valueSet=!1,this.key=n(`kashi-multi`),this.onOutside=e=>{this.contains(e.target)||this.close()}}connectedCallback(){o(()=>{if(this.isConnected){if(this.list===null){let e=A(this);this.list=e,this.valueSet||(this.chosen=e.filter(e=>e.selected).map(e=>e.value))}this.render()}})}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}attributeChangedCallback(e,t,n){this.box&&t!==n&&this.render()}get options(){return this.list??[]}set options(e){this.list=[...e],this.box&&this.paint()}get value(){return[...this.chosen]}set value(e){this.valueSet=!0,this.chosen=[...e],this.box&&this.paint()}render(){let e=this.key,n=this.getAttribute(`aria-label`),r=this.hasAttribute(`label`)?this.getAttribute(`label`):n?null:`انتخاب`,i=`<div class="k-combobox k-multiselect"><div class="k-tag-input"><input id="${e}" class="k-tag-input__control" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="${e}-list" autocomplete="off"${this.hasAttribute(`disabled`)?` disabled`:``}${!r&&n?` aria-label="${s(n)}"`:``}></div><ul id="${e}-list" role="listbox" aria-multiselectable="true" class="k-listbox" hidden style="inset-block-start: calc(100% + 6px)"${r?` aria-label="${s(r)}"`:``}></ul><span id="${e}-count" class="k-sr-only"></span><span class="k-sr-only" aria-live="polite"></span></div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,t({id:e,label:r,control:i})),this.input=this.querySelector(`.k-tag-input__control`),this.box=this.querySelector(`.k-tag-input`),this.listbox=this.querySelector(`.k-listbox`),this.box.addEventListener(`click`,e=>{let t=e.target.closest(`[data-remove]`);t?this.set(this.chosen.filter(e=>e!==t.dataset.remove),`${this.labelOf(t.dataset.remove)} حذف شد`):e.target.closest(`[data-clear]`)&&this.set([],`همه حذف شد`),this.input.focus()}),this.input.addEventListener(`input`,()=>{this.query=this.input.value,this.active=0,this.open()}),this.input.addEventListener(`focus`,()=>this.open()),this.input.addEventListener(`keydown`,e=>this.onKey(e)),this.listbox.addEventListener(`pointerdown`,e=>e.preventDefault()),this.listbox.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);t&&this.toggle(this.filtered()[Number(t.dataset.i)])}),this.paint()}labelOf(e){return this.options.find(t=>t.value===e)?.label??e}filtered(){let e=m(this.query.trim());return this.options.filter(t=>!e||[t.label,t.description??``].some(t=>m(t).includes(e)))}get full(){let e=Number(this.getAttribute(`max`));return!!e&&this.chosen.length>=e}toggle(e){if(!e||e.disabled)return;let t=this.chosen.includes(e.value);if(!t&&this.full)return this.announce(`حداکثر ${u(Number(this.getAttribute(`max`)))} مورد`);this.query=``,this.input.value=``,this.set(t?this.chosen.filter(t=>t!==e.value):[...this.chosen,e.value],`${e.label} ${t?`حذف شد`:`انتخاب شد`}`)}set(e,t){this.chosen=e,this.paint(),this.announce(t),a(this,`kashi-change`,{value:[...e]})}announce(e){this.querySelector(`.k-multiselect > .k-sr-only[aria-live]`).textContent=e}open(){this.hasAttribute(`disabled`)||(this.isOpen=!0,this.listbox.hidden=!1,this.input.setAttribute(`aria-expanded`,`true`),this.querySelector(`.k-combobox`).setAttribute(`data-open`,``),document.addEventListener(`pointerdown`,this.onOutside),this.paintList())}close(){this.isOpen=!1,this.listbox.hidden=!0,this.input.setAttribute(`aria-expanded`,`false`),this.input.removeAttribute(`aria-activedescendant`),this.querySelector(`.k-combobox`).removeAttribute(`data-open`),document.removeEventListener(`pointerdown`,this.onOutside)}onKey(e){let t=this.filtered(),n=t.map((e,t)=>e.disabled?-1:t).filter(e=>e>=0),r=e=>{n.length&&(this.active=n[(n.indexOf(this.active)+e+n.length)%n.length],this.paintList())};if(e.key===`ArrowDown`)e.preventDefault(),this.isOpen?r(1):this.open();else if(e.key===`ArrowUp`)e.preventDefault(),this.isOpen?r(-1):this.open();else if(e.key===`Enter`&&this.isOpen&&t[this.active])e.preventDefault(),this.toggle(t[this.active]);else if(e.key===`Escape`&&this.isOpen)e.preventDefault(),this.close();else if(e.key===`Backspace`&&!this.input.value&&this.chosen.length){let e=this.chosen.at(-1);this.set(this.chosen.slice(0,-1),`${this.labelOf(e)} حذف شد`)}}paint(){let e=this.hasAttribute(`disabled`);this.box.querySelectorAll(`.k-badge, [data-clear]`).forEach(e=>e.remove());let t=this.chosen.map(t=>`<span class="k-badge k-badge--brand${e?``:` k-badge--removable`}">${s(this.labelOf(t))}${e?``:`<button type="button" class="k-badge__remove" data-remove="${s(t)}" aria-label="حذف ${s(this.labelOf(t))}">${O}</button>`}</span>`).join(``);this.input.insertAdjacentHTML(`beforebegin`,t),this.chosen.length>1&&!e&&this.box.insertAdjacentHTML(`beforeend`,`<button type="button" class="k-input__action" data-clear aria-label="پاک کردن همه">${O}</button>`),this.input.placeholder=this.chosen.length?``:this.getAttribute(`placeholder`)??``,this.querySelector(`#${this.key}-count`).textContent=`${u(this.chosen.length)} مورد انتخاب شده`;let n=this.getAttribute(`error`);this.box.toggleAttribute(`data-invalid`,!!n),i(this.querySelector(`:scope > .k-field`),this.input,this.key,n,this.getAttribute(`hint`),`${this.key}-count`),k(this,this.getAttribute(`name`),this.chosen),this.isOpen&&this.paintList()}paintList(){let e=this.filtered(),t=m(this.query.trim()),n=this.full,r=e=>{let n=t?m(e).indexOf(t):-1;return n<0?s(e):`${s(e.slice(0,n))}<mark>${s(e.slice(n,n+t.length))}</mark>${s(e.slice(n+t.length))}`};this.listbox.innerHTML=e.length?e.map((e,t)=>{let i=this.chosen.includes(e.value);return`<li id="${this.key}-list-${t}" data-i="${t}" role="option" aria-selected="${i}"${e.disabled||!i&&n?` aria-disabled="true"`:``}${t===this.active?` data-active`:``} class="k-option k-option--check"><span class="k-multiselect__box" aria-hidden="true">${i?D:``}</span><span class="k-option__body"><span>${r(e.label)}</span>${e.description?`<span class="k-option__desc">${s(e.description)}</span>`:``}</span></li>`}).join(``):`<li class="k-listbox__empty" role="presentation">نتیجهای پیدا نشد.</li>`;let i=this.active>=0?this.listbox.querySelector(`[data-i="${this.active}"]`):null;i?(this.input.setAttribute(`aria-activedescendant`,i.id),i.scrollIntoView?.({block:`nearest`})):this.input.removeAttribute(`aria-activedescendant`)}};j.observedAttributes=[`label`,`hint`,`error`,`placeholder`,`max`,`disabled`,`name`,`aria-label`];var M=class extends c{constructor(){super(...arguments),this.lo=0,this.hi=0,this.valueSet=!1,this.rendered=!1,this.key=n(`kashi-slider`)}connectedCallback(){!this.rendered&&!this.valueSet&&this.readValue(this.getAttribute(`value`)),this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`&&this.readValue(n),this.render())}num(e,t){let n=this.getAttribute(e);return n===null||n===``||Number.isNaN(Number(n))?t:Number(n)}get min(){return this.num(`min`,0)}get max(){return this.num(`max`,100)}get isRange(){return this.hasAttribute(`range`)}readValue(e){let t=(e??``).split(/[,،]/).map(e=>Number(e.trim())).filter(e=>!Number.isNaN(e)&&String(e)!==``);this.isRange?[this.lo,this.hi]=[t[0]??this.min,t[1]??this.max]:[this.lo,this.hi]=[this.min,t[0]??this.min]}get value(){return this.isRange?[this.lo,this.hi]:this.hi}set value(e){this.valueSet=!0,this.readValue(Array.isArray(e)?e.join(`,`):String(e)),this.rendered&&this.render()}fmt(e){let t=this.getAttribute(`unit`);return`${f(e)}${t?` ${t}`:``}`}render(){let e=this.getAttribute(`label`),t=this.isRange,n=this.getAttribute(`name`),r=this.hasAttribute(`disabled`),i=e=>`${(e-this.min)/(this.max-this.min)*100}%`,o=i=>{let a=i===`lo`?this.lo:this.hi,o=n?t?`${n}_${i===`lo`?`min`:`max`}`:n:``;return`<input type="range" class="k-slider__input" data-which="${i}" min="${this.min}" max="${this.max}" step="${this.num(`step`,1)}" value="${a}"${r?` disabled`:``}${o?` name="${s(o)}"`:``}${t?` aria-label="${i===`lo`?`حداقل`:`حداکثر`}${e?` ${s(e)}`:``}"`:e?` aria-labelledby="${this.key}-label"`:``} aria-valuetext="${s(this.fmt(a))}">`},c=(this.getAttribute(`marks`)??``).split(/[,،]/).map(e=>e.trim()).filter(Boolean).map(Number),l=this.getAttribute(`show-value`)!==`false`;this.innerHTML=`<div class="k-slider"${t?` data-range=""`:``}>${e||l?`<div class="k-slider__head">${e?`<span class="k-label" id="${this.key}-label">${s(e)}</span>`:``}${l?`<span class="k-slider__value" aria-hidden="true">${s(t?`${this.fmt(this.lo)} تا ${this.fmt(this.hi)}`:this.fmt(this.hi))}</span>`:``}</div>`:``}<div class="k-slider__track" style="--_from: ${t?i(this.lo):`0%`}; --_to: ${i(this.hi)}"><span class="k-slider__fill" aria-hidden="true"></span>${t?o(`lo`):``}${o(`hi`)}</div>${c.length?`<div class="k-slider__marks" aria-hidden="true">${c.map(e=>`<span>${s(this.fmt(e))}</span>`).join(``)}</div>`:``}</div>`,this.rendered=!0,this.querySelectorAll(`.k-slider__input`).forEach(e=>e.addEventListener(`input`,()=>{let n=Number(e.value);t?e.dataset.which===`lo`?this.lo=Math.min(n,this.hi):this.hi=Math.max(n,this.lo):this.hi=n,e.value=String(e.dataset.which===`lo`?this.lo:this.hi),e.setAttribute(`aria-valuetext`,this.fmt(Number(e.value)));let r=this.querySelector(`.k-slider__track`);r.style.setProperty(`--_from`,t?i(this.lo):`0%`),r.style.setProperty(`--_to`,i(this.hi));let o=this.querySelector(`.k-slider__value`);o&&(o.textContent=t?`${this.fmt(this.lo)} تا ${this.fmt(this.hi)}`:this.fmt(this.hi)),a(this,`kashi-change`,{value:this.value})}))}};M.observedAttributes=[`label`,`min`,`max`,`step`,`value`,`range`,`show-value`,`marks`,`unit`,`disabled`,`name`];var N=class extends c{constructor(){super(...arguments),this.built=!1}connectedCallback(){o(()=>this.isConnected&&!this.built&&this.build())}attributeChangedCallback(){if(!this.built)return;let e=this.getAttribute(`label`);e&&this.setAttribute(`aria-label`,e),this.sync(!1)}get value(){return[...this.querySelectorAll(`.k-chip[aria-pressed="true"]`)].map(e=>e.dataset.value??``)}set value(e){this.querySelectorAll(`.k-chip`).forEach(t=>t.setAttribute(`aria-pressed`,String(e.includes(t.dataset.value??``)))),this.sync(!1)}build(){this.built=!0,this.classList.add(`k-chips`),this.setAttribute(`role`,`group`);let e=this.getAttribute(`label`);e&&this.setAttribute(`aria-label`,e),this.querySelectorAll(`:scope > button`).forEach(e=>{var t;e.type=`button`,e.classList.add(`k-chip`),(t=e.dataset).value||(t.value=e.textContent?.trim()??``),e.setAttribute(`aria-pressed`,String(e.hasAttribute(`data-pressed`)||e.getAttribute(`aria-pressed`)===`true`)),e.insertAdjacentHTML(`afterbegin`,`<svg class="k-chip__check" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 10.5 3.2 3L15 7"/></svg>`),e.dataset.count&&e.insertAdjacentHTML(`beforeend`,`<span class="k-chip__count">${u(e.dataset.count)}</span>`)}),this.addEventListener(`click`,e=>{let t=e.target.closest(`.k-chip`);if(!t||t.disabled)return;let n=t.getAttribute(`aria-pressed`)!==`true`;r(this,`single`)&&this.querySelectorAll(`.k-chip`).forEach(e=>e.setAttribute(`aria-pressed`,`false`)),t.setAttribute(`aria-pressed`,String(n)),this.sync(!0)}),this.sync(!1)}sync(e){k(this,this.getAttribute(`name`),this.value),e&&a(this,`kashi-change`,{value:this.value})}};N.observedAttributes=[`label`,`single`,`name`];const P=[[`حداقل ${u(8)} نویسه`,e=>e.length>=8],[`حروف بزرگ و کوچک انگلیسی`,e=>/[a-z]/.test(e)&&/[A-Z]/.test(e)],[`دستکم یک عدد`,e=>/\d/.test(e)],[`دستکم یک نماد، مثل ! یا @`,e=>/[^A-Za-z0-9\s-ۿ]/.test(e)]];var F=class extends c{constructor(){super(...arguments),this.target=null,this.onInput=()=>this.render(this.target?.value??``)}connectedCallback(){o(()=>{this.isConnected&&(this.attach(),this.render(``))})}disconnectedCallback(){this.target?.removeEventListener(`input`,this.onInput)}attributeChangedCallback(){this.isConnected&&(this.attach(),this.render(this.target?.value??``))}attach(){this.target?.removeEventListener(`input`,this.onInput);let e=this.getAttribute(`for`),t=e?document.getElementById(e):null;if(this.target=t instanceof HTMLInputElement?t:t?.querySelector(`input`)??null,this.target?.addEventListener(`input`,this.onInput),this.target){this.id||=n(`kashi-strength`);let e=(this.target.getAttribute(`aria-describedby`)??``).split(` `).filter(Boolean);e.includes(this.id)||this.target.setAttribute(`aria-describedby`,[...e,this.id].join(` `))}}score(e){let t=P.filter(([,t])=>t(e)).length;return e?Math.max(1,Math.round(t/P.length*4)):0}render(e){let t=this.score(e),n=[`ضعیف`,`متوسط`,`خوب`,`قوی`],r=/[-ۿ]/.test(e);this.innerHTML=`<div class="k-strength" data-score="${t}"><div class="k-strength__bars" aria-hidden="true">${`<span class="k-strength__bar"></span>`.repeat(4)}</div><p class="k-strength__label" aria-live="polite" style="margin: 0">${t?`قدرت رمز: <strong>${n[t-1]}</strong>`:``}</p>${r?`<p class="k-hint k-hint--error" role="alert">رمز حروف فارسی دارد؛ شاید صفحهکلید روی فارسی مانده است.</p>`:``}${this.getAttribute(`show-rules`)===`false`?``:`<ul class="k-strength__rules">${P.map(([t,n])=>{let r=n(e);return`<li class="k-strength__rule"${r?` data-met=""`:``}>${r?D:`<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="2.5" fill="currentColor"/></svg>`}<span>${t}<span class="k-sr-only">${r?`، رعایت شده`:`، رعایت نشده`}</span></span></li>`}).join(``)}</ul>`}</div>`}};F.observedAttributes=[`for`,`show-rules`];var I=class extends c{constructor(){super(...arguments),this.key=n(`kashi-text`),this.rendered=!1,this.valueSet=!1,this.text=``}connectedCallback(){!this.rendered&&!this.valueSet&&(this.text=this.getAttribute(`value`)??``),this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:this.render())}get value(){return this.text}set value(e){this.valueSet=!0,this.text=String(e??``),this.rendered&&(this.control.value=this.text,this.paint())}focus(e){this.control?.focus(e)}render(){let e=this.key,n=this.getAttribute(`aria-label`),r=this.hasAttribute(`label`)?this.getAttribute(`label`):n?null:this.defaultLabel,i=this.getAttribute(`name`),o=`id="${e}" class="k-input__control" dir="auto"${i?` name="${s(i)}"`:``}${this.hasAttribute(`required`)?` required`:``}${this.hasAttribute(`disabled`)?` disabled`:``} placeholder="${s(this.getAttribute(`placeholder`)??``)}"${!r&&n?` aria-label="${s(n)}"`:``}`,c=this.multiline?`<div class="k-input k-input--textarea"><textarea ${o} rows="${Number(this.getAttribute(`rows`))||4}"></textarea></div>`:`<div class="k-input"><input ${o}></div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,t({id:e,label:r,required:this.hasAttribute(`required`),control:c})),this.control=this.querySelector(`.k-input__control`),this.control.value=this.text,this.control.addEventListener(`input`,()=>{this.text=this.control.value,this.paint(),a(this,`kashi-change`,{value:this.text})}),this.rendered=!0,this.paint()}paint(){let e=this.querySelector(`:scope > .k-field`);i(e,this.control,this.key,this.getAttribute(`error`),null);let t=this.hint();if(e.querySelector(`.k-field__hint-row[data-extra]`)?.remove(),t){e.insertAdjacentHTML(`beforeend`,`<div class="k-field__hint-row" data-extra><div class="k-field__hints"><p class="k-hint" id="${this.key}-hint">${t}</p></div></div>`);let n=(this.control.getAttribute(`aria-describedby`)??``).split(` `).filter(Boolean);this.control.setAttribute(`aria-describedby`,[...n,`${this.key}-hint`].join(` `))}}replace(e){this.text=e,this.control.value=e,this.paint(),this.control.focus(),a(this,`kashi-change`,{value:e})}};const L={arabic:`حرف عربی`,zwnj:`نیمفاصله`,punctuation:`علامت`,digits:`رقم`,spacing:`فاصله`};var R=class extends I{constructor(){super(...arguments),this.multiline=!0,this.defaultLabel=`متن`}render(){super.render(),this.control.addEventListener(`blur`,()=>{let e=this.result();r(this,`fix-on-blur`)&&e.count&&this.replace(e.text)}),this.addEventListener(`click`,e=>{e.target.closest(`[data-fix]`)&&this.replace(this.result().text)})}result(){return p(this.text,{digits:this.getAttribute(`fix-digits`)!==`false`})}hint(){if(!this.text.trim())return this.getAttribute(`hint`)?s(this.getAttribute(`hint`)):null;let e=this.result();if(!e.count)return`<span class="k-textfix" data-state="clean"><span class="k-textfix__text">نگارش متن درست است.</span></span>`;let t=Object.keys(L).filter(t=>e.fixes[t]).map(t=>`${u(e.fixes[t])} ${L[t]}`).join(`، `);return`<span class="k-textfix" data-state="fix"><span class="k-textfix__text">${u(e.count)} مورد قابل اصلاح: ${t}</span><button type="button" class="k-btn k-btn--tertiary k-btn--xs" data-fix>اصلاح نگارش</button></span>`}};R.observedAttributes=[`label`,`hint`,`error`,`placeholder`,`required`,`disabled`,`name`,`value`,`rows`,`fix-on-blur`,`fix-digits`,`aria-label`];var z=class extends I{constructor(){super(...arguments),this.multiline=!1,this.defaultLabel=`متن`}render(){super.render(),this.addEventListener(`click`,e=>{e.target.closest(`[data-fix]`)&&this.replace(T(this.text))})}hint(){let e=this.text,t=/[a-z]/i.test(e)&&!/[-ۿ]/.test(e);return(this.getAttribute(`suggest`)===`always`?t:E(e))?`<span class="k-kbfix" role="status">منظورتان <button type="button" class="k-kbfix__btn" data-fix>«${s(T(e))}»</button> بود؟</span>`:this.getAttribute(`hint`)?s(this.getAttribute(`hint`)):null}};z.observedAttributes=[`label`,`hint`,`error`,`placeholder`,`required`,`disabled`,`name`,`value`,`suggest`,`aria-label`];const B=e=>e.hours*60+e.minutes,V=e=>({hours:Math.floor(e/60),minutes:e%60});var H=class extends c{constructor(){super(...arguments),this.current=null,this.invalid=!1,this.valueSet=!1,this.rendered=!1,this.key=n(`kashi-time`)}connectedCallback(){!this.rendered&&!this.valueSet&&(this.current=this.normal(this.getAttribute(`value`))),this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:this.render())}get value(){return this.current??``}set value(e){this.valueSet=!0,this.current=this.normal(e),this.invalid=!1,this.rendered&&this.paint()}normal(e){let t=e?b(e):null;return t?x(t):null}show(e){return e?this.getAttribute(`digits`)===`latin`?e:u(e):``}get lo(){let e=b(this.getAttribute(`min`)??``);return e?B(e):0}get hi(){let e=b(this.getAttribute(`max`)??``);return e?B(e):1439}render(){let e=this.key,n=this.getAttribute(`aria-label`),r=this.hasAttribute(`label`)?this.getAttribute(`label`):n?null:`ساعت`,i=this.getAttribute(`digits`)!==`latin`,a=`<div class="k-input"><input id="${e}" class="k-input__control" type="text" inputmode="numeric" dir="ltr" autocomplete="off" placeholder="${s(this.getAttribute(`placeholder`)??(i?`۰۹:۳۰`:`09:30`))}"${this.hasAttribute(`required`)?` required`:``}${this.hasAttribute(`disabled`)?` disabled`:``}${!r&&n?` aria-label="${s(n)}"`:``}><span class="k-input__addon"><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></span></div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,t({id:e,label:r,required:this.hasAttribute(`required`),control:a})),this.input=this.querySelector(`input.k-input__control`),this.input.addEventListener(`blur`,()=>this.commitText()),this.input.addEventListener(`keydown`,e=>{if(e.key===`Enter`&&this.commitText(),e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return;e.preventDefault();let t=Number(this.getAttribute(`step`))||15,n=b(this.input.value)??b(this.current??``)??V(this.lo),r=B(n),i=e.key===`ArrowUp`?Math.floor(r/t)*t+t:Math.ceil(r/t)*t-t;this.commit(V(Math.min(this.hi,Math.max(this.lo,i))))}),this.rendered=!0,this.paint()}commitText(){let e=this.input.value.trim();if(!e)return this.commit(null);let t=b(e);if(!t)this.invalid=`format`;else if(B(t)<this.lo||B(t)>this.hi)this.invalid=`range`;else return this.commit(t);this.paint(!1)}commit(e){let t=e?x(e):null,n=t!==this.current;this.current=t,this.invalid=!1,this.paint(),n&&a(this,`kashi-change`,{value:t??``})}paint(e=!0){e&&(this.input.value=this.show(this.current));let t=this.invalid===`range`?`ساعت باید بین ${this.show(x(V(this.lo)))} و ${this.show(x(V(this.hi)))} باشد.`:this.invalid?`ساعت معتبر نیست؛ آن را به شکل ۰۹:۳۰ وارد کنید.`:null;this.input.setCustomValidity(t??``),i(this.querySelector(`:scope > .k-field`),this.input,this.key,this.getAttribute(`error`)||t,this.getAttribute(`hint`)),l(this,this.getAttribute(`name`),this.current??``)}};H.observedAttributes=[`label`,`hint`,`error`,`value`,`min`,`max`,`step`,`digits`,`required`,`disabled`,`name`,`placeholder`,`aria-label`];const U={first:``,letter:``,middle:``,region:``};var W=class extends c{constructor(){super(...arguments),this.plate={...U},this.touched=!1,this.valueSet=!1,this.rendered=!1,this.key=n(`kashi-plate`)}connectedCallback(){!this.rendered&&!this.valueSet&&(this.plate=this.parse(this.getAttribute(`value`))),this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=this.parse(n):this.render())}parse(e){let[t=``,n=``,r=``,i=``]=(e??``).split(`-`);return{first:d(t),letter:n,middle:d(r),region:d(i)}}get value(){return{...this.plate}}set value(e){this.valueSet=!0,this.plate={...U,...e},this.rendered&&this.render()}get valid(){return v(this.plate)}render(){let e=this.key,n=this.plate,r=this.hasAttribute(`disabled`)?` disabled`:``,i=(t,i,a,o=``,s=!1)=>`<input${s?` id="${e}-first"`:``} class="k-plate__seg ${o}" data-key="${t}" data-len="${i}" inputmode="numeric" autocomplete="off" aria-label="${a}" placeholder="${u(`0`.repeat(i))}" value="${u(n[t])}"${r}>`,o=this.getAttribute(`label`)??`پلاک خودرو`,c=`<div class="k-plate" role="group" aria-label="${s(o)}" data-type="${_(n.letter)}"><span class="k-plate__flag" aria-hidden="true"><span class="k-plate__flag-colors"></span>I.R.<br>IRAN</span>${i(`first`,2,`دو رقم اول پلاک`,``,!0)}<select class="k-plate__letter" data-key="letter" aria-label="حرف پلاک"${r}><option value="">–</option>${h.map(e=>`<option value="${e}"${e===n.letter?` selected`:``}>${e===`ه`?`هـ`:e}</option>`).join(``)}</select>${i(`middle`,3,`سه رقم پلاک`,`k-plate__seg--3`)}<span class="k-plate__region"><span class="k-plate__region-label" aria-hidden="true">ایران</span>${i(`region`,2,`کد استان`)}</span></div><span class="k-sr-only" aria-live="polite"></span>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,t({id:`${e}-first`,label:o,control:c}));let l=[...this.querySelectorAll(`[data-key]`)];l.forEach((e,t)=>{e.addEventListener(e instanceof HTMLSelectElement?`change`:`input`,()=>{let n=e.dataset.key;if(e instanceof HTMLSelectElement)this.plate.letter=e.value,e.value&&l[t+1]?.focus();else{let r=Number(e.dataset.len),i=d(e.value);n===`middle`&&i.length>r&&(this.plate.region=(this.plate.region+i.slice(r)).slice(0,2)),this.plate[n]=i.slice(0,r),e.value=u(this.plate[n]),this.plate[n].length===r&&l[t+1]?.focus()}this.paint(),a(this,`kashi-change`,{value:this.value,valid:this.valid})}),e.addEventListener(`keydown`,n=>{n.key===`Backspace`&&!e.value&&l[t-1]?.focus()})});let f=this.querySelector(`.k-plate`);f.addEventListener(`focusout`,e=>{f.contains(e.relatedTarget)||(this.touched=!0,this.paint())}),this.rendered=!0,this.paint()}paint(){let e=this.plate,t=this.querySelector(`.k-plate`),n=this.querySelector(`[data-key="region"]`);n.value!==u(e.region)&&(n.value=u(e.region)),t.dataset.type=_(e.letter);let r=e.first.length===2&&!!e.letter&&e.middle.length===3&&e.region.length===2,a=(this.touched||r)&&Object.values(e).some(Boolean)&&!this.valid,o=this.getAttribute(`error`)||(a?`پلاک خودرو معتبر نیست.`:null);t.toggleAttribute(`data-invalid`,!!o),i(this.querySelector(`:scope > .k-field`),t,this.key,o,this.getAttribute(`hint`)),this.querySelector(`.k-field > .k-sr-only`).textContent=this.valid?y(e):``;let c=this.getAttribute(`name`);if(this.querySelectorAll(`:scope > input[type=hidden]`).forEach(e=>e.remove()),c)for(let t of[`first`,`letter`,`middle`,`region`])this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${s(`${c}_${t}`)}" value="${s(e[t])}">`)}};W.observedAttributes=[`label`,`hint`,`error`,`name`,`disabled`,`value`];var G=class extends c{constructor(){super(...arguments),this.text=``,this.editing=!1,this.valueSet=!1,this.rendered=!1}connectedCallback(){!this.rendered&&!this.valueSet&&(this.text=this.getAttribute(`value`)??this.textContent?.trim()??``),this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`&&(this.text=n??``),this.editing||this.render())}get value(){return this.text}set value(e){this.valueSet=!0,this.text=String(e??``),this.rendered&&!this.editing&&this.render()}render(e=!1){let t=this.getAttribute(`label`)??`متن`;this.rendered=!0,this.editing=!1,this.innerHTML=`<span class="k-inline-edit"><button type="button" class="k-inline-edit__view" aria-label="${s(`${t}: ${this.text||`خالی`}، ویرایش`)}">${this.text?s(this.text):`<span class="k-inline-edit__placeholder">${s(this.getAttribute(`placeholder`)??`خالی`)}</span>`}<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m13.5 3.5 3 3L7 16H4v-3Z"/></svg></button></span>`;let n=this.querySelector(`button`);n.addEventListener(`click`,()=>this.edit()),e&&n.focus()}edit(e,t=this.text){this.editing=!0;let r=this.getAttribute(`label`)??`متن`,i=n(`kashi-ie-err`);this.innerHTML=`<span class="k-inline-edit"><span class="k-field" style="gap: 4px"><span class="k-input"${e?` data-state="invalid"`:``}><input class="k-input__control" aria-label="${s(r)}" placeholder="${s(this.getAttribute(`placeholder`)??``)}"${e?` aria-invalid="true" aria-describedby="${i}"`:``}></span>${e?`<span class="k-hint k-hint--error" id="${i}">${s(e)}</span>`:``}</span><span class="k-inline-edit__actions"><button type="button" class="k-btn k-btn--primary k-btn--icon k-btn--sm" data-save aria-label="ثبت">${D}</button><button type="button" class="k-btn k-btn--secondary k-btn--icon k-btn--sm" data-cancel aria-label="انصراف">${O}</button></span></span>`;let a=this.querySelector(`input`);a.value=t,a.focus(),a.select(),a.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),this.commit(a.value)):e.key===`Escape`&&(e.preventDefault(),this.render(!0))}),this.querySelector(`[data-save]`).addEventListener(`click`,()=>this.commit(a.value)),this.querySelector(`[data-cancel]`).addEventListener(`click`,()=>this.render(!0))}async commit(e){let t=e.trim(),n=this.validate?.(t);if(n)return this.edit(n,e);if(t===this.text)return this.render(!0);let r=this.text,i=null;if(a(this,`kashi-save`,{value:t,wait:e=>i=e}),this.text=t,i){this.querySelector(`[data-save]`)?.setAttribute(`aria-busy`,`true`);try{await i}catch{return this.text=r,this.edit(`ذخیره نشد؛ دوباره امتحان کنید.`,e)}}this.render(!0),a(this,`kashi-change`,{value:t})}};G.observedAttributes=[`value`,`label`,`placeholder`],e(`kashi-multi-select`,j,`block`),e(`kashi-slider`,M,`block`),e(`kashi-chip-group`,N),e(`kashi-password-strength`,F,`block`),e(`kashi-persian-textarea`,R,`block`),e(`kashi-keyboard-fix`,z,`block`),e(`kashi-time-input`,H,`block`),e(`kashi-plate-input`,W,`block`),e(`kashi-inline-edit`,G);export{N as KashiChipGroup,G as KashiInlineEdit,z as KashiKeyboardFix,j as KashiMultiSelect,F as KashiPasswordStrength,R as KashiPersianTextarea,W as KashiPlateInput,M as KashiSlider,H as KashiTimeInput};
|