@proj-airi/ui 0.9.0-alpha.15 → 0.9.0-alpha.18

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@proj-airi/ui",
3
3
  "type": "module",
4
- "version": "0.9.0-alpha.15",
4
+ "version": "0.9.0-alpha.18",
5
5
  "description": "A collection of UI components that used by Project AIRI",
6
6
  "author": {
7
7
  "name": "Moeru AI Project AIRI Team",
@@ -1,20 +1,61 @@
1
1
  <script setup lang="ts">
2
2
  import { breakpointsTailwind, useBreakpoints, useElementBounding, useWindowSize } from '@vueuse/core'
3
- import { computed, onMounted, ref } from 'vue'
3
+ import { computed, onMounted, ref, watch } from 'vue'
4
4
 
5
5
  const containerRef = ref<HTMLDivElement>()
6
6
 
7
7
  const breakpoints = useBreakpoints(breakpointsTailwind)
8
- const { width } = useWindowSize()
8
+ const { width, height } = useWindowSize()
9
9
  const containerElementBounding = useElementBounding(containerRef, { immediate: true, windowResize: true, reset: true })
10
10
 
11
+ const isMobile = computed(() => breakpoints.between('sm', 'md').value || breakpoints.smaller('sm').value)
12
+ const isTablet = computed(() => breakpoints.between('md', 'lg').value)
13
+ const isDesktop = computed(() => breakpoints.greaterOrEqual('lg').value)
14
+
11
15
  const canvasWidth = computed(() => {
12
- if (breakpoints.smaller('lg').value)
16
+ if (isDesktop.value)
17
+ return containerElementBounding.width.value
18
+ else if (isMobile.value)
19
+ return (width.value - 16) // padding
20
+ else if (isTablet.value)
13
21
  return (width.value - 16) // padding
14
- return containerElementBounding.width.value
22
+ else
23
+ return containerElementBounding.width.value
15
24
  })
16
25
 
17
- const canvasHeight = computed(() => containerElementBounding.height.value || 0)
26
+ const canvasHeight = ref(0)
27
+
28
+ watch([width, height, containerRef], () => {
29
+ const bounding = containerRef.value?.parentElement?.getBoundingClientRect()
30
+
31
+ if (isDesktop.value) {
32
+ canvasHeight.value = bounding?.height || 0
33
+ }
34
+ else if (isMobile.value) {
35
+ canvasHeight.value = bounding?.height || 0
36
+ }
37
+ else if (isTablet.value) {
38
+ canvasHeight.value = bounding?.height || 0
39
+ }
40
+ else {
41
+ canvasHeight.value = 600
42
+ }
43
+ })
44
+
45
+ watch([containerElementBounding.width, containerElementBounding.height], () => {
46
+ if (isDesktop.value) {
47
+ canvasHeight.value = containerElementBounding.height.value
48
+ }
49
+ else if (isMobile.value) {
50
+ canvasHeight.value = containerElementBounding.height.value
51
+ }
52
+ else if (isTablet.value) {
53
+ canvasHeight.value = containerElementBounding.height.value
54
+ }
55
+ else {
56
+ canvasHeight.value = 600
57
+ }
58
+ })
18
59
 
19
60
  onMounted(async () => {
20
61
  if (!containerRef.value)