mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
adding typescript definitions
This commit is contained in:
parent
4b211dbfdf
commit
8cd4f18bce
4 changed files with 23 additions and 10 deletions
|
@ -676,9 +676,11 @@ class Contents {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
_getStylesheetNode() {
|
_getStylesheetNode(key) {
|
||||||
var styleEl;
|
var styleEl;
|
||||||
var key = "epubjs-inserted-css";
|
key = "epubjs-inserted-css-" + (key || '');
|
||||||
|
|
||||||
|
if(!this.document) return false;
|
||||||
|
|
||||||
// Check if link already exists
|
// Check if link already exists
|
||||||
styleEl = this.document.getElementById(key);
|
styleEl = this.document.getElementById(key);
|
||||||
|
@ -694,11 +696,16 @@ class Contents {
|
||||||
/**
|
/**
|
||||||
* Append stylesheet css
|
* Append stylesheet css
|
||||||
* @param {string} serializedCss
|
* @param {string} serializedCss
|
||||||
|
* @param {string} key If the key is the same, the CSS will be replaced instead of inserted
|
||||||
*/
|
*/
|
||||||
addStylesheetSerialized(serializedCss) {
|
addStylesheetCss(serializedCss, key) {
|
||||||
|
if(!this.document || !serializedCss) return false;
|
||||||
|
|
||||||
var styleEl;
|
var styleEl;
|
||||||
styleEl = this._getStylesheetNode();
|
styleEl = this._getStylesheetNode(key);
|
||||||
styleEl.innerText = serializedCss;
|
styleEl.innerHTML = serializedCss;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -706,14 +713,15 @@ class Contents {
|
||||||
* Array: https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule
|
* Array: https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule
|
||||||
* Object: https://github.com/desirable-objects/json-to-css
|
* Object: https://github.com/desirable-objects/json-to-css
|
||||||
* @param {array | object} rules
|
* @param {array | object} rules
|
||||||
|
* @param {string} key If the key is the same, the CSS will be replaced instead of inserted
|
||||||
*/
|
*/
|
||||||
addStylesheetRules(rules) {
|
addStylesheetRules(rules, key) {
|
||||||
var styleSheet;
|
var styleSheet;
|
||||||
|
|
||||||
if(!this.document || !rules || rules.length === 0) return;
|
if(!this.document || !rules || rules.length === 0) return;
|
||||||
|
|
||||||
// Grab style sheet
|
// Grab style sheet
|
||||||
styleSheet = this._getStylesheetNode().sheet;
|
styleSheet = this._getStylesheetNode(key).sheet;
|
||||||
|
|
||||||
if (Object.prototype.toString.call(rules) === "[object Array]") {
|
if (Object.prototype.toString.call(rules) === "[object Array]") {
|
||||||
for (var i = 0, rl = rules.length; i < rl; i++) {
|
for (var i = 0, rl = rules.length; i < rl; i++) {
|
||||||
|
|
|
@ -188,9 +188,10 @@ class Themes {
|
||||||
if (theme.url) {
|
if (theme.url) {
|
||||||
contents.addStylesheet(theme.url);
|
contents.addStylesheet(theme.url);
|
||||||
} else if (theme.serialized) {
|
} else if (theme.serialized) {
|
||||||
contents.addStylesheetSerialized(theme.serialized);
|
contents.addStylesheetCss(theme.serialized, name);
|
||||||
|
theme.injected = true;
|
||||||
} else if (theme.rules) {
|
} else if (theme.rules) {
|
||||||
contents.addStylesheetRules(theme.rules);
|
contents.addStylesheetRules(theme.rules, name);
|
||||||
theme.injected = true;
|
theme.injected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
types/contents.d.ts
vendored
4
types/contents.d.ts
vendored
|
@ -28,7 +28,9 @@ export default class Contents {
|
||||||
|
|
||||||
addStylesheet(src: string): Promise<boolean>;
|
addStylesheet(src: string): Promise<boolean>;
|
||||||
|
|
||||||
addStylesheetRules(rules: Array<object> | object): Promise<boolean>;
|
addStylesheetRules(rules: Array<object> | object, key: string): Promise<boolean>;
|
||||||
|
|
||||||
|
addStylesheetCss(serializedCss: string, key: string): Promise<boolean>;
|
||||||
|
|
||||||
cfiFromNode(node: Node, ignoreClass?: string): string;
|
cfiFromNode(node: Node, ignoreClass?: string): string;
|
||||||
|
|
||||||
|
|
2
types/themes.d.ts
vendored
2
types/themes.d.ts
vendored
|
@ -14,6 +14,8 @@ export default class Themes {
|
||||||
|
|
||||||
registerThemes( themes: object ): void;
|
registerThemes( themes: object ): void;
|
||||||
|
|
||||||
|
registerCss( name: string, css: string ): void;
|
||||||
|
|
||||||
registerUrl( name: string, input: string ): void;
|
registerUrl( name: string, input: string ): void;
|
||||||
|
|
||||||
registerRules( name: string, rules: object ): void;
|
registerRules( name: string, rules: object ): void;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue