@design-embed/target-vanjs 1.0.0
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/LICENSE +9 -0
- package/README.md +18 -0
- package/dist/design-embed/src/core/diagnostics/diagnostic.d.mts +16 -0
- package/dist/design-embed/src/core/nodes.d.mts +63 -0
- package/dist/design-embed/src/core/plugins/pluginApi.d.mts +41 -0
- package/dist/design-embed/src/core/types.d.mts +98 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.mjs +926 -0
- package/dist/index.test.d.mts +1 -0
- package/dist/index.test.mjs +84 -0
- package/package.json +32 -0
- package/src/index.ts +1565 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jin Woo Lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @design-embed/target-vanjs
|
|
2
|
+
|
|
3
|
+
VanJS target for design-embed. Generates VanJS components from design nodes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @design-embed/target-vanjs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { VanJsTarget } from "@design-embed/target-vanjs";
|
|
15
|
+
|
|
16
|
+
const target = new VanJsTarget();
|
|
17
|
+
// Use with design-embed
|
|
18
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SourceLocation } from "../nodes.mjs";
|
|
2
|
+
|
|
3
|
+
//#region packages/design-embed/src/core/diagnostics/diagnostic.d.ts
|
|
4
|
+
type DiagnosticSeverity = "error" | "warning" | "info";
|
|
5
|
+
interface Diagnostic {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
severity: DiagnosticSeverity;
|
|
9
|
+
file?: string;
|
|
10
|
+
source?: SourceLocation;
|
|
11
|
+
selector?: string;
|
|
12
|
+
property?: string;
|
|
13
|
+
details?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Diagnostic };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region packages/design-embed/src/core/nodes.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Location in the source HTML file.
|
|
4
|
+
*/
|
|
5
|
+
interface SourceLocation {
|
|
6
|
+
/** Absolute offset in characters. */
|
|
7
|
+
offset: number;
|
|
8
|
+
/** 1-based line number. */
|
|
9
|
+
line: number;
|
|
10
|
+
/** 1-based column number. */
|
|
11
|
+
column: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A normalized node in the design AST.
|
|
15
|
+
*/
|
|
16
|
+
interface DesignNode {
|
|
17
|
+
/** The type of node. */
|
|
18
|
+
kind: "element" | "text" | "component";
|
|
19
|
+
/** HTML tag name (for element kind). */
|
|
20
|
+
tagName?: string;
|
|
21
|
+
/** HTML attributes (for element kind). */
|
|
22
|
+
attributes?: Record<string, string>;
|
|
23
|
+
/** Parsed inline styles (for element kind). */
|
|
24
|
+
styles?: Record<string, string>;
|
|
25
|
+
/** Utility classes to apply. */
|
|
26
|
+
generatedClassNames?: string[];
|
|
27
|
+
/** Child nodes. */
|
|
28
|
+
children?: DesignNode[];
|
|
29
|
+
/** Inner text content (for text kind). */
|
|
30
|
+
text?: string;
|
|
31
|
+
/** Original location in the source HTML. */
|
|
32
|
+
source?: SourceLocation;
|
|
33
|
+
/** Component name (for component kind). */
|
|
34
|
+
component?: string;
|
|
35
|
+
/** Named export of the component. */
|
|
36
|
+
importName?: string;
|
|
37
|
+
/** Mapped prop values for the component. */
|
|
38
|
+
props?: Record<string, PropValue>;
|
|
39
|
+
/** Import path of the component. */
|
|
40
|
+
importPath?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The original element node a component was mapped from. Retained so
|
|
43
|
+
* targets can reconstruct the element's structure when emitting the
|
|
44
|
+
* component implementation.
|
|
45
|
+
*/
|
|
46
|
+
sourceElement?: DesignNode;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A value passed to a component prop.
|
|
50
|
+
*/
|
|
51
|
+
type PropValue = {
|
|
52
|
+
kind: "literal";
|
|
53
|
+
value: string | number | boolean; /** Source attribute name when the prop is bound to `$attr.*`. */
|
|
54
|
+
attribute?: string;
|
|
55
|
+
} | {
|
|
56
|
+
kind: "text";
|
|
57
|
+
value: string;
|
|
58
|
+
} | {
|
|
59
|
+
kind: "children";
|
|
60
|
+
value: DesignNode[];
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { DesignNode, SourceLocation };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Diagnostic } from "../diagnostics/diagnostic.mjs";
|
|
2
|
+
|
|
3
|
+
//#region packages/design-embed/src/core/plugins/pluginApi.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Represents a file generated by the compiler.
|
|
6
|
+
*/
|
|
7
|
+
interface GeneratedFile {
|
|
8
|
+
/** Relative path from the output directory. */
|
|
9
|
+
path: string;
|
|
10
|
+
/** File content. */
|
|
11
|
+
contents: string;
|
|
12
|
+
}
|
|
13
|
+
interface GeneratedAsset {
|
|
14
|
+
path: string;
|
|
15
|
+
contents?: string | Uint8Array;
|
|
16
|
+
sourceUrl?: string;
|
|
17
|
+
}
|
|
18
|
+
interface SourcePlugin {
|
|
19
|
+
name: string;
|
|
20
|
+
run(input: SourcePluginInput): Promise<SourcePluginResult>;
|
|
21
|
+
}
|
|
22
|
+
interface SourcePluginInput {
|
|
23
|
+
cwd: string;
|
|
24
|
+
config?: unknown;
|
|
25
|
+
}
|
|
26
|
+
interface SourcePluginResult {
|
|
27
|
+
html?: string;
|
|
28
|
+
css?: string;
|
|
29
|
+
assets?: GeneratedAsset[];
|
|
30
|
+
files?: GeneratedFile[];
|
|
31
|
+
diagnostics: Diagnostic[];
|
|
32
|
+
}
|
|
33
|
+
interface TargetEmitResult {
|
|
34
|
+
files: GeneratedFile[];
|
|
35
|
+
}
|
|
36
|
+
interface TargetTestGenerateResult {
|
|
37
|
+
files: GeneratedFile[];
|
|
38
|
+
diagnostics: Diagnostic[];
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { SourcePlugin, TargetEmitResult, TargetTestGenerateResult };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DesignNode } from "./nodes.mjs";
|
|
2
|
+
import { SourcePlugin, TargetEmitResult, TargetTestGenerateResult } from "./plugins/pluginApi.mjs";
|
|
3
|
+
import { Diagnostic } from "./diagnostics/diagnostic.mjs";
|
|
4
|
+
|
|
5
|
+
//#region packages/design-embed/src/core/types.d.ts
|
|
6
|
+
interface TargetEmitInput {
|
|
7
|
+
nodes: DesignNode[];
|
|
8
|
+
css?: string;
|
|
9
|
+
config?: DesignEmbedConfig;
|
|
10
|
+
diagnostics: Diagnostic[];
|
|
11
|
+
}
|
|
12
|
+
interface TargetEmitter {
|
|
13
|
+
emit(input: TargetEmitInput): TargetEmitResult;
|
|
14
|
+
}
|
|
15
|
+
interface TargetTestGenerateInput {
|
|
16
|
+
html: string;
|
|
17
|
+
css?: string;
|
|
18
|
+
config: DesignEmbedConfig;
|
|
19
|
+
}
|
|
20
|
+
interface TargetTestGenerator {
|
|
21
|
+
generateTests(input: TargetTestGenerateInput): TargetTestGenerateResult;
|
|
22
|
+
}
|
|
23
|
+
type StyleMode = "inline" | "css-modules" | "tailwind";
|
|
24
|
+
interface ComponentMapping {
|
|
25
|
+
selector: string;
|
|
26
|
+
component: string;
|
|
27
|
+
props?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
interface TokenConfig {
|
|
30
|
+
spacing?: {
|
|
31
|
+
unit?: "px" | "rem";
|
|
32
|
+
threshold?: number;
|
|
33
|
+
values?: Record<string, number>;
|
|
34
|
+
};
|
|
35
|
+
sizing?: NumericTokenGroup;
|
|
36
|
+
typography?: NumericTokenGroup;
|
|
37
|
+
radius?: Record<string, number>;
|
|
38
|
+
borderWidth?: Record<string, number>;
|
|
39
|
+
shadow?: Record<string, string>;
|
|
40
|
+
colors?: Record<string, string>;
|
|
41
|
+
colorThreshold?: number;
|
|
42
|
+
}
|
|
43
|
+
interface NumericTokenGroup {
|
|
44
|
+
unit?: "px" | "rem";
|
|
45
|
+
threshold?: number;
|
|
46
|
+
values?: Record<string, number>;
|
|
47
|
+
}
|
|
48
|
+
type StyleMappings = Record<string, Record<string, string>>;
|
|
49
|
+
interface TestGenerationConfig {
|
|
50
|
+
outputDir?: string;
|
|
51
|
+
runner?: "playwright";
|
|
52
|
+
viewports?: TestViewport[];
|
|
53
|
+
states?: TestState[];
|
|
54
|
+
assertions?: TestAssertions;
|
|
55
|
+
}
|
|
56
|
+
interface TestViewport {
|
|
57
|
+
name?: string;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
}
|
|
61
|
+
interface TestState {
|
|
62
|
+
name: string;
|
|
63
|
+
hover?: string;
|
|
64
|
+
focus?: string;
|
|
65
|
+
click?: string;
|
|
66
|
+
waitFor?: string;
|
|
67
|
+
}
|
|
68
|
+
interface TestAssertions {
|
|
69
|
+
screenshot?: boolean;
|
|
70
|
+
layout?: boolean;
|
|
71
|
+
layoutTolerance?: number;
|
|
72
|
+
selectors?: string[];
|
|
73
|
+
/**
|
|
74
|
+
* Per-pixel color sensitivity (0-1) for the screenshot comparison. Smaller
|
|
75
|
+
* is stricter. Defaults to 0.2.
|
|
76
|
+
*/
|
|
77
|
+
screenshotThreshold?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Maximum number of differing pixels tolerated in the screenshot
|
|
80
|
+
* comparison. Defaults to 0 (byte-exact).
|
|
81
|
+
*/
|
|
82
|
+
screenshotMaxDiffPixels?: number;
|
|
83
|
+
}
|
|
84
|
+
interface DesignEmbedConfig {
|
|
85
|
+
output?: {
|
|
86
|
+
viewsDir?: string | URL;
|
|
87
|
+
target?: "html" | TargetEmitter;
|
|
88
|
+
viewName?: string;
|
|
89
|
+
styleMode?: StyleMode;
|
|
90
|
+
};
|
|
91
|
+
components?: ComponentMapping[];
|
|
92
|
+
tokens?: TokenConfig;
|
|
93
|
+
styleMappings?: StyleMappings;
|
|
94
|
+
source?: SourcePlugin;
|
|
95
|
+
tests?: TestGenerationConfig;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { TargetEmitInput, TargetEmitter, TargetTestGenerateInput, TargetTestGenerator };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DesignNode } from "./design-embed/src/core/nodes.mjs";
|
|
2
|
+
import { TargetEmitResult, TargetTestGenerateResult } from "./design-embed/src/core/plugins/pluginApi.mjs";
|
|
3
|
+
import { TargetEmitInput, TargetEmitter, TargetTestGenerateInput, TargetTestGenerator } from "./design-embed/src/core/types.mjs";
|
|
4
|
+
|
|
5
|
+
//#region packages/target-vanjs/src/index.d.ts
|
|
6
|
+
declare class VanJsTarget implements TargetEmitter, TargetTestGenerator {
|
|
7
|
+
emit({
|
|
8
|
+
nodes,
|
|
9
|
+
css,
|
|
10
|
+
config,
|
|
11
|
+
diagnostics
|
|
12
|
+
}: TargetEmitInput): TargetEmitResult;
|
|
13
|
+
generateTests(input: TargetTestGenerateInput): TargetTestGenerateResult;
|
|
14
|
+
}
|
|
15
|
+
declare const vanJsTestGenerator: TargetTestGenerator;
|
|
16
|
+
declare function emitVanJsView(nodes: DesignNode[], viewName: string, options?: {
|
|
17
|
+
cssModulePath?: string;
|
|
18
|
+
}): string;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { VanJsTarget, emitVanJsView, vanJsTestGenerator };
|