From 30dbfa728df23d60775eb8645af5a93ff9b992e2 Mon Sep 17 00:00:00 2001 From: Cahil Foley Date: Thu, 20 Jan 2022 09:30:15 +0800 Subject: [PATCH] fix(Types): Remove labeled tuple elements This was causing TS problems in client apps. fix #33 --- lib/Snowflake.d.ts | 6 +++--- lib/Snowflake.js.map | 2 +- src/Snowflake.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Snowflake.d.ts b/lib/Snowflake.d.ts index a7f914c..061f6c4 100644 --- a/lib/Snowflake.d.ts +++ b/lib/Snowflake.d.ts @@ -7,7 +7,7 @@ export interface SnowflakeProps { * * The default value is `[0.5, 3.0]`. */ - radius: [minimumRadius: number, maximumRadius: number]; + radius: [number, number]; /** * The minimum and maximum speed of the snowflake. * @@ -18,7 +18,7 @@ export interface SnowflakeProps { * * The default value is `[1.0, 3.0]`. */ - speed: [minimumSpeed: number, maximumSpeed: number]; + speed: [number, number]; /** * The minimum and maximum wind of the snowflake. * @@ -29,7 +29,7 @@ export interface SnowflakeProps { * * The default value is `[-0.5, 2.0]`. */ - wind: [minimumWind: number, maximumWind: number]; + wind: [number, number]; /** * The frequency in frames that the wind and speed values * will update. diff --git a/lib/Snowflake.js.map b/lib/Snowflake.js.map index e49175b..a6e69e3 100644 --- a/lib/Snowflake.js.map +++ b/lib/Snowflake.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/Snowflake.ts"],"names":["defaultConfig","color","radius","speed","wind","changeFrequency","Snowflake","canvas","config","updateConfig","params","x","offsetWidth","y","offsetHeight","random","nextSpeed","nextWind","framesSinceLastUpdate","framesPassed","updateTargetParams","ctx","beginPath","arc","Math","PI","fillStyle","closePath","fill"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CO,IAAMA,aAA6B,GAAG;AAC3CC,EAAAA,KAAK,EAAE,SADoC;AAE3CC,EAAAA,MAAM,EAAE,CAAC,GAAD,EAAM,GAAN,CAFmC;AAG3CC,EAAAA,K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;eAGYtB,S","sourcesContent":["import { lerp, random } from './utils'\r\n\r\nexport interface SnowflakeProps {\r\n /** The color of the snowflake, can be any valid CSS color. */\r\n color: string\r\n /**\r\n * The minimum and maximum radius of the snowflake, will be\r\n * randomly selected within this range.\r\n *\r\n * The default value is `[0.5, 3.0]`.\r\n */\r\n radius: [minimumRadius: number, maximumRadius: number]\r\n /**\r\n * The minimum and maximum speed of the snowflake.\r\n *\r\n * The speed determines how quickly the snowflake moves\r\n * along the y axis (vertical speed).\r\n *\r\n * The values will be randomly selected within this range.\r\n *\r\n * The default value is `[1.0, 3.0]`.\r\n */\r\n speed: [minimumSpeed: number, maximumSpeed: number]\r\n /**\r\n * The minimum and maximum wind of the snowflake.\r\n *\r\n * The wind determines how quickly the snowflake moves\r\n * along the x axis (horizontal speed).\r\n *\r\n * The values will be randomly selected within this range.\r\n *\r\n * The default value is `[-0.5, 2.0]`.\r\n */\r\n wind: [minimumWind: number, maximumWind: number]\r\n /**\r\n * The frequency in frames that the wind and speed values\r\n * will update.\r\n *\r\n * The default value is 200.\r\n */\r\n changeFrequency: number\r\n}\r\n\r\nexport type SnowflakeConfig = Partial\r\n\r\nexport const defaultConfig: SnowflakeProps = {\r\n color: '#dee4fd',\r\n radius: [0.5, 3.0],\r\n speed: [1.0, 3.0],\r\n wind: [-0.5, 2.0],\r\n changeFrequency: 200,\r\n}\r\n\r\ninterface SnowflakeParams {\r\n x: number\r\n y: number\r\n radius: number\r\n speed: number\r\n wind: number\r\n nextSpeed: number\r\n nextWind: number\r\n}\r\n\r\n/**\r\n * An individual snowflake that will update it's location every call to `update`\r\n * and draw itself to the canvas every call to `draw`.\r\n */\r\nclass Snowflake {\r\n private config!: SnowflakeProps\r\n private params: SnowflakeParams\r\n private framesSinceLastUpdate: number\r\n\r\n public constructor(canvas: HTMLCanvasElement, config: SnowflakeConfig = {}) {\r\n // Set custom config\r\n this.updateConfig(config)\r\n\r\n // Setting initial parameters\r\n const { radius, wind, speed } = this.config\r\n\r\n this.params = {\r\n x: random(0, canvas.offsetWidth),\r\n y: random(-canvas.offsetHeight, 0),\r\n radius: random(...radius),\r\n speed: random(...speed),\r\n wind: random(...wind),\r\n nextSpeed: random(...wind),\r\n nextWind: random(...speed),\r\n }\r\n\r\n this.framesSinceLastUpdate = 0\r\n }\r\n\r\n public updateConfig(config: SnowflakeConfig): void {\r\n this.config = { ...defaultConfig, ...config }\r\n }\r\n\r\n private updateTargetParams(): void {\r\n this.params.nextSpeed = random(...this.config.speed)\r\n this.params.nextWind = random(...this.config.wind)\r\n }\r\n\r\n public update(canvas: HTMLCanvasElement, framesPassed = 1): void {\r\n const { x, y, wind, speed, nextWind, nextSpeed } = this.params\r\n\r\n // Update current location, wrapping around if going off the canvas\r\n this.params.x = (x + wind * framesPassed) % canvas.offsetWidth\r\n this.params.y = (y + speed * framesPassed) % canvas.offsetHeight\r\n\r\n // Update the wind and speed towards the desired values\r\n this.params.speed = lerp(speed, nextSpeed, 0.01)\r\n this.params.wind = lerp(wind, nextWind, 0.01)\r\n\r\n if (this.framesSinceLastUpdate++ > this.config.changeFrequency) {\r\n this.updateTargetParams()\r\n this.framesSinceLastUpdate = 0\r\n }\r\n }\r\n\r\n public draw(ctx: CanvasRenderingContext2D): void {\r\n ctx.beginPath()\r\n ctx.arc(this.params.x, this.params.y, this.params.radius, 0, 2 * Math.PI)\r\n ctx.fillStyle = this.config.color\r\n ctx.closePath()\r\n ctx.fill()\r\n }\r\n}\r\n\r\nexport default Snowflake\r\n"],"file":"Snowflake.js"} \ No newline at end of file +{"version":3,"sources":["../src/Snowflake.ts"],"names":["defaultConfig","color","radius","speed","wind","changeFrequency","Snowflake","canvas","config","updateConfig","params","x","offsetWidth","y","offsetHeight","random","nextSpeed","nextWind","framesSinceLastUpdate","framesPassed","updateTargetParams","ctx","beginPath","arc","Math","PI","fillStyle","closePath","fill"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CO,IAAMA,aAA6B,GAAG;AAC3CC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AKlB,MAAL,CAAYP,KAA5B;AACAoB,MAAAA,GAAG,CAACM,SAAJ;AACAN,MAAAA,GAAG,CAACO,IAAJ;AACD;;;;;;eAGYtB,S","sourcesContent":["import { lerp, random } from './utils'\r\n\r\nexport interface SnowflakeProps {\r\n /** The color of the snowflake, can be any valid CSS color. */\r\n color: string\r\n /**\r\n * The minimum and maximum radius of the snowflake, will be\r\n * randomly selected within this range.\r\n *\r\n * The default value is `[0.5, 3.0]`.\r\n */\r\n radius: [number, number]\r\n /**\r\n * The minimum and maximum speed of the snowflake.\r\n *\r\n * The speed determines how quickly the snowflake moves\r\n * along the y axis (vertical speed).\r\n *\r\n * The values will be randomly selected within this range.\r\n *\r\n * The default value is `[1.0, 3.0]`.\r\n */\r\n speed: [number, number]\r\n /**\r\n * The minimum and maximum wind of the snowflake.\r\n *\r\n * The wind determines how quickly the snowflake moves\r\n * along the x axis (horizontal speed).\r\n *\r\n * The values will be randomly selected within this range.\r\n *\r\n * The default value is `[-0.5, 2.0]`.\r\n */\r\n wind: [number, number]\r\n /**\r\n * The frequency in frames that the wind and speed values\r\n * will update.\r\n *\r\n * The default value is 200.\r\n */\r\n changeFrequency: number\r\n}\r\n\r\nexport type SnowflakeConfig = Partial\r\n\r\nexport const defaultConfig: SnowflakeProps = {\r\n color: '#dee4fd',\r\n radius: [0.5, 3.0],\r\n speed: [1.0, 3.0],\r\n wind: [-0.5, 2.0],\r\n changeFrequency: 200,\r\n}\r\n\r\ninterface SnowflakeParams {\r\n x: number\r\n y: number\r\n radius: number\r\n speed: number\r\n wind: number\r\n nextSpeed: number\r\n nextWind: number\r\n}\r\n\r\n/**\r\n * An individual snowflake that will update it's location every call to `update`\r\n * and draw itself to the canvas every call to `draw`.\r\n */\r\nclass Snowflake {\r\n private config!: SnowflakeProps\r\n private params: SnowflakeParams\r\n private framesSinceLastUpdate: number\r\n\r\n public constructor(canvas: HTMLCanvasElement, config: SnowflakeConfig = {}) {\r\n // Set custom config\r\n this.updateConfig(config)\r\n\r\n // Setting initial parameters\r\n const { radius, wind, speed } = this.config\r\n\r\n this.params = {\r\n x: random(0, canvas.offsetWidth),\r\n y: random(-canvas.offsetHeight, 0),\r\n radius: random(...radius),\r\n speed: random(...speed),\r\n wind: random(...wind),\r\n nextSpeed: random(...wind),\r\n nextWind: random(...speed),\r\n }\r\n\r\n this.framesSinceLastUpdate = 0\r\n }\r\n\r\n public updateConfig(config: SnowflakeConfig): void {\r\n this.config = { ...defaultConfig, ...config }\r\n }\r\n\r\n private updateTargetParams(): void {\r\n this.params.nextSpeed = random(...this.config.speed)\r\n this.params.nextWind = random(...this.config.wind)\r\n }\r\n\r\n public update(canvas: HTMLCanvasElement, framesPassed = 1): void {\r\n const { x, y, wind, speed, nextWind, nextSpeed } = this.params\r\n\r\n // Update current location, wrapping around if going off the canvas\r\n this.params.x = (x + wind * framesPassed) % canvas.offsetWidth\r\n this.params.y = (y + speed * framesPassed) % canvas.offsetHeight\r\n\r\n // Update the wind and speed towards the desired values\r\n this.params.speed = lerp(speed, nextSpeed, 0.01)\r\n this.params.wind = lerp(wind, nextWind, 0.01)\r\n\r\n if (this.framesSinceLastUpdate++ > this.config.changeFrequency) {\r\n this.updateTargetParams()\r\n this.framesSinceLastUpdate = 0\r\n }\r\n }\r\n\r\n public draw(ctx: CanvasRenderingContext2D): void {\r\n ctx.beginPath()\r\n ctx.arc(this.params.x, this.params.y, this.params.radius, 0, 2 * Math.PI)\r\n ctx.fillStyle = this.config.color\r\n ctx.closePath()\r\n ctx.fill()\r\n }\r\n}\r\n\r\nexport default Snowflake\r\n"],"file":"Snowflake.js"} \ No newline at end of file diff --git a/src/Snowflake.ts b/src/Snowflake.ts index 94b4b61..6e0c879 100644 --- a/src/Snowflake.ts +++ b/src/Snowflake.ts @@ -9,7 +9,7 @@ export interface SnowflakeProps { * * The default value is `[0.5, 3.0]`. */ - radius: [minimumRadius: number, maximumRadius: number] + radius: [number, number] /** * The minimum and maximum speed of the snowflake. * @@ -20,7 +20,7 @@ export interface SnowflakeProps { * * The default value is `[1.0, 3.0]`. */ - speed: [minimumSpeed: number, maximumSpeed: number] + speed: [number, number] /** * The minimum and maximum wind of the snowflake. * @@ -31,7 +31,7 @@ export interface SnowflakeProps { * * The default value is `[-0.5, 2.0]`. */ - wind: [minimumWind: number, maximumWind: number] + wind: [number, number] /** * The frequency in frames that the wind and speed values * will update.