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,152 @@
1
+ import { __decorate } from "tslib";
2
+ import { property, state } from 'lit/decorators.js';
3
+ import { isNonNullish, isNullish, isString } from 'remeda';
4
+ import { CounterAdapter } from '../counter-adapter.js';
5
+ export const CounterBaseMixin = (superClass) => {
6
+ class CounterBaseMixinClass extends superClass {
7
+ get value() {
8
+ return this.numberAdapter.create(this.__value);
9
+ }
10
+ set value(value) {
11
+ value = CounterAdapter.NUMBER_ADAPTER.create(isNullish(value) || (isString(value) && value.trim() === '')
12
+ ? 0
13
+ : value);
14
+ const old = this.__value;
15
+ this.__value = value;
16
+ if (!this.numberAdapter.eq(this.__value, old)) {
17
+ this.requestUpdate('value', old);
18
+ }
19
+ }
20
+ get oldValue() {
21
+ return this.numberAdapter.create(this.__oldValue);
22
+ }
23
+ set oldValue(value) {
24
+ const old = this.__oldValue;
25
+ this.__oldValue = value;
26
+ this.requestUpdate('oldValue', old);
27
+ }
28
+ /**
29
+ * 如果初始值被设置, 组件初始化时会使用该值而不是 `value`, 然后在初始化完成后, 将内部值更新为 `value`.
30
+ *
31
+ * 这对于初始化完成后启动动画效果非常有用.
32
+ */
33
+ get initialValue() {
34
+ return this.numberAdapter.create(this.__initialValue);
35
+ }
36
+ set initialValue(value) {
37
+ const old = this.__initialValue;
38
+ this.__initialValue = value;
39
+ this.requestUpdate('initialValue', old);
40
+ }
41
+ /**
42
+ * 自定义本地化配置, 否则从浏览器环境中获取.
43
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale
44
+ *
45
+ * @default "en-US"
46
+ */
47
+ get locale() {
48
+ return this.__locale;
49
+ }
50
+ set locale(value) {
51
+ const old = this.__locale;
52
+ this.__locale = value;
53
+ this.requestUpdate('locale', old);
54
+ this.localeInstance = isString(this.__locale)
55
+ ? new Intl.Locale(this.__locale)
56
+ : new Intl.Locale(...this.__locale);
57
+ }
58
+ constructor(...args) {
59
+ super(...args);
60
+ this.__value = CounterAdapter.NUMBER_ADAPTER.create(0);
61
+ // value: V = CounterBaseMixinClass.NUMBER_ADAPTER.create(0);
62
+ this.__oldValue = CounterAdapter.NUMBER_ADAPTER.create(0);
63
+ // oldValue: V = CounterBaseMixinClass.NUMBER_ADAPTER.create(0);
64
+ this.__initialValue = CounterAdapter.NUMBER_ADAPTER.create(0);
65
+ this.__locale = 'en-US';
66
+ this.localeInstance = isString(this.locale)
67
+ ? new Intl.Locale(this.locale)
68
+ : new Intl.Locale(...this.locale);
69
+ this.direction = 'up';
70
+ this.oldDirection = this.direction;
71
+ /**
72
+ * 第一次更新时, changedProperties 中 value 的旧值始终为 undefined.
73
+ * 因此, 当 value 第一次更新时, oldValue 的值应当来自 initialValue 或 value.
74
+ * 以保证 oldValue 始终有值.
75
+ * @private
76
+ */
77
+ this.isValueFirstUpdate = true;
78
+ // @ts-ignore
79
+ this.numberAdapter = CounterAdapter.NUMBER_ADAPTER;
80
+ // @ts-ignore
81
+ this.stringAdapter = CounterAdapter.STRING_ADAPTER;
82
+ }
83
+ willUpdate(changedProperties) {
84
+ super.willUpdate(changedProperties);
85
+ if (changedProperties.has('value')) {
86
+ if (this.isValueFirstUpdate) {
87
+ this.isValueFirstUpdate = false;
88
+ this.oldValue = isNonNullish(this.initialValue)
89
+ ? this.initialValue
90
+ : this.value;
91
+ }
92
+ else {
93
+ this.oldValue = changedProperties.get('value') ?? this.oldValue;
94
+ }
95
+ }
96
+ this.oldDirection = this.direction;
97
+ this.direction = this.numberAdapter.gt(this.value, this.oldValue)
98
+ ? 'down'
99
+ : 'up';
100
+ // }
101
+ }
102
+ }
103
+ __decorate([
104
+ property({
105
+ attribute: 'value',
106
+ reflect: true,
107
+ converter: {
108
+ toAttribute: CounterAdapter.VALUE_CONVERTER.toAttribute,
109
+ },
110
+ noAccessor: true,
111
+ })
112
+ ], CounterBaseMixinClass.prototype, "value", null);
113
+ __decorate([
114
+ property({
115
+ attribute: 'old-value',
116
+ reflect: true,
117
+ converter: CounterAdapter.VALUE_CONVERTER,
118
+ noAccessor: true,
119
+ })
120
+ ], CounterBaseMixinClass.prototype, "oldValue", null);
121
+ __decorate([
122
+ property({
123
+ attribute: 'initial-value',
124
+ reflect: true,
125
+ converter: CounterAdapter.VALUE_CONVERTER,
126
+ noAccessor: true,
127
+ })
128
+ ], CounterBaseMixinClass.prototype, "initialValue", null);
129
+ __decorate([
130
+ property({
131
+ converter: value => {
132
+ if (isNullish(value))
133
+ return value;
134
+ try {
135
+ return JSON.parse(value);
136
+ }
137
+ catch (error) {
138
+ return value;
139
+ }
140
+ },
141
+ noAccessor: true,
142
+ })
143
+ ], CounterBaseMixinClass.prototype, "locale", null);
144
+ __decorate([
145
+ state()
146
+ ], CounterBaseMixinClass.prototype, "direction", void 0);
147
+ __decorate([
148
+ state()
149
+ ], CounterBaseMixinClass.prototype, "oldDirection", void 0);
150
+ return CounterBaseMixinClass;
151
+ };
152
+ //# sourceMappingURL=counter-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counter-base.js","sourceRoot":"","sources":["../../../src/mixins/counter-base.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAO3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAoCvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAI9B,UAAa,EACb,EAAE;IACF,MAAM,qBAAsB,SAAQ,UAAU;QAW5C,IAAI,KAAK;YACP,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,KAAK,CAAC,KAAQ;YAChB,KAAK,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,CAC1C,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,E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CAAC;oBAAE,OAAO,KAAK,CAAC;gBAEnC,IAAI,CAAC;oBACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC3B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YACD,UAAU,EAAE,IAAI;SACjB,CAAC;uDAGD;IAqBD;QADC,KAAK,EAAE;4DACwB;IAGhC;QADC,KAAK,EAAE;+DACqC;IA6C/C,OAAO,qBAAsE,CAAC;AAChF,CAAC,CAAC","sourcesContent":["import { LitElement, PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { isNonNullish, isNullish, isString } from 'remeda';\nimport { Constructor } from 'type-fest';\nimport {\n NumberAdapter,\n AvailableNumberAdapterValueType,\n} from '../number-adapter/index.js';\nimport { StringAdapter } from '../string-adapter/index.js';\nimport { CounterAdapter } from '../counter-adapter.js';\n\nexport declare class CounterBaseMixinInterface<\n V extends AvailableNumberAdapterValueType,\n> {\n static NUMBER_ADAPTER: NumberAdapter;\n\n static STRING_ADAPTER: StringAdapter;\n\n get value(): V;\n\n set value(value: V);\n\n get oldValue(): V;\n\n set oldValue(value: V);\n\n get initialValue(): V;\n\n set initialValue(value: V);\n\n direction: 'up' | 'down';\n\n oldDirection: 'up' | 'down';\n\n locale:\n | Intl.UnicodeBCP47LocaleIdentifier\n | [Intl.UnicodeBCP47LocaleIdentifier, Intl.LocaleOptions];\n\n localeInstance: Intl.Locale;\n\n numberAdapter: NumberAdapter;\n\n stringAdapter: StringAdapter;\n}\n\nexport const CounterBaseMixin = <\n V extends AvailableNumberAdapterValueType,\n T extends Constructor<LitElement> = Constructor<LitElement>,\n>(\n superClass: T,\n) => {\n class CounterBaseMixinClass extends superClass {\n private __value: V = CounterAdapter.NUMBER_ADAPTER.create(0);\n\n @property({\n attribute: 'value',\n reflect: true,\n converter: {\n toAttribute: CounterAdapter.VALUE_CONVERTER.toAttribute,\n },\n noAccessor: true,\n })\n get value() {\n return this.numberAdapter.create(this.__value);\n }\n\n set value(value: V) {\n value = CounterAdapter.NUMBER_ADAPTER.create(\n isNullish(value) || (isString(value) && value.trim() === '')\n ? 0\n : value,\n );\n\n const old = this.__value;\n this.__value = value;\n\n if (!this.numberAdapter.eq(this.__value, old)) {\n this.requestUpdate('value', old);\n }\n }\n // value: V = CounterBaseMixinClass.NUMBER_ADAPTER.create(0);\n\n private __oldValue: V = CounterAdapter.NUMBER_ADAPTER.create(0);\n\n @property({\n attribute: 'old-value',\n reflect: true,\n converter: CounterAdapter.VALUE_CONVERTER,\n noAccessor: true,\n })\n get oldValue() {\n return this.numberAdapter.create(this.__oldValue);\n }\n\n set oldValue(value: V) {\n const old = this.__oldValue;\n this.__oldValue = value;\n this.requestUpdate('oldValue', old);\n }\n // oldValue: V = CounterBaseMixinClass.NUMBER_ADAPTER.create(0);\n\n private __initialValue: V = CounterAdapter.NUMBER_ADAPTER.create(0);\n\n /**\n * 如果初始值被设置, 组件初始化时会使用该值而不是 `value`, 然后在初始化完成后, 将内部值更新为 `value`.\n *\n * 这对于初始化完成后启动动画效果非常有用.\n */\n @property({\n attribute: 'initial-value',\n reflect: true,\n converter: CounterAdapter.VALUE_CONVERTER,\n noAccessor: true,\n })\n get initialValue() {\n return this.numberAdapter.create(this.__initialValue);\n }\n\n set initialValue(value: V) {\n const old = this.__initialValue;\n this.__initialValue = value;\n this.requestUpdate('initialValue', old);\n }\n\n private __locale:\n | Intl.UnicodeBCP47LocaleIdentifier\n | [Intl.UnicodeBCP47LocaleIdentifier, Intl.LocaleOptions] = 'en-US';\n\n /**\n * 自定义本地化配置, 否则从浏览器环境中获取.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale\n *\n * @default \"en-US\"\n */\n @property({\n converter: value => {\n if (isNullish(value)) return value;\n\n try {\n return JSON.parse(value);\n } catch (error) {\n return value;\n }\n },\n noAccessor: true,\n })\n get locale() {\n return this.__locale;\n }\n\n set locale(\n value:\n | Intl.UnicodeBCP47LocaleIdentifier\n | [Intl.UnicodeBCP47LocaleIdentifier, Intl.LocaleOptions],\n ) {\n const old = this.__locale;\n this.__locale = value;\n this.requestUpdate('locale', old);\n\n this.localeInstance = isString(this.__locale)\n ? new Intl.Locale(this.__locale)\n : new Intl.Locale(...this.__locale);\n }\n\n localeInstance: Intl.Locale = isString(this.locale)\n ? new Intl.Locale(this.locale)\n : new Intl.Locale(...this.locale);\n\n @state()\n direction: 'up' | 'down' = 'up';\n\n @state()\n oldDirection: 'up' | 'down' = this.direction;\n\n numberAdapter: NumberAdapter;\n\n stringAdapter: StringAdapter;\n\n constructor(...args: any[]) {\n super(...args);\n\n // @ts-ignore\n this.numberAdapter = CounterAdapter.NUMBER_ADAPTER;\n // @ts-ignore\n this.stringAdapter = CounterAdapter.STRING_ADAPTER;\n }\n\n /**\n * 第一次更新时, changedProperties 中 value 的旧值始终为 undefined.\n * 因此, 当 value 第一次更新时, oldValue 的值应当来自 initialValue 或 value.\n * 以保证 oldValue 始终有值.\n * @private\n */\n private isValueFirstUpdate = true;\n\n override willUpdate(changedProperties: PropertyValues<this>) {\n super.willUpdate(changedProperties);\n\n if (changedProperties.has('value')) {\n if (this.isValueFirstUpdate) {\n this.isValueFirstUpdate = false;\n this.oldValue = isNonNullish(this.initialValue)\n ? this.initialValue\n : this.value;\n } else {\n this.oldValue = changedProperties.get('value') ?? this.oldValue;\n }\n }\n\n this.oldDirection = this.direction;\n this.direction = this.numberAdapter.gt(this.value, this.oldValue)\n ? 'down'\n : 'up';\n // }\n }\n }\n\n return CounterBaseMixinClass as Constructor<CounterBaseMixinInterface<V>> & T;\n};\n"]}
@@ -0,0 +1,42 @@
1
+ import { Constructor } from 'type-fest';
2
+ import { CounterBaseMixin } from './counter-base.js';
3
+ import { PartData } from '../types/group.js';
4
+ import { PartPreprocessedData } from '../utils/preprocess-part-data.js';
5
+ import { AvailableNumberAdapterValueType } from '../number-adapter/index.js';
6
+ export interface PartsOptions {
7
+ sampleCount: number;
8
+ /**
9
+ * 可以通过该属性将数字转换为你想要的任意字符串.
10
+ */
11
+ digitToChar: Record<string | number, string> | string[];
12
+ /**
13
+ * 小数点分隔符.
14
+ */
15
+ decimalSeparator: string;
16
+ /**
17
+ * 当**位数不足**时, 强制补全的 [整数, 小数] 位数. 为空时位数自适应.
18
+ */
19
+ minPlaces: [number | undefined, number | undefined];
20
+ fillChar: string;
21
+ /**
22
+ * 数据类型.
23
+ *
24
+ * 1. `'string'`: 字符串类型.
25
+ * 1. 不会使用 `decimalSeparator` 截取小数部分.
26
+ * 2. `'number'`: 数字类型.
27
+ *
28
+ * @default `'number'`
29
+ */
30
+ type: 'string' | 'number';
31
+ }
32
+ export declare class CounterPartsMixinInterface<V extends AvailableNumberAdapterValueType> {
33
+ parts: PartData[];
34
+ oldParts: PartData[];
35
+ partPreprocessDataList: PartPreprocessedData[][];
36
+ get partsOptions(): Partial<PartsOptions>;
37
+ set partsOptions(value: Partial<PartsOptions>);
38
+ sampling(from: V, to: V): V[];
39
+ sampleSplit(samples: V[]): V[][];
40
+ sampleToString(value: V): string;
41
+ }
42
+ export declare const CounterPartsMixin: <V extends AvailableNumberAdapterValueType, T extends ReturnType<typeof CounterBaseMixin<V>> = Constructor<import("./counter-base.js").CounterBaseMixinInterface<V>> & Constructor<import("lit").LitElement>>(superClass: T) => Constructor<CounterPartsMixinInterface<V>> & T;
@@ -0,0 +1,180 @@
1
+ import { __classPrivateFieldGet, __classPrivateFieldSet, __decorate } from "tslib";
2
+ import { zip } from 'd3-array';
3
+ import { property } from 'lit/decorators.js';
4
+ import { isArray, isObjectType } from 'remeda';
5
+ import { transitionDigit } from '../utils/transition-digit.js';
6
+ import { preprocessPartData, } from '../utils/preprocess-part-data.js';
7
+ import { parseJsonString } from '../utils/parse-json-string.js';
8
+ function toChar(value) {
9
+ return String.fromCodePoint(value + 48);
10
+ }
11
+ function preprocessPartsOptions(options) {
12
+ const digitToChar = {};
13
+ if (isArray(options.digitToChar)) {
14
+ options.digitToChar.forEach((char, index) => {
15
+ digitToChar[toChar(index)] = char;
16
+ });
17
+ }
18
+ else if (isObjectType(options.digitToChar)) {
19
+ Object.entries(options.digitToChar).forEach(([key, value]) => {
20
+ digitToChar[key] = value;
21
+ });
22
+ }
23
+ return {
24
+ ...options,
25
+ digitToChar,
26
+ };
27
+ }
28
+ export const CounterPartsMixin = (superClass) => {
29
+ var _a, _CounterPartsMixinClass___partsOptions;
30
+ class CounterPartsMixinClass extends superClass {
31
+ constructor() {
32
+ super(...arguments);
33
+ _CounterPartsMixinClass___partsOptions.set(this, {
34
+ ..._a.DEFAULT_PARTS_OPTIONS,
35
+ });
36
+ // partsOptions: InnerPartsOptions =
37
+ // CounterPartsMixinClass.DEFAULT_PARTS_OPTIONS;
38
+ this.parts = [];
39
+ this.oldParts = [];
40
+ this.partPreprocessDataList = [];
41
+ }
42
+ /**
43
+ * 这是 `usePartData` 的配置项. `usePartData` 被用于从数值的变化中生成用于滚动的数据.
44
+ * 这里不会有太多解释, 因为它是一个底层的配置项. 你可以查看 `CounterPartsMixinClass` 的源码了解更多信息.
45
+ */
46
+ get partsOptions() {
47
+ return __classPrivateFieldGet(this, _CounterPartsMixinClass___partsOptions, "f");
48
+ }
49
+ set partsOptions(value) {
50
+ const old = __classPrivateFieldGet(this, _CounterPartsMixinClass___partsOptions, "f");
51
+ __classPrivateFieldSet(this, _CounterPartsMixinClass___partsOptions, preprocessPartsOptions({
52
+ ..._a.DEFAULT_PARTS_OPTIONS,
53
+ ...value,
54
+ }), "f");
55
+ this.requestUpdate('partsOptions', old);
56
+ }
57
+ sampling(from, to) {
58
+ return transitionDigit(this.numberAdapter, this.numberAdapter.max(from, to), this.numberAdapter.min(from, to), this.partsOptions.sampleCount);
59
+ }
60
+ // eslint-disable-next-line class-methods-use-this
61
+ sampleSplit(samples) {
62
+ return [samples.slice()];
63
+ }
64
+ sampleToString(value) {
65
+ return this.numberAdapter.toString(value);
66
+ }
67
+ willUpdate(changedProperties) {
68
+ super.willUpdate(changedProperties);
69
+ if (changedProperties.has('value') ||
70
+ changedProperties.has('partsOptions')) {
71
+ this.oldParts = this.parts;
72
+ this.parts = this.processPartData();
73
+ this.partPreprocessDataList = preprocessPartData(this.direction, this.parts, this.oldDirection, this.oldParts);
74
+ }
75
+ /**
76
+ * `value` 没变但 `direction` 变化时, 也要重新生成 `partPreprocessDataList`.
77
+ */
78
+ // todo test events 和 animationOptions 冲突
79
+ // if (
80
+ // changedProperties.has('value') ||
81
+ // changedProperties.has('direction')
82
+ // ) {
83
+ // }
84
+ }
85
+ /**
86
+ * process:
87
+ * 1. 采样
88
+ * 2. 转换
89
+ * 3. 构造
90
+ */
91
+ processPartData() {
92
+ const { decimalSeparator, digitToChar, minPlaces, fillChar, type } = this.partsOptions;
93
+ const from = this.value;
94
+ const to = this.oldValue;
95
+ let _sampleToString = value => this.sampleToString(value).split(decimalSeparator);
96
+ if (type === 'string') {
97
+ _sampleToString = value => [this.sampleToString(value), ''];
98
+ }
99
+ const result = [];
100
+ /**
101
+ * 对 {@link from} 到 {@link to} 的范围采样.
102
+ */
103
+ const tempParts = this.sampleSplit(this.sampling(from, to));
104
+ /**
105
+ * 将时间部分的数字转换为用于滚动的字符串数组
106
+ *
107
+ * headNumber: 最先显示的数字. 向下滚动时, 为滚动列表的最后一个数字, 向上滚动时相反.
108
+ * tailNumber: 最后显示的数字. 向下滚动时, 为滚动列表的第一个数字, 向上滚动时相反.
109
+ */
110
+ {
111
+ const directionValue = this.numberAdapter.gt(from, to) ? 'down' : 'up';
112
+ for (let i = 0; i < tempParts.length; i++) {
113
+ const partData = tempParts[i];
114
+ // const headNumber =
115
+ // partData[directionValue === "down" ? partData.length - 1 : 0];
116
+ const tailNumber = partData[directionValue === 'down' ? 0 : partData.length - 1];
117
+ const [minIntegerPlaces = 1, minDecimalPlaces = 0] = minPlaces;
118
+ const numberParts = _sampleToString(tailNumber);
119
+ const integerPlaces = Math.max(
120
+ // numberParts[0].length,
121
+ this.stringAdapter.stringToChars(numberParts[0]).length, minIntegerPlaces);
122
+ const decimalPlaces = Math.max(
123
+ // numberParts[1]?.length ?? 0,
124
+ this.stringAdapter.stringToChars(numberParts[1] ?? '').length, minDecimalPlaces);
125
+ /**
126
+ * 使用 zip 将二维矩阵, 旋转90度
127
+ */
128
+ const data = zip(...partData
129
+ /**
130
+ * 保证位数一致, 向前补零
131
+ */
132
+ .map(digitData => {
133
+ const [integer = '', decimal = ''] = _sampleToString(digitData);
134
+ const integerChars = this.stringAdapter.stringToChars(integer);
135
+ const decimalChars = this.stringAdapter.stringToChars(decimal);
136
+ const filledIntegerPlaces = Math.max(integerPlaces - integerChars.length, 0);
137
+ const filledDecimalPlaces = Math.max(decimalPlaces - decimalChars.length, 0);
138
+ let filledChars = [].concat(new Array(filledIntegerPlaces).fill(fillChar), integerChars);
139
+ if (decimalPlaces > 0) {
140
+ filledChars = filledChars.concat([decimalSeparator], decimalChars, new Array(filledDecimalPlaces).fill(fillChar));
141
+ }
142
+ return filledChars;
143
+ }))
144
+ /**
145
+ * 删除连续的重复项
146
+ */
147
+ .map((digitList, index, array) => ({
148
+ data: digitList
149
+ .filter((digit, digitIndex, digitArray) => digitIndex === 0 || digit !== digitArray[digitIndex - 1])
150
+ .map(digit => digitToChar[digit] ?? digit),
151
+ place: array.length - index,
152
+ }));
153
+ result.push({
154
+ digits: data,
155
+ });
156
+ }
157
+ }
158
+ return result;
159
+ }
160
+ }
161
+ _a = CounterPartsMixinClass, _CounterPartsMixinClass___partsOptions = new WeakMap();
162
+ CounterPartsMixinClass.DEFAULT_PARTS_OPTIONS = {
163
+ sampleCount: 16,
164
+ decimalSeparator: '.',
165
+ fillChar: '0',
166
+ minPlaces: [1, 0],
167
+ digitToChar: {},
168
+ type: 'number',
169
+ };
170
+ __decorate([
171
+ property({
172
+ type: Object,
173
+ attribute: 'parts-options',
174
+ converter: value => parseJsonString(value ?? '') ?? {},
175
+ noAccessor: true,
176
+ })
177
+ ], CounterPartsMixinClass.prototype, "partsOptions", null);
178
+ return CounterPartsMixinClass;
179
+ };
180
+ //# sourceMappingURL=counter-parts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counter-parts.js","sourceRoot":"","sources":["../../../src/mixins/counter-parts.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAEL,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAoDhE,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAqB;IACnD,MAAM,WAAW,GAA2B,EAAE,CAAC;IAE/C,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC1C,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC3D,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,GAAG,OAAO;QACV,WAAW;KACZ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,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;;;IA3Mc,4CAAqB,GAAsB;QACxD,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,GAAG;QACrB,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACjB,WAAW,EAAE,EAAE;QACf,IAAI,EAAE,QAAQ;KACf,AAPmC,CAOlC;IAgBF;QANC,QAAQ,CAAC;YACR,IAAI,EAAE,MAAM;YACZ,SAAS,EAAE,eAAe;YAC1B,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE;YACtD,UAAU,EAAE,IAAI;SACjB,CAAC;8DAGD;IAqLH,OAAO,sBACJ,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { PropertyValues } from 'lit';\nimport { zip } from 'd3-array';\nimport { Constructor } from 'type-fest';\nimport { property } from 'lit/decorators.js';\nimport { isArray, isObjectType } from 'remeda';\nimport { CounterBaseMixin } from './counter-base.js';\nimport { PartData } from '../types/group.js';\nimport { transitionDigit } from '../utils/transition-digit.js';\nimport {\n PartPreprocessedData,\n preprocessPartData,\n} from '../utils/preprocess-part-data.js';\nimport { AvailableNumberAdapterValueType } from '../number-adapter/index.js';\nimport { parseJsonString } from '../utils/parse-json-string.js';\n\nexport interface PartsOptions {\n sampleCount: number;\n /**\n * 可以通过该属性将数字转换为你想要的任意字符串.\n */\n digitToChar: Record<string | number, string> | string[];\n /**\n * 小数点分隔符.\n */\n decimalSeparator: string;\n /**\n * 当**位数不足**时, 强制补全的 [整数, 小数] 位数. 为空时位数自适应.\n */\n minPlaces: [number | undefined, number | undefined];\n fillChar: string;\n /**\n * 数据类型.\n *\n * 1. `'string'`: 字符串类型.\n * 1. 不会使用 `decimalSeparator` 截取小数部分.\n * 2. `'number'`: 数字类型.\n *\n * @default `'number'`\n */\n type: 'string' | 'number';\n}\ntype InnerPartsOptions = Omit<PartsOptions, 'digitToChar'> & {\n digitToChar: Record<string | number, string>;\n};\n\nexport declare class CounterPartsMixinInterface<\n V extends AvailableNumberAdapterValueType,\n> {\n parts: PartData[];\n\n oldParts: PartData[];\n\n partPreprocessDataList: PartPreprocessedData[][];\n\n get partsOptions(): Partial<PartsOptions>;\n\n set partsOptions(value: Partial<PartsOptions>);\n\n sampling(from: V, to: V): V[];\n\n sampleSplit(samples: V[]): V[][];\n\n sampleToString(value: V): string;\n}\n\nfunction toChar(value: number) {\n return String.fromCodePoint(value + 48);\n}\n\nfunction preprocessPartsOptions(options: PartsOptions): InnerPartsOptions {\n const digitToChar: Record<string, string> = {};\n\n if (isArray(options.digitToChar)) {\n options.digitToChar.forEach((char, index) => {\n digitToChar[toChar(index)] = char;\n });\n } else if (isObjectType(options.digitToChar)) {\n Object.entries(options.digitToChar).forEach(([key, value]) => {\n digitToChar[key] = value;\n });\n }\n\n return {\n ...options,\n digitToChar,\n };\n}\n\nexport const CounterPartsMixin = <\n V extends AvailableNumberAdapterValueType,\n T extends ReturnType<typeof CounterBaseMixin<V>> = ReturnType<\n typeof CounterBaseMixin<V>\n >,\n>(\n superClass: T,\n) => {\n class CounterPartsMixinClass extends superClass {\n private static DEFAULT_PARTS_OPTIONS: InnerPartsOptions = {\n sampleCount: 16,\n decimalSeparator: '.',\n fillChar: '0',\n minPlaces: [1, 0],\n digitToChar: {},\n type: 'number',\n };\n\n #__partsOptions: InnerPartsOptions = {\n ...CounterPartsMixinClass.DEFAULT_PARTS_OPTIONS,\n };\n\n /**\n * 这是 `usePartData` 的配置项. `usePartData` 被用于从数值的变化中生成用于滚动的数据.\n * 这里不会有太多解释, 因为它是一个底层的配置项. 你可以查看 `CounterPartsMixinClass` 的源码了解更多信息.\n */\n @property({\n type: Object,\n attribute: 'parts-options',\n converter: value => parseJsonString(value ?? '') ?? {},\n noAccessor: true,\n })\n get partsOptions(): InnerPartsOptions {\n return this.#__partsOptions;\n }\n\n set partsOptions(value: Partial<PartsOptions>) {\n const old = this.#__partsOptions;\n this.#__partsOptions = preprocessPartsOptions({\n ...CounterPartsMixinClass.DEFAULT_PARTS_OPTIONS,\n ...value,\n });\n this.requestUpdate('partsOptions', old);\n }\n // partsOptions: InnerPartsOptions =\n // CounterPartsMixinClass.DEFAULT_PARTS_OPTIONS;\n\n parts: PartData[] = [];\n\n oldParts: PartData[] = [];\n\n partPreprocessDataList: PartPreprocessedData[][] = [];\n\n sampling(from: V, to: V) {\n return transitionDigit(\n this.numberAdapter,\n this.numberAdapter.max(from, to),\n this.numberAdapter.min(from, to),\n this.partsOptions.sampleCount,\n );\n }\n\n // eslint-disable-next-line class-methods-use-this\n sampleSplit(samples: V[]) {\n return [samples.slice()];\n }\n\n sampleToString(value: V) {\n return this.numberAdapter.toString(value);\n }\n\n override willUpdate(changedProperties: PropertyValues<this>) {\n super.willUpdate(changedProperties);\n\n if (\n changedProperties.has('value') ||\n changedProperties.has('partsOptions')\n ) {\n this.oldParts = this.parts;\n this.parts = this.processPartData();\n this.partPreprocessDataList = preprocessPartData(\n this.direction,\n this.parts,\n this.oldDirection,\n this.oldParts,\n );\n }\n\n /**\n * `value` 没变但 `direction` 变化时, 也要重新生成 `partPreprocessDataList`.\n */\n // todo test events 和 animationOptions 冲突\n // if (\n // changedProperties.has('value') ||\n // changedProperties.has('direction')\n // ) {\n // }\n }\n\n /**\n * process:\n * 1. 采样\n * 2. 转换\n * 3. 构造\n */\n private processPartData() {\n const { decimalSeparator, digitToChar, minPlaces, fillChar, type } =\n this.partsOptions;\n\n const from = this.value;\n const to = this.oldValue;\n\n let _sampleToString: (value: V) => string[] = value =>\n this.sampleToString(value).split(decimalSeparator);\n if (type === 'string') {\n _sampleToString = value => [this.sampleToString(value), ''];\n }\n\n const result: PartData[] = [];\n\n /**\n * 对 {@link from} 到 {@link to} 的范围采样.\n */\n const tempParts = this.sampleSplit(this.sampling(from, to));\n\n /**\n * 将时间部分的数字转换为用于滚动的字符串数组\n *\n * headNumber: 最先显示的数字. 向下滚动时, 为滚动列表的最后一个数字, 向上滚动时相反.\n * tailNumber: 最后显示的数字. 向下滚动时, 为滚动列表的第一个数字, 向上滚动时相反.\n */\n {\n const directionValue = this.numberAdapter.gt(from, to) ? 'down' : 'up';\n for (let i = 0; i < tempParts.length; i++) {\n const partData = tempParts[i];\n // const headNumber =\n // partData[directionValue === \"down\" ? partData.length - 1 : 0];\n const tailNumber =\n partData[directionValue === 'down' ? 0 : partData.length - 1];\n\n const [minIntegerPlaces = 1, minDecimalPlaces = 0] = minPlaces;\n\n const numberParts = _sampleToString(tailNumber);\n const integerPlaces = Math.max(\n // numberParts[0].length,\n this.stringAdapter.stringToChars(numberParts[0]).length,\n minIntegerPlaces,\n );\n const decimalPlaces = Math.max(\n // numberParts[1]?.length ?? 0,\n this.stringAdapter.stringToChars(numberParts[1] ?? '').length,\n minDecimalPlaces,\n );\n\n /**\n * 使用 zip 将二维矩阵, 旋转90度\n */\n const data = zip(\n ...partData\n /**\n * 保证位数一致, 向前补零\n */\n .map(digitData => {\n const [integer = '', decimal = ''] = _sampleToString(digitData);\n\n const integerChars = this.stringAdapter.stringToChars(integer);\n const decimalChars = this.stringAdapter.stringToChars(decimal);\n\n const filledIntegerPlaces = Math.max(\n integerPlaces - integerChars.length,\n 0,\n );\n\n const filledDecimalPlaces = Math.max(\n decimalPlaces - decimalChars.length,\n 0,\n );\n\n let filledChars = ([] as string[]).concat(\n new Array(filledIntegerPlaces).fill(fillChar),\n integerChars,\n );\n if (decimalPlaces > 0) {\n filledChars = filledChars.concat(\n [decimalSeparator],\n decimalChars,\n new Array(filledDecimalPlaces).fill(fillChar),\n );\n }\n return filledChars;\n }),\n )\n /**\n * 删除连续的重复项\n */\n .map((digitList, index, array) => ({\n data: digitList\n .filter(\n (digit, digitIndex, digitArray) =>\n digitIndex === 0 || digit !== digitArray[digitIndex - 1],\n )\n .map(digit => digitToChar[digit] ?? digit),\n place: array.length - index,\n }));\n\n result.push({\n digits: data,\n });\n }\n }\n\n return result;\n }\n }\n\n return CounterPartsMixinClass as Constructor<CounterPartsMixinInterface<V>> &\n T;\n};\n"]}
@@ -0,0 +1,17 @@
1
+ import { Constructor } from 'type-fest';
2
+ import { PartDigitCellGetter, PartDigitCellValue, PartDigitGetter, PartDigitValue, PartGetter, PartValue } from '../types/group.js';
3
+ import { CounterPartsMixin } from './counter-parts.js';
4
+ import { AvailableNumberAdapterValueType } from '../number-adapter/index.js';
5
+ export declare class CounterStylesMixinInterface {
6
+ cellStyles: PartDigitCellValue<Partial<CSSStyleDeclaration>>;
7
+ cellStylesDynamic?: PartDigitCellGetter<Partial<CSSStyleDeclaration>>;
8
+ extractCellStyles(): Partial<CSSStyleDeclaration>[][][];
9
+ digitStyles: PartDigitValue<Partial<CSSStyleDeclaration>>;
10
+ digitStylesDynamic?: PartDigitGetter<Partial<CSSStyleDeclaration>>;
11
+ extractDigitStyles(): Partial<CSSStyleDeclaration>[][];
12
+ partStyles: PartValue<Partial<CSSStyleDeclaration>>;
13
+ partStylesDynamic?: PartGetter<Partial<CSSStyleDeclaration>>;
14
+ extractPartStyles(): Partial<CSSStyleDeclaration>[];
15
+ color: string;
16
+ }
17
+ export declare const CounterStylesMixin: <V extends AvailableNumberAdapterValueType, T extends ReturnType<typeof CounterPartsMixin<V>> = Constructor<import("./counter-parts.js").CounterPartsMixinInterface<V>> & Constructor<import("./counter-base.js").CounterBaseMixinInterface<V>> & Constructor<import("lit").LitElement>>(superClass: T) => Constructor<CounterStylesMixinInterface> & T;
@@ -0,0 +1,93 @@
1
+ import { __decorate } from "tslib";
2
+ import { property } from 'lit/decorators.js';
3
+ import { isDeepEqual } from 'remeda';
4
+ import { extractPartDigitCellOption, extractPartDigitOption, extractPartOption, mergePartDigitCellOption, mergePartDigitOption, mergePartOption, } from '../utils/extract-group-option.js';
5
+ export const CounterStylesMixin = (superClass) => {
6
+ class CounterStylesMixinClass extends superClass {
7
+ constructor() {
8
+ super(...arguments);
9
+ /**
10
+ * 对 `cell` 部分的样式进行设置. 传入的对象将被直接应用到 `cell` 的 `style` 上.
11
+ * 你还可以使用 `cellStylesDynamic` 来动态设置样式.
12
+ */
13
+ this.cellStyles = {};
14
+ this.cachedCellStyles = [];
15
+ /**
16
+ * 与 `cell` 类似, 但是是对 `digit` 部分的样式进行设置.
17
+ * 你还可以使用 `digitStylesDynamic` 来动态设置样式.
18
+ */
19
+ this.digitStyles = {};
20
+ this.cachedDigitStyles = [];
21
+ /**
22
+ * 与 `cell` 类似, 但是是对 `part` 部分的样式进行设置.
23
+ * 你还可以使用 `partStylesDynamic` 来动态设置样式.
24
+ */
25
+ this.partStyles = {};
26
+ this.cachedPartStyles = [];
27
+ /**
28
+ * 文本颜色, 可使用 CSS 属性 `color` 和 `background-image` 的值.
29
+ *
30
+ * @default 继承自父元素.
31
+ *
32
+ * @example "red" 红色
33
+ * @example "transparent" 透明
34
+ * @example "linear-gradient(90deg, red, blue)" 红蓝渐变
35
+ * @example "url('https://example.com/image.png')" 图片背景
36
+ */
37
+ this.color = 'inherit';
38
+ }
39
+ extractCellStyles() {
40
+ const getterOptions = {
41
+ preprocessData: this.partPreprocessDataList,
42
+ data: this.parts,
43
+ direction: this.direction,
44
+ value: [this.value, this.oldValue],
45
+ };
46
+ const result = mergePartDigitCellOption(extractPartDigitCellOption(this.cellStyles ?? {}, getterOptions), extractPartDigitCellOption(this.cellStylesDynamic ?? {}, getterOptions));
47
+ if (!isDeepEqual(this.cachedCellStyles, result)) {
48
+ this.cachedCellStyles = result;
49
+ }
50
+ return this.cachedCellStyles;
51
+ }
52
+ extractDigitStyles() {
53
+ const getterOptions = {
54
+ preprocessData: this.partPreprocessDataList,
55
+ data: this.parts,
56
+ direction: this.direction,
57
+ value: [this.value, this.oldValue],
58
+ };
59
+ const result = mergePartDigitOption(extractPartDigitOption(this.digitStyles ?? {}, getterOptions), extractPartDigitOption(this.digitStylesDynamic ?? {}, getterOptions));
60
+ if (!isDeepEqual(this.cachedDigitStyles, result)) {
61
+ this.cachedDigitStyles = result;
62
+ }
63
+ return this.cachedDigitStyles;
64
+ }
65
+ extractPartStyles() {
66
+ const getterOptions = {
67
+ preprocessData: this.partPreprocessDataList,
68
+ data: this.parts,
69
+ direction: this.direction,
70
+ value: [this.value, this.oldValue],
71
+ };
72
+ const result = mergePartOption(extractPartOption(this.partStyles ?? {}, getterOptions), extractPartOption(this.partStylesDynamic ?? {}, getterOptions));
73
+ if (!isDeepEqual(this.cachedPartStyles, result)) {
74
+ this.cachedPartStyles = result;
75
+ }
76
+ return this.cachedPartStyles;
77
+ }
78
+ }
79
+ __decorate([
80
+ property({ type: Object, attribute: 'cell-styles', reflect: true })
81
+ ], CounterStylesMixinClass.prototype, "cellStyles", void 0);
82
+ __decorate([
83
+ property({ type: Object, attribute: 'digit-styles', reflect: true })
84
+ ], CounterStylesMixinClass.prototype, "digitStyles", void 0);
85
+ __decorate([
86
+ property({ type: Object, attribute: 'part-styles', reflect: true })
87
+ ], CounterStylesMixinClass.prototype, "partStyles", void 0);
88
+ __decorate([
89
+ property({ type: String, reflect: true })
90
+ ], CounterStylesMixinClass.prototype, "color", void 0);
91
+ return CounterStylesMixinClass;
92
+ };
93
+ //# sourceMappingURL=counter-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counter-styles.js","sourceRoot":"","sources":["../../../src/mixins/counter-styles.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAUrC,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AA0B1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAMhC,UAAa,EACb,EAAE;IACF,MAAM,uBAAwB,SAAQ,UAAU;QAAhD;;YACE;;;eAGG;YAEH,eAAU,GAAqD,EAAE,CAAC;YAI1D,qBAAgB,GACtB,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AAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0DAChB;IAG5B,OAAO,uBACJ,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { Constructor } from 'type-fest';\nimport { property } from 'lit/decorators.js';\nimport { isDeepEqual } from 'remeda';\nimport {\n GroupGetterOptions,\n PartDigitCellGetter,\n PartDigitCellValue,\n PartDigitGetter,\n PartDigitValue,\n PartGetter,\n PartValue,\n} from '../types/group.js';\nimport {\n extractPartDigitCellOption,\n extractPartDigitOption,\n extractPartOption,\n mergePartDigitCellOption,\n mergePartDigitOption,\n mergePartOption,\n} from '../utils/extract-group-option.js';\nimport { CounterPartsMixin } from './counter-parts.js';\nimport { AvailableNumberAdapterValueType } from '../number-adapter/index.js';\n\nexport declare class CounterStylesMixinInterface {\n cellStyles: PartDigitCellValue<Partial<CSSStyleDeclaration>>;\n\n cellStylesDynamic?: PartDigitCellGetter<Partial<CSSStyleDeclaration>>;\n\n extractCellStyles(): Partial<CSSStyleDeclaration>[][][];\n\n digitStyles: PartDigitValue<Partial<CSSStyleDeclaration>>;\n\n digitStylesDynamic?: PartDigitGetter<Partial<CSSStyleDeclaration>>;\n\n extractDigitStyles(): Partial<CSSStyleDeclaration>[][];\n\n partStyles: PartValue<Partial<CSSStyleDeclaration>>;\n\n partStylesDynamic?: PartGetter<Partial<CSSStyleDeclaration>>;\n\n extractPartStyles(): Partial<CSSStyleDeclaration>[];\n\n color: string;\n}\n\nexport const CounterStylesMixin = <\n V extends AvailableNumberAdapterValueType,\n T extends ReturnType<typeof CounterPartsMixin<V>> = ReturnType<\n typeof CounterPartsMixin<V>\n >,\n>(\n superClass: T,\n) => {\n class CounterStylesMixinClass extends superClass {\n /**\n * 对 `cell` 部分的样式进行设置. 传入的对象将被直接应用到 `cell` 的 `style` 上.\n * 你还可以使用 `cellStylesDynamic` 来动态设置样式.\n */\n @property({ type: Object, attribute: 'cell-styles', reflect: true })\n cellStyles: PartDigitCellValue<Partial<CSSStyleDeclaration>> = {};\n\n cellStylesDynamic?: PartDigitCellGetter<Partial<CSSStyleDeclaration>>;\n\n private cachedCellStyles: Partial<CSSStyleDeclaration | undefined>[][][] =\n [];\n\n extractCellStyles() {\n const getterOptions: GroupGetterOptions = {\n preprocessData: this.partPreprocessDataList,\n data: this.parts,\n direction: this.direction,\n value: [this.value, this.oldValue],\n };\n const result = mergePartDigitCellOption(\n extractPartDigitCellOption(this.cellStyles ?? {}, getterOptions),\n extractPartDigitCellOption(this.cellStylesDynamic ?? {}, getterOptions),\n );\n\n if (!isDeepEqual(this.cachedCellStyles, result)) {\n this.cachedCellStyles = result;\n }\n\n return this.cachedCellStyles;\n }\n\n /**\n * 与 `cell` 类似, 但是是对 `digit` 部分的样式进行设置.\n * 你还可以使用 `digitStylesDynamic` 来动态设置样式.\n */\n @property({ type: Object, attribute: 'digit-styles', reflect: true })\n digitStyles: PartDigitValue<Partial<CSSStyleDeclaration>> = {};\n\n digitStylesDynamic?: PartDigitGetter<Partial<CSSStyleDeclaration>>;\n\n private cachedDigitStyles: Partial<CSSStyleDeclaration | undefined>[][] =\n [];\n\n extractDigitStyles() {\n const getterOptions: GroupGetterOptions = {\n preprocessData: this.partPreprocessDataList,\n data: this.parts,\n direction: this.direction,\n value: [this.value, this.oldValue],\n };\n const result = mergePartDigitOption(\n extractPartDigitOption(this.digitStyles ?? {}, getterOptions),\n extractPartDigitOption(this.digitStylesDynamic ?? {}, getterOptions),\n );\n\n if (!isDeepEqual(this.cachedDigitStyles, result)) {\n this.cachedDigitStyles = result;\n }\n\n return this.cachedDigitStyles;\n }\n\n /**\n * 与 `cell` 类似, 但是是对 `part` 部分的样式进行设置.\n * 你还可以使用 `partStylesDynamic` 来动态设置样式.\n */\n @property({ type: Object, attribute: 'part-styles', reflect: true })\n partStyles: PartValue<Partial<CSSStyleDeclaration>> = {};\n\n partStylesDynamic?: PartGetter<Partial<CSSStyleDeclaration>>;\n\n private cachedPartStyles: Partial<CSSStyleDeclaration | undefined>[] = [];\n\n extractPartStyles() {\n const getterOptions: GroupGetterOptions = {\n preprocessData: this.partPreprocessDataList,\n data: this.parts,\n direction: this.direction,\n value: [this.value, this.oldValue],\n };\n const result = mergePartOption(\n extractPartOption(this.partStyles ?? {}, getterOptions),\n extractPartOption(this.partStylesDynamic ?? {}, getterOptions),\n );\n\n if (!isDeepEqual(this.cachedPartStyles, result)) {\n this.cachedPartStyles = result;\n }\n\n return this.cachedPartStyles;\n }\n\n /**\n * 文本颜色, 可使用 CSS 属性 `color` 和 `background-image` 的值.\n *\n * @default 继承自父元素.\n *\n * @example \"red\" 红色\n * @example \"transparent\" 透明\n * @example \"linear-gradient(90deg, red, blue)\" 红蓝渐变\n * @example \"url('https://example.com/image.png')\" 图片背景\n */\n @property({ type: String, reflect: true })\n color: string = 'inherit';\n }\n\n return CounterStylesMixinClass as Constructor<CounterStylesMixinInterface> &\n T;\n};\n"]}
@@ -0,0 +1,6 @@
1
+ import { NumberAdapter } from "./types.js";
2
+ /**
3
+ * @deprecated
4
+ */
5
+ declare const BuildInBigintAdapter: () => NumberAdapter<bigint>;
6
+ export { BuildInBigintAdapter };