@cocreate/print 1.4.0 → 2.0.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/.github/FUNDING.yml +1 -1
- package/.github/workflows/automated.yml +18 -7
- package/CHANGELOG.md +53 -22
- package/CONTRIBUTING.md +6 -6
- package/CoCreate.config.js +1 -1
- package/README.md +31 -17
- package/demo/index.html +1 -1
- package/docs/index.html +4 -4
- package/package.json +8 -8
- package/src/index.js +231 -153
package/.github/FUNDING.yml
CHANGED
|
@@ -12,16 +12,27 @@ jobs:
|
|
|
12
12
|
- name: Checkout repository
|
|
13
13
|
uses: actions/checkout@v7
|
|
14
14
|
|
|
15
|
-
- name: Sync package.json description to GitHub
|
|
15
|
+
- name: Sync package.json description and keywords to GitHub repository
|
|
16
16
|
env:
|
|
17
|
-
|
|
17
|
+
GH_TOKEN: ${{ secrets.GITHUB }}
|
|
18
18
|
run: |
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if [ ! -f package.json ]; then
|
|
20
|
+
echo "No package.json found; skipping repository metadata sync."
|
|
21
|
+
exit 0
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
DESCRIPTION=$(jq -r '.description // empty' package.json)
|
|
25
|
+
if [ -n "$DESCRIPTION" ]; then
|
|
26
|
+
gh api --method PATCH "repos/${GITHUB_REPOSITORY}" -f description="$DESCRIPTION"
|
|
27
|
+
else
|
|
28
|
+
echo "No package description found; leaving GitHub description unchanged."
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
if jq -e '.keywords | type == "array"' package.json >/dev/null; then
|
|
32
|
+
TOPICS=$(jq -c '.keywords | map(ascii_downcase | gsub("[^a-z0-9-]+"; "-") | gsub("(^-+|-+$)"; "") | .[0:50]) | map(select(length > 0)) | unique | .[0:20]' package.json)
|
|
33
|
+
printf '{"names":%s}' "$TOPICS" | gh api --method PUT -H "Accept: application/vnd.github+json" "repos/${GITHUB_REPOSITORY}/topics" --input -
|
|
23
34
|
else
|
|
24
|
-
echo "No
|
|
35
|
+
echo "No package keywords found; leaving GitHub topics unchanged."
|
|
25
36
|
fi
|
|
26
37
|
|
|
27
38
|
release:
|
package/CHANGELOG.md
CHANGED
|
@@ -1,67 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
# [2.0.0](https://github.com/CoCreateJS/print/compare/v1.2.0...v2.0.0) (2026-11-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### chore
|
|
5
|
+
|
|
6
|
+
* record package identity migration as breaking ([9279540](https://github.com/CoCreateJS/print/commit/92795403acd1c97a8d527aefaab84f6a85220269))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* Consumers must install @cocreate/print and use the renamed CoCreateJS repository identity; the previous package and repository identities are no longer supported.
|
|
12
|
+
|
|
13
|
+
# [1.2.0](https://github.com/CoCreateJS/print/compare/v1.1.2...v1.2.0) (2026-11-02)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* add Deno specific entries to .gitignore ([5327c03](https://github.com/CoCreateJS/print/commit/5327c03ba4de0a0dd02d5f773091dfdd8c387324))
|
|
19
|
+
* bump [@cocreate](https://github.com/cocreate) dependencies ([d0e45de](https://github.com/CoCreateJS/print/commit/d0e45de50ec966f8b6ab8a8330dba784e58763a7))
|
|
20
|
+
* bump [@cocreate](https://github.com/cocreate) package versions ([8815441](https://github.com/CoCreateJS/print/commit/8815441ed28f09f97a94b96d76ab8be8e1bf4a1b))
|
|
21
|
+
* bump versions ([f77e7a5](https://github.com/CoCreateJS/print/commit/f77e7a5e73e151d38a981cec33fe8f8d9c042dcb))
|
|
22
|
+
* bump versions ([d1194f9](https://github.com/CoCreateJS/print/commit/d1194f9a3d97bc8f638620a834629540f05958cc))
|
|
23
|
+
* remove trailing slash from node_modules entry in .gitignore ([41fbdd3](https://github.com/CoCreateJS/print/commit/41fbdd36ce8cd92f88492a8810cd2e53e9138e53))
|
|
24
|
+
* update git url ([121857c](https://github.com/CoCreateJS/print/commit/121857c7ce305db8943479a981028037894196c9))
|
|
25
|
+
* update GitHub Actions to use latest versions and sync package.json description ([6578b9b](https://github.com/CoCreateJS/print/commit/6578b9b85b11160dae18023a14415f799c31b55a))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* replace uuid import and usage with utils ([b3db1b2](https://github.com/CoCreateJS/print/commit/b3db1b2a625c786e2a4c060e79a3c40fdfcf3a1e))
|
|
31
|
+
|
|
32
|
+
## [1.1.2](https://github.com/CoCreateJS/CoCreate-print/compare/v1.1.1...v1.1.2) (2026-07-19)
|
|
2
33
|
|
|
3
34
|
|
|
4
35
|
### Bug Fixes
|
|
5
36
|
|
|
6
|
-
* set default branch to main ([ad5521e](https://github.com/
|
|
37
|
+
* set default branch to main ([ad5521e](https://github.com/CoCreateJS/CoCreate-print/commit/ad5521e9e2f88cba345897634617948db1332793))
|
|
7
38
|
|
|
8
|
-
## [1.1.1](https://github.com/
|
|
39
|
+
## [1.1.1](https://github.com/CoCreateJS/CoCreate-print/compare/v1.1.0...v1.1.1) (2026-07-17)
|
|
9
40
|
|
|
10
41
|
|
|
11
42
|
### Bug Fixes
|
|
12
43
|
|
|
13
|
-
* bump dependencies ([0be97d2](https://github.com/
|
|
44
|
+
* bump dependencies ([0be97d2](https://github.com/CoCreateJS/CoCreate-print/commit/0be97d2bc16657110d988fb2f76a7743160bb002))
|
|
14
45
|
|
|
15
|
-
# [1.1.0](https://github.com/
|
|
46
|
+
# [1.1.0](https://github.com/CoCreateJS/CoCreate-print/compare/v1.0.5...v1.1.0) (2026-07-17)
|
|
16
47
|
|
|
17
48
|
|
|
18
49
|
### Features
|
|
19
50
|
|
|
20
|
-
* update automated workflow and release configuration for improved semantic release handling ([222b9ab](https://github.com/
|
|
51
|
+
* update automated workflow and release configuration for improved semantic release handling ([222b9ab](https://github.com/CoCreateJS/CoCreate-print/commit/222b9ab1fc15e3cfabe020b49ae1c91858d5946d))
|
|
21
52
|
|
|
22
|
-
## [1.0.5](https://github.com/
|
|
53
|
+
## [1.0.5](https://github.com/CoCreateJS/CoCreate-print/compare/v1.0.4...v1.0.5) (2026-07-11)
|
|
23
54
|
|
|
24
55
|
|
|
25
56
|
### Bug Fixes
|
|
26
57
|
|
|
27
|
-
* bump package versions ([43b1d77](https://github.com/
|
|
28
|
-
* removed post install and add add packages to apprved list ([a768b50](https://github.com/
|
|
29
|
-
* semantic version handling ([57fa6a6](https://github.com/
|
|
58
|
+
* bump package versions ([43b1d77](https://github.com/CoCreateJS/CoCreate-print/commit/43b1d7747fade6f3741b329813cf5914581027d3))
|
|
59
|
+
* removed post install and add add packages to apprved list ([a768b50](https://github.com/CoCreateJS/CoCreate-print/commit/a768b50298b84b24d3ade3d0ba68b4eedc8ca6ea))
|
|
60
|
+
* semantic version handling ([57fa6a6](https://github.com/CoCreateJS/CoCreate-print/commit/57fa6a6635d86af3339788b2eb0d4bc837569ddc))
|
|
30
61
|
|
|
31
|
-
## [1.0.4](https://github.com/
|
|
62
|
+
## [1.0.4](https://github.com/CoCreateJS/CoCreate-print/compare/v1.0.3...v1.0.4) (2026-02-04)
|
|
32
63
|
|
|
33
64
|
|
|
34
65
|
### Bug Fixes
|
|
35
66
|
|
|
36
|
-
* update worklow ([b936bf9](https://github.com/
|
|
67
|
+
* update worklow ([b936bf9](https://github.com/CoCreateJS/CoCreate-print/commit/b936bf926d3691a8630a59a35553f1255404e451))
|
|
37
68
|
|
|
38
|
-
## [1.0.3](https://github.com/
|
|
69
|
+
## [1.0.3](https://github.com/CoCreateJS/CoCreate-print/compare/v1.0.2...v1.0.3) (2025-05-01)
|
|
39
70
|
|
|
40
71
|
|
|
41
72
|
### Bug Fixes
|
|
42
73
|
|
|
43
|
-
* added css-loader ([5dbcad6](https://github.com/
|
|
44
|
-
* update [@cocreate](https://github.com/cocreate) dependencies ([680c5ea](https://github.com/
|
|
45
|
-
* update query attributes ([c81e808](https://github.com/
|
|
46
|
-
* webpack.config and devdependencies ([0a7072b](https://github.com/
|
|
74
|
+
* added css-loader ([5dbcad6](https://github.com/CoCreateJS/CoCreate-print/commit/5dbcad68fe262c6a270ebc7904b805735a1d3e68))
|
|
75
|
+
* update [@cocreate](https://github.com/cocreate) dependencies ([680c5ea](https://github.com/CoCreateJS/CoCreate-print/commit/680c5ea73f378ed8d862279ba7d5900b6011914b))
|
|
76
|
+
* update query attributes ([c81e808](https://github.com/CoCreateJS/CoCreate-print/commit/c81e8081a718e5725f34b5f82ea34dbc0b01c412))
|
|
77
|
+
* webpack.config and devdependencies ([0a7072b](https://github.com/CoCreateJS/CoCreate-print/commit/0a7072b0dfb21a962fa9e4d333dbba91befcb257))
|
|
47
78
|
|
|
48
|
-
## [1.0.2](https://github.com/
|
|
79
|
+
## [1.0.2](https://github.com/CoCreateJS/CoCreate-print/compare/v1.0.1...v1.0.2) (2024-12-14)
|
|
49
80
|
|
|
50
81
|
|
|
51
82
|
### Bug Fixes
|
|
52
83
|
|
|
53
|
-
* dispatch printed event ([1acdb66](https://github.com/
|
|
84
|
+
* dispatch printed event ([1acdb66](https://github.com/CoCreateJS/CoCreate-print/commit/1acdb66d9f7988fd5494a0f035c5227e1ba7d831))
|
|
54
85
|
|
|
55
|
-
## [1.0.1](https://github.com/
|
|
86
|
+
## [1.0.1](https://github.com/CoCreateJS/CoCreate-print/compare/v1.0.0...v1.0.1) (2024-12-14)
|
|
56
87
|
|
|
57
88
|
|
|
58
89
|
### Bug Fixes
|
|
59
90
|
|
|
60
|
-
* use iframe to show print dialog only ([a6e3a6d](https://github.com/
|
|
91
|
+
* use iframe to show print dialog only ([a6e3a6d](https://github.com/CoCreateJS/CoCreate-print/commit/a6e3a6d9526654ba64d0c5d89b76701dde352bec))
|
|
61
92
|
|
|
62
93
|
# 1.0.0 (2024-12-14)
|
|
63
94
|
|
|
64
95
|
|
|
65
96
|
### Features
|
|
66
97
|
|
|
67
|
-
* Intial release ([1fbd56c](https://github.com/
|
|
98
|
+
* Intial release ([1fbd56c](https://github.com/CoCreateJS/CoCreate-print/commit/1fbd56cfeabdc62a4483c46a981f1174b43c9549))
|
package/CONTRIBUTING.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# Contributing to CoCreate-print
|
|
2
2
|
|
|
3
|
-
This project is work of [many contributors](https://github.com/
|
|
4
|
-
You're encouraged to submit [pull requests](https://github.com/
|
|
5
|
-
[propose features and discuss issues](https://github.com/
|
|
3
|
+
This project is work of [many contributors](https://github.com/CoCreateJS/print/graphs/contributors).
|
|
4
|
+
You're encouraged to submit [pull requests](https://github.com/CoCreateJS/print/pulls),
|
|
5
|
+
[propose features and discuss issues](https://github.com/CoCreateJS/print/issues).
|
|
6
6
|
|
|
7
7
|
In the examples below, substitute your Github username for `contributor` in URLs.
|
|
8
8
|
|
|
9
9
|
## Fork the Project
|
|
10
10
|
|
|
11
|
-
Fork the [project on Github](https://github.com/
|
|
11
|
+
Fork the [project on Github](https://github.com/CoCreateJS/print) and check out your copy.
|
|
12
12
|
|
|
13
13
|
```
|
|
14
14
|
git clone https://github.com/contributor/CoCreate-print.git
|
|
15
15
|
cd CoCreate-print
|
|
16
|
-
git remote add upstream https://github.com/
|
|
16
|
+
git remote add upstream https://github.com/CoCreateJS/print.git
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Create a Topic Branch
|
|
@@ -74,7 +74,7 @@ git push origin my-feature-branch
|
|
|
74
74
|
|
|
75
75
|
## Make a Pull Request
|
|
76
76
|
|
|
77
|
-
Go to [https://github.com/
|
|
77
|
+
Go to [https://github.com/CoCreateJS/print](https://github.com/CoCreateJS/print) and select your feature branch.
|
|
78
78
|
Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
|
79
79
|
|
|
80
80
|
## Rebase
|
package/CoCreate.config.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = {
|
|
|
10
10
|
name: "index.html",
|
|
11
11
|
path: "/docs/print/index.html",
|
|
12
12
|
src: "{{./docs/index.html}}",
|
|
13
|
-
host: ["
|
|
13
|
+
host: ["CoCreateJS.com", "general.CoCreateJS.com"],
|
|
14
14
|
directory: "print",
|
|
15
15
|
"content-type": "{{content-type}}",
|
|
16
16
|
public: "true"
|
package/README.md
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
# CoCreate-print
|
|
2
2
|
|
|
3
|
-
Highlights syntax within a textarea. Easily configured using HTML5 attributes and/or JavaScript API. Take it for a spin in our [playground!](https://
|
|
3
|
+
Highlights syntax within a textarea. Easily configured using HTML5 attributes and/or JavaScript API. Take it for a spin in our [playground!](https://CoCreateJS.com/docs/print)
|
|
4
4
|
|
|
5
|
-

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
10
|

|
|
11
11
|
|
|
12
|
-

|
|
13
13
|
|
|
14
|
-
## [Docs & Demo](https://
|
|
14
|
+
## [Docs & Demo](https://CoCreateJS.com/docs/print)
|
|
15
15
|
|
|
16
|
-
For a complete guide and working demo refer to the [doumentation](https://
|
|
16
|
+
For a complete guide and working demo refer to the [doumentation](https://CoCreateJS.com/docs/print)
|
|
17
17
|
|
|
18
18
|
## CDN
|
|
19
19
|
|
|
20
20
|
```html
|
|
21
|
-
<script src="https://cdn.
|
|
21
|
+
<script src="https://cdn.CoCreateJS.com/print/latest/CoCreate-print.min.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
```html
|
|
25
|
-
<script src="https://cdn.
|
|
25
|
+
<script src="https://cdn.CoCreateJS.com/print/latest/CoCreate-print.min.css"></script>
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## NPM
|
|
@@ -50,13 +50,13 @@ $ yarn install @cocreate/print
|
|
|
50
50
|
|
|
51
51
|
# Announcements
|
|
52
52
|
|
|
53
|
-
All updates to this library are documented in our [CHANGELOG](https://github.com/
|
|
53
|
+
All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreateJS/print/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreateJS/print/releases). You may also subscribe to email for releases and breaking changes.
|
|
54
54
|
|
|
55
55
|
<a name="roadmap"></a>
|
|
56
56
|
|
|
57
57
|
# Roadmap
|
|
58
58
|
|
|
59
|
-
If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/
|
|
59
|
+
If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreateJS/print/issues) and [pull requests](https://github.com/CoCreateJS/print/pulls). We would love to hear your feedback.
|
|
60
60
|
|
|
61
61
|
<a name="about"></a>
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ If you are interested in the future direction of this project, please take a loo
|
|
|
64
64
|
|
|
65
65
|
CoCreate-print is guided and supported by the CoCreate Developer Experience Team.
|
|
66
66
|
|
|
67
|
-
Please Email the Developer Experience Team [here](mailto:develop@
|
|
67
|
+
Please Email the Developer Experience Team [here](mailto:develop@CoCreateJS.com) in case of any queries.
|
|
68
68
|
|
|
69
69
|
CoCreate-print is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.
|
|
70
70
|
|
|
@@ -72,12 +72,26 @@ CoCreate-print is maintained and funded by CoCreate. The names and logos for CoC
|
|
|
72
72
|
|
|
73
73
|
# How to Contribute
|
|
74
74
|
|
|
75
|
-
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/
|
|
75
|
+
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreateJS/print/blob/master/CONTRIBUTING.md) guide for details.
|
|
76
76
|
|
|
77
|
-
We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/
|
|
77
|
+
We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/CoCreateJS/print/issues) and [pull requests](https://github.com/CoCreateJS/print/pulls) or merely upvote or comment on existing issues or pull requests.
|
|
78
78
|
|
|
79
79
|
We appreciate your continued support, thank you!
|
|
80
80
|
|
|
81
|
+
## Print actions
|
|
82
|
+
|
|
83
|
+
Use `actions="print"` with `print-query` to print selected elements. Without an
|
|
84
|
+
`actions` attribute, `print-query` also works as a standalone click control.
|
|
85
|
+
Repeated initialization does not attach duplicate click handlers.
|
|
86
|
+
|
|
87
|
+
Printing copies current input, checkbox, textarea, and select values into an
|
|
88
|
+
isolated iframe, loads the page styles and images, and expands scroll containers
|
|
89
|
+
without changing the live view. The `printed` event is emitted from the trigger
|
|
90
|
+
and bubbles after the browser's print dialog closes (`afterprint`); it does not
|
|
91
|
+
indicate that the user actually printed rather than cancelled. Action chains
|
|
92
|
+
continue at that point. Failures emit `printError` and abort the chain. The print
|
|
93
|
+
iframe is removed on completion or failure.
|
|
94
|
+
|
|
81
95
|
# License
|
|
82
96
|
|
|
83
|
-
[The MIT License (MIT)](https://github.com/
|
|
97
|
+
[The MIT License (MIT)](https://github.com/CoCreateJS/print/blob/master/LICENSE)
|
package/demo/index.html
CHANGED
|
@@ -37,6 +37,6 @@ test</textarea
|
|
|
37
37
|
|
|
38
38
|
<!-- <script src="../dist/CoCreate-print.js"></script> -->
|
|
39
39
|
<script src="../../../CoCreateJS/dist/CoCreate.js"></script>
|
|
40
|
-
<!-- <script src="https://
|
|
40
|
+
<!-- <script src="https://CoCreateJS.com/dist/CoCreate.js"></script> -->
|
|
41
41
|
</body>
|
|
42
42
|
</html>
|
package/docs/index.html
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
rel="icon"
|
|
10
10
|
type="image/png"
|
|
11
11
|
sizes="32x32"
|
|
12
|
-
href="https://
|
|
12
|
+
href="https://CoCreateJS.com/images/favicon.ico" />
|
|
13
13
|
<meta
|
|
14
14
|
name="description"
|
|
15
15
|
content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
share-width="500"
|
|
37
37
|
share-media="https://via.placeholder.com/300/09f/fff.png">
|
|
38
38
|
<a
|
|
39
|
-
href="https://github.com/
|
|
39
|
+
href="https://github.com/CoCreateJS/CoCreate-print"
|
|
40
40
|
target="_blank"
|
|
41
41
|
class="margin-right:15px"
|
|
42
42
|
><i src="/assets/svg/github.svg"></i
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
<pre
|
|
81
81
|
class="margin-top:15px"><code class="language-javascript">npm install cocreate-print</code></pre>
|
|
82
82
|
<p class="padding:10px_0px">Or you can use cdn link:</p>
|
|
83
|
-
<pre><code class="language-javascript">https://cdn.
|
|
83
|
+
<pre><code class="language-javascript">https://cdn.CoCreateJS.com/js/CoCreate-print.min.js</code></pre>
|
|
84
84
|
|
|
85
85
|
<h2
|
|
86
86
|
class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
|
|
@@ -225,6 +225,6 @@
|
|
|
225
225
|
</div>
|
|
226
226
|
|
|
227
227
|
<!--CoCreateJS-->
|
|
228
|
-
<script src="https://
|
|
228
|
+
<script src="https://CoCreateJS.com/dist/CoCreate.js"></script>
|
|
229
229
|
</body>
|
|
230
230
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/print",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A simple print component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"print",
|
|
@@ -22,27 +22,27 @@
|
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/
|
|
25
|
+
"url": "git+https://github.com/CoCreateJS/print.git"
|
|
26
26
|
},
|
|
27
27
|
"author": "CoCreate LLC",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/CoCreateJS/print/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://
|
|
32
|
+
"homepage": "https://CoCreateJS.com/docs/print",
|
|
33
33
|
"funding": {
|
|
34
34
|
"type": "GitHub Sponsors ❤",
|
|
35
|
-
"url": "https://github.com/sponsors/
|
|
35
|
+
"url": "https://github.com/sponsors/CoCreateJS"
|
|
36
36
|
},
|
|
37
37
|
"main": "./src/index.js",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@cocreate/actions": "^1.24.0",
|
|
40
40
|
"@cocreate/element-prototype": "^1.35.0",
|
|
41
|
-
"@cocreate/observer": "^1.
|
|
42
|
-
"@cocreate/utils": "^1.
|
|
41
|
+
"@cocreate/observer": "^1.23.0",
|
|
42
|
+
"@cocreate/utils": "^1.54.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@cocreate/webpack": "^1.
|
|
45
|
+
"@cocreate/webpack": "^1.9.0"
|
|
46
46
|
},
|
|
47
47
|
"allowScripts": {
|
|
48
48
|
"@cocreate/actions@1.21.4": true,
|
package/src/index.js
CHANGED
|
@@ -1,153 +1,231 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (C) 2020 CoCreate LLC and others.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* SPDX-License-Identifier: MIT
|
|
6
|
-
********************************************************************************/
|
|
7
|
-
|
|
8
|
-
import "@cocreate/element-prototype";
|
|
9
|
-
import { queryElements } from "@cocreate/utils";
|
|
10
|
-
import Actions from "@cocreate/actions";
|
|
11
|
-
import Observer from "@cocreate/observer";
|
|
12
|
-
|
|
13
|
-
const selector = "[print-query]";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2020 CoCreate LLC and others.
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
********************************************************************************/
|
|
7
|
+
|
|
8
|
+
import "@cocreate/element-prototype";
|
|
9
|
+
import { queryElements } from "@cocreate/utils";
|
|
10
|
+
import Actions from "@cocreate/actions";
|
|
11
|
+
import Observer from "@cocreate/observer";
|
|
12
|
+
|
|
13
|
+
const selector = "[print-query]";
|
|
14
|
+
const initialized = new WeakSet();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
* @environment client
|
|
20
|
+
*/
|
|
21
|
+
function init(element) {
|
|
22
|
+
const elements = !element ? document.querySelectorAll(selector)
|
|
23
|
+
: element instanceof Element ? [element] : element;
|
|
24
|
+
for (const target of elements) {
|
|
25
|
+
if (!target.matches(selector) || initialized.has(target)) continue;
|
|
26
|
+
initialized.add(target);
|
|
27
|
+
target.addEventListener("click", () => {
|
|
28
|
+
if (target.hasAttribute("actions")) return;
|
|
29
|
+
runPrint({ element: target });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function cloneForPrint(target) {
|
|
35
|
+
const clone = target.cloneNode(true);
|
|
36
|
+
const originals = [target, ...target.querySelectorAll("*")];
|
|
37
|
+
const copies = [clone, ...clone.querySelectorAll("*")];
|
|
38
|
+
originals.forEach((original, index) => {
|
|
39
|
+
const copy = copies[index];
|
|
40
|
+
const style = getComputedStyle(original);
|
|
41
|
+
// Unclip scrollable layouts without showing intentionally hidden content.
|
|
42
|
+
if (/(auto|scroll|hidden|clip)/.test(`${style.overflowX} ${style.overflowY}`)) {
|
|
43
|
+
for (const [name, value] of Object.entries({ overflow: "visible", height: "auto", "max-height": "none", "min-height": "0" }))
|
|
44
|
+
copy.style.setProperty(name, value, "important");
|
|
45
|
+
}
|
|
46
|
+
if (style.position === "sticky") copy.style.setProperty("position", "static", "important");
|
|
47
|
+
if (original.matches("input")) {
|
|
48
|
+
if (original.type !== "file") copy.setAttribute("value", original.value);
|
|
49
|
+
copy.toggleAttribute("checked", original.checked);
|
|
50
|
+
copy.indeterminate = original.indeterminate;
|
|
51
|
+
} else if (original.matches("textarea")) copy.textContent = original.value;
|
|
52
|
+
else if (original.matches("option")) copy.toggleAttribute("selected", original.selected);
|
|
53
|
+
for (const attribute of [...copy.attributes]) {
|
|
54
|
+
if (attribute.name.startsWith("on")) copy.removeAttribute(attribute.name);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const style = getComputedStyle(target);
|
|
58
|
+
for (const property of style) {
|
|
59
|
+
if (property.startsWith("--")) clone.style.setProperty(property, style.getPropertyValue(property));
|
|
60
|
+
}
|
|
61
|
+
clone.querySelectorAll("script, iframe, object, embed, .simplebar-track, .simplebar-placeholder").forEach(node => node.remove());
|
|
62
|
+
return clone;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
* @environment client
|
|
69
|
+
*/
|
|
70
|
+
async function print(elements) {
|
|
71
|
+
if (!elements) return;
|
|
72
|
+
const targets = elements instanceof Element ? [elements] : Array.from(elements);
|
|
73
|
+
if (!targets.length) return;
|
|
74
|
+
const iframe = document.createElement("iframe");
|
|
75
|
+
iframe.title = "Print preview";
|
|
76
|
+
iframe.setAttribute("aria-hidden", "true");
|
|
77
|
+
iframe.style.cssText = "position:fixed;left:-10000px;top:0;width:1000px;height:800px;border:0";
|
|
78
|
+
document.body.appendChild(iframe);
|
|
79
|
+
const frame = iframe.contentWindow;
|
|
80
|
+
const doc = iframe.contentDocument;
|
|
81
|
+
try {
|
|
82
|
+
doc.open();
|
|
83
|
+
doc.write("<!doctype html><html><head><title>Print</title></head><body></body></html>");
|
|
84
|
+
doc.close();
|
|
85
|
+
for (const attribute of document.documentElement.attributes)
|
|
86
|
+
doc.documentElement.setAttribute(attribute.name, attribute.value);
|
|
87
|
+
for (const attribute of document.body.attributes)
|
|
88
|
+
doc.body.setAttribute(attribute.name, attribute.value);
|
|
89
|
+
const base = doc.createElement("base");
|
|
90
|
+
base.href = document.baseURI;
|
|
91
|
+
doc.head.appendChild(base);
|
|
92
|
+
const loading = [];
|
|
93
|
+
for (const sheet of document.querySelectorAll('style, link[rel="stylesheet"]')) {
|
|
94
|
+
const copy = sheet.cloneNode(true);
|
|
95
|
+
if (copy.tagName === "LINK") {
|
|
96
|
+
loading.push(new Promise(resolve => {
|
|
97
|
+
copy.addEventListener("load", resolve, { once: true });
|
|
98
|
+
copy.addEventListener("error", resolve, { once: true });
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
doc.head.appendChild(copy);
|
|
102
|
+
}
|
|
103
|
+
const styles = doc.createElement("style");
|
|
104
|
+
styles.textContent = `
|
|
105
|
+
html, body { height: auto !important; overflow: visible !important; }
|
|
106
|
+
.simplebar-wrapper, .simplebar-mask, .simplebar-offset,
|
|
107
|
+
.simplebar-content-wrapper, .simplebar-content {
|
|
108
|
+
position: static !important; overflow: visible !important;
|
|
109
|
+
height: auto !important; max-height: none !important;
|
|
110
|
+
width: auto !important; margin: 0 !important; transform: none !important;
|
|
111
|
+
}
|
|
112
|
+
thead { display: table-header-group; }
|
|
113
|
+
tr, img { break-inside: avoid; }
|
|
114
|
+
`;
|
|
115
|
+
doc.head.appendChild(styles);
|
|
116
|
+
for (const target of targets) doc.body.appendChild(doc.adoptNode(cloneForPrint(target)));
|
|
117
|
+
for (const img of doc.images) {
|
|
118
|
+
img.loading = "eager";
|
|
119
|
+
if (!img.complete) loading.push(new Promise(resolve => {
|
|
120
|
+
img.addEventListener("load", resolve, { once: true });
|
|
121
|
+
img.addEventListener("error", resolve, { once: true });
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
await Promise.all(loading);
|
|
125
|
+
if (doc.fonts?.ready) await doc.fonts.ready;
|
|
126
|
+
await new Promise(resolve => frame.requestAnimationFrame(() => frame.requestAnimationFrame(resolve)));
|
|
127
|
+
await new Promise((resolve, reject) => {
|
|
128
|
+
frame.addEventListener("afterprint", resolve, { once: true });
|
|
129
|
+
try { frame.focus(); frame.print(); } catch (error) { reject(error); }
|
|
130
|
+
});
|
|
131
|
+
} finally {
|
|
132
|
+
iframe.remove();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function runPrint(action) {
|
|
137
|
+
try {
|
|
138
|
+
const elements = action.element.hasAttribute("print-query")
|
|
139
|
+
? queryElements({ element: action.element, prefix: "print" }) : [action.element];
|
|
140
|
+
await print(elements);
|
|
141
|
+
if (action.end) action.end();
|
|
142
|
+
else action.element.dispatchEvent(new CustomEvent("printed", { bubbles: true }));
|
|
143
|
+
} catch (error) {
|
|
144
|
+
action.abort?.();
|
|
145
|
+
action.element.dispatchEvent(new CustomEvent("printError", { bubbles: true, detail: { error } }));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
init();
|
|
150
|
+
Actions.init([{ name: "print", endEvent: "printed", callback: runPrint }]);
|
|
151
|
+
Observer.init({
|
|
152
|
+
name: "CoCreatePrintAddedNodes", types: ["addedNodes"], selector,
|
|
153
|
+
callback: mutation => init(mutation.target)
|
|
154
|
+
});
|
|
155
|
+
Observer.init({
|
|
156
|
+
name: "CoCreatePrintObserver", types: ["attributes"], attributeFilter: ["print-query"], selector,
|
|
157
|
+
callback: mutation => init(mutation.target)
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
export default { init, print };
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
* @name actions
|
|
165
|
+
* @kind member
|
|
166
|
+
* @attribute
|
|
167
|
+
* @environment client
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
*
|
|
172
|
+
* @name aria-hidden
|
|
173
|
+
* @kind member
|
|
174
|
+
* @attribute
|
|
175
|
+
* @environment client
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
*
|
|
180
|
+
* @name print-query
|
|
181
|
+
* @kind member
|
|
182
|
+
* @attribute
|
|
183
|
+
* @environment client
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @name value
|
|
189
|
+
* @kind member
|
|
190
|
+
* @attribute
|
|
191
|
+
* @environment client
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A simple print component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.
|
|
196
|
+
*
|
|
197
|
+
* @module print
|
|
198
|
+
* @environment client
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Declarative selectors recognized by this module.
|
|
203
|
+
*
|
|
204
|
+
* @name declarative-selectors
|
|
205
|
+
* @kind member
|
|
206
|
+
* @selectors
|
|
207
|
+
* @environment client
|
|
208
|
+
* @example
|
|
209
|
+
* ```json
|
|
210
|
+
* [
|
|
211
|
+
* "[print-query]"
|
|
212
|
+
* ]
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Declarative actions supported or registered by this module.
|
|
218
|
+
*
|
|
219
|
+
* @name declarative-actions
|
|
220
|
+
* @kind member
|
|
221
|
+
* @actions
|
|
222
|
+
* @environment client
|
|
223
|
+
* @example
|
|
224
|
+
* ```json
|
|
225
|
+
* [
|
|
226
|
+
* {
|
|
227
|
+
* "name": "print"
|
|
228
|
+
* }
|
|
229
|
+
* ]
|
|
230
|
+
* ```
|
|
231
|
+
*/
|