Skip to content

Commit 7bb0f91

Browse files
committed
Change custom element name to ce-squircle
1 parent e60c54e commit 7bb0f91

9 files changed

+40
-36
lines changed

README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ magic](https://tim-harding.github.io/squircle/).
99

1010
### CSS
1111

12-
First, register the squircle web worker.
12+
First, register the squircle web worker.
1313

1414
```js
1515
import { register } from "superellipse-squircle";
@@ -19,15 +19,16 @@ register();
1919
Now you can use `paint(squircle)` as a image source in CSS. Usually that will be
2020
`background: paint(squircle);`, in which case you can use the provided
2121
`squircle` class. This includes a fallback to normal rounded rectangles when CSS
22-
Houdini isn't available.
22+
Houdini isn't available.
2323

2424
```html
2525
<div
2626
class="squircle"
2727
style="
2828
--squircle-border-radius: 1rem;
2929
--squircle-background-color: black;"
30-
></div>;
30+
></div>
31+
;
3132
```
3233

3334
These properties control the squircle drawing:
@@ -59,19 +60,19 @@ squircles on all platforms, you can use the web component instead. It will add
5960
an HTML5 `<canvas>` to draw with when the Paint API isn't available.
6061

6162
```js
62-
import { createCustomElement } from 'superellipse-squircle';
63+
import { createCustomElement } from "superellipse-squircle";
6364
createCustomElement();
6465
```
6566

6667
```html
67-
<th-squircle
68+
<ce-squircle
6869
background-color="rgba(64, 128, 192, 0.5)"
6970
border-radius="16"
7071
border-width="4"
7172
border-color="black"
7273
>
7374
Hello, world!
74-
</th-squircle>
75+
</ce-squircle>
7576
```
7677

7778
### Canvas
@@ -86,13 +87,22 @@ import { draw, paint } from "superellipse-squircle";
8687
draw(canvasContext, posX, posY, width, height, borderRadius);
8788

8889
// Draw the squircle with stroke and fill
89-
paint(canvasContext, posX, posY, width, height, borderRadius,
90-
borderWidth, fillColor, borderColor);
90+
paint(
91+
canvasContext,
92+
posX,
93+
posY,
94+
width,
95+
height,
96+
borderRadius,
97+
borderWidth,
98+
fillColor,
99+
borderColor,
100+
);
91101
```
92102

93103
### SVG
94104

95-
You can create a string that is compatible with SVG `path` elements.
105+
You can create a string that is compatible with SVG `path` elements.
96106

97107
```svg
98108
<svg viewBox="0 0 512 512">
@@ -104,6 +114,6 @@ You can create a string that is compatible with SVG `path` elements.
104114
import { path } from "superellipse-squircle";
105115

106116
const d = path(0, 0, 512, 512, myRadius);
107-
const path = document.getElementById('my-path');
117+
const path = document.getElementById("my-path");
108118
path.d = d;
109119
```

index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@
3737
<svg viewBox="0 0 512 256" width="512" height="256">
3838
<path id="squircle-svg" fill="black"></path>
3939
</svg>
40-
<my-squircle
40+
<ce-squircle
4141
background-color="rgb(255, 127, 63)"
4242
border-radius="16"
4343
border-width="4"
4444
border-color="rgb(63, 127, 255)"
45-
></my-squircle>
45+
></ce-squircle>
4646

4747
<script type="module">
4848
import { register, path, createCustomElement } from "@";
4949

5050
register();
51-
createCustomElement("my-squircle");
51+
createCustomElement();
5252

5353
const svg = document.getElementById("squircle-svg");
5454
const d = path(0, 0, 512, 256, 32);

pages/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ <h1>Squircle</h1>
8282
<th-drag-area>
8383
<th-corner side="top-left"></th-corner>
8484
<th-corner side="bottom-right"></th-corner>
85-
<th-squircle></th-squircle>
85+
<ce-squircle></ce-squircle>
8686
</th-drag-area>
8787

8888
<form>

pages/public/style.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ main {
357357
grid-template-areas: "tester";
358358
}
359359

360-
th-squircle {
360+
ce-squircle {
361361
display: grid;
362362
contain: strict;
363363
pointer-events: none;
@@ -387,7 +387,7 @@ th-drag-area {
387387
background-color: var(--mantle);
388388
border: 1px solid var(--crust);
389389

390-
& > th-squircle {
390+
& > ce-squircle {
391391
position: absolute;
392392
}
393393
}

pages/src/drag-area.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class DragArea extends HTMLElement {
3131
this._r = w - SIDE_OFFSET;
3232
this._b = h - SIDE_OFFSET;
3333

34-
this._squircle = this.querySelector("th-squircle");
34+
this._squircle = this.querySelector("ce-squircle");
3535
this._updateSquircleCorners();
3636

3737
const observer = new ResizeObserver((entries) => {

pages/src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ThemeButton } from "pages/theme-button.js";
77

88
function main() {
99
register();
10-
createCustomElement("th-squircle");
10+
createCustomElement();
1111
customElements.define("th-tester", Tester);
1212
customElements.define("th-drag-area", DragArea);
1313
customElements.define("th-control", Control);

pages/src/tester.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Tester extends HTMLElement {
1515
}
1616

1717
connectedCallback() {
18-
this._squircle = this.querySelector("th-squircle");
18+
this._squircle = this.querySelector("ce-squircle");
1919
}
2020

2121
/**

src/index.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,22 @@ export const register = registerInner();
3333
*
3434
* Usage:
3535
* ```js
36-
* // No argument defaults to th-squircle
37-
* createCustomElement('my-squircle')
36+
* createCustomElement()
3837
* ```
3938
* ```html
40-
* <my-squircle
39+
* <ce-squircle
4140
* background-color="#deadbeef"
4241
* border-radius="16"
4342
* border-width="4"
4443
* border-color="#cafebabe"
45-
* ></my-squircle>
44+
* ></ce-squircle>
4645
* ```
47-
*
48-
* @param {string} [name='th-squircle'] HTML element tag
4946
*/
50-
export function createCustomElement(name = "th-squircle") {
51-
if (customElements.get(name)) return;
47+
export function createCustomElement() {
48+
if (customElements.get("ce-squircle")) return;
5249
register();
5350
/* @ts-ignore */
5451
const isPaintSupported = !!CSS.paintWorklet;
5552
const component = isPaintSupported ? SquircleHoudini : SquircleCanvas;
56-
customElements.define(name, component);
53+
customElements.define("ce-squircle", component);
5754
}

src/squircle-canvas.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ export default class SquircleCanvas extends HTMLElement {
2424
const canvas = document.createElement("canvas");
2525
this.appendChild(canvas);
2626

27-
const ctx = canvas.getContext("2d", {
28-
// TODO: Do I need to test support first?
29-
colorSpace: "display-p3",
30-
});
27+
const ctx = canvas.getContext("2d", {});
3128

3229
if (ctx === null) {
3330
console.error("Could not get canvas 2D context");
@@ -50,10 +47,10 @@ export default class SquircleCanvas extends HTMLElement {
5047
this._width = rect.width;
5148
this._height = rect.height;
5249
}
53-
this._width = Math.round(this._width);
54-
this._height = Math.round(this._height);
55-
canvas.width = Math.round(this._width);
56-
canvas.height = Math.round(this._height);
50+
this._width = Math.floor(this._width);
51+
this._height = Math.floor(this._height);
52+
canvas.width = Math.floor(this._width);
53+
canvas.height = Math.floor(this._height);
5754
ctx.scale(devicePixelRatio, devicePixelRatio);
5855
this._draw();
5956
}

0 commit comments

Comments
 (0)