<commit_before>'use strict';
/**
 * @file basic test
 * @module transfer-rate
 * @package transfer-rate
 * @subpackage test
 * @version 0.0.1
 * @author https://github.com/expressjs/serve-static
 * @license GPLv3
 */

/*
 * initialize module
 */
// import
try {
    var transfer = require('../index.min.js');
    var express = require('express');
    var request = require('supertest');
} catch (MODULE_NOT_FOUND) {
    console.error(MODULE_NOT_FOUND);
    process.exit(1);
}

/*
 * test module
 */
describe('ratio', function() {

    it('should return standard KB/s', function(done) {

        var app = express();
        var rate = transfer();
        app.get('/', function(req, res) {

            var start = process.hrtime();
            res.send('ok');
            if (/^[0-9]*.[0-9]? KB\/s$/.test(rate(req, start))) {
                done();
            }
        });
        request(app).get('/').expect(200).end(function(err, res) {

            if (err)
                throw err;
        });
    });

    it('should return only ratio', function(done) {

        var app = express();
        var rate = transfer({
            output: false
        });
        app.get('/', function(req, res) {

            var start = process.hrtime();
            res.send('ok');
            if (/^[0-9]*.[0-9]?$/.test(rate(req, start))) {
                done();
            }
        });
        request(app).get('/').expect(200).end(function(err, res) {

            if (err)
                throw err;
        });
    });

    describe('response', function() {

        it('should return Byte', function(done) {

            var app = express();
            var rate = transfer({
                data: 'Byte'
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ Byte/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return MB', function(done) {

            var app = express();
            var rate = transfer({
                data: 'MB'
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ MB/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return bit', function(done) {

            var app = express();
            var rate = transfer({
                data: 'bit'
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ bit/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return Kb', function(done) {

            var app = express();
            var rate = transfer({
                data: 'Kb'
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ Kb/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return Mb', function(done) {

            var app = express();
            var rate = transfer({
                data: 'Mb'
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ Mb/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return nanosecond', function(done) {

            var app = express();
            var rate = transfer({
                time: 'nanosecond'
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/\/ns/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return millisecond', function(done) {

            var app = express();
            var rate = transfer({
                time: 'millisecond'
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/\/ms/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });
    });

    describe('request', function() {

        it('should return Byte', function(done) {

            var app = express();
            var rate = transfer({
                data: 'Byte',
                response: false
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ Byte/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return MB', function(done) {

            var app = express();
            var rate = transfer({
                data: 'MB',
                response: false
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ MB/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return bit', function(done) {

            var app = express();
            var rate = transfer({
                data: 'bit',
                response: false
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ bit/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return Kb', function(done) {

            var app = express();
            var rate = transfer({
                data: 'Kb',
                response: false
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ Kb/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return Mb', function(done) {

            var app = express();
            var rate = transfer({
                data: 'Mb',
                response: false
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/ Mb/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return nanosecond', function(done) {

            var app = express();
            var rate = transfer({
                time: 'nanosecond',
                response: false
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/\/ns/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });

        it('should return millisecond', function(done) {

            var app = express();
            var rate = transfer({
                time: 'millisecond',
                response: false
            });
            app.get('/', function(req, res) {

                var start = process.hrtime();
                res.send('ok');
                if (/\/ms/.test(rate(req, start))) {
                    done();
                }
            });
            request(app).get('/').expect(200).end(function(err, res) {

                if (err)
                    throw err;
            });
        });
    });
});
<commit_msg>test: fix missing assert<commit_after>'use strict';
/**
 * @file basic test
 * @module transfer-rate
 * @subpackage test
 * @version 0.0.1
 * @author https://github.com/expressjs/serve-static
 * @license GPLv3
 */

/*
 * initialize module
 */
var transfer = require('..');
var express = require('express');
var request = require('supertest');
var assert = require('assert');

/*
 * test module
 */
describe('ratio', function() {

  it('should return standard KB/s', function(done) {

    var app = express();
    var rate = transfer();
    app.get('/', function(req, res) {

      var start = process.hrtime();
      res.send('ok');
      assert.ok(/^[0-9]*.[0-9]? KB\/s$/.test(rate(req, start)));
      done();
    });
    request(app).get('/').expect(200).end(function(err, res) {

      assert.equal(err, null);
    });
  });
  it('should return only ratio', function(done) {

    var app = express();
    var rate = transfer({
      output: false
    });
    app.get('/', function(req, res) {

      var start = process.hrtime();
      res.send('ok');
      assert.ok(/^[0-9]*.[0-9]?$/.test(rate(req, start)));
      done();
    });
    request(app).get('/').expect(200).end(function(err, res) {

      assert.equal(err, null);
    });
  });

  describe('response', function() {

    it('should return Byte', function(done) {

      var app = express();
      var rate = transfer({
        data: 'Byte'
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ Byte/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return MB', function(done) {

      var app = express();
      var rate = transfer({
        data: 'MB'
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ MB/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return bit', function(done) {

      var app = express();
      var rate = transfer({
        data: 'bit'
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ bit/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return Kb', function(done) {

      var app = express();
      var rate = transfer({
        data: 'Kb'
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ Kb/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return Mb', function(done) {

      var app = express();
      var rate = transfer({
        data: 'Mb'
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ Mb/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return nanosecond', function(done) {

      var app = express();
      var rate = transfer({
        time: 'nanosecond'
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/\/ns/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return millisecond', function(done) {

      var app = express();
      var rate = transfer({
        time: 'millisecond'
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/\/ms/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
  });

  describe('request', function() {

    it('should return Byte', function(done) {

      var app = express();
      var rate = transfer({
        data: 'Byte',
        response: false
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ Byte/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return MB', function(done) {

      var app = express();
      var rate = transfer({
        data: 'MB',
        response: false
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ MB/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return bit', function(done) {

      var app = express();
      var rate = transfer({
        data: 'bit',
        response: false
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ bit/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return Kb', function(done) {

      var app = express();
      var rate = transfer({
        data: 'Kb',
        response: false
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ Kb/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return Mb', function(done) {

      var app = express();
      var rate = transfer({
        data: 'Mb',
        response: false
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/ Mb/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return nanosecond', function(done) {

      var app = express();
      var rate = transfer({
        time: 'nanosecond',
        response: false
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/\/ns/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
    it('should return millisecond', function(done) {

      var app = express();
      var rate = transfer({
        time: 'millisecond',
        response: false
      });
      app.get('/', function(req, res) {

        var start = process.hrtime();
        res.send('ok');
        assert.ok(/\/ms/.test(rate(req, start)));
        done();
      });
      request(app).get('/').expect(200).end(function(err, res) {

        assert.equal(err, null);
      });
    });
  });
});
<|endoftext|>


<commit_before>/* eslint-disable no-magic-numbers */
import React from "react";
import { VictoryTooltip } from "victory-core";
import { VictorySunburst } from "../src/index";
// import flare from "./flare.js";

export default class App extends React.Component {
  render() {
    return (

        <VictorySunburst
          name="fixedLabel"
          style={{
            data: { cursor: "pointer", stroke: "white" },
            labels: {
              fill: (datum, active) => { return active === false ? "none" : "#ADDFFF"; },
              textAnchor: "middle",
              verticalAnchor: "middle"
            }
          }}
        />
        <VictorySunburst
          name="fixedTooltip"
          colorScale="red"
          labelComponent={<VictoryTooltip active height={30} width={40} />}
        />
        <VictorySunburst
          name="hoverTooltip"
          colorScale="green"
          labelComponent={
            <VictoryTooltip
              orientation="bottom" pointerLength={0} height={40} width={60}
              x={0} y={0} dx={0} dy={-20}
            />
          }
          labels={({ data: { name, size } }, totalSize) => {
            return `${name}: ${size}\n(${Math.round(size / totalSize * 100)}%)`;
          }}
        />

    );
  }
}
<commit_msg>update demo<commit_after>/* eslint-disable no-magic-numbers */
import React from "react";
import { VictoryTooltip } from "victory-core";
import { VictorySunburst } from "../src/index";
// import flare from "./flare.js";

export default class App extends React.Component {
  render() {
    return (

        <VictorySunburst />
        <VictorySunburst
          name="fixedLabel"
          colorScale="blue"
          style={{
            labels: {
              fill: (d) => { return !d.parent ? "#004B8F" : "#ADDFFF"; },
              textAnchor: "middle",
              verticalAnchor: "middle"
            }
          }}
        />
        <VictorySunburst
          name="fixedTooltip"
          colorScale="red"
          labelComponent={<VictoryTooltip active={(d) => !!d.parent} height={30} width={40} />}
          labels={(d) => d.data.size}
          style={{
            labels: { fill: "black" }
          }}
        />
        <VictorySunburst
          name="hoverTooltip"
          colorScale="green"
          labelComponent={
            <VictoryTooltip
              active={(d) => !d.parent} orientation="bottom"
              pointerLength={0} height={40} width={60} x={0} y={-20}
            />
          }
          labels={({ data: { name, size } }, totalSize) => {
            return `${name}: ${size}\n(${Math.round(size / totalSize * 100)}%)`;
          }}
          style={{
            labels: { fill: "black" }
          }}
        />

    );
  }
}
<|endoftext|>


<commit_before>(function(exports) {
    "use strict";

    var Window = new Class({
        initialize: function() {
            this.x = 0;
            this.y = 0;
            this.width = 1;
            this.height = 1;
        },
        connect: function(server) {
            this._privateServer = server;
            var connection = this._privateServer.clientConnected(this);
            this._port = connection.clientPort;
            this._port.addEventListener("message", function(messageEvent) {
                this.handleEvent(messageEvent.data);
            }.bind(this));
            this._server = connection.server;
            this.windowId = this._server.createWindow({ x: this.x, y: this.y,
                                                        width: this.width, height: this.height });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["Expose", "ConfigureNotify"] });
        },
        handleEvent: function(event) {
            switch (event.type) {
            case "ConfigureNotify":
                return this.configureNotify(event);
            case "Expose":
                return this.expose(event);
            }
        },
        configureNotify: function(event) {
            if (event.windowId !== this.windowId)
                return;

            if (event.x !== undefined)
                this.x = event.x;
            if (event.y !== undefined)
                this.y = event.y;
            if (event.width !== undefined)
                this.width = event.width;
            if (event.height !== undefined)
                this.height = event.height;
        },
        invalidate: function() {
            this._server.invalidateWindow({ windowId: this.windowId });
        },
        _drawBackground: function(event) {
            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.fillStyle = event.backgroundColor;
                ctx.fillRect(0, 0, this.width, this.height);
            }.bind(this));
        },
        expose: function(event) {
            this._drawBackground(event);
            this.clearDamage();
        },
        map: function() {
            this._server.mapWindow({ windowId: this.windowId });
        },
        moveResize: function(x, y, width, height) {
            this._server.configureWindow({ windowId: this.windowId, x: x, y: y, width: width, height: height });
        },
        changeProperty: function(name, value) {
            this._server.changeProperty({ windowId: this.windowId, name: name, value: value });
        },
        clearDamage: function() {
            var region = new Region();
            region.init_rect(0, 0, this.width, this.height);
            this._server.clearDamage({ windowId: this.windowId,
                                       region: region });
            region.finalize();
        },
    });

    var ImageWindow = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);
            this._image = new Image();
            this._image.addEventListener("load", function() {
                this._loaded = true;
                this.moveResize(undefined, undefined, this._image.width, this._image.height);
            }.bind(this));
        },
        _setImage: function(src) {
            this._loaded = false;
            this._image.src = src;
        },
        configureNotify: function(event) {
            this.parent(event);
            this.invalidate();
        },
        expose: function(event) {
            this._drawBackground(event);

            if (!this._loaded)
                return;

            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.drawImage(this._image, 0, 0, this.width, this.height);
            }.bind(this));
            this.clearDamage();
        },
    });

    var BackgroundWindow = new Class({
        Extends: ImageWindow,
        connect: function(server) {
            this.parent(server);
            this._server.changeAttributes({ windowId: this.windowId, overrideRedirect: true });
            this._setImage("demo/data/background.jpg");
        },
    });

    var Panel = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);
            this._launchers = [];
            var rootWindowGeometry = this._server.getGeometry({ windowId: this._server.rootWindowId });
            this.moveResize(undefined, undefined, rootWindowGeometry.width, 30);
            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#eeeeec" });
            this.changeProperty("_NET_WM_WINDOW_TYPE", "_NET_WM_WINDOW_TYPE_DOCK");
        },
        _relayout: function() {
            var padding = 4;
            var x = padding;
            this._launchers.forEach(function(launcher) {
                launcher.moveResize(x, padding, undefined, undefined);
                x += launcher.width + padding;
            });
        },
        configureNotify: function(event) {
            this.parent(event);
            if (event.windowId !== this.windowId && event.width !== undefined)
                this._relayout();
        },
        addLauncher: function(launcher) {
            this._launchers.push(launcher);
            this._server.selectInput({ windowId: launcher.windowId,
                                       events: ["ConfigureNotify"] });
            this._server.reparentWindow({ windowId: launcher.windowId,
                                          newParentId: this.windowId });
            this._relayout();
        },
        removeLauncher: function(launcher) {
            var idx = this._launchers.indexOf(launcher);
            // XXX -- way to unselect for input
            this._server.reparentWindow({ windowId: launcher.windowId,
                                          newParentId: this._server.rootWindowId });
            this._launchers.splice(idx, 1);
        },
        expose: function(event) {
            this._drawBackground(event);

            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.strokeStyle = '#aaaaaa';
                ctx.lineWidth = 1;
                ctx.beginPath();
                ctx.rect(-1, 0, this.width + 2, this.height);
                ctx.stroke();
            }.bind(this));
        },
    });

    var Launcher = new Class({
        Extends: ImageWindow,
        initialize: function(imageSrc, constructor) {
            this.parent(imageSrc);
            this._imageSrc = imageSrc;
            this._constructor = constructor;
        },
        connect: function(server) {
            this.parent(server);
            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#eeeeec",
                                            cursor: "pointer" });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["ButtonPress"] });
            this._setImage(this._imageSrc);
        },
        _launchApp: function() {
            var client = new this._constructor();
            client.connect(this._privateServer);
            client.map();
        },
        handleEvent: function(event) {
            switch (event.type) {
            case "ButtonPress":
                return this._launchApp();
            default:
                return this.parent(event);
            }
        },
    });

    var FakeTerminalWindow = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);
            this._focused = false;
            this._buffer = "";
            this._server.configureWindow({ windowId: this.windowId,
                                           width: 700, height: 400 });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["KeyPress"] });
            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#121212" });
            this.changeProperty("WM_NAME", "Fake Terminal");
        },
        handleEvent: function(event) {
            switch(event.type) {
            case "KeyPress":
                return this._handleKeyPress(event);
            default:
                return this.parent(event);
            }
        },
        expose: function(event) {
            this._drawBackground(event);

            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.font = 'bold 10pt "Droid Sans Mono Dotted"';

                var x = 4, y = 16;
                function drawText(text) {
                    var metrics = ctx.measureText(text);
                    ctx.fillText(text, x, y);
                    x += metrics.width;
                }

                ctx.fillStyle = '#8ae234';
                drawText("jstpierre@jstpierre-lappy");

                ctx.fillStyle = '#729fcf';
                drawText(" ~ $ ");

                ctx.fillStyle = '#eeeeec';
                drawText(this._buffer);
            }.bind(this));
            this.clearDamage();
        },
        _handleKeyPress: function(event) {
            this._buffer += String.fromCharCode(event.charCode);
            this.invalidate();
        },
    });

    function ellipse(ctx, x, y, rx, ry) {
        x -= rx;
        y -= ry;

        var kappa = .5522848;
        var ox = rx * kappa;
        var oy = ry * kappa;
        var xe = x + rx * 2;
        var ye = y + ry * 2;
        var xm = x + rx;
        var ym = y + ry;

        ctx.beginPath();
        ctx.moveTo(x, ym);
        ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
        ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
        ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
        ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
        ctx.closePath();
    }

    var Xeyes = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);

            this._pixmapId = 0;

            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#eeeeec" });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["MapNotify", "UnmapNotify"] });
            this.moveResize(undefined, undefined, 200, 150);
            this.changeProperty("WM_NAME", "xeyes.js");
        },
        _start: function() {
            this._intervalId = setInterval(function() {
                this.invalidate();
            }.bind(this), 50);
        },
        _stop: function() {
            clearInterval(this._intervalId);
            this._intervalId = 0;
        },
        _destroyPixmap: function() {
            this._server.freePixmap({ pixmapId: this._pixmapId });
            this._pixmapId = 0;
        },
        _ensurePixmap: function() {
            if (this._pixmapId)
                return;

            this._pixmapId = this._server.createPixmap({ width: this.width,
                                                         height: this.height });

            var eyeRX = this.width / 4 - 6;
            var eyeRY = this.height / 2 - 6;
            var eyeCenterLX = this.width * (1/4);
            var eyeCenterRX = this.width * (3/4);
            var eyeCenterY = this.height / 2;

            this._server.drawWithContext(this._pixmapId, function(ctx) {
                ctx.clearRect(0, 0, this.width, this.height);

                ctx.strokeStyle = '#000000';
                ctx.lineWidth = 4;
                ctx.fillStyle = '#ffffff';

                // scleras
                ellipse(ctx, eyeCenterLX, eyeCenterY, eyeRX, eyeRY);
                ctx.fill();
                ctx.stroke();

                ellipse(ctx, eyeCenterRX, eyeCenterY, eyeRX, eyeRY);
                ctx.fill();
                ctx.stroke();
            }.bind(this));
        },
        configureNotify: function(event) {
            this.parent(event);
            this._destroyPixmap();
            this.invalidate();
        },
        handleEvent: function(event) {
            switch(event.type) {
            case "MapNotify":
                return this._start();
            case "UnmapNotify":
                return this._stop();
            default:
                return this.parent(event);
            }
        },
        expose: function(event) {
            this._drawBackground(event);

            this._ensurePixmap();

            var eyeRX = this.width / 4 - 6;
            var eyeRY = this.height / 2 - 6;
            var eyeCenterLX = this.width * (1/4);
            var eyeCenterRX = this.width * (3/4);
            var eyeCenterY = this.height / 2;

            var pupilRX = eyeRX / 2;
            var pupilRY = eyeRY / 2;

            var pointer = this._server.queryPointer();
            var pointerCoords = this._server.translateCoordinates({ srcWindowId: this._server.rootWindowId,
                                                                    destWindowId: this.windowId,
                                                                    x: pointer.rootX, y: pointer.rootY });

            function hypot(x, y) {
                return Math.sqrt(x*x + y*y);
            }

            function getPupilPosition(eyeCenterX) {
                // The max distance away from the center the pupil
                // is allowed to be.
                var maxDistX = eyeRX - pupilRX;
                var maxDistY = eyeRY - pupilRY;

                // Normalize to center of eye.
                var pointerX = pointerCoords.x - eyeCenterX;
                var pointerY = pointerCoords.y - eyeCenterY;

                var distance = hypot(pointerX / maxDistX, pointerY / maxDistY);
                if (distance > 1)
                    distance = 1;

                var angle = Math.atan2(pointerY, pointerX);

                // Pupil position relative to center of eye.
                var pupilX = Math.cos(angle) * distance * maxDistX;
                var pupilY = Math.sin(angle) * distance * maxDistY;

                return { x: pupilX, y: pupilY };
            }

            this._server.copyArea({ srcDrawableId: this._pixmapId,
                                    destDrawableId: this.windowId,
                                    oldX: 0, oldY: 0, newX: 0, newY: 0,
                                    width: this.width, height: this.height });
            this._server.drawWithContext(this.windowId, function(ctx) {
                // pupils
                ctx.fillStyle = '#000000';

                var pos;

                pos = getPupilPosition(eyeCenterLX);
                ellipse(ctx, eyeCenterLX + pos.x, eyeCenterY + pos.y, pupilRX, pupilRY);
                ctx.fill();

                pos = getPupilPosition(eyeCenterRX);
                ellipse(ctx, eyeCenterRX + pos.x, eyeCenterY + pos.y, pupilRX, pupilRY);
                ctx.fill();
            });
            this.clearDamage();
        },
    });

    var server = new Server();
    document.querySelector(".server").appendChild(server.elem);

    var wm = new WindowManager();
    wm.connect(server);

    var w = new BackgroundWindow();
    w.connect(server);
    w.map();

    var panel = new Panel();
    panel.connect(server);
    panel.map();

    var launcher;

    launcher = new Launcher("demo/data/launcher-terminal.png", FakeTerminalWindow);
    launcher.connect(server);
    panel.addLauncher(launcher);
    launcher.map();

    launcher = new Launcher("demo/data/launcher-xeyes.png", Xeyes);
    launcher.connect(server);
    panel.addLauncher(launcher);
    launcher.map();

    window.server = server;

    function syncSize() {
        var width = document.documentElement.clientWidth;
        var height = document.documentElement.clientHeight;
        server.resize(width, height);
    }

    window.addEventListener("resize", syncSize);
    syncSize();

})(window);
<commit_msg>demo: Resize and relayout the panel when the root window changes size<commit_after>(function(exports) {
    "use strict";

    var Window = new Class({
        initialize: function() {
            this.x = 0;
            this.y = 0;
            this.width = 1;
            this.height = 1;
        },
        connect: function(server) {
            this._privateServer = server;
            var connection = this._privateServer.clientConnected(this);
            this._port = connection.clientPort;
            this._port.addEventListener("message", function(messageEvent) {
                this.handleEvent(messageEvent.data);
            }.bind(this));
            this._server = connection.server;
            this.windowId = this._server.createWindow({ x: this.x, y: this.y,
                                                        width: this.width, height: this.height });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["Expose", "ConfigureNotify"] });
        },
        handleEvent: function(event) {
            switch (event.type) {
            case "ConfigureNotify":
                return this.configureNotify(event);
            case "Expose":
                return this.expose(event);
            }
        },
        configureNotify: function(event) {
            if (event.windowId !== this.windowId)
                return;

            if (event.x !== undefined)
                this.x = event.x;
            if (event.y !== undefined)
                this.y = event.y;
            if (event.width !== undefined)
                this.width = event.width;
            if (event.height !== undefined)
                this.height = event.height;
        },
        invalidate: function() {
            this._server.invalidateWindow({ windowId: this.windowId });
        },
        _drawBackground: function(event) {
            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.fillStyle = event.backgroundColor;
                ctx.fillRect(0, 0, this.width, this.height);
            }.bind(this));
        },
        expose: function(event) {
            this._drawBackground(event);
            this.clearDamage();
        },
        map: function() {
            this._server.mapWindow({ windowId: this.windowId });
        },
        moveResize: function(x, y, width, height) {
            this._server.configureWindow({ windowId: this.windowId, x: x, y: y, width: width, height: height });
        },
        changeProperty: function(name, value) {
            this._server.changeProperty({ windowId: this.windowId, name: name, value: value });
        },
        clearDamage: function() {
            var region = new Region();
            region.init_rect(0, 0, this.width, this.height);
            this._server.clearDamage({ windowId: this.windowId,
                                       region: region });
            region.finalize();
        },
    });

    var ImageWindow = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);
            this._image = new Image();
            this._image.addEventListener("load", function() {
                this._loaded = true;
                this.moveResize(undefined, undefined, this._image.width, this._image.height);
            }.bind(this));
        },
        _setImage: function(src) {
            this._loaded = false;
            this._image.src = src;
        },
        configureNotify: function(event) {
            this.parent(event);
            this.invalidate();
        },
        expose: function(event) {
            this._drawBackground(event);

            if (!this._loaded)
                return;

            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.drawImage(this._image, 0, 0, this.width, this.height);
            }.bind(this));
            this.clearDamage();
        },
    });

    var BackgroundWindow = new Class({
        Extends: ImageWindow,
        connect: function(server) {
            this.parent(server);
            this._server.changeAttributes({ windowId: this.windowId, overrideRedirect: true });
            this._setImage("demo/data/background.jpg");
        },
    });

    var Panel = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);
            this._launchers = [];
            this._server.selectInput({ windowId: this._server.rootWindowId,
                                       events: ["ConfigureNotify"] });
            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#eeeeec" });
            this.changeProperty("_NET_WM_WINDOW_TYPE", "_NET_WM_WINDOW_TYPE_DOCK");

            this._syncSize();
        },
        _syncSize: function() {
            var rootWindowGeometry = this._server.getGeometry({ windowId: this._server.rootWindowId });
            this.moveResize(undefined, undefined, rootWindowGeometry.width, 30);
        },
        _relayout: function() {
            var padding = 4;
            var x = padding;
            this._launchers.forEach(function(launcher) {
                launcher.moveResize(x, padding, undefined, undefined);
                x += launcher.width + padding;
            });
        },
        configureNotify: function(event) {
            this.parent(event);
            if (event.windowId === this._server.rootWindowId) {
                this._syncSize();
                this._relayout();
            } else if (event.windowId !== this.windowId && event.width !== undefined) {
                this._relayout();
            }
        },
        addLauncher: function(launcher) {
            this._launchers.push(launcher);
            this._server.selectInput({ windowId: launcher.windowId,
                                       events: ["ConfigureNotify"] });
            this._server.reparentWindow({ windowId: launcher.windowId,
                                          newParentId: this.windowId });
            this._relayout();
        },
        removeLauncher: function(launcher) {
            var idx = this._launchers.indexOf(launcher);
            // XXX -- way to unselect for input
            this._server.reparentWindow({ windowId: launcher.windowId,
                                          newParentId: this._server.rootWindowId });
            this._launchers.splice(idx, 1);
        },
        expose: function(event) {
            this._drawBackground(event);

            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.strokeStyle = '#aaaaaa';
                ctx.lineWidth = 1;
                ctx.beginPath();
                ctx.rect(-1, 0, this.width + 2, this.height);
                ctx.stroke();
            }.bind(this));
        },
    });

    var Launcher = new Class({
        Extends: ImageWindow,
        initialize: function(imageSrc, constructor) {
            this.parent(imageSrc);
            this._imageSrc = imageSrc;
            this._constructor = constructor;
        },
        connect: function(server) {
            this.parent(server);
            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#eeeeec",
                                            cursor: "pointer" });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["ButtonPress"] });
            this._setImage(this._imageSrc);
        },
        _launchApp: function() {
            var client = new this._constructor();
            client.connect(this._privateServer);
            client.map();
        },
        handleEvent: function(event) {
            switch (event.type) {
            case "ButtonPress":
                return this._launchApp();
            default:
                return this.parent(event);
            }
        },
    });

    var FakeTerminalWindow = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);
            this._focused = false;
            this._buffer = "";
            this._server.configureWindow({ windowId: this.windowId,
                                           width: 700, height: 400 });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["KeyPress"] });
            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#121212" });
            this.changeProperty("WM_NAME", "Fake Terminal");
        },
        handleEvent: function(event) {
            switch(event.type) {
            case "KeyPress":
                return this._handleKeyPress(event);
            default:
                return this.parent(event);
            }
        },
        expose: function(event) {
            this._drawBackground(event);

            this._server.drawWithContext(this.windowId, function(ctx) {
                ctx.font = 'bold 10pt "Droid Sans Mono Dotted"';

                var x = 4, y = 16;
                function drawText(text) {
                    var metrics = ctx.measureText(text);
                    ctx.fillText(text, x, y);
                    x += metrics.width;
                }

                ctx.fillStyle = '#8ae234';
                drawText("jstpierre@jstpierre-lappy");

                ctx.fillStyle = '#729fcf';
                drawText(" ~ $ ");

                ctx.fillStyle = '#eeeeec';
                drawText(this._buffer);
            }.bind(this));
            this.clearDamage();
        },
        _handleKeyPress: function(event) {
            this._buffer += String.fromCharCode(event.charCode);
            this.invalidate();
        },
    });

    function ellipse(ctx, x, y, rx, ry) {
        x -= rx;
        y -= ry;

        var kappa = .5522848;
        var ox = rx * kappa;
        var oy = ry * kappa;
        var xe = x + rx * 2;
        var ye = y + ry * 2;
        var xm = x + rx;
        var ym = y + ry;

        ctx.beginPath();
        ctx.moveTo(x, ym);
        ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
        ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
        ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
        ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
        ctx.closePath();
    }

    var Xeyes = new Class({
        Extends: Window,
        connect: function(server) {
            this.parent(server);

            this._pixmapId = 0;

            this._server.changeAttributes({ windowId: this.windowId,
                                            backgroundColor: "#eeeeec" });
            this._server.selectInput({ windowId: this.windowId,
                                       events: ["MapNotify", "UnmapNotify"] });
            this.moveResize(undefined, undefined, 200, 150);
            this.changeProperty("WM_NAME", "xeyes.js");
        },
        _start: function() {
            this._intervalId = setInterval(function() {
                this.invalidate();
            }.bind(this), 50);
        },
        _stop: function() {
            clearInterval(this._intervalId);
            this._intervalId = 0;
        },
        _destroyPixmap: function() {
            this._server.freePixmap({ pixmapId: this._pixmapId });
            this._pixmapId = 0;
        },
        _ensurePixmap: function() {
            if (this._pixmapId)
                return;

            this._pixmapId = this._server.createPixmap({ width: this.width,
                                                         height: this.height });

            var eyeRX = this.width / 4 - 6;
            var eyeRY = this.height / 2 - 6;
            var eyeCenterLX = this.width * (1/4);
            var eyeCenterRX = this.width * (3/4);
            var eyeCenterY = this.height / 2;

            this._server.drawWithContext(this._pixmapId, function(ctx) {
                ctx.clearRect(0, 0, this.width, this.height);

                ctx.strokeStyle = '#000000';
                ctx.lineWidth = 4;
                ctx.fillStyle = '#ffffff';

                // scleras
                ellipse(ctx, eyeCenterLX, eyeCenterY, eyeRX, eyeRY);
                ctx.fill();
                ctx.stroke();

                ellipse(ctx, eyeCenterRX, eyeCenterY, eyeRX, eyeRY);
                ctx.fill();
                ctx.stroke();
            }.bind(this));
        },
        configureNotify: function(event) {
            this.parent(event);
            this._destroyPixmap();
            this.invalidate();
        },
        handleEvent: function(event) {
            switch(event.type) {
            case "MapNotify":
                return this._start();
            case "UnmapNotify":
                return this._stop();
            default:
                return this.parent(event);
            }
        },
        expose: function(event) {
            this._drawBackground(event);

            this._ensurePixmap();

            var eyeRX = this.width / 4 - 6;
            var eyeRY = this.height / 2 - 6;
            var eyeCenterLX = this.width * (1/4);
            var eyeCenterRX = this.width * (3/4);
            var eyeCenterY = this.height / 2;

            var pupilRX = eyeRX / 2;
            var pupilRY = eyeRY / 2;

            var pointer = this._server.queryPointer();
            var pointerCoords = this._server.translateCoordinates({ srcWindowId: this._server.rootWindowId,
                                                                    destWindowId: this.windowId,
                                                                    x: pointer.rootX, y: pointer.rootY });

            function hypot(x, y) {
                return Math.sqrt(x*x + y*y);
            }

            function getPupilPosition(eyeCenterX) {
                // The max distance away from the center the pupil
                // is allowed to be.
                var maxDistX = eyeRX - pupilRX;
                var maxDistY = eyeRY - pupilRY;

                // Normalize to center of eye.
                var pointerX = pointerCoords.x - eyeCenterX;
                var pointerY = pointerCoords.y - eyeCenterY;

                var distance = hypot(pointerX / maxDistX, pointerY / maxDistY);
                if (distance > 1)
                    distance = 1;

                var angle = Math.atan2(pointerY, pointerX);

                // Pupil position relative to center of eye.
                var pupilX = Math.cos(angle) * distance * maxDistX;
                var pupilY = Math.sin(angle) * distance * maxDistY;

                return { x: pupilX, y: pupilY };
            }

            this._server.copyArea({ srcDrawableId: this._pixmapId,
                                    destDrawableId: this.windowId,
                                    oldX: 0, oldY: 0, newX: 0, newY: 0,
                                    width: this.width, height: this.height });
            this._server.drawWithContext(this.windowId, function(ctx) {
                // pupils
                ctx.fillStyle = '#000000';

                var pos;

                pos = getPupilPosition(eyeCenterLX);
                ellipse(ctx, eyeCenterLX + pos.x, eyeCenterY + pos.y, pupilRX, pupilRY);
                ctx.fill();

                pos = getPupilPosition(eyeCenterRX);
                ellipse(ctx, eyeCenterRX + pos.x, eyeCenterY + pos.y, pupilRX, pupilRY);
                ctx.fill();
            });
            this.clearDamage();
        },
    });

    var server = new Server();
    document.querySelector(".server").appendChild(server.elem);

    var wm = new WindowManager();
    wm.connect(server);

    var w = new BackgroundWindow();
    w.connect(server);
    w.map();

    var panel = new Panel();
    panel.connect(server);
    panel.map();

    var launcher;

    launcher = new Launcher("demo/data/launcher-terminal.png", FakeTerminalWindow);
    launcher.connect(server);
    panel.addLauncher(launcher);
    launcher.map();

    launcher = new Launcher("demo/data/launcher-xeyes.png", Xeyes);
    launcher.connect(server);
    panel.addLauncher(launcher);
    launcher.map();

    window.server = server;

    function syncSize() {
        var width = document.documentElement.clientWidth;
        var height = document.documentElement.clientHeight;
        server.resize(width, height);
    }

    window.addEventListener("resize", syncSize);
    syncSize();

})(window);
<|endoftext|>


<commit_before>(function($) {
    $(function() {

        function Transition() {
            // Define a custom transition class, using js pseudo-inheritance to
            // inherit methods from Hashban.DefaultTransition

            // Apply the parent's constructor
            Hashban.DefaultTransition.apply(this, arguments);

            // Provide custom transition_in behaviour
            this.transition_in = function(new_content, contentBody) {
                // slide the new content up
                this.old_content.remove();
                new_content.css({
                    position: 'relative',
                    top: 1000
                }).show().animate({
                    top: 0
                }, 300);

                // swap in the new header
                $('#header h1').css('position', 'relative').animate({
                    left: '-2000px'
                }, 300).queue(function(next) {
                    $(this).html(contentBody.find('#header h1').html()).css({
                        left: '2000px'
                    });
                    next();
                }).animate({
                    left: 0
                }, 300);
            };

            // Other functions which could be overridden:
            // this.should_use = function() {
            //     // return a bool
            // };
            // this.transition_out = function(endfade) {
            //     // perform out transition then call endfade callback
            // };
        };
        // Inherit non-overridden methods from parent
        Transition.prototype = new Hashban.DefaultTransition();

        function content_links() {
            hashban.hijack($('#content'));
        };

        var hashban_options = {
                contentWrapSelector: '#content',
                transitions: [Transition],
                content_init: content_links
            },
            hashban = Hashban(hashban_options);
        hashban.hijack($('#header nav'));
        hashban.bind();
        content_links();
    });
})(jQuery);<commit_msg>demo change<commit_after>(function($) {
    $(function() {

        function Transition() {
            // Define a custom transition class, using js pseudo-inheritance to
            // inherit methods from Hashban.DefaultTransition

            // Apply the parent's constructor
            Hashban.DefaultTransition.apply(this, arguments);

            // Provide custom transition_in behaviour
            this.transition_in = function(new_content, contentBody) {
                // reveal the new content
                this.old_content.remove();
                new_content.fadeIn();

                // swap in the new header
                $('#header h1').css('position', 'relative').animate({
                    left: '-2000px'
                }, 300).queue(function(next) {
                    $(this).html(contentBody.find('#header h1').html()).css({
                        left: '2000px'
                    });
                    next();
                }).animate({
                    left: 0
                }, 300);
            };

            // Other functions which could be overridden:
            // this.should_use = function() {
            //     // return a bool
            // };
            // this.transition_out = function(endfade) {
            //     // perform out transition then call endfade callback
            // };
        };
        // Inherit non-overridden methods from parent
        Transition.prototype = new Hashban.DefaultTransition();

        function content_links() {
            hashban.hijack($('#content'));
        };

        var hashban_options = {
                contentWrapSelector: '#content',
                transitions: [Transition],
                content_init: content_links
            },
            hashban = Hashban(hashban_options);
        hashban.hijack($('#header nav'));
        hashban.bind();
        content_links();
    });
})(jQuery);<|endoftext|>


<commit_before>import URI, {isDNSDomain, parseMailbox} from "https://cdn.jsdelivr.net/gh/wizard04wsu/URI_Parsing@jsfiddle-demo/src/uri_parsing.mjs"

document.getElementById("parse_scheme").addEventListener("click", ()=>{
	let val = document.getElementById("uri").value;
	console.group("scheme");
	try{
		let obj = URI(val);
		console.log("--> "+obj.toString());
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.error(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);

document.getElementById("parse_generic").addEventListener("click", ()=>{
	let val = document.getElementById("uri").value;
	console.group("generic");
	try{
		let obj = URI.parse(val)
		console.log("--> "+obj.toString());
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.error(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);

document.getElementById("parse_mailbox").addEventListener("click", ()=>{
	let val = document.getElementById("email").value;
	console.group("email");
	try{
		let obj = parseMailbox(val);
		console.log("--> "+obj.toString());
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.log(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);
<commit_msg>Update demo.js<commit_after>import URI, {isDNSDomain, parseMailbox} from "https://cdn.jsdelivr.net/gh/wizard04wsu/URI_Parsing@jsfiddle-demo/src/uri_parsing.mjs"

document.getElementById("parse_scheme").addEventListener("click", ()=>{
	let val = document.getElementById("uri").value;
	console.group("scheme");
	try{
		let obj = URI(val);
		console.log("--> "+(obj?obj.toString():obj));
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.error(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);

document.getElementById("parse_generic").addEventListener("click", ()=>{
	let val = document.getElementById("uri").value;
	console.group("generic");
	try{
		let obj = URI.parse(val)
		console.log("--> "+(obj?obj.toString():obj));
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.error(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);

document.getElementById("parse_mailbox").addEventListener("click", ()=>{
	let val = document.getElementById("email").value;
	console.group("email");
	try{
		let obj = parseMailbox(val);
		console.log("--> "+(obj?obj.toString():obj));
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.log(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);
<|endoftext|>


<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import webpack from 'webpack';
import merge from 'webpack-merge';

import path from 'path';

import commonCfg from './webpack.common';

import ExtractTextPlugin from 'extract-text-webpack-plugin';

const backendPort = process.env.BACKEND_PORT || 3000;
const devServerPort = process.env.PORT || 9000;
const devServerHost = process.env.HOST || '0.0.0.0';

export default merge(commonCfg, {
    mode: 'development',
    devtool: 'source-map',
    watch: true,
    module: {
        exprContextCritical: false,
        rules: [
            {
                test: /\.css$/,
                use: ['style', 'css']
            },
            {
                test: /\.scss$/,
                // Version without extract plugin fails on some machines. https://github.com/sass/node-sass/issues/1895
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: 'css',
                            options: {
                                sourceMap: true
                            }
                        },
                        {
                            loader: 'sass',
                            options: {
                                sourceMap: true
                            }
                        }
                    ]
                })
            }
        ]
    },
    devServer: {
        compress: true,
        historyApiFallback: true,
        disableHostCheck: true,
        contentBase: path.resolve('build'),
        // hot: true,
        inline: true,
        proxy: {
            '/socket.io': {
                target: `http://localhost:${backendPort}`,
                ws: true
            },
            '/agents': {
                target: `http://localhost:${backendPort}`,
                ws: true
            },
            '/api/v1/*': {
                target: `http://localhost:${backendPort}`
            }
        },
        watchOptions: {
            aggregateTimeout: 1000,
            poll: 2000
        },
        stats: 'errors-only',
        host: devServerHost,
        port: devServerPort
    }
});
<commit_msg>IGNITE-8556 Web Console: Relaxed DEV mode for Webpack.<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import webpack from 'webpack';
import merge from 'webpack-merge';

import path from 'path';

import commonCfg from './webpack.common';

import ExtractTextPlugin from 'extract-text-webpack-plugin';

const backendPort = process.env.BACKEND_PORT || 3000;
const devServerPort = process.env.PORT || 9000;
const devServerHost = process.env.HOST || '0.0.0.0';

export default merge(commonCfg, {
    mode: 'development',
    devtool: 'source-map',
    watch: true,
    module: {
        exprContextCritical: false,
        rules: [
            {
                test: /\.css$/,
                use: ['style', 'css']
            },
            {
                test: /\.scss$/,
                // Version without extract plugin fails on some machines. https://github.com/sass/node-sass/issues/1895
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: 'css',
                            options: {
                                sourceMap: true
                            }
                        },
                        {
                            loader: 'sass',
                            options: {
                                sourceMap: true
                            }
                        }
                    ]
                })
            }
        ]
    },
    devServer: {
        headers: {
            'Content-Security-Policy': `script-src 'self' 'unsafe-inline' 'unsafe-eval' data: http: https:;`
        },
        compress: true,
        historyApiFallback: true,
        disableHostCheck: true,
        contentBase: path.resolve('build'),
        // hot: true,
        inline: true,
        proxy: {
            '/socket.io': {
                target: `http://localhost:${backendPort}`,
                ws: true
            },
            '/agents': {
                target: `http://localhost:${backendPort}`,
                ws: true
            },
            '/api/*': {
                target: `http://localhost:${backendPort}`
            }
        },
        watchOptions: {
            aggregateTimeout: 1000,
            poll: 2000
        },
        stats: 'errors-only',
        host: devServerHost,
        port: devServerPort
    }
});
<|endoftext|>


<commit_before>'use strict';

const { Model } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
  class <%= name %> extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate (models) {
      // define association here
    }
  };

  <%= name %>.init({
    <% attributes.forEach(function(attribute, index) { %>
      <%= attribute.fieldName %>: DataTypes.<%= attribute.dataFunction ? `${attribute.dataFunction.toUpperCase()}(DataTypes.${attribute.dataType.toUpperCase()})` : attribute.dataValues ? `${attribute.dataType.toUpperCase()}(${attribute.dataValues})` : attribute.dataType.toUpperCase() %>
      <%= (Object.keys(attributes).length - 1) > index ? ',' : '' %>
    <% }) %>
  }, {
    sequelize,
    modelName: '<%= name %>',
    <%= underscored ? 'underscored: true,' : '' %>
  });

  return <%= name %>;
};
<commit_msg>style: remove unnecessary semicolon (#930)<commit_after>'use strict';

const { Model } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
  class <%= name %> extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate (models) {
      // define association here
    }
  }

  <%= name %>.init({
    <% attributes.forEach(function(attribute, index) { %>
      <%= attribute.fieldName %>: DataTypes.<%= attribute.dataFunction ? `${attribute.dataFunction.toUpperCase()}(DataTypes.${attribute.dataType.toUpperCase()})` : attribute.dataValues ? `${attribute.dataType.toUpperCase()}(${attribute.dataValues})` : attribute.dataType.toUpperCase() %>
      <%= (Object.keys(attributes).length - 1) > index ? ',' : '' %>
    <% }) %>
  }, {
    sequelize,
    modelName: '<%= name %>',
    <%= underscored ? 'underscored: true,' : '' %>
  });

  return <%= name %>;
};
<|endoftext|>


<commit_before>/* exported ArticlesForSetCrossSection */

// Copyright 2016 Endless Mobile, Inc.

const Actions = imports.app.actions;
const Dispatcher = imports.app.dispatcher;
const Module = imports.app.interfaces.module;
const SetObjectModel = imports.search.setObjectModel;
const QueryObject = imports.search.queryObject;
const Xapian = imports.app.modules.selection.xapian;

const ArticlesForSetCrossSection = new Module.Class({
    Name: 'Selection.ArticlesForSetCrossSection',
    Extends: Xapian.Xapian,

    _init: function (props={}) {
        this.parent(props);
        this._set_needs_refresh(true);
    },

    // Selection.Xapian implementation
    on_history_changed: function (history) {
        let item = history.get_current_item();
        if (item.model instanceof SetObjectModel.SetObjectModel &&
            item.model !== this._current_set) {
            this._current_set = item.model;
            this._set_needs_refresh(true);
        }
    },

    construct_query_object: function (limit, query_index) {
        if (query_index > 0)
            return null;
        let tags = this.model.child_tags.concat(['EknArticleObject']);
        if (this._current_set)
            tags = tags.concat(this._current_set.child_tags);
        return new QueryObject.QueryObject({
            limit: limit,
            tags_match_all: tags,
            sort: QueryObject.QueryObjectSort.SEQUENCE_NUMBER,
        });
    },

    show_more: function () {
        Dispatcher.get_default().dispatch({
            action_type: Actions.ITEM_CLICKED,
            model: this.model,
            context_label: this.model.title,
        });
    },
});
<commit_msg>articlesForSetCrossSection: use current-set from history store<commit_after>/* exported ArticlesForSetCrossSection */

// Copyright 2016 Endless Mobile, Inc.

const Actions = imports.app.actions;
const Dispatcher = imports.app.dispatcher;
const HistoryStore = imports.app.historyStore;
const Module = imports.app.interfaces.module;
const QueryObject = imports.search.queryObject;
const Xapian = imports.app.modules.selection.xapian;

const ArticlesForSetCrossSection = new Module.Class({
    Name: 'Selection.ArticlesForSetCrossSection',
    Extends: Xapian.Xapian,

    _init: function (props={}) {
        this.parent(props);
        this._set_needs_refresh(true);
        HistoryStore.get_default().connect('notify::current-set', () => {
            this._set_needs_refresh(true);
        });
    },

    construct_query_object: function (limit, query_index) {
        if (query_index > 0)
            return null;
        let tags = this.model.child_tags.concat(['EknArticleObject']);
        let current_set = HistoryStore.get_default().current_set;
        if (current_set)
            tags = tags.concat(current_set.child_tags);
        return new QueryObject.QueryObject({
            limit: limit,
            tags_match_all: tags,
            sort: QueryObject.QueryObjectSort.SEQUENCE_NUMBER,
        });
    },

    show_more: function () {
        Dispatcher.get_default().dispatch({
            action_type: Actions.ITEM_CLICKED,
            model: this.model,
            context_label: this.model.title,
        });
    },
});
<|endoftext|>


<commit_before>var fs = require("fs-extra");
var localPath = require("helper").localPath;
var async = require("async");
var HOSTS = process.env.BLOT_DIRECTORY + "/data/hosts";

module.exports = function(blogID, add, remove, callback) {
  var blogFolder = localPath(blogID, "/").slice(0, -1);
  var staticFolder = process.env.BLOT_DIRECTORY + "/static/" + blogID;

  async.parallel([addSymlinks, removeSymlinks], callback);

  function addSymlinks(done) {
    var links = [];
    var dirs = [blogFolder, staticFolder];

    add.forEach(function(host) {
      dirs.push(HOSTS + "/" + host);
      links.push({ from: blogFolder, to: HOSTS + "/" + host + "/folder" });
      links.push({ from: staticFolder, to: HOSTS + "/" + host + "/static" });
    });

    async.each(dirs, fs.ensureDir, function(err) {
      if (err) return done(err);

      async.each(
        links,
        function(link, next) {
          fs.symlink(link.from, link.to, function(err) {
            if (err && err.code !== "EEXIST") return next(err);
            next();
          });
        },
        done
      );
    });
  }

  function removeSymlinks(done) {
    async.each(
      remove,
      function(host, next) {
        fs.remove(HOSTS + "/" + host, next);
      },
      done
    );
  }
};
<commit_msg>Added comments<commit_after>// The purpose of this module is to set up a number of symlinks between the blogs
// folder stored againsts its ID, e.g. blogs/XYZ and its host, e.g. data/hosts/example.com
// This is designed to allow NGINX to serve static content without a way to lookup the
// blog by ID, and will take load off the Node.js server
var fs = require("fs-extra");
var localPath = require("helper").localPath;
var async = require("async");
var HOSTS = process.env.BLOT_DIRECTORY + "/data/hosts";

if (!process.env.BLOT_DIRECTORY)
  throw new Error("Please declare a BLOT_DIRECTORY environment variable");

module.exports = function(blogID, add, remove, callback) {
  var blogFolder = localPath(blogID, "/").slice(0, -1);
  var staticFolder = process.env.BLOT_DIRECTORY + "/static/" + blogID;

  async.parallel([addSymlinks, removeSymlinks], callback);

  function addSymlinks(done) {
    var links = [];
    var dirs = [blogFolder, staticFolder];

    add.forEach(function(host) {
      dirs.push(HOSTS + "/" + host);
      links.push({ from: blogFolder, to: HOSTS + "/" + host + "/folder" });
      links.push({ from: staticFolder, to: HOSTS + "/" + host + "/static" });
    });

    async.each(dirs, fs.ensureDir, function(err) {
      if (err) return done(err);

      async.each(
        links,
        function(link, next) {
          fs.symlink(link.from, link.to, function(err) {
            if (err && err.code !== "EEXIST") return next(err);
            next();
          });
        },
        done
      );
    });
  }

  function removeSymlinks(done) {
    async.each(
      remove,
      function(host, next) {
        fs.remove(HOSTS + "/" + host, next);
      },
      done
    );
  }
};
<|endoftext|>