dynim-core 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.
Files changed (86) hide show
  1. package/README.md +290 -0
  2. package/dist/builder/ai-prompt-popover.d.ts +26 -0
  3. package/dist/builder/ai-prompt-popover.d.ts.map +1 -0
  4. package/dist/builder/ai-prompt-popover.js +180 -0
  5. package/dist/builder/builder-client.d.ts +48 -0
  6. package/dist/builder/builder-client.d.ts.map +1 -0
  7. package/dist/builder/builder-client.js +157 -0
  8. package/dist/builder/builder.d.ts +41 -0
  9. package/dist/builder/builder.d.ts.map +1 -0
  10. package/dist/builder/builder.js +537 -0
  11. package/dist/builder/bundle-manager.d.ts +60 -0
  12. package/dist/builder/bundle-manager.d.ts.map +1 -0
  13. package/dist/builder/bundle-manager.js +357 -0
  14. package/dist/builder/classifier/classname-analyzer.d.ts +6 -0
  15. package/dist/builder/classifier/classname-analyzer.d.ts.map +1 -0
  16. package/dist/builder/classifier/classname-analyzer.js +107 -0
  17. package/dist/builder/classifier/index.d.ts +20 -0
  18. package/dist/builder/classifier/index.d.ts.map +1 -0
  19. package/dist/builder/classifier/index.js +181 -0
  20. package/dist/builder/classifier/semantic-analyzer.d.ts +24 -0
  21. package/dist/builder/classifier/semantic-analyzer.d.ts.map +1 -0
  22. package/dist/builder/classifier/semantic-analyzer.js +94 -0
  23. package/dist/builder/classifier/size-analyzer.d.ts +7 -0
  24. package/dist/builder/classifier/size-analyzer.d.ts.map +1 -0
  25. package/dist/builder/classifier/size-analyzer.js +120 -0
  26. package/dist/builder/classifier/visual-analyzer.d.ts +6 -0
  27. package/dist/builder/classifier/visual-analyzer.d.ts.map +1 -0
  28. package/dist/builder/classifier/visual-analyzer.js +158 -0
  29. package/dist/builder/client.d.ts +22 -0
  30. package/dist/builder/client.d.ts.map +1 -0
  31. package/dist/builder/client.js +54 -0
  32. package/dist/builder/code-client.d.ts +101 -0
  33. package/dist/builder/code-client.d.ts.map +1 -0
  34. package/dist/builder/code-client.js +418 -0
  35. package/dist/builder/diff-state.d.ts +24 -0
  36. package/dist/builder/diff-state.d.ts.map +1 -0
  37. package/dist/builder/diff-state.js +134 -0
  38. package/dist/builder/dom-scanner.d.ts +20 -0
  39. package/dist/builder/dom-scanner.d.ts.map +1 -0
  40. package/dist/builder/dom-scanner.js +102 -0
  41. package/dist/builder/drag-engine.d.ts +41 -0
  42. package/dist/builder/drag-engine.d.ts.map +1 -0
  43. package/dist/builder/drag-engine.js +686 -0
  44. package/dist/builder/editor-overlays.d.ts +31 -0
  45. package/dist/builder/editor-overlays.d.ts.map +1 -0
  46. package/dist/builder/editor-overlays.js +202 -0
  47. package/dist/builder/editor-state.d.ts +50 -0
  48. package/dist/builder/editor-state.d.ts.map +1 -0
  49. package/dist/builder/editor-state.js +132 -0
  50. package/dist/builder/element-utils.d.ts +43 -0
  51. package/dist/builder/element-utils.d.ts.map +1 -0
  52. package/dist/builder/element-utils.js +227 -0
  53. package/dist/builder/fiber-capture.d.ts +28 -0
  54. package/dist/builder/fiber-capture.d.ts.map +1 -0
  55. package/dist/builder/fiber-capture.js +264 -0
  56. package/dist/builder/freeze-overlay.d.ts +26 -0
  57. package/dist/builder/freeze-overlay.d.ts.map +1 -0
  58. package/dist/builder/freeze-overlay.js +213 -0
  59. package/dist/builder/history-state.d.ts +41 -0
  60. package/dist/builder/history-state.d.ts.map +1 -0
  61. package/dist/builder/history-state.js +76 -0
  62. package/dist/builder/index.d.ts +62 -0
  63. package/dist/builder/index.d.ts.map +1 -0
  64. package/dist/builder/index.js +92 -0
  65. package/dist/builder/state.d.ts +27 -0
  66. package/dist/builder/state.d.ts.map +1 -0
  67. package/dist/builder/state.js +50 -0
  68. package/dist/builder/style-applier.d.ts +61 -0
  69. package/dist/builder/style-applier.d.ts.map +1 -0
  70. package/dist/builder/style-applier.js +311 -0
  71. package/dist/builder/tree-state.d.ts +71 -0
  72. package/dist/builder/tree-state.d.ts.map +1 -0
  73. package/dist/builder/tree-state.js +168 -0
  74. package/dist/builder/widget.d.ts +29 -0
  75. package/dist/builder/widget.d.ts.map +1 -0
  76. package/dist/builder/widget.js +181 -0
  77. package/dist/index.d.ts +11 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +12 -0
  80. package/package.json +25 -0
  81. package/src/styles/base.css +378 -0
  82. package/src/styles/builder.css +422 -0
  83. package/src/styles/editor.css +131 -0
  84. package/src/styles/themes/dark.css +24 -0
  85. package/src/styles/themes/light.css +21 -0
  86. package/src/styles/variables.css +63 -0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Semantic analyzer - analyzes HTML semantic tags and ARIA roles
3
+ */
4
+ export interface Signal {
5
+ source: string;
6
+ indicator: string;
7
+ weight: number;
8
+ }
9
+ export interface ClassifierInput {
10
+ tagName: string;
11
+ id: string | null;
12
+ className: string;
13
+ computedStyles: Record<string, string> | null;
14
+ rect: {
15
+ width: number;
16
+ height: number;
17
+ } | null;
18
+ parentTagName: string | null;
19
+ childCount: number;
20
+ hasTextContent: boolean;
21
+ attributes: Record<string, string> | null;
22
+ }
23
+ export declare function analyzeSemantics(input: ClassifierInput): Signal[];
24
+ //# sourceMappingURL=semantic-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-analyzer.d.ts","sourceRoot":"","sources":["../../../src/builder/classifier/semantic-analyzer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAC9C,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC/C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC3C;AA2DD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,EAAE,CAwCjE"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Semantic analyzer - analyzes HTML semantic tags and ARIA roles
3
+ */
4
+ const SEMANTIC_TAGS = {
5
+ nav: { indicator: 'nav-tag', weight: 0.9 },
6
+ header: { indicator: 'header-tag', weight: 0.85 },
7
+ footer: { indicator: 'footer-tag', weight: 0.85 },
8
+ main: { indicator: 'container-tag', weight: 0.7 },
9
+ article: { indicator: 'article-tag', weight: 0.8 },
10
+ section: { indicator: 'section-tag', weight: 0.6 },
11
+ aside: { indicator: 'sidebar-tag', weight: 0.75 },
12
+ button: { indicator: 'button-tag', weight: 0.95 },
13
+ form: { indicator: 'form-tag', weight: 0.9 },
14
+ input: { indicator: 'input-tag', weight: 0.9 },
15
+ textarea: { indicator: 'input-tag', weight: 0.9 },
16
+ select: { indicator: 'input-tag', weight: 0.9 },
17
+ ul: { indicator: 'list-tag', weight: 0.7 },
18
+ ol: { indicator: 'list-tag', weight: 0.7 },
19
+ li: { indicator: 'list-item-tag', weight: 0.8 },
20
+ img: { indicator: 'img-tag', weight: 0.95 },
21
+ video: { indicator: 'media-tag', weight: 0.9 },
22
+ audio: { indicator: 'media-tag', weight: 0.9 },
23
+ a: { indicator: 'link-tag', weight: 0.6 },
24
+ p: { indicator: 'text-tag', weight: 0.5 },
25
+ span: { indicator: 'inline-tag', weight: 0.3 },
26
+ h1: { indicator: 'heading-tag', weight: 0.7 },
27
+ h2: { indicator: 'heading-tag', weight: 0.7 },
28
+ h3: { indicator: 'heading-tag', weight: 0.65 },
29
+ h4: { indicator: 'heading-tag', weight: 0.6 },
30
+ h5: { indicator: 'heading-tag', weight: 0.55 },
31
+ h6: { indicator: 'heading-tag', weight: 0.5 },
32
+ dialog: { indicator: 'modal-tag', weight: 0.9 },
33
+ table: { indicator: 'table-tag', weight: 0.8 },
34
+ figure: { indicator: 'figure-tag', weight: 0.7 },
35
+ figcaption: { indicator: 'caption-tag', weight: 0.5 },
36
+ blockquote: { indicator: 'quote-tag', weight: 0.6 },
37
+ code: { indicator: 'code-tag', weight: 0.6 },
38
+ pre: { indicator: 'code-block-tag', weight: 0.7 },
39
+ svg: { indicator: 'svg-tag', weight: 0.8 }
40
+ };
41
+ const ROLE_MAPPING = {
42
+ navigation: { indicator: 'nav-role', weight: 0.85 },
43
+ banner: { indicator: 'header-role', weight: 0.8 },
44
+ contentinfo: { indicator: 'footer-role', weight: 0.8 },
45
+ main: { indicator: 'main-role', weight: 0.7 },
46
+ button: { indicator: 'button-role', weight: 0.9 },
47
+ dialog: { indicator: 'modal-role', weight: 0.85 },
48
+ listbox: { indicator: 'list-role', weight: 0.7 },
49
+ menu: { indicator: 'nav-role', weight: 0.7 },
50
+ menubar: { indicator: 'nav-role', weight: 0.75 },
51
+ tab: { indicator: 'tab-role', weight: 0.7 },
52
+ tablist: { indicator: 'tablist-role', weight: 0.75 },
53
+ tabpanel: { indicator: 'tabpanel-role', weight: 0.7 },
54
+ alert: { indicator: 'alert-role', weight: 0.8 },
55
+ alertdialog: { indicator: 'modal-role', weight: 0.85 },
56
+ tooltip: { indicator: 'tooltip-role', weight: 0.7 },
57
+ search: { indicator: 'search-role', weight: 0.75 }
58
+ };
59
+ export function analyzeSemantics(input) {
60
+ const signals = [];
61
+ const tagLower = input.tagName.toLowerCase();
62
+ if (SEMANTIC_TAGS[tagLower]) {
63
+ const { indicator, weight } = SEMANTIC_TAGS[tagLower];
64
+ signals.push({
65
+ source: 'semantic',
66
+ indicator,
67
+ weight
68
+ });
69
+ }
70
+ const role = input.attributes?.role?.toLowerCase();
71
+ if (role && ROLE_MAPPING[role]) {
72
+ signals.push({
73
+ source: 'semantic',
74
+ indicator: ROLE_MAPPING[role].indicator,
75
+ weight: ROLE_MAPPING[role].weight
76
+ });
77
+ }
78
+ if (input.attributes?.onclick || input.attributes?.href || input.attributes?.type === 'submit') {
79
+ signals.push({
80
+ source: 'semantic',
81
+ indicator: 'interactive-element',
82
+ weight: 0.3
83
+ });
84
+ }
85
+ const dataAttrs = Object.keys(input.attributes || {}).filter(k => k.startsWith('data-'));
86
+ if (dataAttrs.some(attr => attr.includes('component') || attr.includes('testid') || attr.includes('id'))) {
87
+ signals.push({
88
+ source: 'semantic',
89
+ indicator: 'data-component-marker',
90
+ weight: 0.4
91
+ });
92
+ }
93
+ return signals;
94
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Size analyzer - analyzes element dimensions for component classification
3
+ */
4
+ import type { Signal, ClassifierInput } from './semantic-analyzer';
5
+ export declare function setViewportSize(width: number, height: number): void;
6
+ export declare function analyzeSize(input: ClassifierInput): Signal[];
7
+ //# sourceMappingURL=size-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"size-analyzer.d.ts","sourceRoot":"","sources":["../../../src/builder/classifier/size-analyzer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAKnE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAGnE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,EAAE,CAgI5D"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Size analyzer - analyzes element dimensions for component classification
3
+ */
4
+ let viewportWidth = 1920;
5
+ let viewportHeight = 1080;
6
+ export function setViewportSize(width, height) {
7
+ viewportWidth = width;
8
+ viewportHeight = height;
9
+ }
10
+ export function analyzeSize(input) {
11
+ const signals = [];
12
+ const { width, height } = input.rect || { width: 0, height: 0 };
13
+ if (width < 10 || height < 10) {
14
+ signals.push({
15
+ source: 'size',
16
+ indicator: 'tiny-element',
17
+ weight: -0.3
18
+ });
19
+ return signals;
20
+ }
21
+ const aspectRatio = width / height;
22
+ const area = width * height;
23
+ if (width >= 60 && width <= 300 && height >= 28 && height <= 60 && aspectRatio > 1.5) {
24
+ signals.push({
25
+ source: 'size',
26
+ indicator: 'button-size',
27
+ weight: 0.4
28
+ });
29
+ }
30
+ if (width >= 14 && width <= 64 && height >= 14 && height <= 64 && Math.abs(aspectRatio - 1) < 0.3) {
31
+ signals.push({
32
+ source: 'size',
33
+ indicator: 'icon-size',
34
+ weight: 0.5
35
+ });
36
+ }
37
+ if (width >= 32 && width <= 128 && height >= 32 && height <= 128 && Math.abs(aspectRatio - 1) < 0.2) {
38
+ signals.push({
39
+ source: 'size',
40
+ indicator: 'avatar-size',
41
+ weight: 0.4
42
+ });
43
+ }
44
+ if (width >= 200 && width <= 500 && height >= 150 && height <= 600) {
45
+ signals.push({
46
+ source: 'size',
47
+ indicator: 'card-size',
48
+ weight: 0.3
49
+ });
50
+ }
51
+ if (width >= 400 && height >= 100 && height <= 300 && aspectRatio > 2) {
52
+ signals.push({
53
+ source: 'size',
54
+ indicator: 'banner-size',
55
+ weight: 0.3
56
+ });
57
+ }
58
+ if (width >= viewportWidth * 0.9) {
59
+ signals.push({
60
+ source: 'size',
61
+ indicator: 'full-width',
62
+ weight: 0.3
63
+ });
64
+ }
65
+ if (width >= 150 && width <= 400 && height >= viewportHeight * 0.5 && aspectRatio < 0.5) {
66
+ signals.push({
67
+ source: 'size',
68
+ indicator: 'sidebar-size',
69
+ weight: 0.4
70
+ });
71
+ }
72
+ if (width >= viewportWidth * 0.8 && height >= 40 && height <= 150) {
73
+ signals.push({
74
+ source: 'size',
75
+ indicator: 'header-footer-size',
76
+ weight: 0.3
77
+ });
78
+ }
79
+ if (width >= 300 &&
80
+ width <= viewportWidth * 0.8 &&
81
+ height >= 200 &&
82
+ height <= viewportHeight * 0.9 &&
83
+ area >= 100000 &&
84
+ area <= viewportWidth * viewportHeight * 0.7) {
85
+ signals.push({
86
+ source: 'size',
87
+ indicator: 'modal-size',
88
+ weight: 0.25
89
+ });
90
+ }
91
+ if (width < 50 || height < 20) {
92
+ signals.push({
93
+ source: 'size',
94
+ indicator: 'inline-size',
95
+ weight: 0.2
96
+ });
97
+ }
98
+ if (width >= 600 && height >= 400) {
99
+ signals.push({
100
+ source: 'size',
101
+ indicator: 'container-size',
102
+ weight: 0.2
103
+ });
104
+ }
105
+ if (width >= 100 && width <= 500 && height >= 30 && height <= 50) {
106
+ signals.push({
107
+ source: 'size',
108
+ indicator: 'input-size',
109
+ weight: 0.3
110
+ });
111
+ }
112
+ if (width >= 80 && width <= 300 && height >= 30 && height <= 45) {
113
+ signals.push({
114
+ source: 'size',
115
+ indicator: 'dropdown-size',
116
+ weight: 0.25
117
+ });
118
+ }
119
+ return signals;
120
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Visual analyzer - analyzes computed styles for visual characteristics
3
+ */
4
+ import type { Signal, ClassifierInput } from './semantic-analyzer';
5
+ export declare function analyzeVisual(input: ClassifierInput): Signal[];
6
+ //# sourceMappingURL=visual-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visual-analyzer.d.ts","sourceRoot":"","sources":["../../../src/builder/classifier/visual-analyzer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEnE,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,EAAE,CA6J9D"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Visual analyzer - analyzes computed styles for visual characteristics
3
+ */
4
+ export function analyzeVisual(input) {
5
+ const signals = [];
6
+ const styles = input.computedStyles || {};
7
+ const display = styles.display || '';
8
+ if (display === 'flex' || display === 'inline-flex') {
9
+ signals.push({
10
+ source: 'visual',
11
+ indicator: 'flex-display',
12
+ weight: 0.4
13
+ });
14
+ }
15
+ else if (display === 'grid' || display === 'inline-grid') {
16
+ signals.push({
17
+ source: 'visual',
18
+ indicator: 'grid-display',
19
+ weight: 0.4
20
+ });
21
+ }
22
+ else if (display === 'none') {
23
+ signals.push({
24
+ source: 'visual',
25
+ indicator: 'hidden-element',
26
+ weight: -0.5
27
+ });
28
+ }
29
+ const boxShadow = styles.boxShadow || '';
30
+ if (boxShadow && boxShadow !== 'none') {
31
+ signals.push({
32
+ source: 'visual',
33
+ indicator: 'has-shadow',
34
+ weight: 0.5
35
+ });
36
+ }
37
+ const borderRadius = parseFloat(styles.borderRadius || '0') || 0;
38
+ if (borderRadius > 0) {
39
+ signals.push({
40
+ source: 'visual',
41
+ indicator: 'has-border-radius',
42
+ weight: Math.min(borderRadius / 20, 0.4)
43
+ });
44
+ }
45
+ const borderWidth = parseFloat(styles.borderWidth || styles.borderTopWidth || '0') || 0;
46
+ const borderStyle = styles.borderStyle || styles.borderTopStyle || '';
47
+ if (borderWidth > 0 && borderStyle !== 'none') {
48
+ signals.push({
49
+ source: 'visual',
50
+ indicator: 'has-border',
51
+ weight: 0.3
52
+ });
53
+ }
54
+ const bgColor = styles.backgroundColor || '';
55
+ const isTransparent = !bgColor || bgColor === 'transparent' || bgColor === 'rgba(0, 0, 0, 0)';
56
+ if (!isTransparent) {
57
+ signals.push({
58
+ source: 'visual',
59
+ indicator: 'has-distinct-background',
60
+ weight: 0.35
61
+ });
62
+ }
63
+ const bgImage = styles.backgroundImage || '';
64
+ if (bgImage && bgImage !== 'none') {
65
+ signals.push({
66
+ source: 'visual',
67
+ indicator: 'has-background-image',
68
+ weight: 0.4
69
+ });
70
+ }
71
+ const padding = parsePaddingSum(styles);
72
+ if (padding > 20) {
73
+ signals.push({
74
+ source: 'visual',
75
+ indicator: 'has-significant-padding',
76
+ weight: Math.min(padding / 100, 0.4)
77
+ });
78
+ }
79
+ const position = styles.position || '';
80
+ if (position === 'fixed') {
81
+ signals.push({
82
+ source: 'visual',
83
+ indicator: 'fixed-position',
84
+ weight: 0.6
85
+ });
86
+ }
87
+ else if (position === 'absolute') {
88
+ signals.push({
89
+ source: 'visual',
90
+ indicator: 'absolute-position',
91
+ weight: 0.3
92
+ });
93
+ }
94
+ else if (position === 'sticky') {
95
+ signals.push({
96
+ source: 'visual',
97
+ indicator: 'sticky-position',
98
+ weight: 0.5
99
+ });
100
+ }
101
+ const zIndex = parseInt(styles.zIndex || '0') || 0;
102
+ if (zIndex > 100) {
103
+ signals.push({
104
+ source: 'visual',
105
+ indicator: 'high-z-index',
106
+ weight: Math.min(zIndex / 1000, 0.5)
107
+ });
108
+ }
109
+ const overflow = styles.overflow || '';
110
+ const overflowX = styles.overflowX || '';
111
+ const overflowY = styles.overflowY || '';
112
+ if (overflow === 'hidden' || overflowX === 'hidden' || overflowY === 'hidden') {
113
+ signals.push({
114
+ source: 'visual',
115
+ indicator: 'overflow-hidden',
116
+ weight: 0.2
117
+ });
118
+ }
119
+ if (overflow === 'auto' || overflow === 'scroll' || overflowY === 'auto' || overflowY === 'scroll') {
120
+ signals.push({
121
+ source: 'visual',
122
+ indicator: 'scrollable',
123
+ weight: 0.3
124
+ });
125
+ }
126
+ const opacity = parseFloat(styles.opacity || '1');
127
+ if (opacity < 1 && opacity > 0) {
128
+ signals.push({
129
+ source: 'visual',
130
+ indicator: 'has-opacity',
131
+ weight: 0.2
132
+ });
133
+ }
134
+ const transform = styles.transform || '';
135
+ if (transform && transform !== 'none') {
136
+ signals.push({
137
+ source: 'visual',
138
+ indicator: 'has-transform',
139
+ weight: 0.2
140
+ });
141
+ }
142
+ const cursor = styles.cursor || '';
143
+ if (cursor === 'pointer') {
144
+ signals.push({
145
+ source: 'visual',
146
+ indicator: 'pointer-cursor',
147
+ weight: 0.3
148
+ });
149
+ }
150
+ return signals;
151
+ }
152
+ function parsePaddingSum(styles) {
153
+ const paddingTop = parseFloat(styles.paddingTop || '0') || 0;
154
+ const paddingRight = parseFloat(styles.paddingRight || '0') || 0;
155
+ const paddingBottom = parseFloat(styles.paddingBottom || '0') || 0;
156
+ const paddingLeft = parseFloat(styles.paddingLeft || '0') || 0;
157
+ return paddingTop + paddingRight + paddingBottom + paddingLeft;
158
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Streaming client for chatbot
3
+ * Uses SSE (Server-Sent Events) for streaming responses
4
+ */
5
+ export interface ClientConfig {
6
+ apiKey?: string;
7
+ endpoint?: string;
8
+ onMessage?: (data: MessageData) => void;
9
+ onError?: (error: Error) => void;
10
+ }
11
+ export interface MessageData {
12
+ text?: string;
13
+ content?: string;
14
+ done?: boolean;
15
+ error?: boolean;
16
+ type?: string;
17
+ }
18
+ export interface StreamClient {
19
+ send: (message: string) => Promise<void>;
20
+ }
21
+ export declare function createClient(config?: ClientConfig): StreamClient;
22
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/builder/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,wBAAgB,YAAY,CAAC,MAAM,GAAE,YAAiB,GAAG,YAAY,CAyDpE"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Streaming client for chatbot
3
+ * Uses SSE (Server-Sent Events) for streaming responses
4
+ */
5
+ export function createClient(config = {}) {
6
+ const { apiKey, endpoint = '/api/chat', onMessage, onError, } = config;
7
+ async function send(message) {
8
+ try {
9
+ const response = await fetch(endpoint, {
10
+ method: 'POST',
11
+ headers: {
12
+ 'Content-Type': 'application/json',
13
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
14
+ },
15
+ body: JSON.stringify({ message })
16
+ });
17
+ if (!response.ok) {
18
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
19
+ }
20
+ const reader = response.body.getReader();
21
+ const decoder = new TextDecoder();
22
+ let buffer = '';
23
+ while (true) {
24
+ const { done, value } = await reader.read();
25
+ if (done)
26
+ break;
27
+ buffer += decoder.decode(value, { stream: true });
28
+ const lines = buffer.split('\n');
29
+ buffer = lines.pop() || '';
30
+ for (const line of lines) {
31
+ if (line.startsWith('data: ')) {
32
+ const data = line.slice(6);
33
+ if (data === '[DONE]')
34
+ return;
35
+ try {
36
+ const parsed = JSON.parse(data);
37
+ onMessage?.(parsed);
38
+ }
39
+ catch {
40
+ onMessage?.({ text: data });
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ catch (err) {
47
+ onError?.(err);
48
+ throw err;
49
+ }
50
+ }
51
+ return {
52
+ send,
53
+ };
54
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Code Client - Handles communication with the flexcode endpoints via build server
3
+ *
4
+ * Uses:
5
+ * - HTTP POST + SSE for code generation (streaming responses)
6
+ * - HTTP POST for save/abandon operations
7
+ * - HTTP GET for retrieving edits
8
+ * - JWT session tokens for authentication
9
+ *
10
+ * The SDK only talks to the build server (:8080), which forwards
11
+ * code requests to the flexcode service (:8765).
12
+ */
13
+ export interface CodeClientConfig {
14
+ apiBase?: string;
15
+ /** JWT session token for authentication */
16
+ sessionToken?: string;
17
+ /** Refresh token for getting new session tokens */
18
+ refreshToken?: string;
19
+ /** Function to fetch a new session when current one expires */
20
+ getSession?: () => Promise<{
21
+ token: string;
22
+ refreshToken?: string;
23
+ }>;
24
+ /** Called when the structured message updates (recommended) */
25
+ onMessageUpdate?: (message: CodeMessage) => void;
26
+ /** Called for each raw SSE event (for debugging/advanced use) */
27
+ onRawEvent?: (event: CodeEvent) => void;
28
+ /** @deprecated Use onMessageUpdate instead */
29
+ onMessage?: (event: CodeEvent) => void;
30
+ /** Called when an edit is received */
31
+ onEdit?: (edit: CodeEdit) => void;
32
+ /** Called on errors */
33
+ onError?: (error: Error) => void;
34
+ /** Called when streaming starts */
35
+ onStreamStart?: () => void;
36
+ /** Called when streaming ends */
37
+ onStreamEnd?: () => void;
38
+ /** Called when session is refreshed */
39
+ onSessionRefresh?: (token: string) => void;
40
+ /** Called when authentication fails */
41
+ onAuthError?: (error: Error) => void;
42
+ }
43
+ /** Structured message with separate thinking and response content */
44
+ export interface CodeMessage {
45
+ /** Accumulated thinking/reasoning content */
46
+ thinking: string;
47
+ /** Accumulated response text */
48
+ text: string;
49
+ /** Code edits received */
50
+ edits: CodeEdit[];
51
+ /** Current status */
52
+ status: 'idle' | 'streaming' | 'waiting' | 'done' | 'error';
53
+ /** Question if waiting for user input */
54
+ question?: string;
55
+ /** Error message if status is 'error' */
56
+ error?: string;
57
+ /** Session ID */
58
+ sessionId?: string;
59
+ /** Whether the bundle is ready for preview */
60
+ bundleReady?: boolean;
61
+ /** Project ID from bundle_ready event (for bundle loading) */
62
+ projectId?: string;
63
+ /** Error if bundle creation failed */
64
+ bundleError?: string;
65
+ }
66
+ export interface CodeEvent {
67
+ type: 'text' | 'thinking' | 'edit' | 'question' | 'done' | 'error' | 'session_started' | 'keepalive' | 'bundle_ready' | 'bundle_error';
68
+ content?: string;
69
+ edit?: CodeEdit;
70
+ session_id?: string;
71
+ project_id?: string;
72
+ }
73
+ export interface CodeEdit {
74
+ file_path: string;
75
+ type: 'create' | 'replace' | 'delete';
76
+ old_content?: string;
77
+ new_content?: string;
78
+ sequence: number;
79
+ }
80
+ export interface CodeClient {
81
+ /** Send a code generation request (streams via SSE) - projectId comes from JWT */
82
+ sendCode: (query: string) => Promise<void>;
83
+ /** Save pending edits (commit temp changes) - projectId comes from JWT */
84
+ saveCode: () => Promise<void>;
85
+ /** Abandon pending edits (discard temp changes) - projectId comes from JWT */
86
+ abandonCode: () => Promise<void>;
87
+ /** Get list of current edits - projectId comes from JWT */
88
+ getEdits: () => Promise<CodeEdit[]>;
89
+ /** Pre-warm the file cache for faster code requests - projectId comes from JWT */
90
+ warmCache: () => Promise<void>;
91
+ /** Set/update the session token */
92
+ setSessionToken: (token: string, refreshToken?: string) => void;
93
+ /** Check if authenticated */
94
+ isAuthenticated: () => boolean;
95
+ /** Get current message state */
96
+ getMessage: () => CodeMessage;
97
+ /** Reset message state */
98
+ resetMessage: () => void;
99
+ }
100
+ export declare function createCodeClient(config?: CodeClientConfig): CodeClient;
101
+ //# sourceMappingURL=code-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-client.d.ts","sourceRoot":"","sources":["../../src/builder/code-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,+DAA+D;IAC/D,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACjD,iEAAiE;IACjE,UAAU,CAAC,E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