Skip to content

Commit

Permalink
Fix issues with rollup embedding
Browse files Browse the repository at this point in the history
Turns out that rollup thinks all imports are modules, while
dom-to-image-more predates most of that fun. Fixing the resolution of
global/window/Node so we don't trip up rollup.
Also finally remembered to `npm run format` so things are reformatted.
  • Loading branch information
IDisposable committed Apr 26, 2023
1 parent 12003de commit 51bece8
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 124 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '19.x'
registry-url: 'https://registry.npmjs.org'

- name: Install npm packages
run: npm ci

- name: Build
run: npm run build:ci

- name: Publish NPM package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '19.x'
registry-url: 'https://registry.npmjs.org'

- name: Install npm packages
run: npm ci

- name: Build
run: npm run build:ci

- name: Publish NPM package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"arrowParens": "always",
"endOfLine": "lf",
"tabWidth": 4,
"printWidth": 90
"printWidth": 90,
"proseWrap": "always"
}
189 changes: 111 additions & 78 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/dom-to-image-more.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dom-to-image-more.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dom-to-image-more",
"version": "3.1.5",
"version": "3.1.6",
"description": "Generates an image from a DOM node using HTML5 canvas and SVG",
"main": "dist/dom-to-image-more.min.js",
"devDependencies": {
Expand Down
25 changes: 16 additions & 9 deletions src/dom-to-image-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
const inliner = newInliner();
const fontFaces = newFontFaces();
const images = newImages();
const ELEMENT_NODE = (Node && Node.ELEMENT_NODE) || 1;


// Default impl options
const defaultOptions = {
// Default is to copy default styles of elements
Expand Down Expand Up @@ -47,8 +46,16 @@
}

// support node and browsers
const getComputedStyle = (global && global.getComputedStyle) || (window && window.getComputedStyle) || globalThis.getComputedStyle;
const atob = (global && global.atob) || (window && window.atob) || globalThis.atob;
const ELEMENT_NODE =
(typeof Node !== 'undefined' ? Node.ELEMENT_NODE : undefined) || 1;
const getComputedStyle =
(typeof global !== 'undefined' ? global.getComputedStyle : undefined) ||
(typeof window !== 'undefined' ? window.getComputedStyle : undefined) ||
globalThis.getComputedStyle;
const atob =
(typeof global !== 'undefined' ? global.atob : undefined) ||
(typeof window !== 'undefined' ? window.atob : undefined) ||
globalThis.atob;

/**
* @param {Node} node - The DOM Node object to render
Expand Down Expand Up @@ -1311,7 +1318,9 @@
const charsetToUse = document.characterSet || 'UTF-8';
const docType = document.doctype;
const docTypeDeclaration = docType
? `<!DOCTYPE ${escapeHTML(docType.name)} ${escapeHTML(docType.publicId)} ${escapeHTML(docType.systemId)}`.trim() + '>'
? `<!DOCTYPE ${escapeHTML(docType.name)} ${escapeHTML(
docType.publicId
)} ${escapeHTML(docType.systemId)}`.trim() + '>'
: '';

// Create a hidden sandbox <iframe> element within we can create default HTML elements and query their
Expand Down Expand Up @@ -1356,11 +1365,9 @@

// let's attempt it using srcdoc, so we can still set the doctype and charset
try {
const sandboxDocument =
document.implementation.createHTMLDocument(title);
const sandboxDocument = document.implementation.createHTMLDocument(title);
sandboxDocument.head.appendChild(metaCharset);
const sandboxHTML =
doctype + sandboxDocument.documentElement.outerHTML;
const sandboxHTML = doctype + sandboxDocument.documentElement.outerHTML;
sandbox.setAttribute('srcdoc', sandboxHTML);
return sandbox.contentWindow;
} catch (_) {
Expand Down

0 comments on commit 51bece8

Please sign in to comment.