diff --git a/packages/driver-worker/CHANGELOG.md b/packages/driver-worker/CHANGELOG.md
deleted file mode 100644
index 1f9cb21164..0000000000
--- a/packages/driver-worker/CHANGELOG.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Changelog
-
-## v0.7.11
-
-- Chore: add `@babel/runtime` as dependency
diff --git a/packages/driver-worker/README.md b/packages/driver-worker/README.md
deleted file mode 100644
index b2485bc568..0000000000
--- a/packages/driver-worker/README.md
+++ /dev/null
@@ -1,35 +0,0 @@
-# driver-worker
-
-> Worker driver for Rax.
-
-## Install
-
-```bash
-$ npm install --save driver-worker
-```
-
-## Usage
-
-`worker.js`
-```js
-import createDriver from 'driver-worker';
-import { render } from 'rax';
-import App from './App';
-
-render(
-
- null,
- {
- driver: createDriver({ postMessage, addEventListener })
- }
-);
-```
-
-`index.js`
-```js
-import domRenderer from 'driver-worker/lib/renderer';
-import spawnWorker from 'worker-loader?inline!./worker.js';
-
-const worker = spawnWorker();
-domRenderer({ worker });
-```
diff --git a/packages/driver-worker/package.json b/packages/driver-worker/package.json
deleted file mode 100644
index e676c7b347..0000000000
--- a/packages/driver-worker/package.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "name": "driver-worker",
- "version": "0.7.11",
- "description": "Worker driver for Rax",
- "license": "BSD-3-Clause",
- "main": "dist/driver-worker.min.js",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/alibaba/rax.git"
- },
- "bugs": {
- "url": "https://github.com/alibaba/rax/issues"
- },
- "homepage": "https://github.com/alibaba/rax#readme",
- "dependencies": {
- "style-unit": "^3.0.0",
- "@babel/runtime": "^7.14.6"
- },
- "devDependencies": {
- "rax": "^0.6.7"
- }
-}
diff --git a/packages/driver-worker/src/Driver.js b/packages/driver-worker/src/Driver.js
deleted file mode 100644
index e36e4df429..0000000000
--- a/packages/driver-worker/src/Driver.js
+++ /dev/null
@@ -1,208 +0,0 @@
-import { convertUnit, setDecimalPixelTransformer, setRpx } from 'style-unit';
-
-const CLASS_NAME = 'className';
-const CLASS = 'class';
-const STYLE = 'style';
-const CHILDREN = 'children';
-const EVENT_PREFIX_REGEXP = /^on[A-Z]/;
-const ADD_EVENT = 'addEvent';
-const REMOVE_EVENT = 'removeEvent';
-const EMPTY_CONTENT = '';
-
-/**
- * Implement rax driver interface for worker driver
- */
-export default class Driver {
- deviceWidth = null;
- viewportWidth = 750;
- eventRegistry = {};
-
- constructor(document) {
- this.document = document;
- }
-
- getDeviceWidth() {
- return this.deviceWidth || this.document.documentElement.clientWidth;
- }
-
- setDeviceWidth(width) {
- this.deviceWidth = width;
- }
-
- getViewportWidth() {
- return this.viewportWidth;
- }
-
- setViewportWidth(width) {
- this.viewportWidth = width;
- }
-
- getElementById(id) {
- return this.document.getElementById(id);
- }
-
- createBody() {
- const { document } = this;
- return document.body;
- }
-
- createComment(content) {
- const { document } = this;
- return document.createComment(content);
- }
-
- createEmpty() {
- return this.createComment(EMPTY_CONTENT);
- }
-
- createText(text) {
- return this.document.createTextNode(text);
- }
-
- updateText(node, text) {
- node.textContent = text;
- }
-
- createElement(component) {
- let node = this.document.createElement(component.type);
- let props = component.props;
-
- this.setNativeProps(node, props);
-
- return node;
- }
-
- appendChild(node, parent) {
- return parent.appendChild(node);
- }
-
- removeChild(node, parent) {
- parent = parent || node.parentNode;
- // Maybe has been removed when remove child
- if (parent) {
- parent.removeChild(node);
- }
- }
-
- replaceChild(newChild, oldChild, parent) {
- parent = parent || oldChild.parentNode;
- if (parent) parent.replaceChild(newChild, oldChild);
- }
-
- insertAfter(node, after, parent) {
- parent = parent || after.parentNode;
- const nextSibling = after.nextSibling;
- if (nextSibling) {
- parent.insertBefore(node, nextSibling);
- } else {
- parent.appendChild(node);
- }
- }
-
- insertBefore(node, before, parent) {
- parent = parent || before.parentNode;
- parent.insertBefore(node, before);
- }
-
- addEventListener(node, eventName, eventHandler, props) {
- if (this.eventRegistry[eventName]) {
- return this.eventRegistry[eventName](
- ADD_EVENT,
- node,
- eventName,
- eventHandler,
- props
- );
- } else {
- return node.addEventListener(eventName, eventHandler);
- }
- }
-
- removeEventListener(node, eventName, eventHandler, props) {
- if (this.eventRegistry[eventName]) {
- return this.eventRegistry[eventName](
- REMOVE_EVENT,
- node,
- eventName,
- eventHandler,
- props
- );
- } else {
- return node.removeEventListener(eventName, eventHandler);
- }
- }
-
- removeAllEventListeners(node) {
- node._eventListeners = {};
- }
-
- removeAttribute(node, propKey) {
- if (propKey === CLASS_NAME) {
- propKey = CLASS;
- }
-
- if (propKey in node) {
- try {
- // Some node property is readonly when in strict mode
- node[propKey] = null;
- } catch (e) { }
- }
-
- node.removeAttribute(propKey);
- }
-
- setAttribute(node, propKey, propValue) {
- if (propKey === CLASS_NAME) {
- propKey = CLASS;
- }
-
- if (propKey in node) {
- try {
- // Some node property is readonly when in strict mode
- node[propKey] = propValue;
- } catch (e) {
- node.setAttribute(propKey, propValue);
- }
- } else {
- node.setAttribute(propKey, propValue);
- }
- }
-
- setStyles(node, styles) {
- let newStyles = node.style;
-
- for (let prop in styles) {
- let val = styles[prop];
- newStyles[prop] = convertUnit(val, prop);
- }
- // Assign to style for trigger style update
- node.style = newStyles;
- }
-
- beforeRender() {
- // Init rem unit
- const rpxRadio = this.getDeviceWidth() / this.getViewportWidth();
- setRpx(rpxRadio);
- setDecimalPixelTransformer((rpx) => Math.floor(parseFloat(rpx) * rpxRadio) + 'px');
- }
-
- setNativeProps(node, props) {
- for (let prop in props) {
- let value = props[prop];
- if (prop === CHILDREN) {
- continue;
- }
-
- if (value != null) {
- if (prop === STYLE) {
- this.setStyles(node, value);
- } else if (EVENT_PREFIX_REGEXP.test(prop)) {
- let eventName = prop.slice(2).toLowerCase();
- this.addEventListener(node, eventName, value);
- } else {
- this.setAttribute(node, prop, value);
- }
- }
- }
- }
-}
diff --git a/packages/driver-worker/src/WorkerDriver.js b/packages/driver-worker/src/WorkerDriver.js
deleted file mode 100644
index 87b88d5cee..0000000000
--- a/packages/driver-worker/src/WorkerDriver.js
+++ /dev/null
@@ -1,203 +0,0 @@
-import createWorkerGlobalScope from './worker/createWorkerGlobalScope';
-import Evaluator from './worker/Evaluator';
-import Event from './worker/Event';
-import Driver from './Driver';
-import memorized from './shared/memorized';
-
-const ELEMENT_NODE = 1;
-const TEXT_NODE = 3;
-const COMMENT_NODE = 8;
-const BODY = 'BODY';
-const IS_TOUCH_EVENTS = /^touch/;
-const TO_SANITIZE = [
- 'target',
- 'addedNodes',
- 'removedNodes',
- 'nextSibling',
- 'previousSibling',
-];
-const isTouchEvent = memorized((type) => IS_TOUCH_EVENTS.test(type));
-
-export default class WorkerDriver extends Driver {
- constructor(options = {}) {
- const { postMessage, addEventListener } = options;
- const workerGlobalScope = createWorkerGlobalScope();
- super(workerGlobalScope.document);
-
- this.evaluator = new Evaluator(postMessage);
- this.nodesMap = new Map();
- this.nodeCounter = 0;
-
- let mutationObserver = this.createMutationObserver(postMessage);
- mutationObserver.observe(this.document, { subtree: true });
-
- addEventListener('message', this.handleMessage);
- }
-
- createMutationObserver(callback) {
- const MutationObserver = this.document.defaultView.MutationObserver;
- return new MutationObserver(mutations => {
- for (let i = mutations.length; i--;) {
- let mutation = mutations[i];
- for (let j = TO_SANITIZE.length; j--;) {
- let prop = TO_SANITIZE[j];
- const value = this.sanitize(mutation[prop], prop);
- if (value) mutation[prop] = value;
- }
- }
-
- callback({
- type: 'MutationRecord',
- mutations: this.optimizeMutations(mutations),
- });
- });
- }
-
- /**
- * Reduce size of mutations, exclude empty operation.
- */
- optimizeMutations(mutations) {
- const ret = [];
- for (let i = 0, l = mutations.length; i < l; i++) {
- const mutation = mutations[i];
-
- if (mutation.type === 'childList') {
- if (mutation.hasOwnProperty('addedNodes')
- && mutation.addedNodes.length === 0) {
- continue;
- }
-
- if (mutation.hasOwnProperty('removedNodes')
- && mutation.removedNodes.length === 0) {
- continue;
- }
- }
-
- ret.push(mutation);
- }
- return ret;
- }
-
- /**
- * Event `message' listener.
- */
- handleMessage = ({ data }) => {
- const document = this.document;
- switch (data.type) {
- case 'init':
- document.URL = data.url;
- document.documentElement.clientWidth = data.width;
- break;
- case 'event':
- this.handleEvent(data.event);
- break;
- case 'return':
- this.handleReturn(data.return);
- break;
- }
- };
-
- /**
- * Serialize instruction.
- */
- sanitize(node, prop) {
- if (!node || typeof node !== 'object') {
- return node;
- }
-
- if (Array.isArray(node)) {
- let ret = [];
- for (let i = 0, l = node.length; i < l; i ++) {
- const sanitized = this.sanitize(node[i], prop);
- if (sanitized !== null) ret.push(sanitized);
- }
- return ret;
- }
-
- if (!node.$$id) {
- node.$$id = String(++this.nodeCounter);
- this.nodesMap.set(node.$$id, node);
- }
-
- const result = {
- $$id: node.$$id,
- };
-
- if (node.nodeName === BODY) {
- result.nodeName = BODY;
- } else if (prop === 'addedNodes') {
- const nodeType = node.nodeType;
- result.nodeType = nodeType;
-
- switch (nodeType) {
- case ELEMENT_NODE:
- result.nodeName = node.nodeName;
-
- const events = node._getEvents();
- if (events.length > 0) result.events = events;
- if (node.attributes && node.attributes.length > 0) result.attributes = node.attributes;
- if (Object.keys(node.style).length > 0) result.style = node.style;
- break;
-
- case TEXT_NODE:
- case COMMENT_NODE:
- result.data = node.data;
- break;
- }
- }
-
- return result;
- }
-
- getNode(node) {
- let id;
- if (node && typeof node === 'object') id = node.$$id;
- if (typeof node === 'string') id = node;
- if (!id) return null;
- if (node.nodeName === BODY) return this.document.body;
- return this.nodesMap.get(id);
- }
-
- handleEvent(rawEventObject) {
- const target = this.getNode(rawEventObject.target);
-
- if (target) {
- const { type } = rawEventObject;
- const event = new Event(type, rawEventObject);
-
- if (isTouchEvent(type)) {
- this.convertTouchTarget(event);
- }
-
- target.dispatchEvent(event);
- }
- }
-
- handleReturn(data) {
- this.evaluator.apply(data);
- }
-
- /**
- * Convert TouchEvent#$$id to targetNode
- */
- extractTouchListTarget(touchList) {
- for (let i = 0, l = touchList.length; i < l; i++) {
- if ('$$id' in touchList[i]) {
- touchList[i].target = this.getNode(touchList[i].$$id);
- delete touchList[i].$$id;
- }
- }
- }
-
- /**
- * Extract touches and currentTouches
- */
- convertTouchTarget(event) {
- if (event.touches) {
- this.extractTouchListTarget(event.touches);
- }
- if (event.changedTouches) {
- this.extractTouchListTarget(event.changedTouches);
- }
- }
-}
diff --git a/packages/driver-worker/src/__tests__/__snapshots__/driver.js.snap b/packages/driver-worker/src/__tests__/__snapshots__/driver.js.snap
deleted file mode 100644
index 7967786dd4..0000000000
--- a/packages/driver-worker/src/__tests__/__snapshots__/driver.js.snap
+++ /dev/null
@@ -1,251 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`driver-worker convertTouchTarget 1`] = `
-Event {
- "bubbles": false,
- "cancelable": false,
- "changedTouches": Array [
- Object {
- "target": "FOO",
- },
- ],
- "defaultPrevented": false,
- "touches": Array [
- Object {
- "target": "FOO",
- },
- ],
- "type": "touchstart",
-}
-`;
-
-exports[`driver-worker sanitize 1`] = `
-Object {
- "$$id": "1",
- "attributes": Array [
- Object {
- "name": "foo",
- "value": "bar",
- },
- ],
- "nodeName": "FOO",
- "nodeType": 1,
- "style": Object {
- "color": "red",
- },
-}
-`;
-
-exports[`driver-worker sanitize 2`] = `
-Array [
- Object {
- "$$id": "1",
- "attributes": Array [
- Object {
- "name": "foo",
- "value": "bar",
- },
- ],
- "nodeName": "FOO",
- "nodeType": 1,
- "style": Object {
- "color": "red",
- },
- },
- Object {
- "$$id": "1",
- "attributes": Array [
- Object {
- "name": "foo",
- "value": "bar",
- },
- ],
- "nodeName": "FOO",
- "nodeType": 1,
- "style": Object {
- "color": "red",
- },
- },
-]
-`;
-
-exports[`driver-worker should be drived by rax 1`] = `
-Object {
- "mutations": Array [
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "1",
- "nodeName": "VIEW",
- "nodeType": 1,
- },
- ],
- "target": Object {
- "$$id": "2",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- ],
- "type": "MutationRecord",
-}
-`;
-
-exports[`driver-worker should work with setNativeProps 1`] = `
-Object {
- "mutations": Array [
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "1",
- "attributes": Array [
- Object {
- "name": "foo",
- "value": "bar",
- },
- Object {
- "name": "number",
- "value": 0,
- },
- ],
- "events": Array [
- "click",
- ],
- "nodeName": "VIEW",
- "nodeType": 1,
- },
- ],
- "target": Object {
- "$$id": "2",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- ],
- "type": "MutationRecord",
-}
-`;
-
-exports[`driver-worker should works with dom operation 1`] = `
-Object {
- "mutations": Array [
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "6",
- "attributes": Array [
- Object {
- "name": "count",
- "value": 0,
- },
- ],
- "nodeName": "VIEW",
- "nodeType": 1,
- },
- ],
- "target": Object {
- "$$id": "3",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "1",
- "data": "empty",
- "nodeType": 8,
- },
- ],
- "target": Object {
- "$$id": "6",
- },
- "type": "childList",
- },
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "5",
- "nodeName": "BE-REMOVE",
- "nodeType": 1,
- },
- ],
- "target": Object {
- "$$id": "3",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- Object {
- "removedNodes": Array [
- Object {
- "$$id": "5",
- },
- ],
- "target": Object {
- "$$id": "3",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- Object {
- "removedNodes": Array [
- Object {
- "$$id": "5",
- },
- ],
- "target": Object {
- "$$id": "3",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "5",
- "nodeName": "BE-REMOVE",
- "nodeType": 1,
- },
- ],
- "target": Object {
- "$$id": "3",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "4",
- "nodeName": "BE-INSERT-AFTER",
- "nodeType": 1,
- },
- ],
- "target": Object {
- "$$id": "3",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- Object {
- "addedNodes": Array [
- Object {
- "$$id": "2",
- "nodeName": "BE-INSERT-BEFORE",
- "nodeType": 1,
- },
- ],
- "nextSibling": Object {
- "$$id": "1",
- },
- "target": Object {
- "$$id": "3",
- "nodeName": "BODY",
- },
- "type": "childList",
- },
- ],
- "type": "MutationRecord",
-}
-`;
diff --git a/packages/driver-worker/src/__tests__/driver.js b/packages/driver-worker/src/__tests__/driver.js
deleted file mode 100644
index 8ed6f90eaa..0000000000
--- a/packages/driver-worker/src/__tests__/driver.js
+++ /dev/null
@@ -1,230 +0,0 @@
-import { render, createElement } from 'rax';
-import Event from '../worker/Event';
-import createDriver from '../index';
-
-describe('driver-worker', () => {
- it('should be drived by rax', (done) => {
- const addEventListener = () => {};
- const postMessage = (message) => {
- expect(message).toMatchSnapshot();
- done();
- };
- const driver = createDriver({ addEventListener, postMessage });
- render(createElement('view'), null, { driver });
- });
-
- it('should works with dom operation', (done) => {
- const addEventListener = (eventName, handler) => {
- // console.log('addEventListener', eventName, handler);
- };
- const postMessage = (message) => {
- expect(message).toMatchSnapshot();
- done();
- };
- const driver = createDriver({ addEventListener, postMessage });
-
- // Create body
- const body = driver.createBody();
- // Create element
- const container = driver.createElement({ type: 'view', props: { count: 0 } });
- // Append child
- body.appendChild(container);
- // Create comment
- const comment = driver.createComment('empty');
- driver.appendChild(comment, container);
-
- // removeChild
- const toBeRemoved = driver.createElement({ type: 'be-remove' });
- body.appendChild(toBeRemoved);
- driver.removeChild(toBeRemoved, body);
-
- // replaceChild
- const toBeReplaced = driver.createElement({ type: 'be-replace' });
- const toReplace = driver.createElement({ type: 'replaced' });
- body.appendChild(toBeRemoved);
- driver.replaceChild(toReplace, toBeReplaced, body);
-
- // insertAfter
- const toBeInsertAfter = driver.createElement({ type: 'be-insert-after' });
- driver.insertAfter(toBeInsertAfter, comment, body);
-
- // insertBefore
- const toBeInsertBefore = driver.createElement({ type: 'be-insert-before' });
- driver.insertBefore(toBeInsertBefore, comment, body);
- });
-
- it('should works with device width and viewport width', () => {
- let sendMessageToWorker;
- const addEventListener = (event, handler) => {
- sendMessageToWorker = handler;
- };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
-
- // Default device width be undefined
- expect(driver.getDeviceWidth()).toBeUndefined();
-
- // Mock init event.
- sendMessageToWorker({
- data: {
- type: 'init',
- width: 100,
- },
- });
- expect(driver.getDeviceWidth()).toEqual(100);
-
- // Set device width
- driver.setDeviceWidth(200);
- expect(driver.getDeviceWidth()).toEqual(200);
-
- // Set viewport width
- driver.setViewportWidth(100);
- expect(driver.getViewportWidth()).toEqual(100);
- });
-
-
- it('shuold work with event listener API', (done) => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
-
- const body = driver.createBody();
- const onMove = (event) => {
- throw new Error('should not fire move event.');
- };
- const el = driver.createElement({
- type: 'view',
- props: {
- onMove,
- onClick: (event) => done(),
- },
- });
- body.appendChild(el);
-
- driver.removeEventListener(el, 'move', onMove);
- el.dispatchEvent({
- type: 'move',
- target: el,
- });
-
- el.dispatchEvent({
- type: 'click',
- target: el,
- });
- });
-
- it('shuold work with remove all event listeners', (done) => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
-
- const body = driver.createBody();
- const toThrow = (event) => {
- throw new Error('should not fire move event.');
- };
- const el = driver.createElement({
- type: 'view',
- props: {
- onMove: toThrow,
- onClick: toThrow,
- },
- });
- body.appendChild(el);
-
- // Remove all event listeners will not fire anymore.
- driver.removeAllEventListeners(el);
- el.dispatchEvent({
- type: 'move',
- target: el,
- });
- el.dispatchEvent({
- type: 'click',
- target: el,
- });
- done();
- });
-
- it('should work with attributes', () => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
-
- const body = driver.createBody();
- const el = driver.createElement({
- type: 'view',
- });
- body.appendChild(el);
-
- driver.setAttribute(el, 'key', 'value');
- expect(el.getAttribute('key')).toEqual('value');
- });
-
- it('should work with setNativeProps', (done) => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {
- expect(message).toMatchSnapshot();
- done();
- };
- const driver = createDriver({ addEventListener, postMessage });
-
- const body = driver.createBody();
- const el = driver.createElement({
- type: 'view',
- });
- driver.setNativeProps(el, {
- onClick: () => {},
- foo: 'bar',
- number: 0,
- });
- body.appendChild(el);
- });
-
- it('sanitize', () => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
- const el = driver.createElement({ type: 'foo' });
- el.setAttribute('foo', 'bar');
- el.style = { color: 'red' };
-
- expect(driver.sanitize(el, 'addedNodes')).toMatchSnapshot();
- expect(driver.sanitize([el, el], 'addedNodes')).toMatchSnapshot();
- });
-
- it('convertTouchTarget', () => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
- const event = new Event('touchstart');
- driver.nodesMap.set('0', 'FOO');
- const touch = {
- $$id: '0',
- };
- event.touches = [touch];
- event.changedTouches = [touch];
- driver.convertTouchTarget(event);
-
- expect(event).toMatchSnapshot();
- });
-
- it('appendChild', () => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
- const parent = driver.createElement({ type: 'parent' });
- const son = driver.createElement({ type: 'son' });
- driver.appendChild(son, parent);
- expect(son.parentNode).toEqual(parent);
- });
-
- it('removeChild', () => {
- const addEventListener = (event, handler) => { };
- const postMessage = (message) => {};
- const driver = createDriver({ addEventListener, postMessage });
- const parent = driver.createElement({ type: 'parent' });
- const son = driver.createElement({ type: 'son' });
- parent.appendChild(son);
- driver.removeChild(son, parent);
- expect(parent.childNodes.length).toEqual(0);
- });
-});
diff --git a/packages/driver-worker/src/index.js b/packages/driver-worker/src/index.js
deleted file mode 100644
index 594fdbd1f9..0000000000
--- a/packages/driver-worker/src/index.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import WorkerDriver from './WorkerDriver';
-
-/**
- * Instantiate a worker driver.
- * @param options.postMessage {Function} Tunnel for send message to renderer.
- * @param options.addEventListener {Function} Tunnel for driver to receive message.
- * @return {WorkerDriver}
- */
-export default function createDriver(options) {
- return new WorkerDriver(options);
-};
diff --git a/packages/driver-worker/src/shared/__tests__/camelCase.js b/packages/driver-worker/src/shared/__tests__/camelCase.js
deleted file mode 100644
index c440a12cf6..0000000000
--- a/packages/driver-worker/src/shared/__tests__/camelCase.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import camelCase from '../camelCase';
-
-describe('camel case', () => {
- it('should transform -foo-bar', () => {
- expect(camelCase('-foo-bar')).toBe('FooBar');
- });
-
- it('should transform foo-bar', () => {
- expect(camelCase('foo-bar')).toBe('fooBar');
- });
-
- it('should not transform foobar', () => {
- expect(camelCase('foobar')).toBe('foobar');
- });
-
- it('should not transform fooBar', () => {
- expect(camelCase('fooBar')).toBe('fooBar');
- });
-});
diff --git a/packages/driver-worker/src/shared/__tests__/kebabCase.js b/packages/driver-worker/src/shared/__tests__/kebabCase.js
deleted file mode 100644
index 9c2a100ee8..0000000000
--- a/packages/driver-worker/src/shared/__tests__/kebabCase.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import kebabCase from '../kebabCase';
-
-describe('kebab case', () => {
- it('should transform fooBar', () => {
- expect(kebabCase('fooBar')).toBe('foo-bar');
- });
-
- it('should transform FooBar', () => {
- expect(kebabCase('FooBar')).toBe('-foo-bar');
- });
-
- it('should not transform foo-bar', () => {
- expect(kebabCase('foo-bar')).toBe('foo-bar');
- });
-
- it('should not transform foobar', () => {
- expect(kebabCase('foobar')).toBe('foobar');
- });
-});
-
diff --git a/packages/driver-worker/src/shared/__tests__/memorized.js b/packages/driver-worker/src/shared/__tests__/memorized.js
deleted file mode 100644
index 5d4a66e358..0000000000
--- a/packages/driver-worker/src/shared/__tests__/memorized.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import memorized from '../memorized';
-
-describe('memorized', () => {
- it('should memory a pure function', () => {
- let count = 0;
- const fn = memorized((str) => count++);
-
- expect(fn('key')).toEqual(0);
- // Memorized by 'key'.
- expect(fn('key')).toEqual(0);
- // A new argument.
- expect(fn('foo')).toEqual(1);
- // Arguments length effects.
- expect(fn('foo', true)).toEqual(2);
- });
-});
diff --git a/packages/driver-worker/src/shared/__tests__/setImmediate.js b/packages/driver-worker/src/shared/__tests__/setImmediate.js
deleted file mode 100644
index 2894dc5a6a..0000000000
--- a/packages/driver-worker/src/shared/__tests__/setImmediate.js
+++ /dev/null
@@ -1,15 +0,0 @@
-describe('setImmediate', () => {
- beforeAll(() => {
- global._setImmediate = global.setImmediate;
- global.setImmediate = null;
- });
- afterAll(() => {
- global.setImmediate = global._setImmediate;
- delete global._setImmediate;
- });
-
- it('setImmediate', (done) => {
- const setImmediate = require('../setImmediate').default;
- setImmediate(done);
- });
-});
diff --git a/packages/driver-worker/src/shared/camelCase.js b/packages/driver-worker/src/shared/camelCase.js
deleted file mode 100644
index 5977405582..0000000000
--- a/packages/driver-worker/src/shared/camelCase.js
+++ /dev/null
@@ -1,11 +0,0 @@
-const CAMELCASE_REG = /-[a-z]/g;
-const CamelCaseCache = {};
-
-export default function camelCase(str) {
- return (
- CamelCaseCache[str] ||
- (CamelCaseCache[str] = str.replace(CAMELCASE_REG, $1 =>
- $1.slice(1).toUpperCase()
- ))
- );
-}
diff --git a/packages/driver-worker/src/shared/findWhere.js b/packages/driver-worker/src/shared/findWhere.js
deleted file mode 100644
index 3a13aa6925..0000000000
--- a/packages/driver-worker/src/shared/findWhere.js
+++ /dev/null
@@ -1,7 +0,0 @@
-export default function findWhere(arr, fn, returnIndex, byValueOnly) {
- let i = arr.length;
- while (i--)
- if (typeof fn === 'function' && !byValueOnly ? fn(arr[i]) : arr[i] === fn)
- break;
- return returnIndex ? i : arr[i];
-}
diff --git a/packages/driver-worker/src/shared/global.js b/packages/driver-worker/src/shared/global.js
deleted file mode 100644
index 0120b437e4..0000000000
--- a/packages/driver-worker/src/shared/global.js
+++ /dev/null
@@ -1,5 +0,0 @@
-const global = typeof global !== 'undefined'
- ? global : typeof self !== 'undefined'
- ? self : new Function('return this')();
-
-export default global;
diff --git a/packages/driver-worker/src/shared/kebabCase.js b/packages/driver-worker/src/shared/kebabCase.js
deleted file mode 100644
index 6503d8e132..0000000000
--- a/packages/driver-worker/src/shared/kebabCase.js
+++ /dev/null
@@ -1,20 +0,0 @@
-const KebabCache = {};
-
-export default function kebabCase(string) {
- if (KebabCache[string]) {
- return KebabCache[string];
- }
-
- let kebab = '';
- for (let i = 0, l = string.length; i < l; i++) {
- if (/[a-z]/.test(string[i])) {
- kebab += string[i];
- } else if (/[A-Z]/.test(string[i])) {
- kebab += '-' + string[i].toLowerCase();
- } else if (string[i] === '-') {
- kebab += '-';
- }
- }
-
- return KebabCache[string] = kebab;
-}
diff --git a/packages/driver-worker/src/shared/memorized.js b/packages/driver-worker/src/shared/memorized.js
deleted file mode 100644
index 926a622977..0000000000
--- a/packages/driver-worker/src/shared/memorized.js
+++ /dev/null
@@ -1,15 +0,0 @@
-const hasOwnProperty = Object.prototype.hasOwnProperty;
-/**
- * Create a memorized version of pure function.
- * @note arguments must be stringify, object or function is not acceptable.
- * @param fn {Function}
- */
-export default function memorized(fn) {
- const cache = Object.create(null);
- return function cachedFn(...args) {
- const cacheKey = args.join('|');
- return hasOwnProperty.call(cache, cacheKey)
- ? cache[cacheKey]
- : cache[cacheKey] = fn.apply(this, args);
- };
-}
diff --git a/packages/driver-worker/src/shared/requestAnimationFrame.js b/packages/driver-worker/src/shared/requestAnimationFrame.js
deleted file mode 100644
index f49076cee7..0000000000
--- a/packages/driver-worker/src/shared/requestAnimationFrame.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import global from './global';
-
-const requestAnimationFrame = global.requestAnimationFrame || function(cb) {
- return setTimeout(cb, 16);
-};
-
-export default requestAnimationFrame;
diff --git a/packages/driver-worker/src/shared/setImmediate.js b/packages/driver-worker/src/shared/setImmediate.js
deleted file mode 100644
index c38629accd..0000000000
--- a/packages/driver-worker/src/shared/setImmediate.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import global from './global';
-
-const setImmediate = global.setImmediate || function(cb) {
- return setTimeout(cb, 0);
-};
-
-export default setImmediate;
diff --git a/packages/driver-worker/src/shared/splice.js b/packages/driver-worker/src/shared/splice.js
deleted file mode 100644
index f72330b0e5..0000000000
--- a/packages/driver-worker/src/shared/splice.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import findWhere from './findWhere';
-
-export default function splice(arr, item, add, byValueOnly) {
- let i = arr ? findWhere(arr, item, true, byValueOnly) : -1;
- if (~i) add ? arr.splice(i, 0, add) : arr.splice(i, 1);
- return i;
-}
diff --git a/packages/driver-worker/src/worker/Animation.js b/packages/driver-worker/src/worker/Animation.js
deleted file mode 100644
index 529e0189e7..0000000000
--- a/packages/driver-worker/src/worker/Animation.js
+++ /dev/null
@@ -1,140 +0,0 @@
-const patchTransform = {};
-
-export function dispatchAnimationToStyle(node, animationGroup) {
- // properties aren't belonged to transform
- const notBelongedToTransform = [
- 'opacity',
- 'backgroundColor',
- 'width',
- 'height',
- 'top',
- 'left',
- 'bottom',
- 'right'
- ];
- let nextProperties = {};
- let nextTranfrom = '';
- let transformActions = [];
-
- // actions about transform
- animationGroup.animation.map(prop => {
- let [name, value] = prop;
-
- if (notBelongedToTransform.indexOf(name) > -1) {
- let unit = '';
- /**
- * Tip:
- * Currently, we are not supprt custom unit
- */
- if (['opacity', 'backgroundColor'].indexOf(name) < 0) {
- unit = 'px';
- } else if (name === 'backgroundColor') {
- name = 'background-color';
- }
-
- nextProperties[name] = value + unit;
- } else {
- transformActions.push({
- name,
- value
- });
- }
- });
-
- // match actions and update patchTransform
- transformActions.forEach(({ name, value }) => {
- let defaultVal = 0;
- let unit = '';
-
- if (/rotate[XYZ]?$/.test(name)) {
- unit = 'deg';
- }
-
- if (/translate/.test(name)) {
- unit = 'px';
- }
- // scale's defaultVal is 1
- if (/scale/.test(name)) {
- defaultVal = 1;
- }
-
- if (['rotate', 'scale', 'translate', 'skew'].indexOf(name) > -1) {
- // if the rotate only has one param, it equals to rotateZ
- if (name === 'rotate' && value.length === 1) {
- patchTransform[`${name}Z`] = (value[0] || defaultVal) + unit;
- return;
- }
-
- if (value.length === 3) {
- patchTransform[`${name}Z`] = (value[2] || defaultVal) + unit;
- }
-
- patchTransform[`${name}X`] = (value[0] || defaultVal) + unit;
- patchTransform[`${name}Y`] = (value[1] || defaultVal) + unit;
- } else if (['scale3d', 'translate3d'].indexOf(name) > -1) {
- // three args
- patchTransform[name] = value
- .map(i => `${i || defaultVal}${unit}`)
- .join(',');
- } else if ('rotate3d' === name) {
- patchTransform[name] =
- value.map(i => `${i || defaultVal}${unit}`).join(',') + 'deg';
- } else if (['matrix', 'matrix3d'].indexOf(name) > -1) {
- nextTranfrom += ` ${name}(${value.join(',')})`;
- } else {
- // key = val
- patchTransform[name] = value[0] + unit;
- }
- });
-
- // stitching patchTransform into a string
- Object.keys(patchTransform).forEach(name => {
- nextTranfrom += ` ${name}(${patchTransform[name]})`;
- });
-
- /**
- * Merge onto style cssText
- * before every animationGroup setTimeout 16ms
- *
- * it shouldn't just assignment cssText
- * but parse cssText
- */
-
- requestAnimationFrame(() => {
- const {
- duration,
- timeFunction,
- delay,
- transformOrigin
- } = animationGroup.config;
- let properties = {};
-
- if (node.style) {
- const propList = Object.keys(node.style);
- const style = {};
- const transformProperties = [
- 'transition',
- 'transform',
- 'transform-origin'
- ];
- // traverse all properties that aren't about transform
- propList.forEach((prop) => {
- if (
- prop &&
- transformProperties.indexOf(prop) < 0
- ) {
- style[prop] = node.style[prop];
- }
- });
- // merge nextProperties into style
- properties = Object.assign(style, nextProperties);
- }
-
- node.style = Object.assign(node.style, {
- transition: `all ${duration}ms ${timeFunction} ${delay}ms`,
- transformOrigin: transformOrigin,
- transform: `${nextTranfrom}`,
- ...properties
- });
- });
-}
diff --git a/packages/driver-worker/src/worker/CanvasElement.js b/packages/driver-worker/src/worker/CanvasElement.js
deleted file mode 100644
index a67fcfa97c..0000000000
--- a/packages/driver-worker/src/worker/CanvasElement.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import Element from './Element';
-import CanvasRenderingContext2D from './CanvasRenderingContext2D';
-
-export default class CanvasElement extends Element {
- getContext(contextType) {
- if (contextType === '2d') {
- return new CanvasRenderingContext2D(this);
- } else {
- return null;
- }
- }
-}
diff --git a/packages/driver-worker/src/worker/CanvasRenderingContext2D.js b/packages/driver-worker/src/worker/CanvasRenderingContext2D.js
deleted file mode 100644
index e97f303d9f..0000000000
--- a/packages/driver-worker/src/worker/CanvasRenderingContext2D.js
+++ /dev/null
@@ -1,122 +0,0 @@
-import { mutate } from './MutationObserver';
-
-const CanvasContext2DMethods = [
- 'arc',
- 'arcTo',
- 'addHitRegion',
- 'beginPath',
- 'bezierCurveTo',
- 'clearHitRegions',
- 'clearRect',
- 'clip',
- 'closePath',
- 'createImageData',
- 'createLinearGradient',
- 'createPattern',
- 'createRadialGradient',
- 'drawFocusIfNeeded',
- 'drawImage',
- 'drawWidgetAsOnScreen',
- 'drawWindow',
- 'ellipse',
- 'fill',
- 'fillRect',
- 'fillText',
- 'getImageData',
- 'getLineDash',
- 'isPointInPath',
- 'isPointInStroke',
- 'lineTo',
- 'measureText',
- 'moveTo',
- 'putImageData',
- 'quadraticCurveTo',
- 'rect',
- 'removeHitRegion',
- 'resetTransform',
- 'restore',
- 'rotate',
- 'save',
- 'scale',
- 'scrollPathIntoView',
- 'setLineDash',
- 'setTransform',
- 'stroke',
- 'strokeRect',
- 'strokeText',
- 'transform',
- 'translate'
-];
-
-export default class CanvasRenderingContext2D {
- constructor(vnode) {
- this.canvas = vnode;
-
- let propertyValues = {
- fillStyle: '#000000',
- filter: 'none',
- font: '10px sans-serif',
- globalAlpha: 1,
- globalCompositeOperation: 'source-over',
- imageSmoothingEnabled: true,
- imageSmoothingQuality: 'low',
- lineCap: 'butt',
- lineDashOffset: 0,
- lineJoin: 'miter',
- lineWidth: 1,
- miterLimit: 10,
- shadowBlur: 0,
- shadowColor: 'rgba(0, 0, 0, 0)',
- shadowOffsetX: 0,
- shadowOffsetY: 0,
- strokeStyle: '#000000',
- textAlign: 'start',
- textBaseline: 'alphabetic'
- };
-
- // context properties
- const properties = [
- 'direction',
- 'fillStyle',
- 'filter',
- 'font',
- 'globalAlpha',
- 'globalCompositeOperation',
- 'imageSmoothingEnabled',
- 'imageSmoothingQuality',
- 'lineCap',
- 'lineDashOffset',
- 'lineJoin',
- 'lineWidth',
- 'miterLimit',
- 'shadowBlur',
- 'shadowColor',
- 'shadowOffsetX',
- 'shadowOffsetY',
- 'strokeStyle',
- 'textAlign',
- 'textBaseline'
- ];
-
- properties.forEach(property => {
- Object.defineProperty(this, property, {
- get: function() {
- return propertyValues[property];
- },
- set: function(value) {
- propertyValues[property] = value;
- }
- });
- });
-
- CanvasContext2DMethods.forEach(method => {
- this[method] = (...args) => {
- mutate(vnode, 'canvasRenderingContext2D', {
- method: method,
- args: args,
- properties: Object.assign({}, propertyValues)
- });
- };
- });
- }
-}
diff --git a/packages/driver-worker/src/worker/Comment.js b/packages/driver-worker/src/worker/Comment.js
deleted file mode 100644
index 90c7b030dd..0000000000
--- a/packages/driver-worker/src/worker/Comment.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import Node from './Node';
-import { COMMENT_NODE } from './NodeTypes';
-
-export default class Comment extends Node {
- constructor(text) {
- super(COMMENT_NODE, '#comment');
- this.data = text;
- }
-}
diff --git a/packages/driver-worker/src/worker/Document.js b/packages/driver-worker/src/worker/Document.js
deleted file mode 100644
index 8dcf413c44..0000000000
--- a/packages/driver-worker/src/worker/Document.js
+++ /dev/null
@@ -1,57 +0,0 @@
-import { DOCUMENT_NODE } from './NodeTypes';
-import MutationObserver from './MutationObserver';
-import Node from './Node';
-import Element, { createElement, createElementNS, registerElement } from './Element';
-import CanvasElement from './CanvasElement';
-import Text from './Text';
-import Event from './Event';
-import Comment from './Comment';
-
-registerElement('canvas', CanvasElement);
-
-export function createDocument() {
- const document = new Document();
- document.appendChild(document.documentElement = createElement('html'));
- document.documentElement.appendChild(document.head = document.createElement('head'));
- document.documentElement.appendChild(document.body = document.createElement('body'));
- return document;
-}
-
-export default class Document extends Element {
- constructor() {
- super(DOCUMENT_NODE, '#DOCUMENT', null);
-
- this.defaultView = {
- document: this,
- MutationObserver,
- Document,
- Node,
- Text,
- Element,
- SVGElement: Element,
- Event,
- Comment,
- };
- }
-
- createElement(tagName) {
- return createElement(tagName);
- }
-
- createElementNS(namespaceURI, tagName) {
- return createElementNS(namespaceURI, tagName);
- }
-
- createComment(content) {
- return new Comment(content);
- }
-
- createTextNode(text) {
- return new Text(text);
- }
-
- getElementById(id) {
- // TODO
- }
-}
-
diff --git a/packages/driver-worker/src/worker/Element.js b/packages/driver-worker/src/worker/Element.js
deleted file mode 100644
index 31df5f42f1..0000000000
--- a/packages/driver-worker/src/worker/Element.js
+++ /dev/null
@@ -1,141 +0,0 @@
-import Node from './Node';
-import { ELEMENT_NODE } from './NodeTypes';
-import { dispatchAnimationToStyle } from './Animation';
-import { mutate } from './MutationObserver';
-import camelCase from '../shared/camelCase';
-import findWhere from '../shared/findWhere';
-import splice from '../shared/splice';
-import memorized from '../shared/memorized';
-
-const IS_DATASET_REG = /^data-/;
-const elementConstructors = {};
-
-export function registerElement(nodeName, elementConstructor) {
- elementConstructors[nodeName] = elementConstructor;
-}
-
-export function createElement(nodeName) {
- return createElementNS(null, nodeName);
-}
-
-export function createElementNS(namespaceURI, nodeName) {
- return new (elementConstructors[nodeName] || Element)(ELEMENT_NODE, nodeName, namespaceURI);
-}
-
-export function isElement(node) {
- return node && node.nodeType === ELEMENT_NODE;
-}
-
-const isDataset = memorized(function(attrName) {
- return IS_DATASET_REG.test(attrName);
-});
-
-const createAttributeFilter = memorized(function(ns, name) {
- return o => o.ns === ns && String(o.name).toLowerCase() === String(name).toLowerCase();
-});
-
-export default class Element extends Node {
- attributes = [];
- _style = {};
-
- constructor(nodeType, nodeName, namespaceURI) {
- super(nodeType || ELEMENT_NODE, nodeName.toUpperCase());
- this._namespace = namespaceURI;
- }
-
- set className(val) {
- this.setAttribute('class', val);
- }
-
- get className() {
- return this.getAttribute('class');
- }
-
- set id(val) {
- this.setAttribute('id', val);
- }
-
- get id() {
- return this.getAttribute('id');
- }
-
- set animation(queues) {
- this.setAttribute('animation', queues);
- if (Array.isArray(queues) && queues.length > 0) {
- const handleAnimationQueue = () => {
- if (queues.length > 0) {
- dispatchAnimationToStyle(this, queues.shift());
- } else {
- this.removeEventListener('transitionend', handleAnimationQueue);
- }
- };
- if (queues.length > 0) {
- dispatchAnimationToStyle(this, queues.shift());
- this.addEventListener('transitionend', handleAnimationQueue);
- }
- }
- }
- get animation() {
- return this.getAttribute('animation');
- }
-
- get children() {
- return this.childNodes.filter(isElement);
- }
-
- get dataset() {
- const dataset = {};
- for (let i = 0, l = this.attributes.length; i < l; i++) {
- const attr = this.attributes[i];
- if (isDataset(attr.name)) {
- // Remove `data-`
- dataset[camelCase(attr.name.slice(5))] = attr.value;
- }
- }
- return dataset;
- }
-
- get style() {
- return this._style;
- }
-
- set style(styleObject) {
- this._style = styleObject;
- mutate(this, 'attributes', { style: styleObject });
- }
-
- setAttribute(key, value) {
- if (value !== this.getAttribute(key)) {
- let attr = findWhere(this.attributes, createAttributeFilter(undefined, key));
- if (!attr) this.attributes.push(attr = { name: key });
- attr.value = value;
- mutate(this, 'attributes', { attributeName: key, newValue: value });
- }
- }
-
- getAttribute(key) {
- return this.getAttributeNS(undefined, key);
- }
-
- removeAttribute(key) {
- this.removeAttributeNS(undefined, key);
- }
-
- setAttributeNS(ns, name, value) {
- let attr = findWhere(this.attributes, createAttributeFilter(ns, name));
- if (!attr) this.attributes.push(attr = { ns, name });
-
- attr.value = value;
- mutate(this, 'attributes', { attributeName: name, newValue: value });
- }
-
- getAttributeNS(ns, name) {
- let attr = findWhere(this.attributes, createAttributeFilter(ns, name));
- return attr && attr.value;
- }
-
- removeAttributeNS(ns, name) {
- splice(this.attributes, createAttributeFilter(ns, name));
- mutate(this, 'attributes', { attributeName: name });
- }
-}
diff --git a/packages/driver-worker/src/worker/Evaluator.js b/packages/driver-worker/src/worker/Evaluator.js
deleted file mode 100644
index 7602824edc..0000000000
--- a/packages/driver-worker/src/worker/Evaluator.js
+++ /dev/null
@@ -1,81 +0,0 @@
-export default class Evaluator {
- _taskPending = {};
- _id = 0;
-
- constructor(sender) {
- this.sender = sender;
- }
-
- apply(data) {
- const task = this._taskPending[data.id];
- // Task only can be resolved once.
- if (task) {
- const { resolve, reject } = task;
- if (data.type === 'success') {
- resolve(data.success);
- } else if (data.type === 'error') {
- reject(data.error);
- }
-
- this._taskPending[data.id] = null;
- }
- }
-
- _send(data) {
- this.sender({
- type: 'EvaluationRecord',
- data,
- });
- }
-
- /**
- * Query a variable's value.
- * get('location.href')
- */
- get(expression) {
- return this._eval({ code: expression });
- }
-
- /**
- * Assign value to an variable.
- * set('location.href', value)
- */
- set(expression, value) {
- return this._eval({ code: `${expression}=${value}` });
- }
-
- /**
- * Delete an variable.
- * delete('location.href')
- */
- delete(expression) {
- return this._eval({ code: `delete ${expression}` });
- }
-
- /**
- * Call a specfic method with params.
- * call('location.replace', '')
- */
- call(method) {
- var params = [];
- for (var l = arguments.length, i = 1; i < l; i++) {
- params[i - 1] = JSON.stringify(arguments[i]);
- }
- return this._eval({ code: `${method}(${params.toString()})` });
- }
-
- _eval({ code }) {
- const id = this._generateId();
- return new Promise((resolve, reject) => {
- this._taskPending[id] = { resolve, reject };
- this._send({ type: 'eval', id, code });
- });
- }
-
- /**
- * Generate a unique procedure id.
- */
- _generateId() {
- return this._id++;
- }
-}
diff --git a/packages/driver-worker/src/worker/Event.js b/packages/driver-worker/src/worker/Event.js
deleted file mode 100644
index 7827feb19d..0000000000
--- a/packages/driver-worker/src/worker/Event.js
+++ /dev/null
@@ -1,25 +0,0 @@
-export default class Event {
- constructor(type, options = {}) {
- Object.assign(this, options); // extend event.
-
- this.defaultPrevented = false;
- this.bubbles = !!options.bubbles;
- this.cancelable = !!options.cancelable;
- this.type = type.toLowerCase();
- }
- stopPropagation() {
- this.bubbles = false;
- }
- stopImmediatePropagation() {
- this.bubbles = false;
- this._end = true;
- }
- preventDefault() {
- if (this.cancelable) {
- this.defaultPrevented = true;
- } else {
- // Calling preventDefault in uncancelable event should produce errors,
- // but in chrome and safari, which not throw or console errors, follow behaviors here.
- }
- }
-}
diff --git a/packages/driver-worker/src/worker/EventTarget.js b/packages/driver-worker/src/worker/EventTarget.js
deleted file mode 100644
index c31eefb692..0000000000
--- a/packages/driver-worker/src/worker/EventTarget.js
+++ /dev/null
@@ -1,65 +0,0 @@
-import { mutate } from './MutationObserver';
-import splice from '../shared/splice';
-
-export default class EventTarget {
- _eventListeners = {};
-
- _getEvents() {
- const eventKeys = Object.keys(this._eventListeners);
- // Must have at least one handler.
- return eventKeys.filter((eventName) => {
- return this._eventListeners[eventName].length > 0;
- });
- }
-
- /**
- * Add event listener.
- * @param type {String} Event name.
- * @param handler {EventHandler} Event handler.
- */
- addEventListener(type, handler) {
- type = String(type).toLowerCase();
- (
- this._eventListeners[type] ||
- (this._eventListeners[type] = [])
- ).push(handler);
- mutate(this, 'addEvent', { eventName: type });
- }
-
- /**
- * Remove event listener.
- * @param type {String} Event name.
- * @param handler {EventHandler} Event handler.
- */
- removeEventListener(type, handler) {
- type = String(type).toLowerCase();
- splice(this._eventListeners[type], handler, 0, true);
- mutate(this, 'removeEvent', { eventName: type });
- }
-
- /**
- * Dispatch an event to target.
- * @param event {Event} event.
- * @return {boolean}
- */
- dispatchEvent(event) {
- let type = event.type;
- let target = event.target = event.currentTarget = this;
-
- let listeners;
- let i;
- do {
- listeners = target._eventListeners && target._eventListeners[type];
- if (listeners) {
- for (i = listeners.length; i--;) {
- const handlerResult = listeners[i].call(target, event);
- if (handlerResult === false || event._end) break;
- }
- }
- } while (
- event.bubbles && !event.defaultPrevented &&
- (event.currentTarget = target = target.parentNode)
- );
- return !event.defaultPrevented;
- }
-}
diff --git a/packages/driver-worker/src/worker/MutationObserver.js b/packages/driver-worker/src/worker/MutationObserver.js
deleted file mode 100644
index 1b5cb4144f..0000000000
--- a/packages/driver-worker/src/worker/MutationObserver.js
+++ /dev/null
@@ -1,59 +0,0 @@
-import splice from '../shared/splice';
-import setImmediate from '../shared/setImmediate';
-
-let observers = [];
-let pendingMutations = false;
-
-export function mutate(target, type, record) {
- record.target = target;
- record.type = type;
-
- for (let i = observers.length; i--;) {
- let _target = target;
- let ob = observers[i],
- match = _target === ob._target;
- if (!match && ob._options.subtree) {
- do {
- if (match = _target === ob._target) break;
- } while (_target = _target.parentNode);
- }
-
- if (match) {
- ob._records.push(record);
- if (!pendingMutations) {
- pendingMutations = true;
- setImmediate(flushMutations, 0);
- }
- }
- }
-}
-
-export function flushMutations() {
- pendingMutations = false;
- for (let i = observers.length; i--;) {
- let ob = observers[i];
- if (ob._records.length) {
- ob.callback(ob.takeRecords());
- }
- }
-}
-
-export default class MutationObserver {
- constructor(callback) {
- this.callback = callback;
- this._records = [];
- }
- observe(target, options) {
- this.disconnect();
- this._target = target;
- this._options = options || {};
- observers.push(this);
- }
- disconnect() {
- this._target = null;
- splice(observers, this);
- }
- takeRecords() {
- return this._records.splice(0, this._records.length);
- }
-}
diff --git a/packages/driver-worker/src/worker/Node.js b/packages/driver-worker/src/worker/Node.js
deleted file mode 100644
index fcda523bdc..0000000000
--- a/packages/driver-worker/src/worker/Node.js
+++ /dev/null
@@ -1,71 +0,0 @@
-import EventTarget from './EventTarget';
-import { mutate } from './MutationObserver';
-import findWhere from '../shared/findWhere';
-import splice from '../shared/splice';
-
-function mutateChildNodes(node) {
- if (node && node.childNodes) {
- for (let i = 0, len = node.childNodes.length; i < len; i++) {
- const child = node.childNodes[i];
- mutate(node, 'childList', { addedNodes: [child] });
- mutateChildNodes(child);
- }
- }
-}
-
-export default class Node extends EventTarget {
- constructor(nodeType, nodeName) {
- super();
- this.nodeType = nodeType;
- this.nodeName = nodeName;
- this.childNodes = [];
- }
- get nextSibling() {
- let p = this.parentNode;
- if (p) return p.childNodes[findWhere(p.childNodes, this, true) + 1];
- }
- get previousSibling() {
- let p = this.parentNode;
- if (p) return p.childNodes[findWhere(p.childNodes, this, true) - 1];
- }
- get firstChild() {
- return this.childNodes[0];
- }
- get lastChild() {
- return this.childNodes[this.childNodes.length - 1];
- }
- appendChild(child) {
- this.insertBefore(child);
- return child;
- }
- insertBefore(child, ref) {
- child.remove();
- child.parentNode = this;
-
- if (ref) {
- splice(this.childNodes, ref, child);
- mutate(this, 'childList', { addedNodes: [child], nextSibling: ref });
- } else {
- this.childNodes.push(child);
- mutate(this, 'childList', { addedNodes: [child] });
- }
-
- mutateChildNodes(child);
- return child;
- }
- replaceChild(child, ref) {
- if (ref.parentNode === this) {
- this.insertBefore(child, ref);
- ref.remove();
- return ref;
- }
- }
- removeChild(child) {
- splice(this.childNodes, child);
- mutate(this, 'childList', { removedNodes: [child] });
- return child;
- }
- remove() {
- if (this.parentNode) this.parentNode.removeChild(this);
- }
-}
diff --git a/packages/driver-worker/src/worker/NodeTypes.js b/packages/driver-worker/src/worker/NodeTypes.js
deleted file mode 100644
index 2844473d0f..0000000000
--- a/packages/driver-worker/src/worker/NodeTypes.js
+++ /dev/null
@@ -1,4 +0,0 @@
-export const ELEMENT_NODE = 1;
-export const TEXT_NODE = 3;
-export const COMMENT_NODE = 8;
-export const DOCUMENT_NODE = 9;
diff --git a/packages/driver-worker/src/worker/Text.js b/packages/driver-worker/src/worker/Text.js
deleted file mode 100644
index 274a73c19a..0000000000
--- a/packages/driver-worker/src/worker/Text.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import Node from './Node';
-import { TEXT_NODE } from './NodeTypes';
-import { mutate } from './MutationObserver';
-
-export default class Text extends Node {
- constructor(text) {
- super(TEXT_NODE, '#text'); // TEXT_NODE
- this.data = text;
- }
- set textContent(text) {
- mutate(this, 'characterData', { newValue: text });
- this.data = text;
- }
- get textContent() {
- return this.data;
- }
-}
diff --git a/packages/driver-worker/src/worker/__tests__/__snapshots__/animation.js.snap b/packages/driver-worker/src/worker/__tests__/__snapshots__/animation.js.snap
deleted file mode 100644
index 56a3b15ff7..0000000000
--- a/packages/driver-worker/src/worker/__tests__/__snapshots__/animation.js.snap
+++ /dev/null
@@ -1,7 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Animation merge style 1`] = `
-Object {
- "transform": "rotate(30deg)",
-}
-`;
diff --git a/packages/driver-worker/src/worker/__tests__/__snapshots__/evaluator.js.snap b/packages/driver-worker/src/worker/__tests__/__snapshots__/evaluator.js.snap
deleted file mode 100644
index 9bcec1d030..0000000000
--- a/packages/driver-worker/src/worker/__tests__/__snapshots__/evaluator.js.snap
+++ /dev/null
@@ -1,56 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Evaluator call with error 1`] = `
-Object {
- "data": Object {
- "code": "foo.bar(123,\\"hello\\")",
- "id": 0,
- "type": "eval",
- },
- "type": "EvaluationRecord",
-}
-`;
-
-exports[`Evaluator call with success 1`] = `
-Object {
- "data": Object {
- "code": "foo.bar(123,\\"hello\\")",
- "id": 0,
- "type": "eval",
- },
- "type": "EvaluationRecord",
-}
-`;
-
-exports[`Evaluator delete 1`] = `
-Object {
- "data": Object {
- "code": "delete foo.bar",
- "id": 0,
- "type": "eval",
- },
- "type": "EvaluationRecord",
-}
-`;
-
-exports[`Evaluator get 1`] = `
-Object {
- "data": Object {
- "code": "document.body.clientWidth",
- "id": 0,
- "type": "eval",
- },
- "type": "EvaluationRecord",
-}
-`;
-
-exports[`Evaluator set 1`] = `
-Object {
- "data": Object {
- "code": "document.body.innerHTML=\\"hello world\\"",
- "id": 0,
- "type": "eval",
- },
- "type": "EvaluationRecord",
-}
-`;
diff --git a/packages/driver-worker/src/worker/__tests__/animation.js b/packages/driver-worker/src/worker/__tests__/animation.js
deleted file mode 100644
index df94743e23..0000000000
--- a/packages/driver-worker/src/worker/__tests__/animation.js
+++ /dev/null
@@ -1,68 +0,0 @@
-import { createElement } from '../Element';
-
-describe('Animation', () => {
- function animate(animation) {
- return [{
- config: {
- transformOrigin: 'top right',
- duration: 3000,
- timeFunction: 'ease-in-out',
- delay: 100
- },
- animation,
- }];
- }
-
- it('merge style', () => {
- const animationConfig = animate([['translate', [35]]]);
- const el = createElement('foo');
- el.style = {
- transform: 'rotate(30deg)'
- };
- el.animation = animationConfig;
- expect(el.animation).toEqual(animationConfig);
- expect(el.style).toMatchSnapshot();
- });
-
- it('translate', () => {
- const animationConfig = animate([['translate', [35]]]);
- const el = createElement('foo');
- el.animation = animationConfig;
- expect(el.animation).toEqual(animationConfig);
- });
-
- it('translate3d', () => {
- const animationConfig = animate([['translate3d', [35, 40, 0]]]);
- const el = createElement('foo');
- el.animation = animationConfig;
- expect(el.animation).toEqual(animationConfig);
- });
-
- it('scale', () => {
- const animationConfig = animate([['scale', [1.5]]]);
- const el = createElement('foo');
- el.animation = animationConfig;
- expect(el.animation).toEqual(animationConfig);
- });
-
- it('scale3d', () => {
- const animationConfig = animate([['scale3d', [1.5, 1.2, 1.0]]]);
- const el = createElement('foo');
- el.animation = animationConfig;
- expect(el.animation).toEqual(animationConfig);
- });
-
- it('rotateX', () => {
- const animationConfig = animate([['rotateX', [30]]]);
- const el = createElement('foo');
- el.animation = animationConfig;
- expect(el.animation).toEqual(animationConfig);
- });
-
- it('rotate3d', () => {
- const animationConfig = animate([['rotate3d', [30, 40, 50]]]);
- const el = createElement('foo');
- el.animation = animationConfig;
- expect(el.animation).toEqual(animationConfig);
- });
-});
diff --git a/packages/driver-worker/src/worker/__tests__/canvas.js b/packages/driver-worker/src/worker/__tests__/canvas.js
deleted file mode 100644
index f2db2ac7c5..0000000000
--- a/packages/driver-worker/src/worker/__tests__/canvas.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import { registerElement, createElement } from '../Element';
-import CanvasElement from '../CanvasElement';
-import CanvasRenderingContext2D from '../CanvasRenderingContext2D';
-
-describe('Canvas', () => {
- registerElement('canvas', CanvasElement);
-
- it('create canvas element', () => {
- const canvas = createElement('canvas');
- expect(typeof canvas.getContext).toEqual('function');
- });
-
- it('getContext', () => {
- const canvas = createElement('canvas');
- const context2d = canvas.getContext('2d');
- expect(context2d).toBeInstanceOf(CanvasRenderingContext2D);
-
- const contextOther = canvas.getContext('webgl');
- expect(contextOther).toBeNull();
- });
-
- describe('context2d', () => {
- it('property', () => {
- const canvas = createElement('canvas');
- const context2d = canvas.getContext('2d');
-
- expect(context2d.globalAlpha).toEqual(1);
- context2d.fillStyle = '#ff5000';
- expect(context2d.fillStyle).toEqual('#ff5000');
- });
-
- it('method', () => {
- const canvas = createElement('canvas');
- const context2d = canvas.getContext('2d');
- context2d.fill('with', 'args');
- });
- });
-});
diff --git a/packages/driver-worker/src/worker/__tests__/element.js b/packages/driver-worker/src/worker/__tests__/element.js
deleted file mode 100644
index 5796f5a721..0000000000
--- a/packages/driver-worker/src/worker/__tests__/element.js
+++ /dev/null
@@ -1,95 +0,0 @@
-import Element, {
- registerElement,
- createElement,
- createElementNS,
- isElement
-} from '../Element';
-import Text from '../Text';
-import { ELEMENT_NODE, TEXT_NODE } from '../NodeTypes';
-
-describe('workerDOM element', () => {
- /**
- *
- *
- * "text"
- *
- * @type {Element}
- */
- const view = new Element(ELEMENT_NODE, 'view');
- view.setAttribute('data-foo', 'foo');
- view.setAttribute('data-foo-bar', 1);
- view.setAttribute('data-object-val', { key: 'value' });
- view.setAttribute('id', 'ID');
- view.className = 'foo bar';
-
- const text = new Element(ELEMENT_NODE, 'text');
- view.appendChild(text);
- const textNode = new Element(TEXT_NODE, 'text');
- view.appendChild(textNode);
-
- it('should get className', () => {
- expect(view.className).toBe('foo bar');
- expect(view.getAttribute('class')).toBe('foo bar');
- });
-
- it('should get id', () => {
- expect(view.id).toBe('ID');
- expect(view.getAttribute('id')).toBe('ID');
- });
-
- it('should get dataset', () => {
- expect(Object.keys(view.dataset)).toEqual(['foo', 'fooBar', 'objectVal']);
- expect(view.dataset.foo).toBe('foo');
- expect(view.dataset.fooBar).toEqual(1);
- expect(view.dataset.objectVal).toEqual({ key: 'value' });
- });
-
- it('should have right length of children', () => {
- expect(view.children.length).toBe(1);
- });
-
- it('setAttribute & getAttribute & removeAttribute', () => {
- const v = new Element(ELEMENT_NODE, 'view');
- v.setAttribute('key', 'val');
- expect(v.getAttribute('key')).toEqual('val');
-
- v.removeAttribute('key');
- expect(v.getAttribute('key')).toEqual(undefined);
- });
-
- it('children', () => {
- const parent = createElement('view');
- const child1 = createElement('view');
- const child2 = createElement('view');
- const child3 = new Text('hello');
- parent.appendChild(child1);
- parent.appendChild(child2);
- parent.appendChild(child3);
-
- expect(parent.children).toEqual([child1, child2]);
- });
-
- it('registerElement', (done) => {
- registerElement('foo', class Foo {
- constructor() {
- done();
- }
- });
- createElement('foo');
- });
-
- it('createElement', () => {
- const el = createElement('view');
- expect(el).toBeInstanceOf(Element);
- });
-
- it('createElementNS', () => {
- const el = createElementNS('namespaceURI', 'view');
- expect(el).toBeInstanceOf(Element);
- });
-
- it('isElement', () => {
- const el = createElement('view');
- expect(isElement(el)).toEqual(true);
- });
-});
diff --git a/packages/driver-worker/src/worker/__tests__/evaluator.js b/packages/driver-worker/src/worker/__tests__/evaluator.js
deleted file mode 100644
index d8625157b0..0000000000
--- a/packages/driver-worker/src/worker/__tests__/evaluator.js
+++ /dev/null
@@ -1,81 +0,0 @@
-import Evaluator from '../Evaluator';
-
-describe('Evaluator', () => {
- it('send', (done) => {
- const data = { hello: 'world' };
- const sender = (message) => {
- expect(message).toEqual({
- type: 'EvaluationRecord',
- data,
- });
- done();
- };
- const evaluator = new Evaluator(sender);
- evaluator._send(data);
- });
-
- it('get', (done) => {
- const sender = (message) => {
- expect(message).toMatchSnapshot();
- done();
- };
- const evaluator = new Evaluator(sender);
- evaluator.get('document.body.clientWidth');
- });
-
- it('set', (done) => {
- const sender = (message) => {
- expect(message).toMatchSnapshot();
- done();
- };
- const evaluator = new Evaluator(sender);
- evaluator.set('document.body.innerHTML', JSON.stringify('hello world'));
- });
-
- it('delete', (done) => {
- const sender = (message) => {
- expect(message).toMatchSnapshot();
- done();
- };
- const evaluator = new Evaluator(sender);
- evaluator.delete('foo.bar');
- });
-
- it('call with success', (done) => {
- const evaluator = new Evaluator((message) => {
- expect(message).toMatchSnapshot();
-
- setTimeout(() => {
- evaluator.apply({
- id: message.data.id,
- type: 'success',
- success: 'YES',
- });
- }, 300);
- });
- evaluator.call('foo.bar', 123, 'hello')
- .then((val) => {
- expect(val).toEqual('YES');
- done();
- });
- });
-
- it('call with error', (done) => {
- const evaluator = new Evaluator((message) => {
- expect(message).toMatchSnapshot();
-
- setTimeout(() => {
- evaluator.apply({
- id: message.data.id,
- type: 'error',
- error: 'NO',
- });
- }, 300);
- });
- evaluator.call('foo.bar', 123, 'hello')
- .catch((error) => {
- expect(error).toEqual('NO');
- done();
- });
- });
-});
diff --git a/packages/driver-worker/src/worker/__tests__/event.js b/packages/driver-worker/src/worker/__tests__/event.js
deleted file mode 100644
index d3a75096e4..0000000000
--- a/packages/driver-worker/src/worker/__tests__/event.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import Event from '../Event';
-
-describe('Event', () => {
- it('contructor', () => {
- const event = new Event('input', {
- bubbles: true,
- cancelable: true,
- });
- expect(event.type).toEqual('input');
- expect(event.bubbles).toEqual(true);
- expect(event.cancelable).toEqual(true);
- });
-
- it('stopPropagation', () => {
- const event = new Event('input');
- event.stopPropagation();
- expect(event.bubbles).toEqual(false);
- });
-
- it('stopImmediatePropagation', () => {
- const event = new Event('input');
- event.stopImmediatePropagation();
- expect(event.bubbles).toEqual(false);
- expect(event._end).toEqual(true);
- });
-
- it('preventDefault', () => {
- const cancelableEvent = new Event('input', { cancelable: true });
- cancelableEvent.preventDefault();
- expect(cancelableEvent.defaultPrevented).toEqual(true);
-
- const uncancelableEvent = new Event('input', { cancelable: false });
- uncancelableEvent.preventDefault();
- expect(uncancelableEvent.defaultPrevented).toEqual(false);
- });
-});
diff --git a/packages/driver-worker/src/worker/__tests__/eventTarget.js b/packages/driver-worker/src/worker/__tests__/eventTarget.js
deleted file mode 100644
index fea9640c00..0000000000
--- a/packages/driver-worker/src/worker/__tests__/eventTarget.js
+++ /dev/null
@@ -1,65 +0,0 @@
-import EventTarget from '../EventTarget';
-import Event from '../Event';
-
-describe('EventTarget', () => {
- it('addEventListener', () => {
- const eventTarget = new EventTarget();
- const handler = () => {};
- eventTarget.addEventListener('foo', handler);
- expect(eventTarget._eventListeners.foo).toEqual([handler]);
- });
-
- it('removeEventListener', () => {
- const eventTarget = new EventTarget();
- const handler = () => {};
- eventTarget.addEventListener('foo', handler);
- eventTarget.removeEventListener('foo', handler);
- expect(eventTarget._eventListeners.foo).toEqual([]);
- });
-
- it('dispatchEvent', (done) => {
- const eventTarget = new EventTarget();
- const handler = () => {
- done();
- };
- eventTarget.addEventListener('foo', handler);
- eventTarget.dispatchEvent(new Event('foo'));
- });
-
- it('getEvents', () => {
- const eventTarget = new EventTarget();
- const handler = () => {};
- eventTarget.addEventListener('foo', handler);
- eventTarget.removeEventListener('foo', handler);
- expect(eventTarget._getEvents()).toEqual([]);
- });
-
-
- it('bubbles', (done) => {
- const eventTarget1 = new EventTarget();
- const eventTarget2 = new EventTarget();
- eventTarget2.parentNode = eventTarget1;
-
- eventTarget1.addEventListener('foo', (evt) => {
- done();
- });
- eventTarget2.dispatchEvent(new Event('foo', { bubbles: true, cancelable: true }));
- });
-
- it('stopPropagation', (done) => {
- const eventTarget1 = new EventTarget();
- const eventTarget2 = new EventTarget();
- eventTarget2.parentNode = eventTarget1;
-
- eventTarget1.addEventListener('foo', (evt) => {
- expect(evt.bubbles).toEqual(false);
- throw new Error('Should not bubble event.');
- });
- eventTarget2.addEventListener('foo', (evt) => {
- expect(evt.bubbles).toEqual(true);
- evt.stopPropagation();
- setTimeout(done);
- });
- eventTarget2.dispatchEvent(new Event('foo', { bubbles: true }));
- });
-});
diff --git a/packages/driver-worker/src/worker/__tests__/node.js b/packages/driver-worker/src/worker/__tests__/node.js
deleted file mode 100644
index 6b2917e1d1..0000000000
--- a/packages/driver-worker/src/worker/__tests__/node.js
+++ /dev/null
@@ -1,67 +0,0 @@
-import Node from '../Node';
-import { ELEMENT_NODE} from '../NodeTypes';
-
-describe('Node', () => {
- it('node type', () => {
- const node = new Node(ELEMENT_NODE, 'view');
- expect(node.nodeType).toEqual(ELEMENT_NODE);
- expect(node.nodeName).toEqual('view');
- });
-
- it('node structures', () => {
- const parent = new Node(ELEMENT_NODE, 'view');
- const child1 = new Node(ELEMENT_NODE, 'view');
- const child2 = new Node(ELEMENT_NODE, 'view');
- const child3 = new Node(ELEMENT_NODE, 'view');
- parent.appendChild(child1);
- parent.appendChild(child2);
- parent.appendChild(child3);
-
- expect(parent.childNodes).toMatchObject([child1, child2, child3]);
- expect(child1.parentNode).toEqual(parent);
- expect(child1.nextSibling).toEqual(child2);
- expect(child2.previousSibling).toEqual(child1);
- expect(parent.firstChild).toEqual(child1);
- expect(parent.lastChild).toEqual(child3);
- });
-
- it('replace child', () => {
- const parent = new Node(ELEMENT_NODE, 'view');
- const child1 = new Node(ELEMENT_NODE, 'view');
- const child2 = new Node(ELEMENT_NODE, 'view');
- const child3 = new Node(ELEMENT_NODE, 'view');
- const child4 = new Node(ELEMENT_NODE, 'view');
- parent.appendChild(child1);
- parent.appendChild(child2);
- parent.appendChild(child3);
-
- parent.replaceChild(child4, child2);
- expect(parent.childNodes[1] === child4).toEqual(true);
- });
-
- it('remove child', () => {
- const parent = new Node(ELEMENT_NODE, 'view');
- const child1 = new Node(ELEMENT_NODE, 'view');
- const child2 = new Node(ELEMENT_NODE, 'view');
- const child3 = new Node(ELEMENT_NODE, 'view');
- parent.appendChild(child1);
- parent.appendChild(child2);
- parent.appendChild(child3);
-
- parent.removeChild(child2);
- expect(parent.childNodes).toEqual([child1, child3]);
- });
-
- it('mutate child nodes', () => {
- const parent = new Node(ELEMENT_NODE, 'view');
- const child1 = new Node(ELEMENT_NODE, 'view');
- const child2 = new Node(ELEMENT_NODE, 'view');
- const child3 = new Node(ELEMENT_NODE, 'view');
- parent.appendChild(child1);
- parent.appendChild(child2);
- parent.appendChild(child3);
-
- const root = new Node(ELEMENT_NODE, 'view');
- root.appendChild(parent);
- });
-});
diff --git a/packages/driver-worker/src/worker/__tests__/text.js b/packages/driver-worker/src/worker/__tests__/text.js
deleted file mode 100644
index 70e6f38f8b..0000000000
--- a/packages/driver-worker/src/worker/__tests__/text.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import Text from '../Text';
-import { TEXT_NODE } from '../NodeTypes';
-
-describe('Text', () => {
- it('type', () => {
- const text = new Text('hello');
- expect(text.nodeType).toEqual(TEXT_NODE);
- });
-
- it('textContent', () => {
- const text = new Text('hello');
- expect(text.data).toEqual('hello');
- expect(text.textContent).toEqual('hello');
-
- text.textContent = 'world';
- expect(text.data).toEqual('world');
- });
-});
diff --git a/packages/driver-worker/src/worker/createWorkerGlobalScope.js b/packages/driver-worker/src/worker/createWorkerGlobalScope.js
deleted file mode 100644
index 6168255e92..0000000000
--- a/packages/driver-worker/src/worker/createWorkerGlobalScope.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import { createDocument } from './Document';
-
-export default function createWorkerGlobalScope() {
- return {
- document: createDocument()
- };
-}
diff --git a/packages/rax-miniapp-renderer/README.md b/packages/rax-miniapp-renderer/README.md
deleted file mode 100644
index 7c4b9cf264..0000000000
--- a/packages/rax-miniapp-renderer/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# rax-miniapp-renderer
-
-> Rax renderer for miniapp.
-
-## Install
-
-```bash
-$ npm install --save rax-miniapp-renderer
-```
-
-## Usage
-
-`render.js`
-```js
-import domRender from 'rax-miniapp-renderer';
-import spawnWorker from 'worker-loader?inline!./worker.js';
-
-const worker = spawnWorker();
-domRender({ worker });
-```
diff --git a/packages/rax-miniapp-renderer/package.json b/packages/rax-miniapp-renderer/package.json
deleted file mode 100644
index 63fe04fcb5..0000000000
--- a/packages/rax-miniapp-renderer/package.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "name": "rax-miniapp-renderer",
- "version": "0.1.1",
- "description": "Rax renderer for miniapp.",
- "license": "BSD-3-Clause",
- "main": "dist/rax-miniapp-renderer.min.js",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/alibaba/rax.git"
- },
- "bugs": {
- "url": "https://github.com/alibaba/rax/issues"
- },
- "homepage": "https://github.com/alibaba/rax#readme",
- "dependencies": {
- "driver-worker": "^0.7.9"
- }
-}
diff --git a/packages/rax-miniapp-renderer/src/EvaluationHandler.js b/packages/rax-miniapp-renderer/src/EvaluationHandler.js
deleted file mode 100644
index bb24e26c83..0000000000
--- a/packages/rax-miniapp-renderer/src/EvaluationHandler.js
+++ /dev/null
@@ -1,45 +0,0 @@
-export default class EvaluationHandler {
- constructor(sender) {
- this.sender = sender;
- }
-
- apply({ data }) {
- const { type } = data;
- this[type](data);
- }
-
- returnSuccess(id, success) {
- if (typeof success === 'object') {
- try {
- success = JSON.parse(JSON.stringify(success));
- } catch (e) {
- success = success.toString();
- }
- }
-
- if (typeof success === 'function') {
- success = success.toString();
- }
-
- this.send({ type: 'success', id, success });
- }
-
- returnError(id, { name, message }) {
- this.send({ type: 'error', id, error: { name, message } });
- }
-
- send(data) {
- this.sender({
- type: 'return',
- return: data,
- });
- }
-
- eval({ id, code }) {
- try {
- this.returnSuccess(id, window.eval(code));
- } catch (error) {
- this.returnError(id, error);
- }
- }
-}
diff --git a/packages/rax-miniapp-renderer/src/EventHandler.js b/packages/rax-miniapp-renderer/src/EventHandler.js
deleted file mode 100644
index 3439f868dd..0000000000
--- a/packages/rax-miniapp-renderer/src/EventHandler.js
+++ /dev/null
@@ -1,196 +0,0 @@
-import { passive as supportsPassive } from './supports';
-
-const EVENT_OPTIONS = supportsPassive ? { capture: true, passive: true } : true;
-const NO_BUBBLES_EVENTS = {
- // Resource Events and Progress Events
- load: true,
- error: true,
- unload: true,
- abort: true,
- loadstart: true,
- progress: true,
- loadend: true,
- // Focus Events
- blur: true,
- focus: true,
- // View Events
- scroll: true, // Not bubles on elements
- appear: true,
- disappear: true,
- // Uncategorized events
- invalid: true
-};
-const TOUCH_EVENTS = ['touchstart', 'touchmove', 'touchend', 'touchcancel'];
-const EVENT_LISTENERS = '__event_listeners__';
-
-export default class EventHandler {
- constructor(handler, options = {}) {
- this.postMessage = handler;
- this.registeredEventCounts = {};
- this.nobubbleEventNodes = [];
- this.mountNode = options.mountNode || document;
- this.touch = null;
- }
-
- addEvent(node, name) {
- if (NO_BUBBLES_EVENTS[name]) {
- this.addNoBubblesEventListener(node, name);
- } else {
- const registeredCount = this.registeredEventCounts[name];
- if (!registeredCount) {
- this.registeredEventCounts[name] = 1;
- // Top-level register
- this.mountNode.addEventListener(name, this.eventProxyHandler, EVENT_OPTIONS);
- } else {
- this.registeredEventCounts[name]++;
- }
- }
- }
-
- removeAllEvents() {
- // Remove no-bubbles events.
- let noBubblesEventNode;
- while (noBubblesEventNode = this.nobubbleEventNodes.pop()) {
- if (noBubblesEventNode[EVENT_LISTENERS]) {
- const eventNames = Object.keys(noBubblesEventNode[EVENT_LISTENERS]);
- for (let i = 0, l = eventNames.length; i < l; i++) {
- this.removeNoBubblesEventListener(noBubblesEventNode, eventNames[i]);
- }
- }
- }
-
- // Remove regular events.
- const events = Object.keys(this.registeredEventCounts);
- for (let i = 0, l = events.length; i < l; i++) {
- const name = events[i];
- this.mountNode.removeEventListener(name, this.eventProxyHandler, EVENT_OPTIONS);
- delete this.registeredEventCounts[name];
- }
- }
-
- removeEvent(node, name) {
- if (NO_BUBBLES_EVENTS[name]) {
- this.removeNoBubblesEventListener(node, name);
- } else {
- this.registeredEventCounts[name]--;
- if (this.registeredEventCounts[name] === 0) {
- this.mountNode.removeEventListener(name, this.eventProxyHandler, EVENT_OPTIONS);
- }
- }
- }
-
- addNoBubblesEventListener(node, name) {
- const listener = (evt) => {
- const target = { $$id: node.$$id };
-
- if (node === document.body) {
- target.nodeName = 'BODY';
- }
-
- this.postMessage({
- type: 'event',
- event: {
- type: name,
- target,
- currentTarget: target,
- detail: evt.detail
- }
- });
- };
- const listeners = node[EVENT_LISTENERS] = node[EVENT_LISTENERS] || {};
- listeners[name] = listeners[name] || [];
- listeners[name].push(listener);
- if (this.nobubbleEventNodes.indexOf(node) !== -1) this.nobubbleEventNodes.push(node);
- node.addEventListener(name, listener, EVENT_OPTIONS);
- }
-
- removeNoBubblesEventListener(node, name) {
- if (node[EVENT_LISTENERS] && node[EVENT_LISTENERS][name]) {
- for (let i = 0, l = node[EVENT_LISTENERS][name].length; i < l; i++) {
- node.removeEventListener(name, node[EVENT_LISTENERS][name][i], EVENT_OPTIONS);
- }
- delete node[EVENT_LISTENERS][name];
- }
- this.nobubbleEventNodes.splice(this.nobubbleEventNodes.indexOf(node), 1);
- }
-
- eventProxyHandler = (e) => {
- if (e.type === 'click' && this.touch) return false;
-
- let event = { type: e.type };
- if (e.target) event.target = e.target.$$id;
- if (e.type === 'scroll' && e.target === document) {
- event.target = document.body.$$id;
- // page scroll container's top
- // safari is document.body.scrollTop
- // chrome is document.documentElement.scrollTop
- event.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- }
- // CustomEvent detail
- if (e.detail) event.detail = e.detail;
- for (let i in e) {
- let v = e[i];
- if (
- typeof v !== 'object' &&
- typeof v !== 'function' &&
- i !== i.toUpperCase() &&
- !event.hasOwnProperty(i)
- ) {
- event[i] = v;
- }
- }
-
- if (TOUCH_EVENTS.indexOf(e.type) !== -1) {
- event.touches = serializeTouchList(e.touches);
- event.changedTouches = serializeTouchList(e.changedTouches);
- }
-
- this.postMessage({
- type: 'event',
- event
- });
-
- if (e.type === 'touchstart') {
- this.touch = getTouch(e);
- } else if (e.type === 'touchend' && this.touch) {
- let t = getTouch(e);
- if (t) {
- let delta = Math.sqrt(
- Math.pow(t.pageX - this.touch.pageX, 2) +
- Math.pow(t.pageY - this.touch.pageY, 2)
- );
- if (delta < 10) {
- event.type = 'click';
- this.postMessage({ type: 'event', event });
- }
- }
- }
- }
-}
-
-function getTouch(e) {
- let t = e.changedTouches && e.changedTouches[0] ||
- e.touches && e.touches[0] || e;
- return t && { pageX: t.pageX, pageY: t.pageY };
-}
-
-function serializeTouchList(touchList) {
- const touches = [];
- for (let i = 0, l = touchList.length; i < l; i++) {
- const {
- clientX, clientY,
- pageX, pageY,
- identifier, target
- } = touchList[i];
-
- touches.push({
- clientX, clientY,
- pageX, pageY,
- identifier,
- // instance id of changed target
- $$id: target.$$id,
- });
- }
- return touches;
-}
-
diff --git a/packages/rax-miniapp-renderer/src/LocationHandler.js b/packages/rax-miniapp-renderer/src/LocationHandler.js
deleted file mode 100644
index 89a2bd5054..0000000000
--- a/packages/rax-miniapp-renderer/src/LocationHandler.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * Deperated location handler.
- */
-export default class LocationHandler {
- constructor(sender) {
- this.sender = sender;
- }
-
- apply(data) {
- const { data: payload } = data;
- const { type, prop } = payload;
-
- if (type === 'call' && prop === 'replace') {
- location.replace(payload.args[0]);
- }
- }
-}
diff --git a/packages/rax-miniapp-renderer/src/MutationHandler.js b/packages/rax-miniapp-renderer/src/MutationHandler.js
deleted file mode 100644
index f5fed9c3fd..0000000000
--- a/packages/rax-miniapp-renderer/src/MutationHandler.js
+++ /dev/null
@@ -1,171 +0,0 @@
-import NodeMap from './NodeMap';
-import EventHandler from './EventHandler';
-import { createNode, getTagName } from './nodes';
-import { setAttribute } from './attrs';
-import { setStyle } from './styles';
-
-const STYLE_ELEMENT = 'STYLE';
-const TEXT_CONTENT = 'textContent';
-const TEXT_CONTENT_ATTR = TEXT_CONTENT in document ? TEXT_CONTENT : 'nodeValue';
-
-/**
- * Returns "attributes" if it was an attribute mutation.
- * "characterData" if it was a mutation to a CharacterData node.
- * And "childList" if it was a mutation to the tree of nodes.
- */
-export default class MutationHandler {
- constructor(sender, mountNode) {
- this.eventHandler = new EventHandler(sender, {
- mountNode
- });
- this.mountNode = mountNode || document.body;
-
- this.sharedNodeMap = new NodeMap();
- this.sharedNodeMap._setMountNode(this.mountNode);
- }
-
- apply(data) {
- let mutations = data.mutations;
- for (let i = 0; i < mutations.length; i++) {
- // apply mutation
- let mutation = mutations[i];
- this[mutation.type](mutation);
- }
- }
-
- childList({ target, removedNodes, addedNodes, nextSibling }) {
- let sharedNodeMap = this.sharedNodeMap;
- let vnode = target;
-
- if (vnode && vnode.nodeName === 'BODY' && vnode.$$id) {
- this.mountNode.$$id = vnode.$$id;
- }
-
- let parent = sharedNodeMap.get(vnode);
- if (removedNodes) {
- for (let i = removedNodes.length; i--;) {
- let node = sharedNodeMap.get(removedNodes[i]);
- /**
- * @NOTE For performance:
- * do not remove style element or textContent of style element.
- */
- if (
- parent
- && parent.nodeName !== STYLE_ELEMENT
- && node
- && node.nodeName !== STYLE_ELEMENT
- ) {
- sharedNodeMap.delete(node);
- parent.removeChild(node);
- }
- }
- }
-
- if (addedNodes) {
- for (let i = 0; i < addedNodes.length; i++) {
- let newNode = sharedNodeMap.get(addedNodes[i]);
- if (!newNode) {
- newNode = this.createNode(addedNodes[i]);
- }
-
- if (parent) {
- let siblingElement = nextSibling && sharedNodeMap.get(nextSibling) || null;
- parent.insertBefore(newNode, siblingElement);
- }
- }
- }
- }
-
- createNode(vnode) {
- let node = createNode(vnode);
-
- if (vnode.nodeType === 1 && getTagName(vnode.nodeName)) {
- if (vnode.className) {
- node.className = vnode.className;
- }
-
- if (vnode.style) {
- setStyle(node, vnode.style);
- }
-
- if (vnode.attributes) {
- for (let i = 0; i < vnode.attributes.length; i++) {
- let { name, value } = vnode.attributes[i];
- setAttribute(node, name, value);
- }
- }
-
- if (vnode.childNodes) {
- for (let i = 0; i < vnode.childNodes.length; i++) {
- node.appendChild(this.createNode(vnode.childNodes[i]));
- }
- }
-
- if (vnode.events) {
- for (let i = 0; i < vnode.events.length; i++) {
- this.eventHandler.addEvent(node, vnode.events[i]);
- }
- }
- }
-
- this.sharedNodeMap.set(vnode, node);
-
- return node;
- }
-
- attributes({ target, attributeName, newValue, style }) {
- let node = this.sharedNodeMap.get(target);
- // Node maybe null when node is removed and there is a setInterval change the node that will cause error
- if (!node) return;
-
- if (style) {
- setAttribute(node, 'style', style);
- }
- if (attributeName) {
- setAttribute(node, attributeName, newValue);
- }
- }
-
- characterData({ target, newValue }) {
- let node = this.sharedNodeMap.get(target);
- node[TEXT_CONTENT_ATTR] = newValue;
- }
-
- addEvent({ target, eventName }) {
- let node = this.sharedNodeMap.get(target);
- if (!node) return;
- this.eventHandler.addEvent(node, eventName);
- }
-
- removeEvent({ target, eventName }) {
- let node = this.sharedNodeMap.get(target);
- if (!node) return;
-
- this.eventHandler.removeEvent(node, eventName);
- }
-
- canvasRenderingContext2D({ target, method, args, properties }) {
- let canvas = this.sharedNodeMap.get(target);
- if (!canvas) return;
-
- let context = canvas.getContext('2d');
-
- if (properties) {
- for (let key in properties) {
- if (properties.hasOwnProperty(key)) {
- context[key] = properties[key];
- }
- }
- }
-
- if (method) {
- context[method].apply(context, args);
- }
- }
-
- destroy() {
- this.eventHandler.removeAllEvents();
- this.sharedNodeMap = null;
- this.mountNode.parentElement.removeChild(this.mountNode);
- }
-}
diff --git a/packages/rax-miniapp-renderer/src/NodeMap.js b/packages/rax-miniapp-renderer/src/NodeMap.js
deleted file mode 100644
index 33ff3d6aa8..0000000000
--- a/packages/rax-miniapp-renderer/src/NodeMap.js
+++ /dev/null
@@ -1,40 +0,0 @@
-
-export default class NodeMap {
- _map = new Map();
-
- _setMountNode(mountNode) {
- this.mountNode = mountNode;
- }
-
- get(vnode) {
- if (!vnode) return null;
- if (vnode.nodeName === 'BODY') return this.mountNode;
- return this._map.get(vnode.$$id);
- }
-
- set(vnode, node) {
- node.$$id = vnode.$$id;
- return this._map.set(vnode.$$id, node);
- }
-
- delete(vnode) {
- if (!vnode) return null;
- const node = this._map.get(vnode.$$id);
- if (node) traverseNodes(node, el => el.$$id && this._map.delete(el.$$id));
- }
-}
-
-/**
- * Traverse HTML Node in DFS (trailing call).
- * @param node {Node}
- * @param effect {Function}
- */
-function traverseNodes(node, effect) {
- if (node.childNodes.length > 0) {
- for (let i = 0, l = node.childNodes.length; i < l; i++) {
- traverseNodes(node.childNodes[i], effect);
- effect(node.childNodes[i]);
- }
- }
- effect(node);
-}
diff --git a/packages/rax-miniapp-renderer/src/attrs.js b/packages/rax-miniapp-renderer/src/attrs.js
deleted file mode 100644
index c2fb9cdd14..0000000000
--- a/packages/rax-miniapp-renderer/src/attrs.js
+++ /dev/null
@@ -1,42 +0,0 @@
-import { setStyle } from './styles';
-import camelCase from './camelCase';
-import kebabCase from './kebabCase';
-
-const STYLE = 'style';
-const INVALID_ATTRS_MAP = {
- /**
- * In web components, slot attribute has side effects to
- * deliver child nodes.
- */
- slot: true,
-};
-
-export function isInvalidAttr(attr) {
- return INVALID_ATTRS_MAP.hasOwnProperty(attr);
-}
-
-export function setAttribute(node, attrName, value) {
- if (isInvalidAttr(attrName)) return;
-
- if (attrName === STYLE) {
- setStyle(node, value);
- return;
- }
-
- if (typeof value === 'object' || typeof value === 'boolean') {
- /**
- * Transform kebab cased attribute name to camel cased property name.
- *
- * ->
- * el.fooBar = true;
- */
- node[camelCase(attrName)] = value;
- } else {
- attrName = kebabCase(attrName);
- if (value == null) {
- node.removeAttribute(attrName);
- } else {
- node.setAttribute(attrName, value);
- }
- }
-}
diff --git a/packages/rax-miniapp-renderer/src/camelCase.js b/packages/rax-miniapp-renderer/src/camelCase.js
deleted file mode 100644
index 5977405582..0000000000
--- a/packages/rax-miniapp-renderer/src/camelCase.js
+++ /dev/null
@@ -1,11 +0,0 @@
-const CAMELCASE_REG = /-[a-z]/g;
-const CamelCaseCache = {};
-
-export default function camelCase(str) {
- return (
- CamelCaseCache[str] ||
- (CamelCaseCache[str] = str.replace(CAMELCASE_REG, $1 =>
- $1.slice(1).toUpperCase()
- ))
- );
-}
diff --git a/packages/rax-miniapp-renderer/src/index.js b/packages/rax-miniapp-renderer/src/index.js
deleted file mode 100644
index a112a5af6c..0000000000
--- a/packages/rax-miniapp-renderer/src/index.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/* global DEVICE_WIDTH */
-import MutationHandler from './MutationHandler';
-import EvaluationHandler from './EvaluationHandler';
-import LocationHandler from './LocationHandler';
-
-export default ({ worker, mountNode }) => {
- const postMessage = worker.postMessage.bind(worker);
-
- let handlers = {
- MutationRecord: new MutationHandler(postMessage, mountNode),
- EvaluationRecord: new EvaluationHandler(postMessage),
-
- // Deprecated handler.
- Location: new LocationHandler(postMessage),
- };
-
- worker.onmessage = ({ data }) => {
- let type = data.type;
- if (handlers[type]) {
- handlers[type].apply(data);
- } else {
- console.error('Can not handle with ' + type, data);
- }
- };
-
- worker.postMessage({
- type: 'init',
- url: location.href,
- width: getDeviceWidth(),
- });
-
- return function unmount() {
- handlers.MutationRecord.destroy();
- worker.onmessage = noop;
- handlers = null;
- };
-};
-
-/**
- * Get device base width
- * @return {number}
- */
-function getDeviceWidth() {
- return typeof DEVICE_WIDTH !== 'undefined'
- ? DEVICE_WIDTH
- : document.documentElement.clientWidth;
-}
-
-function noop() {}
diff --git a/packages/rax-miniapp-renderer/src/kebabCase.js b/packages/rax-miniapp-renderer/src/kebabCase.js
deleted file mode 100644
index 6503d8e132..0000000000
--- a/packages/rax-miniapp-renderer/src/kebabCase.js
+++ /dev/null
@@ -1,20 +0,0 @@
-const KebabCache = {};
-
-export default function kebabCase(string) {
- if (KebabCache[string]) {
- return KebabCache[string];
- }
-
- let kebab = '';
- for (let i = 0, l = string.length; i < l; i++) {
- if (/[a-z]/.test(string[i])) {
- kebab += string[i];
- } else if (/[A-Z]/.test(string[i])) {
- kebab += '-' + string[i].toLowerCase();
- } else if (string[i] === '-') {
- kebab += '-';
- }
- }
-
- return KebabCache[string] = kebab;
-}
diff --git a/packages/rax-miniapp-renderer/src/nodes.js b/packages/rax-miniapp-renderer/src/nodes.js
deleted file mode 100644
index 203bdf46d5..0000000000
--- a/packages/rax-miniapp-renderer/src/nodes.js
+++ /dev/null
@@ -1,37 +0,0 @@
-const CUSTOM_TAG_PREFIX = 'a-';
-
-/**
- * Whitelist that declear w3c standard tag names.
- */
-const w3cTags = {
- style: true,
-};
-
-function isValidW3CTag(tagName) {
- return w3cTags.hasOwnProperty(tagName);
-}
-
-/**
- * Format tag name.
- */
-export function getTagName(nodeName) {
- const tagName = String(nodeName).toLowerCase();
- if (isValidW3CTag(tagName)) {
- return tagName;
- } else {
- return CUSTOM_TAG_PREFIX + tagName;
- }
-}
-
-export function createNode(vnode) {
- let node, tagName;
- if (vnode.nodeType === 3) {
- node = document.createTextNode(vnode.data);
- } else if (vnode.nodeType === 1 && (tagName = getTagName(vnode.nodeName))) {
- node = document.createElement(tagName);
- } else if (vnode.nodeType === 8) {
- node = document.createComment(vnode.data);
- }
-
- return node;
-}
diff --git a/packages/rax-miniapp-renderer/src/styles.js b/packages/rax-miniapp-renderer/src/styles.js
deleted file mode 100644
index 5020af274e..0000000000
--- a/packages/rax-miniapp-renderer/src/styles.js
+++ /dev/null
@@ -1,107 +0,0 @@
-const PREFIX_PROPS = {
- flex: true,
- alignItems: true,
- alignSelf: true,
- flexDirection: true,
- justifyContent: true,
- flexWrap: true,
-
- lineClamp: true,
- textSizeAdjust: true,
- textDecorationLine: true,
- textDecorationColor: true,
- textDecorationStyle: true,
- textDecorationSkip: true,
- writingMode: true,
-
- animatin: true,
- animationName: true,
- animationDuration: true,
- animationTimingFunction: true,
- animationDelay: true,
- animationIterationCount: true,
- animationDirection: true,
- animationFillMode: true,
- animationPlayState: true,
-
- transform: true,
- transformOrigin: true,
- transformStyle: true,
- perspective: true,
- perspectiveOrigin: true,
- backfaceVisibility: true,
- appearance: true,
- userSelect: true,
-
- columns: true,
- columnWidth: true,
- columnCount: true,
- columnGap: true,
- columnRule: true,
- columnRuleWidth: true,
- columnRuleStyle: true,
- columnRuleColor: true,
- columnSpan: true,
- columnFill: true,
- columnBreakBefore: true,
- columnBreakAfter: true,
- columnBreakInside: true,
-};
-
-const PREFIX_PROP_VALS = {
- position: 'sticky',
- display: 'flex',
-};
-
-const StylePrefixer = {
- shouldPrefix(prop) {
- return PREFIX_PROPS[prop] || PREFIX_PROP_VALS[prop];
- },
-};
-
-Object.keys(PREFIX_PROPS).forEach((prop) => {
- const vendorProp = 'webkit' + prop[0].toUpperCase() + prop.slice(1);
- StylePrefixer[prop] = (value, style = {}) => {
- style[vendorProp] = value;
- style[prop] = value;
- return style;
- };
-});
-
-Object.keys(PREFIX_PROP_VALS).forEach((prop) => {
- const rule = PREFIX_PROP_VALS[prop];
- StylePrefixer[prop] = (value, style = {}) => {
- if (value === rule) {
- style[prop] = ['-webkit-' + rule, rule];
- } else {
- style[prop] = value;
- }
- return style;
- };
-});
-
-export function setStyle(node, styleObject) {
- let tranformedStyles = {};
-
- for (let prop in styleObject) {
- let val = styleObject[prop];
- if (StylePrefixer.shouldPrefix(prop)) {
- StylePrefixer[prop](val, tranformedStyles);
- } else {
- tranformedStyles[prop] = val;
- }
- }
-
- for (let prop in tranformedStyles) {
- const transformValue = tranformedStyles[prop];
- // if browser only accept -webkit-flex
- // node.style.display = 'flex' will not work
- if (Array.isArray(transformValue)) {
- for (let i = 0; i < transformValue.length; i++) {
- node.style[prop] = transformValue[i];
- }
- } else {
- node.style[prop] = transformValue;
- }
- }
-}
diff --git a/packages/rax-miniapp-renderer/src/supports.js b/packages/rax-miniapp-renderer/src/supports.js
deleted file mode 100644
index f3aa6c2a24..0000000000
--- a/packages/rax-miniapp-renderer/src/supports.js
+++ /dev/null
@@ -1,11 +0,0 @@
-// feature-detect support for event listener options
-let supportsPassive = false;
-try {
- addEventListener('test', null, {
- get passive() {
- supportsPassive = true;
- }
- });
-} catch (e) { }
-
-export let passive = supportsPassive;
diff --git a/packages/runtime-shared/README.md b/packages/runtime-shared/README.md
deleted file mode 100644
index 436c14387e..0000000000
--- a/packages/runtime-shared/README.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# runtime-shared
-
-
-## Polyfills
-
-
-ES6
-
-* Object.{[assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign), [is](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)}
-* Number.{[isNaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN), [isInteger](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger), [isFinite](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite), [EPSILON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON), [MIN_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER), [MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)}
-* String.prototype.{[startsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith), [endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith), [repeat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat), [includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes), [codePointAt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)}
-* Array.{[from](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from), [to](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/to)}
-* Array.prototype.{[find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find), [findIndex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)}
-
-ES7
-
-* Array.prototype.{[includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)}
-
-ES8
-
-* String.prototype.{[padStart](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart), [padEnd](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)}
-* Object.{[entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries), [values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)}
diff --git a/packages/runtime-shared/package.json b/packages/runtime-shared/package.json
deleted file mode 100644
index 2e793e7a8a..0000000000
--- a/packages/runtime-shared/package.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "name": "runtime-shared",
- "version": "0.6.6-1",
- "description": "Shared Runtime.",
- "license": "BSD-3-Clause",
- "main": "lib/index.js",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/alibaba/rax.git"
- },
- "bugs": {
- "url": "https://github.com/alibaba/rax/issues"
- },
- "homepage": "https://github.com/alibaba/rax#readme"
-}
diff --git a/packages/runtime-shared/src/__tests__/url.js b/packages/runtime-shared/src/__tests__/url.js
deleted file mode 100644
index db49529fae..0000000000
--- a/packages/runtime-shared/src/__tests__/url.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import URL from '../url';
-
-describe('URL', () => {
- it('accept url with proctal', () => {
- var url = new URL('http://example.com/path/to?query=string');
- expect(url.search).toEqual('?query=string');
- expect(url.hostname).toEqual('example.com');
- });
-});
diff --git a/packages/runtime-shared/src/appear/IntersectionObserver.js b/packages/runtime-shared/src/appear/IntersectionObserver.js
deleted file mode 100644
index 3ca807c701..0000000000
--- a/packages/runtime-shared/src/appear/IntersectionObserver.js
+++ /dev/null
@@ -1,652 +0,0 @@
-/**
- * An IntersectionObserver registry. This registry exists to hold a strong
- * reference to IntersectionObserver instances currently observing a target
- * element. Without this registry, instances without another reference may be
- * garbage collected.
- */
-const registry = [];
-
-
-/**
- * Creates the global IntersectionObserverEntry constructor.
- * https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
- * @param {Object} entry A dictionary of instance properties.
- * @constructor
- */
-export function IntersectionObserverEntry(entry) {
- this.time = entry.time;
- this.target = entry.target;
- this.rootBounds = entry.rootBounds;
- this.boundingClientRect = entry.boundingClientRect;
- this.intersectionRect = entry.intersectionRect || getEmptyRect();
- this.isIntersecting = !!entry.intersectionRect;
-
- // Calculates the intersection ratio.
- const targetRect = this.boundingClientRect;
- const targetArea = targetRect.width * targetRect.height;
- const intersectionRect = this.intersectionRect;
- const intersectionArea = intersectionRect.width * intersectionRect.height;
-
- // Sets intersection ratio.
- if (targetArea) {
- // Round the intersection ratio to avoid floating point math issues:
- // https://github.com/w3c/IntersectionObserver/issues/324
- this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
- } else {
- // If area is zero and is intersecting, sets to 1, otherwise to 0
- this.intersectionRatio = this.isIntersecting ? 1 : 0;
- }
-}
-
-export default class IntersectionObserver {
- /**
- * The minimum interval within which the document will be checked for
- * intersection changes.
- */
- THROTTLE_TIMEOUT = 100;
-
- /**
- * The frequency in which the polyfill polls for intersection changes.
- * this can be updated on a per instance basis and must be set prior to
- * calling `observe` on the first target.
- */
- POLL_INTERVAL = null;
-
- /**
- * Use a mutation observer on the root element
- * to detect intersection changes.
- */
- USE_MUTATION_OBSERVER = true;
-
- /**
- * Creates the global IntersectionObserver constructor.
- * https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
- * @param {Function} callback The function to be invoked after intersection
- * changes have queued. The function is not invoked if the queue has
- * been emptied by calling the `takeRecords` method.
- * @param {Object=} optOptions Optional configuration options.
- * @constructor
- */
- constructor(callback, optOptions) {
- const options = optOptions || {};
-
- if (typeof callback != 'function') {
- throw new Error('callback must be a function');
- }
-
- if (options.root && options.root.nodeType != 1) {
- throw new Error('root must be an Element');
- }
-
- // Throttles `this._checkForIntersections`.
- this._checkForIntersections = throttle(this._checkForIntersections, this.THROTTLE_TIMEOUT);
-
- // Private properties.
- this._callback = callback;
- this._observationTargets = [];
- this._queuedEntries = [];
- this._rootMarginValues = this._parseRootMargin(options.rootMargin);
-
- // Public properties.
- this.thresholds = this._initThresholds(options.threshold);
- this.root = options.root || null;
- this.rootMargin = this._rootMarginValues.map((margin) => margin.value + margin.unit).join(' ');
- }
-
- /**
- * Starts observing a target element for intersection changes based on
- * the thresholds values.
- * @param {Element} target The DOM element to observe.
- */
- observe(target) {
- const isTargetAlreadyObserved = this._observationTargets.some((item) => item.element === target);
-
- if (isTargetAlreadyObserved) {
- return;
- }
-
- if (!(target && target.nodeType == 1)) {
- throw new Error('target must be an Element');
- }
-
- this._registerInstance();
- this._observationTargets.push({element: target, entry: null});
- this._monitorIntersections();
- this._checkForIntersections();
- }
-
- /**
- * Stops observing a target element for intersection changes.
- * @param {Element} target The DOM element to observe.
- */
- unobserve(target) {
- this._observationTargets =
- this._observationTargets.filter(function(item) {
- return item.element !== target;
- });
- if (!this._observationTargets.length) {
- this._unmonitorIntersections();
- this._unregisterInstance();
- }
- }
-
- /**
- * Stops observing all target elements for intersection changes.
- */
- disconnect() {
- this._observationTargets = [];
- this._unmonitorIntersections();
- this._unregisterInstance();
- }
-
- /**
- * Returns any queue entries that have not yet been reported to the
- * callback and clears the queue. This can be used in conjunction with the
- * callback to obtain the absolute most up-to-date intersection information.
- * @return {Array} The currently queued entries.
- */
- takeRecords() {
- const records = this._queuedEntries.slice();
- this._queuedEntries = [];
- return records;
- }
-
- /**
- * Accepts the threshold value from the user configuration object and
- * returns a sorted array of unique threshold values. If a value is not
- * between 0 and 1 and error is thrown.
- * @private
- * @param {Array|number=} optThreshold An optional threshold value or
- * a list of threshold values, defaulting to [0].
- * @return {Array} A sorted list of unique and valid threshold values.
- */
- _initThresholds(optThreshold) {
- let threshold = optThreshold || [0];
- if (!Array.isArray(threshold)) threshold = [threshold];
-
- return threshold.sort().filter(function(t, i, a) {
- if (typeof t != 'number' || isNaN(t) || t < 0 || t > 1) {
- throw new Error('threshold must be a number between 0 and 1 inclusively');
- }
- return t !== a[i - 1];
- });
- }
-
- /**
- * Accepts the rootMargin value from the user configuration object
- * and returns an array of the four margin values as an object containing
- * the value and unit properties. If any of the values are not properly
- * formatted or use a unit other than px or %, and error is thrown.
- * @private
- * @param {string=} optRootMargin An optional rootMargin value,
- * defaulting to '0px'.
- * @return {Array