Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: do not download resources separately #503

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
"adapt": false,
"goog": false,
"vivliostyle": false,
"resources": false,
"DataView": false
},
// "extends": "eslint:recommended",
Expand Down
121 changes: 0 additions & 121 deletions resources/user-agent-page.css

This file was deleted.

34 changes: 7 additions & 27 deletions src/adapt/cssvalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ goog.require('adapt.css');
goog.require('adapt.csstok');
goog.require('adapt.cssparse');
goog.require('adapt.expr');
goog.require('resources.txt');

/**
* @interface
Expand Down Expand Up @@ -2220,33 +2221,12 @@ adapt.cssvalid.ValidatorSet.prototype.validatePropertyAndHandleShorthand =
}
};


/**
* @type {adapt.taskutil.Fetcher.<adapt.cssvalid.ValidatorSet>}
*/
adapt.cssvalid.validatorFetcher = new adapt.taskutil.Fetcher(() => {
/** @type {!adapt.task.Frame.<adapt.cssvalid.ValidatorSet>} */ const frame =
adapt.task.newFrame("loadValidatorSet.load");
const url = adapt.base.resolveURL("validation.txt", adapt.base.resourceBaseURL);
const result = adapt.net.ajax(url);
* @return {adapt.cssvalid.ValidatorSet}
*/
adapt.cssvalid.baseValidatorSet = function() {
const validatorSet = new adapt.cssvalid.ValidatorSet();
validatorSet.initBuiltInValidators();
result.then(xhr => {
try {
if (xhr.responseText) {
validatorSet.parse(xhr.responseText);
} else {
vivliostyle.logging.logger.error("Error: missing", url);
}
} catch (err) {
vivliostyle.logging.logger.error(err, "Error:");
}
frame.finish(validatorSet);
});
return frame.result();
}, "validatorFetcher");

/**
* @return {!adapt.task.Result.<adapt.cssvalid.ValidatorSet>}
*/
adapt.cssvalid.loadValidatorSet = () => adapt.cssvalid.validatorFetcher.get();
validatorSet.parse(resources.txt.validation);
return validatorSet;
};
37 changes: 17 additions & 20 deletions src/adapt/ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ goog.require('adapt.font');
goog.require('vivliostyle.break');
goog.require('vivliostyle.page');
goog.require('vivliostyle.column');
goog.require('resources.css');
goog.require('resources.xml');

/**
* @type {adapt.taskutil.Fetcher.<boolean>}
*/
adapt.ops.uaStylesheetBaseFetcher = new adapt.taskutil.Fetcher(() => {
/** @type {!adapt.task.Frame.<boolean>} */ const frame =
adapt.task.newFrame("uaStylesheetBase");
adapt.cssvalid.loadValidatorSet().then(validatorSet => {
const url = adapt.base.resolveURL("user-agent-base.css", adapt.base.resourceBaseURL);
const handler = new adapt.csscasc.CascadeParserHandler(null, null, null, null, null,
validatorSet, true);
handler.startStylesheet(adapt.cssparse.StylesheetFlavor.USER_AGENT);
adapt.csscasc.uaBaseCascade = handler.cascade;
adapt.cssparse.parseStylesheetFromURL(url, handler, null, null).thenFinish(frame);
});
/** @type {!adapt.task.Frame.<boolean>} */
const frame = adapt.task.newFrame("uaStylesheetBase");
const validatorSet = adapt.cssvalid.baseValidatorSet();
const url = adapt.base.resolveURL("user-agent-base.css", adapt.base.resourceBaseURL);
const handler = new adapt.csscasc.CascadeParserHandler(null, null, null, null, null,
validatorSet, true);
handler.startStylesheet(adapt.cssparse.StylesheetFlavor.USER_AGENT);
adapt.csscasc.uaBaseCascade = handler.cascade;
adapt.cssparse.parseStylesheetFromText(resources.css.userAgentBase, handler, url, null, null).thenFinish(frame);
return frame.result();
}, "uaStylesheetBaseFetcher");

Expand Down Expand Up @@ -1569,15 +1570,11 @@ adapt.ops.OPSDocStore.prototype.init = function(authorStyleSheets, userStyleShee
this.setStyleSheets(authorStyleSheets, userStyleSheets);
const userAgentXML = adapt.base.resolveURL("user-agent.xml", adapt.base.resourceBaseURL);
const frame = adapt.task.newFrame("OPSDocStore.init");
const self = this;
adapt.cssvalid.loadValidatorSet().then(validatorSet => {
self.validatorSet = validatorSet;
adapt.ops.loadUABase().then(() => {
self.load(userAgentXML).then(() => {
self.triggerSingleDocumentPreprocessing = true;
frame.finish(true);
});
});
this.validatorSet = adapt.cssvalid.baseValidatorSet();
adapt.ops.loadUABase().then(() => {
this.resources[userAgentXML] = resources.xml.userAgent;
this.triggerSingleDocumentPreprocessing = true;
frame.finish(true);
});
return frame.result();
};
Expand Down Expand Up @@ -1683,7 +1680,7 @@ adapt.ops.OPSDocStore.prototype.parseOPSResource = function(response) {
self.triggersByDocURL[url] = triggers;
const sources = /** @type {Array.<adapt.ops.StyleSource>} */ ([]);
const userAgentURL = adapt.base.resolveURL("user-agent-page.css", adapt.base.resourceBaseURL);
sources.push({url: userAgentURL, text:null,
sources.push({url: userAgentURL, text: resources.css.userAgentPage,
flavor:adapt.cssparse.StylesheetFlavor.USER_AGENT, classes: null, media: null});
const head = xmldoc.head;
if (head) {
Expand Down
3 changes: 3 additions & 0 deletions src/adapt/vgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ adapt.vgen.ViewFactory.prototype.createShadows = function(element, isRoot, cascS
cont1.then(shadow => {
if (computedStyle["display"] === adapt.css.ident.table_cell) {
const url = adapt.base.resolveURL("user-agent.xml#table-cell", adapt.base.resourceBaseURL);
// FIXME:
// What we need here is '<s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="table-cell-container"><s:content/></div></s:template>'
// I'm not sure how I can avoid it downloading from the web.
cont2 = self.createRefShadow(url, adapt.vtree.ShadowType.ROOTLESS, element, shadowContext, shadow);
} else {
cont2 = adapt.task.newResult(shadow);
Expand Down
Loading