Skip to content

Commit 0c71618

Browse files
committed
Change how all classes are defined to be more exportable
1 parent 27326fe commit 0c71618

25 files changed

+25032
-23745
lines changed

src/app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import './core/friendly_errors/file_errors';
66
import './core/friendly_errors/fes_core';
77
import './core/friendly_errors/sketch_reader';
88
import './core/p5.Element';
9-
import './core/p5.Graphics';
10-
import './core/rendering';
9+
// import './core/p5.Graphics';
10+
// import './core/rendering';
1111
import shape from './shape';
1212
shape(p5);
1313

@@ -29,7 +29,8 @@ import data from './data';
2929
data(p5);
3030

3131
// DOM
32-
import './dom/dom';
32+
import dom from './dom/dom';
33+
dom(p5, p5.prototype);
3334

3435
// events
3536
import events from './events';

src/core/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,16 @@ import environment from './environment';
664664
import rendering from './rendering';
665665
import renderer from './p5.Renderer';
666666
import renderer2D from './p5.Renderer2D';
667+
import graphics from './p5.Graphics';
668+
import element from './p5.Element';
667669

668670
p5.registerAddon(transform);
669671
p5.registerAddon(structure);
670672
p5.registerAddon(environment);
671673
p5.registerAddon(rendering);
672674
p5.registerAddon(renderer);
673675
p5.registerAddon(renderer2D);
676+
p5.registerAddon(graphics);
677+
p5.registerAddon(element);
674678

675679
export default p5;

src/core/p5.Element.js

Lines changed: 96 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,7 @@
44
* @for p5.Element
55
*/
66

7-
import p5 from './main';
8-
9-
/**
10-
* A class to describe an
11-
* <a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started" target="_blank">HTML element</a>.
12-
*
13-
* Sketches can use many elements. Common elements include the drawing canvas,
14-
* buttons, sliders, webcam feeds, and so on.
15-
*
16-
* All elements share the methods of the `p5.Element` class. They're created
17-
* with functions such as <a href="#/p5/createCanvas">createCanvas()</a> and
18-
* <a href="#/p5/createButton">createButton()</a>.
19-
*
20-
* @class p5.Element
21-
* @param {HTMLElement} elt wrapped DOM element.
22-
* @param {p5} [pInst] pointer to p5 instance.
23-
*
24-
* @example
25-
* <div>
26-
* <code>
27-
* function setup() {
28-
* createCanvas(100, 100);
29-
*
30-
* background(200);
31-
*
32-
* // Create a button element and
33-
* // place it beneath the canvas.
34-
* let btn = createButton('change');
35-
* btn.position(0, 100);
36-
*
37-
* // Call randomColor() when
38-
* // the button is pressed.
39-
* btn.mousePressed(randomColor);
40-
*
41-
* describe('A gray square with a button that says "change" beneath it. The square changes color when the user presses the button.');
42-
* }
43-
*
44-
* // Paint the background either
45-
* // red, yellow, blue, or green.
46-
* function randomColor() {
47-
* let c = random(['red', 'yellow', 'blue', 'green']);
48-
* background(c);
49-
* }
50-
* </code>
51-
* </div>
52-
*/
53-
p5.Element = class {
7+
class Element {
548
constructor(elt, pInst) {
559
this.elt = elt;
5610
this._pInst = this._pixelsState = pInst;
@@ -944,52 +898,101 @@ p5.Element = class {
944898
}
945899
};
946900

947-
/**
948-
* The element's underlying `HTMLElement` object.
949-
*
950-
* The
951-
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_blank">HTMLElement</a>
952-
* object's properties and methods can be used directly.
953-
*
954-
* @example
955-
* <div>
956-
* <code>
957-
* function setup() {
958-
* // Create a canvas element and
959-
* // assign it to cnv.
960-
* let cnv = createCanvas(100, 100);
961-
*
962-
* background(200);
963-
*
964-
* // Set the border style for the
965-
* // canvas.
966-
* cnv.elt.style.border = '5px dashed deeppink';
967-
*
968-
* describe('A gray square with a pink border drawn with dashed lines.');
969-
* }
970-
* </code>
971-
* </div>
972-
*
973-
* @property elt
974-
* @for p5.Element
975-
* @name elt
976-
* @readOnly
977-
*/
901+
function element(p5, fn){
902+
/**
903+
* A class to describe an
904+
* <a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started" target="_blank">HTML element</a>.
905+
*
906+
* Sketches can use many elements. Common elements include the drawing canvas,
907+
* buttons, sliders, webcam feeds, and so on.
908+
*
909+
* All elements share the methods of the `p5.Element` class. They're created
910+
* with functions such as <a href="#/p5/createCanvas">createCanvas()</a> and
911+
* <a href="#/p5/createButton">createButton()</a>.
912+
*
913+
* @class p5.Element
914+
* @param {HTMLElement} elt wrapped DOM element.
915+
* @param {p5} [pInst] pointer to p5 instance.
916+
*
917+
* @example
918+
* <div>
919+
* <code>
920+
* function setup() {
921+
* createCanvas(100, 100);
922+
*
923+
* background(200);
924+
*
925+
* // Create a button element and
926+
* // place it beneath the canvas.
927+
* let btn = createButton('change');
928+
* btn.position(0, 100);
929+
*
930+
* // Call randomColor() when
931+
* // the button is pressed.
932+
* btn.mousePressed(randomColor);
933+
*
934+
* describe('A gray square with a button that says "change" beneath it. The square changes color when the user presses the button.');
935+
* }
936+
*
937+
* // Paint the background either
938+
* // red, yellow, blue, or green.
939+
* function randomColor() {
940+
* let c = random(['red', 'yellow', 'blue', 'green']);
941+
* background(c);
942+
* }
943+
* </code>
944+
* </div>
945+
*/
946+
p5.Element = Element;
978947

979-
/**
980-
* A `Number` property that stores the element's width.
981-
*
982-
* @type {Number}
983-
* @property width
984-
* @for p5.Element
985-
*/
948+
/**
949+
* The element's underlying `HTMLElement` object.
950+
*
951+
* The
952+
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_blank">HTMLElement</a>
953+
* object's properties and methods can be used directly.
954+
*
955+
* @example
956+
* <div>
957+
* <code>
958+
* function setup() {
959+
* // Create a canvas element and
960+
* // assign it to cnv.
961+
* let cnv = createCanvas(100, 100);
962+
*
963+
* background(200);
964+
*
965+
* // Set the border style for the
966+
* // canvas.
967+
* cnv.elt.style.border = '5px dashed deeppink';
968+
*
969+
* describe('A gray square with a pink border drawn with dashed lines.');
970+
* }
971+
* </code>
972+
* </div>
973+
*
974+
* @property elt
975+
* @for p5.Element
976+
* @name elt
977+
* @readOnly
978+
*/
986979

987-
/**
988-
* A `Number` property that stores the element's height.
989-
*
990-
* @type {Number}
991-
* @property height
992-
* @for p5.Element
993-
*/
980+
/**
981+
* A `Number` property that stores the element's width.
982+
*
983+
* @type {Number}
984+
* @property width
985+
* @for p5.Element
986+
*/
987+
988+
/**
989+
* A `Number` property that stores the element's height.
990+
*
991+
* @type {Number}
992+
* @property height
993+
* @for p5.Element
994+
*/
995+
}
994996

995-
export default p5.Element;
997+
export default element;
998+
export { Element };

0 commit comments

Comments
 (0)