Animations are mainly on the typescript side, not kotlin

This commit is contained in:
James Babcock committed 2026-09-23 22:05:06 -07:00
1 parent 063d8a0b03
commit 440674b261
26 files changed
+783 -128

No files matched your search

+1 -1
View File
@@ -355,7 +355,7 @@ function chatLayerEnv() {
const env = conversations();
const textwrap = load('app/graphics/textwrap.ts', {});
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const graphics = load('app/graphics/image.ts', { './textwrap': textwrap });
const graphics = require('../.test-build/app/graphics/image.js');
const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/terminus/ter-u12n.bdf'), 'utf8'));
let windowOptions;
const { createAiChatWindow } = load('app/apps/ai-chat/ai-chat-app.ts', {
+1 -1
View File
@@ -15,7 +15,7 @@ function load(file, modules = {}) {
}
const textwrap = load('app/graphics/textwrap.ts');
const graphics = load('app/graphics/image.ts', { './textwrap': textwrap });
const graphics = require('../.test-build/app/graphics/image.js');
const plane = load('app/graphics/plane.ts', { './image': graphics });
const gestures = load('app/ui/gestures.ts');
const numeric = load('app/util/numeric-util.ts');
+1 -1
View File
@@ -17,7 +17,7 @@ function load(file, modules = {}, globals = {}) {
return context.exports;
}
const textwrap = load('app/graphics/textwrap.ts');
const graphics = load('app/graphics/image.ts', { './textwrap': textwrap });
const graphics = require('../.test-build/app/graphics/image.js');
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const font = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8'));
const small = font(18), large = font(32);
+2 -2
View File
@@ -19,7 +19,7 @@ function load(file, modules = {}, extra = '', globals = {}) {
const textwrap = load('app/graphics/textwrap.ts');
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const graphics = load('app/graphics/image.ts', { './textwrap': textwrap });
const graphics = require('../.test-build/app/graphics/image.js');
const { GrayImage } = graphics;
const font = (size) => BdfFont.parse(fs.readFileSync(
path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8'));
@@ -156,7 +156,7 @@ test('the background registers once and uses a nine-byte image reference on late
return 1;
} } } } },
});
const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas, './presentation-wire': load('app/graphics/presentation-wire.ts') });
const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas, './presentation-wire': require('../.test-build/app/graphics/presentation-wire.js') });
const background = compass.createCompassBackground(576, 260, 256, 193.25, 98, 140, 1);
for (const heading of [0, 1, 2, 45, 90]) {
const image = background.clone();
+83
View File
@@ -0,0 +1,83 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { DrawExpression: E, ExprOp, varint, DrawBytes, evaluate } = require('../.test-build/app/graphics/draw-expression.js');
const { DrawOp, SCREEN, encodeDisplayList, readDisplayList, paintDisplayList } = require('../.test-build/app/graphics/display-list.js');
const { GrayImage } = require('../.test-build/app/graphics/image.js');
const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js');
// Also consumed by FrameDisplayListTest.kt: bridge bytes, not independently rebuilt native calls.
const MENU = '077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f';
const MULTI = '074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000';
test('extended integers agree with firmware widths and sign extension', () => {
const vectors = [[63,'3f'],[-64,'40'],[64,'8040'],[-65,'bfbf'],[8191,'9fff'],[-8192,'a000'],[8192,'c02000'],[-8193,'dfdfff'],[1048575,'cfffff'],[-1048576,'d00000'],[1048576,'e0100000'],[-1048577,'efefffff'],[134217727,'e7ffffff'],[-134217728,'e8000000'],[134217728,'f008000000'],[2147483647,'f07fffffff'],[-2147483648,'f080000000']];
for (const [value, hex] of vectors) {
assert.equal(Buffer.from(varint(value)).toString('hex'), hex);
assert.equal(new DrawBytes(Buffer.from(hex, 'hex')).variable(), value);
}
for (const n of [0,127,128,16383,16384,2097151,2097152,268435455,268435456,4294967295]) assert.equal(new DrawBytes(Uint8Array.from(varint(n,false))).variable(false), n);
assert.throws(() => E.i32(2147483648));
assert.throws(() => E.f32(Infinity));
});
test('typed expressions follow i32/f32 arithmetic, easing, time and error semantics', () => {
assert.equal(evaluate(E.i32(2147483647).add(E.i32(1)),0).value, -2147483648);
assert.equal(evaluate(E.i32(7).neg().div(E.i32(2)),0).value, -3);
assert.equal(evaluate(E.i32(-2147483648).div(E.i32(-1)),0).value, -2147483648);
assert.equal(evaluate(E.f32(1.5).mul(E.f32(2)).toInt(),0).value, 3);
for (let op = ExprOp.SMOOTHSTEP; op <= ExprOp.EASE_IN_OUT_CUBIC; op++) {
assert.equal(evaluate(E.f32(0).ease(op),0).value, 0);
assert.equal(evaluate(E.f32(1).ease(op),0).value, 1);
}
assert.deepEqual(evaluate(E.i32(300).time(),0,150), {value:150,pending:true});
assert.deepEqual(evaluate(E.i32(300).time(),0,300), {value:300,pending:false});
assert.deepEqual(evaluate(E.i32(300).time().div(E.i32(0)),0,150), {value:0,pending:false});
assert.deepEqual(evaluate(E.decode(Uint8Array.of(ExprOp.IADD)),0), {value:0,pending:false});
});
test('menu authors the golden generic list and stable timeline identity', () => {
const original = Date.now; Date.now = () => 1150;
try {
const image = new GrayImage(8,4);
image.drawMenuSelection(new GrayImage(2,2,255),3,2,16,48,1,2,{dx:-2,dy:-4,startedAt:1000,token:42,durationMs:300});
assert.equal(Buffer.from(encodePresentation(image.draws[0])).toString('hex'), MENU);
const before = image.fingerprint(); Date.now = () => 1250;
assert.equal(image.fingerprint(), before, 'wall time does not change frame identity');
const decoded = readDisplayList(Buffer.from(MENU,'hex'),0,1150).placed;
const y = decoded.displayList.calls[0].y;
assert.deepEqual(evaluate(y,150,0), {value:-2,pending:true});
assert.deepEqual(evaluate(y,150,150), {value:0,pending:false});
assert.deepEqual(evaluate(y,300,0), {value:0,pending:false});
} finally { Date.now = original; }
});
test('local resources, relative placement, stereo and screen restoration round-trip', () => {
const list = { resources:[{width:2,height:1,pixels:Uint8Array.of(0,255)},{width:1,height:1,pixels:Uint8Array.of(96)}], calls:[
{op:DrawOp.IMAGE,resource:0,x:0,y:0,transparent:true},
{op:DrawOp.RECT_COPY,resource:1,x:0,y:0,width:1,height:1,dx:2,dy:0},
{op:DrawOp.RECT_COPY,resource:SCREEN,x:-1,y:0,width:1,height:1,dx:-1,dy:0,depth:-2},
] };
const bytes = encodeDisplayList({displayList:list,x:3,y:2,width:4,height:1,depth:2});
assert.equal(Buffer.from(bytes).toString('hex'), MULTI);
const {placed,end} = readDisplayList(bytes,0);
assert.equal(end,bytes.length);
for (const right of [false,true]) {
const screen = new Uint8Array(64).fill(32), output = screen.slice();
paintDisplayList(output,screen,8,8,placed,right);
assert.equal(output[2*8+(right?3:5)],240);
assert.equal(output[2*8+(right?4:6)],96);
assert.equal(output[2*8+2],32);
}
for (let i=0;i<bytes.length;i++) assert.throws(() => readDisplayList(bytes.slice(0,i),0));
const invalid = {...list, calls:[{op:DrawOp.IMAGE,resource:2,x:0,y:0,transparent:true}]};
assert.throws(() => encodeDisplayList({displayList:invalid,x:0,y:0,width:4,height:1,depth:0}));
});
test('frame submission supports resource-free lists and plain PRESENT-relative time', () => {
const image = new GrayImage(8,8);
image.drawDisplayList({resources:[],calls:[{op:DrawOp.ROUNDED_RECT,x:E.i32(4).time(),y:0,width:2,height:2,radius:0,background:15,border:16}]},0,0,8,8);
const bytes = encodePresentation(image.draws[0]);
const {placed} = readDisplayList(bytes,0,1000);
const output = new Uint8Array(64), screen = output.slice();
paintDisplayList(output,screen,8,8,placed,false,1002);
assert.equal(output[2],240); assert.equal(output[0],0);
});
+1 -1
View File
@@ -83,7 +83,7 @@ test('bounded history preserves equal-time events, snapshots and arrival gaps; p
test('Input events captures while visible, pauses for history, and unsubscribes on removal', () => {
const textwrap = load('app/graphics/textwrap.ts');
const graphics = load('app/graphics/image.ts', { './textwrap': textwrap });
const graphics = require('../.test-build/app/graphics/image.js');
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const font = BdfFont.parse(read('app/fonts/terminus/ter-u18n.bdf'));
class RecordingImage extends graphics.GrayImage {
@@ -72,48 +72,6 @@ class DrawExpressionTest {
assertEquals(110 to false, evaluate(continued.program, 250))
}
@Test fun animatedMenuBridgePreservesElapsedTimeAndTranslation() {
// Tag 6 record emitted by the TypeScript bridge: elapsed=200, delta=(-2,-4), duration=300.
val wire = hex("06030002000200020001001030020000fefffcffc8002a0000002c01ffffffff")
val input = ArrayByteReader(wire)
assertEquals(6, input.get().toInt())
val row = MenuSelection.read(input, DrawRecordKind.ANIMATED_MENU_SELECTION).translated(10, 10)
assertEquals(0, input.remaining())
val motion = assertNotNull(row.animation)
assertEquals(42, motion.token)
assertEquals(300, motion.durationMs)
assertEquals(-2, motion.dx)
assertEquals(-4, motion.dy)
val call = row.calls(7, motion.startedAt + 200).first()
for ((elapsed, expected) in listOf(0L to (12 to 10), 100L to (13 to 12))) {
val reader = DrawReader(call)
assertEquals(8, reader.readU8())
assertEquals(DRAW_FLAG_DEPTH, reader.readU8())
assertEquals(2, reader.readS8())
val frame = DrawEvaluation(elapsed)
assertEquals(expected.first, ExtendedVarint.evaluate(reader, frame))
assertEquals(expected.second, ExtendedVarint.evaluate(reader, frame))
assertEquals(elapsed < 100, frame.animationPending)
}
for (end in 1 until wire.size) assertFails {
MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), DrawRecordKind.ANIMATED_MENU_SELECTION)
}
}
@Test fun menuCoordinatesUseTheSuppliedDuration() {
val row = MenuSelection(0, 4, 2, 2, 0, 15, 16, 0, ByteArray(2),
animation = MenuSelection.Animation(0, -4, 1000, 42, 120))
val call = row.calls(7, 1000).first()
for ((elapsed, y) in listOf(0L to 0, 60L to 2, 120L to 4)) {
val reader = DrawReader(call)
reader.readBytes(3) // opcode, flags, depth
val frame = DrawEvaluation(elapsed)
assertEquals(0, ExtendedVarint.evaluate(reader, frame))
assertEquals(y, ExtendedVarint.evaluate(reader, frame))
assertEquals(elapsed < 120, frame.animationPending)
}
}
@Test fun playerSchedulesOnlyUnfinishedFramesAndCancelsStaleCallbacks() {
val call = DrawProtocol.roundedRect(DrawValue.Integer(0), DrawValue.animate(0, 4, 300), 2, 2, 0, 15)
val renderer = DisplayListRenderer(mapOf(1 to DrawProtocol.displayList(listOf(call))))
@@ -0,0 +1,90 @@
package com.faceclaw.app
import kotlin.test.*
class FrameDisplayListTest {
// Golden records emitted by display-list-authoring.test.cjs.
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f"
private val multi = "074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000"
private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList {
val reader = ArrayByteReader(bytes)
assertEquals(DrawRecordKind.DISPLAY_LIST, reader.get().toInt())
return FrameDisplayList.read(reader, now).also { assertEquals(0, reader.remaining()) }
}
@Test fun authoredExpressionsRebindOnPresentAndTranslateWithTheSurface() {
val row = read(hex(menu)).translated(10, 10)
assertEquals(1, row.resources.size)
fun coordinates(now: Long, elapsed: Long): Triple<Int, Int, Boolean> {
val call = DrawReader(row.calls(intArrayOf(7), now).first())
assertEquals(DRAW_OP_ROUNDED_RECT, call.readU8())
assertEquals(DRAW_FLAG_DEPTH, call.readU8())
assertEquals(2, call.readS8())
val frame = DrawEvaluation(elapsed)
val x = ExtendedVarint.evaluate(call, frame)
val y = ExtendedVarint.evaluate(call, frame)
return Triple(x, y, frame.animationPending)
}
assertEquals(Triple(12, 10, true), coordinates(1150, 0))
assertEquals(Triple(13, 12, false), coordinates(1150, 150))
assertEquals(coordinates(1150, 75), coordinates(1225, 0), "another PRESENT preserves progress")
assertEquals(Triple(13, 12, false), coordinates(1400, 0))
val later = hex(menu).also { it[18] = 200.toByte() } // envelope 5 + elapsed offset 13
assertEquals(read(hex(menu)).fingerprint, read(later).fingerprint)
val other = hex(menu).also { it[14] = 43 } // timeline token
assertNotEquals(read(hex(menu)).fingerprint, read(other).fingerprint)
}
@Test fun localResourceIdsAreResolvedAndScreenCopiesStayAtScreenDepth() {
val list = read(hex(multi)).translated(10, 10)
val calls = list.calls(intArrayOf(41, 42), 1150)
assertContentEquals(DrawProtocol.image(41, 13, 12, 31, depth = 2), calls[0])
assertContentEquals(DrawProtocol.rectCopy(42, 0, 0, 1, 1, 15, 12, depth = 2), calls[1])
assertContentEquals(DrawProtocol.rectCopy(DrawProtocol.SCREEN, 12, 12, 1, 1, 12, 12, depth = 0), calls[2])
val scene = ShellScene(emptyList(), listOf(read(hex(multi))))
assertEquals(2, scene.retainedResources.size)
for (right in listOf(false, true)) {
val pixels = scene.preview(ByteArray(64) { 32 }, 8, 8, right)
assertEquals(240, pixels[16 + if (right) 3 else 5].toInt() and 255)
assertEquals(96, pixels[16 + if (right) 4 else 6].toInt() and 255)
assertEquals(32, pixels[18].toInt() and 255)
}
val cache = ResourceCacheState()
val planner = ScenePlanner(cache)
val screen = ByteArray(32) { 0x22 }
planner.plan(screen, 8, 8, null, scene, 1)
val ids = scene.retainedResources.map { cache.resourceId(it) }
assertTrue(ids.all { it >= 0 }); assertNotEquals(ids[0], ids[1])
planner.plan(screen, 8, 8, null, scene, 1)
assertEquals(ids, scene.retainedResources.map { cache.resourceId(it) })
}
@Test fun frameAndShellSubmissionUseTheSameGenericDecoder() {
val c = SurfaceCompositor()
c.configureScreen(8, 8)
c.configureSurface("app", 0, 0, 8, 8, 0, 0)
c.submitSurface("app", ArrayByteReader(ByteArray(64) { 32 }), 0, 0, 8, 8, "list",
ArrayByteReader(hex(multi)))
val frame = c.composite()
assertEquals(2, frame.shellScene.retainedResources.size)
assertEquals(240, frame.gray[21].toInt() and 255)
assertTrue(frame.screenGray.all { it.toInt() == 32 })
// One opaque 1x1 shell layer, with one generic list after its pixels.
val layer = DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(0) + DrawProtocol.word(0) +
DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(256) + DrawProtocol.word(1) +
DrawProtocol.word(0) + byteArrayOf(32) + hex(multi)
val shell = ShellScene.decode(ArrayByteReader(layer))
assertEquals(2, shell.retainedResources.size)
assertEquals(240, shell.preview(ByteArray(64) { 32 }, 8, 8)[21].toInt() and 255)
}
@Test fun rejectsTruncationBadResourcesAndTrailingData() {
val bytes = hex(multi)
for (end in 1 until bytes.size) assertFails { read(bytes.copyOf(end)) }
assertFails { read(bytes.copyOf().also { it[40] = 9 }) } // first image's local resource
val trailing = bytes + byteArrayOf(0)
trailing[1] = (trailing[1] + 1).toByte()
assertFails { read(trailing) }
}
}
+1 -1
View File
@@ -48,7 +48,7 @@ test('shell menu selection survives serialization and is not baked into its surf
test('later opaque planes occlude a replayed selection without erasing its visible part',()=>{
const image=menu().paint(),row=image.draws.find(d=>d.presentation),cover=new graphics.GrayImage(10,8,1);
const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0},{image:cover,x:row.x+10,y:row.y+2}]);
const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.ok(records[0].occlusions.length);
const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.ok(records[0].displayList.calls.some(c => c.op === 2 && c.resource === 65535));
const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'});
c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws));
const preview=c.composite();
+4 -4
View File
@@ -35,7 +35,7 @@ test('bridge and fallback preview use the supplied animation duration', () => {
image.drawMenuSelection(new GrayImage(2, 2), 5, 0, 0, 255, 0, 0,
{ dx: -4, dy: 0, startedAt: 1000, token: 1, durationMs: 100 });
const record = readPresentation(encodePresentation(image.draws[0]), 0);
assert.equal(record.selection.animation.durationMs, 100);
assert.ok(record.selection.displayList);
const screen = new Uint8Array(16), output = new Uint8Array(16);
paintPresentation(output, screen, 8, 2, record.selection);
assert.equal(output[3], 240, 'halfway at 50 ms');
@@ -56,11 +56,11 @@ test('animated selection bridge carries relative start, elapsed time and stable
image.drawMenuSelection(new GrayImage(2, 2, 255), 3, 2, 16, 48, 1, 2,
{ dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS });
const bytes = encodePresentation(image.draws[0]);
assert.equal(bytes[0], 6);
assert.equal(bytes.length, 32);
assert.equal(bytes[0], 7);
const record = readPresentation(bytes, 0);
assert.equal(record.end, bytes.length);
assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS });
assert.deepEqual(record.selection.displayList.timeline, { startedAt: 1000, token: 42 });
assert.equal(record.selection.displayList.calls[0].op, 8);
assert.equal(record.selection.x, 3);
assert.equal(record.selection.y, 2);
} finally { Date.now = now; }
+1 -1
View File
@@ -137,7 +137,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
const { prefs } = store();
let refreshes = 0, closes = 0;
const textwrap = load('app/graphics/textwrap.ts');
const graphics = load('app/graphics/image.ts', () => textwrap);
const graphics = require('../.test-build/app/graphics/image.js');
const { BdfFont } = load('app/graphics/bdffont.ts', () => ({}));
const font = BdfFont.parse(source('app/fonts/terminus/ter-u20n.bdf'));
class RecordingImage extends graphics.GrayImage {
+1 -1
View File
@@ -53,7 +53,7 @@ function ui(fontSize = 12) {
let dismissals = 0;
let closes = 0;
const textwrap = load('app/graphics/textwrap.ts');
const graphics = load('app/graphics/image.ts', () => textwrap);
const graphics = require('../.test-build/app/graphics/image.js');
const { BdfFont } = load('app/graphics/bdffont.ts', () => ({}));
const font = BdfFont.parse(source(`app/fonts/terminus/ter-u${fontSize}n.bdf`));
class RecordingImage extends graphics.GrayImage {