@mun-ui/ui 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +104 -2
- package/bin/compile.mjs +38 -0
- package/bin/dev-protocol.mjs +94 -0
- package/bin/formatter.mjs +109 -0
- package/bin/hot-reload.mjs +38 -0
- package/bin/mun.mjs +521 -0
- package/bin/native.mjs +133 -0
- package/bin/pnpm-workspace.mjs +58 -0
- package/bin/program-patch.mjs +104 -0
- package/bin/project.mjs +322 -0
- package/bin/watch.mjs +316 -0
- package/bin/workflow.mjs +261 -0
- package/dist/astro.d.ts +3 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +3 -0
- package/dist/astro.js.map +1 -0
- package/dist/closures.d.ts +2 -0
- package/dist/closures.d.ts.map +1 -0
- package/dist/closures.js +2 -0
- package/dist/closures.js.map +1 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +2 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +2 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/legacy.d.ts +3 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +3 -0
- package/dist/legacy.js.map +1 -0
- package/dist/mun.d.ts +5 -0
- package/dist/mun.d.ts.map +1 -0
- package/dist/mun.js +4 -0
- package/dist/mun.js.map +1 -0
- package/dist/progressive-blur/index.d.ts +8 -0
- package/dist/progressive-blur/index.d.ts.map +1 -0
- package/dist/progressive-blur/index.js +8 -0
- package/dist/progressive-blur/index.js.map +1 -0
- package/dist/progressive-blur/plan.d.ts +3 -0
- package/dist/progressive-blur/plan.d.ts.map +1 -0
- package/dist/progressive-blur/plan.js +3 -0
- package/dist/progressive-blur/plan.js.map +1 -0
- package/dist/react-types.d.ts +2 -0
- package/dist/react-types.d.ts.map +1 -0
- package/dist/react-types.js +2 -0
- package/dist/react-types.js.map +1 -0
- package/dist/rendering-quality.d.ts +4 -0
- package/dist/rendering-quality.d.ts.map +1 -0
- package/dist/rendering-quality.js +4 -0
- package/dist/rendering-quality.js.map +1 -0
- package/dist/state.d.ts +2 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +2 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +2 -0
- package/dist/vite.js.map +1 -0
- package/editors/install.mjs +102 -0
- package/editors/lsp/mun-lsp.mjs +123 -0
- package/editors/lsp/service.mjs +306 -0
- package/editors/lsp/source.mjs +58 -0
- package/editors/vscode/client.mjs +40 -0
- package/editors/vscode/dev-client.mjs +83 -0
- package/editors/vscode/discovery.mjs +46 -0
- package/editors/vscode/export.mjs +42 -0
- package/editors/vscode/extension.cjs +226 -0
- package/editors/vscode/language-configuration.json +15 -0
- package/editors/vscode/package.json +119 -0
- package/editors/vscode/protocol.mjs +29 -0
- package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
- package/native/Cargo.lock +3581 -0
- package/native/Cargo.toml +21 -0
- package/native/README.md +21 -0
- package/native/mun-native/Cargo.toml +23 -0
- package/native/mun-native/src/accessibility.rs +738 -0
- package/native/mun-native/src/dev.rs +604 -0
- package/native/mun-native/src/lib.rs +2676 -0
- package/native/mun-native/src/main.rs +204 -0
- package/native/mun-native/src/offscreen.rs +393 -0
- package/native/mun-native/src/rect.wgsl +63 -0
- package/native/mun-native/src/text.rs +310 -0
- package/native/mun-native/tests/offscreen_rendering.rs +161 -0
- package/native/mun-native/tests/stress.rs +408 -0
- package/native/mun-native/tests/window_lifecycle.rs +183 -0
- package/native/mun-runtime/Cargo.toml +13 -0
- package/native/mun-runtime/src/accessibility.rs +193 -0
- package/native/mun-runtime/src/collection.rs +1073 -0
- package/native/mun-runtime/src/gesture.rs +1070 -0
- package/native/mun-runtime/src/input.rs +325 -0
- package/native/mun-runtime/src/ir.rs +782 -0
- package/native/mun-runtime/src/kinetics.rs +500 -0
- package/native/mun-runtime/src/layout.rs +173 -0
- package/native/mun-runtime/src/layout_cache.rs +209 -0
- package/native/mun-runtime/src/lib.rs +49 -0
- package/native/mun-runtime/src/motion.rs +1162 -0
- package/native/mun-runtime/src/retained.rs +574 -0
- package/native/mun-runtime/src/runtime.rs +7078 -0
- package/native/mun-runtime/src/scene.rs +530 -0
- package/native/mun-runtime/src/scroll.rs +521 -0
- package/native/mun-runtime/src/scroll_view.rs +220 -0
- package/native/mun-runtime/src/text_edit.rs +670 -0
- package/native/mun-runtime/src/timeline.rs +1534 -0
- package/native/mun-runtime/src/validate.rs +677 -0
- package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
- package/native/mun-runtime/tests/compiler_contract.rs +110 -0
- package/native/mun-runtime/tests/flexible_frames.rs +47 -0
- package/native/mun-runtime/tests/hot_update.rs +367 -0
- package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
- package/native/mun-runtime/tests/ir_validation.rs +167 -0
- package/native/mun-runtime/tests/keyed_collections.rs +251 -0
- package/native/mun-runtime/tests/native_controls_style.rs +491 -0
- package/native/mun-runtime/tests/native_demo.rs +285 -0
- package/native/mun-runtime/tests/native_layout_style.rs +175 -0
- package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
- package/native/mun-runtime/tests/scroll_view.rs +403 -0
- package/native/mun-runtime/tests/text_editing.rs +491 -0
- package/package.json +210 -3
- package/schemas/README.md +19 -0
- package/schemas/semantic-ui-ir-v1.schema.json +1972 -0
- package/templates/native/App.mun +15 -0
- package/templates/native/gitignore +3 -0
- package/templates/native/mun.toml +8 -0
- package/templates/project/gitignore +5 -0
- package/templates/project/index.html +13 -0
- package/templates/project/package.json +21 -0
- package/templates/project/src/App.mun +13 -0
- package/templates/project/src/index.css +21 -0
- package/templates/project/src/main.ts +5 -0
- package/templates/project/tsconfig.json +20 -0
- package/templates/project/vite.config.ts +6 -0
- package/templates/vite/src/App.css +134 -0
- package/templates/vite/src/App.tsx +91 -0
- package/templates/vite/src/index.css +23 -0
- package/templates/vite/vite.config.ts +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Mün UI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Mün is a **SwiftUI-like frontend language for web applications**. Author UI and
|
|
4
|
+
application behavior in `.mun` using Views, state, bindings, identity and ordered
|
|
5
|
+
modifiers. The compiler targets JavaScript and the existing `@mun-ui/web` HTML/DOM
|
|
6
|
+
runtime. React, Vue and native toolchains are optional integrations.
|
|
7
|
+
|
|
8
|
+
```text
|
|
9
|
+
.mun -> parser / shared analysis -> JavaScript -> @mun-ui/core -> @mun-ui/web DOM / SSR
|
|
10
|
+
JS / TS integration builders ----------------------^
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The first implemented slice is a counter and async profile form with validation,
|
|
14
|
+
cancellation, failure recovery and SSR/hydration. It is a foundation for complete
|
|
15
|
+
applications; routing, typed data APIs and other capabilities remain in progress.
|
|
16
|
+
See the [language contract](docs/LANGUAGE_REFERENCE.md),
|
|
17
|
+
[capability status](docs/CAPABILITIES.md) and [milestone](docs/WEB_MILESTONE.md).
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
Use Node.js 20.19 or newer and a package manager:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g @mun-ui/ui
|
|
25
|
+
mun create HelloMun
|
|
26
|
+
cd HelloMun
|
|
27
|
+
npm run dev
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`mun new`, `mun create`, `mun init`, and `npm create mun` default to a normal
|
|
31
|
+
Vite web project. Dependency installation runs automatically unless you pass
|
|
32
|
+
`--no-install`. Edit `src/App.mun`; the Vite plugin compiles the SwiftUI-like
|
|
33
|
+
syntax to JavaScript. `npm run build` creates deployable static web assets.
|
|
34
|
+
|
|
35
|
+
```swift
|
|
36
|
+
struct Counter: View {
|
|
37
|
+
@State var count = 0
|
|
38
|
+
|
|
39
|
+
var body: some View {
|
|
40
|
+
VStack(spacing: 12) {
|
|
41
|
+
Text("Hello, Mün")
|
|
42
|
+
Text("Count: \(count)")
|
|
43
|
+
Button("Increase") { count += 1 }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default Counter()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Standard Views, layouts, modifiers, `State`/`Binding` and animation APIs resolve in
|
|
52
|
+
`.mun` files without imports; only what a module uses is bundled. Advanced features
|
|
53
|
+
ship in the same install and are opt-in through explicit imports, for example
|
|
54
|
+
`import { BlurProfile, progressiveBlur } from "@mun-ui/ui/progressive-blur"`. See
|
|
55
|
+
[Built-ins and opt-in features](docs/BUILTINS_AND_OPT_IN.md).
|
|
56
|
+
|
|
57
|
+
You can also author Views directly in JavaScript or TypeScript, without the
|
|
58
|
+
`.mun` compiler. Import the authoring API from `@mun-ui/core` (or `@mun-ui/ui`) and
|
|
59
|
+
`mount` / `renderToHTML` from `@mun-ui/web`. Rendering is explicitly separate from
|
|
60
|
+
View composition; `@mun-ui/core/compat` remains an alias for existing imports.
|
|
61
|
+
|
|
62
|
+
## Local development
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm install
|
|
66
|
+
pnpm build
|
|
67
|
+
pnpm dev:create ../HelloMun --no-install
|
|
68
|
+
cd ../HelloMun
|
|
69
|
+
pnpm install
|
|
70
|
+
pnpm dev
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For an existing project, use `mun link <path> --renderer web` from the checkout.
|
|
74
|
+
`pnpm dev:watch` rebuilds workspace packages while developing the framework.
|
|
75
|
+
Run `pnpm demo:language-web` for the SSR profile example (enter `fail` to exercise
|
|
76
|
+
recovery). Run `pnpm test` for the full suite and `pnpm demo:web:build` for the web demo.
|
|
77
|
+
|
|
78
|
+
## Experimental native area
|
|
79
|
+
|
|
80
|
+
The Rust native runtime, Semantic UI IR pipeline, native packaging, and native
|
|
81
|
+
hot-reload work are retained as **experimental**, not the default frontend or a
|
|
82
|
+
prerequisite for web development. Opt in with:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
mun create NativeExperiment --target native
|
|
86
|
+
cd NativeExperiment
|
|
87
|
+
mun dev
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Native `mun dev/run/check/build/package` workflows use `mun.toml` and
|
|
91
|
+
`Sources/App.mun`. Their support and limitations are documented in
|
|
92
|
+
[Native projects](docs/native-projects.md) and
|
|
93
|
+
[Native architecture](docs/NATIVE_ARCHITECTURE.md). Resident Compute Islands are
|
|
94
|
+
also optional research infrastructure, not the core authoring model.
|
|
95
|
+
|
|
96
|
+
## Documentation
|
|
97
|
+
|
|
98
|
+
- [Getting started](docs/GETTING_STARTED.md)
|
|
99
|
+
- [Architecture](docs/ARCHITECTURE.md)
|
|
100
|
+
- [Rendering reliability, URL safety and release gates](docs/rendering-reliability.md)
|
|
101
|
+
- [API](docs/API.md)
|
|
102
|
+
- [Built-ins and opt-in features](docs/BUILTINS_AND_OPT_IN.md)
|
|
103
|
+
- [SwiftUI parity](docs/SWIFTUI_PARITY.md)
|
|
104
|
+
- [Local development](docs/LOCAL_DEVELOPMENT.md)
|
|
105
|
+
- [Migration](docs/MIGRATION.md)
|
package/bin/compile.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { basename, dirname, relative, resolve } from 'node:path'
|
|
5
|
+
import process from 'node:process'
|
|
6
|
+
import { compileMunUiProgram } from '@mun-ui/compiler'
|
|
7
|
+
|
|
8
|
+
function displayPath(path) {
|
|
9
|
+
const local = relative(process.cwd(), path)
|
|
10
|
+
return local && !local.startsWith('..') ? local : path
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const [inputArg, outputArg, ...extra] = process.argv.slice(2)
|
|
14
|
+
if (!inputArg || extra.length > 0) {
|
|
15
|
+
console.error('Usage: mun compile <input.mun> [output.json]')
|
|
16
|
+
process.exit(2)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const input = resolve(process.cwd(), inputArg)
|
|
20
|
+
if (!input.endsWith('.mun')) {
|
|
21
|
+
console.error(`Mün compile expects canonical .mun source: ${displayPath(input)}`)
|
|
22
|
+
process.exit(2)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const output = outputArg
|
|
26
|
+
? resolve(process.cwd(), outputArg)
|
|
27
|
+
: resolve(dirname(input), `${basename(input, '.mun')}.mun.ir.json`)
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const source = readFileSync(input, 'utf8')
|
|
31
|
+
const program = compileMunUiProgram(source, input)
|
|
32
|
+
mkdirSync(dirname(output), { recursive: true })
|
|
33
|
+
writeFileSync(output, `${JSON.stringify(program, null, 2)}\n`)
|
|
34
|
+
console.log(`Compiled ${displayPath(input)} -> ${displayPath(output)}`)
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(`Mün compile failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
37
|
+
process.exit(1)
|
|
38
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Mün development protocol v2 (toolchain side). See native/mun-native/src/dev.rs.
|
|
2
|
+
// Frames: 4-byte big-endian length + UTF-8 JSON. Loopback TCP only; the host
|
|
3
|
+
// connects back and must present the per-session token in its hello.
|
|
4
|
+
import { randomBytes } from 'node:crypto'
|
|
5
|
+
import { createServer } from 'node:net'
|
|
6
|
+
|
|
7
|
+
export const DEV_PROTOCOL_VERSION = 2
|
|
8
|
+
export const MAX_FRAME_BYTES = 16 * 1024 * 1024
|
|
9
|
+
|
|
10
|
+
export function encodeFrame(message) {
|
|
11
|
+
const body = Buffer.from(JSON.stringify(message), 'utf8')
|
|
12
|
+
if (body.length > MAX_FRAME_BYTES) throw new Error(`Dev message of ${body.length} bytes exceeds ${MAX_FRAME_BYTES}`)
|
|
13
|
+
const header = Buffer.alloc(4)
|
|
14
|
+
header.writeUInt32BE(body.length)
|
|
15
|
+
return Buffer.concat([header, body])
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Incremental decoder; throws on oversized or malformed frames. */
|
|
19
|
+
export function createFrameDecoder(onMessage) {
|
|
20
|
+
let buffer = Buffer.alloc(0)
|
|
21
|
+
return chunk => {
|
|
22
|
+
buffer = Buffer.concat([buffer, chunk])
|
|
23
|
+
while (buffer.length >= 4) {
|
|
24
|
+
const length = buffer.readUInt32BE(0)
|
|
25
|
+
if (length > MAX_FRAME_BYTES) throw new Error(`Dev frame of ${length} bytes exceeds ${MAX_FRAME_BYTES}`)
|
|
26
|
+
if (buffer.length < 4 + length) return
|
|
27
|
+
const body = buffer.subarray(4, 4 + length)
|
|
28
|
+
buffer = buffer.subarray(4 + length)
|
|
29
|
+
onMessage(JSON.parse(body.toString('utf8')))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Listen on an ephemeral loopback port for exactly one authenticated host.
|
|
36
|
+
* Resolves `{ endpoint, token, connection }` where `connection` resolves to a
|
|
37
|
+
* channel once the host's hello is verified.
|
|
38
|
+
*/
|
|
39
|
+
export async function listenForHost({ irVersion, onEvent = () => {} } = {}) {
|
|
40
|
+
const token = randomBytes(24).toString('hex')
|
|
41
|
+
let accept, fail
|
|
42
|
+
const connection = new Promise((resolve, reject) => { accept = resolve; fail = reject })
|
|
43
|
+
connection.catch(() => {})
|
|
44
|
+
const server = createServer({ noDelay: true }, socket => {
|
|
45
|
+
let channel
|
|
46
|
+
const pending = new Map()
|
|
47
|
+
let nextId = 1
|
|
48
|
+
const decode = createFrameDecoder(message => {
|
|
49
|
+
if (!channel) {
|
|
50
|
+
if (message.type !== 'hello' || message.token !== token) { socket.destroy(); return }
|
|
51
|
+
if (message.protocol !== DEV_PROTOCOL_VERSION || (irVersion !== undefined && message.semanticUiIrVersion !== irVersion)) {
|
|
52
|
+
socket.destroy()
|
|
53
|
+
fail(new Error(`Native host speaks dev protocol ${message.protocol} / IR ${message.semanticUiIrVersion}; toolchain expects ${DEV_PROTOCOL_VERSION} / ${irVersion}.`))
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
server.close() // one host per session; stop accepting.
|
|
57
|
+
channel = {
|
|
58
|
+
pid: message.pid,
|
|
59
|
+
request(type, payload = {}, timeoutMs = 10000) {
|
|
60
|
+
const id = nextId++
|
|
61
|
+
if (socket.destroyed || !socket.writable) return Promise.reject(new Error('Native app disconnected'))
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const timer = setTimeout(() => { pending.delete(id); reject(new Error(`Dev ${type} timed out`)) }, timeoutMs)
|
|
64
|
+
pending.set(id, { resolve, reject, timer })
|
|
65
|
+
try { socket.write(encodeFrame({ type, id, ...payload })) }
|
|
66
|
+
catch (error) { clearTimeout(timer); pending.delete(id); reject(error) }
|
|
67
|
+
})
|
|
68
|
+
},
|
|
69
|
+
close() { socket.end() },
|
|
70
|
+
closed: new Promise(resolve => socket.once('close', resolve)),
|
|
71
|
+
}
|
|
72
|
+
accept(channel)
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
const waiter = message.id !== undefined && pending.get(message.id)
|
|
76
|
+
if (waiter) { pending.delete(message.id); clearTimeout(waiter.timer); waiter.resolve(message) }
|
|
77
|
+
else onEvent(message)
|
|
78
|
+
})
|
|
79
|
+
socket.on('data', chunk => { try { decode(chunk) } catch (error) { onEvent({ type: 'protocol-error', message: error.message }); socket.destroy() } })
|
|
80
|
+
socket.on('error', () => {})
|
|
81
|
+
socket.on('close', () => {
|
|
82
|
+
for (const { reject, timer } of pending.values()) { clearTimeout(timer); reject(new Error('Native app disconnected')) }
|
|
83
|
+
pending.clear()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(0, '127.0.0.1', resolve) })
|
|
87
|
+
const { port } = server.address()
|
|
88
|
+
return {
|
|
89
|
+
endpoint: `127.0.0.1:${port}`,
|
|
90
|
+
token,
|
|
91
|
+
connection,
|
|
92
|
+
close() { server.close(); fail(new Error('Dev session closed before the native app connected')) },
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Canonical structural formatter. Literal and comment tokens remain opaque;
|
|
2
|
+
// whitespace decisions operate only on source syntax, never on literal contents.
|
|
3
|
+
function stringEnd(source, start) {
|
|
4
|
+
const quote = source[start]
|
|
5
|
+
let i = start + 1
|
|
6
|
+
while (i < source.length) {
|
|
7
|
+
if (source[i] === '\\') {
|
|
8
|
+
if (quote === '"' && source[i + 1] === '(') {
|
|
9
|
+
i += 2; let depth = 1
|
|
10
|
+
while (i < source.length && depth) {
|
|
11
|
+
if (source[i] === '"' || source[i] === "'") i = stringEnd(source, i)
|
|
12
|
+
else if (source.startsWith('/*', i)) { const end = source.indexOf('*/', i + 2); i = end < 0 ? source.length : end + 2 }
|
|
13
|
+
else { if (source[i] === '(') depth++; if (source[i] === ')') depth--; i++ }
|
|
14
|
+
}
|
|
15
|
+
} else i += 2
|
|
16
|
+
} else if (source[i++] === quote) return i
|
|
17
|
+
}
|
|
18
|
+
return i
|
|
19
|
+
}
|
|
20
|
+
function tokenize(source) {
|
|
21
|
+
const tokens = []
|
|
22
|
+
let newline = false, breaks = 0
|
|
23
|
+
for (let i = 0; i < source.length;) {
|
|
24
|
+
if (/\s/u.test(source[i])) { if (source[i] === '\n') { newline = true; breaks++ } i++; continue }
|
|
25
|
+
const start = i
|
|
26
|
+
let kind = 'punctuation'
|
|
27
|
+
if (source.startsWith('//', i)) {
|
|
28
|
+
kind = 'lineComment'; const end = source.indexOf('\n', i); i = end < 0 ? source.length : end
|
|
29
|
+
} else if (source.startsWith('/*', i)) {
|
|
30
|
+
kind = 'comment'; i += 2; let depth = 1
|
|
31
|
+
while (i < source.length && depth) {
|
|
32
|
+
if (source.startsWith('/*', i)) { depth++; i += 2 }
|
|
33
|
+
else if (source.startsWith('*/', i)) { depth--; i += 2 }
|
|
34
|
+
else i++
|
|
35
|
+
}
|
|
36
|
+
} else if (source[i] === '"' || source[i] === "'") {
|
|
37
|
+
kind = 'literal'; i = stringEnd(source, i)
|
|
38
|
+
} else if (/[0-9]/u.test(source[i])) {
|
|
39
|
+
kind = 'literal'
|
|
40
|
+
const number = /^(?:[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)/u.exec(source.slice(i))[0]
|
|
41
|
+
i += number.length
|
|
42
|
+
} else if (/[A-Za-z_]/u.test(source[i])) {
|
|
43
|
+
kind = 'word'; i++
|
|
44
|
+
while (/[A-Za-z_0-9]/u.test(source[i] ?? '')) i++
|
|
45
|
+
} else {
|
|
46
|
+
const operator = /^(?:\.\.\.|\.\.<|->|\+=|-=|\*=|\/=|==|!=|<=|>=|&&|\|\||\?\?)/u.exec(source.slice(i))?.[0]
|
|
47
|
+
i += operator?.length ?? 1
|
|
48
|
+
}
|
|
49
|
+
tokens.push({ text: source.slice(start, i), kind, newline, blank: breaks > 1 }); newline = false; breaks = 0
|
|
50
|
+
}
|
|
51
|
+
return tokens
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function formatSource(source) {
|
|
55
|
+
// Raw/multiline literals are not reformatted until their indentation contract
|
|
56
|
+
// can be preserved. This is deliberate, not a lossy best-effort transformation.
|
|
57
|
+
if (source.includes('"""') || source.includes('`') || source.includes('#"')) return source
|
|
58
|
+
const tokens = tokenize(source.replace(/\r\n/gu, '\n'))
|
|
59
|
+
const lines = [], stack = []
|
|
60
|
+
let line = '', previous
|
|
61
|
+
const indent = () => stack.filter(item => item.multiline).length
|
|
62
|
+
const flush = () => { if (line.trim()) lines.push(`${' '.repeat(indent())}${line.trim()}`); line = '' }
|
|
63
|
+
const write = (text, space = false) => { if (space && line && !line.endsWith(' ')) line += ' '; line += text }
|
|
64
|
+
const binary = new Set(['=', '+=', '-=', '*=', '/=', '==', '!=', '<=', '>=', '&&', '||', '??', '->', '+', '*', '/'])
|
|
65
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
66
|
+
const token = tokens[index], next = tokens[index + 1], text = token.text
|
|
67
|
+
if (token.newline && line && !['.', ',', ')', ']'].includes(text) && previous?.text !== '@') flush()
|
|
68
|
+
if (token.blank) { flush(); if (lines.length && lines.at(-1) !== '') lines.push('') }
|
|
69
|
+
if (text === '}') {
|
|
70
|
+
flush(); const block = stack.pop(); write('}')
|
|
71
|
+
if (block?.block && next?.text !== 'else' && ![')', ']', ',', ';', '.'].includes(next?.text)) flush()
|
|
72
|
+
} else if (text === '{') {
|
|
73
|
+
write('{', !!line)
|
|
74
|
+
flush(); stack.push({ block: true, multiline: true })
|
|
75
|
+
} else if (text === '(' || text === '[') {
|
|
76
|
+
const multiline = !!next?.newline
|
|
77
|
+
write(text, text === '[' && ['return', 'in'].includes(previous?.text))
|
|
78
|
+
if (multiline) flush()
|
|
79
|
+
stack.push({ block: false, multiline })
|
|
80
|
+
} else if (text === ')' || text === ']') {
|
|
81
|
+
const delimiter = stack.at(-1)
|
|
82
|
+
if (delimiter?.multiline) flush()
|
|
83
|
+
stack.pop(); write(text)
|
|
84
|
+
} else if (text === ',') {
|
|
85
|
+
write(','); if (next?.newline) flush(); else write(' ')
|
|
86
|
+
} else if (text === ':') {
|
|
87
|
+
write(':'); write(' ')
|
|
88
|
+
} else if (text === ';') {
|
|
89
|
+
write(';'); flush()
|
|
90
|
+
} else if (text === '.') {
|
|
91
|
+
if (token.newline && line) flush()
|
|
92
|
+
write('.')
|
|
93
|
+
} else if (text === '@' || text === '$') {
|
|
94
|
+
write(text, previous?.kind === 'word')
|
|
95
|
+
} else if (token.kind === 'lineComment') {
|
|
96
|
+
write(text, !!line); flush()
|
|
97
|
+
} else if (token.kind === 'comment') {
|
|
98
|
+
write(text, !!line); if (next?.newline) flush()
|
|
99
|
+
} else if (binary.has(text)) {
|
|
100
|
+
write(text, true); write(' ')
|
|
101
|
+
} else {
|
|
102
|
+
const space = line && previous && (previous.kind === 'word' || previous.kind === 'literal' || previous.kind === 'comment' || [')', ']', '}'].includes(previous.text))
|
|
103
|
+
write(text, !!space)
|
|
104
|
+
}
|
|
105
|
+
previous = token
|
|
106
|
+
}
|
|
107
|
+
flush()
|
|
108
|
+
return `${lines.join('\n')}\n`
|
|
109
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Hot-reload compatibility between the running and the newly compiled program.
|
|
2
|
+
//
|
|
3
|
+
// State identity is the compiler's semantic identity (`@component/<View path>/
|
|
4
|
+
// <name>`), never a source line. A state value may survive only when the new
|
|
5
|
+
// program declares the same identity with the same declared Mün type and the
|
|
6
|
+
// same owning keyed scope. Anything else starts from its new initial value;
|
|
7
|
+
// changes that alter what "the application" is require a process restart.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {{ program: any, metadata: { states: { name: string, type: string, scope?: string }[] } }} previous
|
|
11
|
+
* @param {{ program: any, metadata: { states: { name: string, type: string, scope?: string }[] } }} next
|
|
12
|
+
*/
|
|
13
|
+
export function analyzeCompatibility(previous, next) {
|
|
14
|
+
const restart = reason => ({ mode: 'restart', reason, preserve: [], reset: [], added: [], removed: [] })
|
|
15
|
+
if (previous.program.version !== next.program.version) return restart('Semantic UI IR version changed')
|
|
16
|
+
if (previous.program.entry !== next.program.entry) return restart(`@main entry changed (${previous.program.entry} → ${next.program.entry})`)
|
|
17
|
+
if (previous.program.root.id !== next.program.root.id) return restart('Root window identity changed')
|
|
18
|
+
|
|
19
|
+
const before = new Map(previous.metadata.states.map(state => [state.name, state]))
|
|
20
|
+
const preserve = [], reset = [], added = []
|
|
21
|
+
for (const state of next.metadata.states) {
|
|
22
|
+
const old = before.get(state.name)
|
|
23
|
+
if (!old) added.push(state.name)
|
|
24
|
+
else if (old.type === state.type && (old.scope ?? null) === (state.scope ?? null)) preserve.push(state.name)
|
|
25
|
+
else reset.push({ name: state.name, reason: old.type !== state.type ? `type ${old.type} → ${state.type}` : 'owning keyed scope changed' })
|
|
26
|
+
before.delete(state.name)
|
|
27
|
+
}
|
|
28
|
+
return { mode: 'hot', reason: undefined, preserve, reset, added, removed: [...before.keys()] }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Human-readable name for a state identity: `Row.on` instead of the full path. */
|
|
32
|
+
export function stateLabel(name) {
|
|
33
|
+
const parts = name.split('/')
|
|
34
|
+
const field = parts.at(-1)
|
|
35
|
+
const component = parts.lastIndexOf('component')
|
|
36
|
+
const owner = component >= 0 ? parts[component + 1] : parts[2]
|
|
37
|
+
return `${owner}.${field}`
|
|
38
|
+
}
|