v-auto-color 1.0.4 → 1.0.5

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,142 @@
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/core/hash.ts
6
+ function murmurHash3(text) {
7
+ let h1 = 3735928559;
8
+ const c1 = 3432918353;
9
+ const c2 = 461845907;
10
+ const r1 = 15;
11
+ const r2 = 13;
12
+ const m = 5;
13
+ const n = 3864292196;
14
+ let i = 0;
15
+ const length = text.length;
16
+ let k1 = 0;
17
+ while (i < length) {
18
+ const char = text.charCodeAt(i++);
19
+ k1 = k1 << 8 | char;
20
+ }
21
+ k1 = k1 * c1 >>> 0;
22
+ k1 = (k1 << r1 | k1 >>> 32 - r1) >>> 0;
23
+ k1 = k1 * c2 >>> 0;
24
+ h1 ^= k1;
25
+ h1 = (h1 << r2 | h1 >>> 32 - r2) >>> 0;
26
+ h1 = h1 * m + n >>> 0;
27
+ h1 ^= length;
28
+ h1 ^= h1 >>> 16;
29
+ h1 = h1 * 2246822507 >>> 0;
30
+ h1 ^= h1 >>> 13;
31
+ h1 = h1 * 3266489909 >>> 0;
32
+ h1 ^= h1 >>> 16;
33
+ return h1;
34
+ }
35
+ function getTextHash(text) {
36
+ return murmurHash3(text);
37
+ }
38
+
39
+ // src/core/color.ts
40
+ var ColorGenerator = class {
41
+ constructor(config = {}) {
42
+ __publicField(this, "config");
43
+ this.config = {
44
+ category: config.category || "default",
45
+ hue: config.hue || [0, 360],
46
+ saturation: config.saturation || [70, 100],
47
+ lightness: config.lightness || [40, 60]
48
+ };
49
+ }
50
+ // Generate color from hash value
51
+ generateColor(hash) {
52
+ const { hue, saturation, lightness } = this.config;
53
+ const hueRange = hue[1] - hue[0];
54
+ const calculatedHue = hue[0] + hash % hueRange;
55
+ const satRange = saturation[1] - saturation[0];
56
+ const calculatedSat = saturation[0] + (hash >> 8) % satRange;
57
+ const lightRange = lightness[1] - lightness[0];
58
+ const calculatedLight = lightness[0] + (hash >> 16) % lightRange;
59
+ return `hsl(${calculatedHue}, ${calculatedSat}%, ${calculatedLight}%)`;
60
+ }
61
+ // Get color for text (wrapper method)
62
+ getColor(text, hashFn) {
63
+ const hash = hashFn(text);
64
+ return this.generateColor(hash);
65
+ }
66
+ };
67
+
68
+ // src/vite-plugin.ts
69
+ function createFilter(include, exclude) {
70
+ return function(id) {
71
+ const included = include.some((pattern) => {
72
+ if (pattern === "**/*") return true;
73
+ const regex = new RegExp(pattern.replace(/\*/g, ".*"));
74
+ return regex.test(id);
75
+ });
76
+ const excluded = exclude && exclude.some((pattern) => {
77
+ const regex = new RegExp(pattern.replace(/\*/g, ".*"));
78
+ return regex.test(id);
79
+ });
80
+ return included && !excluded;
81
+ };
82
+ }
83
+ function viteAutoColorPlugin() {
84
+ const filter = createFilter(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
85
+ return {
86
+ name: "v-auto-color",
87
+ // Analyze code during build and inject precomputed colors
88
+ transform(code, id) {
89
+ if (!filter(id)) return null;
90
+ if (!code.includes("useAutoColor")) return null;
91
+ const useAutoColorRegex = /useAutoColor\s*\(\s*(?:(['"])([^'"]+)\1|\{[^}]*\})\s*\)/g;
92
+ const getColorRegex = /\.getColor\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
93
+ let match;
94
+ const colorSets = /* @__PURE__ */ new Set();
95
+ while ((match = useAutoColorRegex.exec(code)) !== null) {
96
+ let category = "default";
97
+ if (match[2]) {
98
+ category = match[2];
99
+ } else {
100
+ const configMatch = match[0].match(/category\s*:\s*['"]([^'"]+)['"]/);
101
+ if (configMatch) {
102
+ category = configMatch[1];
103
+ }
104
+ }
105
+ colorSets.add(category);
106
+ }
107
+ const texts = /* @__PURE__ */ new Set();
108
+ while ((match = getColorRegex.exec(code)) !== null) {
109
+ texts.add(match[1]);
110
+ }
111
+ const colorUsage = {};
112
+ colorSets.forEach((category) => {
113
+ if (!colorUsage[category]) {
114
+ colorUsage[category] = {};
115
+ }
116
+ texts.forEach((text) => {
117
+ const generator = new ColorGenerator({ category });
118
+ const color = generator.getColor(text, getTextHash);
119
+ colorUsage[category][text] = color;
120
+ });
121
+ });
122
+ if (Object.keys(colorUsage).length > 0) {
123
+ const precomputedCode = `
124
+ // Precomputed colors for v-auto-color
125
+ import { __internal__setPrecomputedColors } from 'v-auto-color';
126
+ __internal__setPrecomputedColors(${JSON.stringify(colorUsage, null, 2)});
127
+ `;
128
+ code = precomputedCode + "\n" + code;
129
+ }
130
+ return code;
131
+ }
132
+ };
133
+ }
134
+ var vite_plugin_default = viteAutoColorPlugin;
135
+
136
+ export {
137
+ __publicField,
138
+ getTextHash,
139
+ ColorGenerator,
140
+ viteAutoColorPlugin,
141
+ vite_plugin_default
142
+ };
package/dist/index.js CHANGED
@@ -93,9 +93,22 @@ var ColorGenerator = class {
93
93
  };
94
94
 
95
95
  // src/vite-plugin.ts
96
- var import_pluginutils = require("@rollup/pluginutils");
96
+ function createFilter(include, exclude) {
97
+ return function(id) {
98
+ const included = include.some((pattern) => {
99
+ if (pattern === "**/*") return true;
100
+ const regex = new RegExp(pattern.replace(/\*/g, ".*"));
101
+ return regex.test(id);
102
+ });
103
+ const excluded = exclude && exclude.some((pattern) => {
104
+ const regex = new RegExp(pattern.replace(/\*/g, ".*"));
105
+ return regex.test(id);
106
+ });
107
+ return included && !excluded;
108
+ };
109
+ }
97
110
  function viteAutoColorPlugin() {
98
- const filter = (0, import_pluginutils.createFilter)(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
111
+ const filter = createFilter(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
99
112
  return {
100
113
  name: "v-auto-color",
101
114
  // Analyze code during build and inject precomputed colors
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  __publicField,
4
4
  getTextHash,
5
5
  viteAutoColorPlugin
6
- } from "./chunk-465SVM6G.mjs";
6
+ } from "./chunk-6X3GUPCU.mjs";
7
7
 
8
8
  // src/index.ts
9
9
  var precomputedColors = {};
@@ -26,7 +26,6 @@ __export(vite_plugin_exports, {
26
26
  viteAutoColorPlugin: () => viteAutoColorPlugin
27
27
  });
28
28
  module.exports = __toCommonJS(vite_plugin_exports);
29
- var import_pluginutils = require("@rollup/pluginutils");
30
29
 
31
30
  // src/core/hash.ts
32
31
  function murmurHash3(text) {
@@ -92,8 +91,22 @@ var ColorGenerator = class {
92
91
  };
93
92
 
94
93
  // src/vite-plugin.ts
94
+ function createFilter(include, exclude) {
95
+ return function(id) {
96
+ const included = include.some((pattern) => {
97
+ if (pattern === "**/*") return true;
98
+ const regex = new RegExp(pattern.replace(/\*/g, ".*"));
99
+ return regex.test(id);
100
+ });
101
+ const excluded = exclude && exclude.some((pattern) => {
102
+ const regex = new RegExp(pattern.replace(/\*/g, ".*"));
103
+ return regex.test(id);
104
+ });
105
+ return included && !excluded;
106
+ };
107
+ }
95
108
  function viteAutoColorPlugin() {
96
- const filter = (0, import_pluginutils.createFilter)(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
109
+ const filter = createFilter(["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.vue"]);
97
110
  return {
98
111
  name: "v-auto-color",
99
112
  // Analyze code during build and inject precomputed colors
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  viteAutoColorPlugin,
3
3
  vite_plugin_default
4
- } from "./chunk-465SVM6G.mjs";
4
+ } from "./chunk-6X3GUPCU.mjs";
5
5
  export {
6
6
  vite_plugin_default as default,
7
7
  viteAutoColorPlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v-auto-color",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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",
@@ -32,7 +32,6 @@
32
32
  "vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
33
33
  },
34
34
  "dependencies": {
35
- "@rollup/pluginutils": "^5.0.2"
36
35
  },
37
36
  "devDependencies": {
38
37
  "@types/node": "^18.19.3",
@@ -1,8 +1,27 @@
1
1
  import { Plugin } from 'vite';
2
- import { createFilter } from '@rollup/pluginutils';
3
2
  import { getTextHash } from './core/hash';
4
3
  import { ColorGenerator } from './core/color';
5
4
 
5
+ // Simple file filter implementation (replaces @rollup/pluginutils createFilter)
6
+ function createFilter(include: string[], exclude?: string[]) {
7
+ return function(id: string) {
8
+ // Check if id matches any include pattern
9
+ const included = include.some(pattern => {
10
+ if (pattern === '**/*') return true;
11
+ const regex = new RegExp(pattern.replace(/\*/g, '.*'));
12
+ return regex.test(id);
13
+ });
14
+
15
+ // Check if id matches any exclude pattern
16
+ const excluded = exclude && exclude.some(pattern => {
17
+ const regex = new RegExp(pattern.replace(/\*/g, '.*'));
18
+ return regex.test(id);
19
+ });
20
+
21
+ return included && !excluded;
22
+ };
23
+ }
24
+
6
25
  // Vite plugin for precomputing colors at build time
7
26
  export function viteAutoColorPlugin(): Plugin {
8
27
  const filter = createFilter(['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx', '**/*.vue']);