@orkestrel/form 0.0.5 → 0.0.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["#emitter","#schema","#messages","#baseline","#values","#touched","#disabled","#invalidations","#resolvers","#requireField","#evaluate","#errors","#status","#gate","#batch","#differs","#change","#evaluation","#readSettlement","#snapshot","#pending","#batchDepth","#teardown"],"sources":["../../../src/core/constants.ts","../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/cloners.ts","../../../src/core/helpers.ts","../../../src/core/parsers.ts","../../../src/core/Form.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { FieldControl, FieldRuleName, FormStatus } from './types.js'\n\n/** Lists every field control, in the order declared by the public contract. */\nexport const FIELD_CONTROLS: readonly FieldControl[] = Object.freeze([\n\t'text',\n\t'editor',\n\t'password',\n\t'number',\n\t'date',\n\t'time',\n\t'datetime',\n\t'color',\n\t'confirm',\n\t'select',\n\t'checkbox',\n\t'file',\n])\n\n/** Lists the members every field declares, whatever its control. */\nexport const FIELD_BASE_KEYS: readonly string[] = Object.freeze([\n\t'control',\n\t'name',\n\t'label',\n\t'help',\n\t'group',\n\t'hidden',\n\t'disabled',\n\t'locked',\n\t'rule',\n\t'meta',\n])\n\n/**\n * Lists every member one field control permits, composed from {@link FIELD_BASE_KEYS} and the\n * members the control's own interface adds.\n */\nexport const FIELD_KEYS: Readonly<Record<FieldControl, readonly string[]>> = Object.freeze({\n\ttext: Object.freeze([...FIELD_BASE_KEYS, 'default', 'placeholder']),\n\teditor: Object.freeze([...FIELD_BASE_KEYS, 'default', 'placeholder']),\n\tpassword: Object.freeze([...FIELD_BASE_KEYS, 'mask']),\n\tnumber: Object.freeze([...FIELD_BASE_KEYS, 'default', 'placeholder']),\n\tdate: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\ttime: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tdatetime: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tcolor: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tconfirm: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tselect: Object.freeze([...FIELD_BASE_KEYS, 'choices', 'default', 'open']),\n\tcheckbox: Object.freeze([...FIELD_BASE_KEYS, 'choices', 'default']),\n\tfile: Object.freeze([...FIELD_BASE_KEYS, 'accept', 'multiple']),\n})\n\n/** Lists every form lifecycle status. */\nexport const FORM_STATUSES: readonly FormStatus[] = Object.freeze([\n\t'editing',\n\t'settled',\n\t'abandoned',\n])\n\n/** Holds the default failure copy for every named field rule. */\nexport const RULE_MESSAGES: Readonly<Record<FieldRuleName, string>> = Object.freeze({\n\trequired: 'This field is required',\n\tminimum: 'Must be at least {limit}',\n\tmaximum: 'Must be at most {limit}',\n\tstep: 'Must be a multiple of {limit}',\n\tpattern: 'Must match the required format',\n\temail: 'Must be a valid email address',\n\turl: 'Must be a valid URL',\n\tinteger: 'Must be an integer',\n\talphanumeric: 'Must contain only letters and numbers',\n})\n\n/** Matches a practical whole-address email shape. */\nexport const EMAIL_PATTERN = Object.freeze(/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/)\n\n/** Matches an absolute HTTP or HTTPS URL shape. */\nexport const URL_PATTERN = Object.freeze(/^https?:\\/\\/[^\\s]+$/)\n\n/** Matches one or more ASCII letters or digits. */\nexport const ALPHANUMERIC_PATTERN = Object.freeze(/^[A-Za-z0-9]+$/)\n\n/** Matches a signed or unsigned base-ten integer string. */\nexport const INTEGER_PATTERN = Object.freeze(/^[+-]?\\d+$/)\n\n/** Matches a six-digit hexadecimal color string. */\nexport const COLOR_PATTERN = Object.freeze(/^#[0-9A-Fa-f]{6}$/)\n\n/** Matches an ISO calendar date string in `YYYY-MM-DD` form. */\nexport const DATE_PATTERN = Object.freeze(/^\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])$/)\n\n/** Matches a 24-hour time string with optional seconds. */\nexport const TIME_PATTERN = Object.freeze(/^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$/)\n\n/** Matches an ISO local date and time string with optional seconds. */\nexport const DATETIME_PATTERN = Object.freeze(\n\t/^\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])T(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$/,\n)\n\n/** Caps the accepted source length for an authored regular expression. */\nexport const PATTERN_LIMIT = 256\n\n/** Caps the number of fields one schema may declare. */\nexport const FIELD_LIMIT = 512\n\n/** Caps the number of groups one schema may declare. */\nexport const GROUP_LIMIT = 64\n\n/** Caps the number of choices one `select` or `checkbox` field may offer. */\nexport const CHOICE_LIMIT = 1024\n\n/** Caps the number of entries one list-valued answer may hold. */\nexport const LIST_LIMIT = 1024\n\n/** Caps the length, in UTF-16 code units, of a schema, group, or field name. */\nexport const NAME_LIMIT = 128\n\n/** Caps the length, in UTF-16 code units, of any single retained string. */\nexport const STRING_LIMIT = 65536\n\n/** Caps the total length, in UTF-16 code units, of every string one schema retains. */\nexport const TEXT_LIMIT = 1048576\n\n/** Caps the total number of records, arrays, and leaves one schema retains. */\nexport const NODE_LIMIT = 16384\n","import type { JSONRecord } from '@orkestrel/contract'\nimport type { FormErrorCode } from './types.js'\n\n/**\n * Represents an error raised by the form domain.\n *\n * @example\n * ```ts\n * const error = new FormError('FIELD', 'The schema declares no field named \"nickname\"', {\n * \tfield: 'nickname',\n * })\n *\n * error.code // 'FIELD'\n * error.context // { field: 'nickname' }\n * ```\n */\nexport class FormError extends Error {\n\t/** Holds the machine-readable reason for this failure. */\n\treadonly code: FormErrorCode\n\n\t/** Holds structured values that locate or explain this failure. */\n\treadonly context?: JSONRecord\n\n\t/**\n\t * Creates a form error.\n\t *\n\t * @param code - The machine-readable reason.\n\t * @param message - The human-readable failure text.\n\t * @param context - Optional structured failure details.\n\t */\n\tconstructor(code: FormErrorCode, message: string, context?: JSONRecord) {\n\t\tsuper(message)\n\t\tthis.name = 'FormError'\n\t\tthis.code = code\n\t\tif (context !== undefined) this.context = context\n\t}\n}\n\n/**\n * Determines whether an unknown value is a form error.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a {@link FormError} instance; false otherwise.\n */\nexport function isFormError(input: unknown): input is FormError {\n\treturn input instanceof FormError\n}\n","import type {\n\tFieldChoice,\n\tFieldControl,\n\tFieldError,\n\tFieldRule,\n\tFieldValue,\n\tFormField,\n\tFormGroup,\n\tFormSchema,\n\tFormStatus,\n\tFormValues,\n} from './types.js'\nimport {\n\tarrayOf,\n\tattempt,\n\tisBoolean,\n\tisBoundedJSONRecord,\n\tisFiniteNumber,\n\tisFunction,\n\tisRecord,\n\tisString,\n\tkeyOf,\n\trecordOf,\n\tunionOf,\n} from '@orkestrel/contract'\nimport { FIELD_CONTROLS, FIELD_KEYS, FORM_STATUSES, RULE_MESSAGES } from './constants.js'\n\n/**\n * Determines whether an unknown value is a declared field control.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field control; false otherwise.\n */\nexport function isFieldControl(input: unknown): input is FieldControl {\n\treturn FIELD_CONTROLS.some((control) => control === input)\n}\n\n/**\n * Determines whether an unknown value is a form lifecycle status.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a form status; false otherwise.\n */\nexport function isFormStatus(input: unknown): input is FormStatus {\n\treturn FORM_STATUSES.some((status) => status === input)\n}\n\n/**\n * Determines whether an unknown value has a form field value shape.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field value; false otherwise.\n */\nexport function isFieldValue(input: unknown): input is FieldValue {\n\treturn unionOf(isString, isFiniteNumber, isBoolean, arrayOf(isString))(input)\n}\n\n/**\n * Determines whether an unknown value is one exact field choice record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field choice; false otherwise.\n */\nexport function isFieldChoice(input: unknown): input is FieldChoice {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf({ value: isString, label: isString, help: isString, disabled: isBoolean }, [\n\t\t'help',\n\t\t'disabled',\n\t])(input)\n}\n\n/**\n * Determines whether an unknown value is one exact field rule record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a structurally valid field rule; false otherwise.\n */\nexport function isFieldRule(input: unknown): input is FieldRule {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf(\n\t\t{\n\t\t\trequired: isBoolean,\n\t\t\tminimum: unionOf(isFiniteNumber, isString),\n\t\t\tmaximum: unionOf(isFiniteNumber, isString),\n\t\t\tstep: isFiniteNumber,\n\t\t\tpattern: isString,\n\t\t\temail: isBoolean,\n\t\t\turl: isBoolean,\n\t\t\tinteger: isBoolean,\n\t\t\talphanumeric: isBoolean,\n\t\t\tcustom: isFunction,\n\t\t},\n\t\ttrue,\n\t)(input)\n}\n\n/**\n * Determines whether an unknown value is one exact discriminated form field.\n *\n * @remarks\n * Metadata is admitted structurally as bounded JSON. An accessor-bearing metadata record is\n * refused later when {@link cloneFormField} takes ownership, because ownership accepts enumerable\n * data properties only.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a structurally valid form field; false otherwise.\n */\nexport function isFormField(input: unknown): input is FormField {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input) || !Object.hasOwn(input, 'control') || !Object.hasOwn(input, 'name')) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst control = input.control\n\t\tif (!isFieldControl(control)) return false\n\n\t\tconst permitted = FIELD_KEYS[control]\n\t\tconst exact = Reflect.ownKeys(input).every((key) => isString(key) && permitted.includes(key))\n\n\t\tif (!exact) return false\n\n\t\tconst name = input.name\n\t\tconst hasLabel = Object.hasOwn(input, 'label')\n\t\tconst label = hasLabel ? input.label : undefined\n\t\tconst hasHelp = Object.hasOwn(input, 'help')\n\t\tconst help = hasHelp ? input.help : undefined\n\t\tconst hasGroup = Object.hasOwn(input, 'group')\n\t\tconst group = hasGroup ? input.group : undefined\n\t\tconst hasHidden = Object.hasOwn(input, 'hidden')\n\t\tconst hidden = hasHidden ? input.hidden : undefined\n\t\tconst hasDisabled = Object.hasOwn(input, 'disabled')\n\t\tconst disabled = hasDisabled ? input.disabled : undefined\n\t\tconst hasLocked = Object.hasOwn(input, 'locked')\n\t\tconst locked = hasLocked ? input.locked : undefined\n\t\tconst hasRule = Object.hasOwn(input, 'rule')\n\t\tconst rule = hasRule ? input.rule : undefined\n\t\tconst hasMeta = Object.hasOwn(input, 'meta')\n\t\tconst meta = hasMeta ? input.meta : undefined\n\n\t\tif (\n\t\t\t!isString(name) ||\n\t\t\t(hasLabel && !isString(label)) ||\n\t\t\t(hasHelp && !isString(help)) ||\n\t\t\t(hasGroup && !isString(group)) ||\n\t\t\t(hasHidden && !isBoolean(hidden)) ||\n\t\t\t(hasDisabled && !isBoolean(disabled)) ||\n\t\t\t(hasLocked && !isBoolean(locked)) ||\n\t\t\t(hasRule && !isFieldRule(rule)) ||\n\t\t\t(hasMeta && !isBoundedJSONRecord(meta))\n\t\t) {\n\t\t\treturn false\n\t\t}\n\n\t\tswitch (control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\tconst hasPlaceholder = Object.hasOwn(input, 'placeholder')\n\t\t\t\tconst placeholder = hasPlaceholder ? input.placeholder : undefined\n\t\t\t\treturn (!hasDefault || isString(fallback)) && (!hasPlaceholder || isString(placeholder))\n\t\t\t}\n\t\t\tcase 'password': {\n\t\t\t\tconst hasMask = Object.hasOwn(input, 'mask')\n\t\t\t\tconst mask = hasMask ? input.mask : undefined\n\t\t\t\treturn !hasMask || isString(mask)\n\t\t\t}\n\t\t\tcase 'number': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\tconst hasPlaceholder = Object.hasOwn(input, 'placeholder')\n\t\t\t\tconst placeholder = hasPlaceholder ? input.placeholder : undefined\n\t\t\t\treturn (\n\t\t\t\t\t(!hasDefault || isFiniteNumber(fallback)) && (!hasPlaceholder || isString(placeholder))\n\t\t\t\t)\n\t\t\t}\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\treturn !hasDefault || isString(fallback)\n\t\t\t}\n\t\t\tcase 'confirm': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\treturn !hasDefault || isBoolean(fallback)\n\t\t\t}\n\t\t\tcase 'select': {\n\t\t\t\tif (!Object.hasOwn(input, 'choices')) return false\n\t\t\t\tconst choices = input.choices\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\tconst hasOpen = Object.hasOwn(input, 'open')\n\t\t\t\tconst open = hasOpen ? input.open : undefined\n\t\t\t\treturn (\n\t\t\t\t\tarrayOf(isFieldChoice)(choices) &&\n\t\t\t\t\t(!hasDefault || isString(fallback)) &&\n\t\t\t\t\t(!hasOpen || isBoolean(open))\n\t\t\t\t)\n\t\t\t}\n\t\t\tcase 'checkbox': {\n\t\t\t\tif (!Object.hasOwn(input, 'choices')) return false\n\t\t\t\tconst choices = input.choices\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\treturn arrayOf(isFieldChoice)(choices) && (!hasDefault || arrayOf(isString)(fallback))\n\t\t\t}\n\t\t\tcase 'file': {\n\t\t\t\tconst hasAccept = Object.hasOwn(input, 'accept')\n\t\t\t\tconst accept = hasAccept ? input.accept : undefined\n\t\t\t\tconst hasMultiple = Object.hasOwn(input, 'multiple')\n\t\t\t\tconst multiple = hasMultiple ? input.multiple : undefined\n\t\t\t\treturn (!hasAccept || arrayOf(isString)(accept)) && (!hasMultiple || isBoolean(multiple))\n\t\t\t}\n\t\t}\n\t})\n\n\treturn outcome.success && outcome.value\n}\n\n/**\n * Determines whether an unknown value is one exact form group record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a form group; false otherwise.\n */\nexport function isFormGroup(input: unknown): input is FormGroup {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf({ name: isString, label: isString, help: isString }, ['help'])(input)\n}\n\n/**\n * Determines whether an unknown value is one exact structural form schema.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a structurally valid form schema; false otherwise.\n */\nexport function isFormSchema(input: unknown): input is FormSchema {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf(\n\t\t{\n\t\t\tname: isString,\n\t\t\tlabel: isString,\n\t\t\thelp: isString,\n\t\t\tgroups: arrayOf(isFormGroup),\n\t\t\tfields: arrayOf(isFormField),\n\t\t},\n\t\t['name', 'label', 'help', 'groups'],\n\t)(input)\n}\n\n/**\n * Determines whether an unknown value is a record of field values.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a form values record; false otherwise.\n */\nexport function isFormValues(input: unknown): input is FormValues {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input)) return false\n\t\treturn Reflect.ownKeys(input).every(\n\t\t\t(key) => isString(key) && Object.hasOwn(input, key) && isFieldValue(input[key]),\n\t\t)\n\t})\n\n\treturn outcome.success && outcome.value\n}\n\n/**\n * Determines whether an unknown value is one exact field error record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field error; false otherwise.\n */\nexport function isFieldError(input: unknown): input is FieldError {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf(\n\t\t{\n\t\t\tfield: isString,\n\t\t\tmessage: isString,\n\t\t\trule: keyOf(RULE_MESSAGES),\n\t\t},\n\t\t['rule'],\n\t)(input)\n}\n","import type { JSONRecord } from '@orkestrel/contract'\nimport type { FieldChoice, FieldRule, FieldValue, FormField, FormSchema } from './types.js'\nimport { cloneJSONRecord, isArray, isContractError } from '@orkestrel/contract'\nimport { FormError } from './errors.js'\n\n/**\n * Clones one form value into an owned frozen snapshot.\n *\n * @param value - The field value to own.\n * @returns The scalar unchanged, or a frozen copy of the list.\n */\nexport function cloneValue(value: readonly string[]): readonly string[]\nexport function cloneValue(value: FieldValue): FieldValue\nexport function cloneValue(value: FieldValue): FieldValue {\n\treturn isArray(value) ? Object.freeze(value.slice()) : value\n}\n\n/**\n * Clones a field's choices into an owned frozen snapshot.\n *\n * @param choices - The choices to own.\n * @returns A frozen list of frozen choice records.\n */\nexport function cloneChoices(choices: readonly FieldChoice[]): readonly FieldChoice[] {\n\treturn Object.freeze(choices.map((choice) => Object.freeze({ ...choice })))\n}\n\n/**\n * Clones one form field into an owned frozen snapshot.\n *\n * @param field - The field to own.\n * @returns A frozen field with every nested collection owned.\n * @throws A {@link FormError} coded `SCHEMA` when accessor-bearing metadata cannot be owned.\n */\nexport function cloneFormField(field: FormField): FormField {\n\tconst rule: { rule?: Readonly<FieldRule> } =\n\t\tfield.rule === undefined ? {} : { rule: Object.freeze({ ...field.rule }) }\n\tlet meta: { meta?: JSONRecord } = {}\n\n\tif (field.meta !== undefined) {\n\t\ttry {\n\t\t\tmeta = { meta: cloneJSONRecord(field.meta) }\n\t\t} catch (error) {\n\t\t\tif (!isContractError(error)) throw error\n\t\t\tthrow new FormError('SCHEMA', `Field \"${field.name}\" has metadata that cannot be owned`, {\n\t\t\t\tfield: field.name,\n\t\t\t})\n\t\t}\n\t}\n\n\tswitch (field.control) {\n\t\tcase 'select':\n\t\t\treturn Object.freeze({ ...field, ...rule, ...meta, choices: cloneChoices(field.choices) })\n\t\tcase 'checkbox':\n\t\t\treturn Object.freeze({\n\t\t\t\t...field,\n\t\t\t\t...rule,\n\t\t\t\t...meta,\n\t\t\t\tchoices: cloneChoices(field.choices),\n\t\t\t\t...(field.default === undefined ? {} : { default: cloneValue(field.default) }),\n\t\t\t})\n\t\tcase 'file':\n\t\t\treturn Object.freeze({\n\t\t\t\t...field,\n\t\t\t\t...rule,\n\t\t\t\t...meta,\n\t\t\t\t...(field.accept === undefined ? {} : { accept: cloneValue(field.accept) }),\n\t\t\t})\n\t\tcase 'text':\n\t\tcase 'editor':\n\t\tcase 'password':\n\t\tcase 'number':\n\t\tcase 'date':\n\t\tcase 'time':\n\t\tcase 'datetime':\n\t\tcase 'color':\n\t\tcase 'confirm':\n\t\t\treturn Object.freeze({ ...field, ...rule, ...meta })\n\t}\n}\n\n/**\n * Clones a form schema into an owned frozen snapshot.\n *\n * @param schema - The schema to own.\n * @returns A frozen schema with every nested record and list owned.\n */\nexport function cloneFormSchema(schema: FormSchema): FormSchema {\n\tconst groups = schema.groups\n\n\treturn Object.freeze({\n\t\t...schema,\n\t\t...(groups === undefined\n\t\t\t? {}\n\t\t\t: { groups: Object.freeze(groups.map((group) => Object.freeze({ ...group }))) }),\n\t\tfields: Object.freeze(schema.fields.map((field) => cloneFormField(field))),\n\t})\n}\n","import type { JSONRecord, JSONValue } from '@orkestrel/contract'\nimport type {\n\tEvaluationOptions,\n\tFieldError,\n\tFieldControl,\n\tFieldRuleName,\n\tFieldValue,\n\tFormField,\n\tFormGroup,\n\tFormSchema,\n\tFormValues,\n} from './types.js'\nimport {\n\tattempt,\n\tcloneJSONRecord,\n\tisArray,\n\tisBoolean,\n\tisFiniteNumber,\n\tisInteger,\n\tisContractError,\n\tisRecord,\n\tisString,\n\treadArrayEntries,\n} from '@orkestrel/contract'\nimport { cloneValue } from './cloners.js'\nimport {\n\tALPHANUMERIC_PATTERN,\n\tCHOICE_LIMIT,\n\tCOLOR_PATTERN,\n\tDATE_PATTERN,\n\tDATETIME_PATTERN,\n\tEMAIL_PATTERN,\n\tFIELD_CONTROLS,\n\tFIELD_LIMIT,\n\tGROUP_LIMIT,\n\tINTEGER_PATTERN,\n\tLIST_LIMIT,\n\tNAME_LIMIT,\n\tNODE_LIMIT,\n\tPATTERN_LIMIT,\n\tRULE_MESSAGES,\n\tSTRING_LIMIT,\n\tTEXT_LIMIT,\n\tTIME_PATTERN,\n\tURL_PATTERN,\n} from './constants.js'\nimport { FormError } from './errors.js'\n\n/**\n * Writes one own enumerable data property onto a record.\n *\n * @param target - The record to write into.\n * @param name - The property name to write.\n * @param value - The value to store.\n *\n * @remarks\n * Plain assignment runs an inherited setter, so writing a `__proto__` key that way reaches\n * `Object.prototype` and leaves the record without the entry. Defining the property writes the\n * record itself, whatever the prototype chain declares. The entry stays writable and configurable.\n *\n * @example\n * ```ts\n * const values: Record<string, number> = {}\n * defineEntry(values, '__proto__', 1)\n * Object.hasOwn(values, '__proto__') // true\n * ```\n */\nexport function defineEntry<T>(target: Record<string, T>, name: string, value: T): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t})\n}\n\n/**\n * Writes one own enumerable data property that cannot be rewritten or removed.\n *\n * @param target - The record to write into.\n * @param name - The property name to write.\n * @param value - The value to store.\n *\n * @remarks\n * The prototype-safe write of {@link defineEntry}, frozen: the entry is neither writable nor\n * configurable, so the record a parser hands back cannot be edited through the key it just filled.\n *\n * @example\n * ```ts\n * const values: Record<string, number> = {}\n * freezeEntry(values, '__proto__', 1)\n * Object.getOwnPropertyDescriptor(values, '__proto__')?.writable // false\n * ```\n */\nexport function freezeEntry<T>(target: Record<string, T>, name: string, value: T): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t})\n}\n\n/**\n * Checks whether a value has the shape required by one field control.\n *\n * @param field - The field that owns the value.\n * @param value - The unknown value to inspect.\n * @returns True if the control can hold the value; false otherwise.\n */\nexport function matchesField(field: FormField, value: unknown): value is FieldValue {\n\tif (isString(value) && value.length > STRING_LIMIT) return false\n\n\tlet entries: readonly unknown[] | undefined\n\tif (isArray(value)) {\n\t\tconst length = attempt(() => value.length)\n\t\tif (!length.success || length.value > LIST_LIMIT) return false\n\n\t\tconst read = readArrayEntries(value)\n\t\tif (!read.success || !read.value.dense) return false\n\n\t\tentries = read.value.entries\n\t\tif (entries.some((entry) => !isString(entry) || entry.length > STRING_LIMIT)) return false\n\t}\n\n\tswitch (field.control) {\n\t\tcase 'text':\n\t\tcase 'editor':\n\t\tcase 'password':\n\t\t\treturn isString(value)\n\t\tcase 'number':\n\t\t\treturn isFiniteNumber(value)\n\t\tcase 'date':\n\t\t\treturn isString(value) && DATE_PATTERN.test(value)\n\t\tcase 'time':\n\t\t\treturn isString(value) && TIME_PATTERN.test(value)\n\t\tcase 'datetime':\n\t\t\treturn isString(value) && DATETIME_PATTERN.test(value)\n\t\tcase 'color':\n\t\t\treturn isString(value) && COLOR_PATTERN.test(value)\n\t\tcase 'confirm':\n\t\t\treturn isBoolean(value)\n\t\tcase 'select':\n\t\t\treturn (\n\t\t\t\tisString(value) &&\n\t\t\t\t!field.choices.some((choice) => choice.value === value && choice.disabled === true) &&\n\t\t\t\t(field.open === true ||\n\t\t\t\t\tfield.choices.some((choice) => choice.value === value && choice.disabled !== true))\n\t\t\t)\n\t\tcase 'checkbox':\n\t\t\treturn (\n\t\t\t\tentries !== undefined &&\n\t\t\t\tentries.every(\n\t\t\t\t\t(entry) =>\n\t\t\t\t\t\tisString(entry) &&\n\t\t\t\t\t\tfield.choices.some((choice) => choice.value === entry && choice.disabled !== true),\n\t\t\t\t) &&\n\t\t\t\tnew Set(entries).size === entries.length\n\t\t\t)\n\t\tcase 'file':\n\t\t\treturn entries !== undefined && (field.multiple === true || entries.length <= 1)\n\t}\n}\n\n/**\n * Decides whether a raw binding value projects to an answered field.\n *\n * @remarks\n * Bind with `fill(name, matchesAnswer(raw) ? raw : undefined)`. This projection treats an absent\n * value and a string containing only whitespace as unanswered. Every other field value is an\n * answer, including an empty list, `false`, and zero. Core evaluation does not use this projection:\n * its `required` rule remains presence-only.\n *\n * @param value - The raw field value, or absence.\n * @returns True if the binding preserves the value as an answer; false otherwise.\n */\nexport function matchesAnswer(value: FieldValue | undefined): boolean {\n\treturn value !== undefined && (!isString(value) || value.trim().length > 0)\n}\n\n/**\n * Checks whether a named rule applies to one field control.\n *\n * @remarks\n * The runtime control-membership check keeps this boundary total for JavaScript callers that\n * bypass the declared {@link FieldControl} contract.\n *\n * @param control - The field control to inspect.\n * @param rule - The named rule to inspect.\n * @returns True if the control evaluates that rule; false otherwise.\n */\nexport function appliesRule(control: FieldControl, rule: FieldRuleName): boolean {\n\tif (!FIELD_CONTROLS.some((candidate) => candidate === control)) return false\n\n\tswitch (rule) {\n\t\tcase 'required':\n\t\t\treturn true\n\t\tcase 'minimum':\n\t\tcase 'maximum':\n\t\t\treturn control !== 'color' && control !== 'confirm' && control !== 'select'\n\t\tcase 'step':\n\t\t\treturn control === 'number'\n\t\tcase 'pattern':\n\t\tcase 'email':\n\t\tcase 'url':\n\t\tcase 'alphanumeric':\n\t\t\treturn (\n\t\t\t\tcontrol !== 'number' &&\n\t\t\t\tcontrol !== 'confirm' &&\n\t\t\t\tcontrol !== 'checkbox' &&\n\t\t\t\tcontrol !== 'file'\n\t\t\t)\n\t\tcase 'integer':\n\t\t\treturn control !== 'confirm' && control !== 'checkbox' && control !== 'file'\n\t}\n\n\treturn false\n}\n\n/**\n * Evaluates one field rule against its current value.\n *\n * @param field - The field and rule to evaluate.\n * @param value - The current value, or absence.\n * @param values - Every value available to a custom rule.\n * @param messages - Optional rule-specific message replacements.\n * @returns Every failure in rule order.\n * @throws Thrown when a {@link FieldValidator} supplied through {@link FieldRule.custom} throws:\n * its own value escapes unchanged, because this helper adds no boundary around it.\n */\nexport function evaluateField(\n\tfield: FormField,\n\tvalue: FieldValue | undefined,\n\tvalues: FormValues,\n\tmessages?: Readonly<Partial<Record<FieldRuleName, string>>>,\n): readonly FieldError[] {\n\tconst errors: FieldError[] = []\n\tconst rule = field.rule\n\n\tif (value === undefined) {\n\t\tif (rule?.required === true && appliesRule(field.control, 'required')) {\n\t\t\terrors.push(createFieldError(field, 'required', undefined, messages))\n\t\t}\n\t}\n\n\tif (rule === undefined) return Object.freeze(errors)\n\n\tif (rule.minimum !== undefined && appliesRule(field.control, 'minimum')) {\n\t\tlet failed = false\n\n\t\tswitch (field.control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'password':\n\t\t\t\tfailed = isString(value) && isFiniteNumber(rule.minimum) && value.length < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'number':\n\t\t\t\tfailed = isFiniteNumber(value) && isFiniteNumber(rule.minimum) && value < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\t\tfailed = isString(value) && isString(rule.minimum) && value < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'checkbox':\n\t\t\tcase 'file':\n\t\t\t\tfailed = isArray(value) && isFiniteNumber(rule.minimum) && value.length < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (failed) {\n\t\t\terrors.push(createFieldError(field, 'minimum', rule.minimum, messages))\n\t\t}\n\t}\n\n\tif (rule.maximum !== undefined && appliesRule(field.control, 'maximum')) {\n\t\tlet failed = false\n\n\t\tswitch (field.control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'password':\n\t\t\t\tfailed = isString(value) && isFiniteNumber(rule.maximum) && value.length > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'number':\n\t\t\t\tfailed = isFiniteNumber(value) && isFiniteNumber(rule.maximum) && value > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\t\tfailed = isString(value) && isString(rule.maximum) && value > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'checkbox':\n\t\t\tcase 'file':\n\t\t\t\tfailed = isArray(value) && isFiniteNumber(rule.maximum) && value.length > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (failed) {\n\t\t\terrors.push(createFieldError(field, 'maximum', rule.maximum, messages))\n\t\t}\n\t}\n\n\tif (rule.step !== undefined && appliesRule(field.control, 'step') && isFiniteNumber(value)) {\n\t\tconst base = isFiniteNumber(rule.minimum) ? rule.minimum : 0\n\t\tconst multiple = (value - base) / rule.step\n\n\t\tif (\n\t\t\t!isFiniteNumber(rule.step) ||\n\t\t\trule.step === 0 ||\n\t\t\t!isFiniteNumber(multiple) ||\n\t\t\tMath.abs(multiple - Math.round(multiple)) > 1e-9\n\t\t) {\n\t\t\terrors.push(createFieldError(field, 'step', rule.step, messages))\n\t\t}\n\t}\n\n\tif (isString(value)) {\n\t\tif (rule.pattern !== undefined && appliesRule(field.control, 'pattern')) {\n\t\t\tconst pattern = rule.pattern\n\n\t\t\tif (pattern.length > PATTERN_LIMIT) {\n\t\t\t\terrors.push(createFieldError(field, 'pattern', undefined, messages))\n\t\t\t} else {\n\t\t\t\tconst outcome = attempt(() => new RegExp(pattern).test(value))\n\n\t\t\t\tif (!outcome.success || !outcome.value) {\n\t\t\t\t\terrors.push(createFieldError(field, 'pattern', undefined, messages))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (rule.email === true && appliesRule(field.control, 'email') && !EMAIL_PATTERN.test(value)) {\n\t\t\terrors.push(createFieldError(field, 'email', undefined, messages))\n\t\t}\n\n\t\tif (rule.url === true && appliesRule(field.control, 'url') && !URL_PATTERN.test(value)) {\n\t\t\terrors.push(createFieldError(field, 'url', undefined, messages))\n\t\t}\n\n\t\tif (\n\t\t\trule.alphanumeric === true &&\n\t\t\tappliesRule(field.control, 'alphanumeric') &&\n\t\t\t!ALPHANUMERIC_PATTERN.test(value)\n\t\t) {\n\t\t\terrors.push(createFieldError(field, 'alphanumeric', undefined, messages))\n\t\t}\n\n\t\tif (\n\t\t\trule.integer === true &&\n\t\t\tappliesRule(field.control, 'integer') &&\n\t\t\t!INTEGER_PATTERN.test(value)\n\t\t) {\n\t\t\terrors.push(createFieldError(field, 'integer', undefined, messages))\n\t\t}\n\t}\n\n\tif (\n\t\tvalue !== undefined &&\n\t\tfield.control === 'number' &&\n\t\trule.integer === true &&\n\t\tappliesRule(field.control, 'integer') &&\n\t\t!isInteger(value)\n\t) {\n\t\terrors.push(createFieldError(field, 'integer', undefined, messages))\n\t}\n\n\tif (rule.custom !== undefined) {\n\t\tconst result = rule.custom(value, values)\n\n\t\tif (isString(result)) errors.push(Object.freeze({ field: field.name, message: result }))\n\t}\n\n\treturn Object.freeze(errors)\n}\n\n/**\n * Evaluates every active field in schema order.\n *\n * @param schema - The form schema to evaluate.\n * @param values - The values keyed by field name.\n * @param options - Optional message replacements and the effective disabled field set.\n * @returns Every field failure in schema and rule order.\n * @throws Thrown when a {@link FieldValidator} supplied through {@link FieldRule.custom} throws:\n * its own value escapes unchanged, because this helper adds no boundary around it.\n */\nexport function evaluateForm(\n\tschema: FormSchema,\n\tvalues: FormValues,\n\toptions?: EvaluationOptions,\n): readonly FieldError[] {\n\tconst errors: FieldError[] = []\n\n\tfor (const field of schema.fields) {\n\t\tconst active =\n\t\t\toptions?.disabled === undefined ? field.disabled !== true : !options.disabled.has(field.name)\n\n\t\tif (active) {\n\t\t\tconst value = Object.hasOwn(values, field.name) ? values[field.name] : undefined\n\t\t\terrors.push(...evaluateField(field, value, values, options?.messages))\n\t\t}\n\t}\n\n\treturn Object.freeze(errors)\n}\n\n/**\n * Computes the values explicitly seeded by a schema.\n *\n * @param schema - The schema whose defaults to collect.\n * @returns A value record containing only fields with defaults.\n */\nexport function computeDefaults(schema: FormSchema): FormValues {\n\tconst defaults: Record<string, FieldValue> = {}\n\n\tfor (const field of schema.fields) {\n\t\tswitch (field.control) {\n\t\t\tcase 'checkbox':\n\t\t\t\tif (field.default !== undefined) {\n\t\t\t\t\tdefineEntry(defaults, field.name, cloneValue(field.default))\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase 'password':\n\t\t\tcase 'file':\n\t\t\t\tbreak\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'number':\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\t\tif (field.default !== undefined) {\n\t\t\t\t\tdefineEntry(defaults, field.name, field.default)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\treturn Object.freeze(defaults)\n}\n\n/**\n * Compares two field values by scalar identity or ordered list content.\n *\n * @param a - The first field value.\n * @param b - The second field value.\n * @returns True if both values contain the same answer; false otherwise.\n */\nexport function matchesValue(a: FieldValue, b: FieldValue): boolean {\n\tif (isArray(a) || isArray(b)) {\n\t\treturn (\n\t\t\tisArray(a) &&\n\t\t\tisArray(b) &&\n\t\t\ta.length === b.length &&\n\t\t\ta.every((entry, index) => entry === b[index])\n\t\t)\n\t}\n\n\treturn a === b\n}\n\n/**\n * Extracts the names whose answers differ between two form value records.\n *\n * @remarks\n * Presence is compared in both directions before present values are compared through\n * {@link matchesValue}. The returned set is a new snapshot, exposed as readonly because later\n * changes to either input never alter its membership.\n *\n * @param current - The values the form holds.\n * @param opened - The values held when the form opened.\n * @returns A readonly snapshot of changed field names.\n */\nexport function extractChanges(current: FormValues, opened: FormValues): ReadonlySet<string> {\n\tconst names = new Set([...Object.keys(current), ...Object.keys(opened)])\n\tconst changed = new Set<string>()\n\n\tfor (const name of names) {\n\t\tconst hasCurrent = Object.hasOwn(current, name)\n\t\tconst hasOpened = Object.hasOwn(opened, name)\n\n\t\tif (hasCurrent !== hasOpened) {\n\t\t\tchanged.add(name)\n\t\t\tcontinue\n\t\t}\n\n\t\tconst now = current[name]\n\t\tconst before = opened[name]\n\t\tif (now === undefined || before === undefined || !matchesValue(now, before)) changed.add(name)\n\t}\n\n\treturn changed\n}\n\n/**\n * Compares two form value records by keys and value content.\n *\n * @param a - The first value record.\n * @param b - The second value record.\n * @returns True if both records contain the same answers; false otherwise.\n */\nexport function matchesValues(a: FormValues, b: FormValues): boolean {\n\treturn extractChanges(a, b).size === 0\n}\n\n/**\n * Resolves and interpolates one rule message.\n *\n * @param rule - The rule whose message to resolve.\n * @param limit - The optional operand substituted for `{limit}`.\n * @param messages - Optional rule-specific message replacements.\n * @returns The resolved failure text.\n */\nexport function formatMessage(\n\trule: FieldRuleName,\n\tlimit?: number | string,\n\tmessages?: Readonly<Partial<Record<FieldRuleName, string>>>,\n): string {\n\tconst message = messages?.[rule] ?? RULE_MESSAGES[rule]\n\treturn limit === undefined ? message : message.replaceAll('{limit}', String(limit))\n}\n\n/**\n * Creates one named-rule failure against a field.\n *\n * @param field - The field the rule failed on.\n * @param rule - The named rule that failed.\n * @param limit - The rule's operand, substituted for `{limit}`, or absence when it carries none.\n * @param messages - Optional rule-specific message replacements.\n * @returns A frozen {@link FieldError} carrying the field's name, the resolved text, and the rule.\n *\n * @remarks\n * A `custom` validator and the form's `invalidate` method both report a message of their own\n * under no rule name, so neither builds its failure here.\n *\n * @example\n * ```ts\n * const field: FormField = { control: 'text', name: 'nickname', rule: { minimum: 3 } }\n * const error = createFieldError(field, 'minimum', 3)\n * error.message // 'Must be at least 3'\n * ```\n */\nexport function createFieldError(\n\tfield: FormField,\n\trule: FieldRuleName,\n\tlimit: number | string | undefined,\n\tmessages?: Readonly<Partial<Record<FieldRuleName, string>>>,\n): FieldError {\n\treturn Object.freeze({ field: field.name, message: formatMessage(rule, limit, messages), rule })\n}\n\n/**\n * Projects a schema into JSON while removing custom validators and absent values.\n *\n * @param schema - The schema to project.\n * @returns A deep JSON copy of the serializable schema.\n * @throws A {@link FormError} coded `SCHEMA` when accessor-bearing metadata cannot be owned. A\n * non-contract throw while reading metadata escapes unchanged.\n */\nexport function serializeForm(schema: FormSchema): JSONRecord {\n\tconst output: Record<string, JSONValue> = {}\n\n\tif (schema.name !== undefined) output.name = schema.name\n\tif (schema.label !== undefined) output.label = schema.label\n\tif (schema.help !== undefined) output.help = schema.help\n\tif (schema.groups !== undefined) {\n\t\toutput.groups = schema.groups.map((group): JSONRecord => {\n\t\t\tconst entry: Record<string, JSONValue> = { name: group.name, label: group.label }\n\t\t\tif (group.help !== undefined) entry.help = group.help\n\t\t\treturn entry\n\t\t})\n\t}\n\n\toutput.fields = schema.fields.map((field): JSONRecord => {\n\t\tconst entry: Record<string, JSONValue> = {\n\t\t\tcontrol: field.control,\n\t\t\tname: field.name,\n\t\t}\n\n\t\tif (field.label !== undefined) entry.label = field.label\n\t\tif (field.help !== undefined) entry.help = field.help\n\t\tif (field.group !== undefined) entry.group = field.group\n\t\tif (field.hidden !== undefined) entry.hidden = field.hidden\n\t\tif (field.disabled !== undefined) entry.disabled = field.disabled\n\t\tif (field.locked !== undefined) entry.locked = field.locked\n\t\tconst meta = field.meta\n\t\tif (meta !== undefined) {\n\t\t\ttry {\n\t\t\t\tentry.meta = cloneJSONRecord(meta)\n\t\t\t} catch (error) {\n\t\t\t\tif (!isContractError(error)) throw error\n\t\t\t\tthrow new FormError('SCHEMA', `Field \"${field.name}\" has metadata that cannot be owned`, {\n\t\t\t\t\tfield: field.name,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tswitch (field.control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'number':\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tif (field.placeholder !== undefined) entry.placeholder = field.placeholder\n\t\t\t\tbreak\n\t\t\tcase 'password':\n\t\t\t\tif (field.mask !== undefined) entry.mask = field.mask\n\t\t\t\tbreak\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tbreak\n\t\t\tcase 'select':\n\t\t\t\tentry.choices = field.choices.map((choice): JSONRecord => {\n\t\t\t\t\tconst option: Record<string, JSONValue> = {\n\t\t\t\t\t\tvalue: choice.value,\n\t\t\t\t\t\tlabel: choice.label,\n\t\t\t\t\t}\n\t\t\t\t\tif (choice.help !== undefined) option.help = choice.help\n\t\t\t\t\tif (choice.disabled !== undefined) option.disabled = choice.disabled\n\t\t\t\t\treturn option\n\t\t\t\t})\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tif (field.open !== undefined) entry.open = field.open\n\t\t\t\tbreak\n\t\t\tcase 'checkbox':\n\t\t\t\tentry.choices = field.choices.map((choice): JSONRecord => {\n\t\t\t\t\tconst option: Record<string, JSONValue> = {\n\t\t\t\t\t\tvalue: choice.value,\n\t\t\t\t\t\tlabel: choice.label,\n\t\t\t\t\t}\n\t\t\t\t\tif (choice.help !== undefined) option.help = choice.help\n\t\t\t\t\tif (choice.disabled !== undefined) option.disabled = choice.disabled\n\t\t\t\t\treturn option\n\t\t\t\t})\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tbreak\n\t\t\tcase 'file':\n\t\t\t\tif (field.accept !== undefined) entry.accept = field.accept\n\t\t\t\tif (field.multiple !== undefined) entry.multiple = field.multiple\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (field.rule !== undefined) {\n\t\t\tconst rule: Record<string, JSONValue> = {}\n\n\t\t\tif (field.rule.required !== undefined) rule.required = field.rule.required\n\t\t\tif (field.rule.minimum !== undefined) rule.minimum = field.rule.minimum\n\t\t\tif (field.rule.maximum !== undefined) rule.maximum = field.rule.maximum\n\t\t\tif (field.rule.step !== undefined) rule.step = field.rule.step\n\t\t\tif (field.rule.pattern !== undefined) rule.pattern = field.rule.pattern\n\t\t\tif (field.rule.email !== undefined) rule.email = field.rule.email\n\t\t\tif (field.rule.url !== undefined) rule.url = field.rule.url\n\t\t\tif (field.rule.integer !== undefined) rule.integer = field.rule.integer\n\t\t\tif (field.rule.alphanumeric !== undefined) rule.alphanumeric = field.rule.alphanumeric\n\t\t\tif (Object.keys(rule).length > 0) entry.rule = rule\n\t\t}\n\n\t\treturn entry\n\t})\n\n\treturn cloneJSONRecord(output)\n}\n\n/**\n * Selects referenced groups in first-reference field order.\n *\n * @param schema - The schema whose group references to resolve.\n * @returns The referenced schema groups without duplicates.\n */\nexport function extractGroups(schema: FormSchema): readonly FormGroup[] {\n\tconst groups: FormGroup[] = []\n\n\tif (schema.groups === undefined) return Object.freeze(groups)\n\n\tfor (const field of schema.fields) {\n\t\tif (field.group !== undefined && !groups.some((group) => group.name === field.group)) {\n\t\t\tconst group = schema.groups.find((entry) => entry.name === field.group)\n\t\t\tif (group !== undefined) groups.push(group)\n\t\t}\n\t}\n\n\treturn Object.freeze(groups)\n}\n\n/**\n * Audits a structurally valid schema for domain invariants.\n *\n * @param schema - The form schema to audit.\n * @returns Human-readable invariant violations, or an empty list when the schema is sound.\n */\nexport function auditSchema(schema: FormSchema): readonly string[] {\n\tconst faults: string[] = []\n\tconst fields = new Set<string>()\n\tconst groups = new Set<string>()\n\tlet choiceExceeded: string | undefined\n\tlet nameExceeded = schema.name !== undefined && schema.name.length > NAME_LIMIT\n\n\tif (schema.fields.length > FIELD_LIMIT) {\n\t\tfaults.push(`Schema declares more than ${FIELD_LIMIT} fields`)\n\t}\n\tif (schema.groups !== undefined && schema.groups.length > GROUP_LIMIT) {\n\t\tfaults.push(`Schema declares more than ${GROUP_LIMIT} groups`)\n\t}\n\n\tif (schema.groups !== undefined) {\n\t\tconst count = Math.min(schema.groups.length, GROUP_LIMIT + 1)\n\t\tfor (let index = 0; index < count; index += 1) {\n\t\t\tconst group = schema.groups[index]\n\t\t\tif (group !== undefined && group.name.length > NAME_LIMIT) nameExceeded = true\n\t\t}\n\t}\n\n\tconst fieldCount = Math.min(schema.fields.length, FIELD_LIMIT + 1)\n\tfor (let index = 0; index < fieldCount; index += 1) {\n\t\tconst field = schema.fields[index]\n\t\tif (field === undefined) continue\n\n\t\tif (\n\t\t\tfield.name.length > NAME_LIMIT ||\n\t\t\t(field.group !== undefined && field.group.length > NAME_LIMIT)\n\t\t) {\n\t\t\tnameExceeded = true\n\t\t}\n\t\tif (\n\t\t\tchoiceExceeded === undefined &&\n\t\t\t(field.control === 'select' || field.control === 'checkbox') &&\n\t\t\tfield.choices.length > CHOICE_LIMIT\n\t\t) {\n\t\t\tchoiceExceeded = field.name\n\t\t}\n\t}\n\n\tif (choiceExceeded !== undefined) {\n\t\tfaults.push(`Field \"${choiceExceeded}\" offers more than ${CHOICE_LIMIT} choices`)\n\t}\n\tif (nameExceeded) faults.push(`Schema contains a name longer than ${NAME_LIMIT}`)\n\n\tconst pending: unknown[] = [schema]\n\tconst metadata: boolean[] = [false]\n\tlet position = 0\n\tlet stringExceeded = false\n\tlet textExceeded = false\n\tlet nodeExceeded = false\n\tlet text = 0\n\n\twhile (position < pending.length) {\n\t\tconst node = pending[position]\n\t\tconst inMeta = metadata[position] === true\n\t\tposition += 1\n\n\t\tif (isString(node)) {\n\t\t\tif (node.length > STRING_LIMIT) stringExceeded = true\n\t\t\ttext = Math.min(TEXT_LIMIT + 1, text + node.length)\n\t\t\tif (text > TEXT_LIMIT) textExceeded = true\n\t\t\tcontinue\n\t\t}\n\n\t\tif (isArray(node)) {\n\t\t\tconst length = attempt(() => node.length)\n\t\t\tif (!length.success || length.value > NODE_LIMIT - pending.length) {\n\t\t\t\tnodeExceeded = true\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst read = readArrayEntries(node)\n\t\t\tif (!read.success || !read.value.dense) continue\n\n\t\t\tfor (let index = 0; index < read.value.entries.length; index += 1) {\n\t\t\t\tconst entry = read.value.entries[index]\n\t\t\t\tif (entry !== undefined) {\n\t\t\t\t\tpending.push(entry)\n\t\t\t\t\tmetadata.push(inMeta)\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tif (!isRecord(node)) continue\n\n\t\tconst keys = attempt(() => Object.keys(node))\n\t\tif (!keys.success) continue\n\n\t\tfor (const key of keys.value) {\n\t\t\tif (inMeta) {\n\t\t\t\tif (key.length > STRING_LIMIT) stringExceeded = true\n\t\t\t\ttext = Math.min(TEXT_LIMIT + 1, text + key.length)\n\t\t\t\tif (text > TEXT_LIMIT) textExceeded = true\n\t\t\t}\n\n\t\t\tconst value = attempt(() => node[key])\n\t\t\tif (!value.success || value.value === undefined) continue\n\t\t\tif (pending.length >= NODE_LIMIT) {\n\t\t\t\tnodeExceeded = true\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tpending.push(value.value)\n\t\t\tmetadata.push(inMeta || key === 'meta')\n\t\t}\n\t}\n\n\tif (stringExceeded) faults.push(`Schema contains a string longer than ${STRING_LIMIT}`)\n\tif (textExceeded) faults.push(`Schema retains more than ${TEXT_LIMIT} string code units`)\n\tif (nodeExceeded) faults.push(`Schema retains more than ${NODE_LIMIT} nodes`)\n\n\tif (schema.groups !== undefined) {\n\t\tconst count = Math.min(schema.groups.length, GROUP_LIMIT + 1)\n\t\tfor (let index = 0; index < count; index += 1) {\n\t\t\tconst group = schema.groups[index]\n\t\t\tif (group === undefined) continue\n\t\t\tif (groups.has(group.name)) faults.push(`Group \"${group.name}\" is declared more than once`)\n\t\t\tgroups.add(group.name)\n\t\t}\n\t}\n\n\tfor (let fieldIndex = 0; fieldIndex < fieldCount; fieldIndex += 1) {\n\t\tconst field = schema.fields[fieldIndex]\n\t\tif (field === undefined) continue\n\t\tif (field.name.length === 0) faults.push('Field \"\" has an empty name')\n\t\tif (field.name === '__proto__') faults.push('Field \"__proto__\" has a refused name')\n\t\tif (fields.has(field.name)) faults.push(`Field \"${field.name}\" is declared more than once`)\n\t\tfields.add(field.name)\n\n\t\tif (field.group !== undefined && !groups.has(field.group)) {\n\t\t\tfaults.push(`Field \"${field.name}\" references missing group \"${field.group}\"`)\n\t\t}\n\n\t\tswitch (field.control) {\n\t\t\tcase 'password':\n\t\t\tcase 'file':\n\t\t\t\tbreak\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'number':\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\tcase 'checkbox':\n\t\t\t\tif (field.default !== undefined && !matchesField(field, field.default)) {\n\t\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid default`)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (field.control === 'select' || field.control === 'checkbox') {\n\t\t\tconst choices = new Set<string>()\n\t\t\tconst count = Math.min(field.choices.length, CHOICE_LIMIT + 1)\n\t\t\tlet enabled = 0\n\n\t\t\tfor (let index = 0; index < count; index += 1) {\n\t\t\t\tconst choice = field.choices[index]\n\t\t\t\tif (choice === undefined) continue\n\t\t\t\tif (choice.disabled !== true) enabled += 1\n\t\t\t\tif (choices.has(choice.value)) {\n\t\t\t\t\tfaults.push(`Field \"${field.name}\" offers choice \"${choice.value}\" more than once`)\n\t\t\t\t}\n\t\t\t\tchoices.add(choice.value)\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tfield.control === 'select' &&\n\t\t\t\tfield.rule?.required === true &&\n\t\t\t\tfield.open !== true &&\n\t\t\t\tenabled === 0\n\t\t\t) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" is required but offers no enabled choice`)\n\t\t\t}\n\n\t\t\tconst minimum = field.rule?.minimum\n\t\t\tif (\n\t\t\t\tfield.control === 'checkbox' &&\n\t\t\t\tisFiniteNumber(minimum) &&\n\t\t\t\tminimum > 0 &&\n\t\t\t\tminimum > enabled\n\t\t\t) {\n\t\t\t\tfaults.push(\n\t\t\t\t\t`Field \"${field.name}\" has minimum ${minimum} but offers only ${enabled} enabled ${enabled === 1 ? 'choice' : 'choices'}`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tconst rule = field.rule\n\t\tif (rule === undefined) continue\n\n\t\tconst temporal =\n\t\t\tfield.control === 'date' || field.control === 'time' || field.control === 'datetime'\n\t\tif (rule.minimum !== undefined && !appliesRule(field.control, 'minimum')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has minimum on ${field.control}`)\n\t\t} else if (isString(rule.minimum) && !temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a string minimum on ${field.control}`)\n\t\t}\n\t\tif (rule.maximum !== undefined && !appliesRule(field.control, 'maximum')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has maximum on ${field.control}`)\n\t\t} else if (isString(rule.maximum) && !temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a string maximum on ${field.control}`)\n\t\t}\n\t\tif (isFiniteNumber(rule.minimum) && temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a numeric minimum on ${field.control}`)\n\t\t}\n\t\tif (isFiniteNumber(rule.maximum) && temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a numeric maximum on ${field.control}`)\n\t\t}\n\t\tif (\n\t\t\tisFiniteNumber(rule.maximum) &&\n\t\t\trule.maximum < 0 &&\n\t\t\t(field.control === 'text' ||\n\t\t\t\tfield.control === 'editor' ||\n\t\t\t\tfield.control === 'password' ||\n\t\t\t\tfield.control === 'checkbox' ||\n\t\t\t\tfield.control === 'file')\n\t\t) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a negative maximum on ${field.control}`)\n\t\t}\n\n\t\tif (rule.step !== undefined && !appliesRule(field.control, 'step')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has step on ${field.control}`)\n\t\t}\n\t\tif (rule.step !== undefined && rule.step <= 0) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a non-positive step`)\n\t\t}\n\n\t\tif (rule.pattern !== undefined && !appliesRule(field.control, 'pattern')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has pattern on ${field.control}`)\n\t\t}\n\t\tif (rule.email === true && !appliesRule(field.control, 'email')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has email on ${field.control}`)\n\t\t}\n\t\tif (rule.url === true && !appliesRule(field.control, 'url')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has url on ${field.control}`)\n\t\t}\n\t\tif (rule.alphanumeric === true && !appliesRule(field.control, 'alphanumeric')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has alphanumeric on ${field.control}`)\n\t\t}\n\t\tif (rule.integer === true && !appliesRule(field.control, 'integer')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has integer on ${field.control}`)\n\t\t}\n\n\t\tif (rule.pattern !== undefined) {\n\t\t\tif (rule.pattern.length > PATTERN_LIMIT) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has a pattern longer than ${PATTERN_LIMIT}`)\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tRegExp(rule.pattern)\n\t\t\t\t} catch {\n\t\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid pattern`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t(isFiniteNumber(rule.minimum) &&\n\t\t\t\tisFiniteNumber(rule.maximum) &&\n\t\t\t\trule.minimum > rule.maximum) ||\n\t\t\t(isString(rule.minimum) && isString(rule.maximum) && rule.minimum > rule.maximum)\n\t\t) {\n\t\t\tfaults.push(`Field \"${field.name}\" has minimum greater than maximum`)\n\t\t}\n\n\t\tif (field.control === 'date') {\n\t\t\tif (isString(rule.minimum) && !DATE_PATTERN.test(rule.minimum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid date minimum`)\n\t\t\t}\n\t\t\tif (isString(rule.maximum) && !DATE_PATTERN.test(rule.maximum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid date maximum`)\n\t\t\t}\n\t\t}\n\n\t\tif (field.control === 'time') {\n\t\t\tif (isString(rule.minimum) && !TIME_PATTERN.test(rule.minimum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid time minimum`)\n\t\t\t}\n\t\t\tif (isString(rule.maximum) && !TIME_PATTERN.test(rule.maximum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid time maximum`)\n\t\t\t}\n\t\t}\n\n\t\tif (field.control === 'datetime') {\n\t\t\tif (isString(rule.minimum) && !DATETIME_PATTERN.test(rule.minimum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid datetime minimum`)\n\t\t\t}\n\t\t\tif (isString(rule.maximum) && !DATETIME_PATTERN.test(rule.maximum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid datetime maximum`)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Object.freeze(faults)\n}\n","import type { FieldValue, FormField, FormSchema, FormValues } from './types.js'\nimport {\n\tattempt,\n\tisArray,\n\tisRecord,\n\tisString,\n\tparseNumber,\n\treadArrayEntries,\n} from '@orkestrel/contract'\nimport { cloneValue } from './cloners.js'\nimport { STRING_LIMIT } from './constants.js'\nimport { auditSchema, defineEntry, freezeEntry, matchesField, serializeForm } from './helpers.js'\nimport { isFormSchema } from './validators.js'\n\n/**\n * Parses unknown wire data into an owned, semantically sound form schema.\n *\n * @param input - The unknown schema value to parse.\n * @returns An owned schema with custom rules removed, or `undefined` on refusal.\n */\nexport function parseForm(input: unknown): FormSchema | undefined {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input)) return undefined\n\n\t\tconst schema: Record<string, unknown> = {}\n\t\tfor (const key of Reflect.ownKeys(input)) {\n\t\t\tif (!isString(key)) return undefined\n\t\t\tdefineEntry(schema, key, input[key])\n\t\t}\n\n\t\tconst fields = schema.fields\n\t\tif (!isArray(fields)) return undefined\n\n\t\tconst read = readArrayEntries(fields)\n\t\tif (!read.success || !read.value.dense) return undefined\n\n\t\tconst copies: unknown[] = []\n\t\tfor (let index = 0; index < read.value.entries.length; index += 1) {\n\t\t\tconst field = read.value.entries[index]\n\t\t\tif (!isRecord(field)) {\n\t\t\t\tcopies.push(field)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst copy: Record<string, unknown> = {}\n\t\t\tfor (const key of Reflect.ownKeys(field)) {\n\t\t\t\tif (!isString(key)) return undefined\n\t\t\t\tdefineEntry(copy, key, field[key])\n\t\t\t}\n\n\t\t\tconst rule = copy.rule\n\t\t\tif (isRecord(rule)) {\n\t\t\t\tconst projected: Record<string, unknown> = {}\n\t\t\t\tfor (const key of Reflect.ownKeys(rule)) {\n\t\t\t\t\tif (!isString(key)) return undefined\n\t\t\t\t\tif (key !== 'custom') {\n\t\t\t\t\t\tdefineEntry(projected, key, rule[key])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcopy.rule = projected\n\t\t\t}\n\n\t\t\tcopies.push(copy)\n\t\t}\n\n\t\tschema.fields = copies\n\t\tif (!isFormSchema(schema) || auditSchema(schema).length !== 0) return undefined\n\n\t\tconst parsed = serializeForm(schema)\n\t\treturn isFormSchema(parsed) && auditSchema(parsed).length === 0 ? parsed : undefined\n\t})\n\n\treturn outcome.success ? outcome.value : undefined\n}\n\n/**\n * Parses one answer against its field control.\n *\n * @param field - The field that defines the accepted value.\n * @param input - The unknown value to parse.\n * @returns The typed or lexically coerced field value, or `undefined` on refusal.\n */\nexport function parseValue(field: FormField, input: unknown): FieldValue | undefined {\n\tconst outcome = attempt(() => {\n\t\tif (matchesField(field, input)) return cloneValue(input)\n\t\tif (field.control === 'number') {\n\t\t\tif (isString(input) && input.length > STRING_LIMIT) return undefined\n\t\t\tconst value = parseNumber(input)\n\t\t\treturn value !== undefined && matchesField(field, value) ? value : undefined\n\t\t}\n\t\tif (field.control === 'confirm') {\n\t\t\tif (input === 'true') return true\n\t\t\tif (input === 'false') return false\n\t\t}\n\t\treturn undefined\n\t})\n\n\treturn outcome.success ? outcome.value : undefined\n}\n\n/**\n * Parses a strict answer record against the fields declared by a schema.\n *\n * @param schema - The schema that owns the accepted field names and controls.\n * @param input - The unknown answer record to parse.\n * @returns An owned answer record, or `undefined` when any key or value is refused.\n */\nexport function parseValues(schema: FormSchema, input: unknown): FormValues | undefined {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input)) return undefined\n\n\t\tconst values: Record<string, FieldValue> = {}\n\t\tfor (const key of Reflect.ownKeys(input)) {\n\t\t\tif (!isString(key) || !Object.hasOwn(input, key)) return undefined\n\n\t\t\tconst field = schema.fields.find((candidate) => candidate.name === key)\n\t\t\tif (field === undefined) return undefined\n\n\t\t\tconst value = parseValue(field, input[key])\n\t\t\tif (value === undefined) return undefined\n\n\t\t\tfreezeEntry(values, key, value)\n\t\t}\n\n\t\treturn Object.freeze(values)\n\t})\n\n\treturn outcome.success ? outcome.value : undefined\n}\n","import type { EmitterInterface } from '@orkestrel/emitter'\nimport type {\n\tFieldError,\n\tFieldRuleName,\n\tFieldValue,\n\tFormEventMap,\n\tFormField,\n\tFormInterface,\n\tFormOptions,\n\tFormResult,\n\tFormSchema,\n\tFormStatus,\n\tFormValues,\n} from './types.js'\nimport { attempt, isString } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { cloneFormSchema, cloneValue } from './cloners.js'\nimport { FormError, isFormError } from './errors.js'\nimport {\n\tauditSchema,\n\tcomputeDefaults,\n\tdefineEntry,\n\tevaluateForm,\n\tmatchesField,\n\tmatchesValue,\n\tmatchesValues,\n} from './helpers.js'\nimport { isFormSchema } from './validators.js'\n\n/**\n * Represents a form: a schema, the answers given against it, and the errors they carry.\n *\n * @remarks\n * The form owns its schema, so a later edit to the schema the caller passed changes nothing here.\n *\n * `errors` is recomputed at construction and after every mutation whose evaluation completes,\n * and the `validate` event fires exactly when that list's content changes. A throwing custom\n * validator escapes after any preceding state changes and leaves the prior error list in place.\n * There is no separate check.\n *\n * `valid` and `dirty` are derived on read from the error list and answers respectively, never\n * stored.\n *\n * @example\n * ```ts\n * const form = new Form({\n * \tfields: [{ control: 'text', name: 'email', rule: { required: true, email: true } }],\n * })\n *\n * form.fill('email', 'ada@example.com')\n * const result = form.submit()\n * if (result.success) await form.answer\n * ```\n */\nexport class Form implements FormInterface {\n\treadonly #emitter: Emitter<FormEventMap>\n\treadonly #schema: FormSchema\n\treadonly #messages: Readonly<Partial<Record<FieldRuleName, string>>> | undefined\n\treadonly #baseline: FormValues\n\treadonly #values: Record<string, FieldValue>\n\treadonly #touched = new Set<string>()\n\treadonly #disabled = new Map<string, boolean>()\n\treadonly #invalidations = new Map<string, string>()\n\treadonly #resolvers = Promise.withResolvers<FormValues>()\n\t#errors: readonly FieldError[] = Object.freeze([])\n\t#status: FormStatus = 'editing'\n\t#batchDepth = 0\n\t#evaluation = 0\n\t#pending = false\n\n\t/**\n\t * Opens a form against a schema.\n\t *\n\t * @param schema - The form to ask. It is copied, and the copy is what the form asks.\n\t * @param options - The form's settings.\n\t * @throws A {@link FormError} coded `SCHEMA` when the schema is malformed, `FIELD` when\n\t * `options.values` names a field the schema does not declare, and `CONTROL` when a seeded\n\t * value is one its field's control cannot hold.\n\t */\n\tconstructor(schema: FormSchema, options?: FormOptions) {\n\t\t// Own the schema before reading it, so the guard, the audit, and every later read see one\n\t\t// copy this form holds rather than an object the caller can still answer differently on\n\t\t// each read. `parseForm` takes the same clone-then-guard order at the wire boundary.\n\t\tconst owned = attempt(() => cloneFormSchema(schema))\n\t\tif (!owned.success && isFormError(owned.error)) throw owned.error\n\n\t\tconst copy = owned.success && isFormSchema(owned.value) ? owned.value : undefined\n\t\tconst problems = copy === undefined ? ['The schema is not a form schema'] : auditSchema(copy)\n\n\t\tif (copy === undefined || problems.length > 0) {\n\t\t\tthrow new FormError('SCHEMA', `The form schema is unusable: ${problems.join('; ')}`, {\n\t\t\t\tproblems: [...problems],\n\t\t\t})\n\t\t}\n\n\t\tthis.#schema = copy\n\t\tthis.#messages =\n\t\t\toptions?.messages === undefined ? undefined : Object.freeze({ ...options.messages })\n\n\t\tconst baseline: Record<string, FieldValue> = {}\n\n\t\tfor (const [name, value] of Object.entries(computeDefaults(this.#schema))) {\n\t\t\tdefineEntry(baseline, name, value)\n\t\t}\n\n\t\tfor (const [name, value] of Object.entries(options?.values ?? {})) {\n\t\t\tconst field = this.#requireField(name)\n\n\t\t\tif (!matchesField(field, value)) {\n\t\t\t\tthrow new FormError(\n\t\t\t\t\t'CONTROL',\n\t\t\t\t\t`The ${field.control} field \"${name}\" cannot hold that value`,\n\t\t\t\t\t{ field: name, control: field.control },\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tdefineEntry(baseline, name, cloneValue(value))\n\t\t}\n\n\t\tthis.#baseline = Object.freeze(baseline)\n\t\tthis.#values = {}\n\t\tfor (const [name, value] of Object.entries(baseline)) {\n\t\t\tdefineEntry(this.#values, name, value)\n\t\t}\n\t\t// Nobody has to await `answer`. Without a rejection handler of its own, destroying an\n\t\t// unawaited form would reject a promise no one is watching and take the host down with it.\n\t\tthis.#resolvers.promise.catch(() => undefined)\n\t\t// FormOptions carries `on` and `error` exactly as EmitterOptions declares them, so passing\n\t\t// the options through threads both without rebuilding a record `exactOptionalPropertyTypes`\n\t\t// would then reject for its explicit `undefined` members.\n\t\tthis.#emitter = new Emitter<FormEventMap>(options)\n\t\tthis.#evaluate()\n\t}\n\n\t/** Holds the form's event emitter. */\n\tget emitter(): EmitterInterface<FormEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Holds the schema this form asks, owned and frozen. */\n\tget schema(): FormSchema {\n\t\treturn this.#schema\n\t}\n\n\t/** Reports the answers the form holds. */\n\tget values(): FormValues {\n\t\tconst values: Record<string, FieldValue> = {}\n\n\t\t// Object.entries reads the own enumerable answer population; clear() walks the same one\n\t\t// through Object.keys.\n\t\tfor (const [name, value] of Object.entries(this.#values)) {\n\t\t\tdefineEntry(values, name, value)\n\t\t}\n\n\t\treturn Object.freeze(values)\n\t}\n\n\t/** Holds the answers the form opened with. */\n\tget baseline(): FormValues {\n\t\treturn this.#baseline\n\t}\n\n\t/** Holds every error the last completed evaluation produced. */\n\tget errors(): readonly FieldError[] {\n\t\treturn this.#errors\n\t}\n\n\t/** Lists the names of the fields somebody has visited. */\n\tget touched(): ReadonlySet<string> {\n\t\treturn new Set(this.#touched)\n\t}\n\n\t/** Lists the names of the fields that are out of the form. */\n\tget disabled(): ReadonlySet<string> {\n\t\tconst disabled = new Set<string>()\n\n\t\tfor (const field of this.#schema.fields) {\n\t\t\tif ((this.#disabled.get(field.name) ?? field.disabled === true) === true) {\n\t\t\t\tdisabled.add(field.name)\n\t\t\t}\n\t\t}\n\n\t\treturn disabled\n\t}\n\n\t/** Reports where the form sits in its life. */\n\tget status(): FormStatus {\n\t\treturn this.#status\n\t}\n\n\t/** Reports whether the last completed evaluation found no error. */\n\tget valid(): boolean {\n\t\treturn this.#errors.length === 0\n\t}\n\n\t/** Reports whether any answer has moved since the form opened. */\n\tget dirty(): boolean {\n\t\treturn !matchesValues(this.values, this.#baseline)\n\t}\n\n\t/**\n\t * Holds the answers after the form settles.\n\t *\n\t * @remarks\n\t * It resolves with the submitted values on the first valid submit, and rejects with a\n\t * {@link FormError} coded `ABANDONED` when teardown abandons the form before it settles.\n\t */\n\tget answer(): Promise<FormValues> {\n\t\treturn this.#resolvers.promise\n\t}\n\n\t/**\n\t * Finds one field by name.\n\t *\n\t * @param name - The field's name.\n\t * @returns The field, or `undefined` when the schema declares no such name.\n\t */\n\tfield(name: string): FormField | undefined {\n\t\treturn this.#schema.fields.find((field) => field.name === name)\n\t}\n\n\t/**\n\t * Answers several fields at once.\n\t *\n\t * @param values - The answers to write, each keyed by its field name.\n\t */\n\tfill(values: FormValues): void\n\t/**\n\t * Answers one field.\n\t *\n\t * @param name - The field's name.\n\t * @param value - The answer to write, or `undefined` to clear it.\n\t */\n\tfill(name: string, value: FieldValue | undefined): void\n\t/**\n\t * Answers one field or several.\n\t *\n\t * @param input - One field's name, or the answers to write keyed by field name.\n\t * @param value - The answer to write when `input` names one field.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, `FIELD`\n\t * when a name is not declared, and `CONTROL` when a value is one its control cannot hold.\n\t * Every answer is checked before any is written, so a refused write changes nothing.\n\t */\n\tfill(input: FormValues | string, value?: FieldValue): void {\n\t\tthis.#gate()\n\n\t\tconst entries: ReadonlyArray<readonly [string, FieldValue | undefined]> = isString(input)\n\t\t\t? [[input, value]]\n\t\t\t: Object.entries(input)\n\n\t\tfor (const [name, answer] of entries) {\n\t\t\tconst field = this.#requireField(name)\n\n\t\t\tif (answer !== undefined && !matchesField(field, answer)) {\n\t\t\t\tthrow new FormError(\n\t\t\t\t\t'CONTROL',\n\t\t\t\t\t`The ${field.control} field \"${name}\" cannot hold that value`,\n\t\t\t\t\t{ field: name, control: field.control },\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tthis.#batch(() => {\n\t\t\tconst moved: string[] = []\n\n\t\t\tfor (const [name, answer] of entries) {\n\t\t\t\tif (this.#differs(name, answer)) moved.push(name)\n\t\t\t\tif (answer === undefined) delete this.#values[name]\n\t\t\t\telse {\n\t\t\t\t\tdefineEntry(this.#values, name, cloneValue(answer))\n\t\t\t\t}\n\t\t\t\tthis.#invalidations.delete(name)\n\t\t\t}\n\n\t\t\tfor (const name of moved) {\n\t\t\t\tconst answer = Object.hasOwn(this.#values, name) ? this.#values[name] : undefined\n\t\t\t\tthis.#emitter.emit('fill', name, answer)\n\t\t\t}\n\t\t\tif (this.#evaluate()) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t/**\n\t * Records that somebody has visited a field.\n\t *\n\t * @param name - The field's name.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no such name.\n\t */\n\ttouch(name: string): void {\n\t\tthis.#gate()\n\t\tthis.#requireField(name)\n\t\tthis.#touched.add(name)\n\t}\n\n\t/**\n\t * Fails a field from outside, for what the rules cannot see.\n\t *\n\t * @param name - The field's name.\n\t * @param message - What to tell the person.\n\t * @remarks\n\t * One field holds one external failure: a second call replaces the first. The failure lasts\n\t * until that field is filled again or the form is cleared.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no such name.\n\t */\n\tinvalidate(name: string, message: string): void {\n\t\tthis.#gate()\n\t\tthis.#requireField(name)\n\t\tthis.#batch(() => {\n\t\t\tthis.#invalidations.set(name, message)\n\t\t\tif (this.#evaluate()) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t/** Takes every field out of the form. */\n\tdisable(): void\n\t/**\n\t * Takes one field out of the form.\n\t *\n\t * @param name - The field's name.\n\t */\n\tdisable(name: string): void\n\t/**\n\t * Takes several fields out of the form.\n\t *\n\t * @param names - The field names.\n\t */\n\tdisable(names: readonly string[]): void\n\t/**\n\t * Takes one or more fields out of the form.\n\t *\n\t * @param input - One field name, several names, or absence to select every field.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no requested name. Every name is checked before any field\n\t * moves.\n\t */\n\tdisable(input?: string | readonly string[]): void {\n\t\tthis.#gate()\n\t\tthis.#change(input, true)\n\t}\n\n\t/** Puts every field back into the form. */\n\tenable(): void\n\t/**\n\t * Puts one field back into the form.\n\t *\n\t * @param name - The field's name.\n\t */\n\tenable(name: string): void\n\t/**\n\t * Puts several fields back into the form.\n\t *\n\t * @param names - The field names.\n\t */\n\tenable(names: readonly string[]): void\n\t/**\n\t * Puts one or more fields back into the form.\n\t *\n\t * @param input - One field name, several names, or absence to select every field.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no requested name. Every name is checked before any field\n\t * moves.\n\t */\n\tenable(input?: string | readonly string[]): void {\n\t\tthis.#gate()\n\t\tthis.#change(input, false)\n\t}\n\n\t/**\n\t * Checks every answer and settles the form when they all pass.\n\t *\n\t * @returns The values on success, or every error that stopped them.\n\t * @remarks\n\t * A failed submit marks every enabled field touched, so a renderer can show the errors the\n\t * person has not reached yet. A disabled field is neither checked nor submitted. When a changed\n\t * evaluation notifies listeners and a listener writes, submit evaluates once more after those\n\t * listeners return and decides from that state. Listener work that settled the form wins: that\n\t * settlement is what this call returns, with no further evaluation, resolution, or `submit`\n\t * emission. An evaluation that already failed refuses with the list it checked, even when a\n\t * listener repaired or disabled the field that failed. An evaluation that passed decides from the\n\t * state the drain left, which is why one further evaluation bounds the drain rather than a\n\t * fixpoint loop.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended.\n\t */\n\tsubmit(): FormResult {\n\t\tthis.#gate()\n\n\t\treturn this.#batch(() => {\n\t\t\tconst changed = this.#evaluate()\n\t\t\tconst checked = this.#errors\n\t\t\tconst failed = checked.length > 0\n\t\t\tconst evaluation = this.#evaluation\n\n\t\t\tif (changed) {\n\t\t\t\tthis.#emitter.emit('validate', this.#errors)\n\t\t\t\tconst settlement = this.#readSettlement()\n\t\t\t\tif (settlement !== undefined) return settlement\n\t\t\t\tif (this.#evaluation !== evaluation && this.#evaluate()) {\n\t\t\t\t\tthis.#emitter.emit('validate', this.#errors)\n\t\t\t\t\tconst drained = this.#readSettlement()\n\t\t\t\t\tif (drained !== undefined) return drained\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst errors = failed ? checked : this.#errors\n\t\t\tconst stopped = errors.length > 0\n\n\t\t\tif (stopped) {\n\t\t\t\tconst disabled = this.disabled\n\t\t\t\tfor (const field of this.#schema.fields) {\n\t\t\t\t\tif (!disabled.has(field.name)) this.#touched.add(field.name)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (stopped) return { success: false, error: errors }\n\n\t\t\tconst answers = this.#snapshot()\n\t\t\tthis.#status = 'settled'\n\t\t\tthis.#resolvers.resolve(answers)\n\t\t\tthis.#emitter.emit('submit', answers)\n\n\t\t\treturn { success: true, value: answers }\n\t\t})\n\t}\n\n\t/**\n\t * Returns every answer to the ones the form opened with: the schema's defaults, overlaid with\n\t * any seeded `values`. Reset the runtime disabled state to the schema's declarations.\n\t *\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended.\n\t */\n\tclear(): void {\n\t\tthis.#gate()\n\n\t\tthis.#batch(() => {\n\t\t\tfor (const name of Object.keys(this.#values)) delete this.#values[name]\n\t\t\tfor (const [name, value] of Object.entries(this.#baseline)) {\n\t\t\t\tdefineEntry(this.#values, name, value)\n\t\t\t}\n\n\t\t\tthis.#touched.clear()\n\t\t\tthis.#disabled.clear()\n\t\t\tthis.#invalidations.clear()\n\n\t\t\tconst changed = this.#evaluate()\n\n\t\t\tthis.#emitter.emit('clear')\n\t\t\tif (changed) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t/**\n\t * Tears the form down, abandoning it when it has not settled.\n\t *\n\t * @remarks\n\t * Destroying twice does nothing the second time. A settled form keeps its `settled` status and\n\t * announces nothing. A request from inside a listener defers teardown until the outermost\n\t * mutation batch closes, so an in-flight settlement can win and leave the form `settled` rather\n\t * than `abandoned`. Every getter keeps answering afterwards; every write is refused.\n\t */\n\tdestroy(): void {\n\t\tif (this.#pending) return\n\n\t\tthis.#pending = true\n\t\tif (this.#batchDepth === 0) this.#teardown()\n\t}\n\n\t// Refuse a write to a form that settled before considering whether teardown was requested.\n\t#gate(): void {\n\t\tif (this.#status === 'settled') {\n\t\t\tthrow new FormError('SETTLED', 'The form has settled and cannot change')\n\t\t}\n\t\tif (this.#status === 'abandoned' || this.#pending) {\n\t\t\tthrow new FormError('ABANDONED', 'The form was abandoned and cannot change')\n\t\t}\n\t}\n\n\t#requireField(name: string): FormField {\n\t\tconst field = this.field(name)\n\n\t\tif (field === undefined) {\n\t\t\tthrow new FormError('FIELD', `The schema declares no field named \"${name}\"`, {\n\t\t\t\tfield: name,\n\t\t\t})\n\t\t}\n\n\t\treturn field\n\t}\n\n\t#change(input: string | readonly string[] | undefined, disabled: boolean): void {\n\t\tconst names = new Set(\n\t\t\tinput === undefined\n\t\t\t\t? this.#schema.fields.map((field) => field.name)\n\t\t\t\t: isString(input)\n\t\t\t\t\t? [input]\n\t\t\t\t\t: input,\n\t\t)\n\n\t\tfor (const name of names) this.#requireField(name)\n\n\t\tconst moved: string[] = []\n\t\tfor (const field of this.#schema.fields) {\n\t\t\tconst active = names.has(field.name)\n\t\t\tconst current = this.#disabled.get(field.name) ?? field.disabled === true\n\t\t\tif (active && current !== disabled) moved.push(field.name)\n\t\t}\n\t\tif (moved.length === 0) return\n\n\t\tthis.#batch(() => {\n\t\t\tfor (const name of names) this.#disabled.set(name, disabled)\n\n\t\t\tfor (const name of moved) {\n\t\t\t\tif (disabled) this.#emitter.emit('disable', name)\n\t\t\t\telse this.#emitter.emit('enable', name)\n\t\t\t}\n\n\t\t\tif (this.#evaluate()) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t// Recompute the whole error list and cache it, reporting whether its content moved.\n\t#evaluate(): boolean {\n\t\tconst disabled = this.disabled\n\t\tconst options =\n\t\t\tthis.#messages === undefined ? { disabled } : { messages: this.#messages, disabled }\n\t\tconst errors: FieldError[] = [...evaluateForm(this.#schema, this.values, options)]\n\n\t\tfor (const [field, message] of this.#invalidations) {\n\t\t\tif (!disabled.has(field)) {\n\t\t\t\terrors.push(Object.freeze({ field, message }))\n\t\t\t}\n\t\t}\n\n\t\tconst previous = this.#errors\n\t\tconst next: readonly FieldError[] = Object.freeze(errors)\n\t\tthis.#errors = next\n\n\t\tconst changed =\n\t\t\tnext.length !== previous.length ||\n\t\t\tnext.some((error, index) => {\n\t\t\t\tconst before = previous[index]\n\t\t\t\treturn (\n\t\t\t\t\tbefore === undefined ||\n\t\t\t\t\tbefore.field !== error.field ||\n\t\t\t\t\tbefore.message !== error.message ||\n\t\t\t\t\tbefore.rule !== error.rule\n\t\t\t\t)\n\t\t\t})\n\t\tthis.#evaluation += 1\n\t\treturn changed\n\t}\n\n\t#differs(name: string, value: FieldValue | undefined): boolean {\n\t\tconst current = Object.hasOwn(this.#values, name) ? this.#values[name] : undefined\n\n\t\tif (value === undefined) return current !== undefined\n\t\tif (current === undefined) return true\n\t\treturn !matchesValue(current, value)\n\t}\n\n\t#readSettlement(): FormResult | undefined {\n\t\tif (this.#status === 'settled') return { success: true, value: this.#snapshot() }\n\t\tif (this.#status === 'abandoned') this.#gate()\n\t\treturn undefined\n\t}\n\n\t// The answers a submit hands over: every enabled field somebody has answered.\n\t#snapshot(): FormValues {\n\t\tconst answers: Record<string, FieldValue> = {}\n\t\tconst disabled = this.disabled\n\n\t\tfor (const field of this.#schema.fields) {\n\t\t\tconst value = Object.hasOwn(this.#values, field.name) ? this.#values[field.name] : undefined\n\t\t\tif (!disabled.has(field.name) && value !== undefined) {\n\t\t\t\tdefineEntry(answers, field.name, value)\n\t\t\t}\n\t\t}\n\n\t\treturn Object.freeze(answers)\n\t}\n\n\t#batch<T>(callback: () => T): T {\n\t\tthis.#batchDepth += 1\n\n\t\ttry {\n\t\t\treturn callback()\n\t\t} finally {\n\t\t\tthis.#batchDepth -= 1\n\t\t\tif (this.#batchDepth === 0 && this.#pending) this.#teardown()\n\t\t}\n\t}\n\n\t#teardown(): void {\n\t\tif (this.#status === 'editing') {\n\t\t\tthis.#status = 'abandoned'\n\t\t\tthis.#resolvers.reject(new FormError('ABANDONED', 'The form was destroyed before it settled'))\n\t\t\tthis.#emitter.emit('abandon')\n\t\t}\n\n\t\tthis.#emitter.destroy()\n\t}\n}\n","import type { FormInterface, FormOptions, FormSchema } from './types.js'\nimport { Form } from './Form.js'\n\n/**\n * Opens a form against a schema.\n *\n * @param schema - The form to ask. It is copied, and the copy is what the form asks.\n * @param options - The form's settings.\n * @returns A form open for answers.\n * @remarks\n * Prefer this at a call site that only needs {@link FormInterface}. `new Form(...)` is the same\n * construction and is what a class holding a form as its own field reaches for.\n * @throws A {@link FormError} coded `SCHEMA` when the schema is malformed, `FIELD` when\n * `options.values` names a field the schema does not declare, and `CONTROL` when a seeded value\n * is one its field's control cannot hold.\n * @example\n * ```ts\n * const form = createForm({\n * \tlabel: 'Sign up',\n * \tfields: [\n * \t\t{ control: 'text', name: 'email', label: 'Email', rule: { required: true, email: true } },\n * \t\t{ control: 'confirm', name: 'terms', label: 'I accept the terms', rule: { required: true } },\n * \t],\n * })\n *\n * form.fill({ email: 'ada@example.com', terms: true })\n * form.submit() // { success: true, value: { email: 'ada@example.com', terms: true } }\n * ```\n */\nexport function createForm(schema: FormSchema, options?: FormOptions): FormInterface {\n\treturn new Form(schema, options)\n}\n"],"mappings":";;;;;AAGA,IAAa,iBAA0C,OAAO,OAAO;CACpE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,IAAa,kBAAqC,OAAO,OAAO;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;AAMD,IAAa,aAAgE,OAAO,OAAO;CAC1F,MAAM,OAAO,OAAO;EAAC,GAAG;EAAiB;EAAW;CAAa,CAAC;CAClE,QAAQ,OAAO,OAAO;EAAC,GAAG;EAAiB;EAAW;CAAa,CAAC;CACpE,UAAU,OAAO,OAAO,CAAC,GAAG,iBAAiB,MAAM,CAAC;CACpD,QAAQ,OAAO,OAAO;EAAC,GAAG;EAAiB;EAAW;CAAa,CAAC;CACpE,MAAM,OAAO,OAAO,CAAC,GAAG,iBAAiB,SAAS,CAAC;CACnD,MAAM,OAAO,OAAO,CAAC,GAAG,iBAAiB,SAAS,CAAC;CACnD,UAAU,OAAO,OAAO,CAAC,GAAG,iBAAiB,SAAS,CAAC;CACvD,OAAO,OAAO,OAAO,CAAC,GAAG,iBAAiB,SAAS,CAAC;CACpD,SAAS,OAAO,OAAO,CAAC,GAAG,iBAAiB,SAAS,CAAC;CACtD,QAAQ,OAAO,OAAO;EAAC,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AAU;GACT,KAAKA,eAAe;GACpB,IAAI,KAAKA,gBAAgB,KAAK,KAAKD,UAAU,KAAKE,UAAU;EAC7D;CACD;CAEA,YAAkB;EACjB,IAAI,KAAKV,YAAY,WAAW;GAC/B,KAAKA,UAAU;GACf,KAAKJ,WAAW,OAAO,IAAI,UAAU,aAAa,0CAA0C,CAAC;GAC7F,KAAKR,SAAS,KAAK,SAAS;EAC7B;EAEA,KAAKA,SAAS,QAAQ;CACvB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC7jBA,SAAgB,WAAW,QAAoB,SAAsC;CACpF,OAAO,IAAI,KAAK,QAAQ,OAAO;AAChC"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/core/constants.ts","../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/cloners.ts","../../../src/core/helpers.ts","../../../src/core/parsers.ts","../../../src/core/Form.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { FieldControl, FieldRuleName, FormStatus } from './types.js'\n\n/** Lists every field control, in the order declared by the public contract. */\nexport const FIELD_CONTROLS: readonly FieldControl[] = Object.freeze([\n\t'text',\n\t'editor',\n\t'password',\n\t'number',\n\t'date',\n\t'time',\n\t'datetime',\n\t'color',\n\t'confirm',\n\t'select',\n\t'checkbox',\n\t'file',\n])\n\n/** Lists the members every field declares, whatever its control. */\nexport const FIELD_BASE_KEYS: readonly string[] = Object.freeze([\n\t'control',\n\t'name',\n\t'label',\n\t'help',\n\t'group',\n\t'hidden',\n\t'disabled',\n\t'locked',\n\t'rule',\n\t'meta',\n])\n\n/**\n * Lists every member one field control permits, composed from {@link FIELD_BASE_KEYS} and the\n * members the control's own interface adds.\n */\nexport const FIELD_KEYS: Readonly<Record<FieldControl, readonly string[]>> = Object.freeze({\n\ttext: Object.freeze([...FIELD_BASE_KEYS, 'default', 'placeholder']),\n\teditor: Object.freeze([...FIELD_BASE_KEYS, 'default', 'placeholder']),\n\tpassword: Object.freeze([...FIELD_BASE_KEYS, 'mask']),\n\tnumber: Object.freeze([...FIELD_BASE_KEYS, 'default', 'placeholder']),\n\tdate: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\ttime: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tdatetime: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tcolor: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tconfirm: Object.freeze([...FIELD_BASE_KEYS, 'default']),\n\tselect: Object.freeze([...FIELD_BASE_KEYS, 'choices', 'default', 'open']),\n\tcheckbox: Object.freeze([...FIELD_BASE_KEYS, 'choices', 'default']),\n\tfile: Object.freeze([...FIELD_BASE_KEYS, 'accept', 'multiple']),\n})\n\n/** Lists every form lifecycle status. */\nexport const FORM_STATUSES: readonly FormStatus[] = Object.freeze([\n\t'editing',\n\t'settled',\n\t'abandoned',\n])\n\n/** Holds the default failure copy for every named field rule. */\nexport const RULE_MESSAGES: Readonly<Record<FieldRuleName, string>> = Object.freeze({\n\trequired: 'This field is required',\n\tminimum: 'Must be at least {limit}',\n\tmaximum: 'Must be at most {limit}',\n\tstep: 'Must be a multiple of {limit}',\n\tpattern: 'Must match the required format',\n\temail: 'Must be a valid email address',\n\turl: 'Must be a valid URL',\n\tinteger: 'Must be an integer',\n\talphanumeric: 'Must contain only letters and numbers',\n})\n\n/** Matches a practical whole-address email shape. */\nexport const EMAIL_PATTERN = Object.freeze(/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/)\n\n/** Matches an absolute HTTP or HTTPS URL shape. */\nexport const URL_PATTERN = Object.freeze(/^https?:\\/\\/[^\\s]+$/)\n\n/** Matches one or more ASCII letters or digits. */\nexport const ALPHANUMERIC_PATTERN = Object.freeze(/^[A-Za-z0-9]+$/)\n\n/** Matches a signed or unsigned base-ten integer string. */\nexport const INTEGER_PATTERN = Object.freeze(/^[+-]?\\d+$/)\n\n/** Matches a six-digit hexadecimal color string. */\nexport const COLOR_PATTERN = Object.freeze(/^#[0-9A-Fa-f]{6}$/)\n\n/** Matches an ISO calendar date string in `YYYY-MM-DD` form. */\nexport const DATE_PATTERN = Object.freeze(/^\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])$/)\n\n/** Matches a 24-hour time string with optional seconds. */\nexport const TIME_PATTERN = Object.freeze(/^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$/)\n\n/** Matches an ISO local date and time string with optional seconds. */\nexport const DATETIME_PATTERN = Object.freeze(\n\t/^\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])T(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$/,\n)\n\n/** Caps the accepted source length for an authored regular expression, at 256. */\nexport const PATTERN_LIMIT = 256\n\n/** Caps the number of fields one schema may declare, at 512. */\nexport const FIELD_LIMIT = 512\n\n/** Caps the number of groups one schema may declare, at 64. */\nexport const GROUP_LIMIT = 64\n\n/** Caps the number of choices one `select` or `checkbox` field may offer, at 1024. */\nexport const CHOICE_LIMIT = 1024\n\n/** Caps the number of entries one list-valued answer may hold, at 1024. */\nexport const LIST_LIMIT = 1024\n\n/** Caps the length, in UTF-16 code units, of a schema, group, or field name, at 128. */\nexport const NAME_LIMIT = 128\n\n/** Caps the length, in UTF-16 code units, of any single retained string, at 65536. */\nexport const STRING_LIMIT = 65536\n\n/** Caps the total length, in UTF-16 code units, of every string one schema retains, at 1048576. */\nexport const TEXT_LIMIT = 1048576\n\n/** Caps the total number of records, arrays, and leaves one schema retains, at 16384. */\nexport const NODE_LIMIT = 16384\n","import type { JSONRecord } from '@orkestrel/contract'\nimport type { FormErrorCode } from './types.js'\n\n/**\n * Represents an error raised by the form domain.\n *\n * @example\n * ```ts\n * const error = new FormError('FIELD', 'The schema declares no field named \"nickname\"', {\n * \tfield: 'nickname',\n * })\n *\n * error.code // 'FIELD'\n * error.context // { field: 'nickname' }\n * ```\n */\nexport class FormError extends Error {\n\t/** Holds the machine-readable reason for this failure. */\n\treadonly code: FormErrorCode\n\n\t/** Holds structured values that locate or explain this failure. */\n\treadonly context?: JSONRecord\n\n\t/**\n\t * Creates a form error.\n\t *\n\t * @param code - The machine-readable reason.\n\t * @param message - The human-readable failure text.\n\t * @param context - Optional structured failure details.\n\t */\n\tconstructor(code: FormErrorCode, message: string, context?: JSONRecord) {\n\t\tsuper(message)\n\t\tthis.name = 'FormError'\n\t\tthis.code = code\n\t\tif (context !== undefined) this.context = context\n\t}\n}\n\n/**\n * Determines whether an unknown value is a form error.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a {@link FormError} instance; false otherwise.\n */\nexport function isFormError(input: unknown): input is FormError {\n\treturn input instanceof FormError\n}\n","import type {\n\tFieldChoice,\n\tFieldControl,\n\tFieldError,\n\tFieldRule,\n\tFieldValue,\n\tFormField,\n\tFormGroup,\n\tFormSchema,\n\tFormStatus,\n\tFormValues,\n} from './types.js'\nimport {\n\tarrayOf,\n\tattempt,\n\tisBoolean,\n\tisBoundedJSONRecord,\n\tisFiniteNumber,\n\tisFunction,\n\tisRecord,\n\tisString,\n\tkeyOf,\n\trecordOf,\n\tunionOf,\n} from '@orkestrel/contract'\nimport { FIELD_CONTROLS, FIELD_KEYS, FORM_STATUSES, RULE_MESSAGES } from './constants.js'\n\n/**\n * Determines whether an unknown value is a declared field control.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field control; false otherwise.\n */\nexport function isFieldControl(input: unknown): input is FieldControl {\n\treturn FIELD_CONTROLS.some((control) => control === input)\n}\n\n/**\n * Determines whether an unknown value is a form lifecycle status.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a form status; false otherwise.\n */\nexport function isFormStatus(input: unknown): input is FormStatus {\n\treturn FORM_STATUSES.some((status) => status === input)\n}\n\n/**\n * Determines whether an unknown value has a form field value shape.\n *\n * @remarks\n * A string, a finite number, a boolean, and a list of strings each qualify. A number that is not\n * finite does not, so `NaN` and `Infinity` are refused.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field value; false otherwise.\n */\nexport function isFieldValue(input: unknown): input is FieldValue {\n\treturn unionOf(isString, isFiniteNumber, isBoolean, arrayOf(isString))(input)\n}\n\n/**\n * Determines whether an unknown value is one exact field choice record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field choice; false otherwise.\n */\nexport function isFieldChoice(input: unknown): input is FieldChoice {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf({ value: isString, label: isString, help: isString, disabled: isBoolean }, [\n\t\t'help',\n\t\t'disabled',\n\t])(input)\n}\n\n/**\n * Determines whether an unknown value is one exact field rule record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a structurally valid field rule; false otherwise.\n */\nexport function isFieldRule(input: unknown): input is FieldRule {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf(\n\t\t{\n\t\t\trequired: isBoolean,\n\t\t\tminimum: unionOf(isFiniteNumber, isString),\n\t\t\tmaximum: unionOf(isFiniteNumber, isString),\n\t\t\tstep: isFiniteNumber,\n\t\t\tpattern: isString,\n\t\t\temail: isBoolean,\n\t\t\turl: isBoolean,\n\t\t\tinteger: isBoolean,\n\t\t\talphanumeric: isBoolean,\n\t\t\tcustom: isFunction,\n\t\t},\n\t\ttrue,\n\t)(input)\n}\n\n/**\n * Determines whether an unknown value is one exact discriminated form field.\n *\n * @remarks\n * Metadata is admitted structurally as bounded JSON. An accessor-bearing metadata record is\n * refused later when {@link cloneFormField} takes ownership, because ownership accepts enumerable\n * data properties only.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a structurally valid form field; false otherwise.\n */\nexport function isFormField(input: unknown): input is FormField {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input) || !Object.hasOwn(input, 'control') || !Object.hasOwn(input, 'name')) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst control = input.control\n\t\tif (!isFieldControl(control)) return false\n\n\t\tconst permitted = FIELD_KEYS[control]\n\t\tconst exact = Reflect.ownKeys(input).every((key) => isString(key) && permitted.includes(key))\n\n\t\tif (!exact) return false\n\n\t\tconst name = input.name\n\t\tconst hasLabel = Object.hasOwn(input, 'label')\n\t\tconst label = hasLabel ? input.label : undefined\n\t\tconst hasHelp = Object.hasOwn(input, 'help')\n\t\tconst help = hasHelp ? input.help : undefined\n\t\tconst hasGroup = Object.hasOwn(input, 'group')\n\t\tconst group = hasGroup ? input.group : undefined\n\t\tconst hasHidden = Object.hasOwn(input, 'hidden')\n\t\tconst hidden = hasHidden ? input.hidden : undefined\n\t\tconst hasDisabled = Object.hasOwn(input, 'disabled')\n\t\tconst disabled = hasDisabled ? input.disabled : undefined\n\t\tconst hasLocked = Object.hasOwn(input, 'locked')\n\t\tconst locked = hasLocked ? input.locked : undefined\n\t\tconst hasRule = Object.hasOwn(input, 'rule')\n\t\tconst rule = hasRule ? input.rule : undefined\n\t\tconst hasMeta = Object.hasOwn(input, 'meta')\n\t\tconst meta = hasMeta ? input.meta : undefined\n\n\t\tif (\n\t\t\t!isString(name) ||\n\t\t\t(hasLabel && !isString(label)) ||\n\t\t\t(hasHelp && !isString(help)) ||\n\t\t\t(hasGroup && !isString(group)) ||\n\t\t\t(hasHidden && !isBoolean(hidden)) ||\n\t\t\t(hasDisabled && !isBoolean(disabled)) ||\n\t\t\t(hasLocked && !isBoolean(locked)) ||\n\t\t\t(hasRule && !isFieldRule(rule)) ||\n\t\t\t(hasMeta && !isBoundedJSONRecord(meta))\n\t\t) {\n\t\t\treturn false\n\t\t}\n\n\t\tswitch (control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\tconst hasPlaceholder = Object.hasOwn(input, 'placeholder')\n\t\t\t\tconst placeholder = hasPlaceholder ? input.placeholder : undefined\n\t\t\t\treturn (!hasDefault || isString(fallback)) && (!hasPlaceholder || isString(placeholder))\n\t\t\t}\n\t\t\tcase 'password': {\n\t\t\t\tconst hasMask = Object.hasOwn(input, 'mask')\n\t\t\t\tconst mask = hasMask ? input.mask : undefined\n\t\t\t\treturn !hasMask || isString(mask)\n\t\t\t}\n\t\t\tcase 'number': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\tconst hasPlaceholder = Object.hasOwn(input, 'placeholder')\n\t\t\t\tconst placeholder = hasPlaceholder ? input.placeholder : undefined\n\t\t\t\treturn (\n\t\t\t\t\t(!hasDefault || isFiniteNumber(fallback)) && (!hasPlaceholder || isString(placeholder))\n\t\t\t\t)\n\t\t\t}\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\treturn !hasDefault || isString(fallback)\n\t\t\t}\n\t\t\tcase 'confirm': {\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\treturn !hasDefault || isBoolean(fallback)\n\t\t\t}\n\t\t\tcase 'select': {\n\t\t\t\tif (!Object.hasOwn(input, 'choices')) return false\n\t\t\t\tconst choices = input.choices\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\tconst hasOpen = Object.hasOwn(input, 'open')\n\t\t\t\tconst open = hasOpen ? input.open : undefined\n\t\t\t\treturn (\n\t\t\t\t\tarrayOf(isFieldChoice)(choices) &&\n\t\t\t\t\t(!hasDefault || isString(fallback)) &&\n\t\t\t\t\t(!hasOpen || isBoolean(open))\n\t\t\t\t)\n\t\t\t}\n\t\t\tcase 'checkbox': {\n\t\t\t\tif (!Object.hasOwn(input, 'choices')) return false\n\t\t\t\tconst choices = input.choices\n\t\t\t\tconst hasDefault = Object.hasOwn(input, 'default')\n\t\t\t\tconst fallback = hasDefault ? input.default : undefined\n\t\t\t\treturn arrayOf(isFieldChoice)(choices) && (!hasDefault || arrayOf(isString)(fallback))\n\t\t\t}\n\t\t\tcase 'file': {\n\t\t\t\tconst hasAccept = Object.hasOwn(input, 'accept')\n\t\t\t\tconst accept = hasAccept ? input.accept : undefined\n\t\t\t\tconst hasMultiple = Object.hasOwn(input, 'multiple')\n\t\t\t\tconst multiple = hasMultiple ? input.multiple : undefined\n\t\t\t\treturn (!hasAccept || arrayOf(isString)(accept)) && (!hasMultiple || isBoolean(multiple))\n\t\t\t}\n\t\t}\n\t})\n\n\treturn outcome.success && outcome.value\n}\n\n/**\n * Determines whether an unknown value is one exact form group record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a form group; false otherwise.\n */\nexport function isFormGroup(input: unknown): input is FormGroup {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf({ name: isString, label: isString, help: isString }, ['help'])(input)\n}\n\n/**\n * Determines whether an unknown value is one exact structural form schema.\n *\n * @remarks\n * Structure alone is read. Domain soundness — a duplicate name, a bound no answer satisfies, a\n * breached budget — is {@link auditSchema}'s question.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a structurally valid form schema; false otherwise.\n */\nexport function isFormSchema(input: unknown): input is FormSchema {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf(\n\t\t{\n\t\t\tname: isString,\n\t\t\tlabel: isString,\n\t\t\thelp: isString,\n\t\t\tgroups: arrayOf(isFormGroup),\n\t\t\tfields: arrayOf(isFormField),\n\t\t},\n\t\t['name', 'label', 'help', 'groups'],\n\t)(input)\n}\n\n/**\n * Determines whether an unknown value is a record of field values.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a form values record; false otherwise.\n */\nexport function isFormValues(input: unknown): input is FormValues {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input)) return false\n\t\treturn Reflect.ownKeys(input).every(\n\t\t\t(key) => isString(key) && Object.hasOwn(input, key) && isFieldValue(input[key]),\n\t\t)\n\t})\n\n\treturn outcome.success && outcome.value\n}\n\n/**\n * Determines whether an unknown value is one exact field error record.\n *\n * @param input - The value to inspect.\n * @returns True if the value is a field error; false otherwise.\n */\nexport function isFieldError(input: unknown): input is FieldError {\n\tconst keys = attempt(\n\t\t() => isRecord(input) && Reflect.ownKeys(input).every((key) => isString(key)),\n\t)\n\tif (!keys.success || !keys.value) return false\n\n\treturn recordOf(\n\t\t{\n\t\t\tfield: isString,\n\t\t\tmessage: isString,\n\t\t\trule: keyOf(RULE_MESSAGES),\n\t\t},\n\t\t['rule'],\n\t)(input)\n}\n","import type { JSONRecord } from '@orkestrel/contract'\nimport type { FieldChoice, FieldRule, FieldValue, FormField, FormSchema } from './types.js'\nimport { cloneJSONRecord, isArray, isContractError } from '@orkestrel/contract'\nimport { FormError } from './errors.js'\n\n/**\n * Clones one form value into an owned frozen snapshot.\n *\n * @param value - The field value to own.\n * @returns The scalar unchanged, or a frozen copy of the list.\n */\nexport function cloneValue(value: readonly string[]): readonly string[]\nexport function cloneValue(value: FieldValue): FieldValue\nexport function cloneValue(value: FieldValue): FieldValue {\n\treturn isArray(value) ? Object.freeze(value.slice()) : value\n}\n\n/**\n * Clones a field's choices into an owned frozen snapshot.\n *\n * @param choices - The choices to own.\n * @returns A frozen list of frozen choice records.\n */\nexport function cloneChoices(choices: readonly FieldChoice[]): readonly FieldChoice[] {\n\treturn Object.freeze(choices.map((choice) => Object.freeze({ ...choice })))\n}\n\n/**\n * Clones one form field into an owned frozen snapshot.\n *\n * @param field - The field to own.\n * @returns A frozen field with every nested collection owned.\n * @throws A {@link FormError} coded `SCHEMA` when accessor-bearing metadata cannot be owned.\n */\nexport function cloneFormField(field: FormField): FormField {\n\tconst rule: { rule?: Readonly<FieldRule> } =\n\t\tfield.rule === undefined ? {} : { rule: Object.freeze({ ...field.rule }) }\n\tlet meta: { meta?: JSONRecord } = {}\n\n\tif (field.meta !== undefined) {\n\t\ttry {\n\t\t\tmeta = { meta: cloneJSONRecord(field.meta) }\n\t\t} catch (error) {\n\t\t\tif (!isContractError(error)) throw error\n\t\t\tthrow new FormError('SCHEMA', `Field \"${field.name}\" has metadata that cannot be owned`, {\n\t\t\t\tfield: field.name,\n\t\t\t})\n\t\t}\n\t}\n\n\tswitch (field.control) {\n\t\tcase 'select':\n\t\t\treturn Object.freeze({ ...field, ...rule, ...meta, choices: cloneChoices(field.choices) })\n\t\tcase 'checkbox':\n\t\t\treturn Object.freeze({\n\t\t\t\t...field,\n\t\t\t\t...rule,\n\t\t\t\t...meta,\n\t\t\t\tchoices: cloneChoices(field.choices),\n\t\t\t\t...(field.default === undefined ? {} : { default: cloneValue(field.default) }),\n\t\t\t})\n\t\tcase 'file':\n\t\t\treturn Object.freeze({\n\t\t\t\t...field,\n\t\t\t\t...rule,\n\t\t\t\t...meta,\n\t\t\t\t...(field.accept === undefined ? {} : { accept: cloneValue(field.accept) }),\n\t\t\t})\n\t\tcase 'text':\n\t\tcase 'editor':\n\t\tcase 'password':\n\t\tcase 'number':\n\t\tcase 'date':\n\t\tcase 'time':\n\t\tcase 'datetime':\n\t\tcase 'color':\n\t\tcase 'confirm':\n\t\t\treturn Object.freeze({ ...field, ...rule, ...meta })\n\t}\n}\n\n/**\n * Clones a form schema into an owned frozen snapshot.\n *\n * @param schema - The schema to own.\n * @returns A frozen schema with every nested record and list owned.\n */\nexport function cloneFormSchema(schema: FormSchema): FormSchema {\n\tconst groups = schema.groups\n\n\treturn Object.freeze({\n\t\t...schema,\n\t\t...(groups === undefined\n\t\t\t? {}\n\t\t\t: { groups: Object.freeze(groups.map((group) => Object.freeze({ ...group }))) }),\n\t\tfields: Object.freeze(schema.fields.map((field) => cloneFormField(field))),\n\t})\n}\n","import type { JSONRecord, JSONValue } from '@orkestrel/contract'\nimport type {\n\tEvaluationOptions,\n\tFieldError,\n\tFieldControl,\n\tFieldRuleName,\n\tFieldValue,\n\tFormField,\n\tFormGroup,\n\tFormSchema,\n\tFormValues,\n} from './types.js'\nimport {\n\tattempt,\n\tcloneJSONRecord,\n\tisArray,\n\tisBoolean,\n\tisFiniteNumber,\n\tisInteger,\n\tisContractError,\n\tisRecord,\n\tisString,\n\treadArrayEntries,\n} from '@orkestrel/contract'\nimport { cloneValue } from './cloners.js'\nimport {\n\tALPHANUMERIC_PATTERN,\n\tCHOICE_LIMIT,\n\tCOLOR_PATTERN,\n\tDATE_PATTERN,\n\tDATETIME_PATTERN,\n\tEMAIL_PATTERN,\n\tFIELD_CONTROLS,\n\tFIELD_LIMIT,\n\tGROUP_LIMIT,\n\tINTEGER_PATTERN,\n\tLIST_LIMIT,\n\tNAME_LIMIT,\n\tNODE_LIMIT,\n\tPATTERN_LIMIT,\n\tRULE_MESSAGES,\n\tSTRING_LIMIT,\n\tTEXT_LIMIT,\n\tTIME_PATTERN,\n\tURL_PATTERN,\n} from './constants.js'\nimport { FormError } from './errors.js'\n\n/**\n * Writes one own enumerable data property onto a record.\n *\n * @param target - The record to write into.\n * @param name - The property name to write.\n * @param value - The value to store.\n *\n * @remarks\n * Plain assignment runs an inherited setter, so writing a `__proto__` key that way reaches\n * `Object.prototype` and leaves the record without the entry. Defining the property writes the\n * record itself, whatever the prototype chain declares. The entry stays writable and configurable.\n *\n * @example\n * ```ts\n * const values: Record<string, number> = {}\n * defineEntry(values, '__proto__', 1)\n * Object.hasOwn(values, '__proto__') // true\n * ```\n */\nexport function defineEntry<T>(target: Record<string, T>, name: string, value: T): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t})\n}\n\n/**\n * Writes one own enumerable data property that cannot be rewritten or removed.\n *\n * @param target - The record to write into.\n * @param name - The property name to write.\n * @param value - The value to store.\n *\n * @remarks\n * The prototype-safe write of {@link defineEntry}, frozen: the entry is neither writable nor\n * configurable, so the record a parser hands back cannot be edited through the key it filled.\n *\n * @example\n * ```ts\n * const values: Record<string, number> = {}\n * freezeEntry(values, '__proto__', 1)\n * Object.getOwnPropertyDescriptor(values, '__proto__')?.writable // false\n * ```\n */\nexport function freezeEntry<T>(target: Record<string, T>, name: string, value: T): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t})\n}\n\n/**\n * Checks whether a value has the shape required by one field control.\n *\n * @remarks\n * Every write and every seeded value passes through this gate, and it reads `STRING_LIMIT` and\n * `LIST_LIMIT` before it consults the control, so no regular expression sees an over-long value.\n *\n * @param field - The field that owns the value.\n * @param value - The unknown value to inspect.\n * @returns True if the control can hold the value; false otherwise.\n */\nexport function matchesField(field: FormField, value: unknown): value is FieldValue {\n\tif (isString(value) && value.length > STRING_LIMIT) return false\n\n\tlet entries: readonly unknown[] | undefined\n\tif (isArray(value)) {\n\t\tconst length = attempt(() => value.length)\n\t\tif (!length.success || length.value > LIST_LIMIT) return false\n\n\t\tconst read = readArrayEntries(value)\n\t\tif (!read.success || !read.value.dense) return false\n\n\t\tentries = read.value.entries\n\t\tif (entries.some((entry) => !isString(entry) || entry.length > STRING_LIMIT)) return false\n\t}\n\n\tswitch (field.control) {\n\t\tcase 'text':\n\t\tcase 'editor':\n\t\tcase 'password':\n\t\t\treturn isString(value)\n\t\tcase 'number':\n\t\t\treturn isFiniteNumber(value)\n\t\tcase 'date':\n\t\t\treturn isString(value) && DATE_PATTERN.test(value)\n\t\tcase 'time':\n\t\t\treturn isString(value) && TIME_PATTERN.test(value)\n\t\tcase 'datetime':\n\t\t\treturn isString(value) && DATETIME_PATTERN.test(value)\n\t\tcase 'color':\n\t\t\treturn isString(value) && COLOR_PATTERN.test(value)\n\t\tcase 'confirm':\n\t\t\treturn isBoolean(value)\n\t\tcase 'select':\n\t\t\treturn (\n\t\t\t\tisString(value) &&\n\t\t\t\t!field.choices.some((choice) => choice.value === value && choice.disabled === true) &&\n\t\t\t\t(field.open === true ||\n\t\t\t\t\tfield.choices.some((choice) => choice.value === value && choice.disabled !== true))\n\t\t\t)\n\t\tcase 'checkbox':\n\t\t\treturn (\n\t\t\t\tentries !== undefined &&\n\t\t\t\tentries.every(\n\t\t\t\t\t(entry) =>\n\t\t\t\t\t\tisString(entry) &&\n\t\t\t\t\t\tfield.choices.some((choice) => choice.value === entry && choice.disabled !== true),\n\t\t\t\t) &&\n\t\t\t\tnew Set(entries).size === entries.length\n\t\t\t)\n\t\tcase 'file':\n\t\t\treturn entries !== undefined && (field.multiple === true || entries.length <= 1)\n\t}\n}\n\n/**\n * Decides whether a raw binding value projects to an answered field.\n *\n * @remarks\n * Bind with `fill(name, matchesAnswer(raw) ? raw : undefined)`. This projection treats an absent\n * value and a string containing only whitespace as unanswered. Every other field value is an\n * answer, including an empty list, `false`, and zero. Core evaluation does not use this projection:\n * its `required` rule remains presence-only.\n *\n * @param value - The raw field value, or absence.\n * @returns True if the binding preserves the value as an answer; false otherwise.\n */\nexport function matchesAnswer(value: FieldValue | undefined): boolean {\n\treturn value !== undefined && (!isString(value) || value.trim().length > 0)\n}\n\n/**\n * Checks whether a named rule applies to one field control.\n *\n * @remarks\n * The runtime control-membership check keeps this boundary total for JavaScript callers that\n * bypass the declared {@link FieldControl} contract.\n *\n * @param control - The field control to inspect.\n * @param rule - The named rule to inspect.\n * @returns True if the control evaluates that rule; false otherwise.\n */\nexport function appliesRule(control: FieldControl, rule: FieldRuleName): boolean {\n\tif (!FIELD_CONTROLS.some((candidate) => candidate === control)) return false\n\n\tswitch (rule) {\n\t\tcase 'required':\n\t\t\treturn true\n\t\tcase 'minimum':\n\t\tcase 'maximum':\n\t\t\treturn control !== 'color' && control !== 'confirm' && control !== 'select'\n\t\tcase 'step':\n\t\t\treturn control === 'number'\n\t\tcase 'pattern':\n\t\tcase 'email':\n\t\tcase 'url':\n\t\tcase 'alphanumeric':\n\t\t\treturn (\n\t\t\t\tcontrol !== 'number' &&\n\t\t\t\tcontrol !== 'confirm' &&\n\t\t\t\tcontrol !== 'checkbox' &&\n\t\t\t\tcontrol !== 'file'\n\t\t\t)\n\t\tcase 'integer':\n\t\t\treturn control !== 'confirm' && control !== 'checkbox' && control !== 'file'\n\t}\n\n\treturn false\n}\n\n/**\n * Evaluates one field rule against its current value.\n *\n * @param field - The field and rule to evaluate.\n * @param value - The current value, or absence.\n * @param values - Every value available to a custom rule.\n * @param messages - Optional rule-specific message replacements.\n * @returns Every failure in rule order.\n * @throws Thrown when a {@link FieldValidator} supplied through {@link FieldRule.custom} throws:\n * its own value escapes unchanged, because this helper adds no boundary around it.\n */\nexport function evaluateField(\n\tfield: FormField,\n\tvalue: FieldValue | undefined,\n\tvalues: FormValues,\n\tmessages?: Readonly<Partial<Record<FieldRuleName, string>>>,\n): readonly FieldError[] {\n\tconst errors: FieldError[] = []\n\tconst rule = field.rule\n\n\tif (value === undefined) {\n\t\tif (rule?.required === true && appliesRule(field.control, 'required')) {\n\t\t\terrors.push(createFieldError(field, 'required', undefined, messages))\n\t\t}\n\t}\n\n\tif (rule === undefined) return Object.freeze(errors)\n\n\tif (rule.minimum !== undefined && appliesRule(field.control, 'minimum')) {\n\t\tlet failed = false\n\n\t\tswitch (field.control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'password':\n\t\t\t\tfailed = isString(value) && isFiniteNumber(rule.minimum) && value.length < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'number':\n\t\t\t\tfailed = isFiniteNumber(value) && isFiniteNumber(rule.minimum) && value < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\t\tfailed = isString(value) && isString(rule.minimum) && value < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'checkbox':\n\t\t\tcase 'file':\n\t\t\t\tfailed = isArray(value) && isFiniteNumber(rule.minimum) && value.length < rule.minimum\n\t\t\t\tbreak\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (failed) {\n\t\t\terrors.push(createFieldError(field, 'minimum', rule.minimum, messages))\n\t\t}\n\t}\n\n\tif (rule.maximum !== undefined && appliesRule(field.control, 'maximum')) {\n\t\tlet failed = false\n\n\t\tswitch (field.control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'password':\n\t\t\t\tfailed = isString(value) && isFiniteNumber(rule.maximum) && value.length > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'number':\n\t\t\t\tfailed = isFiniteNumber(value) && isFiniteNumber(rule.maximum) && value > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\t\tfailed = isString(value) && isString(rule.maximum) && value > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'checkbox':\n\t\t\tcase 'file':\n\t\t\t\tfailed = isArray(value) && isFiniteNumber(rule.maximum) && value.length > rule.maximum\n\t\t\t\tbreak\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (failed) {\n\t\t\terrors.push(createFieldError(field, 'maximum', rule.maximum, messages))\n\t\t}\n\t}\n\n\tif (rule.step !== undefined && appliesRule(field.control, 'step') && isFiniteNumber(value)) {\n\t\tconst base = isFiniteNumber(rule.minimum) ? rule.minimum : 0\n\t\tconst multiple = (value - base) / rule.step\n\n\t\tif (\n\t\t\t!isFiniteNumber(rule.step) ||\n\t\t\trule.step === 0 ||\n\t\t\t!isFiniteNumber(multiple) ||\n\t\t\tMath.abs(multiple - Math.round(multiple)) > 1e-9\n\t\t) {\n\t\t\terrors.push(createFieldError(field, 'step', rule.step, messages))\n\t\t}\n\t}\n\n\tif (isString(value)) {\n\t\tif (rule.pattern !== undefined && appliesRule(field.control, 'pattern')) {\n\t\t\tconst pattern = rule.pattern\n\n\t\t\tif (pattern.length > PATTERN_LIMIT) {\n\t\t\t\terrors.push(createFieldError(field, 'pattern', undefined, messages))\n\t\t\t} else {\n\t\t\t\tconst outcome = attempt(() => new RegExp(pattern).test(value))\n\n\t\t\t\tif (!outcome.success || !outcome.value) {\n\t\t\t\t\terrors.push(createFieldError(field, 'pattern', undefined, messages))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (rule.email === true && appliesRule(field.control, 'email') && !EMAIL_PATTERN.test(value)) {\n\t\t\terrors.push(createFieldError(field, 'email', undefined, messages))\n\t\t}\n\n\t\tif (rule.url === true && appliesRule(field.control, 'url') && !URL_PATTERN.test(value)) {\n\t\t\terrors.push(createFieldError(field, 'url', undefined, messages))\n\t\t}\n\n\t\tif (\n\t\t\trule.alphanumeric === true &&\n\t\t\tappliesRule(field.control, 'alphanumeric') &&\n\t\t\t!ALPHANUMERIC_PATTERN.test(value)\n\t\t) {\n\t\t\terrors.push(createFieldError(field, 'alphanumeric', undefined, messages))\n\t\t}\n\n\t\tif (\n\t\t\trule.integer === true &&\n\t\t\tappliesRule(field.control, 'integer') &&\n\t\t\t!INTEGER_PATTERN.test(value)\n\t\t) {\n\t\t\terrors.push(createFieldError(field, 'integer', undefined, messages))\n\t\t}\n\t}\n\n\tif (\n\t\tvalue !== undefined &&\n\t\tfield.control === 'number' &&\n\t\trule.integer === true &&\n\t\tappliesRule(field.control, 'integer') &&\n\t\t!isInteger(value)\n\t) {\n\t\terrors.push(createFieldError(field, 'integer', undefined, messages))\n\t}\n\n\tif (rule.custom !== undefined) {\n\t\tconst result = rule.custom(value, values)\n\n\t\tif (isString(result)) errors.push(Object.freeze({ field: field.name, message: result }))\n\t}\n\n\treturn Object.freeze(errors)\n}\n\n/**\n * Evaluates every active field in schema order.\n *\n * @param schema - The form schema to evaluate.\n * @param values - The values keyed by field name.\n * @param options - Optional message replacements and the effective disabled field set.\n * @returns Every field failure in schema and rule order.\n * @throws Thrown when a {@link FieldValidator} supplied through {@link FieldRule.custom} throws:\n * its own value escapes unchanged, because this helper adds no boundary around it.\n */\nexport function evaluateForm(\n\tschema: FormSchema,\n\tvalues: FormValues,\n\toptions?: EvaluationOptions,\n): readonly FieldError[] {\n\tconst errors: FieldError[] = []\n\n\tfor (const field of schema.fields) {\n\t\tconst active =\n\t\t\toptions?.disabled === undefined ? field.disabled !== true : !options.disabled.has(field.name)\n\n\t\tif (active) {\n\t\t\tconst value = Object.hasOwn(values, field.name) ? values[field.name] : undefined\n\t\t\terrors.push(...evaluateField(field, value, values, options?.messages))\n\t\t}\n\t}\n\n\treturn Object.freeze(errors)\n}\n\n/**\n * Computes the values explicitly seeded by a schema.\n *\n * @remarks\n * `password` and `file` declare no default, so a field of either control never appears in the\n * result.\n *\n * @param schema - The schema whose defaults to collect.\n * @returns A value record containing only fields with defaults.\n */\nexport function computeDefaults(schema: FormSchema): FormValues {\n\tconst defaults: Record<string, FieldValue> = {}\n\n\tfor (const field of schema.fields) {\n\t\tswitch (field.control) {\n\t\t\tcase 'checkbox':\n\t\t\t\tif (field.default !== undefined) {\n\t\t\t\t\tdefineEntry(defaults, field.name, cloneValue(field.default))\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase 'password':\n\t\t\tcase 'file':\n\t\t\t\tbreak\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'number':\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\t\tif (field.default !== undefined) {\n\t\t\t\t\tdefineEntry(defaults, field.name, field.default)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\treturn Object.freeze(defaults)\n}\n\n/**\n * Compares two field values by scalar identity or ordered list content.\n *\n * @param a - The first field value.\n * @param b - The second field value.\n * @returns True if both values contain the same answer; false otherwise.\n */\nexport function matchesValue(a: FieldValue, b: FieldValue): boolean {\n\tif (isArray(a) || isArray(b)) {\n\t\treturn (\n\t\t\tisArray(a) &&\n\t\t\tisArray(b) &&\n\t\t\ta.length === b.length &&\n\t\t\ta.every((entry, index) => entry === b[index])\n\t\t)\n\t}\n\n\treturn a === b\n}\n\n/**\n * Extracts the names whose answers differ between two form value records.\n *\n * @remarks\n * Presence is compared in both directions before present values are compared through\n * {@link matchesValue}. The returned set is a new snapshot, exposed as readonly because later\n * changes to either input never alter its membership.\n *\n * @param current - The values the form holds.\n * @param opened - The values held when the form opened.\n * @returns A readonly snapshot of changed field names.\n */\nexport function extractChanges(current: FormValues, opened: FormValues): ReadonlySet<string> {\n\tconst names = new Set([...Object.keys(current), ...Object.keys(opened)])\n\tconst changed = new Set<string>()\n\n\tfor (const name of names) {\n\t\tconst hasCurrent = Object.hasOwn(current, name)\n\t\tconst hasOpened = Object.hasOwn(opened, name)\n\n\t\tif (hasCurrent !== hasOpened) {\n\t\t\tchanged.add(name)\n\t\t\tcontinue\n\t\t}\n\n\t\tconst now = current[name]\n\t\tconst before = opened[name]\n\t\tif (now === undefined || before === undefined || !matchesValue(now, before)) changed.add(name)\n\t}\n\n\treturn changed\n}\n\n/**\n * Compares two form value records by keys and value content.\n *\n * @param a - The first value record.\n * @param b - The second value record.\n * @returns True if both records contain the same answers; false otherwise.\n */\nexport function matchesValues(a: FormValues, b: FormValues): boolean {\n\treturn extractChanges(a, b).size === 0\n}\n\n/**\n * Resolves and interpolates one rule message.\n *\n * @remarks\n * A replacement in `messages` is read first and {@link RULE_MESSAGES} supplies the copy otherwise,\n * and `{limit}` in whichever text wins is replaced with the rule's operand.\n *\n * @param rule - The rule whose message to resolve.\n * @param limit - The optional operand substituted for `{limit}`.\n * @param messages - Optional rule-specific message replacements.\n * @returns The resolved failure text.\n */\nexport function formatMessage(\n\trule: FieldRuleName,\n\tlimit?: number | string,\n\tmessages?: Readonly<Partial<Record<FieldRuleName, string>>>,\n): string {\n\tconst message = messages?.[rule] ?? RULE_MESSAGES[rule]\n\treturn limit === undefined ? message : message.replaceAll('{limit}', String(limit))\n}\n\n/**\n * Creates one named-rule failure against a field.\n *\n * @param field - The field the rule failed on.\n * @param rule - The named rule that failed.\n * @param limit - The rule's operand, substituted for `{limit}`, or absence when it carries none.\n * @param messages - Optional rule-specific message replacements.\n * @returns A frozen {@link FieldError} carrying the field's name, the resolved text, and the rule.\n *\n * @remarks\n * A `custom` validator and the form's `invalidate` method both report a message of their own\n * under no rule name, so neither builds its failure here.\n *\n * @example\n * ```ts\n * const field: FormField = { control: 'text', name: 'nickname', rule: { minimum: 3 } }\n * const error = createFieldError(field, 'minimum', 3)\n * error.message // 'Must be at least 3'\n * ```\n */\nexport function createFieldError(\n\tfield: FormField,\n\trule: FieldRuleName,\n\tlimit: number | string | undefined,\n\tmessages?: Readonly<Partial<Record<FieldRuleName, string>>>,\n): FieldError {\n\treturn Object.freeze({ field: field.name, message: formatMessage(rule, limit, messages), rule })\n}\n\n/**\n * Projects a schema into JSON while removing custom validators and absent values.\n *\n * @param schema - The schema to project.\n * @returns A deep JSON copy of the serializable schema.\n * @throws A {@link FormError} coded `SCHEMA` when accessor-bearing metadata cannot be owned. A\n * non-contract throw while reading metadata escapes unchanged.\n */\nexport function serializeForm(schema: FormSchema): JSONRecord {\n\tconst output: Record<string, JSONValue> = {}\n\n\tif (schema.name !== undefined) output.name = schema.name\n\tif (schema.label !== undefined) output.label = schema.label\n\tif (schema.help !== undefined) output.help = schema.help\n\tif (schema.groups !== undefined) {\n\t\toutput.groups = schema.groups.map((group): JSONRecord => {\n\t\t\tconst entry: Record<string, JSONValue> = { name: group.name, label: group.label }\n\t\t\tif (group.help !== undefined) entry.help = group.help\n\t\t\treturn entry\n\t\t})\n\t}\n\n\toutput.fields = schema.fields.map((field): JSONRecord => {\n\t\tconst entry: Record<string, JSONValue> = {\n\t\t\tcontrol: field.control,\n\t\t\tname: field.name,\n\t\t}\n\n\t\tif (field.label !== undefined) entry.label = field.label\n\t\tif (field.help !== undefined) entry.help = field.help\n\t\tif (field.group !== undefined) entry.group = field.group\n\t\tif (field.hidden !== undefined) entry.hidden = field.hidden\n\t\tif (field.disabled !== undefined) entry.disabled = field.disabled\n\t\tif (field.locked !== undefined) entry.locked = field.locked\n\t\tconst meta = field.meta\n\t\tif (meta !== undefined) {\n\t\t\ttry {\n\t\t\t\tentry.meta = cloneJSONRecord(meta)\n\t\t\t} catch (error) {\n\t\t\t\tif (!isContractError(error)) throw error\n\t\t\t\tthrow new FormError('SCHEMA', `Field \"${field.name}\" has metadata that cannot be owned`, {\n\t\t\t\t\tfield: field.name,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tswitch (field.control) {\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'number':\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tif (field.placeholder !== undefined) entry.placeholder = field.placeholder\n\t\t\t\tbreak\n\t\t\tcase 'password':\n\t\t\t\tif (field.mask !== undefined) entry.mask = field.mask\n\t\t\t\tbreak\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tbreak\n\t\t\tcase 'select':\n\t\t\t\tentry.choices = field.choices.map((choice): JSONRecord => {\n\t\t\t\t\tconst option: Record<string, JSONValue> = {\n\t\t\t\t\t\tvalue: choice.value,\n\t\t\t\t\t\tlabel: choice.label,\n\t\t\t\t\t}\n\t\t\t\t\tif (choice.help !== undefined) option.help = choice.help\n\t\t\t\t\tif (choice.disabled !== undefined) option.disabled = choice.disabled\n\t\t\t\t\treturn option\n\t\t\t\t})\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tif (field.open !== undefined) entry.open = field.open\n\t\t\t\tbreak\n\t\t\tcase 'checkbox':\n\t\t\t\tentry.choices = field.choices.map((choice): JSONRecord => {\n\t\t\t\t\tconst option: Record<string, JSONValue> = {\n\t\t\t\t\t\tvalue: choice.value,\n\t\t\t\t\t\tlabel: choice.label,\n\t\t\t\t\t}\n\t\t\t\t\tif (choice.help !== undefined) option.help = choice.help\n\t\t\t\t\tif (choice.disabled !== undefined) option.disabled = choice.disabled\n\t\t\t\t\treturn option\n\t\t\t\t})\n\t\t\t\tif (field.default !== undefined) entry.default = field.default\n\t\t\t\tbreak\n\t\t\tcase 'file':\n\t\t\t\tif (field.accept !== undefined) entry.accept = field.accept\n\t\t\t\tif (field.multiple !== undefined) entry.multiple = field.multiple\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (field.rule !== undefined) {\n\t\t\tconst rule: Record<string, JSONValue> = {}\n\n\t\t\tif (field.rule.required !== undefined) rule.required = field.rule.required\n\t\t\tif (field.rule.minimum !== undefined) rule.minimum = field.rule.minimum\n\t\t\tif (field.rule.maximum !== undefined) rule.maximum = field.rule.maximum\n\t\t\tif (field.rule.step !== undefined) rule.step = field.rule.step\n\t\t\tif (field.rule.pattern !== undefined) rule.pattern = field.rule.pattern\n\t\t\tif (field.rule.email !== undefined) rule.email = field.rule.email\n\t\t\tif (field.rule.url !== undefined) rule.url = field.rule.url\n\t\t\tif (field.rule.integer !== undefined) rule.integer = field.rule.integer\n\t\t\tif (field.rule.alphanumeric !== undefined) rule.alphanumeric = field.rule.alphanumeric\n\t\t\tif (Object.keys(rule).length > 0) entry.rule = rule\n\t\t}\n\n\t\treturn entry\n\t})\n\n\treturn cloneJSONRecord(output)\n}\n\n/**\n * Selects referenced groups in first-reference field order.\n *\n * @param schema - The schema whose group references to resolve.\n * @returns The referenced schema groups without duplicates.\n */\nexport function extractGroups(schema: FormSchema): readonly FormGroup[] {\n\tconst groups: FormGroup[] = []\n\n\tif (schema.groups === undefined) return Object.freeze(groups)\n\n\tfor (const field of schema.fields) {\n\t\tif (field.group !== undefined && !groups.some((group) => group.name === field.group)) {\n\t\t\tconst group = schema.groups.find((entry) => entry.name === field.group)\n\t\t\tif (group !== undefined) groups.push(group)\n\t\t}\n\t}\n\n\treturn Object.freeze(groups)\n}\n\n/**\n * Audits a structurally valid schema for domain invariants.\n *\n * @param schema - The form schema to audit.\n * @returns Human-readable invariant violations, or an empty list when the schema is sound.\n */\nexport function auditSchema(schema: FormSchema): readonly string[] {\n\tconst faults: string[] = []\n\tconst fields = new Set<string>()\n\tconst groups = new Set<string>()\n\tlet choiceExceeded: string | undefined\n\tlet nameExceeded = schema.name !== undefined && schema.name.length > NAME_LIMIT\n\n\tif (schema.fields.length > FIELD_LIMIT) {\n\t\tfaults.push(`Schema declares more than ${FIELD_LIMIT} fields`)\n\t}\n\tif (schema.groups !== undefined && schema.groups.length > GROUP_LIMIT) {\n\t\tfaults.push(`Schema declares more than ${GROUP_LIMIT} groups`)\n\t}\n\n\tif (schema.groups !== undefined) {\n\t\tconst count = Math.min(schema.groups.length, GROUP_LIMIT + 1)\n\t\tfor (let index = 0; index < count; index += 1) {\n\t\t\tconst group = schema.groups[index]\n\t\t\tif (group !== undefined && group.name.length > NAME_LIMIT) nameExceeded = true\n\t\t}\n\t}\n\n\tconst fieldCount = Math.min(schema.fields.length, FIELD_LIMIT + 1)\n\tfor (let index = 0; index < fieldCount; index += 1) {\n\t\tconst field = schema.fields[index]\n\t\tif (field === undefined) continue\n\n\t\tif (\n\t\t\tfield.name.length > NAME_LIMIT ||\n\t\t\t(field.group !== undefined && field.group.length > NAME_LIMIT)\n\t\t) {\n\t\t\tnameExceeded = true\n\t\t}\n\t\tif (\n\t\t\tchoiceExceeded === undefined &&\n\t\t\t(field.control === 'select' || field.control === 'checkbox') &&\n\t\t\tfield.choices.length > CHOICE_LIMIT\n\t\t) {\n\t\t\tchoiceExceeded = field.name\n\t\t}\n\t}\n\n\tif (choiceExceeded !== undefined) {\n\t\tfaults.push(`Field \"${choiceExceeded}\" offers more than ${CHOICE_LIMIT} choices`)\n\t}\n\tif (nameExceeded) faults.push(`Schema contains a name longer than ${NAME_LIMIT}`)\n\n\tconst pending: unknown[] = [schema]\n\tconst metadata: boolean[] = [false]\n\tlet position = 0\n\tlet stringExceeded = false\n\tlet textExceeded = false\n\tlet nodeExceeded = false\n\tlet text = 0\n\n\twhile (position < pending.length) {\n\t\tconst node = pending[position]\n\t\tconst inMeta = metadata[position] === true\n\t\tposition += 1\n\n\t\tif (isString(node)) {\n\t\t\tif (node.length > STRING_LIMIT) stringExceeded = true\n\t\t\ttext = Math.min(TEXT_LIMIT + 1, text + node.length)\n\t\t\tif (text > TEXT_LIMIT) textExceeded = true\n\t\t\tcontinue\n\t\t}\n\n\t\tif (isArray(node)) {\n\t\t\tconst length = attempt(() => node.length)\n\t\t\tif (!length.success || length.value > NODE_LIMIT - pending.length) {\n\t\t\t\tnodeExceeded = true\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst read = readArrayEntries(node)\n\t\t\tif (!read.success || !read.value.dense) continue\n\n\t\t\tfor (let index = 0; index < read.value.entries.length; index += 1) {\n\t\t\t\tconst entry = read.value.entries[index]\n\t\t\t\tif (entry !== undefined) {\n\t\t\t\t\tpending.push(entry)\n\t\t\t\t\tmetadata.push(inMeta)\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tif (!isRecord(node)) continue\n\n\t\tconst keys = attempt(() => Object.keys(node))\n\t\tif (!keys.success) continue\n\n\t\tfor (const key of keys.value) {\n\t\t\tif (inMeta) {\n\t\t\t\tif (key.length > STRING_LIMIT) stringExceeded = true\n\t\t\t\ttext = Math.min(TEXT_LIMIT + 1, text + key.length)\n\t\t\t\tif (text > TEXT_LIMIT) textExceeded = true\n\t\t\t}\n\n\t\t\tconst value = attempt(() => node[key])\n\t\t\tif (!value.success || value.value === undefined) continue\n\t\t\tif (pending.length >= NODE_LIMIT) {\n\t\t\t\tnodeExceeded = true\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tpending.push(value.value)\n\t\t\tmetadata.push(inMeta || key === 'meta')\n\t\t}\n\t}\n\n\tif (stringExceeded) faults.push(`Schema contains a string longer than ${STRING_LIMIT}`)\n\tif (textExceeded) faults.push(`Schema retains more than ${TEXT_LIMIT} string code units`)\n\tif (nodeExceeded) faults.push(`Schema retains more than ${NODE_LIMIT} nodes`)\n\n\tif (schema.groups !== undefined) {\n\t\tconst count = Math.min(schema.groups.length, GROUP_LIMIT + 1)\n\t\tfor (let index = 0; index < count; index += 1) {\n\t\t\tconst group = schema.groups[index]\n\t\t\tif (group === undefined) continue\n\t\t\tif (groups.has(group.name)) faults.push(`Group \"${group.name}\" is declared more than once`)\n\t\t\tgroups.add(group.name)\n\t\t}\n\t}\n\n\tfor (let fieldIndex = 0; fieldIndex < fieldCount; fieldIndex += 1) {\n\t\tconst field = schema.fields[fieldIndex]\n\t\tif (field === undefined) continue\n\t\tif (field.name.length === 0) faults.push('Field \"\" has an empty name')\n\t\tif (field.name === '__proto__') faults.push('Field \"__proto__\" has a refused name')\n\t\tif (fields.has(field.name)) faults.push(`Field \"${field.name}\" is declared more than once`)\n\t\tfields.add(field.name)\n\n\t\tif (field.group !== undefined && !groups.has(field.group)) {\n\t\t\tfaults.push(`Field \"${field.name}\" references missing group \"${field.group}\"`)\n\t\t}\n\n\t\tswitch (field.control) {\n\t\t\tcase 'password':\n\t\t\tcase 'file':\n\t\t\t\tbreak\n\t\t\tcase 'text':\n\t\t\tcase 'editor':\n\t\t\tcase 'number':\n\t\t\tcase 'date':\n\t\t\tcase 'time':\n\t\t\tcase 'datetime':\n\t\t\tcase 'color':\n\t\t\tcase 'confirm':\n\t\t\tcase 'select':\n\t\t\tcase 'checkbox':\n\t\t\t\tif (field.default !== undefined && !matchesField(field, field.default)) {\n\t\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid default`)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (field.control === 'select' || field.control === 'checkbox') {\n\t\t\tconst choices = new Set<string>()\n\t\t\tconst count = Math.min(field.choices.length, CHOICE_LIMIT + 1)\n\t\t\tlet enabled = 0\n\n\t\t\tfor (let index = 0; index < count; index += 1) {\n\t\t\t\tconst choice = field.choices[index]\n\t\t\t\tif (choice === undefined) continue\n\t\t\t\tif (choice.disabled !== true) enabled += 1\n\t\t\t\tif (choices.has(choice.value)) {\n\t\t\t\t\tfaults.push(`Field \"${field.name}\" offers choice \"${choice.value}\" more than once`)\n\t\t\t\t}\n\t\t\t\tchoices.add(choice.value)\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tfield.control === 'select' &&\n\t\t\t\tfield.rule?.required === true &&\n\t\t\t\tfield.open !== true &&\n\t\t\t\tenabled === 0\n\t\t\t) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" is required but offers no enabled choice`)\n\t\t\t}\n\n\t\t\tconst minimum = field.rule?.minimum\n\t\t\tif (\n\t\t\t\tfield.control === 'checkbox' &&\n\t\t\t\tisFiniteNumber(minimum) &&\n\t\t\t\tminimum > 0 &&\n\t\t\t\tminimum > enabled\n\t\t\t) {\n\t\t\t\tfaults.push(\n\t\t\t\t\t`Field \"${field.name}\" has minimum ${minimum} but offers only ${enabled} enabled ${enabled === 1 ? 'choice' : 'choices'}`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tconst rule = field.rule\n\t\tif (rule === undefined) continue\n\n\t\tconst temporal =\n\t\t\tfield.control === 'date' || field.control === 'time' || field.control === 'datetime'\n\t\tif (rule.minimum !== undefined && !appliesRule(field.control, 'minimum')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has minimum on ${field.control}`)\n\t\t} else if (isString(rule.minimum) && !temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a string minimum on ${field.control}`)\n\t\t}\n\t\tif (rule.maximum !== undefined && !appliesRule(field.control, 'maximum')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has maximum on ${field.control}`)\n\t\t} else if (isString(rule.maximum) && !temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a string maximum on ${field.control}`)\n\t\t}\n\t\tif (isFiniteNumber(rule.minimum) && temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a numeric minimum on ${field.control}`)\n\t\t}\n\t\tif (isFiniteNumber(rule.maximum) && temporal) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a numeric maximum on ${field.control}`)\n\t\t}\n\t\tif (\n\t\t\tisFiniteNumber(rule.maximum) &&\n\t\t\trule.maximum < 0 &&\n\t\t\t(field.control === 'text' ||\n\t\t\t\tfield.control === 'editor' ||\n\t\t\t\tfield.control === 'password' ||\n\t\t\t\tfield.control === 'checkbox' ||\n\t\t\t\tfield.control === 'file')\n\t\t) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a negative maximum on ${field.control}`)\n\t\t}\n\n\t\tif (rule.step !== undefined && !appliesRule(field.control, 'step')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has step on ${field.control}`)\n\t\t}\n\t\tif (rule.step !== undefined && rule.step <= 0) {\n\t\t\tfaults.push(`Field \"${field.name}\" has a non-positive step`)\n\t\t}\n\n\t\tif (rule.pattern !== undefined && !appliesRule(field.control, 'pattern')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has pattern on ${field.control}`)\n\t\t}\n\t\tif (rule.email === true && !appliesRule(field.control, 'email')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has email on ${field.control}`)\n\t\t}\n\t\tif (rule.url === true && !appliesRule(field.control, 'url')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has url on ${field.control}`)\n\t\t}\n\t\tif (rule.alphanumeric === true && !appliesRule(field.control, 'alphanumeric')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has alphanumeric on ${field.control}`)\n\t\t}\n\t\tif (rule.integer === true && !appliesRule(field.control, 'integer')) {\n\t\t\tfaults.push(`Field \"${field.name}\" has integer on ${field.control}`)\n\t\t}\n\n\t\tif (rule.pattern !== undefined) {\n\t\t\tif (rule.pattern.length > PATTERN_LIMIT) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has a pattern longer than ${PATTERN_LIMIT}`)\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tRegExp(rule.pattern)\n\t\t\t\t} catch {\n\t\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid pattern`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t(isFiniteNumber(rule.minimum) &&\n\t\t\t\tisFiniteNumber(rule.maximum) &&\n\t\t\t\trule.minimum > rule.maximum) ||\n\t\t\t(isString(rule.minimum) && isString(rule.maximum) && rule.minimum > rule.maximum)\n\t\t) {\n\t\t\tfaults.push(`Field \"${field.name}\" has minimum greater than maximum`)\n\t\t}\n\n\t\tif (field.control === 'date') {\n\t\t\tif (isString(rule.minimum) && !DATE_PATTERN.test(rule.minimum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid date minimum`)\n\t\t\t}\n\t\t\tif (isString(rule.maximum) && !DATE_PATTERN.test(rule.maximum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid date maximum`)\n\t\t\t}\n\t\t}\n\n\t\tif (field.control === 'time') {\n\t\t\tif (isString(rule.minimum) && !TIME_PATTERN.test(rule.minimum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid time minimum`)\n\t\t\t}\n\t\t\tif (isString(rule.maximum) && !TIME_PATTERN.test(rule.maximum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid time maximum`)\n\t\t\t}\n\t\t}\n\n\t\tif (field.control === 'datetime') {\n\t\t\tif (isString(rule.minimum) && !DATETIME_PATTERN.test(rule.minimum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid datetime minimum`)\n\t\t\t}\n\t\t\tif (isString(rule.maximum) && !DATETIME_PATTERN.test(rule.maximum)) {\n\t\t\t\tfaults.push(`Field \"${field.name}\" has an invalid datetime maximum`)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Object.freeze(faults)\n}\n","import type { FieldValue, FormField, FormSchema, FormValues } from './types.js'\nimport {\n\tattempt,\n\tisArray,\n\tisRecord,\n\tisString,\n\tparseNumber,\n\treadArrayEntries,\n} from '@orkestrel/contract'\nimport { cloneValue } from './cloners.js'\nimport { STRING_LIMIT } from './constants.js'\nimport { auditSchema, defineEntry, freezeEntry, matchesField, serializeForm } from './helpers.js'\nimport { isFormSchema } from './validators.js'\n\n/**\n * Parses unknown wire data into an owned, semantically sound form schema.\n *\n * @param input - The unknown schema value to parse.\n * @returns An owned schema with custom rules removed, or `undefined` on refusal.\n */\nexport function parseForm(input: unknown): FormSchema | undefined {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input)) return undefined\n\n\t\tconst schema: Record<string, unknown> = {}\n\t\tfor (const key of Reflect.ownKeys(input)) {\n\t\t\tif (!isString(key)) return undefined\n\t\t\tdefineEntry(schema, key, input[key])\n\t\t}\n\n\t\tconst fields = schema.fields\n\t\tif (!isArray(fields)) return undefined\n\n\t\tconst read = readArrayEntries(fields)\n\t\tif (!read.success || !read.value.dense) return undefined\n\n\t\tconst copies: unknown[] = []\n\t\tfor (let index = 0; index < read.value.entries.length; index += 1) {\n\t\t\tconst field = read.value.entries[index]\n\t\t\tif (!isRecord(field)) {\n\t\t\t\tcopies.push(field)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst copy: Record<string, unknown> = {}\n\t\t\tfor (const key of Reflect.ownKeys(field)) {\n\t\t\t\tif (!isString(key)) return undefined\n\t\t\t\tdefineEntry(copy, key, field[key])\n\t\t\t}\n\n\t\t\tconst rule = copy.rule\n\t\t\tif (isRecord(rule)) {\n\t\t\t\tconst projected: Record<string, unknown> = {}\n\t\t\t\tfor (const key of Reflect.ownKeys(rule)) {\n\t\t\t\t\tif (!isString(key)) return undefined\n\t\t\t\t\tif (key !== 'custom') {\n\t\t\t\t\t\tdefineEntry(projected, key, rule[key])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcopy.rule = projected\n\t\t\t}\n\n\t\t\tcopies.push(copy)\n\t\t}\n\n\t\tschema.fields = copies\n\t\tif (!isFormSchema(schema) || auditSchema(schema).length !== 0) return undefined\n\n\t\tconst parsed = serializeForm(schema)\n\t\treturn isFormSchema(parsed) && auditSchema(parsed).length === 0 ? parsed : undefined\n\t})\n\n\treturn outcome.success ? outcome.value : undefined\n}\n\n/**\n * Parses one answer against its field control.\n *\n * @remarks\n * A numeric string coerces to a number for a `number` field, and `'true'` and `'false'` coerce to\n * a boolean for a `confirm` field. Every other value must already have its control's shape.\n *\n * @param field - The field that defines the accepted value.\n * @param input - The unknown value to parse.\n * @returns The typed or lexically coerced field value, or `undefined` on refusal.\n */\nexport function parseValue(field: FormField, input: unknown): FieldValue | undefined {\n\tconst outcome = attempt(() => {\n\t\tif (matchesField(field, input)) return cloneValue(input)\n\t\tif (field.control === 'number') {\n\t\t\tif (isString(input) && input.length > STRING_LIMIT) return undefined\n\t\t\tconst value = parseNumber(input)\n\t\t\treturn value !== undefined && matchesField(field, value) ? value : undefined\n\t\t}\n\t\tif (field.control === 'confirm') {\n\t\t\tif (input === 'true') return true\n\t\t\tif (input === 'false') return false\n\t\t}\n\t\treturn undefined\n\t})\n\n\treturn outcome.success ? outcome.value : undefined\n}\n\n/**\n * Parses a strict answer record against the fields declared by a schema.\n *\n * @param schema - The schema that owns the accepted field names and controls.\n * @param input - The unknown answer record to parse.\n * @returns An owned answer record, or `undefined` when any key or value is refused.\n */\nexport function parseValues(schema: FormSchema, input: unknown): FormValues | undefined {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(input)) return undefined\n\n\t\tconst values: Record<string, FieldValue> = {}\n\t\tfor (const key of Reflect.ownKeys(input)) {\n\t\t\tif (!isString(key) || !Object.hasOwn(input, key)) return undefined\n\n\t\t\tconst field = schema.fields.find((candidate) => candidate.name === key)\n\t\t\tif (field === undefined) return undefined\n\n\t\t\tconst value = parseValue(field, input[key])\n\t\t\tif (value === undefined) return undefined\n\n\t\t\tfreezeEntry(values, key, value)\n\t\t}\n\n\t\treturn Object.freeze(values)\n\t})\n\n\treturn outcome.success ? outcome.value : undefined\n}\n","import type { EmitterInterface } from '@orkestrel/emitter'\nimport type {\n\tFieldError,\n\tFieldRuleName,\n\tFieldValue,\n\tFormEventMap,\n\tFormField,\n\tFormInterface,\n\tFormOptions,\n\tFormResult,\n\tFormSchema,\n\tFormStatus,\n\tFormValues,\n} from './types.js'\nimport { attempt, isString } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { cloneFormSchema, cloneValue } from './cloners.js'\nimport { FormError, isFormError } from './errors.js'\nimport {\n\tauditSchema,\n\tcomputeDefaults,\n\tdefineEntry,\n\tevaluateForm,\n\tmatchesField,\n\tmatchesValue,\n\tmatchesValues,\n} from './helpers.js'\nimport { isFormSchema } from './validators.js'\n\n/**\n * Implements `FormInterface` exactly, over an owned schema, the answers given against it, and the\n * errors they carry.\n *\n * @remarks\n * The form owns its schema, so a later edit to the schema the caller passed changes nothing here.\n *\n * `errors` is recomputed at construction and after every mutation whose evaluation completes,\n * and the `validate` event fires exactly when that list's content changes. A throwing custom\n * validator escapes after any preceding state changes and leaves the prior error list in place.\n * There is no separate check.\n *\n * `valid` and `dirty` are derived on read from the error list and answers respectively, never\n * stored.\n *\n * @example\n * ```ts\n * const form = new Form({\n * \tfields: [{ control: 'text', name: 'email', rule: { required: true, email: true } }],\n * })\n *\n * form.fill('email', 'ada@example.com')\n * const result = form.submit()\n * if (result.success) await form.answer\n * ```\n */\nexport class Form implements FormInterface {\n\treadonly #emitter: Emitter<FormEventMap>\n\treadonly #schema: FormSchema\n\treadonly #messages: Readonly<Partial<Record<FieldRuleName, string>>> | undefined\n\treadonly #baseline: FormValues\n\treadonly #values: Record<string, FieldValue>\n\treadonly #touched = new Set<string>()\n\treadonly #disabled = new Map<string, boolean>()\n\treadonly #invalidations = new Map<string, string>()\n\treadonly #resolvers = Promise.withResolvers<FormValues>()\n\t#errors: readonly FieldError[] = Object.freeze([])\n\t#status: FormStatus = 'editing'\n\t#batchDepth = 0\n\t#evaluation = 0\n\t#pending = false\n\n\t/**\n\t * Opens a form against a schema.\n\t *\n\t * @param schema - The form to ask. It is copied, and the copy is what the form asks.\n\t * @param options - The form's settings.\n\t * @throws A {@link FormError} coded `SCHEMA` when the schema is malformed, `FIELD` when\n\t * `options.values` names a field the schema does not declare, and `CONTROL` when a seeded\n\t * value is one its field's control cannot hold.\n\t */\n\tconstructor(schema: FormSchema, options?: FormOptions) {\n\t\t// Own the schema before reading it, so the guard, the audit, and every later read see one\n\t\t// copy this form holds rather than an object the caller can still answer differently on\n\t\t// each read. `parseForm` takes the same clone-then-guard order at the wire boundary.\n\t\tconst owned = attempt(() => cloneFormSchema(schema))\n\t\tif (!owned.success && isFormError(owned.error)) throw owned.error\n\n\t\tconst copy = owned.success && isFormSchema(owned.value) ? owned.value : undefined\n\t\tconst problems = copy === undefined ? ['The schema is not a form schema'] : auditSchema(copy)\n\n\t\tif (copy === undefined || problems.length > 0) {\n\t\t\tthrow new FormError('SCHEMA', `The form schema is unusable: ${problems.join('; ')}`, {\n\t\t\t\tproblems: [...problems],\n\t\t\t})\n\t\t}\n\n\t\tthis.#schema = copy\n\t\tthis.#messages =\n\t\t\toptions?.messages === undefined ? undefined : Object.freeze({ ...options.messages })\n\n\t\tconst baseline: Record<string, FieldValue> = {}\n\n\t\tfor (const [name, value] of Object.entries(computeDefaults(this.#schema))) {\n\t\t\tdefineEntry(baseline, name, value)\n\t\t}\n\n\t\tfor (const [name, value] of Object.entries(options?.values ?? {})) {\n\t\t\tconst field = this.#requireField(name)\n\n\t\t\tif (!matchesField(field, value)) {\n\t\t\t\tthrow new FormError(\n\t\t\t\t\t'CONTROL',\n\t\t\t\t\t`The ${field.control} field \"${name}\" cannot hold that value`,\n\t\t\t\t\t{ field: name, control: field.control },\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tdefineEntry(baseline, name, cloneValue(value))\n\t\t}\n\n\t\tthis.#baseline = Object.freeze(baseline)\n\t\tthis.#values = {}\n\t\tfor (const [name, value] of Object.entries(baseline)) {\n\t\t\tdefineEntry(this.#values, name, value)\n\t\t}\n\t\t// Nobody has to await `answer`. Without a rejection handler of its own, destroying an\n\t\t// unawaited form would reject a promise no one is watching and take the host down with it.\n\t\tthis.#resolvers.promise.catch(() => undefined)\n\t\t// FormOptions carries `on` and `error` exactly as EmitterOptions declares them, so passing\n\t\t// the options through threads both without rebuilding a record `exactOptionalPropertyTypes`\n\t\t// would then reject for its explicit `undefined` members.\n\t\tthis.#emitter = new Emitter<FormEventMap>(options)\n\t\tthis.#evaluate()\n\t}\n\n\t/** Holds the form's event emitter. */\n\tget emitter(): EmitterInterface<FormEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Holds the schema this form asks, owned and frozen. */\n\tget schema(): FormSchema {\n\t\treturn this.#schema\n\t}\n\n\t/** Reports the answers the form holds. */\n\tget values(): FormValues {\n\t\tconst values: Record<string, FieldValue> = {}\n\n\t\t// Object.entries reads the own enumerable answer population; clear() walks the same one\n\t\t// through Object.keys.\n\t\tfor (const [name, value] of Object.entries(this.#values)) {\n\t\t\tdefineEntry(values, name, value)\n\t\t}\n\n\t\treturn Object.freeze(values)\n\t}\n\n\t/** Holds the answers the form opened with. */\n\tget baseline(): FormValues {\n\t\treturn this.#baseline\n\t}\n\n\t/** Holds every error the last completed evaluation produced. */\n\tget errors(): readonly FieldError[] {\n\t\treturn this.#errors\n\t}\n\n\t/** Lists the names of the fields somebody has visited. */\n\tget touched(): ReadonlySet<string> {\n\t\treturn new Set(this.#touched)\n\t}\n\n\t/** Lists the names of the fields that are out of the form. */\n\tget disabled(): ReadonlySet<string> {\n\t\tconst disabled = new Set<string>()\n\n\t\tfor (const field of this.#schema.fields) {\n\t\t\tif ((this.#disabled.get(field.name) ?? field.disabled === true) === true) {\n\t\t\t\tdisabled.add(field.name)\n\t\t\t}\n\t\t}\n\n\t\treturn disabled\n\t}\n\n\t/** Reports where the form sits in its life. */\n\tget status(): FormStatus {\n\t\treturn this.#status\n\t}\n\n\t/** Reports whether the last completed evaluation found no error. */\n\tget valid(): boolean {\n\t\treturn this.#errors.length === 0\n\t}\n\n\t/** Reports whether any answer has moved since the form opened. */\n\tget dirty(): boolean {\n\t\treturn !matchesValues(this.values, this.#baseline)\n\t}\n\n\t/**\n\t * Holds the answers after the form settles.\n\t *\n\t * @remarks\n\t * It resolves with the submitted values on the first valid submit, and rejects with a\n\t * {@link FormError} coded `ABANDONED` when teardown abandons the form before it settles.\n\t */\n\tget answer(): Promise<FormValues> {\n\t\treturn this.#resolvers.promise\n\t}\n\n\t/**\n\t * Finds one field by name.\n\t *\n\t * @param name - The field's name.\n\t * @returns The field, or `undefined` when the schema declares no such name.\n\t */\n\tfield(name: string): FormField | undefined {\n\t\treturn this.#schema.fields.find((field) => field.name === name)\n\t}\n\n\t/**\n\t * Answers several fields at once.\n\t *\n\t * @param values - The answers to write, each keyed by its field name.\n\t */\n\tfill(values: FormValues): void\n\t/**\n\t * Answers one field.\n\t *\n\t * @param name - The field's name.\n\t * @param value - The answer to write, or `undefined` to clear it.\n\t */\n\tfill(name: string, value: FieldValue | undefined): void\n\t/**\n\t * Answers one field or several.\n\t *\n\t * @param input - One field's name, or the answers to write keyed by field name.\n\t * @param value - The answer to write when `input` names one field.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, `FIELD`\n\t * when a name is not declared, and `CONTROL` when a value is one its control cannot hold.\n\t * Every answer is checked before any is written, so a refused write changes nothing.\n\t */\n\tfill(input: FormValues | string, value?: FieldValue): void {\n\t\tthis.#gate()\n\n\t\tconst entries: ReadonlyArray<readonly [string, FieldValue | undefined]> = isString(input)\n\t\t\t? [[input, value]]\n\t\t\t: Object.entries(input)\n\n\t\tfor (const [name, answer] of entries) {\n\t\t\tconst field = this.#requireField(name)\n\n\t\t\tif (answer !== undefined && !matchesField(field, answer)) {\n\t\t\t\tthrow new FormError(\n\t\t\t\t\t'CONTROL',\n\t\t\t\t\t`The ${field.control} field \"${name}\" cannot hold that value`,\n\t\t\t\t\t{ field: name, control: field.control },\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tthis.#batch(() => {\n\t\t\tconst moved: string[] = []\n\n\t\t\tfor (const [name, answer] of entries) {\n\t\t\t\tif (this.#differs(name, answer)) moved.push(name)\n\t\t\t\tif (answer === undefined) delete this.#values[name]\n\t\t\t\telse {\n\t\t\t\t\tdefineEntry(this.#values, name, cloneValue(answer))\n\t\t\t\t}\n\t\t\t\tthis.#invalidations.delete(name)\n\t\t\t}\n\n\t\t\tfor (const name of moved) {\n\t\t\t\tconst answer = Object.hasOwn(this.#values, name) ? this.#values[name] : undefined\n\t\t\t\tthis.#emitter.emit('fill', name, answer)\n\t\t\t}\n\t\t\tif (this.#evaluate()) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t/**\n\t * Records that somebody has visited a field.\n\t *\n\t * @param name - The field's name.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no such name.\n\t */\n\ttouch(name: string): void {\n\t\tthis.#gate()\n\t\tthis.#requireField(name)\n\t\tthis.#touched.add(name)\n\t}\n\n\t/**\n\t * Fails a field from outside, for what the rules cannot see.\n\t *\n\t * @param name - The field's name.\n\t * @param message - What to tell the person.\n\t * @remarks\n\t * One field holds one external failure: a second call replaces the first. The failure lasts\n\t * until that field is filled again or the form is cleared.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no such name.\n\t */\n\tinvalidate(name: string, message: string): void {\n\t\tthis.#gate()\n\t\tthis.#requireField(name)\n\t\tthis.#batch(() => {\n\t\t\tthis.#invalidations.set(name, message)\n\t\t\tif (this.#evaluate()) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t/** Takes every field out of the form. */\n\tdisable(): void\n\t/**\n\t * Takes one field out of the form.\n\t *\n\t * @param name - The field's name.\n\t */\n\tdisable(name: string): void\n\t/**\n\t * Takes several fields out of the form.\n\t *\n\t * @param names - The field names.\n\t */\n\tdisable(names: readonly string[]): void\n\t/**\n\t * Takes one or more fields out of the form.\n\t *\n\t * @param input - One field name, several names, or absence to select every field.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no requested name. Every name is checked before any field\n\t * moves.\n\t */\n\tdisable(input?: string | readonly string[]): void {\n\t\tthis.#gate()\n\t\tthis.#change(input, true)\n\t}\n\n\t/** Puts every field back into the form. */\n\tenable(): void\n\t/**\n\t * Puts one field back into the form.\n\t *\n\t * @param name - The field's name.\n\t */\n\tenable(name: string): void\n\t/**\n\t * Puts several fields back into the form.\n\t *\n\t * @param names - The field names.\n\t */\n\tenable(names: readonly string[]): void\n\t/**\n\t * Puts one or more fields back into the form.\n\t *\n\t * @param input - One field name, several names, or absence to select every field.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and\n\t * `FIELD` when the schema declares no requested name. Every name is checked before any field\n\t * moves.\n\t */\n\tenable(input?: string | readonly string[]): void {\n\t\tthis.#gate()\n\t\tthis.#change(input, false)\n\t}\n\n\t/**\n\t * Checks every answer and settles the form when they all pass.\n\t *\n\t * @returns The values on success, or every error that stopped them.\n\t * @remarks\n\t * A failed submit marks every enabled field touched, so a renderer can show the errors the\n\t * person has not reached yet. A disabled field is neither checked nor submitted. When a changed\n\t * evaluation notifies listeners and a listener writes, submit evaluates once more after those\n\t * listeners return and decides from that state. Listener work that settled the form wins: that\n\t * settlement is what this call returns, with no further evaluation, resolution, or `submit`\n\t * emission. An evaluation that already failed refuses with the list it checked, even when a\n\t * listener repaired or disabled the field that failed. An evaluation that passed decides from the\n\t * state the drain left, which is why one further evaluation bounds the drain rather than a\n\t * fixpoint loop.\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended.\n\t */\n\tsubmit(): FormResult {\n\t\tthis.#gate()\n\n\t\treturn this.#batch(() => {\n\t\t\tconst changed = this.#evaluate()\n\t\t\tconst checked = this.#errors\n\t\t\tconst failed = checked.length > 0\n\t\t\tconst evaluation = this.#evaluation\n\n\t\t\tif (changed) {\n\t\t\t\tthis.#emitter.emit('validate', this.#errors)\n\t\t\t\tconst settlement = this.#readSettlement()\n\t\t\t\tif (settlement !== undefined) return settlement\n\t\t\t\tif (this.#evaluation !== evaluation && this.#evaluate()) {\n\t\t\t\t\tthis.#emitter.emit('validate', this.#errors)\n\t\t\t\t\tconst drained = this.#readSettlement()\n\t\t\t\t\tif (drained !== undefined) return drained\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst errors = failed ? checked : this.#errors\n\t\t\tconst stopped = errors.length > 0\n\n\t\t\tif (stopped) {\n\t\t\t\tconst disabled = this.disabled\n\t\t\t\tfor (const field of this.#schema.fields) {\n\t\t\t\t\tif (!disabled.has(field.name)) this.#touched.add(field.name)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (stopped) return { success: false, error: errors }\n\n\t\t\tconst answers = this.#snapshot()\n\t\t\tthis.#status = 'settled'\n\t\t\tthis.#resolvers.resolve(answers)\n\t\t\tthis.#emitter.emit('submit', answers)\n\n\t\t\treturn { success: true, value: answers }\n\t\t})\n\t}\n\n\t/**\n\t * Returns every answer to the ones the form opened with: the schema's defaults, overlaid with\n\t * any seeded `values`. Reset the runtime disabled state to the schema's declarations.\n\t *\n\t * @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended.\n\t */\n\tclear(): void {\n\t\tthis.#gate()\n\n\t\tthis.#batch(() => {\n\t\t\tfor (const name of Object.keys(this.#values)) delete this.#values[name]\n\t\t\tfor (const [name, value] of Object.entries(this.#baseline)) {\n\t\t\t\tdefineEntry(this.#values, name, value)\n\t\t\t}\n\n\t\t\tthis.#touched.clear()\n\t\t\tthis.#disabled.clear()\n\t\t\tthis.#invalidations.clear()\n\n\t\t\tconst changed = this.#evaluate()\n\n\t\t\tthis.#emitter.emit('clear')\n\t\t\tif (changed) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t/**\n\t * Tears the form down, abandoning it when it has not settled.\n\t *\n\t * @remarks\n\t * Destroying twice does nothing the second time. A settled form keeps its `settled` status and\n\t * announces nothing. A request from inside a listener defers teardown until the outermost\n\t * mutation batch closes, so an in-flight settlement can win and leave the form `settled` rather\n\t * than `abandoned`. Every getter keeps answering afterwards; every write is refused.\n\t */\n\tdestroy(): void {\n\t\tif (this.#pending) return\n\n\t\tthis.#pending = true\n\t\tif (this.#batchDepth === 0) this.#teardown()\n\t}\n\n\t// Refuse a write to a form that settled before considering whether teardown was requested.\n\t#gate(): void {\n\t\tif (this.#status === 'settled') {\n\t\t\tthrow new FormError('SETTLED', 'The form has settled and cannot change')\n\t\t}\n\t\tif (this.#status === 'abandoned' || this.#pending) {\n\t\t\tthrow new FormError('ABANDONED', 'The form was abandoned and cannot change')\n\t\t}\n\t}\n\n\t#requireField(name: string): FormField {\n\t\tconst field = this.field(name)\n\n\t\tif (field === undefined) {\n\t\t\tthrow new FormError('FIELD', `The schema declares no field named \"${name}\"`, {\n\t\t\t\tfield: name,\n\t\t\t})\n\t\t}\n\n\t\treturn field\n\t}\n\n\t#change(input: string | readonly string[] | undefined, disabled: boolean): void {\n\t\tconst names = new Set(\n\t\t\tinput === undefined\n\t\t\t\t? this.#schema.fields.map((field) => field.name)\n\t\t\t\t: isString(input)\n\t\t\t\t\t? [input]\n\t\t\t\t\t: input,\n\t\t)\n\n\t\tfor (const name of names) this.#requireField(name)\n\n\t\tconst moved: string[] = []\n\t\tfor (const field of this.#schema.fields) {\n\t\t\tconst active = names.has(field.name)\n\t\t\tconst current = this.#disabled.get(field.name) ?? field.disabled === true\n\t\t\tif (active && current !== disabled) moved.push(field.name)\n\t\t}\n\t\tif (moved.length === 0) return\n\n\t\tthis.#batch(() => {\n\t\t\tfor (const name of names) this.#disabled.set(name, disabled)\n\n\t\t\tfor (const name of moved) {\n\t\t\t\tif (disabled) this.#emitter.emit('disable', name)\n\t\t\t\telse this.#emitter.emit('enable', name)\n\t\t\t}\n\n\t\t\tif (this.#evaluate()) this.#emitter.emit('validate', this.#errors)\n\t\t})\n\t}\n\n\t// Recompute the whole error list and cache it, reporting whether its content moved.\n\t#evaluate(): boolean {\n\t\tconst disabled = this.disabled\n\t\tconst options =\n\t\t\tthis.#messages === undefined ? { disabled } : { messages: this.#messages, disabled }\n\t\tconst errors: FieldError[] = [...evaluateForm(this.#schema, this.values, options)]\n\n\t\tfor (const [field, message] of this.#invalidations) {\n\t\t\tif (!disabled.has(field)) {\n\t\t\t\terrors.push(Object.freeze({ field, message }))\n\t\t\t}\n\t\t}\n\n\t\tconst previous = this.#errors\n\t\tconst next: readonly FieldError[] = Object.freeze(errors)\n\t\tthis.#errors = next\n\n\t\tconst changed =\n\t\t\tnext.length !== previous.length ||\n\t\t\tnext.some((error, index) => {\n\t\t\t\tconst before = previous[index]\n\t\t\t\treturn (\n\t\t\t\t\tbefore === undefined ||\n\t\t\t\t\tbefore.field !== error.field ||\n\t\t\t\t\tbefore.message !== error.message ||\n\t\t\t\t\tbefore.rule !== error.rule\n\t\t\t\t)\n\t\t\t})\n\t\tthis.#evaluation += 1\n\t\treturn changed\n\t}\n\n\t#differs(name: string, value: FieldValue | undefined): boolean {\n\t\tconst current = Object.hasOwn(this.#values, name) ? this.#values[name] : undefined\n\n\t\tif (value === undefined) return current !== undefined\n\t\tif (current === undefined) return true\n\t\treturn !matchesValue(current, value)\n\t}\n\n\t#readSettlement(): FormResult | undefined {\n\t\tif (this.#status === 'settled') return { success: true, value: this.#snapshot() }\n\t\tif (this.#status === 'abandoned') this.#gate()\n\t\treturn undefined\n\t}\n\n\t// The answers a submit hands over: every enabled field somebody has answered.\n\t#snapshot(): FormValues {\n\t\tconst answers: Record<string, FieldValue> = {}\n\t\tconst disabled = this.disabled\n\n\t\tfor (const field of this.#schema.fields) {\n\t\t\tconst value = Object.hasOwn(this.#values, field.name) ? this.#values[field.name] : undefined\n\t\t\tif (!disabled.has(field.name) && value !== undefined) {\n\t\t\t\tdefineEntry(answers, field.name, value)\n\t\t\t}\n\t\t}\n\n\t\treturn Object.freeze(answers)\n\t}\n\n\t#batch<T>(callback: () => T): T {\n\t\tthis.#batchDepth += 1\n\n\t\ttry {\n\t\t\treturn callback()\n\t\t} finally {\n\t\t\tthis.#batchDepth -= 1\n\t\t\tif (this.#batchDepth === 0 && this.#pending) this.#teardown()\n\t\t}\n\t}\n\n\t#teardown(): void {\n\t\tif (this.#status === 'editing') {\n\t\t\tthis.#status = 'abandoned'\n\t\t\tthis.#resolvers.reject(new FormError('ABANDONED', 'The form was destroyed before it settled'))\n\t\t\tthis.#emitter.emit('abandon')\n\t\t}\n\n\t\tthis.#emitter.destroy()\n\t}\n}\n","import type { FormInterface, FormOptions, FormSchema } from './types.js'\nimport { Form } from './Form.js'\n\n/**\n * Opens a form against a schema.\n *\n * @param schema - The form to ask. It is copied, and the copy is what the form asks.\n * @param options - The form's settings.\n * @returns A form open for answers.\n * @remarks\n * Prefer this at a call site that only needs {@link FormInterface}. `new Form(...)` is the same\n * construction and is what a class holding a form as its own field reaches for.\n * @throws A {@link FormError} coded `SCHEMA` when the schema is malformed, `FIELD` when\n * `options.values` names a field the schema does not declare, and `CONTROL` when a seeded value\n * is one its field's control cannot hold.\n * @example Open a form, answer it, and settle it\n * ```ts\n * import { createForm } from '@orkestrel/form'\n *\n * const form = createForm({\n * \tlabel: 'Sign up',\n * \tfields: [\n * \t\t{ control: 'text', name: 'email', label: 'Email', rule: { required: true, email: true } },\n * \t\t{ control: 'confirm', name: 'terms', label: 'I accept the terms', rule: { required: true } },\n * \t],\n * })\n *\n * form.fill({ email: 'ada@example.com', terms: true })\n * const result = form.submit() // { success: true, value: { email: 'ada@example.com', terms: true } }\n * const answers = await form.answer // { email: 'ada@example.com', terms: true }\n * ```\n */\nexport function createForm(schema: FormSchema, options?: FormOptions): FormInterface {\n\treturn new Form(schema, options)\n}\n"],"mapp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