unprint 0.11.9 → 0.11.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/app.js +10 -5
- package/tests/index.html +1 -0
- package/tests/init.js +2 -1
package/README.md
CHANGED
|
@@ -166,6 +166,7 @@ Returns the parsed JSON content of an element as an object.
|
|
|
166
166
|
|
|
167
167
|
Options
|
|
168
168
|
* `styleAttribute`: the CSS style attribute to extract, returns an object with all properties by default.
|
|
169
|
+
* `attemptBugfix`: Attempts to fix/bypass JSDOM quirks related in particular to style attributes containing `url()`, at the risk of losing some surrounding definitions (e.g. `url() 0 0 no-repeat;` may become `url()`. Try disabling this property if you require those definitions; it may break the attribute entirely, though.
|
|
169
170
|
|
|
170
171
|
Returns the CSS style attributes of an element as an object.
|
|
171
172
|
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -479,19 +479,24 @@ function querySourceSets(context, selector, attr = 'srcset', customOptions = {})
|
|
|
479
479
|
|
|
480
480
|
function removeStyleFunctionSpaces(el) {
|
|
481
481
|
// jsdom appears to have a bug where it ignores inline CSS attributes set to a function() containing spaces, e.g. url( image.png )
|
|
482
|
-
el.setAttribute('style', el.getAttribute('style')
|
|
482
|
+
el.setAttribute('style', el.getAttribute('style')
|
|
483
|
+
.replace(/\(\s+(.*)\s+\)/g, (match, cssArgs) => `(${cssArgs})`)
|
|
484
|
+
.replace(/\)[\w\s-]+;/g, ');'));
|
|
483
485
|
}
|
|
484
486
|
|
|
485
487
|
function queryStyle(context, selector, customOptions) {
|
|
486
488
|
const options = {
|
|
487
|
-
...customOptions,
|
|
488
489
|
attribute: 'style',
|
|
490
|
+
attemptBugfix: true,
|
|
491
|
+
...customOptions,
|
|
489
492
|
};
|
|
490
493
|
|
|
491
494
|
const element = queryElement(context, selector, options);
|
|
492
495
|
|
|
493
496
|
if (element) {
|
|
494
|
-
|
|
497
|
+
if (options.attemptBugfix) {
|
|
498
|
+
removeStyleFunctionSpaces(element, options);
|
|
499
|
+
}
|
|
495
500
|
|
|
496
501
|
if (element.style) {
|
|
497
502
|
return options.styleAttribute
|
|
@@ -858,8 +863,8 @@ async function request(url, body, customOptions = {}, method = 'GET') {
|
|
|
858
863
|
...options,
|
|
859
864
|
timeout: options.timeout,
|
|
860
865
|
signal: options.abortSignal,
|
|
861
|
-
httpAgent: new http.Agent({ ...options.agent }),
|
|
862
|
-
httpsAgent: new https.Agent({ ...options.agent }),
|
|
866
|
+
httpAgent: options.httpAgent || new http.Agent({ ...options.agent }),
|
|
867
|
+
httpsAgent: options.httpsAgent || new https.Agent({ ...options.agent }),
|
|
863
868
|
});
|
|
864
869
|
|
|
865
870
|
if (!(res.status >= 200 && res.status < 300)) {
|
package/tests/index.html
CHANGED
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
|
|
45
45
|
<!-- deliberate space in url( ) to test JSDOM's quirky handling of this -->
|
|
46
46
|
<div class="style" style="background-image: url( https://i.imgur.com/eDQmLys.jpg ); color: red;"></div>
|
|
47
|
+
<div class="background" style="background: url(https://i.imgur.com/xFHbuDL.jpeg) 0 0 no-repeat; color: green;"></div>
|
|
47
48
|
<div class="style" style="margin: 1rem; color: blue;"></div>
|
|
48
49
|
|
|
49
50
|
<video id="video" poster="https://i.imgur.com/eDQmLys.jpg"><source src="https://i.imgur.com/eDQmLys.mp4"></video>
|
package/tests/init.js
CHANGED
|
@@ -38,7 +38,8 @@ async function initTest() {
|
|
|
38
38
|
console.log('srcset', res.context.query.sourceSet('.srcset'));
|
|
39
39
|
console.log('srcsets', res.context.query.sourceSets('.srcset'));
|
|
40
40
|
console.log('style', res.context.query.style('.style'));
|
|
41
|
-
console.log('style background', res.context.query.style('.style', { styleAttribute: 'background-image' }));
|
|
41
|
+
console.log('style background-image', res.context.query.style('.style', { styleAttribute: 'background-image' }));
|
|
42
|
+
console.log('style background', res.context.query.style('.background'));
|
|
42
43
|
console.log('styles', res.context.query.styles('.style'));
|
|
43
44
|
console.log('styles color', res.context.query.styles('.style', { styleAttribute: 'color' }));
|
|
44
45
|
console.log('path', res.context.query.url('#path'));
|