@wireweave/core 1.0.0-beta.20260107130355

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.
Files changed (43) hide show
  1. package/README.md +351 -0
  2. package/dist/index.cjs +56106 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +252 -0
  5. package/dist/index.d.ts +252 -0
  6. package/dist/index.js +55985 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/parser.cjs +5417 -0
  9. package/dist/parser.cjs.map +1 -0
  10. package/dist/parser.d.cts +89 -0
  11. package/dist/parser.d.ts +89 -0
  12. package/dist/parser.js +5387 -0
  13. package/dist/parser.js.map +1 -0
  14. package/dist/renderer.cjs +50244 -0
  15. package/dist/renderer.cjs.map +1 -0
  16. package/dist/renderer.d.cts +497 -0
  17. package/dist/renderer.d.ts +497 -0
  18. package/dist/renderer.js +50202 -0
  19. package/dist/renderer.js.map +1 -0
  20. package/dist/types-DtovIYS6.d.cts +419 -0
  21. package/dist/types-DtovIYS6.d.ts +419 -0
  22. package/package.json +59 -0
  23. package/src/ast/guards.ts +361 -0
  24. package/src/ast/index.ts +9 -0
  25. package/src/ast/types.ts +661 -0
  26. package/src/ast/utils.ts +238 -0
  27. package/src/grammar/wireframe.peggy +677 -0
  28. package/src/icons/lucide-icons.ts +46422 -0
  29. package/src/index.ts +20 -0
  30. package/src/parser/generated-parser.js +5199 -0
  31. package/src/parser/index.ts +214 -0
  32. package/src/renderer/html/base.ts +186 -0
  33. package/src/renderer/html/components.ts +1092 -0
  34. package/src/renderer/html/index.ts +1608 -0
  35. package/src/renderer/html/layout.ts +392 -0
  36. package/src/renderer/index.ts +143 -0
  37. package/src/renderer/styles-components.ts +1232 -0
  38. package/src/renderer/styles.ts +382 -0
  39. package/src/renderer/svg/index.ts +1050 -0
  40. package/src/renderer/types.ts +173 -0
  41. package/src/types/index.ts +138 -0
  42. package/src/viewport/index.ts +17 -0
  43. package/src/viewport/presets.ts +181 -0
@@ -0,0 +1,497 @@
1
+ import { a1 as WireframeDocument, A as AnyNode, P as PageNode } from './types-DtovIYS6.cjs';
2
+
3
+ /**
4
+ * Renderer type definitions for wireweave
5
+ *
6
+ * Provides types for rendering options, themes, and context
7
+ */
8
+ interface RenderOptions {
9
+ /** Theme variant */
10
+ theme?: 'light' | 'dark';
11
+ /** Scale factor for sizing */
12
+ scale?: number;
13
+ /** Include CSS styles in output */
14
+ includeStyles?: boolean;
15
+ /** Minify output (no indentation/newlines) */
16
+ minify?: boolean;
17
+ /** CSS class prefix for scoping */
18
+ classPrefix?: string;
19
+ }
20
+ interface RenderResult {
21
+ /** Rendered HTML content */
22
+ html: string;
23
+ /** Generated CSS styles */
24
+ css: string;
25
+ }
26
+ interface SvgRenderOptions {
27
+ /** Width of the SVG viewport */
28
+ width?: number;
29
+ /** Height of the SVG viewport */
30
+ height?: number;
31
+ /** Padding around content */
32
+ padding?: number;
33
+ /** Scale factor */
34
+ scale?: number;
35
+ /** Background color */
36
+ background?: string;
37
+ /** Font family */
38
+ fontFamily?: string;
39
+ }
40
+ interface SvgRenderResult {
41
+ /** Rendered SVG content */
42
+ svg: string;
43
+ /** Actual width */
44
+ width: number;
45
+ /** Actual height */
46
+ height: number;
47
+ }
48
+ interface RenderContext {
49
+ /** Resolved render options */
50
+ options: Required<RenderOptions>;
51
+ /** Theme configuration */
52
+ theme: ThemeConfig;
53
+ /** Current nesting depth for indentation */
54
+ depth: number;
55
+ }
56
+ interface ThemeColors {
57
+ /** Primary action color */
58
+ primary: string;
59
+ /** Secondary/muted action color */
60
+ secondary: string;
61
+ /** Success state color */
62
+ success: string;
63
+ /** Warning state color */
64
+ warning: string;
65
+ /** Danger/error state color */
66
+ danger: string;
67
+ /** Muted/disabled color */
68
+ muted: string;
69
+ /** Background color */
70
+ background: string;
71
+ /** Foreground/text color */
72
+ foreground: string;
73
+ /** Border color */
74
+ border: string;
75
+ }
76
+ interface ThemeConfig {
77
+ /** Color palette */
78
+ colors: ThemeColors;
79
+ /** Spacing scale (number -> px value) */
80
+ spacing: Record<number, string>;
81
+ /** Border radius */
82
+ radius: string;
83
+ /** Font family */
84
+ fontFamily: string;
85
+ /** Shadow styles */
86
+ shadows: Record<string, string>;
87
+ }
88
+ /**
89
+ * Default wireframe theme using black/white/gray palette
90
+ * Follows wireweave design principles for sketch-like appearance
91
+ */
92
+ declare const defaultTheme: ThemeConfig;
93
+ /**
94
+ * Dark theme configuration
95
+ * Inverts colors for dark mode display
96
+ */
97
+ declare const darkTheme: ThemeConfig;
98
+ /**
99
+ * Get theme configuration by name
100
+ */
101
+ declare function getTheme(name: 'light' | 'dark'): ThemeConfig;
102
+
103
+ /**
104
+ * Base HTML Renderer for wireweave
105
+ *
106
+ * Provides abstract base class for HTML rendering with theme support
107
+ */
108
+
109
+ /**
110
+ * Abstract base renderer class
111
+ *
112
+ * Provides core infrastructure for HTML rendering:
113
+ * - Theme management
114
+ * - Indentation and formatting
115
+ * - Depth tracking for nested elements
116
+ */
117
+ declare abstract class BaseRenderer {
118
+ protected context: RenderContext;
119
+ constructor(options?: RenderOptions);
120
+ /**
121
+ * Build theme configuration based on options
122
+ */
123
+ protected buildTheme(options: Required<RenderOptions>): ThemeConfig;
124
+ /**
125
+ * Render a wireframe document to HTML and CSS
126
+ */
127
+ render(document: WireframeDocument): RenderResult;
128
+ /**
129
+ * Render a complete wireframe document
130
+ */
131
+ protected renderDocument(document: WireframeDocument): string;
132
+ /**
133
+ * Render a page node (to be implemented by subclasses)
134
+ */
135
+ protected abstract renderPage(node: AnyNode): string;
136
+ /**
137
+ * Render any AST node (to be implemented by subclasses)
138
+ */
139
+ protected abstract renderNode(node: AnyNode): string;
140
+ /**
141
+ * Get the CSS class prefix
142
+ */
143
+ protected get prefix(): string;
144
+ /**
145
+ * Add indentation based on current depth
146
+ */
147
+ protected indent(content: string): string;
148
+ /**
149
+ * Execute a function with increased depth
150
+ */
151
+ protected withDepth<T>(fn: () => T): T;
152
+ /**
153
+ * Escape HTML special characters
154
+ */
155
+ protected escapeHtml(text: string): string;
156
+ /**
157
+ * Build a CSS class string from an array of class names
158
+ */
159
+ protected buildClassString(classes: (string | undefined | false)[]): string;
160
+ /**
161
+ * Build HTML attributes string
162
+ */
163
+ protected buildAttrsString(attrs: Record<string, string | undefined | boolean>): string;
164
+ /**
165
+ * Simple HTML minification
166
+ */
167
+ private minifyHtml;
168
+ /**
169
+ * Simple CSS minification
170
+ */
171
+ private minifyCss;
172
+ }
173
+
174
+ /**
175
+ * HTML Renderer for wireweave
176
+ *
177
+ * Converts AST nodes to HTML output
178
+ */
179
+
180
+ /**
181
+ * HTML Renderer class
182
+ *
183
+ * Renders wireframe AST to semantic HTML with utility classes
184
+ */
185
+ declare class HtmlRenderer extends BaseRenderer {
186
+ constructor(options?: RenderOptions);
187
+ /**
188
+ * Render a page node
189
+ */
190
+ protected renderPage(node: PageNode): string;
191
+ /**
192
+ * Render any AST node
193
+ */
194
+ protected renderNode(node: AnyNode): string;
195
+ /**
196
+ * Render children nodes
197
+ */
198
+ protected renderChildren(children: AnyNode[]): string;
199
+ /**
200
+ * Get common CSS classes from props
201
+ * Uses Omit to exclude 'align' since TextNode/TitleNode have incompatible align types
202
+ *
203
+ * All numeric values are handled by buildCommonStyles as inline px values.
204
+ * CSS classes are only used for keyword values (full, auto, screen, fit, etc.)
205
+ */
206
+ private getCommonClasses;
207
+ private renderHeader;
208
+ private renderMain;
209
+ private renderFooter;
210
+ private renderSidebar;
211
+ private renderSection;
212
+ private renderRow;
213
+ private renderCol;
214
+ /**
215
+ * Build common inline styles for all values
216
+ *
217
+ * Spacing values (p, m, gap) use token system:
218
+ * - number: spacing token (e.g., p=4 → padding: 16px from token table)
219
+ * - ValueWithUnit: direct CSS value (e.g., p=16px → padding: 16px)
220
+ *
221
+ * Size values (w, h, minW, maxW, minH, maxH) use direct px:
222
+ * - number: direct px value (e.g., w=400 → width: 400px)
223
+ * - ValueWithUnit: direct CSS value (e.g., w=50% → width: 50%)
224
+ *
225
+ * Token table: 0=0px, 1=4px, 2=8px, 3=12px, 4=16px, 5=20px, 6=24px, 8=32px, etc.
226
+ *
227
+ * Uses Omit to exclude 'align' since TextNode/TitleNode have incompatible align types
228
+ */
229
+ private buildCommonStyles;
230
+ /**
231
+ * Build inline styles for Col node (extends common styles with order)
232
+ */
233
+ private buildColStyles;
234
+ private renderCard;
235
+ private renderModal;
236
+ private renderDrawer;
237
+ private renderAccordion;
238
+ private renderText;
239
+ private renderTitle;
240
+ private renderLink;
241
+ private renderInput;
242
+ private renderTextarea;
243
+ private renderSelect;
244
+ private renderCheckbox;
245
+ private renderRadio;
246
+ private renderSwitch;
247
+ private renderSlider;
248
+ private renderButton;
249
+ private renderImage;
250
+ private renderPlaceholder;
251
+ private renderAvatar;
252
+ private renderBadge;
253
+ private renderIcon;
254
+ private renderTable;
255
+ private renderList;
256
+ private renderAlert;
257
+ private renderToast;
258
+ private renderProgress;
259
+ private renderSpinner;
260
+ private renderTooltip;
261
+ private renderPopover;
262
+ private renderDropdown;
263
+ private renderNav;
264
+ private renderTabs;
265
+ private renderBreadcrumb;
266
+ private renderDivider;
267
+ /**
268
+ * Parse and render semantic markers in text content
269
+ *
270
+ * Semantic markers use the syntax [component:variant] to indicate
271
+ * what a visual element represents. This helps LLMs understand
272
+ * the meaning of placeholder content.
273
+ *
274
+ * Supported markers:
275
+ * - [avatar] or [avatar:size] - User avatar (renders as circle placeholder)
276
+ * - [badge:variant] TEXT - Status badge (TEXT is displayed inside the badge)
277
+ * - [dot:variant] - Status dot (renders as small circle before text)
278
+ * - [icon:name] - Icon placeholder
279
+ *
280
+ * Examples:
281
+ * - "[avatar] John Doe" → renders avatar circle + "John Doe"
282
+ * - "[badge:primary] PRO" → renders badge containing "PRO"
283
+ * - "[dot:success] Active" → renders green dot + "Active"
284
+ */
285
+ private renderSemanticMarkers;
286
+ /**
287
+ * Render a single semantic marker to HTML (without content)
288
+ */
289
+ private renderSemanticMarker;
290
+ /**
291
+ * Render a semantic marker with text content (for badge)
292
+ */
293
+ private renderSemanticMarkerWithContent;
294
+ /**
295
+ * Process table cell content with semantic markers and newlines
296
+ *
297
+ * Special handling for avatar + text layout:
298
+ * When content starts with [avatar], wraps in flex container
299
+ * so avatar and text align horizontally, with text stacking vertically
300
+ */
301
+ private renderTableCellContent;
302
+ }
303
+ /**
304
+ * Create a new HTML renderer instance
305
+ */
306
+ declare function createHtmlRenderer(options?: RenderOptions): HtmlRenderer;
307
+
308
+ /**
309
+ * SVG Renderer for wireweave
310
+ *
311
+ * Renders wireframe AST to SVG image format
312
+ */
313
+
314
+ /**
315
+ * SVG Renderer class
316
+ *
317
+ * Renders wireframe AST nodes to SVG elements
318
+ */
319
+ declare class SvgRenderer {
320
+ private options;
321
+ private theme;
322
+ private currentX;
323
+ private currentY;
324
+ private contentWidth;
325
+ constructor(options?: SvgRenderOptions);
326
+ /**
327
+ * Render a wireframe document to SVG
328
+ */
329
+ render(doc: WireframeDocument): SvgRenderResult;
330
+ /**
331
+ * Generate SVG defs (styles, patterns, etc.)
332
+ */
333
+ private generateDefs;
334
+ /**
335
+ * Render a page node
336
+ */
337
+ private renderPage;
338
+ /**
339
+ * Render page title
340
+ */
341
+ private renderPageTitle;
342
+ /**
343
+ * Render any AST node
344
+ */
345
+ private renderNode;
346
+ private renderRow;
347
+ private renderCol;
348
+ private renderHeader;
349
+ private renderMain;
350
+ private renderFooter;
351
+ private renderSidebar;
352
+ private renderCard;
353
+ private renderModal;
354
+ private renderText;
355
+ private renderTitle;
356
+ private renderLink;
357
+ private renderInput;
358
+ private renderTextarea;
359
+ private renderSelect;
360
+ private renderCheckbox;
361
+ private renderRadio;
362
+ private renderSwitch;
363
+ private renderButton;
364
+ /**
365
+ * Render icon paths for SVG
366
+ */
367
+ private renderIconPaths;
368
+ private renderImage;
369
+ private renderPlaceholder;
370
+ private renderAvatar;
371
+ private renderBadge;
372
+ private renderTable;
373
+ private renderList;
374
+ private renderAlert;
375
+ private renderProgress;
376
+ private renderSpinner;
377
+ private renderNav;
378
+ private renderTabs;
379
+ private renderBreadcrumb;
380
+ private getFontSize;
381
+ private resolveFontSize;
382
+ private getTitleFontSize;
383
+ private escapeXml;
384
+ }
385
+ /**
386
+ * Create a new SVG renderer instance
387
+ */
388
+ declare function createSvgRenderer(options?: SvgRenderOptions): SvgRenderer;
389
+
390
+ /**
391
+ * CSS Style Generator for wireweave
392
+ *
393
+ * Generates CSS classes for grid, spacing, and flex utilities
394
+ */
395
+
396
+ /**
397
+ * Generate all CSS styles for wireframe rendering
398
+ *
399
+ * @param theme - Theme configuration
400
+ * @param prefix - CSS class prefix (default: 'wf')
401
+ * @returns Complete CSS string
402
+ */
403
+ declare function generateStyles(theme: ThemeConfig, prefix?: string): string;
404
+
405
+ /**
406
+ * Component-specific CSS styles for wireweave
407
+ *
408
+ * Detailed styles for all UI components with:
409
+ * - Wireframe aesthetic (black/white/gray)
410
+ * - Accessibility considerations
411
+ * - Responsive design
412
+ */
413
+
414
+ /**
415
+ * Generate all component-specific CSS styles
416
+ */
417
+ declare function generateComponentStyles(_theme: ThemeConfig, prefix?: string): string;
418
+
419
+ /**
420
+ * Lucide Icons Data
421
+ *
422
+ * Auto-generated from lucide package.
423
+ * Do not edit manually.
424
+ *
425
+ * Total icons: 1666
426
+ *
427
+ * @license ISC License
428
+ *
429
+ * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2023
430
+ * as part of Feather (MIT). All other copyright (c) for Lucide are held
431
+ * by Lucide Contributors 2025.
432
+ *
433
+ * Permission to use, copy, modify, and/or distribute this software for any
434
+ * purpose with or without fee is hereby granted, provided that the above
435
+ * copyright notice and this permission notice appear in all copies.
436
+ *
437
+ * @see https://lucide.dev
438
+ */
439
+ type IconElement = [string, Record<string, string>];
440
+ type IconData = IconElement[];
441
+ declare const lucideIcons: Record<string, IconData>;
442
+ /**
443
+ * Get icon data by name
444
+ */
445
+ declare function getIconData(name: string): IconData | undefined;
446
+ /**
447
+ * Render icon data to SVG string
448
+ */
449
+ declare function renderIconSvg(data: IconData, _size?: number, // size is now controlled by CSS, this param is kept for API compatibility
450
+ strokeWidth?: number, className?: string, styleAttr?: string): string;
451
+
452
+ /**
453
+ * Renderer module for wireweave
454
+ *
455
+ * Provides render functions to convert AST to HTML/CSS and SVG
456
+ */
457
+
458
+ /**
459
+ * Render AST to HTML and CSS
460
+ *
461
+ * @param document - Parsed wireframe document
462
+ * @param options - Render options
463
+ * @returns Object containing HTML and CSS strings
464
+ */
465
+ declare function render(document: WireframeDocument, options?: RenderOptions): RenderResult;
466
+ /**
467
+ * Render AST to standalone HTML with embedded CSS
468
+ *
469
+ * @param document - Parsed wireframe document
470
+ * @param options - Render options
471
+ * @returns Complete HTML document string
472
+ */
473
+ declare function renderToHtml(document: WireframeDocument, options?: RenderOptions): string;
474
+ /**
475
+ * Render AST to SVG using foreignObject with HTML+CSS
476
+ *
477
+ * This approach embeds HTML+CSS inside SVG using foreignObject,
478
+ * which allows CSS flexbox/grid layouts to work properly.
479
+ *
480
+ * @param document - Parsed wireframe document
481
+ * @param options - SVG render options
482
+ * @returns Object containing SVG string and dimensions
483
+ */
484
+ declare function renderToSvg(document: WireframeDocument, options?: SvgRenderOptions): SvgRenderResult;
485
+ /**
486
+ * Render AST to pure SVG (without foreignObject)
487
+ *
488
+ * This uses the original SVG renderer with manual layout calculations.
489
+ * Use this when foreignObject is not supported.
490
+ *
491
+ * @param document - Parsed wireframe document
492
+ * @param options - SVG render options
493
+ * @returns Object containing SVG string and dimensions
494
+ */
495
+ declare function renderToPureSvg(document: WireframeDocument, options?: SvgRenderOptions): SvgRenderResult;
496
+
497
+ export { HtmlRenderer, type IconData, type IconElement, type RenderContext, type RenderOptions, type RenderResult, type SvgRenderOptions, type SvgRenderResult, SvgRenderer, type ThemeColors, type ThemeConfig, createHtmlRenderer, createSvgRenderer, darkTheme, defaultTheme, generateComponentStyles, generateStyles, getIconData, getTheme, lucideIcons, render, renderIconSvg, renderToHtml, renderToPureSvg, renderToSvg };