timered-counter 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.
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/custom-elements.json +8484 -0
- package/dist/src/counter-adapter.d.ts +38 -0
- package/dist/src/counter-adapter.js +69 -0
- package/dist/src/counter-adapter.js.map +1 -0
- package/dist/src/easing/cubic-bezier.d.ts +5 -0
- package/dist/src/easing/cubic-bezier.js +35 -0
- package/dist/src/easing/cubic-bezier.js.map +1 -0
- package/dist/src/easing/easing-functions.d.ts +1 -0
- package/dist/src/easing/easing-functions.js +10 -0
- package/dist/src/easing/easing-functions.js.map +1 -0
- package/dist/src/easing/index.d.ts +2 -0
- package/dist/src/easing/index.js +3 -0
- package/dist/src/easing/index.js.map +1 -0
- package/dist/src/easing/penner-easing-functions.d.ts +33 -0
- package/dist/src/easing/penner-easing-functions.js +82 -0
- package/dist/src/easing/penner-easing-functions.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.js +13 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mixins/counter-aira.d.ts +9 -0
- package/dist/src/mixins/counter-aira.js +41 -0
- package/dist/src/mixins/counter-aira.js.map +1 -0
- package/dist/src/mixins/counter-animation.d.ts +13 -0
- package/dist/src/mixins/counter-animation.js +55 -0
- package/dist/src/mixins/counter-animation.js.map +1 -0
- package/dist/src/mixins/counter-base.d.ts +21 -0
- package/dist/src/mixins/counter-base.js +152 -0
- package/dist/src/mixins/counter-base.js.map +1 -0
- package/dist/src/mixins/counter-parts.d.ts +42 -0
- package/dist/src/mixins/counter-parts.js +180 -0
- package/dist/src/mixins/counter-parts.js.map +1 -0
- package/dist/src/mixins/counter-styles.d.ts +17 -0
- package/dist/src/mixins/counter-styles.js +93 -0
- package/dist/src/mixins/counter-styles.js.map +1 -0
- package/dist/src/number-adapter/build-in-bigint.d.ts +6 -0
- package/dist/src/number-adapter/build-in-bigint.js +92 -0
- package/dist/src/number-adapter/build-in-bigint.js.map +1 -0
- package/dist/src/number-adapter/build-in-number.d.ts +3 -0
- package/dist/src/number-adapter/build-in-number.js +84 -0
- package/dist/src/number-adapter/build-in-number.js.map +1 -0
- package/dist/src/number-adapter/decimal-js.d.ts +4 -0
- package/dist/src/number-adapter/decimal-js.js +87 -0
- package/dist/src/number-adapter/decimal-js.js.map +1 -0
- package/dist/src/number-adapter/index.d.ts +4 -0
- package/dist/src/number-adapter/index.js +5 -0
- package/dist/src/number-adapter/index.js.map +1 -0
- package/dist/src/number-adapter/types.d.ts +34 -0
- package/dist/src/number-adapter/types.js +2 -0
- package/dist/src/number-adapter/types.js.map +1 -0
- package/dist/src/string-adapter/build-in-intl-segmenter.d.ts +10 -0
- package/dist/src/string-adapter/build-in-intl-segmenter.js +18 -0
- package/dist/src/string-adapter/build-in-intl-segmenter.js.map +1 -0
- package/dist/src/string-adapter/build-in-string.d.ts +12 -0
- package/dist/src/string-adapter/build-in-string.js +16 -0
- package/dist/src/string-adapter/build-in-string.js.map +1 -0
- package/dist/src/string-adapter/grapheme-splitter.d.ts +8 -0
- package/dist/src/string-adapter/grapheme-splitter.js +16 -0
- package/dist/src/string-adapter/grapheme-splitter.js.map +1 -0
- package/dist/src/string-adapter/index.d.ts +4 -0
- package/dist/src/string-adapter/index.js +5 -0
- package/dist/src/string-adapter/index.js.map +1 -0
- package/dist/src/string-adapter/types.d.ts +19 -0
- package/dist/src/string-adapter/types.js +2 -0
- package/dist/src/string-adapter/types.js.map +1 -0
- package/dist/src/styles/timered-counter-datetime-styles.d.ts +1 -0
- package/dist/src/styles/timered-counter-datetime-styles.js +8 -0
- package/dist/src/styles/timered-counter-datetime-styles.js.map +1 -0
- package/dist/src/styles/timered-counter-number-styles.d.ts +1 -0
- package/dist/src/styles/timered-counter-number-styles.js +3 -0
- package/dist/src/styles/timered-counter-number-styles.js.map +1 -0
- package/dist/src/styles/timered-counter-string-styles.d.ts +1 -0
- package/dist/src/styles/timered-counter-string-styles.js +3 -0
- package/dist/src/styles/timered-counter-string-styles.js.map +1 -0
- package/dist/src/styles/timered-counter-styles.d.ts +1 -0
- package/dist/src/styles/timered-counter-styles.js +25 -0
- package/dist/src/styles/timered-counter-styles.js.map +1 -0
- package/dist/src/timered-counter-datetime-duration.d.ts +37 -0
- package/dist/src/timered-counter-datetime-duration.js +186 -0
- package/dist/src/timered-counter-datetime-duration.js.map +1 -0
- package/dist/src/timered-counter-number.d.ts +23 -0
- package/dist/src/timered-counter-number.js +114 -0
- package/dist/src/timered-counter-number.js.map +1 -0
- package/dist/src/timered-counter-string.d.ts +30 -0
- package/dist/src/timered-counter-string.js +138 -0
- package/dist/src/timered-counter-string.js.map +1 -0
- package/dist/src/timered-counter.d.ts +15 -0
- package/dist/src/timered-counter.js +80 -0
- package/dist/src/timered-counter.js.map +1 -0
- package/dist/src/transitions/roller/index.d.ts +1 -0
- package/dist/src/transitions/roller/index.js +2 -0
- package/dist/src/transitions/roller/index.js.map +1 -0
- package/dist/src/transitions/roller/roller-digit.d.ts +28 -0
- package/dist/src/transitions/roller/roller-digit.js +259 -0
- package/dist/src/transitions/roller/roller-digit.js.map +1 -0
- package/dist/src/transitions/roller/roller.d.ts +42 -0
- package/dist/src/transitions/roller/roller.js +235 -0
- package/dist/src/transitions/roller/roller.js.map +1 -0
- package/dist/src/transitions/roller/styles.d.ts +2 -0
- package/dist/src/transitions/roller/styles.js +77 -0
- package/dist/src/transitions/roller/styles.js.map +1 -0
- package/dist/src/types/duration.d.ts +33 -0
- package/dist/src/types/duration.js +35 -0
- package/dist/src/types/duration.js.map +1 -0
- package/dist/src/types/group.d.ts +67 -0
- package/dist/src/types/group.js +2 -0
- package/dist/src/types/group.js.map +1 -0
- package/dist/src/utils/any-base.d.ts +6 -0
- package/dist/src/utils/any-base.js +56 -0
- package/dist/src/utils/any-base.js.map +1 -0
- package/dist/src/utils/duration.d.ts +15 -0
- package/dist/src/utils/duration.js +66 -0
- package/dist/src/utils/duration.js.map +1 -0
- package/dist/src/utils/extract-group-option.d.ts +9 -0
- package/dist/src/utils/extract-group-option.js +81 -0
- package/dist/src/utils/extract-group-option.js.map +1 -0
- package/dist/src/utils/iso8601-duration.d.ts +4 -0
- package/dist/src/utils/iso8601-duration.js +32 -0
- package/dist/src/utils/iso8601-duration.js.map +1 -0
- package/dist/src/utils/localized-date-time-fields.d.ts +2 -0
- package/dist/src/utils/localized-date-time-fields.js +24 -0
- package/dist/src/utils/localized-date-time-fields.js.map +1 -0
- package/dist/src/utils/parse-json-string.d.ts +1 -0
- package/dist/src/utils/parse-json-string.js +9 -0
- package/dist/src/utils/parse-json-string.js.map +1 -0
- package/dist/src/utils/polyfill-keyframes.d.ts +1 -0
- package/dist/src/utils/polyfill-keyframes.js +19 -0
- package/dist/src/utils/polyfill-keyframes.js.map +1 -0
- package/dist/src/utils/preprocess-part-data.d.ts +25 -0
- package/dist/src/utils/preprocess-part-data.js +59 -0
- package/dist/src/utils/preprocess-part-data.js.map +1 -0
- package/dist/src/utils/transition-digit.d.ts +2 -0
- package/dist/src/utils/transition-digit.js +51 -0
- package/dist/src/utils/transition-digit.js.map +1 -0
- package/dist/src/utils/uuid.d.ts +1 -0
- package/dist/src/utils/uuid.js +7 -0
- package/dist/src/utils/uuid.js.map +1 -0
- package/dist/stories/story-parts/animation-events.d.ts +9 -0
- package/dist/stories/story-parts/animation-events.js +35 -0
- package/dist/stories/story-parts/animation-events.js.map +1 -0
- package/dist/stories/story-parts/animation-options.d.ts +8 -0
- package/dist/stories/story-parts/animation-options.js +25 -0
- package/dist/stories/story-parts/animation-options.js.map +1 -0
- package/dist/stories/story-parts/big-number.d.ts +8 -0
- package/dist/stories/story-parts/big-number.js +25 -0
- package/dist/stories/story-parts/big-number.js.map +1 -0
- package/dist/stories/story-parts/datetime-locale.d.ts +8 -0
- package/dist/stories/story-parts/datetime-locale.js +30 -0
- package/dist/stories/story-parts/datetime-locale.js.map +1 -0
- package/dist/stories/story-parts/datetime-precision.d.ts +8 -0
- package/dist/stories/story-parts/datetime-precision.js +82 -0
- package/dist/stories/story-parts/datetime-precision.js.map +1 -0
- package/dist/stories/story-parts/edge-case.d.ts +8 -0
- package/dist/stories/story-parts/edge-case.js +12 -0
- package/dist/stories/story-parts/edge-case.js.map +1 -0
- package/dist/stories/story-parts/emoji.d.ts +9 -0
- package/dist/stories/story-parts/emoji.js +20 -0
- package/dist/stories/story-parts/emoji.js.map +1 -0
- package/dist/stories/story-parts/locale-number.d.ts +7 -0
- package/dist/stories/story-parts/locale-number.js +23 -0
- package/dist/stories/story-parts/locale-number.js.map +1 -0
- package/dist/stories/story-parts/slots.d.ts +10 -0
- package/dist/stories/story-parts/slots.js +29 -0
- package/dist/stories/story-parts/slots.js.map +1 -0
- package/dist/stories/story-parts/styles.d.ts +7 -0
- package/dist/stories/story-parts/styles.js +34 -0
- package/dist/stories/story-parts/styles.js.map +1 -0
- package/dist/stories/story-parts/value-change.d.ts +9 -0
- package/dist/stories/story-parts/value-change.js +20 -0
- package/dist/stories/story-parts/value-change.js.map +1 -0
- package/dist/stories/timered-counter/decimaljs.stories.d.ts +6 -0
- package/dist/stories/timered-counter/decimaljs.stories.js +34 -0
- package/dist/stories/timered-counter/decimaljs.stories.js.map +1 -0
- package/dist/stories/timered-counter/index.stories.d.ts +9 -0
- package/dist/stories/timered-counter/index.stories.js +180 -0
- package/dist/stories/timered-counter/index.stories.js.map +1 -0
- package/dist/stories/timered-counter-datetime-duration/index.stories.d.ts +7 -0
- package/dist/stories/timered-counter-datetime-duration/index.stories.js +95 -0
- package/dist/stories/timered-counter-datetime-duration/index.stories.js.map +1 -0
- package/dist/stories/timered-counter-number/decimaljs.stories.d.ts +6 -0
- package/dist/stories/timered-counter-number/decimaljs.stories.js +34 -0
- package/dist/stories/timered-counter-number/decimaljs.stories.js.map +1 -0
- package/dist/stories/timered-counter-number/index.stories.d.ts +9 -0
- package/dist/stories/timered-counter-number/index.stories.js +188 -0
- package/dist/stories/timered-counter-number/index.stories.js.map +1 -0
- package/dist/stories/timered-counter-string/decimaljs.stories.d.ts +7 -0
- package/dist/stories/timered-counter-string/decimaljs.stories.js +55 -0
- package/dist/stories/timered-counter-string/decimaljs.stories.js.map +1 -0
- package/dist/stories/timered-counter-string/grapheme-splitter.stories.d.ts +7 -0
- package/dist/stories/timered-counter-string/grapheme-splitter.stories.js +56 -0
- package/dist/stories/timered-counter-string/grapheme-splitter.stories.js.map +1 -0
- package/dist/stories/timered-counter-string/index.stories.d.ts +9 -0
- package/dist/stories/timered-counter-string/index.stories.js +126 -0
- package/dist/stories/timered-counter-string/index.stories.js.map +1 -0
- package/dist/stories/timered-counter-string/intl-segmenter.stories.d.ts +7 -0
- package/dist/stories/timered-counter-string/intl-segmenter.stories.js +56 -0
- package/dist/stories/timered-counter-string/intl-segmenter.stories.js.map +1 -0
- package/dist/stories/utils/index.d.ts +8 -0
- package/dist/stories/utils/index.js +20 -0
- package/dist/stories/utils/index.js.map +1 -0
- package/dist/test/td-counter.test.d.ts +1 -0
- package/dist/test/td-counter.test.js +25 -0
- package/dist/test/td-counter.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +128 -0
@@ -0,0 +1,235 @@
|
|
1
|
+
import { __decorate } from "tslib";
|
2
|
+
import { html, LitElement } from 'lit';
|
3
|
+
import { repeat } from 'lit/directives/repeat.js';
|
4
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
5
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
6
|
+
import { clone, isNumber, values } from 'remeda';
|
7
|
+
import './roller-digit.js';
|
8
|
+
import { rollerStyles } from './styles.js';
|
9
|
+
import { mergePartDigitOption } from '../../utils/extract-group-option.js';
|
10
|
+
class RollerAnimationEvent extends Event {
|
11
|
+
}
|
12
|
+
let TimeredCounterRoller = class TimeredCounterRoller extends LitElement {
|
13
|
+
constructor() {
|
14
|
+
super(...arguments);
|
15
|
+
this.color = '';
|
16
|
+
this.direction = 'up';
|
17
|
+
this.parts = [];
|
18
|
+
this.partPreprocessDataList = [];
|
19
|
+
this.animationOptions = [];
|
20
|
+
this.keyframes = [];
|
21
|
+
this.cellStyles = [];
|
22
|
+
this.digitStyles = [];
|
23
|
+
this.partStyles = [];
|
24
|
+
this.parentContainerRect = {};
|
25
|
+
this.__mergedDigitStyles = [];
|
26
|
+
/**
|
27
|
+
* 记录一次更新中, 启动动画并结束的 <timered-counter-roller-digit> 元素个数.
|
28
|
+
*
|
29
|
+
* 在每次更新前重置为 0.
|
30
|
+
*
|
31
|
+
* @see {@link __handleDigitAnimationEnd}
|
32
|
+
* @private
|
33
|
+
*/
|
34
|
+
this.digitAnimateEndCount = 0;
|
35
|
+
/**
|
36
|
+
* 记录一次更新中, 需要启动动画的 <timered-counter-roller-digit> 元素总数.
|
37
|
+
*
|
38
|
+
* 在每次更新前重新计算.
|
39
|
+
* @private
|
40
|
+
*/
|
41
|
+
this.digitAnimatedCount = 0;
|
42
|
+
}
|
43
|
+
render() {
|
44
|
+
return html `
|
45
|
+
<span
|
46
|
+
class="roller__prefix"
|
47
|
+
data-part-id="-1"
|
48
|
+
data-digit-id="0"
|
49
|
+
style=${styleMap((this.__mergedDigitStyles[-1]?.[0] ?? {}))}
|
50
|
+
>
|
51
|
+
<slot part="prefix" name="prefix"></slot>
|
52
|
+
</span>
|
53
|
+
<span class="counter-parts">
|
54
|
+
${repeat(this.parts, (_, index) => index, (part, partIndex) => html `<span class="roller-part"
|
55
|
+
>${repeat(part.digits, (_, index) => `${part.digits.length - index}`, (digitInfo, digitIndex) => html `<span
|
56
|
+
class="roller-part__wrapper"
|
57
|
+
data-part-id="${partIndex}"
|
58
|
+
data-digit-id="${digitIndex}"
|
59
|
+
>
|
60
|
+
<timered-counter-roller-digit
|
61
|
+
.digit=${digitInfo}
|
62
|
+
.preprocessData=${this.partPreprocessDataList[partIndex][digitIndex]}
|
63
|
+
.direction=${this.direction}
|
64
|
+
.textStyle=${this.__mergedDigitStyles[partIndex][digitIndex]}
|
65
|
+
.cellStyle=${this.cellStyles[partIndex][digitIndex]}
|
66
|
+
.animationOptions=${this.animationOptions[partIndex][digitIndex]}
|
67
|
+
.keyframes=${this.keyframes[partIndex][digitIndex]}
|
68
|
+
@roller-digit-animation-end=${this
|
69
|
+
.__handleDigitAnimationEnd}
|
70
|
+
></timered-counter-roller-digit>
|
71
|
+
</span>`)}</span
|
72
|
+
>
|
73
|
+
<span
|
74
|
+
class="roller-part__suffix"
|
75
|
+
data-part-id="${partIndex}"
|
76
|
+
data-digit-id="-1"
|
77
|
+
style=${styleMap((this.__mergedDigitStyles[partIndex][-1] ?? {}))}
|
78
|
+
>
|
79
|
+
<slot
|
80
|
+
part="part-suffix"
|
81
|
+
name=${`part-suffix-${partIndex}`}
|
82
|
+
></slot>
|
83
|
+
</span>`)}
|
84
|
+
</span>
|
85
|
+
<span
|
86
|
+
class="roller__suffix"
|
87
|
+
data-part-id="-2"
|
88
|
+
data-digit-id="0"
|
89
|
+
style=${styleMap((this.__mergedDigitStyles[-2]?.[0] ?? {}))}
|
90
|
+
>
|
91
|
+
<slot part="suffix" name="suffix"></slot>
|
92
|
+
</span>
|
93
|
+
`;
|
94
|
+
}
|
95
|
+
willUpdate(_changedProperties) {
|
96
|
+
super.willUpdate(_changedProperties);
|
97
|
+
if (_changedProperties.has('direction') ||
|
98
|
+
_changedProperties.has('parts')) {
|
99
|
+
this.digitAnimateEndCount = 0;
|
100
|
+
this.digitAnimatedCount = this.partPreprocessDataList
|
101
|
+
.flat()
|
102
|
+
.filter(({ animate }) => animate).length;
|
103
|
+
if (this.digitAnimatedCount > 0) {
|
104
|
+
this.__emitAnimationStart();
|
105
|
+
}
|
106
|
+
}
|
107
|
+
/**
|
108
|
+
* 将 color 样式合并到 digitStyles 中.
|
109
|
+
*/
|
110
|
+
this.__mergedDigitStyles = mergePartDigitOption(clone(this.digitStyles), this.__generatePartDigitsColorStyles());
|
111
|
+
}
|
112
|
+
__handleDigitAnimationEnd() {
|
113
|
+
this.digitAnimateEndCount++;
|
114
|
+
if (this.digitAnimateEndCount < this.digitAnimatedCount)
|
115
|
+
return;
|
116
|
+
this.__emitAnimationEnd();
|
117
|
+
}
|
118
|
+
__emitAnimationStart() {
|
119
|
+
if (!this.isConnected)
|
120
|
+
return;
|
121
|
+
this.dispatchEvent(new RollerAnimationEvent('roller-animation-start'));
|
122
|
+
}
|
123
|
+
__emitAnimationEnd() {
|
124
|
+
if (!this.isConnected)
|
125
|
+
return;
|
126
|
+
this.dispatchEvent(new RollerAnimationEvent('roller-animation-end'));
|
127
|
+
}
|
128
|
+
__generatePartDigitsColorStyles() {
|
129
|
+
const result = [];
|
130
|
+
const containerRect = this.parentContainerRect;
|
131
|
+
const {
|
132
|
+
// parts,
|
133
|
+
// oldParts,
|
134
|
+
prefixContainer, suffixContainer, color, } = this;
|
135
|
+
const partDigitElements = Array.from(this.shadowRoot?.querySelectorAll('[data-part-id]').values() ?? []);
|
136
|
+
/**
|
137
|
+
* 当某次更新**将**会导致 DOM 宽高发生变化时(如: 滚动数字的位数增加/减少会导致宽度变化),
|
138
|
+
* 需要跳过这次更新然后等待 DOM 宽高变化完成才能更新(宽高变化后将通过 {@link containerRect} 触发).
|
139
|
+
*/
|
140
|
+
if (!containerRect) {
|
141
|
+
return result;
|
142
|
+
}
|
143
|
+
/**
|
144
|
+
* 比较 {@link data} 前后不同判断是否导致 DOM 宽度会发生变化.
|
145
|
+
*/
|
146
|
+
// if (parts.length !== oldParts.length) {
|
147
|
+
// this.requestUpdate();
|
148
|
+
// return result;
|
149
|
+
// }
|
150
|
+
// for (let i = 0; i < parts.length; i++) {
|
151
|
+
// if (parts[i].digits.length !== oldParts[i].digits.length) {
|
152
|
+
// this.requestUpdate();
|
153
|
+
// return result;
|
154
|
+
// }
|
155
|
+
// }
|
156
|
+
if (prefixContainer)
|
157
|
+
partDigitElements[-1] = prefixContainer;
|
158
|
+
if (suffixContainer)
|
159
|
+
partDigitElements[-2] = suffixContainer;
|
160
|
+
for (const el of values(partDigitElements)) {
|
161
|
+
const partId = Number.parseInt(el.dataset.partId ?? '-1', 10);
|
162
|
+
const digitId = Number.parseInt(el.dataset.digitId ?? '-1', 10);
|
163
|
+
if (!isNumber(partId) || !isNumber(digitId)) {
|
164
|
+
throw new Error('The data-part-id and data-digit-id attributes are required.');
|
165
|
+
}
|
166
|
+
if (!result[partId])
|
167
|
+
result[partId] = [];
|
168
|
+
if (CSS.supports('color', color)) {
|
169
|
+
result[partId][digitId] = { color };
|
170
|
+
}
|
171
|
+
else if (CSS.supports('background-image', color)) {
|
172
|
+
result[partId][digitId] = {
|
173
|
+
backgroundImage: color,
|
174
|
+
backgroundClip: 'text',
|
175
|
+
backgroundSize: `${containerRect.width}px ${containerRect.height}px`,
|
176
|
+
backgroundPositionX: `${-el.offsetLeft}px`,
|
177
|
+
backgroundPositionY: `${-el.offsetTop}px`,
|
178
|
+
backgroundRepeat: 'no-repeat',
|
179
|
+
color: 'transparent',
|
180
|
+
// @ts-ignore
|
181
|
+
'-webkit-text-fill-color': 'transparent',
|
182
|
+
};
|
183
|
+
}
|
184
|
+
else {
|
185
|
+
result[partId][digitId] = {};
|
186
|
+
// todo error event
|
187
|
+
// eslint-disable-next-line no-console
|
188
|
+
console.warn(new Error('The color property is not supported.'));
|
189
|
+
}
|
190
|
+
}
|
191
|
+
return result;
|
192
|
+
}
|
193
|
+
};
|
194
|
+
TimeredCounterRoller.styles = [rollerStyles];
|
195
|
+
__decorate([
|
196
|
+
property({ type: String })
|
197
|
+
], TimeredCounterRoller.prototype, "color", void 0);
|
198
|
+
__decorate([
|
199
|
+
property({ type: String })
|
200
|
+
], TimeredCounterRoller.prototype, "direction", void 0);
|
201
|
+
__decorate([
|
202
|
+
property({ type: Array })
|
203
|
+
], TimeredCounterRoller.prototype, "parts", void 0);
|
204
|
+
__decorate([
|
205
|
+
property({ type: Array })
|
206
|
+
], TimeredCounterRoller.prototype, "partPreprocessDataList", void 0);
|
207
|
+
__decorate([
|
208
|
+
property({ type: Array })
|
209
|
+
], TimeredCounterRoller.prototype, "animationOptions", void 0);
|
210
|
+
__decorate([
|
211
|
+
property({ type: Array })
|
212
|
+
], TimeredCounterRoller.prototype, "keyframes", void 0);
|
213
|
+
__decorate([
|
214
|
+
property({ type: Array })
|
215
|
+
], TimeredCounterRoller.prototype, "cellStyles", void 0);
|
216
|
+
__decorate([
|
217
|
+
property({ type: Array })
|
218
|
+
], TimeredCounterRoller.prototype, "digitStyles", void 0);
|
219
|
+
__decorate([
|
220
|
+
property({ type: Array })
|
221
|
+
], TimeredCounterRoller.prototype, "partStyles", void 0);
|
222
|
+
__decorate([
|
223
|
+
property({ type: Object })
|
224
|
+
], TimeredCounterRoller.prototype, "parentContainerRect", void 0);
|
225
|
+
__decorate([
|
226
|
+
query('.roller__prefix')
|
227
|
+
], TimeredCounterRoller.prototype, "prefixContainer", void 0);
|
228
|
+
__decorate([
|
229
|
+
query('.roller__suffix')
|
230
|
+
], TimeredCounterRoller.prototype, "suffixContainer", void 0);
|
231
|
+
TimeredCounterRoller = __decorate([
|
232
|
+
customElement('timered-counter-roller')
|
233
|
+
], TimeredCounterRoller);
|
234
|
+
export { TimeredCounterRoller };
|
235
|
+
//# sourceMappingURL=roller.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"roller.js","sourceRoot":"","sources":["../../../../src/transitions/roller/roller.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAa,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjD,OAAO,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO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nimport { repeat } from 'lit/directives/repeat.js';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { StyleInfo, styleMap } from 'lit/directives/style-map.js';\nimport { clone, isNumber, values } from 'remeda';\nimport { PartData } from '../../types/group.js';\nimport { PartPreprocessedData } from '../../utils/preprocess-part-data.js';\nimport './roller-digit.js';\nimport { rollerStyles } from './styles.js';\nimport { mergePartDigitOption } from '../../utils/extract-group-option.js';\n\nclass RollerAnimationEvent extends Event {\n // constructor(type: string, eventInitDict?: EventInit) {\n // super(type, eventInitDict);\n // }\n}\n\n@customElement('timered-counter-roller')\nexport class TimeredCounterRoller extends LitElement {\n static styles = [rollerStyles];\n\n @property({ type: String })\n color: string = '';\n\n @property({ type: String })\n direction: 'up' | 'down' = 'up';\n\n @property({ type: Array })\n parts: PartData[] = [];\n\n @property({ type: Array })\n partPreprocessDataList: PartPreprocessedData[][] = [];\n\n @property({ type: Array })\n animationOptions: KeyframeAnimationOptions[][] = [];\n\n @property({ type: Array })\n keyframes: PropertyIndexedKeyframes[][] = [];\n\n @property({ type: Array })\n cellStyles: Partial<CSSStyleDeclaration>[][][] = [];\n\n @property({ type: Array })\n digitStyles: Partial<CSSStyleDeclaration>[][] = [];\n\n @property({ type: Array })\n partStyles: Partial<CSSStyleDeclaration>[] = [];\n\n @property({ type: Object })\n parentContainerRect: DOMRect = {} as DOMRect;\n\n @query('.roller__prefix')\n prefixContainer: HTMLElement | undefined;\n\n @query('.roller__suffix')\n suffixContainer: HTMLElement | undefined;\n\n private __mergedDigitStyles: Partial<CSSStyleDeclaration>[][] = [];\n\n protected render() {\n return html`\n <span\n class=\"roller__prefix\"\n data-part-id=\"-1\"\n data-digit-id=\"0\"\n style=${styleMap(\n (this.__mergedDigitStyles[-1]?.[0] ?? {}) as StyleInfo,\n )}\n >\n <slot part=\"prefix\" name=\"prefix\"></slot>\n </span>\n <span class=\"counter-parts\">\n ${repeat(\n this.parts,\n (_, index) => index,\n (part, partIndex) =>\n html`<span class=\"roller-part\"\n >${repeat(\n part.digits,\n (_, index) => `${part.digits.length - index}`,\n (digitInfo, digitIndex) =>\n html`<span\n class=\"roller-part__wrapper\"\n data-part-id=\"${partIndex}\"\n data-digit-id=\"${digitIndex}\"\n >\n <timered-counter-roller-digit\n .digit=${digitInfo}\n .preprocessData=${this.partPreprocessDataList[\n partIndex\n ][digitIndex]}\n .direction=${this.direction}\n .textStyle=${this.__mergedDigitStyles[partIndex][\n digitIndex\n ]}\n .cellStyle=${this.cellStyles[partIndex][digitIndex]}\n .animationOptions=${this.animationOptions[partIndex][\n digitIndex\n ]}\n .keyframes=${this.keyframes[partIndex][digitIndex]}\n @roller-digit-animation-end=${this\n .__handleDigitAnimationEnd}\n ></timered-counter-roller-digit>\n </span>`,\n )}</span\n >\n <span\n class=\"roller-part__suffix\"\n data-part-id=\"${partIndex}\"\n data-digit-id=\"-1\"\n style=${styleMap(\n (this.__mergedDigitStyles[partIndex][-1] ?? {}) as StyleInfo,\n )}\n >\n <slot\n part=\"part-suffix\"\n name=${`part-suffix-${partIndex}`}\n ></slot>\n </span>`,\n )}\n </span>\n <span\n class=\"roller__suffix\"\n data-part-id=\"-2\"\n data-digit-id=\"0\"\n style=${styleMap(\n (this.__mergedDigitStyles[-2]?.[0] ?? {}) as StyleInfo,\n )}\n >\n <slot part=\"suffix\" name=\"suffix\"></slot>\n </span>\n `;\n }\n\n protected willUpdate(_changedProperties: PropertyValues) {\n super.willUpdate(_changedProperties);\n\n if (\n _changedProperties.has('direction') ||\n _changedProperties.has('parts')\n ) {\n this.digitAnimateEndCount = 0;\n this.digitAnimatedCount = this.partPreprocessDataList\n .flat()\n .filter(({ animate }) => animate).length;\n\n if (this.digitAnimatedCount > 0) {\n this.__emitAnimationStart();\n }\n }\n\n /**\n * 将 color 样式合并到 digitStyles 中.\n */\n this.__mergedDigitStyles = mergePartDigitOption(\n clone(this.digitStyles),\n this.__generatePartDigitsColorStyles(),\n );\n }\n\n /**\n * 记录一次更新中, 启动动画并结束的 <timered-counter-roller-digit> 元素个数.\n *\n * 在每次更新前重置为 0.\n *\n * @see {@link __handleDigitAnimationEnd}\n * @private\n */\n private digitAnimateEndCount = 0;\n\n /**\n * 记录一次更新中, 需要启动动画的 <timered-counter-roller-digit> 元素总数.\n *\n * 在每次更新前重新计算.\n * @private\n */\n private digitAnimatedCount = 0;\n\n private __handleDigitAnimationEnd() {\n this.digitAnimateEndCount++;\n\n if (this.digitAnimateEndCount < this.digitAnimatedCount) return;\n\n this.__emitAnimationEnd();\n }\n\n private __emitAnimationStart() {\n if (!this.isConnected) return;\n\n this.dispatchEvent(new RollerAnimationEvent('roller-animation-start'));\n }\n\n private __emitAnimationEnd() {\n if (!this.isConnected) return;\n\n this.dispatchEvent(new RollerAnimationEvent('roller-animation-end'));\n }\n\n private __generatePartDigitsColorStyles() {\n const result: Partial<CSSStyleDeclaration>[][] = [];\n\n const containerRect = this.parentContainerRect;\n const {\n // parts,\n // oldParts,\n prefixContainer,\n suffixContainer,\n color,\n } = this;\n const partDigitElements = Array.from(\n this.shadowRoot?.querySelectorAll('[data-part-id]').values() ?? [],\n ) as HTMLElement[];\n\n /**\n * 当某次更新**将**会导致 DOM 宽高发生变化时(如: 滚动数字的位数增加/减少会导致宽度变化),\n * 需要跳过这次更新然后等待 DOM 宽高变化完成才能更新(宽高变化后将通过 {@link containerRect} 触发).\n */\n if (!containerRect) {\n return result;\n }\n /**\n * 比较 {@link data} 前后不同判断是否导致 DOM 宽度会发生变化.\n */\n // if (parts.length !== oldParts.length) {\n // this.requestUpdate();\n // return result;\n // }\n // for (let i = 0; i < parts.length; i++) {\n // if (parts[i].digits.length !== oldParts[i].digits.length) {\n // this.requestUpdate();\n // return result;\n // }\n // }\n\n if (prefixContainer) partDigitElements[-1] = prefixContainer;\n if (suffixContainer) partDigitElements[-2] = suffixContainer;\n\n for (const el of values(partDigitElements)) {\n const partId = Number.parseInt(el.dataset.partId ?? '-1', 10);\n const digitId = Number.parseInt(el.dataset.digitId ?? '-1', 10);\n if (!isNumber(partId) || !isNumber(digitId)) {\n throw new Error(\n 'The data-part-id and data-digit-id attributes are required.',\n );\n }\n\n if (!result[partId]) result[partId] = [];\n\n if (CSS.supports('color', color)) {\n result[partId][digitId] = { color };\n } else if (CSS.supports('background-image', color)) {\n result[partId][digitId] = {\n backgroundImage: color,\n backgroundClip: 'text',\n backgroundSize: `${containerRect.width}px ${containerRect.height}px`,\n backgroundPositionX: `${-el.offsetLeft}px`,\n backgroundPositionY: `${-el.offsetTop}px`,\n backgroundRepeat: 'no-repeat',\n color: 'transparent',\n // @ts-ignore\n '-webkit-text-fill-color': 'transparent',\n };\n } else {\n result[partId][digitId] = {};\n // todo error event\n // eslint-disable-next-line no-console\n console.warn(new Error('The color property is not supported.'));\n }\n }\n\n return result;\n }\n}\n"]}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { css } from 'lit';
|
2
|
+
export const rollerStyles = css `
|
3
|
+
.counter-parts {
|
4
|
+
display: inline-flex;
|
5
|
+
flex: 1 1 auto;
|
6
|
+
}
|
7
|
+
|
8
|
+
.roller-part {
|
9
|
+
white-space: nowrap;
|
10
|
+
}
|
11
|
+
|
12
|
+
.roller__prefix,
|
13
|
+
.roller__suffix {
|
14
|
+
flex: none;
|
15
|
+
}
|
16
|
+
|
17
|
+
.roller-part .roller-part__wrapper {
|
18
|
+
display: inline-block;
|
19
|
+
}
|
20
|
+
|
21
|
+
.roller-part .roller-part__suffix {
|
22
|
+
//display: inline-block;
|
23
|
+
}
|
24
|
+
`;
|
25
|
+
export const rollerDigitStyles = css `
|
26
|
+
.roller-part-digit {
|
27
|
+
position: relative;
|
28
|
+
display: inline-block;
|
29
|
+
}
|
30
|
+
|
31
|
+
.placeholder {
|
32
|
+
visibility: hidden;
|
33
|
+
display: inline-block;
|
34
|
+
}
|
35
|
+
|
36
|
+
.roll-list {
|
37
|
+
position: absolute;
|
38
|
+
left: 0;
|
39
|
+
display: inline-flex;
|
40
|
+
width: 100%;
|
41
|
+
flex-direction: column;
|
42
|
+
align-items: center;
|
43
|
+
}
|
44
|
+
|
45
|
+
.roll-list.roll-list__up {
|
46
|
+
top: 0;
|
47
|
+
}
|
48
|
+
|
49
|
+
.roll-list.roll-list__down {
|
50
|
+
bottom: 0;
|
51
|
+
}
|
52
|
+
|
53
|
+
.roll-list__shadow {
|
54
|
+
visibility: hidden;
|
55
|
+
position: absolute;
|
56
|
+
z-index: -10;
|
57
|
+
display: inline-flex;
|
58
|
+
flex-direction: column;
|
59
|
+
white-space: nowrap;
|
60
|
+
}
|
61
|
+
|
62
|
+
.roll-item {
|
63
|
+
display: inline-block;
|
64
|
+
width: 100%;
|
65
|
+
}
|
66
|
+
|
67
|
+
.roll-item.roll-item__head {
|
68
|
+
position: absolute;
|
69
|
+
top: 100%;
|
70
|
+
}
|
71
|
+
|
72
|
+
.roll-item.roll-item__tail {
|
73
|
+
position: absolute;
|
74
|
+
bottom: 100%;
|
75
|
+
}
|
76
|
+
`;
|
77
|
+
//# sourceMappingURL=styles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../src/transitions/roller/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;CAsB9B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDnC,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const rollerStyles = css`\n .counter-parts {\n display: inline-flex;\n flex: 1 1 auto;\n }\n\n .roller-part {\n white-space: nowrap;\n }\n\n .roller__prefix,\n .roller__suffix {\n flex: none;\n }\n\n .roller-part .roller-part__wrapper {\n display: inline-block;\n }\n\n .roller-part .roller-part__suffix {\n //display: inline-block;\n }\n`;\n\nexport const rollerDigitStyles = css`\n .roller-part-digit {\n position: relative;\n display: inline-block;\n }\n\n .placeholder {\n visibility: hidden;\n display: inline-block;\n }\n\n .roll-list {\n position: absolute;\n left: 0;\n display: inline-flex;\n width: 100%;\n flex-direction: column;\n align-items: center;\n }\n\n .roll-list.roll-list__up {\n top: 0;\n }\n\n .roll-list.roll-list__down {\n bottom: 0;\n }\n\n .roll-list__shadow {\n visibility: hidden;\n position: absolute;\n z-index: -10;\n display: inline-flex;\n flex-direction: column;\n white-space: nowrap;\n }\n\n .roll-item {\n display: inline-block;\n width: 100%;\n }\n\n .roll-item.roll-item__head {\n position: absolute;\n top: 100%;\n }\n\n .roll-item.roll-item__tail {\n position: absolute;\n bottom: 100%;\n }\n`;\n"]}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
export declare enum DurationPartType {
|
2
|
+
Millisecond = "millisecond",
|
3
|
+
Second = "second",
|
4
|
+
Minute = "minute",
|
5
|
+
Hour = "hour",
|
6
|
+
Day = "day",
|
7
|
+
Week = "weekOfYear",
|
8
|
+
Month = "month",
|
9
|
+
Quarter = "quarter",
|
10
|
+
Year = "year"
|
11
|
+
}
|
12
|
+
export declare const DurationPartMillisecond: {
|
13
|
+
readonly millisecond: 1;
|
14
|
+
readonly second: 1000;
|
15
|
+
readonly minute: 60000;
|
16
|
+
readonly hour: 3600000;
|
17
|
+
readonly day: 86400000;
|
18
|
+
readonly weekOfYear: 604800000;
|
19
|
+
readonly month: 2629800000;
|
20
|
+
readonly quarter: 7889400000;
|
21
|
+
readonly year: 31557600000;
|
22
|
+
};
|
23
|
+
export declare const DurationPartMillisecondToType: {
|
24
|
+
readonly 1: DurationPartType.Millisecond;
|
25
|
+
readonly 1000: DurationPartType.Second;
|
26
|
+
readonly 60000: DurationPartType.Minute;
|
27
|
+
readonly 3600000: DurationPartType.Hour;
|
28
|
+
readonly 86400000: DurationPartType.Day;
|
29
|
+
readonly 604800000: DurationPartType.Week;
|
30
|
+
readonly 2629800000: DurationPartType.Month;
|
31
|
+
readonly 7889400000: DurationPartType.Quarter;
|
32
|
+
readonly 31557600000: DurationPartType.Year;
|
33
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
export var DurationPartType;
|
2
|
+
(function (DurationPartType) {
|
3
|
+
DurationPartType["Millisecond"] = "millisecond";
|
4
|
+
DurationPartType["Second"] = "second";
|
5
|
+
DurationPartType["Minute"] = "minute";
|
6
|
+
DurationPartType["Hour"] = "hour";
|
7
|
+
DurationPartType["Day"] = "day";
|
8
|
+
DurationPartType["Week"] = "weekOfYear";
|
9
|
+
DurationPartType["Month"] = "month";
|
10
|
+
DurationPartType["Quarter"] = "quarter";
|
11
|
+
DurationPartType["Year"] = "year";
|
12
|
+
})(DurationPartType || (DurationPartType = {}));
|
13
|
+
export const DurationPartMillisecond = {
|
14
|
+
[DurationPartType.Millisecond]: 1,
|
15
|
+
[DurationPartType.Second]: 1000,
|
16
|
+
[DurationPartType.Minute]: 60000,
|
17
|
+
[DurationPartType.Hour]: 3600000,
|
18
|
+
[DurationPartType.Day]: 86400000,
|
19
|
+
[DurationPartType.Week]: 604800000,
|
20
|
+
[DurationPartType.Month]: 2629800000,
|
21
|
+
[DurationPartType.Quarter]: 7889400000,
|
22
|
+
[DurationPartType.Year]: 31557600000,
|
23
|
+
};
|
24
|
+
export const DurationPartMillisecondToType = {
|
25
|
+
1: DurationPartType.Millisecond,
|
26
|
+
1000: DurationPartType.Second,
|
27
|
+
60000: DurationPartType.Minute,
|
28
|
+
3600000: DurationPartType.Hour,
|
29
|
+
86400000: DurationPartType.Day,
|
30
|
+
604800000: DurationPartType.Week,
|
31
|
+
2629800000: DurationPartType.Month,
|
32
|
+
7889400000: DurationPartType.Quarter,
|
33
|
+
31557600000: DurationPartType.Year,
|
34
|
+
};
|
35
|
+
//# sourceMappingURL=duration.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../../src/types/duration.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAA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ute',\n Hour = 'hour',\n Day = 'day',\n Week = 'weekOfYear',\n Month = 'month',\n Quarter = 'quarter',\n Year = 'year',\n}\n\nexport const DurationPartMillisecond = {\n [DurationPartType.Millisecond]: 1,\n [DurationPartType.Second]: 1000,\n [DurationPartType.Minute]: 60000,\n [DurationPartType.Hour]: 3600000,\n [DurationPartType.Day]: 86400000,\n [DurationPartType.Week]: 604800000,\n [DurationPartType.Month]: 2629800000,\n [DurationPartType.Quarter]: 7889400000,\n [DurationPartType.Year]: 31557600000,\n} as const;\n\nexport const DurationPartMillisecondToType = {\n 1: DurationPartType.Millisecond,\n 1000: DurationPartType.Second,\n 60000: DurationPartType.Minute,\n 3600000: DurationPartType.Hour,\n 86400000: DurationPartType.Day,\n 604800000: DurationPartType.Week,\n 2629800000: DurationPartType.Month,\n 7889400000: DurationPartType.Quarter,\n 31557600000: DurationPartType.Year,\n} as const;\n"]}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { PartPreprocessedData } from '../utils/preprocess-part-data.js';
|
2
|
+
export interface PartDataDigit {
|
3
|
+
data: string[];
|
4
|
+
/**
|
5
|
+
* 这是数字的第几位
|
6
|
+
* @example 1024 -> 4 是第 1 位, 2 是第 2 位, 0 是第 3 位, 1 是第 4 位
|
7
|
+
*/
|
8
|
+
place: number;
|
9
|
+
}
|
10
|
+
export interface PartData {
|
11
|
+
/**
|
12
|
+
* 每个数字数位用于过渡动画的数据.
|
13
|
+
* @example 1 -> 10
|
14
|
+
* [
|
15
|
+
* ["0", "1"], // 第一个数位
|
16
|
+
* ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"], // 第二个数位
|
17
|
+
* ]
|
18
|
+
*/
|
19
|
+
digits: PartDataDigit[];
|
20
|
+
/**
|
21
|
+
* 运动方向的头部数字. 向下运动时该值为数组的最后一个元素. 向上运动时该值为数组的第一个元素.
|
22
|
+
* @deprecated
|
23
|
+
*/
|
24
|
+
headNumber?: number;
|
25
|
+
/**
|
26
|
+
* 运动方向的尾部数字.
|
27
|
+
@deprecated
|
28
|
+
*/
|
29
|
+
tailNumber?: number;
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* 1. T: 单个数值. 为所有 part 下的 digit 使用 T.
|
33
|
+
* 2. T[]: 数组数值. 为第 `i` 个 part 下的所有 digit 使用 `T[i]` 值.
|
34
|
+
* 3. T[][]: 二维数组数值. 为第 `i` 个 part 下的第 `j` 个 digit 使用 `T[i][j]` 值.
|
35
|
+
* 4. (data: PartData[]) => T | T[] | T[][]: 同上
|
36
|
+
*/
|
37
|
+
export type GroupValue<T> = T | undefined;
|
38
|
+
export interface GroupGetterOptions {
|
39
|
+
/**
|
40
|
+
* 用于生成滚动列表的数据.
|
41
|
+
*/
|
42
|
+
data: PartData[];
|
43
|
+
/**
|
44
|
+
* 滚动方向.
|
45
|
+
*/
|
46
|
+
direction: 'up' | 'down';
|
47
|
+
/**
|
48
|
+
* 导致这次滚动发生的值. [新值, 旧值].
|
49
|
+
*/
|
50
|
+
value: [unknown, unknown];
|
51
|
+
preprocessData: PartPreprocessedData[][];
|
52
|
+
}
|
53
|
+
export type GroupGetter<T> = (options: GroupGetterOptions) => GroupValue<T>;
|
54
|
+
export type GroupValueOrGetter<T> = GroupValue<T> | GroupGetter<T>;
|
55
|
+
export type PartValue<T> = GroupValue<T> | GroupValue<T[]>;
|
56
|
+
export type PartGetter<T> = GroupGetter<T> | GroupGetter<T[]>;
|
57
|
+
export type PartValueOrGetter<T> = PartValue<T> | PartGetter<T>;
|
58
|
+
export type PartDigitValue<T> = PartValue<T> | PartValue<T[]>;
|
59
|
+
export type PartDigitGetter<T> = PartGetter<T> | PartGetter<T[]>;
|
60
|
+
export type PartDigitValueOrGetter<T> = PartDigitValue<T> | PartDigitGetter<T>;
|
61
|
+
export type PartDigitCellValue<T> = PartValue<T> | PartValue<T[]>;
|
62
|
+
export type PartDigitCellGetter<T> = PartGetter<T> | PartGetter<T[]>;
|
63
|
+
export type PartDigitCellValueOrGetter<T> = PartDigitCellValue<T> | PartDigitCellGetter<T>;
|
64
|
+
export type ExtractGroupValue<T> = T extends GroupValueOrGetter<infer U> ? U extends Array<infer V> ? V : U : never;
|
65
|
+
export type ExtractPartValue<T> = T extends PartValueOrGetter<infer U> ? U extends Array<infer V> ? ExtractGroupValue<V> : U : never;
|
66
|
+
export type ExtractPartDigitValue<T> = T extends PartDigitValueOrGetter<infer U> ? U extends Array<infer V> ? ExtractPartValue<V> : U : never;
|
67
|
+
export type ExtractPartDigitCellValue<T> = T extends PartDigitCellValueOrGetter<infer U> ? U extends Array<infer V> ? ExtractPartDigitValue<V> : U : never;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../../src/types/group.ts"],"names":[],"mappings":"","sourcesContent":["import { PartPreprocessedData } from '../utils/preprocess-part-data.js';\n\nexport interface PartDataDigit {\n data: string[];\n /**\n * 这是数字的第几位\n * @example 1024 -> 4 是第 1 位, 2 是第 2 位, 0 是第 3 位, 1 是第 4 位\n */\n place: number;\n}\n\nexport interface PartData {\n /**\n * 每个数字数位用于过渡动画的数据.\n * @example 1 -> 10\n * [\n * [\"0\", \"1\"], // 第一个数位\n * [\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"0\"], // 第二个数位\n * ]\n */\n digits: PartDataDigit[];\n /**\n * 运动方向的头部数字. 向下运动时该值为数组的最后一个元素. 向上运动时该值为数组的第一个元素.\n * @deprecated\n */\n headNumber?: number;\n /**\n * 运动方向的尾部数字.\n @deprecated\n */\n tailNumber?: number;\n}\n\n/**\n * 1. T: 单个数值. 为所有 part 下的 digit 使用 T.\n * 2. T[]: 数组数值. 为第 `i` 个 part 下的所有 digit 使用 `T[i]` 值.\n * 3. T[][]: 二维数组数值. 为第 `i` 个 part 下的第 `j` 个 digit 使用 `T[i][j]` 值.\n * 4. (data: PartData[]) => T | T[] | T[][]: 同上\n */\nexport type GroupValue<T> = T | undefined;\nexport interface GroupGetterOptions {\n /**\n * 用于生成滚动列表的数据.\n */\n data: PartData[];\n /**\n * 滚动方向.\n */\n direction: 'up' | 'down';\n /**\n * 导致这次滚动发生的值. [新值, 旧值].\n */\n value: [unknown, unknown];\n preprocessData: PartPreprocessedData[][];\n}\nexport type GroupGetter<T> = (options: GroupGetterOptions) => GroupValue<T>;\nexport type GroupValueOrGetter<T> = GroupValue<T> | GroupGetter<T>;\n\nexport type PartValue<T> = GroupValue<T> | GroupValue<T[]>;\nexport type PartGetter<T> = GroupGetter<T> | GroupGetter<T[]>;\nexport type PartValueOrGetter<T> = PartValue<T> | PartGetter<T>;\n\nexport type PartDigitValue<T> = PartValue<T> | PartValue<T[]>;\nexport type PartDigitGetter<T> = PartGetter<T> | PartGetter<T[]>;\nexport type PartDigitValueOrGetter<T> = PartDigitValue<T> | PartDigitGetter<T>;\n\nexport type PartDigitCellValue<T> = PartValue<T> | PartValue<T[]>;\nexport type PartDigitCellGetter<T> = PartGetter<T> | PartGetter<T[]>;\nexport type PartDigitCellValueOrGetter<T> =\n | PartDigitCellValue<T>\n | PartDigitCellGetter<T>;\n\nexport type ExtractGroupValue<T> =\n T extends GroupValueOrGetter<infer U>\n ? U extends Array<infer V>\n ? V\n : U\n : never;\n\nexport type ExtractPartValue<T> =\n T extends PartValueOrGetter<infer U>\n ? U extends Array<infer V>\n ? ExtractGroupValue<V>\n : U\n : never;\n\nexport type ExtractPartDigitValue<T> =\n T extends PartDigitValueOrGetter<infer U>\n ? U extends Array<infer V>\n ? ExtractPartValue<V>\n : U\n : never;\n\nexport type ExtractPartDigitCellValue<T> =\n T extends PartDigitCellValueOrGetter<infer U>\n ? U extends Array<infer V>\n ? ExtractPartDigitValue<V>\n : U\n : never;\n"]}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { StringAdapter } from '../string-adapter/index.js';
|
2
|
+
export declare function anyBase(sa: StringAdapter, srcAlphabet: string, dstAlphabet: string): (number: string) => string;
|
3
|
+
export declare const BIN = "01";
|
4
|
+
export declare const OCT = "01234567";
|
5
|
+
export declare const DEC = "0123456789";
|
6
|
+
export declare const HEX = "0123456789abcdef";
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/**
|
2
|
+
* @license https://github.com/HarasimowiczKamil/any-base
|
3
|
+
*/
|
4
|
+
import { isDeepEqual } from 'remeda';
|
5
|
+
function isValid(number, alphabet) {
|
6
|
+
for (const char of number) {
|
7
|
+
if (alphabet.indexOf(char) === -1) {
|
8
|
+
return false;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
return true;
|
12
|
+
}
|
13
|
+
function convert(srcAlphabet, dstAlphabet, number) {
|
14
|
+
let i;
|
15
|
+
let divide;
|
16
|
+
let newLen;
|
17
|
+
let { length } = number;
|
18
|
+
const numberMap = {};
|
19
|
+
const fromBase = srcAlphabet.length;
|
20
|
+
const toBase = dstAlphabet.length;
|
21
|
+
const result = [];
|
22
|
+
if (!isValid(number, srcAlphabet)) {
|
23
|
+
throw new Error(`Number "${number}" contains of non-alphabetic digits (${srcAlphabet})`);
|
24
|
+
}
|
25
|
+
if (isDeepEqual(srcAlphabet, dstAlphabet)) {
|
26
|
+
return number.join('');
|
27
|
+
}
|
28
|
+
for (i = 0; i < length; i++) {
|
29
|
+
numberMap[i] = srcAlphabet.indexOf(number[i]);
|
30
|
+
}
|
31
|
+
do {
|
32
|
+
divide = 0;
|
33
|
+
newLen = 0;
|
34
|
+
for (i = 0; i < length; i++) {
|
35
|
+
divide = divide * fromBase + numberMap[i];
|
36
|
+
if (divide >= toBase) {
|
37
|
+
numberMap[newLen++] = Math.floor(divide / toBase);
|
38
|
+
divide %= toBase;
|
39
|
+
}
|
40
|
+
else if (newLen > 0) {
|
41
|
+
numberMap[newLen++] = 0;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
length = newLen;
|
45
|
+
result.push(dstAlphabet[divide]);
|
46
|
+
} while (newLen !== 0);
|
47
|
+
return result.reverse().join('');
|
48
|
+
}
|
49
|
+
export function anyBase(sa, srcAlphabet, dstAlphabet) {
|
50
|
+
return (number) => convert(sa.stringToChars(srcAlphabet), sa.stringToChars(dstAlphabet), sa.stringToChars(number));
|
51
|
+
}
|
52
|
+
export const BIN = '01';
|
53
|
+
export const OCT = '01234567';
|
54
|
+
export const DEC = '0123456789';
|
55
|
+
export const HEX = '0123456789abcdef';
|
56
|
+
//# sourceMappingURL=any-base.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"any-base.js","sourceRoot":"","sources":["../../../src/utils/any-base.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGrC,SAAS,OAAO,CAAC,MAAgB,EAAE,QAAkB;IACnD,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,OAAO,CACd,WAAqB,EACrB,WAAqB,EACrB,MAAgB;IAEhB,IAAI,CAAC,CAAC;IACN,IAAI,MAAM,CAAC;IACX,IAAI,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACxB,MAAM,SAAS,GAA2B,EAAE,CAAC;IAC7C,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC;IACpC,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;IAClC,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,WAAW,MAAM,wCAAwC,WAAW,GAAG,CACxE,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CA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;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC;AACxB,MAAM,CAAC,MAAM,GAAG,GAAG,UAAU,CAAC;AAC9B,MAAM,CAAC,MAAM,GAAG,GAAG,YAAY,CAAC;AAChC,MAAM,CAAC,MAAM,GAAG,GAAG,kBAAkB,CAAC","sourcesContent":["/**\n * @license https://github.com/HarasimowiczKamil/any-base\n */\nimport { isDeepEqual } from 'remeda';\nimport type { StringAdapter } from '../string-adapter/index.js';\n\nfunction isValid(number: string[], alphabet: string[]) {\n for (const char of number) {\n if (alphabet.indexOf(char) === -1) {\n return false;\n }\n }\n return true;\n}\n\nfunction convert(\n srcAlphabet: string[],\n dstAlphabet: string[],\n number: string[],\n) {\n let i;\n let divide;\n let newLen;\n let { length } = number;\n const numberMap: Record<string, number> = {};\n const fromBase = srcAlphabet.length;\n const toBase = dstAlphabet.length;\n const result = [];\n\n if (!isValid(number, srcAlphabet)) {\n throw new Error(\n `Number \"${number}\" contains of non-alphabetic digits (${srcAlphabet})`,\n );\n }\n\n if (isDeepEqual(srcAlphabet, dstAlphabet)) {\n return number.join('');\n }\n\n for (i = 0; i < length; i++) {\n numberMap[i] = srcAlphabet.indexOf(number[i]);\n }\n do {\n divide = 0;\n newLen = 0;\n for (i = 0; i < length; i++) {\n divide = divide * fromBase + numberMap[i];\n if (divide >= toBase) {\n numberMap[newLen++] = Math.floor(divide / toBase);\n divide %= toBase;\n } else if (newLen > 0) {\n numberMap[newLen++] = 0;\n }\n }\n length = newLen;\n result.push(dstAlphabet[divide]);\n } while (newLen !== 0);\n\n return result.reverse().join('');\n}\n\nexport function anyBase(\n sa: StringAdapter,\n srcAlphabet: string,\n dstAlphabet: string,\n) {\n return (number: string) =>\n convert(\n sa.stringToChars(srcAlphabet),\n sa.stringToChars(dstAlphabet),\n sa.stringToChars(number),\n );\n}\n\nexport const BIN = '01';\nexport const OCT = '01234567';\nexport const DEC = '0123456789';\nexport const HEX = '0123456789abcdef';\n"]}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { DurationPartType } from '../types/duration.js';
|
2
|
+
/**
|
3
|
+
* 计算两个日期之间的时间间隔. 返回一个数组, 包含 {@link parts} 每个部分的值.
|
4
|
+
*
|
5
|
+
* @example duration(new Date("2022-01-01"), new Date("2022-01-02"), [DurationPartType.Day, DurationPartType.Hour, DurationPartType.Minute, DurationPartType.Second]) // [1, 0, 0, 0]
|
6
|
+
* @example duration(new Date("2022-01-01 12:00:00"), new Date("2022-01-02 12:30:00"), [DurationPartType.Day, DurationPartType.Hour, DurationPartType.Minute, DurationPartType.Second]) // [1, 0, 30, 0]
|
7
|
+
*
|
8
|
+
* @param start
|
9
|
+
* @param end
|
10
|
+
* @param parts
|
11
|
+
*/
|
12
|
+
export declare function durationObject(start: Date, end: Date, parts: DurationPartType[]): {
|
13
|
+
[key in DurationPartType]?: number;
|
14
|
+
};
|
15
|
+
export declare function duration(start: Date, end: Date, parts: DurationPartType[]): number[];
|