hikkaku 0.1.0
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/package.json +25 -0
- package/src/blocks/control.ts +169 -0
- package/src/blocks/data.ts +203 -0
- package/src/blocks/events.ts +116 -0
- package/src/blocks/index.ts +9 -0
- package/src/blocks/looks.ts +189 -0
- package/src/blocks/motion.ts +146 -0
- package/src/blocks/operator.ts +219 -0
- package/src/blocks/procedures.ts +208 -0
- package/src/blocks/sensing.ts +129 -0
- package/src/blocks/sound.ts +77 -0
- package/src/client/fiber.ts +110 -0
- package/src/client/index.ts +26 -0
- package/src/client/types.ts +7 -0
- package/src/compiler/block-helper.ts +49 -0
- package/src/compiler/composer.ts +177 -0
- package/src/compiler/index.ts +6 -0
- package/src/compiler/project.ts +138 -0
- package/src/compiler/types.ts +37 -0
- package/src/index.ts +5 -0
- package/src/utils/assets.ts +4 -0
- package/src/vite/env.ts +46 -0
- package/src/vite/index.ts +77 -0
- package/tsconfig.json +3 -0
- package/tsdown.config.ts +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type * as sb3 from '@pnsk-lab/sb3-types'
|
|
2
|
+
import { createServerModuleRunner, type PluginOption } from 'vite'
|
|
3
|
+
|
|
4
|
+
const BASE_URL = 'https://scratchfoundation.github.io/scratch-gui/'
|
|
5
|
+
|
|
6
|
+
export interface HikkakuViteInit {
|
|
7
|
+
entry: string
|
|
8
|
+
}
|
|
9
|
+
export default function hikkaku(init: HikkakuViteInit): PluginOption {
|
|
10
|
+
return {
|
|
11
|
+
name: 'vite-plugin-hikkaku',
|
|
12
|
+
config() {
|
|
13
|
+
return {
|
|
14
|
+
environments: {
|
|
15
|
+
hikkaku: {},
|
|
16
|
+
client: {},
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
resolveId(source) {
|
|
21
|
+
if (source === '/@virtual/hikkaku-client') {
|
|
22
|
+
return source
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
load(id) {
|
|
26
|
+
if (id === '/@virtual/hikkaku-client') {
|
|
27
|
+
return `
|
|
28
|
+
import 'hikkaku/client'
|
|
29
|
+
`
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
async configureServer(server) {
|
|
33
|
+
const hikkakuEnv = server.environments.hikkaku
|
|
34
|
+
if (!hikkakuEnv) {
|
|
35
|
+
throw new Error('Hikkaku environment is not configured.')
|
|
36
|
+
}
|
|
37
|
+
const runner = createServerModuleRunner(hikkakuEnv)
|
|
38
|
+
await runner.import(init.entry)
|
|
39
|
+
hikkakuEnv.hot.on('hikkaku:project', (project: sb3.ScratchProject) => {
|
|
40
|
+
server.environments.client.hot.send('hikkaku:project', project)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
server.middlewares.use(async (req, res, next) => {
|
|
44
|
+
if (req.url === '/') {
|
|
45
|
+
const html = (await fetch(BASE_URL).then((res) => res.text()))
|
|
46
|
+
.replace(
|
|
47
|
+
'gui.js',
|
|
48
|
+
'https://scratchfoundation.github.io/scratch-gui/gui.js',
|
|
49
|
+
)
|
|
50
|
+
.replace(
|
|
51
|
+
'</head>',
|
|
52
|
+
'<script src="/@vite/client" type="module"></script><script type="module" src="/@virtual/hikkaku-client"></script></head>',
|
|
53
|
+
)
|
|
54
|
+
res.setHeader('Content-Type', 'text/html')
|
|
55
|
+
res.end(html)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
if (req.url?.startsWith('/static/')) {
|
|
59
|
+
const url = new URL(req.url.slice(1), BASE_URL)
|
|
60
|
+
const response = await fetch(url.toString())
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
res.statusCode = response.status
|
|
63
|
+
res.end(`Error fetching ${url}: ${response.statusText}`)
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
res.setHeader(
|
|
67
|
+
'Content-Type',
|
|
68
|
+
response.headers.get('content-type') || 'application/octet-stream',
|
|
69
|
+
)
|
|
70
|
+
res.end(new Uint8Array(await response.arrayBuffer()))
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
next()
|
|
74
|
+
})
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
}
|
package/tsconfig.json
ADDED
package/tsdown.config.ts
ADDED
|
File without changes
|