<commit_before>import { PropTypes } from 'react';
import { requireNativeComponent, View } from 'react-native';

var svgFace = {
    name: 'SVGView',
    propTypes: {
        width: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        height: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        ...View.propTypes // include the default view properties
    },
    };

var shapeFace = {
    name: 'ShapeView',
    propTypes: {
        stroke: PropTypes.string,
        strokeWidth: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        strokeOpacity: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        //strokeLinecap: PropTypes.oneOf(['butt', 'square' , 'round']),
        //strokeLinejoin: PropTypes.oneOf(['miter', 'bevel', 'round']),
        strokeLinecap: PropTypes.string,
        strokeLinejoin: PropTypes.string,
        strokeDasharray: PropTypes.array,
        strokeMiterlimit: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        strokeDashoffset: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        fill: PropTypes.string,
        fillOpacity: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        origin: PropTypes.string,
        originX: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        originY: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        scale: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        rotate: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        opacity: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        x: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        y: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
    },
}

var rectFace = {
    name: 'RectView',
    propTypes: {
        rx: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        ry: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        width: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        height: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var lineFace = {
    name: 'LineView',
    propTypes: {
        x1: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        y1: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        x2: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        y2: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var circleFace = {
    name: 'CircleView',
    propTypes: {
        cx: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        cy: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        r: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var ellipseFace = {
    name: 'EllipseView',
    propTypes: {
        cx: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        cy: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        rx: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        ry: PropTypes.oneOfType(PropTypes.number,PropTypes.string),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var pathFace = {
    name: 'PathView',
    propTypes: {
        d: PropTypes.string,
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var polylineFace = {
    name: 'PolylineView',
    propTypes: {
        points: PropTypes.string,
        fillRule: PropTypes.oneOf(['evenodd', 'nonzero']),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    }
}

var polygonFace = {
    name: 'PolygonView',
    propTypes: {
        points: PropTypes.string,
        fillRule: PropTypes.oneOf(['evenodd', 'nonzero']),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    }
}

var groupFace = {
    name: 'GroupView',
    propTypes: {
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    }
}

export const Svg = requireNativeComponent('RCTSVGView', rectFace);
export const Rect = requireNativeComponent('RCTRectView', rectFace);
export const Line = requireNativeComponent('RCTLineView', lineFace);
export const Circle = requireNativeComponent('RCTCircleView', circleFace);
export const Ellipse = requireNativeComponent('RCTEllipseView', ellipseFace);
export const Polyline = requireNativeComponent('RCTPolylineView', polylineFace);
export const Polygon = requireNativeComponent('RCTPolygonView', polygonFace);
export const Path = requireNativeComponent('RCTPathView', pathFace);
export const G = requireNativeComponent('RCTGroupView', groupFace);<commit_msg>Svg export change and oneOfType warning removed<commit_after>import { PropTypes } from 'react';
import { requireNativeComponent, View } from 'react-native';

var svgFace = {
    name: 'SVGView',
    propTypes: {
        width: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        height: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        ...View.propTypes // include the default view properties
    },
    };

var shapeFace = {
    name: 'ShapeView',
    propTypes: {
        stroke: PropTypes.string,
        strokeWidth: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        strokeOpacity: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        //strokeLinecap: PropTypes.oneOf(['butt', 'square' , 'round']),
        //strokeLinejoin: PropTypes.oneOf(['miter', 'bevel', 'round']),
        strokeLinecap: PropTypes.string,
        strokeLinejoin: PropTypes.string,
        strokeDasharray: PropTypes.array,
        strokeMiterlimit: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        strokeDashoffset: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        fill: PropTypes.string,
        fillOpacity: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        origin: PropTypes.string,
        originX: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        originY: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        scale: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        rotate: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        opacity: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        x: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        y: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
    },
}

var rectFace = {
    name: 'RectView',
    propTypes: {
        rx: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        ry: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        width: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        height: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var lineFace = {
    name: 'LineView',
    propTypes: {
        x1: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        y1: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        x2: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        y2: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var circleFace = {
    name: 'CircleView',
    propTypes: {
        cx: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        cy: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        r: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var ellipseFace = {
    name: 'EllipseView',
    propTypes: {
        cx: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        cy: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        rx: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        ry: PropTypes.oneOfType([PropTypes.number,PropTypes.string]),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var pathFace = {
    name: 'PathView',
    propTypes: {
        d: PropTypes.string,
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    },
}

var polylineFace = {
    name: 'PolylineView',
    propTypes: {
        points: PropTypes.string,
        fillRule: PropTypes.oneOf(['evenodd', 'nonzero']),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    }
}

var polygonFace = {
    name: 'PolygonView',
    propTypes: {
        points: PropTypes.string,
        fillRule: PropTypes.oneOf(['evenodd', 'nonzero']),
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    }
}

var groupFace = {
    name: 'GroupView',
    propTypes: {
        ...shapeFace.propTypes,
        ...View.propTypes // include the default view properties
    }
}

const Svg = requireNativeComponent('RCTSVGView', rectFace);
const Rect = requireNativeComponent('RCTRectView', rectFace);
const Line = requireNativeComponent('RCTLineView', lineFace);
const Circle = requireNativeComponent('RCTCircleView', circleFace);
const Ellipse = requireNativeComponent('RCTEllipseView', ellipseFace);
const Polyline = requireNativeComponent('RCTPolylineView', polylineFace);
const Polygon = requireNativeComponent('RCTPolygonView', polygonFace);
const Path = requireNativeComponent('RCTPathView', pathFace);
const G = requireNativeComponent('RCTGroupView', groupFace);

export {
    Svg,
    Rect,
    Line,
    Circle,
    Ellipse,
    Polyline,
    Polygon,
    Path,
    G
}

export default Svg<|endoftext|>


<commit_before>var container, stats;
var camera, controls, scene, renderer;
var meshes = [];

init();
animate();

function applyVertexColors(g, c) {

    g.faces.forEach(function(f) {

        var n = (f instanceof THREE.Face3) ? 3 : 4;

        for (var j = 0; j < n; j++) {

            f.vertexColors[j] = c;

        }

    });

}

function init_container() {
    container = document.getElementById("container");
}

function init_renderer() {
    renderer = new THREE.WebGLRenderer({
        antialias: true
    });
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(window.innerWidth, window.innerHeight);
    container.appendChild(renderer.domElement);
}

function init_stats() {
    stats = new Stats();
    container.appendChild(stats.dom);
}

function init_scene() {
    scene = new THREE.Scene();
    scene.background = new THREE.Color(0x000000);
}

function init_camera() {
    camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.set(0, 6, 1000);
    camera.lookAt(scene.position);
}

function init_lighting() {
    scene.add(new THREE.AmbientLight(0x555555));
    var light = new THREE.SpotLight(0xffffff, 1.5);
    light.position.set(0, 500, 2000);
    scene.add(light);
}

function hashCode (str){
    var hash = 0;
    if (str.length == 0) return hash;
    for (i = 0; i < str.length; i++) {
        char = str.charCodeAt(i);
        hash = ((hash<<5 + 1)-hash)+char;
        hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
}

var kGridSize = 200;  // mm
var kMaxRobotVelociy = 3000;  // mm/s
var kGridProgressionTime = kGridSize / kMaxRobotVelociy;  // s
var kTimeScale = 1000;  // s => millis

function readTextFile() {
    document.getElementById('file').addEventListener('change', readFile, false);

    function readFile (evt) {
        var files = evt.target.files;
        var file = files[0];
        var reader = new FileReader();
        reader.onload = function(event) {
            var path_coords = [];
            for (l of event.target.result.split('{')) {
                var xy_line = l.split('}')[0].trim();
                var x_and_y = xy_line.split('\n').map(function(x) { return (x.split(':')[1]); }).map(function(x) { return parseInt(x); });
                if (!isNaN(x_and_y[0]) && !isNaN(x_and_y[1])) {
                    path_coords.push(x_and_y);
                }
            }

            var initial_mesh_scales = meshes.map(function(m) { return [m.scale.x, m.scale.y, m.scale.z]; });
            meshes.forEach(function(m) { m.scale.x = 1; m.scale.y = 1; m.scale.z = 1; });

            var cylinder_height = kGridProgressionTime * kTimeScale;

            function make_cylinder(dx, dy) {
                if (dy!= 0 && dx != 0) {
                    return new THREE.CylinderGeometry(90, 90, cylinder_height * 1.414213562, 20);
                } else {
                    return new THREE.CylinderGeometry(90, 90, cylinder_height, 20);
                }
            }

            var cylinder = make_cylinder(0, 0);
            var cylinder_geometry = new THREE.Geometry();
            var cylinder_material = new THREE.MeshPhongMaterial({
                color: 0xffffff,
                flatShading: true,
                vertexColors: THREE.VertexColors,
                shininess: 0
            });

            var matrix = new THREE.Matrix4();
            var quaternion = new THREE.Quaternion();
            var color = new THREE.Color();
            var random_color = hashCode(file.name.toString()) * 0xffffff;

            var time = 0;

            for (var i = 0; i < path_coords.length - 1; ++i) {
                var bottom_pair = path_coords[i];
                var top_pair = path_coords[i + 1];

                var center_x = (top_pair[0] + bottom_pair[0]) / 2;
                var center_y = (top_pair[1] + bottom_pair[1]) / 2;
                var delta_x = (top_pair[0] - bottom_pair[0]);  // mm
                var delta_y = (top_pair[1] - bottom_pair[1]);  // mm
                var delta_x_time = delta_x / kMaxRobotVelociy * kTimeScale;  // millis
                var delta_y_time = delta_y / kMaxRobotVelociy * kTimeScale;  // millis

                cylinder = make_cylinder(delta_x, delta_y);

                var time_delta = Math.sqrt(Math.pow(delta_x_time, 2) + Math.pow(delta_y_time, 2));
                time += time_delta;

                var position = new THREE.Vector3(center_x,
                                                 time - (time_delta / 2),
                                                 center_y);
                var rotation = new THREE.Euler(0, 0, 0, "XYZ");
                var scale = new THREE.Vector3(1, 1, 1);

                quaternion.setFromEuler(rotation, false);
                matrix.compose(position, quaternion, scale);

                function make_shear(dx, dy) {
                    var shear_x = dx / cylinder_height;
                    var shear_y = dy / cylinder_height;
                    if (dx != 0 && dy != 0) {
                        shear_x *= 1 / 1.414213562;
                        shear_y *= 1 / 1.414213562;
                    }

                    var Syx = shear_x,
                        Szx = 0,
                        Sxy = 0,
                        Szy = 0,
                        Sxz = 0,
                        Syz = shear_y;

                    var shear = new THREE.Matrix4();

                    shear.set(1, Syx, Szx, 0,
                              Sxy, 1, Szy, 0,
                              Sxz, Syz, 1, 0,
                              0, 0, 0, 1);

                    return shear;
                }

                matrix.multiply(make_shear(delta_x, delta_y));

                // give the cylinder's vertices a random color, to be displayed

                applyVertexColors(cylinder, color.setHex(random_color));

                cylinder_geometry.merge(cylinder, matrix);
            }

            var cylinder_mesh = new THREE.Mesh(cylinder_geometry, cylinder_material);
            scene.add(cylinder_mesh);
            meshes.push(cylinder_mesh);

            for (var i = 0; i < meshes.length; ++i) {
                meshes[i].scale.x = initial_mesh_scales[0][0];
                meshes[i].scale.y = initial_mesh_scales[0][1];
                meshes[i].scale.z = initial_mesh_scales[0][2];
            }

        };

        reader.readAsText(file);
    }
}

function init() {
    init_container();
    init_renderer();
    init_stats();
    init_scene();
    init_camera();
    init_lighting();

    readTextFile();

    var matrix = new THREE.Matrix4();
    var quaternion = new THREE.Quaternion();

    var wireframe_box = new THREE.PlaneGeometry(6000, 9000);
    var wireframe_geometry = new THREE.Geometry();
    var wireframe_material = new THREE.MeshBasicMaterial({
        color: 0x006400,
        wireframe: false,
        side: THREE.DoubleSide
    });

    quaternion.setFromEuler(new THREE.Euler(1.57, 0, 1.57, "XYZ"), false);
    matrix.compose(new THREE.Vector3(), quaternion, new THREE.Vector3(1, 1, 1));
    wireframe_geometry.merge(wireframe_box, matrix);

    meshes.push(new THREE.Mesh(wireframe_geometry, wireframe_material));

    for (m of meshes) {
        scene.add(m);
    }

    renderer.domElement.addEventListener('mousemove', onMouseMove);
    renderer.domElement.addEventListener('wheel', onMouseScroll);
    document.addEventListener("keydown", onDocumentKeyDown, false);

}

function onMouseMove(e) {
    var mouse_x = e.clientX;
    var mouse_y = e.clientY;
    var rotation_amount = 0.003;
    for (m of meshes) {
        m.rotation.x = mouse_y * rotation_amount;
        m.rotation.y = mouse_x * rotation_amount;
    }
    renderer.render(scene, camera);

}

function onMouseScroll(e) {

    var e = window.event || e;
    var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail || -e.deltaY)));
    var scale_amount = 0.1;
    for (m of meshes) {
        m.scale.x *= (1 + scale_amount * delta);
        m.scale.y *= (1 + scale_amount * delta);
        m.scale.z *= (1 + scale_amount * delta);
    }
};

function onDocumentKeyDown(e) {};

function animate() {

    requestAnimationFrame(animate);

    render();
    stats.update();

}

function render() {

    renderer.render(scene, camera);

}
<commit_msg>Added swap of y coord to match the layout that one would expect for robocup.<commit_after>var container, stats;
var camera, controls, scene, renderer;
var meshes = [];

init();
animate();

function applyVertexColors(g, c) {

    g.faces.forEach(function(f) {

        var n = (f instanceof THREE.Face3) ? 3 : 4;

        for (var j = 0; j < n; j++) {

            f.vertexColors[j] = c;

        }

    });

}

function init_container() {
    container = document.getElementById("container");
}

function init_renderer() {
    renderer = new THREE.WebGLRenderer({
        antialias: true
    });
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(window.innerWidth, window.innerHeight);
    container.appendChild(renderer.domElement);
}

function init_stats() {
    stats = new Stats();
    container.appendChild(stats.dom);
}

function init_scene() {
    scene = new THREE.Scene();
    scene.background = new THREE.Color(0x000000);
}

function init_camera() {
    camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.set(0, 6, 1000);
    camera.lookAt(scene.position);
}

function init_lighting() {
    scene.add(new THREE.AmbientLight(0x555555));
    var light = new THREE.SpotLight(0xffffff, 1.5);
    light.position.set(0, 500, 2000);
    scene.add(light);
}

function hashCode (str){
    var hash = 0;
    if (str.length == 0) return hash;
    for (i = 0; i < str.length; i++) {
        char = str.charCodeAt(i);
        hash = ((hash<<5 + 1)-hash)+char;
        hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
}

var kGridSize = 200;  // mm
var kMaxRobotVelociy = 3000;  // mm/s
var kGridProgressionTime = kGridSize / kMaxRobotVelociy;  // s
var kTimeScale = 1000;  // s => millis

function readTextFile() {
    document.getElementById('file').addEventListener('change', readFile, false);

    function readFile (evt) {
        var files = evt.target.files;
        var file = files[0];
        var reader = new FileReader();
        reader.onload = function(event) {
            var path_coords = [];
            for (l of event.target.result.split('{')) {
                var xy_line = l.split('}')[0].trim();
                var x_and_y = xy_line.split('\n').map(function(x) { return (x.split(':')[1]); }).map(function(x) { return parseInt(x); });
                if (!isNaN(x_and_y[0]) && !isNaN(x_and_y[1])) {
                    var swapped_x_and_y = x_and_y;
                    swapped_x_and_y[1] *= -1;
                    path_coords.push(swapped_x_and_y);
                }
            }

            var initial_mesh_scales = meshes.map(function(m) { return [m.scale.x, m.scale.y, m.scale.z]; });
            meshes.forEach(function(m) { m.scale.x = 1; m.scale.y = 1; m.scale.z = 1; });

            var cylinder_height = kGridProgressionTime * kTimeScale;

            function make_cylinder(dx, dy) {
                if (dy!= 0 && dx != 0) {
                    return new THREE.CylinderGeometry(90, 90, cylinder_height * 1.414213562, 20);
                } else {
                    return new THREE.CylinderGeometry(90, 90, cylinder_height, 20);
                }
            }

            var cylinder = make_cylinder(0, 0);
            var cylinder_geometry = new THREE.Geometry();
            var cylinder_material = new THREE.MeshPhongMaterial({
                color: 0xffffff,
                flatShading: true,
                vertexColors: THREE.VertexColors,
                shininess: 0
            });

            var matrix = new THREE.Matrix4();
            var quaternion = new THREE.Quaternion();
            var color = new THREE.Color();
            var random_color = hashCode(file.name.toString()) * 0xffffff;

            var time = 0;

            for (var i = 0; i < path_coords.length - 1; ++i) {
                var bottom_pair = path_coords[i];
                var top_pair = path_coords[i + 1];

                var center_x = (top_pair[0] + bottom_pair[0]) / 2;
                var center_y = (top_pair[1] + bottom_pair[1]) / 2;
                var delta_x = (top_pair[0] - bottom_pair[0]);  // mm
                var delta_y = (top_pair[1] - bottom_pair[1]);  // mm
                var delta_x_time = delta_x / kMaxRobotVelociy * kTimeScale;  // millis
                var delta_y_time = delta_y / kMaxRobotVelociy * kTimeScale;  // millis

                cylinder = make_cylinder(delta_x, delta_y);

                var time_delta = Math.sqrt(Math.pow(delta_x_time, 2) + Math.pow(delta_y_time, 2));
                time += time_delta;

                var position = new THREE.Vector3(center_x,
                                                 time - (time_delta / 2),
                                                 center_y);
                var rotation = new THREE.Euler(0, 0, 0, "XYZ");
                var scale = new THREE.Vector3(1, 1, 1);

                quaternion.setFromEuler(rotation, false);
                matrix.compose(position, quaternion, scale);

                function make_shear(dx, dy) {
                    var shear_x = dx / cylinder_height;
                    var shear_y = dy / cylinder_height;
                    if (dx != 0 && dy != 0) {
                        shear_x *= 1 / 1.414213562;
                        shear_y *= 1 / 1.414213562;
                    }

                    var Syx = shear_x,
                        Szx = 0,
                        Sxy = 0,
                        Szy = 0,
                        Sxz = 0,
                        Syz = shear_y;

                    var shear = new THREE.Matrix4();

                    shear.set(1, Syx, Szx, 0,
                              Sxy, 1, Szy, 0,
                              Sxz, Syz, 1, 0,
                              0, 0, 0, 1);

                    return shear;
                }

                matrix.multiply(make_shear(delta_x, delta_y));

                // give the cylinder's vertices a random color, to be displayed

                applyVertexColors(cylinder, color.setHex(random_color));

                cylinder_geometry.merge(cylinder, matrix);
            }

            var cylinder_mesh = new THREE.Mesh(cylinder_geometry, cylinder_material);
            scene.add(cylinder_mesh);
            meshes.push(cylinder_mesh);

            for (var i = 0; i < meshes.length; ++i) {
                meshes[i].scale.x = initial_mesh_scales[0][0];
                meshes[i].scale.y = initial_mesh_scales[0][1];
                meshes[i].scale.z = initial_mesh_scales[0][2];
            }

        };

        reader.readAsText(file);
    }
}

function init() {
    init_container();
    init_renderer();
    init_stats();
    init_scene();
    init_camera();
    init_lighting();

    readTextFile();

    var matrix = new THREE.Matrix4();
    var quaternion = new THREE.Quaternion();

    var wireframe_box = new THREE.PlaneGeometry(6000, 9000);
    var wireframe_geometry = new THREE.Geometry();
    var wireframe_material = new THREE.MeshBasicMaterial({
        color: 0x006400,
        wireframe: false,
        side: THREE.DoubleSide
    });

    quaternion.setFromEuler(new THREE.Euler(1.57, 0, 1.57, "XYZ"), false);
    matrix.compose(new THREE.Vector3(), quaternion, new THREE.Vector3(1, 1, 1));
    wireframe_geometry.merge(wireframe_box, matrix);

    meshes.push(new THREE.Mesh(wireframe_geometry, wireframe_material));

    for (m of meshes) {
        scene.add(m);
    }

    renderer.domElement.addEventListener('mousemove', onMouseMove);
    renderer.domElement.addEventListener('wheel', onMouseScroll);
    document.addEventListener("keydown", onDocumentKeyDown, false);

}

function onMouseMove(e) {
    var mouse_x = e.clientX;
    var mouse_y = e.clientY;
    var rotation_amount = 0.003;
    for (m of meshes) {
        m.rotation.x = mouse_y * rotation_amount;
        m.rotation.y = mouse_x * rotation_amount;
    }
    renderer.render(scene, camera);

}

function onMouseScroll(e) {

    var e = window.event || e;
    var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail || -e.deltaY)));
    var scale_amount = 0.1;
    for (m of meshes) {
        m.scale.x *= (1 + scale_amount * delta);
        m.scale.y *= (1 + scale_amount * delta);
        m.scale.z *= (1 + scale_amount * delta);
    }
};

function onDocumentKeyDown(e) {};

function animate() {

    requestAnimationFrame(animate);

    render();
    stats.update();

}

function render() {

    renderer.render(scene, camera);

}
<|endoftext|>


<commit_before>/**
 * Created by kuroky360 on 16-1-25.
 */
!function(window,document,undefined){
    // initial variable
    var angular=window.angular||{},
        toString=Object.prototype.toString;
    // shadow & deep
    function copy(){

    }
    // shadow & deep
    function extend(){

    }

    ////////////////////////////////////
    // Error handler todo
    ////////////////////////////////////

    ////////////////////////////////////
    // Event handler todo
    ////////////////////////////////////

    ////////////////////////////////////
    // Http $q promise todo
    ////////////////////////////////////

    ////////////////////////////////////
    // dom selectors fn todo
    ////////////////////////////////////

    ////////////////////////////////////
    // fn utils
    ////////////////////////////////////
    function isFunciton(value){return typeof value ==='function';}

    function noop(){}

    function isUndefined(value){return typeof value ==='undefined';}

    function isDefined(value){return typeof value !=='undefined';}

    function isString(value){return typeof value==='string';}

    function isObject(value){return value!==null&&typeof value==='object'}

    function isNumber(value){return typeof value === 'number'}

    function isDate(value){ toString.call(value)==='[object Date]'}

    function lowercase(value){return isString(value)?value.toLowerCase():value}

    function uppercase(value){return isString(value)?value.toUpperCase():value}

    function fromJson(value){
        return isString(value)?JSON.parse(value):value;
    }

    function identity($){return $;}

    function toJson(value){
    }

    function valueFn(value){
        return function(){
            return value;
        }
    }

    function toInt(value){
        return parseInt(value,10);
    }

    function isArray(value){ return Array.isArray(value);}

    //reverse params
    function reverseParams(iteratorFn){
        return function(value,key){
            iteratorFn(key,value);
        };
    }

    // module loader setup
    function setupModuleLoader(window) {

        function ensure(obj, child, factory) {
            return obj[child] || (obj[child] = factory());
        }

        var angular = ensure(window, angular, Object);

        return ensure(angular, 'module', function () {
            var modules = {};

            return function module(name, require, config) {
                if (require && modules.hasOwnProperty(name)) {
                    modules[name] = null;
                }
                return ensure(modules, name, function () {
                    var invokeQueue=[];
                    var configBlocks=[];
                    var runBlocks=[];
                    var moduleInstance={
                        _invokeQueue:invokeQueue,
                        _configBlock:configBlocks,
                        _runBlocks:runBlocks,
                        _require:require,
                        _name:name
                    };

                    function invokeLater(provider,method,insertMethod,queue){
                        if(!queue) queue=invokeQueue;
                        return function(){
                            queue[insertMethod||'push']([provider,method,arguments]);
                            return moduleInstance;
                        }
                    }

                    function invokeLaterAndSetModuleName(provider,method){
                        if(isFunciton(method)) method.$$moduleName=name;
                        return function(recipeName,factoryName){
                            invokeQueue.push([provider,method,arguments]);
                            return moduleInstance;
                        };
                    }
                });
            };
        });
    }

    //bootstrap fn
    function bootstrap(element,modules,config){
        var modules=modules||[],
            instaneInjector;

        modules.unshift('ng');
        modules.push(['$provide',function($provide){
            $provide.value('$rootElement',element);
        }]);

        instaneInjector = createInjector(modules);
    }

    // annotate fn
    function annotate(fn){
        var $injectArray=[];
        return $injectArray;
    }

    //injector creator
    function createInjector(){
        var providerSufix='Provider',
            INSTANTING={},
            path=[],
            providerCache={
                $provide:{
                    provider:supportObject(provider),
                    factory:supportObject(factory),
                    service:supportObject(service),
                    value:supportObject(value)
                }
            },
            providerInjector=(providerCache.$injector=createInternalInjector(providerCache,function(seviceName,caller){
                throw new Error('can not found provider!');
            })),
            instanceCache={},
            instanceInjector=(instanceCache.$injector=createInternalInjector(instanceCache,function(serviceName,caller){
                var provider = providerInjector.get(serviceName+providerSufix,caller);
                instanceCache.invoke(provider.$get,provider,undefined,serviceName);
            }));

        //support object arg
        function supportObject(delegate){
            return function(key,value){
                if(isObject(key)){
                    /*forEach(name,function(value,index){
                        fn(index,value);
                    })*/
                }else{
                    return delegate(key,value);
                }
            }
        }
        //provider
        function provider(name,provider_){
            if(isFunciton(provider_)||isArray(provider_)){
                provider_ = providerInjector.instantiate(provider_);
            }
            if(!provider_.$get){
                throw new Error('do not have $get method!');
            }
            return  providerCache[name+providerSufix]=provider_;
        }

        function enForceReturnValue(factoryFn){
            return function(){
                var result=instanceCache.invoke(factoryFn);
                return result;
            };
        }

        //facotry
        function factory(name,factoryFn,enForce){
            return provider(name,{
                $get:enForce===false?enForceReturnValue(factoryFn):factoryFn
            });
        }

        //service
        function service(name,contructor){
            return factory(name,['$injector',function($injector){
                return $injector.instantiate(contructor);
            }]);
        }

        //value
        function value(name,value){
            return factory(name,valueFn(value),false);
        }

        ////////////////////////////////////
        // internal injector
        ////////////////////////////////////
        function createInternalInjector(cache,factory){

            // get service
            function getService(serviceName,caller){
                if(cache.hasOwnProperty(serviceName)){
                    if(cache[serviceName]===INSTANTING){
                        throw new Error('重复循环依赖！');
                    }
                    return cache[serviceName];
                }else{
                    cache[serviceName]=INSTANTING;
                    //path.push(serviceName);
                    return  cache[serviceName]=factory(serviceName,caller);
                }
            }

            //invoke fn
            function invoke(fn,self,locals,serviceName){
                var length,
                    args=[],
                    i,
                    item,
                    annotateArray=annotate(fn);
                for(i=0,length=annotateArray.length;i<length;i++){
                    item=annotateArray[i];
                    args.push(locals&&locals.hasOwnProperty(item)?locals[item]:getService(item,serviceName));
                }

                if(isArray(fn)){
                    fn=fn[fn.length-1];
                }

                return fn.call(self,args);
            }

            // intantiate instace
            function instantiate(type,locals,serviceName){
                var instance = Object.create((isArray(type)? type[type.length-1]:type).prototype||null);
                var returnValue = invoke(type,instance,locals,serviceName);

                return isObject(returnValue)|| isFunciton(returnValue)?returnValue:instance;
            }

            return {
                instantiate:instantiate,
                invoke:invoke,
                get:getService
            };
        }
    }

}(window,document);

<commit_msg>add common fns<commit_after>/**
 * Created by kuroky360 on 16-1-25.
 */
!function(window,document,undefined){
    // initial variable
    var angular=window.angular||{},
        toString=Object.prototype.toString,
        slice=[].slice,
        splice=[].splice,
        jqlite,
        getPrototypeOf=Object.getPrototypeOf;
    // shadow & deep
    function copy(){

    }
    // shadow & deep
    function extend(){

    }

    ////////////////////////////////////
    // Error handler todo
    ////////////////////////////////////

    ////////////////////////////////////
    // Event handler todo
    ////////////////////////////////////

    ////////////////////////////////////
    // Http $q promise todo
    ////////////////////////////////////

    ////////////////////////////////////
    // dom selectors fn todo
    ////////////////////////////////////

    function jqlite(){
        this.length=0;
    }

    jqlite.prototype={
      //todo
    };
    ////////////////////////////////////
    // fn utils
    ////////////////////////////////////
    function isFunciton(value){return typeof value ==='function';}

    function noop(){}

    function isUndefined(value){return typeof value ==='undefined';}

    function isDefined(value){return typeof value !=='undefined';}

    function isString(value){return typeof value==='string';}

    function isObject(value){return value!==null&&typeof value==='object'}

    function isNumber(value){return typeof value === 'number'}

    function isDate(value){ toString.call(value)==='[object Date]'}

    function lowercase(value){return isString(value)?value.toLowerCase():value}

    function uppercase(value){return isString(value)?value.toUpperCase():value}

    function fromJson(value){
        return isString(value)?JSON.parse(value):value;
    }

    function identity($){return $;}

    function toJson(value){
    }

    function valueFn(value){
        return function(){
            return value;
        }
    }

    function toInt(value){
        return parseInt(value,10);
    }

    function isArray(value){ return Array.isArray(value);}

    //reverse params
    function reverseParams(iteratorFn){
        return function(value,key){
            iteratorFn(key,value);
        };
    }

    // check blankObject -->with a null prototype
    function isBlankObject(value){
        return value!==null&&typeof value==='object'&& !getPrototypeOf(value);
    }

    // check window
    function isWindow(obj){
        return obj&&obj.window===obj;
    }

    // is ArrayLike
    function isArrayLike(obj){
        if(obj===null||isWindow(obj)) return false;
        if(isArray(obj)||isString(obj)||jqlite&&obj instanceof jqlite) return true;
        //var length = obj
    }

    // Creates a new object without a prototype.
    function createMap(){
        return Object.create(null);
    }

    // module loader setup
    function setupModuleLoader(window) {

        function ensure(obj, child, factory) {
            return obj[child] || (obj[child] = factory());
        }

        var angular = ensure(window, angular, Object);

        return ensure(angular, 'module', function () {
            var modules = {};

            return function module(name, require, config) {
                if (require && modules.hasOwnProperty(name)) {
                    modules[name] = null;
                }
                return ensure(modules, name, function () {
                    var invokeQueue=[];
                    var configBlocks=[];
                    var runBlocks=[];
                    var moduleInstance={
                        _invokeQueue:invokeQueue,
                        _configBlock:configBlocks,
                        _runBlocks:runBlocks,
                        _require:require,
                        _name:name
                    };

                    function invokeLater(provider,method,insertMethod,queue){
                        if(!queue) queue=invokeQueue;
                        return function(){
                            queue[insertMethod||'push']([provider,method,arguments]);
                            return moduleInstance;
                        }
                    }

                    function invokeLaterAndSetModuleName(provider,method){
                        if(isFunciton(method)) method.$$moduleName=name;
                        return function(recipeName,factoryName){
                            invokeQueue.push([provider,method,arguments]);
                            return moduleInstance;
                        };
                    }
                });
            };
        });
    }

    //bootstrap fn
    function bootstrap(element,modules,config){
        var modules=modules||[],
            instaneInjector;

        modules.unshift('ng');
        modules.push(['$provide',function($provide){
            $provide.value('$rootElement',element);
        }]);

        instaneInjector = createInjector(modules);
    }

    // annotate fn
    function annotate(fn){
        var $injectArray=[];
        return $injectArray;
    }

    //injector creator
    function createInjector(modulesToLoad){
        var providerSufix='Provider',
            INSTANTING={},
            path=[],
            providerCache={
                $provide:{
                    provider:supportObject(provider),
                    factory:supportObject(factory),
                    service:supportObject(service),
                    value:supportObject(value)
                }
            },
            providerInjector=(providerCache.$injector=createInternalInjector(providerCache,function(seviceName,caller){
                throw new Error('can not found provider!');
            })),
            instanceCache={},
            instanceInjector=(instanceCache.$injector=createInternalInjector(instanceCache,function(serviceName,caller){
                var provider = providerInjector.get(serviceName+providerSufix,caller);
                instanceCache.invoke(provider.$get,provider,undefined,serviceName);
            }));
        //forEach load modules

        //support object arg
        function supportObject(delegate){
            return function(key,value){
                if(isObject(key)){
                    /*forEach(name,function(value,index){
                        fn(index,value);
                    })*/
                }else{
                    return delegate(key,value);
                }
            }
        }
        //provider
        function provider(name,provider_){
            if(isFunciton(provider_)||isArray(provider_)){
                provider_ = providerInjector.instantiate(provider_);
            }
            if(!provider_.$get){
                throw new Error('do not have $get method!');
            }
            return  providerCache[name+providerSufix]=provider_;
        }

        function enForceReturnValue(factoryFn){
            return function(){
                var result=instanceCache.invoke(factoryFn);
                return result;
            };
        }

        //facotry
        function factory(name,factoryFn,enForce){
            return provider(name,{
                $get:enForce===false?enForceReturnValue(factoryFn):factoryFn
            });
        }

        //service
        function service(name,contructor){
            return factory(name,['$injector',function($injector){
                return $injector.instantiate(contructor);
            }]);
        }

        //value
        function value(name,value){
            return factory(name,valueFn(value),false);
        }

        ////////////////////////////////////
        // internal injector
        ////////////////////////////////////
        function createInternalInjector(cache,factory){

            // get service
            function getService(serviceName,caller){
                if(cache.hasOwnProperty(serviceName)){
                    if(cache[serviceName]===INSTANTING){
                        throw new Error('重复循环依赖！');
                    }
                    return cache[serviceName];
                }else{
                    cache[serviceName]=INSTANTING;
                    //path.push(serviceName);
                    return  cache[serviceName]=factory(serviceName,caller);
                }
            }

            //invoke fn
            function invoke(fn,self,locals,serviceName){
                var length,
                    args=[],
                    i,
                    item,
                    annotateArray=annotate(fn);
                for(i=0,length=annotateArray.length;i<length;i++){
                    item=annotateArray[i];
                    args.push(locals&&locals.hasOwnProperty(item)?locals[item]:getService(item,serviceName));
                }

                if(isArray(fn)){
                    fn=fn[fn.length-1];
                }

                return fn.call(self,args);
            }

            // intantiate instace
            function instantiate(type,locals,serviceName){
                var instance = Object.create((isArray(type)? type[type.length-1]:type).prototype||null);
                var returnValue = invoke(type,instance,locals,serviceName);

                return isObject(returnValue)|| isFunciton(returnValue)?returnValue:instance;
            }

            return {
                instantiate:instantiate,
                invoke:invoke,
                get:getService
            };
        }
    }

}(window,document);

<|endoftext|>


<commit_before>require.config({
  paths: {
    a11y: '../../src',
    // shims required by a11y.js
    'array.prototype.findindex': '../../bower_components/array.prototype.findindex/index',
    'CSS.escape': '../../bower_components/CSS.escape/css.escape',
    // stuff used for testing and co
    'underscore': '../../bower_components/underscore/underscore',
    'jquery': '../../bower_components/jquery/dist/jquery',
  }
});

require([
  'underscore',
  'jquery',
  './data/all',
  './data/notes'
], function (_, $, data, notes) {

  // TODO: present focusRedirection

  var selectors = _.chain([
    _.chain(data).values().pluck('focusable').value(),
    _.chain(data).values().pluck('focusEvent').value(),
    _.chain(data).values().pluck('noFocusMethod').value(),
    _.chain(data).values().pluck('tabOrder').value(),
    _.chain(data).values().pluck('a11y').filter().pluck('focusable').value(),
    _.chain(data).values().pluck('jquery').filter().pluck('focusable').value(),
  ]).flatten().unique().filter().value();

  var $table = $('#focusable-table');
  var $tbody = $table.find('.items')
  var $versions = $table.find('.versions');
  // prepare template for actual data
  var $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  function setVersions($versions) {
    // fill in proper versions for each browser column
    $versions.children().each(function() {
      var $cell = $(this);
      var key = $cell.attr('data-column');
      var version = data[key] && data[key].platform && data[key].platform.version;
      if (!version) {
        return;
      }

      $cell
        .text(version.split('.').slice(0, 2).join('.'))
        .attr('title', data[key].platform.ua);
    });
  }

  setVersions($versions);

  // add rows of actual data
  selectors.sort().forEach(function(selector) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td').not('[data-column="notes"]');
    var expected = data.expected.focusable.indexOf(selector) !== -1;

    $_row.children('th').text(selector);
    notes[selector] && $_row.children('[data-column="notes"]').html(notes[selector]);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var supported = data[browser].focusable.indexOf(selector) !== -1;
      var tabbable = data[browser].tabOrder.indexOf(selector) !== -1;
      var event = data[browser].focusEvents.indexOf(selector) !== -1;
      var noFocusMethod = data[browser].noFocusMethod.indexOf(selector) !== -1;

      $cell.text(supported ? 'yes' : 'no')
        .attr('data-supported', supported ? 'yes' : 'no')
        .attr('data-correct', expected === supported ? 'yes' : 'no')
        .attr('data-event', event ? 'yes' : 'no')
        .attr('data-method', !noFocusMethod ? 'yes' : 'no')
        .attr('data-tabbable', tabbable ? 'yes' : 'no');

      var title = [];
      !event && (title.push('No focus event dispatched.'))
      noFocusMethod && (title.push('Element does not know the .focus() method.'))
      !tabbable && (title.push('Not tabbable.'))
      tabbable && (title.push('Tabbable.'))
      $cell.attr('title', title.join('\n'));

      if (noFocusMethod) {
        $cell.text('method!');
      }

    });

    $_row.appendTo($tbody);
  });

  // prepare table that shows support of libraries in given browser
  var $scriptTable = $('#script-focusable-table');
  $scriptTable.empty().append($table.children().clone());
  $scriptTable.find('[data-column="notes"]').remove();
  $scriptTable.find('thead td, thead th').not('.meta').attr('colspan', function() {
    return ($(this).attr('colspan') || 1) * 2;
  }).css('border', '3px solid black');

  var $subline = $scriptTable.find('thead tr').last().clone().appendTo($scriptTable.children('thead'));
  $subline.find('.meta').remove();
  $subline.prepend('');
  $subline.find('th').replaceWith(function() {
    return $('Browser	a11y.js	');
  });

  $scriptTable.find('tbody tr').each(function() {
    var $_row = $(this);
    var selector = $_row.attr('data-selector');

    $_row.children('td').not('.meta').each(function() {
      var $browserCell = $(this);
      var browser = $browserCell.attr('data-column');
      var browserSupported = $browserCell.attr('data-supported') === 'yes';
      var a11ySupported = data[browser].a11y.focusable.indexOf(selector) !== -1;
      var jquerySupported = data[browser].jquery.focusable.indexOf(selector) !== -1;

      var $a11yCell = $('?	').insertAfter($browserCell)
        .text(a11ySupported ? 'yes' : 'no')
        .attr('data-supported', a11ySupported ? 'yes' : 'no')
        .attr('data-correct', browserSupported === a11ySupported ? 'yes' : 'no');

      // make browser versions distinguishable
      $browserCell.css('border-left', '3px solid black');
      $a11yCell.css('border-right', '3px solid black');
    })
  });

  $table = $('#focus-redirection-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  setVersions($versions)

  selectors = _.chain(data).values().pluck('focusRedirection').flatten().unique().filter().value();

  // add rows of actual data
  selectors.sort().forEach(function(selector) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td').not('[data-column="target"]');
    var _selector = selector.split(' --- ');
    $_row.children('th').text(_selector[0]).next().text(_selector[1]);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var supported = data[browser].focusRedirection.indexOf(selector) !== -1;

      $cell.text(supported ? 'yes' : 'no')
        .attr('data-supported', supported ? 'yes' : 'no');
    });

    $_row.appendTo($tbody);
  });

  $table = $('#tabbable-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  setVersions($versions)

  selectors = _.chain([
    _.chain(data).values().pluck('focusable').value(),
    _.chain(data).values().pluck('tabOrder').value(),
  ]).flatten().unique().filter().value();

  // add rows of actual data
  selectors.sort().forEach(function(selector) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td');
    var expectedFocusable = data.expected.focusable.indexOf(selector) !== -1 ? 10 : 0;
    var expectedTabbable = data.expected.tabOrder.indexOf(selector) !== -1 ? 1 : 0;
    var expected = expectedFocusable + expectedTabbable;

    $_row.children('th').text(selector);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var focusable = data[browser].focusable.indexOf(selector) !== -1;
      var tabbable = data[browser].tabOrder.indexOf(selector) !== -1;
      var supported = (focusable ? 10 : 0) + (tabbable ? 1 : 0);

      $cell.text(tabbable ? 'tabbable' : focusable ? 'focusable' : 'no')
        .attr('data-correct', expected === supported ? 'yes' : 'no')
        .attr('data-focusable', focusable ? 'yes' : 'no')
        .attr('data-tabbable', tabbable ? 'yes' : 'no');

      var title = [];
      !focusable && tabbable && (title.push('Not focusable but tabbable.'))
      $cell.attr('title', title.join('\n'));

    });

    $_row.appendTo($tbody);
  });

  $table = $('#taborder-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  setVersions($versions)

  function getArrayFoldingIterator(destination) {
    var offset = 0;
    return function(item, index) {
      var target = index + offset;
      var position;
      var _offset;

      if (destination[target] === item) {
        return;
      }

      position = destination.indexOf(item, target);
      _offset = position - target;
      if (position > -1 && _offset < 10) {
        offset += _offset;
        return;
      }

      position =  destination.lastIndexOf(item, target);
      _offset = position - target;
      if (position > -1 && _offset > -10) {
        offset += _offset;
        return;
      }

      destination.splice(index + offset, 0, item);
    };
  }

  function getFoldedArrayIndexMapper(master, list) {
    var offset = 0;
    return function(item, index) {
      var target = index + offset;
      if (item === list[target]) {
        return target;
      }

      var position = list.indexOf(item, target);
      var nextPosition = master.indexOf(list[target + 1], index);

      if (position !== -1) {
        if (nextPosition !== -1) {
          offset--;
          return null;
        }

        offset += position - target;
        return index + offset;
      }

      offset--;
      return null
    };
  }

  selectors = data.expected.tabOrder.slice(0);
  // make HTML the first element of the list (because we splice things in *after* the current item)
  selectors.unshift('HTML');
  // flatten() but maintaining order
  Object.keys(data).forEach(function(browser) {
    data[browser].tabOrder.forEach(getArrayFoldingIterator(selectors));
  });

  // map holes in sequence
  Object.keys(data).forEach(function(browser) {
    var list = data[browser].tabOrder;
    data[browser].interlockedTabOrder = selectors.map(getFoldedArrayIndexMapper(selectors, list));
  });

  // add rows of actual data
  selectors.forEach(function(selector, index) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td');
    var expected = data.expected.tabOrder.indexOf(selector) !== -1;

    $_row.children('th').text(selector);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var _index = data[browser].interlockedTabOrder[index];
      var focusable = data[browser].focusable.indexOf(selector) !== -1;

      $cell.text(_index !== null ? _index : '' )
        .attr('data-correct', expected === (_index !== null) ? 'yes' : 'no')
        .attr('data-tabbable', _index !== null  ? 'yes' : 'no')
        .attr('data-focusable', focusable ? 'yes' : 'no');
    });

    $_row.appendTo($tbody);
  });

  $table = $('#script-taborder-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  $table.find('thead td, thead th').not('.meta').attr('colspan', function() {
    return ($(this).attr('colspan') || 1) * 2;
  }).css('border', '3px solid black');

  $subline = $table.find('thead tr').last().clone().appendTo($table.children('thead'));
  $subline.find('.meta').remove();
  $subline.prepend('');
  $subline.find('th').replaceWith(function() {
    return $('Browser	a11y.js	');
  });

  setVersions($versions);

  // flatten() but maintaining order
  Object.keys(data).forEach(function(browser) {
    data[browser].a11y.tabOrder.forEach(getArrayFoldingIterator(selectors));
  });

  // map holes in sequence
  Object.keys(data).forEach(function(browser) {
    var list = data[browser].tabOrder;
    data[browser].interlockedTabOrder = selectors.map(getFoldedArrayIndexMapper(selectors, list));
    var _list = data[browser].a11y.tabOrder;
    data[browser].a11y.interlockedTabOrder = selectors.map(getFoldedArrayIndexMapper(selectors, _list));
  });

  // add rows of actual data
  selectors.forEach(function(selector, index) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td');
    var expected = data.expected.tabOrder.indexOf(selector) !== -1;

    $_row.children('th').text(selector);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var _index = data[browser].interlockedTabOrder[index];
      var _aIndex = data[browser].a11y.interlockedTabOrder[index];
      var focusable = data[browser].focusable.indexOf(selector) !== -1;
      var aFocusable = data[browser].a11y.focusable.indexOf(selector) !== -1;

      $cell.text(_index !== null ? _index : '')
         .attr('data-tabbable', _index !== null  ? 'yes' : 'no')
         .attr('data-focusable', focusable ? 'yes' : 'no')
         .css('border-left', '3px solid black');

      $('	')
        .text(_aIndex !== null ? _aIndex : '')
        .attr('data-tabbable', _aIndex !== null  ? 'yes' : 'no')
        .attr('data-focusable', aFocusable ? 'yes' : 'no')
        .attr('data-correct', _index === _aIndex ? 'yes' : 'no')
        .css('border-right', '3px solid black')
        .insertAfter($cell);
    });

    $_row.appendTo($tbody);
  });

});
<commit_msg>removing jquery remnants<commit_after>require.config({
  paths: {
    a11y: '../../src',
    // shims required by a11y.js
    'array.prototype.findindex': '../../bower_components/array.prototype.findindex/index',
    'CSS.escape': '../../bower_components/CSS.escape/css.escape',
    // stuff used for testing and co
    'underscore': '../../bower_components/underscore/underscore',
    'jquery': '../../bower_components/jquery/dist/jquery',
  }
});

require([
  'underscore',
  'jquery',
  './data/all',
  './data/notes'
], function (_, $, data, notes) {

  // TODO: present focusRedirection

  var selectors = _.chain([
    _.chain(data).values().pluck('focusable').value(),
    _.chain(data).values().pluck('focusEvent').value(),
    _.chain(data).values().pluck('noFocusMethod').value(),
    _.chain(data).values().pluck('tabOrder').value(),
    _.chain(data).values().pluck('a11y').filter().pluck('focusable').value(),
  ]).flatten().unique().filter().value();

  var $table = $('#focusable-table');
  var $tbody = $table.find('.items')
  var $versions = $table.find('.versions');
  // prepare template for actual data
  var $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  function setVersions($versions) {
    // fill in proper versions for each browser column
    $versions.children().each(function() {
      var $cell = $(this);
      var key = $cell.attr('data-column');
      var version = data[key] && data[key].platform && data[key].platform.version;
      if (!version) {
        return;
      }

      $cell
        .text(version.split('.').slice(0, 2).join('.'))
        .attr('title', data[key].platform.ua);
    });
  }

  setVersions($versions);

  // add rows of actual data
  selectors.sort().forEach(function(selector) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td').not('[data-column="notes"]');
    var expected = data.expected.focusable.indexOf(selector) !== -1;

    $_row.children('th').text(selector);
    notes[selector] && $_row.children('[data-column="notes"]').html(notes[selector]);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var supported = data[browser].focusable.indexOf(selector) !== -1;
      var tabbable = data[browser].tabOrder.indexOf(selector) !== -1;
      var event = data[browser].focusEvents.indexOf(selector) !== -1;
      var noFocusMethod = data[browser].noFocusMethod.indexOf(selector) !== -1;

      $cell.text(supported ? 'yes' : 'no')
        .attr('data-supported', supported ? 'yes' : 'no')
        .attr('data-correct', expected === supported ? 'yes' : 'no')
        .attr('data-event', event ? 'yes' : 'no')
        .attr('data-method', !noFocusMethod ? 'yes' : 'no')
        .attr('data-tabbable', tabbable ? 'yes' : 'no');

      var title = [];
      !event && (title.push('No focus event dispatched.'))
      noFocusMethod && (title.push('Element does not know the .focus() method.'))
      !tabbable && (title.push('Not tabbable.'))
      tabbable && (title.push('Tabbable.'))
      $cell.attr('title', title.join('\n'));

      if (noFocusMethod) {
        $cell.text('method!');
      }

    });

    $_row.appendTo($tbody);
  });

  // prepare table that shows support of libraries in given browser
  var $scriptTable = $('#script-focusable-table');
  $scriptTable.empty().append($table.children().clone());
  $scriptTable.find('[data-column="notes"]').remove();
  $scriptTable.find('thead td, thead th').not('.meta').attr('colspan', function() {
    return ($(this).attr('colspan') || 1) * 2;
  }).css('border', '3px solid black');

  var $subline = $scriptTable.find('thead tr').last().clone().appendTo($scriptTable.children('thead'));
  $subline.find('.meta').remove();
  $subline.prepend('');
  $subline.find('th').replaceWith(function() {
    return $('Browser	a11y.js	');
  });

  $scriptTable.find('tbody tr').each(function() {
    var $_row = $(this);
    var selector = $_row.attr('data-selector');

    $_row.children('td').not('.meta').each(function() {
      var $browserCell = $(this);
      var browser = $browserCell.attr('data-column');
      var browserSupported = $browserCell.attr('data-supported') === 'yes';
      var a11ySupported = data[browser].a11y.focusable.indexOf(selector) !== -1;

      var $a11yCell = $('?	').insertAfter($browserCell)
        .text(a11ySupported ? 'yes' : 'no')
        .attr('data-supported', a11ySupported ? 'yes' : 'no')
        .attr('data-correct', browserSupported === a11ySupported ? 'yes' : 'no');

      // make browser versions distinguishable
      $browserCell.css('border-left', '3px solid black');
      $a11yCell.css('border-right', '3px solid black');
    })
  });

  $table = $('#focus-redirection-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  setVersions($versions)

  selectors = _.chain(data).values().pluck('focusRedirection').flatten().unique().filter().value();

  // add rows of actual data
  selectors.sort().forEach(function(selector) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td').not('[data-column="target"]');
    var _selector = selector.split(' --- ');
    $_row.children('th').text(_selector[0]).next().text(_selector[1]);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var supported = data[browser].focusRedirection.indexOf(selector) !== -1;

      $cell.text(supported ? 'yes' : 'no')
        .attr('data-supported', supported ? 'yes' : 'no');
    });

    $_row.appendTo($tbody);
  });

  $table = $('#tabbable-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  setVersions($versions)

  selectors = _.chain([
    _.chain(data).values().pluck('focusable').value(),
    _.chain(data).values().pluck('tabOrder').value(),
  ]).flatten().unique().filter().value();

  // add rows of actual data
  selectors.sort().forEach(function(selector) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td');
    var expectedFocusable = data.expected.focusable.indexOf(selector) !== -1 ? 10 : 0;
    var expectedTabbable = data.expected.tabOrder.indexOf(selector) !== -1 ? 1 : 0;
    var expected = expectedFocusable + expectedTabbable;

    $_row.children('th').text(selector);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var focusable = data[browser].focusable.indexOf(selector) !== -1;
      var tabbable = data[browser].tabOrder.indexOf(selector) !== -1;
      var supported = (focusable ? 10 : 0) + (tabbable ? 1 : 0);

      $cell.text(tabbable ? 'tabbable' : focusable ? 'focusable' : 'no')
        .attr('data-correct', expected === supported ? 'yes' : 'no')
        .attr('data-focusable', focusable ? 'yes' : 'no')
        .attr('data-tabbable', tabbable ? 'yes' : 'no');

      var title = [];
      !focusable && tabbable && (title.push('Not focusable but tabbable.'))
      $cell.attr('title', title.join('\n'));

    });

    $_row.appendTo($tbody);
  });

  $table = $('#taborder-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  setVersions($versions)

  function getArrayFoldingIterator(destination) {
    var offset = 0;
    return function(item, index) {
      var target = index + offset;
      var position;
      var _offset;

      if (destination[target] === item) {
        return;
      }

      position = destination.indexOf(item, target);
      _offset = position - target;
      if (position > -1 && _offset < 10) {
        offset += _offset;
        return;
      }

      position =  destination.lastIndexOf(item, target);
      _offset = position - target;
      if (position > -1 && _offset > -10) {
        offset += _offset;
        return;
      }

      destination.splice(index + offset, 0, item);
    };
  }

  function getFoldedArrayIndexMapper(master, list) {
    var offset = 0;
    return function(item, index) {
      var target = index + offset;
      if (item === list[target]) {
        return target;
      }

      var position = list.indexOf(item, target);
      var nextPosition = master.indexOf(list[target + 1], index);

      if (position !== -1) {
        if (nextPosition !== -1) {
          offset--;
          return null;
        }

        offset += position - target;
        return index + offset;
      }

      offset--;
      return null
    };
  }

  selectors = data.expected.tabOrder.slice(0);
  // make HTML the first element of the list (because we splice things in *after* the current item)
  selectors.unshift('HTML');
  // flatten() but maintaining order
  Object.keys(data).forEach(function(browser) {
    data[browser].tabOrder.forEach(getArrayFoldingIterator(selectors));
  });

  // map holes in sequence
  Object.keys(data).forEach(function(browser) {
    var list = data[browser].tabOrder;
    data[browser].interlockedTabOrder = selectors.map(getFoldedArrayIndexMapper(selectors, list));
  });

  // add rows of actual data
  selectors.forEach(function(selector, index) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td');
    var expected = data.expected.tabOrder.indexOf(selector) !== -1;

    $_row.children('th').text(selector);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var _index = data[browser].interlockedTabOrder[index];
      var focusable = data[browser].focusable.indexOf(selector) !== -1;

      $cell.text(_index !== null ? _index : '' )
        .attr('data-correct', expected === (_index !== null) ? 'yes' : 'no')
        .attr('data-tabbable', _index !== null  ? 'yes' : 'no')
        .attr('data-focusable', focusable ? 'yes' : 'no');
    });

    $_row.appendTo($tbody);
  });

  $table = $('#script-taborder-table');
  $tbody = $table.find('.items')
  $versions = $table.find('.versions');
  $row = $versions.clone();
  $row.children().replaceWith(function(index) {
    var $this = $(this);
    return index ? $('	').prop('className', $this.prop('className')).attr('data-column', $this.attr('data-column')) : this;
  });

  $table.find('thead td, thead th').not('.meta').attr('colspan', function() {
    return ($(this).attr('colspan') || 1) * 2;
  }).css('border', '3px solid black');

  $subline = $table.find('thead tr').last().clone().appendTo($table.children('thead'));
  $subline.find('.meta').remove();
  $subline.prepend('');
  $subline.find('th').replaceWith(function() {
    return $('Browser	a11y.js	');
  });

  setVersions($versions);

  // flatten() but maintaining order
  Object.keys(data).forEach(function(browser) {
    data[browser].a11y.tabOrder.forEach(getArrayFoldingIterator(selectors));
  });

  // map holes in sequence
  Object.keys(data).forEach(function(browser) {
    var list = data[browser].tabOrder;
    data[browser].interlockedTabOrder = selectors.map(getFoldedArrayIndexMapper(selectors, list));
    var _list = data[browser].a11y.tabOrder;
    data[browser].a11y.interlockedTabOrder = selectors.map(getFoldedArrayIndexMapper(selectors, _list));
  });

  // add rows of actual data
  selectors.forEach(function(selector, index) {
    var $_row = $row.clone().attr('data-selector', selector);
    var $cells = $_row.children('td');
    var expected = data.expected.tabOrder.indexOf(selector) !== -1;

    $_row.children('th').text(selector);

    $cells.each(function() {
      var $cell = $(this);
      var browser = $cell.attr('data-column');
      var _index = data[browser].interlockedTabOrder[index];
      var _aIndex = data[browser].a11y.interlockedTabOrder[index];
      var focusable = data[browser].focusable.indexOf(selector) !== -1;
      var aFocusable = data[browser].a11y.focusable.indexOf(selector) !== -1;

      $cell.text(_index !== null ? _index : '')
         .attr('data-tabbable', _index !== null  ? 'yes' : 'no')
         .attr('data-focusable', focusable ? 'yes' : 'no')
         .css('border-left', '3px solid black');

      $('	')
        .text(_aIndex !== null ? _aIndex : '')
        .attr('data-tabbable', _aIndex !== null  ? 'yes' : 'no')
        .attr('data-focusable', aFocusable ? 'yes' : 'no')
        .attr('data-correct', _index === _aIndex ? 'yes' : 'no')
        .css('border-right', '3px solid black')
        .insertAfter($cell);
    });

    $_row.appendTo($tbody);
  });

});
<|endoftext|>