Commit aab347ec authored by julien's avatar julien

update paged.js

parent 166b5ff3
(function(l, i, v, e) { v = l.createElement(i); v.async = 1; v.src = '//' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; e = l.getElementsByTagName(i)[0]; e.parentNode.insertBefore(v, e)})(document, 'script');
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
......@@ -874,7 +875,7 @@
findBreakToken(overflow, content) {
let offset = overflow.startOffset;
let node, renderedNode, ref, parent, index, temp;
let node, renderedNode, ref, parent, index, temp, startOffset;
if (overflow.startContainer.nodeType === 1) {
// node = children.querySelector("[data-ref='" + overflow.startContainer.childNodes[offset].getAttribute("data-ref") + "']");
......@@ -901,6 +902,8 @@
renderedNode = this.wrapper.querySelector("[data-ref='" + ref + "']");
parent = content.querySelector("[data-ref='"+ renderedNode.getAttribute("data-ref") +"']");
node = parent.childNodes[index];
startOffset = overflow.startContainer.textContent.slice(offset);
offset = parent.textContent.indexOf(startOffset);
}
if (!node) {
......@@ -916,9 +919,21 @@
removeOverflow(overflow) {
return overflow.extractContents();
if (overflow.startContainer.nodeType === 3 && overflow.startOffset > 0) {
let startText = overflow.startContainer.textContent;
let startOffset = overflow.startOffset;
let prevLetter = startText[startOffset-1];
// Add a hyphen if previous character is a letter or soft hyphen
if (/^\w|\u00AD$/.test(prevLetter)) {
overflow.startContainer.textContent = startText.slice(0, startOffset) + "\u2010";
overflow.setStart(overflow.startContainer, startOffset + 1);
}
}
// _requestIdleCallback(() => this.removeEmpty());
return overflow.extractContents();
}
removeEmpty() {
......@@ -1044,9 +1059,10 @@
range = document.createRange();
offset = this.textBreak(node, start, end);
if (!offset) {
offset = 0;
range = undefined;
} else {
range.setStart(node, offset);
}
range.setStart(node, offset);
break;
}
......@@ -1075,7 +1091,9 @@
textBreak(node, start, end) {
let wordwalker = this.words(node);
let left = 0;
let right = 0;
let word, next, done, pos;
let offset;
while (!done) {
next = wordwalker.next();
word = next.value;
......@@ -1088,11 +1106,41 @@
pos = getBoundingClientRect(word);
left = Math.floor(pos.left);
right = Math.floor(pos.right);
if (left >= end) {
offset = word.startOffset;
break;
}
if (right > end) {
let letterwalker = this.letters(word);
let letter, nextLetter, doneLetter;
while (!doneLetter) {
nextLetter = letterwalker.next();
letter = nextLetter.value;
doneLetter = nextLetter.done;
if (!letter) {
break;
}
pos = getBoundingClientRect(letter);
left = Math.floor(pos.left);
if (left >= end) {
offset = letter.startOffset;
done = true;
break;
}
}
}
}
return word && word.startOffset;
return offset;
}
*words(node) {
......@@ -1105,8 +1153,7 @@
while(currentOffset < max) {
currentLetter = currentText[currentOffset];
if (/^\w$/.test(currentLetter)) {
if (/^\S$/.test(currentLetter)) {
if (!range) {
range = document.createRange();
range.setStart(node, currentOffset);
......@@ -1121,10 +1168,38 @@
currentOffset += 1;
}
if (range) {
range.setEnd(node, currentOffset);
yield range;
range = undefined;
}
}
*letters(wordRange) {
let currentText = wordRange.startContainer;
let max = currentText.length;
let currentOffset = wordRange.startOffset;
let currentLetter;
let range;
while(currentOffset < max) {
currentLetter = currentText[currentOffset];
range = document.createRange();
range.setStart(currentText, currentOffset);
range.setEnd(currentText, currentOffset+1);
yield range;
currentOffset += 1;
}
}
prepend(fragment, rebuild=true) {
// this.element.insertBefore(fragment, this.element.firstChild);
if (!fragment) {
return;
}
let walker = walk(fragment.firstChild, this.wrapper);
let next, node, done;
let parent;
......@@ -2377,7 +2452,7 @@
this.remove(oldItem);
};
var List_1 = List;
var list = List;
var createCustomError = function createCustomError(name, message) {
// use Object.create(), because some VMs prevent setting line/column otherwise
......@@ -3841,7 +3916,6 @@
var findIdentifierEnd$2 = utils.findIdentifierEnd;
var findNumberEnd$2 = utils.findNumberEnd;
var findDecimalNumberEnd$1 = utils.findDecimalNumberEnd;
var findStringEnd$2 = utils.findStringEnd;
var isHex$1 = utils.isHex;
var SYMBOL_TYPE$2 = _const.SYMBOL_TYPE;
......@@ -3849,8 +3923,6 @@
var PLUSSIGN$2 = _const.TYPE.PlusSign;
var HYPHENMINUS$3 = _const.TYPE.HyphenMinus;
var NUMBERSIGN = _const.TYPE.NumberSign;
var APOSTROPHE$1 = _const.TYPE.Apostrophe;
var QUOTATIONMARK$1 = _const.TYPE.QuotationMark;
var PERCENTAGE = {
'%': true
......@@ -4022,19 +4094,6 @@
return findIdentifierEnd$2(str, offset + 1);
}
function ident(token, addTokenToMatch) {
if (token === null) {
return false;
}
if (consumeIdentifier(token.value, 0) !== token.value.length) {
return false;
}
addTokenToMatch();
return true;
}
function astNode(type) {
return function(token, addTokenToMatch) {
if (token === null || token.node.type !== type) {
......@@ -4046,25 +4105,6 @@
};
}
function string(token, addTokenToMatch) {
if (token === null || token.value.length < 2) {
return false;
}
var quote = token.value.charCodeAt(0);
if (quote !== APOSTROPHE$1 && quote !== QUOTATIONMARK$1) {
return false;
}
if (findStringEnd$2(token.value, 1, quote) !== token.value.length) {
return false;
}
addTokenToMatch();
return true;
}
function dimension(type) {
return function(token, addTokenToMatch, getNextToken) {
if (calc(token, addTokenToMatch, getNextToken)) {
......@@ -4268,7 +4308,7 @@
'flex': dimension(FLEX),
'hex-color': hexColor,
'id-selector': idSelector, // element( <id-selector> )
'ident': ident,
'ident': astNode('Identifier'),
'integer': integer,
'length': zeroUnitlessDimension(LENGTH),
'number': number,
......@@ -4278,7 +4318,7 @@
'positive-integer': positiveInteger,
'resolution': dimension(RESOLUTION),
'semitones': dimension(SEMITONES),
'string': string,
'string': astNode('String'),
'time': dimension(TIME),
'unicode-range': astNode('UnicodeRange'),
'url': url,
......@@ -4369,7 +4409,7 @@
var EXCLAMATIONMARK$1 = 33; // !
var NUMBERSIGN$1 = 35; // #
var AMPERSAND = 38; // &
var APOSTROPHE$2 = 39; // '
var APOSTROPHE$1 = 39; // '
var LEFTPARENTHESIS$1 = 40; // (
var RIGHTPARENTHESIS$1 = 41; // )
var ASTERISK = 42; // *
......@@ -4574,11 +4614,11 @@
var name;
tokenizer.eat(LESSTHANSIGN$1);
tokenizer.eat(APOSTROPHE$2);
tokenizer.eat(APOSTROPHE$1);
name = scanWord(tokenizer);
tokenizer.eat(APOSTROPHE$2);
tokenizer.eat(APOSTROPHE$1);
tokenizer.eat(GREATERTHANSIGN$1);
return maybeMultiplied(tokenizer, {
......@@ -4758,7 +4798,7 @@
return maybeMultiplied(tokenizer, readGroup(tokenizer));
case LESSTHANSIGN$1:
return tokenizer.nextCharCode() === APOSTROPHE$2
return tokenizer.nextCharCode() === APOSTROPHE$1
? readProperty(tokenizer)
: readType(tokenizer);
......@@ -4787,7 +4827,7 @@
type: 'Comma'
};
case APOSTROPHE$2:
case APOSTROPHE$1:
return maybeMultiplied(tokenizer, {
type: 'String',
value: scanString(tokenizer)
......@@ -6064,9 +6104,9 @@
var start = getFirstMatchNode(matchNode);
var end = getLastMatchNode(matchNode);
lexer.syntax.walk(ast, function(node, item, list) {
lexer.syntax.walk(ast, function(node, item, list$$1) {
if (node === start) {
var nodes = new List_1();
var nodes = new list();
do {
nodes.appendData(item.data);
......@@ -6079,7 +6119,7 @@
} while (item !== null);
fragments.push({
parent: list,
parent: list$$1,
nodes: nodes
});
}
......@@ -6179,7 +6219,7 @@
if (typeof fieldType === 'string') {
valid = node[key] && node[key].type === fieldType;
} else if (Array.isArray(fieldType)) {
valid = node[key] instanceof List_1;
valid = node[key] instanceof list;
}
}
}
......@@ -6735,16 +6775,16 @@
readSequence: sequence,
createList: function() {
return new List_1();
return new list();
},
createSingleNodeList: function(node) {
return new List_1().appendData(node);
return new list().appendData(node);
},
getFirstListNode: function(list) {
return list && list.first();
getFirstListNode: function(list$$1) {
return list$$1 && list$$1.first();
},
getLastListNode: function(list) {
return list.last();
getLastListNode: function(list$$1) {
return list$$1.last();
},
parseWithFallback: function(consumer, fallback) {
......@@ -6778,10 +6818,10 @@
return null;
},
getLocationFromList: function(list) {
getLocationFromList: function(list$$1) {
if (this.needPositions) {
var head = this.getFirstListNode(list);
var tail = this.getLastListNode(list);
var head = this.getFirstListNode(list$$1);
var tail = this.getLastListNode(list$$1);
return this.scanner.getLocationRange(
head !== null ? head.loc.start.offset - this.scanner.startOffset : this.scanner.tokenStart,
tail !== null ? tail.loc.end.offset - this.scanner.startOffset : this.scanner.tokenStart,
......@@ -10035,8 +10075,8 @@
fromPlainObject: function(ast) {
walk(ast, {
enter: function(node) {
if (node.children && node.children instanceof List_1 === false) {
node.children = new List_1().fromArray(node.children);
if (node.children && node.children instanceof list === false) {
node.children = new list().fromArray(node.children);
}
}
});
......@@ -10046,7 +10086,7 @@
toPlainObject: function(ast) {
walk(ast, {
leave: function(node) {
if (node.children && node.children instanceof List_1) {
if (node.children && node.children instanceof list) {
node.children = node.children.toArray();
}
}
......@@ -10279,7 +10319,7 @@
var value = node[key];
if (value) {
if (Array.isArray(value) || value instanceof List_1) {
if (Array.isArray(value) || value instanceof list) {
value = value.map(clone);
} else if (value.constructor === Object) {
value = clone(value);
......@@ -10402,7 +10442,7 @@
var convert = create$3(walk);
var syntax = {
List: List_1,
List: list,
Tokenizer: tokenizer,
Lexer: Lexer_1,
......@@ -18363,7 +18403,7 @@
syntax: "space-between | space-around | space-evenly | stretch"
},
"content-list": {
syntax: "[ <string> | contents | <image> | <quote> | <target> | <leader()> | <element()> ]+"
syntax: "[ <string> | contents | <image> | <quote> | <target> | <leader()> ]+"
},
"content-position": {
syntax: "center | start | end | flex-start | flex-end"
......@@ -19707,50 +19747,6 @@
"pseudo-page": {
comment: "syntax is incorrect and can't be parsed, drop for now",
syntax: null
},
"id-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"attribute-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"wq-name": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"ns-prefix": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"class-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"compound-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"type-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"subclass-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"pseudo-class-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"pseudo-element-selector": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
},
"compound-selector-list": {
comment: "temporary omit due lack of nested syntax definition(s)",
syntax: null
}
};
var patch = {
......@@ -26084,4 +26080,4 @@
await previewer.preview();
});
})));
\ No newline at end of file
})));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment