laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
113 lines (112 loc) • 3.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HTMLDivParser = void 0;
const HTMLElement_1 = require("./HTMLElement");
const HTMLStyleElement_1 = require("./HTMLStyleElement");
const HTMLLinkElement_1 = require("./HTMLLinkElement");
const HTMLStyle_1 = require("../utils/HTMLStyle");
const Layout_1 = require("../utils/Layout");
const Rectangle_1 = require("../../maths/Rectangle");
const IHtml_1 = require("../utils/IHtml");
class HTMLDivParser extends HTMLElement_1.HTMLElement {
constructor() {
super(...arguments);
this.repaintHandler = null;
}
reset() {
HTMLStyleElement_1.HTMLStyleElement;
HTMLLinkElement_1.HTMLLinkElement;
super.reset();
this._style.block = true;
this._style.setLineElement(true);
this._style.width = 200;
this._style.height = 200;
this.repaintHandler = null;
this.contextHeight = 0;
this.contextWidth = 0;
return this;
}
set innerHTML(text) {
this.destroyChildren();
this.appendHTML(text);
}
set width(value) {
var changed;
if (value === 0) {
changed = value != this._width;
}
else {
changed = value != this.width;
}
super.width = value;
if (changed)
this.layout();
}
appendHTML(text) {
IHtml_1.IHtml.HTMLParse.parse(this, text, this.URI);
this.layout();
}
_addChildsToLayout(out) {
var words = this._getWords();
if (words == null && (!this._children || this._children.length == 0))
return false;
words && words.forEach(function (o) {
out.push(o);
});
var tFirstKey = true;
for (var i = 0, len = this._children.length; i < len; i++) {
var o = this._children[i];
if (tFirstKey) {
tFirstKey = false;
}
else {
out.push(null);
}
o._addToLayout(out);
}
return true;
}
_addToLayout(out) {
this.layout();
!this.style.absolute && out.push(this);
}
getBounds() {
if (!this._htmlBounds)
return null;
if (!this._boundsRec)
this._boundsRec = Rectangle_1.Rectangle.create();
return this._boundsRec.copyFrom(this._htmlBounds);
}
parentRepaint(recreate = false) {
super.parentRepaint();
if (this.repaintHandler)
this.repaintHandler.runWith(recreate);
}
layout() {
this.style._type |= HTMLStyle_1.HTMLStyle.ADDLAYOUTED;
var tArray = Layout_1.Layout.layout(this);
if (tArray) {
if (!this._htmlBounds)
this._htmlBounds = Rectangle_1.Rectangle.create();
var tRectangle = this._htmlBounds;
tRectangle.x = tRectangle.y = 0;
tRectangle.width = this.contextWidth = tArray[0];
tRectangle.height = this.contextHeight = tArray[1];
}
}
get height() {
if (this._height)
return this._height;
return this.contextHeight;
}
set height(value) {
super.height = value;
}
get width() {
if (this._width)
return this._width;
return this.contextWidth;
}
}
exports.HTMLDivParser = HTMLDivParser;
IHtml_1.IHtml.HTMLDivParser = HTMLDivParser;