athena-ui-js 2.0.1 → 2.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 (30) hide show
  1. package/README.md +58 -4
  2. package/docs/migration-2.0.md +1 -1
  3. package/docs/styling.md +24 -7
  4. package/package.json +5 -1
  5. package/src/athena-ui.js +2 -1
  6. package/src/libs/config/config.js +1 -1
  7. package/src/libs/core/motion.js +358 -0
  8. package/src/libs/core/popover.js +96 -0
  9. package/src/libs/core/theme.js +12 -0
  10. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +9 -5
  11. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +43 -2
  12. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +2 -1
  13. package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +3 -1
  14. package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +45 -9
  15. package/src/libs/hephaestus/router/router.js +18 -9
  16. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +25 -0
  17. package/src/motion.js +6 -0
  18. package/src/res/themes/default/style.css +260 -10
  19. package/src/res/themes/tokens.css +25 -0
  20. package/types/athena-ui.d.ts +97 -96
  21. package/types/libs/config/config.d.ts +3 -3
  22. package/types/libs/core/motion.d.ts +123 -0
  23. package/types/libs/core/popover.d.ts +36 -0
  24. package/types/libs/core/theme.d.ts +41 -39
  25. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +2 -0
  26. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +238 -222
  27. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +4 -1
  28. package/types/libs/hephaestus/router/router.d.ts +71 -67
  29. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +123 -120
  30. package/types/motion.d.ts +1 -0
@@ -0,0 +1,123 @@
1
+ /** Does the person want less motion? The choice made with setMotion wins over the setting of the system. */
2
+ export function prefersReducedMotion(): boolean;
3
+ /**
4
+ * Chooses how much motion there is: "system", "reduce" (none) or "full". It is put on <html> as data-motion, which the CSS tokens read (the durations
5
+ * become 0), and the functions of this module read it too.
6
+ */
7
+ export function setMotion(value: any): boolean;
8
+ /** Called with { preference, reduced } when setMotion changes it, and when the system setting changes. Returns a function that stops it. */
9
+ export function onMotionChange(listener: any): () => boolean;
10
+ /** A duration token as milliseconds: readDuration("--athena-duration-base") -> 200. 0 under reduced motion. */
11
+ export function readDuration(token?: string, element?: HTMLElement): number;
12
+ /** How long an element takes to finish its CSS transitions, delays included, in ms (0 when it has none, or under reduced motion). */
13
+ export function transitionTime(element: any): number;
14
+ /** Removes an element when its exit transition is over (at once when it has none, which is also what reduced motion gives). */
15
+ export function removeAfterTransition(element: any): void;
16
+ /**
17
+ * A spring as a CSS easing: simulates a damped spring and returns the points as a `linear()` easing (which can overshoot) and how long it takes.
18
+ * `element.animate(keyframes, { duration, easing })` then moves like a spring. Settles when it stays within `precision` of 1.
19
+ *
20
+ * @param {{stiffness?: number, damping?: number, mass?: number, precision?: number}} [options]
21
+ * @returns {{easing: string, duration: number}} duration in ms
22
+ */
23
+ export function spring({ stiffness, damping, mass, precision }?: {
24
+ stiffness?: number;
25
+ damping?: number;
26
+ mass?: number;
27
+ precision?: number;
28
+ }): {
29
+ easing: string;
30
+ duration: number;
31
+ };
32
+ /**
33
+ * Animates an element with the Web Animations API and resolves when it is over. Under reduced motion it does nothing and resolves at once.
34
+ * It resolves (never rejects) when the animation is cancelled, and `null` when there was none.
35
+ *
36
+ * @param {Element} element
37
+ * @param {Keyframe[]|PropertyIndexedKeyframes} keyframes e.g. [{ opacity: 0 }, { opacity: 1 }]
38
+ * @param {object} [options] the options of element.animate (duration, easing, delay, fill, ...), and
39
+ * @param {boolean} [options.commit=false] write the end state to the element's style when it is over (CSSOM: allowed by a strict policy)
40
+ * @param {AbortSignal} [options.signal] cancels the animation when aborted
41
+ * @returns {Promise<Animation|null>}
42
+ */
43
+ export function animate(element: Element, keyframes: Keyframe[] | PropertyIndexedKeyframes, options?: {
44
+ commit?: boolean;
45
+ signal?: AbortSignal;
46
+ }): Promise<Animation | null>;
47
+ /** Fades an element out and removes it. Under reduced motion it is removed at once. */
48
+ export function fadeOut(element: any, options: any): Promise<void>;
49
+ /**
50
+ * A change that is done with CSS (a class, an attribute) and has a CSS transition: runs `change()` and resolves when the element's transition is over.
51
+ * It waits at most the length of the transition (plus a little), so a transition that never ends does not hang anything.
52
+ */
53
+ export function transition(element: any, change: any): Promise<any>;
54
+ /** Runs the functions one after the other, each when the one before is over. Resolves with their results. */
55
+ export function sequence(steps: any): Promise<any[]>;
56
+ /**
57
+ * The delays of a staggered animation: `count` items, `step` ms apart, starting from "start", "end" or "center".
58
+ * @returns {number[]}
59
+ */
60
+ export function staggerDelays(count: any, step?: number, from?: string): number[];
61
+ /**
62
+ * Calls `run(item, index, delay)` for every item with its delay, and resolves when all are over: `stagger(rows, (row, i, delay) => fadeIn(row, { delay }))`.
63
+ * No more than `limit` items are staggered (the rest run with the last delay), so a long list does not take long.
64
+ */
65
+ export function stagger(items: any, run: any, { step, from, limit }?: {
66
+ step?: number;
67
+ from?: string;
68
+ limit?: number;
69
+ }): Promise<any[]>;
70
+ /**
71
+ * Lets the children of a container move smoothly when `change()` rearranges them (sorting, filtering, inserting, removing): First (measure), Last (do the change,
72
+ * measure), Invert and Play (each child that moved starts at its old place and slides to the new one). New children fade in. Under reduced motion `change()` is
73
+ * just done.
74
+ *
75
+ * @param {Element} container its children are what moves
76
+ * @param {() => void} change rearranges the children (synchronously)
77
+ * @param {object} [options]
78
+ * @param {(element: Element) => *} [options.key] what makes a child "the same" before and after, default: the element itself
79
+ * @param {number} [options.limit=60] at most this many children are animated (a long list does not need it, and costs time)
80
+ * @param {number} [options.duration] ms, default the token --athena-duration-base
81
+ * @returns {Promise<void>} resolves when the animations are over
82
+ */
83
+ export function flip(container: Element, change: () => void, { key, limit, duration }?: {
84
+ key?: (element: Element) => any;
85
+ limit?: number;
86
+ duration?: number;
87
+ }): Promise<void>;
88
+ /**
89
+ * Changes numbers over time with requestAnimationFrame: tween({ from: 0, to: 100, duration: 500, easing: easings.easeOutCubic, onUpdate: v => ... }).
90
+ * `from` and `to` can be numbers, or objects with the same keys ({ x: 0, y: 0 } to { x: 10, y: 5 }); onUpdate then gets an object.
91
+ * Under reduced motion it jumps to the end (one onUpdate call). It runs on animation frames; in a page that is not drawn a timer keeps it going slowly, so it still ends.
92
+ *
93
+ * @returns {Promise<void> & {cancel: () => void}} resolves when it is over (also when cancelled)
94
+ */
95
+ export function tween({ from, to, duration, easing, onUpdate, delay }?: {
96
+ from?: number;
97
+ to?: number;
98
+ duration?: number;
99
+ easing?: (t: any) => number;
100
+ delay?: number;
101
+ }): Promise<void> & {
102
+ cancel: () => void;
103
+ };
104
+ /**
105
+ * Runs `update()` (which changes the DOM) as a view transition when the browser can and motion is wanted: the old and the new state cross-fade
106
+ * (or whatever the CSS ::view-transition-* rules say). Elements with a `view-transition-name` move from one place to the other. Without the API,
107
+ * or under reduced motion, `update()` is just run. Resolves when it is over.
108
+ */
109
+ export function viewTransition(update: any): Promise<void>;
110
+ export function getMotion(): "reduce" | "full" | "system";
111
+ export namespace easings {
112
+ function linear(t: any): any;
113
+ function easeInQuad(t: any): number;
114
+ function easeOutQuad(t: any): number;
115
+ function easeInOutQuad(t: any): number;
116
+ function easeInCubic(t: any): number;
117
+ function easeOutCubic(t: any): number;
118
+ function easeInOutCubic(t: any): number;
119
+ function easeOutBack(t: any): number;
120
+ function easeOutElastic(t: any): any;
121
+ }
122
+ export function fadeIn(element: any, options: any): Promise<Animation>;
123
+ export function parallel(steps: any): Promise<any[]>;
@@ -0,0 +1,36 @@
1
+ /** Opens it: showPopover(), or without the API: the element is no longer hidden. Does nothing when it is open already. */
2
+ export function openPopover(element: any): void;
3
+ /** Closes it. Does nothing when it is closed already. */
4
+ export function closePopover(element: any): void;
5
+ /**
6
+ * Where a popover goes, next to the element it belongs to, before it is shown (so there is no frame at the wrong place). Only the side and the alignment
7
+ * are chosen here, from the position of the anchor in the window: the popover is moved with CSS (translate) by its own size. Once it is shown,
8
+ * `settlePopover` measures it and keeps it inside the window.
9
+ *
10
+ * @param {Element} anchor the button or the target of the tooltip
11
+ * @param {HTMLElement} popover
12
+ * @param {object} [options]
13
+ * @param {"bottom"|"top"|"auto"} [options.side="auto"] "bottom": below. "top": above, unless there is less than `room` px above. "auto": below,
14
+ * unless there is less than `room` px below and more room above
15
+ * @param {"start"|"end"|"center"} [options.align="start"] which edge of the anchor the popover lines up with
16
+ * @param {number} [options.gap=4] px between the anchor and the popover
17
+ * @param {number} [options.room=240] how much room a side needs, in px (a tooltip needs about 40)
18
+ */
19
+ export function placePopover(anchor: Element, popover: HTMLElement, { side, align, gap, room }?: {
20
+ side?: "bottom" | "top" | "auto";
21
+ align?: "start" | "end" | "center";
22
+ gap?: number;
23
+ room?: number;
24
+ }): void;
25
+ /**
26
+ * After the popover is shown: measures it and moves it back inside the window when it sticks out to the left, the right or the bottom (a popover that
27
+ * is taller than the room is left where it is: it scrolls).
28
+ */
29
+ export function settlePopover(popover: any): void;
30
+ /**
31
+ * Keeps an open popover next to its anchor while the page scrolls or the window changes size. Returns a function that stops it.
32
+ * (A popover in the top layer does not move with its anchor by itself.)
33
+ */
34
+ export function followAnchor(anchor: any, popover: any, options: any): () => void;
35
+ export function supportsPopover(): boolean;
36
+ export function isOpen(element: any): any;
@@ -1,39 +1,41 @@
1
- /**
2
- * @param {object} options
3
- * @param {{id: string, name?: string, description?: string}[]} options.themes the first one is the default
4
- * @param {{id: string, name?: string}[]} [options.modes] default: system, light, dark. Ids "light" and "dark" are the ones that can be resolved
5
- * @param {string} [options.storageKey="athena.appearance"] localStorage key (also give it to theme-boot.js)
6
- * @param {string} [options.themeColorVariable] CSS variable whose value becomes <meta name="theme-color"> (the bar of a phone browser)
7
- * @param {HTMLElement} [options.root] element that gets the attributes (default: <html>)
8
- * @param {Storage} [options.storage] default: localStorage
9
- * @returns {{themes, modes, appearance: () => object, setTheme: (id) => boolean, setMode: (id) => boolean,
10
- * onChange: (listener) => Function, refresh: Function, destroy: Function}}
11
- */
12
- export function createThemeManager(options?: {
13
- themes: {
14
- id: string;
15
- name?: string;
16
- description?: string;
17
- }[];
18
- modes?: {
19
- id: string;
20
- name?: string;
21
- }[];
22
- storageKey?: string;
23
- themeColorVariable?: string;
24
- root?: HTMLElement;
25
- storage?: Storage;
26
- }): {
27
- themes: any;
28
- modes: any;
29
- appearance: () => object;
30
- setTheme: (id: any) => boolean;
31
- setMode: (id: any) => boolean;
32
- onChange: (listener: any) => Function;
33
- refresh: Function;
34
- destroy: Function;
35
- };
36
- export const DEFAULT_MODES: {
37
- id: string;
38
- name: string;
39
- }[];
1
+ /**
2
+ * @param {object} options
3
+ * @param {{id: string, name?: string, description?: string}[]} options.themes the first one is the default
4
+ * @param {{id: string, name?: string}[]} [options.modes] default: system, light, dark. Ids "light" and "dark" are the ones that can be resolved
5
+ * @param {string} [options.storageKey="athena.appearance"] localStorage key (also give it to theme-boot.js)
6
+ * @param {string} [options.themeColorVariable] CSS variable whose value becomes <meta name="theme-color"> (the bar of a phone browser)
7
+ * @param {HTMLElement} [options.root] element that gets the attributes (default: <html>)
8
+ * @param {Storage} [options.storage] default: localStorage
9
+ * @param {boolean} [options.transition=true] colours cross-fade when the theme or the mode changes (not under reduced motion)
10
+ * @returns {{themes, modes, appearance: () => object, setTheme: (id) => boolean, setMode: (id) => boolean,
11
+ * onChange: (listener) => Function, refresh: Function, destroy: Function}}
12
+ */
13
+ export function createThemeManager(options?: {
14
+ themes: {
15
+ id: string;
16
+ name?: string;
17
+ description?: string;
18
+ }[];
19
+ modes?: {
20
+ id: string;
21
+ name?: string;
22
+ }[];
23
+ storageKey?: string;
24
+ themeColorVariable?: string;
25
+ root?: HTMLElement;
26
+ storage?: Storage;
27
+ transition?: boolean;
28
+ }): {
29
+ themes: any;
30
+ modes: any;
31
+ appearance: () => object;
32
+ setTheme: (id: any) => boolean;
33
+ setMode: (id: any) => boolean;
34
+ onChange: (listener: any) => Function;
35
+ refresh: Function;
36
+ destroy: Function;
37
+ };
38
+ export const DEFAULT_MODES: {
39
+ id: string;
40
+ name: string;
41
+ }[];
@@ -33,6 +33,7 @@ export function decimate(indices: any, values: any, buckets: any): any;
33
33
  * @param {(range: ({from: number, to: number}|null)) => void} [options.onZoom] called when a person zooms or resets
34
34
  * @param {number} [options.maxPoints] `push` keeps at most this many points per series (the oldest are dropped)
35
35
  * @param {number[]} [options.hiddenSeries] the series (or slices) that are hidden at the start; a person hides and shows them with the legend, and a redraw keeps that
36
+ * @param {boolean} [options.animate=true] the first drawing animates: bars grow, a line is drawn, slices pop in (not when it is redrawn, and not under reduced motion)
36
37
  * @param {boolean} [options.interactive=true] line and area charts: false leaves out the pointer layer (tooltip that follows the pointer, zoom)
37
38
  * @returns {(SVGElement & {element: SVGElement, update: (options?: object) => SVGElement, destroy: () => void,
38
39
  * zoom: (from: number, to: number) => void, resetZoom: () => void, getZoom: () => ({from: number, to: number}|null),
@@ -71,6 +72,7 @@ export function generateChart(options?: {
71
72
  } | null)) => void;
72
73
  maxPoints?: number;
73
74
  hiddenSeries?: number[];
75
+ animate?: boolean;
74
76
  interactive?: boolean;
75
77
  }): (SVGElement & {
76
78
  element: SVGElement;