@solar-taro/ui-sun 0.0.0

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 (56) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/README.md +11 -0
  3. package/eslint.config.cjs +22 -0
  4. package/package.json +17 -0
  5. package/project.json +28 -0
  6. package/shims-vue.d.ts +5 -0
  7. package/src/_color.scss +41 -0
  8. package/src/_sun.scss +15 -0
  9. package/src/_wx.scss +23 -0
  10. package/src/accordion/index.scss +18 -0
  11. package/src/accordion/index.ts +1 -0
  12. package/src/accordion/index.vue +27 -0
  13. package/src/chip/index.scss +77 -0
  14. package/src/chip/index.ts +1 -0
  15. package/src/chip/index.vue +27 -0
  16. package/src/fab/fab-group.vue +17 -0
  17. package/src/fab/fab.vue +5 -0
  18. package/src/fab/index.scss +18 -0
  19. package/src/fab/index.ts +2 -0
  20. package/src/index.scss +3 -0
  21. package/src/index.ts +11 -0
  22. package/src/lazy-render/index.ts +1 -0
  23. package/src/lazy-render/index.vue +38 -0
  24. package/src/navbar/index.scss +18 -0
  25. package/src/navbar/index.ts +1 -0
  26. package/src/navbar/index.vue +26 -0
  27. package/src/popover/index.scss +100 -0
  28. package/src/popover/index.ts +1 -0
  29. package/src/popover/index.vue +56 -0
  30. package/src/segment/index.scss +44 -0
  31. package/src/segment/index.ts +2 -0
  32. package/src/segment/injection.ts +8 -0
  33. package/src/segment/segment-btn.vue +28 -0
  34. package/src/segment/segment.vue +86 -0
  35. package/src/spinner/index.scss +84 -0
  36. package/src/spinner/index.ts +1 -0
  37. package/src/spinner/index.vue +26 -0
  38. package/src/sudoku/index.scss +22 -0
  39. package/src/sudoku/index.ts +2 -0
  40. package/src/sudoku/sudoku-item.vue +5 -0
  41. package/src/sudoku/sudoku.vue +23 -0
  42. package/src/table/_table-cell.scss +50 -0
  43. package/src/table/_table-row.scss +14 -0
  44. package/src/table/_table.scss +70 -0
  45. package/src/table/index.scss +3 -0
  46. package/src/table/index.ts +3 -0
  47. package/src/table/table-cell.vue +26 -0
  48. package/src/table/table-row.vue +12 -0
  49. package/src/table/table.vue +39 -0
  50. package/src/virtual-scroll/index.scss +17 -0
  51. package/src/virtual-scroll/index.ts +1 -0
  52. package/src/virtual-scroll/index.vue +138 -0
  53. package/tsconfig.json +21 -0
  54. package/tsconfig.lib.json +26 -0
  55. package/tsconfig.spec.json +28 -0
  56. package/vite.config.ts +130 -0
@@ -0,0 +1,138 @@
1
+ <template>
2
+ <scroll-view
3
+ v-bind="$attrs"
4
+ :id="id"
5
+ class="sun-virtual-scroll"
6
+ :refresher-enabled="refresher"
7
+ :refresher-triggered="refreshing"
8
+ :refresher-background="refresherBg"
9
+ :scroll-x="!isVertical"
10
+ :scroll-y="isVertical"
11
+ :enhanced="true"
12
+ :enable-passive="true"
13
+ :lower-threshold="300"
14
+ @scroll.passive="onScroll($event)"
15
+ @refresherrefresh="vibrator.short('light'); emit('refresh')"
16
+ @scrolltolower="emit('lower')">
17
+ <view class="sun-virtual-scroll-content-container" :style="contentContainerStyle">
18
+ <view
19
+ v-for="(item, index) in visibleItems"
20
+ :key="(item as any)[itemKey!] ?? index"
21
+ class="sun-virtual-scroll-item"
22
+ :style="itemStyle">
23
+ <slot :item="item" :index="index"></slot>
24
+ </view>
25
+ </view>
26
+
27
+ <view class="sun-virtual-scroll-spacer" :style="spacerStyle"></view>
28
+ </scroll-view>
29
+ </template>
30
+
31
+ <script lang="ts">
32
+ let nextId = 1;
33
+ </script>
34
+
35
+ <script lang="ts" setup>
36
+ import { withPixel } from '@solar-kit/core';
37
+ import { rpxToPx, vibrator } from '@solar-taro/core';
38
+ import { createSelectorQuery, NodesRef } from '@tarojs/taro';
39
+ import { computed, CSSProperties, onMounted, ref } from 'vue';
40
+
41
+ const emit = defineEmits<{
42
+ (e: 'refresh'): void;
43
+ (e: 'lower'): void;
44
+ }>();
45
+
46
+ const props = withDefaults(
47
+ defineProps<{
48
+ refreshing?: boolean;
49
+ refresher?: boolean;
50
+ refresherBg?: string;
51
+ direction?: 'vertical' | 'horizontal';
52
+ items: Record<string, any>[];
53
+ itemSize: number | string;
54
+ itemKey?: string;
55
+ id?: string;
56
+ bottomSpace?: number;
57
+ }>(),
58
+ {
59
+ refresherBg: 'transparent',
60
+ direction: 'vertical',
61
+ id: () => `sun-virtual-scroll-${nextId++}`,
62
+ bottomSpace: 0
63
+ }
64
+ );
65
+
66
+ let rafId: number;
67
+
68
+ const visibleItemCount = ref(0);
69
+ const startIndex = ref(0);
70
+ const startOffset = ref(0);
71
+
72
+ const isVertical = computed(() => props.direction === 'vertical');
73
+ const contentContainerStyle = computed<CSSProperties>(() => ({
74
+ right: isVertical.value ? '0' : 'auto',
75
+ transform: `translate${isVertical.value ? 'Y' : 'X'}(${startOffset.value}px)`,
76
+ 'white-space': isVertical.value ? 'normal' : 'nowrap'
77
+ }));
78
+ const itemSizePx = computed(() => {
79
+ if (typeof props.itemSize === 'number') {
80
+ return props.itemSize;
81
+ }
82
+
83
+ if (props.itemSize.endsWith('rpx')) {
84
+ return rpxToPx(parseFloat(props.itemSize));
85
+ }
86
+
87
+ return parseFloat(props.itemSize)
88
+ })
89
+ const spacerSize = computed(() => itemSizePx.value * props.items!.length);
90
+ const spacerStyle = computed(() => ({
91
+ [isVertical.value ? 'height' : 'width']: withPixel(spacerSize.value + props.bottomSpace)
92
+ }));
93
+ const itemStyle = computed(() => ({
94
+ display: isVertical.value ? 'block' : 'inline-block',
95
+ [isVertical.value ? 'height' : 'width']: withPixel(itemSizePx.value)
96
+ }))
97
+ const visibleItems = computed(() =>
98
+ props.items!.slice(
99
+ Math.max(startIndex.value - visibleItemCount.value, 0),
100
+ startIndex.value + visibleItemCount.value * 2
101
+ )
102
+ );
103
+
104
+ function onScroll({ detail }: any) {
105
+ rafId && cancelAnimationFrame(rafId);
106
+ rafId = requestAnimationFrame(() => {
107
+ const scrollDistance = isVertical.value ? detail.scrollTop : detail.scrollLeft;
108
+ startIndex.value = ~~(scrollDistance / itemSizePx.value);
109
+
110
+ if (startIndex.value > visibleItemCount.value - 1) {
111
+ startOffset.value = scrollDistance - (itemSizePx.value * visibleItemCount.value) - (scrollDistance % itemSizePx.value);
112
+ } else {
113
+ startOffset.value = scrollDistance - (scrollDistance % (itemSizePx.value * visibleItemCount.value));
114
+ }
115
+
116
+ rafId = 0;
117
+ });
118
+ }
119
+
120
+ function initViewport() {
121
+ setTimeout(() => {
122
+ createSelectorQuery().select(`#${props.id}`).boundingClientRect(result => {
123
+ // 如果获取不到节点信息,重新初始化
124
+ if (!result) {
125
+ return initViewport()
126
+ }
127
+
128
+ const { height, width } = result as NodesRef.BoundingClientRectCallbackResult;
129
+ const viewportSize = isVertical.value ? height : width;
130
+ visibleItemCount.value = Math.ceil(viewportSize / itemSizePx.value);
131
+ }).exec();
132
+ });
133
+ }
134
+
135
+ onMounted(() => {
136
+ initViewport();
137
+ });
138
+ </script>
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "forceConsistentCasingInFileNames": true,
5
+ "strict": true,
6
+ "noImplicitOverride": true,
7
+ "noImplicitReturns": true,
8
+ "noFallthroughCasesInSwitch": true,
9
+ "noPropertyAccessFromIndexSignature": true
10
+ },
11
+ "files": [],
12
+ "include": [],
13
+ "references": [
14
+ {
15
+ "path": "./tsconfig.lib.json"
16
+ },
17
+ {
18
+ "path": "./tsconfig.spec.json"
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "declaration": true
6
+ },
7
+ "include": [
8
+ "src/**/*.ts",
9
+ "index.ts",
10
+ "index.ts"
11
+ ],
12
+ "exclude": [
13
+ "vite.config.ts",
14
+ "vite.config.mts",
15
+ "vitest.config.ts",
16
+ "vitest.config.mts",
17
+ "src/**/*.test.ts",
18
+ "src/**/*.spec.ts",
19
+ "src/**/*.test.tsx",
20
+ "src/**/*.spec.tsx",
21
+ "src/**/*.test.js",
22
+ "src/**/*.spec.js",
23
+ "src/**/*.test.jsx",
24
+ "src/**/*.spec.jsx"
25
+ ]
26
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": [
6
+ "vitest/globals",
7
+ "vitest/importMeta",
8
+ "vite/client",
9
+ "node",
10
+ "vitest"
11
+ ]
12
+ },
13
+ "include": [
14
+ "vite.config.ts",
15
+ "vite.config.mts",
16
+ "vitest.config.ts",
17
+ "vitest.config.mts",
18
+ "src/**/*.test.ts",
19
+ "src/**/*.spec.ts",
20
+ "src/**/*.test.tsx",
21
+ "src/**/*.spec.tsx",
22
+ "src/**/*.test.js",
23
+ "src/**/*.spec.js",
24
+ "src/**/*.test.jsx",
25
+ "src/**/*.spec.jsx",
26
+ "src/**/*.d.ts"
27
+ ]
28
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,130 @@
1
+ /// <reference types='vitest' />
2
+ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
3
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
4
+ import vue from '@vitejs/plugin-vue';
5
+ import * as path from 'path';
6
+ import { defineConfig } from 'vite';
7
+ import dts from 'vite-plugin-dts';
8
+
9
+ export default defineConfig({
10
+ root: __dirname,
11
+ cacheDir: '../../node_modules/.vite/ui-sun',
12
+ plugins: [
13
+ nxViteTsPaths(),
14
+ nxCopyAssetsPlugin(['*.md']),
15
+ dts({
16
+ entryRoot: 'src',
17
+ include: ['src'],
18
+ tsconfigPath: path.join(__dirname, 'tsconfig.lib.json'),
19
+ copyDtsFiles: true,
20
+ }),
21
+ vue({
22
+ template: {
23
+ transformAssetUrls: {
24
+ video: ['src', 'poster'],
25
+ 'live-player': ['src'],
26
+ audio: ['src'],
27
+ source: ['src'],
28
+ image: ['src'],
29
+ 'cover-image': ['src']
30
+ },
31
+ compilerOptions: {
32
+ mode: 'module',
33
+ optimizeImports: true,
34
+ isNativeTag: tag => {
35
+ return [
36
+ 'slot-view',
37
+ 'view',
38
+ 'scroll-view',
39
+ 'swiper',
40
+ 'cover-view',
41
+ 'cover-image',
42
+ 'icon',
43
+ 'text',
44
+ 'rich-text',
45
+ 'progress',
46
+ 'button',
47
+ 'checkbox',
48
+ 'form',
49
+ 'input',
50
+ 'label',
51
+ 'picker',
52
+ 'picker-view',
53
+ 'picker-view-column',
54
+ 'radio',
55
+ 'radio-group',
56
+ 'checkbox-group',
57
+ 'slider',
58
+ 'switch',
59
+ 'textarea',
60
+ 'navigator',
61
+ 'audio',
62
+ 'image',
63
+ 'video',
64
+ 'camera',
65
+ 'live-player',
66
+ 'live-pusher',
67
+ 'map',
68
+ 'canvas',
69
+ 'open-data',
70
+ 'web-view',
71
+ 'swiper-item',
72
+ 'movable-area',
73
+ 'movable-view',
74
+ 'functional-page-navigator',
75
+ 'ad',
76
+ 'block',
77
+ 'import',
78
+ 'official-account',
79
+ 'editor'
80
+ ].some(o => o === tag) || tag.startsWith('van-')
81
+ },
82
+ }
83
+ }
84
+ })
85
+ ],
86
+ // Uncomment this if you are using workers.
87
+ // worker: {
88
+ // plugins: [ nxViteTsPaths() ],
89
+ // },
90
+ // Configuration for building your library.
91
+ // See: https://vitejs.dev/guide/build.html#library-mode
92
+ build: {
93
+ target: 'es2019',
94
+ outDir: '../../dist/ui-sun',
95
+ emptyOutDir: true,
96
+ reportCompressedSize: true,
97
+ lib: {
98
+ // Could also be a dictionary or array of multiple entry points.
99
+ entry: 'src/index.ts',
100
+ name: 'ui-sun',
101
+ fileName: 'index',
102
+ // Change this to the formats you want to support.
103
+ // Don't forget to update your package.json as well.
104
+ formats: ['es'],
105
+ },
106
+ rollupOptions: {
107
+ // External packages that should not be bundled into your library.
108
+ external: [
109
+ 'vue',
110
+ 'rxjs',
111
+ /@tarojs.+/,
112
+ /@ngify.+/,
113
+ /@opper.+/,
114
+ /@solar-kit.+/,
115
+ /@solar-taro.+/,
116
+ ],
117
+ },
118
+ },
119
+ test: {
120
+ watch: false,
121
+ globals: true,
122
+ environment: 'node',
123
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
124
+ reporters: ['default'],
125
+ coverage: {
126
+ reportsDirectory: '../../coverage/ui-sun',
127
+ provider: 'v8',
128
+ },
129
+ },
130
+ });