occulite-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.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +290 -2
  3. package/THIRD_PARTY_NOTICES.md +36 -0
  4. package/dist/clipboard.d.ts +26 -0
  5. package/dist/clipboard.js +70 -0
  6. package/dist/components/ContextMenu.svelte +158 -0
  7. package/dist/components/ContextMenu.svelte.d.ts +14 -0
  8. package/dist/components/DataTable.svelte +1990 -0
  9. package/dist/components/DataTable.svelte.d.ts +154 -0
  10. package/dist/components/Dialog.svelte +420 -0
  11. package/dist/components/Dialog.svelte.d.ts +55 -0
  12. package/dist/components/GithubLink.svelte +74 -0
  13. package/dist/components/GithubLink.svelte.d.ts +16 -0
  14. package/dist/components/Header.svelte +196 -0
  15. package/dist/components/Header.svelte.d.ts +42 -0
  16. package/dist/components/Icon.svelte +51 -0
  17. package/dist/components/Icon.svelte.d.ts +12 -0
  18. package/dist/components/LanguageSwitch.svelte +63 -0
  19. package/dist/components/LanguageSwitch.svelte.d.ts +17 -0
  20. package/dist/components/Loader.svelte +65 -0
  21. package/dist/components/Loader.svelte.d.ts +9 -0
  22. package/dist/components/MultiSelect.svelte +467 -0
  23. package/dist/components/MultiSelect.svelte.d.ts +28 -0
  24. package/dist/components/Notices.svelte +146 -0
  25. package/dist/components/Notices.svelte.d.ts +16 -0
  26. package/dist/components/PrimaryToolbarButton.svelte +189 -0
  27. package/dist/components/PrimaryToolbarButton.svelte.d.ts +34 -0
  28. package/dist/components/Tabs.svelte +118 -0
  29. package/dist/components/Tabs.svelte.d.ts +16 -0
  30. package/dist/components/ThemeSwitch.svelte +46 -0
  31. package/dist/components/ThemeSwitch.svelte.d.ts +11 -0
  32. package/dist/components/Toolbar.svelte +57 -0
  33. package/dist/components/Toolbar.svelte.d.ts +11 -0
  34. package/dist/components/ToolbarButton.svelte +126 -0
  35. package/dist/components/ToolbarButton.svelte.d.ts +22 -0
  36. package/dist/components/Tooltip.svelte +106 -0
  37. package/dist/components/Tooltip.svelte.d.ts +31 -0
  38. package/dist/components/TooltipBubble.svelte +65 -0
  39. package/dist/components/TooltipBubble.svelte.d.ts +18 -0
  40. package/dist/components/contextMenu.d.ts +19 -0
  41. package/dist/components/contextMenu.js +6 -0
  42. package/dist/components/dialogGeometry.d.ts +91 -0
  43. package/dist/components/dialogGeometry.js +140 -0
  44. package/dist/components/index.d.ts +22 -0
  45. package/dist/components/index.js +22 -0
  46. package/dist/components/multiSelect.d.ts +27 -0
  47. package/dist/components/multiSelect.js +26 -0
  48. package/dist/components/navigation.d.ts +34 -0
  49. package/dist/components/navigation.js +19 -0
  50. package/dist/components/tooltip.d.ts +29 -0
  51. package/dist/components/tooltip.js +27 -0
  52. package/dist/css/app.css +3 -0
  53. package/dist/css/base.css +84 -0
  54. package/dist/css/tokens.css +170 -0
  55. package/dist/dialog/index.d.ts +6 -0
  56. package/dist/dialog/index.js +6 -0
  57. package/dist/embedding/ShellEmbedding.svelte.d.ts +27 -0
  58. package/dist/embedding/ShellEmbedding.svelte.js +79 -0
  59. package/dist/embedding/constants.d.ts +23 -0
  60. package/dist/embedding/constants.js +54 -0
  61. package/dist/embedding/index.d.ts +2 -0
  62. package/dist/embedding/index.js +2 -0
  63. package/dist/externalLink.d.ts +15 -0
  64. package/dist/externalLink.js +20 -0
  65. package/dist/format.d.ts +6 -0
  66. package/dist/format.js +16 -0
  67. package/dist/i18n/i18n.svelte.d.ts +112 -0
  68. package/dist/i18n/i18n.svelte.js +211 -0
  69. package/dist/i18n/index.d.ts +3 -0
  70. package/dist/i18n/index.js +3 -0
  71. package/dist/i18n/messages.d.ts +9 -0
  72. package/dist/i18n/messages.js +58 -0
  73. package/dist/i18n/translator.d.ts +65 -0
  74. package/dist/i18n/translator.js +99 -0
  75. package/dist/icons/index.d.ts +17 -0
  76. package/dist/icons/index.js +11 -0
  77. package/dist/index.d.ts +16 -0
  78. package/dist/index.js +16 -0
  79. package/dist/notices/NoticesStore.svelte.d.ts +64 -0
  80. package/dist/notices/NoticesStore.svelte.js +127 -0
  81. package/dist/notices/index.d.ts +1 -0
  82. package/dist/notices/index.js +1 -0
  83. package/dist/storage.d.ts +11 -0
  84. package/dist/storage.js +27 -0
  85. package/dist/table/LocalColumnWidths.svelte.d.ts +32 -0
  86. package/dist/table/LocalColumnWidths.svelte.js +91 -0
  87. package/dist/table/columnMeasure.d.ts +24 -0
  88. package/dist/table/columnMeasure.js +82 -0
  89. package/dist/table/columnWidths.d.ts +60 -0
  90. package/dist/table/columnWidths.js +86 -0
  91. package/dist/table/dataTableContext.d.ts +26 -0
  92. package/dist/table/dataTableContext.js +16 -0
  93. package/dist/table/index.d.ts +6 -0
  94. package/dist/table/index.js +6 -0
  95. package/dist/table/metrics.d.ts +10 -0
  96. package/dist/table/metrics.js +10 -0
  97. package/dist/table/tableModel.d.ts +306 -0
  98. package/dist/table/tableModel.js +437 -0
  99. package/dist/theme/choices.d.ts +8 -0
  100. package/dist/theme/choices.js +6 -0
  101. package/dist/theme/index.d.ts +2 -0
  102. package/dist/theme/index.js +2 -0
  103. package/dist/theme/theme.svelte.d.ts +60 -0
  104. package/dist/theme/theme.svelte.js +108 -0
  105. package/package.json +137 -4
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The app's own tooltip, shared by the toolbar's `Tooltip` anchor and the grid's
3
+ * cut-off cells.
4
+ *
5
+ * `title` hands the delay to the browser, which on macOS waited four to five seconds; so the delay
6
+ * and the placement are ours, and they are the same wherever a tooltip appears.
7
+ */
8
+ /** How long the pointer has to rest before a tooltip appears. */
9
+ export declare const TOOLTIP_DELAY_MS = 300;
10
+ /** The bubble wraps beyond this; `.hmm-tooltip` has the same `max-width`. */
11
+ export declare const TOOLTIP_MAX_WIDTH = 280;
12
+ export interface TooltipAnchor {
13
+ readonly left: number;
14
+ readonly top: number;
15
+ readonly bottom: number;
16
+ }
17
+ export interface TooltipPlacement {
18
+ readonly left: number;
19
+ readonly top: number;
20
+ }
21
+ /**
22
+ * Below the anchor and left-aligned with it, kept inside the window horizontally. When the bubble
23
+ * is known to be `height` tall and would run past the bottom of the window, it goes above the
24
+ * anchor instead - a grid row near the bottom edge is where that happens.
25
+ */
26
+ export declare function placeTooltip(anchor: TooltipAnchor, viewport: {
27
+ readonly width: number;
28
+ readonly height: number;
29
+ }, height?: number): TooltipPlacement;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The app's own tooltip, shared by the toolbar's `Tooltip` anchor and the grid's
3
+ * cut-off cells.
4
+ *
5
+ * `title` hands the delay to the browser, which on macOS waited four to five seconds; so the delay
6
+ * and the placement are ours, and they are the same wherever a tooltip appears.
7
+ */
8
+ /** How long the pointer has to rest before a tooltip appears. */
9
+ export const TOOLTIP_DELAY_MS = 300;
10
+ /** The bubble wraps beyond this; `.hmm-tooltip` has the same `max-width`. */
11
+ export const TOOLTIP_MAX_WIDTH = 280;
12
+ /** The gap between the anchor and the bubble, and the margin kept to the window's edges. */
13
+ const GAP = 4;
14
+ /**
15
+ * Below the anchor and left-aligned with it, kept inside the window horizontally. When the bubble
16
+ * is known to be `height` tall and would run past the bottom of the window, it goes above the
17
+ * anchor instead - a grid row near the bottom edge is where that happens.
18
+ */
19
+ export function placeTooltip(anchor, viewport, height = 0) {
20
+ const width = Math.min(TOOLTIP_MAX_WIDTH, viewport.width - 2 * GAP);
21
+ const left = Math.max(GAP, Math.min(anchor.left, viewport.width - width - GAP));
22
+ const below = anchor.bottom + GAP;
23
+ if (height > 0 && below + height > viewport.height - GAP && anchor.top - GAP - height >= GAP) {
24
+ return { left, top: anchor.top - GAP - height };
25
+ }
26
+ return { left, top: below };
27
+ }
@@ -0,0 +1,3 @@
1
+ /* occulite-ui's global stylesheet: the tokens, then the base rules. `import 'occulite-ui/app.css'` once. */
2
+ @import './tokens.css';
3
+ @import './base.css';
@@ -0,0 +1,84 @@
1
+ /*
2
+ * The global rules of the kit: the box model, the body, focus, scrollbars and the plain form
3
+ * controls (`.hmm-input`, `.hmm-select`, `.hmm-button`). Imported once by the app, after
4
+ * `tokens.css` (`occulite-ui/app.css` is both). Each component's own CSS is scoped inside it.
5
+ *
6
+ * Nothing here sets a page size or a mount element: those are the app's.
7
+ */
8
+
9
+ html,
10
+ body {
11
+ height: 100%;
12
+ }
13
+
14
+ body {
15
+ margin: 0;
16
+ padding: 0;
17
+ background: var(--hmm-bg);
18
+ color: var(--hmm-fg);
19
+ font-family: var(--hmm-font);
20
+ font-size: var(--hmm-font-size);
21
+ }
22
+
23
+ *,
24
+ *::before,
25
+ *::after {
26
+ box-sizing: border-box;
27
+ }
28
+
29
+ /* Thin scrollbars: a data table has a lot of them, and fat default ones make a window look busy. */
30
+ * {
31
+ scrollbar-width: thin;
32
+ scrollbar-color: var(--hmm-border-strong) transparent;
33
+ }
34
+
35
+ :focus-visible {
36
+ outline: 2px solid var(--hmm-focus);
37
+ outline-offset: -1px;
38
+ }
39
+
40
+ .hmm-mono {
41
+ font-family: var(--hmm-font-mono);
42
+ }
43
+
44
+ button,
45
+ input,
46
+ select,
47
+ textarea {
48
+ font-family: inherit;
49
+ font-size: inherit;
50
+ color: inherit;
51
+ }
52
+
53
+ /* The plain form controls of toolbars and dialogs. */
54
+ .hmm-input,
55
+ .hmm-select {
56
+ height: 24px;
57
+ padding: 2px 6px;
58
+ border: 1px solid var(--hmm-border);
59
+ border-radius: var(--hmm-radius);
60
+ background: var(--hmm-input-bg);
61
+ }
62
+
63
+ .hmm-input:focus-visible,
64
+ .hmm-select:focus-visible {
65
+ border-color: var(--hmm-accent);
66
+ }
67
+
68
+ .hmm-button {
69
+ min-height: 24px;
70
+ padding: 3px 10px;
71
+ border: 1px solid var(--hmm-border);
72
+ border-radius: var(--hmm-radius);
73
+ background: var(--hmm-control-bg);
74
+ cursor: pointer;
75
+ }
76
+
77
+ .hmm-button:hover:not(:disabled) {
78
+ background: var(--hmm-control-bg-hover);
79
+ }
80
+
81
+ .hmm-button:disabled {
82
+ opacity: 0.45;
83
+ cursor: default;
84
+ }
@@ -0,0 +1,170 @@
1
+ /*
2
+ * The design tokens - one file for both themes, light and dark.
3
+ *
4
+ * The visual language: flat surfaces, a quiet palette, one accent, hairline separators, no
5
+ * gradient anywhere, and controls that mark their state with colour rather than with a weight that
6
+ * changes their width.
7
+ *
8
+ * Light is the default and is defined on bare `:root`. Dark is defined twice - once under
9
+ * `prefers-color-scheme` (guarded so an explicit light choice wins) and once under
10
+ * `[data-theme='dark']` - so a manual switch works in both directions. The dark palette is a
11
+ * blue-grey rather than a neutral grey: a neutral grey on grey reads flat. Every colour of the
12
+ * kit's components comes from a token here; `theme.test.ts` fails the build if a component spells
13
+ * one out.
14
+ *
15
+ * Custom properties only; the rules are in `base.css`. The `--hmm-` prefix is kept through 0.x.
16
+ */
17
+
18
+ :root {
19
+ color-scheme: light;
20
+
21
+ /* Surfaces */
22
+ --hmm-bg: #ffffff;
23
+ --hmm-bg-sunken: #f8f8f8;
24
+ /* Bars: the header, the toolbars, the table head, a dialog's title bar. Flat, not a gradient. */
25
+ --hmm-header-bg: #f3f3f3;
26
+ --hmm-header-solid: #ececec;
27
+ /* Controls: a button's face, and the field an input is typed into. */
28
+ --hmm-control-bg: #f0f0f0;
29
+ --hmm-control-bg-hover: #e4e4e4;
30
+ --hmm-input-bg: #ffffff;
31
+ --hmm-row-odd: #ffffff;
32
+ /* No zebra: the row separator does the work. Kept as a token so the two row states stay
33
+ addressable; both are the plain surface. */
34
+ --hmm-row-even: #ffffff;
35
+ --hmm-row-hover: #f0f4f8;
36
+ --hmm-row-selected: #cfe4f7;
37
+ --hmm-row-selected-text: #12314d;
38
+ --hmm-overlay: rgba(255, 255, 255, 0.72);
39
+ --hmm-backdrop: rgba(0, 0, 0, 0.35);
40
+ --hmm-shadow-menu: 0 4px 12px rgb(0 0 0 / 18%);
41
+ --hmm-shadow-toast: 0 2px 10px rgb(0 0 0 / 16%);
42
+
43
+ /* Lines */
44
+ --hmm-border: #cecece;
45
+ --hmm-border-muted: #e6e6e6;
46
+ --hmm-border-strong: #b0b0b0;
47
+
48
+ /* Text */
49
+ --hmm-fg: #3b3b3b;
50
+ --hmm-fg-muted: #6d6d6d;
51
+ --hmm-fg-faint: #9a9a9a;
52
+ --hmm-link: #0070c1;
53
+
54
+ /* Accents */
55
+ --hmm-accent: #0070c1;
56
+ --hmm-accent-bg: #e2eefa;
57
+ /* Text on a surface painted in --hmm-accent: a page's main action. */
58
+ --hmm-accent-fg: #ffffff;
59
+ --hmm-ok: #008000;
60
+ --hmm-warn: #a06800;
61
+ --hmm-error: #cd3131;
62
+ --hmm-focus: #0070c1;
63
+
64
+ /* Type. 13 px is the reading size of the chrome; tables stay a size below it. */
65
+ --hmm-font: system-ui, -apple-system, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
66
+ --hmm-font-mono: ui-monospace, 'Cascadia Mono', Consolas, Menlo, Monaco, monospace;
67
+ --hmm-font-size: 13px;
68
+ --hmm-font-size-grid: 12px;
69
+ --hmm-font-size-small: 11px;
70
+ --hmm-font-size-tiny: 9px;
71
+
72
+ /* Metrics. The row height of every table: 30 px fits a 20 px picture and a 22 px control with
73
+ the cell's padding. A denser app sets it to 26 px and passes the same number to `DataTable`'s
74
+ `rowHeight` (the virtualiser needs it as a number, `ROW_HEIGHT` in `table/metrics.ts`). */
75
+ --hmm-row-height: 30px;
76
+ --hmm-header-height: 36px;
77
+ --hmm-radius: 3px;
78
+
79
+ /*
80
+ * Form metrics, so a dialog's spacing is a decision made once rather than a gap every row
81
+ * brings along. The label column is as wide as a long German switch label needs at 13 px before
82
+ * it wraps, and the two field widths are the ones a *type* asks for: a port is four digits,
83
+ * everything else fills the row it is in.
84
+ */
85
+ --hmm-form-label-width: 210px;
86
+ --hmm-form-column-gap: 10px;
87
+ --hmm-form-row-gap: 6px;
88
+ --hmm-form-section-gap: 14px;
89
+ --hmm-form-help-gap: 2px;
90
+ --hmm-field-narrow: 90px;
91
+ --hmm-field-medium: 150px;
92
+ }
93
+
94
+ @media (prefers-color-scheme: dark) {
95
+ :root:not([data-theme='light']) {
96
+ color-scheme: dark;
97
+
98
+ --hmm-bg: #1b1f26;
99
+ --hmm-bg-sunken: #171a20;
100
+ --hmm-header-bg: #212630;
101
+ --hmm-header-solid: #282e39;
102
+ --hmm-control-bg: #2e3542;
103
+ --hmm-control-bg-hover: #39414f;
104
+ --hmm-input-bg: #353d4a;
105
+ --hmm-row-odd: #1b1f26;
106
+ --hmm-row-even: #1b1f26;
107
+ --hmm-row-hover: #252c38;
108
+ --hmm-row-selected: #264f78;
109
+ --hmm-row-selected-text: #e8f2fb;
110
+ --hmm-overlay: rgba(22, 25, 31, 0.72);
111
+ --hmm-backdrop: rgba(0, 0, 0, 0.6);
112
+ --hmm-shadow-menu: 0 4px 14px rgb(0 0 0 / 60%);
113
+ --hmm-shadow-toast: 0 2px 12px rgb(0 0 0 / 55%);
114
+
115
+ --hmm-border: #363e4b;
116
+ --hmm-border-muted: #2a313c;
117
+ --hmm-border-strong: #4e5769;
118
+
119
+ --hmm-fg: #ccd2dc;
120
+ --hmm-fg-muted: #8b94a3;
121
+ --hmm-fg-faint: #6b7383;
122
+ --hmm-link: #569cd6;
123
+
124
+ --hmm-accent: #569cd6;
125
+ --hmm-accent-bg: #253b52;
126
+ --hmm-accent-fg: #1b1f26;
127
+ --hmm-ok: #4ec9b0;
128
+ --hmm-warn: #cca700;
129
+ --hmm-error: #f48771;
130
+ --hmm-focus: #569cd6;
131
+ }
132
+ }
133
+
134
+ :root[data-theme='dark'] {
135
+ color-scheme: dark;
136
+
137
+ --hmm-bg: #1b1f26;
138
+ --hmm-bg-sunken: #171a20;
139
+ --hmm-header-bg: #212630;
140
+ --hmm-header-solid: #282e39;
141
+ --hmm-control-bg: #2e3542;
142
+ --hmm-control-bg-hover: #39414f;
143
+ --hmm-input-bg: #353d4a;
144
+ --hmm-row-odd: #1b1f26;
145
+ --hmm-row-even: #1b1f26;
146
+ --hmm-row-hover: #252c38;
147
+ --hmm-row-selected: #264f78;
148
+ --hmm-row-selected-text: #e8f2fb;
149
+ --hmm-overlay: rgba(22, 25, 31, 0.72);
150
+ --hmm-backdrop: rgba(0, 0, 0, 0.6);
151
+ --hmm-shadow-menu: 0 4px 14px rgb(0 0 0 / 60%);
152
+ --hmm-shadow-toast: 0 2px 12px rgb(0 0 0 / 55%);
153
+
154
+ --hmm-border: #363e4b;
155
+ --hmm-border-muted: #2a313c;
156
+ --hmm-border-strong: #4e5769;
157
+
158
+ --hmm-fg: #ccd2dc;
159
+ --hmm-fg-muted: #8b94a3;
160
+ --hmm-fg-faint: #6b7383;
161
+ --hmm-link: #569cd6;
162
+
163
+ --hmm-accent: #569cd6;
164
+ --hmm-accent-bg: #253b52;
165
+ --hmm-accent-fg: #1b1f26;
166
+ --hmm-ok: #4ec9b0;
167
+ --hmm-warn: #cca700;
168
+ --hmm-error: #f48771;
169
+ --hmm-focus: #569cd6;
170
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Dialogs. 0.1 has the movable, resizable window dialog (`Dialog`, with its geometry helpers);
3
+ * the question dialog (`ask`, `askText`, `ConfirmDialog`, `ModalDialog`) follows in 0.2.
4
+ */
5
+ export * from '../components/dialogGeometry.js';
6
+ export { default as Dialog } from '../components/Dialog.svelte';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Dialogs. 0.1 has the movable, resizable window dialog (`Dialog`, with its geometry helpers);
3
+ * the question dialog (`ask`, `askText`, `ConfirmDialog`, `ModalDialog`) follows in 0.2.
4
+ */
5
+ export * from '../components/dialogGeometry.js';
6
+ export { default as Dialog } from '../components/Dialog.svelte';
@@ -0,0 +1,27 @@
1
+ import { type ThemeChoice } from '../theme/choices.js';
2
+ /**
3
+ * Whether the page runs inside openccu-lite's shell - the system's menu chrome around an addon
4
+ * page - and which theme and language the shell shows.
5
+ *
6
+ * Inside that frame the shell has the user, the logout and the theme of its own, so a page leaves
7
+ * those controls out and follows the shell. Being on openccu-lite is not enough: the same page
8
+ * opened full screen in a tab of its own, on a classic CCU or in a desktop app keeps every control.
9
+ * So "inside the shell" is a framed page whose parent is of its own origin, *and* the shell's theme
10
+ * on the URL or the shell's message from that parent - a CCU or any other frame sends neither.
11
+ */
12
+ export declare class ShellEmbedding {
13
+ #private;
14
+ /** Inside openccu-lite's shell. */
15
+ embedded: boolean;
16
+ /** The shell's theme while embedded; `undefined` outside, where the app's own choice applies. */
17
+ theme: ThemeChoice | undefined;
18
+ /** The shell's language while embedded, as the shell names it (`de`, `en`); `undefined` outside. */
19
+ lang: string | undefined;
20
+ constructor(win?: Window | undefined);
21
+ dispose(): void;
22
+ }
23
+ /**
24
+ * The page's one `ShellEmbedding`, created on first use: the theme and the language both follow
25
+ * the same shell, and two listeners for one message would only be two places to get it wrong.
26
+ */
27
+ export declare function shellEmbedding(): ShellEmbedding;
@@ -0,0 +1,79 @@
1
+ import { themeOf } from '../theme/choices.js';
2
+ import { LANG_PARAM, SHELL_MESSAGE, searchParam, THEME_PARAM } from './constants.js';
3
+ /**
4
+ * Whether the page runs inside openccu-lite's shell - the system's menu chrome around an addon
5
+ * page - and which theme and language the shell shows.
6
+ *
7
+ * Inside that frame the shell has the user, the logout and the theme of its own, so a page leaves
8
+ * those controls out and follows the shell. Being on openccu-lite is not enough: the same page
9
+ * opened full screen in a tab of its own, on a classic CCU or in a desktop app keeps every control.
10
+ * So "inside the shell" is a framed page whose parent is of its own origin, *and* the shell's theme
11
+ * on the URL or the shell's message from that parent - a CCU or any other frame sends neither.
12
+ */
13
+ export class ShellEmbedding {
14
+ /** Inside openccu-lite's shell. */
15
+ embedded = $state(false);
16
+ /** The shell's theme while embedded; `undefined` outside, where the app's own choice applies. */
17
+ theme = $state(undefined);
18
+ /** The shell's language while embedded, as the shell names it (`de`, `en`); `undefined` outside. */
19
+ lang = $state(undefined);
20
+ #win;
21
+ #onMessage = (event) => {
22
+ this.#message(event);
23
+ };
24
+ constructor(win = typeof window === 'undefined' ? undefined : window) {
25
+ this.#win = win;
26
+ if (!win || !framedBySameOrigin(win)) {
27
+ return;
28
+ }
29
+ const fromUrl = themeOf(searchParam(win.location.search, THEME_PARAM));
30
+ if (fromUrl !== undefined) {
31
+ this.embedded = true;
32
+ this.theme = fromUrl;
33
+ this.lang = langOf(searchParam(win.location.search, LANG_PARAM));
34
+ }
35
+ win.addEventListener('message', this.#onMessage);
36
+ }
37
+ #message(event) {
38
+ const win = this.#win;
39
+ if (!win || event.origin !== win.location.origin || event.source !== win.parent) {
40
+ return;
41
+ }
42
+ const data = event.data;
43
+ if (data === null || typeof data !== 'object' || data.type !== SHELL_MESSAGE) {
44
+ return;
45
+ }
46
+ this.embedded = true;
47
+ this.theme = themeOf(data.theme) ?? this.theme ?? 'system';
48
+ this.lang = langOf(data.lang) ?? this.lang;
49
+ }
50
+ dispose() {
51
+ this.#win?.removeEventListener('message', this.#onMessage);
52
+ }
53
+ }
54
+ /** A language code as the shell sends one: two or three letters, region dropped. */
55
+ function langOf(value) {
56
+ if (typeof value !== 'string') {
57
+ return undefined;
58
+ }
59
+ const code = value.toLowerCase().split('-')[0] ?? '';
60
+ return /^[a-z]{2,3}$/u.test(code) ? code : undefined;
61
+ }
62
+ /** A frame whose parent is a page of this origin; a cross-origin parent throws on `location`. */
63
+ function framedBySameOrigin(win) {
64
+ try {
65
+ return win.self !== win.top && win.parent.location.origin === win.location.origin;
66
+ }
67
+ catch {
68
+ return false;
69
+ }
70
+ }
71
+ let shared;
72
+ /**
73
+ * The page's one `ShellEmbedding`, created on first use: the theme and the language both follow
74
+ * the same shell, and two listeners for one message would only be two places to get it wrong.
75
+ */
76
+ export function shellEmbedding() {
77
+ shared ??= new ShellEmbedding();
78
+ return shared;
79
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * openccu-lite's embedding contract, frame side.
3
+ *
4
+ * The system's shell frames an addon's page as an iframe of the same origin. The frame URL carries
5
+ * `theme=system|light|dark` and `lang=de|en` for the first paint, and the shell posts
6
+ * `{type: SHELL_MESSAGE, theme, lang}` to the frame on load and on every change. For pages of the
7
+ * same origin outside a frame, the shell keeps its choice in two cookies. The contract is the
8
+ * shell's; these constants name it so both ends agree.
9
+ */
10
+ /** The `type` of the message the shell posts to its frames. */
11
+ export declare const SHELL_MESSAGE = "openccu-lite:theme";
12
+ /** The cookie the shell keeps its theme choice in. */
13
+ export declare const THEME_COOKIE = "ol-theme";
14
+ /** The cookie the shell keeps its language in. */
15
+ export declare const LANG_COOKIE = "ol-lang";
16
+ /** The frame URL's parameter for the theme. */
17
+ export declare const THEME_PARAM = "theme";
18
+ /** The frame URL's parameter for the language. */
19
+ export declare const LANG_PARAM = "lang";
20
+ /** The value of a cookie, or `undefined`; never throws (a sandboxed document refuses `cookie`). */
21
+ export declare function readCookie(name: string, doc?: Document | undefined): string | undefined;
22
+ /** The value of a URL search parameter, or `undefined`. */
23
+ export declare function searchParam(search: string, name: string): string | undefined;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * openccu-lite's embedding contract, frame side.
3
+ *
4
+ * The system's shell frames an addon's page as an iframe of the same origin. The frame URL carries
5
+ * `theme=system|light|dark` and `lang=de|en` for the first paint, and the shell posts
6
+ * `{type: SHELL_MESSAGE, theme, lang}` to the frame on load and on every change. For pages of the
7
+ * same origin outside a frame, the shell keeps its choice in two cookies. The contract is the
8
+ * shell's; these constants name it so both ends agree.
9
+ */
10
+ /** The `type` of the message the shell posts to its frames. */
11
+ export const SHELL_MESSAGE = 'openccu-lite:theme';
12
+ /** The cookie the shell keeps its theme choice in. */
13
+ export const THEME_COOKIE = 'ol-theme';
14
+ /** The cookie the shell keeps its language in. */
15
+ export const LANG_COOKIE = 'ol-lang';
16
+ /** The frame URL's parameter for the theme. */
17
+ export const THEME_PARAM = 'theme';
18
+ /** The frame URL's parameter for the language. */
19
+ export const LANG_PARAM = 'lang';
20
+ /** The value of a cookie, or `undefined`; never throws (a sandboxed document refuses `cookie`). */
21
+ export function readCookie(name, doc = typeof document === 'undefined' ? undefined : document) {
22
+ let cookies;
23
+ try {
24
+ cookies = doc?.cookie ?? '';
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ for (const part of cookies.split(';')) {
30
+ const index = part.indexOf('=');
31
+ if (index < 0) {
32
+ continue;
33
+ }
34
+ if (part.slice(0, index).trim() === name) {
35
+ const raw = part.slice(index + 1).trim();
36
+ try {
37
+ return decodeURIComponent(raw);
38
+ }
39
+ catch {
40
+ return raw;
41
+ }
42
+ }
43
+ }
44
+ return undefined;
45
+ }
46
+ /** The value of a URL search parameter, or `undefined`. */
47
+ export function searchParam(search, name) {
48
+ try {
49
+ return new URLSearchParams(search).get(name) ?? undefined;
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
@@ -0,0 +1,2 @@
1
+ export * from './constants.js';
2
+ export * from './ShellEmbedding.svelte.js';
@@ -0,0 +1,2 @@
1
+ export * from './constants.js';
2
+ export * from './ShellEmbedding.svelte.js';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Hands a URL to the host, and says whether the host took it. `false` - no host, or a preload
3
+ * that predates the command - means the browser has to follow the link itself.
4
+ */
5
+ export type OpenExternal = (url: string) => Promise<boolean>;
6
+ /**
7
+ * The click handler of a real link that a desktop host opens in the user's browser.
8
+ *
9
+ * The anchor stays an anchor - `target="_blank"` with `rel="noopener noreferrer"` - so that in a
10
+ * browser, and for the middle button, the context menu and a screen reader, it is the plain link it
11
+ * looks like. In Electron a plain left click is answered by the host bridge instead and the default
12
+ * is prevented, because a renderer that opened a window itself would be a window nobody wanted.
13
+ * Main decides what it opens (an allow-list), not this function.
14
+ */
15
+ export declare function followExternalLink(event: MouseEvent, href: string, openExternal: OpenExternal | undefined): void;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The click handler of a real link that a desktop host opens in the user's browser.
3
+ *
4
+ * The anchor stays an anchor - `target="_blank"` with `rel="noopener noreferrer"` - so that in a
5
+ * browser, and for the middle button, the context menu and a screen reader, it is the plain link it
6
+ * looks like. In Electron a plain left click is answered by the host bridge instead and the default
7
+ * is prevented, because a renderer that opened a window itself would be a window nobody wanted.
8
+ * Main decides what it opens (an allow-list), not this function.
9
+ */
10
+ export function followExternalLink(event, href, openExternal) {
11
+ if (!openExternal || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey) {
12
+ return;
13
+ }
14
+ event.preventDefault();
15
+ void openExternal(href).then((handled) => {
16
+ if (!handled) {
17
+ window.open(href, '_blank', 'noopener,noreferrer');
18
+ }
19
+ });
20
+ }
@@ -0,0 +1,6 @@
1
+ /** `14:22:41` - a time of day, 24-hour, in the given locale. */
2
+ export declare function formatTime(timestamp: number, locale?: string): string;
3
+ /** The date and the time, for where the day matters. */
4
+ export declare function formatDateTime(timestamp: number, locale?: string): string;
5
+ /** `184 ms`, `1.20 s` - a duration. */
6
+ export declare function formatDuration(durationMs: number): string;
package/dist/format.js ADDED
@@ -0,0 +1,16 @@
1
+ /** `14:22:41` - a time of day, 24-hour, in the given locale. */
2
+ export function formatTime(timestamp, locale) {
3
+ return new Date(timestamp).toLocaleTimeString(locale, { hour12: false });
4
+ }
5
+ /** The date and the time, for where the day matters. */
6
+ export function formatDateTime(timestamp, locale) {
7
+ const date = new Date(timestamp);
8
+ return `${date.toLocaleDateString(locale)} ${date.toLocaleTimeString(locale, { hour12: false })}`;
9
+ }
10
+ /** `184 ms`, `1.20 s` - a duration. */
11
+ export function formatDuration(durationMs) {
12
+ if (durationMs < 1000) {
13
+ return `${Math.round(durationMs)} ms`;
14
+ }
15
+ return `${(durationMs / 1000).toFixed(2)} s`;
16
+ }