@opencode/simulation 2.0.7 → 2.0.9
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CliRenderer } from "@opentui/core";
|
|
2
2
|
import { type MockInput, type MockMouse } from "@opentui/core/testing";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
import { SimulationProtocol } from "../protocol";
|
|
@@ -44,6 +44,7 @@ export declare const capture: (harness: Harness) => Effect.Effect<{
|
|
|
44
44
|
width: number;
|
|
45
45
|
}[];
|
|
46
46
|
}[];
|
|
47
|
+
images: SimulationProtocol.Frontend.CapturedImage[];
|
|
47
48
|
}, import("effect/Cause").UnknownError, never>;
|
|
48
49
|
export declare const execute: (harness: Harness, action: {
|
|
49
50
|
readonly type: "ui.type";
|
package/dist/frontend/actions.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { ImageRenderable } from "@opentui/core";
|
|
1
2
|
import {
|
|
2
3
|
createMockKeys,
|
|
3
4
|
createMockMouse,
|
|
4
5
|
KeyCodes
|
|
5
6
|
} from "@opentui/core/testing";
|
|
6
|
-
import { Effect, Schema } from "effect";
|
|
7
|
+
import { Effect, Encoding, Schema } from "effect";
|
|
7
8
|
import { SimulationProtocol } from "../protocol";
|
|
8
9
|
import { SimulationRenderer } from "./renderer";
|
|
9
10
|
import { SimulationSemantics } from "./semantics";
|
|
@@ -107,9 +108,48 @@ export const capture = Effect.fn("SimulationActions.capture")(function* (harness
|
|
|
107
108
|
attributes: span.attributes,
|
|
108
109
|
width: span.width
|
|
109
110
|
}))
|
|
110
|
-
}))
|
|
111
|
+
})),
|
|
112
|
+
images: captureImages(harness.renderer)
|
|
111
113
|
};
|
|
112
|
-
})
|
|
114
|
+
});
|
|
115
|
+
function captureImages(renderer) {
|
|
116
|
+
return all(renderer.root).flatMap((renderable) => {
|
|
117
|
+
if (!(renderable instanceof ImageRenderable) || !renderable.visible || renderable.isDestroyed || !renderable.image)
|
|
118
|
+
return [];
|
|
119
|
+
const fitted = renderable.fit === "cover" ? { width: renderable.width, height: renderable.height } : renderable.getFittedSize(renderable.width, renderable.height);
|
|
120
|
+
if (fitted.width <= 0 || fitted.height <= 0)
|
|
121
|
+
return [];
|
|
122
|
+
const x = renderable.screenX + Math.floor((renderable.width - fitted.width) / 2), y = renderable.screenY + Math.floor((renderable.height - fitted.height) / 2);
|
|
123
|
+
let source = renderable.image, extracted;
|
|
124
|
+
if (renderable.fit === "cover") {
|
|
125
|
+
const targetAspect = renderable.width / (renderable.height * renderable.cellAspectRatio), sourceAspect = source.width / source.height, width = sourceAspect > targetAspect ? Math.max(1, Math.round(source.height * targetAspect)) : source.width, height = sourceAspect > targetAspect ? source.height : Math.max(1, Math.round(source.width / targetAspect));
|
|
126
|
+
extracted = source.extract({
|
|
127
|
+
left: Math.floor((source.width - width) / 2),
|
|
128
|
+
top: Math.floor((source.height - height) / 2),
|
|
129
|
+
width,
|
|
130
|
+
height
|
|
131
|
+
});
|
|
132
|
+
source = extracted;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const raw = source.raw("rgba8"), rgba = new Uint8Array(raw.width * raw.height * 4);
|
|
136
|
+
for (let row = 0;row < raw.height; row++)
|
|
137
|
+
rgba.set(raw.data.subarray(row * raw.stride, row * raw.stride + raw.width * 4), row * raw.width * 4);
|
|
138
|
+
return [{
|
|
139
|
+
x,
|
|
140
|
+
y,
|
|
141
|
+
width: fitted.width,
|
|
142
|
+
height: fitted.height,
|
|
143
|
+
pixelWidth: raw.width,
|
|
144
|
+
pixelHeight: raw.height,
|
|
145
|
+
rgba: Encoding.encodeBase64(rgba)
|
|
146
|
+
}];
|
|
147
|
+
} finally {
|
|
148
|
+
extracted?.dispose();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
export const execute = Effect.fn("SimulationActions.execute")(function* (harness, action) {
|
|
113
153
|
switch (action.type) {
|
|
114
154
|
case "ui.type":
|
|
115
155
|
yield* Effect.tryPromise(() => harness.mockInput.typeText(action.text));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/simulation",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"typecheck": "tsgo -b"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@opencode/core": "2.0.
|
|
51
|
-
"@opencode/ai": "2.0.
|
|
52
|
-
"@opencode/plugin": "2.0.
|
|
53
|
-
"@opencode/protocol": "2.0.
|
|
54
|
-
"@opencode/util": "2.0.
|
|
50
|
+
"@opencode/core": "2.0.9",
|
|
51
|
+
"@opencode/ai": "2.0.9",
|
|
52
|
+
"@opencode/plugin": "2.0.9",
|
|
53
|
+
"@opencode/protocol": "2.0.9",
|
|
54
|
+
"@opencode/util": "2.0.9",
|
|
55
55
|
"@opentui/core": "0.5.10",
|
|
56
56
|
"effect": "4.0.0-rc.112",
|
|
57
57
|
"ws": "8.21.0"
|