@lynx-js/web-elements 0.2.4

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 (204) hide show
  1. package/CHANGELOG.md +323 -0
  2. package/LICENSE.txt +202 -0
  3. package/Notice.txt +1 -0
  4. package/README.md +47 -0
  5. package/dist/LynxWrapper/LynxWrapper.d.ts +2 -0
  6. package/dist/LynxWrapper/LynxWrapper.js +27 -0
  7. package/dist/LynxWrapper/index.d.ts +1 -0
  8. package/dist/LynxWrapper/index.js +2 -0
  9. package/dist/ScrollView/FadeEdgeLengthAttribute.d.ts +10 -0
  10. package/dist/ScrollView/FadeEdgeLengthAttribute.js +43 -0
  11. package/dist/ScrollView/ScrollAttributes.d.ts +8 -0
  12. package/dist/ScrollView/ScrollAttributes.js +83 -0
  13. package/dist/ScrollView/ScrollIntoView.d.ts +9 -0
  14. package/dist/ScrollView/ScrollIntoView.js +71 -0
  15. package/dist/ScrollView/ScrollView.d.ts +31 -0
  16. package/dist/ScrollView/ScrollView.js +185 -0
  17. package/dist/ScrollView/ScrollViewEvents.d.ts +9 -0
  18. package/dist/ScrollView/ScrollViewEvents.js +146 -0
  19. package/dist/ScrollView/index.d.ts +1 -0
  20. package/dist/ScrollView/index.js +2 -0
  21. package/dist/XAudioTT/XAudioAttribute.d.ts +7 -0
  22. package/dist/XAudioTT/XAudioAttribute.js +93 -0
  23. package/dist/XAudioTT/XAudioEvents.d.ts +8 -0
  24. package/dist/XAudioTT/XAudioEvents.js +116 -0
  25. package/dist/XAudioTT/XAudioTT.d.ts +46 -0
  26. package/dist/XAudioTT/XAudioTT.js +183 -0
  27. package/dist/XAudioTT/index.d.ts +1 -0
  28. package/dist/XAudioTT/index.js +2 -0
  29. package/dist/XAudioTT/utils.d.ts +19 -0
  30. package/dist/XAudioTT/utils.js +66 -0
  31. package/dist/XCanvas/CanvasAttributes.d.ts +12 -0
  32. package/dist/XCanvas/CanvasAttributes.js +78 -0
  33. package/dist/XCanvas/XCanvas.d.ts +5 -0
  34. package/dist/XCanvas/XCanvas.js +32 -0
  35. package/dist/XCanvas/index.d.ts +1 -0
  36. package/dist/XCanvas/index.js +2 -0
  37. package/dist/XFoldViewNg/XFoldviewHeaderNg.d.ts +2 -0
  38. package/dist/XFoldViewNg/XFoldviewHeaderNg.js +32 -0
  39. package/dist/XFoldViewNg/XFoldviewHeaderNgFeatures.d.ts +9 -0
  40. package/dist/XFoldViewNg/XFoldviewHeaderNgFeatures.js +32 -0
  41. package/dist/XFoldViewNg/XFoldviewNg.d.ts +11 -0
  42. package/dist/XFoldViewNg/XFoldviewNg.js +52 -0
  43. package/dist/XFoldViewNg/XFoldviewNgEvents.d.ts +7 -0
  44. package/dist/XFoldViewNg/XFoldviewNgEvents.js +55 -0
  45. package/dist/XFoldViewNg/XFoldviewSlotDragNg.d.ts +2 -0
  46. package/dist/XFoldViewNg/XFoldviewSlotDragNg.js +30 -0
  47. package/dist/XFoldViewNg/XFoldviewSlotNg.d.ts +2 -0
  48. package/dist/XFoldViewNg/XFoldviewSlotNg.js +32 -0
  49. package/dist/XFoldViewNg/XFoldviewSlotNgTouchEventsHandler.d.ts +7 -0
  50. package/dist/XFoldViewNg/XFoldviewSlotNgTouchEventsHandler.js +105 -0
  51. package/dist/XFoldViewNg/XFoldviewToolbarNg.d.ts +2 -0
  52. package/dist/XFoldViewNg/XFoldviewToolbarNg.js +30 -0
  53. package/dist/XFoldViewNg/index.d.ts +5 -0
  54. package/dist/XFoldViewNg/index.js +6 -0
  55. package/dist/XImage/DropShadow.d.ts +6 -0
  56. package/dist/XImage/DropShadow.js +30 -0
  57. package/dist/XImage/FilterImage.d.ts +2 -0
  58. package/dist/XImage/FilterImage.js +31 -0
  59. package/dist/XImage/ImageEvents.d.ts +6 -0
  60. package/dist/XImage/ImageEvents.js +68 -0
  61. package/dist/XImage/ImageSrc.d.ts +7 -0
  62. package/dist/XImage/ImageSrc.js +61 -0
  63. package/dist/XImage/XImage.d.ts +2 -0
  64. package/dist/XImage/XImage.js +30 -0
  65. package/dist/XImage/index.d.ts +2 -0
  66. package/dist/XImage/index.js +3 -0
  67. package/dist/XInput/InputBaseAttributes.d.ts +9 -0
  68. package/dist/XInput/InputBaseAttributes.js +99 -0
  69. package/dist/XInput/Placeholder.d.ts +6 -0
  70. package/dist/XInput/Placeholder.js +60 -0
  71. package/dist/XInput/XInput.d.ts +28 -0
  72. package/dist/XInput/XInput.js +129 -0
  73. package/dist/XInput/XInputAttribute.d.ts +9 -0
  74. package/dist/XInput/XInputAttribute.js +52 -0
  75. package/dist/XInput/XInputEvents.d.ts +6 -0
  76. package/dist/XInput/XInputEvents.js +111 -0
  77. package/dist/XInput/index.d.ts +1 -0
  78. package/dist/XInput/index.js +2 -0
  79. package/dist/XList/ListItem.d.ts +2 -0
  80. package/dist/XList/ListItem.js +28 -0
  81. package/dist/XList/XList.d.ts +52 -0
  82. package/dist/XList/XList.js +257 -0
  83. package/dist/XList/XListAttributes.d.ts +8 -0
  84. package/dist/XList/XListAttributes.js +50 -0
  85. package/dist/XList/XListEvents.d.ts +7 -0
  86. package/dist/XList/XListEvents.js +356 -0
  87. package/dist/XList/index.d.ts +2 -0
  88. package/dist/XList/index.js +3 -0
  89. package/dist/XOverlayNg/XOverlayAttributes.d.ts +8 -0
  90. package/dist/XOverlayNg/XOverlayAttributes.js +80 -0
  91. package/dist/XOverlayNg/XOverlayNg.d.ts +2 -0
  92. package/dist/XOverlayNg/XOverlayNg.js +45 -0
  93. package/dist/XOverlayNg/index.d.ts +1 -0
  94. package/dist/XOverlayNg/index.js +2 -0
  95. package/dist/XRefreshView/XRefreshFooter.d.ts +3 -0
  96. package/dist/XRefreshView/XRefreshFooter.js +35 -0
  97. package/dist/XRefreshView/XRefreshHeader.d.ts +3 -0
  98. package/dist/XRefreshView/XRefreshHeader.js +35 -0
  99. package/dist/XRefreshView/XRefreshSubElementIntersectionObserver.d.ts +16 -0
  100. package/dist/XRefreshView/XRefreshSubElementIntersectionObserver.js +52 -0
  101. package/dist/XRefreshView/XRefreshView.d.ts +13 -0
  102. package/dist/XRefreshView/XRefreshView.js +125 -0
  103. package/dist/XRefreshView/XRefreshViewEventsEmitter.d.ts +8 -0
  104. package/dist/XRefreshView/XRefreshViewEventsEmitter.js +246 -0
  105. package/dist/XRefreshView/index.d.ts +3 -0
  106. package/dist/XRefreshView/index.js +4 -0
  107. package/dist/XSvg/XSvg.d.ts +8 -0
  108. package/dist/XSvg/XSvg.js +80 -0
  109. package/dist/XSvg/index.d.ts +1 -0
  110. package/dist/XSvg/index.js +2 -0
  111. package/dist/XSwiper/SwiperItem.d.ts +2 -0
  112. package/dist/XSwiper/SwiperItem.js +28 -0
  113. package/dist/XSwiper/XSwiper.d.ts +14 -0
  114. package/dist/XSwiper/XSwiper.js +231 -0
  115. package/dist/XSwiper/XSwiperAutoScroll.d.ts +8 -0
  116. package/dist/XSwiper/XSwiperAutoScroll.js +63 -0
  117. package/dist/XSwiper/XSwiperCircular.d.ts +8 -0
  118. package/dist/XSwiper/XSwiperCircular.js +191 -0
  119. package/dist/XSwiper/XSwiperEvents.d.ts +8 -0
  120. package/dist/XSwiper/XSwiperEvents.js +144 -0
  121. package/dist/XSwiper/XSwiperIndicator.d.ts +9 -0
  122. package/dist/XSwiper/XSwiperIndicator.js +118 -0
  123. package/dist/XSwiper/index.d.ts +2 -0
  124. package/dist/XSwiper/index.js +3 -0
  125. package/dist/XText/InlineImage.d.ts +11 -0
  126. package/dist/XText/InlineImage.js +56 -0
  127. package/dist/XText/InlineText.d.ts +5 -0
  128. package/dist/XText/InlineText.js +30 -0
  129. package/dist/XText/InlineTruncation.d.ts +5 -0
  130. package/dist/XText/InlineTruncation.js +42 -0
  131. package/dist/XText/RawText.d.ts +7 -0
  132. package/dist/XText/RawText.js +54 -0
  133. package/dist/XText/XText.d.ts +5 -0
  134. package/dist/XText/XText.js +49 -0
  135. package/dist/XText/XTextTruncation.d.ts +11 -0
  136. package/dist/XText/XTextTruncation.js +604 -0
  137. package/dist/XText/index.d.ts +5 -0
  138. package/dist/XText/index.js +6 -0
  139. package/dist/XTextarea/Placeholder.d.ts +7 -0
  140. package/dist/XTextarea/Placeholder.js +59 -0
  141. package/dist/XTextarea/TextareaBaseAttributes.d.ts +6 -0
  142. package/dist/XTextarea/TextareaBaseAttributes.js +70 -0
  143. package/dist/XTextarea/XTextarea.d.ts +21 -0
  144. package/dist/XTextarea/XTextarea.js +101 -0
  145. package/dist/XTextarea/XTextareaAttributes.d.ts +6 -0
  146. package/dist/XTextarea/XTextareaAttributes.js +81 -0
  147. package/dist/XTextarea/XTextareaEvents.d.ts +6 -0
  148. package/dist/XTextarea/XTextareaEvents.js +111 -0
  149. package/dist/XTextarea/index.d.ts +1 -0
  150. package/dist/XTextarea/index.js +2 -0
  151. package/dist/XView/BlurRadius.d.ts +7 -0
  152. package/dist/XView/BlurRadius.js +38 -0
  153. package/dist/XView/XBlurView.d.ts +2 -0
  154. package/dist/XView/XBlurView.js +29 -0
  155. package/dist/XView/XView.d.ts +4 -0
  156. package/dist/XView/XView.js +45 -0
  157. package/dist/XView/index.d.ts +2 -0
  158. package/dist/XView/index.js +3 -0
  159. package/dist/XViewpagerNg/XViewpagerItemNg.d.ts +2 -0
  160. package/dist/XViewpagerNg/XViewpagerItemNg.js +30 -0
  161. package/dist/XViewpagerNg/XViewpagerNg.d.ts +10 -0
  162. package/dist/XViewpagerNg/XViewpagerNg.js +98 -0
  163. package/dist/XViewpagerNg/XViewpagerNgEvents.d.ts +9 -0
  164. package/dist/XViewpagerNg/XViewpagerNgEvents.js +118 -0
  165. package/dist/XViewpagerNg/index.d.ts +2 -0
  166. package/dist/XViewpagerNg/index.js +3 -0
  167. package/dist/all.d.ts +16 -0
  168. package/dist/all.js +17 -0
  169. package/dist/common/Exposure.d.ts +28 -0
  170. package/dist/common/Exposure.js +193 -0
  171. package/dist/common/bindToIntersectionObserver.d.ts +1 -0
  172. package/dist/common/bindToIntersectionObserver.js +23 -0
  173. package/dist/common/commonEventInitConfiguration.d.ts +5 -0
  174. package/dist/common/commonEventInitConfiguration.js +9 -0
  175. package/dist/common/constants.d.ts +4 -0
  176. package/dist/common/constants.js +14 -0
  177. package/dist/common/convertLengthToPx.d.ts +1 -0
  178. package/dist/common/convertLengthToPx.js +25 -0
  179. package/dist/common/renameEvent.d.ts +1 -0
  180. package/dist/common/renameEvent.js +6 -0
  181. package/dist/common/throttle.d.ts +4 -0
  182. package/dist/common/throttle.js +40 -0
  183. package/dist/index.d.ts +4 -0
  184. package/dist/index.js +8 -0
  185. package/dist/lazy.d.ts +1 -0
  186. package/dist/lazy.js +106 -0
  187. package/index.css +19 -0
  188. package/package.json +110 -0
  189. package/src/LynxWrapper/lynx-wrapper.css +12 -0
  190. package/src/ScrollView/scroll-view.css +121 -0
  191. package/src/XAudioTT/x-audio-tt.css +3 -0
  192. package/src/XCanvas/x-canvas.css +16 -0
  193. package/src/XFoldViewNg/x-foldview-ng.css +80 -0
  194. package/src/XImage/x-image.css +82 -0
  195. package/src/XInput/x-input.css +48 -0
  196. package/src/XList/x-list.css +147 -0
  197. package/src/XOverlayNg/x-overlay-ng.css +56 -0
  198. package/src/XRefreshView/x-refresh-view.css +61 -0
  199. package/src/XSvg/x-svg.css +10 -0
  200. package/src/XSwiper/x-swiper.css +319 -0
  201. package/src/XText/x-text.css +272 -0
  202. package/src/XTextarea/x-textarea.css +49 -0
  203. package/src/XViewpagerNg/x-viewpager-ng.css +68 -0
  204. package/src/common-css/linear.css +386 -0
@@ -0,0 +1,604 @@
1
+ import { __esDecorate, __runInitializers, __setFunctionName } from "tslib";
2
+ /*
3
+ // Copyright 2024 The Lynx Authors. All rights reserved.
4
+ // Licensed under the Apache License Version 2.0 that can be found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { boostedQueueMicrotask, genDomGetter, registerAttributeHandler, } from '@lynx-js/web-elements-reactive';
8
+ import { commonComponentEventSetting } from '../common/commonEventInitConfiguration.js';
9
+ let XTextTruncation = (() => {
10
+ var _a;
11
+ let _instanceExtraInitializers = [];
12
+ let _private_handleAttributeChange_decorators;
13
+ let _private_handleAttributeChange_descriptor;
14
+ let _private_handleEnableLayoutEvent_decorators;
15
+ let _private_handleEnableLayoutEvent_descriptor;
16
+ return class XTextTruncation {
17
+ static {
18
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
19
+ _private_handleAttributeChange_decorators = [registerAttributeHandler('text-maxlength', true), registerAttributeHandler('text-maxline', true), registerAttributeHandler('tail-color-convert', true)];
20
+ _private_handleEnableLayoutEvent_decorators = [registerAttributeHandler('x-enable-layout-event', true)];
21
+ __esDecorate(this, _private_handleAttributeChange_descriptor = { value: __setFunctionName(function () {
22
+ this.#maxLength = parseFloat(this.#dom.getAttribute('text-maxlength') ?? '');
23
+ this.#maxLine = parseFloat(this.#dom.getAttribute('text-maxline') ?? '');
24
+ this.#tailColorConvert =
25
+ this.#dom.getAttribute('tail-color-convert') !== 'false';
26
+ if (this.#maxLength < 0)
27
+ this.#maxLength = NaN;
28
+ if (this.#maxLine < 1)
29
+ this.#maxLine = NaN;
30
+ if (!isNaN(this.#maxLine)) {
31
+ this.#getInnerBox().style.webkitLineClamp = this.#maxLine.toString();
32
+ }
33
+ else {
34
+ this.#getInnerBox().style.removeProperty('-webkit-line-clamp');
35
+ }
36
+ this.#layoutText();
37
+ }, "#handleAttributeChange") }, _private_handleAttributeChange_decorators, { kind: "method", name: "#handleAttributeChange", static: false, private: true, access: { has: obj => #handleAttributeChange in obj, get: obj => obj.#handleAttributeChange }, metadata: _metadata }, null, _instanceExtraInitializers);
38
+ __esDecorate(this, _private_handleEnableLayoutEvent_descriptor = { value: __setFunctionName(function (newVal) {
39
+ this.#enableLayoutEvent = newVal !== null;
40
+ }, "#handleEnableLayoutEvent") }, _private_handleEnableLayoutEvent_decorators, { kind: "method", name: "#handleEnableLayoutEvent", static: false, private: true, access: { has: obj => #handleEnableLayoutEvent in obj, get: obj => obj.#handleEnableLayoutEvent }, metadata: _metadata }, null, _instanceExtraInitializers);
41
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
42
+ }
43
+ static exceedMathLengthAttribute = 'x-text-clipped';
44
+ static showInlineTruncation = 'x-show-inline-truncation';
45
+ static observedAttributes = [
46
+ 'text-maxlength',
47
+ 'text-maxline',
48
+ 'tail-color-convert',
49
+ 'x-enable-layout-event',
50
+ ];
51
+ #scheduledTextLayout = (__runInitializers(this, _instanceExtraInitializers), false);
52
+ #componentConnected = false;
53
+ #originalTextMap = new Map();
54
+ #mutationObserver;
55
+ #resizeObserver;
56
+ #inplaceEllipsisNode;
57
+ #textMeasure;
58
+ #firstResizeObserverCallback = false;
59
+ // attribute status
60
+ #maxLength = NaN;
61
+ #maxLine = NaN;
62
+ #tailColorConvert = true;
63
+ #enableLayoutEvent = false;
64
+ get #ellipsisInPlace() {
65
+ return !this.#hasInlineTruncation && !this.#tailColorConvert;
66
+ }
67
+ get #hasInlineTruncation() {
68
+ if (CSS.supports('selector(:has(inline-truncation))')) {
69
+ return this.#dom.matches(':has(inline-truncation)');
70
+ }
71
+ else {
72
+ const candidateElement = this.#dom.querySelector('inline-truncation');
73
+ if (candidateElement?.parentElement === this.#dom) {
74
+ return true;
75
+ }
76
+ }
77
+ return false;
78
+ }
79
+ get #doExpensiveLineLayoutCalculation() {
80
+ return (!isNaN(this.#maxLine)
81
+ && (this.#hasInlineTruncation || !this.#tailColorConvert));
82
+ }
83
+ #dom;
84
+ constructor(dom) {
85
+ this.#dom = dom;
86
+ }
87
+ #getInnerBox = genDomGetter(() => this.#dom.shadowRoot, '#inner-box');
88
+ #updateOriginalText(mutationRecords) {
89
+ mutationRecords.forEach((oneRecord) => {
90
+ oneRecord.removedNodes.forEach((node) => {
91
+ this.#originalTextMap.delete(node);
92
+ });
93
+ if (oneRecord.type === 'characterData'
94
+ && this.#originalTextMap.get(oneRecord.target) !== undefined) {
95
+ this.#originalTextMap.set(oneRecord.target, oneRecord.target.data);
96
+ }
97
+ });
98
+ }
99
+ #revertTruncatedTextNodes() {
100
+ for (const [node, originalText] of this.#originalTextMap) {
101
+ if (node.nodeType === Node.TEXT_NODE) {
102
+ if (originalText !== undefined) {
103
+ node.data = originalText;
104
+ }
105
+ }
106
+ else {
107
+ node.removeAttribute(XTextTruncation.exceedMathLengthAttribute);
108
+ }
109
+ }
110
+ this.#dom.removeAttribute(XTextTruncation.exceedMathLengthAttribute);
111
+ this.#dom.removeAttribute(XTextTruncation.showInlineTruncation);
112
+ }
113
+ #getAllSibilings(targetNode) {
114
+ const sibilingNodes = [];
115
+ let targetNodeSibiling = targetNode;
116
+ while ((targetNodeSibiling = targetNodeSibiling.nextSibling)) {
117
+ if (targetNodeSibiling.nodeType === Node.TEXT_NODE
118
+ || targetNodeSibiling.nodeType === Node.ELEMENT_NODE) {
119
+ sibilingNodes.push(targetNodeSibiling);
120
+ }
121
+ }
122
+ return sibilingNodes;
123
+ }
124
+ #layoutText() {
125
+ if (!this.#componentConnected || this.#dom.matches('x-text>x-text'))
126
+ return;
127
+ if (this.#scheduledTextLayout)
128
+ return;
129
+ this.#scheduledTextLayout = true;
130
+ boostedQueueMicrotask(() => {
131
+ this.#layoutTextInner();
132
+ this.#startObservers();
133
+ queueMicrotask(() => {
134
+ this.#scheduledTextLayout = false;
135
+ });
136
+ });
137
+ }
138
+ #layoutTextInner() {
139
+ this.#inplaceEllipsisNode?.parentElement?.removeChild(this.#inplaceEllipsisNode);
140
+ this.#revertTruncatedTextNodes();
141
+ if (!this.#doExpensiveLineLayoutCalculation && isNaN(this.#maxLength)) {
142
+ return;
143
+ }
144
+ const parentBondingRect = this.#getInnerBox().getBoundingClientRect();
145
+ this.#textMeasure = new TextRenderingMeasureTool(this.#dom, parentBondingRect);
146
+ const measure = this.#textMeasure;
147
+ const maxLengthMeasureResult = !isNaN(this.#maxLength)
148
+ ? measure.getNodeInfoByCharIndex(this.#maxLength)
149
+ : undefined;
150
+ const maxLengthEndAt = maxLengthMeasureResult ? this.#maxLength : Infinity;
151
+ const maxLineMeasureResult = this.#doExpensiveLineLayoutCalculation
152
+ ? measure.getLineInfo(this.#maxLine)
153
+ ? measure.getLineInfo(this.#maxLine - 1)
154
+ : undefined
155
+ : undefined;
156
+ let maxLineEndAt = Infinity;
157
+ let ellipsisLength = 3;
158
+ if (maxLineMeasureResult) {
159
+ const { start, end } = maxLineMeasureResult;
160
+ const currentLineText = end - start;
161
+ if (this.#hasInlineTruncation) {
162
+ this.#dom.setAttribute(XTextTruncation.showInlineTruncation, '');
163
+ const inlineTruncation = this.#dom.querySelector('inline-truncation');
164
+ const inlineTruncationBoundingRect = inlineTruncation
165
+ .getBoundingClientRect();
166
+ const parentWidth = parentBondingRect.width;
167
+ const inlineTruncationWidth = inlineTruncationBoundingRect.width;
168
+ if (parentWidth > inlineTruncationWidth) {
169
+ maxLineEndAt = end - 1;
170
+ const range = document.createRange();
171
+ let currentNodeInfo = measure
172
+ .getNodeInfoByCharIndex(maxLineEndAt);
173
+ const endCharInNodeIndex = end - currentNodeInfo.start;
174
+ range.setEnd(currentNodeInfo.node, endCharInNodeIndex);
175
+ range.setStart(currentNodeInfo.node, endCharInNodeIndex);
176
+ while (range.getBoundingClientRect().width < inlineTruncationWidth
177
+ && (maxLineEndAt -= 1)
178
+ && (currentNodeInfo = measure.getNodeInfoByCharIndex(maxLineEndAt))) {
179
+ range.setStart(currentNodeInfo.node, maxLineEndAt - currentNodeInfo.start);
180
+ }
181
+ }
182
+ else {
183
+ maxLineEndAt = start;
184
+ this.#dom.removeAttribute(XTextTruncation.showInlineTruncation);
185
+ }
186
+ }
187
+ else {
188
+ if (currentLineText < 3) {
189
+ ellipsisLength = currentLineText;
190
+ maxLineEndAt = start;
191
+ }
192
+ else {
193
+ maxLineEndAt = end - 3;
194
+ }
195
+ }
196
+ }
197
+ const truncateAt = Math.min(maxLengthEndAt, maxLineEndAt);
198
+ if (truncateAt < Infinity) {
199
+ const targetNodeInfo = measure.getNodeInfoByCharIndex(truncateAt);
200
+ if (targetNodeInfo) {
201
+ const truncatePositionInNode = truncateAt - targetNodeInfo.start;
202
+ const targetNode = targetNodeInfo.node;
203
+ let toBeHideNodes = [];
204
+ if (targetNode.nodeType === Node.TEXT_NODE) {
205
+ const textNode = targetNode;
206
+ this.#originalTextMap.set(targetNode, textNode.data);
207
+ textNode.data = textNode.data.substring(0, truncatePositionInNode);
208
+ }
209
+ else {
210
+ toBeHideNodes.push(targetNode);
211
+ }
212
+ toBeHideNodes = toBeHideNodes.concat(this.#getAllSibilings(targetNode));
213
+ let targetNodeParentElement = targetNode.parentElement;
214
+ while (targetNodeParentElement !== this.#dom) {
215
+ toBeHideNodes = toBeHideNodes.concat(this.#getAllSibilings(targetNodeParentElement));
216
+ targetNodeParentElement = targetNodeParentElement.parentElement;
217
+ }
218
+ toBeHideNodes.forEach((node) => {
219
+ if (node.nodeType === Node.TEXT_NODE
220
+ && node.data.length !== 0) {
221
+ this.#originalTextMap.set(node, node.data);
222
+ node.data = '';
223
+ }
224
+ else if (node.nodeType === Node.ELEMENT_NODE) {
225
+ this.#originalTextMap.set(node, '');
226
+ node.setAttribute(XTextTruncation.exceedMathLengthAttribute, '');
227
+ }
228
+ });
229
+ if (this.#ellipsisInPlace) {
230
+ const closestParent = (truncatePositionInNode === 0
231
+ ? measure.nodelist.at(targetNodeInfo.nodeIndex - 1)
232
+ ?.parentElement
233
+ : targetNode.parentElement) ?? targetNode.parentElement;
234
+ this.#inplaceEllipsisNode = new Text(new Array(ellipsisLength).fill('.').join(''));
235
+ closestParent.append(this.#inplaceEllipsisNode);
236
+ }
237
+ this.#dom.setAttribute(XTextTruncation.exceedMathLengthAttribute, '');
238
+ }
239
+ this.#sendLayoutEvent(truncateAt);
240
+ }
241
+ }
242
+ #handleMutationObserver = (records) => {
243
+ this.#updateOriginalText(records);
244
+ this.#layoutText();
245
+ };
246
+ #handleRezieObserver = () => {
247
+ if (this.#firstResizeObserverCallback) {
248
+ this.#firstResizeObserverCallback = false;
249
+ return;
250
+ }
251
+ this.#layoutText();
252
+ };
253
+ #startObservers() {
254
+ if (!this.#componentConnected) {
255
+ return;
256
+ }
257
+ if (this.#maxLength || this.#maxLine) {
258
+ if (!this.#mutationObserver) {
259
+ this.#mutationObserver = new MutationObserver(this.#handleMutationObserver);
260
+ this.#mutationObserver.observe(this.#dom, {
261
+ subtree: true,
262
+ childList: true,
263
+ attributes: false,
264
+ characterData: true,
265
+ });
266
+ }
267
+ }
268
+ if (this.#maxLine) {
269
+ if (!this.#resizeObserver) {
270
+ this.#resizeObserver = new ResizeObserver(this.#handleRezieObserver);
271
+ this.#firstResizeObserverCallback = true;
272
+ this.#resizeObserver.observe(this.#getInnerBox(), {
273
+ box: 'content-box',
274
+ });
275
+ }
276
+ }
277
+ }
278
+ #stopObservers() {
279
+ this.#mutationObserver?.disconnect();
280
+ this.#mutationObserver = undefined;
281
+ this.#resizeObserver?.disconnect();
282
+ this.#resizeObserver = undefined;
283
+ }
284
+ get #handleAttributeChange() { return _private_handleAttributeChange_descriptor.value; }
285
+ get #handleEnableLayoutEvent() { return _private_handleEnableLayoutEvent_descriptor.value; }
286
+ #sendLayoutEvent(truncateAt) {
287
+ if (!this.#enableLayoutEvent)
288
+ return;
289
+ const detail = new Proxy(this, {
290
+ get(that, property) {
291
+ if (property === 'lineCount') {
292
+ if (!that.#textMeasure) {
293
+ that.#textMeasure = new TextRenderingMeasureTool(that.#dom, that.#dom.getBoundingClientRect());
294
+ }
295
+ return that.#textMeasure.getLineCount();
296
+ }
297
+ else if (property === 'lines') {
298
+ // event.detail.lines
299
+ return new Proxy(that, {
300
+ get(that, lineIndex) {
301
+ // event.detail.lines[num]
302
+ const lineIndexNum = parseFloat(lineIndex.toString());
303
+ if (!isNaN(lineIndexNum)) {
304
+ if (!that.#textMeasure) {
305
+ that.#textMeasure = new TextRenderingMeasureTool(that.#dom, that.#dom.getBoundingClientRect());
306
+ }
307
+ const lineInfo = that.#textMeasure.getLineInfo(lineIndexNum);
308
+ if (lineInfo) {
309
+ return new Proxy(lineInfo, {
310
+ get(lineInfo, property) {
311
+ // event.detail.lines[num].(<start>, <end>, <ellipsisCount>)
312
+ switch (property) {
313
+ case 'start':
314
+ case 'end':
315
+ return lineInfo[property];
316
+ case 'ellipsisCount':
317
+ if (truncateAt !== undefined
318
+ && truncateAt >= lineInfo.start
319
+ && truncateAt < lineInfo.end) {
320
+ return lineInfo.end - truncateAt;
321
+ }
322
+ return 0;
323
+ }
324
+ },
325
+ });
326
+ }
327
+ }
328
+ },
329
+ });
330
+ }
331
+ },
332
+ });
333
+ this.#dom.dispatchEvent(new CustomEvent('layout', { ...commonComponentEventSetting, detail }));
334
+ }
335
+ dispose() {
336
+ this.#stopObservers();
337
+ }
338
+ connectedCallback() {
339
+ this.#componentConnected = true;
340
+ this.#handleEnableLayoutEvent(this.#dom.getAttribute('x-enable-layout-event'));
341
+ document.fonts.ready.then(() => {
342
+ this.#handleAttributeChange();
343
+ });
344
+ boostedQueueMicrotask(() => {
345
+ this.#sendLayoutEvent();
346
+ });
347
+ }
348
+ };
349
+ })();
350
+ export { XTextTruncation };
351
+ class TextRenderingMeasureTool {
352
+ #cachedLineInfo = [{ start: 0 }];
353
+ #lazyLinesInfo = [];
354
+ #lazyNodesInfo = [];
355
+ #dom;
356
+ #domRect;
357
+ nodelist;
358
+ constructor(containerDom, parentRect) {
359
+ this.#dom = containerDom;
360
+ this.nodelist = new LazyNodesList(this.#dom);
361
+ this.#domRect = parentRect;
362
+ }
363
+ #findWrapIndexInTargetTextNode(lastRectInfo) {
364
+ if (lastRectInfo.node.nodeType === Node.TEXT_NODE) {
365
+ const { rect, rectIndex } = lastRectInfo;
366
+ const textNode = lastRectInfo.node;
367
+ const mesaurementRange = document.createRange();
368
+ mesaurementRange.selectNode(textNode);
369
+ for (let charIndex = 0; charIndex < textNode.data.length; charIndex++) {
370
+ mesaurementRange.setEnd(textNode, charIndex);
371
+ const targetRect = mesaurementRange.getClientRects().item(rectIndex);
372
+ if (targetRect && targetRect.right === rect.right) {
373
+ return charIndex;
374
+ }
375
+ }
376
+ return textNode.data.length;
377
+ }
378
+ else {
379
+ return 1;
380
+ }
381
+ }
382
+ #genLinesInfoUntil(lineIndex) {
383
+ if (this.#lazyLinesInfo[lineIndex])
384
+ return;
385
+ const { left: containerLeft } = this.#domRect;
386
+ const lastLineInfo = this.#lazyLinesInfo[this.#lazyLinesInfo.length - 1];
387
+ const lastNodeInfo = lastLineInfo?.[lastLineInfo.length - 1];
388
+ const nextNodeIndex = lastNodeInfo?.nodeIndex
389
+ ? lastNodeInfo?.nodeIndex + 1
390
+ : 0;
391
+ for (let nodeIndex = nextNodeIndex, currentNodeInfo; (currentNodeInfo = this.#getNodeInfoByIndex(nodeIndex))
392
+ && lineIndex >= this.#lazyLinesInfo.length; nodeIndex++) {
393
+ const { node } = currentNodeInfo;
394
+ let rects;
395
+ if (node.nodeType === Node.ELEMENT_NODE) {
396
+ rects = node.getClientRects();
397
+ }
398
+ else {
399
+ const range = document.createRange();
400
+ range.selectNode(node);
401
+ rects = range.getClientRects();
402
+ }
403
+ if (rects.length > 0) {
404
+ const currentLine = this
405
+ .#lazyLinesInfo[this.#lazyLinesInfo.length - 1];
406
+ const firstRect = rects[0];
407
+ if (Math.abs(firstRect.left - containerLeft) < 0.2 || !currentLine) {
408
+ this.#lazyLinesInfo.push([
409
+ { ...currentNodeInfo, rect: firstRect, rectIndex: 0 },
410
+ ]);
411
+ }
412
+ else {
413
+ currentLine.push({
414
+ ...currentNodeInfo,
415
+ rect: firstRect,
416
+ rectIndex: 0,
417
+ });
418
+ }
419
+ if (rects.length > 1) {
420
+ for (let ii = 1; ii < rects.length; ii++) {
421
+ const rect = rects[ii];
422
+ if (rect.left !== firstRect.left
423
+ || rect.bottom !== firstRect.bottom) {
424
+ if (Math.abs(rect.left - containerLeft) < 0.2) {
425
+ // is a new line
426
+ this.#lazyLinesInfo.push([
427
+ { ...currentNodeInfo, rect, rectIndex: ii },
428
+ ]);
429
+ }
430
+ else {
431
+ const currentLine = this
432
+ .#lazyLinesInfo[this.#lazyLinesInfo.length - 1];
433
+ currentLine.push({
434
+ ...currentNodeInfo,
435
+ rect,
436
+ rectIndex: ii,
437
+ });
438
+ }
439
+ }
440
+ }
441
+ }
442
+ }
443
+ }
444
+ }
445
+ /**
446
+ * **NOTE: this is expensive.**
447
+ * @returns
448
+ */
449
+ getLineCount() {
450
+ this.#genLinesInfoUntil(Infinity);
451
+ return this.#lazyLinesInfo.length;
452
+ }
453
+ getLineInfo(lineIndex) {
454
+ this.#genLinesInfoUntil(lineIndex + 1);
455
+ if (lineIndex < this.#lazyLinesInfo.length) {
456
+ // get catched info first
457
+ const pervLineInfo = lineIndex > 0
458
+ ? this.#cachedLineInfo[lineIndex - 1] ?? {}
459
+ : undefined;
460
+ const currentLineInfo = this.#cachedLineInfo[lineIndex] ?? {};
461
+ const nextLineInfo = lineIndex < this.#lazyLinesInfo.length - 1
462
+ ? this.#cachedLineInfo[lineIndex + 1] ?? {}
463
+ : undefined;
464
+ if (currentLineInfo.start === undefined) {
465
+ // can't be firstline since the first line's start is already initialized at the constructor.
466
+ const pervLineRects = this.#lazyLinesInfo[lineIndex - 1];
467
+ const pervLineLastRectInfo = pervLineRects[pervLineRects.length - 1];
468
+ const wrapPosition = this.#findWrapIndexInTargetTextNode(pervLineLastRectInfo);
469
+ const end = pervLineLastRectInfo.start + wrapPosition;
470
+ if (pervLineInfo)
471
+ pervLineInfo.end = end;
472
+ currentLineInfo.start = end + 1;
473
+ }
474
+ if (currentLineInfo.end === undefined) {
475
+ const currentLineRects = this.#lazyLinesInfo[lineIndex];
476
+ const currentLineLastRectInfo = currentLineRects[currentLineRects.length - 1];
477
+ if (lineIndex === this.#lazyLinesInfo.length - 1) {
478
+ // the last line
479
+ const currentNodeLength = currentLineLastRectInfo.node.nodeType === Node.TEXT_NODE
480
+ ? currentLineLastRectInfo.node.data.length
481
+ : 1;
482
+ currentLineInfo.end = currentLineLastRectInfo.start
483
+ + currentNodeLength;
484
+ }
485
+ else {
486
+ const wrapPosition = this.#findWrapIndexInTargetTextNode(currentLineLastRectInfo);
487
+ currentLineInfo.end = currentLineLastRectInfo.start + wrapPosition;
488
+ nextLineInfo.start = currentLineInfo.end + 1;
489
+ }
490
+ }
491
+ return currentLineInfo;
492
+ }
493
+ }
494
+ #getNodeInfoByIndex(nodeIndex) {
495
+ const lastIndex = this.#lazyNodesInfo.length - 1;
496
+ const lastNode = this.#lazyNodesInfo[lastIndex];
497
+ let currentLength = lastNode ? lastNode.start + lastNode.length : 0;
498
+ for (let currentIndex = this.#lazyNodesInfo.length, nextNode; (nextNode = this.nodelist.at(currentIndex))
499
+ && nodeIndex >= this.#lazyNodesInfo.length; currentIndex++) {
500
+ const nodeLength = nextNode.nodeType === Node.ELEMENT_NODE
501
+ ? 1
502
+ : nextNode.data.length;
503
+ const currentNodeInfo = {
504
+ node: nextNode,
505
+ length: nodeLength,
506
+ start: currentLength,
507
+ nodeIndex: currentIndex,
508
+ };
509
+ this.#lazyNodesInfo.push(currentNodeInfo);
510
+ }
511
+ return this.#lazyNodesInfo[nodeIndex];
512
+ }
513
+ getNodeInfoByCharIndex(searchTarget) {
514
+ // binary search
515
+ let left = 0;
516
+ let right = this.#lazyNodesInfo.length - 1;
517
+ let result;
518
+ while (left <= right) {
519
+ const mid = Math.floor((left + right) / 2);
520
+ const midNodeInfo = this.#lazyNodesInfo[mid];
521
+ const midNode = midNodeInfo.node;
522
+ const mindNodeLength = midNode.nodeType === Node.TEXT_NODE
523
+ ? midNode.data.length
524
+ : 1;
525
+ const midNodeStart = midNodeInfo.start;
526
+ // check searchTarget is placed inside midRange
527
+ if (searchTarget >= midNodeStart
528
+ && searchTarget < midNodeStart + mindNodeLength) {
529
+ result = midNodeInfo;
530
+ break;
531
+ }
532
+ else if (searchTarget < midNodeStart) {
533
+ right = mid - 1;
534
+ }
535
+ else {
536
+ left = mid + 1;
537
+ }
538
+ }
539
+ if (result) {
540
+ return result;
541
+ }
542
+ else {
543
+ for (let currentIndex = this.#lazyNodesInfo.length, nextNode; (nextNode = this.#getNodeInfoByIndex(currentIndex)); currentIndex++) {
544
+ if (searchTarget < nextNode.start + nextNode.length) {
545
+ return nextNode;
546
+ }
547
+ }
548
+ }
549
+ return undefined;
550
+ }
551
+ }
552
+ class LazyNodesList {
553
+ #nodeCache = [];
554
+ #treeWalker;
555
+ constructor(dom) {
556
+ this.#treeWalker = document.createTreeWalker(dom, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT, (node) => {
557
+ if (node.nodeType === Node.ELEMENT_NODE) {
558
+ const tagName = node.tagName;
559
+ if (tagName === 'X-TEXT'
560
+ || tagName === 'INLINE-TEXT'
561
+ || tagName === 'RAW-TEXT'
562
+ || tagName === 'LYNX-WRAPPER') {
563
+ return NodeFilter.FILTER_SKIP;
564
+ }
565
+ }
566
+ return NodeFilter.FILTER_ACCEPT;
567
+ });
568
+ }
569
+ at(index) {
570
+ if (this.#nodeCache[index]) {
571
+ return this.#nodeCache[index];
572
+ }
573
+ this.#fillCacheTo(index);
574
+ return this.#nodeCache[index];
575
+ }
576
+ #fillCacheTo(index) {
577
+ let currentNode = null;
578
+ while (index >= this.#nodeCache.length
579
+ && (currentNode = this.#treeWalker.nextNode())) {
580
+ this.#nodeCache.push(currentNode);
581
+ break;
582
+ }
583
+ }
584
+ }
585
+ // function addClientRectsOverlay(rect: DOMRect, color: string = 'red', size: string = '1px') {
586
+ // /* Absolutely position a div over each client rect so that its border width
587
+ // is the same as the rectangle's width.
588
+ // Note: the overlays will be out of place if the user resizes or zooms. */
589
+ // const tableRectDiv = document.createElement("div");
590
+ // tableRectDiv.style.position = "absolute";
591
+ // tableRectDiv.style.border = `${size} solid ${color}`;
592
+ // const scrollTop =
593
+ // document.documentElement.scrollTop || document.body.scrollTop;
594
+ // const scrollLeft =
595
+ // document.documentElement.scrollLeft || document.body.scrollLeft;
596
+ // tableRectDiv.style.margin = tableRectDiv.style.padding = "0";
597
+ // tableRectDiv.style.top = `${rect.top + scrollTop}px`;
598
+ // tableRectDiv.style.left = `${rect.left + scrollLeft}px`;
599
+ // // We want rect.width to be the border width, so content width is 2px less.
600
+ // tableRectDiv.style.width = `${rect.width - 2}px`;
601
+ // tableRectDiv.style.height = `${rect.height - 2}px`;
602
+ // document.body.appendChild(tableRectDiv);
603
+ // }
604
+ //# sourceMappingURL=XTextTruncation.js.map
@@ -0,0 +1,5 @@
1
+ export { InlineImage } from './InlineImage.js';
2
+ export { InlineText } from './InlineText.js';
3
+ export { InlineTruncation } from './InlineTruncation.js';
4
+ export { RawText } from './RawText.js';
5
+ export { XText } from './XText.js';
@@ -0,0 +1,6 @@
1
+ export { InlineImage } from './InlineImage.js';
2
+ export { InlineText } from './InlineText.js';
3
+ export { InlineTruncation } from './InlineTruncation.js';
4
+ export { RawText } from './RawText.js';
5
+ export { XText } from './XText.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ import { AttributeReactiveClass } from '@lynx-js/web-elements-reactive';
2
+ import { XTextarea } from './XTextarea.js';
3
+ export declare class Placeholder implements InstanceType<AttributeReactiveClass<typeof XTextarea>> {
4
+ #private;
5
+ static observedAttributes: readonly ["placeholder", "placeholder-color", "placeholder-font-size", "placeholder-font-weight", "placeholder-font-family"];
6
+ constructor(dom: HTMLElement);
7
+ }