vanilla-jui 1.4.5 → 1.4.6
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/README.md +6 -0
- package/dist/index.d.ts +1273 -1896
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +21 -2
- package/src/components/accordion.ts +297 -216
- package/src/components/flow.ts +222 -258
- package/src/components/form.ts +44 -102
- package/src/components/menu.ts +268 -356
- package/src/components/modal.ts +181 -641
- package/src/components/offcanvas.ts +225 -106
- package/src/components/pagination.ts +296 -326
- package/src/components/sticky.ts +55 -54
- package/src/components/swiper.ts +237 -247
- package/src/components/tabs.ts +278 -271
- package/src/components/toc.ts +42 -46
- package/src/core/Component.ts +69 -47
- package/src/css/accordion.css +2 -2
- package/src/css/animation.css +1 -5
- package/src/css/avatar.css +1 -1
- package/src/css/badge.css +1 -1
- package/src/css/breadcrumb.css +9 -10
- package/src/css/button.css +1 -1
- package/src/css/card.css +2 -2
- package/src/css/color.css +974 -1002
- package/src/css/color_p3.css +974 -1004
- package/src/css/components.css +1 -1
- package/src/css/content.css +72 -63
- package/src/css/drop.css +1 -1
- package/src/css/editor.css +14 -14
- package/src/css/flow.css +4 -14
- package/src/css/font.css +5 -4
- package/src/css/form.css +76 -52
- package/src/css/gradient.css +299 -222
- package/src/css/icon.css +57 -57
- package/src/css/index.css +1 -1
- package/src/css/layout.css +13 -10
- package/src/css/loading.css +60 -12
- package/src/css/menu.css +262 -188
- package/src/css/modal.css +1 -1
- package/src/css/offcanvas.css +9 -13
- package/src/css/pagination.css +5 -1
- package/src/css/popup.css +1 -1
- package/src/css/skeleton.css +3 -2
- package/src/css/status.css +2 -3
- package/src/css/swiper.css +1 -1
- package/src/css/table.css +1 -1
- package/src/css/tabs.css +12 -11
- package/src/css/tag.css +1 -1
- package/src/css/theme-palette.css +19 -5
- package/src/css/themes/default/accordion.css +61 -61
- package/src/css/themes/default/avatar.css +54 -54
- package/src/css/themes/default/badge.css +62 -62
- package/src/css/themes/default/breadcrumb.css +23 -23
- package/src/css/themes/default/button.css +203 -203
- package/src/css/themes/default/content.css +53 -53
- package/src/css/themes/default/drop.css +10 -10
- package/src/css/themes/default/editor.css +9 -9
- package/src/css/themes/default/index.css +1 -1
- package/src/css/themes/default/loading.css +26 -20
- package/src/css/themes/default/menu.css +75 -11
- package/src/css/themes/default/modal.css +32 -36
- package/src/css/themes/default/pagination.css +7 -7
- package/src/css/themes/default/popup.css +6 -6
- package/src/css/themes/default/swiper.css +32 -32
- package/src/css/themes/default/table.css +16 -16
- package/src/css/themes/default/tabs.css +30 -30
- package/src/css/themes/default/tag.css +71 -71
- package/src/css/themes/default/theme-palette.css +11 -11
- package/src/css/themes/default/tip.css +42 -42
- package/src/css/themes/default/toast.css +60 -60
- package/src/css/themes/default/toolbar.css +23 -29
- package/src/css/themes/default/tooltip.css +43 -13
- package/src/css/themes/index.css +1 -1
- package/src/css/tip.css +2 -2
- package/src/css/toast.css +3 -3
- package/src/css/tokens.css +12 -17
- package/src/css/toolbar.css +9 -10
- package/src/css/tooltip.css +3 -2
- package/src/index.ts +22 -19
- package/src/{components → primitives}/drop.ts +58 -49
- package/src/{components → primitives}/icons.ts +1 -1
- package/src/primitives/loading.ts +23 -0
- package/src/primitives/parabola.ts +388 -0
- package/src/primitives/popup.ts +61 -0
- package/src/{components → primitives}/theme.ts +88 -57
- package/src/{components → primitives}/toast.ts +18 -25
- package/src/{components → primitives}/tooltip.ts +100 -25
- package/src/utilities/browser.ts +23 -49
- package/src/utilities/class-name.ts +5 -0
- package/src/utilities/dom.ts +14 -32
- package/src/utilities/function.ts +4 -0
- package/src/utilities/http.ts +7 -7
- package/src/utilities/id.ts +57 -0
- package/src/utilities/object.ts +5 -0
- package/src/utilities/timer.ts +38 -0
- package/src/utilities/types.ts +420 -0
- package/src/{components → validation}/validator.ts +64 -53
- package/src/components/parabola.ts +0 -335
- package/src/utilities/cache.ts +0 -57
- package/src/utilities/core.ts +0 -614
- package/src/utilities/storage.ts +0 -46
package/src/components/sticky.ts
CHANGED
|
@@ -4,19 +4,19 @@ import Component, {
|
|
|
4
4
|
type ComponentDOM,
|
|
5
5
|
type ComponentRuntime,
|
|
6
6
|
} from '../core/Component.ts';
|
|
7
|
-
import { type ResolveSchema, resolveProps } from '../utilities/core.ts';
|
|
8
7
|
import { type DOMReference, all, requireContainer } from '../utilities/dom.ts';
|
|
8
|
+
import { type ResolveSchema, resolveProps } from '../utilities/types.ts';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type StickyOverflow = 'destroy' | 'ignore';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
interface StickyProps extends Record<string, unknown> {
|
|
13
13
|
target?: DOMReference;
|
|
14
14
|
parent?: DOMReference;
|
|
15
15
|
max?: number;
|
|
16
16
|
top?: number;
|
|
17
17
|
gap?: number;
|
|
18
18
|
overflow?: StickyOverflow;
|
|
19
|
-
|
|
19
|
+
onRefresh?: ((sticky: StickyInstance) => void) | null;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
interface ResolvedStickyProps extends Record<string, unknown> {
|
|
@@ -26,17 +26,15 @@ interface ResolvedStickyProps extends Record<string, unknown> {
|
|
|
26
26
|
top: number;
|
|
27
27
|
gap: number;
|
|
28
28
|
overflow: StickyOverflow;
|
|
29
|
-
|
|
29
|
+
onRefresh: ((sticky: StickyInstance) => void) | null;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
interface StickyStateItem {
|
|
33
33
|
element: HTMLElement;
|
|
34
34
|
top: number;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
interface StickyState extends Record<string, unknown> {
|
|
38
|
-
count: number;
|
|
39
|
-
top: number;
|
|
40
38
|
items: StickyStateItem[];
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -46,49 +44,57 @@ interface StickyDOM extends ComponentDOM {
|
|
|
46
44
|
targets: HTMLElement[];
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
interface
|
|
47
|
+
interface StickyOriginalStyle {
|
|
50
48
|
element: HTMLElement;
|
|
51
|
-
top: number;
|
|
52
49
|
originalPosition: string;
|
|
53
50
|
originalTop: string;
|
|
54
51
|
originalZIndex: string;
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
interface StickyRuntime extends ComponentRuntime {
|
|
58
|
-
active: boolean;
|
|
59
55
|
built: boolean;
|
|
60
|
-
ignored: boolean;
|
|
61
|
-
items: StickyRuntimeItem[];
|
|
62
56
|
}
|
|
63
57
|
|
|
58
|
+
interface StickyCache {
|
|
59
|
+
originalStyles: StickyOriginalStyle[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type StickyInstance = Component<
|
|
63
|
+
ResolvedStickyProps,
|
|
64
|
+
StickyState,
|
|
65
|
+
StickyDOM,
|
|
66
|
+
StickyCache
|
|
67
|
+
> & {
|
|
68
|
+
runtime: StickyRuntime;
|
|
69
|
+
build(): StickyInstance;
|
|
70
|
+
refresh(): StickyInstance;
|
|
71
|
+
};
|
|
72
|
+
|
|
64
73
|
const STICKY_PROPS_SCHEMA = {
|
|
65
74
|
target: { default: null },
|
|
66
75
|
parent: { default: null },
|
|
67
76
|
max: {
|
|
68
77
|
default: 10,
|
|
69
78
|
type: 'number',
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
message: 'expects a positive integer.',
|
|
79
|
+
integer: true,
|
|
80
|
+
greaterThan: 0,
|
|
73
81
|
},
|
|
74
82
|
top: {
|
|
75
83
|
default: 16,
|
|
76
84
|
type: 'number',
|
|
77
|
-
|
|
78
|
-
message: 'expects a positive number or 0.',
|
|
85
|
+
min: 0,
|
|
79
86
|
},
|
|
80
87
|
gap: {
|
|
81
88
|
default: 16,
|
|
82
89
|
type: 'number',
|
|
83
|
-
|
|
84
|
-
message: 'expects a positive number or 0.',
|
|
90
|
+
min: 0,
|
|
85
91
|
},
|
|
86
92
|
overflow: {
|
|
87
93
|
default: 'destroy',
|
|
88
94
|
type: 'string',
|
|
89
95
|
enum: ['destroy', 'ignore'],
|
|
90
96
|
},
|
|
91
|
-
|
|
97
|
+
onRefresh: { default: null, types: ['function', 'null'] },
|
|
92
98
|
} satisfies ResolveSchema<StickyProps>;
|
|
93
99
|
|
|
94
100
|
function normalizeProps(input: StickyProps): ResolvedStickyProps {
|
|
@@ -100,7 +106,7 @@ function normalizeProps(input: StickyProps): ResolvedStickyProps {
|
|
|
100
106
|
top: props.top as number,
|
|
101
107
|
gap: props.gap as number,
|
|
102
108
|
overflow: props.overflow as StickyOverflow,
|
|
103
|
-
|
|
109
|
+
onRefresh: props.onRefresh as ResolvedStickyProps['onRefresh'],
|
|
104
110
|
};
|
|
105
111
|
}
|
|
106
112
|
|
|
@@ -154,32 +160,30 @@ function resolveTarget(
|
|
|
154
160
|
* 用于给一个或多个元素应用 `position: sticky`,并按顺序计算 `top`
|
|
155
161
|
* 偏移,适合页面侧边栏中多个 widget 的堆叠吸附场景。
|
|
156
162
|
*/
|
|
157
|
-
|
|
163
|
+
class Sticky extends Component<
|
|
158
164
|
ResolvedStickyProps,
|
|
159
165
|
StickyState,
|
|
160
|
-
StickyDOM
|
|
166
|
+
StickyDOM,
|
|
167
|
+
StickyCache
|
|
161
168
|
> {
|
|
162
169
|
declare runtime: StickyRuntime;
|
|
170
|
+
declare cache: StickyCache;
|
|
163
171
|
|
|
164
172
|
/**
|
|
165
173
|
* 创建 Sticky 实例。
|
|
166
|
-
* @param {object} [
|
|
174
|
+
* @param {object} [props={}] Sticky 配置。
|
|
167
175
|
*/
|
|
168
|
-
constructor(
|
|
169
|
-
const
|
|
170
|
-
super(
|
|
176
|
+
constructor(props: StickyProps = {}) {
|
|
177
|
+
const settings = normalizeProps(props);
|
|
178
|
+
super(settings);
|
|
171
179
|
|
|
172
180
|
this.dom.parent = null;
|
|
173
181
|
this.dom.targets = [];
|
|
182
|
+
this.cache.originalStyles = [];
|
|
174
183
|
|
|
175
|
-
this.runtime.active = false;
|
|
176
184
|
this.runtime.built = false;
|
|
177
|
-
this.runtime.ignored = false;
|
|
178
|
-
this.runtime.items = [];
|
|
179
185
|
|
|
180
186
|
this.state = createDeepStore({
|
|
181
|
-
count: 0,
|
|
182
|
-
top: props.top,
|
|
183
187
|
items: [],
|
|
184
188
|
});
|
|
185
189
|
}
|
|
@@ -203,16 +207,14 @@ export class Sticky extends Component<
|
|
|
203
207
|
|
|
204
208
|
if (this.dom.targets.length === 0) return this;
|
|
205
209
|
|
|
206
|
-
this.
|
|
207
|
-
this.captureItems();
|
|
210
|
+
this.captureOriginalStyles();
|
|
208
211
|
this.apply();
|
|
209
212
|
return this;
|
|
210
213
|
}
|
|
211
214
|
|
|
212
|
-
private
|
|
213
|
-
this.
|
|
215
|
+
private captureOriginalStyles(): void {
|
|
216
|
+
this.cache.originalStyles = this.dom.targets.map((element) => ({
|
|
214
217
|
element,
|
|
215
|
-
top: this.props.top,
|
|
216
218
|
originalPosition: element.style.position,
|
|
217
219
|
originalTop: element.style.top,
|
|
218
220
|
originalZIndex: element.style.zIndex,
|
|
@@ -223,7 +225,6 @@ export class Sticky extends Component<
|
|
|
223
225
|
const { max, overflow } = this.props;
|
|
224
226
|
if (targets.length <= max) return targets;
|
|
225
227
|
|
|
226
|
-
this.runtime.ignored = overflow === 'ignore';
|
|
227
228
|
return overflow === 'ignore' ? [] : targets.slice(-max);
|
|
228
229
|
}
|
|
229
230
|
|
|
@@ -231,30 +232,27 @@ export class Sticky extends Component<
|
|
|
231
232
|
let nextTop = startTop;
|
|
232
233
|
const stateItems: StickyStateItem[] = [];
|
|
233
234
|
|
|
234
|
-
for (const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
item.element.style.top = `${nextTop}px`;
|
|
235
|
+
for (const element of this.dom.targets) {
|
|
236
|
+
element.style.position = 'sticky';
|
|
237
|
+
element.style.top = `${nextTop}px`;
|
|
238
238
|
|
|
239
|
-
stateItems.push({ element
|
|
240
|
-
nextTop +=
|
|
239
|
+
stateItems.push({ element, top: nextTop });
|
|
240
|
+
nextTop += element.offsetHeight + this.props.gap;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
this.setState({
|
|
244
|
-
count: this.runtime.items.length,
|
|
245
|
-
top: this.runtime.items[0]?.top ?? this.props.top,
|
|
246
244
|
items: stateItems,
|
|
247
245
|
});
|
|
248
246
|
|
|
249
|
-
if (typeof this.props.
|
|
250
|
-
this.props.
|
|
247
|
+
if (typeof this.props.onRefresh === 'function') {
|
|
248
|
+
this.props.onRefresh(this);
|
|
251
249
|
}
|
|
252
250
|
|
|
253
251
|
return nextTop;
|
|
254
252
|
}
|
|
255
253
|
|
|
256
254
|
private restore(): void {
|
|
257
|
-
for (const item of this.
|
|
255
|
+
for (const item of this.cache.originalStyles) {
|
|
258
256
|
item.element.style.position = item.originalPosition;
|
|
259
257
|
item.element.style.top = item.originalTop;
|
|
260
258
|
item.element.style.zIndex = item.originalZIndex;
|
|
@@ -266,7 +264,11 @@ export class Sticky extends Component<
|
|
|
266
264
|
* @returns {Sticky} 当前实例。
|
|
267
265
|
*/
|
|
268
266
|
refresh(): this {
|
|
269
|
-
if (
|
|
267
|
+
if (
|
|
268
|
+
this.runtime.destroyed ||
|
|
269
|
+
!this.runtime.built ||
|
|
270
|
+
this.dom.targets.length === 0
|
|
271
|
+
) {
|
|
270
272
|
return this;
|
|
271
273
|
}
|
|
272
274
|
this.apply();
|
|
@@ -284,13 +286,12 @@ export class Sticky extends Component<
|
|
|
284
286
|
* @private
|
|
285
287
|
*/
|
|
286
288
|
protected onDestroy(): void {
|
|
287
|
-
this.runtime.active = false;
|
|
288
289
|
this.runtime.built = false;
|
|
289
|
-
this.
|
|
290
|
+
this.cache.originalStyles = [];
|
|
290
291
|
this.dom.targets = [];
|
|
291
292
|
}
|
|
292
293
|
}
|
|
293
294
|
|
|
294
|
-
export function createSticky(props: StickyProps = {}):
|
|
295
|
+
export function createSticky(props: StickyProps = {}): StickyInstance {
|
|
295
296
|
return new Sticky(props);
|
|
296
297
|
}
|