|
4 | 4 | * @for p5.Element |
5 | 5 | */ |
6 | 6 |
|
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 { |
54 | 8 | constructor(elt, pInst) { |
55 | 9 | this.elt = elt; |
56 | 10 | this._pInst = this._pixelsState = pInst; |
@@ -944,52 +898,101 @@ p5.Element = class { |
944 | 898 | } |
945 | 899 | }; |
946 | 900 |
|
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; |
978 | 947 |
|
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 | + */ |
986 | 979 |
|
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 | +} |
994 | 996 |
|
995 | | -export default p5.Element; |
| 997 | +export default element; |
| 998 | +export { Element }; |
0 commit comments