@jk2908/cxx 0.3.7 → 0.4.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/README.md +51 -18
- package/dist/build.d.ts +17 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +54 -18
- package/dist/build.js.map +3 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -4
- package/dist/index.js.map +5 -4
- package/dist/next/cxx-loader.cjs +55 -19
- package/dist/next/cxx-loader.cjs.map +4 -4
- package/dist/next/index.d.ts +6 -5
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +55 -19
- package/dist/next/index.js.map +4 -4
- package/dist/style.d.ts +297 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/types.d.ts +35 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +59 -22
- package/dist/vite/index.js.map +4 -4
- package/package.json +1 -1
- package/src/build.ts +66 -24
- package/src/index.ts +41 -14
- package/src/next/index.ts +10 -2
- package/src/style.ts +20 -0
- package/src/types.ts +52 -9
- package/src/vite/index.ts +10 -4
package/src/types.ts
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { ComponentPropsWithRef } from 'react'
|
|
2
|
+
|
|
3
|
+
export type StyleMode = 'embed' | 'extract'
|
|
4
|
+
|
|
5
|
+
export type EmbedStyleDescriptor = {
|
|
6
|
+
mode: 'embed'
|
|
7
|
+
href: string
|
|
8
|
+
css: string
|
|
9
|
+
precedence: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type EmbedResult<ClassName extends string = string> = {
|
|
13
|
+
mode: 'embed'
|
|
14
|
+
styles: Readonly<Record<ClassName, string>>
|
|
15
|
+
styleProps: EmbedStyleDescriptor
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ExtractResult<ClassName extends string = string> = {
|
|
19
|
+
mode: 'extract'
|
|
20
|
+
styles: Readonly<Record<ClassName, string>>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type Result<ClassName extends string = string> =
|
|
24
|
+
| EmbedResult<ClassName>
|
|
25
|
+
| ExtractResult<ClassName>
|
|
26
|
+
|
|
27
|
+
type StyleElementProps = Omit<
|
|
28
|
+
ComponentPropsWithRef<'style'>,
|
|
29
|
+
'href' | 'precedence' | 'children'
|
|
30
|
+
> & {
|
|
31
|
+
href: string
|
|
32
|
+
precedence: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type StyleProps = EmbedStyleDescriptor & StyleElementProps
|
|
6
36
|
|
|
7
37
|
export type Tags = Map<string, string[]>
|
|
8
38
|
|
|
@@ -14,10 +44,23 @@ export type PluginConfig = {
|
|
|
14
44
|
}
|
|
15
45
|
}
|
|
16
46
|
|
|
17
|
-
export type
|
|
47
|
+
export type EmbedTag = <ClassName extends string = string>(
|
|
48
|
+
name: string,
|
|
49
|
+
) => (_: TemplateStringsArray) => EmbedResult<ClassName>
|
|
50
|
+
|
|
51
|
+
export type ExtractTag = <ClassName extends string = string>(
|
|
18
52
|
name: string,
|
|
19
|
-
) => (_: TemplateStringsArray) =>
|
|
53
|
+
) => (_: TemplateStringsArray) => ExtractResult<ClassName>
|
|
54
|
+
|
|
55
|
+
export type EmbedStyleTag = ((_: TemplateStringsArray) => EmbedResult) & {
|
|
56
|
+
tag: EmbedTag
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type ExtractStyleTag = ((_: TemplateStringsArray) => ExtractResult) & {
|
|
60
|
+
tag: ExtractTag
|
|
61
|
+
}
|
|
20
62
|
|
|
21
|
-
export type Cxx =
|
|
22
|
-
|
|
63
|
+
export type Cxx = {
|
|
64
|
+
embed: EmbedStyleTag
|
|
65
|
+
extract: ExtractStyleTag
|
|
23
66
|
}
|
package/src/vite/index.ts
CHANGED
|
@@ -7,9 +7,11 @@ import type { PluginConfig } from '../types.js'
|
|
|
7
7
|
import {
|
|
8
8
|
collect,
|
|
9
9
|
flushTypes,
|
|
10
|
+
injectStyleImports,
|
|
10
11
|
refreshFile,
|
|
11
12
|
seedTypes,
|
|
12
13
|
SOURCE_EXTENSIONS,
|
|
14
|
+
writeStyleSheets,
|
|
13
15
|
writeTypesForFile,
|
|
14
16
|
} from '../build.js'
|
|
15
17
|
import { GENERATED_DIR } from '../config.js'
|
|
@@ -121,15 +123,19 @@ export default function cxx(pluginConfig: PluginConfig = {}) {
|
|
|
121
123
|
|
|
122
124
|
if (!SOURCE_EXTENSIONS.has(path.extname(cleanId))) return null
|
|
123
125
|
|
|
124
|
-
const
|
|
126
|
+
const result = collect(code, cleanId, pluginConfig)
|
|
125
127
|
|
|
126
|
-
if (template === code) return null
|
|
128
|
+
if (result.template === code) return null
|
|
127
129
|
|
|
128
|
-
|
|
130
|
+
const file = resolveWatchFile(cleanId)
|
|
131
|
+
const imports = writeStyleSheets(file, result.sheets)
|
|
132
|
+
const template = injectStyleImports(result.template, imports)
|
|
133
|
+
|
|
134
|
+
void writeTypesForFile(file, result.tags)
|
|
129
135
|
|
|
130
136
|
return {
|
|
131
137
|
code: template,
|
|
132
|
-
map,
|
|
138
|
+
map: result.map,
|
|
133
139
|
}
|
|
134
140
|
},
|
|
135
141
|
configureServer(server: ViteDevServer) {
|