compile to one single file

This commit is contained in:
Lauchmelder 2021-11-26 23:07:28 +01:00
parent 8140a02305
commit 6526241f5e
5 changed files with 46 additions and 44 deletions

View file

@ -1,6 +1,3 @@
import { Vector2D } from "./vector.js"
import * as shape from "./shapes.js"
function loadScript(filepath: string): string function loadScript(filepath: string): string
{ {
var result = null; var result = null;
@ -76,8 +73,8 @@ class Geometry extends HTMLElement
private redraw() private redraw()
{ {
shape.line(this.context, new Vector2D(), new Vector2D(300, 300)); Shape.line(this.context, new Util.Vector2D(), new Util.Vector2D(300, 300));
shape.circle(this.context, new Vector2D(150, 150), 100); Shape.circle(this.context, new Util.Vector2D(150, 150), 100);
} }
} }

View file

@ -1,6 +1,7 @@
module Util
export class ShapeStyle
{ {
export class ShapeStyle
{
public strokeWidth: number; public strokeWidth: number;
public strokeColor: string; public strokeColor: string;
public fillColor: string; public fillColor: string;
@ -11,4 +12,5 @@ export class ShapeStyle
this.strokeColor = '#000000'; this.strokeColor = '#000000';
this.fillColor = '#00000000'; this.fillColor = '#00000000';
} }
}
} }

View file

@ -1,8 +1,7 @@
import { Vector2D } from "./vector.js" module Shape
import { ShapeStyle } from "./shapeStyle.js";
export function line(ctx: CanvasRenderingContext2D, from: Vector2D , to: Vector2D, style: ShapeStyle = new ShapeStyle())
{ {
export function line(ctx: CanvasRenderingContext2D, from: Util.Vector2D , to: Util.Vector2D, style: Util.ShapeStyle = new Util.ShapeStyle())
{
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(from.x, from.y); ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y); ctx.lineTo(to.x, to.y);
@ -10,10 +9,10 @@ export function line(ctx: CanvasRenderingContext2D, from: Vector2D , to: Vector2
ctx.lineWidth = style.strokeWidth; ctx.lineWidth = style.strokeWidth;
ctx.strokeStyle = style.strokeColor; ctx.strokeStyle = style.strokeColor;
ctx.stroke(); ctx.stroke();
} }
export function circle(ctx: CanvasRenderingContext2D, center: Vector2D, radius: number, style: ShapeStyle = new ShapeStyle()) export function circle(ctx: CanvasRenderingContext2D, center: Util.Vector2D, radius: number, style: Util.ShapeStyle = new Util.ShapeStyle())
{ {
ctx.beginPath(); ctx.beginPath();
ctx.arc(center.x, center.y, radius, 0, 2 * Math.PI, false); ctx.arc(center.x, center.y, radius, 0, 2 * Math.PI, false);
@ -23,4 +22,5 @@ export function circle(ctx: CanvasRenderingContext2D, center: Vector2D, radius:
ctx.lineWidth = style.strokeWidth; ctx.lineWidth = style.strokeWidth;
ctx.strokeStyle = style.strokeColor; ctx.strokeStyle = style.strokeColor;
ctx.stroke(); ctx.stroke();
}
} }

View file

@ -1,5 +1,7 @@
export class Vector2D module Util
{ {
export class Vector2D
{
public x: number; public x: number;
public y: number; public y: number;
@ -8,4 +10,5 @@ export class Vector2D
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
}
} }

View file

@ -1,7 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", "target": "es6",
// "outFile": "./out/lauchpioos.js", "outFile": "./out/geometry.js",
"outDir": "./out", "outDir": "./out",
"sourceRoot": "./src", "sourceRoot": "./src",
"rootDir": "./src", "rootDir": "./src",