v-auto-color 1.0.2 → 1.0.3
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/chunk-NJGGDAAU.mjs +140 -0
- package/dist/index.js +6 -5
- package/dist/index.mjs +1 -1
- package/dist/vite-plugin.js +6 -5
- package/dist/vite-plugin.mjs +1 -1
- package/package.json +1 -1
- package/src/vite-plugin.ts +6 -6
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/vite-plugin.ts
|
|
6
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
7
|
+
|
|
8
|
+
// src/core/hash.ts
|
|
9
|
+
function murmurHash3(text) {
|
|
10
|
+
let h1 = 3735928559;
|
|
11
|
+
const c1 = 3432918353;
|
|
12
|
+
const c2 = 461845907;
|
|
13
|
+
const r1 = 15;
|
|
14
|
+
const r2 = 13;
|
|
15
|
+
const m = 5;
|
|
16
|
+
const n = 3864292196;
|
|
17
|
+
let i = 0;
|
|
18
|
+
const length = text.length;
|
|
19
|
+
let k1 = 0;
|
|
20
|
+
while (i < length) {
|
|
21
|
+
const char = text.charCodeAt(i++);
|
|
22
|
+
k1 = k1 << 8 | char;
|
|
23
|
+
}
|
|
24
|
+
k1 = k1 * c1 >>> 0;
|
|
25
|
+
k1 = (k1 << r1 | k1 >>> 32 - r1) >>> 0;
|
|
26
|
+
k1 = k1 * c2 >>> 0;
|
|
27
|
+
h1 ^= k1;
|
|
28
|
+
h1 = (h1 << r2 | h1 >>> 32 - r2) >>> 0;
|
|
29
|
+
h1 = h1 * m + n >>> 0;
|
|
30
|
+
h1 ^= length;
|
|
31
|
+
h1 ^= h1 >>> 16;
|
|
32
|
+
h1 = h1 * 2246822507 >>> 0;
|
|
33
|
+
h1 ^= h1 >>> 13;
|
|
34
|
+
h1 = h1 * 3266489909 >>> 0;
|
|
35
|
+
h1 ^= h1 >>> 16;
|
|
36
|
+
return h1;
|
|
37
|
+
}
|
|
38
|
+
function getTextHash(text) {
|
|
39
|
+
return murmurHash3(text);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/core/color.ts
|
|
43
|
+
var ColorGenerator = class {
|
|
44
|
+
constructor(config = {}) {
|
|
45
|
+
__publicField(this, "config");
|
|
46
|
+
this.config = {
|
|
47
|
+
category: config.category || "default",
|
|
48
|
+
hue: config.hue || [0, 360],
|
|
49
|
+
saturation: config.saturation || [70, 100],
|
|
50
|
+
lightness: config.lightness || [40, 60]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Generate color from hash value
|
|
54
|
+
generateColor(hash) {
|
|
55
|
+
const { hue, saturation, lightness } = this.config;
|
|
56
|
+
const hueRange = hue[1] - hue[0];
|
|
57
|
+
const calculatedHue = hue[0] + hash % hueRange;
|
|
58
|
+
const satRange = saturation[1] - saturation[0];
|
|
59
|
+
const calculatedSat = saturation[0] + (hash >> 8) % satRange;
|
|
60
|
+
const lightRange = lightness[1] - lightness[0];
|
|
61
|
+
const calculatedLight = lightness[0] + (hash >> 16) % lightRange;
|
|
62
|
+
return `hsl(${calculatedHue}, ${calculatedSat}%, ${calculatedLight}%)`;
|
|
63
|
+
}
|
|
64
|
+
// Get color for text (wrapper method)
|
|
65
|
+
getColor(text, hashFn) {
|
|
66
|
+
const hash = hashFn(text);
|
|
67
|
+
return this.generateColor(hash);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/vite-plugin.ts
|
|
72
|
+
function viteAutoColorPlugin() {
|
|
73
|
+
const filter = createFilter(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
|
|
74
|
+
const colorUsage = {};
|
|
75
|
+
return {
|
|
76
|
+
name: "v-auto-color",
|
|
77
|
+
// Analyze code during build
|
|
78
|
+
transform(code, id) {
|
|
79
|
+
if (!filter(id)) return null;
|
|
80
|
+
const useAutoColorRegex = /useAutoColor\s*\(\s*(?:(['"])([^'"]+)\1|\{[^}]*\})\s*\)/g;
|
|
81
|
+
const getColorRegex = /\.getColor\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
82
|
+
let match;
|
|
83
|
+
const colorSets = /* @__PURE__ */ new Set();
|
|
84
|
+
while ((match = useAutoColorRegex.exec(code)) !== null) {
|
|
85
|
+
let category = "default";
|
|
86
|
+
if (match[2]) {
|
|
87
|
+
category = match[2];
|
|
88
|
+
} else {
|
|
89
|
+
const configMatch = match[0].match(/category\s*:\s*['"]([^'"]+)['"]/);
|
|
90
|
+
if (configMatch) {
|
|
91
|
+
category = configMatch[1];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
colorSets.add(category);
|
|
95
|
+
}
|
|
96
|
+
const texts = /* @__PURE__ */ new Set();
|
|
97
|
+
while ((match = getColorRegex.exec(code)) !== null) {
|
|
98
|
+
texts.add(match[1]);
|
|
99
|
+
}
|
|
100
|
+
colorSets.forEach((category) => {
|
|
101
|
+
if (!colorUsage[category]) {
|
|
102
|
+
colorUsage[category] = {};
|
|
103
|
+
}
|
|
104
|
+
texts.forEach((text) => {
|
|
105
|
+
const generator = new ColorGenerator({ category });
|
|
106
|
+
const color = generator.getColor(text, getTextHash);
|
|
107
|
+
colorUsage[category][text] = color;
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return null;
|
|
111
|
+
},
|
|
112
|
+
// Generate precomputed colors module
|
|
113
|
+
generateBundle() {
|
|
114
|
+
const precomputedCode = `
|
|
115
|
+
import { __internal__setPrecomputedColors } from 'v-auto-color';
|
|
116
|
+
__internal__setPrecomputedColors(${JSON.stringify(colorUsage, null, 2)});
|
|
117
|
+
`;
|
|
118
|
+
this.emitFile({
|
|
119
|
+
type: "asset",
|
|
120
|
+
fileName: "v-auto-color-precomputed.js",
|
|
121
|
+
source: precomputedCode
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
// Inject precomputed colors into HTML
|
|
125
|
+
transformIndexHtml(html) {
|
|
126
|
+
return html.replace("</head>", `
|
|
127
|
+
<script type="module" src="/v-auto-color-precomputed.js"></script>
|
|
128
|
+
</head>`);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
var vite_plugin_default = viteAutoColorPlugin;
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
__publicField,
|
|
136
|
+
getTextHash,
|
|
137
|
+
ColorGenerator,
|
|
138
|
+
viteAutoColorPlugin,
|
|
139
|
+
vite_plugin_default
|
|
140
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -145,11 +145,12 @@ function viteAutoColorPlugin() {
|
|
|
145
145
|
fileName: "v-auto-color-precomputed.js",
|
|
146
146
|
source: precomputedCode
|
|
147
147
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
},
|
|
149
|
+
// Inject precomputed colors into HTML
|
|
150
|
+
transformIndexHtml(html) {
|
|
151
|
+
return html.replace("</head>", `
|
|
152
|
+
<script type="module" src="/v-auto-color-precomputed.js"></script>
|
|
153
|
+
</head>`);
|
|
153
154
|
}
|
|
154
155
|
};
|
|
155
156
|
}
|
package/dist/index.mjs
CHANGED
package/dist/vite-plugin.js
CHANGED
|
@@ -143,11 +143,12 @@ function viteAutoColorPlugin() {
|
|
|
143
143
|
fileName: "v-auto-color-precomputed.js",
|
|
144
144
|
source: precomputedCode
|
|
145
145
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
},
|
|
147
|
+
// Inject precomputed colors into HTML
|
|
148
|
+
transformIndexHtml(html) {
|
|
149
|
+
return html.replace("</head>", `
|
|
150
|
+
<script type="module" src="/v-auto-color-precomputed.js"></script>
|
|
151
|
+
</head>`);
|
|
151
152
|
}
|
|
152
153
|
};
|
|
153
154
|
}
|
package/dist/vite-plugin.mjs
CHANGED
package/package.json
CHANGED
package/src/vite-plugin.ts
CHANGED
|
@@ -76,13 +76,13 @@ export function viteAutoColorPlugin(): Plugin {
|
|
|
76
76
|
fileName: 'v-auto-color-precomputed.js',
|
|
77
77
|
source: precomputedCode
|
|
78
78
|
});
|
|
79
|
+
},
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
81
|
+
// Inject precomputed colors into HTML
|
|
82
|
+
transformIndexHtml(html) {
|
|
83
|
+
return html.replace('</head>', `
|
|
84
|
+
<script type="module" src="/v-auto-color-precomputed.js"></script>
|
|
85
|
+
</head>`);
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
}
|