Skip to content

Commit fd2c8d2

Browse files
committed
refactor: use ht instead of domx
1 parent 01daa2c commit fd2c8d2

3 files changed

Lines changed: 37 additions & 47 deletions

File tree

editor/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"imports": {
33
"@kt3k/cell": "jsr:@kt3k/cell@^0.7.6",
4-
"@kt3k/domx": "jsr:@kt3k/domx@^0.1.8",
4+
"@kt3k/ht": "jsr:@kt3k/ht@^0.1.3",
55
"@kt3k/picojsx": "jsr:@kt3k/picojsx@^0.1.5",
66
"@kt3k/weak-value-map": "jsr:@kt3k/weak-value-map@^0.1.2",
77
"@std/encoding": "jsr:@std/encoding@^1.0.6",

editor/deno.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editor/webview.tsx

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
/// <reference lib="dom" />
55
/// <reference types="@types/vscode-webview" />
66

7-
/** @jsxImportSource @kt3k/domx */
8-
/** @jsxRuntime automatic */
9-
107
const vscode = acquireVsCodeApi<{ uri: string; text: string }>()
118

9+
import { type Context, GroupSignal, mount, register, Signal } from "@kt3k/cell"
10+
import * as ht from "@kt3k/ht"
11+
1212
import { BlockMap, FieldBlock, ObjectSpawnInfo } from "../model/field-block.ts"
1313
import { Object } from "../model/object.ts"
1414
import { floorN, modulo } from "../util/math.ts"
1515
import { memoizedLoading } from "../util/memo.ts"
1616
import { CanvasWrapper } from "../util/canvas-wrapper.ts"
17-
import { type Context, GroupSignal, mount, register, Signal } from "@kt3k/cell"
1817
import type * as type from "./types.ts"
1918
import { BLOCK_SIZE, CELL_SIZE } from "../util/constants.ts"
2019

@@ -121,10 +120,9 @@ function ToolControlPanel({ el, on, subscribe }: Context<HTMLElement>) {
121120
toolbox.addCellTool({ kind: "cell", name: cell.name, id })
122121
let div = el.querySelector('[id="' + id + '"]')
123122
if (div) return div
124-
div = (
125-
<div id={id} class="inline-block p-1 m-1 rounded cursor-pointer">
126-
<canvas width="16" height="16" class="pointer-events-none"></canvas>
127-
</div>
123+
div = ht.div(
124+
{ id, class: "inline-block p-1 m-1 rounded cursor-pointer" },
125+
`<canvas width="16" height="16" class="pointer-events-none"></canvas>`,
128126
)
129127
const canvas = div.querySelector("canvas")!
130128
const ctx = canvas.getContext("2d")!
@@ -151,11 +149,14 @@ function ToolControlPanel({ el, on, subscribe }: Context<HTMLElement>) {
151149
const id = "object-remove"
152150
toolbox.addObjectTool({ kind: "object-remove", id })
153151
el.appendChild(
154-
<div id={id} class="inline-block p-1 m-1 rounded cursor-pointer">
155-
<span class="w-4 h-4 block text-xs text-center text-white pointer-events-none">
156-
φ
157-
</span>
158-
</div>,
152+
ht.div(
153+
{ id, class: "inline-block p-1 m-1 rounded cursor-pointer" },
154+
`
155+
<span class="w-4 h-4 block text-xs text-center text-white pointer-events-none">
156+
φ
157+
</span>
158+
`,
159+
),
159160
)
160161
}
161162

@@ -171,10 +172,9 @@ function ToolControlPanel({ el, on, subscribe }: Context<HTMLElement>) {
171172
new URL(src, fieldBlock.url).href,
172173
)
173174
await obj.loadAssets({ loadImage })
174-
const div = (
175-
<div id={id} class="inline-block p-1 m-1 rounded cursor-pointer">
176-
<canvas width="16" height="16" class="pointer-events-none"></canvas>
177-
</div>
175+
const div = ht.div(
176+
{ id, class: "inline-block p-1 m-1 rounded cursor-pointer" },
177+
`<canvas width="16" height="16" class="pointer-events-none"></canvas>`,
178178
)
179179
const canvas = div.querySelector("canvas")!
180180
const ctx = canvas.getContext("2d")!
@@ -213,14 +213,11 @@ function ModeIndicator({ subscribe, el }: Context<HTMLElement>) {
213213

214214
function MainContainer({ subscribe, el }: Context) {
215215
function createCanvasFromImageData(imageData: ImageData) {
216-
const canvas = (
217-
<canvas
218-
width={imageData.width}
219-
height={imageData.height}
220-
class="absolute top-0 left-0"
221-
>
222-
</canvas>
223-
) as HTMLCanvasElement
216+
const canvas = ht.canvas({
217+
width: imageData.width,
218+
height: imageData.height,
219+
class: "absolute top-0 left-0",
220+
})
224221
const ctx = canvas.getContext("2d")!
225222
ctx.putImageData(imageData, 0, 0)
226223
return canvas
@@ -244,15 +241,12 @@ function MainContainer({ subscribe, el }: Context) {
244241
mount("field-block-canvas", el)
245242

246243
{
247-
const objectsCanvas = (
248-
<canvas
249-
width={CANVAS_SIZE}
250-
height={CANVAS_SIZE}
251-
style={`left: ${SIDE_CANVAS_SIZE}px; top: ${SIDE_CANVAS_SIZE}px;`}
252-
class="absolute field-object-canvas pointer-events-none"
253-
>
254-
</canvas>
255-
) as HTMLCanvasElement
244+
const objectsCanvas = ht.canvas({
245+
width: CANVAS_SIZE,
246+
height: CANVAS_SIZE,
247+
style: `left: ${SIDE_CANVAS_SIZE}px; top: ${SIDE_CANVAS_SIZE}px;`,
248+
class: "absolute field-object-canvas pointer-events-none",
249+
})
256250
el.appendChild(objectsCanvas)
257251
mount("field-object-canvas", el)
258252
const wrapper = new CanvasWrapper(objectsCanvas)
@@ -297,14 +291,10 @@ function MainContainer({ subscribe, el }: Context) {
297291
const blockMap = new BlockMap(href, JSON.parse(text))
298292
const fieldBlock = new FieldBlock(blockMap)
299293
await fieldBlock.loadAssets({ loadImage })
300-
const a = (
301-
<a
302-
class="absolute opacity-50 hover:bg-neutral-700 bg-neutral-800 break-all"
303-
href={href.replace(/^file:\/\//, "vscode://file")}
304-
>
305-
block_{k}.{l}.json
306-
</a>
307-
)
294+
const a = ht.a({
295+
class: "absolute hover:bg-neutral-700 bg-neutral-800 break-all",
296+
href: href.replace(/^file:\/\//, "vscode://file"),
297+
}, `block_${k}.${l}.json`)
308298
if (dx === -1) {
309299
const imageData = fieldBlock.createImageDataForRange(
310300
BLOCK_SIZE - 5,

0 commit comments

Comments
 (0)