@mythicalos/ui-core 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.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +89 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/logic/button.d.ts +10 -0
- package/dist/logic/button.js +12 -0
- package/dist/logic/dialog.d.ts +9 -0
- package/dist/logic/dialog.js +12 -0
- package/dist/logic/gauge.d.ts +13 -0
- package/dist/logic/gauge.js +18 -0
- package/dist/logic/poll.d.ts +72 -0
- package/dist/logic/poll.js +80 -0
- package/dist/logic/toast.d.ts +20 -0
- package/dist/logic/toast.js +14 -0
- package/dist/logic/tone.d.ts +8 -0
- package/dist/logic/tone.js +19 -0
- package/package.json +61 -0
- package/src/select/mythical-select.d.ts +115 -0
- package/src/select/mythical-select.js +1279 -0
- package/src/select/register.js +4 -0
- package/styles.css +302 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 mythicalOS
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @mythicalos/ui-core
|
|
2
|
+
|
|
3
|
+
The **framework-agnostic core** of the mythicalOS component library — pure logic; no framework
|
|
4
|
+
runtime. It holds the branchy, DOM-free logic that both the Preact and React bindings import, so
|
|
5
|
+
the two frameworks derive identical classes/behavior from one source: button class derivation, the
|
|
6
|
+
U7 poll-scheduling math + fire-time epoch guard, the confirm-dialog typed-name gate, the toast
|
|
7
|
+
text-composition helper, and the circular-gauge geometry.
|
|
8
|
+
|
|
9
|
+
This package MUST NOT import `preact` or `react` — see `test/agnostic.test.ts`.
|
|
10
|
+
|
|
11
|
+
## Install / Import
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm add @mythicalos/ui-core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`@mythicalos/tokens` is a peer dependency — load its stylesheet *before* this
|
|
18
|
+
package's so the `--my-*` custom properties it defines are already in scope
|
|
19
|
+
when `styles.css` resolves through them:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm add @mythicalos/tokens
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Three import forms, all consumable from a plain Node ESM script, a webpack/vite
|
|
26
|
+
app, or a React/Preact bundle — `./logic` ships compiled ESM + `.d.ts` from
|
|
27
|
+
`dist/` (not raw TypeScript source), so no consumer needs a TS loader for it:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// 1. logic — pure functions/types, zero DOM, zero framework runtime
|
|
31
|
+
import { buttonClass, nextPollDelay, typedNameMatches } from "@mythicalos/ui-core/logic";
|
|
32
|
+
// (equivalently, the package root re-exports the same thing)
|
|
33
|
+
import { buttonClass } from "@mythicalos/ui-core";
|
|
34
|
+
|
|
35
|
+
// 2. styles — the atom-class stylesheet; import @mythicalos/tokens' CSS first
|
|
36
|
+
import "@mythicalos/tokens";
|
|
37
|
+
import "@mythicalos/ui-core/styles.css";
|
|
38
|
+
|
|
39
|
+
// 3. the <mythical-select> web component — a registration side effect
|
|
40
|
+
import "@mythicalos/ui-core/select";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { buttonClass, nextPollDelay, typedNameMatches } from "@mythicalos/ui-core/logic";
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Styles
|
|
50
|
+
|
|
51
|
+
`./styles.css` is the component stylesheet — the atom classes the logic above derives (buttons,
|
|
52
|
+
chips, status lines, banners, gauges, inputs/toggles/checkboxes, toasts, dialogs, empty states).
|
|
53
|
+
Serve it AFTER `@mythicalos/tokens`' stylesheet; every value resolves through a `--my-*` custom
|
|
54
|
+
property.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import "@mythicalos/ui-core/styles.css";
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## `<mythical-select>`
|
|
61
|
+
|
|
62
|
+
A form-associated, native-parity `<select>` web component — vanilla custom elements
|
|
63
|
+
(`<mythical-select>`, `<mythical-option>`, `<mythical-optgroup>`), no framework
|
|
64
|
+
runtime, which is why it lives in core rather than in a Preact/React binding.
|
|
65
|
+
Import it once (a registration side effect) to define the elements:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import "@mythicalos/ui-core/select";
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
TypeScript consumers get the element's ambient DOM typings (`MythicalSelectElement`,
|
|
72
|
+
`HTMLElementTagNameMap` augmentation, …) via the same import path's `types` condition.
|
|
73
|
+
|
|
74
|
+
The component ships a 354-test cross-engine Playwright parity suite (Chromium,
|
|
75
|
+
Firefox, WebKit) covering the ARIA tree, selection/keyboard/typeahead, forms and
|
|
76
|
+
validity, the wrapped-native contract, a strict-CSP fixture, and the
|
|
77
|
+
no-`ElementInternals` fallback. Run it with:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
bun run test:select
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This is separate from `bun test` (the unit suite) on purpose — Playwright's `test`/
|
|
84
|
+
`expect` are not bun:test's, and `test/select/**` is excluded from bun's own test
|
|
85
|
+
discovery (see `bunfig.toml`).
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { buttonClass, type BtnVariant, type BtnState } from "./logic/button.js";
|
|
2
|
+
export { nextPollDelay, makePollEpochGuard, runPollTick, shouldResetEpoch, POLL_JITTER_RATIO, POLL_BACKOFF_CAP_MS, type PollResult, type PollEpochGuard, type PollTickIO, } from "./logic/poll.js";
|
|
3
|
+
export { typedNameMatches, BULLET_ICON, type DialogBullet } from "./logic/dialog.js";
|
|
4
|
+
export { composeToastText, TOAST_SEP, type ToastStatus, type ToastSpec, type ToastBus, } from "./logic/toast.js";
|
|
5
|
+
export { gaugeTone, gaugeGeom, type GaugeGeom } from "./logic/gauge.js";
|
|
6
|
+
export { chipClass, statusLineClass, bannerClass, BANNER_ICON, type Tone, type ChipTone, type StatusTone, type BannerTone, } from "./logic/tone.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @mythicalos/ui-core — barrel. The framework-agnostic core: pure logic + types only, ZERO
|
|
2
|
+
// `preact`/`react` imports (enforced by test/agnostic.test.ts). Both the Preact and React bindings
|
|
3
|
+
// import from here so they derive identical classes/behavior from one source.
|
|
4
|
+
export { buttonClass } from "./logic/button.js";
|
|
5
|
+
export { nextPollDelay, makePollEpochGuard, runPollTick, shouldResetEpoch, POLL_JITTER_RATIO, POLL_BACKOFF_CAP_MS, } from "./logic/poll.js";
|
|
6
|
+
export { typedNameMatches, BULLET_ICON } from "./logic/dialog.js";
|
|
7
|
+
export { composeToastText, TOAST_SEP, } from "./logic/toast.js";
|
|
8
|
+
export { gaugeTone, gaugeGeom } from "./logic/gauge.js";
|
|
9
|
+
export { chipClass, statusLineClass, bannerClass, BANNER_ICON, } from "./logic/tone.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type BtnVariant = "pri" | "acc" | "sec" | "gho" | "dan";
|
|
2
|
+
export interface BtnState {
|
|
3
|
+
loading?: boolean;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
/** Accepted for source-parity with the internal origin surface; currently a no-op — no `.btn--block` selector ships. */
|
|
6
|
+
block?: boolean;
|
|
7
|
+
small?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Compose the button class list (ds/components-buttons). Loading implies inert (disabled). */
|
|
10
|
+
export declare function buttonClass(variant: BtnVariant, s?: BtnState): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @mythicalos/ui-core — PURE, DOM-free button-class derivation (design book ds/components-buttons).
|
|
2
|
+
// Ported verbatim (name + signature identical) from the family's internal Preact atoms package (derive.ts)
|
|
3
|
+
// so the Preact and React bindings both derive the same class string from one source.
|
|
4
|
+
/** Compose the button class list (ds/components-buttons). Loading implies inert (disabled). */
|
|
5
|
+
export function buttonClass(variant, s = {}) {
|
|
6
|
+
const cls = ["btn", `btn--${variant}`];
|
|
7
|
+
if (s.small)
|
|
8
|
+
cls.push("btn--sm");
|
|
9
|
+
if (s.disabled || s.loading)
|
|
10
|
+
cls.push("is-disabled");
|
|
11
|
+
return cls.join(" ");
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Tone } from "./tone.js";
|
|
2
|
+
export interface DialogBullet {
|
|
3
|
+
tone: Tone;
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const BULLET_ICON: Record<DialogBullet["tone"], string>;
|
|
7
|
+
/** The pure typed-name gate: without a required name the confirm is always enabled; with one,
|
|
8
|
+
* only the exact (whitespace-trimmed, case-sensitive) match enables the danger action. */
|
|
9
|
+
export declare function typedNameMatches(requireName: string | undefined, typed: string): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @mythicalos/ui-core — the pure, DOM-free confirm-dialog helpers (ds/components-dialogs). Ported
|
|
2
|
+
// verbatim (names + signatures identical) from the family's internal Preact atoms package (ConfirmDialog.tsx).
|
|
3
|
+
// The `ConfirmDialog`/`Scrim` renderers stay in the framework bindings; this module keeps only the
|
|
4
|
+
// prop-shape types and the typed-name-match gate that drives them.
|
|
5
|
+
export const BULLET_ICON = { ok: "✓", warn: "▲", error: "⬤" };
|
|
6
|
+
/** The pure typed-name gate: without a required name the confirm is always enabled; with one,
|
|
7
|
+
* only the exact (whitespace-trimmed, case-sensitive) match enables the danger action. */
|
|
8
|
+
export function typedNameMatches(requireName, typed) {
|
|
9
|
+
if (requireName === undefined)
|
|
10
|
+
return true;
|
|
11
|
+
return typed.trim() === requireName;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Tone } from "./tone.js";
|
|
2
|
+
/** Fill color steps by threshold per token rule #4: ok/accent < 75%, warn 75–89%, error ≥ 90%. */
|
|
3
|
+
export declare function gaugeTone(pct: number): Tone;
|
|
4
|
+
export interface GaugeGeom {
|
|
5
|
+
/** The circle radius, inset by half the stroke width. */
|
|
6
|
+
r: number;
|
|
7
|
+
/** The full circumference — the SVG circle's `stroke-dasharray`. */
|
|
8
|
+
circ: number;
|
|
9
|
+
/** The `stroke-dashoffset` for the filled arc at `pct` (0 ⇒ full circle drawn, `circ` ⇒ none). */
|
|
10
|
+
offset: number;
|
|
11
|
+
}
|
|
12
|
+
/** Pure SVG geometry (no inline CSS) — the stroke color is a class, the arc is a dash attribute. */
|
|
13
|
+
export declare function gaugeGeom(size: number, stroke: number, pct: number): GaugeGeom;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @mythicalos/ui-core — the pure circular-gauge math (context/usage gauge). Extracted from
|
|
2
|
+
// design-export's packages/preact-ui/src/components/Gauge.jsx, which mixed this geometry into a
|
|
3
|
+
// Preact `h()` render. `pct` is clamped to 0–100 before either the tone or the arc offset is
|
|
4
|
+
// derived, matching the source's `clamped` value — both functions clamp independently so either
|
|
5
|
+
// can be called on its own with an out-of-range input and stay consistent with the other.
|
|
6
|
+
/** Fill color steps by threshold per token rule #4: ok/accent < 75%, warn 75–89%, error ≥ 90%. */
|
|
7
|
+
export function gaugeTone(pct) {
|
|
8
|
+
const clamped = Math.max(0, Math.min(100, pct));
|
|
9
|
+
return clamped >= 90 ? "error" : clamped >= 75 ? "warn" : "ok";
|
|
10
|
+
}
|
|
11
|
+
/** Pure SVG geometry (no inline CSS) — the stroke color is a class, the arc is a dash attribute. */
|
|
12
|
+
export function gaugeGeom(size, stroke, pct) {
|
|
13
|
+
const r = (size - stroke) / 2;
|
|
14
|
+
const circ = 2 * Math.PI * r;
|
|
15
|
+
const clamped = Math.max(0, Math.min(100, pct));
|
|
16
|
+
const offset = circ * (1 - clamped / 100);
|
|
17
|
+
return { r, circ, offset };
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** U7 policy constants: every delay is jittered ±20%; the failure-backoff ladder tops out at 60 s. */
|
|
2
|
+
export declare const POLL_JITTER_RATIO = 0.2;
|
|
3
|
+
export declare const POLL_BACKOFF_CAP_MS = 60000;
|
|
4
|
+
/**
|
|
5
|
+
* The U7 scheduling policy, pure + DOM-free: the next poll delay for a base cadence after
|
|
6
|
+
* `consecutiveFailures` failed reads in a row. ×2 per failure (capped at `capMs`), then ±`jitter`
|
|
7
|
+
* uniform jitter so many clients never phase-lock. `random` is injectable for deterministic tests
|
|
8
|
+
* (0.5 ⇒ no jitter; 0 ⇒ the −20% edge; 1 ⇒ the +20% edge). Success resets the caller's failure
|
|
9
|
+
* count to 0, which resets the ladder.
|
|
10
|
+
*/
|
|
11
|
+
export declare function nextPollDelay(baseMs: number, consecutiveFailures: number, random?: () => number, opts?: {
|
|
12
|
+
jitterRatio?: number;
|
|
13
|
+
capMs?: number;
|
|
14
|
+
}): number;
|
|
15
|
+
export interface PollResult<T> {
|
|
16
|
+
data: T | undefined;
|
|
17
|
+
error: string | undefined;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
/** Force an immediate re-fetch (e.g. a refresh affordance). */
|
|
20
|
+
refresh: () => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* diff r3-F1 — a MONOTONIC request-epoch guard, the usePoll analogue of ui/vm/selection.ts:
|
|
24
|
+
* the render-time epoch reset (§L2) clears retained data, but Preact runs effect CLEANUP after
|
|
25
|
+
* paint, so an in-flight response for the OLD entity resolving in that window still saw
|
|
26
|
+
* `alive === true` and repopulated the new entity's pane (surviving if the new read then failed).
|
|
27
|
+
* Every request is stamped with `current()` at FIRE time; its response `applies()` only while
|
|
28
|
+
* that token is still the live epoch. `invalidate()` opens a new epoch — called at the
|
|
29
|
+
* render-time reset (immediately, before any cleanup) and at effect teardown. Pure + DOM-free.
|
|
30
|
+
*/
|
|
31
|
+
export interface PollEpochGuard {
|
|
32
|
+
/** The token to stamp a request with at fire time. */
|
|
33
|
+
current(): number;
|
|
34
|
+
/** Open a new epoch — every token stamped before this no longer applies. */
|
|
35
|
+
invalidate(): void;
|
|
36
|
+
/** True while `token` is still the live epoch — apply a response ONLY under this. */
|
|
37
|
+
applies(token: number): boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function makePollEpochGuard(): PollEpochGuard;
|
|
40
|
+
/** The IO seams `runPollTick` drives — the hook wires these to its state setters/scheduler. */
|
|
41
|
+
export interface PollTickIO<T> {
|
|
42
|
+
fetch: () => Promise<T>;
|
|
43
|
+
guard: PollEpochGuard;
|
|
44
|
+
/** False once the owning effect's cleanup ran (unmount/dep change). */
|
|
45
|
+
isAlive: () => boolean;
|
|
46
|
+
/** U7 pause: a hidden document never fires a read. */
|
|
47
|
+
isHidden: () => boolean;
|
|
48
|
+
onSuccess: (value: T) => void;
|
|
49
|
+
onFailure: (message: string) => void;
|
|
50
|
+
/** Runs after every fired read settles; `applied` is false when the response was dropped as stale/dead — a stale settle must not touch the new epoch's loading state. */
|
|
51
|
+
onSettled: (applied: boolean) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One poll tick with fire-time epoch stamping (diff r3-F1): the epoch token is captured BEFORE
|
|
55
|
+
* the read starts and the response applies only if it still matches when the read settles —
|
|
56
|
+
* `alive` alone cannot cover the render-to-cleanup window. Extracted pure so the stale-orderings
|
|
57
|
+
* are deterministically testable DOM-free; `usePoll` routes every response through here (pinned
|
|
58
|
+
* by a source scan in the Preact binding's tests).
|
|
59
|
+
*/
|
|
60
|
+
export declare function runPollTick<T>(io: PollTickIO<T>): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* §L2 — should an epoch-guarded poll RESET (clear retained data+error, restart loading) this render?
|
|
63
|
+
* True only when the caller opted into epoch tracking (`useEpoch`) AND either the `epochKey` changed
|
|
64
|
+
* or `enabled` transitioned false→true — both start a NEW epoch whose first read hasn't settled, so
|
|
65
|
+
* the prior epoch's retained data/error must not render as ready/failed for it. Legacy callers (no
|
|
66
|
+
* `epochKey` option) NEVER reset — the retain-across-toggle/dep-change behavior is unchanged.
|
|
67
|
+
* Pure + DOM-free.
|
|
68
|
+
*/
|
|
69
|
+
export declare function shouldResetEpoch(useEpoch: boolean, prev: {
|
|
70
|
+
key: unknown;
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
}, key: unknown, enabled: boolean): boolean;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @mythicalos/ui-core — the pure, DOM-free U7 polling policy math + fire-time epoch guard. Ported
|
|
2
|
+
// verbatim (names + signatures identical) from the family's internal Preact atoms package (hooks.ts).
|
|
3
|
+
// The Preact `usePoll`/`useInterval` hook wrappers stay in the Preact binding package — they import
|
|
4
|
+
// `preact/hooks`, which this package must never depend on. Everything here is the pure math those
|
|
5
|
+
// hooks are built on: per-call interval, ±20% jitter on every delay, exponential ×2 backoff on
|
|
6
|
+
// consecutive failures capped at 60 s (reset on success), and the fire-time epoch stamp (diff r3-F1)
|
|
7
|
+
// so a stale in-flight response for an old entity can never repaint a newer one's pane.
|
|
8
|
+
/** U7 policy constants: every delay is jittered ±20%; the failure-backoff ladder tops out at 60 s. */
|
|
9
|
+
export const POLL_JITTER_RATIO = 0.2;
|
|
10
|
+
export const POLL_BACKOFF_CAP_MS = 60_000;
|
|
11
|
+
/**
|
|
12
|
+
* The U7 scheduling policy, pure + DOM-free: the next poll delay for a base cadence after
|
|
13
|
+
* `consecutiveFailures` failed reads in a row. ×2 per failure (capped at `capMs`), then ±`jitter`
|
|
14
|
+
* uniform jitter so many clients never phase-lock. `random` is injectable for deterministic tests
|
|
15
|
+
* (0.5 ⇒ no jitter; 0 ⇒ the −20% edge; 1 ⇒ the +20% edge). Success resets the caller's failure
|
|
16
|
+
* count to 0, which resets the ladder.
|
|
17
|
+
*/
|
|
18
|
+
export function nextPollDelay(baseMs, consecutiveFailures, random = Math.random, opts = {}) {
|
|
19
|
+
const cap = opts.capMs ?? POLL_BACKOFF_CAP_MS;
|
|
20
|
+
const jitterRatio = opts.jitterRatio ?? POLL_JITTER_RATIO;
|
|
21
|
+
const backed = Math.min(baseMs * 2 ** Math.max(0, consecutiveFailures), cap);
|
|
22
|
+
const jitter = 1 + (random() * 2 - 1) * jitterRatio;
|
|
23
|
+
return Math.round(backed * jitter);
|
|
24
|
+
}
|
|
25
|
+
export function makePollEpochGuard() {
|
|
26
|
+
let epoch = 0;
|
|
27
|
+
return {
|
|
28
|
+
current: () => epoch,
|
|
29
|
+
invalidate: () => {
|
|
30
|
+
epoch += 1;
|
|
31
|
+
},
|
|
32
|
+
applies: (token) => token === epoch,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One poll tick with fire-time epoch stamping (diff r3-F1): the epoch token is captured BEFORE
|
|
37
|
+
* the read starts and the response applies only if it still matches when the read settles —
|
|
38
|
+
* `alive` alone cannot cover the render-to-cleanup window. Extracted pure so the stale-orderings
|
|
39
|
+
* are deterministically testable DOM-free; `usePoll` routes every response through here (pinned
|
|
40
|
+
* by a source scan in the Preact binding's tests).
|
|
41
|
+
*/
|
|
42
|
+
export async function runPollTick(io) {
|
|
43
|
+
if (!io.isAlive())
|
|
44
|
+
return;
|
|
45
|
+
if (io.isHidden())
|
|
46
|
+
return; // paused — the visibilitychange handler rearms
|
|
47
|
+
const token = io.guard.current(); // fire-time stamp (r3-F1)
|
|
48
|
+
let applied = false;
|
|
49
|
+
try {
|
|
50
|
+
const v = await io.fetch();
|
|
51
|
+
if (!io.isAlive() || !io.guard.applies(token))
|
|
52
|
+
return; // stale/dead — drop
|
|
53
|
+
applied = true;
|
|
54
|
+
io.onSuccess(v);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (!io.isAlive() || !io.guard.applies(token))
|
|
58
|
+
return; // a superseded failure never paints either
|
|
59
|
+
applied = true;
|
|
60
|
+
io.onFailure(e instanceof Error ? e.message : String(e));
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
io.onSettled(applied);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* §L2 — should an epoch-guarded poll RESET (clear retained data+error, restart loading) this render?
|
|
68
|
+
* True only when the caller opted into epoch tracking (`useEpoch`) AND either the `epochKey` changed
|
|
69
|
+
* or `enabled` transitioned false→true — both start a NEW epoch whose first read hasn't settled, so
|
|
70
|
+
* the prior epoch's retained data/error must not render as ready/failed for it. Legacy callers (no
|
|
71
|
+
* `epochKey` option) NEVER reset — the retain-across-toggle/dep-change behavior is unchanged.
|
|
72
|
+
* Pure + DOM-free.
|
|
73
|
+
*/
|
|
74
|
+
export function shouldResetEpoch(useEpoch, prev, key, enabled) {
|
|
75
|
+
if (!useEpoch)
|
|
76
|
+
return false;
|
|
77
|
+
if (prev.key !== key)
|
|
78
|
+
return true;
|
|
79
|
+
return enabled && !prev.enabled;
|
|
80
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ToastStatus = "ok" | "warn" | "error" | "info";
|
|
2
|
+
export interface ToastSpec {
|
|
3
|
+
status: ToastStatus;
|
|
4
|
+
title: string;
|
|
5
|
+
body?: string;
|
|
6
|
+
action?: {
|
|
7
|
+
label: string;
|
|
8
|
+
onAction: () => void;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface ToastBus {
|
|
12
|
+
push: (t: ToastSpec) => void;
|
|
13
|
+
}
|
|
14
|
+
/** The separator the toast places between its bold title and its body. */
|
|
15
|
+
export declare const TOAST_SEP = " \u2014 ";
|
|
16
|
+
/** The toast's composed VISIBLE text: the title, then the separator + body when a body is present.
|
|
17
|
+
* Mirrors the render in the binding package (bold title notwithstanding) so callers can assert the
|
|
18
|
+
* exact rendered string without a DOM — and so a body that already repeats the title (the doubled-
|
|
19
|
+
* prefix bug) is caught by a test. Keep this and the binding's JSX in lockstep. */
|
|
20
|
+
export declare function composeToastText(title: string, body?: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @mythicalos/ui-core — the pure toast types + text-composition helper (ds/components-toasts).
|
|
2
|
+
// Ported from the family's internal Preact atoms package (toast-context.ts) (the `ToastStatus`/`ToastSpec`/
|
|
3
|
+
// `ToastBus` types) and src/Toast.tsx (`composeToastText`/`TOAST_SEP`). The `ToastContext`/`useToast`
|
|
4
|
+
// bus wiring (createContext/useContext) and the `Toast`/`ToastProvider` renderers are Preact-bound
|
|
5
|
+
// and stay in the Preact binding package — this package must never import `preact`.
|
|
6
|
+
/** The separator the toast places between its bold title and its body. */
|
|
7
|
+
export const TOAST_SEP = " — ";
|
|
8
|
+
/** The toast's composed VISIBLE text: the title, then the separator + body when a body is present.
|
|
9
|
+
* Mirrors the render in the binding package (bold title notwithstanding) so callers can assert the
|
|
10
|
+
* exact rendered string without a DOM — and so a body that already repeats the title (the doubled-
|
|
11
|
+
* prefix bug) is caught by a test. Keep this and the binding's JSX in lockstep. */
|
|
12
|
+
export function composeToastText(title, body) {
|
|
13
|
+
return body ? `${title}${TOAST_SEP}${body}` : title;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Tone = "ok" | "warn" | "error";
|
|
2
|
+
export type ChipTone = "neutral" | "accent" | "ok" | "warn" | "error" | "info";
|
|
3
|
+
export declare function chipClass(tone: ChipTone): string;
|
|
4
|
+
export type StatusTone = "ok" | "warn" | "error" | "info" | "muted" | "accent";
|
|
5
|
+
export declare function statusLineClass(tone: StatusTone): string;
|
|
6
|
+
export type BannerTone = "warn" | "info" | "ok" | "error";
|
|
7
|
+
export declare const BANNER_ICON: Record<BannerTone, string>;
|
|
8
|
+
export declare function bannerClass(tone: BannerTone): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @mythicalos/ui-core — tone axis and class derivation for chip/status/banner + shared gauge/dialog
|
|
2
|
+
// tri-state (ds/tokens rule #4 and rule #7: status never relies on color alone — an icon/glyph
|
|
3
|
+
// always rides along). Both the Preact and React bindings import from here so they derive identical
|
|
4
|
+
// class strings from one source.
|
|
5
|
+
export function chipClass(tone) {
|
|
6
|
+
return tone === "neutral" ? "my-chip" : `my-chip my-chip--${tone}`;
|
|
7
|
+
}
|
|
8
|
+
export function statusLineClass(tone) {
|
|
9
|
+
return `my-status my-status--${tone}`;
|
|
10
|
+
}
|
|
11
|
+
export const BANNER_ICON = {
|
|
12
|
+
warn: "▲",
|
|
13
|
+
info: "ℹ",
|
|
14
|
+
ok: "✓",
|
|
15
|
+
error: "✕",
|
|
16
|
+
};
|
|
17
|
+
export function bannerClass(tone) {
|
|
18
|
+
return `my-banner my-banner--${tone}`;
|
|
19
|
+
}
|