presenter 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +0,0 @@
1
- {
2
- "name": "simple-presentation",
3
- "version": "1.0.0",
4
- "description": "Simple presentation in Presenter.js",
5
- "main": "dist/main.js",
6
- "scripts": {
7
- "build": "NODE_ENV=production webpack",
8
- "watch": "NODE_ENV=development webpack --watch",
9
- "serve": "NODE_ENV=development webpack serve --open"
10
- },
11
- "devDependencies": {
12
- "ts-loader": "^9.5.1",
13
- "typescript": "^5.7.2",
14
- "webpack": "^5.96.1",
15
- "webpack-cli": "^5.1.4",
16
- "webpack-dev-server": "^5.1.0"
17
- }
18
- }
@@ -1,20 +0,0 @@
1
- import { Presentation, Slide, Text } from "presenter";
2
-
3
- document.addEventListener("DOMContentLoaded", () => {
4
- const slides = [
5
- new Slide([
6
- new Text({
7
- content: "Hello, there!",
8
- position: { x: 2000, y: 1000 },
9
- fontSize: 100,
10
- }),
11
- ]),
12
- ];
13
- const presentation = new Presentation(
14
- "My Presentation",
15
- slides,
16
- document.body,
17
- );
18
-
19
- presentation.present();
20
- });
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "moduleResolution": "node",
4
- "outDir": "./dist/",
5
- "noImplicitAny": true,
6
- "module": "es6",
7
- "target": "es5",
8
- "allowJs": true
9
- }
10
- }
@@ -1,25 +0,0 @@
1
- const path = require("path");
2
-
3
- module.exports = {
4
- mode: process.env.NODE_ENV || "development",
5
- entry: "./src/index.ts",
6
- output: {
7
- filename: "main.js",
8
- path: path.resolve(__dirname, "dist"),
9
- },
10
- devServer: {
11
- static: "./dist",
12
- },
13
- resolve: {
14
- extensions: [".ts", ".js"],
15
- },
16
- module: {
17
- rules: [
18
- {
19
- test: /\.ts$/,
20
- use: "ts-loader",
21
- exclude: /node_modules/,
22
- },
23
- ],
24
- },
25
- };
package/src/index.ts DELETED
@@ -1,16 +0,0 @@
1
- // Presentation
2
- export * from "./presentation/presentation";
3
- export * from "./presentation/slide";
4
- export * from "./presentation/theme";
5
- export * from "./presentation/object";
6
-
7
- // Objects
8
- export * from "./objects/image";
9
- export * from "./objects/text";
10
- export * from "./objects/rectangle";
11
-
12
- // Themes
13
- export * from "./themes/index";
14
-
15
- // Util
16
- export * from "./util/position";
@@ -1,55 +0,0 @@
1
- import { ObjectProps, SlideObject } from "../presentation/object";
2
- import { Presentation } from "../presentation/presentation";
3
- import { BoundingBox, Position } from "../util/position";
4
-
5
- interface ImageProps extends ObjectProps {
6
- href: string;
7
- width: number;
8
- height: number;
9
- }
10
-
11
- export class Image extends SlideObject {
12
- props: ImageProps;
13
-
14
- constructor(props: Partial<ImageProps> = {}) {
15
- if (!props.href) {
16
- throw new Error("Image requires a href");
17
- }
18
- super({
19
- width: 100,
20
- height: 100,
21
- ...props,
22
- });
23
- }
24
-
25
- generate(presentation: Presentation): SVGElement {
26
- const { width, height, href } = this.props;
27
- const element = document.createElementNS(
28
- "http://www.w3.org/2000/svg",
29
- "image",
30
- );
31
-
32
- // Set attributes
33
- element.setAttribute("href", href);
34
- element.setAttribute("width", width.toString());
35
- element.setAttribute("height", height.toString());
36
-
37
- // Position the element.
38
- this.setPositionAttributes(
39
- presentation,
40
- new BoundingBox(this.props.position, width, height),
41
- element,
42
- );
43
-
44
- return element;
45
- }
46
-
47
- animateMove(
48
- position: Position,
49
- params: anime.AnimeParams,
50
- presentation: Presentation,
51
- ) {
52
- const bbox = new BoundingBox(position, this.props.width, this.props.height);
53
- this.animate({ bbox, ...params }, presentation);
54
- }
55
- }
@@ -1,53 +0,0 @@
1
- import { ObjectProps, SlideObject } from "../presentation/object";
2
- import { Presentation } from "../presentation/presentation";
3
- import { BoundingBox, Position } from "../util/position";
4
-
5
- interface RectangleProps extends ObjectProps {
6
- color: string;
7
- width: number;
8
- height: number;
9
- }
10
-
11
- export class Rectangle extends SlideObject {
12
- props: RectangleProps;
13
-
14
- constructor(props: Partial<RectangleProps> = {}) {
15
- super({
16
- color: "#000000",
17
- width: 100,
18
- height: 100,
19
- ...props,
20
- });
21
- }
22
-
23
- generate(presentation: Presentation): SVGElement {
24
- const { width, height, color } = this.props;
25
- const element = document.createElementNS(
26
- "http://www.w3.org/2000/svg",
27
- "rect",
28
- );
29
-
30
- // Set attributes
31
- element.setAttribute("fill", color);
32
- element.setAttribute("width", width.toString());
33
- element.setAttribute("height", height.toString());
34
-
35
- // Position the element.
36
- this.setPositionAttributes(
37
- presentation,
38
- new BoundingBox(this.props.position, width, height),
39
- element,
40
- );
41
-
42
- return element;
43
- }
44
-
45
- animateMove(
46
- position: Position,
47
- params: anime.AnimeParams,
48
- presentation: Presentation,
49
- ) {
50
- const bbox = new BoundingBox(position, this.props.width, this.props.height);
51
- this.animate({ bbox, ...params }, presentation);
52
- }
53
- }
@@ -1,79 +0,0 @@
1
- import { ObjectProps, SlideObject } from "../presentation/object";
2
- import { Presentation } from "../presentation/presentation";
3
- import { BoundingBox, Position } from "../util/position";
4
-
5
- interface TextProps extends ObjectProps {
6
- content: string;
7
- fontStyle: string; // "normal" | "italic" | "bold"
8
- fontSize: number;
9
- fontFamily: string;
10
- color: string;
11
- }
12
-
13
- export class Text extends SlideObject {
14
- props: TextProps;
15
-
16
- constructor(props: Partial<TextProps> = {}) {
17
- super({
18
- color: "#000000",
19
- content: "",
20
- fontSize: 40,
21
- fontStyle: "normal",
22
- fontFamily: "Arial",
23
- ...props,
24
- });
25
- }
26
-
27
- generate(presentation: Presentation): SVGElement {
28
- const element = document.createElementNS(
29
- "http://www.w3.org/2000/svg",
30
- "text",
31
- );
32
- element.innerHTML = this.props.content;
33
- element.style.font = `${this.props.fontStyle} ${this.props.fontSize}px ${this.props.fontFamily}`;
34
- element.style.fill = this.props.color;
35
-
36
- // Position the element. Text coordinates specify the lower-left corner of text baseline.
37
- this.setPositionAttributes(
38
- presentation,
39
- this.computeRenderedBoundingBox(element, presentation, true),
40
- element,
41
- );
42
-
43
- return element;
44
- }
45
-
46
- computePositionAttributes(
47
- presentation: Presentation,
48
- bbox: BoundingBox,
49
- ): any {
50
- const { x, y } = this.positionInPresentation(
51
- presentation,
52
- bbox.origin.x,
53
- bbox.origin.y,
54
- );
55
- const anchoredBox = this.anchorBoundingBox(
56
- new BoundingBox({ x, y }, bbox.width, bbox.height),
57
- );
58
- return { x: anchoredBox.origin.x, y: anchoredBox.origin.y + bbox.height };
59
- }
60
-
61
- animateMove(
62
- position: Position,
63
- params: anime.AnimeParams,
64
- presentation: Presentation,
65
- ) {
66
- const renderedBBox = this.computeRenderedBoundingBox(
67
- this.element() as SVGGraphicsElement,
68
- presentation,
69
- true,
70
- );
71
- const bbox = new BoundingBox(
72
- position,
73
- renderedBBox.width,
74
- renderedBBox.height,
75
- );
76
- console.log(bbox);
77
- this.animate({ bbox, ...params }, presentation);
78
- }
79
- }
@@ -1,190 +0,0 @@
1
- import anime from "animejs/lib/anime.es.js";
2
-
3
- import { BoundingBox, Position } from "../util/position";
4
- import { Presentation } from "./presentation";
5
- import { Theme } from "./theme";
6
-
7
- export interface ObjectProps {
8
- position: Position | null;
9
- verticalAnchor: "center" | "top" | "bottom";
10
- horizontalAnchor: "center" | "start" | "end";
11
- }
12
-
13
- export class SlideObject {
14
- props: ObjectProps;
15
-
16
- _element: SVGElement | null;
17
-
18
- constructor(props: Partial<ObjectProps>) {
19
- this.props = {
20
- position: null,
21
- verticalAnchor: "top",
22
- horizontalAnchor: "start",
23
- ...props,
24
- };
25
- this._element = null;
26
- }
27
-
28
- /* Generate and return the element. */
29
- generate(presentation: Presentation): SVGElement {
30
- return null;
31
- }
32
-
33
- element(): SVGElement {
34
- if (this._element === null) {
35
- throw new Error("Element not yet generated");
36
- }
37
- return this._element;
38
- }
39
-
40
- /**
41
- * Performs an animation on the object's element.
42
- */
43
- animate(params: anime.AnimeParams, presentation: Presentation | null = null) {
44
- const { bbox, ...remainingParams } = params;
45
-
46
- const processedParams = {
47
- ...remainingParams,
48
- // Position
49
- ...(bbox !== undefined
50
- ? this.computePositionAttributes(presentation, bbox)
51
- : {}),
52
- // Default cubic bezier easing
53
- ...(params.easing === "cubic"
54
- ? { easing: "cubicBezier(0.42, 0, 0.58, 1)" }
55
- : {}),
56
- };
57
-
58
- anime({
59
- targets: this.element(),
60
- duration: 500,
61
- easing: "linear",
62
- ...processedParams,
63
- });
64
- }
65
-
66
- /**
67
- * Returns an animation callback function that performs the animation.
68
- */
69
- animation(params: anime.AnimeParams): () => void {
70
- return () => this.animate(params);
71
- }
72
-
73
- /**
74
- * Performs a movement animation.
75
- * Meant to be overriden for object-specific movement.
76
- */
77
- animateMove(
78
- position: Position,
79
- params: anime.AnimeParams,
80
- presentation: Presentation,
81
- ) {
82
- this.animate({ x: position.x, y: position.y, ...params }, presentation);
83
- }
84
-
85
- /**
86
- * Allow for x and y values to be interpreted as percentages of total width/height.
87
- */
88
- positionInPresentation(
89
- presentation: Presentation,
90
- x: number,
91
- y: number,
92
- ): Position {
93
- const adjustedX = x <= 1 ? x * presentation.boundingBox.width : x;
94
- const adjustedY = y <= 1 ? y * presentation.boundingBox.height : y;
95
- return { x: adjustedX, y: adjustedY };
96
- }
97
-
98
- /**
99
- * Adjusts a bounding box to be anchored given the object's vertical and horizontal anchor settings.
100
- * @param bbox
101
- */
102
- anchorBoundingBox(bbox: BoundingBox): BoundingBox {
103
- const { verticalAnchor, horizontalAnchor } = this.props;
104
- const y = (() => {
105
- switch (verticalAnchor) {
106
- case "top":
107
- return bbox.origin.y;
108
- case "center":
109
- return bbox.origin.y - bbox.height / 2;
110
- case "bottom":
111
- return bbox.origin.y - bbox.height;
112
- }
113
- })();
114
-
115
- const x = (() => {
116
- switch (horizontalAnchor) {
117
- case "start":
118
- return bbox.origin.x;
119
- case "center":
120
- return bbox.origin.x - bbox.width / 2;
121
- case "end":
122
- return bbox.origin.x - bbox.width;
123
- }
124
- })();
125
-
126
- return new BoundingBox({ x, y }, bbox.width, bbox.height);
127
- }
128
-
129
- /**
130
- * Computes a bounding box for a given element given its rendered size and defined position.
131
- * @param element
132
- * @param presentation
133
- * @returns
134
- */
135
- computeRenderedBoundingBox(
136
- element: SVGGraphicsElement,
137
- presentation: Presentation,
138
- adjustY: boolean = false,
139
- ): BoundingBox {
140
- const renderedBoundingBox =
141
- presentation.computeRenderedBoundingBox(element);
142
-
143
- const box = new BoundingBox(
144
- {
145
- x: this.props.position.x,
146
- y: this.props.position.y,
147
- },
148
- renderedBoundingBox.width,
149
- renderedBoundingBox.height,
150
- );
151
-
152
- return box;
153
- }
154
-
155
- /**
156
- * Given a particular initial bounding box, returns the DOM attributes that should be set for the element.
157
- * Can be overriden by other elements.
158
- */
159
- computePositionAttributes(
160
- presentation: Presentation,
161
- bbox: BoundingBox,
162
- ): any {
163
- if (presentation === null) {
164
- throw new Error(
165
- "Cannot compute object position attributes without presentation",
166
- );
167
- }
168
- const { x, y } = this.positionInPresentation(
169
- presentation,
170
- bbox.origin.x,
171
- bbox.origin.y,
172
- );
173
- const anchoredBox = this.anchorBoundingBox(
174
- new BoundingBox({ x, y }, bbox.width, bbox.height),
175
- );
176
- return { x: anchoredBox.origin.x, y: anchoredBox.origin.y };
177
- }
178
-
179
- setPositionAttributes(
180
- presentation: Presentation,
181
- bbox: BoundingBox,
182
- element: SVGElement,
183
- ) {
184
- for (const [attribute, value] of Object.entries(
185
- this.computePositionAttributes(presentation, bbox),
186
- )) {
187
- element.setAttribute(attribute, value.toString());
188
- }
189
- }
190
- }