athena-ui-js 2.1.0 → 2.3.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 (33) hide show
  1. package/README.md +81 -3
  2. package/docs/styling.md +21 -6
  3. package/package.json +9 -1
  4. package/src/athena-ui.js +4 -1
  5. package/src/libs/config/config.js +1 -1
  6. package/src/libs/core/gridLayout.js +102 -0
  7. package/src/libs/core/i18n.js +32 -0
  8. package/src/libs/core/motion.js +358 -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 +17 -0
  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/router/router.js +18 -9
  15. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +25 -0
  16. package/src/motion.js +6 -0
  17. package/src/res/themes/default/style.css +413 -10
  18. package/src/res/themes/tokens.css +25 -0
  19. package/src/widgets.js +7 -0
  20. package/types/athena-ui.d.ts +99 -96
  21. package/types/libs/config/config.d.ts +3 -3
  22. package/types/libs/core/gridLayout.d.ts +45 -0
  23. package/types/libs/core/motion.d.ts +123 -0
  24. package/types/libs/core/popover.d.ts +36 -36
  25. package/types/libs/core/theme.d.ts +2 -0
  26. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +2 -0
  27. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +238 -224
  28. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +153 -153
  29. package/types/libs/hephaestus/router/router.d.ts +4 -0
  30. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +3 -0
  31. package/types/libs/hephaestus/widgetGrid/widgetGrid.d.ts +117 -0
  32. package/types/motion.d.ts +1 -0
  33. package/types/widgets.d.ts +2 -0
package/README.md CHANGED
@@ -5,7 +5,7 @@ layout (header, menu, content wrapper, footer) from a single `init()` call, load
5
5
  and theme, and ships the building blocks of a multipurpose application: forms, tables, charts,
6
6
  feedback, navigation, a router and more.
7
7
 
8
- Current version: **2.1.0**
8
+ Current version: **2.3.0**
9
9
 
10
10
  [Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
11
11
 
@@ -67,7 +67,7 @@ import { generateTable } from "athena-ui-js/table"; // or only what you u
67
67
  ```
68
68
 
69
69
  The entry points are `table`, `chart`, `dialog`, `menu`, `navigation`, `forms`, `feedback`, `components`, `inputs`, `router`, `session`, `theme`, `i18n`, `format`,
70
- `validation`, `sanitize`, `csv`, `dom` and `controls`. TypeScript definitions are included (`types/`, generated from the JSDoc with `npm run types`).
70
+ `validation`, `motion`, `widgets`, `sanitize`, `csv`, `dom` and `controls`. TypeScript definitions are included (`types/`, generated from the JSDoc with `npm run types`).
71
71
  The package has `"sideEffects"` for `classic.js`, `theme-boot.js` and CSS only, so a bundler drops everything you do not import.
72
72
 
73
73
  Without npm, serve the `src` folder with any static web server and open `index.html` to see the example.
@@ -149,7 +149,7 @@ It takes the options of `init()`. The header and footer follow the settings `gen
149
149
  | `header_title_text` | `"Athena UI"` | Title in the header |
150
150
  | `header_img_url` | | Header logo URL |
151
151
  | `copyright` | placeholder text | Footer text, the version is appended |
152
- | `version` | `"2.1.0"` | Version shown in the footer |
152
+ | `version` | `"2.3.0"` | Version shown in the footer |
153
153
  | `bordered` | `true` | Draw a border around the layout blocks |
154
154
  | `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
155
155
  | `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
@@ -194,6 +194,8 @@ Everything is exported from `athena-ui.js`:
194
194
  | `generatePageHeader`, `generateFacts`, `generateEmptyState`, `generateLoading`, `copyToClipboard` | See [Page parts and formatting](#page-parts-and-formatting) |
195
195
  | `formatBytes`, `formatNumber`, `formatDuration`, `formatRelativeTime`, `formatDate` | Format helpers on top of `Intl`, in the current language |
196
196
  | `el`, `setContent`, `resolveElement`, `asHandle`, `createSafeBuilder` | See [Safe DOM building](#safe-dom-building) |
197
+ | `animate`, `flip`, `stagger`, `spring`, `tween`, `transition`, `viewTransition`, `setMotion`, `prefersReducedMotion`, `easings`, `generateSkeleton` | See [Motion](#motion-animations-and-transitions) |
198
+ | `registerWidget`, `createWidgetGrid`, `getWidgetTypes`, `placeItem`, `compact`, `findFreeSpot`, `normalize` | See [Widgets](#widgets-a-dashboard-that-can-be-built) |
197
199
  | `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
198
200
  | `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | See [Inputs](#inputs) |
199
201
  | `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
@@ -658,6 +660,82 @@ await copyToClipboard(token); // an
658
660
  formatBytes(1536); formatNumber(1234567.891); formatDuration(7500000); formatRelativeTime(date); formatDate(date, { time: true }); // Intl, in the current language
659
661
  ```
660
662
 
663
+ ### Motion: animations and transitions
664
+
665
+ Motion is an enhancement. Every transition and animation of Athena UI reads the tokens `--athena-duration-fast` (120 ms), `--athena-duration-base` (200 ms) and `--athena-duration-slow` (360 ms),
666
+ and `--athena-ease-standard`, `-in`, `-out` and `-spring`, so one variable slows down or switches off all of it. They are **0 under reduced motion**: when the system asks for it
667
+ (`prefers-reduced-motion`), or the person does (`data-motion="reduce"` on `<html>`, which `setMotion("reduce")` sets; `"full"` keeps the motion although the system asks for less).
668
+ Nothing waits for a transition before it works, and nothing needs an inline style (a strict Content-Security-Policy is fine: CSS classes, custom properties and the Web Animations API).
669
+
670
+ What the components do by themselves:
671
+ - a **dialog** fades and rises in and fades out; the **dropdown menu** and the **tooltip** fade; a **toast** slides in and out; an **accordion** opens smoothly;
672
+ a **progress bar** moves smoothly; a **skeleton** (`generateSkeleton`) shimmers;
673
+ - a **chart** draws itself the first time (bars grow, the line is drawn, slices pop in; `animate: false` turns it off, and it never replays while streaming or zooming);
674
+ - the **theme manager** cross-fades colours when the theme or the mode changes (`createThemeManager({ transition: false })` turns it off);
675
+ - a **table** with `animateRows: true` slides its rows to their new place when sorted, filtered or paged (at most 60 rows, not in a virtual table);
676
+ - the **router** with `transition: true` makes a page change a view transition (`document.startViewTransition`): the old page cross-fades into the new one, and elements with a
677
+ `view-transition-name` move from one page to the next. The old page stays until the page function of the new one has finished, so a page that needs long should draw something first.
678
+
679
+ `athena-ui-js/motion` has the same tools for your own code; all of them resolve at once under reduced motion:
680
+
681
+ ```js
682
+ import { animate, flip, stagger, spring, tween, easings, transition, viewTransition, setMotion, prefersReducedMotion } from "athena-ui-js/motion";
683
+
684
+ await animate(card, [{ opacity: 0, translate: "0 16px" }, { opacity: 1, translate: "0 0" }]); // the Web Animations API, with the tokens as defaults; resolves at the end
685
+ await flip(list, () => list.append(...sorted)); // rows slide from where they were to where they are; new ones fade in
686
+ await stagger(items, (item, index, delay) => animate(item, frames, { delay }), { step: 40 }); // one after the other
687
+ const { easing, duration } = spring({ stiffness: 220, damping: 12 }); // a spring as a CSS easing (linear()), it overshoots
688
+ await animate(ball, [{ translate: "0 0" }, { translate: "240px 0" }], { easing, duration });
689
+ tween({ from: 0, to: 100, duration: 600, easing: easings.easeOutCubic, onUpdate: value => counter.textContent = Math.round(value) }); // numbers over time (games, counters)
690
+ await transition(panel, () => panel.classList.add("open")); // a change made with CSS: resolves when its transition is over
691
+ await viewTransition(() => swapContent()); // cross-fades the change where the browser can
692
+ setMotion("reduce"); // "system" | "reduce" | "full"
693
+ ```
694
+
695
+ In a page that is not drawn (a hidden tab) there are no frames: `animate` and `tween` finish by a timer, so nothing hangs. Dialogs and toasts stay in the page for the length of their
696
+ exit transition (none under reduced motion); in your tests call `setMotion("reduce")` first, so they are gone at once.
697
+
698
+ ### Widgets: a dashboard that can be built
699
+
700
+ `athena-ui-js/widgets`: a grid of widgets that can be added, configured, moved, resized, locked, saved and loaded. No dependency, no drag library, no inline style.
701
+
702
+ ```js
703
+ import { registerWidget, createWidgetGrid } from "athena-ui-js/widgets";
704
+
705
+ // a type of widget: a function that draws into the body it is given, and cleans up after itself
706
+ registerWidget("clock", {
707
+ title: "Clock", defaultSize: { w: 3, h: 2 }, minSize: { w: 2, h: 1 }, defaultConfig: { seconds: true },
708
+ configForm: [{ name: "seconds", label: "Show seconds", type: "checkbox" }], // the settings dialog (showFormDialog)
709
+ render(context) { // called when the widget is first seen (IntersectionObserver)
710
+ const time = el("p");
711
+ context.element.append(time);
712
+ const show = () => time.textContent = new Date().toLocaleTimeString();
713
+ const timer = setInterval(show, 1000);
714
+ return { update: show, destroy: () => clearInterval(timer) }; // update(): config or title changed (throttled), destroy(): removed
715
+ }
716
+ });
717
+
718
+ const grid = createWidgetGrid({
719
+ element: "dashboard", columns: 12, rowHeight: 80, gap: 12, editable: true,
720
+ breakpoints: { wide: { minWidth: 900, columns: 12 }, narrow: { minWidth: 0, columns: 6 } }, // optional: a layout per width
721
+ widgets: [{ type: "clock", x: 0, y: 0 }],
722
+ onChange: (layout, reason) => localStorage.setItem("dashboard", JSON.stringify(layout)) // "move", "resize", "add", "remove", "settings", "undo", ...
723
+ });
724
+ grid.setLayout(JSON.parse(localStorage.getItem("dashboard"))); // plain, versioned JSON ({ version: 1, widgets: [...] })
725
+ ```
726
+
727
+ - **Layout** is CSS grid. The columns, the row height, the gap and the place of every widget are CSS classes written into a constructed style sheet, so a strict
728
+ Content-Security-Policy (no `style` attribute) is fine. Widgets fall upwards (`compact: false` keeps the gaps) and slide to their new places (not under reduced motion).
729
+ - **Edit mode** (`setEditable(true)`): drag by the handle, resize by any edge or corner, snap to cells, push other widgets out of the way. Settings, duplicate and remove buttons.
730
+ A **locked** widget (`lockWidget(id)`) is not moved, not resized, not pushed, and nothing can be put on it.
731
+ - **Keyboard**: focus the handle, Space or Enter picks the widget up, arrow keys move it, Shift with arrow keys resizes it, Enter drops it, Escape cancels. Every step is announced
732
+ in a live region ("Column 2, row 1, 3 wide, 2 high"). Pointer Events: mouse, pen and touch work the same.
733
+ - **Undo and redo** of every change (`undo()`, `redo()`, `canUndo()`); `updateWidget(id, { config })` is for data from code and is not an undo step.
734
+ - **Layouts** (`getLayout()` / `setLayout(json)`) are plain JSON and the application decides where they are stored. Loading is checked: a bad entry is skipped (reported in the result),
735
+ duplicate ids are replaced, places are clamped and made free of overlaps, `__proto__`-style keys are dropped, and a type that is not registered is shown as a placeholder (its data is kept, nothing is executed).
736
+ - **Performance**: a widget is rendered only when it is first seen, `resize(context, size)` is called throttled when its body changes size, and nothing re-renders while it is out of view.
737
+ - The grid maths (`placeItem`, `compact`, `findFreeSpot`, `normalize`, `collides`) is exported as well, for your own layouts.
738
+
661
739
  ### Safe DOM building
662
740
 
663
741
  `el(tag, { class, id, text, attrs, on, prop }, ...children)` is the way Athena builds its own pages, and it is exported. Strings are only ever inserted as **text**, children can be
package/docs/styling.md CHANGED
@@ -40,6 +40,13 @@ Start with the tokens, they cover most of what people want to change.
40
40
  | `--athena-dialog-medium` | `480px` |
41
41
  | `--athena-dialog-large` | `720px` |
42
42
  | `--athena-row-height` | `36px` |
43
+ | `--athena-duration-fast` | `120ms` |
44
+ | `--athena-duration-base` | `200ms` |
45
+ | `--athena-duration-slow` | `360ms` |
46
+ | `--athena-ease-standard` | `cubic-bezier(0.2, 0, 0, 1)` |
47
+ | `--athena-ease-in` | `cubic-bezier(0.4, 0, 1, 1)` |
48
+ | `--athena-ease-out` | `cubic-bezier(0, 0, 0.2, 1)` |
49
+ | `--athena-ease-spring` | `linear(0, 0.009, 0.035 2.1%, 0.141 4.4%, 0.723 12.9%, 0.938 16.7%, 1.017 19.4%, 1.077 22.8%, 1.121 26.7%, 1.149 31.2%, 1.159 36.2%, 1.138 49.9%, 1.115 56.3%, 1.043 69.7%, 1.009 81.2%, 0.998 92.1%, 1)` |
43
50
 
44
51
  Dark colours: set `data-mode="dark"` on `<html>` (or let `createThemeManager` do it); without the attribute the system decides. Themes: see `appearance.css`.
45
52
 
@@ -54,19 +61,19 @@ Dark colours: set `data-mode="dark"` on `<html>` (or let `createThemeManager` do
54
61
  | Modal close button | `.close` | `--athena-fg` `--athena-muted` |
55
62
  | Buttons | `.athena-button` `.button-danger` `.button-large` `.button-link` `.button-secondary` `.button-small` | `--athena-accent` `--athena-accent-fg` `--athena-danger` `--athena-fg` `--athena-line` `--athena-radius` `--athena-surface` |
56
63
  | Forms | `.athena-form` `.choice` `.choices` `.field` `.field-error` `.field-group` `.field-help` `.field-invalid` `.field-label` `.field-required` `.form-actions` `.form-message` `.form-message-error` `.form-message-success` | `--athena-border-width` `--athena-danger` `--athena-line` `--athena-muted` `--athena-radius` `--athena-space-1` `--athena-space-2` `--athena-space-3` `--athena-success` |
57
- | Switch: a checkbox drawn as a toggle | `.switch` `.switch-track` | `--athena-accent` `--athena-line` |
58
- | Spinner, alerts, toasts, progress | `.alert` `.alert-body` `.alert-close` `.alert-error` `.alert-info` `.alert-success` `.alert-warning` `.button-loading` `.progress-bar` `.progress-error` `.progress-fill` `.progress-indeterminate` `.progress-label` `.progress-success` `.progress-warning` `.spinner` `.spinner-large` `.spinner-small` `.toast` `.toast-container` | `--alert-color` `--athena-accent` `--athena-border-width` `--athena-danger` `--athena-fg` `--athena-info` `--athena-line` `--athena-muted` `--athena-radius` `--athena-shadow` `--athena-space-2` `--athena-space-3` `--athena-success` `--athena-surface` `--athena-surface-alt` `--athena-warning` `--progress-color` |
64
+ | Switch: a checkbox drawn as a toggle | `.switch` `.switch-track` | `--athena-accent` `--athena-duration-fast` `--athena-ease-standard` `--athena-line` |
65
+ | Spinner, alerts, toasts, progress | `.alert` `.alert-body` `.alert-close` `.alert-error` `.alert-info` `.alert-success` `.alert-warning` `.button-loading` `.progress-bar` `.progress-error` `.progress-fill` `.progress-indeterminate` `.progress-label` `.progress-success` `.progress-warning` `.spinner` `.spinner-large` `.spinner-small` `.toast` `.toast-container` | `--alert-color` `--athena-accent` `--athena-border-width` `--athena-danger` `--athena-duration-base` `--athena-ease-standard` `--athena-fg` `--athena-info` `--athena-line` `--athena-muted` `--athena-radius` `--athena-shadow` `--athena-space-2` `--athena-space-3` `--athena-success` `--athena-surface` `--athena-surface-alt` `--athena-warning` `--progress-color` |
59
66
  | Dialog: the native <dialog> element, opened with showModal() | `.dialog` | `--athena-bg` `--athena-border-width` `--athena-dialog-medium` `--athena-fg` `--athena-line` `--athena-overlay` `--athena-radius` `--athena-shadow` `--dialog-width` |
60
67
  | The content fills the dialog up to its edge, so a click on the backdrop is a click on the dialog element itself | `.dialog-body` `.dialog-close` `.dialog-footer` `.dialog-full` `.dialog-inner` `.dialog-large` `.dialog-medium` `.dialog-small` `.dialog-title` | `--athena-dialog-large` `--athena-dialog-medium` `--athena-dialog-small` `--athena-muted` `--athena-space-2` |
61
68
  | Tabs | `.tab` `.tab-active` `.tab-list` `.tab-panel` | `--athena-accent` `--athena-border-width` `--athena-fg` `--athena-line` |
62
69
  | Breadcrumbs, pagination | `.breadcrumb-item` `.breadcrumb-list` `.page-button` `.page-current` `.pagination` | `--athena-accent` `--athena-accent-fg` `--athena-bg` `--athena-border-width` `--athena-fg` `--athena-line` `--athena-muted` `--athena-space-1` |
63
- | Accordion: <details> and <summary> | `.accordion-header` `.accordion-icon` `.accordion-item` `.accordion-panel` `.sidebar-parent` | `--athena-accent` `--athena-border-width` `--athena-fg` `--athena-focus` `--athena-focus-width` `--athena-line` `--athena-surface` |
70
+ | Accordion: <details> and <summary> | `.accordion-header` `.accordion-icon` `.accordion-item` `.accordion-panel` `.sidebar-parent` | `--athena-accent` `--athena-border-width` `--athena-duration-fast` `--athena-ease-standard` `--athena-fg` `--athena-focus` `--athena-focus-width` `--athena-line` `--athena-surface` |
64
71
  | Dropdown | `.dropdown` `.dropdown-menu` `.dropdown-right` | `--athena-bg` `--athena-border-width` `--athena-line` `--athena-radius` `--athena-shadow` |
65
72
  | A popover (the dropdown menu, the tooltip) is in the top layer, placed next to its anchor by script through two variables | `.athena-popover` `.athena-popover-above` `.athena-popover-center` `.athena-popover-end` `.dropdown-divider` `.dropdown-item` `.dropdown-menu` | `--athena-fg` `--athena-hover` `--athena-line` `--athena-popover-left` `--athena-popover-top` |
66
73
  | Sidebar | `.accordion-icon` `.sidebar` `.sidebar-link` `.sidebar-list` `.sidebar-parent` `.sidebar-sublist` `.sidebar-toggle` | `--athena-accent` `--athena-accent-fg` `--athena-fg` `--athena-hover` `--athena-space-2` |
67
74
  | Cards, sections, grid | `.athena-grid` `.card` `.card-body` `.card-footer` `.card-image` `.card-title` | `--athena-bg` `--athena-border-width` `--athena-line` `--athena-radius` `--athena-surface-alt` `--grid-columns` `--grid-gap` |
68
75
  | Badge, avatar, stat | `.avatar` `.avatar-large` `.avatar-small` `.badge` `.badge-error` `.badge-info` `.badge-pill` `.badge-success` `.badge-warning` `.stat` `.stat-bad` `.stat-good` `.stat-label` `.stat-neutral` `.stat-value` | `--athena-accent` `--athena-accent-fg` `--athena-bg` `--athena-border-width` `--athena-danger` `--athena-fg` `--athena-info` `--athena-line` `--athena-muted` `--athena-radius` `--athena-success` `--athena-surface` `--athena-warning` |
69
- | Tooltip | `.has-tooltip` `.tooltip-text` `.tooltip-wrap` | - |
76
+ | Tooltip | `.has-tooltip` `.tooltip-text` `.tooltip-wrap` | `--athena-duration-fast` `--athena-ease-standard` |
70
77
  | As a popover it is only drawn while it is open, so it is always visible; the position comes from placePopover() | `.tooltip-text` | - |
71
78
  | Combobox (autocomplete, multi select) and chips | `.chip` `.chip-remove` `.combobox` `.combobox-active` `.combobox-chips` `.combobox-empty` `.combobox-input` `.combobox-list` `.combobox-multiple` `.combobox-option` `.combobox-selected` | `--athena-accent` `--athena-accent-fg` `--athena-bg` `--athena-border-width` `--athena-hover` `--athena-line` `--athena-muted` `--athena-radius` `--athena-shadow` `--athena-space-1` |
72
79
  | File upload | `.dropzone` `.dropzone-disabled` `.dropzone-input` `.dropzone-over` `.file-item` `.file-list` `.file-status` | `--athena-accent` `--athena-hover` `--athena-line` `--athena-muted` `--athena-radius` |
@@ -74,7 +81,8 @@ Dark colours: set `data-mode="dark"` on `<html>` (or let `createThemeManager` do
74
81
  | Tables | `.athena-table` `.athena-table-edit` `.athena-table-filter` `.athena-table-pager` `.athena-table-select` `.athena-table-wrapper` `.clickable` `.editable` `.selected` `.sortable` | `--athena-accent` `--athena-border-width` `--athena-hover` `--athena-line` `--athena-surface` `--athena-surface-alt` |
75
82
  | Table options: density, wrapping, alignment | `.athena-align-center` `.athena-align-right` `.athena-table` `.athena-table-compact` `.athena-table-nowrap` `.athena-table-wrap` | `--athena-focus` `--athena-focus-width` |
76
83
  | Charts | `.athena-chart` `.chart-axis` `.chart-bar` `.chart-grid` `.chart-legend` `.chart-slice` `.chart-tick` `.chart-title` | `--athena-bg` `--athena-fg` `--athena-line` `--athena-muted` |
77
- | Responsive | `.athena-form` `.athena-grid` `.file-item` `.file-progress` `.modal` `.modal-content` `.progress-fill` `.progress-indeterminate` `.sidebar` `.sidebar-list` `.sidebar-open` `.sidebar-toggle` `.spinner` `.stepper-title` | - |
84
+ | Responsive | `.athena-form` `.athena-grid` `.file-item` `.file-progress` `.modal` `.modal-content` `.sidebar` `.sidebar-list` `.sidebar-open` `.sidebar-toggle` `.stepper-title` | - |
85
+ | Reduced motion: a spinner and an indeterminate bar still have to say "busy", but slowly. The transitions read the duration tokens (0). | `.progress-fill` `.progress-indeterminate` `.spinner` | - |
78
86
  | Menu submenus | `.has-submenu` `.menu-parent` `.submenu` `.submenu-item` | `--athena-bg` `--athena-border-width` `--athena-hover` `--athena-line` `--athena-radius` `--athena-shadow` |
79
87
  | Table: resizable columns, virtual scrolling | `.athena-col-resizer` `.athena-table` `.athena-table-resizable` `.athena-table-scroll` `.athena-table-spacer` `.athena-table-virtual` `.resizing` | `--athena-accent` `--athena-border-width` `--athena-line` `--athena-row-height` `--row-height` |
80
88
  | Date range | `.daterange` `.daterange-part` | - |
@@ -85,4 +93,11 @@ Dark colours: set `data-mode="dark"` on `<html>` (or let `createThemeManager` do
85
93
  | Tabs at the bottom (layout "responsive" switches to it under 700px) | `.athena-menu-bottom-tabs` `.athena-menu-list` `.athena-menu-responsive` `.menu-control` `.menu-item` `.menu-item-end` `.menu-sheet` | `--athena-bg` `--athena-border-width` `--athena-line` `--athena-radius` |
86
94
  | Menu: groups inside groups, and badges | `.athena-menu` `.athena-menu-bottom-tabs` `.athena-menu-responsive` `.athena-table-placeholder` `.athena-table-status` `.menu-badge` `.menu-badge-bad` `.menu-badge-info` `.menu-badge-ok` `.menu-badge-warn` `.menu-caret` `.menu-sheet` `.menu-sheet-nested` | `--athena-accent` `--athena-accent-fg` `--athena-danger` `--athena-info` `--athena-muted` `--athena-success` `--athena-warning` |
87
95
  | Charts: pointer layer, zoom | `.athena-chart` `.chart-hit` `.chart-marker` `.chart-reset` `.chart-selection` | `--athena-accent` `--athena-focus` `--athena-focus-width` `--athena-muted` |
88
- | Page header, facts, empty state, loading, stat tone and note | `.empty-icon` `.empty-message` `.empty-state` `.empty-title` `.fact` `.facts` `.facts-inline` `.is-bad` `.is-ok` `.is-warn` `.loading-state` `.page-actions` `.page-description` `.page-header` `.page-header-row` `.page-title` `.stat` `.stat-note` `.stat-value` | `--athena-danger` `--athena-fg` `--athena-muted` `--athena-space-2` `--athena-space-3` `--athena-success` `--athena-warning` |
96
+ | Page header, facts, empty state, loading, stat tone and note | `.athena-popover` `.athena-popover-above` `.dialog` `.empty-icon` `.empty-message` `.empty-state` `.empty-title` `.fact` `.facts` `.facts-inline` `.is-bad` `.is-ok` `.is-warn` `.loading-state` `.page-actions` `.page-description` `.page-header` `.page-header-row` `.page-title` `.stat` `.stat-note` `.stat-value` | `--athena-danger` `--athena-duration-base` `--athena-duration-fast` `--athena-ease-out` `--athena-fg` `--athena-muted` `--athena-space-2` `--athena-space-3` `--athena-success` `--athena-warning` |
97
+ | Toasts slide in from the side, and out again when they are closed | `.is-leaving` `.toast` | `--athena-duration-base` `--athena-ease-out` |
98
+ | The panel of an accordion opens and closes smoothly (a browser without ::details-content opens it at once) | `.accordion-item` | `--athena-duration-base` `--athena-ease-standard` |
99
+ | The mark of the active item, and hover, move gently | `.athena-menu` `.menu-control` | `--athena-duration-fast` `--athena-ease-standard` |
100
+ | A place holder for what is loading: a skeleton with a shimmer (generateSkeleton) | `.athena-skeleton` `.athena-skeleton-line` | `--athena-hover` `--athena-radius` `--athena-space-2` `--athena-surface` |
101
+ | A theme or mode change cross-fades instead of flashing (the theme manager sets the class for a moment) | `.athena-switching` | `--athena-duration-slow` `--athena-ease-standard` |
102
+ | Page transitions of the router (router({ transition: true })) | - | `--athena-duration-base` `--athena-ease-standard` |
103
+ | Charts draw themselves when they appear: bars grow, lines are drawn, slices pop in (only the first time, not when a chart streams or is zoomed) | `.athena-chart-animated` `.athena-widget-grid` `.chart-area` `.chart-bar` `.chart-line` `.chart-point` `.chart-slice` `.is-dragging` `.is-editable` `.is-failed` `.is-locked` `.is-unknown` `.widget` `.widget-action` `.widget-actions` `.widget-body` `.widget-handle` `.widget-header` `.widget-note` `.widget-resize` `.widget-resize-e` `.widget-resize-n` `.widget-resize-ne` `.widget-resize-nw` `.widget-resize-s` `.widget-resize-se` `.widget-resize-sw` `.widget-resize-w` `.widget-title` | `--athena-accent` `--athena-accent-fg` `--athena-border` `--athena-border-width` `--athena-duration-fast` `--athena-duration-slow` `--athena-ease-out` `--athena-ease-standard` `--athena-fg` `--athena-focus` `--athena-focus-width` `--athena-hover` `--athena-line` `--athena-muted` `--athena-radius` `--athena-shadow` `--athena-surface` `--athena-surface-alt` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "athena-ui-js",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "A small, dependency-free UI framework: forms, tables, charts, menus, dialogs, themes and a router, written as ES modules.",
5
5
  "type": "module",
6
6
  "main": "./src/athena-ui.js",
@@ -87,6 +87,14 @@
87
87
  "types": "./types/validation.d.ts",
88
88
  "default": "./src/validation.js"
89
89
  },
90
+ "./motion": {
91
+ "types": "./types/motion.d.ts",
92
+ "default": "./src/motion.js"
93
+ },
94
+ "./widgets": {
95
+ "types": "./types/widgets.d.ts",
96
+ "default": "./src/widgets.js"
97
+ },
90
98
  "./sanitize": {
91
99
  "types": "./types/sanitize.d.ts",
92
100
  "default": "./src/sanitize.js"
package/src/athena-ui.js CHANGED
@@ -2,7 +2,7 @@
2
2
  //Author: Csaba Tóth https://github.com/csabatibortoth/
3
3
  //LICENCE: MIT
4
4
  //Repository: https://github.com/csabatibortoth/athena-ui
5
- //Version: 2.1.0
5
+ //Version: 2.3.0
6
6
 
7
7
  // The whole API as ES module exports. There are no side effects: importing this file does not touch the page, does not load a script and does not
8
8
  // put anything on globalThis. For pages that need globals use `athena-ui-js/classic`, and to download only what you use import from the entry points
@@ -123,6 +123,9 @@ export * from "./libs/core/validation.js";
123
123
  export * from "./libs/core/csv.js";
124
124
  export * from "./libs/core/dateRange.js";
125
125
  export * from "./libs/core/format.js";
126
+ export * from "./libs/core/motion.js";
127
+ export * from "./libs/hephaestus/widgetGrid/widgetGrid.js";
128
+ export * from "./libs/core/gridLayout.js";
126
129
  export * from "./libs/hephaestus/modalGenerator/modalGenerator.js";
127
130
  export * from "./libs/core/theme.js";
128
131
  export * from "./libs/hephaestus/componentGenerator/themePicker.js";
@@ -6,7 +6,7 @@
6
6
  export const BORDERED_CLASS = "default-cointainer-bordered";
7
7
 
8
8
  export const defaults = Object.freeze({
9
- version: "2.1.0",
9
+ version: "2.3.0",
10
10
  container_class: "container",
11
11
  header_class: "header-container",
12
12
  header_menu_class: "header-menu menu",
@@ -0,0 +1,102 @@
1
+ //Grid layout maths of Athena UI (no DOM): where widgets sit on a grid of columns, what moves when one is dragged or resized.
2
+ //An item is { id, x, y, w, h, locked? } in grid cells, x and y counted from 0. Every function returns new items; the argument is not changed.
3
+ //LICENCE: MIT
4
+ //Repository: https://github.com/csabatibortoth/athena-ui
5
+
6
+ /** Do two items cover a common cell? */
7
+ export const collides = (a, b) => a.id !== b.id && a.x < b.x + b.w && a.x + a.w > b.x && a.y < b.y + b.h && a.y + a.h > b.y;
8
+
9
+ const copy = items => items.map(item => ({ ...item }));
10
+ const byPlace = (a, b) => a.y - b.y || a.x - b.x;
11
+
12
+ /** Puts an item inside the columns and inside its size limits ({ min: {w, h}, max: {w, h} }). */
13
+ export function clampItem(item, columns, { min = {}, max = {} } = {}) {
14
+ const minW = Math.max(1, Math.min(min.w ?? 1, columns));
15
+ const minH = Math.max(1, min.h ?? 1);
16
+ const w = Math.min(Math.max(Math.round(item.w) || minW, minW), Math.min(max.w ?? columns, columns));
17
+ const h = Math.min(Math.max(Math.round(item.h) || minH, minH), max.h ?? Infinity);
18
+ const x = Math.min(Math.max(Math.round(item.x) || 0, 0), columns - w);
19
+ const y = Math.max(Math.round(item.y) || 0, 0);
20
+ return { ...item, x, y, w, h };
21
+ }
22
+
23
+ /**
24
+ * Gravity: every item that is not locked moves up as far as it can (locked items stay where they are).
25
+ * @returns {object[]} new items, in the order of the argument
26
+ */
27
+ export function compact(items) {
28
+ const result = copy(items);
29
+ const placed = result.filter(item => item.locked);
30
+ for (const item of result.filter(item => !item.locked).sort(byPlace)) {
31
+ while (item.y > 0) {
32
+ item.y--;
33
+ if (placed.some(other => collides(item, other))) {
34
+ item.y++;
35
+ break;
36
+ }
37
+ }
38
+ placed.push(item);
39
+ }
40
+ return result;
41
+ }
42
+
43
+ /** Pushes what the item `moved` covers downwards, and what that covers in turn. Returns false when a locked item is in the way. */
44
+ function resolve(layout, moved, depth = 0) {
45
+ if (depth > layout.length + 2) return false;
46
+ for (const other of layout.filter(item => collides(moved, item)).sort(byPlace)) {
47
+ if (other.locked) return false;
48
+ other.y = moved.y + moved.h;
49
+ if (!resolve(layout, other, depth + 1)) return false;
50
+ }
51
+ return true;
52
+ }
53
+
54
+ /**
55
+ * Sets the place of one item (clamped), pushes the others out of its way and, unless `compactItems` is false, lets everything fall upwards.
56
+ * @param {object[]} items
57
+ * @param {string} id
58
+ * @param {{x?: number, y?: number, w?: number, h?: number}} place the new place; missing values stay as they are
59
+ * @param {number} columns
60
+ * @param {object} [options]
61
+ * @param {{min?: object, max?: object}} [options.limits] size limits of this item
62
+ * @param {boolean} [options.compactItems=true]
63
+ * @returns {object[]|null} the new layout, or null when it is not possible (a locked item is in the way, or the item is locked)
64
+ */
65
+ export function placeItem(items, id, place, columns, { limits, compactItems = true } = {}) {
66
+ const layout = copy(items);
67
+ const item = layout.find(entry => entry.id === id);
68
+ if (!item || item.locked) return null;
69
+ Object.assign(item, clampItem({ ...item, ...place }, columns, limits));
70
+ if (layout.some(other => other.locked && collides(item, other))) return null;
71
+ if (!resolve(layout, item)) return null;
72
+ return compactItems ? compact(layout) : layout;
73
+ }
74
+
75
+ /** The first free place of the size w x h (rows grow without end). */
76
+ export function findFreeSpot(items, w, h, columns) {
77
+ const width = Math.min(Math.max(1, w), columns);
78
+ for (let y = 0; ; y++) {
79
+ for (let x = 0; x + width <= columns; x++) {
80
+ const probe = { id: "\0probe", x, y, w: width, h };
81
+ if (!items.some(item => collides(probe, item))) return { x, y };
82
+ }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Makes any list of items a valid layout for `columns`: inside the columns, without overlaps, compact. Items keep their order of reading
88
+ * (top to bottom, left to right). Used for loaded layouts and for a breakpoint that has no layout of its own.
89
+ */
90
+ export function normalize(items, columns, limitsOf = () => ({})) {
91
+ const placed = [];
92
+ for (const raw of copy(items).sort(byPlace)) {
93
+ const item = clampItem(raw, columns, limitsOf(raw));
94
+ while (placed.some(other => collides(item, other))) item.y++;
95
+ placed.push(item);
96
+ }
97
+ const order = new Map(items.map((item, index) => [item.id, index]));
98
+ return compact(placed).sort((a, b) => order.get(a.id) - order.get(b.id));
99
+ }
100
+
101
+ /** The height of the layout in rows. */
102
+ export const rowsOf = items => items.reduce((rows, item) => Math.max(rows, item.y + item.h), 0);
@@ -21,6 +21,22 @@ const messages = {
21
21
  rememberMe: "Remember me",
22
22
  ok: "OK",
23
23
  save: "Save",
24
+ "widget.move": "Move {title}",
25
+ "widget.settings": "Settings of {title}",
26
+ "widget.duplicate": "Duplicate {title}",
27
+ "widget.remove": "Remove {title}",
28
+ "widget.copy": "{title} (copy)",
29
+ "widget.titleLabel": "Title",
30
+ "widget.settingsTitle": "Widget settings",
31
+ "widget.unknown": "Unknown widget type \"{type}\".",
32
+ "widget.failed": "This widget could not be shown.",
33
+ "widget.pickedUp": "{title} picked up. Arrow keys move it, Shift with arrow keys resizes it, Enter drops it, Escape cancels.",
34
+ "widget.dropped": "{title} dropped.",
35
+ "widget.cancelled": "Cancelled.",
36
+ "widget.blocked": "Not possible here.",
37
+ "widget.position": "Column {x}, row {y}, {w} wide, {h} high.",
38
+ "widget.added": "{title} added.",
39
+ "widget.removed": "{title} removed.",
24
40
  "range.preset": "Range",
25
41
  "range.custom": "Custom",
26
42
  "range.last15m": "Last 15 minutes",
@@ -118,6 +134,22 @@ const messages = {
118
134
  rememberMe: "Emlékezz rám",
119
135
  ok: "OK",
120
136
  save: "Mentés",
137
+ "widget.move": "{title} áthelyezése",
138
+ "widget.settings": "{title} beállításai",
139
+ "widget.duplicate": "{title} másolása",
140
+ "widget.remove": "{title} eltávolítása",
141
+ "widget.copy": "{title} (másolat)",
142
+ "widget.titleLabel": "Cím",
143
+ "widget.settingsTitle": "Widget beállításai",
144
+ "widget.unknown": "Ismeretlen widgettípus: \"{type}\".",
145
+ "widget.failed": "Ez a widget nem jeleníthető meg.",
146
+ "widget.pickedUp": "{title} felvéve. A nyilak mozgatják, Shift és nyilak átméretezik, Enter leteszi, Escape megszakítja.",
147
+ "widget.dropped": "{title} letéve.",
148
+ "widget.cancelled": "Megszakítva.",
149
+ "widget.blocked": "Itt nem lehetséges.",
150
+ "widget.position": "{x}. oszlop, {y}. sor, {w} széles, {h} magas.",
151
+ "widget.added": "{title} hozzáadva.",
152
+ "widget.removed": "{title} eltávolítva.",
121
153
  "range.preset": "Időszak",
122
154
  "range.custom": "Egyéni",
123
155
  "range.last15m": "Utolsó 15 perc",