@selfhelp/shared 1.2.5 → 1.3.1

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 (64) hide show
  1. package/CHANGELOG.md +341 -326
  2. package/LICENSE +381 -381
  3. package/README.md +57 -57
  4. package/dist/index.d.mts +25 -1
  5. package/dist/index.d.ts +25 -1
  6. package/dist/index.js +2 -0
  7. package/dist/index.mjs +2 -0
  8. package/package.json +102 -102
  9. package/src/api/__tests__/endpoints.test.ts +45 -0
  10. package/src/api/endpoints.ts +2 -0
  11. package/src/api/index.ts +5 -5
  12. package/src/assets/__tests__/resolveAssetUrl.test.ts +61 -61
  13. package/src/assets/index.ts +5 -5
  14. package/src/assets/resolveAssetUrl.ts +44 -44
  15. package/src/cms-classes/__tests__/classify.test.ts +63 -63
  16. package/src/cms-classes/allow-list.ts +158 -158
  17. package/src/cms-classes/classify.ts +90 -90
  18. package/src/cms-classes/index.ts +7 -7
  19. package/src/cms-classes/remap.ts +44 -44
  20. package/src/condition/__tests__/evaluate.test.ts +54 -54
  21. package/src/condition/evaluate.ts +121 -121
  22. package/src/condition/index.ts +5 -5
  23. package/src/index.ts +25 -25
  24. package/src/interpolation/__tests__/replaceCalcedValues.test.ts +41 -41
  25. package/src/interpolation/index.ts +5 -5
  26. package/src/interpolation/replaceCalcedValues.ts +27 -27
  27. package/src/plugin-sdk/define.ts +89 -89
  28. package/src/plugin-sdk/index.ts +103 -103
  29. package/src/plugin-sdk/lock.ts +124 -124
  30. package/src/plugin-sdk/manifest.ts +307 -307
  31. package/src/plugin-sdk/realtime.ts +277 -277
  32. package/src/plugin-sdk/registry.ts +105 -105
  33. package/src/plugin-sdk/runtime-shim.ts +140 -140
  34. package/src/plugin-sdk/types.ts +315 -315
  35. package/src/plugin-sdk/version.ts +209 -209
  36. package/src/registry/__tests__/registry.test.ts +135 -135
  37. package/src/registry/index.ts +94 -94
  38. package/src/registry/styles.registry.ts +295 -295
  39. package/src/testing/__tests__/testing-kit.test.ts +228 -228
  40. package/src/testing/index.ts +483 -483
  41. package/src/theme/index.ts +6 -6
  42. package/src/theme/tailwind.ts +73 -73
  43. package/src/theme/tokens.ts +177 -177
  44. package/src/types/api/auth.ts +22 -0
  45. package/src/types/api/envelope.ts +34 -34
  46. package/src/types/api/forms.ts +76 -76
  47. package/src/types/api/index.ts +9 -9
  48. package/src/types/api/language.ts +12 -12
  49. package/src/types/api/page.ts +9 -9
  50. package/src/types/index.ts +17 -17
  51. package/src/types/mantine/common.ts +142 -142
  52. package/src/types/pages.ts +107 -107
  53. package/src/types/styles/auth.ts +184 -184
  54. package/src/types/styles/base.ts +72 -72
  55. package/src/types/styles/composite.ts +131 -131
  56. package/src/types/styles/forms.ts +439 -439
  57. package/src/types/styles/interactive.ts +165 -165
  58. package/src/types/styles/layout.ts +184 -184
  59. package/src/types/styles/media.ts +68 -68
  60. package/src/types/styles/typography.ts +118 -118
  61. package/src/types/styles/unknown.ts +220 -220
  62. package/src/utils/__tests__/transformPageData.test.ts +69 -69
  63. package/src/utils/spacing.ts +64 -64
  64. package/src/utils/transformPageData.ts +99 -99
@@ -1,105 +1,105 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- /**
6
- * TypeScript mirror of `registry.json` served by a plugin registry.
7
- * The host installer fetches registries (public and private), merges
8
- * per-channel metadata, and shows update availability + changelogs in
9
- * the admin UI.
10
- */
11
-
12
- export type TPluginRegistryChannel = 'stable' | 'beta' | 'alpha' | 'nightly';
13
-
14
- export interface IPluginRegistryVersionEntry {
15
- /** SemVer version. */
16
- version: string;
17
- /** Channel this version was published to. */
18
- channel: TPluginRegistryChannel;
19
- /** ISO datetime the version was published. */
20
- publishedAt: string;
21
- /** Whether this version is a breaking change vs the previous one. */
22
- breaking?: boolean;
23
- /** Whether the host installer should block this version. */
24
- blocked?: boolean;
25
- /** Optional reason for `blocked: true`. */
26
- blockedReason?: string;
27
- /** Composer / npm tarball or git source URL. */
28
- sources: {
29
- backend?: { type: 'composer' | 'git'; package?: string; ref?: string; url?: string };
30
- frontend?: { type: 'npm' | 'git'; package?: string; url?: string };
31
- mobile?: { type: 'npm' | 'git'; package?: string; url?: string };
32
- };
33
- /** SHA-256 checksum of the published artifact. */
34
- checksumSha256: string;
35
- /** Optional Ed25519 signature, base64. */
36
- signatureEd25519?: string;
37
- /** Compatibility metadata mirrored from the manifest. */
38
- compatibility: {
39
- selfhelp: string;
40
- php?: string;
41
- node?: string;
42
- react?: string;
43
- reactNative?: string;
44
- expoSdk?: string;
45
- pluginApiVersion: string;
46
- };
47
- /** Plain-text changelog. Markdown supported. */
48
- changelog?: string;
49
- /** Mirror of `dependencies` from the manifest, for resolver-only consumption. */
50
- dependencies?: { pluginId: string; version: string; required: boolean }[];
51
- }
52
-
53
- export interface IPluginRegistryEntry {
54
- /** Plugin id (e.g. `sh2-shp-survey-js`). */
55
- id: string;
56
- /** Display name. */
57
- name: string;
58
- /** Short description. */
59
- description?: string;
60
- /** Homepage / repo URL. */
61
- homepage?: string;
62
- /** Trust level published by the registry. */
63
- trustLevel: 'official' | 'reviewed' | 'untrusted';
64
- /** Available versions. */
65
- versions: IPluginRegistryVersionEntry[];
66
- /** Optional public icon URL. */
67
- iconUrl?: string;
68
- /** Optional categories. */
69
- categories?: string[];
70
- }
71
-
72
- /**
73
- * Registry root document.
74
- *
75
- * Mirrors `plugin-registry.schema.json` in the host repository. The
76
- * canonical schema requires `schemaVersion` (a string enum, currently
77
- * `'1.0'`) and `plugins`. The publisher/base-url metadata is optional
78
- * but always emitted by `scripts/publish-to-registry.mjs`.
79
- */
80
- export interface IPluginRegistry {
81
- /** Canonical registry schema version. Currently fixed at `'1.0'`. */
82
- schemaVersion: '1.0';
83
- /** ISO timestamp this registry was published. */
84
- publishedAt?: string;
85
- /**
86
- * Public base URL where this registry is served (with trailing
87
- * slash). Plugin publishers join this to relative
88
- * `artifacts/<id>-<version>/...` paths to produce the absolute
89
- * `runtime.entrypointUrl` / `runtime.stylesheetUrl` that gets
90
- * signed and shipped in each plugin entry.
91
- */
92
- baseUrl?: string;
93
- /** Publisher metadata shown in the admin UI. */
94
- publisher?: { name: string; url?: string };
95
- /** Optional registry display name (legacy helper, not in canonical schema). */
96
- name?: string;
97
- /** Registry homepage / maintainer URL (legacy helper, not in canonical schema). */
98
- homepage?: string;
99
- /** Public key used to verify per-version signatures (legacy helper, not in canonical schema). */
100
- trustKey?: { algo: 'ed25519'; publicKeyId: string; publicKey: string };
101
- /** Channels this registry exposes (legacy helper, not in canonical schema). */
102
- channels?: TPluginRegistryChannel[];
103
- /** Listed plugins. */
104
- plugins: IPluginRegistryEntry[];
105
- }
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * TypeScript mirror of `registry.json` served by a plugin registry.
7
+ * The host installer fetches registries (public and private), merges
8
+ * per-channel metadata, and shows update availability + changelogs in
9
+ * the admin UI.
10
+ */
11
+
12
+ export type TPluginRegistryChannel = 'stable' | 'beta' | 'alpha' | 'nightly';
13
+
14
+ export interface IPluginRegistryVersionEntry {
15
+ /** SemVer version. */
16
+ version: string;
17
+ /** Channel this version was published to. */
18
+ channel: TPluginRegistryChannel;
19
+ /** ISO datetime the version was published. */
20
+ publishedAt: string;
21
+ /** Whether this version is a breaking change vs the previous one. */
22
+ breaking?: boolean;
23
+ /** Whether the host installer should block this version. */
24
+ blocked?: boolean;
25
+ /** Optional reason for `blocked: true`. */
26
+ blockedReason?: string;
27
+ /** Composer / npm tarball or git source URL. */
28
+ sources: {
29
+ backend?: { type: 'composer' | 'git'; package?: string; ref?: string; url?: string };
30
+ frontend?: { type: 'npm' | 'git'; package?: string; url?: string };
31
+ mobile?: { type: 'npm' | 'git'; package?: string; url?: string };
32
+ };
33
+ /** SHA-256 checksum of the published artifact. */
34
+ checksumSha256: string;
35
+ /** Optional Ed25519 signature, base64. */
36
+ signatureEd25519?: string;
37
+ /** Compatibility metadata mirrored from the manifest. */
38
+ compatibility: {
39
+ selfhelp: string;
40
+ php?: string;
41
+ node?: string;
42
+ react?: string;
43
+ reactNative?: string;
44
+ expoSdk?: string;
45
+ pluginApiVersion: string;
46
+ };
47
+ /** Plain-text changelog. Markdown supported. */
48
+ changelog?: string;
49
+ /** Mirror of `dependencies` from the manifest, for resolver-only consumption. */
50
+ dependencies?: { pluginId: string; version: string; required: boolean }[];
51
+ }
52
+
53
+ export interface IPluginRegistryEntry {
54
+ /** Plugin id (e.g. `sh2-shp-survey-js`). */
55
+ id: string;
56
+ /** Display name. */
57
+ name: string;
58
+ /** Short description. */
59
+ description?: string;
60
+ /** Homepage / repo URL. */
61
+ homepage?: string;
62
+ /** Trust level published by the registry. */
63
+ trustLevel: 'official' | 'reviewed' | 'untrusted';
64
+ /** Available versions. */
65
+ versions: IPluginRegistryVersionEntry[];
66
+ /** Optional public icon URL. */
67
+ iconUrl?: string;
68
+ /** Optional categories. */
69
+ categories?: string[];
70
+ }
71
+
72
+ /**
73
+ * Registry root document.
74
+ *
75
+ * Mirrors `plugin-registry.schema.json` in the host repository. The
76
+ * canonical schema requires `schemaVersion` (a string enum, currently
77
+ * `'1.0'`) and `plugins`. The publisher/base-url metadata is optional
78
+ * but always emitted by `scripts/publish-to-registry.mjs`.
79
+ */
80
+ export interface IPluginRegistry {
81
+ /** Canonical registry schema version. Currently fixed at `'1.0'`. */
82
+ schemaVersion: '1.0';
83
+ /** ISO timestamp this registry was published. */
84
+ publishedAt?: string;
85
+ /**
86
+ * Public base URL where this registry is served (with trailing
87
+ * slash). Plugin publishers join this to relative
88
+ * `artifacts/<id>-<version>/...` paths to produce the absolute
89
+ * `runtime.entrypointUrl` / `runtime.stylesheetUrl` that gets
90
+ * signed and shipped in each plugin entry.
91
+ */
92
+ baseUrl?: string;
93
+ /** Publisher metadata shown in the admin UI. */
94
+ publisher?: { name: string; url?: string };
95
+ /** Optional registry display name (legacy helper, not in canonical schema). */
96
+ name?: string;
97
+ /** Registry homepage / maintainer URL (legacy helper, not in canonical schema). */
98
+ homepage?: string;
99
+ /** Public key used to verify per-version signatures (legacy helper, not in canonical schema). */
100
+ trustKey?: { algo: 'ed25519'; publicKeyId: string; publicKey: string };
101
+ /** Channels this registry exposes (legacy helper, not in canonical schema). */
102
+ channels?: TPluginRegistryChannel[];
103
+ /** Listed plugins. */
104
+ plugins: IPluginRegistryEntry[];
105
+ }
@@ -1,140 +1,140 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- /**
6
- * Plugin runtime-shim contract.
7
- *
8
- * Plugins ship as native ESM bundles that import bare specifiers like
9
- * `react`, `@mantine/core`, `@tanstack/react-query`, and
10
- * `@selfhelp/shared/plugin-sdk`. The browser cannot resolve those
11
- * without help, and the host explicitly does NOT want each plugin to
12
- * bundle its own copy of those packages — a duplicate React breaks
13
- * hooks, a duplicate `@tanstack/react-query` shadows the host's
14
- * `QueryClient`, a duplicate `STYLE_REGISTRY` desynchronises the
15
- * style dispatcher.
16
- *
17
- * Resolution strategy is a single contract shared across:
18
- *
19
- * 1. The host frontend (`sh-selfhelp_frontend`) which:
20
- * - renders `<script type="importmap">` with the entries from
21
- * {@link PLUGIN_RUNTIME_IMPORT_MAP},
22
- * - serves a tiny per-module shim at
23
- * {@link PLUGIN_RUNTIME_SHIM_BASE_PATH}`<specifier>`,
24
- * - populates {@link PLUGIN_RUNTIME_GLOBAL_KEY} on `globalThis`
25
- * with the singleton module objects the host already loaded.
26
- * 2. Every plugin's frontend Vite build, which externalises the
27
- * same specifiers and rewrites them to the matching shim URL so
28
- * the published bundle's imports resolve through the host.
29
- * 3. Every plugin's local dev-runtime server (Vite middleware),
30
- * which inlines the shim payload fetched from the host so
31
- * on-demand transforms still consume host singletons.
32
- *
33
- * Adding or removing a singleton is a single edit to
34
- * {@link PLUGIN_RUNTIME_SHIM_SPECIFIERS}. The host shell, plugin
35
- * builds, and plugin dev runtimes all derive their behaviour from
36
- * that list, so they stay in lockstep automatically.
37
- */
38
-
39
- /**
40
- * Bare ESM specifier the host exposes to plugins as a runtime
41
- * singleton. The order here is documentation-only; consumers should
42
- * treat the list as a set.
43
- */
44
- export type TPluginRuntimeShimSpecifier =
45
- | 'react'
46
- | 'react/jsx-runtime'
47
- | 'react/jsx-dev-runtime'
48
- | 'react-dom'
49
- | 'react-dom/client'
50
- | '@mantine/core'
51
- | '@mantine/hooks'
52
- | '@mantine/notifications'
53
- | '@tanstack/react-query'
54
- | '@selfhelp/shared'
55
- | '@selfhelp/shared/plugin-sdk'
56
- | '@selfhelp/shared/registry';
57
-
58
- /**
59
- * Canonical list of bare specifiers the host supports for plugin
60
- * runtimes. Every entry MUST be:
61
- *
62
- * 1. Stashed on `globalThis[PLUGIN_RUNTIME_GLOBAL_KEY]` by the host
63
- * (so the shim has something to re-export);
64
- * 2. Listed in {@link PLUGIN_RUNTIME_IMPORT_MAP} (so the browser
65
- * can rewrite the bare specifier to the shim URL); and
66
- * 3. Allowed by the host's `/api/plugins/runtime-shim/*` route
67
- * handler (so the shim payload is actually generated).
68
- *
69
- * The host frontend asserts (1)–(3) cover the same set at build
70
- * time; drift between them is a contract bug.
71
- */
72
- export const PLUGIN_RUNTIME_SHIM_SPECIFIERS: readonly TPluginRuntimeShimSpecifier[] = [
73
- 'react',
74
- 'react/jsx-runtime',
75
- 'react/jsx-dev-runtime',
76
- 'react-dom',
77
- 'react-dom/client',
78
- '@mantine/core',
79
- '@mantine/hooks',
80
- '@mantine/notifications',
81
- '@tanstack/react-query',
82
- '@selfhelp/shared',
83
- '@selfhelp/shared/plugin-sdk',
84
- '@selfhelp/shared/registry',
85
- ] as const;
86
-
87
- /**
88
- * Host-relative path prefix for the per-module shim endpoint. The
89
- * full URL for a given specifier is built by appending the specifier
90
- * as-is (it already includes any `@scope/` segment and any
91
- * `/subpath`). Use {@link buildPluginRuntimeShimPath} so consumers
92
- * never reconstruct the join logic locally.
93
- */
94
- export const PLUGIN_RUNTIME_SHIM_BASE_PATH = '/api/plugins/runtime-shim/' as const;
95
-
96
- /**
97
- * `globalThis` key the host populates with the singleton module
98
- * instances. The shim payload reads from this key at module-load
99
- * time, so identity is preserved between the host shell and every
100
- * plugin without any extra serialization.
101
- */
102
- export const PLUGIN_RUNTIME_GLOBAL_KEY = '__SELFHELP_RUNTIME__' as const;
103
-
104
- /**
105
- * Build the host-relative URL the import map (and the plugin's Vite
106
- * config) should point a given specifier at. The returned string is
107
- * always same-origin with the host shell — the entire shim contract
108
- * relies on browsers loading the bundle from a URL whose imports
109
- * resolve to the host's origin.
110
- */
111
- export function buildPluginRuntimeShimPath(specifier: TPluginRuntimeShimSpecifier): string {
112
- return `${PLUGIN_RUNTIME_SHIM_BASE_PATH}${specifier}`;
113
- }
114
-
115
- /**
116
- * Type-guarded check that a runtime-supplied string is one of the
117
- * specifiers the host knows how to shim. Consumers that take user
118
- * input (route segments, manifest values) should always validate
119
- * through this helper before falling through to dynamic resolution.
120
- */
121
- export function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginRuntimeShimSpecifier {
122
- return typeof value === 'string'
123
- && (PLUGIN_RUNTIME_SHIM_SPECIFIERS as readonly string[]).includes(value);
124
- }
125
-
126
- /**
127
- * Bare-specifier → shim URL map. Rendered as the body of the
128
- * `<script type="importmap">` tag in the host's root layout. Plugins
129
- * also consume the same map at build time to keep externalisation
130
- * symmetric with the browser-side import map.
131
- *
132
- * Frozen so consumers can pass it directly to `JSON.stringify`
133
- * without worrying about accidental mutation.
134
- */
135
- export const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>
136
- = Object.freeze(
137
- Object.fromEntries(
138
- PLUGIN_RUNTIME_SHIM_SPECIFIERS.map((s) => [s, buildPluginRuntimeShimPath(s)]),
139
- ) as Record<TPluginRuntimeShimSpecifier, string>,
140
- );
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Plugin runtime-shim contract.
7
+ *
8
+ * Plugins ship as native ESM bundles that import bare specifiers like
9
+ * `react`, `@mantine/core`, `@tanstack/react-query`, and
10
+ * `@selfhelp/shared/plugin-sdk`. The browser cannot resolve those
11
+ * without help, and the host explicitly does NOT want each plugin to
12
+ * bundle its own copy of those packages — a duplicate React breaks
13
+ * hooks, a duplicate `@tanstack/react-query` shadows the host's
14
+ * `QueryClient`, a duplicate `STYLE_REGISTRY` desynchronises the
15
+ * style dispatcher.
16
+ *
17
+ * Resolution strategy is a single contract shared across:
18
+ *
19
+ * 1. The host frontend (`sh-selfhelp_frontend`) which:
20
+ * - renders `<script type="importmap">` with the entries from
21
+ * {@link PLUGIN_RUNTIME_IMPORT_MAP},
22
+ * - serves a tiny per-module shim at
23
+ * {@link PLUGIN_RUNTIME_SHIM_BASE_PATH}`<specifier>`,
24
+ * - populates {@link PLUGIN_RUNTIME_GLOBAL_KEY} on `globalThis`
25
+ * with the singleton module objects the host already loaded.
26
+ * 2. Every plugin's frontend Vite build, which externalises the
27
+ * same specifiers and rewrites them to the matching shim URL so
28
+ * the published bundle's imports resolve through the host.
29
+ * 3. Every plugin's local dev-runtime server (Vite middleware),
30
+ * which inlines the shim payload fetched from the host so
31
+ * on-demand transforms still consume host singletons.
32
+ *
33
+ * Adding or removing a singleton is a single edit to
34
+ * {@link PLUGIN_RUNTIME_SHIM_SPECIFIERS}. The host shell, plugin
35
+ * builds, and plugin dev runtimes all derive their behaviour from
36
+ * that list, so they stay in lockstep automatically.
37
+ */
38
+
39
+ /**
40
+ * Bare ESM specifier the host exposes to plugins as a runtime
41
+ * singleton. The order here is documentation-only; consumers should
42
+ * treat the list as a set.
43
+ */
44
+ export type TPluginRuntimeShimSpecifier =
45
+ | 'react'
46
+ | 'react/jsx-runtime'
47
+ | 'react/jsx-dev-runtime'
48
+ | 'react-dom'
49
+ | 'react-dom/client'
50
+ | '@mantine/core'
51
+ | '@mantine/hooks'
52
+ | '@mantine/notifications'
53
+ | '@tanstack/react-query'
54
+ | '@selfhelp/shared'
55
+ | '@selfhelp/shared/plugin-sdk'
56
+ | '@selfhelp/shared/registry';
57
+
58
+ /**
59
+ * Canonical list of bare specifiers the host supports for plugin
60
+ * runtimes. Every entry MUST be:
61
+ *
62
+ * 1. Stashed on `globalThis[PLUGIN_RUNTIME_GLOBAL_KEY]` by the host
63
+ * (so the shim has something to re-export);
64
+ * 2. Listed in {@link PLUGIN_RUNTIME_IMPORT_MAP} (so the browser
65
+ * can rewrite the bare specifier to the shim URL); and
66
+ * 3. Allowed by the host's `/api/plugins/runtime-shim/*` route
67
+ * handler (so the shim payload is actually generated).
68
+ *
69
+ * The host frontend asserts (1)–(3) cover the same set at build
70
+ * time; drift between them is a contract bug.
71
+ */
72
+ export const PLUGIN_RUNTIME_SHIM_SPECIFIERS: readonly TPluginRuntimeShimSpecifier[] = [
73
+ 'react',
74
+ 'react/jsx-runtime',
75
+ 'react/jsx-dev-runtime',
76
+ 'react-dom',
77
+ 'react-dom/client',
78
+ '@mantine/core',
79
+ '@mantine/hooks',
80
+ '@mantine/notifications',
81
+ '@tanstack/react-query',
82
+ '@selfhelp/shared',
83
+ '@selfhelp/shared/plugin-sdk',
84
+ '@selfhelp/shared/registry',
85
+ ] as const;
86
+
87
+ /**
88
+ * Host-relative path prefix for the per-module shim endpoint. The
89
+ * full URL for a given specifier is built by appending the specifier
90
+ * as-is (it already includes any `@scope/` segment and any
91
+ * `/subpath`). Use {@link buildPluginRuntimeShimPath} so consumers
92
+ * never reconstruct the join logic locally.
93
+ */
94
+ export const PLUGIN_RUNTIME_SHIM_BASE_PATH = '/api/plugins/runtime-shim/' as const;
95
+
96
+ /**
97
+ * `globalThis` key the host populates with the singleton module
98
+ * instances. The shim payload reads from this key at module-load
99
+ * time, so identity is preserved between the host shell and every
100
+ * plugin without any extra serialization.
101
+ */
102
+ export const PLUGIN_RUNTIME_GLOBAL_KEY = '__SELFHELP_RUNTIME__' as const;
103
+
104
+ /**
105
+ * Build the host-relative URL the import map (and the plugin's Vite
106
+ * config) should point a given specifier at. The returned string is
107
+ * always same-origin with the host shell — the entire shim contract
108
+ * relies on browsers loading the bundle from a URL whose imports
109
+ * resolve to the host's origin.
110
+ */
111
+ export function buildPluginRuntimeShimPath(specifier: TPluginRuntimeShimSpecifier): string {
112
+ return `${PLUGIN_RUNTIME_SHIM_BASE_PATH}${specifier}`;
113
+ }
114
+
115
+ /**
116
+ * Type-guarded check that a runtime-supplied string is one of the
117
+ * specifiers the host knows how to shim. Consumers that take user
118
+ * input (route segments, manifest values) should always validate
119
+ * through this helper before falling through to dynamic resolution.
120
+ */
121
+ export function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginRuntimeShimSpecifier {
122
+ return typeof value === 'string'
123
+ && (PLUGIN_RUNTIME_SHIM_SPECIFIERS as readonly string[]).includes(value);
124
+ }
125
+
126
+ /**
127
+ * Bare-specifier → shim URL map. Rendered as the body of the
128
+ * `<script type="importmap">` tag in the host's root layout. Plugins
129
+ * also consume the same map at build time to keep externalisation
130
+ * symmetric with the browser-side import map.
131
+ *
132
+ * Frozen so consumers can pass it directly to `JSON.stringify`
133
+ * without worrying about accidental mutation.
134
+ */
135
+ export const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>
136
+ = Object.freeze(
137
+ Object.fromEntries(
138
+ PLUGIN_RUNTIME_SHIM_SPECIFIERS.map((s) => [s, buildPluginRuntimeShimPath(s)]),
139
+ ) as Record<TPluginRuntimeShimSpecifier, string>,
140
+ );