@wireweave/core 3.0.1-beta.0 → 3.1.0-beta.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/README.md +80 -417
- package/dist/index.cjs +895 -10
- package/dist/index.d.cts +369 -3
- package/dist/index.d.ts +369 -3
- package/dist/index.js +883 -10
- package/dist/parser.d.cts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/renderer.cjs +4 -3
- package/dist/renderer.d.cts +1 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.js +4 -3
- package/dist/{types-hEr_afgw.d.cts → types-C1kQ4VAF.d.cts} +1 -1
- package/dist/{types-hEr_afgw.d.ts → types-C1kQ4VAF.d.ts} +1 -1
- package/package.json +21 -21
package/README.md
CHANGED
|
@@ -1,476 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
<img src="https://docs.wireweave.org/assets/wireweave-core.svg" width="128" height="128" alt="Wireweave Core">
|
|
3
|
-
</p>
|
|
1
|
+
# @wireweave/core
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
The parser and renderer for the Wireweave wireframe DSL.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## What it does
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
`@wireweave/core` turns Wireweave's text-based DSL into an AST and back into visual output. It provides:
|
|
8
|
+
|
|
9
|
+
- **Parser** — a Peggy-generated parser that converts `.wf` / `.wireframe` source into a typed AST, with strict and error-recovering modes.
|
|
10
|
+
- **Renderers** — render the AST to HTML+CSS, a standalone HTML document, or SVG. Multi-page documents are auto-composed onto a bounded canvas; single-page documents render in legacy single-board mode.
|
|
11
|
+
- **Multi-page canvas** — `.wf` supports multiple pages positioned on a canvas (`page "..." at(x, y)`) with per-page `viewport` / `device` presets.
|
|
12
|
+
- **AST utilities** — type guards and traversal helpers (`walkDocument`, `find`, `findByType`, …).
|
|
13
|
+
- **Validation** — check AST nodes against the DSL specification.
|
|
14
|
+
- **Diff** — structurally compare two documents.
|
|
15
|
+
- **Export** — convert the AST to JSON or a Figma-compatible structure.
|
|
16
|
+
- **Analyze** — compute statistics plus accessibility, complexity, layout, and content metrics.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
10
19
|
|
|
11
20
|
```bash
|
|
12
|
-
npm
|
|
13
|
-
# or
|
|
14
|
-
pnpm add @wireweave/core
|
|
15
|
-
# or
|
|
16
|
-
yarn add @wireweave/core
|
|
21
|
+
npm i @wireweave/core
|
|
17
22
|
```
|
|
18
23
|
|
|
19
|
-
##
|
|
24
|
+
## Usage
|
|
20
25
|
|
|
21
26
|
```typescript
|
|
22
|
-
import { parse, render,
|
|
27
|
+
import { parse, render, renderToHtml, renderToSvg } from '@wireweave/core'
|
|
23
28
|
|
|
24
29
|
const source = `
|
|
25
|
-
page "
|
|
30
|
+
page "Home" {
|
|
26
31
|
card p=4 {
|
|
27
32
|
title "Welcome"
|
|
28
|
-
text "Hello,
|
|
33
|
+
text "Hello, Wireweave!"
|
|
29
34
|
button "Get Started" primary
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
`
|
|
33
38
|
|
|
34
|
-
// Parse DSL
|
|
39
|
+
// Parse DSL into an AST
|
|
35
40
|
const doc = parse(source)
|
|
36
41
|
|
|
37
|
-
// Render to HTML + CSS
|
|
42
|
+
// Render to HTML fragment + CSS
|
|
38
43
|
const { html, css } = render(doc)
|
|
39
44
|
|
|
40
|
-
// Render to
|
|
45
|
+
// Render to a standalone HTML document
|
|
41
46
|
const fullHtml = renderToHtml(doc)
|
|
42
47
|
|
|
43
|
-
// Render to SVG
|
|
48
|
+
// Render to SVG (multi-page docs auto-compose onto a canvas)
|
|
44
49
|
const { svg, width, height } = renderToSvg(doc)
|
|
45
50
|
```
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Parser
|
|
50
|
-
|
|
51
|
-
#### `parse(source: string): WireframeDocument`
|
|
52
|
-
|
|
53
|
-
Parses wireframe DSL source code into an AST (Abstract Syntax Tree).
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
import { parse } from '@wireweave/core'
|
|
57
|
-
|
|
58
|
-
const doc = parse('page { text "Hello" }')
|
|
59
|
-
console.log(doc.children[0].type) // 'Page'
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
**Throws**: `ParseError` if the source contains syntax errors.
|
|
63
|
-
|
|
64
|
-
### HTML Renderer
|
|
65
|
-
|
|
66
|
-
#### `render(doc: WireframeDocument, options?: RenderOptions): RenderResult`
|
|
67
|
-
|
|
68
|
-
Renders the AST to HTML and CSS.
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import { parse, render } from '@wireweave/core'
|
|
72
|
-
|
|
73
|
-
const doc = parse('page { card { text "Hello" } }')
|
|
74
|
-
const { html, css } = render(doc)
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
**Options**:
|
|
78
|
-
| Option | Type | Default | Description |
|
|
79
|
-
|--------|------|---------|-------------|
|
|
80
|
-
| `theme` | `'light' \| 'dark'` | `'light'` | Color theme |
|
|
81
|
-
|
|
82
|
-
**Returns**: `{ html: string, css: string }`
|
|
83
|
-
|
|
84
|
-
#### `renderToHtml(doc: WireframeDocument, options?: RenderOptions): string`
|
|
85
|
-
|
|
86
|
-
Renders the AST to a complete HTML document with embedded CSS.
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
import { parse, renderToHtml } from '@wireweave/core'
|
|
90
|
-
|
|
91
|
-
const doc = parse('page "Test" { text "Hello" }')
|
|
92
|
-
const html = renderToHtml(doc, { theme: 'dark' })
|
|
93
|
-
// Returns: <!DOCTYPE html><html>...</html>
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### SVG Renderer
|
|
97
|
-
|
|
98
|
-
#### `renderToSvg(doc: WireframeDocument, options?: SvgRenderOptions): SvgRenderResult`
|
|
99
|
-
|
|
100
|
-
Renders the AST to SVG format.
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
import { parse, renderToSvg } from '@wireweave/core'
|
|
104
|
-
|
|
105
|
-
const doc = parse('page { button "Click" primary }')
|
|
106
|
-
const { svg, width, height } = renderToSvg(doc, {
|
|
107
|
-
width: 800,
|
|
108
|
-
padding: 20,
|
|
109
|
-
})
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
**Options**:
|
|
113
|
-
| Option | Type | Default | Description |
|
|
114
|
-
|--------|------|---------|-------------|
|
|
115
|
-
| `width` | `number` | `1200` | SVG width in pixels |
|
|
116
|
-
| `padding` | `number` | `24` | Padding around content |
|
|
117
|
-
| `theme` | `'light' \| 'dark'` | `'light'` | Color theme |
|
|
118
|
-
|
|
119
|
-
**Returns**: `{ svg: string, width: number, height: number }`
|
|
120
|
-
|
|
121
|
-
### Analysis
|
|
122
|
-
|
|
123
|
-
#### `analyze(doc: WireframeDocument, options?: AnalysisOptions): AnalysisResult`
|
|
124
|
-
|
|
125
|
-
Analyzes a wireframe document and returns comprehensive statistics.
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
import { parse, analyze } from '@wireweave/core'
|
|
129
|
-
|
|
130
|
-
const doc = parse('page { card { text "Hello" button "Click" } }')
|
|
131
|
-
const result = analyze(doc)
|
|
132
|
-
|
|
133
|
-
console.log(result.summary)
|
|
134
|
-
// { totalComponents: 4, uniqueTypes: 4, mostUsedType: 'Page', ... }
|
|
135
|
-
|
|
136
|
-
console.log(result.tree)
|
|
137
|
-
// { totalNodes: 4, maxDepth: 3, avgDepth: 2, ... }
|
|
138
|
-
|
|
139
|
-
console.log(result.accessibility)
|
|
140
|
-
// { score: 100, imagesWithAlt: 0, inputsWithLabels: 0, ... }
|
|
141
|
-
|
|
142
|
-
console.log(result.complexity)
|
|
143
|
-
// { score: 2, level: 'simple', interactiveElements: 1, ... }
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Options**:
|
|
147
|
-
| Option | Type | Default | Description |
|
|
148
|
-
|--------|------|---------|-------------|
|
|
149
|
-
| `includeComponentBreakdown` | `boolean` | `true` | Include component statistics |
|
|
150
|
-
| `includeAccessibility` | `boolean` | `true` | Include accessibility metrics |
|
|
151
|
-
| `includeComplexity` | `boolean` | `true` | Include complexity analysis |
|
|
152
|
-
| `includeLayout` | `boolean` | `true` | Include layout analysis |
|
|
153
|
-
| `includeContent` | `boolean` | `true` | Include content analysis |
|
|
154
|
-
|
|
155
|
-
### Diff (Document Comparison)
|
|
156
|
-
|
|
157
|
-
#### `diff(oldDoc: WireframeDocument, newDoc: WireframeDocument, options?: DiffOptions): DiffResult`
|
|
158
|
-
|
|
159
|
-
Compares two wireframe documents and returns detailed differences.
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
import { parse, diff } from '@wireweave/core'
|
|
163
|
-
|
|
164
|
-
const oldDoc = parse('page { text "Hello" }')
|
|
165
|
-
const newDoc = parse('page { text "Hello" button "Click" }')
|
|
166
|
-
|
|
167
|
-
const result = diff(oldDoc, newDoc)
|
|
168
|
-
|
|
169
|
-
console.log(result.identical) // false
|
|
170
|
-
console.log(result.description) // "Added 1 component(s): Button."
|
|
171
|
-
console.log(result.summary)
|
|
172
|
-
// { addedCount: 1, removedCount: 0, changedCount: 0, ... }
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
#### `areIdentical(oldDoc: WireframeDocument, newDoc: WireframeDocument): boolean`
|
|
176
|
-
|
|
177
|
-
Quick check if two documents are identical.
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
import { parse, areIdentical } from '@wireweave/core'
|
|
181
|
-
|
|
182
|
-
const doc1 = parse('page { text "Hello" }')
|
|
183
|
-
const doc2 = parse('page { text "Hello" }')
|
|
184
|
-
|
|
185
|
-
console.log(areIdentical(doc1, doc2)) // true
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
#### `getChangeSummary(oldDoc: WireframeDocument, newDoc: WireframeDocument): string`
|
|
189
|
-
|
|
190
|
-
Returns a human-readable summary of changes.
|
|
52
|
+
### Multi-page canvas
|
|
191
53
|
|
|
192
54
|
```typescript
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
55
|
+
const doc = parse(`
|
|
56
|
+
page "Login" at(0, 0) viewport=mobile {
|
|
57
|
+
button "Sign in" primary
|
|
58
|
+
}
|
|
59
|
+
page "Home" at(420, 0) viewport=mobile {
|
|
60
|
+
text "Welcome back"
|
|
61
|
+
}
|
|
62
|
+
`)
|
|
197
63
|
|
|
198
|
-
|
|
199
|
-
// "Modified 1 component(s)."
|
|
64
|
+
const { svg } = renderToSvg(doc) // viewBox sized to the canvas bounding box
|
|
200
65
|
```
|
|
201
66
|
|
|
202
|
-
###
|
|
203
|
-
|
|
204
|
-
#### `exportToJson(doc: WireframeDocument, options?: ExportOptions): JsonExportResult`
|
|
205
|
-
|
|
206
|
-
Exports wireframe to JSON format.
|
|
67
|
+
### Analyze, diff, and export
|
|
207
68
|
|
|
208
69
|
```typescript
|
|
209
|
-
import { parse, exportToJson } from '@wireweave/core'
|
|
70
|
+
import { parse, analyze, diff, exportToJson, exportToFigma } from '@wireweave/core'
|
|
210
71
|
|
|
211
|
-
const
|
|
212
|
-
const
|
|
72
|
+
const a = parse(sourceA)
|
|
73
|
+
const b = parse(sourceB)
|
|
213
74
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
75
|
+
const stats = analyze(a) // totals, accessibility score, complexity, layout, content
|
|
76
|
+
const changes = diff(a, b) // added / removed / changed / moved nodes
|
|
77
|
+
const json = exportToJson(a) // serializable AST
|
|
78
|
+
const figma = exportToFigma(a) // Figma-compatible node tree
|
|
218
79
|
```
|
|
219
80
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
Exports wireframe to JSON string.
|
|
81
|
+
### Print back to canonical DSL
|
|
223
82
|
|
|
224
83
|
```typescript
|
|
225
|
-
import { parse,
|
|
84
|
+
import { parse, printWireframe, formatWireframeCode } from '@wireweave/core'
|
|
226
85
|
|
|
227
|
-
const doc = parse(
|
|
228
|
-
const
|
|
86
|
+
const doc = parse(source)
|
|
87
|
+
const canonical = printWireframe(doc) // deterministic canonical `.wf` text
|
|
88
|
+
const formatted = formatWireframeCode(source) // parse + reprint in one step
|
|
229
89
|
```
|
|
230
90
|
|
|
231
|
-
|
|
91
|
+
The printer emits a single canonical form (fixed indentation, attribute
|
|
92
|
+
ordering, quoting, blank-line policy) with round-trip guarantees:
|
|
93
|
+
`parse(printWireframe(doc))` is structurally equivalent to `doc`, printing is
|
|
94
|
+
idempotent, and already-canonical text reprints byte-identical. Comments are
|
|
95
|
+
not preserved (the parser drops them before the AST).
|
|
232
96
|
|
|
233
|
-
|
|
97
|
+
### Walk the AST
|
|
234
98
|
|
|
235
99
|
```typescript
|
|
236
|
-
import { parse,
|
|
237
|
-
|
|
238
|
-
const doc = parse('page { card { text "Hello" } }')
|
|
239
|
-
const result = exportToFigma(doc)
|
|
240
|
-
|
|
241
|
-
console.log(result.document) // Figma-compatible node tree
|
|
242
|
-
console.log(result.componentMappings)
|
|
243
|
-
// { page: 'CANVAS', card: 'FRAME', text: 'TEXT' }
|
|
244
|
-
```
|
|
100
|
+
import { parse, walkDocument, findByType, isButtonNode } from '@wireweave/core'
|
|
245
101
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
#### `walk(node: ASTNode, callback: WalkCallback): void`
|
|
249
|
-
|
|
250
|
-
Traverses the AST tree depth-first.
|
|
251
|
-
|
|
252
|
-
```typescript
|
|
253
|
-
import { parse } from '@wireweave/core'
|
|
254
|
-
import { walk } from '@wireweave/core/ast'
|
|
102
|
+
const doc = parse(source)
|
|
255
103
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
104
|
+
walkDocument(doc, (node) => {
|
|
105
|
+
if (isButtonNode(node)) {
|
|
106
|
+
console.log(node.content)
|
|
107
|
+
}
|
|
259
108
|
})
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
#### `find(node: ASTNode, predicate: (n: ASTNode) => boolean): ASTNode | undefined`
|
|
263
|
-
|
|
264
|
-
Finds the first node matching the predicate.
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
import { find } from '@wireweave/core/ast'
|
|
268
|
-
|
|
269
|
-
const button = find(doc.children[0], (n) => n.type === 'Button')
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
#### `findAll(node: ASTNode, predicate: (n: ASTNode) => boolean): ASTNode[]`
|
|
273
|
-
|
|
274
|
-
Finds all nodes matching the predicate.
|
|
275
|
-
|
|
276
|
-
```typescript
|
|
277
|
-
import { findAll } from '@wireweave/core/ast'
|
|
278
|
-
|
|
279
|
-
const buttons = findAll(doc.children[0], (n) => n.type === 'Button')
|
|
280
|
-
```
|
|
281
109
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
Finds all nodes of a specific type.
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
import { findByType } from '@wireweave/core/ast'
|
|
288
|
-
import type { ButtonNode } from '@wireweave/core'
|
|
289
|
-
|
|
290
|
-
const buttons = findByType<ButtonNode>(doc.children[0], 'Button')
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
#### `countNodes(node: ASTNode): number`
|
|
294
|
-
|
|
295
|
-
Counts all nodes in the tree.
|
|
296
|
-
|
|
297
|
-
#### `getMaxDepth(node: ASTNode): number`
|
|
298
|
-
|
|
299
|
-
Returns the maximum nesting depth.
|
|
300
|
-
|
|
301
|
-
#### `cloneNode<T>(node: T): T`
|
|
302
|
-
|
|
303
|
-
Creates a deep copy of a node.
|
|
304
|
-
|
|
305
|
-
## Type Definitions
|
|
306
|
-
|
|
307
|
-
### WireframeDocument
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
interface WireframeDocument {
|
|
311
|
-
type: 'Document'
|
|
312
|
-
children: PageNode[]
|
|
313
|
-
}
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
### PageNode
|
|
317
|
-
|
|
318
|
-
```typescript
|
|
319
|
-
interface PageNode {
|
|
320
|
-
type: 'Page'
|
|
321
|
-
title?: string
|
|
322
|
-
children: ASTNode[]
|
|
323
|
-
// ... spacing attributes
|
|
324
|
-
}
|
|
110
|
+
const buttons = findByType(doc.children[0], 'Button')
|
|
325
111
|
```
|
|
326
112
|
|
|
327
|
-
|
|
113
|
+
## Main API
|
|
328
114
|
|
|
329
|
-
|
|
115
|
+
| Export | Description |
|
|
116
|
+
| --------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
117
|
+
| `parse(source, options?)` | Parse DSL into a `WireframeDocument`; throws `ParseError` on syntax errors. |
|
|
118
|
+
| `tryParse` / `isValid` / `getErrors` | Error-recovering parse, boolean check, and error list. |
|
|
119
|
+
| `printWireframe` / `formatWireframeCode` | Canonical `.wf` printer — AST → deterministic DSL text (round-trip safe). |
|
|
120
|
+
| `render(doc, options?)` | Render to `{ html, css }`. Auto canvas mode for multi-page docs. |
|
|
121
|
+
| `renderToHtml(doc, options?)` | Render to a complete standalone HTML document string. |
|
|
122
|
+
| `renderToSvg(doc, options?)` | Render to `{ svg, width, height }` using `foreignObject` (HTML+CSS in SVG). |
|
|
123
|
+
| `renderPage` / `renderCanvas` / `layoutCanvas` | Explicit single-page / multi-page composition primitives. |
|
|
124
|
+
| `validate` / `isValidAst` / `getValidationErrors` | Validate AST nodes against the DSL spec. |
|
|
125
|
+
| `analyze(doc, options?)` | Statistics plus accessibility, complexity, layout, and content metrics. |
|
|
126
|
+
| `diff(oldDoc, newDoc, options?)` | Structural diff; also `areIdentical`, `getChangeSummary`. |
|
|
127
|
+
| `exportToJson` / `importFromJson` / `exportToFigma` | Format conversion to/from JSON and to Figma. |
|
|
128
|
+
| `walkDocument` / `walk` / `find` / `findAll` / `findByType` | AST traversal helpers. |
|
|
129
|
+
| `resolveViewport` / `DEVICE_PRESETS` / `wrapInPreviewContainer` | Viewport sizing, device presets, preview scaling. |
|
|
130
|
+
| AST types + `is*` guards | `WireframeDocument`, `AnyNode`, node types, and type guards. |
|
|
330
131
|
|
|
331
|
-
|
|
332
|
-
- `location?: Location` - Source location info
|
|
333
|
-
- Spacing: `p`, `px`, `py`, `pt`, `pr`, `pb`, `pl`, `m`, `mx`, `my`, `mt`, `mr`, `mb`, `ml`
|
|
334
|
-
- Size: `w`, `h`
|
|
132
|
+
Subpath entries are available for `@wireweave/core/parser` and `@wireweave/core/renderer`.
|
|
335
133
|
|
|
336
|
-
|
|
134
|
+
The build runs `build:grammar` (Peggy) before the TypeScript build to regenerate the parser from `src/grammar/wireframe.peggy`.
|
|
337
135
|
|
|
338
|
-
|
|
339
|
-
// Button
|
|
340
|
-
interface ButtonNode {
|
|
341
|
-
type: 'Button'
|
|
342
|
-
content: string
|
|
343
|
-
primary?: boolean
|
|
344
|
-
secondary?: boolean
|
|
345
|
-
outline?: boolean
|
|
346
|
-
ghost?: boolean
|
|
347
|
-
danger?: boolean
|
|
348
|
-
disabled?: boolean
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// Input
|
|
352
|
-
interface InputNode {
|
|
353
|
-
type: 'Input'
|
|
354
|
-
label?: string
|
|
355
|
-
placeholder?: string
|
|
356
|
-
inputType?: 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'number'
|
|
357
|
-
required?: boolean
|
|
358
|
-
disabled?: boolean
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// Card
|
|
362
|
-
interface CardNode {
|
|
363
|
-
type: 'Card'
|
|
364
|
-
title?: string
|
|
365
|
-
children: ASTNode[]
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// Col
|
|
369
|
-
interface ColNode {
|
|
370
|
-
type: 'Col'
|
|
371
|
-
span?: number
|
|
372
|
-
sm?: number
|
|
373
|
-
md?: number
|
|
374
|
-
lg?: number
|
|
375
|
-
xl?: number
|
|
376
|
-
children: ASTNode[]
|
|
377
|
-
}
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
## DSL Syntax Reference
|
|
381
|
-
|
|
382
|
-
### Page Structure
|
|
383
|
-
|
|
384
|
-
```
|
|
385
|
-
page "Title" {
|
|
386
|
-
header { }
|
|
387
|
-
main { }
|
|
388
|
-
footer { }
|
|
389
|
-
sidebar { }
|
|
390
|
-
aside { }
|
|
391
|
-
}
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
### Layout
|
|
395
|
-
|
|
396
|
-
```
|
|
397
|
-
// Grid columns (12-column system)
|
|
398
|
-
row {
|
|
399
|
-
col span=6 { } // 50% width
|
|
400
|
-
col span=6 { } // 50% width
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Responsive breakpoints
|
|
404
|
-
col span=12 sm=6 md=4 lg=3 xl=2 { }
|
|
405
|
-
|
|
406
|
-
// Flexbox
|
|
407
|
-
row flex justify=center align=center gap=4 wrap { }
|
|
408
|
-
// justify: start, end, center, between, around, evenly
|
|
409
|
-
// align: start, end, center, stretch, baseline
|
|
410
|
-
// direction: row, row-reverse, column, column-reverse
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
### Spacing Scale
|
|
414
|
-
|
|
415
|
-
Values use a 4px base: `1 = 4px`, `2 = 8px`, `4 = 16px`, etc.
|
|
416
|
-
|
|
417
|
-
```
|
|
418
|
-
card p=4 m=2 { } // padding: 16px, margin: 8px
|
|
419
|
-
button mt=4 mb=2 // margin-top: 16px, margin-bottom: 8px
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
### Size
|
|
423
|
-
|
|
424
|
-
```
|
|
425
|
-
image w=400 h=300 // width: 400px, height: 300px
|
|
426
|
-
card w=full // width: 100%
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
### Comments
|
|
430
|
-
|
|
431
|
-
```
|
|
432
|
-
// Single line comment
|
|
433
|
-
|
|
434
|
-
/* Multi-line
|
|
435
|
-
comment */
|
|
436
|
-
|
|
437
|
-
page {
|
|
438
|
-
// Comment inside block
|
|
439
|
-
text "Hello"
|
|
440
|
-
}
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
## Error Handling
|
|
444
|
-
|
|
445
|
-
```typescript
|
|
446
|
-
import { parse } from '@wireweave/core'
|
|
447
|
-
|
|
448
|
-
try {
|
|
449
|
-
const doc = parse('page { invalid }')
|
|
450
|
-
} catch (error) {
|
|
451
|
-
if (error.name === 'ParseError') {
|
|
452
|
-
console.log(error.message)
|
|
453
|
-
// "Syntax error at line 1, column 8: ..."
|
|
454
|
-
console.log(error.location)
|
|
455
|
-
// { start: { line: 1, column: 8 }, end: { ... } }
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
## Browser Support
|
|
461
|
-
|
|
462
|
-
The core library works in both Node.js and browser environments. For browser usage:
|
|
463
|
-
|
|
464
|
-
```html
|
|
465
|
-
<script type="module">
|
|
466
|
-
import { parse, render } from '@wireweave/core'
|
|
467
|
-
|
|
468
|
-
const doc = parse('page { text "Hello" }')
|
|
469
|
-
const { html, css } = render(doc)
|
|
470
|
-
|
|
471
|
-
document.body.innerHTML = `<style>${css}</style>${html}`
|
|
472
|
-
</script>
|
|
473
|
-
```
|
|
136
|
+
Part of the [Wireweave monorepo](https://github.com/wireweave/wireweave).
|
|
474
137
|
|
|
475
138
|
## License
|
|
476
139
|
|