-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa7fbba
commit 1f514e4
Showing
3 changed files
with
21 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,20 +9,24 @@ export async function load() { | |
loadPaintWorklet(), | ||
loadComponents(), | ||
]); | ||
console.log("loaded"); | ||
resolve(undefined); | ||
} | ||
|
||
async function loadComponents() { | ||
const modules = await Promise.all([ | ||
const promises = [ | ||
import("./tester.js"), | ||
import("./drag-area.js"), | ||
import("./control.js"), | ||
import("./corner.js"), | ||
]); | ||
for (const module of modules) { | ||
const { NAME, Component } = module; | ||
customElements.define(NAME, Component); | ||
} | ||
].map((promise) => | ||
promise.then(({ NAME, Component }) => { | ||
console.log(NAME); | ||
customElements.define(NAME, Component); | ||
}), | ||
); | ||
await Promise.all(promises); | ||
console.log("loaded components"); | ||
} | ||
|
||
async function loadPaintWorklet() { | ||
|
@@ -31,6 +35,7 @@ async function loadPaintWorklet() { | |
"https://unpkg.com/[email protected]/index.mjs" | ||
); | ||
register("https://unpkg.com/[email protected]/worklet.min.js"); | ||
console.log("Loaded worklet"); | ||
} | ||
|
||
async function loadSquircleComponent() { | ||
|
@@ -39,4 +44,5 @@ async function loadSquircleComponent() { | |
: import("./squircle-canvas.js"); | ||
const module = await promise; | ||
customElements.define("th-squircle", module.default); | ||
console.log("Loaded squircle"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
import { paint } from "https://unpkg.com/[email protected].6/index.mjs"; | ||
import { paint } from "https://unpkg.com/[email protected].7/index.mjs"; | ||
|
||
export default class SquircleCanvas extends HTMLElement { | ||
/** @type {number} */ | ||
_radius = 0; | ||
/** @type {string} */ | ||
_fill = "transparent"; | ||
/** @type {number} */ | ||
_borderWidth = 0; | ||
/** @type {string} */ | ||
_borderColor = "transparent"; | ||
/** @type {number} */ | ||
_animationFrame = -1; | ||
/** @type {CanvasRenderingContext2D?} */ | ||
_context = null; | ||
|
@@ -132,12 +127,12 @@ export default class SquircleCanvas extends HTMLElement { | |
ctx.reset(); | ||
|
||
if (bc !== "transparent" && bw > 0) { | ||
ctx.fillStyle = this._borderColor; | ||
paint(ctx, 0, 0, w, h, r); | ||
ctx.fillStyle = this._borderColor; | ||
ctx.fill(); | ||
} | ||
|
||
if (fill !== "transparent") { | ||
ctx.fillStyle = fill; | ||
paint( | ||
ctx, | ||
bw, | ||
|
@@ -146,6 +141,8 @@ export default class SquircleCanvas extends HTMLElement { | |
h - bw * 2, | ||
r - this._borderWidth / Math.SQRT2, | ||
); | ||
ctx.fillStyle = fill; | ||
ctx.fill(); | ||
} | ||
} | ||
} |