@faqir-ui/core 1.0.0 → 1.1.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 +45 -5
- package/cdn.json +38 -22
- package/dist/faqir-core.js +89 -52
- package/dist/faqir-core.min.js +3 -3
- package/dist/faqir-core.min.js.map +3 -3
- package/dist/faqir-core.mjs +61 -54
- package/dist/faqir.aurora.css +1209 -507
- package/dist/faqir.brutalist.css +1184 -489
- package/dist/faqir.candy.css +14152 -0
- package/dist/faqir.clinical.css +14152 -0
- package/dist/faqir.contrast.css +1198 -526
- package/dist/faqir.default.css +1261 -588
- package/dist/faqir.document-serif.css +1211 -491
- package/dist/faqir.document.css +1193 -490
- package/dist/faqir.editorial-document.css +14116 -0
- package/dist/faqir.editorial.css +14152 -0
- package/dist/faqir.fintech.css +14152 -0
- package/dist/faqir.glass.css +1214 -517
- package/dist/faqir.ink-document.css +14116 -0
- package/dist/faqir.ink.css +14127 -0
- package/dist/faqir.luxe.css +14211 -0
- package/dist/faqir.midnight.css +1229 -507
- package/dist/faqir.neo.css +14153 -0
- package/dist/faqir.neumorph.css +14151 -0
- package/dist/faqir.nordic.css +14151 -0
- package/dist/faqir.organic.css +14152 -0
- package/dist/faqir.paper.css +1200 -508
- package/dist/faqir.slate.css +1296 -564
- package/dist/faqir.soft.css +1180 -494
- package/dist/faqir.sunset.css +14153 -0
- package/dist/faqir.swiss-document.css +14116 -0
- package/dist/faqir.swiss.css +14153 -0
- package/dist/faqir.terminal.css +1187 -491
- package/dist/plugins/faqir-collapse.js +1 -1
- package/dist/plugins/faqir-intersect.js +2 -0
- package/dist/plugins/faqir-mask.js +27 -17
- package/dist/plugins/faqir-rules.js +63 -0
- package/dist/plugins/faqir-validate.js +471 -58
- package/dist/sri.json +36 -20
- package/faqir-core.d.ts +111 -5
- package/package.json +1 -1
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
Faqir.directive("collapse", function (el, dir, scope) {
|
|
55
55
|
var open = null; // unknown until the first effect run
|
|
56
56
|
|
|
57
|
-
Faqir.effect(function () {
|
|
57
|
+
return Faqir.effect(function () {
|
|
58
58
|
var next = !!Faqir.evaluate(dir.expression, scope, el);
|
|
59
59
|
if (next === open) return;
|
|
60
60
|
var firstRun = open === null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @ui:plugin faqir-intersect
|
|
2
2
|
// @ui:provides l-intersect
|
|
3
|
+
// @ui:modifier l-intersect .leave | Runs when the element leaves the viewport instead of when it enters.
|
|
4
|
+
// @ui:modifier l-intersect .once | Disconnects the observer after its first matching observation.
|
|
3
5
|
/**
|
|
4
6
|
* faqir-intersect — declarative IntersectionObserver hooks. [0.6-05 · §A5]
|
|
5
7
|
*
|
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
|
|
20
20
|
var TOKENS = { "9": /[0-9]/, a: /[A-Za-z]/, "*": /[^]/ };
|
|
21
21
|
|
|
22
|
+
// `in` is safe: callers pass one character, and no inherited Object
|
|
23
|
+
// property has a one-character name.
|
|
22
24
|
function isToken(ch) {
|
|
23
|
-
return
|
|
25
|
+
return ch in TOKENS;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
function tokenTypes(mask) {
|
|
@@ -128,14 +130,26 @@
|
|
|
128
130
|
var caretRaw = start;
|
|
129
131
|
|
|
130
132
|
if (inputType.indexOf("delete") === 0) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
// Every delete* is prevented by the directive, so every one is handled
|
|
134
|
+
// here: a collapsed caret deletes by character, by mask group (a "word":
|
|
135
|
+
// tokens with no literal between them), or by line (all before/after the
|
|
136
|
+
// caret, or everything for an undirected line delete). Undirected
|
|
137
|
+
// content deletes (deleteContent, a collapsed cut) are no-ops.
|
|
138
|
+
var back = /Backward$/.test(inputType);
|
|
139
|
+
var fwd = /Forward$/.test(inputType);
|
|
140
|
+
var line = /Line/.test(inputType);
|
|
141
|
+
var word = line || /Word/.test(inputType);
|
|
142
|
+
var from = start;
|
|
143
|
+
var to = end;
|
|
144
|
+
// Whether a word/line step may continue past slot boundary i: a literal
|
|
145
|
+
// between token slots i-1 and i ends a word; nothing ends a line.
|
|
146
|
+
var more = function (i) { return line || prior.starts[i] === prior.ends[i - 1]; };
|
|
147
|
+
if (start === end) {
|
|
148
|
+
if (back && from > 0) do from--; while (word && from > 0 && more(from));
|
|
149
|
+
if (fwd && to < raw.length) do to++; while (word && to < raw.length && more(to));
|
|
138
150
|
}
|
|
151
|
+
raw = raw.slice(0, from) + raw.slice(to);
|
|
152
|
+
caretRaw = from;
|
|
139
153
|
} else {
|
|
140
154
|
var inserted = readRaw(mask, edit.data == null ? "" : edit.data, start);
|
|
141
155
|
raw = (raw.slice(0, start) + inserted + raw.slice(end)).slice(0, types.length);
|
|
@@ -163,7 +177,7 @@
|
|
|
163
177
|
}
|
|
164
178
|
if (el._faqirMask) {
|
|
165
179
|
if (el._faqirMask._scope === scope) return;
|
|
166
|
-
|
|
180
|
+
el._faqirMask.destroy();
|
|
167
181
|
}
|
|
168
182
|
|
|
169
183
|
var pattern = String(dir.expression || "").trim();
|
|
@@ -178,18 +192,14 @@
|
|
|
178
192
|
var destroyed = false;
|
|
179
193
|
var renderId = 0;
|
|
180
194
|
var pendingCaret = null;
|
|
181
|
-
var initial =
|
|
182
|
-
inputType: "insertFromPaste",
|
|
183
|
-
data: el.value,
|
|
184
|
-
selectionStart: 0,
|
|
185
|
-
selectionEnd: 0,
|
|
186
|
-
});
|
|
195
|
+
var initial = formatResult(el.value);
|
|
187
196
|
var raw = initial.raw;
|
|
188
197
|
|
|
189
198
|
function paint(result, caret) {
|
|
190
199
|
raw = result.raw;
|
|
191
200
|
if (el.value !== result.value) el.value = result.value;
|
|
192
|
-
if (caret !== false
|
|
201
|
+
if (caret !== false) {
|
|
202
|
+
// try: some input types (email, number) throw on selection APIs.
|
|
193
203
|
try {
|
|
194
204
|
el.setSelectionRange(result.caret, result.caret);
|
|
195
205
|
} catch (e) {}
|
|
@@ -293,7 +303,7 @@
|
|
|
293
303
|
el.removeEventListener("beforeinput", onBeforeInput, true);
|
|
294
304
|
el.removeEventListener("paste", onPaste, true);
|
|
295
305
|
el.removeEventListener("input", onInput, true);
|
|
296
|
-
if (
|
|
306
|
+
if (stopModel) stopModel();
|
|
297
307
|
if (el._faqirMask === api) delete el._faqirMask;
|
|
298
308
|
}
|
|
299
309
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @ui:plugin faqir-rules
|
|
2
|
+
// @ui:provides l-rules, $rules
|
|
3
|
+
// GENERATED by scripts/build-rules-plugin.mjs from packages/rules/src/plugin.js
|
|
4
|
+
// and the @faqir-ui/rules evaluator it imports. Do not edit by hand; run
|
|
5
|
+
// `bun run build:rules-plugin`.
|
|
6
|
+
/**
|
|
7
|
+
* faqir-rules — a form's conditional logic, from one JSON definition. [1.1B-04 · §8.3]
|
|
8
|
+
* The browser half of `@faqir-ui/rules`: the same evaluator a server runs.
|
|
9
|
+
*
|
|
10
|
+
* <script type="application/json" id="signup-rules">
|
|
11
|
+
* { "version": "1",
|
|
12
|
+
* "fields": { "plan": { "type": "string" }, "seats": { "type": "integer" } },
|
|
13
|
+
* "rules": [{ "id": "seats-for-teams", "show": "seats",
|
|
14
|
+
* "when": { "==": [{ "var": "plan" }, "team"] } }] }
|
|
15
|
+
* </script>
|
|
16
|
+
* <form l-validate l-rules="#signup-rules"> … </form>
|
|
17
|
+
*
|
|
18
|
+
* On init and on every `input`/`change`/`reset`, the form's controls are read
|
|
19
|
+
* (a control someone else disabled, like a wizard's other steps, still
|
|
20
|
+
* answers), coerced through the definition and handed to `evaluate`, and the
|
|
21
|
+
* answer is applied to the DOM: a hidden field's `[data-ui="field-group"]`
|
|
22
|
+
* takes `hidden` and its controls take `disabled` — held there even if
|
|
23
|
+
* something else enables them — so it neither validates nor submits; `require`
|
|
24
|
+
* toggles `required` + `aria-required`; `compute` writes its value into the
|
|
25
|
+
* scope and into any control of that name; and `jump` lands in `$rules.next`
|
|
26
|
+
* for a wizard to read. Cross-field and remote `validate` rules are registered
|
|
27
|
+
* through `Faqir.validate.register`, so they run at faqir-validate's moments,
|
|
28
|
+
* with faqir-validate's messages and its `validating` state — this plugin owns
|
|
29
|
+
* no message and paints no error of its own.
|
|
30
|
+
*
|
|
31
|
+
* ── The definition ──────────────────────────────────────────────────────────
|
|
32
|
+
* `l-rules="#id"` (any selector — `#`, `.`, `[`) reads a
|
|
33
|
+
* `<script type="application/json">`; anything else is an expression
|
|
34
|
+
* evaluated in the form's scope, so `l-rules="rulesDef"` takes the object (or
|
|
35
|
+
* JSON string) a page already has. The definition is compiled once, at bind.
|
|
36
|
+
*
|
|
37
|
+
* ── Remote rules ────────────────────────────────────────────────────────────
|
|
38
|
+
* `{ "id": …, "validate": "remote", "path": "email", "remote": "/api/check" }`
|
|
39
|
+
* becomes an async validator that POSTs `{ path, value, data }` and expects
|
|
40
|
+
* `{ ok: boolean, message?: string }`. `ok: false` with no non-empty string
|
|
41
|
+
* `message` wears the rule's own sentence, resolved exactly as a server's
|
|
42
|
+
* `validateAsync` resolves it. Anything else — a non-2xx, a body that is not
|
|
43
|
+
* JSON, an `ok` that is not a boolean, a network failure — is a failed check
|
|
44
|
+
* wearing faqir-validate's built-in sentence, never a silent pass.
|
|
45
|
+
*
|
|
46
|
+
* ── Nothing fails quietly ───────────────────────────────────────────────────
|
|
47
|
+
* An `l-rules` that resolves to nothing, a definition the package refuses (an
|
|
48
|
+
* unknown operator, a compute cycle), a rule naming a field the form has no
|
|
49
|
+
* control for, a form with no `l-validate`, and a missing faqir-validate are
|
|
50
|
+
* each reported: in full through the dev engine's diagnostics, and tersely on
|
|
51
|
+
* `console.warn` in production, where that seam says nothing.
|
|
52
|
+
*
|
|
53
|
+
* Self-registers via `Faqir.plugin` when a global `Faqir` is present (load it
|
|
54
|
+
* after faqir-core and after faqir-validate) and exports `install` for bundlers
|
|
55
|
+
* as `@faqir-ui/rules/plugin`. GENERATED into `registry/core/plugins/` by
|
|
56
|
+
* `bun run build:rules-plugin`: the evaluator is `@faqir-ui/rules` itself,
|
|
57
|
+
* bundled in, so the verdict in the page is the verdict on the server by
|
|
58
|
+
* construction rather than by agreement. Zero dependencies. The only attributes
|
|
59
|
+
* it owns are `hidden` on a field-group, `disabled` / `required` /
|
|
60
|
+
* `aria-required` on a control it was told to own, and a computed control's
|
|
61
|
+
* `value` — the frozen five-attribute protocol is untouched.
|
|
62
|
+
*/
|
|
63
|
+
(()=>{var{defineProperty:$1,getOwnPropertyNames:W8,getOwnPropertyDescriptor:V8}=Object,X8=Object.prototype.hasOwnProperty;var _1=new WeakMap,K8=(Z)=>{var Q=_1.get(Z),B;if(Q)return Q;if(Q=$1({},"__esModule",{value:!0}),Z&&typeof Z==="object"||typeof Z==="function")W8(Z).map((W)=>!X8.call(Q,W)&&$1(Q,W,{get:()=>Z[W],enumerable:!(B=V8(Z,W))||B.enumerable}));return _1.set(Z,Q),Q};var U8=(Z,Q)=>{for(var B in Q)$1(Z,B,{get:Q[B],enumerable:!0,configurable:!0,set:(W)=>Q[B]=()=>W})};var XZ={};U8(XZ,{install:()=>Q8});class H extends Error{constructor(Z,Q){super(`@faqir-ui/rules: ${Z}`);this.name="DefinitionError",this.path=Q}}var z8=/^(\d{4})-(\d{2})-(\d{2})$/,Y8=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/i,H8=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,G8=/^[A-Za-z][A-Za-z0-9+.-]*:[^\s\x00-\x1f]+$/,C8=/^[^\s@,;<>()[\]\\"]+@[^\s@.,;<>()[\]\\"]+(?:\.[^\s@.,;<>()[\]\\"]+)*\.[A-Za-z]{2,}$/,F8=/^\+?[0-9 ().-]{6,24}$/,M8=/^[A-Za-z0-9][A-Za-z0-9 -]{0,10}[A-Za-z0-9]$/,I8=/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/,A8=[31,28,31,30,31,30,31,31,30,31,30,31];function O8(Z){return Z%4===0&&Z%100!==0||Z%400===0}function D1(Z){let Q=z8.exec(Z);if(!Q)return!1;let B=Number(Q[1]),W=Number(Q[2]),J=Number(Q[3]);if(W<1||W>12||J<1)return!1;let $=W===2&&O8(B)?29:A8[W-1];return J<=$}function R1(Z){let Q=Y8.exec(Z);if(!Q)return!1;let B=Number(Q[1]),W=Number(Q[2]),J=Q[3]===void 0?0:Number(Q[3]);return B<=23&&W<=59&&J<=60}function N8(Z){let Q=/^(.+?)[Tt ](.+)$/.exec(Z);if(!Q)return!1;return D1(Q[1])&&R1(Q[2])}function q8(Z){if(!F8.test(Z))return!1;let Q=Z.replace(/\D/g,"");return Q.length>=7&&Q.length<=15}function L8(Z){let Q=Z.replace(/[\s-]/g,"").toUpperCase();if(!I8.test(Q))return!1;let B=Q.slice(4)+Q.slice(0,4),W="";for(let $ of B)W+=$>="A"&&$<="Z"?String($.charCodeAt(0)-55):$;let J=0;for(let $=0;$<W.length;$+=7)J=Number(String(J)+W.slice($,$+7))%97;return J===1}function T8(Z){if(Z.length<2||Z.length>12)return!1;if(!M8.test(Z))return!1;return!/[ -]{2}/.test(Z)}var m=new Map([["email",(Z)=>C8.test(Z)&&Z.length<=254],["uri",(Z)=>G8.test(Z)],["date",D1],["time",R1],["date-time",N8],["phone",q8],["iban",L8],["uuid",(Z)=>H8.test(Z)],["postal-code",T8]]),zZ=Object.freeze([...m.keys()]);function b1(Z){return m.has(Z)}function k1(){return[...m.keys()].sort()}function E1(Z,Q){let B=m.get(Z);if(!B)return!0;return B(Q)===!0}var _=1000,h=1e4,J1=1000,B1=64,W1=9999;var j8=Object.freeze(["required","type","enum","const","pattern","format","minLength","maxLength","minimum","exclusiveMinimum","maximum","exclusiveMaximum","multipleOf","minItems","maxItems","uniqueItems"]),y1=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."}),D=Object.freeze({rule:"Please check this value.","remote-error":"This value could not be checked right now."}),V1="en";function c(Z,Q){if(!Q||typeof Z!=="string"||Z.indexOf("{")===-1)return Z;return Z.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(B,W)=>{if(!Object.prototype.hasOwnProperty.call(Q,W))return B;let J=Q[W];if(J===void 0||J===null)return B;if(Array.isArray(J))return J.map(($)=>String($)).join(", ");return String(J)})}function R(Z){let{messages:Q,locale:B,path:W,rule:J,params:$,fallback:V}=Z,K=Z.defaultLocale||"en",U=[`${W}.${J}`,J];for(let X of[B,K]){if(!X)continue;let Y=Q&&Object.prototype.hasOwnProperty.call(Q,X)?Q[X]:void 0;if(!Y)continue;for(let z of U){let G=Object.prototype.hasOwnProperty.call(Y,z)?Y[z]:void 0;if(typeof G==="string")return c(G,$)}}if(typeof V==="string")return c(V,$);for(let X of[y1,D])if(Object.prototype.hasOwnProperty.call(X,J)){let Y=X[J];if(typeof Y==="string")return c(Y,$)}return J}function x(Z){return{min:1,unbounded:!1,wide:!1,flex:!1,zeroWidth:!1,empty:!1,first:Z,innerUnbounded:!1,innerSole:!1,ambiguous:!1}}function P8(Z){return Z.flex||Z.innerSole}function S8(Z,Q){let B=Z[Q],W=null;if(B==="*")W={min:0,max:1/0,end:Q+1};else if(B==="+")W={min:1,max:1/0,end:Q+1};else if(B==="?")W={min:0,max:1,end:Q+1};else if(B==="{"){let J=/^\{(\d+)(,(\d*))?\}/.exec(Z.slice(Q));if(!J)return null;let $=Number(J[1]),V=J[2]===void 0?$:J[3]===""?1/0:Number(J[3]);W={min:$,max:V,end:Q+J[0].length}}if(W&&Z[W.end]==="?")W.end+=1;return W}function _8(Z,Q){if(Z[Q+2]==="{"&&"upP".includes(Z[Q+1])){let B=Z.indexOf("}",Q+3);if(B!==-1)return B+1}return Q+2}function D8(Z,Q){let B;try{B=Z.map((W)=>new RegExp(`^(?:${W})$`))}catch{return!0}for(let W of Q)if(B.filter((J)=>J.test(W)).length>1)return!0;return!1}function R8(Z){let Q=["(?!)"];for(let B of Z)if(Q.push(B.first),!B.empty)return{first:Q.join("|"),empty:!1};return{first:Q.join("|"),empty:!0}}function u(Z){let Q=[{alternatives:[[]],zeroWidth:!1}],B=!1,W=!1,J=new Set(`${Z} \u2028\uFEFF`);for(let U=0;U<128;U+=1)J.add(String.fromCharCode(U));let $=()=>{let U=Q[Q.length-1];return U.alternatives[U.alternatives.length-1]},V=()=>Object.assign(x("(?!)"),{zeroWidth:!0,empty:!0}),K=0;while(K<Z.length){let U=Z[K];if(U==="\\"){let X=_8(Z,K);$().push("bB".includes(Z[K+1])?V():x(Z.slice(K,X))),K=X}else if(U==="["){let X=K+1;while(X<Z.length&&Z[X]!=="]")X=Z[X]==="\\"?X+2:X+1;$().push(x(Z.slice(K,X+1))),K=X+1}else if(U==="("){let X=K+1,Y=!1;if(Z[X]==="?")if(Z[X+1]==="="||Z[X+1]==="!")Y=!0,X+=2;else if(Z[X+1]==="<"&&(Z[X+2]==="="||Z[X+2]==="!"))Y=!0,X+=3;else if(Z[X+1]==="<"){let z=Z.indexOf(">",X+2);X=z===-1?X+2:z+1}else X+=2;Q.push({alternatives:[[]],zeroWidth:Y}),K=X}else if(U===")"&&Q.length>1){let X=Q.pop(),Y=X.alternatives.map(R8),z=X.zeroWidth?V():x(Y.map((G)=>G.first).join("|"));z.empty||=Y.some((G)=>G.empty),z.ambiguous=Y.length>1&&D8(Y.map((G)=>G.first),J);for(let G of X.alternatives){if(G.some((C)=>C.unbounded||C.innerUnbounded))z.innerUnbounded=!0;if(G.some((C)=>C.ambiguous))z.ambiguous=!0;let A=G.findIndex(P8);if(A!==-1&&G.every((C,M)=>M===A||C.min===0||C.zeroWidth))z.innerSole=!0}$().push(z),K+=1}else if(U==="|")Q[Q.length-1].alternatives.push([]),K+=1;else if(U==="^"||U==="$")$().push(V()),K+=1;else{let X=S8(Z,K),Y=$(),z=Y[Y.length-1];if(X&&z){if(z.min=z.min*X.min,z.unbounded=X.max===1/0,z.wide=X.max>1,z.flex=z.wide&&X.max>X.min,X.min===0)z.empty=!0;if(!z.zeroWidth&&z.innerUnbounded&&z.wide)B=!0;if(!z.zeroWidth&&X.max>10&&(z.innerSole||z.ambiguous))W=!0;K=X.end}else $().push(x(U)),K+=1}}if(W)return"catastrophic";return B?"nested":null}function n(Z){return`${Z} repeats a group that can match the same text more than one way, like (a+)+ or (a|a)+, and can backtrack catastrophically.`}var l="1";class o{constructor(Z,Q,B,W,J){this.version=l,this.fields=Z,this.required=Q,this.messages=B,this.defaultLocale=W,this.rules=J}}var b8=["string","number","integer","boolean"],x1=new Set([...b8,"object","array"]),v1=new Set(["version","fields","required","messages","defaultLocale","rules"]),y=["type","title","description","required","enum","const"],f1={string:new Set([...y,"pattern","format","minLength","maxLength"]),number:new Set([...y,"minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"]),integer:new Set([...y,"minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"]),boolean:new Set(y),object:new Set([...y,"properties"]),array:new Set([...y,"items","minItems","maxItems","uniqueItems"])},k8=Object.freeze(Object.fromEntries(Object.entries(f1).map(([Z,Q])=>[Z,Object.freeze([...Q].sort())]))),E8=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"],y8=0.000000001;function I(Z){return typeof Z==="object"&&Z!==null&&!Array.isArray(Z)}function O(Z,Q){return Object.prototype.hasOwnProperty.call(Z,Q)}var g1=new Set(["__proto__","constructor","prototype"]);function z1(Z){return T(Z).some((Q)=>g1.has(Q))}function j(Z,Q){if(z1(Z))throw new H(`the path "${Z}" at ${Q} names __proto__, constructor or prototype.`,Q)}function q(Z){return Z.replace(/\[(\d+)\]/g,".$1")}function T(Z){return q(Z).split(".").filter((Q)=>Q.length>0)}function w(Z,Q){let B=Z,W=Q;while(W.length>0){if(B===void 0||B===null)return;if(I(B)&&O(B,W))return B[W];let J=T(W);if(J.length===0)return;let $=J[0];if(Array.isArray(B)){let V=Number($);if(!Number.isInteger(V))return;B=B[V]}else if(I(B))B=O(B,$)?B[$]:void 0;else return;W=J.slice(1).join(".")}return B}function x8(Z){for(let Q of T(Z)){if(g1.has(Q))return!1;if(/^\d+$/.test(Q)&&Number(Q)>W1)return!1}return!0}function w1(Z,Q,B){let W=T(Q),J=Z;for(let $=0;$<W.length-1;$++){let V=W[$],K=/^\d+$/.test(W[$+1]),U=O(J,V)?J[V]:void 0,X=I(U)||Array.isArray(U)?U:K?[]:{};J[V]=X,J=X}J[W[W.length-1]]=B}function v8(Z,Q){let B=T(Q),W=Z;for(let $=0;$<B.length-1;$++)if(W=O(W,B[$])?W[B[$]]:void 0,!I(W)&&!Array.isArray(W))return;let J=B[B.length-1];if(Array.isArray(W))W.splice(Number(J),1);else if(I(W))delete W[J]}function v(Z,Q,B){let W=Z[Q];if(W===void 0)return;if(typeof W!=="number"||!Number.isFinite(W))throw new H(`"${Q}" at ${B} must be a finite number.`,B)}function X1(Z,Q){if(!I(Z))throw new H(`the field schema at ${Q} must be an object.`,Q);let B=Z.type;if(typeof B!=="string"||!x1.has(B))throw new H(`the field at ${Q} needs a "type" of ${[...x1].join(", ")}${B===void 0?"":` (got ${JSON.stringify(B)})`}.`,Q);let W=f1[B];for(let $ of Object.keys(Z))if(!W.has($))throw new H(`unsupported keyword "${$}" at ${Q} (a "${B}" field accepts ${[...W].sort().join(", ")}).`,Q);let J={type:B,schema:Z};if(Z.required!==void 0)if(Z.required===!0)J.selfRequired=!0;else if(B==="object"&&Array.isArray(Z.required)){for(let $ of Z.required)if(typeof $!=="string")throw new H(`"required" at ${Q} must list property names.`,Q);J.requiredChildren=new Set(Z.required)}else throw new H(B==="object"?`"required" at ${Q} must be true (the object itself is required) or an array of property names.`:`"required" at ${Q} must be true; only an object field may list property names.`,Q);if(Z.enum!==void 0&&(!Array.isArray(Z.enum)||Z.enum.length===0))throw new H(`"enum" at ${Q} must be a non-empty array.`,Q);if(B==="string"){if(Z.pattern!==void 0){if(typeof Z.pattern!=="string")throw new H(`"pattern" at ${Q} must be a string.`,Q);if(Z.pattern.length>_)throw new H(`"pattern" at ${Q} is ${Z.pattern.length} characters; the limit is ${_}.`,Q);try{J.regex=new RegExp(Z.pattern)}catch($){throw new H(`"pattern" at ${Q} is not a valid regular expression: ${$ instanceof Error?$.message:String($)}`,Q)}if(u(Z.pattern)==="catastrophic")throw new H(n(`"pattern" at ${Q}`),Q)}if(Z.format!==void 0){if(typeof Z.format!=="string"||!b1(Z.format))throw new H(`unknown format ${JSON.stringify(Z.format)} at ${Q} (known: ${k1().join(", ")} — add one with registerFormat).`,Q)}v(Z,"minLength",Q),v(Z,"maxLength",Q)}if(B==="number"||B==="integer"){for(let $ of E8)v(Z,$,Q);if(typeof Z.multipleOf==="number"&&Z.multipleOf<=0)throw new H(`"multipleOf" at ${Q} must be greater than zero.`,Q)}if(B==="object"){let $=new Map;if(Z.properties!==void 0){if(!I(Z.properties))throw new H(`"properties" at ${Q} must be an object.`,Q);for(let[V,K]of Object.entries(Z.properties))j(V,`${Q}.properties`),$.set(V,X1(K,`${Q}.${V}`))}for(let V of J.requiredChildren??[])if(!$.has(V))throw new H(`"required" at ${Q} names "${V}", which is not one of its properties.`,Q);J.properties=$}if(B==="array"){if(v(Z,"minItems",Q),v(Z,"maxItems",Q),Z.uniqueItems!==void 0&&typeof Z.uniqueItems!=="boolean")throw new H(`"uniqueItems" at ${Q} must be a boolean.`,Q);if(Z.items!==void 0){let $=X1(Z.items,`${Q}[]`);if($.selfRequired)throw new H(`"required" at ${Q}[] has no meaning: array items are checked by minItems, not by presence.`,`${Q}[]`);J.items=$}}return J}function Y1(Z){if(Z instanceof o)return Z;if(!I(Z))throw new H("a definition must be an object.","");for(let W of Object.keys(Z))if(!v1.has(W))throw new H(`unsupported definition key "${W}" (accepted: ${[...v1].sort().join(", ")}).`,W);if(Z.version!==void 0&&Z.version!==l)throw new H(`unsupported definition version ${JSON.stringify(Z.version)}; this package implements "${l}".`,"version");if(Z.fields!==void 0&&!I(Z.fields))throw new H('"fields" must be a map of paths to field schemas.',"fields");if(Z.messages!==void 0&&!I(Z.messages))throw new H('"messages" must be a map of locales to message tables.',"messages");if(Z.defaultLocale!==void 0&&typeof Z.defaultLocale!=="string")throw new H('"defaultLocale" must be a string.',"defaultLocale");if(Z.rules!==void 0&&!Array.isArray(Z.rules))throw new H('"rules" must be an array.',"rules");let Q=new Map;for(let[W,J]of Object.entries(Z.fields??{})){if(T(W).length===0)throw new H('"fields" has an empty path key.',"fields");j(W,"fields"),Q.set(q(W),X1(J,W))}let B=new Set;if(Z.required!==void 0){if(!Array.isArray(Z.required))throw new H('"required" must be an array of field paths.',"required");for(let W of Z.required){if(typeof W!=="string")throw new H('"required" must list field paths as strings.',"required");let J=q(W);if(!Q.has(J))throw new H(`"required" names "${W}", which is not a key of "fields".`,"required");B.add(J)}}return new o(Q,B,Z.messages??{},typeof Z.defaultLocale==="string"?Z.defaultLocale:V1,Array.isArray(Z.rules)?Z.rules:[])}function H1(Z){if(Z===void 0||Z===null)return!0;if(typeof Z==="string"&&Z.length===0)return!0;if(Array.isArray(Z)&&Z.length===0)return!0;return!1}function w8(Z,Q){switch(Q){case"string":return typeof Z==="string";case"number":return typeof Z==="number"&&Number.isFinite(Z);case"integer":return typeof Z==="number"&&Number.isInteger(Z);case"boolean":return typeof Z==="boolean";case"object":return I(Z);case"array":return Array.isArray(Z);default:return!1}}function b(Z){if(Array.isArray(Z))return`[${Z.map(b).join(",")}]`;if(I(Z))return`{${Object.keys(Z).sort().map((Q)=>`${JSON.stringify(Q)}:${b(Z[Q])}`).join(",")}}`;return JSON.stringify(Z)??"undefined"}function K1(Z,Q,B,W,J){let $=Z.schema,V=(U,X)=>{J.findings.push({path:B,rule:U,message:R({messages:J.messages,locale:J.locale,defaultLocale:J.defaultLocale,path:B,rule:U,params:{path:B,title:$.title,...X}}),params:X})};if(H1(Q)){if(W)V("required",{});return}let K=Z.type;if(!w8(Q,K)){V("type",{type:K});return}if($.enum!==void 0){let U=$.enum;if(!U.some((X)=>b(X)===b(Q)))V("enum",{allowed:U})}if($.const!==void 0&&b($.const)!==b(Q))V("const",{const:$.const});if(K==="string"){let U=Q;if(Z.regex&&(U.length>h||!Z.regex.test(U)))V("pattern",{pattern:$.pattern});if(typeof $.format==="string"&&!E1($.format,U))V("format",{format:$.format});let X=[...U].length;if(typeof $.minLength==="number"&&X<$.minLength)V("minLength",{limit:$.minLength,actual:X});if(typeof $.maxLength==="number"&&X>$.maxLength)V("maxLength",{limit:$.maxLength,actual:X})}if(K==="number"||K==="integer"){let U=Q;if(typeof $.minimum==="number"&&U<$.minimum)V("minimum",{limit:$.minimum});if(typeof $.exclusiveMinimum==="number"&&U<=$.exclusiveMinimum)V("exclusiveMinimum",{limit:$.exclusiveMinimum});if(typeof $.maximum==="number"&&U>$.maximum)V("maximum",{limit:$.maximum});if(typeof $.exclusiveMaximum==="number"&&U>=$.exclusiveMaximum)V("exclusiveMaximum",{limit:$.exclusiveMaximum});if(typeof $.multipleOf==="number"){let X=U/$.multipleOf;if(Math.abs(X-Math.round(X))>y8)V("multipleOf",{multipleOf:$.multipleOf})}}if(K==="array"){let U=Q;if(typeof $.minItems==="number"&&U.length<$.minItems)V("minItems",{limit:$.minItems,actual:U.length});if(typeof $.maxItems==="number"&&U.length>$.maxItems)V("maxItems",{limit:$.maxItems,actual:U.length});if($.uniqueItems===!0){let X=new Set;for(let Y=0;Y<U.length;Y++){let z=b(U[Y]);if(X.has(z)){V("uniqueItems",{index:Y});break}X.add(z)}}if(Z.items)for(let X=0;X<U.length;X++)K1(Z.items,U[X],`${B}.${X}`,!1,J)}if(K==="object"&&Z.properties){let U=Z.requiredChildren;for(let[X,Y]of Z.properties){let z=Y.selfRequired===!0||U!==void 0&&U.has(X);K1(Y,w(Q,X),`${B}.${X}`,z,J)}}}function p1(Z,Q,B){let W={findings:[],messages:Z.messages,locale:B?.locale,defaultLocale:Z.defaultLocale},J=B?.required;for(let[$,V]of Z.fields){let K=V.selfRequired===!0||Z.required.has($)||J!==void 0&&J.has($);K1(V,w(Q,$),$,K,W)}return W.findings}var f8=new Set(["true","on","yes","1"]),g8=new Set(["false","off","no","0"]),p8=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function d8(Z,Q){if(typeof Z!=="string")return Z;let B=Z.trim();if(B.length===0)return;if(Q==="number"||Q==="integer")return p8.test(B)?Number(B):Z;if(Q==="boolean"){let W=B.toLowerCase();if(f8.has(W))return!0;if(g8.has(W))return!1;return Z}return Z}function U1(Z,Q){if(Z.type==="array"){if(Q===void 0||Q===null)return Q;let B=Array.isArray(Q)?Q:Q===""?[]:[Q];return(Z.items?B.map((J)=>U1(Z.items,J)):B.slice()).filter((J)=>J!==void 0)}if(Z.type==="object"){if(!I(Q))return Q;let B={...Q};for(let[W,J]of Z.properties??[]){if(!Object.prototype.hasOwnProperty.call(B,W))continue;let $=U1(J,B[W]);if($===void 0)delete B[W];else B[W]=$}return B}return d8(Q,Z.type)}function G1(Z){let Q={},B=(J,$)=>{if(typeof $!=="string"||z1($))return;if(!O(Q,$))Q[$]=J;else if(Array.isArray(Q[$]))Q[$].push(J);else Q[$]=[Q[$],J]},W=Z;if(W&&typeof W[Symbol.iterator]==="function"){for(let J of W)if(Array.isArray(J))B(J[1],J[0])}else if(W&&typeof W.forEach==="function")W.forEach(B);return Q}function C1(Z,Q){let B=Y1(Z);if(!I(Q))return{};let W=new Set;for(let $ of B.fields.keys())W.add(T($)[0]);let J={};for(let[$,V]of Object.entries(Q)){if(z1($))continue;let K=T($);if(K.length>1&&W.has(K[0])&&x8($))w1(J,$,V);else J[$]=V}for(let[$,V]of B.fields){let K=w(J,$);if(K===void 0)continue;let U=U1(V,K);if(U===void 0)v8(J,$);else w1(J,$,U)}return J}var h1=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}),c1=Object.freeze(Object.keys(h1)),m8=new Set(c1),u1=Object.freeze(["==","!=","<","<=",">",">="]),h8=new Set(u1),s=new Map,c8=200;function i(Z){return typeof Z==="object"&&Z!==null&&!Array.isArray(Z)}function N(Z){if(Array.isArray(Z))return Z.length>0;return Boolean(Z)}function k(Z){return Array.isArray(Z)?Z:[Z]}function f(Z,Q){let B=Q??"",W=B?B:"this expression",J=0,$=(V,K)=>{if(J+=1,J>J1)throw new H(`the logic at ${W} has more than ${J1} nodes.`,B);if(K>B1)throw new H(`the logic at ${W} nests deeper than ${B1} levels.`,B);if(Array.isArray(V)){for(let G of V)$(G,K+1);return}if(!i(V))return;let U=Object.keys(V);if(U.length!==1)throw new H(`a logic expression at ${W} must be a single-operator object; this one has ${U.length===0?"none":`${U.length} (${U.join(", ")})`}.`,B);let X=U[0];if(!m8.has(X))throw new H(`unsupported operator "${X}" at ${W} (implemented: ${c1.join(", ")}).`,B);let Y=k(V[X]),z=h1[X];if(Y.length<z)throw new H(`"${X}" at ${W} needs at least ${z} argument${z===1?"":"s"}, got ${Y.length}.`,B);if(X==="date"&&!h8.has(String(Y[1])))throw new H(`"date" at ${W} needs one of ${u1.join(", ")} as its middle argument (got ${JSON.stringify(Y[1])}).`,B);if(X==="regex")n1(Y[0],B);for(let G of Y)$(G,K+1)};$(Z,0)}function n1(Z,Q){let B=Q?Q:"this expression";if(typeof Z!=="string")throw new H(`"regex" at ${B} needs a literal pattern string as its first argument.`,Q);let W=s.get(Z);if(W)return W;if(Z.length>_)throw new H(`the "regex" pattern at ${B} is ${Z.length} characters; the limit is ${_}.`,Q);let J;try{J=new RegExp(Z)}catch($){throw new H(`the "regex" pattern at ${B} is not a valid regular expression: ${$ instanceof Error?$.message:String($)}`,Q)}if(u(Z)==="catastrophic")throw new H(n(`the "regex" pattern at ${B}`),Q);if(s.size>=c8)s.clear();return s.set(Z,J),J}function F1(Z,Q,B){if(Q===void 0||Q===null||Q===""||Array.isArray(Q)&&Q.length===0)return Z===void 0?null:Z;let W=Z;for(let J of String(Q).split(".")){if(W===void 0||W===null)return B??null;if(Array.isArray(W)){let $=Number(J);W=Number.isInteger($)?W[$]:void 0}else if(i(W))W=Object.prototype.hasOwnProperty.call(W,J)?W[J]:void 0;else return B??null}if(W===void 0)return B??null;return W}function d1(Z){return Z===void 0||Z===null||Z===""}function L(Z){return typeof Z==="number"?Z:parseFloat(String(Z))}function m1(Z){if(typeof Z==="number")return Number.isFinite(Z)?Z:null;if(typeof Z!=="string")return null;let Q=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:?\d{2})?)?$/.exec(Z.trim());if(!Q)return null;let[,B,W,J,$,V,K,U,X]=Q,Y=Number(B),z=Number(W),G=Number(J);if(z<1||z>12||G<1||G>31)return null;let A=$===void 0?0:Number($),C=V===void 0?0:Number(V),M=K===void 0?0:Number(K);if(A>23||C>59||M>59)return null;let d=U===void 0?0:Number(U.padEnd(3,"0")),Z1=Date.UTC(Y,z-1,G,A,C,M,d),Q1=new Date(Z1);if(Q1.getUTCFullYear()!==Y||Q1.getUTCMonth()!==z-1||Q1.getUTCDate()!==G)return null;if(X===void 0||X==="Z")return Z1;let $8=X[0]==="-"?1:-1,J8=Number(X.slice(1,3)),B8=Number(X.slice(-2));return Z1+$8*(J8*60+B8)*60000}function u8(Z,Q,B){switch(Q){case"==":return Z===B;case"!=":return Z!==B;case"<":return Z<B;case"<=":return Z<=B;case">":return Z>B;default:return Z>=B}}function F(Z,Q){if(Array.isArray(Z))return Z.map(($)=>F($,Q));if(!i(Z))return Z;let B=Object.keys(Z)[0],W=Z[B];if(B==="if"){let $=k(W);for(let V=0;V+1<$.length;V+=2)if(N(F($[V],Q)))return F($[V+1],Q);return $.length%2===1?F($[$.length-1],Q):null}if(B==="and"||B==="or"){let $=k(W),V=null;for(let K of $)if(V=F(K,Q),N(V)===(B==="or"))return V;return V}if(B==="some"||B==="all"||B==="none"){let $=k(W),V=F($[0],Q);if(!Array.isArray(V))return B==="none";let K=V.some((U)=>N(F($[1],U)));if(B==="some")return K;if(B==="none")return!K;return V.length>0&&V.every((U)=>N(F($[1],U)))}if(B==="regex"){let $=k(W),V=n1($[0],""),K=F($[1],Q);if(typeof K!=="string"||K.length>h)return!1;return V.test(K)}let J=k(W).map(($)=>F($,Q));switch(B){case"var":return F1(Q,J[0],J.length>1?J[1]:void 0);case"missing":return(J.length===1&&Array.isArray(J[0])?J[0]:J).filter((V)=>d1(F1(Q,V,void 0)));case"missing_some":{let $=Number(J[0]),V=Array.isArray(J[1])?J[1]:[J[1]],K=V.filter((U)=>d1(F1(Q,U,void 0)));return V.length-K.length>=$?[]:K}case"!":return!N(J[0]);case"!!":return N(J[0]);case"==":return J[0]==J[1];case"!=":return J[0]!=J[1];case"===":return J[0]===J[1];case"!==":return J[0]!==J[1];case"<":return J.length>2?J[0]<J[1]&&J[1]<J[2]:J[0]<J[1];case"<=":return J.length>2?J[0]<=J[1]&&J[1]<=J[2]:J[0]<=J[1];case">":return J.length>2?J[0]>J[1]&&J[1]>J[2]:J[0]>J[1];case">=":return J.length>2?J[0]>=J[1]&&J[1]>=J[2]:J[0]>=J[1];case"+":return J.map(L).reduce(($,V)=>$+V,0);case"-":return J.length===1?-L(J[0]):L(J[0])-L(J[1]);case"*":return J.map(L).reduce(($,V)=>$*V);case"/":return L(J[0])/L(J[1]);case"%":return L(J[0])%L(J[1]);case"min":return Math.min(...J);case"max":return Math.max(...J);case"cat":return J.map(($)=>$===null||$===void 0?"":String($)).join("");case"substr":{let $=[...String(J[0])],V=Math.trunc(Number(J[1]))||0;if(V<0)V=Math.max($.length+V,0);let K=$.length;if(J.length>2){let U=Math.trunc(Number(J[2]))||0;K=U<0?$.length+U:Math.min(V+U,$.length)}return $.slice(V,Math.max(K,V)).join("")}case"in":{let $=J[1];if(Array.isArray($))return $.indexOf(J[0])!==-1;if(typeof $==="string")return $.indexOf(String(J[0]))!==-1;return!1}default:{let $=m1(J[0]),V=m1(J[2]);if($===null||V===null)return!1;return u8($,String(J[1]),V)}}}function l1(Z){let Q=[],B=(W)=>{if(Array.isArray(W)){for(let V of W)B(V);return}if(!i(W))return;let J=Object.keys(W)[0],$=k(W[J]);if(J==="var"){let V=$[0];if(typeof V==="string"&&V.length>0)Q.push(V)}else if(J==="missing"||J==="missing_some"){for(let V of $.flat())if(typeof V==="string")Q.push(V)}for(let V of $)B(V)};return B(Z),Q}var M1=Object.freeze(["show","require","validate","compute","jump"]),I1="remote",a={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(a);for(let Z of Object.values(a))Object.freeze(Z);var A1=new WeakMap;function o1(Z){return typeof Z==="object"&&Z!==null&&!Array.isArray(Z)}function s1(Z){return q(Z).split(".").filter((Q)=>Q.length>0)}function P(Z,Q,B){if(typeof Z!=="string"||Z.length===0)throw new H(`"${Q}" at ${B} must be a non-empty string.`,B);return Z}function n8(Z,Q,B){let W=`rules[${Q}]`;if(!o1(Z))throw new H(`the rule at ${W} must be an object.`,W);let J=P(Z.id,"id",W),$=`rules[${Q}] ("${J}")`,V=M1.filter((z)=>Z[z]!==void 0);if(V.length===0)throw new H(`the rule at ${$} has no verb (one of ${M1.join(", ")}).`,$);if(V.length>1)throw new H(`the rule at ${$} has ${V.length} verbs (${V.join(", ")}); a rule does one thing.`,$);let K=V[0],U=a[K];for(let z of Object.keys(Z))if(!U.includes(z))throw new H(`unsupported key "${z}" at ${$} (a "${K}" rule accepts ${U.join(", ")}).`,$);if(K==="show"||K==="require"){let z=q(P(Z[K],K,$));if(j(z,$),Z.when===void 0)throw new H(`"${K}" at ${$} needs a "when" condition; a rule with no condition never changes anything.`,$);if(K==="require"&&!B.has(z))throw new H(`"require" at ${$} names "${z}", which is not a key of "fields".`,$);return f(Z.when,$),{id:J,verb:K,path:z,when:Z.when}}if(K==="compute"){let z=q(P(Z.compute,"compute",$));if(j(z,$),Z.value===void 0)throw new H(`"compute" at ${$} needs a "value" expression.`,$);return f(Z.value,$),{id:J,verb:K,path:z,value:Z.value}}if(K==="jump"){let z=P(Z.jump,"jump",$),G=P(Z.from,"from",$);if(j(z,$),j(G,$),Z.when!==void 0)f(Z.when,$);return{id:J,verb:K,path:z,from:G,when:Z.when}}let X=q(P(Z.path,"path",$));j(X,$);let Y=Z.message===void 0?void 0:P(Z.message,"message",$);if(Z.validate===I1){let z=P(Z.remote,"remote",$);return{id:J,verb:K,path:X,message:Y,remote:z,isRemote:!0}}if(Z.remote!==void 0)throw new H(`"remote" at ${$} only belongs to a rule whose "validate" is ${JSON.stringify(I1)}.`,$);return f(Z.validate,$),{id:J,verb:K,path:X,message:Y,logic:Z.validate}}function l8(Z){if(Z.length===0)return[];let Q=Z.map((V)=>V.path),B=Z.map(()=>[]);for(let V=0;V<Z.length;V++){let K=l1(Z[V].value).map(q);for(let U=0;U<Z.length;U++){let X=Q[U];if(K.some((z)=>z===X||z.startsWith(`${X}.`)||X.startsWith(`${z}.`)))B[V].push(U)}}let W=[],J=Z.map(()=>!1),$=!0;while(W.length<Z.length&&$){$=!1;for(let V=0;V<Z.length;V++){if(J[V]||B[V].some((K)=>!J[K]))continue;J[V]=!0,W.push(Z[V]),$=!0}}if(W.length<Z.length){let V=Z.filter((K,U)=>!J[U]);throw new H(V.length===1?`the "compute" rule "${V[0].id}" reads "${V[0].path}", the value it writes, so it can never settle.`:`the "compute" rules ${V.map((K)=>`"${K.id}"`).join(", ")} depend on each other in a cycle.`,"rules")}return W}function g(Z){let Q=Y1(Z);if(!A1.has(Q)){let B=Q.rules.map(($,V)=>n8($,V,Q.fields)),W=new Set;for(let $ of B){if(W.has($.id))throw new H(`two rules share the id "${$.id}"; ids address messages, so they must be unique.`,"rules");W.add($.id)}let J=l8(B.filter(($)=>$.verb==="compute"));A1.set(Q,{all:B,computes:J})}return Q}function o8(Z){return A1.get(Z)??{all:[],computes:[]}}function t(Z,Q,B){let[W,...J]=Q,$=J.length>0&&/^\d+$/.test(J[0]);if(Array.isArray(Z)){let K=Z.slice(),U=Number(W);return K[U]=J.length===0?B:t(K[U],J,B),K}if(Z===void 0||Z===null){if(/^\d+$/.test(W)){let K=[];return K[Number(W)]=J.length===0?B:t($?[]:{},J,B),K}}let V=o1(Z)?{...Z}:{};return V[W]=J.length===0?B:t(O(V,W)?V[W]:void 0,J,B),V}function O1(Z,Q){let B=(J)=>O(Z,J)&&Z[J]===!1;if(B(Q))return!0;let W=s1(Q);for(let J=1;J<W.length;J++)if(B(W.slice(0,J).join(".")))return!0;return!1}function i1(Z,Q){let{all:B,computes:W}=o8(Z),J={},$={},V={},K={},U=Q;for(let X of W){let Y=F(X.value,U);J[X.path]=Y,U=t(U,s1(X.path),Y)}for(let X of B)if(X.verb==="show"){let Y=N(F(X.when,U));$[X.path]=(O($,X.path)?$[X.path]:!0)&&Y}for(let X of B)if(X.verb==="require"){let Y=N(F(X.when,U));V[X.path]=(O(V,X.path)?V[X.path]:!1)||Y}for(let X of Object.keys(V))if(O1($,X))V[X]=!1;for(let X of B){if(X.verb!=="jump")continue;let Y=X.from;if(O(K,Y))continue;if(X.when===void 0||N(F(X.when,U)))K[Y]=X.path}return{computed:J,visible:$,required:V,next:K,data:U,rules:B}}function N1(Z,Q){let B=i1(g(Z),Q);return{visible:B.visible,required:B.required,computed:B.computed,next:B.next}}function s8(Z,Q,B,W){if(O1(B,Z.path))return!1;if(Q.fields.has(Z.path)&&H1(w(W,Z.path)))return!1;return!0}function i8(Z,Q,B,W,J,$){return{path:Q.path,rule:B,message:$??R({messages:Z.messages,locale:W,defaultLocale:Z.defaultLocale,path:Q.path,rule:B,params:{path:Q.path,...J},fallback:B==="remote-error"?D["remote-error"]:Q.message??D.rule}),params:J}}function q1(Z,Q,B){let W=g(Z),J=B?.locale,$=i1(W,Q),V=new Set;for(let[X,Y]of Object.entries($.required))if(Y)V.add(X);let K=p1(W,$.data,{locale:J,required:V}).filter((X)=>!O1($.visible,X.path)),U=[];for(let X of $.rules){if(X.verb!=="validate")continue;if(!s8(X,W,$.visible,$.data))continue;if(X.isRemote){U.push(X.id);continue}if(!N(F(X.logic,$.data)))K.push(i8(W,X,X.id,J,{}))}return{valid:K.length===0&&U.length===0,findings:K,computed:$.computed,visible:$.visible,required:$.required,next:$.next,pending:U}}var E=null,r=new WeakMap,L1=new WeakSet,t1=new WeakMap,a1=new Set;function t8(){return{visible:{},required:{},computed:{},next:{}}}function S(Z,Q,B){if(E&&E.devtools&&E.devtools.report&&E.devtools.report(Z,Q))return;if(a1.has(Z))return;if(a1.add(Z),typeof console<"u"&&console.warn)console.warn("[Faqir] l-rules: "+(B||Z))}function p(Z){return Z.replace(/\[(\d+)\]/g,".$1")}function e(Z,Q,B){let W=Z.querySelectorAll("input, select, textarea"),J=p(Q),$=[];for(let V=0;V<W.length;V++){if(!W[V].name)continue;let K=p(W[V].name);if(K===J||!B&&K.indexOf(J+".")===0)$.push(W[V])}return $}function a8(Z){return Z.closest('[data-ui="field-group"]')||Z}function P1(Z,Q){let B=[],W=Z.querySelectorAll("input, select, textarea");for(let J=0;J<W.length;J++){let $=W[J],V=$.name;if(!V||Q.hidden.has($))continue;if($.tagName==="SELECT"){let K=$.options;for(let U=0;U<K.length;U++)if(K[U].selected&&!K[U].disabled)B.push([V,K[U].value]);continue}if($.tagName==="INPUT"){let K=$.type;if(K==="submit"||K==="button"||K==="reset"||K==="image")continue;if((K==="checkbox"||K==="radio")&&!$.checked)continue;if(K==="file"){let U=$.files;for(let X=0;U&&X<U.length;X++)B.push([V,U[X]]);continue}}B.push([V,$.value])}return C1(Q.definition,G1(B))}function Z8(Z,Q){for(let W=0;W<Q.length;W++){let J=Q[W].target;if(Z.hidden.has(J))Z.foreign.set(J,J.disabled)}let B=!1;if(Z.hidden.forEach(function(W){let J=W;if(!J.disabled)Z.foreign.set(W,!1),J.disabled=!0,B=!0}),B&&Z.observer)Z.observer.takeRecords()}function S1(Z){Z8(Z,Z.observer?Z.observer.takeRecords():[])}function r1(Z,Q,B){if(Q.disabled===B)return;if(Q.disabled=B,Z.observer)Z.observer.takeRecords()}function r8(Z,Q,B){let W=Object.keys(B);if(W.length===0)return;S1(Q);let J=new Map,$=Z.querySelectorAll("input, select, textarea");for(let V=0;V<$.length;V++){let K=$[V];if(!K.name)continue;let U=p(K.name),X=!1,Y=!0;for(let G=0;G<W.length;G++)if(U===W[G]||U.indexOf(W[G]+".")===0){if(X=!0,B[W[G]]===!1)Y=!1}if(!X)continue;let z=a8(K);if(J.set(z,J.get(z)===!0||!Y),!Y&&!Q.hidden.has(K))Q.foreign.set(K,K.disabled),Q.hidden.add(K),r1(Q,K,!0);else if(Y&&Q.hidden.has(K)){let G=Q.foreign.get(K)===!0;Q.hidden.delete(K),Q.foreign.delete(K),r1(Q,K,G)}}J.forEach(function(V,K){if(V&&!K.hasAttribute("hidden"))K.setAttribute("hidden",""),L1.add(K);else if(!V&&L1.has(K))K.removeAttribute("hidden"),L1.delete(K)})}function e8(Z,Q,B){let W=e(Z,Q);for(let J=0;J<W.length;J++){let $=W[J],V=t1.get($);if(!V)V={required:$.required===!0,aria:$.getAttribute("aria-required")==="true"},t1.set($,V);let K=V.required||B===!0;if($.required!==K)$.required=K;if(K||V.aria)$.setAttribute("aria-required","true");else $.removeAttribute("aria-required")}}function ZZ(Z,Q,B,W){if(Q){let V=B.split("."),K=Q,U=!0;for(let Y=0;Y<V.length-1&&U;Y++){let z=K[V[Y]];if(z&&typeof z==="object")K=z;else U=!1}let X=V[V.length-1];if(U&&K[X]!==W)K[X]=W}let J=W===void 0||W===null?"":String(W),$=e(Z,B,!0);for(let V=0;V<$.length;V++)if($[V].value!==J)$[V].value=J}function T1(Z,Q){let B;try{S1(Q),B=N1(Q.definition,P1(Z,Q))}catch(W){let J=W instanceof Error?W.message:String(W);S("l-rules could not evaluate its rules: "+J,Z,J);return}r8(Z,Q,B.visible);for(let W in B.required)e8(Z,W,B.required[W]);for(let W in B.computed)ZZ(Z,Q.scope,W,B.computed[W]);Q.state.visible=B.visible,Q.state.required=B.required,Q.state.computed=B.computed,Q.state.next=B.next}function QZ(Z,Q,B){for(let W=0;W<Z.findings.length;W++){let J=Z.findings[W];if(J.rule===Q&&(B===void 0||J.path===B))return J.message}return!0}function e1(Z,Q,B,W){return function(){try{return QZ(q1(Q.definition,P1(Z,Q),{locale:Q.locale}),B,W)}catch(J){let $=J instanceof Error?J.message:String(J);return S("l-rules could not evaluate its rules: "+$,Z,$),!0}}}function $Z(Z,Q,B){return function(W){let J=P1(Z,Q);return fetch(B.remote,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:B.path,value:W,data:J})}).then(function($){if(!$.ok)throw Error("remote check answered "+$.status);return $.json()}).then(function($){if(!$||typeof $!=="object"||typeof $.ok!=="boolean")throw Error("remote check answered without a boolean `ok`");if($.ok)return!0;if(typeof $.message==="string"&&$.message)return $.message;let V=p(B.path);return R({messages:Q.definition.messages,locale:Q.locale,defaultLocale:Q.definition.defaultLocale,path:V,rule:B.id,params:{path:V,remote:B.remote},fallback:B.message||D.rule})})}}function JZ(Z,Q){let B=Q.split(".");for(let W=B.length;W>0;W--){let J=Z.fields.get(B.slice(0,W).join("."));if(!J)continue;for(let $=W;$<B.length&&J;$++)J=J.type==="object"&&J.properties?J.properties.get(B[$]):J.type==="array"&&/^\d+$/.test(B[$])?J.items:null;return!!(J&&J.regex)}return!1}function BZ(Z,Q,B){let W=[];for(let U=0;U<B.length;U++){let X=B[U];if(!X||X.validate===void 0)continue;let Y=X.validate==="remote"?$Z(Z,Q,X):e1(Z,Q,X.id),z=X.path,G=[],A=e(Z,z,!0);for(let C=0;C<A.length;C++)if(G.indexOf(A[C].name)===-1)G.push(A[C].name);if(G.length===0)G.push(z);for(let C=0;C<G.length;C++)W.push({field:G[C],name:X.id,fn:Y,message:X.message})}let J=W.length,$=Z.querySelectorAll("input, textarea");for(let U=0;U<$.length;U++){let X=$[U];if(!X.name||X.hasAttribute("pattern"))continue;let Y=p(X.name);if(JZ(Q.definition,Y))W.push({field:X.name,name:"pattern",fn:e1(Z,Q,"pattern",Y)})}if(W.length===0)return[];let V=E;if(!V.validate)return S("l-rules has "+W.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.",Z,"faqir-validate is not loaded; validate rules cannot run."),[];if(J>0&&!Z.hasAttribute("l-validate"))S("l-rules has "+J+" validate rule(s) on a form with no l-validate, so nothing validates them on submit. Add l-validate to the form.",Z,"a form with validate rules has no l-validate.");let K=[];for(let U=0;U<W.length;U++){let X=W[U],Y=V.validate.register(Z,X.field,X.name,X.fn,X.message);if(typeof Y==="function")K.push(Y)}return K}function WZ(Z,Q){for(let B=0;B<Q.length;B++){let W=Q[B];if(!W||W.jump!==void 0||W.compute!==void 0)continue;let J=W.show||W.require||W.path;if(typeof J!=="string"||e(Z,J).length>0)continue;if(W.validate!==void 0){S('l-rules rule "'+W.id+'" is a form-level check: its path "'+J+'" names no control in this form, so a server can report it but this page has no field-group to show it on.',Z,'rule "'+W.id+'" is a form-level check with nowhere to report.');continue}S('l-rules rule "'+W.id+'" names the field "'+J+'", which no control '+"in this form is named for — the rule will never change anything.",Z,'rule "'+W.id+'" names an absent field "'+J+'".')}}function VZ(Z,Q,B,W){let J=(Q||"").trim();if(!J)return W.why="l-rules has no value, so there is no definition to apply.",null;let $=J.charAt(0);if($==="#"||$==="."||$==="["){let K=null;try{K=document.querySelector(J)}catch(U){K=null}if(!K)return W.why='l-rules="'+J+'" matches no element.',null;try{return JSON.parse(K.textContent||"")}catch(U){return W.why='l-rules="'+J+'" found an element whose JSON does not parse.',null}}let V=E.evaluate(J,B,Z);if(typeof V==="string")try{return JSON.parse(V)}catch(K){return W.why='l-rules="'+J+'" is a string that does not parse as JSON.',null}if(!V||typeof V!=="object")return W.why='l-rules="'+J+'" resolved to '+(V===void 0?"nothing":typeof V)+", not a rules definition.",null;return V}function Q8(Z){E=Z,Z.magic("rules",function(Q,B){return r.get(B)||t8()}),Z.directive("rules",function(Q,B,W){let J={why:""},$=VZ(Q,B.expression,W,J);if(!$){S(J.why,Q,J.why);return}let V;try{V=g($)}catch(M){let d=M instanceof Error?M.message:String(M);S("l-rules refused this definition: "+d,Q,d);return}let K=Z.reactive({visible:{},required:{},computed:{},next:{}});r.set(W,K);let U={definition:V,scope:W,state:K,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(M){Z8(U,M)}),U.observer.observe(Q,{subtree:!0,attributes:!0,attributeFilter:["disabled"]});let X=V.rules||[];WZ(Q,X);let Y=BZ(Q,U,X);T1(Q,U);let z=!0;function G(){T1(Q,U)}function A(){setTimeout(function(){if(z)T1(Q,U)},0)}function C(){S1(U)}return Q.addEventListener("input",G,!0),Q.addEventListener("change",G,!0),Q.addEventListener("reset",A,!0),Q.addEventListener("submit",C,!0),function(){if(z=!1,Q.removeEventListener("input",G,!0),Q.removeEventListener("change",G,!0),Q.removeEventListener("reset",A,!0),Q.removeEventListener("submit",C,!0),U.observer)U.observer.disconnect();for(let M=0;M<Y.length;M++)Y[M]();if(r.get(W)===K)r.delete(W)}})}var j1=typeof globalThis<"u"&&globalThis.Faqir||typeof window<"u"&&window.Faqir;if(j1&&typeof j1.plugin==="function")j1.plugin(Q8);})();
|