@nvidia-elements/forms 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/NOTICE.md +1 -39
- package/dist/custom-elements.json +1293 -254
- package/dist/examples/csv.examples.js.map +1 -1
- package/dist/examples/light.examples.js.map +1 -1
- package/dist/examples/simple.examples.js.map +1 -1
- package/dist/examples/visualization.examples.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/controllers/state-active.controller.d.ts +13 -0
- package/dist/internal/controllers/state-active.controller.js +26 -0
- package/dist/internal/controllers/state-active.controller.js.map +1 -0
- package/dist/internal/controllers/state-current.controller.d.ts +15 -0
- package/dist/internal/controllers/state-current.controller.js +34 -0
- package/dist/internal/controllers/state-current.controller.js.map +1 -0
- package/dist/internal/controllers/state-disabled.controller.d.ts +18 -0
- package/dist/internal/controllers/state-disabled.controller.js +17 -0
- package/dist/internal/controllers/state-disabled.controller.js.map +1 -0
- package/dist/internal/controllers/state-expanded.controller.d.ts +12 -0
- package/dist/internal/controllers/state-expanded.controller.js +17 -0
- package/dist/internal/controllers/state-expanded.controller.js.map +1 -0
- package/dist/internal/controllers/state-pressed.controller.d.ts +12 -0
- package/dist/internal/controllers/state-pressed.controller.js +17 -0
- package/dist/internal/controllers/state-pressed.controller.js.map +1 -0
- package/dist/internal/controllers/state-readonly.controller.d.ts +12 -0
- package/dist/internal/controllers/state-readonly.controller.js +17 -0
- package/dist/internal/controllers/state-readonly.controller.js.map +1 -0
- package/dist/internal/controllers/state-selected.controller.d.ts +15 -0
- package/dist/internal/controllers/state-selected.controller.js +34 -0
- package/dist/internal/controllers/state-selected.controller.js.map +1 -0
- package/dist/internal/controllers/type-anchor.controller.d.ts +15 -0
- package/dist/internal/controllers/type-anchor.controller.js +51 -0
- package/dist/internal/controllers/type-anchor.controller.js.map +1 -0
- package/dist/internal/controllers/type-button.controller.d.ts +14 -0
- package/dist/internal/controllers/type-button.controller.js +22 -0
- package/dist/internal/controllers/type-button.controller.js.map +1 -0
- package/dist/internal/controllers/type-command.controller.d.ts +16 -0
- package/dist/internal/controllers/type-command.controller.js +36 -0
- package/dist/internal/controllers/type-command.controller.js.map +1 -0
- package/dist/internal/controllers/type-interest-invoker.controller.d.ts +12 -0
- package/dist/internal/controllers/type-interest-invoker.controller.js +38 -0
- package/dist/internal/controllers/type-interest-invoker.controller.js.map +1 -0
- package/dist/internal/controllers/type-native-button.controller.d.ts +19 -0
- package/dist/internal/controllers/type-native-button.controller.js +54 -0
- package/dist/internal/controllers/type-native-button.controller.js.map +1 -0
- package/dist/internal/controllers/type-popover-trigger.controller.d.ts +16 -0
- package/dist/internal/controllers/type-popover-trigger.controller.js +21 -0
- package/dist/internal/controllers/type-popover-trigger.controller.js.map +1 -0
- package/dist/internal/controllers/types.d.ts +8 -0
- package/dist/internal/errors.js.map +1 -1
- package/dist/internal/schema.js.map +1 -1
- package/dist/internal/types.d.ts +18 -4
- package/dist/internal/utils.d.ts +17 -0
- package/dist/internal/utils.js +53 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/mixins/button.d.ts +22 -0
- package/dist/mixins/button.js +344 -0
- package/dist/mixins/button.js.map +1 -0
- package/dist/mixins/button.types.d.ts +121 -0
- package/dist/mixins/checkbox.d.ts +41 -0
- package/dist/mixins/checkbox.js +109 -0
- package/dist/mixins/checkbox.js.map +1 -0
- package/dist/mixins/control.d.ts +189 -0
- package/dist/mixins/control.js +358 -0
- package/dist/mixins/control.js.map +1 -0
- package/dist/mixins/index.d.ts +5 -0
- package/dist/mixins/index.js +6 -0
- package/dist/mixins/select.d.ts +49 -0
- package/dist/mixins/select.js +80 -0
- package/dist/mixins/select.js.map +1 -0
- package/dist/mixins/slider.d.ts +62 -0
- package/dist/mixins/slider.js +175 -0
- package/dist/mixins/slider.js.map +1 -0
- package/dist/validators/index.js.map +1 -1
- package/package.json +22 -16
- package/dist/mixin/index.d.ts +0 -460
- package/dist/mixin/index.js +0 -188
- package/dist/mixin/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csv.examples.js","names":["#getCSV"],"sources":["../../src/examples/csv.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { css, html, LitElement, nothing } from 'lit';\nimport type { ValidatorResult } from '@nvidia-elements/forms';\nimport { FormControlMixin } from '@nvidia-elements/forms/
|
|
1
|
+
{"version":3,"file":"csv.examples.js","names":["#getCSV"],"sources":["../../src/examples/csv.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { css, html, LitElement, nothing } from 'lit';\nimport type { ValidatorResult } from '@nvidia-elements/forms';\nimport { FormControlMixin } from '@nvidia-elements/forms/mixins';\nimport '@nvidia-elements/core/textarea/define.js';\nimport '@nvidia-elements/core/dropdown/define.js';\nimport '@nvidia-elements/core/checkbox/define.js';\nimport '@nvidia-elements/core/grid/define.js';\nimport './csv.examples.js';\n\nexport default {\n title: 'Labs/Forms/Examples',\n component: ['forms']\n};\n\n/**\n * @summary CSV grid form control with input validation and editable textarea.\n * @tags test-case\n */\nexport const CSV = {\n render: () => html`\n <style>\n ui-csv-grid:invalid {\n outline: 2px dashed red;\n }\n </style>\n <form nve-layout=\"grid span:6 gap:lg pad:lg align:stretch align:center\" style=\"min-width: 1000px;\">\n <nve-textarea style=\"width: max-content\">\n <label>CSV</label>\n <textarea name=\"input\" rows=\"20\" cols=\"50\">${csv}</textarea>\n </nve-textarea>\n <nve-divider orientation=\"vertical\"></nve-divider>\n <ui-csv-grid name=\"csv\"></ui-csv-grid>\n </form>\n <script type=\"module\">\n const form = document.querySelector('form');\n form.elements.csv.value = form.elements.input.value;\n form.addEventListener('input', (e) => {\n form.elements.csv.value = form.elements.input.value;\n });\n </script>\n `\n};\n\nconst csv = `\nresource_id,cpu_usage_percent,memory_usage_gb,storage_used_tb,network_traffic_gb\ninstance-001,45.2,8.5,2.3,156.7\ninstance-002,78.9,12.3,4.1,289.4\ninstance-003,23.4,4.2,1.5,89.3\ninstance-004,92.1,16.7,5.8,412.6\ninstance-005,34.7,6.8,2.9,178.2\ninstance-006,67.8,10.1,3.7,256.9\ninstance-007,12.5,2.9,0.8,45.6\ninstance-008,88.3,14.5,4.9,378.1\ninstance-009,56.4,9.2,3.2,198.5\ninstance-010,41.2,7.6,2.5,167.8`.trim();\n\nexport type CSVValue = string;\n\nexport class CSVExample extends FormControlMixin<typeof LitElement, CSVValue>(LitElement) {\n static readonly metadata = {\n tag: 'ui-csv-grid',\n version: '0.0.0',\n validators: [csvStringValidator],\n valueSchema: {\n type: 'string' as const\n },\n };\n\n static styles = [\n css`:host {\n display: block;\n width: 100%;\n }`\n ];\n\n get #getCSV() {\n const rows = this.value!.trim().split('\\n');\n return {\n columns: rows[0]!.split(','),\n rows: rows.slice(1).map(row => row.split(','))\n };\n }\n\n render() {\n return this.value\n ? html`\n <nve-grid>\n <nve-grid-header>\n ${this.#getCSV.columns.map(column => html`<nve-grid-column>${column}</nve-grid-column>`)}\n </nve-grid-header>\n ${this.#getCSV.rows.map(row => html`<nve-grid-row>${row.map(cell => html`<nve-grid-cell>${cell}</nve-grid-cell>`)}</nve-grid-row>`)}\n </nve-grid>\n `\n : nothing;\n }\n}\n\ncustomElements.get('ui-csv-grid') || customElements.define('ui-csv-grid', CSVExample);\n\nfunction csvStringValidator(value: unknown): ValidatorResult {\n const message = isValidCSV(value as string);\n if (message !== true) {\n return { validity: { badInput: true }, message };\n } else {\n return { validity: {} };\n }\n}\n\nfunction hasUnclosedQuotes(line: string): boolean {\n let inQuotes = false;\n for (let j = 0; j < line.length; j++) {\n if (line[j] === '\"' && !(j > 0 && line[j - 1] === '\\\\')) {\n inQuotes = !inQuotes;\n }\n }\n return inQuotes;\n}\n\nfunction countColumns(line: string): number {\n return (line.match(/,/g) || []).length + 1;\n}\n\nfunction validateLine(line: string, expectedColumns: number): true | string {\n if (hasUnclosedQuotes(line)) {\n return 'csv contains unclosed quotes';\n }\n\n if (countColumns(line) !== expectedColumns) {\n return 'csv contains invalid column count';\n }\n\n return true;\n}\n\nfunction isValidCSV(csvString: string): true | string {\n if (!csvString || csvString.trim().length === 0) {\n return 'empty';\n }\n\n const lines = csvString.split('\\n');\n const columnCount = countColumns(lines[0]!);\n\n for (const line of lines) {\n if (line.trim().length === 0) {\n continue;\n }\n\n const result = validateLine(line, columnCount);\n if (result !== true) {\n return result;\n }\n }\n\n return true;\n}\n"],"mappings":";AAGA,IAAA,IAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"light.examples.js","names":["#updateValue"],"sources":["../../src/examples/light.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { html, LitElement, nothing, unsafeCSS } from 'lit';\nimport { FormControlMixin } from '@nvidia-elements/forms/
|
|
1
|
+
{"version":3,"file":"light.examples.js","names":["#updateValue"],"sources":["../../src/examples/light.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { html, LitElement, nothing, unsafeCSS } from 'lit';\nimport { FormControlMixin } from '@nvidia-elements/forms/mixins';\nimport './light.examples.js';\n\nexport default {\n title: 'Labs/Forms/Examples'\n};\n\n/**\n * @summary Light card form control with toggle and dim range inputs.\n * @tags test-case\n */\nexport const CardToggle = {\n render: () => html`\n<form nve-layout=\"column gap:lg pad:lg\">\n <ui-light-card value='{\"status\": \"on\", \"dim\": 75}' name=\"office-light\"></ui-light-card>\n <pre id=\"light-card-value\"></pre>\n</form>\n\n<script type=\"module\">\n const form = document.querySelector('form');\n const pre = document.querySelector('#light-card-value');\n const lightCard = document.querySelector('ui-light-card[name=\"office-light\"]');\n pre.textContent = JSON.stringify(lightCard.value, null, 2);\n\n form.addEventListener('change', (e) => {\n pre.textContent = JSON.stringify(lightCard.value, null, 2);\n console.log('change', e.target.value, Object.fromEntries(new FormData(form)));\n });\n\n form.addEventListener('input', (e) => {\n pre.textContent = JSON.stringify(lightCard.value, null, 2);\n console.log('input', e.target.value, Object.fromEntries(new FormData(form)));\n });\n</script>\n`\n};\n\n/**\n * @summary Light card form events including submit, reset, and invalid state handling.\n * @tags test-case\n */\nexport const Events = {\n render: () => html`\n<form id=\"novalidate-form\" nve-layout=\"column gap:lg pad:lg\">\n <ui-light-card novalidate name=\"novalidate-light\" value='{\"status\": \"on\", \"dim\": 75}'></ui-light-card>\n <pre></pre>\n <div nve-layout=\"row gap:sm\">\n <button type=\"button\">set invalid value</button>\n <button type=\"reset\">reset</button>\n <button type=\"submit\">submit</button>\n </div>\n</form>\n\n<script type=\"module\">\n const form = document.querySelector('#novalidate-form');\n const pre = form.querySelector('pre');\n const button = form.querySelector('button');\n const light = form.querySelector('[name=\"novalidate-light\"]');\n pre.textContent = JSON.stringify(light.value, null, 2);\n\n button.addEventListener('click', () => {\n light.value = { status: 'invalid', dim: -1 };\n });\n\n form.addEventListener('change', (e) => {\n pre.textContent = JSON.stringify(light.value, null, 2);\n console.log('change', e.target.value);\n });\n\n form.addEventListener('input', (e) => {\n pre.textContent = JSON.stringify(light.value, null, 2);\n console.log('input', e.target.value);\n });\n\n form.addEventListener('submit', (e) => {\n e.preventDefault();\n pre.textContent = JSON.stringify(light.value, null, 2);\n console.log('submit', Object.fromEntries(new FormData(form)));\n });\n\n form.addEventListener('reset', (e) => {\n // reset event fires before the value is reset\n setTimeout(() => {\n pre.textContent = JSON.stringify(light.value, null, 2);\n console.log('reset', Object.fromEntries(new FormData(form)));\n });\n });\n\n light.addEventListener('invalid', (e) => {\n pre.textContent = JSON.stringify(light.value, null, 2);\n console.log('invalid', Object.fromEntries(new FormData(form)));\n });\n</script>\n`\n};\n\nconst styles = /* css */ `\n:host,\n*,\n*:before,\n*:after {\n box-sizing: border-box;\n}\n\n:host {\n display: block;\n max-width: 240px;\n}\n\n:host(:invalid) {\n outline: 2px dashed red;\n}\n\nform {\n position: relative;\n min-width: 50px;\n min-height: 50px;\n display: flex;\n align-items: center;\n gap: var(--nve-ref-space-xs);\n background: var(--nve-sys-interaction-background-200);\n padding: var(--nve-ref-size-300);\n border-radius: var(--nve-ref-border-radius-lg);\n}\n\nnve-icon {\n position: absolute;\n top: 16px;\n left: 16px;\n pointer-events: none;\n z-index: 99;\n}\n\ninput[name='status'] {\n opacity: 0;\n height: 20px;\n width: 20px;\n}\n`;\n\nexport interface LightCardValue {\n status: 'off' | 'on';\n dim: number;\n}\n\n/**\n * Custom element integrating the FormControlMixin with LitElement for form validation.\n */\nexport class LightCard extends FormControlMixin<typeof LitElement, LightCardValue>(LitElement) {\n static readonly metadata = {\n tag: 'ui-light-card',\n version: '0.0.0',\n strict: false,\n valueSchema: {\n type: 'object' as const,\n properties: {\n status: {\n type: 'enum' as const,\n enum: ['off', 'on']\n },\n dim: {\n type: 'number' as const,\n minimum: 0,\n maximum: 100\n }\n },\n required: ['status', 'dim']\n }\n };\n\n static styles = unsafeCSS(styles);\n\n render() {\n return this.value\n ? html`\n <form @input=${this.#updateValue} @change=${this.#updateValue}>\n <nve-icon size=\"lg\" name=\"lightbulb\" style=\"--color: ${this.value.status === 'on' ? 'var(--nve-ref-color-yellow-nova-900)' : 'initial'}; opacity: ${this.value.status === 'on' ? this.value.dim / 100 + 0.3 : 0.5};\"></nve-icon>\n ${\n this.readOnly\n ? nothing\n : html`\n <input type=\"checkbox\" name=\"status\" .checked=${this.value.status === 'on'} ?disabled=${this.readOnly} aria-label=\"Light Status\">\n <input type=\"range\" name=\"dim\" .valueAsNumber=${this.value.dim} ?disabled=${this.readOnly} min=${LightCard.metadata.valueSchema.properties.dim.minimum ?? 0} max=${LightCard.metadata.valueSchema.properties.dim.maximum ?? 100} aria-label=\"Light Dim\">\n `\n }\n </form>`\n : nothing;\n }\n\n constructor() {\n super();\n this.value = { status: 'off', dim: 50 };\n }\n\n #updateValue(event: Event) {\n const form = this.shadowRoot?.querySelector('form') as HTMLFormElement;\n this.value = { status: form.status.checked ? 'on' : 'off', dim: form.dim.valueAsNumber };\n this.dispatchUpdateEvent(event.type as 'input' | 'change');\n }\n}\n\ncustomElements.get('ui-light-card') ?? customElements.define('ui-light-card', LightCard);"],"mappings":";AAGA,IAAA,IAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple.examples.js","names":["#updateValue"],"sources":["../../src/examples/simple.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { css, html, LitElement, nothing } from 'lit';\nimport { FormControlMixin } from '@nvidia-elements/forms/
|
|
1
|
+
{"version":3,"file":"simple.examples.js","names":["#updateValue"],"sources":["../../src/examples/simple.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { css, html, LitElement, nothing } from 'lit';\nimport { FormControlMixin } from '@nvidia-elements/forms/mixins';\n\nexport default {\n title: 'Labs/Forms/Examples'\n};\n\n/**\n * @summary Quality control form with checkbox inputs and schema-based validation.\n * @tags test-case\n */\nexport const QualityCheck = {\n render: () => html`\n<form nve-layout=\"column gap:lg pad:lg\">\n <ui-quality-control value='{\"good\": true, \"fast\": true, \"cheap\": false}' name=\"quality\"></ui-quality-control>\n <pre id=\"quality-control-value\"></pre>\n</form>\n\n<script type=\"module\">\n const form = document.querySelector('form');\n const pre = document.querySelector('#quality-control-value');\n const qualityControl = document.querySelector('ui-quality-control[name=\"quality\"]');\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n\n form.addEventListener('change', (e) => {\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n console.log('change', e.target.value, Object.fromEntries(new FormData(form)));\n });\n\n form.addEventListener('input', (e) => {\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n console.log('input', e.target.value, Object.fromEntries(new FormData(form)));\n });\n</script>\n`\n};\n\n/**\n * @summary Quality control form events with strict mode toggle and invalid state handling.\n * @tags test-case\n */\nexport const Events = {\n render: () => html`\n<form id=\"simple-events-form\" nve-layout=\"column gap:lg pad:lg\">\n <ui-quality-control name=\"quality\" value='{\"good\": true, \"fast\": true, \"cheap\": false}'></ui-quality-control>\n <pre></pre>\n <div nve-layout=\"row gap:sm\">\n <button type=\"button\">set invalid value</button>\n <button type=\"reset\">reset</button>\n <button type=\"submit\">submit</button>\n <label>\n <input type=\"checkbox\" name=\"strict\" checked />\n strict mode\n </label>\n </div>\n</form>\n\n<script type=\"module\">\n const form = document.querySelector('#simple-events-form');\n const pre = form.querySelector('pre');\n const button = form.querySelector('button');\n const qualityControl = form.querySelector('[name=\"quality\"]');\n const strict = form.querySelector('[name=\"strict\"]');\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n\n strict.addEventListener('change', (e) => {\n qualityControl.constructor.metadata.strict = e.target.checked;\n });\n\n button.addEventListener('click', () => {\n qualityControl.value = { good: true, fast: true, cheap: true };\n console.log('click', qualityControl.value);\n });\n\n form.addEventListener('change', (e) => {\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n console.log('change', e.target.value);\n });\n\n form.addEventListener('input', (e) => {\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n console.log('input', e.target.value);\n });\n\n form.addEventListener('submit', (e) => {\n e.preventDefault();\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n console.log('submit', Object.fromEntries(new FormData(form)));\n });\n\n form.addEventListener('reset', (e) => {\n // reset event fires before the value is reset\n setTimeout(() => {\n pre.textContent = JSON.stringify(qualityControl.value, null, 2);\n console.log('reset', Object.fromEntries(new FormData(form)));\n });\n });\n\n qualityControl.addEventListener('invalid', (e) => {\n console.log('invalid', Object.fromEntries(new FormData(form)));\n });\n</script>\n`\n};\n\nexport interface QualityControlValue {\n good: boolean;\n fast: boolean;\n cheap: boolean;\n}\n\nfunction qualityValidator(value: unknown) {\n const v = value as QualityControlValue;\n if (v.good && v.fast && v.cheap) {\n return {\n validity: { badInput: true },\n message: 'at least one value must be false'\n };\n }\n return { validity: { } };\n}\n\n/**\n * Custom element integrating the FormControlMixin with LitElement for form validation.\n */\nexport class QualityControl extends FormControlMixin<typeof LitElement, QualityControlValue>(LitElement) {\n static styles = [\n css`\n :host {\n display: block;\n }\n\n :host(:invalid) {\n outline: 2px dashed red;\n }\n `\n ];\n\n static readonly metadata = {\n tag: 'ui-quality-control',\n version: '0.0.0',\n strict: true,\n validators: [qualityValidator],\n valueSchema: {\n type: 'object' as const,\n properties: {\n good: {\n type: 'boolean' as const\n },\n fast: {\n type: 'boolean' as const\n },\n cheap: {\n type: 'boolean' as const\n }\n },\n required: ['good', 'fast', 'cheap']\n }\n };\n\n render() {\n return this.value\n ? html`\n <form @input=${this.#updateValue} @change=${this.#updateValue}>\n <label>\n <input type=\"checkbox\" name=\"good\" .checked=${this.value.good} ?disabled=${this.disabled || this.readOnly} aria-label=\"Good\">\n Good\n </label>\n <label>\n <input type=\"checkbox\" name=\"fast\" .checked=${this.value.fast} ?disabled=${this.disabled || this.readOnly} aria-label=\"Fast\">\n Fast\n </label>\n <label>\n <input type=\"checkbox\" name=\"cheap\" .checked=${this.value.cheap} ?disabled=${this.disabled || this.readOnly} aria-label=\"Cheap\">\n Cheap\n </label>\n </form>`\n : nothing;\n }\n\n constructor() {\n super();\n this.value = { good: true, fast: true, cheap: true };\n }\n\n #updateValue(event: Event) {\n const form = this.shadowRoot?.querySelector('form') as HTMLFormElement;\n this.value = { good: form.good.checked, fast: form.fast.checked, cheap: form.cheap.checked };\n this.dispatchUpdateEvent(event.type as 'input' | 'change');\n }\n}\n\ncustomElements.get('ui-quality-control') ?? customElements.define('ui-quality-control', QualityControl);"],"mappings":";AAGA,IAAA,IAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visualization.examples.js","names":["#canvas","#startAnimation","#shapes","#animationFrame","#render"],"sources":["../../src/examples/visualization.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { css, html, LitElement, nothing } from 'lit';\nimport { FormControlMixin } from '@nvidia-elements/forms/
|
|
1
|
+
{"version":3,"file":"visualization.examples.js","names":["#canvas","#startAnimation","#shapes","#animationFrame","#render"],"sources":["../../src/examples/visualization.examples.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { css, html, LitElement, nothing } from 'lit';\nimport { FormControlMixin } from '@nvidia-elements/forms/mixins';\nimport '@nvidia-elements/core/color/define.js';\nimport '@nvidia-elements/core/radio/define.js';\nimport '@nvidia-elements/core/range/define.js';\nimport './visualization.examples.js';\n\nexport default {\n title: 'Labs/Forms/Examples'\n};\n\n/**\n * @summary Animated canvas visualization driven by form controls for color, shape, scale, and particle count.\n * @tags test-case\n */\nexport const CanvasParticles = {\n render: () => html`\n<section nve-layout=\"row gap:lg pad:lg align:center\">\n <form nve-layout=\"column gap:lg pad:lg\">\n <nve-color>\n <label>Color</label>\n <input type=\"color\" name=\"color\" value=\"#26ab40\" />\n </nve-color>\n <nve-radio-group>\n <label>Shape</label>\n <nve-radio>\n <label>Circle</label>\n <input type=\"radio\" name=\"shape\" value=\"circle\" checked/>\n </nve-radio>\n <nve-radio>\n <label>Square</label>\n <input type=\"radio\" name=\"shape\" value=\"square\" />\n </nve-radio>\n </nve-radio-group>\n <nve-range>\n <label>Scale</label>\n <input type=\"range\" name=\"scale\" value=\"20\" min=\"5\" max=\"100\" />\n </nve-range>\n <nve-range>\n <label>Particle Count</label>\n <input type=\"range\" name=\"particleCount\" value=\"100\" min=\"1\" max=\"10000\" />\n </nve-range>\n </form>\n <nve-divider orientation=\"vertical\"></nve-divider>\n <ui-entity-draw name=\"draw\" value='{\"color\": \"#26ab40\", \"shape\": \"circle\", \"scale\": 20, \"particleCount\": 100}'></ui-entity-draw>\n</section>\n<script type=\"module\">\n const form = document.querySelector('form');\n const draw = document.querySelector('ui-entity-draw');\n form.addEventListener('input', (e) => {\n draw.value = {\n color: form.elements.color.value,\n shape: form.elements.shape.value,\n scale: form.elements.scale.valueAsNumber,\n particleCount: form.elements.particleCount.valueAsNumber\n }\n });\n</script>\n`\n};\n\nconst styles = css`\n:host {\n display: block;\n}\n\nform {\n background: var(--nve-sys-layer-container-background);\n display: flex;\n flex-direction: column;\n gap: 6px;\n padding: 1rem;\n border-radius: 0.5rem;\n box-shadow: 0 0 0.5rem 0 rgba(0, 0, 0, 0.1);\n}\n\nlabel {\n display: flex;\n align-items: center;\n line-height: 1;\n gap: 0.5rem;\n}\n\ninput {\n margin: 4px 0;\n}\n\npre {\n background: color-mix(in oklab, var(--nve-sys-layer-container-background) 100%, var(--nve-sys-text-muted-color) 7%);\n padding: 12px;\n margin: 0;\n}\n`;\n\nexport interface DrawValue {\n color: string;\n shape: 'circle' | 'square';\n scale: number;\n particleCount: number;\n}\n\nexport class Draw extends FormControlMixin<typeof LitElement, DrawValue>(LitElement) {\n static readonly metadata = {\n version: '0.0.0',\n tag: 'ui-entity-draw',\n valueSchema: {\n type: 'object' as const,\n properties: {\n color: {\n type: 'string' as const,\n format: 'color'\n },\n shape: {\n type: 'enum' as const,\n enum: ['circle', 'square']\n },\n scale: {\n type: 'number' as const,\n minimum: 1,\n maximum: 100\n },\n particleCount: {\n type: 'number' as const,\n minimum: 1,\n maximum: 10000\n }\n },\n required: ['color', 'shape', 'scale', 'particleCount']\n }\n };\n\n static styles = [\n styles,\n css`canvas {border: var(--nve-ref-border-width-sm) solid var(--nve-ref-border-color-muted);}`\n ];\n\n #shapes: Array<{ x: number; y: number; rotation: number }> = [];\n #canvas?: HTMLCanvasElement;\n #animationFrame?: number;\n\n render() {\n return this.value\n ? html`\n <form>\n <canvas name=\"canvas\" width=\"400\" height=\"400\"></canvas>\n <pre>${JSON.stringify(this.value, null, 2)}</pre>\n </form>\n `\n : nothing;\n }\n\n constructor() {\n super();\n this.updateValue({ color: '#000000', shape: 'circle', scale: 50, particleCount: 20 });\n }\n\n firstUpdated() {\n this.#canvas = this.renderRoot.querySelector('canvas') ?? undefined;\n this.#startAnimation();\n }\n\n updated(changedProperties: Map<string, unknown>) {\n super.updated(changedProperties);\n if (this.value && this.value.particleCount !== this.#shapes.length) {\n this.#shapes = new Array(this.value.particleCount).fill(0).map(() => {\n return { x: Math.random() * 400, y: Math.random() * 400, rotation: Math.random() * Math.PI * 2 };\n });\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n if (this.#animationFrame) {\n cancelAnimationFrame(this.#animationFrame);\n }\n }\n\n #startAnimation() {\n const animate = () => {\n if (this.value) {\n this.#render(this.value);\n }\n this.#animationFrame = requestAnimationFrame(animate);\n };\n animate();\n }\n\n #render(value: DrawValue) {\n const ctx = this.#canvas!.getContext('2d')!;\n ctx.clearRect(0, 0, this.#canvas!.width, this.#canvas!.height);\n\n const size = value.scale / 2.5;\n this.#shapes.forEach((shape, i) => {\n shape.y += Math.sin((Date.now() + i * 500) / 1000) * 0.5;\n shape.x += Math.cos((Date.now() + i * 500) / 1000) * 0.5;\n shape.rotation += 0.01;\n shape.x = (shape.x + this.#canvas!.width) % this.#canvas!.width;\n shape.y = (shape.y + this.#canvas!.height) % this.#canvas!.height;\n\n ctx.save();\n ctx.translate(shape.x, shape.y);\n ctx.rotate(shape.rotation);\n ctx.fillStyle = value.color;\n\n if (value.shape === 'circle') {\n ctx.beginPath();\n ctx.arc(0, 0, size / 2, 0, Math.PI * 2);\n ctx.fill();\n } else {\n ctx.fillRect(-size / 2, -size / 2, size, size);\n }\n\n ctx.restore();\n });\n }\n}\n\ncustomElements.get('ui-entity-draw') || customElements.define('ui-entity-draw', Draw);\n"],"mappings":";AAGA,IAAA,IAAc"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type Active = ReactiveElement & {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
_internals?: ElementInternals;
|
|
5
|
+
};
|
|
6
|
+
export declare class StateActiveController<T extends Active> implements ReactiveController {
|
|
7
|
+
#private;
|
|
8
|
+
private host;
|
|
9
|
+
constructor(host: T);
|
|
10
|
+
hostConnected(): void;
|
|
11
|
+
hostDisconnected(): void;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { attachInternals as e } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/state-active.controller.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
e(this.host), this.host.addEventListener("keypress", this.#e), this.host.addEventListener("mousedown", this.#e), this.host.addEventListener("keyup", this.#t), this.host.addEventListener("blur", this.#t), this.host.addEventListener("mouseup", this.#t);
|
|
9
|
+
}
|
|
10
|
+
hostDisconnected() {
|
|
11
|
+
this.host.removeEventListener("keypress", this.#e), this.host.removeEventListener("mousedown", this.#e), this.host.removeEventListener("keyup", this.#t), this.host.removeEventListener("blur", this.#t), this.host.removeEventListener("mouseup", this.#t);
|
|
12
|
+
}
|
|
13
|
+
#e = (e) => {
|
|
14
|
+
!this.host.disabled && this.#n(e) && this.host._internals.states.add("active"), e instanceof KeyboardEvent && e.code === "Space" && e.target === this.host && e.preventDefault();
|
|
15
|
+
};
|
|
16
|
+
#t = () => {
|
|
17
|
+
this.host._internals.states.delete("active");
|
|
18
|
+
};
|
|
19
|
+
#n(e) {
|
|
20
|
+
return e instanceof KeyboardEvent ? e.code === "Space" || e.code === "Enter" : !0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { t as StateActiveController };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=state-active.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-active.controller.js","names":["#onActive","#onInactive","#isValidActiveEvent"],"sources":["../../../src/internal/controllers/state-active.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { attachInternals } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype Active = ReactiveElement & { disabled: boolean; _internals?: ElementInternals };\n\nexport class StateActiveController<T extends Active> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n attachInternals(this.host);\n this.host.addEventListener('keypress', this.#onActive as EventListener);\n this.host.addEventListener('mousedown', this.#onActive as EventListener);\n this.host.addEventListener('keyup', this.#onInactive);\n this.host.addEventListener('blur', this.#onInactive);\n this.host.addEventListener('mouseup', this.#onInactive);\n }\n\n hostDisconnected() {\n this.host.removeEventListener('keypress', this.#onActive as EventListener);\n this.host.removeEventListener('mousedown', this.#onActive as EventListener);\n this.host.removeEventListener('keyup', this.#onInactive);\n this.host.removeEventListener('blur', this.#onInactive);\n this.host.removeEventListener('mouseup', this.#onInactive);\n }\n\n #onActive = (event: KeyboardEvent | PointerEvent) => {\n if (!this.host.disabled && this.#isValidActiveEvent(event)) {\n this.host._internals!.states.add('active');\n }\n\n if (event instanceof KeyboardEvent && event.code === 'Space' && event.target === this.host) {\n event.preventDefault();\n }\n };\n\n #onInactive = () => {\n this.host._internals!.states.delete('active');\n };\n\n #isValidActiveEvent(event: KeyboardEvent | PointerEvent) {\n return event instanceof KeyboardEvent ? event.code === 'Space' || event.code === 'Enter' : true;\n }\n}\n"],"mappings":";;AAQA,IAAa,IAAb,MAAmF;CACjF,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EAMd,AALA,EAAgB,KAAK,IAAI,GACzB,KAAK,KAAK,iBAAiB,YAAY,KAAKA,EAA0B,GACtE,KAAK,KAAK,iBAAiB,aAAa,KAAKA,EAA0B,GACvE,KAAK,KAAK,iBAAiB,SAAS,KAAKC,EAAW,GACpD,KAAK,KAAK,iBAAiB,QAAQ,KAAKA,EAAW,GACnD,KAAK,KAAK,iBAAiB,WAAW,KAAKA,EAAW;CACxD;CAEA,mBAAmB;EAKjB,AAJA,KAAK,KAAK,oBAAoB,YAAY,KAAKD,EAA0B,GACzE,KAAK,KAAK,oBAAoB,aAAa,KAAKA,EAA0B,GAC1E,KAAK,KAAK,oBAAoB,SAAS,KAAKC,EAAW,GACvD,KAAK,KAAK,oBAAoB,QAAQ,KAAKA,EAAW,GACtD,KAAK,KAAK,oBAAoB,WAAW,KAAKA,EAAW;CAC3D;CAEA,MAAa,MAAwC;EAKnD,AAJI,CAAC,KAAK,KAAK,YAAY,KAAKC,GAAoB,CAAK,KACvD,KAAK,KAAK,WAAY,OAAO,IAAI,QAAQ,GAGvC,aAAiB,iBAAiB,EAAM,SAAS,WAAW,EAAM,WAAW,KAAK,QACpF,EAAM,eAAe;CAEzB;CAEA,WAAoB;EAClB,KAAK,KAAK,WAAY,OAAO,OAAO,QAAQ;CAC9C;CAEA,GAAoB,GAAqC;EACvD,OAAO,aAAiB,gBAAgB,EAAM,SAAS,WAAW,EAAM,SAAS,UAAU;CAC7F;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type Current = ReactiveElement & {
|
|
3
|
+
current?: string | null;
|
|
4
|
+
readOnly?: boolean;
|
|
5
|
+
selected?: boolean | null;
|
|
6
|
+
_internals?: ElementInternals;
|
|
7
|
+
};
|
|
8
|
+
export declare class StateCurrentController<T extends Current> implements ReactiveController {
|
|
9
|
+
#private;
|
|
10
|
+
private host;
|
|
11
|
+
constructor(host: T);
|
|
12
|
+
hostConnected(): void;
|
|
13
|
+
hostUpdated(): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { attachInternals as e, toggleState as t } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/state-current.controller.ts
|
|
3
|
+
var n = class {
|
|
4
|
+
#e = null;
|
|
5
|
+
constructor(e) {
|
|
6
|
+
this.host = e, this.host.addController(this);
|
|
7
|
+
}
|
|
8
|
+
hostConnected() {
|
|
9
|
+
e(this.host);
|
|
10
|
+
}
|
|
11
|
+
hostUpdated() {
|
|
12
|
+
if (this.host.readOnly) {
|
|
13
|
+
this.#t();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (this.host._internals?.states.has("anchor")) {
|
|
17
|
+
this.host._internals.ariaCurrent = null, t(this.host._internals, "current", !!this.host.current), this.#t();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.host.current !== null && this.host.current !== void 0 && (this.host._internals.ariaCurrent = `${this.host.current}`), t(this.host._internals, "current", !!this.host.current);
|
|
21
|
+
}
|
|
22
|
+
#t() {
|
|
23
|
+
let e = this.host.querySelector("a"), t = !this.host.readOnly && this.host._internals.states.has("anchor") && !!(this.host.selected || this.host.current);
|
|
24
|
+
if (e && t) {
|
|
25
|
+
this.#e?.removeAttribute("aria-current"), e.setAttribute("aria-current", "page"), this.#e = e;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.#e?.removeAttribute("aria-current"), this.#e = null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { n as StateCurrentController };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=state-current.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-current.controller.js","names":["#syncAnchorCurrentAttribute","#anchorCurrentTarget"],"sources":["../../../src/internal/controllers/state-current.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { attachInternals, toggleState } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype Current = ReactiveElement & {\n current?: string | null;\n readOnly?: boolean;\n selected?: boolean | null;\n _internals?: ElementInternals;\n};\n\nexport class StateCurrentController<T extends Current> implements ReactiveController {\n #anchorCurrentTarget: HTMLAnchorElement | null = null;\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n attachInternals(this.host);\n }\n\n hostUpdated() {\n if (this.host.readOnly) {\n this.#syncAnchorCurrentAttribute();\n return;\n }\n\n if (this.host._internals?.states.has('anchor')) {\n this.host._internals!.ariaCurrent = null;\n toggleState(this.host._internals!, 'current', Boolean(this.host.current));\n this.#syncAnchorCurrentAttribute();\n return;\n }\n\n if (this.host.current !== null && this.host.current !== undefined) {\n this.host._internals!.ariaCurrent = `${this.host.current}`;\n }\n\n toggleState(this.host._internals!, 'current', Boolean(this.host.current));\n }\n\n #syncAnchorCurrentAttribute() {\n const anchor = this.host.querySelector<HTMLAnchorElement>('a');\n const isCurrent =\n !this.host.readOnly &&\n this.host._internals!.states.has('anchor') &&\n Boolean(this.host.selected || this.host.current);\n\n if (anchor && isCurrent) {\n this.#anchorCurrentTarget?.removeAttribute('aria-current');\n anchor.setAttribute('aria-current', 'page');\n this.#anchorCurrentTarget = anchor;\n return;\n }\n\n this.#anchorCurrentTarget?.removeAttribute('aria-current');\n this.#anchorCurrentTarget = null;\n }\n}\n"],"mappings":";;AAaA,IAAa,IAAb,MAAqF;CACnF,KAAiD;CAEjD,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,EAAgB,KAAK,IAAI;CAC3B;CAEA,cAAc;EACZ,IAAI,KAAK,KAAK,UAAU;GACtB,KAAKA,GAA4B;GACjC;EACF;EAEA,IAAI,KAAK,KAAK,YAAY,OAAO,IAAI,QAAQ,GAAG;GAG9C,AAFA,KAAK,KAAK,WAAY,cAAc,MACpC,EAAY,KAAK,KAAK,YAAa,WAAW,EAAQ,KAAK,KAAK,OAAQ,GACxE,KAAKA,GAA4B;GACjC;EACF;EAMA,AAJI,KAAK,KAAK,YAAY,QAAQ,KAAK,KAAK,YAAY,KAAA,MACtD,KAAK,KAAK,WAAY,cAAc,GAAG,KAAK,KAAK,YAGnD,EAAY,KAAK,KAAK,YAAa,WAAW,EAAQ,KAAK,KAAK,OAAQ;CAC1E;CAEA,KAA8B;EAC5B,IAAM,IAAS,KAAK,KAAK,cAAiC,GAAG,GACvD,IACJ,CAAC,KAAK,KAAK,YACX,KAAK,KAAK,WAAY,OAAO,IAAI,QAAQ,KACzC,GAAQ,KAAK,KAAK,YAAY,KAAK,KAAK;EAE1C,IAAI,KAAU,GAAW;GAGvB,AAFA,KAAKC,IAAsB,gBAAgB,cAAc,GACzD,EAAO,aAAa,gBAAgB,MAAM,GAC1C,KAAKA,KAAuB;GAC5B;EACF;EAGA,AADA,KAAKA,IAAsB,gBAAgB,cAAc,GACzD,KAAKA,KAAuB;CAC9B;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type Disabled = ReactiveElement & {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
readOnly?: boolean;
|
|
5
|
+
_internals?: ElementInternals;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Adds disabled support for interactive custom elements including CSS State psuedo-selector :state(disabled) and aria-disabled.
|
|
9
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/states
|
|
10
|
+
* https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled
|
|
11
|
+
*/
|
|
12
|
+
export declare class StateDisabledController<T extends Disabled> implements ReactiveController {
|
|
13
|
+
private host;
|
|
14
|
+
constructor(host: T);
|
|
15
|
+
hostConnected(): void;
|
|
16
|
+
hostUpdated(): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { attachInternals as e } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/state-disabled.controller.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
e(this.host);
|
|
9
|
+
}
|
|
10
|
+
hostUpdated() {
|
|
11
|
+
this.host.disabled !== null && this.host.disabled !== void 0 ? this.host._internals.ariaDisabled = `${this.host.disabled}` : this.host._internals.ariaDisabled = null, this.host.disabled ? this.host._internals.states.add("disabled") : this.host._internals.states.delete("disabled"), this.host.readOnly && (this.host._internals.ariaDisabled = null);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { t as StateDisabledController };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=state-disabled.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-disabled.controller.js","names":[],"sources":["../../../src/internal/controllers/state-disabled.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { attachInternals } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype Disabled = ReactiveElement & { disabled: boolean; readOnly?: boolean; _internals?: ElementInternals };\n\n/**\n * Adds disabled support for interactive custom elements including CSS State psuedo-selector :state(disabled) and aria-disabled.\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/states\n * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled\n */\nexport class StateDisabledController<T extends Disabled> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n attachInternals(this.host);\n }\n\n hostUpdated() {\n if (this.host.disabled !== null && this.host.disabled !== undefined) {\n this.host._internals!.ariaDisabled = `${this.host.disabled}`;\n } else {\n this.host._internals!.ariaDisabled = null;\n }\n\n if (this.host.disabled) {\n this.host._internals!.states.add('disabled');\n } else {\n this.host._internals!.states.delete('disabled');\n }\n\n if (this.host.readOnly) {\n this.host._internals!.ariaDisabled = null;\n }\n }\n}\n"],"mappings":";;AAaA,IAAa,IAAb,MAAuF;CACrF,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,EAAgB,KAAK,IAAI;CAC3B;CAEA,cAAc;EAaZ,AAZI,KAAK,KAAK,aAAa,QAAQ,KAAK,KAAK,aAAa,KAAA,IACxD,KAAK,KAAK,WAAY,eAAe,GAAG,KAAK,KAAK,aAElD,KAAK,KAAK,WAAY,eAAe,MAGnC,KAAK,KAAK,WACZ,KAAK,KAAK,WAAY,OAAO,IAAI,UAAU,IAE3C,KAAK,KAAK,WAAY,OAAO,OAAO,UAAU,GAG5C,KAAK,KAAK,aACZ,KAAK,KAAK,WAAY,eAAe;CAEzC;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type Expanded = ReactiveElement & {
|
|
3
|
+
expanded?: boolean | null;
|
|
4
|
+
_internals?: ElementInternals;
|
|
5
|
+
};
|
|
6
|
+
export declare class StateExpandedController<T extends Expanded> implements ReactiveController {
|
|
7
|
+
private host;
|
|
8
|
+
constructor(host: T);
|
|
9
|
+
hostConnected(): void;
|
|
10
|
+
hostUpdated(): void;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { attachInternals as e, toggleState as t } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/state-expanded.controller.ts
|
|
3
|
+
var n = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
e(this.host);
|
|
9
|
+
}
|
|
10
|
+
hostUpdated() {
|
|
11
|
+
this.host.expanded !== null && this.host.expanded !== void 0 && (this.host._internals.ariaExpanded = `${this.host.expanded}`), t(this.host._internals, "expanded", !!this.host.expanded);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { n as StateExpandedController };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=state-expanded.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-expanded.controller.js","names":[],"sources":["../../../src/internal/controllers/state-expanded.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { attachInternals, toggleState } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype Expanded = ReactiveElement & { expanded?: boolean | null; _internals?: ElementInternals };\n\nexport class StateExpandedController<T extends Expanded> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n attachInternals(this.host);\n }\n\n hostUpdated() {\n if (this.host.expanded !== null && this.host.expanded !== undefined) {\n this.host._internals!.ariaExpanded = `${this.host.expanded}`;\n }\n\n toggleState(this.host._internals!, 'expanded', Boolean(this.host.expanded));\n }\n}\n"],"mappings":";;AAQA,IAAa,IAAb,MAAuF;CACrF,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,EAAgB,KAAK,IAAI;CAC3B;CAEA,cAAc;EAKZ,AAJI,KAAK,KAAK,aAAa,QAAQ,KAAK,KAAK,aAAa,KAAA,MACxD,KAAK,KAAK,WAAY,eAAe,GAAG,KAAK,KAAK,aAGpD,EAAY,KAAK,KAAK,YAAa,YAAY,EAAQ,KAAK,KAAK,QAAS;CAC5E;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type Pressed = ReactiveElement & {
|
|
3
|
+
pressed?: boolean | null;
|
|
4
|
+
_internals?: ElementInternals;
|
|
5
|
+
};
|
|
6
|
+
export declare class StatePressedController<T extends Pressed> implements ReactiveController {
|
|
7
|
+
private host;
|
|
8
|
+
constructor(host: T);
|
|
9
|
+
hostConnected(): void;
|
|
10
|
+
hostUpdated(): void;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { attachInternals as e, toggleState as t } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/state-pressed.controller.ts
|
|
3
|
+
var n = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
e(this.host);
|
|
9
|
+
}
|
|
10
|
+
hostUpdated() {
|
|
11
|
+
this.host.pressed !== null && this.host.pressed !== void 0 && (this.host._internals.ariaPressed = `${this.host.pressed}`), t(this.host._internals, "pressed", !!this.host.pressed);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { n as StatePressedController };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=state-pressed.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-pressed.controller.js","names":[],"sources":["../../../src/internal/controllers/state-pressed.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { attachInternals, toggleState } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype Pressed = ReactiveElement & { pressed?: boolean | null; _internals?: ElementInternals };\n\nexport class StatePressedController<T extends Pressed> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n attachInternals(this.host);\n }\n\n hostUpdated() {\n if (this.host.pressed !== null && this.host.pressed !== undefined) {\n this.host._internals!.ariaPressed = `${this.host.pressed}`;\n }\n\n toggleState(this.host._internals!, 'pressed', Boolean(this.host.pressed));\n }\n}\n"],"mappings":";;AAQA,IAAa,IAAb,MAAqF;CACnF,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,EAAgB,KAAK,IAAI;CAC3B;CAEA,cAAc;EAKZ,AAJI,KAAK,KAAK,YAAY,QAAQ,KAAK,KAAK,YAAY,KAAA,MACtD,KAAK,KAAK,WAAY,cAAc,GAAG,KAAK,KAAK,YAGnD,EAAY,KAAK,KAAK,YAAa,WAAW,EAAQ,KAAK,KAAK,OAAQ;CAC1E;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type ReadOnlyState = ReactiveElement & {
|
|
3
|
+
readOnly?: boolean;
|
|
4
|
+
_internals?: ElementInternals;
|
|
5
|
+
};
|
|
6
|
+
export declare class StateReadOnlyController<T extends ReadOnlyState> implements ReactiveController {
|
|
7
|
+
private host;
|
|
8
|
+
constructor(host: T);
|
|
9
|
+
hostConnected(): void;
|
|
10
|
+
hostUpdated(): void;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { attachInternals as e } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/state-readonly.controller.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
e(this.host);
|
|
9
|
+
}
|
|
10
|
+
hostUpdated() {
|
|
11
|
+
this.host.readOnly && (this.host._internals.ariaDisabled = null, this.host._internals.ariaExpanded = null, this.host._internals.ariaPressed = null, this.host._internals.ariaSelected = null, this.host._internals.ariaCurrent = null, this.host._internals.states.delete("expanded"), this.host._internals.states.delete("pressed"), this.host._internals.states.delete("selected"), this.host._internals.states.delete("current"));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { t as StateReadOnlyController };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=state-readonly.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-readonly.controller.js","names":[],"sources":["../../../src/internal/controllers/state-readonly.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ReactiveController, ReactiveElement } from './types.js';\nimport { attachInternals } from '../utils.js';\n\ntype ReadOnlyState = ReactiveElement & { readOnly?: boolean; _internals?: ElementInternals };\n\nexport class StateReadOnlyController<T extends ReadOnlyState> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n attachInternals(this.host);\n }\n\n hostUpdated() {\n if (this.host.readOnly) {\n this.host._internals!.ariaDisabled = null;\n this.host._internals!.ariaExpanded = null;\n this.host._internals!.ariaPressed = null;\n this.host._internals!.ariaSelected = null;\n this.host._internals!.ariaCurrent = null;\n this.host._internals!.states.delete('expanded');\n this.host._internals!.states.delete('pressed');\n this.host._internals!.states.delete('selected');\n this.host._internals!.states.delete('current');\n }\n }\n}\n"],"mappings":";;AAQA,IAAa,IAAb,MAA4F;CAC1F,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,EAAgB,KAAK,IAAI;CAC3B;CAEA,cAAc;EACZ,AAAI,KAAK,KAAK,aACZ,KAAK,KAAK,WAAY,eAAe,MACrC,KAAK,KAAK,WAAY,eAAe,MACrC,KAAK,KAAK,WAAY,cAAc,MACpC,KAAK,KAAK,WAAY,eAAe,MACrC,KAAK,KAAK,WAAY,cAAc,MACpC,KAAK,KAAK,WAAY,OAAO,OAAO,UAAU,GAC9C,KAAK,KAAK,WAAY,OAAO,OAAO,SAAS,GAC7C,KAAK,KAAK,WAAY,OAAO,OAAO,UAAU,GAC9C,KAAK,KAAK,WAAY,OAAO,OAAO,SAAS;CAEjD;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type Selected = ReactiveElement & {
|
|
3
|
+
current?: string | null;
|
|
4
|
+
readOnly?: boolean;
|
|
5
|
+
selected?: boolean | null;
|
|
6
|
+
_internals?: ElementInternals;
|
|
7
|
+
};
|
|
8
|
+
export declare class StateSelectedController<T extends Selected> implements ReactiveController {
|
|
9
|
+
#private;
|
|
10
|
+
private host;
|
|
11
|
+
constructor(host: T);
|
|
12
|
+
hostConnected(): void;
|
|
13
|
+
hostUpdated(): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { attachInternals as e, toggleState as t } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/state-selected.controller.ts
|
|
3
|
+
var n = class {
|
|
4
|
+
#e = null;
|
|
5
|
+
constructor(e) {
|
|
6
|
+
this.host = e, this.host.addController(this);
|
|
7
|
+
}
|
|
8
|
+
hostConnected() {
|
|
9
|
+
e(this.host);
|
|
10
|
+
}
|
|
11
|
+
hostUpdated() {
|
|
12
|
+
if (this.host.readOnly) {
|
|
13
|
+
this.#t();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (this.host._internals?.states.has("anchor")) {
|
|
17
|
+
this.host._internals.ariaSelected = null, t(this.host._internals, "selected", !!this.host.selected), this.#t();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.host.selected !== null && this.host.selected !== void 0 && (this.host._internals.ariaSelected = `${this.host.selected}`), t(this.host._internals, "selected", !!this.host.selected);
|
|
21
|
+
}
|
|
22
|
+
#t() {
|
|
23
|
+
let e = this.host.querySelector("a"), t = !this.host.readOnly && this.host._internals.states.has("anchor") && !!(this.host.selected || this.host.current);
|
|
24
|
+
if (e && t) {
|
|
25
|
+
this.#e?.removeAttribute("aria-current"), e.setAttribute("aria-current", "page"), this.#e = e;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.#e?.removeAttribute("aria-current"), this.#e = null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { n as StateSelectedController };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=state-selected.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-selected.controller.js","names":["#syncAnchorCurrentAttribute","#anchorCurrentTarget"],"sources":["../../../src/internal/controllers/state-selected.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { attachInternals, toggleState } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype Selected = ReactiveElement & {\n current?: string | null;\n readOnly?: boolean;\n selected?: boolean | null;\n _internals?: ElementInternals;\n};\n\nexport class StateSelectedController<T extends Selected> implements ReactiveController {\n #anchorCurrentTarget: HTMLAnchorElement | null = null;\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n attachInternals(this.host);\n }\n\n hostUpdated() {\n if (this.host.readOnly) {\n this.#syncAnchorCurrentAttribute();\n return;\n }\n\n if (this.host._internals?.states.has('anchor')) {\n this.host._internals!.ariaSelected = null;\n toggleState(this.host._internals!, 'selected', Boolean(this.host.selected));\n this.#syncAnchorCurrentAttribute();\n return;\n }\n\n if (this.host.selected !== null && this.host.selected !== undefined) {\n this.host._internals!.ariaSelected = `${this.host.selected}`;\n }\n\n toggleState(this.host._internals!, 'selected', Boolean(this.host.selected));\n }\n\n #syncAnchorCurrentAttribute() {\n const anchor = this.host.querySelector<HTMLAnchorElement>('a');\n const isCurrent =\n !this.host.readOnly &&\n this.host._internals!.states.has('anchor') &&\n Boolean(this.host.selected || this.host.current);\n\n if (anchor && isCurrent) {\n this.#anchorCurrentTarget?.removeAttribute('aria-current');\n anchor.setAttribute('aria-current', 'page');\n this.#anchorCurrentTarget = anchor;\n return;\n }\n\n this.#anchorCurrentTarget?.removeAttribute('aria-current');\n this.#anchorCurrentTarget = null;\n }\n}\n"],"mappings":";;AAaA,IAAa,IAAb,MAAuF;CACrF,KAAiD;CAEjD,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,EAAgB,KAAK,IAAI;CAC3B;CAEA,cAAc;EACZ,IAAI,KAAK,KAAK,UAAU;GACtB,KAAKA,GAA4B;GACjC;EACF;EAEA,IAAI,KAAK,KAAK,YAAY,OAAO,IAAI,QAAQ,GAAG;GAG9C,AAFA,KAAK,KAAK,WAAY,eAAe,MACrC,EAAY,KAAK,KAAK,YAAa,YAAY,EAAQ,KAAK,KAAK,QAAS,GAC1E,KAAKA,GAA4B;GACjC;EACF;EAMA,AAJI,KAAK,KAAK,aAAa,QAAQ,KAAK,KAAK,aAAa,KAAA,MACxD,KAAK,KAAK,WAAY,eAAe,GAAG,KAAK,KAAK,aAGpD,EAAY,KAAK,KAAK,YAAa,YAAY,EAAQ,KAAK,KAAK,QAAS;CAC5E;CAEA,KAA8B;EAC5B,IAAM,IAAS,KAAK,KAAK,cAAiC,GAAG,GACvD,IACJ,CAAC,KAAK,KAAK,YACX,KAAK,KAAK,WAAY,OAAO,IAAI,QAAQ,KACzC,GAAQ,KAAK,KAAK,YAAY,KAAK,KAAK;EAE1C,IAAI,KAAU,GAAW;GAGvB,AAFA,KAAKC,IAAsB,gBAAgB,cAAc,GACzD,EAAO,aAAa,gBAAgB,MAAM,GAC1C,KAAKA,KAAuB;GAC5B;EACF;EAGA,AADA,KAAKA,IAAsB,gBAAgB,cAAc,GACzD,KAAKA,KAAuB;CAC9B;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type AnchorBehaviorHost = ReactiveElement & {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
readOnly: boolean;
|
|
5
|
+
_internals?: ElementInternals;
|
|
6
|
+
};
|
|
7
|
+
export declare class TypeAnchorController<T extends AnchorBehaviorHost> implements ReactiveController {
|
|
8
|
+
#private;
|
|
9
|
+
private host;
|
|
10
|
+
constructor(host: T);
|
|
11
|
+
get readOnly(): boolean;
|
|
12
|
+
hostUpdated(): void;
|
|
13
|
+
hostDisconnected(): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { removeEmptyTextNode as e } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/type-anchor.controller.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
#e = null;
|
|
5
|
+
#t = !1;
|
|
6
|
+
constructor(e) {
|
|
7
|
+
this.host = e, this.host.addController(this);
|
|
8
|
+
}
|
|
9
|
+
get readOnly() {
|
|
10
|
+
return this.#t;
|
|
11
|
+
}
|
|
12
|
+
hostUpdated() {
|
|
13
|
+
this.#s();
|
|
14
|
+
let e = this.#n;
|
|
15
|
+
this.#t = !!e, e ? this.host._internals.states.add("anchor") : this.host._internals.states.delete("anchor"), this.#i && (this.#i.style.textDecoration = "none", this.host.style.cursor = "pointer"), this.#c(e);
|
|
16
|
+
}
|
|
17
|
+
hostDisconnected() {
|
|
18
|
+
this.#l();
|
|
19
|
+
}
|
|
20
|
+
get #n() {
|
|
21
|
+
return this.#r ?? this.#i;
|
|
22
|
+
}
|
|
23
|
+
get #r() {
|
|
24
|
+
return this.host.shadowRoot?.querySelector("slot, slot[name=anchor]")?.assignedElements()?.find((e) => e?.tagName === "A");
|
|
25
|
+
}
|
|
26
|
+
get #i() {
|
|
27
|
+
return this.host.parentElement?.tagName === "A" ? this.host.parentElement : null;
|
|
28
|
+
}
|
|
29
|
+
get #a() {
|
|
30
|
+
return this.host.shadowRoot?.querySelector("slot:not([name])");
|
|
31
|
+
}
|
|
32
|
+
get #o() {
|
|
33
|
+
return this.host.shadowRoot?.querySelector("slot[name=anchor]");
|
|
34
|
+
}
|
|
35
|
+
#s() {
|
|
36
|
+
this.#n && this.#o && (this.#n.slot = "anchor", this.#a?.assignedNodes().forEach((t) => e(t)));
|
|
37
|
+
}
|
|
38
|
+
#c(e) {
|
|
39
|
+
this.#l(), this.#e = e ?? null, this.#e?.addEventListener("click", this.#u);
|
|
40
|
+
}
|
|
41
|
+
#l() {
|
|
42
|
+
this.#e?.removeEventListener("click", this.#u), this.#e = null;
|
|
43
|
+
}
|
|
44
|
+
#u = (e) => {
|
|
45
|
+
this.host.disabled && (e.preventDefault(), e.stopImmediatePropagation());
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { t as TypeAnchorController };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=type-anchor.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-anchor.controller.js","names":["#readOnly","#updateAnchorSlotAssignment","#anchor","#parentAnchor","#setupAnchorClickBehavior","#removeAnchorClickBehavior","#slottedAnchor","#defaultSlot","#anchorSlot","#anchorClickTarget","#onAnchorClick"],"sources":["../../../src/internal/controllers/type-anchor.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { removeEmptyTextNode } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype AnchorBehaviorHost = ReactiveElement & {\n disabled: boolean;\n readOnly: boolean;\n _internals?: ElementInternals;\n};\n\nexport class TypeAnchorController<T extends AnchorBehaviorHost> implements ReactiveController {\n #anchorClickTarget: HTMLAnchorElement | null = null;\n #readOnly = false;\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n get readOnly() {\n return this.#readOnly;\n }\n\n hostUpdated() {\n this.#updateAnchorSlotAssignment();\n const anchor = this.#anchor;\n this.#readOnly = Boolean(anchor);\n\n if (anchor) {\n this.host._internals!.states.add('anchor');\n } else {\n this.host._internals!.states.delete('anchor');\n }\n\n if (this.#parentAnchor) {\n this.#parentAnchor.style.textDecoration = 'none';\n this.host.style.cursor = 'pointer';\n }\n\n this.#setupAnchorClickBehavior(anchor);\n }\n\n hostDisconnected() {\n this.#removeAnchorClickBehavior();\n }\n\n get #anchor() {\n return this.#slottedAnchor ?? this.#parentAnchor;\n }\n\n get #slottedAnchor() {\n return this.host.shadowRoot\n ?.querySelector<HTMLSlotElement>('slot, slot[name=anchor]')\n ?.assignedElements()\n ?.find(element => element?.tagName === 'A') as HTMLAnchorElement | undefined;\n }\n\n get #parentAnchor() {\n return this.host.parentElement?.tagName === 'A' ? (this.host.parentElement as HTMLAnchorElement) : null;\n }\n\n get #defaultSlot() {\n return this.host.shadowRoot?.querySelector<HTMLSlotElement>('slot:not([name])');\n }\n\n get #anchorSlot() {\n return this.host.shadowRoot?.querySelector<HTMLSlotElement>('slot[name=anchor]');\n }\n\n #updateAnchorSlotAssignment() {\n if (this.#anchor && this.#anchorSlot) {\n this.#anchor.slot = 'anchor';\n this.#defaultSlot?.assignedNodes().forEach(node => removeEmptyTextNode(node));\n }\n }\n\n #setupAnchorClickBehavior(anchor: HTMLAnchorElement | null | undefined) {\n this.#removeAnchorClickBehavior();\n this.#anchorClickTarget = anchor ?? null;\n this.#anchorClickTarget?.addEventListener('click', this.#onAnchorClick);\n }\n\n #removeAnchorClickBehavior() {\n this.#anchorClickTarget?.removeEventListener('click', this.#onAnchorClick);\n this.#anchorClickTarget = null;\n }\n\n #onAnchorClick = (event: Event) => {\n if (this.host.disabled) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n };\n}\n"],"mappings":";;AAYA,IAAa,IAAb,MAA8F;CAC5F,KAA+C;CAC/C,KAAY;CAEZ,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,IAAI,WAAW;EACb,OAAO,KAAKA;CACd;CAEA,cAAc;EACZ,KAAKC,GAA4B;EACjC,IAAM,IAAS,KAAKC;EAcpB,AAbA,KAAKF,KAAY,EAAQ,GAErB,IACF,KAAK,KAAK,WAAY,OAAO,IAAI,QAAQ,IAEzC,KAAK,KAAK,WAAY,OAAO,OAAO,QAAQ,GAG1C,KAAKG,OACP,KAAKA,GAAc,MAAM,iBAAiB,QAC1C,KAAK,KAAK,MAAM,SAAS,YAG3B,KAAKC,GAA0B,CAAM;CACvC;CAEA,mBAAmB;EACjB,KAAKC,GAA2B;CAClC;CAEA,IAAIH,KAAU;EACZ,OAAO,KAAKI,MAAkB,KAAKH;CACrC;CAEA,IAAIG,KAAiB;EACnB,OAAO,KAAK,KAAK,YACb,cAA+B,yBAAyB,GACxD,iBAAiB,GACjB,MAAK,MAAW,GAAS,YAAY,GAAG;CAC9C;CAEA,IAAIH,KAAgB;EAClB,OAAO,KAAK,KAAK,eAAe,YAAY,MAAO,KAAK,KAAK,gBAAsC;CACrG;CAEA,IAAII,KAAe;EACjB,OAAO,KAAK,KAAK,YAAY,cAA+B,kBAAkB;CAChF;CAEA,IAAIC,KAAc;EAChB,OAAO,KAAK,KAAK,YAAY,cAA+B,mBAAmB;CACjF;CAEA,KAA8B;EAC5B,AAAI,KAAKN,MAAW,KAAKM,OACvB,KAAKN,GAAQ,OAAO,UACpB,KAAKK,IAAc,cAAc,EAAE,SAAQ,MAAQ,EAAoB,CAAI,CAAC;CAEhF;CAEA,GAA0B,GAA8C;EAGtE,AAFA,KAAKF,GAA2B,GAChC,KAAKI,KAAqB,KAAU,MACpC,KAAKA,IAAoB,iBAAiB,SAAS,KAAKC,EAAc;CACxE;CAEA,KAA6B;EAE3B,AADA,KAAKD,IAAoB,oBAAoB,SAAS,KAAKC,EAAc,GACzE,KAAKD,KAAqB;CAC5B;CAEA,MAAkB,MAAiB;EACjC,AAAI,KAAK,KAAK,aACZ,EAAM,eAAe,GACrB,EAAM,yBAAyB;CAEnC;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type ButtonBehaviorHost = ReactiveElement & {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
readOnly: boolean;
|
|
5
|
+
_internals?: ElementInternals;
|
|
6
|
+
};
|
|
7
|
+
export declare class TypeButtonController<T extends ButtonBehaviorHost> implements ReactiveController {
|
|
8
|
+
#private;
|
|
9
|
+
private host;
|
|
10
|
+
constructor(host: T);
|
|
11
|
+
hostConnected(): void;
|
|
12
|
+
hostUpdated(): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/internal/controllers/type-button.controller.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
#e = null;
|
|
4
|
+
#t = 0;
|
|
5
|
+
constructor(e) {
|
|
6
|
+
this.host = e, this.host.addController(this);
|
|
7
|
+
}
|
|
8
|
+
hostConnected() {
|
|
9
|
+
this.host.hasAttribute("tabindex") && (this.#t = this.host.tabIndex);
|
|
10
|
+
}
|
|
11
|
+
hostUpdated() {
|
|
12
|
+
if (this.host.readOnly) {
|
|
13
|
+
this.host._internals.role && this.host._internals.role !== "none" && (this.#e = this.host._internals.role), this.host._internals.role = "none", this.host.tabIndex = -1, this.host.removeAttribute("tabindex");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
!this.host._internals.role || this.host._internals.role === "none" ? this.host._internals.role = this.#e ?? "button" : this.#e = this.host._internals.role, this.host.tabIndex = this.host.disabled ? -1 : this.#t;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { e as TypeButtonController };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=type-button.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-button.controller.js","names":["#initialTabIndex","#enabledRole"],"sources":["../../../src/internal/controllers/type-button.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype ButtonBehaviorHost = ReactiveElement & {\n disabled: boolean;\n readOnly: boolean;\n _internals?: ElementInternals;\n};\n\nexport class TypeButtonController<T extends ButtonBehaviorHost> implements ReactiveController {\n #enabledRole: string | null = null;\n #initialTabIndex = 0;\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n if (this.host.hasAttribute('tabindex')) {\n this.#initialTabIndex = this.host.tabIndex;\n }\n }\n\n hostUpdated() {\n if (this.host.readOnly) {\n if (this.host._internals!.role && this.host._internals!.role !== 'none') {\n this.#enabledRole = this.host._internals!.role;\n }\n\n this.host._internals!.role = 'none';\n this.host.tabIndex = -1;\n this.host.removeAttribute('tabindex');\n return;\n }\n\n if (!this.host._internals!.role || this.host._internals!.role === 'none') {\n this.host._internals!.role = this.#enabledRole ?? 'button';\n } else {\n this.#enabledRole = this.host._internals!.role;\n }\n\n this.host.tabIndex = this.host.disabled ? -1 : this.#initialTabIndex;\n }\n}\n"],"mappings":";AAWA,IAAa,IAAb,MAA8F;CAC5F,KAA8B;CAC9B,KAAmB;CAEnB,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,AAAI,KAAK,KAAK,aAAa,UAAU,MACnC,KAAKA,KAAmB,KAAK,KAAK;CAEtC;CAEA,cAAc;EACZ,IAAI,KAAK,KAAK,UAAU;GAOtB,AANI,KAAK,KAAK,WAAY,QAAQ,KAAK,KAAK,WAAY,SAAS,WAC/D,KAAKC,KAAe,KAAK,KAAK,WAAY,OAG5C,KAAK,KAAK,WAAY,OAAO,QAC7B,KAAK,KAAK,WAAW,IACrB,KAAK,KAAK,gBAAgB,UAAU;GACpC;EACF;EAQA,AANI,CAAC,KAAK,KAAK,WAAY,QAAQ,KAAK,KAAK,WAAY,SAAS,SAChE,KAAK,KAAK,WAAY,OAAO,KAAKA,MAAgB,WAElD,KAAKA,KAAe,KAAK,KAAK,WAAY,MAG5C,KAAK,KAAK,WAAW,KAAK,KAAK,WAAW,KAAK,KAAKD;CACtD;AACF"}
|