Commit 6c883e30 authored by Fred Chasen's avatar Fred Chasen

Fixed eslint issues

parent 0f4581a2
......@@ -16,7 +16,10 @@ module.exports = {
"indent": [
"error",
"tab",
{ "VariableDeclarator": { "var": 2, "let": 2, "const": 3 } }
{
"VariableDeclarator": { "var": 2, "let": 2, "const": 3 },
"SwitchCase" : 1
}
],
"linebreak-style": [
"error",
......
......@@ -63,7 +63,6 @@ class Layout {
let hasRenderedContent = false;
let newBreakToken;
let check = 0;
let length = 0;
while (!done && !newBreakToken) {
......@@ -149,7 +148,7 @@ class Layout {
return {
node,
offset
}
};
}
shouldBreak(node) {
......@@ -265,7 +264,7 @@ class Layout {
createBreakToken(overflow, rendered, source) {
let container = overflow.startContainer;
let offset = overflow.startOffset;
let node, renderedNode, ref, parent, index, temp, startOffset;
let node, renderedNode, parent, index, temp;
if (isElement(container)) {
temp = child(container, offset);
......@@ -348,7 +347,6 @@ class Layout {
let walker = walk(rendered.firstChild, rendered);
// Find Start
let startContainer, startOffset;
let next, done, node, offset, skip, breakAvoid, prev, br;
while (!done) {
next = walker.next();
......@@ -512,7 +510,7 @@ class Layout {
if (right > end) {
let letterwalker = letters(word);
let letter, nextLetter, doneLetter, posLetter;
let letter, nextLetter, doneLetter;
while (!doneLetter) {
nextLetter = letterwalker.next();
......
......@@ -145,7 +145,6 @@ class Page {
e = entries[i];
if(e.dataset.ref === ref) {
return e;
break;
}
}
}
......
import htmlparser2 from 'htmlparser2';
/**
* Render a flow of text offscreen
* @class
*/
class Parser {
constructor(content, cb) {
// this.text = text;
// this.nodes = [];
this.refs = {};
this.sections = [];
if (content && content.nodeType) {
// handle dom
} else if(typeof content === "object") {
this.add(content);
} else if (typeof content === "string") {
this.dom = this.parse(content);
}
}
parse(data) {
let options = {};
let process = (node) => {
let uuid = this.uuid();
this.refs[uuid] = node;
node.dataset.ref = uuid; // Refs for all nodes
node.dataset.ref = uuid;
node.dataset.children = node.children.length;
if (node.data) {
node.dataset.text = node.data.length;
}
if (node.name === "section") {
this.sections.push(node);
}
}
let handler = new htmlparser2.DomHandler(undefined, options, process.bind(this));
new htmlparser2.Parser(handler, options).end(data);
return handler.dom;
}
add(contents) {
this.dom = [contents];
let walker = this.walk(this.dom[0]);
let next, done, node;
while (!done) {
next = walker.next();
node = next.value;
done = next.done;
if (node && node.dataset && node.dataset.ref) {
this.refs[node.dataset.ref] = node;
}
}
}
find(ref) {
return this.refs[ref];
}
*walk(start) {
let node = start || this.dom[0];
while (node) {
yield node;
if (node.children && node.children.length) {
node = node.children[0];
} else if (node.next) {
node = node.next;
} else {
while (node) {
node = node.parent;
if (node && node.next) {
node = node.next;
break;
}
}
}
}
}
// isWrapper(element) {
// return wrappersRegex.test(element.nodeName);
// }
isText(node) {
return node.name === "tag";
}
isElement(node) {
return node.name === "text";
}
hasChildren(node) {
return node.children && node.children.length;
}
after(node) {
let after = node;
if (after.next) {
after = after.next;
} else {
while (after) {
after = after.parent;
if (after && after.next) {
after = after.next;
break;
}
}
}
return after;
}
/**
* Generates a UUID
* based on: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
* @returns {string} uuid
*/
uuid() {
var d = new Date().getTime();
if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
d += performance.now(); //use high-precision timer if available
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}
destroy() {
this.refs = undefined;
this.dom = undefined;
}
}
export default Parser;
......@@ -19,8 +19,6 @@ class ContentParser {
}
parse(markup, mime) {
let parser = new DOMParser();
let range = document.createRange();
let fragment = range.createContextualFragment(markup);
......@@ -53,8 +51,8 @@ class ContentParser {
false
);
let node;
while(node = treeWalker.nextNode()) {
let node = treeWalker.nextNode();
while(node) {
if (!node.hasAttribute("data-ref")) {
let uuid = UUID();
......@@ -68,6 +66,7 @@ class ContentParser {
// node.setAttribute("data-children", node.childNodes.length);
// node.setAttribute("data-text", node.textContent.trim().length);
node = treeWalker.nextNode();
}
}
......
import Chunker from './chunker/chunker';
import Polisher from './polisher/polisher';
import Previewer from './polyfill/previewer';
import Handler from './modules/handler';
import { registerHandlers, initializeHandlers } from './utils/handlers';
import Chunker from "./chunker/chunker";
import Polisher from "./polisher/polisher";
import Previewer from "./polyfill/previewer";
import Handler from "./modules/handler";
import { registerHandlers, initializeHandlers } from "./utils/handlers";
export {
Chunker,
......
import RunningHeaders from './running-headers';
import StringSets from './string-sets';
import TargetCounters from './target-counters';
import TargetText from './target-text';
import RunningHeaders from "./running-headers";
import StringSets from "./string-sets";
import TargetCounters from "./target-counters";
import TargetText from "./target-text";
export default [
RunningHeaders,
StringSets,
TargetCounters,
TargetText
]
];
import Handler from "../handler";
import csstree from 'css-tree';
import csstree from "css-tree";
class RunningHeaders extends Handler {
constructor(chunker, polisher, caller) {
......@@ -12,12 +12,12 @@ class RunningHeaders extends Handler {
onDeclaration(declaration, dItem, dList, rule) {
if (declaration.property === "position") {
let selector = csstree.generate(rule.ruleNode.prelude);
let identifier = declaration.value.children.first().name
let identifier = declaration.value.children.first().name;
if (identifier === "running") {
let value;
csstree.walk(declaration, {
visit: 'Function',
visit: "Function",
enter: (node, item, list) => {
value = node.children.first().name;
}
......@@ -27,14 +27,14 @@ class RunningHeaders extends Handler {
identifier: identifier,
value: value,
selector: selector
}
};
}
}
if (declaration.property === "content") {
csstree.walk(declaration, {
visit: 'Function',
visit: "Function",
enter: (funcNode, fItem, fList) => {
if (funcNode.name.indexOf("element") > -1) {
......@@ -61,7 +61,7 @@ class RunningHeaders extends Handler {
style: style || "first",
selector: s,
fullSelector: selector
}
};
});
}
......@@ -89,14 +89,14 @@ class RunningHeaders extends Handler {
let set = this.runningSelectors[name];
let selected = fragment.querySelector(set.selector);
if (selected) {
let cssVar;
// let cssVar;
if (set.identifier === "running") {
// cssVar = selected.textContent.replace(/\\([\s\S])|(["|'])/g,"\\$1$2");
// this.styleSheet.insertRule(`:root { --string-${name}: "${cssVar}"; }`, this.styleSheet.cssRules.length);
// fragment.style.setProperty(`--string-${name}`, `"${cssVar}"`);
set.first = selected;
} else {
console.log(set.value + "needs css replacement");
console.warn(set.value + "needs css replacement");
}
}
}
......@@ -134,13 +134,15 @@ class RunningHeaders extends Handler {
* 5) named page
* 6) named left & right
* 7) named first & nth
* @param {string} [s] selector string
* @return {int} weight
*/
pageWeight(s) {
let weight = 1;
let selector = s.split(" ");
let parts = selector.length && selector[0].split(".");
parts.shift() // remove empty first part
parts.shift(); // remove empty first part
switch (parts.length) {
case 4:
......@@ -184,6 +186,8 @@ class RunningHeaders extends Handler {
*
* Does not try to deduplicate base on specifity of the selector
* Previous matched selector will just be overwritten
* @param {obj} [obj] selectors object
* @return {Array} orderedSelectors
*/
orderSelectors(obj) {
let selectors = Object.keys(obj);
......@@ -213,7 +217,7 @@ class RunningHeaders extends Handler {
beforeTreeParse(text, sheet) {
// element(x) is parsed as image element selector, so update element to element-ident
sheet.text = text.replace(/element[\s]*\(([^\|^#)]*)\)/g, "element-ident($1)");
sheet.text = text.replace(/element[\s]*\(([^|^#)]*)\)/g, "element-ident($1)");
}
}
......
import Handler from "../handler";
import csstree from 'css-tree';
import csstree from "css-tree";
class StringSets extends Handler {
constructor(chunker, polisher, caller) {
......@@ -12,11 +12,11 @@ class StringSets extends Handler {
if (declaration.property === "string-set") {
let selector = csstree.generate(rule.ruleNode.prelude);
let identifier = declaration.value.children.first().name
let identifier = declaration.value.children.first().name;
let value;
csstree.walk(declaration, {
visit: 'Function',
visit: "Function",
enter: (node, item, list) => {
value = csstree.generate(node);
}
......@@ -26,7 +26,7 @@ class StringSets extends Handler {
identifier: identifier,
value: value,
selector: selector
}
};
}
}
......@@ -57,7 +57,7 @@ class StringSets extends Handler {
set.first = cssVar;
fragment.style.setProperty(`--string-${name}`, `"${set.first}"`);
} else {
console.log(set.value + "needs css replacement");
console.warn(set.value + "needs css replacement");
}
} else {
// Use the previous values
......
import Handler from "../handler";
import { UUID, attr, querySelectorEscape } from "../../utils/utils";
import csstree from 'css-tree';
import csstree from "css-tree";
class TargetCounters extends Handler {
constructor(chunker, polisher, caller) {
......@@ -15,12 +15,11 @@ class TargetCounters extends Handler {
if (funcNode.name === "target-counter") {
let selector = csstree.generate(rule.ruleNode.prelude);
let first = funcNode.children.first();
let last = funcNode.children.last();
let func = first.name;
let value = csstree.generate(funcNode);
let args = []
let args = [];
first.children.forEach((child) => {
if (child.type === "Identifier") {
......@@ -41,7 +40,7 @@ class TargetCounters extends Handler {
style = child.name;
}
}
})
});
let variable = "target-counter-" + UUID();
......@@ -55,12 +54,12 @@ class TargetCounters extends Handler {
selector: s,
fullSelector: selector,
variable: variable
}
};
});
// Replace with counter
funcNode.name = "counter";
funcNode.children = new csstree.List()
funcNode.children = new csstree.List();
funcNode.children.appendData({
type: "Identifier",
loc: 0,
......@@ -110,10 +109,10 @@ class TargetCounters extends Handler {
}
}
let psuedo = "";
if (split.length > 1) {
psuedo += "::" + split[1];
}
// let psuedo = "";
// if (split.length > 1) {
// psuedo += "::" + split[1];
// }
this.styleSheet.insertRule(`[data-${target.variable}="${selector}"] { counter-increment: ${target.variable} ${pg}; }`, this.styleSheet.cssRules.length);
} else {
......
import Handler from "../handler";
import { UUID, attr, querySelectorEscape } from "../../utils/utils";
import csstree from 'css-tree';
import csstree from "css-tree";
class TargetText extends Handler {
constructor(chunker, polisher, caller) {
......@@ -19,7 +19,7 @@ class TargetText extends Handler {
let value = csstree.generate(funcNode);
let args = []
let args = [];
first.children.forEach((child) => {
if (child.type === "Identifier") {
......@@ -43,12 +43,12 @@ class TargetText extends Handler {
selector: s,
fullSelector: selector,
variable: variable
}
};
});
// Replace with variable
funcNode.name = "var";
funcNode.children = new csstree.List()
funcNode.children = new csstree.List();
funcNode.children.appendData({
type: "Identifier",
loc: 0,
......@@ -68,7 +68,6 @@ class TargetText extends Handler {
let element = fragment.querySelector(querySelectorEscape(val));
if (element) {
if (target.style === "content") {
let text = element.textContent;
let selector = UUID();
selected.setAttribute("data-target-text", selector);
......@@ -77,7 +76,7 @@ class TargetText extends Handler {
psuedo += "::" + split[1];
}
let textContent = element.textContent.trim().replace(/[\"\']/g, (match) => {
let textContent = element.textContent.trim().replace(/["']/g, (match) => {
return "\\" + match;
}).replace(/[\n]/g, (match) => {
return "\\00000A";
......
This diff is collapsed.
import Handler from "../handler";
import csstree from 'css-tree';
import { rebuildAncestors, elementAfter } from "../../utils/dom";
import csstree from "css-tree";
import { elementAfter } from "../../utils/dom";
class Breaks extends Handler {
constructor(chunker, polisher, caller) {
......@@ -31,7 +31,7 @@ class Breaks extends Handler {
} else {
this.breaks[s].push(breaker);
}
})
});
dList.remove(dItem);
}
......@@ -63,7 +63,7 @@ class Breaks extends Handler {
} else {
this.breaks[s].push(breaker);
}
})
});
// Remove from CSS -- handle right / left in module
dList.remove(dItem);
......
import Handler from "../handler";
import csstree from 'css-tree';
import { rebuildAncestors, elementAfter } from "../../utils/dom";
import csstree from "css-tree";
class Counters extends Handler {
constructor(chunker, polisher, caller) {
......@@ -45,7 +44,7 @@ class Counters extends Handler {
name: name,
increments: {},
resets: {}
}
};
return this.counters[name];
}
......
import AtPage from './atpage';
import Breaks from './breaks';
import PrintMedia from './print-media';
import Splits from './splits';
import Counters from './counters';
import Lists from './lists';
import AtPage from "./atpage";
import Breaks from "./breaks";
import PrintMedia from "./print-media";
import Splits from "./splits";
import Counters from "./counters";
import Lists from "./lists";
export default [
AtPage,
......@@ -12,4 +12,4 @@ export default [
Splits,
Counters,
Lists
]
];
......@@ -5,7 +5,7 @@ class Lists extends Handler {
super(chunker, polisher, caller);
}
afterParsed(content) {
const orderedLists = content.querySelectorAll('ol');
const orderedLists = content.querySelectorAll("ol");
for (var list of orderedLists) {
this.addDataNumbers(list);
......@@ -13,7 +13,7 @@ class Lists extends Handler {
}
afterPageLayout(pageElement, page, breakToken, chunker) {
var orderedLists = pageElement.getElementsByTagName('ol');
var orderedLists = pageElement.getElementsByTagName("ol");
for (var list of orderedLists) {
list.start = list.firstElementChild.dataset.itemNum;
}
......@@ -22,7 +22,7 @@ class Lists extends Handler {
addDataNumbers(list) {
let items = list.children;
for (var i = 0; i < items.length; i++) {
items[i].setAttribute('data-item-num', i + 1);
items[i].setAttribute("data-item-num", i + 1);
}
}
......
import Handler from "../handler";
import csstree from 'css-tree';
import csstree from "css-tree";
class PrintMedia extends Handler {
constructor(chunker, polisher, caller) {
......@@ -23,7 +23,7 @@ class PrintMedia extends Handler {
}
getMediaName(node) {
let media = '';
let media = "";
if (typeof node.prelude === "undefined" ||
node.prelude.type !== "AtrulePrelude" ) {
......@@ -31,7 +31,7 @@ class PrintMedia extends Handler {
}
csstree.walk(node.prelude, {
visit: 'Identifier',
visit: "Identifier",
enter: (identNode, iItem, iList) => {
media = identNode.name;
}
......
import Handler from "../handler";
import csstree from 'css-tree';
class Splits extends Handler {
constructor(chunker, polisher, caller) {
......
import Sheet from './sheet';
import baseStyles from './base';
import { UUID } from '../utils/utils';
import Sheet from "./sheet";
import baseStyles from "./base";
import Hook from "../utils/hook";
class Polisher {
......@@ -52,7 +51,7 @@ class Polisher {
urls.push(arguments[i]);
f = fetch(arguments[i]).then((response) => {
return response.text();
})
});
}
......
import csstree from 'css-tree';
import csstree from "css-tree";
import { UUID } from "../utils/utils";
import Hook from "../utils/hook";
......@@ -66,12 +66,12 @@ class Sheet {
let inserted = this.ast.children.appendData(rule);
inserted.forEach((item) => {
this.declarations(item);
})
});
}
urls(ast) {
csstree.walk(ast, {
visit: 'Url',
visit: "Url",
enter: (node, item, list) => {
this.hooks.onUrl.trigger(node, item, list);
}
......@@ -80,7 +80,7 @@ class Sheet {
atrules(ast) {
csstree.walk(ast, {
visit: 'Atrule',
visit: "Atrule",
enter: (node, item, list) => {
const basename = csstree.keyword(node.name).basename;
......@@ -99,9 +99,8 @@ class Sheet {
rules(ast) {
let parsed = {};
csstree.walk(ast, {
visit: 'Rule',
visit: "Rule",
enter: (ruleNode, ruleItem, rulelist) => {
// console.log("rule", ruleNode);
......@@ -113,7 +112,7 @@ class Sheet {
declarations(ruleNode, ruleItem, rulelist) {
csstree.walk(ruleNode, {
visit: 'Declaration',
visit: "Declaration",
enter: (declarationNode, dItem, dList) => {
// console.log(declarationNode);
......@@ -121,7 +120,7 @@ class Sheet {
if (declarationNode.property === "content") {
csstree.walk(declarationNode, {
visit: 'Function',
visit: "Function",
enter: (funcNode, fItem, fList) => {
this.hooks.onContent.trigger(funcNode, fItem, fList, {declarationNode, dItem, dList}, {ruleNode, ruleItem, rulelist});
}
......@@ -134,10 +133,10 @@ class Sheet {
replaceUrls(ast) {
csstree.walk(ast, {
visit: 'Url',
visit: "Url",
enter: (node, item, list) => {
let href = node.value.value.replace(/["']/g, '');
let url = new URL(href, this.url)
let href = node.</