Skip to content

Commit

Permalink
fix: fix rtl support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmd committed Jan 17, 2022
1 parent eb1a60d commit 4b03b9a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
18 changes: 14 additions & 4 deletions docs/eripusisu.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Eripusisu = factory());
}(this, (function () { 'use strict';
})(this, (function () { 'use strict';

var Eripusisu = /** @class */ (function () {
function Eripusisu(container, lines, options) {
Expand Down Expand Up @@ -216,7 +216,14 @@
};
Object.defineProperty(Eripusisu.prototype, "visuallyCollapsed", {
get: function () {
return this.expanded ? false : this.linesMemo.length > this.lines;
return this.expanded ? false : this.needsCollapse;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Eripusisu.prototype, "needsCollapse", {
get: function () {
return this.linesMemo.length > this.lines;
},
enumerable: false,
configurable: true
Expand Down Expand Up @@ -273,7 +280,10 @@
this.rtl = rtl;
this.lineCount = 0;
this.lastBlockStart = -Infinity;
this.lastInlineEnd = this.rtl ? -Infinity : Infinity;
this.lastInlineEnd = Infinity;
if (this.rtl) {
this.lastInlineEnd = -Infinity;
}
for (var i = 0; i < rects.length; i += 1) {
var rect = rects[i];
var result = this.process(rect, i);
Expand Down Expand Up @@ -344,4 +354,4 @@

return Eripusisu;

})));
}));
12 changes: 8 additions & 4 deletions docs/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
padding: 0 1rem;
border: 1px solid;
}
.rtl {
direction: rtl;
}
.float-left {
float: left;
margin-top: 0;
Expand Down Expand Up @@ -286,9 +289,8 @@ <h2>Tables</h2>
<tr>
<td>2</td>
<td>
Nulla vulputate sem felis, vitae lobortis velit tempus at.
Sed in interdum ligula.
In euismod quis massa nec ullamcorper.
Nulla vulputate sem felis, vitae lobortis velit tempus at. Sed
in interdum ligula. In euismod quis massa nec ullamcorper.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -320,7 +322,7 @@ <h2>Inline Blocks</h2>
</div>

<h2>RTL Support</h2>
<div class="set" style="direction: rtl">
<div class="set rtl">
<div class="container">
<p>
لكن لا بد أن أوضح لك أن كل هذه الأفكار المغلوطة حول استنكار النشوة
Expand Down Expand Up @@ -355,9 +357,11 @@ <h2>RTL Support</h2>
const expanded = typeof set.dataset.expanded === "string";
const container = set.querySelector(".container");
const button = set.querySelector(".toggle");
const rtl = set.matches(".rtl");
const eripusisu = new Eripusisu(container, line, {
expanded: expanded,
toggleButton: button,
rtl: rtl,
});
eripusisues.push(eripusisu);
set.addEventListener("eripusisu-toggle", function (e) {
Expand Down
5 changes: 4 additions & 1 deletion src/eripusisu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,16 @@ export default class Eripusisu {
class RectTraverser {
private lineCount = 0;
private lastBlockStart = -Infinity;
private lastInlineEnd = this.rtl ? -Infinity : Infinity;
private lastInlineEnd = Infinity;

constructor(
private callback: Function,
private rects: EripusisuRect[] = [],
private rtl = false
) {
if (this.rtl) {
this.lastInlineEnd = -Infinity;
}
for (let i = 0; i < rects.length; i += 1) {
const rect = rects[i];
const result = this.process(rect, i);
Expand Down

0 comments on commit 4b03b9a

Please sign in to comment.