Skip to content

Commit b7c3590

Browse files
committed
Update indentation to spaces
1 parent 00ca2b2 commit b7c3590

25 files changed

+994
-996
lines changed

CSSObject/CSSObject.js

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -7,100 +7,100 @@ import Stylesheet from "./parser/Stylesheet.js"
77
*/
88
class CSSObject {
99

10-
/**
11-
* CSSObject constructor
12-
* @param {object} options
13-
* @returns CSSObject
14-
*/
15-
constructor(options = {}) {
16-
this.options(options)
17-
18-
return this
19-
}
20-
21-
/**
22-
* set options to get external stylesheets
23-
* @param {object} options options
24-
* @returns CSSObject
25-
*/
26-
options(options = {}) {
27-
this.__defaultOptions__ = {
28-
29-
/**
30-
* load only especified css files, if used `ignore_files` isn't used
31-
* @type string[]
32-
*/
33-
only_files: (options.only_files || []),
34-
35-
/**
36-
* ignore css files
37-
* @type string[]
38-
*/
39-
ignore_files: (options.ignore_files || []),
40-
41-
/**
42-
* load minified css (default `true`)
43-
* @type boolean
44-
*/
45-
load_min: (options.load_min || true),
46-
}
47-
48-
this._options = { ...this.__defaultOptions__, ...options }
49-
return this
50-
}
51-
52-
/**
53-
* get local stylesheets
54-
* @param {object} callback callback function
55-
* @param {boolean} all return all stylesheets in callback
56-
*/
57-
local(callback, all = false) {
58-
let styles = []
59-
Object.values(document.styleSheets).forEach(sheet => {
60-
if (sheet.ownerNode != null || sheet.ownerNode.childNodes.length > 0)
61-
if (sheet.ownerNode.innerText != "") {
62-
let style = new Stylesheet(sheet.ownerNode.innerText)
63-
all ? styles.push(style) : callback(style)
64-
}
65-
})
66-
67-
if (styles.length > 0) callback(styles)
68-
return this
69-
}
70-
71-
/**
72-
* get external css (link)
73-
* @param {object} callback callback
74-
*/
75-
external(callback) {
76-
Object.values(document.styleSheets).forEach(sheet => {
77-
if (sheet.ownerNode.nodeName == 'LINK') {
78-
this.__external(sheet.href, callback)
79-
}
80-
})
81-
82-
return this
83-
}
84-
85-
/**
86-
* load external stylesheets
87-
* @param {string} link link to external stylesheet
88-
* @returns reponse (promise)
89-
* @private don't use please
90-
*/
91-
async __external(link, callback) {
92-
let filename = link.split('/').pop()
93-
let is_min = filename.endsWith('.min.css')
94-
if (!this._options.load_min_css && is_min) return
95-
if (this._options.only_files.length == 0 && this._options.ignore_files.includes(filename)) return
96-
if (this._options.only_files.length > 0 && !this._options.only_files.includes(filename)) return
97-
98-
return await (fetch(link))
99-
.then(res => res.text())
100-
.then(css => callback(new Stylesheet(css, filename)))
101-
.catch(err => console.error(err))
102-
103-
}
10+
/**
11+
* CSSObject constructor
12+
* @param {object} options
13+
* @returns CSSObject
14+
*/
15+
constructor(options = {}) {
16+
this.options(options)
17+
18+
return this
19+
}
20+
21+
/**
22+
* set options to get external stylesheets
23+
* @param {object} options options
24+
* @returns CSSObject
25+
*/
26+
options(options = {}) {
27+
this.__defaultOptions__ = {
28+
29+
/**
30+
* load only especified css files, if used `ignore_files` isn't used
31+
* @type string[]
32+
*/
33+
only_files: (options.only_files || []),
34+
35+
/**
36+
* ignore css files
37+
* @type string[]
38+
*/
39+
ignore_files: (options.ignore_files || []),
40+
41+
/**
42+
* load minified css (default `true`)
43+
* @type boolean
44+
*/
45+
load_min: (options.load_min || true),
46+
}
47+
48+
this._options = { ...this.__defaultOptions__, ...options }
49+
return this
50+
}
51+
52+
/**
53+
* get local stylesheets
54+
* @param {object} callback callback function
55+
* @param {boolean} all return all stylesheets in callback
56+
*/
57+
local(callback, all = false) {
58+
let styles = []
59+
Object.values(document.styleSheets).forEach(sheet => {
60+
if (sheet.ownerNode != null || sheet.ownerNode.childNodes.length > 0)
61+
if (sheet.ownerNode.innerText != "") {
62+
let style = new Stylesheet(sheet.ownerNode.innerText)
63+
all ? styles.push(style) : callback(style)
64+
}
65+
})
66+
67+
if (styles.length > 0) callback(styles)
68+
return this
69+
}
70+
71+
/**
72+
* get external css (link)
73+
* @param {object} callback callback
74+
*/
75+
external(callback) {
76+
Object.values(document.styleSheets).forEach(sheet => {
77+
if (sheet.ownerNode.nodeName == 'LINK') {
78+
this.__external(sheet.href, callback)
79+
}
80+
})
81+
82+
return this
83+
}
84+
85+
/**
86+
* load external stylesheets
87+
* @param {string} link link to external stylesheet
88+
* @returns reponse (promise)
89+
* @private don't use please
90+
*/
91+
async __external(link, callback) {
92+
let filename = link.split('/').pop()
93+
let is_min = filename.endsWith('.min.css')
94+
if (!this._options.load_min_css && is_min) return
95+
if (this._options.only_files.length == 0 && this._options.ignore_files.includes(filename)) return
96+
if (this._options.only_files.length > 0 && !this._options.only_files.includes(filename)) return
97+
98+
return await (fetch(link))
99+
.then(res => res.text())
100+
.then(css => callback(new Stylesheet(css, filename)))
101+
.catch(err => console.error(err))
102+
103+
}
104104
}
105105

106106

CSSObject/CSSParser.js

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import StatmentsParser from "./parser/StatmentsParser.js"
22
import BlocksParser from "./parser/BlocksParser.js"
33
import ParserBlock from "./parser/ParserBlock.js"
4-
import CommentBlock from "./parser/CommentBlock.js"
5-
import VariableRule from "./rules/VariableRule.js"
64
import ICSS from "./enums/ICSS.js"
75

86

@@ -12,46 +10,46 @@ import ICSS from "./enums/ICSS.js"
1210
*/
1311
class CSSParser extends StatmentsParser(BlocksParser(ParserBlock)) {
1412

15-
/**
16-
* Initialize CSSParser
17-
* @param {string} style css text
18-
* @returns {CSSParser}
19-
*/
20-
constructor(style = null) {
21-
super()
22-
23-
if (style != null) this.parse(style)
24-
return this
25-
}
26-
27-
/**
28-
* parser css
29-
* @method parser to parser css
30-
* @param {string} style_text css style text
31-
*/
32-
parse(style) {
33-
this.comments = this.comment(style)
34-
this.css = this.clean(style)
35-
this.blocks = this.statments()
36-
.split(ICSS.BLOCK.END)
37-
.filter(i => i.trim() != "")
38-
.map(b => this.block(b))
39-
40-
this.variables = this.variables(this.blocks, this.stats)
41-
return this
42-
}
43-
44-
/**
45-
* clean code css
46-
* remove comments, breaklines and tabs
47-
* @returns string
48-
*/
49-
clean(cssText) {
50-
let css = ICSS.REGEX_REPLACE(cssText, {'\n': '', '\r': '', '\t': '', ' ': ''})
51-
this.comments.map(c => css = css.replace(c.toString(), ICSS.EMPTY))
52-
53-
return css.trim()
54-
}
13+
/**
14+
* Initialize CSSParser
15+
* @param {string} style css text
16+
* @returns {CSSParser}
17+
*/
18+
constructor(style = null) {
19+
super()
20+
21+
if (style != null) this.parse(style)
22+
return this
23+
}
24+
25+
/**
26+
* parser css
27+
* @method parser to parser css
28+
* @param {string} style_text css style text
29+
*/
30+
parse(style) {
31+
this.comments = this.comment(style)
32+
this.css = this.clean(style)
33+
this.blocks = this.statments()
34+
.split(ICSS.BLOCK.END)
35+
.filter(i => i.trim() != "")
36+
.map(b => this.block(b))
37+
38+
this.variables = this.variables(this.blocks, this.stats)
39+
return this
40+
}
41+
42+
/**
43+
* clean code css
44+
* remove comments, breaklines and tabs
45+
* @returns string
46+
*/
47+
clean(cssText) {
48+
let css = ICSS.REGEX_REPLACE(cssText, {'\n': '', '\r': '', '\t': '', ' ': ''})
49+
this.comments.map(c => css = css.replace(c.toString(), ICSS.EMPTY))
50+
51+
return css.trim()
52+
}
5553
}
5654

5755

0 commit comments

Comments
 (0)