Skip to content

Commit d7ab095

Browse files
committed
refactor previous commit
1 parent cd94a07 commit d7ab095

7 files changed

Lines changed: 149 additions & 71 deletions

File tree

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
[*.md]
10+
trim_trailing_whitespace = false

.prettierignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node_modules
2+
dist
3+
dist-render
4+
dist-electron
5+
frames
6+
bin
7+
docs/build
8+
docs/.docusaurus
9+
output.mp4
10+
output.gif
11+
output_youtube.mp4
12+
frame-script.gif
13+
circle.gif
14+
assets/NotoSerifCJKJP-Medium.ttf
15+
package-lock.json
16+
docs/package-lock.json

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"semi": false,
5+
"singleQuote": false
6+
}

package-lock.json

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

package.json

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,67 @@
11
{
2-
"name": "frame-script",
3-
"private": true,
4-
"version": "0.0.9",
5-
"type": "module",
6-
"scripts": {
7-
"dev:vite": "vite --config vite.studio.config.ts",
8-
"build:vite": "vite build --config vite.studio.config.ts",
9-
"dev:render": "vite --config vite.render.config.ts",
10-
"build:render": "vite build --config vite.render.config.ts",
11-
"preview": "vite preview --config vite.studio.config.ts",
12-
"build:electron": "tsc -p tsconfig.electron.json",
13-
"dev": "concurrently -k \"npm:dev:vite\" \"npm:dev:render\" \"npm:dev:electron\"",
14-
"predev:electron": "tsc -p tsconfig.electron.json",
15-
"dev:electron": "wait-on http://localhost:5173 && cross-env VITE_DEV_SERVER_URL=http://localhost:5173 electron ./dist-electron/main.js",
16-
"build": "npm run build:vite && npm run build:electron",
17-
"build:all": "npm run build && npm run build:render",
18-
"build:binaries": "node ./scripts/build-binaries.mjs",
19-
"predev:electron:bin": "tsc -p tsconfig.electron.json",
20-
"dev:electron:bin": "wait-on http://localhost:5173 http://localhost:5174/render && cross-env VITE_DEV_SERVER_URL=http://localhost:5173 RENDER_DEV_SERVER_URL=http://localhost:5174/render FRAMESCRIPT_RUN_MODE=bin electron ./dist-electron/main.js",
21-
"dev:bin": "concurrently -k \"npm:dev:vite\" \"npm:dev:render\" \"npm:dev:electron:bin\"",
22-
"start": "npm run dev:bin",
23-
"start:bin": "npm run build:all && npm run build:binaries && node ./scripts/start-bin.mjs",
24-
"start:bin:skip-build": "node ./scripts/start-bin.mjs",
25-
"docs:start": "npm --prefix docs run start",
26-
"docs:build": "npm --prefix docs run build",
27-
"docs:serve": "npm --prefix docs run serve"
28-
},
29-
"dependencies": {
30-
"@ffmpeg-installer/ffmpeg": "^1.1.0",
31-
"@ffprobe-installer/ffprobe": "^2.1.2",
32-
"@types/opentype.js": "^1.3.4",
33-
"ag-psd": "^30.1.0",
34-
"ag-psd-psdtool": "^1.1.10",
35-
"mathjax-full": "^3.2.1",
36-
"opentype.js": "^1.3.4",
37-
"prismjs": "^1.30.0",
38-
"puppeteer": "^24.1.1",
39-
"react": "^19.2.0",
40-
"react-dom": "^19.2.0",
41-
"react-router-dom": "^6.28.0",
42-
"three": "^0.166.1"
43-
},
44-
"devDependencies": {
45-
"@eslint/js": "^9.39.1",
46-
"@types/node": "^24.10.1",
47-
"@types/react": "^19.2.5",
48-
"@types/react-dom": "^19.2.3",
49-
"@types/three": "^0.166.0",
50-
"@vitejs/plugin-react": "^5.1.1",
51-
"@webgpu/types": "^0.1.67",
52-
"concurrently": "^9.2.1",
53-
"cross-env": "^10.1.0",
54-
"electron": "^39.2.5",
55-
"eslint": "^9.39.1",
56-
"eslint-plugin-react-hooks": "^7.0.1",
57-
"eslint-plugin-react-refresh": "^0.4.24",
58-
"globals": "^16.5.0",
59-
"typescript": "~5.9.3",
60-
"typescript-eslint": "^8.46.4",
61-
"vite": "^7.2.4",
62-
"wait-on": "^9.0.3"
63-
}
2+
"name": "frame-script",
3+
"private": true,
4+
"version": "0.0.9",
5+
"type": "module",
6+
"scripts": {
7+
"dev:vite": "vite --config vite.studio.config.ts",
8+
"build:vite": "vite build --config vite.studio.config.ts",
9+
"dev:render": "vite --config vite.render.config.ts",
10+
"build:render": "vite build --config vite.render.config.ts",
11+
"preview": "vite preview --config vite.studio.config.ts",
12+
"build:electron": "tsc -p tsconfig.electron.json",
13+
"dev": "concurrently -k \"npm:dev:vite\" \"npm:dev:render\" \"npm:dev:electron\"",
14+
"predev:electron": "tsc -p tsconfig.electron.json",
15+
"dev:electron": "wait-on http://localhost:5173 && cross-env VITE_DEV_SERVER_URL=http://localhost:5173 electron ./dist-electron/main.js",
16+
"build": "npm run build:vite && npm run build:electron",
17+
"build:all": "npm run build && npm run build:render",
18+
"build:binaries": "node ./scripts/build-binaries.mjs",
19+
"predev:electron:bin": "tsc -p tsconfig.electron.json",
20+
"dev:electron:bin": "wait-on http://localhost:5173 http://localhost:5174/render && cross-env VITE_DEV_SERVER_URL=http://localhost:5173 RENDER_DEV_SERVER_URL=http://localhost:5174/render FRAMESCRIPT_RUN_MODE=bin electron ./dist-electron/main.js",
21+
"dev:bin": "concurrently -k \"npm:dev:vite\" \"npm:dev:render\" \"npm:dev:electron:bin\"",
22+
"start": "npm run dev:bin",
23+
"start:bin": "npm run build:all && npm run build:binaries && node ./scripts/start-bin.mjs",
24+
"start:bin:skip-build": "node ./scripts/start-bin.mjs",
25+
"docs:start": "npm --prefix docs run start",
26+
"docs:build": "npm --prefix docs run build",
27+
"docs:serve": "npm --prefix docs run serve",
28+
"format": "prettier --write .",
29+
"format:check": "prettier --check ."
30+
},
31+
"dependencies": {
32+
"@ffmpeg-installer/ffmpeg": "^1.1.0",
33+
"@ffprobe-installer/ffprobe": "^2.1.2",
34+
"@types/opentype.js": "^1.3.4",
35+
"ag-psd": "^30.1.0",
36+
"ag-psd-psdtool": "^1.1.10",
37+
"mathjax-full": "^3.2.1",
38+
"opentype.js": "^1.3.4",
39+
"prismjs": "^1.30.0",
40+
"puppeteer": "^24.1.1",
41+
"react": "^19.2.0",
42+
"react-dom": "^19.2.0",
43+
"react-router-dom": "^6.28.0",
44+
"three": "^0.166.1"
45+
},
46+
"devDependencies": {
47+
"@eslint/js": "^9.39.1",
48+
"@types/node": "^24.10.1",
49+
"@types/react": "^19.2.5",
50+
"@types/react-dom": "^19.2.3",
51+
"@types/three": "^0.166.0",
52+
"@vitejs/plugin-react": "^5.1.1",
53+
"@webgpu/types": "^0.1.67",
54+
"concurrently": "^9.2.1",
55+
"cross-env": "^10.1.0",
56+
"electron": "^39.2.5",
57+
"eslint": "^9.39.1",
58+
"eslint-plugin-react-hooks": "^7.0.1",
59+
"eslint-plugin-react-refresh": "^0.4.24",
60+
"globals": "^16.5.0",
61+
"prettier": "^3.8.3",
62+
"typescript": "~5.9.3",
63+
"typescript-eslint": "^8.46.4",
64+
"vite": "^7.2.4",
65+
"wait-on": "^9.0.3"
66+
}
6467
}

src/lib/character/character-unit/parser.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import { PsdCharacterElement as PsdElm } from "./ast"
44

55
type AnyElement = ReactElement<any, any>
66

7+
const expandDslFunction = (child: AnyElement): ReactNode => {
8+
const component = child.type as (props: Record<string, unknown>) => ReactNode
9+
return component(child.props)
10+
}
11+
12+
const expandDslElement = (child: AnyElement): AnyElement => {
13+
const expanded = expandDslFunction(child)
14+
if (!isValidElement(expanded)) {
15+
throw new Error("Expanded DSL component must return a single React element")
16+
}
17+
return expanded
18+
}
19+
720

821
export const parsePsdCharacter = (
922
children: ReactNode,
@@ -41,7 +54,7 @@ const parsePsdCharacterChildren = (
4154
result.push(parseMotion(child))
4255
break
4356
case "function":
44-
const expanded = child.type(child.props)
57+
const expanded = expandDslFunction(child)
4558
const expandedAst = parsePsdCharacterChildren(expanded)
4659
result.push(...expandedAst)
4760
break
@@ -91,7 +104,7 @@ const parseMotionSequenceChildren = (
91104
result.push(parseMotion(child))
92105
break
93106
case "function":
94-
const expanded = child.type(child.props)
107+
const expanded = expandDslFunction(child)
95108
const expandedAst = parseMotionSequenceChildren(expanded)
96109
result.push(...expandedAst)
97110
break
@@ -141,7 +154,7 @@ const parseDeclareVariableChild = (
141154
case PsdElm.DeclareAnimation:
142155
return parseDeclareAnimation(child)
143156
case "function":
144-
const expanded = child.type(child.props)
157+
const expanded = expandDslElement(child)
145158
const expandedAst = parseDeclareVariable(expanded)
146159
return expandedAst
147160

@@ -190,7 +203,7 @@ const parseMotionClipChildren = (
190203
result.push(parseMotion(child))
191204
break
192205
case "function":
193-
const expanded = child.type(child.props)
206+
const expanded = expandDslFunction(child)
194207
const expandedAst = parseMotionClipChildren(expanded)
195208
result.push(...expandedAst)
196209
break
@@ -241,7 +254,7 @@ const parseDeclareAnimationChildren = (
241254
result.push(parseMotion(child))
242255
break
243256
case "function":
244-
const expanded = child.type(child.props)
257+
const expanded = expandDslFunction(child)
245258
const expandedAst = parseDeclareAnimationChildren(expanded)
246259
result.push(...expandedAst)
247260
break

src/lib/character/character-unit/psd-character.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PsdCharacterElement as PsdElm, type MotionClipNode, type CharacterNode,
44
import { readPsd, type Psd } from "ag-psd"
55
import { parsePsdCharacter } from "./parser"
66
import { renderPsd } from "ag-psd-psdtool"
7-
import { useAnimation, useVariable, type Variable } from "../../animation"
7+
import { useAnimation, useVariable, type Variable, type VariableType } from "../../animation"
88
import { useCurrentFrame, useGlobalCurrentFrame } from "../../frame"
99
import { Sound } from "../../sound/sound"
1010
import { Clip, ClipSequence } from "../../clip"
@@ -260,6 +260,19 @@ type DeclareVariableRuntimeProps = {
260260
register: OptionRegister
261261
}
262262

263+
const useTypedVariable = (value: VariableType): Variable<VariableType> => {
264+
if (typeof value === "number") {
265+
return useVariable(value) as Variable<VariableType>
266+
}
267+
if (typeof value === "string") {
268+
return useVariable(value as `#${string}`) as Variable<VariableType>
269+
}
270+
if ("z" in value && typeof value.z === "number") {
271+
return useVariable({ x: value.x, y: value.y, z: value.z }) as Variable<VariableType>
272+
}
273+
return useVariable({ x: value.x, y: value.y }) as Variable<VariableType>
274+
}
275+
263276
const DeclareVariableRuntime = ({
264277
ast,
265278
variables,
@@ -270,7 +283,7 @@ const DeclareVariableRuntime = ({
270283
// DeclareVariableで受け取る型がTなので
271284
// ast.initValue: T
272285
// であり、これを使う限り問題ない
273-
const variable = useVariable(ast.initValue)
286+
const variable = useTypedVariable(ast.initValue)
274287
const newInitVariables = {[ast.variableName]: variable, ...initializingVariables}
275288

276289
switch (ast.children.type) {
@@ -544,7 +557,7 @@ const VoiceRuntimeInner = ({
544557
if (!reg.current) {
545558
reg.current = register()
546559
}
547-
const { update, getter, unregister } = reg.current
560+
const { update, unregister } = reg.current
548561

549562
useEffect(() => {
550563
return () => unregister()
@@ -597,7 +610,7 @@ const MotionRuntime = ({
597610
if (!reg.current) {
598611
reg.current = register()
599612
}
600-
const { update, getter, unregister } = reg.current
613+
const { update, unregister } = reg.current
601614

602615
useEffect(() => {
603616
return () => unregister()

0 commit comments

Comments
 (0)