diff --git a/src/components.d.ts b/src/components.d.ts
index f865f0fe..dc11a85d 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -109,6 +109,7 @@ import {
Delete,
Square,
Round,
+ Needle,
} from '@icon-park/vue-next'
declare module 'vue' {
@@ -252,6 +253,7 @@ declare module 'vue' {
IconDelete: typeof Delete
IconSquare: typeof Square
IconRound: typeof Round
+ IconNeedle: typeof Needle
}
}
diff --git a/src/components/ColorPicker/index.vue b/src/components/ColorPicker/index.vue
index dd59ba3c..cb650be9 100644
--- a/src/components/ColorPicker/index.vue
+++ b/src/components/ColorPicker/index.vue
@@ -20,7 +20,7 @@
changeColor(value)" />
-
+
@@ -203,7 +203,34 @@ const changeColor = (value: ColorFormats.RGBA | ColorFormats.HSLA | ColorFormats
updateRecentColorsCache()
}
-const pickColor = () => {
+// 打开取色吸管
+// 检查环境是否支持原生取色吸管,支持则使用原生吸管,否则使用自定义吸管
+const openEyeDropper = () => {
+ const isSupportedEyeDropper = 'EyeDropper' in window
+
+ if (isSupportedEyeDropper) browserEyeDropper()
+ else customEyeDropper()
+}
+
+// 原生取色吸管
+const browserEyeDropper = () => {
+ message.success('按 ESC 键关闭取色吸管')
+
+ // eslint-disable-next-line
+ const eyeDropper = new (window as any).EyeDropper()
+ eyeDropper.open().then((result: { sRGBHex: string }) => {
+ const tColor = tinycolor(result.sRGBHex)
+ hue.value = tColor.toHsl().h
+ color.value = tColor.toRgb()
+
+ updateRecentColorsCache()
+ }).catch(() => {
+ message.success('关闭取色吸管')
+ })
+}
+
+// 基于 Canvas 的自定义取色吸管
+const customEyeDropper = () => {
const targetRef: HTMLElement | null = document.querySelector('.canvas')
if (!targetRef) return
diff --git a/src/plugins/icon.ts b/src/plugins/icon.ts
index 75460fa8..f0468963 100644
--- a/src/plugins/icon.ts
+++ b/src/plugins/icon.ts
@@ -106,6 +106,7 @@ import {
Delete,
Square,
Round,
+ Needle,
} from '@icon-park/vue-next'
const icons = {
@@ -213,6 +214,7 @@ const icons = {
Delete,
Square,
Round,
+ Needle,
}
export default {