@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.
- package/dist/lib/biome-host/define-web-biome.d.ts +3 -2
- package/dist/lib/biome-host/define-web-biome.d.ts.map +1 -1
- package/dist/lib/biome-host/define-web-biome.js +23 -1
- package/dist/lib/biome-host/define-web-biome.js.map +1 -1
- package/dist/lib/biome-host/frontend-biome.d.ts +4 -1
- package/dist/lib/biome-host/frontend-biome.d.ts.map +1 -1
- package/dist/lib/biome-host/host-bridge.d.ts +2 -0
- package/dist/lib/biome-host/host-bridge.d.ts.map +1 -1
- package/dist/lib/biome-host/host-bridge.js.map +1 -1
- package/dist/lib/biome-host/i18n-hooks.d.ts +4 -0
- package/dist/lib/biome-host/i18n-hooks.d.ts.map +1 -0
- package/dist/lib/biome-host/i18n-hooks.js +22 -0
- package/dist/lib/biome-host/i18n-hooks.js.map +1 -0
- package/dist/lib/biome-host/i18n-port.d.ts +15 -0
- package/dist/lib/biome-host/i18n-port.d.ts.map +1 -0
- package/dist/lib/biome-host/i18n-port.js +29 -0
- package/dist/lib/biome-host/i18n-port.js.map +1 -0
- package/dist/lib/biome-host/index.d.ts +2 -0
- package/dist/lib/biome-host/index.d.ts.map +1 -1
- package/dist/lib/biome-host/index.js +2 -0
- package/dist/lib/biome-host/index.js.map +1 -1
- package/dist/lib/biome-host/realtime-port.d.ts +1 -1
- package/dist/lib/biome-host/realtime-port.d.ts.map +1 -1
- package/dist/session-kit/approvals/approval-model.d.ts.map +1 -1
- package/dist/session-kit/approvals/approval-model.js.map +1 -1
- package/dist/ui/branding/app-branding-provider.d.ts +17 -0
- package/dist/ui/branding/app-branding-provider.d.ts.map +1 -0
- package/dist/ui/branding/app-branding-provider.js +81 -0
- package/dist/ui/branding/app-branding-provider.js.map +1 -0
- package/dist/ui/branding/sanitize.d.ts +4 -0
- package/dist/ui/branding/sanitize.d.ts.map +1 -0
- package/dist/ui/branding/sanitize.js +47 -0
- package/dist/ui/branding/sanitize.js.map +1 -0
- package/dist/ui/breakpoints.d.ts +2 -0
- package/dist/ui/breakpoints.d.ts.map +1 -0
- package/dist/ui/breakpoints.js +5 -0
- package/dist/ui/breakpoints.js.map +1 -0
- package/dist/ui/charts/bar-chart.d.ts +7 -0
- package/dist/ui/charts/bar-chart.d.ts.map +1 -0
- package/dist/ui/charts/bar-chart.js +47 -0
- package/dist/ui/charts/bar-chart.js.map +1 -0
- package/dist/ui/charts/chart-frame.d.ts +25 -0
- package/dist/ui/charts/chart-frame.d.ts.map +1 -0
- package/dist/ui/charts/chart-frame.js +23 -0
- package/dist/ui/charts/chart-frame.js.map +1 -0
- package/dist/ui/charts/chart-types.d.ts +19 -0
- package/dist/ui/charts/chart-types.d.ts.map +1 -0
- package/dist/ui/charts/chart-types.js +3 -0
- package/dist/ui/charts/chart-types.js.map +1 -0
- package/dist/ui/charts/chart-utils.d.ts +22 -0
- package/dist/ui/charts/chart-utils.d.ts.map +1 -0
- package/dist/ui/charts/chart-utils.js +97 -0
- package/dist/ui/charts/chart-utils.js.map +1 -0
- package/dist/ui/charts/donut-chart.d.ts +7 -0
- package/dist/ui/charts/donut-chart.d.ts.map +1 -0
- package/dist/ui/charts/donut-chart.js +55 -0
- package/dist/ui/charts/donut-chart.js.map +1 -0
- package/dist/ui/charts/index.d.ts +8 -0
- package/dist/ui/charts/index.d.ts.map +1 -0
- package/dist/ui/charts/index.js +21 -0
- package/dist/ui/charts/index.js.map +1 -0
- package/dist/ui/charts/line-chart.d.ts +7 -0
- package/dist/ui/charts/line-chart.d.ts.map +1 -0
- package/dist/ui/charts/line-chart.js +70 -0
- package/dist/ui/charts/line-chart.js.map +1 -0
- package/dist/ui/charts/sparkline.d.ts +13 -0
- package/dist/ui/charts/sparkline.d.ts.map +1 -0
- package/dist/ui/charts/sparkline.js +39 -0
- package/dist/ui/charts/sparkline.js.map +1 -0
- package/dist/ui/hooks/use-is-mobile.d.ts +2 -0
- package/dist/ui/hooks/use-is-mobile.d.ts.map +1 -0
- package/dist/ui/hooks/use-is-mobile.js +19 -0
- package/dist/ui/hooks/use-is-mobile.js.map +1 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +14 -1
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/pdf/pdf-preview.d.ts +8 -0
- package/dist/ui/pdf/pdf-preview.d.ts.map +1 -0
- package/dist/ui/pdf/pdf-preview.js +34 -0
- package/dist/ui/pdf/pdf-preview.js.map +1 -0
- package/dist/ui/primitives/preview-device-frame.d.ts +9 -0
- package/dist/ui/primitives/preview-device-frame.d.ts.map +1 -0
- package/dist/ui/primitives/preview-device-frame.js +90 -0
- package/dist/ui/primitives/preview-device-frame.js.map +1 -0
- package/package.json +8 -7
- package/src/lib/biome-host/define-web-biome.test.js +93 -0
- package/src/lib/biome-host/define-web-biome.ts +71 -4
- package/src/lib/biome-host/frontend-biome.ts +45 -4
- package/src/lib/biome-host/host-bridge.ts +13 -0
- package/src/lib/biome-host/i18n-hooks.ts +50 -0
- package/src/lib/biome-host/i18n-port.test.ts +50 -0
- package/src/lib/biome-host/i18n-port.ts +96 -0
- package/src/lib/biome-host/index.ts +2 -0
- package/src/lib/biome-host/realtime-port.ts +9 -3
- package/src/lib/system-bus/enums.ts +1 -1
- package/src/lib/system-bus/index.ts +1 -1
- package/src/lib/system-bus/intents.ts +1 -1
- package/src/session-kit/approvals/ApprovalCard.tsx +1 -1
- package/src/session-kit/approvals/ApprovalsCenter.tsx +2 -2
- package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +1 -1
- package/src/session-kit/approvals/Obligation.tsx +1 -1
- package/src/session-kit/approvals/ScopedBody.tsx +1 -1
- package/src/session-kit/approvals/approval-model.ts +7 -8
- package/src/session-kit/approvals/index.ts +1 -1
- package/src/session-kit/approvals/obligation-display.ts +1 -1
- package/src/session-kit/approvals/risk-accent.ts +1 -1
- package/src/session-kit/combobox/Combobox.tsx +1 -1
- package/src/session-kit/display/MessageTurn.tsx +1 -1
- package/src/session-kit/display/TokenMeter.tsx +1 -1
- package/src/session-kit/index.ts +3 -3
- package/src/session-kit/lib/enums.ts +1 -1
- package/src/session-kit/lib/status-dot.ts +1 -1
- package/src/session-kit/primitives/RiskPill.tsx +1 -1
- package/src/ui/branding/app-branding-provider.tsx +146 -0
- package/src/ui/branding/sanitize.ts +77 -0
- package/src/ui/breakpoints.ts +14 -0
- package/src/ui/charts/bar-chart.tsx +135 -0
- package/src/ui/charts/chart-frame.tsx +112 -0
- package/src/ui/charts/chart-types.ts +52 -0
- package/src/ui/charts/chart-utils.ts +158 -0
- package/src/ui/charts/charts.test.tsx +204 -0
- package/src/ui/charts/donut-chart.tsx +111 -0
- package/src/ui/charts/index.ts +27 -0
- package/src/ui/charts/line-chart.tsx +180 -0
- package/src/ui/charts/sparkline.tsx +101 -0
- package/src/ui/hooks/use-is-mobile.ts +28 -0
- package/src/ui/index.ts +22 -0
- package/src/ui/pdf/pdf-preview.tsx +122 -0
- 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
|
+
}
|