Skip to content

Commit

Permalink
Added newSuica, #109, #112
Browse files Browse the repository at this point in the history
  • Loading branch information
boytchev committed Nov 10, 2023
1 parent 59adf25 commit b465582
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
2 changes: 1 addition & 1 deletion BUILD.NUMBER
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45
48
12 changes: 8 additions & 4 deletions bin/suica.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions examples/suica.js

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions src/suica-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class Suica

constructor( suicaTag )
{
if( suicaTag.getAttribute( 'suica-auto-generated' ) )
{
return suica;
}

// internal storage
this._ = {
solidGeometry:{},
Expand All @@ -155,6 +160,7 @@ class Suica
suicaTag.style.display = 'inline-block';

suicaTag.style.boxSizing = 'border-box';
suicaTag.setAttribute( 'suica-auto-generated', true );

if( getComputedStyle(suicaTag).width == 'auto' )
{
Expand Down Expand Up @@ -289,7 +295,7 @@ class Suica
}


// create canvas element inside <suica>
// create canvas element inside <suica> (if it does not exist)
createCanvas()
{
// calculates size - if size is not defined in CSS,
Expand All @@ -300,7 +306,7 @@ class Suica
if( this.suicaTag.clientHeight < 1 )
this.suicaTag.style.height = (this.suicaTag.getAttribute('height') || (TEST_MODE?400:300)) + 'px';

// create canvas elements
// create canvas element
this.canvas = document.createElement( 'canvas' );
this.canvas.width = this.suicaTag.clientWidth;
this.canvas.height = this.suicaTag.clientHeight;
Expand All @@ -311,7 +317,6 @@ class Suica

this.canvas.suicaObject = this;
this.suicaTag.appendChild( this.canvas );

} // Suica.createCanvas


Expand Down Expand Up @@ -1406,6 +1411,16 @@ class Suica
//}


window.newSuica = function( )
{
var suicaTag = document.createElement( 'suica' );
suicaTag.style = 'border: solid 1m red;';
document.body.appendChild( suicaTag );

new Suica( suicaTag );
}


window.style = function( object, properties )
{
for( var n in properties ) object[n] = properties[n];
Expand Down Expand Up @@ -1735,7 +1750,7 @@ window.splane = function( points=Suica.SPLANE.POINTS, closed, interpolant )
//
// idea from https://github.com/jspenguin2017/Snippets/blob/master/onbeforescriptexecute.html
new MutationObserver( function( mutations )
{
{
for( var parentElem of mutations )
{
for( var childElem of parentElem.addedNodes)
Expand Down
1 change: 1 addition & 0 deletions test/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ var cases = [
'square',
'style',
'suica-centered',
'suica-js',
'suica-orientation-xyz',
'suica-orientation-xzy',
'suica-orientation-yxz',
Expand Down
19 changes: 19 additions & 0 deletions test/cases/suica-js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<script src="../test.js"></script>
</head>

<body>

<script>
newSuica();
oxyz();
demo();
cube();
</script>

</body>
</html>
Binary file added test/snapshots/suica-js.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ function compareImages( )

function sendSnapshot( )
{
if( !suica ) return;
if( typeof suica == 'undefined' ) return;

const DELAY = 0.9;

var _onTime = suica.ontime;

suica.ontime = (t, dT)=>{
Expand Down

0 comments on commit b465582

Please sign in to comment.