From 45d58e93dfe7137fa9beafbcaf4a6cc75b3f3a50 Mon Sep 17 00:00:00 2001 From: Ido Rosenthal Date: Sun, 29 Aug 2021 12:53:11 +0300 Subject: [PATCH 01/16] feat: initial design for css value parser --- packages/css-value-parser/package.json | 33 ++ packages/css-value-parser/src/ast-types.ts | 69 ++++ .../css-value-parser/src/define-property.ts | 69 ++++ packages/css-value-parser/src/index.ts | 6 + .../src/properties/background.ts | 46 +++ .../css-value-parser/src/properties/margin.ts | 36 ++ packages/css-value-parser/src/tokenizer.ts | 48 +++ packages/css-value-parser/src/tsconfig.json | 7 + packages/css-value-parser/src/value-parser.ts | 19 + .../test/define-property.spec.ts | 355 ++++++++++++++++++ .../test/properties/background.spec.ts | 29 ++ .../test/properties/margin.spec.ts | 126 +++++++ packages/css-value-parser/test/tsconfig.json | 8 + .../test/value-parser.spec.ts | 76 ++++ tsconfig.json | 2 + 15 files changed, 929 insertions(+) create mode 100644 packages/css-value-parser/package.json create mode 100644 packages/css-value-parser/src/ast-types.ts create mode 100644 packages/css-value-parser/src/define-property.ts create mode 100644 packages/css-value-parser/src/index.ts create mode 100644 packages/css-value-parser/src/properties/background.ts create mode 100644 packages/css-value-parser/src/properties/margin.ts create mode 100644 packages/css-value-parser/src/tokenizer.ts create mode 100644 packages/css-value-parser/src/tsconfig.json create mode 100644 packages/css-value-parser/src/value-parser.ts create mode 100644 packages/css-value-parser/test/define-property.spec.ts create mode 100644 packages/css-value-parser/test/properties/background.spec.ts create mode 100644 packages/css-value-parser/test/properties/margin.spec.ts create mode 100644 packages/css-value-parser/test/tsconfig.json create mode 100644 packages/css-value-parser/test/value-parser.spec.ts diff --git a/packages/css-value-parser/package.json b/packages/css-value-parser/package.json new file mode 100644 index 00000000..adb5732e --- /dev/null +++ b/packages/css-value-parser/package.json @@ -0,0 +1,33 @@ +{ + "name": "@tokey/css-value-parser", + "private": true, + "description": "value parser for css", + "version": "0.0.1", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "test": "mocha \"./dist/test/**/*.spec.js\"" + }, + "dependencies": { + "@tokey/core": "^1.2.1" + }, + "keywords": [ + "parser", + "css", + "value" + ], + "files": [ + "src", + "dist", + "!dist/test", + "!*/tsconfig.{json,tsbuildinfo}" + ], + "publishConfig": { + "access": "public" + }, + "author": "Wix.com", + "license": "MIT", + "repository": "https://github.com/wixplosives/tokey/packages/css-value-parser", + "prettier": {}, + "sideEffects": false +} diff --git a/packages/css-value-parser/src/ast-types.ts b/packages/css-value-parser/src/ast-types.ts new file mode 100644 index 00000000..030f3636 --- /dev/null +++ b/packages/css-value-parser/src/ast-types.ts @@ -0,0 +1,69 @@ +export interface CSSValueAST { + type: TYPE; + start: number; + end: number; +} + +export type BaseAstNode = CustomIdent | DashedIdent | String | Number | Integer; + +/* types */ + +// custom +export type BuildVarAst = CSSValueAST<`build-var`> & { + subType: string; + id: string; +}; + +// separators +export type RawComma = CSSValueAST<`,`>; +export type RawSpace = CSSValueAST<` `>; + +// textual +export type CustomIdent = CSSValueAST<``>; +export type DashedIdent = CSSValueAST<``>; +export type String = CSSValueAST<``>; +export type Url = CSSValueAST<``>; +// numeric +export type Integer = CSSValueAST<``>; +export type Number = CSSValueAST<``>; +export type Percentage = CSSValueAST<``>; +export type Ratio = CSSValueAST<``>; +// distance +export type Length = CSSValueAST<``>; +// other quantities +export type Angle = CSSValueAST<``>; +export type Time = CSSValueAST<`