How to use Read method in Best

Best JavaScript code snippet using best

SEA3D.js

Source:SEA3D.js Github

copy

Full Screen

1/**2 * SEA3D SDK3 * @author Sunag / http://www.sunag.com.br/4 */5'use strict';6var SEA3D = { VERSION : 18000 }7SEA3D.getVersion = function() {8 // Max = 16777215 - VVSSBB | V = Version | S = Subversion | B = Buildversion9 var v = SEA3D.VERSION.toString(), l = v.length;10 return v.substring( 0, l - 4 ) + "." + v.substring( l - 4, l - 3 ) + "." + v.substring( l - 3, l - 2 ) + "." + parseFloat( v.substring( l - 2, l ) ).toString();11};12console.log( 'SEA3D ' + SEA3D.getVersion() );13//14// STREAM : STANDARD DATA-IO ( LITTLE-ENDIAN )15//16SEA3D.Stream = function( buffer ) {17 this.position = 0;18 this.buffer = buffer || new ArrayBuffer();19};20SEA3D.Stream.NONE = 0;21// 1D = 0 at 3122SEA3D.Stream.BOOLEAN = 1;23SEA3D.Stream.BYTE = 2;24SEA3D.Stream.UBYTE = 3;25SEA3D.Stream.SHORT = 4;26SEA3D.Stream.USHORT = 5;27SEA3D.Stream.INT24 = 6;28SEA3D.Stream.UINT24 = 7;29SEA3D.Stream.INT = 8;30SEA3D.Stream.UINT = 9;31SEA3D.Stream.FLOAT = 10;32SEA3D.Stream.DOUBLE = 11;33SEA3D.Stream.DECIMAL = 12;34// 2D = 32 at 6335// 3D = 64 at 9536SEA3D.Stream.VECTOR3D = 74;37// 4D = 96 at 12738SEA3D.Stream.VECTOR4D = 106;39// Undefined Size = 128 at 25540SEA3D.Stream.STRING_TINY = 128;41SEA3D.Stream.STRING_SHORT = 129;42SEA3D.Stream.STRING_LONG = 130;43SEA3D.Stream.ASSET = 200;44SEA3D.Stream.GROUP = 255;45SEA3D.Stream.BLEND_MODE = [46 "normal", "add", "subtract", "multiply", "dividing", "mix", "alpha", "screen", "darken",47 "overlay", "colorburn", "linearburn", "lighten", "colordodge", "lineardodge",48 "softlight", "hardlight", "pinlight", "spotlight", "spotlightblend", "hardmix",49 "average", "difference", "exclusion", "hue", "saturation", "color", "value",50 "linearlight", "grainextract", "reflect", "glow", "darkercolor", "lightercolor", "phoenix", "negation"51];52SEA3D.Stream.INTERPOLATION_TABLE = [53 "normal", "linear",54 "sine.in", "sine.out", "sine.inout",55 "cubic.in", "cubic.out", "cubic.inout",56 "quint.in", "quint.out", "quint.inout",57 "circ.in", "circ.out", "circ.inout",58 "back.in", "back.out", "back.inout",59 "quad.in", "quad.out", "quad.inout",60 "quart.in", "quart.out", "quart.inout",61 "expo.in", "expo.out", "expo.inout",62 "elastic.in", "elastic.out", "elastic.inout",63 "bounce.in", "bounce.out", "bounce.inout"64];65SEA3D.Stream.sizeOf = function( kind ) {66 if ( kind == 0 ) return 0;67 else if ( kind >= 1 && kind <= 31 ) return 1;68 else if ( kind >= 32 && kind <= 63 ) return 2;69 else if ( kind >= 64 && kind <= 95 ) return 3;70 else if ( kind >= 96 && kind <= 125 ) return 4;71 return - 1;72};73SEA3D.Stream.prototype = {74 constructor: SEA3D.Stream,75 set buffer ( val ) {76 this.buf = val;77 this.length = val.byteLength;78 this.data = new DataView( val );79 },80 get buffer () {81 return this.buf;82 },83 get bytesAvailable () {84 return this.length - this.position;85 }86};87SEA3D.Stream.prototype.getByte = function( pos ) {88 return this.data.getInt8( pos );89};90SEA3D.Stream.prototype.readBytes = function( len ) {91 var buf = this.buf.slice( this.position, this.position + len );92 this.position += len;93 return buf;94};95SEA3D.Stream.prototype.readByte = function() {96 return this.data.getInt8( this.position ++ );97};98SEA3D.Stream.prototype.readUByte = function() {99 return this.data.getUint8( this.position ++ );100};101SEA3D.Stream.prototype.readBool = function() {102 return this.data.getInt8( this.position ++ ) != 0;103};104SEA3D.Stream.prototype.readShort = function() {105 var v = this.data.getInt16( this.position, true );106 this.position += 2;107 return v;108};109SEA3D.Stream.prototype.readUShort = function() {110 var v = this.data.getUint16( this.position, true );111 this.position += 2;112 return v;113};114SEA3D.Stream.prototype.readUInt24 = function() {115 var v = this.data.getUint32( this.position, true ) & 0xFFFFFF;116 this.position += 3;117 return v;118};119SEA3D.Stream.prototype.readUInt24F = function() {120 return this.readUShort() | ( this.readUByte() << 16 );121};122SEA3D.Stream.prototype.readInt = function() {123 var v = this.data.getInt32( this.position, true );124 this.position += 4;125 return v;126};127SEA3D.Stream.prototype.readUInt = function() {128 var v = this.data.getUint32( this.position, true );129 this.position += 4;130 return v;131};132SEA3D.Stream.prototype.readFloat = function() {133 var v = this.data.getFloat32( this.position, true );134 this.position += 4;135 return v;136};137SEA3D.Stream.prototype.readUInteger = function() {138 var v = this.readUByte(),139 r = v & 0x7F;140 if ( ( v & 0x80 ) != 0 ) {141 v = this.readUByte();142 r |= ( v & 0x7F ) << 7;143 if ( ( v & 0x80 ) != 0 ) {144 v = this.readUByte();145 r |= ( v & 0x7F ) << 13;146 }147 }148 return r;149};150SEA3D.Stream.prototype.readVector2 = function() {151 return { x: this.readFloat(), y: this.readFloat() }152};153SEA3D.Stream.prototype.readVector3 = function() {154 return { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() }155};156SEA3D.Stream.prototype.readVector4 = function() {157 return { x: this.readFloat(), y: this.readFloat(), z: this.readFloat(), w: this.readFloat() }158};159SEA3D.Stream.prototype.readMatrix = function() {160 var mtx = new Float32Array( 16 );161 mtx[ 0 ] = this.readFloat();162 mtx[ 1 ] = this.readFloat();163 mtx[ 2 ] = this.readFloat();164 mtx[ 3 ] = 0.0;165 mtx[ 4 ] = this.readFloat();166 mtx[ 5 ] = this.readFloat();167 mtx[ 6 ] = this.readFloat();168 mtx[ 7 ] = 0.0;169 mtx[ 8 ] = this.readFloat();170 mtx[ 9 ] = this.readFloat();171 mtx[ 10 ] = this.readFloat();172 mtx[ 11 ] = 0.0;173 mtx[ 12 ] = this.readFloat();174 mtx[ 13 ] = this.readFloat();175 mtx[ 14 ] = this.readFloat();176 mtx[ 15 ] = 1.0;177 return mtx;178};179SEA3D.Stream.prototype.readUTF = function( len ) {180 return String.fromCharCode.apply( undefined, new Uint16Array( new Uint8Array( this.readBytes( len ) ) ) );181};182SEA3D.Stream.prototype.readExt = function() {183 return this.readUTF( 4 ).replace( /\0/g, "" );184};185SEA3D.Stream.prototype.readUTF8 = function() {186 return this.readUTF( this.readUByte() );187};188SEA3D.Stream.prototype.readUTF8Short = function() {189 return this.readUTF( this.readUShort() );190};191SEA3D.Stream.prototype.readUTF8Long = function() {192 return this.readUTF( this.readUInt() );193};194SEA3D.Stream.prototype.readUByteArray = function( length ) {195 var v = new Uint8Array( length );196 SEA3D.Stream.memcpy(197 v.buffer,198 0,199 this.buffer,200 this.position,201 length202 );203 this.position += length;204 return v;205};206SEA3D.Stream.prototype.readUShortArray = function( length ) {207 var v = new Uint16Array( length ),208 len = length * 2;209 SEA3D.Stream.memcpy(210 v.buffer,211 0,212 this.buffer,213 this.position,214 len215 );216 this.position += len;217 return v;218};219SEA3D.Stream.prototype.readUInt24Array = function( length ) {220 var v = new Uint32Array( length );221 for ( var i = 0; i < length; i ++ ) {222 v[ i ] = this.readUInt24();223 }224 return v;225};226SEA3D.Stream.prototype.readUIntArray = function( length ) {227 var v = new Uint32Array( length ),228 len = length * 4;229 SEA3D.Stream.memcpy(230 v.buffer,231 0,232 this.buffer,233 this.position,234 len235 );236 this.position += len;237 return v;238};239SEA3D.Stream.prototype.readFloatArray = function( length ) {240 var v = new Float32Array( length ),241 len = length * 4;242 SEA3D.Stream.memcpy(243 v.buffer,244 0,245 this.buffer,246 this.position,247 len248 );249 this.position += len;250 return v;251};252SEA3D.Stream.prototype.readBlendMode = function() {253 return SEA3D.Stream.BLEND_MODE[ this.readUByte() ];254};255SEA3D.Stream.prototype.readInterpolation = function() {256 return SEA3D.Stream.INTERPOLATION_TABLE[ this.readUByte() ];257};258SEA3D.Stream.prototype.readTags = function( callback ) {259 var numTag = this.readUByte();260 for ( var i = 0; i < numTag; ++ i ) {261 var kind = this.readUShort();262 var size = this.readUInt();263 var pos = this.position;264 callback( kind, data, size );265 this.position = pos += size;266 }267};268SEA3D.Stream.prototype.readProperties = function( sea3d ) {269 var count = this.readUByte(),270 props = {}, types = {};271 props.__type = types;272 for ( var i = 0; i < count; i ++ ) {273 var name = this.readUTF8(),274 type = this.readUByte();275 props[ name ] = this.readToken( type, sea3d );276 types[ name ] = type;277 }278 return props;279};280SEA3D.Stream.prototype.readAnimationList = function( sea3d ) {281 var list = [],282 count = this.readUByte();283 var i = 0;284 while ( i < count ) {285 var attrib = this.readUByte(),286 anm = {};287 anm.relative = ( attrib & 1 ) != 0;288 if ( attrib & 2 ) anm.timeScale = this.readFloat();289 anm.tag = sea3d.getObject( this.readUInt() );290 list[ i ++ ] = anm;291 }292 return list;293};294SEA3D.Stream.prototype.readScriptList = function( sea3d ) {295 var list = [],296 count = this.readUByte();297 var i = 0;298 while ( i < count ) {299 var attrib = this.readUByte(),300 script = {};301 script.priority = ( attrib & 1 ) | ( attrib & 2 );302 if ( attrib & 4 ) {303 var numParams = this.readUByte();304 script.params = {};305 for ( var j = 0; j < numParams; j ++ ) {306 var name = this.readUTF8();307 script.params[ name ] = this.readObject( sea3d );308 }309 }310 if ( attrib & 8 ) {311 script.method = this.readUTF8();312 }313 script.tag = sea3d.getObject( this.readUInt() );314 list[ i ++ ] = script;315 }316 return list;317};318SEA3D.Stream.prototype.readObject = function( sea3d ) {319 return this.readToken( this.readUByte(), sea3d );320};321SEA3D.Stream.prototype.readToken = function( type, sea3d ) {322 switch ( type )323 {324 // 1D325 case SEA3D.Stream.BOOLEAN:326 return this.readBool();327 break;328 case SEA3D.Stream.UBYTE:329 return this.readUByte();330 break;331 case SEA3D.Stream.USHORT:332 return this.readUShort();333 break;334 case SEA3D.Stream.UINT24:335 return this.readUInt24();336 break;337 case SEA3D.Stream.INT:338 return this.readInt();339 break;340 case SEA3D.Stream.UINT:341 return this.readUInt();342 break;343 case SEA3D.Stream.FLOAT:344 return this.readFloat();345 break;346 // 3D347 case SEA3D.Stream.VECTOR3D:348 return this.readVector3();349 break;350 // 4D351 case SEA3D.Stream.VECTOR4D:352 return this.readVector4();353 break;354 // Undefined Values355 case SEA3D.Stream.STRING_TINY:356 return this.readUTF8();357 break;358 case SEA3D.Stream.STRING_SHORT:359 return this.readUTF8Short();360 break;361 case SEA3D.Stream.STRING_LONG:362 return this.readUTF8Long();363 break364 case SEA3D.Stream.ASSET:365 var asset = this.readUInt();366 return asset > 0 ? sea3d.getObject( asset - 1 ).tag : null;367 break;368 default:369 console.error( "DataType not found!" );370 break;371 }372 return null;373};374SEA3D.Stream.prototype.readVector = function( type, length, offset ) {375 var size = SEA3D.Stream.sizeOf( type ),376 i = offset * size,377 count = i + ( length * size );378 switch ( type )379 {380 // 1D381 case SEA3D.Stream.BOOLEAN:382 return this.readUByteArray( count );383 case SEA3D.Stream.UBYTE:384 return this.readUByteArray( count );385 case SEA3D.Stream.USHORT:386 return this.readUShortArray( count );387 case SEA3D.Stream.UINT24:388 return this.readUInt24Array( count );389 case SEA3D.Stream.UINT:390 return this.readUIntArray( count );391 case SEA3D.Stream.FLOAT:392 return this.readFloatArray( count );393 // 3D394 case SEA3D.Stream.VECTOR3D:395 return this.readFloatArray( count );396 // 4D397 case SEA3D.Stream.VECTOR4D:398 return this.readFloatArray( count );399 }400};401SEA3D.Stream.prototype.append = function( data ) {402 var tmp = new ArrayBuffer( this.data.byteLength + data.byteLength );403 tmp.set( new ArrayBuffer( this.data ), 0 );404 tmp.set( new ArrayBuffer( data ), this.data.byteLength );405 this.data = tmp;406};407SEA3D.Stream.prototype.concat = function( position, length ) {408 return new SEA3D.Stream( this.buffer.slice( position, position + length ) );409};410/**411 * @author DataStream.js412 */413SEA3D.Stream.memcpy = function( dst, dstOffset, src, srcOffset, byteLength ) {414 var dstU8 = new Uint8Array( dst, dstOffset, byteLength );415 var srcU8 = new Uint8Array( src, srcOffset, byteLength );416 dstU8.set( srcU8 );417};418//419// UByteArray420//421SEA3D.UByteArray = function() {422 this.ubytes = [];423 this.length = 0;424};425SEA3D.UByteArray.prototype = {426 constructor: SEA3D.UByteArray,427 add : function( ubytes ) {428 this.ubytes.push( ubytes );429 this.length += ubytes.byteLength;430 },431 toBuffer : function() {432 var memcpy = new Uint8Array( this.length );433 for ( var i = 0, offset = 0; i < this.ubytes.length; i ++ ) {434 memcpy.set( this.ubytes[ i ], offset );435 offset += this.ubytes[ i ].byteLength;436 }437 return memcpy.buffer;438 }439};440//441// Math442//443SEA3D.Math = {444 DEGREES : 180 / Math.PI,445 RADIANS : Math.PI / 180446};447SEA3D.Math.angle = function( val ) {448 var ang = 180,449 inv = val < 0;450 val = ( inv ? - val : val ) % 360;451 if ( val > ang ) {452 val = - ang + ( val - ang );453 }454 return ( inv ? - val : val );455};456SEA3D.Math.lerpAngle = function( val, tar, t ) {457 if ( Math.abs( val - tar ) > 180 ) {458 if ( val > tar ) {459 tar += 360;460 }461 else {462 tar -= 360;463 }464 }465 val += ( tar - val ) * t;466 return SEA3D.Math.angle( val );467};468SEA3D.Math.lerpColor = function( val, tar, t ) {469 var a0 = val >> 24 & 0xff,470 r0 = val >> 16 & 0xff,471 g0 = val >> 8 & 0xff,472 b0 = val & 0xff;473 var a1 = tar >> 24 & 0xff,474 r1 = tar >> 16 & 0xff,475 g1 = tar >> 8 & 0xff,476 b1 = tar & 0xff;477 a0 += ( a1 - a0 ) * t;478 r0 += ( r1 - r0 ) * t;479 g0 += ( g1 - g0 ) * t;480 b0 += ( b1 - b0 ) * t;481 return a0 << 24 | r0 << 16 | g0 << 8 | b0;482};483SEA3D.Math.lerp = function( val, tar, t ) {484 return val + ( ( tar - val ) * t );485};486SEA3D.Math.lerp1x = function( val, tar, t ) {487 val[ 0 ] += ( tar[ 0 ] - val[ 0 ] ) * t;488};489SEA3D.Math.lerp3x = function( val, tar, t ) {490 val[ 0 ] += ( tar[ 0 ] - val[ 0 ] ) * t;491 val[ 1 ] += ( tar[ 1 ] - val[ 1 ] ) * t;492 val[ 2 ] += ( tar[ 2 ] - val[ 2 ] ) * t;493};494SEA3D.Math.lerpAng1x = function( val, tar, t ) {495 val[ 0 ] = SEA3D.Math.lerpAngle( val[ 0 ], tar[ 0 ], t );496};497SEA3D.Math.lerpColor1x = function( val, tar, t ) {498 val[ 0 ] = SEA3D.Math.lerpColor( val[ 0 ], tar[ 0 ], t );499};500SEA3D.Math.lerpQuat4x = function( val, tar, t ) {501 var x1 = val[ 0 ],502 y1 = val[ 1 ],503 z1 = val[ 2 ],504 w1 = val[ 3 ];505 var x2 = tar[ 0 ],506 y2 = tar[ 1 ],507 z2 = tar[ 2 ],508 w2 = tar[ 3 ];509 var x, y, z, w, l;510 // shortest direction511 if ( x1 * x2 + y1 * y2 + z1 * z2 + w1 * w2 < 0 ) {512 x2 = - x2;513 y2 = - y2;514 z2 = - z2;515 w2 = - w2;516 }517 x = x1 + t * ( x2 - x1 );518 y = y1 + t * ( y2 - y1 );519 z = z1 + t * ( z2 - z1 );520 w = w1 + t * ( w2 - w1 );521 l = 1.0 / Math.sqrt( w * w + x * x + y * y + z * z );522 val[ 0 ] = x * l;523 val[ 1 ] = y * l;524 val[ 2 ] = z * l;525 val[ 3 ] = w * l;526};527//528// Timer529//530SEA3D.Timer = function() {531 this.time = this.start = Date.now();532};533SEA3D.Timer.prototype = {534 constructor: SEA3D.Timer,535 get now () {536 return Date.now();537 },538 get deltaTime () {539 return Date.now() - this.time;540 },541 get elapsedTime () {542 return Date.now() - this.start;543 },544 update: function() {545 this.time = Date.now();546 }547};548//549// Object550//551SEA3D.Object = function( name, data, type, sea3d ) {552 this.name = name;553 this.data = data;554 this.type = type;555 this.sea3d = sea3d;556};557//558// Geometry Base559//560SEA3D.GeometryBase = function( name, data, sea3d ) {561 this.name = name;562 this.data = data;563 this.sea3d = sea3d;564 this.attrib = data.readUShort();565 this.isBig = ( this.attrib & 1 ) != 0;566 // variable uint567 data.readVInt = this.isBig ? data.readUInt : data.readUShort;568 this.numVertex = data.readVInt();569 this.length = this.numVertex * 3;570};571//572// Geometry573//574SEA3D.Geometry = function( name, data, sea3d ) {575 SEA3D.GeometryBase.call( this, name, data, sea3d );576 var i, j, vec, len;577 // NORMAL578 if ( this.attrib & 4 ) {579 this.normal = data.readFloatArray( this.length );580 }581 // TANGENT582 if ( this.attrib & 8 ) {583 this.tangent = data.readFloatArray( this.length );584 }585 // UV586 if ( this.attrib & 32 ) {587 this.uv = [];588 this.uv.length = data.readUByte();589 len = this.numVertex * 2;590 i = 0;591 while ( i < this.uv.length ) {592 // UV VERTEX DATA593 this.uv[ i ++ ] = data.readFloatArray( len );594 }595 }596 // JOINT-INDEXES / WEIGHTS597 if ( this.attrib & 64 ) {598 this.jointPerVertex = data.readUByte();599 var jntLen = this.numVertex * this.jointPerVertex;600 this.joint = data.readUShortArray( jntLen );601 this.weight = data.readFloatArray( jntLen );602 }603 // VERTEX_COLOR604 if ( this.attrib & 128 ) {605 var colorAttrib = data.readUByte();606 this.numColor = ( ( ( colorAttrib & 64 ) >> 6 ) | ( ( colorAttrib & 128 ) >> 6 ) ) + 1;607 this.color = [];608 for ( i = 0, len = colorAttrib & 15; i < len; i ++ ) {609 this.color.push( data.readFloatArray( this.numVertex * this.numColor ) );610 }611 }612 // VERTEX613 this.vertex = data.readFloatArray( this.length );614 // SUB-MESHES615 var count = data.readUByte();616 this.groups = [];617 if ( this.attrib & 1024 ) {618 // INDEXES619 for ( i = 0, len = 0; i < count; i ++ ) {620 j = data.readVInt() * 3;621 this.groups.push( {622 start : len,623 count : j,624 } );625 len += j;626 }627 this.indexes = this.isBig ? data.readUIntArray( len ) : data.readUShortArray( len );628 } else {629 // INDEXES630 var stride = this.isBig ? 4 : 2,631 bytearray = new SEA3D.UByteArray();632 for ( i = 0, j = 0; i < count; i ++ ) {633 len = data.readVInt() * 3;634 this.groups.push( {635 start : j,636 count : len,637 } );638 j += len;639 bytearray.add( data.readUByteArray( len * stride ) );640 }641 this.indexes = this.isBig ? new Uint32Array( bytearray.toBuffer() ) : new Uint16Array( bytearray.toBuffer() );642 }643};644SEA3D.Geometry.prototype = Object.create( SEA3D.GeometryBase.prototype );645SEA3D.Geometry.prototype.constructor = SEA3D.Geometry;646SEA3D.Geometry.prototype.type = "geo";647//648// Geometry Delta Base649//650SEA3D.GeometryDeltaBase = function( name, data, sea3d ) {651 this.name = name;652 this.data = data;653 this.sea3d = sea3d;654 this.attrib = data.readUShort();655 this.numVertex = data.readUInteger();656 this.length = this.numVertex * 3;657 if ( this.attrib & 1 ) {658 data.readNumber = data.readByte;659 this.numDiv = 0xFF / 2;660 }661 else {662 data.readNumber = data.readShort;663 numDiv = 0xFFFF / 2;664 }665};666//667// Geometry Delta668//669SEA3D.GeometryDelta = function( name, data, sea3d ) {670 SEA3D.GeometryDeltaBase.call( this, name, data, sea3d );671 var i, j, start, delta, len, vec;672 // NORMAL673 if ( this.attrib & 4 ) {674 delta = data.readFloat();675 this.normal = new Float32Array( this.length );676 i = 0;677 while ( i < this.length ) {678 this.normal[ i ++ ] = ( data.readNumber() / this.numDiv ) * delta;679 }680 }681 // TANGENT682 if ( this.attrib & 8 ) {683 delta = data.readFloat();684 this.tangent = new Float32Array( this.length );685 i = 0;686 while ( i < this.length ) {687 this.tangent[ i ++ ] = ( data.readNumber() / this.numDiv ) * delta;688 }689 }690 // UV691 if ( this.attrib & 32 ) {692 this.uv = [];693 this.uv.length = data.readUByte();694 var uvLen = this.numVertex * 2;695 i = 0;696 while ( i < this.uv.length ) {697 // UV VERTEX DATA698 delta = data.readFloat();699 this.uv[ i ++ ] = vec = new Float32Array( uvLen );700 j = 0;701 while ( j < uvLen ) {702 vec[ j ++ ] = ( data.readNumber() / this.numDiv ) * delta;703 }704 }705 }706 // JOINT-INDEXES / WEIGHTS707 if ( this.attrib & 64 ) {708 this.jointPerVertex = data.readUByte();709 var jntLen = this.numVertex * this.jointPerVertex;710 this.joint = new Uint16Array( jntLen );711 this.weight = new Float32Array( jntLen );712 i = 0;713 while ( i < jntLen ) {714 this.joint[ i ++ ] = data.readUInteger();715 }716 i = 0;717 while ( i < jntLen ) {718 this.weight[ i ++ ] = ( data.readNumber() / this.numDiv ) * 1;719 }720 }721 // VERTEX_COLOR722 if ( this.attrib & 128 ) {723 var colorAttrib = data.readUByte(),724 numColorData = ( ( ( colorAttrib & 64 ) >> 6 ) | ( ( colorAttrib & 128 ) >> 6 ) ) + 1,725 colorCount = this.numVertex * 4;726 this.color = [];727 this.color.length = colorAttrib & 15;728 this.numColor = 4;729 for ( i = 0; i < this.color.length; i ++ ) {730 var vColor = new Float32Array( colorCount );731 switch ( numColorData )732 {733 case 1:734 j = 0;735 while ( j < colorCount ) {736 vColor[ j ++ ] = data.readUByte() / 0xFF;737 vColor[ j ++ ] = 0;738 vColor[ j ++ ] = 0;739 vColor[ j ++ ] = 1;740 }741 break;742 case 2:743 j = 0;744 while ( j < colorCount ) {745 vColor[ j ++ ] = data.readUByte() / 0xFF;746 vColor[ j ++ ] = data.readUByte() / 0xFF;747 vColor[ j ++ ] = 0;748 vColor[ j ++ ] = 1;749 }750 break;751 case 3:752 j = 0;753 while ( j < colorCount ) {754 vColor[ j ++ ] = data.readUByte() / 0xFF;755 vColor[ j ++ ] = data.readUByte() / 0xFF;756 vColor[ j ++ ] = data.readUByte() / 0xFF;757 vColor[ j ++ ] = 1;758 }759 break;760 case 4:761 j = 0;762 while ( j < colorCount ) {763 vColor[ j ++ ] = data.readUByte() / 0xFF;764 vColor[ j ++ ] = data.readUByte() / 0xFF;765 vColor[ j ++ ] = data.readUByte() / 0xFF;766 vColor[ j ++ ] = data.readUByte() / 0xFF;767 }768 break;769 }770 this.color[ i ] = vColor;771 }772 }773 // VERTEX774 delta = data.readFloat();775 this.vertex = new Float32Array( this.length );776 i = 0;777 while ( i < this.length ) {778 this.vertex[ i ++ ] = ( data.readNumber() / this.numDiv ) * delta;779 }780 // SUB-MESHES781 var count = data.readUByte();782 this.indexes = vec = [];783 this.groups = [];784 // INDEXES785 j = 0;786 for ( i = 0; i < count; i ++ ) {787 len = data.readVInt() * 3;788 this.groups.push( {789 start : j,790 count : len,791 } );792 len += j;793 while ( j < len ) {794 vec[ j ++ ] = data.readVInt();795 }796 }797 // SUB-MESHES798 var count = data.readUByte();799 this.indexes = vec = [];800 this.groups = [];801 // INDEXES802 if ( this.attrib & 2 ) {803 // POLYGON804 for ( i = 0; i < count; i ++ ) {805 len = data.readUInteger();806 start = vec.length;807 for ( j = 0; j < len; j ++ ) {808 var a = data.readUInteger(),809 b = data.readUInteger(),810 c = data.readUInteger(),811 d = data.readUInteger();812 vec.push( a );813 vec.push( b );814 vec.push( c );815 if ( d > 0 )816 {817 vec.push( c );818 vec.push( d + 1 );819 vec.push( a );820 }821 else continue;822 }823 this.groups.push( {824 start : start,825 count : vec.length - start,826 } );827 }828 } else {829 // TRIANGLE830 j = 0;831 for ( i = 0; i < count; i ++ ) {832 len = data.readUInteger() * 3;833 this.groups.push( {834 start : j,835 count : len,836 } );837 len += j;838 while ( j < len ) {839 vec[ j ++ ] = data.readUInteger();840 }841 }842 }843};844SEA3D.GeometryDeltaBase.prototype = Object.create( SEA3D.GeometryDeltaBase.prototype );845SEA3D.GeometryDeltaBase.prototype.constructor = SEA3D.GeometryDelta;846SEA3D.GeometryDelta.prototype.type = "geDL";847//848// Object3D849//850SEA3D.Object3D = function( name, data, sea3d ) {851 this.name = name;852 this.data = data;853 this.sea3d = sea3d;854 this.isStatic = false;855 this.visible = true;856 this.attrib = data.readUShort();857 if ( this.attrib & 1 ) this.parent = sea3d.getObject( data.readUInt() );858 if ( this.attrib & 2 ) this.animations = data.readAnimationList( sea3d );859 if ( this.attrib & 4 ) this.scripts = data.readScriptList( sea3d );860 if ( this.attrib & 16 ) this.properties = sea3d.getObject( data.readUInt() );861 if ( this.attrib & 32 ) {862 var objectType = data.readUByte();863 this.isStatic = ( objectType & 1 ) != 0;864 this.visible = ( objectType & 2 ) != 0;865 }866};867SEA3D.Object3D.prototype.readTag = function( kind, data, size ) {868};869//870// Entity3D871//872SEA3D.Entity3D = function( name, data, sea3d ) {873 SEA3D.Object3D.call( this, name, data, sea3d );874 this.castShadows = true;875 if ( this.attrib & 64 ) {876 var lightType = data.readUByte();877 this.castShadows = ( lightType & 1 ) == 0;878 }879};880SEA3D.Entity3D.prototype = Object.create( SEA3D.Object3D.prototype );881SEA3D.Entity3D.prototype.constructor = SEA3D.Entity3D;882//883// Sound3D884//885SEA3D.Sound3D = function( name, data, sea3d ) {886 SEA3D.Object3D.call( this, name, data, sea3d );887 this.autoPlay = ( this.attrib & 64 ) != 0;888 if ( this.attrib & 128 ) this.mixer = sea3d.getObject( data.readUInt() );889 this.sound = sea3d.getObject( data.readUInt() );890 this.volume = data.readFloat();891};892SEA3D.Sound3D.prototype = Object.create( SEA3D.Object3D.prototype );893SEA3D.Sound3D.prototype.constructor = SEA3D.Sound3D;894//895// Sound Point896//897SEA3D.SoundPoint = function( name, data, sea3d ) {898 SEA3D.Sound3D.call( this, name, data, sea3d );899 this.position = data.readVector3();900 this.distance = data.readFloat();901 data.readTags( this.readTag.bind( this ) );902};903SEA3D.SoundPoint.prototype = Object.create( SEA3D.Sound3D.prototype );904SEA3D.SoundPoint.prototype.constructor = SEA3D.SoundPoint;905SEA3D.SoundPoint.prototype.type = "sp";906//907// Container3D908//909SEA3D.Container3D = function( name, data, sea3d ) {910 SEA3D.Object3D.call( this, name, data, sea3d );911 this.transform = data.readMatrix();912 data.readTags( this.readTag.bind( this ) );913};914SEA3D.Container3D.prototype = Object.create( SEA3D.Object3D.prototype );915SEA3D.Container3D.prototype.constructor = SEA3D.Container3D;916SEA3D.Container3D.prototype.type = "c3d";917//918// Texture URL919//920SEA3D.TextureURL = function( name, data, sea3d ) {921 this.name = name;922 this.data = data;923 this.sea3d = sea3d;924 this.url = data.readUTF( data.length );925};926SEA3D.TextureURL.prototype.type = "urlT";927//928// Actions929//930SEA3D.Actions = function( name, data, sea3d ) {931 this.name = name;932 this.data = data;933 this.sea3d = sea3d;934 this.count = data.readUInt();935 this.actions = [];936 for ( var i = 0; i < this.count; i ++ ) {937 var flag = data.readUByte();938 var kind = data.readUShort();939 var size = data.readUShort();940 var position = data.position;941 var act = this.actions[ i ] = { kind: kind };942 // range of animation943 if ( flag & 1 ) {944 // start and count in frames945 act.range = [ data.readUInt(), data.readUInt() ];946 }947 // time948 if ( flag & 2 ) {949 act.time = data.readUInt();950 }951 // easing952 if ( flag & 4 ) {953 act.intrpl = data.readInterpolation();954 if ( act.intrpl.indexOf( 'back.' ) == 0 ) {955 act.intrplParam0 = data.readFloat();956 }957 else if ( act.intrpl.indexOf( 'elastic.' ) == 0 ) {958 act.intrplParam0 = data.readFloat();959 act.intrplParam1 = data.readFloat();960 }961 }962 switch ( kind ) {963 case SEA3D.Actions.RTT_TARGET:964 act.source = sea3d.getObject( data.readUInt() );965 act.target = sea3d.getObject( data.readUInt() );966 break;967 case SEA3D.Actions.LOOK_AT:968 act.source = sea3d.getObject( data.readUInt() );969 act.target = sea3d.getObject( data.readUInt() );970 break;971 case SEA3D.Actions.PLAY_SOUND:972 act.sound = sea3d.getObject( data.readUInt() );973 act.offset = data.readUInt();974 break;975 case SEA3D.Actions.PLAY_ANIMATION:976 act.object = sea3d.getObject( data.readUInt() );977 act.name = data.readUTF8();978 break;979 case SEA3D.Actions.FOG:980 act.color = data.readUInt24();981 act.min = data.readFloat();982 act.max = data.readFloat();983 break;984 case SEA3D.Actions.ENVIRONMENT:985 act.texture = sea3d.getObject( data.readUInt() );986 break;987 case SEA3D.Actions.ENVIRONMENT_COLOR:988 act.color = data.readUInt24F();989 break;990 case SEA3D.Actions.CAMERA:991 act.camera = sea3d.getObject( data.readUInt() );992 break;993 case SEA3D.Actions.SCRIPTS:994 act.scripts = data.readScriptList( sea3d );995 break;996 case SEA3D.Actions.CLASS_OF:997 act.classof = sea3d.getObject( data.readUInt() );998 break;999 default:1000 console.log( "Action \"" + kind + "\" not found." );1001 break;1002 }1003 data.position = position + size;1004 }1005};1006SEA3D.Actions.SCENE = 0;1007SEA3D.Actions.ENVIRONMENT_COLOR = 1;1008SEA3D.Actions.ENVIRONMENT = 2;1009SEA3D.Actions.FOG = 3;1010SEA3D.Actions.PLAY_ANIMATION = 4;1011SEA3D.Actions.PLAY_SOUND = 5;1012SEA3D.Actions.ANIMATION_AUDIO_SYNC = 6;1013SEA3D.Actions.LOOK_AT = 7;1014SEA3D.Actions.RTT_TARGET = 8;1015SEA3D.Actions.CAMERA = 9;1016SEA3D.Actions.SCRIPTS = 10;1017SEA3D.Actions.CLASS_OF = 11;1018SEA3D.Actions.prototype.type = "act";1019//1020// Properties1021//1022SEA3D.Properties = function( name, data, sea3d ) {1023 this.name = name;1024 this.data = data;1025 this.sea3d = sea3d;1026 this.tag = data.readProperties( sea3d );1027 this.tag.__name = name;1028};1029SEA3D.Properties.prototype.type = "prop";1030//1031// File Info1032//1033SEA3D.FileInfo = function( name, data, sea3d ) {1034 this.name = name;1035 this.data = data;1036 this.sea3d = sea3d;1037 this.tag = data.readProperties( sea3d );1038 this.tag.__name = name;1039 sea3d.info = this.tag;1040};1041SEA3D.FileInfo.prototype.type = "info";1042//1043// Java Script1044//1045SEA3D.JavaScript = function( name, data, sea3d ) {1046 this.name = name;1047 this.data = data;1048 this.sea3d = sea3d;1049 this.src = data.readUTF( data.length );1050};1051SEA3D.JavaScript.prototype.type = "js";1052//1053// Java Script Method1054//1055SEA3D.JavaScriptMethod = function( name, data, sea3d ) {1056 this.name = name;1057 this.data = data;1058 this.sea3d = sea3d;1059 var count = data.readUShort();1060 this.methods = {};1061 for ( var i = 0; i < count; i ++ ) {1062 var flag = data.readUByte();1063 var method = data.readUTF8();1064 this.methods[ method ] = {1065 src : data.readUTF8Long()1066 }1067 }1068};1069SEA3D.JavaScriptMethod.prototype.type = "jsm";1070//1071// GLSL1072//1073SEA3D.GLSL = function( name, data, sea3d ) {1074 this.name = name;1075 this.data = data;1076 this.sea3d = sea3d;1077 this.src = data.readUTF( data.length );1078};1079SEA3D.GLSL.prototype.type = "glsl";1080//1081// Dummy1082//1083SEA3D.Dummy = function( name, data, sea3d ) {1084 SEA3D.Object3D.call( this, name, data, sea3d );1085 this.transform = data.readMatrix();1086 this.width = data.readFloat();1087 this.height = data.readFloat();1088 this.depth = data.readFloat();1089 data.readTags( this.readTag.bind( this ) );1090};1091SEA3D.Dummy.prototype = Object.create( SEA3D.Object3D.prototype );1092SEA3D.Dummy.prototype.constructor = SEA3D.Dummy;1093SEA3D.Dummy.prototype.type = "dmy";1094//1095// Line1096//1097SEA3D.Line = function( name, data, sea3d ) {1098 SEA3D.Object3D.call( this, name, data, sea3d );1099 this.count = ( this.attrib & 64 ? data.readUInt() : data.readUShort() ) * 3;1100 this.closed = ( this.attrib & 128 ) != 0;1101 this.transform = data.readMatrix();1102 this.vertex = [];1103 var i = 0;1104 while ( i < this.count ) {1105 this.vertex[ i ++ ] = data.readFloat();1106 }1107 data.readTags( this.readTag.bind( this ) );1108};1109SEA3D.Line.prototype = Object.create( SEA3D.Object3D.prototype );1110SEA3D.Line.prototype.constructor = SEA3D.Line;1111SEA3D.Line.prototype.type = "line";1112//1113// Sprite1114//1115SEA3D.Sprite = function( name, data, sea3d ) {1116 SEA3D.Object3D.call( this, name, data, sea3d );1117 if ( this.attrib & 256 ) {1118 this.material = sea3d.getObject( data.readUInt() );1119 }1120 this.position = data.readVector3();1121 this.width = data.readFloat();1122 this.height = data.readFloat();1123 data.readTags( this.readTag.bind( this ) );1124};1125SEA3D.Sprite.prototype = Object.create( SEA3D.Object3D.prototype );1126SEA3D.Sprite.prototype.constructor = SEA3D.Sprite;1127SEA3D.Sprite.prototype.type = "m2d";1128//1129// Mesh1130//1131SEA3D.Mesh = function( name, data, sea3d ) {1132 SEA3D.Entity3D.call( this, name, data, sea3d );1133 // MATERIAL1134 if ( this.attrib & 256 ) {1135 this.material = [];1136 var len = data.readUByte();1137 if ( len == 1 ) this.material[ 0 ] = sea3d.getObject( data.readUInt() );1138 else {1139 var i = 0;1140 while ( i < len ) {1141 var matIndex = data.readUInt();1142 if ( matIndex > 0 ) this.material[ i ++ ] = sea3d.getObject( matIndex - 1 );1143 else this.material[ i ++ ] = undefined;1144 }1145 }1146 }1147 if ( this.attrib & 512 ) {1148 this.modifiers = [];1149 var len = data.readUByte();1150 for ( var i = 0; i < len; i ++ ) {1151 this.modifiers[ i ] = sea3d.getObject( data.readUInt() );1152 }1153 }1154 if ( this.attrib & 1024 ) {1155 this.reference = {1156 type : data.readUByte(),1157 ref : sea3d.getObject( data.readUInt() )1158 };1159 }1160 this.transform = data.readMatrix();1161 this.geometry = sea3d.getObject( data.readUInt() );1162 data.readTags( this.readTag.bind( this ) );1163};1164SEA3D.Mesh.prototype = Object.create( SEA3D.Entity3D.prototype );1165SEA3D.Mesh.prototype.constructor = SEA3D.Mesh;1166SEA3D.Mesh.prototype.type = "m3d";1167//1168// Skeleton1169//1170SEA3D.Skeleton = function( name, data, sea3d ) {1171 this.name = name;1172 this.data = data;1173 this.sea3d = sea3d;1174 var length = data.readUShort();1175 this.joint = [];1176 for ( var i = 0; i < length; i ++ ) {1177 this.joint[ i ] = {1178 name: data.readUTF8(),1179 parentIndex: data.readUShort() - 1,1180 inverseBindMatrix: data.readMatrix()1181 };1182 }1183};1184SEA3D.Skeleton.prototype.type = "skl";1185//1186// Skeleton Local1187//1188SEA3D.SkeletonLocal = function( name, data, sea3d ) {1189 this.name = name;1190 this.data = data;1191 this.sea3d = sea3d;1192 var length = data.readUShort();1193 this.joint = [];1194 for ( var i = 0; i < length; i ++ ) {1195 this.joint[ i ] = {1196 name: data.readUTF8(),1197 parentIndex: data.readUShort() - 1,1198 // POSITION XYZ1199 x: data.readFloat(),1200 y: data.readFloat(),1201 z: data.readFloat(),1202 // QUATERNION XYZW1203 qx: data.readFloat(),1204 qy: data.readFloat(),1205 qz: data.readFloat(),1206 qw: data.readFloat()1207 };1208 }1209};1210SEA3D.SkeletonLocal.prototype.type = "sklq";1211//1212// Animation Base1213//1214SEA3D.AnimationBase = function( name, data, sea3d ) {1215 this.name = name;1216 this.data = data;1217 this.sea3d = sea3d;1218 var flag = data.readUByte();1219 this.sequence = [];1220 if ( flag & 1 ) {1221 var count = data.readUShort();1222 for ( var i = 0; i < count; i ++ ) {1223 flag = data.readUByte();1224 this.sequence[ i ] = {1225 name: data.readUTF8(),1226 start: data.readUInt(),1227 count: data.readUInt(),1228 repeat: ( flag & 1 ) != 0,1229 intrpl: ( flag & 2 ) == 01230 };1231 }1232 }1233 this.frameRate = data.readUByte();1234 this.numFrames = data.readUInt();1235 // no contains sequence1236 if ( this.sequence.length == 0 ) {1237 this.sequence[ 0 ] = { name: "root", start: 0, count: this.numFrames, repeat: true, intrpl: true };1238 }1239};1240//1241// Animation1242//1243SEA3D.Animation = function( name, data, sea3d ) {1244 SEA3D.AnimationBase.call( this, name, data, sea3d );1245 this.dataList = [];1246 for ( var i = 0, l = data.readUByte(); i < l; i ++ ) {1247 var kind = data.readUShort(),1248 type = data.readUByte();1249 var anmRaw = data.readVector( type, this.numFrames, 0 );1250 this.dataList.push( {1251 kind: kind,1252 type: type,1253 blockSize: SEA3D.Stream.sizeOf( type ),1254 data: anmRaw1255 } );1256 }1257};1258SEA3D.Animation.POSITION = 0;1259SEA3D.Animation.ROTATION = 1;1260SEA3D.Animation.SCALE = 2;1261SEA3D.Animation.COLOR = 3;1262SEA3D.Animation.MULTIPLIER = 4;1263SEA3D.Animation.ATTENUATION_START = 5;1264SEA3D.Animation.ATTENUATION_END = 6;1265SEA3D.Animation.FOV = 7;1266SEA3D.Animation.OFFSET_U = 8;1267SEA3D.Animation.OFFSET_V = 9;1268SEA3D.Animation.SCALE_U = 10;1269SEA3D.Animation.SCALE_V = 11;1270SEA3D.Animation.ANGLE = 12;1271SEA3D.Animation.ALPHA = 13;1272SEA3D.Animation.VOLUME = 14;1273SEA3D.Animation.DefaultLerpFuncs = [1274 SEA3D.Math.lerp3x, // POSITION1275 SEA3D.Math.lerpQuat4x, // ROTATION1276 SEA3D.Math.lerp3x, // SCALE1277 SEA3D.Math.lerpColor1x, // COLOR1278 SEA3D.Math.lerp1x, // MULTIPLIER1279 SEA3D.Math.lerp1x, // ATTENUATION_START1280 SEA3D.Math.lerp1x, // ATTENUATION_END1281 SEA3D.Math.lerp1x, // FOV1282 SEA3D.Math.lerp1x, // OFFSET_U1283 SEA3D.Math.lerp1x, // OFFSET_V1284 SEA3D.Math.lerp1x, // SCALE_U1285 SEA3D.Math.lerp1x, // SCALE_V1286 SEA3D.Math.lerpAng1x, // ANGLE1287 SEA3D.Math.lerp1x, // ALPHA1288 SEA3D.Math.lerp1x // VOLUME1289];1290SEA3D.Animation.prototype = Object.create( SEA3D.AnimationBase.prototype );1291SEA3D.Animation.prototype.constructor = SEA3D.Animation;1292SEA3D.Animation.prototype.type = "anm";1293//1294// Skeleton Animation1295//1296SEA3D.SkeletonAnimation = function( name, data, sea3d ) {1297 SEA3D.AnimationBase.call( this, name, data, sea3d );1298 this.name = name;1299 this.data = data;1300 this.sea3d = sea3d;1301 this.numJoints = data.readUShort();1302 this.raw = data.readFloatArray( this.numFrames * this.numJoints * 7 );1303};1304SEA3D.SkeletonAnimation.prototype.type = "skla";1305//1306// Morph1307//1308SEA3D.Morph = function( name, data, sea3d ) {1309 SEA3D.GeometryBase.call( this, name, data, sea3d );1310 var useVertex = ( this.attrib & 2 ) != 0;1311 var useNormal = ( this.attrib & 4 ) != 0;1312 var nodeCount = data.readUShort();1313 this.node = [];1314 for ( var i = 0; i < nodeCount; i ++ ) {1315 var nodeName = data.readUTF8(),1316 verts, norms;1317 if ( useVertex ) verts = data.readFloatArray( this.length );1318 if ( useNormal ) norms = data.readFloatArray( this.length );1319 this.node[ i ] = { vertex: verts, normal: norms, name: nodeName }1320 }1321};1322SEA3D.Morph.prototype = Object.create( SEA3D.GeometryBase.prototype );1323SEA3D.Morph.prototype.constructor = SEA3D.Morph;1324SEA3D.Morph.prototype.type = "mph";1325//1326// Vertex Animation1327//1328SEA3D.VertexAnimation = function( name, data, sea3d ) {1329 SEA3D.AnimationBase.call( this, name, data, sea3d );1330 var flags = data.readUByte();1331 this.isBig = ( flags & 1 ) != 0;1332 data.readVInt = this.isBig ? data.readUInt : data.readUShort;1333 this.numVertex = data.readVInt();1334 this.length = this.numVertex * 3;1335 var useVertex = ( flags & 2 ) != 0;1336 var useNormal = ( flags & 4 ) != 0;1337 this.frame = [];1338 var i, verts, norms;1339 for ( i = 0; i < this.numFrames; i ++ ) {1340 if ( useVertex ) verts = data.readFloatArray( this.length );1341 if ( useNormal ) norms = data.readFloatArray( this.length );1342 this.frame[ i ] = { vertex: verts, normal: norms }1343 }1344};1345SEA3D.VertexAnimation.prototype = Object.create( SEA3D.AnimationBase.prototype );1346SEA3D.VertexAnimation.prototype.constructor = SEA3D.VertexAnimation;1347SEA3D.VertexAnimation.prototype.type = "vtxa";1348//1349// Camera1350//1351SEA3D.Camera = function( name, data, sea3d ) {1352 SEA3D.Object3D.call( this, name, data, sea3d );1353 if ( this.attrib & 64 ) {1354 this.dof = {1355 distance: data.readFloat(),1356 range: data.readFloat()1357 };1358 }1359 this.transform = data.readMatrix();1360 this.fov = data.readFloat();1361 data.readTags( this.readTag.bind( this ) );1362};1363SEA3D.Camera.prototype = Object.create( SEA3D.Object3D.prototype );1364SEA3D.Camera.prototype.constructor = SEA3D.Camera;1365SEA3D.Camera.prototype.type = "cam";1366//1367// Orthographic Camera1368//1369SEA3D.OrthographicCamera = function( name, data, sea3d ) {1370 SEA3D.Object3D.call( this, name, data, sea3d );1371 this.transform = data.readMatrix();1372 this.height = data.readFloat();1373 data.readTags( this.readTag.bind( this ) );1374};1375SEA3D.OrthographicCamera.prototype = Object.create( SEA3D.Object3D.prototype );1376SEA3D.OrthographicCamera.prototype.constructor = SEA3D.OrthographicCamera;1377SEA3D.OrthographicCamera.prototype.type = "camo";1378//1379// Joint Object1380//1381SEA3D.JointObject = function( name, data, sea3d ) {1382 SEA3D.Object3D.call( this, name, data, sea3d );1383 this.target = sea3d.getObject( data.readUInt() );1384 this.joint = data.readUShort();1385 data.readTags( this.readTag.bind( this ) );1386};1387SEA3D.JointObject.prototype = Object.create( SEA3D.Object3D.prototype );1388SEA3D.JointObject.prototype.constructor = SEA3D.JointObject;1389SEA3D.JointObject.prototype.type = "jnt";1390//1391// Light1392//1393SEA3D.Light = function( name, data, sea3d ) {1394 SEA3D.Object3D.call( this, name, data, sea3d );1395 this.attenStart = Number.MAX_VALUE;1396 this.attenEnd = Number.MAX_VALUE;1397 if ( this.attrib & 64 ) {1398 var shadowHeader = data.readUByte();1399 this.shadow = {}1400 this.shadow.opacity = shadowHeader & 1 ? data.readFloat() : 1;1401 this.shadow.color = shadowHeader & 2 ? data.readUInt24() : 0x000000;1402 }1403 if ( this.attrib & 512 ) {1404 this.attenStart = data.readFloat();1405 this.attenEnd = data.readFloat();1406 }1407 this.color = data.readUInt24();1408 this.multiplier = data.readFloat();1409};1410SEA3D.Light.prototype = Object.create( SEA3D.Object3D.prototype );1411SEA3D.Light.prototype.constructor = SEA3D.Light;1412//1413// Point Light1414//1415SEA3D.PointLight = function( name, data, sea3d ) {1416 SEA3D.Light.call( this, name, data, sea3d );1417 if ( this.attrib & 128 ) {1418 this.attenuation = {1419 start: data.readFloat(),1420 end: data.readFloat()1421 }1422 }1423 this.position = data.readVector3();1424 data.readTags( this.readTag.bind( this ) );1425};1426SEA3D.PointLight.prototype = Object.create( SEA3D.Light.prototype );1427SEA3D.PointLight.prototype.constructor = SEA3D.PointLight;1428SEA3D.PointLight.prototype.type = "plht";1429//1430// Hemisphere Light1431//1432SEA3D.HemisphereLight = function( name, data, sea3d ) {1433 SEA3D.Light.call( this, name, data, sea3d );1434 if ( this.attrib & 128 ) {1435 this.attenuation = {1436 start: data.readFloat(),1437 end: data.readFloat()1438 }1439 }1440 this.secondColor = data.readUInt24();1441 data.readTags( this.readTag.bind( this ) );1442};1443SEA3D.HemisphereLight.prototype = Object.create( SEA3D.Light.prototype );1444SEA3D.HemisphereLight.prototype.constructor = SEA3D.HemisphereLight;1445SEA3D.HemisphereLight.prototype.type = "hlht";1446//1447// Ambient Light1448//1449SEA3D.AmbientLight = function( name, data, sea3d ) {1450 SEA3D.Light.call( this, name, data, sea3d );1451 data.readTags( this.readTag.bind( this ) );1452};1453SEA3D.AmbientLight.prototype = Object.create( SEA3D.Light.prototype );1454SEA3D.AmbientLight.prototype.constructor = SEA3D.AmbientLight;1455SEA3D.AmbientLight.prototype.type = "alht";1456//1457// Directional Light1458//1459SEA3D.DirectionalLight = function( name, data, sea3d ) {1460 SEA3D.Light.call( this, name, data, sea3d );1461 this.transform = data.readMatrix();1462 data.readTags( this.readTag.bind( this ) );1463};1464SEA3D.DirectionalLight.prototype = Object.create( SEA3D.Light.prototype );1465SEA3D.DirectionalLight.prototype.constructor = SEA3D.DirectionalLight;1466SEA3D.DirectionalLight.prototype.type = "dlht";1467//1468// Material1469//1470SEA3D.Material = function( name, data, sea3d ) {1471 this.name = name;1472 this.data = data;1473 this.sea3d = sea3d;1474 this.technique = [];1475 this.attrib = data.readUShort();1476 this.alpha = 1;1477 this.blendMode = "normal";1478 this.alphaThreshold = .5;1479 this.physical = false;1480 this.anisotropy = false;1481 this.bothSides = ( this.attrib & 1 ) != 0;1482 this.receiveLights = ( this.attrib & 2 ) == 0;1483 this.receiveShadows = ( this.attrib & 4 ) == 0;1484 this.receiveFog = ( this.attrib & 8 ) == 0;1485 this.smooth = ( this.attrib & 16 ) == 0;1486 if ( this.attrib & 32 )1487 this.alpha = data.readFloat();1488 if ( this.attrib & 64 )1489 this.blendMode = data.readBlendMode();1490 if ( this.attrib & 128 )1491 this.animations = data.readAnimationList( sea3d );1492 this.depthMask = ( this.attrib & 256 ) == 0;1493 this.depthTest = ( this.attrib & 512 ) == 0;1494 var count = data.readUByte();1495 for ( var i = 0; i < count; ++ i ) {1496 var kind = data.readUShort();1497 var size = data.readUShort();1498 var pos = data.position;1499 var tech, methodAttrib;1500 switch ( kind ) {1501 case SEA3D.Material.PHONG:1502 tech = {1503 ambientColor: data.readUInt24(),1504 diffuseColor: data.readUInt24(),1505 specularColor: data.readUInt24(),1506 specular: data.readFloat(),1507 gloss: data.readFloat()1508 };1509 break;1510 case SEA3D.Material.PHYSICAL:1511 this.physical = true;1512 tech = {1513 color: data.readUInt24(),1514 roughness: data.readFloat(),1515 metalness: data.readFloat()1516 };1517 break;1518 case SEA3D.Material.ANISOTROPIC:1519 this.anisotropy = true;1520 break;1521 case SEA3D.Material.COMPOSITE_TEXTURE:1522 tech = {1523 composite: sea3d.getObject( data.readUInt() )1524 };1525 break;1526 case SEA3D.Material.DIFFUSE_MAP:1527 tech = {1528 texture: sea3d.getObject( data.readUInt() )1529 };1530 break;1531 case SEA3D.Material.SPECULAR_MAP:1532 tech = {1533 texture: sea3d.getObject( data.readUInt() )1534 };1535 break;1536 case SEA3D.Material.NORMAL_MAP:1537 tech = {1538 texture: sea3d.getObject( data.readUInt() )1539 };1540 break;1541 case SEA3D.Material.REFLECTION:1542 case SEA3D.Material.FRESNEL_REFLECTION:1543 tech = {1544 texture: sea3d.getObject( data.readUInt() ),1545 alpha: data.readFloat()1546 };1547 if ( kind == SEA3D.Material.FRESNEL_REFLECTION ) {1548 tech.power = data.readFloat();1549 tech.normal = data.readFloat();1550 }1551 break;1552 case SEA3D.Material.REFRACTION:1553 tech = {1554 texture: sea3d.getObject( data.readUInt() ),1555 alpha: data.readFloat(),1556 ior: data.readFloat()1557 };1558 break;1559 case SEA3D.Material.RIM:1560 tech = {1561 color: data.readUInt24(),1562 strength: data.readFloat(),1563 power: data.readFloat(),1564 blendMode: data.readBlendMode()1565 };1566 break;1567 case SEA3D.Material.LIGHT_MAP:1568 tech = {1569 texture: sea3d.getObject( data.readUInt() ),1570 channel: data.readUByte(),1571 blendMode: data.readBlendMode()1572 };1573 break;1574 case SEA3D.Material.DETAIL_MAP:1575 tech = {1576 texture: sea3d.getObject( data.readUInt() ),1577 scale: data.readFloat(),1578 blendMode: data.readBlendMode()1579 };1580 break;1581 case SEA3D.Material.CEL:1582 tech = {1583 color: data.readUInt24(),1584 levels: data.readUByte(),1585 size: data.readFloat(),1586 specularCutOff: data.readFloat(),1587 smoothness: data.readFloat()1588 };1589 break;1590 case SEA3D.Material.TRANSLUCENT:1591 tech = {1592 translucency: data.readFloat(),1593 scattering: data.readFloat()1594 };1595 break;1596 case SEA3D.Material.BLEND_NORMAL_MAP:1597 methodAttrib = data.readUByte();1598 tech = {1599 texture: sea3d.getObject( data.readUInt() ),1600 secondaryTexture: sea3d.getObject( data.readUInt() )1601 };1602 if ( methodAttrib & 1 ) {1603 tech.offsetX0 = data.readFloat();1604 tech.offsetY0 = data.readFloat();1605 tech.offsetX1 = data.readFloat();1606 tech.offsetY1 = data.readFloat();1607 }1608 else {1609 tech.offsetX0 = tech.offsetY0 =1610 tech.offsetX1 = tech.offsetY1 = 01611 }1612 tech.animate = methodAttrib & 2;1613 break;1614 case SEA3D.Material.MIRROR_REFLECTION:1615 tech = {1616 texture: sea3d.getObject( data.readUInt() ),1617 alpha: data.readFloat()1618 };1619 break;1620 case SEA3D.Material.AMBIENT_MAP:1621 tech = {1622 texture: sea3d.getObject( data.readUInt() )1623 }1624 break;1625 case SEA3D.Material.ALPHA_MAP:1626 tech = {1627 texture: sea3d.getObject( data.readUInt() )1628 };1629 break;1630 case SEA3D.Material.EMISSIVE:1631 tech = {1632 color: data.readUInt24()1633 };1634 break;1635 case SEA3D.Material.EMISSIVE_MAP:1636 tech = {1637 texture: sea3d.getObject( data.readUInt() )1638 };1639 break;1640 case SEA3D.Material.ROUGHNESS_MAP:1641 case SEA3D.Material.METALNESS_MAP:1642 tech = {1643 texture: sea3d.getObject( data.readUInt() )1644 };1645 break;1646 case SEA3D.Material.VERTEX_COLOR:1647 tech = {1648 blendMode: data.readBlendMode()1649 };1650 break;1651 case SEA3D.Material.WRAP_LIGHTING:1652 tech = {1653 color: data.readUInt24(),1654 strength: data.readFloat()1655 };1656 break;1657 case SEA3D.Material.COLOR_REPLACE:1658 methodAttrib = data.readUByte();1659 tech = {1660 red: data.readUInt24(),1661 green: data.readUInt24(),1662 blue: data.readUInt24F()1663 };1664 if ( methodAttrib & 1 ) tech.mask = sea3d.getObject( data.readUInt() );1665 if ( methodAttrib & 2 ) tech.alpha = data.readFloat();1666 break;1667 case SEA3D.Material.REFLECTION_SPHERICAL:1668 tech = {1669 texture: sea3d.getObject( data.readUInt() ),1670 alpha: data.readFloat()1671 };1672 break;1673 default:1674 console.warn( "SEA3D: MaterialTechnique not found:", kind.toString( 16 ) );1675 data.position = pos += size;1676 continue;1677 }1678 tech.kind = kind;1679 this.technique.push( tech );1680 data.position = pos += size;1681 }1682};1683SEA3D.Material.PHONG = 0;1684SEA3D.Material.COMPOSITE_TEXTURE = 1;1685SEA3D.Material.DIFFUSE_MAP = 2;1686SEA3D.Material.SPECULAR_MAP = 3;1687SEA3D.Material.REFLECTION = 4;1688SEA3D.Material.REFRACTION = 5;1689SEA3D.Material.NORMAL_MAP = 6;1690SEA3D.Material.FRESNEL_REFLECTION = 7;1691SEA3D.Material.RIM = 8;1692SEA3D.Material.LIGHT_MAP = 9;1693SEA3D.Material.DETAIL_MAP = 10;1694SEA3D.Material.CEL = 11;1695SEA3D.Material.TRANSLUCENT = 12;1696SEA3D.Material.BLEND_NORMAL_MAP = 13;1697SEA3D.Material.MIRROR_REFLECTION = 14;1698SEA3D.Material.AMBIENT_MAP = 15;1699SEA3D.Material.ALPHA_MAP = 16;1700SEA3D.Material.EMISSIVE_MAP = 17;1701SEA3D.Material.VERTEX_COLOR = 18;1702SEA3D.Material.WRAP_LIGHTING = 19;1703SEA3D.Material.COLOR_REPLACE = 20;1704SEA3D.Material.REFLECTION_SPHERICAL = 21;1705SEA3D.Material.ANISOTROPIC = 22;1706SEA3D.Material.EMISSIVE = 23;1707SEA3D.Material.PHYSICAL = 24;1708SEA3D.Material.ROUGHNESS_MAP = 25;1709SEA3D.Material.METALNESS_MAP = 26;1710SEA3D.Material.prototype.type = "mat";1711//1712// Composite1713//1714SEA3D.Composite = function( name, data, sea3d ) {1715 this.name = name;1716 this.data = data;1717 this.sea3d = sea3d;1718 var layerCount = data.readUByte();1719 this.layer = [];1720 for ( var i = 0; i < layerCount; i ++ ) {1721 this.layer[ i ] = new SEA3D.Composite.prototype.Layer( data, sea3d );1722 }1723};1724SEA3D.Composite.prototype.getLayerByName = function( name ) {1725 for ( var i = 0; i < this.layer.length; i ++ ) {1726 if ( this.layer[ i ].name == name ) {1727 return this.layer[ i ];1728 }1729 }1730};1731SEA3D.Composite.prototype.Layer = function( data, sea3d ) {1732 var attrib = data.readUShort();1733 if ( attrib & 1 ) this.texture = new SEA3D.Composite.LayerBitmap( data, sea3d );1734 else this.color = data.readUInt24();1735 if ( attrib & 2 ) {1736 this.mask = new SEA3D.Composite.LayerBitmap( data, sea3d );1737 }1738 if ( attrib & 4 ) {1739 this.name = data.readUTF8();1740 }1741 this.blendMode = attrib & 8 ? data.readBlendMode() : "normal";1742 this.opacity = attrib & 16 ? data.readFloat() : 1;1743};1744SEA3D.Composite.LayerBitmap = function( data, sea3d ) {1745 this.map = sea3d.getObject( data.readUInt() );1746 var attrib = data.readUShort();1747 this.channel = attrib & 1 ? data.readUByte() : 0;1748 this.repeat = attrib & 2 == 0;1749 this.offsetU = attrib & 4 ? data.readFloat() : 0;1750 this.offsetV = attrib & 8 ? data.readFloat() : 0;1751 this.scaleU = attrib & 16 ? data.readFloat() : 1;1752 this.scaleV = attrib & 32 ? data.readFloat() : 1;1753 this.rotation = attrib & 64 ? data.readFloat() : 0;1754 if ( attrib & 128 ) this.animation = data.readAnimationList( sea3d );1755};1756SEA3D.Composite.prototype.type = "ctex";1757//1758// Sphere1759//1760SEA3D.Sphere = function( name, data, sea3d ) {1761 this.name = name;1762 this.data = data;1763 this.sea3d = sea3d;1764 this.radius = data.readFloat();1765};1766SEA3D.Sphere.prototype.type = "sph";1767//1768// Box1769//1770SEA3D.Box = function( name, data, sea3d ) {1771 this.name = name;1772 this.data = data;1773 this.sea3d = sea3d;1774 this.width = data.readFloat();1775 this.height = data.readFloat();1776 this.depth = data.readFloat();1777};1778SEA3D.Box.prototype.type = "box";1779//1780// Cone1781//1782SEA3D.Cone = function( name, data, sea3d ) {1783 this.name = name;1784 this.data = data;1785 this.sea3d = sea3d;1786 this.radius = data.readFloat();1787 this.height = data.readFloat();1788};1789SEA3D.Cone.prototype.type = "cone";1790//1791// Capsule1792//1793SEA3D.Capsule = function( name, data, sea3d ) {1794 this.name = name;1795 this.data = data;1796 this.sea3d = sea3d;1797 this.radius = data.readFloat();1798 this.height = data.readFloat();1799};1800SEA3D.Capsule.prototype.type = "cap";1801//1802// Cylinder1803//1804SEA3D.Cylinder = function( name, data, sea3d ) {1805 this.name = name;1806 this.data = data;1807 this.sea3d = sea3d;1808 this.radius = data.readFloat();1809 this.height = data.readFloat();1810};1811SEA3D.Cylinder.prototype.type = "cyl";1812//1813// Convex Geometry1814//1815SEA3D.ConvexGeometry = function( name, data, sea3d ) {1816 this.name = name;1817 this.data = data;1818 this.sea3d = sea3d;1819 this.geometry = sea3d.getObject( data.readUInt() );1820 this.subGeometryIndex = data.readUByte();1821};1822SEA3D.ConvexGeometry.prototype.type = "gs";1823//1824// Triangle Geometry1825//1826SEA3D.TriangleGeometry = function( name, data, sea3d ) {1827 this.name = name;1828 this.data = data;1829 this.sea3d = sea3d;1830 this.geometry = sea3d.getObject( data.readUInt() );1831 this.subGeometryIndex = data.readUByte();1832};1833SEA3D.TriangleGeometry.prototype.type = "sgs";1834//1835// Compound1836//1837SEA3D.Compound = function( name, data, sea3d ) {1838 this.name = name;1839 this.data = data;1840 this.sea3d = sea3d;1841 this.compounds = [];1842 var count = data.readUByte();1843 for ( var i = 0; i < count; i ++ ) {1844 this.compounds.push( {1845 shape : sea3d.getObject( data.readUInt() ),1846 transform : data.readMatrix()1847 } );1848 }1849};1850SEA3D.Compound.prototype.type = "cmps";1851//1852// Physics1853//1854SEA3D.Physics = function( name, data, sea3d ) {1855 this.name = name;1856 this.data = data;1857 this.sea3d = sea3d;1858 this.attrib = data.readUShort();1859 this.shape = sea3d.getObject( data.readUInt() );1860 if ( this.attrib & 1 ) this.target = sea3d.getObject( data.readUInt() );1861 else this.transform = data.readMatrix();1862};1863SEA3D.Physics.prototype.readTag = function( kind, data, size ) {1864};1865//1866// Rigidy Body Base1867//1868SEA3D.RigidBodyBase = function( name, data, sea3d ) {1869 SEA3D.Physics.call( this, name, data, sea3d );1870 if ( this.attrib & 32 ) {1871 this.linearDamping = data.readFloat();1872 this.angularDamping = data.readFloat();1873 } else {1874 this.linearDamping = 0;1875 this.angularDamping = 0;1876 }1877 this.mass = data.readFloat();1878 this.friction = data.readFloat();1879 this.restitution = data.readFloat();1880};1881SEA3D.RigidBodyBase.prototype = Object.create( SEA3D.Physics.prototype );1882SEA3D.RigidBodyBase.prototype.constructor = SEA3D.RigidBodyBase;1883//1884// Rigidy Body1885//1886SEA3D.RigidBody = function( name, data, sea3d ) {1887 SEA3D.RigidBodyBase.call( this, name, data, sea3d );1888 data.readTags( this.readTag.bind( this ) );1889};1890SEA3D.RigidBody.prototype = Object.create( SEA3D.RigidBodyBase.prototype );1891SEA3D.RigidBody.prototype.constructor = SEA3D.RigidBody;1892SEA3D.RigidBody.prototype.type = "rb";1893//1894// Car Controller1895//1896SEA3D.CarController = function( name, data, sea3d ) {1897 SEA3D.RigidBodyBase.call( this, name, data, sea3d );1898 this.suspensionStiffness = data.readFloat();1899 this.suspensionCompression = data.readFloat();1900 this.suspensionDamping = data.readFloat();1901 this.maxSuspensionTravelCm = data.readFloat();1902 this.frictionSlip = data.readFloat();1903 this.maxSuspensionForce = data.readFloat();1904 this.dampingCompression = data.readFloat();1905 this.dampingRelaxation = data.readFloat();1906 var count = data.readUByte();1907 this.wheel = [];1908 for ( var i = 0; i < count; i ++ ) {1909 this.wheel[ i ] = new SEA3D.CarController.Wheel( data, sea3d );1910 }1911 data.readTags( this.readTag.bind( this ) );1912};1913SEA3D.CarController.Wheel = function( data, sea3d ) {1914 this.data = data;1915 this.sea3d = sea3d;1916 var attrib = data.readUShort();1917 this.isFront = ( attrib & 1 ) != 0,1918 this.target = sea3d.getObject( data.readUInt() );1919 this.pos = data.readVector3();1920 this.dir = data.readVector3();1921 this.axle = data.readVector3();1922 this.radius = data.readFloat();1923 this.suspensionRestLength = data.readFloat();1924};1925SEA3D.CarController.prototype = Object.create( SEA3D.RigidBodyBase.prototype );1926SEA3D.CarController.prototype.constructor = SEA3D.CarController;1927SEA3D.CarController.prototype.type = "carc";1928//1929// Constraints1930//1931SEA3D.Constraints = function( name, data, sea3d ) {1932 this.name = name;1933 this.data = data;1934 this.sea3d = sea3d;1935 this.attrib = data.readUShort();1936 this.disableCollisionsBetweenBodies = this.attrib & 1 != 0;1937 this.targetA = sea3d.getObject( data.readUInt() );1938 this.pointA = data.readVector3();1939 if ( this.attrib & 2 ) {1940 this.targetB = sea3d.getObject( data.readUInt() );1941 this.pointB = data.readVector3();1942 }1943};1944//1945// P2P Constraint1946//1947SEA3D.P2PConstraint = function( name, data, sea3d ) {1948 this.name = name;1949 this.data = data;1950 this.sea3d = sea3d;1951 SEA3D.Constraints.call( this, name, data, sea3d );1952};1953SEA3D.P2PConstraint.prototype = Object.create( SEA3D.Constraints.prototype );1954SEA3D.P2PConstraint.prototype.constructor = SEA3D.P2PConstraint;1955SEA3D.P2PConstraint.prototype.type = "p2pc";1956//1957// Hinge Constraint1958//1959SEA3D.HingeConstraint = function( name, data, sea3d ) {1960 SEA3D.Constraints.call( this, name, data, sea3d );1961 this.axisA = data.readVector3();1962 if ( this.attrib & 1 ) {1963 this.axisB = data.readVector3();1964 }1965 if ( this.attrib & 4 ) {1966 this.limit = {1967 low : data.readFloat(),1968 high : data.readFloat(),1969 softness : data.readFloat(),1970 biasFactor : data.readFloat(),1971 relaxationFactor : data.readFloat()1972 }1973 }1974 if ( this.attrib & 8 ) {1975 this.angularMotor = {1976 velocity : data.readFloat(),1977 impulse : data.readFloat()1978 }1979 }1980};1981SEA3D.HingeConstraint.prototype = Object.create( SEA3D.Constraints.prototype );1982SEA3D.HingeConstraint.prototype.constructor = SEA3D.HingeConstraint;1983SEA3D.HingeConstraint.prototype.type = "hnec";1984//1985// Cone Twist Constraint1986//1987SEA3D.ConeTwistConstraint = function( name, data, sea3d ) {1988 SEA3D.Constraints.call( this, name, data, sea3d );1989 this.axisA = data.readVector3();1990 if ( this.attrib & 1 ) {1991 this.axisB = data.readVector3();1992 }1993 if ( this.attrib & 4 ) {1994 this.limit = {1995 swingSpan1 : data.readFloat(),1996 swingSpan2 : data.readFloat(),1997 twistSpan : data.readFloat(),1998 softness : data.readFloat(),1999 biasFactor : data.readFloat(),2000 relaxationFactor : data.readFloat()2001 };2002 }2003};2004SEA3D.ConeTwistConstraint.prototype = Object.create( SEA3D.Constraints.prototype );2005SEA3D.ConeTwistConstraint.prototype.constructor = SEA3D.ConeTwistConstraint;2006SEA3D.ConeTwistConstraint.prototype.type = "ctwc";2007//2008// Planar Render2009//2010SEA3D.PlanarRender = function( name, data, sea3d ) {2011 this.name = name;2012 this.data = data;2013 this.sea3d = sea3d;2014 this.attrib = data.readUByte();2015 this.quality = ( this.attrib & 1 ) | ( this.attrib & 2 );2016 this.transform = data.readMatrix();2017};2018SEA3D.PlanarRender.prototype.type = "rttp";2019//2020// Cube Render2021//2022SEA3D.CubeRender = function( name, data, sea3d ) {2023 this.name = name;2024 this.data = data;2025 this.sea3d = sea3d;2026 this.attrib = data.readUByte();2027 this.quality = ( this.attrib & 1 ) | ( this.attrib & 2 );2028 this.position = data.readVector3();2029};2030SEA3D.CubeRender.prototype.type = "rttc";2031//2032// Cube Maps2033//2034SEA3D.CubeMap = function( name, data, sea3d ) {2035 this.name = name;2036 this.data = data;2037 this.sea3d = sea3d;2038 this.transparent = false;2039 var ext = data.readExt();2040 this.faces = [];2041 for ( var i = 0; i < 6; i ++ ) {2042 var size = data.readUInt();2043 this.faces[ i ] = data.concat( data.position, size );2044 data.position += size;2045 }2046};2047SEA3D.CubeMap.prototype.type = "cmap";2048//2049// JPEG2050//2051SEA3D.JPEG = function( name, data, sea3d ) {2052 this.name = name;2053 this.data = data;2054 this.sea3d = sea3d;2055 this.transparent = false;2056};2057SEA3D.JPEG.prototype.type = "jpg";2058//2059// JPEG_XR2060//2061SEA3D.JPEG_XR = function( name, data, sea3d ) {2062 this.name = name;2063 this.data = data;2064 this.sea3d = sea3d;2065 this.transparent = true;2066};2067SEA3D.JPEG_XR.prototype.type = "wdp";2068//2069// PNG2070//2071SEA3D.PNG = function( name, data, sea3d ) {2072 this.name = name;2073 this.data = data;2074 this.sea3d = sea3d;2075 this.transparent = data.getByte( 25 ) == 0x06;2076};2077SEA3D.PNG.prototype.type = "png";2078//2079// GIF2080//2081SEA3D.GIF = function( name, data, sea3d ) {2082 this.name = name;2083 this.data = data;2084 this.sea3d = sea3d;2085 this.transparent = data.getByte( 11 ) > 0;2086};2087SEA3D.GIF.prototype.type = "gif";2088//2089// OGG2090//2091SEA3D.OGG = function( name, data, sea3d ) {2092 this.name = name;2093 this.data = data;2094 this.sea3d = sea3d;2095};2096SEA3D.OGG.prototype.type = "ogg";2097//2098// MP32099//2100SEA3D.MP3 = function( name, data, sea3d ) {2101 this.name = name;2102 this.data = data;2103 this.sea3d = sea3d;2104};2105SEA3D.MP3.prototype.type = "mp3";2106//2107// FILE FORMAT2108//2109SEA3D.File = function( config ) {2110 this.config = {2111 streaming: true,2112 timeLimit: 602113 };2114 if ( config ) {2115 if ( config.streaming !== undefined ) this.config.streaming = config.streaming;2116 if ( config.timeLimit !== undefined ) this.config.timeLimit = config.timeLimit;2117 }2118 this.version = SEA3D.VERSION;2119 this.objects = [];2120 this.typeClass = {};2121 this.typeRead = {};2122 this.typeUnique = {};2123 this.position =2124 this.dataPosition = 0;2125 this.scope = this;2126 // SEA3D2127 this.addClass( SEA3D.FileInfo, true );2128 this.addClass( SEA3D.Geometry, true );2129 this.addClass( SEA3D.GeometryDelta, true );2130 this.addClass( SEA3D.Mesh );2131 this.addClass( SEA3D.Sprite );2132 this.addClass( SEA3D.Material );2133 this.addClass( SEA3D.Composite );2134 this.addClass( SEA3D.PointLight );2135 this.addClass( SEA3D.DirectionalLight );2136 this.addClass( SEA3D.HemisphereLight );2137 this.addClass( SEA3D.AmbientLight );2138 this.addClass( SEA3D.Skeleton, true );2139 this.addClass( SEA3D.SkeletonLocal, true );2140 this.addClass( SEA3D.SkeletonAnimation, true );2141 this.addClass( SEA3D.JointObject );2142 this.addClass( SEA3D.Camera );2143 this.addClass( SEA3D.OrthographicCamera );2144 this.addClass( SEA3D.Morph, true );2145 this.addClass( SEA3D.VertexAnimation, true );2146 this.addClass( SEA3D.CubeMap, true );2147 this.addClass( SEA3D.Animation );2148 this.addClass( SEA3D.Dummy );2149 this.addClass( SEA3D.Line );2150 this.addClass( SEA3D.SoundPoint );2151 this.addClass( SEA3D.PlanarRender );2152 this.addClass( SEA3D.CubeRender );2153 this.addClass( SEA3D.Actions );2154 this.addClass( SEA3D.Container3D );2155 this.addClass( SEA3D.Properties );2156 // URL2157 this.addClass( SEA3D.TextureURL, true );2158 // PHYSICS2159 this.addClass( SEA3D.Sphere );2160 this.addClass( SEA3D.Box );2161 this.addClass( SEA3D.Cone );2162 this.addClass( SEA3D.Capsule );2163 this.addClass( SEA3D.Cylinder );2164 this.addClass( SEA3D.ConvexGeometry );2165 this.addClass( SEA3D.TriangleGeometry );2166 this.addClass( SEA3D.Compound );2167 this.addClass( SEA3D.RigidBody );2168 this.addClass( SEA3D.P2PConstraint );2169 this.addClass( SEA3D.HingeConstraint );2170 this.addClass( SEA3D.ConeTwistConstraint );2171 this.addClass( SEA3D.CarController );2172 // UNIVERSAL2173 this.addClass( SEA3D.JPEG, true );2174 this.addClass( SEA3D.JPEG_XR, true );2175 this.addClass( SEA3D.PNG, true );2176 this.addClass( SEA3D.GIF, true );2177 this.addClass( SEA3D.OGG, true );2178 this.addClass( SEA3D.MP3, true );2179 this.addClass( SEA3D.JavaScript, true );2180 this.addClass( SEA3D.JavaScriptMethod, true );2181 this.addClass( SEA3D.GLSL, true );2182};2183SEA3D.File.CompressionLibs = {};2184SEA3D.File.DecompressionMethod = {}2185SEA3D.File.setDecompressionEngine = function( id, name, method ) {2186 SEA3D.File.CompressionLibs[ id ] = name;2187 SEA3D.File.DecompressionMethod[ id ] = method;2188};2189SEA3D.File.prototype.addClass = function( clazz, unique ) {2190 this.typeClass[ clazz.prototype.type ] = clazz;2191 this.typeUnique[ clazz.prototype.type ] = unique === true;2192};2193SEA3D.File.prototype.readHead = function() {2194 if ( this.stream.bytesAvailable < 16 )2195 return false;2196 if ( this.stream.readUTF( 3 ) != "SEA" )2197 throw new Error( "Invalid SEA3D format." );2198 this.sign = this.stream.readUTF( 3 );2199 this.version = this.stream.readUInt24();2200 if ( this.stream.readUByte() != 0 ) {2201 throw new Error( "Protection algorithm not compatible." );2202 }2203 this.compressionID = this.stream.readUByte();2204 this.compressionAlgorithm = SEA3D.File.CompressionLibs[ this.compressionID ];2205 this.decompressionMethod = SEA3D.File.DecompressionMethod[ this.compressionID ];2206 if ( this.compressionID > 0 && ! this.decompressionMethod ) {2207 throw new Error( "Compression algorithm not compatible." );2208 }2209 this.length = this.stream.readUInt();2210 this.dataPosition = this.stream.position;2211 this.objects.length = 0;2212 this.state = this.readBody;2213 if ( this.onHead )2214 this.onHead( {2215 file: this,2216 sign: this.sign2217 } );2218 return true;2219};2220SEA3D.File.prototype.getObject = function( index ) {2221 return this.objects[ index ];2222};2223SEA3D.File.prototype.readSEAObject = function() {2224 if ( this.stream.bytesAvailable < 4 )2225 return null;2226 var size = this.stream.readUInt();2227 var position = this.stream.position;2228 if ( this.stream.bytesAvailable < size )2229 return null;2230 var flag = this.stream.readUByte();2231 var type = this.stream.readExt();2232 var meta = null;2233 var name = flag & 1 ? this.stream.readUTF8() : "",2234 compressed = ( flag & 2 ) != 0,2235 streaming = ( flag & 4 ) != 0;2236 if ( flag & 8 ) {2237 var metalen = this.stream.readUShort();2238 var metabytes = this.stream.concat( this.stream.position, metalen );2239 this.stream.position += metalen;2240 if ( compressed && this.decompressionMethod ) {2241 metabytes.buffer = this.decompressionMethod( metabytes.buffer );2242 }2243 meta = metabytes.readProperties( this );2244 }2245 size -= this.stream.position - position;2246 position = this.stream.position;2247 var data = this.stream.concat( position, size ),2248 obj;2249 if ( this.typeClass[ type ] ) {2250 if ( compressed && this.decompressionMethod ) {2251 data.buffer = this.decompressionMethod( data.buffer );2252 }2253 obj = new this.typeClass[ type ]( name, data, this );2254 if ( this.config.streaming && streaming && this.typeRead[ type ] ) {2255 this.typeRead[ type ].call( this.scope, obj );2256 }2257 }2258 else {2259 obj = new SEA3D.Object( name, data, type, this );2260 console.warn( "SEA3D: Unknown format \"" + type + "\" of file \"" + name + "\". Add a module referring for this format." );2261 }2262 obj.streaming = streaming;2263 obj.metadata = meta;2264 this.objects.push( this.objects[ obj.type + "/" + obj.name ] = obj );2265 this.dataPosition = position + size;2266 ++ this.position;2267 return obj;2268};2269SEA3D.File.prototype.isDone = function() {2270 return this.position == this.length;2271};2272SEA3D.File.prototype.readBody = function() {2273 this.timer.update();2274 while ( this.position < this.length ) {2275 if ( this.timer.deltaTime < this.config.timeLimit ) {2276 this.stream.position = this.dataPosition;2277 var sea = this.readSEAObject();2278 if ( sea ) this.dispatchCompleteObject( sea );2279 else return false;2280 }2281 else return false;2282 }2283 this.state = this.readComplete;2284 return true;2285};2286SEA3D.File.prototype.parse = function() {2287 this.timer = new SEA3D.Timer();2288 this.position = 0;2289 if ( isFinite( this.config.timeLimit ) ) setTimeout( this.parseObject.bind( this ), 10 );2290 else this.parseObject();2291};2292SEA3D.File.prototype.parseObject = function() {2293 this.timer.update();2294 while ( this.position < this.length && this.timer.deltaTime < this.config.timeLimit ) {2295 var obj = this.objects[ this.position ++ ],2296 type = obj.type;2297 if ( ! this.typeUnique[ type ] ) delete obj.tag;2298 if ( obj.streaming && this.typeRead[ type ] ) {2299 if ( obj.tag == undefined ) {2300 this.typeRead[ type ].call( this.scope, obj );2301 }2302 }2303 }2304 if ( this.position == this.length ) {2305 var elapsedTime = this.timer.elapsedTime;2306 var message = elapsedTime + "ms, " + this.objects.length + " objects";2307 if ( this.onParseComplete ) {2308 this.onParseComplete( {2309 file: this,2310 timeTotal: elapsedTime,2311 message: message2312 } );2313 } else console.log( "SEA3D Parse Complete:", message );2314 } else {2315 if ( this.onParseProgress ) {2316 this.onParseProgress( {2317 file: this,2318 loaded: this.position,2319 total: this.length,2320 progress: this.position / this.length2321 } );2322 }2323 setTimeout( this.parseObject.bind( this ), 10 );2324 }2325};2326SEA3D.File.prototype.readComplete = function() {2327 this.stream.position = this.dataPosition;2328 if ( this.stream.readUInt24F() != 0x5EA3D1 )2329 console.warn( "SEA3D file is corrupted." );2330 delete this.state;2331 this.dispatchComplete();2332};2333SEA3D.File.prototype.readState = function() {2334 while ( this.state && this.state() );2335 if ( this.state ) {2336 setTimeout( this.readState.bind( this ), 10 );2337 this.dispatchProgress();2338 }2339};2340SEA3D.File.prototype.read = function( data ) {2341 this.stream = new SEA3D.Stream( data );2342 this.timer = new SEA3D.Timer();2343 this.state = this.readHead;2344 this.readState();2345};2346SEA3D.File.prototype.dispatchCompleteObject = function( obj ) {2347 if ( ! this.onCompleteObject ) return;2348 this.onCompleteObject( {2349 file: this,2350 object: obj2351 } );2352};2353SEA3D.File.prototype.dispatchProgress = function() {2354 if ( ! this.onProgress ) return;2355 this.onProgress( {2356 file: this,2357 loaded: this.position,2358 total: this.length,2359 progress: this.position / this.length2360 } );2361};2362SEA3D.File.prototype.dispatchDownloadProgress = function( position, length ) {2363 if ( ! this.onDownloadProgress ) return;2364 this.onDownloadProgress( {2365 file: this,2366 loaded: position,2367 total: length,2368 progress: position / length2369 } );2370};2371SEA3D.File.prototype.dispatchComplete = function() {2372 var elapsedTime = this.timer.elapsedTime;2373 var message = elapsedTime + "ms, " + this.objects.length + " objects";2374 if ( this.onComplete ) this.onComplete( {2375 file: this,2376 timeTotal: elapsedTime,2377 message: message2378 } );2379 else console.log( "SEA3D:", message );2380};2381SEA3D.File.prototype.dispatchError = function( id, message ) {2382 if ( this.onError ) this.onError( { file: this, id: id, message: message } );2383 else console.error( "SEA3D: #" + id, message );2384};2385SEA3D.File.prototype.load = function( url ) {2386 var file = this,2387 xhr = new XMLHttpRequest();2388 xhr.open( "GET", url, true );2389 xhr.responseType = 'arraybuffer';2390 xhr.onprogress = function( e ) {2391 if ( e.lengthComputable ) {2392 file.dispatchDownloadProgress( e.loaded, e.total );2393 }2394 }2395 xhr.onreadystatechange = function() {2396 if ( xhr.readyState === 2 ) {2397 //xhr.getResponseHeader("Content-Length");2398 } else if ( xhr.readyState === 3 ) {2399 // progress2400 } else if ( xhr.readyState === 4 ) {2401 if ( xhr.status === 200 || xhr.status === 0 ) {2402 // complete2403 file.read( this.response );2404 } else {2405 this.dispatchError( 1001, "Couldn't load [" + url + "] [" + xhr.status + "]" );2406 }2407 }2408 }2409 xhr.send();...

Full Screen

Full Screen

attributes.js

Source:attributes.js Github

copy

Full Screen

1function getProperty(propertyName) {2 return el => el[propertyName];3}4function getAttribute(attributeName) {5 return el => {6 if (el.namespaceURI === '') {7 throw new Error('Not an HTML element.');8 }9 return el.getAttribute(attributeName);10 };11}12function getSVGProperty(propertyName) {13 return el => el[propertyName];14}15function getSVGAttribute(attributeName) {16 return el => {17 if (el.namespaceURI !== 'http://www.w3.org/2000/svg') {18 throw new Error('Not an SVG element.');19 }20 return el.getAttribute(attributeName);21 };22}23const attributes = [24 {name: 'about', read: getAttribute('about')},25 {name: 'aBoUt', read: getAttribute('about')},26 {27 name: 'accent-Height',28 containerTagName: 'svg',29 tagName: 'font-face',30 read: getSVGAttribute('accent-height'),31 },32 {33 name: 'accent-height',34 containerTagName: 'svg',35 tagName: 'font-face',36 read: getSVGAttribute('accent-height'),37 },38 {39 name: 'accentHeight',40 containerTagName: 'svg',41 tagName: 'font-face',42 read: getSVGAttribute('accent-height'),43 },44 {name: 'accept', tagName: 'input'},45 {name: 'accept-charset', tagName: 'form', read: getProperty('acceptCharset')},46 {name: 'accept-Charset', tagName: 'form', read: getProperty('acceptCharset')},47 {name: 'acceptCharset', tagName: 'form'},48 {name: 'accessKey'},49 {50 name: 'accumulate',51 containerTagName: 'svg',52 tagName: 'animate',53 read: getSVGAttribute('accumulate'),54 },55 {name: 'action', tagName: 'form', overrideStringValue: 'https://reactjs.com'},56 {57 name: 'additive',58 containerTagName: 'svg',59 tagName: 'animate',60 read: getSVGAttribute('additive'),61 },62 {63 name: 'alignment-baseline',64 containerTagName: 'svg',65 tagName: 'textPath',66 read: getSVGAttribute('alignment-baseline'),67 },68 {69 name: 'alignmentBaseline',70 containerTagName: 'svg',71 tagName: 'textPath',72 read: getSVGAttribute('alignment-baseline'),73 },74 {75 name: 'allowFullScreen',76 tagName: 'iframe',77 read: getProperty('allowFullscreen'),78 },79 {80 name: 'allowfullscreen',81 tagName: 'iframe',82 read: getProperty('allowFullscreen'),83 },84 {name: 'allowFullscreen', tagName: 'iframe'},85 {86 name: 'allowReorder',87 containerTagName: 'svg',88 tagName: 'switch',89 read: getSVGAttribute('allowReorder'),90 },91 {92 name: 'alphabetic',93 containerTagName: 'svg',94 tagName: 'font-face',95 read: getSVGAttribute('alphabetic'),96 },97 {name: 'alt', tagName: 'img'},98 {99 name: 'amplitude',100 containerTagName: 'svg',101 tagName: 'feFuncA',102 read: getSVGProperty('amplitude'),103 },104 {105 name: 'arabic-form',106 containerTagName: 'svg',107 tagName: 'glyph',108 read: getSVGAttribute('arabic-form'),109 },110 {111 name: 'arabicForm',112 containerTagName: 'svg',113 tagName: 'glyph',114 read: getSVGAttribute('arabic-form'),115 },116 {name: 'aria', read: getAttribute('aria')},117 {name: 'aria-', read: getAttribute('aria-')},118 {name: 'aria-invalidattribute', read: getAttribute('aria-invalidattribute')},119 {name: 'as', tagName: 'link'},120 {121 name: 'ascent',122 containerTagName: 'svg',123 tagName: 'font-face',124 read: getSVGAttribute('ascent'),125 },126 {name: 'async', tagName: 'script'},127 {128 name: 'attributeName',129 containerTagName: 'svg',130 tagName: 'animate',131 read: getSVGAttribute('attributeName'),132 },133 {134 name: 'attributeType',135 containerTagName: 'svg',136 tagName: 'animate',137 read: getSVGAttribute('attributeType'),138 },139 {140 name: 'autoCapitalize',141 tagName: 'input',142 read: getProperty('autocapitalize'),143 overrideStringValue: 'words',144 },145 {146 name: 'autoComplete',147 tagName: 'input',148 overrideStringValue: 'email',149 read: getProperty('autocomplete'),150 },151 {152 name: 'autoCorrect',153 tagName: 'input',154 overrideStringValue: 'off',155 read: getAttribute('autocorrect'),156 },157 {name: 'autoPlay', tagName: 'video', read: getProperty('autoplay')},158 {159 name: 'autoReverse',160 containerTagName: 'svg',161 tagName: 'animate',162 read: getSVGAttribute('autoreverse'),163 },164 {name: 'autoSave', tagName: 'input', read: getAttribute('autosave')},165 {166 name: 'azimuth',167 containerTagName: 'svg',168 tagName: 'feDistantLight',169 read: getSVGProperty('azimuth'),170 },171 {172 name: 'baseFrequency',173 containerTagName: 'svg',174 tagName: 'feTurbulence',175 read: getSVGAttribute('baseFrequency'),176 },177 {178 name: 'baseline-shift',179 containerTagName: 'svg',180 tagName: 'textPath',181 read: getSVGAttribute('baseline-shift'),182 },183 {184 name: 'baselineShift',185 containerTagName: 'svg',186 tagName: 'textPath',187 read: getSVGAttribute('baseline-shift'),188 },189 {name: 'baseProfile', tagName: 'svg', read: getSVGAttribute('baseProfile')},190 {191 name: 'bbox',192 containerTagName: 'svg',193 tagName: 'font-face',194 read: getSVGAttribute('bbox'),195 },196 {197 name: 'begin',198 containerTagName: 'svg',199 tagName: 'animate',200 read: getSVGAttribute('begin'),201 },202 {203 name: 'bias',204 containerTagName: 'svg',205 tagName: 'feConvolveMatrix',206 read: getSVGProperty('bias'),207 },208 {209 name: 'by',210 containerTagName: 'svg',211 tagName: 'animate',212 read: getSVGAttribute('by'),213 },214 {215 name: 'calcMode',216 containerTagName: 'svg',217 tagName: 'animate',218 overrideStringValue: 'discrete',219 read: getSVGAttribute('calcMode'),220 },221 {222 name: 'cap-height',223 containerTagName: 'svg',224 tagName: 'font-face',225 read: getSVGAttribute('cap-height'),226 },227 {228 name: 'capHeight',229 containerTagName: 'svg',230 tagName: 'font-face',231 read: getSVGAttribute('cap-height'),232 },233 {234 name: 'capture',235 tagName: 'input',236 overrideStringValue: 'environment',237 read: getAttribute('capture'),238 },239 {name: 'cellPadding', tagName: 'table'},240 {name: 'cellSpacing', tagName: 'table'},241 {242 name: 'challenge',243 tagName: 'keygen',244 read: getAttribute('challenge'), // The property is not supported in Chrome.245 },246 {name: 'charSet', tagName: 'script', read: getProperty('charset')},247 {name: 'checked', tagName: 'input', extraProps: {onChange() {}}},248 {name: 'Checked', tagName: 'input', read: getAttribute('Checked')},249 {name: 'Children', read: getAttribute('children')},250 {name: 'children'},251 {252 name: 'cite',253 tagName: 'blockquote',254 overrideStringValue: 'http://reactjs.com/',255 },256 {name: 'class', read: getAttribute('class')},257 {name: 'classID', tagName: 'object', read: getAttribute('classid')},258 {name: 'className'},259 {name: 'clip', tagName: 'svg', read: getAttribute('clip')},260 {261 name: 'clip-path',262 containerTagName: 'svg',263 tagName: 'path',264 read: getSVGAttribute('clip-path'),265 },266 {267 name: 'clipPath',268 containerTagName: 'svg',269 tagName: 'path',270 read: getSVGAttribute('clip-path'),271 },272 {273 name: 'clipPathUnits',274 containerTagName: 'svg',275 tagName: 'clipPath',276 overrideStringValue: 'objectBoundingBox',277 read: getSVGProperty('clipPathUnits'),278 },279 {280 name: 'clip-rule',281 containerTagName: 'svg',282 tagName: 'path',283 read: getSVGAttribute('clip-rule'),284 },285 {286 name: 'clipRule',287 containerTagName: 'svg',288 tagName: 'path',289 read: getSVGAttribute('clip-rule'),290 },291 {292 name: 'color',293 containerTagName: 'svg',294 tagName: 'text',295 read: getSVGAttribute('color'),296 },297 {298 name: 'color-interpolation',299 containerTagName: 'svg',300 tagName: 'animate',301 overrideStringValue: 'sRGB',302 read: getSVGAttribute('color-interpolation'),303 },304 {305 name: 'colorInterpolation',306 containerTagName: 'svg',307 tagName: 'animate',308 overrideStringValue: 'sRGB',309 read: getSVGAttribute('color-interpolation'),310 },311 {312 name: 'color-interpolation-filters',313 containerTagName: 'svg',314 tagName: 'feComposite',315 overrideStringValue: 'sRGB',316 read: getSVGAttribute('color-interpolation-filters'),317 },318 {319 name: 'colorInterpolationFilters',320 containerTagName: 'svg',321 tagName: 'feComposite',322 overrideStringValue: 'sRGB',323 read: getSVGAttribute('color-interpolation-filters'),324 },325 {326 name: 'color-profile',327 containerTagName: 'svg',328 tagName: 'image',329 overrideStringValue: 'sRGB',330 read: getSVGAttribute('color-profile'),331 },332 {333 name: 'colorProfile',334 containerTagName: 'svg',335 tagName: 'image',336 overrideStringValue: 'sRGB',337 read: getSVGAttribute('color-profile'),338 },339 {340 name: 'color-rendering',341 containerTagName: 'svg',342 tagName: 'animate',343 overrideStringValue: 'optimizeSpeed',344 read: getSVGAttribute('color-rendering'),345 },346 {347 name: 'colorRendering',348 containerTagName: 'svg',349 tagName: 'animate',350 overrideStringValue: 'optimizeSpeed',351 read: getSVGAttribute('color-rendering'),352 },353 {name: 'cols', tagName: 'textarea'},354 {name: 'colSpan', containerTagName: 'tr', tagName: 'td'},355 {name: 'content', tagName: 'meta'},356 {name: 'contentEditable'},357 {358 name: 'contentScriptType',359 tagName: 'svg',360 read: getSVGAttribute('contentScriptType'),361 },362 {363 name: 'contentStyleType',364 tagName: 'svg',365 read: getSVGAttribute('contentStyleType'),366 },367 {name: 'contextMenu', read: getAttribute('contextmenu')}, // TODO: Read the property by rendering a menu with the ID.368 {name: 'controls', tagName: 'video'},369 {name: 'coords', tagName: 'a'},370 {name: 'crossOrigin', tagName: 'script'},371 {name: 'cursor', tag: 'svg', read: getAttribute('cursor')},372 {373 name: 'cx',374 containerTagName: 'svg',375 tagName: 'circle',376 overrideStringValue: '10px',377 read: getSVGProperty('cx'),378 },379 {380 name: 'cy',381 containerTagName: 'svg',382 tagName: 'circle',383 overrideStringValue: '10%',384 read: getSVGProperty('cy'),385 },386 {387 name: 'd',388 containerTagName: 'svg',389 tagName: 'path',390 read: getSVGAttribute('d'),391 },392 {393 name: 'dangerouslySetInnerHTML',394 read: getAttribute('dangerouslySetInnerHTML'),395 },396 {397 name: 'DangerouslySetInnerHTML',398 read: getAttribute('DangerouslySetInnerHTML'),399 },400 {name: 'data', read: getAttribute('data')},401 {name: 'data-', read: getAttribute('data-')},402 {name: 'data-unknownattribute', read: getAttribute('data-unknownattribute')},403 {name: 'datatype', read: getAttribute('datatype')},404 {405 name: 'dateTime',406 tagName: 'time',407 overrideStringValue: '2001-05-15T19:00',408 read: getAttribute('datetime'),409 },410 {411 name: 'decelerate',412 containerTagName: 'svg',413 tagName: 'animate',414 read: getSVGAttribute('decelerate'),415 },416 {name: 'default', tagName: 'track'},417 {418 name: 'defaultchecked',419 tagName: 'input',420 read: getAttribute('defaultchecked'),421 },422 {name: 'defaultChecked', tagName: 'input'},423 {name: 'defaultValue', tagName: 'input'},424 {name: 'defaultValuE', tagName: 'input', read: getAttribute('defaultValuE')},425 {name: 'defer', tagName: 'script'},426 {427 name: 'descent',428 containerTagName: 'svg',429 tagName: 'font-face',430 read: getSVGAttribute('descent'),431 },432 {433 name: 'diffuseConstant',434 containerTagName: 'svg',435 tagName: 'feDiffuseLighting',436 read: getSVGProperty('diffuseConstant'),437 },438 {name: 'dir', overrideStringValue: 'rtl'},439 {440 name: 'direction',441 containerTagName: 'svg',442 tagName: 'text',443 overrideStringValue: 'rtl',444 read: getSVGAttribute('direction'),445 },446 {name: 'disabled', tagName: 'input'},447 {448 name: 'display',449 tagName: 'svg',450 overrideStringValue: 'list-item',451 read: getAttribute('display'),452 },453 {454 name: 'divisor',455 containerTagName: 'svg',456 tagName: 'feConvolveMatrix',457 read: getSVGProperty('divisor'),458 },459 {460 name: 'dominant-baseline',461 containerTagName: 'svg',462 tagName: 'text',463 read: getSVGAttribute('dominant-baseline'),464 },465 {466 name: 'dominantBaseline',467 containerTagName: 'svg',468 tagName: 'text',469 read: getSVGAttribute('dominant-baseline'),470 },471 {name: 'download', tagName: 'a'},472 {name: 'dOwNlOaD', tagName: 'a', read: getAttribute('dOwNlOaD')},473 {name: 'draggable'},474 {475 name: 'dur',476 containerTagName: 'svg',477 tagName: 'animate',478 read: getSVGAttribute('dur'),479 },480 {481 name: 'dx',482 containerTagName: 'svg',483 tagName: 'text',484 overrideStringValue: '1pt 2px 3em',485 read: getSVGProperty('dx'),486 },487 {488 name: 'dX',489 containerTagName: 'svg',490 tagName: 'text',491 overrideStringValue: '1pt 2px 3em',492 read: getSVGProperty('dx'),493 },494 {495 name: 'dy',496 containerTagName: 'svg',497 tagName: 'text',498 overrideStringValue: '1 2 3',499 read: getSVGProperty('dy'),500 },501 {502 name: 'dY',503 containerTagName: 'svg',504 tagName: 'text',505 overrideStringValue: '1 2 3',506 read: getSVGProperty('dy'),507 },508 {509 name: 'edgeMode',510 containerTagName: 'svg',511 tagName: 'feConvolveMatrix',512 overrideStringValue: 'wrap',513 read: getSVGProperty('edgeMode'),514 },515 {516 name: 'elevation',517 containerTagName: 'svg',518 tagName: 'feDistantLight',519 read: getSVGProperty('elevation'),520 },521 {522 name: 'enable-background',523 containerTagName: 'svg',524 tagName: 'path',525 read: getSVGAttribute('enable-background'),526 },527 {528 name: 'enableBackground',529 containerTagName: 'svg',530 tagName: 'path',531 read: getSVGAttribute('enable-background'),532 },533 {534 name: 'encType',535 tagName: 'form',536 overrideStringValue: 'text/plain',537 read: getProperty('enctype'),538 },539 {540 name: 'end',541 containerTagName: 'svg',542 tagName: 'animate',543 read: getSVGAttribute('end'),544 },545 {546 name: 'exponent',547 read: getSVGProperty('exponent'),548 containerTagName: 'svg',549 tagName: 'feFuncA',550 },551 {552 name: 'externalResourcesRequired',553 containerTagName: 'svg',554 tagName: 'path',555 read: getSVGAttribute('externalResourcesRequired'),556 },557 {558 name: 'fill',559 containerTagName: 'svg',560 tagName: 'path',561 read: getSVGAttribute('fill'),562 },563 {564 name: 'fillOpacity',565 containerTagName: 'svg',566 tagName: 'circle',567 read: getSVGAttribute('fill-opacity'),568 },569 {570 name: 'fill-opacity',571 containerTagName: 'svg',572 tagName: 'circle',573 read: getSVGAttribute('fill-opacity'),574 },575 {576 name: 'fillRule',577 containerTagName: 'svg',578 tagName: 'circle',579 read: getSVGAttribute('fill-rule'),580 },581 {582 name: 'fill-rule',583 containerTagName: 'svg',584 tagName: 'circle',585 read: getSVGAttribute('fill-rule'),586 },587 {588 name: 'filter',589 containerTagName: 'svg',590 tagName: 'g',591 read: getSVGAttribute('filter'),592 },593 {594 name: 'filterRes',595 containerTagName: 'svg',596 tagName: 'filter',597 read: getSVGAttribute('filterRes'),598 },599 {600 name: 'filterUnits',601 containerTagName: 'svg',602 tagName: 'filter',603 overrideStringValue: 'userSpaceOnUse',604 read: getSVGProperty('filterUnits'),605 },606 {607 name: 'flood-color',608 containerTagName: 'svg',609 tagName: 'feflood',610 overrideStringValue: 'currentColor',611 read: getSVGAttribute('flood-color'),612 },613 {614 name: 'floodColor',615 containerTagName: 'svg',616 tagName: 'feflood',617 overrideStringValue: 'currentColor',618 read: getSVGAttribute('flood-color'),619 },620 {621 name: 'flood-opacity',622 containerTagName: 'svg',623 tagName: 'feflood',624 overrideStringValue: 'inherit',625 read: getSVGAttribute('flood-opacity'),626 },627 {628 name: 'floodOpacity',629 containerTagName: 'svg',630 tagName: 'feflood',631 overrideStringValue: 'inherit',632 read: getSVGAttribute('flood-opacity'),633 },634 {name: 'focusable', tagName: 'p', read: getAttribute('focusable')},635 {636 name: 'font-family',637 read: getSVGAttribute('font-family'),638 containerTagName: 'svg',639 tagName: 'font-face',640 },641 {642 name: 'font-size',643 read: getSVGAttribute('font-size'),644 containerTagName: 'svg',645 tagName: 'font-face',646 },647 {648 name: 'font-size-adjust',649 containerTagName: 'svg',650 tagName: 'text',651 read: getSVGAttribute('font-size-adjust'),652 },653 {654 name: 'font-stretch',655 read: getSVGAttribute('font-stretch'),656 containerTagName: 'svg',657 tagName: 'font-face',658 },659 {660 name: 'font-style',661 read: getSVGAttribute('font-style'),662 containerTagName: 'svg',663 tagName: 'font-face',664 },665 {666 name: 'font-variant',667 read: getSVGAttribute('font-variant'),668 containerTagName: 'svg',669 tagName: 'font-face',670 },671 {672 name: 'font-weight',673 read: getSVGAttribute('font-weight'),674 containerTagName: 'svg',675 tagName: 'font-face',676 },677 {678 name: 'fontFamily',679 read: getSVGAttribute('font-family'),680 containerTagName: 'svg',681 tagName: 'font-face',682 },683 {684 name: 'fontSize',685 read: getSVGAttribute('font-size'),686 containerTagName: 'svg',687 tagName: 'font-face',688 },689 {690 name: 'fontSizeAdjust',691 containerTagName: 'svg',692 tagName: 'text',693 read: getSVGAttribute('font-size-adjust'),694 },695 {696 name: 'fontStretch',697 read: getSVGAttribute('font-stretch'),698 containerTagName: 'svg',699 tagName: 'font-face',700 },701 {702 name: 'fontStyle',703 read: getSVGAttribute('font-style'),704 containerTagName: 'svg',705 tagName: 'font-face',706 },707 {708 name: 'fontVariant',709 read: getSVGAttribute('font-variant'),710 containerTagName: 'svg',711 tagName: 'font-face',712 },713 {714 name: 'fontWeight',715 read: getSVGAttribute('font-weight'),716 containerTagName: 'svg',717 tagName: 'font-face',718 },719 {name: 'for', tagName: 'label', read: getProperty('htmlFor')},720 {name: 'fOr', tagName: 'label', read: getProperty('htmlFor')},721 {name: 'form', read: getAttribute('form')}, // TODO: Read the property by rendering into a form with i722 {723 name: 'formAction',724 tagName: 'input',725 overrideStringValue: 'https://reactjs.com',726 },727 {728 name: 'format',729 read: getSVGAttribute('format'),730 containerTagName: 'svg',731 tagName: 'altGlyph',732 },733 {name: 'formEncType', tagName: 'input', read: getProperty('formEnctype')},734 {name: 'formMethod', tagName: 'input', overrideStringValue: 'POST'},735 {name: 'formNoValidate', tagName: 'input'},736 {name: 'formTarget', tagName: 'input'},737 {name: 'frameBorder', tagName: 'iframe'},738 {739 name: 'from',740 read: getSVGAttribute('from'),741 containerTagName: 'svg',742 tagName: 'animate',743 },744 {745 name: 'fx',746 read: getSVGProperty('fx'),747 containerTagName: 'svg',748 overrideStringValue: '10px',749 tagName: 'radialGradient',750 },751 {752 name: 'fX',753 containerTagName: 'svg',754 tagName: 'radialGradient',755 overrideStringValue: '10px',756 read: getSVGProperty('fx'),757 },758 {759 name: 'fY',760 containerTagName: 'svg',761 tagName: 'radialGradient',762 overrideStringValue: '20em',763 read: getSVGProperty('fy'),764 },765 {766 name: 'fy',767 read: getSVGProperty('fy'),768 containerTagName: 'svg',769 overrideStringValue: '20em',770 tagName: 'radialGradient',771 },772 {773 name: 'G1',774 containerTagName: 'svg',775 tagName: 'hkern',776 read: getSVGAttribute('g1'),777 },778 {779 name: 'g1',780 read: getSVGAttribute('g1'),781 containerTagName: 'svg',782 tagName: 'hkern',783 },784 {785 name: 'G2',786 containerTagName: 'svg',787 tagName: 'hkern',788 read: getSVGAttribute('g2'),789 },790 {791 name: 'g2',792 read: getSVGAttribute('g2'),793 containerTagName: 'svg',794 tagName: 'hkern',795 },796 {797 name: 'glyph-name',798 read: getSVGAttribute('glyph-name'),799 containerTagName: 'svg',800 tagName: 'glyph',801 },802 {803 name: 'glyph-orientation-horizontal',804 containerTagName: 'svg',805 tagName: 'text',806 read: getSVGAttribute('glyph-orientation-horizontal'),807 },808 {809 name: 'glyph-orientation-vertical',810 containerTagName: 'svg',811 tagName: 'text',812 read: getSVGAttribute('glyph-orientation-vertical'),813 },814 {815 name: 'glyphName',816 read: getSVGAttribute('glyph-name'),817 containerTagName: 'svg',818 tagName: 'glyph',819 },820 {821 name: 'glyphOrientationHorizontal',822 containerTagName: 'svg',823 tagName: 'text',824 read: getSVGAttribute('glyph-orientation-horizontal'),825 },826 {827 name: 'glyphOrientationVertical',828 containerTagName: 'svg',829 tagName: 'text',830 read: getSVGAttribute('glyph-orientation-vertical'),831 },832 {833 name: 'glyphRef',834 read: getSVGAttribute('glyph-ref'),835 containerTagName: 'svg',836 tagName: 'altGlyph',837 },838 {839 name: 'gradientTransform',840 read: getSVGProperty('gradientTransform'),841 containerTagName: 'svg',842 overrideStringValue:843 'translate(-10,-20) scale(2) rotate(45) translate(5,10)',844 tagName: 'linearGradient',845 },846 {847 name: 'gradientUnits',848 read: getSVGProperty('gradientUnits'),849 containerTagName: 'svg',850 overrideStringValue: 'userSpaceOnUse',851 tagName: 'linearGradient',852 },853 {854 name: 'hanging',855 read: getSVGAttribute('hanging'),856 containerTagName: 'svg',857 tagName: 'font-face',858 },859 // Disabled because it crashes other tests with React 15.860 // TODO: re-enable when we no longer compare to 15.861 // {name: 'hasOwnProperty', read: getAttribute('hasOwnProperty')},862 {name: 'headers', containerTagName: 'tr', tagName: 'td'},863 {name: 'height', tagName: 'img'},864 {865 name: 'height',866 containerTagName: 'svg',867 tagName: 'rect',868 read: getSVGProperty('height'),869 overrideStringValue: '100%',870 },871 {name: 'hidden'},872 {name: 'high', tagName: 'meter'},873 {874 name: 'horiz-adv-x',875 read: getSVGAttribute('horiz-adv-x'),876 containerTagName: 'svg',877 tagName: 'font',878 },879 {880 name: 'horiz-origin-x',881 read: getSVGAttribute('horiz-origin-x'),882 containerTagName: 'svg',883 tagName: 'font',884 },885 {886 name: 'horizAdvX',887 read: getSVGAttribute('horiz-adv-x'),888 containerTagName: 'svg',889 tagName: 'font',890 },891 {892 name: 'horizOriginX',893 read: getSVGAttribute('horiz-origin-x'),894 containerTagName: 'svg',895 tagName: 'font',896 },897 {name: 'href', tagName: 'a', overrideStringValue: 'https://reactjs.com'},898 {name: 'hrefLang', read: getAttribute('hreflang')},899 {name: 'htmlFor', tagName: 'label'},900 {name: 'http-equiv', tagName: 'meta', read: getProperty('httpEquiv')},901 {name: 'httpEquiv', tagName: 'meta'},902 {name: 'icon', tagName: 'command', read: getAttribute('icon')},903 {name: 'id'},904 {name: 'ID', read: getProperty('id')},905 {906 name: 'ideographic',907 read: getSVGAttribute('ideographic'),908 containerTagName: 'svg',909 tagName: 'font-face',910 },911 {912 name: 'image-rendering',913 tagName: 'svg',914 read: getSVGAttribute('image-rendering'),915 },916 {917 name: 'imageRendering',918 tagName: 'svg',919 read: getSVGAttribute('image-rendering'),920 },921 {922 name: 'in',923 read: getSVGAttribute('in'),924 containerTagName: 'svg',925 tagName: 'feBlend',926 },927 {928 name: 'in2',929 read: getSVGProperty('in2'),930 containerTagName: 'svg',931 tagName: 'feBlend',932 },933 {name: 'initialChecked', read: getAttribute('initialchecked')},934 {name: 'initialValue', read: getAttribute('initialvalue')},935 {name: 'inlist', read: getAttribute('inlist')},936 {name: 'inputMode', tagName: 'input', read: getAttribute('inputmode')}, // TODO: Should use property but it's not implemented in Chrome937 {name: 'integrity', tagName: 'script'},938 {939 name: 'intercept',940 read: getSVGProperty('intercept'),941 containerTagName: 'svg',942 tagName: 'feFuncA',943 },944 {945 name: 'is',946 tagName: 'button',947 overrideStringValue: 'x-test-element',948 read: getAttribute('is'), // TODO: This could check if this is an extended custom element but this is a controversial spec.949 },950 {name: 'itemID', read: getAttribute('itemid')},951 {name: 'itemProp', read: getAttribute('itemprop')},952 {name: 'itemRef', read: getAttribute('itemref')},953 {name: 'itemScope', read: getAttribute('itemscope')},954 {name: 'itemType', read: getAttribute('itemtype')},955 {956 name: 'k',957 read: getSVGAttribute('k'),958 containerTagName: 'svg',959 tagName: 'hkern',960 },961 {962 name: 'K',963 containerTagName: 'svg',964 tagName: 'hkern',965 read: getSVGAttribute('k'),966 },967 {968 name: 'K1',969 containerTagName: 'svg',970 tagName: 'feComposite',971 read: getSVGProperty('k1'),972 },973 {974 name: 'k1',975 read: getSVGProperty('k1'),976 containerTagName: 'svg',977 tagName: 'feComposite',978 },979 {980 name: 'k2',981 read: getSVGProperty('k2'),982 containerTagName: 'svg',983 tagName: 'feComposite',984 },985 {986 name: 'k3',987 read: getSVGProperty('k3'),988 containerTagName: 'svg',989 tagName: 'feComposite',990 },991 {992 name: 'k4',993 read: getSVGProperty('k4'),994 containerTagName: 'svg',995 tagName: 'feComposite',996 },997 {998 name: 'kernelMatrix',999 read: getSVGProperty('kernelMatrix'),1000 containerTagName: 'svg',1001 tagName: 'feConvolveMatrix',1002 overrideStringValue: '1 2 3,4',1003 },1004 {1005 name: 'kernelUnitLength',1006 read: getSVGAttribute('kernelUnitLength'),1007 containerTagName: 'svg',1008 tagName: 'feConvolveMatrix',1009 },1010 {1011 name: 'kerning',1012 containerTagName: 'svg',1013 tagName: 'text',1014 read: getSVGAttribute('kerning'),1015 },1016 {name: 'keyParams', read: getAttribute('keyParams')},1017 {1018 name: 'keyPoints',1019 read: getSVGAttribute('keyPoints'),1020 containerTagName: 'svg',1021 tagName: 'animateMotion',1022 },1023 {1024 name: 'keySplines',1025 read: getSVGAttribute('keySplines'),1026 containerTagName: 'svg',1027 tagName: 'animate',1028 },1029 {1030 name: 'keyTimes',1031 read: getSVGAttribute('keyTimes'),1032 containerTagName: 'svg',1033 tagName: 'animate',1034 },1035 {name: 'keyType', read: getAttribute('keyType')},1036 {name: 'kind', tagName: 'track', overrideStringValue: 'captions'},1037 {name: 'label', tagName: 'track'},1038 {name: 'LANG', read: getProperty('lang')},1039 {name: 'lang'},1040 {name: 'length', read: getAttribute('length')},1041 {1042 name: 'lengthAdjust',1043 read: getSVGProperty('lengthAdjust'),1044 containerTagName: 'svg',1045 tagName: 'text',1046 overrideStringValue: 'spacingAndGlyphs',1047 },1048 {1049 name: 'letter-spacing',1050 containerTagName: 'svg',1051 tagName: 'text',1052 read: getSVGAttribute('letter-spacing'),1053 },1054 {1055 name: 'letterSpacing',1056 containerTagName: 'svg',1057 tagName: 'text',1058 read: getSVGAttribute('letter-spacing'),1059 },1060 {1061 name: 'lighting-color',1062 containerTagName: 'svg',1063 tagName: 'feDiffuseLighting',1064 read: getSVGAttribute('lighting-color'),1065 },1066 {1067 name: 'lightingColor',1068 containerTagName: 'svg',1069 tagName: 'feDiffuseLighting',1070 read: getSVGAttribute('lighting-color'),1071 },1072 {1073 name: 'limitingConeAngle',1074 read: getSVGProperty('limitingConeAngle'),1075 containerTagName: 'svg',1076 tagName: 'feSpotLight',1077 },1078 {name: 'list', read: getAttribute('list')}, // TODO: This should match the ID of a datalist element and then read property.1079 {1080 name: 'local',1081 read: getSVGAttribute('local'),1082 containerTagName: 'svg',1083 tagName: 'color-profile',1084 },1085 {name: 'loop', tagName: 'audio'},1086 {name: 'low', tagName: 'meter'},1087 {name: 'manifest', read: getAttribute('manifest')},1088 {name: 'marginHeight', containerTagName: 'frameset', tagName: 'frame'},1089 {name: 'marginWidth', containerTagName: 'frameset', tagName: 'frame'},1090 {1091 name: 'marker-end',1092 containerTagName: 'svg',1093 tagName: 'line',1094 read: getSVGAttribute('marker-end'),1095 },1096 {1097 name: 'marker-mid',1098 containerTagName: 'svg',1099 tagName: 'line',1100 read: getSVGAttribute('marker-mid'),1101 },1102 {1103 name: 'marker-start',1104 containerTagName: 'svg',1105 tagName: 'line',1106 read: getSVGAttribute('marker-start'),1107 },1108 {1109 name: 'markerEnd',1110 containerTagName: 'svg',1111 tagName: 'line',1112 read: getSVGAttribute('marker-end'),1113 },1114 {1115 name: 'markerHeight',1116 read: getSVGProperty('markerHeight'),1117 containerTagName: 'svg',1118 tagName: 'marker',1119 },1120 {1121 name: 'markerMid',1122 containerTagName: 'svg',1123 tagName: 'line',1124 read: getSVGAttribute('marker-mid'),1125 },1126 {1127 name: 'markerStart',1128 containerTagName: 'svg',1129 tagName: 'line',1130 read: getSVGAttribute('marker-start'),1131 },1132 {1133 name: 'markerUnits',1134 read: getSVGProperty('markerUnits'),1135 containerTagName: 'svg',1136 tagName: 'marker',1137 },1138 {1139 name: 'markerWidth',1140 read: getSVGProperty('markerWidth'),1141 containerTagName: 'svg',1142 tagName: 'marker',1143 },1144 {1145 name: 'mask',1146 containerTagName: 'svg',1147 tagName: 'path',1148 read: getSVGAttribute('mask'),1149 },1150 {1151 name: 'maskContentUnits',1152 read: getSVGProperty('maskContentUnits'),1153 containerTagName: 'svg',1154 tagName: 'mask',1155 overrideStringValue: 'objectBoundingBox',1156 },1157 {1158 name: 'maskUnits',1159 read: getSVGProperty('maskUnits'),1160 containerTagName: 'svg',1161 tagName: 'mask',1162 overrideStringValue: 'userSpaceOnUse',1163 },1164 {1165 name: 'mathematical',1166 read: getSVGAttribute('mathematical'),1167 containerTagName: 'svg',1168 tagName: 'font-face',1169 },1170 {name: 'max', tagName: 'input'},1171 {name: 'max', tagName: 'meter'},1172 {name: 'max', tagName: 'progress'},1173 {1174 name: 'max',1175 containerTagName: 'svg',1176 tagName: 'animate',1177 read: getSVGAttribute('max'),1178 },1179 {name: 'maxLength', tagName: 'textarea'},1180 {name: 'media', tagName: 'link'},1181 {1182 name: 'media',1183 containerTagName: 'svg',1184 tagName: 'style',1185 read: getSVGProperty('media'),1186 },1187 {name: 'mediaGroup', tagName: 'video', read: getAttribute('mediagroup')}, // TODO: Not yet implemented in Chrome.1188 {name: 'method', tagName: 'form', overrideStringValue: 'POST'},1189 {1190 name: 'method',1191 containerTagName: 'svg',1192 tagName: 'textPath',1193 read: getSVGProperty('method'),1194 overrideStringValue: 'stretch',1195 },1196 {name: 'min', tagName: 'input'},1197 {name: 'min', tagName: 'meter'},1198 {1199 name: 'min',1200 containerTagName: 'svg',1201 tagName: 'animate',1202 read: getSVGAttribute('min'),1203 },1204 {name: 'minLength', tagName: 'input'},1205 {1206 name: 'mode',1207 read: getSVGProperty('mode'),1208 containerTagName: 'svg',1209 tagName: 'feBlend',1210 overrideStringValue: 'multiply',1211 },1212 {name: 'multiple', tagName: 'select'},1213 {name: 'muted', tagName: 'video'},1214 {name: 'name', tagName: 'input'},1215 {1216 name: 'name',1217 containerTagName: 'svg',1218 tagName: 'color-profile',1219 read: getSVGAttribute('color-profile'),1220 },1221 {name: 'noModule', tagName: 'script'},1222 {name: 'nonce', read: getAttribute('nonce')},1223 {name: 'noValidate', tagName: 'form'},1224 {1225 name: 'numOctaves',1226 read: getSVGProperty('numOctaves'),1227 containerTagName: 'svg',1228 tagName: 'feTurbulence',1229 },1230 {1231 name: 'offset',1232 read: getSVGProperty('offset'),1233 containerTagName: 'svg',1234 tagName: 'stop',1235 },1236 {name: 'on-click'}, // TODO: Check for event subscriptions1237 {name: 'on-unknownevent'}, // TODO: Check for event subscriptions1238 {name: 'onclick'}, // TODO: Check for event subscriptions1239 {name: 'onClick'}, // TODO: Check for event subscriptions1240 {name: 'onunknownevent'}, // TODO: Check for event subscriptions1241 {name: 'onUnknownEvent'}, // TODO: Check for event subscriptions1242 {1243 name: 'opacity',1244 containerTagName: 'svg',1245 tagName: 'path',1246 read: getSVGAttribute('opacity'),1247 },1248 {name: 'open', tagName: 'details'},1249 {1250 name: 'operator',1251 read: getSVGProperty('operator'),1252 containerTagName: 'svg',1253 tagName: 'feComposite',1254 overrideStringValue: 'xor',1255 },1256 {name: 'optimum', tagName: 'meter'},1257 {1258 name: 'order',1259 read: getSVGAttribute('order'),1260 containerTagName: 'svg',1261 tagName: 'feConvolveMatrix',1262 },1263 {1264 name: 'orient',1265 read: getSVGAttribute('orient'),1266 containerTagName: 'svg',1267 tagName: 'marker',1268 },1269 {1270 name: 'orientation',1271 read: getSVGAttribute('orientation'),1272 containerTagName: 'svg',1273 tagName: 'glyph',1274 },1275 {1276 name: 'origin',1277 read: getSVGAttribute('origin'),1278 containerTagName: 'svg',1279 tagName: 'animateMotion',1280 },1281 {1282 name: 'overflow',1283 containerTagName: 'svg',1284 tagName: 'path',1285 read: getSVGAttribute('overflow'),1286 },1287 {1288 name: 'overline-position',1289 read: getSVGAttribute('overline-position'),1290 containerTagName: 'svg',1291 tagName: 'font-face',1292 },1293 {1294 name: 'overline-thickness',1295 read: getSVGAttribute('overline-thickness'),1296 containerTagName: 'svg',1297 tagName: 'font-face',1298 },1299 {1300 name: 'overlinePosition',1301 read: getSVGAttribute('overline-position'),1302 containerTagName: 'svg',1303 tagName: 'font-face',1304 },1305 {1306 name: 'overlineThickness',1307 read: getSVGAttribute('overline-thickness'),1308 containerTagName: 'svg',1309 tagName: 'font-face',1310 },1311 {1312 name: 'paint-order',1313 containerTagName: 'svg',1314 tagName: 'path',1315 read: getSVGAttribute('paint-order'),1316 },1317 {1318 name: 'paintOrder',1319 containerTagName: 'svg',1320 tagName: 'path',1321 read: getSVGAttribute('paint-order'),1322 },1323 {1324 name: 'panose-1',1325 read: getSVGAttribute('panose-1'),1326 containerTagName: 'svg',1327 tagName: 'font-face',1328 },1329 {1330 name: 'panose1',1331 containerTagName: 'svg',1332 tagName: 'font-face',1333 read: getSVGAttribute('panose-1'),1334 },1335 {1336 name: 'pathLength',1337 read: getSVGProperty('pathLength'),1338 containerTagName: 'svg',1339 tagName: 'path',1340 },1341 {name: 'pattern', tagName: 'input'},1342 {1343 name: 'patternContentUnits',1344 read: getSVGProperty('patternContentUnits'),1345 containerTagName: 'svg',1346 tagName: 'pattern',1347 overrideStringValue: 'objectBoundingBox',1348 },1349 {1350 name: 'patternTransform',1351 read: getSVGProperty('patternTransform'),1352 containerTagName: 'svg',1353 tagName: 'pattern',1354 overrideStringValue:1355 'translate(-10,-20) scale(2) rotate(45) translate(5,10)',1356 },1357 {1358 name: 'patternUnits',1359 read: getSVGProperty('patternUnits'),1360 containerTagName: 'svg',1361 tagName: 'pattern',1362 overrideStringValue: 'userSpaceOnUse',1363 },1364 {name: 'placeholder', tagName: 'input'},1365 {name: 'playsInline', read: getAttribute('playsinline')},1366 {1367 name: 'pointer-events',1368 containerTagName: 'svg',1369 tagName: 'path',1370 read: getSVGAttribute('pointer-events'),1371 },1372 {1373 name: 'pointerEvents',1374 containerTagName: 'svg',1375 tagName: 'path',1376 read: getSVGAttribute('pointer-events'),1377 },1378 {1379 name: 'points',1380 read: getSVGProperty('points'),1381 containerTagName: 'svg',1382 tagName: 'polygon',1383 overrideStringValue: '350,75 379,161 469,161',1384 },1385 {1386 name: 'pointsAtX',1387 read: getSVGProperty('pointsAtX'),1388 containerTagName: 'svg',1389 tagName: 'feSpotLight',1390 },1391 {1392 name: 'pointsAtY',1393 read: getSVGProperty('pointsAtY'),1394 containerTagName: 'svg',1395 tagName: 'feSpotLight',1396 },1397 {1398 name: 'pointsAtZ',1399 read: getSVGProperty('pointsAtZ'),1400 containerTagName: 'svg',1401 tagName: 'feSpotLight',1402 },1403 {1404 name: 'poster',1405 tagName: 'video',1406 overrideStringValue: 'https://reactjs.com',1407 },1408 {name: 'prefix', read: getAttribute('prefix')},1409 {name: 'preload', tagName: 'video', overrideStringValue: 'none'},1410 {1411 name: 'preserveAlpha',1412 read: getSVGProperty('preserveAlpha'),1413 containerTagName: 'svg',1414 tagName: 'feConvolveMatrix',1415 },1416 {1417 name: 'preserveAspectRatio',1418 read: getSVGProperty('preserveAspectRatio'),1419 containerTagName: 'svg',1420 tagName: 'feImage',1421 overrideStringValue: 'xMinYMin slice',1422 },1423 {1424 name: 'primitiveUnits',1425 read: getSVGProperty('primitiveUnits'),1426 containerTagName: 'svg',1427 tagName: 'filter',1428 overrideStringValue: 'objectBoundingBox',1429 },1430 {name: 'profile', read: getAttribute('profile')},1431 {name: 'property', read: getAttribute('property')},1432 {name: 'props', read: getAttribute('props')},1433 {1434 name: 'r',1435 read: getSVGProperty('r'),1436 containerTagName: 'svg',1437 tagName: 'circle',1438 overrideStringValue: '10pt',1439 },1440 {name: 'radioGroup', tagName: 'command', read: getAttribute('radiogroup')},1441 {1442 name: 'radius',1443 read: getSVGAttribute('radius'),1444 containerTagName: 'svg',1445 tagName: 'feMorphology',1446 },1447 {name: 'readOnly', tagName: 'input'},1448 {name: 'referrerPolicy', tagName: 'iframe'},1449 {1450 name: 'refX',1451 read: getSVGProperty('refX'),1452 containerTagName: 'svg',1453 tagName: 'marker',1454 overrideStringValue: '5em',1455 },1456 {1457 name: 'refY',1458 read: getSVGProperty('refY'),1459 containerTagName: 'svg',1460 tagName: 'marker',1461 overrideStringValue: '6em',1462 },1463 {name: 'rel', tagName: 'a'},1464 {1465 name: 'rendering-intent',1466 read: getSVGAttribute('rendering-intent'),1467 containerTagName: 'svg',1468 tagName: 'color-profile',1469 },1470 {1471 name: 'renderingIntent',1472 read: getSVGAttribute('rendering-intent'),1473 containerTagName: 'svg',1474 tagName: 'color-profile',1475 },1476 {1477 name: 'repeatCount',1478 read: getSVGAttribute('repeatcount'),1479 containerTagName: 'svg',1480 tagName: 'animate',1481 },1482 {1483 name: 'repeatDur',1484 read: getSVGAttribute('repeatdur'),1485 containerTagName: 'svg',1486 tagName: 'animate',1487 },1488 {name: 'required', tagName: 'input'},1489 {1490 name: 'requiredExtensions',1491 read: getSVGProperty('requiredExtensions'),1492 containerTagName: 'svg',1493 tagName: 'a',1494 },1495 {1496 name: 'requiredFeatures',1497 read: getSVGAttribute('requiredFeatures'),1498 containerTagName: 'svg',1499 tagName: 'a',1500 },1501 {name: 'resource', read: getAttribute('resource')},1502 {1503 name: 'restart',1504 read: getSVGAttribute('resource'),1505 containerTagName: 'svg',1506 tagName: 'animate',1507 },1508 {1509 name: 'result',1510 read: getSVGProperty('result'),1511 containerTagName: 'svg',1512 tagName: 'feBlend',1513 },1514 {name: 'results', tagName: 'input', read: getAttribute('results')}, // TODO: Should use property but it's not supported in Chrome.1515 {name: 'reversed', tagName: 'ol'},1516 {name: 'role', read: getAttribute('role')},1517 {1518 name: 'rotate',1519 read: getSVGAttribute('role'),1520 containerTagName: 'svg',1521 tagName: 'altGlyph',1522 },1523 {name: 'rows', tagName: 'textarea'},1524 {name: 'rowSpan', containerTagName: 'tr', tagName: 'td'},1525 {1526 name: 'rx',1527 read: getSVGProperty('rx'),1528 containerTagName: 'svg',1529 tagName: 'ellipse',1530 overrideStringValue: '1px',1531 },1532 {1533 name: 'ry',1534 read: getSVGProperty('ry'),1535 containerTagName: 'svg',1536 tagName: 'ellipse',1537 overrideStringValue: '2px',1538 },1539 {1540 name: 'sandbox',1541 tagName: 'iframe',1542 overrideStringValue: 'allow-forms allow-scripts',1543 },1544 {1545 name: 'scale',1546 read: getSVGProperty('scale'),1547 containerTagName: 'svg',1548 tagName: 'feDisplacementMap',1549 },1550 {1551 name: 'scope',1552 containerTagName: 'tr',1553 tagName: 'th',1554 overrideStringValue: 'row',1555 },1556 {name: 'scoped', tagName: 'style', read: getAttribute('scoped')},1557 {name: 'scrolling', tagName: 'iframe', overrideStringValue: 'no'},1558 {name: 'seamless', tagName: 'iframe', read: getAttribute('seamless')},1559 {name: 'security', tagName: 'iframe', read: getAttribute('security')},1560 {1561 name: 'seed',1562 read: getSVGProperty('seed'),1563 containerTagName: 'svg',1564 tagName: 'feTurbulence',1565 },1566 {name: 'selected', tagName: 'option', containerTagName: 'select'},1567 {name: 'selectedIndex', tagName: 'select'},1568 {name: 'shape', tagName: 'a'},1569 {1570 name: 'shape-rendering',1571 tagName: 'svg',1572 read: getSVGAttribute('shape-rendering'),1573 },1574 {1575 name: 'shapeRendering',1576 tagName: 'svg',1577 read: getSVGAttribute('shape-rendering'),1578 },1579 {name: 'size', tagName: 'input'},1580 {name: 'sizes', tagName: 'link'},1581 {1582 name: 'slope',1583 read: getSVGAttribute('slope'),1584 containerTagName: 'svg',1585 tagName: 'font-face',1586 },1587 {1588 name: 'spacing',1589 read: getSVGProperty('spacing'),1590 containerTagName: 'svg',1591 tagName: 'textPath',1592 overrideStringValue: 'auto',1593 },1594 {name: 'span', containerTagName: 'colgroup', tagName: 'col'},1595 {1596 name: 'specularConstant',1597 read: getSVGProperty('specularConstant'),1598 containerTagName: 'svg',1599 tagName: 'feSpecularLighting',1600 },1601 {1602 name: 'specularExponent',1603 read: getSVGProperty('specularConstant'),1604 containerTagName: 'svg',1605 tagName: 'feSpecularLighting',1606 },1607 {name: 'speed', read: getAttribute('speed')},1608 {1609 name: 'spellCheck',1610 overrideStringValue: 'false',1611 tagName: 'input',1612 read: getProperty('spellcheck'),1613 },1614 {1615 name: 'spellcheck',1616 overrideStringValue: 'false',1617 tagName: 'input',1618 read: getProperty('spellcheck'),1619 },1620 {1621 name: 'spreadMethod',1622 read: getSVGProperty('spreadMethod'),1623 containerTagName: 'svg',1624 tagName: 'linearGradient',1625 overrideStringValue: 'reflect',1626 },1627 {name: 'src', tagName: 'img', overrideStringValue: 'https://reactjs.com'},1628 {1629 name: 'srcDoc',1630 tagName: 'iframe',1631 overrideStringValue: '<p>Hi</p>',1632 read: getProperty('srcdoc'),1633 },1634 {1635 name: 'srcdoc',1636 tagName: 'iframe',1637 overrideStringValue: '<p>Hi</p>',1638 read: getProperty('srcdoc'),1639 },1640 {1641 name: 'srcLang',1642 containerTagName: 'audio',1643 tagName: 'track',1644 overrideStringValue: 'en',1645 read: getProperty('srclang'),1646 },1647 {1648 name: 'srclang',1649 containerTagName: 'audio',1650 tagName: 'track',1651 overrideStringValue: 'en',1652 read: getProperty('srclang'),1653 },1654 {name: 'srcSet', tagName: 'img'},1655 {name: 'srcset', tagName: 'img'},1656 {name: 'start', tagName: 'ol'},1657 {1658 name: 'startOffset',1659 read: getSVGProperty('startOffset'),1660 containerTagName: 'svg',1661 tagName: 'textPath',1662 },1663 {name: 'state', read: getAttribute('state')},1664 {1665 name: 'stdDeviation',1666 read: getSVGAttribute('stdDeviation'),1667 containerTagName: 'svg',1668 tagName: 'feGaussianBlur',1669 },1670 {1671 name: 'stemh',1672 read: getSVGAttribute('stemh'),1673 containerTagName: 'svg',1674 tagName: 'font-face',1675 },1676 {1677 name: 'stemv',1678 read: getSVGAttribute('stemv'),1679 containerTagName: 'svg',1680 tagName: 'font-face',1681 },1682 {name: 'step', read: getAttribute('step')},1683 {1684 name: 'stitchTiles',1685 read: getSVGProperty('stitchTiles'),1686 containerTagName: 'svg',1687 tagName: 'feTurbulence',1688 overrideStringValue: 'stitch',1689 },1690 {1691 name: 'stop-color',1692 containerTagName: 'svg',1693 tagName: 'stop',1694 read: getSVGAttribute('stop-color'),1695 },1696 {1697 name: 'stop-opacity',1698 containerTagName: 'svg',1699 tagName: 'stop',1700 read: getSVGAttribute('stop-opacity'),1701 },1702 {1703 name: 'stopColor',1704 containerTagName: 'svg',1705 tagName: 'stop',1706 read: getSVGAttribute('stop-color'),1707 },1708 {1709 name: 'stopOpacity',1710 containerTagName: 'svg',1711 tagName: 'stop',1712 read: getSVGAttribute('stop-opacity'),1713 },1714 {1715 name: 'strikethrough-position',1716 read: getSVGAttribute('strikethrough-position'),1717 containerTagName: 'svg',1718 tagName: 'font-face',1719 },1720 {1721 name: 'strikethrough-thickness',1722 read: getSVGAttribute('strikethrough-thickness'),1723 containerTagName: 'svg',1724 tagName: 'font-face',1725 },1726 {1727 name: 'strikethroughPosition',1728 read: getSVGAttribute('strikethrough-position'),1729 containerTagName: 'svg',1730 tagName: 'font-face',1731 },1732 {1733 name: 'strikethroughThickness',1734 read: getSVGAttribute('strikethrough-thickness'),1735 containerTagName: 'svg',1736 tagName: 'font-face',1737 },1738 {1739 name: 'string',1740 read: getSVGAttribute('string'),1741 containerTagName: 'svg',1742 tagName: 'font-face-format',1743 },1744 {1745 name: 'stroke',1746 containerTagName: 'svg',1747 tagName: 'path',1748 read: getSVGAttribute('stroke'),1749 },1750 {1751 name: 'stroke-dasharray',1752 containerTagName: 'svg',1753 tagName: 'path',1754 read: getSVGAttribute('stroke-dasharray'),1755 },1756 {1757 name: 'stroke-Dasharray',1758 containerTagName: 'svg',1759 tagName: 'path',1760 read: getSVGAttribute('stroke-dasharray'),1761 },1762 {1763 name: 'stroke-dashoffset',1764 containerTagName: 'svg',1765 tagName: 'path',1766 read: getSVGAttribute('stroke-dashoffset'),1767 },1768 {1769 name: 'stroke-linecap',1770 containerTagName: 'svg',1771 tagName: 'path',1772 read: getSVGAttribute('stroke-linecap'),1773 },1774 {1775 name: 'stroke-linejoin',1776 containerTagName: 'svg',1777 tagName: 'path',1778 read: getSVGAttribute('stroke-linejoin'),1779 },1780 {1781 name: 'stroke-miterlimit',1782 containerTagName: 'svg',1783 tagName: 'path',1784 read: getSVGAttribute('stroke-miterlimit'),1785 },1786 {1787 name: 'stroke-opacity',1788 containerTagName: 'svg',1789 tagName: 'path',1790 read: getSVGAttribute('stroke-opacity'),1791 },1792 {1793 name: 'stroke-width',1794 containerTagName: 'svg',1795 tagName: 'path',1796 read: getSVGAttribute('stroke-width'),1797 },1798 {1799 name: 'strokeDasharray',1800 containerTagName: 'svg',1801 tagName: 'path',1802 read: getSVGAttribute('stroke-dasharray'),1803 },1804 {1805 name: 'strokeDashoffset',1806 containerTagName: 'svg',1807 tagName: 'path',1808 read: getSVGAttribute('stroke-dashoffset'),1809 },1810 {1811 name: 'strokeLinecap',1812 containerTagName: 'svg',1813 tagName: 'path',1814 read: getSVGAttribute('stroke-linecap'),1815 },1816 {1817 name: 'strokeLinejoin',1818 containerTagName: 'svg',1819 tagName: 'path',1820 read: getSVGAttribute('stroke-linejoin'),1821 },1822 {1823 name: 'strokeMiterlimit',1824 containerTagName: 'svg',1825 tagName: 'path',1826 read: getSVGAttribute('stroke-miterlimit'),1827 },1828 {1829 name: 'strokeOpacity',1830 containerTagName: 'svg',1831 tagName: 'path',1832 read: getSVGAttribute('stroke-opacity'),1833 },1834 {1835 name: 'strokeWidth',1836 containerTagName: 'svg',1837 tagName: 'path',1838 read: getSVGAttribute('stroke-width'),1839 },1840 {name: 'style'},1841 {name: 'summary', tagName: 'table'},1842 {1843 name: 'suppressContentEditableWarning',1844 read: getAttribute('suppresscontenteditablewarning'),1845 },1846 {1847 name: 'surfaceScale',1848 read: getSVGProperty('surfaceScale'),1849 containerTagName: 'svg',1850 tagName: 'feDiffuseLighting',1851 },1852 {1853 name: 'systemLanguage',1854 overrideStringValue: 'en',1855 read: getSVGProperty('systemLanguage'),1856 containerTagName: 'svg',1857 tagName: 'a',1858 },1859 {name: 'tabIndex'},1860 {1861 name: 'tabIndex',1862 read: getSVGProperty('tabIndex'),1863 tagName: 'svg',1864 },1865 {1866 name: 'tableValues',1867 read: getSVGProperty('tableValues'),1868 containerTagName: 'svg',1869 tagName: 'feFuncA',1870 overrideStringValue: '0 1 2 3',1871 },1872 {1873 name: 'target',1874 read: getSVGProperty('target'),1875 containerTagName: 'svg',1876 tagName: 'a',1877 },1878 {1879 name: 'targetX',1880 read: getSVGProperty('targetX'),1881 containerTagName: 'svg',1882 tagName: 'feConvolveMatrix',1883 },1884 {1885 name: 'targetY',1886 read: getSVGProperty('targetY'),1887 containerTagName: 'svg',1888 tagName: 'feConvolveMatrix',1889 },1890 {1891 name: 'text-anchor',1892 containerTagName: 'svg',1893 tagName: 'text',1894 read: getSVGAttribute('text-anchor'),1895 },1896 {1897 name: 'text-decoration',1898 containerTagName: 'svg',1899 tagName: 'text',1900 read: getSVGAttribute('text-decoration'),1901 },1902 {1903 name: 'text-rendering',1904 tagName: 'svg',1905 read: getSVGAttribute('text-rendering'),1906 },1907 {1908 name: 'textAnchor',1909 containerTagName: 'svg',1910 tagName: 'text',1911 read: getSVGAttribute('text-anchor'),1912 },1913 {1914 name: 'textDecoration',1915 containerTagName: 'svg',1916 tagName: 'text',1917 read: getSVGAttribute('text-decoration'),1918 },1919 {1920 name: 'textLength',1921 read: getSVGProperty('textLength'),1922 containerTagName: 'svg',1923 tagName: 'text',1924 },1925 {1926 name: 'textRendering',1927 tagName: 'svg',1928 read: getSVGAttribute('text-rendering'),1929 },1930 {name: 'title'},1931 {1932 name: 'to',1933 read: getSVGAttribute('to'),1934 containerTagName: 'svg',1935 tagName: 'set',1936 },1937 {1938 name: 'transform',1939 read: getSVGProperty('transform'),1940 containerTagName: 'svg',1941 tagName: 'a',1942 overrideStringValue:1943 'translate(-10,-20) scale(2) rotate(45) translate(5,10)',1944 },1945 {name: 'type', tagName: 'button', overrideStringValue: 'reset'},1946 {1947 name: 'type',1948 containerTagName: 'svg',1949 tagName: 'feFuncA',1950 read: getSVGProperty('type'),1951 overrideStringValue: 'discrete',1952 },1953 {name: 'typeof', read: getAttribute('typeof')},1954 {1955 name: 'u1',1956 read: getSVGAttribute('u1'),1957 containerTagName: 'svg',1958 tagName: 'hkern',1959 },1960 {1961 name: 'u2',1962 read: getSVGAttribute('u2'),1963 containerTagName: 'svg',1964 tagName: 'hkern',1965 },1966 {1967 name: 'underline-position',1968 read: getSVGAttribute('underline-position'),1969 containerTagName: 'svg',1970 tagName: 'font-face',1971 },1972 {1973 name: 'underline-thickness',1974 read: getSVGAttribute('underline-thickness'),1975 containerTagName: 'svg',1976 tagName: 'font-face',1977 },1978 {1979 name: 'underlinePosition',1980 read: getSVGAttribute('underline-position'),1981 containerTagName: 'svg',1982 tagName: 'font-face',1983 },1984 {1985 name: 'underlineThickness',1986 read: getSVGAttribute('underline-thickness'),1987 containerTagName: 'svg',1988 tagName: 'font-face',1989 },1990 {1991 name: 'unicode',1992 read: getSVGAttribute('unicode'),1993 containerTagName: 'svg',1994 tagName: 'glyph',1995 },1996 {1997 name: 'unicode-bidi',1998 containerTagName: 'svg',1999 tagName: 'text',2000 read: getSVGAttribute('unicode-bidi'),2001 },2002 {2003 name: 'unicode-range',2004 read: getSVGAttribute('unicode-range'),2005 containerTagName: 'svg',2006 tagName: 'font-face',2007 },2008 {2009 name: 'unicodeBidi',2010 containerTagName: 'svg',2011 tagName: 'text',2012 read: getSVGAttribute('unicode-bidi'),2013 },2014 {2015 name: 'unicodeRange',2016 read: getSVGAttribute('unicode-range'),2017 containerTagName: 'svg',2018 tagName: 'font-face',2019 },2020 {2021 name: 'units-per-em',2022 read: getSVGAttribute('units-per-em'),2023 containerTagName: 'svg',2024 tagName: 'font-face',2025 },2026 {2027 name: 'unitsPerEm',2028 read: getSVGAttribute('unites-per-em'),2029 containerTagName: 'svg',2030 tagName: 'font-face',2031 },2032 {name: 'unknown', read: getAttribute('unknown')},2033 {2034 name: 'unselectable',2035 read: getAttribute('unselectable'),2036 tagName: 'span',2037 overrideStringValue: 'on',2038 },2039 {name: 'useMap', tagName: 'img'},2040 {2041 name: 'v-alphabetic',2042 read: getSVGAttribute('v-alphabetic'),2043 containerTagName: 'svg',2044 tagName: 'font-face',2045 },2046 {2047 name: 'v-hanging',2048 read: getSVGAttribute('v-hanging'),2049 containerTagName: 'svg',2050 tagName: 'font-face',2051 },2052 {2053 name: 'v-ideographic',2054 read: getSVGAttribute('v-ideographic'),2055 containerTagName: 'svg',2056 tagName: 'font-face',2057 },2058 {2059 name: 'v-mathematical',2060 read: getSVGAttribute('v-mathematical'),2061 containerTagName: 'svg',2062 tagName: 'font-face',2063 },2064 {2065 name: 'vAlphabetic',2066 read: getSVGAttribute('v-alphabetic'),2067 containerTagName: 'svg',2068 tagName: 'font-face',2069 },2070 {name: 'value', tagName: 'input', extraProps: {onChange() {}}},2071 {name: 'value', tagName: 'input', type: 'email', extraProps: {onChange() {}}},2072 {2073 name: 'value',2074 tagName: 'input',2075 type: 'number',2076 extraProps: {onChange() {}},2077 },2078 {name: 'value', tagName: 'textarea', extraProps: {onChange() {}}},2079 {2080 name: 'value',2081 containerTagName: 'select',2082 tagName: 'option',2083 extraProps: {onChange() {}},2084 },2085 {2086 name: 'Value',2087 containerTagName: 'select',2088 tagName: 'option',2089 read: getProperty('value'),2090 },2091 {2092 name: 'values',2093 read: getSVGProperty('values'),2094 containerTagName: 'svg',2095 tagName: 'feColorMatrix',2096 overrideStringValue: '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0',2097 },2098 {2099 name: 'vector-effect',2100 containerTagName: 'svg',2101 tagName: 'line',2102 read: getSVGAttribute('vector-effect'),2103 },2104 {2105 name: 'vectorEffect',2106 containerTagName: 'svg',2107 tagName: 'line',2108 read: getSVGAttribute('vector-effect'),2109 },2110 {name: 'version', containerTagName: 'document', tagName: 'html'},2111 {name: 'version', tagName: 'svg', read: getSVGAttribute('version')},2112 {2113 name: 'vert-adv-y',2114 read: getSVGAttribute('vert-origin-y'),2115 containerTagName: 'svg',2116 tagName: 'font',2117 },2118 {2119 name: 'vert-origin-x',2120 read: getSVGAttribute('vert-origin-y'),2121 containerTagName: 'svg',2122 tagName: 'font',2123 },2124 {2125 name: 'vert-origin-y',2126 read: getSVGAttribute('vert-origin-y'),2127 containerTagName: 'svg',2128 tagName: 'font',2129 },2130 {2131 name: 'vertAdvY',2132 read: getSVGAttribute('vert-adv-y'),2133 containerTagName: 'svg',2134 tagName: 'font',2135 },2136 {2137 name: 'vertOriginX',2138 read: getSVGAttribute('vert-origin-x'),2139 containerTagName: 'svg',2140 tagName: 'font',2141 },2142 {2143 name: 'vertOriginY',2144 read: getSVGAttribute('vert-origin-y'),2145 containerTagName: 'svg',2146 tagName: 'font',2147 },2148 {2149 name: 'vHanging',2150 read: getSVGAttribute('v-hanging'),2151 containerTagName: 'svg',2152 tagName: 'font-face',2153 },2154 {2155 name: 'vIdeographic',2156 read: getSVGAttribute('v-ideographic'),2157 containerTagName: 'svg',2158 tagName: 'font-face',2159 },2160 {2161 name: 'viewBox',2162 read: getSVGProperty('viewBox'),2163 containerTagName: 'svg',2164 tagName: 'marker',2165 overrideStringValue: '0 0 1500 1000',2166 },2167 {2168 name: 'viewTarget',2169 read: getSVGAttribute('viewTarget'),2170 containerTagName: 'svg',2171 tagName: 'view',2172 },2173 {name: 'visibility', read: getAttribute('visibility')},2174 {2175 name: 'visibility',2176 containerTagName: 'svg',2177 tagName: 'path',2178 read: getSVGAttribute('visibility'),2179 },2180 {2181 name: 'vMathematical',2182 read: getSVGAttribute('v-mathematical'),2183 containerTagName: 'svg',2184 tagName: 'font-face',2185 },2186 {name: 'vocab', read: getAttribute('vocab')},2187 {name: 'width', tagName: 'img'},2188 {2189 name: 'width',2190 containerTagName: 'svg',2191 tagName: 'rect',2192 read: getSVGProperty('width'),2193 },2194 {2195 name: 'widths',2196 read: getSVGAttribute('widths'),2197 containerTagName: 'svg',2198 tagName: 'font-face',2199 },2200 {name: 'wmode', read: getAttribute('wmode'), tagName: 'embed'},2201 {2202 name: 'word-spacing',2203 containerTagName: 'svg',2204 tagName: 'text',2205 read: getSVGAttribute('word-spacing'),2206 },2207 {2208 name: 'wordSpacing',2209 containerTagName: 'svg',2210 tagName: 'text',2211 read: getSVGAttribute('word-spacing'),2212 },2213 {name: 'wrap', tagName: 'textarea'},2214 {2215 name: 'writing-mode',2216 containerTagName: 'svg',2217 tagName: 'text',2218 read: getSVGAttribute('writing-mode'),2219 },2220 {2221 name: 'writingMode',2222 containerTagName: 'svg',2223 tagName: 'text',2224 read: getSVGAttribute('writing-mode'),2225 },2226 {2227 name: 'x',2228 read: getSVGAttribute('x'),2229 containerTagName: 'svg',2230 tagName: 'altGlyph',2231 },2232 {2233 name: 'x-height',2234 read: getSVGAttribute('x-height'),2235 containerTagName: 'svg',2236 tagName: 'font-face',2237 },2238 {2239 name: 'x1',2240 read: getSVGProperty('x1'),2241 containerTagName: 'svg',2242 tagName: 'line',2243 },2244 {2245 name: 'x2',2246 read: getSVGProperty('x2'),2247 containerTagName: 'svg',2248 tagName: 'line',2249 },2250 {2251 name: 'xChannelSelector',2252 read: getSVGProperty('xChannelSelector'),2253 containerTagName: 'svg',2254 tagName: 'feDisplacementMap',2255 overrideStringValue: 'R',2256 },2257 {2258 name: 'xHeight',2259 read: getSVGAttribute('x-height'),2260 containerTagName: 'svg',2261 tagName: 'font-face',2262 },2263 {name: 'XLink:Actuate', read: getAttribute('XLink:Actuate')},2264 {name: 'xlink:actuate', read: getAttribute('xlink:actuate')},2265 {name: 'xlink:arcrole', read: getAttribute('xlink:arcrole')},2266 {name: 'xlink:href', read: getAttribute('xlink:href')},2267 {name: 'xlink:role', read: getAttribute('xlink:role')},2268 {name: 'xlink:show', read: getAttribute('xlink:show')},2269 {name: 'xlink:title', read: getAttribute('xlink:title')},2270 {name: 'xlink:type', read: getAttribute('xlink:type')},2271 {name: 'xlinkActuate', read: getAttribute('xlink:actuate')},2272 {name: 'XlinkActuate', read: getAttribute('Xlink:actuate')},2273 {name: 'xlinkArcrole', read: getAttribute('xlink:arcrole')},2274 {name: 'xlinkHref', read: getAttribute('xlink:href')},2275 {name: 'xlinkRole', read: getAttribute('xlink:role')},2276 {name: 'xlinkShow', read: getAttribute('xlink:show')},2277 {name: 'xlinkTitle', read: getAttribute('xlink:title')},2278 {name: 'xlinkType', read: getAttribute('xlink:type')},2279 {name: 'xml:base', read: getAttribute('xml:base')},2280 {name: 'xml:lang', read: getAttribute('xml:lang')},2281 {name: 'xml:space', read: getAttribute('xml:space')},2282 {name: 'xmlBase', read: getAttribute('xml:base')},2283 {name: 'xmlLang', read: getAttribute('xml:lang')},2284 {name: 'xmlns', read: getProperty('namespaceURI'), tagName: 'svg'},2285 {name: 'xmlns:xlink', read: getAttribute('xmlns:xlink')},2286 {name: 'xmlnsXlink', read: getAttribute('xmlns:xlink')},2287 {name: 'xmlSpace', read: getAttribute('xml:space')},2288 {2289 name: 'y',2290 read: getSVGAttribute('y'),2291 containerTagName: 'svg',2292 tagName: 'altGlyph',2293 },2294 {2295 name: 'y1',2296 read: getSVGProperty('y1'),2297 containerTagName: 'svg',2298 tagName: 'line',2299 },2300 {2301 name: 'y2',2302 read: getSVGProperty('y2'),2303 containerTagName: 'svg',2304 tagName: 'line',2305 },2306 {2307 name: 'yChannelSelector',2308 read: getSVGProperty('yChannelSelector'),2309 containerTagName: 'svg',2310 tagName: 'feDisplacementMap',2311 overrideStringValue: 'B',2312 },2313 {2314 name: 'z',2315 read: getSVGProperty('z'),2316 containerTagName: 'svg',2317 tagName: 'fePointLight',2318 },2319 {name: 'zoomAndPan', read: getSVGProperty('zoomAndPan'), tagName: 'svg'},2320];2321attributes.forEach(attr => {2322 attr.read = attr.read || getProperty(attr.name);2323});...

Full Screen

Full Screen

replset_read_preference.test.js

Source:replset_read_preference.test.js Github

copy

Full Screen

1'use strict';2var format = require('util').format;3var fs = require('fs');4var test = require('./shared').assert;5var setupDatabase = require('./shared').setupDatabase;6var restartAndDone = function (done) {7 done();8};9function filterSecondaries(hosts, isMaster) {10 return hosts.reduce((secondaries, host) => {11 if (isMaster.primary !== host && isMaster.arbiters && isMaster.arbiters.indexOf(host) === -1) {12 secondaries[host] = host;13 }14 }, {});15}16// NOTE: skipped because they haven't worked in some time, need refactoring17describe.skip('ReplSet (ReadPreference)', function () {18 before(function () {19 return setupDatabase(this.configuration);20 });21 it('Should Correctly Pick lowest ping time', {22 metadata: { requires: { topology: 'replicaset' } },23 test: function (done) {24 var configuration = this.configuration;25 var mongo = configuration.require,26 ReadPreference = mongo.ReadPreference;27 // Open the database28 const client = configuration.newClient(29 {},30 { secondaryAcceptableLatencyMS: 5, debug: true, w: 1 }31 );32 // Trigger test once whole set is up33 client.on('fullsetup', function (client) {34 var db = client.db(configuration.db);35 db.command({ ismaster: true }, function (err, result) {36 test.equal(null, err);37 var time = 10;38 // // Nearest strategy39 // var nearest = client.topology.replset.readPreferenceStrategies['nearest'];40 // Sorted by time41 var byTime = [];42 byTime = client.topology.replset.getServers({ ignoreArbiters: true });43 byTime.forEach(function (s) {44 s.lastIsMasterMS = time;45 time = time + 10;46 });47 // // Set the ping times48 // var keys = Object.keys(nearest.data);49 // for(var i = 0; i < keys.length; i++) {50 // nearest.data[keys[i]] = time;51 // if(keys[i] != result.primary)52 // byTime.push(keys[i]);53 // time += 10;54 // }55 // // Set primary to the highest ping time56 // nearest.data[result.primary] = time;57 // byTime.push(result.primary);58 //59 var hosts = result.hosts.concat(result.passives || []);60 var secondaries = filterSecondaries(hosts, result);61 // // Last server picked62 // var lastServer = null;63 // Pick the server64 client.topology.replset.once('pickedServer', function (readPreference, server) {65 test.equal(byTime[0].name, server.name);66 });67 // Attempt to perform a read68 db.collection('somecollection').findOne(69 {},70 { readPreference: new ReadPreference(ReadPreference.NEAREST) },71 function (err) {72 test.equal(null, err);73 // Pick the server74 client.topology.replset.once('pickedServer', function (readPreference, server) {75 test.ok(secondaries.indexOf(server.name) !== -1);76 });77 // Attempt to perform a read78 db.collection('somecollection').findOne(79 {},80 { readPreference: new ReadPreference(ReadPreference.SECONDARY) },81 function (err) {82 test.equal(null, err);83 // Pick the server84 client.topology.replset.once('pickedServer', function (readPreference, server) {85 test.ok(secondaries.indexOf(server.name) !== -1);86 });87 // Attempt to perform a read88 db.collection('somecollection').findOne(89 {},90 { readPreference: new ReadPreference(ReadPreference.SECONDARY_PREFERRED) },91 function (err) {92 test.equal(null, err);93 // Pick the server94 client.topology.replset.once('pickedServer', function (95 readPreference,96 server97 ) {98 test.equal('localhost:31000', server.name);99 });100 // Attempt to perform a read101 db.collection('somecollection').findOne(102 {},103 { readPreference: new ReadPreference(ReadPreference.PRIMARY) },104 function (err) {105 test.equal(null, err);106 // Close db107 client.close();108 restartAndDone(done);109 }110 );111 }112 );113 }114 );115 }116 );117 });118 });119 client.connect(function (err) {120 test.equal(null, err);121 });122 }123 });124 it('Should Correctly vary read server when using readpreference NEAREST', {125 metadata: { requires: { topology: 'replicaset' } },126 test: function (done) {127 var configuration = this.configuration;128 var mongo = configuration.require,129 ReadPreference = mongo.ReadPreference;130 // Open the database131 const client = configuration.newClient(132 {},133 { w: 1, readPreference: ReadPreference.NEAREST, debug: true }134 );135 client.on('fullsetup', function () {136 var db = client.db(configuration.db);137 // Servers viewed138 var viewedServers = {};139 // Pick the server140 client.topology.replset.once('pickedServer', function (readPreference, server) {141 viewedServers[server.name] = server.name;142 });143 db.collection('nearest_collection_test').findOne({ a: 1 }, function (err) {144 test.equal(null, err);145 // Pick the server146 client.topology.replset.once('pickedServer', function (readPreference, server) {147 viewedServers[server.name] = server.name;148 });149 db.collection('nearest_collection_test').findOne({ a: 1 }, function (err) {150 test.equal(null, err);151 // Pick the server152 client.topology.replset.once('pickedServer', function (readPreference, server) {153 viewedServers[server.name] = server.name;154 });155 db.collection('nearest_collection_test').findOne({ a: 1 }, function (err) {156 test.equal(null, err);157 test.ok(Object.keys(viewedServers).length > 1);158 client.close();159 restartAndDone(done);160 });161 });162 });163 });164 client.connect(function (err) {165 test.equal(null, err);166 });167 }168 });169 it(170 'Should Correctly vary read server when using readpreference NEAREST passed at collection level',171 {172 metadata: { requires: { topology: 'replicaset' } },173 test: function (done) {174 var configuration = this.configuration;175 var mongo = configuration.require,176 ReadPreference = mongo.ReadPreference;177 // Open the database178 var client = configuration.newClient(179 {},180 { w: 1, readPreference: ReadPreference.NEAREST, debug: true }181 );182 client.on('fullsetup', function () {183 var db = client.db(configuration.db);184 // Servers viewed185 var viewedServers = {};186 // Pick the server187 client.topology.replset.once('pickedServer', function (readPreference, server) {188 viewedServers[server.name] = server.name;189 });190 db.collection('nearest_collection_test', {191 readPreference: 'nearest'192 }).findOne({ a: 1 }, function (err) {193 test.equal(null, err);194 // Pick the server195 client.topology.replset.once('pickedServer', function (readPreference, server) {196 viewedServers[server.name] = server.name;197 });198 db.collection('nearest_collection_test', {199 readPreference: 'nearest'200 }).findOne({ a: 1 }, function (err) {201 test.equal(null, err);202 // Pick the server203 client.topology.replset.once('pickedServer', function (readPreference, server) {204 viewedServers[server.name] = server.name;205 });206 db.collection('nearest_collection_test', {207 readPreference: 'nearest'208 }).findOne({ a: 1 }, function (err) {209 test.equal(null, err);210 test.ok(Object.keys(viewedServers).length > 1);211 client.close();212 restartAndDone(done);213 });214 });215 });216 });217 client.connect(function (err) {218 test.equal(null, err);219 });220 }221 }222 );223 it('shouldCorrectlyReadFromGridstoreWithSecondaryReadPreference', {224 metadata: { requires: { topology: 'replicaset' } },225 test: function (done) {226 var configuration = this.configuration;227 var GridStore = configuration.require.GridStore,228 ObjectId = configuration.require.ObjectId,229 ReadPreference = configuration.require.ReadPreference;230 // Create an id231 var id = new ObjectId();232 // Open the database233 var client = configuration.newClient(234 {},235 {236 w: 1,237 readPreference: ReadPreference.NEAREST,238 debug: true239 }240 );241 client.on('fullsetup', function () {242 var db = client.db(configuration.db);243 db.command({ ismaster: true }, function (err, result) {244 test.equal(null, err);245 var gridStore = new GridStore(db, id, 'w', { w: 4 });246 var secondaries = filterSecondaries(result.hosts, result);247 // Force multiple chunks to be stored248 gridStore.chunkSize = 5000;249 var data = fs.readFileSync('./test/functional/data/test_gs_weird_bug.png');250 gridStore.open(function (err, gridStore) {251 test.equal(null, err);252 // Write the file using write253 gridStore.write(data, function (err) {254 test.equal(null, err);255 gridStore.close(function (err, doc) {256 test.equal(null, err);257 // Pick the server258 client.topology.replset.once('pickedServer', function (readPreference, server) {259 test.ok(secondaries[server.name] != null);260 });261 // Read the file using readBuffer262 new GridStore(db, doc._id, 'r', {263 readPreference: ReadPreference.SECONDARY264 }).open(function (err, gridStore) {265 test.equal(null, err);266 gridStore.read(function (err, data2) {267 test.equal(null, err);268 test.equal(data.toString('base64'), data2.toString('base64'));269 client.close();270 restartAndDone(done);271 });272 });273 });274 });275 });276 });277 });278 client.connect(function (err) {279 test.equal(null, err);280 });281 }282 });283 it('Connection to replicaset with primary read preference', {284 metadata: { requires: { topology: 'replicaset' } },285 test: function (done) {286 var configuration = this.configuration;287 var mongo = configuration.require,288 ReadPreference = mongo.ReadPreference;289 // Create db instance290 var client = configuration.newClient(291 {},292 { w: 0, readPreference: ReadPreference.PRIMARY, debug: true }293 );294 // Logger.setLevel('info');295 // Trigger test once whole set is up296 client.on('fullsetup', function (client) {297 var db = client.db(configuration.db);298 db.command({ ismaster: true }, function (err, result) {299 test.equal(null, err);300 // Pick the server301 client.topology.replset.once('pickedServer', function (readPreference, server) {302 test.equal(result.primary, server.name);303 });304 // Grab the collection305 var collection = db.collection('read_preference_replicaset_test_0');306 // Attempt to read (should fail due to the server not being a primary);307 collection.find().toArray(function (err) {308 test.equal(null, err);309 client.close();310 restartAndDone(done);311 });312 });313 });314 // Connect to the db315 client.connect(function (err) {316 test.equal(null, err);317 });318 }319 });320 it('Should Set read preference at collection level using collection method', {321 metadata: { requires: { topology: 'replicaset' } },322 test: function (done) {323 var configuration = this.configuration;324 var mongo = configuration.require,325 ReadPreference = mongo.ReadPreference;326 // Create db instance327 var client = configuration.newClient({}, { w: 0, debug: true });328 // Connect to the db329 client.on('fullsetup', function (client) {330 var db = client.db(configuration.db);331 db.command({ ismaster: true }, function (err, result) {332 test.equal(null, err);333 // Filter out the secondaries334 var secondaries = filterSecondaries(result.hosts, result);335 // Pick the server336 client.topology.replset.once('pickedServer', function (readPreference, server) {337 test.ok(secondaries[server.name] != null);338 });339 // Grab the collection340 var collection = db.collection('read_preferences_all_levels_0', {341 readPreference: ReadPreference.SECONDARY342 });343 // Attempt to read (should fail due to the server not being a primary);344 var cursor = collection.find();345 cursor.toArray(function (err) {346 test.equal(null, err);347 test.equal(ReadPreference.SECONDARY, cursor.readPreference.preference);348 client.close();349 restartAndDone(done);350 });351 });352 });353 // Connect to the db354 client.connect(function (err) {355 test.equal(null, err);356 });357 }358 });359 it('Should Set read preference at collection level using createCollection method', {360 metadata: { requires: { topology: 'replicaset' } },361 test: function (done) {362 var configuration = this.configuration;363 var mongo = configuration.require,364 ReadPreference = mongo.ReadPreference;365 // Create db instance366 var client = configuration.newClient({}, { w: 0, debug: true });367 // Connect to the db368 client.on('fullsetup', function () {369 var db = client.db(configuration.db);370 db.command({ ismaster: true }, function (err, result) {371 // Filter out the secondaries372 var secondaries = filterSecondaries(result.hosts, result);373 // Grab the collection374 db.createCollection(375 'read_preferences_all_levels_1',376 { readPreference: ReadPreference.SECONDARY },377 function (err, collection) {378 test.equal(null, err);379 // Pick the server380 client.topology.replset.once('pickedServer', function (readPreference, server) {381 test.ok(secondaries[server.name] != null);382 });383 var cursor = collection.find();384 // Attempt to read (should fail due to the server not being a primary);385 cursor.toArray(function (err) {386 test.equal(null, err);387 // Does not get called or we don't care388 test.equal(ReadPreference.SECONDARY, cursor.readPreference.preference);389 client.close();390 restartAndDone(done);391 });392 }393 );394 });395 });396 // Connect to the db397 client.connect(function (err) {398 test.equal(null, err);399 });400 }401 });402 it('Should Set read preference at cursor level', {403 metadata: { requires: { topology: 'replicaset' } },404 test: function (done) {405 var configuration = this.configuration;406 var mongo = configuration.require,407 ReadPreference = mongo.ReadPreference;408 // Create db instance409 var client = configuration.newClient({}, { w: 0, debug: true });410 // Connect to the db411 client.on('fullsetup', function () {412 var db = client.db(configuration.db);413 db.command({ ismaster: true }, function (err, result) {414 // Filter out the secondaries415 var secondaries = filterSecondaries(result.hosts, result);416 // Grab the collection417 var collection = db.collection('read_preferences_all_levels_1');418 // Pick the server419 client.topology.replset.once('pickedServer', function () {420 client.topology.replset.once('pickedServer', function (readPreference, server) {421 test.ok(secondaries[server.name] != null);422 });423 });424 // Attempt to read (should fail due to the server not being a primary);425 collection426 .find()427 .setReadPreference(ReadPreference.SECONDARY)428 .toArray(function (err) {429 test.equal(null, err);430 client.close();431 restartAndDone(done);432 });433 });434 });435 // Connect to the db436 client.connect(function (err) {437 test.equal(null, err);438 });439 }440 });441 it('Attempt to change read preference at cursor level after object read legacy', {442 metadata: { requires: { topology: 'replicaset' } },443 test: function (done) {444 var configuration = this.configuration;445 var mongo = configuration.require,446 ReadPreference = mongo.ReadPreference;447 const client = configuration.newClient({}, { w: 0, debug: true });448 // Connect to the db449 client.connect(function (err, client) {450 var db = client.db(configuration.db);451 // Grab the collection452 var collection = db.collection('read_preferences_all_levels_2');453 // Insert a bunch of documents454 collection.insert([{ a: 1 }, { b: 1 }, { c: 1 }], { w: 1 }, function (err) {455 test.equal(null, err);456 // Set up cursor457 var cursor = collection.find().setReadPreference(ReadPreference.SECONDARY);458 cursor.each(function (err, result) {459 if (result == null) {460 client.close();461 restartAndDone(done);462 } else {463 try {464 // Try to change the read preference it should not work as the query was executed465 cursor.setReadPreference(ReadPreference.PRIMARY);466 test.ok(false);467 } catch (err) {468 test.ok(err != null);469 }470 test.equal(ReadPreference.SECONDARY, cursor.readPreference.preference);471 }472 });473 });474 });475 }476 });477 it('Set read preference at db level', {478 metadata: { requires: { topology: 'replicaset' } },479 test: function (done) {480 var configuration = this.configuration;481 var mongo = configuration.require,482 ReadPreference = mongo.ReadPreference;483 const client = configuration.newClient(484 {},485 { w: 0, debug: true, readPreference: new ReadPreference(ReadPreference.SECONDARY) }486 );487 // Connect to the db488 client.on('fullsetup', function () {489 var db = client.db(configuration.db);490 db.command({ ismaster: true }, function (err, result) {491 // Filter out the secondaries492 var hosts = result.hosts.concat(result.passives || []);493 var secondaries = filterSecondaries(hosts, result);494 client.topology.replset.once('pickedServer', function (readPreference, server) {495 test.ok(secondaries[server.name] != null);496 });497 // Grab the collection498 var collection = db.collection('read_preferences_all_levels_2');499 // Attempt to read (should fail due to the server not being a primary);500 var cursor = collection.find();501 cursor.toArray(function (err) {502 test.equal(null, err);503 // Does not get called or we don't care504 test.equal(ReadPreference.SECONDARY, cursor.readPreference.preference);505 client.close();506 restartAndDone(done);507 });508 });509 });510 // Connect to the db511 client.connect(function (err) {512 test.equal(null, err);513 });514 }515 });516 it('Set read preference at collection level using collection method', {517 metadata: { requires: { topology: 'replicaset' } },518 test: function (done) {519 var configuration = this.configuration;520 var mongo = configuration.require,521 ReadPreference = mongo.ReadPreference;522 const client = configuration.newClient({}, { w: 0, debug: true });523 // Connect to the db524 client.on('fullsetup', function (client) {525 var db = client.db(configuration.db);526 db.command({ ismaster: true }, function (err, result) {527 // Filter out the secondaries528 var secondaries = filterSecondaries(result.hosts, result);529 client.topology.replset.once('pickedServer', function (readPreference, server) {530 test.ok(secondaries[server.name] != null);531 });532 // Grab the collection533 var collection = db.collection('read_preferences_all_levels_3', {534 readPreference: new ReadPreference(ReadPreference.SECONDARY)535 });536 // Attempt to read (should fail due to the server not being a primary);537 var cursor = collection.find();538 cursor.toArray(function (err) {539 test.equal(null, err);540 // Does not get called or we don't care541 test.equal(ReadPreference.SECONDARY, cursor.readPreference.preference);542 client.close();543 restartAndDone(done);544 });545 });546 });547 // Connect to the db548 client.connect(function (err) {549 test.equal(null, err);550 });551 }552 });553 it('Ensure tag read goes only to the correct server', {554 metadata: { requires: { topology: 'replicaset' } },555 test: function (done) {556 var configuration = this.configuration;557 var mongo = configuration.require,558 ReadPreference = mongo.ReadPreference;559 // Open the database560 const client = configuration.newClient(561 {},562 {563 w: 0,564 debug: true,565 readPreference: new ReadPreference(ReadPreference.SECONDARY, { loc: 'ny' })566 }567 );568 // Trigger test once whole set is up569 client.on('fullsetup', function () {570 client.topology.replset.once('pickedServer', function (readPreference) {571 test.equal('secondary', readPreference.preference);572 test.equal('ny', readPreference.tags['loc']);573 });574 client575 .db('local')576 .collection('system.replset')577 .find()578 .toArray(function (err) {579 test.equal(null, err);580 client.close();581 restartAndDone(done);582 });583 });584 client.connect(function (err) {585 test.equal(null, err);586 });587 }588 });589 it('Ensure tag read goes only to the correct servers using nearest', {590 metadata: { requires: { topology: 'replicaset' } },591 test: function (done) {592 var configuration = this.configuration;593 var mongo = configuration.require,594 ReadPreference = mongo.ReadPreference;595 // Open the database596 const client = configuration(597 {},598 {599 w: 1,600 debug: true,601 readPreference: new ReadPreference(ReadPreference.NEAREST, { loc: 'ny' })602 }603 );604 var success = false;605 // Trigger test once whole set is up606 client.on('fullsetup', function (client) {607 client.topology.replset.once('pickedServer', function (readPreference, server) {608 test.equal('ny', server.lastIsMaster().tags.loc);609 // Mark success610 success = true;611 });612 client613 .db('local')614 .collection('system.replset')615 .find()616 .toArray(function (err) {617 test.equal(null, err);618 test.ok(success);619 client.close();620 restartAndDone(done);621 });622 });623 client.connect(function (err) {624 test.equal(null, err);625 });626 }627 });628 it('Always uses primary readPreference for findAndModify', {629 metadata: { requires: { topology: 'replicaset' } },630 test: function (done) {631 var configuration = this.configuration;632 var mongo = configuration.require,633 ReadPreference = mongo.ReadPreference;634 // Open the database635 const client = configuration.newClient(636 {},637 {638 w: 0,639 debug: true,640 readPreference: new ReadPreference(ReadPreference.SECONDARY_PREFERRED)641 }642 );643 // Trigger test once whole set is up644 client.on('fullsetup', function (client) {645 var db = client.db(configuration.db);646 db.collection('test').findAndModify({}, {}, { upsert: false }, function (err) {647 test.equal(null, err);648 client.close();649 restartAndDone(done);650 });651 });652 client.connect(function (err) {653 test.equal(null, err);654 });655 }656 });657 it('should correctly apply read preference for direct secondary connection', {658 metadata: { requires: { topology: 'replicaset' } },659 test: function (done) {660 var configuration = this.configuration;661 var mongo = configuration.require,662 Server = mongo.Server,663 ReadPreference = mongo.ReadPreference;664 // Open the database665 const client = configuration.newClient({666 w: 'majority',667 wtimeout: 10000,668 debug: true,669 readPreference: ReadPreference.NEAREST670 });671 client.on('fullsetup', function (client) {672 var db = client.db(configuration.db);673 db.collection('direct_secondary_read_test').insertMany(674 [{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }],675 configuration.writeConcernMax(),676 function (err) {677 test.equal(null, err);678 client.close();679 setTimeout(function () {680 var url = format(681 'mongodb://localhost:%s/integration_test_?readPreference=nearest',682 configuration.port + 1683 );684 // Connect using the MongoClient685 const client2 = configuration.newClient(url);686 client2.connect(url, function (err, client2) {687 test.equal(null, err);688 var db = client2.db(configuration.db);689 test.ok(client2.topology instanceof Server);690 db.collection('direct_secondary_read_test').count(function (err, n) {691 test.equal(null, err);692 test.ok(n > 0);693 client2.close();694 done();695 });696 });697 }, 1000);698 }699 );700 });701 client.connect(function (err) {702 test.equal(null, err);703 });704 }705 });706 /*707 it('should correctly list Collections on secondary', {708 metadata: { requires: { topology: 'replicaset' } },709 test: function(done) {710 var configuration = this.configuration;711 var mongo = configuration.require,712 MongoClient = mongo.MongoClient;713 // var url = format("mongodb://localhost:%s,localhost:%s,localhost:%s/integration_test_?slaveOk=true&rs_name=%s"714 // , configuration.port, configuration.port + 1, configuration.port + 1, configuration.replicasetName);715 var url = format('mongodb://localhost:%s/integration_test_?slaveOk=true', configuration.port);716 // Connect using the MongoClient717 const client = configuration.newClient(url);718 client.connect(function(err, client) {719 test.equal(null, err);720 test.ok(client != null);721 var db = client.db(configuration.db);722 db.collection('replicaset_slave_ok').insert({ testfield: 123 }, function(err) {723 test.equal(null, err);724 db.listCollections().toArray(function(err) {725 test.equal(null, err);726 client.close(done);727 });728 });729 });730 }731 });732 */...

Full Screen

Full Screen

parse.js

Source:parse.js Github

copy

Full Screen

1const util = require('./util')2let source3let parseState4let stack5let pos6let line7let column8let token9let key10let root11module.exports = function parse (text, reviver) {12 source = String(text)13 parseState = 'start'14 stack = []15 pos = 016 line = 117 column = 018 token = undefined19 key = undefined20 root = undefined21 do {22 token = lex()23 // This code is unreachable.24 // if (!parseStates[parseState]) {25 // throw invalidParseState()26 // }27 parseStates[parseState]()28 } while (token.type !== 'eof')29 if (typeof reviver === 'function') {30 return internalize({'': root}, '', reviver)31 }32 return root33}34function internalize (holder, name, reviver) {35 const value = holder[name]36 if (value != null && typeof value === 'object') {37 for (const key in value) {38 const replacement = internalize(value, key, reviver)39 if (replacement === undefined) {40 delete value[key]41 } else {42 value[key] = replacement43 }44 }45 }46 return reviver.call(holder, name, value)47}48let lexState49let buffer50let doubleQuote51let sign52let c53function lex () {54 lexState = 'default'55 buffer = ''56 doubleQuote = false57 sign = 158 for (;;) {59 c = peek()60 // This code is unreachable.61 // if (!lexStates[lexState]) {62 // throw invalidLexState(lexState)63 // }64 const token = lexStates[lexState]()65 if (token) {66 return token67 }68 }69}70function peek () {71 if (source[pos]) {72 return String.fromCodePoint(source.codePointAt(pos))73 }74}75function read () {76 const c = peek()77 if (c === '\n') {78 line++79 column = 080 } else if (c) {81 column += c.length82 } else {83 column++84 }85 if (c) {86 pos += c.length87 }88 return c89}90const lexStates = {91 default () {92 switch (c) {93 case '\t':94 case '\v':95 case '\f':96 case ' ':97 case '\u00A0':98 case '\uFEFF':99 case '\n':100 case '\r':101 case '\u2028':102 case '\u2029':103 read()104 return105 case '/':106 read()107 lexState = 'comment'108 return109 case undefined:110 read()111 return newToken('eof')112 }113 if (util.isSpaceSeparator(c)) {114 read()115 return116 }117 // This code is unreachable.118 // if (!lexStates[parseState]) {119 // throw invalidLexState(parseState)120 // }121 return lexStates[parseState]()122 },123 comment () {124 switch (c) {125 case '*':126 read()127 lexState = 'multiLineComment'128 return129 case '/':130 read()131 lexState = 'singleLineComment'132 return133 }134 throw invalidChar(read())135 },136 multiLineComment () {137 switch (c) {138 case '*':139 read()140 lexState = 'multiLineCommentAsterisk'141 return142 case undefined:143 throw invalidChar(read())144 }145 read()146 },147 multiLineCommentAsterisk () {148 switch (c) {149 case '*':150 read()151 return152 case '/':153 read()154 lexState = 'default'155 return156 case undefined:157 throw invalidChar(read())158 }159 read()160 lexState = 'multiLineComment'161 },162 singleLineComment () {163 switch (c) {164 case '\n':165 case '\r':166 case '\u2028':167 case '\u2029':168 read()169 lexState = 'default'170 return171 case undefined:172 read()173 return newToken('eof')174 }175 read()176 },177 value () {178 switch (c) {179 case '{':180 case '[':181 return newToken('punctuator', read())182 case 'n':183 read()184 literal('ull')185 return newToken('null', null)186 case 't':187 read()188 literal('rue')189 return newToken('boolean', true)190 case 'f':191 read()192 literal('alse')193 return newToken('boolean', false)194 case '-':195 case '+':196 if (read() === '-') {197 sign = -1198 }199 lexState = 'sign'200 return201 case '.':202 buffer = read()203 lexState = 'decimalPointLeading'204 return205 case '0':206 buffer = read()207 lexState = 'zero'208 return209 case '1':210 case '2':211 case '3':212 case '4':213 case '5':214 case '6':215 case '7':216 case '8':217 case '9':218 buffer = read()219 lexState = 'decimalInteger'220 return221 case 'I':222 read()223 literal('nfinity')224 return newToken('numeric', Infinity)225 case 'N':226 read()227 literal('aN')228 return newToken('numeric', NaN)229 case '"':230 case "'":231 doubleQuote = (read() === '"')232 buffer = ''233 lexState = 'string'234 return235 }236 throw invalidChar(read())237 },238 identifierNameStartEscape () {239 if (c !== 'u') {240 throw invalidChar(read())241 }242 read()243 const u = unicodeEscape()244 switch (u) {245 case '$':246 case '_':247 break248 default:249 if (!util.isIdStartChar(u)) {250 throw invalidIdentifier()251 }252 break253 }254 buffer += u255 lexState = 'identifierName'256 },257 identifierName () {258 switch (c) {259 case '$':260 case '_':261 case '\u200C':262 case '\u200D':263 buffer += read()264 return265 case '\\':266 read()267 lexState = 'identifierNameEscape'268 return269 }270 if (util.isIdContinueChar(c)) {271 buffer += read()272 return273 }274 return newToken('identifier', buffer)275 },276 identifierNameEscape () {277 if (c !== 'u') {278 throw invalidChar(read())279 }280 read()281 const u = unicodeEscape()282 switch (u) {283 case '$':284 case '_':285 case '\u200C':286 case '\u200D':287 break288 default:289 if (!util.isIdContinueChar(u)) {290 throw invalidIdentifier()291 }292 break293 }294 buffer += u295 lexState = 'identifierName'296 },297 sign () {298 switch (c) {299 case '.':300 buffer = read()301 lexState = 'decimalPointLeading'302 return303 case '0':304 buffer = read()305 lexState = 'zero'306 return307 case '1':308 case '2':309 case '3':310 case '4':311 case '5':312 case '6':313 case '7':314 case '8':315 case '9':316 buffer = read()317 lexState = 'decimalInteger'318 return319 case 'I':320 read()321 literal('nfinity')322 return newToken('numeric', sign * Infinity)323 case 'N':324 read()325 literal('aN')326 return newToken('numeric', NaN)327 }328 throw invalidChar(read())329 },330 zero () {331 switch (c) {332 case '.':333 buffer += read()334 lexState = 'decimalPoint'335 return336 case 'e':337 case 'E':338 buffer += read()339 lexState = 'decimalExponent'340 return341 case 'x':342 case 'X':343 buffer += read()344 lexState = 'hexadecimal'345 return346 }347 return newToken('numeric', sign * 0)348 },349 decimalInteger () {350 switch (c) {351 case '.':352 buffer += read()353 lexState = 'decimalPoint'354 return355 case 'e':356 case 'E':357 buffer += read()358 lexState = 'decimalExponent'359 return360 }361 if (util.isDigit(c)) {362 buffer += read()363 return364 }365 return newToken('numeric', sign * Number(buffer))366 },367 decimalPointLeading () {368 if (util.isDigit(c)) {369 buffer += read()370 lexState = 'decimalFraction'371 return372 }373 throw invalidChar(read())374 },375 decimalPoint () {376 switch (c) {377 case 'e':378 case 'E':379 buffer += read()380 lexState = 'decimalExponent'381 return382 }383 if (util.isDigit(c)) {384 buffer += read()385 lexState = 'decimalFraction'386 return387 }388 return newToken('numeric', sign * Number(buffer))389 },390 decimalFraction () {391 switch (c) {392 case 'e':393 case 'E':394 buffer += read()395 lexState = 'decimalExponent'396 return397 }398 if (util.isDigit(c)) {399 buffer += read()400 return401 }402 return newToken('numeric', sign * Number(buffer))403 },404 decimalExponent () {405 switch (c) {406 case '+':407 case '-':408 buffer += read()409 lexState = 'decimalExponentSign'410 return411 }412 if (util.isDigit(c)) {413 buffer += read()414 lexState = 'decimalExponentInteger'415 return416 }417 throw invalidChar(read())418 },419 decimalExponentSign () {420 if (util.isDigit(c)) {421 buffer += read()422 lexState = 'decimalExponentInteger'423 return424 }425 throw invalidChar(read())426 },427 decimalExponentInteger () {428 if (util.isDigit(c)) {429 buffer += read()430 return431 }432 return newToken('numeric', sign * Number(buffer))433 },434 hexadecimal () {435 if (util.isHexDigit(c)) {436 buffer += read()437 lexState = 'hexadecimalInteger'438 return439 }440 throw invalidChar(read())441 },442 hexadecimalInteger () {443 if (util.isHexDigit(c)) {444 buffer += read()445 return446 }447 return newToken('numeric', sign * Number(buffer))448 },449 string () {450 switch (c) {451 case '\\':452