valaxy-theme-hairy 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,8 @@
2
2
  import { computed, provide, useCssVars, useSlots } from 'vue'
3
3
  import { renderOverlay } from '@overlastic/vue'
4
4
  import type { ImageViewerProps } from 'element-plus'
5
- import { atWillToUnit } from '@hairy/utils'
6
5
  import HairyImageViewer from './parts/HairyImageViewer.vue'
6
+ import { atWillToUnit } from '../utils';
7
7
 
8
8
  const props = withDefaults(defineProps<{
9
9
  row?: string | number
@@ -2,8 +2,8 @@
2
2
  import { provide, useCssVars } from 'vue'
3
3
  import { renderOverlay } from '@overlastic/vue'
4
4
  import type { ImageViewerProps } from 'element-plus'
5
- import { atWillToUnit } from '@hairy/utils'
6
5
  import HairyImageViewer from './HairyImageViewer.vue'
6
+ import { atWillToUnit } from '../../utils';
7
7
 
8
8
  const props = withDefaults(defineProps<{
9
9
  row?: string | number
@@ -1,8 +1,8 @@
1
1
  import './loading.scss'
2
2
  import { ref } from 'vue'
3
3
  import type { ViteSSGContext } from 'vite-ssg'
4
- import { createDeferred } from '@hairy/utils'
5
4
  import Seto from '../styles/fonts/Seto.ttf?url'
5
+ import { createDeferred } from '../utils'
6
6
 
7
7
  export const fontFaceDeferred = createDeferred<void>()
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valaxy-theme-hairy",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "packageManager": "pnpm@8.10.5",
5
5
  "author": {
6
6
  "email": "wwu710632@gmail.com",
@@ -21,7 +21,6 @@
21
21
  "main": "client/index.ts",
22
22
  "types": "types/index.d.ts",
23
23
  "dependencies": {
24
- "@hairy/utils": "^0.6.8",
25
24
  "@overlastic/vue": "^0.4.7",
26
25
  "element-plus": "^2.7.6",
27
26
  "pinia": "^2.1.7",
package/utils/index.ts CHANGED
@@ -1,37 +1,2 @@
1
- export function ejectWindow(url: string) {
2
- const link = document.createElement('a')
3
- link.href = url
4
- link.target = '_blank'
5
- link.click()
6
- link.remove()
7
- }
8
-
9
- export function riposte<T>(...args: [cond: boolean, value: T][]) {
10
- for (const [cond, value] of args) {
11
- if (cond)
12
- return value
13
- }
14
- }
15
-
16
- export function toArray<T>(value: T | T[]): T[] {
17
- if (Array.isArray(value))
18
- return value as any
19
- else return [value].filter(Boolean) as any
20
- }
21
-
22
- export function removeTags(content = '') {
23
- return content
24
- .replace(/<\/?[^>]*>/g, '')
25
- .replace(/[|]*\n/, '')
26
- }
27
-
28
- export function getArchiveLink(year?: string, month?: string) {
29
- if (!year)
30
- return '/archives/'
31
- if (!month)
32
- return `/archives/${year}`
33
- if (month)
34
- return `/archives/${year}/${month}`
35
-
36
- return ''
37
- }
1
+ export * from './size'
2
+ export * from './util'
package/utils/size.ts ADDED
@@ -0,0 +1,40 @@
1
+
2
+ function isString(val: any) {
3
+ return typeof val === 'string'
4
+ }
5
+
6
+ function isNumber(val: any) {
7
+ return typeof val === 'number'
8
+ }
9
+
10
+ export function atWillToUnit(value: any, unit = 'px') {
11
+ if (!(isString(value) || isNumber(value)))
12
+ return ''
13
+ return (isString(value) && /\D/g.test(value)) ? value : value + unit
14
+ }
15
+
16
+ /** size 转换配置 */
17
+ export type AtWillSize = any | [any, any] | { width: any; height: any }
18
+ export interface Size { width: string; height: string }
19
+
20
+ /**
21
+ * 将 size 转换为宽高,用于元素宽高
22
+ * @param size AtWillSize
23
+ * @returns
24
+ */
25
+ export function atWillToSize(size: AtWillSize, unit?: string): Size {
26
+ const _atWillToUnit = (value: any) => atWillToUnit(value, unit)
27
+ // 单数值正方形
28
+ if (typeof size === 'string' || typeof size === 'number')
29
+ return { width: _atWillToUnit(size), height: _atWillToUnit(size) }
30
+
31
+ // 数组形式尺寸
32
+ if (Array.isArray(size))
33
+ return { width: _atWillToUnit(size[0]), height: _atWillToUnit(size[1]) }
34
+
35
+ // 对象形式尺寸
36
+ if (typeof size === 'object')
37
+ return { width: _atWillToUnit(size.width), height: _atWillToUnit(size.height) }
38
+
39
+ return { width: '', height: '' }
40
+ }
package/utils/util.ts ADDED
@@ -0,0 +1,59 @@
1
+ export function ejectWindow(url: string) {
2
+ const link = document.createElement('a')
3
+ link.href = url
4
+ link.target = '_blank'
5
+ link.click()
6
+ link.remove()
7
+ }
8
+
9
+ export function riposte<T>(...args: [cond: boolean, value: T][]) {
10
+ for (const [cond, value] of args) {
11
+ if (cond)
12
+ return value
13
+ }
14
+ }
15
+
16
+ export function toArray<T>(value: T | T[]): T[] {
17
+ if (Array.isArray(value))
18
+ return value as any
19
+ else return [value].filter(Boolean) as any
20
+ }
21
+
22
+ export function removeTags(content = '') {
23
+ return content
24
+ .replace(/<\/?[^>]*>/g, '')
25
+ .replace(/[|]*\n/, '')
26
+ }
27
+
28
+ export function getArchiveLink(year?: string, month?: string) {
29
+ if (!year)
30
+ return '/archives/'
31
+ if (!month)
32
+ return `/archives/${year}`
33
+ if (month)
34
+ return `/archives/${year}/${month}`
35
+
36
+ return ''
37
+ }
38
+
39
+ export type Deferred<T = void> = Promise<T> & {
40
+ resolve: (value: T) => void
41
+ reject: (value?: any) => void
42
+ }
43
+
44
+ export function createDeferred<T = void>(): Deferred<T> {
45
+ let resolve: any, reject: any
46
+
47
+ const promise = new Promise<any>((_resolve, _reject) => {
48
+ resolve = _resolve
49
+ reject = _reject
50
+ }) as unknown as any
51
+
52
+ promise.resolve = (v: any) => {
53
+ resolve(v)
54
+ return promise
55
+ }
56
+ promise.reject = reject
57
+
58
+ return promise
59
+ }