@knighted/css 1.0.0-rc.9 → 1.0.1
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/cjs/generateTypes.cjs +214 -139
- package/dist/cjs/generateTypes.d.cts +65 -16
- package/dist/cjs/loader-helpers.cjs +6 -0
- package/dist/cjs/loader-helpers.d.cts +4 -0
- package/dist/cjs/loader.cjs +2 -0
- package/dist/cjs/loader.d.cts +2 -1
- package/dist/cjs/moduleGraph.cjs +5 -4
- package/dist/cjs/stableSelectors.cjs +29 -0
- package/dist/cjs/stableSelectors.d.cts +15 -0
- package/dist/cjs/stableSelectorsLiteral.cjs +8 -5
- package/dist/cjs/stableSelectorsLiteral.d.cts +2 -0
- package/dist/generateTypes.d.ts +65 -16
- package/dist/generateTypes.js +214 -139
- package/dist/loader-helpers.d.ts +4 -0
- package/dist/loader-helpers.js +3 -0
- package/dist/loader.d.ts +2 -1
- package/dist/loader.js +2 -0
- package/dist/moduleGraph.js +5 -4
- package/dist/stableSelectors.d.ts +15 -0
- package/dist/stableSelectors.js +28 -0
- package/dist/stableSelectorsLiteral.d.ts +2 -0
- package/dist/stableSelectorsLiteral.js +8 -5
- package/loader-queries.d.ts +6 -1
- package/package.json +11 -2
|
@@ -2,11 +2,13 @@ export interface StableSelectorsLiteralResult {
|
|
|
2
2
|
literal: string;
|
|
3
3
|
selectorMap: Map<string, string>;
|
|
4
4
|
}
|
|
5
|
+
type StableSelectorsLiteralTarget = 'ts' | 'js';
|
|
5
6
|
export declare function buildStableSelectorsLiteral(options: {
|
|
6
7
|
css: string;
|
|
7
8
|
namespace: string;
|
|
8
9
|
resourcePath: string;
|
|
9
10
|
emitWarning: (message: string) => void;
|
|
11
|
+
target?: StableSelectorsLiteralTarget;
|
|
10
12
|
}): StableSelectorsLiteralResult;
|
|
11
13
|
export declare function collectStableSelectors(css: string, namespace: string, filename?: string): Map<string, string>;
|
|
12
14
|
declare function collectStableSelectorsByRegex(css: string, namespace: string): Map<string, string>;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { transform as lightningTransform } from 'lightningcss';
|
|
2
2
|
import { escapeRegex, serializeSelector } from './helpers.js';
|
|
3
3
|
export function buildStableSelectorsLiteral(options) {
|
|
4
|
+
const target = options.target ?? 'ts';
|
|
4
5
|
const trimmedNamespace = options.namespace.trim();
|
|
5
6
|
if (!trimmedNamespace) {
|
|
6
7
|
options.emitWarning(`stableSelectors requested for ${options.resourcePath} but "stableNamespace" resolved to an empty value.`);
|
|
7
|
-
return
|
|
8
|
-
literal: 'export const stableSelectors = {} as const;\n',
|
|
9
|
-
selectorMap: new Map(),
|
|
10
|
-
};
|
|
8
|
+
return finalizeLiteral(new Map(), target);
|
|
11
9
|
}
|
|
12
10
|
const selectorMap = collectStableSelectors(options.css, trimmedNamespace, options.resourcePath);
|
|
13
11
|
if (selectorMap.size === 0) {
|
|
14
12
|
options.emitWarning(`stableSelectors requested for ${options.resourcePath} but no selectors matched namespace "${trimmedNamespace}".`);
|
|
15
13
|
}
|
|
14
|
+
return finalizeLiteral(selectorMap, target);
|
|
15
|
+
}
|
|
16
|
+
function finalizeLiteral(selectorMap, target) {
|
|
17
|
+
const formatted = formatStableSelectorMap(selectorMap);
|
|
18
|
+
const suffix = target === 'ts' ? ' as const' : '';
|
|
16
19
|
return {
|
|
17
|
-
literal: `export const stableSelectors = ${
|
|
20
|
+
literal: `export const stableSelectors = ${formatted}${suffix};\n`,
|
|
18
21
|
selectorMap,
|
|
19
22
|
};
|
|
20
23
|
}
|
package/loader-queries.d.ts
CHANGED
|
@@ -19,7 +19,12 @@ declare module '*?knighted-css&types' {
|
|
|
19
19
|
* TypeScript cannot infer the underlying module automatically, so consumers can
|
|
20
20
|
* import the default export and narrow it with `KnightedCssCombinedModule<typeof import('./file')>`.
|
|
21
21
|
*/
|
|
22
|
-
type
|
|
22
|
+
type KnightedCssCombinedExtras = Readonly<Record<string, unknown>>
|
|
23
|
+
|
|
24
|
+
type KnightedCssCombinedModule<
|
|
25
|
+
TModule,
|
|
26
|
+
TExtras extends KnightedCssCombinedExtras = Record<never, never>,
|
|
27
|
+
> = TModule & TExtras & { knightedCss: string }
|
|
23
28
|
|
|
24
29
|
declare module '*?knighted-css&combined' {
|
|
25
30
|
const combined: KnightedCssCombinedModule<Record<string, unknown>>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knighted/css",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A build-time utility that traverses JavaScript/TypeScript module dependency graphs to extract, compile, and optimize all imported CSS into a single, in-memory string.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/css.js",
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"loader": [
|
|
11
11
|
"./dist/loader.d.ts"
|
|
12
12
|
],
|
|
13
|
+
"loader-helpers": [
|
|
14
|
+
"./dist/loader-helpers.d.ts"
|
|
15
|
+
],
|
|
13
16
|
"loader-queries": [
|
|
14
17
|
"./loader-queries.d.ts"
|
|
15
18
|
],
|
|
@@ -32,6 +35,11 @@
|
|
|
32
35
|
"import": "./dist/loader.js",
|
|
33
36
|
"require": "./dist/cjs/loader.cjs"
|
|
34
37
|
},
|
|
38
|
+
"./loader-helpers": {
|
|
39
|
+
"types": "./dist/loader-helpers.d.ts",
|
|
40
|
+
"import": "./dist/loader-helpers.js",
|
|
41
|
+
"require": "./dist/cjs/loader-helpers.cjs"
|
|
42
|
+
},
|
|
35
43
|
"./loader-queries": {
|
|
36
44
|
"types": "./loader-queries.d.ts",
|
|
37
45
|
"default": "./loader-queries.d.ts"
|
|
@@ -112,7 +120,8 @@
|
|
|
112
120
|
"license": "MIT",
|
|
113
121
|
"repository": {
|
|
114
122
|
"type": "git",
|
|
115
|
-
"url": "git+https://github.com/knightedcodemonkey/css.git"
|
|
123
|
+
"url": "git+https://github.com/knightedcodemonkey/css.git",
|
|
124
|
+
"directory": "packages/css"
|
|
116
125
|
},
|
|
117
126
|
"bugs": {
|
|
118
127
|
"url": "https://github.com/knightedcodemonkey/css/issues"
|