Skip to content

Commit

Permalink
updated dependencies, styling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
daign committed Mar 28, 2023
1 parent b44a82d commit cd90c84
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 55 deletions.
8 changes: 4 additions & 4 deletions lib/styleProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class StyleProcessor<T extends IStyleDeclaration> {
/**
* Calculate the resulting style declaration derived from the elements selector chain and the
* style sheet.
* @param styleSheet The given style sheet.
* @param selectorChain The selector chain of the element.
* @param declarationType The type of the returned style declaration.
* @param elementStyle A style assigned directly to the element. Optional.
* @param styleSheet - The given style sheet.
* @param selectorChain - The selector chain of the element.
* @param declarationType - The type of the returned style declaration.
* @param elementStyle - A style assigned directly to the element. Optional.
* @returns The calculated style declaration.
*/
public calculateStyle(
Expand Down
24 changes: 7 additions & 17 deletions lib/styleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@ import { StyleSelectorChain } from './styleSelectorChain';
* A style rule consisting of a style selector chain and a style declaration.
*/
export class StyleRule {
/**
* The style selector specifying when the style should apply.
*/
public selectorChain: StyleSelectorChain;

/**
* The declaration containing the style attributes.
*/
public declaration: IStyleDeclaration;

/**
* Constructor.
* @param selectorChain The style selector chain.
* @param declaration The style declaration.
* @param selectorChain - The style selector specifying when the style should apply.
* @param declaration - The declaration containing the style attributes.
*/
public constructor( selectorChain: StyleSelectorChain, declaration: IStyleDeclaration ) {
this.selectorChain = selectorChain;
this.declaration = declaration;
}
public constructor(
public selectorChain: StyleSelectorChain,
public declaration: IStyleDeclaration
) {}

/**
* Compares the priority for two style rules.
* @param rule The second rule.
* @param rule - The second rule.
* @returns -1 when priority of first is less than priority of second rule
* 0 when priority of both rules is equal
* 1 when priority of first is greater than priority of second rule
Expand Down
8 changes: 4 additions & 4 deletions lib/styleSelector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Style selector describing the criterias for where a style should apply.
* Style selector describing the criteria for where a style should apply.
*/
export class StyleSelector {
/**
Expand All @@ -9,7 +9,7 @@ export class StyleSelector {

/**
* Constructor.
* @param s Concatenated string of several class names to initialize with. All starting with a
* @param s - Concatenated string of several class names to initialize with. All starting with a
* period, e.g. '.controlPoint.selected'. Optional.
*/
public constructor( s?: string ) {
Expand All @@ -22,7 +22,7 @@ export class StyleSelector {
* Returns whether the given selector falls into the pool of matching selectors defined by this
* object. A given selector only matches if all its parts are also part of this object. However
* the object can also have other parts not found in the given selector. Order does not matter.
* @param selector The given selector.
* @param selector - The given selector.
* @return Returns the boolean result of the match test.
*/
public match( selector: StyleSelector ): boolean {
Expand All @@ -38,7 +38,7 @@ export class StyleSelector {

/**
* Compares the priority for two selectors.
* @param selector The second selector.
* @param selector - The second selector.
* @returns -1 when priority of first is less than priority of second selector
* 0 when priority of both selectors is equal
* 1 when priority of first is greater than priority of second selector
Expand Down
12 changes: 6 additions & 6 deletions lib/styleSelectorChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class StyleSelectorChain {

/**
* Add a selector to the end of the chain.
* @param selector The selector to add.
* @param selector - The selector to add.
* @returns A reference to itself.
*/
public addSelector( selector: StyleSelector ): StyleSelectorChain {
Expand All @@ -44,7 +44,7 @@ export class StyleSelectorChain {

/**
* Add a selector to the front of the chain.
* @param selector The selector to add.
* @param selector - The selector to add.
* @returns A reference to itself.
*/
public addSelectorToFront( selector: StyleSelector ): StyleSelectorChain {
Expand All @@ -54,7 +54,7 @@ export class StyleSelectorChain {

/**
* Remove selectors from the end.
* @param n The number of selectors to drop from the end.
* @param n - The number of selectors to drop from the end.
* @returns A reference to itself.
*/
public dropSelectors( n: number ): StyleSelectorChain {
Expand All @@ -66,7 +66,7 @@ export class StyleSelectorChain {

/**
* Get a selector from the chain.
* @param index The index of the selector to get.
* @param index - The index of the selector to get.
* @returns The style selector object.
*/
public getSelector( index: number ): StyleSelector {
Expand All @@ -80,7 +80,7 @@ export class StyleSelectorChain {
* Determine whether the chains match. Last selector must always match. From there on all
* selectors from the rule chain must match to selectors in the original chain in the given order,
* but in the original chain there can be addional selectors.
* @param ruleChain The selector chain to match with.
* @param ruleChain - The selector chain to match with.
* @returns The boolean result of the match.
*/
public matchFromEnd( ruleChain: StyleSelectorChain ): boolean {
Expand Down Expand Up @@ -116,7 +116,7 @@ export class StyleSelectorChain {

/**
* Compares the priority for two selector chains.
* @param secondChain The second selector chain.
* @param secondChain - The second selector chain.
* @returns -1 when priority of first is less than priority of second chain
* 0 when priority of both chains is equal
* 1 when priority of first is greater than priority of second chain
Expand Down
8 changes: 4 additions & 4 deletions lib/styleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class StyleSheet<T extends IStyleDeclaration> {

/**
* Apply a callback function to every entry of the list.
* @param callback The callback to apply.
* @param callback - The callback to apply.
*/
public forEach( callback: ( rule: StyleRule ) => void ): void {
// Execution from highest to lowest priority rules.
Expand All @@ -42,8 +42,8 @@ export class StyleSheet<T extends IStyleDeclaration> {

/**
* Parse style sheet rules from a string.
* @param input The input string.
* @param declarationType The declaration type.
* @param input - The input string.
* @param declarationType - The declaration type.
*/
public parseFromString( input: string, declarationType: new () => T ): void {
const lines = input.split( '\n' );
Expand Down Expand Up @@ -112,7 +112,7 @@ export class StyleSheet<T extends IStyleDeclaration> {

/**
* Add a style rule to the list.
* @param rule The style rule to add.
* @param rule - The style rule to add.
*/
private addRule( rule: StyleRule ): void {
/* Adding should keep the list sorted. Rules with higher priority come frist. If priority of two
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daign/style-sheets",
"version": "1.0.3",
"version": "1.1.0",
"description": "Simple style sheet processor.",
"keywords": [
"style",
Expand Down Expand Up @@ -30,17 +30,17 @@
"homepage": "https://github.com/daign/daign-style-sheets#readme",
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.0",
"@types/mocha": "^10.0.1",
"@types/sinon": "^10.0.13",
"chai": "^4.3.7",
"mocha": "^10.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"sinon": "^14.0.2",
"sinon": "^15.0.3",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"tslint-no-unused-expression-chai": "^0.1.4",
"typescript": "^4.9.3"
"typescript": "^5.0.2"
},
"dependencies": {},
"nyc": {
Expand Down
8 changes: 4 additions & 4 deletions test/styleRule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import * as sinon from 'sinon';
import { spy } from 'sinon';

import { StyleRule, StyleSelector, StyleSelectorChain } from '../lib';
import { TestStyle } from './testStyle';
Expand Down Expand Up @@ -29,7 +29,7 @@ describe( 'StyleRule', (): void => {

const firstChain = new StyleSelectorChain();
const firstRule = new StyleRule( firstChain, declaration );
const spy = sinon.spy( firstChain, 'comparePriority' );
const comparePrioritySpy = spy( firstChain, 'comparePriority' );

const secondChain = new StyleSelectorChain();
const secondRule = new StyleRule( secondChain, declaration );
Expand All @@ -38,8 +38,8 @@ describe( 'StyleRule', (): void => {
firstRule.comparePriority( secondRule );

// Assert
expect( spy.calledOnce ).to.be.true;
expect( spy.getCall( 0 ).calledWithExactly( secondChain ) ).to.be.true;
expect( comparePrioritySpy.calledOnce ).to.be.true;
expect( comparePrioritySpy.getCall( 0 ).calledWithExactly( secondChain ) ).to.be.true;
} );
} );
} );
20 changes: 10 additions & 10 deletions test/styleSheet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import * as sinon from 'sinon';
import { spy } from 'sinon';

import { StyleSheet } from '../lib';
import { TestStyle } from './testStyle';
Expand All @@ -22,13 +22,13 @@ describe( 'StyleSheet', (): void => {
const rule2 = ( styleSheet as any ).rules[ 1 ];

// Act
const spy = sinon.spy();
styleSheet.forEach( spy );
const callbackSpy = spy();
styleSheet.forEach( callbackSpy );

// Assert
expect( spy.calledTwice ).to.be.true;
expect( spy.getCall( 0 ).args[ 0 ] ).to.equal( rule1 );
expect( spy.getCall( 1 ).args[ 0 ] ).to.equal( rule2 );
expect( callbackSpy.calledTwice ).to.be.true;
expect( callbackSpy.getCall( 0 ).args[ 0 ] ).to.equal( rule1 );
expect( callbackSpy.getCall( 1 ).args[ 0 ] ).to.equal( rule2 );
} );
} );

Expand All @@ -42,13 +42,13 @@ describe( 'StyleSheet', (): void => {
}
}`;
const styleSheet = new StyleSheet<TestStyle>();
const spy = sinon.spy( ( styleSheet as any ), 'addRule' );
const addRuleSpy = spy( ( styleSheet as any ), 'addRule' );

// Act
styleSheet.parseFromString( text, TestStyle );

// Assert
expect( spy.calledOnce ).to.be.true;
expect( addRuleSpy.calledOnce ).to.be.true;
expect( ( styleSheet as any ).rules.length ).to.equal( 1 );
const rule = ( styleSheet as any ).rules[ 0 ];
expect( rule.declaration.fill ).to.equal( 'green' );
Expand Down Expand Up @@ -129,13 +129,13 @@ describe( 'StyleSheet', (): void => {
// Just a comment.
}`;
const styleSheet = new StyleSheet<TestStyle>();
const spy = sinon.spy( ( styleSheet as any ), 'addRule' );
const addRuleSpy = spy( ( styleSheet as any ), 'addRule' );

// Act
styleSheet.parseFromString( text, TestStyle );

// Assert
expect( spy.notCalled ).to.be.true;
expect( addRuleSpy.notCalled ).to.be.true;
expect( ( styleSheet as any ).rules.length ).to.equal( 0 );
} );

Expand Down
1 change: 0 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"no-irregular-whitespace": true,
"no-mergeable-namespace": true,
"no-object-literal-type-assertion": true,
"no-parameter-properties": true,
"no-parameter-reassignment": true,
"no-redundant-jsdoc": true,
"no-require-imports": true,
Expand Down

0 comments on commit cd90c84

Please sign in to comment.