@nordcode/ui 1.1.6 → 1.1.7

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 (67) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/out/bundle.css +150 -79
  3. package/out/bundle_configless.css +150 -79
  4. package/out/colors.css +53 -66
  5. package/out/complete.css +156 -85
  6. package/out/complete_configless.css +156 -85
  7. package/out/src/assets/fonts/DMMono-Regular.woff +0 -0
  8. package/out/src/assets/fonts/DMMono-Regular.woff2 +0 -0
  9. package/out/src/assets/fonts/fonts.css +7 -0
  10. package/out/src/assets/icons/ArrowRightSolid.svelte +1 -0
  11. package/out/src/assets/icons/arrow-right-solid.svg +1 -0
  12. package/out/src/assets/icons/favicon.png +0 -0
  13. package/out/src/assets/icons/favicon.svg +8 -0
  14. package/out/src/assets/logos/nordcode-logo-icon.svg +3 -0
  15. package/out/src/assets/logos/nordcode-logo.svg +17 -0
  16. package/out/src/modules/copyButtons/ts/copyButtons.ts +9 -0
  17. package/out/src/modules/dialogs/svelte/dialog.svelte +27 -0
  18. package/out/src/modules/dialogs/ts/LICENCE +171 -0
  19. package/out/src/modules/dialogs/ts/dialogs.ts +111 -0
  20. package/out/src/modules/notifications/js/notifications.js +294 -0
  21. package/out/src/modules/notifications/svelte/NotificationCenter.svelte +18 -0
  22. package/out/src/modules/notifications/svelte/NotificationTemplate.svelte +16 -0
  23. package/out/src/modules/sectionObserver/ts/sectionOberserver.ts +34 -0
  24. package/out/src/styles/bundle.css +7 -0
  25. package/out/src/styles/bundle_configless.css +5 -0
  26. package/out/src/styles/complete.css +5 -0
  27. package/out/src/styles/complete_configless.css +5 -0
  28. package/out/src/styles/components/alerts.css +20 -0
  29. package/out/src/styles/components/badges.css +14 -0
  30. package/out/src/styles/components/breadcrumbs.css +37 -0
  31. package/out/src/styles/components/bundle.css +13 -0
  32. package/out/src/styles/components/buttons.css +260 -0
  33. package/out/src/styles/components/card.css +55 -0
  34. package/out/src/styles/components/dialogs.css +138 -0
  35. package/out/src/styles/components/forms.css +41 -0
  36. package/out/src/styles/components/gallery.css +66 -0
  37. package/out/src/styles/components/icons.css +60 -0
  38. package/out/src/styles/components/inputs/base.css +249 -0
  39. package/out/src/styles/components/inputs/bundle.css +5 -0
  40. package/out/src/styles/components/inputs/fields.css +76 -0
  41. package/out/src/styles/components/inputs/segmented.css +114 -0
  42. package/out/src/styles/components/inputs/switch.css +42 -0
  43. package/out/src/styles/components/inputs/tag-select.css +41 -0
  44. package/out/src/styles/components/lists.css +40 -0
  45. package/out/src/styles/components/notifications.css +135 -0
  46. package/out/src/styles/components/tables.css +7 -0
  47. package/out/src/styles/config/bundle.css +2 -0
  48. package/out/src/styles/config/config.css +700 -0
  49. package/out/src/styles/config/extras.css +12 -0
  50. package/out/src/styles/exceptions/bundle.css +3 -0
  51. package/out/src/styles/exceptions/misc.css +21 -0
  52. package/out/src/styles/exceptions/spacings.css +15 -0
  53. package/out/src/styles/exceptions/typography.css +57 -0
  54. package/out/src/styles/theme/colors.css +165 -0
  55. package/out/src/styles/theme/colors_processed.css +87 -0
  56. package/out/src/styles/utils/base.css +415 -0
  57. package/out/src/styles/utils/bundle.css +6 -0
  58. package/out/src/styles/utils/easings.css +364 -0
  59. package/out/src/styles/utils/layouts.css +281 -0
  60. package/out/src/styles/utils/media.css +55 -0
  61. package/out/src/styles/utils/reset.css +145 -0
  62. package/out/src/styles/utils/theme.css +125 -0
  63. package/package.json +1 -1
  64. package/src/styles/exceptions/typography.css +15 -0
  65. package/src/styles/utils/base.css +101 -6
  66. package/src/styles/utils/reset.css +4 -6
  67. package/transform.js +11 -23
@@ -0,0 +1,171 @@
1
+ Copyright 2023 Adam Argyle
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+ 1. Definitions.
8
+ "License" shall mean the terms and conditions for use, reproduction,
9
+ and distribution as defined by Sections 1 through 9 of this document.
10
+ "Licensor" shall mean the copyright owner or entity authorized by
11
+ the copyright owner that is granting the License.
12
+ "Legal Entity" shall mean the union of the acting entity and all
13
+ other entities that control, are controlled by, or are under common
14
+ control with that entity. For the purposes of this definition,
15
+ "control" means (i) the power, direct or indirect, to cause the
16
+ direction or management of such entity, whether by contract or
17
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
18
+ outstanding shares, or (iii) beneficial ownership of such entity.
19
+ "You" (or "Your") shall mean an individual or Legal Entity
20
+ exercising permissions granted by this License.
21
+ "Source" form shall mean the preferred form for making modifications,
22
+ including but not limited to software source code, documentation
23
+ source, and configuration files.
24
+ "Object" form shall mean any form resulting from mechanical
25
+ transformation or translation of a Source form, including but
26
+ not limited to compiled object code, generated documentation,
27
+ and conversions to other media types.
28
+ "Work" shall mean the work of authorship, whether in Source or
29
+ Object form, made available under the License, as indicated by a
30
+ copyright notice that is included in or attached to the work
31
+ (an example is provided in the Appendix below).
32
+ "Derivative Works" shall mean any work, whether in Source or Object
33
+ form, that is based on (or derived from) the Work and for which the
34
+ editorial revisions, annotations, elaborations, or other modifications
35
+ represent, as a whole, an original work of authorship. For the purposes
36
+ of this License, Derivative Works shall not include works that remain
37
+ separable from, or merely link (or bind by name) to the interfaces of,
38
+ the Work and Derivative Works thereof.
39
+ "Contribution" shall mean any work of authorship, including
40
+ the original version of the Work and any modifications or additions
41
+ to that Work or Derivative Works thereof, that is intentionally
42
+ submitted to Licensor for inclusion in the Work by the copyright owner
43
+ or by an individual or Legal Entity authorized to submit on behalf of
44
+ the copyright owner. For the purposes of this definition, "submitted"
45
+ means any form of electronic, verbal, or written communication sent
46
+ to the Licensor or its representatives, including but not limited to
47
+ communication on electronic mailing lists, source code control systems,
48
+ and issue tracking systems that are managed by, or on behalf of, the
49
+ Licensor for the purpose of discussing and improving the Work, but
50
+ excluding communication that is conspicuously marked or otherwise
51
+ designated in writing by the copyright owner as "Not a Contribution."
52
+ "Contributor" shall mean Licensor and any individual or Legal Entity
53
+ on behalf of whom a Contribution has been received by Licensor and
54
+ subsequently incorporated within the Work.
55
+ 2. Grant of Copyright License. Subject to the terms and conditions of
56
+ this License, each Contributor hereby grants to You a perpetual,
57
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
58
+ copyright license to reproduce, prepare Derivative Works of,
59
+ publicly display, publicly perform, sublicense, and distribute the
60
+ Work and such Derivative Works in Source or Object form.
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ (except as stated in this section) patent license to make, have made,
65
+ use, offer to sell, sell, import, and otherwise transfer the Work,
66
+ where such license applies only to those patent claims licensable
67
+ by such Contributor that are necessarily infringed by their
68
+ Contribution(s) alone or by combination of their Contribution(s)
69
+ with the Work to which such Contribution(s) was submitted. If You
70
+ institute patent litigation against any entity (including a
71
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
72
+ or a Contribution incorporated within the Work constitutes direct
73
+ or contributory patent infringement, then any patent licenses
74
+ granted to You under this License for that Work shall terminate
75
+ as of the date such litigation is filed.
76
+ 4. Redistribution. You may reproduce and distribute copies of the
77
+ Work or Derivative Works thereof in any medium, with or without
78
+ modifications, and in Source or Object form, provided that You
79
+ meet the following conditions:
80
+ (a) You must give any other recipients of the Work or
81
+ Derivative Works a copy of this License; and
82
+ (b) You must cause any modified files to carry prominent notices
83
+ stating that You changed the files; and
84
+ (c) You must retain, in the Source form of any Derivative Works
85
+ that You distribute, all copyright, patent, trademark, and
86
+ attribution notices from the Source form of the Work,
87
+ excluding those notices that do not pertain to any part of
88
+ the Derivative Works; and
89
+ (d) If the Work includes a "NOTICE" text file as part of its
90
+ distribution, then any Derivative Works that You distribute must
91
+ include a readable copy of the attribution notices contained
92
+ within such NOTICE file, excluding those notices that do not
93
+ pertain to any part of the Derivative Works, in at least one
94
+ of the following places: within a NOTICE text file distributed
95
+ as part of the Derivative Works; within the Source form or
96
+ documentation, if provided along with the Derivative Works; or,
97
+ within a display generated by the Derivative Works, if and
98
+ wherever such third-party notices normally appear. The contents
99
+ of the NOTICE file are for informational purposes only and
100
+ do not modify the License. You may add Your own attribution
101
+ notices within Derivative Works that You distribute, alongside
102
+ or as an addendum to the NOTICE text from the Work, provided
103
+ that such additional attribution notices cannot be construed
104
+ as modifying the License.
105
+ You may add Your own copyright statement to Your modifications and
106
+ may provide additional or different license terms and conditions
107
+ for use, reproduction, or distribution of Your modifications, or
108
+ for any such Derivative Works as a whole, provided Your use,
109
+ reproduction, and distribution of the Work otherwise complies with
110
+ the conditions stated in this License.
111
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
112
+ any Contribution intentionally submitted for inclusion in the Work
113
+ by You to the Licensor shall be under the terms and conditions of
114
+ this License, without any additional terms or conditions.
115
+ Notwithstanding the above, nothing herein shall supersede or modify
116
+ the terms of any separate license agreement you may have executed
117
+ with Licensor regarding such Contributions.
118
+ 6. Trademarks. This License does not grant permission to use the trade
119
+ names, trademarks, service marks, or product names of the Licensor,
120
+ except as required for reasonable and customary use in describing the
121
+ origin of the Work and reproducing the content of the NOTICE file.
122
+ 7. Disclaimer of Warranty. Unless required by applicable law or
123
+ agreed to in writing, Licensor provides the Work (and each
124
+ Contributor provides its Contributions) on an "AS IS" BASIS,
125
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
126
+ implied, including, without limitation, any warranties or conditions
127
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
128
+ PARTICULAR PURPOSE. You are solely responsible for determining the
129
+ appropriateness of using or redistributing the Work and assume any
130
+ risks associated with Your exercise of permissions under this License.
131
+ 8. Limitation of Liability. In no event and under no legal theory,
132
+ whether in tort (including negligence), contract, or otherwise,
133
+ unless required by applicable law (such as deliberate and grossly
134
+ negligent acts) or agreed to in writing, shall any Contributor be
135
+ liable to You for damages, including any direct, indirect, special,
136
+ incidental, or consequential damages of any character arising as a
137
+ result of this License or out of the use or inability to use the
138
+ Work (including but not limited to damages for loss of goodwill,
139
+ work stoppage, computer failure or malfunction, or any and all
140
+ other commercial damages or losses), even if such Contributor
141
+ has been advised of the possibility of such damages.
142
+ 9. Accepting Warranty or Additional Liability. While redistributing
143
+ the Work or Derivative Works thereof, You may choose to offer,
144
+ and charge a fee for, acceptance of support, warranty, indemnity,
145
+ or other liability obligations and/or rights consistent with this
146
+ License. However, in accepting such obligations, You may act only
147
+ on Your own behalf and on Your sole responsibility, not on behalf
148
+ of any other Contributor, and only if You agree to indemnify,
149
+ defend, and hold each Contributor harmless for any liability
150
+ incurred by, or claims asserted against, such Contributor by reason
151
+ of your accepting any such warranty or additional liability.
152
+ END OF TERMS AND CONDITIONS
153
+ APPENDIX: How to apply the Apache License to your work.
154
+ To apply the Apache License to your work, attach the following
155
+ boilerplate notice, with the fields enclosed by brackets "[]"
156
+ replaced with your own identifying information. (Don't include
157
+ the brackets!) The text should be enclosed in the appropriate
158
+ comment syntax for the file format. We also recommend that a
159
+ file or class name and description of purpose be included on the
160
+ same "printed page" as the copyright notice for easier
161
+ identification within third-party archives.
162
+ Copyright [yyyy] [name of copyright owner]
163
+ Licensed under the Apache License, Version 2.0 (the "License");
164
+ you may not use this file except in compliance with the License.
165
+ You may obtain a copy of the License at
166
+ http://www.apache.org/licenses/LICENSE-2.0
167
+ Unless required by applicable law or agreed to in writing, software
168
+ distributed under the License is distributed on an "AS IS" BASIS,
169
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170
+ See the License for the specific language governing permissions and
171
+ limitations under the License.
@@ -0,0 +1,111 @@
1
+ // custom events to be added to <dialog>
2
+ const dialogClosingEvent = new Event('closing')
3
+ const dialogClosedEvent = new Event('closed')
4
+ const dialogOpeningEvent = new Event('opening')
5
+ const dialogOpenedEvent = new Event('opened')
6
+ const dialogRemovedEvent = new Event('removed')
7
+
8
+ // track opening
9
+ const dialogAttrObserver = new MutationObserver((mutations, observer) => {
10
+ mutations.forEach(async mutation => {
11
+ if (mutation.attributeName === 'open') {
12
+ const dialog = mutation.target as HTMLDialogElement;
13
+
14
+ const isOpen = dialog.hasAttribute('open')
15
+ if (!isOpen) return
16
+
17
+ dialog.removeAttribute('inert')
18
+
19
+ // set focus
20
+ const focusTarget = dialog.querySelector('[autofocus]') as HTMLDialogElement;
21
+ focusTarget
22
+ ? focusTarget?.focus()
23
+ : dialog?.querySelector('button')?.focus()
24
+
25
+ dialog.dispatchEvent(dialogOpeningEvent)
26
+ await animationsComplete(dialog)
27
+ dialog.dispatchEvent(dialogOpenedEvent)
28
+ }
29
+ })
30
+ })
31
+
32
+ // track deletion
33
+ const dialogDeleteObserver = new MutationObserver((mutations, observer) => {
34
+ mutations.forEach(mutation => {
35
+ mutation.removedNodes.forEach(removedNode => {
36
+ if (removedNode.nodeName === 'DIALOG') {
37
+ removedNode.removeEventListener('click', lightDismiss)
38
+ removedNode.removeEventListener('close', dialogClose)
39
+ removedNode.dispatchEvent(dialogRemovedEvent)
40
+ }
41
+ })
42
+ })
43
+ })
44
+
45
+ // wait for all dialog animations to complete their promises
46
+ const animationsComplete = (element: HTMLDialogElement) =>
47
+ Promise.allSettled(
48
+ element.getAnimations().map((animation: Animation) =>
49
+ animation.finished))
50
+
51
+ // click outside the dialog handler
52
+ const lightDismiss = ({ target: dialog }) => {
53
+ if (dialog.nodeName === 'DIALOG')
54
+ dialog.close('dismiss')
55
+ }
56
+
57
+ const dialogClose = async ({target:dialog}) => {
58
+ dialog.setAttribute('inert', '')
59
+ dialog.dispatchEvent(dialogClosingEvent)
60
+
61
+ await animationsComplete(dialog)
62
+
63
+ dialog.dispatchEvent(dialogClosedEvent)
64
+ }
65
+
66
+ // page load dialogs setup
67
+ export async function initDialog(dialog: HTMLDialogElement) {
68
+ dialog.addEventListener('click', lightDismiss)
69
+ dialog.addEventListener('close', dialogClose)
70
+
71
+ dialogAttrObserver.observe(dialog, {
72
+ attributes: true,
73
+ })
74
+
75
+ dialogDeleteObserver.observe(document.body, {
76
+ attributes: false,
77
+ subtree: false,
78
+ childList: true,
79
+ })
80
+
81
+ // remove visibility:hidden style
82
+ // prevent page load @keyframes playing
83
+ await animationsComplete(dialog);
84
+ // dialog.style.removeProperty('visibility');
85
+ }
86
+
87
+ const dialogRemoved = ({ target: dialog }) => {
88
+ dialog.removeEventListener('removed', dialogRemoved)
89
+ }
90
+
91
+ // SETUP
92
+ document.querySelectorAll('dialog').forEach((dialog: HTMLDialogElement) => {
93
+ // sugar up <dialog> elements
94
+ initDialog(dialog);
95
+
96
+ dialog.addEventListener('removed', dialogRemoved, { once: true });
97
+ });
98
+
99
+ const htmlEl = document.documentElement;
100
+ htmlEl?.addEventListener('click', (e: MouseEvent) => {
101
+ const el = e.target as HTMLElement;
102
+
103
+ if (el.hasAttribute('data-dialogtarget')) {
104
+ const dialogId = el.getAttribute('data-dialogtarget');
105
+ if (dialogId) window[dialogId].showModal();
106
+ }
107
+
108
+ if (el.hasAttribute('data-closes-dialog')) {
109
+ (el as HTMLButtonElement)?.closest('dialog')?.close('close');
110
+ }
111
+ });
@@ -0,0 +1,294 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @typedef {T[keyof T]} valueOf<T>
5
+ * @template T
6
+ */
7
+
8
+ /**
9
+ * @typedef SelectorType
10
+ * @property {string} notificationTemplate
11
+ * @property {string} notification
12
+ * @property {string} notificationTitle
13
+ * @property {string} notificationDescription
14
+ * @property {string} notificationTime
15
+ * @property {string} notificationButton
16
+ * @property {string} notificationCenterToggle
17
+ * @property {string} notificationCenterDismissAll
18
+ * @property {string} notificationCenter
19
+ * @property {string} notificationCenterContainer
20
+ * @property {string} notificationOutput
21
+ */
22
+
23
+ /**
24
+ * @type {SelectorType}
25
+ */
26
+ export const Selector = {
27
+ notificationTemplate: '#nc-notification',
28
+ notification: '.nc-notification',
29
+ notificationTitle: '.nc-notification-title',
30
+ notificationDescription: '.nc-notification-description',
31
+ notificationTime: '.nc-notification-time',
32
+
33
+ notificationButton: 'button[data-has-notification]',
34
+ notificationCenterToggle: 'button[data-toggle-notification-center]',
35
+ notificationCenterDismissAll: 'button[data-notifications-dismiss-all]',
36
+
37
+ notificationCenter: '.nc-notification-center',
38
+ notificationCenterContainer: '.nc-notification-center-container',
39
+ notificationOutput: '.nc-notification-output',
40
+ };
41
+
42
+ /** @type {Set<string>} */
43
+ const notifications = new Set();
44
+
45
+ /** @type {function(): HTMLTemplateElement | null} */
46
+ const getNotificationTemplate = () => document.querySelector(Selector.notificationTemplate);
47
+
48
+ /** @type {function(): HTMLElement | null} */
49
+ const getNotificationCenter = () => document.querySelector(Selector.notificationCenter);
50
+
51
+ /** @type {function(): NodeListOf<HTMLButtonElement>} */
52
+ const getNotificationCenterToggle = () =>
53
+ document.querySelectorAll(Selector.notificationCenterToggle);
54
+
55
+ /** @type {function(): HTMLOutputElement | null} */
56
+ const getNotificationOutput = () => document.querySelector(Selector.notificationOutput);
57
+
58
+ /** @type {function(): NodeListOf<HTMLButtonElement>} */
59
+ const getNotificationCenterDismissAll = () =>
60
+ document.querySelectorAll(Selector.notificationCenterDismissAll);
61
+
62
+ /** @type {function(): HTMLElement | null} */
63
+ const getNotificationCenterContainer = () =>
64
+ document.querySelector(Selector.notificationCenterContainer);
65
+
66
+ /**
67
+ * Create a unique id for a notification
68
+ * @param {string} title
69
+ * @return {`${string}-${number}`}
70
+ */
71
+ const createNotificationId = (title) => {
72
+ return `${title}-${Date.now()}`;
73
+ };
74
+
75
+ /**
76
+ * Set the inner text of an element if it is defined
77
+ * @param {HTMLElement} notification
78
+ * @param {valueOf<SelectorType>} selector
79
+ * @param {string | undefined} text
80
+ */
81
+ const setElementTextIfItExists = (notification, selector, text) => {
82
+ /** @type {HTMLElement | null} */
83
+ const element = notification.querySelector(selector);
84
+
85
+ if (!element) {
86
+ return;
87
+ }
88
+
89
+ element.textContent = text || '';
90
+ };
91
+
92
+ /**
93
+ * Remove all notifications
94
+ */
95
+ const dismissAllNotifications = () => {
96
+ for (const notificationId of notifications) {
97
+ /** @type {HTMLElement | null} */
98
+ const notification = document.querySelector(`[data-notification-id="${notificationId}"]`);
99
+
100
+ if (!notification) {
101
+ return;
102
+ }
103
+
104
+ removeNotification(notificationId, notification);
105
+ }
106
+ };
107
+
108
+ /**
109
+ * Register all buttons
110
+ */
111
+ const setupNotificationButtons = () => {
112
+ const htmlEl = document.documentElement;
113
+
114
+ htmlEl?.addEventListener('click', (e) => {
115
+ const el = e.target;
116
+ if (el.hasAttribute('data-has-notification')) {
117
+ const title = el.dataset.notificationTitle;
118
+ const description = el.dataset.notificationDescription;
119
+
120
+ if (!title) {
121
+ console.error('No title defined for notification');
122
+ return;
123
+ }
124
+ addNotification(title, description);
125
+ }
126
+ });
127
+
128
+ for (const button of getNotificationCenterDismissAll()) {
129
+ button.addEventListener('click', () => {
130
+ dismissAllNotifications();
131
+ });
132
+ }
133
+
134
+ for (const button of getNotificationCenterToggle()) {
135
+ button.addEventListener('click', () => {
136
+ getNotificationCenter()?.classList.toggle('-open');
137
+ });
138
+ }
139
+ };
140
+
141
+ /**
142
+ * Hide the notification center
143
+ */
144
+ const closeNavigationCenter = () => {
145
+ getNotificationCenter()?.classList?.remove('-open');
146
+ };
147
+
148
+ /**
149
+ * Create a new notification from the template and set the necessary data and event listeners
150
+ * @param {string} title
151
+ * @param {string | undefined} description
152
+ * @param {string} notificationId
153
+ * @return {HTMLElement | null} The notification element
154
+ */
155
+ const createNotification = (title, description, notificationId) => {
156
+ const notificationTemplate = getNotificationTemplate();
157
+
158
+ if (!notificationTemplate) {
159
+ console.error('Could not find notification template', Selector.notificationTemplate);
160
+ return null;
161
+ }
162
+
163
+ const clonedTemplate = notificationTemplate.content.cloneNode(true);
164
+ /** @type {HTMLElement | null} */
165
+ const notificationElement = /** @type {HTMLTemplateElement} */ (clonedTemplate).querySelector(
166
+ Selector.notification,
167
+ );
168
+ if (!notificationElement) {
169
+ console.error('Could not find notification element');
170
+ return null;
171
+ }
172
+
173
+ /** @type {HTMLButtonElement | null} */
174
+ const notificationClose = notificationElement.querySelector('button');
175
+
176
+ notificationElement.dataset.notificationId = notificationId;
177
+ setElementTextIfItExists(notificationElement, Selector.notificationTitle, title);
178
+ setElementTextIfItExists(notificationElement, Selector.notificationDescription, description);
179
+ setElementTextIfItExists(
180
+ notificationElement,
181
+ Selector.notificationTime,
182
+ new Date().toLocaleTimeString(),
183
+ );
184
+
185
+ notificationClose?.addEventListener(
186
+ 'click',
187
+ (e) => {
188
+ closeCorrespondingNotification(e);
189
+ },
190
+ { once: true },
191
+ );
192
+
193
+ return notificationElement;
194
+ };
195
+
196
+ /**
197
+ * Handle the creation of the necessary DOM elements and add them to the DOM
198
+ * @param {string} title
199
+ * @param {string | undefined} description
200
+ */
201
+ export const addNotification = (title, description) => {
202
+ const notificationId = createNotificationId(title);
203
+ const liveNotification = createNotification(title, description, notificationId);
204
+ const notificationOutput = getNotificationOutput();
205
+
206
+ if (!liveNotification || !notificationOutput) {
207
+ return;
208
+ }
209
+
210
+ notificationOutput.append(liveNotification);
211
+ notifications.add(notificationId);
212
+
213
+ setTimeout(() => {
214
+ /** @type {HTMLElement | null} */
215
+ const notification = notificationOutput.querySelector(
216
+ `[data-notification-id="${notificationId}"]`,
217
+ );
218
+
219
+ if (!notification) {
220
+ return;
221
+ }
222
+
223
+ removeNotification(notificationId, notification, false);
224
+ const archiveNotification = createNotification(title, description, notificationId);
225
+ const notificationCenterContainer = getNotificationCenterContainer();
226
+ if (!archiveNotification || !notificationCenterContainer) {
227
+ return;
228
+ }
229
+ notificationCenterContainer.append(archiveNotification);
230
+ }, 4000);
231
+ };
232
+
233
+ /**
234
+ * Close the notification that is associated with the button that was clicked
235
+ * @param {MouseEvent} e
236
+ */
237
+ const closeCorrespondingNotification = (e) => {
238
+ /** @type {HTMLElement | null} */
239
+ const notification = /** @type {HTMLButtonElement} */ (e.target).closest(Selector.notification);
240
+
241
+ const notificationId = notification?.dataset?.notificationId;
242
+ if (!notificationId) {
243
+ return;
244
+ }
245
+ removeAllNotificationsWithId(notificationId);
246
+ };
247
+
248
+ /**
249
+ * Remove a notification from the DOM after playing the closing animation
250
+ *
251
+ * @param {string} notificationId
252
+ * @param {HTMLElement | null} notification
253
+ * @param {boolean} removeId
254
+ */
255
+ const removeNotification = (notificationId, notification, removeId = true) => {
256
+ if (!notification) {
257
+ return;
258
+ }
259
+
260
+ notification.addEventListener(
261
+ 'animationend',
262
+ () => {
263
+ notification.remove();
264
+
265
+ if (removeId) {
266
+ notifications.delete(notificationId);
267
+ }
268
+
269
+ if (notifications.size === 0) {
270
+ closeNavigationCenter();
271
+ }
272
+ },
273
+ { once: true },
274
+ );
275
+
276
+ notification.classList.add('-closing');
277
+ };
278
+
279
+ /**
280
+ * Remove all notifications with the same id. This is used to remove the live notification and the archived notification
281
+ * @param {string} notificationId
282
+ */
283
+ const removeAllNotificationsWithId = (notificationId) => {
284
+ /** @type {NodeListOf<HTMLElement>} */
285
+ const relatedNotifications = document.querySelectorAll(
286
+ `[data-notification-id="${notificationId}"]`,
287
+ );
288
+
289
+ for (const n of relatedNotifications) {
290
+ removeNotification(notificationId, n);
291
+ }
292
+ };
293
+
294
+ setupNotificationButtons();
@@ -0,0 +1,18 @@
1
+ <script lang="ts">
2
+ interface NotificationCenterProps {
3
+ dismissAllText: string;
4
+ closeText: string;
5
+ }
6
+
7
+ let { dismissAllText = 'Dismiss all', closeText = 'Close' }: NotificationCenterProps = $props();
8
+ </script>
9
+
10
+ <div class="nc-notification-center -archive">
11
+ <div class="nc-notification-center-header">
12
+ <button data-notifications-dismiss-all class="nc-button">{dismissAllText}</button>
13
+ <button data-toggle-notification-center class="nc-button">{closeText}</button>
14
+ </div>
15
+ <div class="nc-notification-center-container"></div>
16
+ </div>
17
+
18
+ <output class="nc-notification-output"></output>
@@ -0,0 +1,16 @@
1
+ <script>
2
+
3
+ </script>
4
+
5
+
6
+ <template id="nc-notification">
7
+ <div class="nc-notification">
8
+ <p class="nc-notification-title"></p>
9
+ <p class="nc-notification-description">Some notification</p>
10
+ <div class="nc-notification-footer">
11
+ <button class="nc-button -small">Dismiss</button>
12
+
13
+ <time class="nc-notification-time"></time>
14
+ </div>
15
+ </div>
16
+ </template>
@@ -0,0 +1,34 @@
1
+ const buildThresholds = (steps: number) => {
2
+ const thresholds = [0];
3
+ for (let i = 1.0; i <= steps; i++) {
4
+ const ratio = i / steps;
5
+ thresholds.push(ratio);
6
+ }
7
+ return thresholds;
8
+ };
9
+
10
+ const createObserver = (selector: string, steps: number) => {
11
+ // if the browser does not support the IntersectionObserver API, return
12
+ if (!('IntersectionObserver' in window)) {
13
+ return;
14
+ }
15
+
16
+ const options = {
17
+ root: null,
18
+ rootMargin: '0px',
19
+ threshold: buildThresholds(steps),
20
+ };
21
+
22
+ const observer = new IntersectionObserver((entries) => {
23
+ for (const entry of entries) {
24
+ const ratio = entry.intersectionRatio;
25
+ (entry.target as HTMLElement)?.style?.setProperty('--intersecting', ratio.toString());
26
+ }
27
+ }, options);
28
+
29
+ for (const node of Array.from(document.querySelectorAll(selector))) {
30
+ observer.observe(node);
31
+ }
32
+ };
33
+
34
+ export { createObserver };
@@ -0,0 +1,7 @@
1
+ @layer config, theme, reset, base, utils, components, helpers;
2
+
3
+ @import "./config/bundle.css";
4
+ @import "./theme/colors.css";
5
+
6
+ @import "./utils/bundle.css";
7
+ @import "./exceptions/bundle.css";
@@ -0,0 +1,5 @@
1
+ @layer config, theme, reset, base, utils, components, helpers;
2
+
3
+ @import "./theme/colors.css";
4
+ @import "./utils/bundle.css";
5
+ @import "./exceptions/bundle.css";
@@ -0,0 +1,5 @@
1
+ @layer config, theme, reset, base, utils, components, helpers;
2
+
3
+ @import "./bundle.css";
4
+
5
+ @import "./components/bundle.css";
@@ -0,0 +1,5 @@
1
+ @layer config, theme, reset, base, utils, components, helpers;
2
+
3
+ @import "./bundle_configless.css";
4
+
5
+ @import "./components/bundle.css";