create-hypercolor 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/README.md +84 -0
- package/bin/create-hypercolor-effect.js +10 -0
- package/package.json +54 -0
- package/src/cli.ts +116 -0
- package/src/index.ts +21 -0
- package/src/naming.ts +23 -0
- package/src/prompts.ts +117 -0
- package/src/scaffold.ts +121 -0
- package/src/templates.ts +119 -0
- package/src/types.ts +59 -0
- package/templates/effects/canvas/audio/main.ts.template +49 -0
- package/templates/effects/canvas/base/main.ts.template +50 -0
- package/templates/effects/face/audio/main.ts.template +70 -0
- package/templates/effects/face/base/main.ts.template +68 -0
- package/templates/effects/html/__EFFECT_ID__.html.template +41 -0
- package/templates/effects/shader/audio/fragment.glsl.template +42 -0
- package/templates/effects/shader/audio/main.ts.template +24 -0
- package/templates/effects/shader/base/fragment.glsl.template +38 -0
- package/templates/effects/shader/base/main.ts.template +23 -0
- package/templates/workspace/html/.gitignore.template +2 -0
- package/templates/workspace/html/README.md.template +9 -0
- package/templates/workspace/html/package.json.template +18 -0
- package/templates/workspace/ts/.gitignore.template +3 -0
- package/templates/workspace/ts/README.md.template +14 -0
- package/templates/workspace/ts/biome.jsonc.template +45 -0
- package/templates/workspace/ts/bunfig.toml.template +5 -0
- package/templates/workspace/ts/package.json.template +26 -0
- package/templates/workspace/ts/tsconfig.json.template +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# create-hypercolor
|
|
2
|
+
|
|
3
|
+
Scaffolder for [Hypercolor](https://github.com/hyperb1iss/hypercolor) effect workspaces.
|
|
4
|
+
|
|
5
|
+
One command gives you a ready-to-run Bun workspace with `hypercolor` wired up, a starter effect, and the full authoring loop for build, validate, and install.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
The package is pre-release and not on npm yet. From a directory that contains a
|
|
10
|
+
`hypercolor/` checkout:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
cd hypercolor/sdk
|
|
14
|
+
bun install
|
|
15
|
+
cd ../..
|
|
16
|
+
bun ./hypercolor/sdk/packages/create-effect/bin/create-hypercolor-effect.js my-effects \
|
|
17
|
+
--template canvas \
|
|
18
|
+
--sdk-spec "file:../hypercolor/sdk/packages/core"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The scaffolder prompts you for any omitted template or first-effect option. For
|
|
22
|
+
audio-reactive starter boilerplate:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bun ./hypercolor/sdk/packages/create-effect/bin/create-hypercolor-effect.js my-effects \
|
|
26
|
+
--template canvas \
|
|
27
|
+
--first aurora \
|
|
28
|
+
--audio \
|
|
29
|
+
--sdk-spec "file:../hypercolor/sdk/packages/core"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
cd my-effects
|
|
36
|
+
bun run build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Templates
|
|
40
|
+
|
|
41
|
+
| Template | What you get |
|
|
42
|
+
| -------- | ----------------------------------------------- |
|
|
43
|
+
| `canvas` | TypeScript effect with a Canvas2D draw function |
|
|
44
|
+
| `shader` | TypeScript effect with a GLSL fragment shader |
|
|
45
|
+
| `face` | A device-face layout for sensor dashboards |
|
|
46
|
+
| `html` | A raw LightScript HTML effect, no TypeScript |
|
|
47
|
+
|
|
48
|
+
## Options
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
create-hypercolor-effect [name] [options]
|
|
52
|
+
|
|
53
|
+
--template <type> Starter template: canvas, shader, face, html
|
|
54
|
+
--first <effect-name> Name of the first effect (default: my-effect)
|
|
55
|
+
--audio Include audio-reactive starter boilerplate
|
|
56
|
+
--no-git Skip git init
|
|
57
|
+
--no-install Skip bun install
|
|
58
|
+
--sdk-spec <spec> Required while hypercolor is pre-release.
|
|
59
|
+
Point at a local checkout:
|
|
60
|
+
file:../hypercolor/sdk/packages/core
|
|
61
|
+
(HYPERCOLOR_SDK_PACKAGE_SPEC env var also works).
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Adding more effects
|
|
65
|
+
|
|
66
|
+
Once a workspace exists, scaffold additional effects with the workspace CLI:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bunx hypercolor add ember --template canvas
|
|
70
|
+
bunx hypercolor add skyline --template shader --audio
|
|
71
|
+
bunx hypercolor add flicker --template html
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Prerequisites
|
|
75
|
+
|
|
76
|
+
- Bun 1.2 or newer
|
|
77
|
+
|
|
78
|
+
## Documentation
|
|
79
|
+
|
|
80
|
+
See [Setup](https://github.com/hyperb1iss/hypercolor/tree/main/docs/content/effects/setup.md) and [Dev Workflow](https://github.com/hyperb1iss/hypercolor/tree/main/docs/content/effects/dev-workflow.md) for the full guide.
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
Apache-2.0
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
if (typeof Bun === 'undefined') {
|
|
4
|
+
console.error('create-hypercolor-effect requires Bun. Install Bun from https://bun.sh and try again.')
|
|
5
|
+
process.exit(1)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const cli = await import('../src/cli.ts')
|
|
9
|
+
const exitCode = await cli.main(process.argv.slice(2))
|
|
10
|
+
process.exit(typeof exitCode === 'number' ? exitCode : 0)
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-hypercolor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Bun create scaffolder for Hypercolor effect workspaces",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"module": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"create-hypercolor-effect": "./bin/create-hypercolor-effect.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./src/index.ts",
|
|
15
|
+
"types": "./src/index.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin",
|
|
20
|
+
"src",
|
|
21
|
+
"templates"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc --noEmit",
|
|
25
|
+
"dev": "tsc --noEmit --watch",
|
|
26
|
+
"typecheck": "tsc --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@clack/prompts": "^1.5.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^25.9.1",
|
|
33
|
+
"bun-types": "^1.3.14",
|
|
34
|
+
"typescript": "^6.0.3"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"bun": ">=1.2.0",
|
|
38
|
+
"node": ">=24.0.0"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"hypercolor",
|
|
42
|
+
"rgb",
|
|
43
|
+
"lighting",
|
|
44
|
+
"bun",
|
|
45
|
+
"scaffolding"
|
|
46
|
+
],
|
|
47
|
+
"author": "Stefanie Jane <stef@hyperbliss.tech>",
|
|
48
|
+
"license": "Apache-2.0",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/hyperb1iss/hypercolor",
|
|
52
|
+
"directory": "sdk/packages/create-effect"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { isTemplateKind, normalizeEffectId, normalizeWorkspaceName } from './naming'
|
|
2
|
+
import { promptWorkspaceOptions } from './prompts'
|
|
3
|
+
import { defaultSdkPackageSpec, resolveWorkspaceTarget, scaffoldWorkspace, workspaceNameFromTarget } from './scaffold'
|
|
4
|
+
import type { CliOutput, TemplateKind } from './types'
|
|
5
|
+
|
|
6
|
+
interface CliContext {
|
|
7
|
+
cwd: string
|
|
8
|
+
stdout: CliOutput
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function optionValue(args: string[], name: string): string | undefined {
|
|
12
|
+
const index = args.indexOf(name)
|
|
13
|
+
if (index === -1) return undefined
|
|
14
|
+
return args[index + 1]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function positionalArgs(args: string[]): string[] {
|
|
18
|
+
const positionals: string[] = []
|
|
19
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
20
|
+
const arg = args[index]
|
|
21
|
+
if (!arg) continue
|
|
22
|
+
if (arg.startsWith('--')) {
|
|
23
|
+
const next = args[index + 1]
|
|
24
|
+
if (next && !next.startsWith('--')) index += 1
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
positionals.push(arg)
|
|
28
|
+
}
|
|
29
|
+
return positionals
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function printHelp(stdout: CliOutput): void {
|
|
33
|
+
stdout.log(`create-hypercolor-effect [name] [options]
|
|
34
|
+
|
|
35
|
+
Options:
|
|
36
|
+
--template <type> Starter template: canvas, shader, face, html
|
|
37
|
+
--first <effect-name> Name of the first effect (default: my-effect)
|
|
38
|
+
--audio Include audio-reactive starter boilerplate
|
|
39
|
+
--no-git Skip git init
|
|
40
|
+
--no-install Skip bun install
|
|
41
|
+
--sdk-spec <spec> Required while hypercolor is pre-release.
|
|
42
|
+
Point at a local checkout:
|
|
43
|
+
file:../hypercolor/sdk/packages/core
|
|
44
|
+
(HYPERCOLOR_SDK_PACKAGE_SPEC env var also works).
|
|
45
|
+
`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function main(
|
|
49
|
+
argv = process.argv.slice(2),
|
|
50
|
+
context: CliContext = { cwd: process.cwd(), stdout: console },
|
|
51
|
+
): Promise<number> {
|
|
52
|
+
if (argv.includes('--help') || argv.includes('help')) {
|
|
53
|
+
printHelp(context.stdout)
|
|
54
|
+
return 0
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const [workspaceArg] = positionalArgs(argv)
|
|
58
|
+
const templateArg = optionValue(argv, '--template')
|
|
59
|
+
const templateCandidate = templateArg
|
|
60
|
+
const firstArg = optionValue(argv, '--first')
|
|
61
|
+
const sdkSpec = optionValue(argv, '--sdk-spec') ?? defaultSdkPackageSpec()
|
|
62
|
+
|
|
63
|
+
if (!sdkSpec) {
|
|
64
|
+
context.stdout.error(
|
|
65
|
+
'hypercolor is not published yet. Pass --sdk-spec file:../hypercolor/sdk/packages/core or set HYPERCOLOR_SDK_PACKAGE_SPEC.',
|
|
66
|
+
)
|
|
67
|
+
return 1
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const interactive = !workspaceArg || !templateArg
|
|
71
|
+
const prompted = interactive
|
|
72
|
+
? await promptWorkspaceOptions({
|
|
73
|
+
audio: argv.includes('--audio') ? true : undefined,
|
|
74
|
+
effectId: firstArg ? normalizeEffectId(firstArg) : undefined,
|
|
75
|
+
git: argv.includes('--no-git') ? false : undefined,
|
|
76
|
+
install: argv.includes('--no-install') ? false : undefined,
|
|
77
|
+
template: templateArg,
|
|
78
|
+
workspaceName: workspaceArg ? normalizeWorkspaceName(workspaceArg) : undefined,
|
|
79
|
+
})
|
|
80
|
+
: undefined
|
|
81
|
+
|
|
82
|
+
const workspaceName = prompted?.workspaceName ?? normalizeWorkspaceName(workspaceArg ?? '')
|
|
83
|
+
const template: TemplateKind | undefined =
|
|
84
|
+
prompted?.template ?? (templateCandidate && isTemplateKind(templateCandidate) ? templateCandidate : undefined)
|
|
85
|
+
const firstEffectId = prompted?.effectId ?? normalizeEffectId(firstArg ?? 'my-effect')
|
|
86
|
+
const audio = prompted?.audio ?? argv.includes('--audio')
|
|
87
|
+
const git = prompted?.git ?? !argv.includes('--no-git')
|
|
88
|
+
const install = prompted?.install ?? !argv.includes('--no-install')
|
|
89
|
+
|
|
90
|
+
if (!workspaceName || !template) {
|
|
91
|
+
context.stdout.error('Workspace name and template are required.')
|
|
92
|
+
return 1
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await scaffoldWorkspace({
|
|
96
|
+
audio,
|
|
97
|
+
firstEffectId,
|
|
98
|
+
git,
|
|
99
|
+
install,
|
|
100
|
+
output: context.stdout,
|
|
101
|
+
sdkPackageSpec: sdkSpec,
|
|
102
|
+
targetDir: resolveWorkspaceTarget(context.cwd, workspaceName),
|
|
103
|
+
template,
|
|
104
|
+
workspaceName: workspaceNameFromTarget(workspaceName),
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const nextCommand = template === 'html' ? 'bun run validate' : 'bun run build'
|
|
108
|
+
context.stdout.log(`\nNext steps:\n cd ${workspaceName}\n ${nextCommand}`)
|
|
109
|
+
|
|
110
|
+
return 0
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (import.meta.main) {
|
|
114
|
+
const exitCode = await main()
|
|
115
|
+
process.exit(exitCode)
|
|
116
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { main } from './cli'
|
|
2
|
+
export { displayNameFromEffectId, normalizeEffectId, normalizeWorkspaceName } from './naming'
|
|
3
|
+
export { promptAddEffectOptions, promptWorkspaceOptions } from './prompts'
|
|
4
|
+
export {
|
|
5
|
+
addEffect,
|
|
6
|
+
defaultSdkPackageSpec,
|
|
7
|
+
resolveEditor,
|
|
8
|
+
resolveWorkspaceTarget,
|
|
9
|
+
scaffoldWorkspace,
|
|
10
|
+
workspaceNameFromTarget,
|
|
11
|
+
} from './scaffold'
|
|
12
|
+
export type {
|
|
13
|
+
AddEffectOptions,
|
|
14
|
+
AddEffectResult,
|
|
15
|
+
CliOutput,
|
|
16
|
+
PromptedAddEffectOptions,
|
|
17
|
+
PromptedScaffoldOptions,
|
|
18
|
+
ScaffoldWorkspaceOptions,
|
|
19
|
+
ScaffoldWorkspaceResult,
|
|
20
|
+
TemplateKind,
|
|
21
|
+
} from './types'
|
package/src/naming.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function normalizeWorkspaceName(input: string): string {
|
|
2
|
+
return input.trim()
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function normalizeEffectId(input: string): string {
|
|
6
|
+
return input
|
|
7
|
+
.trim()
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
10
|
+
.replace(/^-+|-+$/g, '')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function displayNameFromEffectId(effectId: string): string {
|
|
14
|
+
return effectId
|
|
15
|
+
.split('-')
|
|
16
|
+
.filter(Boolean)
|
|
17
|
+
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
18
|
+
.join(' ')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isTemplateKind(value: string): value is import('./types').TemplateKind {
|
|
22
|
+
return value === 'canvas' || value === 'shader' || value === 'face' || value === 'html'
|
|
23
|
+
}
|
package/src/prompts.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { cancel, confirm, intro, isCancel, select, text } from '@clack/prompts'
|
|
2
|
+
|
|
3
|
+
import { isTemplateKind, normalizeEffectId, normalizeWorkspaceName } from './naming'
|
|
4
|
+
import type { PromptedAddEffectOptions, PromptedScaffoldOptions, TemplateKind } from './types'
|
|
5
|
+
|
|
6
|
+
function unwrapPrompt<T>(value: T | symbol): T {
|
|
7
|
+
if (!isCancel(value)) return value as T
|
|
8
|
+
cancel('Scaffolding canceled.')
|
|
9
|
+
throw new Error('Prompt canceled')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function templateOptions() {
|
|
13
|
+
return [
|
|
14
|
+
{ label: 'Canvas', value: 'canvas' },
|
|
15
|
+
{ label: 'Shader', value: 'shader' },
|
|
16
|
+
{ label: 'Face', value: 'face' },
|
|
17
|
+
{ label: 'HTML', value: 'html' },
|
|
18
|
+
] satisfies Array<{ label: string; value: TemplateKind }>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function promptEffectId(initialValue: string | undefined, label: string): Promise<string> {
|
|
22
|
+
if (initialValue) return initialValue
|
|
23
|
+
|
|
24
|
+
const value = unwrapPrompt(
|
|
25
|
+
await text({
|
|
26
|
+
message: label,
|
|
27
|
+
placeholder: 'my-effect',
|
|
28
|
+
validate(input) {
|
|
29
|
+
return normalizeEffectId(input ?? '').length > 0 ? undefined : 'Enter an effect name'
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
return normalizeEffectId(String(value))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function promptTemplate(initialValue: TemplateKind | undefined): Promise<TemplateKind> {
|
|
38
|
+
if (initialValue) return initialValue
|
|
39
|
+
return unwrapPrompt(
|
|
40
|
+
await select({
|
|
41
|
+
message: 'Pick a starter template',
|
|
42
|
+
options: templateOptions(),
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function promptAddEffectOptions(initial: {
|
|
48
|
+
audio?: boolean
|
|
49
|
+
effectId?: string
|
|
50
|
+
template?: string
|
|
51
|
+
}): Promise<PromptedAddEffectOptions> {
|
|
52
|
+
intro('Hypercolor effect starter')
|
|
53
|
+
|
|
54
|
+
const templateCandidate = initial.template
|
|
55
|
+
const seededTemplate: TemplateKind | undefined =
|
|
56
|
+
templateCandidate && isTemplateKind(templateCandidate) ? templateCandidate : undefined
|
|
57
|
+
const template = seededTemplate ?? (await promptTemplate(undefined))
|
|
58
|
+
const effectId = await promptEffectId(initial.effectId, 'Name for your effect')
|
|
59
|
+
const audio =
|
|
60
|
+
initial.audio ??
|
|
61
|
+
unwrapPrompt(
|
|
62
|
+
await confirm({
|
|
63
|
+
initialValue: false,
|
|
64
|
+
message: 'Audio reactive?',
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return { audio, effectId, template }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function promptWorkspaceOptions(initial: {
|
|
72
|
+
audio?: boolean
|
|
73
|
+
effectId?: string
|
|
74
|
+
git?: boolean
|
|
75
|
+
install?: boolean
|
|
76
|
+
template?: string
|
|
77
|
+
workspaceName?: string
|
|
78
|
+
}): Promise<PromptedScaffoldOptions> {
|
|
79
|
+
intro('Hypercolor workspace starter')
|
|
80
|
+
|
|
81
|
+
const workspaceName =
|
|
82
|
+
initial.workspaceName ??
|
|
83
|
+
normalizeWorkspaceName(
|
|
84
|
+
String(
|
|
85
|
+
unwrapPrompt(
|
|
86
|
+
await text({
|
|
87
|
+
message: "What's your workspace called?",
|
|
88
|
+
placeholder: 'my-effects',
|
|
89
|
+
validate(input) {
|
|
90
|
+
return normalizeWorkspaceName(input ?? '').length > 0 ? undefined : 'Enter a workspace name'
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
const templateCandidate = initial.template
|
|
97
|
+
const seededTemplate: TemplateKind | undefined =
|
|
98
|
+
templateCandidate && isTemplateKind(templateCandidate) ? templateCandidate : undefined
|
|
99
|
+
const template = seededTemplate ?? (await promptTemplate(undefined))
|
|
100
|
+
const effectId = await promptEffectId(initial.effectId, 'Name for your first effect')
|
|
101
|
+
const audio =
|
|
102
|
+
initial.audio ??
|
|
103
|
+
unwrapPrompt(
|
|
104
|
+
await confirm({
|
|
105
|
+
initialValue: false,
|
|
106
|
+
message: 'Audio reactive?',
|
|
107
|
+
}),
|
|
108
|
+
)
|
|
109
|
+
return {
|
|
110
|
+
audio,
|
|
111
|
+
effectId,
|
|
112
|
+
git: initial.git ?? true,
|
|
113
|
+
install: initial.install ?? true,
|
|
114
|
+
template,
|
|
115
|
+
workspaceName,
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/scaffold.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { normalizeEffectId, normalizeWorkspaceName } from './naming'
|
|
5
|
+
import { createEffectFiles, createWorkspaceFiles } from './templates'
|
|
6
|
+
import type {
|
|
7
|
+
AddEffectOptions,
|
|
8
|
+
AddEffectResult,
|
|
9
|
+
CliOutput,
|
|
10
|
+
ScaffoldWorkspaceOptions,
|
|
11
|
+
ScaffoldWorkspaceResult,
|
|
12
|
+
} from './types'
|
|
13
|
+
|
|
14
|
+
function output(consoleLike: CliOutput | undefined): CliOutput {
|
|
15
|
+
return consoleLike ?? console
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function assertDirectoryAvailable(targetDir: string): void {
|
|
19
|
+
if (!existsSync(targetDir)) return
|
|
20
|
+
if (readdirSync(targetDir).length === 0) return
|
|
21
|
+
throw new Error(`Target directory already exists and is not empty: ${targetDir}`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function runCommand(cmd: string[], cwd: string, message: string): Promise<void> {
|
|
25
|
+
const proc = Bun.spawn({
|
|
26
|
+
cmd,
|
|
27
|
+
cwd,
|
|
28
|
+
stderr: 'inherit',
|
|
29
|
+
stdin: 'ignore',
|
|
30
|
+
stdout: 'inherit',
|
|
31
|
+
})
|
|
32
|
+
const exitCode = await proc.exited
|
|
33
|
+
if (exitCode !== 0) {
|
|
34
|
+
throw new Error(`${message} (exit ${exitCode})`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function addEffect(options: AddEffectOptions): Promise<AddEffectResult> {
|
|
39
|
+
const effectId = normalizeEffectId(options.effectId)
|
|
40
|
+
if (!effectId) throw new Error('Effect name must resolve to a non-empty id')
|
|
41
|
+
|
|
42
|
+
const workspaceDir = resolve(options.workspaceDir)
|
|
43
|
+
const created = createEffectFiles({
|
|
44
|
+
audio: options.audio,
|
|
45
|
+
effectId,
|
|
46
|
+
template: options.template,
|
|
47
|
+
workspaceDir,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const stdout = output(options.output)
|
|
51
|
+
stdout.log(`Created ${effectId} (${options.template})`)
|
|
52
|
+
|
|
53
|
+
const editor = options.editor?.trim()
|
|
54
|
+
if (editor) {
|
|
55
|
+
await runCommand([editor, created.entryPath], workspaceDir, `Failed to open ${created.entryPath}`)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
createdPaths: created.createdPaths,
|
|
60
|
+
effectId,
|
|
61
|
+
entryPath: created.entryPath,
|
|
62
|
+
template: options.template,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function scaffoldWorkspace(options: ScaffoldWorkspaceOptions): Promise<ScaffoldWorkspaceResult> {
|
|
67
|
+
const workspaceName = normalizeWorkspaceName(options.workspaceName)
|
|
68
|
+
const firstEffectId = normalizeEffectId(options.firstEffectId)
|
|
69
|
+
if (!workspaceName) throw new Error('Workspace name must not be empty')
|
|
70
|
+
if (!firstEffectId) throw new Error('First effect name must resolve to a non-empty id')
|
|
71
|
+
|
|
72
|
+
const targetDir = resolve(options.targetDir)
|
|
73
|
+
assertDirectoryAvailable(targetDir)
|
|
74
|
+
|
|
75
|
+
const createdPaths = createWorkspaceFiles({
|
|
76
|
+
sdkPackageSpec: options.sdkPackageSpec,
|
|
77
|
+
template: options.template,
|
|
78
|
+
workspaceDir: targetDir,
|
|
79
|
+
workspaceName,
|
|
80
|
+
})
|
|
81
|
+
const createdEffect = createEffectFiles({
|
|
82
|
+
audio: options.audio,
|
|
83
|
+
effectId: firstEffectId,
|
|
84
|
+
template: options.template,
|
|
85
|
+
workspaceDir: targetDir,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
createdPaths.push(...createdEffect.createdPaths)
|
|
89
|
+
|
|
90
|
+
if (options.git) {
|
|
91
|
+
await runCommand(['git', 'init'], targetDir, 'Failed to initialize git repository')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (options.install) {
|
|
95
|
+
await runCommand(['bun', 'install'], targetDir, 'Failed to install workspace dependencies')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
createdPaths,
|
|
100
|
+
firstEntryPath: createdEffect.entryPath,
|
|
101
|
+
targetDir,
|
|
102
|
+
template: options.template,
|
|
103
|
+
workspaceName,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function defaultSdkPackageSpec(): string | undefined {
|
|
108
|
+
return process.env.HYPERCOLOR_SDK_PACKAGE_SPEC
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function resolveWorkspaceTarget(cwd: string, workspaceName: string): string {
|
|
112
|
+
return resolve(cwd, workspaceName)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function resolveEditor(): string | undefined {
|
|
116
|
+
return process.env.VISUAL ?? process.env.EDITOR
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function workspaceNameFromTarget(target: string): string {
|
|
120
|
+
return normalizeWorkspaceName(target.split('/').at(-1) ?? target)
|
|
121
|
+
}
|
package/src/templates.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { join, resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { displayNameFromEffectId } from './naming'
|
|
5
|
+
import type { ResolvedTemplates, TemplateKind } from './types'
|
|
6
|
+
|
|
7
|
+
const PACKAGE_ROOT = resolve(import.meta.dirname, '..')
|
|
8
|
+
const TEMPLATES_ROOT = join(PACKAGE_ROOT, 'templates')
|
|
9
|
+
|
|
10
|
+
function renderTemplate(content: string, variables: Record<string, string>): string {
|
|
11
|
+
let rendered = content
|
|
12
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
13
|
+
rendered = rendered.replaceAll(`__${key}__`, value)
|
|
14
|
+
}
|
|
15
|
+
return rendered
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function copyTemplateTree(
|
|
19
|
+
sourceDir: string,
|
|
20
|
+
targetDir: string,
|
|
21
|
+
variables: Record<string, string>,
|
|
22
|
+
createdPaths: string[],
|
|
23
|
+
): void {
|
|
24
|
+
mkdirSync(targetDir, { recursive: true })
|
|
25
|
+
|
|
26
|
+
for (const entry of readdirSync(sourceDir, { withFileTypes: true })) {
|
|
27
|
+
const sourcePath = join(sourceDir, entry.name)
|
|
28
|
+
const rawTargetName = entry.name.endsWith('.template') ? entry.name.slice(0, -'.template'.length) : entry.name
|
|
29
|
+
const targetName = renderTemplate(rawTargetName, variables)
|
|
30
|
+
const targetPath = join(targetDir, targetName)
|
|
31
|
+
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
copyTemplateTree(sourcePath, targetPath, variables, createdPaths)
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sourceStat = statSync(sourcePath)
|
|
38
|
+
if (!sourceStat.isFile()) continue
|
|
39
|
+
|
|
40
|
+
const content = readFileSync(sourcePath, 'utf8')
|
|
41
|
+
writeFileSync(targetPath, renderTemplate(content, variables))
|
|
42
|
+
createdPaths.push(targetPath)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function effectTemplateDir(template: TemplateKind, audio: boolean): string {
|
|
47
|
+
if (template === 'html') return join(TEMPLATES_ROOT, 'effects', 'html')
|
|
48
|
+
return join(TEMPLATES_ROOT, 'effects', template, audio ? 'audio' : 'base')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function workspaceTemplateDir(template: TemplateKind): string {
|
|
52
|
+
return join(TEMPLATES_ROOT, 'workspace', template === 'html' ? 'html' : 'ts')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function effectTargetDir(workspaceDir: string, template: TemplateKind, effectId: string): string {
|
|
56
|
+
return template === 'html' ? join(workspaceDir, 'effects') : join(workspaceDir, 'effects', effectId)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function effectEntryPath(workspaceDir: string, template: TemplateKind, effectId: string): string {
|
|
60
|
+
return template === 'html'
|
|
61
|
+
? join(workspaceDir, 'effects', `${effectId}.html`)
|
|
62
|
+
: join(workspaceDir, 'effects', effectId, 'main.ts')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createEffectFiles(args: {
|
|
66
|
+
audio: boolean
|
|
67
|
+
effectId: string
|
|
68
|
+
template: TemplateKind
|
|
69
|
+
workspaceDir: string
|
|
70
|
+
}): ResolvedTemplates {
|
|
71
|
+
const { audio, effectId, template, workspaceDir } = args
|
|
72
|
+
const targetDir = effectTargetDir(workspaceDir, template, effectId)
|
|
73
|
+
const createdPaths: string[] = []
|
|
74
|
+
|
|
75
|
+
const variables = {
|
|
76
|
+
DISPLAY_NAME: displayNameFromEffectId(effectId),
|
|
77
|
+
EFFECT_ID: effectId,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (template === 'html') {
|
|
81
|
+
const entryPath = effectEntryPath(workspaceDir, template, effectId)
|
|
82
|
+
if (existsSync(entryPath)) {
|
|
83
|
+
throw new Error(`Effect "${effectId}" already exists at ${entryPath}`)
|
|
84
|
+
}
|
|
85
|
+
mkdirSync(targetDir, { recursive: true })
|
|
86
|
+
} else if (existsSync(targetDir)) {
|
|
87
|
+
throw new Error(`Effect "${effectId}" already exists at ${targetDir}`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
copyTemplateTree(effectTemplateDir(template, audio), targetDir, variables, createdPaths)
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
createdPaths,
|
|
94
|
+
entryPath: effectEntryPath(workspaceDir, template, effectId),
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function createWorkspaceFiles(args: {
|
|
99
|
+
sdkPackageSpec: string
|
|
100
|
+
template: TemplateKind
|
|
101
|
+
workspaceDir: string
|
|
102
|
+
workspaceName: string
|
|
103
|
+
}): string[] {
|
|
104
|
+
const { sdkPackageSpec, template, workspaceDir, workspaceName } = args
|
|
105
|
+
const createdPaths: string[] = []
|
|
106
|
+
mkdirSync(workspaceDir, { recursive: true })
|
|
107
|
+
|
|
108
|
+
copyTemplateTree(
|
|
109
|
+
workspaceTemplateDir(template),
|
|
110
|
+
workspaceDir,
|
|
111
|
+
{
|
|
112
|
+
SDK_PACKAGE_SPEC: sdkPackageSpec,
|
|
113
|
+
WORKSPACE_NAME: workspaceName,
|
|
114
|
+
},
|
|
115
|
+
createdPaths,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return createdPaths
|
|
119
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type TemplateKind = 'canvas' | 'shader' | 'face' | 'html'
|
|
2
|
+
|
|
3
|
+
export interface CliOutput {
|
|
4
|
+
error(message: string): void
|
|
5
|
+
log(message: string): void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface AddEffectOptions {
|
|
9
|
+
audio: boolean
|
|
10
|
+
editor?: string
|
|
11
|
+
effectId: string
|
|
12
|
+
output?: CliOutput
|
|
13
|
+
template: TemplateKind
|
|
14
|
+
workspaceDir: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AddEffectResult {
|
|
18
|
+
createdPaths: string[]
|
|
19
|
+
entryPath: string
|
|
20
|
+
effectId: string
|
|
21
|
+
template: TemplateKind
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ScaffoldWorkspaceOptions {
|
|
25
|
+
audio: boolean
|
|
26
|
+
firstEffectId: string
|
|
27
|
+
install: boolean
|
|
28
|
+
output?: CliOutput
|
|
29
|
+
sdkPackageSpec: string
|
|
30
|
+
targetDir: string
|
|
31
|
+
template: TemplateKind
|
|
32
|
+
workspaceName: string
|
|
33
|
+
git: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ScaffoldWorkspaceResult {
|
|
37
|
+
createdPaths: string[]
|
|
38
|
+
firstEntryPath: string
|
|
39
|
+
targetDir: string
|
|
40
|
+
template: TemplateKind
|
|
41
|
+
workspaceName: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface PromptedAddEffectOptions {
|
|
45
|
+
audio: boolean
|
|
46
|
+
effectId: string
|
|
47
|
+
template: TemplateKind
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PromptedScaffoldOptions extends PromptedAddEffectOptions {
|
|
51
|
+
git: boolean
|
|
52
|
+
install: boolean
|
|
53
|
+
workspaceName: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ResolvedTemplates {
|
|
57
|
+
createdPaths: string[]
|
|
58
|
+
entryPath: string
|
|
59
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { audio, canvas, combo, num } from 'hypercolor'
|
|
2
|
+
|
|
3
|
+
export default canvas(
|
|
4
|
+
'__DISPLAY_NAME__',
|
|
5
|
+
{
|
|
6
|
+
glow: num('Glow', [0, 100], 68, { group: 'Color' }),
|
|
7
|
+
palette: combo('Palette', ['Aurora', 'Fire', 'Ocean'], { group: 'Color' }),
|
|
8
|
+
speed: num('Speed', [1, 10], 5, { group: 'Motion' }),
|
|
9
|
+
},
|
|
10
|
+
(ctx, time, controls) => {
|
|
11
|
+
const width = ctx.canvas.width
|
|
12
|
+
const height = ctx.canvas.height
|
|
13
|
+
const analysis = audio()
|
|
14
|
+
const speed = (controls.speed as number) ?? 5
|
|
15
|
+
const glow = ((controls.glow as number) ?? 68) / 100
|
|
16
|
+
const palette = (controls.palette as string) ?? 'Aurora'
|
|
17
|
+
const baseHue = palette === 'Fire' ? 20 : palette === 'Ocean' ? 205 : 145
|
|
18
|
+
const pulse = Math.max(analysis.beatPulse, analysis.bassEnv * 0.8, analysis.levelShort * 0.7, 0.08)
|
|
19
|
+
const hue = (baseHue + time * speed * 30 + pulse * 95) % 360
|
|
20
|
+
|
|
21
|
+
ctx.fillStyle = '#04050a'
|
|
22
|
+
ctx.fillRect(0, 0, width, height)
|
|
23
|
+
|
|
24
|
+
const halo = ctx.createRadialGradient(width * 0.5, height * 0.5, 10, width * 0.5, height * 0.5, width * 0.55)
|
|
25
|
+
halo.addColorStop(0, `hsla(${hue}, 100%, 64%, ${0.28 + pulse * 0.35})`)
|
|
26
|
+
halo.addColorStop(0.55, `hsla(${(hue + 55) % 360}, 96%, 52%, ${0.18 + glow * 0.3})`)
|
|
27
|
+
halo.addColorStop(1, 'rgba(0, 0, 0, 0)')
|
|
28
|
+
ctx.fillStyle = halo
|
|
29
|
+
ctx.fillRect(0, 0, width, height)
|
|
30
|
+
|
|
31
|
+
ctx.strokeStyle = `hsla(${(hue + 180) % 360}, 100%, 72%, ${0.16 + glow * 0.4})`
|
|
32
|
+
ctx.lineWidth = 2 + pulse * 18
|
|
33
|
+
ctx.beginPath()
|
|
34
|
+
ctx.arc(width * 0.5, height * 0.5, 24 + pulse * 80, 0, Math.PI * 2)
|
|
35
|
+
ctx.stroke()
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
audio: true,
|
|
39
|
+
author: 'You',
|
|
40
|
+
description: 'A starter audio-reactive canvas effect',
|
|
41
|
+
presets: [
|
|
42
|
+
{
|
|
43
|
+
controls: { glow: 68, palette: 'Aurora', speed: 5 },
|
|
44
|
+
description: 'Responsive halo with balanced bloom.',
|
|
45
|
+
name: 'Default',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { canvas, combo, num } from 'hypercolor'
|
|
2
|
+
|
|
3
|
+
export default canvas(
|
|
4
|
+
'__DISPLAY_NAME__',
|
|
5
|
+
{
|
|
6
|
+
brightness: num('Brightness', [0, 100], 80, { group: 'Color' }),
|
|
7
|
+
palette: combo('Palette', ['Aurora', 'Fire', 'Ocean'], { group: 'Color' }),
|
|
8
|
+
speed: num('Speed', [1, 10], 5, { group: 'Motion' }),
|
|
9
|
+
},
|
|
10
|
+
(ctx, time, controls) => {
|
|
11
|
+
const width = ctx.canvas.width
|
|
12
|
+
const height = ctx.canvas.height
|
|
13
|
+
const speed = (controls.speed as number) ?? 5
|
|
14
|
+
const brightness = ((controls.brightness as number) ?? 80) / 100
|
|
15
|
+
const palette = (controls.palette as string) ?? 'Aurora'
|
|
16
|
+
const baseHue = palette === 'Fire' ? 20 : palette === 'Ocean' ? 205 : 145
|
|
17
|
+
const drift = Math.sin(time * speed * 0.9) * 0.5 + 0.5
|
|
18
|
+
const hue = (baseHue + drift * 55 + time * speed * 24) % 360
|
|
19
|
+
|
|
20
|
+
ctx.fillStyle = '#04050a'
|
|
21
|
+
ctx.fillRect(0, 0, width, height)
|
|
22
|
+
|
|
23
|
+
const gradient = ctx.createLinearGradient(0, 0, width, height)
|
|
24
|
+
gradient.addColorStop(0, `hsla(${hue}, 100%, ${36 + brightness * 10}%, 0.88)`)
|
|
25
|
+
gradient.addColorStop(1, `hsla(${(hue + 42) % 360}, 90%, ${22 + brightness * 12}%, 0.92)`)
|
|
26
|
+
ctx.fillStyle = gradient
|
|
27
|
+
ctx.fillRect(0, 0, width, height)
|
|
28
|
+
|
|
29
|
+
ctx.fillStyle = `hsla(${(hue + 90) % 360}, 100%, 70%, ${0.08 + brightness * 0.18})`
|
|
30
|
+
ctx.beginPath()
|
|
31
|
+
ctx.arc(width * 0.38, height * 0.45, 48 + drift * 52, 0, Math.PI * 2)
|
|
32
|
+
ctx.fill()
|
|
33
|
+
|
|
34
|
+
ctx.fillStyle = `hsla(${(hue + 210) % 360}, 100%, 68%, ${0.06 + brightness * 0.12})`
|
|
35
|
+
ctx.beginPath()
|
|
36
|
+
ctx.arc(width * 0.66, height * 0.55, 42 + (1 - drift) * 44, 0, Math.PI * 2)
|
|
37
|
+
ctx.fill()
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
author: 'You',
|
|
41
|
+
description: 'A starter canvas effect',
|
|
42
|
+
presets: [
|
|
43
|
+
{
|
|
44
|
+
controls: { brightness: 80, palette: 'Aurora', speed: 5 },
|
|
45
|
+
description: 'Balanced motion and brightness.',
|
|
46
|
+
name: 'Default',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { face, num } from 'hypercolor'
|
|
2
|
+
|
|
3
|
+
const styleId = 'hc-face-__EFFECT_ID__'
|
|
4
|
+
|
|
5
|
+
const styles = `
|
|
6
|
+
.hc-face-shell {
|
|
7
|
+
position: absolute;
|
|
8
|
+
inset: 0;
|
|
9
|
+
display: grid;
|
|
10
|
+
place-items: center;
|
|
11
|
+
background:
|
|
12
|
+
radial-gradient(circle at top, rgba(128, 255, 234, 0.18), transparent 55%),
|
|
13
|
+
linear-gradient(180deg, #090b12 0%, #05060a 100%);
|
|
14
|
+
color: white;
|
|
15
|
+
font-family: 'Rajdhani', sans-serif;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.hc-face-value {
|
|
19
|
+
font-size: clamp(64px, 24vw, 160px);
|
|
20
|
+
font-weight: 600;
|
|
21
|
+
letter-spacing: 0.04em;
|
|
22
|
+
text-shadow: 0 0 30px rgba(128, 255, 234, 0.25);
|
|
23
|
+
}
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
function ensureStyles(): void {
|
|
27
|
+
if (document.getElementById(styleId)) return
|
|
28
|
+
const style = document.createElement('style')
|
|
29
|
+
style.id = styleId
|
|
30
|
+
style.textContent = styles
|
|
31
|
+
document.head.appendChild(style)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default face(
|
|
35
|
+
'__DISPLAY_NAME__',
|
|
36
|
+
{
|
|
37
|
+
glow: num('Glow', [0, 100], 68, { group: 'Style' }),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
author: 'You',
|
|
41
|
+
description: 'A starter audio-reactive display face',
|
|
42
|
+
presets: [
|
|
43
|
+
{
|
|
44
|
+
controls: { glow: 68 },
|
|
45
|
+
description: 'Balanced audio-reactive face glow.',
|
|
46
|
+
name: 'Default',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
(ctx) => {
|
|
51
|
+
ensureStyles()
|
|
52
|
+
|
|
53
|
+
const shell = document.createElement('div')
|
|
54
|
+
shell.className = 'hc-face-shell'
|
|
55
|
+
|
|
56
|
+
const value = document.createElement('div')
|
|
57
|
+
value.className = 'hc-face-value'
|
|
58
|
+
shell.appendChild(value)
|
|
59
|
+
ctx.container.appendChild(shell)
|
|
60
|
+
|
|
61
|
+
return (time, controls) => {
|
|
62
|
+
const engineAudio = (globalThis as { engine?: { audio?: { beatPulse?: number; level?: number } } }).engine?.audio
|
|
63
|
+
const pulse = Math.max(engineAudio?.beatPulse ?? 0, engineAudio?.level ?? 0, 0.08)
|
|
64
|
+
const glow = ((controls.glow as number) ?? 68) / 100
|
|
65
|
+
const hue = (time * 42 + pulse * 120) % 360
|
|
66
|
+
shell.style.boxShadow = `inset 0 0 ${28 + glow * 54 + pulse * 60}px hsla(${hue}, 100%, 70%, ${0.16 + glow * 0.18})`
|
|
67
|
+
value.textContent = `${Math.round(pulse * 100)}`
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { face, num } from 'hypercolor'
|
|
2
|
+
|
|
3
|
+
const styleId = 'hc-face-__EFFECT_ID__'
|
|
4
|
+
|
|
5
|
+
const styles = `
|
|
6
|
+
.hc-face-shell {
|
|
7
|
+
position: absolute;
|
|
8
|
+
inset: 0;
|
|
9
|
+
display: grid;
|
|
10
|
+
place-items: center;
|
|
11
|
+
background:
|
|
12
|
+
radial-gradient(circle at top, rgba(128, 255, 234, 0.18), transparent 55%),
|
|
13
|
+
linear-gradient(180deg, #090b12 0%, #05060a 100%);
|
|
14
|
+
color: white;
|
|
15
|
+
font-family: 'Rajdhani', sans-serif;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.hc-face-value {
|
|
19
|
+
font-size: clamp(64px, 24vw, 160px);
|
|
20
|
+
font-weight: 600;
|
|
21
|
+
letter-spacing: 0.04em;
|
|
22
|
+
text-shadow: 0 0 30px rgba(128, 255, 234, 0.25);
|
|
23
|
+
}
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
function ensureStyles(): void {
|
|
27
|
+
if (document.getElementById(styleId)) return
|
|
28
|
+
const style = document.createElement('style')
|
|
29
|
+
style.id = styleId
|
|
30
|
+
style.textContent = styles
|
|
31
|
+
document.head.appendChild(style)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default face(
|
|
35
|
+
'__DISPLAY_NAME__',
|
|
36
|
+
{
|
|
37
|
+
glow: num('Glow', [0, 100], 68, { group: 'Style' }),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
author: 'You',
|
|
41
|
+
description: 'A starter display face',
|
|
42
|
+
presets: [
|
|
43
|
+
{
|
|
44
|
+
controls: { glow: 68 },
|
|
45
|
+
description: 'Balanced face glow.',
|
|
46
|
+
name: 'Default',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
(ctx) => {
|
|
51
|
+
ensureStyles()
|
|
52
|
+
|
|
53
|
+
const shell = document.createElement('div')
|
|
54
|
+
shell.className = 'hc-face-shell'
|
|
55
|
+
|
|
56
|
+
const value = document.createElement('div')
|
|
57
|
+
value.className = 'hc-face-value'
|
|
58
|
+
shell.appendChild(value)
|
|
59
|
+
ctx.container.appendChild(shell)
|
|
60
|
+
|
|
61
|
+
return (time, controls) => {
|
|
62
|
+
const glow = ((controls.glow as number) ?? 68) / 100
|
|
63
|
+
const hue = (time * 42) % 360
|
|
64
|
+
shell.style.boxShadow = `inset 0 0 ${32 + glow * 48}px hsla(${hue}, 100%, 70%, ${0.16 + glow * 0.18})`
|
|
65
|
+
value.textContent = `${Math.round((Math.sin(time * 1.2) * 0.5 + 0.5) * 100)}`
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta name="hypercolor-version" content="1" />
|
|
7
|
+
<meta description="A starter HTML effect" />
|
|
8
|
+
<meta publisher="You" />
|
|
9
|
+
<title>__DISPLAY_NAME__</title>
|
|
10
|
+
</head>
|
|
11
|
+
<body style="margin:0;overflow:hidden;background:#000;">
|
|
12
|
+
<div id="exStage" style="position:relative;overflow:hidden;background:#000;width:100vw;height:100vh;">
|
|
13
|
+
<canvas id="exCanvas" style="display:block;width:100%;height:100%;"></canvas>
|
|
14
|
+
</div>
|
|
15
|
+
<script>
|
|
16
|
+
const canvas = document.getElementById('exCanvas')
|
|
17
|
+
const ctx = canvas.getContext('2d')
|
|
18
|
+
|
|
19
|
+
function resize() {
|
|
20
|
+
canvas.width = window.innerWidth
|
|
21
|
+
canvas.height = window.innerHeight
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function frame(time) {
|
|
25
|
+
const t = time * 0.001
|
|
26
|
+
const hue = (t * 40) % 360
|
|
27
|
+
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height)
|
|
28
|
+
gradient.addColorStop(0, `hsl(${hue}, 100%, 55%)`)
|
|
29
|
+
gradient.addColorStop(1, `hsl(${(hue + 70) % 360}, 100%, 35%)`)
|
|
30
|
+
ctx.fillStyle = gradient
|
|
31
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
|
32
|
+
|
|
33
|
+
requestAnimationFrame(frame)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
resize()
|
|
37
|
+
window.addEventListener('resize', resize)
|
|
38
|
+
requestAnimationFrame(frame)
|
|
39
|
+
</script>
|
|
40
|
+
</body>
|
|
41
|
+
</html>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#version 300 es
|
|
2
|
+
precision highp float;
|
|
3
|
+
|
|
4
|
+
out vec4 fragColor;
|
|
5
|
+
|
|
6
|
+
uniform float iAudioBass;
|
|
7
|
+
uniform float iAudioBeatPulse;
|
|
8
|
+
uniform float iAudioLevel;
|
|
9
|
+
uniform float iIntensity;
|
|
10
|
+
uniform int iPalette;
|
|
11
|
+
uniform vec2 iResolution;
|
|
12
|
+
uniform float iSpeed;
|
|
13
|
+
uniform float iTime;
|
|
14
|
+
|
|
15
|
+
vec3 paletteColor(float t, int paletteIndex) {
|
|
16
|
+
if (paletteIndex == 1) {
|
|
17
|
+
return mix(vec3(0.95, 0.35, 0.18), vec3(1.0, 0.8, 0.25), t);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (paletteIndex == 2) {
|
|
21
|
+
return mix(vec3(0.05, 0.18, 0.42), vec3(0.25, 0.85, 0.95), t);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return mix(vec3(0.12, 0.58, 0.95), vec3(0.68, 0.22, 1.0), t);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void main() {
|
|
28
|
+
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
|
29
|
+
vec2 centered = uv * 2.0 - 1.0;
|
|
30
|
+
centered.x *= iResolution.x / iResolution.y;
|
|
31
|
+
|
|
32
|
+
float t = iTime * (0.25 + iSpeed * 0.08);
|
|
33
|
+
float pulse = max(iAudioBeatPulse, iAudioBass * 0.8 + iAudioLevel * 0.4);
|
|
34
|
+
float swirl = sin(centered.x * (3.0 + pulse * 2.0) + t) + cos(centered.y * 4.5 - t * 1.4);
|
|
35
|
+
float intensity = clamp(iIntensity / 100.0, 0.0, 1.0);
|
|
36
|
+
float bloom = smoothstep(1.15, 0.12, length(centered) - swirl * (0.08 + pulse * 0.12));
|
|
37
|
+
|
|
38
|
+
vec3 color = paletteColor(0.5 + 0.5 * sin(t + swirl + pulse * 3.0), iPalette);
|
|
39
|
+
color *= mix(0.28, 1.2, bloom) * mix(0.35, 1.1, intensity + pulse * 0.2);
|
|
40
|
+
|
|
41
|
+
fragColor = vec4(color, 1.0);
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { combo, effect, num } from 'hypercolor'
|
|
2
|
+
import shader from './fragment.glsl'
|
|
3
|
+
|
|
4
|
+
export default effect(
|
|
5
|
+
'__DISPLAY_NAME__',
|
|
6
|
+
shader,
|
|
7
|
+
{
|
|
8
|
+
intensity: num('Intensity', [0, 100], 70, { group: 'Color' }),
|
|
9
|
+
palette: combo('Palette', ['Aurora', 'Fire', 'Ocean'], { group: 'Color' }),
|
|
10
|
+
speed: num('Speed', [1, 10], 5, { group: 'Motion' }),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
audio: true,
|
|
14
|
+
author: 'You',
|
|
15
|
+
description: 'A starter audio-reactive shader effect',
|
|
16
|
+
presets: [
|
|
17
|
+
{
|
|
18
|
+
controls: { intensity: 70, palette: 'Aurora', speed: 5 },
|
|
19
|
+
description: 'Balanced audio-reactive response.',
|
|
20
|
+
name: 'Default',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#version 300 es
|
|
2
|
+
precision highp float;
|
|
3
|
+
|
|
4
|
+
out vec4 fragColor;
|
|
5
|
+
|
|
6
|
+
uniform float iIntensity;
|
|
7
|
+
uniform int iPalette;
|
|
8
|
+
uniform vec2 iResolution;
|
|
9
|
+
uniform float iSpeed;
|
|
10
|
+
uniform float iTime;
|
|
11
|
+
|
|
12
|
+
vec3 paletteColor(float t, int paletteIndex) {
|
|
13
|
+
if (paletteIndex == 1) {
|
|
14
|
+
return mix(vec3(0.95, 0.35, 0.18), vec3(1.0, 0.8, 0.25), t);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (paletteIndex == 2) {
|
|
18
|
+
return mix(vec3(0.05, 0.18, 0.42), vec3(0.25, 0.85, 0.95), t);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return mix(vec3(0.12, 0.58, 0.95), vec3(0.68, 0.22, 1.0), t);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void main() {
|
|
25
|
+
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
|
26
|
+
vec2 centered = uv * 2.0 - 1.0;
|
|
27
|
+
centered.x *= iResolution.x / iResolution.y;
|
|
28
|
+
|
|
29
|
+
float t = iTime * (0.25 + iSpeed * 0.08);
|
|
30
|
+
float wave = sin(centered.x * 3.0 + t) + cos(centered.y * 4.0 - t * 1.2);
|
|
31
|
+
float intensity = clamp(iIntensity / 100.0, 0.0, 1.0);
|
|
32
|
+
float glow = smoothstep(1.25, 0.15, length(centered) - wave * 0.08);
|
|
33
|
+
|
|
34
|
+
vec3 color = paletteColor(0.5 + 0.5 * sin(t + wave), iPalette);
|
|
35
|
+
color *= mix(0.25, 1.0, glow) * mix(0.35, 1.1, intensity);
|
|
36
|
+
|
|
37
|
+
fragColor = vec4(color, 1.0);
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { combo, effect, num } from 'hypercolor'
|
|
2
|
+
import shader from './fragment.glsl'
|
|
3
|
+
|
|
4
|
+
export default effect(
|
|
5
|
+
'__DISPLAY_NAME__',
|
|
6
|
+
shader,
|
|
7
|
+
{
|
|
8
|
+
intensity: num('Intensity', [0, 100], 70, { group: 'Color' }),
|
|
9
|
+
palette: combo('Palette', ['Aurora', 'Fire', 'Ocean'], { group: 'Color' }),
|
|
10
|
+
speed: num('Speed', [1, 10], 5, { group: 'Motion' }),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
author: 'You',
|
|
14
|
+
description: 'A starter shader effect',
|
|
15
|
+
presets: [
|
|
16
|
+
{
|
|
17
|
+
controls: { intensity: 70, palette: 'Aurora', speed: 5 },
|
|
18
|
+
description: 'Default shader mix.',
|
|
19
|
+
name: 'Default',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__WORKSPACE_NAME__",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"validate": "hypercolor validate effects/*.html",
|
|
8
|
+
"ship": "hypercolor install effects/*.html",
|
|
9
|
+
"ship:daemon": "hypercolor install effects/*.html --daemon"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"hypercolor": "__SDK_PACKAGE_SPEC__"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"bun": ">=1.2.0",
|
|
16
|
+
"node": ">=24.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# __WORKSPACE_NAME__
|
|
2
|
+
|
|
3
|
+
Hypercolor effect workspace.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
- `bun run build` builds every effect into `dist/`
|
|
8
|
+
- `bun run validate` checks built artifacts
|
|
9
|
+
- `bun run ship` installs locally
|
|
10
|
+
|
|
11
|
+
## Layout
|
|
12
|
+
|
|
13
|
+
- `effects/` holds your source effects
|
|
14
|
+
- `dist/` is generated build output
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.6/schema.json",
|
|
3
|
+
"files": {
|
|
4
|
+
"ignoreUnknown": true,
|
|
5
|
+
"includes": ["**", "!dist", "!node_modules"]
|
|
6
|
+
},
|
|
7
|
+
"formatter": {
|
|
8
|
+
"enabled": true,
|
|
9
|
+
"indentStyle": "space",
|
|
10
|
+
"indentWidth": 4,
|
|
11
|
+
"lineWidth": 120
|
|
12
|
+
},
|
|
13
|
+
"javascript": {
|
|
14
|
+
"formatter": {
|
|
15
|
+
"arrowParentheses": "always",
|
|
16
|
+
"quoteStyle": "single",
|
|
17
|
+
"semicolons": "asNeeded",
|
|
18
|
+
"trailingCommas": "all"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"linter": {
|
|
22
|
+
"enabled": true,
|
|
23
|
+
"rules": {
|
|
24
|
+
"recommended": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"overrides": [
|
|
28
|
+
{
|
|
29
|
+
"includes": ["**/*.md", "**/*.json"],
|
|
30
|
+
"assist": { "enabled": false },
|
|
31
|
+
"formatter": { "enabled": false },
|
|
32
|
+
"linter": { "enabled": false }
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"includes": ["**/package.json", "**/biome.jsonc"],
|
|
36
|
+
"assist": {
|
|
37
|
+
"actions": {
|
|
38
|
+
"source": {
|
|
39
|
+
"useSortedKeys": "off"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__WORKSPACE_NAME__",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "hypercolor build --all",
|
|
8
|
+
"build:one": "hypercolor build",
|
|
9
|
+
"validate": "hypercolor validate dist/*.html",
|
|
10
|
+
"ship": "hypercolor install dist/*.html",
|
|
11
|
+
"ship:daemon": "hypercolor install dist/*.html --daemon",
|
|
12
|
+
"add": "hypercolor add",
|
|
13
|
+
"check": "biome check .",
|
|
14
|
+
"check:fix": "biome check --write ."
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@biomejs/biome": "^2.4.6",
|
|
18
|
+
"hypercolor": "__SDK_PACKAGE_SPEC__",
|
|
19
|
+
"bun-types": "^1.3.12",
|
|
20
|
+
"typescript": "^5.9.3"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"bun": ">=1.2.0",
|
|
24
|
+
"node": ">=24.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noUnusedLocals": true,
|
|
8
|
+
"noUnusedParameters": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": ["bun-types"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["effects/**/*"]
|
|
14
|
+
}
|