@ew-color-picker/eyedropper 2.0.13 → 2.0.15
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/eyedropper.esm.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (c) 2024-2026 eveningwater(854806732@qq.com)
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
import { extend, warn, create, addClass, setAttr, eyedropperIcon, insertNode, $, on, off, removeElement, ApplyOrder, getPrefix, isFunction } from '@ew-color-picker/utils';
|
|
6
|
+
import { extend, warn, create, addClass, setAttr, eyedropperIcon, setContent, insertNode, $, on, off, removeElement, ApplyOrder, getPrefix, isFunction } from '@ew-color-picker/utils';
|
|
7
7
|
|
|
8
8
|
/******************************************************************************
|
|
9
9
|
Copyright (c) Microsoft Corporation.
|
|
@@ -149,18 +149,25 @@ var ewColorPickerEyedropperPlugin = /** @class */ (function () {
|
|
|
149
149
|
var extraRow = this.getExtraRow(panelContainer);
|
|
150
150
|
this.container = create("div");
|
|
151
151
|
addClass(this.container, "".concat(this.prefix, "color-picker-eyedropper-group"));
|
|
152
|
+
var label = this.options.eyedropperText;
|
|
153
|
+
// title / aria-label 只接受纯文本,节点取其 textContent
|
|
154
|
+
var labelText = label
|
|
155
|
+
? typeof label === "string"
|
|
156
|
+
? label
|
|
157
|
+
: label.textContent || "取色"
|
|
158
|
+
: "取色";
|
|
152
159
|
this.button = create("button");
|
|
153
160
|
addClass(this.button, "".concat(this.prefix, "color-picker-eyedropper-btn"));
|
|
154
161
|
setAttr(this.button, {
|
|
155
162
|
type: "button",
|
|
156
|
-
title:
|
|
157
|
-
"aria-label":
|
|
163
|
+
title: labelText,
|
|
164
|
+
"aria-label": labelText,
|
|
158
165
|
});
|
|
159
166
|
this.button.innerHTML = eyedropperIcon(undefined, 16, this.prefix);
|
|
160
|
-
if (
|
|
167
|
+
if (label) {
|
|
161
168
|
var text = create("span");
|
|
162
169
|
addClass(text, "".concat(this.prefix, "color-picker-eyedropper-text"));
|
|
163
|
-
text
|
|
170
|
+
setContent(text, label, { html: this.options.eyedropperTextHtml });
|
|
164
171
|
insertNode(this.button, text);
|
|
165
172
|
}
|
|
166
173
|
insertNode(this.container, this.button);
|
package/dist/eyedropper.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["@ew-color-picker/utils"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).Eyedropper=e(t.Utils)})(this,function(n){function o(t,s,c,p){return new(c=c||Promise)(function(o,e){function n(t){try{i(p.next(t))}catch(t){e(t)}}function r(t){try{i(p.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?o(t.value):((e=t.value)instanceof c?e:new c(function(t){t(e)})).then(n,r)}i((p=p.apply(t,s||[])).next())})}function r(n,r){var i,s,c,p={label:0,sent:function(){if(1&c[0])throw c[1];return c[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=t(0),l.throw=t(1),l.return=t(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function t(o){return function(t){var e=[o,t];if(i)throw new TypeError("Generator is already executing.");for(;p=l&&e[l=0]?0:p;)try{if(i=1,s&&(c=2&e[0]?s.return:e[0]?s.throw||((c=s.return)&&c.call(s),0):s.next)&&!(c=c.call(s,e[1])).done)return c;switch(s=0,(e=c?[2&e[0],c.value]:e)[0]){case 0:case 1:c=e;break;case 4:return p.label++,{value:e[1],done:!1};case 5:p.label++,s=e[1],e=[0];continue;case 7:e=p.ops.pop(),p.trys.pop();continue;default:if(!(c=0<(c=p.trys).length&&c[c.length-1])&&(6===e[0]||2===e[0])){p=0;continue}if(3===e[0]&&(!c||e[1]>c[0]&&e[1]<c[3]))p.label=e[1];else if(6===e[0]&&p.label<c[1])p.label=c[1],c=e;else{if(!(c&&p.label<c[2])){c[2]&&p.ops.pop(),p.trys.pop();continue}p.label=c[2],p.ops.push(e)}}e=r.call(n,p)}catch(t){e=[6,t],s=0}finally{i=c=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}function t(t){var e=this;this.ewColorPicker=t,this.options={},this.container=null,this.button=null,this.destroyed=!1,this.handleClick=function(){return o(e,void 0,void 0,function(){var e,o;return r(this,function(t){switch(t.label){case 0:if(this.destroyed)return[2];if(!(e=window.EyeDropper))return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,(new e).open()];case 2:return(o=t.sent(),!this.destroyed&&o&&o.sRGBHex)?(this.ewColorPicker.setColor(o.sRGBHex),n.isFunction(this.options.onEyedropperPick)&&this.options.onEyedropperPick(o.sRGBHex),[3,4]):[2];case 3:return(o=t.sent())instanceof Error&&"AbortError"===o.name?[2]:(n.warn("[ewColorPicker warning]: Failed to pick color with EyeDropper",o),[3,4]);case 4:return[2]}})})},this.ewColorPicker=t,this.handleOptions(),this.run()}return Object.defineProperty(t.prototype,"prefix",{get:function(){return n.getPrefix(this.ewColorPicker)},enumerable:!1,configurable:!0}),t.prototype.isSupported=function(){return"undefined"!=typeof window&&"EyeDropper"in window},t.prototype.handleOptions=function(){this.options=n.extend({},this.options,this.ewColorPicker.options)},t.prototype.updateOptions=function(){this.handleOptions(),this.run()},t.prototype.run=function(){!1!==this.options.showEyedropper&&this.isSupported()?(this.removeContainer(),this.render(),this.bindEvents()):this.removeContainer()},t.prototype.render=function(){var t,e=this.ewColorPicker.getMountPoint("panelContainer");
|
|
1
|
+
((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["@ew-color-picker/utils"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).Eyedropper=e(t.Utils)})(this,function(n){function o(t,s,c,p){return new(c=c||Promise)(function(o,e){function n(t){try{i(p.next(t))}catch(t){e(t)}}function r(t){try{i(p.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?o(t.value):((e=t.value)instanceof c?e:new c(function(t){t(e)})).then(n,r)}i((p=p.apply(t,s||[])).next())})}function r(n,r){var i,s,c,p={label:0,sent:function(){if(1&c[0])throw c[1];return c[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=t(0),l.throw=t(1),l.return=t(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function t(o){return function(t){var e=[o,t];if(i)throw new TypeError("Generator is already executing.");for(;p=l&&e[l=0]?0:p;)try{if(i=1,s&&(c=2&e[0]?s.return:e[0]?s.throw||((c=s.return)&&c.call(s),0):s.next)&&!(c=c.call(s,e[1])).done)return c;switch(s=0,(e=c?[2&e[0],c.value]:e)[0]){case 0:case 1:c=e;break;case 4:return p.label++,{value:e[1],done:!1};case 5:p.label++,s=e[1],e=[0];continue;case 7:e=p.ops.pop(),p.trys.pop();continue;default:if(!(c=0<(c=p.trys).length&&c[c.length-1])&&(6===e[0]||2===e[0])){p=0;continue}if(3===e[0]&&(!c||e[1]>c[0]&&e[1]<c[3]))p.label=e[1];else if(6===e[0]&&p.label<c[1])p.label=c[1],c=e;else{if(!(c&&p.label<c[2])){c[2]&&p.ops.pop(),p.trys.pop();continue}p.label=c[2],p.ops.push(e)}}e=r.call(n,p)}catch(t){e=[6,t],s=0}finally{i=c=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}function t(t){var e=this;this.ewColorPicker=t,this.options={},this.container=null,this.button=null,this.destroyed=!1,this.handleClick=function(){return o(e,void 0,void 0,function(){var e,o;return r(this,function(t){switch(t.label){case 0:if(this.destroyed)return[2];if(!(e=window.EyeDropper))return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,(new e).open()];case 2:return(o=t.sent(),!this.destroyed&&o&&o.sRGBHex)?(this.ewColorPicker.setColor(o.sRGBHex),n.isFunction(this.options.onEyedropperPick)&&this.options.onEyedropperPick(o.sRGBHex),[3,4]):[2];case 3:return(o=t.sent())instanceof Error&&"AbortError"===o.name?[2]:(n.warn("[ewColorPicker warning]: Failed to pick color with EyeDropper",o),[3,4]);case 4:return[2]}})})},this.ewColorPicker=t,this.handleOptions(),this.run()}return Object.defineProperty(t.prototype,"prefix",{get:function(){return n.getPrefix(this.ewColorPicker)},enumerable:!1,configurable:!0}),t.prototype.isSupported=function(){return"undefined"!=typeof window&&"EyeDropper"in window},t.prototype.handleOptions=function(){this.options=n.extend({},this.options,this.ewColorPicker.options)},t.prototype.updateOptions=function(){this.handleOptions(),this.run()},t.prototype.run=function(){!1!==this.options.showEyedropper&&this.isSupported()?(this.removeContainer(),this.render(),this.bindEvents()):this.removeContainer()},t.prototype.render=function(){var t,e,o=this.ewColorPicker.getMountPoint("panelContainer");o?(o=this.getExtraRow(o),this.container=n.create("div"),n.addClass(this.container,"".concat(this.prefix,"color-picker-eyedropper-group")),e=(t=this.options.eyedropperText)?"string"==typeof t?t:t.textContent||"取色":"取色",this.button=n.create("button"),n.addClass(this.button,"".concat(this.prefix,"color-picker-eyedropper-btn")),n.setAttr(this.button,{type:"button",title:e,"aria-label":e}),this.button.innerHTML=n.eyedropperIcon(void 0,16,this.prefix),t&&(e=n.create("span"),n.addClass(e,"".concat(this.prefix,"color-picker-eyedropper-text")),n.setContent(e,t,{html:this.options.eyedropperTextHtml}),n.insertNode(this.button,e)),n.insertNode(this.container,this.button),n.insertNode(o,this.container)):n.warn("[ewColorPicker warning]: Panel container not found")},t.prototype.getExtraRow=function(t){var e,o=n.$(".".concat(this.prefix,"color-picker-extra-row"),t);return o||(o=n.create("div"),n.addClass(o,"".concat(this.prefix,"color-picker-extra-row")),(e=n.$(".".concat(this.prefix,"color-picker-bottom-row"),t))?n.insertNode(t,o,null,e):n.insertNode(t,o),o)},t.prototype.bindEvents=function(){this.button&&n.on(this.button,"click",this.handleClick)},t.prototype.removeContainer=function(){this.button&&n.off(this.button,"click",this.handleClick),this.container&&n.removeElement(this.container),this.button=null;var t,e=(this.container=null)==(e=null==(t=this.ewColorPicker)?void 0:t.getMountPoint)?void 0:e.call(t,"panelContainer");e&&(t=n.$(".".concat(this.prefix,"color-picker-extra-row"),e))&&0===t.children.length&&n.removeElement(t)},t.prototype.destroy=function(){this.destroyed=!0,this.removeContainer()},t.prototype.install=function(t){this.ewColorPicker=t,this.destroyed=!1,this.handleOptions(),null!=(t=this.run)&&t.call(this)},t.pluginName="ewColorPickerEyedropper",t.applyOrder=n.ApplyOrder.Post,t});
|
|
@@ -2,7 +2,8 @@ import ewColorPicker, { ewColorPickerOptions } from "@ew-color-picker/core";
|
|
|
2
2
|
import { ApplyOrder } from "@ew-color-picker/utils";
|
|
3
3
|
export interface EyedropperOptions {
|
|
4
4
|
showEyedropper?: boolean;
|
|
5
|
-
eyedropperText?: string;
|
|
5
|
+
eyedropperText?: string | HTMLElement;
|
|
6
|
+
eyedropperTextHtml?: boolean;
|
|
6
7
|
onEyedropperPick?: (color: string) => void;
|
|
7
8
|
}
|
|
8
9
|
export default class ewColorPickerEyedropperPlugin {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ew-color-picker/eyedropper",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "EW Color Picker Eyedropper Plugin",
|
|
5
5
|
"main": "dist/eyedropper.min.js",
|
|
6
6
|
"module": "dist/eyedropper.esm.js",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"author": "eveningwater(854806732@qq.com)",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ew-color-picker/core": "^2.0.
|
|
31
|
-
"@ew-color-picker/utils": "^2.0.
|
|
30
|
+
"@ew-color-picker/core": "^2.0.15",
|
|
31
|
+
"@ew-color-picker/utils": "^2.0.15"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"rollup": "^3.0.0",
|
|
35
35
|
"rollup-plugin-typescript2": "^0.34.0",
|
|
36
36
|
"typescript": "^4.9.0",
|
|
37
37
|
"rimraf": "^3.0.2",
|
|
38
|
-
"@ew-color-picker/
|
|
39
|
-
"@ew-color-picker/
|
|
38
|
+
"@ew-color-picker/utils": "2.0.15",
|
|
39
|
+
"@ew-color-picker/core": "2.0.15"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|