UNPKG

svgedit

Version:

Powerful SVG-Editor for your browser

899 lines (774 loc) 24.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: components/seColorPicker.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: components/seColorPicker.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/* globals svgEditor */ import { jGraduate, jGraduateMethod } from './jgraduate/jQuery.jGraduate.js' import PaintBox from './PaintBox.js' import { t } from '../locale.js' const template = document.createElement('template') template.innerHTML = ` &lt;style> .jPicker .Icon { display: inline-block; height: 24px; position: relative; text-align: left; width: 25px } .jPicker .Icon span.Color, .jPicker .Icon span.Alpha { background-position: 2px 2px; display: block; height: 100%; left: 0; position: absolute; top: 0; width: 100% } .jPicker .Icon span.Image { background-repeat: no-repeat; cursor: pointer; display: block; height: 100%; left: 0; position: absolute; top: 0; width: 100% } .jPicker.Container { z-index: 10 } table.jPicker { background-color: #efefef; border: 1px outset #666; font-family: Arial, Helvetica, Sans-Serif; font-size: 12px!important; margin: 0; padding: 5px; width: 545px; z-index: 20 } .jPicker .Move { background-color: #ddd; border-color: #fff #666 #666 #fff; border-style: solid; border-width: 1px; cursor: move; height: 12px; padding: 0 } .jPicker .Title { font-size: 11px!important; font-weight: bold; margin: -2px 0 0 0; padding: 0; text-align: center; width: 100% } .jPicker div.Map { border-bottom: 2px solid #fff; border-left: 2px solid #9a9a9a; border-right: 2px solid #fff; border-top: 2px solid #9a9a9a; cursor: crosshair; height: 260px; margin: 0 5px 0 5px; overflow: hidden; padding: 0; position: relative; width: 260px } .jPicker div[class="Map"] { height: 256px; width: 256px } .jPicker div.Bar { border-bottom: 2px solid #fff; border-left: 2px solid #9a9a9a; border-right: 2px solid #fff; border-top: 2px solid #9a9a9a; cursor: n-resize; height: 260px; margin: 12px 10px 0 5px; overflow: hidden; padding: 0; position: relative; width: 24px } .jPicker div[class="Bar"] { height: 256px; width: 20px } .jPicker .Map .Map1, .jPicker .Map .Map2, .jPicker .Map .Map3, .jPicker .Bar .Map1, .jPicker .Bar .Map2, .jPicker .Bar .Map3, .jPicker .Bar .Map4, .jPicker .Bar .Map5, .jPicker .Bar .Map6 { background-color: transparent; background-image: none; display: block; left: 0; position: absolute; top: 0 } .jPicker .Map .Map1, .jPicker .Map .Map2, .jPicker .Map .Map3 { height: 2596px; width: 256px } .jPicker .Bar .Map1, .jPicker .Bar .Map2, .jPicker .Bar .Map3, .jPicker .Bar .Map4 { height: 3896px; width: 20px } .jPicker .Bar .Map5, .jPicker .Bar .Map6 { height: 256px; width: 20px } .jPicker .Map .Map1, .jPicker .Map .Map2, .jPicker .Bar .Map6 { background-repeat: no-repeat } .jPicker .Map .Map3, .jPicker .Bar .Map5 { background-repeat: repeat } .jPicker .Bar .Map1, .jPicker .Bar .Map2, .jPicker .Bar .Map3, .jPicker .Bar .Map4 { background-repeat: repeat-x } .jPicker .Map .Arrow { display: block; position: absolute } .jPicker .Bar .Arrow { display: block; left: 0; position: absolute } .jPicker .Preview { font-size: 9px; text-align: center } .jPicker .Preview div { border: 2px inset #eee; height: 62px; margin: 0 auto; padding: 0; width: 62px } .jPicker .Preview div span { border: 1px solid #000; display: block; height: 30px; margin: 0 auto; padding: 0; width: 60px } .jPicker .Preview .Active { border-bottom-width: 0 } .jPicker .Preview .Current { border-top-width: 0; cursor: pointer } .jPicker .Button { text-align: center; width: 115px } .jPicker .Button input { width: 100px } .jPicker .Button .Ok { margin: 12px 0 5px 0 } .jPicker td.Radio { margin: 0; padding: 0; width: 31px } .jPicker td.Radio input { margin: 0 5px 0 0; padding: 0 } .jPicker td.Text { font-size: 12px!important; height: 22px; margin: 0; padding: 0; text-align: left; width: 70px } .jPicker tr.Hex td.Text { width: 100px } .jPicker td.Text input { background-color: #fff; border: 1px inset #aaa; height: 19px; margin: 0 0 0 5px; text-align: left; width: 30px } .jPicker td[class="Text"] input { height: 15px } .jPicker tr.Hex td.Text input.Hex { width: 50px } .jPicker tr.Hex td.Text input.AHex { width: 20px } .jPicker .Grid { text-align: center; width: 114px } .jPicker .Grid span.QuickColor { border: 1px inset #aaa; cursor: pointer; display: inline-block; height: 15px; line-height: 15px; margin: 0; padding: 0; width: 19px } .jPicker .Grid span[class="QuickColor"] { width: 17px } /* * jGraduate Default CSS * * Copyright (c) 2010 Jeff Schiller * http://blog.codedread.com/ * * Copyright (c) 2010 Alexis Deveria * http://a.deveria.com/ * * Licensed under the MIT License */ h2.jGraduate_Title { font-family: Arial, Helvetica, Sans-Serif; font-size: 11px !important; font-weight: bold; margin: -13px 0px 0px 0px; padding: 0px; text-align: center; } .jGraduate_Picker { font-family: Arial, Helvetica, Sans-Serif; font-size: 12px; border-style: solid; border-color: lightgrey black black lightgrey; border-width: 1px; background-color: #EFEFEF; position: absolute; padding: 10px; } .jGraduate_tabs li { background-color: #ccc; display: inline; border: solid 1px grey; padding: 3px; margin: 2px; cursor: pointer; } li.jGraduate_tab_current { background-color: #EFEFEF; display: inline; padding: 3px; margin: 2px; border: solid 1px black; cursor: pointer; } .jGraduate_colPick { display: none; } .jGraduate_gradPick { display: none; border: outset 1px #666; padding: 10px 7px 5px 5px; overflow: auto; } .jGraduate_gradPick { display: none; border: outset 1px #666; padding: 10px 7px 5px 5px; overflow: auto; /* position: relative;*/ } .jGraduate_tabs { position: relative; background-color: #EFEFEF; padding: 0px; margin: 0px; margin-bottom: 5px; } div.jGraduate_Swatch { float: left; margin: 8px; } div.jGraduate_GradContainer { border: 2px inset #EEE; background-image: url(./components/jgraduate/images/map-opacity.png); background-position: 0px 0px; height: 256px; width: 256px; position: relative; } div.jGraduate_GradContainer div.grad_coord { background: #000; border: 1px solid #fff; border-radius: 5px; -moz-border-radius: 5px; width: 10px; height: 10px; position: absolute; margin: -5px -5px; top: 0; left: 0; text-align: center; font-size: xx-small; line-height: 10px; color: #fff; text-decoration: none; cursor: pointer; -moz-user-select: none; -webkit-user-select: none; } .jGraduate_AlphaArrows { position: absolute; margin-top: -10px; margin-left: 250.5px; } div.jGraduate_Opacity { border: 2px inset #eee; margin-top: 14px; background-color: black; background-image: url(../images/Maps.png); background-position: 0px -2816px; height: 20px; cursor: ew-resize; } div.jGraduate_StopSlider { /* border: 2px inset #eee;*/ margin: 0 0 0 -10px; width: 276px; overflow: visible; background: #efefef; height: 45px; cursor: pointer; } div.jGraduate_StopSection { width: 120px; text-align: center; } input.jGraduate_Ok, input.jGraduate_Cancel { display: block; width: 100px; margin-left: -4px; margin-right: -4px; } input.jGraduate_Ok { margin: 9px -4px 5px -4px; } .colorBox { float: left; height: 16px; width: 16px; border: 1px solid var(--border-color); cursor: pointer; margin: 4px 4px 4px 30px; } .colorBox + label { float: left; margin-top: 7px; } label.jGraduate_Form_Heading { position: relative; top: 10px; background-color: #EFEFEF; padding: 2px; font-weight: bold; font-size: 13px; } div.jGraduate_Form_Section { border-style: solid; border-width: 1px; border-color: grey; -moz-border-radius: 5px; -webkit-border-radius: 5px; padding: 15px 5px 5px 5px; margin: 5px 2px; width: 110px; text-align: center; overflow: auto; } div.jGraduate_Form_Section label { padding: 0 2px; } div.jGraduate_StopSection input[type=text], div.jGraduate_Slider input[type=text] { width: 33px; } div.jGraduate_LightBox { position: fixed; top: 0px; left: 0px; right: 0px; bottom: 0px; background-color: #000; opacity: 0.5; display: none; } div.jGraduate_stopPicker { position: absolute; display: none; background: #E8E8E8; } .jGraduate_gradPick { width: 535px; } .jGraduate_gradPick div.jGraduate_OpacField { position: absolute; left: 0; bottom: 5px; /* width: 270px; left: 284px; width: 266px; height: 200px; top: 167px; margin: -3px 3px 0px 4px; */ } .jGraduate_gradPick .jGraduate_Form { float: left; width: 270px; position: absolute; left: 284px; width: 266px; height: 200px; top: 167px; margin: -3px 3px 0px 10px; } .jGraduate_gradPick .jGraduate_Points { position: static; width: 150px; margin-left: 0; } .jGraduate_SpreadMethod { position: absolute; right: 8px; top: 100px; } .jGraduate_Colorblocks { display: table; border-spacing: 0 5px; } .jGraduate_colorblock { display: table-row; } .jGraduate_Colorblocks .jGraduate_colorblock > * { display: table-cell; vertical-align: middle; margin: 0; float: none; } .jGraduate_gradPick div.jGraduate_StopSection { float: left; width: 133px; margin-top: -8px; } .jGraduate_gradPick .jGraduate_Form_Section { padding-top: 9px; } .jGraduate_Slider { text-align: center; float: left; width: 100%; } .jGraduate_Slider .jGraduate_Form_Section { border: none; width: 250px; padding: 0 2px; overflow: visible; } .jGraduate_Slider label { display: inline-block; float: left; line-height: 50px; padding: 0; } .jGraduate_Slider label.prelabel { width: 40px; text-align: left; } .jGraduate_SliderBar { width: 140px; float: left; margin-right: 5px; border:1px solid #BBB; height:20px; margin-top:14px; margin-left:5px; position: relative; } div.jGraduate_Slider input { margin-top: 5px; } div.jGraduate_Slider img { top: 0; left: 0; position: absolute; margin-top: -10px; cursor:ew-resize; } .jGraduate_gradPick .jGraduate_OkCancel { position: absolute; top: 39px; right: 10px; width: 113px; } .jGraduate_OpacField { position: absolute; right: -10px; bottom: 0; } #logo { height: 18px; width: 18px; } #block { height: 17px; width: 14px; float: right; background-color: darkgrey; } #picker { background: var(--input-color); height: 23px; line-height: 23px; border-radius: 3px; width: 52px; display: flex; align-items: center; margin-right: 4px; margin-top: 1px; justify-content: space-evenly; } #color_picker { z-index: 1000; bottom: 0; } &lt;/style> &lt;div id="picker"> &lt;img src="logo.svg" alt="icon" id="logo"> &lt;label for="color" title="" id="label">&lt;/label> &lt;div id="block"> &lt;/div> &lt;/div> &lt;!-- hidden div --> &lt;div id="color_picker">&lt;/div> ` /** * @class SeColorPicker */ export class SeColorPicker extends HTMLElement { /** * @function constructor */ constructor () { super() // create the shadowDom and insert the template this._shadowRoot = this.attachShadow({ mode: 'open' }) this._shadowRoot.append(template.content.cloneNode(true)) this.$logo = this._shadowRoot.getElementById('logo') this.$label = this._shadowRoot.getElementById('label') this.$block = this._shadowRoot.getElementById('block') this.paintBox = null this.i18next = null this.$picker = this._shadowRoot.getElementById('picker') this.$color_picker = this._shadowRoot.getElementById('color_picker') this.imgPath = svgEditor.configObj.curConfig.imgPath } /** * @function init * @param {any} name * @returns {void} */ init (i18next) { this.i18next = i18next this.setAttribute('config-change_xxx_color', t('config.change_xxx_color')) } /** * @function observedAttributes * @returns {any} observed */ static get observedAttributes () { return ['label', 'src', 'type', 'config-change_xxx_color'] } /** * @function attributeChangedCallback * @param {string} name * @param {string} oldValue * @param {string} newValue * @returns {void} */ attributeChangedCallback (name, oldValue, newValue) { if (oldValue === newValue) return switch (name) { case 'src': this.$logo.setAttribute('src', this.imgPath + '/' + newValue) break case 'label': this.setAttribute('title', t(newValue)) break case 'type': this.$label.setAttribute('title', 'config.pick_paint_opavity') break case 'config-change_xxx_color': this.$label.setAttribute('title', newValue) break default: console.error(`unknown attribute: ${name}`) break } } /** * @function get * @returns {any} */ get label () { return this.$label.getAttribute('title') } /** * @function set * @returns {void} */ set label (value) { this.setAttribute('label', value) } /** * @function get * @returns {any} */ get type () { return this.getAttribute('type') } /** * @function set * @returns {void} */ set type (value) { this.setAttribute('type', value) } /** * @function get * @returns {any} */ get src () { return this.getAttribute('src') } /** * @function set * @returns {void} */ set src (value) { this.setAttribute('src', value) } // Wrap jGraduateMethod in a Promise jGraduateMethodAsync () { return new Promise((resolve, reject) => { jGraduateMethod( this.$color_picker, { images: { clientPath: './components/jgraduate/images/' }, paint: this.paintBox.paint, window: { pickerTitle: this.label }, newstop: 'inverse' }, (p) => resolve(p), () => reject(new Error('jGraduate cancelled')), this.i18next ) }) } async setJGraduateMethod () { try { const p = await this.jGraduateMethodAsync() const paint = new jGraduate.Paint(p) this.setPaint(paint) this.dispatchEvent(new CustomEvent('change', { detail: { paint } })) } catch (err) { // Handle rejection if needed } finally { this.$color_picker.style.display = 'none' } } /** * @param {PlainObject} svgCanvas * @param {PlainObject} selectedElement * @param {bool} apply * @returns {void} */ update (svgCanvas, selectedElement, apply) { const paint = this.paintBox.update(svgCanvas, selectedElement) // We check if the color picker popup is already open if (this.$color_picker.style.display === 'block') { // We recreate the color picker popup with the current color of the selected elements this.setJGraduateMethod() } if (paint &amp;&amp; apply) { this.setPaint(paint) const changeEvent = new CustomEvent('change', { detail: { paint } }) this.dispatchEvent(changeEvent) } } /** * @param {PlainObject} paint * @returns {void} */ setPaint (paint) { this.paintBox.setPaint(paint) } /** * @function connectedCallback * @returns {void} */ connectedCallback () { this.paintBox = new PaintBox(this.$block, this.type) svgEditor.$click(this.$picker, () => { this.setJGraduateMethod() }) } } // Register customElements.define('se-colorpicker', SeColorPicker) </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="editor_extensions_ext-layer_view_locale_zh-CN.module_js.html">editor/extensions/ext-layer_view/locale/zh-CN.js</a></li><li><a href="module-SVGEditor.html">SVGEditor</a></li><li><a href="module-contextmenu.html">contextmenu</a></li><li><a href="module-jGraduate.html">jGraduate</a></li><li><a href="module-jPicker.html">jPicker</a></li><li><a href="module-locale.html">locale</a></li></ul><h3>Externals</h3><ul><li><a href="external-JamilihArray.html">JamilihArray</a></li><li><a href="external-Math.html">Math</a></li><li><a href="external-Window.html">Window</a></li><li><a href="external-jQuery.html">jQuery</a></li></ul><h3>Namespaces</h3><ul><li><a href="external-jQuery.fn.html">fn</a></li><li><a href="external-jQuery.fn.$.fn.jPicker.defaults.html">defaults</a></li><li><a href="external-jQuery.fn.exports.jPickerMethod.html">exports.jPickerMethod</a></li><li><a href="external-jQuery.fn.jGraduateDefaults.html">jGraduateDefaults</a></li><li><a href="external-jQuery.fn.jGraduateDefaults.images.html">images</a></li><li><a href="external-jQuery.fn.jGraduateDefaults.window.html">window</a></li><li><a href="external-jQuery.jGraduate.html">jGraduate</a></li><li><a href="external-jQuery.jPicker.html">jPicker</a></li><li><a href="external-jQuery.jPicker.ColorMethods.html">ColorMethods</a></li></ul><h3>Classes</h3><ul><li><a href="BottomPanel.html">BottomPanel</a></li><li><a href="Dropdown.html">Dropdown</a></li><li><a href="EditorStartup.html">EditorStartup</a></li><li><a href="ElixMenuButton.html">ElixMenuButton</a></li><li><a href="ElixNumberSpinBox.html">ElixNumberSpinBox</a></li><li><a href="ExplorerButton.html">ExplorerButton</a></li><li><a href="FlyingButton.html">FlyingButton</a></li><li><a href="LayersPanel.html">LayersPanel</a></li><li><a href="LeftPanel.html">LeftPanel</a></li><li><a href="MainMenu.html">MainMenu</a></li><li><a href="NumberSpinBox.html">NumberSpinBox</a></li><li><a href="PaintBox.html">PaintBox</a></li><li><a href="PlainNumberSpinBox.html">PlainNumberSpinBox</a></li><li><a href="Rulers.html">Rulers</a></li><li><a href="SEInput.html">SEInput</a></li><li><a href="SEPalette.html">SEPalette</a></li><li><a href="SESpinInput.html">SESpinInput</a></li><li><a href="SeCMenuDialog.html">SeCMenuDialog</a></li><li><a href="SeCMenuLayerDialog.html">SeCMenuLayerDialog</a></li><li><a href="SeColorPicker.html">SeColorPicker</a></li><li><a href="SeEditPrefsDialog.html">SeEditPrefsDialog</a></li><li><a href="SeExportDialog.html">SeExportDialog</a></li><li><a href="SeImgPropDialog.html">SeImgPropDialog</a></li><li><a href="SeList.html">SeList</a></li><li><a href="SeMenu.html">SeMenu</a></li><li><a href="SeMenuItem.html">SeMenuItem</a></li><li><a href="SePlainAlertDialog.html">SePlainAlertDialog</a></li><li><a href="SePlainBorderButton.html">SePlainBorderButton</a></li><li><a href="SePromptDialog.html">SePromptDialog</a></li><li><a href="SeStorageDialog.html">SeStorageDialog</a></li><li><a href="SeSvgSourceEditorDialog.html">SeSvgSourceEditorDialog</a></li><li><a href="SeText.html">SeText</a></li><li><a href="ToolButton.html">ToolButton</a></li><li><a href="TopPanel.html">TopPanel</a></li><li><a href="configObj.html">configObj</a></li><li><a href="external-jQuery.jGraduate.Paint.html">Paint</a></li><li><a href="external-jQuery.jPicker.Color.html">Color</a></li><li><a href="module.exports.html">exports</a></li><li><a href="module.exports_module.exports.html">exports</a></li><li><a href="module-SVGEditor-Editor.html">Editor</a></li><li><a href="module-jPicker.module.exports.html">module.exports</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-SVGEditor.Config.html">Config</a></li><li><a href="module-SVGEditor.Prefs.html">Prefs</a></li><li><a href="module-SVGthis.CustomHandler.html">CustomHandler</a></li><li><a href="module-locale.LocaleEditorInit.html">LocaleEditorInit</a></li></ul><h3>Events</h3><ul><li><a href="module-SVGEditor.html#event:event:svgEditorReadyEvent">svgEditorReadyEvent</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-CanvasAPI.html">CanvasAPI</a></li><li><a href="tutorial-Editor.html">Editor</a></li><li><a href="tutorial-EditorAPI.html">EditorAPI</a></li><li><a href="tutorial-Events.html">Events</a></li><li><a href="tutorial-FrequentlyAskedQuestions.html">Frequently Asked Questions (FAQ)</a></li></ul><h3>Global</h3><ul><li><a href="global.html#attributeChangedCallback">attributeChangedCallback</a></li><li><a href="global.html#connectedCallback">connectedCallback</a></li><li><a href="global.html#constructor">constructor</a></li><li><a href="global.html#createTemplate">createTemplate</a></li><li><a href="global.html#decrement">decrement</a></li><li><a href="global.html#expireCookie">expireCookie</a></li><li><a href="global.html#formatValueFormatthenumericvalueasastring.Thisisusedafterincrementing/decrementingthevaluetoreformatthevalueasastring.">formatValue Format the numeric value as a string. This is used after incrementing/decrementing the value to reformat the value as a string.</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#handleClick">handleClick</a></li><li><a href="global.html#handleClose">handleClose</a></li><li><a href="global.html#handleInput">handleInput</a></li><li><a href="global.html#handleKeyDown">handleKeyDown</a></li><li><a href="global.html#handleMouseDown">handleMouseDown</a></li><li><a href="global.html#handleMouseUp">handleMouseUp</a></li><li><a href="global.html#handleOptionsChange">handleOptionsChange</a></li><li><a href="global.html#handleSelect">handleSelect</a></li><li><a href="global.html#handleShow">handleShow</a></li><li><a href="global.html#increment">increment</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#inputsize">inputsize</a></li><li><a href="global.html#isNullish">isNullish</a></li><li><a href="global.html#loadloadConfig">load load Config</a></li><li><a href="global.html#loadFromURLLoadconfig/datafromURLifgiven">loadFromURL Load config/data from URL if given</a></li><li><a href="global.html#name">name</a></li><li><a href="global.html#observedAttributes">observedAttributes</a></li><li><a href="global.html#parseValue">parseValue</a></li><li><a href="global.html#pref">pref</a></li><li><a href="global.html#readySignal">readySignal</a></li><li><a href="global.html#regexEscape">regexEscape</a></li><li><a href="global.html#removeStoragePrefCookie">removeStoragePrefCookie</a></li><li><a href="global.html#replaceStoragePrompt">replaceStoragePrompt</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#setupCurConfig">setupCurConfig</a></li><li><a href="global.html#setupCurPrefs">setupCurPrefs</a></li><li><a href="global.html#src">src</a></li><li><a href="global.html#stateEffects">stateEffects</a></li><li><a href="global.html#stepDown">stepDown</a></li><li><a href="global.html#stepUp">stepUp</a></li><li><a href="global.html#triggerInputChanged">triggerInputChanged</a></li><li><a href="global.html#updateLib">updateLib</a></li><li><a href="global.html#value">value</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Sun Dec 07 2025 19:46:40 GMT+0100 (Central European Standard Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>