applabjs 1.0.0

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.
package/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Richard Liu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # AppLabJS
2
+
3
+ A JavaScript Library allow to use functions in code.org App Lab in browser enviroment
4
+
5
+ # Installation
6
+
7
+ Add this script tag to your HTML code
8
+
9
+ `
10
+
11
+ ```html
12
+ <script src="https://cdn.jsdelivr.net/gh/richardliucode/applabjs@1.0.2/applab.min.js"></script>
13
+ `
14
+ ```
15
+
16
+ # Usage
17
+ * You can see the document of [code.org App Lab](https://studio.code.org/docs/ide/applab/) to find out the below function, it use the similar api.
18
+ `
19
+
20
+ ```javascript
21
+ onEvent(id, type, callback);
22
+ button(id, text);
23
+ textInput(id, text);
24
+ textLabel(id, text);
25
+ getText(id);
26
+ setText(id);
27
+ getNumber(id);
28
+ setNumber(id, number);
29
+ image(id, url);
30
+ getImageURL(id, url);
31
+ showElement(id);
32
+ hideElement(id);
33
+ deleteElement(id);
34
+ getXPosition();
35
+ getYPosition();
36
+ open();
37
+ ```
package/applab.js ADDED
@@ -0,0 +1,138 @@
1
+ /*
2
+ </>
3
+
4
+ This was build by Richard liu, this is for app lab code in browser
5
+
6
+ You can use this code in your website
7
+ */
8
+
9
+ //UI Control
10
+ function write(text) {
11
+ document.body.innerHTML = text;
12
+ }
13
+
14
+ function getText(elementId) {
15
+ return (
16
+ document.getElementById(elementId).value ||
17
+ document.getElementById(elementId).innerHTML
18
+ );
19
+ }
20
+
21
+ function setImageUrl(ImageId, TargetImageURL) {
22
+ document.getElementById(ImageId).src = TargetImageURL;
23
+ }
24
+
25
+ function getNumber(id) {
26
+ return parseFloat(document.getElementById(id).value);
27
+ }
28
+
29
+ function setNumber(id, Number) {
30
+ if (!isNaN(Number)) {
31
+ if (document.getElementById(id).value == undefined) {
32
+ document.getElementById(id).innerHTML = Number;
33
+ } else {
34
+ document.getElementById(id).value = Number;
35
+ }
36
+ } else {
37
+ if (document.getElementById(id).value == undefined) {
38
+ document.getElementById(id).innerHTML = NaN;
39
+ } else {
40
+ document.getElementById(id).value = NaN;
41
+ }
42
+ }
43
+ }
44
+
45
+ function setImageUrl(ImageId, url) {
46
+ document.getElementById(ImageId).src = url;
47
+ }
48
+
49
+ function getImageUrl(ImageId) {
50
+ return document.getElementById(ImageId).src;
51
+ }
52
+
53
+ function setStyle(ID, CSS) {
54
+ document.getElementById(ID).style = CSS;
55
+ }
56
+
57
+ function setText(elementId, text) {
58
+ let element = document.getElementById(elementId);
59
+ if (element.value != undefined) {
60
+ element.value = text;
61
+ } else {
62
+ element.innerText = text;
63
+ }
64
+ }
65
+
66
+ function hideElement(id) {
67
+ document.getElementById(id).style.display = "none";
68
+ }
69
+
70
+ function showElement(id) {
71
+ document.getElementById(id).style.display = "revert"
72
+ }
73
+
74
+ function deleteElement(id) {
75
+ document.getElementById(id).remove();
76
+ }
77
+
78
+ function onEvent(id, status, callback) {
79
+ var elementForID = document.getElementById(id);
80
+ if (elementForID) {
81
+ elementForID.addEventListener(status, callback);
82
+ } else {
83
+ console.error("Element with ID " + id + " not found.");
84
+ }
85
+ }
86
+
87
+ function open(URLForOpen) {
88
+ window.open(URLForOpen);
89
+ }
90
+
91
+
92
+ function button(id, text) {
93
+ let newButton = document.createElement("button");
94
+ newButton.innerText = text;
95
+ newButton.id = id;
96
+ document.body.appendChild(newButton);
97
+ }
98
+
99
+ function textInput(id, text) {
100
+ let newTextInput = document.createElement("input");
101
+ newTextInput.type = "text";
102
+ newTextInput.value = text;
103
+ newTextInput.id = id;
104
+ document.body.appendChild(newTextInput);
105
+ }
106
+
107
+ function textLabel(id, text) {
108
+ let newLabel = document.createElement("label");
109
+ newLabel.innerText = text;
110
+ newLabel.id = id;
111
+ document.body.appendChild(newLabel);
112
+ }
113
+
114
+ function image(id, url) {
115
+ let newImage = document.createElement("img");
116
+ newImage.id = id;
117
+ newImage.src = url;
118
+ document.body.appendChild(newImage);
119
+ }
120
+
121
+ function getXPosition(id){
122
+ return parseFloat(window.getComputedStyle(document.getElementById(id)).left);
123
+ }
124
+
125
+ function getYPosition(id){
126
+ return parseFloat(window.getComputedStyle(document.getElementById(id)).top);
127
+ }
128
+ //MATH
129
+ function randomNumber(min, max) {
130
+ return parseFloat((Math.random() * (max - min) + min).toFixed(0));
131
+ }
132
+
133
+ //list
134
+ function appendItems(list, item) {
135
+ list.push(item);
136
+ }
137
+
138
+
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "applabjs",
3
+ "version": "1.0.0",
4
+ "description": "A JavaScript Library allow to use functions in code.org App Lab in browser enviroment",
5
+ "keywords": [
6
+ "code.org",
7
+ "AppLab",
8
+ "JavaScript"
9
+ ],
10
+ "homepage": "https://github.com/RichardLiuCode/applabjs#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/RichardLiuCode/applabjs/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/RichardLiuCode/applabjs.git"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Richard Liu",
20
+ "type": "commonjs",
21
+ "main": "applab.js",
22
+ "scripts": {
23
+ "test": "echo \"No test specified\""
24
+ }
25
+ }