Commit 0e4e6ec1 authored by Fred Chasen's avatar Fred Chasen

Replace css.escape with querySelectorEscape, version bump to 0.1.20

parent e88d3def
{
"name": "pagedjs",
"version": "0.1.18",
"version": "0.1.19",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -1758,11 +1758,6 @@
"source-map": "^0.5.3"
}
},
"css.escape": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz",
"integrity": "sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s="
},
"cssom": {
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.4.tgz",
......
{
"name": "pagedjs",
"version": "0.1.19",
"version": "0.1.20",
"description": "Chunks up a document into paged media flows and applies print styles",
"author": "Fred Chasen",
"license": "MIT",
......@@ -10,7 +10,6 @@
"browser": "dist/paged.js",
"dependencies": {
"css-tree": "1.0.0-alpha.29",
"css.escape": "^1.5.1",
"event-emitter": "^0.3.5",
"lodash": "^4.17.10"
},
......
import Handler from "../handler";
import { UUID, attr } from "../../utils/utils";
import { UUID, attr, querySelectorEscape } from "../../utils/utils";
import csstree from 'css-tree';
class TargetCounters extends Handler {
......@@ -71,7 +71,7 @@ class TargetCounters extends Handler {
return;
}
let val = attr(selected, target.args);
let element = chunker.pagesArea.querySelector(CSS.escape(val));
let element = chunker.pagesArea.querySelector(querySelectorEscape(val));
if (element) {
let selector = UUID();
......
import Handler from "../handler";
import { UUID, attr } from "../../utils/utils";
import { UUID, attr, querySelectorEscape } from "../../utils/utils";
import csstree from 'css-tree';
class TargetText extends Handler {
......@@ -65,7 +65,7 @@ class TargetText extends Handler {
let queried = fragment.querySelectorAll(query);
queried.forEach((selected, index) => {
let val = attr(selected, target.args);
let element = fragment.querySelector(CSS.escape(val));
let element = fragment.querySelector(querySelectorEscape(val));
if (element) {
if (target.style === "content") {
let text = element.textContent;
......
......@@ -3,8 +3,6 @@ import baseStyles from './base';
import { UUID } from '../utils/utils';
import Hook from "../utils/hook";
import "css.escape"; // polyfill for CSS.escape
class Polisher {
constructor(setup) {
this.sheets = [];
......
......@@ -136,3 +136,87 @@ export function attr(element, attributes) {
}
}
}
/* Based on by https://mths.be/cssescape v1.5.1 by @mathias | MIT license
* Allows # and .
*/
export function querySelectorEscape(value) {
if (arguments.length == 0) {
throw new TypeError('`CSS.escape` requires an argument.');
}
var string = String(value);
var length = string.length;
var index = -1;
var codeUnit;
var result = '';
var firstCodeUnit = string.charCodeAt(0);
while (++index < length) {
codeUnit = string.charCodeAt(index);
console.log("codeUnit", codeUnit, string.charAt(index));
// Note: there’s no need to special-case astral symbols, surrogate
// pairs, or lone surrogates.
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
// (U+FFFD).
if (codeUnit == 0x0000) {
result += '\uFFFD';
continue;
}
if (
// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
// U+007F, […]
(codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
// If the character is the first character and is in the range [0-9]
// (U+0030 to U+0039), […]
(index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
// If the character is the second character and is in the range [0-9]
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
(
index == 1 &&
codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
firstCodeUnit == 0x002D
)
) {
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
result += '\\' + codeUnit.toString(16) + ' ';
continue;
}
if (
// If the character is the first character and is a `-` (U+002D), and
// there is no second character, […]
index == 0 &&
length == 1 &&
codeUnit == 0x002D
) {
result += '\\' + string.charAt(index);
continue;
}
// If the character is not handled by one of the above rules and is
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
// U+005A), or [a-z] (U+0061 to U+007A), […]
if (
codeUnit >= 0x0080 ||
codeUnit == 0x002D ||
codeUnit == 0x005F ||
codeUnit == 35 || // Allow #
codeUnit == 46 || // Allow .
codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
codeUnit >= 0x0041 && codeUnit <= 0x005A ||
codeUnit >= 0x0061 && codeUnit <= 0x007A
) {
// the character itself
result += string.charAt(index);
continue;
}
// Otherwise, the escaped character.
// https://drafts.csswg.org/cssom/#escape-a-character
result += '\\' + string.charAt(index);
}
return result;
}
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