@ttoss/forms 0.24.9 → 0.25.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.
@@ -1,3260 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- "use strict";
3
-
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
11
- enumerable: true,
12
- configurable: true,
13
- writable: true,
14
- value
15
- }) : obj[key] = value;
16
- var __export = (target, all) => {
17
- for (var name in all) __defProp(target, name, {
18
- get: all[name],
19
- enumerable: true
20
- });
21
- };
22
- var __copyProps = (to, from, except, desc) => {
23
- if (from && typeof from === "object" || typeof from === "function") {
24
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
- get: () => from[key],
26
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
- });
28
- }
29
- return to;
30
- };
31
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
32
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33
- // If the importer is in node compatibility mode or this is not an ESM
34
- // file that has been converted to a CommonJS file using a Babel-
35
- // compatible transform (i.e. "__esModule" has not been set), then set
36
- // "default" to the CommonJS "module.exports" for node compatibility.
37
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
38
- value: mod,
39
- enumerable: true
40
- }) : target, mod));
41
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
42
- value: true
43
- }), mod);
44
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
45
-
46
- // src/MultistepForm/index.ts
47
- var MultistepForm_exports = {};
48
- __export(MultistepForm_exports, {
49
- MultistepForm: () => MultistepForm
50
- });
51
- module.exports = __toCommonJS(MultistepForm_exports);
52
-
53
- // src/MultistepForm/MultistepForm.tsx
54
- var React5 = __toESM(require("react"));
55
- var import_ui20 = require("@ttoss/ui");
56
-
57
- // src/MultistepForm/MultistepFooter.tsx
58
- var import_ui = require("@ttoss/ui");
59
- var import_jsx_runtime = require("react/jsx-runtime");
60
- var MultistepFooter = ({
61
- footer
62
- }) => {
63
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.Flex, {
64
- sx: {
65
- display: "flex",
66
- justifyContent: "center"
67
- },
68
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.Text, {
69
- sx: {
70
- textAlign: "center",
71
- marginTop: "4xl",
72
- marginBottom: "lg",
73
- marginX: "2xl"
74
- },
75
- children: footer
76
- })
77
- });
78
- };
79
-
80
- // src/MultistepForm/MultistepFormStepper.tsx
81
- var import_ui17 = require("@ttoss/ui");
82
-
83
- // src/index.ts
84
- var src_exports = {};
85
- __export(src_exports, {
86
- Controller: () => import_react_hook_form6.Controller,
87
- Form: () => Form,
88
- FormErrorMessage: () => FormErrorMessage,
89
- FormField: () => FormField,
90
- FormFieldCheckbox: () => FormFieldCheckbox,
91
- FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
92
- FormFieldCurrencyInput: () => FormFieldCurrencyInput,
93
- FormFieldInput: () => FormFieldInput,
94
- FormFieldNumericFormat: () => FormFieldNumericFormat,
95
- FormFieldPassword: () => FormFieldPassword,
96
- FormFieldPatternFormat: () => FormFieldPatternFormat,
97
- FormFieldRadio: () => FormFieldRadio,
98
- FormFieldSelect: () => FormFieldSelect,
99
- FormFieldTextarea: () => FormFieldTextarea,
100
- FormGroup: () => FormGroup,
101
- FormProvider: () => import_react_hook_form6.FormProvider,
102
- useController: () => import_react_hook_form6.useController,
103
- useFieldArray: () => import_react_hook_form6.useFieldArray,
104
- useForm: () => import_react_hook_form6.useForm,
105
- useFormContext: () => import_react_hook_form6.useFormContext,
106
- useFormGroup: () => useFormGroup,
107
- useFormState: () => import_react_hook_form6.useFormState,
108
- useWatch: () => import_react_hook_form6.useWatch,
109
- yup: () => yup2,
110
- yupResolver: () => import_yup2.yupResolver
111
- });
112
- var import_yup2 = require("@hookform/resolvers/yup");
113
-
114
- // src/yup/i18n.ts
115
- var import_react_i18n = require("@ttoss/react-i18n");
116
- var import_yup = require("yup");
117
- (0, import_yup.setLocale)({
118
- mixed: {
119
- required: (0, import_react_i18n.defineMessage)({
120
- defaultMessage: "Field is required",
121
- description: "Field is required"
122
- }),
123
- notType: ({
124
- type
125
- }) => {
126
- return {
127
- ...(0, import_react_i18n.defineMessage)({
128
- defaultMessage: "Invalid Value for Field of type {type}",
129
- description: "Invalid Value"
130
- }),
131
- values: {
132
- type
133
- }
134
- };
135
- }
136
- },
137
- string: {
138
- min: ({
139
- min
140
- }) => {
141
- return {
142
- ...(0, import_react_i18n.defineMessage)({
143
- defaultMessage: "Field must be at least {min} characters",
144
- description: "Min length field"
145
- }),
146
- values: {
147
- min
148
- }
149
- };
150
- }
151
- }
152
- });
153
-
154
- // src/yup/schema.ts
155
- var yup = __toESM(require("yup"));
156
-
157
- // src/Brazil/FormFieldCNPJ.tsx
158
- var import_ui2 = require("@ttoss/ui");
159
- var import_react_number_format = require("react-number-format");
160
- var import_jsx_runtime2 = require("react/jsx-runtime");
161
- var isCnpjValid = cnpj => {
162
- if (cnpj?.length != 14) {
163
- return false;
164
- }
165
- if (cnpj == "00000000000000" || cnpj == "11111111111111" || cnpj == "22222222222222" || cnpj == "33333333333333" || cnpj == "44444444444444" || cnpj == "55555555555555" || cnpj == "66666666666666" || cnpj == "77777777777777" || cnpj == "88888888888888" || cnpj == "99999999999999") {
166
- return false;
167
- }
168
- let size = cnpj.length - 2;
169
- let numbers = cnpj.substring(0, size);
170
- const digits = cnpj.substring(size);
171
- let soma = 0;
172
- let pos = size - 7;
173
- for (let i = size; i >= 1; i--) {
174
- soma += numbers.charAt(size - i) * pos--;
175
- if (pos < 2) {
176
- pos = 9;
177
- }
178
- }
179
- let result = soma % 11 < 2 ? 0 : 11 - soma % 11;
180
- if (result != digits.charAt(0)) {
181
- return false;
182
- }
183
- size = size + 1;
184
- numbers = cnpj.substring(0, size);
185
- soma = 0;
186
- pos = size - 7;
187
- for (let i = size; i >= 1; i--) {
188
- soma += numbers.charAt(size - i) * pos--;
189
- if (pos < 2) {
190
- pos = 9;
191
- }
192
- }
193
- result = soma % 11 < 2 ? 0 : 11 - soma % 11;
194
- if (result != digits.charAt(1)) {
195
- return false;
196
- }
197
- return true;
198
- };
199
-
200
- // src/yup/schema.ts
201
- yup.addMethod(yup.string, "cnpj", function () {
202
- return this.test("valid-cnpj", "Invalid CNPJ", value => {
203
- return isCnpjValid(value);
204
- });
205
- });
206
-
207
- // src/yup/yup.ts
208
- var yup2 = __toESM(require("yup"));
209
-
210
- // src/Form.tsx
211
- var import_ui3 = require("@ttoss/ui");
212
- var import_react_hook_form = require("react-hook-form");
213
- var import_jsx_runtime3 = require("react/jsx-runtime");
214
- var Form = ({
215
- children,
216
- onSubmit,
217
- sx,
218
- ...formMethods
219
- }) => {
220
- return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_react_hook_form.FormProvider, {
221
- ...formMethods,
222
- children: /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.Box, {
223
- as: "form",
224
- variant: "forms.form",
225
- onSubmit: formMethods.handleSubmit(data => {
226
- return onSubmit?.(data);
227
- }),
228
- sx,
229
- children
230
- })
231
- });
232
- };
233
-
234
- // src/FormErrorMessage.tsx
235
- var import_error_message = require("@hookform/error-message");
236
- var import_react_hook_form2 = require("react-hook-form");
237
- var import_react_i18n2 = require("@ttoss/react-i18n");
238
- var import_ui4 = require("@ttoss/ui");
239
- var import_jsx_runtime4 = require("react/jsx-runtime");
240
- var isMessageDescriptor = possibleMessageDescriptor => {
241
- return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
242
- };
243
- var FormErrorMessage = ({
244
- name,
245
- disabled
246
- }) => {
247
- const {
248
- formState: {
249
- errors
250
- }
251
- } = (0, import_react_hook_form2.useFormContext)();
252
- return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_error_message.ErrorMessage, {
253
- name,
254
- errors,
255
- render: ({
256
- message
257
- }) => {
258
- return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_ui4.HelpText, {
259
- negative: true,
260
- disabled,
261
- children: (() => {
262
- if (typeof message === "string") {
263
- return message;
264
- }
265
- if (isMessageDescriptor(message)) {
266
- return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_react_i18n2.FormattedMessage, {
267
- ...message
268
- });
269
- }
270
- return JSON.stringify(message);
271
- })()
272
- });
273
- }
274
- });
275
- };
276
-
277
- // src/FormField.tsx
278
- var React = __toESM(require("react"));
279
- var import_react_hook_form3 = require("react-hook-form");
280
- var import_ui5 = require("@ttoss/ui");
281
- var import_jsx_runtime5 = require("react/jsx-runtime");
282
- var FormField = ({
283
- label,
284
- id: idProp,
285
- name,
286
- defaultValue,
287
- disabled,
288
- tooltip,
289
- onTooltipClick,
290
- sx,
291
- css,
292
- render
293
- }) => {
294
- const controllerReturn = (0, import_react_hook_form3.useController)({
295
- name,
296
- defaultValue
297
- });
298
- const id = idProp || `form-field-${name}`;
299
- const memoizedRender = React.useMemo(() => {
300
- return React.Children.map(render(controllerReturn), child => {
301
- return /* @__PURE__ */(0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, {
302
- children: [label && /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_ui5.Label, {
303
- "aria-disabled": disabled,
304
- htmlFor: id,
305
- tooltip,
306
- onTooltipClick,
307
- children: label
308
- }), React.createElement(child.type, {
309
- id,
310
- ...child.props
311
- })]
312
- });
313
- });
314
- }, [controllerReturn, disabled, onTooltipClick, tooltip, id, label, render]);
315
- return /* @__PURE__ */(0, import_jsx_runtime5.jsxs)(import_ui5.Flex, {
316
- sx: {
317
- flexDirection: "column",
318
- width: "100%",
319
- gap: "md",
320
- ...sx
321
- },
322
- css,
323
- children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormErrorMessage, {
324
- name
325
- })]
326
- });
327
- };
328
-
329
- // src/FormFieldCheckbox.tsx
330
- var import_ui6 = require("@ttoss/ui");
331
- var import_react_hook_form4 = require("react-hook-form");
332
- var import_jsx_runtime6 = require("react/jsx-runtime");
333
- var FormFieldCheckbox = ({
334
- label,
335
- name,
336
- sx,
337
- ...checkboxProps
338
- }) => {
339
- const {
340
- field: {
341
- onChange,
342
- onBlur,
343
- value,
344
- ref
345
- },
346
- formState: {
347
- errors
348
- }
349
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
350
- } = (0, import_react_hook_form4.useController)({
351
- name,
352
- defaultValue: false
353
- });
354
- const id = `form-field-checkbox-${name}`;
355
- const error = !!errors[name]?.message;
356
- return /* @__PURE__ */(0, import_jsx_runtime6.jsxs)(import_ui6.Flex, {
357
- sx: {
358
- flexDirection: "column",
359
- width: "100%",
360
- ...sx
361
- },
362
- children: [/* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_ui6.Flex, {
363
- sx: {
364
- alignItems: "center"
365
- },
366
- children: /* @__PURE__ */(0, import_jsx_runtime6.jsxs)(import_ui6.Label, {
367
- "aria-disabled": checkboxProps.disabled,
368
- htmlFor: id,
369
- children: [/* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_ui6.Checkbox, {
370
- id,
371
- ref,
372
- checked: value,
373
- onChange,
374
- onBlur,
375
- name,
376
- "aria-invalid": error ? "true" : "false",
377
- ...checkboxProps
378
- }), label]
379
- })
380
- }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(FormErrorMessage, {
381
- name
382
- })]
383
- });
384
- };
385
-
386
- // src/FormFieldPatternFormat.tsx
387
- var import_ui7 = require("@ttoss/ui");
388
- var import_react_number_format2 = require("react-number-format");
389
- var import_jsx_runtime7 = require("react/jsx-runtime");
390
- var FormFieldPatternFormat = ({
391
- label,
392
- name,
393
- ...patternFormatProps
394
- }) => {
395
- return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(FormField, {
396
- name,
397
- label,
398
- render: ({
399
- field,
400
- fieldState
401
- }) => {
402
- return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_react_number_format2.PatternFormat, {
403
- name: field.name,
404
- value: field.value,
405
- onBlur: field.onBlur,
406
- onValueChange: values => {
407
- field.onChange(values.value);
408
- },
409
- customInput: import_ui7.Input,
410
- "aria-invalid": Boolean(fieldState.error).valueOf(),
411
- ...patternFormatProps
412
- });
413
- }
414
- });
415
- };
416
-
417
- // src/FormFieldCreditCardNumber.tsx
418
- var import_jsx_runtime8 = require("react/jsx-runtime");
419
- var FormFieldCreditCardNumber = ({
420
- label,
421
- name,
422
- ...formFieldPatternFormatProps
423
- }) => {
424
- return /* @__PURE__ */(0, import_jsx_runtime8.jsx)(FormFieldPatternFormat, {
425
- name,
426
- label,
427
- format: "#### #### #### ####",
428
- placeholder: "1234 1234 1234 1234",
429
- ...formFieldPatternFormatProps
430
- });
431
- };
432
-
433
- // src/FormFieldNumericFormat.tsx
434
- var import_ui8 = require("@ttoss/ui");
435
- var import_react_number_format3 = require("react-number-format");
436
- var import_jsx_runtime9 = require("react/jsx-runtime");
437
- var FormFieldNumericFormat = ({
438
- label,
439
- name,
440
- ...numericFormatProps
441
- }) => {
442
- return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormField, {
443
- label,
444
- name,
445
- render: ({
446
- field
447
- }) => {
448
- return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_react_number_format3.NumericFormat, {
449
- name: field.name,
450
- value: field.value,
451
- onBlur: field.onBlur,
452
- onValueChange: values => {
453
- field.onChange(values.floatValue);
454
- },
455
- customInput: import_ui8.Input,
456
- ...numericFormatProps
457
- });
458
- }
459
- });
460
- };
461
-
462
- // src/FormFieldCurrencyInput.tsx
463
- var import_jsx_runtime10 = require("react/jsx-runtime");
464
- var FormFieldCurrencyInput = ({
465
- label,
466
- name,
467
- prefix,
468
- decimalSeparator,
469
- thousandSeparator,
470
- ...formFieldNumericFormatProps
471
- }) => {
472
- return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormFieldNumericFormat, {
473
- name,
474
- label,
475
- fixedDecimalScale: true,
476
- decimalScale: 2,
477
- prefix,
478
- decimalSeparator,
479
- thousandSeparator,
480
- placeholder: `${prefix} 0${decimalSeparator}00`,
481
- allowNegative: false,
482
- ...formFieldNumericFormatProps
483
- });
484
- };
485
-
486
- // src/FormFieldInput.tsx
487
- var import_ui9 = require("@ttoss/ui");
488
- var import_jsx_runtime11 = require("react/jsx-runtime");
489
- var FormFieldInput = ({
490
- label,
491
- name,
492
- tooltip,
493
- onTooltipClick,
494
- sx,
495
- defaultValue = "",
496
- ...inputProps
497
- }) => {
498
- return /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormField, {
499
- name,
500
- label,
501
- disabled: inputProps.disabled,
502
- tooltip,
503
- onTooltipClick,
504
- sx,
505
- defaultValue,
506
- render: ({
507
- field,
508
- fieldState
509
- }) => {
510
- return /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui9.Input, {
511
- ...inputProps,
512
- ...field,
513
- "aria-invalid": fieldState.error ? "true" : void 0
514
- });
515
- }
516
- });
517
- };
518
-
519
- // src/FormFieldPassword.tsx
520
- var import_ui10 = require("@ttoss/ui");
521
- var import_jsx_runtime12 = require("react/jsx-runtime");
522
- var FormFieldPassword = ({
523
- label,
524
- name,
525
- tooltip,
526
- onTooltipClick,
527
- sx,
528
- defaultValue = "",
529
- ...inputProps
530
- }) => {
531
- return /* @__PURE__ */(0, import_jsx_runtime12.jsx)(FormField, {
532
- name,
533
- label,
534
- disabled: inputProps.disabled,
535
- tooltip,
536
- onTooltipClick,
537
- sx,
538
- defaultValue,
539
- render: ({
540
- field,
541
- fieldState
542
- }) => {
543
- return /* @__PURE__ */(0, import_jsx_runtime12.jsx)(import_ui10.InputPassword, {
544
- ...inputProps,
545
- ...field,
546
- "aria-invalid": fieldState.error ? "true" : void 0
547
- });
548
- }
549
- });
550
- };
551
-
552
- // src/FormFieldRadio.tsx
553
- var import_ui11 = require("@ttoss/ui");
554
- var import_react_hook_form5 = require("react-hook-form");
555
- var import_jsx_runtime13 = require("react/jsx-runtime");
556
- var FormFieldRadio = ({
557
- label,
558
- name,
559
- options,
560
- sx,
561
- ...radioProps
562
- }) => {
563
- const {
564
- field: {
565
- onChange,
566
- onBlur,
567
- value,
568
- ref
569
- }
570
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
571
- } = (0, import_react_hook_form5.useController)({
572
- name,
573
- defaultValue: ""
574
- });
575
- return /* @__PURE__ */(0, import_jsx_runtime13.jsxs)(import_ui11.Flex, {
576
- sx: {
577
- flexDirection: "column",
578
- width: "100%",
579
- ...sx
580
- },
581
- children: [label && /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_ui11.Label, {
582
- sx: {
583
- marginBottom: "md"
584
- },
585
- children: label
586
- }), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_ui11.Box, {
587
- children: options.map(option => {
588
- const id = `form-field-radio-${name}-${option.value}`;
589
- return /* @__PURE__ */(0, import_jsx_runtime13.jsxs)(import_ui11.Label, {
590
- htmlFor: id,
591
- children: [/* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_ui11.Radio, {
592
- ref,
593
- onChange,
594
- onBlur,
595
- value: option.value,
596
- checked: value === option.value,
597
- name,
598
- id,
599
- ...radioProps
600
- }), option.label]
601
- }, id);
602
- })
603
- }), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(FormErrorMessage, {
604
- name
605
- })]
606
- });
607
- };
608
-
609
- // src/FormFieldSelect.tsx
610
- var import_ui12 = require("@ttoss/ui");
611
- var import_jsx_runtime14 = require("react/jsx-runtime");
612
- var FormFieldSelect = ({
613
- label,
614
- name,
615
- id,
616
- defaultValue,
617
- sx,
618
- css,
619
- disabled,
620
- tooltip,
621
- onTooltipClick,
622
- ...selectProps
623
- }) => {
624
- return /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormField, {
625
- name,
626
- label,
627
- id,
628
- defaultValue,
629
- disabled,
630
- tooltip,
631
- onTooltipClick,
632
- sx,
633
- css,
634
- render: ({
635
- field,
636
- fieldState
637
- }) => {
638
- return /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Select, {
639
- ...selectProps,
640
- ...field,
641
- isDisabled: disabled,
642
- "aria-invalid": fieldState.error ? "true" : void 0
643
- });
644
- }
645
- });
646
- };
647
-
648
- // src/FormFieldTextarea.tsx
649
- var import_ui13 = require("@ttoss/ui");
650
- var import_jsx_runtime15 = require("react/jsx-runtime");
651
- var FormFieldTextarea = ({
652
- label,
653
- name,
654
- sx,
655
- ...textareaProps
656
- }) => {
657
- const id = `form-field-textarea-${name}`;
658
- return /* @__PURE__ */(0, import_jsx_runtime15.jsx)(FormField, {
659
- label,
660
- name,
661
- id,
662
- sx,
663
- render: ({
664
- field,
665
- fieldState
666
- }) => {
667
- return /* @__PURE__ */(0, import_jsx_runtime15.jsx)(import_ui13.Textarea, {
668
- ...field,
669
- ...textareaProps,
670
- "aria-invalid": fieldState.error ? "true" : void 0
671
- });
672
- }
673
- });
674
- };
675
-
676
- // src/FormGroup.tsx
677
- var React2 = __toESM(require("react"));
678
- var import_ui14 = require("@ttoss/ui");
679
- var import_jsx_runtime16 = require("react/jsx-runtime");
680
- var FormGroupLevelsManagerContext = React2.createContext({
681
- levelsLength: 1,
682
- registerChild: () => {
683
- return null;
684
- }
685
- });
686
- var FormGroupLevelsManager = ({
687
- children
688
- }) => {
689
- const [levelsLength, setLevelsLength] = React2.useState(0);
690
- const registerChild = React2.useCallback(level => {
691
- if (level + 1 > levelsLength) {
692
- setLevelsLength(level + 1);
693
- }
694
- }, [levelsLength]);
695
- return /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormGroupLevelsManagerContext.Provider, {
696
- value: {
697
- levelsLength,
698
- registerChild
699
- },
700
- children
701
- });
702
- };
703
- var FormGroupContext = React2.createContext({});
704
- var useFormGroup = () => {
705
- const {
706
- parentLevel
707
- } = React2.useContext(FormGroupContext);
708
- const {
709
- levelsLength
710
- } = React2.useContext(FormGroupLevelsManagerContext);
711
- return {
712
- level: parentLevel,
713
- levelsLength
714
- };
715
- };
716
- var FormGroupWrapper = ({
717
- title,
718
- direction,
719
- children,
720
- name,
721
- ...boxProps
722
- }) => {
723
- const {
724
- level
725
- } = useFormGroup();
726
- const {
727
- registerChild
728
- } = React2.useContext(FormGroupLevelsManagerContext);
729
- React2.useEffect(() => {
730
- if (typeof level === "number") {
731
- registerChild(level);
732
- }
733
- }, [level, registerChild]);
734
- const childrenContainerSx = {
735
- flexDirection: direction || "column",
736
- gap: "md",
737
- width: "100%"
738
- };
739
- return /* @__PURE__ */(0, import_jsx_runtime16.jsxs)(import_ui14.Box, {
740
- "aria-level": level,
741
- ...boxProps,
742
- sx: {
743
- marginTop: level === 0 ? "none" : "lg",
744
- marginBottom: "lg",
745
- ...boxProps.sx
746
- },
747
- children: [title && /* @__PURE__ */(0, import_jsx_runtime16.jsx)(import_ui14.Box, {
748
- sx: {
749
- marginBottom: "md"
750
- },
751
- children: /* @__PURE__ */(0, import_jsx_runtime16.jsx)(import_ui14.Text, {
752
- sx: {
753
- fontSize: "2xl",
754
- fontWeight: "bold"
755
- },
756
- children: title
757
- })
758
- }), /* @__PURE__ */(0, import_jsx_runtime16.jsx)(import_ui14.Flex, {
759
- sx: childrenContainerSx,
760
- children
761
- }), name && /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormErrorMessage, {
762
- name
763
- })]
764
- });
765
- };
766
- var FormGroup = props => {
767
- const {
768
- level
769
- } = useFormGroup();
770
- const currentLevel = level === void 0 ? 0 : level + 1;
771
- return /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormGroupContext.Provider, {
772
- value: {
773
- parentLevel: currentLevel
774
- },
775
- children: currentLevel === 0 ? /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormGroupLevelsManager, {
776
- children: /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormGroupWrapper, {
777
- ...props
778
- })
779
- }) : /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormGroupWrapper, {
780
- ...props
781
- })
782
- });
783
- };
784
-
785
- // src/index.ts
786
- var import_react_hook_form6 = require("react-hook-form");
787
- __reExport(src_exports, require("react-hook-form"));
788
-
789
- // src/MultistepForm/MultistepFlowMessageImageText.tsx
790
- var import_ui15 = require("@ttoss/ui");
791
- var import_jsx_runtime17 = require("react/jsx-runtime");
792
- var MultistepFlowMessageImageText = ({
793
- src,
794
- description
795
- }) => {
796
- return /* @__PURE__ */(0, import_jsx_runtime17.jsxs)(import_ui15.Flex, {
797
- sx: {
798
- flexDirection: "column",
799
- paddingY: "xl",
800
- paddingX: "2xl",
801
- gap: "xl"
802
- },
803
- children: [/* @__PURE__ */(0, import_jsx_runtime17.jsx)(import_ui15.Image, {
804
- src,
805
- sx: {
806
- width: "184px",
807
- height: "184px",
808
- objectFit: "cover",
809
- alignSelf: "center"
810
- }
811
- }), /* @__PURE__ */(0, import_jsx_runtime17.jsx)(import_ui15.Text, {
812
- sx: {
813
- textAlign: "center"
814
- },
815
- children: description
816
- })]
817
- });
818
- };
819
-
820
- // src/MultistepForm/MultistepFlowMessage.tsx
821
- var import_jsx_runtime18 = require("react/jsx-runtime");
822
- var MultistepFlowMessage = props => {
823
- if (props.variant === "image-text") {
824
- return /* @__PURE__ */(0, import_jsx_runtime18.jsx)(MultistepFlowMessageImageText, {
825
- ...props
826
- });
827
- }
828
- return null;
829
- };
830
-
831
- // src/MultistepForm/MultistepQuestion.tsx
832
- var import_ui16 = require("@ttoss/ui");
833
- var import_jsx_runtime19 = require("react/jsx-runtime");
834
- var MultistepQuestion = ({
835
- fields,
836
- question
837
- }) => {
838
- return /* @__PURE__ */(0, import_jsx_runtime19.jsxs)(import_ui16.Flex, {
839
- sx: {
840
- flexDirection: "column",
841
- paddingTop: "xl",
842
- paddingX: "2xl"
843
- },
844
- children: [/* @__PURE__ */(0, import_jsx_runtime19.jsx)(import_ui16.Text, {
845
- sx: {
846
- textAlign: "center",
847
- fontSize: "lg",
848
- marginBottom: "xl"
849
- },
850
- children: question
851
- }), /* @__PURE__ */(0, import_jsx_runtime19.jsx)(import_ui16.Flex, {
852
- sx: {
853
- flexDirection: "column",
854
- gap: "xl"
855
- },
856
- children: fields
857
- })]
858
- });
859
- };
860
-
861
- // src/MultistepForm/MultistepFormStepper.tsx
862
- var import_jsx_runtime20 = require("react/jsx-runtime");
863
- var MultistepFormStepper = ({
864
- flowMessage,
865
- fields,
866
- onSubmit,
867
- question,
868
- submitLabel,
869
- schema,
870
- isLastStep,
871
- defaultValues,
872
- stepNumber
873
- // isCurrentStep,
874
- }) => {
875
- const formMethods = (0, import_react_hook_form6.useForm)({
876
- resolver: schema ? (0, import_yup2.yupResolver)(schema) : void 0,
877
- defaultValues
878
- });
879
- return /* @__PURE__ */(0, import_jsx_runtime20.jsxs)(Form, {
880
- ...formMethods,
881
- sx: {
882
- display: "flex",
883
- flexDirection: "column"
884
- },
885
- onSubmit,
886
- children: [/* @__PURE__ */(0, import_jsx_runtime20.jsx)(MultistepFlowMessage, {
887
- ...flowMessage
888
- }), /* @__PURE__ */(0, import_jsx_runtime20.jsx)(MultistepQuestion, {
889
- fields,
890
- question
891
- }), /* @__PURE__ */(0, import_jsx_runtime20.jsx)(import_ui17.Button, {
892
- sx: {
893
- justifyContent: "center",
894
- marginTop: "2xl",
895
- marginBottom: "xl",
896
- marginX: "2xl"
897
- },
898
- rightIcon: isLastStep ? void 0 : "nav-right",
899
- "aria-label": `btn-step-${stepNumber}`,
900
- type: "submit",
901
- children: submitLabel
902
- })]
903
- });
904
- };
905
-
906
- // src/MultistepForm/MultistepHeader.tsx
907
- var import_ui18 = require("@ttoss/ui");
908
-
909
- // ../react-icons/src/Icon.tsx
910
- var React4 = __toESM(require("react"));
911
-
912
- // ../../node_modules/.pnpm/@iconify-icon+react@2.1.0_react@18.3.1/node_modules/@iconify-icon/react/dist/iconify.mjs
913
- var import_react = __toESM(require("react"), 1);
914
-
915
- // ../../node_modules/.pnpm/iconify-icon@2.1.0/node_modules/iconify-icon/dist/iconify-icon.mjs
916
- var defaultIconDimensions = Object.freeze({
917
- left: 0,
918
- top: 0,
919
- width: 16,
920
- height: 16
921
- });
922
- var defaultIconTransformations = Object.freeze({
923
- rotate: 0,
924
- vFlip: false,
925
- hFlip: false
926
- });
927
- var defaultIconProps = Object.freeze({
928
- ...defaultIconDimensions,
929
- ...defaultIconTransformations
930
- });
931
- var defaultExtendedIconProps = Object.freeze({
932
- ...defaultIconProps,
933
- body: "",
934
- hidden: false
935
- });
936
- var defaultIconSizeCustomisations = Object.freeze({
937
- width: null,
938
- height: null
939
- });
940
- var defaultIconCustomisations = Object.freeze({
941
- // Dimensions
942
- ...defaultIconSizeCustomisations,
943
- // Transformations
944
- ...defaultIconTransformations
945
- });
946
- function rotateFromString(value, defaultValue = 0) {
947
- const units = value.replace(/^-?[0-9.]*/, "");
948
- function cleanup(value2) {
949
- while (value2 < 0) {
950
- value2 += 4;
951
- }
952
- return value2 % 4;
953
- }
954
- if (units === "") {
955
- const num = parseInt(value);
956
- return isNaN(num) ? 0 : cleanup(num);
957
- } else if (units !== value) {
958
- let split = 0;
959
- switch (units) {
960
- case "%":
961
- split = 25;
962
- break;
963
- case "deg":
964
- split = 90;
965
- }
966
- if (split) {
967
- let num = parseFloat(value.slice(0, value.length - units.length));
968
- if (isNaN(num)) {
969
- return 0;
970
- }
971
- num = num / split;
972
- return num % 1 === 0 ? cleanup(num) : 0;
973
- }
974
- }
975
- return defaultValue;
976
- }
977
- var separator = /[\s,]+/;
978
- function flipFromString(custom, flip) {
979
- flip.split(separator).forEach(str => {
980
- const value = str.trim();
981
- switch (value) {
982
- case "horizontal":
983
- custom.hFlip = true;
984
- break;
985
- case "vertical":
986
- custom.vFlip = true;
987
- break;
988
- }
989
- });
990
- }
991
- var defaultCustomisations = {
992
- ...defaultIconCustomisations,
993
- preserveAspectRatio: ""
994
- };
995
- function getCustomisations(node) {
996
- const customisations = {
997
- ...defaultCustomisations
998
- };
999
- const attr = (key, def) => node.getAttribute(key) || def;
1000
- customisations.width = attr("width", null);
1001
- customisations.height = attr("height", null);
1002
- customisations.rotate = rotateFromString(attr("rotate", ""));
1003
- flipFromString(customisations, attr("flip", ""));
1004
- customisations.preserveAspectRatio = attr("preserveAspectRatio", attr("preserveaspectratio", ""));
1005
- return customisations;
1006
- }
1007
- function haveCustomisationsChanged(value1, value2) {
1008
- for (const key in defaultCustomisations) {
1009
- if (value1[key] !== value2[key]) {
1010
- return true;
1011
- }
1012
- }
1013
- return false;
1014
- }
1015
- var matchIconName = /^[a-z0-9]+(-[a-z0-9]+)*$/;
1016
- var stringToIcon = (value, validate, allowSimpleName, provider = "") => {
1017
- const colonSeparated = value.split(":");
1018
- if (value.slice(0, 1) === "@") {
1019
- if (colonSeparated.length < 2 || colonSeparated.length > 3) {
1020
- return null;
1021
- }
1022
- provider = colonSeparated.shift().slice(1);
1023
- }
1024
- if (colonSeparated.length > 3 || !colonSeparated.length) {
1025
- return null;
1026
- }
1027
- if (colonSeparated.length > 1) {
1028
- const name2 = colonSeparated.pop();
1029
- const prefix = colonSeparated.pop();
1030
- const result = {
1031
- // Allow provider without '@': "provider:prefix:name"
1032
- provider: colonSeparated.length > 0 ? colonSeparated[0] : provider,
1033
- prefix,
1034
- name: name2
1035
- };
1036
- return validate && !validateIconName(result) ? null : result;
1037
- }
1038
- const name = colonSeparated[0];
1039
- const dashSeparated = name.split("-");
1040
- if (dashSeparated.length > 1) {
1041
- const result = {
1042
- provider,
1043
- prefix: dashSeparated.shift(),
1044
- name: dashSeparated.join("-")
1045
- };
1046
- return validate && !validateIconName(result) ? null : result;
1047
- }
1048
- if (allowSimpleName && provider === "") {
1049
- const result = {
1050
- provider,
1051
- prefix: "",
1052
- name
1053
- };
1054
- return validate && !validateIconName(result, allowSimpleName) ? null : result;
1055
- }
1056
- return null;
1057
- };
1058
- var validateIconName = (icon, allowSimpleName) => {
1059
- if (!icon) {
1060
- return false;
1061
- }
1062
- return !!((icon.provider === "" || icon.provider.match(matchIconName)) && (allowSimpleName && icon.prefix === "" || icon.prefix.match(matchIconName)) && icon.name.match(matchIconName));
1063
- };
1064
- function mergeIconTransformations(obj1, obj2) {
1065
- const result = {};
1066
- if (!obj1.hFlip !== !obj2.hFlip) {
1067
- result.hFlip = true;
1068
- }
1069
- if (!obj1.vFlip !== !obj2.vFlip) {
1070
- result.vFlip = true;
1071
- }
1072
- const rotate = ((obj1.rotate || 0) + (obj2.rotate || 0)) % 4;
1073
- if (rotate) {
1074
- result.rotate = rotate;
1075
- }
1076
- return result;
1077
- }
1078
- function mergeIconData(parent, child) {
1079
- const result = mergeIconTransformations(parent, child);
1080
- for (const key in defaultExtendedIconProps) {
1081
- if (key in defaultIconTransformations) {
1082
- if (key in parent && !(key in result)) {
1083
- result[key] = defaultIconTransformations[key];
1084
- }
1085
- } else if (key in child) {
1086
- result[key] = child[key];
1087
- } else if (key in parent) {
1088
- result[key] = parent[key];
1089
- }
1090
- }
1091
- return result;
1092
- }
1093
- function getIconsTree(data, names) {
1094
- const icons = data.icons;
1095
- const aliases = data.aliases || /* @__PURE__ */Object.create(null);
1096
- const resolved = /* @__PURE__ */Object.create(null);
1097
- function resolve(name) {
1098
- if (icons[name]) {
1099
- return resolved[name] = [];
1100
- }
1101
- if (!(name in resolved)) {
1102
- resolved[name] = null;
1103
- const parent = aliases[name] && aliases[name].parent;
1104
- const value = parent && resolve(parent);
1105
- if (value) {
1106
- resolved[name] = [parent].concat(value);
1107
- }
1108
- }
1109
- return resolved[name];
1110
- }
1111
- (names || Object.keys(icons).concat(Object.keys(aliases))).forEach(resolve);
1112
- return resolved;
1113
- }
1114
- function internalGetIconData(data, name, tree) {
1115
- const icons = data.icons;
1116
- const aliases = data.aliases || /* @__PURE__ */Object.create(null);
1117
- let currentProps = {};
1118
- function parse(name2) {
1119
- currentProps = mergeIconData(icons[name2] || aliases[name2], currentProps);
1120
- }
1121
- parse(name);
1122
- tree.forEach(parse);
1123
- return mergeIconData(data, currentProps);
1124
- }
1125
- function parseIconSet(data, callback) {
1126
- const names = [];
1127
- if (typeof data !== "object" || typeof data.icons !== "object") {
1128
- return names;
1129
- }
1130
- if (data.not_found instanceof Array) {
1131
- data.not_found.forEach(name => {
1132
- callback(name, null);
1133
- names.push(name);
1134
- });
1135
- }
1136
- const tree = getIconsTree(data);
1137
- for (const name in tree) {
1138
- const item = tree[name];
1139
- if (item) {
1140
- callback(name, internalGetIconData(data, name, item));
1141
- names.push(name);
1142
- }
1143
- }
1144
- return names;
1145
- }
1146
- var optionalPropertyDefaults = {
1147
- provider: "",
1148
- aliases: {},
1149
- not_found: {},
1150
- ...defaultIconDimensions
1151
- };
1152
- function checkOptionalProps(item, defaults) {
1153
- for (const prop in defaults) {
1154
- if (prop in item && typeof item[prop] !== typeof defaults[prop]) {
1155
- return false;
1156
- }
1157
- }
1158
- return true;
1159
- }
1160
- function quicklyValidateIconSet(obj) {
1161
- if (typeof obj !== "object" || obj === null) {
1162
- return null;
1163
- }
1164
- const data = obj;
1165
- if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") {
1166
- return null;
1167
- }
1168
- if (!checkOptionalProps(obj, optionalPropertyDefaults)) {
1169
- return null;
1170
- }
1171
- const icons = data.icons;
1172
- for (const name in icons) {
1173
- const icon = icons[name];
1174
- if (!name.match(matchIconName) || typeof icon.body !== "string" || !checkOptionalProps(icon, defaultExtendedIconProps)) {
1175
- return null;
1176
- }
1177
- }
1178
- const aliases = data.aliases || /* @__PURE__ */Object.create(null);
1179
- for (const name in aliases) {
1180
- const icon = aliases[name];
1181
- const parent = icon.parent;
1182
- if (!name.match(matchIconName) || typeof parent !== "string" || !icons[parent] && !aliases[parent] || !checkOptionalProps(icon, defaultExtendedIconProps)) {
1183
- return null;
1184
- }
1185
- }
1186
- return data;
1187
- }
1188
- var dataStorage = /* @__PURE__ */Object.create(null);
1189
- function newStorage(provider, prefix) {
1190
- return {
1191
- provider,
1192
- prefix,
1193
- icons: /* @__PURE__ */Object.create(null),
1194
- missing: /* @__PURE__ */new Set()
1195
- };
1196
- }
1197
- function getStorage(provider, prefix) {
1198
- const providerStorage = dataStorage[provider] || (dataStorage[provider] = /* @__PURE__ */Object.create(null));
1199
- return providerStorage[prefix] || (providerStorage[prefix] = newStorage(provider, prefix));
1200
- }
1201
- function addIconSet(storage2, data) {
1202
- if (!quicklyValidateIconSet(data)) {
1203
- return [];
1204
- }
1205
- return parseIconSet(data, (name, icon) => {
1206
- if (icon) {
1207
- storage2.icons[name] = icon;
1208
- } else {
1209
- storage2.missing.add(name);
1210
- }
1211
- });
1212
- }
1213
- function addIconToStorage(storage2, name, icon) {
1214
- try {
1215
- if (typeof icon.body === "string") {
1216
- storage2.icons[name] = {
1217
- ...icon
1218
- };
1219
- return true;
1220
- }
1221
- } catch (err) {}
1222
- return false;
1223
- }
1224
- function listIcons$1(provider, prefix) {
1225
- let allIcons = [];
1226
- const providers = typeof provider === "string" ? [provider] : Object.keys(dataStorage);
1227
- providers.forEach(provider2 => {
1228
- const prefixes = typeof provider2 === "string" && typeof prefix === "string" ? [prefix] : Object.keys(dataStorage[provider2] || {});
1229
- prefixes.forEach(prefix2 => {
1230
- const storage2 = getStorage(provider2, prefix2);
1231
- allIcons = allIcons.concat(Object.keys(storage2.icons).map(name => (provider2 !== "" ? "@" + provider2 + ":" : "") + prefix2 + ":" + name));
1232
- });
1233
- });
1234
- return allIcons;
1235
- }
1236
- var simpleNames = false;
1237
- function allowSimpleNames(allow) {
1238
- if (typeof allow === "boolean") {
1239
- simpleNames = allow;
1240
- }
1241
- return simpleNames;
1242
- }
1243
- function getIconData(name) {
1244
- const icon = typeof name === "string" ? stringToIcon(name, true, simpleNames) : name;
1245
- if (icon) {
1246
- const storage2 = getStorage(icon.provider, icon.prefix);
1247
- const iconName = icon.name;
1248
- return storage2.icons[iconName] || (storage2.missing.has(iconName) ? null : void 0);
1249
- }
1250
- }
1251
- function addIcon$1(name, data) {
1252
- const icon = stringToIcon(name, true, simpleNames);
1253
- if (!icon) {
1254
- return false;
1255
- }
1256
- const storage2 = getStorage(icon.provider, icon.prefix);
1257
- return addIconToStorage(storage2, icon.name, data);
1258
- }
1259
- function addCollection$1(data, provider) {
1260
- if (typeof data !== "object") {
1261
- return false;
1262
- }
1263
- if (typeof provider !== "string") {
1264
- provider = data.provider || "";
1265
- }
1266
- if (simpleNames && !provider && !data.prefix) {
1267
- let added = false;
1268
- if (quicklyValidateIconSet(data)) {
1269
- data.prefix = "";
1270
- parseIconSet(data, (name, icon) => {
1271
- if (icon && addIcon$1(name, icon)) {
1272
- added = true;
1273
- }
1274
- });
1275
- }
1276
- return added;
1277
- }
1278
- const prefix = data.prefix;
1279
- if (!validateIconName({
1280
- provider,
1281
- prefix,
1282
- name: "a"
1283
- })) {
1284
- return false;
1285
- }
1286
- const storage2 = getStorage(provider, prefix);
1287
- return !!addIconSet(storage2, data);
1288
- }
1289
- function iconLoaded$1(name) {
1290
- return !!getIconData(name);
1291
- }
1292
- function getIcon$1(name) {
1293
- const result = getIconData(name);
1294
- return result ? {
1295
- ...defaultIconProps,
1296
- ...result
1297
- } : null;
1298
- }
1299
- function sortIcons(icons) {
1300
- const result = {
1301
- loaded: [],
1302
- missing: [],
1303
- pending: []
1304
- };
1305
- const storage2 = /* @__PURE__ */Object.create(null);
1306
- icons.sort((a, b) => {
1307
- if (a.provider !== b.provider) {
1308
- return a.provider.localeCompare(b.provider);
1309
- }
1310
- if (a.prefix !== b.prefix) {
1311
- return a.prefix.localeCompare(b.prefix);
1312
- }
1313
- return a.name.localeCompare(b.name);
1314
- });
1315
- let lastIcon = {
1316
- provider: "",
1317
- prefix: "",
1318
- name: ""
1319
- };
1320
- icons.forEach(icon => {
1321
- if (lastIcon.name === icon.name && lastIcon.prefix === icon.prefix && lastIcon.provider === icon.provider) {
1322
- return;
1323
- }
1324
- lastIcon = icon;
1325
- const provider = icon.provider;
1326
- const prefix = icon.prefix;
1327
- const name = icon.name;
1328
- const providerStorage = storage2[provider] || (storage2[provider] = /* @__PURE__ */Object.create(null));
1329
- const localStorage = providerStorage[prefix] || (providerStorage[prefix] = getStorage(provider, prefix));
1330
- let list;
1331
- if (name in localStorage.icons) {
1332
- list = result.loaded;
1333
- } else if (prefix === "" || localStorage.missing.has(name)) {
1334
- list = result.missing;
1335
- } else {
1336
- list = result.pending;
1337
- }
1338
- const item = {
1339
- provider,
1340
- prefix,
1341
- name
1342
- };
1343
- list.push(item);
1344
- });
1345
- return result;
1346
- }
1347
- function removeCallback(storages, id) {
1348
- storages.forEach(storage2 => {
1349
- const items = storage2.loaderCallbacks;
1350
- if (items) {
1351
- storage2.loaderCallbacks = items.filter(row => row.id !== id);
1352
- }
1353
- });
1354
- }
1355
- function updateCallbacks(storage2) {
1356
- if (!storage2.pendingCallbacksFlag) {
1357
- storage2.pendingCallbacksFlag = true;
1358
- setTimeout(() => {
1359
- storage2.pendingCallbacksFlag = false;
1360
- const items = storage2.loaderCallbacks ? storage2.loaderCallbacks.slice(0) : [];
1361
- if (!items.length) {
1362
- return;
1363
- }
1364
- let hasPending = false;
1365
- const provider = storage2.provider;
1366
- const prefix = storage2.prefix;
1367
- items.forEach(item => {
1368
- const icons = item.icons;
1369
- const oldLength = icons.pending.length;
1370
- icons.pending = icons.pending.filter(icon => {
1371
- if (icon.prefix !== prefix) {
1372
- return true;
1373
- }
1374
- const name = icon.name;
1375
- if (storage2.icons[name]) {
1376
- icons.loaded.push({
1377
- provider,
1378
- prefix,
1379
- name
1380
- });
1381
- } else if (storage2.missing.has(name)) {
1382
- icons.missing.push({
1383
- provider,
1384
- prefix,
1385
- name
1386
- });
1387
- } else {
1388
- hasPending = true;
1389
- return true;
1390
- }
1391
- return false;
1392
- });
1393
- if (icons.pending.length !== oldLength) {
1394
- if (!hasPending) {
1395
- removeCallback([storage2], item.id);
1396
- }
1397
- item.callback(icons.loaded.slice(0), icons.missing.slice(0), icons.pending.slice(0), item.abort);
1398
- }
1399
- });
1400
- });
1401
- }
1402
- }
1403
- var idCounter = 0;
1404
- function storeCallback(callback, icons, pendingSources) {
1405
- const id = idCounter++;
1406
- const abort = removeCallback.bind(null, pendingSources, id);
1407
- if (!icons.pending.length) {
1408
- return abort;
1409
- }
1410
- const item = {
1411
- id,
1412
- icons,
1413
- callback,
1414
- abort
1415
- };
1416
- pendingSources.forEach(storage2 => {
1417
- (storage2.loaderCallbacks || (storage2.loaderCallbacks = [])).push(item);
1418
- });
1419
- return abort;
1420
- }
1421
- var storage = /* @__PURE__ */Object.create(null);
1422
- function setAPIModule(provider, item) {
1423
- storage[provider] = item;
1424
- }
1425
- function getAPIModule(provider) {
1426
- return storage[provider] || storage[""];
1427
- }
1428
- function listToIcons(list, validate = true, simpleNames2 = false) {
1429
- const result = [];
1430
- list.forEach(item => {
1431
- const icon = typeof item === "string" ? stringToIcon(item, validate, simpleNames2) : item;
1432
- if (icon) {
1433
- result.push(icon);
1434
- }
1435
- });
1436
- return result;
1437
- }
1438
- var defaultConfig = {
1439
- resources: [],
1440
- index: 0,
1441
- timeout: 2e3,
1442
- rotate: 750,
1443
- random: false,
1444
- dataAfterTimeout: false
1445
- };
1446
- function sendQuery(config, payload, query, done) {
1447
- const resourcesCount = config.resources.length;
1448
- const startIndex = config.random ? Math.floor(Math.random() * resourcesCount) : config.index;
1449
- let resources;
1450
- if (config.random) {
1451
- let list = config.resources.slice(0);
1452
- resources = [];
1453
- while (list.length > 1) {
1454
- const nextIndex = Math.floor(Math.random() * list.length);
1455
- resources.push(list[nextIndex]);
1456
- list = list.slice(0, nextIndex).concat(list.slice(nextIndex + 1));
1457
- }
1458
- resources = resources.concat(list);
1459
- } else {
1460
- resources = config.resources.slice(startIndex).concat(config.resources.slice(0, startIndex));
1461
- }
1462
- const startTime = Date.now();
1463
- let status = "pending";
1464
- let queriesSent = 0;
1465
- let lastError;
1466
- let timer = null;
1467
- let queue = [];
1468
- let doneCallbacks = [];
1469
- if (typeof done === "function") {
1470
- doneCallbacks.push(done);
1471
- }
1472
- function resetTimer() {
1473
- if (timer) {
1474
- clearTimeout(timer);
1475
- timer = null;
1476
- }
1477
- }
1478
- function abort() {
1479
- if (status === "pending") {
1480
- status = "aborted";
1481
- }
1482
- resetTimer();
1483
- queue.forEach(item => {
1484
- if (item.status === "pending") {
1485
- item.status = "aborted";
1486
- }
1487
- });
1488
- queue = [];
1489
- }
1490
- function subscribe(callback, overwrite) {
1491
- if (overwrite) {
1492
- doneCallbacks = [];
1493
- }
1494
- if (typeof callback === "function") {
1495
- doneCallbacks.push(callback);
1496
- }
1497
- }
1498
- function getQueryStatus() {
1499
- return {
1500
- startTime,
1501
- payload,
1502
- status,
1503
- queriesSent,
1504
- queriesPending: queue.length,
1505
- subscribe,
1506
- abort
1507
- };
1508
- }
1509
- function failQuery() {
1510
- status = "failed";
1511
- doneCallbacks.forEach(callback => {
1512
- callback(void 0, lastError);
1513
- });
1514
- }
1515
- function clearQueue() {
1516
- queue.forEach(item => {
1517
- if (item.status === "pending") {
1518
- item.status = "aborted";
1519
- }
1520
- });
1521
- queue = [];
1522
- }
1523
- function moduleResponse(item, response, data) {
1524
- const isError = response !== "success";
1525
- queue = queue.filter(queued => queued !== item);
1526
- switch (status) {
1527
- case "pending":
1528
- break;
1529
- case "failed":
1530
- if (isError || !config.dataAfterTimeout) {
1531
- return;
1532
- }
1533
- break;
1534
- default:
1535
- return;
1536
- }
1537
- if (response === "abort") {
1538
- lastError = data;
1539
- failQuery();
1540
- return;
1541
- }
1542
- if (isError) {
1543
- lastError = data;
1544
- if (!queue.length) {
1545
- if (!resources.length) {
1546
- failQuery();
1547
- } else {
1548
- execNext();
1549
- }
1550
- }
1551
- return;
1552
- }
1553
- resetTimer();
1554
- clearQueue();
1555
- if (!config.random) {
1556
- const index = config.resources.indexOf(item.resource);
1557
- if (index !== -1 && index !== config.index) {
1558
- config.index = index;
1559
- }
1560
- }
1561
- status = "completed";
1562
- doneCallbacks.forEach(callback => {
1563
- callback(data);
1564
- });
1565
- }
1566
- function execNext() {
1567
- if (status !== "pending") {
1568
- return;
1569
- }
1570
- resetTimer();
1571
- const resource = resources.shift();
1572
- if (resource === void 0) {
1573
- if (queue.length) {
1574
- timer = setTimeout(() => {
1575
- resetTimer();
1576
- if (status === "pending") {
1577
- clearQueue();
1578
- failQuery();
1579
- }
1580
- }, config.timeout);
1581
- return;
1582
- }
1583
- failQuery();
1584
- return;
1585
- }
1586
- const item = {
1587
- status: "pending",
1588
- resource,
1589
- callback: (status2, data) => {
1590
- moduleResponse(item, status2, data);
1591
- }
1592
- };
1593
- queue.push(item);
1594
- queriesSent++;
1595
- timer = setTimeout(execNext, config.rotate);
1596
- query(resource, payload, item.callback);
1597
- }
1598
- setTimeout(execNext);
1599
- return getQueryStatus;
1600
- }
1601
- function initRedundancy(cfg) {
1602
- const config = {
1603
- ...defaultConfig,
1604
- ...cfg
1605
- };
1606
- let queries = [];
1607
- function cleanup() {
1608
- queries = queries.filter(item => item().status === "pending");
1609
- }
1610
- function query(payload, queryCallback, doneCallback) {
1611
- const query2 = sendQuery(config, payload, queryCallback, (data, error) => {
1612
- cleanup();
1613
- if (doneCallback) {
1614
- doneCallback(data, error);
1615
- }
1616
- });
1617
- queries.push(query2);
1618
- return query2;
1619
- }
1620
- function find(callback) {
1621
- return queries.find(value => {
1622
- return callback(value);
1623
- }) || null;
1624
- }
1625
- const instance = {
1626
- query,
1627
- find,
1628
- setIndex: index => {
1629
- config.index = index;
1630
- },
1631
- getIndex: () => config.index,
1632
- cleanup
1633
- };
1634
- return instance;
1635
- }
1636
- function createAPIConfig(source) {
1637
- let resources;
1638
- if (typeof source.resources === "string") {
1639
- resources = [source.resources];
1640
- } else {
1641
- resources = source.resources;
1642
- if (!(resources instanceof Array) || !resources.length) {
1643
- return null;
1644
- }
1645
- }
1646
- const result = {
1647
- // API hosts
1648
- resources,
1649
- // Root path
1650
- path: source.path || "/",
1651
- // URL length limit
1652
- maxURL: source.maxURL || 500,
1653
- // Timeout before next host is used.
1654
- rotate: source.rotate || 750,
1655
- // Timeout before failing query.
1656
- timeout: source.timeout || 5e3,
1657
- // Randomise default API end point.
1658
- random: source.random === true,
1659
- // Start index
1660
- index: source.index || 0,
1661
- // Receive data after time out (used if time out kicks in first, then API module sends data anyway).
1662
- dataAfterTimeout: source.dataAfterTimeout !== false
1663
- };
1664
- return result;
1665
- }
1666
- var configStorage = /* @__PURE__ */Object.create(null);
1667
- var fallBackAPISources = ["https://api.simplesvg.com", "https://api.unisvg.com"];
1668
- var fallBackAPI = [];
1669
- while (fallBackAPISources.length > 0) {
1670
- if (fallBackAPISources.length === 1) {
1671
- fallBackAPI.push(fallBackAPISources.shift());
1672
- } else {
1673
- if (Math.random() > 0.5) {
1674
- fallBackAPI.push(fallBackAPISources.shift());
1675
- } else {
1676
- fallBackAPI.push(fallBackAPISources.pop());
1677
- }
1678
- }
1679
- }
1680
- configStorage[""] = createAPIConfig({
1681
- resources: ["https://api.iconify.design"].concat(fallBackAPI)
1682
- });
1683
- function addAPIProvider$1(provider, customConfig) {
1684
- const config = createAPIConfig(customConfig);
1685
- if (config === null) {
1686
- return false;
1687
- }
1688
- configStorage[provider] = config;
1689
- return true;
1690
- }
1691
- function getAPIConfig(provider) {
1692
- return configStorage[provider];
1693
- }
1694
- function listAPIProviders() {
1695
- return Object.keys(configStorage);
1696
- }
1697
- function emptyCallback$1() {}
1698
- var redundancyCache = /* @__PURE__ */Object.create(null);
1699
- function getRedundancyCache(provider) {
1700
- if (!redundancyCache[provider]) {
1701
- const config = getAPIConfig(provider);
1702
- if (!config) {
1703
- return;
1704
- }
1705
- const redundancy = initRedundancy(config);
1706
- const cachedReundancy = {
1707
- config,
1708
- redundancy
1709
- };
1710
- redundancyCache[provider] = cachedReundancy;
1711
- }
1712
- return redundancyCache[provider];
1713
- }
1714
- function sendAPIQuery(target, query, callback) {
1715
- let redundancy;
1716
- let send2;
1717
- if (typeof target === "string") {
1718
- const api = getAPIModule(target);
1719
- if (!api) {
1720
- callback(void 0, 424);
1721
- return emptyCallback$1;
1722
- }
1723
- send2 = api.send;
1724
- const cached = getRedundancyCache(target);
1725
- if (cached) {
1726
- redundancy = cached.redundancy;
1727
- }
1728
- } else {
1729
- const config = createAPIConfig(target);
1730
- if (config) {
1731
- redundancy = initRedundancy(config);
1732
- const moduleKey = target.resources ? target.resources[0] : "";
1733
- const api = getAPIModule(moduleKey);
1734
- if (api) {
1735
- send2 = api.send;
1736
- }
1737
- }
1738
- }
1739
- if (!redundancy || !send2) {
1740
- callback(void 0, 424);
1741
- return emptyCallback$1;
1742
- }
1743
- return redundancy.query(query, send2, callback)().abort;
1744
- }
1745
- var browserCacheVersion = "iconify2";
1746
- var browserCachePrefix = "iconify";
1747
- var browserCacheCountKey = browserCachePrefix + "-count";
1748
- var browserCacheVersionKey = browserCachePrefix + "-version";
1749
- var browserStorageHour = 36e5;
1750
- var browserStorageCacheExpiration = 168;
1751
- var browserStorageLimit = 50;
1752
- function getStoredItem(func, key) {
1753
- try {
1754
- return func.getItem(key);
1755
- } catch (err) {}
1756
- }
1757
- function setStoredItem(func, key, value) {
1758
- try {
1759
- func.setItem(key, value);
1760
- return true;
1761
- } catch (err) {}
1762
- }
1763
- function removeStoredItem(func, key) {
1764
- try {
1765
- func.removeItem(key);
1766
- } catch (err) {}
1767
- }
1768
- function setBrowserStorageItemsCount(storage2, value) {
1769
- return setStoredItem(storage2, browserCacheCountKey, value.toString());
1770
- }
1771
- function getBrowserStorageItemsCount(storage2) {
1772
- return parseInt(getStoredItem(storage2, browserCacheCountKey)) || 0;
1773
- }
1774
- var browserStorageConfig = {
1775
- local: true,
1776
- session: true
1777
- };
1778
- var browserStorageEmptyItems = {
1779
- local: /* @__PURE__ */new Set(),
1780
- session: /* @__PURE__ */new Set()
1781
- };
1782
- var browserStorageStatus = false;
1783
- function setBrowserStorageStatus(status) {
1784
- browserStorageStatus = status;
1785
- }
1786
- var _window = typeof window === "undefined" ? {} : window;
1787
- function getBrowserStorage(key) {
1788
- const attr = key + "Storage";
1789
- try {
1790
- if (_window && _window[attr] && typeof _window[attr].length === "number") {
1791
- return _window[attr];
1792
- }
1793
- } catch (err) {}
1794
- browserStorageConfig[key] = false;
1795
- }
1796
- function iterateBrowserStorage(key, callback) {
1797
- const func = getBrowserStorage(key);
1798
- if (!func) {
1799
- return;
1800
- }
1801
- const version = getStoredItem(func, browserCacheVersionKey);
1802
- if (version !== browserCacheVersion) {
1803
- if (version) {
1804
- const total2 = getBrowserStorageItemsCount(func);
1805
- for (let i = 0; i < total2; i++) {
1806
- removeStoredItem(func, browserCachePrefix + i.toString());
1807
- }
1808
- }
1809
- setStoredItem(func, browserCacheVersionKey, browserCacheVersion);
1810
- setBrowserStorageItemsCount(func, 0);
1811
- return;
1812
- }
1813
- const minTime = Math.floor(Date.now() / browserStorageHour) - browserStorageCacheExpiration;
1814
- const parseItem = index => {
1815
- const name = browserCachePrefix + index.toString();
1816
- const item = getStoredItem(func, name);
1817
- if (typeof item !== "string") {
1818
- return;
1819
- }
1820
- try {
1821
- const data = JSON.parse(item);
1822
- if (typeof data === "object" && typeof data.cached === "number" && data.cached > minTime && typeof data.provider === "string" && typeof data.data === "object" && typeof data.data.prefix === "string" &&
1823
- // Valid item: run callback
1824
- callback(data, index)) {
1825
- return true;
1826
- }
1827
- } catch (err) {}
1828
- removeStoredItem(func, name);
1829
- };
1830
- let total = getBrowserStorageItemsCount(func);
1831
- for (let i = total - 1; i >= 0; i--) {
1832
- if (!parseItem(i)) {
1833
- if (i === total - 1) {
1834
- total--;
1835
- setBrowserStorageItemsCount(func, total);
1836
- } else {
1837
- browserStorageEmptyItems[key].add(i);
1838
- }
1839
- }
1840
- }
1841
- }
1842
- function initBrowserStorage() {
1843
- if (browserStorageStatus) {
1844
- return;
1845
- }
1846
- setBrowserStorageStatus(true);
1847
- for (const key in browserStorageConfig) {
1848
- iterateBrowserStorage(key, item => {
1849
- const iconSet = item.data;
1850
- const provider = item.provider;
1851
- const prefix = iconSet.prefix;
1852
- const storage2 = getStorage(provider, prefix);
1853
- if (!addIconSet(storage2, iconSet).length) {
1854
- return false;
1855
- }
1856
- const lastModified = iconSet.lastModified || -1;
1857
- storage2.lastModifiedCached = storage2.lastModifiedCached ? Math.min(storage2.lastModifiedCached, lastModified) : lastModified;
1858
- return true;
1859
- });
1860
- }
1861
- }
1862
- function updateLastModified(storage2, lastModified) {
1863
- const lastValue = storage2.lastModifiedCached;
1864
- if (
1865
- // Matches or newer
1866
- lastValue && lastValue >= lastModified) {
1867
- return lastValue === lastModified;
1868
- }
1869
- storage2.lastModifiedCached = lastModified;
1870
- if (lastValue) {
1871
- for (const key in browserStorageConfig) {
1872
- iterateBrowserStorage(key, item => {
1873
- const iconSet = item.data;
1874
- return item.provider !== storage2.provider || iconSet.prefix !== storage2.prefix || iconSet.lastModified === lastModified;
1875
- });
1876
- }
1877
- }
1878
- return true;
1879
- }
1880
- function storeInBrowserStorage(storage2, data) {
1881
- if (!browserStorageStatus) {
1882
- initBrowserStorage();
1883
- }
1884
- function store(key) {
1885
- let func;
1886
- if (!browserStorageConfig[key] || !(func = getBrowserStorage(key))) {
1887
- return;
1888
- }
1889
- const set = browserStorageEmptyItems[key];
1890
- let index;
1891
- if (set.size) {
1892
- set.delete(index = Array.from(set).shift());
1893
- } else {
1894
- index = getBrowserStorageItemsCount(func);
1895
- if (index >= browserStorageLimit || !setBrowserStorageItemsCount(func, index + 1)) {
1896
- return;
1897
- }
1898
- }
1899
- const item = {
1900
- cached: Math.floor(Date.now() / browserStorageHour),
1901
- provider: storage2.provider,
1902
- data
1903
- };
1904
- return setStoredItem(func, browserCachePrefix + index.toString(), JSON.stringify(item));
1905
- }
1906
- if (data.lastModified && !updateLastModified(storage2, data.lastModified)) {
1907
- return;
1908
- }
1909
- if (!Object.keys(data.icons).length) {
1910
- return;
1911
- }
1912
- if (data.not_found) {
1913
- data = Object.assign({}, data);
1914
- delete data.not_found;
1915
- }
1916
- if (!store("local")) {
1917
- store("session");
1918
- }
1919
- }
1920
- function emptyCallback() {}
1921
- function loadedNewIcons(storage2) {
1922
- if (!storage2.iconsLoaderFlag) {
1923
- storage2.iconsLoaderFlag = true;
1924
- setTimeout(() => {
1925
- storage2.iconsLoaderFlag = false;
1926
- updateCallbacks(storage2);
1927
- });
1928
- }
1929
- }
1930
- function loadNewIcons(storage2, icons) {
1931
- if (!storage2.iconsToLoad) {
1932
- storage2.iconsToLoad = icons;
1933
- } else {
1934
- storage2.iconsToLoad = storage2.iconsToLoad.concat(icons).sort();
1935
- }
1936
- if (!storage2.iconsQueueFlag) {
1937
- storage2.iconsQueueFlag = true;
1938
- setTimeout(() => {
1939
- storage2.iconsQueueFlag = false;
1940
- const {
1941
- provider,
1942
- prefix
1943
- } = storage2;
1944
- const icons2 = storage2.iconsToLoad;
1945
- delete storage2.iconsToLoad;
1946
- let api;
1947
- if (!icons2 || !(api = getAPIModule(provider))) {
1948
- return;
1949
- }
1950
- const params = api.prepare(provider, prefix, icons2);
1951
- params.forEach(item => {
1952
- sendAPIQuery(provider, item, data => {
1953
- if (typeof data !== "object") {
1954
- item.icons.forEach(name => {
1955
- storage2.missing.add(name);
1956
- });
1957
- } else {
1958
- try {
1959
- const parsed = addIconSet(storage2, data);
1960
- if (!parsed.length) {
1961
- return;
1962
- }
1963
- const pending = storage2.pendingIcons;
1964
- if (pending) {
1965
- parsed.forEach(name => {
1966
- pending.delete(name);
1967
- });
1968
- }
1969
- storeInBrowserStorage(storage2, data);
1970
- } catch (err) {
1971
- console.error(err);
1972
- }
1973
- }
1974
- loadedNewIcons(storage2);
1975
- });
1976
- });
1977
- });
1978
- }
1979
- }
1980
- var loadIcons$1 = (icons, callback) => {
1981
- const cleanedIcons = listToIcons(icons, true, allowSimpleNames());
1982
- const sortedIcons = sortIcons(cleanedIcons);
1983
- if (!sortedIcons.pending.length) {
1984
- let callCallback = true;
1985
- if (callback) {
1986
- setTimeout(() => {
1987
- if (callCallback) {
1988
- callback(sortedIcons.loaded, sortedIcons.missing, sortedIcons.pending, emptyCallback);
1989
- }
1990
- });
1991
- }
1992
- return () => {
1993
- callCallback = false;
1994
- };
1995
- }
1996
- const newIcons = /* @__PURE__ */Object.create(null);
1997
- const sources = [];
1998
- let lastProvider, lastPrefix;
1999
- sortedIcons.pending.forEach(icon => {
2000
- const {
2001
- provider,
2002
- prefix
2003
- } = icon;
2004
- if (prefix === lastPrefix && provider === lastProvider) {
2005
- return;
2006
- }
2007
- lastProvider = provider;
2008
- lastPrefix = prefix;
2009
- sources.push(getStorage(provider, prefix));
2010
- const providerNewIcons = newIcons[provider] || (newIcons[provider] = /* @__PURE__ */Object.create(null));
2011
- if (!providerNewIcons[prefix]) {
2012
- providerNewIcons[prefix] = [];
2013
- }
2014
- });
2015
- sortedIcons.pending.forEach(icon => {
2016
- const {
2017
- provider,
2018
- prefix,
2019
- name
2020
- } = icon;
2021
- const storage2 = getStorage(provider, prefix);
2022
- const pendingQueue = storage2.pendingIcons || (storage2.pendingIcons = /* @__PURE__ */new Set());
2023
- if (!pendingQueue.has(name)) {
2024
- pendingQueue.add(name);
2025
- newIcons[provider][prefix].push(name);
2026
- }
2027
- });
2028
- sources.forEach(storage2 => {
2029
- const {
2030
- provider,
2031
- prefix
2032
- } = storage2;
2033
- if (newIcons[provider][prefix].length) {
2034
- loadNewIcons(storage2, newIcons[provider][prefix]);
2035
- }
2036
- });
2037
- return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback;
2038
- };
2039
- var loadIcon$1 = icon => {
2040
- return new Promise((fulfill, reject) => {
2041
- const iconObj = typeof icon === "string" ? stringToIcon(icon, true) : icon;
2042
- if (!iconObj) {
2043
- reject(icon);
2044
- return;
2045
- }
2046
- loadIcons$1([iconObj || icon], loaded => {
2047
- if (loaded.length && iconObj) {
2048
- const data = getIconData(iconObj);
2049
- if (data) {
2050
- fulfill({
2051
- ...defaultIconProps,
2052
- ...data
2053
- });
2054
- return;
2055
- }
2056
- }
2057
- reject(icon);
2058
- });
2059
- });
2060
- };
2061
- function testIconObject(value) {
2062
- try {
2063
- const obj = typeof value === "string" ? JSON.parse(value) : value;
2064
- if (typeof obj.body === "string") {
2065
- return {
2066
- ...obj
2067
- };
2068
- }
2069
- } catch (err) {}
2070
- }
2071
- function parseIconValue(value, onload) {
2072
- const name = typeof value === "string" ? stringToIcon(value, true, true) : null;
2073
- if (!name) {
2074
- const data2 = testIconObject(value);
2075
- return {
2076
- value,
2077
- data: data2
2078
- };
2079
- }
2080
- const data = getIconData(name);
2081
- if (data !== void 0 || !name.prefix) {
2082
- return {
2083
- value,
2084
- name,
2085
- data
2086
- // could be 'null' -> icon is missing
2087
- };
2088
- }
2089
- const loading = loadIcons$1([name], () => onload(value, name, getIconData(name)));
2090
- return {
2091
- value,
2092
- name,
2093
- loading
2094
- };
2095
- }
2096
- var isBuggedSafari = false;
2097
- try {
2098
- isBuggedSafari = navigator.vendor.indexOf("Apple") === 0;
2099
- } catch (err) {}
2100
- function getRenderMode(body, mode) {
2101
- switch (mode) {
2102
- // Force mode
2103
- case "svg":
2104
- case "bg":
2105
- case "mask":
2106
- return mode;
2107
- }
2108
- if (mode !== "style" && (isBuggedSafari || body.indexOf("<a") === -1)) {
2109
- return "svg";
2110
- }
2111
- return body.indexOf("currentColor") === -1 ? "bg" : "mask";
2112
- }
2113
- var unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
2114
- var unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
2115
- function calculateSize$1(size, ratio, precision) {
2116
- if (ratio === 1) {
2117
- return size;
2118
- }
2119
- precision = precision || 100;
2120
- if (typeof size === "number") {
2121
- return Math.ceil(size * ratio * precision) / precision;
2122
- }
2123
- if (typeof size !== "string") {
2124
- return size;
2125
- }
2126
- const oldParts = size.split(unitsSplit);
2127
- if (oldParts === null || !oldParts.length) {
2128
- return size;
2129
- }
2130
- const newParts = [];
2131
- let code = oldParts.shift();
2132
- let isNumber = unitsTest.test(code);
2133
- while (true) {
2134
- if (isNumber) {
2135
- const num = parseFloat(code);
2136
- if (isNaN(num)) {
2137
- newParts.push(code);
2138
- } else {
2139
- newParts.push(Math.ceil(num * ratio * precision) / precision);
2140
- }
2141
- } else {
2142
- newParts.push(code);
2143
- }
2144
- code = oldParts.shift();
2145
- if (code === void 0) {
2146
- return newParts.join("");
2147
- }
2148
- isNumber = !isNumber;
2149
- }
2150
- }
2151
- function splitSVGDefs(content, tag = "defs") {
2152
- let defs = "";
2153
- const index = content.indexOf("<" + tag);
2154
- while (index >= 0) {
2155
- const start = content.indexOf(">", index);
2156
- const end = content.indexOf("</" + tag);
2157
- if (start === -1 || end === -1) {
2158
- break;
2159
- }
2160
- const endEnd = content.indexOf(">", end);
2161
- if (endEnd === -1) {
2162
- break;
2163
- }
2164
- defs += content.slice(start + 1, end).trim();
2165
- content = content.slice(0, index).trim() + content.slice(endEnd + 1);
2166
- }
2167
- return {
2168
- defs,
2169
- content
2170
- };
2171
- }
2172
- function mergeDefsAndContent(defs, content) {
2173
- return defs ? "<defs>" + defs + "</defs>" + content : content;
2174
- }
2175
- function wrapSVGContent(body, start, end) {
2176
- const split = splitSVGDefs(body);
2177
- return mergeDefsAndContent(split.defs, start + split.content + end);
2178
- }
2179
- var isUnsetKeyword = value => value === "unset" || value === "undefined" || value === "none";
2180
- function iconToSVG(icon, customisations) {
2181
- const fullIcon = {
2182
- ...defaultIconProps,
2183
- ...icon
2184
- };
2185
- const fullCustomisations = {
2186
- ...defaultIconCustomisations,
2187
- ...customisations
2188
- };
2189
- const box = {
2190
- left: fullIcon.left,
2191
- top: fullIcon.top,
2192
- width: fullIcon.width,
2193
- height: fullIcon.height
2194
- };
2195
- let body = fullIcon.body;
2196
- [fullIcon, fullCustomisations].forEach(props => {
2197
- const transformations = [];
2198
- const hFlip = props.hFlip;
2199
- const vFlip = props.vFlip;
2200
- let rotation = props.rotate;
2201
- if (hFlip) {
2202
- if (vFlip) {
2203
- rotation += 2;
2204
- } else {
2205
- transformations.push("translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")");
2206
- transformations.push("scale(-1 1)");
2207
- box.top = box.left = 0;
2208
- }
2209
- } else if (vFlip) {
2210
- transformations.push("translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")");
2211
- transformations.push("scale(1 -1)");
2212
- box.top = box.left = 0;
2213
- }
2214
- let tempValue;
2215
- if (rotation < 0) {
2216
- rotation -= Math.floor(rotation / 4) * 4;
2217
- }
2218
- rotation = rotation % 4;
2219
- switch (rotation) {
2220
- case 1:
2221
- tempValue = box.height / 2 + box.top;
2222
- transformations.unshift("rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")");
2223
- break;
2224
- case 2:
2225
- transformations.unshift("rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")");
2226
- break;
2227
- case 3:
2228
- tempValue = box.width / 2 + box.left;
2229
- transformations.unshift("rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")");
2230
- break;
2231
- }
2232
- if (rotation % 2 === 1) {
2233
- if (box.left !== box.top) {
2234
- tempValue = box.left;
2235
- box.left = box.top;
2236
- box.top = tempValue;
2237
- }
2238
- if (box.width !== box.height) {
2239
- tempValue = box.width;
2240
- box.width = box.height;
2241
- box.height = tempValue;
2242
- }
2243
- }
2244
- if (transformations.length) {
2245
- body = wrapSVGContent(body, '<g transform="' + transformations.join(" ") + '">', "</g>");
2246
- }
2247
- });
2248
- const customisationsWidth = fullCustomisations.width;
2249
- const customisationsHeight = fullCustomisations.height;
2250
- const boxWidth = box.width;
2251
- const boxHeight = box.height;
2252
- let width;
2253
- let height;
2254
- if (customisationsWidth === null) {
2255
- height = customisationsHeight === null ? "1em" : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
2256
- width = calculateSize$1(height, boxWidth / boxHeight);
2257
- } else {
2258
- width = customisationsWidth === "auto" ? boxWidth : customisationsWidth;
2259
- height = customisationsHeight === null ? calculateSize$1(width, boxHeight / boxWidth) : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
2260
- }
2261
- const attributes = {};
2262
- const setAttr = (prop, value) => {
2263
- if (!isUnsetKeyword(value)) {
2264
- attributes[prop] = value.toString();
2265
- }
2266
- };
2267
- setAttr("width", width);
2268
- setAttr("height", height);
2269
- const viewBox = [box.left, box.top, boxWidth, boxHeight];
2270
- attributes.viewBox = viewBox.join(" ");
2271
- return {
2272
- attributes,
2273
- viewBox,
2274
- body
2275
- };
2276
- }
2277
- function iconToHTML$1(body, attributes) {
2278
- let renderAttribsHTML = body.indexOf("xlink:") === -1 ? "" : ' xmlns:xlink="http://www.w3.org/1999/xlink"';
2279
- for (const attr in attributes) {
2280
- renderAttribsHTML += " " + attr + '="' + attributes[attr] + '"';
2281
- }
2282
- return '<svg xmlns="http://www.w3.org/2000/svg"' + renderAttribsHTML + ">" + body + "</svg>";
2283
- }
2284
- function encodeSVGforURL(svg) {
2285
- return svg.replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\s+/g, " ");
2286
- }
2287
- function svgToData(svg) {
2288
- return "data:image/svg+xml," + encodeSVGforURL(svg);
2289
- }
2290
- function svgToURL$1(svg) {
2291
- return 'url("' + svgToData(svg) + '")';
2292
- }
2293
- var detectFetch = () => {
2294
- let callback;
2295
- try {
2296
- callback = fetch;
2297
- if (typeof callback === "function") {
2298
- return callback;
2299
- }
2300
- } catch (err) {}
2301
- };
2302
- var fetchModule = detectFetch();
2303
- function setFetch(fetch2) {
2304
- fetchModule = fetch2;
2305
- }
2306
- function getFetch() {
2307
- return fetchModule;
2308
- }
2309
- function calculateMaxLength(provider, prefix) {
2310
- const config = getAPIConfig(provider);
2311
- if (!config) {
2312
- return 0;
2313
- }
2314
- let result;
2315
- if (!config.maxURL) {
2316
- result = 0;
2317
- } else {
2318
- let maxHostLength = 0;
2319
- config.resources.forEach(item => {
2320
- const host = item;
2321
- maxHostLength = Math.max(maxHostLength, host.length);
2322
- });
2323
- const url = prefix + ".json?icons=";
2324
- result = config.maxURL - maxHostLength - config.path.length - url.length;
2325
- }
2326
- return result;
2327
- }
2328
- function shouldAbort(status) {
2329
- return status === 404;
2330
- }
2331
- var prepare = (provider, prefix, icons) => {
2332
- const results = [];
2333
- const maxLength = calculateMaxLength(provider, prefix);
2334
- const type = "icons";
2335
- let item = {
2336
- type,
2337
- provider,
2338
- prefix,
2339
- icons: []
2340
- };
2341
- let length = 0;
2342
- icons.forEach((name, index) => {
2343
- length += name.length + 1;
2344
- if (length >= maxLength && index > 0) {
2345
- results.push(item);
2346
- item = {
2347
- type,
2348
- provider,
2349
- prefix,
2350
- icons: []
2351
- };
2352
- length = name.length;
2353
- }
2354
- item.icons.push(name);
2355
- });
2356
- results.push(item);
2357
- return results;
2358
- };
2359
- function getPath(provider) {
2360
- if (typeof provider === "string") {
2361
- const config = getAPIConfig(provider);
2362
- if (config) {
2363
- return config.path;
2364
- }
2365
- }
2366
- return "/";
2367
- }
2368
- var send = (host, params, callback) => {
2369
- if (!fetchModule) {
2370
- callback("abort", 424);
2371
- return;
2372
- }
2373
- let path = getPath(params.provider);
2374
- switch (params.type) {
2375
- case "icons":
2376
- {
2377
- const prefix = params.prefix;
2378
- const icons = params.icons;
2379
- const iconsList = icons.join(",");
2380
- const urlParams = new URLSearchParams({
2381
- icons: iconsList
2382
- });
2383
- path += prefix + ".json?" + urlParams.toString();
2384
- break;
2385
- }
2386
- case "custom":
2387
- {
2388
- const uri = params.uri;
2389
- path += uri.slice(0, 1) === "/" ? uri.slice(1) : uri;
2390
- break;
2391
- }
2392
- default:
2393
- callback("abort", 400);
2394
- return;
2395
- }
2396
- let defaultError = 503;
2397
- fetchModule(host + path).then(response => {
2398
- const status = response.status;
2399
- if (status !== 200) {
2400
- setTimeout(() => {
2401
- callback(shouldAbort(status) ? "abort" : "next", status);
2402
- });
2403
- return;
2404
- }
2405
- defaultError = 501;
2406
- return response.json();
2407
- }).then(data => {
2408
- if (typeof data !== "object" || data === null) {
2409
- setTimeout(() => {
2410
- if (data === 404) {
2411
- callback("abort", data);
2412
- } else {
2413
- callback("next", defaultError);
2414
- }
2415
- });
2416
- return;
2417
- }
2418
- setTimeout(() => {
2419
- callback("success", data);
2420
- });
2421
- }).catch(() => {
2422
- callback("next", defaultError);
2423
- });
2424
- };
2425
- var fetchAPIModule = {
2426
- prepare,
2427
- send
2428
- };
2429
- function toggleBrowserCache(storage2, value) {
2430
- switch (storage2) {
2431
- case "local":
2432
- case "session":
2433
- browserStorageConfig[storage2] = value;
2434
- break;
2435
- case "all":
2436
- for (const key in browserStorageConfig) {
2437
- browserStorageConfig[key] = value;
2438
- }
2439
- break;
2440
- }
2441
- }
2442
- var nodeAttr = "data-style";
2443
- var customStyle = "";
2444
- function appendCustomStyle(style) {
2445
- customStyle = style;
2446
- }
2447
- function updateStyle(parent, inline) {
2448
- let styleNode = Array.from(parent.childNodes).find(node => node.hasAttribute && node.hasAttribute(nodeAttr));
2449
- if (!styleNode) {
2450
- styleNode = document.createElement("style");
2451
- styleNode.setAttribute(nodeAttr, nodeAttr);
2452
- parent.appendChild(styleNode);
2453
- }
2454
- styleNode.textContent = ":host{display:inline-block;vertical-align:" + (inline ? "-0.125em" : "0") + "}span,svg{display:block}" + customStyle;
2455
- }
2456
- function exportFunctions() {
2457
- setAPIModule("", fetchAPIModule);
2458
- allowSimpleNames(true);
2459
- let _window2;
2460
- try {
2461
- _window2 = window;
2462
- } catch (err) {}
2463
- if (_window2) {
2464
- initBrowserStorage();
2465
- if (_window2.IconifyPreload !== void 0) {
2466
- const preload = _window2.IconifyPreload;
2467
- const err = "Invalid IconifyPreload syntax.";
2468
- if (typeof preload === "object" && preload !== null) {
2469
- (preload instanceof Array ? preload : [preload]).forEach(item => {
2470
- try {
2471
- if (
2472
- // Check if item is an object and not null/array
2473
- typeof item !== "object" || item === null || item instanceof Array ||
2474
- // Check for 'icons' and 'prefix'
2475
- typeof item.icons !== "object" || typeof item.prefix !== "string" ||
2476
- // Add icon set
2477
- !addCollection$1(item)) {
2478
- console.error(err);
2479
- }
2480
- } catch (e) {
2481
- console.error(err);
2482
- }
2483
- });
2484
- }
2485
- }
2486
- if (_window2.IconifyProviders !== void 0) {
2487
- const providers = _window2.IconifyProviders;
2488
- if (typeof providers === "object" && providers !== null) {
2489
- for (const key in providers) {
2490
- const err = "IconifyProviders[" + key + "] is invalid.";
2491
- try {
2492
- const value = providers[key];
2493
- if (typeof value !== "object" || !value || value.resources === void 0) {
2494
- continue;
2495
- }
2496
- if (!addAPIProvider$1(key, value)) {
2497
- console.error(err);
2498
- }
2499
- } catch (e) {
2500
- console.error(err);
2501
- }
2502
- }
2503
- }
2504
- }
2505
- }
2506
- const _api2 = {
2507
- getAPIConfig,
2508
- setAPIModule,
2509
- sendAPIQuery,
2510
- setFetch,
2511
- getFetch,
2512
- listAPIProviders
2513
- };
2514
- return {
2515
- enableCache: storage2 => toggleBrowserCache(storage2, true),
2516
- disableCache: storage2 => toggleBrowserCache(storage2, false),
2517
- iconLoaded: iconLoaded$1,
2518
- iconExists: iconLoaded$1,
2519
- // deprecated, kept to avoid breaking changes
2520
- getIcon: getIcon$1,
2521
- listIcons: listIcons$1,
2522
- addIcon: addIcon$1,
2523
- addCollection: addCollection$1,
2524
- calculateSize: calculateSize$1,
2525
- buildIcon: iconToSVG,
2526
- iconToHTML: iconToHTML$1,
2527
- svgToURL: svgToURL$1,
2528
- loadIcons: loadIcons$1,
2529
- loadIcon: loadIcon$1,
2530
- addAPIProvider: addAPIProvider$1,
2531
- appendCustomStyle,
2532
- _api: _api2
2533
- };
2534
- }
2535
- var monotoneProps = {
2536
- "background-color": "currentColor"
2537
- };
2538
- var coloredProps = {
2539
- "background-color": "transparent"
2540
- };
2541
- var propsToAdd = {
2542
- image: "var(--svg)",
2543
- repeat: "no-repeat",
2544
- size: "100% 100%"
2545
- };
2546
- var propsToAddTo = {
2547
- "-webkit-mask": monotoneProps,
2548
- "mask": monotoneProps,
2549
- "background": coloredProps
2550
- };
2551
- for (const prefix in propsToAddTo) {
2552
- const list = propsToAddTo[prefix];
2553
- for (const prop in propsToAdd) {
2554
- list[prefix + "-" + prop] = propsToAdd[prop];
2555
- }
2556
- }
2557
- function fixSize(value) {
2558
- return value ? value + (value.match(/^[-0-9.]+$/) ? "px" : "") : "inherit";
2559
- }
2560
- function renderSPAN(data, icon, useMask) {
2561
- const node = document.createElement("span");
2562
- let body = data.body;
2563
- if (body.indexOf("<a") !== -1) {
2564
- body += "<!-- " + Date.now() + " -->";
2565
- }
2566
- const renderAttribs = data.attributes;
2567
- const html = iconToHTML$1(body, {
2568
- ...renderAttribs,
2569
- width: icon.width + "",
2570
- height: icon.height + ""
2571
- });
2572
- const url = svgToURL$1(html);
2573
- const svgStyle = node.style;
2574
- const styles = {
2575
- "--svg": url,
2576
- "width": fixSize(renderAttribs.width),
2577
- "height": fixSize(renderAttribs.height),
2578
- ...(useMask ? monotoneProps : coloredProps)
2579
- };
2580
- for (const prop in styles) {
2581
- svgStyle.setProperty(prop, styles[prop]);
2582
- }
2583
- return node;
2584
- }
2585
- var policy;
2586
- function createPolicy() {
2587
- try {
2588
- policy = window.trustedTypes.createPolicy("iconify", {
2589
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
2590
- createHTML: s => s
2591
- });
2592
- } catch (err) {
2593
- policy = null;
2594
- }
2595
- }
2596
- function cleanUpInnerHTML(html) {
2597
- if (policy === void 0) {
2598
- createPolicy();
2599
- }
2600
- return policy ? policy.createHTML(html) : html;
2601
- }
2602
- function renderSVG(data) {
2603
- const node = document.createElement("span");
2604
- const attr = data.attributes;
2605
- let style = "";
2606
- if (!attr.width) {
2607
- style = "width: inherit;";
2608
- }
2609
- if (!attr.height) {
2610
- style += "height: inherit;";
2611
- }
2612
- if (style) {
2613
- attr.style = style;
2614
- }
2615
- const html = iconToHTML$1(data.body, attr);
2616
- node.innerHTML = cleanUpInnerHTML(html);
2617
- return node.firstChild;
2618
- }
2619
- function findIconElement(parent) {
2620
- return Array.from(parent.childNodes).find(node => {
2621
- const tag = node.tagName && node.tagName.toUpperCase();
2622
- return tag === "SPAN" || tag === "SVG";
2623
- });
2624
- }
2625
- function renderIcon(parent, state) {
2626
- const iconData = state.icon.data;
2627
- const customisations = state.customisations;
2628
- const renderData = iconToSVG(iconData, customisations);
2629
- if (customisations.preserveAspectRatio) {
2630
- renderData.attributes["preserveAspectRatio"] = customisations.preserveAspectRatio;
2631
- }
2632
- const mode = state.renderedMode;
2633
- let node;
2634
- switch (mode) {
2635
- case "svg":
2636
- node = renderSVG(renderData);
2637
- break;
2638
- default:
2639
- node = renderSPAN(renderData, {
2640
- ...defaultIconProps,
2641
- ...iconData
2642
- }, mode === "mask");
2643
- }
2644
- const oldNode = findIconElement(parent);
2645
- if (oldNode) {
2646
- if (node.tagName === "SPAN" && oldNode.tagName === node.tagName) {
2647
- oldNode.setAttribute("style", node.getAttribute("style"));
2648
- } else {
2649
- parent.replaceChild(node, oldNode);
2650
- }
2651
- } else {
2652
- parent.appendChild(node);
2653
- }
2654
- }
2655
- function setPendingState(icon, inline, lastState) {
2656
- const lastRender = lastState && (lastState.rendered ? lastState : lastState.lastRender);
2657
- return {
2658
- rendered: false,
2659
- inline,
2660
- icon,
2661
- lastRender
2662
- };
2663
- }
2664
- function defineIconifyIcon(name = "iconify-icon") {
2665
- let customElements;
2666
- let ParentClass;
2667
- try {
2668
- customElements = window.customElements;
2669
- ParentClass = window.HTMLElement;
2670
- } catch (err) {
2671
- return;
2672
- }
2673
- if (!customElements || !ParentClass) {
2674
- return;
2675
- }
2676
- const ConflictingClass = customElements.get(name);
2677
- if (ConflictingClass) {
2678
- return ConflictingClass;
2679
- }
2680
- const attributes = [
2681
- // Icon
2682
- "icon",
2683
- // Mode
2684
- "mode", "inline", "noobserver",
2685
- // Customisations
2686
- "width", "height", "rotate", "flip"];
2687
- const IconifyIcon2 = class extends ParentClass {
2688
- /**
2689
- * Constructor
2690
- */
2691
- constructor() {
2692
- super();
2693
- // Root
2694
- __publicField(this, "_shadowRoot");
2695
- // Initialised
2696
- __publicField(this, "_initialised", false);
2697
- // Icon state
2698
- __publicField(this, "_state");
2699
- // Attributes check queued
2700
- __publicField(this, "_checkQueued", false);
2701
- // Connected
2702
- __publicField(this, "_connected", false);
2703
- // Observer
2704
- __publicField(this, "_observer", null);
2705
- __publicField(this, "_visible", true);
2706
- const root = this._shadowRoot = this.attachShadow({
2707
- mode: "open"
2708
- });
2709
- const inline = this.hasAttribute("inline");
2710
- updateStyle(root, inline);
2711
- this._state = setPendingState({
2712
- value: ""
2713
- }, inline);
2714
- this._queueCheck();
2715
- }
2716
- /**
2717
- * Connected to DOM
2718
- */
2719
- connectedCallback() {
2720
- this._connected = true;
2721
- this.startObserver();
2722
- }
2723
- /**
2724
- * Disconnected from DOM
2725
- */
2726
- disconnectedCallback() {
2727
- this._connected = false;
2728
- this.stopObserver();
2729
- }
2730
- /**
2731
- * Observed attributes
2732
- */
2733
- static get observedAttributes() {
2734
- return attributes.slice(0);
2735
- }
2736
- /**
2737
- * Observed properties that are different from attributes
2738
- *
2739
- * Experimental! Need to test with various frameworks that support it
2740
- */
2741
- /*
2742
- static get properties() {
2743
- return {
2744
- inline: {
2745
- type: Boolean,
2746
- reflect: true,
2747
- },
2748
- // Not listing other attributes because they are strings or combination
2749
- // of string and another type. Cannot have multiple types
2750
- };
2751
- }
2752
- */
2753
- /**
2754
- * Attribute has changed
2755
- */
2756
- attributeChangedCallback(name2) {
2757
- switch (name2) {
2758
- case "inline":
2759
- {
2760
- const newInline = this.hasAttribute("inline");
2761
- const state = this._state;
2762
- if (newInline !== state.inline) {
2763
- state.inline = newInline;
2764
- updateStyle(this._shadowRoot, newInline);
2765
- }
2766
- break;
2767
- }
2768
- case "noobserver":
2769
- {
2770
- const value = this.hasAttribute("noobserver");
2771
- if (value) {
2772
- this.startObserver();
2773
- } else {
2774
- this.stopObserver();
2775
- }
2776
- break;
2777
- }
2778
- default:
2779
- this._queueCheck();
2780
- }
2781
- }
2782
- /**
2783
- * Get/set icon
2784
- */
2785
- get icon() {
2786
- const value = this.getAttribute("icon");
2787
- if (value && value.slice(0, 1) === "{") {
2788
- try {
2789
- return JSON.parse(value);
2790
- } catch (err) {}
2791
- }
2792
- return value;
2793
- }
2794
- set icon(value) {
2795
- if (typeof value === "object") {
2796
- value = JSON.stringify(value);
2797
- }
2798
- this.setAttribute("icon", value);
2799
- }
2800
- /**
2801
- * Get/set inline
2802
- */
2803
- get inline() {
2804
- return this.hasAttribute("inline");
2805
- }
2806
- set inline(value) {
2807
- if (value) {
2808
- this.setAttribute("inline", "true");
2809
- } else {
2810
- this.removeAttribute("inline");
2811
- }
2812
- }
2813
- /**
2814
- * Get/set observer
2815
- */
2816
- get observer() {
2817
- return this.hasAttribute("observer");
2818
- }
2819
- set observer(value) {
2820
- if (value) {
2821
- this.setAttribute("observer", "true");
2822
- } else {
2823
- this.removeAttribute("observer");
2824
- }
2825
- }
2826
- /**
2827
- * Restart animation
2828
- */
2829
- restartAnimation() {
2830
- const state = this._state;
2831
- if (state.rendered) {
2832
- const root = this._shadowRoot;
2833
- if (state.renderedMode === "svg") {
2834
- try {
2835
- root.lastChild.setCurrentTime(0);
2836
- return;
2837
- } catch (err) {}
2838
- }
2839
- renderIcon(root, state);
2840
- }
2841
- }
2842
- /**
2843
- * Get status
2844
- */
2845
- get status() {
2846
- const state = this._state;
2847
- return state.rendered ? "rendered" : state.icon.data === null ? "failed" : "loading";
2848
- }
2849
- /**
2850
- * Queue attributes re-check
2851
- */
2852
- _queueCheck() {
2853
- if (!this._checkQueued) {
2854
- this._checkQueued = true;
2855
- setTimeout(() => {
2856
- this._check();
2857
- });
2858
- }
2859
- }
2860
- /**
2861
- * Check for changes
2862
- */
2863
- _check() {
2864
- if (!this._checkQueued) {
2865
- return;
2866
- }
2867
- this._checkQueued = false;
2868
- const state = this._state;
2869
- const newIcon = this.getAttribute("icon");
2870
- if (newIcon !== state.icon.value) {
2871
- this._iconChanged(newIcon);
2872
- return;
2873
- }
2874
- if (!state.rendered || !this._visible) {
2875
- return;
2876
- }
2877
- const mode = this.getAttribute("mode");
2878
- const customisations = getCustomisations(this);
2879
- if (state.attrMode !== mode || haveCustomisationsChanged(state.customisations, customisations) || !findIconElement(this._shadowRoot)) {
2880
- this._renderIcon(state.icon, customisations, mode);
2881
- }
2882
- }
2883
- /**
2884
- * Icon value has changed
2885
- */
2886
- _iconChanged(newValue) {
2887
- const icon = parseIconValue(newValue, (value, name2, data) => {
2888
- const state = this._state;
2889
- if (state.rendered || this.getAttribute("icon") !== value) {
2890
- return;
2891
- }
2892
- const icon2 = {
2893
- value,
2894
- name: name2,
2895
- data
2896
- };
2897
- if (icon2.data) {
2898
- this._gotIconData(icon2);
2899
- } else {
2900
- state.icon = icon2;
2901
- }
2902
- });
2903
- if (icon.data) {
2904
- this._gotIconData(icon);
2905
- } else {
2906
- this._state = setPendingState(icon, this._state.inline, this._state);
2907
- }
2908
- }
2909
- /**
2910
- * Force render icon on state change
2911
- */
2912
- _forceRender() {
2913
- if (!this._visible) {
2914
- const node = findIconElement(this._shadowRoot);
2915
- if (node) {
2916
- this._shadowRoot.removeChild(node);
2917
- }
2918
- return;
2919
- }
2920
- this._queueCheck();
2921
- }
2922
- /**
2923
- * Got new icon data, icon is ready to (re)render
2924
- */
2925
- _gotIconData(icon) {
2926
- this._checkQueued = false;
2927
- this._renderIcon(icon, getCustomisations(this), this.getAttribute("mode"));
2928
- }
2929
- /**
2930
- * Re-render based on icon data
2931
- */
2932
- _renderIcon(icon, customisations, attrMode) {
2933
- const renderedMode = getRenderMode(icon.data.body, attrMode);
2934
- const inline = this._state.inline;
2935
- renderIcon(this._shadowRoot, this._state = {
2936
- rendered: true,
2937
- icon,
2938
- inline,
2939
- customisations,
2940
- attrMode,
2941
- renderedMode
2942
- });
2943
- }
2944
- /**
2945
- * Start observer
2946
- */
2947
- startObserver() {
2948
- if (!this._observer && !this.hasAttribute("noobserver")) {
2949
- try {
2950
- this._observer = new IntersectionObserver(entries => {
2951
- const intersecting = entries.some(entry => entry.isIntersecting);
2952
- if (intersecting !== this._visible) {
2953
- this._visible = intersecting;
2954
- this._forceRender();
2955
- }
2956
- });
2957
- this._observer.observe(this);
2958
- } catch (err) {
2959
- if (this._observer) {
2960
- try {
2961
- this._observer.disconnect();
2962
- } catch (err2) {}
2963
- this._observer = null;
2964
- }
2965
- }
2966
- }
2967
- }
2968
- /**
2969
- * Stop observer
2970
- */
2971
- stopObserver() {
2972
- if (this._observer) {
2973
- this._observer.disconnect();
2974
- this._observer = null;
2975
- this._visible = true;
2976
- if (this._connected) {
2977
- this._forceRender();
2978
- }
2979
- }
2980
- }
2981
- };
2982
- attributes.forEach(attr => {
2983
- if (!(attr in IconifyIcon2.prototype)) {
2984
- Object.defineProperty(IconifyIcon2.prototype, attr, {
2985
- get: function () {
2986
- return this.getAttribute(attr);
2987
- },
2988
- set: function (value) {
2989
- if (value !== null) {
2990
- this.setAttribute(attr, value);
2991
- } else {
2992
- this.removeAttribute(attr);
2993
- }
2994
- }
2995
- });
2996
- }
2997
- });
2998
- const functions = exportFunctions();
2999
- for (const key in functions) {
3000
- IconifyIcon2[key] = IconifyIcon2.prototype[key] = functions[key];
3001
- }
3002
- customElements.define(name, IconifyIcon2);
3003
- return IconifyIcon2;
3004
- }
3005
- var IconifyIconComponent = defineIconifyIcon() || exportFunctions();
3006
- var {
3007
- enableCache,
3008
- disableCache,
3009
- iconLoaded,
3010
- iconExists,
3011
- // deprecated, kept to avoid breaking changes
3012
- getIcon,
3013
- listIcons,
3014
- addIcon,
3015
- addCollection,
3016
- calculateSize,
3017
- buildIcon,
3018
- iconToHTML,
3019
- svgToURL,
3020
- loadIcons,
3021
- loadIcon,
3022
- addAPIProvider,
3023
- _api
3024
- } = IconifyIconComponent;
3025
-
3026
- // ../../node_modules/.pnpm/@iconify-icon+react@2.1.0_react@18.3.1/node_modules/@iconify-icon/react/dist/iconify.mjs
3027
- var Icon = import_react.default.forwardRef((props, ref) => {
3028
- const newProps = {
3029
- ...props,
3030
- ref
3031
- };
3032
- if (typeof props.icon === "object") {
3033
- newProps.icon = JSON.stringify(props.icon);
3034
- }
3035
- if (!props.inline) {
3036
- delete newProps.inline;
3037
- }
3038
- if (props.className) {
3039
- newProps["class"] = props.className;
3040
- }
3041
- return import_react.default.createElement("iconify-icon", newProps);
3042
- });
3043
-
3044
- // ../react-icons/src/Icon.tsx
3045
- var import_jsx_runtime21 = require("react/jsx-runtime");
3046
- var Icon2 = React4.forwardRef((props, ref) => {
3047
- return /* @__PURE__ */(0, import_jsx_runtime21.jsx)(Icon, {
3048
- ref,
3049
- "data-testid": "iconify-icon",
3050
- ...props
3051
- });
3052
- });
3053
- Icon2.displayName = "Icon";
3054
-
3055
- // src/MultistepForm/MultistepHeader.tsx
3056
- var import_jsx_runtime22 = require("react/jsx-runtime");
3057
- var MultistepHeaderTitled = ({
3058
- title,
3059
- leftIcon,
3060
- onLeftIconClick,
3061
- rightIcon,
3062
- onRightIconClick
3063
- }) => {
3064
- return /* @__PURE__ */(0, import_jsx_runtime22.jsxs)(import_ui18.Flex, {
3065
- sx: {
3066
- display: "flex",
3067
- justifyContent: "space-between",
3068
- paddingX: "xl",
3069
- paddingY: "lg",
3070
- alignItems: "center"
3071
- },
3072
- children: [/* @__PURE__ */(0, import_jsx_runtime22.jsx)(Icon2, {
3073
- icon: leftIcon,
3074
- onClick: onLeftIconClick
3075
- }), /* @__PURE__ */(0, import_jsx_runtime22.jsx)(import_ui18.Text, {
3076
- sx: {
3077
- fontWeight: "bold",
3078
- fontSize: "lg"
3079
- },
3080
- children: title
3081
- }), /* @__PURE__ */(0, import_jsx_runtime22.jsx)(Icon2, {
3082
- icon: rightIcon,
3083
- onClick: onRightIconClick
3084
- })]
3085
- });
3086
- };
3087
- var MultistepHeaderLogo = ({
3088
- onClose,
3089
- src
3090
- }) => {
3091
- return /* @__PURE__ */(0, import_jsx_runtime22.jsxs)(import_ui18.Flex, {
3092
- sx: {
3093
- justifyContent: "space-between",
3094
- alignItems: "center",
3095
- paddingX: "xl",
3096
- paddingY: "lg"
3097
- },
3098
- children: [/* @__PURE__ */(0, import_jsx_runtime22.jsx)(import_ui18.Image, {
3099
- width: 115,
3100
- height: 32,
3101
- sx: {
3102
- objectFit: "cover",
3103
- width: 115,
3104
- height: 32
3105
- },
3106
- src
3107
- }), onClose && /* @__PURE__ */(0, import_jsx_runtime22.jsx)(import_ui18.CloseButton, {
3108
- onClick: onClose
3109
- })]
3110
- });
3111
- };
3112
- var MultistepHeader = props => {
3113
- if (props.variant === "logo") {
3114
- return /* @__PURE__ */(0, import_jsx_runtime22.jsx)(MultistepHeaderLogo, {
3115
- ...props
3116
- });
3117
- }
3118
- if (props.variant === "titled") {
3119
- return /* @__PURE__ */(0, import_jsx_runtime22.jsx)(MultistepHeaderTitled, {
3120
- ...props
3121
- });
3122
- }
3123
- return null;
3124
- };
3125
-
3126
- // src/MultistepForm/MultistepNavigation.tsx
3127
- var import_ui19 = require("@ttoss/ui");
3128
- var import_jsx_runtime23 = require("react/jsx-runtime");
3129
- var MultistepNavigation = ({
3130
- amountOfSteps,
3131
- currentStepNumber,
3132
- onBack,
3133
- stepsLabel
3134
- }) => {
3135
- return /* @__PURE__ */(0, import_jsx_runtime23.jsxs)(import_ui19.Flex, {
3136
- sx: {
3137
- justifyContent: "space-between",
3138
- marginX: "2xl"
3139
- },
3140
- children: [/* @__PURE__ */(0, import_jsx_runtime23.jsxs)(import_ui19.Flex, {
3141
- onClick: onBack,
3142
- sx: {
3143
- alignItems: "center",
3144
- cursor: "pointer"
3145
- },
3146
- children: [/* @__PURE__ */(0, import_jsx_runtime23.jsx)(import_ui19.Text, {
3147
- sx: {
3148
- color: "#ACADB7",
3149
- display: "flex"
3150
- },
3151
- children: /* @__PURE__ */(0, import_jsx_runtime23.jsx)(Icon2, {
3152
- icon: "nav-left"
3153
- })
3154
- }), /* @__PURE__ */(0, import_jsx_runtime23.jsx)(import_ui19.Text, {
3155
- sx: {
3156
- color: "#ACADB7"
3157
- },
3158
- children: stepsLabel[currentStepNumber - 2]
3159
- })]
3160
- }), /* @__PURE__ */(0, import_jsx_runtime23.jsxs)(import_ui19.Text, {
3161
- sx: {
3162
- alignItems: "center",
3163
- color: "#ACADB7"
3164
- },
3165
- children: [currentStepNumber, "/", amountOfSteps]
3166
- })]
3167
- });
3168
- };
3169
-
3170
- // src/MultistepForm/MultistepForm.tsx
3171
- var import_jsx_runtime24 = require("react/jsx-runtime");
3172
- var MultistepForm = ({
3173
- nextStepButtonLabel = "Next",
3174
- submitButtonLabel = "Send",
3175
- ...props
3176
- }) => {
3177
- const amountOfSteps = props.steps.length;
3178
- const [currentStep, setCurrentStep] = React5.useState(1);
3179
- const [form, setForm] = React5.useState({});
3180
- const nextStep = () => {
3181
- if (currentStep < amountOfSteps) {
3182
- setCurrentStep(step => {
3183
- return step + 1;
3184
- });
3185
- }
3186
- };
3187
- const backStep = () => {
3188
- if (currentStep > 1) {
3189
- setCurrentStep(step => {
3190
- return step - 1;
3191
- });
3192
- }
3193
- };
3194
- return /* @__PURE__ */(0, import_jsx_runtime24.jsxs)(import_ui20.Flex, {
3195
- sx: {
3196
- flexDirection: "column",
3197
- maxWidth: "390px",
3198
- background: "#fff"
3199
- },
3200
- children: [/* @__PURE__ */(0, import_jsx_runtime24.jsx)(MultistepHeader, {
3201
- ...props.header
3202
- }), props.steps.map((step, stepIndex) => {
3203
- const isLastStep = stepIndex + 1 === amountOfSteps;
3204
- const isCurrentStep = stepIndex + 1 === currentStep;
3205
- return /* @__PURE__ */(0, import_jsx_runtime24.jsx)(import_ui20.Flex, {
3206
- sx: {
3207
- flexDirection: "column",
3208
- display: isCurrentStep ? "flex" : "none"
3209
- },
3210
- "aria-hidden": !isCurrentStep,
3211
- children: /* @__PURE__ */(0, import_jsx_runtime24.jsx)(MultistepFormStepper, {
3212
- ...step,
3213
- stepNumber: stepIndex + 1,
3214
- isLastStep,
3215
- onSubmit: data => {
3216
- const newValue = {
3217
- ...form,
3218
- ...data
3219
- };
3220
- setForm(newValue);
3221
- if (isLastStep) {
3222
- props.onSubmit(newValue);
3223
- } else {
3224
- nextStep();
3225
- }
3226
- },
3227
- submitLabel: isLastStep ? submitButtonLabel : nextStepButtonLabel
3228
- })
3229
- }, `form-step-${step.question}`);
3230
- }), currentStep > 1 && /* @__PURE__ */(0, import_jsx_runtime24.jsx)(MultistepNavigation, {
3231
- amountOfSteps,
3232
- currentStepNumber: currentStep,
3233
- onBack: backStep,
3234
- stepsLabel: props.steps.map(s => {
3235
- return s.label;
3236
- })
3237
- }), props.footer && /* @__PURE__ */(0, import_jsx_runtime24.jsx)(MultistepFooter, {
3238
- footer: props.footer
3239
- })]
3240
- });
3241
- };
3242
- // Annotate the CommonJS export names for ESM import in node:
3243
- 0 && (module.exports = {
3244
- MultistepForm
3245
- });
3246
- /*! Bundled license information:
3247
-
3248
- iconify-icon/dist/iconify-icon.mjs:
3249
- (**
3250
- * (c) Iconify
3251
- *
3252
- * For the full copyright and license information, please view the license.txt
3253
- * files at https://github.com/iconify/iconify
3254
- *
3255
- * Licensed under MIT.
3256
- *
3257
- * @license MIT
3258
- * @version 2.1.0
3259
- *)
3260
- */