@esri/calcite-components 5.2.0-next.103 → 5.2.0-next.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/{ATWPPYA5.js → 264Q77D5.js} +1 -1
- package/dist/cdn/{E3WBQZVR.js → 2RUE4F4A.js} +1 -1
- package/dist/cdn/{H4LY7LBK.js → 2TXBP24L.js} +1 -1
- package/dist/cdn/{PIYUQJYO.js → 3BZ6M7XT.js} +1 -1
- package/dist/cdn/{N5BF64FZ.js → 3FX4JWQK.js} +1 -1
- package/dist/cdn/{BN7J3DSR.js → 4HHBO3XZ.js} +1 -1
- package/dist/cdn/{PXMBKS4I.js → 4LTEB4JK.js} +1 -1
- package/dist/cdn/{HZOHJOJL.js → 4T7LEQYG.js} +1 -1
- package/dist/cdn/{C47K7XML.js → 52GUFRP5.js} +1 -1
- package/dist/cdn/{6AIJWT53.js → 54U75DHP.js} +1 -1
- package/dist/cdn/{SYK7SBYC.js → 5D3OONRM.js} +1 -1
- package/dist/cdn/{OMBGJQFM.js → 5HRYOFX5.js} +1 -1
- package/dist/cdn/{GJXYW5JA.js → 5I6Y46L4.js} +1 -1
- package/dist/cdn/{TU233PHY.js → 5KJXJHLE.js} +1 -1
- package/dist/cdn/{UHFLHNFQ.js → 5REWXPLJ.js} +1 -1
- package/dist/cdn/{TMPSQ6R3.js → 5XG7MJXM.js} +1 -1
- package/dist/cdn/6BSCY2CN.js +2 -0
- package/dist/cdn/{VM4HT5ED.js → 6OGJG3KA.js} +1 -1
- package/dist/cdn/{EGN6FYWS.js → 6SRMO7QR.js} +1 -1
- package/dist/cdn/{TGR4OOVA.js → 6U3HG35E.js} +1 -1
- package/dist/cdn/{XY4YESU3.js → 6YIR6UQ2.js} +1 -1
- package/dist/cdn/{IHIDGVIU.js → A2JEAX6B.js} +1 -1
- package/dist/cdn/{ZJITKKLT.js → A46Z7TV2.js} +1 -1
- package/dist/cdn/{PQ3QFS5B.js → A6RHKWKU.js} +1 -1
- package/dist/cdn/{VZC4JOKZ.js → A7U6LXNL.js} +1 -1
- package/dist/cdn/{BKDCQ36Q.js → AB2AAI4P.js} +1 -1
- package/dist/cdn/{IZ5RTG2Q.js → AEOCIW6N.js} +1 -1
- package/dist/cdn/{IKG226TX.js → ALZ6O4VG.js} +1 -1
- package/dist/cdn/{JF6FZSXC.js → ANXCH4NM.js} +1 -1
- package/dist/cdn/{7PLHBGIG.js → ATIGQA43.js} +1 -1
- package/dist/cdn/{2NOL7Q65.js → AVBEANMP.js} +1 -1
- package/dist/cdn/{SIHISUDZ.js → AXLKHZF7.js} +1 -1
- package/dist/cdn/{I32PAADY.js → B6ICS4L5.js} +1 -1
- package/dist/cdn/{SEMBAU6Z.js → BBHZTJ7E.js} +1 -1
- package/dist/cdn/{3SKUTKSO.js → BL4UJCS5.js} +1 -1
- package/dist/cdn/{NXUIPQEN.js → BMPLNW7Y.js} +1 -1
- package/dist/cdn/{CATHTHB4.js → BR42QAF2.js} +1 -1
- package/dist/cdn/BUXBC2TD.js +2 -0
- package/dist/cdn/{FDYM4AWK.js → BYJWKSPM.js} +1 -1
- package/dist/cdn/{AGKFDKBX.js → CB56QAVN.js} +1 -1
- package/dist/cdn/{DEMKELDJ.js → CGKKSBUK.js} +1 -1
- package/dist/cdn/{Q3NA4XJS.js → CJPLMHL6.js} +1 -1
- package/dist/cdn/{F66D2GVI.js → CX6VMTHB.js} +1 -1
- package/dist/cdn/{TGNGMEFP.js → D6OXR5HH.js} +1 -1
- package/dist/cdn/{YQT3EPXZ.js → DFJLELTS.js} +1 -1
- package/dist/cdn/{AFR5N4NC.js → DFKGKYEF.js} +1 -1
- package/dist/cdn/{7FW2RVVH.js → DJD3CC5A.js} +1 -1
- package/dist/cdn/{RGGKE5IC.js → DUDXVLZX.js} +1 -1
- package/dist/cdn/{YEOBEDTO.js → DXGTCHAD.js} +1 -1
- package/dist/cdn/{7L2PZVCL.js → EG6PJL34.js} +1 -1
- package/dist/cdn/{4V5MVVRD.js → EGBHDYPW.js} +1 -1
- package/dist/cdn/{SRMV45BG.js → F3FFPXMX.js} +1 -1
- package/dist/cdn/{H3Y3GWRZ.js → FDZX4WWL.js} +1 -1
- package/dist/cdn/{RBLUH75D.js → FEMJOITB.js} +1 -1
- package/dist/cdn/{SAZM37N6.js → FK326MY2.js} +1 -1
- package/dist/cdn/{AUCYXKXH.js → FPQEHXJ3.js} +1 -1
- package/dist/cdn/{BYZQ7O2W.js → GM5YEWMM.js} +1 -1
- package/dist/cdn/{M4XG6CGT.js → GMW5MPTM.js} +1 -1
- package/dist/cdn/{ORUK2RNJ.js → GWQVXROY.js} +1 -1
- package/dist/cdn/{6G2I27TN.js → H32SNSSX.js} +1 -1
- package/dist/cdn/{ZQI4ILEQ.js → H4MYZ7CU.js} +1 -1
- package/dist/cdn/{KB6N7G26.js → H5A5N3SD.js} +1 -1
- package/dist/cdn/{VYXA2N5G.js → HGN6W2NJ.js} +1 -1
- package/dist/cdn/{JH6W45BP.js → HISTK2ZF.js} +1 -1
- package/dist/cdn/{IUMWT6J7.js → HRGDUQAV.js} +1 -1
- package/dist/cdn/{LW5RCTSQ.js → I3MBK6RQ.js} +1 -1
- package/dist/cdn/{4PEEVGHS.js → ICEQ2B2G.js} +1 -1
- package/dist/cdn/{7BSGC2YH.js → IISAEGKF.js} +1 -1
- package/dist/cdn/{QW2BR3TH.js → ILL5MCXC.js} +1 -1
- package/dist/cdn/{MGSSLTW7.js → ILY2U7OP.js} +1 -1
- package/dist/cdn/{RZYJZ7B2.js → IQ47BKLT.js} +1 -1
- package/dist/cdn/{5HDQCOR6.js → IXWEGLDQ.js} +1 -1
- package/dist/cdn/{2JI7T52K.js → IZZHPHVF.js} +1 -1
- package/dist/cdn/{I6OTOCV6.js → J7Z64224.js} +1 -1
- package/dist/cdn/{WBTD2M6Y.js → JBF36T3N.js} +1 -1
- package/dist/cdn/{HVC2BCCM.js → JDYFHYMW.js} +1 -1
- package/dist/cdn/{WIOFWDKD.js → JIGI5ZSK.js} +1 -1
- package/dist/cdn/{62ISXFZN.js → JRFXKWAG.js} +1 -1
- package/dist/cdn/{ZHLLNVRD.js → JRI5SUUW.js} +1 -1
- package/dist/cdn/{5U3NJGQX.js → JXSSREAK.js} +1 -1
- package/dist/cdn/{E5BGBZ4P.js → JZYUW6IY.js} +1 -1
- package/dist/cdn/{LDPZSCQE.js → KMST6UJ3.js} +1 -1
- package/dist/cdn/{BLRUYBMF.js → LJKZP4QZ.js} +1 -1
- package/dist/cdn/{7F56ZKSG.js → LKJXWD5J.js} +1 -1
- package/dist/cdn/{SRTFOHYI.js → LRJHEYDG.js} +1 -1
- package/dist/cdn/{IJB2I3TD.js → LXCVGBWN.js} +1 -1
- package/dist/cdn/{CGU7D6CR.js → MI7EPZ72.js} +1 -1
- package/dist/cdn/{ZXUPYQ5O.js → MWEZH3M4.js} +1 -1
- package/dist/cdn/{MBAXFZ3W.js → NEJIA7VA.js} +1 -1
- package/dist/cdn/{CNY47T4K.js → NIJ3A4IY.js} +1 -1
- package/dist/cdn/{3BPDTQNV.js → NK2OTN4N.js} +1 -1
- package/dist/cdn/{ZTLW2EUH.js → NLYAVVAL.js} +1 -1
- package/dist/cdn/NOODJZAN.js +2 -0
- package/dist/cdn/{KJH4D2S6.js → NPSWLXKP.js} +1 -1
- package/dist/cdn/{W5CF7YHI.js → O3AMPVTL.js} +1 -1
- package/dist/cdn/{R3GNRXGI.js → OLCMMDWX.js} +1 -1
- package/dist/cdn/{4R32CTYU.js → P6CSCVUV.js} +1 -1
- package/dist/cdn/{QPXLDRBN.js → PFRZKJRH.js} +1 -1
- package/dist/cdn/{CMACEQ5G.js → PT5BEFCD.js} +1 -1
- package/dist/cdn/{RIE7E7M6.js → PYBVWWY3.js} +1 -1
- package/dist/cdn/{IUNIMOSP.js → QKCFDUPD.js} +1 -1
- package/dist/cdn/{PJMHCGCH.js → QQKSZ66Y.js} +1 -1
- package/dist/cdn/{ITGZKYPZ.js → QXLJAGMM.js} +1 -1
- package/dist/cdn/{QTATVLQU.js → R5Q4436Z.js} +1 -1
- package/dist/cdn/{77H5FFOU.js → RKOHEWU6.js} +1 -1
- package/dist/cdn/{TIQCZLSJ.js → RQJTT4C4.js} +1 -1
- package/dist/cdn/{O7X4KGBR.js → S3HX76F7.js} +1 -1
- package/dist/cdn/{YDMT3M23.js → S5HTCGOP.js} +1 -1
- package/dist/cdn/{MAJLOAKZ.js → SFQQQ4HL.js} +1 -1
- package/dist/cdn/{NR7NGST5.js → SLOE7CR3.js} +1 -1
- package/dist/cdn/{T665KJMI.js → ST2D3A4C.js} +1 -1
- package/dist/cdn/{KP3FEWJW.js → SXGTS2QT.js} +1 -1
- package/dist/cdn/{3PPFRHH4.js → SZDROVZZ.js} +1 -1
- package/dist/cdn/T2EK7M5W.js +2 -0
- package/dist/cdn/{7HFZ7P6F.js → TAGQIAHC.js} +1 -1
- package/dist/cdn/{VWKHXY64.js → TKY5V6N3.js} +1 -1
- package/dist/cdn/{RWIYEEZL.js → TLXTULLR.js} +1 -1
- package/dist/cdn/{UIW47FPX.js → TXMIPGD7.js} +1 -1
- package/dist/cdn/{TDXSYVVL.js → TXQROMS6.js} +1 -1
- package/dist/cdn/{7LKIC5WK.js → U3NJ5OUI.js} +1 -1
- package/dist/cdn/{YMEXTFWV.js → UCKYBMPL.js} +1 -1
- package/dist/cdn/{NZ6F6C7N.js → UJ7SVXW5.js} +1 -1
- package/dist/cdn/{DBGUFNPK.js → UKCB6Z25.js} +1 -1
- package/dist/cdn/{ON2MMN2J.js → UNHUSMA2.js} +1 -1
- package/dist/cdn/{GH5TSRXM.js → UQ2CL2S6.js} +1 -1
- package/dist/cdn/{4UG53ECI.js → V2XZFSTP.js} +1 -1
- package/dist/cdn/{2JLRCF4I.js → VHWTZ7L2.js} +1 -1
- package/dist/cdn/{UJWDH6OA.js → VTGFMCFV.js} +1 -1
- package/dist/cdn/{WSO7IIGG.js → W2WQCASL.js} +1 -1
- package/dist/cdn/{JKCCMABM.js → W4AT4EUP.js} +1 -1
- package/dist/cdn/{Z6KAIADL.js → WAH6L565.js} +1 -1
- package/dist/cdn/{54WHGMZW.js → WDN7NXSE.js} +1 -1
- package/dist/cdn/{HAGZ2UE4.js → WRRFRZSF.js} +1 -1
- package/dist/cdn/{4EHSWGPR.js → XXPMMKQV.js} +1 -1
- package/dist/cdn/{2IPGIBTO.js → XZPALSDR.js} +1 -1
- package/dist/cdn/{3YGGVMYI.js → YBIVT4F6.js} +1 -1
- package/dist/cdn/{F4WPJCRH.js → YDPXGMY2.js} +1 -1
- package/dist/cdn/{NCOXIVYP.js → YGPHXXML.js} +1 -1
- package/dist/cdn/{GLJEKGXJ.js → Z5T3ZOKL.js} +1 -1
- package/dist/cdn/{NJIBNDLU.js → ZAZOB2QT.js} +1 -1
- package/dist/cdn/{GBQG4OH5.js → ZDTD2JS7.js} +1 -1
- package/dist/cdn/{YBZU2AHE.js → ZN7DDJAR.js} +1 -1
- package/dist/cdn/{PLACFEL6.js → ZP53YJCX.js} +1 -1
- package/dist/cdn/{BRYFJKNK.js → ZQDBLWXZ.js} +1 -1
- package/dist/cdn/{BQLAO6ZR.js → ZQYYCBV6.js} +1 -1
- package/dist/cdn/{S6MLGIDR.js → ZXRTKVNU.js} +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/main.css +1 -1
- package/dist/chunks/dom.js +7 -1
- package/dist/chunks/runtime.js +4 -4
- package/dist/components/calcite-text/customElement.d.ts +19 -0
- package/dist/components/calcite-text/customElement.js +174 -0
- package/dist/components/calcite-text/index.d.ts +1 -0
- package/dist/components/calcite-text/index.js +1 -0
- package/dist/docs/api.json +1 -1
- package/dist/docs/docs.json +1 -1
- package/dist/docs/vscode.html-custom-data.json +1 -1
- package/dist/docs/web-types.json +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/loader.js +1 -0
- package/dist/types/lumina.d.ts +5 -0
- package/dist/types/preact.d.ts +6 -0
- package/dist/types/react.d.ts +7 -0
- package/dist/types/stencil.d.ts +5 -0
- package/package.json +1 -1
- package/dist/cdn/DJBHHZFQ.js +0 -2
- package/dist/cdn/GRGSP36F.js +0 -2
- package/dist/cdn/T26P6UCA.js +0 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference path="../../index.d.ts" />
|
|
2
|
+
import type { PublicLitElement as LitElement } from "@arcgis/lumina";
|
|
3
|
+
|
|
4
|
+
/** @slot - A slot for adding text. */
|
|
5
|
+
export abstract class Text extends LitElement {
|
|
6
|
+
/**
|
|
7
|
+
* Specifies the maximum number of lines to display before truncating the text with an ellipsis.
|
|
8
|
+
*
|
|
9
|
+
* @mdn [maxLines](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/line-clamp)
|
|
10
|
+
*/
|
|
11
|
+
accessor maxLines: number | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Specifies the position of truncation ellipsis when text overflows.
|
|
14
|
+
* `truncatePosition` is ignored when `maxLines` is configured, as multi-line truncation always occurs at the end.
|
|
15
|
+
*/
|
|
16
|
+
accessor truncatePosition: TruncatePosition | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type TruncatePosition = "middle" | "end";
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
|
|
2
|
+
import { c as customElement } from "../../chunks/runtime.js";
|
|
3
|
+
import { LitElement, safeClassMap } from "@arcgis/lumina";
|
|
4
|
+
import { createRef, ref } from "lit/directives/ref.js";
|
|
5
|
+
import { D as getAssignedTextNodesFromSlotEl, k as getTextWidth, E as slotChangeGetTextContent } from "../../chunks/dom.js";
|
|
6
|
+
import { c as createObserver, u as updateRefObserver } from "../../chunks/observers.js";
|
|
7
|
+
import { css, html } from "lit";
|
|
8
|
+
const styles = css`:host{display:block;overflow-wrap:break-word;overflow:hidden;white-space:normal}:host([truncate-position=end]){text-overflow:ellipsis;white-space:nowrap}:host([truncate-position=middle]){white-space:nowrap}.text-container{overflow:inherit;text-overflow:inherit}:host([truncate-position=middle]:not([max-lines])) slot{display:none}:host(:not([truncate-position=middle])) .middle-truncated-text,:host([max-lines]) .middle-truncated-text{display:none}:host([max-lines]) .text-container{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:var(--calcite-internal-text-max-lines, none);white-space:normal}:host([hidden]){display:none}[hidden]{display:none}.assistive-text{position:absolute;inline-size:1px;block-size:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}`;
|
|
9
|
+
const ELLIPSIS_CHAR = "…";
|
|
10
|
+
const CSS = {
|
|
11
|
+
middleTruncatedText: "middle-truncated-text",
|
|
12
|
+
textContainer: "text-container",
|
|
13
|
+
assistiveText: "assistive-text"
|
|
14
|
+
};
|
|
15
|
+
class Text extends LitElement {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.assistiveTextSpanRef = createRef();
|
|
19
|
+
this.defaultSlotRef = createRef();
|
|
20
|
+
this.middleTruncatedSpanRef = createRef();
|
|
21
|
+
this.mutationObserver = createObserver("mutation", (mutations) => {
|
|
22
|
+
const assignedTextNodes = getAssignedTextNodesFromSlotEl(this.defaultSlotRef.value);
|
|
23
|
+
if (mutations.some(({ target }) => assignedTextNodes.includes(target))) {
|
|
24
|
+
this.setValue(assignedTextNodes.map((node) => node.textContent).join("").trim());
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
this.resizeObserver = createObserver("resize", () => {
|
|
28
|
+
this.handleTruncation();
|
|
29
|
+
});
|
|
30
|
+
this.renderedText = "";
|
|
31
|
+
}
|
|
32
|
+
static {
|
|
33
|
+
this.properties = { maxLines: [11, {}, { type: Number, reflect: true }], truncatePosition: [3, {}, { reflect: true }] };
|
|
34
|
+
}
|
|
35
|
+
static {
|
|
36
|
+
this.styles = styles;
|
|
37
|
+
}
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
super.connectedCallback();
|
|
40
|
+
this.mutationObserver?.observe(this.el, {
|
|
41
|
+
characterData: true,
|
|
42
|
+
subtree: true
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
willUpdate(changes) {
|
|
46
|
+
if (changes.has("maxLines") && this.hasUpdated) {
|
|
47
|
+
if (!this.maxLines) {
|
|
48
|
+
this.clearTooltipTitle();
|
|
49
|
+
}
|
|
50
|
+
this.updateMaxLinesToken();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
updated(changes) {
|
|
54
|
+
if (changes.has("truncatePosition") && !this.maxLines) {
|
|
55
|
+
this.handleTruncatePositionChange(changes.get("truncatePosition"));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
disconnectedCallback() {
|
|
59
|
+
super.disconnectedCallback();
|
|
60
|
+
this.resizeObserver?.disconnect();
|
|
61
|
+
this.mutationObserver?.disconnect();
|
|
62
|
+
}
|
|
63
|
+
clearTooltipTitle() {
|
|
64
|
+
this.textContainerEl.title = "";
|
|
65
|
+
}
|
|
66
|
+
getTruncatedText(text, maxWidth, font, letterSpacing) {
|
|
67
|
+
let startIndex = 0;
|
|
68
|
+
let endIndex = text.length;
|
|
69
|
+
const truncatedString = (index) => {
|
|
70
|
+
const leftCount = Math.ceil(index / 2);
|
|
71
|
+
const rightCount = Math.floor(index / 2);
|
|
72
|
+
return text.slice(0, leftCount) + ELLIPSIS_CHAR + text.slice(text.length - rightCount);
|
|
73
|
+
};
|
|
74
|
+
while (startIndex < endIndex) {
|
|
75
|
+
const mid = Math.ceil((startIndex + endIndex) / 2);
|
|
76
|
+
const optimalText = truncatedString(mid);
|
|
77
|
+
if (getTextWidth(optimalText, font, letterSpacing) <= maxWidth) {
|
|
78
|
+
startIndex = mid;
|
|
79
|
+
} else {
|
|
80
|
+
endIndex = mid - 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const optimalIndex = Math.max(0, startIndex);
|
|
84
|
+
if (optimalIndex <= 1) {
|
|
85
|
+
return ELLIPSIS_CHAR;
|
|
86
|
+
}
|
|
87
|
+
return truncatedString(optimalIndex);
|
|
88
|
+
}
|
|
89
|
+
handleDefaultSlotChange(event) {
|
|
90
|
+
this.setValue(slotChangeGetTextContent(event));
|
|
91
|
+
}
|
|
92
|
+
setValue(value) {
|
|
93
|
+
this.value = value;
|
|
94
|
+
this.renderedText = value;
|
|
95
|
+
this.handleTruncation();
|
|
96
|
+
}
|
|
97
|
+
handleTruncation() {
|
|
98
|
+
if (!this.textContainerEl) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const { truncatePosition, maxLines } = this;
|
|
102
|
+
if (this.isTruncatePositionMiddle()) {
|
|
103
|
+
this.truncateMiddleText();
|
|
104
|
+
this.assistiveTextSpanRef.value.textContent = this.value || "";
|
|
105
|
+
} else if (truncatePosition === "end" || maxLines && maxLines >= 1) {
|
|
106
|
+
this.syncTooltipState();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
hasOverflow() {
|
|
110
|
+
return this.textContainerEl.scrollWidth > this.textContainerEl.clientWidth || this.textContainerEl.scrollHeight > this.textContainerEl.clientHeight;
|
|
111
|
+
}
|
|
112
|
+
syncTooltipState() {
|
|
113
|
+
if (this.hasOverflow()) {
|
|
114
|
+
this.setTooltipTitle();
|
|
115
|
+
} else {
|
|
116
|
+
this.clearTooltipTitle();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
handleTruncatePositionChange(oldValue) {
|
|
120
|
+
const newValue = this.truncatePosition;
|
|
121
|
+
if (oldValue && !newValue) {
|
|
122
|
+
this.clearTooltipTitle();
|
|
123
|
+
} else {
|
|
124
|
+
this.handleTruncation();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
setTooltipTitle() {
|
|
128
|
+
this.textContainerEl.title = this.value || "";
|
|
129
|
+
}
|
|
130
|
+
setMiddleTruncatedText(value) {
|
|
131
|
+
const middleTruncatedTextEl = this.middleTruncatedSpanRef.value;
|
|
132
|
+
if (!middleTruncatedTextEl) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
middleTruncatedTextEl.textContent = value || "";
|
|
136
|
+
}
|
|
137
|
+
truncateMiddleText() {
|
|
138
|
+
requestAnimationFrame(() => {
|
|
139
|
+
if (!this.textContainerEl || !this.textContainerEl.clientWidth || this.maxLines || this.truncatePosition !== "middle") {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const clientWidth = this.textContainerEl.clientWidth;
|
|
143
|
+
const computedStyle = getComputedStyle(this.el);
|
|
144
|
+
const font = computedStyle.font || `${computedStyle.fontSize} ${computedStyle.fontFamily}`;
|
|
145
|
+
const textWidth = getTextWidth(this.value, font, computedStyle.letterSpacing);
|
|
146
|
+
if (textWidth <= clientWidth) {
|
|
147
|
+
this.setMiddleTruncatedText(this.value);
|
|
148
|
+
this.clearTooltipTitle();
|
|
149
|
+
} else {
|
|
150
|
+
const middleTruncatedText = this.getTruncatedText(this.renderedText, clientWidth, font, computedStyle.letterSpacing);
|
|
151
|
+
this.setMiddleTruncatedText(middleTruncatedText);
|
|
152
|
+
this.setTooltipTitle();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
updateMaxLinesToken() {
|
|
157
|
+
this.textContainerEl?.style.setProperty("--calcite-internal-text-max-lines", this.maxLines?.toString() || null);
|
|
158
|
+
}
|
|
159
|
+
setTextContainerRef(el) {
|
|
160
|
+
updateRefObserver(this.resizeObserver, this.textContainerEl, el);
|
|
161
|
+
this.textContainerEl = el;
|
|
162
|
+
this.updateMaxLinesToken();
|
|
163
|
+
}
|
|
164
|
+
isTruncatePositionMiddle() {
|
|
165
|
+
return this.truncatePosition === "middle" && !this.maxLines;
|
|
166
|
+
}
|
|
167
|
+
render() {
|
|
168
|
+
return html`<div class=${safeClassMap(CSS.textContainer)} ${ref(this.setTextContainerRef)}><slot @slotchange=${this.handleDefaultSlotChange} ${ref(this.defaultSlotRef)}></slot><span aria-hidden=true class=${safeClassMap(CSS.middleTruncatedText)} ${ref(this.middleTruncatedSpanRef)}></span>${this.isTruncatePositionMiddle() && html`<span aria-live=polite class=${safeClassMap(CSS.assistiveText)} ${ref(this.assistiveTextSpanRef)}></span>` || ""}</div>`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
customElement("calcite-text", Text);
|
|
172
|
+
export {
|
|
173
|
+
Text
|
|
174
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./customElement.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./customElement.js";
|