@redvars/peacock 3.10.1 → 3.11.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/dist/BaseInput-CV0pZgSb.js +58 -0
- package/dist/BaseInput-CV0pZgSb.js.map +1 -0
- package/dist/app-bar.js +16 -16
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/assets/theme.d.ts +66 -0
- package/dist/assets/theme.js +134 -0
- package/dist/assets/tokens.css +1 -1
- package/dist/assets/tokens.css.map +1 -1
- package/dist/base-progress-CLZTRveO.js +33 -0
- package/dist/base-progress-CLZTRveO.js.map +1 -0
- package/dist/bottom-sheet.js +1 -1
- package/dist/button-group.js +9 -7
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +225 -187
- package/dist/button.js.map +1 -1
- package/dist/{chart-bar-CapLbc2e.js → chart-bar-D5dGFJfK.js} +2 -2
- package/dist/{chart-bar-CapLbc2e.js.map → chart-bar-D5dGFJfK.js.map} +1 -1
- package/dist/chart-bar.js +1 -1
- package/dist/chart-stacked-bar.js +1 -1
- package/dist/checkbox.js +78 -53
- package/dist/checkbox.js.map +1 -1
- package/dist/chip-set.js +52 -0
- package/dist/chip-set.js.map +1 -0
- package/dist/chip.js +8 -6
- package/dist/chip.js.map +1 -1
- package/dist/circular-progress.js +177 -0
- package/dist/circular-progress.js.map +1 -0
- package/dist/code-editor.js +129 -72
- package/dist/code-editor.js.map +1 -1
- package/dist/code-highlighter.js +2 -38
- package/dist/code-highlighter.js.map +1 -1
- package/dist/color-field.js +309 -0
- package/dist/color-field.js.map +1 -0
- package/dist/color-picker.js +26 -15
- package/dist/color-picker.js.map +1 -1
- package/dist/copy-to-clipboard-upGx-Ueo.js +39 -0
- package/dist/copy-to-clipboard-upGx-Ueo.js.map +1 -0
- package/dist/custom-elements-jsdocs.json +1044 -382
- package/dist/custom-elements.json +8615 -4726
- package/dist/date-picker.js +241 -0
- package/dist/date-picker.js.map +1 -0
- package/dist/{element-internals-2CMts_0M.js → delegate-py-Ets8N.js} +2 -43
- package/dist/delegate-py-Ets8N.js.map +1 -0
- package/dist/element-internals-QME0yEz4.js +43 -0
- package/dist/element-internals-QME0yEz4.js.map +1 -0
- package/dist/fab.js +51 -49
- package/dist/fab.js.map +1 -1
- package/dist/field.js +25 -0
- package/dist/field.js.map +1 -1
- package/dist/flow.js +5 -5
- package/dist/form-associated-Bhwwr6dT.js +162 -0
- package/dist/form-associated-Bhwwr6dT.js.map +1 -0
- package/dist/{form-associated-BXADnjOB.js → form-submitter-DPI4L6gj.js} +3 -159
- package/dist/form-submitter-DPI4L6gj.js.map +1 -0
- package/dist/html-editor.js +3 -1
- package/dist/html-editor.js.map +1 -1
- package/dist/icon-button.js +195 -156
- package/dist/icon-button.js.map +1 -1
- package/dist/image.js +2 -2
- package/dist/index.js +32 -8
- package/dist/index.js.map +1 -1
- package/dist/input.js +259 -0
- package/dist/input.js.map +1 -0
- package/dist/item.js +2 -1
- package/dist/item.js.map +1 -1
- package/dist/linear-progress.js +192 -0
- package/dist/linear-progress.js.map +1 -0
- package/dist/{list-AdO-PUq_.js → list-item.js} +12 -222
- package/dist/list-item.js.map +1 -0
- package/dist/list.js +225 -6
- package/dist/list.js.map +1 -1
- package/dist/loader-full.js +31 -8
- package/dist/loader-full.js.map +1 -1
- package/dist/loader.js +52 -12
- package/dist/loader.js.map +1 -1
- package/dist/markdown-editor.js +5 -3
- package/dist/markdown-editor.js.map +1 -1
- package/dist/menu-item.js +30 -30
- package/dist/navigation-bar-item.js +41 -0
- package/dist/navigation-bar-item.js.map +1 -0
- package/dist/navigation-bar.js +128 -0
- package/dist/navigation-bar.js.map +1 -0
- package/dist/navigation-drawer-item.js +236 -0
- package/dist/navigation-drawer-item.js.map +1 -0
- package/dist/navigation-drawer.js +293 -0
- package/dist/navigation-drawer.js.map +1 -0
- package/dist/navigation-rail.js +1 -1
- package/dist/number-field.js +280 -0
- package/dist/number-field.js.map +1 -0
- package/dist/pagination.js +1 -1
- package/dist/radio-group.js +209 -0
- package/dist/radio-group.js.map +1 -0
- package/dist/radio.js +47 -37
- package/dist/radio.js.map +1 -1
- package/dist/segmented-button-group.js +12 -0
- package/dist/segmented-button-group.js.map +1 -1
- package/dist/segmented-button.js +10 -6
- package/dist/segmented-button.js.map +1 -1
- package/dist/select.js +653 -0
- package/dist/select.js.map +1 -0
- package/dist/side-sheet.js +1 -1
- package/dist/sidebar-menu-item.js +273 -0
- package/dist/sidebar-menu-item.js.map +1 -0
- package/dist/sidebar-menu.js +193 -0
- package/dist/sidebar-menu.js.map +1 -0
- package/dist/sidebar-sub-menu.js +301 -0
- package/dist/sidebar-sub-menu.js.map +1 -0
- package/dist/slider.js +76 -24
- package/dist/slider.js.map +1 -1
- package/dist/snackbar.js +3 -3
- package/dist/snackbar.js.map +1 -1
- package/dist/split-button.js +2 -2
- package/dist/src/__internal/utils/size.d.ts +9 -0
- package/dist/src/button/ButtonTypes.d.ts +1 -1
- package/dist/src/checkbox/checkbox.d.ts +28 -22
- package/dist/src/chip/chip/chip.d.ts +3 -0
- package/dist/src/chip/tag/tag.d.ts +5 -1
- package/dist/src/code-editor/code-editor.d.ts +37 -10
- package/dist/src/color-field/color-field.d.ts +55 -0
- package/dist/src/color-field/index.d.ts +1 -0
- package/dist/src/color-picker/color-picker.d.ts +1 -1
- package/dist/src/date-picker/date-picker.d.ts +0 -1
- package/dist/src/index.d.ts +4 -3
- package/dist/src/input/BaseInput.d.ts +21 -3
- package/dist/src/input/input.d.ts +15 -7
- package/dist/src/navigation-bar/index.d.ts +2 -0
- package/dist/src/navigation-bar/navigation-bar-item.d.ts +23 -0
- package/dist/src/navigation-bar/navigation-bar.d.ts +44 -0
- package/dist/src/navigation-drawer/index.d.ts +2 -0
- package/dist/src/navigation-drawer/navigation-drawer-item.d.ts +48 -0
- package/dist/src/navigation-drawer/navigation-drawer.d.ts +70 -0
- package/dist/src/number-field/number-field.d.ts +0 -1
- package/dist/src/radio/index.d.ts +1 -0
- package/dist/src/radio/radio-group.d.ts +50 -0
- package/dist/src/radio/radio.d.ts +18 -18
- package/dist/src/segmented-button/segmented-button-group.d.ts +5 -0
- package/dist/src/segmented-button/segmented-button.d.ts +2 -1
- package/dist/src/select/select.d.ts +6 -0
- package/dist/src/slider/slider.d.ts +14 -5
- package/dist/src/switch/switch.d.ts +22 -26
- package/dist/src/tabs/tabs.d.ts +3 -0
- package/dist/src/textarea/textarea.d.ts +0 -1
- package/dist/src/time-picker/time-picker.d.ts +0 -1
- package/dist/src/toolbar/toolbar.d.ts +7 -4
- package/dist/src/url-field/url-field.d.ts +0 -1
- package/dist/svg.js +5 -5
- package/dist/switch.js +413 -0
- package/dist/switch.js.map +1 -0
- package/dist/tab.js +2 -1
- package/dist/tab.js.map +1 -1
- package/dist/tabs.js +10 -8
- package/dist/tabs.js.map +1 -1
- package/dist/tag.js +349 -0
- package/dist/tag.js.map +1 -0
- package/dist/test/code-editor.test.d.ts +1 -0
- package/dist/test/color-field.test.d.ts +1 -0
- package/dist/test/color-picker.test.d.ts +1 -0
- package/dist/test/field.test.d.ts +1 -0
- package/dist/test/form-controls.test.d.ts +1 -0
- package/dist/test/icon.test.d.ts +1 -1
- package/dist/test/input.test.d.ts +1 -0
- package/dist/test/navigation.test.d.ts +1 -0
- package/dist/test/segmented-button.test.d.ts +1 -0
- package/dist/test/slider.test.d.ts +1 -0
- package/dist/textarea.js +237 -0
- package/dist/textarea.js.map +1 -0
- package/dist/time-picker.js +241 -0
- package/dist/time-picker.js.map +1 -0
- package/dist/toolbar.js +26 -9
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/url-field.js +298 -0
- package/dist/url-field.js.map +1 -0
- package/package.json +29 -8
- package/readme.md +2 -2
- package/scss/tokens.css +175 -18
- package/src/__internal/utils/size.ts +23 -0
- package/src/app-bar/app-bar.scss +4 -16
- package/src/bottom-sheet/bottom-sheet.scss +1 -1
- package/src/button/ButtonTypes.ts +2 -0
- package/src/button/button/button-base.scss +84 -84
- package/src/button/button/button-colors.scss +14 -2
- package/src/button/button/button-layers.scss +71 -71
- package/src/button/button/button-shapes.scss +2 -2
- package/src/button/button/button-sizes.scss +35 -35
- package/src/button/button/button.scss +1 -1
- package/src/button/button/button.ts +1 -2
- package/src/button/button-group/button-group.scss +5 -5
- package/src/button/fab/fab-sizes.scss +15 -15
- package/src/button/fab/fab.scss +32 -32
- package/src/button/icon-button/icon-button-sizes.scss +7 -7
- package/src/chart-bar/chart-bar.scss +1 -1
- package/src/checkbox/checkbox.scss +7 -6
- package/src/checkbox/checkbox.ts +92 -40
- package/src/chip/chip/chip.ts +8 -5
- package/src/chip/chip-set/chip-set.ts +2 -0
- package/src/chip/tag/tag-colors.scss +1 -1
- package/src/chip/tag/tag-sizes.scss +9 -0
- package/src/chip/tag/tag.scss +1 -1
- package/src/chip/tag/tag.ts +20 -9
- package/src/code-editor/code-editor.scss +8 -3
- package/src/code-editor/code-editor.ts +148 -79
- package/src/code-highlighter/code-highlighter.scss +1 -1
- package/src/color-field/color-field.scss +48 -0
- package/src/color-field/color-field.ts +239 -0
- package/src/color-field/index.ts +1 -0
- package/src/color-picker/color-picker.scss +33 -15
- package/src/color-picker/color-picker.ts +2 -1
- package/src/date-picker/date-picker.ts +2 -3
- package/src/field/field.scss +31 -0
- package/src/flow/flow.scss +5 -5
- package/src/image/image.scss +2 -2
- package/src/index.ts +7 -3
- package/src/input/BaseInput.ts +54 -4
- package/src/input/input.ts +104 -79
- package/src/list/list-item.ts +2 -0
- package/src/loader.ts +28 -6
- package/src/markdown-editor/markdown-editor.scss +2 -2
- package/src/menu/menu-item/menu-item.scss +30 -30
- package/src/navigation-bar/index.ts +2 -0
- package/src/navigation-bar/navigation-bar-item.ts +25 -0
- package/src/navigation-bar/navigation-bar.scss +27 -0
- package/src/navigation-bar/navigation-bar.ts +96 -0
- package/src/navigation-drawer/index.ts +2 -0
- package/src/navigation-drawer/navigation-drawer-item.scss +82 -0
- package/src/navigation-drawer/navigation-drawer-item.ts +133 -0
- package/src/navigation-drawer/navigation-drawer.scss +99 -0
- package/src/navigation-drawer/navigation-drawer.ts +196 -0
- package/src/navigation-rail/navigation-rail.scss +1 -1
- package/src/number-field/number-field.ts +2 -3
- package/src/pagination/pagination.scss +1 -1
- package/src/progress/circular-progress/circular-progress.ts +2 -0
- package/src/progress/linear-progress/linear-progress.ts +2 -0
- package/src/radio/index.ts +1 -0
- package/src/radio/radio-group.scss +39 -0
- package/src/radio/radio-group.ts +167 -0
- package/src/radio/radio.ts +74 -31
- package/src/segmented-button/segmented-button-group.ts +12 -0
- package/src/segmented-button/segmented-button.ts +12 -6
- package/src/select/select.ts +21 -1
- package/src/side-sheet/side-sheet.scss +1 -1
- package/src/sidebar-menu/sidebar-menu-item.scss +1 -1
- package/src/sidebar-menu/sidebar-menu-item.ts +2 -0
- package/src/sidebar-menu/sidebar-menu.ts +2 -0
- package/src/sidebar-menu/sidebar-sub-menu.scss +1 -1
- package/src/sidebar-menu/sidebar-sub-menu.ts +2 -0
- package/src/slider/slider.scss +3 -3
- package/src/slider/slider.ts +119 -31
- package/src/snackbar/snackbar.ts +3 -3
- package/src/split-button/split-button-colors.scss +2 -2
- package/src/svg/svg.scss +5 -5
- package/src/switch/switch.scss +0 -1
- package/src/switch/switch.ts +82 -47
- package/src/tabs/tab.scss +2 -1
- package/src/tabs/tabs.ts +14 -8
- package/src/textarea/textarea.ts +2 -3
- package/src/time-picker/time-picker.ts +2 -3
- package/src/toolbar/toolbar.scss +4 -4
- package/src/toolbar/toolbar.ts +12 -5
- package/src/url-field/url-field.ts +2 -3
- package/dist/BaseInput-CU1zZYKc.js +0 -27
- package/dist/BaseInput-CU1zZYKc.js.map +0 -1
- package/dist/brand-loader.js +0 -358
- package/dist/brand-loader.js.map +0 -1
- package/dist/element-internals-2CMts_0M.js.map +0 -1
- package/dist/form-associated-BXADnjOB.js.map +0 -1
- package/dist/list-AdO-PUq_.js.map +0 -1
- package/dist/select-DkyRqUTI.js +0 -3955
- package/dist/select-DkyRqUTI.js.map +0 -1
- package/dist/src/brand-loader/brand-loader.d.ts +0 -33
- package/dist/src/brand-loader/index.d.ts +0 -2
- package/src/brand-loader/brand-loader.scss +0 -270
- package/src/brand-loader/brand-loader.ts +0 -115
- package/src/brand-loader/index.ts +0 -2
- /package/dist/test/{brand-loader.test.d.ts → button.test.d.ts} +0 -0
package/dist/code-highlighter.js
CHANGED
|
@@ -3,45 +3,9 @@ import { n } from './property-B49QQ8pS.js';
|
|
|
3
3
|
import { r } from './state-DkTK9EGF.js';
|
|
4
4
|
import { o } from './unsafe-html-Ct0N2_UU.js';
|
|
5
5
|
import { e } from './class-map-DG7CA1et.js';
|
|
6
|
+
import { c as copyToClipboard } from './copy-to-clipboard-upGx-Ueo.js';
|
|
6
7
|
import './directive-ZPhl09Yt.js';
|
|
7
8
|
|
|
8
|
-
function fallbackCopyTextToClipboard(text) {
|
|
9
|
-
const temporaryInput = document.createElement('textarea');
|
|
10
|
-
temporaryInput.value = text;
|
|
11
|
-
// Make the element non-visible but still in the DOM so it can be selected
|
|
12
|
-
temporaryInput.setAttribute('readonly', '');
|
|
13
|
-
temporaryInput.style.position = 'absolute';
|
|
14
|
-
temporaryInput.style.left = '-9999px';
|
|
15
|
-
document.body.appendChild(temporaryInput);
|
|
16
|
-
temporaryInput.select();
|
|
17
|
-
try {
|
|
18
|
-
document.execCommand('copy');
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
console.error('Fallback: Failed to copy text: ', err);
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
document.body.removeChild(temporaryInput);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async function copyToClipboard(text) {
|
|
28
|
-
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
29
|
-
// Use the modern Clipboard API
|
|
30
|
-
try {
|
|
31
|
-
await navigator.clipboard.writeText(text);
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
console.error('Failed to copy text using Clipboard API: ', err);
|
|
35
|
-
// Fallback if API fails for some reason
|
|
36
|
-
fallbackCopyTextToClipboard(text);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
// Use the fallback method for older browsers
|
|
41
|
-
fallbackCopyTextToClipboard(text);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
9
|
var css_248z = i`* {
|
|
46
10
|
box-sizing: border-box;
|
|
47
11
|
-webkit-tap-highlight-color: transparent;
|
|
@@ -92,7 +56,7 @@ var css_248z = i`* {
|
|
|
92
56
|
letter-spacing: var(--typography-body-medium-letter-spacing) !important;
|
|
93
57
|
}
|
|
94
58
|
.code-highlighter .header .copy-button {
|
|
95
|
-
--button-container-shape:
|
|
59
|
+
--button-container-shape: var(--shape-corner-full);
|
|
96
60
|
}
|
|
97
61
|
.code-highlighter .scroll-wrapper {
|
|
98
62
|
flex: 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-highlighter.js","sources":["../../src/__internal/utils/copy-to-clipboard.ts","../../src/code-highlighter/code-highlighter.ts"],"sourcesContent":["function fallbackCopyTextToClipboard(text: string) {\n const temporaryInput = document.createElement('textarea');\n temporaryInput.value = text;\n\n // Make the element non-visible but still in the DOM so it can be selected\n temporaryInput.setAttribute('readonly', '');\n temporaryInput.style.position = 'absolute';\n temporaryInput.style.left = '-9999px';\n\n document.body.appendChild(temporaryInput);\n temporaryInput.select();\n\n try {\n document.execCommand('copy');\n } catch (err) {\n console.error('Fallback: Failed to copy text: ', err);\n } finally {\n document.body.removeChild(temporaryInput);\n }\n}\n\nexport async function copyToClipboard(text: string) {\n if (navigator.clipboard && navigator.clipboard.writeText) {\n // Use the modern Clipboard API\n try {\n await navigator.clipboard.writeText(text);\n } catch (err) {\n console.error('Failed to copy text using Clipboard API: ', err);\n // Fallback if API fails for some reason\n fallbackCopyTextToClipboard(text);\n }\n } else {\n // Use the fallback method for older browsers\n fallbackCopyTextToClipboard(text);\n }\n}\n","import { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport type { BundledLanguage, ShikiTransformer } from 'shiki';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { copyToClipboard } from '@/__internal/utils/copy-to-clipboard.js';\nimport styles from './code-highlighter.scss';\n\n// Module-level promises – Rollup splits each import() specifier into a separate chunk.\n// Caching here prevents parallel loads when multiple instances initialise at the same time.\nlet _shiki: Promise<typeof import('shiki')> | null = null;\nlet _themes: Promise<\n [\n typeof import('@pierre/theme/pierre-dark'),\n typeof import('@pierre/theme/pierre-light'),\n ]\n> | null = null;\nlet _prettier: Promise<typeof import('prettier/standalone')> | null = null;\nlet _pluginBabel: Promise<typeof import('prettier/plugins/babel')> | null =\n null;\nlet _pluginHtml: Promise<typeof import('prettier/plugins/html')> | null = null;\nlet _pluginPostcss: Promise<typeof import('prettier/plugins/postcss')> | null =\n null;\nlet _pluginEstree: Promise<typeof import('prettier/plugins/estree')> | null =\n null;\n\nconst loadShiki = () => (_shiki ??= import('shiki'));\n\nconst loadThemes = () =>\n (_themes ??= Promise.all([\n import('@pierre/theme/pierre-dark'),\n import('@pierre/theme/pierre-light'),\n ]));\n\nconst loadPrettier = () => (_prettier ??= import('prettier/standalone'));\nconst loadPluginBabel = () =>\n (_pluginBabel ??= import('prettier/plugins/babel'));\nconst loadPluginHtml = () => (_pluginHtml ??= import('prettier/plugins/html'));\nconst loadPluginPostcss = () =>\n (_pluginPostcss ??= import('prettier/plugins/postcss'));\nconst loadPluginEstree = () =>\n (_pluginEstree ??= import('prettier/plugins/estree'));\n\nconst locale = {\n loading: 'Loading code...',\n copyToClipboard: 'Copy to clipboard',\n copied: 'Copied',\n copiedCode: 'Copied code',\n};\n\n/**\n * @label Code Highlighter\n * @tag wc-code-highlighter\n * @rawTag code-highlighter\n *\n * @summary A component that provides syntax highlighting for code snippets.\n *\n * @example\n * ```html\n * <wc-code-highlighter language=\"javascript\" style=\"height: 9rem\"><pre><code>\n * function helloWorld() {\n * console.log('Hello, world!');\n * }</code></pre>\n * </wc-code-highlighter>\n * ```\n * @tags display\n */\n@IndividualComponent\nexport class CodeHighlighter extends LitElement {\n static styles = [styles];\n\n private static readonly COPY_FEEDBACK_DURATION = 3000;\n\n @property({ type: String, reflect: true })\n language: BundledLanguage = 'javascript';\n\n @property({ attribute: 'line-numbers', type: Boolean, reflect: true })\n lineNumbers: boolean = false;\n\n @property({ type: String })\n value: string = '';\n\n @property({ type: Boolean, reflect: true })\n format?: boolean = true;\n\n @property({ type: Boolean })\n hideCopy: boolean = false;\n\n @state() private compiledCode: string | null = null;\n\n @state() private _copied = false;\n\n private parsedCode: string | null = null;\n\n private _copyFeedbackTimeout: number | null = null;\n\n async connectedCallback() {\n // eslint-disable-next-line wc/guard-super-call\n super.connectedCallback();\n }\n\n disconnectedCallback() {\n if (this._copyFeedbackTimeout !== null) {\n window.clearTimeout(this._copyFeedbackTimeout);\n this._copyFeedbackTimeout = null;\n }\n super.disconnectedCallback();\n }\n\n firstUpdated() {\n this.__highlightCode();\n }\n\n // eslint-disable-next-line class-methods-use-this\n private decode(str: string) {\n return str.replace(/</g, '<').replace(/>/g, '>');\n }\n\n private async __highlightCode() {\n let codeString = '';\n if (this.value) {\n codeString = this.value;\n } else {\n // Accessing light DOM children\n const codeTag = this.querySelector('code');\n if (codeTag) {\n codeString = codeTag.innerHTML;\n } else if (this.childNodes.length > 0) {\n codeString = (this as HTMLElement).innerText;\n }\n }\n\n codeString = this.decode(codeString);\n\n if (this.format !== false) {\n // eslint-disable-next-line default-case\n switch (this.language) {\n case 'javascript': {\n const [prettier, pluginBabel, pluginEstree] = await Promise.all([\n loadPrettier(),\n loadPluginBabel(),\n loadPluginEstree(),\n ]);\n codeString = await prettier.format(codeString, {\n parser: 'babel',\n plugins: [pluginBabel, pluginEstree],\n bracketSameLine: true,\n htmlWhitespaceSensitivity: 'ignore',\n });\n break;\n }\n case 'html': {\n const [prettier, pluginHtml] = await Promise.all([\n loadPrettier(),\n loadPluginHtml(),\n ]);\n codeString = await prettier.format(codeString, {\n parser: 'html',\n plugins: [pluginHtml],\n bracketSameLine: true,\n htmlWhitespaceSensitivity: 'ignore',\n });\n break;\n }\n case 'css': {\n const [prettier, pluginPostcss] = await Promise.all([\n loadPrettier(),\n loadPluginPostcss(),\n ]);\n codeString = await prettier.format(codeString, {\n parser: 'css',\n plugins: [pluginPostcss],\n });\n break;\n }\n }\n }\n\n this.parsedCode = codeString;\n\n const transformers: ShikiTransformer[] = [];\n\n // If line numbers are enabled, we inject a transformer\n // that adds the 'line' class to every line node.\n if (this.lineNumbers) {\n transformers.push({\n name: 'add-line-class',\n line(node) {\n // Shiki v1 helper to add classes to the AST\n this.addClassToHast(node, 'line');\n },\n });\n }\n\n const [\n { codeToHtml },\n [{ default: pierreDark }, { default: pierreLight }],\n ] = await Promise.all([loadShiki(), loadThemes()]);\n\n this.compiledCode = await codeToHtml(codeString, {\n lang: this.language,\n themes: {\n // @ts-ignore\n light: pierreLight,\n // @ts-ignore\n dark: pierreDark,\n },\n transformers,\n });\n }\n\n protected updated(changed: Map<PropertyKey, unknown>) {\n // Only re-highlight when the source content or rendering options change,\n // not on unrelated state updates like the copy-button feedback toggle.\n if (\n changed.has('value') ||\n changed.has('language') ||\n changed.has('lineNumbers') ||\n changed.has('format')\n ) {\n this.__highlightCode();\n }\n }\n\n private async __handleCopyClick() {\n if (this.parsedCode == null) {\n return;\n }\n\n await copyToClipboard(this.parsedCode);\n this._copied = true;\n\n if (this._copyFeedbackTimeout !== null) {\n window.clearTimeout(this._copyFeedbackTimeout);\n }\n\n this._copyFeedbackTimeout = window.setTimeout(() => {\n this._copied = false;\n this._copyFeedbackTimeout = null;\n }, CodeHighlighter.COPY_FEEDBACK_DURATION);\n }\n\n render() {\n if (this.compiledCode === null) {\n return html`\n <div class=\"code-loader\">\n <wc-circular-progress indeterminate></wc-circular-progress>\n ${locale.loading}\n </div>\n `;\n }\n\n return html`\n <div\n class=${classMap({\n 'code-highlighter': true,\n 'line-numbers': this.lineNumbers,\n })}\n >\n <div class=\"header\">\n <div class=\"header-title\">\n <slot name=\"title\">${this.language?.toUpperCase()}</slot>\n </div>\n <div class=\"header-actions\">\n <wc-icon-button\n color=${this._copied ? 'success' : 'surface'}\n variant=\"text\"\n size=\"xs\"\n aria-label=${this._copied\n ? locale.copied\n : locale.copyToClipboard}\n tooltip=${this._copied ? locale.copied : locale.copyToClipboard}\n @click=${this.__handleCopyClick}\n >\n <wc-icon\n name=${this._copied ? 'check' : 'content_copy'}\n ></wc-icon>\n </wc-icon-button>\n </div>\n </div>\n\n <div class=\"scroll-wrapper\">\n <div class=\"highlighter\">${unsafeHTML(this.compiledCode || '')}</div>\n </div>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","classMap","unsafeHTML","styles","property","state"],"mappings":";;;;;;;AAAA,SAAS,2BAA2B,CAAC,IAAY,EAAA;IAC/C,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC;AACzD,IAAA,cAAc,CAAC,KAAK,GAAG,IAAI;;AAG3B,IAAA,cAAc,CAAC,YAAY,CAAC,UAAU,EAAE,EAAE,CAAC;AAC3C,IAAA,cAAc,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU;AAC1C,IAAA,cAAc,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS;AAErC,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACzC,cAAc,CAAC,MAAM,EAAE;AAEvB,IAAA,IAAI;AACF,QAAA,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC;IAC9B;IAAE,OAAO,GAAG,EAAE;AACZ,QAAA,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC;IACvD;YAAU;AACR,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC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,OAAO,EAAE;AACD,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAET,UAAA,CAAA;AAAhB,IAAAC,CAAK;AAA8C,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAEnC,UAAA,CAAA;AAAhB,IAAAA,CAAK;AAA2B,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAtBtB,eAAe,GAAA,iBAAA,GAAA,UAAA,CAAA;IAD3B;AACY,CAAA,EAAA,eAAe,CA2N3B;;;;"}
|
|
1
|
+
{"version":3,"file":"code-highlighter.js","sources":["../../src/code-highlighter/code-highlighter.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport type { BundledLanguage, ShikiTransformer } from 'shiki';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { copyToClipboard } from '@/__internal/utils/copy-to-clipboard.js';\nimport styles from './code-highlighter.scss';\n\n// Module-level promises – Rollup splits each import() specifier into a separate chunk.\n// Caching here prevents parallel loads when multiple instances initialise at the same time.\nlet _shiki: Promise<typeof import('shiki')> | null = null;\nlet _themes: Promise<\n [\n typeof import('@pierre/theme/pierre-dark'),\n typeof import('@pierre/theme/pierre-light'),\n ]\n> | null = null;\nlet _prettier: Promise<typeof import('prettier/standalone')> | null = null;\nlet _pluginBabel: Promise<typeof import('prettier/plugins/babel')> | null =\n null;\nlet _pluginHtml: Promise<typeof import('prettier/plugins/html')> | null = null;\nlet _pluginPostcss: Promise<typeof import('prettier/plugins/postcss')> | null =\n null;\nlet _pluginEstree: Promise<typeof import('prettier/plugins/estree')> | null =\n null;\n\nconst loadShiki = () => (_shiki ??= import('shiki'));\n\nconst loadThemes = () =>\n (_themes ??= Promise.all([\n import('@pierre/theme/pierre-dark'),\n import('@pierre/theme/pierre-light'),\n ]));\n\nconst loadPrettier = () => (_prettier ??= import('prettier/standalone'));\nconst loadPluginBabel = () =>\n (_pluginBabel ??= import('prettier/plugins/babel'));\nconst loadPluginHtml = () => (_pluginHtml ??= import('prettier/plugins/html'));\nconst loadPluginPostcss = () =>\n (_pluginPostcss ??= import('prettier/plugins/postcss'));\nconst loadPluginEstree = () =>\n (_pluginEstree ??= import('prettier/plugins/estree'));\n\nconst locale = {\n loading: 'Loading code...',\n copyToClipboard: 'Copy to clipboard',\n copied: 'Copied',\n copiedCode: 'Copied code',\n};\n\n/**\n * @label Code Highlighter\n * @tag wc-code-highlighter\n * @rawTag code-highlighter\n *\n * @summary A component that provides syntax highlighting for code snippets.\n *\n * @example\n * ```html\n * <wc-code-highlighter language=\"javascript\" style=\"height: 9rem\"><pre><code>\n * function helloWorld() {\n * console.log('Hello, world!');\n * }</code></pre>\n * </wc-code-highlighter>\n * ```\n * @tags display\n */\n@IndividualComponent\nexport class CodeHighlighter extends LitElement {\n static styles = [styles];\n\n private static readonly COPY_FEEDBACK_DURATION = 3000;\n\n @property({ type: String, reflect: true })\n language: BundledLanguage = 'javascript';\n\n @property({ attribute: 'line-numbers', type: Boolean, reflect: true })\n lineNumbers: boolean = false;\n\n @property({ type: String })\n value: string = '';\n\n @property({ type: Boolean, reflect: true })\n format?: boolean = true;\n\n @property({ type: Boolean })\n hideCopy: boolean = false;\n\n @state() private compiledCode: string | null = null;\n\n @state() private _copied = false;\n\n private parsedCode: string | null = null;\n\n private _copyFeedbackTimeout: number | null = null;\n\n async connectedCallback() {\n // eslint-disable-next-line wc/guard-super-call\n super.connectedCallback();\n }\n\n disconnectedCallback() {\n if (this._copyFeedbackTimeout !== null) {\n window.clearTimeout(this._copyFeedbackTimeout);\n this._copyFeedbackTimeout = null;\n }\n super.disconnectedCallback();\n }\n\n firstUpdated() {\n this.__highlightCode();\n }\n\n // eslint-disable-next-line class-methods-use-this\n private decode(str: string) {\n return str.replace(/</g, '<').replace(/>/g, '>');\n }\n\n private async __highlightCode() {\n let codeString = '';\n if (this.value) {\n codeString = this.value;\n } else {\n // Accessing light DOM children\n const codeTag = this.querySelector('code');\n if (codeTag) {\n codeString = codeTag.innerHTML;\n } else if (this.childNodes.length > 0) {\n codeString = (this as HTMLElement).innerText;\n }\n }\n\n codeString = this.decode(codeString);\n\n if (this.format !== false) {\n // eslint-disable-next-line default-case\n switch (this.language) {\n case 'javascript': {\n const [prettier, pluginBabel, pluginEstree] = await Promise.all([\n loadPrettier(),\n loadPluginBabel(),\n loadPluginEstree(),\n ]);\n codeString = await prettier.format(codeString, {\n parser: 'babel',\n plugins: [pluginBabel, pluginEstree],\n bracketSameLine: true,\n htmlWhitespaceSensitivity: 'ignore',\n });\n break;\n }\n case 'html': {\n const [prettier, pluginHtml] = await Promise.all([\n loadPrettier(),\n loadPluginHtml(),\n ]);\n codeString = await prettier.format(codeString, {\n parser: 'html',\n plugins: [pluginHtml],\n bracketSameLine: true,\n htmlWhitespaceSensitivity: 'ignore',\n });\n break;\n }\n case 'css': {\n const [prettier, pluginPostcss] = await Promise.all([\n loadPrettier(),\n loadPluginPostcss(),\n ]);\n codeString = await prettier.format(codeString, {\n parser: 'css',\n plugins: [pluginPostcss],\n });\n break;\n }\n }\n }\n\n this.parsedCode = codeString;\n\n const transformers: ShikiTransformer[] = [];\n\n // If line numbers are enabled, we inject a transformer\n // that adds the 'line' class to every line node.\n if (this.lineNumbers) {\n transformers.push({\n name: 'add-line-class',\n line(node) {\n // Shiki v1 helper to add classes to the AST\n this.addClassToHast(node, 'line');\n },\n });\n }\n\n const [\n { codeToHtml },\n [{ default: pierreDark }, { default: pierreLight }],\n ] = await Promise.all([loadShiki(), loadThemes()]);\n\n this.compiledCode = await codeToHtml(codeString, {\n lang: this.language,\n themes: {\n // @ts-ignore\n light: pierreLight,\n // @ts-ignore\n dark: pierreDark,\n },\n transformers,\n });\n }\n\n protected updated(changed: Map<PropertyKey, unknown>) {\n // Only re-highlight when the source content or rendering options change,\n // not on unrelated state updates like the copy-button feedback toggle.\n if (\n changed.has('value') ||\n changed.has('language') ||\n changed.has('lineNumbers') ||\n changed.has('format')\n ) {\n this.__highlightCode();\n }\n }\n\n private async __handleCopyClick() {\n if (this.parsedCode == null) {\n return;\n }\n\n await copyToClipboard(this.parsedCode);\n this._copied = true;\n\n if (this._copyFeedbackTimeout !== null) {\n window.clearTimeout(this._copyFeedbackTimeout);\n }\n\n this._copyFeedbackTimeout = window.setTimeout(() => {\n this._copied = false;\n this._copyFeedbackTimeout = null;\n }, CodeHighlighter.COPY_FEEDBACK_DURATION);\n }\n\n render() {\n if (this.compiledCode === null) {\n return html`\n <div class=\"code-loader\">\n <wc-circular-progress indeterminate></wc-circular-progress>\n ${locale.loading}\n </div>\n `;\n }\n\n return html`\n <div\n class=${classMap({\n 'code-highlighter': true,\n 'line-numbers': this.lineNumbers,\n })}\n >\n <div class=\"header\">\n <div class=\"header-title\">\n <slot name=\"title\">${this.language?.toUpperCase()}</slot>\n </div>\n <div class=\"header-actions\">\n <wc-icon-button\n color=${this._copied ? 'success' : 'surface'}\n variant=\"text\"\n size=\"xs\"\n aria-label=${this._copied\n ? locale.copied\n : locale.copyToClipboard}\n tooltip=${this._copied ? locale.copied : locale.copyToClipboard}\n @click=${this.__handleCopyClick}\n >\n <wc-icon\n name=${this._copied ? 'check' : 'content_copy'}\n ></wc-icon>\n </wc-icon-button>\n </div>\n </div>\n\n <div class=\"scroll-wrapper\">\n <div class=\"highlighter\">${unsafeHTML(this.compiledCode || '')}</div>\n </div>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","classMap","unsafeHTML","styles","property","state"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;AACA;AACA,IAAI,MAAM,GAA2C,IAAI;AACzD,IAA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AE,IAAI,EAAE;AACA,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAGzC,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AACxC,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAG7B,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACP,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAGnB,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAClB,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAGxB,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;AACD,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAET,UAAA,CAAA;AAAhB,IAAAC,CAAK;AAA8C,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAEnC,UAAA,CAAA;AAAhB,IAAAA,CAAK;AAA2B,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAtBtB,eAAe,GAAA,iBAAA,GAAA,UAAA,CAAA;IAD3B;AACY,CAAA,EAAA,eAAe,CA2N3B;;;;"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { i, _ as __decorate, I as IndividualComponent, b } from './IndividualComponent-Bdwyrvd6.js';
|
|
2
|
+
import { n } from './property-B49QQ8pS.js';
|
|
3
|
+
import { r } from './state-DkTK9EGF.js';
|
|
4
|
+
import { e } from './query-CHb9Ft_d.js';
|
|
5
|
+
import { o } from './style-map-BQD5Et1D.js';
|
|
6
|
+
import { B as BaseInput } from './BaseInput-CV0pZgSb.js';
|
|
7
|
+
import './base-Cl6v8-BZ.js';
|
|
8
|
+
import './directive-ZPhl09Yt.js';
|
|
9
|
+
import './element-internals-QME0yEz4.js';
|
|
10
|
+
import './form-associated-Bhwwr6dT.js';
|
|
11
|
+
|
|
12
|
+
var css_248z = i`* {
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
-webkit-tap-highlight-color: transparent;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.screen-reader-only {
|
|
18
|
+
display: none !important;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
[hidden] {
|
|
22
|
+
display: none !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
:host {
|
|
26
|
+
display: block;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.popover {
|
|
30
|
+
display: block;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.swatch {
|
|
34
|
+
background: transparent;
|
|
35
|
+
border: none;
|
|
36
|
+
appearance: none;
|
|
37
|
+
margin: 0;
|
|
38
|
+
outline: none;
|
|
39
|
+
padding: 0;
|
|
40
|
+
width: 1.5rem;
|
|
41
|
+
height: 1.5rem;
|
|
42
|
+
border-radius: var(--shape-corner-extra-small);
|
|
43
|
+
background-color: var(--_swatch-color);
|
|
44
|
+
box-shadow: inset 0 0 0 1px var(--color-outline-variant);
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
.swatch:focus-visible {
|
|
48
|
+
outline: 2px solid var(--color-primary);
|
|
49
|
+
outline-offset: 2px;
|
|
50
|
+
}
|
|
51
|
+
.swatch:disabled {
|
|
52
|
+
cursor: not-allowed;
|
|
53
|
+
opacity: var(--state-disabled-content-opacity, 0.38);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.input {
|
|
57
|
+
width: 100%;
|
|
58
|
+
min-width: 0;
|
|
59
|
+
padding: 0;
|
|
60
|
+
border: none;
|
|
61
|
+
outline: none;
|
|
62
|
+
background: transparent;
|
|
63
|
+
font: inherit;
|
|
64
|
+
color: inherit;
|
|
65
|
+
text-transform: lowercase;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.picker-panel {
|
|
69
|
+
--popover-content-min-width: auto;
|
|
70
|
+
}`;
|
|
71
|
+
|
|
72
|
+
const HEX_COLOR = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
73
|
+
/** Normalizes `abc`, `#ABC` or `#aabbcc` to `#aabbcc`; returns null for anything else. */
|
|
74
|
+
function normalizeHex(input) {
|
|
75
|
+
const match = input.trim().match(HEX_COLOR);
|
|
76
|
+
if (!match)
|
|
77
|
+
return null;
|
|
78
|
+
const hex = match[1].toLowerCase();
|
|
79
|
+
return `#${hex.length === 3 ? hex.replace(/./g, c => c + c) : hex}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @label Color Field
|
|
83
|
+
* @tag wc-color-field
|
|
84
|
+
* @rawTag color-field
|
|
85
|
+
*
|
|
86
|
+
* @summary A text field for a hex color, with a swatch that opens a color picker.
|
|
87
|
+
* @overview
|
|
88
|
+
* <p>Color field shows the current color as a swatch next to its hex value. Type a hex value, or
|
|
89
|
+
* click the swatch to pick one with <code>wc-color-picker</code> in a popover.</p>
|
|
90
|
+
* <p>It is form-associated: the hex value is submitted under its <code>name</code>.</p>
|
|
91
|
+
*
|
|
92
|
+
* @fires {CustomEvent<{value: string}>} input - Dispatched while the color changes in the picker.
|
|
93
|
+
* @fires {CustomEvent<{value: string}>} change - Dispatched when a color is committed, from the picker or the text field.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```html
|
|
97
|
+
* <wc-color-field label="Brand color" value="#7c5df0"></wc-color-field>
|
|
98
|
+
* ```
|
|
99
|
+
* @tags input, form
|
|
100
|
+
*/
|
|
101
|
+
let ColorField = class ColorField extends BaseInput {
|
|
102
|
+
constructor() {
|
|
103
|
+
// ── Static ───────────────────────────────────────────────────────────────
|
|
104
|
+
super(...arguments);
|
|
105
|
+
// ── Properties ───────────────────────────────────────────────────────────
|
|
106
|
+
/** The color as a 6-digit hex string, such as `"#7c5df0"`. */
|
|
107
|
+
this.value = '#7c5df0';
|
|
108
|
+
/** Label shown above the field. */
|
|
109
|
+
this.label = '';
|
|
110
|
+
/** Helper text shown below the field. */
|
|
111
|
+
this.helperText = '';
|
|
112
|
+
/** Visual variant of the field. */
|
|
113
|
+
this.variant = 'default';
|
|
114
|
+
/** Where the picker opens, relative to the field. */
|
|
115
|
+
this.placement = 'bottom-start';
|
|
116
|
+
// ── State ────────────────────────────────────────────────────────────────
|
|
117
|
+
/** Text in the hex input; differs from `value` while the user is typing. */
|
|
118
|
+
this.draft = '';
|
|
119
|
+
this.focused = false;
|
|
120
|
+
this.pickerOpen = false;
|
|
121
|
+
/** True after the user typed something that is not a hex color. */
|
|
122
|
+
this.invalid = false;
|
|
123
|
+
}
|
|
124
|
+
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
125
|
+
willUpdate(changed) {
|
|
126
|
+
if (changed.has('value')) {
|
|
127
|
+
this.draft = this.value;
|
|
128
|
+
this.invalid = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// ── Public methods ───────────────────────────────────────────────────────
|
|
132
|
+
focus() {
|
|
133
|
+
this.inputElement?.focus();
|
|
134
|
+
}
|
|
135
|
+
/** Opens the color picker. */
|
|
136
|
+
showPicker() {
|
|
137
|
+
if (this.disabled || this.readonly)
|
|
138
|
+
return;
|
|
139
|
+
this.popoverElement?.show();
|
|
140
|
+
}
|
|
141
|
+
// ── Private methods ──────────────────────────────────────────────────────
|
|
142
|
+
commit(value) {
|
|
143
|
+
this.value = value;
|
|
144
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
145
|
+
detail: { value },
|
|
146
|
+
bubbles: true,
|
|
147
|
+
composed: true,
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
handleSwatchClick(event) {
|
|
151
|
+
// Keep the field from moving focus to the text input.
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
if (this.pickerOpen) {
|
|
154
|
+
this.popoverElement?.hide();
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this.showPicker();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
handleTextInput(event) {
|
|
161
|
+
this.draft = event.target.value;
|
|
162
|
+
this.invalid = false;
|
|
163
|
+
}
|
|
164
|
+
handleTextChange() {
|
|
165
|
+
const hex = normalizeHex(this.draft);
|
|
166
|
+
if (!hex) {
|
|
167
|
+
this.invalid = this.draft.trim() !== '';
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (hex !== this.value)
|
|
171
|
+
this.commit(hex);
|
|
172
|
+
else
|
|
173
|
+
this.draft = hex;
|
|
174
|
+
}
|
|
175
|
+
handleTextKeyDown(event) {
|
|
176
|
+
if (event.key === 'Enter')
|
|
177
|
+
this.handleTextChange();
|
|
178
|
+
if (event.key === 'ArrowDown' && event.altKey) {
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
this.showPicker();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
handlePickerInput(event) {
|
|
184
|
+
event.stopPropagation();
|
|
185
|
+
this.value = event.detail.value;
|
|
186
|
+
this.dispatchEvent(new CustomEvent('input', {
|
|
187
|
+
detail: { value: this.value },
|
|
188
|
+
bubbles: true,
|
|
189
|
+
composed: true,
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
handlePickerChange(event) {
|
|
193
|
+
event.stopPropagation();
|
|
194
|
+
this.commit(event.detail.value);
|
|
195
|
+
}
|
|
196
|
+
// ── Render ───────────────────────────────────────────────────────────────
|
|
197
|
+
render() {
|
|
198
|
+
return b `
|
|
199
|
+
<wc-popover
|
|
200
|
+
class="popover"
|
|
201
|
+
trigger="manual"
|
|
202
|
+
placement=${this.placement}
|
|
203
|
+
offset="4"
|
|
204
|
+
@wc-popover--open=${() => {
|
|
205
|
+
this.pickerOpen = true;
|
|
206
|
+
}}
|
|
207
|
+
@wc-popover--close=${() => {
|
|
208
|
+
this.pickerOpen = false;
|
|
209
|
+
}}
|
|
210
|
+
>
|
|
211
|
+
<wc-field
|
|
212
|
+
label=${this.label}
|
|
213
|
+
helper-text=${this.helperText}
|
|
214
|
+
variant=${this.variant}
|
|
215
|
+
?required=${this.required}
|
|
216
|
+
?disabled=${this.disabled}
|
|
217
|
+
?readonly=${this.readonly}
|
|
218
|
+
?skeleton=${this.skeleton}
|
|
219
|
+
?error=${this.invalid}
|
|
220
|
+
error-text="Enter a hex color, such as #7c5df0"
|
|
221
|
+
populated
|
|
222
|
+
?focused=${this.focused || this.pickerOpen}
|
|
223
|
+
.host=${this}
|
|
224
|
+
>
|
|
225
|
+
<button
|
|
226
|
+
slot="field-start"
|
|
227
|
+
class="swatch"
|
|
228
|
+
type="button"
|
|
229
|
+
aria-label="Choose color"
|
|
230
|
+
aria-haspopup="dialog"
|
|
231
|
+
aria-expanded=${String(this.pickerOpen)}
|
|
232
|
+
?disabled=${this.disabled || this.readonly}
|
|
233
|
+
style=${o({ '--_swatch-color': this.value })}
|
|
234
|
+
@click=${this.handleSwatchClick}
|
|
235
|
+
></button>
|
|
236
|
+
<input
|
|
237
|
+
class="input"
|
|
238
|
+
name=${this.name}
|
|
239
|
+
spellcheck="false"
|
|
240
|
+
autocomplete="off"
|
|
241
|
+
maxlength="7"
|
|
242
|
+
aria-label=${this.label || 'Hex color'}
|
|
243
|
+
.value=${this.draft}
|
|
244
|
+
?disabled=${this.disabled}
|
|
245
|
+
?readonly=${this.readonly}
|
|
246
|
+
?required=${this.required}
|
|
247
|
+
@input=${this.handleTextInput}
|
|
248
|
+
@change=${this.handleTextChange}
|
|
249
|
+
@keydown=${this.handleTextKeyDown}
|
|
250
|
+
@focus=${() => {
|
|
251
|
+
this.focused = true;
|
|
252
|
+
}}
|
|
253
|
+
@blur=${() => {
|
|
254
|
+
this.focused = false;
|
|
255
|
+
}}
|
|
256
|
+
/>
|
|
257
|
+
</wc-field>
|
|
258
|
+
<wc-popover-content class="picker-panel">
|
|
259
|
+
<wc-color-picker
|
|
260
|
+
.value=${this.value}
|
|
261
|
+
?disabled=${this.disabled || this.readonly}
|
|
262
|
+
@input=${this.handlePickerInput}
|
|
263
|
+
@change=${this.handlePickerChange}
|
|
264
|
+
></wc-color-picker>
|
|
265
|
+
</wc-popover-content>
|
|
266
|
+
</wc-popover>
|
|
267
|
+
`;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
ColorField.styles = [css_248z];
|
|
271
|
+
__decorate([
|
|
272
|
+
n({ type: String, reflect: true })
|
|
273
|
+
], ColorField.prototype, "value", void 0);
|
|
274
|
+
__decorate([
|
|
275
|
+
n({ type: String })
|
|
276
|
+
], ColorField.prototype, "label", void 0);
|
|
277
|
+
__decorate([
|
|
278
|
+
n({ type: String, attribute: 'helper-text' })
|
|
279
|
+
], ColorField.prototype, "helperText", void 0);
|
|
280
|
+
__decorate([
|
|
281
|
+
n({ type: String })
|
|
282
|
+
], ColorField.prototype, "variant", void 0);
|
|
283
|
+
__decorate([
|
|
284
|
+
n({ type: String })
|
|
285
|
+
], ColorField.prototype, "placement", void 0);
|
|
286
|
+
__decorate([
|
|
287
|
+
r()
|
|
288
|
+
], ColorField.prototype, "draft", void 0);
|
|
289
|
+
__decorate([
|
|
290
|
+
r()
|
|
291
|
+
], ColorField.prototype, "focused", void 0);
|
|
292
|
+
__decorate([
|
|
293
|
+
r()
|
|
294
|
+
], ColorField.prototype, "pickerOpen", void 0);
|
|
295
|
+
__decorate([
|
|
296
|
+
r()
|
|
297
|
+
], ColorField.prototype, "invalid", void 0);
|
|
298
|
+
__decorate([
|
|
299
|
+
e('wc-popover')
|
|
300
|
+
], ColorField.prototype, "popoverElement", void 0);
|
|
301
|
+
__decorate([
|
|
302
|
+
e('.input')
|
|
303
|
+
], ColorField.prototype, "inputElement", void 0);
|
|
304
|
+
ColorField = __decorate([
|
|
305
|
+
IndividualComponent
|
|
306
|
+
], ColorField);
|
|
307
|
+
|
|
308
|
+
export { ColorField };
|
|
309
|
+
//# sourceMappingURL=color-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-field.js","sources":["../../src/color-field/color-field.ts"],"sourcesContent":["import { html } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport BaseInput from '../input/BaseInput.js';\nimport type { Popover } from '../popover/popover.js';\nimport styles from './color-field.scss';\n\nconst HEX_COLOR = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;\n\n/** Normalizes `abc`, `#ABC` or `#aabbcc` to `#aabbcc`; returns null for anything else. */\nfunction normalizeHex(input: string): string | null {\n const match = input.trim().match(HEX_COLOR);\n if (!match) return null;\n const hex = match[1].toLowerCase();\n return `#${hex.length === 3 ? hex.replace(/./g, c => c + c) : hex}`;\n}\n\n/**\n * @label Color Field\n * @tag wc-color-field\n * @rawTag color-field\n *\n * @summary A text field for a hex color, with a swatch that opens a color picker.\n * @overview\n * <p>Color field shows the current color as a swatch next to its hex value. Type a hex value, or\n * click the swatch to pick one with <code>wc-color-picker</code> in a popover.</p>\n * <p>It is form-associated: the hex value is submitted under its <code>name</code>.</p>\n *\n * @fires {CustomEvent<{value: string}>} input - Dispatched while the color changes in the picker.\n * @fires {CustomEvent<{value: string}>} change - Dispatched when a color is committed, from the picker or the text field.\n *\n * @example\n * ```html\n * <wc-color-field label=\"Brand color\" value=\"#7c5df0\"></wc-color-field>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class ColorField extends BaseInput {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** The color as a 6-digit hex string, such as `\"#7c5df0\"`. */\n @property({ type: String, reflect: true }) value = '#7c5df0';\n\n /** Label shown above the field. */\n @property({ type: String }) label = '';\n\n /** Helper text shown below the field. */\n @property({ type: String, attribute: 'helper-text' }) helperText = '';\n\n /** Visual variant of the field. */\n @property({ type: String }) variant: 'filled' | 'outlined' | 'default' =\n 'default';\n\n /** Where the picker opens, relative to the field. */\n @property({ type: String }) placement: Popover['placement'] = 'bottom-start';\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** Text in the hex input; differs from `value` while the user is typing. */\n @state() private draft = '';\n\n @state() private focused = false;\n\n @state() private pickerOpen = false;\n\n /** True after the user typed something that is not a hex color. */\n @state() private invalid = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('wc-popover') private popoverElement?: Popover;\n\n @query('.input') private inputElement?: HTMLInputElement;\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n protected override willUpdate(changed: Map<PropertyKey, unknown>) {\n if (changed.has('value')) {\n this.draft = this.value;\n this.invalid = false;\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n /** Opens the color picker. */\n showPicker() {\n if (this.disabled || this.readonly) return;\n this.popoverElement?.show();\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private commit(value: string) {\n this.value = value;\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: { value },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n private handleSwatchClick(event: MouseEvent) {\n // Keep the field from moving focus to the text input.\n event.stopPropagation();\n if (this.pickerOpen) {\n this.popoverElement?.hide();\n } else {\n this.showPicker();\n }\n }\n\n private handleTextInput(event: InputEvent) {\n this.draft = (event.target as HTMLInputElement).value;\n this.invalid = false;\n }\n\n private handleTextChange() {\n const hex = normalizeHex(this.draft);\n if (!hex) {\n this.invalid = this.draft.trim() !== '';\n return;\n }\n if (hex !== this.value) this.commit(hex);\n else this.draft = hex;\n }\n\n private handleTextKeyDown(event: KeyboardEvent) {\n if (event.key === 'Enter') this.handleTextChange();\n if (event.key === 'ArrowDown' && event.altKey) {\n event.preventDefault();\n this.showPicker();\n }\n }\n\n private handlePickerInput(event: CustomEvent<{ value: string }>) {\n event.stopPropagation();\n this.value = event.detail.value;\n this.dispatchEvent(\n new CustomEvent('input', {\n detail: { value: this.value },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n private handlePickerChange(event: CustomEvent<{ value: string }>) {\n event.stopPropagation();\n this.commit(event.detail.value);\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n return html`\n <wc-popover\n class=\"popover\"\n trigger=\"manual\"\n placement=${this.placement}\n offset=\"4\"\n @wc-popover--open=${() => {\n this.pickerOpen = true;\n }}\n @wc-popover--close=${() => {\n this.pickerOpen = false;\n }}\n >\n <wc-field\n label=${this.label}\n helper-text=${this.helperText}\n variant=${this.variant}\n ?required=${this.required}\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n ?skeleton=${this.skeleton}\n ?error=${this.invalid}\n error-text=\"Enter a hex color, such as #7c5df0\"\n populated\n ?focused=${this.focused || this.pickerOpen}\n .host=${this}\n >\n <button\n slot=\"field-start\"\n class=\"swatch\"\n type=\"button\"\n aria-label=\"Choose color\"\n aria-haspopup=\"dialog\"\n aria-expanded=${String(this.pickerOpen)}\n ?disabled=${this.disabled || this.readonly}\n style=${styleMap({ '--_swatch-color': this.value })}\n @click=${this.handleSwatchClick}\n ></button>\n <input\n class=\"input\"\n name=${this.name}\n spellcheck=\"false\"\n autocomplete=\"off\"\n maxlength=\"7\"\n aria-label=${this.label || 'Hex color'}\n .value=${this.draft}\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n ?required=${this.required}\n @input=${this.handleTextInput}\n @change=${this.handleTextChange}\n @keydown=${this.handleTextKeyDown}\n @focus=${() => {\n this.focused = true;\n }}\n @blur=${() => {\n this.focused = false;\n }}\n />\n </wc-field>\n <wc-popover-content class=\"picker-panel\">\n <wc-color-picker\n .value=${this.value}\n ?disabled=${this.disabled || this.readonly}\n @input=${this.handlePickerInput}\n @change=${this.handlePickerChange}\n ></wc-color-picker>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MAAA,CAAA;AAE7B,UAAA,CAAA;IAAxBA,CAAK,CAAC,QAAQ;AAA0C,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAvC9C,UAAU,GAAA,UAAA,CAAA;IADtB;AACY,CAAA,EAAA,UAAU,CAuMtB;;;;"}
|
package/dist/color-picker.js
CHANGED
|
@@ -11,7 +11,17 @@ var css_248z = i`:host {
|
|
|
11
11
|
--_thumb-size: 16px;
|
|
12
12
|
--_track-height: 12px;
|
|
13
13
|
--_preview-size: 40px;
|
|
14
|
-
--_radius:
|
|
14
|
+
--_radius: var(--shape-corner-small);
|
|
15
|
+
--_ring-color: var(--color-white);
|
|
16
|
+
--_ring-shadow:
|
|
17
|
+
0 0 0 1px color-mix(in srgb, var(--color-shadow) 30%, transparent),
|
|
18
|
+
0 2px 4px color-mix(in srgb, var(--color-shadow) 30%, transparent);
|
|
19
|
+
--_checker:
|
|
20
|
+
repeating-conic-gradient(
|
|
21
|
+
var(--color-neutral-80) 0% 25%,
|
|
22
|
+
var(--color-white) 0% 50%
|
|
23
|
+
)
|
|
24
|
+
0 0 / 8px 8px;
|
|
15
25
|
display: inline-block;
|
|
16
26
|
width: var(--color-picker-width, 240px);
|
|
17
27
|
touch-action: none;
|
|
@@ -32,7 +42,7 @@ var css_248z = i`:host {
|
|
|
32
42
|
width: 100%;
|
|
33
43
|
height: var(--_sv-height);
|
|
34
44
|
border-radius: var(--_radius);
|
|
35
|
-
background: linear-gradient(to bottom, transparent 0%,
|
|
45
|
+
background: linear-gradient(to bottom, transparent 0%, var(--color-black) 100%), linear-gradient(to right, var(--color-white) 0%, var(--hue-color) 100%);
|
|
36
46
|
cursor: crosshair;
|
|
37
47
|
user-select: none;
|
|
38
48
|
overflow: hidden;
|
|
@@ -43,14 +53,14 @@ var css_248z = i`:host {
|
|
|
43
53
|
width: var(--_thumb-size);
|
|
44
54
|
height: var(--_thumb-size);
|
|
45
55
|
border-radius: 50%;
|
|
46
|
-
border: 2px solid
|
|
47
|
-
box-shadow:
|
|
56
|
+
border: 2px solid var(--_ring-color);
|
|
57
|
+
box-shadow: var(--_ring-shadow);
|
|
48
58
|
transform: translate(-50%, -50%);
|
|
49
59
|
outline: none;
|
|
50
60
|
cursor: crosshair;
|
|
51
61
|
}
|
|
52
62
|
.sv-cursor:focus-visible {
|
|
53
|
-
box-shadow: 0 0 0 2px
|
|
63
|
+
box-shadow: 0 0 0 2px var(--_ring-color), 0 0 0 4px var(--color-primary);
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
.controls-row {
|
|
@@ -65,8 +75,8 @@ var css_248z = i`:host {
|
|
|
65
75
|
border-radius: 50%;
|
|
66
76
|
flex-shrink: 0;
|
|
67
77
|
overflow: hidden;
|
|
68
|
-
background:
|
|
69
|
-
box-shadow: inset 0 0 0 1px
|
|
78
|
+
background: var(--_checker);
|
|
79
|
+
box-shadow: inset 0 0 0 1px var(--color-outline-variant);
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
.preview-inner {
|
|
@@ -95,7 +105,7 @@ var css_248z = i`:host {
|
|
|
95
105
|
}
|
|
96
106
|
|
|
97
107
|
.alpha-track {
|
|
98
|
-
background: linear-gradient(to right, transparent, var(--current-color, currentColor)),
|
|
108
|
+
background: linear-gradient(to right, transparent, var(--current-color, currentColor)), var(--_checker);
|
|
99
109
|
}
|
|
100
110
|
|
|
101
111
|
.slider-thumb {
|
|
@@ -104,20 +114,20 @@ var css_248z = i`:host {
|
|
|
104
114
|
width: var(--_thumb-size);
|
|
105
115
|
height: var(--_thumb-size);
|
|
106
116
|
border-radius: 50%;
|
|
107
|
-
background:
|
|
108
|
-
border: 2px solid
|
|
109
|
-
box-shadow:
|
|
117
|
+
background: var(--_ring-color);
|
|
118
|
+
border: 2px solid color-mix(in srgb, var(--color-shadow) 15%, transparent);
|
|
119
|
+
box-shadow: var(--elevation-level1);
|
|
110
120
|
transform: translate(-50%, -50%);
|
|
111
121
|
cursor: grab;
|
|
112
122
|
outline: none;
|
|
113
123
|
transition: box-shadow 0.15s ease;
|
|
114
124
|
}
|
|
115
125
|
.slider-thumb:focus-visible {
|
|
116
|
-
box-shadow: 0 0 0 2px
|
|
126
|
+
box-shadow: 0 0 0 2px var(--_ring-color), 0 0 0 4px var(--color-primary);
|
|
117
127
|
}
|
|
118
128
|
.slider-thumb:active {
|
|
119
129
|
cursor: grabbing;
|
|
120
|
-
box-shadow:
|
|
130
|
+
box-shadow: var(--elevation-level3);
|
|
121
131
|
}
|
|
122
132
|
|
|
123
133
|
.inputs-row {
|
|
@@ -158,7 +168,7 @@ var css_248z = i`:host {
|
|
|
158
168
|
background: transparent;
|
|
159
169
|
outline: none;
|
|
160
170
|
font-size: 13px;
|
|
161
|
-
font-family: var(--
|
|
171
|
+
font-family: var(--font-family-monospace, monospace);
|
|
162
172
|
color: var(--color-on-surface, #333);
|
|
163
173
|
}
|
|
164
174
|
|
|
@@ -329,7 +339,8 @@ let ColorPicker = class ColorPicker extends i$1 {
|
|
|
329
339
|
this._syncFromValue();
|
|
330
340
|
this._lastEmittedValue = this.value;
|
|
331
341
|
}
|
|
332
|
-
updated
|
|
342
|
+
// willUpdate, not updated: syncing the HSV state here lands in the same render.
|
|
343
|
+
willUpdate(changed) {
|
|
333
344
|
if (changed.has('value') && this.value !== this._lastEmittedValue) {
|
|
334
345
|
this._syncFromValue();
|
|
335
346
|
}
|