@xemahq/ui-kernel 0.6.0 → 0.6.1

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 (130) hide show
  1. package/dist/lib/biome-host/define-web-biome.d.ts +3 -2
  2. package/dist/lib/biome-host/define-web-biome.d.ts.map +1 -1
  3. package/dist/lib/biome-host/define-web-biome.js +23 -1
  4. package/dist/lib/biome-host/define-web-biome.js.map +1 -1
  5. package/dist/lib/biome-host/frontend-biome.d.ts +4 -1
  6. package/dist/lib/biome-host/frontend-biome.d.ts.map +1 -1
  7. package/dist/lib/biome-host/host-bridge.d.ts +2 -0
  8. package/dist/lib/biome-host/host-bridge.d.ts.map +1 -1
  9. package/dist/lib/biome-host/host-bridge.js.map +1 -1
  10. package/dist/lib/biome-host/i18n-hooks.d.ts +4 -0
  11. package/dist/lib/biome-host/i18n-hooks.d.ts.map +1 -0
  12. package/dist/lib/biome-host/i18n-hooks.js +22 -0
  13. package/dist/lib/biome-host/i18n-hooks.js.map +1 -0
  14. package/dist/lib/biome-host/i18n-port.d.ts +15 -0
  15. package/dist/lib/biome-host/i18n-port.d.ts.map +1 -0
  16. package/dist/lib/biome-host/i18n-port.js +29 -0
  17. package/dist/lib/biome-host/i18n-port.js.map +1 -0
  18. package/dist/lib/biome-host/index.d.ts +2 -0
  19. package/dist/lib/biome-host/index.d.ts.map +1 -1
  20. package/dist/lib/biome-host/index.js +2 -0
  21. package/dist/lib/biome-host/index.js.map +1 -1
  22. package/dist/lib/biome-host/realtime-port.d.ts +1 -1
  23. package/dist/lib/biome-host/realtime-port.d.ts.map +1 -1
  24. package/dist/session-kit/approvals/approval-model.d.ts.map +1 -1
  25. package/dist/session-kit/approvals/approval-model.js.map +1 -1
  26. package/dist/ui/branding/app-branding-provider.d.ts +17 -0
  27. package/dist/ui/branding/app-branding-provider.d.ts.map +1 -0
  28. package/dist/ui/branding/app-branding-provider.js +81 -0
  29. package/dist/ui/branding/app-branding-provider.js.map +1 -0
  30. package/dist/ui/branding/sanitize.d.ts +4 -0
  31. package/dist/ui/branding/sanitize.d.ts.map +1 -0
  32. package/dist/ui/branding/sanitize.js +47 -0
  33. package/dist/ui/branding/sanitize.js.map +1 -0
  34. package/dist/ui/breakpoints.d.ts +2 -0
  35. package/dist/ui/breakpoints.d.ts.map +1 -0
  36. package/dist/ui/breakpoints.js +5 -0
  37. package/dist/ui/breakpoints.js.map +1 -0
  38. package/dist/ui/charts/bar-chart.d.ts +7 -0
  39. package/dist/ui/charts/bar-chart.d.ts.map +1 -0
  40. package/dist/ui/charts/bar-chart.js +47 -0
  41. package/dist/ui/charts/bar-chart.js.map +1 -0
  42. package/dist/ui/charts/chart-frame.d.ts +25 -0
  43. package/dist/ui/charts/chart-frame.d.ts.map +1 -0
  44. package/dist/ui/charts/chart-frame.js +23 -0
  45. package/dist/ui/charts/chart-frame.js.map +1 -0
  46. package/dist/ui/charts/chart-types.d.ts +19 -0
  47. package/dist/ui/charts/chart-types.d.ts.map +1 -0
  48. package/dist/ui/charts/chart-types.js +3 -0
  49. package/dist/ui/charts/chart-types.js.map +1 -0
  50. package/dist/ui/charts/chart-utils.d.ts +22 -0
  51. package/dist/ui/charts/chart-utils.d.ts.map +1 -0
  52. package/dist/ui/charts/chart-utils.js +97 -0
  53. package/dist/ui/charts/chart-utils.js.map +1 -0
  54. package/dist/ui/charts/donut-chart.d.ts +7 -0
  55. package/dist/ui/charts/donut-chart.d.ts.map +1 -0
  56. package/dist/ui/charts/donut-chart.js +55 -0
  57. package/dist/ui/charts/donut-chart.js.map +1 -0
  58. package/dist/ui/charts/index.d.ts +8 -0
  59. package/dist/ui/charts/index.d.ts.map +1 -0
  60. package/dist/ui/charts/index.js +21 -0
  61. package/dist/ui/charts/index.js.map +1 -0
  62. package/dist/ui/charts/line-chart.d.ts +7 -0
  63. package/dist/ui/charts/line-chart.d.ts.map +1 -0
  64. package/dist/ui/charts/line-chart.js +70 -0
  65. package/dist/ui/charts/line-chart.js.map +1 -0
  66. package/dist/ui/charts/sparkline.d.ts +13 -0
  67. package/dist/ui/charts/sparkline.d.ts.map +1 -0
  68. package/dist/ui/charts/sparkline.js +39 -0
  69. package/dist/ui/charts/sparkline.js.map +1 -0
  70. package/dist/ui/hooks/use-is-mobile.d.ts +2 -0
  71. package/dist/ui/hooks/use-is-mobile.d.ts.map +1 -0
  72. package/dist/ui/hooks/use-is-mobile.js +19 -0
  73. package/dist/ui/hooks/use-is-mobile.js.map +1 -0
  74. package/dist/ui/index.d.ts +6 -0
  75. package/dist/ui/index.d.ts.map +1 -1
  76. package/dist/ui/index.js +14 -1
  77. package/dist/ui/index.js.map +1 -1
  78. package/dist/ui/pdf/pdf-preview.d.ts +8 -0
  79. package/dist/ui/pdf/pdf-preview.d.ts.map +1 -0
  80. package/dist/ui/pdf/pdf-preview.js +34 -0
  81. package/dist/ui/pdf/pdf-preview.js.map +1 -0
  82. package/dist/ui/primitives/preview-device-frame.d.ts +9 -0
  83. package/dist/ui/primitives/preview-device-frame.d.ts.map +1 -0
  84. package/dist/ui/primitives/preview-device-frame.js +90 -0
  85. package/dist/ui/primitives/preview-device-frame.js.map +1 -0
  86. package/package.json +8 -7
  87. package/src/lib/biome-host/define-web-biome.test.js +93 -0
  88. package/src/lib/biome-host/define-web-biome.ts +71 -4
  89. package/src/lib/biome-host/frontend-biome.ts +45 -4
  90. package/src/lib/biome-host/host-bridge.ts +13 -0
  91. package/src/lib/biome-host/i18n-hooks.ts +50 -0
  92. package/src/lib/biome-host/i18n-port.test.ts +50 -0
  93. package/src/lib/biome-host/i18n-port.ts +96 -0
  94. package/src/lib/biome-host/index.ts +2 -0
  95. package/src/lib/biome-host/realtime-port.ts +9 -3
  96. package/src/lib/system-bus/enums.ts +1 -1
  97. package/src/lib/system-bus/index.ts +1 -1
  98. package/src/lib/system-bus/intents.ts +1 -1
  99. package/src/session-kit/approvals/ApprovalCard.tsx +1 -1
  100. package/src/session-kit/approvals/ApprovalsCenter.tsx +2 -2
  101. package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +1 -1
  102. package/src/session-kit/approvals/Obligation.tsx +1 -1
  103. package/src/session-kit/approvals/ScopedBody.tsx +1 -1
  104. package/src/session-kit/approvals/approval-model.ts +7 -8
  105. package/src/session-kit/approvals/index.ts +1 -1
  106. package/src/session-kit/approvals/obligation-display.ts +1 -1
  107. package/src/session-kit/approvals/risk-accent.ts +1 -1
  108. package/src/session-kit/combobox/Combobox.tsx +1 -1
  109. package/src/session-kit/display/MessageTurn.tsx +1 -1
  110. package/src/session-kit/display/TokenMeter.tsx +1 -1
  111. package/src/session-kit/index.ts +3 -3
  112. package/src/session-kit/lib/enums.ts +1 -1
  113. package/src/session-kit/lib/status-dot.ts +1 -1
  114. package/src/session-kit/primitives/RiskPill.tsx +1 -1
  115. package/src/ui/branding/app-branding-provider.tsx +146 -0
  116. package/src/ui/branding/sanitize.ts +77 -0
  117. package/src/ui/breakpoints.ts +14 -0
  118. package/src/ui/charts/bar-chart.tsx +135 -0
  119. package/src/ui/charts/chart-frame.tsx +112 -0
  120. package/src/ui/charts/chart-types.ts +52 -0
  121. package/src/ui/charts/chart-utils.ts +158 -0
  122. package/src/ui/charts/charts.test.tsx +204 -0
  123. package/src/ui/charts/donut-chart.tsx +111 -0
  124. package/src/ui/charts/index.ts +27 -0
  125. package/src/ui/charts/line-chart.tsx +180 -0
  126. package/src/ui/charts/sparkline.tsx +101 -0
  127. package/src/ui/hooks/use-is-mobile.ts +28 -0
  128. package/src/ui/index.ts +22 -0
  129. package/src/ui/pdf/pdf-preview.tsx +122 -0
  130. package/src/ui/primitives/preview-device-frame.tsx +205 -0
@@ -0,0 +1,205 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // ── PreviewDeviceFrame — CSS-transform-scaled device bezel ──
3
+ //
4
+ // Wraps a child (typically an iframe, but any node works) in a scale-to-fit
5
+ // bezel for Tablet (768×1024) and Mobile (390×844). Desktop renders children
6
+ // at 100% width/height. Presentation renders a responsive 16:9 viewport;
7
+ // A4 renders a 794×1123 portrait sheet — both grow/shrink to fit the panel.
8
+ //
9
+ // IMPORTANT: We scale the *wrapper* via `transform: scale(...)` — the child is
10
+ // always rendered at the bezel's native resolution. This avoids ResizeObserver
11
+ // churn inside an embedded app (width/height stay constant; only the parent's
12
+ // visual size changes). Devices report the bezel's intended CSS pixel
13
+ // dimensions to the child regardless of the visual scale.
14
+ //
15
+ // Owned by the UI kernel so both the host session-preview surface AND biome
16
+ // canvases (e.g. App Forge's builder) reuse ONE bezel — there is no second
17
+ // device-frame implementation.
18
+ // ═══════════════════════════════════════════════════════════════════════════
19
+
20
+ import { useLayoutEffect, useRef, useState, type ReactNode } from 'react';
21
+
22
+ import { cn } from '../cn';
23
+
24
+ /**
25
+ * Closed set of preview viewports. `desktop`/`tablet`/`mobile` are the
26
+ * device widths an app builder offers; `presentation`/`a4` are
27
+ * document-preview viewports used by the session preview surface only.
28
+ */
29
+ export type PreviewDevice =
30
+ | 'desktop'
31
+ | 'tablet'
32
+ | 'mobile'
33
+ | 'presentation'
34
+ | 'a4';
35
+
36
+ interface PreviewDeviceFrameProps {
37
+ readonly device: PreviewDevice;
38
+ readonly children: ReactNode;
39
+ }
40
+
41
+ interface Bezel {
42
+ width: number;
43
+ height: number;
44
+ radius: number;
45
+ }
46
+
47
+ const BEZELS: Record<
48
+ Exclude<PreviewDevice, 'desktop' | 'presentation' | 'a4'>,
49
+ Bezel
50
+ > = {
51
+ tablet: { width: 768, height: 1024, radius: 18 },
52
+ mobile: { width: 390, height: 844, radius: 36 },
53
+ };
54
+
55
+ const PRESENTATION_VIEWPORT: Bezel = { width: 1280, height: 720, radius: 20 };
56
+ // A4 at 96 dpi: 210mm × 297mm → 794×1123 px
57
+ const A4_VIEWPORT: Bezel = { width: 794, height: 1123, radius: 4 };
58
+
59
+ export function PreviewDeviceFrame({
60
+ device,
61
+ children,
62
+ }: PreviewDeviceFrameProps) {
63
+ if (device === 'desktop') {
64
+ return <div className="h-full w-full">{children}</div>;
65
+ }
66
+ if (device === 'presentation') {
67
+ return (
68
+ <ResponsiveViewport bezel={PRESENTATION_VIEWPORT} aspectRatio={16 / 9}>
69
+ {children}
70
+ </ResponsiveViewport>
71
+ );
72
+ }
73
+ if (device === 'a4') {
74
+ return (
75
+ <ResponsiveViewport bezel={A4_VIEWPORT} aspectRatio={794 / 1123}>
76
+ {children}
77
+ </ResponsiveViewport>
78
+ );
79
+ }
80
+ return <ScaledBezel bezel={BEZELS[device]}>{children}</ScaledBezel>;
81
+ }
82
+
83
+ interface ScaledBezelProps {
84
+ readonly bezel: Bezel;
85
+ readonly children: ReactNode;
86
+ }
87
+
88
+ /**
89
+ * Render a fixed-size bezel at (bezel.width × bezel.height) CSS px, then
90
+ * scale the whole wrapper down to fit its container. The child inside stays
91
+ * at the bezel's native resolution.
92
+ */
93
+ function ScaledBezel({ bezel, children }: ScaledBezelProps) {
94
+ const containerRef = useRef<HTMLDivElement | null>(null);
95
+ const [scale, setScale] = useState(1);
96
+
97
+ useLayoutEffect(() => {
98
+ const el = containerRef.current;
99
+ if (!el) return;
100
+ const compute = (): void => {
101
+ const { clientWidth, clientHeight } = el;
102
+ if (clientWidth === 0 || clientHeight === 0) return;
103
+ // Leave a tiny margin so the shadow is not clipped.
104
+ const margin = 24;
105
+ const availW = Math.max(0, clientWidth - margin);
106
+ const availH = Math.max(0, clientHeight - margin);
107
+ const next = Math.min(1, availW / bezel.width, availH / bezel.height);
108
+ setScale(next);
109
+ };
110
+ compute();
111
+ const observer = new ResizeObserver(compute);
112
+ observer.observe(el);
113
+ return () => observer.disconnect();
114
+ }, [bezel.width, bezel.height]);
115
+
116
+ return (
117
+ <div
118
+ ref={containerRef}
119
+ className="flex h-full w-full items-center justify-center overflow-hidden bg-paper-elev/60 p-2"
120
+ >
121
+ <div
122
+ className={cn(
123
+ 'relative shrink-0 overflow-hidden bg-paper shadow-2xl ring-1 ring-border/75',
124
+ )}
125
+ style={{
126
+ width: bezel.width,
127
+ height: bezel.height,
128
+ borderRadius: bezel.radius,
129
+ // Scale the WRAPPER — NOT the child element. The child's own
130
+ // width/height in CSS pixels remain bezel.width × bezel.height, so
131
+ // an embedded app sees a stable viewport and no ResizeObserver churn
132
+ // when the outer panel resizes.
133
+ transform: `scale(${scale})`,
134
+ transformOrigin: 'center center',
135
+ }}
136
+ >
137
+ {children}
138
+ </div>
139
+ </div>
140
+ );
141
+ }
142
+
143
+ interface ResponsiveViewportProps extends ScaledBezelProps {
144
+ /** Width-to-height ratio used to letterbox/pillarbox the frame. */
145
+ readonly aspectRatio: number;
146
+ }
147
+
148
+ /**
149
+ * Fit an arbitrary-aspect-ratio viewport inside the available space and let
150
+ * the child resize to that real size. Content sees the actual viewport
151
+ * dimensions instead of a transform-scaled shell, so it can adapt responsively.
152
+ */
153
+ function ResponsiveViewport({
154
+ bezel,
155
+ aspectRatio,
156
+ children,
157
+ }: ResponsiveViewportProps) {
158
+ const containerRef = useRef<HTMLDivElement | null>(null);
159
+ const [size, setSize] = useState(() => ({
160
+ width: bezel.width,
161
+ height: bezel.height,
162
+ }));
163
+
164
+ useLayoutEffect(() => {
165
+ const el = containerRef.current;
166
+ if (!el) return;
167
+ const compute = (): void => {
168
+ const { clientWidth, clientHeight } = el;
169
+ if (clientWidth === 0 || clientHeight === 0) return;
170
+ const margin = 24;
171
+ const availW = Math.max(0, clientWidth - margin);
172
+ const availH = Math.max(0, clientHeight - margin);
173
+ const nextWidth = Math.min(availW, availH * aspectRatio);
174
+ const nextHeight = nextWidth / aspectRatio;
175
+ setSize({
176
+ width: Math.max(1, Math.round(nextWidth)),
177
+ height: Math.max(1, Math.round(nextHeight)),
178
+ });
179
+ };
180
+ compute();
181
+ const observer = new ResizeObserver(compute);
182
+ observer.observe(el);
183
+ return () => observer.disconnect();
184
+ }, [bezel.width, bezel.height]);
185
+
186
+ return (
187
+ <div
188
+ ref={containerRef}
189
+ className="flex h-full w-full items-center justify-center overflow-hidden bg-paper-elev/60 p-2"
190
+ >
191
+ <div
192
+ className={cn(
193
+ 'relative shrink-0 overflow-hidden bg-paper shadow-2xl ring-1 ring-border/75',
194
+ )}
195
+ style={{
196
+ width: size.width,
197
+ height: size.height,
198
+ borderRadius: bezel.radius,
199
+ }}
200
+ >
201
+ {children}
202
+ </div>
203
+ </div>
204
+ );
205
+ }