@mandujs/core 0.9.41 → 0.9.42

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 (67) hide show
  1. package/package.json +1 -1
  2. package/src/bundler/build.ts +91 -73
  3. package/src/bundler/dev.ts +21 -14
  4. package/src/client/globals.ts +44 -0
  5. package/src/client/index.ts +5 -4
  6. package/src/client/island.ts +8 -13
  7. package/src/client/router.ts +33 -41
  8. package/src/client/runtime.ts +23 -51
  9. package/src/client/window-state.ts +101 -0
  10. package/src/config/index.ts +1 -0
  11. package/src/config/mandu.ts +45 -9
  12. package/src/config/validate.ts +158 -0
  13. package/src/constants.ts +25 -0
  14. package/src/contract/client.ts +4 -3
  15. package/src/contract/define.ts +459 -0
  16. package/src/devtools/ai/context-builder.ts +375 -0
  17. package/src/devtools/ai/index.ts +25 -0
  18. package/src/devtools/ai/mcp-connector.ts +465 -0
  19. package/src/devtools/client/catchers/error-catcher.ts +327 -0
  20. package/src/devtools/client/catchers/index.ts +18 -0
  21. package/src/devtools/client/catchers/network-proxy.ts +363 -0
  22. package/src/devtools/client/components/index.ts +39 -0
  23. package/src/devtools/client/components/kitchen-root.tsx +362 -0
  24. package/src/devtools/client/components/mandu-character.tsx +241 -0
  25. package/src/devtools/client/components/overlay.tsx +368 -0
  26. package/src/devtools/client/components/panel/errors-panel.tsx +259 -0
  27. package/src/devtools/client/components/panel/guard-panel.tsx +244 -0
  28. package/src/devtools/client/components/panel/index.ts +32 -0
  29. package/src/devtools/client/components/panel/islands-panel.tsx +304 -0
  30. package/src/devtools/client/components/panel/network-panel.tsx +292 -0
  31. package/src/devtools/client/components/panel/panel-container.tsx +259 -0
  32. package/src/devtools/client/filters/context-filters.ts +282 -0
  33. package/src/devtools/client/filters/index.ts +16 -0
  34. package/src/devtools/client/index.ts +63 -0
  35. package/src/devtools/client/persistence.ts +335 -0
  36. package/src/devtools/client/state-manager.ts +478 -0
  37. package/src/devtools/design-tokens.ts +263 -0
  38. package/src/devtools/hook/create-hook.ts +207 -0
  39. package/src/devtools/hook/index.ts +13 -0
  40. package/src/devtools/index.ts +439 -0
  41. package/src/devtools/init.ts +266 -0
  42. package/src/devtools/protocol.ts +237 -0
  43. package/src/devtools/server/index.ts +17 -0
  44. package/src/devtools/server/source-context.ts +444 -0
  45. package/src/devtools/types.ts +319 -0
  46. package/src/devtools/worker/index.ts +25 -0
  47. package/src/devtools/worker/redaction-worker.ts +222 -0
  48. package/src/devtools/worker/worker-manager.ts +409 -0
  49. package/src/error/formatter.ts +28 -24
  50. package/src/error/index.ts +13 -9
  51. package/src/error/result.ts +46 -0
  52. package/src/error/types.ts +6 -4
  53. package/src/filling/filling.ts +6 -5
  54. package/src/guard/check.ts +60 -56
  55. package/src/guard/types.ts +3 -1
  56. package/src/guard/watcher.ts +10 -1
  57. package/src/index.ts +81 -0
  58. package/src/intent/index.ts +310 -0
  59. package/src/island/index.ts +304 -0
  60. package/src/router/fs-patterns.ts +7 -0
  61. package/src/router/fs-routes.ts +20 -8
  62. package/src/router/fs-scanner.ts +117 -133
  63. package/src/runtime/server.ts +261 -201
  64. package/src/runtime/ssr.ts +5 -4
  65. package/src/runtime/streaming-ssr.ts +5 -4
  66. package/src/utils/bun.ts +8 -0
  67. package/src/utils/lru-cache.ts +75 -0
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Mandu Kitchen DevTools - Design Tokens
3
+ * @version 1.0.3
4
+ */
5
+
6
+ // ============================================================================
7
+ // Color Tokens
8
+ // ============================================================================
9
+
10
+ export const colors = {
11
+ brand: {
12
+ primary: '#F5E6D3', // 만두피 베이지
13
+ secondary: '#8B4513', // 구운 갈색
14
+ accent: '#E8967A', // 새우 만두 분홍
15
+ },
16
+ semantic: {
17
+ success: '#90EE90',
18
+ warning: '#FFD700',
19
+ error: '#FF6B6B',
20
+ info: '#87CEEB',
21
+ },
22
+ background: {
23
+ dark: '#1A1A2E',
24
+ medium: '#2D2D44',
25
+ light: '#3D3D5C',
26
+ overlay: 'rgba(0, 0, 0, 0.85)',
27
+ },
28
+ text: {
29
+ primary: '#FFFFFF',
30
+ secondary: '#B0B0B0',
31
+ muted: '#707070',
32
+ },
33
+ } as const;
34
+
35
+ // ============================================================================
36
+ // Typography Tokens
37
+ // ============================================================================
38
+
39
+ export const typography = {
40
+ fontFamily: {
41
+ mono: "'JetBrains Mono', 'Fira Code', 'Consolas', monospace",
42
+ sans: "'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
43
+ },
44
+ fontSize: {
45
+ xs: '10px',
46
+ sm: '12px',
47
+ md: '14px',
48
+ lg: '16px',
49
+ xl: '20px',
50
+ '2xl': '24px',
51
+ },
52
+ fontWeight: {
53
+ normal: 400,
54
+ medium: 500,
55
+ semibold: 600,
56
+ bold: 700,
57
+ },
58
+ lineHeight: {
59
+ tight: 1.25,
60
+ normal: 1.5,
61
+ relaxed: 1.75,
62
+ },
63
+ } as const;
64
+
65
+ // ============================================================================
66
+ // Spacing Tokens
67
+ // ============================================================================
68
+
69
+ export const spacing = {
70
+ xs: '4px',
71
+ sm: '8px',
72
+ md: '12px',
73
+ lg: '16px',
74
+ xl: '24px',
75
+ '2xl': '32px',
76
+ '3xl': '48px',
77
+ } as const;
78
+
79
+ // ============================================================================
80
+ // Border Tokens
81
+ // ============================================================================
82
+
83
+ export const borderRadius = {
84
+ sm: '4px',
85
+ md: '8px',
86
+ lg: '12px',
87
+ xl: '16px',
88
+ full: '9999px',
89
+ } as const;
90
+
91
+ export const borderWidth = {
92
+ thin: '1px',
93
+ medium: '2px',
94
+ thick: '4px',
95
+ } as const;
96
+
97
+ // ============================================================================
98
+ // Shadow Tokens
99
+ // ============================================================================
100
+
101
+ export const shadows = {
102
+ sm: '0 1px 2px rgba(0, 0, 0, 0.1)',
103
+ md: '0 4px 6px rgba(0, 0, 0, 0.15)',
104
+ lg: '0 10px 15px rgba(0, 0, 0, 0.2)',
105
+ xl: '0 20px 25px rgba(0, 0, 0, 0.25)',
106
+ overlay: '0 25px 50px rgba(0, 0, 0, 0.5)',
107
+ } as const;
108
+
109
+ // ============================================================================
110
+ // Animation Tokens
111
+ // ============================================================================
112
+
113
+ export const animation = {
114
+ duration: {
115
+ fast: '150ms',
116
+ normal: '300ms',
117
+ slow: '500ms',
118
+ },
119
+ easing: {
120
+ ease: 'ease',
121
+ easeIn: 'ease-in',
122
+ easeOut: 'ease-out',
123
+ easeInOut: 'ease-in-out',
124
+ spring: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)',
125
+ },
126
+ } as const;
127
+
128
+ // ============================================================================
129
+ // Z-Index Tokens
130
+ // ============================================================================
131
+
132
+ export const zIndex = {
133
+ base: 0,
134
+ dropdown: 1000,
135
+ sticky: 1020,
136
+ fixed: 1030,
137
+ modalBackdrop: 1040,
138
+ modal: 1050,
139
+ popover: 1060,
140
+ tooltip: 1070,
141
+ devtools: 2147483640, // 최상위 (max safe - 7)
142
+ overlay: 2147483647, // 가장 높음 (max safe)
143
+ } as const;
144
+
145
+ // ============================================================================
146
+ // Breakpoints
147
+ // ============================================================================
148
+
149
+ export const breakpoints = {
150
+ sm: '640px',
151
+ md: '768px',
152
+ lg: '1024px',
153
+ xl: '1280px',
154
+ '2xl': '1536px',
155
+ } as const;
156
+
157
+ // ============================================================================
158
+ // Combined Design Tokens
159
+ // ============================================================================
160
+
161
+ export const ManduDesignTokens = {
162
+ colors,
163
+ typography,
164
+ spacing,
165
+ borderRadius,
166
+ borderWidth,
167
+ shadows,
168
+ animation,
169
+ zIndex,
170
+ breakpoints,
171
+ } as const;
172
+
173
+ export type ManduDesignTokens = typeof ManduDesignTokens;
174
+
175
+ // ============================================================================
176
+ // CSS Variables Generator
177
+ // ============================================================================
178
+
179
+ export function generateCSSVariables(): string {
180
+ return `
181
+ :host {
182
+ /* Colors - Brand */
183
+ --mk-color-brand-primary: ${colors.brand.primary};
184
+ --mk-color-brand-secondary: ${colors.brand.secondary};
185
+ --mk-color-brand-accent: ${colors.brand.accent};
186
+
187
+ /* Colors - Semantic */
188
+ --mk-color-success: ${colors.semantic.success};
189
+ --mk-color-warning: ${colors.semantic.warning};
190
+ --mk-color-error: ${colors.semantic.error};
191
+ --mk-color-info: ${colors.semantic.info};
192
+
193
+ /* Colors - Background */
194
+ --mk-color-bg-dark: ${colors.background.dark};
195
+ --mk-color-bg-medium: ${colors.background.medium};
196
+ --mk-color-bg-light: ${colors.background.light};
197
+ --mk-color-bg-overlay: ${colors.background.overlay};
198
+
199
+ /* Colors - Text */
200
+ --mk-color-text-primary: ${colors.text.primary};
201
+ --mk-color-text-secondary: ${colors.text.secondary};
202
+ --mk-color-text-muted: ${colors.text.muted};
203
+
204
+ /* Typography */
205
+ --mk-font-mono: ${typography.fontFamily.mono};
206
+ --mk-font-sans: ${typography.fontFamily.sans};
207
+ --mk-font-size-xs: ${typography.fontSize.xs};
208
+ --mk-font-size-sm: ${typography.fontSize.sm};
209
+ --mk-font-size-md: ${typography.fontSize.md};
210
+ --mk-font-size-lg: ${typography.fontSize.lg};
211
+ --mk-font-size-xl: ${typography.fontSize.xl};
212
+
213
+ /* Spacing */
214
+ --mk-space-xs: ${spacing.xs};
215
+ --mk-space-sm: ${spacing.sm};
216
+ --mk-space-md: ${spacing.md};
217
+ --mk-space-lg: ${spacing.lg};
218
+ --mk-space-xl: ${spacing.xl};
219
+
220
+ /* Border Radius */
221
+ --mk-radius-sm: ${borderRadius.sm};
222
+ --mk-radius-md: ${borderRadius.md};
223
+ --mk-radius-lg: ${borderRadius.lg};
224
+ --mk-radius-full: ${borderRadius.full};
225
+
226
+ /* Shadows */
227
+ --mk-shadow-sm: ${shadows.sm};
228
+ --mk-shadow-md: ${shadows.md};
229
+ --mk-shadow-lg: ${shadows.lg};
230
+ --mk-shadow-overlay: ${shadows.overlay};
231
+
232
+ /* Animation */
233
+ --mk-duration-fast: ${animation.duration.fast};
234
+ --mk-duration-normal: ${animation.duration.normal};
235
+ --mk-duration-slow: ${animation.duration.slow};
236
+ --mk-easing-spring: ${animation.easing.spring};
237
+
238
+ /* Z-Index */
239
+ --mk-z-devtools: ${zIndex.devtools};
240
+ --mk-z-overlay: ${zIndex.overlay};
241
+ }
242
+ `;
243
+ }
244
+
245
+ // ============================================================================
246
+ // Test Selectors (data-testid)
247
+ // ============================================================================
248
+
249
+ export const testIds = {
250
+ host: 'mk-host',
251
+ root: 'mk-root',
252
+ overlay: 'mk-overlay',
253
+ panel: 'mk-panel',
254
+ badge: 'mk-badge',
255
+ tabErrors: 'mk-tab-errors',
256
+ tabIslands: 'mk-tab-islands',
257
+ tabNetwork: 'mk-tab-network',
258
+ tabGuard: 'mk-tab-guard',
259
+ errorList: 'mk-error-list',
260
+ mandu: 'mk-mandu',
261
+ } as const;
262
+
263
+ export type TestId = (typeof testIds)[keyof typeof testIds];
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Mandu Kitchen DevTools - Hook Implementation
3
+ * @version 1.0.3
4
+ *
5
+ * Framework ↔ DevTools 통신을 위한 Hook 시스템
6
+ * - emit: 프레임워크 → DevTools 이벤트 발송
7
+ * - connect: DevTools → 프레임워크 sink 등록
8
+ * - queue: DevTools 연결 전 이벤트 버퍼링
9
+ */
10
+
11
+ import type { KitchenEvent } from '../types';
12
+
13
+ // ============================================================================
14
+ // Types
15
+ // ============================================================================
16
+
17
+ export type EventSink = (event: KitchenEvent) => void;
18
+
19
+ export interface ManduDevtoolsHook {
20
+ /** 이벤트 발송 (프레임워크 → DevTools) */
21
+ emit: (event: KitchenEvent) => void;
22
+
23
+ /** DevTools가 sink 등록 (DevTools → 프레임워크) */
24
+ connect: (sink: EventSink) => void;
25
+
26
+ /** DevTools 연결 해제 */
27
+ disconnect: () => void;
28
+
29
+ /** DevTools 연결 전 이벤트 큐 */
30
+ queue: KitchenEvent[];
31
+
32
+ /** 연결 상태 확인 */
33
+ isConnected: () => boolean;
34
+
35
+ /** 버전 정보 */
36
+ version: string;
37
+ }
38
+
39
+ // ============================================================================
40
+ // Constants
41
+ // ============================================================================
42
+
43
+ const MAX_QUEUE_SIZE = 100;
44
+ const HOOK_VERSION = '1.0.3';
45
+
46
+ // ============================================================================
47
+ // Hook Factory
48
+ // ============================================================================
49
+
50
+ /**
51
+ * DevTools Hook 생성
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // 프레임워크 코어에서
56
+ * window.__MANDU_DEVTOOLS_HOOK__ = createDevtoolsHook();
57
+ *
58
+ * // 이벤트 발송
59
+ * window.__MANDU_DEVTOOLS_HOOK__.emit({
60
+ * type: 'error',
61
+ * timestamp: Date.now(),
62
+ * data: normalizedError,
63
+ * });
64
+ *
65
+ * // DevTools에서 연결
66
+ * window.__MANDU_DEVTOOLS_HOOK__.connect((event) => {
67
+ * handleEvent(event);
68
+ * });
69
+ * ```
70
+ */
71
+ export function createDevtoolsHook(): ManduDevtoolsHook {
72
+ // Production 환경에서는 완전한 noop 반환
73
+ if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'production') {
74
+ return createNoopHook();
75
+ }
76
+
77
+ // Development: 실제 구현
78
+ const queue: KitchenEvent[] = [];
79
+ let sink: EventSink | null = null;
80
+
81
+ return {
82
+ version: HOOK_VERSION,
83
+
84
+ emit(event: KitchenEvent): void {
85
+ if (sink) {
86
+ // DevTools 연결됨 - 직접 전송
87
+ try {
88
+ sink(event);
89
+ } catch (e) {
90
+ // DevTools 에러가 앱을 크래시시키면 안 됨
91
+ console.warn('[Mandu Kitchen] Sink error:', e);
92
+ }
93
+ } else {
94
+ // DevTools 미연결 - 큐에 쌓기 (크기 제한)
95
+ if (queue.length >= MAX_QUEUE_SIZE) {
96
+ // 오래된 이벤트 제거 (에러는 우선 보존)
97
+ const nonErrorIndex = queue.findIndex((e) => e.type !== 'error');
98
+ if (nonErrorIndex !== -1) {
99
+ queue.splice(nonErrorIndex, 1);
100
+ } else {
101
+ // 모두 에러면 가장 오래된 것 제거
102
+ queue.shift();
103
+ }
104
+ }
105
+ queue.push(event);
106
+ }
107
+ },
108
+
109
+ connect(nextSink: EventSink): void {
110
+ sink = nextSink;
111
+
112
+ // 큐 플러시
113
+ while (queue.length > 0) {
114
+ const event = queue.shift();
115
+ if (event) {
116
+ try {
117
+ sink(event);
118
+ } catch (e) {
119
+ console.warn('[Mandu Kitchen] Flush error:', e);
120
+ }
121
+ }
122
+ }
123
+ },
124
+
125
+ disconnect(): void {
126
+ sink = null;
127
+ },
128
+
129
+ isConnected(): boolean {
130
+ return sink !== null;
131
+ },
132
+
133
+ queue,
134
+ };
135
+ }
136
+
137
+ // ============================================================================
138
+ // Noop Hook (Production)
139
+ // ============================================================================
140
+
141
+ function createNoopHook(): ManduDevtoolsHook {
142
+ const emptyQueue: KitchenEvent[] = [];
143
+
144
+ return {
145
+ version: HOOK_VERSION,
146
+ emit: () => {},
147
+ connect: () => {},
148
+ disconnect: () => {},
149
+ isConnected: () => false,
150
+ queue: emptyQueue,
151
+ };
152
+ }
153
+
154
+ // ============================================================================
155
+ // Global Hook Accessor
156
+ // ============================================================================
157
+
158
+ declare global {
159
+ interface Window {
160
+ __MANDU_DEVTOOLS_HOOK__?: ManduDevtoolsHook;
161
+ }
162
+ }
163
+
164
+ /**
165
+ * 전역 Hook 가져오기 (없으면 생성)
166
+ */
167
+ export function getOrCreateHook(): ManduDevtoolsHook {
168
+ if (typeof window === 'undefined') {
169
+ // SSR 환경
170
+ return createNoopHook();
171
+ }
172
+
173
+ if (!window.__MANDU_DEVTOOLS_HOOK__) {
174
+ window.__MANDU_DEVTOOLS_HOOK__ = createDevtoolsHook();
175
+ }
176
+
177
+ return window.__MANDU_DEVTOOLS_HOOK__;
178
+ }
179
+
180
+ /**
181
+ * 전역 Hook 가져오기 (없으면 null)
182
+ */
183
+ export function getHook(): ManduDevtoolsHook | null {
184
+ if (typeof window === 'undefined') {
185
+ return null;
186
+ }
187
+ return window.__MANDU_DEVTOOLS_HOOK__ ?? null;
188
+ }
189
+
190
+ /**
191
+ * Hook 초기화 (프레임워크 시작 시 호출)
192
+ */
193
+ export function initializeHook(): ManduDevtoolsHook {
194
+ const hook = getOrCreateHook();
195
+
196
+ // 초기화 이벤트 발송
197
+ hook.emit({
198
+ type: 'init',
199
+ timestamp: Date.now(),
200
+ data: {
201
+ version: HOOK_VERSION,
202
+ timestamp: Date.now(),
203
+ },
204
+ });
205
+
206
+ return hook;
207
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Mandu Kitchen DevTools - Hook Module
3
+ * @version 1.0.3
4
+ */
5
+
6
+ export {
7
+ createDevtoolsHook,
8
+ getOrCreateHook,
9
+ getHook,
10
+ initializeHook,
11
+ type ManduDevtoolsHook,
12
+ type EventSink,
13
+ } from './create-hook';