UNPKG

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,696 lines (1,411 loc) • 680 kB
/** @license React v17.0.2 * 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. */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : (global = global || self, factory(global.ReactART = {}, global.React)); }(this, (function (exports, 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; } // TODO: this is special because it gets imported during build. var ReactVersion = '17.0.2'; var LegacyRoot = 0; var BlockingRoot = 1; var ConcurrentRoot = 2; var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // 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 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); } } var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; var _assign = ReactInternals.assign; 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; var OffscreenComponent = 23; var LegacyHiddenComponent = 24; /** * `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._reactInternals; } function set(key, value) { key._reactInternals = value; } // ATTENTION // When adding new symbols to this file, // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols' // 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 REACT_ELEMENT_TYPE = 0xeac7; var REACT_PORTAL_TYPE = 0xeaca; var REACT_FRAGMENT_TYPE = 0xeacb; var REACT_STRICT_MODE_TYPE = 0xeacc; var REACT_PROFILER_TYPE = 0xead2; var REACT_PROVIDER_TYPE = 0xeacd; var REACT_CONTEXT_TYPE = 0xeace; var REACT_FORWARD_REF_TYPE = 0xead0; var REACT_SUSPENSE_TYPE = 0xead1; var REACT_SUSPENSE_LIST_TYPE = 0xead8; var REACT_MEMO_TYPE = 0xead3; var REACT_LAZY_TYPE = 0xead4; var REACT_BLOCK_TYPE = 0xead9; var REACT_SERVER_BLOCK_TYPE = 0xeada; var REACT_FUNDAMENTAL_TYPE = 0xead5; var REACT_SCOPE_TYPE = 0xead7; var REACT_OPAQUE_ID_TYPE = 0xeae0; var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1; var REACT_OFFSCREEN_TYPE = 0xeae2; var REACT_LEGACY_HIDDEN_TYPE = 0xeae3; if (typeof Symbol === 'function' && Symbol.for) { var symbolFor = Symbol.for; REACT_ELEMENT_TYPE = symbolFor('react.element'); REACT_PORTAL_TYPE = symbolFor('react.portal'); REACT_FRAGMENT_TYPE = symbolFor('react.fragment'); REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode'); REACT_PROFILER_TYPE = symbolFor('react.profiler'); REACT_PROVIDER_TYPE = symbolFor('react.provider'); REACT_CONTEXT_TYPE = symbolFor('react.context'); REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref'); REACT_SUSPENSE_TYPE = symbolFor('react.suspense'); REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list'); REACT_MEMO_TYPE = symbolFor('react.memo'); REACT_LAZY_TYPE = symbolFor('react.lazy'); REACT_BLOCK_TYPE = symbolFor('react.block'); REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block'); REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental'); REACT_SCOPE_TYPE = symbolFor('react.scope'); REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id'); REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode'); REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen'); REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden'); } 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; } function getWrappedName(outerType, innerType, wrapperName) { var functionName = innerType.displayName || innerType.name || ''; return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName); } function getContextName(type) { return type.displayName || 'Context'; } 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: var context = type; return getContextName(context) + '.Consumer'; case REACT_PROVIDER_TYPE: var provider = type; return getContextName(provider._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 lazyComponent = type; var payload = lazyComponent._payload; var init = lazyComponent._init; try { return getComponentName(init(payload)); } catch (x) { return null; } } } } return null; } // Don't change these two values. They're used by React Dev Tools. var NoFlags = /* */ 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; // TODO (effects) Remove this bit once the new reconciler is synced to the old. var PassiveUnmountPendingDev = /* */ 8192; var Hydrating = /* */ 1024; var HydratingAndUpdate = /* */ 1028; // Passive & Update & Callback & Ref & Snapshot var LifecycleEffectMask = /* */ 932; // Union of all host effects var HostEffectMask = /* */ 2047; // These are not really side effects, but we still reuse this field. var Incomplete = /* */ 2048; var ShouldCapture = /* */ 4096; var ForceUpdateForLegacySuspense = /* */ 16384; // Static tags describe aspects of a fiber that are not specific to a render, // Filter certain DOM attributes (e.g. src, href) if their values are empty strings. var enableProfilerTimer = true; // Record durations for commit and passive effects phases. var enableFundamentalAPI = false; // Experimental Scope support. var enableNewReconciler = false; // Errors that are thrown while unmounting (or after in the case of passive effects) 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.flags & (Placement | Hydrating)) !== NoFlags) { // 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; } function doesFiberContain(parentFiber, childFiber) { var node = childFiber; var parentFiberAlternate = parentFiber.alternate; while (node !== null) { if (node === parentFiber || node === parentFiberAlternate) { return true; } node = node.return; } return false; } 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 return null; } function prepareUpdate(domElement, type, oldProps, newProps) { return UPDATE_SIGNAL; } function resetAfterCommit() {// Noop } function resetTextContent(domElement) {// Noop } 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 } function clearContainer(container) {// TODO Implement this } function makeClientIdInDEV(warnOnAccessInDEV) { throw new Error('Not yet implemented'); } function preparePortalMount(portalInstance) {// noop } // Helpers to patch console.logs to avoid logging during side-effect free // replaying on render function. This currently only patches the object // lazily which won't cover if the log function was extracted eagerly. // We could also eagerly patch the method. var disabledDepth = 0; var prevLog; var prevInfo; var prevWarn; var prevError; var prevGroup; var prevGroupCollapsed; var prevGroupEnd; function disabledLog() {} disabledLog.__reactDisabledLog = true; function disableLogs() { { if (disabledDepth === 0) { /* eslint-disable react-internal/no-production-logging */ prevLog = console.log; prevInfo = console.info; prevWarn = console.warn; prevError = console.error; prevGroup = console.group; prevGroupCollapsed = console.groupCollapsed; prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099 var props = { configurable: true, enumerable: true, value: disabledLog, writable: true }; // $FlowFixMe Flow thinks console is immutable. Object.defineProperties(console, { info: props, log: props, warn: props, error: props, group: props, groupCollapsed: props, groupEnd: props }); /* eslint-enable react-internal/no-production-logging */ } disabledDepth++; } } function reenableLogs() { { disabledDepth--; if (disabledDepth === 0) { /* eslint-disable react-internal/no-production-logging */ var props = { configurable: true, enumerable: true, writable: true }; // $FlowFixMe Flow thinks console is immutable. Object.defineProperties(console, { log: _assign({}, props, { value: prevLog }), info: _assign({}, props, { value: prevInfo }), warn: _assign({}, props, { value: prevWarn }), error: _assign({}, props, { value: prevError }), group: _assign({}, props, { value: prevGroup }), groupCollapsed: _assign({}, props, { value: prevGroupCollapsed }), groupEnd: _assign({}, props, { value: prevGroupEnd }) }); /* eslint-enable react-internal/no-production-logging */ } if (disabledDepth < 0) { error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.'); } } } var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; var prefix; function describeBuiltInComponentFrame(name, source, ownerFn) { { if (prefix === undefined) { // Extract the VM specific prefix used by each line. try { throw Error(); } catch (x) { var match = x.stack.trim().match(/\n( *(at )?)/); prefix = match && match[1] || ''; } } // We use the prefix to ensure our stacks line up with native stack frames. return '\n' + prefix + name; } } var reentry = false; var componentFrameCache; { var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; componentFrameCache = new PossiblyWeakMap(); } function describeNativeComponentFrame(fn, construct) { // If something asked for a stack inside a fake render, it should get ignored. if (!fn || reentry) { return ''; } { var frame = componentFrameCache.get(fn); if (frame !== undefined) { return frame; } } var control; reentry = true; var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined. Error.prepareStackTrace = undefined; var previousDispatcher; { previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function // for warnings. ReactCurrentDispatcher.current = null; disableLogs(); } try { // This should throw. if (construct) { // Something should be setting the props in the constructor. var Fake = function () { throw Error(); }; // $FlowFixMe Object.defineProperty(Fake.prototype, 'props', { set: function () { // We use a throwing setter instead of frozen or non-writable props // because that won't throw in a non-strict mode function. throw Error(); } }); if (typeof Reflect === 'object' && Reflect.construct) { // We construct a different control for this case to include any extra // frames added by the construct call. try { Reflect.construct(Fake, []); } catch (x) { control = x; } Reflect.construct(fn, [], Fake); } else { try { Fake.call(); } catch (x) { control = x; } fn.call(Fake.prototype); } } else { try { throw Error(); } catch (x) { control = x; } fn(); } } catch (sample) { // This is inlined manually because closure doesn't do it for us. if (sample && control && typeof sample.stack === 'string') { // This extracts the first frame from the sample that isn't also in the control. // Skipping one frame that we assume is the frame that calls the two. var sampleLines = sample.stack.split('\n'); var controlLines = control.stack.split('\n'); var s = sampleLines.length - 1; var c = controlLines.length - 1; while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) { // We expect at least one stack frame to be shared. // Typically this will be the root most one. However, stack frames may be // cut off due to maximum stack limits. In this case, one maybe cut off // earlier than the other. We assume that the sample is longer or the same // and there for cut off earlier. So we should find the root most frame in // the sample somewhere in the control. c--; } for (; s >= 1 && c >= 0; s--, c--) { // Next we find the first one that isn't the same which should be the // frame that called our sample function and the control. if (sampleLines[s] !== controlLines[c]) { // In V8, the first line is describing the message but other VMs don't. // If we're about to return the first line, and the control is also on the same // line, that's a pretty good indicator that our sample threw at same line as // the control. I.e. before we entered the sample frame. So we ignore this result. // This can happen if you passed a class to function component, or non-function. if (s !== 1 || c !== 1) { do { s--; c--; // We may still have similar intermediate frames from the construct call. // The next one that isn't the same should be our match though. if (c < 0 || sampleLines[s] !== controlLines[c]) { // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier. var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); { if (typeof fn === 'function') { componentFrameCache.set(fn, _frame); } } // Return the line we found. return _frame; } } while (s >= 1 && c >= 0); } break; } } } } finally { reentry = false; { ReactCurrentDispatcher.current = previousDispatcher; reenableLogs(); } Error.prepareStackTrace = previousPrepareStackTrace; } // Fallback to just using the name if we couldn't make it throw. var name = fn ? fn.displayName || fn.name : ''; var syntheticFrame = name ? describeBuiltInComponentFrame(name) : ''; { if (typeof fn === 'function') { componentFrameCache.set(fn, syntheticFrame); } } return syntheticFrame; } function describeClassComponentFrame(ctor, source, ownerFn) { { return describeNativeComponentFrame(ctor, true); } } function describeFunctionComponentFrame(fn, source, ownerFn) { { return describeNativeComponentFrame(fn, false); } } function shouldConstruct(Component) { var prototype = Component.prototype; return !!(prototype && prototype.isReactComponent); } function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) { if (type == null) { return ''; } if (typeof type === 'function') { { return describeNativeComponentFrame(type, shouldConstruct(type)); } } if (typeof type === 'string') { return describeBuiltInComponentFrame(type); } switch (type) { case REACT_SUSPENSE_TYPE: return describeBuiltInComponentFrame('Suspense'); case REACT_SUSPENSE_LIST_TYPE: return describeBuiltInComponentFrame('SuspenseList'); } if (typeof type === 'object') { switch (type.$$typeof) { case REACT_FORWARD_REF_TYPE: return describeFunctionComponentFrame(type.render); case REACT_MEMO_TYPE: // Memo may contain any component type so we recursively resolve it. return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn); case REACT_BLOCK_TYPE: return describeFunctionComponentFrame(type._render); case REACT_LAZY_TYPE: { var lazyComponent = type; var payload = lazyComponent._payload; var init = lazyComponent._init; try { // Lazy may contain any component type so we recursively resolve it. return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn); } catch (x) {} } } } return ''; } var loggedTypeFailures = {}; var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; function setCurrentlyValidatingElement(element) { { if (element) { var owner = element._owner; var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null); ReactDebugCurrentFrame.setExtraStackFrame(stack); } else { ReactDebugCurrentFrame.setExtraStackFrame(null); } } } function checkPropTypes(typeSpecs, values, location, componentName, element) { { // $FlowFixMe This is okay but Flow doesn't know it. var has = Function.call.bind(Object.prototype.hasOwnProperty); for (var typeSpecName in typeSpecs) { if (has(typeSpecs, typeSpecName)) { var error$1 = void 0; // 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] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'); err.name = 'Invariant Violation'; throw err; } error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'); } catch (ex) { error$1 = ex; } if (error$1 && !(error$1 instanceof Error)) { setCurrentlyValidatingElement(element); error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1); setCurrentlyValidatingElement(null); } if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) { // Only monitor this failure once because there tends to be a lot of the // same error. loggedTypeFailures[error$1.message] = true; setCurrentlyValidatingElement(element); error('Failed %s type: %s', location, error$1.message); setCurrentlyValidatingElement(null); } } } } } var valueStack = []; var fiberStack; { fiberStack = []; } var index = -1; function createCursor(defaultValue) { return { current: defaultValue }; } function pop(cursor, fiber) { if (index < 0) { { error('Unexpected pop.'); } return; } { if (fiber !== fiberStack[index]) { error('Unexpected Fiber popped.'); } } cursor.current = valueStack[index]; valueStack[index] = null; { fiberStack[index] = null; } index--; } function push(cursor, value, fiber) { index++; valueStack[index] = cursor.current; { fiberStack[index] = fiber; } cursor.current = value; } var warnedAboutMissingGetChildContext; { warnedAboutMissingGetChildContext = {}; } var emptyContextObject = {}; { Object.freeze(emptyContextObject); } // A cursor to the current merged context object on the stack. var contextStackCursor = createCursor(emptyContextObject); // A cursor