react-art
Version:
React ART is a JavaScript library for drawing vector graphics using React. It provides declarative and reactive bindings to the ART library. Using the same declarative API you can render the output to either Canvas, SVG or VML (IE8).
1,679 lines (1,405 loc) • 632 kB
JavaScript
/** @license React v16.13.0
* react-art.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
typeof define === 'function' && define.amd ? define(['react'], factory) :
(global = global || self, global.ReactART = factory(global.React));
}(this, (function (React) { 'use strict';
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
var ReactVersion = '16.13.0';
var LegacyRoot = 0;
var BlockingRoot = 1;
var ConcurrentRoot = 2;
var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
var _assign = ReactInternals.assign;
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
// Current owner and dispatcher used to share the same ref,
// but PR #14548 split them out to better support the react-debug-tools package.
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
ReactSharedInternals.ReactCurrentDispatcher = {
current: null
};
}
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
ReactSharedInternals.ReactCurrentBatchConfig = {
suspense: null
};
}
// by calls to these methods by a Babel plugin.
//
// In PROD (or in packages without access to React internals),
// they are left as they are instead.
function warn(format) {
{
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
printWarning('warn', format, args);
}
}
function error(format) {
{
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
printWarning('error', format, args);
}
}
function printWarning(level, format, args) {
// When changing this logic, you might want to also
// update consoleWithStackDev.www.js as well.
{
var hasExistingStack = args.length > 0 && typeof args[args.length - 1] === 'string' && args[args.length - 1].indexOf('\n in') === 0;
if (!hasExistingStack) {
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
var stack = ReactDebugCurrentFrame.getStackAddendum();
if (stack !== '') {
format += '%s';
args = args.concat([stack]);
}
}
var argsWithFormat = args.map(function (item) {
return '' + item;
}); // Careful: RN currently depends on this prefix
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
// breaks IE9: https://github.com/facebook/react/issues/13610
// eslint-disable-next-line react-internal/no-production-logging
Function.prototype.apply.call(console[level], console, argsWithFormat);
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
throw new Error(message);
} catch (x) {}
}
}
var FunctionComponent = 0;
var ClassComponent = 1;
var IndeterminateComponent = 2; // Before we know whether it is function or class
var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
var HostComponent = 5;
var HostText = 6;
var Fragment = 7;
var Mode = 8;
var ContextConsumer = 9;
var ContextProvider = 10;
var ForwardRef = 11;
var Profiler = 12;
var SuspenseComponent = 13;
var MemoComponent = 14;
var SimpleMemoComponent = 15;
var LazyComponent = 16;
var IncompleteClassComponent = 17;
var DehydratedFragment = 18;
var SuspenseListComponent = 19;
var FundamentalComponent = 20;
var ScopeComponent = 21;
var Block = 22;
/**
* `ReactInstanceMap` maintains a mapping from a public facing stateful
* instance (key) and the internal representation (value). This allows public
* methods to accept the user facing instance as an argument and map them back
* to internal methods.
*
* Note that this module is currently shared and assumed to be stateless.
* If this becomes an actual Map, that will break.
*/
function get(key) {
return key._reactInternalFiber;
}
function set(key, value) {
key._reactInternalFiber = value;
}
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
// nor polyfill, then a plain number is used for performance.
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
var FAUX_ITERATOR_SYMBOL = '@@iterator';
function getIteratorFn(maybeIterable) {
if (maybeIterable === null || typeof maybeIterable !== 'object') {
return null;
}
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
if (typeof maybeIterator === 'function') {
return maybeIterator;
}
return null;
}
var Uninitialized = -1;
var Pending = 0;
var Resolved = 1;
var Rejected = 2;
function refineResolvedLazyComponent(lazyComponent) {
return lazyComponent._status === Resolved ? lazyComponent._result : null;
}
function initializeLazyComponentType(lazyComponent) {
if (lazyComponent._status === Uninitialized) {
lazyComponent._status = Pending;
var ctor = lazyComponent._ctor;
var thenable = ctor();
lazyComponent._result = thenable;
thenable.then(function (moduleObject) {
if (lazyComponent._status === Pending) {
var defaultExport = moduleObject.default;
{
if (defaultExport === undefined) {
error('lazy: Expected the result of a dynamic import() call. ' + 'Instead received: %s\n\nYour code should look like: \n ' + "const MyComponent = lazy(() => import('./MyComponent'))", moduleObject);
}
}
lazyComponent._status = Resolved;
lazyComponent._result = defaultExport;
}
}, function (error) {
if (lazyComponent._status === Pending) {
lazyComponent._status = Rejected;
lazyComponent._result = error;
}
});
}
}
function getWrappedName(outerType, innerType, wrapperName) {
var functionName = innerType.displayName || innerType.name || '';
return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
}
function getComponentName(type) {
if (type == null) {
// Host root, text node or just invalid type.
return null;
}
{
if (typeof type.tag === 'number') {
error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
}
}
if (typeof type === 'function') {
return type.displayName || type.name || null;
}
if (typeof type === 'string') {
return type;
}
switch (type) {
case REACT_FRAGMENT_TYPE:
return 'Fragment';
case REACT_PORTAL_TYPE:
return 'Portal';
case REACT_PROFILER_TYPE:
return "Profiler";
case REACT_STRICT_MODE_TYPE:
return 'StrictMode';
case REACT_SUSPENSE_TYPE:
return 'Suspense';
case REACT_SUSPENSE_LIST_TYPE:
return 'SuspenseList';
}
if (typeof type === 'object') {
switch (type.$$typeof) {
case REACT_CONTEXT_TYPE:
return 'Context.Consumer';
case REACT_PROVIDER_TYPE:
return 'Context.Provider';
case REACT_FORWARD_REF_TYPE:
return getWrappedName(type, type.render, 'ForwardRef');
case REACT_MEMO_TYPE:
return getComponentName(type.type);
case REACT_BLOCK_TYPE:
return getComponentName(type.render);
case REACT_LAZY_TYPE:
{
var thenable = type;
var resolvedThenable = refineResolvedLazyComponent(thenable);
if (resolvedThenable) {
return getComponentName(resolvedThenable);
}
break;
}
}
}
return null;
}
// Don't change these two values. They're used by React Dev Tools.
var NoEffect =
/* */
0;
var PerformedWork =
/* */
1; // You can change the rest (and add more).
var Placement =
/* */
2;
var Update =
/* */
4;
var PlacementAndUpdate =
/* */
6;
var Deletion =
/* */
8;
var ContentReset =
/* */
16;
var Callback =
/* */
32;
var DidCapture =
/* */
64;
var Ref =
/* */
128;
var Snapshot =
/* */
256;
var Passive =
/* */
512;
var Hydrating =
/* */
1024;
var HydratingAndUpdate =
/* */
1028; // Passive & Update & Callback & Ref & Snapshot
var LifecycleEffectMask =
/* */
932; // Union of all host effects
var HostEffectMask =
/* */
2047;
var Incomplete =
/* */
2048;
var ShouldCapture =
/* */
4096;
var enableProfilerTimer = true; // Trace which interactions trigger each commit.
var enableFundamentalAPI = false; // Experimental Scope support.
var warnAboutStringRefs = false;
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
function getNearestMountedFiber(fiber) {
var node = fiber;
var nearestMounted = fiber;
if (!fiber.alternate) {
// If there is no alternate, this might be a new tree that isn't inserted
// yet. If it is, then it will have a pending insertion effect on it.
var nextNode = node;
do {
node = nextNode;
if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
// This is an insertion or in-progress hydration. The nearest possible
// mounted fiber is the parent but we need to continue to figure out
// if that one is still mounted.
nearestMounted = node.return;
}
nextNode = node.return;
} while (nextNode);
} else {
while (node.return) {
node = node.return;
}
}
if (node.tag === HostRoot) {
// TODO: Check if this was a nested HostRoot when used with
// renderContainerIntoSubtree.
return nearestMounted;
} // If we didn't hit the root, that means that we're in an disconnected tree
// that has been unmounted.
return null;
}
function isFiberMounted(fiber) {
return getNearestMountedFiber(fiber) === fiber;
}
function isMounted(component) {
{
var owner = ReactCurrentOwner.current;
if (owner !== null && owner.tag === ClassComponent) {
var ownerFiber = owner;
var instance = ownerFiber.stateNode;
if (!instance._warnedAboutRefsInRender) {
error('%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber.type) || 'A component');
}
instance._warnedAboutRefsInRender = true;
}
}
var fiber = get(component);
if (!fiber) {
return false;
}
return getNearestMountedFiber(fiber) === fiber;
}
function assertIsMounted(fiber) {
if (!(getNearestMountedFiber(fiber) === fiber)) {
{
throw Error( "Unable to find node on an unmounted component." );
}
}
}
function findCurrentFiberUsingSlowPath(fiber) {
var alternate = fiber.alternate;
if (!alternate) {
// If there is no alternate, then we only need to check if it is mounted.
var nearestMounted = getNearestMountedFiber(fiber);
if (!(nearestMounted !== null)) {
{
throw Error( "Unable to find node on an unmounted component." );
}
}
if (nearestMounted !== fiber) {
return null;
}
return fiber;
} // If we have two possible branches, we'll walk backwards up to the root
// to see what path the root points to. On the way we may hit one of the
// special cases and we'll deal with them.
var a = fiber;
var b = alternate;
while (true) {
var parentA = a.return;
if (parentA === null) {
// We're at the root.
break;
}
var parentB = parentA.alternate;
if (parentB === null) {
// There is no alternate. This is an unusual case. Currently, it only
// happens when a Suspense component is hidden. An extra fragment fiber
// is inserted in between the Suspense fiber and its children. Skip
// over this extra fragment fiber and proceed to the next parent.
var nextParent = parentA.return;
if (nextParent !== null) {
a = b = nextParent;
continue;
} // If there's no parent, we're at the root.
break;
} // If both copies of the parent fiber point to the same child, we can
// assume that the child is current. This happens when we bailout on low
// priority: the bailed out fiber's child reuses the current child.
if (parentA.child === parentB.child) {
var child = parentA.child;
while (child) {
if (child === a) {
// We've determined that A is the current branch.
assertIsMounted(parentA);
return fiber;
}
if (child === b) {
// We've determined that B is the current branch.
assertIsMounted(parentA);
return alternate;
}
child = child.sibling;
} // We should never have an alternate for any mounting node. So the only
// way this could possibly happen is if this was unmounted, if at all.
{
{
throw Error( "Unable to find node on an unmounted component." );
}
}
}
if (a.return !== b.return) {
// The return pointer of A and the return pointer of B point to different
// fibers. We assume that return pointers never criss-cross, so A must
// belong to the child set of A.return, and B must belong to the child
// set of B.return.
a = parentA;
b = parentB;
} else {
// The return pointers point to the same fiber. We'll have to use the
// default, slow path: scan the child sets of each parent alternate to see
// which child belongs to which set.
//
// Search parent A's child set
var didFindChild = false;
var _child = parentA.child;
while (_child) {
if (_child === a) {
didFindChild = true;
a = parentA;
b = parentB;
break;
}
if (_child === b) {
didFindChild = true;
b = parentA;
a = parentB;
break;
}
_child = _child.sibling;
}
if (!didFindChild) {
// Search parent B's child set
_child = parentB.child;
while (_child) {
if (_child === a) {
didFindChild = true;
a = parentB;
b = parentA;
break;
}
if (_child === b) {
didFindChild = true;
b = parentB;
a = parentA;
break;
}
_child = _child.sibling;
}
if (!didFindChild) {
{
throw Error( "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." );
}
}
}
}
if (!(a.alternate === b)) {
{
throw Error( "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." );
}
}
} // If the root is not a host container, we're in a disconnected tree. I.e.
// unmounted.
if (!(a.tag === HostRoot)) {
{
throw Error( "Unable to find node on an unmounted component." );
}
}
if (a.stateNode.current === a) {
// We've determined that A is the current branch.
return fiber;
} // Otherwise B has to be current branch.
return alternate;
}
function findCurrentHostFiber(parent) {
var currentParent = findCurrentFiberUsingSlowPath(parent);
if (!currentParent) {
return null;
} // Next we'll drill down this component to find the first HostComponent/Text.
var node = currentParent;
while (true) {
if (node.tag === HostComponent || node.tag === HostText) {
return node;
} else if (node.child) {
node.child.return = node;
node = node.child;
continue;
}
if (node === currentParent) {
return null;
}
while (!node.sibling) {
if (!node.return || node.return === currentParent) {
return null;
}
node = node.return;
}
node.sibling.return = node.return;
node = node.sibling;
} // Flow needs the return null here, but ESLint complains about it.
// eslint-disable-next-line no-unreachable
return null;
}
var _class = function(mixins){
var proto = {};
for (var i = 0, l = arguments.length; i < l; i++){
var mixin = arguments[i];
if (typeof mixin == 'function') mixin = mixin.prototype;
for (var key in mixin) proto[key] = mixin[key];
}
if (!proto.initialize) proto.initialize = function(){};
proto.constructor = function(a,b,c,d,e,f,g,h){
return new proto.initialize(a,b,c,d,e,f,g,h);
};
proto.constructor.prototype = proto.initialize.prototype = proto;
return proto.constructor;
};
function Transform(xx, yx, xy, yy, x, y){
if (xx && typeof xx == 'object'){
yx = xx.yx; yy = xx.yy; y = xx.y;
xy = xx.xy; x = xx.x; xx = xx.xx;
}
this.xx = xx == null ? 1 : xx;
this.yx = yx || 0;
this.xy = xy || 0;
this.yy = yy == null ? 1 : yy;
this.x = (x == null ? this.x : x) || 0;
this.y = (y == null ? this.y : y) || 0;
this._transform();
return this;
}
var transform = _class({
initialize: Transform,
_transform: function(){},
xx: 1, yx: 0, x: 0,
xy: 0, yy: 1, y: 0,
transform: function(xx, yx, xy, yy, x, y){
var m = this;
if (xx && typeof xx == 'object'){
yx = xx.yx; yy = xx.yy; y = xx.y;
xy = xx.xy; x = xx.x; xx = xx.xx;
}
if (!x) x = 0;
if (!y) y = 0;
return this.transformTo(
m.xx * xx + m.xy * yx,
m.yx * xx + m.yy * yx,
m.xx * xy + m.xy * yy,
m.yx * xy + m.yy * yy,
m.xx * x + m.xy * y + m.x,
m.yx * x + m.yy * y + m.y
);
},
transformTo: Transform,
translate: function(x, y){
return this.transform(1, 0, 0, 1, x, y);
},
move: function(x, y){
this.x += x || 0;
this.y += y || 0;
this._transform();
return this;
},
scale: function(x, y){
if (y == null) y = x;
return this.transform(x, 0, 0, y, 0, 0);
},
rotate: function(deg, x, y){
if (x == null || y == null){
x = (this.left || 0) + (this.width || 0) / 2;
y = (this.top || 0) + (this.height || 0) / 2;
}
var rad = deg * Math.PI / 180, sin = Math.sin(rad), cos = Math.cos(rad);
this.transform(1, 0, 0, 1, x, y);
var m = this;
return this.transformTo(
cos * m.xx - sin * m.yx,
sin * m.xx + cos * m.yx,
cos * m.xy - sin * m.yy,
sin * m.xy + cos * m.yy,
m.x,
m.y
).transform(1, 0, 0, 1, -x, -y);
},
moveTo: function(x, y){
var m = this;
return this.transformTo(m.xx, m.yx, m.xy, m.yy, x, y);
},
rotateTo: function(deg, x, y){
var m = this;
var flip = m.yx / m.xx > m.yy / m.xy ? -1 : 1;
if (m.xx < 0 ? m.xy >= 0 : m.xy < 0) flip = -flip;
return this.rotate(deg - Math.atan2(flip * m.yx, flip * m.xx) * 180 / Math.PI, x, y);
},
scaleTo: function(x, y){
// Normalize
var m = this;
var h = Math.sqrt(m.xx * m.xx + m.yx * m.yx);
m.xx /= h; m.yx /= h;
h = Math.sqrt(m.yy * m.yy + m.xy * m.xy);
m.yy /= h; m.xy /= h;
return this.scale(x, y);
},
resizeTo: function(width, height){
var w = this.width, h = this.height;
if (!w || !h) return this;
return this.scaleTo(width / w, height / h);
},
/*
inverse: function(){
var a = this.xx, b = this.yx,
c = this.xy, d = this.yy,
e = this.x, f = this.y;
if (a * d - b * c == 0) return null;
return new Transform(
d/(a * d-b * c), b/(b * c-a * d),
c/(b * c-a * d), a/(a * d-b * c),
(d * e-c * f)/(b * c-a * d), (b * e-a * f)/(a * d-b * c)
);
},
*/
inversePoint: function(x, y){
var a = this.xx, b = this.yx,
c = this.xy, d = this.yy,
e = this.x, f = this.y;
var det = b * c - a * d;
if (det == 0) return null;
return {
x: (d * (e - x) + c * (y - f)) / det,
y: (a * (f - y) + b * (x - e)) / det
};
},
point: function(x, y){
var m = this;
return {
x: m.xx * x + m.xy * y + m.x,
y: m.yx * x + m.yy * y + m.y
};
}
});
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var current = createCommonjsModule(function (module, exports) {
function warning(){
throw new Error('You must require a mode before requiring anything else.');
}
exports.Surface = warning;
exports.Path = warning;
exports.Shape = warning;
exports.Group = warning;
exports.ClippingRectangle = warning;
exports.Text = warning;
exports.setCurrent = function(mode){
for (var key in mode){
exports[key] = mode[key];
}
};
});
var current_1 = current.Surface;
var current_2 = current.Path;
var current_3 = current.Shape;
var current_4 = current.Group;
var current_5 = current.ClippingRectangle;
var current_6 = current.Text;
var current_7 = current.setCurrent;
var TYPES = {
CLIPPING_RECTANGLE: 'ClippingRectangle',
GROUP: 'Group',
SHAPE: 'Shape',
TEXT: 'Text'
};
var EVENT_TYPES = {
onClick: 'click',
onMouseMove: 'mousemove',
onMouseOver: 'mouseover',
onMouseOut: 'mouseout',
onMouseUp: 'mouseup',
onMouseDown: 'mousedown'
};
function childrenAsString(children) {
if (!children) {
return '';
} else if (typeof children === 'string') {
return children;
} else if (children.length) {
return children.join('');
} else {
return '';
}
}
// can re-export everything from this module.
function shim() {
{
{
throw Error( "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue." );
}
}
} // Hydration (when unsupported)
var isSuspenseInstancePending = shim;
var isSuspenseInstanceFallback = shim;
var hydrateTextInstance = shim;
var pooledTransform = new transform();
var NO_CONTEXT = {};
var UPDATE_SIGNAL = {};
{
Object.freeze(NO_CONTEXT);
Object.freeze(UPDATE_SIGNAL);
}
/** Helper Methods */
function addEventListeners(instance, type, listener) {
// We need to explicitly unregister before unmount.
// For this reason we need to track subscriptions.
if (!instance._listeners) {
instance._listeners = {};
instance._subscriptions = {};
}
instance._listeners[type] = listener;
if (listener) {
if (!instance._subscriptions[type]) {
instance._subscriptions[type] = instance.subscribe(type, createEventHandler(instance), instance);
}
} else {
if (instance._subscriptions[type]) {
instance._subscriptions[type]();
delete instance._subscriptions[type];
}
}
}
function createEventHandler(instance) {
return function handleEvent(event) {
var listener = instance._listeners[event.type];
if (!listener) ; else if (typeof listener === 'function') {
listener.call(instance, event);
} else if (listener.handleEvent) {
listener.handleEvent(event);
}
};
}
function destroyEventListeners(instance) {
if (instance._subscriptions) {
for (var type in instance._subscriptions) {
instance._subscriptions[type]();
}
}
instance._subscriptions = null;
instance._listeners = null;
}
function getScaleX(props) {
if (props.scaleX != null) {
return props.scaleX;
} else if (props.scale != null) {
return props.scale;
} else {
return 1;
}
}
function getScaleY(props) {
if (props.scaleY != null) {
return props.scaleY;
} else if (props.scale != null) {
return props.scale;
} else {
return 1;
}
}
function isSameFont(oldFont, newFont) {
if (oldFont === newFont) {
return true;
} else if (typeof newFont === 'string' || typeof oldFont === 'string') {
return false;
} else {
return newFont.fontSize === oldFont.fontSize && newFont.fontStyle === oldFont.fontStyle && newFont.fontVariant === oldFont.fontVariant && newFont.fontWeight === oldFont.fontWeight && newFont.fontFamily === oldFont.fontFamily;
}
}
/** Render Methods */
function applyClippingRectangleProps(instance, props) {
var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
applyNodeProps(instance, props, prevProps);
instance.width = props.width;
instance.height = props.height;
}
function applyGroupProps(instance, props) {
var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
applyNodeProps(instance, props, prevProps);
instance.width = props.width;
instance.height = props.height;
}
function applyNodeProps(instance, props) {
var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var scaleX = getScaleX(props);
var scaleY = getScaleY(props);
pooledTransform.transformTo(1, 0, 0, 1, 0, 0).move(props.x || 0, props.y || 0).rotate(props.rotation || 0, props.originX, props.originY).scale(scaleX, scaleY, props.originX, props.originY);
if (props.transform != null) {
pooledTransform.transform(props.transform);
}
if (instance.xx !== pooledTransform.xx || instance.yx !== pooledTransform.yx || instance.xy !== pooledTransform.xy || instance.yy !== pooledTransform.yy || instance.x !== pooledTransform.x || instance.y !== pooledTransform.y) {
instance.transformTo(pooledTransform);
}
if (props.cursor !== prevProps.cursor || props.title !== prevProps.title) {
instance.indicate(props.cursor, props.title);
}
if (instance.blend && props.opacity !== prevProps.opacity) {
instance.blend(props.opacity == null ? 1 : props.opacity);
}
if (props.visible !== prevProps.visible) {
if (props.visible == null || props.visible) {
instance.show();
} else {
instance.hide();
}
}
for (var type in EVENT_TYPES) {
addEventListeners(instance, EVENT_TYPES[type], props[type]);
}
}
function applyRenderableNodeProps(instance, props) {
var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
applyNodeProps(instance, props, prevProps);
if (prevProps.fill !== props.fill) {
if (props.fill && props.fill.applyFill) {
props.fill.applyFill(instance);
} else {
instance.fill(props.fill);
}
}
if (prevProps.stroke !== props.stroke || prevProps.strokeWidth !== props.strokeWidth || prevProps.strokeCap !== props.strokeCap || prevProps.strokeJoin !== props.strokeJoin || // TODO: Consider deep check of stokeDash; may benefit VML in IE.
prevProps.strokeDash !== props.strokeDash) {
instance.stroke(props.stroke, props.strokeWidth, props.strokeCap, props.strokeJoin, props.strokeDash);
}
}
function applyShapeProps(instance, props) {
var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
applyRenderableNodeProps(instance, props, prevProps);
var path = props.d || childrenAsString(props.children);
var prevDelta = instance._prevDelta;
var prevPath = instance._prevPath;
if (path !== prevPath || path.delta !== prevDelta || prevProps.height !== props.height || prevProps.width !== props.width) {
instance.draw(path, props.width, props.height);
instance._prevDelta = path.delta;
instance._prevPath = path;
}
}
function applyTextProps(instance, props) {
var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
applyRenderableNodeProps(instance, props, prevProps);
var string = props.children;
if (instance._currentString !== string || !isSameFont(props.font, prevProps.font) || props.alignment !== prevProps.alignment || props.path !== prevProps.path) {
instance.draw(string, props.font, props.alignment, props.path);
instance._currentString = string;
}
}
function appendInitialChild(parentInstance, child) {
if (typeof child === 'string') {
// Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
{
{
throw Error( "Text children should already be flattened." );
}
}
}
child.inject(parentInstance);
}
function createInstance(type, props, internalInstanceHandle) {
var instance;
switch (type) {
case TYPES.CLIPPING_RECTANGLE:
instance = current.ClippingRectangle();
instance._applyProps = applyClippingRectangleProps;
break;
case TYPES.GROUP:
instance = current.Group();
instance._applyProps = applyGroupProps;
break;
case TYPES.SHAPE:
instance = current.Shape();
instance._applyProps = applyShapeProps;
break;
case TYPES.TEXT:
instance = current.Text(props.children, props.font, props.alignment, props.path);
instance._applyProps = applyTextProps;
break;
}
if (!instance) {
{
throw Error( "ReactART does not support the type \"" + type + "\"" );
}
}
instance._applyProps(instance, props);
return instance;
}
function createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
return text;
}
function getPublicInstance(instance) {
return instance;
}
function prepareForCommit() {// Noop
}
function prepareUpdate(domElement, type, oldProps, newProps) {
return UPDATE_SIGNAL;
}
function resetAfterCommit() {// Noop
}
function resetTextContent(domElement) {// Noop
}
function shouldDeprioritizeSubtree(type, props) {
return false;
}
function getRootHostContext() {
return NO_CONTEXT;
}
function getChildHostContext() {
return NO_CONTEXT;
}
var scheduleTimeout = setTimeout;
var cancelTimeout = clearTimeout;
var noTimeout = -1;
function shouldSetTextContent(type, props) {
return typeof props.children === 'string' || typeof props.children === 'number';
} // The ART renderer is secondary to the React DOM renderer.
function appendChild(parentInstance, child) {
if (child.parentNode === parentInstance) {
child.eject();
}
child.inject(parentInstance);
}
function appendChildToContainer(parentInstance, child) {
if (child.parentNode === parentInstance) {
child.eject();
}
child.inject(parentInstance);
}
function insertBefore(parentInstance, child, beforeChild) {
if (!(child !== beforeChild)) {
{
throw Error( "ReactART: Can not insert node before itself" );
}
}
child.injectBefore(beforeChild);
}
function insertInContainerBefore(parentInstance, child, beforeChild) {
if (!(child !== beforeChild)) {
{
throw Error( "ReactART: Can not insert node before itself" );
}
}
child.injectBefore(beforeChild);
}
function removeChild(parentInstance, child) {
destroyEventListeners(child);
child.eject();
}
function removeChildFromContainer(parentInstance, child) {
destroyEventListeners(child);
child.eject();
}
function commitUpdate(instance, updatePayload, type, oldProps, newProps) {
instance._applyProps(instance, newProps, oldProps);
}
function hideInstance(instance) {
instance.hide();
}
function unhideInstance(instance, props) {
if (props.visible == null || props.visible) {
instance.show();
}
}
function unhideTextInstance(textInstance, text) {// Noop
}
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
var ReactPropTypesSecret_1 = ReactPropTypesSecret;
var printWarning$1 = function() {};
{
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
var loggedTypeFailures = {};
var has = Function.call.bind(Object.prototype.hasOwnProperty);
printWarning$1 = function(text) {
var message = 'Warning: ' + text;
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
}
/**
* Assert that the values match with the type specs.
* Error messages are memorized and will only be shown once.
*
* @param {object} typeSpecs Map of name to a ReactPropType
* @param {object} values Runtime values that need to be type-checked
* @param {string} location e.g. "prop", "context", "child context"
* @param {string} componentName Name of the component for error messages.
* @param {?Function} getStack Returns the component stack.
* @private
*/
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
{
for (var typeSpecName in typeSpecs) {
if (has(typeSpecs, typeSpecName)) {
var error;
// Prop type validation may throw. In case they do, we don't want to
// fail the render phase where it didn't fail before. So we log it.
// After these have been cleaned up, we'll let them throw.
try {
// This is intentionally an invariant that gets caught. It's the same
// behavior as without this statement except with a better message.
if (typeof typeSpecs[typeSpecName] !== 'function') {
var err = Error(
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
);
err.name = 'Invariant Violation';
throw err;
}
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
} catch (ex) {
error = ex;
}
if (error && !(error instanceof Error)) {
printWarning$1(
(componentName || 'React class') + ': type specification of ' +
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
'You may have forgotten to pass an argument to the type checker ' +
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
'shape all require an argument).'
);
}
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
// Only monitor this failure once because there tends to be a lot of the
// same error.
loggedTypeFailures[error.message] = true;
var stack = getStack ? getStack() : '';
printWarning$1(
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
);
}
}
}
}
}
/**
* Resets warning cache when testing.
*
* @private
*/
checkPropTypes.resetWarningCache = function() {
{
loggedTypeFailures = {};
}
};
var checkPropTypes_1 = checkPropTypes;
var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
function describeComponentFrame (name, source, ownerName) {
var sourceInfo = '';
if (source) {
var path = source.fileName;
var fileName = path.replace(BEFORE_SLASH_RE, '');
{
// In DEV, include code for a common special case:
// prefer "folder/index.js" instead of just "index.js".
if (/^index\./.test(fileName)) {
var match = path.match(BEFORE_SLASH_RE);
if (match) {
var pathBeforeSlash = match[1];
if (pathBeforeSlash) {
var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
fileName = folderName + '/' + fileName;
}
}
}
}
sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
} else if (ownerName) {
sourceInfo = ' (created by ' + ownerName + ')';
}
return '\n in ' + (name || 'Unknown') + sourceInfo;
}
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
function describeFiber(fiber) {
switch (fiber.tag) {
case HostRoot:
case HostPortal:
case HostText:
case Fragment:
case ContextProvider:
case ContextConsumer:
return '';
default:
var owner = fiber._debugOwner;
var source = fiber._debugSource;
var name = getComponentName(fiber.type);
var ownerName = null;
if (owner) {
ownerName = getComponentName(owner.type);
}
return describeComponentFrame(name, source, ownerName);
}
}
function getStackByFiberInDevAndProd(workInProgress) {
var info = '';
var node = workInProgress;
do {
info += describeFiber(node);
node = node.return;
} while (node);
return info;
}
var current$1 = null;
var phase = null;
function getCurrentFiberOwnerNameInDevOrNull() {
{
if (current$1 === null) {
return null;
}
var owner = current$1._debugOwner;
if (owner !== null && typeof owner !== 'undefined') {
return getComponentName(owner.type);
}
}
return null;
}
function getCurrentFiberStackInDev() {
{
if (current$1 === null) {
return '';
} // Safe because if current fiber exists, we are reconciling,
// and it is guaranteed to be the work-in-progress version.
return getStackByFiberInDevAndProd(current$1);
}
}
function resetCurrentFiber() {
{
ReactDebugCurrentFrame.getCurrentStack = null;
current$1 = null;
phase = null;
}
}
function setCurrentFiber(fiber) {
{
ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
current$1 = fiber;
phase = null;
}
}
function setCurrentPhase(lifeCyclePhase) {
{
phase = lifeCyclePhase;
}
}
// Prefix measurements so that it's possible to filter them.
// Longer prefixes are hard to read in DevTools.
var reactEmoji = "\u269B";
var warningEmoji = "\u26D4";
var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function'; // Keep track of current fiber so that we know the path to unwind on pause.
// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
// Reusing `currentFiber` would be confusing for this because user code fiber
// can change during commit phase too, but we don't need to unwind it (since
// lifecycles in the commit phase don't resemble a tree).
var currentPhase = null;
var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
// so we will keep track of it, and include it in the report.
// Track commits caused by cascading updates.
var isCommitting = false;
var hasScheduledUpdateInCurrentCommit = false;
var hasScheduledUpdateInCurrentPhase = false;
var commitCountInCurrentWorkLoop = 0;
var effectCountInCurrentCommit = 0;
// to avoid stretch the commit phase with measurement overhead.
var labelsInCurrentCommit = new Set();
var formatMarkName = function (markName) {
return reactEmoji + " " + markName;
};
var formatLabel = function (label, warning) {
var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
var suffix = warning ? " Warning: " + warning : '';
return "" + prefix + label + suffix;
};
var beginMark = function (markName) {
performance.mark(formatMarkName(markName));
};
var clearMark = function (markName) {
performance.clearMarks(formatMarkName(markName));
};
var endMark = function (label, markName, warning) {
var formattedMarkName = formatMarkName(markName);
var formattedLabel = formatLabel(label, warning);
try {
performance.measure(formattedLabel, formattedMarkName);
} catch (err) {} // If previous mark was missing for some reason, this will throw.
// This could only happen if React crashed in an unexpected place earlier.
// Don't pile on with more errors.
// Clear marks immediately to avoid growing buffer.
performance.clearMarks(formattedMarkName);
performance.clearMeasures(formattedLabel);
};
var getFiberMarkName = function (label, debugID) {
return label + " (#" + debugID + ")";
};
var getFiberLabel = function (componentName, isMounted, phase) {
if (phase === null) {
// These are composite component total time measurements.
return componentName + " [" + (isMounted ? 'update' : 'mount') + "]";
} else {
// Composite component methods.
return componentName + "." + phase;
}
};
var beginFiberMark = function (fiber, phase) {
var componentName = getComponentName(fiber.type) || 'Unknown';
var debugID = fiber._debugID;
var isMounted = fiber.alternate !== null;
var label = getFiberLabel(componentName, isMounted, phase);
if (isCommitting && labelsInCurrentCommit.has(label)) {
// During the commit phase, we don't show duplicate labels because
// there is a fixed overhead for every measurement, and we don't
// want to stretch the commit phase beyond necessary.
return false;
}
labelsInCurrentCommit.add(label);
var markName = getFiberMarkName(label, debugID);
beginMark(markName);
return true;
};
var clearFiberMark = function (fiber, phase) {
var componentName = getComponentName(fiber.type) || 'Unknown';
var debugID = fiber._debugID;
var isMounted = fiber.alternate !== null;
var label = getFiberLabel(componentName, isMounted, phase);
var markName = getFiberMarkName(label, debugID);
clearMark(markName);
};
var endFiberMark = function (fiber, phase, warning) {
var componentName = getComponentName(fiber.type) || 'Unknown';
var debugID = fiber._debugID;
var isMounted = fiber.alternate !== null;
var label = getFiberLabel(componentName, isMounted, phase);
var markName = getFiberMarkName(label, debugID);
endMark(label, markName, warning);
};
var shouldIgnoreFiber = function (fiber) {
// Host components should be skipped in the timeline.
// We could check typeof fiber.type, but does this work with RN?
switch (fiber.tag) {
case HostRoot:
case HostComponent:
case HostText:
case HostPortal:
case Fragment:
case ContextProvider:
case ContextConsumer:
case Mode:
return true;
default:
return false;
}
};
var clearPendingPhaseMeasurement = function () {
if (currentPhase !== null && currentPhaseFiber !== null) {
clearFiberMark(currentPhaseFiber, currentPhase);
}
currentPhaseFiber = null;
currentPhase = null;
hasScheduledUpdateInCurrentPhase = false;
};
var pauseTimers = function () {
// Stops all currently active measurements so that they can be resumed
// if we continue in a later deferred loop from the same unit of work.
var fiber = currentFiber;
while (fiber) {
if (fiber._debugIsCurrentlyTiming) {
endFiberMark(fiber, null, null);
}
fiber = fiber.return;
}
};
var resumeTimersRecursively = function (fiber) {
if (fiber.return !== null) {
resumeTimersRecursively(fiber.return);
}
if (fiber._debugIsCurrentlyTiming) {
beginFiberMark(fiber, null);
}
};
var resumeTimers = function () {
// Resumes all measurements that were active during the last deferred loop.
if (currentFiber !== null) {
resumeTimersRecursively(currentFiber);
}
};
function recordEffect() {
{
effectCountInCurrentCommit++;
}
}
function recordScheduleUpdate() {
{
if (isCommitting) {
hasScheduledUpdateInCurrentCommit = true;
}
if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
hasScheduledUpdateInCurrentPhase = true;
}
}
}
function startWorkTimer(fiber) {
{
if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
return;
} // If we pause, this is the fiber to unwind from.
currentFiber = fiber;
if (!beginFiberMark(fiber, null)) {
return;
}
fiber._debugIsCurrentlyTiming = true;
}
}
function cancelWorkTimer(fiber) {
{
if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
return;
} // Remember we shouldn't complete measurement for this fiber.
// Otherwise flamechart will be deep even for small updates.
fiber._debugIsCurrentlyTiming = false;
clearFiberMark(fiber, null);
}
}
function stopWorkTimer(fiber) {
{
if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
return;
} // If we pause, its parent is the fiber to unwind from.
currentFiber = fiber.return;
if (!fiber._debugIsCurrentlyTiming) {
return;
}
fiber._debugIsCurrentlyTiming = false;
endFiberMark(fiber, null, null);
}
}
function stopFailedWorkTimer(fiber) {
{
if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
return;
} // If we pause, its