diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afe41f9..93a851d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,7 @@ jobs: env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} - uses: actions/upload-artifact@v3 + if: ${{ failure() }} with: name: test-screenshots path: shots/ diff --git a/README.md b/README.md index bc6dc4b..647b9ae 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ You can then `require('canvas-confetti');` to use it in your project build. _Not You can also include this library in your HTML page directly from a CDN: ```html - + ``` _Note: you should use the latest version at the time that you include your project. You can see all versions [on the releases page](https://github.com/catdad/canvas-confetti/releases)._ diff --git a/fixtures/debug.html b/fixtures/debug.html new file mode 100644 index 0000000..b4a7bf7 --- /dev/null +++ b/fixtures/debug.html @@ -0,0 +1,204 @@ + + + + + + Debug emoji confetti + + + + + + +

+ +

+ + + + diff --git a/package.json b/package.json index df632ed..5fa14ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "canvas-confetti", - "version": "1.9.1", + "version": "1.9.2", "description": "performant confetti animation in the browser", "main": "src/confetti.js", "module": "dist/confetti.module.mjs", @@ -31,7 +31,7 @@ "babel-eslint": "^8.2.1", "browserify": "^15.2.0", "cross-env": "^5.1.3", - "eslint": "^4.16.0", + "eslint": "^6.8.0", "eslint-plugin-ava": "9.0.0", "jimp": "^0.2.28", "puppeteer": "^19.11.1", @@ -39,7 +39,6 @@ "send": "^0.16.1", "terser": "^3.14.1" }, - "dependencies": {}, "keywords": [ "canvas", "confetti", diff --git a/src/confetti.js b/src/confetti.js index a67a345..d92a11a 100644 --- a/src/confetti.js +++ b/src/confetti.js @@ -808,7 +808,7 @@ scalar = 1, color = '#000000', // see https://nolanlawson.com/2022/04/08/the-struggle-of-using-native-emoji-on-the-web/ - fontFamily = '"Twemoji Mozilla", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "system emoji", sans-serif'; + fontFamily = '"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "Twemoji Mozilla", "system emoji", sans-serif'; if (typeof textData === 'string') { text = textData; @@ -829,15 +829,21 @@ ctx.font = font; var size = ctx.measureText(text); - var width = Math.floor(size.width); - var height = Math.floor(size.fontBoundingBoxAscent + size.fontBoundingBoxDescent); + var width = Math.ceil(size.actualBoundingBoxRight + size.actualBoundingBoxLeft); + var height = Math.ceil(size.actualBoundingBoxAscent + size.actualBoundingBoxDescent); + + var padding = 2; + var x = size.actualBoundingBoxLeft + padding; + var y = size.actualBoundingBoxAscent + padding; + width += padding + padding; + height += padding + padding; canvas = new OffscreenCanvas(width, height); ctx = canvas.getContext('2d'); ctx.font = font; ctx.fillStyle = color; - ctx.fillText(text, 0, fontSize); + ctx.fillText(text, x, y); var scale = 1 / scalar; diff --git a/test/index.test.js b/test/index.test.js index 564b860..9da20ee 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -739,8 +739,8 @@ test('[text] shapeFromText renders an emoji', async t => { ...shape }, { type: 'bitmap', - matrix: [ 0.1, 0, 0, 0.1, -6.25, -5.8500000000000005 ], - hash: '8647FpWTCBH' + matrix: [ 0.1, 0, 0, 0.1, -5.7, -5.550000000000001 ], + hash: 'c4y5z8b83AC' }); });