You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
7.4 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, inject, ref, watch, watchEffect, openBlock, createElementBlock, normalizeClass, createElementVNode, Fragment, renderList, normalizeStyle } from 'vue';\nimport { colorPickerContextKey } from '../color-picker2.mjs';\nimport Color from '../utils/color.mjs';\nimport _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';\nimport { useNamespace } from '../../../../hooks/use-namespace/index.mjs';\nconst _sfc_main = defineComponent({\n props: {\n colors: {\n type: Array,\n required: true\n },\n color: {\n type: Object,\n required: true\n },\n enableAlpha: {\n type: Boolean,\n required: true\n }\n },\n setup(props) {\n const ns = useNamespace(\"color-predefine\");\n const {\n currentColor\n } = inject(colorPickerContextKey);\n const rgbaColors = ref(parseColors(props.colors, props.color));\n watch(() => currentColor.value, val => {\n const color = new Color();\n color.fromString(val);\n rgbaColors.value.forEach(item => {\n item.selected = color.compare(item);\n });\n });\n watchEffect(() => {\n rgbaColors.value = parseColors(props.colors, props.color);\n });\n function handleSelect(index) {\n props.color.fromString(props.colors[index]);\n }\n function parseColors(colors, color) {\n return colors.map(value => {\n const c = new Color();\n c.enableAlpha = props.enableAlpha;\n c.format = \"rgba\";\n c.fromString(value);\n c.selected = c.value === color.value;\n return c;\n });\n }\n return {\n rgbaColors,\n handleSelect,\n ns\n };\n }\n});\nfunction _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {\n return openBlock(), createElementBlock(\"div\", {\n class: normalizeClass(_ctx.ns.b())\n }, [createElementVNode(\"div\", {\n class: normalizeClass(_ctx.ns.e(\"colors\"))\n }, [(openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.rgbaColors, (item, index) => {\n return openBlock(), createElementBlock(\"div\", {\n key: _ctx.colors[index],\n class: normalizeClass([_ctx.ns.e(\"color-selector\"), _ctx.ns.is(\"alpha\", item._alpha < 100), {\n selected: item.selected\n }]),\n onClick: $event => _ctx.handleSelect(index)\n }, [createElementVNode(\"div\", {\n style: normalizeStyle({\n backgroundColor: item.value\n })\n }, null, 4)], 10, [\"onClick\"]);\n }), 128))], 2)], 2);\n}\nvar Predefine = /* @__PURE__ */_export_sfc(_sfc_main, [[\"render\", _sfc_render], [\"__file\", \"predefine.vue\"]]);\nexport { Predefine as default };","map":{"version":3,"names":["_sfc_main","defineComponent","props","colors","type","Array","required","color","Object","enableAlpha","Boolean","setup","ns","useNamespace","currentColor","inject","colorPickerContextKey","rgbaColors","ref","parseColors","watch","value","val","Color","fromString","forEach","item","selected","compare","watchEffect","handleSelect","index","map","c","format","_sfc_render","_ctx","_cache","$props","$setup","$data","$options","openBlock","createElementBlock","createElementVNode","class","normalizeClass","e","Fragment","renderList","is","_alpha","style","normalizeStyle","backgroundColor","Predefine","_export_sfc"],"sources":["../../../../../../../packages/components/color-picker/src/components/predefine.vue"],"sourcesContent":["<template>\n <div :class=\"ns.b()\">\n <div :class=\"ns.e('colors')\">\n <div\n v-for=\"(item, index) in rgbaColors\"\n :key=\"colors[index]\"\n :class=\"[\n ns.e('color-selector'),\n ns.is('alpha', item._alpha < 100),\n { selected: item.selected },\n ]\"\n @click=\"handleSelect(index)\"\n >\n <div :style=\"{ backgroundColor: item.value }\" />\n </div>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, inject, ref, watch, watchEffect } from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport {