...
 
Commits (7)
......@@ -43,13 +43,17 @@ class StringSets extends Handler {
funcNode.name = "var";
funcNode.children = new csstree.List();
funcNode.children.append(
funcNode.children.createItem({
type: "Identifier",
loc: null,
name: "--pagedjs-string-" + identifier
})
);
if(this.type === "first" || "last" || "start" || "first-except"){
console.log(this.type);
funcNode.children.append(
funcNode.children.createItem({
type: "Identifier",
loc: null,
name: "--pagedjs-string-" + this.type + "-" + identifier
})
);
}
}
}
......@@ -61,59 +65,67 @@ class StringSets extends Handler {
this.pageLastString = {};
}
// get the value of the previous last string
for (let name of Object.keys(this.stringSetSelectors)) {
let set = this.stringSetSelectors[name];
let selected = fragment.querySelectorAll(set.selector);
// let cssVar = previousPageLastString;
console.log(selected.length);
// Get the last found string for the current identifier
let cssVar = ( name in this.pageLastString ) ? this.pageLastString[name] : "";
selected.forEach((sel) => {
// push each content into the array to define in the variable the first and the last element of the page.
//this.pageLastString = selected[selected.length - 1].textContent;
// Index by identifier
this.pageLastString[name] = selected[selected.length - 1].textContent;
if (this.type === "first") {
cssVar = selected[0].textContent;
}
else if (this.type === "last") {
cssVar = selected[selected.length - 1].textContent;
}
else if (this.type === "start") {
let stringPrevPage = ( name in this.pageLastString ) ? this.pageLastString[name] : "";
let varFirst, varLast, varStart, varFirstExcept;
if(selected.length == 0){
// if there is no sel. on the page
varFirst = stringPrevPage;
varLast = stringPrevPage;
varStart = stringPrevPage;
varFirstExcept = stringPrevPage;
}else{
selected.forEach((sel) => {
// push each content into the array to define in the variable the first and the last element of the page.
this.pageLastString[name] = selected[selected.length - 1].textContent;
if (sel.parentElement.firstChild === sel) {
cssVar = sel.textContent;
}
}
});
/* FIRST */
else if (this.type === "first-except") {
cssVar = "";
varFirst = selected[0].textContent;
/* LAST */
varLast = selected[selected.length - 1].textContent;
/* START */
// Hack to find if the sel. is the first elem of the page / find a better way
let selTop = selected[0].getBoundingClientRect().top;
let pageContent = selected[0].closest(".pagedjs_page_content");
let pageContentTop = pageContent.getBoundingClientRect().top;
if(selTop == pageContentTop){
varStart = varFirst;
}else{
varStart = stringPrevPage;
}
else {
cssVar = selected[0].textContent;
}
});
fragment.setAttribute("data-string", `string-type-${this.type}-${name}`);
// fragment.style.setProperty(`--pagedjs-string-${name}`, `"${cssVar.replace(/\\([\s\S])|(["|'])/g, "\\$1$2")}"`);
fragment.style.setProperty(`--pagedjs-string-${name}`, `"${cleanPseudoContent(cssVar)}`);
// if there is no new string on the page
if (!fragment.hasAttribute("data-string")) {
fragment.style.setProperty(`--pagedjs-string-${name}`, `"${this.pageLastString}"`);
}
/* FIRST EXCEPT */
varFirstExcept = "";
}
fragment.style.setProperty(`--pagedjs-string-first-${name}`, `"${cleanPseudoContent(varFirst)}`);
fragment.style.setProperty(`--pagedjs-string-last-${name}`, `"${cleanPseudoContent(varLast)}`);
fragment.style.setProperty(`--pagedjs-string-start-${name}`, `"${cleanPseudoContent(varStart)}`);
fragment.style.setProperty(`--pagedjs-string-first-except-${name}`, `"${cleanPseudoContent(varFirstExcept)}`);
}
}
......