kasaframe 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/NOTICE +146 -0
- package/README.md +77 -2
- package/app/package.json +12 -0
- package/app/server/engine.ts +415 -0
- package/app/server/main.ts +205 -0
- package/app/web/env.d.ts +2 -0
- package/app/web/icons.ts +31 -0
- package/app/web/index.html +21 -0
- package/app/web/main.ts +1013 -0
- package/app/web/style.css +430 -0
- package/bin/hooks.mjs +51 -0
- package/bin/kf.mjs +14 -0
- package/docs/AGENTS.md +238 -0
- package/music/README.md +13 -0
- package/package.json +44 -4
- package/packages/adapters/package.json +36 -0
- package/packages/adapters/src/css.ts +11 -0
- package/packages/adapters/src/gsap.ts +26 -0
- package/packages/adapters/src/index.ts +9 -0
- package/packages/adapters/src/lottie.ts +22 -0
- package/packages/adapters/src/media.ts +59 -0
- package/packages/adapters/src/page.ts +229 -0
- package/packages/adapters/src/project.ts +214 -0
- package/packages/adapters/src/react.ts +36 -0
- package/packages/adapters/src/svelte.ts +22 -0
- package/packages/adapters/src/three.ts +18 -0
- package/packages/adapters/src/vue.ts +27 -0
- package/packages/check/package.json +19 -0
- package/packages/check/src/check.ts +273 -0
- package/packages/check/src/cli.ts +70 -0
- package/packages/check/src/image.ts +146 -0
- package/packages/check/src/index.ts +9 -0
- package/packages/check/src/ocr.swift +37 -0
- package/packages/check/src/probe.ts +328 -0
- package/packages/check/src/report.ts +44 -0
- package/packages/check/src/rules/assets.ts +42 -0
- package/packages/check/src/rules/beats.ts +212 -0
- package/packages/check/src/rules/camera.ts +217 -0
- package/packages/check/src/rules/captions.ts +49 -0
- package/packages/check/src/rules/flash.ts +235 -0
- package/packages/check/src/rules/frames.ts +135 -0
- package/packages/check/src/rules/layout.ts +257 -0
- package/packages/check/src/rules/page.ts +87 -0
- package/packages/check/src/rules/runs.ts +20 -0
- package/packages/check/src/rules/text.ts +326 -0
- package/packages/check/src/scan.ts +240 -0
- package/packages/check/src/serve.ts +67 -0
- package/packages/check/src/types.ts +80 -0
- package/packages/check/src/video.ts +137 -0
- package/packages/cli/package.json +29 -0
- package/packages/cli/src/blur.ts +68 -0
- package/packages/cli/src/browser.ts +203 -0
- package/packages/cli/src/command.ts +44 -0
- package/packages/cli/src/commands/app.ts +25 -0
- package/packages/cli/src/commands/beats.ts +36 -0
- package/packages/cli/src/commands/blender.ts +270 -0
- package/packages/cli/src/commands/check.ts +25 -0
- package/packages/cli/src/commands/doctor.ts +22 -0
- package/packages/cli/src/commands/gen.ts +173 -0
- package/packages/cli/src/commands/look.ts +39 -0
- package/packages/cli/src/commands/lyrics.ts +111 -0
- package/packages/cli/src/commands/make.ts +542 -0
- package/packages/cli/src/commands/new.ts +176 -0
- package/packages/cli/src/commands/preview.ts +43 -0
- package/packages/cli/src/commands/render.ts +216 -0
- package/packages/cli/src/commands/setup.ts +63 -0
- package/packages/cli/src/commands/sheet.ts +114 -0
- package/packages/cli/src/commands/skill.ts +43 -0
- package/packages/cli/src/commands/still.ts +40 -0
- package/packages/cli/src/commands/theme.ts +85 -0
- package/packages/cli/src/commands/transitions.ts +40 -0
- package/packages/cli/src/deps.ts +122 -0
- package/packages/cli/src/ffmpeg.ts +81 -0
- package/packages/cli/src/index.ts +8 -0
- package/packages/cli/src/kf.ts +53 -0
- package/packages/cli/src/lock.ts +72 -0
- package/packages/cli/src/out.ts +13 -0
- package/packages/cli/src/serve.ts +124 -0
- package/packages/clock/package.json +14 -0
- package/packages/clock/src/index.ts +25 -0
- package/packages/clock/src/install.ts +351 -0
- package/packages/clock/src/types.ts +45 -0
- package/packages/core/package.json +9 -0
- package/packages/core/src/beats.ts +283 -0
- package/packages/core/src/ease.ts +87 -0
- package/packages/core/src/frame.ts +99 -0
- package/packages/core/src/index.ts +27 -0
- package/packages/core/src/project.ts +146 -0
- package/packages/core/src/rand.ts +56 -0
- package/packages/core/src/spring.ts +52 -0
- package/packages/core/src/style.ts +100 -0
- package/packages/core/src/time.ts +88 -0
- package/packages/gen/PROVIDERS.md +55 -0
- package/packages/gen/package.json +9 -0
- package/packages/gen/src/generate.ts +204 -0
- package/packages/gen/src/image/og.ts +133 -0
- package/packages/gen/src/index.ts +18 -0
- package/packages/gen/src/keys.ts +60 -0
- package/packages/gen/src/media.ts +150 -0
- package/packages/gen/src/plan.ts +106 -0
- package/packages/gen/src/registry.ts +51 -0
- package/packages/gen/src/seam.ts +103 -0
- package/packages/gen/src/types.ts +86 -0
- package/packages/gen/src/video/fal.ts +140 -0
- package/packages/gen/src/video/h3.ts +107 -0
- package/packages/gen/src/video/http.ts +44 -0
- package/packages/gen/src/video/ltx.ts +60 -0
- package/packages/gen/src/video/minimax.ts +55 -0
- package/packages/gen/src/video/veo.ts +71 -0
- package/packages/jizura/package.json +16 -0
- package/packages/jizura/src/deny.ts +73 -0
- package/packages/jizura/src/index.ts +7 -0
- package/packages/jizura/src/install.ts +226 -0
- package/packages/jizura/src/layer.ts +282 -0
- package/packages/jizura/src/lyrics.ts +81 -0
- package/packages/jizura/src/pin.ts +5 -0
- package/packages/jizura/src/vite.ts +36 -0
- package/packages/motion/README.md +142 -0
- package/packages/motion/package.json +29 -0
- package/packages/motion/src/camera.ts +97 -0
- package/packages/motion/src/captions.ts +479 -0
- package/packages/motion/src/enter.ts +128 -0
- package/packages/motion/src/hangul.ts +129 -0
- package/packages/motion/src/impact.ts +100 -0
- package/packages/motion/src/index.ts +17 -0
- package/packages/motion/src/moves/brushWipe.ts +90 -0
- package/packages/motion/src/moves/cloneArray.ts +111 -0
- package/packages/motion/src/moves/curtains.ts +81 -0
- package/packages/motion/src/moves/echoStack.ts +70 -0
- package/packages/motion/src/moves/fit.ts +34 -0
- package/packages/motion/src/moves/flood.ts +61 -0
- package/packages/motion/src/moves/ghostStack.ts +79 -0
- package/packages/motion/src/moves/gridFloor.ts +100 -0
- package/packages/motion/src/moves/imageSwarm.ts +109 -0
- package/packages/motion/src/moves/index.ts +19 -0
- package/packages/motion/src/moves/irisBlades.ts +113 -0
- package/packages/motion/src/moves/karaokeLine.ts +94 -0
- package/packages/motion/src/moves/ledBoard.ts +94 -0
- package/packages/motion/src/moves/liquidTab.ts +72 -0
- package/packages/motion/src/moves/markerWrite.ts +63 -0
- package/packages/motion/src/moves/morphBox.ts +96 -0
- package/packages/motion/src/moves/neonSign.ts +77 -0
- package/packages/motion/src/moves/panelPop.ts +78 -0
- package/packages/motion/src/moves/paperTear.ts +75 -0
- package/packages/motion/src/moves/path.ts +64 -0
- package/packages/motion/src/moves/pathText.ts +107 -0
- package/packages/motion/src/moves/pointSphere.ts +109 -0
- package/packages/motion/src/moves/ransomLetters.ts +73 -0
- package/packages/motion/src/moves/shapeMorph.ts +143 -0
- package/packages/motion/src/moves/slamWords.ts +89 -0
- package/packages/motion/src/moves/sparkTrail.ts +114 -0
- package/packages/motion/src/moves/speedLines.ts +91 -0
- package/packages/motion/src/moves/splitFlap.ts +147 -0
- package/packages/motion/src/moves/stepWords.ts +117 -0
- package/packages/motion/src/moves/strikeOut.ts +98 -0
- package/packages/motion/src/moves/sunburst.ts +58 -0
- package/packages/motion/src/moves/tickerRows.ts +87 -0
- package/packages/motion/src/moves/tokenPicker.ts +114 -0
- package/packages/motion/src/moves/truchet.ts +85 -0
- package/packages/motion/src/moves/wordWall.ts +76 -0
- package/packages/motion/src/moves/worldRoll.ts +31 -0
- package/packages/motion/src/particles.ts +102 -0
- package/packages/motion/src/react/index.tsx +21 -0
- package/packages/motion/src/react/parts.tsx +431 -0
- package/packages/motion/src/react/time.tsx +97 -0
- package/packages/motion/src/text.ts +103 -0
- package/packages/motion/src/transition.ts +82 -0
- package/packages/motion/src/transition3d/cards.ts +65 -0
- package/packages/motion/src/transition3d/chain.ts +84 -0
- package/packages/motion/src/transition3d/dive.ts +181 -0
- package/packages/motion/src/transition3d/fold.ts +110 -0
- package/packages/motion/src/transition3d/gl.ts +219 -0
- package/packages/motion/src/transition3d/index.ts +228 -0
- package/packages/motion/src/transition3d/live.ts +70 -0
- package/packages/motion/src/transition3d/portal.ts +115 -0
- package/packages/motion/src/transition3d/react.tsx +29 -0
- package/packages/motion/src/transition3d/rig.ts +502 -0
- package/packages/motion/src/transition3d/shatter.ts +101 -0
- package/packages/motion/src/transition3d/whip.ts +65 -0
- package/packages/motion/src/transition3d/world.ts +683 -0
- package/packages/motion/src/transition3d/zoomOut.ts +114 -0
- package/packages/motion/src/transitions2d/catalog.ts +127 -0
- package/packages/motion/src/transitions2d/css.d.ts +2 -0
- package/packages/motion/src/transitions2d/cult-ui/LICENSE.md +9 -0
- package/packages/motion/src/transitions2d/cult-ui/RollingNumber.tsx +43 -0
- package/packages/motion/src/transitions2d/gl-transitions/LICENSE +25 -0
- package/packages/motion/src/transitions2d/gl-transitions/shaders.ts +1931 -0
- package/packages/motion/src/transitions2d/index.ts +2 -0
- package/packages/motion/src/transitions2d/kokonutui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.css +16 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.tsx +94 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.css +15 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.tsx +115 -0
- package/packages/motion/src/transitions2d/magicui/LICENSE.md +21 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.css +25 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.tsx +130 -0
- package/packages/motion/src/transitions2d/magicui/WordRotate.tsx +42 -0
- package/packages/motion/src/transitions2d/react.ts +13 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.css +39 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.tsx +32 -0
- package/packages/motion/src/transitions2d/smoothui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/smoothui/SharedAxisY.tsx +50 -0
- package/packages/motion/src/transitions2d/smoothui/TextMorph.tsx +90 -0
- package/packages/motion/src/transitions2d/smoothui/shaders.ts +223 -0
- package/packages/motion/src/transitions2d/unlumen/LICENSE +21 -0
- package/packages/motion/src/transitions2d/unlumen/ScrambleText.tsx +114 -0
- package/packages/motion/src/transitions2d/vengeance-ui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.css +69 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.tsx +45 -0
- package/packages/motion/src/type.ts +131 -0
- package/packages/motion/src/ui.ts +172 -0
- package/packages/plan/package.json +15 -0
- package/packages/plan/src/brief.ts +254 -0
- package/packages/plan/src/captions.ts +75 -0
- package/packages/plan/src/detect.ts +93 -0
- package/packages/plan/src/index.ts +23 -0
- package/packages/plan/src/layout.ts +176 -0
- package/packages/plan/src/llm.ts +110 -0
- package/packages/plan/src/look.ts +220 -0
- package/packages/plan/src/plan.ts +125 -0
- package/packages/plan/src/request.ts +55 -0
- package/packages/plan/src/studio.ts +53 -0
- package/packages/plan/src/templates.ts +42 -0
- package/packages/plan/src/themes.ts +48 -0
- package/packages/plan/src/types.ts +106 -0
- package/packages/studio/package.json +12 -0
- package/packages/studio/src/index.ts +1 -0
- package/packages/studio/src/plugin.ts +236 -0
- package/packages/studio/src/ui/main.ts +503 -0
- package/packages/studio/src/ui/studio.css +165 -0
- package/packages/studio/src/ui/timeline.ts +317 -0
- package/packages/themes/kit/THEME-MAKE.md +68 -0
- package/packages/themes/kit/THEME.md +30 -0
- package/packages/themes/kit/briefs/og-intro-15s/brief.json +16 -0
- package/packages/themes/kit/briefs/og-intro-15s/facts.ts +29 -0
- package/packages/themes/kit/briefs/og-intro-15s/logo.svg +12 -0
- package/packages/themes/kit/effects.ts +5 -0
- package/packages/themes/kit/sample/index.html +11 -0
- package/packages/themes/kit/sample/main.ts +9 -0
- package/packages/themes/kit/sample/scenes/scene.ts +15 -0
- package/packages/themes/package.json +16 -0
- package/packages/themes/src/factory.ts +296 -0
- package/packages/themes/src/fx.ts +14 -0
- package/packages/themes/src/index.ts +105 -0
- package/packages/themes/src/stage3d.ts +177 -0
- package/packages/themes/src/types.ts +58 -0
- package/presets/kawaii-pastel.json +94 -0
- package/presets/neutral-dark.json +82 -0
- package/presets/og.json +98 -0
- package/skills/kasaframe/SKILL.md +32 -0
- package/templates/_shared/project/index.html +11 -0
- package/templates/_shared/project/lib/react.ts +22 -0
- package/templates/_shared/project/lib/stage.ts +272 -0
- package/templates/_shared/project/main.ts +9 -0
- package/templates/_shared/scenes/default.ts +18 -0
- package/templates/_shared/scenes/drop.ts +30 -0
- package/templates/_shared/scenes/end.ts +23 -0
- package/templates/_shared/scenes/hook.ts +16 -0
- package/templates/_shared/scenes/seam.ts +41 -0
- package/templates/_shared/scenes/step.ts +40 -0
- package/templates/ad/preview.png +0 -0
- package/templates/ad/template.json +132 -0
- package/templates/demo/preview.png +0 -0
- package/templates/demo/template.json +130 -0
- package/templates/explainer/preview.png +0 -0
- package/templates/explainer/template.json +142 -0
- package/templates/launch/preview.png +0 -0
- package/templates/launch/template.json +130 -0
- package/templates/mv/preview.png +0 -0
- package/templates/mv/scenes/default.ts +95 -0
- package/templates/mv/template.json +176 -0
- package/templates/promo/preview.png +0 -0
- package/templates/promo/template.json +144 -0
- package/templates/shorts/preview.png +0 -0
- package/templates/shorts/scenes/hook.ts +34 -0
- package/templates/shorts/template.json +127 -0
- package/templates/square/preview.png +0 -0
- package/templates/square/template.json +113 -0
- package/themes/debug-hud/THEME.md +39 -0
- package/themes/debug-hud/effects.ts +389 -0
- package/themes/debug-hud/sample/assets/og/logo.svg +12 -0
- package/themes/debug-hud/sample/beats.json +1 -0
- package/themes/debug-hud/sample/index.html +11 -0
- package/themes/debug-hud/sample/kf.json +59 -0
- package/themes/debug-hud/sample/lib/hudkit.ts +49 -0
- package/themes/debug-hud/sample/lib/og.ts +29 -0
- package/themes/debug-hud/sample/main.ts +9 -0
- package/themes/debug-hud/sample/scenes/end.ts +62 -0
- package/themes/debug-hud/sample/scenes/gather.ts +67 -0
- package/themes/debug-hud/sample/scenes/models.ts +70 -0
- package/themes/debug-hud/sample/scenes/price.ts +79 -0
- package/themes/debug-hud/sample/style.json +91 -0
- package/themes/debug-hud/still.png +0 -0
- package/themes/debug-hud/style.json +91 -0
- package/themes/debug-hud/theme.json +68 -0
- package/themes/og-measure/THEME.md +47 -0
- package/themes/og-measure/effects.ts +432 -0
- package/themes/og-measure/sample/assets/brand/og-logo-full.svg +12 -0
- package/themes/og-measure/sample/assets/brand/og-logo.svg +12 -0
- package/themes/og-measure/sample/assets/data/measure.json +353 -0
- package/themes/og-measure/sample/beats.json +1 -0
- package/themes/og-measure/sample/index.html +11 -0
- package/themes/og-measure/sample/kf.json +66 -0
- package/themes/og-measure/sample/lib/data.ts +62 -0
- package/themes/og-measure/sample/main.ts +9 -0
- package/themes/og-measure/sample/measure.ts +78 -0
- package/themes/og-measure/sample/scenes/end.ts +47 -0
- package/themes/og-measure/sample/scenes/gather.ts +51 -0
- package/themes/og-measure/sample/scenes/models.ts +34 -0
- package/themes/og-measure/sample/scenes/one.ts +39 -0
- package/themes/og-measure/sample/scenes/price.ts +56 -0
- package/themes/og-measure/sample/style.json +97 -0
- package/themes/og-measure/still.png +0 -0
- package/themes/og-measure/style.json +97 -0
- package/themes/og-measure/theme.json +79 -0
- package/themes/riso-zine/THEME.md +43 -0
- package/themes/riso-zine/effects.ts +321 -0
- package/themes/riso-zine/sample/assets/og/logo.svg +12 -0
- package/themes/riso-zine/sample/beats.json +1 -0
- package/themes/riso-zine/sample/index.html +11 -0
- package/themes/riso-zine/sample/kf.json +59 -0
- package/themes/riso-zine/sample/lib/og.ts +29 -0
- package/themes/riso-zine/sample/lib/shot.ts +86 -0
- package/themes/riso-zine/sample/lib/zine.ts +42 -0
- package/themes/riso-zine/sample/main.ts +9 -0
- package/themes/riso-zine/sample/scenes/end.ts +61 -0
- package/themes/riso-zine/sample/scenes/gather.ts +62 -0
- package/themes/riso-zine/sample/scenes/models.ts +52 -0
- package/themes/riso-zine/sample/scenes/price.ts +82 -0
- package/themes/riso-zine/sample/style.json +99 -0
- package/themes/riso-zine/still.png +0 -0
- package/themes/riso-zine/style.json +99 -0
- package/themes/riso-zine/theme.json +75 -0
- package/tools/beats/beats.py +372 -0
- package/tools/beats/requirements.txt +3 -0
- package/tools/lyrics/align.py +164 -0
- package/tools/lyrics/requirements.txt +9 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import type { ServerResponse } from "node:http";
|
|
6
|
+
import type { Plugin } from "vite";
|
|
7
|
+
|
|
8
|
+
const uiEntry = fileURLToPath(new URL("./ui/main.ts", import.meta.url));
|
|
9
|
+
const uiCss = fileURLToPath(new URL("./ui/studio.css", import.meta.url));
|
|
10
|
+
|
|
11
|
+
export interface StudioConfig {
|
|
12
|
+
name: string;
|
|
13
|
+
/** 미리보기 페이지에서 쓸 곡 주소. 없으면 진짜 시계로 돈다 */
|
|
14
|
+
music: string | null;
|
|
15
|
+
/** 곡에서 잘라 쓴 시작(초) — beats.json 의 from */
|
|
16
|
+
from: number;
|
|
17
|
+
kf: { fps: number; width: number; height: number; duration: number; scenes?: { id: string; from: number; dur: number }[] } | null;
|
|
18
|
+
/** 화면 자막 — mode 는 kf.json 의 captions 그대로, lines 는 captions.json 줄 수(0 이면 켜도 보일 게 없다) */
|
|
19
|
+
captions: { mode: string; lines: number };
|
|
20
|
+
beats: {
|
|
21
|
+
bpm?: number;
|
|
22
|
+
downbeats?: number[];
|
|
23
|
+
phrases?: number[];
|
|
24
|
+
sections?: { t: number; kind: string; strength?: number }[];
|
|
25
|
+
energy?: { hz: number; low: number[]; mid: number[]; high: number[] };
|
|
26
|
+
} | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readJson<T>(p: string): T | null {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(readFileSync(p, "utf8")) as T;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function expand(p: string): string {
|
|
38
|
+
return p.startsWith("~/") ? join(homedir(), p.slice(2)) : p;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface KfJson {
|
|
42
|
+
fps: number;
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
duration: number;
|
|
46
|
+
music?: string;
|
|
47
|
+
beats?: string;
|
|
48
|
+
captions?: string;
|
|
49
|
+
scenes?: { id: string; from: number; dur: number }[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BeatsFile extends NonNullable<StudioConfig["beats"]> {
|
|
53
|
+
source?: string;
|
|
54
|
+
from?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function load(root: string) {
|
|
58
|
+
const kf = readJson<KfJson>(join(root, "kf.json"));
|
|
59
|
+
const beatsPath = join(root, kf?.beats ?? "beats.json");
|
|
60
|
+
const beats = readJson<BeatsFile>(beatsPath);
|
|
61
|
+
let music: string | null = null;
|
|
62
|
+
if (kf?.music) music = resolve(root, expand(kf.music));
|
|
63
|
+
else if (beats?.source) music = resolve(dirname(beatsPath), expand(beats.source));
|
|
64
|
+
music = music && existsSync(music) ? realpathSync(music) : null;
|
|
65
|
+
return { kf, beats, music };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function urlFor(root: string, abs: string): string {
|
|
69
|
+
const rel = relative(root, abs);
|
|
70
|
+
const path = rel.startsWith("..") || isAbsolute(rel) ? `/@fs${abs}` : `/${rel.split(sep).join("/")}`;
|
|
71
|
+
return encodeURI(path);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 엔진이 Vite 루트를 실제 경로로 잡는다 — 감시 경로·/@fs 주소가 같은 꼴이어야 맞는다
|
|
75
|
+
const realRoot = (dir: string) => realpathSync(resolve(dir));
|
|
76
|
+
|
|
77
|
+
export function studioConfig(dir: string): StudioConfig {
|
|
78
|
+
const root = realRoot(dir);
|
|
79
|
+
const { kf, beats, music } = load(root);
|
|
80
|
+
return {
|
|
81
|
+
name: basename(root),
|
|
82
|
+
music: music ? urlFor(root, music) : null,
|
|
83
|
+
from: beats?.from ?? 0,
|
|
84
|
+
kf: kf ? { fps: kf.fps, width: kf.width, height: kf.height, duration: kf.duration, scenes: kf.scenes } : null,
|
|
85
|
+
captions: { mode: kf?.captions ?? "none", lines: readJson<unknown[]>(join(root, "captions.json"))?.length ?? 0 },
|
|
86
|
+
beats: beats
|
|
87
|
+
? { bpm: beats.bpm, downbeats: beats.downbeats, phrases: beats.phrases, sections: beats.sections, energy: beats.energy }
|
|
88
|
+
: null,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function esc(s: string): string {
|
|
93
|
+
return s.replace(/[&<>"]/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function studioHtml(name: string): string {
|
|
97
|
+
// Vite 클라이언트를 넣지 않는다 — 넣으면 장면 저장 때 미리보기 화면까지 새로 고쳐져 재생 위치·확대를 잃는다
|
|
98
|
+
return `<!doctype html>
|
|
99
|
+
<html lang="ko">
|
|
100
|
+
<head>
|
|
101
|
+
<meta charset="utf-8">
|
|
102
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
103
|
+
<title>${esc(name)} · kf preview</title>
|
|
104
|
+
<style>${readFileSync(uiCss, "utf8")}</style>
|
|
105
|
+
</head>
|
|
106
|
+
<body>
|
|
107
|
+
<div id="app"></div>
|
|
108
|
+
<script type="module" src="/@fs${encodeURI(uiEntry)}"></script>
|
|
109
|
+
</body>
|
|
110
|
+
</html>`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 렌더 결과·의존성·숨김 파일은 미리보기와 상관없다
|
|
114
|
+
function ignoredRel(rel: string): boolean {
|
|
115
|
+
const head = rel.split(sep)[0];
|
|
116
|
+
return rel === "" || rel.startsWith("..") || isAbsolute(rel) || head === "out" || head === "node_modules" || head.startsWith(".");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function scanFiles(root: string): string[] {
|
|
120
|
+
const out: string[] = [];
|
|
121
|
+
for (const rel of readdirSync(root, { recursive: true }) as string[]) {
|
|
122
|
+
if (ignoredRel(rel)) continue;
|
|
123
|
+
const abs = join(root, rel);
|
|
124
|
+
if (stamp(abs)?.startsWith("f")) out.push(abs);
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function stamp(abs: string): string | null {
|
|
130
|
+
try {
|
|
131
|
+
const st = statSync(abs);
|
|
132
|
+
return `${st.isFile() ? "f" : "d"}${st.mtimeMs}:${st.size}:${st.ino}`;
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 프로젝트 파일을 stat 으로 훑어 바뀐 것을 Vite 감시자에 넣는다. 두 번 연속 같은 값일 때만 — 반쯤 쓴 파일을 잡지 않게. */
|
|
139
|
+
export function pollProject(root: string, emit: (ev: "add" | "change" | "unlink", abs: string) => void): () => void {
|
|
140
|
+
const known = new Map<string, string>();
|
|
141
|
+
for (const abs of scanFiles(root)) known.set(abs, stamp(abs)!);
|
|
142
|
+
const pending = new Map<string, string | null>();
|
|
143
|
+
const settle = (abs: string, now: string | null) => {
|
|
144
|
+
if (pending.has(abs) && pending.get(abs) === now) {
|
|
145
|
+
pending.delete(abs);
|
|
146
|
+
if (now === null) {
|
|
147
|
+
if (known.delete(abs)) emit("unlink", abs);
|
|
148
|
+
} else {
|
|
149
|
+
emit(known.has(abs) ? "change" : "add", abs);
|
|
150
|
+
known.set(abs, now);
|
|
151
|
+
}
|
|
152
|
+
} else pending.set(abs, now);
|
|
153
|
+
};
|
|
154
|
+
const fast = setInterval(() => {
|
|
155
|
+
for (const [abs, was] of known) {
|
|
156
|
+
const now = stamp(abs);
|
|
157
|
+
if (now !== was || pending.has(abs)) settle(abs, now);
|
|
158
|
+
}
|
|
159
|
+
for (const abs of pending.keys()) if (!known.has(abs)) settle(abs, stamp(abs));
|
|
160
|
+
}, 100);
|
|
161
|
+
const slow = setInterval(() => {
|
|
162
|
+
for (const abs of scanFiles(root)) if (!known.has(abs) && !pending.has(abs)) pending.set(abs, stamp(abs));
|
|
163
|
+
}, 700);
|
|
164
|
+
return () => {
|
|
165
|
+
clearInterval(fast);
|
|
166
|
+
clearInterval(slow);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 미리보기 화면을 / 에, 프로젝트 페이지를 /index.html 에 낸다. 둘은 iframe 의 window.__kf 로만 말한다. */
|
|
171
|
+
export function studioPlugin(dir: string): Plugin {
|
|
172
|
+
const root = realRoot(dir);
|
|
173
|
+
return {
|
|
174
|
+
name: "kf-studio",
|
|
175
|
+
config() {
|
|
176
|
+
const { music } = load(root);
|
|
177
|
+
return {
|
|
178
|
+
server: {
|
|
179
|
+
...(music ? { fs: { allow: [dirname(music)] } } : {}),
|
|
180
|
+
// chokidar 는 파일마다 fs.watch 를 걸어서 이름을 바꿔 덮어쓰는 저장(편집기·에이전트의 원자적 쓰기)
|
|
181
|
+
// 뒤로 그 파일을 놓치고, macOS FSEvents 는 이벤트를 0.8초까지 묶어 늦게 준다. 프로젝트 폴더는 폴링이 맡는다.
|
|
182
|
+
watch: { ignored: (p: string) => p === root || p.startsWith(root + sep) },
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
},
|
|
186
|
+
configureServer(server) {
|
|
187
|
+
// Vite 는 모듈 그래프에 없는 파일(fetch 로 읽는 json·그림)이 바뀌면 아무것도 안 한다.
|
|
188
|
+
// 미리보기에 따로 알려, Vite 가 iframe 을 안 고치면 미리보기가 고친다.
|
|
189
|
+
const clients = new Set<ServerResponse>();
|
|
190
|
+
const broadcast = (o: object) => {
|
|
191
|
+
const msg = `data: ${JSON.stringify(o)}\n\n`;
|
|
192
|
+
for (const c of clients) c.write(msg);
|
|
193
|
+
};
|
|
194
|
+
const stop = pollProject(root, (ev, abs) => {
|
|
195
|
+
server.watcher.emit(ev, abs);
|
|
196
|
+
broadcast({ ev, file: relative(root, abs).split(sep).join("/") });
|
|
197
|
+
});
|
|
198
|
+
server.httpServer?.once("close", stop);
|
|
199
|
+
|
|
200
|
+
// 장면 파일 문법 오류는 iframe 이 다시 뜨는 사이에 나서 Vite 오류 화면이 안 붙는다 — 오류를 직접 넘긴다
|
|
201
|
+
const hot = server.environments.client.hot;
|
|
202
|
+
const send = hot.send.bind(hot) as (...a: unknown[]) => void;
|
|
203
|
+
hot.send = ((...a: unknown[]) => {
|
|
204
|
+
const p = a[0] as { type?: string; err?: { message?: string; id?: string; frame?: string; loc?: { file?: string; line?: number } } };
|
|
205
|
+
if (p?.type === "error" && p.err) {
|
|
206
|
+
const where = p.err.loc?.file ? `${relative(root, p.err.loc.file)}:${p.err.loc.line ?? ""}` : (p.err.id ?? "");
|
|
207
|
+
broadcast({ ev: "error", message: p.err.message ?? "", where, frame: p.err.frame ?? "" });
|
|
208
|
+
}
|
|
209
|
+
send(...a);
|
|
210
|
+
}) as typeof hot.send;
|
|
211
|
+
server.middlewares.use((req, res, next) => {
|
|
212
|
+
const path = (req.url ?? "/").split("?")[0];
|
|
213
|
+
if (path === "/" || path === "/__kf/studio") {
|
|
214
|
+
res.setHeader("content-type", "text/html; charset=utf-8");
|
|
215
|
+
res.setHeader("cache-control", "no-store");
|
|
216
|
+
res.end(studioHtml(basename(root)));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (path === "/__kf/events") {
|
|
220
|
+
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
|
|
221
|
+
res.write(": kf\n\n");
|
|
222
|
+
clients.add(res);
|
|
223
|
+
req.on("close", () => clients.delete(res));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (path === "/__kf/studio.json") {
|
|
227
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
228
|
+
res.setHeader("cache-control", "no-store");
|
|
229
|
+
res.end(JSON.stringify(studioConfig(root)));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
next();
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|