@compact-design/core 0.1.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 +373 -0
- package/README.md +86 -0
- package/dist/constants.d.ts +2 -0
- package/dist/generated-schema.d.ts +1666 -0
- package/dist/index.cjs +8800 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +8778 -0
- package/dist/lint.d.ts +10 -0
- package/dist/normalize.d.ts +4 -0
- package/dist/parser.d.ts +1 -0
- package/dist/patch.d.ts +6 -0
- package/dist/references.d.ts +6 -0
- package/dist/schema-validation.d.ts +2 -0
- package/dist/schema.d.ts +1 -0
- package/dist/types.d.ts +257 -0
- package/dist/validate.d.ts +2 -0
- package/package.json +55 -0
package/dist/lint.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InternalDocument } from "./types";
|
|
2
|
+
export interface RepairIssue {
|
|
3
|
+
severity: "ERROR" | "WARNING" | "INFO";
|
|
4
|
+
code: string;
|
|
5
|
+
path: string;
|
|
6
|
+
message: string;
|
|
7
|
+
suggestion?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function lintDocument(document: InternalDocument): RepairIssue[];
|
|
10
|
+
export declare function validationIssues(errors: string[]): RepairIssue[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InternalDocument, InternalPatchDocument } from "./types";
|
|
2
|
+
export declare function normalizeDocument(value: unknown): InternalDocument;
|
|
3
|
+
export declare function isPatchDocument(value: unknown): boolean;
|
|
4
|
+
export declare function normalizePatchDocument(value: unknown): InternalPatchDocument;
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseDocument(source: string): unknown;
|
package/dist/patch.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InternalDocument, InternalPatchDocument } from "./types";
|
|
2
|
+
export interface PatchResult {
|
|
3
|
+
document: InternalDocument;
|
|
4
|
+
affectedIds: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function applyDocumentPatch(document: InternalDocument, patch: InternalPatchDocument): PatchResult;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InternalDocument, InternalNode } from "./types";
|
|
2
|
+
export interface DocumentIndex {
|
|
3
|
+
nodes: ReadonlyMap<string, InternalNode>;
|
|
4
|
+
components: ReadonlyMap<string, InternalNode>;
|
|
5
|
+
}
|
|
6
|
+
export declare function indexDocument(document: InternalDocument): DocumentIndex;
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const schema: Readonly<Record<string, unknown>>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
export type JsonObject = Record<string, unknown>;
|
|
2
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
3
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
4
|
+
export type Transform = [[number, number, number], [number, number, number]];
|
|
5
|
+
export interface LineHeight {
|
|
6
|
+
unit: "AUTO" | "PIXELS" | "PERCENT";
|
|
7
|
+
value?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface LetterSpacing {
|
|
10
|
+
unit: "PIXELS" | "PERCENT";
|
|
11
|
+
value: number;
|
|
12
|
+
}
|
|
13
|
+
export interface VectorPath {
|
|
14
|
+
windingRule: "NONZERO" | "EVENODD";
|
|
15
|
+
data: string;
|
|
16
|
+
}
|
|
17
|
+
export interface VariableAlias {
|
|
18
|
+
type: "VARIABLE_ALIAS";
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Constraints {
|
|
22
|
+
horizontal: "MIN" | "CENTER" | "MAX" | "STRETCH" | "SCALE";
|
|
23
|
+
vertical: "MIN" | "CENTER" | "MAX" | "STRETCH" | "SCALE";
|
|
24
|
+
}
|
|
25
|
+
export type ComponentPropertyType = "BOOLEAN" | "TEXT" | "INSTANCE_SWAP" | "VARIANT";
|
|
26
|
+
export interface ComponentPropertyOptions {
|
|
27
|
+
preferredValues?: Array<{
|
|
28
|
+
type: "COMPONENT" | "COMPONENT_SET";
|
|
29
|
+
key: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export type OverflowDirection = "NONE" | "HORIZONTAL" | "VERTICAL" | "BOTH";
|
|
33
|
+
export type BlendMode = "PASS_THROUGH" | "NORMAL" | "DARKEN" | "MULTIPLY" | "LINEAR_BURN" | "COLOR_BURN" | "LIGHTEN" | "SCREEN" | "LINEAR_DODGE" | "COLOR_DODGE" | "OVERLAY" | "SOFT_LIGHT" | "HARD_LIGHT" | "DIFFERENCE" | "EXCLUSION" | "HUE" | "SATURATION" | "COLOR" | "LUMINOSITY";
|
|
34
|
+
export type StrokeCap = "NONE" | "ROUND" | "SQUARE" | "LINE_ARROW" | "TRIANGLE_ARROW" | "DIAMOND_FILLED" | "CIRCLE_FILLED" | "TRIANGLE_FILLED" | "WASHI_TAPE_1" | "WASHI_TAPE_2" | "WASHI_TAPE_3" | "WASHI_TAPE_4" | "WASHI_TAPE_5" | "WASHI_TAPE_6";
|
|
35
|
+
export type StrokeJoin = "MITER" | "BEVEL" | "ROUND";
|
|
36
|
+
export type TextDecoration = "NONE" | "UNDERLINE" | "STRIKETHROUGH";
|
|
37
|
+
export type TextCase = "ORIGINAL" | "UPPER" | "LOWER" | "TITLE" | "SMALL_CAPS" | "SMALL_CAPS_FORCED";
|
|
38
|
+
export interface DesignColor {
|
|
39
|
+
r: number;
|
|
40
|
+
g: number;
|
|
41
|
+
b: number;
|
|
42
|
+
a?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface DesignPoint {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
}
|
|
48
|
+
export interface DesignSize {
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
}
|
|
52
|
+
export interface DesignFont {
|
|
53
|
+
family: string;
|
|
54
|
+
style: string;
|
|
55
|
+
size: number;
|
|
56
|
+
}
|
|
57
|
+
export interface DesignPaint {
|
|
58
|
+
type: string;
|
|
59
|
+
color?: DesignColor;
|
|
60
|
+
opacity?: number;
|
|
61
|
+
src?: string;
|
|
62
|
+
bytes?: Uint8Array;
|
|
63
|
+
sourceWidth?: number;
|
|
64
|
+
sourceHeight?: number;
|
|
65
|
+
resizedWidth?: number;
|
|
66
|
+
resizedHeight?: number;
|
|
67
|
+
scaleMode?: string;
|
|
68
|
+
imageTransform?: Transform;
|
|
69
|
+
gradientTransform?: Transform;
|
|
70
|
+
gradientStops?: Array<{
|
|
71
|
+
position: number;
|
|
72
|
+
color: DesignColor;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
export interface DesignEffect {
|
|
76
|
+
type: string;
|
|
77
|
+
color?: DesignColor;
|
|
78
|
+
offset?: DesignPoint;
|
|
79
|
+
radius?: number;
|
|
80
|
+
spread?: number;
|
|
81
|
+
visible?: boolean;
|
|
82
|
+
blendMode?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface DesignStyles {
|
|
85
|
+
fills: DesignPaint[];
|
|
86
|
+
strokes: DesignPaint[];
|
|
87
|
+
effects: DesignEffect[];
|
|
88
|
+
}
|
|
89
|
+
export interface DesignLayout {
|
|
90
|
+
direction?: "HORIZONTAL" | "VERTICAL" | "GRID";
|
|
91
|
+
itemSpacing?: number;
|
|
92
|
+
counterAxisSpacing?: number;
|
|
93
|
+
padding?: {
|
|
94
|
+
left?: number;
|
|
95
|
+
top?: number;
|
|
96
|
+
right?: number;
|
|
97
|
+
bottom?: number;
|
|
98
|
+
};
|
|
99
|
+
primaryAxisAlignItems?: string;
|
|
100
|
+
counterAxisAlignItems?: string;
|
|
101
|
+
primaryAxisSizingMode?: string;
|
|
102
|
+
counterAxisSizingMode?: string;
|
|
103
|
+
wrap?: boolean;
|
|
104
|
+
}
|
|
105
|
+
export interface DesignProperties {
|
|
106
|
+
position: DesignPoint;
|
|
107
|
+
size: DesignSize;
|
|
108
|
+
rotation: number;
|
|
109
|
+
styles: DesignStyles;
|
|
110
|
+
text?: string;
|
|
111
|
+
font?: DesignFont;
|
|
112
|
+
lineHeight?: LineHeight;
|
|
113
|
+
alignment?: string;
|
|
114
|
+
letterSpacing?: LetterSpacing;
|
|
115
|
+
runs?: JsonObject[];
|
|
116
|
+
layout?: DesignLayout;
|
|
117
|
+
prototype?: JsonObject[];
|
|
118
|
+
bindings?: Record<string, string>;
|
|
119
|
+
styleRefs?: Record<string, string>;
|
|
120
|
+
variableModes?: Record<string, string>;
|
|
121
|
+
breakpoint?: JsonObject;
|
|
122
|
+
componentId?: string;
|
|
123
|
+
variantAxes?: Record<string, string[]>;
|
|
124
|
+
variant?: Record<string, string>;
|
|
125
|
+
svg?: string;
|
|
126
|
+
vectorPaths?: VectorPath[];
|
|
127
|
+
pointCount?: number;
|
|
128
|
+
innerRadius?: number;
|
|
129
|
+
startingAngle?: number;
|
|
130
|
+
endingAngle?: number;
|
|
131
|
+
innerRadiusRatio?: number;
|
|
132
|
+
componentProperties?: Array<{
|
|
133
|
+
name: string;
|
|
134
|
+
type: ComponentPropertyType;
|
|
135
|
+
defaultValue: string | boolean;
|
|
136
|
+
options?: ComponentPropertyOptions;
|
|
137
|
+
}>;
|
|
138
|
+
instanceProperties?: Record<string, string | boolean | VariableAlias>;
|
|
139
|
+
operation?: "UNION" | "SUBTRACT" | "INTERSECT" | "EXCLUDE";
|
|
140
|
+
overflowDirection?: OverflowDirection;
|
|
141
|
+
numberOfFixedChildren?: number;
|
|
142
|
+
layoutGrids?: JsonObject[];
|
|
143
|
+
cornerRadius?: number;
|
|
144
|
+
cornerRadii?: number[];
|
|
145
|
+
opacity?: number;
|
|
146
|
+
blendMode?: BlendMode;
|
|
147
|
+
visible?: boolean;
|
|
148
|
+
locked?: boolean;
|
|
149
|
+
isMask?: boolean;
|
|
150
|
+
clipsContent?: boolean;
|
|
151
|
+
constraints?: Constraints;
|
|
152
|
+
layoutSizingHorizontal?: "FIXED" | "HUG" | "FILL";
|
|
153
|
+
layoutSizingVertical?: "FIXED" | "HUG" | "FILL";
|
|
154
|
+
layoutAlign?: "INHERIT" | "STRETCH";
|
|
155
|
+
layoutGrow?: number;
|
|
156
|
+
layoutPositioning?: "AUTO" | "ABSOLUTE";
|
|
157
|
+
minWidth?: number | null;
|
|
158
|
+
maxWidth?: number | null;
|
|
159
|
+
minHeight?: number | null;
|
|
160
|
+
maxHeight?: number | null;
|
|
161
|
+
strokeWeight?: number;
|
|
162
|
+
strokeTopWeight?: number;
|
|
163
|
+
strokeRightWeight?: number;
|
|
164
|
+
strokeBottomWeight?: number;
|
|
165
|
+
strokeLeftWeight?: number;
|
|
166
|
+
strokeAlign?: "INSIDE" | "OUTSIDE" | "CENTER";
|
|
167
|
+
strokeCap?: StrokeCap;
|
|
168
|
+
strokeJoin?: StrokeJoin;
|
|
169
|
+
dashPattern?: number[];
|
|
170
|
+
textAutoResize?: "NONE" | "WIDTH_AND_HEIGHT" | "HEIGHT" | "TRUNCATE";
|
|
171
|
+
textDecoration?: TextDecoration;
|
|
172
|
+
paragraphSpacing?: number;
|
|
173
|
+
paragraphIndent?: number;
|
|
174
|
+
listSpacing?: number;
|
|
175
|
+
hangingPunctuation?: boolean;
|
|
176
|
+
hangingList?: boolean;
|
|
177
|
+
textCase?: TextCase;
|
|
178
|
+
verticalAlignment?: "TOP" | "CENTER" | "BOTTOM";
|
|
179
|
+
textTruncation?: "DISABLED" | "ENDING";
|
|
180
|
+
maxLines?: number | null;
|
|
181
|
+
}
|
|
182
|
+
export interface VariableDefinition {
|
|
183
|
+
id?: string;
|
|
184
|
+
name: string;
|
|
185
|
+
type: "COLOR" | "FLOAT" | "STRING" | "BOOLEAN";
|
|
186
|
+
value?: JsonValue | DesignColor;
|
|
187
|
+
values?: Record<string, JsonValue | DesignColor>;
|
|
188
|
+
}
|
|
189
|
+
export interface VariableCollectionDefinition {
|
|
190
|
+
name: string;
|
|
191
|
+
modes?: string[];
|
|
192
|
+
items: VariableDefinition[];
|
|
193
|
+
}
|
|
194
|
+
export interface StyleDefinition {
|
|
195
|
+
id?: string;
|
|
196
|
+
name: string;
|
|
197
|
+
type: "PAINT" | "TEXT";
|
|
198
|
+
paints?: DesignPaint[];
|
|
199
|
+
font?: DesignFont;
|
|
200
|
+
lineHeight?: LineHeight | number;
|
|
201
|
+
letterSpacing?: LetterSpacing;
|
|
202
|
+
paragraphSpacing?: number;
|
|
203
|
+
}
|
|
204
|
+
export interface CompactDocument extends JsonObject {
|
|
205
|
+
canvas?: CompactCanvas;
|
|
206
|
+
canvases?: CompactCanvas[];
|
|
207
|
+
nodes?: CompactNode[];
|
|
208
|
+
styles?: JsonObject[];
|
|
209
|
+
variables?: JsonObject[];
|
|
210
|
+
}
|
|
211
|
+
export interface CompactCanvas extends JsonObject {
|
|
212
|
+
id?: string;
|
|
213
|
+
name?: string;
|
|
214
|
+
x?: number;
|
|
215
|
+
y?: number;
|
|
216
|
+
width: number;
|
|
217
|
+
height: number;
|
|
218
|
+
fill?: unknown;
|
|
219
|
+
nodes?: CompactNode[];
|
|
220
|
+
breakpoint?: JsonObject;
|
|
221
|
+
}
|
|
222
|
+
export interface CompactNode extends JsonObject {
|
|
223
|
+
id?: string;
|
|
224
|
+
name?: string;
|
|
225
|
+
type?: string;
|
|
226
|
+
x?: number;
|
|
227
|
+
y?: number;
|
|
228
|
+
w?: number;
|
|
229
|
+
h?: number;
|
|
230
|
+
children?: CompactNode[];
|
|
231
|
+
}
|
|
232
|
+
export interface InternalNode {
|
|
233
|
+
id: string;
|
|
234
|
+
name: string;
|
|
235
|
+
type: string;
|
|
236
|
+
properties: DesignProperties;
|
|
237
|
+
children: InternalNode[];
|
|
238
|
+
}
|
|
239
|
+
export interface InternalDocument {
|
|
240
|
+
nodes: InternalNode[];
|
|
241
|
+
styles: StyleDefinition[];
|
|
242
|
+
variables: VariableCollectionDefinition[];
|
|
243
|
+
}
|
|
244
|
+
export type ImportMode = "CREATE" | "REPLACE" | "UPDATE";
|
|
245
|
+
export interface PatchOperation {
|
|
246
|
+
op: "SET" | "REMOVE" | "APPEND";
|
|
247
|
+
id?: string;
|
|
248
|
+
parent?: string;
|
|
249
|
+
set?: JsonObject;
|
|
250
|
+
normalized?: DesignProperties;
|
|
251
|
+
node?: InternalNode;
|
|
252
|
+
}
|
|
253
|
+
export interface InternalPatchDocument {
|
|
254
|
+
patch: {
|
|
255
|
+
operations: PatchOperation[];
|
|
256
|
+
};
|
|
257
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@compact-design/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reusable parser, normalizer, validator, patch engine, and linter for Compact Design JSON.",
|
|
5
|
+
"license": "MPL-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/Elliot727/compact-design.git",
|
|
28
|
+
"directory": "packages/core"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/Elliot727/compact-design/tree/main/packages/core#readme",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Elliot727/compact-design/issues"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"compact-design",
|
|
36
|
+
"design",
|
|
37
|
+
"json",
|
|
38
|
+
"schema",
|
|
39
|
+
"linter"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"generate:schema": "node scripts/generate-schema.mjs",
|
|
46
|
+
"build": "npm run generate:schema && node scripts/build.mjs",
|
|
47
|
+
"prepack": "npm run build",
|
|
48
|
+
"test": "npm run generate:schema && node scripts/test.mjs",
|
|
49
|
+
"typecheck": "npm run generate:schema && tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
50
|
+
"lint": "node scripts/lint.mjs"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"ajv": "^8.20.0"
|
|
54
|
+
}
|
|
55
|
+
}
|