@varlet/cli 2.15.1 → 2.16.0-alpha.1693852004525

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 (60) hide show
  1. package/lib/node/config/varlet.config.js +2 -1
  2. package/lib/node/config/varlet.default.config.js +264 -7
  3. package/package.json +8 -7
  4. package/site/mobile/App.vue +25 -22
  5. package/site/mobile/{components/AppHome.vue → AppHome.vue} +6 -6
  6. package/site/mobile/main.ts +6 -21
  7. package/site/pc/App.vue +0 -5
  8. package/site/pc/Layout.vue +24 -28
  9. package/site/pc/components/AppHeader.vue +123 -122
  10. package/site/pc/components/AppMobile.vue +9 -2
  11. package/site/pc/components/AppSidebar.vue +18 -17
  12. package/site/{components → pc/components}/code-example/CodeExample.vue +8 -15
  13. package/site/pc/main.ts +6 -23
  14. package/site/pc/pages/index/index.vue +316 -47
  15. package/site/types.ts +6 -0
  16. package/template/generators/base/package.json +1 -0
  17. package/site/components/button/Button.vue +0 -106
  18. package/site/components/button/button.less +0 -183
  19. package/site/components/button/index.ts +0 -10
  20. package/site/components/button/props.ts +0 -78
  21. package/site/components/cell/Cell.vue +0 -54
  22. package/site/components/cell/cell.less +0 -78
  23. package/site/components/cell/index.ts +0 -10
  24. package/site/components/cell/props.ts +0 -27
  25. package/site/components/context/index.ts +0 -21
  26. package/site/components/context/lock.ts +0 -92
  27. package/site/components/context/zIndex.ts +0 -20
  28. package/site/components/icon/Icon.vue +0 -75
  29. package/site/components/icon/icon.less +0 -38
  30. package/site/components/icon/index.ts +0 -10
  31. package/site/components/icon/props.ts +0 -24
  32. package/site/components/loading/Loading.vue +0 -84
  33. package/site/components/loading/index.ts +0 -10
  34. package/site/components/loading/loading.less +0 -505
  35. package/site/components/loading/props.ts +0 -42
  36. package/site/components/popup/Popup.tsx +0 -102
  37. package/site/components/popup/index.ts +0 -10
  38. package/site/components/popup/popup.less +0 -125
  39. package/site/components/popup/props.ts +0 -63
  40. package/site/components/ripple/index.ts +0 -188
  41. package/site/components/ripple/ripple.less +0 -20
  42. package/site/components/snackbar/Snackbar.vue +0 -41
  43. package/site/components/snackbar/core.vue +0 -132
  44. package/site/components/snackbar/index.tsx +0 -270
  45. package/site/components/snackbar/props.ts +0 -97
  46. package/site/components/snackbar/snackbar.less +0 -135
  47. package/site/components/styles/common.less +0 -64
  48. package/site/components/styles/elevation.less +0 -126
  49. package/site/components/styles/var.less +0 -27
  50. package/site/components/utils/components.ts +0 -114
  51. package/site/components/utils/elements.ts +0 -104
  52. package/site/mobile/components/app-bar/AppBar.vue +0 -65
  53. package/site/mobile/components/app-bar/appBar.less +0 -57
  54. package/site/mobile/components/app-bar/index.ts +0 -10
  55. package/site/mobile/components/app-bar/props.ts +0 -25
  56. package/site/pc/components/AnimationBox.vue +0 -62
  57. package/site/pc/components/LogoAnimation.vue +0 -119
  58. package/site/pc/pages/index/index.less +0 -204
  59. /package/site/{components → pc/components}/code-example/codeExample.less +0 -0
  60. /package/site/{components → pc/components}/code-example/index.ts +0 -0
@@ -1,27 +0,0 @@
1
- // 文字
2
- @site-font-size-xs: 10px;
3
- @site-font-size-sm: 12px;
4
- @site-font-size-md: 14px;
5
- @site-font-size-lg: 16px;
6
-
7
- // 图标
8
- @site-icon-size-xs: 16px;
9
- @site-icon-size-sm: 18px;
10
- @site-icon-size-md: 20px;
11
- @site-icon-size-lg: 22px;
12
-
13
- //颜色
14
- @site-color-primary: #3a7afe;
15
- @site-color-info: #00afef;
16
- @site-color-success: #00c48f;
17
- @site-color-warning: #ff9f00;
18
- @site-color-danger: #f44336;
19
- @site-color-disabled: #e0e0e0;
20
-
21
- // 动画函数
22
- @site-cubic-bezier: cubic-bezier(0.25, 0.8, 0.5, 1);
23
-
24
- // 阴影
25
- @site-shadow-key-umbra-opacity: rgba(0, 0, 0, 0.2);
26
- @site-shadow-key-penumbra-opacity: rgba(0, 0, 0, 0.14);
27
- @site-shadow-key-ambient-opacity: rgba(0, 0, 0, 0.12);
@@ -1,114 +0,0 @@
1
- import { createApp, h, onActivated, onDeactivated, onMounted, onUnmounted, ref, Ref } from 'vue'
2
- import type { Component } from 'vue'
3
- import { isArray } from '@varlet/shared'
4
-
5
- export interface MountInstance {
6
- instance: any
7
- unmount: () => void
8
- }
9
-
10
- export function pickProps(props: any, propsKey: string): any
11
- export function pickProps(props: any, propsKey: string[]): any
12
- export function pickProps(props: any, propsKey: any): any {
13
- return Array.isArray(propsKey)
14
- ? propsKey.reduce((pickedProps: any, key) => {
15
- pickedProps[key] = props[key]
16
- return pickedProps
17
- }, {})
18
- : props[propsKey]
19
- }
20
-
21
- export function mount(component: Component): MountInstance {
22
- const app = createApp(component)
23
- const host = document.createElement('div')
24
- document.body.appendChild(host)
25
-
26
- return {
27
- instance: app.mount(host),
28
- unmount() {
29
- app.unmount()
30
- document.body.removeChild(host)
31
- }
32
- }
33
- }
34
-
35
- export function mountInstance(
36
- component: any,
37
- props: Record<string, any> = {},
38
- eventListener: Record<string, any> = {}
39
- ): {
40
- unmountInstance: () => void
41
- } {
42
- const Host = {
43
- setup() {
44
- return () =>
45
- h(component, {
46
- ...props,
47
- ...eventListener
48
- })
49
- }
50
- }
51
-
52
- const { unmount } = mount(Host)
53
- return { unmountInstance: unmount }
54
- }
55
-
56
- export function useTeleport() {
57
- const disabled: Ref<boolean> = ref(false)
58
-
59
- onActivated(() => {
60
- disabled.value = false
61
- })
62
-
63
- onDeactivated(() => {
64
- disabled.value = true
65
- })
66
-
67
- return {
68
- disabled,
69
- }
70
- }
71
-
72
- type ClassName = string | undefined | null
73
- type Classes = (ClassName | [any, ClassName, ClassName?])[]
74
-
75
- export function createNamespace(name: string) {
76
- const namespace = `var-site-${name}`
77
-
78
- const createBEM = (suffix?: string): string => {
79
- if (!suffix) return namespace
80
-
81
- return suffix.startsWith('--') ? `${namespace}${suffix}` : `${namespace}__${suffix}`
82
- }
83
-
84
- const classes = (...classes: Classes): any[] => {
85
- return classes.map((className) => {
86
- if (isArray(className)) {
87
- const [condition, truthy, falsy = null] = className
88
- return condition ? truthy : falsy
89
- }
90
-
91
- return className
92
- })
93
- }
94
-
95
- return {
96
- n: createBEM,
97
- classes,
98
- }
99
- }
100
-
101
- export function call<P extends any[], R>(fn?: ((...arg: P) => R) | null, ...arg: P): R | undefined {
102
- if (fn) return fn(...arg)
103
- }
104
-
105
- export function useRouteListener(cb: () => void) {
106
- onMounted(() => {
107
- window.addEventListener('hashchange', cb)
108
- window.addEventListener('popstate', cb)
109
- })
110
- onUnmounted(() => {
111
- window.removeEventListener('hashchange', cb)
112
- window.removeEventListener('popstate', cb)
113
- })
114
- }
@@ -1,104 +0,0 @@
1
- import { isNumber, isString, toNumber, kebabCase } from '@varlet/shared'
2
- import type { StyleVars } from '@varlet/cli/client'
3
-
4
- export function getLeft(element: HTMLElement): number {
5
- const { left } = element.getBoundingClientRect()
6
-
7
- return left + (document.body.scrollLeft || document.documentElement.scrollLeft)
8
- }
9
-
10
- // example 1rem
11
- export const isRem = (value: unknown): value is string => isString(value) && value.endsWith('rem')
12
-
13
- // example 1 || 1px
14
- export const isPx = (value: unknown): value is string | number =>
15
- (isString(value) && value.endsWith('px')) || isNumber(value)
16
-
17
- // example 1%
18
- export const isPercent = (value: unknown): value is string => isString(value) && value.endsWith('%')
19
-
20
- // example 1vw
21
- export const isVw = (value: unknown): value is string => isString(value) && value.endsWith('vw')
22
-
23
- // example 1vh
24
- export const isVh = (value: unknown): value is string => isString(value) && value.endsWith('vh')
25
-
26
- // example return 1
27
- export const toPxNum = (value: unknown): number => {
28
- if (isNumber(value)) {
29
- return value
30
- }
31
-
32
- if (isPx(value)) {
33
- return +(value as string).replace('px', '')
34
- }
35
-
36
- if (isVw(value)) {
37
- return (+(value as string).replace('vw', '') * window.innerWidth) / 100
38
- }
39
-
40
- if (isVh(value)) {
41
- return (+(value as string).replace('vh', '') * window.innerHeight) / 100
42
- }
43
-
44
- if (isRem(value)) {
45
- const num = +(value as string).replace('rem', '')
46
- const rootFontSize = window.getComputedStyle(document.documentElement).fontSize
47
-
48
- return num * parseFloat(rootFontSize)
49
- }
50
-
51
- if (isString(value)) {
52
- return toNumber(value)
53
- }
54
-
55
- // % and other
56
- return 0
57
- }
58
-
59
- // example return 1px 1% 1vw 1vh 1rem null
60
- export const toSizeUnit = (value: unknown) => {
61
- if (value == null) {
62
- return undefined
63
- }
64
-
65
- if (isPercent(value) || isVw(value) || isVh(value) || isRem(value)) {
66
- return value
67
- }
68
-
69
- return `${toPxNum(value)}px`
70
- }
71
-
72
- export function formatStyleVars(styleVars: StyleVars | null) {
73
- return Object.entries(styleVars ?? {}).reduce((styles, [key, value]) => {
74
- const cssVar = key.startsWith('--') ? key : `--${kebabCase(key)}`
75
- styles[cssVar] = value
76
-
77
- return styles
78
- }, {} as StyleVars)
79
- }
80
-
81
- export function doubleRaf() {
82
- return new Promise((resolve) => {
83
- requestAnimationFrame(() => {
84
- requestAnimationFrame(resolve)
85
- })
86
- })
87
- }
88
-
89
- export function supportTouch() {
90
- const inBrowser = typeof window !== 'undefined'
91
- return inBrowser && 'ontouchstart' in window
92
- }
93
-
94
- export const multiplySizeUnit = (value: unknown, quantity = 1) => {
95
- if (value == null) {
96
- return undefined
97
- }
98
-
99
- const legalSize = toSizeUnit(value) as string
100
-
101
- const unit = legalSize.match(/(vh|%|rem|px|vw)$/)![0]
102
-
103
- return `${parseFloat(legalSize) * quantity}${unit}`
104
- }
@@ -1,65 +0,0 @@
1
- <template>
2
- <div
3
- :class="classes(n(), [elevation, 'var-site-elevation--3'])"
4
- :style="{
5
- background: color,
6
- color: textColor,
7
- }"
8
- >
9
- <div :class="n('left')">
10
- <slot name="left" />
11
- <div :class="n('title')" :style="{ paddingLeft }" v-if="titlePosition === 'left'">
12
- <slot>{{ title }}</slot>
13
- </div>
14
- </div>
15
-
16
- <div :class="n('title')" v-if="titlePosition === 'center'">
17
- <slot>{{ title }}</slot>
18
- </div>
19
-
20
- <div :class="n('right')">
21
- <div :class="n('title')" :style="{ paddingRight }" v-if="titlePosition === 'right'">
22
- <slot>{{ title }}</slot>
23
- </div>
24
- <slot name="right" />
25
- </div>
26
- </div>
27
- </template>
28
-
29
- <script lang="ts">
30
- import { defineComponent, ref, Ref, onMounted, onUpdated } from 'vue'
31
- import { props } from './props'
32
- import { createNamespace } from '../../../components/utils/components'
33
-
34
- const { n, classes } = createNamespace('app-bar')
35
-
36
- export default defineComponent({
37
- name: 'VarAppBar',
38
- props,
39
- setup(props, { slots }) {
40
- const paddingLeft: Ref<number | undefined> = ref()
41
- const paddingRight: Ref<number | undefined> = ref()
42
-
43
- const computePadding = () => {
44
- paddingLeft.value = slots.left ? 0 : undefined
45
- paddingRight.value = slots.right ? 0 : undefined
46
- }
47
-
48
- onMounted(computePadding)
49
- onUpdated(computePadding)
50
-
51
- return {
52
- n,
53
- classes,
54
- paddingLeft,
55
- paddingRight,
56
- }
57
- },
58
- })
59
- </script>
60
-
61
- <style lang="less">
62
- @import '../../../components/styles/common';
63
- @import '../../../components/styles/elevation';
64
- @import './appBar';
65
- </style>
@@ -1,57 +0,0 @@
1
- @site-app-bar-color: var(--site-color-primary);
2
- @site-app-bar-height: 54px;
3
- @site-app-bar-text-color: #fff;
4
- @site-app-bar-title-padding: 0 12px;
5
- @site-app-bar-left-gap: 6px;
6
- @site-app-bar-right-gap: 6px;
7
-
8
- :root {
9
- --site-app-bar-color: @site-app-bar-color;
10
- --site-app-bar-title-padding: @site-app-bar-title-padding;
11
- --site-app-bar-text-color: #fff;
12
- --site-app-bar-height: @site-app-bar-height;
13
- --site-app-bar-left-gap: @site-app-bar-left-gap;
14
- --site-app-bar-right-gap: @site-app-bar-right-gap;
15
- }
16
-
17
- .var-site-app-bar {
18
- position: relative;
19
- display: flex;
20
- width: 100%;
21
- justify-content: center;
22
- align-items: center;
23
- height: var(--site-app-bar-height);
24
- background: var(--site-app-bar-color);
25
- color: var(--site-app-bar-text-color);
26
- transition: background-color 0.25s;
27
-
28
- &__title {
29
- flex: 1;
30
- display: flex;
31
- justify-content: center;
32
- white-space: nowrap;
33
- text-overflow: ellipsis;
34
- overflow: hidden;
35
- padding: var(--site-app-bar-title-padding);
36
- }
37
-
38
- &__left,
39
- &__right {
40
- display: flex;
41
- align-items: center;
42
- height: 100%;
43
- z-index: 2;
44
- }
45
-
46
- &__left {
47
- position: absolute;
48
- top: 0;
49
- left: var(--site-app-bar-left-gap);
50
- }
51
-
52
- &__right {
53
- position: absolute;
54
- top: 0;
55
- right: var(--site-app-bar-right-gap);
56
- }
57
- }
@@ -1,10 +0,0 @@
1
- import type { App } from 'vue'
2
- import AppBar from './AppBar.vue'
3
-
4
- AppBar.install = function (app: App) {
5
- app.component(AppBar.name, AppBar)
6
- }
7
-
8
- export const _AppBarComponent = AppBar
9
-
10
- export default AppBar
@@ -1,25 +0,0 @@
1
- export function positionValidator(position: string): boolean {
2
- const validPositions = ['left', 'center', 'right']
3
- return validPositions.includes(position)
4
- }
5
-
6
- export const props = {
7
- color: {
8
- type: String,
9
- },
10
- textColor: {
11
- type: String,
12
- },
13
- title: {
14
- type: String,
15
- },
16
- titlePosition: {
17
- type: String,
18
- default: 'left',
19
- validator: positionValidator,
20
- },
21
- elevation: {
22
- type: Boolean,
23
- default: true,
24
- },
25
- }
@@ -1,62 +0,0 @@
1
- <script lang="ts">
2
- import { defineComponent, onMounted, onUnmounted, ref, useAttrs } from 'vue'
3
- import { animationBoxData, animationEl, animationElClientRect, isMountedCount } from '../floating'
4
-
5
- export default defineComponent({
6
- name: 'AnimationBox',
7
- setup() {
8
- const varletLogoAnimationRef = ref<HTMLElement>()
9
- const domObserve = new MutationObserver(_onDomChanged)
10
- animationBoxData.attrs = useAttrs()
11
-
12
- onMounted(() => {
13
- animationEl.value = varletLogoAnimationRef.value
14
- varletLogoAnimationRef.value && domObserve.observe(varletLogoAnimationRef.value, { childList: true })
15
-
16
-
17
- isMountedCount.value <= 2 && (isMountedCount.value += 1)
18
- })
19
-
20
- function _onDomChanged(mutations: MutationRecord[]) {
21
- if (!mutations.length || !varletLogoAnimationRef.value) return;
22
- const normal = animationEl.value?.getBoundingClientRect()
23
- const hasFloat: boolean = _onGetNodePosition(varletLogoAnimationRef.value);
24
-
25
- animationElClientRect.value = hasFloat ? normal : {
26
- top: (animationEl.value?.getBoundingClientRect().top || 0) + window.scrollY,
27
- left: (animationEl.value?.getBoundingClientRect().left || 0),
28
- width: animationEl.value?.getBoundingClientRect().width || 0,
29
- height: animationEl.value?.getBoundingClientRect().height || 0,
30
- }
31
- }
32
-
33
- function _onGetNodePosition(node: Element, stopNode = document.body): boolean {
34
- const css = window.getComputedStyle(node, null);
35
- if (css.position === 'fixed') {
36
- return true
37
- }
38
- if (node === stopNode) {
39
- return false
40
- }
41
-
42
- return _onGetNodePosition(node.parentElement || document.body)
43
- }
44
-
45
- onUnmounted(() => {
46
- domObserve.disconnect()
47
- varletLogoAnimationRef.value = undefined
48
- animationEl.value = undefined
49
- animationElClientRect.value = undefined
50
- })
51
-
52
- return {
53
- varletLogoAnimationRef,
54
- }
55
- },
56
- })
57
- </script>
58
-
59
- <template>
60
- <div ref="varletLogoAnimationRef"></div>
61
- </template>
62
-
@@ -1,119 +0,0 @@
1
- <script lang="ts">
2
- import config from '@config'
3
- import { get } from 'lodash-es'
4
- import { computed, defineComponent, onMounted, onBeforeUnmount, ref, watch, nextTick } from 'vue'
5
- import { animationBoxData, animationEl, animationElClientRect, isMountedCount } from '../floating'
6
-
7
- import type { Ref, StyleValue } from 'vue'
8
- import type { Rect } from '../floating'
9
-
10
- export default defineComponent({
11
- name: 'LogoAnimation',
12
- setup() {
13
- const logo: Ref<string> = get(config, 'logo')
14
- const proxyRect: Ref<Rect | undefined> = ref<Rect>()
15
- const floatingState: Ref<boolean> = ref<boolean>(false)
16
-
17
- watch(animationElClientRect, async (newClientRect) => {
18
- if (newClientRect) {
19
- isMountedCount.value > 1 && (floatingState.value = true)
20
-
21
- proxyRect.value = newClientRect
22
- }
23
- })
24
-
25
- const styles: Ref<StyleValue | undefined> = computed(() => ({
26
- width: `${proxyRect.value?.width}px`,
27
- height: `${proxyRect.value?.height}px`,
28
- top: `${proxyRect.value?.top}px`,
29
- left: `${proxyRect.value?.left}px`,
30
- }))
31
-
32
- onMounted(() => {
33
- window.addEventListener('resize', resetPosition, false)
34
- })
35
-
36
- onBeforeUnmount(() => {
37
- resetTimer && clearTimeout(resetTimer)
38
- window.removeEventListener('resize', resetPosition)
39
- })
40
-
41
- const land = () => {
42
- floatingState.value = false
43
- }
44
-
45
- let resetTimer: number
46
-
47
- const resetPosition = async () => {
48
- if (floatingState.value) {
49
- floatingState.value = false
50
- await nextTick()
51
- }
52
- clearTimeout(resetTimer)
53
-
54
- const newBRect = animationEl.value?.getBoundingClientRect()
55
- if (newBRect) {
56
- resetTimer = window.setTimeout(() => {
57
- proxyRect.value = newBRect
58
- }, 200)
59
- }
60
- }
61
-
62
- return {
63
- logo,
64
- animationBoxData,
65
- styles,
66
- animationEl,
67
- floatingState,
68
- land,
69
- }
70
- },
71
- })
72
- </script>
73
-
74
- <template>
75
- <Teleport :to="animationEl || 'body'">
76
- <img
77
- v-if="logo && animationEl"
78
- v-bind="animationBoxData.attrs"
79
- :class="{ 'varlet-cli-logo-position': !animationEl, 'varlet-cli-logo-show': !floatingState }"
80
- :style="styles"
81
- :src="logo"
82
- class="varlet-cli-logo-entity"
83
- alt="logo"
84
- />
85
- </Teleport>
86
- <img
87
- v-if="logo && animationEl"
88
- v-bind="animationBoxData.attrs"
89
- :class="{ 'varlet-cli-logo-show': floatingState }"
90
- :style="styles"
91
- :src="logo"
92
- @transitionend="land"
93
- class="varlet-cli-logo-entity varlet-cli-logo-position varlet-cli-logo-transition"
94
- alt="logo"
95
- />
96
- </template>
97
-
98
- <style lang="less">
99
- .varlet-cli-logo-transition {
100
- width: 100%;
101
- height: 100%;
102
- }
103
-
104
- .varlet-cli-logo-entity {
105
- z-index: 10;
106
- pointer-events: none;
107
- opacity: 0;
108
- }
109
-
110
- .varlet-cli-logo-position {
111
- position: fixed;
112
- transition: 0.5s ease-in-out;
113
- transition-property: left, top, height, width;
114
- }
115
-
116
- .varlet-cli-logo-show {
117
- opacity: 1;
118
- }
119
- </style>