{"version":3,"file":"application-BukKQpjj.js","sources":["../../../app/frontend/types/entrypoints.ts","../../../app/frontend/components/Chapter/Menu.vue","../../../app/frontend/components/Tab/MenuRow.vue","../../../app/frontend/components/Chapter/Filter.vue","../../../app/frontend/components/Chapter/Block.vue","../../../app/frontend/components/Icon/ExclamationCircle.vue","../../../app/frontend/components/ImageCitation/Tooltip.vue","../../../app/frontend/composables/useCommon.ts","../../../app/frontend/components/Chapter/Hero.vue","../../../app/frontend/components/GoBackToTarget.vue","../../../app/frontend/components/Chapter/List.vue","../../../app/frontend/components/Icon/Plus.vue","../../../app/frontend/components/Panel/FullScreen.vue","../../../app/frontend/components/PopUp/Index.vue","../../../app/frontend/components/PopUp/List.vue","../../../app/frontend/components/Tab/List.vue","../../../app/frontend/components/Icon/Logo.vue","../../../app/frontend/composables/useEnvs.ts","../../../app/frontend/components/Icon/Wcmc.vue","../../../app/frontend/components/Icon/Iucn.vue","../../../app/frontend/components/Icon/Wcpa.vue","../../../app/frontend/composables/useLinks.ts","../../../app/frontend/components/SocialMedia/Dropdown.vue","../../../app/frontend/components/Layout/BurgerMenu.vue","../../../app/frontend/components/Icon/Burger.vue","../../../app/frontend/components/Layout/Header.vue","../../../app/frontend/components/ContentBlock/Text.vue","../../../app/frontend/components/ContentBlock/Index.vue","../../../app/frontend/components/Layout/Hero.vue","../../../app/frontend/components/Logo/List.vue","../../../app/frontend/components/Icon/Email.vue","../../../app/frontend/components/Icon/Facebook.vue","../../../app/frontend/components/Icon/X.vue","../../../app/frontend/components/Icon/linkedin.vue","../../../app/frontend/components/SocialMedia/List.vue","../../../app/frontend/components/Link/Index.vue","../../../app/frontend/components/Layout/Footer.vue","../../../constants.ts","../../../app/frontend/composables/useConstants.ts","../../../app/frontend/composables/useAnalytics.ts","../../../node_modules/js-cookie/dist/js.cookie.mjs","../../../app/frontend/composables/useCookie.ts","../../../app/frontend/components/Cookies.vue","../../../node_modules/tslib/tslib.es6.mjs","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Percent.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Type.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Array.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Object.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Disposer.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Utils.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Color.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/EventDispatcher.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Animation.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/List.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Children.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Math.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Ease.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/States.js","../../../node_modules/@amcharts/amcharts5/.internal/core/Registry.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Order.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Entity.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Template.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Sprite.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/patterns/Pattern.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/patterns/PicturePattern.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/backend/Renderer.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Graphics.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Rectangle.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Layout.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/HorizontalLayout.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/VerticalLayout.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/GridLayout.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/TextFormatter.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/PopulateString.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Container.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Text.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/ResizeSensor.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/InterfaceColors.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Label.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/PointedRectangle.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Tooltip.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/NumberFormatter.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Timezone.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/DateFormatter.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/DurationFormatter.js","../../../node_modules/@amcharts/amcharts5/locales/en.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Language.js","../../../node_modules/@amcharts/amcharts5/.internal/core/Theme.js","../../../node_modules/@amcharts/amcharts5/.internal/themes/DefaultTheme.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Matrix.js","../../../node_modules/svg-arc-to-cubic-bezier/modules/index.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/backend/CanvasRenderer.js","../../../node_modules/@amcharts/amcharts5/.internal/core/Root.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Bullet.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/RoundedRectangle.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Button.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Data.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Component.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Time.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Series.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Legend.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/Draw.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Line.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/RadialText.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/RadialLabel.js","../../../node_modules/d3-shape/src/constant.js","../../../node_modules/d3-shape/src/math.js","../../../node_modules/d3-path/src/path.js","../../../node_modules/d3-shape/src/path.js","../../../node_modules/d3-shape/src/arc.js","../../../node_modules/d3-shape/src/array.js","../../../node_modules/d3-shape/src/curve/linear.js","../../../node_modules/d3-shape/src/point.js","../../../node_modules/d3-shape/src/line.js","../../../node_modules/d3-shape/src/area.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Slice.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Chart.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/SerialChart.js","../../../node_modules/@amcharts/amcharts5/.internal/core/render/Tick.js","../../../node_modules/@amcharts/amcharts5/.internal/core/util/ColorSet.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/XYChartDefaultTheme.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/XYChart.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/Grid.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/XYCursor.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/series/XYSeries.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/series/BaseColumnSeries.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/Axis.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/ValueAxis.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/CategoryAxis.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/DateAxis.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/AxisBullet.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/AxisLabel.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/AxisLabelRadial.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/AxisTick.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/AxisRenderer.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/AxisRendererX.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/axes/AxisRendererY.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/series/ColumnSeries.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/xy/series/LineSeries.js","../../../tailwind/colours.ts","../../../node_modules/@amcharts/amcharts5/.internal/themes/AnimatedTheme.js","../../../app/frontend/composables/useChart.ts","../../../app/frontend/components/Chart/Line.vue","../../../node_modules/@amcharts/amcharts5/.internal/charts/percent/PercentDefaultTheme.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/percent/PercentChart.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/percent/PercentSeries.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/pie/PieChart.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/pie/PieSeries.js","../../../app/frontend/components/Chart/Pie.vue","../../../app/frontend/components/Chart/Stacked/Index.vue","../../../app/frontend/components/Chart/ClusteredBar.vue","../../../app/frontend/components/Chart/Stacked/BiogeoGraphicRegionsList.vue","../../../app/frontend/components/Chart/Base.vue","../../../node_modules/@amcharts/amcharts5/.internal/charts/radar/AxisRendererCircular.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/radar/ClockHand.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/radar/RadarDefaultTheme.js","../../../node_modules/@amcharts/amcharts5/.internal/charts/radar/RadarChart.js","../../../app/frontend/components/Chart/Gauge.vue","../../../app/frontend/components/Chart/GaugeList.vue","../../../app/frontend/components/Map/Disclaimer.vue","../../../node_modules/maplibre-gl/dist/maplibre-gl.js","../../../app/frontend/types/Components/map.ts","../../../app/frontend/types/esri.ts","../../../app/frontend/composables/useMap.ts","../../../app/frontend/components/Map/Tabs.vue","../../../app/frontend/components/Input/Tickbox.vue","../../../app/frontend/components/Map/Option.vue","../../../app/frontend/components/Map/Options.vue","../../../app/frontend/components/Input/Toggle.vue","../../../app/frontend/components/Map/Tooltip.vue","../../../app/frontend/components/Map/Panel.vue","../../../app/frontend/components/Map/Styles.vue","../../../node_modules/maplibregl-mapbox-request-transformer/src/index.js","../../../app/frontend/components/Map/Base.vue","../../../app/frontend/entrypoints/application.ts"],"sourcesContent":["import { DISPLAY_DATA_OF_CLUSTERED_BAR_CHART,\n\tDISPLAY_DATA_OF_GAUGE_CHART,\n\tDISPLAY_DATA_OF_LINE_CHART,\n\tDISPLAY_DATA_OF_PIE_CHART,\n\tDISPLAY_DATA_OF_STACKED_CHART,\n\tChapterIs,\n\tDISPLAY_DATA_OF_MAP,\n\tDropdownSelectBackground,\n\tDropdownSelectIcon,\n\tHeroStyleFor,\n\tTARGET_LINE,\n\tVITE_LINKS,\n\tLegend\n} from \"@/types/backend\"\nimport { FrontendChartDataInfo } from \"@/types/chartsData\"\nimport { FrontendMapsDataInfo } from \"@/types/mapsData\"\n\nexport type FrontendData = {\n\tcharts: FrontendChartDataInfo\n\tmaps: FrontendMapsDataInfo\n}\nexport type ChapterContentBlock = {\n\tparentId: number\n\tchapterType: ChapterIs\n\tcontentBlockId: string\n\tcontentBlockHtml: string\n}\nexport type Chapter = {\n\tchapterTitle: string\n\tbackgroundImageInfo: {\n\t\timageUrl: string | undefined\n\t\tcitations: string | undefined\n\t}\n\tchapterContentBlocks: Record | undefined\n}\nexport type Chapters = Map\nexport type ChaptersRaw = Chapters | undefined\nexport type PopUp = {\n\torder: number\n\tpopupElementId: string\n\tparentId: string\n\tpopupId: string\n\ttitle: string\n\tbackgroundImageInfo: {\n\t\timageUrl: string | undefined\n\t\tcitations: string | undefined\n\t}\n\tcontentBlock: string\n\tpopupDescriptionId: string | undefined\n\tpopupDescriptionContentBlock: string\n}\nexport type PopUps = {\n\tbackgroundImageInfo: {\n\t\timageUrl: string | undefined\n\t\tcitations: string | undefined\n\t}\n\tpopUpList: PopUp[]\n}\nexport type PopUpsRaw = Record | undefined\nexport type Tab = {\n\ttabElementId: string\n\tparentId: string\n\ttabId: number\n\ttabName: string\n\tcontentBlock: string\n}\nexport type Tabs = Tab[]\nexport type TabsRaw = Record | undefined\nexport type ContentBlockList = {\n\tdescriptionInPopUpElementId: string\n\tdescriptionOutPopUpElementId: string\n\timageInPopUpHtml: string\n\tlanguage: string\n\tcontentBlock: {\n\t\tdescriptionInPopUp: string\n\t\tdescriptionOutsidePopUp: string\n\t}\n}\nexport type ContentBlock = {\n\tid: number\n\telementId: string\n\tlist: ContentBlockList[]\n\ttitle: string\n\tcentreAllNestedElements: boolean\n\tviewMoreButtonTitle: string\n\tbackgroundImageInfo: {\n\t\timageUrl: string | undefined\n\t\tcitations: string | undefined\n\t}\n\tallNestedElements: { id: string, name: string }[]\n}\nexport type ContentBlocksRaw = Record | undefined\ntype DropdownOptionShared = {\n\tparentId?: string\n\tdownloadFileOptionId?: string\n\ttext: string\n}\nexport type DropdownOptionLink = {\n\tinternalFileLink?: string\n\texternalFileLink?: string\n\tdownloadFileInNewWindow: boolean\n\tvalue?: string\n} & DropdownOptionShared\nexport type DropdownOptionText = {\n\tvalue: string | number\n} & DropdownOptionShared\ntype DropdownOptionsShared = {\n\ttitle?: string\n\telementId: string\n\tparentId: number\n\tbackground?: DropdownSelectBackground\n\ticon?: DropdownSelectIcon\n\tmounted?: boolean\n}\nexport type DropdownOptions = (\n\t| { optionsAreLinks: true, options: DropdownOptionLink[] }\n\t| { optionsAreLinks: false, options: DropdownOptionText[] }\n) &\nDropdownOptionsShared\nexport type DropdownsRaw = Record | undefined\nexport type HeroBackground = {\n\tbackgroundImageUrl: string | undefined\n\tvideoElementHtml: string | undefined\n\tcitations: string | undefined\n}\nexport type HeroRaw =\n\t| {\n\t\telementId: string\n\t\ttitle: string\n\t\theroStyleFor: HeroStyleFor\n\t\theroViewMoreButtonElementHtml: string\n\t\tcontentBlock: string | undefined\n\t\tbackgrounds: HeroBackground[]\n\t}\n\t| undefined\nexport type SocialMediaNames = Record\nexport type HeaderRaw =\n\t| {\n\t\theaderElementId: string\n\t\ttitle: string\n\t\tshowSocialMediaButtons: boolean\n\t\tallNestedElements: { id: string, name: string }[]\n\t}\n\t| undefined\nexport type FooterRaw =\n\t| {\n\t\telementId: string\n\t\ttitle: string\n\t\tsocialMediaNames: SocialMediaNames\n\t\tshowSocialMediaButtons: boolean\n\t\tallNestedElements: { id: string, name: string }[]\n\t}\n\t| undefined\n\nexport type Link = {\n\tparentId: string\n\tlinkId: string\n\ttitle: string\n\tlinkToPage: string\n\tlinkToFile: string\n}\nexport type Links = {\n\tparentId: string\n\telementId: string\n\tlinks: Link[]\n}\nexport type LinksRaw = Record | undefined\nexport type CookiesRaw = {\n\telementId: string\n\tdescriptionHtml: string\n\tisPrivacyPolicyPage: boolean\n}\nexport type TargetLine = {\n\tparentId: string\n\ttargetType: {\n\t\tlegend: TARGET_LINE\n\t\tinternalId: Legend.MARINE | Legend.TERRESTRIAL | Legend.COVERAGE_TARGET\n\t\tlabel: string\n\t}\n\ttargetPercentage: string\n}\nexport type TargetLinesRaw = Record | undefined\nexport type ChartBasic<_DisplayDataOf> = {\n\tcmsId: string\n\telementId: string\n\ttitle: string\n\tdescription: string\n\tdescriptionAfterChart: string\n\tdisplayDataOf: _DisplayDataOf\n\tdownloadButtonsHtml?: string\n}\nexport type MapInfo = {\n\telementId: string\n\tdisclaimerElementId: string\n\ttitle: string\n\tdisplayDataOf: DISPLAY_DATA_OF_MAP\n\tdescriptionAfterMap: string\n\tdownloadButtonsHtml?: string\n\tdisclaimerHtml?: string\n}\nexport type MapRaw = Record | undefined\nexport type CmsInfoChartStacked = ChartBasic\nexport type ChartStackedRaw = Record | undefined\nexport type CmsInfoChartLine = ChartBasic\nexport type ChartLineRaw = Record | undefined\nexport type CmsInfoChartClusteredBar = ChartBasic\nexport type ChartClusteredBarRaw = Record | undefined\nexport type CmsInfoChartGauge = ChartBasic\nexport type ChartGaugeRaw = Record | undefined\nexport type CmsInfoChartPie = ChartBasic\nexport type ChartPieRaw = Record | undefined\nexport type CmsInfo = CmsInfoChartStacked | CmsInfoChartLine | CmsInfoChartClusteredBar | CmsInfoChartGauge | CmsInfoChartPie\nexport enum ChartType {\n\tPIE = \"pie\",\n\tSTACKED = \"stacked\",\n\tLINE = \"line\",\n\tClUSTERED_BAR = \"clusteredBar\",\n\tGAUGE = \"gauge\"\n}\nexport type CmsData = {\n\tchaptersRaw?: ChaptersRaw\n\tpopUpsRaw?: PopUpsRaw\n\ttabsRaw?: TabsRaw\n\tcontentBlocksRaw?: ContentBlocksRaw\n\tdropdownsRaw?: DropdownsRaw\n\theroRaw?: HeroRaw\n\theaderRaw?: HeaderRaw\n\tfooterRaw?: FooterRaw\n\tlinksRaw?: LinksRaw\n\tcookiesRaw?: CookiesRaw\n\tmapRaw?: MapRaw\n\tchartStackedRaw?: ChartStackedRaw\n\tchartLineRaw?: ChartLineRaw\n\tchartClusteredBarRaw?: ChartClusteredBarRaw\n\tchartGaugeRaw?: ChartGaugeRaw\n\tchartPieRaw?: ChartPieRaw\n\ttargetLinesRaw?: TargetLinesRaw\n}\n","\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n","\n","\n\n\n \n","function activeOnlyWhenEnteringViewpoint(element: HTMLElement, func: () => void) {\n\tconst observer = new IntersectionObserver((entries) => {\n\t\tentries.forEach((entry) => {\n\t\t\tif (entry.isIntersecting && (entry.target as { offsetLeft: number } & Element).offsetLeft > 0) {\n\t\t\t\tfunc()\n\t\t\t\tobserver.unobserve(element)\n\t\t\t}\n\t\t})\n\t}, {\n\t\troot: null,\n\t\trootMargin: \"30% 0% 30% 0%\",\n\t\tthreshold: 0\n\t})\n\tobserver.observe(element)\n}\nexport function useCommon() {\n\treturn {\n\t\tfreezeBackground: (freeze: boolean) => (document.body.style.overflow = freeze ? \"hidden\" : \"\"),\n\t\tfreezeVideo: (freeze: boolean, element: HTMLVideoElement) => freeze ? element.pause() : element.play(),\n\t\tactiveOnlyWhenEnteringViewpoint\n\t}\n}\nexport default useCommon\n","\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n\n","\n","\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n\n","\n \n\n\n\n\n\n","\n","export type useEnvs = ImportMetaEnv & {\n\treadonly VITE_MAPBOX_TOKEN: string\n\treadonly VITE_MAPBOX_STYLE_TERRAIN: string\n\treadonly VITE_MAPBOX_STYLE_SATELLITE: string\n\treadonly VITE_LINK_X: string\n\treadonly VITE_LINK_FACEBOOK: string\n\treadonly VITE_LINK_LINKEDIN: string\n\treadonly VITE_LINK_EMAIL: string\n\treadonly VITE_LINK_WCMC: string\n\treadonly VITE_LINK_IUCN: string\n\treadonly VITE_LINK_WCPA: string\n\treadonly VITE_LINK_PP: string\n\treadonly VITE_SHARE_REPORT_LINK_X: string\n\treadonly VITE_SHARE_REPORT_LINK_FACEBOOK: string\n\treadonly VITE_SHARE_REPORT_LINK_LINKEDIN: string\n\treadonly VITE_ENVIROMENT: \"production\" | \"development\" | \"staging\"\n}\n\nexport function useEnvs(): useEnvs {\n\treturn import.meta.env as useEnvs\n}\nexport default useEnvs\n","\n","\n","\n","import { VITE_LINKS } from \"@/types/backend\"\nimport useEnvs from \"./useEnvs\"\nimport { DropdownOptionLink, SocialMediaNames } from \"@/types/entrypoints\"\nimport IconWcmc from \"@/components/Icon/Wcmc.vue\"\nimport IconIucn from \"@/components/Icon/Iucn.vue\"\nimport IconWcpa from \"@/components/Icon/Wcpa.vue\"\nimport IconPp from \"@/components/Icon/Logo.vue\"\n\nexport function useLinks(socialMediaNames?: SocialMediaNames) {\n\ttype SocialMediaLinks = (DropdownOptionLink & { is: VITE_LINKS })[]\n\tconst {\n\t\tVITE_LINK_X,\n\t\tVITE_LINK_EMAIL,\n\t\tVITE_LINK_FACEBOOK,\n\t\tVITE_LINK_LINKEDIN,\n\t\tVITE_LINK_IUCN,\n\t\tVITE_LINK_PP,\n\t\tVITE_LINK_WCMC,\n\t\tVITE_LINK_WCPA,\n\t\tVITE_SHARE_REPORT_LINK_FACEBOOK,\n\t\tVITE_SHARE_REPORT_LINK_LINKEDIN,\n\t\tVITE_SHARE_REPORT_LINK_X\n\t} = useEnvs()\n\tconst siteTitle = window.siteTitle\n\tconst socialMediaList: SocialMediaLinks = socialMediaNames\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.EMAIL,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.EMAIL],\n\t\t\t\t\tvalue: VITE_LINK_EMAIL ? `mailto:${VITE_LINK_EMAIL}?subject=${siteTitle}` : undefined,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.LINKEDIN,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.LINKEDIN],\n\t\t\t\t\tvalue: VITE_LINK_LINKEDIN,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.FACEBOOK,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.FACEBOOK],\n\t\t\t\t\tvalue: VITE_LINK_FACEBOOK,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.X,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.X],\n\t\t\t\t\tvalue: VITE_LINK_X,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t}\n\t\t\t]\n\t\t: []\n\tconst shareReportList: SocialMediaLinks = socialMediaNames\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.EMAIL,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.EMAIL],\n\t\t\t\t\tvalue: `mailto:?subject=Check out the ${siteTitle}&body=${window.siteBaseUrl}`,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.LINKEDIN,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.LINKEDIN],\n\t\t\t\t\tvalue: VITE_SHARE_REPORT_LINK_LINKEDIN,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.FACEBOOK,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.FACEBOOK],\n\t\t\t\t\tvalue: VITE_SHARE_REPORT_LINK_FACEBOOK,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tis: VITE_LINKS.X,\n\t\t\t\t\ttext: socialMediaNames[VITE_LINKS.X],\n\t\t\t\t\tvalue: VITE_SHARE_REPORT_LINK_X,\n\t\t\t\t\tdownloadFileInNewWindow: true\n\t\t\t\t}\n\t\t\t]\n\t\t: []\n\tconst logoLinks = [\n\t\t{\n\t\t\tis: VITE_LINKS.WCMC,\n\t\t\tvalue: VITE_LINK_WCMC,\n\t\t\tcomponent: IconWcmc\n\t\t},\n\t\t{\n\t\t\tis: VITE_LINKS.IUCN,\n\t\t\tvalue: VITE_LINK_IUCN,\n\t\t\tcomponent: IconIucn\n\t\t},\n\t\t{\n\t\t\tis: VITE_LINKS.WCPA,\n\t\t\tvalue: VITE_LINK_WCPA,\n\t\t\tcomponent: IconWcpa\n\t\t},\n\t\t{\n\t\t\tis: VITE_LINKS.PP,\n\t\t\tvalue: VITE_LINK_PP,\n\t\t\tcomponent: IconPp\n\t\t}\n\t]\n\treturn {\n\t\tsocialMediaList,\n\t\tshareReportList,\n\t\tlogoLinks\n\t}\n}\nexport default useLinks\n","\n\n\n\n\n","\n\n\n\n\n","\n","\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n\n","\n","\n","\n","\n","\n \n\n\n\n\n\n","\n\n\n\n\n","\n\n\n\n\n","export const GOOGLEANALYTICSID = {\n\tproduction: \"G-H1TDV4TMW1\",\n\tstaging: \"G-E592D40M7D\"\n}\n\nexport enum COOKIE_NAMES {\n\tCONSENT = \"cookieConsent\"\n}\nexport const MAP_STYLE_ID_TERRAIN = \"cko1hsfi50vog17l697cr4d6p\"\nexport const MAP_STYLE_ID_SATELITE = \"ckniq2twg0q3b17s5gqfxhagf\"\nexport const LAYER_ADDED_AFTER_THIS_LAYER_TERRAIN = \"aerialway\"\nexport const LAYER_ADDED_AFTER_THIS_LAYER_SATELITE = \"aerialway\"\n","import * as constants from \"../../../constants\"\n\nexport default function useConstants() {\n\treturn {\n\t\t...constants\n\t}\n}\n","/* eslint-disable prefer-rest-params */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\n// @ts-nocheck\nimport useConstants from \"@/composables/useConstants\"\nimport useEnvs from \"@/composables/useEnvs\"\n\nconst { GOOGLEANALYTICSID } = useConstants()\nconst { VITE_ENVIROMENT } = useEnvs()\nfunction activateGoogleAnalytics() {\n\tlet gTagId = GOOGLEANALYTICSID.staging\n\tif (VITE_ENVIROMENT === \"production\") gTagId = GOOGLEANALYTICSID.production\n\tconst script = `https://www.googletagmanager.com/gtag/js?id=${gTagId}`\n\tlet tag = document.head.querySelector(`[src=\"${script}\"`)\n\tif (!tag) {\n\t\ttag = document.createElement(\"script\")\n\t\ttag.setAttribute(\"src\", script)\n\t\ttag.setAttribute(\"type\", \"text/javascript\")\n\t\tdocument.head.appendChild(tag)\n\t\twindow.dataLayer = window.dataLayer || []\n\t\tfunction gtag() {\n\t\t\tdataLayer.push(arguments)\n\t\t}\n\t\tgtag(\"js\", new Date())\n\t\tgtag(\"config\", gTagId)\n\t}\n}\nfunction activateHotjar() {\n\tif (VITE_ENVIROMENT === \"production\") {\n\t\t(function (h, o, t, j, a, r) {\n\t\t\th.hj = h.hj || function () {\n\t\t\t\t(h.hj.q = h.hj.q || []).push(arguments)\n\t\t\t}\n\t\t\th._hjSettings = { hjid: 5131004, hjsv: 6 }\n\t\t\ta = o.getElementsByTagName(\"head\")[0]\n\t\t\tr = o.createElement(\"script\")\n\t\t\tr.async = 1\n\t\t\tr.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv\n\t\t\ta.appendChild(r)\n\t\t})(window, document, \"https://static.hotjar.com/c/hotjar-\", \".js?sv=\")\n\t}\n}\nexport default function useAnalytics() {\n\treturn {\n\t\tactivate: {\n\t\t\tall: () => {\n\t\t\t\tactivateGoogleAnalytics()\n\t\t\t\tactivateHotjar()\n\t\t\t},\n\t\t\tactivateHotjar,\n\t\t\tactivateGoogleAnalytics\n\t\t}\n\t}\n}\n","/*! js-cookie v3.0.5 | MIT */\n/* eslint-disable no-var */\nfunction assign (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n for (var key in source) {\n target[key] = source[key];\n }\n }\n return target\n}\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\nvar defaultConverter = {\n read: function (value) {\n if (value[0] === '\"') {\n value = value.slice(1, -1);\n }\n return value.replace(/(%[\\dA-F]{2})+/gi, decodeURIComponent)\n },\n write: function (value) {\n return encodeURIComponent(value).replace(\n /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,\n decodeURIComponent\n )\n }\n};\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\n\nfunction init (converter, defaultAttributes) {\n function set (name, value, attributes) {\n if (typeof document === 'undefined') {\n return\n }\n\n attributes = assign({}, defaultAttributes, attributes);\n\n if (typeof attributes.expires === 'number') {\n attributes.expires = new Date(Date.now() + attributes.expires * 864e5);\n }\n if (attributes.expires) {\n attributes.expires = attributes.expires.toUTCString();\n }\n\n name = encodeURIComponent(name)\n .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)\n .replace(/[()]/g, escape);\n\n var stringifiedAttributes = '';\n for (var attributeName in attributes) {\n if (!attributes[attributeName]) {\n continue\n }\n\n stringifiedAttributes += '; ' + attributeName;\n\n if (attributes[attributeName] === true) {\n continue\n }\n\n // Considers RFC 6265 section 5.2:\n // ...\n // 3. If the remaining unparsed-attributes contains a %x3B (\";\")\n // character:\n // Consume the characters of the unparsed-attributes up to,\n // not including, the first %x3B (\";\") character.\n // ...\n stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];\n }\n\n return (document.cookie =\n name + '=' + converter.write(value, name) + stringifiedAttributes)\n }\n\n function get (name) {\n if (typeof document === 'undefined' || (arguments.length && !name)) {\n return\n }\n\n // To prevent the for loop in the first place assign an empty array\n // in case there are no cookies at all.\n var cookies = document.cookie ? document.cookie.split('; ') : [];\n var jar = {};\n for (var i = 0; i < cookies.length; i++) {\n var parts = cookies[i].split('=');\n var value = parts.slice(1).join('=');\n\n try {\n var found = decodeURIComponent(parts[0]);\n jar[found] = converter.read(value, found);\n\n if (name === found) {\n break\n }\n } catch (e) {}\n }\n\n return name ? jar[name] : jar\n }\n\n return Object.create(\n {\n set,\n get,\n remove: function (name, attributes) {\n set(\n name,\n '',\n assign({}, attributes, {\n expires: -1\n })\n );\n },\n withAttributes: function (attributes) {\n return init(this.converter, assign({}, this.attributes, attributes))\n },\n withConverter: function (converter) {\n return init(assign({}, this.converter, converter), this.attributes)\n }\n },\n {\n attributes: { value: Object.freeze(defaultAttributes) },\n converter: { value: Object.freeze(converter) }\n }\n )\n}\n\nvar api = init(defaultConverter, { path: '/' });\n/* eslint-enable no-var */\n\nexport { api as default };\n","import Cookies from \"js-cookie\"\nimport { COOKIE_NAMES } from \"../../../constants\"\n\nconst defaultExpiresAt = new Date(new Date().setFullYear(new Date().getFullYear() + 1))\nfunction setUserConsentToCookie(decision: boolean) {\n\tCookies.set(COOKIE_NAMES.CONSENT, String(decision === true), {\n\t\texpires: defaultExpiresAt\n\t})\n}\nfunction getUserConsentFromCookie() {\n\treturn Cookies.get(COOKIE_NAMES.CONSENT)\n}\nfunction userConsentedForOptionalCookies() {\n\treturn getUserConsentFromCookie() === \"true\"\n}\nfunction setCookie(cookieName: COOKIE_NAMES, value: string, expires: Date) {\n\tCookies.set(cookieName, value, {\n\t\t// If no date is provided then use defualt expires date\n\t\texpires: expires || defaultExpiresAt\n\t})\n}\nfunction getCookie(cookieName: COOKIE_NAMES) {\n\treturn Cookies.get(cookieName)\n}\nfunction removeCookie(cookieName: COOKIE_NAMES) {\n\tCookies.remove(cookieName)\n}\nexport default function useCookies() {\n\treturn {\n\t\tCOOKIE_NAMES,\n\t\tsetUserConsentToCookie,\n\t\tgetUserConsentFromCookie,\n\t\tuserConsentedForOptionalCookies,\n\t\tsetCookie,\n\t\tgetCookie,\n\t\tremoveCookie\n\t}\n}\n","\n\n\n\n","/******************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise, SuppressedError, Symbol, Iterator */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\n var _, done = false;\n for (var i = decorators.length - 1; i >= 0; i--) {\n var context = {};\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\n if (kind === \"accessor\") {\n if (result === void 0) continue;\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\n if (_ = accept(result.get)) descriptor.get = _;\n if (_ = accept(result.set)) descriptor.set = _;\n if (_ = accept(result.init)) initializers.unshift(_);\n }\n else if (_ = accept(result)) {\n if (kind === \"field\") initializers.unshift(_);\n else descriptor[key] = _;\n }\n }\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\n done = true;\n};\n\nexport function __runInitializers(thisArg, initializers, value) {\n var useValue = arguments.length > 2;\n for (var i = 0; i < initializers.length; i++) {\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\n }\n return useValue ? value : void 0;\n};\n\nexport function __propKey(x) {\n return typeof x === \"symbol\" ? x : \"\".concat(x);\n};\n\nexport function __setFunctionName(f, name, prefix) {\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\n};\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = Object.create((typeof AsyncIterator === \"function\" ? AsyncIterator : Object).prototype), verb(\"next\"), verb(\"throw\"), verb(\"return\", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;\n function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }\n function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n\nexport function __addDisposableResource(env, value, async) {\n if (value !== null && value !== void 0) {\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\n var dispose, inner;\n if (async) {\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\n dispose = value[Symbol.asyncDispose];\n }\n if (dispose === void 0) {\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\n dispose = value[Symbol.dispose];\n if (async) inner = dispose;\n }\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\n if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\n env.stack.push({ value: value, dispose: dispose, async: async });\n }\n else if (async) {\n env.stack.push({ async: true });\n }\n return value;\n}\n\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\n var e = new Error(message);\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\n};\n\nexport function __disposeResources(env) {\n function fail(e) {\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\n env.hasError = true;\n }\n var r, s = 0;\n function next() {\n while (r = env.stack.pop()) {\n try {\n if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);\n if (r.dispose) {\n var result = r.dispose.call(r.value);\n if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\n }\n else s |= 1;\n }\n catch (e) {\n fail(e);\n }\n }\n if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();\n if (env.hasError) throw env.error;\n }\n return next();\n}\n\nexport default {\n __extends,\n __assign,\n __rest,\n __decorate,\n __param,\n __metadata,\n __awaiter,\n __generator,\n __createBinding,\n __exportStar,\n __values,\n __read,\n __spread,\n __spreadArrays,\n __spreadArray,\n __await,\n __asyncGenerator,\n __asyncDelegator,\n __asyncValues,\n __makeTemplateObject,\n __importStar,\n __importDefault,\n __classPrivateFieldGet,\n __classPrivateFieldSet,\n __classPrivateFieldIn,\n __addDisposableResource,\n __disposeResources,\n};\n","/**\r\n * ============================================================================\r\n * MAIN CLASS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Represents a relative value (percent).\r\n *\r\n * The Percent object, can be instantiated using two ways:\r\n *\r\n * * Via `new Percent(X)`.\r\n * * Via `am5.percent(X)`.\r\n *\r\n * You can also use shortcut functions for `0%`, `50%`, and `100%`:\r\n * * `am5.p0`\r\n * * `am5.p50`\r\n * * `am5.p100`\r\n */\r\nexport class Percent {\r\n /**\r\n * Constructor.\r\n *\r\n * @param percent Percent value\r\n */\r\n constructor(percent) {\r\n /**\r\n * Value in percent.\r\n */\r\n Object.defineProperty(this, \"_value\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._value = percent;\r\n }\r\n /**\r\n * Relative value.\r\n *\r\n * E.g. 100% is 1, 50% is 0.5, etc.\r\n *\r\n * This is useful to apply transformations to other values. E.g.:\r\n *\r\n * ```TypeScript\r\n * let value = 256;\r\n * let percent = new am5.p50;\r\n * console.log(value * percent.value); // outputs 128\r\n * ```\r\n * ```JavaScript\r\n * var value = 256;\r\n * var percent = new am5.p50;\r\n * console.log(value * percent.value); // outputs 128\r\n * ```\r\n *\r\n * Alternatively, you can use `am5.percent()` helper function:\r\n *\r\n * ```TypeScript\r\n * let value = 256;\r\n * let percent = am5.p50;\r\n * console.log(value * percent.value); // outputs 128\r\n * ```\r\n * ```JavaScript\r\n * var value = 256;\r\n * var percent = am5.p50;\r\n * console.log(value * percent.value); // outputs 128\r\n * ```\r\n *\r\n * @readonly\r\n * @return Relative value\r\n */\r\n get value() {\r\n return this._value / 100;\r\n }\r\n /**\r\n * Value in percent.\r\n *\r\n * @readonly\r\n * @return Percent\r\n */\r\n get percent() {\r\n return this._value;\r\n }\r\n toString() {\r\n return \"\" + this._value + \"%\";\r\n }\r\n interpolate(min, max) {\r\n return min + (this.value * (max - min));\r\n }\r\n static normalize(percent, min, max) {\r\n if (percent instanceof Percent) {\r\n return percent;\r\n }\r\n else {\r\n if (min === max) {\r\n return new Percent(0);\r\n }\r\n else {\r\n return new Percent(Math.min(Math.max((percent - min) * (1 / (max - min)), 0), 1) * 100);\r\n }\r\n }\r\n }\r\n}\r\n/**\r\n * Converts numeric percent value to a proper [[Percent]] object.\r\n *\r\n * ```TypeScript\r\n * pieSeries.set(\"radius\", am5.percent(80));\r\n * ```\r\n * ```JavaScript\r\n * pieSeries.set(\"radius\", am5.percent(80));\r\n * ```\r\n *\r\n * @param value Percent\r\n * @return Percent object\r\n */\r\nexport function percent(value) {\r\n return new Percent(value);\r\n}\r\n/**\r\n * A shortcut function to `am5.percent(0)`.\r\n */\r\nexport const p0 = percent(0);\r\n/**\r\n * A shortcut function to `am5.percent(100)`.\r\n */\r\nexport const p100 = percent(100);\r\n/**\r\n * A shortcut function to `am5.percent(50)`.\r\n */\r\nexport const p50 = percent(50);\r\n/**\r\n * Checks if value is a [[Percent]] object.\r\n *\r\n * @ignore Exclude from docs\r\n * @param value Input value\r\n * @return Is percent?\r\n */\r\nexport function isPercent(value) {\r\n return value instanceof Percent;\r\n}\r\n//# sourceMappingURL=Percent.js.map","/**\r\n * A collection of utility functions for various type checks and conversion\r\n * @hidden\r\n */\r\n/**\r\n * ============================================================================\r\n * TYPE CHECK\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Returns `true` if value is not a number (NaN).\r\n *\r\n * @param value Input value\r\n * @return Is NaN?\r\n */\r\nexport function isNaN(value) {\r\n return Number(value) !== value;\r\n}\r\n/**\r\n * Returns a type of the value.\r\n *\r\n * @param value Input value\r\n * @return Type of the value\r\n * @ignore\r\n */\r\nexport function getType(value) {\r\n return ({}).toString.call(value);\r\n}\r\n/**\r\n * Asserts that the condition is true.\r\n *\r\n * @param condition Condition to check\r\n * @param message Message to display in the error\r\n * @ignore\r\n */\r\nexport function assert(condition, message = \"Assertion failed\") {\r\n if (!condition) {\r\n throw new Error(message);\r\n }\r\n}\r\n/**\r\n * ============================================================================\r\n * QUICK CONVERSION\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Converts any value into a `number`.\r\n *\r\n * @param value Source value\r\n * @return Number representation of value\r\n */\r\nexport function toNumber(value) {\r\n if (value != null && !isNumber(value)) {\r\n let converted = Number(value);\r\n if (isNaN(converted) && isString(value) && value != \"\") {\r\n return toNumber(value.replace(/[^0-9.\\-]+/g, ''));\r\n }\r\n return converted;\r\n }\r\n return value;\r\n}\r\n/**\r\n * Converts anything to Date object.\r\n *\r\n * @param value A value of any type\r\n * @return Date object representing a value\r\n */\r\nexport function toDate(value) {\r\n if (isDate(value)) {\r\n // TODO maybe don't create a new Date ?\r\n return new Date(value);\r\n }\r\n else if (isNumber(value)) {\r\n return new Date(value);\r\n }\r\n else {\r\n // Try converting to number (assuming timestamp)\r\n let num = Number(value);\r\n if (!isNumber(num)) {\r\n return new Date(value);\r\n }\r\n else {\r\n return new Date(num);\r\n }\r\n }\r\n}\r\n/**\r\n * Converts numeric value into string. Deals with large or small numbers that\r\n * would otherwise use exponents.\r\n *\r\n * @param value Numeric value\r\n * @return Numeric value as string\r\n */\r\nexport function numberToString(value) {\r\n // TODO handle Infinity and -Infinity\r\n if (isNaN(value)) {\r\n return \"NaN\";\r\n }\r\n if (value === Infinity) {\r\n return \"Infinity\";\r\n }\r\n if (value === -Infinity) {\r\n return \"-Infinity\";\r\n }\r\n // Negative 0\r\n if ((value === 0) && (1 / value === -Infinity)) {\r\n return \"-0\";\r\n }\r\n // Preserve negative and deal with absoute values\r\n let negative = value < 0;\r\n value = Math.abs(value);\r\n // TODO test this\r\n let parsed = /^([0-9]+)(?:\\.([0-9]+))?(?:e[\\+\\-]([0-9]+))?$/.exec(\"\" + value);\r\n let digits = parsed[1];\r\n let decimals = parsed[2] || \"\";\r\n let res;\r\n // Leave the nummber as it is if it does not use exponents\r\n if (parsed[3] === undefined) {\r\n res = (decimals === \"\" ? digits : digits + \".\" + decimals);\r\n }\r\n else {\r\n let exponent = +parsed[3];\r\n // Deal with decimals\r\n if (value < 1) {\r\n let zeros = exponent - 1;\r\n res = \"0.\" + repeat(\"0\", zeros) + digits + decimals;\r\n // Deal with integers\r\n }\r\n else {\r\n let zeros = exponent - decimals.length;\r\n if (zeros === 0) {\r\n res = digits + decimals;\r\n }\r\n else if (zeros < 0) {\r\n res = digits + decimals.slice(0, zeros) + \".\" + decimals.slice(zeros);\r\n }\r\n else {\r\n res = digits + decimals + repeat(\"0\", zeros);\r\n }\r\n }\r\n }\r\n return negative ? \"-\" + res : res;\r\n}\r\n/**\r\n * Repeats a `string` number of times as set in `amount`.\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Make this faster\r\n * @param string Source string\r\n * @param amount Number of times to repeat string\r\n * @return New string\r\n */\r\nexport function repeat(string, amount) {\r\n return new Array(amount + 1).join(string);\r\n}\r\n/**\r\n * ============================================================================\r\n * TYPE CHECK\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Checks if parameter is `Date`.\r\n *\r\n * @param value Input value\r\n * @return Is Date?\r\n */\r\nexport function isDate(value) {\r\n return getType(value) === \"[object Date]\";\r\n}\r\n/**\r\n * Checks if parameter is `string`.\r\n *\r\n * @param value Input value\r\n * @return Is string?\r\n */\r\nexport function isString(value) {\r\n return typeof value === \"string\";\r\n}\r\n/**\r\n * Checks if parameter is `number`.\r\n *\r\n * @param value Input value\r\n * @return Is number?\r\n */\r\nexport function isNumber(value) {\r\n return typeof value === \"number\" && Number(value) == value;\r\n}\r\n/**\r\n * Checks if parameter is `object`.\r\n *\r\n * @param value Input value\r\n * @return Is object?\r\n */\r\nexport function isObject(value) {\r\n return typeof value === \"object\" && value !== null;\r\n}\r\n/**\r\n * Checks if parameter is `Array`.\r\n *\r\n * @param value Input value\r\n * @return Is Array?\r\n */\r\nexport function isArray(value) {\r\n return Array.isArray(value);\r\n}\r\n/**\r\n * ============================================================================\r\n * STATIC CONSTANTS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * @ignore Exclude from docs\r\n */\r\nexport const PLACEHOLDER = \"__§§§__\";\r\n/**\r\n * @ignore Exclude from docs\r\n */\r\nexport const PLACEHOLDER2 = \"__§§§§__\";\r\n//# sourceMappingURL=Type.js.map","import * as $type from \"./Type\";\r\n/**\r\n * ============================================================================\r\n * UTILITY FUNCTIONS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Searches `array` for `value`.\r\n *\r\n * Returns -1 if not found.\r\n *\r\n * @param array Source array\r\n * @param value Value to search\r\n * @returns Index\r\n */\r\nexport function indexOf(array, value) {\r\n const length = array.length;\r\n for (let i = 0; i < length; ++i) {\r\n // TODO handle NaN\r\n if (array[i] === value) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n}\r\n/**\r\n * Calls `test` for each element in `array`.\r\n *\r\n * If `test` returns `true` then it immediately returns `true`.\r\n *\r\n * If `test` returns `false` for all of the elements in `array` then it returns `false`.\r\n *\r\n * @param array Source array\r\n * @param test Function which is called on each element\r\n * @returns Whether `test` returned true or not\r\n */\r\nexport function any(array, test) {\r\n const length = array.length;\r\n for (let i = 0; i < length; ++i) {\r\n if (test(array[i])) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n/**\r\n * Calls `fn` function for every member of array and returns a new array out\r\n * of all outputs.\r\n *\r\n * @param array Source array\r\n * @param fn Callback function\r\n * @returns New array\r\n */\r\nexport function map(array, fn) {\r\n const length = array.length;\r\n const output = new Array(length);\r\n for (let i = 0; i < length; ++i) {\r\n output[i] = fn(array[i], i);\r\n }\r\n return output;\r\n}\r\n/**\r\n * Iterates through all items in array and calls `fn` function for each of\r\n * them.\r\n *\r\n * @param array Source array\r\n * @param fn Callback function\r\n */\r\nexport function each(array, fn) {\r\n const length = array.length;\r\n for (let i = 0; i < length; ++i) {\r\n fn(array[i], i);\r\n }\r\n}\r\n/**\r\n * Iterates through all items in array in reverse order and calls `fn` function for each of\r\n * them.\r\n *\r\n * @param array Source array\r\n * @param fn Callback function\r\n */\r\nexport function eachReverse(array, fn) {\r\n let i = array.length;\r\n while (i > 0) {\r\n --i;\r\n fn(array[i], i);\r\n }\r\n}\r\n/**\r\n * Iterates through all items in array and calls `fn` function for each of\r\n * them.\r\n *\r\n * If `fn` call evaluates to `false`, further iteration is cancelled.\r\n *\r\n * @param array Source array\r\n * @param fn Callback function\r\n */\r\nexport function eachContinue(array, fn) {\r\n const length = array.length;\r\n for (let i = 0; i < length; ++i) {\r\n if (!fn(array[i], i)) {\r\n break;\r\n }\r\n }\r\n}\r\n/**\r\n * Shifts an item at `index` towards beginning of the array.\r\n *\r\n * @param array Source array\r\n * @param index Target element index\r\n */\r\nexport function shiftLeft(array, index) {\r\n const length = array.length;\r\n for (let i = index; i < length; ++i) {\r\n array[i - index] = array[i];\r\n }\r\n array.length = length - index;\r\n}\r\n/**\r\n * Returns the last item of the array.\r\n *\r\n * @param array Source array\r\n * @returns Last item\r\n */\r\nexport function last(array) {\r\n const length = array.length;\r\n return length ? array[length - 1] : undefined;\r\n}\r\n/**\r\n * Returns the first item of the array.\r\n *\r\n * @param array Source array\r\n * @returns Last item\r\n */\r\nexport function first(array) {\r\n return array[0];\r\n}\r\n/**\r\n * Inserts `element` into `array` at `index`.\r\n *\r\n * Caps `index` to be between `0` and `array.length`\r\n *\r\n * @param array Source array\r\n * @param element Item to insert\r\n * @param array Index to insert item at\r\n */\r\nexport function insert(array, element, index) {\r\n //if (array) {\r\n index = Math.max(0, Math.min(index, array.length));\r\n array.splice(index, 0, element);\r\n //}\r\n}\r\n/**\r\n * Removes all copies of `element` from `array` (if they exist) and then\r\n * inserts `element` at `index`.\r\n *\r\n * @param array Source array\r\n * @param element Item\r\n * @param array Index to move item to\r\n */\r\nexport function setIndex(array, element, index) {\r\n remove(array, element);\r\n insert(array, element, index);\r\n}\r\n/**\r\n * Pushes all of the elements from `input` into `array`.\r\n *\r\n * @param array Output array\r\n * @param input Input array\r\n */\r\nexport function pushAll(array, input) {\r\n const length = input.length;\r\n for (let i = 0; i < length; ++i) {\r\n array.push(input[i]);\r\n }\r\n}\r\n/**\r\n * Removes `element` from `array`.\r\n *\r\n * If there are multiple copies of `element`, they are all removed.\r\n *\r\n * @param array Source array\r\n * @param element Item to remove\r\n */\r\nexport function remove(array, element) {\r\n let found = false;\r\n let index = 0;\r\n for (;;) {\r\n index = array.indexOf(element, index);\r\n if (index === -1) {\r\n return found;\r\n }\r\n else {\r\n found = true;\r\n array.splice(index, 1);\r\n }\r\n }\r\n}\r\nexport function removeFirst(array, element) {\r\n let index = array.indexOf(element);\r\n if (index !== -1) {\r\n array.splice(index, 1);\r\n return true;\r\n }\r\n else {\r\n return false;\r\n }\r\n}\r\n/**\r\n * Adds an `element` to `array`.\r\n *\r\n * If array already contains and item like this, it is removed before adding\r\n * it again.\r\n *\r\n * Optionally `toIndex` can be specified to add element at specific index.\r\n *\r\n * @param array Source array\r\n * @param element Item to add\r\n * @param array Index to move item to\r\n */\r\nexport function move(array, element, toIndex) {\r\n // @todo this implementation must be the same as the List.moveValue method\r\n // @todo don't do anything if the desired index is the same as the current index\r\n let index = indexOf(array, element);\r\n // @todo remove all old values rather than only the first ?\r\n if (index !== -1) {\r\n removeIndex(array, index);\r\n }\r\n if (toIndex == null) {\r\n array.push(element);\r\n }\r\n else {\r\n insertIndex(array, toIndex, element);\r\n }\r\n}\r\n/**\r\n * Inserts `element` into `array` at `index`.\r\n *\r\n * If `index` is not provided, it will insert `element` at the end of `array`.\r\n *\r\n * @param array Source array\r\n * @param element Item to add\r\n * @param array Index to add item at\r\n */\r\nexport function add(array, element, index) {\r\n // Append to the end if index is not set\r\n if (!$type.isNumber(index)) {\r\n array.push(element);\r\n }\r\n // Add to the beginning of array if index is 0\r\n else if (index === 0) {\r\n array.unshift(element);\r\n }\r\n // Add to indicated place if index is set\r\n else {\r\n array.splice(index, 0, element);\r\n }\r\n}\r\n/**\r\n * Pushes `element` into `array` if it doesn't already exist.\r\n *\r\n * @param array Source array\r\n * @param element Item to add\r\n */\r\nexport function pushOne(array, element) {\r\n if (array.indexOf(element) === -1) {\r\n array.push(element);\r\n }\r\n}\r\n/**\r\n * Removes `element` from `array` (if it exists) and then inserts `element` at\r\n * `index`.\r\n *\r\n * If `index` is not provided, it will insert `element` at the end of `array`.\r\n *\r\n * @param array Source array\r\n * @param element Item to remove\r\n * @param array Index to move item to\r\n */\r\nexport function replace(array, element, index) {\r\n // check if exists\r\n let ind = array.indexOf(element);\r\n // remove if exists\r\n if (ind !== -1) {\r\n array.splice(ind, 1);\r\n }\r\n // add to end if index is not set\r\n if (!$type.isNumber(index)) {\r\n array.push(element);\r\n }\r\n // add to indicated place if index is set\r\n else {\r\n array.splice(index, 0, element);\r\n }\r\n}\r\n/**\r\n * Wraps `input` in an array, if it isn't already an array.\r\n *\r\n * @param input Source value\r\n * @return An array\r\n */\r\nexport function toArray(input) {\r\n if (Array.isArray(input)) {\r\n return input;\r\n }\r\n else {\r\n return [input];\r\n }\r\n}\r\n/**\r\n * Returns `true` if `element` exists in `array`.\r\n *\r\n * @param array Source array\r\n * @param element Item to search for\r\n * @returns Item in array?\r\n */\r\nexport function has(array, element) {\r\n return indexOf(array, element) !== -1;\r\n}\r\n/**\r\n * Returns a shallow copy of `array`.\r\n *\r\n * @param array Source array\r\n * @returns Copy of the array\r\n */\r\nexport function copy(array) {\r\n const length = array.length;\r\n // It's faster to create the array with a pre-defined length\r\n const output = new Array(length);\r\n for (let i = 0; i < length; ++i) {\r\n // Because the array has a pre-defined length, we have to assign rather than push\r\n // This is also faster than pushing\r\n output[i] = array[i];\r\n }\r\n return output;\r\n}\r\n/**\r\n * Returns a copy of `array` which contains all the elements between `start`\r\n * and `end`. (including `start` and excluding `end`)\r\n *\r\n * If `end` is not provided, it defaults to `array.length`.\r\n *\r\n * @param array Source array\r\n * @param start Start index\r\n * @param end End index\r\n * @returns Part of the array\r\n */\r\nexport function slice(array, start, end = array.length) {\r\n const output = new Array(end - start);\r\n for (let i = start; i < end; ++i) {\r\n output[i - start] = array[i];\r\n }\r\n return output;\r\n}\r\n/**\r\n * Inserts a value into array at specific index.\r\n *\r\n * @param array Source array\r\n * @param index Index\r\n * @param value Value to insert\r\n */\r\nexport function insertIndex(array, index, value) {\r\n array.splice(index, 0, value);\r\n}\r\n/**\r\n * Removes a value from array at specific index.\r\n *\r\n * @param array Source array\r\n * @param index Index\r\n */\r\nexport function removeIndex(array, index) {\r\n array.splice(index, 1);\r\n}\r\n/**\r\n * Searches the array using custom function and returns index of the item if\r\n * found.\r\n *\r\n * Will call `matches` function on all items of the array. If return value\r\n * evaluates to `true`, index is returned.\r\n *\r\n * Otherwise returns -1.\r\n *\r\n * @param array Source array\r\n * @param matches Search function\r\n * @returns Index of the item if found\r\n */\r\nexport function findIndex(array, matches) {\r\n const length = array.length;\r\n for (let i = 0; i < length; ++i) {\r\n if (matches(array[i], i)) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n}\r\n/**\r\n * This is the same as `findIndex` except it searches from right to left.\r\n *\r\n * @param array Source array\r\n * @param matches Search function\r\n * @returns Index of the item if found\r\n */\r\nexport function findIndexReverse(array, matches) {\r\n let i = array.length;\r\n while (i > 0) {\r\n --i;\r\n if (matches(array[i], i)) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n}\r\n/**\r\n * Searches the array using custom function and returns item if found.\r\n *\r\n * Will call `matches` function on all items of the array. If return value\r\n * evaluates to `true`, index is returned.\r\n *\r\n * Otherwise returns `undefined`.\r\n *\r\n * @param array Source array\r\n * @param matches Search function\r\n * @returns Item if found\r\n */\r\nexport function find(array, matches) {\r\n const index = findIndex(array, matches);\r\n if (index !== -1) {\r\n return array[index];\r\n }\r\n}\r\n/**\r\n * This is the same as `find` except it searches from right to left.\r\n *\r\n * @param array Source array\r\n * @param matches Search function\r\n * @returns Item if found\r\n */\r\nexport function findReverse(array, matches) {\r\n const index = findIndexReverse(array, matches);\r\n if (index !== -1) {\r\n return array[index];\r\n }\r\n}\r\n/**\r\n * Searches the array using custom function and returns item if found.\r\n *\r\n * Will call `matches` function on all items of the array. If value\r\n * is not `undefined`, it returns it.\r\n *\r\n * Otherwise returns `undefined`.\r\n *\r\n * @param array Source array\r\n * @param matches Search function\r\n * @returns Item if found\r\n */\r\nexport function findMap(array, matches) {\r\n const length = array.length;\r\n for (let i = 0; i < length; ++i) {\r\n const value = matches(array[i], i);\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n }\r\n}\r\n/**\r\n * Iterates through all items in array and calls `fn` function for each of\r\n * them.\r\n *\r\n * @param array Source array\r\n * @param fn Callback function\r\n */\r\nexport function shuffle(array) {\r\n // https://stackoverflow.com/a/2450976/449477\r\n let currentIndex = array.length, temporaryValue, randomIndex;\r\n // While there remain elements to shuffle...\r\n while (0 !== currentIndex) {\r\n // Pick a remaining element...\r\n randomIndex = Math.floor(Math.random() * currentIndex);\r\n currentIndex -= 1;\r\n // And swap it with the current element.\r\n temporaryValue = array[currentIndex];\r\n array[currentIndex] = array[randomIndex];\r\n array[randomIndex] = temporaryValue;\r\n }\r\n}\r\n/**\r\n * Orders an array using specific `ordering` function and returns right-most index of\r\n * the `value`.\r\n *\r\n * @ignore Exclude from docs\r\n * @param array Source array\r\n * @param ordering An ordering function\r\n * @returns Result of the search\r\n */\r\nexport function getSortedIndex(array, ordering) {\r\n let start = 0;\r\n let end = array.length;\r\n let found = false;\r\n while (start < end) {\r\n // TODO is this faster/slower than using Math.floor ?\r\n const pivot = (start + end) >> 1;\r\n const order = ordering(array[pivot]);\r\n // less\r\n if (order < 0) {\r\n start = pivot + 1;\r\n // equal\r\n }\r\n else if (order === 0) {\r\n found = true;\r\n start = pivot + 1;\r\n // more\r\n }\r\n else {\r\n end = pivot;\r\n }\r\n }\r\n return {\r\n found: found,\r\n index: (found ? start - 1 : start)\r\n };\r\n}\r\n/**\r\n * Orders an array using specific `ordering` function and returns left-most index of\r\n * the `value`.\r\n *\r\n * @ignore Exclude from docs\r\n * @param array Source array\r\n * @param ordering An ordering function\r\n * @returns Result of the search\r\n */\r\nexport function getFirstSortedIndex(array, ordering) {\r\n let start = 0;\r\n let end = array.length;\r\n let found = false;\r\n while (start < end) {\r\n // TODO is this faster/slower than using Math.floor ?\r\n const pivot = (start + end) >> 1;\r\n const order = ordering(array[pivot]);\r\n // less\r\n if (order < 0) {\r\n start = pivot + 1;\r\n // equal\r\n }\r\n else if (order === 0) {\r\n found = true;\r\n end = pivot;\r\n // more\r\n }\r\n else {\r\n end = pivot;\r\n }\r\n }\r\n return {\r\n found: found,\r\n index: start\r\n };\r\n}\r\nexport function keepIf(array, keep) {\r\n let i = array.length;\r\n while (i > 0) {\r\n --i;\r\n if (!keep(array[i])) {\r\n array.splice(i, 1);\r\n }\r\n }\r\n}\r\n//# sourceMappingURL=Array.js.map","import * as $array from \"./Array\";\r\nexport function keys(object) {\r\n return Object.keys(object);\r\n}\r\n/**\r\n * Returns an array of object's property names ordered using specific ordering\r\n * function.\r\n *\r\n * @param object Source object\r\n * @param order Ordering function\r\n * @returns Object property names\r\n */\r\nexport function keysOrdered(object, order) {\r\n return keys(object).sort(order);\r\n}\r\nexport function copy(object) {\r\n return Object.assign({}, object);\r\n}\r\nexport function each(object, f) {\r\n keys(object).forEach((key) => {\r\n f(key, object[key]);\r\n });\r\n}\r\n/**\r\n * Iterates through all properties of the object calling `fn` for each of them.\r\n *\r\n * If return value of the function evaluates to `false` further iteration is\r\n * cancelled.\r\n *\r\n * @param object Source object\r\n * @param fn Callback function\r\n */\r\nexport function eachContinue(object, fn) {\r\n for (let key in object) {\r\n if (hasKey(object, key)) {\r\n if (!fn(key, object[key])) {\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n/**\r\n * Orders object properties using custom `ord` function and iterates through\r\n * them calling `fn` for each of them.\r\n *\r\n * @param object Source object\r\n * @param fn Callback function\r\n * @param order Ordering function\r\n */\r\nexport function eachOrdered(object, fn, ord) {\r\n $array.each(keysOrdered(object, ord), (key) => {\r\n fn(key, object[key]);\r\n });\r\n}\r\n/**\r\n * Checks if `object` has a specific `key`.\r\n *\r\n * @param object Source object\r\n * @param key Property name\r\n * @returns Has key?\r\n */\r\nexport function hasKey(object, key) {\r\n return {}.hasOwnProperty.call(object, key);\r\n}\r\n/**\r\n * Copies all properties of one object to the other, omitting undefined, but only if property in target object doesn't have a value set.\r\n *\r\n * @param fromObject Source object\r\n * @param toObject Target object\r\n * @return Updated target object\r\n * @todo Maybe consolidate with utils.copy?\r\n */\r\nexport function softCopyProperties(source, target) {\r\n each(source, (key, value) => {\r\n // only if value is set\r\n //if ($type.hasValue(value) && !($type.hasValue((target)[key]))) {\r\n if (value != null && target[key] == null) {\r\n target[key] = value;\r\n }\r\n });\r\n return target;\r\n}\r\n//# sourceMappingURL=Object.js.map","/**\r\n * ============================================================================\r\n * IMPORTS\r\n * ============================================================================\r\n * @hidden\r\n */\r\nimport * as $array from \"./Array\";\r\n/**\r\n * A base class for disposable objects.\r\n *\r\n * @ignore Exclude from docs\r\n */\r\nexport class DisposerClass {\r\n /**\r\n * Constructor.\r\n */\r\n constructor() {\r\n /**\r\n * Is object disposed?\r\n */\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._disposed = false;\r\n }\r\n /**\r\n * Checks if object is disposed.\r\n *\r\n * @return Disposed?\r\n */\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n /**\r\n * Disposes the object.\r\n */\r\n dispose() {\r\n if (!this._disposed) {\r\n this._disposed = true;\r\n this._dispose();\r\n }\r\n }\r\n}\r\n/**\r\n * A class for creating an IDisposer.\r\n *\r\n * @ignore Exclude from docs\r\n */\r\nexport class Disposer {\r\n /**\r\n * Constructor.\r\n *\r\n * @param dispose Function that disposes object\r\n */\r\n constructor(dispose) {\r\n /**\r\n * Is object disposed?\r\n */\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * Method that disposes the object.\r\n */\r\n Object.defineProperty(this, \"_dispose\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._disposed = false;\r\n this._dispose = dispose;\r\n }\r\n /**\r\n * Checks if object is disposed.\r\n *\r\n * @return Disposed?\r\n */\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n /**\r\n * Disposes the object.\r\n */\r\n dispose() {\r\n if (!this._disposed) {\r\n this._disposed = true;\r\n this._dispose();\r\n }\r\n }\r\n}\r\n/**\r\n * This can be extended by other classes to add a `_disposers` property.\r\n *\r\n * @ignore Exclude from docs\r\n */\r\nexport class ArrayDisposer extends DisposerClass {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_disposers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n }\r\n _dispose() {\r\n $array.each(this._disposers, (x) => {\r\n x.dispose();\r\n });\r\n }\r\n}\r\n/**\r\n * A collection of related disposers that can be disposed in one go.\r\n *\r\n * @ignore Exclude from docs\r\n */\r\nexport class MultiDisposer extends DisposerClass {\r\n constructor(disposers) {\r\n super();\r\n Object.defineProperty(this, \"_disposers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._disposers = disposers;\r\n }\r\n _dispose() {\r\n $array.each(this._disposers, (x) => {\r\n x.dispose();\r\n });\r\n }\r\n get disposers() {\r\n return this._disposers;\r\n }\r\n}\r\n/**\r\n * A special kind of Disposer that has attached value set.\r\n *\r\n * If a new value is set using `set()` method, the old disposer value is\r\n * disposed.\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n */\r\nexport class MutableValueDisposer extends DisposerClass {\r\n constructor() {\r\n super(...arguments);\r\n /**\r\n * Current disposer.\r\n */\r\n Object.defineProperty(this, \"_disposer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * Current value.\r\n */\r\n Object.defineProperty(this, \"_value\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n _dispose() {\r\n if (this._disposer != null) {\r\n this._disposer.dispose();\r\n this._disposer = undefined;\r\n }\r\n }\r\n /**\r\n * Returns current value.\r\n *\r\n * @return Value\r\n */\r\n get() {\r\n return this._value;\r\n }\r\n /**\r\n * Sets value and disposes previous disposer if it was set.\r\n *\r\n * @param value New value\r\n * @param disposer Disposer\r\n */\r\n set(value, disposer) {\r\n if (this._disposer != null) {\r\n this._disposer.dispose();\r\n }\r\n this._disposer = disposer;\r\n this._value = value;\r\n }\r\n /**\r\n * Resets the disposer value.\r\n */\r\n reset() {\r\n this.set(undefined, undefined);\r\n }\r\n}\r\n/**\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n */\r\nexport class CounterDisposer extends Disposer {\r\n constructor() {\r\n super(...arguments);\r\n /**\r\n * [_counter description]\r\n *\r\n * @todo Description\r\n */\r\n Object.defineProperty(this, \"_counter\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n }\r\n /**\r\n * [increment description]\r\n *\r\n * @todo Description\r\n */\r\n increment() {\r\n // TODO throw an error if it is disposed\r\n ++this._counter;\r\n // TODO make this more efficient\r\n return new Disposer(() => {\r\n --this._counter;\r\n if (this._counter === 0) {\r\n this.dispose();\r\n }\r\n });\r\n }\r\n}\r\n//# sourceMappingURL=Disposer.js.map","import * as $type from \"./Type\";\r\nimport * as $array from \"./Array\";\r\nimport * as $object from \"./Object\";\r\nimport { Disposer, DisposerClass } from \"./Disposer\";\r\n/**\r\n * ============================================================================\r\n * DOM FUNCTIONS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Execute a function when DOM is ready.\r\n *\r\n * @since 5.0.2\r\n * @param f Callback\r\n */\r\nexport function ready(f) {\r\n if (document.readyState !== \"loading\") {\r\n f();\r\n }\r\n else {\r\n const listener = () => {\r\n if (document.readyState !== \"loading\") {\r\n document.removeEventListener(\"readystatechange\", listener);\r\n f();\r\n }\r\n };\r\n document.addEventListener(\"readystatechange\", listener);\r\n }\r\n}\r\n/**\r\n * Removes a DOM element.\r\n * @param el Target element\r\n */\r\nexport function removeElement(el) {\r\n if (el.parentNode) {\r\n el.parentNode.removeChild(el);\r\n }\r\n}\r\n/**\r\n * Function that adds a disposable event listener directly to a DOM element.\r\n *\r\n * @ignore Exclude from docs\r\n * @param dom A DOM element to add event to\r\n * @param type Event type\r\n * @param listener Event listener\r\n * @returns Disposable event\r\n */\r\nexport function addEventListener(dom, type, listener, options) {\r\n //@todo proper type check for options: EventListenerOptions | boolean (TS for some reason gives error on passive parameter)\r\n dom.addEventListener(type, listener, options || false);\r\n return new Disposer(() => {\r\n dom.removeEventListener(type, listener, options || false);\r\n });\r\n}\r\n/**\r\n * Function that adds an event listener which is triggered when the browser's zoom changes.\r\n *\r\n * @param listener Event listener\r\n * @returns Disposable event\r\n */\r\nexport function onZoom(listener) {\r\n // TODO use matchMedia instead ?\r\n return addEventListener(window, \"resize\", (_ev) => {\r\n listener();\r\n });\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function supports(cap) {\r\n switch (cap) {\r\n case \"touchevents\":\r\n //return \"ontouchstart\" in document.documentElement;\r\n return window.hasOwnProperty(\"TouchEvent\");\r\n case \"pointerevents\":\r\n return window.hasOwnProperty(\"PointerEvent\");\r\n case \"mouseevents\":\r\n return window.hasOwnProperty(\"MouseEvent\");\r\n case \"wheelevents\":\r\n return window.hasOwnProperty(\"WheelEvent\");\r\n case \"keyboardevents\":\r\n return window.hasOwnProperty(\"KeyboardEvent\");\r\n }\r\n return false;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function getPointerId(event) {\r\n let id = event.pointerId || 0;\r\n return id;\r\n}\r\n/**\r\n * Removes focus from any element by shifting focus to body.\r\n *\r\n * @ignore\r\n */\r\nexport function blur() {\r\n if (document.activeElement && document.activeElement != document.body) {\r\n if (document.activeElement.blur) {\r\n document.activeElement.blur();\r\n }\r\n else {\r\n let input = document.createElement(\"button\");\r\n input.style.position = \"fixed\";\r\n input.style.top = \"0px\";\r\n input.style.left = \"-10000px\";\r\n document.body.appendChild(input);\r\n input.focus();\r\n input.blur();\r\n document.body.removeChild(input);\r\n }\r\n }\r\n}\r\n/**\r\n * Focuses element.\r\n *\r\n * @ignore\r\n */\r\nexport function focus(el) {\r\n if (el) {\r\n el.focus();\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function getRendererEvent(key) {\r\n if (supports(\"pointerevents\")) {\r\n return key;\r\n }\r\n else if (supports(\"touchevents\")) {\r\n switch (key) {\r\n case \"pointerover\": return \"touchstart\";\r\n case \"pointerout\": return \"touchend\";\r\n case \"pointerleave\": return \"touchend\";\r\n case \"pointerdown\": return \"touchstart\";\r\n case \"pointermove\": return \"touchmove\";\r\n case \"pointerup\": return \"touchend\";\r\n case \"click\": return \"click\";\r\n case \"dblclick\": return \"dblclick\";\r\n }\r\n }\r\n else if (supports(\"mouseevents\")) {\r\n switch (key) {\r\n case \"pointerover\": return \"mouseover\";\r\n case \"pointerout\": return \"mouseout\";\r\n case \"pointerleave\": return \"mouseleave\";\r\n case \"pointerdown\": return \"mousedown\";\r\n case \"pointermove\": return \"mousemove\";\r\n case \"pointerup\": return \"mouseup\";\r\n case \"click\": return \"click\";\r\n case \"dblclick\": return \"dblclick\";\r\n }\r\n }\r\n return key;\r\n}\r\n/**\r\n * Determines if pointer event originated from a touch pointer or mouse.\r\n *\r\n * @param ev Original event\r\n * @return Touch pointer?\r\n */\r\nexport function isTouchEvent(ev) {\r\n if (typeof Touch !== \"undefined\" && ev instanceof Touch) {\r\n return true;\r\n }\r\n else if (typeof PointerEvent !== \"undefined\" && ev instanceof PointerEvent && ev.pointerType != null) {\r\n switch (ev.pointerType) {\r\n case \"touch\":\r\n case \"pen\":\r\n case 2:\r\n return true;\r\n case \"mouse\":\r\n case 4:\r\n return false;\r\n default:\r\n return !(ev instanceof MouseEvent);\r\n }\r\n }\r\n else if (ev.type != null) {\r\n if (ev.type.match(/^mouse/)) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n/**\r\n * Sets style property on DOM element.\r\n *\r\n * @ignore Exclude from docs\r\n */\r\nexport function setStyle(dom, property, value) {\r\n dom.style[property] = value;\r\n}\r\nexport function getStyle(dom, property) {\r\n return dom.style[property];\r\n}\r\n/**\r\n * Gets the target of the event, works for shadow DOM too.\r\n */\r\nexport function getEventTarget(event) {\r\n if (event.composedPath) {\r\n const path = event.composedPath();\r\n if (path.length === 0) {\r\n return null;\r\n }\r\n else {\r\n return path[0];\r\n }\r\n }\r\n else {\r\n return event.target;\r\n }\r\n}\r\n/**\r\n * Checks of element `a` contains element `b`.\r\n *\r\n * @param a Aleged ascendant\r\n * @param b Aleged descendant\r\n * @return Contains?\r\n */\r\nexport function contains(a, b) {\r\n let cursor = b;\r\n while (true) {\r\n if (a === cursor) {\r\n return true;\r\n }\r\n else if (cursor.parentNode === null) {\r\n // TODO better ShadowRoot detection\r\n if (cursor.host == null) {\r\n return false;\r\n }\r\n else {\r\n cursor = cursor.host;\r\n }\r\n }\r\n else {\r\n cursor = cursor.parentNode;\r\n }\r\n }\r\n}\r\n/**\r\n * Returns `true` if pointer event originated on an element within Root.\r\n *\r\n * @since 5.2.8\r\n * @param event Event\r\n * @param target Target element\r\n */\r\nexport function isLocalEvent(event, target) {\r\n return event.target && contains(target.root.dom, event.target);\r\n}\r\n/**\r\n * Disables or enables interactivity of a DOM element.\r\n *\r\n * @param target Target element\r\n * @param interactive Interactive?\r\n */\r\nexport function setInteractive(target, interactive) {\r\n if (interactive) {\r\n target.style.pointerEvents = \"auto\";\r\n }\r\n else {\r\n target.style.pointerEvents = \"none\";\r\n }\r\n}\r\nexport function getEventKey(event) {\r\n if (event.key !== undefined) {\r\n return event.key;\r\n }\r\n switch (event.keyCode) {\r\n case 9: return \"Tab\";\r\n case 13: return \"Enter\";\r\n case 16: return \"Shift\";\r\n case 17: return \"Control\";\r\n case 27: return \"Escape\";\r\n case 32: return \" \";\r\n case 37: return \"ArrowLeft\";\r\n case 38: return \"ArrowUp\";\r\n case 39: return \"ArrowRight\";\r\n case 40: return \"ArrowDown\";\r\n case 46: return \"Delete\";\r\n }\r\n return \"\" + event.keyCode;\r\n}\r\n/**\r\n * Returns the shadow root of the element or null\r\n *\r\n * @param a Node\r\n * @return Root\r\n */\r\nexport function getShadowRoot(a) {\r\n let cursor = a;\r\n while (true) {\r\n if (cursor.parentNode === null) {\r\n // TODO better ShadowRoot detection\r\n if (cursor.host != null) {\r\n return cursor;\r\n }\r\n else {\r\n return null;\r\n }\r\n }\r\n else {\r\n cursor = cursor.parentNode;\r\n }\r\n }\r\n}\r\n/**\r\n * [rootStylesheet description]\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n */\r\nlet rootStylesheet;\r\n/**\r\n * @ignore Exclude from docs\r\n */\r\nfunction createStylesheet(element, text, nonce = \"\") {\r\n // TODO use createElementNS ?\r\n const e = document.createElement(\"style\");\r\n e.type = \"text/css\";\r\n if (nonce != \"\") {\r\n e.setAttribute(\"nonce\", nonce);\r\n }\r\n e.textContent = text;\r\n if (element === null) {\r\n document.head.appendChild(e);\r\n }\r\n else {\r\n element.appendChild(e);\r\n }\r\n return e;\r\n}\r\n/**\r\n * [getStylesheet description]\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n * @return [description]\r\n */\r\nfunction getStylesheet(element, nonce = \"\") {\r\n if (element === null) {\r\n if (rootStylesheet == null) {\r\n // TODO use createElementNS ?\r\n const e = document.createElement(\"style\");\r\n e.type = \"text/css\";\r\n if (nonce != \"\") {\r\n e.setAttribute(\"nonce\", nonce);\r\n }\r\n document.head.appendChild(e);\r\n rootStylesheet = e.sheet;\r\n }\r\n return rootStylesheet;\r\n }\r\n else {\r\n // TODO use createElementNS ?\r\n const e = document.createElement(\"style\");\r\n e.type = \"text/css\";\r\n if (nonce != \"\") {\r\n e.setAttribute(\"nonce\", nonce);\r\n }\r\n element.appendChild(e);\r\n return e.sheet;\r\n }\r\n}\r\n/**\r\n * [makeStylesheet description]\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n * @param selector [description]\r\n * @return [description]\r\n */\r\nfunction appendStylesheet(root, selector) {\r\n const index = root.cssRules.length;\r\n root.insertRule(selector + \"{}\", index);\r\n return root.cssRules[index];\r\n}\r\n/**\r\n * Defines a class for a CSS rule.\r\n *\r\n * Can be used to dynamically add CSS to the document.\r\n */\r\nexport class StyleRule extends DisposerClass {\r\n /**\r\n * Constructor.\r\n *\r\n * @param selector CSS selector\r\n * @param styles An object of style attribute - value pairs\r\n */\r\n constructor(element, selector, styles, nonce = \"\") {\r\n super();\r\n Object.defineProperty(this, \"_root\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * CSS rule.\r\n */\r\n Object.defineProperty(this, \"_rule\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._root = getStylesheet(element, nonce);\r\n try {\r\n this._rule = appendStylesheet(this._root, selector);\r\n }\r\n catch (err) {\r\n // Create an empty rule on failed selectors\r\n this._rule = appendStylesheet(this._root, \":not(*)\");\r\n }\r\n $object.each(styles, (key, value) => {\r\n this.setStyle(key, value);\r\n });\r\n }\r\n /**\r\n * A CSS selector text.\r\n *\r\n * E.g.: `.myClass p`\r\n *\r\n * @param selector CSS selector\r\n */\r\n set selector(selector) {\r\n this._rule.selectorText = selector;\r\n }\r\n /**\r\n * @return CSS selector\r\n */\r\n get selector() {\r\n return this._rule.selectorText;\r\n }\r\n // TODO test this\r\n _dispose() {\r\n // TODO a bit hacky\r\n const index = $array.indexOf(this._root.cssRules, this._rule);\r\n if (index === -1) {\r\n throw new Error(\"Could not dispose StyleRule\");\r\n }\r\n else {\r\n // TODO if it's empty remove it from the DOM ?\r\n this._root.deleteRule(index);\r\n }\r\n }\r\n /**\r\n * Sets the same style properties with browser-specific prefixes.\r\n *\r\n * @param name Attribute name\r\n * @param value Attribute value\r\n */\r\n _setVendorPrefixName(name, value) {\r\n const style = this._rule.style;\r\n style.setProperty(\"-webkit-\" + name, value, \"\");\r\n style.setProperty(\"-moz-\" + name, value, \"\");\r\n style.setProperty(\"-ms-\" + name, value, \"\");\r\n style.setProperty(\"-o-\" + name, value, \"\");\r\n style.setProperty(name, value, \"\");\r\n }\r\n /**\r\n * Sets a value for specific style attribute.\r\n *\r\n * @param name Attribute\r\n * @param value Value\r\n */\r\n setStyle(name, value) {\r\n if (name === \"transition\") {\r\n this._setVendorPrefixName(name, value);\r\n }\r\n else {\r\n this._rule.style.setProperty(name, value, \"\");\r\n }\r\n }\r\n}\r\n/**\r\n * Defines a class for an entire CSS style sheet.\r\n *\r\n * Can be used to dynamically add CSS to the document.\r\n */\r\nexport class StyleSheet extends DisposerClass {\r\n /**\r\n * Constructor.\r\n *\r\n * @param text CSS stylesheet\r\n */\r\n constructor(element, text, nonce = \"\") {\r\n super();\r\n Object.defineProperty(this, \"_element\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._element = createStylesheet(element, text, nonce);\r\n }\r\n _dispose() {\r\n if (this._element.parentNode) {\r\n this._element.parentNode.removeChild(this._element);\r\n }\r\n }\r\n}\r\n/**\r\n * Adds a class name to an HTML or SVG element.\r\n *\r\n * @ignore Exclude from docs\r\n * @param element Element\r\n * @param className Class name to add\r\n */\r\nexport function addClass(element, className) {\r\n if (!element) {\r\n return;\r\n }\r\n if (element.classList) {\r\n const classes = className.split(\" \");\r\n $array.each(classes, (name) => {\r\n element.classList.add(name);\r\n });\r\n }\r\n else {\r\n let currentClassName = element.getAttribute(\"class\");\r\n if (currentClassName) {\r\n element.setAttribute(\"class\", currentClassName.split(\" \").filter((item) => {\r\n return item !== className;\r\n }).join(\" \") + \" \" + className);\r\n }\r\n else {\r\n element.setAttribute(\"class\", className);\r\n }\r\n }\r\n}\r\n/**\r\n * Removes a class name from an HTML or SVG element.\r\n *\r\n * @ignore Exclude from docs\r\n * @param element Element\r\n * @param className Class name to add\r\n */\r\nexport function removeClass(element, className) {\r\n if (!element) {\r\n return;\r\n }\r\n if (element.classList) {\r\n element.classList.remove(className);\r\n }\r\n else {\r\n let currentClassName = element.getAttribute(\"class\");\r\n if (currentClassName) {\r\n element.setAttribute(\"class\", currentClassName.split(\" \").filter((item) => {\r\n return item !== className;\r\n }).join(\" \"));\r\n }\r\n }\r\n}\r\n// /**\r\n// * Applies a set of styles to an element. Stores the original styles so they\r\n// * can be restored later.\r\n// *\r\n// * @ignore\r\n// * @param io Element\r\n// */\r\n// export function prepElementForDrag(dom: HTMLElement): void {\r\n// \t// @todo: save current values\r\n// \t// Define possible props\r\n// \tlet props = [\r\n// \t\t\"touchAction\", \"webkitTouchAction\", \"MozTouchAction\", \"MSTouchAction\", \"msTouchAction\", \"oTouchAction\",\r\n// \t\t\"userSelect\", \"webkitUserSelect\", \"MozUserSelect\", \"MSUserSelect\", \"msUserSelect\", \"oUserSelect\",\r\n// \t\t\"touchSelect\", \"webkitTouchSelect\", \"MozTouchSelect\", \"MSTouchSelect\", \"msTouchSelect\", \"oTouchSelect\",\r\n// \t\t\"touchCallout\", \"webkitTouchCallout\", \"MozTouchCallout\", \"MSTouchCallout\", \"msTouchCallout\", \"oTouchCallout\",\r\n// \t\t\"contentZooming\", \"webkitContentZooming\", \"MozContentZooming\", \"MSContentZooming\", \"msContentZooming\", \"oContentZooming\",\r\n// \t\t\"userDrag\", \"webkitUserDrag\", \"MozUserDrag\", \"MSUserDrag\", \"msUserDrag\", \"oUserDrag\"\r\n// \t];\r\n// \tfor (let i = 0; i < props.length; i++) {\r\n// \t\tif (props[i] in dom.style) {\r\n// \t\t\tsetStyle(dom, props[i], \"none\");\r\n// \t\t}\r\n// \t}\r\n// \t// Remove iOS-specific selection;\r\n// \tsetStyle(dom, \"tapHighlightColor\", \"rgba(0, 0, 0, 0)\");\r\n// }\r\n// /**\r\n// * Restores replaced styles\r\n// *\r\n// * @ignore\r\n// * @param io Element\r\n// */\r\n// export function unprepElementForDrag(dom: HTMLElement): void {\r\n// \t// Define possible props\r\n// \tlet props = [\r\n// \t\t\"touchAction\", \"webkitTouchAction\", \"MozTouchAction\", \"MSTouchAction\", \"msTouchAction\", \"oTouchAction\",\r\n// \t\t\"userSelect\", \"webkitUserSelect\", \"MozUserSelect\", \"MSUserSelect\", \"msUserSelect\", \"oUserSelect\",\r\n// \t\t\"touchSelect\", \"webkitTouchSelect\", \"MozTouchSelect\", \"MSTouchSelect\", \"msTouchSelect\", \"oTouchSelect\",\r\n// \t\t\"touchCallout\", \"webkitTouchCallout\", \"MozTouchCallout\", \"MSTouchCallout\", \"msTouchCallout\", \"oTouchCallout\",\r\n// \t\t\"contentZooming\", \"webkitContentZooming\", \"MozContentZooming\", \"MSContentZooming\", \"msContentZooming\", \"oContentZooming\",\r\n// \t\t\"userDrag\", \"webkitUserDrag\", \"MozUserDrag\", \"MSUserDrag\", \"msUserDrag\", \"oUserDrag\"\r\n// \t];\r\n// \tfor (let i = 0; i < props.length; i++) {\r\n// \t\tif (props[i] in dom.style) {\r\n// \t\t\tsetStyle(dom, props[i], \"\");\r\n// \t\t}\r\n// \t}\r\n// \t// Remove iOS-specific selection;\r\n// \tsetStyle(dom, \"tapHighlightColor\", \"\");\r\n// }\r\nexport function iOS() {\r\n return /apple/i.test(navigator.vendor) && \"ontouchend\" in document;\r\n}\r\nexport function getSafeResolution() {\r\n return iOS() ? 1 : undefined;\r\n}\r\nexport function relativeToValue(percent, full) {\r\n if ($type.isNumber(percent)) {\r\n return percent;\r\n }\r\n else if (percent != null && $type.isNumber(percent.value) && $type.isNumber(full)) {\r\n return full * percent.value;\r\n }\r\n else {\r\n return 0;\r\n }\r\n}\r\n/**\r\n * Returns number of decimals\r\n *\r\n * @ignore Exclude from docs\r\n * @param number Input number\r\n * @return Number of decimals\r\n */\r\nexport function decimalPlaces(number) {\r\n let match = ('' + number).match(/(?:\\.(\\d+))?(?:[eE]([+-]?\\d+))?$/);\r\n if (!match) {\r\n return 0;\r\n }\r\n return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));\r\n}\r\n/**\r\n * ============================================================================\r\n * STRING FORMATTING FUNCTIONS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Pads a string with additional characters to certain length.\r\n *\r\n * @param value A numeric value\r\n * @param len Result string length in characters\r\n * @param char A character to use for padding\r\n * @return Padded value as string\r\n */\r\nexport function padString(value, len = 0, char = \"0\") {\r\n if (typeof value !== \"string\") {\r\n value = value.toString();\r\n }\r\n return len > value.length ? Array(len - value.length + 1).join(char) + value : value;\r\n}\r\nexport function trimLeft(text) {\r\n return text.replace(/^[\\s]*/, \"\");\r\n}\r\nexport function trimRight(text) {\r\n return text.replace(/[\\s]*$/, \"\");\r\n}\r\nexport function trim(text) {\r\n return trimLeft(trimRight(text));\r\n}\r\nexport function truncateTextWithEllipsis(text, maxLength, breakWords = false, ellipsis = \"...\") {\r\n if (text.length > maxLength) {\r\n // Find the last non-alphanumeric character before maxLength\r\n let lastNonAlphanumericIndex = maxLength - 1;\r\n while (lastNonAlphanumericIndex >= 0 && text.charAt(lastNonAlphanumericIndex).match(/\\w/)) {\r\n lastNonAlphanumericIndex--;\r\n }\r\n if (lastNonAlphanumericIndex >= 0 && breakWords == false) {\r\n return text.substring(0, lastNonAlphanumericIndex + 1) + '...';\r\n }\r\n else {\r\n // If no non-alphanumeric character found, truncate without breaking words\r\n return text.substring(0, maxLength) + ellipsis;\r\n }\r\n }\r\n else {\r\n return text;\r\n }\r\n}\r\n/**\r\n * Tries to determine format type.\r\n *\r\n * @ignore Exclude from docs\r\n * @param format Format string\r\n * @return Format type (\"string\" | \"number\" | \"date\" | \"duration\")\r\n */\r\nexport function getFormat(format) {\r\n // Undefined?\r\n if (typeof format === \"undefined\") {\r\n return \"string\";\r\n }\r\n // Cleanup and lowercase format\r\n format = format.toLowerCase().replace(/^\\[[^\\]]*\\]/, \"\");\r\n // Remove style tags\r\n format = format.replace(/\\[[^\\]]+\\]/, \"\");\r\n // Trim\r\n format = format.trim();\r\n // Check for any explicit format hints (i.e. /Date)\r\n let hints = format.match(/\\/(date|number|duration)$/);\r\n if (hints) {\r\n return hints[1];\r\n }\r\n // Check for explicit hints\r\n if (format === \"number\") {\r\n return \"number\";\r\n }\r\n if (format === \"date\") {\r\n return \"date\";\r\n }\r\n if (format === \"duration\") {\r\n return \"duration\";\r\n }\r\n // Detect number formatting symbols\r\n if (format.match(/[#0]/)) {\r\n return \"number\";\r\n }\r\n // Detect date formatting symbols\r\n if (format.match(/[ymwdhnsqaxkzgtei]/)) {\r\n return \"date\";\r\n }\r\n // Nothing? Let's display as string\r\n return \"string\";\r\n}\r\n/**\r\n * Cleans up format:\r\n * * Strips out formatter hints\r\n *\r\n * @ignore Exclude from docs\r\n * @param format Format\r\n * @return Cleaned format\r\n */\r\nexport function cleanFormat(format) {\r\n return format.replace(/\\/(date|number|duration)$/i, \"\");\r\n}\r\n/**\r\n * Strips all tags from the string.\r\n *\r\n * @param text Source string\r\n * @return String without tags\r\n */\r\nexport function stripTags(text) {\r\n return text ? text.replace(/<[^>]*>/g, \"\") : text;\r\n}\r\n/**\r\n * Removes new lines and tags from a string.\r\n *\r\n * @param text String to conver\r\n * @return Converted string\r\n */\r\nexport function plainText(text) {\r\n return text ? stripTags((\"\" + text).replace(/[\\n\\r]+/g, \". \")) : text;\r\n}\r\n/**\r\n * Escapes string so it can safely be used in a Regex.\r\n *\r\n * @param value Unsescaped string\r\n * @return Escaped string\r\n */\r\nexport function escapeForRgex(value) {\r\n return value.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\r\n}\r\n/**\r\n * Adds space before each uppercase letter.\r\n *\r\n * @param str Input string\r\n * @return Output string\r\n */\r\nexport function addSpacing(str) {\r\n let result = \"\";\r\n for (let i = 0; i < str.length; i++) {\r\n const char = str.charAt(i);\r\n if (char.toUpperCase() == char && i != 0) {\r\n result += \" \";\r\n }\r\n result += char;\r\n }\r\n return result;\r\n}\r\n/**\r\n * Splits the string into separate characters. Keeps RTL words non-split.\r\n *\r\n * @param source Input\r\n * @return Split text\r\n */\r\nexport function splitString(source) {\r\n // Regular expression to identify RTL characters\r\n const rtlChar = /[\\u0590-\\u05FF\\u0600-\\u06FF\\u0750-\\u077F\\u08A0-\\u08FF\\uFB50-\\uFDFF\\uFE70-\\uFEFF]/;\r\n // Regular expression to capture segments ending with specific Arabic characters\r\n const splitPattern = /([^اأدذرزو]*[اأدذرزو])/gi;\r\n // Split input string into array of words or characters, including whitespace\r\n let segments = source.split(/(\\s+)/); // Split by whitespace, capturing it\r\n let result = [];\r\n segments.forEach(segment => {\r\n if (segment.match(/^\\s+$/)) {\r\n // If the segment is purely whitespace\r\n if (segment = \" \") {\r\n segment = \" \";\r\n }\r\n result.push(segment);\r\n }\r\n else if (rtlChar.test(segment)) {\r\n // If the segment contains RTL characters, handle special splits\r\n let parts = segment.split(splitPattern).filter(part => part !== '');\r\n // Concatenate parts processed by the split pattern directly to result\r\n result = result.concat(parts);\r\n }\r\n else {\r\n // Treat this segment as LTR: split into characters\r\n result = result.concat([...segment]);\r\n }\r\n });\r\n return result;\r\n}\r\n/**\r\n * ============================================================================\r\n * DATE-RELATED FUNCTIONS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * Returns a year day.\r\n *\r\n * @param date Date\r\n * @param utc Assume UTC dates?\r\n * @return Year day\r\n * @todo Account for UTC\r\n */\r\nexport function getYearDay(date, utc = false) {\r\n // TODO: utc needed?\r\n utc;\r\n const start = new Date(date.getFullYear(), 0, 0);\r\n const diff = (date.getTime() - start.getTime()) + ((start.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000);\r\n const oneDay = 1000 * 60 * 60 * 24;\r\n return Math.floor(diff / oneDay);\r\n}\r\n/**\r\n * Returns week number for a given date.\r\n *\r\n * @param date Date\r\n * @param utc Assume UTC dates?\r\n * @return Week number\r\n * @todo Account for UTC\r\n */\r\nexport function getWeek(date, _utc = false) {\r\n const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));\r\n const day = d.getUTCDay() || 7;\r\n d.setUTCDate(d.getUTCDate() + 4 - day);\r\n const firstDay = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));\r\n return Math.ceil((((d.getTime() - firstDay.getTime()) / 86400000) + 1) / 7);\r\n}\r\n/**\r\n * Returns a \"week year\" of the given date.\r\n *\r\n * @param date Date\r\n * @param utc Assume UTC dates?\r\n * @return Year of week\r\n * @since 5.3.0\r\n * @todo Account for UTC\r\n */\r\nexport function getWeekYear(date, _utc = false) {\r\n const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));\r\n const day = d.getUTCDay() || 7;\r\n d.setUTCDate(d.getUTCDate() + 4 - day);\r\n const firstDay = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));\r\n return firstDay.getFullYear();\r\n}\r\n/**\r\n * Returns a week number in the month.\r\n *\r\n * @param date Source Date\r\n * @param utc Assume UTC dates?\r\n * @return Week number in month\r\n */\r\nexport function getMonthWeek(date, utc = false) {\r\n const firstWeek = getWeek(new Date(date.getFullYear(), date.getMonth(), 1), utc);\r\n let currentWeek = getWeek(date, utc);\r\n if (currentWeek == 1) {\r\n currentWeek = 53;\r\n }\r\n return currentWeek - firstWeek + 1;\r\n}\r\n/**\r\n * Returns a year day out of the given week number.\r\n *\r\n * @param week Week\r\n * @param year Year\r\n * @param weekday Weekday\r\n * @param utc Assume UTC dates\r\n * @return Day in a year\r\n */\r\nexport function getDayFromWeek(week, year, weekday = 1, utc = false) {\r\n let date = new Date(year, 0, 4, 0, 0, 0, 0);\r\n if (utc) {\r\n date.setUTCFullYear(year);\r\n }\r\n let day = week * 7 + weekday - ((date.getDay() || 7) + 3);\r\n return day;\r\n}\r\n/**\r\n * Returns 12-hour representation out of the 24-hour hours.\r\n *\r\n * @param hours 24-hour number\r\n * @return 12-hour number\r\n */\r\nexport function get12Hours(hours, base) {\r\n if (hours > 12) {\r\n hours -= 12;\r\n }\r\n else if (hours === 0) {\r\n hours = 12;\r\n }\r\n return base != null ? hours + (base - 1) : hours;\r\n}\r\n/**\r\n * Returns a string name of the time zone.\r\n *\r\n * @param date Date object\r\n * @param long Should return long (\"Pacific Standard Time\") or short abbreviation (\"PST\")\r\n * @param savings Include information if it's in daylight savings mode\r\n * @param utc Assume UTC dates\r\n * @return Time zone name\r\n */\r\nexport function getTimeZone(date, long = false, savings = false, utc = false, timezone) {\r\n if (utc) {\r\n return long ? \"Coordinated Universal Time\" : \"UTC\";\r\n }\r\n else if (timezone) {\r\n const d1 = date.toLocaleString(\"en-US\", { timeZone: timezone });\r\n const d2 = date.toLocaleString(\"en-US\", { timeZone: timezone, timeZoneName: long ? \"long\" : \"short\" });\r\n return trim(d2.substr(d1.length));\r\n }\r\n let wotz = date.toLocaleString(\"UTC\");\r\n let wtz = date.toLocaleString(\"UTC\", { timeZoneName: long ? \"long\" : \"short\" }).substr(wotz.length);\r\n //wtz = wtz.replace(/[+-]+[0-9]+$/, \"\");\r\n if (savings === false) {\r\n wtz = wtz.replace(/ (standard|daylight|summer|winter) /i, \" \");\r\n }\r\n return trim(wtz);\r\n}\r\nexport function getTimezoneOffset(timezone) {\r\n const date = new Date(Date.UTC(2012, 0, 1, 0, 0, 0, 0));\r\n const utcDate = new Date(date.toLocaleString(\"en-US\", { timeZone: \"UTC\" }));\r\n const tzDate = new Date(date.toLocaleString(\"en-US\", { timeZone: timezone }));\r\n return (tzDate.getTime() - utcDate.getTime()) / 6e4 * -1;\r\n}\r\nexport function capitalizeFirst(text) {\r\n return text.charAt(0).toUpperCase() + text.slice(1);\r\n}\r\n/**\r\n * The functions below are taken and adapted from Garry Tan's blog post:\r\n * http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c\r\n *\r\n * The further attributions go mjijackson.com, which now seems to be defunct.\r\n */\r\n/**\r\n * Converts an HSL color value to RGB. Conversion formula\r\n * adapted from http://en.wikipedia.org/wiki/HSL_color_space.\r\n * Assumes h, s, and l are contained in the set [0, 1] and\r\n * returns r, g, and b in the set [0, 255].\r\n *\r\n * Function adapted from:\r\n * http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c\r\n *\r\n * @param h The hue\r\n * @param s The saturation\r\n * @param l The lightness\r\n * @return The RGB representation\r\n */\r\nexport function hslToRgb(color) {\r\n let r, g, b;\r\n let h = color.h;\r\n let s = color.s;\r\n let l = color.l;\r\n if (s == 0) {\r\n r = g = b = l; // achromatic\r\n }\r\n else {\r\n let hue2rgb = function hue2rgb(p, q, t) {\r\n if (t < 0) {\r\n t += 1;\r\n }\r\n if (t > 1) {\r\n t -= 1;\r\n }\r\n if (t < 1 / 6) {\r\n return p + (q - p) * 6 * t;\r\n }\r\n if (t < 1 / 2) {\r\n return q;\r\n }\r\n if (t < 2 / 3) {\r\n return p + (q - p) * (2 / 3 - t) * 6;\r\n }\r\n return p;\r\n };\r\n let q = l < 0.5 ? l * (1 + s) : l + s - l * s;\r\n let p = 2 * l - q;\r\n r = hue2rgb(p, q, h + 1 / 3);\r\n g = hue2rgb(p, q, h);\r\n b = hue2rgb(p, q, h - 1 / 3);\r\n }\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255)\r\n };\r\n}\r\n/**\r\n * Converts an RGB color value to HSL. Conversion formula\r\n * adapted from http://en.wikipedia.org/wiki/HSL_color_space.\r\n * Assumes r, g, and b are contained in the set [0, 255] and\r\n * returns h, s, and l in the set [0, 1].\r\n *\r\n * Function adapted from:\r\n * http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c\r\n *\r\n * @param r The red color value\r\n * @param g The green color value\r\n * @param b The blue color value\r\n * @return The HSL representation\r\n */\r\nexport function rgbToHsl(color) {\r\n let r = color.r / 255;\r\n let g = color.g / 255;\r\n let b = color.b / 255;\r\n let max = Math.max(r, g, b);\r\n let min = Math.min(r, g, b);\r\n let h = 0;\r\n let s = 0;\r\n let l = (max + min) / 2;\r\n if (max === min) {\r\n h = s = 0; // achromatic\r\n }\r\n else {\r\n let d = max - min;\r\n s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\r\n switch (max) {\r\n case r:\r\n h = (g - b) / d + (g < b ? 6 : 0);\r\n break;\r\n case g:\r\n h = (b - r) / d + 2;\r\n break;\r\n case b:\r\n h = (r - g) / d + 4;\r\n break;\r\n }\r\n h /= 6;\r\n }\r\n return {\r\n h: h,\r\n s: s,\r\n l: l,\r\n };\r\n}\r\n/**\r\n * Converts HSV to HSL.\r\n *\r\n * https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL\r\n */\r\nexport function hsvToHsl(hsv) {\r\n const l = hsv.v * (1 - (hsv.s / 2));\r\n const s = (l === 0 || l === 1\r\n ? 0\r\n : (hsv.v - l) / Math.min(l, 1 - l));\r\n return {\r\n h: hsv.h,\r\n s,\r\n l,\r\n a: hsv.a,\r\n };\r\n}\r\n/**\r\n * Converts HSL to HSV.\r\n *\r\n * https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV\r\n */\r\nexport function hslToHsv(hsl) {\r\n const v = hsl.l + (hsl.s * Math.min(hsl.l, 1 - hsl.l));\r\n const s = (v === 0\r\n ? 0\r\n : 2 * (1 - (hsl.l / v)));\r\n return {\r\n h: hsl.h,\r\n s,\r\n v,\r\n a: hsl.a,\r\n };\r\n}\r\n/**\r\n * Returns a color that is `percent` brighter than the reference color.\r\n *\r\n * @param color Reference color\r\n * @param percent Brightness percent\r\n * @return Hex code of the new color\r\n */\r\nexport function lighten(rgb, percent) {\r\n if (rgb) {\r\n return {\r\n r: Math.max(0, Math.min(255, rgb.r + getLightnessStep(rgb.r, percent))),\r\n g: Math.max(0, Math.min(255, rgb.g + getLightnessStep(rgb.g, percent))),\r\n b: Math.max(0, Math.min(255, rgb.b + getLightnessStep(rgb.b, percent))),\r\n a: rgb.a\r\n };\r\n }\r\n else {\r\n // TODO is this correct ?\r\n return rgb;\r\n }\r\n}\r\n;\r\n/**\r\n * Gets lightness step.\r\n *\r\n * @param value Value\r\n * @param percent Percent\r\n * @return Step\r\n */\r\nexport function getLightnessStep(value, percent) {\r\n let base = percent > 0 ? 255 - value : value;\r\n return Math.round(base * percent);\r\n}\r\n/**\r\n * Returns a color that is `percent` brighter than the source `color`.\r\n *\r\n * @param color Source color\r\n * @param percent Brightness percent\r\n * @return New color\r\n */\r\nexport function brighten(rgb, percent) {\r\n if (rgb) {\r\n let base = Math.min(Math.max(rgb.r, rgb.g, rgb.b), 230);\r\n //let base = Math.max(rgb.r, rgb.g, rgb.b);\r\n let step = getLightnessStep(base, percent);\r\n return {\r\n r: Math.max(0, Math.min(255, Math.round(rgb.r + step))),\r\n g: Math.max(0, Math.min(255, Math.round(rgb.g + step))),\r\n b: Math.max(0, Math.min(255, Math.round(rgb.b + step))),\r\n a: rgb.a\r\n };\r\n }\r\n else {\r\n // TODO is this correct ?\r\n return rgb;\r\n }\r\n}\r\n;\r\n/**\r\n * Returns brightness step.\r\n *\r\n * @ignore Exclude from docs\r\n * @param value Value\r\n * @param percent Percent\r\n * @return Step\r\n */\r\nexport function getBrightnessStep(_value, percent) {\r\n let base = 255; //percent > 0 ? 255 - value : value;\r\n return Math.round(base * percent);\r\n}\r\n/**\r\n * Returns `true` if color is \"light\". Useful indetermining which contrasting\r\n * color to use for elements over this color. E.g.: you would want to use\r\n * black text over light background, and vice versa.\r\n *\r\n * @param color Source color\r\n * @return Light?\r\n */\r\nexport function isLight(color) {\r\n return ((color.r * 299) + (color.g * 587) + (color.b * 114)) / 1000 >= 128;\r\n}\r\n/**\r\n * Returns a new [[iRGB]] object based on `rgb` parameter with specific\r\n * saturation applied.\r\n *\r\n * `saturation` can be in the range of 0 (fully desaturated) to 1 (fully\r\n * saturated).\r\n *\r\n * @param color Base color\r\n * @param saturation Saturation (0-1)\r\n * @return New color\r\n */\r\nexport function saturate(rgb, saturation) {\r\n if (rgb === undefined || saturation == 1) {\r\n return rgb;\r\n }\r\n let hsl = rgbToHsl(rgb);\r\n hsl.s = saturation;\r\n return hslToRgb(hsl);\r\n}\r\n/**\r\n * Returns a color which contrasts more with the source `color`.\r\n *\r\n * @param color Base color\r\n * @param lightAlternative Light option\r\n * @param darkAlternative Dark option\r\n * @return New color\r\n */\r\nexport function alternativeColor(color, lightAlternative = { r: 255, g: 255, b: 255 }, darkAlternative = { r: 255, g: 255, b: 255 }) {\r\n let light = lightAlternative;\r\n let dark = darkAlternative;\r\n if (isLight(darkAlternative)) {\r\n light = darkAlternative;\r\n dark = lightAlternative;\r\n }\r\n return isLight(color) ? dark : light;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function mergeTags(tags1, tags2) {\r\n if (!tags1) {\r\n tags1 = [];\r\n }\r\n return [...tags1, ...tags2].filter((value, index, self) => {\r\n return self.indexOf(value) === index;\r\n });\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function sameBounds(a, b) {\r\n if (!b) {\r\n return false;\r\n }\r\n if (a.left != b.left) {\r\n return false;\r\n }\r\n if (a.right != b.right) {\r\n return false;\r\n }\r\n if (a.top != b.top) {\r\n return false;\r\n }\r\n if (a.bottom != b.bottom) {\r\n return false;\r\n }\r\n return true;\r\n}\r\n//# sourceMappingURL=Utils.js.map","import { range } from \"./Animation\";\r\nimport * as $utils from \"./Utils\";\r\nimport * as $type from \"./Type\";\r\n/**\r\n * @ignore\r\n */\r\nfunction string2hex(string) {\r\n //string = cssColorNames[string.toLowerCase()] || string;\r\n if (string[0] === \"#\") {\r\n string = string.substr(1);\r\n }\r\n if (string.length == 3) {\r\n string = string[0].repeat(2) + string[1].repeat(2) + string[2].repeat(2);\r\n }\r\n return parseInt(string, 16);\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function rgba2hex(color) {\r\n color = color.replace(/[ ]/g, \"\");\r\n // Init\r\n let matches = color.match(/^rgb\\(([0-9]*),([0-9]*),([0-9]*)\\)/i);\r\n // Try rgb() format\r\n if (matches) {\r\n matches.push(\"1\");\r\n }\r\n else {\r\n matches = color.match(/^rgba\\(([0-9]*),([0-9]*),([0-9]*),([.0-9]*)\\)/i);\r\n if (!matches) {\r\n return 0x000000;\r\n }\r\n }\r\n let hex = \"\";\r\n for (let i = 1; i <= 3; i++) {\r\n let val = parseInt(matches[i]).toString(16);\r\n if (val.length == 1) {\r\n val = \"0\" + val;\r\n }\r\n hex += val;\r\n }\r\n return string2hex(hex);\r\n}\r\n/**\r\n * Returns a new [[Color]] object base on input.\r\n *\r\n * Accepts parameters in CSS hex or rgb/rtba strings, or hex numbers.\r\n *\r\n * * `\"#f00\"`\r\n * * `\"#ff0000\"`\r\n * * `\"rgb(255, 0, 0)\"`\r\n * * `\"rgba(255, 0, 0, 1)\"`\r\n * * `0xff0000`\r\n *\r\n * @param input Input color\r\n * @return Color\r\n */\r\nexport function color(input) {\r\n return Color.fromAny(input);\r\n}\r\n/**\r\n * Wherever color needs to be specified in amCharts 5, `Color` object needs to\r\n * be used.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/} for more info\r\n * @important\r\n */\r\nexport class Color {\r\n constructor(hex) {\r\n Object.defineProperty(this, \"_hex\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._hex = hex | 0;\r\n }\r\n /**\r\n * Color numeric value.\r\n */\r\n get hex() {\r\n return this._hex;\r\n }\r\n /**\r\n * Value of color's R channel.\r\n * @return R value\r\n */\r\n get r() {\r\n return this._hex >>> 16;\r\n }\r\n /**\r\n * Value of color's G channel.\r\n * @return G value\r\n */\r\n get g() {\r\n return (this._hex >> 8) & 0xFF;\r\n }\r\n /**\r\n * Value of color's B channel.\r\n * @return B value\r\n */\r\n get b() {\r\n return this._hex & 0xFF;\r\n }\r\n /**\r\n * Returns color CSS representation in form of `rgba(r, g, b, a)` string.\r\n *\r\n * @param alpha Opacity\r\n * @return CSS string\r\n */\r\n toCSS(alpha = 1) {\r\n return \"rgba(\" + this.r + \", \" + this.g + \", \" + this.b + \", \" + alpha + \")\";\r\n }\r\n /**\r\n * Returns color CSS representation in form of `#rgb` string.\r\n *\r\n * @return CSS string\r\n */\r\n toCSSHex() {\r\n return \"#\" + $utils.padString(this.r.toString(16), 2) + $utils.padString(this.g.toString(16), 2) + $utils.padString(this.b.toString(16), 2);\r\n }\r\n /**\r\n * Returns color's HSL info.\r\n * @param alpha Opacity\r\n * @return HSL info\r\n */\r\n toHSL(alpha = 1) {\r\n return $utils.rgbToHsl({\r\n r: this.r,\r\n g: this.g,\r\n b: this.b,\r\n a: alpha\r\n });\r\n }\r\n /**\r\n * Converts HSL values into a new [[Color]] object.\r\n *\r\n * @param h H value\r\n * @param s S value\r\n * @param l L value\r\n * @return Color object\r\n */\r\n static fromHSL(h, s, l) {\r\n const rgb = $utils.hslToRgb({\r\n h: h,\r\n s: s,\r\n l: l\r\n });\r\n return this.fromRGB(rgb.r, rgb.g, rgb.b);\r\n }\r\n toString() {\r\n return this.toCSSHex();\r\n }\r\n /**\r\n * Converts hex number into a new [[Color]] object.\r\n *\r\n * ```TypeScript\r\n * Color.fromHex(0xff0000) // red\r\n * ```\r\n * ```JavaScript\r\n * Color.fromHex(0xff0000) // red\r\n * ```\r\n *\r\n * @param hex Hex color\r\n * @return Color\r\n */\r\n static fromHex(hex) {\r\n return new Color(hex);\r\n }\r\n /**\r\n * Converts RGB values to a new [[Color]] object.\r\n *\r\n * @param r R value\r\n * @param g G value\r\n * @param b B value\r\n * @return Color\r\n */\r\n static fromRGB(r, g, b) {\r\n return new Color((b | 0) + (g << 8) + (r << 16));\r\n }\r\n /**\r\n * Converts RGB string to a new [[Color]] object.\r\n *\r\n * ```TypeScript\r\n * Color.fromString(\"#ff0000\") // red\r\n * ```\r\n * ```JavaScript\r\n * Color.fromString(\"#ff0000\") // red\r\n * ```\r\n *\r\n * @param s RGB string\r\n * @return Color\r\n */\r\n static fromString(s) {\r\n return new Color(string2hex(s));\r\n }\r\n /**\r\n * Converts CSS rgba() syntax to a new [[Color]] object.\r\n *\r\n * ```TypeScript\r\n * Color.fromCSS(\"rgba(255, 0, 0, 1)\") // red\r\n * ```\r\n * ```JavaScript\r\n * Color.fromCSS(\"rgba(255, 0, 0, 1)\") // red\r\n * ```\r\n *\r\n * @param {string} s [description]\r\n * @return {Color} [description]\r\n */\r\n static fromCSS(s) {\r\n return new Color(rgba2hex(s));\r\n }\r\n /**\r\n * Convert to color from virtually anything.\r\n *\r\n * Will throw an exception if unable to resolve the color.\r\n *\r\n * @param s Source\r\n * @return Color\r\n */\r\n static fromAny(s) {\r\n if ($type.isString(s)) {\r\n if (s[0] == \"#\") {\r\n return Color.fromString(s);\r\n }\r\n else if (s.substr(0, 3) == \"rgb\") {\r\n return Color.fromCSS(s);\r\n }\r\n }\r\n else if ($type.isNumber(s)) {\r\n return Color.fromHex(s);\r\n }\r\n else if (s instanceof Color) {\r\n return Color.fromHex(s.hex);\r\n }\r\n throw new Error(\"Unknown color syntax: \" + s);\r\n }\r\n /**\r\n * Returns a new [[Color]] object based on either `lightAlternative` or\r\n * `darkAlternative` depending on which one is more contrasting with\r\n * the `color`.\r\n *\r\n * @param color Reference color\r\n * @param lightAlternative Light color\r\n * @param darkAlternative Dark color\r\n * @return Alternative color\r\n */\r\n static alternative(color, lightAlternative, darkAlternative) {\r\n const rgb = $utils.alternativeColor({ r: color.r, g: color.g, b: color.b }, lightAlternative ? { r: lightAlternative.r, g: lightAlternative.g, b: lightAlternative.b } : undefined, darkAlternative ? { r: darkAlternative.r, g: darkAlternative.g, b: darkAlternative.b } : undefined);\r\n return this.fromRGB(rgb.r, rgb.g, rgb.b);\r\n }\r\n /**\r\n * Returns an intermediate Color between two reference colors depending on\r\n * the progress (`diff`) between the two.\r\n *\r\n * @param diff Progress\r\n * @param from Source color\r\n * @param to Target color\r\n * @param mode Interpolation mode\r\n * @return Color\r\n */\r\n static interpolate(diff, from, to, mode = \"rgb\") {\r\n if (mode == \"hsl\") {\r\n const fromHSL = from.toHSL();\r\n const toHSL = to.toHSL();\r\n return Color.fromHSL(range(diff, fromHSL.h, toHSL.h), range(diff, fromHSL.s, toHSL.s), range(diff, fromHSL.l, toHSL.l));\r\n }\r\n else {\r\n return Color.fromRGB(range(diff, from.r, to.r), range(diff, from.g, to.g), range(diff, from.b, to.b));\r\n }\r\n }\r\n /**\r\n * Returns a new [[Color]] lightened by `percent` value.\r\n *\r\n * Use negative value to darken the color.\r\n *\r\n * @param color Source color\r\n * @param percent Percent\r\n * @return New color\r\n */\r\n static lighten(color, percent) {\r\n const rgb = $utils.lighten({ r: color.r, g: color.g, b: color.b }, percent);\r\n return Color.fromRGB(rgb.r, rgb.g, rgb.b);\r\n }\r\n /**\r\n * Returns a new [[Color]] brightened by `percent` value.\r\n *\r\n * Use negative value to dim the color.\r\n *\r\n * @param color Source color\r\n * @param percent Percent\r\n * @return New color\r\n */\r\n static brighten(color, percent) {\r\n const rgb = $utils.brighten({ r: color.r, g: color.g, b: color.b }, percent);\r\n return Color.fromRGB(rgb.r, rgb.g, rgb.b);\r\n }\r\n /**\r\n * Returns a new [[Color]] saturated by `percent` value.\r\n *\r\n * Value range is between `0` (fully desaturated), to `1` (full color).\r\n *\r\n * @param color Source color\r\n * @param percent Percent\r\n * @return New color\r\n */\r\n static saturate(color, percent) {\r\n const rgb = $utils.saturate({ r: color.r, g: color.g, b: color.b }, percent);\r\n return Color.fromRGB(rgb.r, rgb.g, rgb.b);\r\n }\r\n}\r\n//# sourceMappingURL=Color.js.map","/**\r\n * Event Dispatcher module is used for registering listeners and dispatching\r\n * events across amCharts system.\r\n */\r\n/**\r\n * ============================================================================\r\n * IMPORTS\r\n * ============================================================================\r\n * @hidden\r\n */\r\nimport { Disposer, MultiDisposer } from \"./Disposer\";\r\nimport * as $array from \"./Array\";\r\nimport * as $type from \"./Type\";\r\n/**\r\n * Universal Event Dispatcher.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/events/} for more info\r\n */\r\nexport class EventDispatcher {\r\n /**\r\n * Constructor\r\n */\r\n constructor() {\r\n Object.defineProperty(this, \"_listeners\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_killed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_disabled\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_iterating\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_enabled\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._listeners = [];\r\n this._killed = [];\r\n this._disabled = {};\r\n this._iterating = 0;\r\n this._enabled = true;\r\n this._disposed = false;\r\n }\r\n /**\r\n * Returns if this object has been already disposed.\r\n *\r\n * @return Disposed?\r\n */\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n /**\r\n * Dispose (destroy) this object.\r\n */\r\n dispose() {\r\n if (!this._disposed) {\r\n this._disposed = true;\r\n const a = this._listeners;\r\n this._iterating = 1;\r\n this._listeners = null;\r\n this._disabled = null;\r\n try {\r\n $array.each(a, (x) => {\r\n x.disposer.dispose();\r\n });\r\n }\r\n finally {\r\n this._killed = null;\r\n this._iterating = null;\r\n }\r\n }\r\n }\r\n /**\r\n * Checks if this particular event dispatcher has any listeners set.\r\n *\r\n * @return Has listeners?\r\n */\r\n hasListeners() {\r\n return this._listeners.length !== 0;\r\n }\r\n /**\r\n * Checks if this particular event dispatcher has any particular listeners set.\r\n *\r\n * @return Has particular event listeners?\r\n */\r\n hasListenersByType(type) {\r\n return $array.any(this._listeners, (x) => (x.type === null || x.type === type) && !x.killed);\r\n }\r\n /**\r\n * Enable dispatching of events if they were previously disabled by\r\n * `disable()`.\r\n */\r\n enable() {\r\n this._enabled = true;\r\n }\r\n /**\r\n * Disable dispatching of events until re-enabled by `enable()`.\r\n */\r\n disable() {\r\n this._enabled = false;\r\n }\r\n /**\r\n * Enable dispatching particular event, if it was disabled before by\r\n * `disableType()`.\r\n *\r\n * @param type Event type\r\n */\r\n enableType(type) {\r\n delete this._disabled[type];\r\n }\r\n /**\r\n * Disable dispatching of events for a certain event type.\r\n *\r\n * Optionally, can set how many dispatches to skip before automatically\r\n * re-enabling the dispatching.\r\n *\r\n * @param type Event type\r\n * @param amount Number of event dispatches to skip\r\n */\r\n disableType(type, amount = Infinity) {\r\n this._disabled[type] = amount;\r\n }\r\n /**\r\n * Removes listener from dispatcher.\r\n *\r\n * Will throw an exception if such listener does not exists.\r\n *\r\n * @param listener Listener to remove\r\n */\r\n _removeListener(listener) {\r\n if (this._iterating === 0) {\r\n const index = this._listeners.indexOf(listener);\r\n if (index === -1) {\r\n throw new Error(\"Invalid state: could not remove listener\");\r\n }\r\n this._listeners.splice(index, 1);\r\n }\r\n else {\r\n this._killed.push(listener);\r\n }\r\n }\r\n /**\r\n * Removes existing listener by certain parameters.\r\n *\r\n * @param once Listener's once setting\r\n * @param type Listener's type\r\n * @param callback Callback function\r\n * @param context Callback context\r\n */\r\n _removeExistingListener(once, type, callback, context) {\r\n if (this._disposed) {\r\n throw new Error(\"EventDispatcher is disposed\");\r\n }\r\n this._eachListener((info) => {\r\n if (info.once === once && // TODO is this correct ?\r\n info.type === type &&\r\n (callback === undefined || info.callback === callback) &&\r\n info.context === context) {\r\n info.disposer.dispose();\r\n }\r\n });\r\n }\r\n /**\r\n * Checks if dispatching for particular event type is enabled.\r\n *\r\n * @param type Event type\r\n * @return Enabled?\r\n */\r\n isEnabled(type) {\r\n if (this._disposed) {\r\n throw new Error(\"EventDispatcher is disposed\");\r\n }\r\n // TODO is this check correct ?\r\n return this._enabled && this._listeners.length > 0 && this.hasListenersByType(type) && this._disabled[type] === undefined;\r\n }\r\n /**\r\n * Removes all listeners of a particular event type\r\n *\r\n * @param type Listener's type\r\n */\r\n removeType(type) {\r\n if (this._disposed) {\r\n throw new Error(\"EventDispatcher is disposed\");\r\n }\r\n this._eachListener((info) => {\r\n if (info.type === type) {\r\n info.disposer.dispose();\r\n }\r\n });\r\n }\r\n /**\r\n * Checks if there's already a listener with specific parameters.\r\n *\r\n * @param type Listener's type\r\n * @param callback Callback function\r\n * @param context Callback context\r\n * @return Has listener?\r\n */\r\n has(type, callback, context) {\r\n const index = $array.findIndex(this._listeners, (info) => {\r\n return info.once !== true && // Ignoring \"once\" listeners\r\n info.type === type &&\r\n (callback === undefined || info.callback === callback) &&\r\n info.context === context;\r\n });\r\n return index !== -1;\r\n }\r\n /**\r\n * Checks whether event of the particular type should be dispatched.\r\n *\r\n * @param type Event type\r\n * @return Dispatch?\r\n */\r\n _shouldDispatch(type) {\r\n if (this._disposed) {\r\n throw new Error(\"EventDispatcher is disposed\");\r\n }\r\n const count = this._disabled[type];\r\n if (!$type.isNumber(count)) {\r\n return this._enabled;\r\n }\r\n else {\r\n if (count <= 1) {\r\n delete this._disabled[type];\r\n }\r\n else {\r\n --this._disabled[type];\r\n }\r\n return false;\r\n }\r\n }\r\n /**\r\n * [_eachListener description]\r\n *\r\n * All of this extra code is needed when a listener is removed while iterating\r\n *\r\n * @todo Description\r\n * @param fn [description]\r\n */\r\n _eachListener(fn) {\r\n ++this._iterating;\r\n try {\r\n $array.each(this._listeners, fn);\r\n }\r\n finally {\r\n --this._iterating;\r\n // TODO should this be inside or outside the finally ?\r\n if (this._iterating === 0 && this._killed.length !== 0) {\r\n // Remove killed listeners\r\n $array.each(this._killed, (killed) => {\r\n this._removeListener(killed);\r\n });\r\n this._killed.length = 0;\r\n }\r\n }\r\n }\r\n /**\r\n * Dispatches an event immediately without waiting for next cycle.\r\n *\r\n * @param type Event type\r\n * @param event Event object\r\n * @todo automatically add in type and target properties if they are missing\r\n */\r\n dispatch(type, event) {\r\n if (this._shouldDispatch(type)) {\r\n // TODO check if it's faster to use an object of listeners rather than a single big array\r\n // TODO if the function throws, maybe it should keep going ?\r\n this._eachListener((listener) => {\r\n if (!listener.killed && (listener.type === null || listener.type === type)) {\r\n listener.dispatch(type, event);\r\n }\r\n });\r\n }\r\n }\r\n /**\r\n * Shelves the event to be dispatched within next update cycle.\r\n *\r\n * @param type Event type\r\n * @param event Event object\r\n * @todo automatically add in type and target properties if they are missing\r\n */\r\n /*public dispatchLater(type: Key, event: T[Key]): void {\r\n if (this._shouldDispatch(type)) {\r\n this._eachListener((listener) => {\r\n // TODO check if it's faster to use an object of listeners rather than a single big array\r\n if (!listener.killed && (listener.type === null || listener.type === type)) {\r\n // TODO if the function throws, maybe it should keep going ?\r\n // TODO dispatch during the update cycle, rather than using whenIdle\r\n $async.whenIdle(() => {\r\n if (!listener.killed) {\r\n listener.dispatch(type, event);\r\n }\r\n });\r\n }\r\n });\r\n }\r\n }*/\r\n /**\r\n * Creates, catalogs and returns an [[EventListener]].\r\n *\r\n * Event listener can be disposed.\r\n *\r\n * @param once Listener's once setting\r\n * @param type Listener's type\r\n * @param callback Callback function\r\n * @param context Callback context\r\n * @param shouldClone Whether the listener should be copied when the EventDispatcher is copied\r\n * @param dispatch\r\n * @returns An event listener\r\n */\r\n _on(once, type, callback, context, shouldClone, dispatch) {\r\n if (this._disposed) {\r\n throw new Error(\"EventDispatcher is disposed\");\r\n }\r\n this._removeExistingListener(once, type, callback, context);\r\n const info = {\r\n type: type,\r\n callback: callback,\r\n context: context,\r\n shouldClone: shouldClone,\r\n dispatch: dispatch,\r\n killed: false,\r\n once: once,\r\n disposer: new Disposer(() => {\r\n info.killed = true;\r\n this._removeListener(info);\r\n })\r\n };\r\n this._listeners.push(info);\r\n return info;\r\n }\r\n /**\r\n * Creates an event listener to be invoked on **any** event.\r\n *\r\n * @param callback Callback function\r\n * @param context Callback context\r\n * @param shouldClone Whether the listener should be copied when the EventDispatcher is copied\r\n * @returns A disposable event listener\r\n */\r\n onAll(callback, context, shouldClone = true) {\r\n return this._on(false, null, callback, context, shouldClone, (_type, event) => callback.call(context, event)).disposer;\r\n }\r\n /**\r\n * Creates an event listener to be invoked on a specific event type.\r\n *\r\n * ```TypeScript\r\n * button.events.once(\"click\", (ev) => {\r\n * console.log(\"Button clicked\");\r\n * }, this);\r\n * ```\r\n * ```JavaScript\r\n * button.events.once(\"click\", (ev) => {\r\n * console.log(\"Button clicked\");\r\n * }, this);\r\n * ```\r\n *\r\n * The above will invoke our custom event handler whenever series we put\r\n * event on is hidden.\r\n *\r\n * @param type Listener's type\r\n * @param callback Callback function\r\n * @param context Callback context\r\n * @param shouldClone Whether the listener should be copied when the EventDispatcher is copied\r\n * @returns A disposable event listener\r\n */\r\n on(type, callback, context, shouldClone = true) {\r\n return this._on(false, type, callback, context, shouldClone, (_type, event) => callback.call(context, event)).disposer;\r\n }\r\n /**\r\n * Creates an event listener to be invoked on a specific event type once.\r\n *\r\n * Once the event listener is invoked, it is automatically disposed.\r\n *\r\n * ```TypeScript\r\n * button.events.once(\"click\", (ev) => {\r\n * console.log(\"Button clicked\");\r\n * }, this);\r\n * ```\r\n * ```JavaScript\r\n * button.events.once(\"click\", (ev) => {\r\n * console.log(\"Button clicked\");\r\n * }, this);\r\n * ```\r\n *\r\n * The above will invoke our custom event handler the first time series we\r\n * put event on is hidden.\r\n *\r\n * @param type Listener's type\r\n * @param callback Callback function\r\n * @param context Callback context\r\n * @param shouldClone Whether the listener should be copied when the EventDispatcher is copied\r\n * @returns A disposable event listener\r\n */\r\n once(type, callback, context, shouldClone = true) {\r\n const x = this._on(true, type, callback, context, shouldClone, (_type, event) => {\r\n x.disposer.dispose();\r\n callback.call(context, event);\r\n });\r\n // TODO maybe this should return a different Disposer ?\r\n return x.disposer;\r\n }\r\n /**\r\n * Removes the event listener with specific parameters.\r\n *\r\n * @param type Listener's type\r\n * @param callback Callback function\r\n * @param context Callback context\r\n */\r\n off(type, callback, context) {\r\n this._removeExistingListener(false, type, callback, context);\r\n }\r\n /**\r\n * Copies all dispatcher parameters, including listeners, from another event\r\n * dispatcher.\r\n *\r\n * @param source Source event dispatcher\r\n * @ignore\r\n */\r\n copyFrom(source) {\r\n if (this._disposed) {\r\n throw new Error(\"EventDispatcher is disposed\");\r\n }\r\n if (source === this) {\r\n throw new Error(\"Cannot copyFrom the same TargetedEventDispatcher\");\r\n }\r\n const disposers = [];\r\n $array.each(source._listeners, (x) => {\r\n // TODO is this correct ?\r\n if (!x.killed && x.shouldClone) {\r\n if (x.type === null) {\r\n disposers.push(this.onAll(x.callback, x.context));\r\n }\r\n else if (x.once) {\r\n disposers.push(this.once(x.type, x.callback, x.context));\r\n }\r\n else {\r\n disposers.push(this.on(x.type, x.callback, x.context));\r\n }\r\n }\r\n });\r\n return new MultiDisposer(disposers);\r\n }\r\n}\r\n/**\r\n * A version of the [[EventDispatcher]] that dispatches events for a specific\r\n * target object.\r\n *\r\n * @ignore\r\n */\r\nexport class TargetedEventDispatcher extends EventDispatcher {\r\n /**\r\n * Constructor\r\n *\r\n * @param target Event dispatcher target\r\n */\r\n constructor(target) {\r\n super();\r\n /**\r\n * A target object which is originating events using this dispatcher.\r\n */\r\n Object.defineProperty(this, \"target\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this.target = target;\r\n }\r\n /**\r\n * Copies all dispatcher parameters, including listeners, from another event\r\n * dispatcher.\r\n *\r\n * @param source Source event dispatcher\r\n * @ignore\r\n */\r\n copyFrom(source) {\r\n if (this._disposed) {\r\n throw new Error(\"EventDispatcher is disposed\");\r\n }\r\n if (source === this) {\r\n throw new Error(\"Cannot copyFrom the same TargetedEventDispatcher\");\r\n }\r\n const disposers = [];\r\n $array.each(source._listeners, (x) => {\r\n // TODO very hacky\r\n if (x.context === source.target) {\r\n return;\r\n }\r\n // TODO is this correct ?\r\n if (!x.killed && x.shouldClone) {\r\n if (x.type === null) {\r\n disposers.push(this.onAll(x.callback, x.context));\r\n }\r\n else if (x.once) {\r\n disposers.push(this.once(x.type, x.callback, x.context));\r\n }\r\n else {\r\n disposers.push(this.on(x.type, x.callback, x.context));\r\n }\r\n }\r\n });\r\n return new MultiDisposer(disposers);\r\n }\r\n}\r\n//# sourceMappingURL=EventDispatcher.js.map","import { __awaiter } from \"tslib\";\r\nimport { Percent } from \"./Percent\";\r\nimport { Color } from \"./Color\";\r\nimport { EventDispatcher } from \"./EventDispatcher\";\r\nimport * as $object from \"./Object\";\r\n/**\r\n * @ignore\r\n */\r\nexport function waitForAnimations(animations) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n if (animations !== undefined) {\r\n const promises = [];\r\n $object.each(animations, (_, animation) => {\r\n promises.push(animation.waitForStop());\r\n });\r\n yield Promise.all(promises);\r\n }\r\n });\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function normalize(value, min, max) {\r\n if (min === max) {\r\n return 0;\r\n }\r\n else {\r\n return Math.min(Math.max((value - min) * (1 / (max - min)), 0), 1);\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function range(diff, from, to) {\r\n return from + (diff * (to - from));\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function defaultInterpolate(diff, from, to) {\r\n if (diff >= 1) {\r\n return to;\r\n }\r\n else {\r\n return from;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function percentInterpolate(diff, from, to) {\r\n return new Percent(range(diff, from.percent, to.percent));\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function colorInterpolate(diff, from, to) {\r\n return Color.interpolate(diff, from, to);\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function getInterpolate(from, to) {\r\n if (typeof from === \"number\" && typeof to === \"number\") {\r\n return range;\r\n }\r\n if (from instanceof Percent && to instanceof Percent) {\r\n return percentInterpolate;\r\n }\r\n if (from instanceof Color && to instanceof Color) {\r\n return colorInterpolate;\r\n }\r\n return defaultInterpolate;\r\n}\r\nexport var AnimationState;\r\n(function (AnimationState) {\r\n AnimationState[AnimationState[\"Stopped\"] = 0] = \"Stopped\";\r\n AnimationState[AnimationState[\"Playing\"] = 1] = \"Playing\";\r\n AnimationState[AnimationState[\"Paused\"] = 2] = \"Paused\";\r\n})(AnimationState || (AnimationState = {}));\r\n/**\r\n * @ignore\r\n */\r\nexport class AnimationTime {\r\n constructor(entity, duration) {\r\n Object.defineProperty(this, \"_entity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_duration\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_playingDuration\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: null\r\n });\r\n Object.defineProperty(this, \"_startingTime\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: null\r\n });\r\n Object.defineProperty(this, \"_current\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_from\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_to\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new EventDispatcher()\r\n });\r\n Object.defineProperty(this, \"easing\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._entity = entity;\r\n this._duration = duration;\r\n }\r\n _stopEvent() {\r\n const type = \"stopped\";\r\n if (this.events.isEnabled(type)) {\r\n this.events.dispatch(type, { type: type, target: this });\r\n }\r\n }\r\n _runAnimation(currentTime) {\r\n if (this._playingDuration !== null) {\r\n if (this._startingTime === null) {\r\n this._startingTime = currentTime;\r\n return AnimationState.Playing;\r\n }\r\n else {\r\n const diff = (currentTime - this._startingTime) / this._playingDuration;\r\n if (diff >= 1) {\r\n this._playingDuration = null;\r\n this._startingTime = null;\r\n this._from = this._to;\r\n this._current = this._to;\r\n this._entity.markDirty();\r\n this._stopEvent();\r\n const type = \"ended\";\r\n if (this.events.isEnabled(type)) {\r\n this.events.dispatch(type, { type: type, target: this });\r\n }\r\n return AnimationState.Stopped;\r\n }\r\n else {\r\n this._current = range(diff, this._from, this._to);\r\n this._entity.markDirty();\r\n const type = \"progress\";\r\n if (this.events.isEnabled(type)) {\r\n this.events.dispatch(type, { type: type, target: this, progress: diff });\r\n }\r\n return AnimationState.Playing;\r\n }\r\n }\r\n }\r\n else {\r\n return AnimationState.Stopped;\r\n }\r\n }\r\n _play() {\r\n this._from = this._current;\r\n if (this._playingDuration === null) {\r\n this._entity._root._addAnimation(this);\r\n const type = \"started\";\r\n if (this.events.isEnabled(type)) {\r\n this.events.dispatch(type, { type: type, target: this });\r\n }\r\n }\r\n else {\r\n this._startingTime = null;\r\n }\r\n this._playingDuration = Math.abs(this._to - this._from) * this._duration;\r\n }\r\n get duration() {\r\n return this._duration;\r\n }\r\n set duration(value) {\r\n if (this._duration !== value) {\r\n this._duration = value;\r\n if (value === 0) {\r\n this.jumpTo(this._to);\r\n }\r\n else if (this._current !== this._to) {\r\n this._play();\r\n }\r\n }\r\n }\r\n get current() {\r\n if (this.easing) {\r\n return this.easing(this._current);\r\n }\r\n else {\r\n return this._current;\r\n }\r\n }\r\n stop() {\r\n this.jumpTo(this._current);\r\n }\r\n jumpTo(value) {\r\n if (this._current !== value) {\r\n this._entity.markDirty();\r\n }\r\n if (this._playingDuration !== null) {\r\n this._stopEvent();\r\n }\r\n this._playingDuration = null;\r\n this._startingTime = null;\r\n this._current = value;\r\n this._from = value;\r\n this._to = value;\r\n }\r\n tweenTo(value) {\r\n if (this._current === value || this._duration === 0) {\r\n this.jumpTo(value);\r\n }\r\n else {\r\n if (this._to !== value) {\r\n this._to = value;\r\n this._play();\r\n }\r\n }\r\n }\r\n}\r\n/*export class AnimationValue extends AnimationTime {\r\n public _min: number;\r\n public _max: number;\r\n\r\n constructor(entity: Entity, duration: number, min: number, max: number) {\r\n super(entity, duration);\r\n this._min = min;\r\n this._max = max;\r\n }\r\n\r\n public get min(): number {\r\n return this._min;\r\n }\r\n\r\n public set min(value: number) {\r\n if (this._min !== value) {\r\n this._min = value;\r\n this._entity.markDirty();\r\n }\r\n }\r\n\r\n public get max(): number {\r\n return this._max;\r\n }\r\n\r\n public set max(value: number) {\r\n if (this._max !== value) {\r\n this._max = value;\r\n this._entity.markDirty();\r\n }\r\n }\r\n\r\n public currentValue(): number {\r\n return range(super.currentTime(), this._min, this._max);\r\n }\r\n\r\n public jumpToValue(value: number) {\r\n super.jumpToTime(normalize(value, this._min, this._max));\r\n }\r\n\r\n public tweenToValue(value: number) {\r\n super.tweenToTime(normalize(value, this._min, this._max));\r\n }\r\n}\r\n*/\r\n//# sourceMappingURL=Animation.js.map","import { EventDispatcher } from \"./EventDispatcher\";\r\nimport * as $array from \"./Array\";\r\n/**\r\n * Checks if specific index fits into length.\r\n *\r\n * @param index Index\r\n * @param len Length\r\n * @ignore\r\n */\r\nfunction checkBounds(index, len) {\r\n if (!(index >= 0 && index < len)) {\r\n throw new Error(\"Index out of bounds: \" + index);\r\n }\r\n}\r\n/**\r\n * A List class is used to hold a number of indexed items of the same type.\r\n */\r\nexport class List {\r\n /**\r\n * Constructor\r\n *\r\n * @param initial Inital list of values to add to list\r\n */\r\n constructor(initial = []) {\r\n /**\r\n * List values.\r\n */\r\n Object.defineProperty(this, \"_values\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new EventDispatcher()\r\n });\r\n this._values = initial;\r\n }\r\n /**\r\n * An array of values in the list.\r\n *\r\n * Do not use this property to add values. Rather use dedicated methods, like\r\n * `push()`, `removeIndex()`, etc.\r\n *\r\n * @readonly\r\n * @return List values\r\n */\r\n get values() {\r\n return this._values;\r\n }\r\n /**\r\n * Checks if list contains specific item reference.\r\n *\r\n * @param item Item to search for\r\n * @return `true` if found, `false` if not found\r\n */\r\n contains(value) {\r\n return this._values.indexOf(value) !== -1;\r\n }\r\n /**\r\n * Removes specific item from the list.\r\n *\r\n * @param item An item to remove\r\n */\r\n removeValue(value) {\r\n let i = 0;\r\n let length = this._values.length;\r\n while (i < length) {\r\n // TODO handle NaN\r\n if (this._values[i] === value) {\r\n this.removeIndex(i);\r\n --length;\r\n }\r\n else {\r\n ++i;\r\n }\r\n }\r\n }\r\n /**\r\n * Searches the list for specific item and returns its index.\r\n *\r\n * @param item An item to search for\r\n * @return Index or -1 if not found\r\n */\r\n indexOf(value) {\r\n return $array.indexOf(this._values, value);\r\n }\r\n /**\r\n * Number of items in list.\r\n *\r\n * @readonly\r\n * @return Number of items\r\n */\r\n get length() {\r\n return this._values.length;\r\n }\r\n /**\r\n * Checks if there's a value at specific index.\r\n *\r\n * @param index Index\r\n * @return Value exists?\r\n */\r\n hasIndex(index) {\r\n return index >= 0 && index < this._values.length;\r\n }\r\n /**\r\n * Returns an item at specified index.\r\n *\r\n * @param index Index\r\n * @return List item\r\n */\r\n getIndex(index) {\r\n return this._values[index];\r\n }\r\n _onPush(newValue) {\r\n if (this.events.isEnabled(\"push\")) {\r\n this.events.dispatch(\"push\", {\r\n type: \"push\",\r\n target: this,\r\n newValue\r\n });\r\n }\r\n }\r\n _onInsertIndex(index, newValue) {\r\n if (this.events.isEnabled(\"insertIndex\")) {\r\n this.events.dispatch(\"insertIndex\", {\r\n type: \"insertIndex\",\r\n target: this,\r\n index,\r\n newValue\r\n });\r\n }\r\n }\r\n _onSetIndex(index, oldValue, newValue) {\r\n if (this.events.isEnabled(\"setIndex\")) {\r\n this.events.dispatch(\"setIndex\", {\r\n type: \"setIndex\",\r\n target: this,\r\n index,\r\n oldValue,\r\n newValue\r\n });\r\n }\r\n }\r\n _onRemoveIndex(index, oldValue) {\r\n if (this.events.isEnabled(\"removeIndex\")) {\r\n this.events.dispatch(\"removeIndex\", {\r\n type: \"removeIndex\",\r\n target: this,\r\n index,\r\n oldValue\r\n });\r\n }\r\n }\r\n _onMoveIndex(oldIndex, newIndex, value) {\r\n if (this.events.isEnabled(\"moveIndex\")) {\r\n this.events.dispatch(\"moveIndex\", {\r\n type: \"moveIndex\",\r\n target: this,\r\n oldIndex,\r\n newIndex,\r\n value,\r\n });\r\n }\r\n }\r\n _onClear(oldValues) {\r\n if (this.events.isEnabled(\"clear\")) {\r\n this.events.dispatch(\"clear\", {\r\n type: \"clear\",\r\n target: this,\r\n oldValues\r\n });\r\n }\r\n }\r\n /**\r\n * Sets value at specific index.\r\n *\r\n * If there's already a value at the index, it is overwritten.\r\n *\r\n * @param index Index\r\n * @param value New value\r\n * @return New value\r\n */\r\n setIndex(index, value) {\r\n checkBounds(index, this._values.length);\r\n const oldValue = this._values[index];\r\n // Do nothing if the old value and the new value are the same\r\n if (oldValue !== value) {\r\n this._values[index] = value;\r\n this._onSetIndex(index, oldValue, value);\r\n }\r\n return oldValue;\r\n }\r\n /**\r\n * Adds an item to the list at a specific index, which pushes all the other\r\n * items further down the list.\r\n *\r\n * @param index Index\r\n * @param item An item to add\r\n */\r\n insertIndex(index, value) {\r\n checkBounds(index, this._values.length + 1);\r\n $array.insertIndex(this._values, index, value);\r\n this._onInsertIndex(index, value);\r\n return value;\r\n }\r\n /**\r\n * Swaps indexes of two items in the list.\r\n *\r\n * @param a Item 1\r\n * @param b Item 2\r\n */\r\n swap(a, b) {\r\n const len = this._values.length;\r\n checkBounds(a, len);\r\n checkBounds(b, len);\r\n if (a !== b) {\r\n const value_a = this._values[a];\r\n const value_b = this._values[b];\r\n this._values[a] = value_b;\r\n this._onSetIndex(a, value_a, value_b);\r\n this._values[b] = value_a;\r\n this._onSetIndex(b, value_b, value_a);\r\n }\r\n }\r\n /**\r\n * Removes a value at specific index.\r\n *\r\n * @param index Index of value to remove\r\n * @return Removed value\r\n */\r\n removeIndex(index) {\r\n checkBounds(index, this._values.length);\r\n const oldValue = this._values[index];\r\n $array.removeIndex(this._values, index);\r\n this._onRemoveIndex(index, oldValue);\r\n return oldValue;\r\n }\r\n /**\r\n * Moves an item to a specific index within the list.\r\n *\r\n * If the index is not specified it will move the item to the end of the\r\n * list.\r\n *\r\n * @param value Item to move\r\n * @param index Index to place item at\r\n */\r\n moveValue(value, toIndex) {\r\n // TODO don't do anything if the desired index is the same as the current index\r\n let index = this.indexOf(value);\r\n // TODO remove all old values rather than only the first ?\r\n if (index !== -1) {\r\n $array.removeIndex(this._values, index);\r\n if (toIndex == null) {\r\n const toIndex = this._values.length;\r\n this._values.push(value);\r\n this._onMoveIndex(index, toIndex, value);\r\n }\r\n else {\r\n $array.insertIndex(this._values, toIndex, value);\r\n this._onMoveIndex(index, toIndex, value);\r\n }\r\n }\r\n else if (toIndex == null) {\r\n this._values.push(value);\r\n this._onPush(value);\r\n }\r\n else {\r\n $array.insertIndex(this._values, toIndex, value);\r\n this._onInsertIndex(toIndex, value);\r\n }\r\n return value;\r\n }\r\n /**\r\n * Adds an item to the end of the list.\r\n *\r\n * @param item An item to add\r\n */\r\n push(value) {\r\n this._values.push(value);\r\n this._onPush(value);\r\n return value;\r\n }\r\n /**\r\n * Adds an item as a first item in the list.\r\n *\r\n * @param item An item to add\r\n */\r\n unshift(value) {\r\n this.insertIndex(0, value);\r\n return value;\r\n }\r\n /**\r\n * Adds multiple items to the list.\r\n *\r\n * @param items An Array of items to add\r\n */\r\n pushAll(values) {\r\n $array.each(values, (value) => {\r\n this.push(value);\r\n });\r\n }\r\n /**\r\n * Copies and adds items from abother list.\r\n *\r\n * @param source A list top copy items from\r\n */\r\n copyFrom(source) {\r\n this.pushAll(source._values);\r\n }\r\n /**\r\n * Returns the last item from the list, and removes it.\r\n *\r\n * @return Item\r\n */\r\n pop() {\r\n let index = this._values.length - 1;\r\n return index < 0 ? undefined : this.removeIndex(this._values.length - 1);\r\n }\r\n /**\r\n * Returns the first item from the list, and removes it.\r\n *\r\n * @return Item\r\n */\r\n shift() {\r\n return this._values.length ? this.removeIndex(0) : undefined;\r\n }\r\n /**\r\n * Sets multiple items to the list.\r\n *\r\n * All current items are removed.\r\n *\r\n * @param newArray New items\r\n */\r\n setAll(newArray) {\r\n const old = this._values;\r\n this._values = [];\r\n this._onClear(old);\r\n $array.each(newArray, (value) => {\r\n this._values.push(value);\r\n this._onPush(value);\r\n });\r\n }\r\n /**\r\n * Removes all items from the list.\r\n */\r\n clear() {\r\n this.setAll([]);\r\n }\r\n /**\r\n * Returns an ES6 iterator for the list.\r\n */\r\n *[Symbol.iterator]() {\r\n const length = this._values.length;\r\n for (let i = 0; i < length; ++i) {\r\n yield this._values[i];\r\n }\r\n }\r\n /**\r\n * Calls `f` for each element in the list.\r\n *\r\n * `f` should have at least one parameter defined which will get a current\r\n * item, with optional second argument - index.\r\n */\r\n each(f) {\r\n $array.each(this._values, f);\r\n }\r\n /**\r\n * Calls `f` for each element in the list, from right to left.\r\n *\r\n * `f` should have at least one parameter defined which will get a current\r\n * item, with optional second argument - index.\r\n */\r\n eachReverse(f) {\r\n $array.eachReverse(this._values, f);\r\n }\r\n}\r\n/**\r\n * A version of a [[List]] where the elements are disposed automatically when\r\n * removed from the list, unless `autoDispose` is set to `false`.\r\n */\r\nexport class ListAutoDispose extends List {\r\n constructor() {\r\n super(...arguments);\r\n /**\r\n * Automatically disposes elements that are removed from the list.\r\n *\r\n * @default true\r\n */\r\n Object.defineProperty(this, \"autoDispose\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n }\r\n _onSetIndex(index, oldValue, newValue) {\r\n if (this.autoDispose) {\r\n oldValue.dispose();\r\n }\r\n super._onSetIndex(index, oldValue, newValue);\r\n }\r\n _onRemoveIndex(index, oldValue) {\r\n if (this.autoDispose) {\r\n oldValue.dispose();\r\n }\r\n super._onRemoveIndex(index, oldValue);\r\n }\r\n _onClear(oldValues) {\r\n if (this.autoDispose) {\r\n $array.each(oldValues, (x) => {\r\n x.dispose();\r\n });\r\n }\r\n super._onClear(oldValues);\r\n }\r\n _dispose() {\r\n if (this.autoDispose) {\r\n $array.each(this._values, (x) => {\r\n x.dispose();\r\n });\r\n }\r\n }\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n dispose() {\r\n if (!this._disposed) {\r\n this._disposed = true;\r\n this._dispose();\r\n }\r\n }\r\n}\r\n/**\r\n * A version of a [[List]] that is able to create new elements as well as\r\n * apply additional settings to newly created items.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/list-templates/} for more info\r\n */\r\nexport class ListTemplate extends ListAutoDispose {\r\n constructor(template, make) {\r\n super();\r\n Object.defineProperty(this, \"template\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"make\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this.template = template;\r\n this.make = make;\r\n }\r\n _dispose() {\r\n super._dispose();\r\n if (this.autoDispose) {\r\n this.template.dispose();\r\n }\r\n }\r\n}\r\n//# sourceMappingURL=List.js.map","import { List } from \"./List\";\r\nimport * as $array from \"./Array\";\r\n/**\r\n * A version of [[List]] to hold children of the [[Container]].\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/containers/} for more info\r\n */\r\nexport class Children extends List {\r\n constructor(container) {\r\n super();\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_container\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._container = container;\r\n this._events = this.events.onAll((change) => {\r\n if (change.type === \"clear\") {\r\n $array.each(change.oldValues, (x) => {\r\n this._onRemoved(x);\r\n });\r\n }\r\n else if (change.type === \"push\") {\r\n this._onInserted(change.newValue);\r\n }\r\n else if (change.type === \"setIndex\") {\r\n this._onRemoved(change.oldValue);\r\n this._onInserted(change.newValue, change.index);\r\n }\r\n else if (change.type === \"insertIndex\") {\r\n this._onInserted(change.newValue, change.index);\r\n }\r\n else if (change.type === \"removeIndex\") {\r\n this._onRemoved(change.oldValue);\r\n }\r\n else if (change.type === \"moveIndex\") {\r\n this._onRemoved(change.value);\r\n this._onInserted(change.value, change.newIndex);\r\n }\r\n else {\r\n throw new Error(\"Unknown IListEvent type\");\r\n }\r\n });\r\n }\r\n _onInserted(child, index) {\r\n child._setParent(this._container, true);\r\n const childrenDisplay = this._container._childrenDisplay;\r\n if (index === undefined) {\r\n childrenDisplay.addChild(child._display);\r\n }\r\n else {\r\n childrenDisplay.addChildAt(child._display, index);\r\n }\r\n }\r\n _onRemoved(child) {\r\n this._container._childrenDisplay.removeChild(child._display);\r\n this._container.markDirtyBounds();\r\n this._container.markDirty();\r\n }\r\n /**\r\n * Returns `true` if obejct is disposed.\r\n */\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n /**\r\n * Permanently dispose this object.\r\n */\r\n dispose() {\r\n if (!this._disposed) {\r\n this._disposed = true;\r\n this._events.dispose();\r\n $array.each(this.values, (child) => {\r\n child.dispose();\r\n });\r\n }\r\n }\r\n}\r\n//# sourceMappingURL=Children.js.map","import { isNumber } from \"./Type\";\r\n/**\r\n * ============================================================================\r\n * CONSTANTS\r\n * ============================================================================\r\n * @hidden\r\n */\r\nexport const PI = Math.PI;\r\nexport const HALFPI = PI / 2;\r\nexport const RADIANS = PI / 180;\r\nexport const DEGREES = 180 / PI;\r\n/**\r\n * Rounds the numeric value to whole number or specific precision of set.\r\n *\r\n * @param value Value\r\n * @param precision Precision (number of decimal points)\r\n * @param floor In case value ends with 0.5 and precision is 0, we might need to floor the value instead of ceiling it.\r\n * @return Rounded value\r\n */\r\nexport function round(value, precision, floor) {\r\n if (!isNumber(precision) || precision <= 0) {\r\n let rounded = Math.round(value);\r\n if (floor) {\r\n if (rounded - value == 0.5) {\r\n rounded--;\r\n }\r\n }\r\n return rounded;\r\n }\r\n else {\r\n let d = Math.pow(10, precision);\r\n return Math.round(value * d) / d;\r\n }\r\n}\r\n/**\r\n * Ceils the numeric value to whole number or specific precision of set.\r\n *\r\n * @param value Value\r\n * @param precision Precision (number of decimal points)\r\n * @return Rounded value\r\n */\r\nexport function ceil(value, precision) {\r\n if (!isNumber(precision) || precision <= 0) {\r\n return Math.ceil(value);\r\n }\r\n else {\r\n let d = Math.pow(10, precision);\r\n return Math.ceil(value * d) / d;\r\n }\r\n}\r\n/**\r\n * [getCubicControlPointA description]\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n * @param p0 [description]\r\n * @param p1 [description]\r\n * @param p2 [description]\r\n * @param p3 [description]\r\n * @param tensionX [description]\r\n * @param tensionY [description]\r\n * @return [description]\r\n */\r\nexport function getCubicControlPointA(p0, p1, p2, tensionX, tensionY) {\r\n return { x: ((-p0.x + p1.x / tensionX + p2.x) * tensionX), y: ((-p0.y + p1.y / tensionY + p2.y) * tensionY) };\r\n}\r\n/**\r\n * [getCubicControlPointB description]\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n * @param p0 [description]\r\n * @param p1 [description]\r\n * @param p2 [description]\r\n * @param p3 [description]\r\n * @param tensionX [description]\r\n * @param tensionY [description]\r\n * @return [description]\r\n */\r\nexport function getCubicControlPointB(p1, p2, p3, tensionX, tensionY) {\r\n return { x: ((p1.x + p2.x / tensionX - p3.x) * tensionX), y: ((p1.y + p2.y / tensionY - p3.y) * tensionY) };\r\n}\r\nexport function fitToRange(value, min, max) {\r\n return Math.min(Math.max(value, min), max);\r\n}\r\n/**\r\n * Returns sine of an angle specified in degrees.\r\n *\r\n * @param value Value\r\n * @return Sine\r\n */\r\nexport function sin(angle) {\r\n return Math.sin(RADIANS * angle);\r\n}\r\n/**\r\n * Returns tan of an angle specified in degrees.\r\n *\r\n * @param value Value\r\n * @return Sine\r\n */\r\nexport function tan(angle) {\r\n return Math.tan(RADIANS * angle);\r\n}\r\n/**\r\n * Returns cosine of an angle specified in degrees.\r\n *\r\n * @param value Value\r\n * @return Cosine\r\n */\r\nexport function cos(angle) {\r\n return Math.cos(RADIANS * angle);\r\n}\r\n// 0 to 360\r\nexport function normalizeAngle(value) {\r\n value = value % 360;\r\n if (value < 0) {\r\n value += 360;\r\n }\r\n return value;\r\n}\r\n// TODO this doesn't work properly for skewing, and it's probably broken for rotation too\r\nexport function getArcBounds(cx, cy, startAngle, endAngle, radius) {\r\n let minX = Number.MAX_VALUE;\r\n let minY = Number.MAX_VALUE;\r\n let maxX = -Number.MAX_VALUE;\r\n let maxY = -Number.MAX_VALUE;\r\n let bpoints = [];\r\n bpoints.push(getArcPoint(radius, startAngle));\r\n bpoints.push(getArcPoint(radius, endAngle));\r\n let fromAngle = Math.min(Math.floor(startAngle / 90) * 90, Math.floor(endAngle / 90) * 90);\r\n let toAngle = Math.max(Math.ceil(startAngle / 90) * 90, Math.ceil(endAngle / 90) * 90);\r\n for (let angle = fromAngle; angle <= toAngle; angle += 90) {\r\n if (angle >= startAngle && angle <= endAngle) {\r\n bpoints.push(getArcPoint(radius, angle));\r\n }\r\n }\r\n for (let i = 0; i < bpoints.length; i++) {\r\n let pt = bpoints[i];\r\n if (pt.x < minX) {\r\n minX = pt.x;\r\n }\r\n if (pt.y < minY) {\r\n minY = pt.y;\r\n }\r\n if (pt.x > maxX) {\r\n maxX = pt.x;\r\n }\r\n if (pt.y > maxY) {\r\n maxY = pt.y;\r\n }\r\n }\r\n return ({ left: cx + minX, top: cy + minY, right: cx + maxX, bottom: cy + maxY });\r\n}\r\n/**\r\n * Returns point on arc\r\n *\r\n * @param center point\r\n * @param radius\r\n * @param arc\r\n * @return {boolean}\r\n */\r\nexport function getArcPoint(radius, arc) {\r\n return ({ x: radius * cos(arc), y: radius * sin(arc) });\r\n}\r\nexport function mergeBounds(bounds) {\r\n const len = bounds.length;\r\n if (len > 0) {\r\n let bound = bounds[0];\r\n let left = bound.left;\r\n let top = bound.top;\r\n let right = bound.right;\r\n let bottom = bound.bottom;\r\n if (len > 1) {\r\n for (let i = 1; i < len; i++) {\r\n bound = bounds[i];\r\n left = Math.min(bound.left, left);\r\n right = Math.max(bound.right, right);\r\n top = Math.min(bound.top, top);\r\n bottom = Math.max(bound.bottom, bottom);\r\n }\r\n }\r\n return { left, right, top, bottom };\r\n }\r\n return { left: 0, right: 0, top: 0, bottom: 0 };\r\n}\r\nexport function fitAngleToRange(value, startAngle, endAngle) {\r\n if (startAngle > endAngle) {\r\n let temp = startAngle;\r\n startAngle = endAngle;\r\n endAngle = temp;\r\n }\r\n value = normalizeAngle(value);\r\n let count = (startAngle - normalizeAngle(startAngle)) / 360;\r\n if (value < startAngle) {\r\n value += 360 * (count + 1);\r\n }\r\n let maxEnd = startAngle + (endAngle - startAngle) / 2 + 180;\r\n let maxStart = startAngle + (endAngle - startAngle) / 2 - 180;\r\n if (value > endAngle) {\r\n if (value - 360 > startAngle) {\r\n value -= 360;\r\n }\r\n else {\r\n if (value < maxEnd) {\r\n value = endAngle;\r\n }\r\n else {\r\n value = startAngle;\r\n }\r\n }\r\n }\r\n if (value < startAngle) {\r\n if (value > maxStart) {\r\n value = startAngle;\r\n }\r\n else {\r\n value = endAngle;\r\n }\r\n }\r\n return value;\r\n}\r\nexport function inBounds(point, bounds) {\r\n if (point.x >= bounds.left && point.y >= bounds.top && point.x <= bounds.right && point.y <= bounds.bottom) {\r\n return true;\r\n }\r\n return false;\r\n}\r\nexport function getAngle(point1, point2) {\r\n if (!point2) {\r\n point2 = { x: point1.x * 2, y: point1.y * 2 };\r\n }\r\n let diffX = point2.x - point1.x;\r\n let diffY = point2.y - point1.y;\r\n let angle = Math.atan2(diffY, diffX) * DEGREES;\r\n if (angle < 0) {\r\n angle += 360;\r\n }\r\n return normalizeAngle(angle);\r\n}\r\n/**\r\n * [getPointOnQuadraticCurve description]\r\n *\r\n * @ignore Exclude from docs\r\n * @todo Description\r\n * @param pointA [description]\r\n * @param pointB [description]\r\n * @param controlPoint [description]\r\n * @param position [description]\r\n * @return [description]\r\n */\r\nexport function getPointOnQuadraticCurve(pointA, pointB, controlPoint, position) {\r\n let x = (1 - position) * (1 - position) * pointA.x + 2 * (1 - position) * position * controlPoint.x + position * position * pointB.x;\r\n let y = (1 - position) * (1 - position) * pointA.y + 2 * (1 - position) * position * controlPoint.y + position * position * pointB.y;\r\n return { x: x, y: y };\r\n}\r\nexport function getPointOnLine(pointA, pointB, position) {\r\n return { x: pointA.x + (pointB.x - pointA.x) * position, y: pointA.y + (pointB.y - pointA.y) * position };\r\n}\r\n/**\r\n * Returns the closest value from the array of values to the reference value.\r\n *\r\n * @param values Array of values\r\n * @param value Reference value\r\n * @return Closes value from the array\r\n */\r\nexport function closest(values, referenceValue) {\r\n return values.reduce(function (prev, curr) {\r\n return (Math.abs(curr - referenceValue) < Math.abs(prev - referenceValue) ? curr : prev);\r\n });\r\n}\r\n/**\r\n * Returns true if bounds overlap\r\n * @param bounds1 IBounds\r\n * @param bounds2 IBounds\r\n * @returns boolean\r\n */\r\nexport function boundsOverlap(bounds1, bounds2) {\r\n const horizontalOverlap = bounds1.left < bounds2.right && bounds1.right > bounds2.left;\r\n const verticalOverlap = bounds1.top < bounds2.bottom && bounds1.bottom > bounds2.top;\r\n return horizontalOverlap && verticalOverlap;\r\n}\r\n/**\r\n * Generates points of a spiral\r\n * @param cx\r\n * @param cy\r\n * @param radius\r\n * @param radiusY\r\n * @param innerRadius\r\n * @param step\r\n * @param radiusStep\r\n * @param startAngle\r\n * @param endAngle\r\n * @returns IPoint[]\r\n */\r\nexport function spiralPoints(cx, cy, radius, radiusY, innerRadius, step, radiusStep, startAngle, endAngle) {\r\n let r = innerRadius + 0.01;\r\n let angle = startAngle * RADIANS;\r\n let points = [];\r\n while (r < radius + radiusStep) {\r\n let stepSize = step;\r\n if (stepSize / 2 > r) {\r\n stepSize = 2 * r;\r\n }\r\n angle += 2 * Math.asin(stepSize / 2 / r);\r\n if (angle * DEGREES > endAngle + ((radius - innerRadius) / radiusStep) * 360) {\r\n break;\r\n }\r\n let degrees = angle * DEGREES;\r\n let point = { x: cx + r * Math.cos(angle), y: cy + r * radiusY / radius * Math.sin(angle) };\r\n points.push(point);\r\n r = innerRadius + degrees / 360 * radiusStep;\r\n }\r\n points.shift();\r\n return points;\r\n}\r\n/**\r\n * Returns true if circles overlap\r\n * @param circle1\r\n * @param circle2\r\n * @returns boolean\r\n */\r\nexport function circlesOverlap(circle1, circle2) {\r\n return Math.hypot(circle1.x - circle2.x, circle1.y - circle2.y) <= circle1.radius + circle2.radius;\r\n}\r\n//# sourceMappingURL=Math.js.map","/**\r\n * A collection of easing functions\r\n *\r\n * Parts of this collection are taken from D3.js library (https://d3js.org/)\r\n */\r\n/**\r\n * ============================================================================\r\n * IMPORTS\r\n * ============================================================================\r\n * @hidden\r\n */\r\nimport * as $math from \"./Math\";\r\n/**\r\n * The functions below are from D3.js library (https://d3js.org/)\r\n *\r\n * ----------------------------------------------------------------------------\r\n * Copyright 2017 Mike Bostock\r\n *\r\n * Redistribution and use in source and binary forms, with or without\r\n * modification, are permitted provided that the following conditions are met:\r\n *\r\n * 1. Redistributions of source code must retain the above copyright notice,\r\n *\tthis list of conditions and the following disclaimer.\r\n *\r\n * 2. Redistributions in binary form must reproduce the above copyright notice,\r\n *\tthis list of conditions and the following disclaimer in the documentation\r\n *\tand/or other materials provided with the distribution.\r\n *\r\n * 3. Neither the name of the copyright holder nor the names of its\r\n *\tcontributors may be used to endorse or promote products derived from this\r\n *\tsoftware without specific prior written permission.\r\n *\r\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\r\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r\n * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\r\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r\n * POSSIBILITY OF SUCH DAMAGE.\r\n * ----------------------------------------------------------------------------\r\n * @hidden\r\n */\r\n/**\r\n */\r\nexport function linear(t) {\r\n return t;\r\n}\r\nexport function quad(t) {\r\n return t * t;\r\n}\r\nexport function cubic(t) {\r\n return t * t * t;\r\n}\r\nexport function pow(t, e) {\r\n return Math.pow(t, e);\r\n}\r\nexport function exp(t) {\r\n return Math.pow(2, 10 * t - 10);\r\n}\r\nexport function sine(t) {\r\n return 1 - Math.cos(t * $math.HALFPI);\r\n}\r\nexport function circle(t) {\r\n return 1 - Math.sqrt(1 - t * t);\r\n}\r\n/**\r\n * ============================================================================\r\n * TRANSFORMERS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n */\r\nexport function yoyo(ease) {\r\n return function (t) {\r\n if (t < 0.5) {\r\n return ease(t * 2.0);\r\n }\r\n else {\r\n return ease((1.0 - t) * 2.0);\r\n }\r\n };\r\n}\r\nexport function out(ease) {\r\n return function (t) {\r\n return 1.0 - ease(1.0 - t);\r\n };\r\n}\r\nexport function inOut(ease) {\r\n return function (t) {\r\n if (t <= 0.5) {\r\n return ease(t * 2.0) / 2.0;\r\n }\r\n else {\r\n return 1.0 - (ease((1.0 - t) * 2.0) / 2.0);\r\n }\r\n };\r\n}\r\n/**\r\n * ============================================================================\r\n * BOUNCE\r\n * ============================================================================\r\n * @hidden\r\n */\r\nlet b1 = 4 / 11, b2 = 6 / 11, b3 = 8 / 11, b4 = 3 / 4, b5 = 9 / 11, b6 = 10 / 11, b7 = 15 / 16, b8 = 21 / 22, b9 = 63 / 64, b0 = 1 / b1 / b1;\r\nexport function bounce(t) {\r\n return 1 - bounceOut(1 - t);\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction bounceOut(t) {\r\n t = t;\r\n if (t < b1) {\r\n return b0 * t * t;\r\n }\r\n else if (t < b3) {\r\n return b0 * (t -= b2) * t + b4;\r\n }\r\n else if (t < b6) {\r\n return b0 * (t -= b5) * t + b7;\r\n }\r\n else {\r\n return b0 * (t -= b8) * t + b9;\r\n }\r\n}\r\n/**\r\n * ============================================================================\r\n * ELASTIC\r\n * ============================================================================\r\n * @hidden\r\n */\r\n/**\r\n * @ignore\r\n */\r\nlet tau = 2 * Math.PI;\r\n/**\r\n * @ignore\r\n */\r\nlet amplitude = 1;\r\n/**\r\n * @ignore\r\n */\r\nlet period = 0.3 / tau;\r\n/**\r\n * @ignore\r\n */\r\nlet s = Math.asin(1 / amplitude) * period;\r\nexport function elastic(t) {\r\n let v = t;\r\n return amplitude * Math.pow(2, 10 * --v) * Math.sin((s - v) / period);\r\n}\r\n//# sourceMappingURL=Ease.js.map","import * as $object from \"./Object\";\r\nimport * as $ease from \"./Ease\";\r\n/**\r\n * An object representing a collection of setting values to apply as required.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/states/} for more info\r\n */\r\nexport class State {\r\n constructor(entity, settings) {\r\n Object.defineProperty(this, \"_entity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_settings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_userSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n this._entity = entity;\r\n this._settings = settings;\r\n $object.each(settings, (key) => {\r\n this._userSettings[key] = true;\r\n });\r\n }\r\n get(key, fallback) {\r\n const value = this._settings[key];\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n else {\r\n return fallback;\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n setRaw(key, value) {\r\n this._settings[key] = value;\r\n }\r\n /**\r\n * Sets a setting `value` for the specified `key` to be set when the state\r\n * is applied.\r\n *\r\n * @param key Setting key\r\n * @param value Setting value\r\n * @return Setting value\r\n */\r\n set(key, value) {\r\n this._userSettings[key] = true;\r\n this.setRaw(key, value);\r\n }\r\n /**\r\n * Removes a setting value for the specified `key`.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param key Setting key\r\n */\r\n remove(key) {\r\n delete this._userSettings[key];\r\n delete this._settings[key];\r\n }\r\n /**\r\n * Sets multiple settings at once.\r\n *\r\n * `settings` must be an object with key: value pairs.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param settings Settings\r\n */\r\n setAll(settings) {\r\n $object.keys(settings).forEach((key) => {\r\n this.set(key, settings[key]);\r\n });\r\n }\r\n _eachSetting(f) {\r\n $object.each(this._settings, f);\r\n }\r\n /**\r\n * Applies the state to the target element.\r\n *\r\n * All setting values are set immediately.\r\n */\r\n apply() {\r\n const seen = {};\r\n seen[\"stateAnimationEasing\"] = true;\r\n seen[\"stateAnimationDuration\"] = true;\r\n const defaultState = this._entity.states.lookup(\"default\");\r\n this._eachSetting((key, value) => {\r\n if (!seen[key]) {\r\n seen[key] = true;\r\n // save values to default state\r\n if (this !== defaultState) {\r\n if (!(key in defaultState._settings)) {\r\n defaultState._settings[key] = this._entity.get(key);\r\n }\r\n }\r\n this._entity.set(key, value);\r\n }\r\n });\r\n }\r\n /**\r\n * Applies the state to the target element.\r\n *\r\n * Returns an object representing all [[Animation]] objects created for\r\n * each setting key transition.\r\n *\r\n * @return Animations\r\n */\r\n applyAnimate(duration) {\r\n if (duration == null) {\r\n duration = this._settings.stateAnimationDuration;\r\n }\r\n if (duration == null) {\r\n duration = this.get(\"stateAnimationDuration\", this._entity.get(\"stateAnimationDuration\", 0));\r\n }\r\n let easing = this._settings.stateAnimationEasing;\r\n if (easing == null) {\r\n easing = this.get(\"stateAnimationEasing\", this._entity.get(\"stateAnimationEasing\", $ease.cubic));\r\n }\r\n const defaultState = this._entity.states.lookup(\"default\");\r\n const seen = {};\r\n seen[\"stateAnimationEasing\"] = true;\r\n seen[\"stateAnimationDuration\"] = true;\r\n const animations = {};\r\n this._eachSetting((key, value) => {\r\n if (!seen[key]) {\r\n seen[key] = true;\r\n // save values to default state\r\n if (this != defaultState) {\r\n if (!(key in defaultState._settings)) {\r\n defaultState._settings[key] = this._entity.get(key);\r\n }\r\n }\r\n const animation = this._entity.animate({\r\n key: key,\r\n to: value,\r\n duration: duration,\r\n easing: easing\r\n });\r\n if (animation) {\r\n animations[key] = animation;\r\n }\r\n }\r\n });\r\n return animations;\r\n }\r\n}\r\n/**\r\n * Collection of [[State]] objects for an element.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/states/} for more info\r\n */\r\nexport class States {\r\n constructor(entity) {\r\n Object.defineProperty(this, \"_states\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_entity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._entity = entity;\r\n }\r\n /**\r\n * Checks if a state by `name` exists. Returns it there is one.\r\n *\r\n * @param name State name\r\n * @return State\r\n */\r\n lookup(name) {\r\n return this._states[name];\r\n }\r\n /**\r\n * Sets supplied `settings` on a state by the `name`.\r\n *\r\n * If such state does not yet exists, it is created.\r\n *\r\n * @param name State name\r\n * @param settings Settings\r\n * @return New State\r\n */\r\n create(name, settings) {\r\n const state = this._states[name];\r\n if (state) {\r\n state.setAll(settings);\r\n return state;\r\n }\r\n else {\r\n const state = new State(this._entity, settings);\r\n this._states[name] = state;\r\n return state;\r\n }\r\n }\r\n /**\r\n * Removes the state called `name`.\r\n *\r\n * @param name State name\r\n */\r\n remove(name) {\r\n delete this._states[name];\r\n }\r\n /**\r\n * Applies a named state to the target element.\r\n *\r\n * @param newState State name\r\n */\r\n apply(newState) {\r\n const state = this._states[newState];\r\n if (state) {\r\n state.apply();\r\n }\r\n this._entity._applyState(newState);\r\n }\r\n /**\r\n * Applies a named state to the element.\r\n *\r\n * Returns an object representing all [[Animation]] objects created for\r\n * each setting key transition.\r\n *\r\n * @param newState State name\r\n * @return Animations\r\n */\r\n applyAnimate(newState, duration) {\r\n let animations;\r\n const state = this._states[newState];\r\n if (state) {\r\n animations = state.applyAnimate(duration);\r\n }\r\n this._entity._applyStateAnimated(newState, duration);\r\n return animations;\r\n }\r\n}\r\n//# sourceMappingURL=States.js.map","/**\r\n * @ignore\r\n */\r\nexport class Registry {\r\n constructor() {\r\n /**\r\n * Currently running version of amCharts.\r\n */\r\n Object.defineProperty(this, \"version\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"5.10.7\"\r\n });\r\n /**\r\n * List of applied licenses.\r\n * @ignore\r\n */\r\n Object.defineProperty(this, \"licenses\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n /**\r\n * Entities that have their `id` setting set.\r\n */\r\n Object.defineProperty(this, \"entitiesById\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n /**\r\n * All created [[Root]] elements.\r\n */\r\n Object.defineProperty(this, \"rootElements\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport const registry = new Registry();\r\n/**\r\n * Adds a license, e.g.:\r\n *\r\n * ```TypeScript\r\n * am5.addLicense(\"xxxxxxxx\");\r\n * ```\r\n * ```JavaScript\r\n * am5.addLicense(\"xxxxxxxx\");\r\n * ```\r\n *\r\n * Multiple licenses can be added to cover for multiple products.\r\n *\r\n * @param license License key\r\n */\r\nexport function addLicense(license) {\r\n registry.licenses.push(license);\r\n}\r\n/**\r\n * Disposes all [[Root]] elements.\r\n */\r\nexport function disposeAllRootElements() {\r\n let root;\r\n while (root = registry.rootElements.pop()) {\r\n root.dispose();\r\n }\r\n}\r\n/**\r\n * Finds and returns a `Root` element assigned to a container with `id`.\r\n *\r\n * @param id Container ID\r\n * @return Root\r\n * @since 5.9.2\r\n */\r\nexport function getRootById(id) {\r\n let found;\r\n registry.rootElements.forEach((item) => {\r\n if (item.dom.id == id) {\r\n found = item;\r\n }\r\n });\r\n return found;\r\n}\r\n//# sourceMappingURL=Registry.js.map","/**\r\n * @ignore\r\n */\r\nexport function compare(left, right) {\r\n if (left === right) {\r\n return 0;\r\n }\r\n else if (left < right) {\r\n return -1;\r\n }\r\n else {\r\n return 1;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function compareArray(left, right, f) {\r\n const leftLength = left.length;\r\n const rightLength = right.length;\r\n const length = Math.min(leftLength, rightLength);\r\n for (let i = 0; i < length; ++i) {\r\n const order = f(left[i], right[i]);\r\n if (order !== 0) {\r\n return order;\r\n }\r\n }\r\n return compare(leftLength, rightLength);\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function reverse(order) {\r\n if (order < 0) {\r\n return 1;\r\n }\r\n else if (order > 0) {\r\n return -1;\r\n }\r\n else {\r\n return 0;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function compareNumber(a, b) {\r\n if (a === b) {\r\n return 0;\r\n }\r\n else if (a < b) {\r\n return -1;\r\n }\r\n else {\r\n return 1;\r\n }\r\n}\r\n//# sourceMappingURL=Order.js.map","import { Disposer } from \"./Disposer\";\r\nimport { EventDispatcher } from \"./EventDispatcher\";\r\nimport { AnimationState, getInterpolate } from \"./Animation\";\r\nimport { States } from \"./States\";\r\nimport { registry } from \"../Registry\";\r\nimport * as $object from \"./Object\";\r\nimport * as $ease from \"./Ease\";\r\nimport * as $array from \"./Array\";\r\nimport * as $order from \"./Order\";\r\n/**\r\n * Allows to dynamically modify setting value of its target element.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/adapters/} for more info\r\n */\r\nexport class Adapters {\r\n constructor(entity) {\r\n Object.defineProperty(this, \"_entity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_callbacks\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_disabled\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n this._entity = entity;\r\n }\r\n /**\r\n * Add a function (`callback`) that will modify value for setting `key`.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/adapters/} for more info\r\n */\r\n add(key, callback) {\r\n let callbacks = this._callbacks[key];\r\n if (callbacks === undefined) {\r\n callbacks = this._callbacks[key] = [];\r\n }\r\n callbacks.push(callback);\r\n this._entity._markDirtyKey(key);\r\n return new Disposer(() => {\r\n if ($array.removeFirst(callbacks, callback)) {\r\n this._entity._markDirtyKey(key);\r\n }\r\n });\r\n }\r\n /**\r\n * Removes all adapters for the specific key.\r\n *\r\n * @since 5.1.0\r\n */\r\n remove(key) {\r\n const callbacks = this._callbacks[key];\r\n if (callbacks !== undefined) {\r\n delete this._callbacks[key];\r\n if (callbacks.length !== 0) {\r\n this._entity._markDirtyKey(key);\r\n }\r\n }\r\n }\r\n /**\r\n * Enables (previously disabled) adapters for specific key.\r\n *\r\n * @since 5.1.0\r\n */\r\n enable(key) {\r\n if (this._disabled[key]) {\r\n delete this._disabled[key];\r\n this._entity._markDirtyKey(key);\r\n }\r\n }\r\n /**\r\n * Disables all adapters for specific key.\r\n *\r\n * @since 5.1.0\r\n */\r\n disable(key) {\r\n if (!this._disabled[key]) {\r\n this._disabled[key] = true;\r\n this._entity._markDirtyKey(key);\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n fold(key, value) {\r\n if (!this._disabled[key]) {\r\n const callbacks = this._callbacks[key];\r\n if (callbacks !== undefined) {\r\n for (let i = 0, len = callbacks.length; i < len; ++i) {\r\n value = callbacks[i](value, this._entity, key);\r\n }\r\n }\r\n }\r\n return value;\r\n }\r\n}\r\n/**\r\n * Animation object.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/animations/} for more info\r\n */\r\nexport class Animation {\r\n constructor(animation, from, to, duration, easing, loops, startingTime) {\r\n Object.defineProperty(this, \"_animation\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_from\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_to\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_duration\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_easing\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_loops\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_interpolate\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_oldTime\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_time\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_stopped\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_playing\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new EventDispatcher()\r\n });\r\n this._animation = animation;\r\n this._from = from;\r\n this._to = to;\r\n this._duration = duration;\r\n this._easing = easing;\r\n this._loops = loops;\r\n this._interpolate = getInterpolate(from, to);\r\n this._oldTime = startingTime;\r\n }\r\n get to() {\r\n return this._to;\r\n }\r\n get from() {\r\n return this._from;\r\n }\r\n get playing() {\r\n return this._playing;\r\n }\r\n get stopped() {\r\n return this._stopped;\r\n }\r\n stop() {\r\n if (!this._stopped) {\r\n this._stopped = true;\r\n this._playing = false;\r\n if (this.events.isEnabled(\"stopped\")) {\r\n this.events.dispatch(\"stopped\", {\r\n type: \"stopped\",\r\n target: this,\r\n });\r\n }\r\n }\r\n }\r\n pause() {\r\n this._playing = false;\r\n this._oldTime = null;\r\n }\r\n play() {\r\n if (!this._stopped && !this._playing) {\r\n this._playing = true;\r\n this._animation._startAnimation();\r\n }\r\n }\r\n get percentage() {\r\n return this._time / this._duration;\r\n }\r\n waitForStop() {\r\n return new Promise((resolve, _reject) => {\r\n if (this._stopped) {\r\n resolve();\r\n }\r\n else {\r\n const listener = () => {\r\n stopped.dispose();\r\n resolve();\r\n };\r\n const stopped = this.events.on(\"stopped\", listener);\r\n }\r\n });\r\n }\r\n _checkEnded() {\r\n if (this._loops > 1) {\r\n --this._loops;\r\n return false;\r\n }\r\n else {\r\n return true;\r\n }\r\n }\r\n _run(currentTime) {\r\n if (this._oldTime !== null) {\r\n this._time += currentTime - this._oldTime;\r\n if (this._time > this._duration) {\r\n this._time = this._duration;\r\n }\r\n }\r\n this._oldTime = currentTime;\r\n }\r\n _reset(currentTime) {\r\n this._oldTime = currentTime;\r\n this._time = 0;\r\n }\r\n _value(diff) {\r\n return this._interpolate(this._easing(diff), this._from, this._to);\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nlet counter = 0;\r\n/**\r\n * Base class for [[Entity]] objects that support Settings.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n */\r\nexport class Settings {\r\n constructor(settings) {\r\n /**\r\n * Unique ID.\r\n */\r\n Object.defineProperty(this, \"uid\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: ++counter\r\n });\r\n Object.defineProperty(this, \"_settings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_privateSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_settingEvents\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_privateSettingEvents\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_prevSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_prevPrivateSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_animatingSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_animatingPrivateSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n // TODO move this into Entity\r\n Object.defineProperty(this, \"_userProperties\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n /**\r\n * If this is set to `false` then disposing does nothing, it's a no-op.\r\n */\r\n Object.defineProperty(this, \"enableDispose\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n this._settings = settings;\r\n }\r\n _checkDirty() {\r\n $object.keys(this._settings).forEach((key) => {\r\n this._userProperties[key] = true;\r\n this._markDirtyKey(key);\r\n });\r\n }\r\n /**\r\n * @ignore\r\n */\r\n resetUserSettings() {\r\n this._userProperties = {};\r\n }\r\n _runAnimation(currentTime) {\r\n let state = AnimationState.Stopped;\r\n if (!this.isDisposed()) {\r\n let playing = false;\r\n let paused = false;\r\n $object.each(this._animatingSettings, (key, animation) => {\r\n if (animation.stopped) {\r\n this._stopAnimation(key);\r\n }\r\n else if (animation.playing) {\r\n animation._run(currentTime);\r\n const diff = animation.percentage;\r\n if (diff >= 1) {\r\n if (animation._checkEnded()) {\r\n this.set(key, animation._value(1));\r\n }\r\n else {\r\n playing = true;\r\n animation._reset(currentTime);\r\n this._set(key, animation._value(1));\r\n }\r\n }\r\n else {\r\n playing = true;\r\n this._set(key, animation._value(diff));\r\n }\r\n }\r\n else {\r\n paused = true;\r\n }\r\n });\r\n $object.each(this._animatingPrivateSettings, (key, animation) => {\r\n if (animation.stopped) {\r\n this._stopAnimationPrivate(key);\r\n }\r\n else if (animation.playing) {\r\n animation._run(currentTime);\r\n const diff = animation.percentage;\r\n if (diff >= 1) {\r\n if (animation._checkEnded()) {\r\n this.setPrivate(key, animation._value(1));\r\n }\r\n else {\r\n playing = true;\r\n animation._reset(currentTime);\r\n this._setPrivate(key, animation._value(1));\r\n }\r\n }\r\n else {\r\n playing = true;\r\n this._setPrivate(key, animation._value(diff));\r\n }\r\n }\r\n else {\r\n paused = true;\r\n }\r\n });\r\n if (playing) {\r\n state = AnimationState.Playing;\r\n }\r\n else if (paused) {\r\n state = AnimationState.Paused;\r\n }\r\n }\r\n return state;\r\n }\r\n _markDirtyKey(_key) {\r\n this.markDirty();\r\n }\r\n _markDirtyPrivateKey(_key) {\r\n this.markDirty();\r\n }\r\n /**\r\n * Sets a callback function to invoke when specific key of settings changes\r\n * or is set.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/events/#Settings_value_change} for more info\r\n * @param key Settings key\r\n * @param callback Callback\r\n * @return Disposer for event\r\n */\r\n on(key, callback) {\r\n let events = this._settingEvents[key];\r\n if (events === undefined) {\r\n events = this._settingEvents[key] = [];\r\n }\r\n events.push(callback);\r\n return new Disposer(() => {\r\n $array.removeFirst(events, callback);\r\n if (events.length === 0) {\r\n delete this._settingEvents[key];\r\n }\r\n });\r\n }\r\n /**\r\n * Removes a callback for when value of a setting changes.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/events/#Settings_value_change} for more info\r\n * @param key Private settings key\r\n * @param callback Callback\r\n * @since 5.9.2\r\n */\r\n off(key, callback) {\r\n let events = this._settingEvents[key];\r\n if (events !== undefined && callback !== undefined) {\r\n $array.removeFirst(events, callback);\r\n }\r\n else {\r\n delete this._settingEvents[key];\r\n }\r\n }\r\n /**\r\n * Sets a callback function to invoke when specific key of private settings\r\n * changes or is set.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/events/#Settings_value_change} for more info\r\n * @param key Private settings key\r\n * @param callback Callback\r\n * @return Disposer for event\r\n */\r\n onPrivate(key, callback) {\r\n let events = this._privateSettingEvents[key];\r\n if (events === undefined) {\r\n events = this._privateSettingEvents[key] = [];\r\n }\r\n events.push(callback);\r\n return new Disposer(() => {\r\n $array.removeFirst(events, callback);\r\n if (events.length === 0) {\r\n delete this._privateSettingEvents[key];\r\n }\r\n });\r\n }\r\n /**\r\n * Removes a callback for when value of a private setting changes.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/events/#Settings_value_change} for more info\r\n * @param key Private settings key\r\n * @param callback Callback\r\n * @since 5.9.2\r\n */\r\n offPrivate(key, callback) {\r\n let events = this._privateSettingEvents[key];\r\n if (events !== undefined && callback !== undefined) {\r\n $array.removeFirst(events, callback);\r\n }\r\n else {\r\n delete this._privateSettingEvents[key];\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n getRaw(key, fallback) {\r\n const value = this._settings[key];\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n else {\r\n return fallback;\r\n }\r\n }\r\n /**\r\n * Returns `true` if the setting exists.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param key Settings key\r\n * @return {boolean} Key exists\r\n */\r\n has(key) {\r\n return key in this._settings;\r\n }\r\n get(key, fallback) {\r\n return this.getRaw(key, fallback);\r\n }\r\n _sendKeyEvent(key, value) {\r\n const events = this._settingEvents[key];\r\n if (events !== undefined) {\r\n $array.each(events, (callback) => {\r\n callback(value, this, key);\r\n });\r\n }\r\n }\r\n _sendPrivateKeyEvent(key, value) {\r\n const events = this._privateSettingEvents[key];\r\n if (events !== undefined) {\r\n $array.each(events, (callback) => {\r\n callback(value, this, key);\r\n });\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n _setRaw(key, old, value) {\r\n this._prevSettings[key] = old;\r\n this._sendKeyEvent(key, value);\r\n }\r\n /**\r\n * @ignore\r\n */\r\n setRaw(key, value) {\r\n const old = this._settings[key];\r\n this._settings[key] = value;\r\n if (old !== value) {\r\n this._setRaw(key, old, value);\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n _set(key, value) {\r\n const old = this._settings[key];\r\n this._settings[key] = value;\r\n if (old !== value) {\r\n this._setRaw(key, old, value);\r\n this._markDirtyKey(key);\r\n }\r\n }\r\n _stopAnimation(key) {\r\n const animation = this._animatingSettings[key];\r\n if (animation) {\r\n delete this._animatingSettings[key];\r\n animation.stop();\r\n }\r\n }\r\n /**\r\n * Sets a setting `value` for the specified `key`, and returns the same `value`.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param key Setting key\r\n * @param value Setting value\r\n * @return Setting value\r\n */\r\n set(key, value) {\r\n this._set(key, value);\r\n this._stopAnimation(key);\r\n return value;\r\n }\r\n /**\r\n * Removes a setting value for the specified `key`;\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param key Setting key\r\n */\r\n remove(key) {\r\n if (key in this._settings) {\r\n this._prevSettings[key] = this._settings[key];\r\n delete this._settings[key];\r\n this._sendKeyEvent(key, undefined);\r\n this._markDirtyKey(key);\r\n }\r\n this._stopAnimation(key);\r\n }\r\n /**\r\n * Removes all keys;\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n */\r\n removeAll() {\r\n $array.each($object.keys(this._settings), (key) => {\r\n this.remove(key);\r\n });\r\n }\r\n /**\r\n * Returns a value of a private setting.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/#Private_settings} for more info\r\n */\r\n getPrivate(key, fallback) {\r\n const value = this._privateSettings[key];\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n else {\r\n return fallback;\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n _setPrivateRaw(key, old, value) {\r\n this._prevPrivateSettings[key] = old;\r\n this._sendPrivateKeyEvent(key, value);\r\n }\r\n /**\r\n * @ignore\r\n */\r\n setPrivateRaw(key, value) {\r\n const old = this._privateSettings[key];\r\n this._privateSettings[key] = value;\r\n if (old !== value) {\r\n this._setPrivateRaw(key, old, value);\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n _setPrivate(key, value) {\r\n const old = this._privateSettings[key];\r\n this._privateSettings[key] = value;\r\n if (old !== value) {\r\n this._setPrivateRaw(key, old, value);\r\n this._markDirtyPrivateKey(key);\r\n }\r\n }\r\n _stopAnimationPrivate(key) {\r\n const animation = this._animatingPrivateSettings[key];\r\n if (animation) {\r\n animation.stop();\r\n delete this._animatingPrivateSettings[key];\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n setPrivate(key, value) {\r\n this._setPrivate(key, value);\r\n this._stopAnimationPrivate(key);\r\n return value;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n removePrivate(key) {\r\n if (key in this._privateSettings) {\r\n this._prevPrivateSettings[key] = this._privateSettings[key];\r\n delete this._privateSettings[key];\r\n this._markDirtyPrivateKey(key);\r\n }\r\n this._stopAnimationPrivate(key);\r\n }\r\n /**\r\n * Sets multiple settings at once.\r\n *\r\n * `settings` must be an object with key: value pairs.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param settings Settings\r\n */\r\n setAll(settings) {\r\n $object.each(settings, (key, value) => {\r\n this.set(key, value);\r\n });\r\n }\r\n /**\r\n * Animates setting values from current/start values to new ones.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/animations/#Animating_settings} for more info\r\n * @param options Animation options\r\n * @return Animation object\r\n */\r\n animate(options) {\r\n const key = options.key;\r\n const to = options.to;\r\n const duration = options.duration || 0;\r\n const loops = options.loops || 1;\r\n const from = (options.from === undefined ? this.get(key) : options.from);\r\n const easing = (options.easing === undefined ? $ease.linear : options.easing);\r\n if (duration === 0) {\r\n this.set(key, to);\r\n }\r\n else {\r\n if (from === undefined || from === to) {\r\n this.set(key, to);\r\n }\r\n else {\r\n this.set(key, from);\r\n const animation = this._animatingSettings[key] = new Animation(this, from, to, duration, easing, loops, this._animationTime());\r\n this._startAnimation();\r\n return animation;\r\n }\r\n }\r\n const animation = new Animation(this, from, to, duration, easing, loops, null);\r\n animation.stop();\r\n return animation;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n animatePrivate(options) {\r\n const key = options.key;\r\n const to = options.to;\r\n const duration = options.duration || 0;\r\n const loops = options.loops || 1;\r\n const from = (options.from === undefined ? this.getPrivate(key) : options.from);\r\n const easing = (options.easing === undefined ? $ease.linear : options.easing);\r\n if (duration === 0) {\r\n this.setPrivate(key, to);\r\n }\r\n else {\r\n if (from === undefined || from === to) {\r\n this.setPrivate(key, to);\r\n }\r\n else {\r\n this.setPrivate(key, from);\r\n const animation = this._animatingPrivateSettings[key] = new Animation(this, from, to, duration, easing, loops, this._animationTime());\r\n this._startAnimation();\r\n return animation;\r\n }\r\n }\r\n const animation = new Animation(this, from, to, duration, easing, loops, null);\r\n animation.stop();\r\n return animation;\r\n }\r\n _dispose() { }\r\n /**\r\n * Returns `true` if this element is disposed.\r\n *\r\n * @return Disposed\r\n */\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n /**\r\n * Disposes this object.\r\n */\r\n dispose() {\r\n if (this.enableDispose && !this._disposed) {\r\n this._disposed = true;\r\n this._dispose();\r\n }\r\n }\r\n}\r\n/**\r\n * Base class.\r\n *\r\n * @important\r\n */\r\nexport class Entity extends Settings {\r\n /**\r\n * IMPORTANT! Do not instantiate this class via `new Class()` syntax.\r\n *\r\n * Use static method `Class.new()` instead.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/#New_element_syntax} for more info\r\n * @ignore\r\n */\r\n constructor(root, settings, isReal, templates = []) {\r\n super(settings);\r\n Object.defineProperty(this, \"_root\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_user_id\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n }); // for testing purposes\r\n Object.defineProperty(this, \"states\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new States(this)\r\n });\r\n Object.defineProperty(this, \"adapters\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new Adapters(this)\r\n });\r\n Object.defineProperty(this, \"events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._createEvents()\r\n });\r\n Object.defineProperty(this, \"_userPrivateProperties\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_dirty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_dirtyPrivate\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_template\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n // Templates for the themes\r\n Object.defineProperty(this, \"_templates\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n // Internal templates which can be overridden by the user's templates\r\n Object.defineProperty(this, \"_internalTemplates\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n // Default themes which can be overridden by the user's themes\r\n Object.defineProperty(this, \"_defaultThemes\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n // Disposers for all of the templates\r\n Object.defineProperty(this, \"_templateDisposers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_disposers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n // Whether the template setup function should be run\r\n Object.defineProperty(this, \"_runSetup\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"_disposerProperties\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n if (!isReal) {\r\n throw new Error(\"You cannot use `new Class()`, instead use `Class.new()`\");\r\n }\r\n this._root = root;\r\n this._internalTemplates = templates;\r\n if (settings.id) {\r\n this._registerId(settings.id);\r\n }\r\n }\r\n /**\r\n * Use this method to create an instance of this class.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/#New_element_syntax} for more info\r\n * @param root Root element\r\n * @param settings Settings\r\n * @param template Template\r\n * @return Instantiated object\r\n */\r\n static new(root, settings, template) {\r\n const x = (new this(root, settings, true));\r\n x._template = template;\r\n x._afterNew();\r\n return x;\r\n }\r\n static _new(root, settings, templates = []) {\r\n const x = (new this(root, settings, true, templates));\r\n x._afterNew();\r\n return x;\r\n }\r\n _afterNew() {\r\n this._checkDirty();\r\n let shouldApply = false;\r\n const template = this._template;\r\n if (template) {\r\n shouldApply = true;\r\n template._setObjectTemplate(this);\r\n }\r\n $array.each(this._internalTemplates, (template) => {\r\n shouldApply = true;\r\n template._setObjectTemplate(this);\r\n });\r\n if (shouldApply) {\r\n this._applyTemplates(false);\r\n }\r\n this.states.create(\"default\", {});\r\n this._setDefaults();\r\n }\r\n // This is the same as _afterNew, except it also applies the themes.\r\n // This should only be used for classes which don't have a parent (because they extend from Entity and not Sprite).\r\n _afterNewApplyThemes() {\r\n this._checkDirty();\r\n const template = this._template;\r\n if (template) {\r\n template._setObjectTemplate(this);\r\n }\r\n $array.each(this._internalTemplates, (template) => {\r\n template._setObjectTemplate(this);\r\n });\r\n this.states.create(\"default\", {});\r\n this._setDefaults();\r\n this._applyThemes();\r\n }\r\n _createEvents() {\r\n return new EventDispatcher();\r\n }\r\n /**\r\n * @ignore\r\n */\r\n get classNames() {\r\n return this.constructor.classNames;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n get className() {\r\n return this.constructor.className;\r\n }\r\n _setDefaults() {\r\n }\r\n _setDefaultFn(key, f) {\r\n const value = this.get(key);\r\n if (value) {\r\n return value;\r\n }\r\n else {\r\n const value = f();\r\n this.set(key, value);\r\n return value;\r\n }\r\n }\r\n _setDefault(key, value) {\r\n if (!this.has(key)) {\r\n super.set(key, value);\r\n }\r\n }\r\n _setRawDefault(key, value) {\r\n if (!this.has(key)) {\r\n super.setRaw(key, value);\r\n }\r\n }\r\n _clearDirty() {\r\n $object.keys(this._dirty).forEach((key) => {\r\n this._dirty[key] = false;\r\n });\r\n $object.keys(this._dirtyPrivate).forEach((key) => {\r\n this._dirtyPrivate[key] = false;\r\n });\r\n }\r\n /**\r\n * @ignore\r\n */\r\n isDirty(key) {\r\n return !!this._dirty[key];\r\n }\r\n /**\r\n * @ignore\r\n */\r\n isPrivateDirty(key) {\r\n return !!this._dirtyPrivate[key];\r\n }\r\n _markDirtyKey(key) {\r\n this._dirty[key] = true;\r\n super._markDirtyKey(key);\r\n }\r\n _markDirtyPrivateKey(key) {\r\n this._dirtyPrivate[key] = true;\r\n super._markDirtyKey(key);\r\n }\r\n /**\r\n * Checks if element is of certain class (or inherits one).\r\n *\r\n * @param type Class name to check\r\n * @return {boolean} Is of class?\r\n */\r\n isType(type) {\r\n return this.classNames.indexOf(type) !== -1;\r\n }\r\n _pushPropertyDisposer(key, disposer) {\r\n let disposers = this._disposerProperties[key];\r\n if (disposers === undefined) {\r\n disposers = this._disposerProperties[key] = [];\r\n }\r\n disposers.push(disposer);\r\n return disposer;\r\n }\r\n _disposeProperty(key) {\r\n const disposers = this._disposerProperties[key];\r\n if (disposers !== undefined) {\r\n $array.each(disposers, (disposer) => {\r\n disposer.dispose();\r\n });\r\n delete this._disposerProperties[key];\r\n }\r\n }\r\n /**\r\n * @todo needs description\r\n * @param value Template\r\n */\r\n set template(value) {\r\n const template = this._template;\r\n if (template !== value) {\r\n this._template = value;\r\n if (template) {\r\n template._removeObjectTemplate(this);\r\n }\r\n if (value) {\r\n value._setObjectTemplate(this);\r\n }\r\n this._applyTemplates();\r\n }\r\n }\r\n get template() {\r\n return this._template;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirty() {\r\n this._root._addDirtyEntity(this);\r\n }\r\n _startAnimation() {\r\n this._root._addAnimation(this);\r\n }\r\n _animationTime() {\r\n return this._root.animationTime;\r\n }\r\n _applyState(_name) { }\r\n _applyStateAnimated(_name, _duration) { }\r\n get(key, fallback) {\r\n const value = this.adapters.fold(key, this._settings[key]);\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n else {\r\n return fallback;\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n isUserSetting(key) {\r\n return this._userProperties[key] || false;\r\n }\r\n /**\r\n * Sets a setting `value` for the specified `key`, and returns the same `value`.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param key Setting key\r\n * @param value Setting value\r\n * @return Setting value\r\n */\r\n set(key, value) {\r\n this._userProperties[key] = true;\r\n return super.set(key, value);\r\n }\r\n /**\r\n * @ignore\r\n */\r\n setRaw(key, value) {\r\n this._userProperties[key] = true;\r\n super.setRaw(key, value);\r\n }\r\n /**\r\n * Sets a setting `value` for the specified `key` only if the value for this key was not set previously using set method, and returns the same `value`.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param key Setting key\r\n * @param value Setting value\r\n * @return Setting value\r\n */\r\n _setSoft(key, value) {\r\n if (!this._userProperties[key]) {\r\n return super.set(key, value);\r\n }\r\n return value;\r\n }\r\n /**\r\n * Removes a setting value for the specified `key`.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/settings/} for more info\r\n * @param key Setting key\r\n */\r\n remove(key) {\r\n delete this._userProperties[key];\r\n this._removeTemplateProperty(key);\r\n }\r\n /**\r\n * @ignore\r\n */\r\n setPrivate(key, value) {\r\n this._userPrivateProperties[key] = true;\r\n return super.setPrivate(key, value);\r\n }\r\n /**\r\n * @ignore\r\n */\r\n setPrivateRaw(key, value) {\r\n this._userPrivateProperties[key] = true;\r\n super.setPrivateRaw(key, value);\r\n }\r\n /**\r\n * @ignore\r\n */\r\n removePrivate(key) {\r\n delete this._userPrivateProperties[key];\r\n this._removeTemplatePrivateProperty(key);\r\n }\r\n _setTemplateProperty(template, key, value) {\r\n if (!this._userProperties[key]) {\r\n const match = this._findTemplateByKey(key);\r\n if (template === match) {\r\n super.set(key, value);\r\n }\r\n }\r\n }\r\n _setTemplatePrivateProperty(template, key, value) {\r\n if (!this._userPrivateProperties[key]) {\r\n const match = this._findTemplateByPrivateKey(key);\r\n if (template === match) {\r\n super.setPrivate(key, value);\r\n }\r\n }\r\n }\r\n _removeTemplateProperty(key) {\r\n if (!this._userProperties[key]) {\r\n const match = this._findTemplateByKey(key);\r\n if (match) {\r\n // TODO don't stop the animation if the property didn't change\r\n super.set(key, match._settings[key]);\r\n }\r\n else {\r\n super.remove(key);\r\n }\r\n }\r\n }\r\n _removeTemplatePrivateProperty(key) {\r\n if (!this._userPrivateProperties[key]) {\r\n const match = this._findTemplateByPrivateKey(key);\r\n if (match) {\r\n // TODO don't stop the animation if the property didn't change\r\n super.setPrivate(key, match._privateSettings[key]);\r\n }\r\n else {\r\n super.removePrivate(key);\r\n }\r\n }\r\n }\r\n _walkParents(f) {\r\n f(this._root._rootContainer);\r\n f(this);\r\n }\r\n // TODO faster version of this method which is specialized to just 1 key\r\n _applyStateByKey(name) {\r\n const other = this.states.create(name, {});\r\n const seen = {};\r\n this._eachTemplate((template) => {\r\n const state = template.states.lookup(name);\r\n if (state) {\r\n state._apply(other, seen);\r\n }\r\n });\r\n $object.each(other._settings, (key) => {\r\n if (!seen[key] && !other._userSettings[key]) {\r\n other.remove(key);\r\n }\r\n });\r\n }\r\n _applyTemplate(template, state) {\r\n this._templateDisposers.push(template._apply(this, state));\r\n $object.each(template._settings, (key, value) => {\r\n if (!state.settings[key] && !this._userProperties[key]) {\r\n state.settings[key] = true;\r\n super.set(key, value);\r\n }\r\n });\r\n $object.each(template._privateSettings, (key, value) => {\r\n if (!state.privateSettings[key] && !this._userPrivateProperties[key]) {\r\n state.privateSettings[key] = true;\r\n super.setPrivate(key, value);\r\n }\r\n });\r\n if (this._runSetup && template.setup) {\r\n this._runSetup = false;\r\n template.setup(this);\r\n }\r\n }\r\n /**\r\n * Calls the closure with each template and returns the first template which is true\r\n */\r\n _findStaticTemplate(f) {\r\n if (this._template) {\r\n if (f(this._template)) {\r\n return this._template;\r\n }\r\n }\r\n }\r\n _eachTemplate(f) {\r\n this._findStaticTemplate((template) => {\r\n f(template);\r\n return false;\r\n });\r\n // _internalTemplates is sorted with most specific to the right\r\n $array.eachReverse(this._internalTemplates, f);\r\n // _templates is sorted with most specific to the left\r\n $array.each(this._templates, f);\r\n }\r\n _applyTemplates(remove = true) {\r\n if (remove) {\r\n this._disposeTemplates();\r\n }\r\n const state = {\r\n settings: {},\r\n privateSettings: {},\r\n states: {},\r\n };\r\n this._eachTemplate((template) => {\r\n this._applyTemplate(template, state);\r\n });\r\n if (remove) {\r\n $object.each(this._settings, (key) => {\r\n if (!this._userProperties[key] && !state.settings[key]) {\r\n super.remove(key);\r\n }\r\n });\r\n $object.each(this._privateSettings, (key) => {\r\n if (!this._userPrivateProperties[key] && !state.privateSettings[key]) {\r\n super.removePrivate(key);\r\n }\r\n });\r\n }\r\n }\r\n _findTemplate(f) {\r\n const value = this._findStaticTemplate(f);\r\n if (value === undefined) {\r\n // _internalTemplates is sorted with most specific to the right\r\n const value = $array.findReverse(this._internalTemplates, f);\r\n if (value === undefined) {\r\n // _templates is sorted with most specific to the left\r\n return $array.find(this._templates, f);\r\n }\r\n else {\r\n return value;\r\n }\r\n }\r\n else {\r\n return value;\r\n }\r\n }\r\n _findTemplateByKey(key) {\r\n return this._findTemplate((template) => {\r\n return key in template._settings;\r\n });\r\n }\r\n _findTemplateByPrivateKey(key) {\r\n return this._findTemplate((template) => {\r\n return key in template._privateSettings;\r\n });\r\n }\r\n _disposeTemplates() {\r\n $array.each(this._templateDisposers, (disposer) => {\r\n disposer.dispose();\r\n });\r\n this._templateDisposers.length = 0;\r\n }\r\n _removeTemplates() {\r\n $array.each(this._templates, (template) => {\r\n template._removeObjectTemplate(this);\r\n });\r\n this._templates.length = 0;\r\n }\r\n _applyThemes(force = false) {\r\n let isConnected = false;\r\n const defaults = [];\r\n let themes = [];\r\n const themeTags = new Set();\r\n const tags = this.get(\"themeTagsSelf\");\r\n if (tags) {\r\n $array.each(tags, (tag) => {\r\n themeTags.add(tag);\r\n });\r\n }\r\n this._walkParents((entity) => {\r\n if (entity === this._root._rootContainer) {\r\n isConnected = true;\r\n }\r\n if (entity._defaultThemes.length > 0) {\r\n defaults.push(entity._defaultThemes);\r\n }\r\n const theme = entity.get(\"themes\");\r\n if (theme) {\r\n themes.push(theme);\r\n }\r\n const tags = entity.get(\"themeTags\");\r\n if (tags) {\r\n $array.each(tags, (tag) => {\r\n themeTags.add(tag);\r\n });\r\n }\r\n });\r\n themes = defaults.concat(themes);\r\n this._removeTemplates();\r\n if (isConnected || force) {\r\n $array.eachReverse(this.classNames, (name) => {\r\n const allRules = [];\r\n $array.each(themes, (themes) => {\r\n $array.each(themes, (theme) => {\r\n const rules = theme._lookupRules(name);\r\n if (rules) {\r\n $array.eachReverse(rules, (rule) => {\r\n const matches = rule.tags.every((tag) => {\r\n return themeTags.has(tag);\r\n });\r\n if (matches) {\r\n const result = $array.getFirstSortedIndex(allRules, (x) => {\r\n const order = $order.compare(rule.tags.length, x.tags.length);\r\n if (order === 0) {\r\n return $order.compareArray(rule.tags, x.tags, $order.compare);\r\n }\r\n else {\r\n return order;\r\n }\r\n });\r\n allRules.splice(result.index, 0, rule);\r\n }\r\n });\r\n }\r\n });\r\n });\r\n $array.each(allRules, (rule) => {\r\n this._templates.push(rule.template);\r\n rule.template._setObjectTemplate(this);\r\n });\r\n });\r\n }\r\n this._applyTemplates();\r\n if (isConnected || force) {\r\n // This causes it to only run the setup function the first time that the themes are applied\r\n this._runSetup = false;\r\n }\r\n return isConnected || force;\r\n }\r\n _changed() { }\r\n _beforeChanged() {\r\n if (this.isDirty(\"id\")) {\r\n const id = this.get(\"id\");\r\n if (id) {\r\n this._registerId(id);\r\n }\r\n const prevId = this._prevSettings.id;\r\n if (prevId) {\r\n delete registry.entitiesById[prevId];\r\n }\r\n }\r\n }\r\n _registerId(id) {\r\n if (registry.entitiesById[id] && registry.entitiesById[id] !== this) {\r\n throw new Error(\"An entity with id \\\"\" + id + \"\\\" already exists.\");\r\n }\r\n registry.entitiesById[id] = this;\r\n }\r\n _afterChanged() { }\r\n /**\r\n * @ignore\r\n */\r\n addDisposer(disposer) {\r\n this._disposers.push(disposer);\r\n return disposer;\r\n }\r\n _dispose() {\r\n super._dispose();\r\n const template = this._template;\r\n if (template) {\r\n template._removeObjectTemplate(this);\r\n }\r\n $array.each(this._internalTemplates, (template) => {\r\n template._removeObjectTemplate(this);\r\n });\r\n this._removeTemplates();\r\n this._disposeTemplates();\r\n this.events.dispose();\r\n this._disposers.forEach((x) => {\r\n x.dispose();\r\n });\r\n $object.each(this._disposerProperties, (_, disposers) => {\r\n $array.each(disposers, (disposer) => {\r\n disposer.dispose();\r\n });\r\n });\r\n const id = this.get(\"id\");\r\n if (id) {\r\n delete registry.entitiesById[id];\r\n }\r\n }\r\n /**\r\n * Creates and returns a \"disposable\" timeout.\r\n *\r\n * @param fn Callback\r\n * @param delay Delay in milliseconds\r\n * @return Timeout disposer\r\n */\r\n setTimeout(fn, delay) {\r\n const id = setTimeout(() => {\r\n this.removeDispose(disposer);\r\n fn();\r\n }, delay);\r\n const disposer = new Disposer(() => {\r\n clearTimeout(id);\r\n });\r\n this._disposers.push(disposer);\r\n return disposer;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n removeDispose(target) {\r\n if (!this.isDisposed()) {\r\n let index = $array.indexOf(this._disposers, target);\r\n if (index > -1) {\r\n this._disposers.splice(index, 1);\r\n }\r\n }\r\n target.dispose();\r\n }\r\n /**\r\n * @ignore\r\n */\r\n hasTag(tag) {\r\n return $array.indexOf(this.get(\"themeTags\", []), tag) !== -1;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n addTag(tag) {\r\n if (!this.hasTag(tag)) {\r\n const tags = this.get(\"themeTags\", []);\r\n tags.push(tag);\r\n this.set(\"themeTags\", tags);\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n removeTag(tag) {\r\n if (this.hasTag(tag)) {\r\n const tags = this.get(\"themeTags\", []);\r\n $array.remove(tags, tag);\r\n this.set(\"themeTags\", tags);\r\n }\r\n }\r\n _t(text, locale, ...rest) {\r\n return this._root.language.translate(text, locale, ...rest);\r\n }\r\n /**\r\n * An instance of [[Root]] object.\r\n *\r\n * @readonly\r\n * @since 5.0.6\r\n * @return Root object\r\n */\r\n get root() {\r\n return this._root;\r\n }\r\n}\r\nObject.defineProperty(Entity, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Entity\"\r\n});\r\nObject.defineProperty(Entity, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: [\"Entity\"]\r\n});\r\n//# sourceMappingURL=Entity.js.map","import { EventDispatcher } from \"./EventDispatcher\";\r\nimport { Disposer, MultiDisposer } from \"./Disposer\";\r\nimport * as $array from \"./Array\";\r\nimport * as $object from \"./Object\";\r\nimport * as $type from \"./Type\";\r\nfunction disposeSettings(settings) {\r\n $object.each(settings, (_key, value) => {\r\n if ($type.isObject(value) && typeof value.dispose === \"function\") {\r\n value.enableDispose = true;\r\n value.dispose();\r\n }\r\n });\r\n}\r\nexport class TemplateState {\r\n constructor(name, template, settings) {\r\n Object.defineProperty(this, \"_settings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_name\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_template\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._name = name;\r\n this._template = template;\r\n this._settings = settings;\r\n }\r\n _dispose() {\r\n disposeSettings(this._settings);\r\n }\r\n get(key, fallback) {\r\n const value = this._settings[key];\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n else {\r\n return fallback;\r\n }\r\n }\r\n set(key, value) {\r\n this._settings[key] = value;\r\n // TODO maybe only do this if the value changed ?\r\n this._template._stateChanged(this._name);\r\n }\r\n remove(key) {\r\n delete this._settings[key];\r\n // TODO maybe only do this if the value changed ?\r\n this._template._stateChanged(this._name);\r\n }\r\n setAll(settings) {\r\n $object.keys(settings).forEach((key) => {\r\n this._settings[key] = settings[key];\r\n });\r\n this._template._stateChanged(this._name);\r\n }\r\n _apply(other, seen) {\r\n $object.each(this._settings, (key, value) => {\r\n if (!seen[key] && !other._userSettings[key]) {\r\n seen[key] = true;\r\n other.setRaw(key, value);\r\n }\r\n });\r\n }\r\n}\r\nexport class TemplateStates {\r\n constructor(template) {\r\n Object.defineProperty(this, \"_template\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_states\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n this._template = template;\r\n }\r\n _dispose() {\r\n $object.each(this._states, (_key, state) => {\r\n state._dispose();\r\n });\r\n }\r\n lookup(name) {\r\n return this._states[name];\r\n }\r\n create(name, settings) {\r\n const state = this._states[name];\r\n if (state) {\r\n state.setAll(settings);\r\n return state;\r\n }\r\n else {\r\n const state = new TemplateState(name, this._template, settings);\r\n this._states[name] = state;\r\n this._template._stateChanged(name);\r\n return state;\r\n }\r\n }\r\n remove(name) {\r\n delete this._states[name];\r\n this._template._stateChanged(name);\r\n }\r\n _apply(entity, state) {\r\n $object.each(this._states, (key, value) => {\r\n let seen = state.states[key];\r\n if (seen == null) {\r\n seen = state.states[key] = {};\r\n }\r\n const other = entity.states.create(key, {});\r\n value._apply(other, seen);\r\n });\r\n }\r\n}\r\nexport class TemplateAdapters {\r\n constructor() {\r\n Object.defineProperty(this, \"_callbacks\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n }\r\n add(key, callback) {\r\n let callbacks = this._callbacks[key];\r\n if (callbacks === undefined) {\r\n callbacks = this._callbacks[key] = [];\r\n }\r\n callbacks.push(callback);\r\n return new Disposer(() => {\r\n $array.removeFirst(callbacks, callback);\r\n if (callbacks.length === 0) {\r\n delete this._callbacks[key];\r\n }\r\n });\r\n }\r\n remove(key) {\r\n const callbacks = this._callbacks[key];\r\n if (callbacks !== undefined) {\r\n delete this._callbacks[key];\r\n }\r\n }\r\n _apply(entity) {\r\n const disposers = [];\r\n $object.each(this._callbacks, (key, callbacks) => {\r\n $array.each(callbacks, (callback) => {\r\n disposers.push(entity.adapters.add(key, callback));\r\n });\r\n });\r\n return new MultiDisposer(disposers);\r\n }\r\n}\r\n// TODO maybe extend from Properties ?\r\nexport class Template {\r\n constructor(settings, isReal) {\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_settings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_privateSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n // TODO code duplication with Properties\r\n Object.defineProperty(this, \"_settingEvents\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_privateSettingEvents\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_entities\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"states\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new TemplateStates(this)\r\n });\r\n Object.defineProperty(this, \"adapters\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new TemplateAdapters()\r\n });\r\n Object.defineProperty(this, \"events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new EventDispatcher()\r\n });\r\n Object.defineProperty(this, \"setup\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n if (!isReal) {\r\n throw new Error(\"You cannot use `new Class()`, instead use `Class.new()`\");\r\n }\r\n this._settings = settings;\r\n }\r\n /**\r\n * Use this method to create an instance of this class.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/#New_element_syntax} for more info\r\n * @param root Root element\r\n * @param settings Settings\r\n * @param template Template\r\n * @return Instantiated object\r\n */\r\n static new(settings) {\r\n return new Template(settings, true);\r\n }\r\n _dispose() {\r\n disposeSettings(this._settings);\r\n disposeSettings(this._privateSettings);\r\n }\r\n /**\r\n * Returns `true` if this element is disposed.\r\n *\r\n * @return Disposed\r\n */\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n /**\r\n * Disposes this object.\r\n */\r\n dispose() {\r\n if (!this._disposed) {\r\n this._disposed = true;\r\n this._dispose();\r\n }\r\n }\r\n _checkDisposed() {\r\n if (this._disposed) {\r\n throw new Error(\"Template is disposed\");\r\n }\r\n }\r\n /**\r\n * Array of all entities using this template.\r\n */\r\n get entities() {\r\n return this._entities;\r\n }\r\n get(key, fallback) {\r\n this._checkDisposed();\r\n const value = this._settings[key];\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n else {\r\n return fallback;\r\n }\r\n }\r\n setRaw(key, value) {\r\n this._checkDisposed();\r\n this._settings[key] = value;\r\n }\r\n set(key, value) {\r\n this._checkDisposed();\r\n if (this._settings[key] !== value) {\r\n this.setRaw(key, value);\r\n this._entities.forEach((entity) => {\r\n entity._setTemplateProperty(this, key, value);\r\n });\r\n }\r\n }\r\n remove(key) {\r\n this._checkDisposed();\r\n if (key in this._settings) {\r\n delete this._settings[key];\r\n this._entities.forEach((entity) => {\r\n entity._removeTemplateProperty(key);\r\n });\r\n }\r\n }\r\n removeAll() {\r\n this._checkDisposed();\r\n $object.each(this._settings, (key, _value) => {\r\n this.remove(key);\r\n });\r\n }\r\n getPrivate(key, fallback) {\r\n this._checkDisposed();\r\n const value = this._privateSettings[key];\r\n if (value !== undefined) {\r\n return value;\r\n }\r\n else {\r\n return fallback;\r\n }\r\n }\r\n setPrivateRaw(key, value) {\r\n this._checkDisposed();\r\n this._privateSettings[key] = value;\r\n return value;\r\n }\r\n setPrivate(key, value) {\r\n this._checkDisposed();\r\n if (this._privateSettings[key] !== value) {\r\n this.setPrivateRaw(key, value);\r\n this._entities.forEach((entity) => {\r\n entity._setTemplatePrivateProperty(this, key, value);\r\n });\r\n }\r\n return value;\r\n }\r\n removePrivate(key) {\r\n this._checkDisposed();\r\n if (key in this._privateSettings) {\r\n delete this._privateSettings[key];\r\n this._entities.forEach((entity) => {\r\n entity._removeTemplatePrivateProperty(key);\r\n });\r\n }\r\n }\r\n setAll(value) {\r\n this._checkDisposed();\r\n $object.each(value, (key, value) => {\r\n this.set(key, value);\r\n });\r\n }\r\n // TODO code duplication with Properties\r\n on(key, callback) {\r\n this._checkDisposed();\r\n let events = this._settingEvents[key];\r\n if (events === undefined) {\r\n events = this._settingEvents[key] = [];\r\n }\r\n events.push(callback);\r\n return new Disposer(() => {\r\n $array.removeFirst(events, callback);\r\n if (events.length === 0) {\r\n delete this._settingEvents[key];\r\n }\r\n });\r\n }\r\n // TODO code duplication with Properties\r\n onPrivate(key, callback) {\r\n this._checkDisposed();\r\n let events = this._privateSettingEvents[key];\r\n if (events === undefined) {\r\n events = this._privateSettingEvents[key] = [];\r\n }\r\n events.push(callback);\r\n return new Disposer(() => {\r\n $array.removeFirst(events, callback);\r\n if (events.length === 0) {\r\n delete this._privateSettingEvents[key];\r\n }\r\n });\r\n }\r\n _apply(entity, state) {\r\n this._checkDisposed();\r\n const disposers = [];\r\n $object.each(this._settingEvents, (key, events) => {\r\n $array.each(events, (event) => {\r\n disposers.push(entity.on(key, event));\r\n });\r\n });\r\n $object.each(this._privateSettingEvents, (key, events) => {\r\n $array.each(events, (event) => {\r\n disposers.push(entity.onPrivate(key, event));\r\n });\r\n });\r\n this.states._apply(entity, state);\r\n disposers.push(this.adapters._apply(entity));\r\n disposers.push(entity.events.copyFrom(this.events));\r\n return new MultiDisposer(disposers);\r\n }\r\n _setObjectTemplate(entity) {\r\n this._checkDisposed();\r\n this._entities.push(entity);\r\n }\r\n _removeObjectTemplate(entity) {\r\n //this._checkDisposed();\r\n $array.remove(this._entities, entity);\r\n }\r\n _stateChanged(name) {\r\n this._checkDisposed();\r\n this._entities.forEach((entity) => {\r\n entity._applyStateByKey(name);\r\n });\r\n }\r\n}\r\n//# sourceMappingURL=Template.js.map","import { __awaiter } from \"tslib\";\r\nimport { Entity } from \"../util/Entity\";\r\nimport { Template } from \"../util/Template\";\r\nimport { Percent } from \"../util/Percent\";\r\nimport { EventDispatcher } from \"../util/EventDispatcher\";\r\nimport { MultiDisposer, CounterDisposer } from \"../util/Disposer\";\r\nimport { waitForAnimations } from \"../util/Animation\";\r\nimport * as $utils from \"../util/Utils\";\r\nimport * as $array from \"../util/Array\";\r\nimport * as $type from \"../util/Type\";\r\nimport * as $object from \"../util/Object\";\r\nimport * as $math from \"../util/Math\";\r\n//import { populateString } from \"../util/PopulateString\";\r\n/**\r\n * An [[EventDispatcher]] for [[Sprite]].\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/events/} for more info\r\n */\r\nclass SpriteEventDispatcher extends EventDispatcher {\r\n constructor(sprite) {\r\n super();\r\n Object.defineProperty(this, \"_sprite\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_rendererDisposers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_dispatchParents\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n this._sprite = sprite;\r\n }\r\n _makePointerEvent(key, event) {\r\n return {\r\n type: key,\r\n originalEvent: event.event,\r\n point: event.point,\r\n simulated: event.simulated,\r\n native: event.native,\r\n target: this._sprite\r\n };\r\n }\r\n _onRenderer(key, dispatch) {\r\n // TODO: is this OK? it'd be good not to require to set this on each individual element\r\n this._sprite.set(\"interactive\", true);\r\n this._sprite._display.interactive = true;\r\n let events = this._rendererDisposers[key];\r\n if (events === undefined) {\r\n const disposer = this._sprite._display.on(key, (e) => {\r\n dispatch.call(this, e);\r\n });\r\n events = this._rendererDisposers[key] = new CounterDisposer(() => {\r\n delete this._rendererDisposers[key];\r\n disposer.dispose();\r\n });\r\n }\r\n return events.increment();\r\n }\r\n _on(once, type, callback, context, shouldClone, dispatch) {\r\n const info = super._on(once, type, callback, context, shouldClone, dispatch);\r\n const rendererEvent = SpriteEventDispatcher.RENDERER_EVENTS[type];\r\n if (rendererEvent !== undefined) {\r\n info.disposer = new MultiDisposer([\r\n info.disposer,\r\n this._onRenderer(type, rendererEvent),\r\n ]);\r\n }\r\n return info;\r\n }\r\n /**\r\n * Will stop any bubbling up of the event to element's parents.\r\n *\r\n * Should be called in an event handler, e.g.:\r\n *\r\n * ```TypeScript\r\n * element.events.on(\"pointerdown\", function(ev) {\r\n * // Do something here and prevent from \"pointerdown\" bubbling up\r\n * // ...\r\n * ev.target.events.stopParentDispatch();\r\n * });\r\n * ```\r\n * ```JavaScript\r\n * element.events.on(\"pointerdown\", function(ev) {\r\n * // Do something here and prevent from \"pointerdown\" bubbling up\r\n * // ...\r\n * ev.target.events.stopParentDispatch();\r\n * });\r\n * ```\r\n */\r\n stopParentDispatch() {\r\n this._dispatchParents = false;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n dispatchParents(type, event) {\r\n const old = this._dispatchParents;\r\n this._dispatchParents = true;\r\n try {\r\n this.dispatch(type, event);\r\n if (this._dispatchParents && this._sprite.parent) {\r\n this._sprite.parent.events.dispatchParents(type, event);\r\n }\r\n }\r\n finally {\r\n this._dispatchParents = old;\r\n }\r\n }\r\n}\r\nObject.defineProperty(SpriteEventDispatcher, \"RENDERER_EVENTS\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {\r\n \"click\": function (event) {\r\n if (this.isEnabled(\"click\") && !this._sprite.isDragging() && this._sprite._hasDown() && !this._sprite._hasMoved(this._makePointerEvent(\"click\", event))) {\r\n this.dispatch(\"click\", this._makePointerEvent(\"click\", event));\r\n }\r\n },\r\n \"rightclick\": function (event) {\r\n if (this.isEnabled(\"rightclick\")) {\r\n this.dispatch(\"rightclick\", this._makePointerEvent(\"rightclick\", event));\r\n }\r\n },\r\n \"middleclick\": function (event) {\r\n if (this.isEnabled(\"middleclick\")) {\r\n this.dispatch(\"middleclick\", this._makePointerEvent(\"middleclick\", event));\r\n }\r\n },\r\n \"dblclick\": function (event) {\r\n this.dispatchParents(\"dblclick\", this._makePointerEvent(\"dblclick\", event));\r\n },\r\n \"pointerover\": function (event) {\r\n const sprite = this._sprite;\r\n let dispatch = true;\r\n if (sprite.getPrivate(\"trustBounds\")) {\r\n sprite._getBounds();\r\n const bounds = sprite.globalBounds();\r\n if (sprite.isType(\"Graphics\")) {\r\n const strokeWidth = sprite.get(\"strokeWidth\", 1) / 2;\r\n if (strokeWidth >= 1) {\r\n bounds.left -= strokeWidth;\r\n bounds.right += strokeWidth;\r\n bounds.top -= strokeWidth;\r\n bounds.bottom += strokeWidth;\r\n }\r\n }\r\n if (!$math.inBounds(event.point, bounds)) {\r\n dispatch = false;\r\n sprite._root._renderer.removeHovering(sprite._display);\r\n }\r\n }\r\n if (dispatch && this.isEnabled(\"pointerover\")) {\r\n this.dispatch(\"pointerover\", this._makePointerEvent(\"pointerover\", event));\r\n }\r\n },\r\n \"pointerout\": function (event) {\r\n if (this.isEnabled(\"pointerout\")) {\r\n this.dispatch(\"pointerout\", this._makePointerEvent(\"pointerout\", event));\r\n }\r\n },\r\n \"pointerdown\": function (event) {\r\n this.dispatchParents(\"pointerdown\", this._makePointerEvent(\"pointerdown\", event));\r\n },\r\n \"pointerup\": function (event) {\r\n if (this.isEnabled(\"pointerup\")) {\r\n this.dispatch(\"pointerup\", this._makePointerEvent(\"pointerup\", event));\r\n }\r\n },\r\n \"globalpointerup\": function (event) {\r\n if (this.isEnabled(\"globalpointerup\")) {\r\n this.dispatch(\"globalpointerup\", this._makePointerEvent(\"globalpointerup\", event));\r\n }\r\n },\r\n \"globalpointermove\": function (event) {\r\n if (this.isEnabled(\"globalpointermove\")) {\r\n this.dispatch(\"globalpointermove\", this._makePointerEvent(\"globalpointermove\", event));\r\n }\r\n },\r\n \"wheel\": function (event) {\r\n this.dispatchParents(\"wheel\", {\r\n type: \"wheel\",\r\n target: this._sprite,\r\n originalEvent: event.event,\r\n point: event.point,\r\n });\r\n },\r\n }\r\n});\r\n/**\r\n * A base class for all visual elements.\r\n *\r\n * @important\r\n */\r\nexport class Sprite extends Entity {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_adjustedLocalBounds\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: { left: 0, right: 0, top: 0, bottom: 0 }\r\n });\r\n Object.defineProperty(this, \"_localBounds\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: { left: 0, right: 0, top: 0, bottom: 0 }\r\n });\r\n Object.defineProperty(this, \"_parent\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_dataItem\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_templateField\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_sizeDirty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n // Will be true only when dragging\r\n Object.defineProperty(this, \"_isDragging\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n // The event when the dragging starts\r\n Object.defineProperty(this, \"_dragEvent\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n // The position when dragging starts\r\n Object.defineProperty(this, \"_dragPoint\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_isHidden\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_isShowing\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_isHiding\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_isDown\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_downPoint\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_downPoints\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_toggleDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_dragDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltipDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_hoverDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_focusDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltipMoveDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltipPointerDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_statesHandled\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n }\r\n _afterNew() {\r\n this.setPrivateRaw(\"visible\", true);\r\n super._afterNew();\r\n }\r\n /**\r\n * Marks some setting as dirty. Could be used to trigger adapter.\r\n * @param key\r\n */\r\n markDirtyKey(key) {\r\n this._markDirtyKey(key);\r\n }\r\n _markDirtyKey(key) {\r\n super._markDirtyKey(key);\r\n if (key == \"x\" || key == \"y\" || key == \"dx\" || key == \"dy\") {\r\n this.markDirtyBounds();\r\n this._addPercentagePositionChildren();\r\n this.markDirtyPosition();\r\n }\r\n }\r\n _markDirtyPrivateKey(key) {\r\n super._markDirtyPrivateKey(key);\r\n if (key == \"x\" || key == \"y\") {\r\n this.markDirtyPosition();\r\n }\r\n }\r\n _removeTemplateField() {\r\n if (this._templateField) {\r\n this._templateField._removeObjectTemplate(this);\r\n }\r\n }\r\n _createEvents() {\r\n return new SpriteEventDispatcher(this);\r\n }\r\n _processTemplateField() {\r\n let template;\r\n const field = this.get(\"templateField\");\r\n if (field) {\r\n const dataItem = this.dataItem;\r\n if (dataItem) {\r\n const context = dataItem.dataContext;\r\n if (context) {\r\n template = context[field];\r\n if (!(template instanceof Template) && template) {\r\n template = Template.new(template);\r\n }\r\n }\r\n }\r\n }\r\n if (this._templateField !== template) {\r\n this._removeTemplateField();\r\n this._templateField = template;\r\n if (template) {\r\n template._setObjectTemplate(this);\r\n }\r\n this._applyTemplates();\r\n }\r\n }\r\n // TODO change this to run before the element is added to the parent, so that way\r\n // it doesn't need to apply the themes twice\r\n _setDataItem(dataItem) {\r\n const oldDataItem = this._dataItem;\r\n this._dataItem = dataItem;\r\n this._processTemplateField();\r\n const eventType = \"dataitemchanged\";\r\n if (dataItem != oldDataItem) {\r\n if (this.events.isEnabled(eventType)) {\r\n this.events.dispatch(eventType, {\r\n type: eventType,\r\n target: this,\r\n oldDataItem: oldDataItem,\r\n newDataItem: dataItem\r\n });\r\n }\r\n }\r\n }\r\n /**\r\n * A [[DataItem]] used for this element.\r\n *\r\n * NOTE: data item is being assigned automatically in most cases where it\r\n * matters. Use this accessor to set data item only if you know what you're\r\n * doing.\r\n *\r\n * @param value Data item\r\n */\r\n set dataItem(value) {\r\n this._setDataItem(value);\r\n }\r\n /**\r\n * @return DataItem\r\n */\r\n get dataItem() {\r\n if (this._dataItem) {\r\n return this._dataItem;\r\n }\r\n else {\r\n let parent = this._parent;\r\n while (parent) {\r\n if (parent._dataItem) {\r\n return parent._dataItem;\r\n }\r\n else {\r\n parent = parent._parent;\r\n }\r\n }\r\n }\r\n }\r\n _addPercentageSizeChildren() {\r\n let parent = this.parent;\r\n if (parent) {\r\n if (this.get(\"width\") instanceof Percent || this.get(\"height\") instanceof Percent) {\r\n $array.pushOne(parent._percentageSizeChildren, this);\r\n }\r\n else {\r\n $array.removeFirst(parent._percentageSizeChildren, this);\r\n }\r\n }\r\n }\r\n _addPercentagePositionChildren() {\r\n let parent = this.parent;\r\n if (parent) {\r\n if (this.get(\"x\") instanceof Percent || this.get(\"y\") instanceof Percent) {\r\n $array.pushOne(parent._percentagePositionChildren, this);\r\n }\r\n else {\r\n $array.removeFirst(parent._percentagePositionChildren, this);\r\n }\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirtyPosition() {\r\n this._root._addDirtyPosition(this);\r\n }\r\n updatePivotPoint() {\r\n const bounds = this._localBounds;\r\n if (bounds) {\r\n const centerX = this.get(\"centerX\");\r\n if (centerX != null) {\r\n this._display.pivot.x = bounds.left + $utils.relativeToValue(centerX, bounds.right - bounds.left);\r\n }\r\n const centerY = this.get(\"centerY\");\r\n if (centerY != null) {\r\n this._display.pivot.y = bounds.top + $utils.relativeToValue(centerY, bounds.bottom - bounds.top);\r\n }\r\n }\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n // handling states in beforeChanged, otherwise states is not applied without animated theme\r\n this._handleStates();\r\n if (this.isDirty(\"tooltip\")) {\r\n const previous = this._prevSettings.tooltip;\r\n if (previous) {\r\n previous.dispose();\r\n }\r\n }\r\n if (this.isDirty(\"layer\") || this.isDirty(\"layerMargin\")) {\r\n this._display.setLayer(this.get(\"layer\"), this.get(\"layerMargin\"));\r\n this.markDirtyLayer();\r\n }\r\n if (this.isDirty(\"tooltipPosition\")) {\r\n const tooltipMoveDp = this._tooltipMoveDp;\r\n if (tooltipMoveDp) {\r\n tooltipMoveDp.dispose();\r\n this._tooltipMoveDp = undefined;\r\n }\r\n const tooltipPointerDp = this._tooltipPointerDp;\r\n if (tooltipPointerDp) {\r\n tooltipPointerDp.dispose();\r\n this._tooltipPointerDp = undefined;\r\n }\r\n if (this.get(\"tooltipPosition\") == \"pointer\") {\r\n if (this.isHover()) {\r\n this._tooltipMoveDp = this.events.on(\"globalpointermove\", (e) => {\r\n this.showTooltip(e.point);\r\n });\r\n }\r\n this._tooltipPointerDp = new MultiDisposer([\r\n this.events.on(\"pointerover\", () => {\r\n this._tooltipMoveDp = this.events.on(\"globalpointermove\", (e) => {\r\n this.showTooltip(e.point);\r\n });\r\n }),\r\n this.events.on(\"pointerout\", () => {\r\n const tooltipMoveDp = this._tooltipMoveDp;\r\n if (tooltipMoveDp) {\r\n tooltipMoveDp.dispose();\r\n this._tooltipMoveDp = undefined;\r\n }\r\n })\r\n ]);\r\n }\r\n }\r\n }\r\n _handleStates() {\r\n if (!this._statesHandled) {\r\n if (this.isDirty(\"active\")) {\r\n if (this.get(\"active\")) {\r\n this.states.applyAnimate(\"active\");\r\n this.set(\"ariaChecked\", true);\r\n }\r\n else {\r\n if (!this.isHidden()) {\r\n this.states.applyAnimate(\"default\");\r\n }\r\n this.set(\"ariaChecked\", false);\r\n }\r\n this.markDirtyAccessibility();\r\n }\r\n if (this.isDirty(\"disabled\")) {\r\n if (this.get(\"disabled\")) {\r\n this.states.applyAnimate(\"disabled\");\r\n this.set(\"ariaChecked\", false);\r\n }\r\n else {\r\n if (!this.isHidden()) {\r\n this.states.applyAnimate(\"default\");\r\n }\r\n this.set(\"ariaChecked\", true);\r\n }\r\n this.markDirtyAccessibility();\r\n }\r\n this._statesHandled = true;\r\n }\r\n }\r\n _changed() {\r\n super._changed();\r\n const display = this._display;\r\n const events = this.events;\r\n if (this.isDirty(\"draggable\")) {\r\n const draggable = this.get(\"draggable\");\r\n if (draggable) {\r\n this.set(\"interactive\", true);\r\n this._dragDp = new MultiDisposer([\r\n events.on(\"pointerdown\", (ev) => {\r\n this.dragStart(ev);\r\n }),\r\n events.on(\"globalpointermove\", (ev) => {\r\n this.dragMove(ev);\r\n }),\r\n events.on(\"globalpointerup\", (ev) => {\r\n this.dragStop(ev);\r\n })\r\n ]);\r\n }\r\n else {\r\n if (this._dragDp) {\r\n this._dragDp.dispose();\r\n this._dragDp = undefined;\r\n }\r\n }\r\n display.cancelTouch = draggable ? true : false;\r\n }\r\n if (this.isDirty(\"tooltipText\") || this.isDirty(\"tooltipHTML\") || this.isDirty(\"showTooltipOn\")) {\r\n const tooltipText = this.get(\"tooltipText\");\r\n const tooltipHTML = this.get(\"tooltipHTML\");\r\n const showTooltipOn = this.get(\"showTooltipOn\", \"hover\");\r\n if (this._tooltipDp) {\r\n this._tooltipDp.dispose();\r\n this._tooltipDp = undefined;\r\n }\r\n if (tooltipText || tooltipHTML) {\r\n if (showTooltipOn == \"click\") {\r\n this._tooltipDp = new MultiDisposer([\r\n events.on(\"click\", () => {\r\n this.setTimeout(() => {\r\n const tooltip = this.getTooltip();\r\n if (tooltip && !tooltip.isHidden() && tooltip.get(\"tooltipTarget\") === this) {\r\n this.hideTooltip();\r\n }\r\n else {\r\n this.showTooltip();\r\n }\r\n }, 10);\r\n }),\r\n $utils.addEventListener(document, \"click\", (_ev) => {\r\n this.hideTooltip();\r\n })\r\n ]);\r\n this._disposers.push(this._tooltipDp);\r\n }\r\n else if (showTooltipOn == \"always\") {\r\n // nothing\r\n }\r\n else {\r\n this._tooltipDp = new MultiDisposer([\r\n events.on(\"pointerover\", () => {\r\n this.showTooltip();\r\n }),\r\n events.on(\"pointerout\", () => {\r\n this.hideTooltip();\r\n })\r\n ]);\r\n this._disposers.push(this._tooltipDp);\r\n }\r\n }\r\n }\r\n if (this.isDirty(\"toggleKey\")) {\r\n let toggleKey = this.get(\"toggleKey\");\r\n if (toggleKey && toggleKey != \"none\") {\r\n this._toggleDp = events.on(\"click\", () => {\r\n if (!this._isDragging) {\r\n this.set(toggleKey, !this.get(toggleKey));\r\n }\r\n });\r\n }\r\n else {\r\n if (this._toggleDp) {\r\n this._toggleDp.dispose();\r\n this._toggleDp = undefined;\r\n }\r\n }\r\n }\r\n if (this.isDirty(\"opacity\")) {\r\n display.alpha = Math.max(0, this.get(\"opacity\", 1));\r\n if (this.get(\"focusable\")) {\r\n this.markDirtyAccessibility();\r\n }\r\n }\r\n if (this.isDirty(\"rotation\")) {\r\n this.markDirtyBounds();\r\n display.angle = this.get(\"rotation\", 0);\r\n }\r\n if (this.isDirty(\"scale\")) {\r\n this.markDirtyBounds();\r\n display.scale = this.get(\"scale\", 0);\r\n }\r\n if (this.isDirty(\"centerX\") || this.isDirty(\"centerY\")) {\r\n this.markDirtyBounds();\r\n this.updatePivotPoint();\r\n }\r\n if (this.isDirty(\"visible\") || this.isPrivateDirty(\"visible\") || this.isDirty(\"forceHidden\")) {\r\n if (!this.get(\"visible\") || !this.getPrivate(\"visible\") || this.get(\"forceHidden\")) {\r\n display.visible = false;\r\n this.hideTooltip();\r\n }\r\n else {\r\n display.visible = true;\r\n }\r\n this.markDirtyBounds();\r\n if (this.get(\"focusable\")) {\r\n this.markDirtyAccessibility();\r\n }\r\n }\r\n if (this.isDirty(\"width\") || this.isDirty(\"height\")) {\r\n this.markDirtyBounds();\r\n this._addPercentageSizeChildren();\r\n const parent = this.parent;\r\n if (parent) {\r\n if ((this.isDirty(\"width\") && this.get(\"width\") instanceof Percent) || (this.isDirty(\"height\") && this.get(\"height\") instanceof Percent)) {\r\n parent.markDirty();\r\n parent._prevWidth = 0;\r\n }\r\n }\r\n this._sizeDirty = true;\r\n }\r\n if (this.isDirty(\"maxWidth\") || this.isDirty(\"maxHeight\") || this.isPrivateDirty(\"width\") || this.isPrivateDirty(\"height\") || this.isDirty(\"minWidth\") || this.isDirty(\"minHeight\") || this.isPrivateDirty(\"maxWidth\") || this.isPrivateDirty(\"maxHeight\") || this.isPrivateDirty(\"minWidth\") || this.isPrivateDirty(\"minHeight\") || this.isDirty(\"marginLeft\") || this.isDirty(\"marginTop\") || this.isDirty(\"marginRight\") || this.isDirty(\"marginBottom\")) {\r\n this.markDirtyBounds();\r\n this._sizeDirty = true;\r\n }\r\n if (this._sizeDirty) {\r\n this._updateSize();\r\n }\r\n if (this.isDirty(\"wheelable\")) {\r\n const wheelable = this.get(\"wheelable\");\r\n if (wheelable) {\r\n this.set(\"interactive\", true);\r\n }\r\n display.wheelable = wheelable ? true : false;\r\n }\r\n // Accessibility\r\n if (this.isDirty(\"tabindexOrder\") || this.isDirty(\"focusableGroup\")) {\r\n if (this.get(\"focusable\")) {\r\n this._root._registerTabindexOrder(this);\r\n }\r\n else {\r\n this._root._unregisterTabindexOrder(this);\r\n }\r\n }\r\n if (this.isDirty(\"filter\")) {\r\n //this.markDirtyBounds();\r\n display.filter = this.get(\"filter\");\r\n }\r\n let filter = this.get(\"filter\", \"\");\r\n if (this.isDirty(\"blur\")) {\r\n const blur = this.get(\"blur\", 0);\r\n if (blur != 0) {\r\n filter += \" blur(\" + blur + \"px)\";\r\n }\r\n }\r\n if (this.isDirty(\"saturate\")) {\r\n const saturate = this.get(\"saturate\", 1);\r\n if (saturate != 1) {\r\n filter += \" saturate(\" + saturate + \")\";\r\n }\r\n }\r\n if (this.isDirty(\"brightness\")) {\r\n const brightness = this.get(\"brightness\", 1);\r\n if (brightness != 1) {\r\n filter += \" brightness(\" + brightness + \")\";\r\n }\r\n }\r\n if (this.isDirty(\"contrast\")) {\r\n const contrast = this.get(\"contrast\", 1);\r\n if (contrast != 1) {\r\n filter += \" contrast(\" + contrast + \")\";\r\n }\r\n }\r\n if (this.isDirty(\"sepia\")) {\r\n const sepia = this.get(\"sepia\", 0);\r\n if (sepia != 0) {\r\n filter += \" sepia(\" + sepia + \")\";\r\n }\r\n }\r\n if (this.isDirty(\"hue\")) {\r\n const hue = this.get(\"hue\", 0);\r\n if (hue != 0) {\r\n filter += \" hue-rotate(\" + hue + \"deg)\";\r\n }\r\n }\r\n if (this.isDirty(\"invert\")) {\r\n const invert = this.get(\"invert\", 0);\r\n if (invert != 0) {\r\n filter += \" invert(\" + invert + \")\";\r\n }\r\n }\r\n if (filter) {\r\n display.filter = filter;\r\n }\r\n if (this.isDirty(\"cursorOverStyle\")) {\r\n display.cursorOverStyle = this.get(\"cursorOverStyle\");\r\n }\r\n if (this.isDirty(\"hoverOnFocus\")) {\r\n if (this.get(\"hoverOnFocus\")) {\r\n this._focusDp = new MultiDisposer([\r\n events.on(\"focus\", () => {\r\n // TODO: proper hover, not just tooltip\r\n this.showTooltip();\r\n }),\r\n events.on(\"blur\", () => {\r\n // TODO: proper hover, not just tooltip\r\n this.hideTooltip();\r\n })\r\n ]);\r\n }\r\n else {\r\n if (this._focusDp) {\r\n this._focusDp.dispose();\r\n this._focusDp = undefined;\r\n }\r\n }\r\n }\r\n if (this.isDirty(\"focusable\")) {\r\n if (this.get(\"focusable\")) {\r\n this._root._registerTabindexOrder(this);\r\n }\r\n else {\r\n this._root._unregisterTabindexOrder(this);\r\n }\r\n this.markDirtyAccessibility();\r\n this._disposers.push(events.on(\"blur\", () => {\r\n this.setPrivateRaw(\"touchHovering\", false);\r\n }));\r\n }\r\n if (this.isPrivateDirty(\"focusable\")) {\r\n this.markDirtyAccessibility();\r\n }\r\n if (this.isDirty(\"role\") || this.isDirty(\"ariaLive\") || this.isDirty(\"ariaChecked\") || this.isDirty(\"ariaHidden\") || this.isDirty(\"ariaOrientation\") || this.isDirty(\"ariaValueNow\") || this.isDirty(\"ariaValueMin\") || this.isDirty(\"ariaValueMax\") || this.isDirty(\"ariaValueText\") || this.isDirty(\"ariaLabel\") || this.isDirty(\"ariaControls\")) {\r\n // display.accessibility.ariaLabel = populateString(this, this.get(\"ariaLabel\", \"\"));\r\n // @todo make sure ariaLabel gets populated in Root\r\n this.markDirtyAccessibility();\r\n }\r\n if (this.isDirty(\"exportable\")) {\r\n display.exportable = this.get(\"exportable\");\r\n }\r\n if (this.isDirty(\"interactive\")) {\r\n const events = this.events;\r\n if (this.get(\"interactive\") && !events.isDisposed()) {\r\n this._hoverDp = new MultiDisposer([\r\n events.on(\"click\", (ev) => {\r\n if ($utils.isTouchEvent(ev.originalEvent)) {\r\n if (!this.getPrivate(\"touchHovering\")) {\r\n this.setTimeout(() => {\r\n this._handleOver();\r\n if (this.get(\"tooltipText\") || this.get(\"tooltipHTML\")) {\r\n this.showTooltip();\r\n }\r\n this.setPrivateRaw(\"touchHovering\", true);\r\n this.events.dispatch(\"pointerover\", {\r\n type: \"pointerover\",\r\n target: ev.target,\r\n originalEvent: ev.originalEvent,\r\n point: ev.point,\r\n simulated: ev.simulated\r\n });\r\n }, 10);\r\n }\r\n }\r\n }),\r\n events.on(\"globalpointerup\", (ev) => {\r\n if ($utils.isTouchEvent(ev.originalEvent)) {\r\n if (this.getPrivate(\"touchHovering\")) {\r\n this._handleOut();\r\n if (this.get(\"tooltipText\") || this.get(\"tooltipHTML\")) {\r\n this.hideTooltip();\r\n }\r\n this.setPrivateRaw(\"touchHovering\", false);\r\n this.events.dispatch(\"pointerout\", {\r\n type: \"pointerout\",\r\n target: ev.target,\r\n originalEvent: ev.originalEvent,\r\n point: ev.point,\r\n simulated: ev.simulated\r\n });\r\n }\r\n }\r\n if (this._isDown) {\r\n this._handleUp(ev);\r\n }\r\n //this._isDown = false;\r\n }),\r\n events.on(\"pointerover\", () => {\r\n this._handleOver();\r\n }),\r\n events.on(\"pointerout\", () => {\r\n this._handleOut();\r\n }),\r\n events.on(\"pointerdown\", (e) => {\r\n this._handleDown(e);\r\n })\r\n ]);\r\n }\r\n else {\r\n this._display.interactive = false;\r\n if (this._hoverDp) {\r\n this._hoverDp.dispose();\r\n this._hoverDp = undefined;\r\n }\r\n }\r\n }\r\n if (this.isDirty(\"forceInactive\")) {\r\n this._display.inactive = this.get(\"forceInactive\", null);\r\n }\r\n if (this.get(\"showTooltipOn\") == \"always\" && this._display.visible) {\r\n this.showTooltip();\r\n }\r\n }\r\n /**\r\n * @ignore\r\n * @todo should this be user-accessible?\r\n */\r\n dragStart(e) {\r\n this._dragEvent = e;\r\n this.events.stopParentDispatch();\r\n }\r\n /**\r\n * @ignore\r\n * @todo should this be user-accessible?\r\n */\r\n dragStop(e) {\r\n this._dragEvent = undefined;\r\n this._dragPoint = undefined;\r\n this.events.stopParentDispatch();\r\n if (this._isDragging) {\r\n this._isDragging = false;\r\n const type = \"dragstop\";\r\n if (this.events.isEnabled(type)) {\r\n this.events.dispatch(type, {\r\n type: type,\r\n target: this,\r\n originalEvent: e.originalEvent,\r\n point: e.point,\r\n simulated: e.simulated,\r\n });\r\n }\r\n }\r\n }\r\n _handleOver() {\r\n if (!this.isHidden()) {\r\n if (this.get(\"active\") && this.states.lookup(\"hoverActive\")) {\r\n this.states.applyAnimate(\"hoverActive\");\r\n }\r\n else if (this.get(\"disabled\") && this.states.lookup(\"hoverDisabled\")) {\r\n this.states.applyAnimate(\"hoverDisabled\");\r\n }\r\n else {\r\n this.states.applyAnimate(\"hover\");\r\n }\r\n if (this.get(\"draggable\") && this._isDown && this.states.lookup(\"down\")) {\r\n this.states.applyAnimate(\"down\");\r\n }\r\n }\r\n }\r\n _handleOut() {\r\n if (!this.isHidden()) {\r\n if (this.get(\"active\") && this.states.lookup(\"active\")) {\r\n this.states.applyAnimate(\"active\");\r\n }\r\n else if (this.get(\"disabled\") && this.states.lookup(\"disabled\")) {\r\n this.states.applyAnimate(\"disabled\");\r\n }\r\n else {\r\n if (this.states.lookup(\"hover\") || this.states.lookup(\"hoverActive\")) {\r\n this.states.applyAnimate(\"default\");\r\n }\r\n }\r\n if (this.get(\"draggable\") && this._isDown && this.states.lookup(\"down\")) {\r\n this.states.applyAnimate(\"down\");\r\n }\r\n }\r\n }\r\n _handleUp(e) {\r\n if (!this.isHidden()) {\r\n if (this.get(\"active\") && this.states.lookup(\"active\")) {\r\n this.states.applyAnimate(\"active\");\r\n }\r\n else if (this.get(\"disabled\") && this.states.lookup(\"disabled\")) {\r\n this.states.applyAnimate(\"disabled\");\r\n }\r\n else if (this.states.lookup(\"down\")) {\r\n if (this.isHover()) {\r\n this.states.applyAnimate(\"hover\");\r\n }\r\n else {\r\n this.states.applyAnimate(\"default\");\r\n }\r\n }\r\n // @todo remove this once migrated to _downPoints\r\n this._downPoint = undefined;\r\n const pointerId = $utils.getPointerId(e.originalEvent);\r\n delete this._downPoints[pointerId];\r\n if ($object.keys(this._downPoints).length == 0) {\r\n this._isDown = false;\r\n }\r\n }\r\n }\r\n _hasMoved(e) {\r\n // @todo remove this once migrated to _downPoints\r\n // if (this._downPoint) {\r\n // \tconst x = Math.abs(this._downPoint.x - e.point.x);\r\n // \tconst y = Math.abs(this._downPoint.y - e.point.y);\r\n // \treturn (x > 5) || (y > 5);\r\n // }\r\n const pointerId = $utils.getPointerId(e.originalEvent);\r\n const downPoint = this._downPoints[pointerId];\r\n if (downPoint) {\r\n const x = Math.abs(downPoint.x - e.point.x);\r\n const y = Math.abs(downPoint.y - e.point.y);\r\n return (x > 5) || (y > 5);\r\n }\r\n return false;\r\n }\r\n _hasDown() {\r\n return $object.keys(this._downPoints).length > 0;\r\n }\r\n _handleDown(e) {\r\n const parent = this.parent;\r\n if (parent && !this.get(\"draggable\")) {\r\n parent._handleDown(e);\r\n }\r\n if (this.get(\"interactive\") && !this.isHidden()) {\r\n if (this.states.lookup(\"down\")) {\r\n this.states.applyAnimate(\"down\");\r\n }\r\n this._downPoint = {\r\n x: e.point.x,\r\n y: e.point.y\r\n };\r\n // @todo remove this once migrated to _downPoints\r\n this._isDown = true;\r\n const pointerId = $utils.getPointerId(e.originalEvent);\r\n this._downPoints[pointerId] = {\r\n x: e.point.x,\r\n y: e.point.y\r\n };\r\n }\r\n }\r\n /**\r\n * @ignore\r\n * @todo should this be user-accessible?\r\n */\r\n dragMove(e) {\r\n let dragEvent = this._dragEvent;\r\n if (dragEvent) {\r\n if (dragEvent.simulated && !e.simulated) {\r\n return true;\r\n }\r\n let angle = 0;\r\n let parent = this.parent;\r\n let scale = 1;\r\n while (parent != null) {\r\n angle += parent.get(\"rotation\", 0);\r\n parent = parent.parent;\r\n if (parent) {\r\n scale *= parent.get(\"scale\", 1);\r\n }\r\n }\r\n let x = (e.point.x - dragEvent.point.x) / scale;\r\n let y = (e.point.y - dragEvent.point.y) / scale;\r\n const events = this.events;\r\n if (dragEvent.simulated && !this._isDragging) {\r\n this._isDragging = true;\r\n this._dragEvent = e;\r\n this._dragPoint = {\r\n x: this.x(),\r\n y: this.y()\r\n };\r\n const type = \"dragstart\";\r\n if (events.isEnabled(type)) {\r\n events.dispatch(type, {\r\n type: type,\r\n target: this,\r\n originalEvent: e.originalEvent,\r\n point: e.point,\r\n simulated: e.simulated,\r\n });\r\n }\r\n }\r\n if (this._isDragging) {\r\n let dragPoint = this._dragPoint;\r\n this.set(\"x\", dragPoint.x + x * $math.cos(angle) + y * $math.sin(angle));\r\n this.set(\"y\", dragPoint.y + y * $math.cos(angle) - x * $math.sin(angle));\r\n const type = \"dragged\";\r\n if (events.isEnabled(type)) {\r\n events.dispatch(type, {\r\n type: type,\r\n target: this,\r\n originalEvent: e.originalEvent,\r\n point: e.point,\r\n simulated: e.simulated,\r\n });\r\n }\r\n }\r\n else {\r\n if (Math.hypot(x, y) > 5) {\r\n this._isDragging = true;\r\n this._dragEvent = e;\r\n this._dragPoint = {\r\n x: this.x(),\r\n y: this.y()\r\n };\r\n const type = \"dragstart\";\r\n if (events.isEnabled(type)) {\r\n events.dispatch(type, {\r\n type: type,\r\n target: this,\r\n originalEvent: e.originalEvent,\r\n point: e.point,\r\n simulated: e.simulated\r\n });\r\n }\r\n }\r\n }\r\n }\r\n }\r\n _updateSize() {\r\n }\r\n _getBounds() {\r\n this._localBounds = this._display.getLocalBounds();\r\n }\r\n /**\r\n * Returns depth (how deep in the hierachy of the content tree) of this\r\n * element.\r\n *\r\n * @return Depth\r\n */\r\n depth() {\r\n let self = this.parent;\r\n let depth = 0;\r\n while (true) {\r\n if (self) {\r\n ++depth;\r\n self = self.parent;\r\n }\r\n else {\r\n return depth;\r\n }\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirtySize() {\r\n this._sizeDirty = true;\r\n this.markDirty();\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirtyBounds() {\r\n const display = this._display;\r\n if (this.get(\"isMeasured\")) {\r\n this._root._addDirtyBounds(this);\r\n display.isMeasured = true;\r\n display.invalidateBounds();\r\n const parent = this.parent;\r\n if (parent && this.get(\"position\") != \"absolute\") {\r\n if (parent.get(\"width\") == null || parent.get(\"height\") == null || parent.get(\"layout\")) {\r\n parent.markDirtyBounds();\r\n }\r\n }\r\n if (this.get(\"focusable\") && this.isFocus()) {\r\n this.markDirtyAccessibility();\r\n }\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirtyAccessibility() {\r\n //if (this._root.focused(this)) {\r\n this._root._invalidateAccessibility(this);\r\n //}\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirtyLayer() {\r\n //this._display.markDirtyLayer(this.isDirty(\"opacity\") || this.isDirty(\"visible\")); https://codepen.io/team/amcharts/pen/gOWZPmP <- problems\r\n this._display.markDirtyLayer(true);\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirty() {\r\n super.markDirty();\r\n this.markDirtyLayer();\r\n }\r\n _updateBounds() {\r\n const oldBounds = this._adjustedLocalBounds;\r\n let newBounds;\r\n // if display.visible == false, it still returns bounds\r\n if (!this.get(\"visible\") || !this.getPrivate(\"visible\") || this.get(\"forceHidden\")) {\r\n newBounds = {\r\n left: 0,\r\n right: 0,\r\n top: 0,\r\n bottom: 0\r\n };\r\n this._localBounds = newBounds;\r\n this._adjustedLocalBounds = newBounds;\r\n }\r\n else {\r\n this._getBounds();\r\n this._fixMinBounds(this._localBounds);\r\n this.updatePivotPoint();\r\n this._adjustedLocalBounds = this._display.getAdjustedBounds(this._localBounds);\r\n newBounds = this._adjustedLocalBounds;\r\n }\r\n if (!oldBounds || (oldBounds.left !== newBounds.left || oldBounds.top !== newBounds.top || oldBounds.right !== newBounds.right || oldBounds.bottom !== newBounds.bottom)) {\r\n const eventType = \"boundschanged\";\r\n if (this.events.isEnabled(eventType)) {\r\n this.events.dispatch(eventType, { type: eventType, target: this });\r\n }\r\n if (this.parent) {\r\n this.parent.markDirty();\r\n this.parent.markDirtyBounds();\r\n }\r\n // Update tooltip position together with the Sprite\r\n if (this.getPrivate(\"showingTooltip\")) {\r\n this.showTooltip();\r\n }\r\n }\r\n }\r\n _fixMinBounds(bounds) {\r\n let minWidth = this.get(\"minWidth\", this.getPrivate(\"minWidth\"));\r\n let minHeight = this.get(\"minHeight\", this.getPrivate(\"minHeight\"));\r\n if ($type.isNumber(minWidth)) {\r\n if (bounds.right - bounds.left < minWidth) {\r\n bounds.right = bounds.left + minWidth;\r\n }\r\n }\r\n if ($type.isNumber(minHeight)) {\r\n if (bounds.bottom - bounds.top < minHeight) {\r\n bounds.bottom = bounds.top + minHeight;\r\n }\r\n }\r\n let privateWidth = this.getPrivate(\"width\");\r\n let privateHeight = this.getPrivate(\"height\");\r\n if ($type.isNumber(privateWidth)) {\r\n if (privateWidth > 0) {\r\n bounds.right = bounds.left + privateWidth;\r\n }\r\n else {\r\n bounds.left = bounds.right + privateWidth;\r\n }\r\n }\r\n if ($type.isNumber(privateHeight)) {\r\n if (privateHeight > 0) {\r\n bounds.bottom = bounds.top + privateHeight;\r\n }\r\n else {\r\n bounds.top = bounds.bottom + privateHeight;\r\n }\r\n }\r\n }\r\n _removeParent(parent) {\r\n if (parent) {\r\n parent.children.removeValue(this);\r\n $array.removeFirst(parent._percentageSizeChildren, this);\r\n $array.removeFirst(parent._percentagePositionChildren, this);\r\n }\r\n }\r\n _clearDirty() {\r\n super._clearDirty();\r\n this._sizeDirty = false;\r\n this._statesHandled = false;\r\n }\r\n /**\r\n * Simulate hover over element.\r\n */\r\n hover() {\r\n if (!this.isDisposed()) {\r\n this.showTooltip();\r\n this._handleOver();\r\n }\r\n }\r\n /**\r\n * Simulate unhover over element.\r\n */\r\n unhover() {\r\n if (!this.isDisposed()) {\r\n this.hideTooltip();\r\n this._handleOut();\r\n }\r\n }\r\n /**\r\n * Shows element's [[Tooltip]].\r\n */\r\n showTooltip(point) {\r\n if (!this.isDisposed()) {\r\n const tooltip = this.getTooltip();\r\n const tooltipText = this.get(\"tooltipText\");\r\n const tooltipHTML = this.get(\"tooltipHTML\");\r\n if ((tooltipText || tooltipHTML) && tooltip) {\r\n const tooltipPosition = this.get(\"tooltipPosition\");\r\n const tooltipTarget = this.getPrivate(\"tooltipTarget\", this);\r\n if (tooltipPosition == \"fixed\" || !point) {\r\n this._display._setMatrix();\r\n point = this.toGlobal(tooltipTarget._getTooltipPoint());\r\n }\r\n tooltip.set(\"pointTo\", point);\r\n tooltip.set(\"tooltipTarget\", tooltipTarget);\r\n if (!tooltip.get(\"x\")) {\r\n tooltip.set(\"x\", point.x);\r\n }\r\n if (!tooltip.get(\"y\")) {\r\n tooltip.set(\"y\", point.y);\r\n }\r\n if (tooltipText) {\r\n tooltip.label.set(\"text\", tooltipText);\r\n }\r\n if (tooltipHTML) {\r\n tooltip.label.set(\"html\", tooltipHTML);\r\n }\r\n const dataItem = this.dataItem;\r\n if (dataItem) {\r\n tooltip.label._setDataItem(dataItem);\r\n }\r\n if (this.get(\"showTooltipOn\") == \"always\" && (point.x < 0 || point.x > this._root.width() || point.y < 0 || point.y > this._root.height())) {\r\n this.hideTooltip();\r\n return;\r\n }\r\n tooltip.label.text.markDirtyText();\r\n const promise = tooltip.show();\r\n this.setPrivateRaw(\"showingTooltip\", true);\r\n return promise;\r\n }\r\n }\r\n }\r\n /**\r\n * Hides element's [[Tooltip]].\r\n */\r\n hideTooltip() {\r\n const tooltip = this.getTooltip();\r\n if (tooltip) {\r\n if (tooltip.get(\"tooltipTarget\") == this.getPrivate(\"tooltipTarget\", this) || this.get(\"tooltip\") == tooltip) {\r\n let timeout = tooltip.get(\"keepTargetHover\") && tooltip.get(\"stateAnimationDuration\", 0) == 0 ? 400 : undefined;\r\n const promise = tooltip.hide(timeout);\r\n this.setPrivateRaw(\"showingTooltip\", false);\r\n return promise;\r\n }\r\n }\r\n }\r\n _getTooltipPoint() {\r\n const bounds = this._localBounds;\r\n if (bounds) {\r\n let x = 0;\r\n let y = 0;\r\n if (!this.get(\"isMeasured\")) {\r\n x = $utils.relativeToValue(this.get(\"tooltipX\", 0), this.width());\r\n y = $utils.relativeToValue(this.get(\"tooltipY\", 0), this.height());\r\n }\r\n else {\r\n x = bounds.left + $utils.relativeToValue(this.get(\"tooltipX\", 0), bounds.right - bounds.left);\r\n y = bounds.top + $utils.relativeToValue(this.get(\"tooltipY\", 0), bounds.bottom - bounds.top);\r\n }\r\n return { x, y };\r\n }\r\n return { x: 0, y: 0 };\r\n }\r\n /**\r\n * Returns [[Tooltip]] used for this element.\r\n *\r\n * @return Tooltip\r\n */\r\n getTooltip() {\r\n let tooltip = this.get(\"tooltip\");\r\n if (!tooltip) {\r\n let parent = this.parent;\r\n if (parent) {\r\n return parent.getTooltip();\r\n }\r\n }\r\n else {\r\n return tooltip;\r\n }\r\n }\r\n _updatePosition() {\r\n const parent = this.parent;\r\n let dx = this.get(\"dx\", 0);\r\n let dy = this.get(\"dy\", 0);\r\n let x = this.get(\"x\");\r\n let _x = this.getPrivate(\"x\");\r\n let xx = 0;\r\n let yy = 0;\r\n const position = this.get(\"position\");\r\n if (x instanceof Percent) {\r\n if (parent) {\r\n x = parent.innerWidth() * x.value + parent.get(\"paddingLeft\", 0);\r\n }\r\n else {\r\n x = 0;\r\n }\r\n }\r\n if ($type.isNumber(x)) {\r\n xx = x + dx;\r\n }\r\n else {\r\n if (_x != null) {\r\n xx = _x;\r\n }\r\n else if (parent) {\r\n if (position == \"relative\") {\r\n xx = parent.get(\"paddingLeft\", 0) + dx;\r\n }\r\n }\r\n }\r\n let y = this.get(\"y\");\r\n let _y = this.getPrivate(\"y\");\r\n if (y instanceof Percent) {\r\n if (parent) {\r\n y = parent.innerHeight() * y.value + parent.get(\"paddingTop\", 0);\r\n }\r\n else {\r\n y = 0;\r\n }\r\n }\r\n if ($type.isNumber(y)) {\r\n yy = y + dy;\r\n }\r\n else {\r\n if (_y != null) {\r\n yy = _y;\r\n }\r\n else if (parent) {\r\n if (position == \"relative\") {\r\n yy = parent.get(\"paddingTop\", 0) + dy;\r\n }\r\n }\r\n }\r\n const display = this._display;\r\n if (display.x != xx || display.y != yy) {\r\n display.invalidateBounds();\r\n display.x = xx;\r\n display.y = yy;\r\n const eventType = \"positionchanged\";\r\n if (this.events.isEnabled(eventType)) {\r\n this.events.dispatch(eventType, { type: eventType, target: this });\r\n }\r\n }\r\n // Update tooltip position together with the Sprite\r\n if (this.getPrivate(\"showingTooltip\")) {\r\n this.showTooltip();\r\n }\r\n }\r\n /**\r\n * Returns element's actual X position in pixels.\r\n *\r\n * @return X (px)\r\n */\r\n x() {\r\n let x = this.get(\"x\");\r\n let _x = this.getPrivate(\"x\");\r\n const parent = this.parent;\r\n if (parent) {\r\n if (x instanceof Percent) {\r\n return $utils.relativeToValue(x, parent.innerWidth()) + parent.get(\"paddingLeft\", 0);\r\n }\r\n else {\r\n if (!$type.isNumber(x)) {\r\n if (_x != null) {\r\n return _x;\r\n }\r\n else {\r\n return parent.get(\"paddingLeft\", this._display.x);\r\n }\r\n }\r\n else {\r\n return x;\r\n }\r\n }\r\n }\r\n return this._display.x;\r\n }\r\n /**\r\n * Returns element's actual Y position in pixels.\r\n *\r\n * @return Y (px)\r\n */\r\n y() {\r\n let _y = this.getPrivate(\"y\");\r\n if (_y != null) {\r\n return _y;\r\n }\r\n let y = this.get(\"y\");\r\n const parent = this.parent;\r\n if (parent) {\r\n if (y instanceof Percent) {\r\n return $utils.relativeToValue(y, parent.innerHeight()) + parent.get(\"paddingTop\", 0);\r\n }\r\n else {\r\n if (!$type.isNumber(y)) {\r\n if (_y != null) {\r\n return _y;\r\n }\r\n else {\r\n return parent.get(\"paddingTop\", this._display.y);\r\n }\r\n }\r\n else {\r\n return y;\r\n }\r\n }\r\n }\r\n return this._display.y;\r\n }\r\n _dispose() {\r\n super._dispose();\r\n this._display.dispose();\r\n this._removeTemplateField();\r\n this._removeParent(this.parent);\r\n this._root._removeFocusElement(this);\r\n const tooltip = this.get(\"tooltip\");\r\n if (tooltip) {\r\n tooltip.dispose();\r\n }\r\n this.markDirty();\r\n }\r\n /**\r\n * @ignore\r\n */\r\n adjustedLocalBounds() {\r\n this._fixMinBounds(this._adjustedLocalBounds);\r\n return this._adjustedLocalBounds;\r\n }\r\n /**\r\n * Returns local coordinates of the element's bounds.\r\n *\r\n * @ignore\r\n * @return Global bounds\r\n */\r\n localBounds() {\r\n return this._localBounds;\r\n }\r\n /**\r\n * Returns adjusted local coordinates of the element's bounds.\r\n *\r\n * @ignore\r\n * @return Global bounds\r\n */\r\n bounds() {\r\n const bounds = this._adjustedLocalBounds;\r\n const x = this.x();\r\n const y = this.y();\r\n return { left: bounds.left + x, right: bounds.right + x, top: bounds.top + y, bottom: bounds.bottom + y };\r\n }\r\n /**\r\n * Returns global coordinates of the element's bounds.\r\n *\r\n * @ignore\r\n * @return Global bounds\r\n */\r\n globalBounds() {\r\n const bounds = this.localBounds();\r\n const p0 = this.toGlobal({ x: bounds.left, y: bounds.top });\r\n const p1 = this.toGlobal({ x: bounds.right, y: bounds.top });\r\n const p2 = this.toGlobal({ x: bounds.right, y: bounds.bottom });\r\n const p3 = this.toGlobal({ x: bounds.left, y: bounds.bottom });\r\n return {\r\n left: Math.min(p0.x, p1.x, p2.x, p3.x),\r\n top: Math.min(p0.y, p1.y, p2.y, p3.y),\r\n right: Math.max(p0.x, p1.x, p2.x, p3.x),\r\n bottom: Math.max(p0.y, p1.y, p2.y, p3.y)\r\n };\r\n }\r\n _onShow(_duration) {\r\n }\r\n _onHide(_duration) {\r\n }\r\n /**\r\n * Plays initial reveal animation regardless if element is currently hidden\r\n * or visible.\r\n *\r\n * @param duration Duration of the animation in milliseconds\r\n * @param delay Delay showing of the element by X milliseconds\r\n * @return Promise\r\n */\r\n appear(duration, delay) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n yield this.hide(0);\r\n if (delay) {\r\n return new Promise((success, _error) => {\r\n this.setTimeout(() => {\r\n success(this.show(duration));\r\n }, delay);\r\n });\r\n }\r\n else {\r\n return this.show(duration);\r\n }\r\n });\r\n }\r\n /**\r\n * Shows currently hidden element and returns a `Promise` which completes\r\n * when all showing animations are finished.\r\n *\r\n * ```TypeScript\r\n * series.show().then(function(ev) {\r\n * console.log(\"Series is now fully visible\");\r\n * })\r\n * ```\r\n * ```JavaScript\r\n * series.show().then(function(ev) {\r\n * console.log(\"Series is now fully visible\");\r\n * })\r\n * ```\r\n *\r\n * @return Promise\r\n */\r\n show(duration) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n if (!this._isShowing) {\r\n this._isHidden = false;\r\n this._isShowing = true;\r\n this._isHiding = false;\r\n if (this.states.lookup(\"default\").get(\"visible\")) {\r\n this.set(\"visible\", true);\r\n }\r\n this._onShow(duration);\r\n const animations = this.states.applyAnimate(\"default\", duration);\r\n yield waitForAnimations(animations);\r\n this._isShowing = false;\r\n }\r\n });\r\n }\r\n /**\r\n * Hides the element and returns a `Promise` which completes when all hiding\r\n * animations are finished.\r\n *\r\n * ```TypeScript\r\n * series.hide().then(function(ev) {\r\n * console.log(\"Series finished hiding\");\r\n * })\r\n * ```\r\n * ```JavaScript\r\n * series.hide().then(function(ev) {\r\n * console.log(\"Series finished hiding\");\r\n * })\r\n * ```\r\n *\r\n * @return Promise\r\n */\r\n hide(duration) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n if (!this._isHiding && !this._isHidden) {\r\n this._isHiding = true;\r\n this._isShowing = false;\r\n let state = this.states.lookup(\"hidden\");\r\n if (!state) {\r\n state = this.states.create(\"hidden\", {\r\n \"opacity\": 0,\r\n \"visible\": false\r\n });\r\n }\r\n this._isHidden = true;\r\n this._onHide(duration);\r\n const animations = this.states.applyAnimate(\"hidden\", duration);\r\n yield waitForAnimations(animations);\r\n this._isHiding = false;\r\n }\r\n });\r\n }\r\n /**\r\n * Returns `true` if this element is currently hidden.\r\n *\r\n * @return Is hidden?\r\n */\r\n isHidden() {\r\n return this._isHidden;\r\n }\r\n /**\r\n * Returns `true` if this element is currently animating to a default state.\r\n *\r\n * @return Is showing?\r\n */\r\n isShowing() {\r\n return this._isShowing;\r\n }\r\n /**\r\n * Returns `true` if this element is currently animating to a hidden state.\r\n *\r\n * @return Is hiding?\r\n */\r\n isHiding() {\r\n return this._isHiding;\r\n }\r\n /**\r\n * Returns `true` if this element is currently hovered by a pointer.\r\n *\r\n * @return Is hovered?\r\n */\r\n isHover() {\r\n return this._display.hovering();\r\n }\r\n /**\r\n * Returns `true` if this element does currently have focus.\r\n *\r\n * @return Is focused?\r\n */\r\n isFocus() {\r\n return this._root.focused(this);\r\n }\r\n /**\r\n * Returns `true` if this element is currently being dragged.\r\n *\r\n * @return Is dragged?\r\n */\r\n isDragging() {\r\n return this._isDragging;\r\n }\r\n /**\r\n * Returns `false` if if either public or private setting `visible` is set\r\n * to `false`, or `forceHidden` is set to `true`.\r\n *\r\n * @return Visible?\r\n */\r\n isVisible() {\r\n if (this.get(\"visible\") && this.getPrivate(\"visible\") && !this.get(\"forceHidden\")) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Same as `isVisible()`, except it checks all ascendants, too.\r\n *\r\n * @since 5.2.7\r\n * @return Visible?\r\n */\r\n isVisibleDeep() {\r\n return this._parent ? (this._parent.isVisibleDeep() && this.isVisible()) : this.isVisible();\r\n }\r\n /**\r\n * Returns an actual opacity of the element, taking into account all parents.\r\n *\r\n * @return Opacity\r\n * @since 5.2.11\r\n */\r\n compositeOpacity() {\r\n const opacity = this.get(\"opacity\", 1);\r\n return this._parent ? (this._parent.compositeOpacity() * opacity) : opacity;\r\n }\r\n /**\r\n * Returns an actual scale of the element, taking into account all parents.\r\n *\r\n * @return Opacity\r\n * @since 5.9.2\r\n */\r\n compositeScale() {\r\n const scale = this.get(\"scale\", 1);\r\n return this._parent ? (this._parent.compositeScale() * scale) : scale;\r\n }\r\n /**\r\n * Returns an actual roation of the element, taking into account all parents.\r\n *\r\n * @return Opacity\r\n * @since 5.9.2\r\n */\r\n compositeRotation() {\r\n const rotation = this.get(\"rotation\", 0);\r\n return this._parent ? (this._parent.compositeRotation() + rotation) : rotation;\r\n }\r\n /**\r\n * Returns width of this element in pixels.\r\n *\r\n * @return Width (px)\r\n */\r\n width() {\r\n let width = this.get(\"width\");\r\n let maxWidth = this.get(\"maxWidth\", this.getPrivate(\"maxWidth\"));\r\n let minWidth = this.get(\"minWidth\", this.getPrivate(\"minWidth\"));\r\n let privateWidth = this.getPrivate(\"width\");\r\n let w = 0;\r\n if ($type.isNumber(privateWidth)) {\r\n w = privateWidth;\r\n }\r\n else {\r\n if (width == null) {\r\n if (this._adjustedLocalBounds) {\r\n w = this._adjustedLocalBounds.right - this._adjustedLocalBounds.left;\r\n }\r\n }\r\n else {\r\n if (width instanceof Percent) {\r\n const parent = this.parent;\r\n if (parent) {\r\n w = parent.innerWidth() * width.value;\r\n }\r\n else {\r\n w = this._root.width() * width.value;\r\n }\r\n }\r\n else if ($type.isNumber(width)) {\r\n w = width;\r\n }\r\n }\r\n }\r\n if ($type.isNumber(minWidth)) {\r\n w = Math.max(minWidth, w);\r\n }\r\n if ($type.isNumber(maxWidth)) {\r\n w = Math.min(maxWidth, w);\r\n }\r\n return w;\r\n }\r\n /**\r\n * Returns maximum allowed width of this element in pixels.\r\n *\r\n * @return Maximum width (px)\r\n */\r\n maxWidth() {\r\n let maxWidth = this.get(\"maxWidth\", this.getPrivate(\"maxWidth\"));\r\n if ($type.isNumber(maxWidth)) {\r\n return maxWidth;\r\n }\r\n else {\r\n let width = this.get(\"width\");\r\n if ($type.isNumber(width)) {\r\n return width;\r\n }\r\n }\r\n const parent = this.parent;\r\n if (parent) {\r\n return parent.innerWidth();\r\n }\r\n return this._root.width();\r\n }\r\n /**\r\n * Returns maximum allowed height of this element in pixels.\r\n *\r\n * @return Maximum height (px)\r\n */\r\n maxHeight() {\r\n let maxHeight = this.get(\"maxHeight\", this.getPrivate(\"maxHeight\"));\r\n if ($type.isNumber(maxHeight)) {\r\n return maxHeight;\r\n }\r\n else {\r\n let height = this.get(\"height\");\r\n if ($type.isNumber(height)) {\r\n return height;\r\n }\r\n }\r\n const parent = this.parent;\r\n if (parent) {\r\n return parent.innerHeight();\r\n }\r\n return this._root.height();\r\n }\r\n /**\r\n * Returns height of this element in pixels.\r\n *\r\n * @return Height (px)\r\n */\r\n height() {\r\n let height = this.get(\"height\");\r\n let maxHeight = this.get(\"maxHeight\", this.getPrivate(\"maxHeight\"));\r\n let minHeight = this.get(\"minHeight\", this.getPrivate(\"minHeight\"));\r\n let privateHeight = this.getPrivate(\"height\");\r\n let h = 0;\r\n if ($type.isNumber(privateHeight)) {\r\n h = privateHeight;\r\n }\r\n else {\r\n if (height == null) {\r\n if (this._adjustedLocalBounds) {\r\n h = this._adjustedLocalBounds.bottom - this._adjustedLocalBounds.top;\r\n }\r\n }\r\n else {\r\n if (height instanceof Percent) {\r\n const parent = this.parent;\r\n if (parent) {\r\n h = parent.innerHeight() * height.value;\r\n }\r\n else {\r\n h = this._root.height() * height.value;\r\n }\r\n }\r\n else if ($type.isNumber(height)) {\r\n h = height;\r\n }\r\n }\r\n }\r\n if ($type.isNumber(minHeight)) {\r\n h = Math.max(minHeight, h);\r\n }\r\n if ($type.isNumber(maxHeight)) {\r\n h = Math.min(maxHeight, h);\r\n }\r\n return h;\r\n }\r\n _findStaticTemplate(f) {\r\n // templateField overrides template\r\n if (this._templateField && f(this._templateField)) {\r\n return this._templateField;\r\n }\r\n return super._findStaticTemplate(f);\r\n }\r\n _walkParents(f) {\r\n if (this._parent) {\r\n this._walkParent(f);\r\n }\r\n }\r\n _walkParent(f) {\r\n if (this._parent) {\r\n this._parent._walkParent(f);\r\n }\r\n f(this);\r\n }\r\n /**\r\n * Parent [[Container]] of this element.\r\n *\r\n * @return Parent container\r\n */\r\n get parent() {\r\n return this._parent;\r\n }\r\n _setParent(parent, updateChildren = false) {\r\n const prevParent = this._parent;\r\n if (parent !== prevParent) {\r\n this.markDirtyBounds();\r\n parent.markDirty();\r\n this._parent = parent;\r\n if (updateChildren) {\r\n this._removeParent(prevParent);\r\n if (parent) {\r\n this._addPercentageSizeChildren();\r\n this._addPercentagePositionChildren();\r\n }\r\n }\r\n this.markDirtyPosition();\r\n this._applyThemes();\r\n }\r\n }\r\n /**\r\n * Returns an instance of [[NumberFormatter]] used in this element.\r\n *\r\n * If this element does not have it set, global one form [[Root]] is used.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/using-formatters/} for more info\r\n * @return NumberFormatter instace\r\n */\r\n getNumberFormatter() {\r\n return this.get(\"numberFormatter\", this._root.numberFormatter);\r\n }\r\n /**\r\n * Returns an instance of [[DateFormatter]] used in this element.\r\n *\r\n * If this element does not have it set, global one form [[Root]] is used.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/using-formatters/} for more info\r\n * @return DateFormatter instace\r\n */\r\n getDateFormatter() {\r\n return this.get(\"dateFormatter\", this._root.dateFormatter);\r\n }\r\n /**\r\n * Returns an instance of [[DurationFormatter]] used in this element.\r\n *\r\n * If this element does not have it set, global one form [[Root]] is used.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/using-formatters/} for more info\r\n * @return DurationFormatter instace\r\n */\r\n getDurationFormatter() {\r\n return this.get(\"durationFormatter\", this._root.durationFormatter);\r\n }\r\n /**\r\n * Converts X/Y coordinate within this element to a global coordinate.\r\n *\r\n * @param point Local coordinate\r\n * @return Global coordinate\r\n */\r\n toGlobal(point) {\r\n return this._display.toGlobal(point);\r\n }\r\n /**\r\n * Converts global X/Y coordinate to a coordinate within this element.\r\n *\r\n * @param point Global coordinate\r\n * @return Local coordinate\r\n */\r\n toLocal(point) {\r\n return this._display.toLocal(point);\r\n }\r\n _getDownPoint() {\r\n const id = this._getDownPointId();\r\n if (id) {\r\n return this._downPoints[id];\r\n }\r\n }\r\n _getDownPointId() {\r\n if (this._downPoints) {\r\n return $object.keysOrdered(this._downPoints, (a, b) => {\r\n if (a > b) {\r\n return 1;\r\n }\r\n if (a < b) {\r\n return -1;\r\n }\r\n return 0;\r\n })[0];\r\n }\r\n }\r\n /**\r\n * Moves sprite to the end of the parent's children array.\r\n *\r\n * Depending on `layout` setting of the parten container, it may effect the\r\n * positioning or overlapping order of the elements.\r\n */\r\n toFront() {\r\n const parent = this.parent;\r\n if (parent) {\r\n parent.children.moveValue(this, parent.children.length - 1);\r\n }\r\n }\r\n /**\r\n * Moves sprite to the beginning of the parent's children array.\r\n *\r\n * Depending on `layout` setting of the parten container, it may effect the\r\n * positioning or overlapping order of the elements.\r\n */\r\n toBack() {\r\n const parent = this.parent;\r\n if (parent) {\r\n parent.children.moveValue(this, 0);\r\n }\r\n }\r\n}\r\nObject.defineProperty(Sprite, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Sprite\"\r\n});\r\nObject.defineProperty(Sprite, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Entity.classNames.concat([Sprite.className])\r\n});\r\n//# sourceMappingURL=Sprite.js.map","import { Entity } from \"../../util/Entity\";\r\n/**\r\n * Base class for patterns.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/patterns/} for more info\r\n */\r\nexport class Pattern extends Entity {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_display\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._root._renderer.makeGraphics()\r\n });\r\n Object.defineProperty(this, \"_backgroundDisplay\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._root._renderer.makeGraphics()\r\n });\r\n Object.defineProperty(this, \"_clear\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_pattern\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n _afterNew() {\r\n // Applying themes because pattern will not have parent\r\n super._afterNewApplyThemes();\r\n }\r\n get pattern() {\r\n return this._pattern;\r\n }\r\n _draw() { }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n if (this.isDirty(\"repetition\") || this.isDirty(\"width\") || this.isDirty(\"height\") || this.isDirty(\"rotation\") || this.isDirty(\"strokeWidth\") || this.isDirty(\"strokeDasharray\") || this.isDirty(\"strokeDashoffset\") || this.isDirty(\"colorOpacity\") || this.isDirty(\"fillOpacity\")) {\r\n this._clear = true;\r\n }\r\n this._checkDirtyFill();\r\n }\r\n _checkDirtyFill() {\r\n if (this.isDirty(\"color\") || this.isDirty(\"fill\")) {\r\n this._clear = true;\r\n }\r\n }\r\n _changed() {\r\n super._changed();\r\n if (this._clear) {\r\n const repetition = this.get(\"repetition\", \"\");\r\n const width = this.get(\"width\", 100);\r\n const height = this.get(\"height\", 100);\r\n const fill = this.get(\"fill\");\r\n const fillOpacity = this.get(\"fillOpacity\", 1);\r\n const backgroundDisplay = this._backgroundDisplay;\r\n const display = this._display;\r\n display.clear();\r\n backgroundDisplay.clear();\r\n if (fill && (fillOpacity > 0)) {\r\n backgroundDisplay.beginFill(fill, fillOpacity);\r\n backgroundDisplay.drawRect(0, 0, width, height);\r\n backgroundDisplay.endFill();\r\n }\r\n display.angle = this.get(\"rotation\", 0);\r\n //display.pivot = { x: width / 2, y: height / 2 };\r\n this._draw();\r\n this._pattern = this._root._renderer.createPattern(display, backgroundDisplay, repetition, width, height);\r\n }\r\n this._clear = false;\r\n }\r\n}\r\nObject.defineProperty(Pattern, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Pattern\"\r\n});\r\nObject.defineProperty(Pattern, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Entity.classNames.concat([Pattern.className])\r\n});\r\n//# sourceMappingURL=Pattern.js.map","import { Pattern } from \"./Pattern\";\r\n/**\r\n * Picture pattern.\r\n *\r\n * @since 5.2.15\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/patterns/} for more info\r\n */\r\nexport class PicturePattern extends Pattern {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_image\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n this._clear = true;\r\n if (this.isDirty(\"src\")) {\r\n this._load();\r\n }\r\n const canvas = this.get(\"canvas\");\r\n if (canvas) {\r\n this.set(\"width\", canvas.width);\r\n this.set(\"height\", canvas.height);\r\n }\r\n }\r\n _draw() {\r\n super._draw();\r\n const image = this._image;\r\n if (image) {\r\n const patternWidth = this.get(\"width\", 100);\r\n const patternHeight = this.get(\"height\", 100);\r\n // Fit\r\n const fit = this.get(\"fit\", \"image\");\r\n let width = 0;\r\n let height = 0;\r\n if (fit == \"pattern\") {\r\n width = patternWidth;\r\n height = patternHeight;\r\n }\r\n else {\r\n width = image.width;\r\n height = image.height;\r\n if (fit == \"image\") {\r\n this.set(\"width\", width);\r\n this.set(\"height\", height);\r\n }\r\n }\r\n // Position\r\n const centered = this.get(\"centered\", true);\r\n let x = 0;\r\n let y = 0;\r\n if (centered) {\r\n x = patternWidth / 2 - width / 2;\r\n y = patternHeight / 2 - height / 2;\r\n }\r\n this._display.image(image, width, height, x, y);\r\n }\r\n const canvas = this.get(\"canvas\");\r\n if (canvas) {\r\n this._display.image(canvas, canvas.width, canvas.height, 0, 0);\r\n }\r\n }\r\n _load() {\r\n const src = this.get(\"src\");\r\n if (src) {\r\n const image = new Image();\r\n //image.crossOrigin = \"Anonymous\";\r\n image.src = src;\r\n image.decode().then(() => {\r\n this._image = image;\r\n this._draw();\r\n if (this.events.isEnabled(\"loaded\")) {\r\n this.events.dispatch(\"loaded\", { type: \"loaded\", target: this });\r\n }\r\n }).catch((_error) => {\r\n // TODO: maybe raise error?\r\n });\r\n }\r\n }\r\n}\r\nObject.defineProperty(PicturePattern, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"PicturePattern\"\r\n});\r\nObject.defineProperty(PicturePattern, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Pattern.classNames.concat([PicturePattern.className])\r\n});\r\n//# sourceMappingURL=PicturePattern.js.map","/**\r\n * From https://github.com/pixijs/pixi.js/blob/3dd0ff9a935f0bc13a09aefff9eb2872f02c51b9/packages/canvas/canvas-renderer/src/utils/mapCanvasBlendModesToPixi.ts#L13\r\n */\r\nexport var BlendMode;\r\n(function (BlendMode) {\r\n BlendMode[\"ADD\"] = \"lighter\";\r\n BlendMode[\"COLOR\"] = \"color\";\r\n BlendMode[\"COLOR_BURN\"] = \"color-burn\";\r\n BlendMode[\"COLOR_DODGE\"] = \"color-dodge\";\r\n BlendMode[\"DARKEN\"] = \"darken\";\r\n BlendMode[\"DIFFERENCE\"] = \"difference\";\r\n BlendMode[\"DST_OVER\"] = \"destination-over\";\r\n BlendMode[\"EXCLUSION\"] = \"exclusion\";\r\n BlendMode[\"HARD_LIGHT\"] = \"hard-light\";\r\n BlendMode[\"HUE\"] = \"hue\";\r\n BlendMode[\"LIGHTEN\"] = \"lighten\";\r\n BlendMode[\"LUMINOSITY\"] = \"luminosity\";\r\n BlendMode[\"MULTIPLY\"] = \"multiply\";\r\n BlendMode[\"NORMAL\"] = \"source-over\";\r\n BlendMode[\"OVERLAY\"] = \"overlay\";\r\n BlendMode[\"SATURATION\"] = \"saturation\";\r\n BlendMode[\"SCREEN\"] = \"screen\";\r\n BlendMode[\"SOFT_LIGHT\"] = \"soft-light\";\r\n BlendMode[\"SRC_ATOP\"] = \"source-atop\";\r\n BlendMode[\"XOR\"] = \"xor\";\r\n})(BlendMode || (BlendMode = {}));\r\n//# sourceMappingURL=Renderer.js.map","import { PicturePattern } from \"../render/patterns/PicturePattern\";\r\nimport { Sprite } from \"./Sprite\";\r\nimport { BlendMode } from \"./backend/Renderer\";\r\nimport * as $type from \"../util/Type\";\r\nimport * as $array from \"../util/Array\";\r\nexport const visualSettings = [\"fill\", \"fillOpacity\", \"stroke\", \"strokeWidth\", \"strokeOpacity\", \"fillPattern\", \"strokePattern\", \"fillGradient\", \"strokeGradient\", \"strokeDasharray\", \"strokeDashoffset\", \"shadowBlur\", \"shadowColor\", \"shadowOpacity\", \"shadowOffsetX\", \"shadowOffsetY\", \"blur\", \"sepia\", \"invert\", \"brightness\", \"hue\", \"contrast\", \"saturate\"];\r\n/**\r\n * Base class used for drawing shapes.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/graphics/} for more info\r\n * @important\r\n */\r\nexport class Graphics extends Sprite {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_display\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._root._renderer.makeGraphics()\r\n });\r\n Object.defineProperty(this, \"_clear\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n if (this.isDirty(\"draw\") || this.isDirty(\"svgPath\")) {\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"fill\") || this.isDirty(\"stroke\") || this.isDirty(\"visible\") || this.isDirty(\"forceHidden\") || this.isDirty(\"scale\") || this.isDirty(\"fillGradient\") || this.isDirty(\"strokeGradient\") || this.isDirty(\"fillPattern\") || this.isDirty(\"strokePattern\") || this.isDirty(\"fillOpacity\") || this.isDirty(\"strokeOpacity\") || this.isDirty(\"strokeWidth\") || this.isDirty(\"draw\") || this.isDirty(\"blendMode\") || this.isDirty(\"strokeDasharray\") || this.isDirty(\"strokeDashoffset\") || this.isDirty(\"svgPath\") || this.isDirty(\"lineJoin\") || this.isDirty(\"shadowColor\") || this.isDirty(\"shadowBlur\") || this.isDirty(\"shadowOffsetX\") || this.isDirty(\"shadowOffsetY\")) {\r\n this._clear = true;\r\n }\r\n this._display.crisp = this.get(\"crisp\", false);\r\n if (this.isDirty(\"fillGradient\")) {\r\n const gradient = this.get(\"fillGradient\");\r\n if (gradient) {\r\n this._display.isMeasured = true;\r\n const gradientTarget = gradient.get(\"target\");\r\n if (gradientTarget) {\r\n this._disposers.push(gradientTarget.events.on(\"boundschanged\", () => {\r\n this._markDirtyKey(\"fill\");\r\n }));\r\n this._disposers.push(gradientTarget.events.on(\"positionchanged\", () => {\r\n this._markDirtyKey(\"fill\");\r\n }));\r\n }\r\n }\r\n }\r\n if (this.isDirty(\"strokeGradient\")) {\r\n const gradient = this.get(\"strokeGradient\");\r\n if (gradient) {\r\n this._display.isMeasured = true;\r\n const gradientTarget = gradient.get(\"target\");\r\n if (gradientTarget) {\r\n this._disposers.push(gradientTarget.events.on(\"boundschanged\", () => {\r\n this._markDirtyKey(\"stroke\");\r\n }));\r\n this._disposers.push(gradientTarget.events.on(\"positionchanged\", () => {\r\n this._markDirtyKey(\"stroke\");\r\n }));\r\n }\r\n }\r\n }\r\n }\r\n _changed() {\r\n super._changed();\r\n if (this._clear) {\r\n this.markDirtyBounds();\r\n this.markDirtyLayer();\r\n this._display.clear();\r\n let strokeDasharray = this.get(\"strokeDasharray\");\r\n if ($type.isNumber(strokeDasharray)) {\r\n if (strokeDasharray < 0.5) {\r\n strokeDasharray = [0];\r\n }\r\n else {\r\n strokeDasharray = [strokeDasharray];\r\n }\r\n }\r\n this._display.setLineDash(strokeDasharray);\r\n const strokeDashoffset = this.get(\"strokeDashoffset\");\r\n if (strokeDashoffset) {\r\n this._display.setLineDashOffset(strokeDashoffset);\r\n }\r\n const blendMode = this.get(\"blendMode\", BlendMode.NORMAL);\r\n this._display.blendMode = blendMode;\r\n const draw = this.get(\"draw\");\r\n if (draw && typeof draw === \"function\") {\r\n draw(this._display, this);\r\n }\r\n const svgPath = this.get(\"svgPath\");\r\n if (svgPath != null) {\r\n this._display.svgPath(svgPath);\r\n }\r\n }\r\n }\r\n _afterChanged() {\r\n super._afterChanged();\r\n if (this._clear) {\r\n const fill = this.get(\"fill\");\r\n const fillGradient = this.get(\"fillGradient\");\r\n const fillPattern = this.get(\"fillPattern\");\r\n const fillOpacity = this.get(\"fillOpacity\");\r\n const stroke = this.get(\"stroke\");\r\n const strokeGradient = this.get(\"strokeGradient\");\r\n const strokePattern = this.get(\"strokePattern\");\r\n const shadowColor = this.get(\"shadowColor\");\r\n const shadowBlur = this.get(\"shadowBlur\");\r\n const shadowOffsetX = this.get(\"shadowOffsetX\");\r\n const shadowOffsetY = this.get(\"shadowOffsetY\");\r\n const shadowOpacity = this.get(\"shadowOpacity\");\r\n if (shadowColor && (shadowBlur || shadowOffsetX || shadowOffsetY)) {\r\n this._display.shadow(shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY, shadowOpacity);\r\n }\r\n if (fill && !fillGradient) {\r\n this._display.beginFill(fill, fillOpacity);\r\n this._display.endFill();\r\n }\r\n if (fillGradient) {\r\n if (fill) {\r\n const stops = fillGradient.get(\"stops\", []);\r\n if (stops.length) {\r\n $array.each(stops, (stop) => {\r\n if ((!stop.color || stop.colorInherited) && fill) {\r\n stop.color = fill;\r\n stop.colorInherited = true;\r\n }\r\n if (stop.opacity == null || stop.opacityInherited) {\r\n stop.opacity = fillOpacity;\r\n stop.opacityInherited = true;\r\n }\r\n });\r\n }\r\n }\r\n const gradient = fillGradient.getFill(this);\r\n if (gradient) {\r\n this._display.beginFill(gradient, fillOpacity);\r\n this._display.endFill();\r\n }\r\n }\r\n if (fillPattern) {\r\n const pattern = fillPattern.pattern;\r\n if (pattern) {\r\n this._display.beginFill(pattern, fillOpacity);\r\n this._display.endFill();\r\n if (fillPattern instanceof PicturePattern) {\r\n fillPattern.events.once(\"loaded\", () => {\r\n this._clear = true;\r\n this.markDirty();\r\n });\r\n }\r\n }\r\n }\r\n if (stroke || strokeGradient || strokePattern) {\r\n const strokeOpacity = this.get(\"strokeOpacity\");\r\n let strokeWidth = this.get(\"strokeWidth\", 1);\r\n if (this.get(\"nonScalingStroke\")) {\r\n strokeWidth = strokeWidth / this.get(\"scale\", 1);\r\n }\r\n if (this.get(\"crisp\")) {\r\n strokeWidth /= this._root._renderer.resolution;\r\n }\r\n const lineJoin = this.get(\"lineJoin\");\r\n if (stroke && !strokeGradient) {\r\n this._display.lineStyle(strokeWidth, stroke, strokeOpacity, lineJoin);\r\n this._display.endStroke();\r\n }\r\n if (strokeGradient) {\r\n const stops = strokeGradient.get(\"stops\", []);\r\n if (stops.length) {\r\n $array.each(stops, (stop) => {\r\n if ((!stop.color || stop.colorInherited) && stroke) {\r\n stop.color = stroke;\r\n stop.colorInherited = true;\r\n }\r\n if (stop.opacity == null || stop.opacityInherited) {\r\n stop.opacity = strokeOpacity;\r\n stop.opacityInherited = true;\r\n }\r\n });\r\n }\r\n const gradient = strokeGradient.getFill(this);\r\n if (gradient) {\r\n this._display.lineStyle(strokeWidth, gradient, strokeOpacity, lineJoin);\r\n this._display.endStroke();\r\n }\r\n }\r\n if (strokePattern) {\r\n /*\r\n let changed = false;\r\n \r\n if (stroke && (!strokePattern.get(\"color\") || strokePattern.get(\"colorInherited\"))) {\r\n strokePattern.set(\"color\", stroke);\r\n strokePattern.set(\"colorInherited\", true);\r\n changed = true;\r\n }\r\n if (changed) {\r\n // @todo: is this OK?\r\n strokePattern._changed();\r\n }\r\n */\r\n let pattern = strokePattern.pattern;\r\n if (pattern) {\r\n this._display.lineStyle(strokeWidth, pattern, strokeOpacity, lineJoin);\r\n this._display.endStroke();\r\n if (strokePattern instanceof PicturePattern) {\r\n strokePattern.events.once(\"loaded\", () => {\r\n this._clear = true;\r\n this.markDirty();\r\n });\r\n }\r\n }\r\n }\r\n }\r\n if (this.getPrivate(\"showingTooltip\")) {\r\n this.showTooltip();\r\n }\r\n }\r\n this._clear = false;\r\n }\r\n}\r\nObject.defineProperty(Graphics, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Graphics\"\r\n});\r\nObject.defineProperty(Graphics, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Sprite.classNames.concat([Graphics.className])\r\n});\r\n//# sourceMappingURL=Graphics.js.map","import { Graphics } from \"./Graphics\";\r\n/**\r\n * Draws a rectangle.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/graphics/} for more info\r\n * @important\r\n */\r\nexport class Rectangle extends Graphics {\r\n _afterNew() {\r\n super._afterNew();\r\n this._display.isMeasured = true;\r\n this.setPrivateRaw(\"trustBounds\", true);\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n if (this.isDirty(\"width\") || this.isDirty(\"height\") || this.isPrivateDirty(\"width\") || this.isPrivateDirty(\"height\")) {\r\n this._clear = true;\r\n }\r\n }\r\n _changed() {\r\n super._changed();\r\n if (this._clear && !this.get(\"draw\")) {\r\n this._draw();\r\n }\r\n }\r\n _draw() {\r\n this._display.drawRect(0, 0, this.width(), this.height());\r\n }\r\n _updateSize() {\r\n this.markDirty();\r\n this._clear = true;\r\n }\r\n}\r\nObject.defineProperty(Rectangle, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Rectangle\"\r\n});\r\nObject.defineProperty(Rectangle, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Graphics.classNames.concat([Rectangle.className])\r\n});\r\n//# sourceMappingURL=Rectangle.js.map","import { Entity } from \"../util/Entity\";\r\nexport function eachChildren(container, f) {\r\n if (container.get(\"reverseChildren\", false)) {\r\n container.children.eachReverse(f);\r\n }\r\n else {\r\n container.children.each(f);\r\n }\r\n}\r\n/**\r\n * Base class for [[Container]] layouts.\r\n */\r\nexport class Layout extends Entity {\r\n}\r\nObject.defineProperty(Layout, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Layout\"\r\n});\r\nObject.defineProperty(Layout, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Entity.classNames.concat([Layout.className])\r\n});\r\n//# sourceMappingURL=Layout.js.map","import { Layout, eachChildren } from \"./Layout\";\r\nimport * as $type from \"../util/Type\";\r\nimport { Percent } from \"../util/Percent\";\r\n/**\r\n * A horizontal children layout for [[Container]].\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/containers/#Layout} for more info\r\n */\r\nexport class HorizontalLayout extends Layout {\r\n /**\r\n * @ignore\r\n */\r\n updateContainer(container) {\r\n let paddingLeft = container.get(\"paddingLeft\", 0);\r\n let availableWidth = container.innerWidth();\r\n let totalPercent = 0;\r\n eachChildren(container, (child) => {\r\n if (child.isVisible()) {\r\n if (child.get(\"position\") == \"relative\") {\r\n let childWidth = child.get(\"width\");\r\n if (childWidth instanceof Percent) {\r\n totalPercent += childWidth.value;\r\n let w = availableWidth * childWidth.value;\r\n let minWidth = child.get(\"minWidth\", child.getPrivate(\"minWidth\", -Infinity));\r\n if (minWidth > w) {\r\n availableWidth -= minWidth;\r\n totalPercent -= childWidth.value;\r\n }\r\n let maxWidth = child.get(\"maxWidth\", child.getPrivate(\"maxWidth\", Infinity));\r\n if (w > maxWidth) {\r\n availableWidth -= maxWidth;\r\n totalPercent -= childWidth.value;\r\n }\r\n }\r\n else {\r\n if (!$type.isNumber(childWidth)) {\r\n childWidth = child.width();\r\n }\r\n availableWidth -= childWidth + child.get(\"marginLeft\", 0) + child.get(\"marginRight\", 0);\r\n }\r\n }\r\n }\r\n });\r\n if (availableWidth <= 0 || availableWidth == Infinity) {\r\n availableWidth = .1;\r\n }\r\n //if (availableWidth > 0) {\r\n eachChildren(container, (child) => {\r\n if (child.isVisible()) {\r\n if (child.get(\"position\") == \"relative\") {\r\n let childWidth = child.get(\"width\");\r\n if (childWidth instanceof Percent) {\r\n let privateWidth = availableWidth * childWidth.value / totalPercent - child.get(\"marginLeft\", 0) - child.get(\"marginRight\", 0);\r\n let minWidth = child.get(\"minWidth\", child.getPrivate(\"minWidth\", -Infinity));\r\n let maxWidth = child.get(\"maxWidth\", child.getPrivate(\"maxWidth\", Infinity));\r\n privateWidth = Math.min(Math.max(minWidth, privateWidth), maxWidth);\r\n child.setPrivate(\"width\", privateWidth);\r\n }\r\n else {\r\n if (child._prevSettings.width instanceof Percent) {\r\n child.setPrivate(\"width\", undefined);\r\n }\r\n }\r\n }\r\n }\r\n });\r\n //}\r\n let prevX = paddingLeft;\r\n eachChildren(container, (child) => {\r\n if (child.get(\"position\") == \"relative\") {\r\n if (child.isVisible()) {\r\n let bounds = child.adjustedLocalBounds();\r\n let marginLeft = child.get(\"marginLeft\", 0);\r\n let marginRight = child.get(\"marginRight\", 0);\r\n let maxWidth = child.get(\"maxWidth\");\r\n let left = bounds.left;\r\n let right = bounds.right;\r\n if (maxWidth) {\r\n if (right - left > maxWidth) {\r\n right = left + maxWidth;\r\n }\r\n }\r\n let x = prevX + marginLeft - left;\r\n child.setPrivate(\"x\", x);\r\n prevX = x + right + marginRight;\r\n }\r\n else {\r\n child.setPrivate(\"x\", undefined);\r\n }\r\n }\r\n });\r\n }\r\n}\r\nObject.defineProperty(HorizontalLayout, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"HorizontalLayout\"\r\n});\r\nObject.defineProperty(HorizontalLayout, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Layout.classNames.concat([HorizontalLayout.className])\r\n});\r\n//# sourceMappingURL=HorizontalLayout.js.map","import { Layout, eachChildren } from \"./Layout\";\r\nimport * as $type from \"../util/Type\";\r\nimport { Percent } from \"../util/Percent\";\r\n/**\r\n * A vertical children layout for [[Container]].\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/containers/#Layout} for more info\r\n */\r\nexport class VerticalLayout extends Layout {\r\n /**\r\n * @ignore\r\n */\r\n updateContainer(container) {\r\n let paddingTop = container.get(\"paddingTop\", 0);\r\n let availableHeight = container.innerHeight();\r\n let totalPercent = 0;\r\n eachChildren(container, (child) => {\r\n if (child.isVisible()) {\r\n if (child.get(\"position\") == \"relative\") {\r\n let childHeight = child.get(\"height\");\r\n if (childHeight instanceof Percent) {\r\n totalPercent += childHeight.value;\r\n let h = availableHeight * childHeight.value;\r\n let minHeight = child.get(\"minHeight\", child.getPrivate(\"minHeight\", -Infinity));\r\n if (minHeight > h) {\r\n availableHeight -= minHeight;\r\n totalPercent -= childHeight.value;\r\n }\r\n let maxHeight = child.get(\"maxHeight\", child.getPrivate(\"maxHeight\", Infinity));\r\n if (h > maxHeight) {\r\n availableHeight -= maxHeight;\r\n totalPercent -= childHeight.value;\r\n }\r\n }\r\n else {\r\n if (!$type.isNumber(childHeight)) {\r\n childHeight = child.height();\r\n }\r\n availableHeight -= childHeight + child.get(\"marginTop\", 0) + child.get(\"marginBottom\", 0);\r\n }\r\n }\r\n }\r\n });\r\n if (availableHeight <= 0 || availableHeight == Infinity) {\r\n availableHeight = .1;\r\n }\r\n //if (availableHeight > 0) {\r\n eachChildren(container, (child) => {\r\n if (child.isVisible()) {\r\n if (child.get(\"position\") == \"relative\") {\r\n let childHeight = child.get(\"height\");\r\n if (childHeight instanceof Percent) {\r\n let privateHeight = availableHeight * childHeight.value / totalPercent - child.get(\"marginTop\", 0) - child.get(\"marginBottom\", 0);\r\n let minHeight = child.get(\"minHeight\", child.getPrivate(\"minHeight\", -Infinity));\r\n let maxHeight = child.get(\"maxHeight\", child.getPrivate(\"maxHeight\", Infinity));\r\n privateHeight = Math.min(Math.max(minHeight, privateHeight), maxHeight);\r\n child.setPrivate(\"height\", privateHeight);\r\n }\r\n else {\r\n if (child._prevSettings.height instanceof Percent) {\r\n child.setPrivate(\"height\", undefined);\r\n }\r\n }\r\n }\r\n }\r\n });\r\n //}\r\n let prevY = paddingTop;\r\n eachChildren(container, (child) => {\r\n if (child.get(\"position\") == \"relative\") {\r\n if (child.isVisible()) {\r\n let bounds = child.adjustedLocalBounds();\r\n let marginTop = child.get(\"marginTop\", 0);\r\n let top = bounds.top;\r\n let bottom = bounds.bottom;\r\n let maxHeight = child.get(\"maxHeight\");\r\n if (maxHeight) {\r\n if (bottom - top > maxHeight) {\r\n bottom = top + maxHeight;\r\n }\r\n }\r\n let marginBottom = child.get(\"marginBottom\", 0);\r\n let y = prevY + marginTop - top;\r\n child.setPrivate(\"y\", y);\r\n prevY = y + bottom + marginBottom;\r\n }\r\n else {\r\n child.setPrivate(\"y\", undefined);\r\n }\r\n }\r\n });\r\n }\r\n}\r\nObject.defineProperty(VerticalLayout, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"VerticalLayout\"\r\n});\r\nObject.defineProperty(VerticalLayout, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Layout.classNames.concat([VerticalLayout.className])\r\n});\r\n//# sourceMappingURL=VerticalLayout.js.map","import { Layout, eachChildren } from \"./Layout\";\r\nimport * as $array from \"../util/Array\";\r\nimport * as $math from \"../util/Math\";\r\n/**\r\n * A grid children layout for [[Container]].\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/containers/#Layout} for more info\r\n */\r\nexport class GridLayout extends Layout {\r\n _afterNew() {\r\n this._setRawDefault(\"maxColumns\", Number.MAX_VALUE);\r\n super._afterNew();\r\n }\r\n /**\r\n * @ignore\r\n */\r\n updateContainer(container) {\r\n let paddingLeft = container.get(\"paddingLeft\", 0);\r\n let paddingRight = container.get(\"paddingRight\", 0);\r\n let paddingTop = container.get(\"paddingTop\", 0);\r\n let availableWidth = container.maxWidth() - paddingLeft - paddingRight;\r\n let minCellWidth = availableWidth;\r\n let maxCellWidth = 1;\r\n eachChildren(container, (child) => {\r\n if (child.get(\"visible\") && child.getPrivate(\"visible\") && !child.get(\"forceHidden\")) {\r\n if (child.get(\"position\") != \"absolute\") {\r\n let childWidth = child.width();\r\n if (childWidth < minCellWidth) {\r\n minCellWidth = childWidth;\r\n }\r\n if (childWidth > maxCellWidth) {\r\n maxCellWidth = childWidth;\r\n }\r\n }\r\n }\r\n });\r\n minCellWidth = $math.fitToRange(minCellWidth, 1, availableWidth);\r\n maxCellWidth = $math.fitToRange(maxCellWidth, 1, availableWidth);\r\n let columnCount = 1;\r\n if (this.get(\"fixedWidthGrid\")) {\r\n columnCount = availableWidth / maxCellWidth;\r\n }\r\n else {\r\n columnCount = availableWidth / minCellWidth;\r\n }\r\n columnCount = Math.max(1, Math.floor(columnCount));\r\n columnCount = Math.min(this.get(\"maxColumns\", Number.MAX_VALUE), columnCount);\r\n let columnWidths = this.getColumnWidths(container, columnCount, maxCellWidth, availableWidth);\r\n let prevY = paddingTop;\r\n let column = 0;\r\n let maxColumnHeight = 0;\r\n columnCount = columnWidths.length;\r\n let prevX = paddingLeft;\r\n eachChildren(container, (child) => {\r\n if (child.get(\"position\") == \"relative\" && child.isVisible()) {\r\n const marginTop = child.get(\"marginTop\", 0);\r\n const marginBottom = child.get(\"marginBottom\", 0);\r\n let bounds = child.adjustedLocalBounds();\r\n let marginLeft = child.get(\"marginLeft\", 0);\r\n let marginRight = child.get(\"marginRight\", 0);\r\n let x = prevX + marginLeft - bounds.left;\r\n let y = prevY + marginTop - bounds.top;\r\n child.setPrivate(\"x\", x);\r\n child.setPrivate(\"y\", y);\r\n prevX += columnWidths[column] + marginRight;\r\n maxColumnHeight = Math.max(maxColumnHeight, child.height() + marginTop + marginBottom);\r\n column++;\r\n if (column >= columnCount) {\r\n column = 0;\r\n prevX = paddingLeft;\r\n prevY += maxColumnHeight;\r\n }\r\n }\r\n });\r\n }\r\n /**\r\n * @ignore\r\n */\r\n getColumnWidths(container, columnCount, maxCellWidth, availableWidth) {\r\n let totalWidth = 0;\r\n let columnWidths = [];\r\n let column = 0;\r\n eachChildren(container, (child) => {\r\n let bounds = child.adjustedLocalBounds();\r\n if (child.get(\"position\") != \"absolute\" && child.isVisible()) {\r\n if (this.get(\"fixedWidthGrid\")) {\r\n columnWidths[column] = maxCellWidth;\r\n }\r\n else {\r\n columnWidths[column] = Math.max(columnWidths[column] | 0, bounds.right - bounds.left + child.get(\"marginLeft\", 0) + child.get(\"marginRight\", 0));\r\n }\r\n if (column < container.children.length - 1) {\r\n column++;\r\n if (column == columnCount) {\r\n column = 0;\r\n }\r\n }\r\n }\r\n });\r\n $array.each(columnWidths, (w) => {\r\n totalWidth += w;\r\n });\r\n if (totalWidth > availableWidth) {\r\n if (columnCount > 2) {\r\n columnCount -= 1;\r\n return this.getColumnWidths(container, columnCount, maxCellWidth, availableWidth);\r\n }\r\n else {\r\n return [availableWidth];\r\n }\r\n }\r\n return columnWidths;\r\n }\r\n}\r\nObject.defineProperty(GridLayout, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"GridLayout\"\r\n});\r\nObject.defineProperty(GridLayout, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Layout.classNames.concat([GridLayout.className])\r\n});\r\n//# sourceMappingURL=GridLayout.js.map","import { Color } from \"./Color\";\r\nimport * as $type from \"./Type\";\r\nexport class TextFormatter {\r\n /**\r\n * Replaces brackets with temporary placeholders.\r\n *\r\n * @ignore Exclude from docs\r\n * @param text Input text\r\n * @return Escaped text\r\n */\r\n static escape(text) {\r\n return text.\r\n replace(/\\[\\[/g, this.prefix + \"1\").\r\n replace(/([^\\/\\]]{1})\\]\\]/g, \"$1\" + this.prefix + \"2\").\r\n replace(/\\]\\]/g, this.prefix + \"2\").\r\n replace(/\\{\\{/g, this.prefix + \"3\").\r\n replace(/\\}\\}/g, this.prefix + \"4\").\r\n replace(/\\'\\'/g, this.prefix + \"5\");\r\n }\r\n /**\r\n * Replaces placeholders back to brackets.\r\n *\r\n * @ignore Exclude from docs\r\n * @param text Escaped text\r\n * @return Unescaped text\r\n */\r\n static unescape(text) {\r\n return text.\r\n replace(new RegExp(this.prefix + \"1\", \"g\"), \"[[\").\r\n replace(new RegExp(this.prefix + \"2\", \"g\"), \"]]\").\r\n replace(new RegExp(this.prefix + \"3\", \"g\"), \"{{\").\r\n replace(new RegExp(this.prefix + \"4\", \"g\"), \"}}\").\r\n replace(new RegExp(this.prefix + \"5\", \"g\"), \"''\");\r\n }\r\n /**\r\n * Cleans up the text text for leftover double square brackets.\r\n *\r\n * @ignore Exclude from docs\r\n * @param text Input text\r\n * @return Cleaned up text\r\n */\r\n static cleanUp(text) {\r\n return text.\r\n replace(/\\[\\[/g, \"[\").\r\n replace(/\\]\\]/g, \"]\").\r\n replace(/\\{\\{/g, \"{\").\r\n replace(/\\}\\}/g, \"}\").\r\n replace(/\\'\\'/g, \"'\");\r\n }\r\n /**\r\n * Splits string into chunks. (style blocks, quoted blocks, regular blocks)\r\n *\r\n * If the second parameter `quotedBlocks` is set to `true` this method will\r\n * also single out text blocks enclosed within single quotes that no\r\n * formatting should be applied to, and they should be displayed as is.\r\n *\r\n * Default for the above is `false`, so that you can use single quote in text\r\n * without escaping it.\r\n *\r\n * If enabled, single quotes can be escaped by doubling it - adding two\r\n * single quotes, which will be replaced by a one single quote in the final\r\n * output.\r\n *\r\n * @ignore Exclude from docs\r\n * @param text Text to chunk\r\n * @param quotedBlocks Use quoted blocks\r\n * @param noFormatting Formatting blocks will be treated as regular text\r\n * @return Array of string chunks\r\n */\r\n static chunk(text, quotedBlocks = false, noFormatting = false) {\r\n // Init result\r\n let res = [];\r\n // Replace double (escaped) square spaces and quotes with temporary codes\r\n text = this.escape(text);\r\n // Deal with style blocks\r\n let chunks = quotedBlocks ? text.split(\"'\") : [text];\r\n for (let i = 0; i < chunks.length; i++) {\r\n let chunk = chunks[i];\r\n // Empty?\r\n if (chunk === \"\") {\r\n continue;\r\n }\r\n if ((i % 2) === 0) {\r\n // Text outside quotes\r\n // Parse for style blocks which are \"text\" chunks, the rest chunks are\r\n // \"value\"\r\n chunk = chunk.replace(/\\]\\[/g, \"]\" + $type.PLACEHOLDER + \"[\");\r\n chunk = chunk.replace(/\\[\\]/g, \"[ ]\");\r\n let chunks2 = chunk.split(/[\\[\\]]+/);\r\n for (let i2 = 0; i2 < chunks2.length; i2++) {\r\n let chunk2 = this.cleanUp(this.unescape(chunks2[i2]));\r\n // Placeholder?\r\n if (chunk2 === $type.PLACEHOLDER) {\r\n continue;\r\n }\r\n // Empty?\r\n if (chunk2 === \"\") {\r\n continue;\r\n }\r\n // Block or value\r\n if ((i2 % 2) === 0) {\r\n res.push({\r\n \"type\": \"value\",\r\n \"text\": chunk2\r\n });\r\n }\r\n else {\r\n res.push({\r\n \"type\": noFormatting ? \"value\" : \"format\",\r\n \"text\": \"[\" + chunk2 + \"]\"\r\n });\r\n }\r\n }\r\n }\r\n else {\r\n // A text within doublequotes\r\n // All chunks are \"text\"\r\n let chunks2 = chunk.split(/[\\[\\]]+/);\r\n for (let i2 = 0; i2 < chunks2.length; i2++) {\r\n let chunk2 = this.cleanUp(this.unescape(chunks2[i2]));\r\n // Empty?\r\n if (chunk2 === \"\") {\r\n continue;\r\n }\r\n // Block or text\r\n if ((i2 % 2) === 0) {\r\n res.push({\r\n \"type\": \"text\",\r\n \"text\": chunk2\r\n });\r\n }\r\n else if (this.isImage(chunk2)) {\r\n res.push({\r\n \"type\": \"image\",\r\n \"text\": \"[\" + chunk2 + \"]\"\r\n });\r\n }\r\n else {\r\n res.push({\r\n \"type\": \"format\",\r\n \"text\": \"[\" + chunk2 + \"]\"\r\n });\r\n }\r\n }\r\n }\r\n }\r\n return res;\r\n }\r\n /**\r\n * Checks if supplied format contains image information and should be\r\n * formatted as such.\r\n * I.e.: `[img: myImage.png]`\r\n *\r\n * @ignore\r\n * @param text Format\r\n * @return true if it is an image\r\n */\r\n static isImage(text) {\r\n return text.match(/img[ ]?:/) ? true : false;\r\n }\r\n static getTextStyle(style) {\r\n // let textStyle: string[] = [];\r\n // let textFill: string | undefined;\r\n let format = {};\r\n if (style == \"\" || style == \"[ ]\") {\r\n return {};\r\n }\r\n // Pre-process quoted text\r\n const q = style.match(/('[^']*')|(\"[^\"]*\")/gi);\r\n if (q) {\r\n for (let i = 0; i < q.length; i++) {\r\n style = style.replace(q[i], q[i].replace(/['\"]*/g, \"\").replace(/[ ]+/g, \"+\"));\r\n }\r\n }\r\n // Get style parts\r\n let b = style.match(/([\\w\\-]*:[\\s]?[^;\\s\\]]*)|(\\#[\\w]{1,6})|([\\w\\-]+)|(\\/)/gi);\r\n // Empty?\r\n if (!b) {\r\n return {};\r\n }\r\n // Check each part\r\n for (let i = 0; i < b.length; i++) {\r\n if (b[i].match(/^(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)$/i)) {\r\n format.fontWeight = b[i];\r\n }\r\n else if (b[i].match(/^(underline|line-through)$/i)) {\r\n format.textDecoration = b[i];\r\n }\r\n else if (b[i] == \"/\") {\r\n // Just closing tag\r\n // Do nothing\r\n }\r\n else if (!b[i].match(/:/)) {\r\n // Color\r\n format.fill = Color.fromString(b[i]);\r\n }\r\n else {\r\n const p = b[i].replace(\"+\", \" \").split(/:[ ]*/);\r\n format[p[0]] = p[1];\r\n //textStyle.push(b[i].replace(/^[a-zA-Z]:[ ]*/, \"\"));\r\n //b[i] = b[i].replace(/\\+/g, \" \");\r\n }\r\n }\r\n return format;\r\n }\r\n}\r\nObject.defineProperty(TextFormatter, \"prefix\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"__amcharts__\"\r\n});\r\n//# sourceMappingURL=TextFormatter.js.map","/** @ignore */ /** */\r\nimport * as $type from \"./Type\";\r\nimport * as $utils from \"./Utils\";\r\nimport { Sprite } from \"../render/Sprite\";\r\nimport { TextFormatter } from \"./TextFormatter\";\r\n/**\r\n * @ignore\r\n */\r\nexport function populateString(target, string) {\r\n if (string != null) {\r\n string = \"\" + string;\r\n string = TextFormatter.escape(string);\r\n let tags = string.match(/\\{([^}]+)\\}/g);\r\n let i;\r\n if (tags) {\r\n for (i = 0; i < tags.length; i++) {\r\n let tag = tags[i].replace(/\\{([^}]+)\\}/, \"$1\");\r\n let value = getTagValue(target, tag, \"\");\r\n if (value == null) {\r\n value = \"\";\r\n }\r\n string = string.split(tags[i]).join(value);\r\n }\r\n }\r\n string = TextFormatter.unescape(string);\r\n }\r\n else {\r\n string = \"\";\r\n }\r\n // TODO: apply adapter?\r\n return string;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction getTagValue(target, tagName, format) {\r\n let value;\r\n const dataItem = target.dataItem;\r\n // Parse parts\r\n let parts = [];\r\n let reg = /(format[a-zA-Z]*)\\((.*)\\)|([^.]+)/g;\r\n let matches;\r\n while (true) {\r\n matches = reg.exec(tagName);\r\n if (matches === null) {\r\n break;\r\n }\r\n if (matches[3]) {\r\n // Simple property\r\n parts.push({\r\n prop: matches[3]\r\n });\r\n // Check if maybe we should force a formatter on this value\r\n const dateFields = target.getDateFormatter().get(\"dateFields\", []);\r\n const numericFields = target.getNumberFormatter().get(\"numericFields\", []);\r\n const durationFields = target.getDurationFormatter().get(\"durationFields\", []);\r\n if (dateFields.indexOf(matches[3]) !== -1) {\r\n parts.push({\r\n method: \"formatDate\",\r\n params: []\r\n });\r\n }\r\n else if (numericFields.indexOf(matches[3]) !== -1) {\r\n parts.push({\r\n method: \"formatNumber\",\r\n params: []\r\n });\r\n }\r\n else if (durationFields.indexOf(matches[3]) !== -1) {\r\n parts.push({\r\n method: \"formatDuration\",\r\n params: []\r\n });\r\n }\r\n }\r\n else {\r\n // Method\r\n // Parse parameters\r\n let params = [];\r\n if ($utils.trim(matches[2]) != \"\") {\r\n let reg2 = /'([^']*)'|\"([^\"]*)\"|([0-9\\-]+)/g;\r\n let matches2;\r\n while (true) {\r\n matches2 = reg2.exec(matches[2]);\r\n if (matches2 === null) {\r\n break;\r\n }\r\n params.push(matches2[1] || matches2[2] || matches2[3]);\r\n }\r\n }\r\n parts.push({\r\n method: matches[1],\r\n params: params\r\n });\r\n }\r\n }\r\n // Check if we can retrieve the value from data item\r\n if (dataItem) {\r\n // Check values\r\n value = getTagValueFromObject(target, parts, dataItem._settings);\r\n // Check properties\r\n if (value == null || $type.isObject(value)) { // isObject helps to solve problem with date axis, as for example dateX will get dateX from values object and won't get to the dateX date.\r\n value = getTagValueFromObject(target, parts, dataItem);\r\n }\r\n // Check data context\r\n let dataContext = dataItem.dataContext;\r\n if (value == null && dataContext) {\r\n value = getTagValueFromObject(target, parts, dataContext);\r\n // Maybe it's a literal dot-separated name of the key in dataContext?\r\n if (value == null) {\r\n value = getTagValueFromObject(target, [{\r\n prop: tagName\r\n }], dataContext);\r\n }\r\n // scond data context level sometimes exist (tree map)\r\n if (value == null && dataContext.dataContext) {\r\n value = getTagValueFromObject(target, parts, dataContext.dataContext);\r\n }\r\n }\r\n // Check component's data item\r\n if (value == null && dataItem.component && dataItem.component.dataItem !== dataItem) {\r\n value = getTagValue(dataItem.component, tagName, format);\r\n }\r\n }\r\n // Check sprite's properties\r\n if (value == null) {\r\n value = getTagValueFromObject(target, parts, target);\r\n }\r\n // Finally, check the parent\r\n if (value == null && target.parent) {\r\n value = getTagValue(target.parent, tagName, format);\r\n }\r\n return value;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction getCustomDataValue(target, prop) {\r\n const customData = target.getPrivate(\"customData\");\r\n if ($type.isObject(customData)) {\r\n return customData[prop];\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function getTagValueFromObject(target, parts, object, format) {\r\n let current = object;\r\n let formatApplied = false;\r\n for (let i = 0, len = parts.length; i < len; i++) {\r\n let part = parts[i];\r\n if (part.prop) {\r\n // Regular property\r\n if (current instanceof Sprite) {\r\n let tmp = current.get(part.prop);\r\n if (tmp == null)\r\n tmp = current.getPrivate(part.prop);\r\n if (tmp == null)\r\n tmp = getCustomDataValue(current, part.prop);\r\n if (tmp == null)\r\n tmp = current[part.prop];\r\n current = tmp;\r\n }\r\n else if (current.get) {\r\n let tmp = current.get(part.prop);\r\n if (tmp == null)\r\n tmp = current[part.prop];\r\n current = tmp;\r\n }\r\n else {\r\n current = current[part.prop];\r\n }\r\n if (current == null) {\r\n // Not set, return undefined\r\n return;\r\n }\r\n }\r\n else {\r\n // Method\r\n switch (part.method) {\r\n case \"formatNumber\":\r\n let numberValue = $type.toNumber(current);\r\n if (numberValue != null) {\r\n current = target.getNumberFormatter().format(numberValue, format || part.params[0] || undefined);\r\n formatApplied = true;\r\n }\r\n break;\r\n case \"formatDate\":\r\n let dateValue = $type.toDate(current);\r\n if (!$type.isDate(dateValue) || $type.isNaN(dateValue.getTime())) {\r\n // Was not able to get date out of value, quitting and letting\r\n // calling method try another value\r\n return;\r\n }\r\n if (dateValue != null) {\r\n current = target.getDateFormatter().format(dateValue, format || part.params[0] || undefined);\r\n formatApplied = true;\r\n }\r\n break;\r\n case \"formatDuration\":\r\n let durationValue = $type.toNumber(current);\r\n if (durationValue != null) {\r\n current = target.getDurationFormatter().format(durationValue, format || part.params[0] || undefined, part.params[1] || undefined);\r\n formatApplied = true;\r\n }\r\n break;\r\n case \"urlEncode\":\r\n case \"encodeURIComponent\":\r\n current = encodeURIComponent(current);\r\n break;\r\n default:\r\n if (current[part.method]) {\r\n current[part.method].apply(object, part.params);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n // Apply default format if it wasn't applied explicitly\r\n if (!formatApplied) {\r\n let formatParts = [{\r\n method: \"\",\r\n params: format\r\n }];\r\n if (format == null) {\r\n // Format is not set\r\n // Determine from the type of the value\r\n if ($type.isNumber(current)) {\r\n formatParts[0].method = \"formatNumber\";\r\n formatParts[0].params = \"\";\r\n }\r\n else if ($type.isDate(current)) {\r\n formatParts[0].method = \"formatDate\";\r\n formatParts[0].params = \"\";\r\n }\r\n }\r\n else {\r\n // Format set\r\n // Try to determine formatter based on the format\r\n let formatterType = $utils.getFormat(format);\r\n // format\r\n if (formatterType === \"number\") {\r\n formatParts[0].method = \"formatNumber\";\r\n }\r\n else if (formatterType === \"date\") {\r\n formatParts[0].method = \"formatDate\";\r\n }\r\n else if (formatterType === \"duration\") {\r\n formatParts[0].method = \"formatDuration\";\r\n }\r\n }\r\n // Apply format\r\n if (formatParts[0].method) {\r\n current = getTagValueFromObject(target, formatParts, current);\r\n }\r\n }\r\n return current;\r\n}\r\n//# sourceMappingURL=PopulateString.js.map","import { Children } from \"../util/Children\";\r\nimport { Percent } from \"../util/Percent\";\r\nimport { Sprite } from \"./Sprite\";\r\nimport { Rectangle } from \"./Rectangle\";\r\nimport { HorizontalLayout } from \"./HorizontalLayout\";\r\nimport { VerticalLayout } from \"./VerticalLayout\";\r\nimport { GridLayout } from \"./GridLayout\";\r\nimport { populateString } from \"../util/PopulateString\";\r\nimport * as $array from \"../util/Array\";\r\nimport * as $type from \"../util/Type\";\r\nimport * as $utils from \"../util/Utils\";\r\n/**\r\n * A basic element that can have child elements, maintain their layout, and\r\n * have a background.\r\n *\r\n * It can have any [[Sprite]] element as a child, from very basic shapes, to\r\n * full-fledged charts.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/containers/} for more info\r\n * @important\r\n */\r\nexport class Container extends Sprite {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_display\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._root._renderer.makeContainer()\r\n });\r\n Object.defineProperty(this, \"_childrenDisplay\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._root._renderer.makeContainer()\r\n });\r\n /**\r\n * List of Container's child elements.\r\n */\r\n Object.defineProperty(this, \"children\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new Children(this)\r\n });\r\n Object.defineProperty(this, \"_percentageSizeChildren\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_percentagePositionChildren\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_prevWidth\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_prevHeight\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_contentWidth\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_contentHeight\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_contentMask\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_vsbd0\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_vsbd1\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n _afterNew() {\r\n super._afterNew();\r\n this._display.addChild(this._childrenDisplay);\r\n }\r\n _dispose() {\r\n $array.eachReverse(this.allChildren(), (child) => {\r\n child.dispose();\r\n });\r\n if (this.getPrivate(\"htmlElement\")) {\r\n this._root._removeHTMLContent(this);\r\n }\r\n super._dispose();\r\n }\r\n _changed() {\r\n super._changed();\r\n if (this.isDirty(\"interactiveChildren\")) {\r\n this._display.interactiveChildren = this.get(\"interactiveChildren\", false);\r\n }\r\n if (this.isDirty(\"layout\")) {\r\n this._prevWidth = 0;\r\n this._prevHeight = 0;\r\n this.markDirtyBounds();\r\n if (this._prevSettings.layout) {\r\n this.children.each((child) => {\r\n child.removePrivate(\"x\");\r\n child.removePrivate(\"y\");\r\n });\r\n }\r\n }\r\n if (this.isDirty(\"paddingTop\") || this.isDirty(\"paddingBottom\") || this.isDirty(\"paddingLeft\") || this.isDirty(\"paddingRight\")) {\r\n this.children.each((child) => {\r\n child.markDirtyPosition();\r\n });\r\n }\r\n if (this.isDirty(\"maskContent\")) {\r\n const childrenDisplay = this._childrenDisplay;\r\n let contentMask = this._contentMask;\r\n if (this.get(\"maskContent\")) {\r\n if (!contentMask) {\r\n contentMask = Rectangle.new(this._root, {\r\n x: -.5,\r\n y: -.5,\r\n width: this.width() + 1,\r\n height: this.height() + 1\r\n });\r\n this._contentMask = contentMask;\r\n childrenDisplay.addChildAt(contentMask._display, 0);\r\n childrenDisplay.mask = contentMask._display;\r\n }\r\n }\r\n else {\r\n if (contentMask) {\r\n childrenDisplay.removeChild(contentMask._display);\r\n childrenDisplay.mask = null;\r\n contentMask.dispose();\r\n this._contentMask = undefined;\r\n }\r\n }\r\n }\r\n }\r\n _updateSize() {\r\n super._updateSize();\r\n $array.each(this._percentageSizeChildren, (child) => {\r\n child._updateSize();\r\n });\r\n $array.each(this._percentagePositionChildren, (child) => {\r\n child.markDirtyPosition();\r\n child._updateSize();\r\n });\r\n this.updateBackground();\r\n }\r\n updateBackground() {\r\n const background = this.get(\"background\");\r\n let bounds = this._localBounds;\r\n if (bounds && !this.isHidden()) {\r\n let x = bounds.left;\r\n let y = bounds.top;\r\n let w = bounds.right - x;\r\n let h = bounds.bottom - y;\r\n let maxWidth = this.get(\"maxWidth\");\r\n let maxHeight = this.get(\"maxHeight\");\r\n if (maxHeight) {\r\n if (h > maxHeight) {\r\n h = maxHeight;\r\n }\r\n }\r\n if (maxWidth) {\r\n if (w > maxWidth) {\r\n w = maxWidth;\r\n }\r\n }\r\n let width = this.width();\r\n let height = this.height();\r\n if (background) {\r\n background.setAll({ width: w, height: h, x: x, y: y });\r\n if (this._display.interactive) {\r\n background._display.interactive = true;\r\n }\r\n }\r\n const contentMask = this._contentMask;\r\n if (contentMask) {\r\n contentMask.setAll({ width: width + 1, height: height + 1 });\r\n }\r\n const verticalScrollbar = this.get(\"verticalScrollbar\");\r\n if (verticalScrollbar) {\r\n verticalScrollbar.set(\"height\", height);\r\n verticalScrollbar.set(\"x\", width - verticalScrollbar.width() - verticalScrollbar.get(\"marginRight\", 0));\r\n verticalScrollbar.set(\"end\", verticalScrollbar.get(\"start\", 0) + height / this._contentHeight);\r\n const bg = verticalScrollbar.get(\"background\");\r\n if (bg) {\r\n bg.setAll({ width: verticalScrollbar.width(), height: height });\r\n }\r\n let visible = true;\r\n if (this._contentHeight <= height) {\r\n visible = false;\r\n }\r\n verticalScrollbar.setPrivate(\"visible\", visible);\r\n }\r\n }\r\n }\r\n _applyThemes(force = false) {\r\n if (super._applyThemes(force)) {\r\n this.eachChildren((child) => {\r\n child._applyThemes(force);\r\n });\r\n return true;\r\n }\r\n else {\r\n return false;\r\n }\r\n }\r\n _applyState(name) {\r\n super._applyState(name);\r\n if (this.get(\"setStateOnChildren\")) {\r\n this.eachChildren((child) => {\r\n child.states.apply(name);\r\n });\r\n }\r\n }\r\n _applyStateAnimated(name, duration) {\r\n super._applyStateAnimated(name, duration);\r\n if (this.get(\"setStateOnChildren\")) {\r\n this.eachChildren((child) => {\r\n child.states.applyAnimate(name, duration);\r\n });\r\n }\r\n }\r\n /**\r\n * Returns container's inner width (width without padding) in pixels.\r\n *\r\n * @return Inner width (px)\r\n */\r\n innerWidth() {\r\n return this.width() - this.get(\"paddingRight\", 0) - this.get(\"paddingLeft\", 0);\r\n }\r\n /**\r\n * Returns container's inner height (height without padding) in pixels.\r\n *\r\n * @return Inner height (px)\r\n */\r\n innerHeight() {\r\n return this.height() - this.get(\"paddingTop\", 0) - this.get(\"paddingBottom\", 0);\r\n }\r\n _getBounds() {\r\n if (!this.get(\"html\")) {\r\n let width = this.get(\"width\");\r\n let height = this.get(\"height\");\r\n let pWidth = this.getPrivate(\"width\");\r\n let pHeight = this.getPrivate(\"height\");\r\n let bounds = {\r\n left: 0,\r\n top: 0,\r\n right: this.width(),\r\n bottom: this.height()\r\n };\r\n let layout = this.get(\"layout\");\r\n let horizontal = false;\r\n let vertical = false;\r\n if (layout instanceof HorizontalLayout || layout instanceof GridLayout) {\r\n horizontal = true;\r\n }\r\n if (layout instanceof VerticalLayout) {\r\n vertical = true;\r\n }\r\n if ((width != null || pWidth != null) && (height != null || pHeight != null) && !this.get(\"verticalScrollbar\")) {\r\n // void\r\n }\r\n else {\r\n let m = Number.MAX_VALUE;\r\n let l = m;\r\n let r = -m;\r\n let t = m;\r\n let b = -m;\r\n const paddingLeft = this.get(\"paddingLeft\", 0);\r\n const paddingTop = this.get(\"paddingTop\", 0);\r\n const paddingRight = this.get(\"paddingRight\", 0);\r\n const paddingBottom = this.get(\"paddingBottom\", 0);\r\n this.children.each((child) => {\r\n if (child.get(\"position\") != \"absolute\" && child.get(\"isMeasured\")) {\r\n let childBounds = child.adjustedLocalBounds();\r\n let childX = child.x();\r\n let childY = child.y();\r\n let cl = childX + childBounds.left;\r\n let cr = childX + childBounds.right;\r\n let ct = childY + childBounds.top;\r\n let cb = childY + childBounds.bottom;\r\n if (horizontal) {\r\n cl -= child.get(\"marginLeft\", 0);\r\n cr += child.get(\"marginRight\", 0);\r\n }\r\n if (vertical) {\r\n ct -= child.get(\"marginTop\", 0);\r\n cb += child.get(\"marginBottom\", 0);\r\n }\r\n if (cl < l) {\r\n l = cl;\r\n }\r\n if (cr > r) {\r\n r = cr;\r\n }\r\n if (ct < t) {\r\n t = ct;\r\n }\r\n if (cb > b) {\r\n b = cb;\r\n }\r\n }\r\n });\r\n if (l == m) {\r\n l = 0;\r\n }\r\n if (r == -m) {\r\n r = 0;\r\n }\r\n if (t == m) {\r\n t = 0;\r\n }\r\n if (b == -m) {\r\n b = 0;\r\n }\r\n bounds.left = l - paddingLeft;\r\n bounds.top = t - paddingTop;\r\n bounds.right = r + paddingRight;\r\n bounds.bottom = b + paddingBottom;\r\n const minWidth = this.get(\"minWidth\");\r\n if ($type.isNumber(minWidth) && minWidth > 0) {\r\n if (bounds.right - bounds.left < minWidth) {\r\n if (bounds.right >= minWidth) {\r\n bounds.left = bounds.right - minWidth;\r\n }\r\n else {\r\n bounds.right = bounds.left + minWidth;\r\n }\r\n }\r\n }\r\n const minHeight = this.get(\"minHeight\");\r\n if ($type.isNumber(minHeight) && minHeight > 0) {\r\n if (bounds.bottom - bounds.top < minHeight) {\r\n if (bounds.bottom >= minHeight) {\r\n bounds.top = bounds.bottom - minHeight;\r\n }\r\n else {\r\n bounds.bottom = bounds.top + minHeight;\r\n }\r\n }\r\n }\r\n }\r\n this._contentWidth = bounds.right - bounds.left;\r\n this._contentHeight = bounds.bottom - bounds.top;\r\n if ($type.isNumber(width)) {\r\n bounds.left = 0;\r\n bounds.right = width;\r\n }\r\n if ($type.isNumber(pWidth)) {\r\n bounds.left = 0;\r\n bounds.right = pWidth;\r\n }\r\n if ($type.isNumber(height)) {\r\n bounds.top = 0;\r\n bounds.bottom = height;\r\n }\r\n if ($type.isNumber(pHeight)) {\r\n bounds.top = 0;\r\n bounds.bottom = pHeight;\r\n }\r\n this._localBounds = bounds;\r\n }\r\n else {\r\n let bounds = this._localBounds;\r\n if (bounds) {\r\n this._contentWidth = bounds.right - bounds.left;\r\n this._contentHeight = bounds.bottom - bounds.top;\r\n }\r\n }\r\n }\r\n _updateBounds() {\r\n const layout = this.get(\"layout\");\r\n if (layout) {\r\n layout.updateContainer(this);\r\n }\r\n super._updateBounds();\r\n this.updateBackground();\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirty() {\r\n super.markDirty();\r\n this._root._addDirtyParent(this);\r\n }\r\n _prepareChildren() {\r\n const innerWidth = this.innerWidth();\r\n const innerHeight = this.innerHeight();\r\n if (innerWidth != this._prevWidth || innerHeight != this._prevHeight) {\r\n let layout = this.get(\"layout\");\r\n let horizontal = false;\r\n let vertical = false;\r\n if (layout) {\r\n if (layout instanceof HorizontalLayout || layout instanceof GridLayout) {\r\n horizontal = true;\r\n }\r\n if (layout instanceof VerticalLayout) {\r\n vertical = true;\r\n }\r\n }\r\n $array.each(this._percentageSizeChildren, (child) => {\r\n if (!horizontal) {\r\n let width = child.get(\"width\");\r\n if (width instanceof Percent) {\r\n child.setPrivate(\"width\", width.value * innerWidth);\r\n }\r\n }\r\n if (!vertical) {\r\n let height = child.get(\"height\");\r\n if (height instanceof Percent) {\r\n child.setPrivate(\"height\", height.value * innerHeight);\r\n }\r\n }\r\n });\r\n $array.each(this._percentagePositionChildren, (child) => {\r\n child.markDirtyPosition();\r\n child.markDirtyBounds();\r\n });\r\n this._prevWidth = innerWidth;\r\n this._prevHeight = innerHeight;\r\n this._sizeDirty = true;\r\n this.updateBackground();\r\n }\r\n this._handleStates();\r\n }\r\n _updateHTMLContent() {\r\n const html = this.get(\"html\");\r\n if (html && html !== \"\") {\r\n this._root._setHTMLContent(this, populateString(this, this.get(\"html\", \"\")));\r\n }\r\n else {\r\n this._root._removeHTMLContent(this);\r\n }\r\n this._root._positionHTMLElement(this);\r\n }\r\n /**\r\n * If scrolling is enabled on the Container (by adding `verticalScrollbar`)\r\n * the Container will scroll in such way so that target element becomes\r\n * visible if its currently outside of view.\r\n *\r\n * @param child Target child\r\n * @since 5.10.5\r\n */\r\n scrollToChild(child) {\r\n const verticalScrollbar = this.get(\"verticalScrollbar\");\r\n if (verticalScrollbar) {\r\n let y = child.y();\r\n let h = this.innerHeight();\r\n let ch = child.height();\r\n let contentH = this._contentHeight;\r\n let max = 1 - (h - ch / 2) / contentH;\r\n if (y + ch * .7 + this._childrenDisplay.y > h || y - ch * .3 + this._childrenDisplay.y < 0) {\r\n let pos = Math.max(0, Math.min(max, (y - ch / 2) / contentH));\r\n verticalScrollbar.animate({ key: \"start\", to: pos, duration: verticalScrollbar.get(\"animationDuration\", 0), easing: verticalScrollbar.get(\"animationEasing\") });\r\n }\r\n }\r\n }\r\n _updateChildren() {\r\n if (this.isDirty(\"html\")) {\r\n this._updateHTMLContent();\r\n }\r\n if (this.isDirty(\"verticalScrollbar\")) {\r\n const verticalScrollbar = this.get(\"verticalScrollbar\");\r\n if (verticalScrollbar) {\r\n verticalScrollbar._setParent(this);\r\n verticalScrollbar.startGrip.setPrivate(\"visible\", false);\r\n verticalScrollbar.endGrip.setPrivate(\"visible\", false);\r\n this.set(\"maskContent\", true);\r\n this.set(\"paddingRight\", verticalScrollbar.width() + verticalScrollbar.get(\"marginRight\", 0) + verticalScrollbar.get(\"marginLeft\", 0));\r\n let background = this.get(\"background\");\r\n if (!background) {\r\n background = this.set(\"background\", Rectangle.new(this._root, {\r\n themeTags: [\"background\"],\r\n fillOpacity: 0,\r\n fill: this._root.interfaceColors.get(\"alternativeBackground\")\r\n }));\r\n }\r\n this._vsbd0 = this.events.on(\"wheel\", (event) => {\r\n const wheelEvent = event.originalEvent;\r\n // Ignore wheel event if it is happening on a non-chart element, e.g. if\r\n // some page element is over the chart.\r\n if ($utils.isLocalEvent(wheelEvent, this)) {\r\n wheelEvent.preventDefault();\r\n }\r\n else {\r\n return;\r\n }\r\n let shiftY = wheelEvent.deltaY / 5000;\r\n const start = verticalScrollbar.get(\"start\", 0);\r\n const end = verticalScrollbar.get(\"end\", 1);\r\n if (start + shiftY <= 0) {\r\n shiftY = -start;\r\n }\r\n if (end + shiftY >= 1) {\r\n shiftY = 1 - end;\r\n }\r\n if (start + shiftY >= 0 && end + shiftY <= 1) {\r\n verticalScrollbar.set(\"start\", start + shiftY);\r\n verticalScrollbar.set(\"end\", end + shiftY);\r\n }\r\n });\r\n this._disposers.push(this._vsbd0);\r\n this._vsbd1 = verticalScrollbar.events.on(\"rangechanged\", () => {\r\n let h = this._contentHeight;\r\n const childrenDisplay = this._childrenDisplay;\r\n const contentMask = this._contentMask;\r\n childrenDisplay.y = -verticalScrollbar.get(\"start\", 0) * h;\r\n childrenDisplay.markDirtyLayer();\r\n if (contentMask) {\r\n contentMask._display.y = -childrenDisplay.y;\r\n childrenDisplay.mask = contentMask._display;\r\n }\r\n });\r\n this._disposers.push(this._vsbd1);\r\n this._display.addChild(verticalScrollbar._display);\r\n }\r\n else {\r\n const previous = this._prevSettings.verticalScrollbar;\r\n if (previous) {\r\n this._display.removeChild(previous._display);\r\n if (this._vsbd0) {\r\n this._vsbd0.dispose();\r\n }\r\n if (this._vsbd1) {\r\n this._vsbd1.dispose();\r\n }\r\n const childrenDisplay = this._childrenDisplay;\r\n childrenDisplay.y = 0;\r\n this.setPrivate(\"height\", undefined);\r\n this.set(\"maskContent\", false);\r\n this.set(\"paddingRight\", undefined);\r\n }\r\n }\r\n }\r\n if (this.isDirty(\"background\")) {\r\n // TODO maybe this should dispose ?\r\n const previous = this._prevSettings[\"background\"];\r\n if (previous) {\r\n this._display.removeChild(previous._display);\r\n }\r\n const background = this.get(\"background\");\r\n if (background instanceof Sprite) {\r\n background.set(\"isMeasured\", false);\r\n background._setParent(this);\r\n this._display.addChildAt(background._display, 0);\r\n }\r\n }\r\n if (this.isDirty(\"mask\")) {\r\n const mask = this.get(\"mask\");\r\n const previous = this._prevSettings[\"mask\"];\r\n if (previous) {\r\n this._display.removeChild(previous._display);\r\n if (previous != mask) {\r\n previous.dispose();\r\n }\r\n }\r\n if (mask) {\r\n const parent = mask.parent;\r\n if (parent) {\r\n parent.children.removeValue(mask);\r\n }\r\n mask._setParent(this);\r\n this._display.addChildAt(mask._display, 0);\r\n this._childrenDisplay.mask = mask._display;\r\n }\r\n }\r\n }\r\n _processTemplateField() {\r\n super._processTemplateField();\r\n this.children.each((child) => {\r\n child._processTemplateField();\r\n });\r\n }\r\n /**\r\n * @ignore\r\n */\r\n walkChildren(f) {\r\n this.children.each((child) => {\r\n if (child instanceof Container) {\r\n child.walkChildren(f);\r\n }\r\n f(child);\r\n });\r\n }\r\n eachChildren(f) {\r\n const background = this.get(\"background\");\r\n if (background) {\r\n f(background);\r\n }\r\n const verticalScrollbar = this.get(\"verticalScrollbar\");\r\n if (verticalScrollbar) {\r\n f(verticalScrollbar);\r\n }\r\n const mask = this.get(\"mask\");\r\n if (mask) {\r\n f(mask);\r\n }\r\n this.children.values.forEach((child) => {\r\n f(child);\r\n });\r\n }\r\n allChildren() {\r\n const output = [];\r\n this.eachChildren((x) => {\r\n output.push(x);\r\n });\r\n return output;\r\n }\r\n _setDataItem(dataItem) {\r\n const updated = (dataItem !== this._dataItem);\r\n super._setDataItem(dataItem);\r\n const html = this.get(\"html\", \"\");\r\n if (html && html !== \"\" && updated) {\r\n this._root._setHTMLContent(this, populateString(this, html));\r\n }\r\n }\r\n}\r\nObject.defineProperty(Container, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Container\"\r\n});\r\nObject.defineProperty(Container, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Sprite.classNames.concat([Container.className])\r\n});\r\n//# sourceMappingURL=Container.js.map","import { Sprite } from \"./Sprite\";\r\nimport { populateString } from \"../util/PopulateString\";\r\nimport * as $array from \"../util/Array\";\r\nimport * as $utils from \"../util/Utils\";\r\nimport { Disposer } from \"../util/Disposer\";\r\n/**\r\n * @ignore Text is an internal class. Use Label instead.\r\n */\r\nexport class Text extends Sprite {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"textStyle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._root._renderer.makeTextStyle()\r\n });\r\n Object.defineProperty(this, \"_display\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._root._renderer.makeText(\"\", this.textStyle)\r\n });\r\n Object.defineProperty(this, \"_textStyles\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: [\r\n \"textAlign\",\r\n \"fontFamily\",\r\n \"fontSize\",\r\n \"fontStyle\",\r\n \"fontWeight\",\r\n \"fontStyle\",\r\n \"fontVariant\",\r\n \"textDecoration\",\r\n \"shadowColor\",\r\n \"shadowBlur\",\r\n \"shadowOffsetX\",\r\n \"shadowOffsetY\",\r\n \"shadowOpacity\",\r\n // \"leading\",\r\n // \"letterSpacing\",\r\n \"lineHeight\",\r\n \"baselineRatio\",\r\n //\"padding\",\r\n // \"stroke\",\r\n // \"strokeThickness\",\r\n // \"trim\",\r\n // \"wordWrap\",\r\n \"direction\",\r\n \"textBaseline\",\r\n \"oversizedBehavior\",\r\n \"breakWords\",\r\n \"ellipsis\",\r\n \"minScale\",\r\n \"maxChars\"\r\n ]\r\n });\r\n Object.defineProperty(this, \"_originalScale\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n _updateBounds() {\r\n if (!this.get(\"text\")) {\r\n let newBounds = {\r\n left: 0,\r\n right: 0,\r\n top: 0,\r\n bottom: 0,\r\n };\r\n this._adjustedLocalBounds = newBounds;\r\n }\r\n else {\r\n super._updateBounds();\r\n let fillGradient = this.get(\"fillGradient\");\r\n if (fillGradient) {\r\n this._display.style.fill = fillGradient.getFill(this);\r\n }\r\n }\r\n }\r\n _changed() {\r\n super._changed();\r\n this._display.clear();\r\n let textStyle = this.textStyle;\r\n if (this.isDirty(\"opacity\")) {\r\n let opacity = this.get(\"opacity\", 1);\r\n this._display.alpha = opacity;\r\n }\r\n if (this.isDirty(\"text\") || this.isDirty(\"populateText\")) {\r\n this._display.text = this._getText();\r\n this.markDirtyBounds();\r\n if (this.get(\"role\") == \"tooltip\") {\r\n this._root.updateTooltip(this);\r\n }\r\n }\r\n if (this.isPrivateDirty(\"tooltipElement\")) {\r\n const tooltipElement = this.getPrivate(\"tooltipElement\");\r\n if (tooltipElement) {\r\n this._disposers.push(new Disposer(() => {\r\n this._root._removeTooltipElement(this);\r\n }));\r\n }\r\n }\r\n if (this.isDirty(\"width\")) {\r\n textStyle.wordWrapWidth = this.width();\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"oversizedBehavior\")) {\r\n textStyle.oversizedBehavior = this.get(\"oversizedBehavior\", \"none\");\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"breakWords\")) {\r\n textStyle.breakWords = this.get(\"breakWords\", false);\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"ellipsis\")) {\r\n textStyle.ellipsis = this.get(\"ellipsis\");\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"ignoreFormatting\")) {\r\n textStyle.ignoreFormatting = this.get(\"ignoreFormatting\", false);\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"minScale\")) {\r\n textStyle.minScale = this.get(\"minScale\", 0);\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"fill\") || this.isDirty(\"fillGradient\")) {\r\n const fill = this.get(\"fill\");\r\n const fillGradient = this.get(\"fillGradient\");\r\n const fillOpacity = this.get(\"fillOpacity\");\r\n if (fillGradient) {\r\n if (fill) {\r\n const stops = fillGradient.get(\"stops\", []);\r\n if (stops.length) {\r\n $array.each(stops, (stop) => {\r\n if ((!stop.color || stop.colorInherited) && fill) {\r\n stop.color = fill;\r\n stop.colorInherited = true;\r\n }\r\n if (stop.opacity == null || stop.opacityInherited) {\r\n stop.opacity = fillOpacity;\r\n stop.opacityInherited = true;\r\n }\r\n });\r\n }\r\n }\r\n textStyle.fill = fillGradient.getFill(this);\r\n }\r\n else if (fill) {\r\n textStyle.fill = fill;\r\n }\r\n }\r\n if (this.isDirty(\"fillOpacity\")) {\r\n let fillOpacity = this.get(\"fillOpacity\", 1);\r\n if (fillOpacity) {\r\n textStyle.fillOpacity = fillOpacity;\r\n }\r\n }\r\n if (this.isDirty(\"maxWidth\") || this.isPrivateDirty(\"maxWidth\")) {\r\n textStyle.maxWidth = this.get(\"maxWidth\", this.getPrivate(\"maxWidth\"));\r\n this.markDirtyBounds();\r\n }\r\n if (this.isDirty(\"maxHeight\") || this.isPrivateDirty(\"maxHeight\")) {\r\n textStyle.maxHeight = this.get(\"maxHeight\", this.getPrivate(\"maxHeight\"));\r\n this.markDirtyBounds();\r\n }\r\n $array.each(this._textStyles, (styleName) => {\r\n if (this._dirty[styleName]) {\r\n textStyle[styleName] = this.get(styleName);\r\n this.markDirtyBounds();\r\n }\r\n });\r\n textStyle[\"fontSize\"] = this.get(\"fontSize\");\r\n textStyle[\"fontFamily\"] = this.get(\"fontFamily\");\r\n this._display.style = textStyle;\r\n if (this.isDirty(\"role\") && this.get(\"role\") == \"tooltip\") {\r\n this._root.updateTooltip(this);\r\n }\r\n }\r\n _getText() {\r\n let text = this.get(\"text\", \"\");\r\n if (this.get(\"maxChars\")) {\r\n text = $utils.truncateTextWithEllipsis(text, this.get(\"maxChars\", 100000000), this.get(\"breakWords\"), this.get(\"ellipsis\"));\r\n }\r\n return this.get(\"populateText\") ? populateString(this, text) : text;\r\n }\r\n _getAccessibleText() {\r\n const ariaLabel = this.get(\"ariaLabel\");\r\n if (ariaLabel !== undefined) {\r\n return this.get(\"populateText\") ? populateString(this, ariaLabel) : ariaLabel;\r\n }\r\n return this._getText();\r\n }\r\n /**\r\n * Forces the text to be re-evaluated and re-populated.\r\n */\r\n markDirtyText() {\r\n this._display.text = this._getText();\r\n if (this.get(\"role\") == \"tooltip\") {\r\n this._root.updateTooltip(this);\r\n }\r\n this.markDirtyBounds();\r\n this.markDirty();\r\n }\r\n _setDataItem(dataItem) {\r\n super._setDataItem(dataItem);\r\n if (this.get(\"populateText\")) {\r\n this.markDirtyText();\r\n }\r\n }\r\n getNumberFormatter() {\r\n if (this.parent) {\r\n return this.parent.getNumberFormatter();\r\n }\r\n else {\r\n return super.getNumberFormatter();\r\n }\r\n }\r\n getDateFormatter() {\r\n if (this.parent) {\r\n return this.parent.getDateFormatter();\r\n }\r\n else {\r\n return super.getDateFormatter();\r\n }\r\n }\r\n getDurationFormatter() {\r\n if (this.parent) {\r\n return this.parent.getDurationFormatter();\r\n }\r\n else {\r\n return super.getDurationFormatter();\r\n }\r\n }\r\n}\r\nObject.defineProperty(Text, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Text\"\r\n});\r\nObject.defineProperty(Text, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Sprite.classNames.concat([Text.className])\r\n});\r\n//# sourceMappingURL=Text.js.map","/** @ignore */ /** */\r\nimport * as $array from \"./Array\";\r\nimport * as $utils from \"./Utils\";\r\n/**\r\n * @ignore\r\n */\r\nclass Native {\r\n constructor() {\r\n Object.defineProperty(this, \"_observer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_targets\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n this._observer = new ResizeObserver((entries) => {\r\n $array.each(entries, (entry) => {\r\n $array.each(this._targets, (x) => {\r\n if (x.target === entry.target) {\r\n x.callback();\r\n }\r\n });\r\n });\r\n });\r\n }\r\n addTarget(target, callback) {\r\n this._observer.observe(target, { box: \"border-box\" });\r\n this._targets.push({ target, callback });\r\n }\r\n removeTarget(target) {\r\n this._observer.unobserve(target);\r\n $array.keepIf(this._targets, (x) => {\r\n return x.target !== target;\r\n });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass Raf {\r\n constructor() {\r\n Object.defineProperty(this, \"_timer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: null\r\n });\r\n Object.defineProperty(this, \"_targets\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n }\r\n addTarget(target, callback) {\r\n if (this._timer === null) {\r\n let lastTime = null;\r\n const loop = () => {\r\n const currentTime = Date.now();\r\n if (lastTime === null || currentTime > (lastTime + Raf.delay)) {\r\n lastTime = currentTime;\r\n $array.each(this._targets, (x) => {\r\n let newSize = x.target.getBoundingClientRect();\r\n if (newSize.width !== x.size.width || newSize.height !== x.size.height) {\r\n x.size = newSize;\r\n x.callback();\r\n }\r\n });\r\n }\r\n if (this._targets.length === 0) {\r\n this._timer = null;\r\n }\r\n else {\r\n this._timer = requestAnimationFrame(loop);\r\n }\r\n };\r\n this._timer = requestAnimationFrame(loop);\r\n }\r\n // We start off with fake bounds so that sensor always kicks in\r\n let size = { width: 0, height: 0, left: 0, right: 0, top: 0, bottom: 0, x: 0, y: 0 };\r\n this._targets.push({ target, callback, size });\r\n }\r\n removeTarget(target) {\r\n $array.keepIf(this._targets, (x) => {\r\n return x.target !== target;\r\n });\r\n if (this._targets.length === 0) {\r\n if (this._timer !== null) {\r\n cancelAnimationFrame(this._timer);\r\n this._timer = null;\r\n }\r\n }\r\n }\r\n}\r\nObject.defineProperty(Raf, \"delay\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 200\r\n});\r\n/**\r\n * @ignore\r\n */\r\nlet observer = null;\r\n/**\r\n * @ignore\r\n */\r\nfunction makeSensor() {\r\n if (observer === null) {\r\n if (typeof ResizeObserver !== \"undefined\") {\r\n observer = new Native();\r\n }\r\n else {\r\n observer = new Raf();\r\n }\r\n }\r\n return observer;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class ResizeSensor {\r\n constructor(element, callback) {\r\n Object.defineProperty(this, \"_sensor\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_element\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_listener\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_disposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n this._sensor = makeSensor();\r\n this._element = element;\r\n // This is needed because we need to know when the window is zoomed\r\n this._listener = $utils.onZoom(callback);\r\n this._sensor.addTarget(element, callback);\r\n }\r\n isDisposed() {\r\n return this._disposed;\r\n }\r\n dispose() {\r\n if (!this._disposed) {\r\n this._disposed = true;\r\n this._sensor.removeTarget(this._element);\r\n this._listener.dispose();\r\n }\r\n }\r\n get sensor() {\r\n return this._sensor;\r\n }\r\n}\r\n//# sourceMappingURL=ResizeSensor.js.map","import { Entity } from \"./Entity\";\r\n/**\r\n * Presets for common UI elements.\r\n */\r\nexport class InterfaceColors extends Entity {\r\n}\r\nObject.defineProperty(InterfaceColors, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"InterfaceColors\"\r\n});\r\nObject.defineProperty(InterfaceColors, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Entity.classNames.concat([InterfaceColors.className])\r\n});\r\n//# sourceMappingURL=InterfaceColors.js.map","import { Text } from \"../render/Text\";\r\nimport { p50, p100 } from \"../util/Percent\";\r\nimport { Container } from \"./Container\";\r\nimport * as $array from \"../../core/util/Array\";\r\nimport * as $type from \"../../core/util/Type\";\r\n/**\r\n * Creates a label with support for in-line styling and data bindings.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/labels/} for more info\r\n */\r\nexport class Label extends Container {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_text\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_textKeys\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: [\r\n \"text\",\r\n \"fill\",\r\n \"fillGradient\",\r\n \"fillOpacity\",\r\n \"textAlign\",\r\n \"fontFamily\",\r\n \"fontSize\",\r\n \"fontStyle\",\r\n \"fontWeight\",\r\n \"fontStyle\",\r\n \"fontVariant\",\r\n \"textDecoration\",\r\n \"shadowColor\",\r\n \"shadowBlur\",\r\n \"shadowOffsetX\",\r\n \"shadowOffsetY\",\r\n \"shadowOpacity\",\r\n // \"leading\",\r\n // \"letterSpacing\",\r\n \"lineHeight\",\r\n \"baselineRatio\",\r\n //\"padding\",\r\n // \"stroke\",\r\n // \"strokeThickness\",\r\n // \"trim\",\r\n // \"wordWrap\",\r\n \"direction\",\r\n \"textBaseline\",\r\n \"oversizedBehavior\",\r\n \"breakWords\",\r\n \"ellipsis\",\r\n \"minScale\",\r\n \"populateText\",\r\n \"role\",\r\n \"ignoreFormatting\",\r\n \"maxChars\",\r\n \"ariaLabel\"\r\n ]\r\n });\r\n }\r\n /**\r\n * @ignore Text is not to be used directly\r\n */\r\n get text() {\r\n return this._text;\r\n }\r\n _afterNew() {\r\n super._afterNew();\r\n this._makeText();\r\n $array.each(this._textKeys, (property) => {\r\n const propValue = this.get(property);\r\n if (propValue != undefined) {\r\n this._text.set(property, propValue);\r\n }\r\n });\r\n if (this.get(\"html\", \"\") !== \"\") {\r\n this._text.set(\"text\", \"\");\r\n }\r\n this.onPrivate(\"maxWidth\", () => {\r\n this._setMaxDimentions();\r\n });\r\n this.onPrivate(\"maxHeight\", () => {\r\n this._setMaxDimentions();\r\n });\r\n }\r\n _makeText() {\r\n this._text = this.children.push(Text.new(this._root, {}));\r\n }\r\n _updateChildren() {\r\n super._updateChildren();\r\n const text = this._text;\r\n $array.each(this._textKeys, (property) => {\r\n this._text.set(property, this.get(property));\r\n });\r\n if (this.isDirty(\"maxWidth\") || this.isDirty(\"maxHeight\") || this.isDirty(\"rotation\")) {\r\n this._setMaxDimentions();\r\n }\r\n // Do not show regular text if HTML is used\r\n if (this.get(\"html\", \"\") !== \"\") {\r\n text.set(\"text\", \"\");\r\n }\r\n else {\r\n text.set(\"text\", this.get(\"text\"));\r\n this._maybeUpdateHTMLColor();\r\n }\r\n if (this.isDirty(\"fill\") || this.isDirty(\"fillGradient\")) {\r\n this._maybeUpdateHTMLColor();\r\n }\r\n if (this.isDirty(\"textAlign\") || this.isDirty(\"width\")) {\r\n const textAlign = this.get(\"textAlign\");\r\n let x;\r\n if (this.get(\"width\") != null) {\r\n if (textAlign == \"right\") {\r\n x = p100;\r\n }\r\n else if (textAlign == \"center\") {\r\n x = p50;\r\n }\r\n else {\r\n x = 0;\r\n }\r\n }\r\n else {\r\n if (textAlign == \"left\" || textAlign == \"start\") {\r\n x = this.get(\"paddingLeft\", 0);\r\n }\r\n else if (textAlign == \"right\" || textAlign == \"end\") {\r\n x = -this.get(\"paddingRight\", 0);\r\n }\r\n }\r\n text.set(\"x\", x);\r\n }\r\n const background = this.get(\"background\");\r\n if (background) {\r\n background.setPrivate(\"visible\", text._display.textVisible);\r\n }\r\n }\r\n _maybeUpdateHTMLColor() {\r\n const htmlElement = this.getPrivate(\"htmlElement\");\r\n if (htmlElement && this.get(\"fill\")) {\r\n htmlElement.style.color = this.get(\"fill\").toCSSHex();\r\n //@todo support gradient\r\n }\r\n }\r\n _setMaxDimentions() {\r\n const rotation = this.get(\"rotation\");\r\n const vertical = rotation == 90 || rotation == 270 || rotation == -90;\r\n const text = this._text;\r\n const maxWidth = this.get(\"maxWidth\", this.getPrivate(\"maxWidth\", Infinity));\r\n if ($type.isNumber(maxWidth)) {\r\n text.set(vertical ? \"maxHeight\" : \"maxWidth\", maxWidth - this.get(\"paddingLeft\", 0) - this.get(\"paddingRight\", 0));\r\n }\r\n else {\r\n text.set(vertical ? \"maxHeight\" : \"maxWidth\", undefined);\r\n }\r\n const maxHeight = this.get(\"maxHeight\", this.getPrivate(\"maxHeight\", Infinity));\r\n if ($type.isNumber(maxHeight)) {\r\n text.set(vertical ? \"maxWidth\" : \"maxHeight\", maxHeight - this.get(\"paddingTop\", 0) - this.get(\"paddingBottom\", 0));\r\n }\r\n else {\r\n text.set(vertical ? \"maxWidth\" : \"maxHeight\", undefined);\r\n }\r\n this.root.events.once(\"frameended\", () => {\r\n text.markDirtyBounds();\r\n });\r\n }\r\n _setDataItem(dataItem) {\r\n super._setDataItem(dataItem);\r\n this._markDirtyKey(\"text\");\r\n const text = this._text;\r\n if (text.get(\"populateText\")) {\r\n text.markDirtyText();\r\n }\r\n const html = this.get(\"html\");\r\n if (html && html !== \"\") {\r\n this._updateHTMLContent();\r\n }\r\n }\r\n /**\r\n * Returns text with populated placeholders and formatting if `populateText` is\r\n * set to `true`.\r\n *\r\n * @return Populated text\r\n */\r\n getText() {\r\n return this._text._getText();\r\n }\r\n /**\r\n * Returns \"aria-label\" text with populated placeholders and formatting\r\n * if `populateText` is set to `true`.\r\n *\r\n * @return Populated text\r\n */\r\n getAccessibleText() {\r\n return this._text._getAccessibleText();\r\n }\r\n}\r\nObject.defineProperty(Label, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Label\"\r\n});\r\nObject.defineProperty(Label, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Container.classNames.concat([Label.className])\r\n});\r\n//# sourceMappingURL=Label.js.map","import { Graphics } from \"./Graphics\";\r\nimport * as $math from \"../util/Math\";\r\n/**\r\n * Draws a rectangle with a pointer.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/graphics/} for more info\r\n * @important\r\n */\r\nexport class PointedRectangle extends Graphics {\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n if (this.isDirty(\"pointerBaseWidth\") || this.isDirty(\"cornerRadius\") || this.isDirty(\"pointerLength\") || this.isDirty(\"pointerX\") || this.isDirty(\"pointerY\") || this.isDirty(\"width\") || this.isDirty(\"height\")) {\r\n this._clear = true;\r\n }\r\n }\r\n _changed() {\r\n super._changed();\r\n if (this._clear) {\r\n this.markDirtyBounds();\r\n let w = this.width();\r\n let h = this.height();\r\n if (w > 0 && h > 0) {\r\n let cr = this.get(\"cornerRadius\", 8);\r\n cr = $math.fitToRange(cr, 0, Math.min(w / 2, h / 2));\r\n let x = this.get(\"pointerX\", 0);\r\n let y = this.get(\"pointerY\", 0);\r\n let bwh = this.get(\"pointerBaseWidth\", 15) / 2;\r\n // corner coordinates\r\n // top left\r\n let xtl = 0;\r\n let ytl = 0;\r\n // top right\r\n let xtr = w;\r\n let ytr = 0;\r\n // bottom right\r\n let xbr = w;\r\n let ybr = h;\r\n // bottom left\r\n let xbl = 0;\r\n let ybl = h;\r\n // find stem base side: http://$math.stackexchange.com/questions/274712/calculate-on-which-side-of-straign-line-is-dot-located\r\n // d=(x−x1)(y2−y1)−(y−y1)(x2−x1)\r\n let d1 = (x - xtl) * (ybr - ytl) - (y - ytl) * (xbr - xtl);\r\n let d2 = (x - xbl) * (ytr - ybl) - (y - ybl) * (xtr - xbl);\r\n const display = this._display;\r\n // top\r\n display.moveTo(cr, 0);\r\n if (d1 > 0 && d2 > 0) {\r\n let stemX = Math.round($math.fitToRange(x, cr + bwh, w - bwh - cr));\r\n y = $math.fitToRange(y, -Infinity, 0);\r\n display.lineTo(stemX - bwh, 0);\r\n display.lineTo(x, y);\r\n display.lineTo(stemX + bwh, 0);\r\n }\r\n display.lineTo(w - cr, 0);\r\n display.arcTo(w, 0, w, cr, cr);\r\n // right\r\n if (d1 > 0 && d2 < 0) {\r\n let stemY = Math.round($math.fitToRange(y, cr + bwh, h - bwh - cr));\r\n x = $math.fitToRange(x, w, Infinity);\r\n display.lineTo(w, cr);\r\n display.lineTo(w, Math.max(stemY - bwh, cr));\r\n display.lineTo(x, y);\r\n display.lineTo(w, stemY + bwh);\r\n }\r\n display.lineTo(w, h - cr);\r\n display.arcTo(w, h, w - cr, h, cr);\r\n // bottom\r\n if (d1 < 0 && d2 < 0) {\r\n let stemX = Math.round($math.fitToRange(x, cr + bwh, w - bwh - cr));\r\n y = $math.fitToRange(y, h, Infinity);\r\n display.lineTo(w - cr, h);\r\n display.lineTo(stemX + bwh, h);\r\n display.lineTo(x, y);\r\n display.lineTo(stemX - bwh, h);\r\n }\r\n display.lineTo(cr, h);\r\n display.arcTo(0, h, 0, h - cr, cr);\r\n // left\r\n if (d1 < 0 && d2 > 0) {\r\n let stemY = Math.round($math.fitToRange(y, cr + bwh, h - cr - bwh));\r\n x = $math.fitToRange(x, -Infinity, 0);\r\n display.lineTo(0, h - cr);\r\n display.lineTo(0, stemY + bwh);\r\n display.lineTo(x, y);\r\n display.lineTo(0, Math.max(stemY - bwh, cr));\r\n }\r\n display.lineTo(0, cr);\r\n display.arcTo(0, 0, cr, 0, cr);\r\n display.closePath();\r\n }\r\n }\r\n }\r\n}\r\nObject.defineProperty(PointedRectangle, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"PointedRectangle\"\r\n});\r\nObject.defineProperty(PointedRectangle, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Graphics.classNames.concat([PointedRectangle.className])\r\n});\r\n//# sourceMappingURL=PointedRectangle.js.map","import { MultiDisposer } from \"../util/Disposer\";\r\nimport { Label } from \"../render/Label\";\r\nimport { PointedRectangle } from \"../render/PointedRectangle\";\r\nimport { Container } from \"./Container\";\r\nimport { Percent } from \"../util/Percent\";\r\nimport { Color } from \"../util/Color\";\r\nimport * as $math from \"../util/Math\";\r\nimport * as $array from \"../util/Array\";\r\nimport * as $utils from \"../util/Utils\";\r\n/**\r\n * Creates a tooltip.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/tooltips/} for more info\r\n * @important\r\n */\r\nexport class Tooltip extends Container {\r\n constructor(root, settings, isReal, templates = []) {\r\n super(root, settings, isReal, templates);\r\n Object.defineProperty(this, \"_fx\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_fy\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_label\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_fillDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_strokeDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_labelDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_w\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_h\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_keepHoverDp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_htmlContentHovered\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n }\r\n _afterNew() {\r\n this._settings.themeTags = $utils.mergeTags(this._settings.themeTags, [\"tooltip\"]);\r\n super._afterNew();\r\n const background = this._setDefaultFn(\"background\", () => {\r\n return PointedRectangle.new(this._root, {});\r\n });\r\n background.set(\"themeTags\", [\"tooltip\", \"background\"]);\r\n this._label = this.children.push(Label.new(this._root, {}));\r\n this._disposers.push(this._label.events.on(\"boundschanged\", () => {\r\n this._updateBackground();\r\n }));\r\n this._disposers.push(this.on(\"bounds\", () => {\r\n this._updateBackground();\r\n }));\r\n this._updateTextColor();\r\n this._root.tooltipContainer.children.push(this);\r\n this.hide(0);\r\n this._disposers.push(this.label.onPrivate(\"htmlElement\", (htmlElement) => {\r\n if (htmlElement) {\r\n this._disposers.push($utils.addEventListener(htmlElement, \"pointerover\", (_ev) => {\r\n this._htmlContentHovered = true;\r\n }));\r\n this._disposers.push($utils.addEventListener(htmlElement, \"pointerout\", (_ev) => {\r\n this._htmlContentHovered = false;\r\n }));\r\n }\r\n }));\r\n this.on(\"visible\", (_ev) => {\r\n this._handleReaderAnnouncement();\r\n });\r\n this.label.events.on(\"dataitemchanged\", (_ev) => {\r\n this._handleReaderAnnouncement();\r\n });\r\n this._root._tooltips.push(this);\r\n }\r\n _handleReaderAnnouncement() {\r\n if (this.get(\"readerAnnounce\") && this.isVisibleDeep()) {\r\n this._root.readerAlert(this.label.getAccessibleText());\r\n }\r\n }\r\n /**\r\n * A [[Label]] element for the tooltip.\r\n *\r\n * @readonly\r\n * @return Label\r\n */\r\n get label() {\r\n return this._label;\r\n }\r\n /**\r\n * Permanently disposes the tooltip.\r\n */\r\n _dispose() {\r\n super._dispose();\r\n $array.remove(this._root._tooltips, this);\r\n }\r\n _updateChildren() {\r\n super._updateChildren();\r\n if (this.isDirty(\"pointerOrientation\") || this.isPrivateDirty(\"minWidth\") || this.isPrivateDirty(\"minHeight\")) {\r\n this.get(\"background\")._markDirtyKey(\"width\");\r\n }\r\n const labelText = this.get(\"labelText\");\r\n if (labelText != null) {\r\n this.label.set(\"text\", this.get(\"labelText\"));\r\n }\r\n const labelHTML = this.get(\"labelHTML\");\r\n if (labelHTML != null) {\r\n this.label.set(\"html\", this.get(\"labelHTML\"));\r\n }\r\n const labelAriaLabel = this.get(\"labelAriaLabel\");\r\n if (labelAriaLabel != null) {\r\n this.label.set(\"ariaLabel\", this.get(\"labelAriaLabel\"));\r\n }\r\n }\r\n _changed() {\r\n super._changed();\r\n if (this.isDirty(\"pointTo\") || this.isDirty(\"pointerOrientation\")) {\r\n // can't compare to previous, as sometimes pointTo is set twice (when pointer moves, so the position won't be udpated)\r\n this._updateBackground();\r\n }\r\n if (this.isDirty(\"tooltipTarget\")) {\r\n this.updateBackgroundColor();\r\n }\r\n if (this.isDirty(\"keepTargetHover\")) {\r\n const keephover = this.get(\"keepTargetHover\");\r\n if (keephover) {\r\n const bg = this.get(\"background\");\r\n this._keepHoverDp = new MultiDisposer([\r\n bg.events.on(\"pointerover\", (_ev) => {\r\n let target = this.get(\"tooltipTarget\");\r\n if (target) {\r\n if (target.parent && target.parent.getPrivate(\"tooltipTarget\") == target) {\r\n target = target.parent;\r\n }\r\n target.hover();\r\n }\r\n }),\r\n bg.events.on(\"pointerout\", (_ev) => {\r\n let target = this.get(\"tooltipTarget\");\r\n if (target) {\r\n if (target.parent && target.parent.getPrivate(\"tooltipTarget\") == target) {\r\n target = target.parent;\r\n }\r\n if (!this._htmlContentHovered) {\r\n target.unhover();\r\n }\r\n }\r\n })\r\n ]);\r\n this.label.onPrivate(\"htmlElement\", (htmlElement) => {\r\n if (this._keepHoverDp && htmlElement) {\r\n this._keepHoverDp.disposers.push($utils.addEventListener(htmlElement, \"pointerleave\", (ev) => {\r\n const outEvent = this.root._renderer.getEvent(ev);\r\n bg.events.dispatch(\"pointerout\", {\r\n type: \"pointerout\",\r\n originalEvent: outEvent.event,\r\n point: outEvent.point,\r\n simulated: false,\r\n target: bg\r\n });\r\n }));\r\n }\r\n });\r\n }\r\n else {\r\n if (this._keepHoverDp) {\r\n this._keepHoverDp.dispose();\r\n this._keepHoverDp = undefined;\r\n }\r\n }\r\n }\r\n }\r\n _onShow() {\r\n super._onShow();\r\n this.updateBackgroundColor();\r\n }\r\n updateBackgroundColor() {\r\n let tooltipTarget = this.get(\"tooltipTarget\");\r\n const background = this.get(\"background\");\r\n let fill;\r\n let stroke;\r\n if (tooltipTarget && background) {\r\n fill = tooltipTarget.get(\"fill\");\r\n stroke = tooltipTarget.get(\"stroke\");\r\n if (fill == null) {\r\n fill = stroke;\r\n }\r\n if (this.get(\"getFillFromSprite\")) {\r\n if (this._fillDp) {\r\n this._fillDp.dispose();\r\n }\r\n if (fill != null) {\r\n background.set(\"fill\", fill);\r\n }\r\n this._fillDp = tooltipTarget.on(\"fill\", (fill) => {\r\n if (fill != null) {\r\n background.set(\"fill\", fill);\r\n this._updateTextColor(fill);\r\n }\r\n });\r\n this._disposers.push(this._fillDp);\r\n }\r\n if (this.get(\"getStrokeFromSprite\")) {\r\n if (this._strokeDp) {\r\n this._strokeDp.dispose();\r\n }\r\n if (fill != null) {\r\n background.set(\"stroke\", fill);\r\n }\r\n this._strokeDp = tooltipTarget.on(\"fill\", (fill) => {\r\n if (fill != null) {\r\n background.set(\"stroke\", fill);\r\n }\r\n });\r\n this._disposers.push(this._strokeDp);\r\n }\r\n if (this.get(\"getLabelFillFromSprite\")) {\r\n if (this._labelDp) {\r\n this._labelDp.dispose();\r\n }\r\n if (fill != null) {\r\n this.label.set(\"fill\", fill);\r\n }\r\n this._labelDp = tooltipTarget.on(\"fill\", (fill) => {\r\n if (fill != null) {\r\n this.label.set(\"fill\", fill);\r\n }\r\n });\r\n this._disposers.push(this._labelDp);\r\n }\r\n }\r\n this._updateTextColor(fill);\r\n }\r\n _updateTextColor(fill) {\r\n if (this.get(\"autoTextColor\")) {\r\n if (fill == null) {\r\n fill = this.get(\"background\").get(\"fill\");\r\n }\r\n if (fill == null) {\r\n fill = this._root.interfaceColors.get(\"background\");\r\n }\r\n if (fill instanceof Color) {\r\n this.label.set(\"fill\", Color.alternative(fill, this._root.interfaceColors.get(\"alternativeText\"), this._root.interfaceColors.get(\"text\")));\r\n }\r\n }\r\n }\r\n _setDataItem(dataItem) {\r\n super._setDataItem(dataItem);\r\n this.label._setDataItem(dataItem);\r\n }\r\n _updateBackground() {\r\n super.updateBackground();\r\n const parent = this._root.container;\r\n if (parent) {\r\n let cw = 0.5;\r\n let ch = 0.5;\r\n let centerX = this.get(\"centerX\");\r\n if (centerX instanceof Percent) {\r\n cw = centerX.value;\r\n }\r\n let centerY = this.get(\"centerY\");\r\n if (centerY instanceof Percent) {\r\n ch = centerY.value;\r\n }\r\n let parentW = parent.width();\r\n let parentH = parent.height();\r\n let tooltipContainer = this.parent;\r\n let xx = 0;\r\n let yy = 0;\r\n if (tooltipContainer) {\r\n xx = tooltipContainer.x();\r\n yy = tooltipContainer.y();\r\n const layerMargin = tooltipContainer.get(\"layerMargin\");\r\n if (layerMargin) {\r\n xx += layerMargin.left || 0;\r\n yy += layerMargin.top || 0;\r\n parentW += (layerMargin.left || 0) + (layerMargin.right || 0);\r\n parentH += (layerMargin.top || 0) + (layerMargin.bottom || 0);\r\n }\r\n }\r\n const bounds = this.get(\"bounds\", { left: -xx, top: -yy, right: parentW - xx, bottom: parentH - yy });\r\n this._updateBounds();\r\n let w = this.width();\r\n let h = this.height();\r\n // use old w and h,as when tooltip is hidden, these are 0 and unneeded animation happens\r\n if (w === 0) {\r\n w = this._w;\r\n }\r\n if (h === 0) {\r\n h = this._h;\r\n }\r\n let pointTo = this.get(\"pointTo\", { x: parentW / 2, y: parentH / 2 });\r\n let x = pointTo.x;\r\n let y = pointTo.y;\r\n let pointerOrientation = this.get(\"pointerOrientation\");\r\n let background = this.get(\"background\");\r\n let pointerLength = 0;\r\n let bgStrokeSizeY = 0;\r\n let bgStrokeSizeX = 0;\r\n if (background instanceof PointedRectangle) {\r\n pointerLength = background.get(\"pointerLength\", 0);\r\n bgStrokeSizeY = background.get(\"strokeWidth\", 0) / 2;\r\n bgStrokeSizeX = bgStrokeSizeY;\r\n background.set(\"width\", w);\r\n background.set(\"height\", h);\r\n }\r\n let pointerX = 0;\r\n let pointerY = 0;\r\n let boundsW = bounds.right - bounds.left;\r\n let boundsH = bounds.bottom - bounds.top;\r\n // horizontal\r\n if (pointerOrientation == \"horizontal\" || pointerOrientation == \"left\" || pointerOrientation == \"right\") {\r\n bgStrokeSizeY = 0;\r\n if (pointerOrientation == \"horizontal\") {\r\n if (x > bounds.left + boundsW / 2) {\r\n x -= (w * (1 - cw) + pointerLength);\r\n bgStrokeSizeX *= -1;\r\n }\r\n else {\r\n x += (w * cw + pointerLength);\r\n }\r\n }\r\n else if (pointerOrientation == \"left\") {\r\n x += (w * (1 - cw) + pointerLength);\r\n }\r\n else {\r\n x -= (w * cw + pointerLength);\r\n bgStrokeSizeX *= -1;\r\n }\r\n }\r\n // vertical pointer\r\n else {\r\n bgStrokeSizeX = 0;\r\n if (pointerOrientation == \"vertical\") {\r\n if (y > bounds.top + h / 2 + pointerLength) {\r\n y -= (h * (1 - ch) + pointerLength);\r\n }\r\n else {\r\n y += (h * ch + pointerLength);\r\n bgStrokeSizeY *= -1;\r\n }\r\n }\r\n else if (pointerOrientation == \"down\") {\r\n y -= (h * (1 - ch) + pointerLength);\r\n }\r\n else {\r\n y += (h * ch + pointerLength);\r\n bgStrokeSizeY *= -1;\r\n }\r\n }\r\n x = $math.fitToRange(x, bounds.left + w * cw, bounds.left + boundsW - w * (1 - cw)) + bgStrokeSizeX;\r\n y = $math.fitToRange(y, bounds.top + h * ch, bounds.top + boundsH - h * (1 - ch)) - bgStrokeSizeY;\r\n pointerX = pointTo.x - x + w * cw + bgStrokeSizeX;\r\n pointerY = pointTo.y - y + h * ch - bgStrokeSizeY;\r\n this._fx = x;\r\n this._fy = y;\r\n const animationDuration = this.get(\"animationDuration\", 0);\r\n if (animationDuration > 0 && this.get(\"visible\") && this.get(\"opacity\") > 0.1) {\r\n const animationEasing = this.get(\"animationEasing\");\r\n this.animate({ key: \"x\", to: x, duration: animationDuration, easing: animationEasing });\r\n this.animate({ key: \"y\", to: y, duration: animationDuration, easing: animationEasing });\r\n }\r\n else {\r\n this.set(\"x\", x);\r\n this.set(\"y\", y);\r\n }\r\n if (background instanceof PointedRectangle) {\r\n background.set(\"pointerX\", pointerX);\r\n background.set(\"pointerY\", pointerY);\r\n }\r\n if (w > 0) {\r\n this._w = w;\r\n }\r\n if (h > 0) {\r\n this._h = h;\r\n }\r\n }\r\n }\r\n}\r\nObject.defineProperty(Tooltip, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Tooltip\"\r\n});\r\nObject.defineProperty(Tooltip, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Container.classNames.concat([Tooltip.className])\r\n});\r\n//# sourceMappingURL=Tooltip.js.map","import { Entity } from \"./Entity\";\r\nimport { TextFormatter } from \"./TextFormatter\";\r\nimport * as $object from \"./Object\";\r\nimport * as $utils from \"./Utils\";\r\nimport * as $type from \"./Type\";\r\n/**\r\n * Number formatter\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/formatters/formatting-numbers/} for more info\r\n * @important\r\n */\r\nexport class NumberFormatter extends Entity {\r\n _setDefaults() {\r\n // Defaults\r\n this._setDefault(\"negativeBase\", 0);\r\n this._setDefault(\"numberFormat\", \"#,###.#####\");\r\n this._setDefault(\"smallNumberThreshold\", 1.00);\r\n const bns = \"_big_number_suffix_\";\r\n const sns = \"_small_number_suffix_\";\r\n const bs = \"_byte_suffix_\";\r\n this._setDefault(\"bigNumberPrefixes\", [\r\n { \"number\": 1e+3, \"suffix\": this._t(bns + \"3\") },\r\n { \"number\": 1e+6, \"suffix\": this._t(bns + \"6\") },\r\n { \"number\": 1e+9, \"suffix\": this._t(bns + \"9\") },\r\n { \"number\": 1e+12, \"suffix\": this._t(bns + \"12\") },\r\n { \"number\": 1e+15, \"suffix\": this._t(bns + \"15\") },\r\n { \"number\": 1e+18, \"suffix\": this._t(bns + \"18\") },\r\n { \"number\": 1e+21, \"suffix\": this._t(bns + \"21\") },\r\n { \"number\": 1e+24, \"suffix\": this._t(bns + \"24\") }\r\n ]);\r\n this._setDefault(\"smallNumberPrefixes\", [\r\n { \"number\": 1e-24, \"suffix\": this._t(sns + \"24\") },\r\n { \"number\": 1e-21, \"suffix\": this._t(sns + \"21\") },\r\n { \"number\": 1e-18, \"suffix\": this._t(sns + \"18\") },\r\n { \"number\": 1e-15, \"suffix\": this._t(sns + \"15\") },\r\n { \"number\": 1e-12, \"suffix\": this._t(sns + \"12\") },\r\n { \"number\": 1e-9, \"suffix\": this._t(sns + \"9\") },\r\n { \"number\": 1e-6, \"suffix\": this._t(sns + \"6\") },\r\n { \"number\": 1e-3, \"suffix\": this._t(sns + \"3\") }\r\n ]);\r\n this._setDefault(\"bytePrefixes\", [\r\n { \"number\": 1, suffix: this._t(bs + \"B\") },\r\n { \"number\": 1024, suffix: this._t(bs + \"KB\") },\r\n { \"number\": 1048576, suffix: this._t(bs + \"MB\") },\r\n { \"number\": 1073741824, suffix: this._t(bs + \"GB\") },\r\n { \"number\": 1099511627776, suffix: this._t(bs + \"TB\") },\r\n { \"number\": 1125899906842624, suffix: this._t(bs + \"PB\") }\r\n ]);\r\n super._setDefaults();\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n }\r\n /**\r\n * Formats the number according to specific format.\r\n *\r\n * @param value Value to format\r\n * @param format Format to apply\r\n * @return Formatted number\r\n */\r\n format(value, format, precision) {\r\n // no format passed in or \"Number\"\r\n if (format == null || ($type.isString(format) && format.toLowerCase() === \"number\")) {\r\n format = this.get(\"numberFormat\", \"\");\r\n }\r\n // Init return value\r\n let formatted;\r\n // Cast to number just in case\r\n // TODO: maybe use better casting\r\n let source = Number(value);\r\n // Is it a built-in format or Intl.NumberFormatOptions\r\n if ($type.isObject(format)) {\r\n try {\r\n if (this.get(\"intlLocales\")) {\r\n return new Intl.NumberFormat(this.get(\"intlLocales\"), format).format(source);\r\n }\r\n else {\r\n return new Intl.NumberFormat(undefined, format).format(source);\r\n }\r\n }\r\n catch (e) {\r\n return \"Invalid\";\r\n }\r\n }\r\n else {\r\n // Clean format\r\n format = $utils.cleanFormat(format);\r\n // Get format info (it will also deal with parser caching)\r\n let info = this.parseFormat(format, this._root.language);\r\n // format and replace the number\r\n let details;\r\n if (source > this.get(\"negativeBase\")) {\r\n details = info.positive;\r\n }\r\n else if (source < this.get(\"negativeBase\")) {\r\n details = info.negative;\r\n }\r\n else {\r\n details = info.zero;\r\n }\r\n // Adjust precision\r\n if (precision != null && !details.mod) {\r\n details = $object.copy(details);\r\n details.decimals.active = source == 0 ? 0 : precision;\r\n }\r\n // Format\r\n formatted = details.template.split($type.PLACEHOLDER).join(this.applyFormat(source, details));\r\n }\r\n if (this.get(\"forceLTR\") === true) {\r\n formatted = \"‎\" + formatted;\r\n }\r\n return formatted;\r\n }\r\n /**\r\n * Parses supplied format into structured object which can be used to format\r\n * the number.\r\n *\r\n * @param format Format string, i.e. \"#,###.00\"\r\n * @param language Language\r\n * @ignore\r\n */\r\n parseFormat(format, language) {\r\n // Check cache\r\n // TODO\r\n // let cached = this.getCache(format);\r\n // if (cached != null) {\r\n // \treturn cached;\r\n // }\r\n const thousandSeparator = language.translateEmpty(\"_thousandSeparator\");\r\n const decimalSeparator = language.translateEmpty(\"_decimalSeparator\");\r\n // init format parse info holder\r\n let info = {\r\n \"positive\": {\r\n \"thousands\": {\r\n \"active\": -1,\r\n \"passive\": -1,\r\n \"interval\": -1,\r\n \"separator\": thousandSeparator\r\n },\r\n \"decimals\": {\r\n \"active\": -1,\r\n \"passive\": -1,\r\n \"separator\": decimalSeparator\r\n },\r\n \"template\": \"\",\r\n \"source\": \"\",\r\n \"parsed\": false\r\n },\r\n \"negative\": {\r\n \"thousands\": {\r\n \"active\": -1,\r\n \"passive\": -1,\r\n \"interval\": -1,\r\n \"separator\": thousandSeparator\r\n },\r\n \"decimals\": {\r\n \"active\": -1,\r\n \"passive\": -1,\r\n \"separator\": decimalSeparator\r\n },\r\n \"template\": \"\",\r\n \"source\": \"\",\r\n \"parsed\": false\r\n },\r\n \"zero\": {\r\n \"thousands\": {\r\n \"active\": -1,\r\n \"passive\": -1,\r\n \"interval\": -1,\r\n \"separator\": thousandSeparator\r\n },\r\n \"decimals\": {\r\n \"active\": -1,\r\n \"passive\": -1,\r\n \"separator\": decimalSeparator\r\n },\r\n \"template\": \"\",\r\n \"source\": \"\",\r\n \"parsed\": false\r\n }\r\n };\r\n // Escape double vertical bars (that mean display one vertical bar)\r\n format = format.replace(\"||\", $type.PLACEHOLDER2);\r\n // Split it up and deal with different formats\r\n let parts = format.split(\"|\");\r\n info.positive.source = parts[0];\r\n if (typeof parts[2] === \"undefined\") {\r\n info.zero = info.positive;\r\n }\r\n else {\r\n info.zero.source = parts[2];\r\n }\r\n if (typeof parts[1] === \"undefined\") {\r\n info.negative = info.positive;\r\n }\r\n else {\r\n info.negative.source = parts[1];\r\n }\r\n // Parse each\r\n $object.each(info, (_part, item) => {\r\n // Already parsed\r\n if (item.parsed) {\r\n return;\r\n }\r\n // Check cached\r\n // TODO\r\n // if (typeof this.getCache(item.source) !== \"undefined\") {\r\n // \tinfo[part] = this.getCache(item.source);\r\n // \treturn;\r\n // }\r\n // Begin parsing\r\n let partFormat = item.source;\r\n // Just \"Number\"?\r\n if (partFormat.toLowerCase() === \"number\") {\r\n partFormat = this.get(\"numberFormat\", \"#,###.#####\");\r\n }\r\n // Let TextFormatter split into chunks\r\n let chunks = TextFormatter.chunk(partFormat, true);\r\n for (let i = 0; i < chunks.length; i++) {\r\n let chunk = chunks[i];\r\n // replace back double vertical bar\r\n chunk.text = chunk.text.replace($type.PLACEHOLDER2, \"|\");\r\n if (chunk.type === \"value\") {\r\n // Parse format\r\n // Look for codes\r\n let matches = chunk.text.match(/[#0.,]+[ ]?[abespABESP%!]?[abespABESP‰!]?/);\r\n if (matches) {\r\n if (matches === null || matches[0] === \"\") {\r\n // no codes here - assume string\r\n // nothing to do here\r\n item.template += chunk.text;\r\n }\r\n else {\r\n // look for the format modifiers at the end\r\n let mods = matches[0].match(/[abespABESP%‰!]{2}|[abespABESP%‰]{1}$/);\r\n if (mods) {\r\n item.mod = mods[0].toLowerCase();\r\n item.modSpacing = matches[0].match(/[ ]{1}[abespABESP%‰!]{1}$/) ? true : false;\r\n }\r\n // break the format up\r\n let a = matches[0].split(\".\");\r\n // Deal with thousands\r\n if (a[0] === \"\") {\r\n // No directives for thousands\r\n // Leave default settings (no formatting)\r\n }\r\n else {\r\n // Counts\r\n item.thousands.active = (a[0].match(/0/g) || []).length;\r\n item.thousands.passive = (a[0].match(/\\#/g) || []).length + item.thousands.active;\r\n // Separator interval\r\n let b = a[0].split(\",\");\r\n if (b.length === 1) {\r\n // No thousands separators\r\n // Do nothing\r\n }\r\n else {\r\n // Use length fo the last chunk as thousands length\r\n item.thousands.interval = (b.pop() || \"\").length;\r\n if (item.thousands.interval === 0) {\r\n item.thousands.interval = -1;\r\n }\r\n }\r\n }\r\n // Deal with decimals\r\n if (typeof (a[1]) === \"undefined\") {\r\n // No directives for decimals\r\n // Leave at defaults (no formatting)\r\n }\r\n else {\r\n // Counts\r\n item.decimals.active = (a[1].match(/0/g) || []).length;\r\n item.decimals.passive = (a[1].match(/\\#/g) || []).length + item.decimals.active;\r\n }\r\n // Add special code to template\r\n item.template += chunk.text.split(matches[0]).join($type.PLACEHOLDER);\r\n }\r\n }\r\n }\r\n else {\r\n // Quoted string - take it as it is\r\n item.template += chunk.text;\r\n }\r\n }\r\n // Apply style formatting\r\n //item.template = getTextFormatter().format(item.template, this.outputFormat);\r\n // Save cache\r\n // TODO\r\n //this.setCache(item.source, item);\r\n // Mark this as parsed\r\n item.parsed = true;\r\n });\r\n // Save cache (the whole thing)\r\n // TODO\r\n //this.setCache(format, info);\r\n return info;\r\n }\r\n /**\r\n * Applies parsed format to a numeric value.\r\n *\r\n * @param value Value\r\n * @param details Parsed format as returned by parseFormat()\r\n * @return Formatted number\r\n * @ignore\r\n */\r\n applyFormat(value, details) {\r\n // Use absolute values\r\n let negative = value < 0;\r\n value = Math.abs(value);\r\n // Recalculate according to modifier\r\n let prefix = \"\", suffix = \"\";\r\n let mods = details.mod ? details.mod.split(\"\") : [];\r\n if (mods.indexOf(\"b\") !== -1) {\r\n let a = this.applyPrefix(value, this.get(\"bytePrefixes\"), mods.indexOf(\"!\") !== -1);\r\n value = a[0];\r\n prefix = a[1];\r\n suffix = a[2];\r\n if (details.modSpacing) {\r\n suffix = \" \" + suffix;\r\n }\r\n }\r\n else if (mods.indexOf(\"a\") !== -1) {\r\n let a = this.applyPrefix(value, value < this.get(\"smallNumberThreshold\") ? this.get(\"smallNumberPrefixes\") : this.get(\"bigNumberPrefixes\"), mods.indexOf(\"!\") !== -1);\r\n value = a[0];\r\n prefix = a[1];\r\n suffix = a[2];\r\n if (details.modSpacing) {\r\n suffix = \" \" + suffix;\r\n }\r\n }\r\n else if (mods.indexOf(\"p\") !== -1) {\r\n let ol = Math.min(value.toString().length + 2, 21);\r\n //value *= 100;\r\n value = parseFloat(value.toPrecision(ol));\r\n prefix = this._root.language.translate(\"_percentPrefix\");\r\n suffix = this._root.language.translate(\"_percentSuffix\");\r\n if (prefix == \"\" && suffix == \"\") {\r\n suffix = \"%\";\r\n }\r\n }\r\n else if (mods.indexOf(\"%\") !== -1) {\r\n let ol = Math.min(value.toString().length + 2, 21);\r\n value *= 100;\r\n value = parseFloat(value.toPrecision(ol));\r\n suffix = \"%\";\r\n }\r\n else if (mods.indexOf(\"‰\") !== -1) {\r\n let ol = Math.min(value.toString().length + 3, 21);\r\n value *= 1000;\r\n value = parseFloat(value.toPrecision(ol));\r\n suffix = \"‰\";\r\n }\r\n // Round to passive\r\n if (mods.indexOf(\"e\") !== -1) {\r\n // convert the value to exponential\r\n let exp;\r\n if (details.decimals.passive >= 0) {\r\n exp = value.toExponential(details.decimals.passive).split(\"e\");\r\n }\r\n else {\r\n exp = value.toExponential().split(\"e\");\r\n }\r\n value = Number(exp[0]);\r\n suffix = \"e\" + exp[1];\r\n if (details.modSpacing) {\r\n suffix = \" \" + suffix;\r\n }\r\n }\r\n else if (details.decimals.passive === 0) {\r\n value = Math.round(value);\r\n }\r\n else if (details.decimals.passive > 0) {\r\n const decimals = $utils.decimalPlaces(value);\r\n if (decimals > 0) {\r\n const d = Math.pow(10, details.decimals.passive);\r\n value = Math.round(parseFloat((value * d).toFixed(decimals))) / d;\r\n }\r\n }\r\n // Init return value\r\n let res = \"\";\r\n // Calc integer and decimal parts\r\n let a = $type.numberToString(value).split(\".\");\r\n // Format integers\r\n let ints = a[0];\r\n // Pad integers to active length\r\n if (ints.length < details.thousands.active) {\r\n ints = Array(details.thousands.active - ints.length + 1).join(\"0\") + ints;\r\n }\r\n // Insert thousands separators\r\n if (details.thousands.interval > 0) {\r\n let ip = [];\r\n let intsr = ints.split(\"\").reverse().join(\"\");\r\n for (let i = 0, len = ints.length; i <= len; i += details.thousands.interval) {\r\n let c = intsr.substr(i, details.thousands.interval).split(\"\").reverse().join(\"\");\r\n if (c !== \"\") {\r\n ip.unshift(c);\r\n }\r\n }\r\n ints = ip.join(details.thousands.separator);\r\n }\r\n // Add integers\r\n res += ints;\r\n // Add decimals\r\n if (a.length === 1) {\r\n a.push(\"\");\r\n }\r\n let decs = a[1];\r\n // Fill zeros?\r\n if (decs.length < details.decimals.active) {\r\n decs += Array(details.decimals.active - decs.length + 1).join(\"0\");\r\n }\r\n if (decs !== \"\") {\r\n res += details.decimals.separator + decs;\r\n }\r\n // Can't have empty return value\r\n if (res === \"\") {\r\n res = \"0\";\r\n }\r\n // Add minus sign back\r\n if (value !== 0 && negative && (mods.indexOf(\"s\") === -1)) {\r\n res = \"-\" + res;\r\n }\r\n // Add suffixes/prefixes\r\n if (prefix) {\r\n res = prefix + res;\r\n }\r\n if (suffix) {\r\n res += suffix;\r\n }\r\n return res;\r\n }\r\n applyPrefix(value, prefixes, force = false) {\r\n let newvalue = value;\r\n let prefix = \"\";\r\n let suffix = \"\";\r\n let applied = false;\r\n let k = 1;\r\n for (let i = 0, len = prefixes.length; i < len; i++) {\r\n if (prefixes[i].number <= value) {\r\n if (prefixes[i].number === 0) {\r\n newvalue = 0;\r\n }\r\n else {\r\n newvalue = value / prefixes[i].number;\r\n k = prefixes[i].number;\r\n }\r\n prefix = prefixes[i].prefix;\r\n suffix = prefixes[i].suffix;\r\n applied = true;\r\n }\r\n }\r\n if (!applied && force && prefixes.length && value != 0) {\r\n // Prefix was not applied. Use the first prefix.\r\n newvalue = value / prefixes[0].number;\r\n prefix = prefixes[0].prefix;\r\n suffix = prefixes[0].suffix;\r\n applied = true;\r\n }\r\n if (applied) {\r\n newvalue = parseFloat(newvalue.toPrecision(Math.min(k.toString().length + Math.floor(newvalue).toString().replace(/[^0-9]*/g, \"\").length, 21)));\r\n }\r\n return [newvalue, prefix, suffix];\r\n }\r\n /**\r\n * Replaces brackets with temporary placeholders.\r\n *\r\n * @ignore Exclude from docs\r\n * @param text Input text\r\n * @return Escaped text\r\n */\r\n escape(text) {\r\n return text.replace(\"||\", $type.PLACEHOLDER2);\r\n }\r\n /**\r\n * Replaces placeholders back to brackets.\r\n *\r\n * @ignore Exclude from docs\r\n * @param text Escaped text\r\n * @return Unescaped text\r\n */\r\n unescape(text) {\r\n return text.replace($type.PLACEHOLDER2, \"|\");\r\n }\r\n}\r\n//# sourceMappingURL=NumberFormatter.js.map","function parseDate(timezone, date) {\r\n let year = 0;\r\n let month = 0;\r\n let day = 1;\r\n let hour = 0;\r\n let minute = 0;\r\n let second = 0;\r\n let millisecond = 0;\r\n let weekday = 0;\r\n timezone.formatToParts(date).forEach((x) => {\r\n switch (x.type) {\r\n case \"year\":\r\n year = +x.value;\r\n break;\r\n case \"month\":\r\n month = (+x.value) - 1;\r\n break;\r\n case \"day\":\r\n day = +x.value;\r\n break;\r\n case \"hour\":\r\n hour = +x.value;\r\n break;\r\n case \"minute\":\r\n minute = +x.value;\r\n break;\r\n case \"second\":\r\n second = +x.value;\r\n break;\r\n case \"fractionalSecond\":\r\n millisecond = +x.value;\r\n break;\r\n case \"weekday\":\r\n switch (x.value) {\r\n case \"Sun\":\r\n weekday = 0;\r\n break;\r\n case \"Mon\":\r\n weekday = 1;\r\n break;\r\n case \"Tue\":\r\n weekday = 2;\r\n break;\r\n case \"Wed\":\r\n weekday = 3;\r\n break;\r\n case \"Thu\":\r\n weekday = 4;\r\n break;\r\n case \"Fri\":\r\n weekday = 5;\r\n break;\r\n case \"Sat\":\r\n weekday = 6;\r\n break;\r\n }\r\n }\r\n });\r\n if (hour === 24) {\r\n hour = 0;\r\n }\r\n return { year, month, day, hour, minute, second, millisecond, weekday };\r\n}\r\nfunction toUTCDate(timezone, date) {\r\n const { year, month, day, hour, minute, second, millisecond } = parseDate(timezone, date);\r\n return Date.UTC(year, month, day, hour, minute, second, millisecond);\r\n}\r\nexport class Timezone {\r\n constructor(timezone, isReal) {\r\n Object.defineProperty(this, \"_utc\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_dtf\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"name\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n if (!isReal) {\r\n throw new Error(\"You cannot use `new Class()`, instead use `Class.new()`\");\r\n }\r\n this.name = timezone;\r\n this._utc = new Intl.DateTimeFormat(\"UTC\", {\r\n hour12: false,\r\n timeZone: \"UTC\",\r\n year: \"numeric\",\r\n month: \"2-digit\",\r\n day: \"2-digit\",\r\n hour: \"2-digit\",\r\n minute: \"2-digit\",\r\n second: \"2-digit\",\r\n weekday: \"short\",\r\n fractionalSecondDigits: 3,\r\n });\r\n this._dtf = new Intl.DateTimeFormat(\"UTC\", {\r\n hour12: false,\r\n timeZone: timezone,\r\n year: \"numeric\",\r\n month: \"2-digit\",\r\n day: \"2-digit\",\r\n hour: \"2-digit\",\r\n minute: \"2-digit\",\r\n second: \"2-digit\",\r\n weekday: \"short\",\r\n fractionalSecondDigits: 3,\r\n });\r\n }\r\n /**\r\n * Use this method to create an instance of this class.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/#New_element_syntax} for more info\r\n * @param timezone IANA timezone\r\n * @return Instantiated object\r\n */\r\n static new(timezone) {\r\n return (new this(timezone, true));\r\n }\r\n convertLocal(date) {\r\n const offset = this.offsetUTC(date);\r\n const userOffset = date.getTimezoneOffset();\r\n const output = new Date(date);\r\n output.setUTCMinutes(output.getUTCMinutes() - (offset - userOffset));\r\n const newUserOffset = output.getTimezoneOffset();\r\n if (userOffset != newUserOffset) {\r\n output.setUTCMinutes(output.getUTCMinutes() + newUserOffset - userOffset);\r\n }\r\n return output;\r\n }\r\n offsetUTC(date) {\r\n const utc = toUTCDate(this._utc, date);\r\n const dtf = toUTCDate(this._dtf, date);\r\n return (utc - dtf) / 60000;\r\n }\r\n parseDate(date) {\r\n return parseDate(this._dtf, date);\r\n }\r\n}\r\n//# sourceMappingURL=Timezone.js.map","import { Entity } from \"./Entity\";\r\nimport { TextFormatter } from \"./TextFormatter\";\r\nimport { Timezone } from \"./Timezone\";\r\nimport * as $type from \"./Type\";\r\nimport * as $utils from \"./Utils\";\r\n/**\r\n * Date formatter class.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/formatters/formatting-dates/} for more info\r\n * @important\r\n */\r\nexport class DateFormatter extends Entity {\r\n _setDefaults() {\r\n // Defaults\r\n this._setDefault(\"capitalize\", true);\r\n this._setDefault(\"dateFormat\", \"yyyy-MM-dd\");\r\n super._setDefaults();\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n }\r\n /**\r\n * Formats a source `Date` object into string format\r\n * @param source inpout date\r\n * @param format Output format\r\n * @param ignoreTimezone Ignore timezone?\r\n * @return Formatted date\r\n */\r\n format(source, format, ignoreTimezone = false) {\r\n // Locale?\r\n // TODO\r\n // No format passed in or it's empty\r\n if (typeof format === \"undefined\" || format === \"\") {\r\n format = this.get(\"dateFormat\", \"yyyy-MM-dd\");\r\n }\r\n // Init return value\r\n let formatted;\r\n // Cast?\r\n // TODO: decide if we need to cast\r\n let date = source;\r\n // Is it a built-in format or Intl.DateTimeFormat\r\n if ($type.isObject(format)) {\r\n try {\r\n const locales = this.get(\"intlLocales\");\r\n if (locales) {\r\n return new Intl.DateTimeFormat(locales, format).format(date);\r\n }\r\n else {\r\n return new Intl.DateTimeFormat(undefined, format).format(date);\r\n }\r\n }\r\n catch (e) {\r\n return \"Invalid\";\r\n }\r\n }\r\n // get format info (it will also deal with parser caching)\r\n let info = this.parseFormat(format);\r\n // Should we apply custom time zone?\r\n const timezone = this._root.timezone;\r\n if (timezone && !this._root.utc && !ignoreTimezone) {\r\n date = timezone.convertLocal(date);\r\n }\r\n // Check if it's a valid date\r\n if (!$type.isNumber(date.getTime())) {\r\n // TODO translation\r\n //return this._t(\"Invalid date\");\r\n return \"Invalid date\";\r\n }\r\n // Apply format\r\n formatted = this.applyFormat(date, info, ignoreTimezone);\r\n // Capitalize\r\n if (this.get(\"capitalize\")) {\r\n formatted = formatted.replace(/^.{1}/, formatted.substr(0, 1).toUpperCase());\r\n }\r\n // We're done\r\n return formatted;\r\n }\r\n /**\r\n * Applies format to Date.\r\n *\r\n * @param date Date object\r\n * @param info Parsed format information\r\n * @return Formatted date string\r\n */\r\n applyFormat(date, info, ignoreTimezone = false) {\r\n // Init return value\r\n let res = info.template;\r\n // Get values\r\n let fullYear, month, weekday, day, hours, minutes, seconds, milliseconds, timestamp = date.getTime();\r\n if (this._root.utc && !ignoreTimezone) {\r\n fullYear = date.getUTCFullYear();\r\n month = date.getUTCMonth();\r\n weekday = date.getUTCDay();\r\n day = date.getUTCDate();\r\n hours = date.getUTCHours();\r\n minutes = date.getUTCMinutes();\r\n seconds = date.getUTCSeconds();\r\n milliseconds = date.getUTCMilliseconds();\r\n }\r\n else {\r\n fullYear = date.getFullYear();\r\n month = date.getMonth();\r\n weekday = date.getDay();\r\n day = date.getDate();\r\n hours = date.getHours();\r\n minutes = date.getMinutes();\r\n seconds = date.getSeconds();\r\n milliseconds = date.getMilliseconds();\r\n }\r\n // Go through each part and format/replace it in template\r\n for (let i = 0, len = info.parts.length; i < len; i++) {\r\n let value = \"\";\r\n switch (info.parts[i]) {\r\n case \"G\":\r\n value = this._t(fullYear < 0\r\n ? \"_era_bc\"\r\n : \"_era_ad\");\r\n break;\r\n case \"yyyy\":\r\n value = Math.abs(fullYear).toString();\r\n if (fullYear < 0) {\r\n value += this._t(\"_era_bc\");\r\n }\r\n break;\r\n case \"yyy\":\r\n case \"yy\":\r\n case \"y\":\r\n value = Math.abs(fullYear).toString().substr(-info.parts[i].length);\r\n if (fullYear < 0) {\r\n value += this._t(\"_era_bc\");\r\n }\r\n break;\r\n case \"YYYY\":\r\n case \"YYY\":\r\n case \"YY\":\r\n case \"Y\":\r\n let year = $utils.getWeekYear(date, this._root.utc);\r\n if (info.parts[i] == \"YYYY\") {\r\n value = Math.abs(year).toString();\r\n }\r\n else {\r\n value = Math.abs(year).toString().substr(-info.parts[i].length);\r\n }\r\n if (year < 0) {\r\n value += this._t(\"_era_bc\");\r\n }\r\n break;\r\n case \"u\":\r\n // @todo\r\n break;\r\n case \"q\":\r\n value = \"\" + Math.ceil((date.getMonth() + 1) / 3);\r\n break;\r\n case \"MMMMM\":\r\n value = this._t(this._getMonth(month)).substr(0, 1);\r\n break;\r\n case \"MMMM\":\r\n value = this._t(this._getMonth(month));\r\n break;\r\n case \"MMM\":\r\n value = this._t(this._getShortMonth(month));\r\n break;\r\n case \"MM\":\r\n value = $utils.padString(month + 1, 2, \"0\");\r\n break;\r\n case \"M\":\r\n value = (month + 1).toString();\r\n break;\r\n case \"ww\":\r\n value = $utils.padString($utils.getWeek(date, this._root.utc), 2, \"0\");\r\n break;\r\n case \"w\":\r\n value = $utils.getWeek(date, this._root.utc).toString();\r\n break;\r\n case \"W\":\r\n value = $utils.getMonthWeek(date, this._root.utc).toString();\r\n break;\r\n case \"dd\":\r\n value = $utils.padString(day, 2, \"0\");\r\n break;\r\n case \"d\":\r\n value = day.toString();\r\n break;\r\n case \"DD\":\r\n case \"DDD\":\r\n value = $utils.padString($utils.getYearDay(date, this._root.utc).toString(), info.parts[i].length, \"0\");\r\n break;\r\n case \"D\":\r\n value = $utils.getYearDay(date, this._root.utc).toString();\r\n break;\r\n case \"F\":\r\n // @todo\r\n break;\r\n case \"g\":\r\n // @todo\r\n break;\r\n case \"t\":\r\n value = this._root.language.translateFunc(\"_dateOrd\").call(this, day);\r\n break;\r\n case \"E\":\r\n value = (weekday || 7).toString();\r\n break;\r\n case \"EE\":\r\n value = $utils.padString((weekday || 7).toString(), 2, \"0\");\r\n break;\r\n case \"EEE\":\r\n case \"eee\":\r\n value = this._t(this._getShortWeekday(weekday));\r\n break;\r\n case \"EEEE\":\r\n case \"eeee\":\r\n value = this._t(this._getWeekday(weekday));\r\n break;\r\n case \"EEEEE\":\r\n case \"eeeee\":\r\n value = this._t(this._getShortWeekday(weekday)).substr(0, 1);\r\n break;\r\n case \"e\":\r\n case \"ee\":\r\n value = (weekday - (this._root.locale.firstDayOfWeek || 1) + 1).toString();\r\n if (info.parts[i] == \"ee\") {\r\n value = $utils.padString(value, 2, \"0\");\r\n }\r\n break;\r\n case \"a\":\r\n if (hours >= 12) {\r\n value = this._t(\"PM\");\r\n }\r\n else {\r\n value = this._t(\"AM\");\r\n }\r\n break;\r\n case \"aa\":\r\n if (hours >= 12) {\r\n value = this._t(\"P.M.\");\r\n }\r\n else {\r\n value = this._t(\"A.M.\");\r\n }\r\n break;\r\n case \"aaa\":\r\n if (hours >= 12) {\r\n value = this._t(\"P\");\r\n }\r\n else {\r\n value = this._t(\"A\");\r\n }\r\n break;\r\n case \"h\":\r\n value = $utils.get12Hours(hours).toString();\r\n break;\r\n case \"hh\":\r\n value = $utils.padString($utils.get12Hours(hours), 2, \"0\");\r\n break;\r\n case \"H\":\r\n value = hours.toString();\r\n break;\r\n case \"HH\":\r\n value = $utils.padString(hours, 2, \"0\");\r\n break;\r\n case \"K\":\r\n value = $utils.get12Hours(hours, 0).toString();\r\n break;\r\n case \"KK\":\r\n value = $utils.padString($utils.get12Hours(hours, 0), 2, \"0\");\r\n break;\r\n case \"k\":\r\n value = (hours + 1).toString();\r\n break;\r\n case \"kk\":\r\n value = $utils.padString(hours + 1, 2, \"0\");\r\n break;\r\n case \"m\":\r\n value = minutes.toString();\r\n break;\r\n case \"mm\":\r\n value = $utils.padString(minutes, 2, \"0\");\r\n break;\r\n case \"s\":\r\n value = seconds.toString();\r\n break;\r\n case \"ss\":\r\n value = $utils.padString(seconds, 2, \"0\");\r\n break;\r\n case \"S\":\r\n case \"SS\":\r\n case \"SSS\":\r\n value = Math.round((milliseconds / 1000) * Math.pow(10, info.parts[i].length)).toString();\r\n break;\r\n case \"x\":\r\n value = timestamp.toString();\r\n break;\r\n case \"n\":\r\n case \"nn\":\r\n case \"nnn\":\r\n value = $utils.padString(milliseconds, info.parts[i].length, \"0\");\r\n break;\r\n case \"z\":\r\n value = $utils.getTimeZone(date, false, false, this._root.utc, this._root.timezone ? this._root.timezone.name : undefined).replace(/[+-]+[0-9]+$/, \"\");\r\n break;\r\n case \"zz\":\r\n value = $utils.getTimeZone(date, true, false, this._root.utc, this._root.timezone ? this._root.timezone.name : undefined);\r\n break;\r\n case \"zzz\":\r\n value = $utils.getTimeZone(date, false, true, this._root.utc, this._root.timezone ? this._root.timezone.name : undefined).replace(/[+-]+[0-9]+$/, \"\");\r\n break;\r\n case \"zzzz\":\r\n value = $utils.getTimeZone(date, true, true, this._root.utc, this._root.timezone ? this._root.timezone.name : undefined);\r\n break;\r\n case \"Z\":\r\n case \"ZZ\":\r\n let timezone = this._root.utc ? \"UTC\" : this._root.timezone;\r\n if (timezone instanceof Timezone) {\r\n timezone = timezone.name;\r\n }\r\n const offset = timezone ? $utils.getTimezoneOffset(timezone) : date.getTimezoneOffset();\r\n let tz = Math.abs(offset) / 60;\r\n let tzh = Math.floor(tz);\r\n let tzm = tz * 60 - tzh * 60;\r\n if (this._root.utc) {\r\n tzh = 0;\r\n tzm = 0;\r\n }\r\n if (info.parts[i] == \"Z\") {\r\n value = \"GMT\";\r\n value += offset > 0 ? \"-\" : \"+\";\r\n value += $utils.padString(tzh, 2) + \":\" + $utils.padString(tzm, 2);\r\n }\r\n else {\r\n value = offset > 0 ? \"-\" : \"+\";\r\n value += $utils.padString(tzh, 2) + $utils.padString(tzm, 2);\r\n }\r\n break;\r\n case \"i\":\r\n value = date.toISOString();\r\n break;\r\n case \"I\":\r\n value = date.toUTCString();\r\n break;\r\n }\r\n res = res.replace($type.PLACEHOLDER, value);\r\n }\r\n return res;\r\n }\r\n /**\r\n * Parses format into structured infromation.\r\n *\r\n * @param format Format template\r\n */\r\n parseFormat(format) {\r\n // Check cache\r\n // TODO: implement caching of the parsed format\r\n // Init format parse info holder\r\n let info = {\r\n \"template\": \"\",\r\n \"parts\": []\r\n };\r\n // Let TextFormatter split into chunks\r\n let chunks = TextFormatter.chunk(format, true);\r\n for (let i = 0; i < chunks.length; i++) {\r\n let chunk = chunks[i];\r\n if (chunk.type === \"value\") {\r\n // Just \"Date\"?\r\n if (chunk.text.match(/^date$/i)) {\r\n let dateFormat = this.get(\"dateFormat\", \"yyyy-MM-dd\");\r\n if (!$type.isString(dateFormat)) {\r\n dateFormat = \"yyyy-MM-dd\";\r\n }\r\n chunk.text = dateFormat;\r\n }\r\n // Find all possible parts\r\n let matches = chunk.text.match(/G|yyyy|yyy|yy|y|YYYY|YYY|YY|Y|u|q|MMMMM|MMMM|MMM|MM|M|ww|w|W|dd|d|DDD|DD|D|F|g|EEEEE|EEEE|EEE|EE|E|eeeee|eeee|eee|ee|e|aaa|aa|a|hh|h|HH|H|KK|K|kk|k|mm|m|ss|s|SSS|SS|S|A|zzzz|zzz|zz|z|ZZ|Z|t|x|nnn|nn|n|i|I/g);\r\n // Found?\r\n if (matches) {\r\n // Populate template\r\n for (let x = 0; x < matches.length; x++) {\r\n info.parts.push(matches[x]);\r\n chunk.text = chunk.text.replace(matches[x], $type.PLACEHOLDER);\r\n }\r\n }\r\n }\r\n // Apply to template\r\n info.template += chunk.text;\r\n }\r\n // Save cache\r\n // TODO\r\n return info;\r\n }\r\n _months() {\r\n return [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"];\r\n }\r\n _getMonth(index) {\r\n return this._months()[index];\r\n }\r\n _shortMonths() {\r\n return [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May(short)\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\r\n }\r\n _getShortMonth(index) {\r\n return this._shortMonths()[index];\r\n }\r\n _weekdays() {\r\n return [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\r\n }\r\n _getWeekday(index) {\r\n return this._weekdays()[index];\r\n }\r\n _shortWeekdays() {\r\n return [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\r\n }\r\n _getShortWeekday(index) {\r\n return this._shortWeekdays()[index];\r\n }\r\n parse(source, format) {\r\n // Is it already a Date\r\n if (source instanceof Date) {\r\n return source;\r\n }\r\n // Is it a numeric timestamp\r\n if ($type.isNumber(source)) {\r\n return new Date(source);\r\n }\r\n // Are we parsing a timestamp?\r\n if (format == \"x\") {\r\n return new Date(parseInt(source));\r\n }\r\n // No? Let's check if it's string, and try converting to it if nec\r\n if (!$type.isString(source)) {\r\n source = source.toString();\r\n }\r\n // Init return value\r\n let res;\r\n // Init RegEx for parsing\r\n let reg = \"\";\r\n // Clean format\r\n format = $utils.cleanFormat(format);\r\n // Clip format to length of the source string\r\n format = format.substr(0, source.length);\r\n // Parse format\r\n let info = this.parseFormat(format);\r\n // Init parsed items holder\r\n let parsedIndexes = {\r\n \"year\": -1,\r\n \"year3\": -1,\r\n \"year2\": -1,\r\n \"year1\": -1,\r\n \"month\": -1,\r\n \"monthShort\": -1,\r\n \"monthLong\": -1,\r\n \"weekdayShort\": -1,\r\n \"weekdayLong\": -1,\r\n \"day\": -1,\r\n \"yearDay\": -1,\r\n \"week\": -1,\r\n \"hourBase0\": -1,\r\n \"hour12Base0\": -1,\r\n \"hourBase1\": -1,\r\n \"hour12Base1\": -1,\r\n \"minute\": -1,\r\n \"second\": -1,\r\n \"millisecond\": -1,\r\n \"millisecondDigits\": -1,\r\n \"am\": -1,\r\n \"zone\": -1,\r\n \"timestamp\": -1,\r\n \"iso\": -1\r\n };\r\n // Init values\r\n let resValues = {\r\n \"year\": 1970,\r\n \"month\": 0,\r\n \"day\": 1,\r\n \"hour\": 0,\r\n \"minute\": 0,\r\n \"second\": 0,\r\n \"millisecond\": 0,\r\n \"timestamp\": null,\r\n \"offset\": 0,\r\n \"utc\": this._root.utc\r\n };\r\n // Index adjuster\r\n let indexAdjust = 0;\r\n let index = 0;\r\n // Iterate through all of the parts\r\n for (let i = 0; i < info.parts.length; i++) {\r\n // Set current match index\r\n index = i + indexAdjust + 1;\r\n switch (info.parts[i]) {\r\n case \"yyyy\":\r\n case \"YYYY\":\r\n reg += \"([0-9]{4})\";\r\n parsedIndexes.year = index;\r\n break;\r\n case \"yyy\":\r\n case \"YYY\":\r\n reg += \"([0-9]{3})\";\r\n parsedIndexes.year3 = index;\r\n break;\r\n case \"yy\":\r\n case \"YY\":\r\n reg += \"([0-9]{2})\";\r\n parsedIndexes.year2 = index;\r\n break;\r\n case \"y\":\r\n case \"Y\":\r\n reg += \"([0-9]{1})\";\r\n parsedIndexes.year1 = index;\r\n break;\r\n case \"MMMM\":\r\n reg += \"(\" + this.getStringList(this._months()).join(\"|\") + \")\";\r\n parsedIndexes.monthLong = index;\r\n break;\r\n case \"MMM\":\r\n reg += \"(\" + this.getStringList(this._shortMonths()).join(\"|\") + \")\";\r\n parsedIndexes.monthShort = index;\r\n break;\r\n case \"MM\":\r\n case \"M\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.month = index;\r\n break;\r\n case \"ww\":\r\n case \"w\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.week = index;\r\n break;\r\n case \"dd\":\r\n case \"d\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.day = index;\r\n break;\r\n case \"DDD\":\r\n case \"DD\":\r\n case \"D\":\r\n reg += \"([0-9]{3}|[0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.yearDay = index;\r\n break;\r\n case \"dddd\":\r\n reg += \"(\" + this.getStringList(this._weekdays()).join(\"|\") + \")\";\r\n parsedIndexes.weekdayLong = index;\r\n break;\r\n case \"ddd\":\r\n reg += \"(\" + this.getStringList(this._shortWeekdays()).join(\"|\") + \")\";\r\n parsedIndexes.weekdayShort = index;\r\n break;\r\n case \"aaa\":\r\n case \"aa\":\r\n case \"a\":\r\n // TODO: fix (escape regex)\r\n reg += \"(\" + this.getStringList([\"AM\", \"PM\", \"A\\.M\\.\", \"P\\.M\\.\", \"A\", \"P\"]).join(\"|\") + \")\";\r\n parsedIndexes.am = index;\r\n break;\r\n case \"hh\":\r\n case \"h\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.hour12Base1 = index;\r\n break;\r\n case \"HH\":\r\n case \"H\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.hourBase0 = index;\r\n break;\r\n case \"KK\":\r\n case \"K\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.hour12Base0 = index;\r\n break;\r\n case \"kk\":\r\n case \"k\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.hourBase1 = index;\r\n break;\r\n case \"mm\":\r\n case \"m\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.minute = index;\r\n break;\r\n case \"ss\":\r\n case \"s\":\r\n reg += \"([0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.second = index;\r\n break;\r\n case \"SSS\":\r\n case \"SS\":\r\n case \"S\":\r\n reg += \"([0-9]{3}|[0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.millisecond = index;\r\n parsedIndexes.millisecondDigits = info.parts[i].length;\r\n break;\r\n case \"nnn\":\r\n case \"nn\":\r\n case \"n\":\r\n reg += \"([0-9]{3}|[0-9]{2}|[0-9]{1})\";\r\n parsedIndexes.millisecond = index;\r\n break;\r\n case \"x\":\r\n reg += \"([0-9]{1,})\";\r\n parsedIndexes.timestamp = index;\r\n break;\r\n case \"Z\":\r\n reg += \"GMT([-+]+[0-9]{2}:[0-9]{2})\";\r\n parsedIndexes.zone = index;\r\n break;\r\n case \"ZZ\":\r\n reg += \"([\\\\-+]+[0-9]{2}[0-9]{2})\";\r\n parsedIndexes.zone = index;\r\n break;\r\n case \"i\":\r\n reg += \"([0-9]{4})-?([0-9]{2})-?([0-9]{2})T?([0-9]{2}):?([0-9]{2}):?([0-9]{2})\\\\.?([0-9]{0,3})([zZ]|[+\\\\-][0-9]{2}:?[0-9]{2}|$)\";\r\n parsedIndexes.iso = index;\r\n indexAdjust += 7;\r\n break;\r\n case \"G\":\r\n case \"YYYY\":\r\n case \"YYY\":\r\n case \"YY\":\r\n case \"Y\":\r\n case \"MMMMM\":\r\n case \"W\":\r\n case \"EEEEE\":\r\n case \"EEEE\":\r\n case \"EEE\":\r\n case \"EE\":\r\n case \"E\":\r\n case \"eeeee\":\r\n case \"eeee\":\r\n case \"eee\":\r\n case \"ee\":\r\n case \"e\":\r\n case \"zzzz\":\r\n case \"zzz\":\r\n case \"zz\":\r\n case \"z\":\r\n case \"t\":\r\n // Ignore\r\n indexAdjust--;\r\n break;\r\n }\r\n reg += \"[^0-9]*\";\r\n }\r\n // Try matching\r\n let regex = new RegExp(reg);\r\n let matches = source.match(regex);\r\n if (matches) {\r\n // Populate the date object\r\n // Full year\r\n if (parsedIndexes.year > -1) {\r\n resValues.year = parseInt(matches[parsedIndexes.year]);\r\n }\r\n // 3-digit year\r\n if (parsedIndexes.year3 > -1) {\r\n let val = parseInt(matches[parsedIndexes.year3]);\r\n val += 1000;\r\n resValues.year = val;\r\n }\r\n // 2-digit year\r\n if (parsedIndexes.year2 > -1) {\r\n let val = parseInt(matches[parsedIndexes.year2]);\r\n if (val > 50) {\r\n val += 1000;\r\n }\r\n else {\r\n val += 2000;\r\n }\r\n resValues.year = val;\r\n }\r\n // 1-digit year\r\n if (parsedIndexes.year1 > -1) {\r\n let val = parseInt(matches[parsedIndexes.year1]);\r\n val = Math.floor((new Date().getFullYear()) / 10) * 10 + val;\r\n resValues.year = val;\r\n }\r\n // Full month\r\n if (parsedIndexes.monthLong > -1) {\r\n resValues.month = this.resolveMonth(matches[parsedIndexes.monthLong]);\r\n }\r\n // Short month\r\n if (parsedIndexes.monthShort > -1) {\r\n resValues.month = this.resolveShortMonth(matches[parsedIndexes.monthShort]);\r\n }\r\n // Numeric month\r\n if (parsedIndexes.month > -1) {\r\n resValues.month = parseInt(matches[parsedIndexes.month]) - 1;\r\n }\r\n // Weekday\r\n // @todo\r\n // Week\r\n if ((parsedIndexes.week > -1) && (parsedIndexes.day === -1)) {\r\n // We parse weeks ONLY if day is not explicitly set\r\n // TODO: this needs work\r\n // (but maybe later - I can hardly imagine anyone passing their dates in weeks)\r\n resValues.month = 0;\r\n resValues.day = $utils.getDayFromWeek(parseInt(matches[parsedIndexes.week]), resValues.year, 1, this._root.utc);\r\n }\r\n // Day\r\n if (parsedIndexes.day > -1) {\r\n resValues.day = parseInt(matches[parsedIndexes.day]);\r\n }\r\n // Year day\r\n if (parsedIndexes.yearDay > -1) {\r\n resValues.month = 0;\r\n resValues.day = parseInt(matches[parsedIndexes.yearDay]);\r\n }\r\n // 24 Hour (0-23)\r\n if (parsedIndexes.hourBase0 > -1) {\r\n resValues.hour = parseInt(matches[parsedIndexes.hourBase0]);\r\n }\r\n // 24 Hour (1-24)\r\n if (parsedIndexes.hourBase1 > -1) {\r\n resValues.hour = parseInt(matches[parsedIndexes.hourBase1]) - 1;\r\n }\r\n // 12 Hour (0-11)\r\n if (parsedIndexes.hour12Base0 > -1) {\r\n let val = parseInt(matches[parsedIndexes.hour12Base0]);\r\n if (val == 11) {\r\n val = 0;\r\n }\r\n if ((parsedIndexes.am > -1) && !this.isAm(matches[parsedIndexes.am])) {\r\n val += 12;\r\n }\r\n resValues.hour = val;\r\n }\r\n // 12 Hour (1-12)\r\n if (parsedIndexes.hour12Base1 > -1) {\r\n let val = parseInt(matches[parsedIndexes.hour12Base1]);\r\n if (val == 12) {\r\n val = 0;\r\n }\r\n if ((parsedIndexes.am > -1) && !this.isAm(matches[parsedIndexes.am])) {\r\n val += 12;\r\n }\r\n resValues.hour = val;\r\n }\r\n // Minute\r\n if (parsedIndexes.minute > -1) {\r\n resValues.minute = parseInt(matches[parsedIndexes.minute]);\r\n }\r\n // Second\r\n if (parsedIndexes.second > -1) {\r\n resValues.second = parseInt(matches[parsedIndexes.second]);\r\n }\r\n // Millisecond\r\n if (parsedIndexes.millisecond > -1) {\r\n let val = parseInt(matches[parsedIndexes.millisecond]);\r\n if (parsedIndexes.millisecondDigits == 2) {\r\n val *= 10;\r\n }\r\n else if (parsedIndexes.millisecondDigits == 1) {\r\n val *= 100;\r\n }\r\n resValues.millisecond = val;\r\n }\r\n // Timestamp\r\n if (parsedIndexes.timestamp > -1) {\r\n resValues.timestamp = parseInt(matches[parsedIndexes.timestamp]);\r\n const ts = new Date(resValues.timestamp);\r\n resValues.year = ts.getUTCFullYear();\r\n resValues.month = ts.getUTCMonth();\r\n resValues.day = ts.getUTCDate();\r\n resValues.hour = ts.getUTCHours();\r\n resValues.minute = ts.getUTCMinutes();\r\n resValues.second = ts.getUTCSeconds();\r\n resValues.millisecond = ts.getUTCMilliseconds();\r\n }\r\n // Adjust time zone\r\n if (parsedIndexes.zone > -1) {\r\n resValues.offset = this.resolveTimezoneOffset(new Date(resValues.year, resValues.month, resValues.day), matches[parsedIndexes.zone]);\r\n }\r\n // ISO\r\n if (parsedIndexes.iso > -1) {\r\n resValues.year = $type.toNumber(matches[parsedIndexes.iso + 0]);\r\n resValues.month = $type.toNumber(matches[parsedIndexes.iso + 1]) - 1;\r\n resValues.day = $type.toNumber(matches[parsedIndexes.iso + 2]);\r\n resValues.hour = $type.toNumber(matches[parsedIndexes.iso + 3]);\r\n resValues.minute = $type.toNumber(matches[parsedIndexes.iso + 4]);\r\n resValues.second = $type.toNumber(matches[parsedIndexes.iso + 5]);\r\n resValues.millisecond = $type.toNumber(matches[parsedIndexes.iso + 6]);\r\n if (matches[parsedIndexes.iso + 7] == \"Z\" || matches[parsedIndexes.iso + 7] == \"z\") {\r\n resValues.utc = true;\r\n }\r\n else if (matches[parsedIndexes.iso + 7] != \"\") {\r\n resValues.offset = this.resolveTimezoneOffset(new Date(resValues.year, resValues.month, resValues.day), matches[parsedIndexes.iso + 7]);\r\n }\r\n }\r\n // Create Date object\r\n if (resValues.utc) {\r\n res = new Date(Date.UTC(resValues.year, resValues.month, resValues.day, resValues.hour, resValues.minute, resValues.second, resValues.millisecond));\r\n }\r\n else {\r\n res = new Date(resValues.year, resValues.month, resValues.day, resValues.hour, resValues.minute + resValues.offset, resValues.second, resValues.millisecond);\r\n }\r\n }\r\n else {\r\n // Didn't match anything\r\n // Let's try dropping it into Date constructor and hope for the best\r\n res = new Date(source);\r\n }\r\n return res;\r\n }\r\n resolveTimezoneOffset(date, zone) {\r\n let value = zone.match(/([+\\-]?)([0-9]{2}):?([0-9]{2})/);\r\n if (value) {\r\n let match = zone.match(/([+\\-]?)([0-9]{2}):?([0-9]{2})/);\r\n let dir = match[1];\r\n let hour = match[2];\r\n let minute = match[3];\r\n let offset = parseInt(hour) * 60 + parseInt(minute);\r\n // Adjust offset\r\n // Making it negative does not seem to make sense, but it's right\r\n // because of how JavaScript calculates GMT offsets\r\n if (dir == \"+\") {\r\n offset *= -1;\r\n }\r\n // Check the difference in offset\r\n let originalOffset = (date || new Date()).getTimezoneOffset();\r\n let diff = offset - originalOffset;\r\n return diff;\r\n }\r\n return 0;\r\n }\r\n /**\r\n * Resolves month name (i.e. \"December\") into a month number (11).\r\n *\r\n * @param value Month name\r\n * @return Month number\r\n */\r\n resolveMonth(value) {\r\n // Let's try English first\r\n let month = this._months().indexOf(value);\r\n if (month > -1) {\r\n return month;\r\n }\r\n // Try the translation\r\n if (!this._root.language.isDefault()) {\r\n month = this._root.language.translateAll(this._months()).indexOf(value);\r\n if (month > -1) {\r\n return month;\r\n }\r\n }\r\n return 0;\r\n }\r\n /**\r\n * Resolves short month name (i.e. \"Dec\") into a month number.\r\n *\r\n * @param value Short month name\r\n * @return Month number\r\n */\r\n resolveShortMonth(value) {\r\n // Let's try English first\r\n let month = this._shortMonths().indexOf(value);\r\n if (month > -1) {\r\n return month;\r\n }\r\n // Maybe long month (workaround for May)\r\n month = this._months().indexOf(value);\r\n if (month > -1) {\r\n return month;\r\n }\r\n // Try the translation\r\n if (this._root.language && !this._root.language.isDefault()) {\r\n month = this._root.language.translateAll(this._shortMonths()).indexOf(value);\r\n if (month > -1) {\r\n return month;\r\n }\r\n }\r\n return 0;\r\n }\r\n /**\r\n * Checks if passed in string represents AM/PM notation in many of its\r\n * versions.\r\n *\r\n * @param value Source string\r\n * @return Is it AM/PM?\r\n */\r\n isAm(value) {\r\n let list = this.getStringList([\"AM\", \"A.M.\", \"A\"]);\r\n return list.indexOf(value.toUpperCase()) > -1;\r\n }\r\n /**\r\n * Translates list of strings.\r\n *\r\n * @param list Source strings\r\n * @return Translated strings\r\n */\r\n getStringList(list) {\r\n let res = [];\r\n for (let i = 0; i < list.length; i++) {\r\n // translate?\r\n if (this._root.language) {\r\n res.push($utils.escapeForRgex(this._t(list[i])));\r\n }\r\n else {\r\n res.push($utils.escapeForRgex(list[i]));\r\n }\r\n }\r\n return res;\r\n }\r\n}\r\n//# sourceMappingURL=DateFormatter.js.map","import { Entity } from \"./Entity\";\r\nimport { TextFormatter } from \"./TextFormatter\";\r\nimport * as $object from \"./Object\";\r\nimport * as $utils from \"./Utils\";\r\nimport * as $type from \"./Type\";\r\n/**\r\n * A class used to format numberic values as time duration.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/formatters/formatting-durations/} for more info\r\n */\r\nexport class DurationFormatter extends Entity {\r\n constructor() {\r\n super(...arguments);\r\n /**\r\n * Collection of aliases for units.\r\n */\r\n Object.defineProperty(this, \"_unitAliases\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {\r\n \"Y\": \"y\",\r\n \"D\": \"d\",\r\n \"H\": \"h\",\r\n \"K\": \"h\",\r\n \"k\": \"h\",\r\n \"n\": \"S\"\r\n }\r\n });\r\n }\r\n _setDefaults() {\r\n const dmillisecond = \"_duration_millisecond\";\r\n const dsecond = \"_duration_second\";\r\n const dminute = \"_duration_minute\";\r\n const dhour = \"_duration_hour\";\r\n const dday = \"_duration_day\";\r\n const dweek = \"_duration_week\";\r\n const dmonth = \"_duration_month\";\r\n const dyear = \"_duration_year\";\r\n const asecond = \"_second\";\r\n const aminute = \"_minute\";\r\n const ahour = \"_hour\";\r\n const aday = \"_day\";\r\n const aweek = \"_week\";\r\n const amonth = \"_week\";\r\n const ayear = \"_year\";\r\n // Defaults\r\n this._setDefault(\"negativeBase\", 0);\r\n this._setDefault(\"baseUnit\", \"second\");\r\n this._setDefault(\"durationFormats\", {\r\n \"millisecond\": {\r\n \"millisecond\": this._t(dmillisecond),\r\n \"second\": this._t((dmillisecond + asecond)),\r\n \"minute\": this._t((dmillisecond + aminute)),\r\n \"hour\": this._t((dmillisecond + ahour)),\r\n \"day\": this._t((dmillisecond + aday)),\r\n \"week\": this._t((dmillisecond + aweek)),\r\n \"month\": this._t((dmillisecond + amonth)),\r\n \"year\": this._t((dmillisecond + ayear))\r\n },\r\n \"second\": {\r\n \"second\": this._t((dsecond)),\r\n \"minute\": this._t((dsecond + aminute)),\r\n \"hour\": this._t((dsecond + ahour)),\r\n \"day\": this._t((dsecond + aday)),\r\n \"week\": this._t((dsecond + aweek)),\r\n \"month\": this._t((dsecond + amonth)),\r\n \"year\": this._t((dsecond + ayear))\r\n },\r\n \"minute\": {\r\n \"minute\": this._t((dminute)),\r\n \"hour\": this._t((dminute + ahour)),\r\n \"day\": this._t((dminute + aday)),\r\n \"week\": this._t((dminute + aweek)),\r\n \"month\": this._t((dminute + amonth)),\r\n \"year\": this._t((dminute + ayear))\r\n },\r\n \"hour\": {\r\n \"hour\": this._t((dhour)),\r\n \"day\": this._t((dhour + aday)),\r\n \"week\": this._t((dhour + aweek)),\r\n \"month\": this._t((dhour + amonth)),\r\n \"year\": this._t((dhour + ayear))\r\n },\r\n \"day\": {\r\n \"day\": this._t((dday)),\r\n \"week\": this._t((dday + aweek)),\r\n \"month\": this._t((dday + amonth)),\r\n \"year\": this._t((dday + ayear))\r\n },\r\n \"week\": {\r\n \"week\": this._t((dweek)),\r\n \"month\": this._t((dweek + amonth)),\r\n \"year\": this._t((dweek + ayear))\r\n },\r\n \"month\": {\r\n \"month\": this._t((dmonth)),\r\n \"year\": this._t((dmonth + ayear))\r\n },\r\n \"year\": {\r\n \"year\": this._t(dyear)\r\n }\r\n });\r\n super._setDefaults();\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n }\r\n /**\r\n * Formats the number as duration.\r\n *\r\n * For example `1000` (base unit seconds) would be converted to `16:40` as in\r\n * 16 minutes and 40 seconds.\r\n *\r\n * @param value Value to format\r\n * @param format Format to apply\r\n * @param base Override base unit\r\n * @return Formatted number\r\n */\r\n format(value, format, base) {\r\n // no base unit?\r\n let baseUnit = base || this.get(\"baseUnit\");\r\n // no format passed in or empty\r\n if (typeof format === \"undefined\" || format === \"\") {\r\n if (this.get(\"durationFormat\") != null) {\r\n format = this.get(\"durationFormat\");\r\n }\r\n else {\r\n format = this.getFormat($type.toNumber(value), undefined, baseUnit);\r\n }\r\n }\r\n // Clean format\r\n format = $utils.cleanFormat(format);\r\n // get format info (it will also deal with parser caching)\r\n let info = this.parseFormat(format, baseUnit);\r\n // cast to number just in case\r\n // TODO: maybe use better casting\r\n let source = Number(value);\r\n // format and replace the number\r\n let details;\r\n if (source > this.get(\"negativeBase\")) {\r\n details = info.positive;\r\n }\r\n else if (source < this.get(\"negativeBase\")) {\r\n details = info.negative;\r\n }\r\n else {\r\n details = info.zero;\r\n }\r\n // Format\r\n let formatted = this.applyFormat(source, details);\r\n // Apply color?\r\n if (details.color !== \"\") {\r\n formatted = \"[\" + details.color + \"]\" + formatted + \"[/]\";\r\n }\r\n return formatted;\r\n }\r\n /**\r\n * Parses supplied format into structured object which can be used to format\r\n * the number.\r\n *\r\n * @param format Format string, i.e. \"#,###.00\"\r\n * @param base Override base unit\r\n * @return Parsed information\r\n */\r\n parseFormat(format, base) {\r\n // Check cache\r\n // TODO\r\n // let cached = this.getCache(format);\r\n // if (cached != null) {\r\n // \treturn cached;\r\n // }\r\n // no base unit?\r\n let baseUnit = base || this.get(\"baseUnit\");\r\n // Initialize duration parsing info\r\n let info = {\r\n \"positive\": {\r\n \"color\": \"\",\r\n \"template\": \"\",\r\n \"parts\": [],\r\n \"source\": \"\",\r\n \"baseUnit\": baseUnit,\r\n \"parsed\": false,\r\n \"absolute\": false\r\n },\r\n \"negative\": {\r\n \"color\": \"\",\r\n \"template\": \"\",\r\n \"parts\": [],\r\n \"source\": \"\",\r\n \"baseUnit\": baseUnit,\r\n \"parsed\": false,\r\n \"absolute\": false\r\n },\r\n \"zero\": {\r\n \"color\": \"\",\r\n \"template\": \"\",\r\n \"parts\": [],\r\n \"source\": \"\",\r\n \"baseUnit\": baseUnit,\r\n \"parsed\": false,\r\n \"absolute\": false\r\n }\r\n };\r\n // Escape double vertical bars (that mean display one vertical bar)\r\n format = format.replace(\"||\", $type.PLACEHOLDER2);\r\n // Split it up and deal with different formats\r\n let parts = format.split(\"|\");\r\n info.positive.source = parts[0];\r\n if (typeof parts[2] === \"undefined\") {\r\n info.zero = info.positive;\r\n }\r\n else {\r\n info.zero.source = parts[2];\r\n }\r\n if (typeof parts[1] === \"undefined\") {\r\n info.negative = info.positive;\r\n }\r\n else {\r\n info.negative.source = parts[1];\r\n }\r\n // Parse each\r\n $object.each(info, (_part, item) => {\r\n // Already parsed\r\n if (item.parsed) {\r\n return;\r\n }\r\n // Check cached\r\n // TODO\r\n // if (typeof this.getCache(item.source) !== \"undefined\") {\r\n // \tinfo[part] = this.getCache(item.source);\r\n // \treturn;\r\n // }\r\n // Begin parsing\r\n let partFormat = item.source;\r\n // Check for [] directives\r\n let dirs = [];\r\n dirs = item.source.match(/^\\[([^\\]]*)\\]/);\r\n if (dirs && dirs.length && dirs[0] !== \"\") {\r\n partFormat = item.source.substr(dirs[0].length);\r\n item.color = dirs[1];\r\n }\r\n // Let TextFormatter split into chunks\r\n let chunks = TextFormatter.chunk(partFormat, true);\r\n for (let i = 0; i < chunks.length; i++) {\r\n let chunk = chunks[i];\r\n // replace back double vertical bar\r\n chunk.text = chunk.text.replace($type.PLACEHOLDER2, \"|\");\r\n if (chunk.type === \"value\") {\r\n // Just \"Duration\"?\r\n // if (chunk.text.toLowerCase() === \"duration\") {\r\n // \tchunk.text = durationFormat;\r\n // }\r\n // Check for \"a\" (absolute) modifier\r\n if (chunk.text.match(/[yYMdDwhHKkmsSn]+a/)) {\r\n item.absolute = true;\r\n chunk.text = chunk.text.replace(/([yYMdDwhHKkmsSn]+)a/, \"$1\");\r\n }\r\n // Find all possible parts\r\n let matches = chunk.text.match(/y+|Y+|M+|d+|D+|w+|h+|H+|K+|k+|m+|s+|S+|n+/g);\r\n if (matches) {\r\n // Populate template\r\n for (let x = 0; x < matches.length; x++) {\r\n // Is it an alias?\r\n if (matches[x] == null) {\r\n matches[x] = this._unitAliases[matches[x]];\r\n }\r\n item.parts.push(matches[x]);\r\n chunk.text = chunk.text.replace(matches[x], $type.PLACEHOLDER);\r\n }\r\n }\r\n }\r\n // Apply to template\r\n item.template += chunk.text;\r\n }\r\n // Apply style formatting\r\n //item.template = TextFormatter.format(item.template, this.outputFormat);\r\n // Save cache\r\n // TODO\r\n //this.setCache(item.source, item);\r\n // Mark this as parsed\r\n item.parsed = true;\r\n });\r\n // Save cache (the whole thing)\r\n // TODO\r\n //this.setCache(format, info);\r\n return info;\r\n }\r\n /**\r\n * Applies parsed format to a numeric value.\r\n *\r\n * @param value Value\r\n * @param details Parsed format as returned by {parseFormat}\r\n * @return Formatted duration\r\n */\r\n applyFormat(value, details) {\r\n // Use absolute values\r\n let negative = !details.absolute && (value < this.get(\"negativeBase\"));\r\n value = Math.abs(value);\r\n // Recalculate to milliseconds\r\n let tstamp = this.toTimeStamp(value, details.baseUnit);\r\n // Init return value\r\n let res = details.template;\r\n // Iterate through duration parts\r\n for (let i = 0, len = details.parts.length; i < len; i++) {\r\n // Gather the part\r\n let part = details.parts[i];\r\n let unit = this._toTimeUnit(part.substr(0, 1));\r\n let digits = part.length;\r\n // Calculate current unit value\r\n let ints;\r\n const unitValue = this._getUnitValue(unit);\r\n if (i < (len - 1)) {\r\n ints = Math.floor(tstamp / unitValue);\r\n }\r\n else {\r\n ints = Math.round(tstamp / unitValue);\r\n }\r\n res = res.replace($type.PLACEHOLDER, $utils.padString(ints, digits, \"0\"));\r\n // Reduce timestamp\r\n tstamp -= ints * unitValue;\r\n }\r\n // Reapply negative sign\r\n if (negative) {\r\n res = \"-\" + res;\r\n }\r\n return res;\r\n }\r\n /**\r\n * Converts numeric value to timestamp in milliseconds.\r\n *\r\n * @param value A source value\r\n * @param baseUnit Base unit the source value is in: \"q\", \"s\", \"i\", \"h\", \"d\", \"w\", \"m\", \"y\"\r\n * @return Value representation as a timestamp in milliseconds\r\n */\r\n toTimeStamp(value, baseUnit) {\r\n return value * this._getUnitValue(baseUnit);\r\n }\r\n _toTimeUnit(code) {\r\n switch (code) {\r\n case \"S\":\r\n return \"millisecond\";\r\n case \"s\":\r\n return \"second\";\r\n case \"m\":\r\n return \"minute\";\r\n case \"h\":\r\n return \"hour\";\r\n case \"d\":\r\n return \"day\";\r\n case \"w\":\r\n return \"week\";\r\n case \"M\":\r\n return \"month\";\r\n case \"y\":\r\n return \"year\";\r\n }\r\n ;\r\n }\r\n /**\r\n * Returns appropriate default format for the value.\r\n *\r\n * If `maxValue` is sepcified, it will use that value to determine the time\r\n * unit for the format.\r\n *\r\n * For example if your `baseUnit` is `\"second\"` and you pass in `10`, you\r\n * will get `\"10\"`.\r\n *\r\n * However, you might want it to be formatted in the context of bigger scale,\r\n * say 10 minutes (600 seconds). If you pass in `600` as `maxValue`, all\r\n * values, including small ones will use format with minutes, e.g.:\r\n * `00:10`, `00:50`, `12: 30`, etc.\r\n *\r\n * @param value Value to format\r\n * @param maxValue Maximum value to be used to determine format\r\n * @param baseUnit Base unit of the value\r\n * @return Format\r\n */\r\n getFormat(value, maxValue, baseUnit) {\r\n // Is format override set?\r\n if (this.get(\"durationFormat\") != null) {\r\n return this.get(\"durationFormat\");\r\n }\r\n // Get base unit\r\n if (!baseUnit) {\r\n baseUnit = this.get(\"baseUnit\");\r\n }\r\n if (maxValue != null && value != maxValue) {\r\n value = Math.abs(value);\r\n maxValue = Math.abs(maxValue);\r\n let maxUnit = this.getValueUnit(Math.max(value, maxValue), baseUnit);\r\n return this.get(\"durationFormats\")[baseUnit][maxUnit];\r\n }\r\n else {\r\n let unit = this.getValueUnit(value, baseUnit);\r\n return this.get(\"durationFormats\")[baseUnit][unit];\r\n }\r\n }\r\n /**\r\n * Returns value's closest denominator time unit, e.g 100 seconds is\r\n * `\"minute\"`, while 59 seconds would still be `second`.\r\n *\r\n * @param value Source duration value\r\n * @param baseUnit Base unit\r\n * @return Denominator\r\n */\r\n getValueUnit(value, baseUnit) {\r\n // Get base unit\r\n if (!baseUnit) {\r\n baseUnit = this.get(\"baseUnit\");\r\n }\r\n // Convert to milliseconds\r\n let currentUnit;\r\n let ms = this.getMilliseconds(value, baseUnit);\r\n $object.eachContinue(this._getUnitValues(), (key, val) => {\r\n if (key == baseUnit || currentUnit) {\r\n let num = ms / val;\r\n if (num <= 1) {\r\n if (!currentUnit) {\r\n currentUnit = key;\r\n }\r\n return false;\r\n }\r\n currentUnit = key;\r\n }\r\n return true;\r\n });\r\n return currentUnit;\r\n }\r\n /**\r\n * Converts value to milliseconds according to `baseUnit`.\r\n *\r\n * @param value Source duration value\r\n * @param baseUnit Base unit\r\n * @return Value in milliseconds\r\n */\r\n getMilliseconds(value, baseUnit) {\r\n // Get base unit\r\n if (!baseUnit) {\r\n baseUnit = this.get(\"baseUnit\");\r\n }\r\n return value * this._getUnitValue(baseUnit);\r\n }\r\n _getUnitValue(timeUnit) {\r\n return this._getUnitValues()[timeUnit];\r\n }\r\n _getUnitValues() {\r\n return {\r\n \"millisecond\": 1,\r\n \"second\": 1000,\r\n \"minute\": 60000,\r\n \"hour\": 3600000,\r\n \"day\": 86400000,\r\n \"week\": 604800000,\r\n \"month\": 2592000000,\r\n \"year\": 31536000000,\r\n };\r\n }\r\n}\r\n//# sourceMappingURL=DurationFormatter.js.map","/**\r\n * amCharts 5 locale\r\n *\r\n * Locale: en\r\n * Language: International English\r\n * Author: Martynas Majeris\r\n *\r\n * Follow instructions in [on this page](https://www.amcharts.com/docs/v5/tutorials/creating-translations/) to make corrections or add new translations.\r\n *\r\n * ---\r\n * Edit but leave the header section above this line. You can remove any\r\n * subsequent comment sections.\r\n * ---\r\n *\r\n * Use this file as a template to create translations. Leave the key part in\r\n * English intact. Fill the value with a translation.\r\n *\r\n * Empty string means no translation, so default \"International English\"\r\n * will be used.\r\n *\r\n * If you need the translation to literally be an empty string, use `null`\r\n * instead.\r\n *\r\n * IMPORTANT:\r\n * When translating make good effort to keep the translation length\r\n * at least the same chartcount as the English, especially for short prompts.\r\n *\r\n * Having significantly longer prompts may distort the actual charts.\r\n *\r\n * NOTE:\r\n * Some prompts - like months or weekdays - come in two versions: full and\r\n * shortened.\r\n *\r\n * If there's no official shortened version of these in your language, and it\r\n * would not be possible to invent such short versions that don't seem weird\r\n * to native speakers of that language, fill those with the same as full\r\n * version.\r\n *\r\n * PLACEHOLDERS:\r\n * Some prompts have placeholders like \"%1\". Those will be replaced by actual\r\n * values during translation and should be retained in the translated prompts.\r\n *\r\n * Placeholder positions may be changed to better suit structure of the\r\n * sentence.\r\n *\r\n * For example \"From %1 to %2\", when actually used will replace \"%1\" with an\r\n * actual value representing range start, and \"%2\" will be replaced by end\r\n * value.\r\n *\r\n * E.g. in a Scrollbar for Value axis \"From %1 to %2\" will become\r\n * \"From 100 to 200\". You may translate \"From\" and \"to\", as well as re-arrange\r\n * the order of the prompt itself, but make sure the \"%1\" and \"%2\" remain, in\r\n * places where they will make sense.\r\n *\r\n * Save the file as language_LOCALE, i.e. `en_GB.ts`, `fr_FR.ts`, etc.\r\n */\r\nexport default {\r\n \"firstDayOfWeek\": 1,\r\n // Number formatting options.\r\n // \r\n // Please check with the local standards which separator is accepted to be\r\n // used for separating decimals, and which for thousands.\r\n \"_decimalSeparator\": \".\",\r\n \"_thousandSeparator\": \",\",\r\n // Position of the percent sign in numbers\r\n \"_percentPrefix\": null,\r\n \"_percentSuffix\": \"%\",\r\n // Suffixes for numbers\r\n // When formatting numbers, big or small numers might be reformatted to\r\n // shorter version, by applying a suffix.\r\n // \r\n // For example, 1000000 might become \"1m\".\r\n // Or 1024 might become \"1KB\" if we're formatting byte numbers.\r\n // \r\n // This section defines such suffixes for all such cases.\r\n \"_big_number_suffix_3\": \"k\",\r\n \"_big_number_suffix_6\": \"M\",\r\n \"_big_number_suffix_9\": \"G\",\r\n \"_big_number_suffix_12\": \"T\",\r\n \"_big_number_suffix_15\": \"P\",\r\n \"_big_number_suffix_18\": \"E\",\r\n \"_big_number_suffix_21\": \"Z\",\r\n \"_big_number_suffix_24\": \"Y\",\r\n \"_small_number_suffix_3\": \"m\",\r\n \"_small_number_suffix_6\": \"μ\",\r\n \"_small_number_suffix_9\": \"n\",\r\n \"_small_number_suffix_12\": \"p\",\r\n \"_small_number_suffix_15\": \"f\",\r\n \"_small_number_suffix_18\": \"a\",\r\n \"_small_number_suffix_21\": \"z\",\r\n \"_small_number_suffix_24\": \"y\",\r\n \"_byte_suffix_B\": \"B\",\r\n \"_byte_suffix_KB\": \"KB\",\r\n \"_byte_suffix_MB\": \"MB\",\r\n \"_byte_suffix_GB\": \"GB\",\r\n \"_byte_suffix_TB\": \"TB\",\r\n \"_byte_suffix_PB\": \"PB\",\r\n // Default date formats for various periods.\r\n // \r\n // This should reflect official or de facto formatting universally accepted\r\n // in the country translation is being made for\r\n // Available format codes here:\r\n // https://www.amcharts.com/docs/v5/concepts/formatters/formatting-dates/#Format_codes\r\n // \r\n // This will be used when formatting date/time for particular granularity,\r\n // e.g. \"_date_hour\" will be shown whenever we need to show time as hours.\r\n // \r\n // \"date\" is used as in default date format when showing standalone dates.\r\n \"_date\": \"yyyy-MM-dd\",\r\n \"_date_millisecond\": \"mm:ss SSS\",\r\n \"_date_millisecond_full\": \"HH:mm:ss SSS\",\r\n \"_date_second\": \"HH:mm:ss\",\r\n \"_date_second_full\": \"HH:mm:ss\",\r\n \"_date_minute\": \"HH:mm\",\r\n \"_date_minute_full\": \"HH:mm - MMM dd, yyyy\",\r\n \"_date_hour\": \"HH:mm\",\r\n \"_date_hour_full\": \"HH:mm - MMM dd, yyyy\",\r\n \"_date_day\": \"MMM dd\",\r\n \"_date_day_full\": \"MMM dd, yyyy\",\r\n \"_date_week\": \"ww\",\r\n \"_date_week_full\": \"MMM dd, yyyy\",\r\n \"_date_month\": \"MMM\",\r\n \"_date_month_full\": \"MMM, yyyy\",\r\n \"_date_year\": \"yyyy\",\r\n // Default duration formats for various base units.\r\n // \r\n // This will be used by DurationFormatter to format numeric values into\r\n // duration.\r\n // \r\n // Notice how each duration unit comes in several versions. This is to ensure\r\n // that each base unit is shown correctly.\r\n // \r\n // For example, if we have baseUnit set to \"second\", meaning our duration is\r\n // in seconds.\r\n // \r\n // If we pass in `50` to formatter, it will know that we have just 50 seconds\r\n // (less than a minute) so it will use format in `\"_duration_second\"` (\"ss\"),\r\n // and the formatted result will be in like `\"50\"`.\r\n // \r\n // If we pass in `70`, which is more than a minute, the formatter will switch\r\n // to `\"_duration_second_minute\"` (\"mm:ss\"), resulting in \"01:10\" formatted\r\n // text.\r\n // \r\n // Available codes here:\r\n // https://www.amcharts.com/docs/v4/concepts/formatters/formatting-duration/#Available_Codes\r\n \"_duration_millisecond\": \"SSS\",\r\n \"_duration_millisecond_second\": \"ss.SSS\",\r\n \"_duration_millisecond_minute\": \"mm:ss SSS\",\r\n \"_duration_millisecond_hour\": \"hh:mm:ss SSS\",\r\n \"_duration_millisecond_day\": \"d'd' mm:ss SSS\",\r\n \"_duration_millisecond_week\": \"d'd' mm:ss SSS\",\r\n \"_duration_millisecond_month\": \"M'm' dd'd' mm:ss SSS\",\r\n \"_duration_millisecond_year\": \"y'y' MM'm' dd'd' mm:ss SSS\",\r\n \"_duration_second\": \"ss\",\r\n \"_duration_second_minute\": \"mm:ss\",\r\n \"_duration_second_hour\": \"hh:mm:ss\",\r\n \"_duration_second_day\": \"d'd' hh:mm:ss\",\r\n \"_duration_second_week\": \"d'd' hh:mm:ss\",\r\n \"_duration_second_month\": \"M'm' dd'd' hh:mm:ss\",\r\n \"_duration_second_year\": \"y'y' MM'm' dd'd' hh:mm:ss\",\r\n \"_duration_minute\": \"mm\",\r\n \"_duration_minute_hour\": \"hh:mm\",\r\n \"_duration_minute_day\": \"d'd' hh:mm\",\r\n \"_duration_minute_week\": \"d'd' hh:mm\",\r\n \"_duration_minute_month\": \"M'm' dd'd' hh:mm\",\r\n \"_duration_minute_year\": \"y'y' MM'm' dd'd' hh:mm\",\r\n \"_duration_hour\": \"hh'h'\",\r\n \"_duration_hour_day\": \"d'd' hh'h'\",\r\n \"_duration_hour_week\": \"d'd' hh'h'\",\r\n \"_duration_hour_month\": \"M'm' dd'd' hh'h'\",\r\n \"_duration_hour_year\": \"y'y' MM'm' dd'd' hh'h'\",\r\n \"_duration_day\": \"d'd'\",\r\n \"_duration_day_week\": \"d'd'\",\r\n \"_duration_day_month\": \"M'm' dd'd'\",\r\n \"_duration_day_year\": \"y'y' MM'm' dd'd'\",\r\n \"_duration_week\": \"w'w'\",\r\n \"_duration_week_month\": \"w'w'\",\r\n \"_duration_week_year\": \"w'w'\",\r\n \"_duration_month\": \"M'm'\",\r\n \"_duration_month_year\": \"y'y' MM'm'\",\r\n \"_duration_year\": \"y'y'\",\r\n // Era translations\r\n \"_era_ad\": \"AD\",\r\n \"_era_bc\": \"BC\",\r\n // Day part, used in 12-hour formats, e.g. 5 P.M.\r\n // Please note that these come in 3 variants:\r\n // * one letter (e.g. \"A\")\r\n // * two letters (e.g. \"AM\")\r\n // * two letters with dots (e.g. \"A.M.\")\r\n // \r\n // All three need to to be translated even if they are all the same. Some\r\n // users might use one, some the other.\r\n \"A\": \"\",\r\n \"P\": \"\",\r\n \"AM\": \"\",\r\n \"PM\": \"\",\r\n \"A.M.\": \"\",\r\n \"P.M.\": \"\",\r\n // Date-related stuff.\r\n // \r\n // When translating months, if there's a difference, use the form which is\r\n // best for a full date, e.g. as you would use it in \"2018 January 1\".\r\n // \r\n // Note that May is listed twice. This is because in English May is the same\r\n // in both long and short forms, while in other languages it may not be the\r\n // case. Translate \"May\" to full word, while \"May(short)\" to shortened\r\n // version.\r\n // \r\n // Should month names and weekdays be capitalized or not?\r\n // \r\n // Rule of thumb is this: if the names should always be capitalized,\r\n // regardless of name position within date (\"January\", \"21st January 2018\",\r\n // etc.) use capitalized names. Otherwise enter all lowercase.\r\n // \r\n // The date formatter will automatically capitalize names if they are the\r\n // first (or only) word in resulting date.\r\n \"January\": \"\",\r\n \"February\": \"\",\r\n \"March\": \"\",\r\n \"April\": \"\",\r\n \"May\": \"\",\r\n \"June\": \"\",\r\n \"July\": \"\",\r\n \"August\": \"\",\r\n \"September\": \"\",\r\n \"October\": \"\",\r\n \"November\": \"\",\r\n \"December\": \"\",\r\n \"Jan\": \"\",\r\n \"Feb\": \"\",\r\n \"Mar\": \"\",\r\n \"Apr\": \"\",\r\n \"May(short)\": \"May\",\r\n \"Jun\": \"\",\r\n \"Jul\": \"\",\r\n \"Aug\": \"\",\r\n \"Sep\": \"\",\r\n \"Oct\": \"\",\r\n \"Nov\": \"\",\r\n \"Dec\": \"\",\r\n // Weekdays.\r\n \"Sunday\": \"\",\r\n \"Monday\": \"\",\r\n \"Tuesday\": \"\",\r\n \"Wednesday\": \"\",\r\n \"Thursday\": \"\",\r\n \"Friday\": \"\",\r\n \"Saturday\": \"\",\r\n \"Sun\": \"\",\r\n \"Mon\": \"\",\r\n \"Tue\": \"\",\r\n \"Wed\": \"\",\r\n \"Thu\": \"\",\r\n \"Fri\": \"\",\r\n \"Sat\": \"\",\r\n // Date ordinal function.\r\n // \r\n // This is used when adding number ordinal when formatting days in dates.\r\n // \r\n // E.g. \"January 1st\", \"February 2nd\".\r\n // \r\n // The function accepts day number, and returns a string to be added to the\r\n // day, like in default English translation, if we pass in 2, we will receive\r\n // \"nd\" back.\r\n \"_dateOrd\": function (day) {\r\n let res = \"th\";\r\n if ((day < 11) || (day > 13)) {\r\n switch (day % 10) {\r\n case 1:\r\n res = \"st\";\r\n break;\r\n case 2:\r\n res = \"nd\";\r\n break;\r\n case 3:\r\n res = \"rd\";\r\n break;\r\n }\r\n }\r\n return res;\r\n },\r\n // Various chart controls.\r\n // Shown as a tooltip on zoom out button.\r\n \"Zoom Out\": \"\",\r\n // Timeline buttons\r\n \"Play\": \"\",\r\n \"Stop\": \"\",\r\n // Chart's Legend screen reader title.\r\n \"Legend\": \"\",\r\n // Legend's item screen reader indicator.\r\n \"Press ENTER to toggle\": \"\",\r\n // Shown when the chart is busy loading something.\r\n \"Loading\": \"\",\r\n // Shown as the first button in the breadcrumb navigation, e.g.:\r\n // Home > First level > ...\r\n \"Home\": \"\",\r\n // Chart types.\r\n // Those are used as default screen reader titles for the main chart element\r\n // unless developer has set some more descriptive title.\r\n \"Chart\": \"\",\r\n \"Serial chart\": \"\",\r\n \"X/Y chart\": \"\",\r\n \"Pie chart\": \"\",\r\n \"Gauge chart\": \"\",\r\n \"Radar chart\": \"\",\r\n \"Sankey diagram\": \"\",\r\n \"Flow diagram\": \"\",\r\n \"Chord diagram\": \"\",\r\n \"TreeMap chart\": \"\",\r\n \"Force directed tree\": \"\",\r\n \"Sliced chart\": \"\",\r\n // Series types.\r\n // Used to name series by type for screen readers if they do not have their\r\n // name set.\r\n \"Series\": \"\",\r\n \"Candlestick Series\": \"\",\r\n \"OHLC Series\": \"\",\r\n \"Column Series\": \"\",\r\n \"Line Series\": \"\",\r\n \"Pie Slice Series\": \"\",\r\n \"Funnel Series\": \"\",\r\n \"Pyramid Series\": \"\",\r\n \"X/Y Series\": \"\",\r\n // Map-related stuff.\r\n \"Map\": \"\",\r\n \"Press ENTER to zoom in\": \"\",\r\n \"Press ENTER to zoom out\": \"\",\r\n \"Use arrow keys to zoom in and out\": \"\",\r\n \"Use plus and minus keys on your keyboard to zoom in and out\": \"\",\r\n // Export-related stuff.\r\n // These prompts are used in Export menu labels.\r\n // \r\n // \"Export\" is the top-level menu item.\r\n // \r\n // \"Image\", \"Data\", \"Print\" as second-level indicating type of export\r\n // operation.\r\n // \r\n // Leave actual format untranslated, unless you absolutely know that they\r\n // would convey more meaning in some other way.\r\n \"Export\": \"\",\r\n \"Image\": \"\",\r\n \"Data\": \"\",\r\n \"Print\": \"\",\r\n \"Press ENTER or use arrow keys to navigate\": \"\",\r\n \"Press ENTER to open\": \"\",\r\n \"Press ENTER to print.\": \"\",\r\n \"Press ENTER to export as %1.\": \"\",\r\n \"(Press ESC to close this message)\": \"\",\r\n \"Image Export Complete\": \"\",\r\n \"Export operation took longer than expected. Something might have gone wrong.\": \"\",\r\n \"Saved from\": \"\",\r\n \"PNG\": \"\",\r\n \"JPG\": \"\",\r\n \"GIF\": \"\",\r\n \"SVG\": \"\",\r\n \"PDF\": \"\",\r\n \"JSON\": \"\",\r\n \"CSV\": \"\",\r\n \"XLSX\": \"\",\r\n \"HTML\": \"\",\r\n // Scrollbar-related stuff.\r\n // \r\n // Scrollbar is a control which can zoom and pan the axes on the chart.\r\n // \r\n // Each scrollbar has two grips: left or right (for horizontal scrollbar) or\r\n // upper and lower (for vertical one).\r\n // \r\n // Prompts change in relation to whether Scrollbar is vertical or horizontal.\r\n // \r\n // The final section is used to indicate the current range of selection.\r\n \"Use TAB to select grip buttons or left and right arrows to change selection\": \"\",\r\n \"Use left and right arrows to move selection\": \"\",\r\n \"Use left and right arrows to move left selection\": \"\",\r\n \"Use left and right arrows to move right selection\": \"\",\r\n \"Use TAB select grip buttons or up and down arrows to change selection\": \"\",\r\n \"Use up and down arrows to move selection\": \"\",\r\n \"Use up and down arrows to move lower selection\": \"\",\r\n \"Use up and down arrows to move upper selection\": \"\",\r\n \"From %1 to %2\": \"\",\r\n \"From %1\": \"\",\r\n \"To %1\": \"\",\r\n // Data loader-related.\r\n \"No parser available for file: %1\": \"\",\r\n \"Error parsing file: %1\": \"\",\r\n \"Unable to load file: %1\": \"\",\r\n \"Invalid date\": \"\",\r\n // Common actions\r\n \"Close\": \"\",\r\n \"Minimize\": \"\"\r\n};\r\n//# sourceMappingURL=en.js.map","import { Entity } from \"./Entity\";\r\nimport * as $array from \"./Array\";\r\nimport * as $object from \"./Object\";\r\nimport en from \"../../../locales/en\";\r\n;\r\n/**\r\n * Add localization functionality.\r\n */\r\nexport class Language extends Entity {\r\n _setDefaults() {\r\n this.setPrivate(\"defaultLocale\", en);\r\n super._setDefaults();\r\n }\r\n /**\r\n * Returns a prompt translation.\r\n *\r\n * @param prompt Prompt to translate\r\n * @param locale Target locale\r\n * @param ...rest Parameters\r\n * @return Translation\r\n */\r\n translate(prompt, locale, ...rest) {\r\n // Get langauge\r\n if (!locale) {\r\n locale = this._root.locale || this.getPrivate(\"defaultLocale\");\r\n }\r\n // Init translation\r\n let translation = prompt;\r\n let value = locale[prompt];\r\n // Try to look for the translation\r\n if (value === null) {\r\n translation = \"\";\r\n }\r\n else if (value != null) {\r\n // It might be an empty string\r\n if (value) {\r\n translation = value;\r\n }\r\n }\r\n else if (locale !== this.getPrivate(\"defaultLocale\")) {\r\n // Try to look in default language\r\n return this.translate(prompt, this.getPrivate(\"defaultLocale\"), ...rest);\r\n }\r\n // Replace %1, %2, etc params\r\n if (rest.length) {\r\n for (let len = rest.length, i = 0; i < len; ++i) {\r\n translation = translation.split(\"%\" + (i + 1)).join(rest[i]);\r\n }\r\n }\r\n // Return the translation\r\n return translation;\r\n }\r\n /**\r\n * Returns a prompt translation, including custom prompts.\r\n *\r\n * @param prompt Prompt to translate\r\n * @param locale Target locale\r\n * @param ...rest Parameters\r\n * @return Translation\r\n */\r\n translateAny(prompt, locale, ...rest) {\r\n return this.translate(prompt, locale, ...rest);\r\n }\r\n /**\r\n * Add a custom prompt to locale.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/locales/creating-translations/#Extending_locale_with_custom_prompts}\r\n * @param prompt Source prompt\r\n * @param translation Tanslation\r\n * @param locale Target locale\r\n */\r\n setTranslationAny(prompt, translation, locale) {\r\n const localeTarget = locale || this._root.locale;\r\n localeTarget[prompt] = translation;\r\n }\r\n /**\r\n * Add a batch of custom prompts.\r\n *\r\n * @since 5.3.3\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/locales/creating-translations/#Extending_locale_with_custom_prompts}\r\n * @param translations Translations\r\n * @param locale Target locale\r\n */\r\n setTranslationsAny(translations, locale) {\r\n $object.each(translations, (key, val) => {\r\n this.setTranslationAny(key, val, locale);\r\n });\r\n }\r\n translateEmpty(prompt, locale, ...rest) {\r\n let translation = this.translate(prompt, locale, ...rest);\r\n return translation == prompt ? \"\" : translation;\r\n }\r\n translateFunc(prompt, locale) {\r\n if (this._root.locale[prompt]) {\r\n return this._root.locale[prompt];\r\n }\r\n // Try to look in default language\r\n if (locale !== this.getPrivate(\"defaultLocale\")) {\r\n return this.translateFunc(prompt, this.getPrivate(\"defaultLocale\"));\r\n }\r\n // Fail - return empty function\r\n return () => {\r\n return \"\";\r\n };\r\n }\r\n /**\r\n * Translates a btach of prompts.\r\n *\r\n * @param list Array of prompts to translate\r\n * @param locale Target locale\r\n * @return Array of translations\r\n */\r\n translateAll(list, locale) {\r\n // Translate all items in the list\r\n if (!this.isDefault()) {\r\n return $array.map(list, (x) => this.translate(x, locale));\r\n }\r\n else {\r\n return list;\r\n }\r\n }\r\n /**\r\n * Returns `true` if the currently selected locale is a default locale.\r\n *\r\n * @return `true` if locale is default; `false` if it is not.\r\n */\r\n isDefault() {\r\n return this.getPrivate(\"defaultLocale\") === this._root.locale;\r\n }\r\n}\r\n//# sourceMappingURL=Language.js.map","import { Template } from \"./util/Template\";\r\nimport * as $order from \"./util/Order\";\r\nimport * as $array from \"./util/Array\";\r\n/**\r\n * A base class for an amCharts theme.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/themes/} for more info\r\n * @important\r\n */\r\nexport class Theme {\r\n constructor(root, isReal) {\r\n Object.defineProperty(this, \"_root\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_rules\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n this._root = root;\r\n if (!isReal) {\r\n throw new Error(\"You cannot use `new Class()`, instead use `Class.new()`\");\r\n }\r\n }\r\n /**\r\n * Use this method to create an instance of this class.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/#New_element_syntax} for more info\r\n * @param root Root element\r\n * @param settings Settings\r\n * @param template Template\r\n * @return Instantiated object\r\n */\r\n static new(root) {\r\n const x = (new this(root, true));\r\n x.setupDefaultRules();\r\n return x;\r\n }\r\n setupDefaultRules() { }\r\n /**\r\n * Looks up the rules for a specific theme class.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/themes/} for more info\r\n * @param themeClass Theme class\r\n * @return Array>\r\n */\r\n _lookupRules(themeClass) {\r\n return this._rules[themeClass];\r\n }\r\n /**\r\n * Creates a [[Template]] for specific theme class and tags.\r\n *\r\n * NOTE: the difference from `rule()` is that `ruleRaw()` does not do any\r\n * type checks.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/themes/} for more info\r\n * @param themeClass Theme class\r\n * @param themeTags Theme tags\r\n * @return Template\r\n */\r\n ruleRaw(themeClass, themeTags = []) {\r\n let rules = this._rules[themeClass];\r\n if (!rules) {\r\n rules = this._rules[themeClass] = [];\r\n }\r\n themeTags.sort($order.compare);\r\n const { index, found } = $array.getSortedIndex(rules, (x) => {\r\n const order = $order.compare(x.tags.length, themeTags.length);\r\n if (order === 0) {\r\n return $order.compareArray(x.tags, themeTags, $order.compare);\r\n }\r\n else {\r\n return order;\r\n }\r\n });\r\n if (found) {\r\n return rules[index].template;\r\n }\r\n else {\r\n const template = Template.new({});\r\n rules.splice(index, 0, {\r\n tags: themeTags,\r\n template,\r\n });\r\n return template;\r\n }\r\n }\r\n /**\r\n * Creates a [[Template]] for specific theme class and tags.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/themes/} for more info\r\n * @param themeClass Theme class\r\n * @param themeTags Theme tags\r\n * @return Template\r\n */\r\n rule(themeClass, themeTags = []) {\r\n return this.ruleRaw(themeClass, themeTags);\r\n }\r\n}\r\n//# sourceMappingURL=Theme.js.map","import { Theme } from \"../core/Theme\";\r\nimport { p100, p50 } from \"../core/util/Percent\";\r\nimport { Color } from \"../core/util/Color\";\r\nimport { GridLayout } from \"../core/render/GridLayout\";\r\nimport * as $ease from \"../core/util/Ease\";\r\n/**\r\n * @ignore\r\n */\r\nexport function setColor(rule, key, ic, name) {\r\n // TODO this shouldn't use get, figure out a better way\r\n rule.set(key, ic.get(name));\r\n ic.on(name, (value) => {\r\n rule.set(key, value);\r\n });\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class DefaultTheme extends Theme {\r\n setupDefaultRules() {\r\n super.setupDefaultRules();\r\n const language = this._root.language;\r\n const ic = this._root.interfaceColors;\r\n const horizontalLayout = this._root.horizontalLayout;\r\n const verticalLayout = this._root.verticalLayout;\r\n const r = this.rule.bind(this);\r\n /**\r\n * ========================================================================\r\n * core\r\n * ========================================================================\r\n */\r\n r(\"InterfaceColors\").setAll({\r\n stroke: Color.fromHex(0xe5e5e5),\r\n fill: Color.fromHex(0xf3f3f3),\r\n primaryButton: Color.fromHex(0x6794dc),\r\n primaryButtonHover: Color.fromHex(0x6771dc),\r\n primaryButtonDown: Color.fromHex(0x68dc76),\r\n primaryButtonActive: Color.fromHex(0x68dc76),\r\n primaryButtonDisabled: Color.fromHex(0xdadada),\r\n primaryButtonTextDisabled: Color.fromHex(0xffffff),\r\n primaryButtonText: Color.fromHex(0xffffff),\r\n primaryButtonStroke: Color.fromHex(0xffffff),\r\n secondaryButton: Color.fromHex(0xd9d9d9),\r\n secondaryButtonHover: Color.fromHex(0xa3a3a3),\r\n secondaryButtonDown: Color.fromHex(0x8d8d8d),\r\n secondaryButtonActive: Color.fromHex(0xe6e6e6),\r\n secondaryButtonText: Color.fromHex(0x000000),\r\n secondaryButtonStroke: Color.fromHex(0xffffff),\r\n grid: Color.fromHex(0x000000),\r\n background: Color.fromHex(0xffffff),\r\n alternativeBackground: Color.fromHex(0x000000),\r\n text: Color.fromHex(0x000000),\r\n alternativeText: Color.fromHex(0xffffff),\r\n disabled: Color.fromHex(0xadadad),\r\n positive: Color.fromHex(0x50b300),\r\n negative: Color.fromHex(0xb30000)\r\n });\r\n {\r\n const rule = r(\"ColorSet\");\r\n rule.setAll({\r\n passOptions: {\r\n hue: 0.05,\r\n saturation: 0,\r\n lightness: 0\r\n },\r\n colors: [\r\n Color.fromHex(0x67b7dc)\r\n ],\r\n step: 1,\r\n //baseColor: Color.fromRGB(103, 183, 220),\r\n //count: 20,\r\n reuse: false,\r\n startIndex: 0\r\n });\r\n rule.setPrivate(\"currentStep\", 0);\r\n rule.setPrivate(\"currentPass\", 0);\r\n }\r\n r(\"Entity\").setAll({\r\n stateAnimationDuration: 0,\r\n stateAnimationEasing: $ease.out($ease.cubic)\r\n });\r\n r(\"Component\").setAll({\r\n interpolationDuration: 0,\r\n interpolationEasing: $ease.out($ease.cubic)\r\n });\r\n r(\"Sprite\").setAll({\r\n visible: true,\r\n scale: 1,\r\n opacity: 1,\r\n rotation: 0,\r\n position: \"relative\",\r\n tooltipX: p50,\r\n tooltipY: p50,\r\n tooltipPosition: \"fixed\",\r\n isMeasured: true\r\n });\r\n r(\"Sprite\").states.create(\"default\", { \"visible\": true, opacity: 1 });\r\n r(\"Container\").setAll({\r\n interactiveChildren: true,\r\n setStateOnChildren: false\r\n });\r\n r(\"Graphics\").setAll({\r\n strokeWidth: 1\r\n });\r\n r(\"Chart\").setAll({\r\n width: p100,\r\n height: p100,\r\n interactiveChildren: false\r\n });\r\n r(\"ZoomableContainer\").setAll({\r\n width: p100,\r\n height: p100,\r\n wheelable: true,\r\n pinchZoom: true,\r\n maxZoomLevel: 32,\r\n minZoomLevel: 1,\r\n zoomStep: 2,\r\n animationEasing: $ease.out($ease.cubic),\r\n animationDuration: 600,\r\n maxPanOut: 0.4\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: alignment\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Sprite\", [\"horizontal\", \"center\"]).setAll({\r\n centerX: p50,\r\n x: p50\r\n });\r\n r(\"Sprite\", [\"vertical\", \"center\"]).setAll({\r\n centerY: p50,\r\n y: p50\r\n });\r\n r(\"Container\", [\"horizontal\", \"layout\"]).setAll({\r\n layout: horizontalLayout\r\n });\r\n r(\"Container\", [\"vertical\", \"layout\"]).setAll({\r\n layout: verticalLayout\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: patterns\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Pattern\").setAll({\r\n repetition: \"repeat\",\r\n width: 50,\r\n height: 50,\r\n rotation: 0,\r\n fillOpacity: 1\r\n });\r\n r(\"LinePattern\").setAll({\r\n gap: 6,\r\n colorOpacity: 1,\r\n width: 49,\r\n height: 49\r\n });\r\n r(\"RectanglePattern\").setAll({\r\n gap: 6,\r\n checkered: false,\r\n centered: true,\r\n maxWidth: 5,\r\n maxHeight: 5,\r\n width: 48,\r\n height: 48,\r\n strokeWidth: 0\r\n });\r\n r(\"CirclePattern\").setAll({\r\n gap: 5,\r\n checkered: false,\r\n centered: false,\r\n radius: 3,\r\n strokeWidth: 0,\r\n width: 45,\r\n height: 45\r\n });\r\n r(\"GrainPattern\").setAll({\r\n width: 200,\r\n height: 200,\r\n colors: [Color.fromHex(0x000000)],\r\n size: 1,\r\n horizontalGap: 0,\r\n verticalGap: 0,\r\n density: 1,\r\n minOpacity: 0,\r\n maxOpacity: 0.2\r\n });\r\n {\r\n const rule = r(\"PatternSet\");\r\n rule.setAll({\r\n step: 1\r\n });\r\n setColor(rule, \"color\", ic, \"stroke\");\r\n }\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: gradients\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"LinearGradient\").setAll({\r\n rotation: 90\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: Legend\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Legend\").setAll({\r\n fillField: \"fill\",\r\n strokeField: \"stroke\",\r\n nameField: \"name\",\r\n layout: GridLayout.new(this._root, {}),\r\n layer: 30,\r\n clickTarget: \"itemContainer\"\r\n });\r\n // Class: Container\r\n r(\"Container\", [\"legend\", \"item\", \"itemcontainer\"]).setAll({\r\n paddingLeft: 5,\r\n paddingRight: 5,\r\n paddingBottom: 5,\r\n paddingTop: 5,\r\n layout: horizontalLayout,\r\n setStateOnChildren: true,\r\n interactiveChildren: false,\r\n ariaChecked: true,\r\n focusable: true,\r\n ariaLabel: language.translate(\"Press ENTER to toggle\"),\r\n role: \"checkbox\"\r\n });\r\n {\r\n const rule = r(\"Rectangle\", [\"legend\", \"item\", \"background\"]);\r\n rule.setAll({\r\n fillOpacity: 0,\r\n });\r\n setColor(rule, \"fill\", ic, \"background\");\r\n }\r\n r(\"Container\", [\"legend\", \"marker\"]).setAll({\r\n setStateOnChildren: true,\r\n centerY: p50,\r\n paddingLeft: 0,\r\n paddingRight: 0,\r\n paddingBottom: 0,\r\n paddingTop: 0,\r\n width: 18,\r\n height: 18\r\n });\r\n r(\"RoundedRectangle\", [\"legend\", \"marker\", \"rectangle\"]).setAll({\r\n width: p100,\r\n height: p100,\r\n cornerRadiusBL: 3,\r\n cornerRadiusTL: 3,\r\n cornerRadiusBR: 3,\r\n cornerRadiusTR: 3\r\n });\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"legend\", \"marker\", \"rectangle\"]).states.create(\"disabled\", {});\r\n setColor(rule, \"fill\", ic, \"disabled\");\r\n setColor(rule, \"stroke\", ic, \"disabled\");\r\n }\r\n r(\"Label\", [\"legend\", \"label\"]).setAll({\r\n centerY: p50,\r\n marginLeft: 5,\r\n paddingRight: 0,\r\n paddingLeft: 0,\r\n paddingTop: 0,\r\n paddingBottom: 0,\r\n populateText: true\r\n });\r\n {\r\n const rule = r(\"Label\", [\"legend\", \"label\"]).states.create(\"disabled\", {});\r\n setColor(rule, \"fill\", ic, \"disabled\");\r\n }\r\n r(\"Label\", [\"legend\", \"value\", \"label\"]).setAll({\r\n centerY: p50,\r\n marginLeft: 5,\r\n paddingRight: 0,\r\n paddingLeft: 0,\r\n paddingTop: 0,\r\n paddingBottom: 0,\r\n width: 50,\r\n centerX: p100,\r\n populateText: true\r\n });\r\n {\r\n const rule = r(\"Label\", [\"legend\", \"value\", \"label\"]).states.create(\"disabled\", {});\r\n setColor(rule, \"fill\", ic, \"disabled\");\r\n }\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: HeatLegend\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"HeatLegend\").setAll({\r\n stepCount: 1\r\n });\r\n r(\"RoundedRectangle\", [\"heatlegend\", \"marker\"]).setAll({\r\n cornerRadiusTR: 0,\r\n cornerRadiusBR: 0,\r\n cornerRadiusTL: 0,\r\n cornerRadiusBL: 0\r\n });\r\n r(\"RoundedRectangle\", [\"vertical\", \"heatlegend\", \"marker\"]).setAll({\r\n height: p100,\r\n width: 15\r\n });\r\n r(\"RoundedRectangle\", [\"horizontal\", \"heatlegend\", \"marker\"]).setAll({\r\n width: p100,\r\n height: 15\r\n });\r\n r(\"HeatLegend\", [\"vertical\"]).setAll({\r\n height: p100\r\n });\r\n r(\"HeatLegend\", [\"horizontal\"]).setAll({\r\n width: p100\r\n });\r\n r(\"Label\", [\"heatlegend\", \"start\"]).setAll({\r\n paddingLeft: 5,\r\n paddingRight: 5,\r\n paddingTop: 5,\r\n paddingBottom: 5\r\n });\r\n r(\"Label\", [\"heatlegend\", \"end\"]).setAll({\r\n paddingLeft: 5,\r\n paddingRight: 5,\r\n paddingTop: 5,\r\n paddingBottom: 5\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: Labels\r\n * ------------------------------------------------------------------------\r\n */\r\n {\r\n const rule = r(\"Label\");\r\n rule.setAll({\r\n paddingTop: 8,\r\n paddingBottom: 8,\r\n paddingLeft: 10,\r\n paddingRight: 10,\r\n fontFamily: \"-apple-system, BlinkMacSystemFont, \\\"Segoe UI\\\", Roboto, Helvetica, Arial, sans-serif, \\\"Apple Color Emoji\\\", \\\"Segoe UI Emoji\\\", \\\"Segoe UI Symbol\\\"\",\r\n fontSize: \"1em\",\r\n populateText: false\r\n });\r\n setColor(rule, \"fill\", ic, \"text\");\r\n }\r\n r(\"RadialLabel\").setAll({\r\n textType: \"regular\",\r\n centerY: p50,\r\n centerX: p50,\r\n inside: false,\r\n radius: 0,\r\n baseRadius: p100,\r\n orientation: \"auto\",\r\n textAlign: \"center\"\r\n });\r\n r(\"EditableLabel\").setAll({\r\n editOn: \"click\",\r\n //setStateOnChildren: true,\r\n themeTags: [\"editablelabel\"],\r\n multiLine: true\r\n });\r\n r(\"RoundedRectangle\", [\"editablelabel\", \"background\"]).setAll({\r\n fillOpacity: 0,\r\n fill: Color.fromHex(0x000000),\r\n cornerRadiusBL: 3,\r\n cornerRadiusBR: 3,\r\n cornerRadiusTL: 3,\r\n cornerRadiusTR: 3,\r\n strokeOpacity: 0,\r\n stroke: Color.fromHex(0x000000)\r\n });\r\n {\r\n r(\"RoundedRectangle\", [\"editablelabel\", \"background\"]).states.create(\"active\", {\r\n strokeOpacity: 0.2,\r\n });\r\n }\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: Elements and shapes\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"RoundedRectangle\").setAll({\r\n cornerRadiusTL: 8,\r\n cornerRadiusBL: 8,\r\n cornerRadiusTR: 8,\r\n cornerRadiusBR: 8\r\n });\r\n r(\"PointedRectangle\").setAll({\r\n pointerBaseWidth: 15,\r\n pointerLength: 10,\r\n cornerRadius: 8\r\n });\r\n r(\"Slice\").setAll({\r\n shiftRadius: 0,\r\n dRadius: 0,\r\n dInnerRadius: 0\r\n });\r\n {\r\n const rule = r(\"Tick\");\r\n rule.setAll({\r\n strokeOpacity: .15,\r\n isMeasured: false,\r\n length: 4.5,\r\n position: \"absolute\",\r\n crisp: true\r\n });\r\n setColor(rule, \"stroke\", ic, \"grid\");\r\n }\r\n r(\"Bullet\").setAll({\r\n locationX: 0.5,\r\n locationY: 0.5\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: Tooltip\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Tooltip\").setAll({\r\n position: \"absolute\",\r\n getFillFromSprite: true,\r\n getStrokeFromSprite: false,\r\n autoTextColor: true,\r\n paddingTop: 9,\r\n paddingBottom: 8,\r\n paddingLeft: 10,\r\n paddingRight: 10,\r\n marginBottom: 5,\r\n pointerOrientation: \"vertical\",\r\n centerX: p50,\r\n centerY: p50,\r\n animationEasing: $ease.out($ease.cubic),\r\n exportable: false\r\n //layer: 100\r\n });\r\n r(\"Polygon\").setAll({\r\n animationEasing: $ease.out($ease.cubic),\r\n });\r\n {\r\n const rule = r(\"PointedRectangle\", [\"tooltip\", \"background\"]);\r\n rule.setAll({\r\n strokeOpacity: 0.9,\r\n cornerRadius: 4,\r\n pointerLength: 4,\r\n pointerBaseWidth: 8,\r\n fillOpacity: 0.9,\r\n stroke: Color.fromHex(0xffffff)\r\n });\r\n }\r\n {\r\n const rule = r(\"Label\", [\"tooltip\"]);\r\n rule.setAll({\r\n role: \"tooltip\",\r\n populateText: true,\r\n paddingRight: 0,\r\n paddingTop: 0,\r\n paddingLeft: 0,\r\n paddingBottom: 0\r\n });\r\n setColor(rule, \"fill\", ic, \"alternativeText\");\r\n }\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: Button\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Button\").setAll({\r\n paddingTop: 8,\r\n paddingBottom: 8,\r\n paddingLeft: 10,\r\n paddingRight: 10,\r\n interactive: true,\r\n layout: horizontalLayout,\r\n interactiveChildren: false,\r\n setStateOnChildren: true,\r\n focusable: true\r\n });\r\n r(\"Button\").states.create(\"hover\", {});\r\n r(\"Button\").states.create(\"down\", { stateAnimationDuration: 0 });\r\n r(\"Button\").states.create(\"active\", {});\r\n r(\"Button\").states.create(\"disabled\", {\r\n forceInactive: true\r\n });\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"button\", \"background\"]);\r\n setColor(rule, \"fill\", ic, \"primaryButton\");\r\n setColor(rule, \"stroke\", ic, \"primaryButtonStroke\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"button\", \"background\"]).states.create(\"hover\", {});\r\n setColor(rule, \"fill\", ic, \"primaryButtonHover\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"button\", \"background\"]).states.create(\"down\", { stateAnimationDuration: 0 });\r\n setColor(rule, \"fill\", ic, \"primaryButtonDown\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"button\", \"background\"]).states.create(\"active\", {});\r\n setColor(rule, \"fill\", ic, \"primaryButtonActive\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"button\", \"background\"]).states.create(\"disabled\", {});\r\n setColor(rule, \"fill\", ic, \"primaryButtonDisabled\");\r\n }\r\n {\r\n const rule = r(\"Graphics\", [\"button\", \"icon\"]).states.create(\"disabled\", {});\r\n setColor(rule, \"fill\", ic, \"primaryButtonTextDisabled\");\r\n }\r\n {\r\n const rule = r(\"Label\", [\"button\"]).states.create(\"disabled\", {});\r\n setColor(rule, \"fill\", ic, \"primaryButtonTextDisabled\");\r\n }\r\n {\r\n const rule = r(\"Graphics\", [\"button\", \"icon\"]);\r\n rule.setAll({\r\n forceInactive: true\r\n });\r\n setColor(rule, \"stroke\", ic, \"primaryButtonText\");\r\n }\r\n {\r\n const rule = r(\"Label\", [\"button\"]);\r\n setColor(rule, \"fill\", ic, \"primaryButtonText\");\r\n }\r\n /**\r\n * ------------------------------------------------------------------------\r\n * charts/xy: ZoomOutButton\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Button\", [\"zoom\"]).setAll({\r\n paddingTop: 18,\r\n paddingBottom: 18,\r\n paddingLeft: 12,\r\n paddingRight: 12,\r\n centerX: 46,\r\n centerY: -10,\r\n y: 0,\r\n x: p100,\r\n role: \"button\",\r\n ariaLabel: language.translate(\"Zoom Out\"),\r\n layer: 30\r\n });\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"background\", \"button\", \"zoom\"]);\r\n rule.setAll({\r\n cornerRadiusBL: 40,\r\n cornerRadiusBR: 40,\r\n cornerRadiusTL: 40,\r\n cornerRadiusTR: 40\r\n });\r\n setColor(rule, \"fill\", ic, \"primaryButton\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"background\", \"button\", \"zoom\"]).states.create(\"hover\", {});\r\n setColor(rule, \"fill\", ic, \"primaryButtonHover\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"background\", \"button\", \"zoom\"]).states.create(\"down\", { stateAnimationDuration: 0 });\r\n setColor(rule, \"fill\", ic, \"primaryButtonDown\");\r\n }\r\n {\r\n const rule = r(\"Graphics\", [\"icon\", \"button\", \"zoom\"]);\r\n rule.setAll({\r\n crisp: true,\r\n strokeOpacity: 0.7,\r\n draw: (display) => {\r\n display.moveTo(0, 0);\r\n display.lineTo(12, 0);\r\n }\r\n });\r\n setColor(rule, \"stroke\", ic, \"primaryButtonText\");\r\n }\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: ResizeButton\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Button\", [\"resize\"]).setAll({\r\n paddingTop: 9,\r\n paddingBottom: 9,\r\n paddingLeft: 13,\r\n paddingRight: 13,\r\n draggable: true,\r\n centerX: p50,\r\n centerY: p50,\r\n position: \"absolute\",\r\n role: \"slider\",\r\n ariaValueMin: \"0\",\r\n ariaValueMax: \"100\",\r\n ariaLabel: language.translate(\"Use up and down arrows to move selection\")\r\n });\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"background\", \"resize\", \"button\"]);\r\n rule.setAll({\r\n cornerRadiusBL: 40,\r\n cornerRadiusBR: 40,\r\n cornerRadiusTL: 40,\r\n cornerRadiusTR: 40\r\n });\r\n setColor(rule, \"fill\", ic, \"secondaryButton\");\r\n setColor(rule, \"stroke\", ic, \"secondaryButtonStroke\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"background\", \"resize\", \"button\"]).states.create(\"hover\", {});\r\n setColor(rule, \"fill\", ic, \"secondaryButtonHover\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"background\", \"resize\", \"button\"]).states.create(\"down\", { stateAnimationDuration: 0 });\r\n setColor(rule, \"fill\", ic, \"secondaryButtonDown\");\r\n }\r\n {\r\n const rule = r(\"Graphics\", [\"resize\", \"button\", \"icon\"]);\r\n rule.setAll({\r\n interactive: false,\r\n crisp: true,\r\n strokeOpacity: 0.5,\r\n draw: (display) => {\r\n display.moveTo(0, 0.5);\r\n display.lineTo(0, 12.5);\r\n display.moveTo(4, 0.5);\r\n display.lineTo(4, 12.5);\r\n }\r\n });\r\n setColor(rule, \"stroke\", ic, \"secondaryButtonText\");\r\n }\r\n r(\"Button\", [\"resize\", \"vertical\"]).setAll({\r\n rotation: 90,\r\n cursorOverStyle: \"ns-resize\"\r\n });\r\n r(\"Button\", [\"resize\", \"horizontal\"]).setAll({\r\n cursorOverStyle: \"ew-resize\"\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: PlayButton\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Button\", [\"play\"]).setAll({\r\n paddingTop: 13,\r\n paddingBottom: 13,\r\n paddingLeft: 14,\r\n paddingRight: 14,\r\n ariaLabel: language.translate(\"Play\"),\r\n toggleKey: \"active\"\r\n });\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"play\", \"background\"]);\r\n rule.setAll({\r\n strokeOpacity: 0.5,\r\n cornerRadiusBL: 100,\r\n cornerRadiusBR: 100,\r\n cornerRadiusTL: 100,\r\n cornerRadiusTR: 100\r\n });\r\n setColor(rule, \"fill\", ic, \"primaryButton\");\r\n }\r\n {\r\n const rule = r(\"Graphics\", [\"play\", \"icon\"]);\r\n rule.setAll({\r\n stateAnimationDuration: 0,\r\n dx: 1,\r\n draw: (display) => {\r\n display.moveTo(0, -5);\r\n display.lineTo(8, 0);\r\n display.lineTo(0, 5);\r\n display.lineTo(0, -5);\r\n }\r\n });\r\n setColor(rule, \"fill\", ic, \"primaryButtonText\");\r\n }\r\n r(\"Graphics\", [\"play\", \"icon\"]).states.create(\"default\", {\r\n stateAnimationDuration: 0\r\n });\r\n r(\"Graphics\", [\"play\", \"icon\"]).states.create(\"active\", {\r\n stateAnimationDuration: 0,\r\n draw: (display) => {\r\n display.moveTo(-4, -5);\r\n display.lineTo(-1, -5);\r\n display.lineTo(-1, 5);\r\n display.lineTo(-4, 5);\r\n display.lineTo(-4, -5);\r\n display.moveTo(4, -5);\r\n display.lineTo(1, -5);\r\n display.lineTo(1, 5);\r\n display.lineTo(4, 5);\r\n display.lineTo(4, -5);\r\n }\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: SwitchButton\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Button\", [\"switch\"]).setAll({\r\n paddingTop: 4,\r\n paddingBottom: 4,\r\n paddingLeft: 4,\r\n paddingRight: 4,\r\n ariaLabel: language.translate(\"Press ENTER to toggle\"),\r\n toggleKey: \"active\",\r\n width: 40,\r\n height: 24,\r\n layout: null\r\n });\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"switch\", \"background\"]);\r\n rule.setAll({\r\n strokeOpacity: 0.5,\r\n cornerRadiusBL: 100,\r\n cornerRadiusBR: 100,\r\n cornerRadiusTL: 100,\r\n cornerRadiusTR: 100\r\n });\r\n setColor(rule, \"fill\", ic, \"primaryButton\");\r\n }\r\n {\r\n const rule = r(\"Circle\", [\"switch\", \"icon\"]);\r\n rule.setAll({\r\n radius: 8,\r\n centerY: 0,\r\n centerX: 0,\r\n dx: 0\r\n });\r\n setColor(rule, \"fill\", ic, \"primaryButtonText\");\r\n }\r\n r(\"Graphics\", [\"switch\", \"icon\"]).states.create(\"active\", {\r\n dx: 16\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * core: Scrollbar\r\n * ------------------------------------------------------------------------\r\n */\r\n r(\"Scrollbar\").setAll({\r\n start: 0,\r\n end: 1,\r\n layer: 30,\r\n animationEasing: $ease.out($ease.cubic)\r\n });\r\n r(\"Scrollbar\", [\"vertical\"]).setAll({\r\n marginRight: 13,\r\n marginLeft: 13,\r\n minWidth: 12,\r\n height: p100\r\n });\r\n r(\"Scrollbar\", [\"horizontal\"]).setAll({\r\n marginTop: 13,\r\n marginBottom: 13,\r\n minHeight: 12,\r\n width: p100\r\n });\r\n this.rule(\"Button\", [\"scrollbar\"]).setAll({\r\n exportable: false\r\n });\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"scrollbar\", \"main\", \"background\"]);\r\n rule.setAll({\r\n cornerRadiusTL: 8,\r\n cornerRadiusBL: 8,\r\n cornerRadiusTR: 8,\r\n cornerRadiusBR: 8,\r\n fillOpacity: 0.8,\r\n });\r\n setColor(rule, \"fill\", ic, \"fill\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"scrollbar\", \"thumb\"]);\r\n rule.setAll({\r\n role: \"slider\",\r\n ariaLive: \"polite\",\r\n position: \"absolute\",\r\n draggable: true\r\n });\r\n setColor(rule, \"fill\", ic, \"secondaryButton\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"scrollbar\", \"thumb\"]).states.create(\"hover\", {});\r\n setColor(rule, \"fill\", ic, \"secondaryButtonHover\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"scrollbar\", \"thumb\"]).states.create(\"down\", { stateAnimationDuration: 0 });\r\n setColor(rule, \"fill\", ic, \"secondaryButtonDown\");\r\n }\r\n r(\"RoundedRectangle\", [\"scrollbar\", \"thumb\", \"vertical\"]).setAll({\r\n x: p50,\r\n width: p100,\r\n centerX: p50,\r\n ariaLabel: language.translate(\"Use up and down arrows to move selection\")\r\n });\r\n r(\"RoundedRectangle\", [\"scrollbar\", \"thumb\", \"horizontal\"]).setAll({\r\n y: p50,\r\n centerY: p50,\r\n height: p100,\r\n ariaLabel: language.translate(\"Use left and right arrows to move selection\")\r\n });\r\n // @todo: is this needed? used to be \"ContentScrollbar\"\r\n // r(\"Scrollbar\", [\"content?\"]).setAll({\r\n // \tmarginRight: 0,\r\n // \tmarginLeft: 5,\r\n // \tlayer: 5\r\n // });\r\n /**\r\n * ========================================================================\r\n * charts/xy\r\n * ========================================================================\r\n *\r\n * This needs to be in DefaultTheme because it's the only theme that is\r\n * automatically applied to Root, and tooltips different ancestors\r\n * than actual charts using them.\r\n */\r\n {\r\n const rule = r(\"PointedRectangle\", [\"axis\", \"tooltip\", \"background\"]);\r\n rule.setAll({\r\n cornerRadius: 0\r\n });\r\n setColor(rule, \"fill\", ic, \"alternativeBackground\");\r\n }\r\n r(\"Label\", [\"axis\", \"tooltip\"]).setAll({\r\n role: undefined\r\n });\r\n r(\"Label\", [\"axis\", \"tooltip\", \"y\"]).setAll({\r\n textAlign: \"right\"\r\n });\r\n r(\"Label\", [\"axis\", \"tooltip\", \"y\", \"opposite\"]).setAll({\r\n textAlign: \"left\"\r\n });\r\n r(\"Label\", [\"axis\", \"tooltip\", \"x\"]).setAll({\r\n textAlign: \"center\"\r\n });\r\n r(\"Tooltip\", [\"categoryaxis\"]).setAll({\r\n labelText: \"{category}\"\r\n });\r\n /**\r\n * ------------------------------------------------------------------------\r\n * Shapes\r\n * ------------------------------------------------------------------------\r\n */\r\n // Class: Graphics\r\n r(\"Star\").setAll({\r\n spikes: 5,\r\n innerRadius: 5,\r\n radius: 10\r\n });\r\n // STOCK\r\n r(\"Tooltip\", [\"stock\"]).setAll({\r\n paddingTop: 6,\r\n paddingBottom: 5,\r\n paddingLeft: 7,\r\n paddingRight: 7\r\n });\r\n r(\"PointedRectangle\", [\"tooltip\", \"stock\", \"axis\"]).setAll({\r\n pointerLength: 0,\r\n pointerBaseWidth: 0,\r\n cornerRadius: 3\r\n });\r\n r(\"Label\", [\"tooltip\", \"stock\"]).setAll({\r\n fontSize: \"0.8em\"\r\n });\r\n // resizer\r\n r(\"SpriteResizer\").setAll({\r\n rotationStep: 10,\r\n isMeasured: false\r\n });\r\n {\r\n const rule = r(\"Container\", [\"resizer\", \"grip\"]);\r\n rule.states.create(\"hover\", {});\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"resizer\", \"grip\"]);\r\n rule.setAll({\r\n strokeOpacity: 0.7,\r\n strokeWidth: 1,\r\n fillOpacity: 1,\r\n width: 12,\r\n height: 12\r\n });\r\n setColor(rule, \"fill\", ic, \"background\");\r\n setColor(rule, \"stroke\", ic, \"alternativeBackground\");\r\n }\r\n {\r\n const rule = r(\"RoundedRectangle\", [\"resizer\", \"grip\", \"outline\"]);\r\n rule.setAll({\r\n strokeOpacity: 0,\r\n fillOpacity: 0,\r\n width: 20,\r\n height: 20\r\n });\r\n rule.states.create(\"hover\", {\r\n fillOpacity: 0.3\r\n });\r\n setColor(rule, \"fill\", ic, \"alternativeBackground\");\r\n }\r\n r(\"RoundedRectangle\", [\"resizer\", \"grip\", \"left\"]).setAll({\r\n cornerRadiusBL: 0,\r\n cornerRadiusBR: 0,\r\n cornerRadiusTL: 0,\r\n cornerRadiusTR: 0\r\n });\r\n r(\"RoundedRectangle\", [\"resizer\", \"grip\", \"right\"]).setAll({\r\n cornerRadiusBL: 0,\r\n cornerRadiusBR: 0,\r\n cornerRadiusTL: 0,\r\n cornerRadiusTR: 0\r\n });\r\n {\r\n const rule = r(\"Rectangle\", [\"resizer\", \"rectangle\"]);\r\n rule.setAll({\r\n strokeDasharray: [2, 2],\r\n strokeOpacity: 0.5,\r\n strokeWidth: 1\r\n });\r\n setColor(rule, \"stroke\", ic, \"alternativeBackground\");\r\n }\r\n r(\"Graphics\", [\"button\", \"plus\", \"icon\"]).setAll({\r\n x: p50,\r\n y: p50,\r\n draw: (display) => {\r\n display.moveTo(-4, 0);\r\n display.lineTo(4, 0);\r\n display.moveTo(0, -4);\r\n display.lineTo(0, 4);\r\n }\r\n });\r\n r(\"Graphics\", [\"button\", \"minus\", \"icon\"]).setAll({\r\n x: p50,\r\n y: p50,\r\n draw: (display) => {\r\n display.moveTo(-4, 0);\r\n display.lineTo(4, 0);\r\n }\r\n });\r\n r(\"Graphics\", [\"button\", \"home\", \"icon\"]).setAll({\r\n x: p50,\r\n y: p50,\r\n svgPath: \"M 8 -1 L 6 -1 L 6 7 L 2 7 L 2 1 L -2 1 L -2 7 L -6 7 L -6 -1 L -8 -1 L 0 -9 L 8 -1 Z M 8 -1\"\r\n });\r\n r(\"Button\", [\"zoomtools\"]).setAll({\r\n marginTop: 1,\r\n marginBottom: 2\r\n });\r\n r(\"ZoomTools\").setAll({\r\n x: p100,\r\n centerX: p100,\r\n y: p100,\r\n centerY: p100,\r\n paddingRight: 10,\r\n paddingBottom: 10\r\n });\r\n }\r\n}\r\n//# sourceMappingURL=DefaultTheme.js.map","/**\r\n * Modified from Pixi:\r\n *\r\n * The MIT License\r\n *\r\n * Copyright (c) 2013-2017 Mathew Groves, Chad Engler\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in\r\n * all copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n * THE SOFTWARE.\r\n */\r\n/**\r\n * @ignore\r\n */\r\nexport class Matrix {\r\n constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {\r\n Object.defineProperty(this, \"a\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"b\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"c\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"d\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"tx\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"ty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this.a = a;\r\n this.b = b;\r\n this.c = c;\r\n this.d = d;\r\n this.tx = tx;\r\n this.ty = ty;\r\n }\r\n /**\r\n * Sets the matrix based on all the available properties\r\n */\r\n setTransform(x, y, pivotX, pivotY, rotation, scale = 1) {\r\n this.a = Math.cos(rotation) * scale;\r\n this.b = Math.sin(rotation) * scale;\r\n this.c = -Math.sin(rotation) * scale;\r\n this.d = Math.cos(rotation) * scale;\r\n this.tx = x - ((pivotX * this.a) + (pivotY * this.c));\r\n this.ty = y - ((pivotX * this.b) + (pivotY * this.d));\r\n }\r\n /**\r\n * Get a new position with the current transformation applied.\r\n * Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)\r\n */\r\n apply(origin) {\r\n return {\r\n x: (this.a * origin.x) + (this.c * origin.y) + this.tx,\r\n y: (this.b * origin.x) + (this.d * origin.y) + this.ty\r\n };\r\n }\r\n /**\r\n * Get a new position with the inverse of the current transformation applied.\r\n * Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)\r\n */\r\n applyInverse(origin) {\r\n const id = 1 / ((this.a * this.d) + (this.c * -this.b));\r\n return {\r\n x: (this.d * id * origin.x) + (-this.c * id * origin.y) + (((this.ty * this.c) - (this.tx * this.d)) * id),\r\n y: (this.a * id * origin.y) + (-this.b * id * origin.x) + (((-this.ty * this.a) + (this.tx * this.b)) * id)\r\n };\r\n }\r\n /**\r\n * Appends the given Matrix to this Matrix.\r\n */\r\n append(matrix) {\r\n const a1 = this.a;\r\n const b1 = this.b;\r\n const c1 = this.c;\r\n const d1 = this.d;\r\n this.a = (matrix.a * a1) + (matrix.b * c1);\r\n this.b = (matrix.a * b1) + (matrix.b * d1);\r\n this.c = (matrix.c * a1) + (matrix.d * c1);\r\n this.d = (matrix.c * b1) + (matrix.d * d1);\r\n this.tx = (matrix.tx * a1) + (matrix.ty * c1) + this.tx;\r\n this.ty = (matrix.tx * b1) + (matrix.ty * d1) + this.ty;\r\n }\r\n /**\r\n * Prepends the given Matrix to this Matrix.\r\n */\r\n prepend(matrix) {\r\n const tx1 = this.tx;\r\n if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) {\r\n const a1 = this.a;\r\n const c1 = this.c;\r\n this.a = (a1 * matrix.a) + (this.b * matrix.c);\r\n this.b = (a1 * matrix.b) + (this.b * matrix.d);\r\n this.c = (c1 * matrix.a) + (this.d * matrix.c);\r\n this.d = (c1 * matrix.b) + (this.d * matrix.d);\r\n }\r\n this.tx = (tx1 * matrix.a) + (this.ty * matrix.c) + matrix.tx;\r\n this.ty = (tx1 * matrix.b) + (this.ty * matrix.d) + matrix.ty;\r\n }\r\n /**\r\n * Copies the other matrix's properties into this matrix\r\n */\r\n copyFrom(matrix) {\r\n this.a = matrix.a;\r\n this.b = matrix.b;\r\n this.c = matrix.c;\r\n this.d = matrix.d;\r\n this.tx = matrix.tx;\r\n this.ty = matrix.ty;\r\n }\r\n}\r\n//# sourceMappingURL=Matrix.js.map","var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar TAU = Math.PI * 2;\n\nvar mapToEllipse = function mapToEllipse(_ref, rx, ry, cosphi, sinphi, centerx, centery) {\n var x = _ref.x,\n y = _ref.y;\n\n x *= rx;\n y *= ry;\n\n var xp = cosphi * x - sinphi * y;\n var yp = sinphi * x + cosphi * y;\n\n return {\n x: xp + centerx,\n y: yp + centery\n };\n};\n\nvar approxUnitArc = function approxUnitArc(ang1, ang2) {\n // If 90 degree circular arc, use a constant\n // as derived from http://spencermortensen.com/articles/bezier-circle\n var a = ang2 === 1.5707963267948966 ? 0.551915024494 : ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);\n\n var x1 = Math.cos(ang1);\n var y1 = Math.sin(ang1);\n var x2 = Math.cos(ang1 + ang2);\n var y2 = Math.sin(ang1 + ang2);\n\n return [{\n x: x1 - y1 * a,\n y: y1 + x1 * a\n }, {\n x: x2 + y2 * a,\n y: y2 - x2 * a\n }, {\n x: x2,\n y: y2\n }];\n};\n\nvar vectorAngle = function vectorAngle(ux, uy, vx, vy) {\n var sign = ux * vy - uy * vx < 0 ? -1 : 1;\n\n var dot = ux * vx + uy * vy;\n\n if (dot > 1) {\n dot = 1;\n }\n\n if (dot < -1) {\n dot = -1;\n }\n\n return sign * Math.acos(dot);\n};\n\nvar getArcCenter = function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {\n var rxsq = Math.pow(rx, 2);\n var rysq = Math.pow(ry, 2);\n var pxpsq = Math.pow(pxp, 2);\n var pypsq = Math.pow(pyp, 2);\n\n var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;\n\n if (radicant < 0) {\n radicant = 0;\n }\n\n radicant /= rxsq * pypsq + rysq * pxpsq;\n radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);\n\n var centerxp = radicant * rx / ry * pyp;\n var centeryp = radicant * -ry / rx * pxp;\n\n var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;\n var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;\n\n var vx1 = (pxp - centerxp) / rx;\n var vy1 = (pyp - centeryp) / ry;\n var vx2 = (-pxp - centerxp) / rx;\n var vy2 = (-pyp - centeryp) / ry;\n\n var ang1 = vectorAngle(1, 0, vx1, vy1);\n var ang2 = vectorAngle(vx1, vy1, vx2, vy2);\n\n if (sweepFlag === 0 && ang2 > 0) {\n ang2 -= TAU;\n }\n\n if (sweepFlag === 1 && ang2 < 0) {\n ang2 += TAU;\n }\n\n return [centerx, centery, ang1, ang2];\n};\n\nvar arcToBezier = function arcToBezier(_ref2) {\n var px = _ref2.px,\n py = _ref2.py,\n cx = _ref2.cx,\n cy = _ref2.cy,\n rx = _ref2.rx,\n ry = _ref2.ry,\n _ref2$xAxisRotation = _ref2.xAxisRotation,\n xAxisRotation = _ref2$xAxisRotation === undefined ? 0 : _ref2$xAxisRotation,\n _ref2$largeArcFlag = _ref2.largeArcFlag,\n largeArcFlag = _ref2$largeArcFlag === undefined ? 0 : _ref2$largeArcFlag,\n _ref2$sweepFlag = _ref2.sweepFlag,\n sweepFlag = _ref2$sweepFlag === undefined ? 0 : _ref2$sweepFlag;\n\n var curves = [];\n\n if (rx === 0 || ry === 0) {\n return [];\n }\n\n var sinphi = Math.sin(xAxisRotation * TAU / 360);\n var cosphi = Math.cos(xAxisRotation * TAU / 360);\n\n var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;\n var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;\n\n if (pxp === 0 && pyp === 0) {\n return [];\n }\n\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n\n var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);\n\n if (lambda > 1) {\n rx *= Math.sqrt(lambda);\n ry *= Math.sqrt(lambda);\n }\n\n var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp),\n _getArcCenter2 = _slicedToArray(_getArcCenter, 4),\n centerx = _getArcCenter2[0],\n centery = _getArcCenter2[1],\n ang1 = _getArcCenter2[2],\n ang2 = _getArcCenter2[3];\n\n // If 'ang2' == 90.0000000001, then `ratio` will evaluate to\n // 1.0000000001. This causes `segments` to be greater than one, which is an\n // unecessary split, and adds extra points to the bezier curve. To alleviate\n // this issue, we round to 1.0 when the ratio is close to 1.0.\n\n\n var ratio = Math.abs(ang2) / (TAU / 4);\n if (Math.abs(1.0 - ratio) < 0.0000001) {\n ratio = 1.0;\n }\n\n var segments = Math.max(Math.ceil(ratio), 1);\n\n ang2 /= segments;\n\n for (var i = 0; i < segments; i++) {\n curves.push(approxUnitArc(ang1, ang2));\n ang1 += ang2;\n }\n\n return curves.map(function (curve) {\n var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery),\n x1 = _mapToEllipse.x,\n y1 = _mapToEllipse.y;\n\n var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery),\n x2 = _mapToEllipse2.x,\n y2 = _mapToEllipse2.y;\n\n var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery),\n x = _mapToEllipse3.x,\n y = _mapToEllipse3.y;\n\n return { x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y };\n });\n};\n\nexport default arcToBezier;","/** @ignore */ /** */\r\nimport { BlendMode } from \"./Renderer\";\r\nimport { Color } from \"../../util/Color\";\r\nimport { Matrix } from \"../../util/Matrix\";\r\nimport { Percent, percent } from \"../../util/Percent\";\r\n//import { Throttler } from \"../../util/Throttler\";\r\nimport { ArrayDisposer, Disposer, DisposerClass, CounterDisposer, MultiDisposer } from \"../../util/Disposer\";\r\nimport { TextFormatter } from \"../../util/TextFormatter\";\r\nimport * as $utils from \"../../util/Utils\";\r\nimport * as $array from \"../../util/Array\";\r\nimport * as $object from \"../../util/Object\";\r\nimport * as $type from \"../../util/Type\";\r\nimport * as $math from \"../../util/Math\";\r\nimport arcToBezier from 'svg-arc-to-cubic-bezier';\r\n/**\r\n * @ignore\r\n */\r\nfunction checkArgs(name, actual, expected) {\r\n if (actual !== expected) {\r\n throw new Error(\"Required \" + expected + \" arguments for \" + name + \" but got \" + actual);\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction checkMinArgs(name, actual, expected) {\r\n if (actual < expected) {\r\n throw new Error(\"Required at least \" + expected + \" arguments for \" + name + \" but got \" + actual);\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction checkEvenArgs(name, actual, expected) {\r\n checkMinArgs(name, actual, expected);\r\n if ((actual % expected) !== 0) {\r\n throw new Error(\"Arguments for \" + name + \" must be in pairs of \" + expected);\r\n }\r\n}\r\n/**\r\n * @ignore\r\n * This splits the flag so that way 0017 will be processed as 0 0 17\r\n *\r\n * This is important for weird paths like `M17 5A1 1 0 0017 30 1 1 0 0017 5`\r\n */\r\nfunction splitArcFlags(args) {\r\n for (let i = 0; i < args.length; i += 7) {\r\n let index = i + 3;\r\n let flag = args[index];\r\n if (flag.length > 1) {\r\n const a = /^([01])([01])(.*)$/.exec(flag);\r\n if (a !== null) {\r\n args.splice(index, 0, a[1]);\r\n ++index;\r\n args.splice(index, 0, a[2]);\r\n ++index;\r\n if (a[3].length > 0) {\r\n args[index] = a[3];\r\n }\r\n else {\r\n args.splice(index, 1);\r\n }\r\n }\r\n }\r\n ++index;\r\n flag = args[index];\r\n if (flag.length > 1) {\r\n const a = /^([01])(.+)$/.exec(flag);\r\n if (a !== null) {\r\n args.splice(index, 0, a[1]);\r\n ++index;\r\n args[index] = a[2];\r\n }\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction assertBinary(value) {\r\n if (value === 0 || value === 1) {\r\n return value;\r\n }\r\n else {\r\n throw new Error(\"Flag must be 0 or 1\");\r\n }\r\n}\r\n// 1 -> 0xffffff * (2 / 2)\r\n// 2 -> 0xffffff * (1 / 2)\r\n//\r\n// 3 -> 0xffffff * (3 / 4)\r\n// 4 -> 0xffffff * (1 / 4)\r\n//\r\n// 5 -> 0xffffff * (7 / 8)\r\n// 6 -> 0xffffff * (5 / 8)\r\n// 7 -> 0xffffff * (3 / 8)\r\n// 8 -> 0xffffff * (1 / 8)\r\n//\r\n// 9 -> 0xffffff * (15 / 16)\r\n// 10 -> 0xffffff * (13 / 16)\r\n// 11 -> 0xffffff * (11 / 16)\r\n// 12 -> 0xffffff * (9 / 16)\r\n// 13 -> 0xffffff * (7 / 16)\r\n// 14 -> 0xffffff * (5 / 16)\r\n// 15 -> 0xffffff * (3 / 16)\r\n// 16 -> 0xffffff * (1 / 16)\r\n// @todo remove this old color distribution algo if the new one pans out\r\n/*function distributeId(id: number): number {\r\n if (id === 1) {\r\n return 0x000001;\r\n\r\n } else {\r\n // Finds the closest power of 2\r\n const base = Math.pow(2, Math.ceil(Math.log(id) / Math.log(2)));\r\n\r\n // Translates the id into an odd fraction index\r\n const index = ((base - id) * 2) + 1;\r\n\r\n // TODO is Math.round correct ?\r\n return Math.round(0xffffff * (index / base));\r\n }\r\n}*/\r\n/**\r\n * Function by smeans:\r\n * https://lowcode.life/generating-unique-contrasting-colors-in-javascript/\r\n * @ignore\r\n */\r\nfunction distributeId(id) {\r\n const rgb = [0, 0, 0];\r\n for (let i = 0; i < 24; i++) {\r\n rgb[i % 3] <<= 1;\r\n rgb[i % 3] |= id & 0x01;\r\n id >>= 1;\r\n }\r\n return (rgb[0] | 0) + (rgb[1] << 8) + (rgb[2] << 16);\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction eachTargets(hitTarget, f) {\r\n for (;;) {\r\n if (hitTarget.interactive) {\r\n if (!f(hitTarget)) {\r\n break;\r\n }\r\n }\r\n if (hitTarget._parent) {\r\n hitTarget = hitTarget._parent;\r\n }\r\n else {\r\n break;\r\n }\r\n }\r\n}\r\n// TODO feature detection for mouse/touch/pointer\r\n/**\r\n * @ignore\r\n */\r\nfunction onPointerEvent(element, name, f) {\r\n return $utils.addEventListener(element, $utils.getRendererEvent(name), (event) => {\r\n const target = $utils.getEventTarget(event);\r\n let touches = event.touches;\r\n if (touches) {\r\n if (touches.length == 0) {\r\n touches = event.changedTouches;\r\n }\r\n f($array.copy(touches), target);\r\n }\r\n else {\r\n f([event], target);\r\n }\r\n });\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction isTainted(image) {\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = 1;\r\n canvas.height = 1;\r\n const context = canvas.getContext(\"2d\", { willReadFrequently: true });\r\n context.drawImage(image, 0, 0, 1, 1);\r\n try {\r\n context.getImageData(0, 0, 1, 1);\r\n return false;\r\n }\r\n catch (err) {\r\n console.warn(\"Image \\\"\" + image.src + \"\\\" is loaded from different host and is not covered by CORS policy. For more information about the implications read here: https://www.amcharts.com/docs/v5/concepts/cors\");\r\n return true;\r\n }\r\n}\r\n/**\r\n * This is needed to workaround a bug in iOS which causes it to not GC canvas elements.\r\n *\r\n * @ignore\r\n */\r\nfunction clearCanvas(view) {\r\n view.width = 0;\r\n view.height = 0;\r\n view.style.width = \"0px\";\r\n view.style.height = \"0px\";\r\n}\r\n/**\r\n * Aligns the coordinate to the pixel, so it renders crisp\r\n *\r\n * @ignore\r\n */\r\nfunction crisp(x) {\r\n return Math.floor(x) + .5;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasPivot {\r\n constructor() {\r\n Object.defineProperty(this, \"_x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n }\r\n get x() {\r\n return this._x;\r\n }\r\n get y() {\r\n return this._y;\r\n }\r\n set x(value) {\r\n this._x = value;\r\n }\r\n set y(value) {\r\n this._y = value;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasDisplayObject extends DisposerClass {\r\n constructor(renderer) {\r\n super();\r\n Object.defineProperty(this, \"_layer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"mask\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: null\r\n });\r\n Object.defineProperty(this, \"visible\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"exportable\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"interactive\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"inactive\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: null\r\n });\r\n Object.defineProperty(this, \"wheelable\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"cancelTouch\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"isMeasured\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"buttonMode\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"alpha\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 1\r\n });\r\n Object.defineProperty(this, \"compoundAlpha\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 1\r\n });\r\n Object.defineProperty(this, \"angle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"scale\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 1\r\n });\r\n Object.defineProperty(this, \"x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"crisp\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"pivot\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new CanvasPivot()\r\n });\r\n Object.defineProperty(this, \"filter\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"cursorOverStyle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_replacedCursorStyle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_localMatrix\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new Matrix()\r\n });\r\n Object.defineProperty(this, \"_matrix\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new Matrix()\r\n });\r\n // TODO can this be replaced with _localMatrix ?\r\n Object.defineProperty(this, \"_uMatrix\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new Matrix()\r\n });\r\n Object.defineProperty(this, \"_renderer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_parent\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_localBounds\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_bounds\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_colorId\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._renderer = renderer;\r\n }\r\n subStatus(status) {\r\n return {\r\n inactive: (this.inactive == null ? status.inactive : this.inactive),\r\n layer: this._layer || status.layer,\r\n };\r\n }\r\n _dispose() {\r\n this._renderer._removeObject(this);\r\n this.getLayer().dirty = true;\r\n }\r\n getCanvas() {\r\n return this.getLayer().view;\r\n }\r\n getLayer() {\r\n let self = this;\r\n for (;;) {\r\n if (self._layer) {\r\n return self._layer;\r\n }\r\n else if (self._parent) {\r\n self = self._parent;\r\n }\r\n else {\r\n return this._renderer.defaultLayer;\r\n }\r\n }\r\n }\r\n setLayer(order, margin) {\r\n if (order == null) {\r\n this._layer = undefined;\r\n }\r\n else {\r\n const visible = true;\r\n this._layer = this._renderer.getLayer(order, visible);\r\n this._layer.visible = visible;\r\n this._layer.margin = margin;\r\n if (margin) {\r\n $utils.setInteractive(this._layer.view, false);\r\n }\r\n this._renderer._ghostLayer.setMargin(this._renderer.layers);\r\n if (this._parent) {\r\n this._parent.registerChildLayer(this._layer);\r\n }\r\n this._layer.dirty = true;\r\n this._renderer.resizeLayer(this._layer);\r\n this._renderer.resizeGhost();\r\n }\r\n }\r\n markDirtyLayer() {\r\n this.getLayer().dirty = true;\r\n }\r\n clear() {\r\n this.invalidateBounds();\r\n }\r\n invalidateBounds() {\r\n this._localBounds = undefined;\r\n }\r\n _addBounds(_bounds) { }\r\n _getColorId() {\r\n if (this._colorId === undefined) {\r\n this._colorId = this._renderer.paintId(this);\r\n }\r\n return this._colorId;\r\n }\r\n _isInteractive(status) {\r\n return !status.inactive && (this.interactive || this._renderer._forceInteractive > 0);\r\n }\r\n _isInteractiveMask(status) {\r\n return this._isInteractive(status);\r\n }\r\n contains(child) {\r\n for (;;) {\r\n if (child === this) {\r\n return true;\r\n }\r\n else if (child._parent) {\r\n child = child._parent;\r\n }\r\n else {\r\n return false;\r\n }\r\n }\r\n }\r\n toGlobal(point) {\r\n return this._matrix.apply(point);\r\n }\r\n toLocal(point) {\r\n return this._matrix.applyInverse(point);\r\n }\r\n getLocalMatrix() {\r\n this._uMatrix.setTransform(0, 0, this.pivot.x, this.pivot.y, this.angle * Math.PI / 180, this.scale);\r\n return this._uMatrix;\r\n }\r\n getLocalBounds() {\r\n if (!this._localBounds) {\r\n const bn = 10000000;\r\n this._localBounds = {\r\n left: bn,\r\n top: bn,\r\n right: -bn,\r\n bottom: -bn\r\n };\r\n this._addBounds(this._localBounds);\r\n }\r\n return this._localBounds;\r\n }\r\n getAdjustedBounds(bounds) {\r\n this._setMatrix();\r\n const matrix = this.getLocalMatrix();\r\n const p0 = matrix.apply({ x: bounds.left, y: bounds.top });\r\n const p1 = matrix.apply({ x: bounds.right, y: bounds.top });\r\n const p2 = matrix.apply({ x: bounds.right, y: bounds.bottom });\r\n const p3 = matrix.apply({ x: bounds.left, y: bounds.bottom });\r\n return {\r\n left: Math.min(p0.x, p1.x, p2.x, p3.x),\r\n top: Math.min(p0.y, p1.y, p2.y, p3.y),\r\n right: Math.max(p0.x, p1.x, p2.x, p3.x),\r\n bottom: Math.max(p0.y, p1.y, p2.y, p3.y)\r\n };\r\n }\r\n on(key, callback, context) {\r\n if (this.interactive) {\r\n return this._renderer._addEvent(this, key, callback, context);\r\n }\r\n else {\r\n return new Disposer(() => { });\r\n }\r\n }\r\n _setMatrix() {\r\n // TODO only calculate this if it has actually changed\r\n this._localMatrix.setTransform(this.x, this.y, this.pivot.x, this.pivot.y, \r\n // Converts degrees to radians\r\n this.angle * Math.PI / 180, this.scale);\r\n this._matrix.copyFrom(this._localMatrix);\r\n if (this._parent) {\r\n // TODO only calculate this if it has actually changed\r\n this._matrix.prepend(this._parent._matrix);\r\n }\r\n }\r\n _transform(context, resolution) {\r\n const m = this._matrix;\r\n let tx = m.tx * resolution;\r\n let ty = m.ty * resolution;\r\n if (this.crisp) {\r\n tx = crisp(tx);\r\n ty = crisp(ty);\r\n }\r\n context.setTransform(m.a * resolution, m.b * resolution, m.c * resolution, m.d * resolution, tx, ty);\r\n }\r\n _transformMargin(context, resolution, margin) {\r\n const m = this._matrix;\r\n context.setTransform(m.a * resolution, m.b * resolution, m.c * resolution, m.d * resolution, (m.tx + margin.left) * resolution, (m.ty + margin.top) * resolution);\r\n }\r\n _transformLayer(context, resolution, layer) {\r\n if (layer.margin) {\r\n this._transformMargin(context, layer.scale || resolution, layer.margin);\r\n }\r\n else {\r\n this._transform(context, layer.scale || resolution);\r\n }\r\n }\r\n render(status) {\r\n if (this.visible && (this.exportable !== false || !this._renderer._omitTainted)) {\r\n this._setMatrix();\r\n const subStatus = this.subStatus(status);\r\n const resolution = this._renderer.resolution;\r\n const layers = this._renderer.layers;\r\n const ghostLayer = this._renderer._ghostLayer;\r\n const ghostContext = ghostLayer.context;\r\n const mask = this.mask;\r\n if (mask) {\r\n mask._setMatrix();\r\n }\r\n // TODO improve this\r\n $array.each(layers, (layer) => {\r\n if (layer) {\r\n const context = layer.context;\r\n context.save();\r\n // We must apply the mask before we transform the element\r\n if (mask) {\r\n mask._transformLayer(context, resolution, layer);\r\n mask._runPath(context);\r\n context.clip();\r\n }\r\n context.globalAlpha = this.compoundAlpha * this.alpha;\r\n this._transformLayer(context, resolution, layer);\r\n if (this.filter) {\r\n context.filter = this.filter;\r\n }\r\n }\r\n });\r\n ghostContext.save();\r\n // We must apply the mask before we transform the element\r\n if (mask && this._isInteractiveMask(subStatus)) {\r\n mask._transformMargin(ghostContext, resolution, ghostLayer.margin);\r\n mask._runPath(ghostContext);\r\n ghostContext.clip();\r\n }\r\n this._transformMargin(ghostContext, resolution, ghostLayer.margin);\r\n this._render(subStatus);\r\n ghostContext.restore();\r\n $array.each(layers, (layer) => {\r\n if (layer) {\r\n layer.context.restore();\r\n }\r\n });\r\n }\r\n }\r\n _render(status) {\r\n if (this.exportable === false) {\r\n status.layer.tainted = true;\r\n }\r\n }\r\n hovering() {\r\n return this._renderer._hovering.has(this);\r\n }\r\n dragging() {\r\n return this._renderer._dragging.some((x) => x.value === this);\r\n }\r\n shouldCancelTouch() {\r\n const renderer = this._renderer;\r\n if (renderer.tapToActivate && !renderer._touchActive) {\r\n return false;\r\n }\r\n if (this.cancelTouch) {\r\n return true;\r\n }\r\n else if (this._parent) {\r\n return this._parent.shouldCancelTouch();\r\n }\r\n return false;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasContainer extends CanvasDisplayObject {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"interactiveChildren\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"_childLayers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_children\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n }\r\n _isInteractiveMask(status) {\r\n return this.interactiveChildren || super._isInteractiveMask(status);\r\n }\r\n addChild(child) {\r\n child._parent = this;\r\n this._children.push(child);\r\n if (child._layer) {\r\n this.registerChildLayer(child._layer);\r\n }\r\n }\r\n addChildAt(child, index) {\r\n child._parent = this;\r\n this._children.splice(index, 0, child);\r\n if (child._layer) {\r\n this.registerChildLayer(child._layer);\r\n }\r\n }\r\n removeChild(child) {\r\n child._parent = undefined;\r\n $array.removeFirst(this._children, child);\r\n }\r\n _render(status) {\r\n super._render(status);\r\n const renderer = this._renderer;\r\n if (this.interactive && this.interactiveChildren) {\r\n ++renderer._forceInteractive;\r\n }\r\n $array.each(this._children, (child) => {\r\n child.compoundAlpha = this.compoundAlpha * this.alpha;\r\n child.render(status);\r\n });\r\n if (this.interactive && this.interactiveChildren) {\r\n --renderer._forceInteractive;\r\n }\r\n }\r\n registerChildLayer(layer) {\r\n if (!this._childLayers) {\r\n this._childLayers = [];\r\n }\r\n $array.pushOne(this._childLayers, layer);\r\n if (this._parent) {\r\n this._parent.registerChildLayer(layer);\r\n }\r\n }\r\n markDirtyLayer(deep = false) {\r\n super.markDirtyLayer();\r\n if (deep && this._childLayers) {\r\n $array.each(this._childLayers, (layer) => layer.dirty = true);\r\n }\r\n }\r\n _dispose() {\r\n super._dispose();\r\n if (this._childLayers) {\r\n $array.each(this._childLayers, (layer) => {\r\n layer.dirty = true;\r\n });\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nfunction setPoint(bounds, point) {\r\n bounds.left = Math.min(bounds.left, point.x);\r\n bounds.top = Math.min(bounds.top, point.y);\r\n bounds.right = Math.max(bounds.right, point.x);\r\n bounds.bottom = Math.max(bounds.bottom, point.y);\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass Op {\r\n colorize(_context, _forceColor) { }\r\n colorizeGhost(context, forceColor) {\r\n this.colorize(context, forceColor);\r\n }\r\n path(_context) { }\r\n pathGhost(context) {\r\n this.path(context);\r\n }\r\n addBounds(_bounds) { }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass BeginPath extends Op {\r\n colorize(context, _forceColor) {\r\n context.beginPath();\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass BeginFill extends Op {\r\n constructor(color) {\r\n super();\r\n Object.defineProperty(this, \"color\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: color\r\n });\r\n }\r\n colorize(context, forceColor) {\r\n if (forceColor !== undefined) {\r\n context.fillStyle = forceColor;\r\n }\r\n else {\r\n context.fillStyle = this.color;\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass EndFill extends Op {\r\n constructor(clearShadow) {\r\n super();\r\n Object.defineProperty(this, \"clearShadow\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: clearShadow\r\n });\r\n }\r\n colorize(context, _forceColor) {\r\n context.fill();\r\n if (this.clearShadow) {\r\n context.shadowColor = \"\";\r\n context.shadowBlur = 0;\r\n context.shadowOffsetX = 0;\r\n context.shadowOffsetY = 0;\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass EndStroke extends Op {\r\n colorize(context, _forceColor) {\r\n context.stroke();\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass LineStyle extends Op {\r\n constructor(width, color, lineJoin) {\r\n super();\r\n Object.defineProperty(this, \"width\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: width\r\n });\r\n Object.defineProperty(this, \"color\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: color\r\n });\r\n Object.defineProperty(this, \"lineJoin\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: lineJoin\r\n });\r\n }\r\n colorize(context, forceColor) {\r\n if (forceColor !== undefined) {\r\n context.strokeStyle = forceColor;\r\n }\r\n else {\r\n context.strokeStyle = this.color;\r\n }\r\n context.lineWidth = this.width;\r\n if (this.lineJoin) {\r\n context.lineJoin = this.lineJoin;\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass LineDash extends Op {\r\n constructor(dash) {\r\n super();\r\n Object.defineProperty(this, \"dash\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: dash\r\n });\r\n }\r\n colorize(context, _forceColor) {\r\n context.setLineDash(this.dash);\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass LineDashOffset extends Op {\r\n constructor(dashOffset) {\r\n super();\r\n Object.defineProperty(this, \"dashOffset\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: dashOffset\r\n });\r\n }\r\n colorize(context, _forceColor) {\r\n context.lineDashOffset = this.dashOffset;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass DrawRect extends Op {\r\n constructor(x, y, width, height) {\r\n super();\r\n Object.defineProperty(this, \"x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x\r\n });\r\n Object.defineProperty(this, \"y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y\r\n });\r\n Object.defineProperty(this, \"width\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: width\r\n });\r\n Object.defineProperty(this, \"height\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: height\r\n });\r\n }\r\n path(context) {\r\n context.rect(this.x, this.y, this.width, this.height);\r\n }\r\n addBounds(bounds) {\r\n const l = this.x;\r\n const t = this.y;\r\n const r = l + this.width;\r\n const b = t + this.height;\r\n setPoint(bounds, { x: l, y: t });\r\n setPoint(bounds, { x: r, y: t });\r\n setPoint(bounds, { x: l, y: b });\r\n setPoint(bounds, { x: r, y: b });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass DrawCircle extends Op {\r\n constructor(x, y, radius) {\r\n super();\r\n Object.defineProperty(this, \"x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x\r\n });\r\n Object.defineProperty(this, \"y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y\r\n });\r\n Object.defineProperty(this, \"radius\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: radius\r\n });\r\n }\r\n path(context) {\r\n context.moveTo(this.x + this.radius, this.y);\r\n context.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);\r\n }\r\n // TODO handle skewing and rotation\r\n addBounds(bounds) {\r\n setPoint(bounds, { x: this.x - this.radius, y: this.y - this.radius });\r\n setPoint(bounds, { x: this.x + this.radius, y: this.y + this.radius });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass DrawEllipse extends Op {\r\n constructor(x, y, radiusX, radiusY) {\r\n super();\r\n Object.defineProperty(this, \"x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x\r\n });\r\n Object.defineProperty(this, \"y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y\r\n });\r\n Object.defineProperty(this, \"radiusX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: radiusX\r\n });\r\n Object.defineProperty(this, \"radiusY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: radiusY\r\n });\r\n }\r\n path(context) {\r\n context.ellipse(0, 0, this.radiusX, this.radiusY, 0, 0, Math.PI * 2);\r\n }\r\n // TODO handle skewing and rotation\r\n addBounds(bounds) {\r\n setPoint(bounds, { x: this.x - this.radiusX, y: this.y - this.radiusY });\r\n setPoint(bounds, { x: this.x + this.radiusX, y: this.y + this.radiusY });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass Arc extends Op {\r\n constructor(cx, cy, radius, startAngle, endAngle, anticlockwise) {\r\n super();\r\n Object.defineProperty(this, \"cx\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cx\r\n });\r\n Object.defineProperty(this, \"cy\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cy\r\n });\r\n Object.defineProperty(this, \"radius\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: radius\r\n });\r\n Object.defineProperty(this, \"startAngle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: startAngle\r\n });\r\n Object.defineProperty(this, \"endAngle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: endAngle\r\n });\r\n Object.defineProperty(this, \"anticlockwise\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: anticlockwise\r\n });\r\n }\r\n path(context) {\r\n if (this.radius > 0) {\r\n context.arc(this.cx, this.cy, this.radius, this.startAngle, this.endAngle, this.anticlockwise);\r\n }\r\n }\r\n addBounds(bounds) {\r\n let arcBounds = $math.getArcBounds(this.cx, this.cy, this.startAngle * $math.DEGREES, this.endAngle * $math.DEGREES, this.radius);\r\n setPoint(bounds, { x: arcBounds.left, y: arcBounds.top });\r\n setPoint(bounds, { x: arcBounds.right, y: arcBounds.bottom });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass ArcTo extends Op {\r\n constructor(x1, y1, x2, y2, radius) {\r\n super();\r\n Object.defineProperty(this, \"x1\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x1\r\n });\r\n Object.defineProperty(this, \"y1\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y1\r\n });\r\n Object.defineProperty(this, \"x2\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x2\r\n });\r\n Object.defineProperty(this, \"y2\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y2\r\n });\r\n Object.defineProperty(this, \"radius\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: radius\r\n });\r\n }\r\n path(context) {\r\n if (this.radius > 0) {\r\n context.arcTo(this.x1, this.y1, this.x2, this.y2, this.radius);\r\n }\r\n }\r\n // TODO: add points\r\n addBounds(_bounds) {\r\n /*\r\n // not finished\r\n https://math.stackexchange.com/questions/1781438/finding-the-center-of-a-circle-given-two-points-and-a-radius-algebraically\r\n\r\n if (prevPoint) {\r\n let x1 = prevPoint.x;\r\n let y1 = prevPoint.y;\r\n let x2 = this.x2;\r\n let y2 = this.y2;\r\n let r = this.radius;\r\n\r\n let xa = (x2 - x1) / 2;\r\n let ya = (y2 - y1) / 2;\r\n\r\n let x0 = x1 + xa;\r\n let y0 = y1 + ya;\r\n\r\n let a = Math.hypot(xa, ya);\r\n let b = Math.sqrt(r * r - a * a);\r\n\r\n let cx = x0 + b * ya / a;\r\n let cy = y0 - b * xa / a;\r\n\r\n console.log(cx, cy);\r\n }*/\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass LineTo extends Op {\r\n constructor(x, y) {\r\n super();\r\n Object.defineProperty(this, \"x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x\r\n });\r\n Object.defineProperty(this, \"y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y\r\n });\r\n }\r\n path(context) {\r\n context.lineTo(this.x, this.y);\r\n }\r\n addBounds(bounds) {\r\n setPoint(bounds, { x: this.x, y: this.y });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass MoveTo extends Op {\r\n constructor(x, y) {\r\n super();\r\n Object.defineProperty(this, \"x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x\r\n });\r\n Object.defineProperty(this, \"y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y\r\n });\r\n }\r\n path(context) {\r\n context.moveTo(this.x, this.y);\r\n }\r\n addBounds(bounds) {\r\n setPoint(bounds, { x: this.x, y: this.y });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass ClosePath extends Op {\r\n path(context) {\r\n context.closePath();\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass BezierCurveTo extends Op {\r\n constructor(cpX, cpY, cpX2, cpY2, toX, toY) {\r\n super();\r\n Object.defineProperty(this, \"cpX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cpX\r\n });\r\n Object.defineProperty(this, \"cpY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cpY\r\n });\r\n Object.defineProperty(this, \"cpX2\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cpX2\r\n });\r\n Object.defineProperty(this, \"cpY2\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cpY2\r\n });\r\n Object.defineProperty(this, \"toX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: toX\r\n });\r\n Object.defineProperty(this, \"toY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: toY\r\n });\r\n }\r\n path(context) {\r\n context.bezierCurveTo(this.cpX, this.cpY, this.cpX2, this.cpY2, this.toX, this.toY);\r\n }\r\n // TODO: OK?\r\n addBounds(bounds) {\r\n setPoint(bounds, { x: this.cpX, y: this.cpY });\r\n setPoint(bounds, { x: this.cpX2, y: this.cpY2 });\r\n setPoint(bounds, { x: this.toX, y: this.toY });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass QuadraticCurveTo extends Op {\r\n constructor(cpX, cpY, toX, toY) {\r\n super();\r\n Object.defineProperty(this, \"cpX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cpX\r\n });\r\n Object.defineProperty(this, \"cpY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: cpY\r\n });\r\n Object.defineProperty(this, \"toX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: toX\r\n });\r\n Object.defineProperty(this, \"toY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: toY\r\n });\r\n }\r\n path(context) {\r\n context.quadraticCurveTo(this.cpX, this.cpY, this.toX, this.toY);\r\n }\r\n // TODO: OK?\r\n addBounds(bounds) {\r\n setPoint(bounds, { x: this.cpX, y: this.cpY });\r\n setPoint(bounds, { x: this.toX, y: this.toY });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass Shadow extends Op {\r\n constructor(color, blur, offsetX, offsetY, opacity) {\r\n super();\r\n Object.defineProperty(this, \"color\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: color\r\n });\r\n Object.defineProperty(this, \"blur\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: blur\r\n });\r\n Object.defineProperty(this, \"offsetX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: offsetX\r\n });\r\n Object.defineProperty(this, \"offsetY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: offsetY\r\n });\r\n Object.defineProperty(this, \"opacity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: opacity\r\n });\r\n }\r\n colorize(context, _forceColor) {\r\n if (this.opacity) {\r\n context.fillStyle = this.color;\r\n }\r\n context.shadowColor = this.color;\r\n context.shadowBlur = this.blur;\r\n context.shadowOffsetX = this.offsetX;\r\n context.shadowOffsetY = this.offsetY;\r\n }\r\n colorizeGhost(_context, _forceColor) { }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nclass GraphicsImage extends Op {\r\n constructor(image, width, height, x, y) {\r\n super();\r\n Object.defineProperty(this, \"image\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: image\r\n });\r\n Object.defineProperty(this, \"width\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: width\r\n });\r\n Object.defineProperty(this, \"height\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: height\r\n });\r\n Object.defineProperty(this, \"x\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: x\r\n });\r\n Object.defineProperty(this, \"y\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: y\r\n });\r\n }\r\n path(context) {\r\n context.drawImage(this.image, this.x, this.y, this.width, this.height);\r\n }\r\n // TODO: OK?\r\n addBounds(bounds) {\r\n setPoint(bounds, { x: this.x, y: this.y });\r\n setPoint(bounds, { x: this.width, y: this.height });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasGraphics extends CanvasDisplayObject {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_operations\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"blendMode\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: BlendMode.NORMAL\r\n });\r\n Object.defineProperty(this, \"_hasShadows\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_fillAlpha\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_strokeAlpha\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n clear() {\r\n super.clear();\r\n this._operations.length = 0;\r\n }\r\n _pushOp(op) {\r\n this._operations.push(op);\r\n }\r\n beginFill(color, alpha = 1) {\r\n this._fillAlpha = alpha;\r\n if (color) {\r\n if (color instanceof Color) {\r\n this._pushOp(new BeginFill(color.toCSS(alpha)));\r\n }\r\n else {\r\n this.isMeasured = true;\r\n this._pushOp(new BeginFill(color));\r\n }\r\n }\r\n else {\r\n this._pushOp(new BeginFill(\"rgba(0, 0, 0, \" + alpha + \")\"));\r\n }\r\n }\r\n endFill() {\r\n this._pushOp(new EndFill(this._hasShadows));\r\n }\r\n endStroke() {\r\n this._pushOp(new EndStroke());\r\n }\r\n beginPath() {\r\n this._pushOp(new BeginPath());\r\n }\r\n lineStyle(width = 0, color, alpha = 1, lineJoin) {\r\n this._strokeAlpha = alpha;\r\n if (color) {\r\n if (color instanceof Color) {\r\n this._pushOp(new LineStyle(width, color.toCSS(alpha), lineJoin));\r\n }\r\n else {\r\n this._pushOp(new LineStyle(width, color, lineJoin));\r\n }\r\n }\r\n else {\r\n this._pushOp(new LineStyle(width, \"rgba(0, 0, 0, \" + alpha + \")\", lineJoin));\r\n }\r\n }\r\n setLineDash(dash) {\r\n this._pushOp(new LineDash(dash ? dash : []));\r\n }\r\n setLineDashOffset(dashOffset = 0) {\r\n this._pushOp(new LineDashOffset(dashOffset));\r\n }\r\n drawRect(x, y, width, height) {\r\n this._pushOp(new DrawRect(x, y, width, height));\r\n }\r\n drawCircle(x, y, radius) {\r\n this._pushOp(new DrawCircle(x, y, radius));\r\n }\r\n drawEllipse(x, y, radiusX, radiusY) {\r\n this._pushOp(new DrawEllipse(x, y, radiusX, radiusY));\r\n }\r\n arc(cx, cy, radius, startAngle, endAngle, anticlockwise = false) {\r\n this._pushOp(new Arc(cx, cy, radius, startAngle, endAngle, anticlockwise));\r\n }\r\n arcTo(x1, y1, x2, y2, radius) {\r\n this._pushOp(new ArcTo(x1, y1, x2, y2, radius));\r\n }\r\n lineTo(x, y) {\r\n this._pushOp(new LineTo(x, y));\r\n }\r\n moveTo(x, y) {\r\n this._pushOp(new MoveTo(x, y));\r\n }\r\n bezierCurveTo(cpX, cpY, cpX2, cpY2, toX, toY) {\r\n this._pushOp(new BezierCurveTo(cpX, cpY, cpX2, cpY2, toX, toY));\r\n }\r\n quadraticCurveTo(cpX, cpY, toX, toY) {\r\n this._pushOp(new QuadraticCurveTo(cpX, cpY, toX, toY));\r\n }\r\n closePath() {\r\n this._pushOp(new ClosePath());\r\n }\r\n shadow(color, blur = 0, offsetX = 0, offsetY = 0, opacity) {\r\n this._hasShadows = true;\r\n this._pushOp(new Shadow(opacity ? color.toCSS(opacity) : color.toCSS(this._fillAlpha || this._strokeAlpha), blur, offsetX, offsetY));\r\n }\r\n image(image, width, height, x, y) {\r\n this._pushOp(new GraphicsImage(image, width, height, x, y));\r\n }\r\n // https://svgwg.org/svg2-draft/paths.html#DProperty\r\n // TODO better error checking\r\n svgPath(path) {\r\n let x = 0;\r\n let y = 0;\r\n let cpx = null;\r\n let cpy = null;\r\n let qcpx = null;\r\n let qcpy = null;\r\n const SEGMENTS_REGEXP = /([MmZzLlHhVvCcSsQqTtAa])([^MmZzLlHhVvCcSsQqTtAa]*)/g;\r\n const ARGS_REGEXP = /[\\u0009\\u0020\\u000A\\u000C\\u000D]*([\\+\\-]?[0-9]*\\.?[0-9]+(?:[eE][\\+\\-]?[0-9]+)?)[\\u0009\\u0020\\u000A\\u000C\\u000D]*,?/g;\r\n let match;\r\n while ((match = SEGMENTS_REGEXP.exec(path)) !== null) {\r\n const name = match[1];\r\n const rest = match[2];\r\n const args = [];\r\n while ((match = ARGS_REGEXP.exec(rest)) !== null) {\r\n args.push(match[1]);\r\n }\r\n // Reset control point\r\n if (name !== \"S\" && name !== \"s\" && name !== \"C\" && name !== \"c\") {\r\n cpx = null;\r\n cpy = null;\r\n }\r\n // Reset control point\r\n if (name !== \"Q\" && name !== \"q\" && name !== \"T\" && name !== \"t\") {\r\n qcpx = null;\r\n qcpy = null;\r\n }\r\n switch (name) {\r\n case \"M\":\r\n checkEvenArgs(name, args.length, 2);\r\n x = +args[0];\r\n y = +args[1];\r\n this.moveTo(x, y);\r\n for (let i = 2; i < args.length; i += 2) {\r\n x = +args[i];\r\n y = +args[i + 1];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"m\":\r\n checkEvenArgs(name, args.length, 2);\r\n x += +args[0];\r\n y += +args[1];\r\n this.moveTo(x, y);\r\n for (let i = 2; i < args.length; i += 2) {\r\n x += +args[i];\r\n y += +args[i + 1];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"L\":\r\n checkEvenArgs(name, args.length, 2);\r\n for (let i = 0; i < args.length; i += 2) {\r\n x = +args[i];\r\n y = +args[i + 1];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"l\":\r\n checkEvenArgs(name, args.length, 2);\r\n for (let i = 0; i < args.length; i += 2) {\r\n x += +args[i];\r\n y += +args[i + 1];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"H\":\r\n checkMinArgs(name, args.length, 1);\r\n for (let i = 0; i < args.length; ++i) {\r\n x = +args[i];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"h\":\r\n checkMinArgs(name, args.length, 1);\r\n for (let i = 0; i < args.length; ++i) {\r\n x += +args[i];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"V\":\r\n checkMinArgs(name, args.length, 1);\r\n for (let i = 0; i < args.length; ++i) {\r\n y = +args[i];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"v\":\r\n checkMinArgs(name, args.length, 1);\r\n for (let i = 0; i < args.length; ++i) {\r\n y += +args[i];\r\n this.lineTo(x, y);\r\n }\r\n break;\r\n case \"C\":\r\n checkEvenArgs(name, args.length, 6);\r\n for (let i = 0; i < args.length; i += 6) {\r\n const x1 = +args[i];\r\n const y1 = +args[i + 1];\r\n cpx = +args[i + 2];\r\n cpy = +args[i + 3];\r\n x = +args[i + 4];\r\n y = +args[i + 5];\r\n this.bezierCurveTo(x1, y1, cpx, cpy, x, y);\r\n }\r\n break;\r\n case \"c\":\r\n checkEvenArgs(name, args.length, 6);\r\n for (let i = 0; i < args.length; i += 6) {\r\n const x1 = +args[i] + x;\r\n const y1 = +args[i + 1] + y;\r\n cpx = +args[i + 2] + x;\r\n cpy = +args[i + 3] + y;\r\n x += +args[i + 4];\r\n y += +args[i + 5];\r\n this.bezierCurveTo(x1, y1, cpx, cpy, x, y);\r\n }\r\n break;\r\n case \"S\":\r\n checkEvenArgs(name, args.length, 4);\r\n if (cpx === null || cpy === null) {\r\n cpx = x;\r\n cpy = y;\r\n }\r\n for (let i = 0; i < args.length; i += 4) {\r\n const x1 = 2 * x - cpx;\r\n const y1 = 2 * y - cpy;\r\n cpx = +args[i];\r\n cpy = +args[i + 1];\r\n x = +args[i + 2];\r\n y = +args[i + 3];\r\n this.bezierCurveTo(x1, y1, cpx, cpy, x, y);\r\n }\r\n break;\r\n case \"s\":\r\n checkEvenArgs(name, args.length, 4);\r\n if (cpx === null || cpy === null) {\r\n cpx = x;\r\n cpy = y;\r\n }\r\n for (let i = 0; i < args.length; i += 4) {\r\n const x1 = 2 * x - cpx;\r\n const y1 = 2 * y - cpy;\r\n cpx = +args[i] + x;\r\n cpy = +args[i + 1] + y;\r\n x += +args[i + 2];\r\n y += +args[i + 3];\r\n this.bezierCurveTo(x1, y1, cpx, cpy, x, y);\r\n }\r\n break;\r\n case \"Q\":\r\n checkEvenArgs(name, args.length, 4);\r\n for (let i = 0; i < args.length; i += 4) {\r\n qcpx = +args[i];\r\n qcpy = +args[i + 1];\r\n x = +args[i + 2];\r\n y = +args[i + 3];\r\n this.quadraticCurveTo(qcpx, qcpy, x, y);\r\n }\r\n break;\r\n case \"q\":\r\n checkEvenArgs(name, args.length, 4);\r\n for (let i = 0; i < args.length; i += 4) {\r\n qcpx = +args[i] + x;\r\n qcpy = +args[i + 1] + y;\r\n x += +args[i + 2];\r\n y += +args[i + 3];\r\n this.quadraticCurveTo(qcpx, qcpy, x, y);\r\n }\r\n break;\r\n case \"T\":\r\n checkEvenArgs(name, args.length, 2);\r\n if (qcpx === null || qcpy === null) {\r\n qcpx = x;\r\n qcpy = y;\r\n }\r\n for (let i = 0; i < args.length; i += 2) {\r\n qcpx = 2 * x - qcpx;\r\n qcpy = 2 * y - qcpy;\r\n x = +args[i];\r\n y = +args[i + 1];\r\n this.quadraticCurveTo(qcpx, qcpy, x, y);\r\n }\r\n break;\r\n case \"t\":\r\n checkEvenArgs(name, args.length, 2);\r\n if (qcpx === null || qcpy === null) {\r\n qcpx = x;\r\n qcpy = y;\r\n }\r\n for (let i = 0; i < args.length; i += 2) {\r\n qcpx = 2 * x - qcpx;\r\n qcpy = 2 * y - qcpy;\r\n x += +args[i];\r\n y += +args[i + 1];\r\n this.quadraticCurveTo(qcpx, qcpy, x, y);\r\n }\r\n break;\r\n case \"A\":\r\n case \"a\":\r\n const relative = (name === \"a\");\r\n splitArcFlags(args);\r\n checkEvenArgs(name, args.length, 7);\r\n for (let i = 0; i < args.length; i += 7) {\r\n let cx = +args[i + 5];\r\n let cy = +args[i + 6];\r\n if (relative) {\r\n cx += x;\r\n cy += y;\r\n }\r\n const bs = arcToBezier({\r\n px: x,\r\n py: y,\r\n rx: +args[i],\r\n ry: +args[i + 1],\r\n xAxisRotation: +args[i + 2],\r\n largeArcFlag: assertBinary(+args[i + 3]),\r\n sweepFlag: assertBinary(+args[i + 4]),\r\n cx,\r\n cy,\r\n });\r\n $array.each(bs, (b) => {\r\n this.bezierCurveTo(b.x1, b.y1, b.x2, b.y2, b.x, b.y);\r\n x = b.x;\r\n y = b.y;\r\n });\r\n }\r\n break;\r\n case \"Z\":\r\n case \"z\":\r\n checkArgs(name, args.length, 0);\r\n this.closePath();\r\n break;\r\n }\r\n }\r\n }\r\n _runPath(context) {\r\n context.beginPath();\r\n $array.each(this._operations, (op) => {\r\n op.path(context);\r\n });\r\n }\r\n _render(status) {\r\n super._render(status);\r\n const layerDirty = status.layer.dirty;\r\n const interactive = this._isInteractive(status);\r\n if (layerDirty || interactive) {\r\n const context = status.layer.context;\r\n const ghostContext = this._renderer._ghostLayer.context;\r\n if (layerDirty) {\r\n context.globalCompositeOperation = this.blendMode;\r\n context.beginPath();\r\n }\r\n let color;\r\n if (interactive) {\r\n ghostContext.beginPath();\r\n color = this._getColorId();\r\n }\r\n $array.each(this._operations, (op) => {\r\n if (layerDirty) {\r\n op.path(context);\r\n op.colorize(context, undefined);\r\n }\r\n if (interactive) {\r\n op.pathGhost(ghostContext);\r\n op.colorizeGhost(ghostContext, color);\r\n }\r\n });\r\n }\r\n }\r\n renderDetached(context) {\r\n if (this.visible) {\r\n this._setMatrix();\r\n context.save();\r\n // We must apply the mask before we transform the element\r\n const mask = this.mask;\r\n if (mask) {\r\n mask._setMatrix();\r\n mask._transform(context, 1);\r\n mask._runPath(context);\r\n context.clip();\r\n }\r\n // TODO handle compoundAlpha somehow ?\r\n context.globalAlpha = this.compoundAlpha * this.alpha;\r\n this._transform(context, 1);\r\n if (this.filter) {\r\n context.filter = this.filter;\r\n }\r\n context.globalCompositeOperation = this.blendMode;\r\n context.beginPath();\r\n $array.each(this._operations, (op) => {\r\n op.path(context);\r\n op.colorize(context, undefined);\r\n });\r\n context.restore();\r\n }\r\n }\r\n _addBounds(bounds) {\r\n if (this.visible && this.isMeasured) {\r\n $array.each(this._operations, (op) => {\r\n op.addBounds(bounds);\r\n });\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasText extends CanvasDisplayObject {\r\n constructor(renderer, text, style) {\r\n super(renderer);\r\n Object.defineProperty(this, \"text\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"style\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"resolution\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 1\r\n });\r\n Object.defineProperty(this, \"textVisible\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"_textInfo\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_originalScale\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 1\r\n });\r\n this.text = text;\r\n this.style = style;\r\n }\r\n invalidateBounds() {\r\n super.invalidateBounds();\r\n this._textInfo = undefined;\r\n }\r\n _shared(context) {\r\n if (this.style.textAlign) {\r\n context.textAlign = this.style.textAlign;\r\n }\r\n if (this.style.direction) {\r\n context.direction = this.style.direction;\r\n }\r\n if (this.style.textBaseline) {\r\n context.textBaseline = this.style.textBaseline;\r\n }\r\n }\r\n _prerender(status, ignoreGhost = false, ignoreFontWeight = false) {\r\n super._render(status);\r\n const context = status.layer.context;\r\n const ghostContext = this._renderer._ghostLayer.context;\r\n // Font style\r\n const style = this.style;\r\n let fontStyle = this._getFontStyle(undefined, ignoreFontWeight);\r\n context.font = fontStyle;\r\n if (this._isInteractive(status) && !ignoreGhost) {\r\n ghostContext.font = fontStyle;\r\n }\r\n // Other parameters\r\n if (style.fill) {\r\n if (style.fill instanceof Color) {\r\n context.fillStyle = style.fill.toCSS(style.fillOpacity != undefined ? style.fillOpacity : 1);\r\n }\r\n else {\r\n context.fillStyle = style.fill;\r\n }\r\n }\r\n if (style.shadowColor) {\r\n status.layer.context.shadowColor = style.shadowColor.toCSS(style.shadowOpacity || 1);\r\n }\r\n if (style.shadowBlur) {\r\n status.layer.context.shadowBlur = style.shadowBlur;\r\n }\r\n if (style.shadowOffsetX) {\r\n status.layer.context.shadowOffsetX = style.shadowOffsetX;\r\n }\r\n if (style.shadowOffsetY) {\r\n status.layer.context.shadowOffsetY = style.shadowOffsetY;\r\n }\r\n this._shared(context);\r\n if (this._isInteractive(status) && !ignoreGhost) {\r\n ghostContext.fillStyle = this._getColorId();\r\n this._shared(ghostContext);\r\n }\r\n }\r\n _getFontStyle(style2, ignoreFontWeight = false) {\r\n // Process defaults\r\n const style = this.style;\r\n let fontStyle = [];\r\n if (style2 && style2.fontVariant) {\r\n fontStyle.push(style2.fontVariant);\r\n }\r\n else if (style.fontVariant) {\r\n fontStyle.push(style.fontVariant);\r\n }\r\n if (!ignoreFontWeight) {\r\n if (style2 && style2.fontWeight) {\r\n fontStyle.push(style2.fontWeight);\r\n }\r\n else if (style.fontWeight) {\r\n fontStyle.push(style.fontWeight);\r\n }\r\n }\r\n if (style2 && style2.fontStyle) {\r\n fontStyle.push(style2.fontStyle);\r\n }\r\n else if (style.fontStyle) {\r\n fontStyle.push(style.fontStyle);\r\n }\r\n if (style2 && style2.fontSize) {\r\n if ($type.isNumber(style2.fontSize)) {\r\n style2.fontSize = style2.fontSize + \"px\";\r\n }\r\n fontStyle.push(style2.fontSize);\r\n }\r\n else if (style.fontSize) {\r\n if ($type.isNumber(style.fontSize)) {\r\n style.fontSize = style.fontSize + \"px\";\r\n }\r\n fontStyle.push(style.fontSize);\r\n }\r\n if (style2 && style2.fontFamily) {\r\n fontStyle.push(style2.fontFamily);\r\n }\r\n else if (style.fontFamily) {\r\n fontStyle.push(style.fontFamily);\r\n }\r\n else if (fontStyle.length) {\r\n fontStyle.push(\"Arial\");\r\n }\r\n return fontStyle.join(\" \");\r\n }\r\n _render(status) {\r\n // We need measurements in order to properly position text for alignment\r\n if (!this._textInfo) {\r\n this._measure(status);\r\n }\r\n if (this.textVisible) {\r\n const interactive = this._isInteractive(status);\r\n const context = status.layer.context;\r\n const layerDirty = status.layer.dirty;\r\n const ghostContext = this._renderer._ghostLayer.context;\r\n context.save();\r\n ghostContext.save();\r\n this._prerender(status);\r\n // const lines = this.text.toString().replace(/\\r/g, \"\").split(/\\n/);\r\n // const x = this._localBounds && (this._localBounds.left < 0) ? Math.abs(this._localBounds.left) : 0;\r\n // Process text info produced by _measure()\r\n $array.each(this._textInfo, (line, _index) => {\r\n $array.each(line.textChunks, (chunk, _index) => {\r\n // Set style\r\n if (chunk.style) {\r\n context.save();\r\n ghostContext.save();\r\n context.font = chunk.style;\r\n if (this._isInteractive(status)) {\r\n ghostContext.font = chunk.style;\r\n }\r\n }\r\n if (chunk.fill) {\r\n context.save();\r\n context.fillStyle = chunk.fill.toCSS();\r\n // Color does not affect ghostContext so we not set it\r\n }\r\n // Draw text\r\n if (layerDirty) {\r\n context.fillText(chunk.text, chunk.offsetX, line.offsetY + chunk.offsetY);\r\n }\r\n // Draw underline\r\n if (chunk.textDecoration == \"underline\" || chunk.textDecoration == \"line-through\") {\r\n let thickness = 1;\r\n let offset = 1;\r\n let fontSize = chunk.height;\r\n const oversizedBehavior = this.style.oversizedBehavior || \"\";\r\n if ([\"truncate\", \"wrap\", \"wrap-no-break\"].indexOf(oversizedBehavior) > -1) {\r\n // Measure actual width of the text so the line fits\r\n const metrics = this._measureText(chunk.text, context);\r\n chunk.width = metrics.actualBoundingBoxLeft + metrics.actualBoundingBoxRight;\r\n }\r\n let offsetX = chunk.offsetX;\r\n switch (this.style.textAlign) {\r\n case \"right\":\r\n case \"end\":\r\n offsetX -= chunk.width;\r\n break;\r\n case \"center\":\r\n offsetX -= chunk.width / 2;\r\n break;\r\n }\r\n if (chunk.style) {\r\n const format = TextFormatter.getTextStyle(chunk.style);\r\n switch (format.fontWeight) {\r\n case \"bolder\":\r\n case \"bold\":\r\n case \"700\":\r\n case \"800\":\r\n case \"900\":\r\n thickness = 2;\r\n break;\r\n }\r\n }\r\n if (fontSize) {\r\n offset = fontSize / 20;\r\n }\r\n let y;\r\n if (chunk.textDecoration == \"line-through\") {\r\n y = thickness + line.offsetY + chunk.offsetY - chunk.height / 2;\r\n }\r\n else {\r\n y = thickness + offset * 1.5 + line.offsetY + chunk.offsetY;\r\n }\r\n context.save();\r\n context.beginPath();\r\n if (chunk.fill) {\r\n context.strokeStyle = chunk.fill.toCSS();\r\n }\r\n else if (this.style.fill && this.style.fill instanceof Color) {\r\n context.strokeStyle = this.style.fill.toCSS();\r\n }\r\n context.lineWidth = thickness * offset;\r\n context.moveTo(offsetX, y);\r\n context.lineTo(offsetX + chunk.width, y);\r\n context.stroke();\r\n context.restore();\r\n }\r\n if (interactive && this.interactive) {\r\n // Draw text in ghost canvas ONLY if it is set as interactive\r\n // explicitly. This way we avoid hit test anomalies caused by anti\r\n // aliasing of text.\r\n ghostContext.fillText(chunk.text, chunk.offsetX, line.offsetY + chunk.offsetY);\r\n }\r\n if (chunk.fill) {\r\n context.restore();\r\n // Color does not affect ghostContext so we not set it\r\n }\r\n // Reset style\r\n if (chunk.style) {\r\n context.restore();\r\n ghostContext.restore();\r\n }\r\n });\r\n });\r\n context.restore();\r\n ghostContext.restore();\r\n }\r\n }\r\n _addBounds(bounds) {\r\n if (this.visible && this.isMeasured) {\r\n //if (this._textVisible) {\r\n const x = this._measure({\r\n inactive: this.inactive,\r\n layer: this.getLayer(),\r\n });\r\n setPoint(bounds, { x: x.left, y: x.top });\r\n setPoint(bounds, { x: x.right, y: x.bottom });\r\n //}\r\n }\r\n }\r\n _ignoreFontWeight() {\r\n return /apple/i.test(navigator.vendor);\r\n }\r\n _measure(status) {\r\n const context = status.layer.context;\r\n const ghostContext = this._renderer._ghostLayer.context;\r\n const rtl = this.style.direction == \"rtl\";\r\n // Reset text info\r\n this._textInfo = [];\r\n // Init\r\n const oversizedBehavior = this.style.oversizedBehavior;\r\n const maxWidth = this.style.maxWidth;\r\n const truncate = $type.isNumber(maxWidth) && oversizedBehavior == \"truncate\";\r\n const wrap = $type.isNumber(maxWidth) && (oversizedBehavior == \"wrap\" || oversizedBehavior == \"wrap-no-break\");\r\n // Pre-render\r\n context.save();\r\n ghostContext.save();\r\n this._prerender(status, true, this._ignoreFontWeight());\r\n // Get default font metrix\r\n const refText = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 \";\r\n // Split up text into lines\r\n const lines = this.text.toString().replace(/\\r/g, \"\").split(/\\n/);\r\n let styleRestored = true;\r\n let minX = 0;\r\n let maxX = 0;\r\n // Iterate through the lines\r\n let offsetY = 0;\r\n let currentStyle;\r\n $array.each(lines, (line, _index) => {\r\n // Split up line into format/value chunks\r\n let chunks;\r\n if (line == \"\") {\r\n chunks = [{\r\n type: \"value\",\r\n text: \"\"\r\n }];\r\n }\r\n else {\r\n chunks = TextFormatter.chunk(line, false, this.style.ignoreFormatting);\r\n }\r\n while (chunks.length > 0) {\r\n // Init line object\r\n let lineInfo = {\r\n offsetY: offsetY,\r\n ascent: 0,\r\n width: 0,\r\n height: 0,\r\n left: 0,\r\n right: 0,\r\n textChunks: []\r\n };\r\n // Measure reference text\r\n const metrics = this._measureText(refText, context);\r\n const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n lineInfo.height = height;\r\n lineInfo.ascent = metrics.actualBoundingBoxAscent;\r\n let currentFormat;\r\n let currentDecoration = this.style.textDecoration;\r\n let currentFill;\r\n let currentChunkWidth;\r\n let skipFurtherText = false;\r\n let firstTextChunk = true;\r\n let leftoverChunks = [];\r\n let currentVerticalAlign;\r\n //let offsetX = 0;\r\n //let chunk;\r\n //while(chunk = chunks.shift()) {\r\n $array.eachContinue(chunks, (chunk, index) => {\r\n // Format chunk\r\n if (chunk.type == \"format\") {\r\n if (chunk.text == \"[/]\") {\r\n if (!styleRestored) {\r\n context.restore();\r\n ghostContext.restore();\r\n styleRestored = true;\r\n }\r\n currentFill = undefined;\r\n currentStyle = undefined;\r\n currentChunkWidth = undefined;\r\n currentDecoration = this.style.textDecoration;\r\n currentVerticalAlign = undefined;\r\n currentFormat = chunk.text;\r\n }\r\n else {\r\n if (!styleRestored) {\r\n context.restore();\r\n ghostContext.restore();\r\n }\r\n let format = TextFormatter.getTextStyle(chunk.text);\r\n const fontStyle = this._getFontStyle(format);\r\n context.save();\r\n ghostContext.save();\r\n context.font = fontStyle;\r\n currentStyle = fontStyle;\r\n currentFormat = chunk.text;\r\n if (format.textDecoration) {\r\n currentDecoration = format.textDecoration;\r\n }\r\n if (format.fill) {\r\n currentFill = format.fill;\r\n }\r\n if (format.width) {\r\n currentChunkWidth = $type.toNumber(format.width);\r\n }\r\n if (format.verticalAlign) {\r\n currentVerticalAlign = format.verticalAlign;\r\n }\r\n styleRestored = false;\r\n // Measure reference text after change of format\r\n const metrics = this._measureText(refText, context);\r\n const height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n if (height > lineInfo.height) {\r\n lineInfo.height = height;\r\n }\r\n if (metrics.actualBoundingBoxAscent > lineInfo.ascent) {\r\n lineInfo.ascent = metrics.actualBoundingBoxAscent;\r\n }\r\n }\r\n }\r\n // Text chunk\r\n else if (chunk.type == \"value\" && !skipFurtherText) {\r\n // Measure\r\n const metrics = this._measureText(chunk.text, context);\r\n let chunkWidth = metrics.actualBoundingBoxLeft + metrics.actualBoundingBoxRight;\r\n // Check for fit\r\n if (truncate) {\r\n // Break words?\r\n let breakWords = firstTextChunk || this.style.breakWords || false;\r\n // Measure ellipsis and check if it fits\r\n const ellipsis = this.style.ellipsis || \"\";\r\n const ellipsisMetrics = this._measureText(ellipsis, context);\r\n const ellipsisWidth = ellipsisMetrics.actualBoundingBoxLeft + ellipsisMetrics.actualBoundingBoxRight;\r\n // Check fit\r\n if ((lineInfo.width + chunkWidth) > maxWidth) {\r\n const excessWidth = maxWidth - lineInfo.width - ellipsisWidth;\r\n chunk.text = this._truncateText(context, chunk.text, excessWidth, breakWords);\r\n chunk.text += ellipsis;\r\n skipFurtherText = true;\r\n }\r\n }\r\n else if (wrap) {\r\n // Check fit\r\n if ((lineInfo.width + chunkWidth) > maxWidth) {\r\n const excessWidth = maxWidth - lineInfo.width;\r\n const tmpText = this._truncateText(context, chunk.text, excessWidth, false, (firstTextChunk && this.style.oversizedBehavior != \"wrap-no-break\"));\r\n if (tmpText == \"\") {\r\n // Unable to fit a single letter - hide the whole label\r\n this.textVisible = true;\r\n return false;\r\n }\r\n //skipFurtherText = true;\r\n //Add remaining chunks for the next line\r\n leftoverChunks = chunks.slice(index + 1);\r\n //Add remaining text of current chunk if it was forced-cut\r\n if ($utils.trim(tmpText) != $utils.trim(chunk.text)) {\r\n leftoverChunks.unshift({\r\n type: \"value\",\r\n text: chunk.text.substr(tmpText.length)\r\n });\r\n if (currentFormat) {\r\n leftoverChunks.unshift({\r\n type: \"format\",\r\n text: currentFormat\r\n });\r\n }\r\n }\r\n // Set current chunk (truncated)\r\n chunk.text = $utils.trim(tmpText);\r\n chunks = [];\r\n skipFurtherText = true;\r\n }\r\n }\r\n // Chunk width?\r\n let leftBoundMod = 1;\r\n let rightBoundMod = 1;\r\n if (currentStyle && currentChunkWidth && (currentChunkWidth > chunkWidth)) {\r\n // increase horizontal bounding boxes accordingly\r\n const boundsMod = chunkWidth / currentChunkWidth;\r\n switch (this.style.textAlign) {\r\n case \"right\":\r\n case \"end\":\r\n leftBoundMod = boundsMod;\r\n break;\r\n case \"center\":\r\n leftBoundMod = boundsMod;\r\n rightBoundMod = boundsMod;\r\n break;\r\n default:\r\n rightBoundMod = boundsMod;\r\n }\r\n chunkWidth = currentChunkWidth;\r\n }\r\n const chunkHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n if (chunkHeight > lineInfo.height) {\r\n lineInfo.height = chunkHeight;\r\n }\r\n if (metrics.actualBoundingBoxAscent > lineInfo.ascent) {\r\n lineInfo.ascent = metrics.actualBoundingBoxAscent;\r\n }\r\n lineInfo.width += chunkWidth;\r\n lineInfo.left += metrics.actualBoundingBoxLeft / leftBoundMod;\r\n lineInfo.right += metrics.actualBoundingBoxRight / rightBoundMod;\r\n lineInfo.textChunks.push({\r\n style: currentStyle,\r\n fill: currentFill,\r\n text: chunk.text,\r\n width: chunkWidth,\r\n height: chunkHeight,\r\n left: metrics.actualBoundingBoxLeft,\r\n right: metrics.actualBoundingBoxRight,\r\n ascent: metrics.actualBoundingBoxAscent,\r\n offsetX: 0,\r\n offsetY: 0,\r\n textDecoration: currentDecoration,\r\n verticalAlign: currentVerticalAlign\r\n });\r\n //offsetX += chunkWidth;\r\n firstTextChunk = false;\r\n }\r\n if (leftoverChunks) {\r\n //return false;\r\n }\r\n return true;\r\n //}\r\n });\r\n if (this.style.lineHeight instanceof Percent) {\r\n lineInfo.height *= this.style.lineHeight.value;\r\n lineInfo.ascent *= this.style.lineHeight.value;\r\n }\r\n else {\r\n lineInfo.height *= this.style.lineHeight || 1.2;\r\n lineInfo.ascent *= this.style.lineHeight || 1.2;\r\n }\r\n if (minX < lineInfo.left) {\r\n minX = lineInfo.left;\r\n }\r\n if (maxX < lineInfo.right) {\r\n maxX = lineInfo.right;\r\n }\r\n this._textInfo.push(lineInfo);\r\n //lineInfo.offsetY += lineInfo.ascent;\r\n offsetY += lineInfo.height;\r\n // Reset chunks so that it can proceed to the next line\r\n chunks = leftoverChunks || [];\r\n }\r\n });\r\n if (!styleRestored) {\r\n context.restore();\r\n ghostContext.restore();\r\n }\r\n // Adjust chunk internal offsets\r\n $array.each(this._textInfo, (lineInfo, _index) => {\r\n let currentChunkOffset = 0;\r\n $array.each(lineInfo.textChunks, (chunk) => {\r\n chunk.offsetX = currentChunkOffset + chunk.left - lineInfo.left;\r\n chunk.offsetY += lineInfo.height - lineInfo.height * (this.style.baselineRatio || 0.19);\r\n currentChunkOffset += chunk.width;\r\n if (chunk.verticalAlign) {\r\n switch (chunk.verticalAlign) {\r\n case \"super\":\r\n chunk.offsetY -= lineInfo.height / 2 - chunk.height / 2;\r\n break;\r\n case \"sub\":\r\n chunk.offsetY += chunk.height / 2;\r\n break;\r\n }\r\n }\r\n });\r\n });\r\n const bounds = {\r\n left: rtl ? -maxX : -minX,\r\n top: 0,\r\n right: rtl ? minX : maxX,\r\n bottom: offsetY,\r\n };\r\n // We need to fit?\r\n if (oversizedBehavior !== \"none\") {\r\n const ratio = this._fitRatio(bounds);\r\n if (ratio < 1) {\r\n if (oversizedBehavior == \"fit\") {\r\n if ($type.isNumber(this.style.minScale) && (ratio < this.style.minScale)) {\r\n this.textVisible = false;\r\n bounds.left = 0;\r\n bounds.top = 0;\r\n bounds.right = 0;\r\n bounds.bottom = 0;\r\n }\r\n else {\r\n if (!this._originalScale || this._originalScale == 1) {\r\n this._originalScale = this.scale;\r\n }\r\n this.scale = ratio;\r\n this.textVisible = true;\r\n }\r\n }\r\n else if (oversizedBehavior == \"hide\") {\r\n this.textVisible = false;\r\n bounds.left = 0;\r\n bounds.top = 0;\r\n bounds.right = 0;\r\n bounds.bottom = 0;\r\n }\r\n else {\r\n switch (this.style.textAlign) {\r\n case \"right\":\r\n case \"end\":\r\n bounds.left = rtl ? maxWidth : -maxWidth;\r\n bounds.right = 0;\r\n break;\r\n case \"center\":\r\n bounds.left = -maxWidth / 2;\r\n bounds.right = maxWidth / 2;\r\n break;\r\n default:\r\n bounds.left = 0;\r\n bounds.right = rtl ? -maxWidth : maxWidth;\r\n }\r\n this.scale = this._originalScale || 1;\r\n this._originalScale = undefined;\r\n this.textVisible = true;\r\n }\r\n }\r\n else {\r\n this.scale = this._originalScale || 1;\r\n this._originalScale = undefined;\r\n this.textVisible = true;\r\n }\r\n }\r\n context.restore();\r\n ghostContext.restore();\r\n return bounds;\r\n }\r\n _fitRatio(bounds) {\r\n const maxW = this.style.maxWidth;\r\n const maxH = this.style.maxHeight;\r\n if (!$type.isNumber(maxW) && !$type.isNumber(maxH)) {\r\n return 1;\r\n }\r\n const w = bounds.right - bounds.left;\r\n const h = bounds.bottom - bounds.top;\r\n return Math.min(maxW / w || 1, maxH / h || 1);\r\n }\r\n _truncateText(context, text, maxWidth, breakWords = false, fallbackBreakWords = true) {\r\n let width;\r\n do {\r\n if (breakWords) {\r\n text = text.slice(0, -1);\r\n }\r\n else {\r\n let tmp = text.replace(/[^,;:!?\\\\\\/\\s​]+[,;:!?\\\\\\/\\s​]*$/g, \"\");\r\n if ((tmp == \"\" || tmp === text) && fallbackBreakWords) {\r\n breakWords = true;\r\n }\r\n else if (tmp == \"\") {\r\n return text;\r\n }\r\n else {\r\n text = tmp;\r\n }\r\n }\r\n const metrics = this._measureText(text, context);\r\n width = metrics.actualBoundingBoxLeft + metrics.actualBoundingBoxRight;\r\n } while ((width > maxWidth) && text != \"\");\r\n return text;\r\n }\r\n _measureText(text, context) {\r\n let metrics = context.measureText(text);\r\n let fakeMetrics = {};\r\n if (metrics.actualBoundingBoxAscent == null) {\r\n const div = document.createElement(\"div\");\r\n div.innerText = text;\r\n div.style.visibility = \"hidden\";\r\n div.style.position = \"absolute\";\r\n div.style.top = \"-1000000px;\";\r\n div.style.fontFamily = this.style.fontFamily || \"\";\r\n div.style.fontSize = this.style.fontSize + \"\";\r\n document.body.appendChild(div);\r\n const bbox = div.getBoundingClientRect();\r\n document.body.removeChild(div);\r\n const h = bbox.height;\r\n const w = metrics.width;\r\n let left = 0;\r\n let right = w;\r\n fakeMetrics = {\r\n actualBoundingBoxAscent: h,\r\n actualBoundingBoxDescent: 0,\r\n actualBoundingBoxLeft: left,\r\n actualBoundingBoxRight: right,\r\n fontBoundingBoxAscent: h,\r\n fontBoundingBoxDescent: 0,\r\n width: w\r\n };\r\n //return fake;\r\n }\r\n else {\r\n fakeMetrics = {\r\n actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,\r\n actualBoundingBoxDescent: metrics.actualBoundingBoxDescent,\r\n actualBoundingBoxLeft: metrics.actualBoundingBoxLeft,\r\n actualBoundingBoxRight: metrics.actualBoundingBoxRight,\r\n fontBoundingBoxAscent: metrics.actualBoundingBoxAscent,\r\n fontBoundingBoxDescent: metrics.actualBoundingBoxDescent,\r\n width: metrics.width\r\n };\r\n }\r\n const w = metrics.width;\r\n switch (this.style.textAlign) {\r\n case \"right\":\r\n case \"end\":\r\n fakeMetrics.actualBoundingBoxLeft = w;\r\n fakeMetrics.actualBoundingBoxRight = 0;\r\n break;\r\n case \"center\":\r\n fakeMetrics.actualBoundingBoxLeft = w / 2;\r\n fakeMetrics.actualBoundingBoxRight = w / 2;\r\n break;\r\n default:\r\n fakeMetrics.actualBoundingBoxLeft = 0;\r\n fakeMetrics.actualBoundingBoxRight = w;\r\n }\r\n return fakeMetrics;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasTextStyle {\r\n constructor() {\r\n //public wordWrapWidth: number = 100;\r\n Object.defineProperty(this, \"fill\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"fillOpacity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"textAlign\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"fontFamily\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"fontSize\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"fontWeight\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"fontStyle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"fontVariant\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"textDecoration\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowColor\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowBlur\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowOffsetX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowOffsetY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowOpacity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n // leading?: number;\r\n // letterSpacing?: number;\r\n Object.defineProperty(this, \"lineHeight\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: percent(120)\r\n });\r\n Object.defineProperty(this, \"baselineRatio\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0.19\r\n });\r\n // padding?: number;\r\n // stroke?: number;\r\n // strokeThickness?: number;\r\n // trim?: number;\r\n // wordWrap?: boolean;\r\n Object.defineProperty(this, \"direction\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"textBaseline\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"oversizedBehavior\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"none\"\r\n });\r\n Object.defineProperty(this, \"breakWords\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"ellipsis\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"…\"\r\n });\r\n Object.defineProperty(this, \"maxWidth\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"maxHeight\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"minScale\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"ignoreFormatting\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasRadialText extends CanvasText {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"textType\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"circular\"\r\n });\r\n Object.defineProperty(this, \"radius\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"startAngle\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"inside\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"orientation\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"auto\"\r\n });\r\n Object.defineProperty(this, \"kerning\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_textReversed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n }\r\n _render(status) {\r\n switch (this.textType) {\r\n case \"circular\":\r\n this._renderCircular(status);\r\n break;\r\n default:\r\n super._render(status);\r\n break;\r\n }\r\n }\r\n _renderCircular(status) {\r\n if (this.textVisible) {\r\n this._prerender(status);\r\n const interactive = this._isInteractive(status);\r\n const context = status.layer.context;\r\n const layerDirty = status.layer.dirty;\r\n const ghostContext = this._renderer._ghostLayer.context;\r\n // Savepoint\r\n context.save();\r\n if (interactive) {\r\n ghostContext.save();\r\n }\r\n // We need measurements in order to properly position text for alignment\r\n if (!this._textInfo) {\r\n this._measure(status);\r\n }\r\n // Init\r\n let radius = (this.radius || 0);\r\n let startAngle = (this.startAngle || 0);\r\n let deltaAngle = 0;\r\n let orientation = this.orientation;\r\n let inward = orientation == \"auto\" ? \"auto\" : orientation == \"inward\";\r\n const inside = this.inside;\r\n const align = this.style.textAlign || \"left\";\r\n const kerning = this.kerning || 0;\r\n let clockwise = align == \"left\" ? 1 : -1;\r\n const shouldReverse = !this._textReversed;\r\n // Check if we need to invert the whole stuff\r\n if (inward == \"auto\") {\r\n // Calc max angle so we know whether we need to flip it\r\n let maxAngle = 0;\r\n let midAngle = 0;\r\n $array.each(this._textInfo, (line, _index) => {\r\n const deltaAngle = startAngle + (line.width / (radius - line.height)) / 2 * -clockwise;\r\n if (deltaAngle > maxAngle) {\r\n maxAngle = deltaAngle;\r\n }\r\n });\r\n if (align == \"left\") {\r\n midAngle = (maxAngle + deltaAngle / 2) * $math.DEGREES;\r\n }\r\n else if (align == \"right\") {\r\n midAngle = (maxAngle - deltaAngle / 2) * $math.DEGREES;\r\n }\r\n else {\r\n midAngle = startAngle * $math.DEGREES;\r\n }\r\n midAngle = $math.normalizeAngle(midAngle);\r\n inward = (midAngle >= 270) || (midAngle <= 90);\r\n }\r\n if (inward == true && shouldReverse) {\r\n this._textInfo.reverse();\r\n this._textReversed = true;\r\n }\r\n // if ((inward == false && align == \"left\") || (inward == true && align == \"right\")) {\r\n // \tclockwise *= -1;\r\n // }\r\n // Process text info produced by _measure()\r\n $array.each(this._textInfo, (line, _index) => {\r\n const textHeight = line.height;\r\n // Adjust radius (for `inside = false`)\r\n // Radius adjustment for `inside = false` is below the line calculation\r\n if (!inside) {\r\n radius += textHeight;\r\n }\r\n // Reverse letters if we're painting them counter-clockwise\r\n if (((clockwise == -1 && inward) || (clockwise == 1 && !inward)) && shouldReverse) {\r\n line.textChunks.reverse();\r\n }\r\n // Init angles\r\n let lineStartAngle = startAngle;\r\n deltaAngle = 0;\r\n // Adjust for center-align\r\n if (align == \"center\") {\r\n lineStartAngle += (line.width / (radius - textHeight)) / 2 * -clockwise;\r\n deltaAngle = lineStartAngle - startAngle;\r\n }\r\n // if (inward == \"auto\") {\r\n // \tlet midAngle;\r\n // \tif (align == \"left\") {\r\n // \t\tmidAngle = (lineStartAngle + deltaAngle / 2) * $math.DEGREES;\r\n // \t}\r\n // \telse if () {\r\n // \t\tmidAngle = (lineStartAngle - deltaAngle / 2) * $math.DEGREES;\r\n // \t}\r\n // \tinward = (midAngle >= 270) || (midAngle <= 90);\r\n // }\r\n // Rotate letters if they are facing outward\r\n lineStartAngle += (Math.PI * (inward ? 0 : 1)); // Rotate 180 if outward\r\n // Savepoint\r\n context.save();\r\n if (interactive) {\r\n ghostContext.save();\r\n }\r\n // Assume starting angle\r\n context.rotate(lineStartAngle);\r\n if (interactive) {\r\n ghostContext.rotate(lineStartAngle);\r\n }\r\n let angleShift = 0;\r\n $array.each(line.textChunks, (chunk, _index) => {\r\n // Draw the letter\r\n const char = chunk.text;\r\n const charWidth = chunk.width;\r\n // Rotate half a letter\r\n angleShift = (charWidth / 2) / (radius - textHeight) * clockwise;\r\n context.rotate(angleShift);\r\n if (interactive) {\r\n ghostContext.rotate(angleShift);\r\n }\r\n // Set style\r\n if (chunk.style) {\r\n context.save();\r\n ghostContext.save();\r\n context.font = chunk.style;\r\n if (interactive) {\r\n ghostContext.font = chunk.style;\r\n }\r\n }\r\n if (chunk.fill) {\r\n context.save();\r\n context.fillStyle = chunk.fill.toCSS();\r\n // Color does not affect ghostContext so we not set it\r\n }\r\n // Center letters\r\n context.textBaseline = \"middle\";\r\n context.textAlign = \"center\";\r\n if (interactive) {\r\n ghostContext.textBaseline = \"middle\";\r\n ghostContext.textAlign = \"center\";\r\n }\r\n // Plop the letter\r\n if (layerDirty) {\r\n context.fillText(char, 0, (inward ? 1 : -1) * (0 - radius + textHeight / 2));\r\n }\r\n if (interactive) {\r\n ghostContext.fillText(char, 0, (inward ? 1 : -1) * (0 - radius + textHeight / 2));\r\n }\r\n if (chunk.fill) {\r\n context.restore();\r\n // Color does not affect ghostContext so we not set it\r\n }\r\n // Reset style\r\n if (chunk.style) {\r\n context.restore();\r\n ghostContext.restore();\r\n }\r\n // Rotate half a letter and add spacing\r\n angleShift = (charWidth / 2 + kerning) / (radius - textHeight) * clockwise;\r\n context.rotate(angleShift);\r\n if (interactive) {\r\n ghostContext.rotate(angleShift);\r\n }\r\n });\r\n // Restore angle\r\n context.restore();\r\n if (interactive) {\r\n ghostContext.restore();\r\n }\r\n // Adjust radius (for `inside = true`)\r\n if (inside) {\r\n radius -= textHeight;\r\n }\r\n });\r\n // Restore\r\n context.restore();\r\n if (interactive) {\r\n ghostContext.restore();\r\n }\r\n }\r\n }\r\n _measure(status) {\r\n switch (this.textType) {\r\n case \"circular\":\r\n return this._measureCircular(status);\r\n default:\r\n return super._measure(status);\r\n }\r\n }\r\n _measureCircular(status) {\r\n const context = status.layer.context;\r\n const ghostContext = this._renderer._ghostLayer.context;\r\n const rtl = this.style.direction == \"rtl\";\r\n const oversizedBehavior = this.style.oversizedBehavior;\r\n const maxWidth = this.style.maxWidth;\r\n const truncate = $type.isNumber(maxWidth) && oversizedBehavior == \"truncate\";\r\n const ellipsis = this.style.ellipsis || \"\";\r\n let ellipsisMetrics;\r\n //const wrap = $type.isNumber(maxWidth) && (oversizedBehavior == \"wrap\" || oversizedBehavior == \"wrap-no-break\");\r\n // Reset text info\r\n this.textVisible = true;\r\n this._textInfo = [];\r\n this._textReversed = false;\r\n // Pre-render\r\n context.save();\r\n ghostContext.save();\r\n this._prerender(status, true);\r\n // Split up text into lines\r\n const lines = this.text.toString().replace(/\\r/g, \"\").split(/\\n/);\r\n let styleRestored = true;\r\n let totalWidth = 0;\r\n // Iterate through the lines\r\n let offsetY = 0;\r\n $array.each(lines, (line, _index) => {\r\n // Split up line into format/value chunks\r\n let chunks = TextFormatter.chunk(line, false, this.style.ignoreFormatting);\r\n // Init line object\r\n let lineInfo = {\r\n offsetY: offsetY,\r\n ascent: 0,\r\n width: 0,\r\n height: 0,\r\n left: 0,\r\n right: 0,\r\n textChunks: []\r\n };\r\n let currentStyle;\r\n let currentFill;\r\n let currentChunkWidth;\r\n //while(chunk = chunks.shift()) {\r\n $array.each(chunks, (chunk, _index) => {\r\n // Format chunk\r\n if (chunk.type == \"format\") {\r\n if (chunk.text == \"[/]\") {\r\n if (!styleRestored) {\r\n context.restore();\r\n ghostContext.restore();\r\n styleRestored = true;\r\n }\r\n currentFill = undefined;\r\n currentStyle = undefined;\r\n currentChunkWidth = undefined;\r\n }\r\n else {\r\n let format = TextFormatter.getTextStyle(chunk.text);\r\n const fontStyle = this._getFontStyle(format);\r\n context.save();\r\n ghostContext.save();\r\n context.font = fontStyle;\r\n currentStyle = fontStyle;\r\n if (format.fill) {\r\n currentFill = format.fill;\r\n }\r\n if (format.width) {\r\n currentChunkWidth = $type.toNumber(format.width);\r\n }\r\n styleRestored = false;\r\n }\r\n if (truncate) {\r\n ellipsisMetrics = this._measureText(ellipsis, context);\r\n }\r\n }\r\n // Text format\r\n else if (chunk.type == \"value\") {\r\n // Measure each letter\r\n let chars = chunk.text.match(/./ug) || [];\r\n if (rtl) {\r\n chars = $utils.splitString(chunk.text);\r\n chars.reverse();\r\n }\r\n for (let i = 0; i < chars.length; i++) {\r\n const char = chars[i];\r\n // Measure\r\n const metrics = this._measureText(char, context);\r\n let chunkWidth = metrics.width;\r\n // Chunk width?\r\n if (currentStyle && currentChunkWidth && (currentChunkWidth > chunkWidth)) {\r\n chunkWidth = currentChunkWidth;\r\n }\r\n const chunkHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;\r\n if (chunkHeight > lineInfo.height) {\r\n lineInfo.height = chunkHeight;\r\n }\r\n if (metrics.actualBoundingBoxAscent > lineInfo.ascent) {\r\n lineInfo.ascent = metrics.actualBoundingBoxAscent;\r\n }\r\n totalWidth += chunkWidth;\r\n // Handle oversized behavior\r\n if (truncate) {\r\n // Measure ellipsis and check if it fits\r\n if (!ellipsisMetrics) {\r\n ellipsisMetrics = this._measureText(ellipsis, context);\r\n }\r\n const ellipsisWidth = ellipsisMetrics.actualBoundingBoxLeft + ellipsisMetrics.actualBoundingBoxRight;\r\n //totalWidth += ellipsisWidth;\r\n if ((totalWidth + ellipsisWidth) > maxWidth) {\r\n if (lineInfo.textChunks.length == 1) {\r\n this.textVisible = false;\r\n }\r\n else {\r\n lineInfo.width += ellipsisWidth;\r\n lineInfo.left += ellipsisMetrics.actualBoundingBoxLeft;\r\n lineInfo.right += ellipsisMetrics.actualBoundingBoxRight;\r\n lineInfo.textChunks.push({\r\n style: currentStyle,\r\n fill: currentFill,\r\n text: ellipsis,\r\n width: ellipsisWidth,\r\n height: chunkHeight + ellipsisMetrics.actualBoundingBoxDescent,\r\n left: ellipsisMetrics.actualBoundingBoxLeft,\r\n right: ellipsisMetrics.actualBoundingBoxRight,\r\n ascent: ellipsisMetrics.actualBoundingBoxAscent,\r\n offsetX: 0,\r\n offsetY: chunkHeight,\r\n textDecoration: undefined\r\n });\r\n }\r\n break;\r\n }\r\n }\r\n lineInfo.width += chunkWidth;\r\n lineInfo.left += metrics.actualBoundingBoxLeft;\r\n lineInfo.right += metrics.actualBoundingBoxRight;\r\n lineInfo.textChunks.push({\r\n style: currentStyle,\r\n fill: currentFill,\r\n text: char,\r\n width: chunkWidth,\r\n height: chunkHeight + metrics.actualBoundingBoxDescent,\r\n left: metrics.actualBoundingBoxLeft,\r\n right: metrics.actualBoundingBoxRight,\r\n ascent: metrics.actualBoundingBoxAscent,\r\n offsetX: 0,\r\n offsetY: chunkHeight,\r\n textDecoration: undefined\r\n });\r\n if (rtl) {\r\n // @todo still needed?\r\n //break;\r\n }\r\n }\r\n }\r\n });\r\n if (this.style.lineHeight instanceof Percent) {\r\n lineInfo.height *= this.style.lineHeight.value;\r\n }\r\n else {\r\n lineInfo.height *= this.style.lineHeight || 1.2;\r\n }\r\n this._textInfo.push(lineInfo);\r\n //lineInfo.offsetY += lineInfo.ascent;\r\n offsetY += lineInfo.height;\r\n });\r\n if (!styleRestored) {\r\n context.restore();\r\n ghostContext.restore();\r\n }\r\n if (oversizedBehavior == \"hide\" && (totalWidth > maxWidth)) {\r\n this.textVisible = false;\r\n }\r\n // Adjust chunk internal offsets\r\n $array.each(this._textInfo, (lineInfo) => {\r\n $array.each(lineInfo.textChunks, (chunk) => {\r\n chunk.offsetY += Math.round((lineInfo.height - chunk.height + (lineInfo.ascent - chunk.ascent)) / 2);\r\n });\r\n });\r\n context.restore();\r\n ghostContext.restore();\r\n return {\r\n left: 0,\r\n top: 0,\r\n right: 0,\r\n bottom: 0,\r\n };\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasImage extends CanvasDisplayObject {\r\n constructor(renderer, image) {\r\n super(renderer);\r\n Object.defineProperty(this, \"width\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"height\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"image\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"tainted\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowColor\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowBlur\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowOffsetX\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowOffsetY\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"shadowOpacity\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_imageMask\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this.image = image;\r\n }\r\n _dispose() {\r\n super._dispose();\r\n if (this._imageMask) {\r\n clearCanvas(this._imageMask);\r\n }\r\n }\r\n getLocalBounds() {\r\n if (!this._localBounds) {\r\n let w = 0;\r\n let h = 0;\r\n if (this.width) {\r\n w = this.width;\r\n }\r\n if (this.height) {\r\n h = this.height;\r\n }\r\n this._localBounds = {\r\n left: 0,\r\n top: 0,\r\n right: w,\r\n bottom: h\r\n };\r\n this._addBounds(this._localBounds);\r\n }\r\n return this._localBounds;\r\n }\r\n _render(status) {\r\n super._render(status);\r\n if (this.image) {\r\n if (this.tainted === undefined) {\r\n this.tainted = isTainted(this.image);\r\n status.layer.tainted = true;\r\n }\r\n if (this.tainted && this._renderer._omitTainted) {\r\n return;\r\n }\r\n if (status.layer.dirty) {\r\n if (this.shadowColor) {\r\n status.layer.context.shadowColor = this.shadowColor.toCSS(this.shadowOpacity || 1);\r\n }\r\n if (this.shadowBlur) {\r\n status.layer.context.shadowBlur = this.shadowBlur;\r\n }\r\n if (this.shadowOffsetX) {\r\n status.layer.context.shadowOffsetX = this.shadowOffsetX;\r\n }\r\n if (this.shadowOffsetY) {\r\n status.layer.context.shadowOffsetY = this.shadowOffsetY;\r\n }\r\n // TODO should this round ?\r\n const width = this.width || this.image.naturalWidth;\r\n const height = this.height || this.image.naturalHeight;\r\n status.layer.context.drawImage(this.image, 0, 0, width, height);\r\n }\r\n if (this.interactive && this._isInteractive(status)) {\r\n const mask = this._getMask(this.image);\r\n this._renderer._ghostLayer.context.drawImage(mask, 0, 0);\r\n }\r\n }\r\n }\r\n clear() {\r\n super.clear();\r\n this.image = undefined;\r\n this._imageMask = undefined;\r\n }\r\n _getMask(image) {\r\n if (this._imageMask === undefined) {\r\n // TODO should this round ?\r\n const width = this.width || image.naturalWidth;\r\n const height = this.height || image.naturalHeight;\r\n // We need to create a second canvas because destination-in clears out the entire canvas\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = width;\r\n canvas.height = height;\r\n const context = canvas.getContext(\"2d\");\r\n context.imageSmoothingEnabled = false;\r\n context.fillStyle = this._getColorId();\r\n context.fillRect(0, 0, width, height);\r\n if (!isTainted(image)) {\r\n context.globalCompositeOperation = \"destination-in\";\r\n context.drawImage(image, 0, 0, width, height);\r\n }\r\n this._imageMask = canvas;\r\n }\r\n return this._imageMask;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasRendererEvent {\r\n constructor(event, originalPoint, point, bbox) {\r\n Object.defineProperty(this, \"event\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: event\r\n });\r\n Object.defineProperty(this, \"originalPoint\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: originalPoint\r\n });\r\n Object.defineProperty(this, \"point\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: point\r\n });\r\n Object.defineProperty(this, \"bbox\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: bbox\r\n });\r\n Object.defineProperty(this, \"id\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"simulated\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"native\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n if ($utils.supports(\"touchevents\") && event instanceof Touch) {\r\n this.id = event.identifier;\r\n }\r\n else {\r\n this.id = null;\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasRenderer extends ArrayDisposer {\r\n constructor(resolution) {\r\n super();\r\n Object.defineProperty(this, \"view\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: document.createElement(\"div\")\r\n });\r\n Object.defineProperty(this, \"_layerDom\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: document.createElement(\"div\")\r\n });\r\n Object.defineProperty(this, \"layers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_dirtyLayers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"defaultLayer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this.getLayer(0)\r\n });\r\n Object.defineProperty(this, \"_ghostLayer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new GhostLayer()\r\n });\r\n Object.defineProperty(this, \"_patternCanvas\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: document.createElement(\"canvas\")\r\n });\r\n Object.defineProperty(this, \"_patternContext\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._patternCanvas.getContext(\"2d\")\r\n });\r\n Object.defineProperty(this, \"_realWidth\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_realHeight\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_calculatedWidth\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_calculatedHeight\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"resolution\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"interactionsEnabled\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"_listeners\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_colorId\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_colorMap\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_forceInteractive\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_omitTainted\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n // TODO this should store the Id as well\r\n Object.defineProperty(this, \"_hovering\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new Set()\r\n });\r\n Object.defineProperty(this, \"_dragging\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_mousedown\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_lastPointerMoveEvent\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"tapToActivate\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"tapToActivateTimeout\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 3000\r\n });\r\n Object.defineProperty(this, \"_touchActive\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_touchActiveTimeout\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n if (resolution == null) {\r\n this.resolution = window.devicePixelRatio;\r\n }\r\n else {\r\n this.resolution = resolution;\r\n }\r\n this.view.style.position = \"absolute\";\r\n this.view.setAttribute(\"aria-hidden\", \"true\");\r\n this.view.appendChild(this._layerDom);\r\n this._disposers.push(new Disposer(() => {\r\n $object.each(this._events, (_key, events) => {\r\n events.disposer.dispose();\r\n });\r\n $array.each(this.layers, (layer) => {\r\n clearCanvas(layer.view);\r\n if (layer.exportableView) {\r\n clearCanvas(layer.exportableView);\r\n }\r\n });\r\n clearCanvas(this._ghostLayer.view);\r\n clearCanvas(this._patternCanvas);\r\n }));\r\n /*\r\n this._disposers.push($utils.addEventListener(this._ghostLayer.view, \"click\", (originalEvent: MouseEvent) => {\r\n const event = this.getEvent(originalEvent);\r\n const target = this._getHitTarget(event.originalPoint, event.bbox);\r\n console.debug(target);\r\n }));\r\n */\r\n // Monitor for possible pixel ratio changes (when page is zoomed)\r\n this._disposers.push($utils.onZoom(() => {\r\n if (resolution == null) {\r\n this.resolution = window.devicePixelRatio;\r\n }\r\n }));\r\n // We need this in order top prevent default touch gestures when dragging\r\n // draggable elements\r\n if ($utils.supports(\"touchevents\")) {\r\n const listener = (ev) => {\r\n if (this._dragging.length !== 0) {\r\n $array.eachContinue(this._dragging, (item) => {\r\n if (item.value.shouldCancelTouch()) {\r\n ev.preventDefault();\r\n return false;\r\n }\r\n return true;\r\n });\r\n }\r\n // If touch down happends, delay touch out\r\n if (this._touchActiveTimeout) {\r\n this._delayTouchDeactivate();\r\n }\r\n };\r\n this._disposers.push($utils.addEventListener(window, \"touchstart\", listener, { passive: false }));\r\n this._disposers.push($utils.addEventListener(this.view, \"touchstart\", listener, { passive: false }));\r\n this._disposers.push($utils.addEventListener(this.view, \"touchmove\", () => {\r\n // If touch is moving, delay touch out\r\n if (this._touchActiveTimeout) {\r\n this._delayTouchDeactivate();\r\n }\r\n }, { passive: true }));\r\n this._disposers.push($utils.addEventListener(window, \"click\", (_ev) => {\r\n this._touchActive = false;\r\n }, { passive: true }));\r\n this._disposers.push($utils.addEventListener(this.view, \"click\", (_ev) => {\r\n window.setTimeout(() => {\r\n this._touchActive = true;\r\n this._delayTouchDeactivate();\r\n }, 100);\r\n }, { passive: true }));\r\n }\r\n // Prevent scrolling of the window when hovering on \"wheelable\" object\r\n if ($utils.supports(\"wheelevents\")) {\r\n this._disposers.push($utils.addEventListener(this.view, \"wheel\", (ev) => {\r\n let prevent = false;\r\n this._hovering.forEach((obj) => {\r\n if (obj.wheelable) {\r\n prevent = true;\r\n return false;\r\n }\r\n });\r\n if (prevent) {\r\n ev.preventDefault();\r\n }\r\n }, { passive: false }));\r\n }\r\n }\r\n /*protected _mouseMoveThrottler: Throttler = new Throttler(() => {\r\n this._dispatchGlobalMousemove(this._lastPointerMoveEvent.event, this._lastPointerMoveEvent.native);\r\n });\r\n */\r\n resetImageArray() {\r\n this._ghostLayer.imageArray = undefined;\r\n }\r\n _delayTouchDeactivate() {\r\n if (this._touchActiveTimeout) {\r\n clearTimeout(this._touchActiveTimeout);\r\n }\r\n if (this.tapToActivateTimeout > 0) {\r\n this._touchActiveTimeout = window.setTimeout(() => {\r\n this._touchActive = false;\r\n }, this.tapToActivateTimeout);\r\n }\r\n }\r\n get debugGhostView() {\r\n return !!this._ghostLayer.view.parentNode;\r\n }\r\n set debugGhostView(value) {\r\n if (value) {\r\n if (!this._ghostLayer.view.parentNode) {\r\n this.view.appendChild(this._ghostLayer.view);\r\n }\r\n }\r\n else {\r\n if (this._ghostLayer.view.parentNode) {\r\n this._ghostLayer.view.parentNode.removeChild(this._ghostLayer.view);\r\n }\r\n }\r\n }\r\n createLinearGradient(x1, y1, x2, y2) {\r\n return this.defaultLayer.context.createLinearGradient(x1, y1, x2, y2);\r\n }\r\n createRadialGradient(x1, y1, radius1, x2, y2, radius2) {\r\n return this.defaultLayer.context.createRadialGradient(x1, y1, radius1, x2, y2, radius2);\r\n }\r\n createPattern(graphics, background, repetition, width, height) {\r\n // const patternCanvas = document.createElement(\"canvas\");\r\n // const patternContext = patternCanvas.getContext(\"2d\")!;\r\n // patternCanvas.width = width;\r\n // patternCanvas.height = height;\r\n // if (fill) {\r\n // \tpatternContext.fillStyle = fill.toCSS();\r\n // \tpatternContext.fillRect(0, 0, patternCanvas.width, patternCanvas.height);\r\n // }\r\n // const layer = {\r\n // \tview: patternCanvas,\r\n // \tcontext: patternContext,\r\n // \tvisible: true,\r\n // \torder: 0,\r\n // \twidth: width,\r\n // \theight: height,\r\n // \tdirty: true\r\n // };\r\n // // patternContext.arc(0, 0, 50, 0, .5 * Math.PI);\r\n // // patternContext.stroke();\r\n // image.targetLayer = layer;\r\n // image.render(layer);\r\n //this._layerDom.appendChild(patternCanvas);\r\n this._patternCanvas.width = width;\r\n this._patternCanvas.height = height;\r\n this._patternContext.clearRect(0, 0, width, height);\r\n // patternCanvas.style.width = width * this.resolution + \"px\";\r\n // patternCanvas.style.height = height * this.resolution + \"px\";\r\n background.renderDetached(this._patternContext);\r\n graphics.renderDetached(this._patternContext);\r\n return this._patternContext.createPattern(this._patternCanvas, repetition);\r\n }\r\n makeContainer() {\r\n return new CanvasContainer(this);\r\n }\r\n makeGraphics() {\r\n return new CanvasGraphics(this);\r\n }\r\n makeText(text, style) {\r\n return new CanvasText(this, text, style);\r\n }\r\n makeTextStyle() {\r\n return new CanvasTextStyle();\r\n }\r\n makeRadialText(text, style) {\r\n return new CanvasRadialText(this, text, style);\r\n }\r\n makePicture(image) {\r\n return new CanvasImage(this, image);\r\n }\r\n resizeLayer(layer) {\r\n layer.resize(this._calculatedWidth, this._calculatedHeight, this._calculatedWidth, this._calculatedHeight, this.resolution);\r\n }\r\n resizeGhost() {\r\n this._ghostLayer.resize(this._calculatedWidth, this._calculatedHeight, this._calculatedWidth, this._calculatedHeight, this.resolution);\r\n }\r\n resize(realWidth, realHeight, calculatedWidth, calculatedHeight) {\r\n this._realWidth = realWidth;\r\n this._realHeight = realHeight;\r\n this._calculatedWidth = calculatedWidth;\r\n this._calculatedHeight = calculatedHeight;\r\n $array.each(this.layers, (layer) => {\r\n if (layer) {\r\n layer.dirty = true;\r\n this.resizeLayer(layer);\r\n }\r\n });\r\n this.resizeGhost();\r\n this.view.style.width = calculatedWidth + \"px\";\r\n this.view.style.height = calculatedHeight + \"px\";\r\n }\r\n createDetachedLayer(willReadFrequently = false) {\r\n const view = document.createElement(\"canvas\");\r\n const context = view.getContext(\"2d\", { willReadFrequently: willReadFrequently });\r\n const layer = new CanvasLayer(view, context);\r\n view.style.position = \"absolute\";\r\n view.style.top = \"0px\";\r\n view.style.left = \"0px\";\r\n return layer;\r\n }\r\n getLayerByOrder(order) {\r\n const layers = this.layers;\r\n const length = layers.length;\r\n for (let i = 0; i < length; i++) {\r\n const layer = layers[i];\r\n if (layer.order == order) {\r\n return layer;\r\n }\r\n }\r\n }\r\n getLayer(order, visible = true) {\r\n let existingLayer = this.getLayerByOrder(order);\r\n if (existingLayer) {\r\n return existingLayer;\r\n }\r\n const layer = this.createDetachedLayer(order == 99);\r\n layer.order = order;\r\n layer.visible = visible;\r\n layer.view.className = \"am5-layer-\" + order;\r\n if (layer.visible) {\r\n this.resizeLayer(layer);\r\n }\r\n const layers = this.layers;\r\n layers.push(layer);\r\n layers.sort((a, b) => {\r\n if (a.order > b.order) {\r\n return 1;\r\n }\r\n else if (a.order < b.order) {\r\n return -1;\r\n }\r\n else {\r\n return 0;\r\n }\r\n });\r\n const length = layers.length;\r\n const layerIndex = $array.indexOf(layers, layer);\r\n let next;\r\n for (let i = layerIndex + 1; i < length; i++) {\r\n if (layers[i].visible) {\r\n next = layers[i];\r\n break;\r\n }\r\n }\r\n if (layer.visible) {\r\n if (next === undefined) {\r\n this._layerDom.appendChild(layer.view);\r\n }\r\n else {\r\n this._layerDom.insertBefore(layer.view, next.view);\r\n }\r\n }\r\n return layer;\r\n }\r\n render(root) {\r\n this._dirtyLayers.length = 0;\r\n $array.each(this.layers, (layer) => {\r\n if (layer) {\r\n if (layer.dirty && layer.visible) {\r\n this._dirtyLayers.push(layer);\r\n layer.clear();\r\n }\r\n }\r\n });\r\n this._ghostLayer.clear();\r\n root.render({\r\n inactive: null,\r\n layer: this.defaultLayer,\r\n });\r\n this._ghostLayer.context.restore();\r\n //setTimeout(() => {\r\n // Remove this after the Chrome bug is fixed:\r\n // https://bugs.chromium.org/p/chromium/issues/detail?id=1279394\r\n $array.each(this.layers, (layer) => {\r\n if (layer) {\r\n const context = layer.context;\r\n context.beginPath();\r\n context.moveTo(0, 0);\r\n context.stroke();\r\n }\r\n });\r\n $array.each(this._dirtyLayers, (layer) => {\r\n layer.context.restore();\r\n layer.dirty = false;\r\n });\r\n //}, 100)\r\n if (this._hovering.size && this._lastPointerMoveEvent) {\r\n const { events, target, native } = this._lastPointerMoveEvent;\r\n //this._mouseMoveThrottler.run();\r\n $array.each(events, (event) => {\r\n this._dispatchGlobalMousemove(event, target, native);\r\n });\r\n }\r\n }\r\n paintId(obj) {\r\n const id = distributeId(++this._colorId);\r\n const color = Color.fromHex(id).toCSS();\r\n this._colorMap[color] = obj;\r\n return color;\r\n }\r\n _removeObject(obj) {\r\n if (obj._colorId !== undefined) {\r\n delete this._colorMap[obj._colorId];\r\n }\r\n }\r\n // protected _identifyObjectByColor(colorId: number): CanvasDisplayObject | undefined {\r\n // \treturn this._colorMap[colorId];\r\n // }\r\n _adjustBoundingBox(bbox) {\r\n const margin = this._ghostLayer.margin;\r\n return new DOMRect(-margin.left, -margin.top, bbox.width + margin.left + margin.right, bbox.height + margin.top + margin.bottom);\r\n }\r\n getEvent(originalEvent, adjustPoint = true) {\r\n const bbox = this.view.getBoundingClientRect();\r\n const x = originalEvent.clientX || 0;\r\n const y = originalEvent.clientY || 0;\r\n const widthScale = this._calculatedWidth / this._realWidth;\r\n const heightScale = this._calculatedHeight / this._realHeight;\r\n const originalPoint = {\r\n x: x - bbox.left,\r\n y: y - bbox.top,\r\n };\r\n const point = {\r\n x: (x - (adjustPoint ? bbox.left : 0)) * widthScale,\r\n y: (y - (adjustPoint ? bbox.top : 0)) * heightScale,\r\n };\r\n return new CanvasRendererEvent(originalEvent, originalPoint, point, this._adjustBoundingBox(bbox));\r\n }\r\n _getHitTarget(point, bbox, target) {\r\n if (bbox.width === 0 || bbox.height === 0 || point.x < bbox.left || point.x > bbox.right || point.y < bbox.top || point.y > bbox.bottom) {\r\n return;\r\n }\r\n if (!target || !this._layerDom.contains(target)) {\r\n return;\r\n }\r\n const pixel = this._ghostLayer.getImageData(point, bbox);\r\n if (pixel.data[0] === 0 && pixel.data[1] === 0 && pixel.data[2] === 0) {\r\n return false;\r\n }\r\n const colorId = Color.fromRGB(pixel.data[0], pixel.data[1], pixel.data[2]).toCSS();\r\n const hit = this._colorMap[colorId];\r\n return hit;\r\n }\r\n getObjectAtPoint(point) {\r\n const data = this._ghostLayer.getImageArray(point);\r\n if (data[0] === 0 && data[1] === 0 && data[2] === 0) {\r\n return undefined;\r\n }\r\n const colorId = Color.fromRGB(data[0], data[1], data[2]).toCSS();\r\n const hit = this._colorMap[colorId];\r\n return hit;\r\n }\r\n _withEvents(key, f) {\r\n const events = this._events[key];\r\n if (events !== undefined) {\r\n events.dispatching = true;\r\n try {\r\n f(events);\r\n }\r\n finally {\r\n events.dispatching = false;\r\n if (events.cleanup) {\r\n events.cleanup = false;\r\n $array.keepIf(events.callbacks, (callback) => {\r\n return !callback.disposed;\r\n });\r\n if (events.callbacks.length === 0) {\r\n events.disposer.dispose();\r\n delete this._events[key];\r\n }\r\n }\r\n }\r\n }\r\n }\r\n _dispatchEventAll(key, event) {\r\n if (!this.interactionsEnabled) {\r\n return;\r\n }\r\n this._withEvents(key, (events) => {\r\n $array.each(events.callbacks, (callback) => {\r\n if (!callback.disposed) {\r\n callback.callback.call(callback.context, event);\r\n }\r\n });\r\n });\r\n }\r\n _dispatchEvent(key, target, event) {\r\n if (!this.interactionsEnabled) {\r\n return false;\r\n }\r\n let dispatched = false;\r\n this._withEvents(key, (events) => {\r\n $array.each(events.callbacks, (callback) => {\r\n if (!callback.disposed && callback.object === target) {\r\n callback.callback.call(callback.context, event);\r\n dispatched = true;\r\n }\r\n });\r\n });\r\n return dispatched;\r\n }\r\n _dispatchMousedown(originalEvent, originalTarget) {\r\n const button = originalEvent.button;\r\n if (button != 0 && button != 2 && button != 1 && button !== undefined) {\r\n // Ignore non-primary mouse buttons\r\n return;\r\n }\r\n const event = this.getEvent(originalEvent);\r\n const target = this._getHitTarget(event.originalPoint, event.bbox, originalTarget);\r\n if (target) {\r\n const id = event.id;\r\n let dragged = false;\r\n eachTargets(target, (obj) => {\r\n const info = { id: id, value: obj };\r\n this._mousedown.push(info);\r\n if (!dragged && this._dispatchEvent(\"pointerdown\", obj, event)) {\r\n // Only dispatch the first element which matches\r\n dragged = true;\r\n const has = this._dragging.some((x) => {\r\n return x.value === obj && x.id === id;\r\n });\r\n if (!has) {\r\n this._dragging.push(info);\r\n }\r\n }\r\n return true;\r\n });\r\n }\r\n }\r\n _dispatchGlobalMousemove(originalEvent, originalTarget, native) {\r\n const event = this.getEvent(originalEvent);\r\n const target = this._getHitTarget(event.originalPoint, event.bbox, originalTarget);\r\n event.native = native;\r\n if (target) {\r\n this._hovering.forEach((obj) => {\r\n if (!obj.contains(target)) {\r\n this._hovering.delete(obj);\r\n if (obj.cursorOverStyle) {\r\n $utils.setStyle(document.body, \"cursor\", obj._replacedCursorStyle);\r\n }\r\n this._dispatchEvent(\"pointerout\", obj, event);\r\n }\r\n });\r\n if (event.native) {\r\n eachTargets(target, (obj) => {\r\n if (!this._hovering.has(obj)) {\r\n this._hovering.add(obj);\r\n if (obj.cursorOverStyle) {\r\n obj._replacedCursorStyle = $utils.getStyle(document.body, \"cursor\");\r\n $utils.setStyle(document.body, \"cursor\", obj.cursorOverStyle);\r\n }\r\n this._dispatchEvent(\"pointerover\", obj, event);\r\n }\r\n return true;\r\n });\r\n }\r\n //} else if (target === false) {\r\n }\r\n else {\r\n this._hovering.forEach((obj) => {\r\n if (obj.cursorOverStyle) {\r\n $utils.setStyle(document.body, \"cursor\", obj._replacedCursorStyle);\r\n }\r\n this._dispatchEvent(\"pointerout\", obj, event);\r\n });\r\n this._hovering.clear();\r\n }\r\n this._dispatchEventAll(\"globalpointermove\", event);\r\n }\r\n removeHovering(graphics) {\r\n this._hovering.delete(graphics);\r\n if (graphics.cursorOverStyle) {\r\n $utils.setStyle(document.body, \"cursor\", graphics._replacedCursorStyle);\r\n }\r\n }\r\n _dispatchGlobalMouseup(originalEvent, native) {\r\n const event = this.getEvent(originalEvent);\r\n event.native = native;\r\n //const target = this._getHitTarget(event.originalPoint);\r\n this._dispatchEventAll(\"globalpointerup\", event);\r\n }\r\n _dispatchDragMove(originalEvent) {\r\n if (this._dragging.length !== 0) {\r\n const event = this.getEvent(originalEvent);\r\n const id = event.id;\r\n this._dragging.forEach((obj) => {\r\n if (obj.id === id) {\r\n this._dispatchEvent(\"pointermove\", obj.value, event);\r\n }\r\n });\r\n }\r\n }\r\n _dispatchDragEnd(originalEvent, originalTarget) {\r\n const button = originalEvent.button;\r\n let clickevent;\r\n if (button == 0 || button === undefined) {\r\n clickevent = \"click\";\r\n }\r\n else if (button == 2) {\r\n clickevent = \"rightclick\";\r\n }\r\n else if (button == 1) {\r\n clickevent = \"middleclick\";\r\n }\r\n else {\r\n // Ignore non-primary mouse buttons\r\n return;\r\n }\r\n const event = this.getEvent(originalEvent);\r\n const id = event.id;\r\n if (this._mousedown.length !== 0) {\r\n const target = this._getHitTarget(event.originalPoint, event.bbox, originalTarget);\r\n if (target) {\r\n this._mousedown.forEach((obj) => {\r\n if (obj.id === id && obj.value.contains(target)) {\r\n this._dispatchEvent(clickevent, obj.value, event);\r\n }\r\n });\r\n }\r\n this._mousedown.length = 0;\r\n }\r\n if (this._dragging.length !== 0) {\r\n this._dragging.forEach((obj) => {\r\n if (obj.id === id) {\r\n this._dispatchEvent(\"pointerup\", obj.value, event);\r\n }\r\n });\r\n this._dragging.length = 0;\r\n }\r\n }\r\n _dispatchDoubleClick(originalEvent, originalTarget) {\r\n const event = this.getEvent(originalEvent);\r\n const target = this._getHitTarget(event.originalPoint, event.bbox, originalTarget);\r\n if (target) {\r\n eachTargets(target, (obj) => {\r\n if (this._dispatchEvent(\"dblclick\", obj, event)) {\r\n return false;\r\n }\r\n else {\r\n return true;\r\n }\r\n });\r\n }\r\n }\r\n _dispatchWheel(originalEvent, originalTarget) {\r\n const event = this.getEvent(originalEvent);\r\n const target = this._getHitTarget(event.originalPoint, event.bbox, originalTarget);\r\n if (target) {\r\n eachTargets(target, (obj) => {\r\n if (this._dispatchEvent(\"wheel\", obj, event)) {\r\n return false;\r\n }\r\n else {\r\n return true;\r\n }\r\n });\r\n }\r\n }\r\n _makeSharedEvent(key, f) {\r\n if (this._listeners[key] === undefined) {\r\n const listener = f();\r\n this._listeners[key] = new CounterDisposer(() => {\r\n delete this._listeners[key];\r\n listener.dispose();\r\n });\r\n }\r\n return this._listeners[key].increment();\r\n }\r\n _onPointerEvent(name, f) {\r\n let native = false;\r\n let timer = null;\r\n function clear() {\r\n timer = null;\r\n native = false;\r\n }\r\n return new MultiDisposer([\r\n new Disposer(() => {\r\n if (timer !== null) {\r\n clearTimeout(timer);\r\n }\r\n clear();\r\n }),\r\n $utils.addEventListener(this.view, $utils.getRendererEvent(name), (_) => {\r\n native = true;\r\n if (timer !== null) {\r\n clearTimeout(timer);\r\n }\r\n timer = window.setTimeout(clear, 0);\r\n }),\r\n onPointerEvent(window, name, (ev, target) => {\r\n if (timer !== null) {\r\n clearTimeout(timer);\r\n timer = null;\r\n }\r\n f(ev, target, native);\r\n native = false;\r\n }),\r\n ]);\r\n }\r\n // This ensures that only a single DOM event is added (e.g. only a single mousemove event listener)\r\n _initEvent(key) {\r\n switch (key) {\r\n case \"globalpointermove\":\r\n case \"pointerover\":\r\n case \"pointerout\":\r\n return this._makeSharedEvent(\"pointermove\", () => {\r\n const listener = (events, target, native) => {\r\n this._lastPointerMoveEvent = { events, target, native };\r\n $array.each(events, (event) => {\r\n this._dispatchGlobalMousemove(event, target, native);\r\n });\r\n };\r\n return new MultiDisposer([\r\n this._onPointerEvent(\"pointerdown\", listener),\r\n this._onPointerEvent(\"pointermove\", listener),\r\n ]);\r\n });\r\n case \"globalpointerup\":\r\n return this._makeSharedEvent(\"pointerup\", () => {\r\n const mouseup = this._onPointerEvent(\"pointerup\", (events, target, native) => {\r\n $array.each(events, (event) => {\r\n this._dispatchGlobalMouseup(event, native);\r\n });\r\n this._lastPointerMoveEvent = { events, target, native };\r\n });\r\n const pointercancel = this._onPointerEvent(\"pointercancel\", (events, target, native) => {\r\n $array.each(events, (event) => {\r\n this._dispatchGlobalMouseup(event, native);\r\n });\r\n this._lastPointerMoveEvent = { events, target, native };\r\n });\r\n return new Disposer(() => {\r\n mouseup.dispose();\r\n pointercancel.dispose();\r\n });\r\n });\r\n case \"click\":\r\n case \"rightclick\":\r\n case \"middleclick\":\r\n case \"pointerdown\":\r\n /*\r\n return this._makeSharedEvent(\"pointerdown\", () => {\r\n return this._onPointerEvent(\"pointerdown\", (event, target, native) => {\r\n this._lastPointerMoveEvent = { event, target, native };\r\n this._dispatchMousedown(event)\r\n });\r\n });\r\n */\r\n case \"pointermove\":\r\n case \"pointerup\":\r\n return this._makeSharedEvent(\"pointerdown\", () => {\r\n //const throttler = new Throttler();\r\n const mousedown = this._onPointerEvent(\"pointerdown\", (events, target) => {\r\n $array.each(events, (ev) => {\r\n this._dispatchMousedown(ev, target);\r\n });\r\n });\r\n // TODO handle throttling properly for multitouch\r\n const mousemove = this._onPointerEvent(\"pointermove\", (ev) => {\r\n //throttler.throttle(() => {\r\n $array.each(ev, (ev) => {\r\n this._dispatchDragMove(ev);\r\n });\r\n //});\r\n });\r\n const mouseup = this._onPointerEvent(\"pointerup\", (ev, target) => {\r\n $array.each(ev, (ev) => {\r\n this._dispatchDragEnd(ev, target);\r\n });\r\n });\r\n const pointercancel = this._onPointerEvent(\"pointercancel\", (ev, target) => {\r\n $array.each(ev, (ev) => {\r\n this._dispatchDragEnd(ev, target);\r\n });\r\n });\r\n return new Disposer(() => {\r\n mousedown.dispose();\r\n mousemove.dispose();\r\n mouseup.dispose();\r\n pointercancel.dispose();\r\n });\r\n });\r\n case \"dblclick\":\r\n return this._makeSharedEvent(\"dblclick\", () => {\r\n return this._onPointerEvent(\"dblclick\", (ev, target) => {\r\n $array.each(ev, (ev) => {\r\n this._dispatchDoubleClick(ev, target);\r\n });\r\n });\r\n });\r\n case \"wheel\":\r\n return this._makeSharedEvent(\"wheel\", () => {\r\n return $utils.addEventListener(this.view, $utils.getRendererEvent(\"wheel\"), (event) => {\r\n this._dispatchWheel(event, $utils.getEventTarget(event));\r\n }, { passive: false });\r\n });\r\n }\r\n }\r\n _addEvent(object, key, callback, context) {\r\n let events = this._events[key];\r\n if (events === undefined) {\r\n events = this._events[key] = {\r\n disposer: this._initEvent(key),\r\n callbacks: [],\r\n dispatching: false,\r\n cleanup: false,\r\n };\r\n }\r\n const listener = { object, context, callback, disposed: false };\r\n events.callbacks.push(listener);\r\n return new Disposer(() => {\r\n listener.disposed = true;\r\n if (events.dispatching) {\r\n events.cleanup = true;\r\n }\r\n else {\r\n $array.removeFirst(events.callbacks, listener);\r\n if (events.callbacks.length === 0) {\r\n events.disposer.dispose();\r\n delete this._events[key];\r\n }\r\n }\r\n });\r\n }\r\n getCanvas(root, options) {\r\n // Make sure everything is rendered\r\n this.render(root);\r\n if (!options) {\r\n options = {};\r\n }\r\n let scale = this.resolution;\r\n let canvasWidth = Math.floor(this._calculatedWidth * this.resolution);\r\n let canvasHeight = Math.floor(this._calculatedHeight * this.resolution);\r\n // Check if we need to scale\r\n if (options.minWidth && (options.minWidth > canvasWidth)) {\r\n let minScale = options.minWidth / canvasWidth;\r\n if (minScale > scale) {\r\n scale = minScale * this.resolution;\r\n }\r\n }\r\n if (options.minHeight && (options.minHeight > canvasHeight)) {\r\n let minScale = options.minHeight / canvasHeight;\r\n if (minScale > scale) {\r\n scale = minScale * this.resolution;\r\n }\r\n }\r\n if (options.maxWidth && (options.maxWidth < canvasWidth)) {\r\n let maxScale = options.maxWidth / canvasWidth;\r\n if (maxScale < scale) {\r\n scale = maxScale * this.resolution;\r\n }\r\n }\r\n if (options.maxHeight && (options.maxHeight > canvasHeight)) {\r\n let maxScale = options.maxHeight / canvasHeight;\r\n if (maxScale < scale) {\r\n scale = maxScale * this.resolution;\r\n }\r\n }\r\n // Check if we need to compensate for pixel ratio\r\n if (options.maintainPixelRatio) {\r\n scale /= this.resolution;\r\n }\r\n // Init list canvases to remove from DOM after export\r\n const canvases = [];\r\n // Set up new canvas for export\r\n let forceRender = false;\r\n const canvas = document.createElement(\"canvas\");\r\n if (scale != this.resolution) {\r\n forceRender = true;\r\n canvasWidth = canvasWidth * scale / this.resolution;\r\n canvasHeight = canvasHeight * scale / this.resolution;\r\n }\r\n canvas.width = canvasWidth;\r\n canvas.height = canvasHeight;\r\n // Add to DOM so it inherits CSS\r\n canvas.style.position = \"fixed\";\r\n canvas.style.top = \"-10000px\";\r\n this.view.appendChild(canvas);\r\n canvases.push(canvas);\r\n // Context\r\n const context = canvas.getContext(\"2d\");\r\n let width = 0;\r\n let height = 0;\r\n let needRerender = false;\r\n $array.each(this.layers, (layer) => {\r\n if (layer && layer.visible) {\r\n if (layer.tainted || forceRender) {\r\n needRerender = true;\r\n layer.exportableView = layer.view;\r\n layer.exportableContext = layer.context;\r\n layer.view = document.createElement(\"canvas\");\r\n // Add to DOM so it inherits CSS\r\n layer.view.style.position = \"fixed\";\r\n layer.view.style.top = \"-10000px\";\r\n this.view.appendChild(layer.view);\r\n canvases.push(layer.view);\r\n let extraX = 0;\r\n let extraY = 0;\r\n if (layer.margin) {\r\n extraX += layer.margin.left || 0 + layer.margin.right || 0;\r\n extraY += layer.margin.top || 0 + layer.margin.bottom || 0;\r\n }\r\n layer.view.width = canvasWidth + extraX;\r\n layer.view.height = canvasHeight + extraY;\r\n layer.context = layer.view.getContext(\"2d\");\r\n layer.dirty = true;\r\n layer.scale = scale;\r\n }\r\n }\r\n });\r\n if (needRerender) {\r\n this._omitTainted = true;\r\n this.render(root);\r\n this._omitTainted = false;\r\n }\r\n $array.each(this.layers, (layer) => {\r\n if (layer && layer.visible) {\r\n // Layer is fine. Just plop it into our target canvas\r\n let x = 0;\r\n let y = 0;\r\n if (layer.margin) {\r\n x = -(layer.margin.left || 0) * this.resolution;\r\n y = -(layer.margin.top || 0) * this.resolution;\r\n }\r\n context.drawImage(layer.view, x, y);\r\n // Restore layer original canvas\r\n if (layer.exportableView) {\r\n layer.view = layer.exportableView;\r\n layer.exportableView = undefined;\r\n }\r\n if (layer.exportableContext) {\r\n layer.context = layer.exportableContext;\r\n layer.exportableContext = undefined;\r\n }\r\n if (width < layer.view.clientWidth) {\r\n width = layer.view.clientWidth;\r\n }\r\n if (height < layer.view.clientHeight) {\r\n height = layer.view.clientHeight;\r\n }\r\n layer.scale = undefined;\r\n }\r\n });\r\n canvas.style.width = width + \"px\";\r\n canvas.style.height = height + \"px\";\r\n $array.each(canvases, (canvas) => {\r\n canvas.style.position = \"\";\r\n canvas.style.top = \"\";\r\n this.view.removeChild(canvas);\r\n });\r\n return canvas;\r\n }\r\n}\r\nclass GhostLayer {\r\n constructor() {\r\n Object.defineProperty(this, \"view\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"context\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"margin\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {\r\n left: 0,\r\n right: 0,\r\n top: 0,\r\n bottom: 0,\r\n }\r\n });\r\n Object.defineProperty(this, \"_resolution\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 1\r\n });\r\n Object.defineProperty(this, \"_width\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_height\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"imageArray\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this.view = document.createElement(\"canvas\");\r\n this.context = this.view.getContext(\"2d\", { alpha: false, willReadFrequently: true });\r\n this.context.imageSmoothingEnabled = false;\r\n this.view.style.position = \"absolute\";\r\n this.view.style.top = \"0px\";\r\n this.view.style.left = \"0px\";\r\n }\r\n resize(canvasWidth, canvasHeight, domWidth, domHeight, resolution) {\r\n this._resolution = resolution;\r\n canvasWidth += (this.margin.left + this.margin.right);\r\n canvasHeight += (this.margin.top + this.margin.bottom);\r\n // TODO this should take into account calculateSize\r\n domWidth += (this.margin.left + this.margin.right);\r\n domHeight += (this.margin.top + this.margin.bottom);\r\n this.view.style.left = -this.margin.left + \"px\";\r\n this.view.style.top = -this.margin.top + \"px\";\r\n this._width = Math.floor(canvasWidth * resolution);\r\n this._height = Math.floor(canvasHeight * resolution);\r\n this.view.width = this._width;\r\n this.view.style.width = domWidth + \"px\";\r\n this.view.height = this._height;\r\n this.view.style.height = domHeight + \"px\";\r\n }\r\n getImageData(point, bbox) {\r\n return this.context.getImageData(\r\n // TODO should this round ?\r\n Math.round(((point.x - bbox.left) / bbox.width) * this._width), Math.round(((point.y - bbox.top) / bbox.height) * this._height), 1, 1);\r\n }\r\n getImageArray(point) {\r\n if (!this.imageArray) {\r\n this.imageArray = this.context.getImageData(0, 0, this._width, this._height).data;\r\n }\r\n const data = this.imageArray;\r\n const x = Math.round(point.x * this._resolution);\r\n const y = Math.round(point.y * this._resolution);\r\n const i = (y * this._width + x) * 4;\r\n return [data[i], data[i + 1], data[i + 2], data[i + 3]];\r\n }\r\n setMargin(layers) {\r\n this.margin.left = 0;\r\n this.margin.right = 0;\r\n this.margin.top = 0;\r\n this.margin.bottom = 0;\r\n $array.each(layers, (layer) => {\r\n if (layer.margin) {\r\n this.margin.left = Math.max(this.margin.left, layer.margin.left);\r\n this.margin.right = Math.max(this.margin.right, layer.margin.right);\r\n this.margin.top = Math.max(this.margin.top, layer.margin.top);\r\n this.margin.bottom = Math.max(this.margin.bottom, layer.margin.bottom);\r\n }\r\n });\r\n }\r\n clear() {\r\n this.context.save();\r\n this.context.fillStyle = '#000';\r\n this.context.fillRect(0, 0, this._width, this._height);\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport class CanvasLayer {\r\n constructor(view, context) {\r\n Object.defineProperty(this, \"view\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"context\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"tainted\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"margin\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"order\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"visible\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"width\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"height\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"scale\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"dirty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"exportableView\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"exportableContext\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_width\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n Object.defineProperty(this, \"_height\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n this.view = view;\r\n this.context = context;\r\n }\r\n resize(canvasWidth, canvasHeight, domWidth, domHeight, resolution) {\r\n // TODO should this take into account calculateSize ?\r\n if (this.width != null) {\r\n canvasWidth = this.width;\r\n domWidth = this.width;\r\n }\r\n // TODO should this take into account calculateSize ?\r\n if (this.height != null) {\r\n canvasHeight = this.height;\r\n domHeight = this.height;\r\n }\r\n if (this.margin) {\r\n canvasWidth += (this.margin.left + this.margin.right);\r\n canvasHeight += (this.margin.top + this.margin.bottom);\r\n // TODO this should take into account calculateSize\r\n domWidth += (this.margin.left + this.margin.right);\r\n domHeight += (this.margin.top + this.margin.bottom);\r\n this.view.style.left = -this.margin.left + \"px\";\r\n this.view.style.top = -this.margin.top + \"px\";\r\n }\r\n else {\r\n this.view.style.left = \"0px\";\r\n this.view.style.top = \"0px\";\r\n }\r\n this._width = Math.floor(canvasWidth * resolution);\r\n this._height = Math.floor(canvasHeight * resolution);\r\n this.view.width = this._width;\r\n this.view.style.width = domWidth + \"px\";\r\n this.view.height = this._height;\r\n this.view.style.height = domHeight + \"px\";\r\n }\r\n clear() {\r\n this.context.save();\r\n this.context.clearRect(0, 0, this._width, this._height);\r\n }\r\n}\r\n//# sourceMappingURL=CanvasRenderer.js.map","import { AnimationState } from \"./util/Animation\";\r\nimport { Container } from \"./render/Container\";\r\nimport { Text } from \"./render/Text\";\r\nimport { HorizontalLayout } from \"./render/HorizontalLayout\";\r\nimport { VerticalLayout } from \"./render/VerticalLayout\";\r\nimport { GridLayout } from \"./render/GridLayout\";\r\nimport { Disposer } from \"./util/Disposer\";\r\nimport { ResizeSensor } from \"./util/ResizeSensor\";\r\nimport { InterfaceColors } from \"./util/InterfaceColors\";\r\nimport { Graphics } from \"./render/Graphics\";\r\nimport { Rectangle } from \"./render/Rectangle\";\r\nimport { Tooltip } from \"./render/Tooltip\";\r\nimport { NumberFormatter } from \"./util/NumberFormatter\";\r\nimport { DateFormatter } from \"./util/DateFormatter\";\r\nimport { DurationFormatter } from \"./util/DurationFormatter\";\r\nimport { Language } from \"./util/Language\";\r\nimport { EventDispatcher } from \"./util/EventDispatcher\";\r\nimport { DefaultTheme } from \"../themes/DefaultTheme\";\r\nimport { CanvasRenderer } from \"./render/backend/CanvasRenderer\";\r\nimport { p100, percent, isPercent, Percent } from \"./util/Percent\";\r\nimport { color } from \"./util/Color\";\r\nimport { populateString } from \"./util/PopulateString\";\r\nimport { registry } from \"./Registry\";\r\nimport * as $order from \"./util/Order\";\r\nimport * as $array from \"./util/Array\";\r\nimport * as $object from \"./util/Object\";\r\nimport * as $utils from \"./util/Utils\";\r\nimport * as $type from \"./util/Type\";\r\nimport en from \"../../locales/en\";\r\nfunction rAF(fps, callback) {\r\n if (fps == null) {\r\n requestAnimationFrame(callback);\r\n }\r\n else {\r\n setTimeout(() => {\r\n requestAnimationFrame(callback);\r\n }, 1000 / fps);\r\n }\r\n}\r\n// TODO implement Disposer\r\n/**\r\n * Root element of the chart.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/#Root_element} for more info\r\n */\r\nexport class Root {\r\n constructor(id, settings = {}, isReal) {\r\n /**\r\n * A reference to original chart container (div element).\r\n */\r\n Object.defineProperty(this, \"dom\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_inner\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_settings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_isDirty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_isDirtyParents\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_isDirtyAnimation\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_dirty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_dirtyParents\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_dirtyBounds\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_dirtyPositions\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: {}\r\n });\r\n Object.defineProperty(this, \"_ticker\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: null\r\n });\r\n Object.defineProperty(this, \"_tickers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_updateTick\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n /**\r\n * Root's event dispatcher.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/events/} for more info\r\n */\r\n Object.defineProperty(this, \"events\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new EventDispatcher()\r\n });\r\n /**\r\n * @ignore\r\n * @todo needs description\r\n */\r\n Object.defineProperty(this, \"animationTime\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: null\r\n });\r\n Object.defineProperty(this, \"_animations\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_renderer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_rootContainer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * Main content container.\r\n */\r\n Object.defineProperty(this, \"container\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * A [[Container]] used to display tooltips in.\r\n */\r\n Object.defineProperty(this, \"tooltipContainer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltipContainerSettings\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltip\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n // Locale-related\r\n /**\r\n * @ignore\r\n */\r\n Object.defineProperty(this, \"language\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Language.new(this, {})\r\n });\r\n /**\r\n * Locale used by the chart.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/locales/}\r\n */\r\n Object.defineProperty(this, \"locale\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: en\r\n });\r\n // Date-time related\r\n /**\r\n * Use UTC when formatting date/time.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/formatters/formatting-dates/#utc-and-time-zones} for more info\r\n */\r\n Object.defineProperty(this, \"utc\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n /**\r\n * If set, will format date/time in specific time zone.\r\n *\r\n * The value should be named time zone, e.g.:\r\n * `\"America/Vancouver\"`, `\"Australia/Sydney\"`, `\"UTC\"`.\r\n *\r\n * NOTE: Using time zone feature may noticeable affect performance of the\r\n * chart, especially with large data sets, since every single date will need\r\n * to be recalculated.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/root-element/#time-zone} for more info\r\n * @since 5.1.0\r\n */\r\n Object.defineProperty(this, \"timezone\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * The maximum FPS that the Root will run at.\r\n *\r\n * If `undefined` it will run at the highest FPS.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/root-element/#Performance} for more info\r\n */\r\n Object.defineProperty(this, \"fps\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * Number formatter.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/formatters/formatting-numbers/} for more info\r\n */\r\n Object.defineProperty(this, \"numberFormatter\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: NumberFormatter.new(this, {})\r\n });\r\n /**\r\n * Date/time formatter.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/formatters/formatting-dates/} for more info\r\n */\r\n Object.defineProperty(this, \"dateFormatter\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: DateFormatter.new(this, {})\r\n });\r\n /**\r\n * Duration formatter.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/formatters/formatting-dates/} for more info\r\n */\r\n Object.defineProperty(this, \"durationFormatter\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: DurationFormatter.new(this, {})\r\n });\r\n // Accessibility\r\n /**\r\n * Global tab index for using for the whole chart\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/accessibility/} for more info\r\n */\r\n Object.defineProperty(this, \"tabindex\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: 0\r\n });\r\n //@todo maybe make this better\r\n Object.defineProperty(this, \"_tabindexes\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_a11yD\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_focusElementDirty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_focusElementContainer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_focusedSprite\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_isShift\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_keyboardDragPoint\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltipElementContainer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_readerAlertElement\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_logo\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltipDiv\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * Used for dynamically-created CSS and JavaScript with strict source policies.\r\n */\r\n Object.defineProperty(this, \"nonce\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * Special color set to be used for various controls.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/#Interface_colors} for more info\r\n */\r\n Object.defineProperty(this, \"interfaceColors\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * An instance of vertical layout object that can be used to set `layout` setting\r\n * of a [[Container]].\r\n *\r\n * @default VerticalLayout.new()\r\n */\r\n Object.defineProperty(this, \"verticalLayout\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: VerticalLayout.new(this, {})\r\n });\r\n /**\r\n * An instance of horizontal layout object that can be used to set `layout` setting\r\n * of a [[Container]].\r\n *\r\n * @default HorizontalLayout.new()\r\n */\r\n Object.defineProperty(this, \"horizontalLayout\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: HorizontalLayout.new(this, {})\r\n });\r\n /**\r\n * An instance of grid layout object that can be used to set `layout` setting\r\n * of a [[Container]].\r\n *\r\n * @default VerticalLayout.new()\r\n */\r\n Object.defineProperty(this, \"gridLayout\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: GridLayout.new(this, {})\r\n });\r\n Object.defineProperty(this, \"_paused\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n /**\r\n * Indicates whether chart should resized automatically when parent container\r\n * width and/or height changes.\r\n *\r\n * If disabled (`autoResize = false`) you can make the chart resize manually\r\n * by calling root element's `resize()` method.\r\n */\r\n Object.defineProperty(this, \"autoResize\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: true\r\n });\r\n Object.defineProperty(this, \"_fontHash\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"\"\r\n });\r\n Object.defineProperty(this, \"_isDisposed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_disposers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_resizeSensorDisposer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_tooltips\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_htmlElementContainer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_htmlEnabledContainers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n if (!isReal) {\r\n throw new Error(\"You cannot use `new Class()`, instead use `Class.new()`\");\r\n }\r\n this._settings = settings;\r\n if (settings.accessible == false) {\r\n this._a11yD = true;\r\n }\r\n if (settings.useSafeResolution == null) {\r\n settings.useSafeResolution = true;\r\n }\r\n let resolution;\r\n if (settings.useSafeResolution) {\r\n resolution = $utils.getSafeResolution();\r\n }\r\n this._renderer = new CanvasRenderer(resolution);\r\n let dom;\r\n if (id instanceof HTMLElement) {\r\n dom = id;\r\n }\r\n else {\r\n dom = document.getElementById(id);\r\n }\r\n $array.each(registry.rootElements, (root) => {\r\n if (root.dom === dom) {\r\n throw new Error(\"You cannot have multiple Roots on the same DOM node\");\r\n }\r\n });\r\n this.interfaceColors = InterfaceColors.new(this, {});\r\n if (dom === null) {\r\n throw new Error(\"Could not find HTML element with id `\" + id + \"`\");\r\n }\r\n this.dom = dom;\r\n let inner = document.createElement(\"div\");\r\n inner.style.position = \"relative\";\r\n inner.style.width = \"100%\";\r\n inner.style.height = \"100%\";\r\n dom.appendChild(inner);\r\n const tooltipContainerBounds = settings.tooltipContainerBounds;\r\n if (tooltipContainerBounds) {\r\n this._tooltipContainerSettings = tooltipContainerBounds;\r\n }\r\n this._inner = inner;\r\n this._updateComputedStyles();\r\n registry.rootElements.push(this);\r\n }\r\n static new(id, settings) {\r\n const root = new Root(id, settings, true);\r\n root._init();\r\n return root;\r\n }\r\n moveDOM(id) {\r\n let dom;\r\n if (id instanceof HTMLElement) {\r\n dom = id;\r\n }\r\n else {\r\n dom = document.getElementById(id);\r\n }\r\n if (dom) {\r\n while (this.dom.childNodes.length > 0) {\r\n dom.appendChild(this.dom.childNodes[0]);\r\n }\r\n this.dom = dom;\r\n this._initResizeSensor();\r\n this.resize();\r\n }\r\n }\r\n _handleLogo() {\r\n if (this._logo) {\r\n const w = this.dom.offsetWidth;\r\n const h = this.dom.offsetHeight;\r\n if ((w <= 150) || (h <= 60)) {\r\n this._logo.hide();\r\n }\r\n else {\r\n this._logo.show();\r\n }\r\n }\r\n }\r\n _showBranding() {\r\n if (!this._logo) {\r\n const logo = this.tooltipContainer.children.push(Container.new(this, {\r\n interactive: true,\r\n interactiveChildren: false,\r\n position: \"absolute\",\r\n setStateOnChildren: true,\r\n paddingTop: 9,\r\n paddingRight: 9,\r\n paddingBottom: 9,\r\n paddingLeft: 9,\r\n scale: .6,\r\n y: percent(100),\r\n centerY: p100,\r\n tooltipText: \"Created using amCharts 5\",\r\n tooltipX: p100,\r\n cursorOverStyle: \"pointer\",\r\n background: Rectangle.new(this, {\r\n fill: color(0x474758),\r\n fillOpacity: 0,\r\n tooltipY: 5\r\n })\r\n }));\r\n const tooltip = Tooltip.new(this, {\r\n pointerOrientation: \"horizontal\",\r\n paddingTop: 4,\r\n paddingRight: 7,\r\n paddingBottom: 4,\r\n paddingLeft: 7\r\n });\r\n tooltip.label.setAll({\r\n fontSize: 12\r\n });\r\n tooltip.get(\"background\").setAll({\r\n fill: this.interfaceColors.get(\"background\"),\r\n stroke: this.interfaceColors.get(\"grid\"),\r\n strokeOpacity: 0.3\r\n });\r\n logo.set(\"tooltip\", tooltip);\r\n logo.events.on(\"click\", () => {\r\n window.open(\"https://www.amcharts.com/\", \"_blank\");\r\n });\r\n logo.states.create(\"hover\", {});\r\n const m = logo.children.push(Graphics.new(this, {\r\n stroke: color(0xcccccc),\r\n strokeWidth: 3,\r\n svgPath: \"M5 25 L13 25h13.6c3.4 0 6 0 10.3-4.3s5.2-12 8.6-12c3.4 0 4.3 8.6 7.7 8.6M83.4 25H79.8c-3.4 0-6 0-10.3-4.3s-5.2-12-8.6-12-4.3 8.6-7.7 8.6\"\r\n }));\r\n m.states.create(\"hover\", { stroke: color(0x3CABFF) });\r\n const a = logo.children.push(Graphics.new(this, {\r\n stroke: color(0x888888),\r\n strokeWidth: 3,\r\n svgPath: \"M83.4 25h-31C37 25 39.5 4.4 28.4 4.4S18.9 24.2 4.3 25H0\"\r\n }));\r\n a.states.create(\"hover\", { stroke: color(0x474758) });\r\n //logo.set(\"tooltip\", this._tooltip);\r\n //logo.setPrivate(\"tooltipTarget\", logo.get(\"background\"));\r\n this._logo = logo;\r\n this._handleLogo();\r\n }\r\n }\r\n _getRealSize() {\r\n return this.dom.getBoundingClientRect();\r\n }\r\n _getCalculatedSize(rect) {\r\n if (this._settings.calculateSize) {\r\n return this._settings.calculateSize(rect);\r\n }\r\n else {\r\n return {\r\n width: rect.width,\r\n height: rect.height,\r\n };\r\n }\r\n }\r\n _init() {\r\n const settings = this._settings;\r\n if (settings.accessible !== false) {\r\n if (settings.focusable) {\r\n this._inner.setAttribute(\"focusable\", \"true\");\r\n this._inner.setAttribute(\"tabindex\", this.tabindex + \"\");\r\n }\r\n if (settings.ariaLabel) {\r\n this._inner.setAttribute(\"aria-label\", settings.ariaLabel);\r\n }\r\n if (settings.role) {\r\n this._inner.setAttribute(\"role\", settings.role);\r\n }\r\n }\r\n const renderer = this._renderer;\r\n const rect = this._getRealSize();\r\n const size = this._getCalculatedSize(rect);\r\n const width = Math.floor(size.width);\r\n const height = Math.floor(size.height);\r\n const realWidth = Math.floor(rect.width);\r\n const realHeight = Math.floor(rect.height);\r\n const rootContainer = Container.new(this, {\r\n visible: true,\r\n width: width,\r\n height: height,\r\n });\r\n this._rootContainer = rootContainer;\r\n this._rootContainer._defaultThemes.push(DefaultTheme.new(this));\r\n const container = rootContainer.children.push(Container.new(this, { visible: true, width: p100, height: p100 }));\r\n this.container = container;\r\n renderer.resize(realWidth, realHeight, width, height);\r\n //@todo: better appendChild - refer\r\n this._inner.appendChild(renderer.view);\r\n // TODO: TMP TMP TMP for testing only, remove\r\n //renderer.debugGhostView = true;\r\n this._initResizeSensor();\r\n // HTML content holder\r\n const htmlElementContainer = document.createElement(\"div\");\r\n this._htmlElementContainer = htmlElementContainer;\r\n htmlElementContainer.className = \"am5-html-container\";\r\n htmlElementContainer.style.position = \"absolute\";\r\n htmlElementContainer.style.pointerEvents = \"none\";\r\n if (!this._tooltipContainerSettings) {\r\n htmlElementContainer.style.overflow = \"hidden\";\r\n }\r\n this._inner.appendChild(htmlElementContainer);\r\n if (this._a11yD !== true) {\r\n // Create element which is used to make announcements to screen reader\r\n const readerAlertElement = document.createElement(\"div\");\r\n readerAlertElement.className = \"am5-reader-container\";\r\n readerAlertElement.setAttribute(\"role\", \"alert\");\r\n // readerAlertElement.style.zIndex = \"-100000\";\r\n // readerAlertElement.style.opacity = \"0\";\r\n // readerAlertElement.style.top = \"0\";\r\n readerAlertElement.style.position = \"absolute\";\r\n readerAlertElement.style.width = \"1px\";\r\n readerAlertElement.style.height = \"1px\";\r\n readerAlertElement.style.overflow = \"hidden\";\r\n readerAlertElement.style.clip = \"rect(1px, 1px, 1px, 1px)\";\r\n this._readerAlertElement = readerAlertElement;\r\n this._inner.appendChild(this._readerAlertElement);\r\n const focusElementContainer = document.createElement(\"div\");\r\n focusElementContainer.className = \"am5-focus-container\";\r\n focusElementContainer.style.position = \"absolute\";\r\n focusElementContainer.style.pointerEvents = \"none\";\r\n focusElementContainer.style.top = \"0px\";\r\n focusElementContainer.style.left = \"0px\";\r\n focusElementContainer.style.overflow = \"hidden\";\r\n focusElementContainer.style.width = width + \"px\";\r\n focusElementContainer.style.height = height + \"px\";\r\n focusElementContainer.setAttribute(\"role\", \"graphics-document\");\r\n $utils.setInteractive(focusElementContainer, false);\r\n this._focusElementContainer = focusElementContainer;\r\n this._inner.appendChild(this._focusElementContainer);\r\n const tooltipElementContainer = document.createElement(\"div\");\r\n this._tooltipElementContainer = tooltipElementContainer;\r\n tooltipElementContainer.className = \"am5-tooltip-container\";\r\n this._inner.appendChild(tooltipElementContainer);\r\n // Add keyboard events for accessibility, e.g. simulating drag with arrow\r\n // keys and click with ENTER\r\n if ($utils.supports(\"keyboardevents\")) {\r\n this._disposers.push($utils.addEventListener(window, \"keydown\", (ev) => {\r\n const eventKey = $utils.getEventKey(ev);\r\n if (eventKey == \"Shift\") {\r\n this._isShift = true;\r\n }\r\n else if (eventKey == \"Tab\") {\r\n this._isShift = ev.shiftKey;\r\n }\r\n }));\r\n this._disposers.push($utils.addEventListener(window, \"keyup\", (ev) => {\r\n const eventKey = $utils.getEventKey(ev);\r\n if (eventKey == \"Shift\") {\r\n this._isShift = false;\r\n }\r\n }));\r\n this._disposers.push($utils.addEventListener(focusElementContainer, \"click\", () => {\r\n // Some screen readers convert ENTER (and some SPACE) press whil on\r\n // focused element to a \"click\" event, preventing actual \"keydown\"\r\n // event from firing. We're using this \"click\" event to still\r\n // generate internal click events.\r\n const focusedSprite = this._focusedSprite;\r\n if (focusedSprite) {\r\n const downEvent = renderer.getEvent(new MouseEvent(\"click\"));\r\n focusedSprite.events.dispatch(\"click\", {\r\n type: \"click\",\r\n originalEvent: downEvent.event,\r\n point: downEvent.point,\r\n simulated: true,\r\n target: focusedSprite\r\n });\r\n }\r\n }));\r\n this._disposers.push($utils.addEventListener(focusElementContainer, \"keydown\", (ev) => {\r\n const focusedSprite = this._focusedSprite;\r\n if (focusedSprite) {\r\n if (ev.key == \"Escape\") {\r\n // ESC pressed - lose current focus\r\n $utils.blur();\r\n this._focusedSprite = undefined;\r\n }\r\n let dragOffsetX = 0;\r\n let dragOffsetY = 0;\r\n // TODO: figure out if using bogus MouseEvent is fine, or it will\r\n // fail on some platforms\r\n const eventKey = $utils.getEventKey(ev);\r\n switch (eventKey) {\r\n case \"Enter\":\r\n case \" \":\r\n if (eventKey == \" \" && focusedSprite.get(\"role\") != \"checkbox\") {\r\n return;\r\n }\r\n ev.preventDefault();\r\n const downEvent = renderer.getEvent(new MouseEvent(\"mouse\"));\r\n focusedSprite.events.dispatch(\"click\", {\r\n type: \"click\",\r\n originalEvent: downEvent.event,\r\n point: downEvent.point,\r\n simulated: true,\r\n target: focusedSprite\r\n });\r\n return;\r\n case \"ArrowLeft\":\r\n dragOffsetX = -6;\r\n break;\r\n case \"ArrowRight\":\r\n dragOffsetX = 6;\r\n break;\r\n case \"ArrowUp\":\r\n dragOffsetY = -6;\r\n break;\r\n case \"ArrowDown\":\r\n dragOffsetY = 6;\r\n break;\r\n default:\r\n return;\r\n }\r\n if (dragOffsetX != 0 || dragOffsetY != 0) {\r\n ev.preventDefault();\r\n if (!focusedSprite.isDragging()) {\r\n // Start dragging\r\n this._keyboardDragPoint = {\r\n x: 0,\r\n y: 0\r\n };\r\n const downEvent = renderer.getEvent(new MouseEvent(\"mousedown\", {\r\n clientX: 0,\r\n clientY: 0\r\n }));\r\n downEvent.point = {\r\n x: 0,\r\n y: 0\r\n };\r\n if (focusedSprite.events.isEnabled(\"pointerdown\")) {\r\n focusedSprite.events.dispatch(\"pointerdown\", {\r\n type: \"pointerdown\",\r\n originalEvent: downEvent.event,\r\n point: downEvent.point,\r\n simulated: true,\r\n target: focusedSprite\r\n });\r\n }\r\n }\r\n else {\r\n // Move focus marker\r\n //this._positionFocusElement(focusedSprite);\r\n }\r\n // Move incrementally\r\n const dragPoint = this._keyboardDragPoint;\r\n dragPoint.x += dragOffsetX;\r\n dragPoint.y += dragOffsetY;\r\n const moveEvent = renderer.getEvent(new MouseEvent(\"mousemove\", {\r\n clientX: dragPoint.x,\r\n clientY: dragPoint.y\r\n }), false);\r\n if (focusedSprite.events.isEnabled(\"globalpointermove\")) {\r\n focusedSprite.events.dispatch(\"globalpointermove\", {\r\n type: \"globalpointermove\",\r\n originalEvent: moveEvent.event,\r\n point: moveEvent.point,\r\n simulated: true,\r\n target: focusedSprite\r\n });\r\n }\r\n }\r\n }\r\n }));\r\n this._disposers.push($utils.addEventListener(focusElementContainer, \"keyup\", (ev) => {\r\n if (this._focusedSprite) {\r\n const focusedSprite = this._focusedSprite;\r\n const eventKey = $utils.getEventKey(ev);\r\n switch (eventKey) {\r\n case \"ArrowLeft\":\r\n case \"ArrowRight\":\r\n case \"ArrowTop\":\r\n case \"ArrowDown\":\r\n if (focusedSprite.isDragging()) {\r\n // Simulate drag stop\r\n const dragPoint = this._keyboardDragPoint;\r\n const upEvent = renderer.getEvent(new MouseEvent(\"mouseup\", {\r\n clientX: dragPoint.x,\r\n clientY: dragPoint.y\r\n }));\r\n if (focusedSprite.events.isEnabled(\"globalpointerup\")) {\r\n focusedSprite.events.dispatch(\"globalpointerup\", {\r\n type: \"globalpointerup\",\r\n originalEvent: upEvent.event,\r\n point: upEvent.point,\r\n simulated: true,\r\n target: focusedSprite\r\n });\r\n }\r\n //this._positionFocusElement(focusedSprite);\r\n this._keyboardDragPoint = undefined;\r\n // @todo dispatch mouseup event instead of calling dragStop?\r\n // this._dispatchEvent(\"globalpointerup\", target, upEvent);\r\n return;\r\n }\r\n else if (focusedSprite.get(\"focusableGroup\")) {\r\n // Find next item in focusable group\r\n const group = focusedSprite.get(\"focusableGroup\");\r\n const items = this._tabindexes.filter((item) => {\r\n return item.get(\"focusableGroup\") == group && item.getPrivate(\"focusable\") !== false && item.isVisibleDeep() ? true : false;\r\n });\r\n let index = items.indexOf(focusedSprite);\r\n const lastIndex = items.length - 1;\r\n index += (eventKey == \"ArrowRight\" || eventKey == \"ArrowDown\") ? 1 : -1;\r\n if (index < 0) {\r\n index = lastIndex;\r\n }\r\n else if (index > lastIndex) {\r\n index = 0;\r\n }\r\n $utils.focus(items[index].getPrivate(\"focusElement\").dom);\r\n }\r\n break;\r\n }\r\n }\r\n }));\r\n }\r\n }\r\n this._startTicker();\r\n this.setThemes([]);\r\n this._addTooltip();\r\n if (!this._hasLicense()) {\r\n this._showBranding();\r\n }\r\n }\r\n _initResizeSensor() {\r\n if (this._resizeSensorDisposer) {\r\n this._resizeSensorDisposer.dispose();\r\n }\r\n this._resizeSensorDisposer = new ResizeSensor(this.dom, () => {\r\n if (this.autoResize) {\r\n this.resize();\r\n }\r\n });\r\n this._disposers.push(this._resizeSensorDisposer);\r\n }\r\n /**\r\n * If automatic resizing of char is disabled (`root.autoResize = false`), it\r\n * can be resized manually by calling this method.\r\n */\r\n resize() {\r\n const rect = this._getRealSize();\r\n const size = this._getCalculatedSize(rect);\r\n const w = Math.floor(size.width);\r\n const h = Math.floor(size.height);\r\n if (w > 0 && h > 0) {\r\n const realWidth = Math.floor(rect.width);\r\n const realHeight = Math.floor(rect.height);\r\n const htmlElementContainer = this._htmlElementContainer;\r\n htmlElementContainer.style.width = w + \"px\";\r\n htmlElementContainer.style.height = h + \"px\";\r\n if (this._a11yD !== true) {\r\n const focusElementContainer = this._focusElementContainer;\r\n focusElementContainer.style.width = w + \"px\";\r\n focusElementContainer.style.height = h + \"px\";\r\n }\r\n this._renderer.resize(realWidth, realHeight, w, h);\r\n const rootContainer = this._rootContainer;\r\n rootContainer.setPrivate(\"width\", w);\r\n rootContainer.setPrivate(\"height\", h);\r\n this._render();\r\n this._handleLogo();\r\n }\r\n }\r\n _render() {\r\n this._renderer.render(this._rootContainer._display);\r\n if (this._focusElementDirty) {\r\n this._updateCurrentFocus();\r\n this._focusElementDirty = false;\r\n }\r\n }\r\n _runTickers(currentTime) {\r\n $array.each(this._tickers, (f) => {\r\n f(currentTime);\r\n });\r\n }\r\n _runAnimations(currentTime) {\r\n let running = 0;\r\n $array.keepIf(this._animations, (animation) => {\r\n const state = animation._runAnimation(currentTime);\r\n if (state === AnimationState.Stopped) {\r\n return false;\r\n }\r\n else if (state === AnimationState.Playing) {\r\n ++running;\r\n return true;\r\n }\r\n else {\r\n return true;\r\n }\r\n });\r\n this._isDirtyAnimation = false;\r\n return running === 0;\r\n }\r\n _runDirties() {\r\n //console.log(\"tick **************************************************************\");\r\n let allParents = {};\r\n while (this._isDirtyParents) {\r\n // This must be before calling _prepareChildren\r\n this._isDirtyParents = false;\r\n $object.keys(this._dirtyParents).forEach((key) => {\r\n const parent = this._dirtyParents[key];\r\n delete this._dirtyParents[key];\r\n if (!parent.isDisposed()) {\r\n allParents[parent.uid] = parent;\r\n parent._prepareChildren();\r\n }\r\n });\r\n }\r\n $object.keys(allParents).forEach((key) => {\r\n allParents[key]._updateChildren();\r\n });\r\n const objects = [];\r\n //\t\tconsole.log(\"_beforeChanged\")\r\n $object.keys(this._dirty).forEach((key) => {\r\n const entity = this._dirty[key];\r\n if (entity.isDisposed()) {\r\n delete this._dirty[entity.uid];\r\n }\r\n else {\r\n objects.push(entity);\r\n entity._beforeChanged();\r\n }\r\n });\r\n //\t\tconsole.log(\"_changed\")\r\n objects.forEach((entity) => {\r\n entity._changed();\r\n delete this._dirty[entity.uid];\r\n entity._clearDirty();\r\n });\r\n this._isDirty = false;\r\n const depths = {};\r\n const bounds = [];\r\n $object.keys(this._dirtyBounds).forEach((key) => {\r\n const entity = this._dirtyBounds[key];\r\n delete this._dirtyBounds[key];\r\n if (!entity.isDisposed()) {\r\n depths[entity.uid] = entity.depth();\r\n bounds.push(entity);\r\n }\r\n });\r\n this._positionHTMLElements();\r\n // High depth -> low depth\r\n bounds.sort((x, y) => {\r\n return $order.compare(depths[y.uid], depths[x.uid]);\r\n });\r\n //\t\tconsole.log(\"_updateBounds\")\r\n bounds.forEach((entity) => {\r\n entity._updateBounds();\r\n });\r\n //\t\tconsole.log(\"_updatePosition\")\r\n const dirtyPositions = this._dirtyPositions;\r\n $object.keys(dirtyPositions).forEach((key) => {\r\n const sprite = dirtyPositions[key];\r\n delete dirtyPositions[key];\r\n if (!sprite.isDisposed()) {\r\n sprite._updatePosition();\r\n }\r\n });\r\n //\t\tconsole.log(\"_afterChanged\")\r\n objects.forEach((entity) => {\r\n entity._afterChanged();\r\n });\r\n }\r\n _renderFrame(currentTime) {\r\n if (this._updateTick) {\r\n if (this.events.isEnabled(\"framestarted\")) {\r\n this.events.dispatch(\"framestarted\", {\r\n type: \"framestarted\",\r\n target: this,\r\n timestamp: currentTime,\r\n });\r\n }\r\n this._checkComputedStyles();\r\n this._runTickers(currentTime);\r\n const animationDone = this._runAnimations(currentTime);\r\n this._runDirties();\r\n this._render();\r\n this._renderer.resetImageArray();\r\n this._positionHTMLElements();\r\n if (this.events.isEnabled(\"frameended\")) {\r\n this.events.dispatch(\"frameended\", {\r\n type: \"frameended\",\r\n target: this,\r\n timestamp: currentTime,\r\n });\r\n }\r\n return this._tickers.length === 0 &&\r\n animationDone &&\r\n !this._isDirtyAnimation &&\r\n !this._isDirty;\r\n }\r\n else {\r\n return true;\r\n }\r\n }\r\n _runTicker(currentTime, now) {\r\n if (!this.isDisposed()) {\r\n this.animationTime = currentTime;\r\n const done = this._renderFrame(currentTime);\r\n // No more work to do\r\n if (done) {\r\n this._ticker = null;\r\n this.animationTime = null;\r\n }\r\n else {\r\n if (!this._paused) {\r\n if (now) {\r\n this._ticker;\r\n }\r\n else {\r\n rAF(this.fps, this._ticker);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n _runTickerNow(timeout = 10000) {\r\n if (!this.isDisposed()) {\r\n const endTime = performance.now() + timeout;\r\n for (;;) {\r\n const currentTime = performance.now();\r\n if (currentTime >= endTime) {\r\n this.animationTime = null;\r\n break;\r\n }\r\n this.animationTime = currentTime;\r\n const done = this._renderFrame(currentTime);\r\n if (done) {\r\n this.animationTime = null;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n _startTicker() {\r\n if (this._ticker === null) {\r\n this.animationTime = null;\r\n this._ticker = (currentTime) => {\r\n this._runTicker(currentTime);\r\n };\r\n rAF(this.fps, this._ticker);\r\n }\r\n }\r\n /**\r\n * Returns whether the root is updating or not.\r\n */\r\n get updateTick() {\r\n return this._updateTick;\r\n }\r\n /**\r\n * Enables or disables the root updating.\r\n */\r\n set updateTick(value) {\r\n this._updateTick = value;\r\n if (value) {\r\n this._startTicker();\r\n }\r\n }\r\n _addDirtyEntity(entity) {\r\n this._isDirty = true;\r\n if (this._dirty[entity.uid] === undefined) {\r\n this._dirty[entity.uid] = entity;\r\n }\r\n this._startTicker();\r\n }\r\n _addDirtyParent(parent) {\r\n this._isDirty = true;\r\n this._isDirtyParents = true;\r\n if (this._dirtyParents[parent.uid] === undefined) {\r\n this._dirtyParents[parent.uid] = parent;\r\n }\r\n this._startTicker();\r\n }\r\n _addDirtyBounds(entity) {\r\n this._isDirty = true;\r\n if (this._dirtyBounds[entity.uid] === undefined) {\r\n this._dirtyBounds[entity.uid] = entity;\r\n }\r\n this._startTicker();\r\n }\r\n _addDirtyPosition(sprite) {\r\n this._isDirty = true;\r\n if (this._dirtyPositions[sprite.uid] === undefined) {\r\n this._dirtyPositions[sprite.uid] = sprite;\r\n }\r\n this._startTicker();\r\n }\r\n _addAnimation(animation) {\r\n this._isDirtyAnimation = true;\r\n // TODO use numeric id instead\r\n if (this._animations.indexOf(animation) === -1) {\r\n this._animations.push(animation);\r\n }\r\n this._startTicker();\r\n }\r\n _markDirty() {\r\n this._isDirty = true;\r\n }\r\n _markDirtyRedraw() {\r\n this.events.once(\"frameended\", () => {\r\n this._isDirty = true;\r\n this._startTicker();\r\n });\r\n }\r\n eachFrame(f) {\r\n this._tickers.push(f);\r\n this._startTicker();\r\n return new Disposer(() => {\r\n $array.removeFirst(this._tickers, f);\r\n });\r\n }\r\n markDirtyGlobal(container) {\r\n if (!container) {\r\n container = this.container;\r\n }\r\n container.walkChildren((child) => {\r\n if (child instanceof Container) {\r\n this.markDirtyGlobal(child);\r\n }\r\n child.markDirty();\r\n child.markDirtyBounds();\r\n });\r\n }\r\n /**\r\n * Returns width of the target container, in pixels.\r\n *\r\n * @return Width\r\n */\r\n width() {\r\n // TODO make this more efficient, maybe just return the renderer's width ?\r\n return Math.floor(this._getCalculatedSize(this._getRealSize()).width);\r\n }\r\n /**\r\n * Returns height of the target container, in pixels.\r\n *\r\n * @return Height\r\n */\r\n height() {\r\n // TODO make this more efficient, maybe just return the renderer's height ?\r\n return Math.floor(this._getCalculatedSize(this._getRealSize()).height);\r\n }\r\n /**\r\n * Disposes root and all the content in it.\r\n */\r\n dispose() {\r\n if (!this._isDisposed) {\r\n this._isDisposed = true;\r\n this._rootContainer.dispose();\r\n this._renderer.dispose();\r\n this.horizontalLayout.dispose();\r\n this.verticalLayout.dispose();\r\n this.interfaceColors.dispose();\r\n $array.each(this._disposers, (x) => {\r\n x.dispose();\r\n });\r\n if (this._inner) {\r\n $utils.removeElement(this._inner);\r\n }\r\n $array.remove(registry.rootElements, this);\r\n }\r\n }\r\n /**\r\n * Returns `true` if root element is disposed.\r\n *\r\n * @return Disposed?\r\n */\r\n isDisposed() {\r\n return this._isDisposed;\r\n }\r\n /**\r\n * Triggers screen reader read out a message.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/accessibility/} for more info\r\n * @param text Alert text\r\n */\r\n readerAlert(text) {\r\n if (this._a11yD !== true) {\r\n this._readerAlertElement.innerHTML = $utils.stripTags(text);\r\n }\r\n }\r\n /**\r\n * Sets themes to be used for the chart.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/themes/} for more info\r\n * @param themes A list of themes\r\n */\r\n setThemes(themes) {\r\n this._rootContainer.set(\"themes\", themes);\r\n // otherwise new themes are not applied\r\n const tooltipContainer = this.tooltipContainer;\r\n if (tooltipContainer) {\r\n tooltipContainer._applyThemes();\r\n }\r\n // @todo review this\r\n const interfaceColors = this.interfaceColors;\r\n if (interfaceColors) {\r\n interfaceColors._applyThemes();\r\n }\r\n }\r\n _addTooltip() {\r\n if (!this.tooltipContainer) {\r\n const tooltipContainerSettings = this._tooltipContainerSettings;\r\n const tooltipContainer = this._rootContainer.children.push(Container.new(this, {\r\n position: \"absolute\",\r\n isMeasured: false,\r\n width: p100,\r\n height: p100,\r\n layer: tooltipContainerSettings ? 35 : 30,\r\n layerMargin: tooltipContainerSettings ? tooltipContainerSettings : undefined\r\n }));\r\n this.tooltipContainer = tooltipContainer;\r\n const tooltip = Tooltip.new(this, {});\r\n this.container.set(\"tooltip\", tooltip);\r\n tooltip.hide(0);\r\n this._tooltip = tooltip;\r\n }\r\n }\r\n /**\r\n * Accesibility\r\n */\r\n _registerTabindexOrder(target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n if (target.get(\"focusable\")) {\r\n $array.pushOne(this._tabindexes, target);\r\n }\r\n else {\r\n $array.remove(this._tabindexes, target);\r\n }\r\n this._invalidateTabindexes();\r\n }\r\n _unregisterTabindexOrder(target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n $array.remove(this._tabindexes, target);\r\n this._invalidateTabindexes();\r\n }\r\n _invalidateTabindexes() {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n this._tabindexes.sort((a, b) => {\r\n const aindex = a.get(\"tabindexOrder\", 0);\r\n const bindex = b.get(\"tabindexOrder\", 0);\r\n if (aindex == bindex) {\r\n return 0;\r\n }\r\n else if (aindex > bindex) {\r\n return 1;\r\n }\r\n else {\r\n return -1;\r\n }\r\n });\r\n const groups = [];\r\n $array.each(this._tabindexes, (item, index) => {\r\n if (!item.getPrivate(\"focusElement\")) {\r\n this._makeFocusElement(index, item);\r\n }\r\n else {\r\n this._moveFocusElement(index, item);\r\n }\r\n const group = item.get(\"focusableGroup\");\r\n if (group && item.getPrivate(\"focusable\") !== false) {\r\n if (groups.indexOf(group) !== -1) {\r\n // Non-first element in the group, make it not directly focusable\r\n item.getPrivate(\"focusElement\").dom.setAttribute(\"tabindex\", \"-1\");\r\n }\r\n else {\r\n groups.push(group);\r\n }\r\n }\r\n });\r\n }\r\n _updateCurrentFocus() {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n if (this._focusedSprite) {\r\n this._decorateFocusElement(this._focusedSprite);\r\n this._positionFocusElement(this._focusedSprite);\r\n }\r\n }\r\n _decorateFocusElement(target, focusElement) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n // Decorate with proper accessibility attributes\r\n if (!focusElement) {\r\n focusElement = target.getPrivate(\"focusElement\").dom;\r\n }\r\n if (!focusElement) {\r\n return;\r\n }\r\n const role = target.get(\"role\");\r\n if (role) {\r\n focusElement.setAttribute(\"role\", role);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"role\");\r\n }\r\n const ariaLabel = target.get(\"ariaLabel\");\r\n if (ariaLabel) {\r\n const label = populateString(target, ariaLabel);\r\n focusElement.setAttribute(\"aria-label\", label);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-label\");\r\n }\r\n const ariaLive = target.get(\"ariaLive\");\r\n if (ariaLive) {\r\n focusElement.setAttribute(\"aria-live\", ariaLive);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-live\");\r\n }\r\n const ariaChecked = target.get(\"ariaChecked\");\r\n if (ariaChecked != null && role && [\"checkbox\", \"option\", \"radio\", \"menuitemcheckbox\", \"menuitemradio\", \"treeitem\"].indexOf(role) !== -1) {\r\n focusElement.setAttribute(\"aria-checked\", ariaChecked ? \"true\" : \"false\");\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-checked\");\r\n }\r\n const ariaCurrent = target.get(\"ariaCurrent\");\r\n if (ariaCurrent != null) {\r\n focusElement.setAttribute(\"aria-current\", ariaCurrent);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-current\");\r\n }\r\n const ariaSelected = target.get(\"ariaSelected\");\r\n if (ariaSelected != null && role && [\"gridcell\", \"option\", \"row\", \"tab\", \"columnheader\", \"rowheader\", \"treeitem\"].indexOf(role) !== -1) {\r\n focusElement.setAttribute(\"aria-selected\", ariaSelected ? \"true\" : \"false\");\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-selected\");\r\n }\r\n if (target.get(\"ariaHidden\")) {\r\n focusElement.setAttribute(\"aria-hidden\", \"true\");\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-hidden\");\r\n }\r\n const ariaOrientation = target.get(\"ariaOrientation\");\r\n if (ariaOrientation) {\r\n focusElement.setAttribute(\"aria-orientation\", ariaOrientation);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-orientation\");\r\n }\r\n const ariaValueNow = target.get(\"ariaValueNow\");\r\n if (ariaValueNow) {\r\n focusElement.setAttribute(\"aria-valuenow\", ariaValueNow);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-valuenow\");\r\n }\r\n const ariaValueMin = target.get(\"ariaValueMin\");\r\n if (ariaValueMin) {\r\n focusElement.setAttribute(\"aria-valuemin\", ariaValueMin);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-valuemin\");\r\n }\r\n const ariaValueMax = target.get(\"ariaValueMax\");\r\n if (ariaValueMax) {\r\n focusElement.setAttribute(\"aria-valuemax\", ariaValueMax);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-valuemax\");\r\n }\r\n const ariaValueText = target.get(\"ariaValueText\");\r\n if (ariaValueText) {\r\n focusElement.setAttribute(\"aria-valuetext\", ariaValueText);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-valuetext\");\r\n }\r\n const ariaControls = target.get(\"ariaControls\");\r\n if (ariaControls) {\r\n focusElement.setAttribute(\"aria-controls\", ariaControls);\r\n }\r\n else {\r\n focusElement.removeAttribute(\"aria-controls\");\r\n }\r\n if (target.get(\"visible\") && target.get(\"opacity\") !== 0 && target.get(\"role\") != \"tooltip\" && !target.isHidden() && target.getPrivate(\"focusable\") !== false) {\r\n if (focusElement.getAttribute(\"tabindex\") != \"-1\") {\r\n focusElement.setAttribute(\"tabindex\", \"\" + this.tabindex);\r\n }\r\n focusElement.removeAttribute(\"aria-hidden\");\r\n }\r\n else {\r\n focusElement.removeAttribute(\"tabindex\");\r\n focusElement.setAttribute(\"aria-hidden\", \"true\");\r\n }\r\n }\r\n _makeFocusElement(index, target) {\r\n if (target.getPrivate(\"focusElement\") || this._a11yD == true) {\r\n return;\r\n }\r\n // Init\r\n const focusElement = document.createElement(\"div\");\r\n if (target.get(\"role\") != \"tooltip\") {\r\n focusElement.tabIndex = this.tabindex;\r\n }\r\n focusElement.style.position = \"absolute\";\r\n $utils.setInteractive(focusElement, false);\r\n const disposers = [];\r\n target.setPrivate(\"focusElement\", {\r\n dom: focusElement,\r\n disposers,\r\n });\r\n this._decorateFocusElement(target);\r\n disposers.push($utils.addEventListener(focusElement, \"focus\", (ev) => {\r\n this._handleFocus(ev);\r\n }));\r\n disposers.push($utils.addEventListener(focusElement, \"blur\", (ev) => {\r\n this._handleBlur(ev);\r\n }));\r\n this._moveFocusElement(index, target);\r\n }\r\n _removeFocusElement(target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n $array.remove(this._tabindexes, target);\r\n const focusElement = target.getPrivate(\"focusElement\");\r\n if (focusElement) {\r\n const container = this._focusElementContainer;\r\n container.removeChild(focusElement.dom);\r\n $array.each(focusElement.disposers, (x) => {\r\n x.dispose();\r\n });\r\n }\r\n }\r\n _hideFocusElement(target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n const focusElement = target.getPrivate(\"focusElement\");\r\n focusElement.dom.style.display = \"none\";\r\n }\r\n _moveFocusElement(index, target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n // Get container\r\n const container = this._focusElementContainer;\r\n const focusElement = target.getPrivate(\"focusElement\").dom;\r\n if (focusElement === this._focusElementContainer.children[index]) {\r\n // Nothing to do\r\n return;\r\n }\r\n const next = this._focusElementContainer.children[index + 1];\r\n if (next) {\r\n container.insertBefore(focusElement, next);\r\n }\r\n else {\r\n container.append(focusElement);\r\n }\r\n }\r\n _positionFocusElement(target) {\r\n if (this._a11yD == true || target == undefined) {\r\n return;\r\n }\r\n const bounds = target.globalBounds();\r\n let width = bounds.right == bounds.left ? target.width() : bounds.right - bounds.left;\r\n let height = bounds.top == bounds.bottom ? target.height() : bounds.bottom - bounds.top;\r\n const padding = this._settings.focusPadding !== undefined ? this._settings.focusPadding : 2;\r\n let x = bounds.left - padding;\r\n let y = bounds.top - padding;\r\n if (width < 0) {\r\n x += width;\r\n width = Math.abs(width);\r\n }\r\n if (height < 0) {\r\n y += height;\r\n height = Math.abs(height);\r\n }\r\n const focusElement = target.getPrivate(\"focusElement\").dom;\r\n focusElement.style.top = y + \"px\";\r\n focusElement.style.left = x + \"px\";\r\n focusElement.style.width = (width + padding * 2) + \"px\";\r\n focusElement.style.height = (height + padding * 2) + \"px\";\r\n }\r\n _getSpriteByFocusElement(target) {\r\n let found;\r\n $array.eachContinue(this._tabindexes, (item, _index) => {\r\n if (item.getPrivate(\"focusElement\").dom === target) {\r\n found = item;\r\n return false;\r\n }\r\n return true;\r\n });\r\n return found;\r\n }\r\n _handleFocus(ev) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n // Get element\r\n //const focused = this._tabindexes[index];\r\n const focused = this._getSpriteByFocusElement(ev.target);\r\n if (!focused) {\r\n return;\r\n }\r\n // Jump over hidden elements\r\n if (!focused.isVisibleDeep()) {\r\n this._focusNext(ev.target, this._isShift ? -1 : 1);\r\n return;\r\n }\r\n // Size and position\r\n this._positionFocusElement(focused);\r\n //this._decorateFocusElement(focused);\r\n this._focusedSprite = focused;\r\n if (focused.events.isEnabled(\"focus\")) {\r\n focused.events.dispatch(\"focus\", {\r\n type: \"focus\",\r\n originalEvent: ev,\r\n target: focused\r\n });\r\n }\r\n }\r\n _focusNext(el, direction) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n const focusableElements = Array.from(document.querySelectorAll([\r\n 'a[href]',\r\n 'area[href]',\r\n 'button:not([disabled])',\r\n 'details',\r\n 'input:not([disabled])',\r\n 'iframe:not([disabled])',\r\n 'select:not([disabled])',\r\n 'textarea:not([disabled])',\r\n '[contentEditable=\"\"]',\r\n '[contentEditable=\"true\"]',\r\n '[contentEditable=\"TRUE\"]',\r\n '[tabindex]:not([tabindex^=\"-\"])',\r\n //':not([disabled])'\r\n ].join(',')));\r\n let index = focusableElements.indexOf(el) + direction;\r\n if (index < 0) {\r\n index = focusableElements.length - 1;\r\n }\r\n else if (index >= focusableElements.length) {\r\n index = 0;\r\n }\r\n focusableElements[index].focus();\r\n }\r\n _handleBlur(ev) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n const focused = this._focusedSprite;\r\n if (focused && !focused.isDisposed() && focused.events.isEnabled(\"blur\")) {\r\n focused.events.dispatch(\"blur\", {\r\n type: \"blur\",\r\n originalEvent: ev,\r\n target: focused\r\n });\r\n }\r\n this._focusedSprite = undefined;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n updateTooltip(target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n const text = $utils.stripTags(target._getText());\r\n let tooltipElement = target.getPrivate(\"tooltipElement\");\r\n if (target.get(\"role\") == \"tooltip\" && text != \"\") {\r\n if (!tooltipElement) {\r\n tooltipElement = this._makeTooltipElement(target);\r\n }\r\n if (tooltipElement.innerHTML != text) {\r\n tooltipElement.innerHTML = text;\r\n }\r\n tooltipElement.setAttribute(\"aria-hidden\", target.isVisibleDeep() ? \"false\" : \"true\");\r\n }\r\n else if (tooltipElement) {\r\n tooltipElement.remove();\r\n target.removePrivate(\"tooltipElement\");\r\n }\r\n }\r\n _makeTooltipElement(target) {\r\n const container = this._tooltipElementContainer;\r\n const tooltipElement = document.createElement(\"div\");\r\n tooltipElement.style.position = \"absolute\";\r\n tooltipElement.style.width = \"1px\";\r\n tooltipElement.style.height = \"1px\";\r\n tooltipElement.style.overflow = \"hidden\";\r\n tooltipElement.style.clip = \"rect(1px, 1px, 1px, 1px)\";\r\n $utils.setInteractive(tooltipElement, false);\r\n this._decorateFocusElement(target, tooltipElement);\r\n container.append(tooltipElement);\r\n target.setPrivate(\"tooltipElement\", tooltipElement);\r\n return tooltipElement;\r\n }\r\n _removeTooltipElement(target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n const tooltipElement = target.getPrivate(\"tooltipElement\");\r\n if (tooltipElement) {\r\n const parent = tooltipElement.parentElement;\r\n if (parent) {\r\n parent.removeChild(tooltipElement);\r\n }\r\n }\r\n }\r\n _invalidateAccessibility(target) {\r\n if (this._a11yD == true) {\r\n return;\r\n }\r\n this._focusElementDirty = true;\r\n const focusElement = target.getPrivate(\"focusElement\");\r\n if (target.get(\"focusable\")) {\r\n if (focusElement) {\r\n this._decorateFocusElement(target);\r\n this._positionFocusElement(target);\r\n }\r\n // else {\r\n // \tthis._renderer._makeFocusElement(0, this);\r\n // }\r\n }\r\n else if (focusElement) {\r\n this._removeFocusElement(target);\r\n }\r\n //this.updateCurrentFocus();\r\n }\r\n /**\r\n * Returns `true` if `target` is currently focused.\r\n *\r\n * @param target Target\r\n * @return Focused?\r\n */\r\n focused(target) {\r\n return this._focusedSprite === target;\r\n }\r\n /**\r\n * Converts document coordinates to coordinates withing root element.\r\n *\r\n * @param point Document point\r\n * @return Root point\r\n */\r\n documentPointToRoot(point) {\r\n const rect = this._getRealSize();\r\n const size = this._getCalculatedSize(rect);\r\n const scaleWidth = size.width / rect.width;\r\n const scaleHeight = size.height / rect.height;\r\n return {\r\n x: (point.x - rect.left) * scaleWidth,\r\n y: (point.y - rect.top) * scaleHeight,\r\n };\r\n }\r\n /**\r\n * Converts root coordinates to document\r\n *\r\n * @param point Document point\r\n * @return Root point\r\n */\r\n rootPointToDocument(point) {\r\n const rect = this._getRealSize();\r\n const size = this._getCalculatedSize(rect);\r\n const scaleWidth = size.width / rect.width;\r\n const scaleHeight = size.height / rect.height;\r\n return {\r\n x: (point.x / scaleWidth) + rect.left,\r\n y: (point.y / scaleHeight) + rect.top\r\n };\r\n }\r\n /**\r\n * @ignore\r\n */\r\n addDisposer(disposer) {\r\n this._disposers.push(disposer);\r\n return disposer;\r\n }\r\n _updateComputedStyles() {\r\n const styles = window.getComputedStyle(this.dom);\r\n let fontHash = \"\";\r\n $object.each(styles, (key, val) => {\r\n if ($type.isString(key) && key.match(/^font/)) {\r\n fontHash += val;\r\n }\r\n });\r\n const changed = fontHash != this._fontHash;\r\n if (changed) {\r\n this._fontHash = fontHash;\r\n }\r\n return changed;\r\n }\r\n _checkComputedStyles() {\r\n if (this._updateComputedStyles()) {\r\n this._invalidateLabelBounds(this.container);\r\n }\r\n }\r\n _invalidateLabelBounds(target) {\r\n if (target instanceof Container) {\r\n target.children.each((child) => {\r\n this._invalidateLabelBounds(child);\r\n });\r\n }\r\n else if (target instanceof Text) {\r\n target.markDirtyBounds();\r\n }\r\n }\r\n /**\r\n * To all the clever heads out there. Yes, we did not make any attempts to\r\n * scramble this.\r\n *\r\n * This is a part of a tool meant for our users to manage their commercial\r\n * licenses for removal of amCharts branding from charts.\r\n *\r\n * The only legit way to do so is to purchase a commercial license for amCharts:\r\n * https://www.amcharts.com/online-store/\r\n *\r\n * Removing or altering this code, or disabling amCharts branding in any other\r\n * way is against the license and thus illegal.\r\n */\r\n _hasLicense() {\r\n for (let i = 0; i < registry.licenses.length; i++) {\r\n if (registry.licenses[i].match(/^AM5C.{5,}/i)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n _licenseApplied() {\r\n if (this._logo) {\r\n this._logo.set(\"forceHidden\", true);\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n get debugGhostView() {\r\n return this._renderer.debugGhostView;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n set debugGhostView(value) {\r\n this._renderer.debugGhostView = value;\r\n }\r\n /**\r\n * Set this to `true` if you need chart to require first a tap onto it before\r\n * touch gesture related functionality like zoom/pan is turned on.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/root-element/#Touch_related_options} for more info\r\n * @default false\r\n * @since 5.2.9\r\n * @param value Needs a tap to activate touch functions\r\n */\r\n set tapToActivate(value) {\r\n this._renderer.tapToActivate = value;\r\n }\r\n /**\r\n * @return Needs a tap to activate touch functions\r\n */\r\n get tapToActivate() {\r\n return this._renderer.tapToActivate;\r\n }\r\n /**\r\n * If `tapToActivate` is set to `true`, this setting will determine number\r\n * of milliseconds the chart will stay \"active\", before releasing the\r\n * controls back to the page.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/getting-started/root-element/#Touch_related_options} for more info\r\n * @default 3000\r\n * @since 5.2.9\r\n * @param value Timeout\r\n */\r\n set tapToActivateTimeout(value) {\r\n this._renderer.tapToActivateTimeout = value;\r\n }\r\n /**\r\n * @return Timeout\r\n */\r\n get tapToActivateTimeout() {\r\n return this._renderer.tapToActivateTimeout;\r\n }\r\n _makeHTMLElement(target) {\r\n // Get container\r\n const container = this._htmlElementContainer;\r\n // Init\r\n const htmlElement = document.createElement(\"div\");\r\n target.setPrivate(\"htmlElement\", htmlElement);\r\n //htmlElement.tabIndex = this.tabindex;\r\n htmlElement.style.position = \"absolute\";\r\n htmlElement.style.overflow = \"auto\";\r\n htmlElement.style.boxSizing = \"border-box\";\r\n $utils.setInteractive(htmlElement, target.get(\"interactive\", false));\r\n // Translate events\r\n if (target.events.isEnabled(\"click\")) {\r\n $utils.setInteractive(htmlElement, true);\r\n this._disposers.push($utils.addEventListener(htmlElement, \"click\", (ev) => {\r\n const downEvent = this._renderer.getEvent(ev);\r\n target.events.dispatch(\"click\", {\r\n type: \"click\",\r\n originalEvent: downEvent.event,\r\n point: downEvent.point,\r\n simulated: false,\r\n target: target\r\n });\r\n }));\r\n }\r\n this._positionHTMLElement(target);\r\n container.append(htmlElement);\r\n $array.pushOne(this._htmlEnabledContainers, target);\r\n return htmlElement;\r\n }\r\n _positionHTMLElements() {\r\n $array.each(this._htmlEnabledContainers, (target) => {\r\n this._positionHTMLElement(target);\r\n });\r\n }\r\n _positionHTMLElement(target) {\r\n const htmlElement = target.getPrivate(\"htmlElement\");\r\n if (htmlElement) {\r\n // Translate settings\r\n const visualSettings = [\"paddingTop\", \"paddingRight\", \"paddingBottom\", \"paddingLeft\", \"minWidth\", \"minHeight\", \"maxWidth\", \"maxHeight\"];\r\n $array.each(visualSettings, (setting) => {\r\n const value = target.get(setting);\r\n if (value) {\r\n htmlElement.style[setting] = value + \"px\";\r\n }\r\n else {\r\n htmlElement.style[setting] = \"\";\r\n }\r\n });\r\n // Init and reset scale / rotation\r\n const scale = target.compositeScale() || 1;\r\n const rotation = target.compositeRotation() || 0;\r\n htmlElement.style.transform = \"\";\r\n htmlElement.style.transformOrigin = \"\";\r\n // Deal with opacity\r\n const opacity = target.compositeOpacity();\r\n setTimeout(() => {\r\n htmlElement.style.opacity = opacity + \"\";\r\n }, 10);\r\n const visible = target.isVisibleDeep();\r\n if (visible) {\r\n htmlElement.style.display = \"block\";\r\n }\r\n // Deal with position\r\n // const bounds = target.globalBounds();\r\n // htmlElement.style.top = (bounds.top) + \"px\";\r\n // htmlElement.style.left = (bounds.left) + \"px\";\r\n let pos = {\r\n x: target.x(),\r\n y: target.y()\r\n };\r\n if (target.parent) {\r\n pos = target.parent.toGlobal(pos);\r\n }\r\n htmlElement.style.top = pos.y + \"px\";\r\n htmlElement.style.left = pos.x + \"px\";\r\n // Use width/height if those are set\r\n const width = target.get(\"width\");\r\n const height = target.get(\"height\");\r\n let w = 0;\r\n let h = 0;\r\n if (width) {\r\n w = target.width();\r\n }\r\n if (height) {\r\n h = target.height();\r\n }\r\n if (!width || !height) {\r\n htmlElement.style.position = \"fixed\";\r\n htmlElement.style.width = \"\";\r\n htmlElement.style.height = \"\";\r\n const bbox = htmlElement.getBoundingClientRect();\r\n htmlElement.style.position = \"absolute\";\r\n if (!width)\r\n w = bbox.width;\r\n if (!height)\r\n h = bbox.height;\r\n let lw = w / scale;\r\n let lh = h / scale;\r\n let cx = target.get(\"centerX\", 0);\r\n let cy = target.get(\"centerY\", 0);\r\n let ll = 0;\r\n let lr = 0;\r\n let lt = 0;\r\n let lb = 0;\r\n if (cx instanceof Percent) {\r\n ll = -cx.value * lw;\r\n lr = (1 - cx.value) * lw;\r\n }\r\n else {\r\n ll = -cx;\r\n lr = lw - cx;\r\n }\r\n if (cy instanceof Percent) {\r\n lt = -cy.value * lh;\r\n lb = (1 - cy.value) * lh;\r\n }\r\n else {\r\n lt = -cy;\r\n lb = lh - cy;\r\n }\r\n target._localBounds = { left: ll, right: lr, top: lt, bottom: lb };\r\n let previousBounds = target._adjustedLocalBounds;\r\n let newBounds = target._display.getAdjustedBounds(target._localBounds);\r\n target._adjustedLocalBounds = newBounds;\r\n // compare each value of the bounds\r\n if (previousBounds.left !== newBounds.left || previousBounds.right !== newBounds.right || previousBounds.top !== newBounds.top || previousBounds.bottom !== newBounds.bottom) {\r\n target.markDirtyBounds();\r\n }\r\n }\r\n if (w > 0) {\r\n htmlElement.style.minWidth = (w) + \"px\";\r\n }\r\n if (h > 0) {\r\n htmlElement.style.minHeight = (h) + \"px\";\r\n }\r\n // Hide or show\r\n if (!visible || opacity == 0) {\r\n htmlElement.style.display = \"none\";\r\n }\r\n // Center position\r\n const x = target.get(\"centerX\", 0);\r\n const originX = isPercent(x) ? x.percent + \"%\" : x + \"px\";\r\n const y = target.get(\"centerY\", 0);\r\n const originY = isPercent(y) ? y.percent + \"%\" : y + \"px\";\r\n if (x || y) {\r\n htmlElement.style.transform = \"translate(-\" + originX + \", -\" + originY + \")\" + htmlElement.style.transform;\r\n }\r\n // Deal with scale\r\n if (scale != 1) {\r\n htmlElement.style.transform += \"scale(\" + scale + \")\";\r\n }\r\n if (rotation != 0) {\r\n htmlElement.style.transform += \" rotate(\" + rotation + \"deg)\";\r\n }\r\n if (htmlElement.style.transform != \"\") {\r\n htmlElement.style.transformOrigin = originX + \" \" + originY;\r\n //htmlElement.style.transformOrigin = \"0% 0%\";\r\n }\r\n }\r\n }\r\n _setHTMLContent(target, html) {\r\n let htmlElement = target.getPrivate(\"htmlElement\");\r\n if (!htmlElement) {\r\n htmlElement = this._makeHTMLElement(target);\r\n }\r\n if (htmlElement.innerHTML != html) {\r\n htmlElement.innerHTML = html;\r\n }\r\n }\r\n _removeHTMLContent(target) {\r\n let htmlElement = target.getPrivate(\"htmlElement\");\r\n if (htmlElement) {\r\n this._htmlElementContainer.removeChild(htmlElement);\r\n target.removePrivate(\"htmlElement\");\r\n }\r\n $array.remove(this._htmlEnabledContainers, target);\r\n }\r\n}\r\n//# sourceMappingURL=Root.js.map","import { Entity } from \"../../core/util/Entity\";\r\n/**\r\n * A universal placeholder for bullet elements.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/bullets/} for more info\r\n */\r\nexport class Bullet extends Entity {\r\n constructor() {\r\n super(...arguments);\r\n // used by MapPolygons where one data item can have multiple bullets of the same kind\r\n Object.defineProperty(this, \"_index\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * Target series object if it's a bullet for series.\r\n */\r\n Object.defineProperty(this, \"series\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n _afterNew() {\r\n // Applying themes because bullet will not have parent\r\n super._afterNewApplyThemes();\r\n }\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n if (this.isDirty(\"sprite\")) {\r\n const sprite = this.get(\"sprite\");\r\n if (sprite) {\r\n sprite.setAll({ position: \"absolute\", role: \"figure\" });\r\n this._disposers.push(sprite);\r\n }\r\n }\r\n if (this.isDirty(\"locationX\") || this.isDirty(\"locationY\")) {\r\n if (this.series) {\r\n this.series._positionBullet(this);\r\n }\r\n }\r\n }\r\n}\r\nObject.defineProperty(Bullet, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Bullet\"\r\n});\r\nObject.defineProperty(Bullet, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Entity.classNames.concat([Bullet.className])\r\n});\r\n//# sourceMappingURL=Bullet.js.map","import * as $type from \"../util/Type\";\r\nimport * as $math from \"../util/Math\";\r\nimport * as $utils from \"../util/Utils\";\r\nimport { Rectangle } from \"./Rectangle\";\r\n/**\r\n * Draws a rectangle with rounded corners.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/graphics/} for more info\r\n * @important\r\n */\r\nexport class RoundedRectangle extends Rectangle {\r\n _beforeChanged() {\r\n super._beforeChanged();\r\n if (this.isDirty(\"cornerRadiusTL\") || this.isDirty(\"cornerRadiusTR\") || this.isDirty(\"cornerRadiusBR\") || this.isDirty(\"cornerRadiusBL\")) {\r\n this._clear = true;\r\n }\r\n }\r\n _draw() {\r\n let width = this.width();\r\n let height = this.height();\r\n let w = width;\r\n let h = height;\r\n let wSign = w / Math.abs(width);\r\n let hSign = h / Math.abs(height);\r\n if ($type.isNumber(w) && $type.isNumber(h)) {\r\n let minSide = Math.min(w, h) / 2;\r\n let crtl = $utils.relativeToValue(this.get(\"cornerRadiusTL\", 8), minSide);\r\n let crtr = $utils.relativeToValue(this.get(\"cornerRadiusTR\", 8), minSide);\r\n let crbr = $utils.relativeToValue(this.get(\"cornerRadiusBR\", 8), minSide);\r\n let crbl = $utils.relativeToValue(this.get(\"cornerRadiusBL\", 8), minSide);\r\n let maxcr = Math.min(Math.abs(w / 2), Math.abs(h / 2));\r\n crtl = $math.fitToRange(crtl, 0, maxcr);\r\n crtr = $math.fitToRange(crtr, 0, maxcr);\r\n crbr = $math.fitToRange(crbr, 0, maxcr);\r\n crbl = $math.fitToRange(crbl, 0, maxcr);\r\n const display = this._display;\r\n display.moveTo(crtl * wSign, 0);\r\n display.lineTo(w - crtr * wSign, 0);\r\n if (crtr > 0) {\r\n display.arcTo(w, 0, w, crtr * hSign, crtr);\r\n }\r\n display.lineTo(w, h - crbr * hSign);\r\n if (crbr > 0) {\r\n display.arcTo(w, h, w - crbr * wSign, h, crbr);\r\n }\r\n display.lineTo(crbl * wSign, h);\r\n if (crbl > 0) {\r\n display.arcTo(0, h, 0, h - crbl * hSign, crbl);\r\n }\r\n display.lineTo(0, crtl * hSign);\r\n if (crtl > 0) {\r\n display.arcTo(0, 0, crtl * wSign, 0, crtl);\r\n }\r\n display.closePath();\r\n }\r\n }\r\n}\r\nObject.defineProperty(RoundedRectangle, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"RoundedRectangle\"\r\n});\r\nObject.defineProperty(RoundedRectangle, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Rectangle.classNames.concat([RoundedRectangle.className])\r\n});\r\n//# sourceMappingURL=RoundedRectangle.js.map","import { RoundedRectangle } from \"../render/RoundedRectangle\";\r\nimport { Container } from \"./Container\";\r\nimport * as $utils from \"../../core/util/Utils\";\r\n/**\r\n * Draws an interactive button.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/buttons/} for more info\r\n * @important\r\n */\r\nexport class Button extends Container {\r\n _afterNew() {\r\n this._settings.themeTags = $utils.mergeTags(this._settings.themeTags, [\"button\"]);\r\n super._afterNew();\r\n if (!this._settings.background) {\r\n this.set(\"background\", RoundedRectangle.new(this._root, {\r\n themeTags: $utils.mergeTags(this._settings.themeTags, [\"background\"])\r\n }));\r\n }\r\n this.setPrivate(\"trustBounds\", true);\r\n }\r\n _prepareChildren() {\r\n super._prepareChildren();\r\n if (this.isDirty(\"icon\")) {\r\n const previous = this._prevSettings.icon;\r\n const icon = this.get(\"icon\");\r\n if (icon !== previous) {\r\n this._disposeProperty(\"icon\");\r\n if (previous) {\r\n previous.dispose();\r\n }\r\n if (icon) {\r\n this.children.push(icon);\r\n }\r\n this._prevSettings.icon = icon;\r\n }\r\n }\r\n if (this.isDirty(\"label\")) {\r\n const previous = this._prevSettings.label;\r\n const label = this.get(\"label\");\r\n if (label !== previous) {\r\n this._disposeProperty(\"label\");\r\n if (previous) {\r\n previous.dispose();\r\n }\r\n if (label) {\r\n this.children.push(label);\r\n }\r\n this._prevSettings.label = label;\r\n }\r\n }\r\n }\r\n}\r\nObject.defineProperty(Button, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Button\"\r\n});\r\nObject.defineProperty(Button, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Container.classNames.concat([Button.className])\r\n});\r\n//# sourceMappingURL=Button.js.map","import { List } from \"./List\";\r\n/**\r\n * A [[List]] that holds components data.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/data/} for more info\r\n */\r\nexport class ListData extends List {\r\n constructor() {\r\n super(...arguments);\r\n /**\r\n * An optional processor for data.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/data/#Pre_processing_data} for more info\r\n */\r\n Object.defineProperty(this, \"processor\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n }\r\n /**\r\n * @ignore\r\n */\r\n incrementRef() { }\r\n /**\r\n * @ignore\r\n */\r\n decrementRef() { }\r\n _onPush(newValue) {\r\n if (this.processor) {\r\n this.processor.processRow(newValue);\r\n }\r\n super._onPush(newValue);\r\n }\r\n _onInsertIndex(index, newValue) {\r\n if (this.processor) {\r\n this.processor.processRow(newValue);\r\n }\r\n super._onInsertIndex(index, newValue);\r\n }\r\n _onSetIndex(index, oldValue, newValue) {\r\n if (this.processor) {\r\n this.processor.processRow(newValue);\r\n }\r\n super._onSetIndex(index, oldValue, newValue);\r\n }\r\n}\r\n/**\r\n * @deprecated\r\n * @todo remove\r\n */\r\nexport class JsonData {\r\n constructor(value) {\r\n Object.defineProperty(this, \"processor\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_value\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this._value = value;\r\n }\r\n incrementRef() { }\r\n decrementRef() { }\r\n}\r\n//# sourceMappingURL=Data.js.map","import { __awaiter } from \"tslib\";\r\nimport { Settings } from \"../util/Entity\";\r\nimport { Container } from \"./Container\";\r\nimport { ListData } from \"../util/Data\";\r\nimport * as $array from \"../util/Array\";\r\nimport * as $object from \"../util/Object\";\r\n/**\r\n * A base element that holds data bit (data item) for any [[Component]].\r\n */\r\nexport class DataItem extends Settings {\r\n constructor(component, dataContext, settings) {\r\n super(settings);\r\n /**\r\n * A data item's owener [[Component]].\r\n */\r\n Object.defineProperty(this, \"component\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * A reference to actual item in source data this item is based on.\r\n */\r\n Object.defineProperty(this, \"dataContext\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * @todo requires description\r\n */\r\n Object.defineProperty(this, \"bullets\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * A set of \"open\" values.\r\n */\r\n Object.defineProperty(this, \"open\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * A set of \"close\" values.\r\n */\r\n Object.defineProperty(this, \"close\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n this.dataContext = dataContext;\r\n this.component = component;\r\n this._settings.visible = true;\r\n this._checkDirty();\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirty() {\r\n this.component.markDirtyValues(this);\r\n }\r\n _startAnimation() {\r\n this.component._root._addAnimation(this);\r\n }\r\n _animationTime() {\r\n return this.component._root.animationTime;\r\n }\r\n _dispose() {\r\n if (this.component) {\r\n this.component.disposeDataItem(this);\r\n }\r\n super._dispose();\r\n }\r\n /**\r\n * Shows a data item that's currently hidden.\r\n */\r\n show(duration) {\r\n this.setRaw(\"visible\", true);\r\n if (this.component) {\r\n this.component.showDataItem(this, duration);\r\n }\r\n }\r\n /**\r\n * Hides a data item that's currently visible.\r\n */\r\n hide(duration) {\r\n this.setRaw(\"visible\", false);\r\n if (this.component) {\r\n this.component.hideDataItem(this, duration);\r\n }\r\n }\r\n isHidden() {\r\n return !this.get(\"visible\");\r\n }\r\n}\r\n/**\r\n * A base class for elements that make use of data.\r\n */\r\nexport class Component extends Container {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_data\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new ListData()\r\n });\r\n Object.defineProperty(this, \"_dataItems\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"_mainDataItems\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this._dataItems\r\n });\r\n Object.defineProperty(this, \"valueFields\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: []\r\n });\r\n Object.defineProperty(this, \"fields\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: [\"id\"]\r\n });\r\n Object.defineProperty(this, \"_valueFields\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_valueFieldsF\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_fields\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_fieldsF\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_valuesDirty\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_dataChanged\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_dataGrouped\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n /**\r\n * Indicates if the component has already been initialized.\r\n */\r\n Object.defineProperty(this, \"inited\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n }\r\n /**\r\n * Component's data.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/data/} for more info\r\n */\r\n set data(data) {\r\n data.incrementRef();\r\n this._data.decrementRef();\r\n this._data = data;\r\n }\r\n /**\r\n * @return Data\r\n */\r\n get data() {\r\n return this._data;\r\n }\r\n _dispose() {\r\n super._dispose();\r\n this._data.decrementRef();\r\n }\r\n _onDataClear() {\r\n }\r\n _afterNew() {\r\n super._afterNew();\r\n this._data.incrementRef();\r\n this._updateFields();\r\n this._disposers.push(this.data.events.onAll((change) => {\r\n const dataItems = this._mainDataItems;\r\n this.markDirtyValues();\r\n this._markDirtyGroup();\r\n this._dataChanged = true;\r\n if (change.type === \"clear\") {\r\n $array.each(dataItems, (dataItem) => {\r\n dataItem.dispose();\r\n });\r\n dataItems.length = 0;\r\n this._onDataClear();\r\n }\r\n else if (change.type === \"push\") {\r\n const dataItem = new DataItem(this, change.newValue, this._makeDataItem(change.newValue));\r\n dataItems.push(dataItem);\r\n this.processDataItem(dataItem);\r\n }\r\n else if (change.type === \"setIndex\") {\r\n const dataItem = dataItems[change.index];\r\n const properties = this._makeDataItem(change.newValue);\r\n if (dataItem.bullets && dataItem.bullets.length == 0) {\r\n dataItem.bullets = undefined;\r\n }\r\n $object.keys(properties).forEach((key) => {\r\n dataItem.animate({\r\n key: key,\r\n to: properties[key],\r\n duration: this.get(\"interpolationDuration\", 0),\r\n easing: this.get(\"interpolationEasing\"),\r\n });\r\n });\r\n dataItem.dataContext = change.newValue;\r\n }\r\n else if (change.type === \"insertIndex\") {\r\n const dataItem = new DataItem(this, change.newValue, this._makeDataItem(change.newValue));\r\n dataItems.splice(change.index, 0, dataItem);\r\n this.processDataItem(dataItem);\r\n }\r\n else if (change.type === \"removeIndex\") {\r\n const dataItem = dataItems[change.index];\r\n dataItem.dispose();\r\n dataItems.splice(change.index, 1);\r\n }\r\n else if (change.type === \"moveIndex\") {\r\n const dataItem = dataItems[change.oldIndex];\r\n dataItems.splice(change.oldIndex, 1);\r\n dataItems.splice(change.newIndex, 0, dataItem);\r\n }\r\n else {\r\n throw new Error(\"Unknown IStreamEvent type\");\r\n }\r\n this._afterDataChange();\r\n }));\r\n }\r\n _updateFields() {\r\n if (this.valueFields) {\r\n this._valueFields = [];\r\n this._valueFieldsF = {};\r\n $array.each(this.valueFields, (key) => {\r\n const field = this.get((key + \"Field\"));\r\n if (field) {\r\n this._valueFields.push(key);\r\n this._valueFieldsF[key] = { fieldKey: key + \"Field\", workingKey: key + \"Working\" };\r\n }\r\n });\r\n }\r\n if (this.fields) {\r\n this._fields = [];\r\n this._fieldsF = {};\r\n $array.each(this.fields, (key) => {\r\n const field = this.get((key + \"Field\"));\r\n if (field) {\r\n this._fields.push(key);\r\n this._fieldsF[key] = key + \"Field\";\r\n }\r\n });\r\n }\r\n }\r\n /**\r\n * A list of component's data items.\r\n *\r\n * @return Data items\r\n */\r\n get dataItems() {\r\n return this._dataItems;\r\n }\r\n processDataItem(_dataItem) { }\r\n _makeDataItem(data) {\r\n //const output: this[\"_dataItemSettings\"] = {};\r\n const output = {}; // temporary to solve error\r\n if (this._valueFields) {\r\n $array.each(this._valueFields, (key) => {\r\n const field = this.get((this._valueFieldsF[key].fieldKey));\r\n output[key] = data[field];\r\n output[this._valueFieldsF[key].workingKey] = output[key];\r\n });\r\n }\r\n if (this._fields) {\r\n $array.each(this._fields, (key) => {\r\n const field = this.get((this._fieldsF[key]));\r\n output[key] = data[field];\r\n });\r\n }\r\n return output;\r\n }\r\n /**\r\n * Creates a new data item and processes it.\r\n *\r\n * @param data Data item settings\r\n * @param dataContext Data context\r\n * @return New data item\r\n */\r\n makeDataItem(data, dataContext) {\r\n let dataItem = new DataItem(this, dataContext, data);\r\n this.processDataItem(dataItem);\r\n return dataItem;\r\n }\r\n /**\r\n * Adds new explicit data item to series.\r\n *\r\n * @param data Data item settings\r\n * @param dataContext Data context\r\n * @return New data item\r\n */\r\n pushDataItem(data, dataContext) {\r\n const dataItem = this.makeDataItem(data, dataContext);\r\n this._mainDataItems.push(dataItem);\r\n return dataItem;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n disposeDataItem(_dataItem) {\r\n }\r\n /**\r\n * Shows component's data item.\r\n *\r\n * @param dataItem Data item\r\n * @param _duration Animation duration in milliseconds\r\n * @return Promise\r\n */\r\n showDataItem(dataItem, _duration) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n dataItem.set(\"visible\", true);\r\n });\r\n }\r\n /**\r\n * Hides component's data item.\r\n *\r\n * @param dataItem Data item\r\n * @param _duration Animation duration in milliseconds\r\n * @return Promise\r\n */\r\n hideDataItem(dataItem, _duration) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n dataItem.set(\"visible\", false);\r\n });\r\n }\r\n _clearDirty() {\r\n super._clearDirty();\r\n this._valuesDirty = false;\r\n }\r\n _afterDataChange() {\r\n }\r\n _afterChanged() {\r\n super._afterChanged();\r\n if (this._dataChanged) {\r\n const type = \"datavalidated\";\r\n if (this.events.isEnabled(type)) {\r\n this.events.dispatch(type, { type: type, target: this });\r\n }\r\n this._dataChanged = false;\r\n }\r\n this.inited = true;\r\n }\r\n /**\r\n * Forces a repaint of the element which relies on data.\r\n *\r\n * @since 5.0.21\r\n */\r\n markDirtyValues(_dataItem) {\r\n this.markDirty();\r\n this._valuesDirty = true;\r\n }\r\n _markDirtyGroup() {\r\n this._dataGrouped = false;\r\n }\r\n /**\r\n * @ignore\r\n */\r\n markDirtySize() {\r\n this._sizeDirty = true;\r\n this.markDirty();\r\n }\r\n}\r\nObject.defineProperty(Component, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Component\"\r\n});\r\nObject.defineProperty(Component, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Container.classNames.concat([Component.className])\r\n});\r\n//# sourceMappingURL=Component.js.map","/**\r\n * ============================================================================\r\n * IMPORTS\r\n * ============================================================================\r\n * @hidden\r\n */\r\nimport * as $type from \"./Type\";\r\nimport * as $utils from \"./Utils\";\r\n/**\r\n * Returns a `Promise` which can be used to execute code after number of\r\n * milliseconds.\r\n *\r\n * @param ms Sleep duration in ms\r\n * @return Promise\r\n */\r\nexport function sleep(ms) {\r\n return new Promise((resolve, _reject) => {\r\n setTimeout(resolve, ms);\r\n });\r\n}\r\n/**\r\n * Maps time period names to their numeric representations in milliseconds.\r\n *\r\n * @ignore Exclude from docs\r\n */\r\nexport let timeUnitDurations = {\r\n millisecond: 1,\r\n second: 1000,\r\n minute: 60000,\r\n hour: 3600000,\r\n day: 86400000,\r\n week: 604800000,\r\n month: 365.242 / 12 * 86400000,\r\n year: 31536000000\r\n};\r\n/**\r\n * Returns the next time unit that goes after source `unit`.\r\n *\r\n * E.g. \"hour\" is the next unit after \"minute\", etc.\r\n *\r\n * @ignore Exclude from docs\r\n * @param unit Source time unit\r\n * @return Next time unit\r\n */\r\nexport function getNextUnit(unit) {\r\n switch (unit) {\r\n case \"year\":\r\n return;\r\n case \"month\":\r\n return \"year\";\r\n case \"week\":\r\n return \"month\";\r\n case \"day\":\r\n return \"month\"; // not a mistake\r\n case \"hour\":\r\n return \"day\";\r\n case \"minute\":\r\n return \"hour\";\r\n case \"second\":\r\n return \"minute\";\r\n case \"millisecond\":\r\n return \"second\";\r\n }\r\n}\r\n/**\r\n * Returns number of milliseconds in the `count` of time `unit`.\r\n *\r\n * Available units: \"millisecond\", \"second\", \"minute\", \"hour\", \"day\", \"week\",\r\n * \"month\", and \"year\".\r\n *\r\n * @param unit Time unit\r\n * @param count Number of units\r\n * @return Milliseconds\r\n */\r\nexport function getDuration(unit, count) {\r\n if (count == null) {\r\n count = 1;\r\n }\r\n return timeUnitDurations[unit] * count;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function getIntervalDuration(interval) {\r\n if (interval) {\r\n return timeUnitDurations[interval.timeUnit] * interval.count;\r\n }\r\n return 0;\r\n}\r\nexport function getDateIntervalDuration(interval, date, firstDateOfWeek, utc, timezone) {\r\n const unit = interval.timeUnit;\r\n const count = interval.count;\r\n if (unit == \"hour\" || unit == \"minute\" || unit == \"second\" || unit == \"millisecond\") {\r\n return timeUnitDurations[interval.timeUnit] * interval.count;\r\n }\r\n else {\r\n const firstTime = round(new Date(date.getTime()), unit, count, firstDateOfWeek, utc, undefined, timezone).getTime();\r\n let lastTime = firstTime + count * getDuration(unit) * 1.05;\r\n lastTime = round(new Date(lastTime), unit, 1, firstDateOfWeek, utc, undefined, timezone).getTime();\r\n return lastTime - firstTime;\r\n }\r\n}\r\n/**\r\n * Returns current `Date` object.\r\n *\r\n * @return Current date\r\n */\r\nexport function now() {\r\n return new Date();\r\n}\r\n/**\r\n * Returns current timestamp.\r\n *\r\n * @return Current timestamp\r\n */\r\nexport function getTime() {\r\n return now().getTime();\r\n}\r\n/**\r\n * Returns a copy of the `Date` object.\r\n *\r\n * @param date Source date\r\n * @return Copy\r\n */\r\nexport function copy(date) {\r\n return new Date(date.getTime()); // todo: check if this is ok. new Date(date) used to strip milliseconds on FF in v3\r\n}\r\n/**\r\n * Checks if the `unit` part of two `Date` objects do not match. Two dates\r\n * represent a \"range\" of time, rather the same time date.\r\n *\r\n * @param timeOne timestamp\r\n * @param timeTwo timestamp\r\n * @param unit Time unit to check\r\n * @return Range?\r\n */\r\nexport function checkChange(timeOne, timeTwo, unit, utc, timezone) {\r\n // quick\r\n if ((timeTwo - timeOne) > getDuration(unit, 1.2)) {\r\n return true;\r\n }\r\n let dateOne = new Date(timeOne);\r\n let dateTwo = new Date(timeTwo);\r\n if (timezone) {\r\n dateOne = timezone.convertLocal(dateOne);\r\n dateTwo = timezone.convertLocal(dateTwo);\r\n }\r\n let timeZoneOffset1 = 0;\r\n let timeZoneOffset2 = 0;\r\n if (!utc && unit != \"millisecond\") {\r\n timeZoneOffset1 = dateOne.getTimezoneOffset();\r\n dateOne.setUTCMinutes(dateOne.getUTCMinutes() - timeZoneOffset1);\r\n timeZoneOffset2 = dateTwo.getTimezoneOffset();\r\n dateTwo.setUTCMinutes(dateTwo.getUTCMinutes() - timeZoneOffset2);\r\n }\r\n let changed = false;\r\n switch (unit) {\r\n case \"year\":\r\n if (dateOne.getUTCFullYear() != dateTwo.getUTCFullYear()) {\r\n changed = true;\r\n }\r\n break;\r\n case \"month\":\r\n if (dateOne.getUTCFullYear() != dateTwo.getUTCFullYear()) {\r\n changed = true;\r\n }\r\n else if (dateOne.getUTCMonth() != dateTwo.getUTCMonth()) {\r\n changed = true;\r\n }\r\n break;\r\n case \"day\":\r\n if (dateOne.getUTCMonth() != dateTwo.getUTCMonth()) {\r\n changed = true;\r\n }\r\n else if (dateOne.getUTCDate() != dateTwo.getUTCDate()) {\r\n changed = true;\r\n }\r\n break;\r\n case \"hour\":\r\n if (dateOne.getUTCHours() != dateTwo.getUTCHours()) {\r\n changed = true;\r\n }\r\n break;\r\n case \"minute\":\r\n if (dateOne.getUTCMinutes() != dateTwo.getUTCMinutes()) {\r\n changed = true;\r\n }\r\n break;\r\n case \"second\":\r\n if (dateOne.getUTCSeconds() != dateTwo.getUTCSeconds()) {\r\n changed = true;\r\n }\r\n break;\r\n case \"millisecond\":\r\n if (dateOne.getTime() != dateTwo.getTime()) {\r\n changed = true;\r\n }\r\n break;\r\n }\r\n if (changed) {\r\n return changed;\r\n }\r\n let nextUnit = getNextUnit(unit);\r\n if (nextUnit) {\r\n return checkChange(timeOne, timeTwo, nextUnit, utc, timezone);\r\n }\r\n else {\r\n return false;\r\n }\r\n}\r\n/**\r\n * Adds `count` of time `unit` to the source date. Returns a modified `Date` object.\r\n *\r\n * @param date Source date\r\n * @param unit Time unit\r\n * @param count Number of units to add\r\n * @return Modified date\r\n */\r\nexport function add(date, unit, count, utc, timezone) {\r\n let timeZoneOffset = 0;\r\n if (!utc && unit != \"millisecond\") {\r\n timeZoneOffset = date.getTimezoneOffset();\r\n if (timezone) {\r\n timeZoneOffset -= timezone.offsetUTC(date);\r\n }\r\n date.setUTCMinutes(date.getUTCMinutes() - timeZoneOffset);\r\n }\r\n switch (unit) {\r\n case \"day\":\r\n let day = date.getUTCDate();\r\n date.setUTCDate(day + count);\r\n break;\r\n case \"second\":\r\n let seconds = date.getUTCSeconds();\r\n date.setUTCSeconds(seconds + count);\r\n break;\r\n case \"millisecond\":\r\n let milliseconds = date.getUTCMilliseconds();\r\n date.setUTCMilliseconds(milliseconds + count);\r\n break;\r\n case \"hour\":\r\n let hours = date.getUTCHours();\r\n date.setUTCHours(hours + count);\r\n break;\r\n case \"minute\":\r\n let minutes = date.getUTCMinutes();\r\n date.setUTCMinutes(minutes + count);\r\n break;\r\n case \"year\":\r\n let year = date.getUTCFullYear();\r\n date.setUTCFullYear(year + count);\r\n break;\r\n case \"month\":\r\n const endDays = date.getUTCDate();\r\n const startDays = new Date(date.getUTCFullYear(), date.getUTCMonth(), 0).getUTCDate();\r\n let month = date.getUTCMonth();\r\n if (endDays > startDays) {\r\n date.setUTCMonth(month + count, startDays);\r\n }\r\n else {\r\n date.setUTCMonth(month + count);\r\n }\r\n break;\r\n case \"week\":\r\n let wday = date.getUTCDate();\r\n date.setUTCDate(wday + count * 7);\r\n break;\r\n }\r\n if (!utc && unit != \"millisecond\") {\r\n date.setUTCMinutes(date.getUTCMinutes() + timeZoneOffset);\r\n if (unit == \"day\" || unit == \"week\" || unit == \"month\" || unit == \"year\") {\r\n let newTimeZoneOffset = date.getTimezoneOffset();\r\n if (timezone) {\r\n newTimeZoneOffset += timezone.offsetUTC(date);\r\n }\r\n if (newTimeZoneOffset != timeZoneOffset) {\r\n let diff = newTimeZoneOffset - timeZoneOffset;\r\n date.setUTCMinutes(date.getUTCMinutes() + diff);\r\n // solves issues if new time falls back to old time zone\r\n if (date.getTimezoneOffset() != newTimeZoneOffset) {\r\n date.setUTCMinutes(date.getUTCMinutes() - diff);\r\n }\r\n }\r\n }\r\n }\r\n return date;\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function roun(time, unit, count, root, firstTime) {\r\n let firstDate;\r\n if (firstTime != null) {\r\n firstDate = new Date(firstTime);\r\n }\r\n return round(new Date(time), unit, count, root.locale.firstDayOfWeek, root.utc, firstDate, root.timezone).getTime();\r\n}\r\n/**\r\n * \"Rounds\" the date to specific time unit.\r\n *\r\n * @param date Source date\r\n * @param unit Time unit\r\n * @param count Number of units to round to\r\n * @param firstDateOfWeek First day of week\r\n * @param utc Use UTC timezone\r\n * @param firstDate First date to round to\r\n * @param roundMinutes Minutes to round to (some timezones use non-whole hour)\r\n * @param timezone Use specific named timezone when rounding\r\n * @return New date\r\n */\r\nexport function round(date, unit, count, firstDateOfWeek, utc, firstDate, timezone) {\r\n if (!timezone || utc) {\r\n let timeZoneOffset = 0;\r\n if (!utc && unit != \"millisecond\") {\r\n timeZoneOffset = date.getTimezoneOffset();\r\n date.setUTCMinutes(date.getUTCMinutes() - timeZoneOffset);\r\n }\r\n switch (unit) {\r\n case \"day\":\r\n let day = date.getUTCDate();\r\n if (count > 1) {\r\n //\tday = Math.floor(day / count) * count;\r\n if (firstDate) {\r\n firstDate = round(firstDate, \"day\", 1);\r\n let difference = date.getTime() - firstDate.getTime();\r\n let unitCount = Math.floor(difference / getDuration(\"day\") / count);\r\n let duration = getDuration(\"day\", unitCount * count);\r\n date.setTime(firstDate.getTime() + duration - timeZoneOffset * getDuration(\"minute\"));\r\n }\r\n }\r\n else {\r\n date.setUTCDate(day);\r\n }\r\n date.setUTCHours(0, 0, 0, 0);\r\n break;\r\n case \"second\":\r\n let seconds = date.getUTCSeconds();\r\n if (count > 1) {\r\n seconds = Math.floor(seconds / count) * count;\r\n }\r\n date.setUTCSeconds(seconds, 0);\r\n break;\r\n case \"millisecond\":\r\n if (count == 1) {\r\n return date; // much better for perf!\r\n }\r\n let milliseconds = date.getUTCMilliseconds();\r\n milliseconds = Math.floor(milliseconds / count) * count;\r\n date.setUTCMilliseconds(milliseconds);\r\n break;\r\n case \"hour\":\r\n let hours = date.getUTCHours();\r\n if (count > 1) {\r\n hours = Math.floor(hours / count) * count;\r\n }\r\n date.setUTCHours(hours, 0, 0, 0);\r\n break;\r\n case \"minute\":\r\n let minutes = date.getUTCMinutes();\r\n if (count > 1) {\r\n minutes = Math.floor(minutes / count) * count;\r\n }\r\n date.setUTCMinutes(minutes, 0, 0);\r\n break;\r\n case \"month\":\r\n let month = date.getUTCMonth();\r\n if (count > 1) {\r\n month = Math.floor(month / count) * count;\r\n }\r\n date.setUTCMonth(month, 1);\r\n date.setUTCHours(0, 0, 0, 0);\r\n break;\r\n case \"year\":\r\n let year = date.getUTCFullYear();\r\n if (count > 1) {\r\n year = Math.floor(year / count) * count;\r\n }\r\n date.setUTCFullYear(year, 0, 1);\r\n date.setUTCHours(0, 0, 0, 0);\r\n break;\r\n case \"week\":\r\n if (count > 1) {\r\n if (firstDate) {\r\n firstDate = round(firstDate, \"week\", 1);\r\n let difference = date.getTime() - firstDate.getTime();\r\n let unitCount = Math.floor(difference / getDuration(\"week\") / count);\r\n let duration = getDuration(\"week\", unitCount * count);\r\n date.setTime(firstDate.getTime() + duration - timeZoneOffset * getDuration(\"minute\"));\r\n }\r\n }\r\n let wday = date.getUTCDate();\r\n let weekDay = date.getUTCDay();\r\n if (!$type.isNumber(firstDateOfWeek)) {\r\n firstDateOfWeek = 1;\r\n }\r\n if (weekDay >= firstDateOfWeek) {\r\n wday = wday - weekDay + firstDateOfWeek;\r\n }\r\n else {\r\n wday = wday - (7 + weekDay) + firstDateOfWeek;\r\n }\r\n date.setUTCDate(wday);\r\n date.setUTCHours(0, 0, 0, 0);\r\n break;\r\n }\r\n if (!utc && unit != \"millisecond\") {\r\n date.setUTCMinutes(date.getUTCMinutes() + timeZoneOffset);\r\n if (unit == \"day\" || unit == \"week\" || unit == \"month\" || unit == \"year\") {\r\n let newTimeZoneOffset = date.getTimezoneOffset();\r\n if (newTimeZoneOffset != timeZoneOffset) {\r\n let diff = newTimeZoneOffset - timeZoneOffset;\r\n date.setUTCMinutes(date.getUTCMinutes() + diff);\r\n }\r\n }\r\n }\r\n return date;\r\n }\r\n else {\r\n if (isNaN(date.getTime())) {\r\n return date;\r\n }\r\n let tzoffset = timezone.offsetUTC(date);\r\n let timeZoneOffset = date.getTimezoneOffset();\r\n let parsedDate = timezone.parseDate(date);\r\n let year = parsedDate.year;\r\n let month = parsedDate.month;\r\n let day = parsedDate.day;\r\n let hour = parsedDate.hour;\r\n let minute = parsedDate.minute;\r\n let second = parsedDate.second;\r\n let millisecond = parsedDate.millisecond;\r\n let weekday = parsedDate.weekday;\r\n let offsetDif = tzoffset - timeZoneOffset;\r\n switch (unit) {\r\n case \"day\":\r\n if (count > 1 && firstDate) {\r\n firstDate = round(firstDate, \"day\", 1, firstDateOfWeek, utc, undefined, timezone);\r\n let difference = date.getTime() - firstDate.getTime();\r\n let unitCount = Math.floor(difference / getDuration(\"day\") / count);\r\n let duration = getDuration(\"day\", unitCount * count);\r\n date.setTime(firstDate.getTime() + duration);\r\n parsedDate = timezone.parseDate(date);\r\n year = parsedDate.year;\r\n month = parsedDate.month;\r\n day = parsedDate.day;\r\n }\r\n hour = 0;\r\n minute = offsetDif;\r\n second = 0;\r\n millisecond = 0;\r\n break;\r\n case \"second\":\r\n minute += offsetDif;\r\n if (count > 1) {\r\n second = Math.floor(second / count) * count;\r\n }\r\n millisecond = 0;\r\n break;\r\n case \"millisecond\":\r\n minute += offsetDif;\r\n if (count > 1) {\r\n millisecond = Math.floor(millisecond / count) * count;\r\n }\r\n break;\r\n case \"hour\":\r\n if (count > 1) {\r\n hour = Math.floor(hour / count) * count;\r\n }\r\n minute = offsetDif;\r\n second = 0;\r\n millisecond = 0;\r\n break;\r\n case \"minute\":\r\n if (count > 1) {\r\n minute = Math.floor(minute / count) * count;\r\n }\r\n minute += offsetDif;\r\n second = 0;\r\n millisecond = 0;\r\n break;\r\n case \"month\":\r\n if (count > 1) {\r\n month = Math.floor(month / count) * count;\r\n }\r\n day = 1;\r\n hour = 0;\r\n minute = offsetDif;\r\n second = 0;\r\n millisecond = 0;\r\n break;\r\n case \"year\":\r\n if (count > 1) {\r\n year = Math.floor(year / count) * count;\r\n }\r\n month = 0;\r\n day = 1;\r\n hour = 0;\r\n minute = offsetDif;\r\n second = 0;\r\n millisecond = 0;\r\n break;\r\n case \"week\":\r\n if (!$type.isNumber(firstDateOfWeek)) {\r\n firstDateOfWeek = 1;\r\n }\r\n if (weekday >= firstDateOfWeek) {\r\n day = day - weekday + firstDateOfWeek;\r\n }\r\n else {\r\n day = day - (7 + weekday) + firstDateOfWeek;\r\n }\r\n hour = 0;\r\n minute = offsetDif;\r\n second = 0;\r\n millisecond = 0;\r\n break;\r\n }\r\n date = new Date(year, month, day, hour, minute, second, millisecond);\r\n let newTimeZoneOffset = date.getTimezoneOffset();\r\n let newTzoffset = timezone.offsetUTC(date);\r\n let newDiff = newTzoffset - newTimeZoneOffset;\r\n if (newDiff != offsetDif) {\r\n date.setTime(date.getTime() + (newDiff - offsetDif) * 60000);\r\n }\r\n return date;\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function chooseInterval(index, duration, gridCount, intervals) {\r\n let gridInterval = intervals[index];\r\n let intervalDuration = getIntervalDuration(gridInterval);\r\n let lastIndex = intervals.length - 1;\r\n if (index >= lastIndex) {\r\n return Object.assign({}, intervals[lastIndex]);\r\n }\r\n let count = Math.ceil(duration / intervalDuration);\r\n if (duration < intervalDuration && index > 0) {\r\n return Object.assign({}, intervals[index - 1]);\r\n }\r\n if (count <= gridCount) {\r\n return Object.assign({}, intervals[index]);\r\n }\r\n else {\r\n if (index + 1 < intervals.length) {\r\n return chooseInterval(index + 1, duration, gridCount, intervals);\r\n }\r\n else {\r\n return Object.assign({}, intervals[index]);\r\n }\r\n }\r\n}\r\n/**\r\n * @ignore\r\n */\r\nexport function getUnitValue(date, unit) {\r\n switch (unit) {\r\n case \"day\":\r\n return date.getDate();\r\n case \"second\":\r\n return date.getSeconds();\r\n case \"millisecond\":\r\n return date.getMilliseconds();\r\n case \"hour\":\r\n return date.getHours();\r\n case \"minute\":\r\n return date.getMinutes();\r\n case \"month\":\r\n return date.getMonth();\r\n case \"year\":\r\n return date.getFullYear();\r\n case \"week\":\r\n return $utils.getWeek(date);\r\n }\r\n}\r\n//# sourceMappingURL=Time.js.map","import { __awaiter } from \"tslib\";\r\nimport { Component } from \"../../core/render/Component\";\r\nimport { List } from \"../../core/util/List\";\r\nimport { Color } from \"../../core/util/Color\";\r\nimport { percentInterpolate } from \"../../core/util/Animation\";\r\nimport { Percent } from \"../../core/util/Percent\";\r\nimport { p100 } from \"../../core/util/Percent\";\r\nimport { Container } from \"../../core/render/Container\";\r\nimport { Label } from \"../../core/render/Label\";\r\n//import { Animations } from \"../../core/util/Animation\";\r\nimport * as $array from \"../../core/util/Array\";\r\nimport * as $type from \"../../core/util/Type\";\r\nimport * as $time from \"../../core/util/Time\";\r\n/**\r\n * A base class for all series.\r\n */\r\nexport class Series extends Component {\r\n constructor() {\r\n super(...arguments);\r\n Object.defineProperty(this, \"_aggregatesCalculated\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_selectionAggregatesCalculated\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_dataProcessed\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: false\r\n });\r\n Object.defineProperty(this, \"_psi\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n Object.defineProperty(this, \"_pei\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * A chart series belongs to.\r\n */\r\n Object.defineProperty(this, \"chart\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: void 0\r\n });\r\n /**\r\n * List of bullets to use for the series.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/bullets/} for more info\r\n */\r\n Object.defineProperty(this, \"bullets\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: new List()\r\n });\r\n /**\r\n * A [[Container]] series' bullets are stored in.\r\n *\r\n * @default Container.new()\r\n */\r\n Object.defineProperty(this, \"bulletsContainer\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Container.new(this._root, { width: p100, height: p100, position: \"absolute\" })\r\n });\r\n }\r\n _afterNew() {\r\n this.valueFields.push(\"value\", \"customValue\");\r\n super._afterNew();\r\n this.setPrivate(\"customData\", {});\r\n this._disposers.push(this.bullets.events.onAll((change) => {\r\n if (change.type === \"clear\") {\r\n this._handleBullets(this.dataItems);\r\n }\r\n else if (change.type === \"push\") {\r\n this._handleBullets(this.dataItems);\r\n }\r\n else if (change.type === \"setIndex\") {\r\n this._handleBullets(this.dataItems);\r\n }\r\n else if (change.type === \"insertIndex\") {\r\n this._handleBullets(this.dataItems);\r\n }\r\n else if (change.type === \"removeIndex\") {\r\n this._handleBullets(this.dataItems);\r\n }\r\n else if (change.type === \"moveIndex\") {\r\n this._handleBullets(this.dataItems);\r\n }\r\n else {\r\n throw new Error(\"Unknown IListEvent type\");\r\n }\r\n }));\r\n }\r\n _dispose() {\r\n this.bulletsContainer.dispose(); // can be in a different parent\r\n super._dispose();\r\n }\r\n startIndex() {\r\n let len = this.dataItems.length;\r\n return Math.min(this.getPrivate(\"startIndex\", 0), len);\r\n }\r\n endIndex() {\r\n let len = this.dataItems.length;\r\n return Math.min(this.getPrivate(\"endIndex\", len), len);\r\n }\r\n _handleBullets(dataItems) {\r\n $array.each(dataItems, (dataItem) => {\r\n const bullets = dataItem.bullets;\r\n if (bullets) {\r\n $array.each(bullets, (bullet) => {\r\n bullet.dispose();\r\n });\r\n dataItem.bullets = undefined;\r\n }\r\n });\r\n this.markDirtyValues();\r\n }\r\n /**\r\n * Looks up and returns a data item by its ID.\r\n *\r\n * @param id ID\r\n * @return Data item\r\n */\r\n getDataItemById(id) {\r\n return $array.find(this.dataItems, (dataItem) => {\r\n return dataItem.get(\"id\") == id;\r\n });\r\n }\r\n _makeBullets(dataItem) {\r\n if (this._shouldMakeBullet(dataItem)) {\r\n dataItem.bullets = [];\r\n this.bullets.each((bulletFunction) => {\r\n this._makeBullet(dataItem, bulletFunction);\r\n });\r\n }\r\n }\r\n _shouldMakeBullet(_dataItem) {\r\n return true;\r\n }\r\n _makeBullet(dataItem, bulletFunction, index) {\r\n const bullet = bulletFunction(this._root, this, dataItem);\r\n if (bullet) {\r\n bullet._index = index;\r\n this._makeBulletReal(dataItem, bullet);\r\n }\r\n return bullet;\r\n }\r\n _makeBulletReal(dataItem, bullet) {\r\n let sprite = bullet.get(\"sprite\");\r\n if (sprite) {\r\n sprite._setDataItem(dataItem);\r\n sprite.setRaw(\"position\", \"absolute\");\r\n this.bulletsContainer.children.push(sprite);\r\n }\r\n bullet.series = this;\r\n dataItem.bullets.push(bullet);\r\n }\r\n /**\r\n * Adds bullet directly to a data item.\r\n *\r\n * Please note: method accepts [[Bullet]] instance as a paramter, not a\r\n * reference to a function.\r\n *\r\n * You should add Bullet instance, not a method like you do it on series.\r\n *\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/common-elements/bullets/#Adding_directly_to_data_item} for more info\r\n * @since 5.6.0\r\n *\r\n * @param dataItem Target data item\r\n * @param bullet Bullet instance\r\n */\r\n addBullet(dataItem, bullet) {\r\n if (!dataItem.bullets) {\r\n dataItem.bullets = [];\r\n }\r\n if (bullet) {\r\n this._makeBulletReal(dataItem, bullet);\r\n }\r\n }\r\n _clearDirty() {\r\n super._clearDirty();\r\n this._aggregatesCalculated = false;\r\n this._selectionAggregatesCalculated = false;\r\n }\r\n _prepareChildren() {\r\n super._prepareChildren();\r\n let startIndex = this.startIndex();\r\n let endIndex = this.endIndex();\r\n if (this.isDirty(\"name\")) {\r\n this.updateLegendValue();\r\n }\r\n if (this.isDirty(\"heatRules\")) {\r\n this._valuesDirty = true;\r\n }\r\n if (this.isPrivateDirty(\"baseValueSeries\")) {\r\n const baseValueSeries = this.getPrivate(\"baseValueSeries\");\r\n if (baseValueSeries) {\r\n this._disposers.push(baseValueSeries.onPrivate(\"startIndex\", () => {\r\n this.markDirtyValues();\r\n }));\r\n }\r\n }\r\n const calculateAggregates = this.get(\"calculateAggregates\");\r\n if (calculateAggregates) {\r\n if (this._valuesDirty && !this._dataProcessed) {\r\n if (!this._aggregatesCalculated) {\r\n this._calculateAggregates(0, this.dataItems.length);\r\n this._aggregatesCalculated = true;\r\n if (startIndex != 0) {\r\n this._psi = undefined;\r\n }\r\n }\r\n }\r\n if ((this._psi != startIndex || this._pei != endIndex || this.isPrivateDirty(\"adjustedStartIndex\")) && !this._selectionAggregatesCalculated) {\r\n if (startIndex === 0 && endIndex === this.dataItems.length && this._aggregatesCalculated) {\r\n // void\r\n }\r\n else {\r\n this._calculateAggregates(startIndex, endIndex);\r\n }\r\n this._selectionAggregatesCalculated = true;\r\n }\r\n }\r\n if (this.isDirty(\"tooltip\")) {\r\n let tooltip = this.get(\"tooltip\");\r\n if (tooltip) {\r\n tooltip.hide(0);\r\n tooltip.set(\"tooltipTarget\", this);\r\n }\r\n }\r\n if (this.isDirty(\"fill\") || this.isDirty(\"stroke\")) {\r\n let markerRectangle;\r\n const legendDataItem = this.get(\"legendDataItem\");\r\n if (legendDataItem) {\r\n markerRectangle = legendDataItem.get(\"markerRectangle\");\r\n if (markerRectangle) {\r\n if (this.isVisible()) {\r\n if (this.isDirty(\"stroke\")) {\r\n let stroke = this.get(\"stroke\");\r\n markerRectangle.set(\"stroke\", stroke);\r\n }\r\n if (this.isDirty(\"fill\")) {\r\n let fill = this.get(\"fill\");\r\n markerRectangle.set(\"fill\", fill);\r\n }\r\n }\r\n }\r\n }\r\n this.updateLegendMarker(undefined);\r\n }\r\n if (this.bullets.length > 0) {\r\n let startIndex = this.startIndex();\r\n let endIndex = this.endIndex();\r\n if (endIndex < this.dataItems.length) {\r\n endIndex++;\r\n }\r\n for (let i = startIndex; i < endIndex; i++) {\r\n let dataItem = this.dataItems[i];\r\n if (!dataItem.bullets) {\r\n this._makeBullets(dataItem);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n _adjustStartIndex(index) {\r\n return index;\r\n }\r\n _calculateAggregates(startIndex, endIndex) {\r\n let fields = this._valueFields;\r\n if (!fields) {\r\n throw new Error(\"No value fields are set for the series.\");\r\n }\r\n const sum = {};\r\n const absSum = {};\r\n const count = {};\r\n const low = {};\r\n const high = {};\r\n const open = {};\r\n const close = {};\r\n const average = {};\r\n const previous = {};\r\n $array.each(fields, (key) => {\r\n sum[key] = 0;\r\n absSum[key] = 0;\r\n count[key] = 0;\r\n });\r\n $array.each(fields, (key) => {\r\n let change = key + \"Change\";\r\n let changePercent = key + \"ChangePercent\";\r\n let changePrevious = key + \"ChangePrevious\";\r\n let changePreviousPercent = key + \"ChangePreviousPercent\";\r\n let changeSelection = key + \"ChangeSelection\";\r\n let changeSelectionPercent = key + \"ChangeSelectionPercent\";\r\n let openKey = \"valueY\";\r\n if (key == \"valueX\" || key == \"openValueX\" || key == \"lowValueX\" || key == \"highValueX\") {\r\n openKey = \"valueX\";\r\n }\r\n const baseValueSeries = this.getPrivate(\"baseValueSeries\");\r\n const adjustedStartIndex = this.getPrivate(\"adjustedStartIndex\", startIndex);\r\n for (let i = adjustedStartIndex; i < endIndex; i++) {\r\n const dataItem = this.dataItems[i];\r\n if (dataItem) {\r\n let value = dataItem.get(key);\r\n if (value != null) {\r\n count[key]++;\r\n sum[key] += value;\r\n absSum[key] += Math.abs(value);\r\n average[key] = sum[key] / count[key];\r\n if (low[key] > value || low[key] == null) {\r\n low[key] = value;\r\n }\r\n if (high[key] < value || high[key] == null) {\r\n high[key] = value;\r\n }\r\n close[key] = value;\r\n if (open[key] == null) {\r\n open[key] = value;\r\n previous[key] = value;\r\n if (baseValueSeries) {\r\n open[openKey] = baseValueSeries._getBase(openKey);\r\n }\r\n }\r\n if (startIndex === 0) {\r\n dataItem.setRaw((change), value - open[openKey]);\r\n dataItem.setRaw((changePercent), (value - open[openKey]) / open[openKey] * 100);\r\n }\r\n dataItem.setRaw((changePrevious), value - previous[openKey]);\r\n dataItem.setRaw((changePreviousPercent), (value - previous[openKey]) / previous[openKey] * 100);\r\n dataItem.setRaw((changeSelection), value - open[openKey]);\r\n dataItem.setRaw((changeSelectionPercent), (value - open[openKey]) / open[openKey] * 100);\r\n previous[key] = value;\r\n }\r\n }\r\n }\r\n if (endIndex < this.dataItems.length - 1) {\r\n const dataItem = this.dataItems[endIndex];\r\n if (dataItem) {\r\n let value = dataItem.get(key);\r\n dataItem.setRaw((changePrevious), value - previous[openKey]);\r\n dataItem.setRaw((changePreviousPercent), (value - previous[openKey]) / previous[openKey] * 100);\r\n dataItem.setRaw((changeSelection), value - open[openKey]);\r\n dataItem.setRaw((changeSelectionPercent), (value - open[openKey]) / open[openKey] * 100);\r\n }\r\n }\r\n if (startIndex > 0) {\r\n startIndex--;\r\n }\r\n delete previous[key];\r\n for (let i = startIndex; i < adjustedStartIndex; i++) {\r\n const dataItem = this.dataItems[i];\r\n if (dataItem) {\r\n let value = dataItem.get(key);\r\n if (previous[key] == null) {\r\n previous[key] = value;\r\n }\r\n if (value != null) {\r\n dataItem.setRaw((changePrevious), value - previous[openKey]);\r\n dataItem.setRaw((changePreviousPercent), (value - previous[openKey]) / previous[openKey] * 100);\r\n dataItem.setRaw((changeSelection), value - open[openKey]);\r\n dataItem.setRaw((changeSelectionPercent), (value - open[openKey]) / open[openKey] * 100);\r\n previous[key] = value;\r\n }\r\n }\r\n }\r\n });\r\n $array.each(fields, (key) => {\r\n this.setPrivate((key + \"AverageSelection\"), average[key]);\r\n this.setPrivate((key + \"CountSelection\"), count[key]);\r\n this.setPrivate((key + \"SumSelection\"), sum[key]);\r\n this.setPrivate((key + \"AbsoluteSumSelection\"), absSum[key]);\r\n this.setPrivate((key + \"LowSelection\"), low[key]);\r\n this.setPrivate((key + \"HighSelection\"), high[key]);\r\n this.setPrivate((key + \"OpenSelection\"), open[key]);\r\n this.setPrivate((key + \"CloseSelection\"), close[key]);\r\n });\r\n if (startIndex === 0 && endIndex === this.dataItems.length) {\r\n $array.each(fields, (key) => {\r\n this.setPrivate((key + \"Average\"), average[key]);\r\n this.setPrivate((key + \"Count\"), count[key]);\r\n this.setPrivate((key + \"Sum\"), sum[key]);\r\n this.setPrivate((key + \"AbsoluteSum\"), absSum[key]);\r\n this.setPrivate((key + \"Low\"), low[key]);\r\n this.setPrivate((key + \"High\"), high[key]);\r\n this.setPrivate((key + \"Open\"), open[key]);\r\n this.setPrivate((key + \"Close\"), close[key]);\r\n });\r\n }\r\n }\r\n _updateChildren() {\r\n super._updateChildren();\r\n this._psi = this.startIndex();\r\n this._pei = this.endIndex();\r\n if (this.isDirty(\"visible\")) {\r\n this.bulletsContainer.set(\"visible\", this.get(\"visible\"));\r\n }\r\n // Apply heat rules\r\n const rules = this.get(\"heatRules\");\r\n if (this._valuesDirty && rules && rules.length > 0) {\r\n $array.each(rules, (rule) => {\r\n const minValue = rule.minValue || this.getPrivate((rule.dataField + \"Low\")) || 0;\r\n const maxValue = rule.maxValue || this.getPrivate((rule.dataField + \"High\")) || 0;\r\n $array.each(rule.target._entities, (target) => {\r\n const value = target.dataItem.get(rule.dataField);\r\n if (!$type.isNumber(value)) {\r\n if (rule.neutral) {\r\n target.set(rule.key, rule.neutral);\r\n }\r\n const states = target.states;\r\n if (states) {\r\n const defaultState = states.lookup(\"default\");\r\n if (defaultState && rule.neutral) {\r\n defaultState.set(rule.key, rule.neutral);\r\n }\r\n }\r\n if (!rule.customFunction) {\r\n return;\r\n }\r\n }\r\n if (rule.customFunction) {\r\n rule.customFunction.call(this, target, minValue, maxValue, value);\r\n }\r\n else {\r\n let percent;\r\n if (rule.logarithmic) {\r\n percent = (Math.log(value) * Math.LOG10E - Math.log(minValue) * Math.LOG10E) / ((Math.log(maxValue) * Math.LOG10E - Math.log(minValue) * Math.LOG10E));\r\n }\r\n else {\r\n percent = (value - minValue) / (maxValue - minValue);\r\n }\r\n if ($type.isNumber(value) && (!$type.isNumber(percent) || Math.abs(percent) == Infinity)) {\r\n percent = 0.5;\r\n }\r\n // fixes problems if all values are the same\r\n let propertyValue;\r\n if ($type.isNumber(rule.min)) {\r\n propertyValue = rule.min + (rule.max - rule.min) * percent;\r\n }\r\n else if (rule.min instanceof Color) {\r\n propertyValue = Color.interpolate(percent, rule.min, rule.max);\r\n }\r\n else if (rule.min instanceof Percent) {\r\n propertyValue = percentInterpolate(percent, rule.min, rule.max);\r\n }\r\n target.set(rule.key, propertyValue);\r\n const states = target.states;\r\n if (states) {\r\n const defaultState = states.lookup(\"default\");\r\n if (defaultState) {\r\n defaultState.set(rule.key, propertyValue);\r\n }\r\n }\r\n }\r\n });\r\n });\r\n }\r\n if (this.get(\"visible\")) {\r\n let count = this.dataItems.length;\r\n let startIndex = this.startIndex();\r\n let endIndex = this.endIndex();\r\n if (endIndex < count) {\r\n endIndex++;\r\n }\r\n if (startIndex > 0) {\r\n startIndex--;\r\n }\r\n for (let i = 0; i < startIndex; i++) {\r\n this._hideBullets(this.dataItems[i]);\r\n }\r\n for (let i = startIndex; i < endIndex; i++) {\r\n this._positionBullets(this.dataItems[i]);\r\n }\r\n for (let i = endIndex; i < count; i++) {\r\n this._hideBullets(this.dataItems[i]);\r\n }\r\n }\r\n }\r\n _positionBullets(dataItem) {\r\n if (dataItem.bullets) {\r\n $array.each(dataItem.bullets, (bullet) => {\r\n this._positionBullet(bullet);\r\n const sprite = bullet.get(\"sprite\");\r\n if (bullet.get(\"dynamic\")) {\r\n if (sprite) {\r\n sprite._markDirtyKey(\"fill\");\r\n sprite.markDirtySize();\r\n }\r\n if (sprite instanceof Container) {\r\n sprite.walkChildren((child) => {\r\n child._markDirtyKey(\"fill\");\r\n child.markDirtySize();\r\n if (child instanceof Label) {\r\n child.text.markDirtyText();\r\n }\r\n });\r\n }\r\n }\r\n if (sprite instanceof Label && sprite.get(\"populateText\")) {\r\n sprite.text.markDirtyText();\r\n }\r\n });\r\n }\r\n }\r\n _hideBullets(dataItem) {\r\n if (dataItem.bullets) {\r\n $array.each(dataItem.bullets, (bullet) => {\r\n let sprite = bullet.get(\"sprite\");\r\n if (sprite) {\r\n sprite.setPrivate(\"visible\", false);\r\n }\r\n });\r\n }\r\n }\r\n _positionBullet(_bullet) {\r\n }\r\n _placeBulletsContainer(chart) {\r\n chart.bulletsContainer.children.moveValue(this.bulletsContainer);\r\n }\r\n _removeBulletsContainer() {\r\n const bulletsContainer = this.bulletsContainer;\r\n if (bulletsContainer.parent) {\r\n bulletsContainer.parent.children.removeValue(bulletsContainer);\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n disposeDataItem(dataItem) {\r\n //super.disposeDataItem(dataItem); // does nothing\r\n const bullets = dataItem.bullets;\r\n if (bullets) {\r\n $array.each(bullets, (bullet) => {\r\n bullet.dispose();\r\n });\r\n }\r\n }\r\n _getItemReaderLabel() {\r\n return \"\";\r\n }\r\n /**\r\n * Shows series's data item.\r\n *\r\n * @param dataItem Data item\r\n * @param duration Animation duration in milliseconds\r\n * @return Promise\r\n */\r\n showDataItem(dataItem, duration) {\r\n const _super = Object.create(null, {\r\n showDataItem: { get: () => super.showDataItem }\r\n });\r\n return __awaiter(this, void 0, void 0, function* () {\r\n const promises = [_super.showDataItem.call(this, dataItem, duration)];\r\n const bullets = dataItem.bullets;\r\n if (bullets) {\r\n $array.each(bullets, (bullet) => {\r\n const sprite = bullet.get(\"sprite\");\r\n if (sprite) {\r\n promises.push(sprite.show(duration));\r\n }\r\n });\r\n }\r\n yield Promise.all(promises);\r\n });\r\n }\r\n /**\r\n * Hides series's data item.\r\n *\r\n * @param dataItem Data item\r\n * @param duration Animation duration in milliseconds\r\n * @return Promise\r\n */\r\n hideDataItem(dataItem, duration) {\r\n const _super = Object.create(null, {\r\n hideDataItem: { get: () => super.hideDataItem }\r\n });\r\n return __awaiter(this, void 0, void 0, function* () {\r\n const promises = [_super.hideDataItem.call(this, dataItem, duration)];\r\n const bullets = dataItem.bullets;\r\n if (bullets) {\r\n $array.each(bullets, (bullet) => {\r\n const sprite = bullet.get(\"sprite\");\r\n if (sprite) {\r\n promises.push(sprite.hide(duration));\r\n }\r\n });\r\n }\r\n yield Promise.all(promises);\r\n });\r\n }\r\n _sequencedShowHide(show, duration) {\r\n return __awaiter(this, void 0, void 0, function* () {\r\n if (this.get(\"sequencedInterpolation\")) {\r\n if (!$type.isNumber(duration)) {\r\n duration = this.get(\"interpolationDuration\", 0);\r\n }\r\n if (duration > 0) {\r\n const startIndex = this.startIndex();\r\n const endIndex = this.endIndex();\r\n yield Promise.all($array.map(this.dataItems, (dataItem, i) => __awaiter(this, void 0, void 0, function* () {\r\n let realDuration = duration || 0;\r\n if (i < startIndex - 10 || i > endIndex + 10) {\r\n realDuration = 0;\r\n }\r\n //let delay = this.get(\"sequencedDelay\", 0) * i + realDuration * (i - startIndex) / (endIndex - startIndex);\r\n let delay = this.get(\"sequencedDelay\", 0) + realDuration / (endIndex - startIndex);\r\n yield $time.sleep(delay * (i - startIndex));\r\n if (show) {\r\n yield this.showDataItem(dataItem, realDuration);\r\n }\r\n else {\r\n yield this.hideDataItem(dataItem, realDuration);\r\n }\r\n })));\r\n }\r\n else {\r\n yield Promise.all($array.map(this.dataItems, (dataItem) => {\r\n if (show) {\r\n return this.showDataItem(dataItem, 0);\r\n }\r\n else {\r\n return this.hideDataItem(dataItem, 0);\r\n }\r\n }));\r\n }\r\n }\r\n });\r\n }\r\n /**\r\n * @ignore\r\n */\r\n updateLegendValue(dataItem) {\r\n if (dataItem) {\r\n const legendDataItem = dataItem.get(\"legendDataItem\");\r\n if (legendDataItem) {\r\n const valueLabel = legendDataItem.get(\"valueLabel\");\r\n if (valueLabel) {\r\n const text = valueLabel.text;\r\n let txt = \"\";\r\n valueLabel._setDataItem(dataItem);\r\n txt = this.get(\"legendValueText\", text.get(\"text\", \"\"));\r\n valueLabel.set(\"text\", txt);\r\n text.markDirtyText();\r\n }\r\n const label = legendDataItem.get(\"label\");\r\n if (label) {\r\n const text = label.text;\r\n let txt = \"\";\r\n label._setDataItem(dataItem);\r\n txt = this.get(\"legendLabelText\", text.get(\"text\", \"\"));\r\n label.set(\"text\", txt);\r\n text.markDirtyText();\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n updateLegendMarker(_dataItem) {\r\n }\r\n _onHide() {\r\n super._onHide();\r\n const tooltip = this.getTooltip();\r\n if (tooltip) {\r\n tooltip.hide();\r\n }\r\n }\r\n /**\r\n * @ignore\r\n */\r\n hoverDataItem(_dataItem) { }\r\n /**\r\n * @ignore\r\n */\r\n unhoverDataItem(_dataItem) { }\r\n /**\r\n * @ignore\r\n */\r\n _getBase(key) {\r\n const dataItem = this.dataItems[this.startIndex()];\r\n if (dataItem) {\r\n return dataItem.get(key);\r\n }\r\n return 0;\r\n }\r\n}\r\nObject.defineProperty(Series, \"className\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: \"Series\"\r\n});\r\nObject.defineProperty(Series, \"classNames\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: Component.classNames.concat([Series.className])\r\n});\r\n//# sourceMappingURL=Series.js.map","import { Series } from \"./Series\";\r\nimport { Container } from \"../../core/render/Container\";\r\nimport { Label } from \"../../core/render/Label\";\r\nimport { RoundedRectangle } from \"../../core/render/RoundedRectangle\";\r\nimport { Template } from \"../../core/util/Template\";\r\nimport { ListTemplate } from \"../../core/util/List\";\r\nimport * as $utils from \"../../core/util/Utils\";\r\n/**\r\n * A universal legend control.\r\n *\r\n * @important\r\n * @see {@link https://www.amcharts.com/docs/v5/concepts/legend/} for more info\r\n */\r\nexport class Legend extends Series {\r\n constructor() {\r\n super(...arguments);\r\n /**\r\n * List of all [[Container]] elements for legend items.\r\n *\r\n * @default new ListTemplate\r\n */\r\n Object.defineProperty(this, \"itemContainers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this.addDisposer(new ListTemplate(Template.new({}), () => Container._new(this._root, {\r\n themeTags: $utils.mergeTags(this.itemContainers.template.get(\"themeTags\", []), [\"legend\", \"item\"]),\r\n themeTagsSelf: $utils.mergeTags(this.itemContainers.template.get(\"themeTagsSelf\", []), [\"itemcontainer\"]),\r\n background: RoundedRectangle.new(this._root, {\r\n themeTags: $utils.mergeTags(this.itemContainers.template.get(\"themeTags\", []), [\"legend\", \"item\", \"background\"]),\r\n themeTagsSelf: $utils.mergeTags(this.itemContainers.template.get(\"themeTagsSelf\", []), [\"itemcontainer\"])\r\n })\r\n }, [this.itemContainers.template])))\r\n });\r\n /**\r\n * List of legend marker elements.\r\n *\r\n * @default new ListTemplate\r\n */\r\n Object.defineProperty(this, \"markers\", {\r\n enumerable: true,\r\n configurable: true,\r\n writable: true,\r\n value: this.addDisposer(new ListTemplate(Template.new({}), () => Container._new(this._root, {\r\n themeTags: $utils.mergeTags(this.markers.template.get(\"themeTags\", []), [\"legend\", \"marker\"])\r\n }, [this.markers.template])))\r\n });\r\n /**\r\n * List of legend label elements.\r\n *\r\n * @default new ListTemplate