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.
Files changed (206) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -0
  3. package/dist/custom-elements.json +8484 -0
  4. package/dist/src/counter-adapter.d.ts +38 -0
  5. package/dist/src/counter-adapter.js +69 -0
  6. package/dist/src/counter-adapter.js.map +1 -0
  7. package/dist/src/easing/cubic-bezier.d.ts +5 -0
  8. package/dist/src/easing/cubic-bezier.js +35 -0
  9. package/dist/src/easing/cubic-bezier.js.map +1 -0
  10. package/dist/src/easing/easing-functions.d.ts +1 -0
  11. package/dist/src/easing/easing-functions.js +10 -0
  12. package/dist/src/easing/easing-functions.js.map +1 -0
  13. package/dist/src/easing/index.d.ts +2 -0
  14. package/dist/src/easing/index.js +3 -0
  15. package/dist/src/easing/index.js.map +1 -0
  16. package/dist/src/easing/penner-easing-functions.d.ts +33 -0
  17. package/dist/src/easing/penner-easing-functions.js +82 -0
  18. package/dist/src/easing/penner-easing-functions.js.map +1 -0
  19. package/dist/src/index.d.ts +18 -0
  20. package/dist/src/index.js +13 -0
  21. package/dist/src/index.js.map +1 -0
  22. package/dist/src/mixins/counter-aira.d.ts +9 -0
  23. package/dist/src/mixins/counter-aira.js +41 -0
  24. package/dist/src/mixins/counter-aira.js.map +1 -0
  25. package/dist/src/mixins/counter-animation.d.ts +13 -0
  26. package/dist/src/mixins/counter-animation.js +55 -0
  27. package/dist/src/mixins/counter-animation.js.map +1 -0
  28. package/dist/src/mixins/counter-base.d.ts +21 -0
  29. package/dist/src/mixins/counter-base.js +152 -0
  30. package/dist/src/mixins/counter-base.js.map +1 -0
  31. package/dist/src/mixins/counter-parts.d.ts +42 -0
  32. package/dist/src/mixins/counter-parts.js +180 -0
  33. package/dist/src/mixins/counter-parts.js.map +1 -0
  34. package/dist/src/mixins/counter-styles.d.ts +17 -0
  35. package/dist/src/mixins/counter-styles.js +93 -0
  36. package/dist/src/mixins/counter-styles.js.map +1 -0
  37. package/dist/src/number-adapter/build-in-bigint.d.ts +6 -0
  38. package/dist/src/number-adapter/build-in-bigint.js +92 -0
  39. package/dist/src/number-adapter/build-in-bigint.js.map +1 -0
  40. package/dist/src/number-adapter/build-in-number.d.ts +3 -0
  41. package/dist/src/number-adapter/build-in-number.js +84 -0
  42. package/dist/src/number-adapter/build-in-number.js.map +1 -0
  43. package/dist/src/number-adapter/decimal-js.d.ts +4 -0
  44. package/dist/src/number-adapter/decimal-js.js +87 -0
  45. package/dist/src/number-adapter/decimal-js.js.map +1 -0
  46. package/dist/src/number-adapter/index.d.ts +4 -0
  47. package/dist/src/number-adapter/index.js +5 -0
  48. package/dist/src/number-adapter/index.js.map +1 -0
  49. package/dist/src/number-adapter/types.d.ts +34 -0
  50. package/dist/src/number-adapter/types.js +2 -0
  51. package/dist/src/number-adapter/types.js.map +1 -0
  52. package/dist/src/string-adapter/build-in-intl-segmenter.d.ts +10 -0
  53. package/dist/src/string-adapter/build-in-intl-segmenter.js +18 -0
  54. package/dist/src/string-adapter/build-in-intl-segmenter.js.map +1 -0
  55. package/dist/src/string-adapter/build-in-string.d.ts +12 -0
  56. package/dist/src/string-adapter/build-in-string.js +16 -0
  57. package/dist/src/string-adapter/build-in-string.js.map +1 -0
  58. package/dist/src/string-adapter/grapheme-splitter.d.ts +8 -0
  59. package/dist/src/string-adapter/grapheme-splitter.js +16 -0
  60. package/dist/src/string-adapter/grapheme-splitter.js.map +1 -0
  61. package/dist/src/string-adapter/index.d.ts +4 -0
  62. package/dist/src/string-adapter/index.js +5 -0
  63. package/dist/src/string-adapter/index.js.map +1 -0
  64. package/dist/src/string-adapter/types.d.ts +19 -0
  65. package/dist/src/string-adapter/types.js +2 -0
  66. package/dist/src/string-adapter/types.js.map +1 -0
  67. package/dist/src/styles/timered-counter-datetime-styles.d.ts +1 -0
  68. package/dist/src/styles/timered-counter-datetime-styles.js +8 -0
  69. package/dist/src/styles/timered-counter-datetime-styles.js.map +1 -0
  70. package/dist/src/styles/timered-counter-number-styles.d.ts +1 -0
  71. package/dist/src/styles/timered-counter-number-styles.js +3 -0
  72. package/dist/src/styles/timered-counter-number-styles.js.map +1 -0
  73. package/dist/src/styles/timered-counter-string-styles.d.ts +1 -0
  74. package/dist/src/styles/timered-counter-string-styles.js +3 -0
  75. package/dist/src/styles/timered-counter-string-styles.js.map +1 -0
  76. package/dist/src/styles/timered-counter-styles.d.ts +1 -0
  77. package/dist/src/styles/timered-counter-styles.js +25 -0
  78. package/dist/src/styles/timered-counter-styles.js.map +1 -0
  79. package/dist/src/timered-counter-datetime-duration.d.ts +37 -0
  80. package/dist/src/timered-counter-datetime-duration.js +186 -0
  81. package/dist/src/timered-counter-datetime-duration.js.map +1 -0
  82. package/dist/src/timered-counter-number.d.ts +23 -0
  83. package/dist/src/timered-counter-number.js +114 -0
  84. package/dist/src/timered-counter-number.js.map +1 -0
  85. package/dist/src/timered-counter-string.d.ts +30 -0
  86. package/dist/src/timered-counter-string.js +138 -0
  87. package/dist/src/timered-counter-string.js.map +1 -0
  88. package/dist/src/timered-counter.d.ts +15 -0
  89. package/dist/src/timered-counter.js +80 -0
  90. package/dist/src/timered-counter.js.map +1 -0
  91. package/dist/src/transitions/roller/index.d.ts +1 -0
  92. package/dist/src/transitions/roller/index.js +2 -0
  93. package/dist/src/transitions/roller/index.js.map +1 -0
  94. package/dist/src/transitions/roller/roller-digit.d.ts +28 -0
  95. package/dist/src/transitions/roller/roller-digit.js +259 -0
  96. package/dist/src/transitions/roller/roller-digit.js.map +1 -0
  97. package/dist/src/transitions/roller/roller.d.ts +42 -0
  98. package/dist/src/transitions/roller/roller.js +235 -0
  99. package/dist/src/transitions/roller/roller.js.map +1 -0
  100. package/dist/src/transitions/roller/styles.d.ts +2 -0
  101. package/dist/src/transitions/roller/styles.js +77 -0
  102. package/dist/src/transitions/roller/styles.js.map +1 -0
  103. package/dist/src/types/duration.d.ts +33 -0
  104. package/dist/src/types/duration.js +35 -0
  105. package/dist/src/types/duration.js.map +1 -0
  106. package/dist/src/types/group.d.ts +67 -0
  107. package/dist/src/types/group.js +2 -0
  108. package/dist/src/types/group.js.map +1 -0
  109. package/dist/src/utils/any-base.d.ts +6 -0
  110. package/dist/src/utils/any-base.js +56 -0
  111. package/dist/src/utils/any-base.js.map +1 -0
  112. package/dist/src/utils/duration.d.ts +15 -0
  113. package/dist/src/utils/duration.js +66 -0
  114. package/dist/src/utils/duration.js.map +1 -0
  115. package/dist/src/utils/extract-group-option.d.ts +9 -0
  116. package/dist/src/utils/extract-group-option.js +81 -0
  117. package/dist/src/utils/extract-group-option.js.map +1 -0
  118. package/dist/src/utils/iso8601-duration.d.ts +4 -0
  119. package/dist/src/utils/iso8601-duration.js +32 -0
  120. package/dist/src/utils/iso8601-duration.js.map +1 -0
  121. package/dist/src/utils/localized-date-time-fields.d.ts +2 -0
  122. package/dist/src/utils/localized-date-time-fields.js +24 -0
  123. package/dist/src/utils/localized-date-time-fields.js.map +1 -0
  124. package/dist/src/utils/parse-json-string.d.ts +1 -0
  125. package/dist/src/utils/parse-json-string.js +9 -0
  126. package/dist/src/utils/parse-json-string.js.map +1 -0
  127. package/dist/src/utils/polyfill-keyframes.d.ts +1 -0
  128. package/dist/src/utils/polyfill-keyframes.js +19 -0
  129. package/dist/src/utils/polyfill-keyframes.js.map +1 -0
  130. package/dist/src/utils/preprocess-part-data.d.ts +25 -0
  131. package/dist/src/utils/preprocess-part-data.js +59 -0
  132. package/dist/src/utils/preprocess-part-data.js.map +1 -0
  133. package/dist/src/utils/transition-digit.d.ts +2 -0
  134. package/dist/src/utils/transition-digit.js +51 -0
  135. package/dist/src/utils/transition-digit.js.map +1 -0
  136. package/dist/src/utils/uuid.d.ts +1 -0
  137. package/dist/src/utils/uuid.js +7 -0
  138. package/dist/src/utils/uuid.js.map +1 -0
  139. package/dist/stories/story-parts/animation-events.d.ts +9 -0
  140. package/dist/stories/story-parts/animation-events.js +35 -0
  141. package/dist/stories/story-parts/animation-events.js.map +1 -0
  142. package/dist/stories/story-parts/animation-options.d.ts +8 -0
  143. package/dist/stories/story-parts/animation-options.js +25 -0
  144. package/dist/stories/story-parts/animation-options.js.map +1 -0
  145. package/dist/stories/story-parts/big-number.d.ts +8 -0
  146. package/dist/stories/story-parts/big-number.js +25 -0
  147. package/dist/stories/story-parts/big-number.js.map +1 -0
  148. package/dist/stories/story-parts/datetime-locale.d.ts +8 -0
  149. package/dist/stories/story-parts/datetime-locale.js +30 -0
  150. package/dist/stories/story-parts/datetime-locale.js.map +1 -0
  151. package/dist/stories/story-parts/datetime-precision.d.ts +8 -0
  152. package/dist/stories/story-parts/datetime-precision.js +82 -0
  153. package/dist/stories/story-parts/datetime-precision.js.map +1 -0
  154. package/dist/stories/story-parts/edge-case.d.ts +8 -0
  155. package/dist/stories/story-parts/edge-case.js +12 -0
  156. package/dist/stories/story-parts/edge-case.js.map +1 -0
  157. package/dist/stories/story-parts/emoji.d.ts +9 -0
  158. package/dist/stories/story-parts/emoji.js +20 -0
  159. package/dist/stories/story-parts/emoji.js.map +1 -0
  160. package/dist/stories/story-parts/locale-number.d.ts +7 -0
  161. package/dist/stories/story-parts/locale-number.js +23 -0
  162. package/dist/stories/story-parts/locale-number.js.map +1 -0
  163. package/dist/stories/story-parts/slots.d.ts +10 -0
  164. package/dist/stories/story-parts/slots.js +29 -0
  165. package/dist/stories/story-parts/slots.js.map +1 -0
  166. package/dist/stories/story-parts/styles.d.ts +7 -0
  167. package/dist/stories/story-parts/styles.js +34 -0
  168. package/dist/stories/story-parts/styles.js.map +1 -0
  169. package/dist/stories/story-parts/value-change.d.ts +9 -0
  170. package/dist/stories/story-parts/value-change.js +20 -0
  171. package/dist/stories/story-parts/value-change.js.map +1 -0
  172. package/dist/stories/timered-counter/decimaljs.stories.d.ts +6 -0
  173. package/dist/stories/timered-counter/decimaljs.stories.js +34 -0
  174. package/dist/stories/timered-counter/decimaljs.stories.js.map +1 -0
  175. package/dist/stories/timered-counter/index.stories.d.ts +9 -0
  176. package/dist/stories/timered-counter/index.stories.js +180 -0
  177. package/dist/stories/timered-counter/index.stories.js.map +1 -0
  178. package/dist/stories/timered-counter-datetime-duration/index.stories.d.ts +7 -0
  179. package/dist/stories/timered-counter-datetime-duration/index.stories.js +95 -0
  180. package/dist/stories/timered-counter-datetime-duration/index.stories.js.map +1 -0
  181. package/dist/stories/timered-counter-number/decimaljs.stories.d.ts +6 -0
  182. package/dist/stories/timered-counter-number/decimaljs.stories.js +34 -0
  183. package/dist/stories/timered-counter-number/decimaljs.stories.js.map +1 -0
  184. package/dist/stories/timered-counter-number/index.stories.d.ts +9 -0
  185. package/dist/stories/timered-counter-number/index.stories.js +188 -0
  186. package/dist/stories/timered-counter-number/index.stories.js.map +1 -0
  187. package/dist/stories/timered-counter-string/decimaljs.stories.d.ts +7 -0
  188. package/dist/stories/timered-counter-string/decimaljs.stories.js +55 -0
  189. package/dist/stories/timered-counter-string/decimaljs.stories.js.map +1 -0
  190. package/dist/stories/timered-counter-string/grapheme-splitter.stories.d.ts +7 -0
  191. package/dist/stories/timered-counter-string/grapheme-splitter.stories.js +56 -0
  192. package/dist/stories/timered-counter-string/grapheme-splitter.stories.js.map +1 -0
  193. package/dist/stories/timered-counter-string/index.stories.d.ts +9 -0
  194. package/dist/stories/timered-counter-string/index.stories.js +126 -0
  195. package/dist/stories/timered-counter-string/index.stories.js.map +1 -0
  196. package/dist/stories/timered-counter-string/intl-segmenter.stories.d.ts +7 -0
  197. package/dist/stories/timered-counter-string/intl-segmenter.stories.js +56 -0
  198. package/dist/stories/timered-counter-string/intl-segmenter.stories.js.map +1 -0
  199. package/dist/stories/utils/index.d.ts +8 -0
  200. package/dist/stories/utils/index.js +20 -0
  201. package/dist/stories/utils/index.js.map +1 -0
  202. package/dist/test/td-counter.test.d.ts +1 -0
  203. package/dist/test/td-counter.test.js +25 -0
  204. package/dist/test/td-counter.test.js.map +1 -0
  205. package/dist/tsconfig.tsbuildinfo +1 -0
  206. package/package.json +128 -0
@@ -0,0 +1,80 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement } from 'lit';
3
+ import { customElement, query, state } from 'lit/decorators.js';
4
+ import { repeat } from 'lit/directives/repeat.js';
5
+ import { CounterStylesMixin } from './mixins/counter-styles.js';
6
+ import { CounterPartsMixin } from './mixins/counter-parts.js';
7
+ import { CounterBaseMixin } from './mixins/counter-base.js';
8
+ import { timeredCounterStyles } from './styles/timered-counter-styles.js';
9
+ import { CounterAnimationMixin } from './mixins/counter-animation.js';
10
+ import './transitions/roller/index.js';
11
+ import { CounterAiraMixin } from './mixins/counter-aira.js';
12
+ class TimeredCounterAnimationEvent extends Event {
13
+ }
14
+ let TimeredCounter = class TimeredCounter extends CounterAiraMixin(CounterAnimationMixin(CounterStylesMixin(CounterPartsMixin(CounterBaseMixin(LitElement))))) {
15
+ constructor() {
16
+ super();
17
+ this.resizeObserver = new ResizeObserver(() => {
18
+ this.partsContainerRect = this.partsContainer
19
+ ? this.partsContainer.getBoundingClientRect()
20
+ : new DOMRect();
21
+ });
22
+ }
23
+ firstUpdated(_changedProperties) {
24
+ super.firstUpdated(_changedProperties);
25
+ if (this.partsContainer) {
26
+ this.resizeObserver.observe(this.partsContainer);
27
+ }
28
+ }
29
+ render() {
30
+ const cellStyles = this.extractCellStyles();
31
+ const digitStyles = this.extractDigitStyles();
32
+ const partStyles = this.extractPartStyles();
33
+ const animationOptions = this.extractAnimationOptions();
34
+ const keyframes = this.extractKeyframes();
35
+ return html `
36
+ <timered-counter-roller
37
+ exportparts="prefix, suffix, part-suffix"
38
+ class="timered-counter"
39
+ aria-hidden="true"
40
+ color=${this.color}
41
+ .parentContainerRect=${this.partsContainerRect}
42
+ .parts=${this.parts}
43
+ .partPreprocessDataList=${this.partPreprocessDataList}
44
+ .animationOptions=${animationOptions}
45
+ .keyframes=${keyframes}
46
+ .cellStyles=${cellStyles}
47
+ .digitStyles=${digitStyles}
48
+ .partStyles=${partStyles}
49
+ .direction=${this.direction}
50
+ @roller-animation-start=${this.dispatchTimeredCounterAnimationStart}
51
+ @roller-animation-end=${this.dispatchTimeredCounterAnimationEnd}
52
+ >
53
+ <slot name="prefix" slot="prefix"></slot>
54
+ <slot name="suffix" slot="suffix"></slot>
55
+ ${repeat(this.parts, (_, index) => index, (_, partIndex) => html `<slot
56
+ name=${`part-suffix-${partIndex}`}
57
+ slot=${`part-suffix-${partIndex}`}
58
+ ></slot>`)}
59
+ </timered-counter-roller>
60
+ `;
61
+ }
62
+ dispatchTimeredCounterAnimationStart() {
63
+ this.dispatchEvent(new TimeredCounterAnimationEvent('timered-counter-animation-start'));
64
+ }
65
+ dispatchTimeredCounterAnimationEnd() {
66
+ this.dispatchEvent(new TimeredCounterAnimationEvent('timered-counter-animation-end'));
67
+ }
68
+ };
69
+ TimeredCounter.styles = [timeredCounterStyles];
70
+ __decorate([
71
+ state()
72
+ ], TimeredCounter.prototype, "partsContainerRect", void 0);
73
+ __decorate([
74
+ query('timered-counter-roller')
75
+ ], TimeredCounter.prototype, "partsContainer", void 0);
76
+ TimeredCounter = __decorate([
77
+ customElement('timered-counter')
78
+ ], TimeredCounter);
79
+ export { TimeredCounter };
80
+ //# sourceMappingURL=timered-counter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timered-counter.js","sourceRoot":"","sources":["../../src/timered-counter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,O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C,sBAAsB;4BACjC,gBAAgB;qBACvB,SAAS;sBACR,UAAU;uBACT,WAAW;sBACZ,UAAU;qBACX,IAAI,CAAC,SAAS;kCACD,IAAI,CAAC,oCAAoC;gCAC3C,IAAI,CAAC,kCAAkC;;;;UAI7D,MAAM,CACN,IAAI,CAAC,KAAK,EACV,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EACnB,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CACf,IAAI,CAAA;qBACK,eAAe,SAAS,EAAE;qBAC1B,eAAe,SAAS,EAAE;qBAC1B,CACZ;;KAEJ,CAAC;IACJ,CAAC;IAED,oCAAoC;QAClC,IAAI,CAAC,aAAa,CAChB,IAAI,4BAA4B,CAAC,iCAAiC,CAAC,CACpE,CAAC;IACJ,CAAC;IAED,kCAAkC;QAChC,IAAI,CAAC,aAAa,CAChB,IAAI,4BAA4B,CAAC,+BAA+B,CAAC,CAClE,CAAC;IACJ,CAAC;;AA/EM,qBAAM,GAAG,CAAC,oBAAoB,CAAC,AAAzB,CAA0B;AAKvC;IADC,KAAK,EAAE;0DACgC;AAGxC;IADC,KAAK,CAAC,wBAAwB,CAAC;sDACQ;AAb7B,cAAc;IAD1B,aAAa,CAAC,iBAAiB,CAAC;GACpB,cAAc,CAqF1B","sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { customElement, query, state } from 'lit/decorators.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { CounterStylesMixin } from './mixins/counter-styles.js';\nimport { CounterPartsMixin } from './mixins/counter-parts.js';\nimport { CounterBaseMixin } from './mixins/counter-base.js';\nimport { timeredCounterStyles } from './styles/timered-counter-styles.js';\nimport { CounterAnimationMixin } from './mixins/counter-animation.js';\nimport './transitions/roller/index.js';\nimport { CounterAiraMixin } from './mixins/counter-aira.js';\n\nclass TimeredCounterAnimationEvent extends Event {\n // constructor(type: string, eventInitDict?: EventInit) {\n // super(type, eventInitDict);\n // }\n}\n\n@customElement('timered-counter')\nexport class TimeredCounter extends CounterAiraMixin(\n CounterAnimationMixin(\n CounterStylesMixin(CounterPartsMixin(CounterBaseMixin(LitElement))),\n ),\n) {\n static styles = [timeredCounterStyles];\n\n resizeObserver: ResizeObserver;\n\n @state()\n partsContainerRect: DOMRect | undefined;\n\n @query('timered-counter-roller')\n partsContainer: HTMLElement | undefined;\n\n constructor() {\n super();\n\n this.resizeObserver = new ResizeObserver(() => {\n this.partsContainerRect = this.partsContainer\n ? this.partsContainer.getBoundingClientRect()\n : new DOMRect();\n });\n }\n\n protected firstUpdated(_changedProperties: PropertyValues) {\n super.firstUpdated(_changedProperties);\n\n if (this.partsContainer) {\n this.resizeObserver.observe(this.partsContainer);\n }\n }\n\n render() {\n const cellStyles = this.extractCellStyles();\n const digitStyles = this.extractDigitStyles();\n const partStyles = this.extractPartStyles();\n\n const animationOptions = this.extractAnimationOptions();\n const keyframes = this.extractKeyframes();\n\n return html`\n <timered-counter-roller\n exportparts=\"prefix, suffix, part-suffix\"\n class=\"timered-counter\"\n aria-hidden=\"true\"\n color=${this.color}\n .parentContainerRect=${this.partsContainerRect}\n .parts=${this.parts}\n .partPreprocessDataList=${this.partPreprocessDataList}\n .animationOptions=${animationOptions}\n .keyframes=${keyframes}\n .cellStyles=${cellStyles}\n .digitStyles=${digitStyles}\n .partStyles=${partStyles}\n .direction=${this.direction}\n @roller-animation-start=${this.dispatchTimeredCounterAnimationStart}\n @roller-animation-end=${this.dispatchTimeredCounterAnimationEnd}\n >\n <slot name=\"prefix\" slot=\"prefix\"></slot>\n <slot name=\"suffix\" slot=\"suffix\"></slot>\n ${repeat(\n this.parts,\n (_, index) => index,\n (_, partIndex) =>\n html`<slot\n name=${`part-suffix-${partIndex}`}\n slot=${`part-suffix-${partIndex}`}\n ></slot>`,\n )}\n </timered-counter-roller>\n `;\n }\n\n dispatchTimeredCounterAnimationStart() {\n this.dispatchEvent(\n new TimeredCounterAnimationEvent('timered-counter-animation-start'),\n );\n }\n\n dispatchTimeredCounterAnimationEnd() {\n this.dispatchEvent(\n new TimeredCounterAnimationEvent('timered-counter-animation-end'),\n );\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export { TimeredCounterRoller } from './roller.js';
@@ -0,0 +1,2 @@
1
+ export { TimeredCounterRoller } from './roller.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/transitions/roller/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { TimeredCounterRoller } from './roller.js';\n"]}
@@ -0,0 +1,28 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ import { PartPreprocessedData } from '../../utils/preprocess-part-data.js';
3
+ import { PartDataDigit } from '../../types/group.js';
4
+ export declare class TimeredCounterRollerDigit extends LitElement {
5
+ static styles: import("lit").CSSResult[];
6
+ digit: PartDataDigit;
7
+ preprocessData: PartPreprocessedData;
8
+ direction: 'up' | 'down';
9
+ textStyle: Partial<CSSStyleDeclaration>;
10
+ cellStyle: Partial<CSSStyleDeclaration>[];
11
+ animationOptions: KeyframeAnimationOptions;
12
+ keyframes: PropertyIndexedKeyframes;
13
+ clonedRollDigitList: HTMLElement | undefined;
14
+ rollList: HTMLElement | undefined;
15
+ digitWidth: number;
16
+ resizeObserver: ResizeObserver;
17
+ animation: Animation | undefined;
18
+ constructor();
19
+ protected firstUpdated(_changedProperties: PropertyValues<this>): void;
20
+ disconnectedCallback(): void;
21
+ protected updated(_changedProperties: PropertyValues): void;
22
+ render(): import("lit-html").TemplateResult<1>;
23
+ shouldAnimate(): boolean;
24
+ startAnimation(): Promise<void>;
25
+ clearAnimation(): void;
26
+ private __emitAnimationStart;
27
+ private __emitAnimationEnd;
28
+ }
@@ -0,0 +1,259 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement } from 'lit';
3
+ import { repeat } from 'lit/directives/repeat.js';
4
+ import { styleMap } from 'lit/directives/style-map.js';
5
+ import { intersection, isEmpty, isNullish, isString, merge, omit, range, } from 'remeda';
6
+ import { classMap } from 'lit/directives/class-map.js';
7
+ import { customElement, property, query, state } from 'lit/decorators.js';
8
+ import { rollerDigitStyles } from './styles.js';
9
+ import * as EasingFunctions from '../../easing/index.js';
10
+ class RollerDigitAnimationEvent extends Event {
11
+ }
12
+ let TimeredCounterRollerDigit = class TimeredCounterRollerDigit extends LitElement {
13
+ constructor() {
14
+ super();
15
+ this.digit = { data: [], place: 0 };
16
+ this.preprocessData = {
17
+ animate: true,
18
+ cancelPrevAnimation: false,
19
+ earlyReturn: '',
20
+ index: 0,
21
+ partIndex: 0,
22
+ digitIndex: 0,
23
+ };
24
+ this.direction = 'up';
25
+ this.textStyle = {};
26
+ this.cellStyle = [];
27
+ this.animationOptions = {};
28
+ this.keyframes = {};
29
+ this.digitWidth = 0;
30
+ this.resizeObserver = new ResizeObserver(() => {
31
+ this.digitWidth = (this.clonedRollDigitList
32
+ ? this.clonedRollDigitList.getBoundingClientRect()
33
+ : new DOMRect()).width;
34
+ });
35
+ }
36
+ firstUpdated(_changedProperties) {
37
+ super.firstUpdated(_changedProperties);
38
+ if (this.clonedRollDigitList) {
39
+ this.resizeObserver.observe(this.clonedRollDigitList);
40
+ }
41
+ }
42
+ disconnectedCallback() {
43
+ super.disconnectedCallback();
44
+ this.resizeObserver.disconnect();
45
+ }
46
+ updated(_changedProperties) {
47
+ super.updated(_changedProperties);
48
+ /**
49
+ * 仅当影响滚动列表 dom 结构的属性发生变化时才会触发动画.
50
+ */
51
+ if (intersection(Array.from(_changedProperties.keys()), [
52
+ 'digit',
53
+ 'preprocessData',
54
+ 'direction',
55
+ 'animationOptions',
56
+ 'keyframes',
57
+ ]).length > 0) {
58
+ if (this.shouldAnimate()) {
59
+ this.startAnimation().then();
60
+ }
61
+ }
62
+ }
63
+ render() {
64
+ const shadowCellStyle = this.cellStyle.map(style => omit(style, ['position']));
65
+ return html `
66
+ <span class="roller-part-digit">
67
+ <!-- 占位 -->
68
+ <span
69
+ class="placeholder"
70
+ style=${styleMap({ width: `${Math.round(this.digitWidth)}px` })}
71
+ >
72
+ 0
73
+ </span>
74
+ <!-- 一个不可见的滚动列表的复制, 用于计算该列表的最大宽度. -->
75
+ <span class="roll-list__shadow">
76
+ ${repeat(this.digit.data, (_, index) => index, (digit, index) => html `
77
+ <span style=${styleMap(shadowCellStyle[index])}>
78
+ ${digit}
79
+ </span>
80
+ `)}
81
+ </span>
82
+ <span
83
+ class=${classMap({
84
+ /**
85
+ * 向上(up)滚动时, 使滚动列表顶部对齐以便于应用 `translationY(-100%)` 实现向上滚动效果
86
+ * 向下同理
87
+ */
88
+ 'roll-list__up': this.direction === 'up',
89
+ 'roll-list__down': this.direction === 'down',
90
+ 'roll-list': true,
91
+ })}
92
+ >
93
+ ${this.digit.data.length > 1
94
+ ? repeat(this.digit.data, (_, index) => index, (digit, index) => {
95
+ if (this.direction === 'up' &&
96
+ index === this.digit.data.length - 1) {
97
+ return html `<span
98
+ class="roll-item roll-item__head"
99
+ style=${styleMap(this.cellStyle[index])}
100
+ >
101
+ <span style=${styleMap(this.textStyle)}
102
+ >${digit}</span
103
+ >
104
+ </span>`;
105
+ }
106
+ if (this.direction === 'down' && index === 0) {
107
+ return html `
108
+ <span
109
+ class="roll-item roll-item__tail"
110
+ style=${styleMap(this.cellStyle[index])}
111
+ >
112
+ <span style=${styleMap(this.textStyle)}
113
+ >${digit}</span
114
+ >
115
+ </span>
116
+ `;
117
+ }
118
+ return html `
119
+ <span
120
+ class="roll-item"
121
+ style=${styleMap(this.cellStyle[index])}
122
+ >
123
+ <span style=${styleMap(this.textStyle)}
124
+ >${digit}</span
125
+ >
126
+ </span>
127
+ `;
128
+ })
129
+ : html `
130
+ <span
131
+ class="roll-item"
132
+ style=${styleMap(this.cellStyle[0])}
133
+ >
134
+ <span style=${styleMap(this.textStyle)}
135
+ >${this.digit.data[0]}</span
136
+ >
137
+ </span>
138
+ `}
139
+ </span>
140
+ </span>
141
+ `;
142
+ }
143
+ shouldAnimate() {
144
+ const { cancelPrevAnimation, animate } = this.preprocessData;
145
+ if (cancelPrevAnimation) {
146
+ if (this.animation) {
147
+ this.animation.cancel();
148
+ }
149
+ if (this.rollList && this.rollList.style && this.rollList.style.cssText) {
150
+ this.rollList.style.cssText = '';
151
+ }
152
+ }
153
+ if (!animate)
154
+ return false;
155
+ return true;
156
+ }
157
+ async startAnimation() {
158
+ if (isNullish(this.rollList))
159
+ return;
160
+ this.__emitAnimationStart();
161
+ const anmOptions = merge({ duration: 1000, iterations: 1, easing: 'ease-out', fill: 'forwards' }, this.animationOptions);
162
+ const keyframes = isEmpty(this.keyframes)
163
+ ? {
164
+ up: { transform: ['translateY(0)', 'translateY(-100%)'] },
165
+ down: { transform: ['translateY(0)', 'translateY(100%)'] },
166
+ }[this.direction]
167
+ : this.keyframes;
168
+ /**
169
+ * 尝试从 `PennerEasingFunctions` 中获取对应的 easing 函数
170
+ */
171
+ // {
172
+ if (isString(anmOptions.easing) &&
173
+ EasingFunctions[anmOptions.easing]) {
174
+ const func = EasingFunctions[anmOptions.easing];
175
+ anmOptions.easing = `linear(${range(0, 64)
176
+ .map((_, i) => func(i / 63))
177
+ .join(',')})`;
178
+ }
179
+ // }
180
+ try {
181
+ this.clearAnimation();
182
+ this.animation = this.rollList.animate(keyframes, anmOptions);
183
+ this.animation.addEventListener('finish', () => this.__emitAnimationEnd(), {
184
+ once: true,
185
+ });
186
+ // /**
187
+ // * 动画播放完成或被其他动画中断都会使得 `finished` resolve.
188
+ // * 只有当动画顺利播放完成的情况下, 才能调用 `cancel` 取消动画. 在其他情况下调用, 会抛出异常[1].
189
+ // *
190
+ // * 因此, 提前检查 `playState` 的值. 当 `playState` 不是 `finished` 时, 说明动画被其他 `Animation` 实例中断.
191
+ // * 因为已经有其他 `Animation` 实例的存在, 我们可以直接丢弃这个 `Animation` 实例, 而不用担心无动画可用.
192
+ // *
193
+ // * [1]: https://developer.mozilla.org/en-US/docs/Web/API/Animation/cancel#exceptions
194
+ // */
195
+ // await this.animation.finished;
196
+ // if (
197
+ // this.animation.playState === 'finished' &&
198
+ // this.rollList.checkVisibility()
199
+ // ) {
200
+ // // this.animation.commitStyles();
201
+ // // this.animation.cancel();
202
+ // }
203
+ }
204
+ catch (e) {
205
+ // eslint-disable-next-line no-console
206
+ console.error(e);
207
+ }
208
+ }
209
+ clearAnimation() {
210
+ this.animation?.removeEventListener('finish', this.__emitAnimationEnd);
211
+ this.animation?.cancel();
212
+ }
213
+ __emitAnimationStart() {
214
+ if (!this.isConnected)
215
+ return;
216
+ this.dispatchEvent(new RollerDigitAnimationEvent('roller-digit-animation-start'));
217
+ }
218
+ __emitAnimationEnd() {
219
+ if (!this.isConnected)
220
+ return;
221
+ this.dispatchEvent(new RollerDigitAnimationEvent('roller-digit-animation-end'));
222
+ }
223
+ };
224
+ TimeredCounterRollerDigit.styles = [rollerDigitStyles];
225
+ __decorate([
226
+ property({ type: Object })
227
+ ], TimeredCounterRollerDigit.prototype, "digit", void 0);
228
+ __decorate([
229
+ property({ type: Object })
230
+ ], TimeredCounterRollerDigit.prototype, "preprocessData", void 0);
231
+ __decorate([
232
+ property({ type: String })
233
+ ], TimeredCounterRollerDigit.prototype, "direction", void 0);
234
+ __decorate([
235
+ property({ type: Object })
236
+ ], TimeredCounterRollerDigit.prototype, "textStyle", void 0);
237
+ __decorate([
238
+ property({ type: Array })
239
+ ], TimeredCounterRollerDigit.prototype, "cellStyle", void 0);
240
+ __decorate([
241
+ property({ type: Object })
242
+ ], TimeredCounterRollerDigit.prototype, "animationOptions", void 0);
243
+ __decorate([
244
+ property({ type: Object })
245
+ ], TimeredCounterRollerDigit.prototype, "keyframes", void 0);
246
+ __decorate([
247
+ query('.roll-list__shadow')
248
+ ], TimeredCounterRollerDigit.prototype, "clonedRollDigitList", void 0);
249
+ __decorate([
250
+ query('.roll-list')
251
+ ], TimeredCounterRollerDigit.prototype, "rollList", void 0);
252
+ __decorate([
253
+ state()
254
+ ], TimeredCounterRollerDigit.prototype, "digitWidth", void 0);
255
+ TimeredCounterRollerDigit = __decorate([
256
+ customElement('timered-counter-roller-digit')
257
+ ], TimeredCounterRollerDigit);
258
+ export { TimeredCounterRollerDigit };
259
+ //# sourceMappingURL=roller-digit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roller-digit.js","sourceRoot":"","sources":["../../../../src/transitions/roller/roller-digit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAa,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EACL,YAAY,EACZ,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,KAAK,GACN,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AAEzD,MAAM,yBAA0B,SAAQ,KAAK;CAI5C;AAGM,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,UAAU;IA4CvD;QACE,KAAK,EAAE,CAAC;QAzCV,UAAK,GAAkB,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAG9C,mBAAc,GAAyB;YACrC,OAAO,EAAE,IAAI;YACb,mBAAmB,EAAE,KAAK;YAC1B,WAAW,EAAE,EAAE;YACf,KAAK,EAAE,CAAC;YACR,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,CAAC;SACd,CAAC;QAGF,cAAS,GAAkB,IAAI,CAAC;QAGhC,cAAS,GAAiC,EAAE,CA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DACqB;AAG/C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mEACqB;AAGhD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4DACc;AAGzC;IADC,KAAK,CAAC,oBAAoB,CAAC;sEACiB;AAG7C;IADC,KAAK,CAAC,YAAY,CAAC;2DACc;AAGlC;IADC,KAAK,EAAE;6DACe;AAtCZ,yBAAyB;IADrC,aAAa,CAAC,8BAA8B,CAAC;GACjC,yBAAyB,CAkSrC","sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { StyleInfo, styleMap } from 'lit/directives/style-map.js';\nimport {\n intersection,\n isEmpty,\n isNullish,\n isString,\n merge,\n omit,\n range,\n} from 'remeda';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { PartPreprocessedData } from '../../utils/preprocess-part-data.js';\nimport { PartDataDigit } from '../../types/group.js';\nimport { rollerDigitStyles } from './styles.js';\nimport * as EasingFunctions from '../../easing/index.js';\n\nclass RollerDigitAnimationEvent extends Event {\n // constructor(type: string, eventInitDict?: EventInit) {\n // super(type, eventInitDict);\n // }\n}\n\n@customElement('timered-counter-roller-digit')\nexport class TimeredCounterRollerDigit extends LitElement {\n static styles = [rollerDigitStyles];\n\n @property({ type: Object })\n digit: PartDataDigit = { data: [], place: 0 };\n\n @property({ type: Object })\n preprocessData: PartPreprocessedData = {\n animate: true,\n cancelPrevAnimation: false,\n earlyReturn: '',\n index: 0,\n partIndex: 0,\n digitIndex: 0,\n };\n\n @property({ type: String })\n direction: 'up' | 'down' = 'up';\n\n @property({ type: Object })\n textStyle: Partial<CSSStyleDeclaration> = {};\n\n @property({ type: Array })\n cellStyle: Partial<CSSStyleDeclaration>[] = [];\n\n @property({ type: Object })\n animationOptions: KeyframeAnimationOptions = {};\n\n @property({ type: Object })\n keyframes: PropertyIndexedKeyframes = {};\n\n @query('.roll-list__shadow')\n clonedRollDigitList: HTMLElement | undefined;\n\n @query('.roll-list')\n rollList: HTMLElement | undefined;\n\n @state()\n digitWidth: number = 0;\n\n resizeObserver: ResizeObserver;\n\n animation: Animation | undefined;\n\n constructor() {\n super();\n\n this.resizeObserver = new ResizeObserver(() => {\n this.digitWidth = (\n this.clonedRollDigitList\n ? this.clonedRollDigitList.getBoundingClientRect()\n : new DOMRect()\n ).width;\n });\n }\n\n protected firstUpdated(_changedProperties: PropertyValues<this>) {\n super.firstUpdated(_changedProperties);\n\n if (this.clonedRollDigitList) {\n this.resizeObserver.observe(this.clonedRollDigitList);\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n\n this.resizeObserver.disconnect();\n }\n\n protected updated(_changedProperties: PropertyValues) {\n super.updated(_changedProperties);\n\n /**\n * 仅当影响滚动列表 dom 结构的属性发生变化时才会触发动画.\n */\n if (\n intersection(Array.from(_changedProperties.keys()), [\n 'digit',\n 'preprocessData',\n 'direction',\n 'animationOptions',\n 'keyframes',\n ]).length > 0\n ) {\n if (this.shouldAnimate()) {\n this.startAnimation().then();\n }\n }\n }\n\n render() {\n const shadowCellStyle = this.cellStyle.map(style =>\n omit(style, ['position']),\n );\n\n return html`\n <span class=\"roller-part-digit\">\n <!-- 占位 -->\n <span\n class=\"placeholder\"\n style=${styleMap({ width: `${Math.round(this.digitWidth)}px` })}\n >\n 0\n </span>\n <!-- 一个不可见的滚动列表的复制, 用于计算该列表的最大宽度. -->\n <span class=\"roll-list__shadow\">\n ${repeat(\n this.digit.data,\n (_, index) => index,\n (digit, index) => html`\n <span style=${styleMap(shadowCellStyle[index] as StyleInfo)}>\n ${digit}\n </span>\n `,\n )}\n </span>\n <span\n class=${classMap({\n /**\n * 向上(up)滚动时, 使滚动列表顶部对齐以便于应用 `translationY(-100%)` 实现向上滚动效果\n * 向下同理\n */\n 'roll-list__up': this.direction === 'up',\n 'roll-list__down': this.direction === 'down',\n 'roll-list': true,\n })}\n >\n ${this.digit.data.length > 1\n ? repeat(\n this.digit.data,\n (_, index) => index,\n (digit, index) => {\n if (\n this.direction === 'up' &&\n index === this.digit.data.length - 1\n ) {\n return html`<span\n class=\"roll-item roll-item__head\"\n style=${styleMap(this.cellStyle[index] as StyleInfo)}\n >\n <span style=${styleMap(this.textStyle as StyleInfo)}\n >${digit}</span\n >\n </span>`;\n }\n if (this.direction === 'down' && index === 0) {\n return html`\n <span\n class=\"roll-item roll-item__tail\"\n style=${styleMap(this.cellStyle[index] as StyleInfo)}\n >\n <span style=${styleMap(this.textStyle as StyleInfo)}\n >${digit}</span\n >\n </span>\n `;\n }\n return html`\n <span\n class=\"roll-item\"\n style=${styleMap(this.cellStyle[index] as StyleInfo)}\n >\n <span style=${styleMap(this.textStyle as StyleInfo)}\n >${digit}</span\n >\n </span>\n `;\n },\n )\n : html`\n <span\n class=\"roll-item\"\n style=${styleMap(this.cellStyle[0] as StyleInfo)}\n >\n <span style=${styleMap(this.textStyle as StyleInfo)}\n >${this.digit.data[0]}</span\n >\n </span>\n `}\n </span>\n </span>\n `;\n }\n\n shouldAnimate() {\n const { cancelPrevAnimation, animate } = this.preprocessData;\n if (cancelPrevAnimation) {\n if (this.animation) {\n this.animation.cancel();\n }\n\n if (this.rollList && this.rollList.style && this.rollList.style.cssText) {\n this.rollList.style.cssText = '';\n }\n }\n\n if (!animate) return false;\n\n return true;\n }\n\n async startAnimation() {\n if (isNullish(this.rollList)) return;\n\n this.__emitAnimationStart();\n\n const anmOptions = merge(\n { duration: 1000, iterations: 1, easing: 'ease-out', fill: 'forwards' },\n this.animationOptions,\n );\n\n const keyframes = isEmpty(this.keyframes)\n ? {\n up: { transform: ['translateY(0)', 'translateY(-100%)'] },\n down: { transform: ['translateY(0)', 'translateY(100%)'] },\n }[this.direction]\n : this.keyframes;\n\n /**\n * 尝试从 `PennerEasingFunctions` 中获取对应的 easing 函数\n */\n // {\n if (\n isString(anmOptions.easing) &&\n EasingFunctions[anmOptions.easing as keyof typeof EasingFunctions]\n ) {\n const func =\n EasingFunctions[anmOptions.easing as keyof typeof EasingFunctions];\n anmOptions.easing = `linear(${range(0, 64)\n .map((_, i) => func(i / 63))\n .join(',')})`;\n }\n // }\n\n try {\n this.clearAnimation();\n this.animation = this.rollList.animate(keyframes, anmOptions);\n\n this.animation.addEventListener(\n 'finish',\n () => this.__emitAnimationEnd(),\n {\n once: true,\n },\n );\n\n // /**\n // * 动画播放完成或被其他动画中断都会使得 `finished` resolve.\n // * 只有当动画顺利播放完成的情况下, 才能调用 `cancel` 取消动画. 在其他情况下调用, 会抛出异常[1].\n // *\n // * 因此, 提前检查 `playState` 的值. 当 `playState` 不是 `finished` 时, 说明动画被其他 `Animation` 实例中断.\n // * 因为已经有其他 `Animation` 实例的存在, 我们可以直接丢弃这个 `Animation` 实例, 而不用担心无动画可用.\n // *\n // * [1]: https://developer.mozilla.org/en-US/docs/Web/API/Animation/cancel#exceptions\n // */\n // await this.animation.finished;\n // if (\n // this.animation.playState === 'finished' &&\n // this.rollList.checkVisibility()\n // ) {\n // // this.animation.commitStyles();\n // // this.animation.cancel();\n // }\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n }\n }\n\n clearAnimation() {\n this.animation?.removeEventListener('finish', this.__emitAnimationEnd);\n this.animation?.cancel();\n }\n\n private __emitAnimationStart() {\n if (!this.isConnected) return;\n\n this.dispatchEvent(\n new RollerDigitAnimationEvent('roller-digit-animation-start'),\n );\n }\n\n private __emitAnimationEnd() {\n if (!this.isConnected) return;\n\n this.dispatchEvent(\n new RollerDigitAnimationEvent('roller-digit-animation-end'),\n );\n }\n}\n"]}
@@ -0,0 +1,42 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ import { PartData } from '../../types/group.js';
3
+ import { PartPreprocessedData } from '../../utils/preprocess-part-data.js';
4
+ import './roller-digit.js';
5
+ export declare class TimeredCounterRoller extends LitElement {
6
+ static styles: import("lit").CSSResult[];
7
+ color: string;
8
+ direction: 'up' | 'down';
9
+ parts: PartData[];
10
+ partPreprocessDataList: PartPreprocessedData[][];
11
+ animationOptions: KeyframeAnimationOptions[][];
12
+ keyframes: PropertyIndexedKeyframes[][];
13
+ cellStyles: Partial<CSSStyleDeclaration>[][][];
14
+ digitStyles: Partial<CSSStyleDeclaration>[][];
15
+ partStyles: Partial<CSSStyleDeclaration>[];
16
+ parentContainerRect: DOMRect;
17
+ prefixContainer: HTMLElement | undefined;
18
+ suffixContainer: HTMLElement | undefined;
19
+ private __mergedDigitStyles;
20
+ protected render(): import("lit-html").TemplateResult<1>;
21
+ protected willUpdate(_changedProperties: PropertyValues): void;
22
+ /**
23
+ * 记录一次更新中, 启动动画并结束的 <timered-counter-roller-digit> 元素个数.
24
+ *
25
+ * 在每次更新前重置为 0.
26
+ *
27
+ * @see {@link __handleDigitAnimationEnd}
28
+ * @private
29
+ */
30
+ private digitAnimateEndCount;
31
+ /**
32
+ * 记录一次更新中, 需要启动动画的 <timered-counter-roller-digit> 元素总数.
33
+ *
34
+ * 在每次更新前重新计算.
35
+ * @private
36
+ */
37
+ private digitAnimatedCount;
38
+ private __handleDigitAnimationEnd;
39
+ private __emitAnimationStart;
40
+ private __emitAnimationEnd;
41
+ private __generatePartDigitsColorStyles;
42
+ }