@lijian-ui/dsh-term 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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/cordis.patch.yml +8 -0
  4. package/lib/client.js +7824 -0
  5. package/lib/client.js.map +1 -0
  6. package/lib/index.js +434 -0
  7. package/lib/tsconfig.client.tsbuildinfo +1 -0
  8. package/lib/tsconfig.host.tsbuildinfo +1 -0
  9. package/lib/types/client/index.d.ts +26 -0
  10. package/lib/types/client/index.d.ts.map +1 -0
  11. package/lib/types/client/term/TerminalPanel.d.ts +24 -0
  12. package/lib/types/client/term/TerminalPanel.d.ts.map +1 -0
  13. package/lib/types/client/term/api.d.ts +34 -0
  14. package/lib/types/client/term/api.d.ts.map +1 -0
  15. package/lib/types/client/term/xterm-styles.d.ts +9 -0
  16. package/lib/types/client/term/xterm-styles.d.ts.map +1 -0
  17. package/lib/types/core/types.d.ts +76 -0
  18. package/lib/types/core/types.d.ts.map +1 -0
  19. package/lib/types/host/loopback.d.ts +25 -0
  20. package/lib/types/host/loopback.d.ts.map +1 -0
  21. package/lib/types/host/pty-service.d.ts +45 -0
  22. package/lib/types/host/pty-service.d.ts.map +1 -0
  23. package/lib/types/host/routes.d.ts +17 -0
  24. package/lib/types/host/routes.d.ts.map +1 -0
  25. package/lib/types/index.d.ts +19 -0
  26. package/lib/types/index.d.ts.map +1 -0
  27. package/lib/types/mount-once.d.ts +25 -0
  28. package/lib/types/mount-once.d.ts.map +1 -0
  29. package/package.json +79 -0
  30. package/src/client/css-modules.d.ts +4 -0
  31. package/src/client/index.ts +223 -0
  32. package/src/client/term/TerminalPanel.tsx +259 -0
  33. package/src/client/term/api.ts +66 -0
  34. package/src/client/term/term.module.css +153 -0
  35. package/src/client/term/xterm-styles.ts +182 -0
  36. package/src/core/types.ts +73 -0
  37. package/src/host/loopback.ts +63 -0
  38. package/src/host/pty-service.ts +131 -0
  39. package/src/host/routes.ts +198 -0
  40. package/src/index.ts +37 -0
  41. package/src/mount-once.ts +48 -0
@@ -0,0 +1,48 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/host/mount-once.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * Host single-instance guard shared by the plugin family. The family bundle
4
+ * (dsh-web-ui-all / dsh-skins) namespaces every child row id (web-ui-*), so
5
+ * the loader accepts a standalone install of the same package side by side;
6
+ * without this guard the second instance would still re-register the same
7
+ * webserver routes, tools, settings namespaces, and system-prompt sections
8
+ * and fail the boot. mountOnce makes the second host apply a no-op for the
9
+ * lifetime of the first instance (the browser half is already deduped by
10
+ * package name in the client module host).
11
+ *
12
+ * The registry rides a global symbol so two module instances of the same
13
+ * package (npm copy vs repository link) still share one verdict. cordis
14
+ * `ctx.effect` runs its callback immediately and treats the callback's
15
+ * return value as the fiber disposer, so the unmarker is returned, not run.
16
+ */
17
+
18
+ const MOUNTED = Symbol.for('dsh-web-ui.mounted-plugins')
19
+
20
+ interface MountRegistry {
21
+ [MOUNTED]?: Set<string>
22
+ }
23
+
24
+ function mountedSet(): Set<string> {
25
+ const registry = globalThis as MountRegistry
26
+ return (registry[MOUNTED] ??= new Set())
27
+ }
28
+
29
+ /**
30
+ * Wrap a cordis plugin apply so the package runs at most once per process.
31
+ * The first mount registers normally and unmarks when its fiber disposes;
32
+ * any later mount of the same package name is a no-op.
33
+ * @param packageName - npm package identity shared by every install source.
34
+ * @param fn - the original plugin apply.
35
+ * @returns an apply of the same shape.
36
+ */
37
+ export function mountOnce<T extends (...args: any[]) => unknown>(packageName: string, fn: T): T {
38
+ return ((...args: unknown[]) => {
39
+ const mounted = mountedSet()
40
+ if (mounted.has(packageName)) return
41
+ mounted.add(packageName)
42
+ const ctx = args[0] as { effect?: (effect: () => unknown) => unknown } | undefined
43
+ ctx?.effect?.(() => () => {
44
+ mounted.delete(packageName)
45
+ })
46
+ return fn(...args)
47
+ }) as T
48
+ }