litecms 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1387 -0
  3. package/dist/admin/CmsAdminLayout.d.ts +27 -0
  4. package/dist/admin/CmsAdminLayout.d.ts.map +1 -0
  5. package/dist/admin/CmsAdminPage.d.ts +31 -0
  6. package/dist/admin/CmsAdminPage.d.ts.map +1 -0
  7. package/dist/admin/config.d.ts +83 -0
  8. package/dist/admin/config.d.ts.map +1 -0
  9. package/dist/admin/config.js +53 -0
  10. package/dist/admin/exports.d.ts +7 -0
  11. package/dist/admin/exports.d.ts.map +1 -0
  12. package/dist/admin/exports.js +452 -0
  13. package/dist/admin/index.d.ts +147 -0
  14. package/dist/admin/index.d.ts.map +1 -0
  15. package/dist/components/CmsAutoForm.d.ts +73 -0
  16. package/dist/components/CmsAutoForm.d.ts.map +1 -0
  17. package/dist/components/CmsField.d.ts +50 -0
  18. package/dist/components/CmsField.d.ts.map +1 -0
  19. package/dist/components/CmsForm.d.ts +74 -0
  20. package/dist/components/CmsForm.d.ts.map +1 -0
  21. package/dist/components/CmsImageField.d.ts +33 -0
  22. package/dist/components/CmsImageField.d.ts.map +1 -0
  23. package/dist/components/CmsNavSection.d.ts +7 -0
  24. package/dist/components/CmsNavSection.d.ts.map +1 -0
  25. package/dist/components/CmsSimpleForm.d.ts +54 -0
  26. package/dist/components/CmsSimpleForm.d.ts.map +1 -0
  27. package/dist/components/index.d.ts +43 -0
  28. package/dist/components/index.d.ts.map +1 -0
  29. package/dist/components/index.js +619 -0
  30. package/dist/domain/index.d.ts +1 -0
  31. package/dist/domain/index.d.ts.map +1 -0
  32. package/dist/index-8zcd33mx.js +39 -0
  33. package/dist/index-pmb5m3ek.js +4135 -0
  34. package/dist/index.d.ts +4 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +32 -0
  37. package/dist/schema/index.d.ts +80 -0
  38. package/dist/schema/index.d.ts.map +1 -0
  39. package/dist/schema/index.js +46 -0
  40. package/dist/server/index.d.ts +79 -0
  41. package/dist/server/index.d.ts.map +1 -0
  42. package/dist/server/index.js +117 -0
  43. package/dist/shared/utils.d.ts +23 -0
  44. package/dist/shared/utils.d.ts.map +1 -0
  45. package/dist/storage/index.d.ts +86 -0
  46. package/dist/storage/index.d.ts.map +1 -0
  47. package/dist/storage/index.js +86 -0
  48. package/dist/stores/index.d.ts +1 -0
  49. package/dist/stores/index.d.ts.map +1 -0
  50. package/package.json +90 -0
@@ -0,0 +1,4135 @@
1
+ // node_modules/react-hook-form/dist/index.esm.mjs
2
+ import React from "react";
3
+ var isCheckBoxInput = (element) => element.type === "checkbox";
4
+ var isDateObject = (value) => value instanceof Date;
5
+ var isNullOrUndefined = (value) => value == null;
6
+ var isObjectType = (value) => typeof value === "object";
7
+ var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
8
+ var getEventValue = (event) => isObject(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;
9
+ var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
10
+ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
11
+ var isPlainObject = (tempObject) => {
12
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
13
+ return isObject(prototypeCopy) && prototypeCopy.hasOwnProperty("isPrototypeOf");
14
+ };
15
+ var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
16
+ function cloneObject(data) {
17
+ if (data instanceof Date) {
18
+ return new Date(data);
19
+ }
20
+ const isFileListInstance = typeof FileList !== "undefined" && data instanceof FileList;
21
+ if (isWeb && (data instanceof Blob || isFileListInstance)) {
22
+ return data;
23
+ }
24
+ const isArray = Array.isArray(data);
25
+ if (!isArray && !(isObject(data) && isPlainObject(data))) {
26
+ return data;
27
+ }
28
+ const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
29
+ for (const key in data) {
30
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
31
+ copy[key] = cloneObject(data[key]);
32
+ }
33
+ }
34
+ return copy;
35
+ }
36
+ var isKey = (value) => /^\w*$/.test(value);
37
+ var isUndefined = (val) => val === undefined;
38
+ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
39
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
40
+ var get = (object, path, defaultValue) => {
41
+ if (!path || !isObject(object)) {
42
+ return defaultValue;
43
+ }
44
+ const result = (isKey(path) ? [path] : stringToPath(path)).reduce((result2, key) => isNullOrUndefined(result2) ? result2 : result2[key], object);
45
+ return isUndefined(result) || result === object ? isUndefined(object[path]) ? defaultValue : object[path] : result;
46
+ };
47
+ var isBoolean = (value) => typeof value === "boolean";
48
+ var isFunction = (value) => typeof value === "function";
49
+ var set = (object, path, value) => {
50
+ let index = -1;
51
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
52
+ const length = tempPath.length;
53
+ const lastIndex = length - 1;
54
+ while (++index < length) {
55
+ const key = tempPath[index];
56
+ let newValue = value;
57
+ if (index !== lastIndex) {
58
+ const objValue = object[key];
59
+ newValue = isObject(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index + 1]) ? [] : {};
60
+ }
61
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
62
+ return;
63
+ }
64
+ object[key] = newValue;
65
+ object = object[key];
66
+ }
67
+ };
68
+ var EVENTS = {
69
+ BLUR: "blur",
70
+ FOCUS_OUT: "focusout",
71
+ CHANGE: "change"
72
+ };
73
+ var VALIDATION_MODE = {
74
+ onBlur: "onBlur",
75
+ onChange: "onChange",
76
+ onSubmit: "onSubmit",
77
+ onTouched: "onTouched",
78
+ all: "all"
79
+ };
80
+ var INPUT_VALIDATION_RULES = {
81
+ max: "max",
82
+ min: "min",
83
+ maxLength: "maxLength",
84
+ minLength: "minLength",
85
+ pattern: "pattern",
86
+ required: "required",
87
+ validate: "validate"
88
+ };
89
+ var HookFormControlContext = React.createContext(null);
90
+ HookFormControlContext.displayName = "HookFormControlContext";
91
+ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
92
+ const result = {
93
+ defaultValues: control._defaultValues
94
+ };
95
+ for (const key in formState) {
96
+ Object.defineProperty(result, key, {
97
+ get: () => {
98
+ const _key = key;
99
+ if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
100
+ control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
101
+ }
102
+ localProxyFormState && (localProxyFormState[_key] = true);
103
+ return formState[_key];
104
+ }
105
+ });
106
+ }
107
+ return result;
108
+ };
109
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
110
+ var isString = (value) => typeof value === "string";
111
+ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
112
+ if (isString(names)) {
113
+ isGlobal && _names.watch.add(names);
114
+ return get(formValues, names, defaultValue);
115
+ }
116
+ if (Array.isArray(names)) {
117
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
118
+ }
119
+ isGlobal && (_names.watchAll = true);
120
+ return formValues;
121
+ };
122
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
123
+ function deepEqual(object1, object2, _internal_visited = new WeakSet) {
124
+ if (isPrimitive(object1) || isPrimitive(object2)) {
125
+ return Object.is(object1, object2);
126
+ }
127
+ if (isDateObject(object1) && isDateObject(object2)) {
128
+ return Object.is(object1.getTime(), object2.getTime());
129
+ }
130
+ const keys1 = Object.keys(object1);
131
+ const keys2 = Object.keys(object2);
132
+ if (keys1.length !== keys2.length) {
133
+ return false;
134
+ }
135
+ if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
136
+ return true;
137
+ }
138
+ _internal_visited.add(object1);
139
+ _internal_visited.add(object2);
140
+ for (const key of keys1) {
141
+ const val1 = object1[key];
142
+ if (!keys2.includes(key)) {
143
+ return false;
144
+ }
145
+ if (key !== "ref") {
146
+ const val2 = object2[key];
147
+ if (isDateObject(val1) && isDateObject(val2) || isObject(val1) && isObject(val2) || Array.isArray(val1) && Array.isArray(val2) ? !deepEqual(val1, val2, _internal_visited) : !Object.is(val1, val2)) {
148
+ return false;
149
+ }
150
+ }
151
+ }
152
+ return true;
153
+ }
154
+ var HookFormContext = React.createContext(null);
155
+ HookFormContext.displayName = "HookFormContext";
156
+ var useFormContext = () => React.useContext(HookFormContext);
157
+ var FormProvider = (props) => {
158
+ const { children, watch, getValues, getFieldState, setError, clearErrors, setValue, trigger, formState, resetField, reset, handleSubmit, unregister, control, register, setFocus, subscribe } = props;
159
+ return React.createElement(HookFormContext.Provider, { value: React.useMemo(() => ({
160
+ watch,
161
+ getValues,
162
+ getFieldState,
163
+ setError,
164
+ clearErrors,
165
+ setValue,
166
+ trigger,
167
+ formState,
168
+ resetField,
169
+ reset,
170
+ handleSubmit,
171
+ unregister,
172
+ control,
173
+ register,
174
+ setFocus,
175
+ subscribe
176
+ }), [
177
+ clearErrors,
178
+ control,
179
+ formState,
180
+ getFieldState,
181
+ getValues,
182
+ handleSubmit,
183
+ register,
184
+ reset,
185
+ resetField,
186
+ setError,
187
+ setFocus,
188
+ setValue,
189
+ subscribe,
190
+ trigger,
191
+ unregister,
192
+ watch
193
+ ]) }, React.createElement(HookFormControlContext.Provider, { value: control }, children));
194
+ };
195
+ var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria ? {
196
+ ...errors[name],
197
+ types: {
198
+ ...errors[name] && errors[name].types ? errors[name].types : {},
199
+ [type]: message || true
200
+ }
201
+ } : {};
202
+ var convertToArrayPayload = (value) => Array.isArray(value) ? value : [value];
203
+ var createSubject = () => {
204
+ let _observers = [];
205
+ const next = (value) => {
206
+ for (const observer of _observers) {
207
+ observer.next && observer.next(value);
208
+ }
209
+ };
210
+ const subscribe = (observer) => {
211
+ _observers.push(observer);
212
+ return {
213
+ unsubscribe: () => {
214
+ _observers = _observers.filter((o) => o !== observer);
215
+ }
216
+ };
217
+ };
218
+ const unsubscribe = () => {
219
+ _observers = [];
220
+ };
221
+ return {
222
+ get observers() {
223
+ return _observers;
224
+ },
225
+ next,
226
+ subscribe,
227
+ unsubscribe
228
+ };
229
+ };
230
+ function extractFormValues(fieldsState, formValues) {
231
+ const values = {};
232
+ for (const key in fieldsState) {
233
+ if (fieldsState.hasOwnProperty(key)) {
234
+ const fieldState = fieldsState[key];
235
+ const fieldValue = formValues[key];
236
+ if (fieldState && isObject(fieldState) && fieldValue) {
237
+ const nestedFieldsState = extractFormValues(fieldState, fieldValue);
238
+ if (isObject(nestedFieldsState)) {
239
+ values[key] = nestedFieldsState;
240
+ }
241
+ } else if (fieldsState[key]) {
242
+ values[key] = fieldValue;
243
+ }
244
+ }
245
+ }
246
+ return values;
247
+ }
248
+ var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
249
+ var isFileInput = (element) => element.type === "file";
250
+ var isHTMLElement = (value) => {
251
+ if (!isWeb) {
252
+ return false;
253
+ }
254
+ const owner = value ? value.ownerDocument : 0;
255
+ return value instanceof (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement);
256
+ };
257
+ var isMultipleSelect = (element) => element.type === `select-multiple`;
258
+ var isRadioInput = (element) => element.type === "radio";
259
+ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
260
+ var live = (ref) => isHTMLElement(ref) && ref.isConnected;
261
+ function baseGet(object, updatePath) {
262
+ const length = updatePath.slice(0, -1).length;
263
+ let index = 0;
264
+ while (index < length) {
265
+ object = isUndefined(object) ? index++ : object[updatePath[index++]];
266
+ }
267
+ return object;
268
+ }
269
+ function isEmptyArray(obj) {
270
+ for (const key in obj) {
271
+ if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
272
+ return false;
273
+ }
274
+ }
275
+ return true;
276
+ }
277
+ function unset(object, path) {
278
+ const paths = Array.isArray(path) ? path : isKey(path) ? [path] : stringToPath(path);
279
+ const childObject = paths.length === 1 ? object : baseGet(object, paths);
280
+ const index = paths.length - 1;
281
+ const key = paths[index];
282
+ if (childObject) {
283
+ delete childObject[key];
284
+ }
285
+ if (index !== 0 && (isObject(childObject) && isEmptyObject(childObject) || Array.isArray(childObject) && isEmptyArray(childObject))) {
286
+ unset(object, paths.slice(0, -1));
287
+ }
288
+ return object;
289
+ }
290
+ var objectHasFunction = (data) => {
291
+ for (const key in data) {
292
+ if (isFunction(data[key])) {
293
+ return true;
294
+ }
295
+ }
296
+ return false;
297
+ };
298
+ function isTraversable(value) {
299
+ return Array.isArray(value) || isObject(value) && !objectHasFunction(value);
300
+ }
301
+ function markFieldsDirty(data, fields = {}) {
302
+ for (const key in data) {
303
+ const value = data[key];
304
+ if (isTraversable(value)) {
305
+ fields[key] = Array.isArray(value) ? [] : {};
306
+ markFieldsDirty(value, fields[key]);
307
+ } else if (!isUndefined(value)) {
308
+ fields[key] = true;
309
+ }
310
+ }
311
+ return fields;
312
+ }
313
+ function getDirtyFields(data, formValues, dirtyFieldsFromValues) {
314
+ if (!dirtyFieldsFromValues) {
315
+ dirtyFieldsFromValues = markFieldsDirty(formValues);
316
+ }
317
+ for (const key in data) {
318
+ const value = data[key];
319
+ if (isTraversable(value)) {
320
+ if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
321
+ dirtyFieldsFromValues[key] = markFieldsDirty(value, Array.isArray(value) ? [] : {});
322
+ } else {
323
+ getDirtyFields(value, isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
324
+ }
325
+ } else {
326
+ const formValue = formValues[key];
327
+ dirtyFieldsFromValues[key] = !deepEqual(value, formValue);
328
+ }
329
+ }
330
+ return dirtyFieldsFromValues;
331
+ }
332
+ var defaultResult = {
333
+ value: false,
334
+ isValid: false
335
+ };
336
+ var validResult = { value: true, isValid: true };
337
+ var getCheckboxValue = (options) => {
338
+ if (Array.isArray(options)) {
339
+ if (options.length > 1) {
340
+ const values = options.filter((option) => option && option.checked && !option.disabled).map((option) => option.value);
341
+ return { value: values, isValid: !!values.length };
342
+ }
343
+ return options[0].checked && !options[0].disabled ? options[0].attributes && !isUndefined(options[0].attributes.value) ? isUndefined(options[0].value) || options[0].value === "" ? validResult : { value: options[0].value, isValid: true } : validResult : defaultResult;
344
+ }
345
+ return defaultResult;
346
+ };
347
+ var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value) ? value : valueAsNumber ? value === "" ? NaN : value ? +value : value : valueAsDate && isString(value) ? new Date(value) : setValueAs ? setValueAs(value) : value;
348
+ var defaultReturn = {
349
+ isValid: false,
350
+ value: null
351
+ };
352
+ var getRadioValue = (options) => Array.isArray(options) ? options.reduce((previous, option) => option && option.checked && !option.disabled ? {
353
+ isValid: true,
354
+ value: option.value
355
+ } : previous, defaultReturn) : defaultReturn;
356
+ function getFieldValue(_f) {
357
+ const ref = _f.ref;
358
+ if (isFileInput(ref)) {
359
+ return ref.files;
360
+ }
361
+ if (isRadioInput(ref)) {
362
+ return getRadioValue(_f.refs).value;
363
+ }
364
+ if (isMultipleSelect(ref)) {
365
+ return [...ref.selectedOptions].map(({ value }) => value);
366
+ }
367
+ if (isCheckBoxInput(ref)) {
368
+ return getCheckboxValue(_f.refs).value;
369
+ }
370
+ return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
371
+ }
372
+ var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
373
+ const fields = {};
374
+ for (const name of fieldsNames) {
375
+ const field = get(_fields, name);
376
+ field && set(fields, name, field._f);
377
+ }
378
+ return {
379
+ criteriaMode,
380
+ names: [...fieldsNames],
381
+ fields,
382
+ shouldUseNativeValidation
383
+ };
384
+ };
385
+ var isRegex = (value) => value instanceof RegExp;
386
+ var getRuleValue = (rule) => isUndefined(rule) ? rule : isRegex(rule) ? rule.source : isObject(rule) ? isRegex(rule.value) ? rule.value.source : rule.value : rule;
387
+ var getValidationModes = (mode) => ({
388
+ isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
389
+ isOnBlur: mode === VALIDATION_MODE.onBlur,
390
+ isOnChange: mode === VALIDATION_MODE.onChange,
391
+ isOnAll: mode === VALIDATION_MODE.all,
392
+ isOnTouch: mode === VALIDATION_MODE.onTouched
393
+ });
394
+ var ASYNC_FUNCTION = "AsyncFunction";
395
+ var hasPromiseValidation = (fieldReference) => !!fieldReference && !!fieldReference.validate && !!(isFunction(fieldReference.validate) && fieldReference.validate.constructor.name === ASYNC_FUNCTION || isObject(fieldReference.validate) && Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION));
396
+ var hasValidation = (options) => options.mount && (options.required || options.min || options.max || options.maxLength || options.minLength || options.pattern || options.validate);
397
+ var isWatched = (name, _names, isBlurEvent) => !isBlurEvent && (_names.watchAll || _names.watch.has(name) || [..._names.watch].some((watchName) => name.startsWith(watchName) && /^\.\w+/.test(name.slice(watchName.length))));
398
+ var iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
399
+ for (const key of fieldsNames || Object.keys(fields)) {
400
+ const field = get(fields, key);
401
+ if (field) {
402
+ const { _f, ...currentField } = field;
403
+ if (_f) {
404
+ if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
405
+ return true;
406
+ } else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
407
+ return true;
408
+ } else {
409
+ if (iterateFieldsByAction(currentField, action)) {
410
+ break;
411
+ }
412
+ }
413
+ } else if (isObject(currentField)) {
414
+ if (iterateFieldsByAction(currentField, action)) {
415
+ break;
416
+ }
417
+ }
418
+ }
419
+ }
420
+ return;
421
+ };
422
+ function schemaErrorLookup(errors, _fields, name) {
423
+ const error = get(errors, name);
424
+ if (error || isKey(name)) {
425
+ return {
426
+ error,
427
+ name
428
+ };
429
+ }
430
+ const names = name.split(".");
431
+ while (names.length) {
432
+ const fieldName = names.join(".");
433
+ const field = get(_fields, fieldName);
434
+ const foundError = get(errors, fieldName);
435
+ if (field && !Array.isArray(field) && name !== fieldName) {
436
+ return { name };
437
+ }
438
+ if (foundError && foundError.type) {
439
+ return {
440
+ name: fieldName,
441
+ error: foundError
442
+ };
443
+ }
444
+ if (foundError && foundError.root && foundError.root.type) {
445
+ return {
446
+ name: `${fieldName}.root`,
447
+ error: foundError.root
448
+ };
449
+ }
450
+ names.pop();
451
+ }
452
+ return {
453
+ name
454
+ };
455
+ }
456
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
457
+ updateFormState(formStateData);
458
+ const { name, ...formState } = formStateData;
459
+ return isEmptyObject(formState) || Object.keys(formState).length >= Object.keys(_proxyFormState).length || Object.keys(formState).find((key) => _proxyFormState[key] === (!isRoot || VALIDATION_MODE.all));
460
+ };
461
+ var shouldSubscribeByName = (name, signalName, exact) => !name || !signalName || name === signalName || convertToArrayPayload(name).some((currentName) => currentName && (exact ? currentName === signalName : currentName.startsWith(signalName) || signalName.startsWith(currentName)));
462
+ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
463
+ if (mode.isOnAll) {
464
+ return false;
465
+ } else if (!isSubmitted && mode.isOnTouch) {
466
+ return !(isTouched || isBlurEvent);
467
+ } else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
468
+ return !isBlurEvent;
469
+ } else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
470
+ return isBlurEvent;
471
+ }
472
+ return true;
473
+ };
474
+ var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
475
+ var updateFieldArrayRootError = (errors, error, name) => {
476
+ const fieldArrayErrors = convertToArrayPayload(get(errors, name));
477
+ set(fieldArrayErrors, "root", error[name]);
478
+ set(errors, name, fieldArrayErrors);
479
+ return errors;
480
+ };
481
+ function getValidateError(result, ref, type = "validate") {
482
+ if (isString(result) || Array.isArray(result) && result.every(isString) || isBoolean(result) && !result) {
483
+ return {
484
+ type,
485
+ message: isString(result) ? result : "",
486
+ ref
487
+ };
488
+ }
489
+ }
490
+ var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData) ? validationData : {
491
+ value: validationData,
492
+ message: ""
493
+ };
494
+ var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
495
+ const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount } = field._f;
496
+ const inputValue = get(formValues, name);
497
+ if (!mount || disabledFieldNames.has(name)) {
498
+ return {};
499
+ }
500
+ const inputRef = refs ? refs[0] : ref;
501
+ const setCustomValidity = (message) => {
502
+ if (shouldUseNativeValidation && inputRef.reportValidity) {
503
+ inputRef.setCustomValidity(isBoolean(message) ? "" : message || "");
504
+ inputRef.reportValidity();
505
+ }
506
+ };
507
+ const error = {};
508
+ const isRadio = isRadioInput(ref);
509
+ const isCheckBox = isCheckBoxInput(ref);
510
+ const isRadioOrCheckbox2 = isRadio || isCheckBox;
511
+ const isEmpty = (valueAsNumber || isFileInput(ref)) && isUndefined(ref.value) && isUndefined(inputValue) || isHTMLElement(ref) && ref.value === "" || inputValue === "" || Array.isArray(inputValue) && !inputValue.length;
512
+ const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
513
+ const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
514
+ const message = exceedMax ? maxLengthMessage : minLengthMessage;
515
+ error[name] = {
516
+ type: exceedMax ? maxType : minType,
517
+ message,
518
+ ref,
519
+ ...appendErrorsCurry(exceedMax ? maxType : minType, message)
520
+ };
521
+ };
522
+ if (isFieldArray ? !Array.isArray(inputValue) || !inputValue.length : required && (!isRadioOrCheckbox2 && (isEmpty || isNullOrUndefined(inputValue)) || isBoolean(inputValue) && !inputValue || isCheckBox && !getCheckboxValue(refs).isValid || isRadio && !getRadioValue(refs).isValid)) {
523
+ const { value, message } = isString(required) ? { value: !!required, message: required } : getValueAndMessage(required);
524
+ if (value) {
525
+ error[name] = {
526
+ type: INPUT_VALIDATION_RULES.required,
527
+ message,
528
+ ref: inputRef,
529
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message)
530
+ };
531
+ if (!validateAllFieldCriteria) {
532
+ setCustomValidity(message);
533
+ return error;
534
+ }
535
+ }
536
+ }
537
+ if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
538
+ let exceedMax;
539
+ let exceedMin;
540
+ const maxOutput = getValueAndMessage(max);
541
+ const minOutput = getValueAndMessage(min);
542
+ if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
543
+ const valueNumber = ref.valueAsNumber || (inputValue ? +inputValue : inputValue);
544
+ if (!isNullOrUndefined(maxOutput.value)) {
545
+ exceedMax = valueNumber > maxOutput.value;
546
+ }
547
+ if (!isNullOrUndefined(minOutput.value)) {
548
+ exceedMin = valueNumber < minOutput.value;
549
+ }
550
+ } else {
551
+ const valueDate = ref.valueAsDate || new Date(inputValue);
552
+ const convertTimeToDate = (time) => new Date(new Date().toDateString() + " " + time);
553
+ const isTime = ref.type == "time";
554
+ const isWeek = ref.type == "week";
555
+ if (isString(maxOutput.value) && inputValue) {
556
+ exceedMax = isTime ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value) : isWeek ? inputValue > maxOutput.value : valueDate > new Date(maxOutput.value);
557
+ }
558
+ if (isString(minOutput.value) && inputValue) {
559
+ exceedMin = isTime ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value) : isWeek ? inputValue < minOutput.value : valueDate < new Date(minOutput.value);
560
+ }
561
+ }
562
+ if (exceedMax || exceedMin) {
563
+ getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
564
+ if (!validateAllFieldCriteria) {
565
+ setCustomValidity(error[name].message);
566
+ return error;
567
+ }
568
+ }
569
+ }
570
+ if ((maxLength || minLength) && !isEmpty && (isString(inputValue) || isFieldArray && Array.isArray(inputValue))) {
571
+ const maxLengthOutput = getValueAndMessage(maxLength);
572
+ const minLengthOutput = getValueAndMessage(minLength);
573
+ const exceedMax = !isNullOrUndefined(maxLengthOutput.value) && inputValue.length > +maxLengthOutput.value;
574
+ const exceedMin = !isNullOrUndefined(minLengthOutput.value) && inputValue.length < +minLengthOutput.value;
575
+ if (exceedMax || exceedMin) {
576
+ getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
577
+ if (!validateAllFieldCriteria) {
578
+ setCustomValidity(error[name].message);
579
+ return error;
580
+ }
581
+ }
582
+ }
583
+ if (pattern && !isEmpty && isString(inputValue)) {
584
+ const { value: patternValue, message } = getValueAndMessage(pattern);
585
+ if (isRegex(patternValue) && !inputValue.match(patternValue)) {
586
+ error[name] = {
587
+ type: INPUT_VALIDATION_RULES.pattern,
588
+ message,
589
+ ref,
590
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message)
591
+ };
592
+ if (!validateAllFieldCriteria) {
593
+ setCustomValidity(message);
594
+ return error;
595
+ }
596
+ }
597
+ }
598
+ if (validate) {
599
+ if (isFunction(validate)) {
600
+ const result = await validate(inputValue, formValues);
601
+ const validateError = getValidateError(result, inputRef);
602
+ if (validateError) {
603
+ error[name] = {
604
+ ...validateError,
605
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message)
606
+ };
607
+ if (!validateAllFieldCriteria) {
608
+ setCustomValidity(validateError.message);
609
+ return error;
610
+ }
611
+ }
612
+ } else if (isObject(validate)) {
613
+ let validationResult = {};
614
+ for (const key in validate) {
615
+ if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
616
+ break;
617
+ }
618
+ const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
619
+ if (validateError) {
620
+ validationResult = {
621
+ ...validateError,
622
+ ...appendErrorsCurry(key, validateError.message)
623
+ };
624
+ setCustomValidity(validateError.message);
625
+ if (validateAllFieldCriteria) {
626
+ error[name] = validationResult;
627
+ }
628
+ }
629
+ }
630
+ if (!isEmptyObject(validationResult)) {
631
+ error[name] = {
632
+ ref: inputRef,
633
+ ...validationResult
634
+ };
635
+ if (!validateAllFieldCriteria) {
636
+ return error;
637
+ }
638
+ }
639
+ }
640
+ }
641
+ setCustomValidity(true);
642
+ return error;
643
+ };
644
+ var defaultOptions = {
645
+ mode: VALIDATION_MODE.onSubmit,
646
+ reValidateMode: VALIDATION_MODE.onChange,
647
+ shouldFocusError: true
648
+ };
649
+ function createFormControl(props = {}) {
650
+ let _options = {
651
+ ...defaultOptions,
652
+ ...props
653
+ };
654
+ let _formState = {
655
+ submitCount: 0,
656
+ isDirty: false,
657
+ isReady: false,
658
+ isLoading: isFunction(_options.defaultValues),
659
+ isValidating: false,
660
+ isSubmitted: false,
661
+ isSubmitting: false,
662
+ isSubmitSuccessful: false,
663
+ isValid: false,
664
+ touchedFields: {},
665
+ dirtyFields: {},
666
+ validatingFields: {},
667
+ errors: _options.errors || {},
668
+ disabled: _options.disabled || false
669
+ };
670
+ let _fields = {};
671
+ let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values) ? cloneObject(_options.defaultValues || _options.values) || {} : {};
672
+ let _formValues = _options.shouldUnregister ? {} : cloneObject(_defaultValues);
673
+ let _state = {
674
+ action: false,
675
+ mount: false,
676
+ watch: false,
677
+ keepIsValid: false
678
+ };
679
+ let _names = {
680
+ mount: new Set,
681
+ disabled: new Set,
682
+ unMount: new Set,
683
+ array: new Set,
684
+ watch: new Set
685
+ };
686
+ let delayErrorCallback;
687
+ let timer = 0;
688
+ const defaultProxyFormState = {
689
+ isDirty: false,
690
+ dirtyFields: false,
691
+ validatingFields: false,
692
+ touchedFields: false,
693
+ isValidating: false,
694
+ isValid: false,
695
+ errors: false
696
+ };
697
+ const _proxyFormState = {
698
+ ...defaultProxyFormState
699
+ };
700
+ let _proxySubscribeFormState = {
701
+ ..._proxyFormState
702
+ };
703
+ const _subjects = {
704
+ array: createSubject(),
705
+ state: createSubject()
706
+ };
707
+ const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
708
+ const debounce = (callback) => (wait) => {
709
+ clearTimeout(timer);
710
+ timer = setTimeout(callback, wait);
711
+ };
712
+ const _setValid = async (shouldUpdateValid) => {
713
+ if (_state.keepIsValid) {
714
+ return;
715
+ }
716
+ if (!_options.disabled && (_proxyFormState.isValid || _proxySubscribeFormState.isValid || shouldUpdateValid)) {
717
+ let isValid;
718
+ if (_options.resolver) {
719
+ isValid = isEmptyObject((await _runSchema()).errors);
720
+ _updateIsValidating();
721
+ } else {
722
+ isValid = await executeBuiltInValidation(_fields, true);
723
+ }
724
+ if (isValid !== _formState.isValid) {
725
+ _subjects.state.next({
726
+ isValid
727
+ });
728
+ }
729
+ }
730
+ };
731
+ const _updateIsValidating = (names, isValidating) => {
732
+ if (!_options.disabled && (_proxyFormState.isValidating || _proxyFormState.validatingFields || _proxySubscribeFormState.isValidating || _proxySubscribeFormState.validatingFields)) {
733
+ (names || Array.from(_names.mount)).forEach((name) => {
734
+ if (name) {
735
+ isValidating ? set(_formState.validatingFields, name, isValidating) : unset(_formState.validatingFields, name);
736
+ }
737
+ });
738
+ _subjects.state.next({
739
+ validatingFields: _formState.validatingFields,
740
+ isValidating: !isEmptyObject(_formState.validatingFields)
741
+ });
742
+ }
743
+ };
744
+ const _setFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
745
+ if (args && method && !_options.disabled) {
746
+ _state.action = true;
747
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
748
+ const fieldValues = method(get(_fields, name), args.argA, args.argB);
749
+ shouldSetValues && set(_fields, name, fieldValues);
750
+ }
751
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_formState.errors, name))) {
752
+ const errors = method(get(_formState.errors, name), args.argA, args.argB);
753
+ shouldSetValues && set(_formState.errors, name, errors);
754
+ unsetEmptyArray(_formState.errors, name);
755
+ }
756
+ if ((_proxyFormState.touchedFields || _proxySubscribeFormState.touchedFields) && shouldUpdateFieldsAndState && Array.isArray(get(_formState.touchedFields, name))) {
757
+ const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
758
+ shouldSetValues && set(_formState.touchedFields, name, touchedFields);
759
+ }
760
+ if (_proxyFormState.dirtyFields || _proxySubscribeFormState.dirtyFields) {
761
+ _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
762
+ }
763
+ _subjects.state.next({
764
+ name,
765
+ isDirty: _getDirty(name, values),
766
+ dirtyFields: _formState.dirtyFields,
767
+ errors: _formState.errors,
768
+ isValid: _formState.isValid
769
+ });
770
+ } else {
771
+ set(_formValues, name, values);
772
+ }
773
+ };
774
+ const updateErrors = (name, error) => {
775
+ set(_formState.errors, name, error);
776
+ _subjects.state.next({
777
+ errors: _formState.errors
778
+ });
779
+ };
780
+ const _setErrors = (errors) => {
781
+ _formState.errors = errors;
782
+ _subjects.state.next({
783
+ errors: _formState.errors,
784
+ isValid: false
785
+ });
786
+ };
787
+ const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
788
+ const field = get(_fields, name);
789
+ if (field) {
790
+ const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
791
+ isUndefined(defaultValue) || ref && ref.defaultChecked || shouldSkipSetValueAs ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f)) : setFieldValue(name, defaultValue);
792
+ _state.mount && !_state.action && _setValid();
793
+ }
794
+ };
795
+ const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
796
+ let shouldUpdateField = false;
797
+ let isPreviousDirty = false;
798
+ const output = {
799
+ name
800
+ };
801
+ if (!_options.disabled) {
802
+ if (!isBlurEvent || shouldDirty) {
803
+ if (_proxyFormState.isDirty || _proxySubscribeFormState.isDirty) {
804
+ isPreviousDirty = _formState.isDirty;
805
+ _formState.isDirty = output.isDirty = _getDirty();
806
+ shouldUpdateField = isPreviousDirty !== output.isDirty;
807
+ }
808
+ const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
809
+ isPreviousDirty = !!get(_formState.dirtyFields, name);
810
+ isCurrentFieldPristine ? unset(_formState.dirtyFields, name) : set(_formState.dirtyFields, name, true);
811
+ output.dirtyFields = _formState.dirtyFields;
812
+ shouldUpdateField = shouldUpdateField || (_proxyFormState.dirtyFields || _proxySubscribeFormState.dirtyFields) && isPreviousDirty !== !isCurrentFieldPristine;
813
+ }
814
+ if (isBlurEvent) {
815
+ const isPreviousFieldTouched = get(_formState.touchedFields, name);
816
+ if (!isPreviousFieldTouched) {
817
+ set(_formState.touchedFields, name, isBlurEvent);
818
+ output.touchedFields = _formState.touchedFields;
819
+ shouldUpdateField = shouldUpdateField || (_proxyFormState.touchedFields || _proxySubscribeFormState.touchedFields) && isPreviousFieldTouched !== isBlurEvent;
820
+ }
821
+ }
822
+ shouldUpdateField && shouldRender && _subjects.state.next(output);
823
+ }
824
+ return shouldUpdateField ? output : {};
825
+ };
826
+ const shouldRenderByError = (name, isValid, error, fieldState) => {
827
+ const previousFieldError = get(_formState.errors, name);
828
+ const shouldUpdateValid = (_proxyFormState.isValid || _proxySubscribeFormState.isValid) && isBoolean(isValid) && _formState.isValid !== isValid;
829
+ if (_options.delayError && error) {
830
+ delayErrorCallback = debounce(() => updateErrors(name, error));
831
+ delayErrorCallback(_options.delayError);
832
+ } else {
833
+ clearTimeout(timer);
834
+ delayErrorCallback = null;
835
+ error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
836
+ }
837
+ if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) || !isEmptyObject(fieldState) || shouldUpdateValid) {
838
+ const updatedFormState = {
839
+ ...fieldState,
840
+ ...shouldUpdateValid && isBoolean(isValid) ? { isValid } : {},
841
+ errors: _formState.errors,
842
+ name
843
+ };
844
+ _formState = {
845
+ ..._formState,
846
+ ...updatedFormState
847
+ };
848
+ _subjects.state.next(updatedFormState);
849
+ }
850
+ };
851
+ const _runSchema = async (name) => {
852
+ _updateIsValidating(name, true);
853
+ const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
854
+ return result;
855
+ };
856
+ const executeSchemaAndUpdateState = async (names) => {
857
+ const { errors } = await _runSchema(names);
858
+ _updateIsValidating(names);
859
+ if (names) {
860
+ for (const name of names) {
861
+ const error = get(errors, name);
862
+ error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
863
+ }
864
+ } else {
865
+ _formState.errors = errors;
866
+ }
867
+ return errors;
868
+ };
869
+ const executeBuiltInValidation = async (fields, shouldOnlyCheckValid, context = {
870
+ valid: true
871
+ }) => {
872
+ for (const name in fields) {
873
+ const field = fields[name];
874
+ if (field) {
875
+ const { _f, ...fieldValue } = field;
876
+ if (_f) {
877
+ const isFieldArrayRoot = _names.array.has(_f.name);
878
+ const isPromiseFunction = field._f && hasPromiseValidation(field._f);
879
+ if (isPromiseFunction && _proxyFormState.validatingFields) {
880
+ _updateIsValidating([_f.name], true);
881
+ }
882
+ const fieldError = await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
883
+ if (isPromiseFunction && _proxyFormState.validatingFields) {
884
+ _updateIsValidating([_f.name]);
885
+ }
886
+ if (fieldError[_f.name]) {
887
+ context.valid = false;
888
+ if (shouldOnlyCheckValid || props.shouldUseNativeValidation) {
889
+ break;
890
+ }
891
+ }
892
+ !shouldOnlyCheckValid && (get(fieldError, _f.name) ? isFieldArrayRoot ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name) : set(_formState.errors, _f.name, fieldError[_f.name]) : unset(_formState.errors, _f.name));
893
+ }
894
+ !isEmptyObject(fieldValue) && await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context);
895
+ }
896
+ }
897
+ return context.valid;
898
+ };
899
+ const _removeUnmounted = () => {
900
+ for (const name of _names.unMount) {
901
+ const field = get(_fields, name);
902
+ field && (field._f.refs ? field._f.refs.every((ref) => !live(ref)) : !live(field._f.ref)) && unregister(name);
903
+ }
904
+ _names.unMount = new Set;
905
+ };
906
+ const _getDirty = (name, data) => !_options.disabled && (name && data && set(_formValues, name, data), !deepEqual(getValues(), _defaultValues));
907
+ const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
908
+ ..._state.mount ? _formValues : isUndefined(defaultValue) ? _defaultValues : isString(names) ? { [names]: defaultValue } : defaultValue
909
+ }, isGlobal, defaultValue);
910
+ const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
911
+ const setFieldValue = (name, value, options = {}) => {
912
+ const field = get(_fields, name);
913
+ let fieldValue = value;
914
+ if (field) {
915
+ const fieldReference = field._f;
916
+ if (fieldReference) {
917
+ !fieldReference.disabled && set(_formValues, name, getFieldValueAs(value, fieldReference));
918
+ fieldValue = isHTMLElement(fieldReference.ref) && isNullOrUndefined(value) ? "" : value;
919
+ if (isMultipleSelect(fieldReference.ref)) {
920
+ [...fieldReference.ref.options].forEach((optionRef) => optionRef.selected = fieldValue.includes(optionRef.value));
921
+ } else if (fieldReference.refs) {
922
+ if (isCheckBoxInput(fieldReference.ref)) {
923
+ fieldReference.refs.forEach((checkboxRef) => {
924
+ if (!checkboxRef.defaultChecked || !checkboxRef.disabled) {
925
+ if (Array.isArray(fieldValue)) {
926
+ checkboxRef.checked = !!fieldValue.find((data) => data === checkboxRef.value);
927
+ } else {
928
+ checkboxRef.checked = fieldValue === checkboxRef.value || !!fieldValue;
929
+ }
930
+ }
931
+ });
932
+ } else {
933
+ fieldReference.refs.forEach((radioRef) => radioRef.checked = radioRef.value === fieldValue);
934
+ }
935
+ } else if (isFileInput(fieldReference.ref)) {
936
+ fieldReference.ref.value = "";
937
+ } else {
938
+ fieldReference.ref.value = fieldValue;
939
+ if (!fieldReference.ref.type) {
940
+ _subjects.state.next({
941
+ name,
942
+ values: cloneObject(_formValues)
943
+ });
944
+ }
945
+ }
946
+ }
947
+ }
948
+ (options.shouldDirty || options.shouldTouch) && updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
949
+ options.shouldValidate && trigger(name);
950
+ };
951
+ const setValues = (name, value, options) => {
952
+ for (const fieldKey in value) {
953
+ if (!value.hasOwnProperty(fieldKey)) {
954
+ return;
955
+ }
956
+ const fieldValue = value[fieldKey];
957
+ const fieldName = name + "." + fieldKey;
958
+ const field = get(_fields, fieldName);
959
+ (_names.array.has(name) || isObject(fieldValue) || field && !field._f) && !isDateObject(fieldValue) ? setValues(fieldName, fieldValue, options) : setFieldValue(fieldName, fieldValue, options);
960
+ }
961
+ };
962
+ const setValue = (name, value, options = {}) => {
963
+ const field = get(_fields, name);
964
+ const isFieldArray = _names.array.has(name);
965
+ const cloneValue = cloneObject(value);
966
+ set(_formValues, name, cloneValue);
967
+ if (isFieldArray) {
968
+ _subjects.array.next({
969
+ name,
970
+ values: cloneObject(_formValues)
971
+ });
972
+ if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields || _proxySubscribeFormState.isDirty || _proxySubscribeFormState.dirtyFields) && options.shouldDirty) {
973
+ _subjects.state.next({
974
+ name,
975
+ dirtyFields: getDirtyFields(_defaultValues, _formValues),
976
+ isDirty: _getDirty(name, cloneValue)
977
+ });
978
+ }
979
+ } else {
980
+ field && !field._f && !isNullOrUndefined(cloneValue) ? setValues(name, cloneValue, options) : setFieldValue(name, cloneValue, options);
981
+ }
982
+ if (isWatched(name, _names)) {
983
+ _subjects.state.next({
984
+ ..._formState,
985
+ name,
986
+ values: cloneObject(_formValues)
987
+ });
988
+ } else {
989
+ _subjects.state.next({
990
+ name: _state.mount ? name : undefined,
991
+ values: cloneObject(_formValues)
992
+ });
993
+ }
994
+ };
995
+ const onChange = async (event) => {
996
+ _state.mount = true;
997
+ const target = event.target;
998
+ let name = target.name;
999
+ let isFieldValueUpdated = true;
1000
+ const field = get(_fields, name);
1001
+ const _updateIsFieldValueUpdated = (fieldValue) => {
1002
+ isFieldValueUpdated = Number.isNaN(fieldValue) || isDateObject(fieldValue) && isNaN(fieldValue.getTime()) || deepEqual(fieldValue, get(_formValues, name, fieldValue));
1003
+ };
1004
+ const validationModeBeforeSubmit = getValidationModes(_options.mode);
1005
+ const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1006
+ if (field) {
1007
+ let error;
1008
+ let isValid;
1009
+ const fieldValue = target.type ? getFieldValue(field._f) : getEventValue(event);
1010
+ const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1011
+ const shouldSkipValidation = !hasValidation(field._f) && !_options.resolver && !get(_formState.errors, name) && !field._f.deps || skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
1012
+ const watched = isWatched(name, _names, isBlurEvent);
1013
+ set(_formValues, name, fieldValue);
1014
+ if (isBlurEvent) {
1015
+ if (!target || !target.readOnly) {
1016
+ field._f.onBlur && field._f.onBlur(event);
1017
+ delayErrorCallback && delayErrorCallback(0);
1018
+ }
1019
+ } else if (field._f.onChange) {
1020
+ field._f.onChange(event);
1021
+ }
1022
+ const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
1023
+ const shouldRender = !isEmptyObject(fieldState) || watched;
1024
+ !isBlurEvent && _subjects.state.next({
1025
+ name,
1026
+ type: event.type,
1027
+ values: cloneObject(_formValues)
1028
+ });
1029
+ if (shouldSkipValidation) {
1030
+ if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
1031
+ if (_options.mode === "onBlur") {
1032
+ if (isBlurEvent) {
1033
+ _setValid();
1034
+ }
1035
+ } else if (!isBlurEvent) {
1036
+ _setValid();
1037
+ }
1038
+ }
1039
+ return shouldRender && _subjects.state.next({ name, ...watched ? {} : fieldState });
1040
+ }
1041
+ !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1042
+ if (_options.resolver) {
1043
+ const { errors } = await _runSchema([name]);
1044
+ _updateIsValidating([name]);
1045
+ _updateIsFieldValueUpdated(fieldValue);
1046
+ if (isFieldValueUpdated) {
1047
+ const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1048
+ const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1049
+ error = errorLookupResult.error;
1050
+ name = errorLookupResult.name;
1051
+ isValid = isEmptyObject(errors);
1052
+ }
1053
+ } else {
1054
+ _updateIsValidating([name], true);
1055
+ error = (await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1056
+ _updateIsValidating([name]);
1057
+ _updateIsFieldValueUpdated(fieldValue);
1058
+ if (isFieldValueUpdated) {
1059
+ if (error) {
1060
+ isValid = false;
1061
+ } else if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
1062
+ isValid = await executeBuiltInValidation(_fields, true);
1063
+ }
1064
+ }
1065
+ }
1066
+ if (isFieldValueUpdated) {
1067
+ field._f.deps && (!Array.isArray(field._f.deps) || field._f.deps.length > 0) && trigger(field._f.deps);
1068
+ shouldRenderByError(name, isValid, error, fieldState);
1069
+ }
1070
+ }
1071
+ };
1072
+ const _focusInput = (ref, key) => {
1073
+ if (get(_formState.errors, key) && ref.focus) {
1074
+ ref.focus();
1075
+ return 1;
1076
+ }
1077
+ return;
1078
+ };
1079
+ const trigger = async (name, options = {}) => {
1080
+ let isValid;
1081
+ let validationResult;
1082
+ const fieldNames = convertToArrayPayload(name);
1083
+ if (_options.resolver) {
1084
+ const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1085
+ isValid = isEmptyObject(errors);
1086
+ validationResult = name ? !fieldNames.some((name2) => get(errors, name2)) : isValid;
1087
+ } else if (name) {
1088
+ validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
1089
+ const field = get(_fields, fieldName);
1090
+ return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
1091
+ }))).every(Boolean);
1092
+ !(!validationResult && !_formState.isValid) && _setValid();
1093
+ } else {
1094
+ validationResult = isValid = await executeBuiltInValidation(_fields);
1095
+ }
1096
+ _subjects.state.next({
1097
+ ...!isString(name) || (_proxyFormState.isValid || _proxySubscribeFormState.isValid) && isValid !== _formState.isValid ? {} : { name },
1098
+ ..._options.resolver || !name ? { isValid } : {},
1099
+ errors: _formState.errors
1100
+ });
1101
+ options.shouldFocus && !validationResult && iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
1102
+ return validationResult;
1103
+ };
1104
+ const getValues = (fieldNames, config) => {
1105
+ let values = {
1106
+ ..._state.mount ? _formValues : _defaultValues
1107
+ };
1108
+ if (config) {
1109
+ values = extractFormValues(config.dirtyFields ? _formState.dirtyFields : _formState.touchedFields, values);
1110
+ }
1111
+ return isUndefined(fieldNames) ? values : isString(fieldNames) ? get(values, fieldNames) : fieldNames.map((name) => get(values, name));
1112
+ };
1113
+ const getFieldState = (name, formState) => ({
1114
+ invalid: !!get((formState || _formState).errors, name),
1115
+ isDirty: !!get((formState || _formState).dirtyFields, name),
1116
+ error: get((formState || _formState).errors, name),
1117
+ isValidating: !!get(_formState.validatingFields, name),
1118
+ isTouched: !!get((formState || _formState).touchedFields, name)
1119
+ });
1120
+ const clearErrors = (name) => {
1121
+ name && convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
1122
+ _subjects.state.next({
1123
+ errors: name ? _formState.errors : {}
1124
+ });
1125
+ };
1126
+ const setError = (name, error, options) => {
1127
+ const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1128
+ const currentError = get(_formState.errors, name) || {};
1129
+ const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
1130
+ set(_formState.errors, name, {
1131
+ ...restOfErrorTree,
1132
+ ...error,
1133
+ ref
1134
+ });
1135
+ _subjects.state.next({
1136
+ name,
1137
+ errors: _formState.errors,
1138
+ isValid: false
1139
+ });
1140
+ options && options.shouldFocus && ref && ref.focus && ref.focus();
1141
+ };
1142
+ const watch = (name, defaultValue) => isFunction(name) ? _subjects.state.subscribe({
1143
+ next: (payload) => ("values" in payload) && name(_getWatch(undefined, defaultValue), payload)
1144
+ }) : _getWatch(name, defaultValue, true);
1145
+ const _subscribe = (props2) => _subjects.state.subscribe({
1146
+ next: (formState) => {
1147
+ if (shouldSubscribeByName(props2.name, formState.name, props2.exact) && shouldRenderFormState(formState, props2.formState || _proxyFormState, _setFormState, props2.reRenderRoot)) {
1148
+ props2.callback({
1149
+ values: { ..._formValues },
1150
+ ..._formState,
1151
+ ...formState,
1152
+ defaultValues: _defaultValues
1153
+ });
1154
+ }
1155
+ }
1156
+ }).unsubscribe;
1157
+ const subscribe = (props2) => {
1158
+ _state.mount = true;
1159
+ _proxySubscribeFormState = {
1160
+ ..._proxySubscribeFormState,
1161
+ ...props2.formState
1162
+ };
1163
+ return _subscribe({
1164
+ ...props2,
1165
+ formState: {
1166
+ ...defaultProxyFormState,
1167
+ ...props2.formState
1168
+ }
1169
+ });
1170
+ };
1171
+ const unregister = (name, options = {}) => {
1172
+ for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
1173
+ _names.mount.delete(fieldName);
1174
+ _names.array.delete(fieldName);
1175
+ if (!options.keepValue) {
1176
+ unset(_fields, fieldName);
1177
+ unset(_formValues, fieldName);
1178
+ }
1179
+ !options.keepError && unset(_formState.errors, fieldName);
1180
+ !options.keepDirty && unset(_formState.dirtyFields, fieldName);
1181
+ !options.keepTouched && unset(_formState.touchedFields, fieldName);
1182
+ !options.keepIsValidating && unset(_formState.validatingFields, fieldName);
1183
+ !_options.shouldUnregister && !options.keepDefaultValue && unset(_defaultValues, fieldName);
1184
+ }
1185
+ _subjects.state.next({
1186
+ values: cloneObject(_formValues)
1187
+ });
1188
+ _subjects.state.next({
1189
+ ..._formState,
1190
+ ...!options.keepDirty ? {} : { isDirty: _getDirty() }
1191
+ });
1192
+ !options.keepIsValid && _setValid();
1193
+ };
1194
+ const _setDisabledField = ({ disabled, name }) => {
1195
+ if (isBoolean(disabled) && _state.mount || !!disabled || _names.disabled.has(name)) {
1196
+ const wasDisabled = _names.disabled.has(name);
1197
+ const isDisabled = !!disabled;
1198
+ const disabledStateChanged = wasDisabled !== isDisabled;
1199
+ disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
1200
+ disabledStateChanged && _state.mount && !_state.action && _setValid();
1201
+ }
1202
+ };
1203
+ const register = (name, options = {}) => {
1204
+ let field = get(_fields, name);
1205
+ const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
1206
+ set(_fields, name, {
1207
+ ...field || {},
1208
+ _f: {
1209
+ ...field && field._f ? field._f : { ref: { name } },
1210
+ name,
1211
+ mount: true,
1212
+ ...options
1213
+ }
1214
+ });
1215
+ _names.mount.add(name);
1216
+ if (field) {
1217
+ _setDisabledField({
1218
+ disabled: isBoolean(options.disabled) ? options.disabled : _options.disabled,
1219
+ name
1220
+ });
1221
+ } else {
1222
+ updateValidAndValue(name, true, options.value);
1223
+ }
1224
+ return {
1225
+ ...disabledIsDefined ? { disabled: options.disabled || _options.disabled } : {},
1226
+ ..._options.progressive ? {
1227
+ required: !!options.required,
1228
+ min: getRuleValue(options.min),
1229
+ max: getRuleValue(options.max),
1230
+ minLength: getRuleValue(options.minLength),
1231
+ maxLength: getRuleValue(options.maxLength),
1232
+ pattern: getRuleValue(options.pattern)
1233
+ } : {},
1234
+ name,
1235
+ onChange,
1236
+ onBlur: onChange,
1237
+ ref: (ref) => {
1238
+ if (ref) {
1239
+ register(name, options);
1240
+ field = get(_fields, name);
1241
+ const fieldRef = isUndefined(ref.value) ? ref.querySelectorAll ? ref.querySelectorAll("input,select,textarea")[0] || ref : ref : ref;
1242
+ const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
1243
+ const refs = field._f.refs || [];
1244
+ if (radioOrCheckbox ? refs.find((option) => option === fieldRef) : fieldRef === field._f.ref) {
1245
+ return;
1246
+ }
1247
+ set(_fields, name, {
1248
+ _f: {
1249
+ ...field._f,
1250
+ ...radioOrCheckbox ? {
1251
+ refs: [
1252
+ ...refs.filter(live),
1253
+ fieldRef,
1254
+ ...Array.isArray(get(_defaultValues, name)) ? [{}] : []
1255
+ ],
1256
+ ref: { type: fieldRef.type, name }
1257
+ } : { ref: fieldRef }
1258
+ }
1259
+ });
1260
+ updateValidAndValue(name, false, undefined, fieldRef);
1261
+ } else {
1262
+ field = get(_fields, name, {});
1263
+ if (field._f) {
1264
+ field._f.mount = false;
1265
+ }
1266
+ (_options.shouldUnregister || options.shouldUnregister) && !(isNameInFieldArray(_names.array, name) && _state.action) && _names.unMount.add(name);
1267
+ }
1268
+ }
1269
+ };
1270
+ };
1271
+ const _focusError = () => _options.shouldFocusError && iterateFieldsByAction(_fields, _focusInput, _names.mount);
1272
+ const _disableForm = (disabled) => {
1273
+ if (isBoolean(disabled)) {
1274
+ _subjects.state.next({ disabled });
1275
+ iterateFieldsByAction(_fields, (ref, name) => {
1276
+ const currentField = get(_fields, name);
1277
+ if (currentField) {
1278
+ ref.disabled = currentField._f.disabled || disabled;
1279
+ if (Array.isArray(currentField._f.refs)) {
1280
+ currentField._f.refs.forEach((inputRef) => {
1281
+ inputRef.disabled = currentField._f.disabled || disabled;
1282
+ });
1283
+ }
1284
+ }
1285
+ }, 0, false);
1286
+ }
1287
+ };
1288
+ const handleSubmit = (onValid, onInvalid) => async (e) => {
1289
+ let onValidError = undefined;
1290
+ if (e) {
1291
+ e.preventDefault && e.preventDefault();
1292
+ e.persist && e.persist();
1293
+ }
1294
+ let fieldValues = cloneObject(_formValues);
1295
+ _subjects.state.next({
1296
+ isSubmitting: true
1297
+ });
1298
+ if (_options.resolver) {
1299
+ const { errors, values } = await _runSchema();
1300
+ _updateIsValidating();
1301
+ _formState.errors = errors;
1302
+ fieldValues = cloneObject(values);
1303
+ } else {
1304
+ await executeBuiltInValidation(_fields);
1305
+ }
1306
+ if (_names.disabled.size) {
1307
+ for (const name of _names.disabled) {
1308
+ unset(fieldValues, name);
1309
+ }
1310
+ }
1311
+ unset(_formState.errors, "root");
1312
+ if (isEmptyObject(_formState.errors)) {
1313
+ _subjects.state.next({
1314
+ errors: {}
1315
+ });
1316
+ try {
1317
+ await onValid(fieldValues, e);
1318
+ } catch (error) {
1319
+ onValidError = error;
1320
+ }
1321
+ } else {
1322
+ if (onInvalid) {
1323
+ await onInvalid({ ..._formState.errors }, e);
1324
+ }
1325
+ _focusError();
1326
+ setTimeout(_focusError);
1327
+ }
1328
+ _subjects.state.next({
1329
+ isSubmitted: true,
1330
+ isSubmitting: false,
1331
+ isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
1332
+ submitCount: _formState.submitCount + 1,
1333
+ errors: _formState.errors
1334
+ });
1335
+ if (onValidError) {
1336
+ throw onValidError;
1337
+ }
1338
+ };
1339
+ const resetField = (name, options = {}) => {
1340
+ if (get(_fields, name)) {
1341
+ if (isUndefined(options.defaultValue)) {
1342
+ setValue(name, cloneObject(get(_defaultValues, name)));
1343
+ } else {
1344
+ setValue(name, options.defaultValue);
1345
+ set(_defaultValues, name, cloneObject(options.defaultValue));
1346
+ }
1347
+ if (!options.keepTouched) {
1348
+ unset(_formState.touchedFields, name);
1349
+ }
1350
+ if (!options.keepDirty) {
1351
+ unset(_formState.dirtyFields, name);
1352
+ _formState.isDirty = options.defaultValue ? _getDirty(name, cloneObject(get(_defaultValues, name))) : _getDirty();
1353
+ }
1354
+ if (!options.keepError) {
1355
+ unset(_formState.errors, name);
1356
+ _proxyFormState.isValid && _setValid();
1357
+ }
1358
+ _subjects.state.next({ ..._formState });
1359
+ }
1360
+ };
1361
+ const _reset = (formValues, keepStateOptions = {}) => {
1362
+ const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
1363
+ const cloneUpdatedValues = cloneObject(updatedValues);
1364
+ const isEmptyResetValues = isEmptyObject(formValues);
1365
+ const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
1366
+ if (!keepStateOptions.keepDefaultValues) {
1367
+ _defaultValues = updatedValues;
1368
+ }
1369
+ if (!keepStateOptions.keepValues) {
1370
+ if (keepStateOptions.keepDirtyValues) {
1371
+ const fieldsToCheck = new Set([
1372
+ ..._names.mount,
1373
+ ...Object.keys(getDirtyFields(_defaultValues, _formValues))
1374
+ ]);
1375
+ for (const fieldName of Array.from(fieldsToCheck)) {
1376
+ const isDirty = get(_formState.dirtyFields, fieldName);
1377
+ const existingValue = get(_formValues, fieldName);
1378
+ const newValue = get(values, fieldName);
1379
+ if (isDirty && !isUndefined(existingValue)) {
1380
+ set(values, fieldName, existingValue);
1381
+ } else if (!isDirty && !isUndefined(newValue)) {
1382
+ setValue(fieldName, newValue);
1383
+ }
1384
+ }
1385
+ } else {
1386
+ if (isWeb && isUndefined(formValues)) {
1387
+ for (const name of _names.mount) {
1388
+ const field = get(_fields, name);
1389
+ if (field && field._f) {
1390
+ const fieldReference = Array.isArray(field._f.refs) ? field._f.refs[0] : field._f.ref;
1391
+ if (isHTMLElement(fieldReference)) {
1392
+ const form = fieldReference.closest("form");
1393
+ if (form) {
1394
+ form.reset();
1395
+ break;
1396
+ }
1397
+ }
1398
+ }
1399
+ }
1400
+ }
1401
+ if (keepStateOptions.keepFieldsRef) {
1402
+ for (const fieldName of _names.mount) {
1403
+ setValue(fieldName, get(values, fieldName));
1404
+ }
1405
+ } else {
1406
+ _fields = {};
1407
+ }
1408
+ }
1409
+ _formValues = _options.shouldUnregister ? keepStateOptions.keepDefaultValues ? cloneObject(_defaultValues) : {} : cloneObject(values);
1410
+ _subjects.array.next({
1411
+ values: { ...values }
1412
+ });
1413
+ _subjects.state.next({
1414
+ values: { ...values }
1415
+ });
1416
+ }
1417
+ _names = {
1418
+ mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set,
1419
+ unMount: new Set,
1420
+ array: new Set,
1421
+ disabled: new Set,
1422
+ watch: new Set,
1423
+ watchAll: false,
1424
+ focus: ""
1425
+ };
1426
+ _state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid || !!keepStateOptions.keepDirtyValues || !_options.shouldUnregister && !isEmptyObject(values);
1427
+ _state.watch = !!_options.shouldUnregister;
1428
+ _state.keepIsValid = !!keepStateOptions.keepIsValid;
1429
+ _state.action = false;
1430
+ if (!keepStateOptions.keepErrors) {
1431
+ _formState.errors = {};
1432
+ }
1433
+ _subjects.state.next({
1434
+ submitCount: keepStateOptions.keepSubmitCount ? _formState.submitCount : 0,
1435
+ isDirty: isEmptyResetValues ? false : keepStateOptions.keepDirty ? _formState.isDirty : !!(keepStateOptions.keepDefaultValues && !deepEqual(formValues, _defaultValues)),
1436
+ isSubmitted: keepStateOptions.keepIsSubmitted ? _formState.isSubmitted : false,
1437
+ dirtyFields: isEmptyResetValues ? {} : keepStateOptions.keepDirtyValues ? keepStateOptions.keepDefaultValues && _formValues ? getDirtyFields(_defaultValues, _formValues) : _formState.dirtyFields : keepStateOptions.keepDefaultValues && formValues ? getDirtyFields(_defaultValues, formValues) : keepStateOptions.keepDirty ? _formState.dirtyFields : {},
1438
+ touchedFields: keepStateOptions.keepTouched ? _formState.touchedFields : {},
1439
+ errors: keepStateOptions.keepErrors ? _formState.errors : {},
1440
+ isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful ? _formState.isSubmitSuccessful : false,
1441
+ isSubmitting: false,
1442
+ defaultValues: _defaultValues
1443
+ });
1444
+ };
1445
+ const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues) ? formValues(_formValues) : formValues, { ..._options.resetOptions, ...keepStateOptions });
1446
+ const setFocus = (name, options = {}) => {
1447
+ const field = get(_fields, name);
1448
+ const fieldReference = field && field._f;
1449
+ if (fieldReference) {
1450
+ const fieldRef = fieldReference.refs ? fieldReference.refs[0] : fieldReference.ref;
1451
+ if (fieldRef.focus) {
1452
+ setTimeout(() => {
1453
+ fieldRef.focus();
1454
+ options.shouldSelect && isFunction(fieldRef.select) && fieldRef.select();
1455
+ });
1456
+ }
1457
+ }
1458
+ };
1459
+ const _setFormState = (updatedFormState) => {
1460
+ _formState = {
1461
+ ..._formState,
1462
+ ...updatedFormState
1463
+ };
1464
+ };
1465
+ const _resetDefaultValues = () => isFunction(_options.defaultValues) && _options.defaultValues().then((values) => {
1466
+ reset(values, _options.resetOptions);
1467
+ _subjects.state.next({
1468
+ isLoading: false
1469
+ });
1470
+ });
1471
+ const methods = {
1472
+ control: {
1473
+ register,
1474
+ unregister,
1475
+ getFieldState,
1476
+ handleSubmit,
1477
+ setError,
1478
+ _subscribe,
1479
+ _runSchema,
1480
+ _updateIsValidating,
1481
+ _focusError,
1482
+ _getWatch,
1483
+ _getDirty,
1484
+ _setValid,
1485
+ _setFieldArray,
1486
+ _setDisabledField,
1487
+ _setErrors,
1488
+ _getFieldArray,
1489
+ _reset,
1490
+ _resetDefaultValues,
1491
+ _removeUnmounted,
1492
+ _disableForm,
1493
+ _subjects,
1494
+ _proxyFormState,
1495
+ get _fields() {
1496
+ return _fields;
1497
+ },
1498
+ get _formValues() {
1499
+ return _formValues;
1500
+ },
1501
+ get _state() {
1502
+ return _state;
1503
+ },
1504
+ set _state(value) {
1505
+ _state = value;
1506
+ },
1507
+ get _defaultValues() {
1508
+ return _defaultValues;
1509
+ },
1510
+ get _names() {
1511
+ return _names;
1512
+ },
1513
+ set _names(value) {
1514
+ _names = value;
1515
+ },
1516
+ get _formState() {
1517
+ return _formState;
1518
+ },
1519
+ get _options() {
1520
+ return _options;
1521
+ },
1522
+ set _options(value) {
1523
+ _options = {
1524
+ ..._options,
1525
+ ...value
1526
+ };
1527
+ }
1528
+ },
1529
+ subscribe,
1530
+ trigger,
1531
+ register,
1532
+ handleSubmit,
1533
+ watch,
1534
+ setValue,
1535
+ getValues,
1536
+ reset,
1537
+ resetField,
1538
+ clearErrors,
1539
+ unregister,
1540
+ setError,
1541
+ setFocus,
1542
+ getFieldState
1543
+ };
1544
+ return {
1545
+ ...methods,
1546
+ formControl: methods
1547
+ };
1548
+ }
1549
+ function useForm(props = {}) {
1550
+ const _formControl = React.useRef(undefined);
1551
+ const _values = React.useRef(undefined);
1552
+ const [formState, updateFormState] = React.useState({
1553
+ isDirty: false,
1554
+ isValidating: false,
1555
+ isLoading: isFunction(props.defaultValues),
1556
+ isSubmitted: false,
1557
+ isSubmitting: false,
1558
+ isSubmitSuccessful: false,
1559
+ isValid: false,
1560
+ submitCount: 0,
1561
+ dirtyFields: {},
1562
+ touchedFields: {},
1563
+ validatingFields: {},
1564
+ errors: props.errors || {},
1565
+ disabled: props.disabled || false,
1566
+ isReady: false,
1567
+ defaultValues: isFunction(props.defaultValues) ? undefined : props.defaultValues
1568
+ });
1569
+ if (!_formControl.current) {
1570
+ if (props.formControl) {
1571
+ _formControl.current = {
1572
+ ...props.formControl,
1573
+ formState
1574
+ };
1575
+ if (props.defaultValues && !isFunction(props.defaultValues)) {
1576
+ props.formControl.reset(props.defaultValues, props.resetOptions);
1577
+ }
1578
+ } else {
1579
+ const { formControl, ...rest } = createFormControl(props);
1580
+ _formControl.current = {
1581
+ ...rest,
1582
+ formState
1583
+ };
1584
+ }
1585
+ }
1586
+ const control = _formControl.current.control;
1587
+ control._options = props;
1588
+ useIsomorphicLayoutEffect(() => {
1589
+ const sub = control._subscribe({
1590
+ formState: control._proxyFormState,
1591
+ callback: () => updateFormState({ ...control._formState }),
1592
+ reRenderRoot: true
1593
+ });
1594
+ updateFormState((data) => ({
1595
+ ...data,
1596
+ isReady: true
1597
+ }));
1598
+ control._formState.isReady = true;
1599
+ return sub;
1600
+ }, [control]);
1601
+ React.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
1602
+ React.useEffect(() => {
1603
+ if (props.mode) {
1604
+ control._options.mode = props.mode;
1605
+ }
1606
+ if (props.reValidateMode) {
1607
+ control._options.reValidateMode = props.reValidateMode;
1608
+ }
1609
+ }, [control, props.mode, props.reValidateMode]);
1610
+ React.useEffect(() => {
1611
+ if (props.errors) {
1612
+ control._setErrors(props.errors);
1613
+ control._focusError();
1614
+ }
1615
+ }, [control, props.errors]);
1616
+ React.useEffect(() => {
1617
+ props.shouldUnregister && control._subjects.state.next({
1618
+ values: control._getWatch()
1619
+ });
1620
+ }, [control, props.shouldUnregister]);
1621
+ React.useEffect(() => {
1622
+ if (control._proxyFormState.isDirty) {
1623
+ const isDirty = control._getDirty();
1624
+ if (isDirty !== formState.isDirty) {
1625
+ control._subjects.state.next({
1626
+ isDirty
1627
+ });
1628
+ }
1629
+ }
1630
+ }, [control, formState.isDirty]);
1631
+ React.useEffect(() => {
1632
+ var _a;
1633
+ if (props.values && !deepEqual(props.values, _values.current)) {
1634
+ control._reset(props.values, {
1635
+ keepFieldsRef: true,
1636
+ ...control._options.resetOptions
1637
+ });
1638
+ if (!((_a = control._options.resetOptions) === null || _a === undefined ? undefined : _a.keepIsValid)) {
1639
+ control._setValid();
1640
+ }
1641
+ _values.current = props.values;
1642
+ updateFormState((state) => ({ ...state }));
1643
+ } else {
1644
+ control._resetDefaultValues();
1645
+ }
1646
+ }, [control, props.values]);
1647
+ React.useEffect(() => {
1648
+ if (!control._state.mount) {
1649
+ control._setValid();
1650
+ control._state.mount = true;
1651
+ }
1652
+ if (control._state.watch) {
1653
+ control._state.watch = false;
1654
+ control._subjects.state.next({ ...control._formState });
1655
+ }
1656
+ control._removeUnmounted();
1657
+ });
1658
+ _formControl.current.formState = React.useMemo(() => getProxyFormState(formState, control), [control, formState]);
1659
+ return _formControl.current;
1660
+ }
1661
+
1662
+ // node_modules/clsx/dist/clsx.mjs
1663
+ function r(e) {
1664
+ var t, f, n = "";
1665
+ if (typeof e == "string" || typeof e == "number")
1666
+ n += e;
1667
+ else if (typeof e == "object")
1668
+ if (Array.isArray(e)) {
1669
+ var o = e.length;
1670
+ for (t = 0;t < o; t++)
1671
+ e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
1672
+ } else
1673
+ for (f in e)
1674
+ e[f] && (n && (n += " "), n += f);
1675
+ return n;
1676
+ }
1677
+ function clsx() {
1678
+ for (var e, t, f = 0, n = "", o = arguments.length;f < o; f++)
1679
+ (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
1680
+ return n;
1681
+ }
1682
+
1683
+ // node_modules/tailwind-merge/dist/bundle-mjs.mjs
1684
+ var concatArrays = (array1, array2) => {
1685
+ const combinedArray = new Array(array1.length + array2.length);
1686
+ for (let i = 0;i < array1.length; i++) {
1687
+ combinedArray[i] = array1[i];
1688
+ }
1689
+ for (let i = 0;i < array2.length; i++) {
1690
+ combinedArray[array1.length + i] = array2[i];
1691
+ }
1692
+ return combinedArray;
1693
+ };
1694
+ var createClassValidatorObject = (classGroupId, validator) => ({
1695
+ classGroupId,
1696
+ validator
1697
+ });
1698
+ var createClassPartObject = (nextPart = new Map, validators = null, classGroupId) => ({
1699
+ nextPart,
1700
+ validators,
1701
+ classGroupId
1702
+ });
1703
+ var CLASS_PART_SEPARATOR = "-";
1704
+ var EMPTY_CONFLICTS = [];
1705
+ var ARBITRARY_PROPERTY_PREFIX = "arbitrary..";
1706
+ var createClassGroupUtils = (config) => {
1707
+ const classMap = createClassMap(config);
1708
+ const {
1709
+ conflictingClassGroups,
1710
+ conflictingClassGroupModifiers
1711
+ } = config;
1712
+ const getClassGroupId = (className) => {
1713
+ if (className.startsWith("[") && className.endsWith("]")) {
1714
+ return getGroupIdForArbitraryProperty(className);
1715
+ }
1716
+ const classParts = className.split(CLASS_PART_SEPARATOR);
1717
+ const startIndex = classParts[0] === "" && classParts.length > 1 ? 1 : 0;
1718
+ return getGroupRecursive(classParts, startIndex, classMap);
1719
+ };
1720
+ const getConflictingClassGroupIds = (classGroupId, hasPostfixModifier) => {
1721
+ if (hasPostfixModifier) {
1722
+ const modifierConflicts = conflictingClassGroupModifiers[classGroupId];
1723
+ const baseConflicts = conflictingClassGroups[classGroupId];
1724
+ if (modifierConflicts) {
1725
+ if (baseConflicts) {
1726
+ return concatArrays(baseConflicts, modifierConflicts);
1727
+ }
1728
+ return modifierConflicts;
1729
+ }
1730
+ return baseConflicts || EMPTY_CONFLICTS;
1731
+ }
1732
+ return conflictingClassGroups[classGroupId] || EMPTY_CONFLICTS;
1733
+ };
1734
+ return {
1735
+ getClassGroupId,
1736
+ getConflictingClassGroupIds
1737
+ };
1738
+ };
1739
+ var getGroupRecursive = (classParts, startIndex, classPartObject) => {
1740
+ const classPathsLength = classParts.length - startIndex;
1741
+ if (classPathsLength === 0) {
1742
+ return classPartObject.classGroupId;
1743
+ }
1744
+ const currentClassPart = classParts[startIndex];
1745
+ const nextClassPartObject = classPartObject.nextPart.get(currentClassPart);
1746
+ if (nextClassPartObject) {
1747
+ const result = getGroupRecursive(classParts, startIndex + 1, nextClassPartObject);
1748
+ if (result)
1749
+ return result;
1750
+ }
1751
+ const validators = classPartObject.validators;
1752
+ if (validators === null) {
1753
+ return;
1754
+ }
1755
+ const classRest = startIndex === 0 ? classParts.join(CLASS_PART_SEPARATOR) : classParts.slice(startIndex).join(CLASS_PART_SEPARATOR);
1756
+ const validatorsLength = validators.length;
1757
+ for (let i = 0;i < validatorsLength; i++) {
1758
+ const validatorObj = validators[i];
1759
+ if (validatorObj.validator(classRest)) {
1760
+ return validatorObj.classGroupId;
1761
+ }
1762
+ }
1763
+ return;
1764
+ };
1765
+ var getGroupIdForArbitraryProperty = (className) => className.slice(1, -1).indexOf(":") === -1 ? undefined : (() => {
1766
+ const content = className.slice(1, -1);
1767
+ const colonIndex = content.indexOf(":");
1768
+ const property = content.slice(0, colonIndex);
1769
+ return property ? ARBITRARY_PROPERTY_PREFIX + property : undefined;
1770
+ })();
1771
+ var createClassMap = (config) => {
1772
+ const {
1773
+ theme,
1774
+ classGroups
1775
+ } = config;
1776
+ return processClassGroups(classGroups, theme);
1777
+ };
1778
+ var processClassGroups = (classGroups, theme) => {
1779
+ const classMap = createClassPartObject();
1780
+ for (const classGroupId in classGroups) {
1781
+ const group = classGroups[classGroupId];
1782
+ processClassesRecursively(group, classMap, classGroupId, theme);
1783
+ }
1784
+ return classMap;
1785
+ };
1786
+ var processClassesRecursively = (classGroup, classPartObject, classGroupId, theme) => {
1787
+ const len = classGroup.length;
1788
+ for (let i = 0;i < len; i++) {
1789
+ const classDefinition = classGroup[i];
1790
+ processClassDefinition(classDefinition, classPartObject, classGroupId, theme);
1791
+ }
1792
+ };
1793
+ var processClassDefinition = (classDefinition, classPartObject, classGroupId, theme) => {
1794
+ if (typeof classDefinition === "string") {
1795
+ processStringDefinition(classDefinition, classPartObject, classGroupId);
1796
+ return;
1797
+ }
1798
+ if (typeof classDefinition === "function") {
1799
+ processFunctionDefinition(classDefinition, classPartObject, classGroupId, theme);
1800
+ return;
1801
+ }
1802
+ processObjectDefinition(classDefinition, classPartObject, classGroupId, theme);
1803
+ };
1804
+ var processStringDefinition = (classDefinition, classPartObject, classGroupId) => {
1805
+ const classPartObjectToEdit = classDefinition === "" ? classPartObject : getPart(classPartObject, classDefinition);
1806
+ classPartObjectToEdit.classGroupId = classGroupId;
1807
+ };
1808
+ var processFunctionDefinition = (classDefinition, classPartObject, classGroupId, theme) => {
1809
+ if (isThemeGetter(classDefinition)) {
1810
+ processClassesRecursively(classDefinition(theme), classPartObject, classGroupId, theme);
1811
+ return;
1812
+ }
1813
+ if (classPartObject.validators === null) {
1814
+ classPartObject.validators = [];
1815
+ }
1816
+ classPartObject.validators.push(createClassValidatorObject(classGroupId, classDefinition));
1817
+ };
1818
+ var processObjectDefinition = (classDefinition, classPartObject, classGroupId, theme) => {
1819
+ const entries = Object.entries(classDefinition);
1820
+ const len = entries.length;
1821
+ for (let i = 0;i < len; i++) {
1822
+ const [key, value] = entries[i];
1823
+ processClassesRecursively(value, getPart(classPartObject, key), classGroupId, theme);
1824
+ }
1825
+ };
1826
+ var getPart = (classPartObject, path) => {
1827
+ let current = classPartObject;
1828
+ const parts = path.split(CLASS_PART_SEPARATOR);
1829
+ const len = parts.length;
1830
+ for (let i = 0;i < len; i++) {
1831
+ const part = parts[i];
1832
+ let next = current.nextPart.get(part);
1833
+ if (!next) {
1834
+ next = createClassPartObject();
1835
+ current.nextPart.set(part, next);
1836
+ }
1837
+ current = next;
1838
+ }
1839
+ return current;
1840
+ };
1841
+ var isThemeGetter = (func) => ("isThemeGetter" in func) && func.isThemeGetter === true;
1842
+ var createLruCache = (maxCacheSize) => {
1843
+ if (maxCacheSize < 1) {
1844
+ return {
1845
+ get: () => {
1846
+ return;
1847
+ },
1848
+ set: () => {}
1849
+ };
1850
+ }
1851
+ let cacheSize = 0;
1852
+ let cache = Object.create(null);
1853
+ let previousCache = Object.create(null);
1854
+ const update = (key, value) => {
1855
+ cache[key] = value;
1856
+ cacheSize++;
1857
+ if (cacheSize > maxCacheSize) {
1858
+ cacheSize = 0;
1859
+ previousCache = cache;
1860
+ cache = Object.create(null);
1861
+ }
1862
+ };
1863
+ return {
1864
+ get(key) {
1865
+ let value = cache[key];
1866
+ if (value !== undefined) {
1867
+ return value;
1868
+ }
1869
+ if ((value = previousCache[key]) !== undefined) {
1870
+ update(key, value);
1871
+ return value;
1872
+ }
1873
+ },
1874
+ set(key, value) {
1875
+ if (key in cache) {
1876
+ cache[key] = value;
1877
+ } else {
1878
+ update(key, value);
1879
+ }
1880
+ }
1881
+ };
1882
+ };
1883
+ var IMPORTANT_MODIFIER = "!";
1884
+ var MODIFIER_SEPARATOR = ":";
1885
+ var EMPTY_MODIFIERS = [];
1886
+ var createResultObject = (modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition, isExternal) => ({
1887
+ modifiers,
1888
+ hasImportantModifier,
1889
+ baseClassName,
1890
+ maybePostfixModifierPosition,
1891
+ isExternal
1892
+ });
1893
+ var createParseClassName = (config) => {
1894
+ const {
1895
+ prefix,
1896
+ experimentalParseClassName
1897
+ } = config;
1898
+ let parseClassName = (className) => {
1899
+ const modifiers = [];
1900
+ let bracketDepth = 0;
1901
+ let parenDepth = 0;
1902
+ let modifierStart = 0;
1903
+ let postfixModifierPosition;
1904
+ const len = className.length;
1905
+ for (let index = 0;index < len; index++) {
1906
+ const currentCharacter = className[index];
1907
+ if (bracketDepth === 0 && parenDepth === 0) {
1908
+ if (currentCharacter === MODIFIER_SEPARATOR) {
1909
+ modifiers.push(className.slice(modifierStart, index));
1910
+ modifierStart = index + 1;
1911
+ continue;
1912
+ }
1913
+ if (currentCharacter === "/") {
1914
+ postfixModifierPosition = index;
1915
+ continue;
1916
+ }
1917
+ }
1918
+ if (currentCharacter === "[")
1919
+ bracketDepth++;
1920
+ else if (currentCharacter === "]")
1921
+ bracketDepth--;
1922
+ else if (currentCharacter === "(")
1923
+ parenDepth++;
1924
+ else if (currentCharacter === ")")
1925
+ parenDepth--;
1926
+ }
1927
+ const baseClassNameWithImportantModifier = modifiers.length === 0 ? className : className.slice(modifierStart);
1928
+ let baseClassName = baseClassNameWithImportantModifier;
1929
+ let hasImportantModifier = false;
1930
+ if (baseClassNameWithImportantModifier.endsWith(IMPORTANT_MODIFIER)) {
1931
+ baseClassName = baseClassNameWithImportantModifier.slice(0, -1);
1932
+ hasImportantModifier = true;
1933
+ } else if (baseClassNameWithImportantModifier.startsWith(IMPORTANT_MODIFIER)) {
1934
+ baseClassName = baseClassNameWithImportantModifier.slice(1);
1935
+ hasImportantModifier = true;
1936
+ }
1937
+ const maybePostfixModifierPosition = postfixModifierPosition && postfixModifierPosition > modifierStart ? postfixModifierPosition - modifierStart : undefined;
1938
+ return createResultObject(modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition);
1939
+ };
1940
+ if (prefix) {
1941
+ const fullPrefix = prefix + MODIFIER_SEPARATOR;
1942
+ const parseClassNameOriginal = parseClassName;
1943
+ parseClassName = (className) => className.startsWith(fullPrefix) ? parseClassNameOriginal(className.slice(fullPrefix.length)) : createResultObject(EMPTY_MODIFIERS, false, className, undefined, true);
1944
+ }
1945
+ if (experimentalParseClassName) {
1946
+ const parseClassNameOriginal = parseClassName;
1947
+ parseClassName = (className) => experimentalParseClassName({
1948
+ className,
1949
+ parseClassName: parseClassNameOriginal
1950
+ });
1951
+ }
1952
+ return parseClassName;
1953
+ };
1954
+ var createSortModifiers = (config) => {
1955
+ const modifierWeights = new Map;
1956
+ config.orderSensitiveModifiers.forEach((mod, index) => {
1957
+ modifierWeights.set(mod, 1e6 + index);
1958
+ });
1959
+ return (modifiers) => {
1960
+ const result = [];
1961
+ let currentSegment = [];
1962
+ for (let i = 0;i < modifiers.length; i++) {
1963
+ const modifier = modifiers[i];
1964
+ const isArbitrary = modifier[0] === "[";
1965
+ const isOrderSensitive = modifierWeights.has(modifier);
1966
+ if (isArbitrary || isOrderSensitive) {
1967
+ if (currentSegment.length > 0) {
1968
+ currentSegment.sort();
1969
+ result.push(...currentSegment);
1970
+ currentSegment = [];
1971
+ }
1972
+ result.push(modifier);
1973
+ } else {
1974
+ currentSegment.push(modifier);
1975
+ }
1976
+ }
1977
+ if (currentSegment.length > 0) {
1978
+ currentSegment.sort();
1979
+ result.push(...currentSegment);
1980
+ }
1981
+ return result;
1982
+ };
1983
+ };
1984
+ var createConfigUtils = (config) => ({
1985
+ cache: createLruCache(config.cacheSize),
1986
+ parseClassName: createParseClassName(config),
1987
+ sortModifiers: createSortModifiers(config),
1988
+ ...createClassGroupUtils(config)
1989
+ });
1990
+ var SPLIT_CLASSES_REGEX = /\s+/;
1991
+ var mergeClassList = (classList, configUtils) => {
1992
+ const {
1993
+ parseClassName,
1994
+ getClassGroupId,
1995
+ getConflictingClassGroupIds,
1996
+ sortModifiers
1997
+ } = configUtils;
1998
+ const classGroupsInConflict = [];
1999
+ const classNames = classList.trim().split(SPLIT_CLASSES_REGEX);
2000
+ let result = "";
2001
+ for (let index = classNames.length - 1;index >= 0; index -= 1) {
2002
+ const originalClassName = classNames[index];
2003
+ const {
2004
+ isExternal,
2005
+ modifiers,
2006
+ hasImportantModifier,
2007
+ baseClassName,
2008
+ maybePostfixModifierPosition
2009
+ } = parseClassName(originalClassName);
2010
+ if (isExternal) {
2011
+ result = originalClassName + (result.length > 0 ? " " + result : result);
2012
+ continue;
2013
+ }
2014
+ let hasPostfixModifier = !!maybePostfixModifierPosition;
2015
+ let classGroupId = getClassGroupId(hasPostfixModifier ? baseClassName.substring(0, maybePostfixModifierPosition) : baseClassName);
2016
+ if (!classGroupId) {
2017
+ if (!hasPostfixModifier) {
2018
+ result = originalClassName + (result.length > 0 ? " " + result : result);
2019
+ continue;
2020
+ }
2021
+ classGroupId = getClassGroupId(baseClassName);
2022
+ if (!classGroupId) {
2023
+ result = originalClassName + (result.length > 0 ? " " + result : result);
2024
+ continue;
2025
+ }
2026
+ hasPostfixModifier = false;
2027
+ }
2028
+ const variantModifier = modifiers.length === 0 ? "" : modifiers.length === 1 ? modifiers[0] : sortModifiers(modifiers).join(":");
2029
+ const modifierId = hasImportantModifier ? variantModifier + IMPORTANT_MODIFIER : variantModifier;
2030
+ const classId = modifierId + classGroupId;
2031
+ if (classGroupsInConflict.indexOf(classId) > -1) {
2032
+ continue;
2033
+ }
2034
+ classGroupsInConflict.push(classId);
2035
+ const conflictGroups = getConflictingClassGroupIds(classGroupId, hasPostfixModifier);
2036
+ for (let i = 0;i < conflictGroups.length; ++i) {
2037
+ const group = conflictGroups[i];
2038
+ classGroupsInConflict.push(modifierId + group);
2039
+ }
2040
+ result = originalClassName + (result.length > 0 ? " " + result : result);
2041
+ }
2042
+ return result;
2043
+ };
2044
+ var twJoin = (...classLists) => {
2045
+ let index = 0;
2046
+ let argument;
2047
+ let resolvedValue;
2048
+ let string = "";
2049
+ while (index < classLists.length) {
2050
+ if (argument = classLists[index++]) {
2051
+ if (resolvedValue = toValue(argument)) {
2052
+ string && (string += " ");
2053
+ string += resolvedValue;
2054
+ }
2055
+ }
2056
+ }
2057
+ return string;
2058
+ };
2059
+ var toValue = (mix) => {
2060
+ if (typeof mix === "string") {
2061
+ return mix;
2062
+ }
2063
+ let resolvedValue;
2064
+ let string = "";
2065
+ for (let k = 0;k < mix.length; k++) {
2066
+ if (mix[k]) {
2067
+ if (resolvedValue = toValue(mix[k])) {
2068
+ string && (string += " ");
2069
+ string += resolvedValue;
2070
+ }
2071
+ }
2072
+ }
2073
+ return string;
2074
+ };
2075
+ var createTailwindMerge = (createConfigFirst, ...createConfigRest) => {
2076
+ let configUtils;
2077
+ let cacheGet;
2078
+ let cacheSet;
2079
+ let functionToCall;
2080
+ const initTailwindMerge = (classList) => {
2081
+ const config = createConfigRest.reduce((previousConfig, createConfigCurrent) => createConfigCurrent(previousConfig), createConfigFirst());
2082
+ configUtils = createConfigUtils(config);
2083
+ cacheGet = configUtils.cache.get;
2084
+ cacheSet = configUtils.cache.set;
2085
+ functionToCall = tailwindMerge;
2086
+ return tailwindMerge(classList);
2087
+ };
2088
+ const tailwindMerge = (classList) => {
2089
+ const cachedResult = cacheGet(classList);
2090
+ if (cachedResult) {
2091
+ return cachedResult;
2092
+ }
2093
+ const result = mergeClassList(classList, configUtils);
2094
+ cacheSet(classList, result);
2095
+ return result;
2096
+ };
2097
+ functionToCall = initTailwindMerge;
2098
+ return (...args) => functionToCall(twJoin(...args));
2099
+ };
2100
+ var fallbackThemeArr = [];
2101
+ var fromTheme = (key) => {
2102
+ const themeGetter = (theme) => theme[key] || fallbackThemeArr;
2103
+ themeGetter.isThemeGetter = true;
2104
+ return themeGetter;
2105
+ };
2106
+ var arbitraryValueRegex = /^\[(?:(\w[\w-]*):)?(.+)\]$/i;
2107
+ var arbitraryVariableRegex = /^\((?:(\w[\w-]*):)?(.+)\)$/i;
2108
+ var fractionRegex = /^\d+\/\d+$/;
2109
+ var tshirtUnitRegex = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/;
2110
+ var lengthUnitRegex = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/;
2111
+ var colorFunctionRegex = /^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/;
2112
+ var shadowRegex = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/;
2113
+ var imageRegex = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/;
2114
+ var isFraction = (value) => fractionRegex.test(value);
2115
+ var isNumber = (value) => !!value && !Number.isNaN(Number(value));
2116
+ var isInteger = (value) => !!value && Number.isInteger(Number(value));
2117
+ var isPercent = (value) => value.endsWith("%") && isNumber(value.slice(0, -1));
2118
+ var isTshirtSize = (value) => tshirtUnitRegex.test(value);
2119
+ var isAny = () => true;
2120
+ var isLengthOnly = (value) => lengthUnitRegex.test(value) && !colorFunctionRegex.test(value);
2121
+ var isNever = () => false;
2122
+ var isShadow = (value) => shadowRegex.test(value);
2123
+ var isImage = (value) => imageRegex.test(value);
2124
+ var isAnyNonArbitrary = (value) => !isArbitraryValue(value) && !isArbitraryVariable(value);
2125
+ var isArbitrarySize = (value) => getIsArbitraryValue(value, isLabelSize, isNever);
2126
+ var isArbitraryValue = (value) => arbitraryValueRegex.test(value);
2127
+ var isArbitraryLength = (value) => getIsArbitraryValue(value, isLabelLength, isLengthOnly);
2128
+ var isArbitraryNumber = (value) => getIsArbitraryValue(value, isLabelNumber, isNumber);
2129
+ var isArbitraryPosition = (value) => getIsArbitraryValue(value, isLabelPosition, isNever);
2130
+ var isArbitraryImage = (value) => getIsArbitraryValue(value, isLabelImage, isImage);
2131
+ var isArbitraryShadow = (value) => getIsArbitraryValue(value, isLabelShadow, isShadow);
2132
+ var isArbitraryVariable = (value) => arbitraryVariableRegex.test(value);
2133
+ var isArbitraryVariableLength = (value) => getIsArbitraryVariable(value, isLabelLength);
2134
+ var isArbitraryVariableFamilyName = (value) => getIsArbitraryVariable(value, isLabelFamilyName);
2135
+ var isArbitraryVariablePosition = (value) => getIsArbitraryVariable(value, isLabelPosition);
2136
+ var isArbitraryVariableSize = (value) => getIsArbitraryVariable(value, isLabelSize);
2137
+ var isArbitraryVariableImage = (value) => getIsArbitraryVariable(value, isLabelImage);
2138
+ var isArbitraryVariableShadow = (value) => getIsArbitraryVariable(value, isLabelShadow, true);
2139
+ var getIsArbitraryValue = (value, testLabel, testValue) => {
2140
+ const result = arbitraryValueRegex.exec(value);
2141
+ if (result) {
2142
+ if (result[1]) {
2143
+ return testLabel(result[1]);
2144
+ }
2145
+ return testValue(result[2]);
2146
+ }
2147
+ return false;
2148
+ };
2149
+ var getIsArbitraryVariable = (value, testLabel, shouldMatchNoLabel = false) => {
2150
+ const result = arbitraryVariableRegex.exec(value);
2151
+ if (result) {
2152
+ if (result[1]) {
2153
+ return testLabel(result[1]);
2154
+ }
2155
+ return shouldMatchNoLabel;
2156
+ }
2157
+ return false;
2158
+ };
2159
+ var isLabelPosition = (label) => label === "position" || label === "percentage";
2160
+ var isLabelImage = (label) => label === "image" || label === "url";
2161
+ var isLabelSize = (label) => label === "length" || label === "size" || label === "bg-size";
2162
+ var isLabelLength = (label) => label === "length";
2163
+ var isLabelNumber = (label) => label === "number";
2164
+ var isLabelFamilyName = (label) => label === "family-name";
2165
+ var isLabelShadow = (label) => label === "shadow";
2166
+ var getDefaultConfig = () => {
2167
+ const themeColor = fromTheme("color");
2168
+ const themeFont = fromTheme("font");
2169
+ const themeText = fromTheme("text");
2170
+ const themeFontWeight = fromTheme("font-weight");
2171
+ const themeTracking = fromTheme("tracking");
2172
+ const themeLeading = fromTheme("leading");
2173
+ const themeBreakpoint = fromTheme("breakpoint");
2174
+ const themeContainer = fromTheme("container");
2175
+ const themeSpacing = fromTheme("spacing");
2176
+ const themeRadius = fromTheme("radius");
2177
+ const themeShadow = fromTheme("shadow");
2178
+ const themeInsetShadow = fromTheme("inset-shadow");
2179
+ const themeTextShadow = fromTheme("text-shadow");
2180
+ const themeDropShadow = fromTheme("drop-shadow");
2181
+ const themeBlur = fromTheme("blur");
2182
+ const themePerspective = fromTheme("perspective");
2183
+ const themeAspect = fromTheme("aspect");
2184
+ const themeEase = fromTheme("ease");
2185
+ const themeAnimate = fromTheme("animate");
2186
+ const scaleBreak = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"];
2187
+ const scalePosition = () => [
2188
+ "center",
2189
+ "top",
2190
+ "bottom",
2191
+ "left",
2192
+ "right",
2193
+ "top-left",
2194
+ "left-top",
2195
+ "top-right",
2196
+ "right-top",
2197
+ "bottom-right",
2198
+ "right-bottom",
2199
+ "bottom-left",
2200
+ "left-bottom"
2201
+ ];
2202
+ const scalePositionWithArbitrary = () => [...scalePosition(), isArbitraryVariable, isArbitraryValue];
2203
+ const scaleOverflow = () => ["auto", "hidden", "clip", "visible", "scroll"];
2204
+ const scaleOverscroll = () => ["auto", "contain", "none"];
2205
+ const scaleUnambiguousSpacing = () => [isArbitraryVariable, isArbitraryValue, themeSpacing];
2206
+ const scaleInset = () => [isFraction, "full", "auto", ...scaleUnambiguousSpacing()];
2207
+ const scaleGridTemplateColsRows = () => [isInteger, "none", "subgrid", isArbitraryVariable, isArbitraryValue];
2208
+ const scaleGridColRowStartAndEnd = () => ["auto", {
2209
+ span: ["full", isInteger, isArbitraryVariable, isArbitraryValue]
2210
+ }, isInteger, isArbitraryVariable, isArbitraryValue];
2211
+ const scaleGridColRowStartOrEnd = () => [isInteger, "auto", isArbitraryVariable, isArbitraryValue];
2212
+ const scaleGridAutoColsRows = () => ["auto", "min", "max", "fr", isArbitraryVariable, isArbitraryValue];
2213
+ const scaleAlignPrimaryAxis = () => ["start", "end", "center", "between", "around", "evenly", "stretch", "baseline", "center-safe", "end-safe"];
2214
+ const scaleAlignSecondaryAxis = () => ["start", "end", "center", "stretch", "center-safe", "end-safe"];
2215
+ const scaleMargin = () => ["auto", ...scaleUnambiguousSpacing()];
2216
+ const scaleSizing = () => [isFraction, "auto", "full", "dvw", "dvh", "lvw", "lvh", "svw", "svh", "min", "max", "fit", ...scaleUnambiguousSpacing()];
2217
+ const scaleColor = () => [themeColor, isArbitraryVariable, isArbitraryValue];
2218
+ const scaleBgPosition = () => [...scalePosition(), isArbitraryVariablePosition, isArbitraryPosition, {
2219
+ position: [isArbitraryVariable, isArbitraryValue]
2220
+ }];
2221
+ const scaleBgRepeat = () => ["no-repeat", {
2222
+ repeat: ["", "x", "y", "space", "round"]
2223
+ }];
2224
+ const scaleBgSize = () => ["auto", "cover", "contain", isArbitraryVariableSize, isArbitrarySize, {
2225
+ size: [isArbitraryVariable, isArbitraryValue]
2226
+ }];
2227
+ const scaleGradientStopPosition = () => [isPercent, isArbitraryVariableLength, isArbitraryLength];
2228
+ const scaleRadius = () => [
2229
+ "",
2230
+ "none",
2231
+ "full",
2232
+ themeRadius,
2233
+ isArbitraryVariable,
2234
+ isArbitraryValue
2235
+ ];
2236
+ const scaleBorderWidth = () => ["", isNumber, isArbitraryVariableLength, isArbitraryLength];
2237
+ const scaleLineStyle = () => ["solid", "dashed", "dotted", "double"];
2238
+ const scaleBlendMode = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"];
2239
+ const scaleMaskImagePosition = () => [isNumber, isPercent, isArbitraryVariablePosition, isArbitraryPosition];
2240
+ const scaleBlur = () => [
2241
+ "",
2242
+ "none",
2243
+ themeBlur,
2244
+ isArbitraryVariable,
2245
+ isArbitraryValue
2246
+ ];
2247
+ const scaleRotate = () => ["none", isNumber, isArbitraryVariable, isArbitraryValue];
2248
+ const scaleScale = () => ["none", isNumber, isArbitraryVariable, isArbitraryValue];
2249
+ const scaleSkew = () => [isNumber, isArbitraryVariable, isArbitraryValue];
2250
+ const scaleTranslate = () => [isFraction, "full", ...scaleUnambiguousSpacing()];
2251
+ return {
2252
+ cacheSize: 500,
2253
+ theme: {
2254
+ animate: ["spin", "ping", "pulse", "bounce"],
2255
+ aspect: ["video"],
2256
+ blur: [isTshirtSize],
2257
+ breakpoint: [isTshirtSize],
2258
+ color: [isAny],
2259
+ container: [isTshirtSize],
2260
+ "drop-shadow": [isTshirtSize],
2261
+ ease: ["in", "out", "in-out"],
2262
+ font: [isAnyNonArbitrary],
2263
+ "font-weight": ["thin", "extralight", "light", "normal", "medium", "semibold", "bold", "extrabold", "black"],
2264
+ "inset-shadow": [isTshirtSize],
2265
+ leading: ["none", "tight", "snug", "normal", "relaxed", "loose"],
2266
+ perspective: ["dramatic", "near", "normal", "midrange", "distant", "none"],
2267
+ radius: [isTshirtSize],
2268
+ shadow: [isTshirtSize],
2269
+ spacing: ["px", isNumber],
2270
+ text: [isTshirtSize],
2271
+ "text-shadow": [isTshirtSize],
2272
+ tracking: ["tighter", "tight", "normal", "wide", "wider", "widest"]
2273
+ },
2274
+ classGroups: {
2275
+ aspect: [{
2276
+ aspect: ["auto", "square", isFraction, isArbitraryValue, isArbitraryVariable, themeAspect]
2277
+ }],
2278
+ container: ["container"],
2279
+ columns: [{
2280
+ columns: [isNumber, isArbitraryValue, isArbitraryVariable, themeContainer]
2281
+ }],
2282
+ "break-after": [{
2283
+ "break-after": scaleBreak()
2284
+ }],
2285
+ "break-before": [{
2286
+ "break-before": scaleBreak()
2287
+ }],
2288
+ "break-inside": [{
2289
+ "break-inside": ["auto", "avoid", "avoid-page", "avoid-column"]
2290
+ }],
2291
+ "box-decoration": [{
2292
+ "box-decoration": ["slice", "clone"]
2293
+ }],
2294
+ box: [{
2295
+ box: ["border", "content"]
2296
+ }],
2297
+ display: ["block", "inline-block", "inline", "flex", "inline-flex", "table", "inline-table", "table-caption", "table-cell", "table-column", "table-column-group", "table-footer-group", "table-header-group", "table-row-group", "table-row", "flow-root", "grid", "inline-grid", "contents", "list-item", "hidden"],
2298
+ sr: ["sr-only", "not-sr-only"],
2299
+ float: [{
2300
+ float: ["right", "left", "none", "start", "end"]
2301
+ }],
2302
+ clear: [{
2303
+ clear: ["left", "right", "both", "none", "start", "end"]
2304
+ }],
2305
+ isolation: ["isolate", "isolation-auto"],
2306
+ "object-fit": [{
2307
+ object: ["contain", "cover", "fill", "none", "scale-down"]
2308
+ }],
2309
+ "object-position": [{
2310
+ object: scalePositionWithArbitrary()
2311
+ }],
2312
+ overflow: [{
2313
+ overflow: scaleOverflow()
2314
+ }],
2315
+ "overflow-x": [{
2316
+ "overflow-x": scaleOverflow()
2317
+ }],
2318
+ "overflow-y": [{
2319
+ "overflow-y": scaleOverflow()
2320
+ }],
2321
+ overscroll: [{
2322
+ overscroll: scaleOverscroll()
2323
+ }],
2324
+ "overscroll-x": [{
2325
+ "overscroll-x": scaleOverscroll()
2326
+ }],
2327
+ "overscroll-y": [{
2328
+ "overscroll-y": scaleOverscroll()
2329
+ }],
2330
+ position: ["static", "fixed", "absolute", "relative", "sticky"],
2331
+ inset: [{
2332
+ inset: scaleInset()
2333
+ }],
2334
+ "inset-x": [{
2335
+ "inset-x": scaleInset()
2336
+ }],
2337
+ "inset-y": [{
2338
+ "inset-y": scaleInset()
2339
+ }],
2340
+ start: [{
2341
+ start: scaleInset()
2342
+ }],
2343
+ end: [{
2344
+ end: scaleInset()
2345
+ }],
2346
+ top: [{
2347
+ top: scaleInset()
2348
+ }],
2349
+ right: [{
2350
+ right: scaleInset()
2351
+ }],
2352
+ bottom: [{
2353
+ bottom: scaleInset()
2354
+ }],
2355
+ left: [{
2356
+ left: scaleInset()
2357
+ }],
2358
+ visibility: ["visible", "invisible", "collapse"],
2359
+ z: [{
2360
+ z: [isInteger, "auto", isArbitraryVariable, isArbitraryValue]
2361
+ }],
2362
+ basis: [{
2363
+ basis: [isFraction, "full", "auto", themeContainer, ...scaleUnambiguousSpacing()]
2364
+ }],
2365
+ "flex-direction": [{
2366
+ flex: ["row", "row-reverse", "col", "col-reverse"]
2367
+ }],
2368
+ "flex-wrap": [{
2369
+ flex: ["nowrap", "wrap", "wrap-reverse"]
2370
+ }],
2371
+ flex: [{
2372
+ flex: [isNumber, isFraction, "auto", "initial", "none", isArbitraryValue]
2373
+ }],
2374
+ grow: [{
2375
+ grow: ["", isNumber, isArbitraryVariable, isArbitraryValue]
2376
+ }],
2377
+ shrink: [{
2378
+ shrink: ["", isNumber, isArbitraryVariable, isArbitraryValue]
2379
+ }],
2380
+ order: [{
2381
+ order: [isInteger, "first", "last", "none", isArbitraryVariable, isArbitraryValue]
2382
+ }],
2383
+ "grid-cols": [{
2384
+ "grid-cols": scaleGridTemplateColsRows()
2385
+ }],
2386
+ "col-start-end": [{
2387
+ col: scaleGridColRowStartAndEnd()
2388
+ }],
2389
+ "col-start": [{
2390
+ "col-start": scaleGridColRowStartOrEnd()
2391
+ }],
2392
+ "col-end": [{
2393
+ "col-end": scaleGridColRowStartOrEnd()
2394
+ }],
2395
+ "grid-rows": [{
2396
+ "grid-rows": scaleGridTemplateColsRows()
2397
+ }],
2398
+ "row-start-end": [{
2399
+ row: scaleGridColRowStartAndEnd()
2400
+ }],
2401
+ "row-start": [{
2402
+ "row-start": scaleGridColRowStartOrEnd()
2403
+ }],
2404
+ "row-end": [{
2405
+ "row-end": scaleGridColRowStartOrEnd()
2406
+ }],
2407
+ "grid-flow": [{
2408
+ "grid-flow": ["row", "col", "dense", "row-dense", "col-dense"]
2409
+ }],
2410
+ "auto-cols": [{
2411
+ "auto-cols": scaleGridAutoColsRows()
2412
+ }],
2413
+ "auto-rows": [{
2414
+ "auto-rows": scaleGridAutoColsRows()
2415
+ }],
2416
+ gap: [{
2417
+ gap: scaleUnambiguousSpacing()
2418
+ }],
2419
+ "gap-x": [{
2420
+ "gap-x": scaleUnambiguousSpacing()
2421
+ }],
2422
+ "gap-y": [{
2423
+ "gap-y": scaleUnambiguousSpacing()
2424
+ }],
2425
+ "justify-content": [{
2426
+ justify: [...scaleAlignPrimaryAxis(), "normal"]
2427
+ }],
2428
+ "justify-items": [{
2429
+ "justify-items": [...scaleAlignSecondaryAxis(), "normal"]
2430
+ }],
2431
+ "justify-self": [{
2432
+ "justify-self": ["auto", ...scaleAlignSecondaryAxis()]
2433
+ }],
2434
+ "align-content": [{
2435
+ content: ["normal", ...scaleAlignPrimaryAxis()]
2436
+ }],
2437
+ "align-items": [{
2438
+ items: [...scaleAlignSecondaryAxis(), {
2439
+ baseline: ["", "last"]
2440
+ }]
2441
+ }],
2442
+ "align-self": [{
2443
+ self: ["auto", ...scaleAlignSecondaryAxis(), {
2444
+ baseline: ["", "last"]
2445
+ }]
2446
+ }],
2447
+ "place-content": [{
2448
+ "place-content": scaleAlignPrimaryAxis()
2449
+ }],
2450
+ "place-items": [{
2451
+ "place-items": [...scaleAlignSecondaryAxis(), "baseline"]
2452
+ }],
2453
+ "place-self": [{
2454
+ "place-self": ["auto", ...scaleAlignSecondaryAxis()]
2455
+ }],
2456
+ p: [{
2457
+ p: scaleUnambiguousSpacing()
2458
+ }],
2459
+ px: [{
2460
+ px: scaleUnambiguousSpacing()
2461
+ }],
2462
+ py: [{
2463
+ py: scaleUnambiguousSpacing()
2464
+ }],
2465
+ ps: [{
2466
+ ps: scaleUnambiguousSpacing()
2467
+ }],
2468
+ pe: [{
2469
+ pe: scaleUnambiguousSpacing()
2470
+ }],
2471
+ pt: [{
2472
+ pt: scaleUnambiguousSpacing()
2473
+ }],
2474
+ pr: [{
2475
+ pr: scaleUnambiguousSpacing()
2476
+ }],
2477
+ pb: [{
2478
+ pb: scaleUnambiguousSpacing()
2479
+ }],
2480
+ pl: [{
2481
+ pl: scaleUnambiguousSpacing()
2482
+ }],
2483
+ m: [{
2484
+ m: scaleMargin()
2485
+ }],
2486
+ mx: [{
2487
+ mx: scaleMargin()
2488
+ }],
2489
+ my: [{
2490
+ my: scaleMargin()
2491
+ }],
2492
+ ms: [{
2493
+ ms: scaleMargin()
2494
+ }],
2495
+ me: [{
2496
+ me: scaleMargin()
2497
+ }],
2498
+ mt: [{
2499
+ mt: scaleMargin()
2500
+ }],
2501
+ mr: [{
2502
+ mr: scaleMargin()
2503
+ }],
2504
+ mb: [{
2505
+ mb: scaleMargin()
2506
+ }],
2507
+ ml: [{
2508
+ ml: scaleMargin()
2509
+ }],
2510
+ "space-x": [{
2511
+ "space-x": scaleUnambiguousSpacing()
2512
+ }],
2513
+ "space-x-reverse": ["space-x-reverse"],
2514
+ "space-y": [{
2515
+ "space-y": scaleUnambiguousSpacing()
2516
+ }],
2517
+ "space-y-reverse": ["space-y-reverse"],
2518
+ size: [{
2519
+ size: scaleSizing()
2520
+ }],
2521
+ w: [{
2522
+ w: [themeContainer, "screen", ...scaleSizing()]
2523
+ }],
2524
+ "min-w": [{
2525
+ "min-w": [
2526
+ themeContainer,
2527
+ "screen",
2528
+ "none",
2529
+ ...scaleSizing()
2530
+ ]
2531
+ }],
2532
+ "max-w": [{
2533
+ "max-w": [
2534
+ themeContainer,
2535
+ "screen",
2536
+ "none",
2537
+ "prose",
2538
+ {
2539
+ screen: [themeBreakpoint]
2540
+ },
2541
+ ...scaleSizing()
2542
+ ]
2543
+ }],
2544
+ h: [{
2545
+ h: ["screen", "lh", ...scaleSizing()]
2546
+ }],
2547
+ "min-h": [{
2548
+ "min-h": ["screen", "lh", "none", ...scaleSizing()]
2549
+ }],
2550
+ "max-h": [{
2551
+ "max-h": ["screen", "lh", ...scaleSizing()]
2552
+ }],
2553
+ "font-size": [{
2554
+ text: ["base", themeText, isArbitraryVariableLength, isArbitraryLength]
2555
+ }],
2556
+ "font-smoothing": ["antialiased", "subpixel-antialiased"],
2557
+ "font-style": ["italic", "not-italic"],
2558
+ "font-weight": [{
2559
+ font: [themeFontWeight, isArbitraryVariable, isArbitraryNumber]
2560
+ }],
2561
+ "font-stretch": [{
2562
+ "font-stretch": ["ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded", isPercent, isArbitraryValue]
2563
+ }],
2564
+ "font-family": [{
2565
+ font: [isArbitraryVariableFamilyName, isArbitraryValue, themeFont]
2566
+ }],
2567
+ "fvn-normal": ["normal-nums"],
2568
+ "fvn-ordinal": ["ordinal"],
2569
+ "fvn-slashed-zero": ["slashed-zero"],
2570
+ "fvn-figure": ["lining-nums", "oldstyle-nums"],
2571
+ "fvn-spacing": ["proportional-nums", "tabular-nums"],
2572
+ "fvn-fraction": ["diagonal-fractions", "stacked-fractions"],
2573
+ tracking: [{
2574
+ tracking: [themeTracking, isArbitraryVariable, isArbitraryValue]
2575
+ }],
2576
+ "line-clamp": [{
2577
+ "line-clamp": [isNumber, "none", isArbitraryVariable, isArbitraryNumber]
2578
+ }],
2579
+ leading: [{
2580
+ leading: [
2581
+ themeLeading,
2582
+ ...scaleUnambiguousSpacing()
2583
+ ]
2584
+ }],
2585
+ "list-image": [{
2586
+ "list-image": ["none", isArbitraryVariable, isArbitraryValue]
2587
+ }],
2588
+ "list-style-position": [{
2589
+ list: ["inside", "outside"]
2590
+ }],
2591
+ "list-style-type": [{
2592
+ list: ["disc", "decimal", "none", isArbitraryVariable, isArbitraryValue]
2593
+ }],
2594
+ "text-alignment": [{
2595
+ text: ["left", "center", "right", "justify", "start", "end"]
2596
+ }],
2597
+ "placeholder-color": [{
2598
+ placeholder: scaleColor()
2599
+ }],
2600
+ "text-color": [{
2601
+ text: scaleColor()
2602
+ }],
2603
+ "text-decoration": ["underline", "overline", "line-through", "no-underline"],
2604
+ "text-decoration-style": [{
2605
+ decoration: [...scaleLineStyle(), "wavy"]
2606
+ }],
2607
+ "text-decoration-thickness": [{
2608
+ decoration: [isNumber, "from-font", "auto", isArbitraryVariable, isArbitraryLength]
2609
+ }],
2610
+ "text-decoration-color": [{
2611
+ decoration: scaleColor()
2612
+ }],
2613
+ "underline-offset": [{
2614
+ "underline-offset": [isNumber, "auto", isArbitraryVariable, isArbitraryValue]
2615
+ }],
2616
+ "text-transform": ["uppercase", "lowercase", "capitalize", "normal-case"],
2617
+ "text-overflow": ["truncate", "text-ellipsis", "text-clip"],
2618
+ "text-wrap": [{
2619
+ text: ["wrap", "nowrap", "balance", "pretty"]
2620
+ }],
2621
+ indent: [{
2622
+ indent: scaleUnambiguousSpacing()
2623
+ }],
2624
+ "vertical-align": [{
2625
+ align: ["baseline", "top", "middle", "bottom", "text-top", "text-bottom", "sub", "super", isArbitraryVariable, isArbitraryValue]
2626
+ }],
2627
+ whitespace: [{
2628
+ whitespace: ["normal", "nowrap", "pre", "pre-line", "pre-wrap", "break-spaces"]
2629
+ }],
2630
+ break: [{
2631
+ break: ["normal", "words", "all", "keep"]
2632
+ }],
2633
+ wrap: [{
2634
+ wrap: ["break-word", "anywhere", "normal"]
2635
+ }],
2636
+ hyphens: [{
2637
+ hyphens: ["none", "manual", "auto"]
2638
+ }],
2639
+ content: [{
2640
+ content: ["none", isArbitraryVariable, isArbitraryValue]
2641
+ }],
2642
+ "bg-attachment": [{
2643
+ bg: ["fixed", "local", "scroll"]
2644
+ }],
2645
+ "bg-clip": [{
2646
+ "bg-clip": ["border", "padding", "content", "text"]
2647
+ }],
2648
+ "bg-origin": [{
2649
+ "bg-origin": ["border", "padding", "content"]
2650
+ }],
2651
+ "bg-position": [{
2652
+ bg: scaleBgPosition()
2653
+ }],
2654
+ "bg-repeat": [{
2655
+ bg: scaleBgRepeat()
2656
+ }],
2657
+ "bg-size": [{
2658
+ bg: scaleBgSize()
2659
+ }],
2660
+ "bg-image": [{
2661
+ bg: ["none", {
2662
+ linear: [{
2663
+ to: ["t", "tr", "r", "br", "b", "bl", "l", "tl"]
2664
+ }, isInteger, isArbitraryVariable, isArbitraryValue],
2665
+ radial: ["", isArbitraryVariable, isArbitraryValue],
2666
+ conic: [isInteger, isArbitraryVariable, isArbitraryValue]
2667
+ }, isArbitraryVariableImage, isArbitraryImage]
2668
+ }],
2669
+ "bg-color": [{
2670
+ bg: scaleColor()
2671
+ }],
2672
+ "gradient-from-pos": [{
2673
+ from: scaleGradientStopPosition()
2674
+ }],
2675
+ "gradient-via-pos": [{
2676
+ via: scaleGradientStopPosition()
2677
+ }],
2678
+ "gradient-to-pos": [{
2679
+ to: scaleGradientStopPosition()
2680
+ }],
2681
+ "gradient-from": [{
2682
+ from: scaleColor()
2683
+ }],
2684
+ "gradient-via": [{
2685
+ via: scaleColor()
2686
+ }],
2687
+ "gradient-to": [{
2688
+ to: scaleColor()
2689
+ }],
2690
+ rounded: [{
2691
+ rounded: scaleRadius()
2692
+ }],
2693
+ "rounded-s": [{
2694
+ "rounded-s": scaleRadius()
2695
+ }],
2696
+ "rounded-e": [{
2697
+ "rounded-e": scaleRadius()
2698
+ }],
2699
+ "rounded-t": [{
2700
+ "rounded-t": scaleRadius()
2701
+ }],
2702
+ "rounded-r": [{
2703
+ "rounded-r": scaleRadius()
2704
+ }],
2705
+ "rounded-b": [{
2706
+ "rounded-b": scaleRadius()
2707
+ }],
2708
+ "rounded-l": [{
2709
+ "rounded-l": scaleRadius()
2710
+ }],
2711
+ "rounded-ss": [{
2712
+ "rounded-ss": scaleRadius()
2713
+ }],
2714
+ "rounded-se": [{
2715
+ "rounded-se": scaleRadius()
2716
+ }],
2717
+ "rounded-ee": [{
2718
+ "rounded-ee": scaleRadius()
2719
+ }],
2720
+ "rounded-es": [{
2721
+ "rounded-es": scaleRadius()
2722
+ }],
2723
+ "rounded-tl": [{
2724
+ "rounded-tl": scaleRadius()
2725
+ }],
2726
+ "rounded-tr": [{
2727
+ "rounded-tr": scaleRadius()
2728
+ }],
2729
+ "rounded-br": [{
2730
+ "rounded-br": scaleRadius()
2731
+ }],
2732
+ "rounded-bl": [{
2733
+ "rounded-bl": scaleRadius()
2734
+ }],
2735
+ "border-w": [{
2736
+ border: scaleBorderWidth()
2737
+ }],
2738
+ "border-w-x": [{
2739
+ "border-x": scaleBorderWidth()
2740
+ }],
2741
+ "border-w-y": [{
2742
+ "border-y": scaleBorderWidth()
2743
+ }],
2744
+ "border-w-s": [{
2745
+ "border-s": scaleBorderWidth()
2746
+ }],
2747
+ "border-w-e": [{
2748
+ "border-e": scaleBorderWidth()
2749
+ }],
2750
+ "border-w-t": [{
2751
+ "border-t": scaleBorderWidth()
2752
+ }],
2753
+ "border-w-r": [{
2754
+ "border-r": scaleBorderWidth()
2755
+ }],
2756
+ "border-w-b": [{
2757
+ "border-b": scaleBorderWidth()
2758
+ }],
2759
+ "border-w-l": [{
2760
+ "border-l": scaleBorderWidth()
2761
+ }],
2762
+ "divide-x": [{
2763
+ "divide-x": scaleBorderWidth()
2764
+ }],
2765
+ "divide-x-reverse": ["divide-x-reverse"],
2766
+ "divide-y": [{
2767
+ "divide-y": scaleBorderWidth()
2768
+ }],
2769
+ "divide-y-reverse": ["divide-y-reverse"],
2770
+ "border-style": [{
2771
+ border: [...scaleLineStyle(), "hidden", "none"]
2772
+ }],
2773
+ "divide-style": [{
2774
+ divide: [...scaleLineStyle(), "hidden", "none"]
2775
+ }],
2776
+ "border-color": [{
2777
+ border: scaleColor()
2778
+ }],
2779
+ "border-color-x": [{
2780
+ "border-x": scaleColor()
2781
+ }],
2782
+ "border-color-y": [{
2783
+ "border-y": scaleColor()
2784
+ }],
2785
+ "border-color-s": [{
2786
+ "border-s": scaleColor()
2787
+ }],
2788
+ "border-color-e": [{
2789
+ "border-e": scaleColor()
2790
+ }],
2791
+ "border-color-t": [{
2792
+ "border-t": scaleColor()
2793
+ }],
2794
+ "border-color-r": [{
2795
+ "border-r": scaleColor()
2796
+ }],
2797
+ "border-color-b": [{
2798
+ "border-b": scaleColor()
2799
+ }],
2800
+ "border-color-l": [{
2801
+ "border-l": scaleColor()
2802
+ }],
2803
+ "divide-color": [{
2804
+ divide: scaleColor()
2805
+ }],
2806
+ "outline-style": [{
2807
+ outline: [...scaleLineStyle(), "none", "hidden"]
2808
+ }],
2809
+ "outline-offset": [{
2810
+ "outline-offset": [isNumber, isArbitraryVariable, isArbitraryValue]
2811
+ }],
2812
+ "outline-w": [{
2813
+ outline: ["", isNumber, isArbitraryVariableLength, isArbitraryLength]
2814
+ }],
2815
+ "outline-color": [{
2816
+ outline: scaleColor()
2817
+ }],
2818
+ shadow: [{
2819
+ shadow: [
2820
+ "",
2821
+ "none",
2822
+ themeShadow,
2823
+ isArbitraryVariableShadow,
2824
+ isArbitraryShadow
2825
+ ]
2826
+ }],
2827
+ "shadow-color": [{
2828
+ shadow: scaleColor()
2829
+ }],
2830
+ "inset-shadow": [{
2831
+ "inset-shadow": ["none", themeInsetShadow, isArbitraryVariableShadow, isArbitraryShadow]
2832
+ }],
2833
+ "inset-shadow-color": [{
2834
+ "inset-shadow": scaleColor()
2835
+ }],
2836
+ "ring-w": [{
2837
+ ring: scaleBorderWidth()
2838
+ }],
2839
+ "ring-w-inset": ["ring-inset"],
2840
+ "ring-color": [{
2841
+ ring: scaleColor()
2842
+ }],
2843
+ "ring-offset-w": [{
2844
+ "ring-offset": [isNumber, isArbitraryLength]
2845
+ }],
2846
+ "ring-offset-color": [{
2847
+ "ring-offset": scaleColor()
2848
+ }],
2849
+ "inset-ring-w": [{
2850
+ "inset-ring": scaleBorderWidth()
2851
+ }],
2852
+ "inset-ring-color": [{
2853
+ "inset-ring": scaleColor()
2854
+ }],
2855
+ "text-shadow": [{
2856
+ "text-shadow": ["none", themeTextShadow, isArbitraryVariableShadow, isArbitraryShadow]
2857
+ }],
2858
+ "text-shadow-color": [{
2859
+ "text-shadow": scaleColor()
2860
+ }],
2861
+ opacity: [{
2862
+ opacity: [isNumber, isArbitraryVariable, isArbitraryValue]
2863
+ }],
2864
+ "mix-blend": [{
2865
+ "mix-blend": [...scaleBlendMode(), "plus-darker", "plus-lighter"]
2866
+ }],
2867
+ "bg-blend": [{
2868
+ "bg-blend": scaleBlendMode()
2869
+ }],
2870
+ "mask-clip": [{
2871
+ "mask-clip": ["border", "padding", "content", "fill", "stroke", "view"]
2872
+ }, "mask-no-clip"],
2873
+ "mask-composite": [{
2874
+ mask: ["add", "subtract", "intersect", "exclude"]
2875
+ }],
2876
+ "mask-image-linear-pos": [{
2877
+ "mask-linear": [isNumber]
2878
+ }],
2879
+ "mask-image-linear-from-pos": [{
2880
+ "mask-linear-from": scaleMaskImagePosition()
2881
+ }],
2882
+ "mask-image-linear-to-pos": [{
2883
+ "mask-linear-to": scaleMaskImagePosition()
2884
+ }],
2885
+ "mask-image-linear-from-color": [{
2886
+ "mask-linear-from": scaleColor()
2887
+ }],
2888
+ "mask-image-linear-to-color": [{
2889
+ "mask-linear-to": scaleColor()
2890
+ }],
2891
+ "mask-image-t-from-pos": [{
2892
+ "mask-t-from": scaleMaskImagePosition()
2893
+ }],
2894
+ "mask-image-t-to-pos": [{
2895
+ "mask-t-to": scaleMaskImagePosition()
2896
+ }],
2897
+ "mask-image-t-from-color": [{
2898
+ "mask-t-from": scaleColor()
2899
+ }],
2900
+ "mask-image-t-to-color": [{
2901
+ "mask-t-to": scaleColor()
2902
+ }],
2903
+ "mask-image-r-from-pos": [{
2904
+ "mask-r-from": scaleMaskImagePosition()
2905
+ }],
2906
+ "mask-image-r-to-pos": [{
2907
+ "mask-r-to": scaleMaskImagePosition()
2908
+ }],
2909
+ "mask-image-r-from-color": [{
2910
+ "mask-r-from": scaleColor()
2911
+ }],
2912
+ "mask-image-r-to-color": [{
2913
+ "mask-r-to": scaleColor()
2914
+ }],
2915
+ "mask-image-b-from-pos": [{
2916
+ "mask-b-from": scaleMaskImagePosition()
2917
+ }],
2918
+ "mask-image-b-to-pos": [{
2919
+ "mask-b-to": scaleMaskImagePosition()
2920
+ }],
2921
+ "mask-image-b-from-color": [{
2922
+ "mask-b-from": scaleColor()
2923
+ }],
2924
+ "mask-image-b-to-color": [{
2925
+ "mask-b-to": scaleColor()
2926
+ }],
2927
+ "mask-image-l-from-pos": [{
2928
+ "mask-l-from": scaleMaskImagePosition()
2929
+ }],
2930
+ "mask-image-l-to-pos": [{
2931
+ "mask-l-to": scaleMaskImagePosition()
2932
+ }],
2933
+ "mask-image-l-from-color": [{
2934
+ "mask-l-from": scaleColor()
2935
+ }],
2936
+ "mask-image-l-to-color": [{
2937
+ "mask-l-to": scaleColor()
2938
+ }],
2939
+ "mask-image-x-from-pos": [{
2940
+ "mask-x-from": scaleMaskImagePosition()
2941
+ }],
2942
+ "mask-image-x-to-pos": [{
2943
+ "mask-x-to": scaleMaskImagePosition()
2944
+ }],
2945
+ "mask-image-x-from-color": [{
2946
+ "mask-x-from": scaleColor()
2947
+ }],
2948
+ "mask-image-x-to-color": [{
2949
+ "mask-x-to": scaleColor()
2950
+ }],
2951
+ "mask-image-y-from-pos": [{
2952
+ "mask-y-from": scaleMaskImagePosition()
2953
+ }],
2954
+ "mask-image-y-to-pos": [{
2955
+ "mask-y-to": scaleMaskImagePosition()
2956
+ }],
2957
+ "mask-image-y-from-color": [{
2958
+ "mask-y-from": scaleColor()
2959
+ }],
2960
+ "mask-image-y-to-color": [{
2961
+ "mask-y-to": scaleColor()
2962
+ }],
2963
+ "mask-image-radial": [{
2964
+ "mask-radial": [isArbitraryVariable, isArbitraryValue]
2965
+ }],
2966
+ "mask-image-radial-from-pos": [{
2967
+ "mask-radial-from": scaleMaskImagePosition()
2968
+ }],
2969
+ "mask-image-radial-to-pos": [{
2970
+ "mask-radial-to": scaleMaskImagePosition()
2971
+ }],
2972
+ "mask-image-radial-from-color": [{
2973
+ "mask-radial-from": scaleColor()
2974
+ }],
2975
+ "mask-image-radial-to-color": [{
2976
+ "mask-radial-to": scaleColor()
2977
+ }],
2978
+ "mask-image-radial-shape": [{
2979
+ "mask-radial": ["circle", "ellipse"]
2980
+ }],
2981
+ "mask-image-radial-size": [{
2982
+ "mask-radial": [{
2983
+ closest: ["side", "corner"],
2984
+ farthest: ["side", "corner"]
2985
+ }]
2986
+ }],
2987
+ "mask-image-radial-pos": [{
2988
+ "mask-radial-at": scalePosition()
2989
+ }],
2990
+ "mask-image-conic-pos": [{
2991
+ "mask-conic": [isNumber]
2992
+ }],
2993
+ "mask-image-conic-from-pos": [{
2994
+ "mask-conic-from": scaleMaskImagePosition()
2995
+ }],
2996
+ "mask-image-conic-to-pos": [{
2997
+ "mask-conic-to": scaleMaskImagePosition()
2998
+ }],
2999
+ "mask-image-conic-from-color": [{
3000
+ "mask-conic-from": scaleColor()
3001
+ }],
3002
+ "mask-image-conic-to-color": [{
3003
+ "mask-conic-to": scaleColor()
3004
+ }],
3005
+ "mask-mode": [{
3006
+ mask: ["alpha", "luminance", "match"]
3007
+ }],
3008
+ "mask-origin": [{
3009
+ "mask-origin": ["border", "padding", "content", "fill", "stroke", "view"]
3010
+ }],
3011
+ "mask-position": [{
3012
+ mask: scaleBgPosition()
3013
+ }],
3014
+ "mask-repeat": [{
3015
+ mask: scaleBgRepeat()
3016
+ }],
3017
+ "mask-size": [{
3018
+ mask: scaleBgSize()
3019
+ }],
3020
+ "mask-type": [{
3021
+ "mask-type": ["alpha", "luminance"]
3022
+ }],
3023
+ "mask-image": [{
3024
+ mask: ["none", isArbitraryVariable, isArbitraryValue]
3025
+ }],
3026
+ filter: [{
3027
+ filter: [
3028
+ "",
3029
+ "none",
3030
+ isArbitraryVariable,
3031
+ isArbitraryValue
3032
+ ]
3033
+ }],
3034
+ blur: [{
3035
+ blur: scaleBlur()
3036
+ }],
3037
+ brightness: [{
3038
+ brightness: [isNumber, isArbitraryVariable, isArbitraryValue]
3039
+ }],
3040
+ contrast: [{
3041
+ contrast: [isNumber, isArbitraryVariable, isArbitraryValue]
3042
+ }],
3043
+ "drop-shadow": [{
3044
+ "drop-shadow": [
3045
+ "",
3046
+ "none",
3047
+ themeDropShadow,
3048
+ isArbitraryVariableShadow,
3049
+ isArbitraryShadow
3050
+ ]
3051
+ }],
3052
+ "drop-shadow-color": [{
3053
+ "drop-shadow": scaleColor()
3054
+ }],
3055
+ grayscale: [{
3056
+ grayscale: ["", isNumber, isArbitraryVariable, isArbitraryValue]
3057
+ }],
3058
+ "hue-rotate": [{
3059
+ "hue-rotate": [isNumber, isArbitraryVariable, isArbitraryValue]
3060
+ }],
3061
+ invert: [{
3062
+ invert: ["", isNumber, isArbitraryVariable, isArbitraryValue]
3063
+ }],
3064
+ saturate: [{
3065
+ saturate: [isNumber, isArbitraryVariable, isArbitraryValue]
3066
+ }],
3067
+ sepia: [{
3068
+ sepia: ["", isNumber, isArbitraryVariable, isArbitraryValue]
3069
+ }],
3070
+ "backdrop-filter": [{
3071
+ "backdrop-filter": [
3072
+ "",
3073
+ "none",
3074
+ isArbitraryVariable,
3075
+ isArbitraryValue
3076
+ ]
3077
+ }],
3078
+ "backdrop-blur": [{
3079
+ "backdrop-blur": scaleBlur()
3080
+ }],
3081
+ "backdrop-brightness": [{
3082
+ "backdrop-brightness": [isNumber, isArbitraryVariable, isArbitraryValue]
3083
+ }],
3084
+ "backdrop-contrast": [{
3085
+ "backdrop-contrast": [isNumber, isArbitraryVariable, isArbitraryValue]
3086
+ }],
3087
+ "backdrop-grayscale": [{
3088
+ "backdrop-grayscale": ["", isNumber, isArbitraryVariable, isArbitraryValue]
3089
+ }],
3090
+ "backdrop-hue-rotate": [{
3091
+ "backdrop-hue-rotate": [isNumber, isArbitraryVariable, isArbitraryValue]
3092
+ }],
3093
+ "backdrop-invert": [{
3094
+ "backdrop-invert": ["", isNumber, isArbitraryVariable, isArbitraryValue]
3095
+ }],
3096
+ "backdrop-opacity": [{
3097
+ "backdrop-opacity": [isNumber, isArbitraryVariable, isArbitraryValue]
3098
+ }],
3099
+ "backdrop-saturate": [{
3100
+ "backdrop-saturate": [isNumber, isArbitraryVariable, isArbitraryValue]
3101
+ }],
3102
+ "backdrop-sepia": [{
3103
+ "backdrop-sepia": ["", isNumber, isArbitraryVariable, isArbitraryValue]
3104
+ }],
3105
+ "border-collapse": [{
3106
+ border: ["collapse", "separate"]
3107
+ }],
3108
+ "border-spacing": [{
3109
+ "border-spacing": scaleUnambiguousSpacing()
3110
+ }],
3111
+ "border-spacing-x": [{
3112
+ "border-spacing-x": scaleUnambiguousSpacing()
3113
+ }],
3114
+ "border-spacing-y": [{
3115
+ "border-spacing-y": scaleUnambiguousSpacing()
3116
+ }],
3117
+ "table-layout": [{
3118
+ table: ["auto", "fixed"]
3119
+ }],
3120
+ caption: [{
3121
+ caption: ["top", "bottom"]
3122
+ }],
3123
+ transition: [{
3124
+ transition: ["", "all", "colors", "opacity", "shadow", "transform", "none", isArbitraryVariable, isArbitraryValue]
3125
+ }],
3126
+ "transition-behavior": [{
3127
+ transition: ["normal", "discrete"]
3128
+ }],
3129
+ duration: [{
3130
+ duration: [isNumber, "initial", isArbitraryVariable, isArbitraryValue]
3131
+ }],
3132
+ ease: [{
3133
+ ease: ["linear", "initial", themeEase, isArbitraryVariable, isArbitraryValue]
3134
+ }],
3135
+ delay: [{
3136
+ delay: [isNumber, isArbitraryVariable, isArbitraryValue]
3137
+ }],
3138
+ animate: [{
3139
+ animate: ["none", themeAnimate, isArbitraryVariable, isArbitraryValue]
3140
+ }],
3141
+ backface: [{
3142
+ backface: ["hidden", "visible"]
3143
+ }],
3144
+ perspective: [{
3145
+ perspective: [themePerspective, isArbitraryVariable, isArbitraryValue]
3146
+ }],
3147
+ "perspective-origin": [{
3148
+ "perspective-origin": scalePositionWithArbitrary()
3149
+ }],
3150
+ rotate: [{
3151
+ rotate: scaleRotate()
3152
+ }],
3153
+ "rotate-x": [{
3154
+ "rotate-x": scaleRotate()
3155
+ }],
3156
+ "rotate-y": [{
3157
+ "rotate-y": scaleRotate()
3158
+ }],
3159
+ "rotate-z": [{
3160
+ "rotate-z": scaleRotate()
3161
+ }],
3162
+ scale: [{
3163
+ scale: scaleScale()
3164
+ }],
3165
+ "scale-x": [{
3166
+ "scale-x": scaleScale()
3167
+ }],
3168
+ "scale-y": [{
3169
+ "scale-y": scaleScale()
3170
+ }],
3171
+ "scale-z": [{
3172
+ "scale-z": scaleScale()
3173
+ }],
3174
+ "scale-3d": ["scale-3d"],
3175
+ skew: [{
3176
+ skew: scaleSkew()
3177
+ }],
3178
+ "skew-x": [{
3179
+ "skew-x": scaleSkew()
3180
+ }],
3181
+ "skew-y": [{
3182
+ "skew-y": scaleSkew()
3183
+ }],
3184
+ transform: [{
3185
+ transform: [isArbitraryVariable, isArbitraryValue, "", "none", "gpu", "cpu"]
3186
+ }],
3187
+ "transform-origin": [{
3188
+ origin: scalePositionWithArbitrary()
3189
+ }],
3190
+ "transform-style": [{
3191
+ transform: ["3d", "flat"]
3192
+ }],
3193
+ translate: [{
3194
+ translate: scaleTranslate()
3195
+ }],
3196
+ "translate-x": [{
3197
+ "translate-x": scaleTranslate()
3198
+ }],
3199
+ "translate-y": [{
3200
+ "translate-y": scaleTranslate()
3201
+ }],
3202
+ "translate-z": [{
3203
+ "translate-z": scaleTranslate()
3204
+ }],
3205
+ "translate-none": ["translate-none"],
3206
+ accent: [{
3207
+ accent: scaleColor()
3208
+ }],
3209
+ appearance: [{
3210
+ appearance: ["none", "auto"]
3211
+ }],
3212
+ "caret-color": [{
3213
+ caret: scaleColor()
3214
+ }],
3215
+ "color-scheme": [{
3216
+ scheme: ["normal", "dark", "light", "light-dark", "only-dark", "only-light"]
3217
+ }],
3218
+ cursor: [{
3219
+ cursor: ["auto", "default", "pointer", "wait", "text", "move", "help", "not-allowed", "none", "context-menu", "progress", "cell", "crosshair", "vertical-text", "alias", "copy", "no-drop", "grab", "grabbing", "all-scroll", "col-resize", "row-resize", "n-resize", "e-resize", "s-resize", "w-resize", "ne-resize", "nw-resize", "se-resize", "sw-resize", "ew-resize", "ns-resize", "nesw-resize", "nwse-resize", "zoom-in", "zoom-out", isArbitraryVariable, isArbitraryValue]
3220
+ }],
3221
+ "field-sizing": [{
3222
+ "field-sizing": ["fixed", "content"]
3223
+ }],
3224
+ "pointer-events": [{
3225
+ "pointer-events": ["auto", "none"]
3226
+ }],
3227
+ resize: [{
3228
+ resize: ["none", "", "y", "x"]
3229
+ }],
3230
+ "scroll-behavior": [{
3231
+ scroll: ["auto", "smooth"]
3232
+ }],
3233
+ "scroll-m": [{
3234
+ "scroll-m": scaleUnambiguousSpacing()
3235
+ }],
3236
+ "scroll-mx": [{
3237
+ "scroll-mx": scaleUnambiguousSpacing()
3238
+ }],
3239
+ "scroll-my": [{
3240
+ "scroll-my": scaleUnambiguousSpacing()
3241
+ }],
3242
+ "scroll-ms": [{
3243
+ "scroll-ms": scaleUnambiguousSpacing()
3244
+ }],
3245
+ "scroll-me": [{
3246
+ "scroll-me": scaleUnambiguousSpacing()
3247
+ }],
3248
+ "scroll-mt": [{
3249
+ "scroll-mt": scaleUnambiguousSpacing()
3250
+ }],
3251
+ "scroll-mr": [{
3252
+ "scroll-mr": scaleUnambiguousSpacing()
3253
+ }],
3254
+ "scroll-mb": [{
3255
+ "scroll-mb": scaleUnambiguousSpacing()
3256
+ }],
3257
+ "scroll-ml": [{
3258
+ "scroll-ml": scaleUnambiguousSpacing()
3259
+ }],
3260
+ "scroll-p": [{
3261
+ "scroll-p": scaleUnambiguousSpacing()
3262
+ }],
3263
+ "scroll-px": [{
3264
+ "scroll-px": scaleUnambiguousSpacing()
3265
+ }],
3266
+ "scroll-py": [{
3267
+ "scroll-py": scaleUnambiguousSpacing()
3268
+ }],
3269
+ "scroll-ps": [{
3270
+ "scroll-ps": scaleUnambiguousSpacing()
3271
+ }],
3272
+ "scroll-pe": [{
3273
+ "scroll-pe": scaleUnambiguousSpacing()
3274
+ }],
3275
+ "scroll-pt": [{
3276
+ "scroll-pt": scaleUnambiguousSpacing()
3277
+ }],
3278
+ "scroll-pr": [{
3279
+ "scroll-pr": scaleUnambiguousSpacing()
3280
+ }],
3281
+ "scroll-pb": [{
3282
+ "scroll-pb": scaleUnambiguousSpacing()
3283
+ }],
3284
+ "scroll-pl": [{
3285
+ "scroll-pl": scaleUnambiguousSpacing()
3286
+ }],
3287
+ "snap-align": [{
3288
+ snap: ["start", "end", "center", "align-none"]
3289
+ }],
3290
+ "snap-stop": [{
3291
+ snap: ["normal", "always"]
3292
+ }],
3293
+ "snap-type": [{
3294
+ snap: ["none", "x", "y", "both"]
3295
+ }],
3296
+ "snap-strictness": [{
3297
+ snap: ["mandatory", "proximity"]
3298
+ }],
3299
+ touch: [{
3300
+ touch: ["auto", "none", "manipulation"]
3301
+ }],
3302
+ "touch-x": [{
3303
+ "touch-pan": ["x", "left", "right"]
3304
+ }],
3305
+ "touch-y": [{
3306
+ "touch-pan": ["y", "up", "down"]
3307
+ }],
3308
+ "touch-pz": ["touch-pinch-zoom"],
3309
+ select: [{
3310
+ select: ["none", "text", "all", "auto"]
3311
+ }],
3312
+ "will-change": [{
3313
+ "will-change": ["auto", "scroll", "contents", "transform", isArbitraryVariable, isArbitraryValue]
3314
+ }],
3315
+ fill: [{
3316
+ fill: ["none", ...scaleColor()]
3317
+ }],
3318
+ "stroke-w": [{
3319
+ stroke: [isNumber, isArbitraryVariableLength, isArbitraryLength, isArbitraryNumber]
3320
+ }],
3321
+ stroke: [{
3322
+ stroke: ["none", ...scaleColor()]
3323
+ }],
3324
+ "forced-color-adjust": [{
3325
+ "forced-color-adjust": ["auto", "none"]
3326
+ }]
3327
+ },
3328
+ conflictingClassGroups: {
3329
+ overflow: ["overflow-x", "overflow-y"],
3330
+ overscroll: ["overscroll-x", "overscroll-y"],
3331
+ inset: ["inset-x", "inset-y", "start", "end", "top", "right", "bottom", "left"],
3332
+ "inset-x": ["right", "left"],
3333
+ "inset-y": ["top", "bottom"],
3334
+ flex: ["basis", "grow", "shrink"],
3335
+ gap: ["gap-x", "gap-y"],
3336
+ p: ["px", "py", "ps", "pe", "pt", "pr", "pb", "pl"],
3337
+ px: ["pr", "pl"],
3338
+ py: ["pt", "pb"],
3339
+ m: ["mx", "my", "ms", "me", "mt", "mr", "mb", "ml"],
3340
+ mx: ["mr", "ml"],
3341
+ my: ["mt", "mb"],
3342
+ size: ["w", "h"],
3343
+ "font-size": ["leading"],
3344
+ "fvn-normal": ["fvn-ordinal", "fvn-slashed-zero", "fvn-figure", "fvn-spacing", "fvn-fraction"],
3345
+ "fvn-ordinal": ["fvn-normal"],
3346
+ "fvn-slashed-zero": ["fvn-normal"],
3347
+ "fvn-figure": ["fvn-normal"],
3348
+ "fvn-spacing": ["fvn-normal"],
3349
+ "fvn-fraction": ["fvn-normal"],
3350
+ "line-clamp": ["display", "overflow"],
3351
+ rounded: ["rounded-s", "rounded-e", "rounded-t", "rounded-r", "rounded-b", "rounded-l", "rounded-ss", "rounded-se", "rounded-ee", "rounded-es", "rounded-tl", "rounded-tr", "rounded-br", "rounded-bl"],
3352
+ "rounded-s": ["rounded-ss", "rounded-es"],
3353
+ "rounded-e": ["rounded-se", "rounded-ee"],
3354
+ "rounded-t": ["rounded-tl", "rounded-tr"],
3355
+ "rounded-r": ["rounded-tr", "rounded-br"],
3356
+ "rounded-b": ["rounded-br", "rounded-bl"],
3357
+ "rounded-l": ["rounded-tl", "rounded-bl"],
3358
+ "border-spacing": ["border-spacing-x", "border-spacing-y"],
3359
+ "border-w": ["border-w-x", "border-w-y", "border-w-s", "border-w-e", "border-w-t", "border-w-r", "border-w-b", "border-w-l"],
3360
+ "border-w-x": ["border-w-r", "border-w-l"],
3361
+ "border-w-y": ["border-w-t", "border-w-b"],
3362
+ "border-color": ["border-color-x", "border-color-y", "border-color-s", "border-color-e", "border-color-t", "border-color-r", "border-color-b", "border-color-l"],
3363
+ "border-color-x": ["border-color-r", "border-color-l"],
3364
+ "border-color-y": ["border-color-t", "border-color-b"],
3365
+ translate: ["translate-x", "translate-y", "translate-none"],
3366
+ "translate-none": ["translate", "translate-x", "translate-y", "translate-z"],
3367
+ "scroll-m": ["scroll-mx", "scroll-my", "scroll-ms", "scroll-me", "scroll-mt", "scroll-mr", "scroll-mb", "scroll-ml"],
3368
+ "scroll-mx": ["scroll-mr", "scroll-ml"],
3369
+ "scroll-my": ["scroll-mt", "scroll-mb"],
3370
+ "scroll-p": ["scroll-px", "scroll-py", "scroll-ps", "scroll-pe", "scroll-pt", "scroll-pr", "scroll-pb", "scroll-pl"],
3371
+ "scroll-px": ["scroll-pr", "scroll-pl"],
3372
+ "scroll-py": ["scroll-pt", "scroll-pb"],
3373
+ touch: ["touch-x", "touch-y", "touch-pz"],
3374
+ "touch-x": ["touch"],
3375
+ "touch-y": ["touch"],
3376
+ "touch-pz": ["touch"]
3377
+ },
3378
+ conflictingClassGroupModifiers: {
3379
+ "font-size": ["leading"]
3380
+ },
3381
+ orderSensitiveModifiers: ["*", "**", "after", "backdrop", "before", "details-content", "file", "first-letter", "first-line", "marker", "placeholder", "selection"]
3382
+ };
3383
+ };
3384
+ var twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
3385
+
3386
+ // src/shared/utils.ts
3387
+ function cn(...inputs) {
3388
+ return twMerge(clsx(inputs));
3389
+ }
3390
+ function groupPages(pages) {
3391
+ const groups = new Map;
3392
+ for (const page of pages) {
3393
+ const groupName = page.group ?? null;
3394
+ if (!groups.has(groupName)) {
3395
+ groups.set(groupName, { name: groupName, pages: [] });
3396
+ }
3397
+ groups.get(groupName).pages.push({
3398
+ slug: page.slug,
3399
+ title: page.title,
3400
+ icon: page.icon
3401
+ });
3402
+ }
3403
+ return Array.from(groups.values()).sort((a, b) => {
3404
+ if (a.name === null)
3405
+ return -1;
3406
+ if (b.name === null)
3407
+ return 1;
3408
+ return a.name.localeCompare(b.name);
3409
+ });
3410
+ }
3411
+ function getNestedError(errors, path) {
3412
+ const parts = path.split(".");
3413
+ let current = errors;
3414
+ for (const part of parts) {
3415
+ if (current && typeof current === "object" && part in current) {
3416
+ current = current[part];
3417
+ } else {
3418
+ return;
3419
+ }
3420
+ }
3421
+ return current;
3422
+ }
3423
+ function flattenValue(key, value, result = []) {
3424
+ if (value === null || value === undefined) {
3425
+ return result;
3426
+ }
3427
+ if (Array.isArray(value)) {
3428
+ value.forEach((item, index) => {
3429
+ flattenValue(`${key}[${index}]`, item, result);
3430
+ });
3431
+ } else if (typeof value === "object") {
3432
+ for (const [subKey, subValue] of Object.entries(value)) {
3433
+ flattenValue(`${key}.${subKey}`, subValue, result);
3434
+ }
3435
+ } else {
3436
+ result.push([key, String(value)]);
3437
+ }
3438
+ return result;
3439
+ }
3440
+ function groupFields(fields) {
3441
+ const groups = new Map;
3442
+ for (const field of fields) {
3443
+ const groupName = field.meta.group ?? null;
3444
+ if (!groups.has(groupName)) {
3445
+ groups.set(groupName, { name: groupName, fields: [] });
3446
+ }
3447
+ groups.get(groupName).fields.push(field);
3448
+ }
3449
+ return Array.from(groups.values()).sort((a, b) => {
3450
+ if (a.name === null)
3451
+ return -1;
3452
+ if (b.name === null)
3453
+ return 1;
3454
+ return a.name.localeCompare(b.name);
3455
+ });
3456
+ }
3457
+
3458
+ // src/components/CmsField.tsx
3459
+ import { jsxDEV } from "react/jsx-dev-runtime";
3460
+ var defaultInputClass = "w-full px-4 py-2.5 text-sm bg-white border border-neutral-200 text-neutral-900 placeholder:text-neutral-300 outline-none hover:border-neutral-300 focus:border-neutral-900 transition-colors";
3461
+ var defaultTextareaClass = cn(defaultInputClass, "min-h-[120px] resize-y py-3");
3462
+ var defaultSelectClass = "w-full px-4 py-2.5 text-sm bg-white border border-neutral-200 text-neutral-900 outline-none hover:border-neutral-300 focus:border-neutral-900 transition-colors appearance-none cursor-pointer";
3463
+ var defaultLabelClass = "text-xs font-medium uppercase tracking-widest text-neutral-400 mb-3 block";
3464
+ var defaultErrorClass = "text-xs mt-2 text-red-600";
3465
+ var defaultHelpClass = "text-xs mt-2 text-neutral-400";
3466
+ var defaultCheckboxClass = "h-4 w-4 border border-neutral-300 bg-transparent focus:ring-0 focus:ring-offset-0 disabled:cursor-not-allowed disabled:opacity-50 transition-colors cursor-pointer accent-neutral-900";
3467
+ function CmsField({
3468
+ name,
3469
+ label,
3470
+ type = "text",
3471
+ placeholder,
3472
+ helpText,
3473
+ options = [],
3474
+ rows = 4,
3475
+ required = false,
3476
+ disabled = false,
3477
+ className = "space-y-1",
3478
+ inputClassName,
3479
+ labelClassName,
3480
+ errorClassName,
3481
+ helpClassName
3482
+ }) {
3483
+ const {
3484
+ register,
3485
+ formState: { errors }
3486
+ } = useFormContext();
3487
+ const error = name.includes(".") ? getNestedError(errors, name) : errors[name];
3488
+ const errorMessage = error?.message;
3489
+ const inputId = `cms-field-${name.replace(/\./g, "-")}`;
3490
+ const registerOptions = type === "number" ? { valueAsNumber: true } : undefined;
3491
+ const commonProps = {
3492
+ id: inputId,
3493
+ placeholder,
3494
+ disabled,
3495
+ "aria-invalid": !!error,
3496
+ "aria-describedby": errorMessage ? `${inputId}-error` : helpText ? `${inputId}-help` : undefined,
3497
+ ...register(name, registerOptions)
3498
+ };
3499
+ const resolvedInputClass = inputClassName ?? (type === "textarea" ? defaultTextareaClass : type === "select" ? defaultSelectClass : defaultInputClass);
3500
+ const errorBorderClass = errorMessage ? "border-red-400 focus:border-red-600" : "";
3501
+ return /* @__PURE__ */ jsxDEV("div", {
3502
+ className,
3503
+ children: [
3504
+ /* @__PURE__ */ jsxDEV("label", {
3505
+ htmlFor: inputId,
3506
+ className: labelClassName ?? defaultLabelClass,
3507
+ children: [
3508
+ label,
3509
+ required && /* @__PURE__ */ jsxDEV("span", {
3510
+ className: "text-red-500 ml-0.5",
3511
+ "aria-hidden": "true",
3512
+ children: "*"
3513
+ }, undefined, false, undefined, this)
3514
+ ]
3515
+ }, undefined, true, undefined, this),
3516
+ /* @__PURE__ */ jsxDEV("div", {
3517
+ className: "relative",
3518
+ children: type === "textarea" ? /* @__PURE__ */ jsxDEV("textarea", {
3519
+ ...commonProps,
3520
+ rows,
3521
+ className: cn(resolvedInputClass, errorBorderClass)
3522
+ }, undefined, false, undefined, this) : type === "select" ? /* @__PURE__ */ jsxDEV("div", {
3523
+ className: "relative",
3524
+ children: [
3525
+ /* @__PURE__ */ jsxDEV("select", {
3526
+ ...commonProps,
3527
+ className: cn(resolvedInputClass, errorBorderClass),
3528
+ children: [
3529
+ /* @__PURE__ */ jsxDEV("option", {
3530
+ value: "",
3531
+ className: "text-neutral-400",
3532
+ children: "Select..."
3533
+ }, undefined, false, undefined, this),
3534
+ options.map((opt) => /* @__PURE__ */ jsxDEV("option", {
3535
+ value: opt.value,
3536
+ children: opt.label
3537
+ }, opt.value, false, undefined, this))
3538
+ ]
3539
+ }, undefined, true, undefined, this),
3540
+ /* @__PURE__ */ jsxDEV("div", {
3541
+ className: "pointer-events-none absolute inset-y-0 right-0 flex items-center text-neutral-400",
3542
+ children: /* @__PURE__ */ jsxDEV("svg", {
3543
+ className: "h-4 w-4",
3544
+ fill: "none",
3545
+ stroke: "currentColor",
3546
+ viewBox: "0 0 24 24",
3547
+ children: /* @__PURE__ */ jsxDEV("path", {
3548
+ strokeLinecap: "round",
3549
+ strokeLinejoin: "round",
3550
+ strokeWidth: "1.5",
3551
+ d: "M19 9l-7 7-7-7"
3552
+ }, undefined, false, undefined, this)
3553
+ }, undefined, false, undefined, this)
3554
+ }, undefined, false, undefined, this)
3555
+ ]
3556
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsxDEV("input", {
3557
+ ...commonProps,
3558
+ type,
3559
+ inputMode: type === "number" ? "numeric" : undefined,
3560
+ className: cn(resolvedInputClass, errorBorderClass)
3561
+ }, undefined, false, undefined, this)
3562
+ }, undefined, false, undefined, this),
3563
+ helpText && !errorMessage && /* @__PURE__ */ jsxDEV("p", {
3564
+ id: `${inputId}-help`,
3565
+ className: helpClassName ?? defaultHelpClass,
3566
+ children: helpText
3567
+ }, undefined, false, undefined, this),
3568
+ errorMessage && /* @__PURE__ */ jsxDEV("p", {
3569
+ id: `${inputId}-error`,
3570
+ role: "alert",
3571
+ className: errorClassName ?? defaultErrorClass,
3572
+ children: errorMessage
3573
+ }, undefined, false, undefined, this)
3574
+ ]
3575
+ }, undefined, true, undefined, this);
3576
+ }
3577
+ function CmsHiddenField({
3578
+ name,
3579
+ value
3580
+ }) {
3581
+ return /* @__PURE__ */ jsxDEV("input", {
3582
+ type: "hidden",
3583
+ name,
3584
+ value
3585
+ }, undefined, false, undefined, this);
3586
+ }
3587
+ function CmsCheckbox({
3588
+ name,
3589
+ label,
3590
+ helpText,
3591
+ disabled = false,
3592
+ className = "space-y-2",
3593
+ inputClassName,
3594
+ labelClassName,
3595
+ errorClassName,
3596
+ helpClassName
3597
+ }) {
3598
+ const {
3599
+ register,
3600
+ formState: { errors }
3601
+ } = useFormContext();
3602
+ const error = name.includes(".") ? getNestedError(errors, name) : errors[name];
3603
+ const errorMessage = error?.message;
3604
+ const inputId = `cms-checkbox-${name.replace(/\./g, "-")}`;
3605
+ return /* @__PURE__ */ jsxDEV("div", {
3606
+ className,
3607
+ children: [
3608
+ /* @__PURE__ */ jsxDEV("div", {
3609
+ className: "flex items-start gap-3",
3610
+ children: [
3611
+ /* @__PURE__ */ jsxDEV("div", {
3612
+ className: "flex h-5 items-center",
3613
+ children: /* @__PURE__ */ jsxDEV("input", {
3614
+ type: "checkbox",
3615
+ id: inputId,
3616
+ disabled,
3617
+ "aria-invalid": !!error,
3618
+ "aria-describedby": errorMessage ? `${inputId}-error` : undefined,
3619
+ className: inputClassName ?? defaultCheckboxClass,
3620
+ ...register(name)
3621
+ }, undefined, false, undefined, this)
3622
+ }, undefined, false, undefined, this),
3623
+ /* @__PURE__ */ jsxDEV("div", {
3624
+ className: "space-y-1",
3625
+ children: [
3626
+ /* @__PURE__ */ jsxDEV("label", {
3627
+ htmlFor: inputId,
3628
+ className: labelClassName ?? "text-sm text-neutral-900 cursor-pointer",
3629
+ children: label
3630
+ }, undefined, false, undefined, this),
3631
+ helpText && /* @__PURE__ */ jsxDEV("p", {
3632
+ id: `${inputId}-help`,
3633
+ className: helpClassName ?? "text-xs text-neutral-400",
3634
+ children: helpText
3635
+ }, undefined, false, undefined, this)
3636
+ ]
3637
+ }, undefined, true, undefined, this)
3638
+ ]
3639
+ }, undefined, true, undefined, this),
3640
+ errorMessage && /* @__PURE__ */ jsxDEV("p", {
3641
+ id: `${inputId}-error`,
3642
+ role: "alert",
3643
+ className: errorClassName ?? defaultErrorClass,
3644
+ children: errorMessage
3645
+ }, undefined, false, undefined, this)
3646
+ ]
3647
+ }, undefined, true, undefined, this);
3648
+ }
3649
+
3650
+ // src/components/CmsImageField.tsx
3651
+ import * as React2 from "react";
3652
+ import { jsxDEV as jsxDEV2, Fragment } from "react/jsx-dev-runtime";
3653
+ var defaultLabelClass2 = "text-xs font-medium uppercase tracking-widest text-neutral-400 mb-3 block";
3654
+ var defaultErrorClass2 = "text-xs mt-2 text-red-600";
3655
+ var defaultHelpClass2 = "text-xs mt-2 text-neutral-400";
3656
+ function CmsImageField({
3657
+ name,
3658
+ label,
3659
+ helpText,
3660
+ required = false,
3661
+ disabled = false,
3662
+ accept = "image/*",
3663
+ className = "space-y-1",
3664
+ labelClassName,
3665
+ errorClassName,
3666
+ helpClassName,
3667
+ storage
3668
+ }) {
3669
+ const {
3670
+ register,
3671
+ setValue,
3672
+ watch,
3673
+ formState: { errors }
3674
+ } = useFormContext();
3675
+ const [isModalOpen, setIsModalOpen] = React2.useState(false);
3676
+ const currentValue = watch(name);
3677
+ const error = errors[name];
3678
+ const errorMessage = error?.message;
3679
+ const inputId = `cms-image-${name.replace(/\./g, "-")}`;
3680
+ const handleImageSelect = (url) => {
3681
+ setValue(name, url, {
3682
+ shouldValidate: true,
3683
+ shouldDirty: true
3684
+ });
3685
+ setIsModalOpen(false);
3686
+ };
3687
+ const handleClear = () => {
3688
+ setValue(name, "", { shouldValidate: true, shouldDirty: true });
3689
+ };
3690
+ return /* @__PURE__ */ jsxDEV2("div", {
3691
+ className,
3692
+ children: [
3693
+ /* @__PURE__ */ jsxDEV2("input", {
3694
+ type: "hidden",
3695
+ ...register(name)
3696
+ }, undefined, false, undefined, this),
3697
+ /* @__PURE__ */ jsxDEV2("label", {
3698
+ htmlFor: inputId,
3699
+ className: labelClassName ?? defaultLabelClass2,
3700
+ children: [
3701
+ label,
3702
+ required && /* @__PURE__ */ jsxDEV2("span", {
3703
+ className: "text-red-500 ml-0.5",
3704
+ "aria-hidden": "true",
3705
+ children: "*"
3706
+ }, undefined, false, undefined, this)
3707
+ ]
3708
+ }, undefined, true, undefined, this),
3709
+ /* @__PURE__ */ jsxDEV2("div", {
3710
+ className: "border border-neutral-200 bg-neutral-50",
3711
+ children: currentValue ? /* @__PURE__ */ jsxDEV2("div", {
3712
+ className: "relative group",
3713
+ children: [
3714
+ /* @__PURE__ */ jsxDEV2("img", {
3715
+ src: currentValue,
3716
+ alt: `${label} preview`,
3717
+ className: "w-full h-48 object-cover"
3718
+ }, undefined, false, undefined, this),
3719
+ /* @__PURE__ */ jsxDEV2("div", {
3720
+ className: "absolute inset-0 flex items-center justify-center gap-4 opacity-0 group-hover:opacity-100 transition-opacity bg-black/50",
3721
+ children: [
3722
+ /* @__PURE__ */ jsxDEV2("button", {
3723
+ type: "button",
3724
+ onClick: () => setIsModalOpen(true),
3725
+ disabled,
3726
+ className: "text-xs tracking-wide text-white border-b border-white pb-0.5 hover:pb-1 transition-all cursor-pointer",
3727
+ children: "Replace"
3728
+ }, undefined, false, undefined, this),
3729
+ /* @__PURE__ */ jsxDEV2("button", {
3730
+ type: "button",
3731
+ onClick: handleClear,
3732
+ disabled,
3733
+ className: "text-xs tracking-wide text-white/70 hover:text-white transition-colors cursor-pointer",
3734
+ children: "Remove"
3735
+ }, undefined, false, undefined, this)
3736
+ ]
3737
+ }, undefined, true, undefined, this)
3738
+ ]
3739
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsxDEV2("div", {
3740
+ className: "flex flex-col items-center justify-center py-12 px-4 cursor-pointer transition-colors hover:bg-neutral-100",
3741
+ onClick: () => !disabled && setIsModalOpen(true),
3742
+ children: [
3743
+ /* @__PURE__ */ jsxDEV2("svg", {
3744
+ className: "w-8 h-8 mb-3 text-neutral-300",
3745
+ viewBox: "0 0 24 24",
3746
+ fill: "none",
3747
+ stroke: "currentColor",
3748
+ strokeWidth: "1",
3749
+ children: [
3750
+ /* @__PURE__ */ jsxDEV2("rect", {
3751
+ x: "3",
3752
+ y: "3",
3753
+ width: "18",
3754
+ height: "18",
3755
+ rx: "0"
3756
+ }, undefined, false, undefined, this),
3757
+ /* @__PURE__ */ jsxDEV2("circle", {
3758
+ cx: "8.5",
3759
+ cy: "8.5",
3760
+ r: "1.5"
3761
+ }, undefined, false, undefined, this),
3762
+ /* @__PURE__ */ jsxDEV2("polyline", {
3763
+ points: "21 15 16 10 5 21"
3764
+ }, undefined, false, undefined, this)
3765
+ ]
3766
+ }, undefined, true, undefined, this),
3767
+ /* @__PURE__ */ jsxDEV2("span", {
3768
+ className: "text-sm text-neutral-400",
3769
+ children: "Click to select image"
3770
+ }, undefined, false, undefined, this)
3771
+ ]
3772
+ }, undefined, true, undefined, this)
3773
+ }, undefined, false, undefined, this),
3774
+ helpText && !errorMessage && /* @__PURE__ */ jsxDEV2("p", {
3775
+ id: `${inputId}-help`,
3776
+ className: helpClassName ?? defaultHelpClass2,
3777
+ children: helpText
3778
+ }, undefined, false, undefined, this),
3779
+ errorMessage && /* @__PURE__ */ jsxDEV2("p", {
3780
+ id: `${inputId}-error`,
3781
+ role: "alert",
3782
+ className: errorClassName ?? defaultErrorClass2,
3783
+ children: errorMessage
3784
+ }, undefined, false, undefined, this),
3785
+ isModalOpen && /* @__PURE__ */ jsxDEV2(ImagePickerModal, {
3786
+ storage,
3787
+ accept,
3788
+ onSelect: handleImageSelect,
3789
+ onClose: () => setIsModalOpen(false),
3790
+ currentValue
3791
+ }, undefined, false, undefined, this)
3792
+ ]
3793
+ }, undefined, true, undefined, this);
3794
+ }
3795
+ function ImagePickerModal({
3796
+ storage,
3797
+ accept,
3798
+ onSelect,
3799
+ onClose,
3800
+ currentValue
3801
+ }) {
3802
+ const [images, setImages] = React2.useState([]);
3803
+ const [isLoading, setIsLoading] = React2.useState(true);
3804
+ const [isUploading, setIsUploading] = React2.useState(false);
3805
+ const [uploadProgress, setUploadProgress] = React2.useState([]);
3806
+ const [error, setError] = React2.useState(null);
3807
+ const [isDragging, setIsDragging] = React2.useState(false);
3808
+ const [selectedImage, setSelectedImage] = React2.useState(currentValue || null);
3809
+ const fileInputRef = React2.useRef(null);
3810
+ const dropZoneRef = React2.useRef(null);
3811
+ React2.useEffect(() => {
3812
+ if (storage?.listEndpoint) {
3813
+ fetchImages();
3814
+ } else {
3815
+ setIsLoading(false);
3816
+ }
3817
+ }, [storage?.listEndpoint]);
3818
+ const fetchImages = async () => {
3819
+ if (!storage?.listEndpoint)
3820
+ return;
3821
+ try {
3822
+ const response = await fetch(storage.listEndpoint);
3823
+ if (response.ok) {
3824
+ const data = await response.json();
3825
+ const sortedImages = (data.files || []).sort((a, b) => {
3826
+ const dateA = a.lastModified ? new Date(a.lastModified).getTime() : 0;
3827
+ const dateB = b.lastModified ? new Date(b.lastModified).getTime() : 0;
3828
+ return dateB - dateA;
3829
+ });
3830
+ setImages(sortedImages);
3831
+ }
3832
+ } catch (err) {
3833
+ console.error("[litecms] Failed to fetch images:", err);
3834
+ } finally {
3835
+ setIsLoading(false);
3836
+ }
3837
+ };
3838
+ const uploadFiles = async (files) => {
3839
+ if (!storage?.uploadEndpoint)
3840
+ return;
3841
+ const fileArray = Array.from(files).filter((f) => f.type.startsWith("image/"));
3842
+ if (fileArray.length === 0) {
3843
+ setError("Please select image files only");
3844
+ return;
3845
+ }
3846
+ setIsUploading(true);
3847
+ setError(null);
3848
+ setUploadProgress([]);
3849
+ const uploadedUrls = [];
3850
+ for (let i = 0;i < fileArray.length; i++) {
3851
+ const file = fileArray[i];
3852
+ setUploadProgress((prev) => [...prev, `Uploading ${file.name}...`]);
3853
+ try {
3854
+ const formData = new FormData;
3855
+ formData.append("file", file);
3856
+ const response = await fetch(storage.uploadEndpoint, {
3857
+ method: "POST",
3858
+ body: formData
3859
+ });
3860
+ if (!response.ok) {
3861
+ const errorData = await response.json().catch(() => ({}));
3862
+ throw new Error(errorData.error || `Failed to upload ${file.name}`);
3863
+ }
3864
+ const data = await response.json();
3865
+ uploadedUrls.push(data.url);
3866
+ setUploadProgress((prev) => prev.map((p, idx) => idx === i ? `✓ ${file.name}` : p));
3867
+ } catch (err) {
3868
+ console.error("[litecms] Upload error:", err);
3869
+ setUploadProgress((prev) => prev.map((p, idx) => idx === i ? `✗ ${file.name} failed` : p));
3870
+ }
3871
+ }
3872
+ setIsUploading(false);
3873
+ await fetchImages();
3874
+ if (uploadedUrls.length > 0) {
3875
+ setSelectedImage(uploadedUrls[uploadedUrls.length - 1]);
3876
+ }
3877
+ setTimeout(() => setUploadProgress([]), 2000);
3878
+ };
3879
+ const handleDragOver = (e) => {
3880
+ e.preventDefault();
3881
+ e.stopPropagation();
3882
+ setIsDragging(true);
3883
+ };
3884
+ const handleDragLeave = (e) => {
3885
+ e.preventDefault();
3886
+ e.stopPropagation();
3887
+ if (dropZoneRef.current && !dropZoneRef.current.contains(e.relatedTarget)) {
3888
+ setIsDragging(false);
3889
+ }
3890
+ };
3891
+ const handleDrop = (e) => {
3892
+ e.preventDefault();
3893
+ e.stopPropagation();
3894
+ setIsDragging(false);
3895
+ const files = e.dataTransfer.files;
3896
+ if (files.length > 0) {
3897
+ uploadFiles(files);
3898
+ }
3899
+ };
3900
+ const handleFileSelect = (e) => {
3901
+ const files = e.target.files;
3902
+ if (files && files.length > 0) {
3903
+ uploadFiles(files);
3904
+ }
3905
+ e.target.value = "";
3906
+ };
3907
+ const handleConfirm = () => {
3908
+ if (selectedImage) {
3909
+ onSelect(selectedImage);
3910
+ }
3911
+ };
3912
+ React2.useEffect(() => {
3913
+ const handleKeyDown = (e) => {
3914
+ if (e.key === "Escape") {
3915
+ onClose();
3916
+ }
3917
+ };
3918
+ window.addEventListener("keydown", handleKeyDown);
3919
+ return () => window.removeEventListener("keydown", handleKeyDown);
3920
+ }, [onClose]);
3921
+ return /* @__PURE__ */ jsxDEV2("div", {
3922
+ className: "fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60",
3923
+ onClick: (e) => e.target === e.currentTarget && onClose(),
3924
+ children: /* @__PURE__ */ jsxDEV2("div", {
3925
+ className: "w-full max-w-3xl max-h-[85vh] flex flex-col bg-white border border-neutral-200",
3926
+ children: [
3927
+ /* @__PURE__ */ jsxDEV2("div", {
3928
+ className: "flex items-center justify-between px-6 py-4 border-b border-neutral-200",
3929
+ children: [
3930
+ /* @__PURE__ */ jsxDEV2("h2", {
3931
+ className: "text-sm font-medium tracking-wide text-neutral-900",
3932
+ children: "Select Image"
3933
+ }, undefined, false, undefined, this),
3934
+ /* @__PURE__ */ jsxDEV2("button", {
3935
+ type: "button",
3936
+ onClick: onClose,
3937
+ className: "text-neutral-400 hover:text-neutral-900 transition-colors cursor-pointer",
3938
+ children: /* @__PURE__ */ jsxDEV2("svg", {
3939
+ className: "w-5 h-5",
3940
+ viewBox: "0 0 24 24",
3941
+ fill: "none",
3942
+ stroke: "currentColor",
3943
+ strokeWidth: "1.5",
3944
+ children: [
3945
+ /* @__PURE__ */ jsxDEV2("line", {
3946
+ x1: "18",
3947
+ y1: "6",
3948
+ x2: "6",
3949
+ y2: "18"
3950
+ }, undefined, false, undefined, this),
3951
+ /* @__PURE__ */ jsxDEV2("line", {
3952
+ x1: "6",
3953
+ y1: "6",
3954
+ x2: "18",
3955
+ y2: "18"
3956
+ }, undefined, false, undefined, this)
3957
+ ]
3958
+ }, undefined, true, undefined, this)
3959
+ }, undefined, false, undefined, this)
3960
+ ]
3961
+ }, undefined, true, undefined, this),
3962
+ /* @__PURE__ */ jsxDEV2("div", {
3963
+ ref: dropZoneRef,
3964
+ className: `mx-6 mt-6 border transition-colors ${isDragging ? "border-neutral-900 bg-neutral-50" : "border-neutral-200 border-dashed"}`,
3965
+ onDragOver: handleDragOver,
3966
+ onDragLeave: handleDragLeave,
3967
+ onDrop: handleDrop,
3968
+ children: [
3969
+ /* @__PURE__ */ jsxDEV2("div", {
3970
+ className: "flex flex-col items-center justify-center py-8 px-4",
3971
+ children: isUploading ? /* @__PURE__ */ jsxDEV2(Fragment, {
3972
+ children: [
3973
+ /* @__PURE__ */ jsxDEV2("svg", {
3974
+ className: "w-6 h-6 mb-2 animate-spin text-neutral-400",
3975
+ viewBox: "0 0 24 24",
3976
+ fill: "none",
3977
+ stroke: "currentColor",
3978
+ strokeWidth: "1.5",
3979
+ children: /* @__PURE__ */ jsxDEV2("path", {
3980
+ d: "M21 12a9 9 0 1 1-6.219-8.56"
3981
+ }, undefined, false, undefined, this)
3982
+ }, undefined, false, undefined, this),
3983
+ /* @__PURE__ */ jsxDEV2("div", {
3984
+ className: "text-xs text-neutral-500 space-y-1",
3985
+ children: uploadProgress.map((p, i) => /* @__PURE__ */ jsxDEV2("div", {
3986
+ children: p
3987
+ }, i, false, undefined, this))
3988
+ }, undefined, false, undefined, this)
3989
+ ]
3990
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsxDEV2(Fragment, {
3991
+ children: [
3992
+ /* @__PURE__ */ jsxDEV2("svg", {
3993
+ className: "w-6 h-6 mb-2 text-neutral-300",
3994
+ viewBox: "0 0 24 24",
3995
+ fill: "none",
3996
+ stroke: "currentColor",
3997
+ strokeWidth: "1",
3998
+ children: [
3999
+ /* @__PURE__ */ jsxDEV2("path", {
4000
+ d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"
4001
+ }, undefined, false, undefined, this),
4002
+ /* @__PURE__ */ jsxDEV2("polyline", {
4003
+ points: "17 8 12 3 7 8"
4004
+ }, undefined, false, undefined, this),
4005
+ /* @__PURE__ */ jsxDEV2("line", {
4006
+ x1: "12",
4007
+ y1: "3",
4008
+ x2: "12",
4009
+ y2: "15"
4010
+ }, undefined, false, undefined, this)
4011
+ ]
4012
+ }, undefined, true, undefined, this),
4013
+ /* @__PURE__ */ jsxDEV2("span", {
4014
+ className: "text-sm text-neutral-500",
4015
+ children: isDragging ? "Drop images here" : "Drag & drop images"
4016
+ }, undefined, false, undefined, this),
4017
+ /* @__PURE__ */ jsxDEV2("span", {
4018
+ className: "text-xs text-neutral-400 mt-1",
4019
+ children: [
4020
+ "or",
4021
+ " ",
4022
+ /* @__PURE__ */ jsxDEV2("button", {
4023
+ type: "button",
4024
+ onClick: () => fileInputRef.current?.click(),
4025
+ className: "text-neutral-900 border-b border-neutral-900 cursor-pointer",
4026
+ children: "browse"
4027
+ }, undefined, false, undefined, this)
4028
+ ]
4029
+ }, undefined, true, undefined, this)
4030
+ ]
4031
+ }, undefined, true, undefined, this)
4032
+ }, undefined, false, undefined, this),
4033
+ /* @__PURE__ */ jsxDEV2("input", {
4034
+ ref: fileInputRef,
4035
+ type: "file",
4036
+ accept,
4037
+ multiple: true,
4038
+ onChange: handleFileSelect,
4039
+ className: "sr-only"
4040
+ }, undefined, false, undefined, this)
4041
+ ]
4042
+ }, undefined, true, undefined, this),
4043
+ error && /* @__PURE__ */ jsxDEV2("div", {
4044
+ className: "mx-6 mt-2 text-xs text-red-600",
4045
+ children: error
4046
+ }, undefined, false, undefined, this),
4047
+ /* @__PURE__ */ jsxDEV2("div", {
4048
+ className: "flex-1 overflow-y-auto px-6 py-6 min-h-0",
4049
+ children: [
4050
+ /* @__PURE__ */ jsxDEV2("h3", {
4051
+ className: "text-xs font-medium uppercase tracking-widest text-neutral-400 mb-4",
4052
+ children: isLoading ? "Loading..." : `Library (${images.length})`
4053
+ }, undefined, false, undefined, this),
4054
+ isLoading ? /* @__PURE__ */ jsxDEV2("div", {
4055
+ className: "flex items-center justify-center py-12",
4056
+ children: /* @__PURE__ */ jsxDEV2("svg", {
4057
+ className: "w-6 h-6 animate-spin text-neutral-400",
4058
+ viewBox: "0 0 24 24",
4059
+ fill: "none",
4060
+ stroke: "currentColor",
4061
+ strokeWidth: "1.5",
4062
+ children: /* @__PURE__ */ jsxDEV2("path", {
4063
+ d: "M21 12a9 9 0 1 1-6.219-8.56"
4064
+ }, undefined, false, undefined, this)
4065
+ }, undefined, false, undefined, this)
4066
+ }, undefined, false, undefined, this) : images.length === 0 ? /* @__PURE__ */ jsxDEV2("div", {
4067
+ className: "flex flex-col items-center justify-center py-12 text-neutral-400",
4068
+ children: /* @__PURE__ */ jsxDEV2("span", {
4069
+ className: "text-sm",
4070
+ children: "No images yet"
4071
+ }, undefined, false, undefined, this)
4072
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV2("div", {
4073
+ className: "grid grid-cols-4 sm:grid-cols-5 md:grid-cols-6 gap-2",
4074
+ children: images.map((image) => /* @__PURE__ */ jsxDEV2("button", {
4075
+ type: "button",
4076
+ onClick: () => setSelectedImage(image.url),
4077
+ className: `relative aspect-square overflow-hidden transition-all cursor-pointer ${selectedImage === image.url ? "ring-2 ring-neutral-900 ring-offset-2" : "hover:opacity-80"}`,
4078
+ children: [
4079
+ /* @__PURE__ */ jsxDEV2("img", {
4080
+ src: image.url,
4081
+ alt: image.key,
4082
+ className: "w-full h-full object-cover",
4083
+ loading: "lazy"
4084
+ }, undefined, false, undefined, this),
4085
+ selectedImage === image.url && /* @__PURE__ */ jsxDEV2("div", {
4086
+ className: "absolute inset-0 flex items-center justify-center bg-black/30",
4087
+ children: /* @__PURE__ */ jsxDEV2("svg", {
4088
+ className: "w-6 h-6 text-white",
4089
+ viewBox: "0 0 24 24",
4090
+ fill: "none",
4091
+ stroke: "currentColor",
4092
+ strokeWidth: "2",
4093
+ children: /* @__PURE__ */ jsxDEV2("polyline", {
4094
+ points: "20 6 9 17 4 12"
4095
+ }, undefined, false, undefined, this)
4096
+ }, undefined, false, undefined, this)
4097
+ }, undefined, false, undefined, this)
4098
+ ]
4099
+ }, image.key, true, undefined, this))
4100
+ }, undefined, false, undefined, this)
4101
+ ]
4102
+ }, undefined, true, undefined, this),
4103
+ /* @__PURE__ */ jsxDEV2("div", {
4104
+ className: "flex items-center justify-between px-6 py-4 border-t border-neutral-200",
4105
+ children: [
4106
+ /* @__PURE__ */ jsxDEV2("span", {
4107
+ className: "text-xs text-neutral-400",
4108
+ children: selectedImage ? "Image selected" : "No selection"
4109
+ }, undefined, false, undefined, this),
4110
+ /* @__PURE__ */ jsxDEV2("div", {
4111
+ className: "flex items-center gap-6",
4112
+ children: [
4113
+ /* @__PURE__ */ jsxDEV2("button", {
4114
+ type: "button",
4115
+ onClick: onClose,
4116
+ className: "text-sm text-neutral-400 hover:text-neutral-900 transition-colors cursor-pointer",
4117
+ children: "Cancel"
4118
+ }, undefined, false, undefined, this),
4119
+ /* @__PURE__ */ jsxDEV2("button", {
4120
+ type: "button",
4121
+ onClick: handleConfirm,
4122
+ disabled: !selectedImage,
4123
+ className: "text-sm text-neutral-900 border-b border-neutral-900 pb-0.5 hover:pb-1 transition-all disabled:opacity-30 disabled:cursor-not-allowed cursor-pointer",
4124
+ children: "Select →"
4125
+ }, undefined, false, undefined, this)
4126
+ ]
4127
+ }, undefined, true, undefined, this)
4128
+ ]
4129
+ }, undefined, true, undefined, this)
4130
+ ]
4131
+ }, undefined, true, undefined, this)
4132
+ }, undefined, false, undefined, this);
4133
+ }
4134
+
4135
+ export { get, set, FormProvider, appendErrors, useForm, groupPages, flattenValue, groupFields, CmsField, CmsHiddenField, CmsCheckbox, CmsImageField };