@getflip/swirl-components 0.34.2 → 0.34.3

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/components.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "timestamp": "2023-03-31T10:23:07",
2
+ "timestamp": "2023-04-03T10:09:33",
3
3
  "compiler": {
4
4
  "name": "@stencil/core",
5
5
  "version": "3.0.0",
@@ -6,6 +6,169 @@ const index = require('./index-83363034.js');
6
6
  const index$1 = require('./index-2ddd0598.js');
7
7
  const balancetext = require('./balancetext-562c7a48.js');
8
8
 
9
+ /**
10
+ shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
11
+ @version v5.0.2
12
+ @link https://github.com/yowainwright/shave#readme
13
+ @author Jeff Wainwright <yowainwright@gmail.com> (jeffry.in)
14
+ @license MIT
15
+ **/
16
+ /******************************************************************************
17
+ Copyright (c) Microsoft Corporation.
18
+
19
+ Permission to use, copy, modify, and/or distribute this software for any
20
+ purpose with or without fee is hereby granted.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
+ PERFORMANCE OF THIS SOFTWARE.
29
+ ***************************************************************************** */
30
+
31
+ function __read(o, n) {
32
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
33
+ if (!m) return o;
34
+ var i = m.call(o), r, ar = [], e;
35
+ try {
36
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
37
+ }
38
+ catch (error) { e = { error: error }; }
39
+ finally {
40
+ try {
41
+ if (r && !r.done && (m = i["return"])) m.call(i);
42
+ }
43
+ finally { if (e) throw e.error; }
44
+ }
45
+ return ar;
46
+ }
47
+
48
+ function __spreadArray(to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ }
57
+
58
+ function generateArrayOfNodes(target) {
59
+ if (typeof target === 'string') {
60
+ return __spreadArray([], __read(document.querySelectorAll(target)), false);
61
+ }
62
+ else if ('length' in target) {
63
+ return __spreadArray([], __read(target), false);
64
+ }
65
+ else {
66
+ return [target];
67
+ }
68
+ }
69
+ function shave(target, maxHeight, opts) {
70
+ if (opts === void 0) { opts = {}; }
71
+ if (typeof maxHeight === 'undefined' || isNaN(maxHeight)) {
72
+ throw Error('maxHeight is required');
73
+ }
74
+ var els = generateArrayOfNodes(target);
75
+ if (!els.length) {
76
+ return;
77
+ }
78
+ var _a = opts.character, character = _a === void 0 ? '…' : _a, _b = opts.classname, classname = _b === void 0 ? 'js-shave' : _b, _c = opts.spaces, initialSpaces = _c === void 0 ? true : _c, _d = opts.charclassname, charclassname = _d === void 0 ? 'js-shave-char' : _d, _e = opts.link, link = _e === void 0 ? {} : _e;
79
+ /**
80
+ * @notes
81
+ * the initialSpaces + spaces variable definition below fixes
82
+ * a previous bug where spaces being a boolean type wasn't clear
83
+ * meaning people were using (a string, in example—which is truthy)
84
+ * hence, doing it this way is a non-breaking change
85
+ */
86
+ var spaces = typeof initialSpaces === 'boolean' ? initialSpaces : true;
87
+ /**
88
+ * @notes
89
+ * - create a span or anchor element and assign properties to it
90
+ * - JSON.stringify is used to support IE8+
91
+ * - if link.href is not provided, link object properties are ignored
92
+ */
93
+ var isLink = link && JSON.stringify(link) !== '{}' && link.href;
94
+ var shavedTextElType = isLink ? 'a' : 'span';
95
+ for (var i = 0; i < els.length; i += 1) {
96
+ var el = els[i];
97
+ var styles = el.style;
98
+ var span = el.querySelector('.' + classname);
99
+ var textProp = el.textContent === undefined ? 'innerText' : 'textContent';
100
+ // If element text has already been shaved
101
+ if (span) {
102
+ // Remove the ellipsis to recapture the original text
103
+ el.removeChild(el.querySelector('.' + charclassname));
104
+ el[textProp] = el[textProp]; // eslint-disable-line
105
+ // nuke span, recombine text
106
+ }
107
+ var fullText = el[textProp];
108
+ var words = spaces ? fullText.split(' ') : fullText;
109
+ // If 0 or 1 words, we're done
110
+ if (words.length < 2) {
111
+ continue;
112
+ }
113
+ // Temporarily remove any CSS height for text height calculation
114
+ var heightStyle = styles.height;
115
+ styles.height = 'auto';
116
+ var maxHeightStyle = styles.maxHeight;
117
+ styles.maxHeight = 'none';
118
+ // If already short enough, we're done
119
+ if (el.offsetHeight <= maxHeight) {
120
+ styles.height = heightStyle;
121
+ styles.maxHeight = maxHeightStyle;
122
+ continue;
123
+ }
124
+ var textContent = isLink && link.textContent ? link.textContent : character;
125
+ var shavedTextEl = document.createElement(shavedTextElType);
126
+ var shavedTextElAttributes = {
127
+ className: charclassname,
128
+ textContent: textContent,
129
+ };
130
+ for (var property in shavedTextElAttributes) {
131
+ shavedTextEl[property] = shavedTextElAttributes[property];
132
+ shavedTextEl.textContent = character;
133
+ }
134
+ if (isLink) {
135
+ for (var linkProperty in link) {
136
+ shavedTextEl[linkProperty] = link[linkProperty];
137
+ }
138
+ }
139
+ // Binary search for number of words which can fit in allotted height
140
+ var max = words.length - 1;
141
+ var min = 0;
142
+ var pivot = void 0;
143
+ while (min < max) {
144
+ pivot = (min + max + 1) >> 1; // eslint-disable-line no-bitwise
145
+ el[textProp] = spaces
146
+ ? words.slice(0, pivot).join(' ')
147
+ : words.slice(0, pivot);
148
+ el.insertAdjacentElement('beforeend', shavedTextEl);
149
+ if (el.offsetHeight > maxHeight) {
150
+ max = pivot - 1;
151
+ }
152
+ else {
153
+ min = pivot;
154
+ }
155
+ }
156
+ el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
157
+ el.insertAdjacentElement('beforeend', shavedTextEl);
158
+ var diff = spaces
159
+ ? " ".concat(words.slice(max).join(' '))
160
+ : words.slice(max);
161
+ var shavedText = document.createTextNode(diff);
162
+ var elWithShavedText = document.createElement('span');
163
+ elWithShavedText.classList.add(classname);
164
+ elWithShavedText.style.display = 'none';
165
+ elWithShavedText.appendChild(shavedText);
166
+ el.insertAdjacentElement('beforeend', elWithShavedText);
167
+ styles.height = heightStyle;
168
+ styles.maxHeight = maxHeightStyle;
169
+ }
170
+ }
171
+
9
172
  const swirlTextCss = ".sc-swirl-text-h{display:block;max-width:100%}.sc-swirl-text-h *.sc-swirl-text{box-sizing:border-box}.text.sc-swirl-text{overflow:hidden;margin:0;padding:0}.text--align-start.sc-swirl-text{text-align:start}.text--align-center.sc-swirl-text{text-align:center}.text--align-end.sc-swirl-text{text-align:end}.text--color-default.sc-swirl-text{color:var(--s-text-default)}.text--color-subdued.sc-swirl-text{color:var(--s-text-subdued)}.text--color-critical.sc-swirl-text{color:var(--s-text-critical)}.text--color-success.sc-swirl-text{color:var(--s-text-success)}.text--color-warning.sc-swirl-text{color:var(--s-text-warning)}.text--size-sm.sc-swirl-text{font-size:var(--s-font-size-sm);line-height:var(--s-line-height-sm)}.text--size-base.sc-swirl-text{font-size:var(--s-font-size-base);line-height:var(--s-line-height-base)}@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px){.text--size-base.sc-swirl-text{font-size:var(--s-font-size-sm);line-height:var(--s-line-height-sm)}}.text--size-lg.sc-swirl-text{font-size:var(--s-font-size-lg);line-height:var(--s-line-height-lg)}@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px){.text--size-lg.sc-swirl-text{font-size:var(--s-font-size-base);line-height:var(--s-line-height-base)}}.text--weight-normal.sc-swirl-text{font-weight:var(--s-font-weight-normal)}.text--weight-medium.sc-swirl-text{font-weight:var(--s-font-weight-medium)}.text--weight-semibold.sc-swirl-text{font-weight:var(--s-font-weight-semibold)}.text--weight-bold.sc-swirl-text{font-weight:var(--s-font-weight-bold)}.text--font-style-normal.sc-swirl-text{font-style:normal}.text--font-style-italic.sc-swirl-text{font-style:italic}.text--truncate.sc-swirl-text{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}";
10
173
 
11
174
  const SwirlText = class {
@@ -23,9 +186,23 @@ const SwirlText = class {
23
186
  }
24
187
  componentDidRender() {
25
188
  this.rebalance();
189
+ this.handleTruncation();
26
190
  }
27
191
  onWindowResize() {
28
192
  this.rebalance();
193
+ this.handleTruncation();
194
+ }
195
+ handleTruncation() {
196
+ if (!this.truncate || !Boolean(this.lines) || this.lines === 1) {
197
+ return;
198
+ }
199
+ const lineHeight = +window
200
+ .getComputedStyle(this.textEl, null)
201
+ .getPropertyValue("line-height")
202
+ .replace("px", "");
203
+ if (lineHeight > 0) {
204
+ shave(this.textEl, lineHeight * this.lines);
205
+ }
29
206
  }
30
207
  rebalance() {
31
208
  if (!this.balance || !Boolean(this.textEl)) {
@@ -35,16 +212,10 @@ const SwirlText = class {
35
212
  }
36
213
  render() {
37
214
  const Tag = this.as;
38
- const styles = Boolean(this.lines)
39
- ? {
40
- display: "-webkit-box",
41
- "-webkit-line-clamp": String(this.lines),
42
- "-webkit-box-orient": "vertical",
43
- whiteSpace: "normal",
44
- }
45
- : undefined;
46
- const className = index$1.classnames("text", `text--align-${this.align}`, `text--color-${this.color}`, `text--font-style-${this.fontStyle}`, `text--size-${this.size}`, `text--weight-${this.weight}`, { "text--truncate": this.truncate });
47
- return (index.h(index.Host, null, index.h(Tag, { class: className, ref: (el) => (this.textEl = el), style: styles }, index.h("slot", null))));
215
+ const className = index$1.classnames("text", `text--align-${this.align}`, `text--color-${this.color}`, `text--font-style-${this.fontStyle}`, `text--size-${this.size}`, `text--weight-${this.weight}`, {
216
+ "text--truncate": this.truncate && (!Boolean(this.lines) || this.lines === 1),
217
+ });
218
+ return (index.h(index.Host, null, index.h(Tag, { class: className, ref: (el) => (this.textEl = el) }, index.h("slot", null))));
48
219
  }
49
220
  get el() { return index.getElement(this); }
50
221
  };