-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
708 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2016-2023 Moddable Tech, Inc. | ||
* | ||
* This file is part of the Moddable SDK. | ||
* | ||
* This work is licensed under the | ||
* Creative Commons Attribution 4.0 International License. | ||
* To view a copy of this license, visit | ||
* <http://creativecommons.org/licenses/by/4.0> | ||
* or send a letter to Creative Commons, PO Box 1866, | ||
* Mountain View, CA 94042, USA. | ||
* | ||
*/ | ||
|
||
import {} from "piu/MC"; | ||
|
||
const backgroundSkin = new Skin({ fill:"silver" }); | ||
const ballTexture = new Texture("balls.png"); | ||
const ballSkin = new Skin({ texture:ballTexture, x:0, y:0, width:30, height:30, variants:30 }); | ||
|
||
class BallBehavior extends Behavior { | ||
onCreate(ball, delta) { | ||
this.dx = delta; | ||
this.dy = delta; | ||
} | ||
onDisplaying(ball) { | ||
this.x = ball.x; | ||
this.y = ball.y; | ||
this.width = ball.container.width - ball.width; | ||
this.height = ball.container.height - ball.height; | ||
ball.start(); | ||
} | ||
onTimeChanged(ball) { | ||
var dx = this.dx; | ||
var dy = this.dy; | ||
ball.moveBy(dx, dy); | ||
var x = this.x + dx; | ||
var y = this.y + dy; | ||
if ((x < 0) || (x > this.width)) dx = -dx; | ||
if ((y < 0) || (y > this.height)) dy = -dy; | ||
this.dx = dx; | ||
this.dy = dy; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
}; | ||
|
||
let BallApplication = Application.template($ => ({ | ||
skin:backgroundSkin, | ||
contents: [ | ||
Content(6, { left:0, top:0, skin:ballSkin, variant:0, Behavior: BallBehavior } ), | ||
Content(5, { right:0, top:0, skin:ballSkin, variant:1, Behavior: BallBehavior } ), | ||
Content(4, { right:0, bottom:0, skin:ballSkin, variant:2, Behavior: BallBehavior } ), | ||
Content(3, { left:0, bottom:0, skin:ballSkin, variant:3, Behavior: BallBehavior } ), | ||
] | ||
})); | ||
|
||
export default new BallApplication(null, { touchCount:0, pixels: screen.width * 4 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"config": { | ||
"touchCount": 0 | ||
}, | ||
"resources":{ | ||
"*": [ | ||
"./balls" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@moddable/example-balls", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
}, | ||
"main": "./main.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"description": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright (c) 2021-2022 Moddable Tech, Inc. | ||
* | ||
* This file is part of the Moddable SDK. | ||
* | ||
* This work is licensed under the | ||
* Creative Commons Attribution 4.0 International License. | ||
* To view a copy of this license, visit | ||
* <http://creativecommons.org/licenses/by/4.0>. | ||
* or send a letter to Creative Commons, PO Box 1866, | ||
* Mountain View, CA 94042, USA. | ||
* | ||
*/ | ||
|
||
const headers = new Headers([ | ||
['Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8'], | ||
["Date", Date()], | ||
["User-Agent", "ecma-419 test"] | ||
]); | ||
|
||
const body = new URLSearchParams([ | ||
["Date", Date()], | ||
["Input", "This is no input!"] | ||
]); | ||
|
||
// HTTP | ||
|
||
fetch("http://httpbin.org/post", { method:"POST", headers, body }) | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.json(); | ||
}) | ||
.then(json => { | ||
console.log(JSON.stringify(json, null, "\t")); | ||
}); | ||
|
||
fetch("http://httpbin.org/put", { method:"PUT", body:"This is no data!" }) | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.json(); | ||
}) | ||
.then(json => { | ||
console.log(JSON.stringify(json, null, "\t")); | ||
}); | ||
|
||
fetch("http://httpbin.org/gzip") | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.arrayBuffer(); | ||
}) | ||
.then(arrayBuffer => { | ||
const array = new Uint8Array(arrayBuffer); | ||
console.log(array + "\n"); | ||
}); | ||
|
||
fetch("http://httpbin.org/json") | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.json(); | ||
}) | ||
.then(json => { | ||
console.log(JSON.stringify(json, null, "\t")); | ||
}); | ||
|
||
fetch("http://httpbin.org/encoding/utf8") | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.text(); | ||
}) | ||
.then(text => { | ||
const c = text.length; | ||
for (let i = 0; i < c; i++) { | ||
let lf = text.indexOf("\n", i); | ||
if (-1 === lf) lf = c; | ||
console.log(text.substring(i, lf)); | ||
i = lf + 1; | ||
} | ||
}); | ||
|
||
// HTTPS | ||
|
||
fetch("https://httpbin.org/post", { method:"POST", headers, body }) | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.json(); | ||
}) | ||
.then(json => { | ||
console.log(JSON.stringify(json, null, "\t")); | ||
}); | ||
|
||
fetch("https://httpbin.org/put", { method:"PUT", body:"This is no data!" }) | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.json(); | ||
}) | ||
.then(json => { | ||
console.log(JSON.stringify(json, null, "\t")); | ||
}); | ||
|
||
fetch("https://httpbin.org/gzip") | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.arrayBuffer(); | ||
}) | ||
.then(arrayBuffer => { | ||
const array = new Uint8Array(arrayBuffer); | ||
console.log(array + "\n"); | ||
}); | ||
|
||
fetch("https://httpbin.org/json") | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.json(); | ||
}) | ||
.then(json => { | ||
console.log(JSON.stringify(json, null, "\t")); | ||
}); | ||
|
||
fetch("https://httpbin.org/encoding/utf8") | ||
.then(response => { | ||
console.log(`${response.url} ${response.status} ${response.statusText}\n\n`); | ||
response.headers.forEach((value, key) => console.log(`${key}: ${value}\n`)); | ||
return response.text(); | ||
}) | ||
.then(text => { | ||
const c = text.length; | ||
for (let i = 0; i < c; i++) { | ||
let lf = text.indexOf("\n", i); | ||
if (-1 === lf) lf = c; | ||
console.log(text.substring(i, lf)); | ||
i = lf + 1; | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "@moddable/example-fetch", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
}, | ||
"main": "./main.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"moddable": { | ||
"manifest": { | ||
"data": { | ||
"*": [ | ||
"$(MODULES)/crypt/data/ca222" | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import test from "#test"; | ||
|
||
import module0 from "./module0.js"; | ||
import module1 from "@moddable/example-hello1/mod.js"; | ||
import main2 from "@moddable/example-hello2"; | ||
|
||
console.log(test); | ||
console.log(module0); | ||
console.log(module1); | ||
console.log(main2); | ||
|
||
import Mustache from "mustache"; | ||
|
||
const view = { | ||
title: "Joe", | ||
calc: function () { | ||
return 2 + 4; | ||
} | ||
}; | ||
|
||
const output = Mustache.render("{{title}} spends {{calc}}", view); | ||
console.log(`${output}\n`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import main2 from "@moddable/example-hello2/main.js"; | ||
export default "mod0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "@moddable/example-hello", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"mustache": "^4.2.0", | ||
"@moddable/example-hello1": "^1.0.2", | ||
"@moddable/example-hello2": "^1.0.2" | ||
}, | ||
"imports": { | ||
"#test": { | ||
"moddable": "./test-xs.js", | ||
"default": "./test-node.js" | ||
} | ||
}, | ||
"main": "./main.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"description": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "node"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "xs"; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const backgroundSkin = new Skin({ fill:"silver" }); | ||
const ballTexture = new Texture({ archive, path:"balls.png" }); | ||
const ballSkin = new Skin({ texture:ballTexture, x:0, y:0, width:30, height:30, variants:30 }); | ||
|
||
class BallBehavior extends Behavior { | ||
onCreate(ball, delta) { | ||
this.dx = delta; | ||
this.dy = delta; | ||
} | ||
onDisplaying(ball) { | ||
this.x = ball.x; | ||
this.y = ball.y; | ||
this.width = ball.container.width - ball.width; | ||
this.height = ball.container.height - ball.height; | ||
ball.start(); | ||
} | ||
onTimeChanged(ball) { | ||
var dx = this.dx; | ||
var dy = this.dy; | ||
ball.moveBy(dx, dy); | ||
var x = this.x + dx; | ||
var y = this.y + dy; | ||
if ((x < 0) || (x > this.width)) dx = -dx; | ||
if ((y < 0) || (y > this.height)) dy = -dy; | ||
this.dx = dx; | ||
this.dy = dy; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
}; | ||
|
||
export default Application.template($ => ({ | ||
left:0, right:0, top:0, bottom: 0, skin:backgroundSkin, | ||
contents: [ | ||
Content(6, { left:0, top:0, skin:ballSkin, variant:0, Behavior: BallBehavior } ), | ||
Content(5, { right:0, top:0, skin:ballSkin, variant:1, Behavior: BallBehavior } ), | ||
Content(4, { right:0, bottom:0, skin:ballSkin, variant:2, Behavior: BallBehavior } ), | ||
Content(3, { left:0, bottom:0, skin:ballSkin, variant:3, Behavior: BallBehavior } ), | ||
] | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@moddable/example-mod-balls", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
}, | ||
"main": "./mod.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"moddable": { | ||
"manifest": { | ||
"resources": { | ||
"*": "./balls" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.