v-auto-color 1.0.1 → 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.
@@ -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
+ };
@@ -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
@@ -1,3 +1,6 @@
1
+ export { default as viteAutoColorPlugin } from './vite-plugin.mjs';
2
+ import 'vite';
3
+
1
4
  interface ColorConfig {
2
5
  category?: string;
3
6
  hue?: [number, number];
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ export { default as viteAutoColorPlugin } from './vite-plugin.js';
2
+ import 'vite';
3
+
1
4
  interface ColorConfig {
2
5
  category?: string;
3
6
  hue?: [number, number];
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,69 @@ 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
+ },
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>`);
154
+ }
155
+ };
156
+ }
157
+
94
158
  // src/index.ts
95
159
  var precomputedColors = {};
96
160
  var ColorSet = class {
@@ -129,5 +193,6 @@ function __internal__setPrecomputedColors(colors) {
129
193
  0 && (module.exports = {
130
194
  ColorSet,
131
195
  __internal__setPrecomputedColors,
132
- useAutoColor
196
+ useAutoColor,
197
+ viteAutoColorPlugin
133
198
  });
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  ColorGenerator,
3
3
  __publicField,
4
- getTextHash
5
- } from "./chunk-GO6JHW6J.mjs";
4
+ getTextHash,
5
+ viteAutoColorPlugin
6
+ } from "./chunk-NJGGDAAU.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
  };
@@ -143,11 +143,12 @@ function viteAutoColorPlugin() {
143
143
  fileName: "v-auto-color-precomputed.js",
144
144
  source: precomputedCode
145
145
  });
146
- this.emitFile({
147
- type: "asset",
148
- fileName: "v-auto-color-initializer.js",
149
- source: `import "/v-auto-color-precomputed.js";`
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
  }
@@ -1,70 +1,7 @@
1
1
  import {
2
- ColorGenerator,
3
- getTextHash
4
- } from "./chunk-GO6JHW6J.mjs";
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-NJGGDAAU.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.1",
3
+ "version": "1.0.3",
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",
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 };
@@ -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
- // Ensure the precomputed module is loaded before application code
81
- this.emitFile({
82
- type: 'asset',
83
- fileName: 'v-auto-color-initializer.js',
84
- source: `import "/v-auto-color-precomputed.js";`
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
  }