-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extract element analysis to its own package.
Elemenent analysis data structures needed to be stand-alone in order to remove a circular dependency between modules during development.
- Loading branch information
1 parent
d31bb9a
commit f591418
Showing
54 changed files
with
4,581 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "@opticss/element-analysis", | ||
"version": "0.1.0", | ||
"description": "Data structures for storing the analysis of elements.", | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"scripts": { | ||
"env": "env", | ||
"compile": "rm -rf dist test/build && tsc", | ||
"pretest": "yarn run compile && yarn run tslint", | ||
"prepublish": "rm -rf dist && tsc", | ||
"tslint": "tslint --project tsconfig.json", | ||
"test": "mocha dist/test --opts test/mocha.opts", | ||
"coverage": "istanbul cover -i \"dist/src/**/*.js\" --dir ./build/coverage node_modules/.bin/_mocha -- dist/test --opts test/mocha.opts", | ||
"remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html", | ||
"docs": "typedoc --out ./docs ." | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/css-blocks/opticss.git" | ||
}, | ||
"keywords": [ | ||
"css", | ||
"cascade" | ||
], | ||
"author": "Chris Eppstein", | ||
"license": "BSD-2-Clause", | ||
"bugs": { | ||
"url": "https://github.com/css-blocks/opticss/issues" | ||
}, | ||
"homepage": "https://github.com/css-blocks/opticss#readme", | ||
"peerDependencies": { | ||
"opticss": "*" | ||
}, | ||
"dependencies": { | ||
"@opticss/util": "*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.26", | ||
"mocha": "^3.4.2", | ||
"mocha-typescript": "^1.1.9", | ||
"tslint": "^5.1.0", | ||
"typescript": "^2.4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { SourceLocation } from "./index"; | ||
import { Tag, SerializedTagname } from "./Tagname"; | ||
import { Attr, SerializedAttribute } from "./Attribute"; | ||
import { POSITION_UNKNOWN } from "./SourceLocation"; | ||
|
||
export type Selectable = Element | Tag | Attr; | ||
|
||
export interface ElementInfo<TagnameType = Tag, AttributeType = Attr> { sourceLocation?: SourceLocation; | ||
tagname: TagnameType; | ||
attributes: Array<AttributeType>; | ||
id?: string; | ||
} | ||
|
||
export type SerializedElementInfo = ElementInfo<SerializedTagname, SerializedAttribute>; | ||
|
||
export class Element implements ElementInfo { | ||
sourceLocation: SourceLocation; | ||
tagname: Tag; | ||
attributes: Array<Attr>; | ||
id: string | undefined; | ||
constructor(tagname: Tag, attributes: Array<Attr>, sourceLocation?: SourceLocation, id?: string) { | ||
this.tagname = tagname; | ||
this.attributes = attributes; | ||
this.sourceLocation = sourceLocation || {start: POSITION_UNKNOWN}; | ||
this.id = id; | ||
} | ||
|
||
static fromElementInfo(info: ElementInfo): Element { | ||
return new Element(info.tagname, info.attributes, info.sourceLocation, info.id); | ||
} | ||
|
||
serialize(): SerializedElementInfo { | ||
let e: SerializedElementInfo = { | ||
tagname: this.tagname.toJSON(), | ||
attributes: this.attributes.map(a => a.toJSON()) | ||
}; | ||
if (this.sourceLocation && this.sourceLocation.start.line >= 0) { | ||
e.sourceLocation = this.sourceLocation; | ||
} | ||
return e; | ||
} | ||
toString() { | ||
let parts = []; | ||
parts.push(this.tagname); | ||
for (let attr of this.attributes) { | ||
parts.push(attr); | ||
} | ||
return `<${parts.join(" ")}>`; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.