nehan
Version:
Html layout engine for paged-media written in Typescript
69 lines • 2.26 kB
JavaScript
import { ListStylePosition, ListStyleType, CssCascade, PseudoElementTagName, SpaceChar, } from "./public-api";
export class ListStyle {
isNone() {
return this.type_.isNone();
}
isPositionOutside() {
return this.position.isOutside();
}
isPositionInside() {
return this.position.isInside();
}
isTcyMarker() {
return this.type_.isTcyMarker();
}
getMarkerText(index) {
return this.type_.getMarkerText(index);
}
insertMarkerText(element) {
const markerElement = element.firstChild;
if (!markerElement || markerElement.tagName !== PseudoElementTagName.MARKER) {
return;
}
if (markerElement.firstChild && markerElement.firstChild.isTextElement()) {
return;
}
let markerText = this.getMarkerText(element.indexOfType);
if (element.querySelector("li")) {
markerText = SpaceChar.markerSpace;
}
const markerTextNode = element.root.createTextNode(markerText);
markerElement.appendChild(markerTextNode);
}
static load(element) {
const listStyle = new ListStyle();
listStyle.type_ = ListStyleType.load(element);
listStyle.position = ListStylePosition.load(element);
listStyle.image = ListStyle.loadImage(element);
return listStyle;
}
static loadImage(element) {
return CssCascade.getValue(element, "list-style-image");
}
static inferProp(value) {
if (value.indexOf("url(") >= 0) {
return "list-style-image";
}
switch (value) {
case "inside":
case "outside":
return "list-style-position";
}
return "list-style-type";
}
static parseShorthand(cssText) {
let declr = {
"list-style-image": "none",
"list-style-type": "none",
"list-style-position": "outside"
};
cssText.split().forEach(value => {
const prop = ListStyle.inferProp(value);
declr[prop] = value;
});
return Object.keys(declr).map(prop => {
return { prop, value: declr[prop] };
});
}
}
//# sourceMappingURL=list-style.js.map