@progress/kendo-react-inputs 9.0.0-develop.2 → 9.0.0-develop.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +63 -62
  2. package/colors/ColorContrastLabels.mjs +10 -1
  3. package/colors/ColorContrastSvg.mjs +14 -2
  4. package/colors/ColorInput.js +1 -1
  5. package/colors/ColorInput.mjs +15 -12
  6. package/colors/ColorPalette.js +1 -1
  7. package/colors/ColorPalette.mjs +13 -14
  8. package/colors/ColorPicker.mjs +62 -79
  9. package/colors/FlatColorPicker.mjs +68 -22
  10. package/colors/HexInput.js +1 -1
  11. package/colors/HexInput.mjs +9 -8
  12. package/colors/models/palette-presets.mjs +656 -12
  13. package/colors/utils/color-cache.js +1 -1
  14. package/colors/utils/color-cache.mjs +3 -6
  15. package/colors/utils/color-parser.js +1 -1
  16. package/colors/utils/color-parser.mjs +2 -5
  17. package/dist/cdn/js/kendo-react-inputs.js +1 -1
  18. package/index.d.mts +21 -87
  19. package/index.d.ts +21 -87
  20. package/index.js +1 -1
  21. package/index.mjs +65 -66
  22. package/input/Input.js +1 -1
  23. package/input/Input.mjs +144 -179
  24. package/input/InputClearValue.mjs +6 -11
  25. package/input/InputPrefix.mjs +17 -18
  26. package/input/InputSeparator.mjs +12 -10
  27. package/input/InputSuffix.mjs +17 -18
  28. package/input/InputValidationIcon.mjs +3 -1
  29. package/maskedtextbox/masking.service.js +1 -1
  30. package/maskedtextbox/masking.service.mjs +2 -2
  31. package/maskedtextbox/parsing/parsers.js +1 -1
  32. package/maskedtextbox/parsing/parsers.mjs +22 -23
  33. package/numerictextbox/NumericTextBox.mjs +259 -320
  34. package/numerictextbox/utils/index.mjs +16 -14
  35. package/package-metadata.mjs +1 -1
  36. package/package.json +9 -9
  37. package/radiobutton/RadioButton.mjs +7 -18
  38. package/radiobutton/RadioGroup.mjs +3 -6
  39. package/range-slider/RangeSlider.mjs +68 -62
  40. package/rating/Rating.mjs +73 -90
  41. package/rating/RatingItem.mjs +29 -50
  42. package/signature/Signature.mjs +60 -93
  43. package/slider/SliderLabel.mjs +6 -10
  44. package/switch/Switch.mjs +9 -5
  45. package/textarea/TextArea.mjs +19 -47
  46. package/textbox/Textbox.mjs +37 -55
package/input/Input.mjs CHANGED
@@ -6,192 +6,157 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  "use client";
9
- import * as o from "react";
10
- import i from "prop-types";
11
- import { validatePackage as C, classNames as M, uInput as S, createPropsContext as I, withIdHOC as L, withPropsContext as V, withUnstyledHOC as N } from "@progress/kendo-react-common";
12
- import { FloatingLabel as P } from "@progress/kendo-react-labels";
13
- import { packageMetadata as D } from "../package-metadata.mjs";
14
- const s = class s extends o.Component {
15
- constructor(e) {
16
- super(e), this._input = null, this.focus = () => {
17
- this._input && this._input.focus();
18
- }, this.isInvalid = (t) => {
19
- let a = !1;
20
- for (let l in t)
21
- t.hasOwnProperty(l) && (a = a || !!t[l]);
22
- return a;
23
- }, this.setValidity = () => {
24
- this._input && this._input.setCustomValidity && (this.validity.valid || !this.validityStyles ? this._input.classList.remove("k-invalid") : this._input.classList.add("k-invalid"), this._input.setCustomValidity(
25
- this.validity.valid ? "" : this.props.validationMessage || ""
26
- ));
27
- }, this.handleChange = (t) => {
28
- this.setState({
29
- value: t.target.value
30
- }), this.valueDuringOnChange = t.target.value, this.props.onChange && this.props.onChange.call(void 0, {
31
- syntheticEvent: t,
32
- nativeEvent: t.nativeEvent,
33
- value: t.target.value,
34
- target: this
35
- }), this.valueDuringOnChange = void 0;
36
- }, this.handleAutoFill = (t) => {
37
- if (t.animationName === "autoFillStart") {
38
- let a = t.target.parentNode;
39
- a && a.classList.contains("k-empty") && a.classList.remove("k-empty");
40
- }
41
- }, C(D), this.state = {
42
- value: this.props.defaultValue || s.defaultProps.defaultValue
43
- };
44
- }
45
- get _inputId() {
46
- return this.props.id;
47
- }
48
- /**
49
- * Gets the native input element of the Input component.
50
- */
51
- get element() {
52
- return this._input;
53
- }
54
- /**
55
- * Gets the value of the Input.
56
- */
57
- get value() {
58
- return this.valueDuringOnChange !== void 0 ? this.valueDuringOnChange : this.props.value !== void 0 ? this.props.value : this.state.value;
59
- }
60
- /**
61
- * Gets the `name` property of the Input.
62
- */
63
- get name() {
64
- return this.props.name;
65
- }
66
- /**
67
- * Represents the validity state into which the Input is set.
68
- */
69
- get validity() {
70
- const e = {
71
- badInput: this._input ? this._input.validity.badInput : !1,
72
- patternMismatch: this._input ? this._input.validity.patternMismatch : !1,
73
- rangeOverflow: this._input ? this._input.validity.rangeOverflow : !1,
74
- rangeUnderflow: this._input ? this._input.validity.rangeUnderflow : !1,
75
- stepMismatch: this._input ? this._input.validity.stepMismatch : !1,
76
- tooLong: this._input ? this._input.validity.tooLong : !1,
77
- typeMismatch: this._input ? this._input.validity.typeMismatch : !1,
78
- valueMissing: this._input ? this._input.validity.valueMissing : !1
9
+ import * as r from "react";
10
+ import a from "prop-types";
11
+ import { validatePackage as J, applyDefaultProps as Q, useUnstyled as W, useId as X, classNames as Y, uInput as Z, createPropsContext as _ } from "@progress/kendo-react-common";
12
+ import { FloatingLabel as $ } from "@progress/kendo-react-labels";
13
+ import { packageMetadata as ee } from "../package-metadata.mjs";
14
+ const I = r.forwardRef((L, M) => {
15
+ const P = r.useContext(te).call(void 0, L);
16
+ J(ee);
17
+ const [, x] = r.useReducer((t) => t, !0), i = Q(P, ae), {
18
+ className: E,
19
+ label: o,
20
+ labelClassName: N,
21
+ id: k,
22
+ validationMessage: v,
23
+ defaultValue: R,
24
+ valid: p,
25
+ unstyled: f,
26
+ // Removed to support direct use in Form Field component
27
+ visited: ie,
28
+ touched: ne,
29
+ modified: se,
30
+ autoFocus: V,
31
+ ariaLabelledBy: w,
32
+ ariaDescribedBy: F,
33
+ validityStyles: m,
34
+ style: y,
35
+ ariaLabel: U,
36
+ ...B
37
+ } = i, D = W(), g = f || D, O = g && g.uInput, S = X(), [T, q] = r.useState({
38
+ value: R
39
+ }), b = k || S, e = r.useRef(null), s = r.useRef(void 0), u = r.useRef(null), A = () => {
40
+ e.current && e.current.focus();
41
+ }, c = () => s.current !== void 0 ? s.current : i.value !== void 0 ? i.value : T.value, l = () => {
42
+ const t = {
43
+ badInput: e.current ? e.current.validity.badInput : !1,
44
+ patternMismatch: e.current ? e.current.validity.patternMismatch : !1,
45
+ rangeOverflow: e.current ? e.current.validity.rangeOverflow : !1,
46
+ rangeUnderflow: e.current ? e.current.validity.rangeUnderflow : !1,
47
+ stepMismatch: e.current ? e.current.validity.stepMismatch : !1,
48
+ tooLong: e.current ? e.current.validity.tooLong : !1,
49
+ typeMismatch: e.current ? e.current.validity.typeMismatch : !1,
50
+ valueMissing: e.current ? e.current.validity.valueMissing : !1
79
51
  };
80
52
  return {
81
- ...e,
82
- customError: this.props.validationMessage !== void 0,
83
- valid: this.props.valid !== void 0 ? this.props.valid : this._input ? !this.isInvalid(e) : !0
53
+ ...t,
54
+ customError: v !== void 0,
55
+ valid: p !== void 0 ? p : e.current ? !G(t) : !0
84
56
  };
85
- }
86
- /**
87
- * @hidden
88
- */
89
- get validityStyles() {
90
- return this.props.validityStyles !== void 0 ? this.props.validityStyles : s.defaultProps.validityStyles;
91
- }
92
- /**
93
- * @hidden
94
- */
95
- componentDidMount() {
96
- this.forceUpdate();
97
- }
98
- /**
99
- * @hidden
100
- */
101
- componentDidUpdate() {
102
- this.setValidity();
103
- }
104
- /**
105
- * @hidden
106
- */
107
- render() {
108
- const {
109
- className: e,
110
- label: t,
111
- labelClassName: a,
112
- id: l,
113
- validationMessage: F,
114
- defaultValue: k,
115
- valid: E,
116
- unstyled: r,
117
- // Removed to support direct use in Form Field component
118
- visited: B,
119
- touched: U,
120
- modified: x,
121
- autoFocus: c,
122
- ariaLabelledBy: y,
123
- ariaDescribedBy: g,
124
- validityStyles: A,
125
- style: u,
126
- ariaLabel: m,
127
- ...n
128
- } = this.props, h = l || this._inputId, d = !this.validityStyles || this.validity.valid, f = r && r.uInput, b = M(e, S.input(
129
- {
130
- c: f,
131
- invalid: !d,
132
- disabled: this.props.disabled
133
- }
134
- )), v = /* @__PURE__ */ o.createElement(
135
- "input",
136
- {
137
- "aria-labelledby": y,
138
- "aria-describedby": g,
139
- "aria-disabled": this.props.disabled || void 0,
140
- "aria-invalid": !d || void 0,
141
- "aria-label": m || void 0,
142
- ...n,
143
- style: t ? void 0 : u,
144
- value: this.value,
145
- id: h,
146
- autoFocus: c,
147
- className: b,
148
- onChange: this.handleChange,
149
- onAnimationStart: this.handleAutoFill,
150
- ref: (_) => {
151
- this._input = _;
152
- }
153
- }
154
- );
155
- return t ? /* @__PURE__ */ o.createElement(
156
- P,
157
- {
158
- label: t,
159
- labelClassName: a,
160
- editorId: h,
161
- editorValue: String(this.value),
162
- editorValid: d,
163
- editorDisabled: n.disabled,
164
- editorPlaceholder: n.placeholder,
165
- children: v,
166
- style: u,
167
- dir: n.dir,
168
- unstyled: r
169
- }
170
- ) : v;
171
- }
172
- };
173
- s.displayName = "Input", s.propTypes = {
174
- label: i.string,
175
- labelClassName: i.string,
176
- validationMessage: i.string,
177
- required: i.bool,
178
- validate: i.bool,
179
- id: i.string,
180
- ariaLabelledBy: i.string,
181
- ariaDescribedBy: i.string,
182
- ariaLabel: i.string,
183
- autoFocus: i.bool
184
- }, s.defaultProps = {
57
+ };
58
+ r.useImperativeHandle(u, () => ({
59
+ element: e.current,
60
+ props: i,
61
+ get value() {
62
+ return c();
63
+ },
64
+ name: i.name,
65
+ get validity() {
66
+ return l();
67
+ },
68
+ focus: A
69
+ })), r.useImperativeHandle(M, () => u.current);
70
+ const G = (t) => {
71
+ let n = !1;
72
+ for (const C in t)
73
+ t.hasOwnProperty(C) && (n = n || !!t[C]);
74
+ return n;
75
+ }, d = !m || l().valid, H = Y(
76
+ E,
77
+ Z.input({
78
+ c: O,
79
+ invalid: !d,
80
+ disabled: i.disabled
81
+ })
82
+ ), K = () => {
83
+ e.current && e.current.setCustomValidity && (l().valid || !m ? e.current.classList.remove("k-invalid") : e.current.classList.add("k-invalid"), e.current.setCustomValidity(l().valid ? "" : v || ""));
84
+ }, j = (t) => {
85
+ q({
86
+ value: t.target.value
87
+ }), s.current = t.target.value, i.onChange && i.onChange.call(void 0, {
88
+ syntheticEvent: t,
89
+ nativeEvent: t.nativeEvent,
90
+ value: t.target.value,
91
+ target: u.current
92
+ }), s.current = void 0;
93
+ }, z = (t) => {
94
+ if (t.animationName === "autoFillStart") {
95
+ const n = t.target.parentNode;
96
+ n && n.classList.contains("k-empty") && n.classList.remove("k-empty");
97
+ }
98
+ };
99
+ r.useEffect(() => {
100
+ x();
101
+ }, []), r.useEffect(() => {
102
+ K();
103
+ });
104
+ const h = /* @__PURE__ */ r.createElement(
105
+ "input",
106
+ {
107
+ "aria-labelledby": w,
108
+ "aria-describedby": F,
109
+ "aria-disabled": i.disabled || void 0,
110
+ "aria-invalid": !d || void 0,
111
+ "aria-label": U || void 0,
112
+ ...B,
113
+ style: o ? void 0 : y,
114
+ value: c(),
115
+ id: b,
116
+ autoFocus: V,
117
+ className: H,
118
+ onChange: j,
119
+ onAnimationStart: z,
120
+ ref: e
121
+ }
122
+ );
123
+ return o ? /* @__PURE__ */ r.createElement(
124
+ $,
125
+ {
126
+ label: o,
127
+ labelClassName: N,
128
+ editorId: b,
129
+ editorValue: String(c()),
130
+ editorValid: d,
131
+ editorDisabled: i.disabled,
132
+ editorPlaceholder: i.placeholder,
133
+ children: h,
134
+ style: y,
135
+ dir: i.dir,
136
+ unstyled: f
137
+ }
138
+ ) : h;
139
+ }), te = _(), ae = {
185
140
  defaultValue: "",
186
141
  required: !1,
187
142
  validityStyles: !0,
188
143
  autoFocus: !1
189
144
  };
190
- let p = s;
191
- const O = I(), w = L(V(O, N(p)));
192
- w.displayName = "KendoReactInput";
145
+ I.displayName = "KendoReactInput";
146
+ I.propTypes = {
147
+ label: a.string,
148
+ labelClassName: a.string,
149
+ validationMessage: a.string,
150
+ required: a.bool,
151
+ validate: a.bool,
152
+ id: a.string,
153
+ ariaLabelledBy: a.string,
154
+ ariaDescribedBy: a.string,
155
+ ariaLabel: a.string,
156
+ autoFocus: a.bool,
157
+ value: a.oneOfType([a.string, a.number, a.array])
158
+ };
193
159
  export {
194
- w as Input,
195
- O as InputPropsContext,
196
- p as InputWithoutContext
160
+ I as Input,
161
+ te as InputPropsContext
197
162
  };
@@ -9,18 +9,13 @@
9
9
  import * as e from "react";
10
10
  import { useUnstyled as c, classNames as m, uInput as o } from "@progress/kendo-react-common";
11
11
  const p = e.forwardRef((t, a) => {
12
- const n = e.useRef(null), l = e.useRef(null), s = c(), u = s && s.uInput, r = m(o.clearButton(
13
- {
12
+ const n = e.useRef(null), l = e.useRef(null), s = c(), u = s && s.uInput, r = m(
13
+ o.clearButton({
14
14
  c: u
15
- }
16
- ), t.className);
17
- return e.useImperativeHandle(
18
- n,
19
- () => ({ element: l.current })
20
- ), e.useImperativeHandle(
21
- a,
22
- () => n.current
23
- ), /* @__PURE__ */ e.createElement("span", { ...t, className: r });
15
+ }),
16
+ t.className
17
+ );
18
+ return e.useImperativeHandle(n, () => ({ element: l.current })), e.useImperativeHandle(a, () => n.current), /* @__PURE__ */ e.createElement("span", { ...t, className: r });
24
19
  });
25
20
  p.displayName = "KendoReactInputClearValue";
26
21
  export {
@@ -8,24 +8,23 @@
8
8
  "use client";
9
9
  import * as e from "react";
10
10
  import { useUnstyled as u, classNames as o, uTextBox as x } from "@progress/kendo-react-common";
11
- const f = e.forwardRef(({ orientation: t = "horizontal", ...s }, r) => {
12
- const a = e.useRef(null), c = e.useRef(null), n = u(), l = n && n.uTextBox;
13
- e.useImperativeHandle(
14
- a,
15
- () => ({ element: c.current })
16
- ), e.useImperativeHandle(
17
- r,
18
- () => a.current
19
- );
20
- const m = e.useMemo(
21
- () => o(x.prefix({
22
- c: l,
23
- orientation: t
24
- }), s.className),
25
- [s.className, l, t]
26
- );
27
- return /* @__PURE__ */ e.createElement("span", { ...s, className: m });
28
- });
11
+ const f = e.forwardRef(
12
+ ({ orientation: t = "horizontal", ...s }, r) => {
13
+ const a = e.useRef(null), c = e.useRef(null), n = u(), l = n && n.uTextBox;
14
+ e.useImperativeHandle(a, () => ({ element: c.current })), e.useImperativeHandle(r, () => a.current);
15
+ const m = e.useMemo(
16
+ () => o(
17
+ x.prefix({
18
+ c: l,
19
+ orientation: t
20
+ }),
21
+ s.className
22
+ ),
23
+ [s.className, l, t]
24
+ );
25
+ return /* @__PURE__ */ e.createElement("span", { ...s, className: m });
26
+ }
27
+ );
29
28
  f.displayName = "KendoReactInputPrefix";
30
29
  export {
31
30
  f as InputPrefix
@@ -8,16 +8,18 @@
8
8
  "use client";
9
9
  import * as e from "react";
10
10
  import { classNames as l } from "@progress/kendo-react-common";
11
- const u = e.forwardRef(({ orientation: r = "vertical", ...t }, n) => {
12
- const a = e.useRef(null), s = e.useRef(null);
13
- return e.useImperativeHandle(
14
- a,
15
- () => ({ element: s.current })
16
- ), e.useImperativeHandle(
17
- n,
18
- () => a.current
19
- ), /* @__PURE__ */ e.createElement("span", { ...t, className: l("k-input-separator", t.className, `k-input-separator-${r}`) });
20
- });
11
+ const u = e.forwardRef(
12
+ ({ orientation: r = "vertical", ...t }, n) => {
13
+ const a = e.useRef(null), s = e.useRef(null);
14
+ return e.useImperativeHandle(a, () => ({ element: s.current })), e.useImperativeHandle(n, () => a.current), /* @__PURE__ */ e.createElement(
15
+ "span",
16
+ {
17
+ ...t,
18
+ className: l("k-input-separator", t.className, `k-input-separator-${r}`)
19
+ }
20
+ );
21
+ }
22
+ );
21
23
  u.displayName = "KendoReactInputSeparator";
22
24
  export {
23
25
  u as InputSeparator
@@ -8,24 +8,23 @@
8
8
  "use client";
9
9
  import * as e from "react";
10
10
  import { useUnstyled as o, classNames as r, uTextBox as f } from "@progress/kendo-react-common";
11
- const x = e.forwardRef(({ orientation: t = "horizontal", ...s }, u) => {
12
- const a = e.useRef(null), c = e.useRef(null), n = o(), l = n && n.uTextBox;
13
- e.useImperativeHandle(
14
- a,
15
- () => ({ element: c.current })
16
- ), e.useImperativeHandle(
17
- u,
18
- () => a.current
19
- );
20
- const m = e.useMemo(
21
- () => r(f.suffix({
22
- c: l,
23
- orientation: t
24
- }), s.className),
25
- [s.className, l, t]
26
- );
27
- return /* @__PURE__ */ e.createElement("span", { ...s, className: m });
28
- });
11
+ const x = e.forwardRef(
12
+ ({ orientation: t = "horizontal", ...s }, u) => {
13
+ const a = e.useRef(null), c = e.useRef(null), n = o(), l = n && n.uTextBox;
14
+ e.useImperativeHandle(a, () => ({ element: c.current })), e.useImperativeHandle(u, () => a.current);
15
+ const m = e.useMemo(
16
+ () => r(
17
+ f.suffix({
18
+ c: l,
19
+ orientation: t
20
+ }),
21
+ s.className
22
+ ),
23
+ [s.className, l, t]
24
+ );
25
+ return /* @__PURE__ */ e.createElement("span", { ...s, className: m });
26
+ }
27
+ );
29
28
  x.displayName = "KendoReactInputSuffix";
30
29
  export {
31
30
  x as InputSuffix
@@ -8,7 +8,9 @@
8
8
  "use client";
9
9
  import { IconWrap as n, classNames as o } from "@progress/kendo-react-common";
10
10
  import * as e from "react";
11
- const c = e.forwardRef((a, t) => /* @__PURE__ */ e.createElement(n, { ref: t, ...a, className: o("k-input-validation-icon", a.className) }));
11
+ const c = e.forwardRef(
12
+ (a, t) => /* @__PURE__ */ e.createElement(n, { ref: t, ...a, className: o("k-input-validation-icon", a.className) })
13
+ );
12
14
  c.displayName = "KendoReactInputValidationIcon";
13
15
  export {
14
16
  c as InputValidationIcon
@@ -5,4 +5,4 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./parsing/combinators.js"),a=require("./parsing/parsers.js");class u{constructor(){this.rules={},this.prompt="_",this.mask="",this.promptPlaceholder=" ",this.includeLiterals=!1,this.maskTokens=[],this.unmaskTokens=[],this.rawTokens=[],this.validationTokens=[]}update({mask:e="",prompt:s="",promptPlaceholder:t=" ",rules:r={},includeLiterals:n=!1}){this.mask=e,this.prompt=s,this.promptPlaceholder=t,this.rules=r,this.includeLiterals=n,this.tokenize()}validationValue(e=""){let s=e;return i.sequence(this.validationTokens).run(e).fold(t=>{s=t.join("")}),s}rawValue(e=""){let s=e;return this.rawTokens.length&&i.sequence(this.rawTokens).run(e).fold(t=>{s=t.join("")}),s}maskRaw(e=""){let s=e;return this.maskTokens.length&&i.sequence(this.maskTokens).run(e).fold(t=>{s=t.join("")}),s}maskInput(e,s,t){return e.length<s.length?this.maskRemoved(e,s,t):this.maskInserted(e,s,t)}maskInRange(e,s,t,r){let n="",l=r;const o=s.split("").slice(0,t),h=s.split("").slice(r);return i.sequence(this.maskTokens.slice(t,r)).run(e).fold(k=>{n=o.concat(k).concat(h).join("")}),{selection:l,value:n}}maskRemoved(e,s,t){let r="",n=t;const l=e.split("").slice(t),o=e.split("").slice(0,t).join(""),h=this.maskTokens.length-(e.length-t);return i.sequence(this.maskTokens.slice(0,h)).run(o,s).fold(k=>{n=this.adjustPosition(k,n),r=k.concat(l).join("")}),{selection:n,value:r}}adjustPosition(e,s){const t=e[s];return!this.maskTokens[s].isLiteral(t)&&t!==this.prompt?s+1:s}maskInserted(e,s,t){let r="",n=t;const l=e.slice(0,t);return i.sequence(this.unmaskTokens).run(l,s).chain(o=>{n=o.join("").length;const h=s.slice(n);return i.sequence(this.maskTokens).run(o.join("")+h,s)}).fold(o=>{r=o.join("")}),{selection:n,value:r}}get maskTokenCreator(){const{prompt:e,promptPlaceholder:s}=this;return{literal:t=>a.literal(t),mask:t=>a.mask({prompt:e,promptPlaceholder:s})(t)}}get unmaskTokenCreator(){return{literal:e=>a.unliteral(e),mask:e=>a.unmask(this.prompt)(e)}}get rawTokenCreator(){const{prompt:e,promptPlaceholder:s,includeLiterals:t}=this;return{literal:r=>a.rawLiteral(t),mask:r=>a.rawMask({prompt:e,promptPlaceholder:s})}}get validationTokenCreator(){const{prompt:e}=this;return{literal:s=>a.rawLiteral(!1),mask:s=>a.rawMask({prompt:e,promptPlaceholder:""})}}tokenize(){i.greedy(a.token(this.rules,this.maskTokenCreator)).run(this.mask).fold((e,s)=>{this.maskTokens=e}),i.greedy(a.token(this.rules,this.unmaskTokenCreator)).run(this.mask).fold((e,s)=>{this.unmaskTokens=e}),i.greedy(a.token(this.rules,this.rawTokenCreator)).run(this.mask).fold((e,s)=>{this.rawTokens=e}),i.greedy(a.token(this.rules,this.validationTokenCreator)).run(this.mask).fold((e,s)=>{this.validationTokens=e})}}exports.MaskingService=u;
8
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./parsing/combinators.js"),a=require("./parsing/parsers.js");class u{constructor(){this.rules={},this.prompt="_",this.mask="",this.promptPlaceholder=" ",this.includeLiterals=!1,this.maskTokens=[],this.unmaskTokens=[],this.rawTokens=[],this.validationTokens=[]}update({mask:e="",prompt:s="",promptPlaceholder:t=" ",rules:r={},includeLiterals:n=!1}){this.mask=e,this.prompt=s,this.promptPlaceholder=t,this.rules=r,this.includeLiterals=n,this.tokenize()}validationValue(e=""){let s=e;return i.sequence(this.validationTokens).run(e).fold(t=>{s=t.join("")}),s}rawValue(e=""){let s=e;return this.rawTokens.length&&i.sequence(this.rawTokens).run(e).fold(t=>{s=t.join("")}),s}maskRaw(e=""){let s=e;return this.maskTokens.length&&i.sequence(this.maskTokens).run(e).fold(t=>{s=t.join("")}),s}maskInput(e,s,t){return e.length<s.length?this.maskRemoved(e,s,t):this.maskInserted(e,s,t)}maskInRange(e,s,t,r){let n="";const l=r,o=s.split("").slice(0,t),h=s.split("").slice(r);return i.sequence(this.maskTokens.slice(t,r)).run(e).fold(k=>{n=o.concat(k).concat(h).join("")}),{selection:l,value:n}}maskRemoved(e,s,t){let r="",n=t;const l=e.split("").slice(t),o=e.split("").slice(0,t).join(""),h=this.maskTokens.length-(e.length-t);return i.sequence(this.maskTokens.slice(0,h)).run(o,s).fold(k=>{n=this.adjustPosition(k,n),r=k.concat(l).join("")}),{selection:n,value:r}}adjustPosition(e,s){const t=e[s];return!this.maskTokens[s].isLiteral(t)&&t!==this.prompt?s+1:s}maskInserted(e,s,t){let r="",n=t;const l=e.slice(0,t);return i.sequence(this.unmaskTokens).run(l,s).chain(o=>{n=o.join("").length;const h=s.slice(n);return i.sequence(this.maskTokens).run(o.join("")+h,s)}).fold(o=>{r=o.join("")}),{selection:n,value:r}}get maskTokenCreator(){const{prompt:e,promptPlaceholder:s}=this;return{literal:t=>a.literal(t),mask:t=>a.mask({prompt:e,promptPlaceholder:s})(t)}}get unmaskTokenCreator(){return{literal:e=>a.unliteral(e),mask:e=>a.unmask(this.prompt)(e)}}get rawTokenCreator(){const{prompt:e,promptPlaceholder:s,includeLiterals:t}=this;return{literal:r=>a.rawLiteral(t),mask:r=>a.rawMask({prompt:e,promptPlaceholder:s})}}get validationTokenCreator(){const{prompt:e}=this;return{literal:s=>a.rawLiteral(!1),mask:s=>a.rawMask({prompt:e,promptPlaceholder:""})}}tokenize(){i.greedy(a.token(this.rules,this.maskTokenCreator)).run(this.mask).fold((e,s)=>{this.maskTokens=e}),i.greedy(a.token(this.rules,this.unmaskTokenCreator)).run(this.mask).fold((e,s)=>{this.unmaskTokens=e}),i.greedy(a.token(this.rules,this.rawTokenCreator)).run(this.mask).fold((e,s)=>{this.rawTokens=e}),i.greedy(a.token(this.rules,this.validationTokenCreator)).run(this.mask).fold((e,s)=>{this.validationTokens=e})}}exports.MaskingService=u;
@@ -40,8 +40,8 @@ class C {
40
40
  return e.length < s.length ? this.maskRemoved(e, s, t) : this.maskInserted(e, s, t);
41
41
  }
42
42
  maskInRange(e, s, t, r) {
43
- let n = "", o = r;
44
- const a = s.split("").slice(0, t), l = s.split("").slice(r);
43
+ let n = "";
44
+ const o = r, a = s.split("").slice(0, t), l = s.split("").slice(r);
45
45
  return i(this.maskTokens.slice(t, r)).run(e).fold((h) => {
46
46
  n = a.concat(h).concat(l).join("");
47
47
  }), {
@@ -5,4 +5,4 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./result.js"),o=require("./stream.js"),w=r=>(r||"").split(""),a="\\";class s{constructor(t){this.parse=t}run(t,e=""){return t instanceof o.Stream?this.parse(t):this.parse(new o.Stream(w(t),w(e)))}map(t){return new s(e=>this.parse(e).map(t))}chain(t){return new s(e=>this.parse(e).chain((l,u)=>t(l).run(u)))}isLiteral(t){return this.run(t).type===n.ResultType.Literal}}const p=r=>t=>new s(e=>{const{prompt:l,promptPlaceholder:u}=r;for(;!e.eof();){const{char:i,control:c}=e.peek();if(i===c&&c===l)return e.eat(),new n.Result(l,e,n.ResultType.Mask);if(t.test(i))return e.eat(),new n.Result(i,e,n.ResultType.Mask);if(i===u)return e.eat(),new n.Result(l,e,n.ResultType.Mask);e.eat_input()}return e.eat(),new n.Result(l,e,n.ResultType.Mask)}),R=r=>new s(t=>t.peek().char===r?(t.eat(),new n.Result(r,t,n.ResultType.Literal)):new n.Result(r,t,n.ResultType.Literal)),h=r=>t=>new s(e=>{for(;!e.eof();){const{char:l,control:u}=e.peek();if(l===r&&u===r)return e.eat(),new n.Result(l,e);if(t.test(l))return e.eat(),new n.Result(l,e);e.eat_input()}return e.eat(),new n.Result("",e)}),f=r=>new s(t=>{if(t.eof())return new n.Result("",t);const{char:e}=t.peek();return e===r&&t.eat(),new n.Result(r,t)}),k=(r,t)=>new s(e=>{let{char:l}=e.next();const u=r[l];return l===a?(l=e.next().char,new n.Result(t.literal(l),e)):u?new n.Result(t.mask(u),e):new n.Result(t.literal(l),e)}),y=r=>new s(t=>{const{prompt:e,promptPlaceholder:l}=r;let{char:u}=t.next();return u===e?new n.Result(l,t):new n.Result(u,t)}),T=r=>new s(t=>{let{char:e}=t.next();return r?new n.Result(e,t):new n.Result("",t)});exports.Parser=s;exports.literal=R;exports.mask=p;exports.rawLiteral=T;exports.rawMask=y;exports.token=k;exports.unliteral=f;exports.unmask=h;
8
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./result.js"),o=require("./stream.js"),w=r=>(r||"").split(""),a="\\";class s{constructor(t){this.parse=t}run(t,e=""){return t instanceof o.Stream?this.parse(t):this.parse(new o.Stream(w(t),w(e)))}map(t){return new s(e=>this.parse(e).map(t))}chain(t){return new s(e=>this.parse(e).chain((u,l)=>t(u).run(l)))}isLiteral(t){return this.run(t).type===n.ResultType.Literal}}const p=r=>t=>new s(e=>{const{prompt:u,promptPlaceholder:l}=r;for(;!e.eof();){const{char:i,control:c}=e.peek();if(i===c&&c===u)return e.eat(),new n.Result(u,e,n.ResultType.Mask);if(t.test(i))return e.eat(),new n.Result(i,e,n.ResultType.Mask);if(i===l)return e.eat(),new n.Result(u,e,n.ResultType.Mask);e.eat_input()}return e.eat(),new n.Result(u,e,n.ResultType.Mask)}),R=r=>new s(t=>t.peek().char===r?(t.eat(),new n.Result(r,t,n.ResultType.Literal)):new n.Result(r,t,n.ResultType.Literal)),h=r=>t=>new s(e=>{for(;!e.eof();){const{char:u,control:l}=e.peek();if(u===r&&l===r)return e.eat(),new n.Result(u,e);if(t.test(u))return e.eat(),new n.Result(u,e);e.eat_input()}return e.eat(),new n.Result("",e)}),f=r=>new s(t=>{if(t.eof())return new n.Result("",t);const{char:e}=t.peek();return e===r&&t.eat(),new n.Result(r,t)}),k=(r,t)=>new s(e=>{let{char:u}=e.next();const l=r[u];return u===a?(u=e.next().char,new n.Result(t.literal(u),e)):l?new n.Result(t.mask(l),e):new n.Result(t.literal(u),e)}),y=r=>new s(t=>{const{prompt:e,promptPlaceholder:u}=r,{char:l}=t.next();return l===e?new n.Result(u,t):new n.Result(l,t)}),T=r=>new s(t=>{const{char:e}=t.next();return r?new n.Result(e,t):new n.Result("",t)});exports.Parser=s;exports.literal=R;exports.mask=p;exports.rawLiteral=T;exports.rawMask=y;exports.token=k;exports.unliteral=f;exports.unmask=h;
@@ -6,10 +6,10 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  "use client";
9
- import { Result as i, ResultType as l } from "./result.mjs";
9
+ import { Result as i, ResultType as u } from "./result.mjs";
10
10
  import { Stream as p } from "./stream.mjs";
11
11
  const h = (t) => (t || "").split(""), a = "\\";
12
- class u {
12
+ class o {
13
13
  constructor(e) {
14
14
  this.parse = e;
15
15
  }
@@ -18,30 +18,30 @@ class u {
18
18
  }
19
19
  // map :: Functor f => f a ~> (a -> b) -> f b
20
20
  map(e) {
21
- return new u((n) => this.parse(n).map(e));
21
+ return new o((n) => this.parse(n).map(e));
22
22
  }
23
23
  // chain :: Chain m => m a ~> (a -> m b) -> m b
24
24
  chain(e) {
25
- return new u((n) => this.parse(n).chain((r, c) => e(r).run(c)));
25
+ return new o((n) => this.parse(n).chain((r, c) => e(r).run(c)));
26
26
  }
27
27
  isLiteral(e) {
28
- return this.run(e).type === l.Literal;
28
+ return this.run(e).type === u.Literal;
29
29
  }
30
30
  }
31
- const k = (t) => (e) => new u((n) => {
31
+ const k = (t) => (e) => new o((n) => {
32
32
  const { prompt: r, promptPlaceholder: c } = t;
33
33
  for (; !n.eof(); ) {
34
- const { char: o, control: w } = n.peek();
35
- if (o === w && w === r)
36
- return n.eat(), new i(r, n, l.Mask);
37
- if (e.test(o))
38
- return n.eat(), new i(o, n, l.Mask);
39
- if (o === c)
40
- return n.eat(), new i(r, n, l.Mask);
34
+ const { char: w, control: l } = n.peek();
35
+ if (w === l && l === r)
36
+ return n.eat(), new i(r, n, u.Mask);
37
+ if (e.test(w))
38
+ return n.eat(), new i(w, n, u.Mask);
39
+ if (w === c)
40
+ return n.eat(), new i(r, n, u.Mask);
41
41
  n.eat_input();
42
42
  }
43
- return n.eat(), new i(r, n, l.Mask);
44
- }), x = (t) => new u((e) => e.peek().char === t ? (e.eat(), new i(t, e, l.Literal)) : new i(t, e, l.Literal)), L = (t) => (e) => new u((n) => {
43
+ return n.eat(), new i(r, n, u.Mask);
44
+ }), x = (t) => new o((e) => e.peek().char === t ? (e.eat(), new i(t, e, u.Literal)) : new i(t, e, u.Literal)), L = (t) => (e) => new o((n) => {
45
45
  for (; !n.eof(); ) {
46
46
  const { char: r, control: c } = n.peek();
47
47
  if (r === t && c === t)
@@ -51,25 +51,24 @@ const k = (t) => (e) => new u((n) => {
51
51
  n.eat_input();
52
52
  }
53
53
  return n.eat(), new i("", n);
54
- }), M = (t) => new u((e) => {
54
+ }), M = (t) => new o((e) => {
55
55
  if (e.eof())
56
56
  return new i("", e);
57
57
  const { char: n } = e.peek();
58
58
  return n === t && e.eat(), new i(t, e);
59
- }), A = (t, e) => new u((n) => {
59
+ }), A = (t, e) => new o((n) => {
60
60
  let { char: r } = n.next();
61
61
  const c = t[r];
62
62
  return r === a ? (r = n.next().char, new i(e.literal(r), n)) : c ? new i(e.mask(c), n) : new i(e.literal(r), n);
63
- }), R = (t) => new u((e) => {
64
- const { prompt: n, promptPlaceholder: r } = t;
65
- let { char: c } = e.next();
63
+ }), R = (t) => new o((e) => {
64
+ const { prompt: n, promptPlaceholder: r } = t, { char: c } = e.next();
66
65
  return c === n ? new i(r, e) : new i(c, e);
67
- }), y = (t) => new u((e) => {
68
- let { char: n } = e.next();
66
+ }), y = (t) => new o((e) => {
67
+ const { char: n } = e.next();
69
68
  return t ? new i(n, e) : new i("", e);
70
69
  });
71
70
  export {
72
- u as Parser,
71
+ o as Parser,
73
72
  x as literal,
74
73
  k as mask,
75
74
  y as rawLiteral,