UNPKG

igniteui-react-core

Version:
957 lines (956 loc) 31.2 kB
/* THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE: https://www.infragistics.com/legal/license/igultimate-la https://www.infragistics.com/legal/license/igultimate-eula GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company. */ import { Base, runOn, Delegate_$type, markType, typeCast, INotifyPropertyChanged_$type, PropertyChangedEventArgs, EventArgs, Point_$type, markDep } from "./type"; import { ISchedulableRender_$type } from "./ISchedulableRender"; import { List$1 } from "./List$1"; import { Image } from "./Image"; import { RenderingContext } from "./RenderingContext"; import { Dictionary$2 } from "./Dictionary$2"; import { Tile } from "./Tile"; import { Rect } from "./Rect"; import { CanvasRenderScheduler } from "./CanvasRenderScheduler"; import { StackPool$1 } from "./StackPool$1"; import { WriteableBitmap } from "./WriteableBitmap"; import { Uri } from "./Uri"; import { CancellingMultiScaleImageEventArgs } from "./CancellingMultiScaleImageEventArgs"; import { DownloadingMultiScaleImageEventArgs } from "./DownloadingMultiScaleImageEventArgs"; import { CanvasViewRenderer } from "./CanvasViewRenderer"; import { truncate, intDivide, logBase } from "./number"; import { DependencyObject } from "./DependencyObject"; import { Control } from "./Control"; import { DependencyProperty } from "./DependencyProperty"; import { IEasingFunction_$type } from "./IEasingFunction"; import { LRUCache$2 } from "./LRUCache$2"; import { TilePositionComparer } from "./TilePositionComparer"; import { Convert } from "./Convert"; import { MathUtil } from "./MathUtil"; import { PropertyMetadata } from "./PropertyMetadata"; import { stringIsNullOrEmpty } from "./string"; import { dateNow } from "./date"; /** * @hidden */ export let XamMultiScaleImageView = /*@__PURE__*/ (() => { class XamMultiScaleImageView extends Base { constructor(a) { super(); this.b = null; this.h = null; this.g = new Dictionary$2(Base.$, List$1.$.specialize(Delegate_$type), 0); this.j = new List$1(Tile.$, 0); this.i = new List$1(Tile.$, 0); this.p = -1; this.o = -1; this.k = null; this.m = null; this.c = null; this._isDirty = false; this.au = Rect.empty; this.l = null; this.b = a; this.b.ag.o(this); this.h = new List$1(Image.$, 0); this.b.ap = ((() => { let $ret = new StackPool$1(Image.$); $ret.j = runOn(this, this.at); $ret.b = runOn(this, this.y); $ret.c = runOn(this, this.aa); $ret.d = runOn(this, this.z); return $ret; })()); for (let b = 0; b < 4; ++b) { this.i.add(null); } } at() { return new Image(); } y(a) { this.h.add(a); } aa(a) { this.h.remove(a); } z(a) { } ao(a, b, c) { a.n = b; a.o = c; } r(a) { for (let b = 0; b < this.i.count; ++b) { if (a == this.i._inner[b]) { if (a.i != null && a.i.ac != null) { let c = a.i.ac; let d = c.c; let e = this.b.ao.w(a.f + 8, a.d, a.e); if (e != null) { let f = ((() => { let $ret = new CancellingMultiScaleImageEventArgs(); $ret.uri = e.value; $ret.image = d; return $ret; })()); this.b.bu(f); } if (this.g.containsKey(d)) { let g = this.g.item(d); for (let h = 0; h < g.count; h++) { g._inner[h](); } g.clear(); this.g.removeItem(d); } } this.i._inner[b] = null; this.q(); return; } } for (let i = 0; i < this.j.count; ++i) { if (this.j._inner[i] == a) { this.j.removeAt(i); break; } } } u(a) { this.j.add(a); this.j.aa((b, c) => { let d = 0; let e = 0; if (b.h != null) { d = b.h.ac.b; } if (c.h != null) { e = c.h.ac.b; } if (d < e) { return -1; } else if (d > e) { return 1; } return 0; }); this.q(); } q() { let index_ = -1; if (this.l == null) { return; } if (this.j.count > 0) { for (let a = 0; a < this.i.count; ++a) { if (this.i._inner[a] == null) { index_ = a; break; } } } if (index_ >= 0) { this.i._inner[index_] = this.j._inner[0]; let b = new WriteableBitmap(this.b.ao.r, this.b.ao.p); this.i._inner[index_].i.ac = b; let ele_ = this.l.createElement("img"); let c = ele_.getNativeElement(); b.c = c; let self_ = this; let d = new List$1(Delegate_$type, 0); this.g.addItem(c, d); d.add(ele_.listen("load", (e) => this.ab(e, index_))); d.add(ele_.listen("readystatechange", (e) => this.ab(e, index_))); d.add(ele_.listen("error", (e) => this.ac(e, index_))); this.j.removeAt(0); let e = this.b.ao.w(this.i._inner[index_].f + 8, this.i._inner[index_].d, this.i._inner[index_].e); if (e == null) { return; } let f = e.value; let g = ((() => { let $ret = new DownloadingMultiScaleImageEventArgs(); $ret.uri = f; $ret.image = c; return $ret; })()); this.b.bv(g); f = g.uri; if (f != null) { c.src = f; } } } ab(a, b) { let e_ = a.originalEvent; let img_ = (e_.target); let c = (img_.complete || (img_.readyState == 'complete' && e_.type == 'readystatechange')); if (c) { this.downloadCompleted(a, b); } } ac(a, b) { this.downloadError(a, b); } downloadError(a, b) { let c = this.i._inner[b]; this.i._inner[b] = null; if (c != null && c.i != null && c.i.ac != null) { let e_ = a.originalEvent; let d = (e_.target); if (this.g.containsKey(d)) { let e = this.g.item(d); for (let f = 0; f < e.count; f++) { e._inner[f](); } e.clear(); this.g.removeItem(d); } } this.q(); this.ad(); } downloadCompleted(a, b) { let c = this.i._inner[b]; let d = true; if (c != null && c.i != null && c.i.ac != null) { d = false; let ele_ = c.i.ac.c; if (!ele_.complete) { d = true; } if ((ele_.width == 0 && ele_.height == 0)) { d = true; } } this.i._inner[b] = null; if (d) { this.q(); this.ad(); return; } let e_ = a.originalEvent; let e = (e_.target); if (this.g.containsKey(e)) { let f = this.g.item(e); for (let g = 0; g < f.count; g++) { f._inner[g](); } f.clear(); this.g.removeItem(e); } this.b.bo(c, c.i.ac); if (c.i != null) { this.b.ca(c); } this.q(); this.ad(); } a(a, b, c, d) { let e = new WriteableBitmap(a, a); e.c = b.c; if (!b.d.isEmpty) { c += truncate(Math.round(b.d.left)); d += truncate(Math.round(b.d.top)); } e.d = new Rect(0, c, d, a, a); return e; } am(a) { a.s = 0; } an(a) { a.s = 1; } f() { return true; } s(a) { if (this.b.al != null) { this.b.al.deferredRefresh(); } else { if (this.k != null) { this.k.setTimeout(a, 0); } else { window.setTimeout(a, 0); } } } aq() { if (this.p == -1) { this.p = window.setInterval(runOn(this.b, this.b.b9), 50); } } as() { if (this.p != -1) { window.clearInterval(this.p); this.p = -1; } } ap() { if (this.o == -1) { this.o = window.setInterval(runOn(this.b, this.b.br), 50); } } ar() { if (this.o != -1) { window.clearInterval(this.o); this.o = -1; } } t() { if (this.p != -1) { this.ar(); this.b.by(); } } ae(a) { this.k = a; this.k.rootWrapper.setStyleProperty("position", "relative"); this.m = this.k.createElement("canvas"); this.m.setStyleProperty("position", "absolute"); this.m.setStyleProperty("top", "0px"); this.m.setStyleProperty("left", "0px"); this.k.append(this.m); this.c = new RenderingContext(new CanvasViewRenderer(), this.k.get2DCanvasContext(this.m)); this.af(this.k.rootWrapper.width(), this.k.rootWrapper.height()); } af(a, b) { this.m.setAttribute("width", truncate((a * this.b.a4)).toString()); this.m.setAttribute("height", truncate((b * this.b.a4)).toString()); this.m.setStyleProperty("width", a.toString() + "px"); this.m.setStyleProperty("height", b.toString() + "px"); this.b.cn = new Rect(0, 0, 0, a, b); this.b.b5(); } aj() { this.ad(); } get index() { return 0; } postRender() { } get isDirty() { return this._isDirty; } set isDirty(a) { this._isDirty = a; } ad() { if (this.c == null) { return; } if (!this.isDirty) { this.isDirty = true; this.b.ag.q(); } } undirty(a) { this.isDirty = false; this.ak(); } ak() { if (this.c == null) { return; } if (this.c.d && this.b.a4 != 1) { this.c.aa(); this.c.ab(this.b.a4, this.b.a4); } if (!this.au.isEmpty) { this.c.l(this.au.left, this.au.top, this.au.width, this.au.height); } this.au = this.b.cn; for (let a = 0; a < this.h.count; a++) { let b = this.h._inner[a]; if (b.s == 0) { this.al(b); } } for (let c = 0; c < this.h.count; c++) { let d = this.h._inner[c]; if (d.s == 1) { this.al(d); } } if (this.c.d && this.b.a4 != 1) { this.c.z(); } this.b.bt(); this.b.bw(); } d() { let a = true; for (let b = 0; b < this.i.count; b++) { if (this.i._inner[b] != null) { a = false; } } return a; } al(a) { if (this.c == null) { return; } let b = a.ac; let c = a._opacity * this.b._opacity; if (b == null || b.c == null) { return; } if (this.e(b.c)) { return; } if (!b.d.isEmpty) { if (b.d.width < 1 || b.d.height < 1) { return; } this.c.o(b.c, c, b.d.left, b.d.top, b.d.width, b.d.height, Math.round(a.n + this.b.cn.left), Math.round(a.o + this.b.cn.top), a.width, a.height); } else { this.c.n(b.c, c, Math.round(a.n + this.b.cn.left), Math.round(a.o + this.b.cn.top), a.width, a.height); } } e(a) { let img_ = a; if (!img_.complete) { return true; } if ((img_.width == 0 && img_.height == 0)) { return true; } return false; } x() { this.ad(); } ag(a) { this.c = a; this.ad(); } ah(a) { this.l = a; this.q(); } ai(a) { this.b.cn = a; this.b.b5(); } preRender() { } isValid() { return true; } } XamMultiScaleImageView.$t = /*@__PURE__*/ markType(XamMultiScaleImageView, 'XamMultiScaleImageView', Base.$, [ISchedulableRender_$type]); return XamMultiScaleImageView; })(); /** * @hidden */ export let XamMultiScaleTileSource = /*@__PURE__*/ (() => { class XamMultiScaleTileSource extends DependencyObject { constructor(a, b, c, d, e) { super(); this.t = 0; this.s = 0; this.n = 1; this.l = false; this.r = 0; this.p = 0; this.q = 0; this.j = null; this.t = a; this.s = b; this.r = c; this.p = d; this.q = e; } get v() { return this.t; } set v(a) { this.t = a; this.y(0, 0, 0, 0); } get u() { return this.s; } set u(a) { this.s = a; this.y(0, 0, 0, 0); } get o() { return this.n; } set o(a) { this.n = a; if (this.k != null) { this.k._opacity = this.n; } } get m() { return this.l; } set m(a) { this.l = a; if (this.k != null) { this.k.av = this.l; } } get k() { return this.j; } set k(a) { this.j = a; if (this.j != null) { this.j._opacity = this.o; } } w(a, b, c) { let d = new List$1(Base.$, 0); this.x(a, b, c, d); let e = null; if (d.count > 0) { e = typeCast(Uri.$, d._inner[0]); } return e; } y(a, b, c, d) { if (this.k != null) { this.k.bs(a, b, c, d); } } } XamMultiScaleTileSource.$t = /*@__PURE__*/ markType(XamMultiScaleTileSource, 'XamMultiScaleTileSource', DependencyObject.$); return XamMultiScaleTileSource; })(); /** * @hidden */ export let XamMultiScaleImage = /*@__PURE__*/ (() => { class XamMultiScaleImage extends Control { constructor() { super(); this.ap = null; this.an = null; this.ak = null; this.ck = null; this.a2 = 0; this.at = false; this.propertyChanged = null; this.ba = 0; this.bb = 0; this.a0 = new Date(); this.cl = null; this.a3 = 0; this.ay = new List$1(Tile.$, 0); this.aw = false; this.aq = new LRUCache$2(Tile.$, WriteableBitmap.$, 1, 0x7FFFFFFF, new TilePositionComparer()); this.az = new List$1(Tile.$, 0); this.imageTilesReady = null; this.as = false; this.cn = null; this.ag = null; this.imagesChanged = null; this.downloadingImage = null; this.cancellingImage = null; this.a1 = 1; this.cn = Rect.empty; this.ag = new CanvasRenderScheduler(); this.an = new XamMultiScaleImageView(this); this.ab = XamMultiScaleImage.$; this.ck = this.cm; this.a2 = this.a5; } get al() { return this.ak; } set al(a) { if (this.ak != null) { this.ak.unRegister(this); } this.ak = a; if (this.ak != null) { this.ak.register(this, runOn(this, this.b6)); } } bc() { if (!stringIsNullOrEmpty(this.bf)) { return this.bf; } return null; } bd() { if (!stringIsNullOrEmpty(this.bj)) { return this.bj; } return null; } bx(a, b, c) { let d = new PropertyChangedEventArgs(a); if (this.propertyChanged != null) { this.propertyChanged(this, d); } switch (a) { case XamMultiScaleImage.$$p[2]: if (this.ao != null) { this.ao.k = this; } this.b4(); this.b7(); this.b5(); break; case XamMultiScaleImage.$$p[6]: this.b8(); break; case XamMultiScaleImage.$$p[7]: this.b8(); break; case XamMultiScaleImage.$$p[4]: if (!this.ax) { this.an.t(); } break; case XamMultiScaleImage.$$p[0]: this.at = this.av; this.b5(); break; } } v() { super.v(); this.b5(); } b7() { this.cb(); if (this.ao != null) { this.ba = Convert.toInt32(logBase(this.ao.r, 2)); this.bb = Convert.toInt32(logBase(this.ao.v, 2)); } } bs(a, b, c, d) { this.b4(); this.b7(); this.b5(); } b8() { if (this.ax) { this.a0 = dateNow(); this.cl = this.ck; this.a3 = this.a2; this.an.aq(); } else { this.ck = this.cm; this.a2 = this.a5; this.b5(); } } b9() { let a = 2; let b = dateNow().getTime() - this.a0.getTime(); let c = b / 1000; let d = MathUtil.d((c) / a, 0, 1); let e = this.aj != null ? this.aj.ease(d) : d; let f = 1 - e; this.a2 = this.a3 * f + this.a5 * e; this.ck = { $type: Point_$type, x: this.cl.x * f + this.cm.x * e, y: this.cl.y * f + this.cm.y * e }; if (d >= 1) { this.an.as(); } else { } this.b5(); } a8(a, b, c, d) { for (let e = 0; e < this.ay.count; ++e) { if (this.ay._inner[e].c == a && this.ay._inner[e].d == b && this.ay._inner[e].e == c && this.ay._inner[e].f == d) { return e; } } return -1; } b6(a) { this.aw = false; this.as = false; let b = this.at; if (this.ao == null || !this.an.f() || this.cn.width == 0 || this.cn.height == 0) { return; } let c = truncate(Math.ceil(this.cn.width / this.ao.r)); let d = truncate(Math.max(1, Math.floor(-logBase(this.a2 / c, 2)))); if (d >= this.bb - 8) { d = (this.bb - 8) - 1; } let e = truncate(Math.round(Math.pow(2, d))); let f = this.a2; let g = this.cn.height * f / this.cn.width; let h = this.ao.v / Math.pow(2, d); let i = this.ao.u / Math.pow(2, d); let j = truncate(Math.floor((this.ck.x * this.ao.v) / h)); let k = truncate(Math.ceil(((this.ck.x + f) * this.ao.v) / h)); let l = truncate(Math.floor((this.ck.y * this.ao.u) / i)); let m = truncate(Math.ceil(((this.ck.y + g) * this.ao.v) / i)); if (!b) { j = Math.max(j, 0); k = Math.min(k, e); } l = Math.max(l, 0); m = Math.min(m, e); let n = ((j * h) - (this.ck.x * this.ao.v)) / h; let o = ((l * i) - (this.ck.y * this.ao.u)) / i; let p = (f * this.ao.v / h) * (this.ao.r / this.cn.width); let q = new List$1(Tile.$, 0); let r; let s; for (let t = j; t < k; ++t) { r = t; s = t; while (s < 0) { s = e + s; } while (s > e - 1) { s = (s - e); } for (let u = l; u < m; ++u) { let v = this.a8(r, s, u, d); if (v >= 0) { q.add(this.ay._inner[v]); this.ay.removeAt(v); } else { q.add(((() => { let $ret = new Tile(); $ret.c = r; $ret.d = s; $ret.e = u; $ret.f = d; return $ret; })())); } } } this.ap.f = true; this.cb(); this.ay = q; for (let w = 0; w < this.ay.count; ++w) { if (this.ay._inner[w].i == null) { this.ay._inner[w].i = this.ap.a(); this.ay._inner[w].i._opacity = 1; this.an.am(this.ay._inner[w].i); let x = this.am(this.ay._inner[w]); if (x != null) { this.ay._inner[w].i.ac = x; } else { let y = null; let z = ((() => { let $ret = new Tile(); $ret.d = this.ay._inner[w].d; $ret.e = this.ay._inner[w].e; $ret.f = this.ay._inner[w].f; return $ret; })()); while (z.f >= 0 && y == null) { z.d = z.d >> 1; z.e = z.e >> 1; z.f = z.f - 1; y = this.am(z); } if (y != null) { let aa = truncate(Math.pow(2, this.ay._inner[w].f - z.f)); let ab = intDivide(256, aa); let ac = ab * (this.ay._inner[w].d % aa); let ad = ab * (this.ay._inner[w].e % aa); this.ay._inner[w].h = this.ap.a(); this.ay._inner[w].h._opacity = 1; this.an.an(this.ay._inner[w].h); x = this.an.a(ab, y, ac, ad); this.ay._inner[w].h.ac = x; } this.an.u(this.ay._inner[w]); } } let ae = this.ao.r / p; let af = this.ao.p / p; let ag = (this.ay._inner[w].c - j + n) * ae; let ah = (this.ay._inner[w].e - l + o) * af; this.ay._inner[w].i.width = ae + 0.5; this.ay._inner[w].i.height = af + 0.5; this.an.ao(this.ay._inner[w].i, ag, ah); if (this.ay._inner[w].h != null) { this.ay._inner[w].h.width = ae + 0.5; this.ay._inner[w].h.height = af + 0.5; this.an.ao(this.ay._inner[w].h, ag, ah); } } this.ap.f = false; this.an.aj(); } b5() { if (this.ao == null || !this.an.f() || this.cn.width == 0 || this.cn.height == 0) { return; } if (this.aw) { return; } this.aw = true; this.an.s(runOn(this, this.b6)); } cb() { for (let a = 0; a < this.ay.count; ++a) { this.an.r(this.ay._inner[a]); this.bp(this.ay._inner[a]); if (this.ay._inner[a].i != null) { this.ap.n(this.ay._inner[a].i); this.ay._inner[a].i.ac = null; this.ay._inner[a].i = null; } } } b4() { this.ar.i(); } am(a) { return this.ar.item(a); } bo(a, b) { this.ar.item(a, b); } get ar() { return this.aq; } set ar(a) { this.aq = a; } au() { return this.az.count != 0; } bt() { let a = true; if (this.au()) { a = false; } if (!this.an.d()) { a = false; } if (a && !this.as) { if (this.imageTilesReady != null) { this.imageTilesReady(this, new EventArgs()); } } this.as = a; } ca(a) { if (a.h != null) { a.b = dateNow(); this.az.add(a); this.an.ap(); } else { this.bt(); } } bp(a) { if (a.h != null) { this.ap.n(a.h); a.h.ac = null; a.h = null; for (let b = 0; b < this.az.count; ++b) { if (this.az._inner[b] == a) { this.az.removeAt(b); break; } } if (this.az.count == 0) { this.an.ar(); } } } br() { let a = dateNow(); let b = 0.5; for (let c = 0; c < this.az.count;) { let d = a.getTime() - this.az._inner[c].b.getTime(); let e = d / 1000; let f = (e) / b; f = MathUtil.d(f, 0, 1); this.az._inner[c].h._opacity = 1 - f; if (f >= 1) { this.ap.n(this.az._inner[c].h); this.az._inner[c].h.ac = null; this.az._inner[c].h = null; this.az.removeAt(c); } else { ++c; } this.an.x(); } if (this.az.count == 0) { this.an.ar(); } } by() { this.a2 = this.a5; this.ck = this.cm; this.b5(); } b0(a) { let b = a; this.ag.m(b); this.an.ae(a); } b1(a) { this.an.ag(a); } b2(a) { this.an.ah(a); } b3(a) { this.an.ai(a); } bw() { if (this.imagesChanged != null) { this.imagesChanged(this, new EventArgs()); } } bq() { this.aw = false; } bv(a) { if (this.downloadingImage != null) { this.downloadingImage(this, a); } } bu(a) { if (this.cancellingImage != null) { this.cancellingImage(this, a); } } get a4() { return this.a1; } bz(a) { this.a1 = a; } get a9() { return this.ar.h; } set a9(a) { let b = a != this.a9; if (b) { this.ar = new LRUCache$2(Tile.$, WriteableBitmap.$, 1, a, new TilePositionComparer()); } } } XamMultiScaleImage.$t = /*@__PURE__*/ markType(XamMultiScaleImage, 'XamMultiScaleImage', Control.$, [INotifyPropertyChanged_$type]); XamMultiScaleImage.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, XamMultiScaleImage, 'bx', ['IsHorizontalTileWrappingEnabled:av:cc', [0, false], 'Referer:bf:cd', [2, null], 'Source:ao:ce', [XamMultiScaleTileSource.$, null], 'SpringsEasingFunction:aj:cf', [IEasingFunction_$type, null], 'UseSprings:ax:ch', [0, false], 'UserAgent:bj:cg', [2, null], 'ViewportOrigin:cm:ci', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'ViewportWidth:a5:cj', [1, 1]]); return XamMultiScaleImage; })();