@substrate-system/input 0.0.19 → 0.0.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.
package/LICENSE CHANGED
@@ -6,11 +6,15 @@ Version 2.0.2
6
6
 
7
7
  ## Purpose
8
8
 
9
- These terms let you use and share this software for noncommercial purposes and in small business for free, while also guaranteeing that paid licenses for big businesses will be available on fair, reasonable, and nondiscriminatory terms.
9
+ These terms let you use and share this software for noncommercial purposes
10
+ and in small business for free, while also guaranteeing that paid licenses
11
+ for big businesses will be available on fair, reasonable, and
12
+ nondiscriminatory terms.
10
13
 
11
14
  ## Acceptance
12
15
 
13
- In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
16
+ In order to get any license under these terms, you must agree to them as
17
+ both strict obligations and conditions to all your licenses.
14
18
 
15
19
  ## Noncommercial Purposes
16
20
 
@@ -18,82 +22,147 @@ You may use the software for any noncommercial purpose.
18
22
 
19
23
  ## Personal Uses
20
24
 
21
- Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, count as use for noncommercial purposes.
25
+ Personal use for research, experiment, and testing for the benefit of
26
+ public knowledge, personal study, private entertainment, hobby projects,
27
+ amateur pursuits, or religious observance, without any anticipated
28
+ commercial application, count as use for noncommercial purposes.
22
29
 
23
30
  ## Noncommercial Organizations
24
31
 
25
- Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution counts as use for noncommercial purposes, regardless of the source of funding or obligations resulting from the funding.
32
+ Use by any charitable organization, educational institution, public
33
+ research organization, public safety or health organization, environmental
34
+ protection organization, or government institution counts as use for
35
+ noncommercial purposes, regardless of the source of funding or obligations
36
+ resulting from the funding.
26
37
 
27
38
  ## Small Business
28
39
 
29
- You may use the software for the benefit of your company if it meets all these criteria:
40
+ You may use the software for the benefit of your company if it meets all
41
+ these criteria:
30
42
 
31
- 1. had fewer than 20 total individuals working as employees and independent contractors at all times during the last tax year
43
+ 1. had fewer than 20 total individuals working as employees and
44
+ independent contractors at all times during the last tax year
32
45
 
33
46
  2. earned less than $1,000,000 total revenue in the last tax year
34
47
 
35
- 3. received less than $1,000,000 total debt, equity, and other investment in the last five tax years, counting investment in predecessor companies that reorganized into, merged with, or spun out your company
48
+ 3. received less than $1,000,000 total debt, equity, and other investment
49
+ in the last five tax years, counting investment in predecessor
50
+ companies that reorganized into, merged with, or spun out your company
36
51
 
37
- All dollar figures are United States dollars as of 2019. Adjust for them inflation according to the United States Bureau of Labor Statistics' consumer price index for all urban consumers, United States city average, for all items, not seasonally adjusted, with 1982–1984=100 reference base.
52
+ All dollar figures are United States dollars as of 2019. Adjust for them
53
+ inflation according to the United States Bureau of Labor Statistics'
54
+ consumer price index for all urban consumers, United States city average,
55
+ for all items, not seasonally adjusted, with 1982–1984=100 reference base.
38
56
 
39
57
  ## Big Business
40
58
 
41
59
  You may use the software for the benefit of your company:
42
60
 
43
- 1. for 128 days after your company stops qualifying under [Small Business](#small-business)
61
+ 1. for 128 days after your company stops qualifying under
62
+ [Small Business](#small-business)
44
63
 
45
- 2. indefinitely, if the licensor or their legal successor does not offer fair, reasonable, and nondiscriminatory terms for a commercial license for the software within 32 days of [written request](#how-to-request) and negotiate in good faith to conclude a deal
64
+ 2. indefinitely, if the licensor or their legal successor does not offer
65
+ fair, reasonable, and nondiscriminatory terms for a commercial license for
66
+ the software within 32 days of [written request](#how-to-request) and
67
+ negotiate in good faith to conclude a deal
46
68
 
47
69
  ## How to Request
48
70
 
49
- If this software includes an address for the licensor or an agent of the licensor in a standard place, such as in documentation, software package metadata, or an "about" page or screen, try to request a fair commercial license at that address. If this package includes both online and offline addresses, try online before offline. If you can't deliver a request that way, or this software doesn't include any addressees, spend one hour online researching an address, recording all your searches and inquiries as you go, and try any addresses that you find. If you can't find any addresses, or if those addresses also fail, that counts as failure to offer a fair commercial license by the licensor under [Big Business](#big-business).
71
+ If this software includes an address for the licensor or an agent of the
72
+ licensor in a standard place, such as in documentation, software package
73
+ metadata, or an "about" page or screen, try to request a fair commercial
74
+ license at that address. If this package includes both online and offline
75
+ addresses, try online before offline. If you can't deliver a request that
76
+ way, or this software doesn't include any addressees, spend one hour online
77
+ researching an address, recording all your searches and inquiries as you
78
+ go, and try any addresses that you find. If you can't find any addresses,
79
+ or if those addresses also fail, that counts as failure to offer a fair
80
+ commercial license by the licensor under [Big Business](#big-business).
50
81
 
51
82
  ## Fair, Reasonable, and Nondiscriminatory Terms
52
83
 
53
- Fair, reasonable, and nondiscriminatory terms may license the software perpetually or for a term, and may or may not cover new versions of the software. If the licensor advertises license terms and a pricing structure for generally available commercial licenses, the licensor proposes license terms and a price as advertised, and a customer not affiliated with the licensor has bought a commercial license for the software on substantially equivalent terms in the past year, the proposal is fair, reasonable, and nondiscriminatory.
84
+ Fair, reasonable, and nondiscriminatory terms may license the software
85
+ perpetually or for a term, and may or may not cover new versions of the
86
+ software. If the licensor advertises license terms and a pricing structure
87
+ for generally available commercial licenses, the licensor proposes license
88
+ terms and a price as advertised, and a customer not affiliated with the
89
+ licensor has bought a commercial license for the software on substantially
90
+ equivalent terms in the past year, the proposal is fair, reasonable, and
91
+ nondiscriminatory.
54
92
 
55
93
  ## Copyright License
56
94
 
57
- The licensor grants you a copyright license to do everything with the software that would otherwise infringe the licensor's copyright in it for any purpose allowed by these terms.
95
+ The licensor grants you a copyright license to do everything with the
96
+ software that would otherwise infringe the licensor's copyright in it for
97
+ any purpose allowed by these terms.
58
98
 
59
99
  ## Notices
60
100
 
61
- You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
101
+ You must ensure that anyone who gets a copy of any part of the software
102
+ from you also gets a copy of these terms or the URL for them above, as well
103
+ as copies of any plain-text lines beginning with `Required Notice:` that
104
+ the licensor provided with the software. For example:
62
105
 
63
- > Required Notice: Nick Thomas (https://nichoth.com)
106
+ > Required Notice: Copyright Nick Thomas (https://nichoth.com)
64
107
 
65
108
  ## Patent License
66
109
 
67
- The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
110
+ The licensor grants you a patent license for the software that covers
111
+ patent claims the licensor can license, or becomes able to license, that
112
+ you would infringe by using the software.
68
113
 
69
114
  ## Fair Use
70
115
 
71
- You may have "fair use" rights for the software under the law. These terms do not limit them.
116
+ You may have "fair use" rights for the software under the law. These terms
117
+ do not limit them.
72
118
 
73
119
  ## No Other Rights
74
120
 
75
- These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
121
+ These terms do not allow you to sublicense or transfer any of your licenses
122
+ to anyone else, or prevent the licensor from granting licenses to anyone
123
+ else. These terms do not imply any other licenses.
76
124
 
77
125
  ## Patent Defense
78
126
 
79
- If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
127
+ If you make any written claim that the software infringes or contributes to
128
+ infringement of any patent, your patent license for the software granted
129
+ under these terms ends immediately. If your company makes such a claim,
130
+ your patent license ends immediately for work on behalf of your company.
80
131
 
81
132
  ## Violations
82
133
 
83
- The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
134
+ The first time you are notified in writing that you have violated any of
135
+ these terms, or done anything with the software not covered by your
136
+ licenses, your licenses can nonetheless continue if you come into full
137
+ compliance with these terms, and take practical steps to correct past
138
+ violations, within 32 days of receiving notice. Otherwise, all your
139
+ licenses end immediately.
84
140
 
85
141
  ## No Liability
86
142
 
87
- ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
143
+ ***As far as the law allows, the software comes as is, without any warranty
144
+ or condition, and the licensor will not be liable to you for any damages
145
+ arising out of these terms or the use or nature of the software, under any
146
+ kind of legal claim.***
88
147
 
89
148
  ## Definitions
90
149
 
91
- The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
150
+ The **licensor** is the individual or entity offering these terms, and
151
+ the **software** is the software the licensor makes available under these
152
+ terms.
92
153
 
93
154
  **You** refers to the individual or entity agreeing to these terms.
94
155
 
95
- **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
156
+ **Your company** is any legal entity, sole proprietorship, or other kind of
157
+ organization that you work for, plus all organizations that have control
158
+ over, are under the control of, or are under common control with that
159
+ organization. **Control** means ownership of substantially all the assets
160
+ of an entity, or the power to direct its management and policies by vote,
161
+ contract, or otherwise. Control can be direct or indirect.
96
162
 
97
- **Your licenses** are all the licenses granted to you for the software under these terms.
163
+ **Your licenses** are all the licenses granted to you for the software
164
+ under these terms.
165
+
166
+ **Use** means anything you do with the software requiring one of your
167
+ licenses.
98
168
 
99
- **Use** means anything you do with the software requiring one of your licenses.
package/README.md CHANGED
@@ -1,67 +1,98 @@
1
- # input
2
- [![tests](https://img.shields.io/github/actions/workflow/status/substrate-system/input/nodejs.yml?style=flat-square)](https://github.com/substrate-system/input/actions/workflows/nodejs.yml)
1
+ # Input
2
+ ![tests](https://github.com/substrate-system/input/actions/workflows/nodejs.yml/badge.svg)
3
3
  [![types](https://img.shields.io/npm/types/@substrate-system/input?style=flat-square)](README.md)
4
4
  [![module](https://img.shields.io/badge/module-ESM%2FCJS-blue?style=flat-square)](README.md)
5
- [![install size](https://flat.badgen.net/packagephobia/install/@substrate-system/input?cache-control=no-cache)](https://packagephobia.com/result?p=@substrate-system/input)
6
- [![GZip size](https://flat.badgen.net/bundlephobia/minzip/@substrate-system/input)](https://bundlephobia.com/package/@substrate-system/input)
5
+ [![install size](https://flat.badgen.net/packagephobia/install/@bicycle-codes/keys?cache-control=no-cache)](https://packagephobia.com/result?p=@bicycle-codes/keys)
6
+ [![GZip size](https://img.badgesize.io/https%3A%2F%2Fesm.sh%2F%40substrate-system%2Finput%2Fes2022%2Ffile.mjs?style=flat-square&compression=gzip)](https://esm.sh/@substrate-system/input/es2022/input.mjs)
7
7
  [![dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg?style=flat-square)](package.json)
8
8
  [![semantic versioning](https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&style=flat-square)](https://semver.org/)
9
9
  [![Common Changelog](https://nichoth.github.io/badge/common-changelog.svg)](./CHANGELOG.md)
10
10
  [![license](https://img.shields.io/badge/license-Big_Time-blue?style=flat-square)](LICENSE)
11
11
 
12
12
 
13
- A parent web component to inherit from.
13
+ Inputs with style.
14
14
 
15
15
  [See a live demo](https://substrate-system.github.io/input/)
16
16
 
17
+ <details><summary><h2>Contents</h2></summary>
18
+
17
19
  <!-- toc -->
18
20
 
19
21
  - [Install](#install)
20
- - [Modules](#modules)
21
- * [ESM](#esm)
22
- * [Common JS](#common-js)
23
- - [Use](#use)
22
+ - [CSS](#css)
23
+ * [Import CSS](#import-css)
24
+ * [Customize CSS via some variables](#customize-css-via-some-variables)
25
+ - [use](#use)
24
26
  * [JS](#js)
27
+ * [HTML](#html)
28
+ * [pre-built](#pre-built)
25
29
 
26
30
  <!-- tocstop -->
27
31
 
32
+ </details>
33
+
28
34
  ## Install
29
35
 
36
+ Installation instructions
37
+
30
38
  ```sh
31
39
  npm i -S @substrate-system/input
32
40
  ```
33
41
 
34
- ## Modules
42
+ ## CSS
35
43
 
36
- This exposes ESM and common JS via [package.json `exports` field](https://nodejs.org/api/packages.html#exports).
44
+ ### Import CSS
37
45
 
38
- ### ESM
39
46
  ```js
40
- import { Input } from '@substrate-system/input'
47
+ import '@substrate-system/input/css'
41
48
  ```
42
49
 
43
- ### Common JS
50
+ Or minified:
44
51
  ```js
45
- const { Input } = require('@substrate-system/input')
52
+ import '@substrate-system/input/min/css'
46
53
  ```
47
54
 
48
- -----------------
55
+ ### Customize CSS via some variables
56
+
57
+ ```css
58
+ substrate-input {
59
+ --example: pink;
60
+ }
61
+ ```
49
62
 
50
- ## Use
51
- Inherit from this module.
63
+ ## use
64
+ This calls the global function `customElements.define`. Just import, then use
65
+ the tag in your HTML.
52
66
 
53
67
  ### JS
54
68
  ```js
55
- import { Input } from '@substrate-system/input'
69
+ import '@substrate-system/input'
70
+ ```
56
71
 
57
- class FooBar extends Input {
58
- static tag = 'foo-bar'
59
- }
72
+ ### HTML
73
+ ```html
74
+ <div>
75
+ <substrate-input></substrate-input>
76
+ </div>
77
+ ```
60
78
 
61
- // Use the static method `define`
62
- FooBar.define()
79
+ ### pre-built
80
+ This package exposes minified JS and CSS files too. Copy them to a location that is
81
+ accessible to your web server, then link to them in HTML.
82
+
83
+ #### copy
84
+ ```sh
85
+ cp ./node_modules/@substrate-system/input/dist/index.min.js ./public/substrate-input.min.js
86
+ cp ./node_modules/@substrate-system/input/dist/style.min.css ./public/substrate-input.css
87
+ ```
63
88
 
64
- document.body.innerHTML += `
65
- <foo-bar></foo-bar>
66
- `
89
+ #### HTML
90
+ ```html
91
+ <head>
92
+ <link rel="stylesheet" href="./substrate-input.css">
93
+ </head>
94
+ <body>
95
+ <!-- ... -->
96
+ <script type="module" src="./substrate-input.min.js"></script>
97
+ </body>
67
98
  ```
package/dist/index.cjs CHANGED
@@ -19,169 +19,153 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var index_exports = {};
21
21
  __export(index_exports, {
22
- Input: () => Input
22
+ SubstrateInput: () => SubstrateInput
23
23
  });
24
24
  module.exports = __toCommonJS(index_exports);
25
- class Input extends HTMLElement {
25
+ var import_web_component = require("@substrate-system/web-component");
26
+ var import_util = require("@substrate-system/web-component/util");
27
+ var import_util2 = require("./util");
28
+ class SubstrateInput extends import_web_component.WebComponent.create("substrate-input") {
26
29
  static {
27
- __name(this, "Input");
28
- }
29
- // for `attributeChangedCallback`
30
- static observedAttributes = ["autofocus", "disabled"];
31
- static TAG;
32
- static define() {
33
- if (!("customElements" in window)) return;
34
- if (customElements.get(this.TAG)) return;
35
- return customElements.define(this.TAG, this);
36
- }
37
- constructor() {
38
- super();
39
- const disabled = this.getAttribute("disabled");
40
- if (disabled !== null) {
41
- setTimeout(() => {
42
- this.disabled = true;
43
- }, 0);
44
- }
45
- setTimeout(() => {
46
- const attr = this.getAttribute("value");
47
- if (attr) this.value = attr;
48
- const type = this.getAttribute("type");
49
- if (type) this.type = type;
50
- }, 0);
51
- }
52
- get input() {
53
- return this.querySelector("input");
54
- }
55
- get tabindex() {
56
- const i = this.input?.getAttribute("tabindex");
57
- if (!i) return 0;
58
- return parseInt(i);
59
- }
60
- get name() {
61
- return this.getAttribute("name");
62
- }
63
- get placeholder() {
64
- return this.getAttribute("placeholder");
65
- }
66
- get autocomplete() {
67
- return this.getAttribute("autocomplete");
68
- }
69
- set name(newName) {
70
- this.setAttribute("name", newName);
71
- }
72
- /**
73
- * Remove from `this` element and also child.
74
- */
75
- _removeAttribute(name) {
76
- this.removeAttribute(name);
77
- this.input?.removeAttribute(name);
30
+ __name(this, "SubstrateInput");
31
+ }
32
+ static TAG = "substrate-input";
33
+ static INPUT_ATTRIBUTES = import_util2.INPUT_ATTRIBUTES;
34
+ static ARIA_ATTRIBUTES = import_util2.ARIA_ATTRIBUTES;
35
+ static observedAttributes = ["label", "id"].concat(SubstrateInput.INPUT_ATTRIBUTES).concat(SubstrateInput.ARIA_ATTRIBUTES);
36
+ inputId = null;
37
+ inputAriaAttributes = {};
38
+ ignoredAriaCallbackNames = /* @__PURE__ */ new Set();
39
+ ignoredIdCallback = false;
40
+ generatedInputId = `substrate-input-${Math.random().toString(36).slice(2, 10)}`;
41
+ handleChange_label(_oldValue, _newValue) {
42
+ this.render();
78
43
  }
79
- get disabled() {
80
- return !!this.input?.hasAttribute("disabled");
44
+ handleChange_aria(name, _oldValue, newValue) {
45
+ if (this.ignoredAriaCallbackNames.has(name)) {
46
+ this.ignoredAriaCallbackNames.delete(name);
47
+ return;
48
+ }
49
+ if (newValue === null) {
50
+ delete this.inputAriaAttributes[name];
51
+ this.querySelector("input")?.removeAttribute(name);
52
+ return;
53
+ }
54
+ this.inputAriaAttributes[name] = newValue;
55
+ this.querySelector("input")?.setAttribute(name, newValue);
56
+ if (this.hasAttribute(name)) {
57
+ this.ignoredAriaCallbackNames.add(name);
58
+ this.removeAttribute(name);
59
+ }
81
60
  }
82
- set disabled(disabledValue) {
83
- if (!disabledValue) {
84
- this._removeAttribute("disabled");
85
- this.input?.setAttribute("aria-disabled", "false");
86
- } else {
87
- this.input?.setAttribute("disabled", "");
88
- this.input?.setAttribute("aria-disabled", "true");
61
+ handleChange_id(_oldValue, newValue) {
62
+ if (this.ignoredIdCallback) {
63
+ this.ignoredIdCallback = false;
64
+ return;
65
+ }
66
+ if (newValue === null) {
67
+ this.inputId = null;
68
+ this.querySelector("input")?.removeAttribute("id");
69
+ return;
70
+ }
71
+ this.inputId = newValue;
72
+ this.querySelector("input")?.setAttribute("id", newValue);
73
+ if (this.hasAttribute("id")) {
74
+ this.ignoredIdCallback = true;
75
+ this.removeAttribute("id");
89
76
  }
90
77
  }
91
- /**
92
- * Handle 'example' attribute changes
93
- * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
94
- *
95
- * @param {string|null} _oldValue The old attribute value
96
- * @param {string|null} newValue The new attribute value
97
- */
98
- handleChange_disabled(_oldValue, newValue) {
99
- if (!this.input) {
100
- setTimeout(() => {
101
- if (newValue === null || newValue === "null") {
102
- this.disabled = false;
103
- } else {
104
- this.disabled = true;
105
- }
106
- }, 0);
107
- } else {
108
- if (newValue === null || newValue === "null") {
109
- this.disabled = false;
110
- } else {
111
- this.disabled = true;
112
- }
78
+ handleChange_inputAttribute(name, newValue) {
79
+ const input = this.querySelector("input");
80
+ if (!input) return;
81
+ if (newValue === null) {
82
+ input.removeAttribute(name);
83
+ return;
113
84
  }
85
+ input.setAttribute(name, newValue);
114
86
  }
115
- /**
116
- * Runs when the value of an attribute is changed
117
- *
118
- * @param {string} name The attribute name
119
- * @param {string} oldValue The old attribute value
120
- * @param {string} newValue The new attribute value
121
- */
122
- attributeChangedCallback(name, oldValue, newValue) {
123
- const handler = this[`handleChange_${name}`];
124
- handler && handler.call(this, oldValue, newValue);
125
- this.render();
87
+ async attributeChangedCallback(name, oldValue, newValue) {
88
+ if (name === "id") {
89
+ this.handleChange_id(oldValue, newValue);
90
+ return;
91
+ }
92
+ if (name.startsWith("aria-")) {
93
+ this.handleChange_aria(name, oldValue, newValue);
94
+ return;
95
+ }
96
+ if (SubstrateInput.INPUT_ATTRIBUTES.includes(name)) {
97
+ this.handleChange_inputAttribute(name, newValue);
98
+ return;
99
+ }
100
+ if (this[`handleChange_${name}`]) {
101
+ this[`handleChange_${name}`](oldValue, newValue);
102
+ }
126
103
  }
127
104
  connectedCallback() {
128
105
  this.render();
129
106
  }
130
- get type() {
131
- return this.input?.getAttribute("type");
107
+ getInputIdForRender() {
108
+ return this.inputId || this.generatedInputId;
132
109
  }
133
- set type(value) {
134
- this._setAttribute("type", value);
110
+ set label(value) {
111
+ if (value === null) {
112
+ this.removeAttribute("label");
113
+ return;
114
+ }
115
+ this.setAttribute("label", value);
135
116
  }
136
- get value() {
137
- return this.input?.value;
117
+ get label() {
118
+ return this.getAttribute("label");
138
119
  }
139
- set value(text) {
140
- if (!text) this.input?.removeAttribute("value");
141
- else {
142
- this.input.value = text;
120
+ render() {
121
+ const label = this.getAttribute("label");
122
+ const hostId = this.getAttribute("id");
123
+ const hostAriaAttributes = Array.from(this.attributes).filter((attr) => attr.name.startsWith("aria-"));
124
+ if (hostId !== null) {
125
+ this.inputId = hostId;
143
126
  }
144
- }
145
- /**
146
- * Set attributes on the internal input element.
147
- */
148
- _setAttribute(name, value) {
149
- if (!value) {
150
- return this._removeAttribute(name);
127
+ for (const attr of hostAriaAttributes) {
128
+ this.inputAriaAttributes[attr.name] = attr.value;
151
129
  }
152
- if (value === true) {
153
- return this.input?.setAttribute(name, "");
130
+ const name = this.getAttribute("name");
131
+ const attrs = Array.from(this.attributes).filter(
132
+ (attr) => attr.name !== "label" && attr.name !== "id" && !attr.name.startsWith("aria-")
133
+ ).map(
134
+ (attr) => attr.name + (attr.value === "" ? "" : `="${attr.value}"`)
135
+ ).join(" ");
136
+ const classes = (this.getAttribute("class") ?? "").split(" ").concat(["substrate", "input", name || ""]).filter(Boolean).join(" ");
137
+ const inputId = this.getInputIdForRender();
138
+ const renderedIdAttribute = `id="${inputId}"`;
139
+ const ariaAttributes = Object.entries(this.inputAriaAttributes).map(([attrName, attrValue]) => {
140
+ return attrName + (attrValue === "" ? "" : `="${attrValue}"`);
141
+ }).join(" ");
142
+ this.innerHTML = label ? `
143
+ <div class="${classes}">
144
+ <label class="label-content" for="${inputId}">${label}</label>
145
+ <input
146
+ ${renderedIdAttribute}
147
+ ${ariaAttributes}
148
+ ${attrs}
149
+ />
150
+ </div>
151
+ ` : `
152
+ <div class="${classes}">
153
+ <input
154
+ ${renderedIdAttribute}
155
+ ${ariaAttributes}
156
+ ${attrs}
157
+ />
158
+ </div>
159
+ `;
160
+ if (this.hasAttribute("id")) {
161
+ this.ignoredIdCallback = true;
162
+ this.removeAttribute("id");
163
+ }
164
+ for (const attr of hostAriaAttributes) {
165
+ this.ignoredAriaCallbackNames.add(attr.name);
166
+ this.removeAttribute(attr.name);
154
167
  }
155
- this.input?.setAttribute(name, value);
156
- }
157
- render() {
158
- const {
159
- type,
160
- autofocus,
161
- tabindex,
162
- disabled,
163
- value,
164
- name,
165
- placeholder,
166
- autocomplete
167
- } = this;
168
- if (!name) throw new Error("not name");
169
- const classes = ["substrate-input"];
170
- const btn = !!(this.type === "submit" || this.type === "button");
171
- const props = [
172
- `class="${classes.filter(Boolean).join(" ")}"`,
173
- disabled ? "disabled" : "",
174
- disabled ? 'aria-disabled="true"' : 'aria-disabled="false"',
175
- autofocus ? "autofocus" : "",
176
- type ? `type="${this.type}"` : "",
177
- tabindex ? `tabindex="${tabindex}"` : 'tabindex="0"',
178
- btn ? 'role="button"' : "",
179
- value ? `value="${value}"` : "",
180
- name ? `name="${name}"` : "",
181
- autocomplete ? `autocomplete="${autocomplete}"` : "",
182
- placeholder ? `placeholder="${placeholder}"` : ""
183
- ].filter(Boolean).join(" ");
184
- return `<input ${props} />`;
185
168
  }
186
169
  }
170
+ (0, import_util.define)(SubstrateInput.TAG, SubstrateInput);
187
171
  //# sourceMappingURL=index.cjs.map