@cmodjs/core 5.6.0 → 5.8.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/docs/commands.md +7 -5
- package/docs/dependencies.md +2 -2
- package/docs/install-steps.md +1 -1
- package/docs/mod.md +1 -1
- package/docs/ui.md +5 -3
- package/package.json +2 -2
- package/records.d.ts +15 -2
- package/records.d.ts.map +1 -1
- package/records.js +15 -3
- package/register.d.ts +3 -0
- package/register.d.ts.map +1 -1
- package/register.js +25 -15
- package/runtime/before.d.ts +3 -0
- package/runtime/before.d.ts.map +1 -1
- package/runtime/before.js +66 -31
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +29 -9
- package/runtime/lifecycle.d.ts +24 -2
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +36 -31
- package/runtime/pages.d.ts +2 -1
- package/runtime/pages.d.ts.map +1 -1
- package/runtime/pages.js +3 -6
- package/runtime/programs.d.ts +1 -0
- package/runtime/programs.d.ts.map +1 -1
- package/runtime/programs.js +8 -1
- package/runtime/router.d.ts +4 -2
- package/runtime/router.d.ts.map +1 -1
- package/runtime/router.js +10 -8
- package/runtime/toaster.d.ts.map +1 -1
- package/runtime/toaster.js +15 -7
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +27 -24
- package/src/records.ts +17 -3
- package/src/register.ts +29 -13
- package/src/runtime/before.ts +71 -34
- package/src/runtime/conversations.ts +26 -8
- package/src/runtime/lifecycle.ts +61 -43
- package/src/runtime/pages.ts +4 -3
- package/src/runtime/programs.ts +12 -1
- package/src/runtime/router.ts +11 -9
- package/src/runtime/toaster.ts +15 -7
- package/src/runtime/ui.ts +24 -21
- package/src/testing/fake-elements.ts +15 -3
- package/src/testing.ts +6 -3
- package/testing/fake-elements.js +15 -3
- package/testing.d.ts.map +1 -1
- package/testing.js +6 -3
- package/vendor-markdown.js +4 -8698
- package/vendor.js +7 -3384
package/src/runtime/lifecycle.ts
CHANGED
|
@@ -3,20 +3,20 @@ import type { Step } from '../installer.js'
|
|
|
3
3
|
|
|
4
4
|
import type { Imports, Mod, ModDefinition, Reservation, SettingsFile, SettingsFileChange, SettingsFileChangeListener, Subscription, Timer as ModTimer } from '../mod.js'
|
|
5
5
|
import type { Options, OptionValues } from '../options.js'
|
|
6
|
-
import { dataFolder, finishStepsMethod, isAtLeast, isProgramNewer, oldestCmodVersion, pendingStepsMethod, parseEvent, programPath,
|
|
6
|
+
import { dataFolder, finishStepsMethod, isAtLeast, isProgramNewer, oldestCmodVersion, pendingStepsMethod, parseEvent, programPath, readRecord, readSteps, recordPath, scriptsSha256, storeFolder, type ReadFile, type RunnerEvent, type Steps } from '../records.js'
|
|
7
7
|
import { homePrefix, ifMissing, relativePath } from '../utils/paths.js'
|
|
8
8
|
import { firstLine, formatExit, messageOf } from '../utils/text.js'
|
|
9
9
|
import type { Claude } from './claude.js'
|
|
10
10
|
import { beforeDeadline, settledAfterAbort } from './deadline.js'
|
|
11
11
|
import { announcementMs, announcementOf } from './announce.js'
|
|
12
12
|
import { bind } from './bound.js'
|
|
13
|
-
import {
|
|
13
|
+
import type { Conversations } from './conversations.js'
|
|
14
14
|
import { answerCall, answeringOwnCalls, cmodPluginName, dependencyCalls, loadedMethod, withBareRefusals } from './dependencies.js'
|
|
15
15
|
import type { Device } from '../session/context/turn/device.js'
|
|
16
16
|
import { keepEngine } from './engine.js'
|
|
17
17
|
import { classicFailure, classicHook, userSkillHook, type Hook, type HookFields, type HookListener, type RoutedEvent } from './hooks.js'
|
|
18
18
|
import type { PermissionRoutes } from './permission-check.js'
|
|
19
|
-
import { cmodError, locatingPrograms, readLines, spawnCmod, type Programs } from './programs.js'
|
|
19
|
+
import { cmodError, locatingPrograms, newestCmodVersion, readLines, spawnCmod, type Programs } from './programs.js'
|
|
20
20
|
import { createModFiles, resolvedPath, type Places } from './metadata.js'
|
|
21
21
|
import { fitsOption } from '../options.js'
|
|
22
22
|
import { createInstaller } from './installer.js'
|
|
@@ -30,11 +30,11 @@ import { createState } from './state.js'
|
|
|
30
30
|
import { createToaster, type Failure, type ShownToast, type Toaster } from './toaster.js'
|
|
31
31
|
import { toolCalls } from './tool-calls.js'
|
|
32
32
|
import { createHotkeys } from './hotkeys.js'
|
|
33
|
-
import {
|
|
33
|
+
import type { Pages } from './pages.js'
|
|
34
34
|
import { drawnParts, type DrawnParts } from './parts.js'
|
|
35
35
|
import { createWatches } from './watches.js'
|
|
36
|
-
import { createUi, partMethods, type BorrowedMarkdown, type PartDraw, type PartPress, type PartsUpdate, type ShownPages, type UiArea } from './ui.js'
|
|
37
|
-
import {
|
|
36
|
+
import { createUi, partMethods, stalePress, type BorrowedMarkdown, type PartDraw, type PartPress, type PartsUpdate, type ShownPages, type UiArea } from './ui.js'
|
|
37
|
+
import type { Widgets } from './widgets.js'
|
|
38
38
|
import { Progress } from '../ui/components.js'
|
|
39
39
|
import { Box, Text } from '../ui/elements.js'
|
|
40
40
|
|
|
@@ -63,6 +63,21 @@ export type Lifecycle<State extends object> = {
|
|
|
63
63
|
raise(method: string, payload: Readonly<Record<string, unknown>>): Promise<unknown>
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
export type CmodPlugin = { readonly conversations: Conversations; readonly widgets: Widgets; readonly pages: Pages }
|
|
67
|
+
|
|
68
|
+
export type ServeCmodPlugin = (served: {
|
|
69
|
+
readonly claude: Claude
|
|
70
|
+
readonly router: Router
|
|
71
|
+
readonly store: string
|
|
72
|
+
readonly project: () => string
|
|
73
|
+
readonly report: (id: string, message: string, error: unknown) => void
|
|
74
|
+
readonly clear: (id: string) => void
|
|
75
|
+
readonly tellRefusedPress: (mod: string, error: unknown) => void
|
|
76
|
+
readonly parts: DrawnParts
|
|
77
|
+
readonly markdownIn: UiArea<object>['markdownIn']
|
|
78
|
+
readonly tellStylers: UiArea<object>['restyled']
|
|
79
|
+
}) => CmodPlugin
|
|
80
|
+
|
|
66
81
|
type ModRuntime = {
|
|
67
82
|
readonly claude: Claude
|
|
68
83
|
readonly router: Router
|
|
@@ -72,6 +87,7 @@ type ModRuntime = {
|
|
|
72
87
|
readonly permissionRoutes: () => PermissionRoutes | undefined
|
|
73
88
|
readonly options: PluginOptions
|
|
74
89
|
readonly nextDraw: () => number
|
|
90
|
+
readonly serveCmodPlugin: ServeCmodPlugin | undefined
|
|
75
91
|
}
|
|
76
92
|
|
|
77
93
|
type ActiveMod<State extends object, Declared extends Options> = {
|
|
@@ -128,7 +144,7 @@ export async function readPlugin(claude: Claude): Promise<Plugin> {
|
|
|
128
144
|
const store = storeFolder({ HOME: await claude.env.home(), XDG_DATA_HOME: await claude.env.dataHome() })
|
|
129
145
|
const steps = readSteps(await readJson(read, `${root}/package.json`)) ?? {}
|
|
130
146
|
if (name === cmodPluginName) {
|
|
131
|
-
const installed = await
|
|
147
|
+
const installed = await newestCmodVersion(claude)
|
|
132
148
|
return { name, root, version, store, steps, isInstalled: version !== undefined && installed !== undefined && isAtLeast(installed, version), shouldRecord: false }
|
|
133
149
|
}
|
|
134
150
|
const plugin = { name, root, version, store, steps }
|
|
@@ -166,24 +182,15 @@ async function readJson(read: ReadFile, path: string): Promise<unknown> {
|
|
|
166
182
|
}
|
|
167
183
|
}
|
|
168
184
|
|
|
169
|
-
async function cmodVersion(claude: Claude): Promise<string | undefined> {
|
|
170
|
-
const store = storeFolder({ HOME: await claude.env.home(), XDG_DATA_HOME: await claude.env.dataHome() })
|
|
171
|
-
return readCmodVersion(
|
|
172
|
-
{
|
|
173
|
-
list: async (folder) => (await claude.fs.list(folder).catch(ifMissing([]))).map((entry) => entry.name),
|
|
174
|
-
exists: async (path) => (await claude.fs.stat(path).catch(ifMissing(undefined))) !== undefined,
|
|
175
|
-
},
|
|
176
|
-
store,
|
|
177
|
-
)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
185
|
export function createLifecycle<State extends object, Declared extends Options = Options>(
|
|
181
186
|
definition: ModDefinition<State, string, Declared>,
|
|
182
187
|
permissionRoutes: () => PermissionRoutes | undefined = () => undefined,
|
|
183
188
|
options: PluginOptions = {},
|
|
184
189
|
asksPerson = true,
|
|
190
|
+
serveCmodPlugin?: ServeCmodPlugin,
|
|
185
191
|
): Lifecycle<State> {
|
|
186
192
|
let router: Router = createRouter()
|
|
193
|
+
let startingRouter: Router | undefined
|
|
187
194
|
let phase: Phase = 'starting'
|
|
188
195
|
let runtime: Pick<ModRuntime, 'claude' | 'toaster'> | undefined
|
|
189
196
|
let programs: Programs | undefined
|
|
@@ -286,7 +293,7 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
286
293
|
}
|
|
287
294
|
|
|
288
295
|
const recordThroughCmod = async () => {
|
|
289
|
-
if (plugin === undefined || (await
|
|
296
|
+
if (plugin === undefined || (await newestCmodVersion(claude())) === undefined) return
|
|
290
297
|
let failed: string | undefined
|
|
291
298
|
const { code, lastError } = await readLines(claude().process.spawn({ argv: ['cmod', 'setup', plugin.root, '--events'] }), (text) => {
|
|
292
299
|
const event = parseEvent(text)
|
|
@@ -372,12 +379,17 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
372
379
|
const activate = async (): Promise<void> => {
|
|
373
380
|
if (runtime === undefined || plugin === undefined) return
|
|
374
381
|
const activeRouter = createRouter()
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
382
|
+
startingRouter = activeRouter
|
|
383
|
+
const active = await createMod(definition, { ...runtime, router: activeRouter, dataFolder: dataFolder(plugin.store, plugin.name), store: plugin.store, permissionRoutes, options: pluginOptions, nextDraw, serveCmodPlugin })
|
|
384
|
+
.catch(async (error: unknown) => {
|
|
385
|
+
if (error instanceof MissingOptions && (await askOptions(error))) return undefined
|
|
386
|
+
await installer.close()
|
|
387
|
+
fail(messageOf(error), error instanceof MissingOptions ? `Retry asks for ${error.keys.length === 1 ? 'it' : 'them'}.` : undefined, begin, error)
|
|
388
|
+
throw error
|
|
389
|
+
})
|
|
390
|
+
.finally(() => {
|
|
391
|
+
startingRouter = undefined
|
|
392
|
+
})
|
|
381
393
|
if (active === undefined) return activate()
|
|
382
394
|
const { added } = active
|
|
383
395
|
mod = active.mod
|
|
@@ -429,7 +441,7 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
429
441
|
if (plugin === undefined) return
|
|
430
442
|
if (plugin.name === cmodPluginName) return bootstrap(plugin.root)
|
|
431
443
|
phase = 'installing'
|
|
432
|
-
const found = await
|
|
444
|
+
const found = await newestCmodVersion(claude())
|
|
433
445
|
if (!fits(found)) return waitForcmod(found)
|
|
434
446
|
if (!isQuiet) installing()
|
|
435
447
|
let outcome: RunnerEvent | undefined
|
|
@@ -460,7 +472,7 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
460
472
|
}
|
|
461
473
|
const poll = (ms: number) =>
|
|
462
474
|
claude().clock.every(ms, () => {
|
|
463
|
-
check ??=
|
|
475
|
+
check ??= newestCmodVersion(claude())
|
|
464
476
|
.then((version) => {
|
|
465
477
|
check = undefined
|
|
466
478
|
latest = version
|
|
@@ -575,24 +587,24 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
575
587
|
if (activation !== undefined && phase !== 'active') await activation
|
|
576
588
|
}
|
|
577
589
|
|
|
578
|
-
const held = (work: Promise<void>, signal: AbortSignal | undefined): Promise<
|
|
590
|
+
const held = (work: Promise<void>, signal: AbortSignal | undefined): Promise<boolean> =>
|
|
579
591
|
runtime === undefined
|
|
580
|
-
? work
|
|
581
|
-
: new Promise<
|
|
582
|
-
const limit = claude().clock.after(startHoldMs, resolve)
|
|
583
|
-
if (signal?.aborted === true) resolve()
|
|
584
|
-
signal?.addEventListener('abort', () => resolve(), { once: true })
|
|
592
|
+
? work.then(() => false)
|
|
593
|
+
: new Promise<boolean>((resolve) => {
|
|
594
|
+
const limit = claude().clock.after(startHoldMs, () => resolve(true))
|
|
595
|
+
if (signal?.aborted === true) resolve(false)
|
|
596
|
+
signal?.addEventListener('abort', () => resolve(false), { once: true })
|
|
585
597
|
void work.then(() => {
|
|
586
598
|
limit.cancel()
|
|
587
|
-
resolve()
|
|
599
|
+
resolve(false)
|
|
588
600
|
})
|
|
589
601
|
})
|
|
590
602
|
|
|
591
|
-
const holdUntilStarted = (signal?: AbortSignal): Promise<
|
|
603
|
+
const holdUntilStarted = (signal?: AbortSignal): Promise<boolean> => held(startSettled.then(whenActive), signal)
|
|
592
604
|
|
|
593
|
-
const holdUntilActive = (signal: AbortSignal | undefined): Promise<
|
|
605
|
+
const holdUntilActive = (signal: AbortSignal | undefined): Promise<boolean> => {
|
|
594
606
|
const activating = whenActive()
|
|
595
|
-
return activation !== undefined && phase !== 'active' ? held(activating, signal) : activating
|
|
607
|
+
return activation !== undefined && phase !== 'active' ? held(activating, signal) : activating.then(() => false)
|
|
596
608
|
}
|
|
597
609
|
|
|
598
610
|
const routed = async <N extends RoutedEvent>(event: N, e: Frozen<Args<N>>, next: RouterNext<N>, signal?: AbortSignal): Promise<EventResult<N>> => {
|
|
@@ -617,7 +629,7 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
617
629
|
const tool = (e as { readonly tool?: unknown }).tool
|
|
618
630
|
const isCallToThisMod = (event === 'cmod.call' && (e as Frozen<Args<'cmod.call'>>).to === definition.name) || (event === 'tool.call' && typeof tool === 'string' && tool.startsWith(`mcp__${definition.name}__`))
|
|
619
631
|
if (event === 'cmod.call' && !isCallToThisMod) return next(e)
|
|
620
|
-
await (event === 'classic.SessionStart' || event === 'session.append' || isCallToThisMod ? holdUntilStarted(signal) : holdUntilActive(signal))
|
|
632
|
+
const isLate = await (event === 'classic.SessionStart' || event === 'session.append' || isCallToThisMod ? holdUntilStarted(signal) : holdUntilActive(signal))
|
|
621
633
|
if (event === 'classic.SessionStart' && phase !== 'active') {
|
|
622
634
|
missedSessionStart = e as Frozen<Args<'classic.SessionStart'>>
|
|
623
635
|
return next(e)
|
|
@@ -629,6 +641,7 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
629
641
|
}
|
|
630
642
|
return { deny: phase === 'failed' ? notSetUp() : `${definition.name} is installing. Try again when it's ready.` } as EventResult<N>
|
|
631
643
|
}
|
|
644
|
+
if (isLate && phase !== 'active') return (startingRouter ?? router).dispatchFailure(event, e, new Error(`it was still starting after ${startHoldMs / 1000} s`), next, false)
|
|
632
645
|
const call = e as Frozen<Args<'cmod.call'>>
|
|
633
646
|
if (event === 'cmod.call' && call.to === definition.name && mod !== undefined) {
|
|
634
647
|
if (call.method === pendingStepsMethod) return { value: await pendingSteps(mod) } as EventResult<N>
|
|
@@ -712,7 +725,7 @@ export function createLifecycle<State extends object, Declared extends Options =
|
|
|
712
725
|
const error = new Error(reason)
|
|
713
726
|
const failedBeneath = called && kind === 'throw' ? await next(e).then(() => undefined, messageOf) : undefined
|
|
714
727
|
if (failedBeneath === undefined || failedBeneath !== message) toastFailure({ id: `stopped:${event}`, message: `Claude Code stopped its ${event.replace(/^classic\./, '')} hook`, error })
|
|
715
|
-
return router.dispatchFailure(event, e, error, next)
|
|
728
|
+
return (startingRouter ?? router).dispatchFailure(event, e, error, next, called)
|
|
716
729
|
},
|
|
717
730
|
}
|
|
718
731
|
}
|
|
@@ -1011,18 +1024,23 @@ async function createMod<State extends object, Declared extends Options>(definit
|
|
|
1011
1024
|
router.add('skill.prompt', userSkillHook(claude))
|
|
1012
1025
|
router.add('ui.press', (e, next) => area.asked(() => next(e)))
|
|
1013
1026
|
let api: Readonly<Record<string, (input: never) => unknown>> = {}
|
|
1014
|
-
const conversations = definition.name === cmodPluginName ? serveConversations({ claude, router, store: runtime.store, project: () => modState.root, report: (id, message, error) => report({ id, message, error }), clear: (id) => toaster.toast.dismiss(id) }) : undefined
|
|
1015
1027
|
let pages: Pages | undefined
|
|
1016
1028
|
const reportPart = (id: string, message: string, error: unknown) => report({ id, message, error })
|
|
1029
|
+
const tellRefusedPress = (to: string, error: unknown) => {
|
|
1030
|
+
if (messageOf(error).includes(stalePress)) toaster.toast.warning(`The ${to} button was from an older drawing, so nothing ran`, { id: `press:${to}`, description: 'Press the button it shows now.' })
|
|
1031
|
+
else report({ id: `press:${to}`, message: `${to} did not take the press`, error, isCritical: true })
|
|
1032
|
+
}
|
|
1017
1033
|
const pressElsewhere = (to: string, input: PartPress) =>
|
|
1018
1034
|
void claude.cmod.call({ to, method: partMethods.press, input }).catch((error: unknown) => {
|
|
1019
1035
|
parts?.forget(to)
|
|
1020
1036
|
claude.ui.invalidate('ui.render')
|
|
1021
|
-
|
|
1037
|
+
tellRefusedPress(to, error)
|
|
1022
1038
|
})
|
|
1023
1039
|
parts = drawnParts({ claude, report: reportPart, press: (to, input) => (pages === undefined ? pressElsewhere(to, input) : pages.press(to, input)) })
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1040
|
+
const served = runtime.serveCmodPlugin?.({ claude, router, store: runtime.store, project: () => modState.root, report: reportPart, clear: (id) => toaster.toast.dismiss(id), tellRefusedPress, parts, markdownIn: area.markdownIn, tellStylers: area.restyled })
|
|
1041
|
+
const conversations = served?.conversations
|
|
1042
|
+
const widgets = served?.widgets
|
|
1043
|
+
pages = served?.pages
|
|
1026
1044
|
const tellColor = (to: string, told: SessionColor) => {
|
|
1027
1045
|
if (told.session === '' || to === cmodPluginName) return
|
|
1028
1046
|
claude.clock.after(0, () => void claude.cmod.call({ to, method: conversationMethods.sessionColor, input: told }).catch((error: unknown) => claude.ui.warn('color:tell', `cmod: ${to} did not hear the session's color: ${messageOf(error)}`)))
|
package/src/runtime/pages.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Claude } from './claude.js'
|
|
|
6
6
|
import { cmodPluginName, isNotInstalled } from './dependencies.js'
|
|
7
7
|
import type { DrawnParts } from './parts.js'
|
|
8
8
|
import type { Router } from './router.js'
|
|
9
|
-
import { partMethods,
|
|
9
|
+
import { partMethods, type PageDeclaration, type PageRequest, type PartPress, type PartsUpdate, type ShownPages } from './ui.js'
|
|
10
10
|
import type { Widgets } from './widgets.js'
|
|
11
11
|
|
|
12
12
|
const askedWaitMs = 1000
|
|
@@ -34,6 +34,7 @@ export function servePages({
|
|
|
34
34
|
claude,
|
|
35
35
|
router,
|
|
36
36
|
report,
|
|
37
|
+
tellRefusedPress,
|
|
37
38
|
widgets,
|
|
38
39
|
parts,
|
|
39
40
|
tellStylers,
|
|
@@ -41,6 +42,7 @@ export function servePages({
|
|
|
41
42
|
readonly claude: Claude
|
|
42
43
|
readonly router: Router
|
|
43
44
|
readonly report: (id: string, message: string, error: unknown) => void
|
|
45
|
+
readonly tellRefusedPress: (mod: string, error: unknown) => void
|
|
44
46
|
readonly widgets: Pick<Widgets, 'update'>
|
|
45
47
|
readonly parts: DrawnParts
|
|
46
48
|
readonly tellStylers: (stylers: readonly string[]) => void
|
|
@@ -131,8 +133,7 @@ export function servePages({
|
|
|
131
133
|
(error: unknown) => {
|
|
132
134
|
parts.forget(mod)
|
|
133
135
|
claude.ui.invalidate('ui.render')
|
|
134
|
-
|
|
135
|
-
else report(`press:${mod}`, `${mod} did not take the press`, error)
|
|
136
|
+
tellRefusedPress(mod, error)
|
|
136
137
|
},
|
|
137
138
|
)
|
|
138
139
|
.finally(() => pressing.delete(pending))
|
package/src/runtime/programs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HookStream, ProcessSpawnChunk, ProcessSpawnResult } from 'claude-code'
|
|
2
|
-
import { storeFolder } from '../records.js'
|
|
2
|
+
import { readCmodVersion, storeFolder } from '../records.js'
|
|
3
3
|
import { ifMissing } from '../utils/paths.js'
|
|
4
4
|
import { formatExit } from '../utils/text.js'
|
|
5
5
|
import type { Claude } from './claude.js'
|
|
@@ -46,6 +46,17 @@ export async function isHeld(claude: Claude, lock: string, staleMs: number): Pro
|
|
|
46
46
|
return touched.some((at) => now - at < staleMs)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
export async function newestCmodVersion(claude: Claude): Promise<string | undefined> {
|
|
50
|
+
const store = storeFolder({ HOME: await claude.env.home(), XDG_DATA_HOME: await claude.env.dataHome() })
|
|
51
|
+
return readCmodVersion(
|
|
52
|
+
{
|
|
53
|
+
list: async (folder) => (await claude.fs.list(folder).catch(ifMissing([]))).map((entry) => entry.name),
|
|
54
|
+
exists: async (path) => (await claude.fs.stat(path).catch(ifMissing(undefined))) !== undefined,
|
|
55
|
+
},
|
|
56
|
+
store,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
49
60
|
export async function runCmod(claude: Claude, args: readonly string[], session: string): Promise<string> {
|
|
50
61
|
const lines: string[] = []
|
|
51
62
|
const { code, lastError } = await readLines(spawnCmod(claude, args, session), (line) => void lines.push(line))
|
package/src/runtime/router.ts
CHANGED
|
@@ -8,17 +8,17 @@ export type RoutedNext<N extends RoutedEvent> = RouterNext<N> & { readonly signa
|
|
|
8
8
|
|
|
9
9
|
export type RoutedHook<N extends RoutedEvent> = (e: Frozen<Args<N>>, next: RoutedNext<N>) => EventResult<N> | Promise<EventResult<N>>
|
|
10
10
|
|
|
11
|
-
export type RoutedFailure<N extends RoutedEvent> = (e: Frozen<Args<N>>, error: Error, next: RoutedNext<N>) => EventResult<N> | undefined | Promise<EventResult<N> | undefined>
|
|
11
|
+
export type RoutedFailure<N extends RoutedEvent> = (e: Frozen<Args<N>>, error: Error, next: RoutedNext<N> & { readonly called: boolean }) => EventResult<N> | undefined | Promise<EventResult<N> | undefined>
|
|
12
12
|
|
|
13
13
|
export type Router = {
|
|
14
14
|
add<N extends RoutedEvent>(event: N, hook: RoutedHook<N>, failed?: RoutedFailure<N>): Subscription
|
|
15
15
|
dispatch<N extends RoutedEvent>(event: N, e: Frozen<Args<N>>, next: RouterNext<N>, signal?: AbortSignal): Promise<EventResult<N>>
|
|
16
|
-
dispatchFailure<N extends RoutedEvent>(event: N, e: Frozen<Args<N>>, error: Error, next: RouterNext<N
|
|
16
|
+
dispatchFailure<N extends RoutedEvent>(event: N, e: Frozen<Args<N>>, error: Error, next: RouterNext<N>, called: boolean): Promise<EventResult<N>>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type Next = ((e: unknown) => Promise<unknown>) & { readonly signal: AbortSignal }
|
|
20
20
|
|
|
21
|
-
type Route = { readonly hook: (e: unknown, next: Next) => unknown; readonly failed?: (e: unknown, error: Error, next: Next) => unknown }
|
|
21
|
+
type Route = { readonly hook: (e: unknown, next: Next) => unknown; readonly failed?: (e: unknown, error: Error, next: Next & { readonly called: boolean }) => unknown }
|
|
22
22
|
|
|
23
23
|
export const unaborted = new AbortController().signal
|
|
24
24
|
|
|
@@ -46,13 +46,15 @@ export function createRouter(): Router {
|
|
|
46
46
|
}
|
|
47
47
|
return call(0, e) as Promise<EventResult<N>>
|
|
48
48
|
},
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
49
|
+
dispatchFailure<N extends RoutedEvent>(event: N, e: Frozen<Args<N>>, error: Error, next: RouterNext<N>, called: boolean): Promise<EventResult<N>> {
|
|
50
|
+
const chain = routes.get(event)
|
|
51
|
+
const fail = async (index: number, current: unknown): Promise<unknown> => {
|
|
52
|
+
const route = chain?.[index]
|
|
53
|
+
if (route === undefined) return next(current as Frozen<Args<N>>)
|
|
54
|
+
const answer = await route.failed?.(current, error, Object.assign((passed: unknown) => fail(index + 1, passed), { signal: unaborted, called }))
|
|
55
|
+
return answer === undefined ? fail(index + 1, current) : answer
|
|
54
56
|
}
|
|
55
|
-
return
|
|
57
|
+
return fail(0, e) as Promise<EventResult<N>>
|
|
56
58
|
},
|
|
57
59
|
}
|
|
58
60
|
}
|
package/src/runtime/toaster.ts
CHANGED
|
@@ -314,7 +314,7 @@ export function createToaster(claude: Claude, name: string, version: () => strin
|
|
|
314
314
|
changed()
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
const row = (entry: Entry): RenderElement => {
|
|
317
|
+
const row = (entry: Entry, columns: number): RenderElement => {
|
|
318
318
|
const { description } = entry.options
|
|
319
319
|
const isText = typeof description === 'string'
|
|
320
320
|
const icon = entry.type === 'loading' || entry.trying !== undefined ? { glyph: isSpinning(entry) ? (spinner[frame % spinner.length] as string) : still, color: 'claude' } : icons[entry.type]
|
|
@@ -323,17 +323,25 @@ export function createToaster(claude: Claude, name: string, version: () => strin
|
|
|
323
323
|
const fixed = (child: RenderElement) => Box({ flexShrink: 0, children: child })
|
|
324
324
|
const close = Button({ plain: true, dimColor: true, key: `toast:${entry.id}:close`, label: entry.hides === undefined ? '✕' : 'Hide', onPress: () => hide(entry) })
|
|
325
325
|
const actions = entry.actions.map((action, index) => Button({ plain: true, key: `toast:${entry.id}:${index === 0 ? 'action' : `action-${index}`}`, label: action.label, onPress: press(entry, action.onClick) }))
|
|
326
|
-
const buttons = Box({ gap: 2, flexWrap: 'wrap', children: [...actions,
|
|
326
|
+
const buttons = Box({ gap: 2, flexWrap: 'wrap', children: [...actions, Text({ dimColor: true, children: clockTime(entry.at) })].map(fixed) })
|
|
327
327
|
const trying = entry.trying === undefined ? undefined : Box({ gap: 1, children: [Text({ dimColor: true, children: 'Trying again:' }), typeof entry.trying === 'string' ? Text({ dimColor: true, wrap: 'truncate-end', children: entry.trying }) : entry.trying] })
|
|
328
328
|
const text = details === undefined ? [message] : [message, trying ?? details]
|
|
329
329
|
const under = trying !== undefined && details === undefined ? [trying] : entry.reporting === undefined ? [buttons] : reportChoices(entry, entry.reporting)
|
|
330
330
|
return Box({
|
|
331
|
+
width: columns,
|
|
331
332
|
gap: 2,
|
|
333
|
+
justifyContent: 'space-between',
|
|
332
334
|
children: [
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
Box({
|
|
336
|
+
gap: 2,
|
|
337
|
+
flexShrink: 1,
|
|
338
|
+
children: [
|
|
339
|
+
fixed(Text({ ...(icon.color === undefined ? {} : { color: icon.color }), children: icon.glyph })),
|
|
340
|
+
fixed(Text({ dimColor: true, children: name })),
|
|
341
|
+
Box({ flexDirection: 'column', flexShrink: 1, children: entry.hides === undefined ? text : [...text, ...under] }),
|
|
342
|
+
],
|
|
343
|
+
}),
|
|
344
|
+
Box({ gap: 2, flexShrink: 0, alignSelf: 'flex-end', children: entry.hides === undefined ? [...actions, close] : [close] }),
|
|
337
345
|
],
|
|
338
346
|
})
|
|
339
347
|
}
|
|
@@ -397,7 +405,7 @@ export function createToaster(claude: Claude, name: string, version: () => strin
|
|
|
397
405
|
changed()
|
|
398
406
|
},
|
|
399
407
|
})
|
|
400
|
-
return drawWith(table, () => Box({ flexDirection: 'column', children: [drawn, ...(hidden > 0 ? [more] : []), ...all.slice(hidden).map(row)] }))
|
|
408
|
+
return drawWith(table, () => Box({ flexDirection: 'column', children: [drawn, ...(hidden > 0 ? [more] : []), ...all.slice(hidden).map((entry) => row(entry, band.bodyColumns))] }))
|
|
401
409
|
},
|
|
402
410
|
}
|
|
403
411
|
}
|
package/src/runtime/ui.ts
CHANGED
|
@@ -659,32 +659,34 @@ export function createUi<State extends object>({ name, claude, router, report, a
|
|
|
659
659
|
latestDraws.delete(key)
|
|
660
660
|
}
|
|
661
661
|
|
|
662
|
-
const drawPart = (key: string, title: string, input: PartDraw, render: () => RenderElement | undefined
|
|
662
|
+
const drawPart = (key: string, title: string, input: PartDraw, render: () => RenderElement | undefined, drawFailure: (error: unknown) => RenderElement | undefined = () => undefined): DrawnPart => {
|
|
663
|
+
let handlers: Handler[] = []
|
|
664
|
+
let tree: unknown
|
|
663
665
|
try {
|
|
664
|
-
|
|
665
|
-
const tree = treeOf(render, pressed)
|
|
666
|
+
tree = treeOf(render, handlers)
|
|
666
667
|
failedDraws.delete(key)
|
|
667
|
-
const number = nextDraw()
|
|
668
|
-
const inputs = latestDraws.get(key) ?? new Map<string, SentDrawing>()
|
|
669
|
-
latestDraws.set(key, inputs)
|
|
670
|
-
const drawnFor = JSON.stringify('turn' in input ? { ...input, turn: input.turn.prompt.id } : input)
|
|
671
|
-
const earlier = inputs.get(drawnFor)?.draws ?? []
|
|
672
|
-
const kept = [...earlier, number].slice(-2)
|
|
673
|
-
for (const draw of earlier) if (!kept.includes(draw)) draws.delete(draw)
|
|
674
|
-
inputs.delete(drawnFor)
|
|
675
|
-
inputs.set(drawnFor, { draws: kept, tree: JSON.stringify(tree), render })
|
|
676
|
-
const [oldest] = inputs
|
|
677
|
-
if (inputs.size > keptDrawInputs && oldest !== undefined) {
|
|
678
|
-
for (const draw of oldest[1].draws) draws.delete(draw)
|
|
679
|
-
inputs.delete(oldest[0])
|
|
680
|
-
}
|
|
681
|
-
draws.set(number, { id: key, handlers: pressed })
|
|
682
|
-
return { draw: number, tree }
|
|
683
668
|
} catch (error) {
|
|
684
669
|
if (!failedDraws.has(key)) report({ id: key, message: `The ${title} could not draw`, error })
|
|
685
670
|
failedDraws.add(key)
|
|
686
|
-
|
|
671
|
+
handlers = []
|
|
672
|
+
tree = treeOf(() => drawFailure(error), handlers)
|
|
673
|
+
}
|
|
674
|
+
const number = nextDraw()
|
|
675
|
+
const inputs = latestDraws.get(key) ?? new Map<string, SentDrawing>()
|
|
676
|
+
latestDraws.set(key, inputs)
|
|
677
|
+
const drawnFor = JSON.stringify('turn' in input ? { ...input, turn: input.turn.prompt.id } : input)
|
|
678
|
+
const earlier = inputs.get(drawnFor)?.draws ?? []
|
|
679
|
+
const kept = [...earlier, number].slice(-2)
|
|
680
|
+
for (const draw of earlier) if (!kept.includes(draw)) draws.delete(draw)
|
|
681
|
+
inputs.delete(drawnFor)
|
|
682
|
+
inputs.set(drawnFor, { draws: kept, tree: JSON.stringify(tree), render })
|
|
683
|
+
const [oldest] = inputs
|
|
684
|
+
if (inputs.size > keptDrawInputs && oldest !== undefined) {
|
|
685
|
+
for (const draw of oldest[1].draws) draws.delete(draw)
|
|
686
|
+
inputs.delete(oldest[0])
|
|
687
687
|
}
|
|
688
|
+
draws.set(number, { id: key, handlers })
|
|
689
|
+
return { draw: number, tree }
|
|
688
690
|
}
|
|
689
691
|
|
|
690
692
|
const draw = (input: PartDraw): DrawnPart | null => {
|
|
@@ -692,7 +694,8 @@ export function createUi<State extends object>({ name, claude, router, report, a
|
|
|
692
694
|
if ('page' in input) {
|
|
693
695
|
const added = pages.get(input.page)
|
|
694
696
|
if (added === undefined) throw new Error(`${name} has no ${input.page} page.`)
|
|
695
|
-
|
|
697
|
+
const title = `${added.init.title} page`
|
|
698
|
+
return drawPart(`page:${input.page}`, title, input, () => added.init.render(mod(), { params: input.params, isFocused: input.isFocused, columns: input.columns }), (error) => Text({ color: 'error', children: `The ${title} could not draw: ${messageOf(error)}` }))
|
|
696
699
|
}
|
|
697
700
|
const widget = widgets.get(input.widget)
|
|
698
701
|
if (widget === undefined || !widget.areas.includes(input.area)) return null
|
|
@@ -132,7 +132,7 @@ function boxRows({ props, children = [] }: Drawn, width: number): string[] {
|
|
|
132
132
|
const ordered = direction.endsWith('-reverse') ? [...flowing].reverse() : flowing
|
|
133
133
|
const outer = Math.min(width, size('width') ?? width)
|
|
134
134
|
const inner = outer - left - right - border * 2
|
|
135
|
-
const rows = direction.startsWith('column') ? stacked(ordered, inner, size('rowGap') ?? size('gap') ?? 0) : sideBySide(ordered, inner, size('columnGap') ?? size('gap') ?? 0, props['justifyContent'] === 'space-between')
|
|
135
|
+
const rows = direction.startsWith('column') ? stacked(ordered, inner, size('rowGap') ?? size('gap') ?? 0) : sideBySide(ordered, inner, size('columnGap') ?? size('gap') ?? 0, props['justifyContent'] === 'space-between', props['alignItems'])
|
|
136
136
|
const content = border === 1 && Number.isFinite(inner) ? inner : right === 0 && border === 0 ? 0 : Math.max(widthOf(rows), (size('minWidth') ?? 0) - left - right - border * 2)
|
|
137
137
|
const padded = [...blankRows(space('Top', 'Y')), ...rows.map((row) => `${' '.repeat(left)}${paddedTo(row, content)}${' '.repeat(right)}`), ...blankRows(space('Bottom', 'Y'))]
|
|
138
138
|
const framed = border === 0 ? padded : framedRows(padded, left + content + right, props['borderStyle'])
|
|
@@ -176,7 +176,7 @@ function stacked(children: readonly RenderNode[], width: number, gap: number): s
|
|
|
176
176
|
return blocks.flatMap((block, index) => [...blankRows(index === 0 ? 0 : gap), ...block])
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
function sideBySide(children: readonly RenderNode[], width: number, gap: number, isSpread
|
|
179
|
+
function sideBySide(children: readonly RenderNode[], width: number, gap: number, isSpread: boolean, alignItems: unknown): string[] {
|
|
180
180
|
const laid = children
|
|
181
181
|
.map((child) => ({ child, natural: rowsOf(child, Number.POSITIVE_INFINITY) }))
|
|
182
182
|
.filter(({ natural }) => natural.length > 0)
|
|
@@ -189,7 +189,19 @@ function sideBySide(children: readonly RenderNode[], width: number, gap: number,
|
|
|
189
189
|
const spaces = blocks.length - 1
|
|
190
190
|
const free = isSpread && Number.isFinite(width) ? Math.max(width - columns.reduce((sum, each) => sum + each, 0) - gap * spaces, 0) : 0
|
|
191
191
|
const gapAfter = (index: number) => gap + Math.floor(free / spaces) + (index < free % spaces ? 1 : 0)
|
|
192
|
-
|
|
192
|
+
const tops = laid.map(({ child }, index) => topOf(alignOf(child, alignItems), height - (blocks[index]?.length ?? 0)))
|
|
193
|
+
return Array.from({ length: height }, (_, row) => blocks.map((block, index) => `${paddedTo(block[row - (tops[index] ?? 0)] ?? '', index === spaces ? 0 : (columns[index] ?? 0))}${index === spaces ? '' : ' '.repeat(gapAfter(index))}`).join(''))
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function alignOf(node: RenderNode, alignItems: unknown): unknown {
|
|
197
|
+
const alignSelf = typeof node === 'string' ? undefined : insideOf(node).props['alignSelf']
|
|
198
|
+
return alignSelf === undefined || alignSelf === 'auto' ? alignItems : alignSelf
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function topOf(align: unknown, spare: number): number {
|
|
202
|
+
if (align === 'flex-end') return spare
|
|
203
|
+
if (align === 'center') return Math.floor(spare / 2)
|
|
204
|
+
return 0
|
|
193
205
|
}
|
|
194
206
|
|
|
195
207
|
function minWidthOf(node: RenderNode): number {
|
package/src/testing.ts
CHANGED
|
@@ -32,6 +32,7 @@ import { keepClaudeCode, type ClaudeCode } from './testing/claude-code.js'
|
|
|
32
32
|
import { createRouter } from './runtime/router.js'
|
|
33
33
|
import { toolInputOf } from './runtime/tool-calls.js'
|
|
34
34
|
import { createLifecycle } from './runtime/lifecycle.js'
|
|
35
|
+
import { serveCmodPlugin } from './register.js'
|
|
35
36
|
import { MissingOptions } from './runtime/options.js'
|
|
36
37
|
import { conversationMethods, pickedColor, type SessionColor } from './runtime/sessions.js'
|
|
37
38
|
import type { ShownToast } from './runtime/toaster.js'
|
|
@@ -282,7 +283,8 @@ export function testMod<State extends object, Declared extends Options = Options
|
|
|
282
283
|
}
|
|
283
284
|
const cmodClaude: Claude = { ...fake.claude, cmod: { call: async (input) => (input.to === name ? callMod(input.method, input.input) : fake.claude.cmod.call(input)) } }
|
|
284
285
|
const reportPart = (_id: string, message: string, error: unknown) => fake.claude.ui.log(`cmod: ${message}: ${messageOf(error)}`, { to: 'debug' })
|
|
285
|
-
const
|
|
286
|
+
const tellRefusedPress = (_mod: string, error: unknown) => fake.claude.ui.log(`cmod: ${name} did not take the press: ${messageOf(error)}`, { to: 'debug' })
|
|
287
|
+
const parts = drawnParts({ claude: cmodClaude, report: reportPart, press: (mod: string, input: PartPress) => void pressPart(input).catch((error: unknown) => tellRefusedPress(mod, error)) })
|
|
286
288
|
const servedWidgets = async (): Promise<Widgets> => {
|
|
287
289
|
const own = name === cmodPluginName && lifecycle.mod !== undefined ? engineOf(lifecycle.mod).widgets : undefined
|
|
288
290
|
if (own !== undefined) return own
|
|
@@ -298,7 +300,7 @@ export function testMod<State extends object, Declared extends Options = Options
|
|
|
298
300
|
}
|
|
299
301
|
const widgetsOf = () => (widgets ??= servedWidgets())
|
|
300
302
|
const cmodBeneath = createRouter()
|
|
301
|
-
const pages = servePages({ claude: cmodClaude, router: cmodBeneath, report: reportPart, widgets: { update: (mod, update) => void widgetsOf().then((served) => served.update(mod, update)) }, parts, tellStylers: () => undefined })
|
|
303
|
+
const pages = servePages({ claude: cmodClaude, router: cmodBeneath, report: reportPart, tellRefusedPress, widgets: { update: (mod, update) => void widgetsOf().then((served) => served.update(mod, update)) }, parts, tellStylers: () => undefined })
|
|
302
304
|
pages.apply((_mod, requests) => applyRequests(requests))
|
|
303
305
|
const dependencies = fakeDependencies(name, options.dependencies ?? {}, conversations)
|
|
304
306
|
fake.fakes.cmod.call = async (call) => {
|
|
@@ -366,7 +368,7 @@ export function testMod<State extends object, Declared extends Options = Options
|
|
|
366
368
|
const starting = options.state as Record<string, object> | undefined
|
|
367
369
|
const declared = Object.entries(definition.state ?? {}) as [string, object][]
|
|
368
370
|
const state = Object.fromEntries(declared.map(([lifetime, values]) => [lifetime, { ...values, ...starting?.[lifetime] }])) as State
|
|
369
|
-
const lifecycle = createLifecycle<State, Declared>({ ...definition, state }, () => permissionRoutes,(options.options ?? {}) as PluginOptions, false)
|
|
371
|
+
const lifecycle = createLifecycle<State, Declared>({ ...definition, state }, () => permissionRoutes, (options.options ?? {}) as PluginOptions, false, definition.name === cmodPluginName ? serveCmodPlugin : undefined)
|
|
370
372
|
let started: Promise<void> | undefined
|
|
371
373
|
let isColorTold = false
|
|
372
374
|
let deviceNoted: Promise<void> | undefined
|
|
@@ -425,6 +427,7 @@ export function testMod<State extends object, Declared extends Options = Options
|
|
|
425
427
|
place: async () => conversations.place(),
|
|
426
428
|
wants: async (event) => conversations.wants(name, event),
|
|
427
429
|
fold: decide,
|
|
430
|
+
failedBefore: () => undefined,
|
|
428
431
|
},
|
|
429
432
|
})
|
|
430
433
|
|
package/testing/fake-elements.js
CHANGED
|
@@ -139,7 +139,7 @@ function boxRows({ props, children = [] }, width) {
|
|
|
139
139
|
const ordered = direction.endsWith('-reverse') ? [...flowing].reverse() : flowing;
|
|
140
140
|
const outer = Math.min(width, size('width') ?? width);
|
|
141
141
|
const inner = outer - left - right - border * 2;
|
|
142
|
-
const rows = direction.startsWith('column') ? stacked(ordered, inner, size('rowGap') ?? size('gap') ?? 0) : sideBySide(ordered, inner, size('columnGap') ?? size('gap') ?? 0, props['justifyContent'] === 'space-between');
|
|
142
|
+
const rows = direction.startsWith('column') ? stacked(ordered, inner, size('rowGap') ?? size('gap') ?? 0) : sideBySide(ordered, inner, size('columnGap') ?? size('gap') ?? 0, props['justifyContent'] === 'space-between', props['alignItems']);
|
|
143
143
|
const content = border === 1 && Number.isFinite(inner) ? inner : right === 0 && border === 0 ? 0 : Math.max(widthOf(rows), (size('minWidth') ?? 0) - left - right - border * 2);
|
|
144
144
|
const padded = [...blankRows(space('Top', 'Y')), ...rows.map((row) => `${' '.repeat(left)}${paddedTo(row, content)}${' '.repeat(right)}`), ...blankRows(space('Bottom', 'Y'))];
|
|
145
145
|
const framed = border === 0 ? padded : framedRows(padded, left + content + right, props['borderStyle']);
|
|
@@ -176,7 +176,7 @@ function stacked(children, width, gap) {
|
|
|
176
176
|
const blocks = children.map((child) => rowsOf(child, width)).filter((block) => block.length > 0);
|
|
177
177
|
return blocks.flatMap((block, index) => [...blankRows(index === 0 ? 0 : gap), ...block]);
|
|
178
178
|
}
|
|
179
|
-
function sideBySide(children, width, gap, isSpread
|
|
179
|
+
function sideBySide(children, width, gap, isSpread, alignItems) {
|
|
180
180
|
const laid = children
|
|
181
181
|
.map((child) => ({ child, natural: rowsOf(child, Number.POSITIVE_INFINITY) }))
|
|
182
182
|
.filter(({ natural }) => natural.length > 0)
|
|
@@ -189,7 +189,19 @@ function sideBySide(children, width, gap, isSpread = false) {
|
|
|
189
189
|
const spaces = blocks.length - 1;
|
|
190
190
|
const free = isSpread && Number.isFinite(width) ? Math.max(width - columns.reduce((sum, each) => sum + each, 0) - gap * spaces, 0) : 0;
|
|
191
191
|
const gapAfter = (index) => gap + Math.floor(free / spaces) + (index < free % spaces ? 1 : 0);
|
|
192
|
-
|
|
192
|
+
const tops = laid.map(({ child }, index) => topOf(alignOf(child, alignItems), height - (blocks[index]?.length ?? 0)));
|
|
193
|
+
return Array.from({ length: height }, (_, row) => blocks.map((block, index) => `${paddedTo(block[row - (tops[index] ?? 0)] ?? '', index === spaces ? 0 : (columns[index] ?? 0))}${index === spaces ? '' : ' '.repeat(gapAfter(index))}`).join(''));
|
|
194
|
+
}
|
|
195
|
+
function alignOf(node, alignItems) {
|
|
196
|
+
const alignSelf = typeof node === 'string' ? undefined : insideOf(node).props['alignSelf'];
|
|
197
|
+
return alignSelf === undefined || alignSelf === 'auto' ? alignItems : alignSelf;
|
|
198
|
+
}
|
|
199
|
+
function topOf(align, spare) {
|
|
200
|
+
if (align === 'flex-end')
|
|
201
|
+
return spare;
|
|
202
|
+
if (align === 'center')
|
|
203
|
+
return Math.floor(spare / 2);
|
|
204
|
+
return 0;
|
|
193
205
|
}
|
|
194
206
|
function minWidthOf(node) {
|
|
195
207
|
if (typeof node === 'string')
|
package/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAEJ,gBAAgB,EAIhB,WAAW,EAUX,eAAe,EAGhB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAEJ,gBAAgB,EAIhB,WAAW,EAUX,eAAe,EAGhB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAczD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;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