@witchcraft/ui 0.3.9 → 0.3.11

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "witchcraftUi",
3
3
  "configKey": "witchcraftUi",
4
- "version": "0.3.9",
4
+ "version": "0.3.11",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -11,7 +11,13 @@ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
11
11
  }
12
12
  declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props, {
13
13
  focus: () => void;
14
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
14
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
15
+ pause: (notification: NotificationEntry) => any;
16
+ resume: (notification: NotificationEntry) => any;
17
+ }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
18
+ onPause?: ((notification: NotificationEntry) => any) | undefined;
19
+ onResume?: ((notification: NotificationEntry) => any) | undefined;
20
+ }>, {
15
21
  handler: NotificationHandler;
16
22
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
17
23
  top?: (props: {
@@ -20,13 +20,16 @@
20
20
  p-1
21
21
  text-sm
22
22
  focus:border-accent-500
23
+ focus-within:border-accent-500
23
24
  `,
24
25
  $attrs.class
25
26
  )"
26
27
  v-bind="{ ...$attrs, class: void 0 }"
27
28
  tabindex="0"
29
+ :data-id="notification.id"
28
30
  ref="notificationEl"
29
31
  @keydown.enter.self="NotificationHandler.resolveToDefault(notification)"
32
+ @pointerenter="notification.timeout && !notification.isPaused && emit('pause', notification)"
30
33
  >
31
34
  <slot
32
35
  name="top"
@@ -148,7 +151,7 @@
148
151
  </template>
149
152
 
150
153
  <script setup>
151
- import { computed, onMounted, ref, useAttrs } from "vue";
154
+ import { computed, onBeforeUnmount, onMounted, ref, useAttrs } from "vue";
152
155
  import IFa6RegularCopy from "~icons/fa6-regular/copy";
153
156
  import IFa6SolidXmark from "~icons/fa6-solid/xmark";
154
157
  import { useSlotVars } from "../../composables/useSlotVars.js";
@@ -167,11 +170,29 @@ const props = defineProps({
167
170
  notification: { type: null, required: true },
168
171
  handler: { type: Object, required: false, default: void 0 }
169
172
  });
170
- const getColor = (notification, option) => notification.default === option ? "primary" : notification.dangerous.includes(option) ? "danger" : "secondary";
173
+ const emit = defineEmits(["pause", "resume"]);
174
+ const getColor = (notification, option) => {
175
+ return notification.dangerous.includes(option) ? "danger" : notification.default === option ? "primary" : "secondary";
176
+ };
171
177
  const buttonColors = computed(() => props.notification.options.map((option) => getColor(props.notification, option)));
172
178
  const notificationEl = ref(null);
179
+ const mousedownAbortController = new AbortController();
173
180
  onMounted(() => {
174
181
  notificationEl.value?.focus();
182
+ if (props.notification.timeout) {
183
+ window.addEventListener("pointerdown", (e) => {
184
+ if (!e.target || !(e.target instanceof HTMLElement)) return;
185
+ if (e.target === notificationEl.value || notificationEl.value?.contains(e.target)) {
186
+ if (props.notification.isPaused) return;
187
+ emit("pause", props.notification);
188
+ } else {
189
+ emit("resume", props.notification);
190
+ }
191
+ }, { signal: mousedownAbortController.signal });
192
+ }
193
+ });
194
+ onBeforeUnmount(() => {
195
+ mousedownAbortController.abort();
175
196
  });
176
197
  defineExpose({
177
198
  focus: () => {
@@ -11,7 +11,13 @@ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
11
11
  }
12
12
  declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props, {
13
13
  focus: () => void;
14
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
14
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
15
+ pause: (notification: NotificationEntry) => any;
16
+ resume: (notification: NotificationEntry) => any;
17
+ }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
18
+ onPause?: ((notification: NotificationEntry) => any) | undefined;
19
+ onResume?: ((notification: NotificationEntry) => any) | undefined;
20
+ }>, {
15
21
  handler: NotificationHandler;
16
22
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
17
23
  top?: (props: {
@@ -32,8 +32,8 @@
32
32
  class="overflow-hidden my-2"
33
33
  v-for="notification of notifications"
34
34
  :key="notification.id"
35
- @pointerenter="notification.timeout && !notification.isPaused && handler.pause(notification)"
36
- @blur="notification.timeout && notification.isPaused && handler.resume(notification)"
35
+ @pause="handler.pause(notification)"
36
+ @resume="handler.resume(notification)"
37
37
  >
38
38
  <template #top>
39
39
  <LibProgressBar
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns whether the text should be inverted (to white) based on the given color.
3
+ */
4
+ export declare function doInvertTextColor(color: string): boolean;
@@ -0,0 +1,8 @@
1
+ import Color from "colorjs.io";
2
+ export function doInvertTextColor(color) {
3
+ const c = new Color(color).to("hsv");
4
+ const v = c.hsv[2];
5
+ const a = c.alpha;
6
+ const doInvert = !!(v < 50 || (a === void 0 || a < 0.5));
7
+ return doInvert;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@witchcraft/ui",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "Vue component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/runtime/main.lib.js",
package/src/module.ts CHANGED
@@ -21,7 +21,6 @@ import { unpluginIconViteOptions } from "./runtime/build/unpluginIconViteOptions
21
21
  import { themeConvertionOpts } from "./runtime/tailwind/themeConvertionOpts.js"
22
22
  import { theme } from "./runtime/theme.js"
23
23
 
24
- import pkg from "../package.json" assert { type: "json" }
25
24
 
26
25
  const knownDirectives = ["vExtractRootEl", "vResizableCols", "vResizeObserver", "vResizableCols"] as const
27
26
 
@@ -19,12 +19,15 @@
19
19
  p-1
20
20
  text-sm
21
21
  focus:border-accent-500
22
+ focus-within:border-accent-500
22
23
  `,
23
24
  ($attrs as any).class)"
24
25
  v-bind="{ ...$attrs, class: undefined }"
25
26
  tabindex="0"
27
+ :data-id="notification.id"
26
28
  ref="notificationEl"
27
29
  @keydown.enter.self="NotificationHandler.resolveToDefault(notification)"
30
+ @pointerenter="notification.timeout && !notification.isPaused && emit('pause', notification)"
28
31
  >
29
32
  <slot
30
33
  name="top"
@@ -145,7 +148,7 @@
145
148
  </template>
146
149
 
147
150
  <script setup lang="ts">
148
- import { computed, type HTMLAttributes, onMounted, ref, useAttrs } from "vue"
151
+ import { computed, type HTMLAttributes, onBeforeUnmount, onMounted, ref, useAttrs } from "vue"
149
152
 
150
153
  import IFa6RegularCopy from "~icons/fa6-regular/copy"
151
154
  import IFa6SolidXmark from "~icons/fa6-solid/xmark"
@@ -171,16 +174,46 @@ const props = withDefaults(defineProps<Props>(), {
171
174
  handler: undefined
172
175
  })
173
176
 
174
- const getColor = (notification: NotificationEntry, option: string): "ok" | "primary" | "danger" | "secondary" => notification.default === option ? "primary" : notification.dangerous.includes(option) ? "danger" : "secondary"
177
+ const emit = defineEmits<{
178
+ (e: "pause", notification: NotificationEntry): void
179
+ (e: "resume", notification: NotificationEntry): void
180
+ }>()
181
+
182
+ const getColor = (notification: NotificationEntry, option: string): "ok" | "primary" | "danger" | "secondary" => {
183
+ return notification.dangerous.includes(option)
184
+ ? "danger"
185
+ : notification.default === option
186
+ ? "primary"
187
+ : "secondary"
188
+ }
175
189
 
176
190
  /* Todo make this more flexible? */
177
191
 
178
192
  const buttonColors = computed(() => props.notification.options.map((option: any /* what ??? */) => getColor(props.notification, option)))
179
193
 
180
194
  const notificationEl = ref<null | HTMLElement>(null)
195
+
196
+ const mousedownAbortController = new AbortController()
197
+
181
198
  onMounted(() => {
182
199
  notificationEl.value?.focus()
200
+ if (props.notification.timeout) {
201
+ window.addEventListener("pointerdown", e => {
202
+ if (!e.target || !(e.target instanceof HTMLElement)) return
203
+ if (e.target === notificationEl.value || notificationEl.value?.contains(e.target)) {
204
+ if (props.notification.isPaused) return
205
+ emit("pause", props.notification)
206
+ } else {
207
+ emit("resume", props.notification)
208
+ }
209
+ }, { signal: mousedownAbortController.signal })
210
+ }
211
+ })
212
+
213
+ onBeforeUnmount(() => {
214
+ mousedownAbortController.abort()
183
215
  })
216
+
184
217
  defineExpose({
185
218
  focus: () => {
186
219
  notificationEl.value?.focus()
@@ -32,8 +32,8 @@
32
32
  class="overflow-hidden my-2"
33
33
  v-for="notification of notifications"
34
34
  :key="notification.id"
35
- @pointerenter="notification.timeout && !notification.isPaused && handler.pause(notification)"
36
- @blur="notification.timeout && notification.isPaused && handler.resume(notification)"
35
+ @pause="handler.pause(notification)"
36
+ @resume="handler.resume(notification)"
37
37
  >
38
38
  <template #top>
39
39
  <LibProgressBar
@@ -0,0 +1,11 @@
1
+ import Color from "colorjs.io"
2
+ /**
3
+ * Returns whether the text should be inverted (to white) based on the given color.
4
+ */
5
+ export function doInvertTextColor(color: string) {
6
+ const c = new Color(color).to("hsv")
7
+ const v = c.hsv[2]
8
+ const a = c.alpha
9
+ const doInvert = !!(v! < 50 || (a === undefined || a < 0.5))
10
+ return doInvert
11
+ }