kemet-ui 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/elements/otp-input.ts","../../src/styles/elements/otp-input.ts","../../src/utilities/events.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport {\n customElement, property, queryAll, state\n} from 'lit/decorators.js';\nimport { stylesBase } from '../styles/elements/otp-input';\nimport { EnumKeyCodes } from '../utilities/constants';\nimport { emitEvent } from '../utilities/events';\n\n\n/**\n * @since 4.1.0\n * @status stable\n *\n * @tagname kemet-otp-input\n * @summary An input element that accepts multiple items from a combo.\n *\n * @prop {number} digits - The number of inputs.\n * @prop {string} pattern - The pattern to match against for stripping characters\n * @prop {string} value - All digits entered by the user combined in one string.\n *\n * @csspart input - The input elements.\n *\n * @cssproperty --kemet-otp-input-color - The text color of the otp inputs.\n * @cssproperty --kemet-otp-input-min-width - The minimum width of the otp inputs.\n * @cssproperty --kemet-otp-input-font-size - The font size of the otp inputs.\n * @cssproperty --kemet-otp-input-border - The border of the otp inputs.\n * @cssproperty --kemet-otp-input-border-radius - The border radius of the otp inputs.\n *\n * @event kemet-completed - Fires when otp is filled out completely\n *\n */\n\n@customElement('kemet-otp-input')\nexport default class KemetOtpInput extends LitElement {\n static styles = [stylesBase];\n\n @property({ type: Number })\n digits: number = 6;\n\n @property({ type: String, reflect: true })\n value: string = '';\n\n @property()\n pattern: string;\n\n @state()\n autoFocus: boolean = true;\n\n @state()\n values: string[] = [];\n\n @state()\n lastInput: string;\n\n @state()\n completed: boolean = false;\n\n @queryAll('input')\n inputElements: NodeListOf<HTMLInputElement>;\n\n updated() {\n this.determineCompleted();\n }\n\n render() {\n return this.makeInputs();\n }\n\n determineCompleted() {\n const hasBlankValues = this.values.includes('');\n if (this.values.length === this.digits && !hasBlankValues && !this.completed) {\n emitEvent(this, 'kemet-completed', {\n detail: { value: this.value },\n bubbles: true,\n composed: true,\n });\n this.completed = true;\n }\n }\n\n makeInputs() {\n return Array.from(\n { length: this.digits },\n (_, index) => html`\n <label>\n <span>Enter digit ${index + 1}</span>\n <input\n part=\"input\"\n id=\"${index}\"\n maxlength=\"1\"\n @input=${this.handleInput}\n @keydown=${this.handleKeyDown}\n @paste=${this.handlePaste}\n />\n </label>\n `\n );\n }\n\n eatCharacters(inputValue: string) {\n const regex = new RegExp(this.pattern);\n return inputValue.replace(regex, '');\n }\n\n handleInput(event: InputEvent) {\n const input = event.target as HTMLInputElement;\n const currentIndex = parseInt(input.getAttribute('id'));\n const nextInput = this.inputElements[currentIndex + 1];\n\n if (this.pattern) {\n input.value = this.eatCharacters(input.value);\n }\n\n this.values[currentIndex] = input.value;\n this.value = this.values.join('');\n this.lastInput = input.value;\n\n const fullDigits = this.values.length === this.digits && !!input.value;\n\n if (!fullDigits) {\n this.completed = false;\n }\n\n if (nextInput && this.autoFocus && !!input.value) {\n nextInput.focus();\n }\n }\n\n handleKeyDown(event: KeyboardEvent) {\n this.autoFocus = event.key !== EnumKeyCodes.BACKSPACE;\n }\n\n handlePaste(event: ClipboardEvent) {\n event.preventDefault();\n const pasteData = event.clipboardData?.getData('text') ?? '';\n\n // Trim and limit to number of digits\n const charactersString = this.eatCharacters(pasteData.trim().slice(0, this.digits).split('').join(''));\n const charactersArray = charactersString.split('');\n\n // Fill the inputs and values array one by one\n charactersArray.forEach((character, index) => {\n const input = this.inputElements[index];\n if (input && !!character) {\n input.value = character;\n this.values[index] = character;\n }\n });\n\n const lastFilled = this.inputElements[charactersArray.length - 1];\n lastFilled?.focus();\n this.value = this.values.join('');\n this.determineCompleted();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'kemet-otp-input': KemetOtpInput\n }\n}\n","import { css } from 'lit';\n\nexport const stylesBase = css`\n :host {\n --kemet-otp-input-color: rgb(var(--kemet-color-gray-600));\n --kemet-otp-input-min-width: 3rem;\n --kemet-otp-input-font-size: 2rem;\n --kemet-otp-input-border: 1px solid rgb(var(--kemet-color-gray-300));\n --kemet-otp-input-border-radius: var(--kemet-border-radius-md);\n\n display: grid;\n gap: var(--kemet-spacer-md);\n grid-template-columns: repeat(auto-fit, minmax(var(--kemet-otp-input-min-width), 1fr));\n }\n\n label {\n display: flex;\n aspect-ratio: 4/3;\n }\n\n span {\n position: absolute;\n margin: -1px;\n width: 1px;\n height: 1px;\n display: block;\n overflow: hidden;\n border-width: 0;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n }\n\n [part=\"input\"] {\n color: var(--kemet-otp-input-color);\n text-align: center;\n width: 100%;\n height: 100%;\n font-size: var(--kemet-otp-input-font-size);\n border: var(--kemet-otp-input-border);\n border-radius: var(--kemet-otp-input-border-radius);\n }\n`;\n","export const emitEvent = (element, name, detail, bubbles = true, composed = true) => {\n element.dispatchEvent(\n new CustomEvent(name, { bubbles, composed, detail }),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAAiC;AACjC,wBAEO;;;ACHP,iBAAoB;AAEb,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACFnB,IAAM,YAAY,CAAC,SAAS,MAAM,QAAQ,UAAU,MAAM,WAAW,SAAS;AACnF,UAAQ;AAAA,IACN,IAAI,YAAY,MAAM,EAAE,SAAS,UAAU,OAAO,CAAC;AAAA,EACrD;AACF;;;AF6BA,IAAqB,gBAArB,cAA2C,uBAAW;AAAA,EAAtD;AAAA;AAIE,kBAAiB;AAGjB,iBAAgB;AAMhB,qBAAqB;AAGrB,kBAAmB,CAAC;AAMpB,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AA,GAxBE,cAyBnB;AAzBmB,gBAArB;AAAA,MADC,iCAAc,iBAAiB;AAAA,GACX;","names":["import_lit"]}
@@ -0,0 +1,180 @@
1
+ import {
2
+ emitEvent
3
+ } from "../chunk-LHEY3UOF.mjs";
4
+ import "../chunk-42U43NKG.mjs";
5
+ import {
6
+ __decorateClass
7
+ } from "../chunk-SAWN7RJP.mjs";
8
+
9
+ // src/elements/otp-input.ts
10
+ import { html, LitElement } from "lit";
11
+ import {
12
+ customElement,
13
+ property,
14
+ queryAll,
15
+ state
16
+ } from "lit/decorators.js";
17
+
18
+ // src/styles/elements/otp-input.ts
19
+ import { css } from "lit";
20
+ var stylesBase = css`
21
+ :host {
22
+ --kemet-otp-input-color: rgb(var(--kemet-color-gray-600));
23
+ --kemet-otp-input-min-width: 3rem;
24
+ --kemet-otp-input-font-size: 2rem;
25
+ --kemet-otp-input-border: 1px solid rgb(var(--kemet-color-gray-300));
26
+ --kemet-otp-input-border-radius: var(--kemet-border-radius-md);
27
+
28
+ display: grid;
29
+ gap: var(--kemet-spacer-md);
30
+ grid-template-columns: repeat(auto-fit, minmax(var(--kemet-otp-input-min-width), 1fr));
31
+ }
32
+
33
+ label {
34
+ display: flex;
35
+ aspect-ratio: 4/3;
36
+ }
37
+
38
+ span {
39
+ position: absolute;
40
+ margin: -1px;
41
+ width: 1px;
42
+ height: 1px;
43
+ display: block;
44
+ overflow: hidden;
45
+ border-width: 0;
46
+ clip: rect(0, 0, 0, 0);
47
+ white-space: nowrap;
48
+ }
49
+
50
+ [part="input"] {
51
+ color: var(--kemet-otp-input-color);
52
+ text-align: center;
53
+ width: 100%;
54
+ height: 100%;
55
+ font-size: var(--kemet-otp-input-font-size);
56
+ border: var(--kemet-otp-input-border);
57
+ border-radius: var(--kemet-otp-input-border-radius);
58
+ }
59
+ `;
60
+
61
+ // src/elements/otp-input.ts
62
+ var KemetOtpInput = class extends LitElement {
63
+ constructor() {
64
+ super(...arguments);
65
+ this.digits = 6;
66
+ this.value = "";
67
+ this.autoFocus = true;
68
+ this.values = [];
69
+ this.completed = false;
70
+ }
71
+ updated() {
72
+ this.determineCompleted();
73
+ }
74
+ render() {
75
+ return this.makeInputs();
76
+ }
77
+ determineCompleted() {
78
+ const hasBlankValues = this.values.includes("");
79
+ if (this.values.length === this.digits && !hasBlankValues && !this.completed) {
80
+ emitEvent(this, "kemet-completed", {
81
+ detail: { value: this.value },
82
+ bubbles: true,
83
+ composed: true
84
+ });
85
+ this.completed = true;
86
+ }
87
+ }
88
+ makeInputs() {
89
+ return Array.from(
90
+ { length: this.digits },
91
+ (_, index) => html`
92
+ <label>
93
+ <span>Enter digit ${index + 1}</span>
94
+ <input
95
+ part="input"
96
+ id="${index}"
97
+ maxlength="1"
98
+ @input=${this.handleInput}
99
+ @keydown=${this.handleKeyDown}
100
+ @paste=${this.handlePaste}
101
+ />
102
+ </label>
103
+ `
104
+ );
105
+ }
106
+ eatCharacters(inputValue) {
107
+ const regex = new RegExp(this.pattern);
108
+ return inputValue.replace(regex, "");
109
+ }
110
+ handleInput(event) {
111
+ const input = event.target;
112
+ const currentIndex = parseInt(input.getAttribute("id"));
113
+ const nextInput = this.inputElements[currentIndex + 1];
114
+ if (this.pattern) {
115
+ input.value = this.eatCharacters(input.value);
116
+ }
117
+ this.values[currentIndex] = input.value;
118
+ this.value = this.values.join("");
119
+ this.lastInput = input.value;
120
+ const fullDigits = this.values.length === this.digits && !!input.value;
121
+ if (!fullDigits) {
122
+ this.completed = false;
123
+ }
124
+ if (nextInput && this.autoFocus && !!input.value) {
125
+ nextInput.focus();
126
+ }
127
+ }
128
+ handleKeyDown(event) {
129
+ this.autoFocus = event.key !== "Backspace" /* BACKSPACE */;
130
+ }
131
+ handlePaste(event) {
132
+ event.preventDefault();
133
+ const pasteData = event.clipboardData?.getData("text") ?? "";
134
+ const charactersString = this.eatCharacters(pasteData.trim().slice(0, this.digits).split("").join(""));
135
+ const charactersArray = charactersString.split("");
136
+ charactersArray.forEach((character, index) => {
137
+ const input = this.inputElements[index];
138
+ if (input && !!character) {
139
+ input.value = character;
140
+ this.values[index] = character;
141
+ }
142
+ });
143
+ const lastFilled = this.inputElements[charactersArray.length - 1];
144
+ lastFilled?.focus();
145
+ this.value = this.values.join("");
146
+ this.determineCompleted();
147
+ }
148
+ };
149
+ KemetOtpInput.styles = [stylesBase];
150
+ __decorateClass([
151
+ property({ type: Number })
152
+ ], KemetOtpInput.prototype, "digits", 2);
153
+ __decorateClass([
154
+ property({ type: String, reflect: true })
155
+ ], KemetOtpInput.prototype, "value", 2);
156
+ __decorateClass([
157
+ property()
158
+ ], KemetOtpInput.prototype, "pattern", 2);
159
+ __decorateClass([
160
+ state()
161
+ ], KemetOtpInput.prototype, "autoFocus", 2);
162
+ __decorateClass([
163
+ state()
164
+ ], KemetOtpInput.prototype, "values", 2);
165
+ __decorateClass([
166
+ state()
167
+ ], KemetOtpInput.prototype, "lastInput", 2);
168
+ __decorateClass([
169
+ state()
170
+ ], KemetOtpInput.prototype, "completed", 2);
171
+ __decorateClass([
172
+ queryAll("input")
173
+ ], KemetOtpInput.prototype, "inputElements", 2);
174
+ KemetOtpInput = __decorateClass([
175
+ customElement("kemet-otp-input")
176
+ ], KemetOtpInput);
177
+ export {
178
+ KemetOtpInput as default
179
+ };
180
+ //# sourceMappingURL=otp-input.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/elements/otp-input.ts","../../src/styles/elements/otp-input.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport {\n customElement, property, queryAll, state\n} from 'lit/decorators.js';\nimport { stylesBase } from '../styles/elements/otp-input';\nimport { EnumKeyCodes } from '../utilities/constants';\nimport { emitEvent } from '../utilities/events';\n\n\n/**\n * @since 4.1.0\n * @status stable\n *\n * @tagname kemet-otp-input\n * @summary An input element that accepts multiple items from a combo.\n *\n * @prop {number} digits - The number of inputs.\n * @prop {string} pattern - The pattern to match against for stripping characters\n * @prop {string} value - All digits entered by the user combined in one string.\n *\n * @csspart input - The input elements.\n *\n * @cssproperty --kemet-otp-input-color - The text color of the otp inputs.\n * @cssproperty --kemet-otp-input-min-width - The minimum width of the otp inputs.\n * @cssproperty --kemet-otp-input-font-size - The font size of the otp inputs.\n * @cssproperty --kemet-otp-input-border - The border of the otp inputs.\n * @cssproperty --kemet-otp-input-border-radius - The border radius of the otp inputs.\n *\n * @event kemet-completed - Fires when otp is filled out completely\n *\n */\n\n@customElement('kemet-otp-input')\nexport default class KemetOtpInput extends LitElement {\n static styles = [stylesBase];\n\n @property({ type: Number })\n digits: number = 6;\n\n @property({ type: String, reflect: true })\n value: string = '';\n\n @property()\n pattern: string;\n\n @state()\n autoFocus: boolean = true;\n\n @state()\n values: string[] = [];\n\n @state()\n lastInput: string;\n\n @state()\n completed: boolean = false;\n\n @queryAll('input')\n inputElements: NodeListOf<HTMLInputElement>;\n\n updated() {\n this.determineCompleted();\n }\n\n render() {\n return this.makeInputs();\n }\n\n determineCompleted() {\n const hasBlankValues = this.values.includes('');\n if (this.values.length === this.digits && !hasBlankValues && !this.completed) {\n emitEvent(this, 'kemet-completed', {\n detail: { value: this.value },\n bubbles: true,\n composed: true,\n });\n this.completed = true;\n }\n }\n\n makeInputs() {\n return Array.from(\n { length: this.digits },\n (_, index) => html`\n <label>\n <span>Enter digit ${index + 1}</span>\n <input\n part=\"input\"\n id=\"${index}\"\n maxlength=\"1\"\n @input=${this.handleInput}\n @keydown=${this.handleKeyDown}\n @paste=${this.handlePaste}\n />\n </label>\n `\n );\n }\n\n eatCharacters(inputValue: string) {\n const regex = new RegExp(this.pattern);\n return inputValue.replace(regex, '');\n }\n\n handleInput(event: InputEvent) {\n const input = event.target as HTMLInputElement;\n const currentIndex = parseInt(input.getAttribute('id'));\n const nextInput = this.inputElements[currentIndex + 1];\n\n if (this.pattern) {\n input.value = this.eatCharacters(input.value);\n }\n\n this.values[currentIndex] = input.value;\n this.value = this.values.join('');\n this.lastInput = input.value;\n\n const fullDigits = this.values.length === this.digits && !!input.value;\n\n if (!fullDigits) {\n this.completed = false;\n }\n\n if (nextInput && this.autoFocus && !!input.value) {\n nextInput.focus();\n }\n }\n\n handleKeyDown(event: KeyboardEvent) {\n this.autoFocus = event.key !== EnumKeyCodes.BACKSPACE;\n }\n\n handlePaste(event: ClipboardEvent) {\n event.preventDefault();\n const pasteData = event.clipboardData?.getData('text') ?? '';\n\n // Trim and limit to number of digits\n const charactersString = this.eatCharacters(pasteData.trim().slice(0, this.digits).split('').join(''));\n const charactersArray = charactersString.split('');\n\n // Fill the inputs and values array one by one\n charactersArray.forEach((character, index) => {\n const input = this.inputElements[index];\n if (input && !!character) {\n input.value = character;\n this.values[index] = character;\n }\n });\n\n const lastFilled = this.inputElements[charactersArray.length - 1];\n lastFilled?.focus();\n this.value = this.values.join('');\n this.determineCompleted();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'kemet-otp-input': KemetOtpInput\n }\n}\n","import { css } from 'lit';\n\nexport const stylesBase = css`\n :host {\n --kemet-otp-input-color: rgb(var(--kemet-color-gray-600));\n --kemet-otp-input-min-width: 3rem;\n --kemet-otp-input-font-size: 2rem;\n --kemet-otp-input-border: 1px solid rgb(var(--kemet-color-gray-300));\n --kemet-otp-input-border-radius: var(--kemet-border-radius-md);\n\n display: grid;\n gap: var(--kemet-spacer-md);\n grid-template-columns: repeat(auto-fit, minmax(var(--kemet-otp-input-min-width), 1fr));\n }\n\n label {\n display: flex;\n aspect-ratio: 4/3;\n }\n\n span {\n position: absolute;\n margin: -1px;\n width: 1px;\n height: 1px;\n display: block;\n overflow: hidden;\n border-width: 0;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n }\n\n [part=\"input\"] {\n color: var(--kemet-otp-input-color);\n text-align: center;\n width: 100%;\n height: 100%;\n font-size: var(--kemet-otp-input-font-size);\n border: var(--kemet-otp-input-border);\n border-radius: var(--kemet-otp-input-border-radius);\n }\n`;\n"],"mappings":";;;;;;;;;AAAA,SAAS,MAAM,kBAAkB;AACjC;AAAA,EACC;AAA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;AAAA,EAC1B;AACF;AAzHqB,cACZ,SAAS,CAAC,UAAU;AAG3B;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAHP,cAInB;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,QAAQ,SAAS,KAAK,CAAC;AAAA,GANtB,cAOnB;AAGA;AAAA,EADC,SAAS;AAAA,GATS,cAUnB;AAGA;AAAA,EADC,MAAM;AAAA,GAZY,cAanB;AAGA;AAAA,EADC,MAAM;AAAA,GAfY,cAgBnB;AAGA;AAAA,EADC,MAAM;AAAA,GAlBY,cAmBnB;AAGA;AAAA,EADC,MAAM;AAAA,GArBY,cAsBnB;AAGA;AAAA,EADC,SAAS,OAAO;AAAA,GAxBE,cAyBnB;AAzBmB,gBAArB;AAAA,EADC,cAAc,iBAAiB;AAAA,GACX;","names":[]}
@@ -0,0 +1,41 @@
1
+ import * as lit_html from 'lit-html';
2
+ import { LitElement, PropertyValues } from 'lit';
3
+
4
+ /**
5
+ * @since 4.1.0
6
+ * @status stable
7
+ *
8
+ * @tagname kemet-typewriter
9
+ * @summary An element that types out content.
10
+ *
11
+ * @prop {string} content - The content to be typed.
12
+ * @prop {number} delay - The delay between each character.
13
+ * @prop {string} cursor - The cursor to be displayed.
14
+ * @prop {boolean} loop - Whether to loop the content.
15
+ * @prop {number} restartDelay - The delay before restarting the typewriter.
16
+ *
17
+ * @event kemet-completed - Fires when typewriter is completed
18
+ *
19
+ */
20
+ declare class KemetTypewriter extends LitElement {
21
+ content: string;
22
+ delay: number;
23
+ cursor: string;
24
+ loop: boolean;
25
+ restartDelay: number;
26
+ private typewriter;
27
+ private timeoutId;
28
+ createRenderRoot(): this;
29
+ firstUpdated(): void;
30
+ updated(changedProperties: PropertyValues<this>): void;
31
+ disconnectedCallback(): void;
32
+ render(): lit_html.TemplateResult<1>;
33
+ restartTypewriter(): void;
34
+ }
35
+ declare global {
36
+ interface HTMLElementTagNameMap {
37
+ 'kemet-typewriter': KemetTypewriter;
38
+ }
39
+ }
40
+
41
+ export { KemetTypewriter as default };
@@ -0,0 +1,41 @@
1
+ import * as lit_html from 'lit-html';
2
+ import { LitElement, PropertyValues } from 'lit';
3
+
4
+ /**
5
+ * @since 4.1.0
6
+ * @status stable
7
+ *
8
+ * @tagname kemet-typewriter
9
+ * @summary An element that types out content.
10
+ *
11
+ * @prop {string} content - The content to be typed.
12
+ * @prop {number} delay - The delay between each character.
13
+ * @prop {string} cursor - The cursor to be displayed.
14
+ * @prop {boolean} loop - Whether to loop the content.
15
+ * @prop {number} restartDelay - The delay before restarting the typewriter.
16
+ *
17
+ * @event kemet-completed - Fires when typewriter is completed
18
+ *
19
+ */
20
+ declare class KemetTypewriter extends LitElement {
21
+ content: string;
22
+ delay: number;
23
+ cursor: string;
24
+ loop: boolean;
25
+ restartDelay: number;
26
+ private typewriter;
27
+ private timeoutId;
28
+ createRenderRoot(): this;
29
+ firstUpdated(): void;
30
+ updated(changedProperties: PropertyValues<this>): void;
31
+ disconnectedCallback(): void;
32
+ render(): lit_html.TemplateResult<1>;
33
+ restartTypewriter(): void;
34
+ }
35
+ declare global {
36
+ interface HTMLElementTagNameMap {
37
+ 'kemet-typewriter': KemetTypewriter;
38
+ }
39
+ }
40
+
41
+ export { KemetTypewriter as default };
@@ -0,0 +1,136 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var __decorateClass = (decorators, target, key, kind) => {
29
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
30
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
31
+ if (decorator = decorators[i])
32
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
33
+ if (kind && result) __defProp(target, key, result);
34
+ return result;
35
+ };
36
+
37
+ // src/elements/typewriter.ts
38
+ var typewriter_exports = {};
39
+ __export(typewriter_exports, {
40
+ default: () => KemetTypewriter
41
+ });
42
+ module.exports = __toCommonJS(typewriter_exports);
43
+ var import_lit = require("lit");
44
+ var import_decorators = require("lit/decorators.js");
45
+ var import_core = __toESM(require("typewriter-effect/dist/core"));
46
+
47
+ // src/utilities/events.ts
48
+ var emitEvent = (element, name, detail, bubbles = true, composed = true) => {
49
+ element.dispatchEvent(
50
+ new CustomEvent(name, { bubbles, composed, detail })
51
+ );
52
+ };
53
+
54
+ // src/elements/typewriter.ts
55
+ var KemetTypewriter = class extends import_lit.LitElement {
56
+ constructor() {
57
+ super(...arguments);
58
+ this.content = "";
59
+ this.delay = 10;
60
+ this.cursor = "";
61
+ this.loop = false;
62
+ this.restartDelay = 1e3;
63
+ this.timeoutId = null;
64
+ }
65
+ createRenderRoot() {
66
+ return this;
67
+ }
68
+ firstUpdated() {
69
+ const target = this.querySelector("kemet-typewriter-target");
70
+ this.typewriter = new import_core.default(target, {
71
+ cursor: this.cursor,
72
+ loop: this.loop,
73
+ delay: this.delay
74
+ });
75
+ this.restartTypewriter();
76
+ }
77
+ updated(changedProperties) {
78
+ if (changedProperties.has("content") || changedProperties.has("delay") || changedProperties.has("cursor") || changedProperties.has("loop")) {
79
+ const target = this.querySelector("kemet-typewriter-target");
80
+ if (this.typewriter) {
81
+ this.typewriter.stop();
82
+ }
83
+ this.typewriter = new import_core.default(target, {
84
+ cursor: this.cursor,
85
+ loop: this.loop,
86
+ delay: this.delay
87
+ });
88
+ this.restartTypewriter();
89
+ }
90
+ }
91
+ disconnectedCallback() {
92
+ super.disconnectedCallback();
93
+ if (this.timeoutId) {
94
+ clearTimeout(this.timeoutId);
95
+ this.timeoutId = null;
96
+ }
97
+ if (this.typewriter) {
98
+ this.typewriter.stop();
99
+ }
100
+ }
101
+ render() {
102
+ return import_lit.html`
103
+ <kemet-typewriter-target></kemet-typewriter-target>
104
+ `;
105
+ }
106
+ restartTypewriter() {
107
+ if (!this.typewriter) return;
108
+ if (this.timeoutId) {
109
+ clearTimeout(this.timeoutId);
110
+ }
111
+ this.timeoutId = setTimeout(() => {
112
+ this.typewriter.deleteAll(1).typeString(this.content).callFunction(() => {
113
+ emitEvent(this, "kemet-completed", { element: this });
114
+ }).start();
115
+ }, this.restartDelay);
116
+ }
117
+ };
118
+ __decorateClass([
119
+ (0, import_decorators.property)({ type: String })
120
+ ], KemetTypewriter.prototype, "content", 2);
121
+ __decorateClass([
122
+ (0, import_decorators.property)({ type: Number })
123
+ ], KemetTypewriter.prototype, "delay", 2);
124
+ __decorateClass([
125
+ (0, import_decorators.property)({ type: String })
126
+ ], KemetTypewriter.prototype, "cursor", 2);
127
+ __decorateClass([
128
+ (0, import_decorators.property)({ type: Boolean })
129
+ ], KemetTypewriter.prototype, "loop", 2);
130
+ __decorateClass([
131
+ (0, import_decorators.property)({ type: Number, attribute: "restart-delay" })
132
+ ], KemetTypewriter.prototype, "restartDelay", 2);
133
+ KemetTypewriter = __decorateClass([
134
+ (0, import_decorators.customElement)("kemet-typewriter")
135
+ ], KemetTypewriter);
136
+ //# sourceMappingURL=typewriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/elements/typewriter.ts","../../src/utilities/events.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport Typewriter from 'typewriter-effect/dist/core';\nimport { emitEvent } from '../utilities/events';\n\n/**\n * @since 4.1.0\n * @status stable\n *\n * @tagname kemet-typewriter\n * @summary An element that types out content.\n *\n * @prop {string} content - The content to be typed.\n * @prop {number} delay - The delay between each character.\n * @prop {string} cursor - The cursor to be displayed.\n * @prop {boolean} loop - Whether to loop the content.\n * @prop {number} restartDelay - The delay before restarting the typewriter.\n *\n * @event kemet-completed - Fires when typewriter is completed\n *\n */\n\n@customElement('kemet-typewriter')\nexport default class KemetTypewriter extends LitElement {\n @property({ type: String })\n content: string = '';\n\n @property({ type: Number })\n delay: number = 10;\n\n @property({ type: String })\n cursor: string = '';\n\n @property({ type: Boolean })\n loop: boolean = false;\n\n @property({ type: Number, attribute: 'restart-delay' })\n restartDelay: number = 1000;\n\n private typewriter!: Typewriter;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n createRenderRoot() {\n return this;\n }\n\n firstUpdated() {\n const target = this.querySelector('kemet-typewriter-target') as HTMLElement;\n\n this.typewriter = new Typewriter(target, {\n cursor: this.cursor,\n loop: this.loop,\n delay: this.delay,\n });\n\n this.restartTypewriter();\n }\n\n updated(changedProperties: PropertyValues<this>) {\n if (\n changedProperties.has('content') ||\n changedProperties.has('delay') ||\n changedProperties.has('cursor') ||\n changedProperties.has('loop')\n ) {\n const target = this.querySelector('kemet-typewriter-target') as HTMLElement;\n\n if (this.typewriter) {\n this.typewriter.stop();\n }\n\n this.typewriter = new Typewriter(target, {\n cursor: this.cursor,\n loop: this.loop,\n delay: this.delay,\n });\n\n this.restartTypewriter();\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n\n if (this.typewriter) {\n this.typewriter.stop();\n }\n }\n\n render() {\n return html`\n <kemet-typewriter-target></kemet-typewriter-target>\n `;\n }\n\n restartTypewriter() {\n if (!this.typewriter) return;\n\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n this.timeoutId = setTimeout(() => {\n this.typewriter\n .deleteAll(1)\n .typeString(this.content)\n .callFunction(() => {\n emitEvent(this, 'kemet-completed', { element: this });\n })\n .start();\n }, this.restartDelay);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'kemet-typewriter': KemetTypewriter;\n }\n}\n","export const emitEvent = (element, name, detail, bubbles = true, composed = true) => {\n element.dispatchEvent(\n new CustomEvent(name, { bubbles, composed, detail }),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiD;AACjD,wBAAwC;AACxC,kBAAuB;;;ACFhB,IAAM,YAAY,CAAC,SAAS,MAAM,QAAQ,UAAU,MAAM,WAAW,SAAS;AACnF,UAAQ;AAAA,IACN,IAAI,YAAY,MAAM,EAAE,SAAS,UAAU,OAAO,CAAC;AAAA,EACrD;AACF;;;ADmBA,IAAqB,kBAArB,cAA6C,sBAAW;AAAA,EAAxD;AAAA;AAEE,mBAAkB;AAGlB,iBAAgB;AAGhB,kBAAiB;AAGjB,gBAAgB;AAGhB,wBAAuB;AAGvB,SAAQ,YAAkD;AAAA;AAAA,EAE1D,mBAAmB;AACjB,WAAO;AAAA,EACT;AAAA,EAEA,eAAe;AACb,UAAM,SAAS,KAAK,cAAc,yBAAyB;AAE3D,SAAK,aAAa,IAAI,YAAAA,QAAW,QAAQ;AAAA,MACvC,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK;AAAA,MACX,OAAO,KAAK;AAAA,IACd,CAAC;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A,GAPP,gBAQnB;AAGA;AAAA,MADC,4BAAS,EAAE,MAAM,QAAQ,CAAC;AAAA,GAVR,gBAWnB;AAGA;AAAA,MADC,4BAAS,EAAE,MAAM,QAAQ,WAAW,gBAAgB,CAAC;AAAA,GAbnC,gBAcnB;AAdmB,kBAArB;AAAA,MADC,iCAAc,kBAAkB;AAAA,GACZ;","names":["Typewriter"]}
@@ -0,0 +1,96 @@
1
+ import {
2
+ emitEvent
3
+ } from "../chunk-LHEY3UOF.mjs";
4
+ import {
5
+ __decorateClass
6
+ } from "../chunk-SAWN7RJP.mjs";
7
+
8
+ // src/elements/typewriter.ts
9
+ import { html, LitElement } from "lit";
10
+ import { customElement, property } from "lit/decorators.js";
11
+ import Typewriter from "typewriter-effect/dist/core";
12
+ var KemetTypewriter = class extends LitElement {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.content = "";
16
+ this.delay = 10;
17
+ this.cursor = "";
18
+ this.loop = false;
19
+ this.restartDelay = 1e3;
20
+ this.timeoutId = null;
21
+ }
22
+ createRenderRoot() {
23
+ return this;
24
+ }
25
+ firstUpdated() {
26
+ const target = this.querySelector("kemet-typewriter-target");
27
+ this.typewriter = new Typewriter(target, {
28
+ cursor: this.cursor,
29
+ loop: this.loop,
30
+ delay: this.delay
31
+ });
32
+ this.restartTypewriter();
33
+ }
34
+ updated(changedProperties) {
35
+ if (changedProperties.has("content") || changedProperties.has("delay") || changedProperties.has("cursor") || changedProperties.has("loop")) {
36
+ const target = this.querySelector("kemet-typewriter-target");
37
+ if (this.typewriter) {
38
+ this.typewriter.stop();
39
+ }
40
+ this.typewriter = new Typewriter(target, {
41
+ cursor: this.cursor,
42
+ loop: this.loop,
43
+ delay: this.delay
44
+ });
45
+ this.restartTypewriter();
46
+ }
47
+ }
48
+ disconnectedCallback() {
49
+ super.disconnectedCallback();
50
+ if (this.timeoutId) {
51
+ clearTimeout(this.timeoutId);
52
+ this.timeoutId = null;
53
+ }
54
+ if (this.typewriter) {
55
+ this.typewriter.stop();
56
+ }
57
+ }
58
+ render() {
59
+ return html`
60
+ <kemet-typewriter-target></kemet-typewriter-target>
61
+ `;
62
+ }
63
+ restartTypewriter() {
64
+ if (!this.typewriter) return;
65
+ if (this.timeoutId) {
66
+ clearTimeout(this.timeoutId);
67
+ }
68
+ this.timeoutId = setTimeout(() => {
69
+ this.typewriter.deleteAll(1).typeString(this.content).callFunction(() => {
70
+ emitEvent(this, "kemet-completed", { element: this });
71
+ }).start();
72
+ }, this.restartDelay);
73
+ }
74
+ };
75
+ __decorateClass([
76
+ property({ type: String })
77
+ ], KemetTypewriter.prototype, "content", 2);
78
+ __decorateClass([
79
+ property({ type: Number })
80
+ ], KemetTypewriter.prototype, "delay", 2);
81
+ __decorateClass([
82
+ property({ type: String })
83
+ ], KemetTypewriter.prototype, "cursor", 2);
84
+ __decorateClass([
85
+ property({ type: Boolean })
86
+ ], KemetTypewriter.prototype, "loop", 2);
87
+ __decorateClass([
88
+ property({ type: Number, attribute: "restart-delay" })
89
+ ], KemetTypewriter.prototype, "restartDelay", 2);
90
+ KemetTypewriter = __decorateClass([
91
+ customElement("kemet-typewriter")
92
+ ], KemetTypewriter);
93
+ export {
94
+ KemetTypewriter as default
95
+ };
96
+ //# sourceMappingURL=typewriter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/elements/typewriter.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport Typewriter from 'typewriter-effect/dist/core';\nimport { emitEvent } from '../utilities/events';\n\n/**\n * @since 4.1.0\n * @status stable\n *\n * @tagname kemet-typewriter\n * @summary An element that types out content.\n *\n * @prop {string} content - The content to be typed.\n * @prop {number} delay - The delay between each character.\n * @prop {string} cursor - The cursor to be displayed.\n * @prop {boolean} loop - Whether to loop the content.\n * @prop {number} restartDelay - The delay before restarting the typewriter.\n *\n * @event kemet-completed - Fires when typewriter is completed\n *\n */\n\n@customElement('kemet-typewriter')\nexport default class KemetTypewriter extends LitElement {\n @property({ type: String })\n content: string = '';\n\n @property({ type: Number })\n delay: number = 10;\n\n @property({ type: String })\n cursor: string = '';\n\n @property({ type: Boolean })\n loop: boolean = false;\n\n @property({ type: Number, attribute: 'restart-delay' })\n restartDelay: number = 1000;\n\n private typewriter!: Typewriter;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n createRenderRoot() {\n return this;\n }\n\n firstUpdated() {\n const target = this.querySelector('kemet-typewriter-target') as HTMLElement;\n\n this.typewriter = new Typewriter(target, {\n cursor: this.cursor,\n loop: this.loop,\n delay: this.delay,\n });\n\n this.restartTypewriter();\n }\n\n updated(changedProperties: PropertyValues<this>) {\n if (\n changedProperties.has('content') ||\n changedProperties.has('delay') ||\n changedProperties.has('cursor') ||\n changedProperties.has('loop')\n ) {\n const target = this.querySelector('kemet-typewriter-target') as HTMLElement;\n\n if (this.typewriter) {\n this.typewriter.stop();\n }\n\n this.typewriter = new Typewriter(target, {\n cursor: this.cursor,\n loop: this.loop,\n delay: this.delay,\n });\n\n this.restartTypewriter();\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n\n if (this.typewriter) {\n this.typewriter.stop();\n }\n }\n\n render() {\n return html`\n <kemet-typewriter-target></kemet-typewriter-target>\n `;\n }\n\n restartTypewriter() {\n if (!this.typewriter) return;\n\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n this.timeoutId = setTimeout(() => {\n this.typewriter\n .deleteAll(1)\n .typeString(this.content)\n .callFunction(() => {\n emitEvent(this, 'kemet-completed', { element: this });\n })\n .start();\n }, this.restartDelay);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'kemet-typewriter': KemetTypewriter;\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,MAAM,kBAAkC;AACjD,SAAS,eAAe,gBAAgB;AACxC,OAAO,gBAAgB;AAqBvB,IAAqB,kBAAr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C,EACX,WAAW,KAAK,OAAO,EACvB,aAAa,MAAM;AAClB,kBAAU,MAAM,mBAAmB,EAAE,SAAS,KAAK,CAAC;AAAA,MACtD,CAAC,EACA,MAAM;AAAA,IACX,GAAG,KAAK,YAAY;AAAA,EACtB;AACF;AA5FE;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GADP,gBAEnB;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAJP,gBAKnB;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAPP,gBAQnB;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,QAAQ,CAAC;AAAA,GAVR,gBAWnB;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,QAAQ,WAAW,gBAAgB,CAAC;AAAA,GAbnC,gBAcnB;AAdmB,kBAArB;AAAA,EADC,cAAc,kBAAkB;AAAA,GACZ;","names":[]}
@@ -0,0 +1,42 @@
1
+ import { css } from 'lit';
2
+
3
+ export const stylesBase = css`
4
+ :host {
5
+ --kemet-otp-input-color: rgb(var(--kemet-color-gray-600));
6
+ --kemet-otp-input-min-width: 3rem;
7
+ --kemet-otp-input-font-size: 2rem;
8
+ --kemet-otp-input-border: 1px solid rgb(var(--kemet-color-gray-300));
9
+ --kemet-otp-input-border-radius: var(--kemet-border-radius-md);
10
+
11
+ display: grid;
12
+ gap: var(--kemet-spacer-md);
13
+ grid-template-columns: repeat(auto-fit, minmax(var(--kemet-otp-input-min-width), 1fr));
14
+ }
15
+
16
+ label {
17
+ display: flex;
18
+ aspect-ratio: 4/3;
19
+ }
20
+
21
+ span {
22
+ position: absolute;
23
+ margin: -1px;
24
+ width: 1px;
25
+ height: 1px;
26
+ display: block;
27
+ overflow: hidden;
28
+ border-width: 0;
29
+ clip: rect(0, 0, 0, 0);
30
+ white-space: nowrap;
31
+ }
32
+
33
+ [part="input"] {
34
+ color: var(--kemet-otp-input-color);
35
+ text-align: center;
36
+ width: 100%;
37
+ height: 100%;
38
+ font-size: var(--kemet-otp-input-font-size);
39
+ border: var(--kemet-otp-input-border);
40
+ border-radius: var(--kemet-otp-input-border-radius);
41
+ }
42
+ `;