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

Move output/common/CssStyles.ts to util/StyleList.ts #493

Merged
merged 4 commits into from
Jun 15, 2020
Merged
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
2 changes: 1 addition & 1 deletion ts/a11y/assistive-mml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {MathItem, AbstractMathItem, STATE, newState} from '../core/MathItem.js';
import {MmlNode} from '../core/MmlTree/MmlNode.js';
import {SerializedMmlVisitor} from '../core/MmlTree/SerializedMmlVisitor.js';
import {OptionList, expandable} from '../util/Options.js';
import {StyleList} from '../output/common/CssStyles.js';
import {StyleList} from '../util/StyleList.js';

/**
* Generic constructor for Mixins
Expand Down
2 changes: 1 addition & 1 deletion ts/a11y/explorer/Region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


import {MathDocument} from '../../core/MathDocument.js';
import {CssStyles} from '../../output/common/CssStyles.js';
import {CssStyles} from '../../util/StyleList.js';
import '../sre.js';

export type A11yDocument = MathDocument<HTMLElement, Text, Document>;
Expand Down
2 changes: 1 addition & 1 deletion ts/handlers/html/HTMLDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {HTMLDomStrings} from './HTMLDomStrings.js';
import {DOMAdaptor} from '../../core/DOMAdaptor.js';
import {InputJax} from '../../core/InputJax.js';
import {STATE, ProtoItem, Location} from '../../core/MathItem.js';
import {StyleList} from '../../output/common/CssStyles.js';
import {StyleList} from '../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CommonOutputJax} from './common/OutputJax.js';
import {CommonWrapper} from './common/Wrapper.js';
import {StyleList} from '../util/Styles.js';
import {StyleList as CssStyleList} from './common/CssStyles.js';
import {StyleList as CssStyleList} from '../util/StyleList.js';
import {OptionList} from '../util/Options.js';
import {MathDocument} from '../core/MathDocument.js';
import {MathItem} from '../core/MathItem.js';
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/FontData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import {CharMap, CharOptions, CharData, VariantData, DelimiterData, FontData, DIRECTION} from '../common/FontData.js';
import {StringMap} from './Wrapper.js';
import {StyleList, StyleData} from '../common/CssStyles.js';
import {StyleList, StyleData} from '../../util/StyleList.js';
import {em} from '../../util/lengths.js';
import {OptionList, defaultOptions, userOptions} from '../../util/Options.js';

Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {TextNode} from '../../../core/MmlTree/MmlNode.js';
import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonTextNodeMixin} from '../../common/Wrappers/TextNode.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/maction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {ActionDef} from '../../common/Wrappers/maction.js';
import {EventHandler, TooltipData} from '../../common/Wrappers/maction.js';
import {MmlMaction} from '../../../core/MmlTree/MmlNodes/maction.js';
import {TextNode} from '../../../core/MmlTree/MmlNode.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonMathMixin} from '../../common/Wrappers/math.js';
import {MmlMath} from '../../../core/MmlTree/MmlNodes/math.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';
import {BBox} from '../BBox.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/menclose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {CHTMLmsqrt} from './msqrt.js';
import * as Notation from '../Notation.js';
import {MmlMenclose} from '../../../core/MmlTree/MmlNodes/menclose.js';
import {OptionList} from '../../../util/Options.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';
import {em} from '../../../util/lengths.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mfrac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonMfracMixin} from '../../common/Wrappers/mfrac.js';
import {MmlMfrac} from '../../../core/MmlTree/MmlNodes/mfrac.js';
import {CHTMLmo} from './mo.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';
import {OptionList} from '../../../util/Options.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mglyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonMglyphMixin} from '../../common/Wrappers/mglyph.js';
import {MmlMglyph} from '../../../core/MmlTree/MmlNodes/mglyph.js';
import {StyleList, StyleData} from '../../common/CssStyles.js';
import {StyleList, StyleData} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mmultiscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {CHTMLmsubsup} from './msubsup.js';
import {CommonMmultiscriptsMixin} from '../../common/Wrappers/mmultiscripts.js';
import {MmlMmultiscripts} from '../../../core/MmlTree/MmlNodes/mmultiscripts.js';
import {BBox} from '../BBox.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {CHTMLWrapper, CHTMLConstructor, StringMap} from '../Wrapper.js';
import {CommonMoMixin, DirectionVH} from '../../common/Wrappers/mo.js';
import {MmlMo} from '../../../core/MmlTree/MmlNodes/mo.js';
import {BBox} from '../BBox.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';
import {DIRECTION} from '../FontData.js';

/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mpadded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CHTMLWrapper, CHTMLConstructor, StringMap} from '../Wrapper.js';
import {CommonMpaddedMixin} from '../../common/Wrappers/mpadded.js';
import {MmlMpadded} from '../../../core/MmlTree/MmlNodes/mpadded.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/msqrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {CommonMsqrtMixin} from '../../common/Wrappers/msqrt.js';
import {CHTMLmo} from './mo.js';
import {BBox} from '../BBox.js';
import {MmlMsqrt} from '../../../core/MmlTree/MmlNodes/msqrt.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/msubsup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {CommonMsubMixin} from '../../common/Wrappers/msubsup.js';
import {CommonMsupMixin} from '../../common/Wrappers/msubsup.js';
import {CommonMsubsupMixin} from '../../common/Wrappers/msubsup.js';
import {MmlMsubsup, MmlMsub, MmlMsup} from '../../../core/MmlTree/MmlNodes/msubsup.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {CHTMLmtr} from './mtr.js';
import {CHTMLmtd} from './mtd.js';
import {MmlMtable} from '../../../core/MmlTree/MmlNodes/mtable.js';
import {MmlNode} from '../../../core/MmlTree/MmlNode.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';
import {isPercent} from '../../../util/string.js';
import {OptionList} from '../../../util/Options.js';

Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mtd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonMtdMixin} from '../../common/Wrappers/mtd.js';
import {MmlMtd} from '../../../core/MmlTree/MmlNodes/mtd.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/mtr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {CommonMlabeledtrMixin} from '../../common/Wrappers/mtr.js';
import {CHTMLmtable} from './mtable.js';
import {CHTMLmtd} from './mtd.js';
import {MmlMtr, MmlMlabeledtr} from '../../../core/MmlTree/MmlNodes/mtr.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/munderover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {CommonMunderMixin} from '../../common/Wrappers/munderover.js';
import {CommonMoverMixin} from '../../common/Wrappers/munderover.js';
import {CommonMunderoverMixin} from '../../common/Wrappers/munderover.js';
import {MmlMunderover, MmlMunder, MmlMover} from '../../../core/MmlTree/MmlNodes/munderover.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/scriptbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonScriptbaseMixin} from '../../common/Wrappers/scriptbase.js';
import {BBox} from '../BBox.js';
import {StyleData} from '../../common/CssStyles.js';
import {StyleData} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrappers/semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {CommonSemanticsMixin} from '../../common/Wrappers/semantics.js';
import {BBox} from '../BBox.js';
import {MmlSemantics, MmlAnnotation, MmlAnnotationXML} from '../../../core/MmlTree/MmlNodes/semantics.js';
import {XMLNode} from '../../../core/MmlTree/MmlNode.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
124 changes: 5 additions & 119 deletions ts/output/common/CssStyles.ts
Original file line number Diff line number Diff line change
@@ -1,120 +1,6 @@
/*************************************************************
*
* Copyright (c) 2017 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Temporary compatibility file for renaming of this file to util/StyleList.ts
// (to be removed in the next release)
//
export * from '../../util/StyleList.js';

/**
* @fileoverview Implements the CssStyles class for handling stylesheets
*
* @author [email protected] (Davide Cervone)
*/

/**
* The data for a selector
*/
export type StyleData = {
[property: string]: string | number;
};

/**
* A list of selectors and their data (basically a stylesheet)
*/
export type StyleList = {
[selector: string]: StyleData;
};

/******************************************************************************/
/**
* The CssStyles class (for managing a collection of CSS style definitions)
*/

export class CssStyles {
/**
* The styles as they currently stand
*/
protected styles: StyleList = {};

/**
* @return {string} The styles as a CSS string
*/
get cssText(): string {
return this.getStyleString();
}

/**
* @param {StyleList} styles The initial styles to use, if any
* @constructor
*/
constructor(styles: StyleList = null) {
this.addStyles(styles);
}

/**
* @param {StyleList} styles The styles to combine with the existing ones
*/
public addStyles(styles: StyleList) {
if (!styles) return;
for (const style of Object.keys(styles)) {
if (!this.styles[style]) {
this.styles[style] = {};
}
Object.assign(this.styles[style], styles[style]);
}
}

/**
* @param {string[]} selectors The selectors for the styles to remove
*/
public removeStyles(...selectors: string[]) {
for (const selector of selectors) {
delete this.styles[selector];
}
}

/**
* Clear all the styles
*/
public clear() {
this.styles = {};
}

/**
* @return {string} The CSS string for the style list
*/
public getStyleString(): string {
const selectors = Object.keys(this.styles);
const defs: string[] = new Array(selectors.length);
let i = 0;
for (const selector of selectors) {
defs[i++] = selector + ' {\n' + this.getStyleDefString(this.styles[selector]) + '\n}';
}
return defs.join('\n\n');
}

/**
* @param {StyleData} styles The style data to be stringified
* @return {string} The CSS string for the given data
*/
public getStyleDefString(styles: StyleData): string {
const properties = Object.keys(styles);
const values: string[] = new Array(properties.length);
let i = 0;
for (const property of properties) {
values[i++] = ' ' + property + ': ' + styles[property] + ';';
}
return values.join('\n');
}

}
2 changes: 1 addition & 1 deletion ts/output/common/FontData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import {OptionList} from '../../util/Options.js';
import {StyleList} from './CssStyles.js';
import {StyleList} from '../../util/StyleList.js';

/****************************************************************************/

Expand Down
3 changes: 1 addition & 2 deletions ts/output/common/OutputJax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import {MathItem, Metrics, STATE} from '../../core/MathItem.js';
import {MmlNode} from '../../core/MmlTree/MmlNode.js';
import {FontData, FontDataClass, CharOptions, DelimiterData, CssFontData} from './FontData.js';
import {OptionList, separateOptions} from '../../util/Options.js';
import {CssStyles} from './CssStyles.js';
import {CommonWrapper, AnyWrapper, AnyWrapperClass} from './Wrapper.js';
import {CommonWrapperFactory, AnyWrapperFactory} from './WrapperFactory.js';
import {percent} from '../../util/lengths.js';
import {StyleList, Styles} from '../../util/Styles.js';
import {StyleList as CssStyleList} from './CssStyles.js';
import {StyleList as CssStyleList, CssStyles} from '../../util/StyleList.js';

/*****************************************************************/

Expand Down
2 changes: 1 addition & 1 deletion ts/output/common/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import {Property} from '../../core/Tree/Node.js';
import {unicodeChars} from '../../util/string.js';
import * as LENGTHS from '../../util/lengths.js';
import {Styles} from '../../util/Styles.js';
import {StyleList} from '../../util/StyleList.js';
import {CommonOutputJax} from './OutputJax.js';
import {CommonWrapperFactory} from './WrapperFactory.js';
import {BBox} from './BBox.js';
import {FontData, DelimiterData, CharData, CharOptions, DIRECTION, NOSTRETCH} from './FontData.js';
import {StyleList} from '../common/CssStyles.js';

/*****************************************************************/

Expand Down
2 changes: 1 addition & 1 deletion ts/output/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {SVGWrapper} from './svg/Wrapper.js';
import {SVGWrapperFactory} from './svg/WrapperFactory.js';
import {SVGFontData} from './svg/FontData.js';
import {TeXFont} from './svg/fonts/tex.js';
import {StyleList as CssStyleList} from './common/CssStyles.js';
import {StyleList as CssStyleList} from '../util/StyleList.js';
import {FontCache} from './svg/FontCache.js';
import {unicodeChars} from '../util/string.js';
import {percent} from '../util/lengths.js';
Expand Down
2 changes: 1 addition & 1 deletion ts/output/svg/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {TextNode} from '../../../core/MmlTree/MmlNode.js';
import {SVGWrapper, SVGConstructor} from '../Wrapper.js';
import {CommonTextNodeMixin} from '../../common/Wrappers/TextNode.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/svg/Wrappers/maction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {ActionDef} from '../../common/Wrappers/maction.js';
import {EventHandler, TooltipData} from '../../common/Wrappers/maction.js';
import {MmlMaction} from '../../../core/MmlTree/MmlNodes/maction.js';
import {TextNode, AbstractMmlNode} from '../../../core/MmlTree/MmlNode.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';

/*****************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion ts/output/svg/Wrappers/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {SVGWrapper, SVGConstructor} from '../Wrapper.js';
import {CommonMathMixin} from '../../common/Wrappers/math.js';
import {MmlMath} from '../../../core/MmlTree/MmlNodes/math.js';
import {StyleList} from '../../common/CssStyles.js';
import {StyleList} from '../../../util/StyleList.js';
import {BBox} from '../BBox.js';

/*****************************************************************/
Expand Down
Loading