@faqir-ui/core 1.1.2 → 1.2.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 +9 -8
- package/cdn.json +40 -35
- package/dist/faqir-core.js +74 -68
- package/dist/faqir-core.min.js +3 -3
- package/dist/faqir-core.min.js.map +3 -3
- package/dist/faqir-core.mjs +134 -56
- package/dist/faqir.aurora.css +5013 -428
- package/dist/faqir.brutalist.css +5013 -428
- package/dist/faqir.candy.css +5013 -428
- package/dist/faqir.clay.css +19164 -0
- package/dist/faqir.clinical.css +5013 -428
- package/dist/faqir.contrast.css +5013 -428
- package/dist/faqir.deco.css +19247 -0
- package/dist/faqir.default.css +5013 -428
- package/dist/faqir.document-serif.css +5013 -428
- package/dist/faqir.document.css +5014 -428
- package/dist/faqir.editorial-document.css +5013 -428
- package/dist/faqir.editorial.css +5013 -428
- package/dist/faqir.fintech.css +5013 -428
- package/dist/faqir.glass.css +5013 -428
- package/dist/faqir.ink-document.css +5013 -428
- package/dist/faqir.ink.css +5013 -428
- package/dist/faqir.luxe.css +5013 -428
- package/dist/faqir.memphis.css +19163 -0
- package/dist/faqir.midnight.css +5013 -428
- package/dist/faqir.monolith.css +19162 -0
- package/dist/faqir.neo.css +5013 -428
- package/dist/faqir.neumorph.css +5013 -428
- package/dist/faqir.nordic.css +5013 -428
- package/dist/faqir.organic.css +5013 -428
- package/dist/faqir.paper.css +5013 -428
- package/dist/faqir.slate.css +5013 -428
- package/dist/faqir.soft.css +5013 -428
- package/dist/faqir.sunset.css +5013 -428
- package/dist/faqir.swiss-document.css +5013 -428
- package/dist/faqir.swiss.css +5013 -428
- package/dist/faqir.terminal.css +5013 -428
- package/dist/plugins/faqir-rules.js +1 -1
- package/dist/plugins/faqir-tweak.js +304 -0
- package/dist/plugins/faqir-validate.js +12 -4
- package/dist/sri.json +38 -33
- package/faqir-core.d.ts +42 -0
- package/package.json +1 -1
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
* `aria-required` on a control it was told to own, and a computed control's
|
|
61
61
|
* `value` — the frozen five-attribute protocol is untouched.
|
|
62
62
|
*/
|
|
63
|
-
(()=>{var{defineProperty:re,getOwnPropertyNames:ot,getOwnPropertyDescriptor:at}=Object,ut=Object.prototype.hasOwnProperty;function ft(e){return this[e]}var lt=(e)=>{var t=(_e??=new WeakMap).get(e),i;if(t)return t;if(t=re({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var s of ot(e))if(!ut.call(t,s))re(t,s,{get:ft.bind(e,s),enumerable:!(i=at(e,s))||i.enumerable})}return _e.set(e,t),t},_e;var ct=(e)=>e;function dt(e,t){this[e]=ct.bind(null,t)}var mt=(e,t)=>{for(var i in t)re(e,i,{get:t[i],enumerable:!0,configurable:!0,set:dt.bind(t,i)})};var dn={};mt(dn,{install:()=>nt});class d extends Error{constructor(e,t){super(`@faqir-ui/rules: ${e}`);this.name="DefinitionError",this.path=t}}var pt=/^(\d{4})-(\d{2})-(\d{2})$/,ht=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/i,gt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,yt=/^[A-Za-z][A-Za-z0-9+.-]*:[^\s\x00-\x1f]+$/,bt=/^[^\s@,;<>()[\]\\"]+@[^\s@.,;<>()[\]\\"]+(?:\.[^\s@.,;<>()[\]\\"]+)*\.[A-Za-z]{2,}$/,wt=/^\+?[0-9 ().-]{6,24}$/,Et=/^[A-Za-z0-9][A-Za-z0-9 -]{0,10}[A-Za-z0-9]$/,At=/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/,xt=[31,28,31,30,31,30,31,31,30,31,30,31];function St(e){return e%4===0&&e%100!==0||e%400===0}function je(e){let t=pt.exec(e);if(!t)return!1;let i=Number(t[1]),s=Number(t[2]),r=Number(t[3]);if(s<1||s>12||r<1)return!1;let n=s===2&&St(i)?29:xt[s-1];return r<=n}function qe(e){let t=ht.exec(e);if(!t)return!1;let i=Number(t[1]),s=Number(t[2]),r=t[3]===void 0?0:Number(t[3]);return i<=23&&s<=59&&r<=60}function $t(e){let t=/^(.+?)[Tt ](.+)$/.exec(e);if(!t)return!1;return je(t[1])&&qe(t[2])}function Ot(e){if(!wt.test(e))return!1;let t=e.replace(/\D/g,"");return t.length>=7&&t.length<=15}function vt(e){let t=e.replace(/[\s-]/g,"").toUpperCase();if(!At.test(t))return!1;let i=t.slice(4)+t.slice(0,4),s="";for(let n of i)s+=n>="A"&&n<="Z"?String(n.charCodeAt(0)-55):n;let r=0;for(let n=0;n<s.length;n+=7)r=Number(String(r)+s.slice(n,n+7))%97;return r===1}function Lt(e){if(e.length<2||e.length>12)return!1;if(!Et.test(e))return!1;return!/[ -]{2}/.test(e)}var z=new Map([["email",(e)=>bt.test(e)&&e.length<=254],["uri",(e)=>yt.test(e)],["date",je],["time",qe],["date-time",$t],["phone",Ot],["iban",vt],["uuid",(e)=>gt.test(e)],["postal-code",Lt]]),hn=Object.freeze([...z.keys()]);function Ne(e){return z.has(e)}function Ie(){return[...z.keys()].sort()}function Me(e,t){let i=z.get(e);if(!i)return!0;return i(t)===!0}var _=1000,G=1e4,ie=1000,se=64,oe=9999;var _t=Object.freeze(["required","type","enum","const","pattern","format","minLength","maxLength","minimum","exclusiveMinimum","maximum","exclusiveMaximum","multipleOf","minItems","maxItems","uniqueItems"]),Re=Object.freeze({required:"This field is required.",type:"Please enter a valid value.",enum:"Please choose one of the allowed values.",const:"Please enter the required value.",pattern:"Please match the requested format.",format:"Please enter a valid value.",minLength:"Please lengthen this value.",maxLength:"Please shorten this value.",minimum:"Value is too small.",exclusiveMinimum:"Value is too small.",maximum:"Value is too large.",exclusiveMaximum:"Value is too large.",multipleOf:"Please enter a valid value.",minItems:"Please choose more items.",maxItems:"Please choose fewer items.",uniqueItems:"Please remove the duplicate entries."}),j=Object.freeze({rule:"Please check this value.","remote-error":"This value could not be checked right now."}),ae="en";function X(e,t){if(!t||typeof e!=="string"||e.indexOf("{")===-1)return e;return e.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(i,s)=>{if(!Object.prototype.hasOwnProperty.call(t,s))return i;let r=t[s];if(r===void 0||r===null)return i;if(Array.isArray(r))return r.map((n)=>String(n)).join(", ");return String(r)})}function q(e){let{messages:t,locale:i,path:s,rule:r,params:n,fallback:o}=e,u=e.defaultLocale||"en",f=[`${s}.${r}`,r];for(let a of[i,u]){if(!a)continue;let c=t&&Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0;if(!c)continue;for(let l of f){let m=Object.prototype.hasOwnProperty.call(c,l)?c[l]:void 0;if(typeof m==="string")return X(m,n)}}if(typeof o==="string")return X(o,n);for(let a of[Re,j])if(Object.prototype.hasOwnProperty.call(a,r)){let c=a[r];if(typeof c==="string")return X(c,n)}return r}function k(e){return{min:1,unbounded:!1,wide:!1,flex:!1,zeroWidth:!1,empty:!1,first:e,innerUnbounded:!1,innerSole:!1,ambiguous:!1}}function jt(e){return e.flex||e.innerSole}function qt(e,t){let i=e[t],s=null;if(i==="*")s={min:0,max:1/0,end:t+1};else if(i==="+")s={min:1,max:1/0,end:t+1};else if(i==="?")s={min:0,max:1,end:t+1};else if(i==="{"){let r=/^\{(\d+)(,(\d*))?\}/.exec(e.slice(t));if(!r)return null;let n=Number(r[1]),o=r[2]===void 0?n:r[3]===""?1/0:Number(r[3]);s={min:n,max:o,end:t+r[0].length}}if(s&&e[s.end]==="?")s.end+=1;return s}function Nt(e,t){if(e[t+2]==="{"&&"upP".includes(e[t+1])){let i=e.indexOf("}",t+3);if(i!==-1)return i+1}return t+2}function It(e,t){let i;try{i=e.map((s)=>new RegExp(`^(?:${s})$`))}catch{return!0}for(let s of t)if(i.filter((r)=>r.test(s)).length>1)return!0;return!1}function Mt(e){let t=["(?!)"];for(let i of e)if(t.push(i.first),!i.empty)return{first:t.join("|"),empty:!1};return{first:t.join("|"),empty:!0}}function H(e){let t=[{alternatives:[[]],zeroWidth:!1}],i=!1,s=!1,r=new Set(`${e} \u2028\uFEFF`);for(let f=0;f<128;f+=1)r.add(String.fromCharCode(f));let n=()=>{let f=t[t.length-1];return f.alternatives[f.alternatives.length-1]},o=()=>Object.assign(k("(?!)"),{zeroWidth:!0,empty:!0}),u=0;while(u<e.length){let f=e[u];if(f==="\\"){let a=Nt(e,u);n().push("bB".includes(e[u+1])?o():k(e.slice(u,a))),u=a}else if(f==="["){let a=u+1;while(a<e.length&&e[a]!=="]")a=e[a]==="\\"?a+2:a+1;n().push(k(e.slice(u,a+1))),u=a+1}else if(f==="("){let a=u+1,c=!1;if(e[a]==="?")if(e[a+1]==="="||e[a+1]==="!")c=!0,a+=2;else if(e[a+1]==="<"&&(e[a+2]==="="||e[a+2]==="!"))c=!0,a+=3;else if(e[a+1]==="<"){let l=e.indexOf(">",a+2);a=l===-1?a+2:l+1}else a+=2;t.push({alternatives:[[]],zeroWidth:c}),u=a}else if(f===")"&&t.length>1){let a=t.pop(),c=a.alternatives.map(Mt),l=a.zeroWidth?o():k(c.map((m)=>m.first).join("|"));l.empty||=c.some((m)=>m.empty),l.ambiguous=c.length>1&&It(c.map((m)=>m.first),r);for(let m of a.alternatives){if(m.some((p)=>p.unbounded||p.innerUnbounded))l.innerUnbounded=!0;if(m.some((p)=>p.ambiguous))l.ambiguous=!0;let b=m.findIndex(jt);if(b!==-1&&m.every((p,g)=>g===b||p.min===0||p.zeroWidth))l.innerSole=!0}n().push(l),u+=1}else if(f==="|")t[t.length-1].alternatives.push([]),u+=1;else if(f==="^"||f==="$")n().push(o()),u+=1;else{let a=qt(e,u),c=n(),l=c[c.length-1];if(a&&l){if(l.min=l.min*a.min,l.unbounded=a.max===1/0,l.wide=a.max>1,l.flex=l.wide&&a.max>a.min,a.min===0)l.empty=!0;if(!l.zeroWidth&&l.innerUnbounded&&l.wide)i=!0;if(!l.zeroWidth&&a.max>10&&(l.innerSole||l.ambiguous))s=!0;u=a.end}else n().push(k(f)),u+=1}}if(s)return"catastrophic";return i?"nested":null}function Y(e){return`${e} repeats a group that can match the same text more than one way, like (a+)+ or (a|a)+, and can backtrack catastrophically.`}var W="1";class J{constructor(e,t,i,s,r){this.version=W,this.fields=e,this.required=t,this.messages=i,this.defaultLocale=s,this.rules=r}}var Rt=["string","number","integer","boolean"],ke=new Set([...Rt,"object","array"]),Te=new Set(["version","fields","required","messages","defaultLocale","rules"]),R=["type","title","description","required","enum","const"],De={string:new Set([...R,"pattern","format","minLength","maxLength"]),number:new Set([...R,"minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"]),integer:new Set([...R,"minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"]),boolean:new Set(R),object:new Set([...R,"properties"]),array:new Set([...R,"items","minItems","maxItems","uniqueItems"])},kt=Object.freeze(Object.fromEntries(Object.entries(De).map(([e,t])=>[e,Object.freeze([...t].sort())]))),Tt=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"],Pt=0.000000001;function y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function w(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var Ce=new Set(["__proto__","constructor","prototype"]);function ce(e){return S(e).some((t)=>Ce.has(t))}function O(e,t){if(ce(e))throw new d(`the path "${e}" at ${t} names __proto__, constructor or prototype.`,t)}function A(e){return e.replace(/\[(\d+)\]/g,".$1")}function S(e){return A(e).split(".").filter((t)=>t.length>0)}function P(e,t){let i=e,s=t;while(s.length>0){if(i===void 0||i===null)return;if(y(i)&&w(i,s))return i[s];let r=S(s);if(r.length===0)return;let n=r[0];if(Array.isArray(i)){let o=Number(n);if(!Number.isInteger(o))return;i=i[o]}else if(y(i))i=w(i,n)?i[n]:void 0;else return;s=r.slice(1).join(".")}return i}function Dt(e){for(let t of S(e)){if(Ce.has(t))return!1;if(/^\d+$/.test(t)&&Number(t)>oe)return!1}return!0}function Pe(e,t,i){let s=S(t),r=e;for(let n=0;n<s.length-1;n++){let o=s[n],u=/^\d+$/.test(s[n+1]),f=w(r,o)?r[o]:void 0,a=y(f)||Array.isArray(f)?f:u?[]:{};r[o]=a,r=a}r[s[s.length-1]]=i}function Ct(e,t){let i=S(t),s=e;for(let n=0;n<i.length-1;n++)if(s=w(s,i[n])?s[i[n]]:void 0,!y(s)&&!Array.isArray(s))return;let r=i[i.length-1];if(Array.isArray(s))s.splice(Number(r),1);else if(y(s))delete s[r]}function T(e,t,i){let s=e[t];if(s===void 0)return;if(typeof s!=="number"||!Number.isFinite(s))throw new d(`"${t}" at ${i} must be a finite number.`,i)}function ue(e,t){if(!y(e))throw new d(`the field schema at ${t} must be an object.`,t);let i=e.type;if(typeof i!=="string"||!ke.has(i))throw new d(`the field at ${t} needs a "type" of ${[...ke].join(", ")}${i===void 0?"":` (got ${JSON.stringify(i)})`}.`,t);let s=De[i];for(let n of Object.keys(e))if(!s.has(n))throw new d(`unsupported keyword "${n}" at ${t} (a "${i}" field accepts ${[...s].sort().join(", ")}).`,t);let r={type:i,schema:e};if(e.required!==void 0)if(e.required===!0)r.selfRequired=!0;else if(i==="object"&&Array.isArray(e.required)){for(let n of e.required)if(typeof n!=="string")throw new d(`"required" at ${t} must list property names.`,t);r.requiredChildren=new Set(e.required)}else throw new d(i==="object"?`"required" at ${t} must be true (the object itself is required) or an array of property names.`:`"required" at ${t} must be true; only an object field may list property names.`,t);if(e.enum!==void 0&&(!Array.isArray(e.enum)||e.enum.length===0))throw new d(`"enum" at ${t} must be a non-empty array.`,t);if(i==="string"){if(e.pattern!==void 0){if(typeof e.pattern!=="string")throw new d(`"pattern" at ${t} must be a string.`,t);if(e.pattern.length>_)throw new d(`"pattern" at ${t} is ${e.pattern.length} characters; the limit is ${_}.`,t);try{r.regex=new RegExp(e.pattern)}catch(n){throw new d(`"pattern" at ${t} is not a valid regular expression: ${n instanceof Error?n.message:String(n)}`,t)}if(H(e.pattern)==="catastrophic")throw new d(Y(`"pattern" at ${t}`),t)}if(e.format!==void 0){if(typeof e.format!=="string"||!Ne(e.format))throw new d(`unknown format ${JSON.stringify(e.format)} at ${t} (known: ${Ie().join(", ")} — add one with registerFormat).`,t)}T(e,"minLength",t),T(e,"maxLength",t)}if(i==="number"||i==="integer"){for(let n of Tt)T(e,n,t);if(typeof e.multipleOf==="number"&&e.multipleOf<=0)throw new d(`"multipleOf" at ${t} must be greater than zero.`,t)}if(i==="object"){let n=new Map;if(e.properties!==void 0){if(!y(e.properties))throw new d(`"properties" at ${t} must be an object.`,t);for(let[o,u]of Object.entries(e.properties))O(o,`${t}.properties`),n.set(o,ue(u,`${t}.${o}`))}for(let o of r.requiredChildren??[])if(!n.has(o))throw new d(`"required" at ${t} names "${o}", which is not one of its properties.`,t);r.properties=n}if(i==="array"){if(T(e,"minItems",t),T(e,"maxItems",t),e.uniqueItems!==void 0&&typeof e.uniqueItems!=="boolean")throw new d(`"uniqueItems" at ${t} must be a boolean.`,t);if(e.items!==void 0){let n=ue(e.items,`${t}[]`);if(n.selfRequired)throw new d(`"required" at ${t}[] has no meaning: array items are checked by minItems, not by presence.`,`${t}[]`);r.items=n}}return r}function de(e){if(e instanceof J)return e;if(!y(e))throw new d("a definition must be an object.","");for(let s of Object.keys(e))if(!Te.has(s))throw new d(`unsupported definition key "${s}" (accepted: ${[...Te].sort().join(", ")}).`,s);if(e.version!==void 0&&e.version!==W)throw new d(`unsupported definition version ${JSON.stringify(e.version)}; this package implements "${W}".`,"version");if(e.fields!==void 0&&!y(e.fields))throw new d('"fields" must be a map of paths to field schemas.',"fields");if(e.messages!==void 0&&!y(e.messages))throw new d('"messages" must be a map of locales to message tables.',"messages");if(e.defaultLocale!==void 0&&typeof e.defaultLocale!=="string")throw new d('"defaultLocale" must be a string.',"defaultLocale");if(e.rules!==void 0&&!Array.isArray(e.rules))throw new d('"rules" must be an array.',"rules");let t=new Map;for(let[s,r]of Object.entries(e.fields??{})){if(S(s).length===0)throw new d('"fields" has an empty path key.',"fields");O(s,"fields"),t.set(A(s),ue(r,s))}let i=new Set;if(e.required!==void 0){if(!Array.isArray(e.required))throw new d('"required" must be an array of field paths.',"required");for(let s of e.required){if(typeof s!=="string")throw new d('"required" must list field paths as strings.',"required");let r=A(s);if(!t.has(r))throw new d(`"required" names "${s}", which is not a key of "fields".`,"required");i.add(r)}}return new J(t,i,e.messages??{},typeof e.defaultLocale==="string"?e.defaultLocale:ae,Array.isArray(e.rules)?e.rules:[])}function me(e){if(e===void 0||e===null)return!0;if(typeof e==="string"&&e.length===0)return!0;if(Array.isArray(e)&&e.length===0)return!0;return!1}function Ft(e,t){switch(t){case"string":return typeof e==="string";case"number":return typeof e==="number"&&Number.isFinite(e);case"integer":return typeof e==="number"&&Number.isInteger(e);case"boolean":return typeof e==="boolean";case"object":return y(e);case"array":return Array.isArray(e);default:return!1}}function N(e){if(Array.isArray(e))return`[${e.map(N).join(",")}]`;if(y(e))return`{${Object.keys(e).sort().map((t)=>`${JSON.stringify(t)}:${N(e[t])}`).join(",")}}`;return JSON.stringify(e)??"undefined"}function fe(e,t,i,s,r){let n=e.schema,o=(f,a)=>{r.findings.push({path:i,rule:f,message:q({messages:r.messages,locale:r.locale,defaultLocale:r.defaultLocale,path:i,rule:f,params:{path:i,title:n.title,...a}}),params:a})};if(me(t)){if(s)o("required",{});return}let u=e.type;if(!Ft(t,u)){o("type",{type:u});return}if(n.enum!==void 0){let f=n.enum;if(!f.some((a)=>N(a)===N(t)))o("enum",{allowed:f})}if(n.const!==void 0&&N(n.const)!==N(t))o("const",{const:n.const});if(u==="string"){let f=t;if(e.regex&&(f.length>G||!e.regex.test(f)))o("pattern",{pattern:n.pattern});if(typeof n.format==="string"&&!Me(n.format,f))o("format",{format:n.format});let a=[...f].length;if(typeof n.minLength==="number"&&a<n.minLength)o("minLength",{limit:n.minLength,actual:a});if(typeof n.maxLength==="number"&&a>n.maxLength)o("maxLength",{limit:n.maxLength,actual:a})}if(u==="number"||u==="integer"){let f=t;if(typeof n.minimum==="number"&&f<n.minimum)o("minimum",{limit:n.minimum});if(typeof n.exclusiveMinimum==="number"&&f<=n.exclusiveMinimum)o("exclusiveMinimum",{limit:n.exclusiveMinimum});if(typeof n.maximum==="number"&&f>n.maximum)o("maximum",{limit:n.maximum});if(typeof n.exclusiveMaximum==="number"&&f>=n.exclusiveMaximum)o("exclusiveMaximum",{limit:n.exclusiveMaximum});if(typeof n.multipleOf==="number"){let a=f/n.multipleOf;if(Math.abs(a-Math.round(a))>Pt)o("multipleOf",{multipleOf:n.multipleOf})}}if(u==="array"){let f=t;if(typeof n.minItems==="number"&&f.length<n.minItems)o("minItems",{limit:n.minItems,actual:f.length});if(typeof n.maxItems==="number"&&f.length>n.maxItems)o("maxItems",{limit:n.maxItems,actual:f.length});if(n.uniqueItems===!0){let a=new Set;for(let c=0;c<f.length;c++){let l=N(f[c]);if(a.has(l)){o("uniqueItems",{index:c});break}a.add(l)}}if(e.items)for(let a=0;a<f.length;a++)fe(e.items,f[a],`${i}.${a}`,!1,r)}if(u==="object"&&e.properties){let f=e.requiredChildren;for(let[a,c]of e.properties){let l=c.selfRequired===!0||f!==void 0&&f.has(a);fe(c,P(t,a),`${i}.${a}`,l,r)}}}function Fe(e,t,i){let s={findings:[],messages:e.messages,locale:i?.locale,defaultLocale:e.defaultLocale},r=i?.required;for(let[n,o]of e.fields){let u=o.selfRequired===!0||e.required.has(n)||r!==void 0&&r.has(n);fe(o,P(t,n),n,u,s)}return s.findings}var Ut=new Set(["true","on","yes","1"]),zt=new Set(["false","off","no","0"]),Gt=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function Xt(e,t){if(typeof e!=="string")return e;let i=e.trim();if(i.length===0)return;if(t==="number"||t==="integer")return Gt.test(i)?Number(i):e;if(t==="boolean"){let s=i.toLowerCase();if(Ut.has(s))return!0;if(zt.has(s))return!1;return e}return e}function le(e,t){if(e.type==="array"){if(t===void 0||t===null)return t;let i=Array.isArray(t)?t:t===""?[]:[t];return(e.items?i.map((r)=>le(e.items,r)):i.slice()).filter((r)=>r!==void 0)}if(e.type==="object"){if(!y(t))return t;let i={...t};for(let[s,r]of e.properties??[]){if(!Object.prototype.hasOwnProperty.call(i,s))continue;let n=le(r,i[s]);if(n===void 0)delete i[s];else i[s]=n}return i}return Xt(t,e.type)}function pe(e){let t={},i=(r,n)=>{if(typeof n!=="string"||ce(n))return;if(!w(t,n))t[n]=r;else if(Array.isArray(t[n]))t[n].push(r);else t[n]=[t[n],r]},s=e;if(s&&typeof s[Symbol.iterator]==="function"){for(let r of s)if(Array.isArray(r))i(r[1],r[0])}else if(s&&typeof s.forEach==="function")s.forEach(i);return t}function he(e,t){let i=de(e);if(!y(t))return{};let s=new Set;for(let n of i.fields.keys())s.add(S(n)[0]);let r={};for(let[n,o]of Object.entries(t)){if(ce(n))continue;let u=S(n);if(u.length>1&&s.has(u[0])&&Dt(n))Pe(r,n,o);else r[n]=o}for(let[n,o]of i.fields){let u=P(r,n);if(u===void 0)continue;let f=le(o,u);if(f===void 0)Ct(r,n);else Pe(r,n,f)}return r}var Ge=Object.freeze({var:0,missing:0,missing_some:2,if:0,and:1,or:1,"!":1,"!!":1,"==":2,"===":2,"!=":2,"!==":2,"<":2,"<=":2,">":2,">=":2,"+":1,"-":1,"*":1,"/":2,"%":2,min:1,max:1,cat:0,substr:2,in:2,some:2,all:2,none:2,date:3,regex:2}),Xe=Object.freeze(Object.keys(Ge)),Ht=new Set(Xe),He=Object.freeze(["==","!=","<","<=",">",">="]),Yt=new Set(He),Z=new Map,Wt=200;function V(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function E(e){if(Array.isArray(e))return e.length>0;return Boolean(e)}function I(e){return Array.isArray(e)?e:[e]}function D(e,t){let i=t??"",s=i?i:"this expression",r=0,n=(o,u)=>{if(r+=1,r>ie)throw new d(`the logic at ${s} has more than ${ie} nodes.`,i);if(u>se)throw new d(`the logic at ${s} nests deeper than ${se} levels.`,i);if(Array.isArray(o)){for(let m of o)n(m,u+1);return}if(!V(o))return;let f=Object.keys(o);if(f.length!==1)throw new d(`a logic expression at ${s} must be a single-operator object; this one has ${f.length===0?"none":`${f.length} (${f.join(", ")})`}.`,i);let a=f[0];if(!Ht.has(a))throw new d(`unsupported operator "${a}" at ${s} (implemented: ${Xe.join(", ")}).`,i);let c=I(o[a]),l=Ge[a];if(c.length<l)throw new d(`"${a}" at ${s} needs at least ${l} argument${l===1?"":"s"}, got ${c.length}.`,i);if(a==="date"&&!Yt.has(String(c[1])))throw new d(`"date" at ${s} needs one of ${He.join(", ")} as its middle argument (got ${JSON.stringify(c[1])}).`,i);if(a==="regex")Ye(c[0],i);for(let m of c)n(m,u+1)};n(e,0)}function Ye(e,t){let i=t?t:"this expression";if(typeof e!=="string")throw new d(`"regex" at ${i} needs a literal pattern string as its first argument.`,t);let s=Z.get(e);if(s)return s;if(e.length>_)throw new d(`the "regex" pattern at ${i} is ${e.length} characters; the limit is ${_}.`,t);let r;try{r=new RegExp(e)}catch(n){throw new d(`the "regex" pattern at ${i} is not a valid regular expression: ${n instanceof Error?n.message:String(n)}`,t)}if(H(e)==="catastrophic")throw new d(Y(`the "regex" pattern at ${i}`),t);if(Z.size>=Wt)Z.clear();return Z.set(e,r),r}function ge(e,t,i){if(t===void 0||t===null||t===""||Array.isArray(t)&&t.length===0)return e===void 0?null:e;let s=e;for(let r of String(t).split(".")){if(s===void 0||s===null)return i??null;if(Array.isArray(s)){let n=Number(r);s=Number.isInteger(n)?s[n]:void 0}else if(V(s))s=Object.prototype.hasOwnProperty.call(s,r)?s[r]:void 0;else return i??null}if(s===void 0)return i??null;return s}function Ue(e){return e===void 0||e===null||e===""}function x(e){return typeof e==="number"?e:parseFloat(String(e))}function ze(e){if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="string")return null;let t=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:?\d{2})?)?$/.exec(e.trim());if(!t)return null;let[,i,s,r,n,o,u,f,a]=t,c=Number(i),l=Number(s),m=Number(r);if(l<1||l>12||m<1||m>31)return null;let b=n===void 0?0:Number(n),p=o===void 0?0:Number(o),g=u===void 0?0:Number(u);if(b>23||p>59||g>59)return null;let U=f===void 0?0:Number(f.padEnd(3,"0")),te=Date.UTC(c,l-1,m,b,p,g,U),ne=new Date(te);if(ne.getUTCFullYear()!==c||ne.getUTCMonth()!==l-1||ne.getUTCDate()!==m)return null;if(a===void 0||a==="Z")return te;let rt=a[0]==="-"?1:-1,it=Number(a.slice(1,3)),st=Number(a.slice(-2));return te+rt*(it*60+st)*60000}function Jt(e,t,i){switch(t){case"==":return e===i;case"!=":return e!==i;case"<":return e<i;case"<=":return e<=i;case">":return e>i;default:return e>=i}}function h(e,t){if(Array.isArray(e))return e.map((n)=>h(n,t));if(!V(e))return e;let i=Object.keys(e)[0],s=e[i];if(i==="if"){let n=I(s);for(let o=0;o+1<n.length;o+=2)if(E(h(n[o],t)))return h(n[o+1],t);return n.length%2===1?h(n[n.length-1],t):null}if(i==="and"||i==="or"){let n=I(s),o=null;for(let u of n)if(o=h(u,t),E(o)===(i==="or"))return o;return o}if(i==="some"||i==="all"||i==="none"){let n=I(s),o=h(n[0],t);if(!Array.isArray(o))return i==="none";let u=o.some((f)=>E(h(n[1],f)));if(i==="some")return u;if(i==="none")return!u;return o.length>0&&o.every((f)=>E(h(n[1],f)))}if(i==="regex"){let n=I(s),o=Ye(n[0],""),u=h(n[1],t);if(typeof u!=="string"||u.length>G)return!1;return o.test(u)}let r=I(s).map((n)=>h(n,t));switch(i){case"var":return ge(t,r[0],r.length>1?r[1]:void 0);case"missing":return(r.length===1&&Array.isArray(r[0])?r[0]:r).filter((o)=>Ue(ge(t,o,void 0)));case"missing_some":{let n=Number(r[0]),o=Array.isArray(r[1])?r[1]:[r[1]],u=o.filter((f)=>Ue(ge(t,f,void 0)));return o.length-u.length>=n?[]:u}case"!":return!E(r[0]);case"!!":return E(r[0]);case"==":return r[0]==r[1];case"!=":return r[0]!=r[1];case"===":return r[0]===r[1];case"!==":return r[0]!==r[1];case"<":return r.length>2?r[0]<r[1]&&r[1]<r[2]:r[0]<r[1];case"<=":return r.length>2?r[0]<=r[1]&&r[1]<=r[2]:r[0]<=r[1];case">":return r.length>2?r[0]>r[1]&&r[1]>r[2]:r[0]>r[1];case">=":return r.length>2?r[0]>=r[1]&&r[1]>=r[2]:r[0]>=r[1];case"+":return r.map(x).reduce((n,o)=>n+o,0);case"-":return r.length===1?-x(r[0]):x(r[0])-x(r[1]);case"*":return r.map(x).reduce((n,o)=>n*o);case"/":return x(r[0])/x(r[1]);case"%":return x(r[0])%x(r[1]);case"min":return Math.min(...r);case"max":return Math.max(...r);case"cat":return r.map((n)=>n===null||n===void 0?"":String(n)).join("");case"substr":{let n=[...String(r[0])],o=Math.trunc(Number(r[1]))||0;if(o<0)o=Math.max(n.length+o,0);let u=n.length;if(r.length>2){let f=Math.trunc(Number(r[2]))||0;u=f<0?n.length+f:Math.min(o+f,n.length)}return n.slice(o,Math.max(u,o)).join("")}case"in":{let n=r[1];if(Array.isArray(n))return n.indexOf(r[0])!==-1;if(typeof n==="string")return n.indexOf(String(r[0]))!==-1;return!1}default:{let n=ze(r[0]),o=ze(r[2]);if(n===null||o===null)return!1;return Jt(n,String(r[1]),o)}}}function We(e){let t=[],i=(s)=>{if(Array.isArray(s)){for(let o of s)i(o);return}if(!V(s))return;let r=Object.keys(s)[0],n=I(s[r]);if(r==="var"){let o=n[0];if(typeof o==="string"&&o.length>0)t.push(o)}else if(r==="missing"||r==="missing_some"){for(let o of n.flat())if(typeof o==="string")t.push(o)}for(let o of n)i(o)};return i(e),t}var ye=Object.freeze(["show","require","validate","compute","jump"]),be="remote",K={show:["id","show","when"],require:["id","require","when"],validate:["id","validate","path","message","remote"],compute:["id","compute","value"],jump:["id","jump","from","when"]};Object.freeze(K);for(let e of Object.values(K))Object.freeze(e);var we=new WeakMap;function Je(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ze(e){return A(e).split(".").filter((t)=>t.length>0)}function v(e,t,i){if(typeof e!=="string"||e.length===0)throw new d(`"${t}" at ${i} must be a non-empty string.`,i);return e}function Zt(e,t,i){let s=`rules[${t}]`;if(!Je(e))throw new d(`the rule at ${s} must be an object.`,s);let r=v(e.id,"id",s),n=`rules[${t}] ("${r}")`,o=ye.filter((l)=>e[l]!==void 0);if(o.length===0)throw new d(`the rule at ${n} has no verb (one of ${ye.join(", ")}).`,n);if(o.length>1)throw new d(`the rule at ${n} has ${o.length} verbs (${o.join(", ")}); a rule does one thing.`,n);let u=o[0],f=K[u];for(let l of Object.keys(e))if(!f.includes(l))throw new d(`unsupported key "${l}" at ${n} (a "${u}" rule accepts ${f.join(", ")}).`,n);if(u==="show"||u==="require"){let l=A(v(e[u],u,n));if(O(l,n),e.when===void 0)throw new d(`"${u}" at ${n} needs a "when" condition; a rule with no condition never changes anything.`,n);if(u==="require"&&!i.has(l))throw new d(`"require" at ${n} names "${l}", which is not a key of "fields".`,n);return D(e.when,n),{id:r,verb:u,path:l,when:e.when}}if(u==="compute"){let l=A(v(e.compute,"compute",n));if(O(l,n),e.value===void 0)throw new d(`"compute" at ${n} needs a "value" expression.`,n);return D(e.value,n),{id:r,verb:u,path:l,value:e.value}}if(u==="jump"){let l=v(e.jump,"jump",n),m=v(e.from,"from",n);if(O(l,n),O(m,n),e.when!==void 0)D(e.when,n);return{id:r,verb:u,path:l,from:m,when:e.when}}let a=A(v(e.path,"path",n));O(a,n);let c=e.message===void 0?void 0:v(e.message,"message",n);if(e.validate===be){let l=v(e.remote,"remote",n);return{id:r,verb:u,path:a,message:c,remote:l,isRemote:!0}}if(e.remote!==void 0)throw new d(`"remote" at ${n} only belongs to a rule whose "validate" is ${JSON.stringify(be)}.`,n);return D(e.validate,n),{id:r,verb:u,path:a,message:c,logic:e.validate}}function Vt(e){if(e.length===0)return[];let t=e.map((o)=>o.path),i=e.map(()=>[]);for(let o=0;o<e.length;o++){let u=We(e[o].value).map(A);for(let f=0;f<e.length;f++){let a=t[f];if(u.some((l)=>l===a||l.startsWith(`${a}.`)||a.startsWith(`${l}.`)))i[o].push(f)}}let s=[],r=e.map(()=>!1),n=!0;while(s.length<e.length&&n){n=!1;for(let o=0;o<e.length;o++){if(r[o]||i[o].some((u)=>!r[u]))continue;r[o]=!0,s.push(e[o]),n=!0}}if(s.length<e.length){let o=e.filter((u,f)=>!r[f]);throw new d(o.length===1?`the "compute" rule "${o[0].id}" reads "${o[0].path}", the value it writes, so it can never settle.`:`the "compute" rules ${o.map((u)=>`"${u.id}"`).join(", ")} depend on each other in a cycle.`,"rules")}return s}function C(e){let t=de(e);if(!we.has(t)){let i=t.rules.map((n,o)=>Zt(n,o,t.fields)),s=new Set;for(let n of i){if(s.has(n.id))throw new d(`two rules share the id "${n.id}"; ids address messages, so they must be unique.`,"rules");s.add(n.id)}let r=Vt(i.filter((n)=>n.verb==="compute"));we.set(t,{all:i,computes:r})}return t}function Bt(e){return we.get(e)??{all:[],computes:[]}}function B(e,t,i){let[s,...r]=t,n=r.length>0&&/^\d+$/.test(r[0]);if(Array.isArray(e)){let u=e.slice(),f=Number(s);return u[f]=r.length===0?i:B(u[f],r,i),u}if(e===void 0||e===null){if(/^\d+$/.test(s)){let u=[];return u[Number(s)]=r.length===0?i:B(n?[]:{},r,i),u}}let o=Je(e)?{...e}:{};return o[s]=r.length===0?i:B(w(o,s)?o[s]:void 0,r,i),o}function Ee(e,t){let i=(r)=>w(e,r)&&e[r]===!1;if(i(t))return!0;let s=Ze(t);for(let r=1;r<s.length;r++)if(i(s.slice(0,r).join(".")))return!0;return!1}function Ve(e,t){let{all:i,computes:s}=Bt(e),r={},n={},o={},u={},f=t;for(let a of s){let c=h(a.value,f);r[a.path]=c,f=B(f,Ze(a.path),c)}for(let a of i)if(a.verb==="show"){let c=E(h(a.when,f));n[a.path]=(w(n,a.path)?n[a.path]:!0)&&c}for(let a of i)if(a.verb==="require"){let c=E(h(a.when,f));o[a.path]=(w(o,a.path)?o[a.path]:!1)||c}for(let a of Object.keys(o))if(Ee(n,a))o[a]=!1;for(let a of i){if(a.verb!=="jump")continue;let c=a.from;if(w(u,c))continue;if(a.when===void 0||E(h(a.when,f)))u[c]=a.path}return{computed:r,visible:n,required:o,next:u,data:f,rules:i}}function Ae(e,t){let i=Ve(C(e),t);return{visible:i.visible,required:i.required,computed:i.computed,next:i.next}}function Kt(e,t,i,s){if(Ee(i,e.path))return!1;if(t.fields.has(e.path)&&me(P(s,e.path)))return!1;return!0}function Qt(e,t,i,s,r,n){return{path:t.path,rule:i,message:n??q({messages:e.messages,locale:s,defaultLocale:e.defaultLocale,path:t.path,rule:i,params:{path:t.path,...r},fallback:i==="remote-error"?j["remote-error"]:t.message??j.rule}),params:r}}function xe(e,t,i){let s=C(e),r=i?.locale,n=Ve(s,t),o=new Set;for(let[a,c]of Object.entries(n.required))if(c)o.add(a);let u=Fe(s,n.data,{locale:r,required:o}).filter((a)=>!Ee(n.visible,a.path)),f=[];for(let a of n.rules){if(a.verb!=="validate")continue;if(!Kt(a,s,n.visible,n.data))continue;if(a.isRemote){f.push(a.id);continue}if(!E(h(a.logic,n.data)))u.push(Qt(s,a,a.id,r,{}))}return{valid:u.length===0&&f.length===0,findings:u,computed:n.computed,visible:n.visible,required:n.required,next:n.next,pending:f}}var M=null,Q=new WeakMap,Se=new WeakSet,Be=new WeakMap,Ke=new Set;function en(){return{visible:{},required:{},computed:{},next:{}}}function L(e,t,i){if(M&&M.devtools&&M.devtools.report&&M.devtools.report(e,t))return;if(Ke.has(e))return;if(Ke.add(e),typeof console<"u"&&console.warn)console.warn("[Faqir] l-rules: "+(i||e))}function F(e){return e.replace(/\[(\d+)\]/g,".$1")}function ee(e,t,i){let s=e.querySelectorAll("input, select, textarea"),r=F(t),n=[];for(let o=0;o<s.length;o++){if(!s[o].name)continue;let u=F(s[o].name);if(u===r||!i&&u.indexOf(r+".")===0)n.push(s[o])}return n}function tn(e){return e.closest('[data-ui="field-group"]')||e}function ve(e,t){let i=[],s=e.querySelectorAll("input, select, textarea");for(let r=0;r<s.length;r++){let n=s[r],o=n.name;if(!o||t.hidden.has(n))continue;if(n.tagName==="SELECT"){let u=n.options;for(let f=0;f<u.length;f++)if(u[f].selected&&!u[f].disabled)i.push([o,u[f].value]);continue}if(n.tagName==="INPUT"){let u=n.type;if(u==="submit"||u==="button"||u==="reset"||u==="image")continue;if((u==="checkbox"||u==="radio")&&!n.checked)continue;if(u==="file"){let f=n.files;for(let a=0;f&&a<f.length;a++)i.push([o,f[a]]);continue}}i.push([o,n.value])}return he(t.definition,pe(i))}function tt(e,t){for(let s=0;s<t.length;s++){let r=t[s].target;if(e.hidden.has(r))e.foreign.set(r,r.disabled)}let i=!1;if(e.hidden.forEach(function(s){let r=s;if(!r.disabled)e.foreign.set(s,!1),r.disabled=!0,i=!0}),i&&e.observer)e.observer.takeRecords()}function Le(e){tt(e,e.observer?e.observer.takeRecords():[])}function Qe(e,t,i){if(t.disabled===i)return;if(t.disabled=i,e.observer)e.observer.takeRecords()}function nn(e,t,i){let s=Object.keys(i);if(s.length===0)return;Le(t);let r=new Map,n=e.querySelectorAll("input, select, textarea");for(let o=0;o<n.length;o++){let u=n[o];if(!u.name)continue;let f=F(u.name),a=!1,c=!0;for(let m=0;m<s.length;m++)if(f===s[m]||f.indexOf(s[m]+".")===0){if(a=!0,i[s[m]]===!1)c=!1}if(!a)continue;let l=tn(u);if(r.set(l,r.get(l)===!0||!c),!c&&!t.hidden.has(u))t.foreign.set(u,u.disabled),t.hidden.add(u),Qe(t,u,!0);else if(c&&t.hidden.has(u)){let m=t.foreign.get(u)===!0;t.hidden.delete(u),t.foreign.delete(u),Qe(t,u,m)}}r.forEach(function(o,u){if(o&&!u.hasAttribute("hidden"))u.setAttribute("hidden",""),Se.add(u);else if(!o&&Se.has(u))u.removeAttribute("hidden"),Se.delete(u)})}function rn(e,t,i){let s=ee(e,t);for(let r=0;r<s.length;r++){let n=s[r],o=Be.get(n);if(!o)o={required:n.required===!0,aria:n.getAttribute("aria-required")==="true"},Be.set(n,o);let u=o.required||i===!0;if(n.required!==u)n.required=u;if(u||o.aria)n.setAttribute("aria-required","true");else n.removeAttribute("aria-required")}}function sn(e,t,i,s){if(t){let o=i.split("."),u=t,f=!0;for(let c=0;c<o.length-1&&f;c++){let l=u[o[c]];if(l&&typeof l==="object")u=l;else f=!1}let a=o[o.length-1];if(f&&u[a]!==s)u[a]=s}let r=s===void 0||s===null?"":String(s),n=ee(e,i,!0);for(let o=0;o<n.length;o++)if(n[o].value!==r)n[o].value=r}function $e(e,t){let i;try{Le(t),i=Ae(t.definition,ve(e,t))}catch(s){let r=s instanceof Error?s.message:String(s);L("l-rules could not evaluate its rules: "+r,e,r);return}nn(e,t,i.visible);for(let s in i.required)rn(e,s,i.required[s]);for(let s in i.computed)sn(e,t.scope,s,i.computed[s]);t.state.visible=i.visible,t.state.required=i.required,t.state.computed=i.computed,t.state.next=i.next}function on(e,t,i){for(let s=0;s<e.findings.length;s++){let r=e.findings[s];if(r.rule===t&&(i===void 0||r.path===i))return r.message}return!0}function et(e,t,i,s){return function(){try{return on(xe(t.definition,ve(e,t),{locale:t.locale}),i,s)}catch(r){let n=r instanceof Error?r.message:String(r);return L("l-rules could not evaluate its rules: "+n,e,n),!0}}}function an(e,t,i){return function(s){let r=ve(e,t);return fetch(i.remote,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:i.path,value:s,data:r})}).then(function(n){if(!n.ok)throw Error("remote check answered "+n.status);return n.json()}).then(function(n){if(!n||typeof n!=="object"||typeof n.ok!=="boolean")throw Error("remote check answered without a boolean `ok`");if(n.ok)return!0;if(typeof n.message==="string"&&n.message)return n.message;let o=F(i.path);return q({messages:t.definition.messages,locale:t.locale,defaultLocale:t.definition.defaultLocale,path:o,rule:i.id,params:{path:o,remote:i.remote},fallback:i.message||j.rule})})}}function un(e,t){let i=t.split(".");for(let s=i.length;s>0;s--){let r=e.fields.get(i.slice(0,s).join("."));if(!r)continue;for(let n=s;n<i.length&&r;n++)r=r.type==="object"&&r.properties?r.properties.get(i[n]):r.type==="array"&&/^\d+$/.test(i[n])?r.items:null;return!!(r&&r.regex)}return!1}function fn(e,t,i){let s=[];for(let f=0;f<i.length;f++){let a=i[f];if(!a||a.validate===void 0)continue;let c=a.validate==="remote"?an(e,t,a):et(e,t,a.id),l=a.path,m=[],b=ee(e,l,!0);for(let p=0;p<b.length;p++)if(m.indexOf(b[p].name)===-1)m.push(b[p].name);if(m.length===0)m.push(l);for(let p=0;p<m.length;p++)s.push({field:m[p],name:a.id,fn:c,message:a.message})}let r=s.length,n=e.querySelectorAll("input, textarea");for(let f=0;f<n.length;f++){let a=n[f];if(!a.name||a.hasAttribute("pattern"))continue;let c=F(a.name);if(un(t.definition,c))s.push({field:a.name,name:"pattern",fn:et(e,t,"pattern",c)})}if(s.length===0)return[];let o=M;if(!o.validate)return L("l-rules has "+s.length+" check(s) to run but faqir-validate is not loaded, so none of them can run. Load faqir-validate.js before faqir-rules.js.",e,"faqir-validate is not loaded; validate rules cannot run."),[];if(r>0&&!e.hasAttribute("l-validate"))L("l-rules has "+r+" validate rule(s) on a form with no l-validate, so nothing validates them on submit. Add l-validate to the form.",e,"a form with validate rules has no l-validate.");let u=[];for(let f=0;f<s.length;f++){let a=s[f],c=o.validate.register(e,a.field,a.name,a.fn,a.message);if(typeof c==="function")u.push(c)}return u}function ln(e,t){for(let i=0;i<t.length;i++){let s=t[i];if(!s||s.jump!==void 0||s.compute!==void 0)continue;let r=s.show||s.require||s.path;if(typeof r!=="string"||ee(e,r).length>0)continue;if(s.validate!==void 0){L('l-rules rule "'+s.id+'" is a form-level check: its path "'+r+'" names no control in this form, so a server can report it but this page has no field-group to show it on.',e,'rule "'+s.id+'" is a form-level check with nowhere to report.');continue}L('l-rules rule "'+s.id+'" names the field "'+r+'", which no control '+"in this form is named for — the rule will never change anything.",e,'rule "'+s.id+'" names an absent field "'+r+'".')}}function cn(e,t,i,s){let r=(t||"").trim();if(!r)return s.why="l-rules has no value, so there is no definition to apply.",null;let n=r.charAt(0);if(n==="#"||n==="."||n==="["){let u=null;try{u=document.querySelector(r)}catch(f){u=null}if(!u)return s.why='l-rules="'+r+'" matches no element.',null;try{return JSON.parse(u.textContent||"")}catch(f){return s.why='l-rules="'+r+'" found an element whose JSON does not parse.',null}}let o=M.evaluate(r,i,e);if(typeof o==="string")try{return JSON.parse(o)}catch(u){return s.why='l-rules="'+r+'" is a string that does not parse as JSON.',null}if(!o||typeof o!=="object")return s.why='l-rules="'+r+'" resolved to '+(o===void 0?"nothing":typeof o)+", not a rules definition.",null;return o}function nt(e){M=e,e.magic("rules",function(t,i){return Q.get(i)||en()}),e.directive("rules",function(t,i,s){let r={why:""},n=cn(t,i.expression,s,r);if(!n){L(r.why,t,r.why);return}let o;try{o=C(n)}catch(g){let U=g instanceof Error?g.message:String(g);L("l-rules refused this definition: "+U,t,U);return}let u=e.reactive({visible:{},required:{},computed:{},next:{}});Q.set(s,u);let f={definition:o,scope:s,state:u,locale:typeof document<"u"&&document.documentElement&&document.documentElement.lang||void 0,hidden:new Set,foreign:new Map,observer:null};if(typeof MutationObserver==="function")f.observer=new MutationObserver(function(g){tt(f,g)}),f.observer.observe(t,{subtree:!0,attributes:!0,attributeFilter:["disabled"]});let a=o.rules||[];ln(t,a);let c=fn(t,f,a);$e(t,f);let l=!0;function m(){$e(t,f)}function b(){setTimeout(function(){if(l)$e(t,f)},0)}function p(){Le(f)}return t.addEventListener("input",m,!0),t.addEventListener("change",m,!0),t.addEventListener("reset",b,!0),t.addEventListener("submit",p,!0),function(){if(l=!1,t.removeEventListener("input",m,!0),t.removeEventListener("change",m,!0),t.removeEventListener("reset",b,!0),t.removeEventListener("submit",p,!0),f.observer)f.observer.disconnect();for(let g=0;g<c.length;g++)c[g]();if(Q.get(s)===u)Q.delete(s)}})}var Oe=typeof globalThis<"u"&&globalThis.Faqir||typeof window<"u"&&window.Faqir;if(Oe&&typeof Oe.plugin==="function")Oe.plugin(nt);})();
|
|
63
|
+
(()=>{var{defineProperty:ie,getOwnPropertyNames:ot,getOwnPropertyDescriptor:at}=Object,ut=Object.prototype.hasOwnProperty;function ft(e){return this[e]}var lt=(e)=>{var t=(_e??=new WeakMap).get(e),i;if(t)return t;if(t=ie({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var s of ot(e))if(!ut.call(t,s))ie(t,s,{get:ft.bind(e,s),enumerable:!(i=at(e,s))||i.enumerable})}return _e.set(e,t),t},_e;var ct=(e)=>e;function dt(e,t){this[e]=ct.bind(null,t)}var mt=(e,t)=>{for(var i in t)ie(e,i,{get:t[i],enumerable:!0,configurable:!0,set:dt.bind(t,i)})};var dn={};mt(dn,{install:()=>nt});class d extends Error{constructor(e,t){super(`@faqir-ui/rules: ${e}`);this.name="DefinitionError",this.path=t}}var pt=/^(\d{4})-(\d{2})-(\d{2})$/,ht=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/i,gt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,yt=/^[A-Za-z][A-Za-z0-9+.-]*:[^\s\x00-\x1f]+$/,bt=/^[^\s@,;<>()[\]\\"]+@[^\s@.,;<>()[\]\\"]+(?:\.[^\s@.,;<>()[\]\\"]+)*\.[A-Za-z]{2,}$/,wt=/^\+?[0-9 ().-]{6,24}$/,Et=/^[A-Za-z0-9][A-Za-z0-9 -]{0,10}[A-Za-z0-9]$/,At=/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/,xt=[31,28,31,30,31,30,31,31,30,31,30,31];function St(e){return e%4===0&&e%100!==0||e%400===0}function je(e){let t=pt.exec(e);if(!t)return!1;let i=Number(t[1]),s=Number(t[2]),r=Number(t[3]);if(s<1||s>12||r<1)return!1;let n=s===2&&St(i)?29:xt[s-1];return r<=n}function qe(e){let t=ht.exec(e);if(!t)return!1;let i=Number(t[1]),s=Number(t[2]),r=t[3]===void 0?0:Number(t[3]);return i<=23&&s<=59&&r<=60}function $t(e){let t=/^(.+?)[Tt ](.+)$/.exec(e);if(!t)return!1;return je(t[1])&&qe(t[2])}function Ot(e){if(!wt.test(e))return!1;let t=e.replace(/\D/g,"");return t.length>=7&&t.length<=15}function vt(e){let t=e.replace(/[\s-]/g,"").toUpperCase();if(!At.test(t))return!1;let i=t.slice(4)+t.slice(0,4),s="";for(let n of i)s+=n>="A"&&n<="Z"?String(n.charCodeAt(0)-55):n;let r=0;for(let n=0;n<s.length;n+=7)r=Number(String(r)+s.slice(n,n+7))%97;return r===1}function Lt(e){if(e.length<2||e.length>12)return!1;if(!Et.test(e))return!1;return!/[ -]{2}/.test(e)}var z=new Map([["email",(e)=>bt.test(e)&&e.length<=254],["uri",(e)=>yt.test(e)],["date",je],["time",qe],["date-time",$t],["phone",Ot],["iban",vt],["uuid",(e)=>gt.test(e)],["postal-code",Lt]]),hn=Object.freeze([...z.keys()]);function Ne(e){return z.has(e)}function Ie(){return[...z.keys()].sort()}function Me(e,t){let i=z.get(e);if(!i)return!0;return i(t)===!0}var _=1000,G=1e4,se=1000,oe=64,ae=9999;var _t=Object.freeze(["required","type","enum","const","pattern","format","minLength","maxLength","minimum","exclusiveMinimum","maximum","exclusiveMaximum","multipleOf","minItems","maxItems","uniqueItems"]),Re=Object.freeze({required:"This field is required.",type:"Please enter a valid value.",enum:"Please choose one of the allowed values.",const:"Please enter the required value.",pattern:"Please match the requested format.",format:"Please enter a valid value.",minLength:"Please lengthen this value.",maxLength:"Please shorten this value.",minimum:"Value is too small.",exclusiveMinimum:"Value is too small.",maximum:"Value is too large.",exclusiveMaximum:"Value is too large.",multipleOf:"Please enter a valid value.",minItems:"Please choose more items.",maxItems:"Please choose fewer items.",uniqueItems:"Please remove the duplicate entries."}),j=Object.freeze({rule:"Please check this value.","remote-error":"This value could not be checked right now."}),ue="en";function X(e,t){if(!t||typeof e!=="string"||e.indexOf("{")===-1)return e;return e.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(i,s)=>{if(!Object.prototype.hasOwnProperty.call(t,s))return i;let r=t[s];if(r===void 0||r===null)return i;if(Array.isArray(r))return r.map((n)=>String(n)).join(", ");return String(r)})}function q(e){let{messages:t,locale:i,path:s,rule:r,params:n,fallback:o}=e,f=e.defaultLocale||"en",u=[`${s}.${r}`,r];for(let a of[i,f]){if(!a)continue;let c=t&&Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0;if(!c)continue;for(let l of u){let m=Object.prototype.hasOwnProperty.call(c,l)?c[l]:void 0;if(typeof m==="string")return X(m,n)}}if(typeof o==="string")return X(o,n);for(let a of[Re,j])if(Object.prototype.hasOwnProperty.call(a,r)){let c=a[r];if(typeof c==="string")return X(c,n)}return r}function k(e){return{min:1,unbounded:!1,wide:!1,flex:!1,zeroWidth:!1,empty:!1,first:e,innerUnbounded:!1,innerSole:!1,ambiguous:!1}}function jt(e){return e.flex||e.innerSole}function qt(e,t){let i=e[t],s=null;if(i==="*")s={min:0,max:1/0,end:t+1};else if(i==="+")s={min:1,max:1/0,end:t+1};else if(i==="?")s={min:0,max:1,end:t+1};else if(i==="{"){let r=/^\{(\d+)(,(\d*))?\}/.exec(e.slice(t));if(!r)return null;let n=Number(r[1]),o=r[2]===void 0?n:r[3]===""?1/0:Number(r[3]);s={min:n,max:o,end:t+r[0].length}}if(s&&e[s.end]==="?")s.end+=1;return s}function Nt(e,t){if(e[t+2]==="{"&&"upP".includes(e[t+1])){let i=e.indexOf("}",t+3);if(i!==-1)return i+1}return t+2}function It(e,t){let i;try{i=e.map((s)=>new RegExp(`^(?:${s})$`))}catch{return!0}for(let s of t)if(i.filter((r)=>r.test(s)).length>1)return!0;return!1}function Mt(e){let t=["(?!)"];for(let i of e)if(t.push(i.first),!i.empty)return{first:t.join("|"),empty:!1};return{first:t.join("|"),empty:!0}}function H(e){let t=[{alternatives:[[]],zeroWidth:!1}],i=!1,s=!1,r=new Set(`${e} \u2028\uFEFF`);for(let u=0;u<128;u+=1)r.add(String.fromCharCode(u));let n=()=>{let u=t[t.length-1];return u.alternatives[u.alternatives.length-1]},o=()=>Object.assign(k("(?!)"),{zeroWidth:!0,empty:!0}),f=0;while(f<e.length){let u=e[f];if(u==="\\"){let a=Nt(e,f);n().push("bB".includes(e[f+1])?o():k(e.slice(f,a))),f=a}else if(u==="["){let a=f+1;while(a<e.length&&e[a]!=="]")a=e[a]==="\\"?a+2:a+1;n().push(k(e.slice(f,a+1))),f=a+1}else if(u==="("){let a=f+1,c=!1;if(e[a]==="?")if(e[a+1]==="="||e[a+1]==="!")c=!0,a+=2;else if(e[a+1]==="<"&&(e[a+2]==="="||e[a+2]==="!"))c=!0,a+=3;else if(e[a+1]==="<"){let l=e.indexOf(">",a+2);a=l===-1?a+2:l+1}else a+=2;t.push({alternatives:[[]],zeroWidth:c}),f=a}else if(u===")"&&t.length>1){let a=t.pop(),c=a.alternatives.map(Mt),l=a.zeroWidth?o():k(c.map((m)=>m.first).join("|"));l.empty||=c.some((m)=>m.empty),l.ambiguous=c.length>1&&It(c.map((m)=>m.first),r);for(let m of a.alternatives){if(m.some((p)=>p.unbounded||p.innerUnbounded))l.innerUnbounded=!0;if(m.some((p)=>p.ambiguous))l.ambiguous=!0;let h=m.findIndex(jt);if(h!==-1&&m.every((p,y)=>y===h||p.min===0||p.zeroWidth))l.innerSole=!0}n().push(l),f+=1}else if(u==="|")t[t.length-1].alternatives.push([]),f+=1;else if(u==="^"||u==="$")n().push(o()),f+=1;else{let a=qt(e,f),c=n(),l=c[c.length-1];if(a&&l){if(l.min=l.min*a.min,l.unbounded=a.max===1/0,l.wide=a.max>1,l.flex=l.wide&&a.max>a.min,a.min===0)l.empty=!0;if(!l.zeroWidth&&l.innerUnbounded&&l.wide)i=!0;if(!l.zeroWidth&&a.max>10&&(l.innerSole||l.ambiguous))s=!0;f=a.end}else n().push(k(u)),f+=1}}if(s)return"catastrophic";return i?"nested":null}function Y(e){return`${e} repeats a group that can match the same text more than one way, like (a+)+ or (a|a)+, and can backtrack catastrophically.`}var W="1";class J{constructor(e,t,i,s,r){this.version=W,this.fields=e,this.required=t,this.messages=i,this.defaultLocale=s,this.rules=r}}var Rt=["string","number","integer","boolean"],ke=new Set([...Rt,"object","array"]),Te=new Set(["version","fields","required","messages","defaultLocale","rules"]),R=["type","title","description","required","enum","const"],De={string:new Set([...R,"pattern","format","minLength","maxLength"]),number:new Set([...R,"minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"]),integer:new Set([...R,"minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"]),boolean:new Set(R),object:new Set([...R,"properties"]),array:new Set([...R,"items","minItems","maxItems","uniqueItems"])},kt=Object.freeze(Object.fromEntries(Object.entries(De).map(([e,t])=>[e,Object.freeze([...t].sort())]))),Tt=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"],Pt=0.000000001;function b(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function w(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var Ce=new Set(["__proto__","constructor","prototype"]);function de(e){return S(e).some((t)=>Ce.has(t))}function O(e,t){if(de(e))throw new d(`the path "${e}" at ${t} names __proto__, constructor or prototype.`,t)}function A(e){return e.replace(/\[(\d+)\]/g,".$1")}function S(e){return A(e).split(".").filter((t)=>t.length>0)}function P(e,t){let i=e,s=t;while(s.length>0){if(i===void 0||i===null)return;if(b(i)&&w(i,s))return i[s];let r=S(s);if(r.length===0)return;let n=r[0];if(Array.isArray(i)){let o=Number(n);if(!Number.isInteger(o))return;i=i[o]}else if(b(i))i=w(i,n)?i[n]:void 0;else return;s=r.slice(1).join(".")}return i}function Dt(e){for(let t of S(e)){if(Ce.has(t))return!1;if(/^\d+$/.test(t)&&Number(t)>ae)return!1}return!0}function Pe(e,t,i){let s=S(t),r=e;for(let n=0;n<s.length-1;n++){let o=s[n],f=/^\d+$/.test(s[n+1]),u=w(r,o)?r[o]:void 0,a=b(u)||Array.isArray(u)?u:f?[]:{};r[o]=a,r=a}r[s[s.length-1]]=i}function Ct(e,t){let i=S(t),s=e;for(let n=0;n<i.length-1;n++)if(s=w(s,i[n])?s[i[n]]:void 0,!b(s)&&!Array.isArray(s))return;let r=i[i.length-1];if(Array.isArray(s))s.splice(Number(r),1);else if(b(s))delete s[r]}function T(e,t,i){let s=e[t];if(s===void 0)return;if(typeof s!=="number"||!Number.isFinite(s))throw new d(`"${t}" at ${i} must be a finite number.`,i)}function fe(e,t){if(!b(e))throw new d(`the field schema at ${t} must be an object.`,t);let i=e.type;if(typeof i!=="string"||!ke.has(i))throw new d(`the field at ${t} needs a "type" of ${[...ke].join(", ")}${i===void 0?"":` (got ${JSON.stringify(i)})`}.`,t);let s=De[i];for(let n of Object.keys(e))if(!s.has(n))throw new d(`unsupported keyword "${n}" at ${t} (a "${i}" field accepts ${[...s].sort().join(", ")}).`,t);let r={type:i,schema:e};if(e.required!==void 0)if(e.required===!0)r.selfRequired=!0;else if(i==="object"&&Array.isArray(e.required)){for(let n of e.required)if(typeof n!=="string")throw new d(`"required" at ${t} must list property names.`,t);r.requiredChildren=new Set(e.required)}else throw new d(i==="object"?`"required" at ${t} must be true (the object itself is required) or an array of property names.`:`"required" at ${t} must be true; only an object field may list property names.`,t);if(e.enum!==void 0&&(!Array.isArray(e.enum)||e.enum.length===0))throw new d(`"enum" at ${t} must be a non-empty array.`,t);if(i==="string"){if(e.pattern!==void 0){if(typeof e.pattern!=="string")throw new d(`"pattern" at ${t} must be a string.`,t);if(e.pattern.length>_)throw new d(`"pattern" at ${t} is ${e.pattern.length} characters; the limit is ${_}.`,t);try{r.regex=new RegExp(e.pattern)}catch(n){throw new d(`"pattern" at ${t} is not a valid regular expression: ${n instanceof Error?n.message:String(n)}`,t)}if(H(e.pattern)==="catastrophic")throw new d(Y(`"pattern" at ${t}`),t)}if(e.format!==void 0){if(typeof e.format!=="string"||!Ne(e.format))throw new d(`unknown format ${JSON.stringify(e.format)} at ${t} (known: ${Ie().join(", ")} — add one with registerFormat).`,t)}T(e,"minLength",t),T(e,"maxLength",t)}if(i==="number"||i==="integer"){for(let n of Tt)T(e,n,t);if(typeof e.multipleOf==="number"&&e.multipleOf<=0)throw new d(`"multipleOf" at ${t} must be greater than zero.`,t)}if(i==="object"){let n=new Map;if(e.properties!==void 0){if(!b(e.properties))throw new d(`"properties" at ${t} must be an object.`,t);for(let[o,f]of Object.entries(e.properties))O(o,`${t}.properties`),n.set(o,fe(f,`${t}.${o}`))}for(let o of r.requiredChildren??[])if(!n.has(o))throw new d(`"required" at ${t} names "${o}", which is not one of its properties.`,t);r.properties=n}if(i==="array"){if(T(e,"minItems",t),T(e,"maxItems",t),e.uniqueItems!==void 0&&typeof e.uniqueItems!=="boolean")throw new d(`"uniqueItems" at ${t} must be a boolean.`,t);if(e.items!==void 0){let n=fe(e.items,`${t}[]`);if(n.selfRequired)throw new d(`"required" at ${t}[] has no meaning: array items are checked by minItems, not by presence.`,`${t}[]`);r.items=n}}return r}function me(e){if(e instanceof J)return e;if(!b(e))throw new d("a definition must be an object.","");for(let s of Object.keys(e))if(!Te.has(s))throw new d(`unsupported definition key "${s}" (accepted: ${[...Te].sort().join(", ")}).`,s);if(e.version!==void 0&&e.version!==W)throw new d(`unsupported definition version ${JSON.stringify(e.version)}; this package implements "${W}".`,"version");if(e.fields!==void 0&&!b(e.fields))throw new d('"fields" must be a map of paths to field schemas.',"fields");if(e.messages!==void 0&&!b(e.messages))throw new d('"messages" must be a map of locales to message tables.',"messages");if(e.defaultLocale!==void 0&&typeof e.defaultLocale!=="string")throw new d('"defaultLocale" must be a string.',"defaultLocale");if(e.rules!==void 0&&!Array.isArray(e.rules))throw new d('"rules" must be an array.',"rules");let t=new Map;for(let[s,r]of Object.entries(e.fields??{})){if(S(s).length===0)throw new d('"fields" has an empty path key.',"fields");O(s,"fields"),t.set(A(s),fe(r,s))}let i=new Set;if(e.required!==void 0){if(!Array.isArray(e.required))throw new d('"required" must be an array of field paths.',"required");for(let s of e.required){if(typeof s!=="string")throw new d('"required" must list field paths as strings.',"required");let r=A(s);if(!t.has(r))throw new d(`"required" names "${s}", which is not a key of "fields".`,"required");i.add(r)}}return new J(t,i,e.messages??{},typeof e.defaultLocale==="string"?e.defaultLocale:ue,Array.isArray(e.rules)?e.rules:[])}function pe(e){if(e===void 0||e===null)return!0;if(typeof e==="string"&&e.length===0)return!0;if(Array.isArray(e)&&e.length===0)return!0;return!1}function Ft(e,t){switch(t){case"string":return typeof e==="string";case"number":return typeof e==="number"&&Number.isFinite(e);case"integer":return typeof e==="number"&&Number.isInteger(e);case"boolean":return typeof e==="boolean";case"object":return b(e);case"array":return Array.isArray(e);default:return!1}}function N(e){if(Array.isArray(e))return`[${e.map(N).join(",")}]`;if(b(e))return`{${Object.keys(e).sort().map((t)=>`${JSON.stringify(t)}:${N(e[t])}`).join(",")}}`;return JSON.stringify(e)??"undefined"}function le(e,t,i,s,r){let n=e.schema,o=(u,a)=>{r.findings.push({path:i,rule:u,message:q({messages:r.messages,locale:r.locale,defaultLocale:r.defaultLocale,path:i,rule:u,params:{path:i,title:n.title,...a}}),params:a})};if(pe(t)){if(s)o("required",{});return}let f=e.type;if(!Ft(t,f)){o("type",{type:f});return}if(n.enum!==void 0){let u=n.enum;if(!u.some((a)=>N(a)===N(t)))o("enum",{allowed:u})}if(n.const!==void 0&&N(n.const)!==N(t))o("const",{const:n.const});if(f==="string"){let u=t;if(e.regex&&(u.length>G||!e.regex.test(u)))o("pattern",{pattern:n.pattern});if(typeof n.format==="string"&&!Me(n.format,u))o("format",{format:n.format});let a=[...u].length;if(typeof n.minLength==="number"&&a<n.minLength)o("minLength",{limit:n.minLength,actual:a});if(typeof n.maxLength==="number"&&a>n.maxLength)o("maxLength",{limit:n.maxLength,actual:a})}if(f==="number"||f==="integer"){let u=t;if(typeof n.minimum==="number"&&u<n.minimum)o("minimum",{limit:n.minimum});if(typeof n.exclusiveMinimum==="number"&&u<=n.exclusiveMinimum)o("exclusiveMinimum",{limit:n.exclusiveMinimum});if(typeof n.maximum==="number"&&u>n.maximum)o("maximum",{limit:n.maximum});if(typeof n.exclusiveMaximum==="number"&&u>=n.exclusiveMaximum)o("exclusiveMaximum",{limit:n.exclusiveMaximum});if(typeof n.multipleOf==="number"){let a=u/n.multipleOf;if(Math.abs(a-Math.round(a))>Pt)o("multipleOf",{multipleOf:n.multipleOf})}}if(f==="array"){let u=t;if(typeof n.minItems==="number"&&u.length<n.minItems)o("minItems",{limit:n.minItems,actual:u.length});if(typeof n.maxItems==="number"&&u.length>n.maxItems)o("maxItems",{limit:n.maxItems,actual:u.length});if(n.uniqueItems===!0){let a=new Set;for(let c=0;c<u.length;c++){let l=N(u[c]);if(a.has(l)){o("uniqueItems",{index:c});break}a.add(l)}}if(e.items)for(let a=0;a<u.length;a++)le(e.items,u[a],`${i}.${a}`,!1,r)}if(f==="object"&&e.properties){let u=e.requiredChildren;for(let[a,c]of e.properties){let l=c.selfRequired===!0||u!==void 0&&u.has(a);le(c,P(t,a),`${i}.${a}`,l,r)}}}function Fe(e,t,i){let s={findings:[],messages:e.messages,locale:i?.locale,defaultLocale:e.defaultLocale},r=i?.required;for(let[n,o]of e.fields){let f=o.selfRequired===!0||e.required.has(n)||r!==void 0&&r.has(n);le(o,P(t,n),n,f,s)}return s.findings}var Ut=new Set(["true","on","yes","1"]),zt=new Set(["false","off","no","0"]),Gt=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function Xt(e,t){if(typeof e!=="string")return e;let i=e.trim();if(i.length===0)return;if(t==="number"||t==="integer")return Gt.test(i)?Number(i):e;if(t==="boolean"){let s=i.toLowerCase();if(Ut.has(s))return!0;if(zt.has(s))return!1;return e}return e}function ce(e,t){if(e.type==="array"){if(t===void 0||t===null)return t;let i=Array.isArray(t)?t:t===""?[]:[t];return(e.items?i.map((r)=>ce(e.items,r)):i.slice()).filter((r)=>r!==void 0)}if(e.type==="object"){if(!b(t))return t;let i={...t};for(let[s,r]of e.properties??[]){if(!Object.prototype.hasOwnProperty.call(i,s))continue;let n=ce(r,i[s]);if(n===void 0)delete i[s];else i[s]=n}return i}return Xt(t,e.type)}function he(e){let t={},i=(r,n)=>{if(typeof n!=="string"||de(n))return;if(!w(t,n))t[n]=r;else if(Array.isArray(t[n]))t[n].push(r);else t[n]=[t[n],r]},s=e;if(s&&typeof s[Symbol.iterator]==="function"){for(let r of s)if(Array.isArray(r))i(r[1],r[0])}else if(s&&typeof s.forEach==="function")s.forEach(i);return t}function ge(e,t){let i=me(e);if(!b(t))return{};let s=new Set;for(let n of i.fields.keys())s.add(S(n)[0]);let r={};for(let[n,o]of Object.entries(t)){if(de(n))continue;let f=S(n);if(f.length>1&&s.has(f[0])&&Dt(n))Pe(r,n,o);else r[n]=o}for(let[n,o]of i.fields){let f=P(r,n);if(f===void 0)continue;let u=ce(o,f);if(u===void 0)Ct(r,n);else Pe(r,n,u)}return r}var Ge=Object.freeze({var:0,missing:0,missing_some:2,if:0,and:1,or:1,"!":1,"!!":1,"==":2,"===":2,"!=":2,"!==":2,"<":2,"<=":2,">":2,">=":2,"+":1,"-":1,"*":1,"/":2,"%":2,min:1,max:1,cat:0,substr:2,in:2,some:2,all:2,none:2,date:3,regex:2}),Xe=Object.freeze(Object.keys(Ge)),Ht=new Set(Xe),He=Object.freeze(["==","!=","<","<=",">",">="]),Yt=new Set(He),Z=new Map,Wt=200;function V(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function E(e){if(Array.isArray(e))return e.length>0;return Boolean(e)}function I(e){return Array.isArray(e)?e:[e]}function D(e,t){let i=t??"",s=i?i:"this expression",r=0,n=(o,f)=>{if(r+=1,r>se)throw new d(`the logic at ${s} has more than ${se} nodes.`,i);if(f>oe)throw new d(`the logic at ${s} nests deeper than ${oe} levels.`,i);if(Array.isArray(o)){for(let m of o)n(m,f+1);return}if(!V(o))return;let u=Object.keys(o);if(u.length!==1)throw new d(`a logic expression at ${s} must be a single-operator object; this one has ${u.length===0?"none":`${u.length} (${u.join(", ")})`}.`,i);let a=u[0];if(!Ht.has(a))throw new d(`unsupported operator "${a}" at ${s} (implemented: ${Xe.join(", ")}).`,i);let c=I(o[a]),l=Ge[a];if(c.length<l)throw new d(`"${a}" at ${s} needs at least ${l} argument${l===1?"":"s"}, got ${c.length}.`,i);if(a==="date"&&!Yt.has(String(c[1])))throw new d(`"date" at ${s} needs one of ${He.join(", ")} as its middle argument (got ${JSON.stringify(c[1])}).`,i);if(a==="regex")Ye(c[0],i);for(let m of c)n(m,f+1)};n(e,0)}function Ye(e,t){let i=t?t:"this expression";if(typeof e!=="string")throw new d(`"regex" at ${i} needs a literal pattern string as its first argument.`,t);let s=Z.get(e);if(s)return s;if(e.length>_)throw new d(`the "regex" pattern at ${i} is ${e.length} characters; the limit is ${_}.`,t);let r;try{r=new RegExp(e)}catch(n){throw new d(`the "regex" pattern at ${i} is not a valid regular expression: ${n instanceof Error?n.message:String(n)}`,t)}if(H(e)==="catastrophic")throw new d(Y(`the "regex" pattern at ${i}`),t);if(Z.size>=Wt)Z.clear();return Z.set(e,r),r}function ye(e,t,i){if(t===void 0||t===null||t===""||Array.isArray(t)&&t.length===0)return e===void 0?null:e;let s=e;for(let r of String(t).split(".")){if(s===void 0||s===null)return i??null;if(Array.isArray(s)){let n=Number(r);s=Number.isInteger(n)?s[n]:void 0}else if(V(s))s=Object.prototype.hasOwnProperty.call(s,r)?s[r]:void 0;else return i??null}if(s===void 0)return i??null;return s}function Ue(e){return e===void 0||e===null||e===""}function x(e){return typeof e==="number"?e:parseFloat(String(e))}function ze(e){if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="string")return null;let t=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:?\d{2})?)?$/.exec(e.trim());if(!t)return null;let[,i,s,r,n,o,f,u,a]=t,c=Number(i),l=Number(s),m=Number(r);if(l<1||l>12||m<1||m>31)return null;let h=n===void 0?0:Number(n),p=o===void 0?0:Number(o),y=f===void 0?0:Number(f);if(h>23||p>59||y>59)return null;let U=u===void 0?0:Number(u.padEnd(3,"0")),ne=Date.UTC(c,l-1,m,h,p,y,U),re=new Date(ne);if(re.getUTCFullYear()!==c||re.getUTCMonth()!==l-1||re.getUTCDate()!==m)return null;if(a===void 0||a==="Z")return ne;let rt=a[0]==="-"?1:-1,it=Number(a.slice(1,3)),st=Number(a.slice(-2));return ne+rt*(it*60+st)*60000}function Jt(e,t,i){switch(t){case"==":return e===i;case"!=":return e!==i;case"<":return e<i;case"<=":return e<=i;case">":return e>i;default:return e>=i}}function g(e,t){if(Array.isArray(e))return e.map((n)=>g(n,t));if(!V(e))return e;let i=Object.keys(e)[0],s=e[i];if(i==="if"){let n=I(s);for(let o=0;o+1<n.length;o+=2)if(E(g(n[o],t)))return g(n[o+1],t);return n.length%2===1?g(n[n.length-1],t):null}if(i==="and"||i==="or"){let n=I(s),o=null;for(let f of n)if(o=g(f,t),E(o)===(i==="or"))return o;return o}if(i==="some"||i==="all"||i==="none"){let n=I(s),o=g(n[0],t);if(!Array.isArray(o))return i==="none";let f=o.some((u)=>E(g(n[1],u)));if(i==="some")return f;if(i==="none")return!f;return o.length>0&&o.every((u)=>E(g(n[1],u)))}if(i==="regex"){let n=I(s),o=Ye(n[0],""),f=g(n[1],t);if(typeof f!=="string"||f.length>G)return!1;return o.test(f)}let r=I(s).map((n)=>g(n,t));switch(i){case"var":return ye(t,r[0],r.length>1?r[1]:void 0);case"missing":return(r.length===1&&Array.isArray(r[0])?r[0]:r).filter((o)=>Ue(ye(t,o,void 0)));case"missing_some":{let n=Number(r[0]),o=Array.isArray(r[1])?r[1]:[r[1]],f=o.filter((u)=>Ue(ye(t,u,void 0)));return o.length-f.length>=n?[]:f}case"!":return!E(r[0]);case"!!":return E(r[0]);case"==":return r[0]==r[1];case"!=":return r[0]!=r[1];case"===":return r[0]===r[1];case"!==":return r[0]!==r[1];case"<":return r.length>2?r[0]<r[1]&&r[1]<r[2]:r[0]<r[1];case"<=":return r.length>2?r[0]<=r[1]&&r[1]<=r[2]:r[0]<=r[1];case">":return r.length>2?r[0]>r[1]&&r[1]>r[2]:r[0]>r[1];case">=":return r.length>2?r[0]>=r[1]&&r[1]>=r[2]:r[0]>=r[1];case"+":return r.map(x).reduce((n,o)=>n+o,0);case"-":return r.length===1?-x(r[0]):x(r[0])-x(r[1]);case"*":return r.map(x).reduce((n,o)=>n*o);case"/":return x(r[0])/x(r[1]);case"%":return x(r[0])%x(r[1]);case"min":return Math.min(...r);case"max":return Math.max(...r);case"cat":return r.map((n)=>n===null||n===void 0?"":String(n)).join("");case"substr":{let n=[...String(r[0])],o=Math.trunc(Number(r[1]))||0;if(o<0)o=Math.max(n.length+o,0);let f=n.length;if(r.length>2){let u=Math.trunc(Number(r[2]))||0;f=u<0?n.length+u:Math.min(o+u,n.length)}return n.slice(o,Math.max(f,o)).join("")}case"in":{let n=r[1];if(Array.isArray(n))return n.indexOf(r[0])!==-1;if(typeof n==="string")return n.indexOf(String(r[0]))!==-1;return!1}default:{let n=ze(r[0]),o=ze(r[2]);if(n===null||o===null)return!1;return Jt(n,String(r[1]),o)}}}function We(e){let t=[],i=(s)=>{if(Array.isArray(s)){for(let o of s)i(o);return}if(!V(s))return;let r=Object.keys(s)[0],n=I(s[r]);if(r==="var"){let o=n[0];if(typeof o==="string"&&o.length>0)t.push(o)}else if(r==="missing"||r==="missing_some"){for(let o of n.flat())if(typeof o==="string")t.push(o)}for(let o of n)i(o)};return i(e),t}var be=Object.freeze(["show","require","validate","compute","jump"]),we="remote",K={show:["id","show","when"],require:["id","require","when"],validate:["id","validate","path","message","remote"],compute:["id","compute","value"],jump:["id","jump","from","when"]};Object.freeze(K);for(let e of Object.values(K))Object.freeze(e);var Ee=new WeakMap;function Je(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ze(e){return A(e).split(".").filter((t)=>t.length>0)}function v(e,t,i){if(typeof e!=="string"||e.length===0)throw new d(`"${t}" at ${i} must be a non-empty string.`,i);return e}function Zt(e,t,i){let s=`rules[${t}]`;if(!Je(e))throw new d(`the rule at ${s} must be an object.`,s);let r=v(e.id,"id",s),n=`rules[${t}] ("${r}")`,o=be.filter((l)=>e[l]!==void 0);if(o.length===0)throw new d(`the rule at ${n} has no verb (one of ${be.join(", ")}).`,n);if(o.length>1)throw new d(`the rule at ${n} has ${o.length} verbs (${o.join(", ")}); a rule does one thing.`,n);let f=o[0],u=K[f];for(let l of Object.keys(e))if(!u.includes(l))throw new d(`unsupported key "${l}" at ${n} (a "${f}" rule accepts ${u.join(", ")}).`,n);if(f==="show"||f==="require"){let l=A(v(e[f],f,n));if(O(l,n),e.when===void 0)throw new d(`"${f}" at ${n} needs a "when" condition; a rule with no condition never changes anything.`,n);if(f==="require"&&!i.has(l))throw new d(`"require" at ${n} names "${l}", which is not a key of "fields".`,n);return D(e.when,n),{id:r,verb:f,path:l,when:e.when}}if(f==="compute"){let l=A(v(e.compute,"compute",n));if(O(l,n),e.value===void 0)throw new d(`"compute" at ${n} needs a "value" expression.`,n);return D(e.value,n),{id:r,verb:f,path:l,value:e.value}}if(f==="jump"){let l=v(e.jump,"jump",n),m=v(e.from,"from",n);if(O(l,n),O(m,n),e.when!==void 0)D(e.when,n);return{id:r,verb:f,path:l,from:m,when:e.when}}let a=A(v(e.path,"path",n));O(a,n);let c=e.message===void 0?void 0:v(e.message,"message",n);if(e.validate===we){let l=v(e.remote,"remote",n);return{id:r,verb:f,path:a,message:c,remote:l,isRemote:!0}}if(e.remote!==void 0)throw new d(`"remote" at ${n} only belongs to a rule whose "validate" is ${JSON.stringify(we)}.`,n);return D(e.validate,n),{id:r,verb:f,path:a,message:c,logic:e.validate}}function Vt(e){if(e.length===0)return[];let t=e.map((o)=>o.path),i=e.map(()=>[]);for(let o=0;o<e.length;o++){let f=We(e[o].value).map(A);for(let u=0;u<e.length;u++){let a=t[u];if(f.some((l)=>l===a||l.startsWith(`${a}.`)||a.startsWith(`${l}.`)))i[o].push(u)}}let s=[],r=e.map(()=>!1),n=!0;while(s.length<e.length&&n){n=!1;for(let o=0;o<e.length;o++){if(r[o]||i[o].some((f)=>!r[f]))continue;r[o]=!0,s.push(e[o]),n=!0}}if(s.length<e.length){let o=e.filter((f,u)=>!r[u]);throw new d(o.length===1?`the "compute" rule "${o[0].id}" reads "${o[0].path}", the value it writes, so it can never settle.`:`the "compute" rules ${o.map((f)=>`"${f.id}"`).join(", ")} depend on each other in a cycle.`,"rules")}return s}function C(e){let t=me(e);if(!Ee.has(t)){let i=t.rules.map((n,o)=>Zt(n,o,t.fields)),s=new Set;for(let n of i){if(s.has(n.id))throw new d(`two rules share the id "${n.id}"; ids address messages, so they must be unique.`,"rules");s.add(n.id)}let r=Vt(i.filter((n)=>n.verb==="compute"));Ee.set(t,{all:i,computes:r})}return t}function Bt(e){return Ee.get(e)??{all:[],computes:[]}}function B(e,t,i){let[s,...r]=t,n=r.length>0&&/^\d+$/.test(r[0]);if(Array.isArray(e)){let f=e.slice(),u=Number(s);return f[u]=r.length===0?i:B(f[u],r,i),f}if(e===void 0||e===null){if(/^\d+$/.test(s)){let f=[];return f[Number(s)]=r.length===0?i:B(n?[]:{},r,i),f}}let o=Je(e)?{...e}:{};return o[s]=r.length===0?i:B(w(o,s)?o[s]:void 0,r,i),o}function Ae(e,t){let i=(r)=>w(e,r)&&e[r]===!1;if(i(t))return!0;let s=Ze(t);for(let r=1;r<s.length;r++)if(i(s.slice(0,r).join(".")))return!0;return!1}function Ve(e,t){let{all:i,computes:s}=Bt(e),r={},n={},o={},f={},u=t;for(let a of s){let c=g(a.value,u);r[a.path]=c,u=B(u,Ze(a.path),c)}for(let a of i)if(a.verb==="show"){let c=E(g(a.when,u));n[a.path]=(w(n,a.path)?n[a.path]:!0)&&c}for(let a of i)if(a.verb==="require"){let c=E(g(a.when,u));o[a.path]=(w(o,a.path)?o[a.path]:!1)||c}for(let a of Object.keys(o))if(Ae(n,a))o[a]=!1;for(let a of i){if(a.verb!=="jump")continue;let c=a.from;if(w(f,c))continue;if(a.when===void 0||E(g(a.when,u)))f[c]=a.path}return{computed:r,visible:n,required:o,next:f,data:u,rules:i}}function xe(e,t){let i=Ve(C(e),t);return{visible:i.visible,required:i.required,computed:i.computed,next:i.next}}function Kt(e,t,i,s){if(Ae(i,e.path))return!1;if(t.fields.has(e.path)&&pe(P(s,e.path)))return!1;return!0}function Qt(e,t,i,s,r,n){return{path:t.path,rule:i,message:n??q({messages:e.messages,locale:s,defaultLocale:e.defaultLocale,path:t.path,rule:i,params:{path:t.path,...r},fallback:i==="remote-error"?j["remote-error"]:t.message??j.rule}),params:r}}function Se(e,t,i){let s=C(e),r=i?.locale,n=Ve(s,t),o=new Set;for(let[a,c]of Object.entries(n.required))if(c)o.add(a);let f=Fe(s,n.data,{locale:r,required:o}).filter((a)=>!Ae(n.visible,a.path)),u=[];for(let a of n.rules){if(a.verb!=="validate")continue;if(!Kt(a,s,n.visible,n.data))continue;if(a.isRemote){u.push(a.id);continue}if(!E(g(a.logic,n.data)))f.push(Qt(s,a,a.id,r,{}))}return{valid:f.length===0&&u.length===0,findings:f,computed:n.computed,visible:n.visible,required:n.required,next:n.next,pending:u}}var M=null,Q=new WeakMap,$e=new WeakSet,Be=new WeakMap,Ke=new Set;function en(){return{visible:{},required:{},computed:{},next:{}}}function L(e,t,i){if(M&&M.devtools&&M.devtools.report&&M.devtools.report(e,t))return;if(Ke.has(e))return;if(Ke.add(e),typeof console<"u"&&console.warn)console.warn("[Faqir] l-rules: "+(i||e))}function F(e){return e.replace(/\[(\d+)\]/g,".$1")}function te(e,t,i){let s=e.querySelectorAll("input, select, textarea"),r=F(t),n=[];for(let o=0;o<s.length;o++){if(!s[o].name)continue;let f=F(s[o].name);if(f===r||!i&&f.indexOf(r+".")===0)n.push(s[o])}return n}function tn(e){return e.closest('[data-ui="field-group"]')||e}function ve(e,t){let i=[],s=e.querySelectorAll("input, select, textarea");for(let r=0;r<s.length;r++){let n=s[r],o=n.name;if(!o||t.hidden.has(n))continue;if(n.tagName==="SELECT"){let f=n.options;for(let u=0;u<f.length;u++)if(f[u].selected&&!f[u].disabled)i.push([o,f[u].value]);continue}if(n.tagName==="INPUT"){let f=n.type;if(f==="submit"||f==="button"||f==="reset"||f==="image")continue;if((f==="checkbox"||f==="radio")&&!n.checked)continue;if(f==="file"){let u=n.files;for(let a=0;u&&a<u.length;a++)i.push([o,u[a]]);continue}}i.push([o,n.value])}return ge(t.definition,he(i))}function tt(e,t){for(let s=0;s<t.length;s++){let r=t[s].target;if(e.hidden.has(r))e.foreign.set(r,r.disabled)}let i=!1;if(e.hidden.forEach(function(s){let r=s;if(!r.disabled)e.foreign.set(s,!1),r.disabled=!0,i=!0}),i&&e.observer)e.observer.takeRecords()}function Le(e){tt(e,e.observer?e.observer.takeRecords():[])}function Qe(e,t,i){if(t.disabled===i)return;if(t.disabled=i,e.observer)e.observer.takeRecords()}function nn(e,t,i){let s=Object.keys(i),r=!1;if(s.length===0)return r;Le(t);let n=new Map,o=e.querySelectorAll("input, select, textarea");for(let f=0;f<o.length;f++){let u=o[f];if(!u.name)continue;let a=F(u.name),c=!1,l=!0;for(let h=0;h<s.length;h++)if(a===s[h]||a.indexOf(s[h]+".")===0){if(c=!0,i[s[h]]===!1)l=!1}if(!c)continue;let m=tn(u);if(n.set(m,n.get(m)===!0||!l),!l&&!t.hidden.has(u))r=!0,t.foreign.set(u,u.disabled),t.hidden.add(u),Qe(t,u,!0);else if(l&&t.hidden.has(u)){r=!0;let h=t.foreign.get(u)===!0;t.hidden.delete(u),t.foreign.delete(u),Qe(t,u,h)}}return n.forEach(function(f,u){if(f&&!u.hasAttribute("hidden"))u.setAttribute("hidden",""),$e.add(u);else if(!f&&$e.has(u))u.removeAttribute("hidden"),$e.delete(u)}),r}function rn(e,t,i){let s=te(e,t);for(let r=0;r<s.length;r++){let n=s[r],o=Be.get(n);if(!o)o={required:n.required===!0,aria:n.getAttribute("aria-required")==="true"},Be.set(n,o);let f=o.required||i===!0;if(n.required!==f)n.required=f;if(f||o.aria)n.setAttribute("aria-required","true");else n.removeAttribute("aria-required")}}function sn(e,t,i,s){if(t){let o=i.split("."),f=t,u=!0;for(let c=0;c<o.length-1&&u;c++){let l=f[o[c]];if(l&&typeof l==="object")f=l;else u=!1}let a=o[o.length-1];if(u&&f[a]!==s)f[a]=s}let r=s===void 0||s===null?"":String(s),n=te(e,i,!0);for(let o=0;o<n.length;o++)if(n[o].value!==r)n[o].value=r}function ee(e,t){let i;for(let s=0;s<4;s++){try{Le(t),i=xe(t.definition,ve(e,t))}catch(r){let n=r instanceof Error?r.message:String(r);L("l-rules could not evaluate its rules: "+n,e,n);return}if(!nn(e,t,i.visible))break}for(let s in i.required)rn(e,s,i.required[s]);for(let s in i.computed)sn(e,t.scope,s,i.computed[s]);t.state.visible=i.visible,t.state.required=i.required,t.state.computed=i.computed,t.state.next=i.next}function on(e,t,i){for(let s=0;s<e.findings.length;s++){let r=e.findings[s];if(r.rule===t&&(i===void 0||r.path===i))return r.message}return!0}function et(e,t,i,s){return function(){try{return on(Se(t.definition,ve(e,t),{locale:t.locale}),i,s)}catch(r){let n=r instanceof Error?r.message:String(r);return L("l-rules could not evaluate its rules: "+n,e,n),!0}}}function an(e,t,i){return function(s){let r=ve(e,t);return fetch(i.remote,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:i.path,value:s,data:r})}).then(function(n){if(!n.ok)throw Error("remote check answered "+n.status);return n.json()}).then(function(n){if(!n||typeof n!=="object"||typeof n.ok!=="boolean")throw Error("remote check answered without a boolean `ok`");if(n.ok)return!0;if(typeof n.message==="string"&&n.message)return n.message;let o=F(i.path);return q({messages:t.definition.messages,locale:t.locale,defaultLocale:t.definition.defaultLocale,path:o,rule:i.id,params:{path:o,remote:i.remote},fallback:i.message||j.rule})})}}function un(e,t){let i=t.split(".");for(let s=i.length;s>0;s--){let r=e.fields.get(i.slice(0,s).join("."));if(!r)continue;for(let n=s;n<i.length&&r;n++)r=r.type==="object"&&r.properties?r.properties.get(i[n]):r.type==="array"&&/^\d+$/.test(i[n])?r.items:null;return!!(r&&r.regex)}return!1}function fn(e,t,i){let s=[];for(let u=0;u<i.length;u++){let a=i[u];if(!a||a.validate===void 0)continue;let c=a.validate==="remote"?an(e,t,a):et(e,t,a.id),l=a.path,m=[],h=te(e,l,!0);for(let p=0;p<h.length;p++)if(m.indexOf(h[p].name)===-1)m.push(h[p].name);if(m.length===0)m.push(l);for(let p=0;p<m.length;p++)s.push({field:m[p],name:a.id,fn:c,message:a.message})}let r=s.length,n=e.querySelectorAll("input, textarea");for(let u=0;u<n.length;u++){let a=n[u];if(!a.name||a.hasAttribute("pattern"))continue;let c=F(a.name);if(un(t.definition,c))s.push({field:a.name,name:"pattern",fn:et(e,t,"pattern",c)})}if(s.length===0)return[];let o=M;if(!o.validate)return L("l-rules has "+s.length+" check(s) to run but faqir-validate is not loaded, so none of them can run. Load faqir-validate.js before faqir-rules.js.",e,"faqir-validate is not loaded; validate rules cannot run."),[];if(r>0&&!e.hasAttribute("l-validate"))L("l-rules has "+r+" validate rule(s) on a form with no l-validate, so nothing validates them on submit. Add l-validate to the form.",e,"a form with validate rules has no l-validate.");let f=[];for(let u=0;u<s.length;u++){let a=s[u],c=o.validate.register(e,a.field,a.name,a.fn,a.message);if(typeof c==="function")f.push(c)}return f}function ln(e,t){for(let i=0;i<t.length;i++){let s=t[i];if(!s||s.jump!==void 0||s.compute!==void 0)continue;let r=s.show||s.require||s.path;if(typeof r!=="string"||te(e,r).length>0)continue;if(s.validate!==void 0){L('l-rules rule "'+s.id+'" is a form-level check: its path "'+r+'" names no control in this form, so a server can report it but this page has no field-group to show it on.',e,'rule "'+s.id+'" is a form-level check with nowhere to report.');continue}L('l-rules rule "'+s.id+'" names the field "'+r+'", which no control '+"in this form is named for — the rule will never change anything.",e,'rule "'+s.id+'" names an absent field "'+r+'".')}}function cn(e,t,i,s){let r=(t||"").trim();if(!r)return s.why="l-rules has no value, so there is no definition to apply.",null;let n=r.charAt(0);if(n==="#"||n==="."||n==="["){let f=null;try{f=document.querySelector(r)}catch(u){f=null}if(!f)return s.why='l-rules="'+r+'" matches no element.',null;try{return JSON.parse(f.textContent||"")}catch(u){return s.why='l-rules="'+r+'" found an element whose JSON does not parse.',null}}let o=M.evaluate(r,i,e);if(typeof o==="string")try{return JSON.parse(o)}catch(f){return s.why='l-rules="'+r+'" is a string that does not parse as JSON.',null}if(!o||typeof o!=="object")return s.why='l-rules="'+r+'" resolved to '+(o===void 0?"nothing":typeof o)+", not a rules definition.",null;return o}function nt(e){M=e,e.magic("rules",function(t,i){return Q.get(i)||en()}),e.directive("rules",function(t,i,s){let r={why:""},n=cn(t,i.expression,s,r);if(!n){L(r.why,t,r.why);return}let o;try{o=C(n)}catch(y){let U=y instanceof Error?y.message:String(y);L("l-rules refused this definition: "+U,t,U);return}let f=e.reactive({visible:{},required:{},computed:{},next:{}});Q.set(s,f);let u={definition:o,scope:s,state:f,locale:typeof document<"u"&&document.documentElement&&document.documentElement.lang||void 0,hidden:new Set,foreign:new Map,observer:null};if(typeof MutationObserver==="function")u.observer=new MutationObserver(function(y){tt(u,y)}),u.observer.observe(t,{subtree:!0,attributes:!0,attributeFilter:["disabled"]});let a=o.rules||[];ln(t,a);let c=fn(t,u,a);ee(t,u);let l=!0;Promise.resolve().then(function(){if(l)ee(t,u)});function m(){ee(t,u)}function h(){setTimeout(function(){if(l)ee(t,u)},0)}function p(){Le(u)}return t.addEventListener("input",m,!0),t.addEventListener("change",m,!0),t.addEventListener("reset",h,!0),t.addEventListener("submit",p,!0),function(){if(l=!1,t.removeEventListener("input",m,!0),t.removeEventListener("change",m,!0),t.removeEventListener("reset",h,!0),t.removeEventListener("submit",p,!0),u.observer)u.observer.disconnect();for(let y=0;y<c.length;y++)c[y]();if(Q.get(s)===f)Q.delete(s)}})}var Oe=typeof globalThis<"u"&&globalThis.Faqir||typeof window<"u"&&window.Faqir;if(Oe&&typeof Oe.plugin==="function")Oe.plugin(nt);})();
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// @ui:plugin faqir-tweak
|
|
2
|
+
// @ui:provides l-tweak
|
|
3
|
+
/**
|
|
4
|
+
* faqir-tweak — a live theme studio for any Faqir page.
|
|
5
|
+
*
|
|
6
|
+
* <aside l-tweak aria-label="Theme studio"></aside>
|
|
7
|
+
*
|
|
8
|
+
* Mounts a panel of dials into the element: scheme and density, the accent's
|
|
9
|
+
* hue and chroma, the radius, spacing, type and motion scales, the heading
|
|
10
|
+
* voice, easing personality, hover lift, edge weight, depth and material.
|
|
11
|
+
* Every dial writes design tokens onto `<html>` as inline custom properties —
|
|
12
|
+
* nothing is recompiled, every component on the page follows at once — and
|
|
13
|
+
* `Faqir.tweak.css()` hands back the overrides as a `:root` block to paste
|
|
14
|
+
* into a theme. The state persists in localStorage, so a tweak survives a
|
|
15
|
+
* reload. Self-registering, zero dependencies.
|
|
16
|
+
*/
|
|
17
|
+
(function () {
|
|
18
|
+
"use strict";
|
|
19
|
+
|
|
20
|
+
var KEY = "faqir:tweak";
|
|
21
|
+
var root = typeof document !== "undefined" ? document.documentElement : null;
|
|
22
|
+
|
|
23
|
+
// Token families each scale dial multiplies. A dial never invents a value:
|
|
24
|
+
// it reads what the theme computed, scales the number, keeps the unit.
|
|
25
|
+
var SCALES = {
|
|
26
|
+
radius: ["--radius-sm", "--radius-md", "--radius-lg", "--radius-xl", "--radius-2xl"],
|
|
27
|
+
space: ["--space-0h", "--space-1", "--space-1h", "--space-2", "--space-2h", "--space-3", "--space-3h", "--space-4", "--space-5", "--space-6", "--space-7", "--space-8", "--space-10", "--space-12", "--space-16", "--space-20", "--space-24", "--space-32", "--control-height-sm", "--control-height-md", "--control-height-lg"],
|
|
28
|
+
type: ["--text-xs", "--text-sm", "--text-base", "--text-lg", "--text-xl", "--text-2xl", "--text-3xl", "--text-4xl"],
|
|
29
|
+
speed: ["--duration-instant", "--duration-fast", "--duration-normal", "--duration-slow", "--duration-slower", "--duration-slowest", "--motion-stagger", "--motion-ambient-duration"],
|
|
30
|
+
};
|
|
31
|
+
var ACCENT = ["--color-primary", "--color-primary-hover", "--color-primary-active", "--color-primary-subtle", "--color-ring"];
|
|
32
|
+
var SHADOWS = ["--shadow-xs", "--shadow-sm", "--shadow-md", "--shadow-lg", "--shadow-xl"];
|
|
33
|
+
var EASING = { spring: "var(--ease-spring)", bounce: "var(--ease-bounce)", linear: "var(--ease-linear)" };
|
|
34
|
+
var BORDER = { hairline: ["sm", "md"], regular: ["md", "lg"], heavy: ["lg", "lg"] };
|
|
35
|
+
var FONTS = { sans: "var(--font-sans)", serif: "var(--font-serif)", mono: "var(--font-mono)" };
|
|
36
|
+
var TEXTURES = ["none", "grain", "paper", "dots", "grid", "stripes", "mesh"];
|
|
37
|
+
|
|
38
|
+
var DEFAULTS = {
|
|
39
|
+
scheme: "", density: "", hue: 0, chroma: 1, radius: 1, space: 1, type: 1, speed: 1,
|
|
40
|
+
weight: "", tracking: "", headingFont: "", bodyFont: "", easing: "",
|
|
41
|
+
lift: "", ambient: "", border: "", depth: "", page: "", surface: "",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var base = null; // token → computed value, read once before the first write
|
|
45
|
+
var attrs = null; // the page's own data-theme / data-density
|
|
46
|
+
var wrote = { "data-theme": null, "data-density": null }; // what the studio last set
|
|
47
|
+
var state = null;
|
|
48
|
+
var applied = [];
|
|
49
|
+
var panels = [];
|
|
50
|
+
|
|
51
|
+
function computed(name) {
|
|
52
|
+
return getComputedStyle(root).getPropertyValue(name).trim();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function capture() {
|
|
56
|
+
if (base) return;
|
|
57
|
+
base = {};
|
|
58
|
+
Object.keys(SCALES).forEach(function (k) {
|
|
59
|
+
SCALES[k].forEach(function (t) { base[t] = computed(t); });
|
|
60
|
+
});
|
|
61
|
+
ACCENT.forEach(function (t) { base[t] = computed(t); });
|
|
62
|
+
attrs = {};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// "0.375rem" × 1.5 → "0.5625rem"; a value with no leading number is kept.
|
|
66
|
+
function scaled(value, k) {
|
|
67
|
+
var m = /^(-?[\d.]+)([a-z%]*)$/.exec(value);
|
|
68
|
+
if (!m) return value;
|
|
69
|
+
return String(Math.round(parseFloat(m[1]) * k * 10000) / 10000) + m[2];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The complete override set for a state: token → value. One pure function,
|
|
73
|
+
// so the panel, the export and the restore all agree on what a state means.
|
|
74
|
+
function overrides(s) {
|
|
75
|
+
var out = {};
|
|
76
|
+
["radius", "space", "type", "speed"].forEach(function (k) {
|
|
77
|
+
if (+s[k] !== 1) SCALES[k].forEach(function (t) { out[t] = scaled(base[t], +s[k]); });
|
|
78
|
+
});
|
|
79
|
+
if (+s.hue !== 0 || +s.chroma !== 1) {
|
|
80
|
+
ACCENT.forEach(function (t) {
|
|
81
|
+
out[t] = "oklch(from " + base[t] + " l calc(c * " + s.chroma + ") calc(h + " + s.hue + "))";
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (s.weight) out["--heading-weight"] = s.weight;
|
|
85
|
+
if (s.tracking) out["--heading-tracking"] = s.tracking + "em";
|
|
86
|
+
if (FONTS[s.headingFont]) out["--font-heading"] = FONTS[s.headingFont];
|
|
87
|
+
if (FONTS[s.bodyFont]) { out["--font-body"] = FONTS[s.bodyFont]; out["--font-ui"] = FONTS[s.bodyFont]; }
|
|
88
|
+
if (EASING[s.easing]) {
|
|
89
|
+
out["--ease-default"] = EASING[s.easing];
|
|
90
|
+
out["--motion-enter-ease"] = EASING[s.easing];
|
|
91
|
+
out["--motion-reveal-ease"] = EASING[s.easing];
|
|
92
|
+
}
|
|
93
|
+
if (s.lift) out["--motion-hover-lift"] = s.lift;
|
|
94
|
+
if (s.ambient === "paused") out["--motion-ambient-play"] = "paused";
|
|
95
|
+
if (BORDER[s.border]) {
|
|
96
|
+
out["--border-width"] = "var(--border-width-" + BORDER[s.border][0] + ")";
|
|
97
|
+
out["--border-width-strong"] = "var(--border-width-" + BORDER[s.border][1] + ")";
|
|
98
|
+
}
|
|
99
|
+
if (s.depth === "flat") SHADOWS.forEach(function (t) { out[t] = "none"; });
|
|
100
|
+
if (s.depth === "deep") SHADOWS.forEach(function (t, i) { out[t] = "var(" + SHADOWS[Math.min(i + 1, 4)] + ")"; });
|
|
101
|
+
if (s.page) out["--texture-page"] = "var(--texture-" + s.page + ")";
|
|
102
|
+
if (s.surface) out["--texture-surface"] = "var(--texture-" + s.surface + ")";
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// A page may switch its own data-theme after the studio is open (a theme
|
|
107
|
+
// toggle); an attribute the studio did not write is the page's, and is what a
|
|
108
|
+
// cleared dial goes back to.
|
|
109
|
+
function setAttr(name, value) {
|
|
110
|
+
var current = root.getAttribute(name);
|
|
111
|
+
if (current !== wrote[name]) attrs[name] = current;
|
|
112
|
+
var next = value || attrs[name];
|
|
113
|
+
if (next) root.setAttribute(name, next);
|
|
114
|
+
else root.removeAttribute(name);
|
|
115
|
+
wrote[name] = next || null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function apply(next) {
|
|
119
|
+
capture();
|
|
120
|
+
state = {};
|
|
121
|
+
Object.keys(DEFAULTS).forEach(function (k) { state[k] = next && k in next ? next[k] : DEFAULTS[k]; });
|
|
122
|
+
applied.forEach(function (t) { root.style.removeProperty(t); });
|
|
123
|
+
var out = overrides(state);
|
|
124
|
+
applied = Object.keys(out);
|
|
125
|
+
applied.forEach(function (t) { root.style.setProperty(t, out[t]); });
|
|
126
|
+
setAttr("data-theme", state.scheme);
|
|
127
|
+
setAttr("data-density", state.density);
|
|
128
|
+
try { localStorage.setItem(KEY, JSON.stringify(state)); } catch (e) {}
|
|
129
|
+
panels.forEach(function (sync) { sync(); });
|
|
130
|
+
return state;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function css() {
|
|
134
|
+
capture();
|
|
135
|
+
var out = overrides(state || DEFAULTS);
|
|
136
|
+
var lines = Object.keys(out).map(function (t) { return " " + t + ": " + out[t] + ";"; });
|
|
137
|
+
var head = [];
|
|
138
|
+
if (state && state.scheme) head.push('data-theme="' + state.scheme + '"');
|
|
139
|
+
if (state && state.density) head.push('data-density="' + state.density + '"');
|
|
140
|
+
return (head.length ? "/* <html " + head.join(" ") + "> */\n" : "") + ":root {\n" + lines.join("\n") + "\n}\n";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function restore() {
|
|
144
|
+
try {
|
|
145
|
+
var saved = JSON.parse(localStorage.getItem(KEY) || "null");
|
|
146
|
+
if (saved) apply(saved);
|
|
147
|
+
} catch (e) {}
|
|
148
|
+
return state;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── The panel ──
|
|
152
|
+
// Built from the registry's own primitives, so the studio is styled by the
|
|
153
|
+
// very tokens it edits. Every control is labelled; every value is announced.
|
|
154
|
+
function h(tag, attributes, children) {
|
|
155
|
+
var el = document.createElement(tag);
|
|
156
|
+
Object.keys(attributes || {}).forEach(function (k) {
|
|
157
|
+
if (attributes[k] == null) return;
|
|
158
|
+
if (k === "text") el.textContent = attributes[k];
|
|
159
|
+
else el.setAttribute(k, attributes[k]);
|
|
160
|
+
});
|
|
161
|
+
(children || []).forEach(function (c) { el.appendChild(c); });
|
|
162
|
+
return el;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var uid = 0;
|
|
166
|
+
|
|
167
|
+
function merged(next) {
|
|
168
|
+
var s = {};
|
|
169
|
+
Object.keys(state).forEach(function (k) { s[k] = state[k]; });
|
|
170
|
+
Object.keys(next).forEach(function (k) { s[k] = next[k]; });
|
|
171
|
+
return s;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function range(key, min, max, step, format) {
|
|
175
|
+
var input = h("input", { type: "range", min: min, max: max, step: step, "data-tweak": key });
|
|
176
|
+
var out = h("output", { "data-ui": "text", "data-size": "sm", "data-variant": "muted" });
|
|
177
|
+
input.addEventListener("input", function () {
|
|
178
|
+
var next = {}; next[key] = +input.value;
|
|
179
|
+
apply(merged(next));
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
input: input,
|
|
183
|
+
node: h("div", { "data-ui": "cluster", "data-gap": "3", "data-align": "center" }, [input, out]),
|
|
184
|
+
sync: function () { input.value = state[key]; out.textContent = format(state[key]); },
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function select(key, options) {
|
|
189
|
+
var input = h("select", { "data-ui": "select", "data-tweak": key });
|
|
190
|
+
options.forEach(function (o) { input.appendChild(h("option", { value: o[0], text: o[1] })); });
|
|
191
|
+
input.addEventListener("change", function () {
|
|
192
|
+
var next = {}; next[key] = input.value;
|
|
193
|
+
apply(merged(next));
|
|
194
|
+
});
|
|
195
|
+
return { input: input, node: input, sync: function () { input.value = state[key]; } };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function section(title, open, rows) {
|
|
199
|
+
return h("details", { "data-ui": "collapsible", "data-variant": "bordered", open: open ? "" : null }, [
|
|
200
|
+
h("summary", { "data-part": "trigger", text: title }),
|
|
201
|
+
h("div", { "data-part": "content" }, [h("div", { "data-ui": "stack", "data-gap": "4" }, rows)]),
|
|
202
|
+
]);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function times(v) { return "× " + v; }
|
|
206
|
+
function pct(v) { return Math.round(v * 100) + "%"; }
|
|
207
|
+
|
|
208
|
+
function mount(el) {
|
|
209
|
+
capture();
|
|
210
|
+
if (!state && !restore()) apply(null);
|
|
211
|
+
var controls = [];
|
|
212
|
+
function row(label, c) {
|
|
213
|
+
controls.push(c);
|
|
214
|
+
var id = "faqir-tweak-" + ++uid;
|
|
215
|
+
c.input.setAttribute("id", id);
|
|
216
|
+
return h("div", { "data-ui": "field-group" }, [h("label", { "data-ui": "label", "for": id, text: label }), c.node]);
|
|
217
|
+
}
|
|
218
|
+
var textures = TEXTURES.map(function (t) { return [t === "none" ? "" : t, t]; });
|
|
219
|
+
var defaultOr = function (pairs) { return [["", "Theme default"]].concat(pairs); };
|
|
220
|
+
|
|
221
|
+
var status = h("p", { "data-ui": "text", "data-size": "sm", "data-variant": "muted", "aria-live": "polite" });
|
|
222
|
+
var copy = h("button", { "data-ui": "button", "data-variant": "primary", type: "button", text: "Copy CSS" });
|
|
223
|
+
copy.addEventListener("click", function () {
|
|
224
|
+
var text = css();
|
|
225
|
+
var done = function () { status.textContent = "Copied " + applied.length + " overrides."; };
|
|
226
|
+
var show = function () { status.textContent = text; };
|
|
227
|
+
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(text).then(done, show);
|
|
228
|
+
else show();
|
|
229
|
+
});
|
|
230
|
+
var reset = h("button", { "data-ui": "button", "data-variant": "outline", type: "button", text: "Reset" });
|
|
231
|
+
reset.addEventListener("click", function () { apply(null); status.textContent = "Back to the theme."; });
|
|
232
|
+
|
|
233
|
+
var panel = h("div", { "data-ui": "stack", "data-gap": "3" }, [
|
|
234
|
+
section("Scheme & density", true, [
|
|
235
|
+
row("Colour scheme", select("scheme", defaultOr([["light", "Light"], ["dark", "Dark"], ["auto", "Follow the system"]]))),
|
|
236
|
+
row("Density", select("density", defaultOr([["compact", "Compact"], ["comfortable", "Comfortable"], ["spacious", "Spacious"]]))),
|
|
237
|
+
]),
|
|
238
|
+
section("Accent", true, [
|
|
239
|
+
row("Hue shift", range("hue", -180, 180, 5, function (v) { return v + "°"; })),
|
|
240
|
+
row("Chroma", range("chroma", 0, 2, 0.05, times)),
|
|
241
|
+
]),
|
|
242
|
+
section("Shape & space", false, [
|
|
243
|
+
row("Radius", range("radius", 0, 2.5, 0.05, times)),
|
|
244
|
+
row("Spacing", range("space", 0.6, 1.5, 0.05, times)),
|
|
245
|
+
row("Edges", select("border", defaultOr([["hairline", "Hairline"], ["regular", "Regular"], ["heavy", "Heavy"]]))),
|
|
246
|
+
row("Depth", select("depth", defaultOr([["flat", "Flat"], ["deep", "One step deeper"]]))),
|
|
247
|
+
]),
|
|
248
|
+
section("Type", false, [
|
|
249
|
+
row("Type scale", range("type", 0.8, 1.3, 0.025, pct)),
|
|
250
|
+
row("Heading weight", select("weight", defaultOr([["400", "Regular"], ["500", "Medium"], ["600", "Semibold"], ["700", "Bold"], ["800", "Extra bold"], ["900", "Black"]]))),
|
|
251
|
+
row("Heading tracking", select("tracking", defaultOr([["-0.04", "Tight"], ["0", "Normal"], ["0.06", "Wide"]]))),
|
|
252
|
+
row("Heading face", select("headingFont", defaultOr([["sans", "Sans"], ["serif", "Serif"], ["mono", "Mono"]]))),
|
|
253
|
+
row("Body face", select("bodyFont", defaultOr([["sans", "Sans"], ["serif", "Serif"], ["mono", "Mono"]]))),
|
|
254
|
+
]),
|
|
255
|
+
section("Motion", false, [
|
|
256
|
+
row("Speed", range("speed", 0.25, 2, 0.05, times)),
|
|
257
|
+
row("Easing", select("easing", defaultOr([["spring", "Spring"], ["bounce", "Bounce"], ["linear", "Linear"]]))),
|
|
258
|
+
row("Hover lift", select("lift", defaultOr([["0 -1px", "Subtle"], ["0 -2px", "Lift"], ["0 -4px", "Float"]]))),
|
|
259
|
+
row("Ambient loops", select("ambient", defaultOr([["paused", "Paused"]]))),
|
|
260
|
+
]),
|
|
261
|
+
section("Material", false, [
|
|
262
|
+
row("Page texture", select("page", textures)),
|
|
263
|
+
row("Surface texture", select("surface", textures)),
|
|
264
|
+
]),
|
|
265
|
+
h("div", { "data-ui": "cluster", "data-gap": "2" }, [copy, reset]),
|
|
266
|
+
status,
|
|
267
|
+
]);
|
|
268
|
+
|
|
269
|
+
var sync = function () { controls.forEach(function (c) { c.sync(); }); };
|
|
270
|
+
panels.push(sync);
|
|
271
|
+
sync();
|
|
272
|
+
el.appendChild(panel);
|
|
273
|
+
return function () {
|
|
274
|
+
panels.splice(panels.indexOf(sync), 1);
|
|
275
|
+
if (panel.parentNode) panel.parentNode.removeChild(panel);
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function install(Faqir) {
|
|
280
|
+
Faqir.tweak = {
|
|
281
|
+
apply: apply,
|
|
282
|
+
reset: function () { return apply(null); },
|
|
283
|
+
css: css,
|
|
284
|
+
restore: restore,
|
|
285
|
+
get state() { return state; },
|
|
286
|
+
};
|
|
287
|
+
Faqir.directive("tweak", function (el) {
|
|
288
|
+
if (!root || el.__faqirTweak) return;
|
|
289
|
+
el.__faqirTweak = true;
|
|
290
|
+
var unmount = mount(el);
|
|
291
|
+
return function () {
|
|
292
|
+
el.__faqirTweak = false;
|
|
293
|
+
unmount();
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (typeof module !== "undefined" && module.exports) module.exports = install;
|
|
299
|
+
|
|
300
|
+
var F =
|
|
301
|
+
(typeof globalThis !== "undefined" && globalThis.Faqir) ||
|
|
302
|
+
(typeof window !== "undefined" && window.Faqir);
|
|
303
|
+
if (F && typeof F.plugin === "function") F.plugin(install);
|
|
304
|
+
})();
|
|
@@ -80,8 +80,9 @@
|
|
|
80
80
|
* optional `Faqir.validate` member — plugin-installed surface, declared in
|
|
81
81
|
* `faqir-core.d.ts` as optional for exactly that reason. Zero dependencies,
|
|
82
82
|
* ≤ 3 KB gzip. The only attributes it owns are `data-state="invalid"` and
|
|
83
|
-
* `data-state="validating"` on the group
|
|
84
|
-
* on the control
|
|
83
|
+
* `data-state="validating"` on the group, `aria-invalid`/`aria-describedby`
|
|
84
|
+
* on the control and `novalidate` on the form (the plugin replaces the
|
|
85
|
+
* browser's own bubbles) — the frozen five-attribute protocol is untouched.
|
|
85
86
|
*/
|
|
86
87
|
(function () {
|
|
87
88
|
"use strict";
|
|
@@ -554,12 +555,19 @@
|
|
|
554
555
|
function install(Faqir) {
|
|
555
556
|
F = Faqir;
|
|
556
557
|
// Plugin-installed surface. Declared optional in faqir-core.d.ts because a
|
|
557
|
-
// page that never loads this file does not have it.
|
|
558
|
-
|
|
558
|
+
// page that never loads this file does not have it. Always this instance's:
|
|
559
|
+
// the directive below replaces any earlier one, so a second copy of this file
|
|
560
|
+
// (two script tags, a bundle beside the CDN) must not leave `register()`
|
|
561
|
+
// writing to a registry the live directive no longer reads.
|
|
562
|
+
Faqir.validate = api;
|
|
559
563
|
|
|
560
564
|
Faqir.directive("validate", function (form, dir, scope) {
|
|
561
565
|
var ctx = { scope: scope, submitted: false };
|
|
562
566
|
contexts.set(form, ctx);
|
|
567
|
+
// This plugin runs the constraints and shows the messages. Left on, the
|
|
568
|
+
// browser's own validation cancels an invalid submit before any submit
|
|
569
|
+
// event fires, so a real browser never reached the handler below.
|
|
570
|
+
form.noValidate = true;
|
|
563
571
|
|
|
564
572
|
// Submit: validate everything; block + focus the first offender when dirty.
|
|
565
573
|
form.addEventListener("submit", function (e) {
|