diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ee3376..afe41f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3.8.1 with: - node-version: 12 + node-version: 14 registry-url: https://registry.npmjs.org/ - run: npm install - run: npm run lint @@ -25,3 +25,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request' env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} + - uses: actions/upload-artifact@v3 + with: + name: test-screenshots + path: shots/ diff --git a/README.md b/README.md index 41bb2d9..69ba290 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)._ @@ -72,12 +72,12 @@ The `confetti` parameter is a single optional `options` object, which has the fo - `origin.x` _Number (default: 0.5)_: The `x` position on the page, with `0` being the left edge and `1` being the right edge. - `origin.y` _Number (default: 0.5)_: The `y` position on the page, with `0` being the top edge and `1` being the bottom edge. - `colors` _Array<String>_: An array of color strings, in the HEX format... you know, like `#bada55`. -- `shapes` _Array<String|Shape>_: An array of shapes for the confetti. There are 3 built-in values of `square`, `circle`, and `star`. The default is to use both squares and circles in an even mix. To use a single shape, you can provide just one shape in the array, such as `['star']`. You can also change the mix by providing a value such as `['circle', 'circle', 'square']` to use two third circles and one third squares. You can also create your own shapes using the `confetti.shapeFromPath` helper method. +- `shapes` _Array<String|Shape>_: An array of shapes for the confetti. There are 3 built-in values of `square`, `circle`, and `star`. The default is to use both squares and circles in an even mix. To use a single shape, you can provide just one shape in the array, such as `['star']`. You can also change the mix by providing a value such as `['circle', 'circle', 'square']` to use two third circles and one third squares. You can also create your own shapes using the [`confetti.shapeFromPath`](#confettishapefrompath-path-matrix---shape) or [`confetti.shapeFromText`](#confettishapefromtext-text-scalar-color-fontfamily---shape) helper methods. - `scalar` _Number (default: 1)_: Scale factor for each confetti particle. Use decimals to make the confetti smaller. Go on, try teeny tiny confetti, they are adorable! - `zIndex` _Integer (default: 100)_: The confetti should be on top, after all. But if you have a crazy high page, you can set it even higher. - `disableForReducedMotion` _Boolean (default: false)_: Disables confetti entirely for users that [prefer reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion). The `confetti()` promise will resolve immediately in this case. -### `confetti.shapeFromPath({ path, matrix? })` -> `Shape` +### `confetti.shapeFromPath({ path, matrix? })` → `Shape` This helper method lets you create a custom confetti shape using an [SVG Path string](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d). Any valid path should work, though there are a few caveats: - All paths will be filed. If you were hoping to have a stroke path, that is not implemented. @@ -98,6 +98,31 @@ confetti({ }); ``` +### `confetti.shapeFromText({ text, scalar?, color?, fontFamily? })` → `Shape` + +This is the highly anticipated feature to render emoji confetti! Use any standard unicode emoji. Or other text, but... maybe don't use other text. + +While any text should work, there are some caveats: +- For flailing confetti, something that is mostly square works best. That is, a single character, especially an emoji. +- Rather than rendering text every time a confetti is drawn, this helper actually rasterizes the text. Therefore, it does not scale well after it is created. If you plan to use the `scalar` value to scale your confetti, use the same `scalar` value here when creating the shape. This will make sure the confetti are not blurry. + +The options for this method are: +- `options` _`Object`_: + - `text` _`String`_: the text to be rendered as a confetti. If you can't make up your mind, I suggest "🐈". + - `scalar` _`Number, optional, default: 1`_: a scale value relative to the default size. It matches the `scalar` value in the confetti options. + - `color` _`String, optional, default: #000000`_: the color used to render the text. + - `fontFamily` _`String, optional, default: native emoji`_: the font family name to use when rendering the text. The default follows [best practices for rendring the native OS emoji of the device](https://nolanlawson.com/2022/04/08/the-struggle-of-using-native-emoji-on-the-web/), falling back to `sans-serif`. If using a web font, make sure this [font is loaded](https://developer.mozilla.org/en-US/docs/Web/API/FontFace/load) before rendering your confetti. + +```javascript +var scalar = 2; +var pineapple = confetti.shapeFromText({ text: '🍍', scalar }); + +confetti({ + shapes: [pineapple], + scalar +}); +``` + ### `confetti.create(canvas, [globalOptions])` → `function` This method creates an instance of the `confetti` function that uses a custom canvas. This is useful if you want to limit the area on your page in which confetti appear. By default, this method will not modify the canvas in any way (other than drawing to it). diff --git a/index.html b/index.html index ff16356..ebac7ec 100644 --- a/index.html +++ b/index.html @@ -8,8 +8,9 @@ + -
+ Don't know any custom shapes? That's okay, just use emoji instead! That's what they + are for anyway. I mean... why do they even exist if we weren't supposed to make + confetti out of them? Think about it. +
+