@arcanewizards/sigil 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.
Files changed (66) hide show
  1. package/dist/chunk-4PMRDURG.js +66 -0
  2. package/dist/chunk-5DRI7C4U.cjs +66 -0
  3. package/dist/chunk-A5LYYZER.cjs +103 -0
  4. package/dist/chunk-BIY5HAXP.js +125 -0
  5. package/dist/chunk-CAYKPJIX.cjs +10 -0
  6. package/dist/chunk-EJNNLQ2S.js +72 -0
  7. package/dist/chunk-FHXT3DAL.js +103 -0
  8. package/dist/chunk-H4U4Z4GM.js +66 -0
  9. package/dist/chunk-LSHKAVON.js +10 -0
  10. package/dist/chunk-MXDDIFIO.cjs +767 -0
  11. package/dist/chunk-PEARNJ5G.cjs +125 -0
  12. package/dist/chunk-RI33QVOD.cjs +66 -0
  13. package/dist/chunk-VZ4A6RRT.cjs +72 -0
  14. package/dist/chunk-XAK7WC3D.js +767 -0
  15. package/dist/frontend/appearance.cjs +88 -0
  16. package/dist/frontend/appearance.d.cts +11 -0
  17. package/dist/frontend/appearance.d.ts +11 -0
  18. package/dist/frontend/appearance.js +88 -0
  19. package/dist/frontend/context.cjs +16 -0
  20. package/dist/frontend/context.d.cts +32 -0
  21. package/dist/frontend/context.d.ts +32 -0
  22. package/dist/frontend/context.js +16 -0
  23. package/dist/frontend/controls/index.cjs +49 -0
  24. package/dist/frontend/controls/index.d.cts +168 -0
  25. package/dist/frontend/controls/index.d.ts +168 -0
  26. package/dist/frontend/controls/index.js +49 -0
  27. package/dist/frontend/dialogs.cjs +17 -0
  28. package/dist/frontend/dialogs.d.cts +36 -0
  29. package/dist/frontend/dialogs.d.ts +36 -0
  30. package/dist/frontend/dialogs.js +17 -0
  31. package/dist/frontend/input.cjs +8 -0
  32. package/dist/frontend/input.d.cts +33 -0
  33. package/dist/frontend/input.d.ts +33 -0
  34. package/dist/frontend/input.js +8 -0
  35. package/dist/frontend/preferences.cjs +54 -0
  36. package/dist/frontend/preferences.d.cts +14 -0
  37. package/dist/frontend/preferences.d.ts +14 -0
  38. package/dist/frontend/preferences.js +54 -0
  39. package/dist/frontend/styles/base.css +321 -0
  40. package/dist/frontend/styles/sigil.css +785 -0
  41. package/dist/frontend/styles/theme.css +625 -0
  42. package/dist/frontend/styling.cjs +18 -0
  43. package/dist/frontend/styling.d.cts +32 -0
  44. package/dist/frontend/styling.d.ts +32 -0
  45. package/dist/frontend/styling.js +18 -0
  46. package/dist/frontend/toolbars.cjs +18 -0
  47. package/dist/frontend/toolbars.d.cts +11 -0
  48. package/dist/frontend/toolbars.d.ts +11 -0
  49. package/dist/frontend/toolbars.js +18 -0
  50. package/dist/frontend/tooltip.cjs +10 -0
  51. package/dist/frontend/tooltip.d.cts +16 -0
  52. package/dist/frontend/tooltip.d.ts +16 -0
  53. package/dist/frontend/tooltip.js +10 -0
  54. package/dist/frontend.cjs +359 -0
  55. package/dist/frontend.d.cts +90 -0
  56. package/dist/frontend.d.ts +90 -0
  57. package/dist/frontend.js +359 -0
  58. package/dist/index.cjs +492 -0
  59. package/dist/index.d.cts +134 -0
  60. package/dist/index.d.ts +134 -0
  61. package/dist/index.js +492 -0
  62. package/dist/proto-B-WcMUOE.d.cts +33 -0
  63. package/dist/proto-kGDF-yWB.d.ts +33 -0
  64. package/dist/types-X8O95zmC.d.cts +23 -0
  65. package/dist/types-X8O95zmC.d.ts +23 -0
  66. package/package.json +123 -0
@@ -0,0 +1,90 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { S as SigilAppRootComponent } from './proto-kGDF-yWB.js';
3
+ export { A as AppRootGetLogs, a as AppRootGetLogsArgs, b as AppRootGetLogsReturn, c as SIGIL_NAMESPACE, d as SigilComponent, e as SigilComponentCalls, i as isSigilComponent, f as isSigilComponentCall } from './proto-kGDF-yWB.js';
4
+ import * as react from 'react';
5
+ import { PropsWithChildren, FC, ReactNode } from 'react';
6
+ import { FrontendComponentRenderer } from '@arcanejs/toolkit-frontend/types';
7
+ export { DebuggerContext, SystemInformationContext, useDebuggerContext, useSystemInformation } from './frontend/context.js';
8
+ export { A as AppRootLogEntry, a as AppRootLogEntryStackFrame, S as SystemInformation } from './types-X8O95zmC.js';
9
+ import '@arcanejs/protocol';
10
+ import '@arcanejs/diff';
11
+
12
+ type MediaSessionAction = {
13
+ action: 'play' | 'pause' | 'playpause';
14
+ } | {
15
+ action: 'seekto';
16
+ seekTimeMillis: number;
17
+ } | {
18
+ action: 'seekbackward' | 'seekforward';
19
+ seekOffsetMillis?: number;
20
+ };
21
+ type MediaSessionHandler = (action: MediaSessionAction) => void;
22
+ type MediaPlayState = {
23
+ state: 'playing';
24
+ effectiveStartTime: number;
25
+ speed: number;
26
+ } | {
27
+ state: 'stopped';
28
+ speed: number;
29
+ currentTimeMillis: number;
30
+ };
31
+ type MediaMetadata = {
32
+ title?: string;
33
+ artist?: string;
34
+ durationMillis: number;
35
+ state: MediaPlayState;
36
+ };
37
+ type MediaSessionControl = {
38
+ setMetaData: (metadata: MediaMetadata | null) => void;
39
+ setHandler: (handler: MediaSessionHandler | null) => void;
40
+ };
41
+ type NewWindowOptions = {
42
+ /**
43
+ * If true, try and find an existing window with the same URL,
44
+ * and just bring it into focus instead of opening a new one.
45
+ */
46
+ canUseExisting?: boolean;
47
+ /**
48
+ * If supported by the the electron environment,
49
+ * specify a string mode identifier to configure the window behavior.
50
+ */
51
+ mode?: string;
52
+ };
53
+ type BaseBrowserContext = {
54
+ openExternalLink: (url: string) => void;
55
+ openNewWidow: (url: string, options?: NewWindowOptions) => void;
56
+ selectDirectory: (() => Promise<string | null>) | null;
57
+ openDevTools: (() => Promise<null>) | null;
58
+ confirmClose: (message: string) => void;
59
+ mediaSession: MediaSessionControl;
60
+ };
61
+ declare const createDefaultBrowserContext: <TBrowserContext extends BaseBrowserContext = BaseBrowserContext>(browser?: Partial<TBrowserContext> | null) => TBrowserContext;
62
+ declare const BrowserContext: react.Context<BaseBrowserContext>;
63
+ declare const BrowserContextProvider: <TBrowserContext extends BaseBrowserContext>({ browser, children, }: PropsWithChildren<{
64
+ browser: TBrowserContext;
65
+ }>) => react_jsx_runtime.JSX.Element;
66
+ declare const useBrowserContext: <TBrowserContext extends BaseBrowserContext = BaseBrowserContext>() => TBrowserContext;
67
+
68
+ type Props<TBrowserContext extends BaseBrowserContext> = {
69
+ info: SigilAppRootComponent;
70
+ browser: TBrowserContext;
71
+ };
72
+ declare const AppRoot: <TBrowserContext extends BaseBrowserContext>({ info, browser, }: Props<TBrowserContext>) => react_jsx_runtime.JSX.Element;
73
+
74
+ type DebuggerProps = {
75
+ title: ReactNode;
76
+ className?: string;
77
+ };
78
+ declare const Debugger: FC<DebuggerProps>;
79
+
80
+ declare const createSigilFrontendRenderer: <TBrowserContext extends BaseBrowserContext>(browser: TBrowserContext) => FrontendComponentRenderer;
81
+ type StartSigilFrontendOptions<TBrowserContext extends BaseBrowserContext> = {
82
+ browser?: Partial<TBrowserContext> | null;
83
+ appRenderers: FrontendComponentRenderer[];
84
+ loadingState?: () => ReactNode;
85
+ };
86
+ declare const startSigilFrontend: <TBrowserContext extends BaseBrowserContext>({ browser, appRenderers, loadingState, }: StartSigilFrontendOptions<TBrowserContext>) => TBrowserContext;
87
+
88
+ declare const createBrowserMediaSession: () => MediaSessionControl;
89
+
90
+ export { type BaseBrowserContext, BrowserContext, BrowserContextProvider, Debugger, type MediaMetadata, type MediaPlayState, type MediaSessionAction, type MediaSessionControl, type MediaSessionHandler, type NewWindowOptions, AppRoot as SigilAppRoot, SigilAppRootComponent, type StartSigilFrontendOptions, createBrowserMediaSession, createDefaultBrowserContext, createSigilFrontendRenderer, startSigilFrontend, useBrowserContext };
@@ -0,0 +1,359 @@
1
+ import {
2
+ ToolbarDivider,
3
+ ToolbarRow,
4
+ ToolbarWrapper
5
+ } from "./chunk-FHXT3DAL.js";
6
+ import {
7
+ SIGIL_NAMESPACE,
8
+ isSigilComponent,
9
+ isSigilComponentCall
10
+ } from "./chunk-LSHKAVON.js";
11
+ import {
12
+ DebuggerContext,
13
+ SystemInformationContext,
14
+ useDebuggerContext,
15
+ useSystemInformation
16
+ } from "./chunk-EJNNLQ2S.js";
17
+ import {
18
+ ControlButton
19
+ } from "./chunk-XAK7WC3D.js";
20
+ import "./chunk-BIY5HAXP.js";
21
+ import "./chunk-4PMRDURG.js";
22
+ import {
23
+ cnd
24
+ } from "./chunk-H4U4Z4GM.js";
25
+
26
+ // src/frontend/app-root.tsx
27
+ import { StageContext } from "@arcanejs/toolkit-frontend";
28
+ import { Tooltip } from "radix-ui";
29
+ import { useContext as useContext2, useEffect, useMemo, useState } from "react";
30
+
31
+ // src/frontend/browser-context.tsx
32
+ import { createContext, useContext } from "react";
33
+
34
+ // src/frontend/media-session.ts
35
+ var NOOP_MEDIA_SESSION = {
36
+ setMetaData: () => {
37
+ },
38
+ setHandler: () => {
39
+ }
40
+ };
41
+ var createBrowserMediaSession = () => {
42
+ if (typeof navigator === "undefined" || !("mediaSession" in navigator) || !navigator.mediaSession) {
43
+ return NOOP_MEDIA_SESSION;
44
+ }
45
+ let handler = null;
46
+ const setMetaData = (data) => {
47
+ if (!data) {
48
+ navigator.mediaSession.metadata = null;
49
+ navigator.mediaSession.playbackState = "none";
50
+ return;
51
+ }
52
+ const { title, artist, durationMillis, state } = data;
53
+ navigator.mediaSession.metadata = new MediaMetadata({
54
+ title,
55
+ artist
56
+ });
57
+ if (state.state === "playing") {
58
+ navigator.mediaSession.playbackState = "playing";
59
+ navigator.mediaSession.setPositionState({
60
+ duration: durationMillis / 1e3,
61
+ position: Math.max(0, (Date.now() - state.effectiveStartTime) * state.speed) / 1e3,
62
+ playbackRate: state.speed
63
+ });
64
+ return;
65
+ }
66
+ navigator.mediaSession.playbackState = "paused";
67
+ navigator.mediaSession.setPositionState({
68
+ duration: durationMillis / 1e3,
69
+ position: state.currentTimeMillis / 1e3
70
+ });
71
+ };
72
+ const setHandler = (value) => {
73
+ handler = value;
74
+ };
75
+ navigator.mediaSession.setActionHandler("play", () => {
76
+ handler?.({ action: "play" });
77
+ });
78
+ navigator.mediaSession.setActionHandler("pause", () => {
79
+ handler?.({ action: "pause" });
80
+ });
81
+ const handleSeekAction = (action) => {
82
+ if (action.action === "seekto") {
83
+ handler?.({
84
+ action: "seekto",
85
+ seekTimeMillis: (action.seekTime ?? 0) * 1e3
86
+ });
87
+ return;
88
+ }
89
+ if (action.action === "seekbackward" || action.action === "seekforward") {
90
+ handler?.({
91
+ action: action.action,
92
+ seekOffsetMillis: (action.seekOffset ?? 0) * 1e3
93
+ });
94
+ }
95
+ };
96
+ navigator.mediaSession.setActionHandler("seekto", handleSeekAction);
97
+ navigator.mediaSession.setActionHandler("seekbackward", handleSeekAction);
98
+ navigator.mediaSession.setActionHandler("seekforward", handleSeekAction);
99
+ return {
100
+ setMetaData,
101
+ setHandler
102
+ };
103
+ };
104
+
105
+ // src/frontend/browser-context.tsx
106
+ import { jsx } from "react/jsx-runtime";
107
+ var createDefaultBrowserContext = (browser) => {
108
+ const defaults = {
109
+ openExternalLink: (url) => {
110
+ window.open(url, "_blank", "noopener,noreferrer");
111
+ },
112
+ openNewWidow: (url) => {
113
+ window.open(url, "_blank", "noopener,noreferrer");
114
+ },
115
+ selectDirectory: null,
116
+ openDevTools: null,
117
+ confirmClose: () => {
118
+ },
119
+ mediaSession: createBrowserMediaSession()
120
+ };
121
+ return {
122
+ ...defaults,
123
+ ...browser
124
+ };
125
+ };
126
+ var BrowserContext = createContext(
127
+ new Proxy({}, {
128
+ get: () => {
129
+ throw new Error("BrowserContext not provided.");
130
+ }
131
+ })
132
+ );
133
+ var BrowserContextProvider = ({
134
+ browser,
135
+ children
136
+ }) => {
137
+ return /* @__PURE__ */ jsx(BrowserContext.Provider, { value: browser, children });
138
+ };
139
+ var useBrowserContext = () => useContext(BrowserContext);
140
+
141
+ // src/frontend/app-root.tsx
142
+ import { jsx as jsx2 } from "react/jsx-runtime";
143
+ var AppRoot = ({
144
+ info,
145
+ browser
146
+ }) => {
147
+ const { child, lastLog } = info;
148
+ const { renderComponent, call } = useContext2(StageContext);
149
+ const [logs, setLogs] = useState({ lastLog: -1, logs: [] });
150
+ const [debugMode, setDebugMode] = useState(false);
151
+ useEffect(() => {
152
+ if (!debugMode || !call) return;
153
+ const lastLogId = logs.logs[logs.logs.length - 1]?.index ?? -1;
154
+ call({
155
+ namespace: "sigil",
156
+ type: "component-call",
157
+ componentKey: info.key,
158
+ action: "app-root-get-logs",
159
+ after: lastLogId
160
+ }).then(({ logs: newLogs }) => {
161
+ if (newLogs.length === 0) return;
162
+ setLogs({
163
+ lastLog,
164
+ logs: [...logs.logs, ...newLogs]
165
+ });
166
+ });
167
+ }, [call, debugMode, info.key, lastLog, logs]);
168
+ const debuggerContext = useMemo(
169
+ () => ({
170
+ logs: logs.logs,
171
+ setDebugMode
172
+ }),
173
+ [logs.logs]
174
+ );
175
+ return /* @__PURE__ */ jsx2(SystemInformationContext.Provider, { value: info.system, children: /* @__PURE__ */ jsx2(BrowserContextProvider, { browser, children: /* @__PURE__ */ jsx2(DebuggerContext.Provider, { value: debuggerContext, children: /* @__PURE__ */ jsx2(Tooltip.Provider, { children: child && renderComponent(child) }) }) }) });
176
+ };
177
+
178
+ // src/frontend/debugger.tsx
179
+ import { useCallback, useEffect as useEffect2, useRef } from "react";
180
+ import { cn } from "@arcanejs/toolkit-frontend/util";
181
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
182
+ var TIME_FORMATTER = new Intl.DateTimeFormat("en-US", {
183
+ hour: "2-digit",
184
+ minute: "2-digit",
185
+ second: "2-digit",
186
+ fractionalSecondDigits: 3
187
+ });
188
+ var unwrapErrorStack = (error) => {
189
+ let stack = `${error.message}
190
+ ${error.stack ?? ""}`;
191
+ if (error.cause) {
192
+ stack += `
193
+ Caused by: ${unwrapErrorStack(error.cause)}`;
194
+ }
195
+ return stack;
196
+ };
197
+ var Debugger = ({ title, className }) => {
198
+ const scrollRef = useRef(null);
199
+ const shouldScrollToBottom = useRef(true);
200
+ const { openDevTools } = useBrowserContext();
201
+ const { setDebugMode, logs } = useDebuggerContext();
202
+ const system = useSystemInformation();
203
+ useEffect2(() => {
204
+ setDebugMode(true);
205
+ return () => {
206
+ setDebugMode(false);
207
+ };
208
+ }, [setDebugMode]);
209
+ const handleScroll = () => {
210
+ if (!scrollRef.current) return;
211
+ const { scrollTop, scrollHeight, clientHeight } = scrollRef.current;
212
+ shouldScrollToBottom.current = scrollTop + clientHeight >= scrollHeight - 10;
213
+ };
214
+ const scrollToBottomIfRequired = useCallback(() => {
215
+ if (shouldScrollToBottom.current && scrollRef.current) {
216
+ scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
217
+ }
218
+ }, []);
219
+ useEffect2(scrollToBottomIfRequired, [logs, scrollToBottomIfRequired]);
220
+ useEffect2(() => {
221
+ window.addEventListener("resize", scrollToBottomIfRequired);
222
+ return () => {
223
+ window.removeEventListener("resize", scrollToBottomIfRequired);
224
+ };
225
+ }, [scrollToBottomIfRequired]);
226
+ const exportLogs = useCallback(() => {
227
+ const logText = JSON.stringify({ system, logs }, null, 2);
228
+ const blob = new Blob([logText], { type: "application/json" });
229
+ const url = URL.createObjectURL(blob);
230
+ const link = document.createElement("a");
231
+ link.href = url;
232
+ link.download = `sigil-logs-${(/* @__PURE__ */ new Date()).toISOString()}.json`;
233
+ link.click();
234
+ URL.revokeObjectURL(url);
235
+ }, [system, logs]);
236
+ const handleRequestScrollToBottom = useCallback(() => {
237
+ shouldScrollToBottom.current = true;
238
+ scrollToBottomIfRequired();
239
+ }, [scrollToBottomIfRequired]);
240
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", className), children: [
241
+ /* @__PURE__ */ jsx3(ToolbarWrapper, { children: /* @__PURE__ */ jsxs(ToolbarRow, { children: [
242
+ /* @__PURE__ */ jsx3("span", { className: "grow px-1", children: title }),
243
+ /* @__PURE__ */ jsx3(ToolbarDivider, {}),
244
+ openDevTools && /* @__PURE__ */ jsx3(
245
+ ControlButton,
246
+ {
247
+ onClick: openDevTools,
248
+ variant: "toolbar",
249
+ icon: "build",
250
+ children: "Open Dev Tools"
251
+ }
252
+ ),
253
+ /* @__PURE__ */ jsx3(
254
+ ControlButton,
255
+ {
256
+ onClick: handleRequestScrollToBottom,
257
+ variant: "toolbar",
258
+ icon: "south",
259
+ children: "Scroll to Bottom"
260
+ }
261
+ ),
262
+ /* @__PURE__ */ jsx3(ControlButton, { onClick: exportLogs, variant: "toolbar", icon: "publish", children: "Export Logs" })
263
+ ] }) }),
264
+ /* @__PURE__ */ jsx3(
265
+ "pre",
266
+ {
267
+ className: "\n m-0 overflow-x-auto border-b border-sigil-border bg-sigil-bg-dark p-2\n scrollbar-sigil\n ",
268
+ children: `OS: ${system.os}
269
+ Version: ${system.version}
270
+ App Path: ${system.appPath}
271
+ CWD: ${system.cwd}
272
+ Data Directory: ${system.dataDirectory}`
273
+ }
274
+ ),
275
+ /* @__PURE__ */ jsx3(
276
+ "div",
277
+ {
278
+ ref: scrollRef,
279
+ onScroll: handleScroll,
280
+ className: "flex-1 overflow-auto scrollbar-sigil",
281
+ children: logs.map((log) => /* @__PURE__ */ jsxs("div", { className: "px-arcane whitespace-pre-wrap", children: [
282
+ /* @__PURE__ */ jsxs("p", { children: [
283
+ TIME_FORMATTER.format(log.timestamp),
284
+ " - ",
285
+ /* @__PURE__ */ jsx3(
286
+ "span",
287
+ {
288
+ className: cn(
289
+ cnd(log.level === "error", "text-sigil-usage-red-foreground"),
290
+ cnd(
291
+ log.level === "warn",
292
+ "text-sigil-usage-yellow-foreground"
293
+ ),
294
+ cnd(log.level === "info", "text-sigil-usage-blue-foreground")
295
+ ),
296
+ children: log.level
297
+ }
298
+ ),
299
+ " - ",
300
+ log.message
301
+ ] }),
302
+ log.stack && /* @__PURE__ */ jsx3("pre", { className: "m-0 ml-2", children: unwrapErrorStack(log.stack) })
303
+ ] }, log.index))
304
+ }
305
+ )
306
+ ] });
307
+ };
308
+
309
+ // src/frontend/index.tsx
310
+ import { startArcaneFrontend } from "@arcanejs/toolkit/frontend";
311
+ import { CORE_FRONTEND_COMPONENT_RENDERER } from "@arcanejs/toolkit-frontend";
312
+ import { jsx as jsx4 } from "react/jsx-runtime";
313
+ var createSigilFrontendRenderer = (browser) => ({
314
+ namespace: SIGIL_NAMESPACE,
315
+ render: (info) => {
316
+ if (!isSigilComponent(info)) {
317
+ throw new Error(`Cannot render component ${info.namespace}`);
318
+ }
319
+ switch (info.component) {
320
+ case "app-root":
321
+ return /* @__PURE__ */ jsx4(AppRoot, { browser, info });
322
+ }
323
+ }
324
+ });
325
+ var defaultLoadingState = () => /* @__PURE__ */ jsx4("div", { style: { width: "100%", textAlign: "center", padding: "2rem" }, children: "Loading..." });
326
+ var startSigilFrontend = ({
327
+ browser,
328
+ appRenderers,
329
+ loadingState = defaultLoadingState
330
+ }) => {
331
+ const resolvedBrowser = createDefaultBrowserContext(browser);
332
+ startArcaneFrontend({
333
+ renderers: [
334
+ CORE_FRONTEND_COMPONENT_RENDERER,
335
+ createSigilFrontendRenderer(resolvedBrowser),
336
+ ...appRenderers
337
+ ],
338
+ loadingState
339
+ });
340
+ return resolvedBrowser;
341
+ };
342
+ export {
343
+ BrowserContext,
344
+ BrowserContextProvider,
345
+ Debugger,
346
+ DebuggerContext,
347
+ SIGIL_NAMESPACE,
348
+ AppRoot as SigilAppRoot,
349
+ SystemInformationContext,
350
+ createBrowserMediaSession,
351
+ createDefaultBrowserContext,
352
+ createSigilFrontendRenderer,
353
+ isSigilComponent,
354
+ isSigilComponentCall,
355
+ startSigilFrontend,
356
+ useBrowserContext,
357
+ useDebuggerContext,
358
+ useSystemInformation
359
+ };