v-auto-color 1.0.0 → 1.0.2
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-VOGH5JNO.mjs +139 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +66 -2
- package/dist/index.mjs +5 -3
- package/dist/vite-plugin.mjs +3 -66
- package/package.json +2 -2
- package/src/index.ts +4 -0
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
this.emitFile({
|
|
124
|
+
type: "asset",
|
|
125
|
+
fileName: "v-auto-color-initializer.js",
|
|
126
|
+
source: `import "/v-auto-color-precomputed.js";`
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
var vite_plugin_default = viteAutoColorPlugin;
|
|
132
|
+
|
|
133
|
+
export {
|
|
134
|
+
__publicField,
|
|
135
|
+
getTextHash,
|
|
136
|
+
ColorGenerator,
|
|
137
|
+
viteAutoColorPlugin,
|
|
138
|
+
vite_plugin_default
|
|
139
|
+
};
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,7 +24,8 @@ var index_exports = {};
|
|
|
24
24
|
__export(index_exports, {
|
|
25
25
|
ColorSet: () => ColorSet,
|
|
26
26
|
__internal__setPrecomputedColors: () => __internal__setPrecomputedColors,
|
|
27
|
-
useAutoColor: () => useAutoColor
|
|
27
|
+
useAutoColor: () => useAutoColor,
|
|
28
|
+
viteAutoColorPlugin: () => viteAutoColorPlugin
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(index_exports);
|
|
30
31
|
|
|
@@ -91,6 +92,68 @@ var ColorGenerator = class {
|
|
|
91
92
|
}
|
|
92
93
|
};
|
|
93
94
|
|
|
95
|
+
// src/vite-plugin.ts
|
|
96
|
+
var import_pluginutils = require("@rollup/pluginutils");
|
|
97
|
+
function viteAutoColorPlugin() {
|
|
98
|
+
const filter = (0, import_pluginutils.createFilter)(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
|
|
99
|
+
const colorUsage = {};
|
|
100
|
+
return {
|
|
101
|
+
name: "v-auto-color",
|
|
102
|
+
// Analyze code during build
|
|
103
|
+
transform(code, id) {
|
|
104
|
+
if (!filter(id)) return null;
|
|
105
|
+
const useAutoColorRegex = /useAutoColor\s*\(\s*(?:(['"])([^'"]+)\1|\{[^}]*\})\s*\)/g;
|
|
106
|
+
const getColorRegex = /\.getColor\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
107
|
+
let match;
|
|
108
|
+
const colorSets = /* @__PURE__ */ new Set();
|
|
109
|
+
while ((match = useAutoColorRegex.exec(code)) !== null) {
|
|
110
|
+
let category = "default";
|
|
111
|
+
if (match[2]) {
|
|
112
|
+
category = match[2];
|
|
113
|
+
} else {
|
|
114
|
+
const configMatch = match[0].match(/category\s*:\s*['"]([^'"]+)['"]/);
|
|
115
|
+
if (configMatch) {
|
|
116
|
+
category = configMatch[1];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
colorSets.add(category);
|
|
120
|
+
}
|
|
121
|
+
const texts = /* @__PURE__ */ new Set();
|
|
122
|
+
while ((match = getColorRegex.exec(code)) !== null) {
|
|
123
|
+
texts.add(match[1]);
|
|
124
|
+
}
|
|
125
|
+
colorSets.forEach((category) => {
|
|
126
|
+
if (!colorUsage[category]) {
|
|
127
|
+
colorUsage[category] = {};
|
|
128
|
+
}
|
|
129
|
+
texts.forEach((text) => {
|
|
130
|
+
const generator = new ColorGenerator({ category });
|
|
131
|
+
const color = generator.getColor(text, getTextHash);
|
|
132
|
+
colorUsage[category][text] = color;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
return null;
|
|
136
|
+
},
|
|
137
|
+
// Generate precomputed colors module
|
|
138
|
+
generateBundle() {
|
|
139
|
+
const precomputedCode = `
|
|
140
|
+
import { __internal__setPrecomputedColors } from 'v-auto-color';
|
|
141
|
+
__internal__setPrecomputedColors(${JSON.stringify(colorUsage, null, 2)});
|
|
142
|
+
`;
|
|
143
|
+
this.emitFile({
|
|
144
|
+
type: "asset",
|
|
145
|
+
fileName: "v-auto-color-precomputed.js",
|
|
146
|
+
source: precomputedCode
|
|
147
|
+
});
|
|
148
|
+
this.emitFile({
|
|
149
|
+
type: "asset",
|
|
150
|
+
fileName: "v-auto-color-initializer.js",
|
|
151
|
+
source: `import "/v-auto-color-precomputed.js";`
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
94
157
|
// src/index.ts
|
|
95
158
|
var precomputedColors = {};
|
|
96
159
|
var ColorSet = class {
|
|
@@ -129,5 +192,6 @@ function __internal__setPrecomputedColors(colors) {
|
|
|
129
192
|
0 && (module.exports = {
|
|
130
193
|
ColorSet,
|
|
131
194
|
__internal__setPrecomputedColors,
|
|
132
|
-
useAutoColor
|
|
195
|
+
useAutoColor,
|
|
196
|
+
viteAutoColorPlugin
|
|
133
197
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ColorGenerator,
|
|
3
3
|
__publicField,
|
|
4
|
-
getTextHash
|
|
5
|
-
|
|
4
|
+
getTextHash,
|
|
5
|
+
viteAutoColorPlugin
|
|
6
|
+
} from "./chunk-VOGH5JNO.mjs";
|
|
6
7
|
|
|
7
8
|
// src/index.ts
|
|
8
9
|
var precomputedColors = {};
|
|
@@ -41,5 +42,6 @@ function __internal__setPrecomputedColors(colors) {
|
|
|
41
42
|
export {
|
|
42
43
|
ColorSet,
|
|
43
44
|
__internal__setPrecomputedColors,
|
|
44
|
-
useAutoColor
|
|
45
|
+
useAutoColor,
|
|
46
|
+
viteAutoColorPlugin
|
|
45
47
|
};
|
package/dist/vite-plugin.mjs
CHANGED
|
@@ -1,70 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
|
|
6
|
-
// src/vite-plugin.ts
|
|
7
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
8
|
-
function viteAutoColorPlugin() {
|
|
9
|
-
const filter = createFilter(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
|
|
10
|
-
const colorUsage = {};
|
|
11
|
-
return {
|
|
12
|
-
name: "v-auto-color",
|
|
13
|
-
// Analyze code during build
|
|
14
|
-
transform(code, id) {
|
|
15
|
-
if (!filter(id)) return null;
|
|
16
|
-
const useAutoColorRegex = /useAutoColor\s*\(\s*(?:(['"])([^'"]+)\1|\{[^}]*\})\s*\)/g;
|
|
17
|
-
const getColorRegex = /\.getColor\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
18
|
-
let match;
|
|
19
|
-
const colorSets = /* @__PURE__ */ new Set();
|
|
20
|
-
while ((match = useAutoColorRegex.exec(code)) !== null) {
|
|
21
|
-
let category = "default";
|
|
22
|
-
if (match[2]) {
|
|
23
|
-
category = match[2];
|
|
24
|
-
} else {
|
|
25
|
-
const configMatch = match[0].match(/category\s*:\s*['"]([^'"]+)['"]/);
|
|
26
|
-
if (configMatch) {
|
|
27
|
-
category = configMatch[1];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
colorSets.add(category);
|
|
31
|
-
}
|
|
32
|
-
const texts = /* @__PURE__ */ new Set();
|
|
33
|
-
while ((match = getColorRegex.exec(code)) !== null) {
|
|
34
|
-
texts.add(match[1]);
|
|
35
|
-
}
|
|
36
|
-
colorSets.forEach((category) => {
|
|
37
|
-
if (!colorUsage[category]) {
|
|
38
|
-
colorUsage[category] = {};
|
|
39
|
-
}
|
|
40
|
-
texts.forEach((text) => {
|
|
41
|
-
const generator = new ColorGenerator({ category });
|
|
42
|
-
const color = generator.getColor(text, getTextHash);
|
|
43
|
-
colorUsage[category][text] = color;
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
return null;
|
|
47
|
-
},
|
|
48
|
-
// Generate precomputed colors module
|
|
49
|
-
generateBundle() {
|
|
50
|
-
const precomputedCode = `
|
|
51
|
-
import { __internal__setPrecomputedColors } from 'v-auto-color';
|
|
52
|
-
__internal__setPrecomputedColors(${JSON.stringify(colorUsage, null, 2)});
|
|
53
|
-
`;
|
|
54
|
-
this.emitFile({
|
|
55
|
-
type: "asset",
|
|
56
|
-
fileName: "v-auto-color-precomputed.js",
|
|
57
|
-
source: precomputedCode
|
|
58
|
-
});
|
|
59
|
-
this.emitFile({
|
|
60
|
-
type: "asset",
|
|
61
|
-
fileName: "v-auto-color-initializer.js",
|
|
62
|
-
source: `import "/v-auto-color-precomputed.js";`
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
var vite_plugin_default = viteAutoColorPlugin;
|
|
2
|
+
viteAutoColorPlugin,
|
|
3
|
+
vite_plugin_default
|
|
4
|
+
} from "./chunk-VOGH5JNO.mjs";
|
|
68
5
|
export {
|
|
69
6
|
vite_plugin_default as default,
|
|
70
7
|
viteAutoColorPlugin
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "v-auto-color",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Vite plugin for automatic color generation based on text similarity",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"author": "",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"vite": "^4.0.0 || ^5.0.0"
|
|
32
|
+
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@rollup/pluginutils": "^5.0.2"
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getTextHash } from './core/hash';
|
|
2
2
|
import { ColorConfig, ColorGenerator } from './core/color';
|
|
3
|
+
import { viteAutoColorPlugin } from './vite-plugin';
|
|
3
4
|
|
|
4
5
|
// Precomputed colors cache (filled by Vite plugin at build time)
|
|
5
6
|
const precomputedColors: Record<string, Record<string, string>> = {};
|
|
@@ -53,3 +54,6 @@ export function __internal__setPrecomputedColors(colors: Record<string, Record<s
|
|
|
53
54
|
|
|
54
55
|
// Export types
|
|
55
56
|
export type { ColorConfig };
|
|
57
|
+
|
|
58
|
+
// Export Vite plugin
|
|
59
|
+
export { viteAutoColorPlugin };
|