Share the one HTTP envelope and the one byte formatter
Both stores carried their own ~28-line request<T>, and formatBytes existed twice – the second copy had lost the "B" branch, so a small sprite would have read as 0 KB had its caller ever passed one under a kilobyte. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
787a19d525
commit
b13b130da7
11 files changed
+80
-78
No files matched your search
@@ -60,10 +60,6 @@ export function hsvToRgb({ h, s, v }: HSV): number {
|
||||
// Pixi has no 2D gradients worth the trouble, so pickers paint these into a 2D canvas once and
|
||||
// show the result as a texture.
|
||||
|
||||
// --- gradient rasterisation ------------------------------------------------------------------
|
||||
// Pixi has no 2D gradients worth the trouble, so pickers paint these into a 2D canvas once and
|
||||
// show the result as a texture.
|
||||
|
||||
/** Paints the full hue spectrum left to right, at the context's origin. */
|
||||
export function paintHueBar(ctx: CanvasRenderingContext2D, width: number, height: number): void {
|
||||
const grad = ctx.createLinearGradient(0, 0, width, 0);
|
||||
|
||||
+3
-2
@@ -3,7 +3,7 @@ export { HStack, VStack, Spacer, Stack, type StackOptions } from './layout/Stack
|
||||
export { Theme, textStyle, type TextStyleToken } from './Theme';
|
||||
export { initUI, ui, type UIContext } from './UIContext';
|
||||
export { drawControlBox, drawGrid, type ControlBoxOptions, type GridOptions } from './draw';
|
||||
export { clamp, centreY, formatNumber, NUMBER_DECIMALS, snapToStep, zoomFactor } from './math';
|
||||
export { clamp, centreY, formatBytes, formatNumber, NUMBER_DECIMALS, snapToStep, zoomFactor } from './math';
|
||||
export { activeDrag, type DragPayload, endDrag, onDragChange, startDrag } from './drag';
|
||||
export { Label, truncate } from './widgets/Label';
|
||||
export { Button, type ButtonOptions } from './widgets/Button';
|
||||
@@ -20,4 +20,5 @@ export { TextField } from './widgets/TextField';
|
||||
export { NumberField } from './widgets/NumberField';
|
||||
export { ColorField } from './widgets/ColorField';
|
||||
export { ColorPicker } from './widgets/ColorPicker';
|
||||
export * from './color';
|
||||
export { type HSV, hsvToRgb, paintHueBar, paintSvSquare, parseHex, rgbToHsv, toHex } from './color';
|
||||
export { pressCount } from './clicks';
|
||||
@@ -42,3 +42,9 @@ export function snapToStep(value: number, stepSize: number): number {
|
||||
export function zoomFactor(deltaY: number): number {
|
||||
return Math.exp(-deltaY * 0.0015);
|
||||
}
|
||||
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (bytes >= 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
||||
// A small sprite is a few hundred bytes, and "0 KB" reads like a broken file.
|
||||
return bytes >= 1024 ? `${Math.round(bytes / 1024)} KB` : `${bytes} B`;
|
||||
}
|
||||
@@ -202,8 +202,6 @@ export class ListView extends Widget {
|
||||
this.drawDropMarker();
|
||||
}
|
||||
|
||||
// --- pointer input -------------------------------------------------------------------------
|
||||
|
||||
private onRowPress(row: ListRow, e: FederatedPointerEvent): void {
|
||||
const { item } = row;
|
||||
const modifiers: PickModifiers = { ctrl: e.ctrlKey || e.metaKey, shift: e.shiftKey };
|
||||
|
||||
@@ -115,8 +115,6 @@ export class TextField extends Widget implements TextEditTarget {
|
||||
this.dragSelecting = true;
|
||||
}
|
||||
|
||||
// --- focus ---------------------------------------------------------------------------------
|
||||
|
||||
override onFocus(): void {
|
||||
super.onFocus();
|
||||
this.startEditing();
|
||||
@@ -173,8 +171,6 @@ export class TextField extends Widget implements TextEditTarget {
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
// --- TextEditTarget ------------------------------------------------------------------------
|
||||
|
||||
/** Adopts the input's value and selection verbatim; fires `onInput` only when the text changed. */
|
||||
onBridgeInput(value: string, selectionStart: number, selectionEnd: number): void {
|
||||
const changed = value !== this.valueText;
|
||||
@@ -212,8 +208,6 @@ export class TextField extends Widget implements TextEditTarget {
|
||||
if (ui().focus.focused === this) ui().focus.blur();
|
||||
}
|
||||
|
||||
// --- geometry ------------------------------------------------------------------------------
|
||||
|
||||
private textWidth(text: string): number {
|
||||
return CanvasTextMetrics.measureText(text, this.textNode.style).width;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user