|
@@ -9,6 +9,8 @@ import { getMouseColors } from "@/utils/colors.ts";
|
|
|
import { FixScreen } from "@/utils/bound.ts";
|
|
|
import { InteractiveFix, InteractiveTo, MatResponseProps } from "../index.ts";
|
|
|
import { Size } from "@/utils/math.ts";
|
|
|
+import { getSvgContent, parseSvgContent } from "@/utils/resource.ts";
|
|
|
+import { Color } from "three";
|
|
|
|
|
|
export { default as Component } from "./icon.vue";
|
|
|
export { default as TempComponent } from "./temp-icon.vue";
|
|
@@ -22,6 +24,64 @@ export const defaultStyle = {
|
|
|
height: 80,
|
|
|
};
|
|
|
|
|
|
+ type ColorCounts = [string, number][]
|
|
|
+ const colorsManage = (counts: ColorCounts, color: any) => {
|
|
|
+ if (!color) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const colorHex = new Color(color).getHexString()
|
|
|
+ const item = counts.find(([c]) => c === colorHex)
|
|
|
+ if (!item) {
|
|
|
+ counts.push([colorHex, 1])
|
|
|
+ } else {
|
|
|
+ item[1]++
|
|
|
+ }
|
|
|
+}
|
|
|
+const findColor = (counts: ColorCounts) => {
|
|
|
+ let ndx = -1
|
|
|
+ let max = 0
|
|
|
+ for (let i = 0; i < counts.length; i++) {
|
|
|
+ if (counts[i][1] >= max) {
|
|
|
+ ndx = i
|
|
|
+ max = counts[i][1]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (~ndx) {
|
|
|
+ return `#${counts[ndx][0]}`
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const getIconStyle = async (url: string, width = defaultStyle.width, height = defaultStyle.height) => {
|
|
|
+ const svgContent = parseSvgContent(await getSvgContent(url));
|
|
|
+ if (width / height > svgContent.width / svgContent.height) {
|
|
|
+ width = svgContent.width / svgContent.height * height
|
|
|
+ } else {
|
|
|
+ height = svgContent.height / svgContent.width * width
|
|
|
+ }
|
|
|
+ const fillColorCounts: [string, number][] = []
|
|
|
+ const strokeColorCounts: [string, number][] = []
|
|
|
+
|
|
|
+ for (let i = 0; i < svgContent.paths.length; i++) {
|
|
|
+ colorsManage(fillColorCounts, svgContent.paths[i].fill)
|
|
|
+ colorsManage(strokeColorCounts, svgContent.paths[i].stroke)
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(fillColorCounts, strokeColorCounts)
|
|
|
+ const color = {
|
|
|
+ fill: findColor(fillColorCounts) || null,
|
|
|
+ stroke: findColor(strokeColorCounts) || null
|
|
|
+ };
|
|
|
+ if (!color.fill && !color.stroke) {
|
|
|
+ color.stroke = "#000000";
|
|
|
+ }
|
|
|
+ console.log(color, fillColorCounts)
|
|
|
+ return {
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ ...color
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export const addMode = "dot";
|
|
|
|
|
|
export const getSnapInfos = (data: IconData) => {
|