@gomeniucivan/ui 1.0.52 → 1.0.53
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/index.d.mts +375 -4
- package/dist/index.d.ts +375 -4
- package/dist/index.js +400 -385
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +398 -383
- package/dist/index.mjs.map +1 -1
- package/loader.js +167 -0
- package/next-plugin.js +53 -0
- package/package.json +12 -5
package/loader.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gomeniucivan/ui webpack loader
|
|
3
|
+
*
|
|
4
|
+
* Automatically injects `{ path: '<relative-file-path>' }` into every
|
|
5
|
+
* `createStaticStyles()` and `createStyles()` call at build time.
|
|
6
|
+
*
|
|
7
|
+
* This enables the DebugObserver (when `isDebug` is enabled on ThemeProvider)
|
|
8
|
+
* to annotate `<style>` and DOM elements with `data-insp-path`, showing
|
|
9
|
+
* exactly which source file defined each CSS class.
|
|
10
|
+
*
|
|
11
|
+
* Usage in next.config.ts / webpack.config.js:
|
|
12
|
+
*
|
|
13
|
+
* config.module.rules.push({
|
|
14
|
+
* test: /\.tsx?$/,
|
|
15
|
+
* enforce: 'pre',
|
|
16
|
+
* exclude: /node_modules/,
|
|
17
|
+
* use: [require.resolve('@gomeniucivan/ui/loader')],
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* The loader computes paths relative to the repository root (two levels up
|
|
21
|
+
* from node_modules/@gomeniucivan/ui/). Override with the `rootDir` option:
|
|
22
|
+
*
|
|
23
|
+
* use: [{ loader: require.resolve('@gomeniucivan/ui/loader'), options: { rootDir: __dirname } }],
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
'use strict';
|
|
27
|
+
|
|
28
|
+
const nodePath = require('path');
|
|
29
|
+
|
|
30
|
+
/** Functions whose calls get a `{ path }` second argument injected. */
|
|
31
|
+
const TARGET_FNS = ['createStaticStyles', 'createStyles'];
|
|
32
|
+
const CALL_RE = new RegExp(`(?:${TARGET_FNS.join('|')})\\s*\\(`, 'g');
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the project root directory.
|
|
36
|
+
* - If the consumer passes `options.rootDir`, use that.
|
|
37
|
+
* - Otherwise walk up from the loader's own location until we leave
|
|
38
|
+
* `node_modules` (works for both hoisted and nested installs).
|
|
39
|
+
* - Fallback: `process.cwd()`.
|
|
40
|
+
*/
|
|
41
|
+
function resolveRoot(loaderContext) {
|
|
42
|
+
const opts =
|
|
43
|
+
typeof loaderContext.getOptions === 'function' ? loaderContext.getOptions() : loaderContext.query || {};
|
|
44
|
+
|
|
45
|
+
if (opts.rootDir) return nodePath.resolve(opts.rootDir);
|
|
46
|
+
|
|
47
|
+
// Walk up from this file (inside node_modules/@gomeniucivan/ui/)
|
|
48
|
+
let dir = __dirname;
|
|
49
|
+
while (dir !== nodePath.dirname(dir)) {
|
|
50
|
+
if (nodePath.basename(dir) === 'node_modules') {
|
|
51
|
+
return nodePath.dirname(dir); // parent of node_modules
|
|
52
|
+
}
|
|
53
|
+
dir = nodePath.dirname(dir);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return process.cwd();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = function injectStylePathLoader(source) {
|
|
60
|
+
// Fast bail-out
|
|
61
|
+
if (!CALL_RE.test(source)) return source;
|
|
62
|
+
CALL_RE.lastIndex = 0;
|
|
63
|
+
|
|
64
|
+
const resourcePath = this.resourcePath.replace(/\\/g, '/');
|
|
65
|
+
|
|
66
|
+
// Skip the factory implementation files themselves
|
|
67
|
+
if (
|
|
68
|
+
(resourcePath.includes('createStaticStyles') || resourcePath.includes('createStyles')) &&
|
|
69
|
+
resourcePath.endsWith('index.ts')
|
|
70
|
+
) {
|
|
71
|
+
return source;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const rootDir = resolveRoot(this);
|
|
75
|
+
|
|
76
|
+
// Relative path from project root, forward slashes, no extension
|
|
77
|
+
const filePath = nodePath
|
|
78
|
+
.relative(rootDir, this.resourcePath)
|
|
79
|
+
.replace(/\\/g, '/')
|
|
80
|
+
.replace(/\.\w+$/, '');
|
|
81
|
+
|
|
82
|
+
// Find every target function call
|
|
83
|
+
const positions = [];
|
|
84
|
+
let m;
|
|
85
|
+
while ((m = CALL_RE.exec(source)) !== null) {
|
|
86
|
+
// Skip if inside a comment
|
|
87
|
+
const lineStart = source.lastIndexOf('\n', m.index) + 1;
|
|
88
|
+
const lineText = source.slice(lineStart, m.index).trimStart();
|
|
89
|
+
if (lineText.startsWith('*') || lineText.startsWith('//')) continue;
|
|
90
|
+
positions.push(m.index + m[0].length); // right after opening `(`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (positions.length === 0) return source;
|
|
94
|
+
|
|
95
|
+
// Process in reverse so indices don't shift
|
|
96
|
+
let result = source;
|
|
97
|
+
for (let ci = positions.length - 1; ci >= 0; ci--) {
|
|
98
|
+
const afterParen = positions[ci];
|
|
99
|
+
|
|
100
|
+
// Count parens to find matching close (skip strings and template literals)
|
|
101
|
+
let depth = 1;
|
|
102
|
+
let closeIdx = -1;
|
|
103
|
+
let inStr = false;
|
|
104
|
+
let strCh = '';
|
|
105
|
+
let inTpl = false;
|
|
106
|
+
let tplDepth = 0;
|
|
107
|
+
|
|
108
|
+
for (let i = afterParen; i < result.length; i++) {
|
|
109
|
+
const ch = result[i];
|
|
110
|
+
const prev = i > 0 ? result[i - 1] : '';
|
|
111
|
+
|
|
112
|
+
if (inStr) {
|
|
113
|
+
if (ch === strCh && prev !== '\\') inStr = false;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (inTpl) {
|
|
117
|
+
if (ch === '`' && prev !== '\\') {
|
|
118
|
+
inTpl = false;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (ch === '$' && result[i + 1] === '{') {
|
|
122
|
+
tplDepth++;
|
|
123
|
+
i++;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (ch === '}' && tplDepth > 0) {
|
|
127
|
+
tplDepth--;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (ch === '"' || ch === "'") {
|
|
133
|
+
inStr = true;
|
|
134
|
+
strCh = ch;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (ch === '`') {
|
|
138
|
+
inTpl = true;
|
|
139
|
+
tplDepth = 0;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (ch === '(') depth++;
|
|
143
|
+
if (ch === ')') {
|
|
144
|
+
depth--;
|
|
145
|
+
if (depth === 0) {
|
|
146
|
+
closeIdx = i;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (closeIdx === -1) continue;
|
|
153
|
+
|
|
154
|
+
// Skip if already has a path option
|
|
155
|
+
const inner = result.slice(afterParen, closeIdx);
|
|
156
|
+
if (inner.includes('path:')) continue;
|
|
157
|
+
|
|
158
|
+
const hasTrailingComma = /,\s*$/.test(inner);
|
|
159
|
+
const pathArg = hasTrailingComma
|
|
160
|
+
? ` { path: '${filePath}' }`
|
|
161
|
+
: `, { path: '${filePath}' }`;
|
|
162
|
+
|
|
163
|
+
result = result.slice(0, closeIdx) + pathArg + result.slice(closeIdx);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return result;
|
|
167
|
+
};
|
package/next-plugin.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gomeniucivan/ui Next.js plugin
|
|
3
|
+
*
|
|
4
|
+
* Wraps your Next.js config to automatically inject style debug paths.
|
|
5
|
+
* This is OPTIONAL — in dev mode (localhost), paths are auto-detected
|
|
6
|
+
* at runtime without any build config. Use this plugin for production
|
|
7
|
+
* builds or when you want guaranteed path accuracy.
|
|
8
|
+
*
|
|
9
|
+
* Usage in next.config.ts:
|
|
10
|
+
*
|
|
11
|
+
* import withStyleDebug from '@gomeniucivan/ui/next-plugin';
|
|
12
|
+
* export default withStyleDebug({ ...yourConfig });
|
|
13
|
+
*
|
|
14
|
+
* Or in next.config.js:
|
|
15
|
+
*
|
|
16
|
+
* const withStyleDebug = require('@gomeniucivan/ui/next-plugin');
|
|
17
|
+
* module.exports = withStyleDebug({ ...yourConfig });
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
const path = require('path');
|
|
23
|
+
|
|
24
|
+
function withStyleDebug(nextConfig = {}) {
|
|
25
|
+
const userWebpack = nextConfig.webpack;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
...nextConfig,
|
|
29
|
+
webpack: (config, options) => {
|
|
30
|
+
// Add the style path injection loader
|
|
31
|
+
config.module.rules.push({
|
|
32
|
+
test: /\.tsx?$/,
|
|
33
|
+
enforce: 'pre',
|
|
34
|
+
exclude: /node_modules/,
|
|
35
|
+
use: [
|
|
36
|
+
{
|
|
37
|
+
loader: require.resolve('./loader.js'),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Chain with user's webpack config if present
|
|
43
|
+
if (typeof userWebpack === 'function') {
|
|
44
|
+
return userWebpack(config, options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return config;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = withStyleDebug;
|
|
53
|
+
module.exports.default = withStyleDebug;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gomeniucivan/ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"private": false,
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
|
+
"./loader": "./loader.js",
|
|
16
|
+
"./next-plugin": "./next-plugin.js"
|
|
15
17
|
},
|
|
16
18
|
"main": "dist/index.js",
|
|
17
19
|
"module": "dist/index.mjs",
|
|
18
20
|
"types": "dist/index.d.ts",
|
|
19
21
|
"files": [
|
|
20
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"loader.js",
|
|
24
|
+
"next-plugin.js"
|
|
21
25
|
],
|
|
22
26
|
"scripts": {
|
|
23
27
|
"build": "tsup",
|
|
@@ -52,7 +56,12 @@
|
|
|
52
56
|
"@dnd-kit/utilities": "^3.2.2",
|
|
53
57
|
"@emoji-mart/data": "^1.2.1",
|
|
54
58
|
"@emoji-mart/react": "^1.1.1",
|
|
59
|
+
"@emotion/cache": "^11.11.0",
|
|
60
|
+
"@emotion/css": "^11.11.2",
|
|
55
61
|
"@emotion/is-prop-valid": "^1.4.0",
|
|
62
|
+
"@emotion/react": "^11.11.4",
|
|
63
|
+
"@emotion/serialize": "^1.1.3",
|
|
64
|
+
"@emotion/utils": "^1.2.1",
|
|
56
65
|
"@floating-ui/react": "^0.27.17",
|
|
57
66
|
"@giscus/react": "^3.1.0",
|
|
58
67
|
"@mdx-js/mdx": "^3.1.1",
|
|
@@ -63,7 +72,6 @@
|
|
|
63
72
|
"@shikijs/transformers": "^3.22.0",
|
|
64
73
|
"@splinetool/runtime": "0.9.526",
|
|
65
74
|
"ahooks": "^3.9.6",
|
|
66
|
-
"antd-style": "^4.1.0",
|
|
67
75
|
"chroma-js": "^3.2.0",
|
|
68
76
|
"class-variance-authority": "^0.7.1",
|
|
69
77
|
"clsx": "^2.1.1",
|
|
@@ -134,7 +142,6 @@
|
|
|
134
142
|
"@types/uuid": "^11.0.0",
|
|
135
143
|
"@vitest/coverage-v8": "^3.2.4",
|
|
136
144
|
"antd": "^6.2.3",
|
|
137
|
-
"babel-plugin-antd-style": "^1.0.4",
|
|
138
145
|
"cheerio": "^1.2.0",
|
|
139
146
|
"clean-package": "^2.2.0",
|
|
140
147
|
"commitlint": "^19.8.1",
|