unprint 0.10.11 → 0.11.0
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 +2 -2
- package/package.json +1 -1
- package/src/app.js +44 -1
- package/tests/index.html +3 -0
- package/tests/init.js +4 -0
package/README.md
CHANGED
|
@@ -24,14 +24,14 @@ For optimal flexibility, unprint query methods can be used with or without initi
|
|
|
24
24
|
Both `unprint.get()` and `unprint.init()` return its `query` methods pre-initialized, removing the element argument in favor of the element retrieved or received. Initialized query methods therefore will *not* accept a custom element, usually expecting the selector as the first argument instead.
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
const result = await unprint.get('http://
|
|
27
|
+
const result = await unprint.get('http://localhost:3101/html');
|
|
28
28
|
const { query } = result.context;
|
|
29
29
|
|
|
30
30
|
query.element('h1#title'); // HTMLHeadingElement
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
|
-
const result = await fetch('http://
|
|
34
|
+
const result = await fetch('http://localhost:3101/html');
|
|
35
35
|
const body = await res.text();
|
|
36
36
|
const { query } = await unprint.init(body);
|
|
37
37
|
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -184,7 +184,11 @@ function queryAttributes(context, selector, attribute, customOptions) {
|
|
|
184
184
|
function queryDataset(context, selector, dataAttribute, customOptions) {
|
|
185
185
|
const target = queryElement(context, selector, customOptions);
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
if (target) {
|
|
188
|
+
return target.dataset[dataAttribute];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return null;
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
function queryDatasets(context, selector, dataAttribute, customOptions) {
|
|
@@ -479,6 +483,43 @@ function querySourceSets(context, selector, attr = 'srcset', customOptions = {})
|
|
|
479
483
|
return sourceSets.map((sourceSet) => extractSourceSet(sourceSet, customOptions));
|
|
480
484
|
}
|
|
481
485
|
|
|
486
|
+
/*
|
|
487
|
+
function removeStyleFunctionSpaces(el) {
|
|
488
|
+
// jsdom appears to have a bug where it ignores inline CSS attributes set to a function() containing spaces, e.g. url( image.png )
|
|
489
|
+
el.setAttribute('style', el.getAttribute('style').replace(/\(\s+(.*)\s+\)/g, (match, cssArgs) => `(${cssArgs})`));
|
|
490
|
+
}
|
|
491
|
+
*/
|
|
492
|
+
|
|
493
|
+
function queryStyle(context, selector, customOptions) {
|
|
494
|
+
const options = {
|
|
495
|
+
...customOptions,
|
|
496
|
+
attribute: 'style',
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
const style = queryContent(context, selector, options);
|
|
500
|
+
|
|
501
|
+
if (style) {
|
|
502
|
+
return options.styleAttribute
|
|
503
|
+
? style.getPropertyValue(options.styleAttribute)
|
|
504
|
+
: style._values;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function queryStyles(context, selector, customOptions) {
|
|
511
|
+
const options = {
|
|
512
|
+
...customOptions,
|
|
513
|
+
attribute: 'style',
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const elStyles = queryContents(context, selector, options).map((style) => (options.styleAttribute
|
|
517
|
+
? style.getPropertyValue(options.styleAttribute)
|
|
518
|
+
: style._values));
|
|
519
|
+
|
|
520
|
+
return elStyles;
|
|
521
|
+
}
|
|
522
|
+
|
|
482
523
|
function queryVideo(context, selector = 'source', customOptions) {
|
|
483
524
|
const options = {
|
|
484
525
|
...context.options,
|
|
@@ -677,6 +718,8 @@ const queryFns = {
|
|
|
677
718
|
imgs: queryImages,
|
|
678
719
|
json: queryJson,
|
|
679
720
|
jsons: queryJsons,
|
|
721
|
+
style: queryStyle,
|
|
722
|
+
styles: queryStyles,
|
|
680
723
|
number: queryNumber,
|
|
681
724
|
num: queryNumber,
|
|
682
725
|
numbers: queryNumbers,
|
package/tests/index.html
CHANGED
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
<img class="srcset" srcset="https://i.redd.it/e91oo4ueyeb71.jpg 240w, https://i.redd.it/vn9h981hlx281.png 480w, https://i.redd.it/e91oo4ueyeb71.jpg 640w">
|
|
43
43
|
<img class="srcset" srcset="https://i.redd.it/e91oo4ueyeb71.jpg 240w, https://i.redd.it/vn9h981hlx281.png 480w, https://i.redd.it/e91oo4ueyeb71.jpg 640w">
|
|
44
44
|
|
|
45
|
+
<div class="style" style="background-image: url('https://i.imgur.com/eDQmLys.jpg'); color: red;"></div>
|
|
46
|
+
<div class="style" style="margin: 1rem; color: blue;"></div>
|
|
47
|
+
|
|
45
48
|
<video id="video" poster="https://i.imgur.com/eDQmLys.jpg"><source src="https://i.imgur.com/eDQmLys.mp4"></video>
|
|
46
49
|
|
|
47
50
|
<script id="json" type="application/js">{"foo": "bar", "lorem": "ipsum", "hello": "world"}</script>
|
package/tests/init.js
CHANGED
|
@@ -37,6 +37,10 @@ async function initTest() {
|
|
|
37
37
|
console.log('images', res.context.query.imgs('.image'));
|
|
38
38
|
console.log('srcset', res.context.query.sourceSet('.srcset'));
|
|
39
39
|
console.log('srcsets', res.context.query.sourceSets('.srcset'));
|
|
40
|
+
console.log('style', res.context.query.style('.style'));
|
|
41
|
+
console.log('style background', res.context.query.style('.style', { styleAttribute: 'background-image' }));
|
|
42
|
+
console.log('styles', res.context.query.styles('.style'));
|
|
43
|
+
console.log('styles color', res.context.query.styles('.style', { styleAttribute: 'color' }));
|
|
40
44
|
console.log('path', res.context.query.url('#path'));
|
|
41
45
|
console.log('relative path', res.context.query.url('#relativePath'));
|
|
42
46
|
console.log('exists', res.context.query.exists('#title'));
|